Name | Type | is_array | initial_value |
i | integer | No | |
IsUnitPreplaced | boolean | Yes | |
nFirstName | string | No | |
nFirstNames | string | Yes | |
nLastName | string | No | |
nLastNames | string | Yes | |
nUnit | unit | No | |
nUnitName | string | No | |
nUnitTypes | unitcode | Yes | |
UDex | integer | No | |
UDexGen | integer | No | |
UDexNext | integer | Yes | |
UDexPrev | integer | Yes | |
UDexRecycle | integer | No | |
UDexUnits | unit | Yes | |
UDexWasted | integer | No | |
UnitIndexerEnabled | boolean | No | |
UnitIndexEvent | real | No |
library Table /* made by Bribe, special thanks to Vexorian & Nestharus, version 4.1.0.1.
One map, one hashtable. Welcome to NewTable 4.1.0.1
This newest iteration of Table introduces the new HashTable struct.
You can now instantiate HashTables which enables the use of large
parent and large child keys, just like a standard hashtable. Previously,
the user would have to instantiate a Table to do this on their own which -
while doable - is something the user should not have to do if I can add it
to this resource myself (especially if they are inexperienced).
This library was originally called NewTable so it didn't conflict with
the API of Table by Vexorian. However, the damage is done and it's too
late to change the library name now. To help with damage control, I
have provided an extension library called TableBC, which bridges all
the functionality of Vexorian's Table except for 2-D string arrays &
the ".flush(integer)" method. I use ".flush()" to flush a child hash-
table, because I wanted the API in NewTable to reflect the API of real
hashtables (I thought this would be more intuitive).
API
------------
struct Table
| static method create takes nothing returns Table
| create a new Table
|
| method destroy takes nothing returns nothing
| destroy it
|
| method flush takes nothing returns nothing
| flush all stored values inside of it
|
| method remove takes integer key returns nothing
| remove the value at index "key"
|
| method operator []= takes integer key, $TYPE$ value returns nothing
| assign "value" to index "key"
|
| method operator [] takes integer key returns $TYPE$
| load the value at index "key"
|
| method has takes integer key returns boolean
| whether or not the key was assigned
|
----------------
struct TableArray
| static method operator [] takes integer array_size returns TableArray
| create a new array of Tables of size "array_size"
|
| method destroy takes nothing returns nothing
| destroy it
|
| method flush takes nothing returns nothing
| flush and destroy it
|
| method operator size takes nothing returns integer
| returns the size of the TableArray
|
| method operator [] takes integer key returns Table
| returns a Table accessible exclusively to index "key"
*/
globals
private integer less = 0 //Index generation for TableArrays (below 0).
private integer more = 8190 //Index generation for Tables.
//Configure it if you use more than 8190 "key" variables in your map (this will never happen though).
private hashtable ht = InitHashtable()
private key sizeK
private key listK
endglobals
private struct dex extends array
static method operator size takes nothing returns Table
return sizeK
endmethod
static method operator list takes nothing returns Table
return listK
endmethod
endstruct
private struct handles extends array
method has takes integer key returns boolean
return HaveSavedHandle(ht, this, key)
endmethod
method remove takes integer key returns nothing
call RemoveSavedHandle(ht, this, key)
endmethod
endstruct
private struct agents extends array
method operator []= takes integer key, agent value returns nothing
call SaveAgentHandle(ht, this, key, value)
endmethod
endstruct
//! textmacro NEW_ARRAY_BASIC takes SUPER, FUNC, TYPE
private struct $TYPE$s extends array
method operator [] takes integer key returns $TYPE$
return Load$FUNC$(ht, this, key)
endmethod
method operator []= takes integer key, $TYPE$ value returns nothing
call Save$FUNC$(ht, this, key, value)
endmethod
method has takes integer key returns boolean
return HaveSaved$SUPER$(ht, this, key)
endmethod
method remove takes integer key returns nothing
call RemoveSaved$SUPER$(ht, this, key)
endmethod
endstruct
private module $TYPE$m
method operator $TYPE$ takes nothing returns $TYPE$s
return this
endmethod
endmodule
//! endtextmacro
//! textmacro NEW_ARRAY takes FUNC, TYPE
private struct $TYPE$s extends array
method operator [] takes integer key returns $TYPE$
return Load$FUNC$Handle(ht, this, key)
endmethod
method operator []= takes integer key, $TYPE$ value returns nothing
call Save$FUNC$Handle(ht, this, key, value)
endmethod
method has takes integer key returns boolean
return HaveSavedHandle(ht, this, key)
endmethod
method remove takes integer key returns nothing
call RemoveSavedHandle(ht, this, key)
endmethod
endstruct
private module $TYPE$m
method operator $TYPE$ takes nothing returns $TYPE$s
return this
endmethod
endmodule
//! endtextmacro
//Run these textmacros to include the entire hashtable API as wrappers.
//Don't be intimidated by the number of macros - Vexorian's map optimizer is
//supposed to kill functions which inline (all of these functions inline).
//! runtextmacro NEW_ARRAY_BASIC("Real", "Real", "real")
//! runtextmacro NEW_ARRAY_BASIC("Boolean", "Boolean", "boolean")
//! runtextmacro NEW_ARRAY_BASIC("String", "Str", "string")
//New textmacro to allow table.integer[] syntax for compatibility with textmacros that might desire it.
//! runtextmacro NEW_ARRAY_BASIC("Integer", "Integer", "integer")
//! runtextmacro NEW_ARRAY("Player", "player")
//! runtextmacro NEW_ARRAY("Widget", "widget")
//! runtextmacro NEW_ARRAY("Destructable", "destructable")
//! runtextmacro NEW_ARRAY("Item", "item")
//! runtextmacro NEW_ARRAY("Unit", "unit")
//! runtextmacro NEW_ARRAY("Ability", "ability")
//! runtextmacro NEW_ARRAY("Timer", "timer")
//! runtextmacro NEW_ARRAY("Trigger", "trigger")
//! runtextmacro NEW_ARRAY("TriggerCondition", "triggercondition")
//! runtextmacro NEW_ARRAY("TriggerAction", "triggeraction")
//! runtextmacro NEW_ARRAY("TriggerEvent", "event")
//! runtextmacro NEW_ARRAY("Force", "force")
//! runtextmacro NEW_ARRAY("Group", "group")
//! runtextmacro NEW_ARRAY("Location", "location")
//! runtextmacro NEW_ARRAY("Rect", "rect")
//! runtextmacro NEW_ARRAY("BooleanExpr", "boolexpr")
//! runtextmacro NEW_ARRAY("Sound", "sound")
//! runtextmacro NEW_ARRAY("Effect", "effect")
//! runtextmacro NEW_ARRAY("UnitPool", "unitpool")
//! runtextmacro NEW_ARRAY("ItemPool", "itempool")
//! runtextmacro NEW_ARRAY("Quest", "quest")
//! runtextmacro NEW_ARRAY("QuestItem", "questitem")
//! runtextmacro NEW_ARRAY("DefeatCondition", "defeatcondition")
//! runtextmacro NEW_ARRAY("TimerDialog", "timerdialog")
//! runtextmacro NEW_ARRAY("Leaderboard", "leaderboard")
//! runtextmacro NEW_ARRAY("Multiboard", "multiboard")
//! runtextmacro NEW_ARRAY("MultiboardItem", "multiboarditem")
//! runtextmacro NEW_ARRAY("Trackable", "trackable")
//! runtextmacro NEW_ARRAY("Dialog", "dialog")
//! runtextmacro NEW_ARRAY("Button", "button")
//! runtextmacro NEW_ARRAY("TextTag", "texttag")
//! runtextmacro NEW_ARRAY("Lightning", "lightning")
//! runtextmacro NEW_ARRAY("Image", "image")
//! runtextmacro NEW_ARRAY("Ubersplat", "ubersplat")
//! runtextmacro NEW_ARRAY("Region", "region")
//! runtextmacro NEW_ARRAY("FogState", "fogstate")
//! runtextmacro NEW_ARRAY("FogModifier", "fogmodifier")
//! runtextmacro NEW_ARRAY("Hashtable", "hashtable")
struct Table extends array
// Implement modules for intuitive syntax (tb.handle; tb.unit; etc.)
implement realm
implement integerm
implement booleanm
implement stringm
implement playerm
implement widgetm
implement destructablem
implement itemm
implement unitm
implement abilitym
implement timerm
implement triggerm
implement triggerconditionm
implement triggeractionm
implement eventm
implement forcem
implement groupm
implement locationm
implement rectm
implement boolexprm
implement soundm
implement effectm
implement unitpoolm
implement itempoolm
implement questm
implement questitemm
implement defeatconditionm
implement timerdialogm
implement leaderboardm
implement multiboardm
implement multiboarditemm
implement trackablem
implement dialogm
implement buttonm
implement texttagm
implement lightningm
implement imagem
implement ubersplatm
implement regionm
implement fogstatem
implement fogmodifierm
implement hashtablem
method operator handle takes nothing returns handles
return this
endmethod
method operator agent takes nothing returns agents
return this
endmethod
//set this = tb[GetSpellAbilityId()]
method operator [] takes integer key returns Table
return LoadInteger(ht, this, key) //return this.integer[key]
endmethod
//set tb[389034] = 8192
method operator []= takes integer key, Table tb returns nothing
call SaveInteger(ht, this, key, tb) //set this.integer[key] = tb
endmethod
//set b = tb.has(2493223)
method has takes integer key returns boolean
return HaveSavedInteger(ht, this, key) //return this.integer.has(key)
endmethod
//call tb.remove(294080)
method remove takes integer key returns nothing
call RemoveSavedInteger(ht, this, key) //call this.integer.remove(key)
endmethod
//Remove all data from a Table instance
method flush takes nothing returns nothing
call FlushChildHashtable(ht, this)
endmethod
//local Table tb = Table.create()
static method create takes nothing returns Table
local Table this = dex.list[0]
if this == 0 then
set this = more + 1
set more = this
else
set dex.list[0] = dex.list[this]
call dex.list.remove(this) //Clear hashed memory
endif
debug set dex.list[this] = -1
return this
endmethod
// Removes all data from a Table instance and recycles its index.
//
// call tb.destroy()
//
method destroy takes nothing returns nothing
debug if dex.list[this] != -1 then
debug call BJDebugMsg("Table Error: Tried to double-free instance: " + I2S(this))
debug return
debug endif
call this.flush()
set dex.list[this] = dex.list[0]
set dex.list[0] = this
endmethod
//! runtextmacro optional TABLE_BC_METHODS()
endstruct
//! runtextmacro optional TABLE_BC_STRUCTS()
struct TableArray extends array
//Returns a new TableArray to do your bidding. Simply use:
//
// local TableArray ta = TableArray[array_size]
//
static method operator [] takes integer array_size returns TableArray
local Table tb = dex.size[array_size] //Get the unique recycle list for this array size
local TableArray this = tb[0] //The last-destroyed TableArray that had this array size
debug if array_size <= 0 then
debug call BJDebugMsg("TypeError: Invalid specified TableArray size: " + I2S(array_size))
debug return 0
debug endif
if this == 0 then
set this = less - array_size
set less = this
else
set tb[0] = tb[this] //Set the last destroyed to the last-last destroyed
call tb.remove(this) //Clear hashed memory
endif
set dex.size[this] = array_size //This remembers the array size
return this
endmethod
//Returns the size of the TableArray
method operator size takes nothing returns integer
return dex.size[this]
endmethod
//This magic method enables two-dimensional[array][syntax] for Tables,
//similar to the two-dimensional utility provided by hashtables them-
//selves.
//
//ta[integer a].unit[integer b] = unit u
//ta[integer a][integer c] = integer d
//
//Inline-friendly when not running in debug mode
//
method operator [] takes integer key returns Table
static if DEBUG_MODE then
local integer i = this.size
if i == 0 then
call BJDebugMsg("IndexError: Tried to get key from invalid TableArray instance: " + I2S(this))
return 0
elseif key < 0 or key >= i then
call BJDebugMsg("IndexError: Tried to get key [" + I2S(key) + "] from outside TableArray bounds: " + I2S(i))
return 0
endif
endif
return this + key
endmethod
//Destroys a TableArray without flushing it; I assume you call .flush()
//if you want it flushed too. This is a public method so that you don't
//have to loop through all TableArray indices to flush them if you don't
//need to (ie. if you were flushing all child-keys as you used them).
//
method destroy takes nothing returns nothing
local Table tb = dex.size[this.size]
debug if this.size == 0 then
debug call BJDebugMsg("TypeError: Tried to destroy an invalid TableArray: " + I2S(this))
debug return
debug endif
if tb == 0 then
//Create a Table to index recycled instances with their array size
set tb = Table.create()
set dex.size[this.size] = tb
endif
call dex.size.remove(this) //Clear the array size from hash memory
set tb[this] = tb[0]
set tb[0] = this
endmethod
private static Table tempTable
private static integer tempEnd
//Avoids hitting the op limit
private static method clean takes nothing returns nothing
local Table tb = .tempTable
local integer end = tb + 0x1000
if end < .tempEnd then
set .tempTable = end
call ForForce(bj_FORCE_PLAYER[0], function thistype.clean)
else
set end = .tempEnd
endif
loop
call tb.flush()
set tb = tb + 1
exitwhen tb == end
endloop
endmethod
//Flushes the TableArray and also destroys it. Doesn't get any more
//similar to the FlushParentHashtable native than this.
//
method flush takes nothing returns nothing
debug if this.size == 0 then
debug call BJDebugMsg("TypeError: Tried to flush an invalid TableArray instance: " + I2S(this))
debug return
debug endif
set .tempTable = this
set .tempEnd = this + this.size
call ForForce(bj_FORCE_PLAYER[0], function thistype.clean)
call this.destroy()
endmethod
endstruct
//NEW: Added in Table 4.0. A fairly simple struct but allows you to do more
//than that which was previously possible.
struct HashTable extends array
//Enables myHash[parentKey][childKey] syntax.
//Basically, it creates a Table in the place of the parent key if
//it didn't already get created earlier.
method operator [] takes integer index returns Table
local Table t = Table(this)[index]
if t == 0 then
set t = Table.create()
set Table(this)[index] = t //whoops! Forgot that line. I'm out of practice!
endif
return t
endmethod
//You need to call this on each parent key that you used if you
//intend to destroy the HashTable or simply no longer need that key.
method remove takes integer index returns nothing
local Table t = Table(this)[index]
if t != 0 then
call t.destroy()
call Table(this).remove(index)
endif
endmethod
//Added in version 4.1
method has takes integer index returns boolean
return Table(this).has(index)
endmethod
//HashTables are just fancy Table indices.
method destroy takes nothing returns nothing
call Table(this).destroy()
endmethod
//Like I said above...
static method create takes nothing returns thistype
return Table.create()
endmethod
endstruct
endlibrary
/*
Naming System v 1.1
by Pinzu
This library enables the creation of name pools that can be combined to give regular units
hero names, and a few other basic things.
Requirements:
Table by Bribe
https://hiveworkshop.com/threads/snippet-new-table.188084/
Configuraton
1) After copying the library to your map you can change public globals to your chosing.
2) To use it you have to create a setup trigger somewhere. See "UnitNamingOnEvent" for more.
API
function UnitHasNamePool takes unit u returns boolean
returns true if the unit exists in any TypeNamePool.
function ChangeUnitFullName takes unit u, string firstname, string lastname, string unitname returns nothing
Changes the units name to provided firstname, lastname and unitname.
function GetUnitNamePool takes unit u returns TypeNamePool
Returns the name pool that a certain unit belongs to. Useful if you want access to random names from there.
function SetUnitRandomNameSimple takes unit u returns boolean
Will assign a unit a random name if it belongs to any random unit name pool. Does not store any data about the unit names.
A simple struct containing only a list of strings. You can create it, destroy it, add names to it and draw a random name from it.
struct NamePool
static method create takes nothing returns thistype
method destroy takes nothing returns nothing
method add takes string name returns thistype
method getRandom takes nothing returns string
This struct contains 2 NamePools and a list of unit-types that the name pool belongs to.
struct TypeNamePool
static method create takes NamePool firstPool, NamePool lastPool returns thistype
Creates it. Requires 2 NamePool to draw first and last names from.
method destroy takes nothing returns nothing
Deallocates it.
method remove takes integer unitTypeId returns boolean
Removes a saved unit-type from the pool.
method add takes integer unitTypeId returns thistype
Adds a unit-type to the pool. Note a unit can only belong to one NamePool at a time.
method getRandomFirstName takes nothing returns string
Draws a random first name from the pool.
method getRandomLastName takes nothing returns string
Draws a random last name from the pool.
//
// Extended features provides additional API used to replace the regular natives for name management.
// Among other things allows to set units first and last name separately, and give units hero proper names. '
//
API
function SetUnitNormalName takes unit u, string normalname returns nothing
Basically the same as 'BlzSetUnitName' except that it keeps the proper name if any such is set
function GetUnitNormalName takes unit u returns string
Basically the same as 'GetUnitName', excludes the proper names if such exist
Note that it only works for units that have been configured by the system
function SetUnitProperName takes unit u, string firstname, string lastname returns nothing
Same as setting a heroes name, devided in first and last names
function GetUnitProperName takes unit u returns string
Returns the units proper name with both first and last name if such exist
function GetUnitFirstName takes unit u returns string
Returns the first name of the unit
function SetUnitFirstName takes unit u, string firstname returns nothing
Changes the units first name
function GetUnitLastName takes unit u returns string
Returns the last name of the unit
function SetUnitLastName takes unit u, string lastname returns nothing
Changes the units last name
function SetUnitRandomName takes unit u returns boolean
Gives a unit a random name based on the unit-type. WARNING: Will store data about the named unit which needs to be removed when the
unit is no longer used to prevent leaks.
Note that if the unit-type is not configured to any unit pool the unit wont be affected
function SaveDefaultName takes unit u returns nothing
This will save the equivalent of GetUnitName and BlzGetHeroProperName the first time its
used by the unit. Any times called after that will be ignored, the purpose is to be able
to reset the units name to the default name.
function DestroyUnitName takes unit u returns nothing
Used to deallocate unit names from units. Should be used on deindex
*/
library UnitNaming uses Table optional UnitDex, optional UnitIndexerGUI optional WorldBounds
/* Configurables */
globals
boolean keepNormalNames = true // Flag for if the unit-type name should be kept
boolean colorHeroes = true // Flag for if hero names should be colored
string color = "|cffffcc00" // The unit proper name color
// Used to include extended features, such as being able to change different names associated with a unit and retrieving it.
//
constant boolean INCLUDE_UNAME_EXTENDED = false
// This will save the default name of the unit when it is given a random name upon being indexed.
// Recommended setting for this is off, unless you have a special reason for using it.
// What it does is basically when you destroy allocated unit name it will reset to default.
//
private constant boolean SAVE_DEFAULT_NAME = false
endglobals
/* This is the implementation of the name design, you can switch things around here to whatever you prefer, if you know what you are doing. */
function ChangeUnitFullName takes unit u, string firstname, string lastname, string unitname returns nothing
if IsUnitType(u, UNIT_TYPE_HERO) then
if keepNormalNames then
call BlzSetUnitName(u, unitname)
else
call BlzSetUnitName(u, " ")
endif
if colorHeroes then
call BlzSetHeroProperName(u, color + firstname + " " + lastname + "|r")
else
call BlzSetHeroProperName(u, firstname + " " + lastname)
endif
else
if StringLength(firstname) > 0 or StringLength(lastname) > 0 then
if keepNormalNames then
call BlzSetUnitName(u, color + firstname + " " + lastname + "|r|n" + unitname)
else
call BlzSetUnitName(u, color + firstname + " " + lastname + "|r|n")
endif
else
call BlzSetUnitName(u, unitname)
endif
endif
endfunction
/* This is the simple method of giving a unit a random name, it will not store any data to the unit. */
function SetUnitRandomNameSimple takes unit u returns boolean
local TypeNamePool namepool = TypeNamePool.typesNameTable[GetUnitTypeId(u)]
if namepool != 0 then
call ChangeUnitFullName(u, namepool.getRandomFirstName(), namepool.getRandomLastName(), GetUnitName(u))
return true
endif
return false
endfunction
function GetUnitNamePool takes unit u returns TypeNamePool
return TypeNamePool.typesNameTable[GetUnitTypeId(u)]
endfunction
function UnitHasNamePool takes unit u returns boolean
return TypeNamePool.typesNameTable.has(GetUnitTypeId(u))
endfunction
struct TypeNamePool
private Table types
private integer size
private NamePool firstNamePool
private NamePool lastNamePool
static Table typesNameTable = 0
static method setup takes nothing returns nothing
if .typesNameTable == 0 then
set typesNameTable = Table.create()
endif
endmethod
method getRandomFirstName takes nothing returns string
return firstNamePool.getRandom()
endmethod
method getRandomLastName takes nothing returns string
return lastNamePool.getRandom()
endmethod
static method create takes NamePool firstPool, NamePool lastPool returns thistype
local thistype this = .allocate()
set this.types = Table.create()
set this.firstNamePool = firstPool
set this.lastNamePool = lastPool
set this.size = 0
return this
endmethod
private method indexOf takes integer unitTypeId returns integer
local integer i = 0
loop
exitwhen i == .size
if .types[i] == unitTypeId then
return i
endif
set i = i + 1
endloop
return -1
endmethod
method remove takes integer unitTypeId returns boolean
if thistype.typesNameTable[unitTypeId] == this then
call thistype.typesNameTable.remove(unitTypeId)
set .size = .size - 1
set .types[.indexOf(unitTypeId)] = .types[.size]
call .types.remove(.size)
return true
endif
debug call BJDebugMsg("[Library_UnitNaming] TypeNames.remove: Unit Type does not belong to this name pool.")
return false
endmethod
method add takes integer unitTypeId returns thistype
local thistype prev = thistype.typesNameTable[unitTypeId]
if prev != 0 then
call prev.remove(unitTypeId)
endif
set thistype.typesNameTable[unitTypeId] = this
set .types[.size] = unitTypeId
set .size = .size + 1
return this
endmethod
method destroy takes nothing returns nothing
call types.destroy()
call .deallocate()
endmethod
endstruct
struct NamePool
private Table names
private integer size
static method create takes nothing returns thistype
local thistype this = .allocate()
set this.names = Table.create()
set this.size = 0
return this
endmethod
method getRandom takes nothing returns string
debug if .size <= 0 then
debug call BJDebugMsg("[Library_UnitNaming] NamePool.getRandom: No names to draw from.")
debug return ""
debug endif
return .names.string[GetRandomInt(0, .size - 1)]
endmethod
method add takes string name returns thistype
set .names.string[.size] = name
set .size = .size + 1
return this
endmethod
method destroy takes nothing returns nothing
local integer i = 0
loop
exitwhen i == .size
set .names.string[i] = null
set i = i + 1
endloop
call names.destroy()
call .deallocate()
endmethod
endstruct
/*
Extension Library
*/
static if INCLUDE_UNAME_EXTENDED then
globals
private constant integer H_NAME = -1
private constant integer U_NAME = 1
endglobals
struct UnitName
static Table uTable = 0
static Table defaultName = 0
string firstname
string lastname
string unitname
private integer uid
static method create takes unit u, string first, string last returns thistype
local thistype this = .allocate()
set this.firstname = first
set this.lastname = last
if not (keepNormalNames)then
set this.unitname = " "
else
set this.unitname = GetUnitName(u)
endif
set this.uid = GetHandleId(u)
set uTable[this.uid] = this
return this
endmethod
method destroy takes nothing returns nothing
call uTable.remove(.uid)
set .firstname = null
set .lastname = null
set .unitname = null
call .deallocate()
endmethod
static method setup takes nothing returns nothing
if .uTable == 0 then
set .uTable = Table.create()
endif
endmethod
endstruct
function SaveDefaultName takes unit u returns nothing
local integer id = GetHandleId(u)
if UnitName.defaultName == 0 then
set UnitName.defaultName = Table.create()
endif
if UnitName.defaultName.string.has(U_NAME*id) then
return
endif
set UnitName.defaultName.string[U_NAME*id] = GetUnitName(u)
if IsUnitType(u, UNIT_TYPE_HERO) then
set UnitName.defaultName.string[H_NAME*id] = GetHeroProperName(u)
endif
endfunction
function SetUnitNormalName takes unit u, string normalname returns nothing
local UnitName name = UnitName.uTable[GetHandleId(u)]
static if SAVE_DEFAULT_NAME then
call SaveDefaultName(u)
endif
if name == 0 then
if normalname == "" then
call BlzSetUnitName(u, " ")
else
call BlzSetUnitName(u, normalname)
endif
else
set name.unitname = normalname
if not keepNormalNames then
set keepNormalNames = true // allows an exception
call ChangeUnitFullName(u, name.firstname, name.lastname, name.unitname)
set keepNormalNames = false
else
call ChangeUnitFullName(u, name.firstname, name.lastname, name.unitname)
endif
endif
endfunction
function SetUnitProperName takes unit u, string firstname, string lastname returns nothing
local UnitName name = UnitName.uTable[GetHandleId(u)]
static if SAVE_DEFAULT_NAME then
call SaveDefaultName(u)
endif
if name == 0 then
set name = UnitName.create(u, firstname, lastname)
else
set name.firstname = firstname
set name.lastname = lastname
endif
call ChangeUnitFullName(u, name.firstname, name.lastname, name.unitname)
endfunction
function SetUnitFirstName takes unit u, string firstname returns nothing
local UnitName name = UnitName.uTable[GetHandleId(u)]
static if SAVE_DEFAULT_NAME then
call SaveDefaultName(u)
endif
if name == 0 then
set name = UnitName.create(u, firstname, "")
else
set name.firstname = firstname
endif
call ChangeUnitFullName(u, name.firstname, name.lastname, name.unitname)
endfunction
function SetUnitLastName takes unit u, string lastname returns nothing
local UnitName name = UnitName.uTable[GetHandleId(u)]
static if SAVE_DEFAULT_NAME then
call SaveDefaultName(u)
endif
if name == 0 then
set name = UnitName.create(u, "", lastname)
else
set name.lastname = lastname
endif
call ChangeUnitFullName(u, name.firstname, name.lastname, name.unitname)
endfunction
function GetUnitProperName takes unit u returns string
local UnitName name = UnitName.uTable[GetHandleId(u)]
if name == 0 then
if (IsUnitType(u, UNIT_TYPE_HERO)) then
return GetHeroProperName(u)
endif
return ""
endif
return name.firstname + " " + name.lastname
endfunction
function GetUnitFirstName takes unit u returns string
local UnitName name = UnitName.uTable[GetHandleId(u)]
if name == 0 then
return ""
endif
return name.firstname
endfunction
function GetUnitLastName takes unit u returns string
local UnitName name = UnitName.uTable[GetHandleId(u)]
if name == 0 then
return ""
endif
return name.lastname
endfunction
function GetUnitNormalName takes unit u returns string
local UnitName name = UnitName.uTable[GetHandleId(u)]
if name == 0 then
return ""
endif
return name.unitname
endfunction
function DestroyUnitName takes unit u returns nothing
local integer id = GetHandleId(u)
local UnitName name = UnitName.uTable[id]
if name != 0 then
call name.destroy()
endif
if UnitName.defaultName.string.has(U_NAME*id) then
call BlzSetUnitName(u, UnitName.defaultName.string[U_NAME*id])
call UnitName.defaultName.string.remove(U_NAME*id)
endif
if UnitName.defaultName.string.has(H_NAME*id) then
call BlzSetHeroProperName(u, UnitName.defaultName.string[H_NAME*id])
call UnitName.defaultName.string.remove(H_NAME*id)
endif
endfunction
function SetUnitRandomName takes unit u returns boolean
local UnitName name
local TypeNamePool namepool = TypeNamePool.typesNameTable[GetUnitTypeId(u)]
if namepool == 0 then
return false
endif
static if SAVE_DEFAULT_NAME then
call SaveDefaultName(u)
endif
set name = UnitName.uTable[GetHandleId(u)]
if name == 0 then
set name = UnitName.create(u, namepool.getRandomFirstName(), namepool.getRandomLastName())
else
set name.firstname = namepool.getRandomFirstName()
set name.firstname = namepool.getRandomLastName()
endif
call ChangeUnitFullName(u, name.firstname, name.lastname, name.unitname)
return true
endfunction
endif
/*
Setup
*/
private struct Init
static if LIBRARY_UnitIndexerGUI then
private static method onIndex takes nothing returns boolean
local unit u = GetIndexedUnit()
static if INCLUDE_UNAME_EXTENDED then
call SetUnitRandomName(u)
else
call SetUnitRandomNameSimple(u)
endif
set u = null
return false
endmethod
static if INCLUDE_UNAME_EXTENDED then
private static method onDeindex takes nothing returns boolean
local unit u = GetIndexedUnit()
call DestroyUnitName(u)
set u = null
return false
endmethod
endif
endif
static if LIBRARY_UnitDex and not LIBRARY_UnitIndexerGUI then
private static method onIndex takes nothing returns boolean
local unit u = GetIndexedUnit()
static if INCLUDE_UNAME_EXTENDED then
call SetUnitRandomName(u)
else
call SetUnitRandomNameSimple(u)
endif
set u = null
return false
endmethod
static if INCLUDE_UNAME_EXTENDED then
private static method onDeindex takes nothing returns boolean
static if INCLUDE_UNAME_EXTENDED then
local unit u = GetIndexedUnit()
call DestroyUnitName(u)
set u = null
endif
return false
endmethod
endif
endif
static if not LIBRARY_UnitIndexerGUI and not LIBRARY_UnitDex and not INCLUDE_UNAME_EXTENDED then
private static method onEnterMap takes nothing returns boolean
call SetUnitRandomNameSimple(GetTriggerUnit()) // No memory saved to unit
return false
endmethod
endif
private static method onTimer takes nothing returns nothing
local timer t = GetExpiredTimer()
local group g = CreateGroup()
local rect r
local unit u
local trigger trg
static if LIBRARY_WorldBounds then
set r = WorldBounds.world
else
set r = GetWorldBounds()
endif
call GroupEnumUnitsInRect(g, r, null)
loop
set u = FirstOfGroup(g)
exitwhen u == null
call GroupRemoveUnit(g, u)
static if INCLUDE_UNAME_EXTENDED then
static if LIBRARY_UnitIndexerGUI then
call SetUnitRandomName(u)
elseif LIBRARY_UnitDex then
call SetUnitRandomName(u)
else
call SetUnitRandomNameSimple(u)
endif
else
call SetUnitRandomNameSimple(u)
endif
endloop
static if LIBRARY_UnitIndexerGUI then
call OnUnitIndex(function thistype.onIndex)
static if INCLUDE_UNAME_EXTENDED then
call OnUnitDeindex(function thistype.onDeindex)
endif
endif
static if LIBRARY_UnitDex and not LIBRARY_UnitIndexerGUI then
call RegisterUnitIndexEvent(Filter(function thistype.onIndex) , EVENT_UNIT_INDEX)
static if INCLUDE_UNAME_EXTENDED then
call RegisterUnitIndexEvent(Filter(function thistype.onDeindex), EVENT_UNIT_DEINDEX)
endif
endif
// If no UnitIndexer and extended features disabled then handle entering units
static if not LIBRARY_UnitDex and not LIBRARY_UnitIndexerGUI and not INCLUDE_UNAME_EXTENDED then
set trg = CreateTrigger()
call TriggerRegisterEnterRectSimple(trg, r)
call TriggerAddAction(trg, function thistype.onEnterMap)
set trg = null
endif
static if not LIBRARY_WorldBounds then
call RemoveRect(r)
endif
call DestroyGroup(g)
call PauseTimer(t)
call DestroyTimer(t)
set t = null
set g = null
set r = null
endmethod
private static method onInit takes nothing returns nothing
local timer t = CreateTimer()
call TimerStart(t, 0.2, false, function thistype.onTimer) // We delay setup slightly
set t = null
call TypeNamePool.setup()
static if INCLUDE_UNAME_EXTENDED then
call UnitName.setup()
endif
endmethod
endstruct
endlibrary
library WorldBounds /* v2.0.0.0
************************************************************************************
*
* struct WorldBounds extends array
*
* Fields
* -------------------------
*
* readonly static integer maxX
* readonly static integer maxY
* readonly static integer minX
* readonly static integer minY
*
* readonly static integer centerX
* readonly static integer centerY
*
* readonly static rect world
* readonly static region worldRegion
*
************************************************************************************/
private module WorldBoundInit
private static method onInit takes nothing returns nothing
set world = GetWorldBounds()
set maxX = R2I(GetRectMaxX(world))
set maxY = R2I(GetRectMaxY(world))
set minX = R2I(GetRectMinX(world))
set minY = R2I(GetRectMinY(world))
set centerX = R2I((maxX + minX)/2)
set centerY = R2I((minY + maxY)/2)
set worldRegion = CreateRegion()
call RegionAddRect(worldRegion, world)
endmethod
endmodule
struct WorldBounds extends array
readonly static integer maxX
readonly static integer maxY
readonly static integer minX
readonly static integer minY
readonly static integer centerX
readonly static integer centerY
readonly static rect world
readonly static region worldRegion
implement WorldBoundInit
endstruct
endlibrary
library UnitIndexerGUI //requires GUI Unit Indexer
globals
private trigger index = null
private trigger deindex = null
private trigger init = null
private trigger tempTrig
endglobals
private function DoTheThings takes trigger t, code c, real r returns trigger
if t == null then
set t = CreateTrigger()
call TriggerRegisterVariableEvent(t, "udg_UnitIndexEvent", EQUAL, r)
endif
call TriggerAddCondition(t, Filter(c))
set tempTrig = t
set t = null
return tempTrig
endfunction
//call RegisterUnitIndexEvent(Filter(function Blah), EVENT_UNIT_INDEXED)
//->
//call OnUnitIndex(function Blah)
function OnUnitIndex takes code c returns nothing
set index = DoTheThings(index, c, 1.)
endfunction
//call RegisterUnitIndexEvent(Filter(function Blah), EVENT_UNIT_DEINDEXED)
//->
//call OnUnitDeindex(function Blah)
function OnUnitDeindex takes code c returns nothing
set deindex = DoTheThings(deindex, c, 2.)
endfunction
private function DestroyInit takes nothing returns boolean
call DestroyTrigger(init) //will still allow consecutive triggerconditions to run.
set init = null
return false
endfunction
//GUI Unit Indexer will initialize after any vJass stuff, so you need to do your
//unit-indexer-requiring stuff after this event instead of a module/struct/library
//initializer.
function OnUnitIndexerInitialized takes code c returns nothing
if init == null then
set init = CreateTrigger()
call TriggerAddCondition(init, Filter(function DestroyInit))
call TriggerRegisterVariableEvent(init, "udg_UnitIndexEvent", EQUAL, 3.00)
endif
call TriggerAddCondition(init, Filter(c))
endfunction
function GetUnitId takes unit u returns integer
return GetUnitUserData(u)
endfunction
function GetUnitById takes integer id returns unit
return udg_UDexUnits[id]
endfunction
function GetIndexedUnit takes nothing returns unit
return udg_UDexUnits[udg_UDex]
endfunction
function GetIndexedUnitId takes nothing returns integer
return udg_UDex
endfunction
function IsUnitIndexed takes unit u returns boolean
return udg_UDexUnits[GetUnitUserData(u)] == u
endfunction
endlibrary
library UnitDex uses optional WorldBounds, optional GroupUtils
/***************************************************************
*
* v1.2.2, by TriggerHappy
* ¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯
* UnitDex assigns every unit an unique integer. It attempts to make that number within the
* maximum array limit so you can associate it with one.
* _________________________________________________________________________
* 1. Installation
* ¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯
* Copy the script to your map, save it, then restart the editor and comment out the line below.
*/
//! external ObjectMerger w3a Adef uDex anam "Detect Leave" ansf "(UnitDex)" aart "" acat "" arac 0
/* ________________________________________________________________________
* 2. Configuration
* ¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯
*/
private module UnitDexConfig
// The raw code of the leave detection ability.
static constant integer DETECT_LEAVE_ABILITY = 'uDex'
// Allow debug messages (debug mode must also be on)
static constant boolean ALLOW_DEBUGGING = true
// Uncomment the lines below to define a global filter for units being indexed
/*static method onFilter takes unit u returns boolean
return true
endmethod*/
endmodule
/* _________________________________________________________________________
* 3. Function API
* ¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯
* Every function inlines.
*
* function GetUnitId takes unit whichUnit returns integer
* function GetUnitById takes integer index returns unit
*
* function UnitDexEnable takes boolean flag returns nothing
* function UnitDexRemove takes unit u, boolean runEvents returns boolean
*
* function IsUnitIndexed takes unit u returns boolean
* function IsIndexingEnabled takes nothing returns boolean
*
* function GetIndexedUnit takes nothing returns unit
* function GetIndexedUnitId takes nothing returns integer
*
* function RegisterUnitIndexEvent takes boolexpr func, integer eventtype returns indexevent
* function RemoveUnitIndexEvent takes triggercondition c, integer eventtype returns nothing
* function TriggerRegisterUnitIndexEvent takes trigger t, integer eventtype returns nothing
*
* function OnUnitIndex takes code func returns triggercondition
* function OnUnitDeidex takes code func returns triggercondition
* _________________________________________________________________________
* 4. Struct API
* ¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯
* UnitDex.Enabled = false // toggle the indexer
* UnitDex.Initialized // returns true if the preload timer has finished
* UnitDex.Count // returns the amount of units indexed
* UnitDex.Unit[0] // access the UnitDex array directly
* UnitDex.Group // a unit group containing every indexed unit (for enumeration)
* UnitDex.LastIndex // returns the last indexed unit's id
* _________________________________________________________________________
* 5. Public Variables
* ¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯
* These are to be used with the "eventtype" argument of the event API:
*
* constant integer EVENT_UNIT_INDEX = 0
* constant integer EVENT_UNIT_DEINDEX = 1
* _________________________________________________________________________
* 6. Examples
* ¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯
* 1. Associate a unit with a variable
*
* set UnitFlag[GetUnitId(yourUnit)] = true
*
* 2. Allocate a struct instance using a units assigned ID
*
* local somestruct data = GetUnitId(yourUnit)
*
* 3. Detect when a unit leaves the map
*
* function Exit takes nothing returns nothing
* call BJDebugMsg("The unit " + GetUnitName(GetIndexedUnit()) + " has left the map.")
* endfunction
*
* call OnUnitDeindex(function Exit)
* // or
* call RegisterUnitIndexEvent(Filter(function Exit), EVENT_UNIT_DEINDEX)
*
*
* _________________________________________________________________________
* 7. How it works
* ¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯
* 1. Enumerate all preplaced units
* 2. TriggerRegisterEnterRegion native to detect when a unit enters the map
* 3. Assign each unit that enters the map a unique integer
* 4. Give every unit an ability based off of defend. There is no native to accurately
* detect when a unit leaves the map but when a unit dies or is removed from the game
* they are issued the "undefend" order
* 5. Catch the "undefend" order and remove unit from the queue
* _________________________________________________________________________
* 8. Notes
* ¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯
* - This system is compatable with GUI because it utilizes UnitUserData (custom values for units).
* - The object merger line should be commented out after saving and restarting.
*
* -http://www.hiveworkshop.com/forums/submissions-414/unitdex-lightweight-unit-indexer-248209/
*
* ¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯
*/
globals
// Event types
constant integer EVENT_UNIT_INDEX = 0
constant integer EVENT_UNIT_DEINDEX = 1
// System variables
private trigger array IndexTrig
private integer Index = 0
private real E=-1
private boolexpr FilterEnter
endglobals
function GetUnitId takes unit whichUnit returns integer
return GetUnitUserData(whichUnit)
endfunction
function GetUnitById takes integer index returns unit
return UnitDex.Unit[index]
endfunction
function GetIndexedUnit takes nothing returns unit
return UnitDex.Unit[UnitDex.LastIndex]
endfunction
function GetIndexedUnitId takes nothing returns integer
return UnitDex.LastIndex
endfunction
function IsUnitIndexed takes unit u returns boolean
return (GetUnitById(GetUnitId(u)) != null)
endfunction
function UnitDexEnable takes boolean flag returns nothing
set UnitDex.Enabled = flag
endfunction
function IsIndexingEnabled takes nothing returns boolean
return UnitDex.Enabled
endfunction
function RegisterUnitIndexEvent takes boolexpr func, integer eventtype returns triggercondition
return TriggerAddCondition(IndexTrig[eventtype], func)
endfunction
function RemoveUnitIndexEvent takes triggercondition c, integer eventtype returns nothing
call TriggerRemoveCondition(IndexTrig[eventtype], c)
endfunction
function TriggerRegisterUnitIndexEvent takes trigger t, integer eventtype returns nothing
call TriggerRegisterVariableEvent(t, SCOPE_PRIVATE + "E", EQUAL, eventtype)
endfunction
function OnUnitIndex takes code func returns triggercondition
return TriggerAddCondition(IndexTrig[EVENT_UNIT_INDEX], Filter(func))
endfunction
function OnUnitDeindex takes code func returns triggercondition
return TriggerAddCondition(IndexTrig[EVENT_UNIT_DEINDEX], Filter(func))
endfunction
/****************************************************************/
private keyword UnitDexCore
struct UnitDex extends array
static boolean Enabled = true
readonly static integer LastIndex
readonly static boolean Initialized=false
readonly static group Group=CreateGroup()
readonly static unit array Unit
readonly static integer Count = 0
readonly static integer array List
implement UnitDexConfig
private static integer Counter = 0
implement UnitDexCore
endstruct
function UnitDexRemove takes unit u, boolean runEvents returns boolean
return UnitDex.Remove(u, runEvents)
endfunction
/****************************************************************/
private module UnitDexCore
static method Remove takes unit u, boolean runEvents returns boolean
local integer i
if (IsUnitIndexed(u)) then
set i = GetUnitId(u)
set UnitDex.List[i] = Index
set Index = i
call GroupRemoveUnit(UnitDex.Group, u)
call SetUnitUserData(u, 0)
if (runEvents) then
set UnitDex.LastIndex = i
set E = EVENT_UNIT_DEINDEX
call TriggerEvaluate(IndexTrig[EVENT_UNIT_DEINDEX])
set E = -1
endif
set UnitDex.Unit[i] = null
set UnitDex.Count = UnitDex.Count - 1
return true
endif
return false
endmethod
private static method onGameStart takes nothing returns nothing
local integer i = 1
loop
exitwhen i > Counter
set LastIndex = i
call TriggerEvaluate(IndexTrig[EVENT_UNIT_INDEX])
set E = EVENT_UNIT_INDEX
set E = -1
set i = i + 1
endloop
set LastIndex = Counter
set Initialized = true
set FilterEnter = null
call DestroyTimer(GetExpiredTimer())
endmethod
private static method onEnter takes nothing returns boolean
local unit u = GetFilterUnit()
local integer i = GetUnitId(u)
local integer t = Index
if (i == 0 and thistype.Enabled) then
// If a filter was defined pass the unit through it.
static if (thistype.onFilter.exists) then
if (not thistype.onFilter(u)) then
set u = null
return false // check failed
endif
endif
// Handle debugging
static if (thistype.DEBUG_MODE and thistype.ALLOW_DEBUGGING) then
if (t == 0 and Counter+1 >= JASS_MAX_ARRAY_SIZE) then
call DisplayTextToPlayer(GetLocalPlayer(), 0, 0, "UnitDex: Maximum number of units reached!")
set u = null
return false
endif
endif
// Add to group of indexed units
call GroupAddUnit(thistype.Group, u)
// Give unit the leave detection ability
call UnitAddAbility(u, thistype.DETECT_LEAVE_ABILITY)
call UnitMakeAbilityPermanent(u, true, thistype.DETECT_LEAVE_ABILITY)
// Allocate index
if (Index != 0) then
set Index = List[t]
else
set Counter = Counter + 1
set t = Counter
endif
set List[t] = -1
set LastIndex = t
set thistype.Unit[t] = u
set Count = Count + 1
// Store the index
call SetUnitUserData(u, t)
if (thistype.Initialized) then
// Execute custom events registered with RegisterUnitIndexEvent
call TriggerEvaluate(IndexTrig[EVENT_UNIT_INDEX])
// Handle TriggerRegisterUnitIndexEvent
set E = EVENT_UNIT_INDEX
// Reset so the event can occur again
set E = -1
endif
endif
set u = null
return false
endmethod
private static method onLeave takes nothing returns boolean
local unit u
local integer i
// Check if order is undefend.
if (thistype.Enabled and GetIssuedOrderId() == 852056) then
set u = GetTriggerUnit()
// If unit was killed (not removed) then don't continue
if (GetUnitAbilityLevel(u, thistype.DETECT_LEAVE_ABILITY) != 0) then
set u = null
return false
endif
set i = GetUnitId(u)
// If unit has been indexed then deindex it
if (i > 0 and i <= Counter and u == GetUnitById(i)) then
// Recycle the index
set List[i] = Index
set Index = i
set LastIndex = i
// Remove to group of indexed units
call GroupRemoveUnit(thistype.Group, u)
// Execute custom events without any associated triggers
call TriggerEvaluate(IndexTrig[EVENT_UNIT_DEINDEX])
// Handle TriggerRegisterUnitIndexEvent
set E = EVENT_UNIT_DEINDEX
// Remove entry
call SetUnitUserData(u, 0)
set thistype.Unit[i] = null
// Decrement unit count
set Count = Count - 1
// Reset so the event can occur again
set E = -1
endif
set u = null
endif
return false
endmethod
private static method onInit takes nothing returns nothing
local trigger t = CreateTrigger()
local integer i = 0
local player p
local unit u
static if (not LIBRARY_WorldBounds) then // Check if WorldBounts exists, if not then define the necessary vars
local region reg = CreateRegion() // If WorldBounds wasn't found, create the region manually
local rect world = GetWorldBounds()
endif
static if (not LIBRARY_GroupUtils) then // Check if GroupUtils exists so we can use it's enumeration group.
local group ENUM_GROUP = CreateGroup() // If not, create the group.
endif
set FilterEnter = Filter(function thistype.onEnter)
// Begin to index units when they enter the map
static if (LIBRARY_WorldBounds) then
call TriggerRegisterEnterRegion(CreateTrigger(), WorldBounds.worldRegion, FilterEnter)
else
call RegionAddRect(reg, world)
call TriggerRegisterEnterRegion(CreateTrigger(), reg, FilterEnter)
call RemoveRect(world)
set world = null
endif
call TriggerAddCondition(t, Filter(function thistype.onLeave))
set IndexTrig[EVENT_UNIT_INDEX] = CreateTrigger()
set IndexTrig[EVENT_UNIT_DEINDEX] = CreateTrigger()
loop
set p = Player(i)
// Detect "undefend"
call TriggerRegisterPlayerUnitEvent(t, p, EVENT_PLAYER_UNIT_ISSUED_ORDER, null)
// Hide the detect ability from players
call SetPlayerAbilityAvailable(p, thistype.DETECT_LEAVE_ABILITY, false)
set i = i + 1
exitwhen i == bj_MAX_PLAYER_SLOTS
endloop
// Index preplaced units
set i = 0
loop
call GroupEnumUnitsOfPlayer(ENUM_GROUP, Player(i), FilterEnter)
set i = i + 1
exitwhen i == bj_MAX_PLAYER_SLOTS
endloop
static if (not LIBRARY_GroupUtils) then
call DestroyGroup(ENUM_GROUP)
set ENUM_GROUP = null
endif
set LastIndex = Counter
// run init triggers
call TimerStart(CreateTimer(), 0.00, false, function thistype.onGameStart)
endmethod
endmodule
endlibrary
scope UnitNamingSetup initializer Init
globals
NamePool firstNamesMale
NamePool firstNamesFem
NamePool lastNames
TypeNamePool females
TypeNamePool males
endglobals
/* This is the configuration of the name pools, each UniTypePool consist of two pools of first names
and which unit-types that it should be applied to.
*/
private function Init takes nothing returns nothing
set firstNamesFem = NamePool.create()
set firstNamesMale = NamePool.create()
set lastNames = NamePool.create()
set females = TypeNamePool.create(firstNamesFem, lastNames)
set males = TypeNamePool.create(firstNamesMale, lastNames)
call females.add('nvlw').add('nhef').add('hsor')
call males.add('nvil').add('nvl2').add('Hpal').add('nvk2').add('hfoo').add('hrif')
call ExecuteFunc("SetupFemaleFirstNames")
call ExecuteFunc("SetupMaleFirstNames")
call ExecuteFunc("SetupLastNames")
endfunction
function SetupLastNames takes nothing returns nothing
call lastNames.add("Alcaraz")
call lastNames.add("Anand")
call lastNames.add("Appiah")
call lastNames.add("Appleton")
call lastNames.add("Archer")
call lastNames.add("Atkins")
call lastNames.add("Baldwin")
call lastNames.add("Ball")
call lastNames.add("Barker")
call lastNames.add("Barnes")
call lastNames.add("Barrett")
call lastNames.add("Bartley")
call lastNames.add("Beard")
call lastNames.add("Beard")
call lastNames.add("Bell")
call lastNames.add("Betteridge")
call lastNames.add("Biddle")
call lastNames.add("Binns")
call lastNames.add("Bishop")
call lastNames.add("Boothroyd")
call lastNames.add("Boyle")
call lastNames.add("Briggs")
call lastNames.add("Bright")
call lastNames.add("Brinn")
call lastNames.add("Brown")
call lastNames.add("Brown")
call lastNames.add("Capell")
call lastNames.add("Carden")
call lastNames.add("Carter")
call lastNames.add("Cass")
call lastNames.add("Casson")
call lastNames.add("Childs")
call lastNames.add("Clark")
call lastNames.add("Collyer")
call lastNames.add("Cooch")
call lastNames.add("Cook")
call lastNames.add("Cox")
call lastNames.add("Cross")
call lastNames.add("Cunningham")
call lastNames.add("Cuthbert")
call lastNames.add("Daines")
call lastNames.add("Davies")
call lastNames.add("Davis")
endfunction
function SetupMaleFirstNames takes nothing returns nothing
call firstNamesMale.add("Paul")
call firstNamesMale.add("Brian")
call firstNamesMale.add("Russell")
call firstNamesMale.add("Jurgen")
call firstNamesMale.add("Robert")
call firstNamesMale.add("Michael")
call firstNamesMale.add("Mark")
call firstNamesMale.add("Harry")
call firstNamesMale.add("Jeremy")
call firstNamesMale.add("Ronald")
call firstNamesMale.add("John")
call firstNamesMale.add("Harpal")
call firstNamesMale.add("Adrian")
call firstNamesMale.add("Timothy")
call firstNamesMale.add("Mike")
call firstNamesMale.add("Timothy")
call firstNamesMale.add("James")
call firstNamesMale.add("Alastair")
call firstNamesMale.add("Jonathan")
call firstNamesMale.add("Mark")
call firstNamesMale.add("Peter")
call firstNamesMale.add("William")
call firstNamesMale.add("Colin")
call firstNamesMale.add("Craig")
call firstNamesMale.add("Lucus")
call firstNamesMale.add("Simon")
call firstNamesMale.add("David")
call firstNamesMale.add("John")
call firstNamesMale.add("Stephen")
call firstNamesMale.add("Jason")
call firstNamesMale.add("Doug")
call firstNamesMale.add("Simon")
call firstNamesMale.add("Mark")
call firstNamesMale.add("Dennis")
call firstNamesMale.add("Adrian")
call firstNamesMale.add("Arthur")
call firstNamesMale.add("William")
call firstNamesMale.add("Daniel")
call firstNamesMale.add("Charles")
call firstNamesMale.add("Stephen")
call firstNamesMale.add("John")
call firstNamesMale.add("David")
call firstNamesMale.add("Andrew")
call firstNamesMale.add("Ibrar")
call firstNamesMale.add("Richard")
call firstNamesMale.add("Samuel")
call firstNamesMale.add("Paul")
call firstNamesMale.add("Patrick")
call firstNamesMale.add("Shawn")
call firstNamesMale.add("Gordon")
call firstNamesMale.add("John")
call firstNamesMale.add("Glenn")
call firstNamesMale.add("Edward")
call firstNamesMale.add("Mark")
call firstNamesMale.add("David")
call firstNamesMale.add("Jonathan")
call firstNamesMale.add("Moray")
call firstNamesMale.add("Paul")
call firstNamesMale.add("Philip")
call firstNamesMale.add("Stefan")
call firstNamesMale.add("Christopher")
call firstNamesMale.add("Jp")
call firstNamesMale.add("Simmy")
call firstNamesMale.add("Steven")
call firstNamesMale.add("Andrew")
call firstNamesMale.add("Robert")
call firstNamesMale.add("Christopher")
call firstNamesMale.add("Paul")
call firstNamesMale.add("John")
call firstNamesMale.add("Gordhanbhai")
call firstNamesMale.add("Douglas")
call firstNamesMale.add("John")
call firstNamesMale.add("Evan")
call firstNamesMale.add("Stuart")
call firstNamesMale.add("Timothy")
call firstNamesMale.add("Craig")
call firstNamesMale.add("Lukman")
call firstNamesMale.add("David")
call firstNamesMale.add("John")
call firstNamesMale.add("Steven")
call firstNamesMale.add("Baljinder")
call firstNamesMale.add("Jag")
call firstNamesMale.add("Nigel")
call firstNamesMale.add("Kenneth")
call firstNamesMale.add("Gavin")
call firstNamesMale.add("Martin")
call firstNamesMale.add("Anthony")
call firstNamesMale.add("Richard")
call firstNamesMale.add("Mark")
call firstNamesMale.add("Christopher")
call firstNamesMale.add("Paul")
call firstNamesMale.add("Mark")
call firstNamesMale.add("Philip")
call firstNamesMale.add("Peter")
call firstNamesMale.add("David")
call firstNamesMale.add("Keith")
call firstNamesMale.add("Ben")
endfunction
function SetupFemaleFirstNames takes nothing returns nothing
call firstNamesFem.add("Mary")
call firstNamesFem.add("Seema")
call firstNamesFem.add("Alice")
call firstNamesFem.add("Carolyn")
call firstNamesFem.add("Jacqueline")
call firstNamesFem.add("Christine")
call firstNamesFem.add("Lesley")
call firstNamesFem.add("Kay")
call firstNamesFem.add("Margaret")
call firstNamesFem.add("Inez")
call firstNamesFem.add("Sara")
call firstNamesFem.add("Rose")
call firstNamesFem.add("Helena")
call firstNamesFem.add("Sheila")
call firstNamesFem.add("Lisa")
call firstNamesFem.add("Pamela")
call firstNamesFem.add("Ann")
call firstNamesFem.add("Kandiah")
call firstNamesFem.add("Lucia")
call firstNamesFem.add("Sarah")
call firstNamesFem.add("Louise")
call firstNamesFem.add("Barbara")
call firstNamesFem.add("Julie")
call firstNamesFem.add("May")
call firstNamesFem.add("Deirdre")
call firstNamesFem.add("Susan")
call firstNamesFem.add("Diane")
call firstNamesFem.add("Inger")
call firstNamesFem.add("Clare")
call firstNamesFem.add("Yvonne")
call firstNamesFem.add("Angela")
call firstNamesFem.add("Charlotte")
call firstNamesFem.add("Sally")
call firstNamesFem.add("Elaine")
call firstNamesFem.add("Maureen")
call firstNamesFem.add("June")
call firstNamesFem.add("Cheryl")
call firstNamesFem.add("Anne")
call firstNamesFem.add("Katie")
call firstNamesFem.add("Judith")
call firstNamesFem.add("Adele")
call firstNamesFem.add("Janine")
call firstNamesFem.add("Julia")
call firstNamesFem.add("Rosamund")
call firstNamesFem.add("Anna")
call firstNamesFem.add("Anthea")
call firstNamesFem.add("Patricia")
call firstNamesFem.add("Jane")
call firstNamesFem.add("Anne")
call firstNamesFem.add("Melissa")
call firstNamesFem.add("Carol")
call firstNamesFem.add("Beverly")
call firstNamesFem.add("Elizabeth")
call firstNamesFem.add("Susan")
call firstNamesFem.add("Margaret")
call firstNamesFem.add("Mary")
call firstNamesFem.add("Phyllis")
call firstNamesFem.add("Lesley")
call firstNamesFem.add("Ebonie")
call firstNamesFem.add("Irene")
call firstNamesFem.add("Maria")
call firstNamesFem.add("Lesley")
call firstNamesFem.add("Kim")
call firstNamesFem.add("Amy")
call firstNamesFem.add("Katie")
call firstNamesFem.add("Jane")
call firstNamesFem.add("Gillian")
call firstNamesFem.add("Kathleen")
call firstNamesFem.add("Claire")
call firstNamesFem.add("Yvonne")
call firstNamesFem.add("Mildred")
call firstNamesFem.add("Dawn")
call firstNamesFem.add("Brenda")
call firstNamesFem.add("Patricia")
call firstNamesFem.add("Elizabeth")
call firstNamesFem.add("Susan")
call firstNamesFem.add("Lorraine")
call firstNamesFem.add("Pamela")
call firstNamesFem.add("Sharon")
call firstNamesFem.add("Maria")
call firstNamesFem.add("Suzanne")
call firstNamesFem.add("Susan")
call firstNamesFem.add("Jackie")
call firstNamesFem.add("Victoria")
call firstNamesFem.add("Valerie")
call firstNamesFem.add("Nichola")
call firstNamesFem.add("Susan")
call firstNamesFem.add("Sarah")
call firstNamesFem.add("Rebecca")
call firstNamesFem.add("Patricia")
call firstNamesFem.add("Belinda")
call firstNamesFem.add("Anne")
call firstNamesFem.add("Sarah")
call firstNamesFem.add("Claudia")
call firstNamesFem.add("Harriet")
call firstNamesFem.add("Jennifer")
call firstNamesFem.add("Winnie")
endfunction
endscope
function Trig_Esc_Actions takes nothing returns nothing
local real t = 30
call DisplayTimedTextToForce( GetPlayersAll(), t, "---------------------------")
call DisplayTimedTextToForce( GetPlayersAll(), t, "-setfirst [firstname]")
call DisplayTimedTextToForce( GetPlayersAll(), t, "-getfirst")
call DisplayTimedTextToForce( GetPlayersAll(), t, "-setlast [lastname]")
call DisplayTimedTextToForce( GetPlayersAll(), t, "-getlast")
call DisplayTimedTextToForce( GetPlayersAll(), t, "-setuname [unit name]")
call DisplayTimedTextToForce( GetPlayersAll(), t, "-getuname")
call DisplayTimedTextToForce( GetPlayersAll(), t, "-getproper")
call DisplayTimedTextToForce( GetPlayersAll(), t, "-random")
call DisplayTimedTextToForce( GetPlayersAll(), t, "-destroy")
call DisplayTimedTextToForce( GetPlayersAll(), t, "-hammer (to rename MK")
endfunction
//===========================================================================
function InitTrig_Esc takes nothing returns nothing
set gg_trg_Esc = CreateTrigger( )
call TriggerRegisterPlayerEventEndCinematic( gg_trg_Esc, Player(0) )
call TriggerAddAction( gg_trg_Esc, function Trig_Esc_Actions )
endfunction