//TESH.scrollpos=138
//TESH.alwaysfold=0
function IsUnitAnEnemy takes nothing returns boolean
if IsPlayerEnemy(GetOwningPlayer(GetFilterUnit()), udg_Player) and GetUnitAbilityLevel(GetFilterUnit(), 039;Aloc039;) == 0 and GetUnitState(GetFilterUnit(), UNIT_STATE_LIFE) > 0 then
return true
else
return false
endif
endfunction
//Rounds off a real\\
function RR takes real r returns real
return I2R(R2I(r + 0.5))
endfunction
//KaTTaNa's Handle Vars\\
function H2I takes handle h returns integer
return h
return 0
endfunction
function LocalVars takes nothing returns gamecache
return udg_Cache
endfunction
function SetHandleHandle takes handle subject, string name, handle value returns nothing
if value==null then
call FlushStoredInteger(LocalVars(),I2S(H2I(subject)),name)
else
call StoreInteger(LocalVars(), I2S(H2I(subject)), name, H2I(value))
endif
endfunction
function SetHandleInt takes handle subject, string name, integer value returns nothing
if value==0 then
call FlushStoredInteger(LocalVars(),I2S(H2I(subject)),name)
else
call StoreInteger(LocalVars(), I2S(H2I(subject)), name, value)
endif
endfunction
function SetHandleBoolean takes handle subject, string name, boolean value returns nothing
if value==false then
call FlushStoredBoolean(LocalVars(),I2S(H2I(subject)),name)
else
call StoreBoolean(LocalVars(), I2S(H2I(subject)), name, value)
endif
endfunction
function SetHandleReal takes handle subject, string name, real value returns nothing
if value==0 then
call FlushStoredReal(LocalVars(), I2S(H2I(subject)), name)
else
call StoreReal(LocalVars(), I2S(H2I(subject)), name, value)
endif
endfunction
function SetHandleString takes handle subject, string name, string value returns nothing
if value==null then
call FlushStoredString(LocalVars(), I2S(H2I(subject)), name)
else
call StoreString(LocalVars(), I2S(H2I(subject)), name, value)
endif
endfunction
function GetHandleHandle takes handle subject, string name returns handle
return GetStoredInteger(LocalVars(), I2S(H2I(subject)), name)
return null
endfunction
function GetHandleTA takes handle subject, string name returns triggeraction
return GetStoredInteger(LocalVars(), I2S(H2I(subject)), name)
return null
endfunction
function GetHandleInt takes handle subject, string name returns integer
return GetStoredInteger(LocalVars(), I2S(H2I(subject)), name)
endfunction
function GetHandleBoolean takes handle subject, string name returns boolean
return GetStoredBoolean(LocalVars(), I2S(H2I(subject)), name)
endfunction
function GetHandleReal takes handle subject, string name returns real
return GetStoredReal(LocalVars(), I2S(H2I(subject)), name)
endfunction
function GetHandleString takes handle subject, string name returns string
return GetStoredString(LocalVars(), I2S(H2I(subject)), name)
endfunction
function GetHandleUnit takes handle subject, string name returns unit
return GetStoredInteger(LocalVars(), I2S(H2I(subject)), name)
return null
endfunction
function GetHandleTimer takes handle subject, string name returns timer
return GetStoredInteger(LocalVars(), I2S(H2I(subject)), name)
return null
endfunction
function GetHandleTrigger takes handle subject, string name returns trigger
return GetStoredInteger(LocalVars(), I2S(H2I(subject)), name)
return null
endfunction
function GetHandleEffect takes handle subject, string name returns effect
return GetStoredInteger(LocalVars(), I2S(H2I(subject)), name)
return null
endfunction
function GetHandleGroup takes handle subject, string name returns group
return GetStoredInteger(LocalVars(), I2S(H2I(subject)), name)
return null
endfunction
function GetHandleLightning takes handle subject, string name returns lightning
return GetStoredInteger(LocalVars(), I2S(H2I(subject)), name)
return null
endfunction
function GetHandleWidget takes handle subject, string name returns widget
return GetStoredInteger(LocalVars(), I2S(H2I(subject)), name)
return null
endfunction
function FlushHandleLocals takes handle subject returns nothing
call FlushStoredMission(LocalVars(), I2S(H2I(subject)) )
endfunction
//divided line
function H2i takes handle h returns item
return h
endfunction
function H2TC takes handle h returns triggercondition
return h
endfunction
function Wait takes real duration returns nothing
local timer t
local real timeRemaining
if (duration > 0.00) then
set t = CreateTimer ()
call TimerStart (t,duration,false,null)
loop
set timeRemaining = TimerGetRemaining (t)
exitwhen timeRemaining <= 0.00
if (timeRemaining > 0.271828) then
call TriggerSleepAction (timeRemaining / 10.00)
else
call TriggerSleepAction (0.10)
endif
endloop
call PauseTimer (t)
call DestroyTimer (t)
endif
set t = null
endfunction
function H2i takes handle h returns item
return h
endfunction
function H2TC takes handle h returns triggercondition
return h
endfunction
library REGROWTREES initializer Init
globals
private constant real RegrowAfter = 23.0 // seconds to wait until tree regrows
private constant real Range = 250.0 // distance around tree that needs to be free of units before regrowing
private unit u
private group g = CreateGroup()
private boolexpr b
private boolean ok
endglobals
private function IsTree takes nothing returns boolean
local boolean b
call SetUnitX(u, GetWidgetX(GetFilterDestructable()))
call SetUnitY(u, GetWidgetY(GetFilterDestructable()))
set b = IssueTargetOrder(u, "harvest", GetFilterDestructable())
call IssueImmediateOrder(u, "stop")
return b
endfunction
private function IsUnitNear takes nothing returns boolean
if GetUnitState(GetFilterUnit(), UNIT_STATE_LIFE) > 0.5 then
set ok = false
endif
return false
endfunction
private function Regrow takes nothing returns nothing
local destructable t = GetTriggerDestructable()
call TriggerSleepAction(RegrowAfter)
loop
set ok = true
call GroupClear(g)
call GroupEnumUnitsInRange(g, GetDestructableX(t), GetDestructableY(t), Range, b)
exitwhen ok
call TriggerSleepAction(3.0)
endloop
call DestructableRestoreLife(t, GetDestructableMaxLife(t), true)
set t = null
endfunction
private function Register takes nothing returns nothing
call TriggerRegisterDeathEvent(bj_destInRegionDiesTrig, GetEnumDestructable())
endfunction
private function Init takes nothing returns nothing
set u = CreateUnit(Player(PLAYER_NEUTRAL_PASSIVE), 039;nmpe039;, 0, 0, 0) // Mur'gul Slave...
call SetUnitInvulnerable(u, true)
call ShowUnit(u, false)
call UnitAddAbility(u, 039;Aloc039;) // Locust
call UnitAddAbility(u, 039;Ahrl039;) // Harvest Lumber
set bj_destInRegionDiesTrig = CreateTrigger()
call EnumDestructablesInRect(bj_mapInitialPlayableArea, Condition(function IsTree), function Register)
call TriggerAddAction(bj_destInRegionDiesTrig, function Regrow)
set b = Condition(function IsUnitNear)
call RemoveUnit(u)
set u = null
endfunction
endlibrary
//==============================================================================
// ABC -- STRUCT ATTACHMENT SYSTEM BY COHADAR -- v6.1
//==============================================================================
//==============================================================================
// Quick function index:
//==============================================================================
//
// ----------------------------------------------------------------------
// Set Functions - these functions attach struct to a handle
// ----------------------------------------------------------------------
// SetTimerStructA(timer, struct)
// SetTimerStructB(timer, struct)
// SetTimerStructC(timer, struct)
//
// SetTriggerStructA(trigger, struct)
// SetTriggerStructB(trigger, struct)
// SetTriggerStructC(trigger, struct)
//
// SetDialogStructA(dialog, struct)
// SetDialogStructB(dialog, struct)
// SetDialogStructC(dialog, struct)
//
// SetRegionStructA(region, struct)
// SetRegionStructB(region, struct)
// SetRegionStructC(region, struct)
//
// ----------------------------------------------------------------------
// Get Functions - these functions retrieve attached structs
// ----------------------------------------------------------------------
// GetTimerStructA(timer) -> struct
// GetTimerStructB(timer) -> struct
// GetTimerStructC(timer) -> struct
//
// GetTriggerStructA(trigger) -> struct
// GetTriggerStructB(trigger) -> struct
// GetTriggerStructC(trigger) -> struct
//
// GetDialogStructA(dialog) -> struct
// GetDialogStructB(dialog) -> struct
// GetDialogStructC(dialog) -> struct
//
// GetRegionStructA(region) -> struct
// GetRegionStructB(region) -> struct
// GetRegionStructC(region) -> struct
//
// ----------------------------------------------------------------------
// Clear Functions - these functions clear and return attached value
// ----------------------------------------------------------------------
// ClearTimerStructA(timer) -> struct
// ClearTimerStructB(timer) -> struct
// ClearTimerStructC(timer) -> struct
//
// ClearTriggerStructA(trigger) -> struct
// ClearTriggerStructB(trigger) -> struct
// ClearTriggerStructC(trigger) -> struct
//
// ClearDialogStructA(dialog) -> struct
// ClearDialogStructB(dialog) -> struct
// ClearDialogStructC(dialog) -> struct
//
// ClearRegionStructA(region) -> struct
// ClearRegionStructB(region) -> struct
// ClearRegionStructC(region) -> struct
//
//==============================================================================
//==============================================================================
// DOCUMENTATION:
//==============================================================================
//
// PURPOUSE OF ABC:
// * Type safe handle attaching.
//
// * Currently supported handle types are timer, trigger, dialog and region
//
// PROS:
// * ABC is faster than gamecache based systems.
//
// * You can attach up to 3 structs on the same handle
//
// * System reports collision, and clearing of non-existent value.
//
// * This system will work even if your map leaks
// and will NOT slow down because of it.
//
// CONS:
// * you must manually clear the stored value - REMEMBER THIS RULE!!!
// Don't forget to use Clear functions
//
// DETAILS:
// * You can use Get to check if struct is attached to handle
// It will return 0 if it is not.
//
// * ABC will not interfere with other attachment systems
// You can freely use any other system alongside ABC
//
// * For unit attaching I recommend using PUI
//
// SPECIAL THANKS TO:
// * NagelBagel - for finding errors in versions 4.3 and 4.4
// * Here-b-Trollz - for testing ABC and for making cool spells with it.
// * Toadcop - for being pain in the ass and for pushing me to improve ABC.
// * emjlr3 - for pointing out the need for non-generic trigger attachments
// * PandaMine - I found a bug in ABC by examining his HSAS vs ABC test
// * All those people out there who use and support my systems
// Thank you guys.
//
// HOW TO IMPORT:
// * Just create a trigger named ABC
// * convert it to text and replace the whole trigger text with this one
//
//==============================================================================
//==============================================================================
// Macro function cores
//==============================================================================
//------------------------------------------------------------------------------
//! textmacro ABC_Set takes X, NAME, TYPE
local integer i = GetHandleId(key)
set i = i - (i / HASH) * HASH
if $NAME$Key$X$<i> == null then
set $NAME$Key$X$<i> = key
set $NAME$Value$X$<i> = value
else
debug set $NAME$Collision$X$<i> = $NAME$Collision$X$<i> + 1
debug if $NAME$MaxCollision$X$ < $NAME$Collision$X$<i> then
debug set $NAME$MaxCollision$X$ = $NAME$Collision$X$<i>
debug call BJDebugMsg("|cFFFF00FFWarning: Set$NAME$Struct$X$("+I2S(GetHandleId(key))+", "+I2S(value)+") - index: "+I2S(i)+", collision: "+I2S($NAME$MaxCollision$X$))
debug endif
call SaveInteger($NAME$Hash, 039;$X$039;, GetHandleId(key), value)
endif
//! endtextmacro
//------------------------------------------------------------------------------
//! textmacro ABC_Get takes X, NAME, TYPE
local integer i = GetHandleId(key)
set i = i - (i / HASH) * HASH
if $NAME$Key$X$<i> == key then
return $NAME$Value$X$<i>
else
return LoadInteger($NAME$Hash, 039;$X$039;, GetHandleId(key))
endif
//! endtextmacro
//------------------------------------------------------------------------------
//! textmacro ABC_Clear takes X, NAME, TYPE
local integer ret
local integer i = GetHandleId(key)
set i = i - (i / HASH) * HASH
if $NAME$Key$X$<i> == key then
set ret = $NAME$Value$X$<i>
set $NAME$Key$X$<i> = null
set $NAME$Value$X$<i> = 0
else
if HaveSavedInteger($NAME$Hash, 039;$X$039;, GetHandleId(key)) then
debug set $NAME$Collision$X$<i> = $NAME$Collision$X$<i> - 1
set ret = LoadInteger($NAME$Hash, 039;$X$039;, GetHandleId(key))
call RemoveSavedInteger($NAME$Hash, 039;$X$039;, GetHandleId(key))
else
call BJDebugMsg("|cFFFF0000ERROR: Clear$NAME$Struct$X$("+I2S(GetHandleId(key))+") - clear attempt on bad key")
set ret = 0
endif
endif
return ret
//! endtextmacro
//==============================================================================
library ABC initializer Init
globals
private constant integer HASH = 8191
private timer array TimerKeyA
private timer array TimerKeyB
private timer array TimerKeyC
private trigger array TriggerKeyA
private trigger array TriggerKeyB
private trigger array TriggerKeyC
private dialog array DialogKeyA
private dialog array DialogKeyB
private dialog array DialogKeyC
private region array RegionKeyA
private region array RegionKeyB
private region array RegionKeyC
private integer array TimerValueA
private integer array TimerValueB
private integer array TimerValueC
private integer array TriggerValueA
private integer array TriggerValueB
private integer array TriggerValueC
private integer array DialogValueA
private integer array DialogValueB
private integer array DialogValueC
private integer array RegionValueA
private integer array RegionValueB
private integer array RegionValueC
private integer array TimerCollisionA
private integer array TimerCollisionB
private integer array TimerCollisionC
private integer array TriggerCollisionA
private integer array TriggerCollisionB
private integer array TriggerCollisionC
private integer array DialogCollisionA
private integer array DialogCollisionB
private integer array DialogCollisionC
private integer array RegionCollisionA
private integer array RegionCollisionB
private integer array RegionCollisionC
private integer TimerMaxCollisionA = 0
private integer TimerMaxCollisionB = 0
private integer TimerMaxCollisionC = 0
private integer TriggerMaxCollisionA = 0
private integer TriggerMaxCollisionB = 0
private integer TriggerMaxCollisionC = 0
private integer DialogMaxCollisionA = 0
private integer DialogMaxCollisionB = 0
private integer DialogMaxCollisionC = 0
private integer RegionMaxCollisionA = 0
private integer RegionMaxCollisionB = 0
private integer RegionMaxCollisionC = 0
private hashtable TimerHash
private hashtable TriggerHash
private hashtable DialogHash
private hashtable RegionHash
endglobals
//==============================================================================
// Collision check functions
//==============================================================================
//------------------------------------------------------------------------------
function GetTimerCollisionA takes nothing returns integer
return TimerMaxCollisionA
endfunction
//------------------------------------------------------------------------------
function GetTimerCollisionB takes nothing returns integer
return TimerMaxCollisionB
endfunction
//------------------------------------------------------------------------------
function GetTimerCollisionC takes nothing returns integer
return TimerMaxCollisionC
endfunction
//------------------------------------------------------------------------------
function GetTriggerCollisionA takes nothing returns integer
return TriggerMaxCollisionA
endfunction
//------------------------------------------------------------------------------
function GetTriggerCollisionB takes nothing returns integer
return TriggerMaxCollisionB
endfunction
//------------------------------------------------------------------------------
function GetTriggerCollisionC takes nothing returns integer
return TriggerMaxCollisionC
endfunction
//------------------------------------------------------------------------------
function GetDialogCollisionA takes nothing returns integer
return DialogMaxCollisionA
endfunction
//------------------------------------------------------------------------------
function GetDialogCollisionB takes nothing returns integer
return DialogMaxCollisionB
endfunction
//------------------------------------------------------------------------------
function GetDialogCollisionC takes nothing returns integer
return DialogMaxCollisionC
endfunction
//------------------------------------------------------------------------------
function GetRegionCollisionA takes nothing returns integer
return RegionMaxCollisionA
endfunction
//------------------------------------------------------------------------------
function GetRegionCollisionB takes nothing returns integer
return RegionMaxCollisionB
endfunction
//------------------------------------------------------------------------------
function GetRegionCollisionC takes nothing returns integer
return RegionMaxCollisionC
endfunction
//==============================================================================
// Set functions
//==============================================================================
//------------------------------------------------------------------------------
function SetTimerStructA takes timer key, integer value returns nothing
//! runtextmacro ABC_Set("A", "Timer", "timer")
endfunction
//------------------------------------------------------------------------------
function SetTimerStructB takes timer key, integer value returns nothing
//! runtextmacro ABC_Set("B", "Timer", "timer")
endfunction
//------------------------------------------------------------------------------
function SetTimerStructC takes timer key, integer value returns nothing
//! runtextmacro ABC_Set("C", "Timer", "timer")
endfunction
//------------------------------------------------------------------------------
function SetTriggerStructA takes trigger key, integer value returns nothing
//! runtextmacro ABC_Set("A", "Trigger", "trigger")
endfunction
//------------------------------------------------------------------------------
function SetTriggerStructB takes trigger key, integer value returns nothing
//! runtextmacro ABC_Set("B", "Trigger", "trigger")
endfunction
//------------------------------------------------------------------------------
function SetTriggerStructC takes trigger key, integer value returns nothing
//! runtextmacro ABC_Set("C", "Trigger", "trigger")
endfunction
//------------------------------------------------------------------------------
function SetDialogStructA takes dialog key, integer value returns nothing
//! runtextmacro ABC_Set("A", "Dialog", "dialog")
endfunction
//------------------------------------------------------------------------------
function SetDialogStructB takes dialog key, integer value returns nothing
//! runtextmacro ABC_Set("B", "Dialog", "dialog")
endfunction
//------------------------------------------------------------------------------
function SetDialogStructC takes dialog key, integer value returns nothing
//! runtextmacro ABC_Set("C", "Dialog", "dialog")
endfunction
//------------------------------------------------------------------------------
function SetRegionStructA takes region key, integer value returns nothing
//! runtextmacro ABC_Set("A", "Region", "region")
endfunction
//------------------------------------------------------------------------------
function SetRegionStructB takes region key, integer value returns nothing
//! runtextmacro ABC_Set("B", "Region", "region")
endfunction
//------------------------------------------------------------------------------
function SetRegionStructC takes region key, integer value returns nothing
//! runtextmacro ABC_Set("C", "Region", "region")
endfunction
//==============================================================================
// Get functions
//==============================================================================
//------------------------------------------------------------------------------
function GetTimerStructA takes timer key returns integer
//! runtextmacro ABC_Get("A", "Timer", "timer")
endfunction
//------------------------------------------------------------------------------
function GetTimerStructB takes timer key returns integer
//! runtextmacro ABC_Get("B", "Timer", "timer")
endfunction
//------------------------------------------------------------------------------
function GetTimerStructC takes timer key returns integer
//! runtextmacro ABC_Get("C", "Timer", "timer")
endfunction
//------------------------------------------------------------------------------
function GetTriggerStructA takes trigger key returns integer
//! runtextmacro ABC_Get("A", "Trigger", "trigger")
endfunction
//------------------------------------------------------------------------------
function GetTriggerStructB takes trigger key returns integer
//! runtextmacro ABC_Get("B", "Trigger", "trigger")
endfunction
//------------------------------------------------------------------------------
function GetTriggerStructC takes trigger key returns integer
//! runtextmacro ABC_Get("C", "Trigger", "trigger")
endfunction
//------------------------------------------------------------------------------
function GetDialogStructA takes dialog key returns integer
//! runtextmacro ABC_Get("A", "Dialog", "dialog")
endfunction
//------------------------------------------------------------------------------
function GetDialogStructB takes dialog key returns integer
//! runtextmacro ABC_Get("B", "Dialog", "dialog")
endfunction
//------------------------------------------------------------------------------
function GetDialogStructC takes dialog key returns integer
//! runtextmacro ABC_Get("C", "Dialog", "dialog")
endfunction
//------------------------------------------------------------------------------
function GetRegionStructA takes region key returns integer
//! runtextmacro ABC_Get("A", "Region", "region")
endfunction
//------------------------------------------------------------------------------
function GetRegionStructB takes region key returns integer
//! runtextmacro ABC_Get("B", "Region", "region")
endfunction
//------------------------------------------------------------------------------
function GetRegionStructC takes region key returns integer
//! runtextmacro ABC_Get("C", "Region", "region")
endfunction
//==============================================================================
// Clear functions
//==============================================================================
//------------------------------------------------------------------------------
function ClearTimerStructA takes timer key returns integer
//! runtextmacro ABC_Clear("A", "Timer", "timer")
endfunction
//------------------------------------------------------------------------------
function ClearTimerStructB takes timer key returns integer
//! runtextmacro ABC_Clear("B", "Timer", "timer")
endfunction
//------------------------------------------------------------------------------
function ClearTimerStructC takes timer key returns integer
//! runtextmacro ABC_Clear("C", "Timer", "timer")
endfunction
//------------------------------------------------------------------------------
function ClearTriggerStructA takes trigger key returns integer
//! runtextmacro ABC_Clear("A", "Trigger", "trigger")
endfunction
//------------------------------------------------------------------------------
function ClearTriggerStructB takes trigger key returns integer
//! runtextmacro ABC_Clear("B", "Trigger", "trigger")
endfunction
//------------------------------------------------------------------------------
function ClearTriggerStructC takes trigger key returns integer
//! runtextmacro ABC_Clear("C", "Trigger", "trigger")
endfunction
//------------------------------------------------------------------------------
function ClearDialogStructA takes dialog key returns integer
//! runtextmacro ABC_Clear("A", "Dialog", "dialog")
endfunction
//------------------------------------------------------------------------------
function ClearDialogStructB takes dialog key returns integer
//! runtextmacro ABC_Clear("B", "Dialog", "dialog")
endfunction
//------------------------------------------------------------------------------
function ClearDialogStructC takes dialog key returns integer
//! runtextmacro ABC_Clear("C", "Dialog", "dialog")
endfunction
//------------------------------------------------------------------------------
function ClearRegionStructA takes region key returns integer
//! runtextmacro ABC_Clear("A", "Region", "region")
endfunction
//------------------------------------------------------------------------------
function ClearRegionStructB takes region key returns integer
//! runtextmacro ABC_Clear("B", "Region", "region")
endfunction
//------------------------------------------------------------------------------
function ClearRegionStructC takes region key returns integer
//! runtextmacro ABC_Clear("C", "Region", "region")
endfunction
//==============================================================================
// Initialization
//==============================================================================
private function Init takes nothing returns nothing
set TimerKeyA[HASH-1] = null
set TimerKeyB[HASH-1] = null
set TimerKeyC[HASH-1] = null
set TriggerKeyA[HASH-1] = null
set TriggerKeyB[HASH-1] = null
set TriggerKeyC[HASH-1] = null
set DialogKeyA[HASH-1] = null
set DialogKeyB[HASH-1] = null
set DialogKeyC[HASH-1] = null
set RegionKeyA[HASH-1] = null
set RegionKeyB[HASH-1] = null
set RegionKeyC[HASH-1] = null
set TimerValueA[HASH-1] = 0
set TimerValueB[HASH-1] = 0
set TimerValueC[HASH-1] = 0
set TriggerValueA[HASH-1] = 0
set TriggerValueB[HASH-1] = 0
set TriggerValueC[HASH-1] = 0
set DialogValueA[HASH-1] = 0
set DialogValueB[HASH-1] = 0
set DialogValueC[HASH-1] = 0
set RegionValueA[HASH-1] = 0
set RegionValueB[HASH-1] = 0
set RegionValueC[HASH-1] = 0
set TimerCollisionA[HASH-1] = 0
set TimerCollisionB[HASH-1] = 0
set TimerCollisionC[HASH-1] = 0
set TriggerCollisionA[HASH-1] = 0
set TriggerCollisionB[HASH-1] = 0
set TriggerCollisionC[HASH-1] = 0
set DialogCollisionA[HASH-1] = 0
set DialogCollisionB[HASH-1] = 0
set DialogCollisionC[HASH-1] = 0
set RegionCollisionA[HASH-1] = 0
set RegionCollisionB[HASH-1] = 0
set RegionCollisionC[HASH-1] = 0
set TimerHash = InitHashtable()
set TriggerHash = InitHashtable()
set DialogHash = InitHashtable()
set RegionHash = InitHashtable()
endfunction
endlibrary
//==============================================================================
// END OF ABC STRUCT ATTACHMENT SYSTEM
//==============================================================================
</i></i></i></i></i></i></i></i></i></i></i></i></i></i></i>
library Table
//***************************************************************
//* Table object 3.0
//* ------------
//*
//* set t=Table.create() - instanceates a new table object
//* call t.destroy() - destroys it
//* t[1234567] - Get value for key 1234567
//* (zero if not assigned previously)
//* set t[12341]=32 - Assigning it.
//* call t.flush(12341) - Flushes the stored value, so it
//* doesn't use any more memory
//* t.exists(32) - Was key 32 assigned? Notice
//* that flush() unassigns values.
//* call t.reset() - Flushes the whole contents of the
//* Table.
//*
//* call t.destroy() - Does reset() and also recycles the id.
//*
//* If you use HandleTable instead of Table, it is the same
//* but it uses handles as keys, the same with StringTable.
//*
//* You can use Table on structs' onInit if the struct is
//* placed in a library that requires Table or outside a library.
//*
//* You can also do 2D array syntax if you want to touch
//* mission keys directly, however, since this is shared space
//* you may want to prefix your mission keys accordingly:
//*
//* set Table["thisstring"][ 7 ] = 2
//* set Table["thisstring"][ 5 ] = Table["thisstring"][7]
//*
//***************************************************************
//=============================================================
globals
private constant integer MAX_INSTANCES=8100 //400000
//Feel free to change max instances if necessary, it will only affect allocation
//speed which shouldn't matter that much.
//=========================================================
private hashtable ht
endglobals
private struct GTable[MAX_INSTANCES]
method reset takes nothing returns nothing
call FlushChildHashtable(ht, integer(this) )
endmethod
private method onDestroy takes nothing returns nothing
call this.reset()
endmethod
//=============================================================
// initialize it all.
//
private static method onInit takes nothing returns nothing
set ht = InitHashtable()
endmethod
endstruct
//Hey: Don't instanciate other people's textmacros that you are not supposed to, thanks.
//! textmacro Table__make takes name, type, key
struct $name$ extends GTable
method operator [] takes $type$ key returns integer
return LoadInteger(ht, integer(this), $key$)
endmethod
method operator []= takes $type$ key, integer value returns nothing
call SaveInteger(ht, integer(this) ,$key$, value)
endmethod
method flush takes $type$ key returns nothing
call RemoveSavedInteger(ht, integer(this), $key$)
endmethod
method exists takes $type$ key returns boolean
return HaveSavedInteger( ht, integer(this) ,$key$)
endmethod
static method flush2D takes string firstkey returns nothing
call $name$(- StringHash(firstkey)).reset()
endmethod
static method operator [] takes string firstkey returns $name$
return $name$(- StringHash(firstkey) )
endmethod
endstruct
//! endtextmacro
//! runtextmacro Table__make("Table","integer","key" )
//! runtextmacro Table__make("StringTable","string", "StringHash(key)" )
//! runtextmacro Table__make("HandleTable","handle","GetHandleId(key)" )
endlibrary
/*******************************************************************************************
Faux Handle Vars
----------------
Do not use these functions for new stuff, it is just not the right thing to do...
The intention of Faux Handle Vars is to be a patch fix for a map's migration to
patch 1.24 This library might not cover all uses of handle vars, some of them are just
impossible with the new rules set in patches 1.23b and 1.24, but they should work for
most of the cases....
All of them but the SetHandle*** ones are inline friendly. I follow the interface
in official Kattana's handle vars from wc3jass.com, if your handle vars functions
look different, then you were not using handle vars but another thing...
*******************************************************************************************/
//==========================================================================================
library HandleVars initializer init
globals
private hashtable ht
endglobals
// too bad the Handle vars' old functionality forces me to make these things
// inline-unfriendly
function SetHandleHandle takes agent subject, string label, agent value returns nothing
if(value==null) then
call RemoveSavedHandle( ht, GetHandleId(subject), StringHash(label))
else
call SaveAgentHandle( ht, GetHandleId(subject), StringHash(label), value)
endif
endfunction
function SetHandleInt takes agent subject, string label, integer value returns nothing
if value==0 then
call RemoveSavedInteger(ht, GetHandleId(subject), StringHash(label))
else
call SaveInteger(ht, GetHandleId(subject), StringHash(label), value)
endif
endfunction
function SetHandleBoolean takes agent subject, string label, boolean value returns nothing
if (value == false) then
call RemoveSavedBoolean(ht, GetHandleId(subject), StringHash(label))
else
call SaveBoolean(ht, GetHandleId(subject), StringHash(label), value)
endif
endfunction
function SetHandleReal takes agent subject, string label, real value returns nothing
if (value == 0.0) then
call RemoveSavedReal(ht, GetHandleId(subject), StringHash(label))
else
call SaveReal(ht, GetHandleId(subject), StringHash(label), value)
endif
endfunction
function SetHandleString takes agent subject, string label, string value returns nothing
if ((value=="") or (value==null)) then
call RemoveSavedString(ht, GetHandleId(subject), StringHash(label))
else
call SaveStr(ht, GetHandleId(subject), StringHash(label), value) //yay for blizz' consistent naming scheme...
endif
endfunction
function GetHandleHandle takes agent subject, string label returns agent
debug call BJDebugMsg("[debug] What the heck? Why would you call HandleHandle I guess this was caused by a search and replace mistake")
return null
endfunction
// these are inline friendly, ok, maybe they aren't because jasshelper does not recognize
// GetHandleId as non-state changing. But they will be once I fix jasshelper...
function GetHandleInt takes agent subject, string label returns integer
return LoadInteger(ht, GetHandleId(subject), StringHash(label))
endfunction
function GetHandleBoolean takes agent subject, string label returns boolean
return LoadBoolean(ht, GetHandleId(subject), StringHash(label))
endfunction
function GetHandleString takes agent subject, string label returns string
return LoadStr(ht, GetHandleId(subject), StringHash(label))
endfunction
function GetHandleReal takes agent subject, string label returns real
return LoadReal(ht, GetHandleId(subject), StringHash(label))
endfunction
// got bored so I now use a textmacro...
//! textmacro FAUX_HANDLE_VARS_GetHandleHandle takes NAME, TYPE
function SetHandle$NAME$ takes agent subject, string label, $TYPE$ value returns nothing
if(value==null) then
call RemoveSavedHandle( ht, GetHandleId(subject), StringHash(label))
else
call Save$NAME$Handle( ht, GetHandleId(subject), StringHash(label), value)
endif
endfunction
function GetHandle$NAME$ takes agent subject, string label returns $TYPE$
return Load$NAME$Handle( ht, GetHandleId(subject), StringHash(label))
endfunction
//! endtextmacro
//! runtextmacro FAUX_HANDLE_VARS_GetHandleHandle("Player","player")
//! runtextmacro FAUX_HANDLE_VARS_GetHandleHandle("Widget","widget")
//! runtextmacro FAUX_HANDLE_VARS_GetHandleHandle("Destructable","destructable")
//! runtextmacro FAUX_HANDLE_VARS_GetHandleHandle("Item","item")
//! runtextmacro FAUX_HANDLE_VARS_GetHandleHandle("Unit","unit")
//! runtextmacro FAUX_HANDLE_VARS_GetHandleHandle("Ability","ability")
//! runtextmacro FAUX_HANDLE_VARS_GetHandleHandle("Timer","timer")
//! runtextmacro FAUX_HANDLE_VARS_GetHandleHandle("Trigger","trigger")
//! runtextmacro FAUX_HANDLE_VARS_GetHandleHandle("TriggerCondition","triggercondition")
//! runtextmacro FAUX_HANDLE_VARS_GetHandleHandle("TriggerAction","triggeraction")
//! runtextmacro FAUX_HANDLE_VARS_GetHandleHandle("TriggerEvent","event")
//! runtextmacro FAUX_HANDLE_VARS_GetHandleHandle("Force","force")
//! runtextmacro FAUX_HANDLE_VARS_GetHandleHandle("Group","group")
//! runtextmacro FAUX_HANDLE_VARS_GetHandleHandle("Location","location")
//! runtextmacro FAUX_HANDLE_VARS_GetHandleHandle("Rect","rect")
//! runtextmacro FAUX_HANDLE_VARS_GetHandleHandle("BooleanExpr","boolexpr")
//! runtextmacro FAUX_HANDLE_VARS_GetHandleHandle("Sound","sound")
//! runtextmacro FAUX_HANDLE_VARS_GetHandleHandle("Effect","effect")
//! runtextmacro FAUX_HANDLE_VARS_GetHandleHandle("UnitPool","unitpool")
//! runtextmacro FAUX_HANDLE_VARS_GetHandleHandle("ItemPool","itempool")
//! runtextmacro FAUX_HANDLE_VARS_GetHandleHandle("Quest","quest")
//! runtextmacro FAUX_HANDLE_VARS_GetHandleHandle("QuestItem","questitem")
//! runtextmacro FAUX_HANDLE_VARS_GetHandleHandle("DefeatCondition","defeatcondition")
//! runtextmacro FAUX_HANDLE_VARS_GetHandleHandle("TimerDialog","timerdialog")
//! runtextmacro FAUX_HANDLE_VARS_GetHandleHandle("Leaderboard","leaderboard")
//! runtextmacro FAUX_HANDLE_VARS_GetHandleHandle("Multiboard","multiboard")
//! runtextmacro FAUX_HANDLE_VARS_GetHandleHandle("MultiboardItem","multiboarditem")
//! runtextmacro FAUX_HANDLE_VARS_GetHandleHandle("Trackable","trackable")
//! runtextmacro FAUX_HANDLE_VARS_GetHandleHandle("Dialog","dialog")
//! runtextmacro FAUX_HANDLE_VARS_GetHandleHandle("Button","button")
//! runtextmacro FAUX_HANDLE_VARS_GetHandleHandle("TextTag","texttag")
//! runtextmacro FAUX_HANDLE_VARS_GetHandleHandle("Lightning","lightning")
//! runtextmacro FAUX_HANDLE_VARS_GetHandleHandle("Image","image")
//! runtextmacro FAUX_HANDLE_VARS_GetHandleHandle("Ubersplat","ubersplat")
//! runtextmacro FAUX_HANDLE_VARS_GetHandleHandle("Region","region")
//! runtextmacro FAUX_HANDLE_VARS_GetHandleHandle("FogState","fogstate")
//! runtextmacro FAUX_HANDLE_VARS_GetHandleHandle("FogModifier","fogmodifier")
//! runtextmacro FAUX_HANDLE_VARS_GetHandleHandle("Hashtable","hashtable")
function FlushHandleVars takes agent subject returns nothing
call FlushChildHashtable(ht, GetHandleId(subject))
endfunction
function FlushHandleLocals takes agent subject returns nothing
call FlushHandleVars(subject)
endfunction
private function init takes nothing returns nothing
set ht=InitHashtable()
endfunction
endlibrary
library_once TimerUtils initializer init
//*********************************************************************
//* TimerUtils (Blue flavor for 1.23b or later)
//* ----------
//*
//* To implement it , create a custom text trigger called TimerUtils
//* and paste the contents of this script there.
//*
//* To copy from a map to another, copy the trigger holding this
//* library to your map.
//*
//* (requires vJass) More scripts: htt://www.wc3campaigns.net
//*
//* For your timer needs:
//* * Attaching
//* * Recycling (with double-free protection)
//*
//* set t=NewTimer() : Get a timer (alternative to CreateTimer)
//* ReleaseTimer(t) : Relese a timer (alt to DestroyTimer)
//* SetTimerData(t,2) : Attach value 2 to timer
//* GetTimerData(t) : Get the timer's value.
//* You can assume a timer's value is 0
//* after NewTimer.
//*
//* Blue Flavor: Slower than the red flavor, it got a 408000 handle id
//* limit, which means that if more than 408000 handle ids
//* are used in your map, TimerUtils might fail, this
//* value is quite big and it is much bigger than the
//* timer limit in Red flavor.
//*
//********************************************************************
//==================================================================================================
globals
private hashtable hasht //I <3 blizz
endglobals
//It is dependent on jasshelper's recent inlining optimization in order to perform correctly.
function SetTimerData takes timer t, integer value returns nothing
call SaveInteger(hasht,0, GetHandleId(t), value)
endfunction
function GetTimerData takes timer t returns integer
return LoadInteger(hasht, 0, GetHandleId(t))
endfunction
//==========================================================================================
globals
private timer array tT
private integer tN = 0
private constant integer HELD=0x28829022
//use a totally random number here, the more improbable someone uses it, the better.
endglobals
//==========================================================================================
function NewTimer takes nothing returns timer
if (tN==0) then
set tT[0]=CreateTimer()
else
set tN=tN-1
endif
call SetTimerData(tT[tN],0)
return tT[tN]
endfunction
//==========================================================================================
function ReleaseTimer takes timer t returns nothing
if(t==null) then
debug call BJDebugMsg("Warning: attempt to release a null timer")
return
endif
if (tN==8191) then
debug call BJDebugMsg("Warning: Timer stack is full, destroying timer!!")
//stack is full, the map already has much more troubles than the chance of bug
call DestroyTimer(t)
else
call PauseTimer(t)
if(GetTimerData(t)==HELD) then
debug call BJDebugMsg("Warning: ReleaseTimer: Double free!")
return
endif
call SetTimerData(t,HELD)
set tT[tN]=t
set tN=tN+1
endif
endfunction
private function init takes nothing returns nothing
set hasht = InitHashtable()
endfunction
endlibrary