AI Targeting in LOS

All development conversation and discussion takes place here

Moderator: Moderator

Post Reply
Message
Author
benli
Thalore
Posts: 125
Joined: Tue Aug 17, 2010 5:02 am

AI Targeting in LOS

#1 Post by benli »

I was trying to fix a problem with AI targeting though objects that have block_sight = true. To prevent I added this code to ensure that actors can't be targeted unless they can be seen in some way (LOS, telepathy, etc). I'm using the requires_knowledge flag here to allow targeting without "seeing" the target.

Without this, AI can use talents through Creeping Darkness and Smoke Bomb and other forms of block_sight. The canProject method currently prevents doing this through block_move objects.

--- Returns the current target
function _M:getTarget(typ)
-- make sure that the target actor is actually in LOS or seen some other way
if self.ai_target.actor then
if not typ or not typ.requires_knowledge == false then
-- checks LOS and other kinds of "sight"
if self.fov and self.fov.actors_dist then
local found
for _, value in pairs(self.fov.actors_dist) do
if value == self.ai_target.actor then
found = true
break
end
end
if not found then return end
else
-- fallback to check only LOS
if self:hasLOS(self.ai_target.actor) then return end
end
end
end


-- get location where we think the target is
local tx, ty = self:aiSeeTargetPos(self.ai_target.actor)
return tx, ty, self.ai_target.actor
end

Post Reply