Skip to content
Snippets Groups Projects
Commit a464527c authored by Chris Davidson's avatar Chris Davidson
Browse files

NPCs only pass aggro if they have had their target in their actual FOV at least once

parent 4b43bb08
No related branches found
No related tags found
No related merge requests found
......@@ -61,12 +61,16 @@ end
function _M:init(t)
self.ai_state = self.ai_state or {}
self.ai_target = self.ai_target or {}
self.ai_actors_seen = self.ai_actors_seen or {} -- List of actors the AI has had LOS of at least once (regardless of target)
self:autoLoadedAI()
end
function _M:autoLoadedAI()
-- Make the table with weak values, so that threat list does not prevent garbage collection
setmetatable(self.ai_target, {__mode='v'})
self.ai_actors_seen = self.ai_actors_seen or {}
setmetatable(self.ai_actors_seen, {__mode='v'})
end
function _M:aiCanPass(x, y)
......@@ -131,6 +135,11 @@ function _M:doAI()
-- we forget it
self:clearAITarget()
-- Keep track of actors we've actually seen at least once in our own FOV, NPC calls doFOV right before doAI
for i,v in ipairs(self.fov.actors_dist) do
self.ai_actors_seen[v] = v
end
-- Update the ai_target table
local target_pos = self.ai_target.actor and self.fov and self.fov.actors and self.fov.actors[self.ai_target.actor]
if target_pos then
......
......@@ -200,8 +200,10 @@ function _M:seen_by(who)
if self.dont_pass_target then return end -- This means that ghosts can alert other NPC's but not vice versa ;)
local who_target = who.ai_target and who.ai_target.actor
if not (who_target and who_target.x) then return end
if not (who and who.ai_actors_seen[who_target]) then return end -- Only pass target if we've seen them via FOV at least once, this limits chain aggro
if self.ai_target and self.ai_target.actor == who_target then return end
if not rng.percent(who:getRankTalkativeAdjust()) then return end
-- Only receive (usually) hostile targets from allies
if self:reactionToward(who) <= 0 or not who.ai_state._pass_friendly_target and who:reactionToward(who_target) > 0 then return end
......@@ -210,7 +212,7 @@ function _M:seen_by(who)
-- Check if it's actually a being of cold machinery and not of blood and flesh
if not who.aiSeeTargetPos then return end
if self.ai_target.actor and not who_target:attr("stealthed_prevents_targetting") then
-- Pass last seen coordinates
-- Pass last seen coordinates if we already have the same target
if self.ai_target.actor == who_target then
-- Adding some type-safety checks, but this isn't fixing the source of the errors
local last_seen = {turn=0}
......
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