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) ...@@ -34,6 +34,11 @@ newAI("move_dmap", function(self)
local a = self.ai_target.actor local a = self.ai_target.actor
local ax, ay = self:aiSeeTargetPos(a) 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 c = a:distanceMap(self.x, self.y)
local dir = 5 local dir = 5
...@@ -42,7 +47,8 @@ newAI("move_dmap", function(self) ...@@ -42,7 +47,8 @@ newAI("move_dmap", function(self)
local sx, sy = util.coordAddDir(self.x, self.y, i) local sx, sy = util.coordAddDir(self.x, self.y, i)
local cd = a:distanceMap(sx, sy) local cd = a:distanceMap(sx, sy)
-- print("looking for dmap", dir, i, "::", c, cd) -- 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 end
return self:moveDirection(util.coordAddDir(self.x, self.y, dir)) return self:moveDirection(util.coordAddDir(self.x, self.y, dir))
else else
......
...@@ -25,19 +25,22 @@ local canFleeDmapKeepLos = function(self) ...@@ -25,19 +25,22 @@ local canFleeDmapKeepLos = function(self)
if self.never_move then return false end -- Dont move, dont flee if self.never_move then return false end -- Dont move, dont flee
if self.ai_target.actor then if self.ai_target.actor then
local act = self.ai_target.actor local act = self.ai_target.actor
local c = act:distanceMap(self.x, self.y) local dir, c
if not c then return end if self:hasLOS(act.x, act.y) then
local dir dir = 5
c = act:distanceMap(self.x, self.y)
if not c then return end
end
for _, i in ipairs(util.adjacentDirs()) do for _, i in ipairs(util.adjacentDirs()) do
local sx, sy = util.coordAddDir(self.x, self.y, i) local sx, sy = util.coordAddDir(self.x, self.y, i)
-- Check LOS first -- Check LOS first
if self:hasLOS(act.x, act.y, nil, nil, sx, sy) then if self:hasLOS(act.x, act.y, nil, nil, sx, sy) then
local cd = act:distanceMap(sx, sy) local cd = act:distanceMap(sx, sy)
-- print("looking for dmap", dir, i, "::", c, cd) -- 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
end end
if dir then if dir and dir ~= 5 then
local dx, dy = util.dirToCoord(dir, self.x, self.y) local dx, dy = util.dirToCoord(dir, self.x, self.y)
return true, self.x + dx, self.y + dy return true, self.x + dx, self.y + dy
else else
...@@ -393,12 +396,14 @@ newAI("tactical", function(self) ...@@ -393,12 +396,14 @@ newAI("tactical", function(self)
end end
if targeted and not self.energy.used then if targeted and not self.energy.used then
local moved
if special_move then if special_move then
return self:runAI(special_move) moved = self:runAI(special_move)
elseif self.ai_tactic.safe_range and not self:hasLOS(ax, ay) then end
local moved = self:runAI("flee_dmap_keep_los") if not moved and self.ai_tactic.safe_range and not self:hasLOS(ax, ay) then
return self:runAI(self.ai_state.ai_move or "move_simple") moved = self:runAI("flee_dmap_keep_los")
else end
if not moved then
return self:runAI(self.ai_state.ai_move or "move_simple") return self:runAI(self.ai_state.ai_move or "move_simple")
end end
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