Name | Type | is_array | initial_value |
GMUI_Hashtable | hashtable | No | |
GMUI_Index | integer | No | |
GMUI_RecycleKey | integer | No | |
Lists_Data | integer | No | |
Lists_Hashtable | hashtable | No | |
Lists_Instance | integer | No | |
Lists_ListID | integer | No | |
Lists_LoopUntil | integer | No | |
Lists_RECYCLE_KEY | integer | No | |
Lists_Trigger | trigger | No | |
Test_DestroyList | integer | No | |
Test_EscTimer | timer | No | |
Test_Footman_Array | unit | Yes | |
Test_GIOL_DestroyList | integer | No | |
Test_GIUL_DestroyList | integer | No | |
Test_GLL_DestroyList | integer | No | |
Test_Indexer_Footman | integer | No | |
Test_Indexer_Knight | integer | No | |
Test_Indexer_Rifleman | integer | No | |
Test_Knight_Array | unit | Yes | |
Test_Rifleman_Array | unit | Yes |
////////////////////////////////////////////////////////////////////////////////////////////////////
//Guhun's MUI Engine version 2.0.0
////////////////////////////////////////////////////////////////////////////////////////////////////
//This code generates an instance number for a RecycleKey
function GMUI_GetIndex takes integer RecycleKey returns integer
local integer instance
set instance = LoadInteger(udg_GMUI_Hashtable, RecycleKey, 0)
if not HaveSavedInteger(udg_GMUI_Hashtable, RecycleKey, instance) then
call SaveInteger(udg_GMUI_Hashtable, RecycleKey, 0, instance + 1)
else
call SaveInteger(udg_GMUI_Hashtable, RecycleKey, 0, LoadInteger(udg_GMUI_Hashtable, RecycleKey, instance))
call RemoveSavedInteger(udg_GMUI_Hashtable, RecycleKey, instance)
endif
return instance
endfunction
//This code generates recycles a used instance number for a RecycleKey
function GMUI_RecycleIndex takes integer RecycleKey, integer instance returns nothing
call SaveInteger(udg_GMUI_Hashtable, RecycleKey, instance, LoadInteger(udg_GMUI_Hashtable, RecycleKey, 0))
call SaveInteger(udg_GMUI_Hashtable, RecycleKey, 0, instance)
endfunction
//This code generates a new, unused, RecycleKey
function GMUI_CreateRecycleKey takes nothing returns integer
local integer newKey = GMUI_GetIndex(0)
call SaveInteger(udg_GMUI_Hashtable, newKey, 0, 1)
return newKey
endfunction
//This code recycles a used RecycleKey
function GMUI_DestroyRecycleKey takes integer whichKey returns nothing
if whichKey == 0 then
return
endif
call GMUI_RecycleIndex(0, whichKey)
call FlushChildHashtable(udg_GMUI_Hashtable, whichKey)
endfunction
//This function initializes GMUI if it has not yet been initialized
function GMUI_Initialize takes nothing returns nothing
if udg_GMUI_Hashtable == null then
//Initialize Hashtable
set udg_GMUI_Hashtable = InitHashtable()
//Initialize the recycling algorithm for Recycle Keys
call SaveInteger(udg_GMUI_Hashtable, 0, 0, 1)
//Initialize the generic Recycle Key
call GMUI_CreateRecycleKey() //Will always be 1
endif
endfunction
////////////////////////////////////////////////////////////////////////////////////////////////////
//End of MUI Engine
////////////////////////////////////////////////////////////////////////////////////////////////////
//===========================================================================
//! novjass
function InitTrig_GMUI takes nothing returns nothing
endfunction
//! endnovjass
////////////////////////////////////////////////////////////////////////////////////////////////////
//Guhun's Iterateable Ordered Lists v.2.0.0
////////////////////////////////////////////////////////////////////////////////////////////////////
//==============
// Utilities (Private Functions)
function GIOL__SetSize takes integer listKey, integer recycleKey returns nothing
call SaveInteger(udg_Lists_Hashtable, listKey, 0, recycleKey)
endfunction
function GIOL__GetCurrent takes integer listKey returns integer
return LoadInteger(udg_GMUI_Hashtable, udg_Lists_RECYCLE_KEY, -listKey)
endfunction
function GIOL__SetCurrent takes integer listKey, integer current returns nothing
call SaveInteger(udg_GMUI_Hashtable, udg_Lists_RECYCLE_KEY, -listKey, current)
endfunction
function GIOL__ResetCurrent takes integer listKey returns nothing
call RemoveSavedInteger(udg_GMUI_Hashtable, udg_Lists_RECYCLE_KEY, -listKey)
endfunction
//==============================================
// System API
//==============================================
//==============
//Getters and Setters
//Gets data in specified index of a list
//Available since 2.0.0
function GIOL_Get takes integer listKey, integer index returns integer
return LoadInteger(udg_Lists_Hashtable, listKey, index)
endfunction
//Gets the size of a specified list
//Available since 2.0.0, replaced GetListSize
function GIOL_SizeOf takes integer listKey returns integer
return LoadInteger(udg_Lists_Hashtable, listKey, 0)
endfunction
//Sets the value stored inside a specified index
//Available since 2.0.0
function GIOL_Set takes integer listKey, integer index, integer data returns nothing
call SaveInteger(udg_Lists_Hashtable, listKey, index, data)
endfunction
//Adds data to the end of a list and returns the index the data was added at (equal to size of the list)
//Available since 2.0.0, replaced GIUL_AddData
function GIOL_Append takes integer listKey, integer data returns integer
local integer size = GIOL_SizeOf(listKey) + 1
call GIOL_Set(listKey, size, data)
call GIOL__SetSize(listKey, size)
return size
endfunction
//Removes data from a certain index of a List
//Available since 2.0.0, replaced RemoveData
function GIOL_Remove takes integer listKey, integer instance returns nothing
local integer size = GIOL_SizeOf(listKey)
loop
exitwhen instance > size
call GIOL_Set(listKey, instance - 1, GIOL_Get(listKey, instance))
set instance = instance + 1
endloop
call RemoveSavedInteger(udg_Lists_Hashtable, listKey, size)
call GIOL__SetSize(listKey, size - 1)
endfunction
//==============
//List creation and destruction
//Creates a list and returns its list key/list ID
function GIOL_CreateList takes nothing returns integer
local integer listKey = GMUI_GetIndex(udg_Lists_RECYCLE_KEY)
call GIOL__SetSize(listKey, 0)
return listKey
endfunction
//Destroys the specified list
function GIOL_DestroyList takes integer listKey returns nothing
call FlushChildHashtable(udg_Lists_Hashtable, listKey)
call GIOL__ResetCurrent(listKey)
call GMUI_RecycleIndex(udg_Lists_RECYCLE_KEY, listKey)
endfunction
//==============
//Looping functionality
//======
//Functions for simplified looping
//Returns the next index of a list. If the index is 0, the end of the list has been reached.
//If you are using this function to loop, you should NOT use GIOL_Remove!
//Available since 2.0.0
function GIOL_Next takes integer listKey returns integer
local integer current = GIOL__GetCurrent(listKey)
if current < GIOL_SizeOf(listKey) then
call GIOL__SetCurrent(listKey, current+1)
return current+1
else
call GIOL__ResetCurrent(listKey)
return 0
endif
endfunction
//If you are iterating over a list using a GIUL_Next loop, you can use this function to remove the
//element in the index that you are currently at.
//Available since 2.0.0
function GIOL_RemoveCurrent takes integer listKey returns nothing
local integer current = GIOL__GetCurrent(listKey)
call GIOL_Remove(listKey, current)
call GIOL__SetCurrent(listKey, current-1)
endfunction
//Loop example using GIOL_Next:
// loop
// set index = GIOL_Next(mylist)
// exitwhen index == 0
// //...do stuff...
// endloop
//======
//Functions for code/trigger loops
//Loops over a list and executes the given trigger
//Stops after it enconters "until" number of elements
//If a negative "until" is specified, it will only stop when there are no more elements
//Sets the udg_Lists_Data, Instance and ListID variables to their correct values each time before running the trigger
function GIOL_ForEachCounted takes integer listKey, trigger trig, integer until returns nothing
local integer size = GIOL_SizeOf(listKey)
local integer newSize = size
local integer instance = 1
local integer count = 0
loop
exitwhen instance > newSize or count == until
set udg_Lists_Data= GIOL_Get(listKey, instance)
set udg_Lists_Instance = instance
set udg_Lists_ListID = listKey
if IsTriggerEnabled(trig) and TriggerEvaluate(trig) then
call TriggerExecute(trig)
endif
set newSize = GIOL_SizeOf(listKey)
if newSize == size then
set instance = instance + 1
else
set size = newSize
endif
set count = count + 1
endloop
endfunction
function GIOL_ForEach takes integer listKey, trigger trig returns nothing
call GIOL_ForEachCounted(listKey, trig, -1)
endfunction
//Same as GIOL_Loop, but executes the given code in a ForPlayer loop, instead of a trigger
//Added in version 1.1.0
function GIOL_ForEachCodeCounted takes integer listKey, code func, integer until returns nothing
local integer size = GIOL_SizeOf(listKey)
local integer newSize = size
local integer instance = 1
local integer count = 0
loop
exitwhen instance > newSize or count == until
set udg_Lists_Data= GIOL_Get(listKey, instance)
set udg_Lists_Instance = instance
set udg_Lists_ListID = listKey
call ForForce(bj_FORCE_PLAYER[0], func)
set newSize = GIOL_SizeOf(listKey)
if newSize == size then
set instance = instance + 1
else
set size = newSize
endif
set count = count + 1
endloop
endfunction
function GIOL_ForEachCode takes integer listKey, code func returns nothing
call GIOL_ForEachCodeCounted(listKey, func, -1)
endfunction
//==============
//System Initialization
//Initialzies GIOL if it has not been initialized
function GIOL_Initialize takes nothing returns nothing
if udg_Lists_Hashtable == null then
//Initialize dependencies
call GMUI_Initialize()
//Initialize Hashtable
set udg_Lists_Hashtable = InitHashtable()
//Get Recycle Key
set udg_Lists_RECYCLE_KEY = GMUI_CreateRecycleKey()
endif
endfunction
////////////////////////////////////////////////////////////////////////////////////////////////////
//End of Interateable Ordered Lists
////////////////////////////////////////////////////////////////////////////////////////////////////
//===========================================================================
//! novjass
function InitTrig_GIOL takes nothing returns nothing
endfunction
//! endnovjass
////////////////////////////////////////////////////////////////////////////////////////////////////
//Guhun's Iterateable Unordered Lists v.2.0.0
////////////////////////////////////////////////////////////////////////////////////////////////////
//==============
// Utilities (Private Functions)
function GIUL__SetSize takes integer listKey, integer recycleKey returns nothing
call SaveInteger(udg_Lists_Hashtable, listKey, 0, recycleKey)
endfunction
function GIUL__GetCurrent takes integer listKey returns integer
return LoadInteger(udg_GMUI_Hashtable, udg_Lists_RECYCLE_KEY, -listKey)
endfunction
function GIUL__SetCurrent takes integer listKey, integer current returns nothing
call SaveInteger(udg_GMUI_Hashtable, udg_Lists_RECYCLE_KEY, -listKey, current)
endfunction
function GIUL__ResetCurrent takes integer listKey returns nothing
call RemoveSavedInteger(udg_GMUI_Hashtable, udg_Lists_RECYCLE_KEY, -listKey)
endfunction
//==============================================
// System API
//==============================================
//==============
//Getters and Setters
//Gets data in specified index of a list
//Available since 2.0.0
function GIUL_Get takes integer listKey, integer index returns integer
return LoadInteger(udg_Lists_Hashtable, listKey, index)
endfunction
//Gets the size of a specified list
//Available since 2.0.0, replaced GetListSize
function GIUL_SizeOf takes integer listKey returns integer
return LoadInteger(udg_Lists_Hashtable, listKey, 0)
endfunction
//Sets the value stored inside a specified index
//Available since 2.0.0
function GIUL_Set takes integer listKey, integer index, integer data returns nothing
call SaveInteger(udg_Lists_Hashtable, listKey, index, data)
endfunction
//==============
//Getters and Setters
//Adds data to the end of a list and returns the index the data was added at (equal to size of the list)
//Available since 2.0.0, replaced GIUL_AddData
function GIUL_Append takes integer listKey, integer data returns integer
local integer size = GIUL_SizeOf(listKey) + 1
call SaveInteger(udg_Lists_Hashtable, listKey, size, data)
call GIUL__SetSize(listKey, size)
return size
endfunction
//Removes data from a certain index of a List
//Available since 2.0.0, replaced RemoveData
function GIUL_Remove takes integer listKey, integer index returns nothing
local integer size = GIUL_SizeOf(listKey)
call SaveInteger(udg_Lists_Hashtable, listKey, index, LoadInteger(udg_Lists_Hashtable, listKey, size))
call RemoveSavedInteger(udg_Lists_Hashtable, listKey, size)
call GIUL__SetSize(listKey, size - 1)
endfunction
//==============
//List creation and destruction
//Creates a new list and returns its ID
function GIUL_CreateList takes nothing returns integer
local integer listKey = GMUI_GetIndex(udg_Lists_RECYCLE_KEY)
call GIUL__SetSize(listKey, 0)
return listKey
endfunction
//Destroys the specified list
function GIUL_DestroyList takes integer listKey returns nothing
call FlushChildHashtable(udg_Lists_Hashtable, listKey)
call GIUL__ResetCurrent(listKey)
call GMUI_RecycleIndex(udg_Lists_RECYCLE_KEY, listKey)
endfunction
//==============
//Looping functionality
//======
//Functions for simplified looping
//Returns the next index of a list. If the index is 0, the end of the list has been reached.
//If you are using this function to loop, you should NOT use GIUL_Remove!
//Available since 2.0.0
function GIUL_Next takes integer listKey returns integer
local integer current = GIUL__GetCurrent(listKey)
if current < GIUL_SizeOf(listKey) then
call GIUL__SetCurrent(listKey, current+1)
return current+1
else
call GIUL__ResetCurrent(listKey)
return 0
endif
endfunction
//If you are iterating over a list using a GIUL_Next loop, you can use this function to remove the
//element in the index that you are currently at.
//Available since 2.0.0
function GIUL_RemoveCurrent takes integer listKey returns nothing
local integer current = LoadInteger(udg_GMUI_Hashtable, udg_Lists_RECYCLE_KEY, -listKey)
call GIUL_Remove(listKey, current)
call GIUL__SetCurrent(listKey, current-1)
endfunction
//Loop example using GIUL_Next:
// loop
// set index = GIUL_Next(mylist)
// exitwhen index == 0
// //...do stuff...
// endloop
//======
//Functions for code/trigger loops
//Loops over a list and executes the given trigger
//Stops after it enconters "until" number of elements
//If a negative "until" is specified, it will only stop when there are no more elements
//Sets the udg_Lists_Data, Instance and listKey variables to their correct values each time before running the trigger
function GIUL_ForEachCounted takes integer listKey, trigger trig, integer until returns nothing
local integer size = GIUL_SizeOf(listKey)
local integer newSize = size
local integer instance = 1
local integer count = 0
loop
exitwhen instance > newSize or count == until
set udg_Lists_Data= GIUL_Get(listKey, instance)
set udg_Lists_Instance = instance
set udg_Lists_ListID = listKey
if IsTriggerEnabled(trig) and TriggerEvaluate(trig) then
call TriggerExecute(trig)
endif
set newSize = GIUL_SizeOf(listKey)
if newSize == size then
set instance = instance + 1
else
set size = newSize
endif
set count = count + 1
endloop
endfunction
function GIUL_ForEach takes integer listKey, trigger trig returns nothing
call GIUL_ForEachCounted(listKey, trig, -1)
endfunction
//Same as GIUL_Loop, but executes the given code in a ForPlayer loop, instead of a trigger
//Added in version 1.1.0
function GIUL_ForEachCodeCounted takes integer listKey, code func, integer until returns nothing
local integer size = GIUL_SizeOf(listKey)
local integer newSize = size
local integer instance = 1
local integer count = 0
loop
exitwhen instance > newSize or count == until
set udg_Lists_Data= GIUL_Get(listKey, instance)
set udg_Lists_Instance = instance
set udg_Lists_ListID = listKey
call ForForce(bj_FORCE_PLAYER[0], func)
set newSize = GIUL_SizeOf(listKey)
if newSize == size then
set instance = instance + 1
else
set size = newSize
endif
set count = count + 1
endloop
endfunction
function GIUL_ForEachCode takes integer listKey, code func returns nothing
call GIUL_ForEachCodeCounted(listKey, func, -1)
endfunction
//==============
//System Initialization
//Initializes GIUL if it has not yet been initialized.
function GIUL_Initialize takes nothing returns nothing
if udg_Lists_Hashtable == null then
//Initialize dependencies
call GMUI_Initialize()
//Initialize Hashtable
set udg_Lists_Hashtable = InitHashtable()
//Get Recycle Key
set udg_Lists_RECYCLE_KEY = GMUI_CreateRecycleKey()
endif
endfunction
////////////////////////////////////////////////////////////////////////////////////////////////////
//End of Interateable Unordered Lists
////////////////////////////////////////////////////////////////////////////////////////////////////
//===========================================================================
//! novjass
function InitTrig_GIUL takes nothing returns nothing
endfunction
//! endnovjass
////////////////////////////////////////////////////////////////////////////////////////////////////
//GLL : Guhun's Ordered Sets v.1.2.0
// An implementation of an ordered set with a linked list backend. AKA. LinkedHashSet.
////////////////////////////////////////////////////////////////////////////////////////////////////
//==============
// Utilities (Private functions)
// If a negative setKey is specified, this will actually set the previous element of the positive setKey
function GLL__SetNext takes integer setKey, integer data, integer next returns nothing
call SaveInteger(udg_Lists_Hashtable, setKey, data, next)
endfunction
// If a negative setKey is specified, this will actually set the next element of the positive setKey
function GLL__SetPrev takes integer setKey, integer data, integer prev returns nothing
call SaveInteger(udg_Lists_Hashtable, -setKey, data, prev)
endfunction
// These functions clear the link data of an element (used to remove stuff from the list)
function GLL__ClearNext takes integer setKey, integer data returns nothing
call RemoveSavedInteger(udg_Lists_Hashtable, setKey, data)
endfunction
function GLL__ClearPrev takes integer setKey, integer data returns nothing
call RemoveSavedInteger(udg_Lists_Hashtable, -setKey, data)
endfunction
//==============================================
// System API
//==============================================
//==============
// Set Navigation
//Returns the next element after the specified "data" in the set
//To get the first element, pass "0" as the parameter "data"
function GLL_GetNext takes integer setKey, integer data returns integer
return LoadInteger(udg_Lists_Hashtable, setKey, data)
endfunction
//Returns the element that preceeds the specified "data" in the set
//To get the last element, pass "0" as the parameter "data"
function GLL_GetPrev takes integer setKey, integer data returns integer
return LoadInteger(udg_Lists_Hashtable, -setKey, data)
endfunction
//Returns the first element of a set
//Available since 1.2.0
function GLL_FirstOf takes integer setKey returns integer
return GLL_GetNext(setKey, 0)
endfunction
//Returns the last element of a set
//Available since 1.2.0
function GLL_LastOf takes integer setKey returns integer
return GLL_GetPrev(setKey, 0)
endfunction
//Returns whether a set contains the specified data or not
function GLL_ListHasData takes integer setKey, integer data returns boolean
return HaveSavedInteger(udg_Lists_Hashtable, setKey, data)
endfunction
//Returns wheter there are any elements in a set
//Available since 1.2.0
function GLL_IsEmpty takes integer setKey returns boolean
return GLL_FirstOf(setKey) == 0
endfunction
//Returns the number of elements contained in a set
//Available since 1.2.0
function GLL_SizeOf takes integer setKey returns integer
local integer data = GLL_FirstOf(setKey)
local integer count = 0
loop
exitwhen data == 0
set count = count + 1
endloop
return count
endfunction
//==============
// Element Addition/Removal
//Adds an element to a set, in the position preceeding the element passed as the second parameter
//If data is already present in set, behaviour is undefined
function GLL_AddData takes integer setKey, integer next, integer data returns nothing
local integer prev = GLL_GetPrev(setKey, next)
call GLL__SetNext(setKey, prev, data)
call GLL__SetPrev(setKey, next, data)
call GLL__SetNext(setKey, data, next)
call GLL__SetPrev(setKey, data, prev)
endfunction
//Adds an element to a set, in the position following the element passed as the second parameter
//Available since 1.2.0
function GLL_AddDataAfter takes integer setKey, integer prev, integer data returns nothing
call GLL_AddData(-setKey, prev, data)
endfunction
//Adds an element to the end of the set
//Available since 1.2.0
function GLL_Append takes integer setKey, integer data returns nothing
call GLL_AddData(setKey, 0, data)
endfunction
//Adds an element to the beginning of the set
//Available since 1.2.0
function GLL_Prepend takes integer setKey, integer data returns nothing
call GLL_Append(-setKey, data)
endfunction
//Removes the given element from a set
//If data is not present in Set, behaviour is undefined
function GLL_RemoveData takes integer setKey, integer data returns nothing
local integer next = GLL_GetNext(setKey, data)
local integer prev = GLL_GetPrev(setKey, data)
call GLL__SetPrev(setKey, next, prev)
call GLL__SetNext(setKey, prev, next)
call GLL__ClearNext(setKey, data)
call GLL__ClearPrev(-setKey, data)
endfunction
//==============
// Set Creation/Destruction
//Creates a new set and returns its ID/key
function GLL_CreateList takes nothing returns integer
local integer listId = GMUI_GetIndex(udg_Lists_RECYCLE_KEY)
call SaveInteger(udg_Lists_Hashtable, listId, 0, 0)
call SaveInteger(udg_Lists_Hashtable, -listId, 0, 0)
return listId
endfunction
//Destroys the specified set
function GLL_DestroyList takes integer listId returns nothing
call FlushChildHashtable(udg_Lists_Hashtable, listId)
call FlushChildHashtable(udg_Lists_Hashtable, -listId)
call GMUI_RecycleIndex(udg_Lists_RECYCLE_KEY, listId)
endfunction
//==============
// Looping Functionality
// If you want to execute a backwards loop, pass the opposite (negative) of the setKey.
//This function loops through a Set and executes a trigger for each element, setting the udg_List variables to their relevant equivalents each time
//If until is a non-negative number, then the loop will break after iterating over that many elements
function GLL_Loop takes integer setKey, trigger trig, integer until returns nothing
local integer data = GLL_FirstOf(setKey)
local integer count = 0
loop
exitwhen data == 0 or count == until
set udg_Lists_Data= data
set udg_Lists_ListID = setKey
set data = GLL_GetNext(setKey, data)
if IsTriggerEnabled(trig) and TriggerEvaluate(trig) then
call TriggerExecute(trig)
endif
set count = count + 1
endloop
endfunction
//Works like GLL_Loop, but is more efficient if you want to loop over all elements
//Available since 1.2.0
function GLL_LoopAll takes integer setKey, trigger trig returns nothing
local integer data = GLL_FirstOf(setKey)
loop
exitwhen data == 0
set udg_Lists_Data= data
set udg_Lists_ListID = setKey
set data = GLL_GetNext(setKey, data)
if IsTriggerEnabled(trig) and TriggerEvaluate(trig) then
call TriggerExecute(trig)
endif
endloop
endfunction
//Same as GLL_Loop, however, you may specify a code that will run in a ForPlayer loop instead of a trigger
//If until is a non-negative number, then the loop will break after iterating over that many elements
//Added in version 1.1.0
function GLL_CodeLoop takes integer setKey, code func, integer until returns nothing
local integer data = GLL_FirstOf(setKey)
local integer count = 0
loop
exitwhen data == 0 or count == until
set udg_Lists_Data= data
set udg_Lists_ListID = setKey
set data = GLL_GetNext(setKey, data)
call ForForce(bj_FORCE_PLAYER[0], func)
set count = count + 1
endloop
endfunction
//Works like GLL_CodeLoop, but is more efficient if you want to loop over all elements
//Available since 1.2.0
function GLL_CodeLoopAll takes integer setKey, code func returns nothing
local integer data = GLL_FirstOf(setKey)
loop
exitwhen data == 0
set udg_Lists_Data= data
set udg_Lists_ListID = setKey
set data = GLL_GetNext(setKey, data)
call ForForce(bj_FORCE_PLAYER[0], func)
endloop
endfunction
//Loops over a set from the value following "start" to the value preceding "finish" (or the end of the list, whichever comes first)
//Each iteration sets Lists_Data to the current value and then runs the specified code in a ForForce loop
//Added in version 1.1.0
function GLL_ClearList takes integer setKey, integer start, integer finish, code func returns integer
local integer data = GLL_GetNext(setKey, start)
local integer nextData
local integer countRemoved = 0
loop
exitwhen data == finish or data == 0
set nextData = GLL_GetNext(setKey, data)
call GLL__ClearNext(setKey, data)
call GLL__ClearPrev(-setKey, data)
set udg_Lists_Data = data
set udg_Lists_ListID = setKey
call ForForce(bj_FORCE_PLAYER[0], func)
set data = nextData
set countRemoved = countRemoved + 1
endloop
call GLL__SetPrev(setKey, data, start)
call GLL__SetNext(setKey, start, data)
return countRemoved
endfunction
//==============
// System initialization
//This function initializes GLL if it has not yet been initialized
function GLL_Initialize takes nothing returns nothing
if udg_Lists_Hashtable == null then
//Initialize dependencies
call GMUI_Initialize()
//Initialize Hashtable
set udg_Lists_Hashtable = InitHashtable()
//Get Recycle Key
set udg_Lists_RECYCLE_KEY = GMUI_CreateRecycleKey()
endif
endfunction
////////////////////////////////////////////////////////////////////////////////////////////////////
//End of Ordered Sets
////////////////////////////////////////////////////////////////////////////////////////////////////
//===========================================================================
//! novjass
function InitTrig_GLL takes nothing returns nothing
endfunction
//! endnovjass
////////////////////////////////////////////////////////
//Guhun's MUI Engine version 2.0.0
////////////////////////////////////////////////////////
//This code generates an instance number for a RecycleKey
function GMUI_GetIndex takes integer RecycleKey returns integer
local integer instance
set instance = LoadInteger(udg_GMUI_Hashtable, RecycleKey, 0)
if not HaveSavedInteger(udg_GMUI_Hashtable, RecycleKey, instance) then
call SaveInteger(udg_GMUI_Hashtable, RecycleKey, 0, instance + 1)
else
call SaveInteger(udg_GMUI_Hashtable, RecycleKey, 0, LoadInteger(udg_GMUI_Hashtable, RecycleKey, instance))
call RemoveSavedInteger(udg_GMUI_Hashtable, RecycleKey, instance)
endif
return instance
endfunction
//This code generates recycles a used instance number for a RecycleKey
function GMUI_RecycleIndex takes integer RecycleKey, integer instance returns nothing
call SaveInteger(udg_GMUI_Hashtable, RecycleKey, instance, LoadInteger(udg_GMUI_Hashtable, RecycleKey, 0))
call SaveInteger(udg_GMUI_Hashtable, RecycleKey, 0, instance)
endfunction
//This code generates a new, unused, RecycleKey
function GMUI_CreateRecycleKey takes nothing returns integer
local integer newKey = GMUI_GetIndex(0)
call SaveInteger(udg_GMUI_Hashtable, newKey, 0, 1)
return newKey
endfunction
//This code recycles a used RecycleKey
function GMUI_DestroyRecycleKey takes integer whichKey returns nothing
if whichKey == 0 then
return
endif
call GMUI_RecycleIndex(0, whichKey)
call FlushChildHashtable(udg_GMUI_Hashtable, whichKey)
endfunction
//This function initializes GMUI if it has not yet been initialized
function GMUI_Initialize takes nothing returns nothing
if udg_GMUI_Hashtable == null then
//Initialize Hashtable
set udg_GMUI_Hashtable = InitHashtable()
//Initialize the recycling algorithm for Recycle Keys
call SaveInteger(udg_GMUI_Hashtable, 0, 0, 1)
//Initialize the generic Recycle Key
call GMUI_CreateRecycleKey() //Will always be 1
endif
endfunction
////////////////////////////////////////////////////////
//End of MUI Engine
////////////////////////////////////////////////////////
function Trig_GMUI_Main_Actions takes nothing returns nothing
if udg_GMUI_RecycleKey == 0 then
set udg_GMUI_RecycleKey = GMUI_CreateRecycleKey()
else
call GMUI_DestroyRecycleKey(udg_GMUI_RecycleKey)
endif
endfunction
function Trig_GMUI_Main_Conditions takes nothing returns boolean
if udg_GMUI_Index == 0 then
set udg_GMUI_Index = GMUI_GetIndex(udg_GMUI_RecycleKey)
else
call GMUI_RecycleIndex(udg_GMUI_RecycleKey, udg_GMUI_Index)
endif
return false
endfunction
//===========================================================================
function InitTrig_GMUI_Main takes nothing returns nothing
call GMUI_Initialize()
//Create Trigger for GUI users
set gg_trg_GMUI_Main = CreateTrigger( )
call TriggerAddAction( gg_trg_GMUI_Main, function Trig_GMUI_Main_Actions )
call TriggerAddCondition(gg_trg_GMUI_Main, Condition(function Trig_GMUI_Main_Conditions))
endfunction
////////////////////////////////////////////////////////////////////////////////////////////////////
//Guhun's Iterateable Ordered Lists v.2.0.0
////////////////////////////////////////////////////////////////////////////////////////////////////
//==============================================
// System API
//==============================================
//==============
//Getters and Setters
//Gets data in specified index of a list
//Available since 2.0.0
function GIOL_Get takes integer listKey,integer index returns integer
return LoadInteger(udg_Lists_Hashtable, listKey, index)
endfunction
//Gets the size of a specified list
//Available since 2.0.0, replaced GetListSize
function GIOL_SizeOf takes integer listKey returns integer
return LoadInteger(udg_Lists_Hashtable, listKey, 0)
endfunction
//Sets the value stored inside a specified index
//Available since 2.0.0
function GIOL_Set takes integer listKey,integer index,integer data returns nothing
call SaveInteger(udg_Lists_Hashtable, listKey, index, data)
endfunction
//Adds data to the end of a list and returns the index the data was added at (equal to size of the list)
//Available since 2.0.0, replaced GIUL_AddData
function GIOL_Append takes integer listKey,integer data returns integer
local integer size= (LoadInteger(udg_Lists_Hashtable, (listKey), 0)) + 1 // INLINED!!
call SaveInteger(udg_Lists_Hashtable, (listKey ), ( size ), ( data)) // INLINED!!
call SaveInteger(udg_Lists_Hashtable, (listKey ), 0, ( size)) // INLINED!!
return size
endfunction
//Removes data from a certain index of a List
//Available since 2.0.0, replaced RemoveData
function GIOL_Remove takes integer listKey,integer instance returns nothing
local integer size= (LoadInteger(udg_Lists_Hashtable, (listKey), 0)) // INLINED!!
loop
exitwhen instance > size
call SaveInteger(udg_Lists_Hashtable, (listKey ), ( instance - 1 ), ( (LoadInteger(udg_Lists_Hashtable, (listKey ), ( instance))))) // INLINED!!
set instance=instance + 1
endloop
call RemoveSavedInteger(udg_Lists_Hashtable, listKey, size)
call SaveInteger(udg_Lists_Hashtable, (listKey ), 0, ( size - 1)) // INLINED!!
endfunction
//==============
//List creation and destruction
//Creates a list and returns its list key/list ID
function GIOL_CreateList takes nothing returns integer
local integer listKey= GMUI_GetIndex(udg_Lists_RECYCLE_KEY)
call SaveInteger(udg_Lists_Hashtable, (listKey ), 0, ( 0)) // INLINED!!
return listKey
endfunction
//Destroys the specified list
function GIOL_DestroyList takes integer listKey returns nothing
call FlushChildHashtable(udg_Lists_Hashtable, listKey)
call RemoveSavedInteger(udg_GMUI_Hashtable, udg_Lists_RECYCLE_KEY, - (listKey)) // INLINED!!
call GMUI_RecycleIndex(udg_Lists_RECYCLE_KEY , listKey)
endfunction
//======
//Functions for simplified looping
//If you are using this function to loop, you should NOT use GIUL_Remove!
//Available since 2.0.0
function GIOL_Next takes integer listKey returns integer
local integer current= (LoadInteger(udg_GMUI_Hashtable, udg_Lists_RECYCLE_KEY, - (listKey))) // INLINED!!
if current < (LoadInteger(udg_Lists_Hashtable, (listKey), 0)) then // INLINED!!
call SaveInteger(udg_GMUI_Hashtable, udg_Lists_RECYCLE_KEY, - (listKey ), ( current + 1)) // INLINED!!
return current + 1
else
call RemoveSavedInteger(udg_GMUI_Hashtable, udg_Lists_RECYCLE_KEY, - (listKey)) // INLINED!!
return 0
endif
endfunction
//If you are iterating over a list using a GIUL_Next loop, you can use this function to remove the
//element in the index that you are currently at.
//Available since 2.0.0
function GIOL_RemoveCurrent takes integer listKey returns nothing
local integer current= (LoadInteger(udg_GMUI_Hashtable, udg_Lists_RECYCLE_KEY, - (listKey))) // INLINED!!
call GIOL_Remove(listKey , current)
call SaveInteger(udg_GMUI_Hashtable, udg_Lists_RECYCLE_KEY, - (listKey ), ( current - 1)) // INLINED!!
endfunction
//Loop example using GIUL_Next:
// loop
// set index = GIUL_Next(mylist)
// exitwhen index == 0
// //...do stuff...
// endloop
//======
//Functions for code/trigger loops
//Loops over a list and executes the given trigger
//Stops after it enconters "until" number of elements
//If a negative "until" is specified, it will only stop when there are no more elements
//Sets the udg_Lists_Data, Instance and ListID variables to their correct values each time before running the trigger
function GIOL_ForEachCounted takes integer listKey,trigger trig,integer until returns nothing
local integer size= (LoadInteger(udg_Lists_Hashtable, (listKey), 0)) // INLINED!!
local integer newSize= size
local integer instance= 1
local integer count= 0
loop
exitwhen instance > newSize or count == until
set udg_Lists_Data=(LoadInteger(udg_Lists_Hashtable, (listKey ), ( instance))) // INLINED!!
set udg_Lists_Instance=instance
set udg_Lists_ListID=listKey
if IsTriggerEnabled(trig) and TriggerEvaluate(trig) then
call TriggerExecute(trig)
endif
set newSize=(LoadInteger(udg_Lists_Hashtable, (listKey), 0)) // INLINED!!
if newSize == size then
set instance=instance + 1
else
set size=newSize
endif
set count=count + 1
endloop
endfunction
function GIOL_ForEach takes integer listKey,trigger trig returns nothing
call GIOL_ForEachCounted(listKey , trig , - 1)
endfunction
//Same as GIOL_Loop, but executes the given code in a ForPlayer loop, instead of a trigger
//Added in version 1.1.0
function GIOL_ForEachCodeCounted takes integer listKey,code func,integer until returns nothing
local integer size= (LoadInteger(udg_Lists_Hashtable, (listKey), 0)) // INLINED!!
local integer newSize= size
local integer instance= 1
local integer count= 0
loop
exitwhen instance > newSize or count == until
set udg_Lists_Data=(LoadInteger(udg_Lists_Hashtable, (listKey ), ( instance))) // INLINED!!
set udg_Lists_Instance=instance
set udg_Lists_ListID=listKey
call ForForce(bj_FORCE_PLAYER[0], func)
set newSize=(LoadInteger(udg_Lists_Hashtable, (listKey), 0)) // INLINED!!
if newSize == size then
set instance=instance + 1
else
set size=newSize
endif
set count=count + 1
endloop
endfunction
function GIOL_ForEachCode takes integer listKey,code func returns nothing
call GIOL_ForEachCodeCounted(listKey , func , - 1)
endfunction
//==============
//System Initialization
//Initialzies GIOL if it has not been initialized
function GIOL_Initialize takes nothing returns nothing
if udg_Lists_Hashtable == null then
//Initialize dependencies
call GMUI_Initialize()
//Initialize Hashtable
set udg_Lists_Hashtable=InitHashtable()
//Get Recycle Key
set udg_Lists_RECYCLE_KEY=GMUI_CreateRecycleKey()
endif
endfunction
////////////////////////////////////////////////////////////////////////////////////////////////////
//End of Interateable Ordered Lists
////////////////////////////////////////////////////////////////////////////////////////////////////
function Trig_GIOL_Main_Actions takes nothing returns nothing
if udg_Lists_ListID == 0 then
set udg_Lists_ListID = GIOL_CreateList()
else
call GIOL_DestroyList(udg_Lists_ListID)
endif
endfunction
function Trig_GIOL_Main_Conditions takes nothing returns boolean
if udg_Lists_Instance == 0 then
set udg_Lists_Instance = GIOL_Append(udg_Lists_ListID, udg_Lists_Data)
else
call GIOL_Remove(udg_Lists_ListID, udg_Lists_Instance)
endif
return false
endfunction
//===========================================================================
function InitTrig_GIOL_Main takes nothing returns nothing
call GIOL_Initialize()
set gg_trg_GIOL_Main = CreateTrigger( )
call TriggerAddAction( gg_trg_GIOL_Main, function Trig_GIOL_Main_Actions )
call TriggerAddCondition( gg_trg_GIOL_Main, Condition(function Trig_GIOL_Main_Conditions))
endfunction
////////////////////////////////////////////////////////////////////////////////////////////////////
//Guhun's Iterateable Unordered Lists v.2.0.0
////////////////////////////////////////////////////////////////////////////////////////////////////
//==============================================
// System API
//==============================================
//==============
//Getters and Setters
//Gets data in specified index of a list
//Available since 2.0.0
function GIUL_Get takes integer listKey,integer index returns integer
return LoadInteger(udg_Lists_Hashtable, listKey, index)
endfunction
//Gets the size of a specified list
//Available since 2.0.0, replaced GetListSize
function GIUL_SizeOf takes integer listKey returns integer
return LoadInteger(udg_Lists_Hashtable, listKey, 0)
endfunction
//Sets the value stored inside a specified index
//Available since 2.0.0
function GIUL_Set takes integer listKey,integer index,integer data returns nothing
call SaveInteger(udg_Lists_Hashtable, listKey, index, data)
endfunction
//==============
//Getters and Setters
//Adds data to the end of a list and returns the index the data was added at (equal to size of the list)
//Available since 2.0.0, replaced GIUL_AddData
function GIUL_Append takes integer listKey,integer data returns integer
local integer size= (LoadInteger(udg_Lists_Hashtable, (listKey), 0)) + 1 // INLINED!!
call SaveInteger(udg_Lists_Hashtable, listKey, size, data)
call SaveInteger(udg_Lists_Hashtable, (listKey ), 0, ( size)) // INLINED!!
return size
endfunction
//Removes data from a certain index of a List
//Available since 2.0.0, replaced RemoveData
function GIUL_Remove takes integer listKey,integer index returns nothing
local integer size= (LoadInteger(udg_Lists_Hashtable, (listKey), 0)) // INLINED!!
call SaveInteger(udg_Lists_Hashtable, listKey, index, LoadInteger(udg_Lists_Hashtable, listKey, size))
call RemoveSavedInteger(udg_Lists_Hashtable, listKey, size)
call SaveInteger(udg_Lists_Hashtable, (listKey ), 0, ( size - 1)) // INLINED!!
endfunction
//==============
//List creation and destruction
//Creates a new list and returns its ID
function GIUL_CreateList takes nothing returns integer
local integer listKey= GMUI_GetIndex(udg_Lists_RECYCLE_KEY)
call SaveInteger(udg_Lists_Hashtable, (listKey ), 0, ( 0)) // INLINED!!
return listKey
endfunction
//Destroys the specified list
function GIUL_DestroyList takes integer listKey returns nothing
call FlushChildHashtable(udg_Lists_Hashtable, listKey)
call RemoveSavedInteger(udg_GMUI_Hashtable, udg_Lists_RECYCLE_KEY, - (listKey)) // INLINED!!
call GMUI_RecycleIndex(udg_Lists_RECYCLE_KEY , listKey)
endfunction
//==============
//Looping functionality
//======
//Functions for simplified looping
//If you are using this function to loop, you should NOT use GIUL_Remove!
//Available since 2.0.0
function GIUL_Next takes integer listKey returns integer
local integer current= (LoadInteger(udg_GMUI_Hashtable, udg_Lists_RECYCLE_KEY, - (listKey))) // INLINED!!
if current < (LoadInteger(udg_Lists_Hashtable, (listKey), 0)) then // INLINED!!
call SaveInteger(udg_GMUI_Hashtable, udg_Lists_RECYCLE_KEY, - (listKey ), ( current + 1)) // INLINED!!
return current + 1
else
call RemoveSavedInteger(udg_GMUI_Hashtable, udg_Lists_RECYCLE_KEY, - (listKey)) // INLINED!!
return 0
endif
endfunction
//If you are iterating over a list using a GIUL_Next loop, you can use this function to remove the
//element in the index that you are currently at.
//Available since 2.0.0
function GIUL_RemoveCurrent takes integer listKey returns nothing
local integer current= LoadInteger(udg_GMUI_Hashtable, udg_Lists_RECYCLE_KEY, - listKey)
call GIUL_Remove(listKey , current)
call SaveInteger(udg_GMUI_Hashtable, udg_Lists_RECYCLE_KEY, - (listKey ), ( current - 1)) // INLINED!!
endfunction
//Loop example using GIUL_Next:
// loop
// set index = GIUL_Next(mylist)
// exitwhen index == 0
// //...do stuff...
// endloop
//======
//Functions for code/trigger loops
//Loops over a list and executes the given trigger
//Stops after it enconters "until" number of elements
//If a negative "until" is specified, it will only stop when there are no more elements
//Sets the udg_Lists_Data, Instance and listKey variables to their correct values each time before running the trigger
function GIUL_ForEachCounted takes integer listKey,trigger trig,integer until returns nothing
local integer size= (LoadInteger(udg_Lists_Hashtable, (listKey), 0)) // INLINED!!
local integer newSize= size
local integer instance= 1
local integer count= 0
loop
exitwhen instance > newSize or count == until
set udg_Lists_Data=(LoadInteger(udg_Lists_Hashtable, (listKey ), ( instance))) // INLINED!!
set udg_Lists_Instance=instance
set udg_Lists_ListID=listKey
if IsTriggerEnabled(trig) and TriggerEvaluate(trig) then
call TriggerExecute(trig)
endif
set newSize=(LoadInteger(udg_Lists_Hashtable, (listKey), 0)) // INLINED!!
if newSize == size then
set instance=instance + 1
else
set size=newSize
endif
set count=count + 1
endloop
endfunction
function GIUL_ForEach takes integer listKey,trigger trig returns nothing
call GIUL_ForEachCounted(listKey , trig , - 1)
endfunction
//Same as GIUL_Loop, but executes the given code in a ForPlayer loop, instead of a trigger
//Added in version 1.1.0
function GIUL_ForEachCodeCounted takes integer listKey,code func,integer until returns nothing
local integer size= (LoadInteger(udg_Lists_Hashtable, (listKey), 0)) // INLINED!!
local integer newSize= size
local integer instance= 1
local integer count= 0
loop
exitwhen instance > newSize or count == until
set udg_Lists_Data=(LoadInteger(udg_Lists_Hashtable, (listKey ), ( instance))) // INLINED!!
set udg_Lists_Instance=instance
set udg_Lists_ListID=listKey
call ForForce(bj_FORCE_PLAYER[0], func)
set newSize=(LoadInteger(udg_Lists_Hashtable, (listKey), 0)) // INLINED!!
if newSize == size then
set instance=instance + 1
else
set size=newSize
endif
set count=count + 1
endloop
endfunction
function GIUL_ForEachCode takes integer listKey,code func returns nothing
call GIUL_ForEachCodeCounted(listKey , func , - 1)
endfunction
//==============
//System Initialization
//Initializes GIUL if it has not yet been initialized.
function GIUL_Initialize takes nothing returns nothing
if udg_Lists_Hashtable == null then
//Initialize dependencies
call GMUI_Initialize()
//Initialize Hashtable
set udg_Lists_Hashtable=InitHashtable()
//Get Recycle Key
set udg_Lists_RECYCLE_KEY=GMUI_CreateRecycleKey()
endif
endfunction
////////////////////////////////////////////////////////////////////////////////////////////////////
//End of Interateable Unordered Lists
////////////////////////////////////////////////////////////////////////////////////////////////////
function Trig_GIUL_Main_Actions takes nothing returns nothing
if udg_Lists_ListID == 0 then
set udg_Lists_ListID = GIUL_CreateList()
else
call GIUL_DestroyList(udg_Lists_ListID)
endif
endfunction
function Trig_GIUL_Main_Conditions takes nothing returns boolean
if udg_Lists_Instance == 0 then
set udg_Lists_Instance = GIUL_Append(udg_Lists_ListID, udg_Lists_Data)
else
call GIUL_Remove(udg_Lists_ListID, udg_Lists_Instance)
endif
return false
endfunction
//===========================================================================
function InitTrig_GIUL_Main takes nothing returns nothing
call GIUL_Initialize()
set gg_trg_GIUL_Main = CreateTrigger( )
call TriggerAddAction( gg_trg_GIUL_Main, function Trig_GIUL_Main_Actions )
call TriggerAddCondition( gg_trg_GIUL_Main, Condition(function Trig_GIUL_Main_Conditions))
endfunction
////////////////////////////////////////////////////////////////////////////////////////////////////
//GLL : Guhun's Ordered Sets v.1.2.0
// An implementation of an ordered set with a linked list backend. AKA. LinkedHashSet.
////////////////////////////////////////////////////////////////////////////////////////////////////
//==============================================
// System API
//==============================================
//==============
// Set Navigation
//Returns the next element after the specified "data" in the set
//To get the first element, pass "0" as the parameter "data"
function GLL_GetNext takes integer setKey,integer data returns integer
return LoadInteger(udg_Lists_Hashtable, setKey, data)
endfunction
//Returns the element that preceeds the specified "data" in the set
//To get the last element, pass "0" as the parameter "data"
function GLL_GetPrev takes integer setKey,integer data returns integer
return LoadInteger(udg_Lists_Hashtable, - setKey, data)
endfunction
//Returns the first element of a set
//Available since 1.2.0
function GLL_FirstOf takes integer setKey returns integer
return (LoadInteger(udg_Lists_Hashtable, (setKey ), ( 0))) // INLINED!!
endfunction
//Returns the last element of a set
//Available since 1.2.0
function GLL_LastOf takes integer setKey returns integer
return (LoadInteger(udg_Lists_Hashtable, - (setKey ), ( 0))) // INLINED!!
endfunction
//Returns whether a set contains the specified data or not
function GLL_ListHasData takes integer setKey,integer data returns boolean
return HaveSavedInteger(udg_Lists_Hashtable, setKey, data)
endfunction
//Returns wheter there are any elements in a set
//Available since 1.2.0
function GLL_IsEmpty takes integer setKey returns boolean
return (LoadInteger(udg_Lists_Hashtable, ((setKey) ), ( 0))) == 0 // INLINED!!
endfunction
//Returns the number of elements contained in a set
//Available since 1.2.0
function GLL_SizeOf takes integer setKey returns integer
local integer data= (LoadInteger(udg_Lists_Hashtable, ((setKey) ), ( 0))) // INLINED!!
local integer count= 0
loop
exitwhen data == 0
set count=count + 1
endloop
return count
endfunction
//==============
// Element Addition/Removal
//Adds an element to a set, in the position preceeding the element passed as the second parameter
//If data is already present in set, behaviour is undefined
function GLL_AddData takes integer setKey,integer next,integer data returns nothing
local integer prev= (LoadInteger(udg_Lists_Hashtable, - (setKey ), ( next))) // INLINED!!
call SaveInteger(udg_Lists_Hashtable, (setKey ), ( prev ), ( data)) // INLINED!!
call SaveInteger(udg_Lists_Hashtable, - (setKey ), ( next ), ( data)) // INLINED!!
call SaveInteger(udg_Lists_Hashtable, (setKey ), ( data ), ( next)) // INLINED!!
call SaveInteger(udg_Lists_Hashtable, - (setKey ), ( data ), ( prev)) // INLINED!!
endfunction
//Adds an element to a set, in the position following the element passed as the second parameter
//Available since 1.2.0
function GLL_AddDataAfter takes integer setKey,integer prev,integer data returns nothing
call GLL_AddData(- setKey , prev , data)
endfunction
//Adds an element to the end of the set
//Available since 1.2.0
function GLL_Append takes integer setKey,integer data returns nothing
call GLL_AddData(setKey , 0 , data)
endfunction
//Adds an element to the beginning of the set
//Available since 1.2.0
function GLL_Prepend takes integer setKey,integer data returns nothing
call GLL_AddData((- setKey ) , 0 , ( data)) // INLINED!!
endfunction
//Removes the given element from a set
//If data is not present in Set, behaviour is undefined
function GLL_RemoveData takes integer setKey,integer data returns nothing
local integer next= (LoadInteger(udg_Lists_Hashtable, (setKey ), ( data))) // INLINED!!
local integer prev= (LoadInteger(udg_Lists_Hashtable, - (setKey ), ( data))) // INLINED!!
call SaveInteger(udg_Lists_Hashtable, - (setKey ), ( next ), ( prev)) // INLINED!!
call SaveInteger(udg_Lists_Hashtable, (setKey ), ( prev ), ( next)) // INLINED!!
call RemoveSavedInteger(udg_Lists_Hashtable, (setKey ), ( data)) // INLINED!!
call RemoveSavedInteger(udg_Lists_Hashtable, - (- setKey ), ( data)) // INLINED!!
endfunction
//==============
// Set Creation/Destruction
//Creates a new set and returns its ID/key
function GLL_CreateList takes nothing returns integer
local integer listId= GMUI_GetIndex(udg_Lists_RECYCLE_KEY)
call SaveInteger(udg_Lists_Hashtable, listId, 0, 0)
call SaveInteger(udg_Lists_Hashtable, - listId, 0, 0)
return listId
endfunction
//Destroys the specified set
function GLL_DestroyList takes integer listId returns nothing
call FlushChildHashtable(udg_Lists_Hashtable, listId)
call FlushChildHashtable(udg_Lists_Hashtable, - listId)
call GMUI_RecycleIndex(udg_Lists_RECYCLE_KEY , listId)
endfunction
//==============
// Looping Functionality
// If you want to execute a backwards loop, pass the opposite (negative) of the setKey.
//This function loops through a Set and executes a trigger for each element, setting the udg_List variables to their relevant equivalents each time
//If until is a non-negative number, then the loop will break after iterating over that many elements
function GLL_Loop takes integer setKey,trigger trig,integer until returns nothing
local integer data= (LoadInteger(udg_Lists_Hashtable, ((setKey) ), ( 0))) // INLINED!!
local integer count= 0
loop
exitwhen data == 0 or count == until
set udg_Lists_Data=data
set udg_Lists_ListID=setKey
set data=(LoadInteger(udg_Lists_Hashtable, (setKey ), ( data))) // INLINED!!
if IsTriggerEnabled(trig) and TriggerEvaluate(trig) then
call TriggerExecute(trig)
endif
set count=count + 1
endloop
endfunction
//Works like GLL_Loop, but is more efficient if you want to loop over all elements
//Available since 1.2.0
function GLL_LoopAll takes integer setKey,trigger trig returns nothing
local integer data= (LoadInteger(udg_Lists_Hashtable, ((setKey) ), ( 0))) // INLINED!!
loop
exitwhen data == 0
set udg_Lists_Data=data
set udg_Lists_ListID=setKey
set data=(LoadInteger(udg_Lists_Hashtable, (setKey ), ( data))) // INLINED!!
if IsTriggerEnabled(trig) and TriggerEvaluate(trig) then
call TriggerExecute(trig)
endif
endloop
endfunction
//Same as GLL_Loop, however, you may specify a code that will run in a ForPlayer loop instead of a trigger
//If until is a non-negative number, then the loop will break after iterating over that many elements
//Added in version 1.1.0
function GLL_CodeLoop takes integer setKey,code func,integer until returns nothing
local integer data= (LoadInteger(udg_Lists_Hashtable, ((setKey) ), ( 0))) // INLINED!!
local integer count= 0
loop
exitwhen data == 0 or count == until
set udg_Lists_Data=data
set udg_Lists_ListID=setKey
set data=(LoadInteger(udg_Lists_Hashtable, (setKey ), ( data))) // INLINED!!
call ForForce(bj_FORCE_PLAYER[0], func)
set count=count + 1
endloop
endfunction
//Works like GLL_CodeLoop, but is more efficient if you want to loop over all elements
//Available since 1.2.0
function GLL_CodeLoopAll takes integer setKey,code func returns nothing
local integer data= (LoadInteger(udg_Lists_Hashtable, ((setKey) ), ( 0))) // INLINED!!
loop
exitwhen data == 0
set udg_Lists_Data=data
set udg_Lists_ListID=setKey
set data=(LoadInteger(udg_Lists_Hashtable, (setKey ), ( data))) // INLINED!!
call ForForce(bj_FORCE_PLAYER[0], func)
endloop
endfunction
//Loops over a set from the value following "start" to the value preceding "finish" (or the end of the list, whichever comes first)
//Each iteration sets Lists_Data to the current value and then runs the specified code in a ForForce loop
//Added in version 1.1.0
function GLL_ClearList takes integer setKey,integer start,integer finish,code func returns integer
local integer data= (LoadInteger(udg_Lists_Hashtable, (setKey ), ( start))) // INLINED!!
local integer nextData
local integer countRemoved= 0
loop
exitwhen data == finish or data == 0
set nextData=(LoadInteger(udg_Lists_Hashtable, (setKey ), ( data))) // INLINED!!
call RemoveSavedInteger(udg_Lists_Hashtable, (setKey ), ( data)) // INLINED!!
call RemoveSavedInteger(udg_Lists_Hashtable, - (- setKey ), ( data)) // INLINED!!
set udg_Lists_Data=data
set udg_Lists_ListID=setKey
call ForForce(bj_FORCE_PLAYER[0], func)
set data=nextData
set countRemoved=countRemoved + 1
endloop
call SaveInteger(udg_Lists_Hashtable, - (setKey ), ( data ), ( start)) // INLINED!!
call SaveInteger(udg_Lists_Hashtable, (setKey ), ( start ), ( data)) // INLINED!!
return countRemoved
endfunction
//==============
// System initialization
//This function initializes GLL if it has not yet been initialized
function GLL_Initialize takes nothing returns nothing
if udg_Lists_Hashtable == null then
//Initialize dependencies
call GMUI_Initialize()
//Initialize Hashtable
set udg_Lists_Hashtable=InitHashtable()
//Get Recycle Key
set udg_Lists_RECYCLE_KEY=GMUI_CreateRecycleKey()
endif
endfunction
////////////////////////////////////////////////////////////////////////////////////////////////////
//End of Ordered Sets
////////////////////////////////////////////////////////////////////////////////////////////////////
function Trig_GLL_Main_Actions takes nothing returns nothing
if udg_Lists_ListID == 0 then
set udg_Lists_ListID = GLL_CreateList()
else
call GLL_DestroyList(udg_Lists_ListID)
endif
endfunction
function Trig_GLL_Main_Conditions takes nothing returns boolean
if HaveSavedInteger(udg_Lists_Hashtable, udg_Lists_ListID, udg_Lists_Data) then //Faster than GLL_ListHasData function
call GLL_RemoveData(udg_Lists_ListID, udg_Lists_Data)
else
call GLL_AddData(udg_Lists_ListID, udg_Lists_Instance, udg_Lists_Data)
endif
return false
endfunction
//===========================================================================
function InitTrig_GLL_Main takes nothing returns nothing
call GLL_Initialize()
set gg_trg_GLL_Main = CreateTrigger( )
call TriggerAddAction( gg_trg_GLL_Main, function Trig_GLL_Main_Actions )
call TriggerAddCondition( gg_trg_GLL_Main, Condition(function Trig_GLL_Main_Conditions))
endfunction
//Functions for simplified looping
function GLL_Next takes integer listId returns integer
local integer next = GLL_GetNext(LoadInteger(udg_GMUI_Hashtable, udg_Lists_REYCLE_KEY, -listId))
call SaveInteger(udg_GMUI_Hashtable, udg_Lists_REYCLE_KEY, -listId, next)
return next
endfunction
function GLL_HasNext takes integer listId returns boolean
return GLL_GetNext(LoadInteger(udg_GMUI_Hashtable, udg_Lists_REYCLE_KEY, -listId)) != 0
endfunction
//Loop example:
// loop
// exitwhen not GLL_HasNext(mylist)
// set mydata = GLL_Next(mylist)
// //...do stuff...
// endloop
////////////////////////////////////////////////////////
//Guhun's Linked Unordered Lists v.1.0.0
////////////////////////////////////////////////////////
//To get the first element, pass "0" as the parameter "data"
function GLUL_GetNext takes integer listKey, integer data returns integer
return LoadInteger(udg_Lists_Hashtable, listKey, data)
endfunction
//To get the last element, pass "0" as the parameter "data"
function GLUL_GetPrev takes integer listKey, integer data returns integer
return LoadInteger(udg_Lists_Hashtable, -listKey, data)
endfunction
function GLUL_ListHasData takes integer listKey, integer data returns boolean
return HaveSavedInteger(udg_Lists_Hashtable, listKey, data)
endfunction
//Adds data to a list
//If data is already present in list, behaviour is undefined
function GLUL_AddData takes integer listKey, integer next, integer data returns nothing
local integer prev = LoadInteger(udg_Lists_Hashtable, -listKey, next)
local integer instance = GIUL_AddData(listKey, data)
call SaveInteger(udg_Lists_Hashtable, -listKey, prev, instance)
call SaveInteger(udg_Lists_Hashtable, -listKey, -next, instance)
call SaveInteger(udg_Lists_Hashtable, -listKey, instance, next)
call SaveInteger(udg_Lists_Hashtable, -listKey, -instance, prev)
endfunction
//Removes the given Data from a list
//If data is not present in List, behaviour is undefined
function GLUL_RemoveData takes integer listKey, integer index returns nothing
local integer next = LoadInteger(udg_Lists_Hashtable, -listKey, index)
local integer prev = LoadInteger(udg_Lists_Hashtable, -listKey, -index)
call SaveInteger(udg_Lists_Hashtable, -listKey, -next, prev)
call SaveInteger(udg_Lists_Hashtable, -listKey, prev, next)
call RemoveSavedInteger(udg_Lists_Hashtable, -listKey, index)
call RemoveSavedInteger(udg_Lists_Hashtable, -listKey, -index)
call GIUL_RemoveData(listKey, index)
endfunction
function GLUL_CreateList takes nothing returns integer
local integer listId = GMUI_GetIndex(udg_Lists_RECYCLE_KEY)
call SaveInteger(udg_Lists_Hashtable, listId, 0, 0)
call SaveInteger(udg_Lists_Hashtable, -listId, 0, 0)
return listId
endfunction
function GLUL_DestroyList takes integer listId returns nothing
call FlushChildHashtable(udg_Lists_Hashtable, listId)
call FlushChildHashtable(udg_Lists_Hashtable, -listId)
call GMUI_RecycleIndex(udg_Lists_RECYCLE_KEY, listId)
endfunction
//This function loops through a List and executes a trigger for each element, setting the list variables to their relevant equivalents each time
function GLUL_Loop takes integer listKey, trigger trig, integer until returns nothing
local integer index = LoadInteger(udg_Lists_Hashtable, listKey, 0)
local integer data
local integer count = 0
local integer negListKey = listKey
loop
exitwhen index == 0 or count == until
set data = LoadInteger(udg_Lists_Hashtable, listKey, index)
set udg_Lists_Data= data
set udg_Lists_ListID = listKey
set index = LoadInteger(udg_Lists_Hashtable, negListKey, index)
if IsTriggerEnabled(trig) and TriggerEvaluate(trig) then
call TriggerExecute(trig)
endif
set count = count + 1
endloop
endfunction
//This function initializes GLL if it has not yet been initialized
function GLUL_Initialize takes nothing returns nothing
if udg_Lists_Hashtable == null then
//Initialize dependencies
call GMUI_Initialize()
//Initialize Hashtable
set udg_Lists_Hashtable = InitHashtable()
//Get Recycle Key
set udg_Lists_RECYCLE_KEY = GMUI_CreateRecycleKey()
endif
endfunction
////////////////////////////////////////////////////////
//End of Linked Unordered Lists
////////////////////////////////////////////////////////