Name | Type | is_array | initial_value |
tempItem | item | No |
//TESH.scrollpos=0
//TESH.alwaysfold=0
library NoItemSharing /*
No Item Sharing v1.11 by Flux
-------------------------------------------------------------------------
This System disable players from selling other player's item.
It also allows other players from not using a certain player's item
and/or disable its Stats Bonus.
It also allows to change icons and tooltips of Shared Items for easily
indicating the difference in-game.
-------------------------------------------------------------------------
*/ requires /*
*/ optional Table /* http://www.hiveworkshop.com/forums/jass-resources-412/snippet-new-table-188084/
If not found, this system will use a hashtable instead. Hashtables is limited to
256 per map. If your map is close to the hashtable limit, it is recommended
to use Table
NOTES:
- Dropping a Shared Item in the ground will turn it into the Original Item
thus Shared Item only appear in Inventory. That way, you don't need to edit the Text
Description (ides) of the Shared Version decreasing the overall purple data fields
of the map.
- The Original Version and the Shared Version must be manually created at Object Editor
- Useful in AoS, Hero Arena and Hero Defense Maps by not allowing team feeding to a certain
player who will carry the whole team.
- Added Bonus: Coincidentally make the Treasure Chest Play an opening animation when dropped.
- To fully understand how the system works, test with DEBUG_SYSTEM = true and run in Debug Mode.
-----------------------------------------------------------------------------------------
Item Shared Version can either be:
- Disabled Shared: The Shared Item is unuseable/provides no stats and cannot be sold
It is recommended to use a Disabled Icon for items like this.
Demo Example: Boots of Speed, Claws of Attack.
- Usabled Shared: The Shared Item can be used but cannot be sold.
Demo Example: Clarity Potion
-----------------------------------------------------------------------------------------
******************************************************************
***************************** API: *******************************
******************************************************************
function ItemShare.data takes integer origId, integer shareId returns nothing
- Tells the system the the shared item type of origId is sharedId.
function ItemShare.getOwner takes item it returns player
- Returns the owner of a certain item, returns null if item has no owner.
- Returns null if item type is not in Database.
function ItemShare.setOwner item it, player p returns nothing
- Set the new owner of an item.
- It automatically transform the items based on the new owner. If the new
owner is null, the item is automatically dropped and the first player to
pick it will be the new owner.
******************************************************************
CREDITS:
Bribe - Table
*/
//===============================================================================
//============================= CONFIGURATION ===================================
//===============================================================================
//! textmacro ITEM_SHARING_INITIAL_DATA
//*** Input Item rawcodes here **
//call ItemShare.data(original Item Type, shared Item Type)
call ItemShare.data('I000', 'I001')
call ItemShare.data('I002', 'I003')
call ItemShare.data('I004', 'I005')
call ItemShare.data('I006', 'I007')
//** Add more here **
//call ItemShare.data(original Item Type, shared Item Type)
//........
//! endtextmacro
globals
//Show Debug Messages to help you understand how the system works.
private constant boolean DEBUG_SYSTEM = true
endglobals
//===============================================================================
//=========================== END CONFIGURATION =================================
//===============================================================================
struct ItemShare extends array
//Integer: alternate type (uses itemTypeId)
//Player: owner (uses GetHandleId)
//Boolean: status (uses itemTypeId) - true if original, false if shared
static if LIBRARY_Table then
private static Table tb
private static Table holder
else
private static hashtable hash = InitHashtable()
endif
private static trigger pickTrg = CreateTrigger()
private static trigger dropTrg = CreateTrigger()
static if DEBUG_SYSTEM then
private static constant string prefix = "|cffffcc00[NoItemSharing]|r: "
endif
static method data takes integer origId, integer shareId returns nothing
static if LIBRARY_Table then
set tb[origId] = shareId
set tb[shareId] = origId
set tb.boolean[origId] = true
set tb.boolean[shareId] = false
else
call SaveInteger(hash, origId, 0, shareId)
call SaveInteger(hash, shareId, 0, origId)
call SaveBoolean(hash, origId, 0, true)
call SaveBoolean(hash, shareId, 0, false)
endif
endmethod
private static method convert takes nothing returns nothing
local timer t = GetExpiredTimer()
local integer handleId = GetHandleId(t)
local real x
local real y
static if LIBRARY_Table then
local item it = tb.item[handleId]
local integer itemType1 = GetItemTypeId(it)
local integer itemType2 = tb[itemType1]
local boolean shared = not tb.boolean[itemType1] and tb.boolean[itemType2]
local integer id = GetHandleId(it)
local player owner = tb.player[id]
else
local item it = LoadItemHandle(hash, handleId, 0)
local integer itemType1 = GetItemTypeId(it)
local integer itemType2 = LoadInteger(hash, itemType1, 0)
local boolean shared = not LoadBoolean(hash, itemType1, 0) and LoadBoolean(hash, itemType2, 0)
local integer id = GetHandleId(it)
local player owner = LoadPlayerHandle(hash, id, 0)
endif
if shared and not IsItemOwned(it) then
set x = GetItemX(it)
set y = GetItemY(it)
static if DEBUG_SYSTEM then
call BJDebugMsg(prefix + "|cffffcc00" + GetItemName(it) + "|r is converted to its original form")
endif
call RemoveItem(it)
set it = CreateItem(itemType2, x, y)
static if LIBRARY_Table then
call tb.player.remove(id)
set tb.player[GetHandleId(it)] = owner
else
call RemoveSavedHandle(hash, id, 0)
call SavePlayerHandle(hash, GetHandleId(it), 0, owner)
endif
endif
static if LIBRARY_Table then
call tb.item.remove(handleId)
else
call RemoveSavedHandle(hash, handleId, 0)
endif
set it = null
call DestroyTimer(t)
set t = null
set owner = null
endmethod
private static method onDrop takes nothing returns boolean
local item it = GetManipulatedItem()
local integer itemType1 = GetItemTypeId(it)
local integer id = GetHandleId(it)
local timer t
static if LIBRARY_Table then
local integer itemType2 = tb[itemType1]
if not tb.boolean[itemType1] and tb.boolean[itemType2] then
static if DEBUG_SYSTEM then
call BJDebugMsg(prefix + GetPlayerName(GetTriggerPlayer()) + " has dropped a shared Item belonging to " + GetPlayerName(tb.player[GetHandleId(it)]))
endif
set t = CreateTimer()
set tb.item[GetHandleId(t)] = it
call TimerStart(t, 0.0, false, function thistype.convert)
set t = null
else
static if DEBUG_SYSTEM then
call BJDebugMsg(prefix + GetPlayerName(GetTriggerPlayer()) + " has dropped an original Item belonging to " + GetPlayerName(tb.player[GetHandleId(it)]))
endif
endif
else
local integer itemType2 = LoadInteger(hash, itemType1, 0)
if not LoadBoolean(hash, itemType1, 0) and LoadBoolean(hash, itemType2, 0) then
static if DEBUG_SYSTEM then
call BJDebugMsg(prefix + GetPlayerName(GetTriggerPlayer()) + " has dropped a shared Item belonging to " + GetPlayerName(LoadPlayerHandle(hash, GetHandleId(it), 0)))
endif
set t = CreateTimer()
call SaveItemHandle(hash, GetHandleId(t), 0, it)
call TimerStart(t, 0.0, false, function thistype.convert)
set t = null
else
static if DEBUG_SYSTEM then
call BJDebugMsg(prefix + GetPlayerName(GetTriggerPlayer()) + " has dropped an original Item belonging to " + GetPlayerName(LoadPlayerHandle(hash, GetHandleId(it), 0)))
endif
endif
endif
static if LIBRARY_Table then
call holder.unit.remove(id)
else
call RemoveSavedHandle(hash, id, 1)
endif
set it = null
return false
endmethod
private static method onPick takes nothing returns boolean
local item it = GetManipulatedItem()
local unit u = GetTriggerUnit()
local integer id = GetHandleId(it)
local player trigPlayer = GetTriggerPlayer()
local integer itemType1 = GetItemTypeId(it)
static if LIBRARY_Table then
local integer itemType2 = tb[itemType1]
local boolean orig = tb.boolean[itemType1] and not tb.boolean[itemType2]
local boolean shared = not tb.boolean[itemType1] and tb.boolean[itemType2]
local player prevPlayer = tb.player[id]
else
local integer itemType2 = LoadInteger(hash, itemType1, 0)
local boolean orig = LoadBoolean(hash, itemType1, 0) and not LoadBoolean(hash, itemType2, 0)
local boolean shared = not LoadBoolean(hash, itemType1, 0) and LoadBoolean(hash, itemType2, 0)
local player prevPlayer = LoadPlayerHandle(hash, id, 0)
endif
static if DEBUG_SYSTEM then
call BJDebugMsg(prefix + GetPlayerName(trigPlayer) + " has picked |cffffcc00" + GetItemName(it) + "|r which originally belongs to " + GetPlayerName(prevPlayer))
endif
//If item is in the database
if (orig or shared) then
//If item has no owner
if prevPlayer == null then
static if LIBRARY_Table then
set tb.player[id] = trigPlayer
else
call SavePlayerHandle(hash, id, 0, trigPlayer)
endif
static if DEBUG_SYSTEM then
call BJDebugMsg(prefix + GetPlayerName(trigPlayer) + " is the now the owner of |cffffcc00" + GetItemName(it) + "|r")
endif
endif
//orig -> shared will happen if a player happens to pick an item belonging to other players
//shared -> orig will happen if you're the owner or if there is no owner or if you're the owner
if (orig and trigPlayer != prevPlayer and prevPlayer != null) or (shared and (prevPlayer == null or trigPlayer == prevPlayer)) then
//Convert
call DisableTrigger(pickTrg)
call DisableTrigger(dropTrg)
static if DEBUG_SYSTEM then
call BJDebugMsg(prefix + "|cffffcc00" + GetItemName(it) + "|r is converted")
endif
call RemoveItem(it)
set it = CreateItem(itemType2, 0, 0)
call UnitAddItem(u, it)
static if LIBRARY_Table then
call tb.player.remove(id)
set tb.player[GetHandleId(it)] = prevPlayer
else
call RemoveSavedHandle(hash, id, 0)
call SavePlayerHandle(hash, GetHandleId(it), 0, prevPlayer)
endif
call EnableTrigger(pickTrg)
call EnableTrigger(dropTrg)
endif
//Save Unit holding the item to have O(1) operation for unit dropping the item
static if LIBRARY_Table then
set holder.unit[GetHandleId(it)] = u
else
call SaveUnitHandle(hash, GetHandleId(it), 1, u)
endif
else
static if DEBUG_SYSTEM then
call BJDebugMsg(prefix + "|cffffcc00" + GetItemName(it) + "|r is not in the database. It will treate it as a normal item")
endif
endif
set it = null
set u = null
set trigPlayer = null
set prevPlayer = null
return false
endmethod
private static method onInit takes nothing returns nothing
local integer i = 0
loop
call TriggerRegisterPlayerUnitEvent(pickTrg, Player(i), EVENT_PLAYER_UNIT_PICKUP_ITEM, null)
call TriggerRegisterPlayerUnitEvent(dropTrg, Player(i), EVENT_PLAYER_UNIT_DROP_ITEM, null)
set i = i + 1
exitwhen i == bj_MAX_PLAYER_SLOTS
endloop
call TriggerAddCondition(pickTrg, Condition(function thistype.onPick))
call TriggerAddCondition(dropTrg, Condition(function thistype.onDrop))
static if LIBRARY_Table then
set tb = Table.create()
set holder = Table.create()
endif
//! runtextmacro ITEM_SHARING_INITIAL_DATA()
endmethod
static method getOwner takes item it returns player
static if LIBRARY_Table then
return tb.player[GetHandleId(it)]
else
return LoadPlayerHandle(hash, GetHandleId(it), 0)
endif
endmethod
static method setOwner takes item it, player p returns nothing
local integer itemType1 = GetItemTypeId(it)
local unit u
static if LIBRARY_Table then
local integer itemType2 = tb[itemType1]
local boolean orig = tb.boolean[itemType1] and not tb.boolean[itemType2]
local boolean shared = not tb.boolean[itemType1] and tb.boolean[itemType2]
else
local integer itemType2 = LoadInteger(hash, itemType1, 0)
local boolean orig = LoadBoolean(hash, itemType1, 0) and not LoadBoolean(hash, itemType2, 0)
local boolean shared = not LoadBoolean(hash, itemType1, 0) and LoadBoolean(hash, itemType2, 0)
endif
if orig or shared then
if p == null then
static if LIBRARY_Table then
call tb.player.remove(GetHandleId(it))
else
call RemoveSavedHandle(hash, GetHandleId(it), 0)
endif
else
static if LIBRARY_Table then
set tb.player[GetHandleId(it)] = p
else
call SavePlayerHandle(hash, GetHandleId(it), 0, p)
endif
endif
//Refresh Item Status
if IsItemOwned(it) then
static if LIBRARY_Table then
set u = holder.unit[GetHandleId(it)]
else
set u = LoadUnitHandle(hash, GetHandleId(it), 1)
endif
call UnitRemoveItem(u, it)
if p != null then
call UnitAddItem(u, it)
endif
set u = null
endif
endif
endmethod
endstruct
endlibrary
//TESH.scrollpos=0
//TESH.alwaysfold=0
/*
HOW TO USE:
1. Make the items (Original and Shared) in the Object Editor.
2. Make sure that the 'Stats - Can Be Sold to Merchant' of Shared Item is FALSE.
3. You can edit the Item Name of Shared Items by putting (|cffffcc00Shared|r) besides the name to
indicate in-game that it is a Shared Item Version. You can also edit the Icon as done
in this demo (look at Import Manager).
4. You can remove the Ability of the Shared Item Version to disable its ability when picked by
other players.
5. Input the Raw codes of the item (Press CTRL + D in Object Manager) in the System Configuration.
*/
//TESH.scrollpos=97
//TESH.alwaysfold=0
library Table /* made by Bribe, special thanks to Vexorian & Nestharus, version 3.1.1.0
One map, one hashtable. Welcome to NewTable 3.1
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
endlibrary