Skip to content

GameTime UnitLifeTime #4703

@tdauth

Description

@tdauth
library GameTime initializer Init requires OnGameStart

globals
    public constant real CYCLE_TIME = 9999999999.0

    private timer t = CreateTimer()
    private integer cycle = 0
endglobals

function GameGetElapsed takes nothing returns real
    return TimerGetElapsed(t) + CYCLE_TIME * cycle
endfunction

private function TimerFunctionAddCycle takes nothing returns nothing
    set cycle = cycle + 1
endfunction

private function StartTime takes nothing returns nothing
    call TimerStart(t, 9999999999.0, true, function TimerFunctionAddCycle)
endfunction

private function Init takes nothing returns nothing
    call OnGameStart(function StartTime)
endfunction

endlibrary

library TimedLife

globals
    private constant integer KEY_INITIAL_DURATION = 0
    private constant integer KEY_ELAPSED_GAME_TIME = 1

    private hashtable h = InitHashtable()
endglobals

function UnitHasTimedLife takes unit whichUnit returns boolean
    return HaveSavedReal(h, GetHandleId(whichUnit), KEY_INITIAL_DURATION)
endfunction

function GetUnitTimedLifeInitialDuration takes unit whichUnit returns real
    return LoadReal(h, GetHandleId(whichUnit), KEY_INITIAL_DURATION)
endfunction

function GetUnitTimedLifeInitialGameTime takes unit whichUnit returns real
    return LoadReal(h, GetHandleId(whichUnit), 1)
endfunction

private function HookUnitApplyTimedLife takes unit whichUnit, integer buffId, real duration returns nothing
    call SetUnitTimedLifeDuration(whichUnit, duration)
endfunction

hook UnitApplyTimedLife HookUnitApplyTimedLife
hook RemoveUnit FlushUnitTimedLifeDuration

endlibrary

Metadata

Metadata

Assignees

Labels

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions