//************************************************************************************************
//* *
//* Tree Revival System *
//* by Spinnaker *
//* *
//************************************************************************************************
//*************************************************************************
//*
//* Globals required
//*
//*************************************************************************
//* udg_TreeRevivalTrig Trigger for handling the revive actions
//* udg_TRhash Hashtable for timer issues
//* udg_dummyh Dummy harvester for IsDestructibleTree function
//* Configurable function for delay before tree gets resurrected
constant function TreeReviveDelay takes nothing returns real
return 5.
endfunction
//* Tells if birth animation should be shown while resurrecting a tree
constant function TreeShowAnimation takes nothing returns boolean
return true
endfunction
//* System itself
function TrCallback takes nothing returns nothing
local timer t = GetExpiredTimer()
local destructable d = LoadDestructableHandle(udg_TRhash, GetHandleId(t), 0)
call DestructableRestoreLife(d, GetDestructableMaxLife(d), TreeShowAnimation())
call PauseTimer(t)
call DestroyTimer(t)
call FlushChildHashtable(udg_TRhash, GetHandleId(t))
set d = null
set t = null
endfunction
function CallTreeRevive takes nothing returns boolean
local timer t = CreateTimer()
call SaveDestructableHandle(udg_TRhash, GetHandleId(t), 0, GetTriggerDestructable())
call TimerStart(t, TreeReviveDelay(), false, function TrCallback)
set t = null
return false
endfunction
function IsDestructableTree takes destructable dest returns boolean
return IssueTargetOrderById(udg_dummyh, 852018, dest)
endfunction
function CallAddTree takes nothing returns nothing
if IsDestructableTree(GetEnumDestructable()) then
call TriggerRegisterDeathEvent(udg_TreeReviveTrig, GetEnumDestructable())
endif
endfunction
//***************************************************************************
function InitTrig_TreeRevive takes nothing returns nothing
set udg_TreeReviveTrig = CreateTrigger()
set udg_TRhash = InitHashtable()
//* Actions required for IsDestructibleTree function
set udg_dummyh = CreateUnit(Player(15), 'uloc', 0., 0., 0.)
call ShowUnit(udg_dummyh, false)
call UnitAddAbility(udg_dummyh, 'Ahrl')
call UnitRemoveAbility(udg_dummyh, 'Amov')
//* Revival setup
call EnumDestructablesInRect(bj_mapInitialPlayableArea, null, function CallAddTree)
call TriggerAddCondition(udg_TreeReviveTrig, Condition(function CallTreeRevive))
endfunction