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

U2.U2NPCController


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
//=============================================================================
// U2NPCController.uc
// Created By: Mike Fox
// Created On: 8/01/00
// $Author: Mfox $
// $Date: 12/17/02 8:30p $
// $Revision: 56 $
//=============================================================================

class U2NPCController extends AIController
	abstract;

/*=============================================================================
Base interface class for all U2 NPCs. Also contains some debugging and error 
handling code, mainly just to keep the size of the U2AI classes under control.
=============================================================================*/

// orders (here so these are part of the interface for U2-level classes)

const OrdersNone	      			= '';					// NPC is free to make its own decisions
const OrdersAttack					= 'attack';				// NPC is on autonomous offense (will attack enemy)
const OrdersDefend					= 'defend';				// NPC is on autonomous defense (will defend base)
const OrdersFollow					= 'follow';				// NPC will stay close to order object
const OrdersGoto					= 'goto';				// NPC will stay at or near a specific location (still gathers inventory)
const OrdersHold					= 'hold';				// NPC will stay at or near a specific location (still gathers inventory)
const OrdersSquad					= 'squad';				// really just "placeholder" orders so NPC is counted as following orders if in a squad

const NotImplementedMessage			= "function not implemented";

const StyleCharge					=  10.0;
const StyleClose					=   1.6;
const StyleNeutral					=   0.0;
const StyleBackOff					=  -1.6;
const StyleRetreat  				=  -5.0;
const StyleRunaway					= -10.0;

// placed under Controller properties so easier to locate/set in-game
var(Controller) globalconfig bool bVisibleAI;	// show/hide AI destination actors, dormant NPCs, movement lines etc.

/* !!mdf-tbd: obsolete / or tbi?
function bool GetAdvancedTactics();
function AlternatePathInterf GetAlternatePath();
function float GetDefaultAggressiveness();
function bool GetInitialized();
function bool GetInitLifeMessage();
function bool GetIsNovice();
function float GetLastAttractCheck();
function bool GetNoClearSpecial();
function Pawn GetOldEnemy();
function float GetPointDied();
function bool GetPowerPlay();
function bool GetTacticalDir();
function bool GetNoTact();

function AddBaseAggressiveness( float Val );
function AddSkill( int AddSkill );
function SetBaseAggressiveness( float NewBaseAggressiveness );
function SetBaseAlertness( float NewBaseAlertness );
function SetCampingRate( float NewCampingRate );
function SetCampOnlyOnce( bool bVal );
function SetCampTime( float Val );
function SetInitialized( bool bVal );
function SetInitLifeMessage( bool bVal );
function SetIsJumpy( bool bVal );
function SetIsKamikaze( bool bVal );
function SetIsLeading( bool bVal );		
function SetIsNovice( bool bVal );		
function SetLastAttractCheck( float Val );	// !!mdf-tbr?
function SetNoClearSpecial( bool bVal );
function SetOldEnemy( Pawn P );
function SetPointDied( float Val );
function SetPowerPlay( bool bVal );
function SetStayFreelance( bool bVal );
function SetStrafingAbility( float NewStrafingAbility );
function SetThreePlus( bool bVal );

function StartMatch();					

function bool FindAmbushSpot();
*/

//!!mdf-tbr:
function NILog( coerce string ContextStr )
{
	DMTNS( "Warning -- " $ NotImplementedMessage $ "(Pawn=" $ Pawn $ ")" $ ": " $ ContextStr );
}

//!!mdf-tbd: called but not implemented!
//!!mdf-tbd: function AmbushPoint GetAmbushSpot()		{ NILog( GetContext(0) ); return None; }
function bool GetIsKamikaze()							{ NILog( GetContext(0) ); return false; }
function bool IsMeleeAttacking()						{ NILog( GetContext(0) ); return false; }
function bool GetIsSniping()							{ NILog( GetContext(0) ); return false; }
function bool GetQuickFire()							{ NILog( GetContext(0) ); return false; }
function bool ShouldBounceProjectile()					{ NILog( GetContext(0) ); return false; }
function float GetBounceLifespan()						{ NILog( GetContext(0) ); return 1.0; }
function bool MaybeSetEnemy( Pawn NewEnemy, optional bool bAlertingOthers )	{ NILog( GetContext(0) ); return false; }
function MaybeInheritEnemy( Pawn Other, Pawn NewEnemy, optional bool bCanSee ) { NILog( GetContext(0) ); }

function DyingRestart()									{ NILog( GetContext(0) ); }

function bool ReadyForAction()							{ return true; }
function bool ReadyForOrders()							{ return true; }

//!!mdf-tbd: function SetAlternatePath( AlternatePath AP )	{ GetContext(0) ); }
//!!mdf-tbd: function SetAmbushSpot( AmbushPoint AP )		{ GetContext(0) ); }
//!!mdf-tbd: function SetVerbose( bool bVal )				{ GetContext(0) ); }

function int GetNumWeapons()							{ return -1; }

//-----------------------------------------------------------------------------
// misc
//-----------------------------------------------------------------------------

function BigJump( Actor JumpDest );
function HandleIncoming( Actor IncomingActor, vector IncomingDirection, float IncomingSpeed );
function HearPickup( Pawn Other );		
function ReflectNotify( name NotifyName );
function YellAt( Pawn Moron );
function SetRandomSoundTimer();
								
//-----------------------------------------------------------------------------
// orders
//-----------------------------------------------------------------------------

function bool SetOrders( optional name NewOrders, optional Actor NewOrdersObject, optional float NewOrdersThreshold, optional Object NewOrderGiver, optional bool bAcknowledge );
function SetSpecialGoal( Actor NewSpecialGoal, optional float NewSpecialGoalDistance, optional bool bFaceSpecialGoalNew );
function name GetOrders() {	return OrdersNone; }
function Actor GetOrdersObject() { return None; }
function float GetOrdersThreshold() { return 0.0; }
function Object GetOrderGiver();
function SetExecuteOrders( bool bVal );

function SetDormant( bool bVal, optional bool bStayDormantVal );

function Actor GetSpecialGoal();
function float GetSpecialGoalDistance();
function bool GetFaceSpecialGoal();
								
//-----------------------------------------------------------------------------
// Weapons
//-----------------------------------------------------------------------------

//!!mdf-tbr?: function SetAccuracy( float NewAccuracy );
//!!mdf-tbr?: function SetFavoriteWeapon( class<Weapon> W );
function bool SupportsWeaponFire( Weapon W )	{ return true; }
function bool SupportsWeaponAltFire( Weapon W )	{ return true; }
function RefreshWeapon( name WeaponName );

//-----------------------------------------------------------------------------
// Scripting
//-----------------------------------------------------------------------------

function EnableProbeEvent( name EventName, bool bVal );
function ReloadScriptController();
function SetScript( string NewCommandFileName, optional string NewStartLabel );
function Shutdown( bool bVal );
function bool HasScript() { return false; }
function bool UnderScriptControl() { return false; }

//-----------------------------------------------------------------------------
// Debugging
//-----------------------------------------------------------------------------

function string GetExtendedStateInformation() { return ""; }
function GetExtendedInformation( out array<string> ReturnedStrings );
function string GetMetaStateName() { return "NA"; }
function string GetMetaStateNameShort() { return "NA"; }

function DumpAIEvents();
function NPCErrorExternal( coerce string Msg );
function NPCErrorInternal( coerce string Msg );
function bool SetTestMoveTarget( Actor TargetActor, optional float MoveSpeed, optional ETacticalMoveType TMT );
function bool IsFiring() { return false; }
function bool CanFire( bool bTest ) { return true; }
function bool CheckTargetInAttackRange( bool bTest ) { return false; }

function ForceNavigationError( bool bScriptedStateMoves, bool bMoveTarget, bool bMinZ );

//-----------------------------------------------------------------------------
//@ _DEBUGGING CODE -- !!mdf-tbr: remove any calls this stuff before shipping!
//-----------------------------------------------------------------------------

function SetDebugAI( bool bVal )
{
	if( bVal )
		AddDebugFlag( Debug_AI );
	else
		RemoveDebugFlag( Debug_AI );
}

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

function SetDebugAIEvents( bool bVal )
{
	if( bVal )
		AddDebugFlag( Debug_AIEvents );
	else
		RemoveDebugFlag( Debug_AIEvents );
}

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

function SetDebugAIMovement( bool bVal )
{
	if( bVal )
		AddDebugFlag( Debug_AIMovement );
	else
		RemoveDebugFlag( Debug_AIMovement );
}

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

function SetDebugAIAttacks( bool bVal )
{
	if( bVal )
		AddDebugFlag( Debug_AIAttacks );
	else
		RemoveDebugFlag( Debug_AIAttacks );
}

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

function SetDebugAIFlags( int Value )
{
	SetDebugFlags( Value );
}

//tbd #debugbegin
//-----------------------------------------------------------------------------
// generic AI messages

function AIMessage( string Prefix, coerce string Msg, optional bool bSkipLine )
{
	class'UtilGame'.static.LogAIDebugMessage( Self, Prefix, Msg, GetMetaStateName() $ "." $ GetStateName(), bSkipLine );
}

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

function DMAI( coerce string Msg, optional bool bForce )
{
	if( (bForce && DebugAIForced()) || DebugAI() )
		AIMessage( "DMAI", Msg );
}

//-----------------------------------------------------------------------------
// attack related messages

function DMAIA( coerce string Msg, optional bool bForce )
{
	if( (bForce && DebugAIForced()) || DebugAIAttacks() )
		AIMessage( "DMAIA", Msg );
}

//-----------------------------------------------------------------------------
// event related messages

function DMAIE( coerce string Msg, optional bool bForce )
{
	// !!mdf-tbd: 
	// if( DebugAIEventHandling() )
	if( (bForce && DebugAIForced()) || DebugAIEvents() )
		AIMessage( "DMAIE", Msg );
}

//-----------------------------------------------------------------------------
// label reached messages

function DMAIL( coerce string Msg, optional bool bForce )
{
	if( (bForce && DebugAIForced()) || DebugAI() )
		AIMessage( "DMAIL", Msg );
}

//-----------------------------------------------------------------------------
// navigation related messages

function DMAIM( coerce string Msg, optional bool bForce )
{
	if( (bForce && DebugAIForced()) || DebugAIMovement() )
		AIMessage( "DMAIM", Msg );
}
//tbd #debugend

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

function DMAssert( bool bTestCondition, coerce string Msg, optional coerce string PreFix )
{
	if( Prefix != "" )
		Prefix = Prefix @ class'UtilGame'.static.GetAIDebugMessage( Self, "", "" ) @ " ";
	else
		Prefix = class'UtilGame'.static.GetAIDebugMessage( Self, "", "" ) @ " ";
		
	Super.DMAssert( bTestCondition, Msg, Prefix  );
}

#debugbegin
//-----------------------------------------------------------------------------
// Can be used during development/testing to catch invalid state transitions.
// Only called (via NotifyStateChange) if bTrackStateChanges=true. Subclasses 
// can override/extend this to perform their own verifications.
// !!mdf-tbd make sure not used in release builds

function VerifyStateChange( name OldState, name NewState, name Label, bool bGoto, string ContextNameStr, int ContextLineNum );

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

event NotifyStateChange( name OldState, name NewState, name Label, bool bGoto, string ContextNameStr, int ContextLineNum )
{
	local string ContextStr;

	if( DebugAI() )
	{
		ContextStr = "  CONTEXT=" $ ContextNameStr $ " Line=" $ ContextLineNum;
		
		if( bGoto )
		{
			// goto
			AIMessage( "Goto", Label $ ContextStr, false );
		}
		else
		{
			// gotostate
			// this should catch all GotoStates and Gotos (since all state changes also call GotoLabel)
			AIMessage( "GotoS", OldState $ " --> " $ NewState $ "," $ Label $ ContextStr, NewState != OldState );
		}
	}

	VerifyStateChange( OldState, NewState, Label, bGoto, ContextNameStr, ContextLineNum );

	Super.NotifyStateChange( OldState, NewState, Label, bGoto, ContextNameStr, ContextLineNum );
}
#debugend

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

function HideActor( Actor A )
{
	if( A != None )
	{
		A.bHidden = A.default.bHidden;
		A.SetDrawScale( A.default.DrawScale );
	}
}

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

function ShowActor( Actor A, optional float NewDrawScale, optional ERenderStyle NewStyle )
{
	if( A != None )
	{
		A.bHidden   = false;

		if( NewDrawScale ~= 0.0 )
			NewDrawScale = A.default.DrawScale;
		A.SetDrawScale( NewDrawScale );

		if( NewStyle == STY_None )
			NewStyle = A.default.Style;
		A.Style = NewStyle;
	}
}

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

function string GetAIEventInfo()
{
	return( "AEnd "			$ byte(IsProbing( Event_AnimEnd )) @
			"Tick "			$ byte(IsProbing( Event_Tick )) @
			"Timer "		$ byte(IsProbing( Event_Timer )) @
			"Trigger "		$ byte(IsProbing( Event_Trigger )) @
			"EInvalid "	    $ byte(IsProbing( Event_EnemyInvalid )) @
			"EMRange "	    $ byte(IsProbing( Event_EnemyInMeleeRange )) @
			"ENotMRange "	$ byte(IsProbing( Event_EnemyNotInMeleeRange )) @
			"ENotVis "		$ byte(IsProbing( Event_EnemyNotVisible )) @
			"ERangeT "	    $ byte(IsProbing( Event_EnemyRangeTransition )) @
			"Bump "			$ byte(IsProbing( Event_NotifyBump )) @
			"Hear "			$ byte(IsProbing( Event_HearNoise )) @
			"RT "			$ byte(IsProbing( Event_ActorRangeTransition )) @
			"SeeEnemy "		$ byte(IsProbing( Event_SeeEnemy )) @
			"SeeFriend "	$ byte(IsProbing( Event_SeeFriend )) @
			"SeeAlert "		$ byte(IsProbing( Event_SeeAlertFriend )) );
			//tbd: "SeeOther "		$ byte(IsProbing( Event_SeeOther )) );
}

//-----------------------------------------------------------------------------
//@ _ERROR HANDLING CODE
//-----------------------------------------------------------------------------

// !!mdf-tbd: remove this stuff before shipping (or earlier) and add code for
// handling navigation problems as gracefully as possible (might still want to
// flag an error if the NPC is scripted up until ship time...).

function NPCError( U2Pawn.EErrorType ErrorType, coerce string Msg )
{
	U2Pawn(Pawn).ErrorGeneral( ErrorType, Msg );
}

//-----------------------------------------------------------------------------
// Appends closest navigation point to NCP to given error message.

function NavigationError( U2Pawn.EErrorType ErrorType, string ErrorMessage )
{
	local NavigationPoint NP, ClosestNP;
	local float Dist, ClosestDist;

	ClosestDist = 9999999.9;
	for( NP=Level.NavigationPointList; NP!=None; NP=NP.nextNavigationPoint )
	{
		Dist = VSize( Pawn.Location - NP.Location );
		if( Dist < ClosestDist )
		{
			ClosestNP	= NP;
			ClosestDist = Dist;
		}
	}

	//AddArrow( Pawn.Location, ClosestNP.Location, ColorRed() );
	ErrorMessage = ErrorMessage $ " (State: " $ GetStateName() $ " MoveTarget:" $ MoveTarget $ " Location: " $ class'Util'.static.GetVectorString(Pawn.Location) $ " Destination:" $ class'Util'.static.GetVectorString(Destination) $ " Closest NP:" $ ClosestNP.Name $ " Distance:" $ class'Util'.static.GetFloatString(ClosestDist) $ ")";
	NPCError( ErrorType, ErrorMessage );
}

//-----------------------------------------------------------------------------
// Return true if the given actor is a valid target for an attack. Return true
// if the target is an enemy even if the target's health is < 0.

function bool OKToHit( Actor HitActor, vector HitLocation, vector HitNormal )
{
	#debug DMAI( "OKToHit: " $ HitActor );

	if( HitActor == None )
		return true;
		
	if( Pawn(HitActor) == None )
		return HitActor.CanHit( Self );

	if( HitActor == ControllerEnemy )
		return true;

	return ( GetAttitudeTo( Pawn(HitActor) ) != ATTITUDE_Friend );
}

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

function bool CanKnockdown( Pawn Instigator, vector HitLocation, float Damage, class<DamageType> DamageType, vector Momentum )
{
	if( !UnderScriptControl() )
		return true;
		
	if( Pawn != None && !Pawn.SameTeam( Instigator ) )
		return true;
		
	return false;
}

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

function bool CanPanic( Pawn Instigator, vector HitLocation, float Damage, class<DamageType> DamageType, vector Momentum )
{
	if( !UnderScriptControl() )
		return true;
		
	if( Pawn != None && !Pawn.SameTeam( Instigator ) )
		return true;
	
	return false;
}

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

function bool CanDoRagdollHit() { return true; }

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

defaultproperties
{
     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:42.000 - Creation time: sk 3-1-2016 10:48:42.830 - Created with UnCodeX