- Joined
- Apr 5, 2011
- Messages
- 245
[Snippet] Indexer
Reworked:
Example of usage (old):
SpellTypeIndexed:
SpellTypePoison:
Reworked:
JASS:
//===============
//=== Indexer ===
//=== v1.050 ====
/*************************************************************************
* Functions
* function CreateIndexer takes integer n returns integer
* - Creates an indexer meant for n instances and returns its id
* function IndexCount takes integer CODE returns integer
* - Returns count of indexes used by indexer
* (In very deed this returns the largest index used currently)
* function Indexed takes integer CODE, integer index returns boolean
* - Is this index of an indexer currently occupied
* function Index takes integer CODE returns integer
* - Occupies free index of an indexer and returns it
* function Deindex takes integer CODE, integer index returns boolean
* - Frees an index of an indexer
*
* Array data
* bool: ... [Indexer N created] ------------> [0 indexed] [1 indexed] ... [Indexer N+1 created] ...
* int: ... [Indexer N index count] [Freeindex address] [Freeindex 0] [Freeindex 1] ... [Indexer N+1 index count] ...
*************************************************************************/
library Indexer
//=== Settings ===
globals
private constant integer SIZE = 256
//================
private integer count = 0
private boolean array b
private integer array i
endglobals
function CreateIndexer takes integer n returns integer
local integer temp = count
set b[count] = true
set i[count] = 0
set i[count + 1] = 1
set count = count + n
return temp
endfunction
function IndexCount takes integer CODE returns integer
return i[CODE]
endfunction
function Indexed takes integer CODE, integer index returns boolean
return b[CODE + 1 + index]
endfunction
function Index takes integer CODE returns integer
local integer j = CODE + 1
local integer index
if i[j] == 1 then
set index = i[CODE]
set i[CODE] = i[CODE] + 1
else
set index = i[i[j]]
set i[j] = i[j] - 1
endif
set b[j + index] = true
return index
endfunction
function Deindex takes integer CODE, integer index returns boolean
local integer j = CODE + 1 + index
if b[j] then
set b[j] = false
if i[CODE] == index + 1 then
set i[CODE] = index
else
set CODE = CODE + 1
set i[CODE] = i[CODE] + 1
set i[i[CODE]] = index
endif
return true
endif
return false
endfunction
endlibrary
JASS:
//========================
//=== SpellPoisonSting ===
//======== v1.000 ========
library SpellPoisonSting requires Cast, Indexed, SpellTypePoison
//=== Settings ===
globals
private constant integer ABILCODE = 'X204'
private constant integer BUFFCODE = 'W012'
private constant integer SLOW_ABILITY = 'X206'
private constant string SLOW_ORDER = "slow"
//----------------
private constant integer TICK_COUNT = 15
private constant real TICK_TIME = 1
endglobals
struct SpellPoisonSting extends array
private static real array TICK_DAMAGE
private static method onInit takes nothing returns nothing
set TICK_DAMAGE[1] = 4
set TICK_DAMAGE[2] = 6
set TICK_DAMAGE[3] = 9
set TICK_DAMAGE[4] = 13
//================
set indexer = CreateIndexer()
endmethod
private static integer indexer
private static unit array target
private static unit array caster
private static integer array level
private static integer array tick_count
private static timer array t
private static method damage takes nothing returns nothing
set Assist.workTimer = GetExpiredTimer()
//! runtextmacro ObtainTimerIndex("t")
//! runtextmacro DealPurePoisonDamage()
if tick_count[Assist.workInteger] == 0 then
//! runtextmacro EndPoison("indexer")
endif
endmethod
static method onUnitTakesDamage takes nothing returns nothing
local integer level
if GetUnitAbilityLevel(Damage.target, BUFFCODE) != 0 then
call UnitRemoveAbility(Damage.target, BUFFCODE)
set level = GetUnitAbilityLevel(Damage.source, ABILCODE)
call CastUnit(Damage.source, Damage.target, CASTER_DEFAULT_LIFETIME, SLOW_ABILITY, level, SLOW_ORDER)
if level != 0 then
//! runtextmacro BreakPoison("indexer")
//! runtextmacro SetPoison("indexer")
set tick_count[Assist.workInteger] = TICK_COUNT
call TimerStart(t[Assist.workInteger], TICK_TIME, true, function thistype.damage)
endif
endif
endmethod
endstruct
endlibrary
JASS:
//===============
//=== Indexed ===
//=== v0.950 ====
library Indexed requires Indexer
//Timers
//! textmacro ObtainTimerIndex takes t
set Assist.workInteger = 0
loop
exitwhen $t$[Assist.workInteger] == Assist.workTimer
set Assist.workInteger = Assist.workInteger + 1
endloop
//! endtextmacro
//Units
//! textmacro ObtainUnitIndex takes u
set Assist.workInteger = 0
loop
exitwhen $u$[Assist.workInteger] == Assist.workUnit
set Assist.workInteger = Assist.workInteger + 1
endloop
//! endtextmacro
//! textmacro SeekUnit takes indexer, u
set Assist.workBoolean = false
set Assist.workInteger = 0
loop
exitwhen Assist.workInteger == IndexCount($indexer$) or Assist.workBoolean
if $u$[Assist.workInteger] == Assist.workUnit then
set Assist.workBoolean = true
endif
set Assist.workInteger = Assist.workInteger + 1
endloop
//! endtextmacro
endlibrary
JASS:
//=======================
//=== SpellTypePoison ===
//======= v1.000 ========
library SpellTypePoison requires Assist, Indexer, vGDC
//-=- General -=-
//! textmacro BreakPoison takes indexer
set Assist.workInteger = 0
loop
exitwhen Assist.workInteger == IndexCount($indexer$)
if target[Assist.workInteger] == Damage.target then
set tick_count[Assist.workInteger] = 1
set Assist.workInteger = IndexCount($indexer$)
else
set Assist.workInteger = Assist.workInteger + 1
endif
endloop
//! endtextmacro
//! textmacro SetPoison takes indexer
set Assist.workInteger = Index($indexer$)
set target[Assist.workInteger] = Damage.target
set caster[Assist.workInteger] = Damage.source
set thistype.level[Assist.workInteger] = level
if t[Assist.workInteger] == null then
set t[Assist.workInteger] = CreateTimer()
endif
//! endtextmacro
//! textmacro EndPoison takes indexer
call Deindex($indexer$, Assist.workInteger)
set target[Assist.workInteger] = null
set caster[Assist.workInteger] = null
call PauseTimer(t[Assist.workInteger])
//! endtextmacro
//-=- Pure poison -=-
//! textmacro DealPurePoisonDamage
set Assist.workReal = GetWidgetLife(target[Assist.workInteger])
if Assist.workReal != 0 then
if Assist.workReal < TICK_DAMAGE[level[Assist.workInteger]] then
call DealDamage(caster[Assist.workInteger], target[Assist.workInteger], ULTIMATE_DAMAGE, PURE, false)
set tick_count[Assist.workInteger] = 0
else
call SetWidgetLife(target[Assist.workInteger], Assist.workReal - TICK_DAMAGE[level[Assist.workInteger]])
set tick_count[Assist.workInteger] = tick_count[Assist.workInteger] - 1
endif
endif
//! endtextmacro
endlibrary
Last edited: