//************************************************************************************
//*
//*
//* LINKED LIST TABLE
//*
//* BY : ALMIA
//*
//*
//************************************************************************************
//*
//* Used to create linked list
//*
//************************************************************************************
//*
//*
//* CODE API
//*
//* constant function LLT_PrevArrayValueKey takes nothing returns integer
//* constant function LLT_NextArrayValueKey takes nothing returns integer
//* constant function LLT_RecycleArrayValueKey takes nothing returns integer
//* constant function LLT_ICChildKey takes nothing returns integer
//*
//* - system constants for settings
//* - Recommended not to be touched
//*
//* function LLT_GetNextKey takes integer index returns integer
//* function LLT_GetPrevKey takes integer index returns integer
//* function LLT_GetRCKey takes integer index returns integer
//*
//* - Value keys
//*
//* function GetNextIndexOfList takes integer list , integer index returns integer
//* function GetPrevIndexOfList takes integer list , integer index returns integer
//* function GetRecycleIndexOfList takes integer list, integer index returns integer
//* function GetInstanceCountOfList takes integer list returns integer
//*
//* - Getters of indexes
//* - Used for linked list's values
//*
//* function SetNextIndexOfList takes integer list , integer index , integer value returns nothing
//* function SetPrevIndexOfList takes integer list , integer index , integer value returns nothing
//* function SetRecycleIndexOfList takes integer list , integer index , integer value returns nothing
//* function SetInstanceIndexOfList takes integer list , integer value returns nothing
//*
//* - Setters for indexes
//* - Used for setting values of linked lists
//*
//* function CreateLinkedList takes nothing returns integer
//*
//* - Creates linked lists
//*
//* function ClearLinkedList takes integer list returns nothing
//*
//* - Clears linked lists cached values
//*
//* function DestroyLinkedList takes integer list returns nothing
//*
//* - Destroys linked list
//*
//* function GetNewIndexFromLinkedList takes integer list returns integer
//*
//* - Allocates a new instance for the linked list
//*
//* function RecycleIndexFromLinkedList takes integer list,integer index returns nothing
//*
//* - Recycles the instance
//* - Commonly used when a code's effect ends
//*
//* function GetNextIndexFromLinkedList takes integer index , integer list returns integer
//*
//* - Gets next index for the enumeration of index
//*
//* function GetFirstIndexFromLinkedList takes integer list returns integer
//*
//* - Gets first index for the enumeration of index
//*
//************************************************************************************
//*
//* ITERATION MODULE
//*
//* Module for iterating instance
//* Must be CnPed
//*
//* All words in between "$" should be replaced by
//* your own variable
//*
//* Legend:
//*
//* $LIST$ = Your List
//* $INDEX$ = Your Index
//* $CODE$ = Your code
//*
//*
//* set $INDEX$ = GetFirstIndexFromLinkedList($LIST$)
//*
//* loop
//* exitwhen $INDEX$ == 0
//*
//* $CODE$
//* ( NOTE : If the code's effect ends
//* please recycle index via calling:
//* call RecycleIndexFromLinkedList($LIST$, $INDEX$)
//* in a custom script)
//*
//* set $INDEX$ = GetNextIndexFromLinkedList($LIST$, $INDEX$)
//*
//* endloop
//*
//*
//* DESCRIPTION :
//*
//* This way,you can iterate indexed variables
//* unlike Indexed Arrays or Dynamic Indexing
//* You use custom scripts because GUI For Loop Integer
//* cannot handle this kind of iteration
//*
//************************************************************************************
//*
//* Variables :
//*
//* LLT_Table = hashtable
//* LLT_RC = integer array
//* LLT_IC = integer
//*
//************************************************************************************
//*
//* Credits :
//*
//* - Magtheridon96
//* - Maker
//*
//************************************************************************************
//***********************************************************
//*
//* SETTINGS
//*
//***********************************************************
//The following constants refer to minimum value of next
//prev and recycle.
constant function LLT_PrevArrayValueKey takes nothing returns integer
return 0
endfunction
constant function LLT_NextArrayValueKey takes nothing returns integer
return JASS_MAX_ARRAY_SIZE// 8192
endfunction
constant function LLT_RecycleArrayValueKey takes nothing returns integer
return 2* JASS_MAX_ARRAY_SIZE //16384
endfunction
constant function LLT_ICChildKey takes nothing returns integer
return -1
endfunction
//***********************************************************
//*
//* TOOLS
//*
//***********************************************************
function LLT_GetNextKey takes integer index returns integer
return LLT_NextArrayValueKey() + index
endfunction
function LLT_GetPrevKey takes integer index returns integer
return LLT_PrevArrayValueKey() + index
endfunction
function LLT_GetRCKey takes integer index returns integer
return LLT_RecycleArrayValueKey() + index
endfunction
//* SETS and GETS functions
//Get Values
function GetNextIndexOfList takes integer list , integer index returns integer
return LoadInteger(udg_LLT_Table, list, LLT_GetNextKey(index))
endfunction
function GetPrevIndexOfList takes integer list , integer index returns integer
return LoadInteger(udg_LLT_Table, list, LLT_GetPrevKey(index))
endfunction
function GetRecycleIndexOfList takes integer list , integer index returns integer
return LoadInteger(udg_LLT_Table, list, LLT_GetRCKey(index))
endfunction
function GetInstanceCountOfList takes integer list returns integer
return LoadInteger(udg_LLT_Table, list, LLT_ICChildKey())
endfunction
//Set Values
function SetNextIndexOfList takes integer list , integer index , integer value returns nothing
call SaveInteger(udg_LLT_Table, list, LLT_GetNextKey(index), value)
endfunction
function SetPrevIndexOfList takes integer list , integer index , integer value returns nothing
call SaveInteger(udg_LLT_Table, list, LLT_GetPrevKey(index), value)
endfunction
function SetRecycleIndexOfList takes integer list , integer index , integer value returns nothing
call SaveInteger(udg_LLT_Table, list, LLT_GetRCKey(index), value)
endfunction
function SetInstanceIndexOfList takes integer list , integer value returns nothing
call SaveInteger(udg_LLT_Table, list, LLT_ICChildKey(), value)
endfunction
//***********************************************************
//*
//* MAIN FUNCTIONS
//*
//***********************************************************
function CreateLinkedList takes nothing returns integer
local integer index = udg_LLT_RC[0]
//Initializing
if null == udg_LLT_Table then
set udg_LLT_Table = InitHashtable()
endif
if 0 == index then
set udg_LLT_IC = udg_LLT_IC + 1
return udg_LLT_IC
endif
set udg_LLT_RC[0] = udg_LLT_RC[index]
return index
endfunction
function ClearLinkedList takes integer list returns nothing
call FlushChildHashtable(udg_LLT_Table, list)
endfunction
function DestroyLinkedList takes integer list returns nothing
call ClearLinkedList(list)
set udg_LLT_RC[list] = udg_LLT_RC[0]
set udg_LLT_RC[0] = list
endfunction
function GetNewIndexFromLinkedList takes integer list returns integer
local integer this = GetRecycleIndexOfList(list, 0)
local integer ic
//Allocating Instance
if 0 == this then
set ic = GetInstanceCountOfList(list) + 1
call SetInstanceIndexOfList(list, ic)
set this = ic
else
call SetRecycleIndexOfList(list, 0, GetRecycleIndexOfList(list, this))
endif
// Adding the instance to list
call SetNextIndexOfList(list, this, 0)
call SetPrevIndexOfList(list, this, 0)
call SetNextIndexOfList(list, GetPrevIndexOfList(list, 0), this)
call SetPrevIndexOfList(list, 0, this)
return this
endfunction
function RecycleIndexFromLinkedList takes integer list,integer index returns nothing
//Recycling instance
call SetNextIndexOfList(list, GetPrevIndexOfList(list, index), GetNextIndexOfList(list, index))
call SetPrevIndexOfList(list, GetNextIndexOfList(list, index), GetPrevIndexOfList(list, index))
call SetRecycleIndexOfList(list, index, GetRecycleIndexOfList(list, 0))
call SetRecycleIndexOfList(list, 0, index)
endfunction
//***********************************************************
//*
//* EXTRA FUNCTIONS
//*
//***********************************************************
function GetNextIndexFromLinkedList takes integer list , integer index returns integer
return GetNextIndexOfList(list, index)
endfunction
function GetFirstIndexFromLinkedList takes integer list returns integer
return GetNextIndexOfList(list, 0)
endfunction
Name | Type | is_array | initial_value |
LLT_IC | integer | No | |
LLT_RC | integer | Yes | |
LLT_Table | hashtable | No | |
TA_Ability | integer | Yes | |
TA_Count | integer | No | |
TA_Duration | real | Yes | |
TA_Hash | hashtable | No | |
TA_List | integer | No | |
TA_Timer | timer | No | |
TA_Unit | unit | Yes |
//************************************************************************************
//*
//*
//* 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 GetUnitTimedAbilityId 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