globals
group enumGrp = CreateGroup()
endglobals
function TrueFilter takes nothing returns boolean
return true
endfunction
function Get_unit_in_square takes real x, real y returns unit
call GroupEnumUnitsInRange(enumGrp, x, y, 200, Filter(function TrueFilter))
return FirstOfGroup(enumGrp)
// leeeeeeeeeeeeeeeak
endfunction
function Facing_AI_choose takes unit turner returns nothing
local real angle = 0
local real ox = GetUnitX(turner)
local real oy = GetUnitY(turner)
local real x
local real y
local real bestX = ox
local real bestY = oy
local real targetHealth = 150000
local unit targetUnit
loop
exitwhen angle == 360
set x = ox + 384. * Cos(angle * bj_DEGTORAD)
set y = oy + 384. * Sin(angle * bj_DEGTORAD)
set targetUnit = Get_unit_in_square(x, y)
if (targetUnit != null and IsPlayerEnemy(GetOwningPlayer(targetUnit), GetOwningPlayer(turner)) and targetHealth > GetUnitState(targetUnit, UNIT_STATE_LIFE)) then
set bestX = x
set bestY = y
set targetHealth = GetUnitState(targetUnit, UNIT_STATE_LIFE)
call dbug("cc")
endif
set angle = angle + 90
endloop
call dbug(GetUnitName(turner) + R2S(bestX) + R2S(bestY) + R2S(ox) + R2S(oy))
if (bestX == ox and bestY == oy) then
set targetUnit = null
call dbug("returns")
return
endif
call IssuePointOrderById(turner, 'A000', bestX, bestY)
set targetUnit = null
endfunction