Name | Type | is_array | initial_value |
GMSS_Hashtable | hashtable | No | |
GMSS_HASHTABLE_ADDRESS | integer | No | |
GMSS_MaximumSpeed | real | No | |
GMSS_MinimumSpeed | real | No | |
GMSS_MoveBonus | real | No | |
GMSS_MoveMultiplier | real | No | |
GMSS_Target | unit | No | |
Test_EscTimer | timer | No | |
UDex | integer | No | |
UDexUnits | unit | Yes | |
UnitIndexEvent | real | No |
library MoveSpeedBonus requires optional Table
//////////////////////////////////////////////////////
// Guhun's Move Speed System v2.0.1
//-----------------------------------
//===================================================
// Simple configuration
//===================================================
/*
Just change these numbers to whatever you want, you can also set them to a variable (remember to
put "udg_" in front of the variable)
*/
function GMSS_GetDefaultMaxSpeed takes nothing returns real
return 522.0 // Value for Default Maximum Speed
endfunction
function GMSS_GetDefaultMinSpeed takes nothing returns real
return 0.000 // Value for Default Minimum Speed
endfunction
//===================================================
// Advanced configuration
//===================================================
globals
// Use a Table instance instead of a Hashtable (requires library: Table https://www.hiveworkshop.com/threads/snippet-new-table.188084/ )
public constant boolean USE_TABLE = true
// Create a new Hashtable for the system, instead of using an existing one.
// If this is false, and you are not using GUI, make sure to also change the 2 textmacros below.
public constant boolean INIT_HASHTABLE = false
// This textmacro returns the Alternate Hashtable when INIT_HASHTABLE is false.
//! textmacro GMSS_AlternateHashtable
return udg_GMSS_Hashtable
//! endtextmacro
// This textmacro returns the integer Key used for storing data when INIT_HASHTABLE is false.
//! textmacro GMSS_AlternateHashtableKey
return udg_GMSS_HASHTABLE_ADDRESS
//! endtextmacro
// Automatically clean up unit data by removing any data when a unit is created that has an ID that was previously used
// If you disable this, then you must call GMSS_ClearData whenever a unit enters the game or is removed from it
public constant boolean AUTO_CLEANUP = true
endglobals
//! novjass
' '
' API '
// Adds "amount" to unit speed bonus and sets move speed between "minSpeed" and "maxSpeed".
function GMSS_UnitAddMoveSpeedEx
takes
unit whichUnit
real amount => //!The amount to add to the unit's move speed.
real minSpeed => //!The unit's new speed will not be lower than this value.
real maxSpeed => //!The unit's new speed will not be higher than this value.
returns
real => //!The unit's flat move speed bonus after changes are applied.
endfunction
// Multiplies unit speed multiplier by "amount" and sets move speed between "minSpeed" and "maxSpeed".
function GMSS_UnitMultiplyMoveSpeedEx
takes
unit whichUnit
real amount => //!The amount to add to the unit's move speed.
real minSpeed => //!The unit's new speed will not be lower than this value.
real maxSpeed => //!The unit's new speed will not be higher than this value.
returns
real => //!The unit's move speed multiplier after changes are applied.
endfunction
// Like GMSS_UnitAddMoveSpeedEx, but min and max values are drawn from GMSS_GetDefaultMax(Min)Speed.
function GMSS_UnitAddMoveSpeed takes unit whichUnit, real amount returns real
takes
unit whichUnit
real amount => //!The amount to add to the unit's move speed.
returns
real => //!The unit's flat move speed bonus after changes are applied.
endfunction
// Like GMSS_UnitMultiplyMoveSpeedEx, but min and max values are drawn from GMSS_GetDefaultMax(Min)Speed.
function GMSS_UnitMultiplyMoveSpeed takes unit whichUnit, real amount returns real
takes
unit whichUnit
real amount => //!The amount to add to the unit's move speed.
returns
real => //!The unit's move speed multiplier after changes are applied.
endfunction
function GMSS_UnitGetMoveBonus takes unit whichUnit returns real
takes
unit whichUnit
returns
real => //!The unit's movement speed flat bonus.
endfunction
function GMSS_UnitGetMoveMultiplier takes unit whichUnit returns real
takes
unit whichUnit
returns
real => //!The unit's movement speed multiplier.
endfunction
// Clears all Hashtable or Table data stored for 'whichUnit' in the system.
// You won't need to call this yourself unless AUTO_CLEANUP is set to false.
function GMSS_ClearData takes unit whichUnit returns nothing
takes
unit whichUnit
returns
nothing
endfunction
' '
' Source Code '
//! endnovjass
static if LIBRARY_Table and USE_TABLE then
globals
private integer data
endglobals
elseif INIT_HASHTABLE then
globals
private hashtable hashTable = null
endglobals
endif
static if LIBRARY_Table and USE_TABLE then
else
function GMSS_GetHashtable takes nothing returns hashtable
static if INIT_HASHTABLE then
return hashTable
else
//! runtextmacro GMSS_AlternateHashtable()
endif
endfunction
endif
//===================================================
// Data Storage Utilities
//===================================================
//Positive Unit Handle ID > Move Bonus
//Negative Unit Handle ID > Move Multiplier
private function KEY takes nothing returns integer
static if INIT_HASHTABLE then
return 0
else
//! runtextmacro GMSS_AlternateHashtableKey()
endif
endfunction
private function GetUnitId takes unit whichUnit returns integer
return GetHandleId(whichUnit)
endfunction
private function LoadMultiplier takes integer uId returns real
static if LIBRARY_Table and USE_TABLE then
return Table(data).real[-uId]
else
return LoadReal(GMSS_GetHashtable(), KEY(), -uId)
endif
endfunction
private function LoadBonus takes integer uId returns real
static if LIBRARY_Table and USE_TABLE then
return Table(data).real[uId]
else
return LoadReal(GMSS_GetHashtable(), KEY(), uId)
endif
endfunction
private function RemoveMultiplier takes integer uId returns nothing
static if LIBRARY_Table and USE_TABLE then
call Table(data).real.remove(-uId)
else
call RemoveSavedReal(GMSS_GetHashtable(), KEY(), -uId)
endif
endfunction
private function RemoveBonus takes integer uId returns nothing
static if LIBRARY_Table and USE_TABLE then
call Table(data).real.remove(uId)
else
call RemoveSavedReal(GMSS_GetHashtable(), KEY(), uId)
endif
endfunction
private function SaveMultiplier takes integer uId, real value returns nothing
static if LIBRARY_Table and USE_TABLE then
set Table(data).real[-uId] = value
else
call SaveReal(GMSS_GetHashtable(), KEY(), -uId, value)
endif
endfunction
private function SaveBonus takes integer uId, real value returns nothing
static if LIBRARY_Table and USE_TABLE then
set Table(data).real[uId] = value
else
call SaveReal(GMSS_GetHashtable(), KEY(), uId, value)
endif
endfunction
//===================================================
// API functions
//===================================================
// Adds "amount" to unit speed bonus and sets unit speed between "minSpeed" and "maxSpeed".
function GMSS_UnitAddMoveSpeedEx takes unit whichUnit, real amount, real minSpeed, real maxSpeed returns real
local integer uId = GetUnitId(whichUnit)
local real bonus = LoadBonus(uId)
local real multiplier = LoadMultiplier(uId)
//Fix multiplier for when there is no saved value
if multiplier == 0 then
set multiplier = 1
endif
if amount != 0 then
//Set new value and save/clear data as necessary
set bonus = bonus + amount
if bonus < -0.99999 and bonus > 0.00001 then //Consider floating point imprecision when clearing Hashtable data
call RemoveBonus(uId)
else
call SaveBonus(uId, bonus)
endif
endif
//Set Unit Move Speed (any ability modifiers are applied to this after it is set)
call SetUnitMoveSpeed(whichUnit, RMaxBJ(minSpeed, RMinBJ(maxSpeed, GetUnitDefaultMoveSpeed(whichUnit)*multiplier + bonus)))
return bonus
endfunction
// Multiplies unit speed multiplier by "amount" and sets unit speed between "minSpeed" and "maxSpeed".
function GMSS_UnitMultiplyMoveSpeedEx takes unit whichUnit, real amount, real minSpeed, real maxSpeed returns real
local integer uId = GetUnitId(whichUnit)
local real bonus = LoadBonus(uId)
local real multiplier = LoadMultiplier(uId)
//Fix multiplier for when there is no saved value
if multiplier == 0 then
set multiplier = 1
endif
if amount == 1 or amount <= 0 then
else
//Set new value and save/clear data as necessary
set multiplier = multiplier * amount
if multiplier < 1.00001 and multiplier > 0.99999 then //Consider floating point imprecision when clearing Hashtable data
call RemoveMultiplier(uId)
else
call SaveMultiplier(uId, multiplier)
endif
endif
//Set Unit Move Speed (any ability modifiers are applied to this after it is set)
call SetUnitMoveSpeed(whichUnit, RMaxBJ(minSpeed, RMinBJ(maxSpeed, GetUnitDefaultMoveSpeed(whichUnit)*multiplier + bonus)))
return multiplier
endfunction
// Like GMSS_UnitAddMoveSpeedEx, but min and max values are drawn from GMSS_GetDefaultMax(Min)Speed.
function GMSS_UnitAddMoveSpeed takes unit whichUnit, real amount returns real
return GMSS_UnitAddMoveSpeedEx(whichUnit, amount, GMSS_GetDefaultMinSpeed(), GMSS_GetDefaultMaxSpeed())
endfunction
// Like GMSS_UnitMultiplyMoveSpeedEx, but min and max values are drawn from GMSS_GetDefaultMax(Min)Speed.
function GMSS_UnitMultiplyMoveSpeed takes unit whichUnit, real amount returns real
return GMSS_UnitMultiplyMoveSpeedEx(whichUnit, amount, GMSS_GetDefaultMinSpeed(), GMSS_GetDefaultMaxSpeed())
endfunction
function GMSS_UnitGetMoveBonus takes unit whichUnit returns real
return LoadBonus(GetUnitId(whichUnit))
endfunction
function GMSS_UnitGetMoveMultiplier takes unit whichUnit returns real
local real multiplier = LoadMultiplier(GetUnitId(whichUnit))
if multiplier == 0 then
return 1.0
endif
return multiplier
endfunction
// Clears all Hashtable or Table data stored for 'whichUnit' in the system.
function GMSS_ClearData takes unit whichUnit returns nothing
local integer uId = GetHandleId(whichUnit)
call RemoveBonus(uId)
call RemoveMultiplier(uId)
endfunction
//===================================================
// Auto Cleanup and Initialization
//===================================================
static if AUTO_CLEANUP then
private function TrigCleanupCondition takes nothing returns boolean
call GMSS_ClearData(GetTriggerUnit())
return false
endfunction
endif
private module Init
static method onInit takes nothing returns nothing
local trigger trig
static if LIBRARY_Table and USE_TABLE then
set data = Table.create()
elseif INIT_HASHTABLE then
set hashTable = InitHashtable()
endif
static if AUTO_CLEANUP then
set trig = CreateTrigger()
call TriggerRegisterEnterRectSimple(trig, GetWorldBounds())
call TriggerAddCondition(trig, Condition(function TrigCleanupCondition))
set trig = null
endif
endmethod
endmodule
//! textmacro GMSS_Initialization takes GLOBE
private struct Initializer$GLOBE$ extends array
implement Init
endstruct
//! endtextmacro
// This trick is used because you can't have two structs with the same name, even inside an unused static if.
static if LIBRARY_Table and USE_TABLE then
//! runtextmacro GMSS_Initialization("1")
elseif AUTO_CLEANUP then
//! runtextmacro GMSS_Initialization("2")
elseif INIT_HASHTABLE then
//! runtextmacro GMSS_Initialization("3")
endif
endlibrary
function Trig_GMSS_Main_Actions takes nothing returns nothing
if udg_GMSS_MoveMultiplier >= 0 then
set udg_GMSS_MoveBonus = GMSS_UnitAddMoveSpeedEx(udg_GMSS_Target, udg_GMSS_MoveBonus, udg_GMSS_MinimumSpeed, udg_GMSS_MaximumSpeed)
set udg_GMSS_MoveMultiplier = GMSS_UnitMultiplyMoveSpeedEx(udg_GMSS_Target, udg_GMSS_MoveMultiplier, udg_GMSS_MinimumSpeed, udg_GMSS_MaximumSpeed)
else
set udg_GMSS_MoveBonus = GMSS_UnitGetMoveBonus(udg_GMSS_Target)
set udg_GMSS_MoveMultiplier = GMSS_UnitGetMoveMultiplier(udg_GMSS_Target)
endif
endfunction
function Trig_GMSS_Main_Conditions takes nothing returns boolean
set udg_GMSS_MoveBonus = GMSS_UnitAddMoveSpeed(udg_GMSS_Target, udg_GMSS_MoveBonus)
set udg_GMSS_MoveMultiplier = GMSS_UnitMultiplyMoveSpeed(udg_GMSS_Target, udg_GMSS_MoveMultiplier)
return false
endfunction
//===========================================================================
function InitTrig_GMSS_Main takes nothing returns nothing
set gg_trg_GMSS_Main = CreateTrigger( )
call TriggerAddAction( gg_trg_GMSS_Main, function Trig_GMSS_Main_Actions )
call TriggerAddCondition( gg_trg_GMSS_Main, Condition(function Trig_GMSS_Main_Conditions))
endfunction
library Table /* made by Bribe, special thanks to Vexorian & Nestharus, version 4.1.0.1.
One map, one hashtable. Welcome to NewTable 4.1.0.1
This newest iteration of Table introduces the new HashTable struct.
You can now instantiate HashTables which enables the use of large
parent and large child keys, just like a standard hashtable. Previously,
the user would have to instantiate a Table to do this on their own which -
while doable - is something the user should not have to do if I can add it
to this resource myself (especially if they are inexperienced).
This library was originally called NewTable so it didn't conflict with
the API of Table by Vexorian. However, the damage is done and it's too
late to change the library name now. To help with damage control, I
have provided an extension library called TableBC, which bridges all
the functionality of Vexorian's Table except for 2-D string arrays &
the ".flush(integer)" method. I use ".flush()" to flush a child hash-
table, because I wanted the API in NewTable to reflect the API of real
hashtables (I thought this would be more intuitive).
API
------------
struct Table
| static method create takes nothing returns Table
| create a new Table
|
| method destroy takes nothing returns nothing
| destroy it
|
| method flush takes nothing returns nothing
| flush all stored values inside of it
|
| method remove takes integer key returns nothing
| remove the value at index "key"
|
| method operator []= takes integer key, $TYPE$ value returns nothing
| assign "value" to index "key"
|
| method operator [] takes integer key returns $TYPE$
| load the value at index "key"
|
| method has takes integer key returns boolean
| whether or not the key was assigned
|
----------------
struct TableArray
| static method operator [] takes integer array_size returns TableArray
| create a new array of Tables of size "array_size"
|
| method destroy takes nothing returns nothing
| destroy it
|
| method flush takes nothing returns nothing
| flush and destroy it
|
| method operator size takes nothing returns integer
| returns the size of the TableArray
|
| method operator [] takes integer key returns Table
| returns a Table accessible exclusively to index "key"
*/
globals
private integer less = 0 //Index generation for TableArrays (below 0).
private integer more = 8190 //Index generation for Tables.
//Configure it if you use more than 8190 "key" variables in your map (this will never happen though).
private hashtable ht = InitHashtable()
private key sizeK
private key listK
endglobals
private struct dex extends array
static method operator size takes nothing returns Table
return sizeK
endmethod
static method operator list takes nothing returns Table
return listK
endmethod
endstruct
private struct handles extends array
method has takes integer key returns boolean
return HaveSavedHandle(ht, this, key)
endmethod
method remove takes integer key returns nothing
call RemoveSavedHandle(ht, this, key)
endmethod
endstruct
private struct agents extends array
method operator []= takes integer key, agent value returns nothing
call SaveAgentHandle(ht, this, key, value)
endmethod
endstruct
//! textmacro NEW_ARRAY_BASIC takes SUPER, FUNC, TYPE
private struct $TYPE$s extends array
method operator [] takes integer key returns $TYPE$
return Load$FUNC$(ht, this, key)
endmethod
method operator []= takes integer key, $TYPE$ value returns nothing
call Save$FUNC$(ht, this, key, value)
endmethod
method has takes integer key returns boolean
return HaveSaved$SUPER$(ht, this, key)
endmethod
method remove takes integer key returns nothing
call RemoveSaved$SUPER$(ht, this, key)
endmethod
endstruct
private module $TYPE$m
method operator $TYPE$ takes nothing returns $TYPE$s
return this
endmethod
endmodule
//! endtextmacro
//! textmacro NEW_ARRAY takes FUNC, TYPE
private struct $TYPE$s extends array
method operator [] takes integer key returns $TYPE$
return Load$FUNC$Handle(ht, this, key)
endmethod
method operator []= takes integer key, $TYPE$ value returns nothing
call Save$FUNC$Handle(ht, this, key, value)
endmethod
method has takes integer key returns boolean
return HaveSavedHandle(ht, this, key)
endmethod
method remove takes integer key returns nothing
call RemoveSavedHandle(ht, this, key)
endmethod
endstruct
private module $TYPE$m
method operator $TYPE$ takes nothing returns $TYPE$s
return this
endmethod
endmodule
//! endtextmacro
//Run these textmacros to include the entire hashtable API as wrappers.
//Don't be intimidated by the number of macros - Vexorian's map optimizer is
//supposed to kill functions which inline (all of these functions inline).
//! runtextmacro NEW_ARRAY_BASIC("Real", "Real", "real")
//! runtextmacro NEW_ARRAY_BASIC("Boolean", "Boolean", "boolean")
//! runtextmacro NEW_ARRAY_BASIC("String", "Str", "string")
//New textmacro to allow table.integer[] syntax for compatibility with textmacros that might desire it.
//! runtextmacro NEW_ARRAY_BASIC("Integer", "Integer", "integer")
//! runtextmacro NEW_ARRAY("Player", "player")
//! runtextmacro NEW_ARRAY("Widget", "widget")
//! runtextmacro NEW_ARRAY("Destructable", "destructable")
//! runtextmacro NEW_ARRAY("Item", "item")
//! runtextmacro NEW_ARRAY("Unit", "unit")
//! runtextmacro NEW_ARRAY("Ability", "ability")
//! runtextmacro NEW_ARRAY("Timer", "timer")
//! runtextmacro NEW_ARRAY("Trigger", "trigger")
//! runtextmacro NEW_ARRAY("TriggerCondition", "triggercondition")
//! runtextmacro NEW_ARRAY("TriggerAction", "triggeraction")
//! runtextmacro NEW_ARRAY("TriggerEvent", "event")
//! runtextmacro NEW_ARRAY("Force", "force")
//! runtextmacro NEW_ARRAY("Group", "group")
//! runtextmacro NEW_ARRAY("Location", "location")
//! runtextmacro NEW_ARRAY("Rect", "rect")
//! runtextmacro NEW_ARRAY("BooleanExpr", "boolexpr")
//! runtextmacro NEW_ARRAY("Sound", "sound")
//! runtextmacro NEW_ARRAY("Effect", "effect")
//! runtextmacro NEW_ARRAY("UnitPool", "unitpool")
//! runtextmacro NEW_ARRAY("ItemPool", "itempool")
//! runtextmacro NEW_ARRAY("Quest", "quest")
//! runtextmacro NEW_ARRAY("QuestItem", "questitem")
//! runtextmacro NEW_ARRAY("DefeatCondition", "defeatcondition")
//! runtextmacro NEW_ARRAY("TimerDialog", "timerdialog")
//! runtextmacro NEW_ARRAY("Leaderboard", "leaderboard")
//! runtextmacro NEW_ARRAY("Multiboard", "multiboard")
//! runtextmacro NEW_ARRAY("MultiboardItem", "multiboarditem")
//! runtextmacro NEW_ARRAY("Trackable", "trackable")
//! runtextmacro NEW_ARRAY("Dialog", "dialog")
//! runtextmacro NEW_ARRAY("Button", "button")
//! runtextmacro NEW_ARRAY("TextTag", "texttag")
//! runtextmacro NEW_ARRAY("Lightning", "lightning")
//! runtextmacro NEW_ARRAY("Image", "image")
//! runtextmacro NEW_ARRAY("Ubersplat", "ubersplat")
//! runtextmacro NEW_ARRAY("Region", "region")
//! runtextmacro NEW_ARRAY("FogState", "fogstate")
//! runtextmacro NEW_ARRAY("FogModifier", "fogmodifier")
//! runtextmacro NEW_ARRAY("Hashtable", "hashtable")
struct Table extends array
// Implement modules for intuitive syntax (tb.handle; tb.unit; etc.)
implement realm
implement integerm
implement booleanm
implement stringm
implement playerm
implement widgetm
implement destructablem
implement itemm
implement unitm
implement abilitym
implement timerm
implement triggerm
implement triggerconditionm
implement triggeractionm
implement eventm
implement forcem
implement groupm
implement locationm
implement rectm
implement boolexprm
implement soundm
implement effectm
implement unitpoolm
implement itempoolm
implement questm
implement questitemm
implement defeatconditionm
implement timerdialogm
implement leaderboardm
implement multiboardm
implement multiboarditemm
implement trackablem
implement dialogm
implement buttonm
implement texttagm
implement lightningm
implement imagem
implement ubersplatm
implement regionm
implement fogstatem
implement fogmodifierm
implement hashtablem
method operator handle takes nothing returns handles
return this
endmethod
method operator agent takes nothing returns agents
return this
endmethod
//set this = tb[GetSpellAbilityId()]
method operator [] takes integer key returns Table
return LoadInteger(ht, this, key) //return this.integer[key]
endmethod
//set tb[389034] = 8192
method operator []= takes integer key, Table tb returns nothing
call SaveInteger(ht, this, key, tb) //set this.integer[key] = tb
endmethod
//set b = tb.has(2493223)
method has takes integer key returns boolean
return HaveSavedInteger(ht, this, key) //return this.integer.has(key)
endmethod
//call tb.remove(294080)
method remove takes integer key returns nothing
call RemoveSavedInteger(ht, this, key) //call this.integer.remove(key)
endmethod
//Remove all data from a Table instance
method flush takes nothing returns nothing
call FlushChildHashtable(ht, this)
endmethod
//local Table tb = Table.create()
static method create takes nothing returns Table
local Table this = dex.list[0]
if this == 0 then
set this = more + 1
set more = this
else
set dex.list[0] = dex.list[this]
call dex.list.remove(this) //Clear hashed memory
endif
debug set dex.list[this] = -1
return this
endmethod
// Removes all data from a Table instance and recycles its index.
//
// call tb.destroy()
//
method destroy takes nothing returns nothing
debug if dex.list[this] != -1 then
debug call BJDebugMsg("Table Error: Tried to double-free instance: " + I2S(this))
debug return
debug endif
call this.flush()
set dex.list[this] = dex.list[0]
set dex.list[0] = this
endmethod
//! runtextmacro optional TABLE_BC_METHODS()
endstruct
//! runtextmacro optional TABLE_BC_STRUCTS()
struct TableArray extends array
//Returns a new TableArray to do your bidding. Simply use:
//
// local TableArray ta = TableArray[array_size]
//
static method operator [] takes integer array_size returns TableArray
local Table tb = dex.size[array_size] //Get the unique recycle list for this array size
local TableArray this = tb[0] //The last-destroyed TableArray that had this array size
debug if array_size <= 0 then
debug call BJDebugMsg("TypeError: Invalid specified TableArray size: " + I2S(array_size))
debug return 0
debug endif
if this == 0 then
set this = less - array_size
set less = this
else
set tb[0] = tb[this] //Set the last destroyed to the last-last destroyed
call tb.remove(this) //Clear hashed memory
endif
set dex.size[this] = array_size //This remembers the array size
return this
endmethod
//Returns the size of the TableArray
method operator size takes nothing returns integer
return dex.size[this]
endmethod
//This magic method enables two-dimensional[array][syntax] for Tables,
//similar to the two-dimensional utility provided by hashtables them-
//selves.
//
//ta[integer a].unit[integer b] = unit u
//ta[integer a][integer c] = integer d
//
//Inline-friendly when not running in debug mode
//
method operator [] takes integer key returns Table
static if DEBUG_MODE then
local integer i = this.size
if i == 0 then
call BJDebugMsg("IndexError: Tried to get key from invalid TableArray instance: " + I2S(this))
return 0
elseif key < 0 or key >= i then
call BJDebugMsg("IndexError: Tried to get key [" + I2S(key) + "] from outside TableArray bounds: " + I2S(i))
return 0
endif
endif
return this + key
endmethod
//Destroys a TableArray without flushing it; I assume you call .flush()
//if you want it flushed too. This is a public method so that you don't
//have to loop through all TableArray indices to flush them if you don't
//need to (ie. if you were flushing all child-keys as you used them).
//
method destroy takes nothing returns nothing
local Table tb = dex.size[this.size]
debug if this.size == 0 then
debug call BJDebugMsg("TypeError: Tried to destroy an invalid TableArray: " + I2S(this))
debug return
debug endif
if tb == 0 then
//Create a Table to index recycled instances with their array size
set tb = Table.create()
set dex.size[this.size] = tb
endif
call dex.size.remove(this) //Clear the array size from hash memory
set tb[this] = tb[0]
set tb[0] = this
endmethod
private static Table tempTable
private static integer tempEnd
//Avoids hitting the op limit
private static method clean takes nothing returns nothing
local Table tb = .tempTable
local integer end = tb + 0x1000
if end < .tempEnd then
set .tempTable = end
call ForForce(bj_FORCE_PLAYER[0], function thistype.clean)
else
set end = .tempEnd
endif
loop
call tb.flush()
set tb = tb + 1
exitwhen tb == end
endloop
endmethod
//Flushes the TableArray and also destroys it. Doesn't get any more
//similar to the FlushParentHashtable native than this.
//
method flush takes nothing returns nothing
debug if this.size == 0 then
debug call BJDebugMsg("TypeError: Tried to flush an invalid TableArray instance: " + I2S(this))
debug return
debug endif
set .tempTable = this
set .tempEnd = this + this.size
call ForForce(bj_FORCE_PLAYER[0], function thistype.clean)
call this.destroy()
endmethod
endstruct
//NEW: Added in Table 4.0. A fairly simple struct but allows you to do more
//than that which was previously possible.
struct HashTable extends array
//Enables myHash[parentKey][childKey] syntax.
//Basically, it creates a Table in the place of the parent key if
//it didn't already get created earlier.
method operator [] takes integer index returns Table
local Table t = Table(this)[index]
if t == 0 then
set t = Table.create()
set Table(this)[index] = t //whoops! Forgot that line. I'm out of practice!
endif
return t
endmethod
//You need to call this on each parent key that you used if you
//intend to destroy the HashTable or simply no longer need that key.
method remove takes integer index returns nothing
local Table t = Table(this)[index]
if t != 0 then
call t.destroy()
call Table(this).remove(index)
endif
endmethod
//Added in version 4.1
method has takes integer index returns boolean
return Table(this).has(index)
endmethod
//HashTables are just fancy Table indices.
method destroy takes nothing returns nothing
call Table(this).destroy()
endmethod
//Like I said above...
static method create takes nothing returns thistype
return Table.create()
endmethod
endstruct
endlibrary