- Joined
- Jul 10, 2007
- Messages
- 6,306
JASS:
library DamageSource /* v1.0.0.0
*************************************************************************************
*
* All damage creators require a damage source that represents the source of the damage
*
************************************************************************************
*
* struct DamageSourceType extends array
*
* static method create takes DamageSourceType parentType returns thistype
*
************************************************************************************
*
* struct DamageSource extends array
*
* readonly DamageSourceType type
*
* static method create takes DamageSourceType damageSourceType returns thistype
* method destroy takes nothing returns nothing
*
*************************************************************************************/
struct DamageSourceType extends array
private static integer instanceCount = 0
private thistype parentType
method operator == takes thistype damageSourceType returns boolean
if (integer(this) != integer(damageSourceType) and (0 == integer(this) or 0 == integer(damageSourceType))) then
return false
endif
loop
exitwhen integer(damageSourceType) == integer(this) or 0 == integer(this)
set this = parentType
endloop
return integer(this) == integer(damageSourceType)
endmethod
static method create takes DamageSourceType parentType returns thistype
local thistype this = instanceCount + 1
set instanceCount = this
set this.parentType = parentType
return this
endmethod
endstruct
struct DamageSource extends array
private static integer instanceCount = 0
private static integer array recycler
readonly DamageSourceType type
static method create takes DamageSourceType damageSourceType returns thistype
local thistype this = recycler[0]
if (0 == this) then
set this = instanceCount + 1
set instanceCount = this
else
set recycler[0] = recycler[this]
endif
set this.type = damageSourceType
return this
endmethod
method destroy takes nothing returns nothing
set recycler[this] = recycler[0]
set recycler[0] = this
endmethod
endstruct
endlibrary
Demonstration
JASS:
library DamageSourceTypes uses DamageSource
private module DamageSourceTypes_mod
readonly static DamageSourceType NULL = 0
readonly static DamageSourceType HANDS
readonly static DamageSourceType WEAPON
private static method onInit takes nothing returns nothing
set WEAPON = DamageSourceType.create(NULL)
set HANDS = DamageSourceType.create(WEAPON)
endmethod
endmodule
struct DamageSourceTypes extends array
implement DamageSourceTypes_mod
endstruct
endlibrary
Last edited: