Questions about minor NPC AI editing

A refuge for those migrating from the fallen DXEditing.com and a place for general discussion relating to Deus Ex editing (coding, mapping, etc).
G-Flex
Silhouette
Posts: 621
Joined: Mon Jul 11, 2011 10:16 pm

Questions about minor NPC AI editing

Post by G-Flex »

I got the idea that it would be nice if some fairly numerical aspects of enemy AI could scale with difficulty.

Specifically, I was aiming to have NPCs react more quickly (get suspicious faster when they see you, go from suspicious to alert faster when they continue seeing you), and to see farther.

For some reason, I can't seem to accomplish either of these tasks. I can't figure out what in ScriptedPawn specifically controls how quickly their alertness rises; I tried messing with UpdateReactionLevel(), but no matter how fast I set ReactionLevel to rise in there, it doesn't seem to do much. Regarding vision, changing a ScriptedPawn's SightRadius doesn't seem to help, nor does changing the distance after which bCheckPlayer is set to False.

If anyone's ever done any modding or knows a lot about NPC scripting, I appreciate any help/explanation. This seems like stuff that should be trivial to edit, but I can't seem to figure it out.
User avatar
SilverSpook
MJ12
Posts: 319
Joined: Wed Feb 15, 2012 8:34 am

Re: Questions about minor NPC AI editing

Post by SilverSpook »

I have AI rework on the side-burner right now and I'm pretty much planning to do exactly what you're saying at some point. I did hack my way through the UT2K4 AI to get it tighter and faster way back when, but it's been a while. I'll let you know if I make any headway.

Off the top of my head, I think that the sniper NPCs would need to see farther, perhaps check those out?

There is also this in the ScriptedPawn global 'tick' function that might affect AI sight range:

Code: Select all

        if (DistanceFromPlayer > 2500)
			bCheckPlayer = false;
Image
G-Flex
Silhouette
Posts: 621
Joined: Mon Jul 11, 2011 10:16 pm

Re: Questions about minor NPC AI editing

Post by G-Flex »

Yeah, I did notice that check, and set the condition to a much higher number; it didn't do much. The base "Pawn" class also has a variable called "SightRadius", and making that higher doesn't do anything either.

I checked the sniper in the Area 51 tower near the helipad, and his SightRadius is set to 5000, and his VisibilityThreshold is significantly lower than average. Interesting.
Captain_Destro
UNATCO
Posts: 100
Joined: Wed Sep 28, 2011 10:48 pm

Re: Questions about minor NPC AI editing

Post by Captain_Destro »

G-Flex wrote:Yeah, I did notice that check, and set the condition to a much higher number; it didn't do much. The base "Pawn" class also has a variable called "SightRadius", and making that higher doesn't do anything either.

I checked the sniper in the Area 51 tower near the helipad, and his SightRadius is set to 5000, and his VisibilityThreshold is significantly lower than average. Interesting.

The lower the number on visibilitythreshold the farther he can see. Kind of like the difficulty setting. in my weapons port for 2027 I increased the difficulty of many npcs. Even adding snipers at the top of the statue. I had to adjust it just enough so you don't get sniped at the starting docks lol.
User avatar
SilverSpook
MJ12
Posts: 319
Joined: Wed Feb 15, 2012 8:34 am

Re: Questions about minor NPC AI editing

Post by SilverSpook »

Yeah, that's an important bit. The AI's vision increases as the visibilitythreshold decreases. It's explained in the SDK but an easy bit of info to miss.
Image
G-Flex
Silhouette
Posts: 621
Joined: Mon Jul 11, 2011 10:16 pm

Re: Questions about minor NPC AI editing

Post by G-Flex »

Lowering VisibilityThreshold does seem to help, although I believe the CheckPlayer check needs to be modified as well; judging by a little bit of testing, the modified NPCs (with lower VisibilityThreshold and higher SightRadius) still don't notice me until I'm under 2500 units away.

In fact, SightRadius doesn't seem to do much anyway; the terrorists in the first mission have a SightRadius of 2000 instead of 2500, but can still spot me at just under 2500.

My idea right now is to scale any ScriptedPawn's SightRadius, VisibilityThreshold, CheckPlayer distance, and possibly HearingThreshold by a factor related to difficulty, probably in PostBeginPlay() or something like that.

This should take care of enemy awareness to at least some degree.


