AI & Tear Gas

A refuge for those migrating from the fallen DXEditing.com and a place for general discussion relating to Deus Ex editing (coding, mapping, etc).
Post Reply
Cybernetic pig
Illuminati
Posts: 2284
Joined: Thu Mar 08, 2012 3:21 am

AI & Tear Gas

Post by Cybernetic pig »

So, AI appear to avoid class'TearGas' very effectively when spawned from the peppergun, but not at all when spawned from gas grenades.

The gas as spawned from ThrownProjectile.uc:

Code: Select all

gas = spawn(class'TearGas', None,, loc);
			if (gas != None)
			{
				gas.Velocity = vect(0,0,0);
				gas.Acceleration = vect(0,0,0);
				gas.DrawScale = FRand() * 0.5 + 2.0;
				gas.LifeSpan = FRand() * 10 + 30;
				if ( Level.NetMode != NM_Standalone )
					gas.bFloating = False;
				else
					gas.bFloating = True;
				gas.Instigator = Instigator;
			}
Nothing that should make it different to the gas spawned from the pepper gun in this regard.
I look at the avoidharm code and everything related in ScriptedPawn. Again, as far as I can tell, nothing.
WeaponPepperGun.uc? Nope.

Any ideas?
Hanfling
MJ12
Posts: 406
Joined: Sun Oct 04, 2009 6:54 pm

Re: AI & Tear Gas

Post by Hanfling »

Check for AISendEvent(). Another idea would be that they do not avoid the teargas, but rather the player using a weapon.
I demand my DXE User ID back. Launcher for DeusEx, Rune, Nerf, Unreal & Botpack. HX on Mod DB. Revision on Steam.
Cybernetic pig
Illuminati
Posts: 2284
Joined: Thu Mar 08, 2012 3:21 am

Re: AI & Tear Gas

Post by Cybernetic pig »

Hanfling wrote:Check for AISendEvent(). Another idea would be that they do not avoid the teargas, but rather the player using a weapon.
AISendEvent() is not related. Nor should the weapon used be (it looks for the projectile, not the weapon).

From what I can make out, what happens is if bAvoidHarm is true, then AI attempt to avoid projectiles if within range (gasclouds extend DeusEx Projectile).

This function in scriptedpawn determines if the projectile is dangerous and should be avoided:

Code: Select all

function int GetProjectileList(out NearbyProjectileList projList, vector Location)
{
	local float            dist;
	local int              count;
	local DeusExProjectile curProj;
	local ThrownProjectile throwProj;
	local Cloud            cloudProj;
	local vector           HitNormal, HitLocation;
	local vector           extent;
	local vector           traceEnd;
	local Actor            hitActor;
	local float            range;
	local vector           pos;
	local float            time;
	local float            maxTime;
	local float            elasticity;
	local int              i;
	local bool             bValid;

	for (i=0; i<ArrayCount(projList.list); i++)
		projList.list[i].projectile = None;
	projList.center = Location;

	maxTime = 2.0;
	foreach RadiusActors(Class'DeusExProjectile', curProj, 1000)
	{
		if (IsProjectileDangerous(curProj))
		{
			throwProj = ThrownProjectile(curProj);
			cloudProj = Cloud(curProj);
			extent   = vect(1,1,0)*curProj.CollisionRadius;
			extent.Z = curProj.CollisionHeight;

			range    = VSize(extent);
			if (curProj.bExplodes)
				if (range < curProj.blastRadius)
					range = curProj.blastRadius;
			if (cloudProj != None)
				if (range < cloudProj.cloudRadius)
					range = cloudProj.cloudRadius;
			range += CollisionRadius+60;

			if (throwProj != None)
				elasticity = throwProj.Elasticity;
			else
				elasticity = 0.2;

			bValid = true;
			if (throwProj != None)
				if (throwProj.bProximityTriggered)  // HACK!!!
					bValid = false;

			if (((curProj.Physics == PHYS_Falling) || (curProj.Physics == PHYS_Projectile) || (curProj.Physics == PHYS_None)) &&
			    bValid)
			{
				pos = curProj.Location;
				dist = VSize(Location - curProj.Location);
				AddProjectileToList(projList, curProj, pos, dist, range);
				if (curProj.Physics == PHYS_Projectile)
				{
					traceEnd = curProj.Location + curProj.Velocity*maxTime;
					hitActor = Trace(HitLocation, HitNormal, traceEnd, curProj.Location, true, extent);
					if (hitActor == None)
						pos = traceEnd;
					else
						pos = HitLocation;
					dist = VSize(Location - pos);
					AddProjectileToList(projList, curProj, pos, dist, range);
				}
				else if (curProj.Physics == PHYS_Falling)
				{
					time = ParabolicTrace(pos, curProj.Velocity, curProj.Location, true, extent, maxTime,
					                      elasticity, curProj.bBounce, 60);
					if (time > 0)
					{
						dist = VSize(Location - pos);
						AddProjectileToList(projList, curProj, pos, dist, range);
					}
				}
			}
		}
	}

	count = 0;
	for (i=0; i<ArrayCount(projList.list); i++)
		if (projList.list[i].projectile != None)
			count++;

	return (count);

}
This function returns true if the function above spits out a valid projectile, and said valid projectile is in range to the NPC:

