function GroupEnumLocustsInRange takes group g, real x, real y, real radius, boolexpr filter returns nothing
local group ga = CreateGroup()
local group gaa
local integer i = 0
local unit u
loop
exitwhen i == 12
set gaa = CreateGroup()
call GroupEnumUnitsOfPlayer( gaa, Player( i ), filter )
set bj_wantDestroyGroup = true
call GroupAddGroup( gaa, ga )
set i = i + 1
endloop
loop
set u = FirstOfGroup( ga )
exitwhen u == null
if GetUnitAbilityLevel( u, 'Aloc' ) > 0 and IsUnitInRangeXY( u, x, y, radius ) then
call GroupAddUnit( g, u )
endif
call GroupRemoveUnit( ga, u )
endloop
call DestroyGroup( ga )
set ga = null
set gaa = null
endfunction
function GroupEnumLocustsInRect takes group g, rect r, boolexpr filter returns nothing
local group ga = CreateGroup()
local group gaa
local integer i = 0
local unit u
local region re = CreateRegion()
call RegionAddRect( re, r )
loop
exitwhen i == 12
set gaa = CreateGroup()
call GroupEnumUnitsOfPlayer( gaa, Player( i ), filter )
set bj_wantDestroyGroup = true
call GroupAddGroup( gaa, ga )
set i = i + 1
endloop
loop
set u = FirstOfGroup( ga )
exitwhen u == null
if GetUnitAbilityLevel( u, 'Aloc' ) > 0 and IsUnitInRegion( re, u ) then
call GroupAddUnit( g, u )
endif
call GroupRemoveUnit( ga, u )
endloop
call RegionClearRect( re, r )
call RemoveRegion( re )
call DestroyGroup( ga )
set re = null
set ga = null
set gaa = null
endfunction