AceHart
Your Friendly Neighborhood Admin
Sector:
Imagine a cake, the round type,
cut it into pieces, taking care to cut through the center,
take one piece,
look at it from the top.
That's a sector.
Still not seeing it? Here's an image.
Yes, I actually think it works...
The demo map is simple to use, select the Blood Mage, move somewhere, press "escape".
The list of names you get would be the units within 400 distance and 60 degrees in front.
Yes, it includes the Mage... that's because the filter function simply picks anything...
Imagine a cake, the round type,
cut it into pieces, taking care to cut through the center,
take one piece,
look at it from the top.
That's a sector.
Still not seeing it? Here's an image.
JASS:
JASS:
// whichGroup: the group the units will be added to
// xc, yc: the starting point, sort of like the center of the circle
// facing: the direction the "middle" of the sector goes to, in radians
// radius: the "length" of the sector
// angle: the maximum opening angle of the sector, in radians
// filter: the condition function to apply to the units in the sector.
function GroupEnumUnitsInSector takes group whichGroup,real xc,real yc,real facing,real radius,real angle,boolexpr filter returns nothing
local group g = CreateGroup()
local unit u
local real x
local real y
local real x1
local real y1
local real x2
local real y2
call GroupEnumUnitsInRange(g, xc, yc, radius, filter)
set angle = angle * 0.5
set x1 = Cos(facing  angle)
set y1 = Sin(facing  angle)
set x2 = Cos(facing + angle)
set y2 = Sin(facing + angle)
loop
set u = FirstOfGroup(g)
exitwhen u == null
call GroupRemoveUnit(g, u)
set x = GetUnitX(u)  xc
set y = GetUnitY(u)  yc
if y * x1 >= x * y1 and y * x2 <= x * y2 then
call GroupAddUnit(whichGroup, u)
endif
endloop
call DestroyGroup(g)
set g = null
endfunction
// point: the starting point, sort of like the center of the circle
// facing: the direction the "middle" of the sector goes to, in degrees
// radius: the "length" of the sector
// angle: the maximum opening angle of the sector, in degrees
// filter: the condition function to apply to the units in the sector. Pass null for all units
function GetUnitsInSector takes location point,real facing,real radius,real angle,boolexpr filter returns group
local group g = CreateGroup()
if filter == null then
set filter = FILTER_True
endif
call GroupEnumUnitsInSector(g, GetLocationX(point), GetLocationY(point), facing * bj_DEGTORAD, radius, angle * bj_DEGTORAD, filter)
return g
endfunction
Yes, I actually think it works...
The demo map is simple to use, select the Blood Mage, move somewhere, press "escape".
The list of names you get would be the units within 400 distance and 60 degrees in front.
Yes, it includes the Mage... that's because the filter function simply picks anything...
Attachments

14.8 KB Views: 231