Overview Package Class Source Class tree Glossary
previous class      next class frames      no frames

U2.StationaryPawn


00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035
00036
00037
00038
00039
00040
00041
00042
00043
00044
00045
00046
00047
00048
00049
00050
00051
00052
00053
00054
00055
00056
00057
00058
00059
00060
00061
00062
00063
00064
00065
00066
00067
00068
00069
00070
00071
00072
00073
00074
00075
00076
00077
00078
00079
00080
00081
00082
00083
00084
00085
00086
00087
00088
00089
00090
00091
00092
00093
00094
00095
00096
00097
00098
00099
00100
00101
00102
00103
00104
00105
00106
00107
00108
00109
00110
00111
00112
00113
00114
00115
00116
00117
00118
00119
00120
00121
00122
00123
00124
00125
00126
00127
00128
00129
00130
00131
00132
00133
00134
00135
00136
00137
00138
00139
00140
00141
00142
00143
00144
00145
00146
00147
00148
00149
00150
00151
00152
00153
00154
00155
00156
00157
00158
00159
00160
00161
00162
00163
00164
00165
00166
00167
00168
00169
00170
00171
00172
00173
00174
00175
00176
00177
00178
00179
00180
00181
00182
00183
00184
00185
00186
00187
00188
00189
00190
00191
00192
00193
00194
00195
00196
00197
00198
00199
00200
00201
00202
00203
00204
00205
00206
00207
00208
00209
00210
00211
00212
00213
00214
00215
00216
00217
00218
00219
00220
00221
00222
00223
00224
00225
00226
00227
00228
00229
00230
00231
00232
00233
00234
00235
00236
00237
00238
00239
00240
00241
00242
00243
00244
00245
00246
00247
00248
00249
00250
00251
00252
00253
00254
00255
00256
00257
00258
00259
00260
00261
//=============================================================================
// StationaryPawn.
//=============================================================================

class StationaryPawn extends U2Pawn
	abstract;

/*-----------------------------------------------------------------------------
NOTE: StationaryPawns (and subclasses) can add lots of unnecessary overhead if
not used carefully.

a) Set their SightRadius to 0 if the StationaryPawn won't react to other NPCs
   or set this as low as possible (e.g. 1024 for a turret which will only shoot
   at enemies which are within that range.

b) Set their SeenRadius as low as possible. e.g. for "aggressive" stationary
   pawns like turrets, set this to something just greater than the SP's
   SightRadius + splash damage radius so NPCs will react to these just outside 
   of that range (or less if NPCs shouldn't see these prior to the SP firing at
   them, at which point the SeenRadius could maybe be goosed up since the NPCs
   will now "know" about it).

c) Set their HearingThreshold to 0 if the SP won't react to hearing noises.
*/

var bool bHasAttack;		// whether the stationary pawn is capable of attacking
var bool bCoverActor;		// whether NPCs can use this actor for cover (hide behind it)
var bool bSpecialCollider;	// if true, is colliding but not during path building
var bool bSpecialEnemy;		// if true, ConsiderAttacking does special checks

var array<ReachSpec> ModifiedReachSpecs; // reachspecs that this stationary pawn modifies

var int RouteCacheDepthCheck; // depth to which route cache is probed when deciding whether to be an enemy

//-----------------------------------------------------------------------------

function bool IsMobile() { return false; }

//-----------------------------------------------------------------------------

event PreBeginPlay()
{
	//NOTE: add before calling PreBeginPlay because the Super can destroy 
	//actors based on difficulty so Destroyed below might try to remove this
	//item from lists below before they were added.
	if( bCoverActor )
		Level.AddToCoverActorList( Self );
	if( bSpecialCollider )
		Level.AddToSpecialColliderList( Self );
		
	Super.PreBeginPlay();
}

//-----------------------------------------------------------------------------

event Destroyed()
{
	if( !bDeleteMe )
	{
		if( bCoverActor )
			Level.RemoveFromCoverActorList( Self );
		if( bSpecialCollider )
			Level.RemoveFromSpecialColliderList( Self );
	}
	
	Super.Destroyed();
}

//-----------------------------------------------------------------------------

function LaunchPawn( Actor Stompee )
{
	// if I'm sitting on another stationary Pawn don't launch myself
	if( StationaryPawn( Stompee ) == None )
		Super.LaunchPawn( Stompee );
}

//-----------------------------------------------------------------------------

function bool PathTraverses( Controller SourceController, NavigationPoint P1, NavigationPoint P2 )
{
	local ReachSpec RS;
	local int ii;
	
	if( P1 == None || P2 == None )
		return false;

	// find the reachspec from P1 to P2
	for( ii=0; ii<P1.PathList.Length; ii++ )
	{
		if( P1.PathList[ ii ].End == P2 )
		{
			RS = P1.PathList[ ii ];
			break;
		}
	}
	
	if( RS == None )
	{
		//!!mdf-tbd: I got a bunch of these playing obolus!?
		//DMTNS( "WARNING (ASSERT): can't find reachspec for path from " $ P1 $ " to " $ P2 $ "!" );
		//AddArrow( P1.Location, P2.Location, ColorOrange() );
		//AddActor( SourceController.Pawn, ColorOrange() );
		#debug DMAssert( false, GetContext() );
		return false;
	}
		
	// see if its one that this field modified
	for( ii=0; ii<ModifiedReachSpecs.Length; ii++ )
		if( ModifiedReachSpecs[ ii ] == RS )
			return true;
			
	return false;
}

//-----------------------------------------------------------------------------
// Subclasses can override this if they consist of multiple actors.

function bool HitSelf( Actor HitActor )
{
	return( HitActor == Self );
}

