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
AI Targeting in LOS
All development conversation and discussion takes place here
Moderator: Moderator
Message
Author
Jump to
- General
- ↳ Announcements
- ToME 4
- ↳ General Discussion
- ↳ Dumb Questions
- ↳ Character Reports
- ↳ Ideas
- ↳ Spoilers
- ↳ Metaclass: Warriors
- ↳ Metaclass: Rogues
- ↳ Metaclass: Mages
- ↳ Metaclass: Wilders
- ↳ Metaclass: Celestials
- ↳ Metaclass: Defilers
- ↳ Metaclass: Afflicted
- ↳ Metaclass: Chronomancers
- ↳ Metaclass: Psionics
- ↳ Metaclass: Adventurers
- ↳ Metaclass: Tinkers
- ↳ Metaclass: Demented
- ↳ Bugs
- ↳ Bugs Archive
- ↳ Development
- ↳ Addons
- T-Engine 4
- ↳ General Discussion
- ↳ Ideas
- ↳ Modules
- ↳ Development
- ↳ Bugs
- ToME 2.x.x
- ↳ General Discussion
- ↳ Ideas
- ↳ Gameplay
- ↳ Spoilers
- ↳ Modules
- ↳ ToME/Bugs
- ToME 3.x.x
- ↳ General Discussion
- ↳ Ideas
- ↳ T-Engine Development
- ↳ Modules
- ↳ Spoilers
- ↳ Bugs
- Behind the Void
- ↳ Tolkien
- ↳ The Void
- Archives
- ↳ Archives