Troll-Brain
You can change this now in User CP.
- Reaction score
- 85
JASS:
library UnitList requires AutoIndex
struct UnitList
readonly integer Count = 0
readonly thistype First = 0
readonly thistype Next = 0
readonly thistype Prev = 0
readonly thistype Last = 0
implement AutoDestroy
method clear takes nothing returns nothing
local thistype s = .First
set thistype.ignoreDestroy = true
loop
exitwhen s == 0
call s.destroy()
set s = s.Next
endloop
set .Count = 0
call FlushChildHashtable(thistype.hashT,.whichList)
set thistype.ignoreDestroy = false
endmethod
method onDestroy takes nothing returns nothing
if thistype.ignoreDestroy then
return
endif
if this == .whichList then // the whole group is destroyed
call .clear()
return
endif
set .whichList.Count = .whichList.Count-1
call RemoveSavedInteger(thistype.hashT,.whichList,GetUnitId(.me))
if this == .whichList.First then
set .Prev = 0
set .whichList.First = .Next
elseif this == .whichList.Last then
set .Prev.Next = 0
set .whichList.Last = .Prev
else
set .Prev.Next = .Next
set .Next.Prev = .Prev
endif
endmethod
method addUnit takes unit u returns boolean
if LoadInteger(thistype.hashT,this,GetUnitId(u)) != 0 then // the unit is already inside the group
return false
endif
if .Count == 0 then // the group was empty
set .First = thistype.allocate()
set .Last = .First
else
set .Last.Next = thistype.allocate()
set .Last.Next.Prev = .Last
set .Last = .Last.Next
endif
set .Last.me = u
set .Last.whichList = this
call SaveInteger(thistype.hashT,this,GetUnitId(u),integer(.Last))
set .Count = .Count+1
return true
endmethod
//implement AutoDestroy
method removeUnit takes unit u returns boolean
if LoadInteger(thistype.hashT,this,GetUnitId(u)) == 0 then // the unit wasn't inside the group
return false
endif
call thistype(LoadInteger(thistype.hashT,this,GetUnitId(u))).destroy()
return true
endmethod
method isUnitInList takes unit u returns boolean
return LoadInteger(thistype.hashT,this,GetUnitId(u)) != 0
endmethod
method addUnitList takes UnitList whichUnitList returns nothing
set whichUnitList = whichUnitList.First
loop
exitwhen whichUnitList == 0
call .addUnit(whichUnitList.me)
set whichUnitList = whichUnitList.Next
endloop
endmethod
static method wrap takes group g returns UnitList
if not SaveGroupHandle(thistype.hashT,0,0,g) then // group invalid
return 0
endif
set thistype.wrapList = thistype.allocate()
call ForGroup(g,function thistype.WrapList)
return thistype.wrapList
endmethod
private static method WrapList takes nothing returns nothing
call thistype.wrapList.addUnit(GetEnumUnit())
endmethod
private thistype whichList = 0
private static hashtable hashT
private static boolean ignoreDestroy = false
private static thistype wrapList = 0
private static method onInit takes nothing returns nothing
set thistype.hashT = InitHashtable()
endmethod
endstruct
endlibrary
- What is that ?
Ever heard about ghost units ?
Those units which are removed of the game but not inside the group they were.
- What's the problem with ghost units ?
If a group has many ghost units, we can have performance issues, also we can't safely use a FirstOfGroup, exitwhen <unit> == null loop.
This, automatically removes units when they are about to removed, so you can't have ghost units at all.
And that makes group recycling fairly useless.
Also if include a group global, GroupUtils becomes pointless imho.
I don't make comments, because i suppose if it has enough good feedbacks Jesus4Lyf will just make it from scratch using AIDS (needs an update of it though) *shrugs*
So i don't want to lose time, since making English comments is the most annoying part of a submission for me.
Any comments are welcome.