Name | Type | is_array | initial_value |
//TESH.scrollpos=0
//TESH.alwaysfold=0
library ReputationSystem requires Table, UnitIndexer //by edo494
/*
Table by Bribe - http://www.hiveworkshop.com/forums/jass-resources-412/snippet-new-table-188084/
UnitIndexer by Nestharus - http://www.hiveworkshop.com/forums/jass-resources-412/system-unit-indexer-172090/
This is wrote mainly for my own needs
This system allows you to create factions(reputations) for instance shops with requirements of some reputation,
gain reputation when we kill some monster and also gain some reputation when for isntance quests are done
You can also deincrease reputation to punish not good done job and other stuff.
Together with custom units and techtree, you can even have shops with items which require you to have some amount
of reputation in order to buy those items.
note: When I say in API reputation I most likely mean reputation as currency and reputation itself is
referred as faction.
*/
//------------------------------------------------------------------------
/*
API: First is struct API, if you are too lazy to use it, under it is a normal funcion API
struct reputation
Normal API:
(static) function(arguments) -> return type(if any) description
static create(string) -> Reputation //Creates a new faction with name
static createEx(string, integer) -> Reputation //Creates a new faction with name at starting value of reputation
remove() //Destroys a given faction
static setRank(integer rank, string, integer tonextrank) //Creates a new rank(currently globally), like hostile, friendly, revered ...
//has a protection of overriding ranks(in debug displays message)
increase(integer howmany, integer forplayer) //Adds reputation in given faction for a player
decrease(integer howmany, integer forplayer) //Lowers reputation in given faction for a player
getName() -> string //returns a name of a faction
repS2I(string name) -> integer //turns a name of a faction into an integer(id of a faction), if invalid returns 0
//This method can be used to get a non referenced reputation by knowing its name.
getRep(integer ofplayer) -> integer //returns a current standing of a player to faction(not Rank but value)
getTotalRep(integer playerindex) -> integer //returns total reputation of player gained
getTypeById(integer id) -> string //returns a name of a rank by id(this is not bound to faction)
getRankTypeOfPlayer(integer ofplayer) -> string //returns name of a current rank in given faction of player
getRankOfPlayer(integer ofplayer) -> integer //returns a current rank in given faction of player(the same as GetCurrentRepTypeOfPlayer but as integer)
Trigger API:
global private constant boolean wanttoregister = true //if you want to use TriggerRegisterRepChange, let it true, otherwise set to false
//to shorten the code a little bit
registerRepChangeEvent(code c, integer rankchange, boolean upside) //registers a rankchange to trigger, the boolean tells
//if it is upside or downside, whenever the reputation rank is changed
//all functions registered to that reputation are executed regardless of how much
//times the same function is there
Single Player API:
Those commands shouldnt be used in multiplayer games because they are not changed for each player differently
and doing so could desync the game.
addToFaction(unit toadd) -> boolean //Bounds a unit to that faction. One unit can be in any number of factions
//but that may cause problems in changing aggresivity.
//If successful returns true, if already saved or invalid unit(null) returns false.
removeFromFaction(unit toremove) -> boolean //Removes a unit from a faction. If successful returns true, otherwise returns false.
defineHostility(integer rank) //Defines at which rank the units start to be friendly/hostile in that faction. Default is: friendly at all time.
changeFaction(boolean good) //Immedietally forces the system to swtich all units in given faction to
//friendly(true) or hostile(false)
static getOriginalOwner(unit u) -> player //returns a original owner of a unit bound to faction
static getOriginalOwnerId(unit u) -> integer //returns Id of original owner of a unit bound to faction
In case you dont like to use structs or methods, there is library with a function API for this system(it requires this system tho).
*/
//------------------------------------------------------------------------
/*
Change note:
Version Log:
122812 - rewrote the documentation
- made some fixes
- rereleased
121108 - fixed a bug with reqxp variable in .remove() method
- fixed a bugged .remove() method destroying a Rank as well
- fixed a badly scripted .increase() and .decrease() not working properly
- fixed .getName() and .getS2I() not working correctly
121107b - lighted up .update() method, making it O(n) (was O(O(n)) before)
121107 - fixed a bug with CreateNewRepEx(121107 and later, createEx) not
setting name of the reputation
- renamed all methods(check API to see new names)
- moved function API into separated library
- reworked how repS2I works ( O(n) -> O(1) )
121104 - remoworked how .ChangeFaction() works in AddRep and LowerRep methods
- added 2 new methods: GetOriginalOwner and GetOriginalOwnerId as well as 2 functions
with the same name
121103 - Intial release
*/
//------------------------------------------------------------------------
globals
private constant boolean wanttoregister = true //If you plan on using RegisterRepChangeEvent let this true, otherwise set to false
endglobals
struct Reputation
private static string array reptypename
private static Table repname
private static integer maxreptype = 0
private static TableArray tab
private static TableArray tac
private static integer array pointtoname //sololy for .getName() so we can point to every instance, otherwise
//method repS2I would be O(n)
private static integer array repreq
private static integer array reqxp
/*
why all arrays instead of normal variables as reptypename may you ask?
I like array syntax more then struct syntax, also I dont need to declare another
integer(thistype) in every function Im passing integers not reputation or without allocation
and still can access the desired index. Example is in setRank
If I didnt have arrays I would have to declare another integer = waste of memory
*/
static method create takes string name returns thistype
local integer i = 0
local thistype this = .allocate()
set pointtoname[this] = StringHash(name)
set repname[pointtoname[this]] = this
set repname.string[this] = name
loop
set tac[i][this] = 0
exitwhen i == 15
set i = i + 1
endloop
return this
endmethod
static method createEx takes string name, integer startingrep returns thistype
local integer i = 0
local thistype this = .allocate()
set pointtoname[this] = StringHash(name)
set repname[pointtoname[this]] = this
set repname.string[this] = name
loop
set tac[i][this] = startingrep
exitwhen i == 15
set i = i + 1
endloop
return this
endmethod
method remove takes nothing returns nothing
local integer i = 0
set repname.string[this] = ""
set repname[pointtoname[this]] = 0
set pointtoname[this] = 0
loop
set tab[i][this] = 0
exitwhen i == 15
set i = i + 1
endloop
call .deallocate()
endmethod
static method setRank takes integer rank, string name, integer xpto returns nothing
//protection
if repreq[rank] == -1 then
debug call BJDebugMsg("rank in Reputation" + I2S(rank) + " already exists")
return
endif
set repreq[rank] = -1
set reptypename[rank] = name
// to ensure that even when we get over the rep needed it will show the correct rep
set reptypename[rank+1] = name
set reqxp[rank] = xpto
set maxreptype = maxreptype + 1
endmethod
method changeFaction takes boolean good returns nothing
local unit u
local integer i = 1
loop
set u = GetUnitById(saver[this][i])
if good then
call SetUnitOwner(u, Player(15), true)
else
call SetUnitOwner(u, Player(12), true)
endif
exitwhen i == hunit[this]
set i = i + 1
endloop
endmethod
method increase takes integer howmany, integer forplayer returns nothing
local integer a = tac[forplayer][this]
local integer b = tab[forplayer][this]
set a = a + howmany
loop
exitwhen a < reqxp[b] or maxreptype == b
if a > reqxp[b] then
set a = a - reqxp[b]
set b = b + 1
endif
endloop
if b > hostile[this] and not changed[this] then
call .changeFaction(true)
set changed[this] = true
endif
static if wanttoregister then
if b > (tac[forplayer][this]) then
if regist[this].trigger[b*2-1] != null then
call TriggerEvaluate(regist[this].trigger[b*2-1])
endif
endif
endif
set tac[forplayer][this] = a
set tab[forplayer][this] = b
endmethod
method decrease takes integer howmany, integer forplayer returns nothing
local integer a = tac[forplayer][this]
local integer b = tab[forplayer][this]
set a = a - howmany
loop
exitwhen a > 0 or b == 0
if b <= 0 and a < 0 then
set a = 0
endif
set a = a + reqxp[b]
set b = b - 1
endloop
if b < hostile[this] and changed[this] then
call .changeFaction(false)
set changed[this] = false
endif
static if wanttoregister then
if b < (tac[forplayer][this]) then
if regist[this].trigger[b*2] != null then
call TriggerEvaluate(regist[this].trigger[b*2])
endif
endif
endif
set tac[forplayer][this] = a
set tab[forplayer][this] = b
endmethod
method getName takes nothing returns string
return repname.string[repname[pointtoname[this]]]
endmethod
static method repS2I takes string name returns integer
return repname[StringHash(name)]
endmethod
method getRep takes integer playerindex returns integer
return tac[playerindex][this]
endmethod
method getTotalRep takes integer playerindex returns integer
local integer a = tab[this][playerindex]
local integer total = tac[this][playerindex]
loop
exitwhen a == 0
set total = total + reqxp[a]
endloop
return total
endmethod
static method getTypeById takes integer id returns string
return reptypename[id]
endmethod
method getRankTypeOfPlayer takes integer forplayer returns string
return reptypename[tab[forplayer][this]]
endmethod
method getRankOfPlayer takes integer ofplayer returns integer
return tab[ofplayer][this]
endmethod
// !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
private static method onInit takes nothing returns nothing
set tab = TableArray[16]
set tac = TableArray[16]
set saver = TableArray[0x2000]
set repname = Table.create()
static if wanttoregister then
set regist = TableArray[0x2000]
endif
endmethod
// !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
//Single Player commands:
private static TableArray saver
private static integer array hostile
private static integer array hunit
private static player array origown
private static boolean array changed
private method update takes nothing returns nothing
local integer forplayer = 0
local integer q
set forplayer = 0
set q = tab[forplayer][this]
loop
if hostile[this] >= q and not changed[this] then
call .changeFaction(true)
elseif hostile[this] < q and changed[this] then
call .changeFaction(false)
endif
exitwhen forplayer == 15
set forplayer = forplayer + 1
endloop
endmethod
method addToFaction takes unit u returns boolean
//double save protection
if saver[this][GetUnitUserData(u)] != GetUnitUserData(u) and u != null then
set saver[this][GetUnitUserData(u)] = GetUnitUserData(u)
set origown[GetUnitUserData(u)] = GetOwningPlayer(u)
set hunit[this] = hunit[this] + 1
call .update()
return true
else
return false
endif
endmethod
method removeFromFaction takes unit u returns boolean
//double free protection
if saver[this][GetUnitUserData(u)] == 0 or u == null then
return false
else
set saver[this][GetUnitUserData(u)] = 0
set hunit[this] = hunit[this] - 1
set origown[this] = null
return true
endif
endmethod
method defineHostility takes integer rank returns nothing
set hostile[this] = rank
call .update()
endmethod
// Register command:
static if wanttoregister then
private static TableArray regist
method registerRepChangeEvent takes code c, integer rankchange, boolean upside returns nothing
if upside then
if regist[this].trigger[rankchange*2-1] == null then
set regist[this].trigger[rankchange*2-1] = CreateTrigger()
endif
call TriggerAddCondition(regist[this].trigger[rankchange*2-1], Condition(c))
else
if regist[this].trigger[rankchange*2] == null then
set regist[this].trigger[rankchange*2] = CreateTrigger()
endif
call TriggerAddCondition(regist[this].trigger[rankchange*2], Condition(c))
endif
endmethod
endif
static method getOriginalOwner takes unit u returns player
return origown[GetUnitUserData(u)]
endmethod
static method getOriginalOwnerId takes unit u returns integer
return GetPlayerId(origown[GetUnitUserData(u)])
endmethod
endstruct
endlibrary
library ReputationSystemFunctionAPI requires ReputationSystem //by edo494
/*
Im not going to say what each function does, if you want to know, please reffer to their counterparts in struct
API:
function(arguments) -> return type(if any)...................................what the function does
CreateNewReputation(string name) -> reputation return Reputation.create(name)
CreateNewReputationEx(string name, integer startingrep) -> reputation return Reputation.createEx(name, startingrep)
RemoveReputation(Reputation rep) call rep.remove()
SetReputationRank(integer rank, string name, integer xpto) call Reputation.setRank(rank, name, xpto)
IncreaseReputation(Reputation rep, integer value, integer forplayer) call rep.increase(value, forplayer)
LowerReputation(Reputation rep, integer value, integer forplayer) call rep.decrease(value, forplayer)
GetReputationName(Reputation rep) -> string return rep.getName()
ReputationS2I(string s) -> integer return Reputation.repS2I(s)
GetCurrentReputation(Reputation rep, integer playerindex) -> integer return rep.getRep(playerindex)
GetTotalReputation(Reputation rep, integer playerindex) -> integer return rep.getTotalXp(playerindex)
GetRepTypeById(integer id) -> string return Reputation.getTypeById(id)
GetCurrentRepTypeOfPlayer(Reputation rep, integer playerindex) -> string return rep.getRankTypeOfPlayer(playerindex)
GetCurrentRankOfPlayer(Reputation rep, integer playerindex) -> integer return rep.getRankOfPlayer(playerindex)
//----------------------------------------------------------
Single Player API(Should not be used in multiplayer for 100% correct result)
ChangeFaction(Reputation rep, boolean flag) call rep.changeFaction(flag)
AddUnitToFaction(Reputation rep, unit u) call rep.addToFaction(u)
RemoveUnitFromFaction(Reputation rep, unit u) call rep.removeFromFaction(u)
DefineHostility(Reputation rep, integer rank) call rep.defineHostility(rank)
GetOriginalOwner(unit u) -> player return Reputation.getOriginalOwner(u)
GetOriginalOwnerId(unit u) -> integer return Reputation.getOriginalOwnerId(u)
//----------------------------------------------------------
Trigger API, only works with global called wanttoregister == true
RegisterRepChangeEvent(reputation rep, code c, integer rank, boolean good) call rep.registerRepChangeEvent(c, rank, flag)
*/
// Function API:
function CreateNewReputation takes string name returns Reputation
return Reputation.create(name)
endfunction
function CreateNewReputationEx takes string name, integer startingrep returns Reputation
return Reputation.createEx(name, startingrep)
endfunction
function RemoveReputation takes Reputation rep returns nothing
call rep.remove()
endfunction
function SetReputationRank takes integer rank, string name, integer xpto returns nothing
call Reputation.setRank(rank, name, xpto)
endfunction
function IncreaseReputation takes Reputation rep, integer value, integer forplayer returns nothing
call rep.increase(value, forplayer)
endfunction
function LowerReputation takes Reputation rep, integer value, integer forplayer returns nothing
call rep.decrease(value, forplayer)
endfunction
function GetReputationName takes Reputation rep returns string
return rep.getName()
endfunction
function ReputationS2I takes string s returns integer
return Reputation.repS2I(s)
endfunction
function GetCurrentReputation takes Reputation rep, integer playerindex returns integer
return rep.getRep(playerindex)
endfunction
function GetRepTypeById takes integer id returns string
return Reputation.getTypeById(id)
endfunction
function GetCurrentRepTypeOfPlayer takes Reputation rep, integer playerindex returns string
return rep.getRankTypeOfPlayer(playerindex)
endfunction
function GetCurrentRankOfPlayer takes Reputation rep, integer playerindex returns integer
return rep.getRankOfPlayer(playerindex)
endfunction
function ChangeFaction takes Reputation rep, boolean flag returns nothing
call rep.changeFaction(flag)
endfunction
function AddUnitToFaction takes Reputation rep, unit u returns nothing
call rep.addToFaction(u)
endfunction
function RemoveUnitFromFaction takes Reputation rep, unit u returns nothing
call rep.removeFromFaction(u)
endfunction
function DefineHostility takes Reputation rep, integer rank returns nothing
call rep.defineHostility(rank)
endfunction
static if wanttoregister then
function RegisterRepChangeEvent takes Reputation rep, code c, integer rank, boolean flag returns nothing
call rep.registerRepChangeEvent(c, rank, flag)
endfunction
endif
function GetOriginalOwner takes unit u returns player
return Reputation.getOriginalOwner(u)
endfunction
function GetOriginalOwnerId takes unit u returns integer
return Reputation.getOriginalOwnerId(u)
endfunction
function GetTotalReputation takes Reputation rep, integer playerindex returns integer
return rep.getTotalRep(playerindex)
endfunction
endlibrary
//TESH.scrollpos=201
//TESH.alwaysfold=0
library ReputationForUnit requires Table, UnitIndexer
/*
Table - http://www.hiveworkshop.com/forums/jass-resources-412/snippet-new-table-188084/
UnitIndexer - http://www.hiveworkshop.com/forums/jass-resources-412/system-unit-indexer-172090/
This library does the same as the Reputation library but this one works for unit rather then player per instance.
One unit for one instace of this struct
The name is URep to keep it intuitive(Unit based Reputation System, shortly URep) yet short enough to make it easy
to type while creating maps.
API:
static create(string name, unit holder) -> URep //registers a unit and a name to unique URep and returns
//it as a struct
static createEx (string name, integer startingrep, unit registerer) -> URep //does the same as create but with
//addition of choosing your own starting reputation
remove() //removes instance of URep(does not destroy ranks!)
static setRank(integer rank, string name, integer xpto) //creates a new rank globally for your URep struct with
//desired rank, name and xp required to gain next rank
//has a protection of setting the same rank twice
//(in debug mode will display debug message)
increase(integer howmuch) //increases a reputation(not rank!) by given value
//if a flag for having a registering trigger is set to on,
//this will also fire TriggerEvaluate in case the rank increased
decrease(integer howmuch) //decreses a reputation(not rank!) by a given value
//if a flag for having a registering trigger is set to on,
//this will also fire TriggerEvaluate in case the rank decreased
getName() -> string //returns a name of URep(string registered in create(Ex))
repS2I(string name) -> integer //returns an id of URep found by name, in case there is no
//UReps with the name, returns 0
getRep() -> integer //returns current reputation(not rank! or instance!)
//however, returned value is only a reputation from 0 to (rep to next rank)
getTotalRep() -> integer //returns total reputation of unit
getTypeById(integer id) -> string //returns a name of a rank(not reputation or isntance!) by its id
getRankType() -> string //returns current rank of unit bound to the current instance of URep
getUnit() -> unit //returns unit bound to current URep
getUnitId() -> integer //returns an index of unit bound to current URep in Unit Indexer
/--------------------------------------------------------------------
Trigger API:
constant boolean wanttoregister = true //if set to false, functionality with registering
//events to the system will not be avaliable
registerRepChangeEvent(code c, integer rankchange, boolean upside)
//registers function c to system
//when a unit gains or loses reputation and rank changes,
//this will be Evaluated depending on if it is upside or not
//true - if rank increases
//false - if rank decreases
Unlike Reputation struct, this one doesnt provide a single player commands
In case you dont like to use structs or methods, there is library with a function API for this system(it requires this system tho).
*/
globals
private constant boolean wanttoregister = true //If you plan on using RegisterURepChangeEvent let this true, otherwise set to false
endglobals
struct URep
private static unit array holding
private static string array reptypename
private static Table repname
private static integer maxreptype = 0
private static integer array xps
private static integer array rank
private static integer array pointtoname //sololy for .getName() so we can point to every instance, otherwise
//method repS2I would be O(n)
private static integer array repreq
private static integer array reqxp
private static integer array totalxp
/*
why all arrays instead of normal variables as repname may you ask?
I like array syntax more then struct syntax, also I dont need to declare another
integer(thistype) in every function Im passing integers not reputation or without allocation
and still can access the desired index. Example is in setRank
If I didnt have arrays I would have to declare another integer = waste of memory
*/
static method create takes string name, unit registerer returns thistype
local thistype this = .allocate()
set pointtoname[this] = StringHash(name)
set repname[pointtoname[this]] = this
set repname.string[this] = name
set xps[this] = 0
set holding[this] = registerer
set totalxp[this] = 0
return this
endmethod
static method createEx takes string name, integer startingrep, unit registerer returns thistype
local thistype this = .allocate()
set pointtoname[this] = StringHash(name)
set repname[pointtoname[this]] = this
set repname.string[this] = name
set xps[this] = startingrep
set holding[this] = registerer
set totalxp[this] = 0
return this
endmethod
method remove takes nothing returns nothing
set repname.string[this] = ""
set repname[pointtoname[this]] = 0
set pointtoname[this] = 0
set xps[this] = 0
set holding[this] = null
set totalxp[this] = 0
call .deallocate()
endmethod
static method setRank takes integer rank, string name, integer xpto returns nothing
//protection
if repreq[rank] == -1 then
debug call BJDebugMsg("rank in URep" + I2S(rank) + " already exists.")
return
endif
set repreq[rank] = -1
set reptypename[rank] = name
// to ensure that even when we get over the rep needed it will show the correct rep
set reptypename[rank+1] = name
set reqxp[rank] = xpto
set maxreptype = maxreptype + 1
endmethod
method increase takes integer howmany returns nothing
local integer a = xps[this] + howmany
local integer b = rank[this]
set totalxp[this] = totalxp[this] + a
loop
exitwhen a < reqxp[b] or maxreptype == b
if a > reqxp[b] then
set a = a - reqxp[b]
set b = b + 1
endif
endloop
static if wanttoregister then
if b > (rank[this]) then
if regist[this].trigger[b*2-1] != null then
call TriggerEvaluate(regist[this].trigger[b*2-1])
endif
endif
endif
set xps[this] = a
set rank[this] = b
endmethod
method decrease takes integer howmany returns nothing
local integer a = xps[this] + howmany
local integer b = rank[this]
set totalxp[this] = totalxp[this] - a
loop
exitwhen a > 0 or b == 0
if b <= 0 and a < 0 then
set a = 0
endif
set a = a + reqxp[b]
set b = b - 1
endloop
static if wanttoregister then
if b < (rank[this]) then
if regist[this].trigger[b*2] != null then
call TriggerEvaluate(regist[this].trigger[b*2])
endif
endif
endif
set xps[this] = a
set rank[this] = b
endmethod
method getName takes nothing returns string
return repname.string[repname[pointtoname[this]]]
endmethod
static method repS2I takes string name returns integer
return repname[StringHash(name)]
endmethod
method getRep takes nothing returns integer
return xps[this]
endmethod
method getTotalRep takes nothing returns integer
return totalxp[this]
endmethod
static method getTypeById takes integer id returns string
return reptypename[id]
endmethod
method getRankType takes nothing returns string
return reptypename[rank[this]]
endmethod
method getRank takes nothing returns integer
return rank[this]
endmethod
method getUnit takes nothing returns unit
return holding[this]
endmethod
method getUnitId takes nothing returns integer
return GetUnitId(holding[this])
endmethod
// !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
private static method onInit takes nothing returns nothing
set repname = Table.create()
static if wanttoregister then
set regist = TableArray[0x2000]
endif
endmethod
// !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
// Register command:
static if wanttoregister then
private static TableArray regist
method registerRepChangeEvent takes code c, integer rankchange, boolean upside returns nothing
if upside then
if regist[this].trigger[rankchange*2-1] == null then
set regist[this].trigger[rankchange*2-1] = CreateTrigger()
endif
call TriggerAddCondition(regist[this].trigger[rankchange*2-1], Condition(c))
else
if regist[this].trigger[rankchange*2] == null then
set regist[this].trigger[rankchange*2] = CreateTrigger()
endif
call TriggerAddCondition(regist[this].trigger[rankchange*2], Condition(c))
endif
endmethod
endif
endstruct
endlibrary
library URepSystemFunctionAPI requires ReputationForUnit //by edo494
/*
Im not going to say what each function does, if you want to know, please reffer to their counterparts in struct
API:
function(arguments) -> return type(if any)...................................what the function does
CreateUnitReputation(string name, unit toregister) -> URep return URep.create(name)
CreateUnitReputationEx(string name, integer startingrep, unit toregister) -> URep return URep.createEx(name, startingrep)
RemoveUnitReputation(URep rep) call rep.remove()
SetUnitReputationRank(integer rank, string name, integer xpto) call URep.setRank(rank, name, xpto)
IncreaseUnitReputation(URep rep, integer value) call rep.increase(value)
LowerUnitReputation(URep rep, integer value) call rep.decrease(value, forplayer)
GetUnitReputationName(URep rep) -> string return rep.getName()
UnitReputationS2I(string s) -> integer return URep.repS2I(s)
GetCurrentUnitReputation(URep rep) -> integer return rep.getRep(playerindex)
GetUnitTotalRep(URep rep) -> integer return rep.getTotalRep()
URepTypeById(integer id) -> string return URep.getTypeById(id)
GetCurrentURepType(URep rep) -> string return rep.getRankTypeOfPlayer(playerindex)
GetCurrentRankOfUnit(URep rep) -> integer return rep.getRankOfPlayer(playerindex)
UnitOfRep(Urep rep) -> unit return rep.getUnit()
UnitIdOfRep(Urep rep) -> integer return rep.getUnitId()
Trigger API, only works with global called wanttoregister == true
RegisterURepChangeEvent(URep rep, code c, integer rank, boolean good) call urep.registerRepChangeEvent(c, rank, flag)
*/
// Function API:
function CreateUnitReputation takes string name, unit u returns Reputation
return URep.create(name, u)
endfunction
function CreateUnitReputationEx takes string name, integer startingrep, unit u returns Reputation
return URep.createEx(name, startingrep, u)
endfunction
function RemoveUnitReputation takes URep rep returns nothing
call rep.remove()
endfunction
function SetUnitReputationRank takes integer rank, string name, integer xpto returns nothing
call URep.setRank(rank, name, xpto)
endfunction
function IncreaseUnitReputation takes URep rep, integer value returns nothing
call rep.increase(value)
endfunction
function LowerUnitReputation takes URep rep, integer value returns nothing
call rep.decrease(value)
endfunction
function GetUnitReputationName takes URep rep returns string
return rep.getName()
endfunction
function UnitReputationS2I takes string s returns integer
return URep.repS2I(s)
endfunction
function GetCurrentUnitReputation takes URep rep returns integer
return rep.getRep()
endfunction
function URepTypeById takes integer id returns string
return URep.getTypeById(id)
endfunction
function GetCurrentURepType takes URep rep returns string
return rep.getRankType()
endfunction
function GetCurrentRankOfUnit takes URep rep returns integer
return rep.getRank()
endfunction
static if wanttoregister then
function RegisterURepChangeEvent takes URep rep, code c, integer rank, boolean flag returns nothing
call rep.registerRepChangeEvent(c, rank, flag)
endfunction
endif
function UnitOfRep takes URep rep returns unit
return rep.getUnit()
endfunction
function UnitIdOfRep takes URep rep returns integer
return rep.getUnitId()
endfunction
function GetUnitTotalRep takes URep rep returns integer
return rep.getTotalRep()
endfunction
endlibrary
//TESH.scrollpos=0
//TESH.alwaysfold=0
library Table /* made by Bribe, special thanks to Vexorian & Nestharus, version 3.1.0.1
One map, one hashtable. Welcome to NewTable 3.1
This library was originally called NewTable so it didn't conflict with
the API of Table by Vexorian. However, the damage is done and it's too
late to change the library name now. To help with damage control, I
have provided an extension library called TableBC, which bridges all
the functionality of Vexorian's Table except for 2-D string arrays &
the ".flush(integer)" method. I use ".flush()" to flush a child hash-
table, because I wanted the API in NewTable to reflect the API of real
hashtables (I thought this would be more intuitive).
API
------------
struct Table
| static method create takes nothing returns Table
| create a new Table
|
| method destroy takes nothing returns nothing
| destroy it
|
| method flush takes nothing returns nothing
| flush all stored values inside of it
|
| method remove takes integer key returns nothing
| remove the value at index "key"
|
| method operator []= takes integer key, $TYPE$ value returns nothing
| assign "value" to index "key"
|
| method operator [] takes integer key returns $TYPE$
| load the value at index "key"
|
| method has takes integer key returns boolean
| whether or not the key was assigned
|
----------------
struct TableArray
| static method operator [] takes integer array_size returns TableArray
| create a new array of Tables of size "array_size"
|
| method destroy takes nothing returns nothing
| destroy it
|
| method flush takes nothing returns nothing
| flush and destroy it
|
| method operator size takes nothing returns integer
| returns the size of the TableArray
|
| method operator [] takes integer key returns Table
| returns a Table accessible exclusively to index "key"
*/
globals
private integer less = 0 //Index generation for TableArrays (below 0).
private integer more = 8190 //Index generation for Tables.
//Configure it if you use more than 8190 "key" variables in your map (this will never happen though).
private hashtable ht = InitHashtable()
private key sizeK
private key listK
endglobals
private struct dex extends array
static method operator size takes nothing returns Table
return sizeK
endmethod
static method operator list takes nothing returns Table
return listK
endmethod
endstruct
private struct handles extends array
method has takes integer key returns boolean
return HaveSavedHandle(ht, this, key)
endmethod
method remove takes integer key returns nothing
call RemoveSavedHandle(ht, this, key)
endmethod
endstruct
private struct agents extends array
method operator []= takes integer key, agent value returns nothing
call SaveAgentHandle(ht, this, key, value)
endmethod
endstruct
//! textmacro NEW_ARRAY_BASIC takes SUPER, FUNC, TYPE
private struct $TYPE$s extends array
method operator [] takes integer key returns $TYPE$
return Load$FUNC$(ht, this, key)
endmethod
method operator []= takes integer key, $TYPE$ value returns nothing
call Save$FUNC$(ht, this, key, value)
endmethod
method has takes integer key returns boolean
return HaveSaved$SUPER$(ht, this, key)
endmethod
method remove takes integer key returns nothing
call RemoveSaved$SUPER$(ht, this, key)
endmethod
endstruct
private module $TYPE$m
method operator $TYPE$ takes nothing returns $TYPE$s
return this
endmethod
endmodule
//! endtextmacro
//! textmacro NEW_ARRAY takes FUNC, TYPE
private struct $TYPE$s extends array
method operator [] takes integer key returns $TYPE$
return Load$FUNC$Handle(ht, this, key)
endmethod
method operator []= takes integer key, $TYPE$ value returns nothing
call Save$FUNC$Handle(ht, this, key, value)
endmethod
endstruct
private module $TYPE$m
method operator $TYPE$ takes nothing returns $TYPE$s
return this
endmethod
endmodule
//! endtextmacro
//Run these textmacros to include the entire hashtable API as wrappers.
//Don't be intimidated by the number of macros - Vexorian's map optimizer is
//supposed to kill functions which inline (all of these functions inline).
//! runtextmacro NEW_ARRAY_BASIC("Real", "Real", "real")
//! runtextmacro NEW_ARRAY_BASIC("Boolean", "Boolean", "boolean")
//! runtextmacro NEW_ARRAY_BASIC("String", "Str", "string")
//! runtextmacro NEW_ARRAY("Player", "player")
//! runtextmacro NEW_ARRAY("Widget", "widget")
//! runtextmacro NEW_ARRAY("Destructable", "destructable")
//! runtextmacro NEW_ARRAY("Item", "item")
//! runtextmacro NEW_ARRAY("Unit", "unit")
//! runtextmacro NEW_ARRAY("Ability", "ability")
//! runtextmacro NEW_ARRAY("Timer", "timer")
//! runtextmacro NEW_ARRAY("Trigger", "trigger")
//! runtextmacro NEW_ARRAY("TriggerCondition", "triggercondition")
//! runtextmacro NEW_ARRAY("TriggerAction", "triggeraction")
//! runtextmacro NEW_ARRAY("TriggerEvent", "event")
//! runtextmacro NEW_ARRAY("Force", "force")
//! runtextmacro NEW_ARRAY("Group", "group")
//! runtextmacro NEW_ARRAY("Location", "location")
//! runtextmacro NEW_ARRAY("Rect", "rect")
//! runtextmacro NEW_ARRAY("BooleanExpr", "boolexpr")
//! runtextmacro NEW_ARRAY("Sound", "sound")
//! runtextmacro NEW_ARRAY("Effect", "effect")
//! runtextmacro NEW_ARRAY("UnitPool", "unitpool")
//! runtextmacro NEW_ARRAY("ItemPool", "itempool")
//! runtextmacro NEW_ARRAY("Quest", "quest")
//! runtextmacro NEW_ARRAY("QuestItem", "questitem")
//! runtextmacro NEW_ARRAY("DefeatCondition", "defeatcondition")
//! runtextmacro NEW_ARRAY("TimerDialog", "timerdialog")
//! runtextmacro NEW_ARRAY("Leaderboard", "leaderboard")
//! runtextmacro NEW_ARRAY("Multiboard", "multiboard")
//! runtextmacro NEW_ARRAY("MultiboardItem", "multiboarditem")
//! runtextmacro NEW_ARRAY("Trackable", "trackable")
//! runtextmacro NEW_ARRAY("Dialog", "dialog")
//! runtextmacro NEW_ARRAY("Button", "button")
//! runtextmacro NEW_ARRAY("TextTag", "texttag")
//! runtextmacro NEW_ARRAY("Lightning", "lightning")
//! runtextmacro NEW_ARRAY("Image", "image")
//! runtextmacro NEW_ARRAY("Ubersplat", "ubersplat")
//! runtextmacro NEW_ARRAY("Region", "region")
//! runtextmacro NEW_ARRAY("FogState", "fogstate")
//! runtextmacro NEW_ARRAY("FogModifier", "fogmodifier")
//! runtextmacro NEW_ARRAY("Hashtable", "hashtable")
struct Table extends array
// Implement modules for intuitive syntax (tb.handle; tb.unit; etc.)
implement realm
implement 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)
endmethod
//set tb[389034] = 8192
method operator []= takes integer key, Table tb returns nothing
call SaveInteger(ht, this, key, tb)
endmethod
//set b = tb.has(2493223)
method has takes integer key returns boolean
return HaveSavedInteger(ht, this, key)
endmethod
//call tb.remove(294080)
method remove takes integer key returns nothing
call RemoveSavedInteger(ht, this, 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
//TESH.scrollpos=23
//TESH.alwaysfold=0
library UnitIndexer /* v4.0.2.7
*************************************************************************************
*
* Assigns unique indexes to units via unit user data.
*
*************************************************************************************
*
* */uses/*
*
* */ WorldBounds /* hiveworkshop.com/forums/jass-functions-413/snippet-worldbounds-180494/
* */ Event /* hiveworkshop.com/forums/submissions-414/snippet-event-186555/
*
************************************************************************************
*
* SETTINGS
*/
globals
constant integer ABILITIES_UNIT_INDEXER = 'A000'
endglobals
/*
************************************************************************************
*
* Functions
*
* function RegisterUnitIndexEvent takes boolexpr codeToRegister, Event unitIndexEvent returns nothing
* function TriggerRegisterUnitIndexEvent takes trigger triggerToRegister, Event unitIndexEvent returns nothing
*
* function GetUnitById takes integer index returns unit
* - Returns unit given a unit index
* function GetUnitId takes unit u returns integer
* - Returns unit index given a unit
*
* function IsUnitIndexed takes unit u returns boolean
* function IsUnitDeindexing takes unit u returns boolean
*
* function GetIndexedUnitId takes nothing returns integer
* function GetIndexedUnit takes nothing returns unit
*
************************************************************************************
*
* module UnitIndexStructMethods
* static method operator [] takes unit u returns thistype
* - Return GetUnitUserData(u)
*
* readonly unit unit
* - The indexed unit of the struct
*
************************************************************************************
*
* module UnitIndexStruct extends UnitIndexStructMethods
*
* - A pseudo module interface that runs a set of methods if they exist and provides
* - a few fields and operators. Runs on static ifs to minimize code.
*
* readonly boolean allocated
* - Is unit allocated for the struct
*
* Interface:
*
* - These methods don't have to exist. If they don't exist, the code
* - that calls them won't even be in the module.
*
* private method index takes nothing returns nothing
* - called when a unit is indexed and passes the filter.
* -
* - thistype this: Unit's index
* private method deindex takes nothing returns nothing
* - called when a unit is deindexed and is allocated for struct
* -
* - thistype this: Unit's index
* private static method filter takes unit unitToIndex returns boolean
* - Determines whether or not to allocate struct for unit
* -
* - unit unitToIndex: Unit being filtered
*
************************************************************************************
*
* struct UnitIndexer extends array
*
* - Controls the unit indexer system.
*
* static constant Event UnitIndexer.INDEX
* static constant Event UnitIndexer.DEINDEX
* - Don't register functions and triggers directly to the events. Register them via
* - RegisterUnitIndexEvent and TriggerRegisterUnitIndexEvent.
*
* static boolean enabled
* - Enables and disables unit indexing. Useful for filtering out dummy units.
*
************************************************************************************
*
* struct UnitIndex extends UnitIndexStructMethods
*
* - Constrols specific unit indexes.
*
* method lock takes nothing returns nothing
* - Locks an index. When an index is locked, it will not be recycled
* - when the unit is deindexed until all locks are removed. Deindex
* - events still fire at the appropriate times, the index just doesn't
* - get thrown into the recycler.
* method unlock takes nothing returns nothing
* - Unlocks an index.
*
************************************************************************************/
globals
private trigger q=CreateTrigger()
private trigger l=CreateTrigger()
private unit array e
private integer r=0
private integer y=0
private integer o=0
private boolean a=false
private integer array n
private integer array p
private integer array lc
endglobals
function GetIndexedUnitId takes nothing returns integer
return o
endfunction
function GetIndexedUnit takes nothing returns unit
return e[o]
endfunction
//! runtextmacro optional UNIT_LIST_LIB()
private struct PreLoader extends array
public static method run takes nothing returns nothing
call DestroyTimer(GetExpiredTimer())
set a=true
endmethod
public static method eval takes trigger t returns nothing
local integer f=n[0]
local integer d=o
loop
exitwhen 0==f
if (IsTriggerEnabled(t)) then
set o=f
if (TriggerEvaluate(t)) then
call TriggerExecute(t)
endif
else
exitwhen true
endif
set f=n[f]
endloop
set o=d
endmethod
public static method evalb takes boolexpr c returns nothing
local trigger t=CreateTrigger()
local thistype f=n[0]
local integer d=o
call TriggerAddCondition(t,c)
loop
exitwhen 0==f
set o=f
call TriggerEvaluate(t)
set f=n[f]
endloop
call DestroyTrigger(t)
set t=null
set o=d
endmethod
endstruct
//! runtextmacro optional UNIT_EVENT_MACRO()
private module UnitIndexerInit
private static method onInit takes nothing returns nothing
local integer i=15
local boolexpr bc=Condition(function thistype.onLeave)
local boolexpr bc2=Condition(function thistype.onEnter)
local group g=CreateGroup()
local player p
set INDEX=CreateEvent()
set DEINDEX=CreateEvent()
call TriggerRegisterEnterRegion(q,WorldBounds.worldRegion,bc2)
loop
set p=Player(i)
call TriggerRegisterPlayerUnitEvent(l,p,EVENT_PLAYER_UNIT_ISSUED_ORDER,bc)
call SetPlayerAbilityAvailable(p,ABILITIES_UNIT_INDEXER,false)
call GroupEnumUnitsOfPlayer(g,p,bc2)
exitwhen 0==i
set i=i-1
endloop
call DestroyGroup(g)
set bc=null
set g=null
set bc2=null
set p=null
call TimerStart(CreateTimer(),0,false,function PreLoader.run)
endmethod
endmodule
struct UnitIndex extends array
method lock takes nothing returns nothing
debug if (null!=e[this]) then
set lc[this]=lc[this]+1
debug else
debug call DisplayTimedTextToPlayer(GetLocalPlayer(),0,0,60,"UNIT INDEXER ERROR: ATTEMPT TO LOCK NULL INDEX")
debug endif
endmethod
method unlock takes nothing returns nothing
debug if (0<lc[this]) then
set lc[this]=lc[this]-1
if (0==lc[this] and null==e[this]) then
set n[this]=y
set y=this
endif
debug else
debug call DisplayTimedTextToPlayer(GetLocalPlayer(),0,0,60,"UNIT INDEXER ERROR: ATTEMPT TO UNLOCK UNLOCKED INDEX")
debug endif
endmethod
method operator unit takes nothing returns unit
return e[this]
endmethod
static method operator [] takes unit whichUnit returns thistype
return GetUnitUserData(whichUnit)
endmethod
endstruct
struct UnitIndexer extends array
readonly static Event INDEX
readonly static Event DEINDEX
static boolean enabled=true
private static method onEnter takes nothing returns boolean
local unit Q=GetFilterUnit()
local integer i
local integer d=o
if (enabled and Q!=e[GetUnitUserData(Q)] and 0==GetUnitUserData(Q)) then
if (0==y) then
set r=r+1
set i=r
else
set i=y
set y=n[y]
endif
call UnitAddAbility(Q,ABILITIES_UNIT_INDEXER)
call UnitMakeAbilityPermanent(Q,true,ABILITIES_UNIT_INDEXER)
call SetUnitUserData(Q,i)
set e[i]=Q
static if not LIBRARY_UnitList then
if (not a)then
set p[i]=p[0]
set n[p[0]]=i
set n[i]=0
set p[0]=i
endif
else
set p[i]=p[0]
set n[p[0]]=i
set n[i]=0
set p[0]=i
call GroupAddUnit(g,e[i])
endif
set o=i
call FireEvent(INDEX)
set o=d
endif
set Q=null
return false
endmethod
private static method onLeave takes nothing returns boolean
static if LIBRARY_UnitEvent then
implement optional UnitEventModule
else
local unit u=GetFilterUnit()
local integer i=GetUnitUserData(u)
local integer d=o
if (0==GetUnitAbilityLevel(u,ABILITIES_UNIT_INDEXER) and u==e[i]) then
static if not LIBRARY_UnitList then
if (not a)then
set n[p[i]]=n[i]
set p[n[i]]=p[i]
endif
else
set n[p[i]]=n[i]
set p[n[i]]=p[i]
call GroupRemoveUnit(g,e[i])
endif
set o=i
call FireEvent(DEINDEX)
set o=d
if (0==lc[i]) then
set n[i]=y
set y=i
endif
set e[i]=null
endif
set u=null
endif
return false
endmethod
implement UnitIndexerInit
endstruct
//! runtextmacro optional UNIT_EVENT_MACRO_2()
function RegisterUnitIndexEvent takes boolexpr c,integer ev returns nothing
call RegisterEvent(c, ev)
if (not a and ev==UnitIndexer.INDEX and 0!=n[0]) then
call PreLoader.evalb(c)
endif
endfunction
function TriggerRegisterUnitIndexEvent takes trigger t,integer ev returns nothing
call TriggerRegisterEvent(t,ev)
if (not a and ev == UnitIndexer.INDEX and 0!=n[0]) then
call PreLoader.eval(t)
endif
endfunction
function GetUnitById takes integer W returns unit
return e[W]
endfunction
function GetUnitId takes unit u returns integer
return GetUnitUserData(u)
endfunction
function IsUnitIndexed takes unit u returns boolean
return u==e[GetUnitUserData(u)]
endfunction
function IsUnitDeindexing takes unit u returns boolean
return IsUnitIndexed(u) and 0==GetUnitAbilityLevel(u,ABILITIES_UNIT_INDEXER)
endfunction
module UnitIndexStructMethods
static method operator [] takes unit u returns thistype
return GetUnitUserData(u)
endmethod
method operator unit takes nothing returns unit
return e[this]
endmethod
endmodule
module UnitIndexStruct
implement UnitIndexStructMethods
static if thistype.filter.exists then
static if thistype.index.exists then
static if thistype.deindex.exists then
readonly boolean allocated
else
method operator allocated takes nothing returns boolean
return filter(e[this])
endmethod
endif
else
method operator allocated takes nothing returns boolean
return filter(e[this])
endmethod
endif
elseif (thistype.index.exists) then
static if thistype.deindex.exists then
readonly boolean allocated
else
method operator allocated takes nothing returns boolean
return this==GetUnitUserData(e[this])
endmethod
endif
else
method operator allocated takes nothing returns boolean
return this==GetUnitUserData(e[this])
endmethod
endif
static if thistype.index.exists then
private static method onIndexEvent takes nothing returns boolean
static if thistype.filter.exists then
if (filter(e[o])) then
static if thistype.deindex.exists then
set thistype(o).allocated=true
endif
call thistype(o).index()
endif
else
static if thistype.deindex.exists then
set thistype(o).allocated=true
endif
call thistype(o).index()
endif
return false
endmethod
endif
static if thistype.deindex.exists then
private static method onDeindexEvent takes nothing returns boolean
static if thistype.filter.exists then
static if thistype.index.exists then
if (thistype(o).allocated) then
set thistype(o).allocated=false
call thistype(o).deindex()
endif
else
if (filter(e[o])) then
call thistype(o).deindex()
endif
endif
else
static if thistype.index.exists then
set thistype(o).allocated=false
endif
call thistype(o).deindex()
endif
return false
endmethod
endif
static if thistype.index.exists then
static if thistype.deindex.exists then
private static method onInit takes nothing returns nothing
call RegisterUnitIndexEvent(Condition(function thistype.onIndexEvent),UnitIndexer.INDEX)
call RegisterUnitIndexEvent(Condition(function thistype.onDeindexEvent),UnitIndexer.DEINDEX)
endmethod
else
private static method onInit takes nothing returns nothing
call RegisterUnitIndexEvent(Condition(function thistype.onIndexEvent),UnitIndexer.INDEX)
endmethod
endif
elseif thistype.deindex.exists then
private static method onInit takes nothing returns nothing
call RegisterUnitIndexEvent(Condition(function thistype.onDeindexEvent),UnitIndexer.DEINDEX)
endmethod
endif
endmodule
endlibrary
//TESH.scrollpos=24
//TESH.alwaysfold=0
library Event
//2.0.0.1
/////////////////////////////////////////////////////////////////////////
//function CreateEvent takes nothing returns integer
//function TriggerRegisterEvent takes trigger t, integer ev returns nothing
//function RegisterEvent takes boolexpr c, integer ev returns nothing
//function FireEvent takes integer ev returns nothing
//struct Event extends array
//static method create takes nothing returns thistype
//method registerTrigger takes trigger t returns nothing
//method register takes boolexpr c returns nothing
//method fire takes nothing returns nothing
/////////////////////////////////////////////////////////////////////////
globals
private real q=0
endglobals
struct Event extends array
private static integer w=0
private static trigger array e
static method create takes nothing returns thistype
set w=w+1
set e[w]=CreateTrigger()
return w
endmethod
method registerTrigger takes trigger t returns nothing
call TriggerRegisterVariableEvent(t,SCOPE_PRIVATE+"q",EQUAL,this)
endmethod
method register takes boolexpr c returns nothing
call TriggerAddCondition(e[this],c)
endmethod
method fire takes nothing returns nothing
set q=0
set q=this
call TriggerEvaluate(e[this])
endmethod
endstruct
function CreateEvent takes nothing returns Event
return Event.create()
endfunction
function TriggerRegisterEvent takes trigger t,Event ev returns nothing
call ev.registerTrigger(t)
endfunction
function RegisterEvent takes boolexpr c,Event ev returns nothing
call ev.register(c)
endfunction
function FireEvent takes Event ev returns nothing
call ev.fire()
endfunction
endlibrary
//TESH.scrollpos=15
//TESH.alwaysfold=0
library WorldBounds
//struct WorldBounds extends array
//static readonly rect world
// same as GetWorldBounds()
//static readonly region worldRegion
// contains world for triggers
//static readonly real maxX
//static readonly real maxY
//static readonly real minX
//static readonly real minY
//static readonly real centerX
//static readonly real centerY
private module WorldBoundInit
private static method onInit takes nothing returns nothing
set world=GetWorldBounds()
set maxX=GetRectMaxX(world)
set maxY=GetRectMaxY(world)
set minX=GetRectMinX(world)
set minY=GetRectMinY(world)
set centerX=(maxX+minX)/2
set centerY=(minY+maxY)/2
set worldRegion=CreateRegion()
call RegionAddRect(worldRegion,world)
endmethod
endmodule
struct WorldBounds extends array
readonly static real maxX
readonly static real maxY
readonly static real minX
readonly static real minY
readonly static real centerX
readonly static real centerY
readonly static rect world
readonly static region worldRegion
implement WorldBoundInit
endstruct
endlibrary