Enemy AI and Stealth

All development conversation and discussion takes place here

Moderator: Moderator

Post Reply
Message
Author
grayswandir
Uruivellas
Posts: 708
Joined: Wed Apr 30, 2008 5:55 pm

Enemy AI and Stealth

#1 Post by grayswandir »

I think stealth can be better.

Here's how npcs currently work (if I've read the code right):

If they don't have a target (or a 10% chance if they do), they set their target to the closest hostile in their field of view (out to their sight range, usually 10, but blocked by walls), regardless of stealth/invisibility/etc.

When an npc loses sight of their target (from walking behind a wall, stealth, or whatever), they try to guess its position. They have a radius X that goes up by 1 each turn, starting from 1 on the first turn they fail to see you (Or 3 if they've never seen you before). They pick a random position within X spaces of your true position, and average that with whatever their last guess was. That's where they treat you as being.

I didn't go deep into target passing, but it seems pretty good to me when I look at it. :) You can't pass your target if you can't see your target currently.

Here's what I don't like about it:
  • NPCs always know you're there if you enter their field of view, even if you have 9999 stealth. It starts out slightly inaccurate, but they are still alerted to your presence.
  • They can divine your location if you teleport halfway across the map.
  • The averaging doesn't work for large jumps. If I make a jump they'll target the space roughly halfway between for a turn, which doesn't make much sense.

Here's my suggestions for making stealth better:
  • NPCs have a confidence level, which starts at 50. Every turn, this is decreased by the distance from their estimated target to the target's actual position. So in an actual combat it'll slowly decrease, but if you teleport away they'll quickly lose confidence.
  • NPCs with at least double confidence and the same target can pass their target info on. So a group of enemies that can't see the target will still spread out over time, but if one enemy can see and the rest can't, they'll periodically retarget based on what the seeing enemy tells them.
  • NPCs that run out of confidence lose their target.
  • When an NPC first targets something they can't see, they start with a confidence of 10.
  • The retargeting chance is increased when confidence is low. Note that this can retarget the same thing, which will raise the confidence back up to 10 and reset their estimated position. This is essentially the npc noticing a "new" enemy and forgetting about the old one.
  • The estimated position does not take the real position into account. Instead, it deviates by sqrt(51 - confidence) every turn. We'll rely on the retargeting to deal with updating the true position.
Addons: Arcane Blade Tweaks, Fallen Race, Monk Class, Weapons Pack
Currently working on Elementals. It's a big project, so any help would be appreciated. :)

Nagyhal
Wyrmic
Posts: 282
Joined: Tue Feb 15, 2011 12:01 am

Re: Enemy AI and Stealth

#2 Post by Nagyhal »

grayswandir, I really like the emergent properties of this proposal! I'm not clear on a couple of basic matters, though. Maybe you could talk me through this like I'm 7.

What actually happens if the player is stealthed, wanders through a corridor and steps into range 10 of an enemy the player's never seen before?
grayswandir wrote:
  • NPCs have a confidence level, which starts at 50. Every turn, this is decreased by the distance from their estimated target to the target's actual position. So in an actual combat it'll slowly decrease, but if you teleport away they'll quickly lose confidence.
Will it be on to me from Turn 1? I think a true stealth mechanic should offer the possibility of creeping up on foes completely unawares. That's one of the key things that makes stealth gameplay fun.

If the enemy starts moving about, no matter how incompetently, whenever I enter sight range (and while supposedly fully hidden), then that's really going to break the immersion.
grayswandir wrote:
  • The retargeting chance is increased when confidence is low. Note that this can retarget the same thing, which will raise the confidence back up to 10 and reset their estimated position. This is essentially the npc noticing a "new" enemy and forgetting about the old one.
So assuming that sometimes our stealth will mean the enemy is unaware of any threat whatsoever, how is this simulated?
grayswandir wrote:
  • The estimated position does not take the real position into account. Instead, it deviates by sqrt(51 - confidence) every turn. We'll rely on the retargeting to deal with updating the true position.
This is wonderful, as it means rogues can use their movement capabilities to enhance their deception, which opens up a lot of beautiful synergies within the current stealth classes. As you mentioned, the current system crushes all such possibilities. Roll on the total rework, says I!

grayswandir
Uruivellas
Posts: 708
Joined: Wed Apr 30, 2008 5:55 pm

Re: Enemy AI and Stealth

#3 Post by grayswandir »

Nagyhal wrote:Will it be on to me from Turn 1? I think a true stealth mechanic should offer the possibility of creeping up on foes completely unawares. That's one of the key things that makes stealth gameplay fun.

If the enemy starts moving about, no matter how incompetently, whenever I enter sight range (and while supposedly fully hidden), then that's really going to break the immersion.
Yeah, I forgot to mention exactly what happens here. I'm thinking what would be best is if the npc's confidence level is set based on distance to the target and how badly they fail seeing through stealth. Say, 50 - 5 per space - points they failed the stealth check by. (I'd like to make stealth and see stealth follow the saves curve as well, but right now they don't so big numbers like this are possible, I think). And then, of course, if it's below 0 they don't notice at all.

And the starting estimated position will go through a round or two of movement based on that confidence on first sighting.


Also, I forgot to mention, but an npc taking damage from something when it doesn't have a target will make the npc target the damage source. This is a bit more complicated, as it means that enemies can track you while you've poisoned them. For now I think it'd be best if we just give 50 confidence if they notice you because of damage, and then see how that ends up working.
Addons: Arcane Blade Tweaks, Fallen Race, Monk Class, Weapons Pack
Currently working on Elementals. It's a big project, so any help would be appreciated. :)

Nagyhal
Wyrmic
Posts: 282
Joined: Tue Feb 15, 2011 12:01 am

Re: Enemy AI and Stealth

#4 Post by Nagyhal »

grayswandir wrote:Yeah, I forgot to mention exactly what happens here. I'm thinking what would be best is if the npc's confidence level is set based on distance to the target and how badly they fail seeing through stealth. Say, 50 - 5 per space - points they failed the stealth check by. (I'd like to make stealth and see stealth follow the saves curve as well, but right now they don't so big numbers like this are possible, I think). And then, of course, if it's below 0 they don't notice at all.

And the starting estimated position will go through a round or two of movement based on that confidence on first sighting.
As long as it doesn't work like the current system where, no matter what you do, enemies start out at maximum awareness of your position and progress toward a lower awareness.

Besides all that, it's the kind of system where it's really easy to fine-tune behaviour after a basic implementation. So I'd guess that any vaguely-defined stealth "feel" could be approximated from this approach
  • Also, I forgot to mention, but an npc taking damage from something when it doesn't have a target will make the npc target the damage source. This is a bit more complicated, as it means that enemies can track you while you've poisoned them. For now I think it'd be best if we just give 50 confidence if they notice you because of damage, and then see how that ends up working.
This might be another good argument for implementing our damage source flag idea (i.e., damage is flagged if it's a direct hit, retributory damage, damage from a DoT, etc.)

grayswandir
Uruivellas
Posts: 708
Joined: Wed Apr 30, 2008 5:55 pm

Re: Enemy AI and Stealth

#5 Post by grayswandir »

Alright, very rough version done: http://te4.org/games/addons/tome/graysw ... lth-rework

You can mess with most of the numbers in the gameplay options.
Addons: Arcane Blade Tweaks, Fallen Race, Monk Class, Weapons Pack
Currently working on Elementals. It's a big project, so any help would be appreciated. :)

Nagyhal
Wyrmic
Posts: 282
Joined: Tue Feb 15, 2011 12:01 am

Re: Enemy AI and Stealth

#6 Post by Nagyhal »

Lua error detected.

I can get the gist of this - something's setting the confidence value to nil when an Actor tries to get its last seen target - but there's a lot of breadcrumbs to chase and I don't have the time at this moment.

It seems to be happening when I attack an enemy that hasn't got a target.

I hope you'll forgive the emphasis on this question but the bug has made me very suspicious... Is it the case that in testing 10~ levels of rogue you failed to attack a target that completely hadn't seen you?

Nonetheless from watching the assumed locations of these enemies it's clear this is already an improvement over the base stealth implementation! I look forward to more!

Code: Select all

Lua Error: ...ir-stealth-rework/superload/engine/interface/ActorAI.lua:95: attempt to compare nil with number
	At [C]:-1 __le
	At ...ir-stealth-rework/superload/engine/interface/ActorAI.lua:95 aiSeeTargetPos
	At /engine/ai//talented.lua:27 runAI
	At /engine/ai//talented.lua:62 doAI
	At /mod/class/NPC.lua:72 act
	At /engine/GameEnergyBased.lua:129 tickLevel
	At /engine/GameEnergyBased.lua:64 tick
	At /engine/GameTurnBased.lua:51 tick
	At /mod/class/Game.lua:1255
 ----------------  Stack Dump ----------------
--------------- Stack Dump Finished ---------------

Dracos
Archmage
Posts: 405
Joined: Sun Jul 13, 2014 4:09 pm

Re: Enemy AI and Stealth

#7 Post by Dracos »

*sees this*

Not playing a stealth character this second but... Rah, Rah *cheers you on*

Enemies having too much psychic knowledge of player position when stealthed really is unfortunate, even with the high stealth multiplier helping to kill them in late game.
ToME Tips - auto-generated spoilers for ToME. - someone else made. I find super awesome, so spreading as well.

Post Reply