scope EnumerationTest initializer OnInit
//==================================================================================================
function IsUnitInSector takes unit u, real collision, real x, real y, real radius, real face, real fov returns boolean
local real a
if IsUnitInRangeXY(u, x, y, radius) then
set x = GetUnitX(u) - x
set y = GetUnitY(u) - y
set radius = x*x + y*y
if radius > 0. then
set a = Atan2(y, x)
set fov = fov/2 + Acos((1 - (collision*collision)/(2*radius)))
return RAbsBJ(face - a) <= fov and RAbsBJ(face - a - 2.00*bj_PI) > fov
endif
return true
endif
return false
endfunction
//==================================================================================================
function IsPointInCone takes real centerx, real centery, real face, real fov, real pointx, real pointy returns boolean
local real angle = bj_RADTODEG*Atan2(pointy - centery, pointx - centerx)
return not (RAbsBJ(face - angle) > (fov/2) and RAbsBJ(face - angle - 360.) > (fov/2))
endfunction
function IsCircleOnLine takes real cx, real cy, real radius, real p1x, real p1y, real p2x, real p2y returns boolean
local real dx = p2x - p1x
local real dy = p2y - p1y
local real a = dx * dx + dy * dy
local real b = 2 * (dx * (p1x - cx) + dy * (p1y - cy))
local real c = (p1x - cx) * (p1x - cx) + (p1y - cy) * (p1y - cy) - radius * radius
local real det = b * b - 4 * a * c
if ((a <= 0.000001) or (det < 0)) then
return false
endif
return true
endfunction
function IsUnitInCone takes real centerx, real centery, real face, real fov, real length, unit target returns boolean
local real radius = BlzGetUnitCollisionSize(target)
local real p2x
local real p2y
if not IsUnitInRangeXY(target, centerx, centery, length) then
return false
endif
if IsPointInCone(centerx, centery, face, fov, GetUnitX(target), GetUnitY(target)) then
return true
endif
set p2x = centerx + Cos(bj_DEGTORAD*(face - fov/2)) * length
set p2y = centery + Sin(bj_DEGTORAD*(face - fov/2)) * length
if IsCircleOnLine(GetUnitX(target), GetUnitY(target), radius, centerx, centery, p2x, p2y) then
return true
endif
set p2x = centerx + Cos(bj_DEGTORAD*(face + fov/2)) * length
set p2y = centery + Sin(bj_DEGTORAD*(face + fov/2)) * length
if IsCircleOnLine(GetUnitX(target), GetUnitY(target), radius, centerx, centery, p2x, p2y) then
return true
endif
return false
endfunction
private function InitEnumerationTest takes integer unitId, integer I, integer J, real spacing returns nothing
local integer j
local real offset = -(spacing*I*0.5)
local unit u
loop
exitwhen I == 0
set j = J
loop
exitwhen j == 0
set u = CreateUnit(Player(0), unitId, I*spacing + offset, j*spacing + offset, 90.00)
if IsUnitInSector(u, BlzGetUnitCollisionSize(u), 0, 0, 1200, bj_PI*0.25, bj_PI*0.25) then
call SetUnitVertexColor(u, 255, 0, 0, 255)
else
call SetUnitVertexColor(u, 0, 255, 0, 255)
endif
if IsUnitInCone(0, 0, bj_PI*0.25*bj_RADTODEG, bj_PI*0.25*bj_RADTODEG, 1200, u) then
call AddSpecialEffectTarget("Abilities\\Spells\\Other\\TalkToMe\\TalkToMe.mdl", u, "overhead")
endif
set j = j - 1
endloop
set I = I - 1
endloop
set u = null
endfunction
private function OnInit takes nothing returns nothing
call FogEnable(false)
call FogMaskEnable(false)
call PanCameraToTimed(0.00, 0.00, 0.00)
call InitEnumerationTest('hpea', 30, 30, 75.00)
endfunction
endscope