function PhoenixBonus takes unit u returns nothing
local integer id=GetUnitTypeId(u)
if id=='hphx' then // the lvl 2,3..n phoenixes or id=='hph1' or id=='hph2' or...
call UnitAddAbility(u,'Apmf')
call UnitAddAbility(u,'Apxf')
call SetUnitAbilityLevel(u,'Apmf',IntegerTertiaryOp(id=='hphx',1,IntegerTertiaryOp(id=='hph1',2,3)))
call SetUnitAbilityLevel(u,'Apxf',IntegerTertiaryOp(id=='hphx',1,IntegerTertiaryOp(id=='hph1',2,3)))
// to be continued to the second last lvl
endif
set u=null
endfunction
function PhoenixHandle takes nothing returns nothing
local unit u=GetTriggerUnit()
local trigger t=GetTriggeringTrigger()
loop
exitwhen GetUnitTypeId(u)=='hpxe' or GetUnitState(u,UNIT_STATE_LIFE)==0
call TriggerSleepAction(0)
endloop
loop
exitwhen GetUnitTypeId(u)!='hpxe' or GetUnitState(u,UNIT_STATE_LIFE)==0
call TriggerSleepAction(0)
endloop
if GetUnitState(u,UNIT_STATE_LIFE)==0 then
call DestroyTrigger(t)
else
call PhoenixBonus(u)
endif
set u=null
set t=null
endfunction
function Phoenix_EnterMap takes nothing returns nothing
local unit u=GetTriggerUnit()
local integer id=GetUnitTypeId(u)
local trigger t
if id=='hphx' then // the lvl 2,3..n phoenixes or id=='hph1' or id=='hph2' or...
call PhoenixBonus(u)
set t=CreateTrigger()
call TriggerRegisterUnitLifeEvent(t,u,LESS_THAN_OR_EQUAL,1)
call TriggerAddAction(t,function PhoenixHandle)
endif
set u=null
set t=null
endfunction
function InitTrig_Phoenix takes nothing returns nothing
set gg_trg_Phoenix = CreateTrigger()
call TriggerRegisterEnterRectSimple(gg_trg_Summons,GetEntireMapRect())
call TriggerAddAction(gg_trg_Phoenix,function Phoenix_EnterMap)
endfunction