library ReviveDestructables requires TimerUtils
globals
private constant real DELAY = 10.0
private constant boolean SHOW_BIRTH = false
private constant trigger TRIG = CreateTrigger()
endglobals
private module Init
static method add takes nothing returns nothing
call TriggerRegisterDeathEvent(TRIG,GetEnumDestructable())
endmethod
static method filter takes nothing returns boolean
return true
endmethod
private static method onInit takes nothing returns nothing
local rect r = Rect(-32256,-32256,32256,32256)
call EnumDestructablesInRect(r,function thistype.filter,function thistype.add)
call TriggerAddCondition(TRIG,Condition(function thistype.run))
call RemoveRect(r)
set r = null
endmethod
endmodule
private struct Destructables
destructable d
method destroy takes nothing returns nothing
set .d = null
call .deallocate()
endmethod
static method expire takes nothing returns nothing
local timer t = GetExpiredTimer()
local thistype this = GetTimerData(t)
call DestructableRestoreLife(.d,GetDestructableMaxLife(.d),SHOW_BIRTH)
call ReleaseTimer(t)
call .destroy()
set t = null
endmethod
static method run takes nothing returns boolean
local thistype this = thistype.allocate()
local timer t = NewTimer()
set .d = GetTriggerDestructable()
call SetTimerData(t,this)
call TimerStart(t,DELAY,false,function thistype.expire)
set t = null
return false
endmethod
implement Init
endstruct
endlibrary