However, I'm still stumped regarding reaction time. One of the reasons I find Deus Ex too easy is that enemies, in addition to generally being pretty stupid, do not react quickly enough to spotting the player. You get enough time to fire off shots that running-and-gunning becomes a bit too viable if you're any good at it. I'm still investigating a bit, and will mention if I figure anything out.
SilverSpook wrote:Yeah, that's an important bit. The AI's vision increases as the visibilitythreshold decreases. It's explained in the SDK but an easy bit of info to miss.
Wait, things are explained in the SDK? Where? I've been trying to figure all this out from the script files and in-game testing.
User avatar
SilverSpook
MJ12
Posts: 319
Joined: Wed Feb 15, 2012 8:34 am

Re: Questions about minor NPC AI editing

Post by SilverSpook »

Yeah, this is from EditorDocumentation.doc from DeusExSDK1112f:
AI visibilityThreshold - float - Acuteness of vision or how easily they can notice a player. The closer this number is to zero, the better the NPC’s sight is.
Image
G-Flex
Silhouette
Posts: 621
Joined: Mon Jul 11, 2011 10:16 pm

Re: Questions about minor NPC AI editing

Post by G-Flex »

Thanks for letting me know about that. It at least lets me know that "SightRadius" is obsolete... which makes it pretty ironic that they actually bothered changing it for different NPCs (e.g. snipers) without changing the CheckPlayer check. Oh well.

At any rate, I think I figured out what to do regarding enemy reaction time:
I had already known about UpdateReactionLevel(), and messing with that didn't work, but I also just found the part of the script that changes EnemyReadiness (in CheckCycle()), and that seems to be what I was looking for, or perhaps they both were.

So, that takes care of that problem. Personally, I always thought NPC reaction time in Deus Ex was way too slow. At higher difficulties, stealth is valued more because direct confrontation is more difficult and stealth isn't. It remains pretty easy to run up to an NPC from behind and plug them with an initial shot/stab before they react.

The only other thing I'd want to change but can't figure out how to do so is: NPC reaction to things that put them in "seeking" behavior (e.g. loud noises, seeing the player but not fully reacting). Specifically, I have no clue what to change in order to get them to wander around (when they pick a random point nearby and go there while suspicious) more or less frequently, or more sporadically.
G-Flex
Silhouette
Posts: 621
Joined: Mon Jul 11, 2011 10:16 pm

Re: Questions about minor NPC AI editing

Post by G-Flex »

EDIT: Never mind, I'm stupid. There's an initialization function in ScriptedPawn that works perfectly. Also, I double-posted. Whoops.

Actually, another problem:

I'm trying to adjust various aspects of NPC behavior based on difficulty setting, as I mentioned.

