- Joined
- Apr 24, 2012
- Messages
- 5,113
Allows you to automatically create spell structs.
Demo:
TestMap:
JASS:
library SpellMacro
/*
Allows you to automatically create spell structs
Thanks to Bribe for SpellEffectEvent
Warning:
All spells must be inside a library and the library must require SpellEffectEvent
The two methods for cast and periodic effect must be named cast and periodic
method shall be inside a module
*/
//! textmacro NEW_SPELL takes NAME, MODULE, ABILITY
private struct $NAME$ extends array
static integer array n
static integer array p
static integer ic = 0
static integer array r
static integer c = 0
static timer t = CreateTimer()
static real TIMEOUT = 0.031250000
static method allocate takes nothing returns $NAME$
local $NAME$ this = r[0]
if 0 == this then
set ic = ic + 1
return ic
endif
set r[0] = r[this]
return this
endmethod
method deallocate takes nothing returns nothing
set r[this] = r[0]
set r[0] = this
endmethod
method add takes nothing returns nothing
set n[this] = 0
set p[this] = 0
set n[p[0]] = this
set p[0] = this
endmethod
method remove takes nothing returns nothing
set n[p[this]] = n[this]
set p[n[this]] = p[this]
endmethod
method destroy takes nothing returns nothing
call this.remove()
call this.deallocate()
set c = c - 1
if 0 == c then
call PauseTimer(t)
endif
endmethod
implement $MODULE$
static method update takes nothing returns nothing
local $NAME$ this = n[0]
loop
exitwhen 0 == this
call this.periodic()
set this = n[this]
endloop
endmethod
static method run takes nothing returns boolean
local $NAME$ this = $NAME$.allocate()
call this.add()
call this.cast()
set c = c + 1
if 1 == c then
call TimerStart(t, TIMEOUT, true, function $NAME$.update)
endif
return false
endmethod
static method onInit takes nothing returns nothing
call RegisterSpellEffectEvent($ABILITY$, function $NAME$.run)
endmethod
endstruct
//! endtextmacro
endlibrary
Demo:
JASS:
library Test requires SpellEffectEvent SpellMacro
module Test
static unit array u
static real array d
static integer clap = 'AHtc'
method periodic takes nothing returns nothing
if 0 < d[this] then
set d[this] = d[this] - TIMEOUT
call DestroyEffect(AddSpecialEffect("Abilities\\Spells\\Human\\Feedback\\ArcaneTowerAttack.mdl", GetUnitX(u[this]), GetUnitY(u[this])))
else
call this.destroy()
set u[this] = null
set d[this] = 0
endif
endmethod
method cast takes nothing returns nothing
set u[this] = GetTriggerUnit()
set d[this] = 5
endmethod
endmodule
//! runtextmacro NEW_SPELL ("Clap", "Test", "clap")
endlibrary
TestMap: