Moderator
M
Moderator
04:32, 30th Mar 2013
Magtheridon96: Approved. This is useful.
Magtheridon96: Approved. This is useful.
//************************************************************************************
//*
//*
//* TIMED ABILITY
//*
//* BY: ALMIA
//*
//*
//************************************************************************************
//*
//* Adds timed abilities to a unit
//*
//************************************************************************************
//*
//* Requires:
//*
//* Linked List Table - http://www.hiveworkshop.com/forums/spells-569/linked-list-table-v1-3-a-230076/
//*
//************************************************************************************
//*
//* CODE API
//*
//* constant function TimedAbilityDefaultTimeout takes nothing returns real
//*
//* - System default timeout
//*
//* function GetUnitTimedAbilityIndex takes integer spell, unit owner returns integer
//*
//* - Gets the id of the given spell and unit in the system
//* - "spell" must be in ASCII(Ex: 'AHtc')
//*
//* function TimedAbilityPeriodic takes nothing returns nothing
//*
//* - Periodic function of system
//*
//* function AddTimedAbility takes unit owner, integer spell, real duration returns nothing
//*
//* - Registers the unit to the system
//* - "spell" must be in ASCII(Ex: 'AHtc')
//*
//************************************************************************************
//*
//* Variables
//*
//* TA_List = Integer
//* TA_Timer = Timer
//* TA_Duration = Real Array
//* TA_Ability = Integer Array
//* TA_Unit = Unit Array
//* TA_Count = Integer
//*
//************************************************************************************
constant function TimedAbilityDefaultTimeout takes nothing returns real
return 0.031250000
endfunction
//************************************************************************************
function GetUnitTimedAbilityIndex takes integer spell, unit owner returns integer
return LoadInteger(udg_TA_Hash, GetHandleId(owner), spell)
endfunction
//************************************************************************************
function TimedAbilityPeriodic takes nothing returns nothing
local integer id = GetFirstIndexFromLinkedList(udg_TA_List)
loop
exitwhen 0 == id
// Check if duration is not yet 0
if 0 < udg_TA_Duration[id] then
set udg_TA_Duration[id] = udg_TA_Duration[id] - TimedAbilityDefaultTimeout()
else
//Removing Ability and Recycling Index
call UnitRemoveAbility(udg_TA_Unit[id], udg_TA_Ability[id])
call RecycleIndexFromLinkedList(udg_TA_List, id)
set udg_TA_Ability[id] = 0
set udg_TA_Unit[id] = null
set udg_TA_Count = udg_TA_Count - 1
if 0 == udg_TA_Count then
call PauseTimer(udg_TA_Timer)
endif
endif
set id = GetNextIndexFromLinkedList(udg_TA_List, id)
endloop
endfunction
//************************************************************************************
function AddTimedAbility takes unit owner, integer spell, real duration returns nothing
local integer index = GetUnitTimedAbilityId(spell, owner)
if 0 == index then
// Assigning new id to the unregistered unit
set index = GetNewIndexFromLinkedList(udg_TA_List)
set udg_TA_Count = udg_TA_Count + 1
if 1 == udg_TA_Count then
call TimerStart(udg_TA_Timer, TimedAbilityDefaultTimeout(), true, function TimedAbilityPeriodic)
endif
call UnitAddAbility(owner, spell)
call SaveInteger(udg_TA_Hash, GetHandleId(owner), spell, index)
endif
set udg_TA_Ability[index] = spell
set udg_TA_Duration[index] = duration
set udg_TA_Unit[index] = owner
endfunction
//************************************************************************************
function InitTrig_Timed_Ability takes nothing returns nothing
set udg_TA_List = CreateLinkedList()
set udg_TA_Hash = InitHashtable()
endfunction