Code: Select all

// ----------------------------------------------------------------------
// IsLocationDangerous()
// ----------------------------------------------------------------------

function bool IsLocationDangerous(NearbyProjectileList projList,
								  vector Location)
{
	local bool  bDanger;
	local int   i;
	local float dist;

	bDanger = false;
	for (i=0; i<ArrayCount(projList.list); i++)
	{
		if (projList.list[i].projectile == None)
			break;
		if (projList.center == Location)
			dist = projList.list[i].dist;
		else
			dist = VSize(projList.list[i].location - Location);
		if (dist < projList.list[i].range)
		{
			bDanger = true;
			break;
		}
	}

	return (bDanger);

}
Then bDanger is used in other functions for telling the Pawn to get the fuck away from the projectile (movement code, PickDestination()).

I don't get what could possibly saying pepper gun tear gas should be avoided, but feel free to run into gas grenade-spawned gas. I hate AI code.
Hanfling
MJ12
Posts: 406
Joined: Sun Oct 04, 2009 6:54 pm

Re: AI & Tear Gas

Post by Hanfling »

Are the physics right? Is the collision radius huge enough? However i opted that i will rewrite the whole projectile shit for HX, and these Clouds just suck for multiplayer. However... one thing which is rather strange (relative to other ion code):

ThrownProjectile.uc

Code: Select all

//
// SpawnTearGas needs to happen on the server so the clouds are insync and damage is dealt out of them
//
function SpawnTearGas()
{
	local Vector loc;
	local TearGas gas;
	local int i;

	if ( Role < ROLE_Authority )
		return;

	for (i=0; i<blastRadius/36; i++)
	{
		if (FRand() < 0.9)
		{
			loc = Location;
			loc.X += FRand() * blastRadius - blastRadius * 0.5;
			loc.Y += FRand() * blastRadius - blastRadius * 0.5;
			loc.Z += 32;
			gas = spawn(class'TearGas', None,, loc);
			if (gas != None)
			{
				gas.Velocity = vect(0,0,0);
				gas.Acceleration = vect(0,0,0);
				gas.DrawScale = FRand() * 0.5 + 2.0;
				gas.LifeSpan = FRand() * 10 + 30;
				if ( Level.NetMode != NM_Standalone )
					gas.bFloating = False;
				else
					gas.bFloating = True;
				gas.Instigator = Instigator;
			}
		}
	}
}
Basically the have a PHYS_Projectile but set velocitiy and acceleration to zero. THATS defininatly not what PHYS_Projectile was intended fore. Also they do some weired stuff with setting location. Maybe try either spawning teargas and set Physics to sth. else or make up and own Cloud and set defprop physics to sth. else. Or rewrite the whole game until nothing is left which ion did (despite assets).. i suppose thats the only thing which actually makes sense to do.
gas.Velocity = vect(0,0,0);
gas.Acceleration = vect(0,0,0);
I demand my DXE User ID back. Launcher for DeusEx, Rune, Nerf, Unreal & Botpack. HX on Mod DB. Revision on Steam.
Cybernetic pig
Illuminati
Posts: 2284
Joined: Thu Mar 08, 2012 3:21 am

Re: AI & Tear Gas

Post by Cybernetic pig »

Worth a shot. I shall report the results.
Cybernetic pig
Illuminati
Posts: 2284
Joined: Thu Mar 08, 2012 3:21 am

Re: AI & Tear Gas

Post by Cybernetic pig »

None of that worked, but I seem to have found the problem:

In function GetProjectileList:

Code: Select all

if (cloudProj != None)
            if (range < cloudProj.cloudRadius)
               range = cloudProj.cloudRadius;
         range += CollisionRadius+60;
+60 range between the collision radius of the pawn and the cloud wasn't enough it seems.

The below modification adds a bit of extra distance, but for cloud.uc and children only. Doesn't apply to the various other projectile types.

Code: Select all

if (cloudProj != None)
            if (range < cloudProj.cloudRadius)
               range = cloudProj.cloudRadius+128;
         range += CollisionRadius+60; 
Of course, this hasn't had extensive testing, but they seemed to effectively stay clear of the many individual gas clouds this time.
Note this code may not be suitable for vanilla/other mods. It is for GMDX as demolition skill increases grenade blast radius and at master level makes gas grenades insta-K.O, plus other modifications.

Now to make them not avoid the gas from the pepper gun, so it is actually viable to use at all.
lookneedful
Mole Person
Posts: 5
Joined: Thu Jul 27, 2023 3:23 am

Re: AI & Tear Gas

Post by lookneedful »

Great. I also will try it.connections game
Post Reply