BlueMirage
Trust, but doubt.
- Reaction score
- 39
I've been trying to make my own function that will filter out units in a group that is not within a cone. I probably messed up with the unit groups. I know for sure that it does not even do any actions for the units in the group, because if it would, I would get a BJDebugMsg from my Angle function.
EDIT: I also know that this function manages to remove all units of the group I'm filtering, despite going through 0 of its units. Done by checking how many units are inside the group before and after the filter.
I'm making my own function as I could not get the ones I found on this site working.
EDIT: I also know that this function manages to remove all units of the group I'm filtering, despite going through 0 of its units. Done by checking how many units are inside the group before and after the filter.
I'm making my own function as I could not get the ones I found on this site working.
JASS:
// This will give you the angle between two points.
function Angle takes real x1, real y1, real x2, real y2 returns real
local real r = bj_RADTODEG * Atan2(y2 - y1, x2 - x1)
if r < 0 then
set r = 360 + r
endif
call BJDebugMsg(R2S(r))
return r
endfunction
//Filters out units not in a cone.
function FilterCone takes group whichGroup, real x ,real y, real facing, real angle returns group
local unit u
local group g = CreateGroup()
local group g2 = CreateGroup()
local real ua //Unit Angle to centre
set g = whichGroup
set angle = angle / 2
loop
set u = FirstOfGroup(g)
exitwhen u == null
call GroupRemoveUnit(g, u)
set ua = Angle(x, y, GetUnitX(u), GetUnitY(u))
if RAbsBJ(facing - ua) > 180 then //Check for the smallest angle between the two (Gives a difference of 100 instead of 260 for example)
if facing > ua then
set ua = ua + 360
else
set ua = ua - 360
endif
endif
if facing + angle >= ua and facing - angle <= ua then
call GroupAddUnit(g2, u)
endif
endloop
call DestroyGroup(g)
set g = null
return g2
endfunction