- Joined
- Jul 10, 2007
- Messages
- 6,306
JASS:
library DamageSourceInstance /* v1.0.0.1
*************************************************************************************
*
* Each damage source requires an instance. Must always create instance of damage
* in damage creator.
*
*************************************************************************************
*
* */uses/*
*
* */ DamageEvent /* hiveworkshop.com/forums/jass-resources-412/snippet-damageevent-186829/
*
************************************************************************************
*
* struct DamageSourceInstance extends array
*
* static method create takes UnitIndex target, DamageSource source returns DamageSourceInstance
*
*************************************************************************************/
globals
private Table instance
private Table locked
private integer instanceCount = 0
endglobals
private struct DamageSourceInstance_p extends array
private static method PRIORITY takes nothing returns integer
return DAMAGE_PRIORITY_CLEANUP
endmethod
private static method onDamage takes nothing returns nothing
if (1 == depth) then
call instance.flush()
call locked.flush()
set instanceCount = 0
else
set locked.boolean[sourceId*8192+targetId] = false
endif
endmethod
implement DamageEvent
endstruct
private module DamageSourceInstance_mod
private static method onInit takes nothing returns nothing
set locked = Table.create()
set instance = Table.create()
endmethod
endmodule
struct DamageSourceInstance extends array
static method create takes UnitIndex target, DamageSource source returns thistype
if (not locked.boolean[source*8192+target]) then
set locked.boolean[source*8192+target] = true
set instanceCount = instanceCount + 1
set instance[source*8192+target] = instanceCount
endif
return instance[source*8192+target]
endmethod
implement DamageSourceInstance_mod
endstruct
endlibrary