Name | Type | is_array | initial_value |
library AllocT /* v1.0.2.0
*************************************************************************************
*
* */uses/*
*
* */ ErrorMessage /* https://github.com/nestharus/JASS/tree/master/jass/Systems/ErrorMessage
* */ Table /* http://www.hiveworkshop.com/forums/jass-resources-412/snippet-new-table-188084/
*
*************************************************************************************
*
* Minimizes code generation and global variables while maintaining
* excellent performance.
*
* Uses hashtable instead of array, which drastically reduces performance
* but uncaps the instance limit. Should use with table fields instead of
* array fields.
*
* local thistype this = recycler[0]
*
* if (recycler[this] == 0) then
* set recycler[0] = this + 1
* else
* set recycler[0] = recycler[this]
* endif
*
************************************************************************************
*
* module AllocT
*
* static method allocate takes nothing returns thistype
* method deallocate takes nothing returns nothing
*
* readonly boolean isAllocated
*
* debug static method calculateMemoryUsage takes nothing returns integer
* debug static method getAllocatedMemoryAsString takes nothing returns string
*
************************************************************************************/
module AllocT
/*
* stack
*/
private static Table recycler
/*
* list of allocated memory
*/
debug private static Table allocatedNext
debug private static Table allocatedPrev
/*
* free memory counter
*/
debug private static integer usedMemory = 0
/*
* allocation
*/
static method allocate takes nothing returns thistype
local thistype this = recycler[0]
debug call ThrowError(this < 0, "AllocT", "allocate", "thistype", 0, "Overflow.")
if (recycler[this] == 0) then
set recycler[0] = this + 1
else
set recycler[0] = recycler[this]
endif
set recycler[this] = -1
debug set usedMemory = usedMemory + 1
debug set allocatedNext[this] = 0
debug set allocatedPrev[this] = allocatedPrev[0]
debug set allocatedNext[allocatedPrev[0]] = this
debug set allocatedPrev[0] = this
return this
endmethod
method deallocate takes nothing returns nothing
debug call ThrowError(recycler[this] != -1, "AllocT", "deallocate", "thistype", this, "Attempted To Deallocate Null Instance.")
set recycler[this] = recycler[0]
set recycler[0] = this
debug set usedMemory = usedMemory - 1
debug set allocatedNext[allocatedPrev[this]] = allocatedNext[this]
debug set allocatedPrev[allocatedNext[this]] = allocatedPrev[this]
endmethod
/*
* analysis
*/
method operator isAllocated takes nothing returns boolean
return recycler[this] == -1
endmethod
static if DEBUG_MODE then
static method calculateMemoryUsage takes nothing returns integer
return usedMemory
endmethod
static method getAllocatedMemoryAsString takes nothing returns string
local integer memoryCell = allocatedNext[0]
local string memoryRepresentation = null
loop
exitwhen memoryCell == 0
if (memoryRepresentation == null) then
set memoryRepresentation = I2S(memoryCell)
else
set memoryRepresentation = memoryRepresentation + ", " + I2S(memoryCell)
endif
set memoryCell = allocatedNext[memoryCell]
endloop
return memoryRepresentation
endmethod
endif
/*
* initialization
*/
private static method onInit takes nothing returns nothing
set recycler = Table.create()
debug set allocatedNext = Table.create()
debug set allocatedPrev = Table.create()
set recycler[0] = 1
endmethod
endmodule
endlibrary
library ErrorMessage /* v1.0.1.4
*************************************************************************************
*
* Issue Compliant Error Messages
*
************************************************************************************
*
* debug function ThrowError takes boolean expression, string libraryName, string functionName, string objectName, integer objectInstance, string description returns nothing
* - In the event of an error the game will be permanently paused
*
* debug function ThrowWarning takes boolean expression, string libraryName, string functionName, string objectName, integer objectInstance, string description returns nothing
*
************************************************************************************/
static if DEBUG_MODE then
private struct Fields extends array
static constant string COLOR_RED = "|cffff0000"
static constant string COLOR_YELLOW = "|cffffff00"
static string lastError = null
endstruct
private function Pause takes nothing returns nothing
call PauseGame(true)
endfunction
private function ThrowMessage takes string libraryName, string functionName, string objectName, integer objectInstance, string description, string errorType, string color returns nothing
local string str
local string color_braces = "|cff66FF99"
local string orange = "|cffff6600"
set str = "->\n-> " + color_braces + "{|r " + "Library" + color_braces + "(" + orange + libraryName + color_braces + ")"
if (objectName != null) then
if (objectInstance > 0) then
set str = str + "|r.Object" + color_braces + "(" + orange + objectName + color_braces + " (|rinstance = " + orange + I2S(objectInstance) + color_braces + ") )" + "|r." + "Method" + color_braces + "(" + orange + functionName + color_braces + ")"
else
set str = str + "|r.Object" + color_braces + "(" + orange + objectName + color_braces + ")|r." + "Method" + color_braces + "(" + orange + functionName + color_braces + ")"
endif
else
set str = str + "|r." + "Function" + color_braces + "(" + orange + functionName + color_braces + ")"
endif
set str = str + color_braces + " }|r " + "has thrown an exception of type " + color_braces + "(" + color + errorType + color_braces + ")|r."
set Fields.lastError = str + "\n->\n" + "-> " + color + description + "|r\n->"
endfunction
function ThrowError takes boolean expression, string libraryName, string functionName, string objectName, integer objectInstance, string description returns nothing
if (Fields.lastError != null) then
set objectInstance = 1/0
endif
if (expression) then
call ThrowMessage(libraryName, functionName, objectName, objectInstance, description, "Error", Fields.COLOR_RED)
call DisplayTimedTextToPlayer(GetLocalPlayer(),0,0,60000,Fields.lastError)
call TimerStart(CreateTimer(), 0, true, function Pause)
set objectInstance = 1/0
endif
endfunction
function ThrowWarning takes boolean expression, string libraryName, string functionName, string objectName, integer objectInstance, string description returns nothing
if (Fields.lastError != null) then
set objectInstance = 1/0
endif
if (expression) then
call ThrowMessage(libraryName, functionName, objectName, objectInstance, description, "Warning", Fields.COLOR_YELLOW)
call DisplayTimedTextToPlayer(GetLocalPlayer(),0,0,60000,Fields.lastError)
set Fields.lastError = null
endif
endfunction
endif
endlibrary
library ListT /* v1.0.1.0
************************************************************************************
*
* */ uses /*
*
* */ ErrorMessage /*
*
************************************************************************************
*
* module ListT
*
* Description
* -------------------------
*
* NA
*
* Fields
* -------------------------
*
* debug readonly boolean isList
* debug readonly boolean isElement
*
* readonly static integer sentinel
*
* readonly thistype list
*
* readonly thistype first
* readonly thistype last
*
* readonly thistype next
* readonly thistype prev
*
* Methods
* -------------------------
*
* static method create takes nothing returns thistype
* method destroy takes nothing returns nothing
* - May only destroy lists
*
* method push takes nothing returns thistype
* method enqueue takes nothing returns thistype
*
* method pop takes nothing returns nothing
* method dequeue takes nothing returns nothing
*
* method remove takes nothing returns nothing
*
* method clear takes nothing returns nothing
*
* debug static method calculateMemoryUsage takes nothing returns integer
* debug static method getAllocatedMemoryAsString takes nothing returns string
*
************************************************************************************/
private keyword isNode
private keyword isCollection
private keyword pp_list
private keyword pp_next
private keyword pp_prev
private keyword pp_first
private keyword pp_last
module ListT
private static thistype collectionCount = 0
private static thistype nodeCount = 0
debug private static Table p_isNode
debug method operator isNode takes nothing returns boolean
debug return p_isNode.boolean[this]
debug endmethod
debug method operator isNode= takes boolean value returns nothing
debug set p_isNode.boolean[this] = value
debug endmethod
debug private static Table p_isCollection
debug method operator isCollection takes nothing returns boolean
debug return p_isCollection.boolean[this]
debug endmethod
debug method operator isCollection= takes boolean value returns nothing
debug set p_isCollection.boolean[this] = value
debug endmethod
debug method operator isList takes nothing returns boolean
debug return isCollection
debug endmethod
debug method operator isElement takes nothing returns boolean
debug return isNode
debug endmethod
private static Table p_list
method operator pp_list takes nothing returns thistype
return p_list[this]
endmethod
method operator pp_list= takes thistype value returns nothing
set p_list[this] = value
endmethod
method operator list takes nothing returns thistype
debug call ThrowError(this == 0, "List", "list", "thistype", this, "Attempted To Read Null Node.")
debug call ThrowError(not isNode, "List", "list", "thistype", this, "Attempted To Read Invalid Node.")
return pp_list
endmethod
private static Table p_next
method operator pp_next takes nothing returns thistype
return p_next[this]
endmethod
method operator pp_next= takes thistype value returns nothing
set p_next[this] = value
endmethod
method operator next takes nothing returns thistype
debug call ThrowError(this == 0, "List", "next", "thistype", this, "Attempted To Go Out Of Bounds.")
debug call ThrowError(not isNode, "List", "next", "thistype", this, "Attempted To Read Invalid Node.")
return pp_next
endmethod
private static Table p_prev
method operator pp_prev takes nothing returns thistype
return p_prev[this]
endmethod
method operator pp_prev= takes thistype value returns nothing
set p_prev[this] = value
endmethod
method operator prev takes nothing returns thistype
debug call ThrowError(this == 0, "List", "prev", "thistype", this, "Attempted To Go Out Of Bounds.")
debug call ThrowError(not isNode, "List", "prev", "thistype", this, "Attempted To Read Invalid Node.")
return pp_prev
endmethod
private static Table p_first
method operator pp_first takes nothing returns thistype
return p_first[this]
endmethod
method operator pp_first= takes thistype value returns nothing
set p_first[this] = value
endmethod
method operator first takes nothing returns thistype
debug call ThrowError(this == 0, "List", "first", "thistype", this, "Attempted To Read Null List.")
debug call ThrowError(not isCollection, "List", "first", "thistype", this, "Attempted To Read Invalid List.")
return pp_first
endmethod
private static Table p_last
method operator pp_last takes nothing returns thistype
return p_last[this]
endmethod
method operator pp_last= takes thistype value returns nothing
set p_last[this] = value
endmethod
method operator last takes nothing returns thistype
debug call ThrowError(this == 0, "List", "last", "thistype", this, "Attempted To Read Null List.")
debug call ThrowError(not isCollection, "List", "last", "thistype", this, "Attempted To Read Invalid List.")
return pp_last
endmethod
static method operator sentinel takes nothing returns integer
return 0
endmethod
private static method allocateCollection takes nothing returns thistype
local thistype this = thistype(0).pp_first
if (0 == this) then
debug call ThrowError(collectionCount == 8191, "List", "allocateCollection", "thistype", 0, "Overflow.")
set this = collectionCount + 1
set collectionCount = this
else
set thistype(0).pp_first = pp_first
endif
return this
endmethod
private static method allocateNode takes nothing returns thistype
local thistype this = thistype(0).pp_next
if (0 == this) then
debug call ThrowError(nodeCount == 8191, "List", "allocateNode", "thistype", 0, "Overflow.")
set this = nodeCount + 1
set nodeCount = this
else
set thistype(0).pp_next = pp_next
endif
return this
endmethod
static method create takes nothing returns thistype
local thistype this = allocateCollection()
debug set isCollection = true
set pp_first = 0
return this
endmethod
method push takes nothing returns thistype
local thistype node = allocateNode()
debug call ThrowError(this == 0, "List", "push", "thistype", this, "Attempted To Push On To Null List.")
debug call ThrowError(not isCollection, "List", "push", "thistype", this, "Attempted To Push On To Invalid List.")
debug set node.isNode = true
set node.pp_list = this
if (pp_first == 0) then
set pp_first = node
set pp_last = node
set node.pp_next = 0
else
set pp_first.pp_prev = node
set node.pp_next = pp_first
set pp_first = node
endif
set node.pp_prev = 0
return node
endmethod
method enqueue takes nothing returns thistype
local thistype node = allocateNode()
debug call ThrowError(this == 0, "List", "enqueue", "thistype", this, "Attempted To Enqueue On To Null List.")
debug call ThrowError(not isCollection, "List", "enqueue", "thistype", this, "Attempted To Enqueue On To Invalid List.")
debug set node.isNode = true
set node.pp_list = this
if (pp_first == 0) then
set pp_first = node
set pp_last = node
set node.pp_prev = 0
else
set pp_last.pp_next = node
set node.pp_prev = pp_last
set pp_last = node
endif
set node.pp_next = 0
return node
endmethod
method pop takes nothing returns nothing
local thistype node = pp_first
debug call ThrowError(this == 0, "List", "pop", "thistype", this, "Attempted To Pop Null List.")
debug call ThrowError(not isCollection, "List", "pop", "thistype", this, "Attempted To Pop Invalid List.")
debug call ThrowError(node == 0, "List", "pop", "thistype", this, "Attempted To Pop Empty List.")
debug set node.isNode = false
set pp_first.pp_list = 0
set pp_first = pp_first.pp_next
if (pp_first == 0) then
set pp_last = 0
else
set pp_first.pp_prev = 0
endif
set node.pp_next = thistype(0).pp_next
set thistype(0).pp_next = node
endmethod
method dequeue takes nothing returns nothing
local thistype node = pp_last
debug call ThrowError(this == 0, "List", "dequeue", "thistype", this, "Attempted To Dequeue Null List.")
debug call ThrowError(not isCollection, "List", "dequeue", "thistype", this, "Attempted To Dequeue Invalid List.")
debug call ThrowError(node == 0, "List", "dequeue", "thistype", this, "Attempted To Dequeue Empty List.")
debug set node.isNode = false
set pp_last.pp_list = 0
set pp_last = pp_last.pp_prev
if (pp_last == 0) then
set pp_first = 0
else
set pp_last.pp_next = 0
endif
set node.pp_next = thistype(0).pp_next
set thistype(0).pp_next = node
endmethod
method remove takes nothing returns nothing
local thistype node = this
set this = node.pp_list
debug call ThrowError(node == 0, "List", "remove", "thistype", this, "Attempted To Remove Null Node.")
debug call ThrowError(not node.isNode, "List", "remove", "thistype", this, "Attempted To Remove Invalid Node (" + I2S(node) + ").")
debug set node.isNode = false
set node.pp_list = 0
if (0 == node.pp_prev) then
set pp_first = node.pp_next
else
set node.pp_prev.pp_next = node.pp_next
endif
if (0 == node.pp_next) then
set pp_last = node.pp_prev
else
set node.pp_next.pp_prev = node.pp_prev
endif
set node.pp_next = thistype(0).pp_next
set thistype(0).pp_next = node
endmethod
method clear takes nothing returns nothing
debug local thistype node = pp_first
debug call ThrowError(this == 0, "List", "clear", "thistype", this, "Attempted To Clear Null List.")
debug call ThrowError(not isCollection, "List", "clear", "thistype", this, "Attempted To Clear Invalid List.")
static if DEBUG_MODE then
loop
exitwhen node == 0
set node.isNode = false
set node = node.pp_next
endloop
endif
if (pp_first == 0) then
return
endif
set pp_last.pp_next = thistype(0).pp_next
set thistype(0).pp_next = pp_first
set pp_first = 0
set pp_last = 0
endmethod
method destroy takes nothing returns nothing
debug call ThrowError(this == 0, "List", "destroy", "thistype", this, "Attempted To Destroy Null List.")
debug call ThrowError(not isCollection, "List", "destroy", "thistype", this, "Attempted To Destroy Invalid List.")
static if DEBUG_MODE then
debug call clear()
debug set isCollection = false
else
if (pp_first != 0) then
set pp_last.pp_next = thistype(0).pp_next
set thistype(0).pp_next = pp_first
set pp_last = 0
endif
endif
set pp_first = thistype(0).pp_first
set thistype(0).pp_first = this
endmethod
private static method onInit takes nothing returns nothing
static if DEBUG_MODE then
set p_isNode = Table.create()
set p_isCollection = Table.create()
endif
set p_list = Table.create()
set p_next = Table.create()
set p_prev = Table.create()
set p_first = Table.create()
set p_last = Table.create()
endmethod
static if DEBUG_MODE then
static method calculateMemoryUsage takes nothing returns integer
local thistype start = 1
local thistype end = 8191
local integer count = 0
loop
exitwhen integer(start) > integer(end)
if (integer(start) + 500 > integer(end)) then
return count + checkRegion(start, end)
else
set count = count + checkRegion(start, start + 500)
set start = start + 501
endif
endloop
return count
endmethod
private static method checkRegion takes thistype start, thistype end returns integer
local integer count = 0
loop
exitwhen integer(start) > integer(end)
if (start.isNode) then
set count = count + 1
endif
if (start.isCollection) then
set count = count + 1
endif
set start = start + 1
endloop
return count
endmethod
static method getAllocatedMemoryAsString takes nothing returns string
local thistype start = 1
local thistype end = 8191
local string memory = null
loop
exitwhen integer(start) > integer(end)
if (integer(start) + 500 > integer(end)) then
if (memory != null) then
set memory = memory + ", "
endif
set memory = memory + checkRegion2(start, end)
set start = end + 1
else
if (memory != null) then
set memory = memory + ", "
endif
set memory = memory + checkRegion2(start, start + 500)
set start = start + 501
endif
endloop
return memory
endmethod
private static method checkRegion2 takes thistype start, thistype end returns string
local string memory = null
loop
exitwhen integer(start) > integer(end)
if (start.isNode) then
if (memory == null) then
set memory = I2S(start)
else
set memory = memory + ", " + I2S(start) + "N"
endif
endif
if (start.isCollection) then
if (memory == null) then
set memory = I2S(start)
else
set memory = memory + ", " + I2S(start) + "C"
endif
endif
set start = start + 1
endloop
return memory
endmethod
endif
endmodule
endlibrary
library Table /* made by Bribe, special thanks to Vexorian & Nestharus, version 3.1.0.3
One map, one hashtable. Welcome to NewTable 3.2
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 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
//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("Real", "Real", "real")
//! runtextmacro NEW_ARRAY("Boolean", "Boolean", "boolean")
//! runtextmacro NEW_ARRAY("String", "Str", "string")
//New textmacro to allow table.integer[] syntax for compatibility with textmacros that might desire it.
//! runtextmacro NEW_ARRAY("Integer", "Integer", "integer")
//! runtextmacro NEW_ARRAY("Handle", "PlayerHandle", "player")
//! runtextmacro NEW_ARRAY("Handle", "WidgetHandle", "widget")
//! runtextmacro NEW_ARRAY("Handle", "DestructableHandle", "destructable")
//! runtextmacro NEW_ARRAY("Handle", "ItemHandle", "item")
//! runtextmacro NEW_ARRAY("Handle", "UnitHandle", "unit")
//! runtextmacro NEW_ARRAY("Handle", "AbilityHandle", "ability")
//! runtextmacro NEW_ARRAY("Handle", "TimerHandle", "timer")
//! runtextmacro NEW_ARRAY("Handle", "TriggerHandle", "trigger")
//! runtextmacro NEW_ARRAY("Handle", "TriggerConditionHandle", "triggercondition")
//! runtextmacro NEW_ARRAY("Handle", "TriggerActionHandle", "triggeraction")
//! runtextmacro NEW_ARRAY("Handle", "TriggerEventHandle", "event")
//! runtextmacro NEW_ARRAY("Handle", "ForceHandle", "force")
//! runtextmacro NEW_ARRAY("Handle", "GroupHandle", "group")
//! runtextmacro NEW_ARRAY("Handle", "LocationHandle", "location")
//! runtextmacro NEW_ARRAY("Handle", "RectHandle", "rect")
//! runtextmacro NEW_ARRAY("Handle", "BooleanExprHandle", "boolexpr")
//! runtextmacro NEW_ARRAY("Handle", "SoundHandle", "sound")
//! runtextmacro NEW_ARRAY("Handle", "EffectHandle", "effect")
//! runtextmacro NEW_ARRAY("Handle", "UnitPoolHandle", "unitpool")
//! runtextmacro NEW_ARRAY("Handle", "ItemPoolHandle", "itempool")
//! runtextmacro NEW_ARRAY("Handle", "QuestHandle", "quest")
//! runtextmacro NEW_ARRAY("Handle", "QuestItemHandle", "questitem")
//! runtextmacro NEW_ARRAY("Handle", "DefeatConditionHandle", "defeatcondition")
//! runtextmacro NEW_ARRAY("Handle", "TimerDialogHandle", "timerdialog")
//! runtextmacro NEW_ARRAY("Handle", "LeaderboardHandle", "leaderboard")
//! runtextmacro NEW_ARRAY("Handle", "MultiboardHandle", "multiboard")
//! runtextmacro NEW_ARRAY("Handle", "MultiboardItemHandle", "multiboarditem")
//! runtextmacro NEW_ARRAY("Handle", "TrackableHandle", "trackable")
//! runtextmacro NEW_ARRAY("Handle", "DialogHandle", "dialog")
//! runtextmacro NEW_ARRAY("Handle", "ButtonHandle", "button")
//! runtextmacro NEW_ARRAY("Handle", "TextTagHandle", "texttag")
//! runtextmacro NEW_ARRAY("Handle", "LightningHandle", "lightning")
//! runtextmacro NEW_ARRAY("Handle", "ImageHandle", "image")
//! runtextmacro NEW_ARRAY("Handle", "UbersplatHandle", "ubersplat")
//! runtextmacro NEW_ARRAY("Handle", "RegionHandle", "region")
//! runtextmacro NEW_ARRAY("Handle", "FogStateHandle", "fogstate")
//! runtextmacro NEW_ARRAY("Handle", "FogModifierHandle", "fogmodifier")
//! runtextmacro NEW_ARRAY("Handle", "HashtableHandle", "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
library Init /* v1.0.0.0
************************************************************************************
*
* module Init
*
* interface private static method init takes nothing returns nothing
* - Runs at map init
*
*************************************************************************************
*
* module InitTimer
*
* interface private static method init takes nothing returns nothing
* - Runs after a one-shot timer with a period of 0
*
************************************************************************************/
module Init
static if thistype.init.exists then
private static method onInit takes nothing returns nothing
call init()
endmethod
endif
endmodule
module InitTimer
static if thistype.init.exists then
private static method initex takes nothing returns nothing
call DestroyTimer(GetExpiredTimer())
call init()
endmethod
private static method onInit takes nothing returns nothing
call TimerStart(CreateTimer(), 0, false, function thistype.initex)
endmethod
endif
endmodule
endlibrary
library NxListT /* v1.0.0.1
************************************************************************************
*
* */ uses /*
*
* */ ErrorMessage /*
* */ TableField /*
*
************************************************************************************
*
* module NxListT
*
* Description
* -------------------------
*
* NA
*
* Fields
* -------------------------
*
* readonly static integer sentinel
*
* readonly thistype list
*
* readonly thistype first
* readonly thistype last
*
* readonly thistype next
* readonly thistype prev
*
* Methods
* -------------------------
*
* method destroy takes nothing returns nothing
* - May only destroy lists
*
* method push takes nothing returns thistype
* method enqueue takes nothing returns thistype
*
* method pop takes nothing returns nothing
* method dequeue takes nothing returns nothing
*
* method remove takes nothing returns nothing
*
* method clear takes nothing returns nothing
* - Initializes list, use instead of create
*
* debug static method calculateMemoryUsage takes nothing returns integer
* debug static method getAllocatedMemoryAsString takes nothing returns string
*
************************************************************************************/
private keyword isNode
private keyword isCollection
private keyword p_list
private keyword p_next
private keyword p_prev
private keyword p_first
private keyword p_last
module NxListT
private static thistype nodeCount = 0
static if DEBUG_MODE then
//! runtextmacro CREATE_TABLE_FIELD("public", "boolean", "isNode", "boolean")
//! runtextmacro CREATE_TABLE_FIELD("public", "boolean", "isCollection", "boolean")
endif
//! runtextmacro CREATE_TABLE_FIELD("public", "integer", "p_list", "thistype")
method operator list takes nothing returns thistype
debug call ThrowError(this == 0, "NxList", "list", "thistype", this, "Attempted To Read Null Node.")
debug call ThrowError(not isNode, "NxList", "list", "thistype", this, "Attempted To Read Invalid Node.")
return p_list
endmethod
//! runtextmacro CREATE_TABLE_FIELD("public", "integer", "p_next", "thistype")
method operator next takes nothing returns thistype
debug call ThrowError(this == 0, "NxList", "next", "thistype", this, "Attempted To Go Out Of Bounds.")
debug call ThrowError(not isNode, "NxList", "next", "thistype", this, "Attempted To Read Invalid Node.")
return p_next
endmethod
//! runtextmacro CREATE_TABLE_FIELD("public", "integer", "p_prev", "thistype")
method operator prev takes nothing returns thistype
debug call ThrowError(this == 0, "NxList", "prev", "thistype", this, "Attempted To Go Out Of Bounds.")
debug call ThrowError(not isNode, "NxList", "prev", "thistype", this, "Attempted To Read Invalid Node.")
return p_prev
endmethod
//! runtextmacro CREATE_TABLE_FIELD("public", "integer", "p_first", "thistype")
method operator first takes nothing returns thistype
debug call ThrowError(this == 0, "NxList", "first", "thistype", this, "Attempted To Read Null List.")
debug call ThrowError(not isCollection, "NxList", "first", "thistype", this, "Attempted To Read Invalid List.")
return p_first
endmethod
//! runtextmacro CREATE_TABLE_FIELD("public", "integer", "p_last", "thistype")
method operator last takes nothing returns thistype
debug call ThrowError(this == 0, "NxList", "last", "thistype", this, "Attempted To Read Null List.")
debug call ThrowError(not isCollection, "NxList", "last", "thistype", this, "Attempted To Read Invalid List.")
return p_last
endmethod
static method operator sentinel takes nothing returns integer
return 0
endmethod
private static method allocateNode takes nothing returns thistype
local thistype this = thistype(0).p_next
if (0 == this) then
set this = nodeCount + 1
set nodeCount = this
else
set thistype(0).p_next = p_next
endif
return this
endmethod
method push takes nothing returns thistype
local thistype node = allocateNode()
debug call ThrowError(this == 0, "NxList", "push", "thistype", this, "Attempted To Push On To Null List.")
debug call ThrowError(not isCollection, "NxList", "push", "thistype", this, "Attempted To Push On To Invalid List.")
debug set node.isNode = true
set node.p_list = this
if (p_first == 0) then
set p_first = node
set p_last = node
set node.p_next = 0
else
set p_first.p_prev = node
set node.p_next = p_first
set p_first = node
endif
set node.p_prev = 0
return node
endmethod
method enqueue takes nothing returns thistype
local thistype node = allocateNode()
debug call ThrowError(this == 0, "NxList", "enqueue", "thistype", this, "Attempted To Enqueue On To Null List.")
debug call ThrowError(not isCollection, "NxList", "enqueue", "thistype", this, "Attempted To Enqueue On To Invalid List.")
debug set node.isNode = true
set node.p_list = this
if (p_first == 0) then
set p_first = node
set p_last = node
set node.p_prev = 0
else
set p_last.p_next = node
set node.p_prev = p_last
set p_last = node
endif
set node.p_next = 0
return node
endmethod
method pop takes nothing returns nothing
local thistype node = p_first
debug call ThrowError(this == 0, "NxList", "pop", "thistype", this, "Attempted To Pop Null List.")
debug call ThrowError(not isCollection, "NxList", "pop", "thistype", this, "Attempted To Pop Invalid List.")
debug call ThrowError(node == 0, "NxList", "pop", "thistype", this, "Attempted To Pop Empty List.")
debug set node.isNode = false
set p_first.p_list = 0
set p_first = p_first.p_next
if (p_first == 0) then
set p_last = 0
else
set p_first.p_prev = 0
endif
set node.p_next = thistype(0).p_next
set thistype(0).p_next = node
endmethod
method dequeue takes nothing returns nothing
local thistype node = p_last
debug call ThrowError(this == 0, "NxList", "dequeue", "thistype", this, "Attempted To Dequeue Null List.")
debug call ThrowError(not isCollection, "NxList", "dequeue", "thistype", this, "Attempted To Dequeue Invalid List.")
debug call ThrowError(node == 0, "NxList", "dequeue", "thistype", this, "Attempted To Dequeue Empty List.")
debug set node.isNode = false
set p_last.p_list = 0
set p_last = p_last.p_prev
if (p_last == 0) then
set p_first = 0
else
set p_last.p_next = 0
endif
set node.p_next = thistype(0).p_next
set thistype(0).p_next = node
endmethod
method remove takes nothing returns nothing
local thistype node = this
set this = node.p_list
debug call ThrowError(node == 0, "NxList", "remove", "thistype", this, "Attempted To Remove Null Node.")
debug call ThrowError(not node.isNode, "NxList", "remove", "thistype", this, "Attempted To Remove Invalid Node (" + I2S(node) + ").")
debug set node.isNode = false
set node.p_list = 0
if (0 == node.p_prev) then
set p_first = node.p_next
else
set node.p_prev.p_next = node.p_next
endif
if (0 == node.p_next) then
set p_last = node.p_prev
else
set node.p_next.p_prev = node.p_prev
endif
set node.p_next = thistype(0).p_next
set thistype(0).p_next = node
endmethod
method clear takes nothing returns nothing
debug local thistype node = p_first
debug call ThrowError(this == 0, "NxList", "clear", "thistype", this, "Attempted To Clear Null List.")
debug if (not isCollection) then
debug set isCollection = true
debug set p_first = 0
debug set p_last = 0
debug return
debug endif
static if DEBUG_MODE then
loop
exitwhen node == 0
set node.isNode = false
set node = node.p_next
endloop
endif
if (p_first == 0) then
return
endif
set p_last.p_next = thistype(0).p_next
set thistype(0).p_next = p_first
set p_first = 0
set p_last = 0
endmethod
method destroy takes nothing returns nothing
debug call ThrowError(this == 0, "NxList", "destroy", "thistype", this, "Attempted To Destroy Null List.")
debug call ThrowError(not isCollection, "NxList", "destroy", "thistype", this, "Attempted To Destroy Invalid List.")
call clear()
debug set isCollection = false
endmethod
private static method onInit takes nothing returns nothing
static if DEBUG_MODE then
//! runtextmacro INITIALIZE_TABLE_FIELD("isNode")
//! runtextmacro INITIALIZE_TABLE_FIELD("isCollection")
endif
//! runtextmacro INITIALIZE_TABLE_FIELD("p_list")
//! runtextmacro INITIALIZE_TABLE_FIELD("p_next")
//! runtextmacro INITIALIZE_TABLE_FIELD("p_prev")
//! runtextmacro INITIALIZE_TABLE_FIELD("p_first")
//! runtextmacro INITIALIZE_TABLE_FIELD("p_last")
endmethod
static if DEBUG_MODE then
static method calculateMemoryUsage takes nothing returns integer
local thistype start = 1
local thistype end = 8191
local integer count = 0
loop
exitwhen integer(start) > integer(end)
if (integer(start) + 500 > integer(end)) then
return count + checkRegion(start, end)
else
set count = count + checkRegion(start, start + 500)
set start = start + 501
endif
endloop
return count
endmethod
private static method checkRegion takes thistype start, thistype end returns integer
local integer count = 0
loop
exitwhen integer(start) > integer(end)
if (start.isNode) then
set count = count + 1
endif
if (start.isCollection) then
set count = count + 1
endif
set start = start + 1
endloop
return count
endmethod
static method getAllocatedMemoryAsString takes nothing returns string
local thistype start = 1
local thistype end = 8191
local string memory = null
loop
exitwhen integer(start) > integer(end)
if (integer(start) + 500 > integer(end)) then
set memory = memory + checkRegion2(start, end)
set start = end + 1
else
set memory = memory + checkRegion2(start, start + 500)
set start = start + 501
endif
endloop
return memory
endmethod
private static method checkRegion2 takes thistype start, thistype end returns string
local string memory = null
loop
exitwhen integer(start) > integer(end)
if (start.isNode) then
if (memory == null) then
set memory = I2S(start)
else
set memory = memory + ", " + I2S(start) + "N"
endif
endif
if (start.isCollection) then
if (memory == null) then
set memory = I2S(start)
else
set memory = memory + ", " + I2S(start) + "C"
endif
endif
set start = start + 1
endloop
return memory
endmethod
endif
endmodule
endlibrary
library BooleanExpression /* v1.2.0.0
************************************************************************************
*
* */ uses /*
*
* */ ErrorMessage /*
* */ ListT /*
* */ Table /*
* */ Init /*
* */ TableField /*
*
************************************************************************************
*
* struct BooleanExpression extends array
*
* Description
* -------------------------
*
* Creates a single boolean expression via Or's
*
* Provides a slight speed boost
*
* Allows the for the safe usage of TriggerRemoveCondition given that the only boolexpr on the trigger
* is the one from this struct
*
* To put multiple boolean expressions on to one trigger, combine them with Or. Be sure to destroy later.
*
* Alternatively, they can be wrapped with another BooleanExpression, but this will add overhead. Only use
* if more than three are planned to be on one trigger.
*
* Fields
* -------------------------
*
* readonly boolexpr expression
*
* Examples: call booleanExpression.register(myCode)
* call TriggerRemoveCondition(thisTrigger, theOneCondition)
* set theOneCondition = TriggerAddCondition(thisTrigger, booleanExpression.expression)
*
* boolean reversed
* - if this is true, the expression will run in reverse
*
* Methods
* -------------------------
*
* static method create takes boolean reversed returns BooleanExpression
* - if reversed is true, the expression will run in reverse
*
* method destroy takes nothing returns nothing
* - only use .destroy with BooleanExpression from .create, not .register
*
* method register takes boolexpr expression returns BooleanExpression
* - the returned BooleanExpression is a subtype to be used with
* - .unregister and .replace
* method unregister takes nothing returns nothing
* - unregisters a BooleanExpression
* - only use BooleanExpression from .register, not .create
*
* method replace takes boolexpr expression returns nothing
* - replaces the boolexpr inside of the registered expression
* - useful for updating expressions without breaking order
* - null expressions take no space and have no overhead, so use them
* - only use BooleanExpression from .register, not .create
*
* method clear takes nothing returns nothing
* - only use .clear with BooleanExpression from .create, not .register
*
* debug static method calculateMemoryUsage takes nothing returns integer
* - calculates how many instances are currently active
* debug static method getAllocatedMemoryAsString takes nothing returns string
* - returns a list of all active instances as a string
*
************************************************************************************/
private struct List extends array
//! runtextmacro CREATE_TABLE_FIELD("public", "boolean", "reversed", "boolean")
implement ListT
private static method init takes nothing returns nothing
//! runtextmacro INITIALIZE_TABLE_FIELD("reversed")
endmethod
implement Init
endstruct
private struct TreeNode extends array
/*
* Tree Fields
*/
//! runtextmacro CREATE_TABLE_FIELD("public", "integer", "root", "thistype")
//! runtextmacro CREATE_TABLE_FIELD("public", "integer", "left", "thistype")
//! runtextmacro CREATE_TABLE_FIELD("public", "integer", "right", "thistype")
//! runtextmacro CREATE_TABLE_FIELD("public", "integer", "height", "integer")
/*
* Standard Fields
*/
//! runtextmacro CREATE_TABLE_FIELD("public", "boolexpr", "expression", "boolexpr")
//! runtextmacro CREATE_TABLE_FIELD("public", "boolean", "canDestroy", "boolean")
///! runtextmacro CREATE_TABLE_FIELD("public", "integer", "list", "ListExpression")
public method operator isData takes nothing returns boolean
return height == 1
endmethod
public method operator isNode takes nothing returns boolean
return height != 1
endmethod
public method join takes nothing returns nothing
if (canDestroy) then
call DestroyBoolExpr(expression)
endif
if (left.expression == null) then
set canDestroy = false
if (right.expression == null) then
call expression_clear()
else
set expression = right.expression
endif
elseif (right.expression == null) then
set canDestroy = false
set expression = left.expression
elseif (List(this).list.reversed) then
set canDestroy = true
set expression = Or(right.expression, left.expression)
else
set canDestroy = true
set expression = Or(left.expression, right.expression)
endif
endmethod
public method rebuild takes nothing returns nothing
if (isNode) then
call left.rebuild()
call right.rebuild()
call join()
endif
endmethod
public method replace takes boolexpr expression returns nothing
if (this.expression == expression) then
return
endif
if (expression == null) then
call this.expression_clear()
else
set this.expression = expression
endif
loop
set this = root
exitwhen this == 0
call join()
endloop
endmethod
public static method create takes List parent returns thistype
local thistype this = parent.enqueue()
set canDestroy = false
set height = 1
return this
endmethod
public static method createData takes List parent returns thistype
local thistype this = parent.push()
set canDestroy = false
return this
endmethod
method clean takes nothing returns nothing
if (canDestroy) then
call DestroyBoolExpr(expression)
endif
call expression_clear()
endmethod
method destroy takes nothing returns nothing
call clean()
call List(this).remove()
endmethod
public method operator sibling takes nothing returns thistype
if (root != 0) then
if (root.left == this) then
return root.right
else
return root.left
endif
endif
return 0
endmethod
method updateHeight takes nothing returns nothing
if (left.height > right.height) then
set height = left.height + 1
else
set height = right.height + 1
endif
endmethod
method operator factor takes nothing returns integer
return left.height - right.height
endmethod
method setRoot takes thistype newNode returns nothing
local thistype root = this.root
if (root != 0) then
if (this == root.left) then
set root.left = newNode
else
set root.right = newNode
endif
endif
set newNode.root = root
endmethod
method rotateRight takes nothing returns thistype
local thistype newRoot = left
call setRoot(newRoot)
set root = newRoot
set left = newRoot.right
set left.root = this
set newRoot.right = this
call updateHeight()
call newRoot.updateHeight()
call join()
call newRoot.join()
return newRoot
endmethod
method rotateLeft takes nothing returns thistype
local thistype newRoot = right
call setRoot(newRoot)
set root = newRoot
set right = newRoot.left
set right.root = this
set newRoot.left = this
call updateHeight()
call newRoot.updateHeight()
call join()
call newRoot.join()
return newRoot
endmethod
method balance takes nothing returns thistype
local integer factor
local thistype node
loop
call updateHeight()
set factor = this.factor
if (factor > 1) then
if (left.factor < 0) then
call left.rotateLeft()
endif
set this = rotateRight()
exitwhen true
elseif (factor < -1) then
if (right.factor > 0) then
call right.rotateRight()
endif
set this = rotateLeft()
exitwhen true
else
call join()
endif
set this = root
exitwhen this == 0
endloop
if (this != 0) then
set node = root
loop
exitwhen node == 0
call node.updateHeight()
call node.join()
set node = node.root
endloop
endif
return this
endmethod
private static method init takes nothing returns nothing
//! runtextmacro INITIALIZE_TABLE_FIELD("root")
//! runtextmacro INITIALIZE_TABLE_FIELD("left")
//! runtextmacro INITIALIZE_TABLE_FIELD("right")
//! runtextmacro INITIALIZE_TABLE_FIELD("height")
//! runtextmacro INITIALIZE_TABLE_FIELD("expression")
//! runtextmacro INITIALIZE_TABLE_FIELD("canDestroy")
endmethod
implement Init
endstruct
private struct Tree extends array
//! runtextmacro CREATE_TABLE_FIELD("public", "integer", "root", "TreeNode")
public static method create takes boolean reversed returns thistype
local thistype this = List.create()
set List(this).reversed = reversed
return this
endmethod
method clear takes nothing returns nothing
local List node = List(this).first
loop
exitwhen node == 0
call TreeNode(node).clean()
set node = node.next
endloop
call List(this).clear()
call root_clear()
endmethod
method destroy takes nothing returns nothing
call clear()
call List(this).destroy()
endmethod
method operator reversed takes nothing returns boolean
return List(this).reversed
endmethod
method operator reversed= takes boolean b returns nothing
if (b == reversed) then
return
endif
set List(this).reversed = b
if (root != 0) then
call root.rebuild()
endif
endmethod
method updateRoot takes TreeNode node returns nothing
if (node != 0 and node.root == 0) then
set this.root = node
endif
endmethod
method insert takes boolexpr expression returns TreeNode
local TreeNode sibling = List(this).last
local TreeNode node = TreeNode.create(this)
local TreeNode root = 0
local TreeNode grandroot = 0
if (expression != null) then
set node.expression = expression
endif
if (sibling != 0) then
set root = TreeNode.createData(this)
set grandroot = sibling.root
set root.left = sibling
set root.right = node
set node.root = root
set sibling.root = root
set root.height = 2
set root.root = grandroot
call root.join()
if (grandroot != 0) then
set grandroot.right = root
call updateRoot(grandroot.balance())
else
set this.root = root
endif
else
set this.root = node
call node.root_clear()
endif
call node.left_clear()
call node.right_clear()
return node
endmethod
method delete takes TreeNode node returns nothing
local TreeNode sibling = node.sibling
local TreeNode root = node.root
local TreeNode grandroot
if (root != 0) then
set grandroot = root.root
endif
if (sibling != 0) then
if (sibling.isData) then
set sibling.root = grandroot
if (grandroot != 0) then
if (grandroot.left == root) then
set grandroot.left = sibling
else
set grandroot.right = sibling
endif
call updateRoot(grandroot.balance())
else
set this.root = sibling
endif
call root.destroy()
else
set root.left = sibling.left
set root.right = sibling.right
call root.updateHeight()
call root.join()
if (sibling.left != 0) then
set sibling.left.root = root
endif
if (sibling.right != 0) then
set sibling.right.root = root
endif
call sibling.destroy()
if (grandroot != 0) then
call updateRoot(grandroot.balance())
endif
endif
else
set this.root = 0
endif
call node.destroy()
endmethod
private static method init takes nothing returns nothing
//! runtextmacro INITIALIZE_TABLE_FIELD("root")
endmethod
implement Init
endstruct
struct BooleanExpression extends array
method operator expression takes nothing returns boolexpr
debug call ThrowError(not List(this).isList, "BooleanExpression", "expression", "BooleanExpression", this, "Attempted To Read Null Boolean Expression.")
if (Tree(this).root != 0) then
return Tree(this).root.expression
endif
return null
endmethod
method operator reversed takes nothing returns boolean
debug call ThrowError(not List(this).isList, "BooleanExpression", "reversed", "BooleanExpression", this, "Attempted To Read Null Boolean Expression.")
return Tree(this).reversed
endmethod
method operator reversed= takes boolean b returns nothing
debug call ThrowError(not List(this).isList, "BooleanExpression", "reversed", "BooleanExpression", this, "Attempted To Set Null Boolean Expression.")
set Tree(this).reversed = b
endmethod
static method create takes boolean reversed returns thistype
return Tree.create(reversed)
endmethod
method destroy takes nothing returns nothing
debug call ThrowError(not List(this).isList, "BooleanExpression", "reversed", "BooleanExpression", this, "Attempted To Destroy Null Boolean Expression.")
call Tree(this).destroy()
endmethod
method register takes boolexpr expression returns BooleanExpression
return Tree(this).insert(expression)
endmethod
method unregister takes nothing returns nothing
debug call ThrowError(not TreeNode(this).isData, "BooleanExpression", "unregister", "BooleanExpression", this, "Attempted To Unregister Null Boolean Expression.")
call Tree(List(this).list).delete(this)
endmethod
method replace takes boolexpr expression returns nothing
debug call ThrowError(not TreeNode(this).isData, "BooleanExpression", "replace", "BooleanExpression", this, "Attempted To Replace Null Boolean Expression.")
call TreeNode(this).replace(expression)
endmethod
method clear takes nothing returns nothing
debug call ThrowError(not List(this).isList, "BooleanExpression", "clear", "BooleanExpression", this, "Attempted To Clear Null Boolean Expression.")
call Tree(this).clear()
endmethod
private static string indentation = " "
static method printEx takes TreeNode node, string indent, boolean height returns nothing
if (node != 0) then
call printEx(node.right, indent + indentation, height)
if (height) then
call DisplayTimedTextToPlayer(GetLocalPlayer(), 0, 0, 60000, indent + I2S(node.height))
else
call DisplayTimedTextToPlayer(GetLocalPlayer(), 0, 0, 60000, indent + I2S(node))
endif
call printEx(node.left, indent + indentation, height)
endif
endmethod
method print takes boolean height returns nothing
call printEx(Tree(this).root, "", height)
call DisplayTimedTextFromPlayer(GetLocalPlayer(), 0, 0, 60000, "------------------------------------")
endmethod
debug static method calculateMemoryUsage takes nothing returns integer
debug return List.calculateMemoryUsage()
debug endmethod
debug static method getAllocatedMemoryAsString takes nothing returns string
debug return List.getAllocatedMemoryAsString()
debug endmethod
endstruct
endlibrary
library TableField /* v1.0.0.1
************************************************************************************
*
* */ uses /*
*
* */ Table /*
* */ Init /*
*
************************************************************************************
*
* //! textmacro CREATE_TABLE_FIELD takes ACCESS_MODIFIER, TYPE, NAME, RETURN_TYPE
* - creates a table field surrounded by method operators
*
* //! textmacro INITIALIZE_TABLE_FIELD takes NAME
* - initializes table field
* - used in onInit
*
* //! textmacro CREATE_TABLE_FIELD_ARRAY takes TYPE, NAME, RETURN_TYPE
* - creates a struct that acts as an array
* - not used in a struct
*
* //! textmacro USE_TABLE_FIELD_ARRAY takes ACCESS_MODIFIER, NAME
* - creates a field of a struct array
* - used in a struct
*
************************************************************************************/
//! textmacro CREATE_TABLE_FIELD takes ACCESS_MODIFIER, TYPE, NAME, RETURN_TYPE
private static Table t$NAME$
$ACCESS_MODIFIER$ method operator $NAME$ takes nothing returns $RETURN_TYPE$
return t$NAME$.$TYPE$[this]
endmethod
$ACCESS_MODIFIER$ method operator $NAME$= takes $RETURN_TYPE$ value returns nothing
set t$NAME$.$TYPE$[this] = value
endmethod
$ACCESS_MODIFIER$ method $NAME$_clear takes nothing returns nothing
call t$NAME$.$TYPE$.remove(this)
endmethod
//! endtextmacro
//! textmacro CREATE_TABLE_FIELD_ARRAY takes TYPE, NAME, RETURN_TYPE
private struct T$NAME$ extends array
private static Table table
method operator [] takes integer index returns $RETURN_TYPE$
return table.$TYPE$[index]
endmethod
method operator []= takes integer index, $RETURN_TYPE$ value returns nothing
set table.$TYPE$[index] = value
endmethod
static method remove takes integer index returns nothing
call table.$TYPE$.remove(index)
endmethod
static method clear takes nothing returns nothing
call table.flush()
endmethod
private static method init takes nothing returns nothing
set table = Table.create()
endmethod
implement Init
endstruct
//! endtextmacro
//! textmacro USE_TABLE_FIELD_ARRAY takes ACCESS_MODIFIER, NAME
$ACCESS_MODIFIER$ static T$NAME$ $NAME$ = 0
//! endtextmacro
//! textmacro INITIALIZE_TABLE_FIELD takes NAME
set t$NAME$ = Table.create()
//! endtextmacro
endlibrary
library UniqueNxListT /* v1.0.0.1
************************************************************************************
*
* */ uses /*
*
* */ ErrorMessage /*
* */ TableField /*
*
************************************************************************************
*
* module UniqueNxListT
*
* Description
* -------------------------
*
* Node Properties:
*
* Unique
* Allocated
* Not 0
*
* Fields
* -------------------------
*
* readonly static integer sentinel
*
* readonly thistype list
*
* readonly thistype first
* readonly thistype last
*
* readonly thistype next
* readonly thistype prev
*
* Methods
* -------------------------
*
* method destroy takes nothing returns nothing
* - May only destroy lists
*
* method push takes thistype node returns nothing
* method enqueue takes thistype node returns nothing
*
* method pop takes nothing returns nothing
* method dequeue takes nothing returns nothing
*
* method remove takes nothing returns nothing
*
* method clear takes nothing returns nothing
* - Initializes list, use instead of create
*
* debug static method calculateMemoryUsage takes nothing returns integer
* debug static method getAllocatedMemoryAsString takes nothing returns string
*
************************************************************************************/
private keyword isNode
private keyword isCollection
private keyword p_list
private keyword p_next
private keyword p_prev
private keyword p_first
private keyword p_last
module UniqueNxListT
static if DEBUG_MODE then
//! runtextmacro CREATE_TABLE_FIELD("public", "boolean", "isNode", "boolean")
//! runtextmacro CREATE_TABLE_FIELD("public", "boolean", "isCollection", "boolean")
endif
//! runtextmacro CREATE_TABLE_FIELD("public", "integer", "p_list", "thistype")
method operator list takes nothing returns thistype
debug call ThrowError(this == 0, "UniqueNxListT", "list", "thistype", this, "Attempted To Read Null Node.")
debug call ThrowError(not isNode, "UniqueNxListT", "list", "thistype", this, "Attempted To Read Invalid Node.")
return p_list
endmethod
//! runtextmacro CREATE_TABLE_FIELD("public", "integer", "p_next", "thistype")
method operator next takes nothing returns thistype
debug call ThrowError(this == 0, "UniqueNxListT", "next", "thistype", this, "Attempted To Go Out Of Bounds.")
debug call ThrowError(not isNode, "UniqueNxListT", "next", "thistype", this, "Attempted To Read Invalid Node.")
return p_next
endmethod
//! runtextmacro CREATE_TABLE_FIELD("public", "integer", "p_prev", "thistype")
method operator prev takes nothing returns thistype
debug call ThrowError(this == 0, "UniqueNxListT", "prev", "thistype", this, "Attempted To Go Out Of Bounds.")
debug call ThrowError(not isNode, "UniqueNxListT", "prev", "thistype", this, "Attempted To Read Invalid Node.")
return p_prev
endmethod
//! runtextmacro CREATE_TABLE_FIELD("public", "integer", "p_first", "thistype")
method operator first takes nothing returns thistype
debug call ThrowError(this == 0, "UniqueNxListT", "first", "thistype", this, "Attempted To Read Null List.")
debug call ThrowError(not isCollection, "UniqueNxListT", "first", "thistype", this, "Attempted To Read Invalid List.")
return p_first
endmethod
//! runtextmacro CREATE_TABLE_FIELD("public", "integer", "p_last", "thistype")
method operator last takes nothing returns thistype
debug call ThrowError(this == 0, "UniqueNxListT", "last", "thistype", this, "Attempted To Read Null List.")
debug call ThrowError(not isCollection, "UniqueNxListT", "last", "thistype", this, "Attempted To Read Invalid List.")
return p_last
endmethod
static method operator sentinel takes nothing returns integer
return 0
endmethod
method push takes thistype node returns nothing
debug call ThrowError(this == 0, "UniqueNxListT", "push", "thistype", this, "Attempted To Push (" + I2S(node) + ") On To Null List.")
debug call ThrowError(not isCollection, "UniqueNxListT", "push", "thistype", this, "Attempted To Push (" + I2S(node) + ") On To Invalid List.")
debug call ThrowError(node == 0, "UniqueNxListT", "push", "thistype", this, "Attempted To Push Null Node.")
debug call ThrowError(node.isNode, "UniqueNxListT", "push", "thistype", this, "Attempted To Push Owned Node (" + I2S(node) + ").")
debug set node.isNode = true
set node.p_list = this
if (p_first == 0) then
set p_first = node
set p_last = node
set node.p_next = 0
else
set p_first.p_prev = node
set node.p_next = p_first
set p_first = node
endif
set node.p_prev = 0
endmethod
method enqueue takes thistype node returns nothing
debug call ThrowError(this == 0, "UniqueNxListT", "enqueue", "thistype", this, "Attempted To Enqueue (" + I2S(node) + ") On To Null List.")
debug call ThrowError(not isCollection, "UniqueNxListT", "enqueue", "thistype", this, "Attempted To Enqueue (" + I2S(node) + ") On To Invalid List.")
debug call ThrowError(node == 0, "UniqueNxListT", "enqueue", "thistype", this, "Attempted To Enqueue Null Node.")
debug call ThrowError(node.isNode, "UniqueNxListT", "enqueue", "thistype", this, "Attempted To Enqueue Owned Node (" + I2S(node) + ").")
debug set node.isNode = true
set node.p_list = this
if (p_first == 0) then
set p_first = node
set p_last = node
set node.p_prev = 0
else
set p_last.p_next = node
set node.p_prev = p_last
set p_last = node
endif
set node.p_next = 0
endmethod
method pop takes nothing returns nothing
debug call ThrowError(this == 0, "UniqueNxListT", "pop", "thistype", this, "Attempted To Pop Null List.")
debug call ThrowError(not isCollection, "UniqueNxListT", "pop", "thistype", this, "Attempted To Pop Invalid List.")
debug call ThrowError(p_first == 0, "UniqueNxListT", "pop", "thistype", this, "Attempted To Pop Empty List.")
debug set p_first.isNode = false
set p_first.p_list = 0
set p_first = p_first.p_next
if (p_first == 0) then
set p_last = 0
else
set p_first.p_prev = 0
endif
endmethod
method dequeue takes nothing returns nothing
debug call ThrowError(this == 0, "UniqueNxListT", "dequeue", "thistype", this, "Attempted To Dequeue Null List.")
debug call ThrowError(not isCollection, "UniqueNxListT", "dequeue", "thistype", this, "Attempted To Dequeue Invalid List.")
debug call ThrowError(p_last == 0, "UniqueNxListT", "dequeue", "thistype", this, "Attempted To Dequeue Empty List.")
debug set p_last.isNode = false
set p_last.p_list = 0
set p_last = p_last.p_prev
if (p_last == 0) then
set p_first = 0
else
set p_last.p_next = 0
endif
endmethod
method remove takes nothing returns nothing
local thistype node = this
set this = node.p_list
debug call ThrowError(node == 0, "UniqueNxListT", "remove", "thistype", this, "Attempted To Remove Null Node.")
debug call ThrowError(not node.isNode, "UniqueNxListT", "remove", "thistype", this, "Attempted To Remove Invalid Node (" + I2S(node) + ").")
debug set node.isNode = false
set node.p_list = 0
if (0 == node.p_prev) then
set p_first = node.p_next
else
set node.p_prev.p_next = node.p_next
endif
if (0 == node.p_next) then
set p_last = node.p_prev
else
set node.p_next.p_prev = node.p_prev
endif
endmethod
method clear takes nothing returns nothing
debug local thistype node = p_first
debug call ThrowError(this == 0, "UniqueNxListT", "clear", "thistype", this, "Attempted To Clear Null List.")
debug if (not isCollection) then
debug set isCollection = true
debug set p_first = 0
debug set p_last = 0
debug return
debug endif
static if DEBUG_MODE then
loop
exitwhen node == 0
set node.isNode = false
set node = node.p_next
endloop
endif
if (p_first == 0) then
return
endif
set p_first = 0
set p_last = 0
endmethod
method destroy takes nothing returns nothing
debug call ThrowError(this == 0, "UniqueNxListT", "destroy", "thistype", this, "Attempted To Destroy Null List.")
debug call ThrowError(not isCollection, "UniqueNxListT", "destroy", "thistype", this, "Attempted To Destroy Invalid List.")
call clear()
debug set isCollection = false
endmethod
private static method onInit takes nothing returns nothing
static if DEBUG_MODE then
//! runtextmacro INITIALIZE_TABLE_FIELD("isNode")
//! runtextmacro INITIALIZE_TABLE_FIELD("isCollection")
endif
//! runtextmacro INITIALIZE_TABLE_FIELD("p_list")
//! runtextmacro INITIALIZE_TABLE_FIELD("p_next")
//! runtextmacro INITIALIZE_TABLE_FIELD("p_prev")
//! runtextmacro INITIALIZE_TABLE_FIELD("p_first")
//! runtextmacro INITIALIZE_TABLE_FIELD("p_last")
endmethod
static if DEBUG_MODE then
static method calculateMemoryUsage takes nothing returns integer
local thistype start = 1
local thistype end = 8191
local integer count = 0
loop
exitwhen integer(start) > integer(end)
if (integer(start) + 500 > integer(end)) then
return count + checkRegion(start, end)
else
set count = count + checkRegion(start, start + 500)
set start = start + 501
endif
endloop
return count
endmethod
private static method checkRegion takes thistype start, thistype end returns integer
local integer count = 0
loop
exitwhen integer(start) > integer(end)
if (start.isNode) then
set count = count + 1
endif
if (start.isCollection) then
set count = count + 1
endif
set start = start + 1
endloop
return count
endmethod
static method getAllocatedMemoryAsString takes nothing returns string
local thistype start = 1
local thistype end = 8191
local string memory = null
loop
exitwhen integer(start) > integer(end)
if (integer(start) + 500 > integer(end)) then
set memory = memory + checkRegion2(start, end)
set start = end + 1
else
set memory = memory + checkRegion2(start, start + 500)
set start = start + 501
endif
endloop
return memory
endmethod
private static method checkRegion2 takes thistype start, thistype end returns string
local string memory = null
loop
exitwhen integer(start) > integer(end)
if (start.isNode) then
if (memory == null) then
set memory = I2S(start)
else
set memory = memory + ", " + I2S(start) + "N"
endif
endif
if (start.isCollection) then
if (memory == null) then
set memory = I2S(start)
else
set memory = memory + ", " + I2S(start) + "C"
endif
endif
set start = start + 1
endloop
return memory
endmethod
endif
endmodule
endlibrary
library Trigger /* v1.1.0.2
************************************************************************************
*
* */ uses /*
*
* */ ErrorMessage /*
* */ BooleanExpression /*
* */ NxListT /*
* */ UniqueNxListT /*
* */ Init /*
* */ AllocT /*
*
************************************************************************************
*
* struct Trigger extends array
*
* Fields
* -------------------------
*
* readonly trigger trigger
* - use to register events, nothing else
* - keep in mind that triggers referencing this trigger won't fire when events fire
* - this trigger will fire when triggers referencing this trigger are fired
*
* boolean enabled
*
* Methods
* -------------------------
*
* static method create takes boolean reversed returns Trigger
* - when reverse is true, the entire expression is run in reverse
*
* method destroy takes nothing returns nothing
*
* method register takes boolexpr expression returns TriggerCondition
*
* method reference takes Trigger trig returns TriggerReference
* - like register, but for triggers instead
*
* method fire takes nothing returns nothing
*
* method clear takes nothing returns nothing
* - clears expressions
* method clearReferences takes nothing returns nothing
* - clears trigger references
* method clearBackReferences takes nothing returns nothing
* - removes references for all triggers referencing this trigger
* method clearEvents takes nothing returns nothing
* - clears events
*
* debug static method calculateMemoryUsage takes nothing returns integer
* debug static method getAllocatedMemoryAsString takes nothing returns string
*
************************************************************************************
*
* struct TriggerReference extends array
*
* Methods
* -------------------------
*
* method destroy takes nothing returns nothing
*
* method replace takes Trigger trigger returns nothing
*
************************************************************************************
*
* struct TriggerCondition extends array
*
* Methods
* -------------------------
*
* method destroy takes nothing returns nothing
*
* method replace takes boolexpr expr returns nothing
*
************************************************************************************/
private struct TriggerMemory extends array
//! runtextmacro CREATE_TABLE_FIELD("public", "trigger", "trig", "trigger")
//! runtextmacro CREATE_TABLE_FIELD("public", "triggercondition", "tc", "triggercondition")
//! runtextmacro CREATE_TABLE_FIELD("public", "integer", "expression", "BooleanExpression") //the trigger's expression
//! runtextmacro CREATE_TABLE_FIELD("public", "boolean", "enabled", "boolean")
method updateTrigger takes nothing returns nothing
if (tc != null) then
call TriggerRemoveCondition(trig, tc)
endif
if (enabled and expression.expression != null) then
set tc = TriggerAddCondition(trig, expression.expression)
else
call tc_clear()
endif
endmethod
private static method init takes nothing returns nothing
//! runtextmacro INITIALIZE_TABLE_FIELD("trig")
//! runtextmacro INITIALIZE_TABLE_FIELD("tc")
//! runtextmacro INITIALIZE_TABLE_FIELD("expression")
//! runtextmacro INITIALIZE_TABLE_FIELD("enabled")
endmethod
implement Init
endstruct
private struct TriggerAllocator extends array
implement AllocT
endstruct
private keyword TriggerReferencedList
private struct TriggerReferenceListData extends array
//! runtextmacro CREATE_TABLE_FIELD("public", "integer", "trig", "TriggerMemory") //the referenced trigger
//! runtextmacro CREATE_TABLE_FIELD("public", "integer", "ref", "TriggerReferencedList") //the TriggerReferencedList data for that trigger (relationship in 2 places)
//! runtextmacro CREATE_TABLE_FIELD("public", "integer", "expr", "BooleanExpression")
implement NxListT
private static method init takes nothing returns nothing
//! runtextmacro INITIALIZE_TABLE_FIELD("trig")
//! runtextmacro INITIALIZE_TABLE_FIELD("ref")
//! runtextmacro INITIALIZE_TABLE_FIELD("expr")
endmethod
implement Init
endstruct
/*
* List of triggers referencing current trigger
*/
private struct TriggerReferencedList extends array
//! runtextmacro CREATE_TABLE_FIELD("public", "integer", "trig", "TriggerMemory") //the trigger referencing this trigger
//! runtextmacro CREATE_TABLE_FIELD("public", "integer", "ref", "TriggerReferenceListData") //the ref
implement NxListT
method updateExpression takes nothing returns nothing
local thistype node
local boolexpr expr
/*
* Retrieve the expression of the referenced trigger
*/
if (TriggerMemory(this).enabled) then
set expr = TriggerMemory(this).expression.expression
else
set expr = null
endif
/*
* Iterate over all triggers referencing this trigger
*/
set node = first
loop
exitwhen node == 0
/*
* Replace expression and then update the target trigger
*/
call node.ref.expr.replace(expr)
call node.trig.updateTrigger()
call TriggerReferencedList(node.trig).updateExpression()
set node = node.next
endloop
set expr = null
endmethod
method purge takes nothing returns nothing
local thistype node = first
loop
exitwhen node == 0
/*
* Unregister the expression from the referencing trigger
* Update that trigger
*/
call node.ref.expr.unregister()
call node.trig.updateTrigger()
call node.ref.remove()
call TriggerReferencedList(node.trig).updateExpression()
set node = node.next
endloop
call destroy()
endmethod
method clearReferences takes nothing returns nothing
local thistype node = first
loop
exitwhen node == 0
/*
* Unregister the expression from the referencing trigger
* Update that trigger
*/
call node.ref.expr.unregister()
call node.trig.updateTrigger()
call node.ref.remove()
call TriggerReferencedList(node.trig).updateExpression()
set node = node.next
endloop
call clear()
endmethod
private static method init takes nothing returns nothing
//! runtextmacro INITIALIZE_TABLE_FIELD("trig")
//! runtextmacro INITIALIZE_TABLE_FIELD("ref")
endmethod
implement Init
endstruct
/*
* List of triggers current trigger references
*/
private struct TriggerReferenceList extends array
method add takes TriggerReferencedList trig returns thistype
local TriggerReferenceListData node = TriggerReferenceListData(this).enqueue()
/*
* Register the trigger as a reference
*/
set node.trig = trig
set node.ref = TriggerReferencedList(trig).enqueue()
set node.ref.trig = this
set node.ref.ref = node
/*
* Add the reference's expression
*
* Add even if null to ensure correct order
*/
if (TriggerMemory(trig).enabled) then
set node.expr = TriggerMemory(this).expression.register(TriggerMemory(trig).expression.expression)
else
set node.expr = TriggerMemory(this).expression.register(null)
endif
call TriggerMemory(this).updateTrigger()
/*
* Update the expressions of triggers referencing this trigger
*/
call TriggerReferencedList(this).updateExpression()
/*
* Return the reference
*/
return node
endmethod
method erase takes nothing returns nothing
local TriggerReferenceListData node = this //the node
set this = node.ref.trig //this trigger
call node.expr.unregister()
call TriggerMemory(this).updateTrigger()
call TriggerReferencedList(this).updateExpression()
call node.ref.remove()
call node.remove()
endmethod
method replace takes TriggerMemory trig returns nothing
local TriggerReferenceListData node = this
set this = node.list
call node.ref.remove()
set node.trig = trig
set node.ref = TriggerReferencedList(trig).enqueue()
set node.ref.trig = this
set node.ref.ref = node
if (trig.enabled) then
call node.expr.replace(trig.expression.expression)
else
call node.expr.replace(null)
endif
call TriggerMemory(this).updateTrigger()
call TriggerReferencedList(this).updateExpression()
endmethod
/*
* Purges all references
*/
method purge takes nothing returns nothing
local TriggerReferenceListData node = TriggerReferenceListData(this).first
loop
exitwhen node == 0
/*
* Removes the reference from the referenced list
* (triggers no longer referenced by this)
*/
call node.ref.remove()
set node = node.next
endloop
/*
* Destroy all references by triggers referencing this
*/
call TriggerReferencedList(this).purge()
call TriggerReferenceListData(this).destroy()
endmethod
method clearReferences takes nothing returns nothing
local TriggerReferenceListData node = TriggerReferenceListData(this).first
loop
exitwhen node == 0
/*
* Removes the reference from the referenced list
* (triggers no longer referenced by this)
*/
call node.ref.remove()
/*
* unregisters code
*/
call node.expr.unregister()
set node = node.next
endloop
call TriggerReferenceListData(this).clear()
endmethod
endstruct
private struct TriggerReferenceData extends array
static if DEBUG_MODE then
//! runtextmacro CREATE_TABLE_FIELD("private", "boolean", "isTriggerReference", "boolean")
endif
static method create takes TriggerReferenceList origin, TriggerMemory ref returns thistype
local thistype this = origin.add(ref)
debug set isTriggerReference = true
return this
endmethod
method destroy takes nothing returns nothing
debug call ThrowError(this == 0, "Trigger", "destroy", "TriggerReferenceData", this, "Attempted To Destroy Null TriggerReferenceData.")
debug call ThrowError(not isTriggerReference, "Trigger", "destroy", "TriggerReferenceData", this, "Attempted To Destroy Invalid TriggerReferenceData.")
debug set isTriggerReference = false
call TriggerReferenceList(this).erase()
endmethod
method replace takes Trigger trig returns nothing
debug call ThrowError(this == 0, "Trigger", "destroy", "TriggerReferenceData", this, "Attempted To Destroy Null TriggerReferenceData.")
debug call ThrowError(not isTriggerReference, "Trigger", "destroy", "TriggerReferenceData", this, "Attempted To Destroy Invalid TriggerReferenceData.")
call TriggerReferenceList(this).replace(trig)
endmethod
private static method init takes nothing returns nothing
static if DEBUG_MODE then
//! runtextmacro INITIALIZE_TABLE_FIELD("isTriggerReference")
endif
endmethod
implement Init
endstruct
private struct TriggerConditionDataCollection extends array
implement UniqueNxListT
endstruct
private struct TriggerConditionData extends array
static if DEBUG_MODE then
//! runtextmacro CREATE_TABLE_FIELD("private", "boolean", "isCondition", "boolean")
endif
//! runtextmacro CREATE_TABLE_FIELD("private", "integer", "trig", "TriggerMemory")
private static method updateTrigger takes TriggerMemory trig returns nothing
call trig.updateTrigger()
call TriggerReferencedList(trig).updateExpression()
endmethod
static method create takes TriggerMemory trig, boolexpr expression returns thistype
local thistype this = trig.expression.register(expression)
set this.trig = trig
debug set isCondition = true
call TriggerConditionDataCollection(trig).enqueue(this)
call updateTrigger(trig)
return this
endmethod
method destroy takes nothing returns nothing
debug call ThrowError(this == 0, "Trigger", "destroy", "TriggerConditionData", this, "Attempted To Destroy Null TriggerConditionData.")
debug call ThrowError(not isCondition, "Trigger", "destroy", "TriggerConditionData", this, "Attempted To Destroy Invalid TriggerConditionData.")
call BooleanExpression(this).unregister()
call TriggerConditionDataCollection(this).remove()
debug set isCondition = false
/*
* Update the expression
*/
call updateTrigger(trig)
endmethod
method replace takes boolexpr expr returns nothing
debug call ThrowError(this == 0, "Trigger", "destroy", "TriggerConditionData", this, "Attempted To Destroy Null TriggerConditionData.")
debug call ThrowError(not isCondition, "Trigger", "destroy", "TriggerConditionData", this, "Attempted To Destroy Invalid TriggerConditionData.")
call BooleanExpression(this).replace(expr)
call updateTrigger(trig)
endmethod
private static method init takes nothing returns nothing
static if DEBUG_MODE then
//! runtextmacro INITIALIZE_TABLE_FIELD("isCondition")
endif
//! runtextmacro INITIALIZE_TABLE_FIELD("trig")
endmethod
implement Init
endstruct
struct TriggerReference extends array
method destroy takes nothing returns nothing
call TriggerReferenceData(this).destroy()
endmethod
method replace takes Trigger trig returns nothing
call TriggerReferenceData(this).replace(trig)
endmethod
endstruct
struct TriggerCondition extends array
method destroy takes nothing returns nothing
call TriggerConditionData(this).destroy()
endmethod
method replace takes boolexpr expr returns nothing
call TriggerConditionData(this).replace(expr)
endmethod
endstruct
struct Trigger extends array
static if DEBUG_MODE then
//! runtextmacro CREATE_TABLE_FIELD("private", "boolean", "isTrigger", "boolean")
endif
static method create takes boolean reversed returns thistype
local thistype this = TriggerAllocator.allocate()
debug set isTrigger = true
set TriggerMemory(this).enabled = true
call TriggerReferencedList(this).clear()
call TriggerReferenceListData(this).clear()
call TriggerConditionDataCollection(this).clear()
set TriggerMemory(this).expression = BooleanExpression.create(reversed)
set TriggerMemory(this).trig = CreateTrigger()
return this
endmethod
static if DEBUG_MODE then
method destroy takes nothing returns nothing
call destroy_p()
endmethod
private method destroy_p takes nothing returns nothing
debug call ThrowError(this == 0, "Trigger", "destroy", "Trigger", this, "Attempted To Destroy Null Trigger.")
debug call ThrowError(not isTrigger, "Trigger", "destroy", "Trigger", this, "Attempted To Destroy Invalid Trigger.")
debug set isTrigger = false
call TriggerReferenceList(this).purge()
call TriggerConditionDataCollection(this).destroy()
if (TriggerMemory(this).tc != null) then
call TriggerRemoveCondition(TriggerMemory(this).trig, TriggerMemory(this).tc)
endif
call TriggerMemory(this).tc_clear()
call DestroyTrigger(TriggerMemory(this).trig)
call TriggerMemory(this).trig_clear()
call TriggerMemory(this).expression.destroy()
call TriggerAllocator(this).deallocate()
endmethod
else
method destroy takes nothing returns nothing
debug call ThrowError(this == 0, "Trigger", "destroy", "Trigger", this, "Attempted To Destroy Null Trigger.")
debug call ThrowError(not isTrigger, "Trigger", "destroy", "Trigger", this, "Attempted To Destroy Invalid Trigger.")
debug set isTrigger = false
call TriggerReferenceList(this).purge()
call TriggerConditionDataCollection(this).destroy()
if (TriggerMemory(this).tc != null) then
call TriggerRemoveCondition(TriggerMemory(this).trig, TriggerMemory(this).tc)
endif
call TriggerMemory(this).tc_clear()
call DestroyTrigger(TriggerMemory(this).trig)
call TriggerMemory(this).trig_clear()
call TriggerMemory(this).expression.destroy()
call TriggerAllocator(this).deallocate()
endmethod
endif
static if DEBUG_MODE then
method register takes boolexpr expression returns TriggerCondition
return register_p(expression)
endmethod
private method register_p takes boolexpr expression returns TriggerCondition
debug call ThrowError(this == 0, "Trigger", "register", "Trigger", this, "Attempted To Register To Null Trigger.")
debug call ThrowError(not isTrigger, "Trigger", "register", "Trigger", this, "Attempted To Register To Invalid Trigger.")
/*
* Register the expression
*/
return TriggerConditionData.create(this, expression)
endmethod
else
method register takes boolexpr expression returns TriggerCondition
debug call ThrowError(this == 0, "Trigger", "register", "Trigger", this, "Attempted To Register To Null Trigger.")
debug call ThrowError(not isTrigger, "Trigger", "register", "Trigger", this, "Attempted To Register To Invalid Trigger.")
/*
* Register the expression
*/
return TriggerConditionData.create(this, expression)
endmethod
endif
static if DEBUG_MODE then
method clear takes nothing returns nothing
call clear_p()
endmethod
private method clear_p takes nothing returns nothing
local TriggerConditionDataCollection node = TriggerConditionDataCollection(this).first
debug call ThrowError(this == 0, "Trigger", "clear", "Trigger", this, "Attempted To Clear Null Trigger.")
debug call ThrowError(not isTrigger, "Trigger", "clear", "Trigger", this, "Attempted To Clear Invalid Trigger.")
loop
exitwhen node == 0
call BooleanExpression(node).unregister()
set node = node.next
endloop
call TriggerConditionDataCollection(this).clear()
call TriggerMemory(this).updateTrigger()
call TriggerReferencedList(this).updateExpression()
endmethod
else
method clear takes nothing returns nothing
local TriggerConditionDataCollection node = TriggerConditionDataCollection(this).first
debug call ThrowError(this == 0, "Trigger", "clear", "Trigger", this, "Attempted To Clear Null Trigger.")
debug call ThrowError(not isTrigger, "Trigger", "clear", "Trigger", this, "Attempted To Clear Invalid Trigger.")
loop
exitwhen node == 0
call BooleanExpression(node).unregister()
set node = node.next
endloop
call TriggerConditionDataCollection(this).clear()
call TriggerMemory(this).updateTrigger()
call TriggerReferencedList(this).updateExpression()
endmethod
endif
static if DEBUG_MODE then
method clearReferences takes nothing returns nothing
call clearReferences_p()
endmethod
private method clearReferences_p takes nothing returns nothing
debug call ThrowError(this == 0, "Trigger", "clearReferences", "Trigger", this, "Attempted To Clear References Of Null Trigger.")
debug call ThrowError(not isTrigger, "Trigger", "clearReferences", "Trigger", this, "Attempted To Clear References Of Invalid Trigger.")
call TriggerReferenceList(this).clearReferences()
call TriggerMemory(this).updateTrigger()
call TriggerReferencedList(this).updateExpression()
endmethod
else
method clearReferences takes nothing returns nothing
debug call ThrowError(this == 0, "Trigger", "clearReferences", "Trigger", this, "Attempted To Clear References Of Null Trigger.")
debug call ThrowError(not isTrigger, "Trigger", "clearReferences", "Trigger", this, "Attempted To Clear References Of Invalid Trigger.")
call TriggerReferenceList(this).clearReferences()
call TriggerMemory(this).updateTrigger()
call TriggerReferencedList(this).updateExpression()
endmethod
endif
static if DEBUG_MODE then
method clearBackReferences takes nothing returns nothing
call clearBackReferences_p()
endmethod
private method clearBackReferences_p takes nothing returns nothing
debug call ThrowError(this == 0, "Trigger", "clearReferences", "Trigger", this, "Attempted To Clear Back References Of Null Trigger.")
debug call ThrowError(not isTrigger, "Trigger", "clearReferences", "Trigger", this, "Attempted To Clear Back References Of Invalid Trigger.")
call TriggerReferencedList(this).clearReferences()
endmethod
else
method clearBackReferences takes nothing returns nothing
debug call ThrowError(this == 0, "Trigger", "clearReferences", "Trigger", this, "Attempted To Clear Back References Of Null Trigger.")
debug call ThrowError(not isTrigger, "Trigger", "clearReferences", "Trigger", this, "Attempted To Clear Back References Of Invalid Trigger.")
call TriggerReferencedList(this).clearReferences()
endmethod
endif
static if DEBUG_MODE then
method reference takes thistype trig returns TriggerReference
return reference_p(trig)
endmethod
private method reference_p takes thistype trig returns TriggerReference
debug call ThrowError(this == 0, "Trigger", "reference", "Trigger", this, "Attempted To Make Null Trigger Reference Trigger.")
debug call ThrowError(not isTrigger, "Trigger", "reference", "Trigger", this, "Attempted To Make Invalid Trigger Reference Trigger.")
debug call ThrowError(trig == 0, "Trigger", "reference", "Trigger", this, "Attempted To Reference Null Trigger (" + I2S(trig) + ").")
debug call ThrowError(not trig.isTrigger, "Trigger", "reference", "Trigger", this, "Attempted To Reference Invalid Trigger (" + I2S(trig) + ").")
return TriggerReferenceData.create(this, trig)
endmethod
else
method reference takes thistype trig returns TriggerReference
debug call ThrowError(this == 0, "Trigger", "reference", "Trigger", this, "Attempted To Make Null Trigger Reference Trigger.")
debug call ThrowError(not isTrigger, "Trigger", "reference", "Trigger", this, "Attempted To Make Invalid Trigger Reference Trigger.")
debug call ThrowError(trig == 0, "Trigger", "reference", "Trigger", this, "Attempted To Reference Null Trigger (" + I2S(trig) + ").")
debug call ThrowError(not trig.isTrigger, "Trigger", "reference", "Trigger", this, "Attempted To Reference Invalid Trigger (" + I2S(trig) + ").")
return TriggerReferenceData.create(this, trig)
endmethod
endif
static if DEBUG_MODE then
method clearEvents takes nothing returns nothing
call clearEvents_p()
endmethod
private method clearEvents_p takes nothing returns nothing
debug call ThrowError(this == 0, "Trigger", "clearEvents", "Trigger", this, "Attempted To Clear Events Of Null Trigger.")
debug call ThrowError(not isTrigger, "Trigger", "clearEvents", "Trigger", this, "Attempted To Clear Events Of Invalid Trigger.")
if (TriggerMemory(this).tc != null) then
call TriggerRemoveCondition(TriggerMemory(this).trig, TriggerMemory(this).tc)
endif
call DestroyTrigger(TriggerMemory(this).trig)
set TriggerMemory(this).trig = CreateTrigger()
if (TriggerMemory(this).enabled) then
set TriggerMemory(this).tc = TriggerAddCondition(TriggerMemory(this).trig, TriggerMemory(this).expression.expression)
else
call TriggerMemory(this).tc_clear()
endif
endmethod
else
method clearEvents takes nothing returns nothing
debug call ThrowError(this == 0, "Trigger", "clearEvents", "Trigger", this, "Attempted To Clear Events Of Null Trigger.")
debug call ThrowError(not isTrigger, "Trigger", "clearEvents", "Trigger", this, "Attempted To Clear Events Of Invalid Trigger.")
if (TriggerMemory(this).tc != null) then
call TriggerRemoveCondition(TriggerMemory(this).trig, TriggerMemory(this).tc)
endif
call DestroyTrigger(TriggerMemory(this).trig)
set TriggerMemory(this).trig = CreateTrigger()
if (TriggerMemory(this).enabled) then
set TriggerMemory(this).tc = TriggerAddCondition(TriggerMemory(this).trig, TriggerMemory(this).expression.expression)
else
call TriggerMemory(this).tc_clear()
endif
endmethod
endif
method fire takes nothing returns nothing
debug call ThrowError(this == 0, "Trigger", "fire", "Trigger", this, "Attempted To Fire Null Trigger.")
debug call ThrowError(not isTrigger, "Trigger", "fire", "Trigger", this, "Attempted To Fire Invalid Trigger.")
call TriggerEvaluate(TriggerMemory(this).trig)
endmethod
method operator trigger takes nothing returns trigger
debug call ThrowError(this == 0, "Trigger", "trigger", "Trigger", this, "Attempted To Read Null Trigger.")
debug call ThrowError(not isTrigger, "Trigger", "trigger", "Trigger", this, "Attempted To Read Invalid Trigger.")
return TriggerMemory(this).trig
endmethod
method operator enabled takes nothing returns boolean
debug call ThrowError(this == 0, "Trigger", "enabled", "Trigger", this, "Attempted To Read Null Trigger.")
debug call ThrowError(not isTrigger, "Trigger", "enabled", "Trigger", this, "Attempted To Read Invalid Trigger.")
return TriggerMemory(this).enabled
endmethod
static if DEBUG_MODE then
method operator enabled= takes boolean enable returns nothing
set enabled_p = enable
endmethod
private method operator enabled_p= takes boolean enable returns nothing
debug call ThrowError(this == 0, "Trigger", "enabled=", "Trigger", this, "Attempted To Set Null Trigger.")
debug call ThrowError(not isTrigger, "Trigger", "enabled=", "Trigger", this, "Attempted To Set Invalid Trigger.")
debug call ThrowWarning(TriggerMemory(this).enabled == enable, "Trigger", "enabled=", "Trigger", this, "Setting Enabled To Its Value.")
set TriggerMemory(this).enabled = enable
call TriggerMemory(this).updateTrigger()
call TriggerReferencedList(this).updateExpression()
endmethod
else
method operator enabled= takes boolean enable returns nothing
debug call ThrowError(this == 0, "Trigger", "enabled=", "Trigger", this, "Attempted To Set Null Trigger.")
debug call ThrowError(not isTrigger, "Trigger", "enabled=", "Trigger", this, "Attempted To Set Invalid Trigger.")
debug call ThrowWarning(TriggerMemory(this).enabled == enable, "Trigger", "enabled=", "Trigger", this, "Setting Enabled To Its Value.")
set TriggerMemory(this).enabled = enable
call TriggerMemory(this).updateTrigger()
call TriggerReferencedList(this).updateExpression()
endmethod
endif
static if DEBUG_MODE then
static method calculateMemoryUsage takes nothing returns integer
return /*
*/ TriggerAllocator.calculateMemoryUsage() + /*
*/ TriggerConditionDataCollection.calculateMemoryUsage() + /*
*/ TriggerReferenceListData.calculateMemoryUsage() + /*
*/ TriggerReferencedList.calculateMemoryUsage() + /*
*/ BooleanExpression.calculateMemoryUsage()
endmethod
static method getAllocatedMemoryAsString takes nothing returns string
return /*
*/ "(Trigger)[" + TriggerAllocator.getAllocatedMemoryAsString() + "], " + /*
*/ "(Trigger TriggerConditionDataCollection)[" + TriggerConditionDataCollection.getAllocatedMemoryAsString() + "], " + /*
*/ "(Trigger Reference)[" + TriggerReferenceListData.getAllocatedMemoryAsString() + "], " + /*
*/ "(Trigger Reference Back)[" + TriggerReferencedList.getAllocatedMemoryAsString() + "], " + /*
*/ "(Boolean Expression (all))[" + BooleanExpression.getAllocatedMemoryAsString() + "]"
endmethod
endif
private static method init takes nothing returns nothing
static if DEBUG_MODE then
//! runtextmacro INITIALIZE_TABLE_FIELD("isTrigger")
endif
endmethod
implement Init
endstruct
endlibrary
/*
* Here we have two triggers where Chat Message relies on a filter
*
* The filter will stop all messages starting with ~. After the first successful message, it
* will stop all messages starting with either ~ or -.
*/
struct ChatFilter extends array
readonly static Trigger filter
readonly static Trigger filter2
private static method onChat takes nothing returns boolean
return SubString(GetEventPlayerChatString(), 0, 1) == "~"
endmethod
private static method onChat2 takes nothing returns boolean
return SubString(GetEventPlayerChatString(), 0, 1) == "-"
endmethod
private static method onInit takes nothing returns nothing
set filter = Trigger.create(false)
call filter.register(Condition(function thistype.onChat))
set filter2 = Trigger.create(false)
call filter2.register(Condition(function thistype.onChat)) //can either reference first filter
//or just use the function directly
call filter2.register(Condition(function thistype.onChat2))
endmethod
endstruct
struct TriggerChatMessage extends array
readonly static Trigger onChat
readonly static TriggerReference reference
private static method onChatFunction takes nothing returns boolean
call DisplayTimedTextToPlayer(GetLocalPlayer(),0,0,60000,"You Said \"" + GetEventPlayerChatString() + "\"")
call reference.replace(ChatFilter.filter2)
return false
endmethod
private static method onInit takes nothing returns nothing
set onChat = Trigger.create(false)
set reference = onChat.reference(ChatFilter.filter)
call onChat.register(Condition(function thistype.onChatFunction))
call TriggerRegisterPlayerChatEvent(onChat.trigger, Player(0), "", false)
endmethod
endstruct
/*
* Here we have two libraries
*
* MyLib
*
* Runs whenever the player presses Escape
*
* ClearLib
*
* Contains a trigger that when run, clears text messages
*
* From here
*
* Struct 1
*
* Makes MybLib reference ClearLib, which makes ClearLib run before MyLib does
* Registers to MyLib
*
* Struct 2
*
* Registers to MyLib
*
* The result
*
* Clear Text Messages
*
* Run Struct 1
* If Struct 1 returns false
* Run Struct 2
*/
library MyLib
struct MyLib extends array
readonly static Trigger myEvent
private static method onInit takes nothing returns nothing
set myEvent = Trigger.create(false)
call TriggerRegisterPlayerEvent(myEvent.trigger, Player(0), EVENT_PLAYER_END_CINEMATIC)
endmethod
endstruct
endlibrary
library ClearLib
struct ClearLib extends array
/*
* Clears Text
*/
readonly static Trigger clear
private static method myCode takes nothing returns boolean
call ClearTextMessages()
return false
endmethod
private static method onInit takes nothing returns nothing
set clear = Trigger.create(false)
call clear.register(Condition(function thistype.myCode))
endmethod
endstruct
endlibrary
struct User extends array
private static boolean terminate = true
private static method myCode takes nothing returns boolean
call DisplayTimedTextToPlayer(GetLocalPlayer(),0,0,60000,"User Pressed Escape")
set terminate = not terminate
/*
* If terminate == true, then triggers past this trigger will not fire
*/
return terminate
endmethod
private static method onInit takes nothing returns nothing
call MyLib.myEvent.reference(ClearLib.clear)
call MyLib.myEvent.register(Condition(function thistype.myCode))
endmethod
endstruct
struct User2 extends array
private static method myCode takes nothing returns boolean
call DisplayTimedTextToPlayer(GetLocalPlayer(),0,0,60000,"The Event Was Not Terminated")
return false
endmethod
private static method onInit takes nothing returns nothing
call MyLib.myEvent.register(Condition(function thistype.myCode))
endmethod
endstruct
/*
* Same as Event Registration example except that this uses Trigger.reference instead of Trigger.register
*/
library MyLib
struct MyLib extends array
readonly static Trigger myEvent
private static method onInit takes nothing returns nothing
set myEvent = Trigger.create(false)
call TriggerRegisterPlayerEvent(myEvent.trigger, Player(0), EVENT_PLAYER_END_CINEMATIC)
endmethod
endstruct
endlibrary
library ClearLib
struct ClearLib extends array
/*
* Clears Text
*/
readonly static Trigger clear
private static method myCode takes nothing returns boolean
call ClearTextMessages()
return false
endmethod
private static method onInit takes nothing returns nothing
set clear = Trigger.create(false)
call clear.register(Condition(function thistype.myCode))
endmethod
endstruct
endlibrary
struct User extends array
private static Trigger trigger
private static boolean terminate = true
private static method myCode takes nothing returns boolean
call DisplayTimedTextToPlayer(GetLocalPlayer(),0,0,60000,"User Pressed Escape")
set terminate = not terminate
/*
* If terminate == true, then triggers past this trigger will not fire
*/
return terminate
endmethod
private static method onInit takes nothing returns nothing
set trigger = Trigger.create(false)
/*
* Rely on clear text messages
*
* Clear could be registered to MyLib.myEvent instead
*/
call trigger.reference(ClearLib.clear)
call trigger.register(Condition(function thistype.myCode))
/*
* Register trigger
*/
call MyLib.myEvent.reference(trigger)
endmethod
endstruct
struct User2 extends array
private static Trigger trigger
private static method myCode takes nothing returns boolean
call DisplayTimedTextToPlayer(GetLocalPlayer(),0,0,60000,"The Event Was Not Terminated")
return false
endmethod
private static method onInit takes nothing returns nothing
set trigger = Trigger.create(false)
call trigger.register(Condition(function thistype.myCode))
/*
* Register trigger
*/
call MyLib.myEvent.reference(trigger)
endmethod
endstruct
/*
* Here we have 4 triggers
*
* OnEscape runs whenever player 0 hits escape
*
* C references B
* B references A
*
* OnEscape references C so that C will run when the player hits escape, it is otherwise empty (another way to register events)
*
* When the player hits escape 5 times, B will be destroyed
*
* When OnEscape is run, it will run in this order (remember references run first)
*
* A, B, C
*
* When B is destroyed, only C will run as C loses its connection to A
*
* One interesting thing to note is that when B is destroyed, C is still run
*
* Try the same example with plain triggers and triggerconditions to see what happens (native trigger stability example)
*/
struct OnEscape extends array
readonly static Trigger trigger
private static method onInit takes nothing returns nothing
set trigger = Trigger.create(false)
call TriggerRegisterPlayerEvent(trigger.trigger, Player(0), EVENT_PLAYER_END_CINEMATIC)
endmethod
endstruct
struct A extends array
readonly static Trigger trigger
private static method onFire takes nothing returns boolean
call DisplayTimedTextToPlayer(GetLocalPlayer(),0,0,60000,"Ran A")
return false
endmethod
private static method onInit takes nothing returns nothing
set trigger = Trigger.create(false)
call trigger.register(Condition(function thistype.onFire))
endmethod
endstruct
struct B extends array
readonly static Trigger trigger
private static integer escapeCount = 0
private static method onFire takes nothing returns boolean
set escapeCount = escapeCount + 1
if (escapeCount == 5) then
call DisplayTimedTextToPlayer(GetLocalPlayer(),0,0,60000,"Destroyed B")
call trigger.destroy()
else
call DisplayTimedTextToPlayer(GetLocalPlayer(),0,0,60000,"Ran B: " + I2S(escapeCount))
endif
return false
endmethod
private static method onInit takes nothing returns nothing
set trigger = Trigger.create(false)
call trigger.reference(A.trigger)
call trigger.register(Condition(function thistype.onFire))
endmethod
endstruct
struct C extends array
readonly static Trigger trigger
private static method onFire takes nothing returns boolean
call DisplayTimedTextToPlayer(GetLocalPlayer(),0,0,60000,"Ran C\n------------------------------------------------")
return false
endmethod
private static method onInit takes nothing returns nothing
set trigger = Trigger.create(false)
call trigger.reference(B.trigger)
call trigger.register(Condition(function thistype.onFire))
call OnEscape.trigger.reference(trigger)
endmethod
endstruct
//TESH.scrollpos=0
//TESH.alwaysfold=0
/*
* Notice that when B is destroyed, C is never run
*/
struct OnEscape extends array
readonly static trigger trigger
private static method onInit takes nothing returns nothing
set trigger = CreateTrigger()
call TriggerRegisterPlayerEvent(trigger, Player(0), EVENT_PLAYER_END_CINEMATIC)
endmethod
endstruct
struct A extends array
private static method onFire takes nothing returns boolean
call DisplayTimedTextToPlayer(GetLocalPlayer(),0,0,60000,"Ran A")
return false
endmethod
private static method onInit takes nothing returns nothing
call TriggerAddCondition(OnEscape.trigger, Condition(function thistype.onFire))
endmethod
endstruct
struct B extends array
private static triggercondition tc
private static integer escapeCount = 0
private static method onFire takes nothing returns boolean
set escapeCount = escapeCount + 1
if (escapeCount == 5) then
call DisplayTimedTextToPlayer(GetLocalPlayer(),0,0,60000,"Destroyed B")
call TriggerRemoveCondition(GetTriggeringTrigger(), tc)
set tc = null
else
call DisplayTimedTextToPlayer(GetLocalPlayer(),0,0,60000,"Ran B: " + I2S(escapeCount))
endif
return false
endmethod
private static method onInit takes nothing returns nothing
set tc = TriggerAddCondition(OnEscape.trigger, Condition(function thistype.onFire))
endmethod
endstruct
struct C extends array
private static method onFire takes nothing returns boolean
call DisplayTimedTextToPlayer(GetLocalPlayer(),0,0,60000,"Ran C\n------------------------------------------------")
return false
endmethod
private static method onInit takes nothing returns nothing
call TriggerAddCondition(OnEscape.trigger, Condition(function thistype.onFire))
endmethod
endstruct
/*
* Here we have a very simple library
*
* Whenever a unit is created, the eventTrigger will run
*
* The library contains two triggers
* eventTrigger
* event
*
* eventTrigger contains the library's own internal code (even a single function)
* event is for users to register code to the library
*
* There are two triggers that are registered in the following order
*
* OnUnitCreationUserLibrary
* OnUnitCreationUserLibrary2
*
* From here, user code is registered in the following order
*
* UserLib3 -> OnUnitCreationUserLibrary2
* UserLib1 -> OnUnitCreationUserLibrary
* User1 -> OnUnitCreation
* UserLib2 -> OnUnitCreationUserLibrary
*
* The resulting order of the code will be
*
* UserLib1
* UserLib2
* UserLib3
* User1
*
* To understand order
*
* OnUnitCreation
* OnUnitCreationUserLibrary
* OnUnitCreationUserLibrary2
* User1
*
* OnUnitCreationUserLibrary
* UserLib1
* UserLib2
*
* OnUnitCreationUserLibrary2
* UserLib3
*
* If any of the functions return true, all of the functions after them will not be run
*
* Only the primary system should ever return true. If wanting to enable/disable things, run internal
* triggers via trigger.fire().
*
* One possible design for a VERY fast DDS would be to create 1 trigger for each unit and then make it reference
* the DDS library followed by the global DDS event. Anything registered to that specific unit will then fire only for that
* unit, and anything registered to the global trigger will fire for every unit. No traditional trigger.fire() is used in
* this design, but the design uses extra memory as each unit gets its very own trigger.
*/
library OnUnitCreation uses Trigger
struct OnUnitCreation extends array
readonly static Trigger event //event response trigger
private static integer instanceCount = 0
private static method onCreate takes nothing returns boolean
call DisplayTimedTextToPlayer(GetLocalPlayer(),0,0,60000,"Main Library: Indexed Unit")
set instanceCount = instanceCount + 1
call SetUnitUserData(GetTriggerUnit(), instanceCount)
return false
endmethod
private static method init takes nothing returns nothing
local rect worldBounds = GetWorldBounds()
local region worldBoundsRegion = CreateRegion()
call RegionAddRect(worldBoundsRegion, worldBounds)
call RemoveRect(worldBounds)
set worldBounds = null
set event = Trigger.create(false)
call TriggerRegisterEnterRegion(event.trigger, worldBoundsRegion, null)
set worldBoundsRegion = null
call event.register(Condition(function thistype.onCreate))
endmethod
implement Init
endstruct
endlibrary
/*
* Libraries?
*/
struct OnUnitCreationUserLibrary extends array
readonly static Trigger event
private static method onInit takes nothing returns nothing
set event = Trigger.create(false)
call OnUnitCreation.event.reference(event)
endmethod
endstruct
/*
* Libraries?
*/
struct OnUnitCreationUserLibrary2 extends array
readonly static Trigger event
private static method onInit takes nothing returns nothing
set event = Trigger.create(false)
call OnUnitCreation.event.reference(event)
endmethod
endstruct
/*
* Event Response
*/
struct UserLib3 extends array
private static method onCreate takes nothing returns boolean
call DisplayTimedTextToPlayer(GetLocalPlayer(),0,0,60000,"Uses OnUnitCreationUserLibrary2 (3)")
return false
endmethod
private static method onInit takes nothing returns nothing
call OnUnitCreationUserLibrary2.event.register(Condition(function thistype.onCreate))
endmethod
endstruct
struct UserLib1 extends array
private static method onCreate takes nothing returns boolean
call DisplayTimedTextToPlayer(GetLocalPlayer(),0,0,60000,"Uses OnUnitCreationUserLibrary (1)")
return false
endmethod
private static method onInit takes nothing returns nothing
call OnUnitCreationUserLibrary.event.register(Condition(function thistype.onCreate))
endmethod
endstruct
struct User1 extends array
private static method onCreate takes nothing returns boolean
call DisplayTimedTextToPlayer(GetLocalPlayer(),0,0,60000,"Uses OnUnitCreation (1)")
return false
endmethod
private static method onInit takes nothing returns nothing
call OnUnitCreation.event.register(Condition(function thistype.onCreate))
endmethod
endstruct
struct UserLib2 extends array
private static method onCreate takes nothing returns boolean
call DisplayTimedTextToPlayer(GetLocalPlayer(),0,0,60000,"Uses OnUnitCreationUserLibrary (2)")
return false
endmethod
private static method onInit takes nothing returns nothing
call OnUnitCreationUserLibrary.event.register(Condition(function thistype.onCreate))
endmethod
endstruct
/*
* Run
*/
struct UserCode extends array
private static method onInit takes nothing returns nothing
call CreateUnit(Player(0), 'hfoo', 0, 0, 270)
endmethod
endstruct
/*
* Here, the entry point of a system for some event is A
*
* B depends on the data of A
*/
library A uses Trigger
struct A extends array
static Trigger event
static Trigger start
static Trigger end
static integer data = 0
private static method s takes nothing returns boolean
set data = 100
call DisplayTimedTextToPlayer(GetLocalPlayer(), 0, 0, 60000, "A Start -> " + I2S(data))
return false
endmethod
private static method e takes nothing returns boolean
set data = 0
call DisplayTimedTextToPlayer(GetLocalPlayer(), 0, 0, 60000, "A End -> " + I2S(data))
return false
endmethod
private static method onInit takes nothing returns nothing
set event = Trigger.create(false)
set start = Trigger.create(false)
set end = Trigger.create(true)
call start.register(Condition(function thistype.s))
call end.register(Condition(function thistype.e))
call event.reference(start)
call event.reference(end)
endmethod
endstruct
endlibrary
library B uses A
/*
* can do sub events if desired with triggers in B
*/
struct B extends array
static integer data = 0
private static method s takes nothing returns boolean
set data = A.data*2
call DisplayTimedTextToPlayer(GetLocalPlayer(), 0, 0, 60000, "B Start -> " + I2S(A.data) + ", " + I2S(data))
return false
endmethod
private static method e takes nothing returns boolean
set data = 0
call DisplayTimedTextToPlayer(GetLocalPlayer(), 0, 0, 60000, "B End -> " + I2S(A.data) + ", " + I2S(data))
return false
endmethod
private static method onInit takes nothing returns nothing
call A.start.register(Condition(function thistype.s))
call A.end.register(Condition(function thistype.e))
endmethod
endstruct
endlibrary
library User uses A, B
struct User extends array
static integer data = 0
private static method s takes nothing returns boolean
set data = B.data + A.data
call DisplayTimedTextToPlayer(GetLocalPlayer(), 0, 0, 60000, "User Start -> " + I2S(A.data) + ", " + I2S(B.data) + ", " + I2S(data))
return false
endmethod
private static method e takes nothing returns boolean
set data = 0
call DisplayTimedTextToPlayer(GetLocalPlayer(), 0, 0, 60000, "User End -> " + I2S(A.data) + ", " + I2S(B.data) + ", " + I2S(data))
return false
endmethod
private static method onInit takes nothing returns nothing
call A.start.register(Condition(function thistype.s))
call A.end.register(Condition(function thistype.e))
endmethod
endstruct
endlibrary
struct Run extends array
private static method onInit takes nothing returns nothing
call A.event.fire()
endmethod
endstruct
module Run
private static method init takes nothing returns nothing
call DestroyTimer(GetExpiredTimer())
call run()
endmethod
private static method onInit takes nothing returns nothing
call TimerStart(CreateTimer(), 0, false, function thistype.init)
endmethod
endmodule
struct Test extends array
/*
* DDS Entry Points
*/
private static Trigger t0
private static Trigger t1
private static Trigger t2
private static Trigger t3
private static Trigger t4
private static Trigger t5
private static Trigger t6
private static Trigger t7
private static Trigger t8
private static Trigger t9
private static Trigger t10
private static Trigger t11
private static Trigger t12
private static Trigger t13
private static Trigger t14
private static Trigger t15
private static Trigger t16
private static Trigger t17
private static Trigger t18
private static Trigger t19
private static Trigger t20
private static Trigger t21
private static Trigger t22
private static Trigger t23
private static Trigger t24
private static Trigger t25
private static Trigger t26
private static Trigger t27
private static Trigger t28
private static Trigger t29
private static Trigger t30
private static method d1 takes nothing returns boolean
return false
endmethod
private static method d2 takes nothing returns boolean
return false
endmethod
private static method d3 takes nothing returns boolean
return false
endmethod
private static method d4 takes nothing returns boolean
return false
endmethod
private static method d5 takes nothing returns boolean
return false
endmethod
private static method d6 takes nothing returns boolean
return false
endmethod
private static method d7 takes nothing returns boolean
return false
endmethod
private static method d8 takes nothing returns boolean
return false
endmethod
private static method d9 takes nothing returns boolean
return false
endmethod
private static method d10 takes nothing returns boolean
return false
endmethod
private static method d11 takes nothing returns boolean
return false
endmethod
private static method d12 takes nothing returns boolean
return false
endmethod
private static method d13 takes nothing returns boolean
return false
endmethod
private static method d14 takes nothing returns boolean
return false
endmethod
private static method d15 takes nothing returns boolean
return false
endmethod
private static method d16 takes nothing returns boolean
return false
endmethod
private static method d17 takes nothing returns boolean
return false
endmethod
private static method d18 takes nothing returns boolean
return false
endmethod
private static method d19 takes nothing returns boolean
return false
endmethod
private static method d20 takes nothing returns boolean
return false
endmethod
private static method d21 takes nothing returns boolean
return false
endmethod
private static method d22 takes nothing returns boolean
return false
endmethod
private static method d23 takes nothing returns boolean
return false
endmethod
private static method d24 takes nothing returns boolean
return false
endmethod
private static method d25 takes nothing returns boolean
return false
endmethod
private static method d26 takes nothing returns boolean
return false
endmethod
private static method d27 takes nothing returns boolean
return false
endmethod
private static method d28 takes nothing returns boolean
return false
endmethod
private static method d29 takes nothing returns boolean
return false
endmethod
private static method d30 takes nothing returns boolean
return false
endmethod
private static method d31 takes nothing returns boolean
return false
endmethod
private static method d32 takes nothing returns boolean
return false
endmethod
private static method d33 takes nothing returns boolean
return false
endmethod
private static method d34 takes nothing returns boolean
return false
endmethod
private static method d35 takes nothing returns boolean
return false
endmethod
private static method d36 takes nothing returns boolean
return false
endmethod
private static method d37 takes nothing returns boolean
return false
endmethod
private static method d38 takes nothing returns boolean
return false
endmethod
private static method d39 takes nothing returns boolean
return false
endmethod
private static method d40 takes nothing returns boolean
return false
endmethod
private static method d41 takes nothing returns boolean
return false
endmethod
private static method d42 takes nothing returns boolean
return false
endmethod
private static method d43 takes nothing returns boolean
return false
endmethod
private static method d44 takes nothing returns boolean
return false
endmethod
private static method d45 takes nothing returns boolean
return false
endmethod
private static method d46 takes nothing returns boolean
return false
endmethod
private static method d47 takes nothing returns boolean
return false
endmethod
private static method d48 takes nothing returns boolean
return false
endmethod
private static method d49 takes nothing returns boolean
return false
endmethod
private static method d50 takes nothing returns boolean
return false
endmethod
private static method d51 takes nothing returns boolean
return false
endmethod
private static method d52 takes nothing returns boolean
return false
endmethod
private static method d53 takes nothing returns boolean
return false
endmethod
private static method d54 takes nothing returns boolean
return false
endmethod
private static method d55 takes nothing returns boolean
return false
endmethod
private static method d56 takes nothing returns boolean
return false
endmethod
private static method d57 takes nothing returns boolean
return false
endmethod
private static method d58 takes nothing returns boolean
return false
endmethod
private static method d59 takes nothing returns boolean
return false
endmethod
private static method d60 takes nothing returns boolean
return false
endmethod
private static method run takes nothing returns nothing
call createTriggers()
call referenceTriggers()
call registerCode()
debug call DisplayTimedTextToPlayer(GetLocalPlayer(), 0, 0, 60000, "Memory Usage: " + I2S(Trigger.calculateMemoryUsage()))
call clean()
debug call DisplayTimedTextToPlayer(GetLocalPlayer(), 0, 0, 60000, "Memory Usage: " + I2S(Trigger.calculateMemoryUsage()))
endmethod
private static method createTriggers takes nothing returns nothing
local integer i = 0
local boolean success = true
call createTriggersRun()
loop
set i = i + 1
if (not complete[i]) then
call DisplayTimedTextToPlayer(GetLocalPlayer(), 0, 0, 60000, "Trigger Creation Failure: " + I2S(i - 1))
set success = false
endif
set complete[i] = false
exitwhen i == 31
endloop
if (success) then
call DisplayTimedTextToPlayer(GetLocalPlayer(), 0, 0, 60000, "Trigger Creation Complete")
endif
endmethod
private static method createTriggersRun takes nothing returns nothing
/*
* create entry points
*/
set t0 = Trigger.create(false)
set complete[1] = true
set t1 = Trigger.create(false)
set complete[2] = true
set t2 = Trigger.create(false)
set complete[3] = true
set t3 = Trigger.create(false)
set complete[4] = true
set t4 = Trigger.create(false)
set complete[5] = true
set t5 = Trigger.create(false)
set complete[6] = true
set t6 = Trigger.create(false)
set complete[7] = true
set t7 = Trigger.create(false)
set complete[8] = true
set t8 = Trigger.create(false)
set complete[9] = true
set t9 = Trigger.create(false)
set complete[10] = true
set t10 = Trigger.create(false)
set complete[11] = true
set t11 = Trigger.create(false)
set complete[12] = true
set t12 = Trigger.create(false)
set complete[13] = true
set t13 = Trigger.create(false)
set complete[14] = true
set t14 = Trigger.create(false)
set complete[15] = true
set t15 = Trigger.create(false)
set complete[16] = true
set t16 = Trigger.create(false)
set complete[17] = true
set t17 = Trigger.create(false)
set complete[18] = true
set t18 = Trigger.create(false)
set complete[19] = true
set t19 = Trigger.create(false)
set complete[20] = true
set t20 = Trigger.create(false)
set complete[21] = true
set t21 = Trigger.create(false)
set complete[22] = true
set t22 = Trigger.create(false)
set complete[23] = true
set t23 = Trigger.create(false)
set complete[24] = true
set t24 = Trigger.create(false)
set complete[25] = true
set t25 = Trigger.create(false)
set complete[26] = true
set t26 = Trigger.create(false)
set complete[27] = true
set t27 = Trigger.create(false)
set complete[28] = true
set t28 = Trigger.create(false)
set complete[29] = true
set t29 = Trigger.create(false)
set complete[30] = true
set t30 = Trigger.create(false)
set complete[31] = true
endmethod
private static method referenceTriggers takes nothing returns nothing
local integer i = 0
local boolean success = true
call referenceTriggersRun()
loop
set i = i + 1
if (not complete[i]) then
call DisplayTimedTextToPlayer(GetLocalPlayer(), 0, 0, 60000, "Trigger Reference Failure: " + I2S(i - 1))
set success = false
endif
set complete[i] = false
exitwhen i == 30
endloop
if (success) then
call DisplayTimedTextToPlayer(GetLocalPlayer(), 0, 0, 60000, "Trigger Referencing Complete")
endif
endmethod
private static method referenceTriggersRun takes nothing returns nothing
/*
* reference triggers
*/
call t0.reference(t1)
set complete[1] = true
call t1.reference(t2)
set complete[2] = true
call t2.reference(t3)
set complete[3] = true
call t3.reference(t4)
set complete[4] = true
call t4.reference(t5)
set complete[5] = true
call t5.reference(t6)
set complete[6] = true
call t6.reference(t7)
set complete[7] = true
call t7.reference(t8)
set complete[8] = true
call t8.reference(t9)
set complete[9] = true
call t9.reference(t10)
set complete[10] = true
call t10.reference(t11)
set complete[11] = true
call t11.reference(t12)
set complete[12] = true
call t12.reference(t13)
set complete[13] = true
call t13.reference(t14)
set complete[14] = true
call t14.reference(t15)
set complete[15] = true
call t15.reference(t16)
set complete[16] = true
call t16.reference(t17)
set complete[17] = true
call t17.reference(t18)
set complete[18] = true
call t18.reference(t19)
set complete[19] = true
call t19.reference(t20)
set complete[20] = true
call t20.reference(t21)
set complete[21] = true
call t21.reference(t22)
set complete[22] = true
call t22.reference(t23)
set complete[23] = true
call t23.reference(t24)
set complete[24] = true
call t24.reference(t25)
set complete[25] = true
call t25.reference(t26)
set complete[26] = true
call t26.reference(t27)
set complete[27] = true
call t27.reference(t28)
set complete[28] = true
call t28.reference(t29)
set complete[29] = true
call t29.reference(t30)
set complete[30] = true
endmethod
private static boolean array complete
private static method registerCode takes nothing returns nothing
local integer i = 0
local boolean success = true
call registerCodeRun()
loop
set i = i + 1
if (not complete[i]) then
call DisplayTimedTextToPlayer(GetLocalPlayer(), 0, 0, 60000, "Trigger Code Registration Failure: " + I2S(i))
set success = false
endif
set complete[i] = false
exitwhen i == 30
endloop
if (success) then
call DisplayTimedTextToPlayer(GetLocalPlayer(), 0, 0, 60000, "Trigger Code Registration Complete")
endif
endmethod
private static method registerCode1 takes nothing returns nothing
call t1.register(Condition(function thistype.d1))
call t1.register(Condition(function thistype.d2))
call t1.register(Condition(function thistype.d3))
set complete[1] = true
endmethod
private static method registerCode2 takes nothing returns nothing
call t2.register(Condition(function thistype.d4))
call t2.register(Condition(function thistype.d5))
set complete[2] = true
endmethod
private static method registerCode3 takes nothing returns nothing
call t3.register(Condition(function thistype.d6))
call t3.register(Condition(function thistype.d7))
call t3.register(Condition(function thistype.d8))
set complete[3] = true
endmethod
private static method registerCode4 takes nothing returns nothing
call t4.register(Condition(function thistype.d9))
set complete[4] = true
endmethod
private static method registerCode5 takes nothing returns nothing
call t5.register(Condition(function thistype.d10))
call t5.register(Condition(function thistype.d11))
set complete[5] = true
endmethod
private static method registerCode6 takes nothing returns nothing
call t6.register(Condition(function thistype.d12))
call t6.register(Condition(function thistype.d13))
call t6.register(Condition(function thistype.d14))
call t6.register(Condition(function thistype.d15))
set complete[6] = true
endmethod
private static method registerCode7 takes nothing returns nothing
call t7.register(Condition(function thistype.d16))
set complete[7] = true
endmethod
private static method registerCode8 takes nothing returns nothing
call t8.register(Condition(function thistype.d17))
call t8.register(Condition(function thistype.d18))
set complete[8] = true
endmethod
private static method registerCode9 takes nothing returns nothing
call t9.register(Condition(function thistype.d19))
call t9.register(Condition(function thistype.d20))
call t9.register(Condition(function thistype.d21))
call t9.register(Condition(function thistype.d22))
call t9.register(Condition(function thistype.d23))
set complete[9] = true
endmethod
private static method registerCode10 takes nothing returns nothing
call t10.register(Condition(function thistype.d24))
call t10.register(Condition(function thistype.d25))
set complete[10] = true
endmethod
private static method registerCode11 takes nothing returns nothing
call t11.register(Condition(function thistype.d26))
set complete[11] = true
endmethod
private static method registerCode12 takes nothing returns nothing
call t12.register(Condition(function thistype.d27))
set complete[12] = true
endmethod
private static method registerCode13 takes nothing returns nothing
call t13.register(Condition(function thistype.d28))
set complete[13] = true
endmethod
private static method registerCode14 takes nothing returns nothing
call t14.register(Condition(function thistype.d29))
set complete[14] = true
endmethod
private static method registerCode15 takes nothing returns nothing
call t15.register(Condition(function thistype.d30))
set complete[15] = true
endmethod
private static method registerCode16 takes nothing returns nothing
call t16.register(Condition(function thistype.d31))
call t16.register(Condition(function thistype.d32))
call t16.register(Condition(function thistype.d33))
set complete[16] = true
endmethod
private static method registerCode17 takes nothing returns nothing
call t17.register(Condition(function thistype.d34))
call t17.register(Condition(function thistype.d35))
set complete[17] = true
endmethod
private static method registerCode18 takes nothing returns nothing
call t18.register(Condition(function thistype.d36))
call t18.register(Condition(function thistype.d37))
call t18.register(Condition(function thistype.d38))
set complete[18] = true
endmethod
private static method registerCode19 takes nothing returns nothing
call t19.register(Condition(function thistype.d39))
set complete[19] = true
endmethod
private static method registerCode20 takes nothing returns nothing
call t20.register(Condition(function thistype.d40))
call t20.register(Condition(function thistype.d41))
set complete[20] = true
endmethod
private static method registerCode21 takes nothing returns nothing
call t21.register(Condition(function thistype.d42))
call t21.register(Condition(function thistype.d43))
call t21.register(Condition(function thistype.d44))
call t21.register(Condition(function thistype.d45))
set complete[21] = true
endmethod
private static method registerCode22 takes nothing returns nothing
call t22.register(Condition(function thistype.d46))
set complete[22] = true
endmethod
private static method registerCode23 takes nothing returns nothing
call t23.register(Condition(function thistype.d47))
call t23.register(Condition(function thistype.d48))
set complete[23] = true
endmethod
private static method registerCode24 takes nothing returns nothing
call t24.register(Condition(function thistype.d49))
call t24.register(Condition(function thistype.d50))
call t24.register(Condition(function thistype.d51))
call t24.register(Condition(function thistype.d52))
call t24.register(Condition(function thistype.d53))
set complete[24] = true
endmethod
private static method registerCode25 takes nothing returns nothing
call t25.register(Condition(function thistype.d54))
call t25.register(Condition(function thistype.d55))
set complete[25] = true
endmethod
private static method registerCode26 takes nothing returns nothing
call t26.register(Condition(function thistype.d56))
set complete[26] = true
endmethod
private static method registerCode27 takes nothing returns nothing
call t27.register(Condition(function thistype.d57))
set complete[27] = true
endmethod
private static method registerCode28 takes nothing returns nothing
call t28.register(Condition(function thistype.d58))
set complete[28] = true
endmethod
private static method registerCode29 takes nothing returns nothing
call t29.register(Condition(function thistype.d59))
set complete[29] = true
endmethod
private static method registerCode30 takes nothing returns nothing
call t30.register(Condition(function thistype.d60))
set complete[30] = true
endmethod
private static method registerCodeRun takes nothing returns nothing
/*
* register code
*/
call registerCode1()
call registerCode2()
call registerCode3()
call registerCode4()
call registerCode5()
call registerCode6()
call registerCode7()
call registerCode8()
call registerCode9()
call registerCode10()
call registerCode11()
call registerCode12()
call registerCode13()
call registerCode14()
call registerCode15()
call registerCode16()
call registerCode17()
call registerCode18()
call registerCode19()
call registerCode20()
call registerCode21()
call registerCode22()
call registerCode23()
call registerCode24()
call registerCode25()
call registerCode26()
call registerCode27()
call registerCode28()
call registerCode29()
call registerCode30()
endmethod
private static method clean takes nothing returns nothing
call t0.destroy()
call t1.destroy()
call t2.destroy()
call t3.destroy()
call t4.destroy()
call t5.destroy()
call t6.destroy()
call t7.destroy()
call t8.destroy()
call t9.destroy()
call t10.destroy()
call t11.destroy()
call t12.destroy()
call t13.destroy()
call t14.destroy()
call t15.destroy()
call t16.destroy()
call t17.destroy()
call t18.destroy()
call t19.destroy()
call t20.destroy()
call t21.destroy()
call t22.destroy()
call t23.destroy()
call t24.destroy()
call t25.destroy()
call t26.destroy()
call t27.destroy()
call t28.destroy()
call t29.destroy()
call t30.destroy()
call DisplayTimedTextToPlayer(GetLocalPlayer(), 0, 0, 60000, "Trigger Destruction Complete")
endmethod
implement Run
endstruct