However, difficulty is a member variable of DeusExPlayer. The code I'm using for difficulty adjustments is in ScriptedPawn's PostPostBeginPlay() function, which apparently is running before the player itself is initialized on the map (the script thinks there's no local player; GetPlayerPawn() is returning None).

Obviously, the code needs to run ASAP when a ScriptedPawn appears or the map is loaded. Is there a better place to do that?
User avatar
SilverSpook
MJ12
Posts: 319
Joined: Wed Feb 15, 2012 8:34 am

Re: Questions about minor NPC AI editing

Post by SilverSpook »

G-Flex wrote: Obviously, the code needs to run ASAP when a ScriptedPawn appears or the map is loaded. Is there a better place to do that?
Do you have a custom PlayerPawn? For example I have a subclass of DeusExPlayer in which I have a bunch of different functionality that happens only when the player enters the game during "event TravelPostAccept".

You could have this custom player grab all the NPCs during this function and perform the initialization then.

You could also possibly stick it in Level.Game, but it might be more work without bang for the buck.
Image
G-Flex
Silhouette
Posts: 621
Joined: Mon Jul 11, 2011 10:16 pm

Re: Questions about minor NPC AI editing

Post by G-Flex »

I considered something like that, but ike I said in my edit, I found another function to slap it in (InitializePawn(), which is called from the StartUp state).

I think I committed a mortal sin, though.

I noticed that the "tougher" enemies (MJ12 troops, MIBs, Commandos, Gunther/Anna/Simons, etc.), generally speaking, aren't really any better at seeing/hearing/reacting than the weaker ones (NSF troops, thugs). I found it pretty weird that augmented agents and people in powered commando armor can't hear or see or react to things any better than a civilian. So I decided to alter their properties a bit.

The mortal sin part comes into play because I did this with another initialization function, overloaded for those classes, that sets the new values by multiplying the old values by a factor. I had to do it this way, because changing the default properties of a class (presumably) won't affect specific properties of a pre-placed NPC on a map, and I know a decent number of maps have NPCs with non-default values. If I'm going to make MJ12 troopers smarter and more alert, I wouldn't want to leave out the ones that already are more or less alert than default. It just feels like such a hack to have to do it that way, but that's that, I guess.
DDL
Traditional Evil Scientist
Traditional Evil Scientist
Posts: 3791
Joined: Mon Oct 17, 2005 10:03 am

Re: Questions about minor NPC AI editing

Post by DDL »

Given how hacky DX code is anyway, I wouldn't worry. Plus multipliers are always better than flat adjustments, surely? Or is it just constant additional function creation that's making you feel bad?

(and if so...heh: you should see my scriptedpawns)
G-Flex
Silhouette
Posts: 621
Joined: Mon Jul 11, 2011 10:16 pm

Re: Questions about minor NPC AI editing

Post by G-Flex »

It's just a block of code like this:

Code: Select all

class MIB extends HumanMilitary;

function AdjustProperties()
{
	//1.400000 instead of 2.000000
	SurprisePeriod *= 0.700000;
	//0.350000 instead of 0.500000
	attackPeriod *= 0.700000;
	//3.150000 instead of 4.500000
	maxAttackPeriod *= 0.700000;
	//0.007500 instead of 0.010000
	VisibilityThreshold *= 0.750000;
	//0.112500 instead of 0.150000
	HearingThreshold *= 0.750000;
}
It's just annoying having to do that in order to guarantee preplaced NPCs will work sanely, instead of modifying default parameters, which is what you'd think is sufficient.

Also, did you know that there are MJ12 snipers in the OceanLab starting map who have a VisibilityThreshold of zero? Perplexing. I'm not sure what the intended effect is, but I put a sanity check in the difficulty-adjustment function I wrote in ScriptedPawn that restricts it to some minimum value.

I had to make attackPeriod and maxAttackPeriod object variables; previously they had been hardcoded as specific values in the function that handles EnemyReadiness or whatever it's called.
User avatar
SilverSpook
MJ12
Posts: 319
Joined: Wed Feb 15, 2012 8:34 am

Re: Questions about minor NPC AI editing

Post by SilverSpook »

G-Flex wrote:It's just a block of code like this:

Code: Select all

class MIB extends HumanMilitary;

function AdjustProperties()
{
	//1.400000 instead of 2.000000
	SurprisePeriod *= 0.700000;
	//0.350000 instead of 0.500000
	attackPeriod *= 0.700000;
	//3.150000 instead of 4.500000
	maxAttackPeriod *= 0.700000;
	//0.007500 instead of 0.010000
	VisibilityThreshold *= 0.750000;
	//0.112500 instead of 0.150000
	HearingThreshold *= 0.750000;
}
It's just annoying having to do that in order to guarantee preplaced NPCs will work sanely, instead of modifying default parameters, which is what you'd think is sufficient.
Yeah, there's not really any way around doing a multiplier thing. You could add a "base" value or a "base multiplier" default property for the pawns, but the more degrees of attribute manipulation you add the more complex it's going to get any way you cut it.
Also, did you know that there are MJ12 snipers in the OceanLab starting map who have a VisibilityThreshold of zero? Perplexing. I'm not sure what the intended effect is, but I put a sanity check in the difficulty-adjustment function I wrote in ScriptedPawn that restricts it to some minimum value.
I think the zero VisibilityThreshold is to allow the sniper to hit the player from any distance as long as the sniper has line-of-sight on the target.
Image
G-Flex
Silhouette
Posts: 621
Joined: Mon Jul 11, 2011 10:16 pm

Re: Questions about minor NPC AI editing

Post by G-Flex »

SilverSpook wrote:I think the zero VisibilityThreshold is to allow the sniper to hit the player from any distance as long as the sniper has line-of-sight on the target.
Sure, but they only check for the player within 2500 units anyway (although my mod scales that value with difficulty). I suppose having a VisibilityThreshold of zero doesn't have extremely bad implications, but it irked me enough on general principle that I felt the need to change it anyway.
Post Reply