Name | Type | is_array | initial_value |
t | terraintype | Yes | |
tmpPoint | location | No |
//TESH.scrollpos=0
//TESH.alwaysfold=0
library SlidingSystem/* v3.4 By IcemanBo
*/ requires /*
*/ UnitIndexer /* The one in test map. (by Nestharus v4.0.2.6)
*/ TimerUtils /* http://www.wc3c.net/showthread.php?t=101322
*/ Table /* http://www.hiveworkshop.com/forums/jass-resources-412/snippet-new-table-188084/
*/ WorldBounds /* https://github.com/nestharus/JASS/blob/master/jass/Systems/WorldBounds/script.j
*/ Event /* The one in test map.
** Info
** ¯¯¯¯¯¯¯¯
**
** Sliders can have a special sliding behaviour on different terrain types.
** Each slider also can have it's own movement speed while sliding,
** seperated and indepentand from the terrain type.
**
** This library provides various possibilities
** to create an individual behaviour for each terrain type. (Config - Part)
**
**
** Struct Terrain:
**
**
** static method create takes integer terainType, real terrainSpeed returns thistype
**
** Furthermore you can define and read these public members:
** (by default all values are "0" or "false".
**
** pullSpeed = Unit will be constantly pulled with this speed. (real)
** pullDirection = Direction for pulling, in degrees. (real)
** angle = Angle that will be added, when steering. (real)
** lifeAddition = Life that will be added each second. Negagtive values are also possible. (real)
** allowSteer = If unit can steer on the tarrainType or not. (boolean)
** allowCast = If unit can cast on the terrainType or not. (boolean)
** kill = Kill the unit on the terrainType or not. (boolean)
**
**
** You can have a look into folder TestMap -> "Terrain Settings" for a better understanding and examples.
**
**
** Struct Slider:
**
**
** static methods:
** ¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯
**
** static method create takes unit u returns thistype
**
** static method getSliderId takes unit u returns thistype
**
** static method isUnitSlider takes unit u returns boolean
**
**
**
** methods:
** ¯¯¯¯¯¯¯¯¯¯
**
** method destroy takes nothing returns nothing
**
** method enable takes boolean b returns nothing (disabled instance can't slide)
**
** method isEnabled takes nothing returns boolean
**
** method getDefaultSpeed takes nothing returns real
**
** method getTempSpeed takes nothing returns real
**
** method setDefaultSpeed takes real s returns nothing
**
** method addDefaultSpeed takes real s returns nothing
**
** method addTempSpeed takes real speed, real duration returns nothing
**
**
**
** Deindexed units will be automatically removed from system.
** You can have a look into folder TestMap -> "Create Slider" for a better understanding and examples.
**
***************************************************************************
**
** Credits to guys named in brackets.
**
** Requires:
** - Table (Bribe)
** - TimerUtils (Vexorian)
** - UnitIndexer (Nestharus)
** • WorldBounds (Nestharus)
** • Event (Nestharus)
**
**
**************************************************************************
*
*
************************ Configuration - Start ***************************/
globals
private constant boolean SLIDER_UNCLICKABLE = true // Make Slider unclickable.
private constant boolean SLIDER_NO_PATHING = true // Disable pathing for Slider.
private constant boolean CHECK_PATHING = false // Check for pathability while sliding.
/************************ Configuration - End *****************************/
private constant real INTERVAL = .03 // Sliding looks smoother smoother with .03 instead of 0.312500.
private constant real TPS = 1/INTERVAL // Operation threads per second
private trigger steerTrigger = CreateTrigger()
private trigger moveTrigger = CreateTrigger() // Sliding looks smoother with trigger instead of a timer.
private constant integer SMART = 851971
private constant integer STOP = 851972
private constant integer PATROL = 851990
private constant integer MOVE = 851986
endglobals
/*
* Terrain struct, to define sliding behaviour.
*/
struct Terrain
private static key k
private static Table table = k
private integer terrainType
real speed
real pullSpeed = 0
real pullDirection = 0
real angle = 0
real lifeAddition = 0
boolean allowSteer = false
boolean allowCast = false
boolean kill = false
static method create takes integer whichTerrain, real whichSpeed returns thistype
local thistype this = thistype.allocate()
set thistype.table[whichTerrain] = this
set this.terrainType = whichTerrain
set this.speed = whichSpeed/TPS
return this
endmethod
static method operator [] takes integer i returns thistype
return thistype.table[i]
endmethod
endstruct
/*
* Acceleration struct, to manipulate Slider's temporary speed
*/
private struct Acceleration
public timer tim
public real speedChange
public Slider instance
static method create takes Slider slider, real speed returns thistype
local thistype this = thistype.allocate()
set this.instance = slider
set this.speedChange = speed
return this
endmethod
method destroy takes nothing returns nothing
call this.deallocate()
call ReleaseTimer(tim)
endmethod
endstruct
/*
* Slider struct (main code)
*/
struct Slider
private static thistype array list
private static boolean array is // Is unit a slider
private unit slider
public real defaultSpeed // Permanent speed
public real bonusSpeed // Temporary speed
private real propWindow
private real turnSpeed
private boolean enabled // If slider is currently enabled.
private thistype prev
private thistype next
static thistype first = 0
static method create takes unit u returns thistype
local thistype this
local integer index = GetUnitUserData(u)
if (isUnitSlider(u)) then
debug call BJDebugMsg("Error - Sliding System - create: " + GetUnitName(u) + ", Index[" + I2S(index) + "] is already a Slider." )
return 0
endif
set this = thistype.allocate()
set this.slider = u
set thistype.list[index] = this
set this.is[index] = true
set this.enabled = true
set this.propWindow = GetUnitDefaultPropWindow(slider)*bj_RADTODEG
set this.turnSpeed = GetUnitDefaultTurnSpeed(slider)
static if (SLIDER_UNCLICKABLE) then
call UnitAddAbility(u,'Aloc')
call ShowUnit(u,false)
call ShowUnit(u,true)
call UnitRemoveAbility(u,'Aloc')
endif
static if (SLIDE_NO_PATHING) then
call SetUnitPathing( u, false )
endif
if (thistype.first == 0) then
call EnableTrigger(moveTrigger)
endif
set this.next = thistype.first
set thistype.first.prev = this
set thistype.first = this
set this.prev = 0
return this
endmethod
method destroy takes nothing returns nothing
local integer index = GetUnitUserData(slider)
call this.deallocate()
set thistype.list[index] = 0
set this.is[index] = false
set this.slider = null
if (this == thistype.first) then
set thistype.first = this.next
endif
set this.next.prev = this.prev
set this.prev.next = this.next
if (thistype.first == 0) then
call DisableTrigger(moveTrigger)
endif
endmethod
/*
* Sliding - Movement (periodic call)
*/
private static method onMove takes nothing returns nothing
local real angle
local real offset
local real x
local real y
local integer terrainType
local thistype this = thistype.first
loop
exitwhen this == 0
if enabled then
set x = GetUnitX(slider)
set y = GetUnitY(slider)
set terrainType = GetTerrainType(x, y)
// Check if slider is on a registered terrain type.
if (Terrain[terrainType] != 0) then
if (Terrain[terrainType].kill) then
call KillUnit(slider)
else
set angle = (GetUnitFacing(slider)*bj_DEGTORAD)
set offset = defaultSpeed + bonusSpeed + Terrain[terrainType].speed
// Heal/damage the slider.
call SetWidgetLife(slider,GetWidgetLife(slider) + Terrain[terrainType].lifeAddition/TPS)
set x = x + offset * Cos(angle)
set y = y + offset * Sin(angle)
// Sliding
static if (CHECK_PATHING) then
call SetUnitPosition(slider, x, y)
else
call SetUnitX(slider, x)
call SetUnitY(slider, y)
endif
// Check if terrain type is pulling.
if (Terrain[terrainType].pullSpeed != 0) then
static if (CHECK_PATHING) then
call SetUnitPosition(slider, x + (Terrain[terrainType].pullSpeed/TPS) * Cos(Terrain[terrainType].pullDirection*bj_DEGTORAD), y + (Terrain[terrainType].pullSpeed/TPS) * Sin(Terrain[terrainType].pullDirection*bj_DEGTORAD))
else
call SetUnitX(slider, x + (Terrain[terrainType].pullSpeed/TPS) * Cos(Terrain[terrainType].pullDirection*bj_DEGTORAD))
call SetUnitY(slider, y + (Terrain[terrainType].pullSpeed/TPS) * Sin(Terrain[terrainType].pullDirection*bj_DEGTORAD))
endif
endif
// Make slider unmoveable while sliding.
call SetUnitPropWindow(slider, 0)
call SetUnitTurnSpeed(slider, 0.00)
endif
else
// Make slider moveable.
call SetUnitPropWindow(slider, propWindow )
call SetUnitTurnSpeed(slider, turnSpeed)
endif
endif
set this = next
endloop
endmethod
/*
* Sliding - Steering
*/
private static method onTurn takes nothing returns boolean
local unit u = GetTriggerUnit()
local real x
local real y
local integer terrainType
local integer order = GetIssuedOrderId()
local boolean b = true
if (isUnitSlider(u) and list[GetUnitUserData(u)].enabled) then
set x = GetUnitX(u)
set y = GetUnitY(u)
set terrainType = GetTerrainType(x, y)
// Check if slider is on a registered terrain type.
if (Terrain[terrainType] != 0) then
if( (order == SMART) and (Terrain[terrainType].allowSteer)) then
// Let the slider turn.
call SetUnitFacing( u, (Atan2(GetOrderPointY() - y , GetOrderPointX() - x) * bj_RADTODEG) + Terrain[terrainType].angle)
elseif ((order != SMART) and (order != MOVE) and (order != PATROL) and (Terrain[terrainType].allowCast)) then
// The slider is casting an ability. Let him face wanted position, if allowed.
call SetUnitFacing( u, Atan2(GetOrderPointY() - y , GetOrderPointX() - x) * bj_RADTODEG)
set b = false
endif
if ((order == SMART) or (order == MOVE) or (order == PATROL) or (b)) then
call DisableTrigger( steerTrigger )
call PauseUnit (u,true)
call IssueImmediateOrderById(u, STOP) // That will abbort unit's order if unit is not casting.
call PauseUnit (u,false)
call EnableTrigger( steerTrigger )
endif
endif
endif
set u = null
return false
endmethod
// API - Start
static method getSliderId takes unit u returns thistype
return list[GetUnitUserData(u)]
endmethod
static method isUnitSlider takes unit u returns boolean
return is[GetUnitUserData(u)]
endmethod
method enable takes boolean b returns nothing
set enabled = b
endmethod
method isEnabled takes nothing returns boolean
return enabled
endmethod
method getDefaultSpeed takes nothing returns real
return defaultSpeed*TPS
endmethod
method getTempSpeed takes nothing returns real
return bonusSpeed*TPS
endmethod
/* Permanent Boost */
method setDefaultSpeed takes real s returns nothing
set defaultSpeed = s/TPS
endmethod
method addDefaultSpeed takes real s returns nothing
set defaultSpeed = defaultSpeed + s/TPS
endmethod
/* Temporary Boost */
private static method callback takes nothing returns nothing
local Acceleration this = GetTimerData(GetExpiredTimer())
set this.instance.bonusSpeed = this.instance.bonusSpeed - this.speedChange
call this.destroy()
endmethod
method addTempSpeed takes real speed, real duration returns nothing
local integer handleId
local Acceleration newData
if duration > 0 then
set speed = speed/TPS
set bonusSpeed = bonusSpeed + speed
set newData = Acceleration.create(this, speed)
set newData.tim = NewTimerEx(newData)
call TimerStart(newData.tim, duration, false, function thistype.callback)
else
debug call BJDebugMsg("Error - Sliding System - AddTempSpeed: Duration must be greater 0.")
endif
endmethod
// API - End
private static method onDeindex takes nothing returns boolean
if (thistype.isUnitSlider(GetIndexedUnit())) then
call thistype.getSliderId(GetIndexedUnit()).destroy()
endif
return false
endmethod
private static method onInit takes nothing returns nothing
call TriggerRegisterAnyUnitEventBJ( steerTrigger, EVENT_PLAYER_UNIT_ISSUED_POINT_ORDER )
call TriggerAddCondition(steerTrigger, Condition(function thistype.onTurn))
call TriggerRegisterTimerEvent(moveTrigger, INTERVAL, true)
call TriggerAddAction(moveTrigger, function thistype.onMove)
call DisableTrigger(moveTrigger)
call RegisterUnitIndexEvent(Condition(function thistype.onDeindex), UnitIndexer.DEINDEX)
endmethod
endstruct
endlibrary
//TESH.scrollpos=0
//TESH.alwaysfold=0
library Table /* made by Bribe, special thanks to Vexorian & Nestharus, version 3.1.1.0
One map, one hashtable. Welcome to NewTable 3.1
This library was originally called NewTable so it didn't conflict with
the API of Table by Vexorian. However, the damage is done and it's too
late to change the library name now. To help with damage control, I
have provided an extension library called TableBC, which bridges all
the functionality of Vexorian's Table except for 2-D string arrays &
the ".flush(integer)" method. I use ".flush()" to flush a child hash-
table, because I wanted the API in NewTable to reflect the API of real
hashtables (I thought this would be more intuitive).
API
------------
struct Table
| static method create takes nothing returns Table
| create a new Table
|
| method destroy takes nothing returns nothing
| destroy it
|
| method flush takes nothing returns nothing
| flush all stored values inside of it
|
| method remove takes integer key returns nothing
| remove the value at index "key"
|
| method operator []= takes integer key, $TYPE$ value returns nothing
| assign "value" to index "key"
|
| method operator [] takes integer key returns $TYPE$
| load the value at index "key"
|
| method has takes integer key returns boolean
| whether or not the key was assigned
|
----------------
struct TableArray
| static method operator [] takes integer array_size returns TableArray
| create a new array of Tables of size "array_size"
|
| method destroy takes nothing returns nothing
| destroy it
|
| method flush takes nothing returns nothing
| flush and destroy it
|
| method operator size takes nothing returns integer
| returns the size of the TableArray
|
| method operator [] takes integer key returns Table
| returns a Table accessible exclusively to index "key"
*/
globals
private integer less = 0 //Index generation for TableArrays (below 0).
private integer more = 8190 //Index generation for Tables.
//Configure it if you use more than 8190 "key" variables in your map (this will never happen though).
private hashtable ht = InitHashtable()
private key sizeK
private key listK
endglobals
private struct dex extends array
static method operator size takes nothing returns Table
return sizeK
endmethod
static method operator list takes nothing returns Table
return listK
endmethod
endstruct
private struct handles extends array
method has takes integer key returns boolean
return HaveSavedHandle(ht, this, key)
endmethod
method remove takes integer key returns nothing
call RemoveSavedHandle(ht, this, key)
endmethod
endstruct
private struct agents extends array
method operator []= takes integer key, agent value returns nothing
call SaveAgentHandle(ht, this, key, value)
endmethod
endstruct
//! textmacro NEW_ARRAY_BASIC takes SUPER, FUNC, TYPE
private struct $TYPE$s extends array
method operator [] takes integer key returns $TYPE$
return Load$FUNC$(ht, this, key)
endmethod
method operator []= takes integer key, $TYPE$ value returns nothing
call Save$FUNC$(ht, this, key, value)
endmethod
method has takes integer key returns boolean
return HaveSaved$SUPER$(ht, this, key)
endmethod
method remove takes integer key returns nothing
call RemoveSaved$SUPER$(ht, this, key)
endmethod
endstruct
private module $TYPE$m
method operator $TYPE$ takes nothing returns $TYPE$s
return this
endmethod
endmodule
//! endtextmacro
//! textmacro NEW_ARRAY takes FUNC, TYPE
private struct $TYPE$s extends array
method operator [] takes integer key returns $TYPE$
return Load$FUNC$Handle(ht, this, key)
endmethod
method operator []= takes integer key, $TYPE$ value returns nothing
call Save$FUNC$Handle(ht, this, key, value)
endmethod
method has takes integer key returns boolean
return HaveSavedHandle(ht, this, key)
endmethod
method remove takes integer key returns nothing
call RemoveSavedHandle(ht, this, key)
endmethod
endstruct
private module $TYPE$m
method operator $TYPE$ takes nothing returns $TYPE$s
return this
endmethod
endmodule
//! endtextmacro
//Run these textmacros to include the entire hashtable API as wrappers.
//Don't be intimidated by the number of macros - Vexorian's map optimizer is
//supposed to kill functions which inline (all of these functions inline).
//! runtextmacro NEW_ARRAY_BASIC("Real", "Real", "real")
//! runtextmacro NEW_ARRAY_BASIC("Boolean", "Boolean", "boolean")
//! runtextmacro NEW_ARRAY_BASIC("String", "Str", "string")
//New textmacro to allow table.integer[] syntax for compatibility with textmacros that might desire it.
//! runtextmacro NEW_ARRAY_BASIC("Integer", "Integer", "integer")
//! runtextmacro NEW_ARRAY("Player", "player")
//! runtextmacro NEW_ARRAY("Widget", "widget")
//! runtextmacro NEW_ARRAY("Destructable", "destructable")
//! runtextmacro NEW_ARRAY("Item", "item")
//! runtextmacro NEW_ARRAY("Unit", "unit")
//! runtextmacro NEW_ARRAY("Ability", "ability")
//! runtextmacro NEW_ARRAY("Timer", "timer")
//! runtextmacro NEW_ARRAY("Trigger", "trigger")
//! runtextmacro NEW_ARRAY("TriggerCondition", "triggercondition")
//! runtextmacro NEW_ARRAY("TriggerAction", "triggeraction")
//! runtextmacro NEW_ARRAY("TriggerEvent", "event")
//! runtextmacro NEW_ARRAY("Force", "force")
//! runtextmacro NEW_ARRAY("Group", "group")
//! runtextmacro NEW_ARRAY("Location", "location")
//! runtextmacro NEW_ARRAY("Rect", "rect")
//! runtextmacro NEW_ARRAY("BooleanExpr", "boolexpr")
//! runtextmacro NEW_ARRAY("Sound", "sound")
//! runtextmacro NEW_ARRAY("Effect", "effect")
//! runtextmacro NEW_ARRAY("UnitPool", "unitpool")
//! runtextmacro NEW_ARRAY("ItemPool", "itempool")
//! runtextmacro NEW_ARRAY("Quest", "quest")
//! runtextmacro NEW_ARRAY("QuestItem", "questitem")
//! runtextmacro NEW_ARRAY("DefeatCondition", "defeatcondition")
//! runtextmacro NEW_ARRAY("TimerDialog", "timerdialog")
//! runtextmacro NEW_ARRAY("Leaderboard", "leaderboard")
//! runtextmacro NEW_ARRAY("Multiboard", "multiboard")
//! runtextmacro NEW_ARRAY("MultiboardItem", "multiboarditem")
//! runtextmacro NEW_ARRAY("Trackable", "trackable")
//! runtextmacro NEW_ARRAY("Dialog", "dialog")
//! runtextmacro NEW_ARRAY("Button", "button")
//! runtextmacro NEW_ARRAY("TextTag", "texttag")
//! runtextmacro NEW_ARRAY("Lightning", "lightning")
//! runtextmacro NEW_ARRAY("Image", "image")
//! runtextmacro NEW_ARRAY("Ubersplat", "ubersplat")
//! runtextmacro NEW_ARRAY("Region", "region")
//! runtextmacro NEW_ARRAY("FogState", "fogstate")
//! runtextmacro NEW_ARRAY("FogModifier", "fogmodifier")
//! runtextmacro NEW_ARRAY("Hashtable", "hashtable")
struct Table extends array
// Implement modules for intuitive syntax (tb.handle; tb.unit; etc.)
implement realm
implement integerm
implement booleanm
implement stringm
implement playerm
implement widgetm
implement destructablem
implement itemm
implement unitm
implement abilitym
implement timerm
implement triggerm
implement triggerconditionm
implement triggeractionm
implement eventm
implement forcem
implement groupm
implement locationm
implement rectm
implement boolexprm
implement soundm
implement effectm
implement unitpoolm
implement itempoolm
implement questm
implement questitemm
implement defeatconditionm
implement timerdialogm
implement leaderboardm
implement multiboardm
implement multiboarditemm
implement trackablem
implement dialogm
implement buttonm
implement texttagm
implement lightningm
implement imagem
implement ubersplatm
implement regionm
implement fogstatem
implement fogmodifierm
implement hashtablem
method operator handle takes nothing returns handles
return this
endmethod
method operator agent takes nothing returns agents
return this
endmethod
//set this = tb[GetSpellAbilityId()]
method operator [] takes integer key returns Table
return LoadInteger(ht, this, key) //return this.integer[key]
endmethod
//set tb[389034] = 8192
method operator []= takes integer key, Table tb returns nothing
call SaveInteger(ht, this, key, tb) //set this.integer[key] = tb
endmethod
//set b = tb.has(2493223)
method has takes integer key returns boolean
return HaveSavedInteger(ht, this, key) //return this.integer.has(key)
endmethod
//call tb.remove(294080)
method remove takes integer key returns nothing
call RemoveSavedInteger(ht, this, key) //call this.integer.remove(key)
endmethod
//Remove all data from a Table instance
method flush takes nothing returns nothing
call FlushChildHashtable(ht, this)
endmethod
//local Table tb = Table.create()
static method create takes nothing returns Table
local Table this = dex.list[0]
if this == 0 then
set this = more + 1
set more = this
else
set dex.list[0] = dex.list[this]
call dex.list.remove(this) //Clear hashed memory
endif
debug set dex.list[this] = -1
return this
endmethod
// Removes all data from a Table instance and recycles its index.
//
// call tb.destroy()
//
method destroy takes nothing returns nothing
debug if dex.list[this] != -1 then
debug call BJDebugMsg("Table Error: Tried to double-free instance: " + I2S(this))
debug return
debug endif
call this.flush()
set dex.list[this] = dex.list[0]
set dex.list[0] = this
endmethod
//! runtextmacro optional TABLE_BC_METHODS()
endstruct
//! runtextmacro optional TABLE_BC_STRUCTS()
struct TableArray extends array
//Returns a new TableArray to do your bidding. Simply use:
//
// local TableArray ta = TableArray[array_size]
//
static method operator [] takes integer array_size returns TableArray
local Table tb = dex.size[array_size] //Get the unique recycle list for this array size
local TableArray this = tb[0] //The last-destroyed TableArray that had this array size
debug if array_size <= 0 then
debug call BJDebugMsg("TypeError: Invalid specified TableArray size: " + I2S(array_size))
debug return 0
debug endif
if this == 0 then
set this = less - array_size
set less = this
else
set tb[0] = tb[this] //Set the last destroyed to the last-last destroyed
call tb.remove(this) //Clear hashed memory
endif
set dex.size[this] = array_size //This remembers the array size
return this
endmethod
//Returns the size of the TableArray
method operator size takes nothing returns integer
return dex.size[this]
endmethod
//This magic method enables two-dimensional[array][syntax] for Tables,
//similar to the two-dimensional utility provided by hashtables them-
//selves.
//
//ta[integer a].unit[integer b] = unit u
//ta[integer a][integer c] = integer d
//
//Inline-friendly when not running in debug mode
//
method operator [] takes integer key returns Table
static if DEBUG_MODE then
local integer i = this.size
if i == 0 then
call BJDebugMsg("IndexError: Tried to get key from invalid TableArray instance: " + I2S(this))
return 0
elseif key < 0 or key >= i then
call BJDebugMsg("IndexError: Tried to get key [" + I2S(key) + "] from outside TableArray bounds: " + I2S(i))
return 0
endif
endif
return this + key
endmethod
//Destroys a TableArray without flushing it; I assume you call .flush()
//if you want it flushed too. This is a public method so that you don't
//have to loop through all TableArray indices to flush them if you don't
//need to (ie. if you were flushing all child-keys as you used them).
//
method destroy takes nothing returns nothing
local Table tb = dex.size[this.size]
debug if this.size == 0 then
debug call BJDebugMsg("TypeError: Tried to destroy an invalid TableArray: " + I2S(this))
debug return
debug endif
if tb == 0 then
//Create a Table to index recycled instances with their array size
set tb = Table.create()
set dex.size[this.size] = tb
endif
call dex.size.remove(this) //Clear the array size from hash memory
set tb[this] = tb[0]
set tb[0] = this
endmethod
private static Table tempTable
private static integer tempEnd
//Avoids hitting the op limit
private static method clean takes nothing returns nothing
local Table tb = .tempTable
local integer end = tb + 0x1000
if end < .tempEnd then
set .tempTable = end
call ForForce(bj_FORCE_PLAYER[0], function thistype.clean)
else
set end = .tempEnd
endif
loop
call tb.flush()
set tb = tb + 1
exitwhen tb == end
endloop
endmethod
//Flushes the TableArray and also destroys it. Doesn't get any more
//similar to the FlushParentHashtable native than this.
//
method flush takes nothing returns nothing
debug if this.size == 0 then
debug call BJDebugMsg("TypeError: Tried to flush an invalid TableArray instance: " + I2S(this))
debug return
debug endif
set .tempTable = this
set .tempEnd = this + this.size
call ForForce(bj_FORCE_PLAYER[0], function thistype.clean)
call this.destroy()
endmethod
endstruct
endlibrary
//TESH.scrollpos=15
//TESH.alwaysfold=0
library UnitIndexer /* v4.0.2.6
*************************************************************************************
*
* 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/
*
************************************************************************************
*
* 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,'Adef',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)]) then
if (0==y) then
set r=r+1
set i=r
else
set i=y
set y=n[y]
endif
call UnitAddAbility(Q,'Adef')
call UnitMakeAbilityPermanent(Q,true,'Adef')
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,'Adef') 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,'Adef')
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=0
//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
//TESH.scrollpos=0
//TESH.alwaysfold=0
library TimerUtils initializer init
//*********************************************************************
//* TimerUtils (red+blue+orange flavors for 1.24b+) 2.0
//* ----------
//*
//* To implement it , create a custom text trigger called TimerUtils
//* and paste the contents of this script there.
//*
//* To copy from a map to another, copy the trigger holding this
//* library to your map.
//*
//* (requires vJass) More scripts: htt://www.wc3c.net
//*
//* For your timer needs:
//* * Attaching
//* * Recycling (with double-free protection)
//*
//* set t=NewTimer() : Get a timer (alternative to CreateTimer)
//* set t=NewTimerEx(x) : Get a timer (alternative to CreateTimer), call
//* Initialize timer data as x, instead of 0.
//*
//* ReleaseTimer(t) : Relese a timer (alt to DestroyTimer)
//* SetTimerData(t,2) : Attach value 2 to timer
//* GetTimerData(t) : Get the timer's value.
//* You can assume a timer's value is 0
//* after NewTimer.
//*
//* Multi-flavor:
//* Set USE_HASH_TABLE to true if you don't want to complicate your life.
//*
//* If you like speed and giberish try learning about the other flavors.
//*
//********************************************************************
//================================================================
globals
//How to tweak timer utils:
// USE_HASH_TABLE = true (new blue)
// * SAFEST
// * SLOWEST (though hash tables are kind of fast)
//
// USE_HASH_TABLE = false, USE_FLEXIBLE_OFFSET = true (orange)
// * kinda safe (except there is a limit in the number of timers)
// * ALMOST FAST
//
// USE_HASH_TABLE = false, USE_FLEXIBLE_OFFSET = false (red)
// * THE FASTEST (though is only faster than the previous method
// after using the optimizer on the map)
// * THE LEAST SAFE ( you may have to tweak OFSSET manually for it to
// work)
//
private constant boolean USE_HASH_TABLE = true
private constant boolean USE_FLEXIBLE_OFFSET = false
private constant integer OFFSET = 0x100000
private integer VOFFSET = OFFSET
//Timers to preload at map init:
private constant integer QUANTITY = 256
//Changing this to something big will allow you to keep recycling
// timers even when there are already AN INCREDIBLE AMOUNT of timers in
// the stack. But it will make things far slower so that's probably a bad idea...
private constant integer ARRAY_SIZE = 8190
endglobals
//==================================================================================================
globals
private integer array data[ARRAY_SIZE]
private hashtable ht
endglobals
//It is dependent on jasshelper's recent inlining optimization in order to perform correctly.
function SetTimerData takes timer t, integer value returns nothing
static if(USE_HASH_TABLE) then
// new blue
call SaveInteger(ht,0,GetHandleId(t), value)
elseif (USE_FLEXIBLE_OFFSET) then
// orange
static if (DEBUG_MODE) then
if(GetHandleId(t)-VOFFSET<0) then
call BJDebugMsg("SetTimerData: Wrong handle id, only use SetTimerData on timers created by NewTimer")
endif
endif
set data[GetHandleId(t)-VOFFSET]=value
else
// new red
static if (DEBUG_MODE) then
if(GetHandleId(t)-OFFSET<0) then
call BJDebugMsg("SetTimerData: Wrong handle id, only use SetTimerData on timers created by NewTimer")
endif
endif
set data[GetHandleId(t)-OFFSET]=value
endif
endfunction
function GetTimerData takes timer t returns integer
static if(USE_HASH_TABLE) then
// new blue
return LoadInteger(ht,0,GetHandleId(t) )
elseif (USE_FLEXIBLE_OFFSET) then
// orange
static if (DEBUG_MODE) then
if(GetHandleId(t)-VOFFSET<0) then
call BJDebugMsg("SetTimerData: Wrong handle id, only use SetTimerData on timers created by NewTimer")
endif
endif
return data[GetHandleId(t)-VOFFSET]
else
// new red
static if (DEBUG_MODE) then
if(GetHandleId(t)-OFFSET<0) then
call BJDebugMsg("SetTimerData: Wrong handle id, only use SetTimerData on timers created by NewTimer")
endif
endif
return data[GetHandleId(t)-OFFSET]
endif
endfunction
//==========================================================================================
globals
private timer array tT[ARRAY_SIZE]
private integer tN = 0
private constant integer HELD=0x28829022
//use a totally random number here, the more improbable someone uses it, the better.
private boolean didinit = false
endglobals
private keyword init
//==========================================================================================
// I needed to decide between duplicating code ignoring the "Once and only once" rule
// and using the ugly textmacros. I guess textmacros won.
//
//! textmacro TIMERUTIS_PRIVATE_NewTimerCommon takes VALUE
// On second thought, no.
//! endtextmacro
function NewTimerEx takes integer value returns timer
if (tN==0) then
if (not didinit) then
//This extra if shouldn't represent a major performance drawback
//because QUANTITY rule is not supposed to be broken every day.
call init.evaluate()
set tN = tN - 1
else
//If this happens then the QUANTITY rule has already been broken, try to fix the
// issue, else fail.
debug call BJDebugMsg("NewTimer: Warning, Exceeding TimerUtils_QUANTITY, make sure all timers are getting recycled correctly")
set tT[0]=CreateTimer()
static if( not USE_HASH_TABLE) then
debug call BJDebugMsg("In case of errors, please increase it accordingly, or set TimerUtils_USE_HASH_TABLE to true")
static if( USE_FLEXIBLE_OFFSET) then
if (GetHandleId(tT[0])-VOFFSET<0) or (GetHandleId(tT[0])-VOFFSET>=ARRAY_SIZE) then
//all right, couldn't fix it
call BJDebugMsg("NewTimer: Unable to allocate a timer, you should probably set TimerUtils_USE_HASH_TABLE to true or fix timer leaks.")
return null
endif
else
if (GetHandleId(tT[0])-OFFSET<0) or (GetHandleId(tT[0])-OFFSET>=ARRAY_SIZE) then
//all right, couldn't fix it
call BJDebugMsg("NewTimer: Unable to allocate a timer, you should probably set TimerUtils_USE_HASH_TABLE to true or fix timer leaks.")
return null
endif
endif
endif
endif
else
set tN=tN-1
endif
call SetTimerData(tT[tN],value)
return tT[tN]
endfunction
function NewTimer takes nothing returns timer
return NewTimerEx(0)
endfunction
//==========================================================================================
function ReleaseTimer takes timer t returns nothing
if(t==null) then
debug call BJDebugMsg("Warning: attempt to release a null timer")
return
endif
if (tN==ARRAY_SIZE) then
debug call BJDebugMsg("Warning: Timer stack is full, destroying timer!!")
//stack is full, the map already has much more troubles than the chance of bug
call DestroyTimer(t)
else
call PauseTimer(t)
if(GetTimerData(t)==HELD) then
debug call BJDebugMsg("Warning: ReleaseTimer: Double free!")
return
endif
call SetTimerData(t,HELD)
set tT[tN]=t
set tN=tN+1
endif
endfunction
private function init takes nothing returns nothing
local integer i=0
local integer o=-1
local boolean oops = false
if ( didinit ) then
return
else
set didinit = true
endif
static if( USE_HASH_TABLE ) then
set ht = InitHashtable()
loop
exitwhen(i==QUANTITY)
set tT[i]=CreateTimer()
call SetTimerData(tT[i], HELD)
set i=i+1
endloop
set tN = QUANTITY
else
loop
set i=0
loop
exitwhen (i==QUANTITY)
set tT[i] = CreateTimer()
if(i==0) then
set VOFFSET = GetHandleId(tT[i])
static if(USE_FLEXIBLE_OFFSET) then
set o=VOFFSET
else
set o=OFFSET
endif
endif
if (GetHandleId(tT[i])-o>=ARRAY_SIZE) then
exitwhen true
endif
if (GetHandleId(tT[i])-o>=0) then
set i=i+1
endif
endloop
set tN = i
exitwhen(tN == QUANTITY)
set oops = true
exitwhen not USE_FLEXIBLE_OFFSET
debug call BJDebugMsg("TimerUtils_init: Failed a initialization attempt, will try again")
endloop
if(oops) then
static if ( USE_FLEXIBLE_OFFSET) then
debug call BJDebugMsg("The problem has been fixed.")
//If this message doesn't appear then there is so much
//handle id fragmentation that it was impossible to preload
//so many timers and the thread crashed! Therefore this
//debug message is useful.
elseif(DEBUG_MODE) then
call BJDebugMsg("There were problems and the new timer limit is "+I2S(i))
call BJDebugMsg("This is a rare ocurrence, if the timer limit is too low:")
call BJDebugMsg("a) Change USE_FLEXIBLE_OFFSET to true (reduces performance a little)")
call BJDebugMsg("b) or try changing OFFSET to "+I2S(VOFFSET) )
endif
endif
endif
endfunction
endlibrary
//TESH.scrollpos=0
//TESH.alwaysfold=0
library Event
globals
private real q=0
endglobals
struct Event extends array
readonly static thistype last = 0
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 GetHandleId(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
local thistype p = thistype.last
set thistype.last = this
set q=0
set q=this
call TriggerEvaluate(e[this])
set thistype.last = p
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=0
//TESH.alwaysfold=0
scope spawn initializer Init
globals
real spawnX = -1500
real spawnY = 2000
endglobals
private function Death takes nothing returns nothing
call ReviveHero(GetTriggerUnit(), spawnX, spawnY, false)
call SelectUnit(GetTriggerUnit(), true)
endfunction
private function Init takes nothing returns nothing
local trigger t = CreateTrigger( )
call TriggerRegisterAnyUnitEventBJ( t, EVENT_PLAYER_UNIT_DEATH )
call TriggerAddAction( t, function Death )
endfunction
endscope
//TESH.scrollpos=0
//TESH.alwaysfold=0
scope test initializer Init
globals
Slider hero
endglobals
private function Init takes nothing returns nothing
local unit u = CreateUnit(Player(0), 'E000', spawnX, spawnY, 270)
set hero = Slider.create(u)
call SetCameraTargetController(u, 0, 0, false)
call SelectUnit(u, true)
// Add 200 additional speed for 5 seconds.
call hero.addTempSpeed(200, 5)
// Set the defaultSpeed to 50. (can be used, if unit picks up boots for example)
call hero.setDefaultSpeed(50)
set u = null
endfunction
endscope
//TESH.scrollpos=0
//TESH.alwaysfold=0
scope Abilities initializer Init
globals
private constant integer BOOST_ID = 'A000'
private constant real SPEED = 300
private constant real DURATION = 1
endglobals
private function Cast takes nothing returns boolean
if GetSpellAbilityId() == BOOST_ID then
call hero.addTempSpeed(SPEED, DURATION) // Temporary adds 250 speed.
endif
return false
endfunction
private function Init takes nothing returns nothing
local trigger t = CreateTrigger()
call TriggerRegisterAnyUnitEventBJ( t, EVENT_PLAYER_UNIT_SPELL_CAST )
call TriggerAddCondition(t, Filter(function Cast))
endfunction
endscope
//TESH.scrollpos=39
//TESH.alwaysfold=0
scope TerrainSettings initializer Init
globals
/*
* I use my own variables, but the file "Terrain Types"
* provides all types of terrain via globals.
*/
integer normal_fast = 'Iice'
integer mirror_slow = 'Glvc'
integer snow = 'Nsnw'
integer normal = 'Nice'
integer mirror = 'Glav'
integer dark = 'Idki'
endglobals
private function Init takes nothing returns nothing
/*
* Follow this structure:
*
* call Terrain.create(terainType, terrainSpeed)
*
* After you created a new instance, you have the possibility to define more aspects for the sliding behaviour.
*
* Full list of data you can configurate for the terrain:
* (by default all values are "0" or "false".
*
* pullSpeed = Unit will be constantly pulled with this speed. (real)
* pullDirection = Direction for pulling, in degrees. (real)
* angle = Angle that will be added, when steering. (real)
* lifeAddition = Life that will be added each second. Negagtive values are also possible. (real)
* allowSteer = If unit can steer on the tarrainType or not. (boolean)
* allowCast = If unit can cast on the terrainType or not. (boolean)
* kill = Kill the unit on the terrainType or not. (boolean)
*
*/
// Normal sliding, healing, casting allowed.
call Terrain.create(normal, 350.)
set Terrain[normal].allowSteer = true
set Terrain[normal].lifeAddition = 10.
set Terrain[normal].allowCast = true
// Normal sldiing, fast.
call Terrain.create(normal_fast, 600.)
set Terrain[normal_fast].allowSteer = true
// Reverse sliding, damaging, casting allowed.
call Terrain.create(mirror, 350.)
set Terrain[mirror].allowSteer = true
set Terrain[mirror].angle = 180.
set Terrain[mirror].lifeAddition = -10.
set Terrain[mirror].allowCast = true
// Slower reverse slding, with a pulling towards 270 degrees.
call Terrain.create(mirror_slow, 250.)
set Terrain[mirror_slow].allowSteer = true
set Terrain[mirror_slow].angle = 180.
set Terrain[mirror_slow].pullSpeed = 100.
set Terrain[mirror_slow].pullDirection = 270.
// Unsteerable terrain, with normal sliding speed.
call Terrain.create(dark, 350.)
// Killer terrain.
call Terrain.create(snow, 0.)
set Terrain[snow].kill = true
endfunction
endscope
//TESH.scrollpos=57
//TESH.alwaysfold=0
//-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
//-=-=-= Terrain Type Constants by Darthfett =-=-=-=-=-
//-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
//-=-=-=-= Thanks to Romek for the Raw Codes -=-=-=-=-
//-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
scope LORDAERONSUMMER
// Lordaeron Summer
globals
public constant integer DIRT = 'Ldrt'
public constant integer ROUGH_DIRT = 'Ldro'
public constant integer GRASSY_DIRT = 'Ldrg'
public constant integer ROCK = 'Lrok'
public constant integer GRASS = 'Lgrs'
public constant integer DARK_GRASS = 'Lgrd'
public constant integer DIRT_CLIFF = 'cLc2'
public constant integer GRASS_CLIFF = 'cLc1'
endglobals
endscope
scope LORDAERONFALL
// Lordaeron Fall
globals
public constant integer DIRT = 'Fdrt'
public constant integer ROUGH_DIRT = 'Fdro'
public constant integer GRASSY_DIRT = 'Fdrg'
public constant integer ROCK = 'Frok'
public constant integer GRASS = 'Fgrs'
public constant integer DARK_GRASS = 'Fgrd'
public constant integer DIRT_CLIFF = 'cFc2'
public constant integer GRASS_CLIFF = 'cFc1'
endglobals
endscope
scope LORDAERONWINTER
// Lordaeron Winter
globals
public constant integer DIRT = 'Wdrt'
public constant integer ROUGH_DIRT = 'Wdro'
public constant integer GRASSY_SNOW = 'Wsng'
public constant integer ROCK = 'Wrok'
public constant integer GRASS = 'Wgrs'
public constant integer SNOW = 'Wsnw'
public constant integer GRASS_CLIFF = 'cWc2'
public constant integer SNOW_CLIFF = 'cWc1'
endglobals
endscope
scope BARRENS
// Barrens
globals
public constant integer DIRT = 'Bdrt'
public constant integer ROUGH_DIRT = 'Bdrh'
public constant integer PEBBLES = 'Bdrr'
public constant integer GRASSY_DIRT = 'Bdrg'
public constant integer DESERT = 'Bdsr'
public constant integer DARK_DESERT = 'Bdsd'
public constant integer ROCK = 'Bflr'
public constant integer GRASS = 'Bgrr'
public constant integer DESERT_CLIFF = 'cBc2'
public constant integer GRASS_CLIFF = 'cBc1'
endglobals
endscope
scope ASHENVALE
// Ashenvale
globals
public constant integer DIRT = 'Adrt'
public constant integer ROUGH_DIRT = 'Adrd'
public constant integer GRASS = 'Agrs'
public constant integer ROCK = 'Arck'
public constant integer LUMPY_GRASS = 'Agrd'
public constant integer VINES = 'Avin'
public constant integer GRASSY_DIRT = 'Adrg'
public constant integer LEAVES = 'Alvd'
public constant integer DIRT_CLIFF = 'cAc2'
public constant integer GRASS_CLIFF = 'cAc1'
endglobals
endscope
scope FELWOOD
// Felwood
globals
public constant integer DIRT = 'Cdrt'
public constant integer ROUGH_DIRT = 'Cdrd'
public constant integer POISON = 'Cpos'
public constant integer ROCK = 'Crck'
public constant integer VINES = 'Cvin'
public constant integer GRASS = 'Cgrs'
public constant integer LEAVES = 'Clvg'
public constant integer DIRT_CLIFF = 'cCc2'
public constant integer GRASS_CLIFF = 'cCc1'
endglobals
endscope
scope NORTHREND
// Northrend
globals
public constant integer DIRT = 'Ndrt'
public constant integer DARK_DIRT = 'Ndrd'
public constant integer ROCK = 'Nrck'
public constant integer GRASS = 'Ngrs'
public constant integer ICE = 'Nice'
public constant integer SNOW = 'Nsnw'
public constant integer ROCKY_SNOW = 'Nsnr'
public constant integer DIRT_CLIFF = 'cNc2'
public constant integer SNOW_CLIFF = 'cNc1'
endglobals
endscope
scope CITYSCAPE
// Cityscape
globals
public constant integer DIRT = 'Ydrt'
public constant integer ROUGH_DIRT = 'Ydtr'
public constant integer BLACK_MARBLE = 'Yblm'
public constant integer BRICK = 'Ybtl'
public constant integer SQUARE_TILES = 'Ysqd'
public constant integer ROUND_TILES = 'Yrtl'
public constant integer GRASS = 'Ygsb'
public constant integer GRASS_TRIM = 'Yhdg'
public constant integer WHITE_MARBLE = 'Ywmb'
public constant integer DIRT_CLIFF = 'cYc2'
public constant integer SQUARE_TILES_CLIFF = 'cYc1'
endglobals
endscope
scope VILLAGE
// Village
globals
public constant integer DIRT = 'Vdrt'
public constant integer ROUGH_DIRT = 'Vdrr'
public constant integer CROPS = 'Vcrp'
public constant integer COBBLE_PATH = 'Vcbp'
public constant integer STONE_PATH = 'Vstp'
public constant integer SHORT_GRASS = 'Vgrs'
public constant integer ROCKS = 'Vrck'
public constant integer THICK_GRASS = 'Vgrt'
public constant integer DIRT_CLIFF = 'cVc2'
public constant integer GRASS_THICK_CLIFF = 'cVc1'
endglobals
endscope
scope VILLAGEFALL
// Village Fall
globals
public constant integer DIRT = 'Qdrt'
public constant integer ROUGH_DIRT = 'Qdrr'
public constant integer CROPS = 'Qcrp'
public constant integer COBBLE_PATH = 'Qcbp'
public constant integer STONE_PATH = 'Qstp'
public constant integer SHORT_GRASS = 'Qgrs'
public constant integer ROCKS = 'Qrck'
public constant integer THICK_GRASS = 'Qgrt'
public constant integer DIRT_CLIFF = 'cQc2'
public constant integer GRASS_THICK_CLIFF = 'cQc1'
endglobals
endscope
scope DALARAN
// Dalaran
globals
public constant integer DIRT = 'Xdrt'
public constant integer ROUGH_DIRT = 'Xdtr'
public constant integer BLACK_MARBLE = 'Xblm'
public constant integer BRICK_TILES = 'Xbtl'
public constant integer SQUARE_TILES = 'Xsqd'
public constant integer ROUND_TILES = 'Xrtl'
public constant integer GRASS = 'Xgsb'
public constant integer TRIM_GRASS = 'Xhdg'
public constant integer WHITE_MARBLE = 'Xwmb'
public constant integer DIRT_CLIFF = 'cXc2'
public constant integer SQUARE_TILES_CLIFF = 'cXc1'
endglobals
endscope
scope DUNGEON
// Dungeon
globals
public constant integer DIRT = 'Ddrt'
public constant integer BRICK = 'Dbrk'
public constant integer RED_STONES = 'Drds'
public constant integer LAVA_CRACKS = 'Dlvc'
public constant integer LAVA = 'Dlav'
public constant integer DARK_ROCKS = 'Ddkr'
public constant integer GREY_STONES = 'Dgrs'
public constant integer SQUARE_TILES = 'Dsqd'
public constant integer DIRT_CLIFF = 'cDc2'
public constant integer SQUARE_TILES_CLIFF = 'cDc1'
endglobals
endscope
scope UNDERGROUND
// Underground
globals
public constant integer DIRT = 'Gdrt'
public constant integer BRICK = 'Gbrk'
public constant integer RED_STONES = 'Grds'
public constant integer LAVA_CRACKS = 'Glvc'
public constant integer LAVA = 'Glav'
public constant integer DARK_ROCKS = 'Gdkr'
public constant integer GREY_STONES = 'Ggrs'
public constant integer SQUARE_TILES = 'Gsqd'
public constant integer DIRT_CLIFF = 'cGc2'
public constant integer SQUARE_TILES_CLIFF = 'cGc1'
endglobals
endscope
scope SUNKENRUINS
// Sunken Ruins
globals
public constant integer DIRT = 'Zdrt'
public constant integer ROUGH_DIRT = 'Zdtr'
public constant integer GRASSY_DIRT = 'Zdrg'
public constant integer SMALL_BRICKS = 'Zbks'
public constant integer SAND = 'Zsan'
public constant integer LARGE_BRICKS = 'Zbkl'
public constant integer ROUND_TILES = 'Ztil'
public constant integer GRASS = 'Zgrs'
public constant integer DARK_GRASS = 'Zvin'
public constant integer DIRT_CLIFF = 'cZc2'
public constant integer LARGE_BRICKS_CLIFF = 'cZc1'
endglobals
endscope
scope ICECROWNGLACIER
// Icecrown Glacier
globals
public constant integer DIRT = 'Idrt'
public constant integer ROUGH_DIRT = 'Idtr'
public constant integer DARK_ICE = 'Idki'
public constant integer BLACK_BRICKS = 'Ibkb'
public constant integer RUNE_BRICKS = 'Irbk'
public constant integer TILED_BRICKS = 'Itbk'
public constant integer ICE = 'Iice'
public constant integer BLACK_SQUARES = 'Ibsq'
public constant integer SNOW = 'Isnw'
public constant integer RUNE_BRICKS_CLIFF = 'cIc2'
public constant integer SNOW_CLIFF = 'cIc1'
endglobals
endscope
scope OUTLAND
// Outland
globals
public constant integer DIRT = 'Odrt'
public constant integer LIGHT_DIRT = 'Odtr'
public constant integer ROUGH_DIRT = 'Osmb'
public constant integer CRACKED_DIRT = 'Ofst'
public constant integer FLAT_STONES = 'Olgb'
public constant integer ROCK = 'Orok'
public constant integer LIGHT_FLAT_STONES = 'Ofsl'
public constant integer ABYSS = 'Oaby'
public constant integer ABYSS_CLIFF = 'cOc1'
public constant integer ROUGH_DIRT_CLIFF = 'cOc2'
endglobals
endscope
scope BLACKCITADEL
// Black Citadel
globals
public constant integer DIRT = 'Kdrt'
public constant integer LIGHT_DIRT = 'Kfsl'
public constant integer ROUGH_DIRT = 'Kdtr'
public constant integer FLAT_STONES = 'Kfst'
public constant integer SMALL_BRICKS = 'Ksmb'
public constant integer LARGE_BRICKS = 'Klgb'
public constant integer SQUARE_TILES = 'Ksqt'
public constant integer DARK_TILES = 'Kdkt'
public constant integer DIRT_CLIFF = 'cKc1'
public constant integer DARK_TILES_CLIFF = 'cKc2'
endglobals
endscope
scope DALARANRUINS
// Dalaran Ruins
globals
public constant integer DIRT = 'Jdrt'
public constant integer ROUGH_DIRT = 'Jdtr'
public constant integer BLACK_MARBLE = 'Jblm'
public constant integer BRICK_TILES = 'Jbtl'
public constant integer SQUARE_TILES = 'Jsqd'
public constant integer ROUND_TILES = 'Jrtl'
public constant integer GRASS = 'Jgsb'
public constant integer TRIM_GRASS = 'Jhdg'
public constant integer WHITE_MARBLE = 'Jwmb'
public constant integer DIRT_CLIFF = 'cJc2'
public constant integer SQUARE_TILES_CLIFF = 'cJc1'
endglobals
endscope