- Joined
- Oct 23, 2011
- Messages
- 182
I thought it might be a good idea to use one effect array.. since you likely won't have 8191 effects in map at once.
edit: fixed error
Demo:
JASS:
library EffectList /* v1.0.0.4
*************************************************************************************
*
* This system allows you to easily manage and link effects.
*
*************************************************************************************
*
* struct Effect extends array
*
* Methods
* ------------------
* static method create takes nothing returns thistype
* - Creates a list of effects.
*
* method addPoint takes string s, real x, real y returns thistype
* - Add a point effect to list.
* method addTarget takes string s, unit u, string attachment returns thistype
* - Add a target effect to list.
*
* static method createPoint takes string s, real x, real y returns thistype
* - Creates an effect on point.
*
* static method createTarget takes string s, unit u, string attachment returns thistype
* - Creates an effect on target.
*
* method destroy takes nothing returns nothing
* - Destroys effect and any effects linked to the instance
*
**************************************************************************************/
struct Effect extends array
readonly thistype prev
readonly thistype next
readonly effect eff
readonly boolean head
readonly boolean linked
private static integer index = 0
method destroy takes nothing returns nothing
local thistype node
if .head then
set .head = false
set node = .next
loop
exitwhen node == this
call DestroyEffect(node.eff)
set node.eff = null
set node.linked = false
set node = node.next
endloop
set .next.prev = thistype(0).prev
else
if .linked then
set .linked = false
set .prev.next = .next
set .next.prev = .prev
endif
set .prev = thistype(0).prev
call DestroyEffect(.eff)
set .eff = null
endif
set thistype(0).prev = this
endmethod
private static method allocate takes nothing returns thistype
local thistype this = thistype(0).prev
if this == 0 then
set index = index + 1
set this = index
else
set thistype(0).prev = .prev
endif
return this
endmethod
private method linkNode takes thistype node returns thistype
set node.prev = .prev
set .prev.next = node
set .prev = node
set node.next = this
set node.linked = true
return node
endmethod
private static method createNode takes effect e returns thistype
local thistype this = thistype.allocate()
set .eff = e
return this
endmethod
static method createPoint takes string s, real x, real y returns thistype
return createNode(AddSpecialEffect(s, x, y))
endmethod
static method createTarget takes string s, unit u, string a returns thistype
return createNode(AddSpecialEffectTarget(s, u, a))
endmethod
method addPoint takes string s, real x, real y returns thistype
return .linkNode(createPoint(s, x, y))
endmethod
method addTarget takes string s, unit u, string a returns thistype
return .linkNode(createTarget(s, u, a))
endmethod
static method create takes nothing returns thistype
local thistype this = thistype.allocate()
set .prev = this
set .next = this
set .head = true
return this
endmethod
endstruct
endlibrary
edit: fixed error
Demo:
JASS:
struct Demo extends array
static Effect e1
static Effect e2
static Effect e3
private static method onInit takes nothing returns nothing
local unit u = CreateUnit(Player(0), 'hpea', 0, 0, 0)
set e1 = Effect.createTarget("Blabla.mdl", u, "origin") //Single effect
set e2 = Effect.create() //Multiple effect
set e3 = Effect.create() //Multiple effect
call e2.addTarget("Blabla.mdl", u, "hand right")
call e2.addTarget("Blabla.mdl", u, "hand left")
call e3.addTarget("Blabla.mdl", u, "hand right").addTarget("Blabla.mdl", u, "hand left")
call e1.destroy() //Single effect destroyed in this case
call e2.destroy() //Multiple effect destroyed in this case
call e3.destroy() //Multiple effect destroyed in this case
endmethod
endstruct
Last edited: