library ussSystem uses timerIndex
//Requires:
// - Unit Indexer (Bribe)
// - TimerUtils (Vexorian)
// - TimerIndex (Wietlol)
globals
real USS_PERIOD_INTERVAL = 0.03
real array unitSize_X
real array unitSize_Y
real array unitSize_Z
unit array USS_TargetedUnit
real array USS_SizeStep_X
real array USS_SizeStep_Y
real array USS_SizeStep_Z
real array USS_RemainingTime
endglobals
function UnitChangeSize takes unit whichUnit, real sizeFactor_X, real sizeFactor_Y, real sizeFactor_Z returns nothing
local integer id = GetUnitUserData(whichUnit)
set unitSize_X[id] = unitSize_X[id] * sizeFactor_X
set unitSize_Y[id] = unitSize_Y[id] * sizeFactor_Y
set unitSize_Z[id] = unitSize_Z[id] * sizeFactor_Z
call SetUnitScale(whichUnit, unitSize_X[id], unitSize_Y[id], unitSize_Z[id])
endfunction
function UnitChangeSizeSimple takes unit whichUnit, real sizeFactor returns nothing
call UnitChangeSize(whichUnit, sizeFactor, sizeFactor, sizeFactor)
endfunction
function UnitSetSize takes unit whichUnit, real size_X, real size_Y, real size_Z returns nothing
local integer id = GetUnitUserData(whichUnit)
set unitSize_X[id] = size_X
set unitSize_Y[id] = size_Y
set unitSize_Z[id] = size_Z
call SetUnitScale(whichUnit, size_X, size_Y, size_Z)
endfunction
function UnitSetSizeSimple takes unit whichUnit, real size returns nothing
call UnitSetSize(whichUnit, size, size, size)
endfunction
function UnitChangeSize_Callback takes nothing returns nothing
local timer t = GetExpiredTimer()
local integer timerId = GetTimerData(t)
call UnitChangeSize(USS_TargetedUnit[timerId], USS_SizeStep_X[timerId], USS_SizeStep_Y[timerId], USS_SizeStep_Z[timerId])
set USS_RemainingTime[timerId] = USS_RemainingTime[timerId] - USS_PERIOD_INTERVAL
if USS_RemainingTime[timerId] <= 0. then
call ReleaseIndexedTimer(t)
endif
set t = null
endfunction
function UnitChangeSize_Period takes unit whichUnit, real sizeFactor_X, real sizeFactor_Y, real sizeFactor_Z, real duration returns nothing
local timer t = NewIndexedTimer()
local integer timerId = GetTimerData(t)
local integer steps = R2I(duration/USS_PERIOD_INTERVAL)
local real power = 1./I2R(steps)
set USS_RemainingTime[timerId] = duration - ModuloReal(duration, USS_PERIOD_INTERVAL)
set USS_SizeStep_X[timerId] = Pow(sizeFactor_X, power)
set USS_SizeStep_Y[timerId] = Pow(sizeFactor_Y, power)
set USS_SizeStep_Z[timerId] = Pow(sizeFactor_Z, power)
set USS_TargetedUnit[timerId] = whichUnit
call TimerStart(t, USS_PERIOD_INTERVAL, true, function UnitChangeSize_Callback)
set t = null
endfunction
function UnitChangeSizeSimple_Period takes unit whichUnit, real sizeFactor, real duration returns nothing
call UnitChangeSize_Period(whichUnit, sizeFactor, sizeFactor, sizeFactor, duration)
endfunction
function UnitSetSize_Callback takes nothing returns nothing
local timer t = GetExpiredTimer()
local integer timerId = GetTimerData(t)
call UnitChangeSize(USS_TargetedUnit[timerId], USS_SizeStep_X[timerId], USS_SizeStep_Y[timerId], USS_SizeStep_Z[timerId])
set USS_RemainingTime[timerId] = USS_RemainingTime[timerId] - USS_PERIOD_INTERVAL
if USS_RemainingTime[timerId] < 0. then
call ReleaseIndexedTimer(t)
endif
set t = null
endfunction
function UnitSetSize_Period takes unit whichUnit, real sizeFactor_X, real sizeFactor_Y, real sizeFactor_Z, real duration returns nothing
local timer t = NewIndexedTimer()
local integer timerId = GetTimerData(t)
local integer unitId = GetUnitUserData(whichUnit)
local integer steps = R2I(duration/USS_PERIOD_INTERVAL)
local real power = 1./I2R(steps)
set USS_RemainingTime[timerId] = duration - ModuloReal(duration, USS_PERIOD_INTERVAL)
set USS_SizeStep_X[timerId] = Pow(sizeFactor_X/unitSize_X[unitId], power)
set USS_SizeStep_Y[timerId] = Pow(sizeFactor_Y/unitSize_Y[unitId], power)
set USS_SizeStep_Z[timerId] = Pow(sizeFactor_Z/unitSize_Z[unitId], power)
set USS_TargetedUnit[timerId] = whichUnit
call TimerStart(t, USS_PERIOD_INTERVAL, true, function UnitSetSize_Callback)
set t = null
endfunction
function UnitSetSizeSimple_Period takes unit whichUnit, real sizeFactor, real duration returns nothing
call UnitSetSize_Period(whichUnit, sizeFactor, sizeFactor, sizeFactor, duration)
endfunction
endlibrary
//System-only function.
function UnitCreated takes nothing returns boolean
local integer id = GetUnitUserData(udg_UDexUnits[udg_UDex])
set unitSize_X[id] = 1.
set unitSize_Y[id] = 1.
set unitSize_Z[id] = 1.
return false
endfunction
//===========================================================================
function InitTrig_USS_System takes nothing returns nothing
local trigger t = CreateTrigger()
call TriggerRegisterVariableEvent(t, "udg_UnitIndexEvent", EQUAL, 1.00)
call TriggerAddCondition(t, Filter(function UnitCreated))
endfunction