scope ArmyLocust
globals
private unit acu
endglobals
function ArmyLocustCond takes nothing returns boolean
local integer i = GetUnitTypeId(GetTrainedUnit())
if ( i == 'e000' ) then
return true
endif
if ( i == 'h008' ) then
return true
endif
return false
endfunction
function ArmyUnitCallback takes nothing returns nothing
local unit u = GetEnumUnit()
local integer i = LoadInteger(MUAC, 0, GetHandleId(u))
local integer p = GetPlayerId(GetOwningPlayer(u))
if ( i < MaxArmyCampUnits) then
call BJDebugMsg(I2S(i))
set acu = u
set i = i + 1
call SaveInteger(MUAC, 0, GetHandleId(u), i)
call SaveUnitHandle(MUAC, 2, GetHandleId(GetTrainedUnit()), u)
set u = null
endif
set u = null
endfunction
function ArmyLocustAct takes nothing returns nothing
local unit u = GetTrainedUnit()
local integer p = GetPlayerId(GetOwningPlayer(u))
local integer h = GetHandleId(u)
local real x
local real y
if (LoadUnitHandle(MUAC, 2, h) == null) then
call ForGroup(ArmyCamps, function ArmyUnitCallback)
endif
set x = GetUnitX(acu) + GetRandomReal(50, 300) * Cos(GetRandomDirectionDeg() * bj_DEGTORAD)
set y = GetUnitY(acu) + GetRandomReal(50, 300) * Sin(GetRandomDirectionDeg() * bj_DEGTORAD)
call SaveUnitHandle(MUAC, 2, h, acu)
call GroupAddUnit(ArmyUnits, u)
call UnitAddAbility(u, 'Abun')
call UnitAddAbility(u, 'Aloc')
call IssuePointOrder(u, "move", x, y)
set u = null
set acu = null
endfunction
//===========================================================================
function InitTrig_Army_Locust takes nothing returns nothing
set gg_trg_Army_Locust = CreateTrigger( )
call TriggerRegisterAnyUnitEventBJ( gg_trg_Army_Locust, EVENT_PLAYER_UNIT_TRAIN_FINISH )
call TriggerAddCondition( gg_trg_Army_Locust, Condition( function ArmyLocustCond ) )
call TriggerAddAction( gg_trg_Army_Locust, function ArmyLocustAct )
endfunction
endscope