Code: Select all
newAI("flee_simple", function(self)
if self.ai_target.actor then
local tx, ty = self:aiSeeTargetPos(self.ai_target.actor)
local dir = 5
local bestdist = 0
for i = 1, 9 do
local sx, sy = util.coordAddDir(self.x, self.y, i)
local sqdist = math.pow(self.x - sx, 2) + math.pow(self.y - sy, 2)
if self:canMove(sx, sy) and sqdist < bestdist then
bestdist = sqdist
dir = i
end
end
return self:moveDirection(util.coordAddDir(tx, ty, dir))
end
end)