library LocustUnits initializer init //has optional GroupUtils
globals
private boolexpr filt
private integer ID = 'Aloc'
endglobals
private function IsLocust takes nothing returns boolean
return GetUnitAbilityLevel(GetFilterUnit(), ID) > 0
endfunction
function GroupAddLocustUnitsOfPlayer takes group TarG, player TarP returns nothing
call GroupEnumUnitsOfPlayer(TarG, TarP, filt)
endfunction
function GroupAddLocustUnitsInRange takes group TarG, real TarX, real TarY, real R, boolexpr someFilter returns nothing
local integer i = -1
local unit u
local group g
local real x
local real y
set R = R*R
static if LIBRARY_GroupUtils then
set g = NewGroup()
else
set g = CreateGroup()
endif
loop
set i = i+1
exitwhen i > 15
call GroupEnumUnitsOfPlayer(g,Player(i),filt)
loop
set u = FirstOfGroup(g)
exitwhen u == null
call GroupRemoveUnit(g,u)
set x = TarX-GetUnitX(u)
set y = TarY-GetUnitY(u)
if x*x+y*y <= R then
call GroupAddUnit(TarG,u)
endif
endloop
endloop
static if LIBRARY_GroupUtils then
call ReleaseGroup(g)
else
call DestroyGroup(g)
endif
set g = null
set u = null
endfunction
private function init takes nothing returns nothing
set filt = Filter(function IsLocust)
endfunction
endlibrary