constant function hss_ChooseHeroSpellId takes nothing returns integer
return 'A000'
endfunction
constant function hss_RandomHeroSpellId takes nothing returns integer
return 'A002'
endfunction
constant function hss_SelectionArrowSpellId takes nothing returns integer
return 'A001'
endfunction
constant function hss_ComputerHeroes takes nothing returns boolean
return true
endfunction
constant function hss_DoCleanup takes nothing returns boolean
return true
endfunction
constant function hss_DoubleHeroesEnabled takes nothing returns boolean
return false
endfunction
constant function hss_TimeLimit takes nothing returns integer
return 10
endfunction
constant function hss_KillInactive takes nothing returns boolean
return false
endfunction
function hssFilterIsPossible takes nothing returns boolean
return IsUnitInGroup(GetFilterUnit(), udg_hss_SelectableHeroes) and RectContainsUnit( udg_hss_HeroSection[GetConvertedPlayerId(bj_groupEnumOwningPlayer)], GetFilterUnit() )
endfunction
function hssFilterIsAvailable takes nothing returns boolean
if GetTriggerUnit() == null and FirstOfGroup(udg_hss_AvailableHeroes) == null then
return hssFilterIsPossible()
endif
return IsUnitInGroup(GetFilterUnit(), udg_hss_AvailableHeroes) and RectContainsUnit( udg_hss_HeroSection[GetConvertedPlayerId(bj_groupEnumOwningPlayer)], GetFilterUnit() )
endfunction
function hssFilterIsComputerWithoutHero takes nothing returns boolean
return (GetPlayerController(GetFilterPlayer()) == MAP_CONTROL_COMPUTER) and (udg_hss_Heroes[GetConvertedPlayerId(GetFilterPlayer())] == null)
endfunction
function hss_Message takes integer i returns string
return GetAbilityEffectById(hss_ChooseHeroSpellId(),EFFECT_TYPE_SPECIAL,i)
endfunction
function SetPlayerHero takes player id, unit hero, string suffix returns nothing
local integer P=GetPlayerId(id)+1
local real x=GetRectCenterX(udg_hss_HeroCreation[P])
local real y=GetRectCenterY(udg_hss_HeroCreation[P])
if (id == null) or (P > 12) or (hero == null) then
return
endif
call GroupRemoveUnit( udg_hss_AvailableHeroes, hero )
if not hss_DoubleHeroesEnabled() then
call SetUnitColor( hero, GetPlayerColor(id) )
call UnitAddAbility(hero,'Aloc')
call SetUnitVertexColor( hero, 255, 255, 255, 127 )
endif
set udg_hss_Heroes[P]=CreateUnit(id, GetUnitTypeId(hero),x,y, bj_UNIT_FACING )
call SelectUnitAddForPlayer( udg_hss_Heroes[P], id )
call SetCameraPositionForPlayer(id, x, y)
call DisplayTextToForce( GetPlayersAll(), GetPlayerNameColored(id)+hss_Message(1)+GetUnitName(hero)+" "+suffix)
if udg_hss_CreatedHeroTrigger != null then
set bj_lastCreatedUnit=udg_hss_Heroes[P]
call ConditionalTriggerExecute( udg_hss_CreatedHeroTrigger )
endif
endfunction
function hss_GetRandomHero takes player a, boolean forced returns unit
local group heroes=CreateGroup()
local unit current
local boolexpr B=Condition(function hssFilterIsAvailable)
set bj_groupEnumOwningPlayer=a
call GroupEnumUnitsOfPlayer(heroes,Player(PLAYER_NEUTRAL_PASSIVE),B)
set current = GroupPickRandomUnit(heroes)
if (current == null) and forced then
set bj_groupEnumOwningPlayer=a
call DestroyBoolExpr(B)
set B=Condition(function hssFilterIsPossible)
call GroupEnumUnitsOfPlayer(heroes,Player(15),B)
set current = GroupPickRandomUnit(heroes)
endif
call DestroyGroup(heroes)
call DestroyBoolExpr(B)
set udg_hss_Heroes[100]=current
set current=null
set B=null
set heroes=null
return udg_hss_Heroes[100]
endfunction
function hss_OrderToPreviewHero takes nothing returns nothing
local unit selunit=GetTriggerUnit()
local player selplayer=GetOwningPlayer(selunit)
if GetIssuedOrderId() == OrderId("stop") or GetUnitUserData( selunit) == 1 or (udg_hss_Heroes[13+GetPlayerId(selplayer)] != selunit) or (udg_hss_Heroes[1+GetPlayerId(selplayer)] != null) then
set selunit=null
set selplayer=null
return
endif
call SetUnitUserData(selunit,1)
if GetIssuedOrderId() == 852273 then
call SetUnitOwner( selunit, Player(PLAYER_NEUTRAL_PASSIVE), true )
call UnitRemoveAbility( selunit,hss_SelectionArrowSpellId())
call SetPlayerHero(selplayer, selunit, "")
elseif GetIssuedOrderId() == 852277 then
set udg_hss_Heroes[100]=hss_GetRandomHero(selplayer,false)
if (udg_hss_Heroes[100] == null) then
call SimError(GetOwningPlayer(selunit), hss_Message(2))
else
call SetUnitOwner(selunit, Player(PLAYER_NEUTRAL_PASSIVE), true )
call UnitRemoveAbility(selunit, hss_SelectionArrowSpellId())
call SetPlayerHero(selplayer, udg_hss_Heroes[100], hss_Message(3))
endif
else
call SimError(GetOwningPlayer(selunit), hss_Message(4))
endif
set selunit=GetTriggerUnit()
call PauseUnit( selunit, true)
call IssueImmediateOrder( selunit, "stop" )
call PauseUnit(selunit, false)
call SetUnitUserData( selunit, 0 )
set selunit=null
set selplayer=null
endfunction
function hss_HeroIsClicked takes nothing returns nothing
local unit sel=GetTriggerUnit()
local player sp=GetTriggerPlayer()
local integer a
local unit old=udg_hss_Heroes[13+GetPlayerId(sp)]
if old != sel then
call SetUnitOwner( old, Player(15), true )
call UnitRemoveAbility( old, hss_SelectionArrowSpellId())
set udg_hss_Heroes[13+GetPlayerId(sp)] = null
if udg_hss_Heroes[GetConvertedPlayerId(sp)] == null and IsUnitInGroup(sel,udg_hss_SelectableHeroes) and IsUnitOwnedByPlayer(sel,Player(15)) then
if RectContainsUnit( udg_hss_HeroSection[GetConvertedPlayerId(sp)], sel ) then
call SetUnitManaPercentBJ( sel, 100 )
set udg_hss_Heroes[13+GetPlayerId(sp)] = sel
call UnitAddAbility(sel, hss_SelectionArrowSpellId())
call SetUnitUserData( sel,1)
call SetUnitOwner( sel, sp, true )
call SetUnitUserData( sel,0)
else
call SimError(sp, hss_Message(5))
endif
endif
endif
set sel=null
set sp=null
set old=null
endfunction
function hss_HeroShareVision takes nothing returns nothing
if RectContainsUnit( udg_hss_HeroSection[bj_forLoopAIndex+1], GetEnumUnit() ) then
call UnitShareVision( GetEnumUnit(), Player(bj_forLoopAIndex), true)
endif
endfunction
function hss_MakePlayerChooseHero_child takes nothing returns nothing
local player id=bj_groupEnumOwningPlayer
local unit current = udg_hss_Heroes[GetPlayerId(id) + 13]
call PolledWait(GetRandomReal(0.5,3))
call SetUnitUserData( current, 0)
if IsUnitOwnedByPlayer( current, id) then
call IssueImmediateOrderById( current, 852273)
endif
set id=null
set current=null
endfunction
function hss_MakePlayerChooseHero takes player id, unit hero returns boolean
local boolean res=false
if (id==null) then
return false
endif
if (udg_hss_Heroes[GetPlayerId(id) + 13] != null) and (udg_hss_Heroes[GetPlayerId(id) + 13] != hero) then
call SetUnitOwner( udg_hss_Heroes[GetPlayerId(id) + 13], Player(15), true )
call UnitRemoveAbility( udg_hss_Heroes[GetPlayerId(id) + 13], hss_SelectionArrowSpellId())
endif
if (udg_hss_Heroes[GetPlayerId(id)+1] == null) and IsUnitInGroup(hero,udg_hss_SelectableHeroes) and IsUnitOwnedByPlayer(hero,Player(15)) then
set udg_hss_Heroes[GetPlayerId(id) + 13] = hero
call UnitAddAbility( hero, hss_SelectionArrowSpellId())
call SetUnitOwner( hero, id, true)
set bj_groupEnumOwningPlayer=id
call ExecuteFunc("hss_MakePlayerChooseHero_child")
set res=true
endif
set hero=null
set id=null
return res
endfunction
function hss_AIChoose takes nothing returns nothing
local integer a=0
local force forcevar=CreateForce()
local player ai
local unit current
local boolexpr B=Condition(function hssFilterIsComputerWithoutHero)
loop
call TriggerSleepAction( GetRandomReal(0.05, 2) )
call ForceClear(forcevar)
call ForceEnumPlayers(forcevar,B)
set ai = ForcePickRandomPlayer(forcevar)
exitwhen (ai==null) or (a>40)
set current=hss_GetRandomHero(ai,(a>30))
if (current!=null) then
call hss_MakePlayerChooseHero(ai, current)
endif
set a=a+1
endloop
call DestroyForce(forcevar)
call DestroyBoolExpr(B)
set B=null
set current=null
set forcevar=null
set ai=null
endfunction
function StartVxHSS takes boolean rand, boolean comps, boolean cleanup returns nothing
local group heroes=CreateGroup()
local unit current
local integer a=0
local real x
local real y
local trigger UnitSel=CreateTrigger()
local trigger UnitOrder=CreateTrigger()
local force forcevar
local player ai
local timer t=null
local timerdialog td=null
local triggeraction uoac=TriggerAddAction(UnitOrder, function hss_OrderToPreviewHero)
local triggeraction usac=TriggerAddAction(UnitSel, function hss_HeroIsClicked)
set bj_wantDestroyGroup=false
call GroupAddGroup(udg_hss_SelectableHeroes,heroes)
loop
set current = FirstOfGroup(heroes)
exitwhen (current == null)
call GroupRemoveUnit(heroes, current)
call UnitRemoveAbility(current, 'Amov' )
call UnitAddAbility(current, 'Abun' )
call UnitAddAbility(current, hss_ChooseHeroSpellId() )
if rand then
call UnitAddAbility(current, hss_RandomHeroSpellId() )
endif
call TriggerRegisterUnitEvent( UnitOrder, current, EVENT_UNIT_ISSUED_TARGET_ORDER )
call TriggerRegisterUnitEvent( UnitOrder, current, EVENT_UNIT_ISSUED_POINT_ORDER )
call TriggerRegisterUnitEvent( UnitOrder, current, EVENT_UNIT_ISSUED_ORDER )
endloop
call DestroyGroup(heroes)
loop
exitwhen a>11
set x=GetRectCenterX(udg_hss_HeroSection[a+1])
set y=GetRectCenterY(udg_hss_HeroSection[a+1])
if GetLocalPlayer() == Player(a) then
call SetCameraPosition(x,y)
call SetCameraQuickPosition(x,y)
endif
set bj_forLoopAIndex=a
call ForGroup( udg_hss_SelectableHeroes, function hss_HeroShareVision)
call TriggerRegisterPlayerSelectionEventBJ( UnitSel, Player(a), true )
set a=a+1
endloop
call TriggerSleepAction(0)
if (hss_TimeLimit()>0) then
set t=CreateTimer()
call TimerStart(t,hss_TimeLimit(),false,null)
set td=CreateTimerDialogBJ(t,hss_Message(0))
call TimerDialogDisplay(td,true)
endif
if rand and IsMapFlagSet(MAP_RANDOM_HERO) then
set a=0
loop
exitwhen a>11
call TriggerSleepAction(0)
if (GetPlayerSlotState(Player(a)) == PLAYER_SLOT_STATE_PLAYING) and (comps or GetPlayerController(Player(a)) != MAP_CONTROL_COMPUTER) then
call SetPlayerHero(Player(a), hss_GetRandomHero(Player(a),true), hss_Message(6))
endif
set a=a+1
endloop
elseif comps then
call ExecuteFunc("hss_AIChoose")
endif
set x=0
loop
set a=0
set y=0
loop
exitwhen a>11
if (udg_hss_Heroes[a+1] == null) and (GetPlayerSlotState(Player(a)) == PLAYER_SLOT_STATE_PLAYING) and (comps or (GetPlayerController(Player(a))!=MAP_CONTROL_COMPUTER)) then
if (t!=null) and (TimerGetRemaining(t)<=0) then
if hss_KillInactive() then
call CustomDefeatBJ(Player(a),hss_Message(8))
else
call SetPlayerHero(Player(a), hss_GetRandomHero(Player(a),true), hss_Message(7))
endif
endif
set y=y+1
elseif (GetLocalPlayer()==Player(a)) then
call TimerDialogDisplay(td,false)
endif
set a=a+1
endloop
exitwhen (y <= 0)
call TriggerSleepAction(0)
endloop
loop
set current = FirstOfGroup(udg_hss_SelectableHeroes)
exitwhen current == null or not cleanup
call GroupRemoveUnit(udg_hss_SelectableHeroes, current)
call RemoveUnit( current)
endloop
call DestroyTimer(t)
call DestroyTimerDialog(td)
call DestroyGroup(udg_hss_SelectableHeroes)
call DestroyGroup(udg_hss_AvailableHeroes)
call TriggerRemoveAction(UnitSel,usac)
call DestroyTrigger(UnitSel)
call TriggerRemoveAction(UnitOrder,uoac)
call DestroyTrigger(UnitOrder)
set a=1
loop
exitwhen a>12
call TriggerSleepAction(0)
call RemoveRect(udg_hss_HeroSection[a])
call RemoveRect(udg_hss_HeroCreation[a])
set udg_hss_HeroSection[a] = null
set udg_hss_HeroCreation[a] = null
set udg_hss_Heroes[13+a-1] = null
set a=a+1
endloop
set t=null
set td=null
set uoac=null
set usac=null
set udg_hss_SelectableHeroes=null
set udg_hss_AvailableHeroes=null
set forcevar=null
set heroes=null
set current=null
endfunction
function VxHSS takes nothing returns nothing
call StartVxHSS((hss_RandomHeroSpellId()>0),hss_ComputerHeroes(),hss_DoCleanup())
endfunction
function InitTrig_Selection_System takes nothing returns nothing
endfunction