//TESH.scrollpos=0
//TESH.alwaysfold=0
scope Init initializer InitFunction
private function A takes nothing returns nothing
local unit u = GetTriggerUnit()
call CreateUnit(GetTriggerPlayer(), GetUnitTypeId(u), GetRandomReal(I2R(WorldBounds.minX), I2R(WorldBounds.maxX)), GetRandomReal(I2R(WorldBounds.minY), I2R(WorldBounds.maxY)), GetRandomReal(0, 360))
call TriggerSleepAction(10)
call RemoveUnit(u)
set u = null
endfunction
private function B takes nothing returns nothing
call SetCameraField(CAMERA_FIELD_ZOFFSET, GetCameraField(CAMERA_FIELD_ZOFFSET) + 200, 0)
endfunction
private function InitFunction takes nothing returns nothing
local unit u = CreateUnit(Player(0), 'H001', 0, 0, 0)
local player p = Player(1)
local real dist = 1300
local integer creepcount = 20
local integer campcount = 15
local real c = 2*bj_PI
local real f = c/campcount
local real i = f
local real x
local real y
local integer a
local real facing
local trigger t1 = CreateTrigger()
local trigger t2 = CreateTrigger()
local trigger t3 = CreateTrigger()
call PanCameraToTimed(0, 0, 0)
call FogEnable(false)
call FogMaskEnable(false)
call SetPlayerState(p, PLAYER_STATE_GIVES_BOUNTY, 1)
call SelectUnit(u, true)
call SetHeroLevel(u, 10, false)
loop
set x = dist*Cos(i)
set y = dist*Sin(i)
set facing = bj_RADTODEG*Atan2(y, x)
set a = 0
loop
set a = a + 1
call CreateUnit(p, 'hpea', x, y, facing)
exitwhen a == creepcount
endloop
set i = i + f
exitwhen i >= c
endloop
set u = null
call TriggerRegisterAnyUnitEventBJ(t1, EVENT_PLAYER_UNIT_DEATH)
call TriggerAddAction(t1, function A)
call TriggerRegisterPlayerEvent(t3, Player(0), EVENT_PLAYER_END_CINEMATIC)
call TriggerAddAction(t3, function B)
set t1 = null
set t2 = null
set t3 = null
endfunction
endscope
Name | Type | is_array | initial_value |
library TorrentSystem /* v2.1.0
*/uses /*
*/StunSystem /* https://www.hiveworkshop.com/threads/196749/
*/Table /* https://www.hiveworkshop.com/threads/188084/
*/UnitDex /* https://www.hiveworkshop.com/threads/248209/
*/optional DummyRecycler /* https://www.hiveworkshop.com/threads/277659/
*/optional AutoFly /* https://www.hiveworkshop.com/threads/249422/
*/optional WorldBounds /* https://github.com/nestharus/JASS/blob/master/jass/Systems/WorldBounds/script.j
Resource Link: https://www.hiveworkshop.com/threads/305301/
*///! novjass
|=========|
| Credits |
|=========|
/*
Author:
- AGD
Dependendies:
- iAyanami (StunSystem)
- Nestharus (WorldBounds)
- Bribe (Table)
- Flux (DummyRecycler)
- TriggerHappy (UnitDex, AutoFly)
Other:
- Aniki (Finding bugs)
- Vexorian (dummy.mdx)
- IceFrog (Original Concept)
*/
|===========|
| Importing |
|===========|
/*
1. Import the dummy.mdx model into your map.
2. Copy the "TorrentSystem" library into your map.
3. Configure the necessary data in the system configuration below.
Note:
Torrent instances is based on the index of dummy units. You should make sure that dummy units used
by this system are not excluded from unit indexers.
*/
|=====|
| API |
|=====|
struct Torrent/*
*/readonly static Torrent triggerInstance /* The exploding/vanishing torrent instance (Only use inside a torrent event handler)
*/readonly group targetGroup /* The group containing the targets of the <triggerInstance> (Only use inside a torrent event handler)
*/unit caster /* The unit considered as the owner of the Torrent
*/real height /* Height of the tossed targets
*/real duration /* Duration of the Torrent's explosion
*/real explosionDamage /* Initial damage caused by the Torrent
*/real damagePerSecond /* Damage dealt per second to the tossed targets
*/attacktype attackType /* AttackType of the damage from the Torrent
*/damagetype damageType /* DamageType of the damage from the Torrent
*/weapontype weaponType /* WeaponType of the damage from the Torrent
*/boolexpr filterExpr /* The boolexpr for filtering target units
*/boolean pauseTargets /* Determines if tossed targets are paused (Normally, you should set this to true)
*/string targetStaticSfxModel /* Sfx model attached to the targets while being tossed
*/string targetStaticSfxAttachPoint /* Sfx model attachment point for <targetStaticSfxModel>
*/string landedTargetSfxModel /* Sfx model attached to the landed targets
*/string landedTargetSfxAttachPoint /* Sfx model attachment point for <landedTargetSfxModel>
*/string tossedTargetAnimation /* Animation played by the tossed units
*/static method create takes real centerX, real centerY, real radius, integer borderCount, string model, string borderSfxModel, string onSummonSfxModel returns thistype/*
- Creates a new Torrent instance
- Arguments:
* centerX - The x-coordinate of the Torrent's center
* centerY - The y-coordinate of the Torrent's center
* radius - The radius of the Torrent
* borderCount - number of special effects created in the Torrent's circumference
* model - Sfx model for the Torrent's explosion
* borderSfxModel - Sfx model for the Torrent's borders
* onSummonSfxModel - Sfx model for the Torrent's appearance/creation
*/method destroy takes nothing returns nothing/*
- Destroys a Torrent instance
*/method explode takes boolean tossUnits returns nothing/*
- Explodes a Torrent instance, dealing initial damage to the units within its area, and tossing them while damaging them over time if <tossUnits>
is true
- The Torrent instance is then destroyed
*/method explodeTimed takes real delay, boolean tossUnits returns nothing/*
- Explodes a torrent after a certain delay
*/method registerExplosionHandler takes boolexpr expr returns nothing/*
- Registers a boolexpr that will run upon the Torrent's explosion (when explode() is called)
*/method registerVanishHandler takes boolexpr expr returns nothing/*
- Registers a boolexpr that will run upon the Torrent's disappearance, after tossed units are landed
- This will not run when <tossUnits> is false
*/method registerExplosionHandlerFunc takes code handler returns nothing/*
*/method registerVanishHandlerFunc takes code handler returns nothing/*
- Same to the methods above but takes code instead
*/method clearExplosionHandlers takes nothing returns nothing/*
*/method clearVanishHandlers takes nothing returns nothing/*
*///! endnovjass
native UnitAlive takes unit u returns boolean
/*
This serves as the default target filter flags whenever a new
Torrent instance is created. You can delete this module if
it's not needed. By default, all units except the caster are
allowed as targets. */
private module DefaultTargetFilters
private static method targetFilter takes nothing returns boolean
return GetFilterUnit() != Torrent.triggerInstance.caster
endmethod
endmodule
private module TorrentModule
/*================ SYSTEM CONFIGURATION ================*/
/*
The static timer timeout in real seconds
Default value: 1.00/32.00 (32 FPS) */
static constant real TIMEOUT = 0.031250000
/*
The delay before dummy units are removed
Make sure there's enough time for the special
effects to play its death animation
Default value: 2.00 */
static constant real DUMMY_DURATION = 2.00
/*
The owner of the dummy units
Default value: Player(14) */
static constant player DUMMY_OWNER = Player(14)
/*
The rawcode of the dummy units */
static constant integer DUMMY_ID = 'h000'
/*================ END OF CONFIGURATION ================*/
static if not LIBRARY_WorldBounds then
private static real mapMinX
private static real mapMaxX
private static real mapMinY
private static real mapMaxY
endif
private static TableArray table
private static timer staticTimer = CreateTimer()
private static group tempGroup = CreateGroup()
private static group refreshGroup
private static boolean clearGroup
private trigger onExplodeTrigger
private trigger onVanishTrigger
private integer borderCount
private real radius
private real centerX
private real centerY
private real elapsed
private real damagePerInterval
private group tossedGroup
private string model
private string borderModel
private thistype prev
private thistype next
readonly static thistype triggerInstance = 0
readonly group targetGroup
boolexpr filterExpr
boolean pauseTargets
real height
real duration
real explosionDamage
attacktype attackType
damagetype damageType
weapontype weaponType
string tossedTargetSfxModel
string landedTargetSfxModel
string tossedTargetSfxAttachPoint
string landedTargetSfxAttachPoint
string tossedTargetAnimation
unit caster
private static method getBoundedValue takes real value, real min, real max returns real
if value < min then
return min
elseif value > max then
return max
endif
return value
endmethod
private method evaluate takes trigger whichTrigger returns nothing
local thistype prevInstance = triggerInstance
set triggerInstance = this
call TriggerEvaluate(whichTrigger)
set triggerInstance = prevInstance
endmethod
private method destroyBorders takes nothing returns nothing
local integer count
if .borderModel != null then
set .borderModel = null
/* Iterate through all border special effects and destroy
each one */
set count = .borderCount
loop
exitwhen count == 0
call DestroyEffect(table[this].effect[count])
set count = count - 1
endloop
endif
call DestroyEffect(table[this].effect[0])
set .borderCount = 0
endmethod
method destroy takes nothing returns nothing
/* Check if this torrent tosses its targets
If yes, make sure it has finished its business
before destroying */
if .tossedGroup == null or .elapsed >= .duration then
/* If the torrent borders haven't been destroyed yet, do so now */
call .destroyBorders()
call table[this].flush()
static if LIBRARY_DummyRecycler then
call DummyAddRecycleTimer(GetUnitById(this), DUMMY_DURATION)
else
call UnitApplyTimedLife(GetUnitById(this), 'BTLF', DUMMY_DURATION)
endif
call DestroyTrigger(.onExplodeTrigger)
call DestroyTrigger(.onVanishTrigger)
call DestroyGroup(.targetGroup)
call DestroyGroup(.tossedGroup)
set .pauseTargets = false
set .caster = null
set .centerX = 0.00
set .centerY = 0.00
set .radius = 0.00
set .height = 0.00
set .duration = 0.00
set .explosionDamage = 0.00
set .damagePerSecond = 0.00
set .attackType = null
set .damageType = null
set .weaponType = null
set .model = null
set .tossedTargetSfxModel = null
set .landedTargetSfxModel = null
set .tossedTargetSfxAttachPoint = null
set .landedTargetSfxAttachPoint = null
set .filterExpr = null
set .onExplodeTrigger = null
set .onVanishTrigger = null
set .targetGroup = null
if .tossedGroup != null then
call DestroyGroup(.tossedGroup)
set .tossedGroup = null
set .elapsed = 0.00
set .next.prev = .prev
set .prev.next = .next
if thistype(0).next == 0 then
call PauseTimer(staticTimer)
endif
endif
endif
endmethod
private static method periodic takes nothing returns nothing
local thistype this = thistype(0).next
local integer id
local effect sfx
local group g
local unit u
local unit dummy
local real time
local real speed
local player owner
local boolean recreate
local boolean staticSfx
/* Iterate through all currently exploding torrents and
do actions */
loop
exitwhen this == 0
set .elapsed = .elapsed + TIMEOUT
set owner = GetOwningPlayer(.caster)
if .elapsed < .duration then
set time = 2.00*.elapsed/.duration
set speed = 2.00*.height
set dummy = GetUnitById(this)
/* Adjust units' fly height and deal damage over time */
loop
set u = FirstOfGroup(.tossedGroup)
exitwhen u == null
call GroupRemoveUnit(.tossedGroup, u)
call GroupAddUnit(tempGroup, u)
if speed > 0.00 then
call SetUnitFlyHeight(u, GetUnitDefaultFlyHeight(u) + speed*time - 0.5*speed*time*time, 0)
endif
if .caster == null then
call UnitDamageTarget(dummy, u, .damagePerInterval, true, false, .attackType, .damageType, .weaponType)
else
call UnitDamageTarget(.caster, u, .damagePerInterval, true, false, .attackType, .damageType, .weaponType)
endif
if .tossedTargetSfxModel != null and not UnitAlive(u) then
set id = GetHandleId(u)
set sfx = table[this].effect[id]
if sfx != null then
call DestroyEffect(sfx)
call table[this].effect.remove(id)
endif
endif
if .pauseTargets then
call Stun.apply(u, 0.01, false)
endif
endloop
set g = tempGroup
set tempGroup = .tossedGroup
set .tossedGroup = g
set g = null
set dummy = null
else
set recreate = .onVanishTrigger != null and .targetGroup == null
if recreate then
set .targetGroup = CreateGroup()
endif
loop
set u = FirstOfGroup(.tossedGroup)
exitwhen u == null
call GroupRemoveUnit(.tossedGroup, u)
if recreate then
call GroupAddUnit(.targetGroup, u)
endif
if .landedTargetSfxModel != null then
call DestroyEffect(AddSpecialEffectTarget(.landedTargetSfxModel, u, .landedTargetSfxAttachPoint))
endif
if .tossedTargetSfxModel != null then
set sfx = table[this].effect[GetHandleId(u)]
if sfx != null then
call DestroyEffect(sfx)
set sfx = null
endif
endif
/* Reset tossed units' fly height to default upon landing */
call SetUnitFlyHeight(u, GetUnitDefaultFlyHeight(u), 0.00)
endloop
if recreate then
/* Fire torrent disappearance handler */
call .evaluate(.onVanishTrigger)
endif
call .destroy()
endif
set this = .next
endloop
endmethod
method explode takes boolean tossUnits returns nothing
local unit dummy = GetUnitById(this)
local player owner = GetOwningPlayer(.caster)
local boolean evaluateExplosion
local thistype prevInstance
local unit u
call .destroyBorders()
set tossUnits = tossUnits and .duration >= 2.00*TIMEOUT
if tossUnits then
/* Add this torrent instance to the periodic loop actions */
set .next = 0
set .prev = thistype(0).prev
set thistype(0).prev = this
set .prev.next = this
set .tossedGroup = CreateGroup()
if .prev == 0 then
call TimerStart(staticTimer, TIMEOUT, true, function thistype.periodic)
endif
endif
if .model != null then
/* Creating torrent explosion SFX */
call DestroyEffect(AddSpecialEffectTarget(.model, dummy, "origin"))
endif
set evaluateExplosion = .onExplodeTrigger != null
if evaluateExplosion then
set .targetGroup = CreateGroup()
endif
set prevInstance = triggerInstance
set triggerInstance = this
call GroupEnumUnitsInRange(tempGroup, .centerX, .centerY, .radius, .filterExpr)
set triggerInstance = prevInstance
loop
set u = FirstOfGroup(tempGroup)
exitwhen u == null
call GroupRemoveUnit(tempGroup, u)
if evaluateExplosion then
call GroupAddUnit(.targetGroup, u)
endif
if tossUnits then
call GroupAddUnit(.tossedGroup, u)
static if not LIBRARY_AutoFly then
if UnitAddAbility(u, 'Arav') and UnitRemoveAbility(u, 'Arav') then
endif
endif
call SetUnitAnimation(u, .tossedTargetAnimation)
if .tossedTargetSfxModel != null then
set table[this].effect[GetHandleId(u)] = AddSpecialEffectTarget(.tossedTargetSfxModel, u, .tossedTargetSfxAttachPoint)
endif
elseif .tossedTargetSfxModel != null then
call DestroyEffect(AddSpecialEffectTarget(.tossedTargetSfxModel, u, .tossedTargetSfxAttachPoint))
endif
if .caster == null then
call UnitDamageTarget(dummy, u, .explosionDamage, true, false, .attackType, .damageType, .weaponType)
else
call UnitDamageTarget(.caster, u, .explosionDamage, true, false, .attackType, .damageType, .weaponType)
endif
endloop
if evaluateExplosion then
/* Fire the torrent's explosion handler */
call .evaluate(.onExplodeTrigger)
call GroupClear(.targetGroup)
endif
if not tossUnits then
/* If <tossUnits> is false, destroy instantly */
call .destroy()
endif
set owner = null
set dummy = null
endmethod
private static method onExplodeTimerExpire takes nothing returns nothing
local timer expired = GetExpiredTimer()
local integer timerId = GetHandleId(expired)
local thistype node = table[0][timerId]
if node > 0 then
call node.explode(true)
else
call thistype(-node).explode(false)
endif
call table[0].remove(timerId)
call DestroyTimer(expired)
set expired = null
endmethod
method explodeTimed takes real delay, boolean tossUnits returns nothing
local timer t = CreateTimer()
if tossUnits then
set table[0][GetHandleId(t)] = this
else
set table[0][GetHandleId(t)] = -this
endif
call TimerStart(t, delay, false, function thistype.onExplodeTimerExpire)
set t = null
endmethod
static method create takes real centerX, real centerY, real radius, integer borderCount, string model, string borderSfxModel, string onSummonSfxModel returns thistype
static if LIBRARY_DummyRecycler then
local unit dummy = GetRecycledDummyAnyAngle(centerX, centerY, 0)
else
local unit dummy = CreateUnit(DUMMY_OWNER, DUMMY_ID, centerX, centerY, 0)
endif
local thistype this = GetUnitId(dummy)
local real deltaAngle
local real angle
/* Initialize default target filters */
static if thistype.targetFilter.exists then
set .filterExpr = Filter(function thistype.targetFilter)
endif
set .pauseTargets = true
set .centerX = centerX
set .centerY = centerY
set .borderCount = borderCount
set .radius = radius
set .model = model
set .borderModel = borderSfxModel
if borderSfxModel != null and borderCount > 0 then
/* Adjust the radius a bit for the border effects' location
to fit with the radius */
set radius = radius - 20
set deltaAngle = 2.00*bj_PI/borderCount
loop
exitwhen borderCount == 0
set angle = deltaAngle*borderCount
/* Implement map bounds */
static if LIBRARY_WorldBounds then
set table[this].effect[borderCount] = AddSpecialEffect(borderSfxModel, getBoundedValue(centerX + radius*Cos(angle), WorldBounds.minX, WorldBounds.maxX), getBoundedValue(centerY + radius*Sin(angle), WorldBounds.minY, WorldBounds.maxY))
else
set table[this].effect[borderCount] = AddSpecialEffect(borderSfxModel, getBoundedValue(centerX + radius*Cos(angle), minX, maxX), getBoundedValue(centerY + radius*Sin(angle), minY, maxY))
endif
set borderCount = borderCount - 1
endloop
endif
call SetUnitScale(dummy, radius*0.01 , 0, 0)
set table[this].effect[0] = AddSpecialEffectTarget(onSummonSfxModel, dummy, "origin")
set .caster = dummy
set dummy = null
return this
endmethod
method registerExplosionHandler takes boolexpr expr returns nothing
if expr != null then
if .onExplodeTrigger == null then
set .onExplodeTrigger = CreateTrigger()
endif
call TriggerAddCondition(.onExplodeTrigger, expr)
endif
endmethod
method registerVanishHandler takes boolexpr expr returns nothing
if expr != null then
if .onVanishTrigger == null then
set .onVanishTrigger = CreateTrigger()
endif
call TriggerAddCondition(.onVanishTrigger, expr)
endif
endmethod
method registerExplosionHandlerFunc takes code handler returns nothing
call .registerExplosionHandler(Filter(handler))
return
endmethod
method registerVanishHandlerFunc takes code handler returns nothing
call .registerVanishHandler(Filter(handler))
return
endmethod
method clearExplosionHandlers takes nothing returns nothing
call DestroyTrigger(.onExplodeTrigger)
set .onExplodeTrigger = null
endmethod
method clearVanishHandlers takes nothing returns nothing
call DestroyTrigger(.onVanishTrigger)
set .onVanishTrigger = null
endmethod
method operator damagePerSecond= takes real dps returns nothing
set .damagePerInterval = dps*TIMEOUT
endmethod
method operator damagePerSecond takes nothing returns real
return .damagePerInterval/TIMEOUT
endmethod
/* Clean groups from removed units which is more efficient than
regularly cleaning groups per tossing period */
private static method onDeindex takes nothing returns boolean
local thistype this = thistype(0).next
local unit deindexed = GetIndexedUnit()
loop
exitwhen this == 0
call GroupRemoveUnit(.tossedGroup, deindexed)
set this = .next
endloop
set deindexed = null
return false
endmethod
private static method onInit takes nothing returns nothing
/* Setup map bounds */
static if not LIBRARY_WorldBounds then
local rect bounds = GetWorldBounds()
set mapMinX = GetRectMinX(bounds)
set mapMinY = GetRectMinY(bounds)
set mapMaxX = GetRectMaxX(bounds)
set mapMaxY = GetRectMaxY(bounds)
call RemoveRect(bounds)
set bounds = null
endif
set table = TableArray[JASS_MAX_ARRAY_SIZE]
call OnUnitDeindex(function thistype.onDeindex)
endmethod
endmodule
struct Torrent extends array
implement TorrentModule
endstruct
endlibrary
library StunSystem uses Table
//********************************************************************************
// Stun - Version 1.2.0.0 - By iAyanami aka Ayanami
//********************************************************************************
//
// Stun:
// - An easy to use system that stuns units
// - Able to keep track of the remaining stun duration
//
// Requirements:
// - JASS NewGen
// - Table
//
// Functions:
// - Stun.apply takes unit whichUnit, real duration, boolean stack returns nothing
// * whichUnit is the target to be stunned
// * duration is the duration of the stun
// * stack is to determine if the stun should be a stacking one or not
// * true - the stun will stack, the duration of the stun will add up with the previous duration
// * false - the stun will not stack, the unit will be stunned for the longer stun duration
//
// - Stun.getDuration takes unit whichUnit returns real
// * whichUnit is the target to check
// * returns the remaining stun duration
//
// - Stun.stop takes unit whichUnit returns nothing
// * removes stun from the target
//
// How to import:
// - Copy the whole "Stun" Trigger Folder into your map
// - Save the map. Close and re-opem the map.
// - You should have a new unit (Stun Dummy), ability (Stun (System)) and buff (Stun (System)) created
// - Read through the Configuration part of the code
//
// Credits:
// - Bribe for Table
//
//********************************************************************************
// CONFIGURABLES
//********************************************************************************
globals
// timer period. lower the value, the more accurate but might cause decrease in
// performance
private constant real PERIOD = 0.03125
// raw code of ability "Stun (System)"
private constant integer ABILID = 'ASTN'
// raw code of buff "Stun (System)"
private constant integer BUFFID = 'BSTN'
// raw code of unit "Stun Dummy"
private constant integer STUNID = 'sTUN'
endglobals
//********************************************************************************
// CODE
//********************************************************************************
// initialization
module Init
private static method onInit takes nothing returns nothing
set table = Table.create()
set caster = CreateUnit(Player(13), STUNID, 0, 0, 0)
call UnitAddAbility(caster, ABILID)
endmethod
endmodule
struct Stun extends array
private unit u
private real dur
private thistype next
private thistype prev
private static Table table
private static timer t = CreateTimer()
private static unit caster
private static integer count = 0
// remove the stun and deallocate
private method destroy takes nothing returns nothing
call UnitRemoveAbility(this.u, BUFFID)
if this.next != 0 then
set this.next.prev = this.prev
endif
set this.prev.next = this.next
set this.dur = 0
set this.prev = thistype(0).prev
set thistype(0).prev = this
if thistype(0).next == 0 then
call PauseTimer(t)
endif
call table.remove(GetHandleId(this.u))
endmethod
// iterating through all instances every PERIOD
private static method iterate takes nothing returns nothing
local thistype this = thistype(0)
loop
set this = this.next
exitwhen this == 0
if this.dur <= 0 or IsUnitType(this.u, UNIT_TYPE_DEAD) or GetUnitTypeId(this.u) == 0 then
call this.destroy()
else
set this.dur = this.dur - PERIOD
endif
endloop
endmethod
// immediately removes stun for the specified unit
// ex: call Stun.stop(whichTarget)
static method stop takes unit u returns nothing
local integer id = GetHandleId(u)
if table.has(id) then
call thistype(table[id]).destroy()
endif
endmethod
// gets the duration left for stun, not stunned units always return 0
// ex: local real r = Stun.getDuration(whichTarget)
static method getDuration takes unit u returns real
return thistype(table[GetHandleId(u)]).dur
endmethod
// stunning specified target and to see if the stun is a stacking one or not
// ex: call Stun.apply(whichTarget, 5.0, false)
static method apply takes unit u, real dur, boolean b returns nothing
local thistype this
local integer id = GetHandleId(u)
if table.has(id) then
set this = table[id]
else
if thistype(0).prev == 0 then
set count = count + 1
set this = count
else
set this = thistype(0).prev
set thistype(0).prev = thistype(0).prev.prev
endif
if thistype(0).next == 0 then
call TimerStart(t, PERIOD, true, function thistype.iterate)
else
set thistype(0).next.prev = this
endif
set this.next = thistype(0).next
set thistype(0).next = this
set this.prev = thistype(0)
set table[id] = this
set this.u = u
set this.dur = 0
call IssueTargetOrder(caster, "firebolt", this.u)
endif
if b and dur > 0 then
set this.dur = this.dur + dur
elseif this.dur < dur then
set this.dur = dur
endif
endmethod
implement Init
endstruct
endlibrary
library Table /* made by Bribe, special thanks to Vexorian & Nestharus, version 4.1.0.1.
One map, one hashtable. Welcome to NewTable 4.1.0.1
This newest iteration of Table introduces the new HashTable struct.
You can now instantiate HashTables which enables the use of large
parent and large child keys, just like a standard hashtable. Previously,
the user would have to instantiate a Table to do this on their own which -
while doable - is something the user should not have to do if I can add it
to this resource myself (especially if they are inexperienced).
This library was originally called NewTable so it didn't conflict with
the API of Table by Vexorian. However, the damage is done and it's too
late to change the library name now. To help with damage control, I
have provided an extension library called TableBC, which bridges all
the functionality of Vexorian's Table except for 2-D string arrays &
the ".flush(integer)" method. I use ".flush()" to flush a child hash-
table, because I wanted the API in NewTable to reflect the API of real
hashtables (I thought this would be more intuitive).
API
------------
struct Table
| static method create takes nothing returns Table
| create a new Table
|
| method destroy takes nothing returns nothing
| destroy it
|
| method flush takes nothing returns nothing
| flush all stored values inside of it
|
| method remove takes integer key returns nothing
| remove the value at index "key"
|
| method operator []= takes integer key, $TYPE$ value returns nothing
| assign "value" to index "key"
|
| method operator [] takes integer key returns $TYPE$
| load the value at index "key"
|
| method has takes integer key returns boolean
| whether or not the key was assigned
|
----------------
struct TableArray
| static method operator [] takes integer array_size returns TableArray
| create a new array of Tables of size "array_size"
|
| method destroy takes nothing returns nothing
| destroy it
|
| method flush takes nothing returns nothing
| flush and destroy it
|
| method operator size takes nothing returns integer
| returns the size of the TableArray
|
| method operator [] takes integer key returns Table
| returns a Table accessible exclusively to index "key"
*/
globals
private integer less = 0 //Index generation for TableArrays (below 0).
private integer more = 8190 //Index generation for Tables.
//Configure it if you use more than 8190 "key" variables in your map (this will never happen though).
private hashtable ht = InitHashtable()
private key sizeK
private key listK
endglobals
private struct dex extends array
static method operator size takes nothing returns Table
return sizeK
endmethod
static method operator list takes nothing returns Table
return listK
endmethod
endstruct
private struct handles extends array
method has takes integer key returns boolean
return HaveSavedHandle(ht, this, key)
endmethod
method remove takes integer key returns nothing
call RemoveSavedHandle(ht, this, key)
endmethod
endstruct
private struct agents extends array
method operator []= takes integer key, agent value returns nothing
call SaveAgentHandle(ht, this, key, value)
endmethod
endstruct
//! textmacro NEW_ARRAY_BASIC takes SUPER, FUNC, TYPE
private struct $TYPE$s extends array
method operator [] takes integer key returns $TYPE$
return Load$FUNC$(ht, this, key)
endmethod
method operator []= takes integer key, $TYPE$ value returns nothing
call Save$FUNC$(ht, this, key, value)
endmethod
method has takes integer key returns boolean
return HaveSaved$SUPER$(ht, this, key)
endmethod
method remove takes integer key returns nothing
call RemoveSaved$SUPER$(ht, this, key)
endmethod
endstruct
private module $TYPE$m
method operator $TYPE$ takes nothing returns $TYPE$s
return this
endmethod
endmodule
//! endtextmacro
//! textmacro NEW_ARRAY takes FUNC, TYPE
private struct $TYPE$s extends array
method operator [] takes integer key returns $TYPE$
return Load$FUNC$Handle(ht, this, key)
endmethod
method operator []= takes integer key, $TYPE$ value returns nothing
call Save$FUNC$Handle(ht, this, key, value)
endmethod
method has takes integer key returns boolean
return HaveSavedHandle(ht, this, key)
endmethod
method remove takes integer key returns nothing
call RemoveSavedHandle(ht, this, key)
endmethod
endstruct
private module $TYPE$m
method operator $TYPE$ takes nothing returns $TYPE$s
return this
endmethod
endmodule
//! endtextmacro
//Run these textmacros to include the entire hashtable API as wrappers.
//Don't be intimidated by the number of macros - Vexorian's map optimizer is
//supposed to kill functions which inline (all of these functions inline).
//! runtextmacro NEW_ARRAY_BASIC("Real", "Real", "real")
//! runtextmacro NEW_ARRAY_BASIC("Boolean", "Boolean", "boolean")
//! runtextmacro NEW_ARRAY_BASIC("String", "Str", "string")
//New textmacro to allow table.integer[] syntax for compatibility with textmacros that might desire it.
//! runtextmacro NEW_ARRAY_BASIC("Integer", "Integer", "integer")
//! runtextmacro NEW_ARRAY("Player", "player")
//! runtextmacro NEW_ARRAY("Widget", "widget")
//! runtextmacro NEW_ARRAY("Destructable", "destructable")
//! runtextmacro NEW_ARRAY("Item", "item")
//! runtextmacro NEW_ARRAY("Unit", "unit")
//! runtextmacro NEW_ARRAY("Ability", "ability")
//! runtextmacro NEW_ARRAY("Timer", "timer")
//! runtextmacro NEW_ARRAY("Trigger", "trigger")
//! runtextmacro NEW_ARRAY("TriggerCondition", "triggercondition")
//! runtextmacro NEW_ARRAY("TriggerAction", "triggeraction")
//! runtextmacro NEW_ARRAY("TriggerEvent", "event")
//! runtextmacro NEW_ARRAY("Force", "force")
//! runtextmacro NEW_ARRAY("Group", "group")
//! runtextmacro NEW_ARRAY("Location", "location")
//! runtextmacro NEW_ARRAY("Rect", "rect")
//! runtextmacro NEW_ARRAY("BooleanExpr", "boolexpr")
//! runtextmacro NEW_ARRAY("Sound", "sound")
//! runtextmacro NEW_ARRAY("Effect", "effect")
//! runtextmacro NEW_ARRAY("UnitPool", "unitpool")
//! runtextmacro NEW_ARRAY("ItemPool", "itempool")
//! runtextmacro NEW_ARRAY("Quest", "quest")
//! runtextmacro NEW_ARRAY("QuestItem", "questitem")
//! runtextmacro NEW_ARRAY("DefeatCondition", "defeatcondition")
//! runtextmacro NEW_ARRAY("TimerDialog", "timerdialog")
//! runtextmacro NEW_ARRAY("Leaderboard", "leaderboard")
//! runtextmacro NEW_ARRAY("Multiboard", "multiboard")
//! runtextmacro NEW_ARRAY("MultiboardItem", "multiboarditem")
//! runtextmacro NEW_ARRAY("Trackable", "trackable")
//! runtextmacro NEW_ARRAY("Dialog", "dialog")
//! runtextmacro NEW_ARRAY("Button", "button")
//! runtextmacro NEW_ARRAY("TextTag", "texttag")
//! runtextmacro NEW_ARRAY("Lightning", "lightning")
//! runtextmacro NEW_ARRAY("Image", "image")
//! runtextmacro NEW_ARRAY("Ubersplat", "ubersplat")
//! runtextmacro NEW_ARRAY("Region", "region")
//! runtextmacro NEW_ARRAY("FogState", "fogstate")
//! runtextmacro NEW_ARRAY("FogModifier", "fogmodifier")
//! runtextmacro NEW_ARRAY("Hashtable", "hashtable")
struct Table extends array
// Implement modules for intuitive syntax (tb.handle; tb.unit; etc.)
implement realm
implement integerm
implement booleanm
implement stringm
implement playerm
implement widgetm
implement destructablem
implement itemm
implement unitm
implement abilitym
implement timerm
implement triggerm
implement triggerconditionm
implement triggeractionm
implement eventm
implement forcem
implement groupm
implement locationm
implement rectm
implement boolexprm
implement soundm
implement effectm
implement unitpoolm
implement itempoolm
implement questm
implement questitemm
implement defeatconditionm
implement timerdialogm
implement leaderboardm
implement multiboardm
implement multiboarditemm
implement trackablem
implement dialogm
implement buttonm
implement texttagm
implement lightningm
implement imagem
implement ubersplatm
implement regionm
implement fogstatem
implement fogmodifierm
implement hashtablem
method operator handle takes nothing returns handles
return this
endmethod
method operator agent takes nothing returns agents
return this
endmethod
//set this = tb[GetSpellAbilityId()]
method operator [] takes integer key returns Table
return LoadInteger(ht, this, key) //return this.integer[key]
endmethod
//set tb[389034] = 8192
method operator []= takes integer key, Table tb returns nothing
call SaveInteger(ht, this, key, tb) //set this.integer[key] = tb
endmethod
//set b = tb.has(2493223)
method has takes integer key returns boolean
return HaveSavedInteger(ht, this, key) //return this.integer.has(key)
endmethod
//call tb.remove(294080)
method remove takes integer key returns nothing
call RemoveSavedInteger(ht, this, key) //call this.integer.remove(key)
endmethod
//Remove all data from a Table instance
method flush takes nothing returns nothing
call FlushChildHashtable(ht, this)
endmethod
//local Table tb = Table.create()
static method create takes nothing returns Table
local Table this = dex.list[0]
if this == 0 then
set this = more + 1
set more = this
else
set dex.list[0] = dex.list[this]
call dex.list.remove(this) //Clear hashed memory
endif
debug set dex.list[this] = -1
return this
endmethod
// Removes all data from a Table instance and recycles its index.
//
// call tb.destroy()
//
method destroy takes nothing returns nothing
debug if dex.list[this] != -1 then
debug call BJDebugMsg("Table Error: Tried to double-free instance: " + I2S(this))
debug return
debug endif
call this.flush()
set dex.list[this] = dex.list[0]
set dex.list[0] = this
endmethod
//! runtextmacro optional TABLE_BC_METHODS()
endstruct
//! runtextmacro optional TABLE_BC_STRUCTS()
struct TableArray extends array
//Returns a new TableArray to do your bidding. Simply use:
//
// local TableArray ta = TableArray[array_size]
//
static method operator [] takes integer array_size returns TableArray
local Table tb = dex.size[array_size] //Get the unique recycle list for this array size
local TableArray this = tb[0] //The last-destroyed TableArray that had this array size
debug if array_size <= 0 then
debug call BJDebugMsg("TypeError: Invalid specified TableArray size: " + I2S(array_size))
debug return 0
debug endif
if this == 0 then
set this = less - array_size
set less = this
else
set tb[0] = tb[this] //Set the last destroyed to the last-last destroyed
call tb.remove(this) //Clear hashed memory
endif
set dex.size[this] = array_size //This remembers the array size
return this
endmethod
//Returns the size of the TableArray
method operator size takes nothing returns integer
return dex.size[this]
endmethod
//This magic method enables two-dimensional[array][syntax] for Tables,
//similar to the two-dimensional utility provided by hashtables them-
//selves.
//
//ta[integer a].unit[integer b] = unit u
//ta[integer a][integer c] = integer d
//
//Inline-friendly when not running in debug mode
//
method operator [] takes integer key returns Table
static if DEBUG_MODE then
local integer i = this.size
if i == 0 then
call BJDebugMsg("IndexError: Tried to get key from invalid TableArray instance: " + I2S(this))
return 0
elseif key < 0 or key >= i then
call BJDebugMsg("IndexError: Tried to get key [" + I2S(key) + "] from outside TableArray bounds: " + I2S(i))
return 0
endif
endif
return this + key
endmethod
//Destroys a TableArray without flushing it; I assume you call .flush()
//if you want it flushed too. This is a public method so that you don't
//have to loop through all TableArray indices to flush them if you don't
//need to (ie. if you were flushing all child-keys as you used them).
//
method destroy takes nothing returns nothing
local Table tb = dex.size[this.size]
debug if this.size == 0 then
debug call BJDebugMsg("TypeError: Tried to destroy an invalid TableArray: " + I2S(this))
debug return
debug endif
if tb == 0 then
//Create a Table to index recycled instances with their array size
set tb = Table.create()
set dex.size[this.size] = tb
endif
call dex.size.remove(this) //Clear the array size from hash memory
set tb[this] = tb[0]
set tb[0] = this
endmethod
private static Table tempTable
private static integer tempEnd
//Avoids hitting the op limit
private static method clean takes nothing returns nothing
local Table tb = .tempTable
local integer end = tb + 0x1000
if end < .tempEnd then
set .tempTable = end
call ForForce(bj_FORCE_PLAYER[0], function thistype.clean)
else
set end = .tempEnd
endif
loop
call tb.flush()
set tb = tb + 1
exitwhen tb == end
endloop
endmethod
//Flushes the TableArray and also destroys it. Doesn't get any more
//similar to the FlushParentHashtable native than this.
//
method flush takes nothing returns nothing
debug if this.size == 0 then
debug call BJDebugMsg("TypeError: Tried to flush an invalid TableArray instance: " + I2S(this))
debug return
debug endif
set .tempTable = this
set .tempEnd = this + this.size
call ForForce(bj_FORCE_PLAYER[0], function thistype.clean)
call this.destroy()
endmethod
endstruct
//NEW: Added in Table 4.0. A fairly simple struct but allows you to do more
//than that which was previously possible.
struct HashTable extends array
//Enables myHash[parentKey][childKey] syntax.
//Basically, it creates a Table in the place of the parent key if
//it didn't already get created earlier.
method operator [] takes integer index returns Table
local Table t = Table(this)[index]
if t == 0 then
set t = Table.create()
set Table(this)[index] = t //whoops! Forgot that line. I'm out of practice!
endif
return t
endmethod
//You need to call this on each parent key that you used if you
//intend to destroy the HashTable or simply no longer need that key.
method remove takes integer index returns nothing
local Table t = Table(this)[index]
if t != 0 then
call t.destroy()
call Table(this).remove(index)
endif
endmethod
//Added in version 4.1
method has takes integer index returns boolean
return Table(this).has(index)
endmethod
//HashTables are just fancy Table indices.
method destroy takes nothing returns nothing
call Table(this).destroy()
endmethod
//Like I said above...
static method create takes nothing returns thistype
return Table.create()
endmethod
endstruct
endlibrary
library UnitDex uses optional WorldBounds, optional GroupUtils
/***************************************************************
*
* v1.2.1, by TriggerHappy
* ¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯
* UnitDex assigns every unit an unique integer. It attempts to make that number within the
* maximum array limit so you can associate it with one.
* _________________________________________________________________________
* 1. Installation
* ¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯
* Copy the script to your map, save it, then restart the editor and comment out the line below.
*/
// external ObjectMerger w3a Adef uDex anam "Detect Leave" ansf "(UnitDex)" aart "" acat "" arac 0
/* ________________________________________________________________________
* 2. Configuration
* ¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯
*/
private module UnitDexConfig
// The raw code of the leave detection ability.
static constant integer DETECT_LEAVE_ABILITY = 'uDex'
// Allow debug messages (debug mode must also be on)
static constant boolean ALLOW_DEBUGGING = true
// Uncomment the lines below to define a filter for units being indexed
/*static method onFilter takes unit u returns boolean
return true
endmethod*/
endmodule
/* _________________________________________________________________________
* 3. Function API
* ¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯
* Every function inlines except for UnitDexRemove
*
* function GetUnitId takes unit whichUnit returns integer
* function GetUnitById takes integer index returns unit
*
* function UnitDexEnable takes boolean flag returns nothing
* function UnitDexRemove takes unit u, boolean runEvents returns boolean
*
* function IsUnitIndexed takes unit u returns boolean
* function IsIndexingEnabled takes nothing returns boolean
*
* function GetIndexedUnit takes nothing returns unit
* function GetIndexedUnitId takes nothing returns integer
*
* function RegisterUnitIndexEvent takes boolexpr func, integer eventtype returns indexevent
* function RemoveUnitIndexEvent takes triggercondition c, integer eventtype returns nothing
* function TriggerRegisterUnitIndexEvent takes trigger t, integer eventtype returns nothing
*
* function OnUnitIndex takes code func returns triggercondition
* function OnUnitDeidex takes code func returns triggercondition
* _________________________________________________________________________
* 4. Struct API
* ¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯
* UnitDex.Enabled = false // toggle the indexer
* UnitDex.Initialized // returns true if the preload timer has finished
* UnitDex.Count // returns the amount of units indexed
* UnitDex.Unit[0] // access the UnitDex array directly
* UnitDex.Group // a unit group containing every indexed unit (for enumeration)
* UnitDex.LastIndex // returns the last indexed unit's id
* _________________________________________________________________________
* 5. Public Variables
* ¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯
* These are to be used with the "eventtype" argument of the event API:
*
* constant integer EVENT_UNIT_INDEX = 0
* constant integer EVENT_UNIT_DEINDEX = 1
* _________________________________________________________________________
* 6. Examples
* ¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯
* 1. Associate a unit with a variable
*
* set UnitFlag[GetUnitId(yourUnit)] = true
*
* 2. Allocate a struct instance using a units assigned ID
*
* local somestruct data = GetUnitId(yourUnit)
*
* 3. Detect when a unit leaves the map
*
* function Exit takes nothing returns nothing
* call BJDebugMsg("The unit " + GetUnitName(GetIndexedUnit()) + " has left the map.")
* endfunction
*
* call OnUnitDeindex(function Exit)
* // or
* call RegisterUnitIndexEvent(Filter(function Exit), EVENT_UNIT_DEINDEX)
*
*
* _________________________________________________________________________
* 7. How it works
* ¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯
* 1. Enumerate all preplaced units
* 2. TriggerRegisterEnterRegion native to detect when a unit enters the map
* 3. Assign each unit that enters the map a unique integer
* 4. Give every unit an ability based off of defend. There is no native to accurately
* detect when a unit leaves the map but when a unit dies or is removed from the game
* they are issued the "undefend" order
* 5. Catch the "undefend" order and remove unit from the queue
* _________________________________________________________________________
* 8. Notes
* ¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯
* - This system is compatable with GUI because it utilizes UnitUserData (custom values for units).
* - The object merger line should be commented out after saving and restarting.
* - All public functions are inlined except UnitDexRemove.
*
* -http://www.hiveworkshop.com/forums/submissions-414/unitdex-lightweight-unit-indexer-248209/
*
* ¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯
*/
globals
// Event types
constant integer EVENT_UNIT_INDEX = 0
constant integer EVENT_UNIT_DEINDEX = 1
// System variables
private trigger array IndexTrig
private integer Index = 0
private real E=-1
private boolexpr FilterEnter
endglobals
function GetUnitId takes unit whichUnit returns integer
return GetUnitUserData(whichUnit)
endfunction
function GetUnitById takes integer index returns unit
return UnitDex.Unit[index]
endfunction
function GetIndexedUnit takes nothing returns unit
return UnitDex.Unit[UnitDex.LastIndex]
endfunction
function GetIndexedUnitId takes nothing returns integer
return UnitDex.LastIndex
endfunction
function IsUnitIndexed takes unit u returns boolean
return (GetUnitById(GetUnitId(u)) != null)
endfunction
function UnitDexEnable takes boolean flag returns nothing
set UnitDex.Enabled = flag
endfunction
function IsIndexingEnabled takes nothing returns boolean
return UnitDex.Enabled
endfunction
function RegisterUnitIndexEvent takes boolexpr func, integer eventtype returns triggercondition
return TriggerAddCondition(IndexTrig[eventtype], func)
endfunction
function RemoveUnitIndexEvent takes triggercondition c, integer eventtype returns nothing
call TriggerRemoveCondition(IndexTrig[eventtype], c)
endfunction
function TriggerRegisterUnitIndexEvent takes trigger t, integer eventtype returns nothing
call TriggerRegisterVariableEvent(t, SCOPE_PRIVATE + "E", EQUAL, eventtype)
endfunction
function OnUnitIndex takes code func returns triggercondition
return TriggerAddCondition(IndexTrig[EVENT_UNIT_INDEX], Filter(func))
endfunction
function OnUnitDeindex takes code func returns triggercondition
return TriggerAddCondition(IndexTrig[EVENT_UNIT_DEINDEX], Filter(func))
endfunction
function UnitDexRemove takes unit u, boolean runEvents returns boolean
return UnitDex.Remove(u, runEvents)
endfunction
/****************************************************************/
private keyword UnitDexCore
struct UnitDex extends array
static boolean Enabled = true
readonly static integer LastIndex
readonly static boolean Initialized=false
readonly static group Group=CreateGroup()
readonly static unit array Unit
readonly static integer Count = 0
readonly static integer array List
implement UnitDexConfig
private static integer Counter = 0
implement UnitDexCore
endstruct
/****************************************************************/
private module UnitDexCore
static method Remove takes unit u, boolean runEvents returns boolean
local integer i
if (IsUnitIndexed(u)) then
set i = GetUnitId(u)
set UnitDex.List[i] = Index
set Index = i
call GroupRemoveUnit(UnitDex.Group, u)
call SetUnitUserData(u, 0)
if (runEvents) then
set UnitDex.LastIndex = i
set E = EVENT_UNIT_DEINDEX
call TriggerEvaluate(IndexTrig[EVENT_UNIT_DEINDEX])
set E = -1
endif
set UnitDex.Unit[i] = null
set UnitDex.Count = UnitDex.Count - 1
return true
endif
return false
endmethod
private static method onGameStart takes nothing returns nothing
local integer i = 0
static if (not LIBRARY_GroupUtils) then // Check if GroupUtils exists so we can use it's enumeration group.
local group ENUM_GROUP = CreateGroup() // If not, create the group.
endif
// Index preplaced units
loop
call GroupEnumUnitsOfPlayer(ENUM_GROUP, Player(i), FilterEnter)
set i = i + 1
exitwhen i == bj_MAX_PLAYER_SLOTS
endloop
static if (not LIBRARY_GroupUtils) then
call DestroyGroup(ENUM_GROUP)
set ENUM_GROUP = null
endif
// run init triggers
set i = 1
loop
exitwhen i > Counter
set LastIndex = i
call TriggerEvaluate(IndexTrig[EVENT_UNIT_INDEX])
set E = EVENT_UNIT_INDEX
set E = -1
set i = i + 1
endloop
set LastIndex = Counter
set Initialized = true
set FilterEnter = null
call DestroyTimer(GetExpiredTimer())
endmethod
private static method onEnter takes nothing returns boolean
local unit u = GetFilterUnit()
local integer i = GetUnitId(u)
local integer t = Index
if (i == 0 and thistype.Enabled) then
// If a filter was defined pass the unit through it.
static if (thistype.onFilter.exists) then
if (not thistype.onFilter(u)) then
set u = null
return false // check failed
endif
endif
// Handle debugging
static if (thistype.DEBUG_MODE and thistype.ALLOW_DEBUGGING) then
if (t == 0 and Counter+1 >= JASS_MAX_ARRAY_SIZE) then
call DisplayTextToPlayer(GetLocalPlayer(), 0, 0, "UnitDex: Maximum number of units reached!")
set u = null
return false
endif
endif
// Add to group of indexed units
call GroupAddUnit(thistype.Group, u)
// Give unit the leave detection ability
call UnitAddAbility(u, thistype.DETECT_LEAVE_ABILITY)
call UnitMakeAbilityPermanent(u, true, thistype.DETECT_LEAVE_ABILITY)
// Allocate index
if (Index != 0) then
set Index = List[t]
else
set Counter = Counter + 1
set t = Counter
endif
set List[t] = -1
set LastIndex = t
set thistype.Unit[t] = u
set Count = Count + 1
// Store the index
call SetUnitUserData(u, t)
if (thistype.Initialized) then
// Execute custom events registered with RegisterUnitIndexEvent
call TriggerEvaluate(IndexTrig[EVENT_UNIT_INDEX])
// Handle TriggerRegisterUnitIndexEvent
set E = EVENT_UNIT_INDEX
// Reset so the event can occur again
set E = -1
endif
endif
set u = null
return false
endmethod
private static method onLeave takes nothing returns boolean
local unit u
local integer i
// Check if order is undefend.
if (thistype.Enabled and GetIssuedOrderId() == 852056) then
set u = GetTriggerUnit()
// If unit was killed (not removed) then don't continue
if (GetUnitAbilityLevel(u, thistype.DETECT_LEAVE_ABILITY) != 0) then
set u = null
return false
endif
set i = GetUnitId(u)
// If unit has been indexed then deindex it
if (i > 0 and i <= Counter and u == GetUnitById(i)) then
// Recycle the index
set List[i] = Index
set Index = i
set LastIndex = i
// Remove to group of indexed units
call GroupRemoveUnit(thistype.Group, u)
// Execute custom events without any associated triggers
call TriggerEvaluate(IndexTrig[EVENT_UNIT_DEINDEX])
// Handle TriggerRegisterUnitIndexEvent
set E = EVENT_UNIT_DEINDEX
// Remove entry
call SetUnitUserData(u, 0)
set thistype.Unit[i] = null
// Decrement unit count
set Count = Count - 1
// Reset so the event can occur again
set E = -1
endif
set u = null
endif
return false
endmethod
private static method onInit takes nothing returns nothing
local trigger t = CreateTrigger()
local integer i = 0
local player p
local unit u
static if (not LIBRARY_WorldBounds) then // Check if WorldBounts exists, if not then define the necessary vars
local region reg = CreateRegion() // If WorldBounds wasn't found, create the region manually
local rect world = GetWorldBounds()
endif
set FilterEnter = Filter(function thistype.onEnter)
// Begin to index units when they enter the map
static if (LIBRARY_WorldBounds) then
call TriggerRegisterEnterRegion(CreateTrigger(), WorldBounds.worldRegion, FilterEnter)
else
call RegionAddRect(reg, world)
call TriggerRegisterEnterRegion(CreateTrigger(), reg, FilterEnter)
call RemoveRect(world)
set world = null
endif
call TriggerAddCondition(t, Filter(function thistype.onLeave))
set IndexTrig[EVENT_UNIT_INDEX] = CreateTrigger()
set IndexTrig[EVENT_UNIT_DEINDEX] = CreateTrigger()
loop
set p = Player(i)
// Detect "undefend"
call TriggerRegisterPlayerUnitEvent(t, p, EVENT_PLAYER_UNIT_ISSUED_ORDER, null)
// Hide the detect ability from players
call SetPlayerAbilityAvailable(p, thistype.DETECT_LEAVE_ABILITY, false)
set i = i + 1
exitwhen i == bj_MAX_PLAYER_SLOTS
endloop
call TimerStart(CreateTimer(), 0, false, function thistype.onGameStart)
endmethod
endmodule
endlibrary
library DummyRecycler /*
// DummyRecycler v1.24
// by Flux
//
// A system that recycles dummy units while considering their facing angle.
// It can be used as attachment units or as dummy caster.
//
// Why is recycling a unit important?
// Because creating a unit is is one of the slowest function in the game
// and it will always leave a permanent tiny bit of memory (0.04 KB).
// Furthermore, if a Damage Detection System (DDS) or a Unit Indexer is
// imported to your map, using this system will even result to better
// performance because DDS and Unit Indexer process new created units.
//
//
*/ requires /*
nothing
*/ optional Table/*
if not found, this system will use a hashtable. Hashtables are limited to
255 per map.
*/ optional WorldBounds /*
if not found, this system will initialize its own Map Boundaries.
//
//
// Features:
//
// -- Dummy Sharing
// When a Dummy List gets low on unit count, it will borrow Dummy Units
// from the Dummy List with the highest unit count. The transfer is not
// instant because the shared Dummy Unit has to turn to the appropriate
// angle of its new Dummy List before it can be recycled.
// See BORROW_REQUEST.
//
// -- Self-balancing recycling algorithm
// Recycled Dummy Units will be thrown to the List having the least number
// of Dummy Units.
//
// -- Recycling least used
// Allows recycling a Dummy from the Dummy List with the highest
// unit count. It is useful when the facing angle of the Dummy Unit
// does not matter.
// See GetRecycledDummyAnyAngle.
//
// -- Self-adaptation
// When there are no free Dummy Units from a Dummy List, it will end up creating
// a new unit instead but that unit will be permanently added as a Dummy
// Unit to be recycled increasing the overall total Dummy Unit count.
//
// -- Count control
// Allows limiting the overall number of Dummy Units.
// See MAX_DUMMY_COUNT.
//
// -- Delayed Recycle
// Allows recycling Dummy Units after some delay to allocate time for the
// death animation of Special Effects to be seen.
// See DummyAddRecycleTimer.
//
// ******************************************************************
// ***************************** API: *******************************
// ******************************************************************
//
// function GetRecycledDummy takes real x, real y, real z, real facing returns unit
// - Retrieve an unused Dummy Unit from the List.
// - The equivalent of CreateUnit.
// - To use as a Dummy Caster, follow it with PauseUnit(dummy, false).
//
// function GetRecycledDummyAnyAngle takes real x, real y, real z returns unit
// - Use this function if the facing angle of the Dummy doesn't matter to you.
// - It will return a unit from the list having the highest number of unused Dummy Units.
// - To use as a Dummy Caster, follow it with PauseUnit(dummy, false).
//
// function RecycleDummy takes unit u returns nothing
// - Recycle the Dummy unit for it to be used again later.
// - The equivalent of RemoveUnit.
//
// function DummyAddRecycleTimer takes unit u, real time returns nothing
// - Recycle the Dummy unit after a certain time.
// - Use this to allocate time for the the death animation of an effect attached to the
// Dummy Unit to finish..
// - The equivalent of UnitApplyTimedLife.
//
//--------------------
// CREDITS
//--------------------
// Bribe - for the MissileRecycler (vJASS) where I got this concept from
// http://www.hiveworkshop.com/forums/jass-resources-412/system-missilerecycler-206086/
// - for the optional Table
// http://www.hiveworkshop.com/forums/jass-resources-412/snippet-new-table-188084/
// Vexorian - for the Attachable and Pitch Animation Model (dummy.mdx)
// http://www.wc3c.net/showthread.php?t=101150
// Maker and IcemanBo - for the unit permanent 0.04 KB memory leak of units.
// http://www.hiveworkshop.com/forums/trigger-gui-editor-tutorials-279/memory-leaks-263410/
// Nestharus - for the data structure
// http://www.hiveworkshop.com/forums/2809461-post7.html
// - for the optional WorldBounds
// http://githubusercontent.com/nestharus/JASS/master/jass/Systems/WorldBounds/script.j
// =============================================================== //
// ====================== CONFIGURATION ========================== //
// =============================================================== */
globals
//The rawcode of the Dummy Unit
private constant integer DUMMY_ID = 'h000'
//The owner of the Dummy Unit
private constant player OWNER = Player(15)
//The number of indexed angle. The higher the value the:
// - Lesser the turning time for the Dummy Units.
// - Higher the total number of Dummy Units created at Map Initialization.
// Recommended Value: 10 (Max difference of 18 degrees)
private constant integer ANGLES_COUNT = 10
//The number of Dummy units per ANGLES_COUNT. The higher the value the:
// - Higher the number of units that can be recycled per angle, when
// no more units are in queue, the system will resort to use CreateUnit.
// - Higher the total number of Dummy Units created at Map Initialization.
// Recommended Value: 3 to 5 (for less overhead in Map Loading Screen)
private constant integer STORED_UNIT_COUNT = 3
//The maximum number of Dummy units that can exist. When the system resort
//to using CreateUnit, the unit will be permanently added to the Dummy
//List. To avoid spamming Dummy Units and having too much free Dummy
//Units to allocate, the maximum number of Dummy Units is capped.
// Recommended Value: 80 to 120
private constant integer MAX_DUMMY_COUNT = 100
//When a certain angle have less than BORROW_REQUEST units in its list,
//it will start to borrow Dummy Units from the list with the highest
//Dummy Unit count.
// Recommended Value: Half of maximum STORED_UNIT_COUNT
private constant integer BORROW_REQUEST = 5
//It will only return a Dummy if the current dummy is close
//to it's appropriate facing angle. This is to avoid returning
//a Dummy which is still turning to face it's list angle.
private constant real ANGLE_TOLERANCE = 10.0
//An additional option to automatically hide recycled dummy units in the
//corner of the map camera bounds
private constant boolean HIDE_ON_MAP_CORNER = true
endglobals
//Every time a new dummy unit is retrieved, it will apply this resets
//If it is redundant/you dont need it, remove it.
//! textmacro DUMMY_UNIT_RESET
call SetUnitScale(bj_lastCreatedUnit, 1, 0, 0)
call SetUnitVertexColor(bj_lastCreatedUnit, 255, 255, 255, 255)
call SetUnitAnimationByIndex(bj_lastCreatedUnit, 90)
//! endtextmacro
// =============================================================== //
// ==================== END CONFIGURATION ======================== //
// =============================================================== //
globals
private integer dummyCount = ANGLES_COUNT*STORED_UNIT_COUNT
private real array angle
private integer array count
private integer array countHead
private integer array countNext
private integer array countPrev
private integer array next
private integer array prev
private unit array dummy
private integer upper
private integer lower
private integer lastInstance
private constant real FACING_OFFSET = 180.0/ANGLES_COUNT
endglobals
static if HIDE_ON_MAP_CORNER and not LIBRARY_WorldBounds then
private module BoundsInit
readonly static real x
readonly static real y
private static method onInit takes nothing returns nothing
local rect map = GetWorldBounds()
set thistype.x = GetRectMaxX(map)
set thistype.y = GetRectMaxY(map)
call RemoveRect(map)
set map = null
endmethod
endmodule
private struct Bounds extends array
implement BoundsInit
endstruct
endif
private module M
static if LIBRARY_Table then
static Table tb
else
static hashtable hash = InitHashtable()
endif
private static method onInit takes nothing returns nothing
local real add = 360.0/ANGLES_COUNT
local real a = 0
local integer this = ANGLES_COUNT
local integer head = 0
local integer cHead = JASS_MAX_ARRAY_SIZE - 1 //avoid allocation collision
local integer i = R2I(MAX_DUMMY_COUNT/ANGLES_COUNT + 0.5)
set upper = STORED_UNIT_COUNT
set lower = STORED_UNIT_COUNT
static if LIBRARY_Table then
set tb = Table.create()
endif
//Initialize countHeads
loop
exitwhen i < 0
set countNext[cHead] = cHead
set countPrev[cHead] = cHead
set countHead[i] = cHead
set cHead = cHead - 1
set i = i - 1
endloop
set cHead = countHead[STORED_UNIT_COUNT] //All heads will be inserted here initially
//Create the Dummy units
loop
exitwhen a >= 360
//Initialize head
set next[head] = head
set prev[head] = head
set count[head] = STORED_UNIT_COUNT
set angle[head] = a
//Insert head in the Count List
set countNext[head] = cHead
set countPrev[head] = countPrev[cHead]
set countNext[countPrev[head]] = head
set countPrev[countNext[head]] = head
set i = 0
loop
exitwhen i >= STORED_UNIT_COUNT
//Queued Linked List
set next[this] = head
set prev[this] = prev[head]
set next[prev[this]] = this
set prev[next[this]] = this
static if HIDE_ON_MAP_CORNER then
static if LIBRARY_WorldBounds then
set dummy[this] = CreateUnit(OWNER, DUMMY_ID, WorldBounds.maxX, WorldBounds.maxY, a)
else
set dummy[this] = CreateUnit(OWNER, DUMMY_ID, Bounds.x, Bounds.y, a)
endif
else
set dummy[this] = CreateUnit(OWNER, DUMMY_ID, 0, 0, a)
endif
call PauseUnit(dummy[this], true)
static if LIBRARY_Table then
set tb[GetHandleId(dummy[this])] = this
else
call SaveInteger(hash, GetHandleId(dummy[this]), 0, this)
endif
set this = this + 1
set i = i + 1
endloop
set head = head + 1
set a = a + add
endloop
set lastInstance = this
endmethod
endmodule
private struct S extends array
implement M
endstruct
private function GetHead takes integer facing returns integer
if facing < 0 or facing >= 360 then
set facing = facing - (facing/360)*360
if facing < 0 then
set facing = facing + 360
endif
endif
return R2I((facing*ANGLES_COUNT/360.0))
endfunction
function GetRecycledDummy takes real x, real y, real z, real facing returns unit
local integer head = GetHead(R2I(facing + FACING_OFFSET))
local integer this = next[head]
local integer cHead
//If there are Dummy Units in the Queue List already facing close to the appropriate angle
if this != head and RAbsBJ(GetUnitFacing(dummy[this]) - angle[head]) <= ANGLE_TOLERANCE then
//Remove from the Queue List
set next[prev[this]] = next[this]
set prev[next[this]] = prev[this]
//For double free protection
set next[this] = -1
//Unit Properties
set bj_lastCreatedUnit = dummy[this]
call SetUnitX(bj_lastCreatedUnit, x)
call SetUnitY(bj_lastCreatedUnit, y)
call SetUnitFacing(bj_lastCreatedUnit, facing)
call SetUnitFlyHeight(bj_lastCreatedUnit, z, 0)
//! runtextmacro DUMMY_UNIT_RESET()
//Update Count and Bounds
set count[head] = count[head] - 1
//------------------------------------------------
// Unit Sharing
//------------------------------------------------
if count[head] < BORROW_REQUEST and count[countNext[countHead[upper]]] > count[head] then
set count[head] = count[head] + 1
set this = next[countNext[countHead[upper]]]
call SetUnitFacing(dummy[this], angle[head])
//Remove
set next[prev[this]] = next[this]
set prev[next[this]] = prev[this]
//Add to the Current List
set next[this] = head
set prev[this] = prev[head]
set next[prev[this]] = this
set prev[next[this]] = this
set head = countNext[countHead[upper]]
set count[head] = count[head] - 1
endif
//---------------------------
//Update Count Lists
//---------------------------
//Remove from the current Count List
set countNext[countPrev[head]] = countNext[head]
set countPrev[countNext[head]] = countPrev[head]
//Add to the new Count List
set cHead = countHead[count[head]]
set countNext[head] = cHead
set countPrev[head] = countPrev[cHead]
set countNext[countPrev[head]] = head
set countPrev[countNext[head]] = head
//---------------------------
// Update Bounds
//---------------------------
set cHead = countHead[upper]
if countNext[cHead] == cHead then
set upper = upper - 1
endif
if count[head] < lower then
set lower = count[head]
endif
else
set bj_lastCreatedUnit = CreateUnit(OWNER, DUMMY_ID, x, y, facing)
call PauseUnit(bj_lastCreatedUnit, true)
call SetUnitFlyHeight(bj_lastCreatedUnit, z, 0)
if dummyCount < MAX_DUMMY_COUNT then
set this = lastInstance
//For double free protection
set next[this] = -1
set dummy[this] = bj_lastCreatedUnit
static if LIBRARY_Table then
set S.tb[GetHandleId(bj_lastCreatedUnit)] = this
else
call SaveInteger(S.hash, GetHandleId(bj_lastCreatedUnit), 0, this)
endif
set lastInstance = lastInstance + 1
endif
set dummyCount = dummyCount + 1
endif
return bj_lastCreatedUnit
endfunction
function RecycleDummy takes unit u returns nothing
static if LIBRARY_Table then
local integer this = S.tb[GetHandleId(u)]
else
local integer this = LoadInteger(S.hash, GetHandleId(u), 0)
endif
local integer head
local integer cHead
//If the unit is a legit Dummy Unit
if this > 0 and next[this] == -1 then
//Find where to insert based on the list having the least number of units
set head = countNext[countHead[lower]]
set next[this] = head
set prev[this] = prev[head]
set next[prev[this]] = this
set prev[next[this]] = this
//Update Status
call SetUnitFacing(u, angle[head])
call PauseUnit(u, true)
call SetUnitOwner(u, OWNER, false)
static if HIDE_ON_MAP_CORNER then
static if LIBRARY_WorldBounds then
call SetUnitX(u, WorldBounds.maxX)
call SetUnitY(u, WorldBounds.maxY)
else
call SetUnitX(u, Bounds.x)
call SetUnitY(u, Bounds.y)
endif
else
call SetUnitScale(u, 0, 0, 0)
call SetUnitVertexColor(u, 0, 0, 0, 0)
endif
set count[head] = count[head] + 1
//---------------------------
// Update Count Lists
//---------------------------
//Remove
set countNext[countPrev[head]] = countNext[head]
set countPrev[countNext[head]] = countPrev[head]
//Add to the new Count List
set cHead = countHead[count[head]]
set countNext[head] = cHead
set countPrev[head] = countPrev[cHead]
set countNext[countPrev[head]] = head
set countPrev[countNext[head]] = head
//---------------------------
// Update Bounds
//---------------------------
set cHead = countHead[lower]
if countNext[cHead] == cHead then
set lower = lower + 1
endif
if count[head] > upper then
set upper = count[head]
endif
elseif this == 0 then
call RemoveUnit(u)
debug elseif next[this] != -1 then
debug call BJDebugMsg("|cffffcc00[DummyRecycler]:|r Attempted to recycle a pending/free Dummy Unit.")
endif
endfunction
private function Expires takes nothing returns nothing
local timer t = GetExpiredTimer()
local integer id = GetHandleId(t)
static if LIBRARY_Table then
call RecycleDummy(S.tb.unit[id])
call S.tb.unit.remove(id)
else
call RecycleDummy(LoadUnitHandle(S.hash, id, 0))
call FlushChildHashtable(S.hash, id)
endif
call DestroyTimer(t)
set t = null
endfunction
function DummyAddRecycleTimer takes unit u, real time returns nothing
local timer t = CreateTimer()
static if LIBRARY_Table then
set S.tb.unit[GetHandleId(t)] = u
else
call SaveUnitHandle(S.hash, GetHandleId(t), 0, u)
endif
call TimerStart(t, time, false, function Expires)
set t = null
endfunction
function GetRecycledDummyAnyAngle takes real x, real y, real z returns unit
return GetRecycledDummy(x, y, z, angle[countNext[countHead[upper]]])
endfunction
// runtextmacro DUMMY_DEBUG_TOOLS()
endlibrary
library WorldBounds /* v2.0.0.0
************************************************************************************
*
* struct WorldBounds extends array
*
* Fields
* -------------------------
*
* readonly static integer maxX
* readonly static integer maxY
* readonly static integer minX
* readonly static integer minY
*
* readonly static integer centerX
* readonly static integer centerY
*
* readonly static rect world
* readonly static region worldRegion
*
************************************************************************************/
private module WorldBoundInit
private static method onInit takes nothing returns nothing
set world=GetWorldBounds()
set maxX = R2I(GetRectMaxX(world))
set maxY = R2I(GetRectMaxY(world))
set minX = R2I(GetRectMinX(world))
set minY = R2I(GetRectMinY(world))
set centerX = R2I((maxX + minX)/2)
set centerY = R2I((minY + maxY)/2)
set worldRegion = CreateRegion()
call RegionAddRect(worldRegion, world)
endmethod
endmodule
struct WorldBounds extends array
readonly static integer maxX
readonly static integer maxY
readonly static integer minX
readonly static integer minY
readonly static integer centerX
readonly static integer centerY
readonly static rect world
readonly static region worldRegion
implement WorldBoundInit
endstruct
endlibrary
library AutoFly initializer onInit requires UnitDex
/***************************************************************
*
* v1.0, by TriggerHappy
* ¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯
* AutoFly adds & removes crow of upon any unit entering the map. This
* allows modifying of the units height without having to do it manually.
*
* Credits go to azlier for the orginal idea.
*
****************************************************************/
globals
private constant integer CROW_FORM = 'Amrf'
endglobals
private function AddFly takes nothing returns boolean
return UnitAddAbility(GetIndexedUnit(), CROW_FORM) and UnitRemoveAbility(GetIndexedUnit(), CROW_FORM)
endfunction
private function onInit takes nothing returns nothing
call RegisterUnitIndexEvent(Filter(function AddFly), EVENT_UNIT_INDEX)
endfunction
endlibrary
scope TorrentOfTheAdmiral /* spell taken from DotA */ initializer Init
/*============================= Spell Configuration ============================*/
private constant function SpellId takes nothing returns integer
return 'TOR1'
endfunction
private constant function TossDuration takes integer level returns real
return 1.75 + 0.00*level
endfunction
private constant function ExplosionDelay takes integer level returns real
return 2.00 + 0.00*level
endfunction
private constant function Radius takes integer level returns real
return 200.00 + 0.00*level
endfunction
private constant function InitialDamage takes integer level returns real
return 100.00 + 20.00*level
endfunction
private constant function DamagePerSecond takes integer level returns real
return 10.00 + 5.00*level
endfunction
private constant function TossHeight takes integer level returns real
return 600.00 + 0.00*level
endfunction
private constant function BorderCount takes integer level returns integer
return 20 + 0*level
endfunction
private constant function AttackType takes nothing returns attacktype
return ATTACK_TYPE_HERO
endfunction
private constant function DamageType takes nothing returns damagetype
return DAMAGE_TYPE_NORMAL
endfunction
private constant function WeaponType takes nothing returns weapontype
return null
endfunction
private constant function TorrentModel takes nothing returns string
return "Objects\\Spawnmodels\\Naga\\NagaDeath\\NagaDeath.mdl"
endfunction
private constant function TorrentBorderModel takes nothing returns string
return "Abilities\\Weapons\\ZigguratMissile\\ZigguratMissile.mdl"
endfunction
private function TargetFilter takes nothing returns boolean
return GetFilterUnit() != Torrent.triggerInstance.caster
endfunction
/*==============================================================================*/
globals
private hashtable table = InitHashtable()
endglobals
private function Explode takes nothing returns nothing
local timer t = GetExpiredTimer()
call Torrent(LoadInteger(table, 0, GetHandleId(t))).explode(true)
call DestroyTimer(t)
set t = null
endfunction
private function OnCast takes nothing returns boolean
local Torrent torrent
local timer t
local unit u
local integer level
if GetSpellAbilityId() == SpellId() then
set u = GetTriggerUnit()
set level = GetUnitAbilityLevel(u, SpellId())
set torrent = Torrent.create(GetSpellTargetX(), GetSpellTargetY(), Radius(level), BorderCount(level), TorrentModel(), TorrentBorderModel(), null)
set torrent.caster = u
set torrent.duration = TossDuration(level)
set torrent.explosionDamage = InitialDamage(level)
set torrent.damagePerSecond = DamagePerSecond(level)
set torrent.height = TossHeight(level)
set torrent.attackType = AttackType()
set torrent.damageType = DamageType()
set torrent.weaponType = WeaponType()
set torrent.filterExpr = Filter(function TargetFilter) //Allows all units except the caster
set t = CreateTimer()
call SaveInteger(table, 0, GetHandleId(t), torrent)
call TimerStart(t, ExplosionDelay(level), false, function Explode)
set u = null
set t = null
endif
return false
endfunction
private function Init takes nothing returns nothing
local trigger t = CreateTrigger()
call TriggerRegisterAnyUnitEventBJ(t, EVENT_PLAYER_UNIT_SPELL_EFFECT)
call TriggerAddCondition(t, Filter(function OnCast))
set t = null
endfunction
endscope