- Joined
- Feb 3, 2013
- Messages
- 277
Hi all I've been trying to learn more about structs and currently trying to recreate an unit indexer for the sake of practice.
The index works just fine, but the de - index won't go through - what am I doing wrong?
Okay i think its working now, but I'm not 100% sure..
The index works just fine, but the de - index won't go through - what am I doing wrong?
JASS:
scope JassUnitIndexer initializer init
globals
real indexEvent = 0.00
unit array units
integer array prev
integer array next
integer array rn
integer ic = 0
endglobals
private function indexUnits takes unit u returns nothing
local integer this = rn[0]
if this == 0 then
set ic = ic + 1
set this = ic
else
set rn[0] = rn[this]
endif
set next[this] = 0
set prev[this] = prev[0]
set next[prev[this]] = this
set prev[0] = this
set units[this] = u
call SetUnitUserData(units[this], this)
set indexEvent = 1.00
set indexEvent = 0.00
call BJDebugMsg("UNIT HAS BEEN INDEXED! UNIT " + GetUnitName(u) + " HAS BEEN INDEXED AS NUMBER " + I2S(this) + "!")
endfunction
private function initializeIndex takes nothing returns boolean
local unit lvUnit = GetTriggerUnit()
local integer this
set this = next[0]
loop
if GetUnitState(units[this], UNIT_STATE_LIFE) == 0 and units[this] != null then
call BJDebugMsg("Instance number " + I2S(this) + ", " + GetUnitName(units[this]) + " is being recycled!")
set units[this] = null
set prev[next[this]] = prev[this]
set next[prev[this]] = next[this]
set rn[this] = rn[0]
set rn[0] = this
set indexEvent = 2.00
set indexEvent = 0.00
set this = 0
endif
exitwhen next[this] == 0 or (GetUnitState(units[this], UNIT_STATE_LIFE) == 0 and units[this] != null)
set this = next[this]
endloop
call indexUnits(lvUnit)
set lvUnit = null
return false
endfunction
private function init takes nothing returns nothing
local trigger t = CreateTrigger()
local rect lvRect = GetWorldBounds()
local region lvReg = CreateRegion()
local group g = CreateGroup()
local unit fog
call GroupEnumUnitsInRect(g, lvRect, null)
loop
set fog = FirstOfGroup(g)
exitwhen fog == null
call indexUnits(fog)
call GroupRemoveUnit(g, fog)
endloop
call RegionAddRect(lvReg, lvRect)
call TriggerRegisterEnterRegion(t, lvReg, null)
call TriggerAddCondition(t, function initializeIndex)
call DestroyGroup(g)
set g = null
set t = null
endfunction
endscope
Okay i think its working now, but I'm not 100% sure..
Last edited: