AI gets stuck targetting friendlies

Where bugs go to lie down and rest

Moderator: Moderator

Post Reply
Message
Author
Hachem_Muche
Uruivellas
Posts: 744
Joined: Thu Nov 18, 2010 6:42 pm

AI gets stuck targetting friendlies

#1 Post by Hachem_Muche »

Apparently, if an npc gets a friendly actor assigned as its AI target, there is no way for it to get untargeted.

I just encountered a cluster of about a dozen orcs all targetting another orc and just milling about, bumping into each other for dozens of turns - even after hit them all with AOE damage. They were all the same faction (reaction +100) and I'm not sure how they all got targeted on to same friendly npc, but I have seen a similar problem with NPC's keeping the player targeted (like if an undead pc forgets his cloak.)
From engine.ai.simple.lua:

Code: Select all

-- Find an hostile target
-- this requires the ActorFOV interface, or an interface that provides self.fov.actors*
newAI("target_simple", function(self)
	if self.ai_target.actor and not self.ai_target.actor.dead and rng.percent(90) then return true end

	-- Find closer enemy and target it
	-- Get list of actors ordered by distance
	local arr = self.fov.actors_dist
	local act
	for i = 1, #arr do
		act = self.fov.actors_dist[i]
--		print("AI looking for target", self.uid, self.name, "::", act.uid, act.name, self.fov.actors[act].sqdist)
		-- find the closest enemy
		if act and self:reactionToward(act) < 0 and not act.dead then
			self:setTarget(act)
			self:check("on_acquire_target", act)
			return true
		end
	end
end)
There is a 10% chance each turn of the npc looking for a new target. If there are no unfriendly targets withing sight range, however, it will keep it's current target. A possible fix for this (I haven't looked at all of the AI code that could be impacted.) is to clear the AI target before looking for a new one.
Author of the Infinite 500 and PlenumTooltip addons, and the joys of Scaling in ToME.

R_D
Halfling
Posts: 104
Joined: Fri Jan 18, 2013 6:53 pm
Location: Somewhere only we know...

Re: AI gets stuck targetting friendlies

#2 Post by R_D »

This happened to me on High Peak: Ascent (the top floor) recently on my necromancer. After killing both bosses and all the enemies were gone, I noticed Aeryn was following me constantly and spamming sun flare whenever available. I clicked on her and saw she was targeting one of my ghouls, and the sun flare wasn't damaging it (or me) b/c we were friendly. She stopped following me (or the ghoul, technically) as soon as the ghoul died.
?Wub?Wub?Wub?

Post Reply