Skip to content
Snippets Groups Projects
Commit 6f8f8ea7 authored by dg's avatar dg
Browse files

NPCs can only pass target if the target and the npc given them are within at most sight range

When an NPC can has been fooled by teleporting away, it stays fooled instead of magicalyl finding the way


git-svn-id: http://svn.net-core.org/repos/t-engine4@6196 51575b47-30f0-44d4-a5cc-537603b46e54
parent f35ed208
No related branches found
No related tags found
No related merge requests found
......@@ -32,28 +32,19 @@ end)
newAI("move_dmap", function(self)
if self.ai_target.actor and self.x and self.y then
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
if self:hasLOS(a.x, a.y) then return self:runAI("move_simple") end
local c = a:distanceMap(self.x, self.y)
if not c then return self:runAI("move_simple") end
local dir = 5
if c and ax == a.x and ay == a.y then
for _, i in ipairs(util.adjacentDirs()) do
local sx, sy = util.coordAddDir(self.x, self.y, i)
local cd = a:distanceMap(sx, sy)
-- print("looking for dmap", dir, i, "::", c, cd)
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
return self:runAI("move_simple")
for _, i in ipairs(util.adjacentDirs()) do
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
end
return self:moveDirection(util.coordAddDir(self.x, self.y, dir))
end
end)
......@@ -168,6 +159,8 @@ newAI("move_blocked_astar", function(self)
end)
newAI("move_complex", function(self)
do return self:runAI("move_dmap") end
if self.ai_target.actor and self.x and self.y then
local tx, ty = self:aiSeeTargetPos(self.ai_target.actor)
local moved
......@@ -184,7 +177,7 @@ newAI("move_complex", function(self)
-- Check blocking
if not moved then
-- Make sure that we are indeed blocked
moved = self:runAI("move_simple")
-- moved = self:runAI("move_simple")
if not moved and self:hasLOS(tx, ty) then
-- Wait at least 5 turns of not moving before switching to blocked_astar
-- add 2 since we remove 1 every turn
......
......@@ -160,9 +160,12 @@ function _M:seen_by(who)
if self.dont_pass_target then return end
if not who.ai_target then return end
if not who.ai_target.actor then return end
if not who.ai_target.actor.x then return end
if self:reactionToward(who) <= 0 then return end
if not who:canSee(who.ai_target.actor) then return end
if not who.x or not self:hasLOS(who.x, who.y) then return end
if core.fov.distance(self.x, self.y, who.x, who.y) > self.sight then return end
if core.fov.distance(self.x, self.y, who.ai_target.actor.x, who.ai_target.actor.y) > self.sight then return end
self:setTarget(who.ai_target.actor)
print("[TARGET] Passing target", self.name, "from", who.name, "to", who.ai_target.actor.name)
end
......
......@@ -70,6 +70,7 @@ function _M:use(item)
if act == "extra" then item.action_fct()
elseif act == "move_to" then game.player:mouseMove(self.tmx, self.tmy, true)
elseif act == "control" then game.party:setPlayer(item.actor)
elseif act == "target-player" then item.actor:setTarget(game.player)
elseif act == "order" then game.party:giveOrders(item.actor)
elseif act == "change_level" then game.key:triggerVirtual("CHANGE_LEVEL")
elseif act == "pickup" then game.key:triggerVirtual("PICKUP_FLOOR")
......@@ -118,6 +119,7 @@ function _M:generateList()
if g and not self.on_player then list[#list+1] = {name="Move to", action="move_to", color=colors.simple(colors.ANTIQUE_WHITE)} end
if a and not self.on_player and game.party:canControl(a, false) then list[#list+1] = {name="Control", action="control", color=colors.simple(colors.TEAL), actor=a} end
if a and not self.on_player and game.party:canOrder(a, false) then list[#list+1] = {name="Give order", action="order", color=colors.simple(colors.TEAL), actor=a} end
if a and not self.on_player and config.settings.cheat then list[#list+1] = {name="Target player", action="target-player", color=colors.simple(colors.RED), actor=a} end
if self.on_player then list[#list+1] = {name="Rest a while", action="rest", color=colors.simple(colors.ANTIQUE_WHITE)} end
if self.on_player then list[#list+1] = {name="Auto-explore", action="autoexplore", color=colors.simple(colors.ANTIQUE_WHITE)} end
if self.on_player then list[#list+1] = {name="Inventory", action="inventory", color=colors.simple(colors.ANTIQUE_WHITE)} 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