Skip to content
Snippets Groups Projects
Commit 74a644be authored by dg's avatar dg
Browse files

fix

git-svn-id: http://svn.net-core.org/repos/t-engine4@6100 51575b47-30f0-44d4-a5cc-537603b46e54
parent 1c72452b
No related branches found
No related tags found
No related merge requests found
......@@ -34,6 +34,11 @@ newAI("move_dmap", function(self)
local a = self.ai_target.actor
local ax, ay = self:aiSeeTargetPos(a)
-- If we have a vision, go straight towards the target
if self:hasLOS(ax, ay) then
return self:runAI("move_simple")
end
local c = a:distanceMap(self.x, self.y)
local dir = 5
......@@ -42,7 +47,8 @@ newAI("move_dmap", function(self)
local sx, sy = util.coordAddDir(self.x, self.y, i)
local cd = a:distanceMap(sx, sy)
-- print("looking for dmap", dir, i, "::", c, cd)
if cd and cd > c and self:canMove(sx, sy) then c = cd; dir = i end
local tile_available = self:canMove(sx, sy) or (sx == ax and sy == ay)
if cd and cd > c and tile_available then c = cd; dir = i end
end
return self:moveDirection(util.coordAddDir(self.x, self.y, dir))
else
......
......@@ -25,19 +25,22 @@ local canFleeDmapKeepLos = function(self)
if self.never_move then return false end -- Dont move, dont flee
if self.ai_target.actor then
local act = self.ai_target.actor
local c = act:distanceMap(self.x, self.y)
if not c then return end
local dir
local dir, c
if self:hasLOS(act.x, act.y) then
dir = 5
c = act:distanceMap(self.x, self.y)
if not c then return end
end
for _, i in ipairs(util.adjacentDirs()) do
local sx, sy = util.coordAddDir(self.x, self.y, i)
-- Check LOS first
if self:hasLOS(act.x, act.y, nil, nil, sx, sy) then
local cd = act:distanceMap(sx, sy)
-- print("looking for dmap", dir, i, "::", c, cd)
if not cd or (c and (cd < c and self:canMove(sx, sy))) then c = cd; dir = i end
if not cd or ((not c or cd < c) and self:canMove(sx, sy)) then c = cd; dir = i end
end
end
if dir then
if dir and dir ~= 5 then
local dx, dy = util.dirToCoord(dir, self.x, self.y)
return true, self.x + dx, self.y + dy
else
......@@ -393,12 +396,14 @@ newAI("tactical", function(self)
end
if targeted and not self.energy.used then
local moved
if special_move then
return self:runAI(special_move)
elseif self.ai_tactic.safe_range and not self:hasLOS(ax, ay) then
local moved = self:runAI("flee_dmap_keep_los")
return self:runAI(self.ai_state.ai_move or "move_simple")
else
moved = self:runAI(special_move)
end
if not moved and self.ai_tactic.safe_range and not self:hasLOS(ax, ay) then
moved = self:runAI("flee_dmap_keep_los")
end
if not moved then
return self:runAI(self.ai_state.ai_move or "move_simple")
end
end
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment