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

Engine.AIController


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
00262
00263
00264
00265
00266
00267
00268
00269
00270
00271
00272
00273
00274
00275
00276
00277
00278
00279
00280
00281
00282
00283
00284
00285
00286
00287
00288
00289
00290
00291
00292
00293
00294
00295
00296
00297
00298
00299
00300
00301
00302
00303
00304
00305
00306
00307
00308
00309
00310
00311
00312
00313
00314
00315
00316
00317
00318
00319
00320
00321
00322
00323
00324
00325
00326
00327
00328
00329
00330
00331
00332
00333
00334
00335
00336
00337
00338
00339
00340
00341
00342
00343
00344
00345
00346
00347
00348
00349
00350
00351
00352
00353
00354
00355
00356
00357
00358
00359
00360
00361
00362
00363
00364
00365
00366
00367
00368
00369
00370
00371
00372
00373
00374
00375
00376
00377
00378
00379
00380
00381
00382
00383
00384
00385
00386
00387
00388
00389
00390
00391
00392
00393
00394
00395
00396
00397
00398
00399
00400
00401
00402
00403
00404
00405
00406
00407
00408
00409
00410
00411
00412
00413
00414
00415
00416
00417
00418
00419
00420
00421
00422
00423
00424
00425
00426
00427
00428
00429
00430
00431
00432
00433
00434
00435
00436
00437
00438
00439
00440
00441
00442
00443
00444
00445
00446
00447
00448
00449
00450
00451
00452
00453
00454
00455
00456
00457
00458
00459
00460
00461
00462
00463
00464
00465
00466
00467
00468
00469
00470
00471
00472
00473
00474
00475
00476
00477
00478
00479
00480
00481
00482
00483
00484
00485
00486
00487
00488
00489
00490
00491
00492
00493
00494
00495
00496
00497
00498
00499
00500
00501
00502
00503
00504
00505
00506
00507
00508
00509
00510
00511
00512
//=============================================================================
// AIController, the base class of AI.
//
// Controllers are non-physical actors that can be attached to a pawn to control 
// its actions.  AIControllers implement the artificial intelligence for the pawns they control.  
//
// This is a built-in Unreal class and it shouldn't be modified.
//=============================================================================
//NEW
class AIController extends LicenseeController
/*OLD
class AIController extends Controller
*/
	native;

//NEW (mdf): renamed from EAttitude and moved here where it belongs
enum EReaction						// order in increasing "friendliness"
{
	REACTION_Fear,					// will try to run away
	REACTION_Attack,				// will attack enemy
//!!mdf-tbr?:	REACTION_Frenzy,		// will attack anything, indiscriminately
//!!mdf-tbd:	REACTION_Threaten,		// animations, but no attack
//!!mdf-tbd:	REACTION_Ignore,		// will ignore -- no reaction beyond maybe looking at target
//!!mdf-tbd:	REACTION_Friendly,		// will act especially friendly
//!!mdf-tbd:	REACTION_Follow 		// will follow accepts player as leader
};
//OLD
var		bool		bHunting;			// tells navigation code that pawn is hunting another pawn,
										//	so fall back to finding a path to a visible pathnode if none
										//	are reachable
var		bool		bAdjustFromWalls;	// auto-adjust around corners, with no hitwall notification for controller or pawn
										// if wall is hit during a MoveToXXX latent execution.

//NEW (mdf) not used with U2
/*OLD
var		AIScript MyScript;
*/

var(AI) private float Skill;				//NEW (mdf) NPC's base skill in 0.0..1.0

simulated //NEW
event PreBeginPlay()
{
	Super.PreBeginPlay();
	if ( bDeleteMe )
		return;

//NEW (mdf) not used with U2
/*OLD
	if ( Level.Game != None )
		Skill += Level.Game.Difficulty; 
	Skill = FClamp(Skill, 0, 3);
*/
}

/* Reset() 
reset actor to initial state - used when restarting level without reloading.
*/
function Reset()
{
	Super.Reset();

	// by default destroy bots (let game re-create)
	if ( bIsPlayer )
		Destroy();
}

//NEW (mdf)
/*OLD
function NotifyTakeHit( Pawn Instigator, vector HitLocation, int Damage, class<DamageType> DamageType, vector Momentum )
{
	if( Instigator != None && Instigator != Pawn )
		DamageAttitudeTo( Instigator, Damage );
} 
*/
//OLD

//NEW (mdf) not used with U2
/*OLD
function Trigger( actor Other, pawn EventInstigator )
{
	TriggerScript(Other,EventInstigator);
}
*/

//NEW (mdf) see GetInverseTrajectory
/*OLD
function float AdjustToss(Ammunition TossedAmmunition, vector Start, vector End)
{
	local vector RecommendedVector, Dir2D;
	local float ReachTime, Dist2D, StartVelZ, EndZ;

	// check for negative gravity
	if ( Pawn.PhysicsVolume.Gravity.Z >= 0 ) 
		return 0;

	RecommendedVector = TossedProjectileClass.Static.GetTossVelocity( Pawn, rot(0,0,0) );

	//determine how long I might be in the air 
	StartVelZ = RecommendedVector.Z;
	RecommendedVector.Z = 0;

	Dir2D = End - Start;
	//Dir2D.Z = 0;
	Dist2D = VSize(Dir2D);
	ReachTime = Dist2D/VSize(RecommendedVector); 	
	EndZ = StartVelZ/ReachTime - 0.25f * Pawn.PhysicsVolume.Gravity.Z * ReachTime;	

	return FMin( -1 * EndZ, Dist2D );
}
*/

/* TriggerScript()
trigger AI script (this may enable it)
*/
//NEW (mdf) not used with U2
/*OLD
function bool TriggerScript( actor Other, pawn EventInstigator )
{
	if ( MyScript != None )
	{
		MyScript.Trigger(EventInstigator,pawn);
		return true;
	}
	return false;
}
*/
	
/* DisplayDebug()
list important controller attributes on canvas
*/
function DisplayDebug(Canvas Canvas, out float YL, out float YPos)
{
	local int i;
	local string T;

	Super.DisplayDebug(Canvas,YL, YPos);

	Canvas.DrawColor.B = 255;	
	Canvas.DrawText("      NAVIGATION MoveTarget "$GetItemName(String(MoveTarget))$" PendingMover "$PendingMover$" MoveTimer "$MoveTimer, false);
	YPos += YL;
	Canvas.SetPos(4,YPos);

	Canvas.DrawText("      Destination "$Destination$" Focus "$GetItemName(string(Focus)), false);
	YPos += YL;
	Canvas.SetPos(4,YPos);

	Canvas.DrawText("      RouteGoal "$GetItemName(string(RouteGoal))$" RouteDist "$RouteDist, false);
	YPos += YL;
	Canvas.SetPos(4,YPos);

	for ( i=0; i<16; i++ )
	{
		if ( RouteCache[i] == None )
		{
			if ( i > 5 )
				T = T$"--"$GetItemName(string(RouteCache[i-1]));
			break;
		}
		else if ( i < 5 )
			T = T$GetItemName(string(RouteCache[i]))$"-";
	}

	Canvas.DrawText("RouteCache: "$T, false);
}

function HearPickup(Pawn Other);

function float AdjustDesireFor(Pickup P)
{
	return 0;
}

//NEW (mdf) 

//let NPC block switching if desired
function bool AllowPickupWeaponSwitch( Weapon Self, float CurrentRating, float PendingRating )
{
	return true;
}

// default implementation
exec function bool SwitchToBestWeapon( optional out float Rating, optional out byte bUseAltMode )	
{ 
	return false; 
}
//OLD

/* GetFacingDirection()
returns direction faced relative to movement dir

0 = forward
16384 = right
32768 = back
49152 = left
*/

//NEW (mdf) not used currently...
/*
...and would need to be changed to work with new serpentine code
need to know whether doing / about to do move with strafing... 
and currently GetTacticalMove returns random results in some cases...

	if ( bAdvancedTactics && !bNoTact )

-->

	if( GetTacticalMoveType() != TMT_None && !bNoTact )
*/	
/*OLD	
function int GetFacingDirection()
{
	local float strafeMag;
	local vector Focus2D, Loc2D, Dest2D, Dir, LookDir, Y;

	if ( (FocalPoint == Destination) || ((MoveTarget != None) && (MoveTarget == Focus)) )
		return 0;

	if ( bAdvancedTactics && !bNoTact )
	{
		if ( bTacticalDir )
			return 49152;
		else
			return 16384;
			
		return 0;
	}

	// check for strafe or backup
	Focus2D = FocalPoint;
	Focus2D.Z = 0;
	Loc2D = Pawn.Location;
	Loc2D.Z = 0;
	Dest2D = Destination;
	Dest2D.Z = 0;
	lookDir = Normal(Focus2D - Loc2D);
	Dir = Normal(Dest2D - Loc2D);
	strafeMag = lookDir dot Dir;
	Y = (lookDir Cross vect(0,0,1));
	if ((Y Dot (Dest2D - Loc2D)) < 0)
		return ( 49152 + 16384 * strafeMag );	
	else
		return ( 16384 - 16384 * strafeMag );
}
*/

/* 
UpdateTactics() - called every 0.5 seconds if TacticalMoveType is TMT_Basic
and is performing a latent MoveToActor() 
*/
event UpdateTactics()
{
	//DMTNS( "UpdateTactics!" );

	if ( bTacticalDir )
	{
		bTacticalDir = false;
		bNoTact = ( FRand() < 0.3 );
	}
	else
	{
		bTacticalDir = true;
		bNoTact = ( FRand() < 0.3 );
	}
}

// UpdateEyeHeight() called if Controller's pawn is viewtarget of a player
function AdjustView(float DeltaTime)
{
	local float TargetYaw, TargetPitch;
	local rotator OldViewRotation,ViewRotation;

	//NEW (mdf) 829 fix pending reply from stevep
	Super.AdjustView( DeltaTime );
	if( !Pawn.bUpdateEyeHeight )
		return;
	//OLD

	// update viewrotation
	ViewRotation = Rotation;
	OldViewRotation = Rotation;			

	//NEW (mdf)
	if ( ControllerEnemy == None )
	/*OLD
	if ( Enemy == None )
	*/
	{
		ViewRotation.Roll = 0;
		if ( DeltaTime < 0.2 )
		{
			OldViewRotation.Yaw = OldViewRotation.Yaw & 65535;
			OldViewRotation.Pitch = OldViewRotation.Pitch & 65535;
			TargetYaw = float(Rotation.Yaw & 65535);
			if ( Abs(TargetYaw - OldViewRotation.Yaw) > 32768 )
			{
				if ( TargetYaw < OldViewRotation.Yaw )
					TargetYaw += 65536;
				else
					TargetYaw -= 65536;
			}
			TargetYaw = float(OldViewRotation.Yaw) * (1 - 5 * DeltaTime) + TargetYaw * 5 * DeltaTime;
			ViewRotation.Yaw = int(TargetYaw);

			TargetPitch = float(Rotation.Pitch & 65535);
			if ( Abs(TargetPitch - OldViewRotation.Pitch) > 32768 )
			{
				if ( TargetPitch < OldViewRotation.Pitch )
					TargetPitch += 65536;
				else
					TargetPitch -= 65536;
			}
			TargetPitch = float(OldViewRotation.Pitch) * (1 - 5 * DeltaTime) + TargetPitch * 5 * DeltaTime;
			ViewRotation.Pitch = int(TargetPitch);
			SetRotation(ViewRotation);
		}
	}
}

//NEW (mdf) not used
/*OLD
function SetOrders(name NewOrders, Controller OrderGiver);

function actor GetOrdersObject()
{
	return None;
} 

function name GetOrders()
{
	return ''; //NEW (mdf)
	//OLD return 'None';
}
*/

/* PrepareForMove()
Give controller a chance to prepare for a move along the navigation network, from
Anchor (current node) to Goal, given the reachspec for that movement.

Called if the reachspec doesn't support the pawn's current configuration.
By default, the pawn will crouch when it hits an actual obstruction. However,
Pawns with complex behaviors for setting up their smaller collision may want
to call that behavior from here
*/
event PrepareForMove(NavigationPoint Goal, ReachSpec Path);

/* WaitForMover()
Wait for Mover M to tell me it has completed its move
*/
function WaitForMover(Mover M)
{
    PendingMover = M;
	bPreparingMove = true;
//NEW (mdf)
	StopMovement( true, false );
/*OLD
	Pawn.Acceleration = vect(0,0,0);
*/
}

/* MoverFinished()
Called by Mover when it finishes a move, and this pawn has the mover
set as its PendingMover
*/
function MoverFinished()
{
	if ( PendingMover.MyMarker.ProceedWithMove(Pawn) )
	{
		PendingMover = None;
		bPreparingMove = false;
	}
}

/* UnderLift()
called by mover when it hits a pawn with that mover as its pendingmover while moving to its destination
*/
function UnderLift(Mover M)
{
	local NavigationPoint N;

	bPreparingMove = false;
	PendingMover = None;

	// find nearest lift exit and go for that
	if ( (MoveTarget != None) && MoveTarget.IsA('LiftCenter') )
		for ( N=Level.NavigationPointList; N!=None; N=N.NextNavigationPoint )
			if ( N.IsA('LiftExit') && (LiftExit(N).LiftTag == M.Tag)
				&& ActorReachable(N) )
			{
				MoveTarget = N;
				return;
			}
}

//NEW (mdf)
//-----------------------------------------------------------------------------
// ADDITIONAL INTERFACE FUNCTIONS 
//-----------------------------------------------------------------------------

function ETacticalMoveType GetTacticalMoveType()
{
	if( GetTimeSinceEnemyLastSeen() < 1.0 && GetSkill() > (1.25*FRand()-1) )
		return Pawn.TacticalMoveType;
	else
		return TMT_None;
}
	
//-----------------------------------------------------------------------------
	
function bool GetAimingLocation( out vector TargetLocation )
{
	local Actor TargetActor;
	local bool bValid;
	local Pawn CurrentEnemy;
	local Actor CurrentTarget;
	
	TargetActor = GetTarget();	
	if( TargetActor != None )
	{
		CurrentEnemy = ControllerEnemy;
		
		if( TargetActor == CurrentEnemy )
		{
			if( GetTimeSinceEnemyLastSeen() > 0.5 )
			{
				// aim at last seen location
				TargetLocation = GetLastEnemySeenLocation();
			}
			else
			{
				TargetLocation = CurrentEnemy.Location;
			}
			
			TargetLocation.Z += 0.90*CurrentEnemy.CollisionHeight;
			bValid = true;
		}
		else 
		{
			CurrentTarget = ControllerTarget;
			if( CurrentTarget != None )
			{
				if( Pawn(CurrentTarget) != None )
					TargetLocation = CurrentTarget.Location + vect(0,0,1)*0.9*CurrentTarget.CollisionHeight;
				else
					TargetLocation = CurrentTarget.Location + vect(0,0,1)*0.5*CurrentTarget.CollisionHeight;
				bValid = true;
			}
		}
	}
	
	//if( bValid )	
	//	DMTNS( "GetAimingLocation Actor: " $ TargetActor $ " returning " $ bValid );
	
	return bValid;
}

/*-----------------------------------------------------------------------------
NOTE: an NPC's skill is in the range 0.0..1.0. The skill returned by GetSkill
has the game's difficulty level added to it (clamped into 0.0..1.0). This 
allows for having NPCs of varying skill within the same game difficulty level,
although it is unlikely that this will be used for singleplayer (this is really
more useful for having customized bots in multiplayer games). Game code that
makes use of an NPC's skill probably shouldn't assume anything about the number 
of skill levels although we may need to do this in some cases where values 
don't scale well linearly.
*/

function SetSkill( float NewSkill )
{
	Skill = FClamp( NewSkill, 0.0, 1.0 );
}

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

function float GetSkill()
{
	return FClamp( Skill + Level.Game.GetNormalizedDifficulty(), 0.0, 1.0 );
}

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

function DisableSenses( optional bool bIncludingBumps )
{
	Disable( Event_HearNoise );
	Disable( Event_SeeEnemy );
	//!!mdf-tbr? if( bIncludingBumps )
	Disable( Event_NotifyBump );
}

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

function EnableSenses( optional bool bIncludingBumps )
{
	Enable( Event_HearNoise );
	Enable( Event_SeeEnemy );
	//!!mdf-tbr? if( bIncludingBumps )
	Enable( Event_NotifyBump );
}
//OLD

defaultproperties
{
	bAdjustFromWalls=true
	bShouldPossess=true
	MinHitWall=-0.500000
     UseReticleOnEvents(0)="UseReticleText"
     UseReticleOnEvents(1)="UseReticleCorners"
     UseReticleOnEvents(2)="UseReticleTopBars"
     ProximityReticleOnEvents(0)="ProximityReticleCorners"
     ProximityReticleOnEvents(1)="ProximityReticleTopBars"
}

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