/*-----------------------------------------------------------------------------
NPCs will only attack StationaryPawns with bSpecialEnemy=true if the NPC 
currently has no path or if the current path will intersect with the 
StationaryPawn within some number of reachspecs.
*/

function bool ConsiderAttacking( Actor TargetActor, U2NPCController AttackingController )
{
	local int ii;
	local Actor HitActor;
	local vector HitLocation, HitNormal;
	local vector Delta;
	local float DistanceBetweenCylinders2D;
	local bool bResult;
	
	//DMTNS( "Should " $ AttackingController.Pawn $ " (" $ AttackingController.GetStateName() $ ")" $ " consider attacking " $ Self );
	
	if( !bSpecialEnemy )
	{
		//DMTNS( "  yes because I'm always a valid enemy" );
		bResult = true; // should always consider attacking
	}
	else if( AttackingController.Pawn == None )
	{	
		// invalid attacker
		//DMTNS( "  no because attacker is invalid (no pawn)" );
	}
	else if( AttackingController.ControllerEnemy != None && StationaryPawn(AttackingController.ControllerEnemy) == None )
	{
		// has a non-stationary pawn enemy currently
		//DMTNS( "  no because attacker already has a non-stationary pawn enemy" );
	}
	/* 2002.12.12 (mdf) might be safer to remove this check in case NPCs are going into perma-PHYS_Falling?
	else if( AttackingController.Pawn.Physics != PHYS_Walking )
	{
		// wait until attacker lands?
		//DMTNS( "  no because attacker is falling" );
	}
	*/
	else
	{
		Delta = AttackingController.Pawn.Location - TargetActor.Location;
		DistanceBetweenCylinders2D = VSize2D( Delta ) - AttackingController.Pawn.CollisionRadius - TargetActor.CollisionRadius;
		
		//DMTNS( "  DistanceBetweenCylinders2D: " $ DistanceBetweenCylinders2D );
		if( DistanceBetweenCylinders2D > 2000 )
		{
			// too far away to worry about
			//DMTNS( "  no because attacker is too far away currently" );
		}
		else if( DistanceBetweenCylinders2D < 8 && Abs(Delta.Z) <= (AttackingController.Pawn.CollisionHeight + TargetActor.CollisionHeight + 8) )
		{
			// actors are practically touching
			//DMTNS( "  yes because attacker is real close" );
			bResult = true;
		}
		else if( AttackingController.MoveTarget == None )
		{
			//2002.12.12 (mdf) check for whether NPC *has* a script not whether its 
			// actually under script control or NPC can acquire enemies which aren't
			// actually blocking it when script won't take NPC anywhere near it?
			//if( !AttackingController.UnderScriptControl() )
			if( !AttackingController.HasScript() )
			{
				// if attacker has no goal (e.g. wandering), can attack XMP item
				//DMTNS( "  yes because attacker has no movetarget currently and isn't under script control" );
				bResult = true;
			}
			else
			{
				//DMTNS( "  no because attacker has no movetarget but is under script control" );
			}
		}
		else
		{
			// if NPC's current direction will send it through item (or part of it), attack it
			//!!mdf-tbd: this could be made more robust (2D geometric check)?
			HitActor = AttackingController.Pawn.Trace( HitLocation, HitNormal, AttackingController.MoveTarget.Location, AttackingController.Pawn.Location, true );
			if( HitSelf( HitActor ) )
			{
				//AddArrow( AttackingController.Pawn.Location, AttackingController.MoveTarget.Location, ColorWhite() );
				//DMTNS( "  yes because attacker is headed towards me: " $ AttackingController.MoveTarget );
				bResult = true;
			}
			else
			{
				for( ii=0; ii<RouteCacheDepthCheck-1; ii++ )
					if( PathTraverses( AttackingController, NavigationPoint(AttackingController.RouteCache[ ii ]), NavigationPoint(AttackingController.RouteCache[ ii+1 ]) ) )
					{
						//AddArrow( NavigationPoint(AttackingController.RouteCache[ ii ]).Location, NavigationPoint(AttackingController.RouteCache[ ii+1 ]).Location, ColorWhite() );
						//DMTNS( "  yes because attacker's route cache will pass through me #" $ ii );
						bResult = true;
						break;
					}
			}
			
			//if( !bResult )
			//	DMTNS( "  no because attacker NOT pathing through me" );
		}
	}
			
	//DMTNS( "  StationaryPawn.ConsiderAttacking returning " $ bResult );
	return bResult;
}

//-----------------------------------------------------------------------------

simulated function AddVelocity( vector NewVelocity );

//-----------------------------------------------------------------------------

defaultproperties
{
	bCoverActor=true
	RouteCacheDepthCheck=3
	bCanOpenDoors=false
	bCanDoSpecial=false
	MaxDesiredSpeed=0.000000
	HearingThreshold=0.000000
	SightRadius=0.000000
	SeenRadius=1024.000000
	GroundSpeed=0.000000
	WaterSpeed=0.000000
	AccelRate=0.000000
	JumpZ=0.000000
	Health=500
	ControllerClass=Class'U2.StationaryPawnController'
	bCanTeleport=false
	bIgnoreSingularityForces=true
	RemoteRole=ROLE_DumbProxy
	RotationRate=(Pitch=0,Yaw=0,Roll=0)
     UseReticleOnEvents(0)="UseReticleText"
     UseReticleOnEvents(1)="UseReticleCorners"
     UseReticleOnEvents(2)="UseReticleSideBars"
     ProximityReticleOnEvents(0)="ProximityReticleCorners"
     ProximityReticleOnEvents(1)="ProximityReticleSideBars"
}

Overview Package Class Source Class tree Glossary
previous class      next class frames      no frames
Class file time: sk 3-1-2016 10:38:42.000 - Creation time: sk 3-1-2016 10:48:41.868 - Created with UnCodeX