Name | Type | is_array | initial_value |
//TESH.scrollpos=224
//TESH.alwaysfold=0
/*************************************
*
* AtomicBomb
* v3.1.0.1
* By Magtheridon96
*
* - Creates a bombing plane behind the caster
* that will drop an atomic bomb dealing damage
* to enemy units in an area of effect. Deals
* bonus damage to closer units.
*
* Requires:
* ---------
*
* - CTL by Nestharus
* - hiveworkshop.com/forums/jass-resources-412/snippet-constant-timer-loop-32-a-201381/
* - SpellEffectEvent by Bribe
* - hiveworkshop.com/forums/jass-resources-412/snippet-spelleffectevent-187193/
* - Particle by Nestharus
* - hiveworkshop.com/forums/submissions-414/snippet-needs-work-particle-206279/
*
* Optional:
* ---------
*
* - TimerUtils by Vexorian (This also caters to my version of TimerUtils in the Hive Jass section Graveyard)
* - wc3c.net/showthread.php?t=101322
*
* Importing:
* ----------
*
* - Copy this code to a new trigger.
* - Make sure you have all the requirements implemented too.
* - Go the object editor and copy/paste the objects to your map (1 ability, 2 dummy units).
* - There is also an object called Particle that you need which is part of the Particle library.
* - Import the special effect and dummy.mdl to your map.
* - Configure the data in the globals to your liking.
* - Done!
*
* Credits:
* --------
*
* - WILL THE ALMIGHTY (Explosion Effect)
* - Bribe (SpellEffectEvent, Table)
* - Nestharus (CTL, Particle)
* - Vexorian (TimerUtils)
*
*************************************/
library AtomicBomb requires CTL, SpellEffectEvent, Particle, optional TimerUtils
// Configuration
globals
// The ability raw code
private constant integer ABIL_CODE = 'A000'
// The plane dummy unit raw code
private constant integer PLANE_CODE = 'h003'
// The bomb dummy unit raw code
private constant integer BOMB_CODE = 'h001'
// Explosion Effect
private constant string EXPLOSION_EFFECT = "war3mapImported\\NuclearExplosion.mdx"
// The effect that is created when the plane is created.
private constant string PLANE_IN_EFFECT = "Abilities\\Spells\\Items\\TomeOfRetraining\\TomeOfRetrainingCaster.mdl"
// The effect that is created when the plane is destroyed.
private constant string PLANE_OUT_EFFECT = "Abilities\\Spells\\Items\\TomeOfRetraining\\TomeOfRetrainingCaster.mdl"
// How much time should we wait before destroying the explosion effect?
private constant real DESTROY_EXPLOSION_AFTER = 15.
// How much time should we wait before destroying the effect created when the plane is created?
private constant real DESTROY_IN_EFFECT_PARTICLE_AFTER = 1.4
// How much time should we wait before destroying the effect created when the plane is destroyed?
private constant real DESTROY_OUT_EFFECT_PARTICLE_AFTER = 1.4
// Bomb and Plane height
private constant real BOMB_HEIGHT = 700.
// Bomb Drop Speed Base (It will accelerate starting from this base-speed)
private constant real BOMB_DROP_SPEED = 1.
// Bomb Drop Acceleration
private constant real BOMB_DROP_ACCEL = 1.
// The dummy owning player
private constant player DUMMY_OWNER = Player(13)
// Destroy trees around the explosion?
private constant boolean DESTROY_TREES = true
// The offset from the point from the target point for plane creation
private constant real PLANE_DISTANCE = 800.
// How long does the plane stay after it drops the bomb?
private constant real PLANE_AFTER_DROP = 2.
// Attack type
private constant attacktype ATTACK_TYPE = ATTACK_TYPE_NORMAL
// Damage type
private constant damagetype DAMAGE_TYPE = DAMAGE_TYPE_MAGIC
// The largest collision a unit has in your map
private constant real MAX_COLLISION = 197.
endglobals
// End Configuration
// The speed of the plane per 1/32th of a second
private function GetPlaneSpeedFactor takes integer level returns real
return 9.
endfunction
// The damage dealed to each unit
private function GetDamage takes integer level returns real
return 150 + level * 75.
endfunction
// The damage radius
private function GetDamageRadius takes integer level returns real
return 275 + level * 75.
endfunction
// How close do units have to be for the spell to deal bonus damage?
private function GetBonusDamageRadius takes integer level returns real
return 125 + level * 50.
endfunction
// I want the spell to deal double the damage to units closer than the bonus damage radius.
private function GetBonusDamageFactor takes integer level returns real
return 1.3
endfunction
// This function will filter out some targets (Allied, dead, magic immune and structures)
private function TargetFilter takes player owner, unit caster, unit target returns boolean
return IsUnitEnemy(target, owner) and not (IsUnitType(target, UNIT_TYPE_MAGIC_IMMUNE) or IsUnitType(target, UNIT_TYPE_STRUCTURE) or IsUnitType(target, UNIT_TYPE_DEAD) or GetUnitTypeId(target) == 0)
endfunction
private struct Spell extends array
private static group enumGroup = CreateGroup()
private static unit array caster
private static unit array plane
private static unit array bomb
private static real array xDis
private static real array yDis
private static real array planeX
private static real array planeY
private static real array dropX
private static real array dropY
private static real array damage
private static real array radius
private static real array bonusDamage
private static real array bonusRadius
private static real array speed
private static real array height
private static integer array counter
private static integer array level
private static boolean array dropped
private static boolean array exploded
private static player array owner
static if DESTROY_TREES then
private static rect treeRect = null
private static unit treeDetector = null
private static real treesRadius = 0
private static real treesX = 0
private static real treesY = 0
private static method isTree takes destructable d returns boolean
return IssueTargetOrderById(treeDetector, 852018, d) and IssueImmediateOrderById(treeDetector, 851972)
endmethod
private static method destroyTree takes nothing returns nothing
local destructable d = GetEnumDestructable()
local real x = GetWidgetX(d) - treesX
local real y = GetWidgetY(d) - treesY
// If the destructable is a tree and it is in the circle, kill it
if x*x+y*y <= treesRadius and isTree(d) then
call KillDestructable(d)
endif
set d = null
endmethod
endif
// You don't need a Table or a hashtable if you have TimerUtils
static if not LIBRARY_TimerUtils then
private static Table timerData
endif
// I want to murder this function
private static method destroyParticle takes nothing returns nothing
static if LIBRARY_TimerUtilsEx then
call Particle(ReleaseTimer(GetExpiredTimer())).destroy()
elseif LIBRARY_TimerUtils then
call Particle(GetTimerData(GetExpiredTimer())).destroy()
call ReleaseTimer(GetExpiredTimer())
else
call Particle(timerData[GetHandleId(GetExpiredTimer())]).destroy()
call DestroyTimer(GetExpiredTimer())
endif
endmethod
implement CTL
local timer t
local unit u
local real x
local real y
implement CTLExpire
// Set the planeX and planeY coordinates
set planeX[this] = planeX[this] + xDis[this]
set planeY[this] = planeY[this] + yDis[this]
// Moving the plane out of the map bounds would crash the game, so we should make sure the coordinates are sound.
if planeX[this] <= WorldBounds.maxX or planeX[this] >= WorldBounds.minX or planeY[this] <= WorldBounds.maxY or planeY[this] >= WorldBounds.minY then
// Move the plane
call SetUnitX(plane[this], planeX[this])
call SetUnitY(plane[this], planeY[this])
endif
// If the bomb has been dropped
if dropped[this] then
// If the bomb exploded
if exploded[this] then
// Counter-based checking
set counter[this] = counter[this] - 1
if counter[this] == 0 then
// Destroy the current instance of the spell
call this.destroy()
// Remove the plane
call RemoveUnit(plane[this])
// Timer Utils is optional :3
// This is a pretty ugly way of creating a special effect with a Z-coordinate.
static if LIBRARY_TimerUtils then
call TimerStart(NewTimerEx(Particle.createEx(Player(13), planeX[this], planeY[this], BOMB_HEIGHT, 0, 0, 1, 255, 255, 255, 255, PLANE_OUT_EFFECT, 0)), DESTROY_OUT_EFFECT_PARTICLE_AFTER, false, function thistype.destroyParticle)
else
set t = CreateTimer()
set timerData[GetHandleId(t)] = Particle.createEx(Player(13), planeX[this], planeY[this], BOMB_HEIGHT, 0, 0, 1, 255, 255, 255, 255, PLANE_OUT_EFFECT, 0)
call TimerStart(t, DESTROY_OUT_EFFECT_PARTICLE_AFTER, false, function thistype.destroyParticle)
set t = null
endif
// Null variables
set caster[this] = null
set plane[this] = null
set bomb[this] = null
set owner[this] = null
endif
else
// If the height of the bomb is close to 0
if height[this] <= 5 then
// Destroy the bomb and create the explosion
call RemoveUnit(bomb[this])
static if LIBRARY_TimerUtils then
call TimerStart(NewTimerEx(Particle.createEx(Player(13), dropX[this], dropY[this], 0, 0, 0, 1, 255, 255, 255, 255, EXPLOSION_EFFECT, 0)), DESTROY_EXPLOSION_AFTER, false, function thistype.destroyParticle)
else
set t = CreateTimer()
set timerData[GetHandleId(t)] = Particle.createEx(Player(13), dropX[this], dropY[this], 0, 0, 0, 1, 255, 255, 255, 255, EXPLOSION_EFFECT, 0)
call TimerStart(t, DESTROY_EXPLOSION_AFTER, false, function thistype.destroyParticle)
set t = null
endif
// Loop through all units in the area
call GroupEnumUnitsInRange(enumGroup, dropX[this], dropY[this], radius[this] + MAX_COLLISION, null)
loop
set u = FirstOfGroup(enumGroup)
exitwhen u == null
call GroupRemoveUnit(enumGroup, u)
// Check if the target unit passes the filter and make sure he's in the blast radius.
if TargetFilter(owner[this], caster[this], u) and IsUnitInRangeXY(u, dropX[this], dropY[this], radius[this]) then
set x = GetUnitX(u) - dropX[this]
set y = GetUnitY(u) - dropY[this]
// If the unit is closer than the bonusRange
if x*x+y*y <= bonusRadius[this] then
// We deal the bonus damage
call UnitDamageTarget(caster[this], u, bonusDamage[this], false, false, ATTACK_TYPE, DAMAGE_TYPE, null)
else
// Else, we deal the normal damage
call UnitDamageTarget(caster[this], u, damage[this], false, false, ATTACK_TYPE, DAMAGE_TYPE, null)
endif
endif
endloop
static if DESTROY_TREES then
call SetRect(treeRect, dropX[this] - radius[this], dropY[this] - radius[this], dropX[this] + radius[this], dropY[this] + radius[this])
// Cache tree destroy data
set treesRadius = radius[this]*radius[this]
set treesX = dropX[this]
set treesY = dropY[this]
// Enumerate through all destructables in the rect
call EnumDestructablesInRect(treeRect, null, function thistype.destroyTree)
endif
// The counter is now going to be used to determine
// the number of iterations before the spell ends.
set counter[this] = R2I(PLANE_AFTER_DROP * 32)
set exploded[this] = true
else
// Decrease the bomb's height a bit
set height[this] = height[this] - speed[this]
call SetUnitFlyHeight(bomb[this], height[this], 0)
// Accelerate drop speed
set speed[this] = speed[this] + BOMB_DROP_ACCEL
endif
endif
else
// Decrease the counter by 1
set counter[this] = counter[this] - 1
// When the counter is 0, the plane has reached it's destination.
if counter[this] == 0 then
// Store the dropX and dropY coordinates
set dropX[this] = planeX[this]
set dropY[this] = planeY[this]
// Create the bomb under the plane
set bomb[this] = CreateUnit(DUMMY_OWNER, BOMB_CODE, dropX[this], dropY[this], 0)
// Set the bomb's height
call UnitAddAbility(bomb[this], 'Amrf')
call UnitRemoveAbility(bomb[this], 'Amrf')
call SetUnitFlyHeight(bomb[this], BOMB_HEIGHT, 0)
// We have dropped the bomb
set dropped[this] = true
// Set the bomb height and the bomb drop speed
set height[this] = BOMB_HEIGHT
set speed[this] = BOMB_DROP_SPEED
endif
endif
implement CTLNull
set u = null
implement CTLEnd
private static method run takes nothing returns nothing
local thistype this = create()
local real x = GetSpellTargetX()
local real y = GetSpellTargetY()
local real a
local real s
local real cos
local real sin
local timer t
// Set the caster and the owner and the level of the ability
set caster[this] = GetTriggerUnit()
set owner[this] = GetTriggerPlayer()
set level[this] = GetUnitAbilityLevel(caster[this], ABIL_CODE)
// Cache angle data
set a = Atan2(y - GetUnitY(caster[this]), x - GetUnitX(caster[this]))
set cos = Cos(a)
set sin = Sin(a)
// Set the plane coordinates
set planeX[this] = x - PLANE_DISTANCE * cos
set planeY[this] = y - PLANE_DISTANCE * sin
// Create the plane
set plane[this] = CreateUnit(DUMMY_OWNER, PLANE_CODE, planeX[this], planeY[this], a * bj_RADTODEG)
// Set the speed and x/yOffsets per timeout
set s = GetPlaneSpeedFactor(level[this])
set xDis[this] = cos * s
set yDis[this] = sin * s
// We haven't dropped or exploded the bomb
set dropped[this] = false
set exploded[this] = false
// Number of iterations before the bomb drops
set counter[this] = R2I(PLANE_DISTANCE / s)
// Set the plane's height
call UnitAddAbility(plane[this], 'Amrf')
call UnitRemoveAbility(plane[this], 'Amrf')
call SetUnitFlyHeight(plane[this], BOMB_HEIGHT, 0)
// TimerUtils is optional
// This is an ugly way of creating a special effect with Z
static if LIBRARY_TimerUtils then
call TimerStart(NewTimerEx(Particle.createEx(Player(13), planeX[this], planeY[this], BOMB_HEIGHT, 0, 0, 1, 255, 255, 255, 255, PLANE_IN_EFFECT, 0)), DESTROY_IN_EFFECT_PARTICLE_AFTER, false, function thistype.destroyParticle)
else
set t = CreateTimer()
set timerData[GetHandleId(t)] = Particle.createEx(Player(13), planeX[this], planeY[this], BOMB_HEIGHT, 0, 0, 1, 255, 255, 255, 255, PLANE_IN_EFFECT, 0)
call TimerStart(t, DESTROY_IN_EFFECT_PARTICLE_AFTER, false, function thistype.destroyParticle)
set t = null
endif
// Set the damage and the radius
set damage[this] = GetDamage(level[this])
set radius[this] = GetDamageRadius(level[this])
// Set the bonus damage and the bonus radius
set a = GetBonusDamageRadius(level[this])
set bonusRadius[this] = a*a
set bonusDamage[this] = GetBonusDamageFactor(level[this])*damage[this]
endmethod
private static method onInit takes nothing returns nothing
// Register the spell to SpellEffectEvent
call RegisterSpellEffectEvent(ABIL_CODE, function thistype.run)
static if DESTROY_TREES then
set treeDetector = CreateUnit(Player(15), 'hfoo', 0, 0, 0)
call UnitAddAbility(treeDetector, 'Ahrl')
call UnitAddAbility(treeDetector, 'Aloc')
call ShowUnit(treeDetector, false)
set treeRect = Rect(0,0,0,0)
endif
// If you don't have TimerUtils, you need a Table
static if not LIBRARY_TimerUtils then
set timerData = Table.create()
endif
endmethod
endstruct
endlibrary
//TESH.scrollpos=60
//TESH.alwaysfold=0
library CTL /* v1.2.0.1
*************************************************************************************
*
* CTL or Constant Timer Loop provides a loop for constant merged timers of timeout .03125
*
* Similar to T32 but pauses timer when no structs have instances and removes structs
* from timer trigger when those structs have no instances.
*
* This can also create new timers after destroying a previous timer and generates less
* code in the module. It also generates no triggers so long as the module is implemented
* at the top of the struct.
*
************************************************************************************
*
* module CTL
*
* Allows creation/destruction of timers in a struct. Provides instancing of those timers.
*
* - static method create takes nothing returns thistype
* - method destroy takes nothing returns nothing
*
* CTL (optional)
* local variables, code before running any timers
* CTLExpire (not optional)
* timer code
* CTLNull (optional)
* null any locals, runs after all timers
* CTLEnd (not optional)
*
* module CT32
*
* Converts struct into a timer group. Allows the timer group to be started and stopped.
* Instancing and looping through active timers is up to the user.
*
* - static method start takes nothing returns nothing
* - static method stop takes nothing returns nothing
*
* CT32 (not optional)
* timer code
* CT32End (not optional)
*
* struct TimerGroup32 extends array
*
* Allows for the creation of timer groups. Timer instancing and looping is entirely up
* to the user.
*
* - static method create takes code func returns thistype
* - method destroy takes nothing returns nothing
* - method start takes nothing returns nothing
* - method stop takes nothing returns nothing
*
************************************************************************************/
globals
private integer tgc = 0 //timer group count
private integer array tgr //timer group recycler
private integer ic=0 //instance count
private integer tc=0 //timer count
private integer array rf //root first
private integer array n //next
private integer array p //previous
private integer array th //timer head
private integer array ns //next stack
private trigger t=CreateTrigger()
private timer m=CreateTimer()
private triggercondition array ct
private conditionfunc array rc
private boolean array e32 //enabled
private integer array i32r //ct32 recycler
private integer i32cr = 0 //ct32 count recycler
private boolean array ir32 //is recycling
private boolean array id32 //is destroying
endglobals
private function E takes nothing returns nothing
local integer i=ns[0]
set ns[0]=0
loop
exitwhen 0==i
if (0==p[i]) then
if (0==n[i]) then
call TriggerRemoveCondition(t,ct[th[i]])
set ct[th[i]]=null
set tc=tc-1
set rf[th[i]]=0
else
set rf[th[i]]=n[i]
set p[n[i]]=0
endif
else
set p[n[i]]=p[i]
set n[p[i]]=n[i]
endif
set n[i]=n[0]
set n[0]=i
set i=ns[i]
endloop
loop
exitwhen 0 == i32cr
set i32cr = i32cr - 1
set i = i32r[i32cr]
if (not e32[i]) then
call TriggerRemoveCondition(t,ct[i])
set ct[i] = null
if (id32[i]) then
set tgr[i] = tgr[0]
set tgr[0] = i
set id32[i] = false
set e32[i] = false
set ir32[i] = false
endif
endif
endloop
if (0==tc) then
call PauseTimer(m)
else
call TriggerEvaluate(t)
endif
endfunction
private function CT takes integer r returns integer
local integer i
local integer f
if (0==n[0]) then
set i=ic+1
set ic=i
else
set i=n[0]
set n[0]=n[i]
endif
set th[i]=r
set ns[i]=-1
set f=rf[r]
if (0==f) then
set n[i]=0
set p[i]=0
set rf[r]=i
set ct[r] = TriggerAddCondition(t,rc[r])
//set ct[r] = null
if (0==tc) then
call TimerStart(m,.031250000,true,function E)
endif
set tc=tc+1
else
set n[i]=f
set p[i]=0
set p[f]=i
set rf[r]=i
endif
return i
endfunction
private function DT takes integer t returns nothing
debug if (0>ns[t]) then
set ns[t]=ns[0]
set ns[0]=t
debug else
debug call DisplayTimedTextToPlayer(GetLocalPlayer(),0,0,60,"TIMER LOOP ERROR: ATTEMPT TO DESTROY NULL TIMER")
debug endif
endfunction
private function A takes code c returns integer
local integer i = tgr[0]
if (0 == i) then
set i = tgc + 1
set tgc = i
else
set tgr[0] = tgr[i]
endif
set rc[i]=Condition(c)
return i
endfunction
private function A32 takes integer i returns nothing
if (not e32[i]) then
if (not ir32[i] and not id32[i]) then
set ct[i] = TriggerAddCondition(t, rc[i])
endif
if (0 == tc) then
call TimerStart(m,.031250000,true,function E)
endif
set tc = tc + 1
set e32[i] = true
endif
endfunction
private function SR32 takes integer i returns nothing
if (e32[i]) then
if (not ir32[i] and not id32[i]) then
set i32r[i32cr] = i
set i32cr = i32cr + 1
set ir32[i] = true
endif
set e32[i] = false
set tc = tc - 1
endif
endfunction
private function DT32 takes integer i returns nothing
if (not id32[i]) then
if (not ir32[i]) then
set ir32[i] = true
set tc = tc - 1
set i32r[i32cr] = i
set i32cr = i32cr + 1
set e32[i] = false
endif
set id32[i] = true
endif
endfunction
private keyword r
private keyword e
module CTL
static integer rctl32
static method create takes nothing returns thistype
return CT(rctl32)
endmethod
method destroy takes nothing returns nothing
call DT(this)
endmethod
static method ectl32 takes nothing returns boolean
local thistype this=rf[rctl32]
endmodule
module CTLExpire
implement CTL
loop
exitwhen 0==this
endmodule
module CTLNull
set this=n[this]
endloop
endmodule
module CTLEnd
implement CTLNull
return false
endmethod
private static method onInit takes nothing returns nothing
set rctl32 = A(function thistype.ectl32)
endmethod
endmodule
module CT32
static integer rctl32
static method ectl32 takes nothing returns boolean
endmodule
module CT32End
return false
endmethod
static method start takes nothing returns nothing
call A32(rctl32)
endmethod
static method stop takes nothing returns nothing
call SR32(rctl32)
endmethod
private static method onInit takes nothing returns nothing
set rctl32 = A(function thistype.ectl32)
endmethod
endmodule
struct TimerGroup32 extends array
static method create takes code c returns thistype
return A(c)
endmethod
method destroy takes nothing returns nothing
call DT32(this)
endmethod
method start takes nothing returns nothing
call A32(this)
endmethod
method stop takes nothing returns nothing
call SR32(this)
endmethod
endstruct
endlibrary
//TESH.scrollpos=0
//TESH.alwaysfold=0
library Particle /* v2.0.2.2
*************************************************************************************
*
* Unit for spell effects
*
* Thanks to Vexorian for dummy.mdx
* Thanks to Magtheridon96 for updates
*
*************************************************************************************
*
* */uses/*
*
* */ UnitIndexer /* hiveworkshop.com/forums/jass-functions-413/unit-indexer-172090/
* */ GetUnitCollision /* hiveworkshop.com/forums/jass-resources-412/snippet-getunitcollision-180495/
*
************************************************************************************
*
* SETTINGS
*/
globals
constant integer PARTICLE_ID = 'n000'
endglobals
/*
************************************************************************************
*
* function GetUnitParticle takes UnitIndex whichUnit returns Particle
*
************************************************************************************
*
* struct Particle extends array
*
* real x
* real y
* real z
*
* real xyAngle
* real zAngle
*
* real scale
*
* player owner
*
* string model
*
* integer red
* integer green
* integer blue
* integer alpha
*
* boolean hidden
*
* readonly real collision
*
* readonly unit unit
*
* static method create takes player owner, real x, real y, real xyAngle, string model, real collision returns Particle
* static method createEx takes player owner, real x, real y, real z, real xyAngle, real zAngle, real scale, integer red, integer green, integer blue, integer alpha, string model, real collision returns Particle
* static method createFromUnit takes unit whichUnit returns Particle
* method destroy takes nothing returns nothing
*
* method setColor takes integer red, integer green, integer blue, integer alpha returns nothing
*
************************************************************************************/
globals
private integer array unitParticle
endglobals
struct Particle extends array
private static integer instanceCount = 0
private static integer array recycler
private unit particle
private unit trueParticle
private real scl
private real tlt
private integer red1
private integer blue1
private integer green1
private integer alpha1
private string mdl
private effect mdle
private real xp
private real yp
private real zp
private real ap
private real collision_p
private static location zloc = Location(0,0)
method operator unit takes nothing returns unit
return particle
endmethod
method operator collision takes nothing returns real
return collision_p
endmethod
method operator x takes nothing returns real
return xp
endmethod
method operator x= takes real v returns nothing
set xp = v
call SetUnitX(particle, v)
endmethod
method operator y takes nothing returns real
return yp
endmethod
method operator y= takes real v returns nothing
set yp = v
call SetUnitY(particle, v)
endmethod
method operator z takes nothing returns real
return zp
endmethod
method operator z= takes real v returns nothing
set zp = v
call MoveLocation(zloc, xp, yp)
call SetUnitFlyHeight(particle, v - GetLocationZ(zloc), 0)
endmethod
method operator xyAngle takes nothing returns real
return ap
endmethod
method operator xyAngle= takes real v returns nothing
set ap = v
call SetUnitFacing(particle,v*57.2957795)
endmethod
method operator zAngle takes nothing returns real
return tlt
endmethod
method operator zAngle= takes real v returns nothing
local integer i = R2I(v*57.2957795+90.5)
set tlt = v
if (179 < i) then
set i = 179
elseif (0 > i) then
set i = 0
endif
call SetUnitAnimationByIndex(particle, i)
endmethod
method operator hidden takes nothing returns boolean
return IsUnitHidden(particle)
endmethod
method operator hidden= takes boolean v returns nothing
call ShowUnit(particle, not v)
endmethod
method operator scale takes nothing returns real
return scl
endmethod
method operator scale= takes real v returns nothing
set scl = v
call SetUnitScale(particle, v, 0, 0)
endmethod
method operator owner takes nothing returns player
return GetOwningPlayer(particle)
endmethod
method operator owner= takes player v returns nothing
call SetUnitOwner(particle, v, true)
endmethod
method operator model takes nothing returns string
return mdl
endmethod
method operator model= takes string s returns nothing
call DestroyEffect(mdle)
if (null != s and "" != s) then
set mdle = AddSpecialEffectTarget(s, particle, "origin")
else
set mdle = null
endif
set mdl = s
endmethod
method setColor takes integer red, integer green, integer blue, integer alpha returns nothing
set this.red1 = red
set this.green1 = green
set this.blue1 = blue
set this.alpha1 = alpha
call SetUnitVertexColor(particle, red, green, blue, alpha)
endmethod
method operator red takes nothing returns integer
return red1
endmethod
method operator blue takes nothing returns integer
return blue1
endmethod
method operator green takes nothing returns integer
return green1
endmethod
method operator alpha takes nothing returns integer
return alpha1
endmethod
method operator red= takes integer v returns nothing
set red1 = v
call SetUnitVertexColor(particle, red1, green1, blue1, alpha1)
endmethod
method operator blue= takes integer v returns nothing
set blue1 = v
call SetUnitVertexColor(particle, red1, green1, blue1, alpha1)
endmethod
method operator green= takes integer v returns nothing
set green1 = v
call SetUnitVertexColor(particle, red1, green1, blue1, alpha1)
endmethod
method operator alpha= takes integer v returns nothing
set alpha1 = v
call SetUnitVertexColor(particle, red1, green1, blue1, alpha1)
endmethod
static method createEx takes player p, real x, real y, real z, real xyAngle, real zAngle, real scale, integer red, integer green, integer blue, integer alpha, string model, real collision returns thistype
local thistype this
local unit u
if (0 == recycler[0]) then
set this = instanceCount + 1
set instanceCount = this
else
set this = recycler[0]
set recycler[0] = recycler[this]
endif
if (null == trueParticle) then
set trueParticle = CreateUnit(p, PARTICLE_ID, x, y, xyAngle * 57.2957795)
set unitParticle[GetUnitUserData(trueParticle)] = this
else
call SetUnitX(trueParticle, x)
call SetUnitY(trueParticle, y)
call SetUnitFacing(trueParticle, xyAngle * 57.2957795)
call SetUnitOwner(trueParticle, p, false)
endif
set xp = x
set yp = y
set zp = z
set ap = xyAngle
set particle = trueParticle
call UnitRemoveAbility(trueParticle, 'Amov')
call UnitAddAbility(trueParticle, 'Amrf')
call UnitRemoveAbility(trueParticle, 'Amrf')
call SetUnitFlyHeight(trueParticle, z, 0)
set mdl = model
set mdle = AddSpecialEffectTarget(model, trueParticle, "origin")
set this.zAngle = zAngle
call setColor(red, green, blue, alpha)
set this.scale = scale
set collision_p = collision
return this
endmethod
static method create takes player p, real x, real y, real xyAngle, string model, real collision returns thistype
return createEx(p, x, y, 0, xyAngle, 0, 1, 255, 255, 255, 255, model, collision)
endmethod
static method createFromUnit takes unit u returns thistype
local thistype this
if (0 == recycler[0]) then
set this = instanceCount + 1
set instanceCount = this
else
set this = recycler[0]
set recycler[0] = recycler[this]
endif
set particle = u
set xp = GetUnitX(u)
set yp = GetUnitY(u)
set zp = GetUnitFlyHeight(u)
set ap = GetUnitFacing(u)*bj_DEGTORAD
set collision_p = GetUnitCollision(u)
set unitParticle[GetUnitUserData(u)] = this
return this
endmethod
method destroy takes nothing returns nothing
if (particle == trueParticle) then
set hidden = false
call DestroyEffect(mdle)
set mdle = null
call SetUnitX(trueParticle, WorldBounds.maxX)
call SetUnitY(trueParticle, WorldBounds.maxY)
else
set particle = null
endif
set recycler[this] = recycler[0]
set recycler[0] = this
endmethod
endstruct
function GetUnitParticle takes UnitIndex whichUnit returns Particle
return unitParticle[whichUnit]
endfunction
endlibrary
//TESH.scrollpos=0
//TESH.alwaysfold=0
library GetUnitCollision /* v2.0.1.0
*************************************************************************************
*
* Retrieves collision size for a unit (different from pathing map)
*
* Assumes collision will always be an integer
*
* 100% accurate to 1 decimal for collision sizes >= 5.1
*
*************************************************************************************
*
* */uses/*
*
* */ Table /* hiveworkshop.com/forums/jass-functions-413/snippet-new-table-188084/
*
*************************************************************************************
*
* Functions
*
* function GetUnitCollision takes unit whichUnit returns real
*
************************************************************************************/
globals
private Table uc
endglobals
private function C takes unit u, real x, real y, integer i returns real
local real l = 0
local real h = 300
local real m = 150
local real nm
loop
if (IsUnitInRangeXY(u, x+m, y, 0)) then
set l = m
else
set h = m
endif
set nm = (l+h)/2
exitwhen nm+.001 > m and nm-.001 < m
set m = nm
endloop
set m = R2I(m*10)/10.
set uc.real[i] = m
return m
endfunction
function GetUnitCollision takes unit u returns real
local integer i = GetUnitTypeId(u)
if (uc.real.has(i)) then
return uc.real[i]
endif
return C(u, GetUnitX(u), GetUnitY(u), i)
endfunction
private struct init extends array
private static method onInit takes nothing returns nothing
set uc = Table.create()
endmethod
endstruct
endlibrary
//TESH.scrollpos=20
//TESH.alwaysfold=0
//============================================================================
// SpellEffectEvent
// - Version 1.1.0.0
//
// API
// ---
// RegisterSpellEffectEvent(integer abil, code onCast)
//
// Requires
// --------
// RegisterPlayerUnitEvent: hiveworkshop.com/forums/showthread.php?t=203338
//
// Optional
// --------
// Table: hiveworkshop.com/forums/showthread.php?t=188084
//
library SpellEffectEvent requires RegisterPlayerUnitEvent, optional Table
//============================================================================
private module M
static if LIBRARY_Table then
static Table tb
else
static hashtable ht = InitHashtable()
endif
static method onCast takes nothing returns nothing
static if LIBRARY_Table then
call TriggerEvaluate(.tb.trigger[GetSpellAbilityId()])
else
call TriggerEvaluate(LoadTriggerHandle(.ht, 0, GetSpellAbilityId()))
endif
endmethod
private static method onInit takes nothing returns nothing
static if LIBRARY_Table then
set .tb = Table.create()
endif
call RegisterPlayerUnitEvent(EVENT_PLAYER_UNIT_SPELL_EFFECT, function thistype.onCast)
endmethod
endmodule
//============================================================================
private struct S extends array
implement M
endstruct
//============================================================================
function RegisterSpellEffectEvent takes integer abil, code onCast returns nothing
static if LIBRARY_Table then
if not S.tb.handle.has(abil) then
set S.tb.trigger[abil] = CreateTrigger()
endif
call TriggerAddCondition(S.tb.trigger[abil], Filter(onCast))
else
if not HaveSavedHandle(S.ht, 0, abil) then
call SaveTriggerHandle(S.ht, 0, abil, CreateTrigger())
endif
call TriggerAddCondition(LoadTriggerHandle(S.ht, 0, abil), Filter(onCast))
endif
endfunction
endlibrary
//TESH.scrollpos=0
//TESH.alwaysfold=0
/**************************************************************
*
* RegisterPlayerUnitEvent
* v5.1.0.0
* By Magtheridon96
*
* I would like to give a special thanks to Bribe, azlier
* and BBQ for improving this library. For modularity, it only
* supports player unit events.
*
* Functions passed to RegisterPlayerUnitEvent must either
* return a boolean (false) or nothing. (Which is a Pro)
*
* Warning:
* --------
*
* - Don't use TriggerSleepAction inside registered code.
* - Don't destroy a trigger unless you really know what you're doing.
*
* API:
* ----
*
* - function RegisterPlayerUnitEvent takes playerunitevent whichEvent, code whichFunction returns nothing
* - Registers code that will execute when an event fires.
* - function RegisterPlayerUnitEventForPlayer takes playerunitevent whichEvent, code whichFunction, player whichPlayer returns nothing
* - Registers code that will execute when an event fires for a certain player.
* - function GetPlayerUnitEventTrigger takes playerunitevent whichEvent returns trigger
* - Returns the trigger corresponding to ALL functions of a playerunitevent.
*
**************************************************************/
library RegisterPlayerUnitEvent // Special Thanks to Bribe and azlier
globals
private trigger array t
endglobals
function RegisterPlayerUnitEvent takes playerunitevent p, code c returns nothing
local integer i = GetHandleId(p)
local integer k = 15
if t[i] == null then
set t[i] = CreateTrigger()
loop
call TriggerRegisterPlayerUnitEvent(t[i], Player(k), p, null)
exitwhen k == 0
set k = k - 1
endloop
endif
call TriggerAddCondition(t[i], Filter(c))
endfunction
function RegisterPlayerUnitEventForPlayer takes playerunitevent p, code c, player pl returns nothing
local integer i = 260 + 16 * GetHandleId(p) + GetPlayerId(pl)
if t[i] == null then
set t[i] = CreateTrigger()
call TriggerRegisterPlayerUnitEvent(t[i], pl, p, null)
endif
call TriggerAddCondition(t[i], Filter(c))
endfunction
function GetPlayerUnitEventTrigger takes playerunitevent p returns trigger
return t[GetHandleId(p)]
endfunction
endlibrary
//TESH.scrollpos=0
//TESH.alwaysfold=0
library Table /* made by Bribe, special thanks to Vexorian & Nestharus, version 3.1.0.1
One map, one hashtable. Welcome to NewTable 3.1
This library was originally called NewTable so it didn't conflict with
the API of Table by Vexorian. However, the damage is done and it's too
late to change the library name now. To help with damage control, I
have provided an extension library called TableBC, which bridges all
the functionality of Vexorian's Table except for 2-D string arrays &
the ".flush(integer)" method. I use ".flush()" to flush a child hash-
table, because I wanted the API in NewTable to reflect the API of real
hashtables (I thought this would be more intuitive).
API
------------
struct Table
| static method create takes nothing returns Table
| create a new Table
|
| method destroy takes nothing returns nothing
| destroy it
|
| method flush takes nothing returns nothing
| flush all stored values inside of it
|
| method remove takes integer key returns nothing
| remove the value at index "key"
|
| method operator []= takes integer key, $TYPE$ value returns nothing
| assign "value" to index "key"
|
| method operator [] takes integer key returns $TYPE$
| load the value at index "key"
|
| method has takes integer key returns boolean
| whether or not the key was assigned
|
----------------
struct TableArray
| static method operator [] takes integer array_size returns TableArray
| create a new array of Tables of size "array_size"
|
| method destroy takes nothing returns nothing
| destroy it
|
| method flush takes nothing returns nothing
| flush and destroy it
|
| method operator size takes nothing returns integer
| returns the size of the TableArray
|
| method operator [] takes integer key returns Table
| returns a Table accessible exclusively to index "key"
*/
globals
private integer less = 0 //Index generation for TableArrays (below 0).
private integer more = 8190 //Index generation for Tables.
//Configure it if you use more than 8190 "key" variables in your map (this will never happen though).
private hashtable ht = InitHashtable()
private key sizeK
private key listK
endglobals
private struct dex extends array
static method operator size takes nothing returns Table
return sizeK
endmethod
static method operator list takes nothing returns Table
return listK
endmethod
endstruct
private struct handles extends array
method has takes integer key returns boolean
return HaveSavedHandle(ht, this, key)
endmethod
method remove takes integer key returns nothing
call RemoveSavedHandle(ht, this, key)
endmethod
endstruct
private struct agents extends array
method operator []= takes integer key, agent value returns nothing
call SaveAgentHandle(ht, this, key, value)
endmethod
endstruct
//! textmacro NEW_ARRAY_BASIC takes SUPER, FUNC, TYPE
private struct $TYPE$s extends array
method operator [] takes integer key returns $TYPE$
return Load$FUNC$(ht, this, key)
endmethod
method operator []= takes integer key, $TYPE$ value returns nothing
call Save$FUNC$(ht, this, key, value)
endmethod
method has takes integer key returns boolean
return HaveSaved$SUPER$(ht, this, key)
endmethod
method remove takes integer key returns nothing
call RemoveSaved$SUPER$(ht, this, key)
endmethod
endstruct
private module $TYPE$m
method operator $TYPE$ takes nothing returns $TYPE$s
return this
endmethod
endmodule
//! endtextmacro
//! textmacro NEW_ARRAY takes FUNC, TYPE
private struct $TYPE$s extends array
method operator [] takes integer key returns $TYPE$
return Load$FUNC$Handle(ht, this, key)
endmethod
method operator []= takes integer key, $TYPE$ value returns nothing
call Save$FUNC$Handle(ht, this, key, value)
endmethod
endstruct
private module $TYPE$m
method operator $TYPE$ takes nothing returns $TYPE$s
return this
endmethod
endmodule
//! endtextmacro
//Run these textmacros to include the entire hashtable API as wrappers.
//Don't be intimidated by the number of macros - Vexorian's map optimizer is
//supposed to kill functions which inline (all of these functions inline).
//! runtextmacro NEW_ARRAY_BASIC("Real", "Real", "real")
//! runtextmacro NEW_ARRAY_BASIC("Boolean", "Boolean", "boolean")
//! runtextmacro NEW_ARRAY_BASIC("String", "Str", "string")
//! runtextmacro NEW_ARRAY("Player", "player")
//! runtextmacro NEW_ARRAY("Widget", "widget")
//! runtextmacro NEW_ARRAY("Destructable", "destructable")
//! runtextmacro NEW_ARRAY("Item", "item")
//! runtextmacro NEW_ARRAY("Unit", "unit")
//! runtextmacro NEW_ARRAY("Ability", "ability")
//! runtextmacro NEW_ARRAY("Timer", "timer")
//! runtextmacro NEW_ARRAY("Trigger", "trigger")
//! runtextmacro NEW_ARRAY("TriggerCondition", "triggercondition")
//! runtextmacro NEW_ARRAY("TriggerAction", "triggeraction")
//! runtextmacro NEW_ARRAY("TriggerEvent", "event")
//! runtextmacro NEW_ARRAY("Force", "force")
//! runtextmacro NEW_ARRAY("Group", "group")
//! runtextmacro NEW_ARRAY("Location", "location")
//! runtextmacro NEW_ARRAY("Rect", "rect")
//! runtextmacro NEW_ARRAY("BooleanExpr", "boolexpr")
//! runtextmacro NEW_ARRAY("Sound", "sound")
//! runtextmacro NEW_ARRAY("Effect", "effect")
//! runtextmacro NEW_ARRAY("UnitPool", "unitpool")
//! runtextmacro NEW_ARRAY("ItemPool", "itempool")
//! runtextmacro NEW_ARRAY("Quest", "quest")
//! runtextmacro NEW_ARRAY("QuestItem", "questitem")
//! runtextmacro NEW_ARRAY("DefeatCondition", "defeatcondition")
//! runtextmacro NEW_ARRAY("TimerDialog", "timerdialog")
//! runtextmacro NEW_ARRAY("Leaderboard", "leaderboard")
//! runtextmacro NEW_ARRAY("Multiboard", "multiboard")
//! runtextmacro NEW_ARRAY("MultiboardItem", "multiboarditem")
//! runtextmacro NEW_ARRAY("Trackable", "trackable")
//! runtextmacro NEW_ARRAY("Dialog", "dialog")
//! runtextmacro NEW_ARRAY("Button", "button")
//! runtextmacro NEW_ARRAY("TextTag", "texttag")
//! runtextmacro NEW_ARRAY("Lightning", "lightning")
//! runtextmacro NEW_ARRAY("Image", "image")
//! runtextmacro NEW_ARRAY("Ubersplat", "ubersplat")
//! runtextmacro NEW_ARRAY("Region", "region")
//! runtextmacro NEW_ARRAY("FogState", "fogstate")
//! runtextmacro NEW_ARRAY("FogModifier", "fogmodifier")
//! runtextmacro NEW_ARRAY("Hashtable", "hashtable")
struct Table extends array
// Implement modules for intuitive syntax (tb.handle; tb.unit; etc.)
implement realm
implement booleanm
implement stringm
implement playerm
implement widgetm
implement destructablem
implement itemm
implement unitm
implement abilitym
implement timerm
implement triggerm
implement triggerconditionm
implement triggeractionm
implement eventm
implement forcem
implement groupm
implement locationm
implement rectm
implement boolexprm
implement soundm
implement effectm
implement unitpoolm
implement itempoolm
implement questm
implement questitemm
implement defeatconditionm
implement timerdialogm
implement leaderboardm
implement multiboardm
implement multiboarditemm
implement trackablem
implement dialogm
implement buttonm
implement texttagm
implement lightningm
implement imagem
implement ubersplatm
implement regionm
implement fogstatem
implement fogmodifierm
implement hashtablem
method operator handle takes nothing returns handles
return this
endmethod
method operator agent takes nothing returns agents
return this
endmethod
//set this = tb[GetSpellAbilityId()]
method operator [] takes integer key returns Table
return LoadInteger(ht, this, key)
endmethod
//set tb[389034] = 8192
method operator []= takes integer key, Table tb returns nothing
call SaveInteger(ht, this, key, tb)
endmethod
//set b = tb.has(2493223)
method has takes integer key returns boolean
return HaveSavedInteger(ht, this, key)
endmethod
//call tb.remove(294080)
method remove takes integer key returns nothing
call RemoveSavedInteger(ht, this, key)
endmethod
//Remove all data from a Table instance
method flush takes nothing returns nothing
call FlushChildHashtable(ht, this)
endmethod
//local Table tb = Table.create()
static method create takes nothing returns Table
local Table this = dex.list[0]
if this == 0 then
set this = more + 1
set more = this
else
set dex.list[0] = dex.list[this]
call dex.list.remove(this) //Clear hashed memory
endif
debug set dex.list[this] = -1
return this
endmethod
// Removes all data from a Table instance and recycles its index.
//
// call tb.destroy()
//
method destroy takes nothing returns nothing
debug if dex.list[this] != -1 then
debug call BJDebugMsg("Table Error: Tried to double-free instance: " + I2S(this))
debug return
debug endif
call this.flush()
set dex.list[this] = dex.list[0]
set dex.list[0] = this
endmethod
//! runtextmacro optional TABLE_BC_METHODS()
endstruct
//! runtextmacro optional TABLE_BC_STRUCTS()
struct TableArray extends array
//Returns a new TableArray to do your bidding. Simply use:
//
// local TableArray ta = TableArray[array_size]
//
static method operator [] takes integer array_size returns TableArray
local Table tb = dex.size[array_size] //Get the unique recycle list for this array size
local TableArray this = tb[0] //The last-destroyed TableArray that had this array size
debug if array_size <= 0 then
debug call BJDebugMsg("TypeError: Invalid specified TableArray size: " + I2S(array_size))
debug return 0
debug endif
if this == 0 then
set this = less - array_size
set less = this
else
set tb[0] = tb[this] //Set the last destroyed to the last-last destroyed
call tb.remove(this) //Clear hashed memory
endif
set dex.size[this] = array_size //This remembers the array size
return this
endmethod
//Returns the size of the TableArray
method operator size takes nothing returns integer
return dex.size[this]
endmethod
//This magic method enables two-dimensional[array][syntax] for Tables,
//similar to the two-dimensional utility provided by hashtables them-
//selves.
//
//ta[integer a].unit[integer b] = unit u
//ta[integer a][integer c] = integer d
//
//Inline-friendly when not running in debug mode
//
method operator [] takes integer key returns Table
static if DEBUG_MODE then
local integer i = this.size
if i == 0 then
call BJDebugMsg("IndexError: Tried to get key from invalid TableArray instance: " + I2S(this))
return 0
elseif key < 0 or key >= i then
call BJDebugMsg("IndexError: Tried to get key [" + I2S(key) + "] from outside TableArray bounds: " + I2S(i))
return 0
endif
endif
return this + key
endmethod
//Destroys a TableArray without flushing it; I assume you call .flush()
//if you want it flushed too. This is a public method so that you don't
//have to loop through all TableArray indices to flush them if you don't
//need to (ie. if you were flushing all child-keys as you used them).
//
method destroy takes nothing returns nothing
local Table tb = dex.size[this.size]
debug if this.size == 0 then
debug call BJDebugMsg("TypeError: Tried to destroy an invalid TableArray: " + I2S(this))
debug return
debug endif
if tb == 0 then
//Create a Table to index recycled instances with their array size
set tb = Table.create()
set dex.size[this.size] = tb
endif
call dex.size.remove(this) //Clear the array size from hash memory
set tb[this] = tb[0]
set tb[0] = this
endmethod
private static Table tempTable
private static integer tempEnd
//Avoids hitting the op limit
private static method clean takes nothing returns nothing
local Table tb = .tempTable
local integer end = tb + 0x1000
if end < .tempEnd then
set .tempTable = end
call ForForce(bj_FORCE_PLAYER[0], function thistype.clean)
else
set end = .tempEnd
endif
loop
call tb.flush()
set tb = tb + 1
exitwhen tb == end
endloop
endmethod
//Flushes the TableArray and also destroys it. Doesn't get any more
//similar to the FlushParentHashtable native than this.
//
method flush takes nothing returns nothing
debug if this.size == 0 then
debug call BJDebugMsg("TypeError: Tried to flush an invalid TableArray instance: " + I2S(this))
debug return
debug endif
set .tempTable = this
set .tempEnd = this + this.size
call ForForce(bj_FORCE_PLAYER[0], function thistype.clean)
call this.destroy()
endmethod
endstruct
endlibrary
//TESH.scrollpos=90
//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 constant integer ABILITIES_UNIT_INDEXER = 'A@!!'
private trigger q=CreateTrigger()
private trigger l=CreateTrigger()
private unit array e
private integer r=0
private integer y=0
private integer o=0
private boolean a=false
private integer array n
private integer array p
private integer array lc
endglobals
function GetIndexedUnitId takes nothing returns integer
return o
endfunction
function GetIndexedUnit takes nothing returns unit
return e[o]
endfunction
//! runtextmacro optional UNIT_LIST_LIB()
private struct PreLoader extends array
public static method run takes nothing returns nothing
call DestroyTimer(GetExpiredTimer())
set a=true
endmethod
public static method eval takes trigger t returns nothing
local integer f=n[0]
local integer d=o
loop
exitwhen 0==f
if (IsTriggerEnabled(t)) then
set o=f
if (TriggerEvaluate(t)) then
call TriggerExecute(t)
endif
else
exitwhen true
endif
set f=n[f]
endloop
set o=d
endmethod
public static method evalb takes boolexpr c returns nothing
local trigger t=CreateTrigger()
local thistype f=n[0]
local integer d=o
call TriggerAddCondition(t,c)
loop
exitwhen 0==f
set o=f
call TriggerEvaluate(t)
set f=n[f]
endloop
call DestroyTrigger(t)
set t=null
set o=d
endmethod
endstruct
//! runtextmacro optional UNIT_EVENT_MACRO()
private module UnitIndexerInit
private static method onInit takes nothing returns nothing
local integer i=15
local boolexpr bc=Condition(function thistype.onLeave)
local boolexpr bc2=Condition(function thistype.onEnter)
local group g=CreateGroup()
local player p
set INDEX=CreateEvent()
set DEINDEX=CreateEvent()
call TriggerRegisterEnterRegion(q,WorldBounds.worldRegion,bc2)
loop
set p=Player(i)
call TriggerRegisterPlayerUnitEvent(l,p,EVENT_PLAYER_UNIT_ISSUED_ORDER,bc)
call SetPlayerAbilityAvailable(p,ABILITIES_UNIT_INDEXER,false)
call GroupEnumUnitsOfPlayer(g,p,bc2)
exitwhen 0==i
set i=i-1
endloop
call DestroyGroup(g)
set bc=null
set g=null
set bc2=null
set p=null
call TimerStart(CreateTimer(),0,false,function PreLoader.run)
endmethod
endmodule
struct UnitIndex extends array
method lock takes nothing returns nothing
debug if (null!=e[this]) then
set lc[this]=lc[this]+1
debug else
debug call DisplayTimedTextToPlayer(GetLocalPlayer(),0,0,60,"UNIT INDEXER ERROR: ATTEMPT TO LOCK NULL INDEX")
debug endif
endmethod
method unlock takes nothing returns nothing
debug if (0<lc[this]) then
set lc[this]=lc[this]-1
if (0==lc[this] and null==e[this]) then
set n[this]=y
set y=this
endif
debug else
debug call DisplayTimedTextToPlayer(GetLocalPlayer(),0,0,60,"UNIT INDEXER ERROR: ATTEMPT TO UNLOCK UNLOCKED INDEX")
debug endif
endmethod
method operator unit takes nothing returns unit
return e[this]
endmethod
static method operator [] takes unit whichUnit returns thistype
return GetUnitUserData(whichUnit)
endmethod
endstruct
struct UnitIndexer extends array
readonly static Event INDEX
readonly static Event DEINDEX
static boolean enabled=true
private static method onEnter takes nothing returns boolean
local unit Q=GetFilterUnit()
local integer i
local integer d=o
if (enabled and Q!=e[GetUnitUserData(Q)]) then
if (0==y) then
set r=r+1
set i=r
else
set i=y
set y=n[y]
endif
call UnitAddAbility(Q,ABILITIES_UNIT_INDEXER)
call UnitMakeAbilityPermanent(Q,true,ABILITIES_UNIT_INDEXER)
call SetUnitUserData(Q,i)
set e[i]=Q
static if not LIBRARY_UnitList then
if (not a)then
set p[i]=p[0]
set n[p[0]]=i
set n[i]=0
set p[0]=i
endif
else
set p[i]=p[0]
set n[p[0]]=i
set n[i]=0
set p[0]=i
call GroupAddUnit(g,e[i])
endif
set o=i
call FireEvent(INDEX)
set o=d
endif
set Q=null
return false
endmethod
private static method onLeave takes nothing returns boolean
static if LIBRARY_UnitEvent then
implement optional UnitEventModule
else
local unit u=GetFilterUnit()
local integer i=GetUnitUserData(u)
local integer d=o
if (0==GetUnitAbilityLevel(u,ABILITIES_UNIT_INDEXER) and u==e[i]) then
static if not LIBRARY_UnitList then
if (not a)then
set n[p[i]]=n[i]
set p[n[i]]=p[i]
endif
else
set n[p[i]]=n[i]
set p[n[i]]=p[i]
call GroupRemoveUnit(g,e[i])
endif
set o=i
call FireEvent(DEINDEX)
set o=d
if (0==lc[i]) then
set n[i]=y
set y=i
endif
set e[i]=null
endif
set u=null
endif
return false
endmethod
implement UnitIndexerInit
endstruct
//! runtextmacro optional UNIT_EVENT_MACRO_2()
function RegisterUnitIndexEvent takes boolexpr c,integer ev returns nothing
call RegisterEvent(c, ev)
if (not a and ev==UnitIndexer.INDEX and 0!=n[0]) then
call PreLoader.evalb(c)
endif
endfunction
function TriggerRegisterUnitIndexEvent takes trigger t,integer ev returns nothing
call TriggerRegisterEvent(t,ev)
if (not a and ev == UnitIndexer.INDEX and 0!=n[0]) then
call PreLoader.eval(t)
endif
endfunction
function GetUnitById takes integer W returns unit
return e[W]
endfunction
function GetUnitId takes unit u returns integer
return GetUnitUserData(u)
endfunction
function IsUnitIndexed takes unit u returns boolean
return u==e[GetUnitUserData(u)]
endfunction
function IsUnitDeindexing takes unit u returns boolean
return IsUnitIndexed(u) and 0==GetUnitAbilityLevel(u,ABILITIES_UNIT_INDEXER)
endfunction
module UnitIndexStructMethods
static method operator [] takes unit u returns thistype
return GetUnitUserData(u)
endmethod
method operator unit takes nothing returns unit
return e[this]
endmethod
endmodule
module UnitIndexStruct
implement UnitIndexStructMethods
static if thistype.filter.exists then
static if thistype.index.exists then
static if thistype.deindex.exists then
readonly boolean allocated
else
method operator allocated takes nothing returns boolean
return filter(e[this])
endmethod
endif
else
method operator allocated takes nothing returns boolean
return filter(e[this])
endmethod
endif
elseif (thistype.index.exists) then
static if thistype.deindex.exists then
readonly boolean allocated
else
method operator allocated takes nothing returns boolean
return this==GetUnitUserData(e[this])
endmethod
endif
else
method operator allocated takes nothing returns boolean
return this==GetUnitUserData(e[this])
endmethod
endif
static if thistype.index.exists then
private static method onIndexEvent takes nothing returns boolean
static if thistype.filter.exists then
if (filter(e[o])) then
static if thistype.deindex.exists then
set thistype(o).allocated=true
endif
call thistype(o).index()
endif
else
static if thistype.deindex.exists then
set thistype(o).allocated=true
endif
call thistype(o).index()
endif
return false
endmethod
endif
static if thistype.deindex.exists then
private static method onDeindexEvent takes nothing returns boolean
static if thistype.filter.exists then
static if thistype.index.exists then
if (thistype(o).allocated) then
set thistype(o).allocated=false
call thistype(o).deindex()
endif
else
if (filter(e[o])) then
call thistype(o).deindex()
endif
endif
else
static if thistype.index.exists then
set thistype(o).allocated=false
endif
call thistype(o).deindex()
endif
return false
endmethod
endif
static if thistype.index.exists then
static if thistype.deindex.exists then
private static method onInit takes nothing returns nothing
call RegisterUnitIndexEvent(Condition(function thistype.onIndexEvent),UnitIndexer.INDEX)
call RegisterUnitIndexEvent(Condition(function thistype.onDeindexEvent),UnitIndexer.DEINDEX)
endmethod
else
private static method onInit takes nothing returns nothing
call RegisterUnitIndexEvent(Condition(function thistype.onIndexEvent),UnitIndexer.INDEX)
endmethod
endif
elseif thistype.deindex.exists then
private static method onInit takes nothing returns nothing
call RegisterUnitIndexEvent(Condition(function thistype.onDeindexEvent),UnitIndexer.DEINDEX)
endmethod
endif
endmodule
endlibrary
//TESH.scrollpos=0
//TESH.alwaysfold=0
library WorldBounds /* v2.0.0.0
************************************************************************************
*
* 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
*
************************************************************************************/
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
//TESH.scrollpos=0
//TESH.alwaysfold=0
library Event /* v2.0.0.1
************************************************************************************
*
* Functions
*
* function CreateEvent takes nothing returns integer
* function TriggerRegisterEvent takes trigger t, integer ev returns nothing
*
************************************************************************************
*
* struct Event extends array
*
* static method create takes nothing returns thistype
* method registerTrigger takes trigger t returns nothing
* method register takes boolexpr c returns nothing
* method fire takes nothing returns nothing
*
************************************************************************************/
globals
private real q=0
endglobals
struct Event extends array
private static integer w=0
private static trigger array e
static method create takes nothing returns thistype
set w=w+1
set e[w]=CreateTrigger()
return w
endmethod
method registerTrigger takes trigger t returns nothing
call TriggerRegisterVariableEvent(t,SCOPE_PRIVATE+"q",EQUAL,this)
endmethod
method register takes boolexpr c returns nothing
call TriggerAddCondition(e[this],c)
endmethod
method fire takes nothing returns nothing
set q=0
set q=this
call TriggerEvaluate(e[this])
endmethod
endstruct
function CreateEvent takes nothing returns Event
return Event.create()
endfunction
function TriggerRegisterEvent takes trigger t,Event ev returns nothing
call ev.registerTrigger(t)
endfunction
function RegisterEvent takes boolexpr c,Event ev returns nothing
call ev.register(c)
endfunction
function FireEvent takes Event ev returns nothing
call ev.fire()
endfunction
endlibrary
//TESH.scrollpos=219
//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=140
//TESH.alwaysfold=0
library TimerUtilsEx requires optional Table
/*************************************************
*
* TimerUtilsEx
* v2.1.0.2
* By Vexorian, Bribe & Magtheridon96
*
* Original version by Vexorian.
*
* Flavors:
* Hashtable:
* - RAM: Minimal
* - TimerData: Slow
*
* Array:
* - RAM: Maximal
* - TimerData: Fast
*
* All the functions have O(1) complexity.
* The Array version is the fastest, but the hashtable
* version is the safest. The Array version is still
* quite safe though, and I would recommend using it.
* The system is much slower in debug mode.
*
* Optional Requirement:
* - Table by Bribe
* - hiveworkshop.com/forums/showthread.php?t=188084
*
* API:
* ----
* - function NewTimer takes nothing returns timer
* - Returns a new timer from the stack.
* - function NewTimerEx takes integer i returns timer
* - Returns a new timer from the stack and attaches a value to it.
* - function ReleaseTimer takes timer t returns integer
* - Throws a timer back into the stack. Also returns timer data.
* - function SetTimerData takes timer t, integer value returns nothing
* - Attaches a value to a timer.
* - function GetTimerData takes timer t returns integer
* - Returns the attached value.
*
*************************************************/
// Configuration
globals
// Use hashtable, or fast array?
private constant boolean USE_HASH = false
// Max Number of Timers Held in Stack
private constant integer QUANTITY = 256
endglobals
globals
private timer array tT
private integer tN = 0
endglobals
private module Init
private static method onInit takes nothing returns nothing
static if not USE_HASH then
local integer i = QUANTITY
loop
set i = i - 1
set tT[i] = CreateTimer()
exitwhen i == 0
endloop
set tN = QUANTITY
elseif LIBRARY_Table then
set tb = Table.create()
endif
endmethod
endmodule
// JassHelper doesn't support static ifs for globals.
private struct Data extends array
static if not USE_HASH then
static integer array data
endif
static if LIBRARY_Table then
static Table tb = 0
else
static hashtable ht = InitHashtable()
endif
implement Init
endstruct
// Double free protection
private function ValidTimer takes integer i returns boolean
static if LIBRARY_Table then
return Data.tb.boolean[-i]
else
return LoadBoolean(Data.ht, i, 1)
endif
endfunction
private function Get takes integer id returns integer
debug if not ValidTimer(id) then
debug call DisplayTimedTextToPlayer(GetLocalPlayer(), 0, 0, 60, "[TimerUtils]Error: Tried to get data from invalid timer.")
debug endif
static if USE_HASH then
static if LIBRARY_Table then
return Data.tb[id]
else
return LoadInteger(Data.ht, id, 0)
endif
else
return Data.data[id - 0x100000]
endif
endfunction
private function Set takes integer id, integer data returns nothing
debug if not ValidTimer(id) then
debug call DisplayTimedTextToPlayer(GetLocalPlayer(), 0, 0, 60, "[TimerUtils]Error: Tried to attach data to invalid timer.")
debug endif
static if USE_HASH then
static if LIBRARY_Table then
set Data.tb[id] = data
else
call SaveInteger(Data.ht, id, 0, data)
endif
else
set Data.data[id - 0x100000] = data
endif
endfunction
function SetTimerData takes timer t, integer data returns nothing
call Set(GetHandleId(t), data)
endfunction
function GetTimerData takes timer t returns integer
return Get(GetHandleId(t))
endfunction
function NewTimerEx takes integer data returns timer
local integer id
if tN == 0 then
static if USE_HASH then
set tT[0] = CreateTimer()
else
debug call DisplayTimedTextToPlayer(GetLocalPlayer(), 0, 0, 60, "[TimerUtils]Error: No Timers In The Stack! You must increase 'QUANTITY'")
return null
endif
else
set tN = tN - 1
endif
set id = GetHandleId(tT[tN])
static if LIBRARY_Table then
set Data.tb.boolean[-id] = true
else
call SaveBoolean(Data.ht, id, 1, true)
endif
call Set(id, data)
return tT[tN]
endfunction
function NewTimer takes nothing returns timer
return NewTimerEx(0)
endfunction
function ReleaseTimer takes timer t returns integer
local integer id = GetHandleId(t)
local integer data = 0
// Pause the timer just in case.
call PauseTimer(t)
// Make sure the timer is valid.
if ValidTimer(id) then
// Get the timer's data.
set data = Get(id)
// Unmark handle id as a valid timer.
static if LIBRARY_Table then
call Data.tb.boolean.remove(-id)
else
call RemoveSavedBoolean(Data.ht, id, 1)
endif
//If it's not run in USE_HASH mode, this next block is useless.
static if USE_HASH then
//At least clear hash memory while it's in the recycle stack.
static if LIBRARY_Table then
call Data.tb.remove(id)
else
call RemoveSavedInteger(Data.ht, id, 0)
endif
// If the recycle limit is reached
if tN == QUANTITY then
// then we destroy the timer.
call DestroyTimer(t)
return data
endif
endif
//Recycle the timer.
set tT[tN] = t
set tN = tN + 1
//Tried to pass a bad timer.
debug else
debug call DisplayTimedTextToPlayer(GetLocalPlayer(), 0, 0, 60, "[TimerUtils]Error: Tried to release non-active timer!")
endif
//Return Timer Data.
return data
endfunction
endlibrary
library TimerUtils requires TimerUtilsEx
endlibrary
//TESH.scrollpos=94
//TESH.alwaysfold=0
struct Demo extends array
static unit hero = null
static timer t = CreateTimer()
static real dist = 0
private static trigger unitCreater = CreateTrigger()
private static method cast takes real x, real y returns nothing
call IssuePointOrderById(hero, OrderId("channel"), x, y)
endmethod
private static method makeUnit takes real x, real y returns unit
return CreateUnit(Player(1), 'hfoo', x, y, 270)
endmethod
private static method destroyThem takes nothing returns nothing
call RemoveDestructable(GetEnumDestructable())
endmethod
private static method setDist takes nothing returns nothing
call SetCameraField(CAMERA_FIELD_TARGET_DISTANCE, dist, 0)
endmethod
private static method lockCam takes real distance returns nothing
call TimerStart(t, 0.05, true, function thistype.setDist)
set dist = distance
endmethod
private static method print takes string s returns nothing
call DisplayTimedTextToPlayer(GetLocalPlayer(), 0, 0, 5, s)
endmethod
private static method test takes nothing returns nothing
local integer i = 0
local unit u
local real x = 800
local real y = 800
call FogModifierStart(CreateFogModifierRadius(Player(0), FOG_OF_WAR_VISIBLE, 0, 0, 9000, false, false))
call print("Phase 1: Multi-unit Instanceability")
call TriggerSleepAction(1)
set hero = CreateUnit(Player(0), 'H002', 0, 0, 270)
call SelectHeroSkill(hero, 'A000')
call UnitRemoveAbility(hero, 'Amov')
call TriggerSleepAction(0)
call cast(400, 400)
call TriggerSleepAction(0)
call cast(400, -400)
call TriggerSleepAction(0)
call cast(-400, 400)
call TriggerSleepAction(0)
call cast(-400, -400)
call TriggerSleepAction(18)
call DisplayTimedTextToPlayer(GetLocalPlayer(), 0, 0, 5, "Phase 2: Efficiency")
call SetUnitX(hero, -500)
call SetUnitY(hero, 0)
call SetUnitFacing(hero, 0)
call TriggerSleepAction(0.5)
loop
call cast(0,0)
call TriggerSleepAction(0)
set i = i + 1
exitwhen i == 10
endloop
call TriggerSleepAction(18)
call DisplayTimedTextToPlayer(GetLocalPlayer(), 0, 0, 5, "Phase 3: Damage")
call makeUnit(0,0)
set i = 0
loop
call makeUnit(200*Cos(i*(bj_PI/4)),200*Sin(i*(bj_PI/4)))
set i = i + 1
exitwhen i == 8
endloop
loop
call makeUnit(400*Cos(i*(bj_PI/4)),400*Sin(i*(bj_PI/4)))
set i = i + 1
exitwhen i == 16
endloop
call TriggerSleepAction(2)
call cast(0,0)
call TriggerSleepAction(18)
call DisplayTimedTextToPlayer(GetLocalPlayer(), 0, 0, 5, "Phase 4: Trees")
call GroupEnumUnitsInRange(bj_lastCreatedGroup, 0, 0, 1000, null)
loop
set u = FirstOfGroup(bj_lastCreatedGroup)
exitwhen u == null
call GroupRemoveUnit(bj_lastCreatedGroup, u)
if hero != u then
call RemoveUnit(u)
endif
endloop
set i = 0
loop
loop
call CreateDestructable('LTlt', x, y, 0, 1, 1)
set x = x - 100
exitwhen x == -900
endloop
set y = y - 100
set x = 800
exitwhen y == -900
endloop
call SetUnitX(hero, 0)
call SetUnitY(hero, 1000)
call lockCam(3000)
call TriggerSleepAction(1)
call cast(0,0)
call TriggerSleepAction(18)
call print("Phase 5: Have fun!")
call EnumDestructablesInRect(bj_mapInitialPlayableArea, null, function thistype.destroyThem)
call SetUnitX(hero, 0)
call SetUnitY(hero, 0)
call lockCam(2500)
call EnableTrigger(unitCreater)
call print("Type 'unit X' to create X units")
call RemoveUnit(hero)
set hero = CreateUnit(Player(0), 'H002', 0, 0, 270)
call SetHeroLevel(hero, 20, false)
call SelectHeroSkill(hero, 'A000')
call SelectHeroSkill(hero, 'A000')
call SelectHeroSkill(hero, 'A000')
endmethod
private static method unitCommand takes nothing returns boolean
local string s = GetEventPlayerChatString()
local integer i = S2I(SubString(s, 5, StringLength(s)))
loop
exitwhen i == 0
call CreateUnit(Player(1), 'hfoo', 0, 0, 0)
set i = i - 1
endloop
return false
endmethod
private static method onInit takes nothing returns nothing
local trigger t = CreateTrigger()
call TriggerRegisterPlayerChatEvent(t, Player(0), "start", true)
call TriggerAddAction(t, function thistype.test)
call print("Type 'start' to begin the test.")
call TriggerRegisterPlayerChatEvent(unitCreater, Player(0), "unit", false)
call TriggerAddCondition(unitCreater, Condition(function thistype.unitCommand))
call DisableTrigger(unitCreater)
set t = null
endmethod
endstruct