- Joined
- Oct 16, 2011
- Messages
- 296
function GroupEnumUnitsInCone takes group whichGroup, real x, real y, real radius, real direction, real size returns group
local unit FoG
local group g = CreateGroup()
local real x2
local real y2
local real difference
call GroupEnumUnitsInRange(g, x, y, radius, null)
loop
set FoG = FirstOfGroup(g)
exitwhen FoG == null
call GroupRemoveUnit(g,FoG)
set difference = DeNormalizeAngle(AngleBetweenCoordinates(x, y, GetUnitX(FoG), GetUnitY(FoG)) - direction)
if difference > -size and difference < size then
call GroupAddUnit(whichGroup, FoG)
endif
endloop
call DestroyGroup(g)
set g = null
return whichGroup
endfunction
function AngleBetweenCoordinates takes real x1, real y1, real x2, real y2 returns real
return bj_RADTODEG * Atan2(y2 - y1, x2 - x1)
endfunction
function DeNormalizeAngle takes real angle returns real
loop
if angle <= -180 then
set angle = angle + 360
elseif angle > 180 then
set angle = angle - 360
else
return angle
endif
endloop
return 0.
endfunction
function GroupEnumUnitsInCone takes group whichGroup, real x, real y, real radius, real direction, real size returns group
local unit FoG
local group g = CreateGroup()
local real x2
local real y2
local real difference
call GroupEnumUnitsInRange(g, x, y, radius, null)
loop
set FoG = FirstOfGroup(g)
exitwhen FoG == null
call GroupRemoveUnit(g,FoG)
set difference = DeNormalizeAngle(AngleBetweenCoordinates(x, y, GetUnitX(FoG), GetUnitY(FoG)) - direction)
if difference > -size and difference < size then
call GroupAddUnit(whichGroup, FoG)
endif
endloop
call DestroyGroup(g)
set g = null
return whichGroup
endfunction