Engine
Class AIController

source: C:\XIII\Engine\Classes\AIController.uc
Core.Object
   |
   +--Engine.Actor
      |
      +--Engine.Controller
         |
         +--Engine.AIController
Direct Known Subclasses:XIIISpecificController, USA02HelicoBossController, IAController, JohanssonController, Plongeur_Usa01_Controller, SharkController, MitraillGuardController, XIIITransientACreature, BotController, XIIIMPDuckController

class AIController
extends Engine.Controller

//============================================================================= // 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. //=============================================================================

Function Summary
 float AdjustDesireFor(Pickup P)
 float AdjustToss(Ammunition TossedAmmunition, vector Start, vector End)
     
/* AdjustToss()
return adjustment to Z component of aiming vector to compensate for arc given the target
distance
*/
 void AdjustView(float DeltaTime)
     
// UpdateEyeHeight() called if Controller's pawn is viewtarget of a player
 void DisplayDebug(Canvas Canvas, out float, out float)
     
/* DisplayDebug()
list important controller attributes on canvas
*/
 int GetFacingDirection()
     
/* GetFacingDirection()
returns direction faced relative to movement dir

0 = forward
16384 = right
32768 = back
49152 = left
*/
 Actor GetOrderObject()
 name GetOrders()
 void HearPickup(Pawn Other)
 void MoverFinished()
     
/* MoverFinished()
Called by Mover when it finishes a move, and this pawn has the mover
set as its PendingMover
*/
 void Reset()
     
/* Reset() 
reset actor to initial state - used when restarting level without reloading.
*/
 void SetOrders(name NewOrders, Controller OrderGiver)
 void Trigger(Actor Other, Pawn EventInstigator)
 bool TriggerScript(Actor Other, Pawn EventInstigator)
     
/* TriggerScript()
trigger AI script (this may enable it)
*/
 void UnderLift(Mover M)
     
/* UnderLift()
called by mover when it hits a pawn with that mover as its pendingmover while moving to its destination
*/
 void WaitForMover(Mover M)
     
/* WaitForMover()
Wait for Mover M to tell me it has completed its move
*/



Source Code


00001	//=============================================================================
00002	// AIController, the base class of AI.
00003	//
00004	// Controllers are non-physical actors that can be attached to a pawn to control 
00005	// its actions.  AIControllers implement the artificial intelligence for the pawns they control.  
00006	//
00007	// This is a built-in Unreal class and it shouldn't be modified.
00008	//=============================================================================
00009	class AIController extends Controller
00010		native;
00011	
00012	var		bool		bHunting;			// tells navigation code that pawn is hunting another pawn,
00013											//	so fall back to finding a path to a visible pathnode if none
00014											//	are reachable
00015	var		bool		bAdjustFromWalls;	// auto-adjust around corners, with no hitwall notification for controller or pawn
00016											// if wall is hit during a MoveTo() or MoveToward() latent execution.
00017	
00018	var		AIScript MyScript;
00019	
00020	event PreBeginPlay()
00021	{
00022		Super.PreBeginPlay();
00023		if ( bDeleteMe )
00024			return;
00025	
00026		if ( Level.Game != None )
00027			Skill += Level.Game.Difficulty; 
00028		Skill = FClamp(Skill, 0, 3);
00029	}
00030	
00031	/* Reset() 
00032	reset actor to initial state - used when restarting level without reloading.
00033	*/
00034	function Reset()
00035	{
00036		Super.Reset();
00037	
00038		// by default destroy bots (let game re-create)
00039		if ( bIsPlayer )
00040			Destroy();
00041	}
00042	
00043	function Trigger( actor Other, pawn EventInstigator )
00044	{
00045		TriggerScript(Other,EventInstigator);
00046	}
00047	
00048	/* AdjustToss()
00049	return adjustment to Z component of aiming vector to compensate for arc given the target
00050	distance
00051	*/
00052	function float AdjustToss(Ammunition TossedAmmunition, vector Start, vector End)
00053	{
00054		local vector RecommendedVector,Dir2D;
00055		local float ReachTime, Dist2D, StartVelZ, EndZ;
00056	
00057		// check for negative gravity
00058		if ( Pawn.PhysicsVolume.Gravity.Z >= 0 ) 
00059			return 0;
00060	
00061		RecommendedVector = TossedAmmunition.ProjectileClass.Static.GetTossVelocity(Pawn, rot(0,0,0));
00062	
00063		//determine how long I might be in the air 
00064		StartVelZ = RecommendedVector.Z;
00065		RecommendedVector.Z = 0;
00066		Dir2D = End - Start;
00067		Dir2D.Z = 0;
00068		Dist2D = VSize(Dir2D);
00069		ReachTime = Dist2D/VSize(RecommendedVector); 	
00070		EndZ = StartVelZ/ReachTime - 0.25f * Pawn.PhysicsVolume.Gravity.Z * ReachTime;	
00071		return FMin(-1 * EndZ,Dist2D);
00072	}
00073	
00074	/* TriggerScript()
00075	trigger AI script (this may enable it)
00076	*/
00077	function bool TriggerScript( actor Other, pawn EventInstigator )
00078	{
00079		if ( MyScript != None )
00080		{
00081			MyScript.Trigger(EventInstigator,pawn);
00082			return true;
00083		}
00084		return false;
00085	}
00086		
00087	/* DisplayDebug()
00088	list important controller attributes on canvas
00089	*/
00090	function DisplayDebug(Canvas Canvas, out float YL, out float YPos)
00091	{
00092		local int i;
00093		local string T;
00094	
00095		Super.DisplayDebug(Canvas,YL, YPos);
00096	
00097		Canvas.DrawColor.B = 255;	
00098		Canvas.DrawText("      NAVIGATION MoveTarget "$GetItemName(String(MoveTarget))$" PendingMover "$PendingMover$" MoveTimer "$MoveTimer, false);
00099		YPos += YL;
00100		Canvas.SetPos(4,YPos);
00101	
00102		Canvas.DrawText("      Destination "$Destination$" Focus "$GetItemName(string(Focus)), false);
00103		YPos += YL;
00104		Canvas.SetPos(4,YPos);
00105	
00106		Canvas.DrawText("      RouteGoal "$GetItemName(string(RouteGoal))$" RouteDist "$RouteDist, false);
00107		YPos += YL;
00108		Canvas.SetPos(4,YPos);
00109	
00110		for ( i=0; i<16; i++ )
00111		{
00112			if ( RouteCache[i] == None )
00113			{
00114				if ( i > 5 )
00115					T = T$"--"$GetItemName(string(RouteCache[i-1]));
00116				break;
00117			}
00118			else if ( i < 5 )
00119				T = T$GetItemName(string(RouteCache[i]))$"-";
00120		}
00121	
00122		Canvas.DrawText("RouteCache: "$T, false);
00123	}
00124	
00125	function HearPickup(Pawn Other);
00126	
00127	function float AdjustDesireFor(Pickup P)
00128	{
00129		return 0;
00130	}
00131	
00132	/* GetFacingDirection()
00133	returns direction faced relative to movement dir
00134	
00135	0 = forward
00136	16384 = right
00137	32768 = back
00138	49152 = left
00139	*/
00140	function int GetFacingDirection()
00141	{
00142		local float strafeMag;
00143		local vector Focus2D, Loc2D, Dest2D, Dir, LookDir, Y;
00144	
00145		if ( (FocalPoint == Destination) || ((MoveTarget != None) && (MoveTarget == Focus)) )
00146			return 0;
00147	
00148		if ( bAdvancedTactics && !bNoTact )
00149		{
00150			if ( bTacticalDir )
00151				return 49152;
00152			else
00153				return 16384;
00154			return 0;
00155		}
00156	
00157		// check for strafe or backup
00158		Focus2D = FocalPoint;
00159		Focus2D.Z = 0;
00160		Loc2D = Pawn.Location;
00161		Loc2D.Z = 0;
00162		Dest2D = Destination;
00163		Dest2D.Z = 0;
00164		lookDir = Normal(Focus2D - Loc2D);
00165		Dir = Normal(Dest2D - Loc2D);
00166		strafeMag = lookDir dot Dir;
00167		Y = (lookDir Cross vect(0,0,1));
00168		if ((Y Dot (Dest2D - Loc2D)) < 0)
00169			return ( 49152 + 16384 * strafeMag );	
00170		else
00171			return ( 16384 - 16384 * strafeMag );
00172	}
00173	
00174	/* UpdateTactics() - called every 0.5 seconds if bAdvancedTactics is true and is 
00175	performing a latent MoveToward() */
00176	event UpdateTactics()
00177	{
00178		if ( bTacticalDir )
00179		{
00180			bTacticalDir = false;
00181			bNoTact = ( FRand() < 0.3 );
00182		}
00183		else
00184		{
00185			bTacticalDir = true;
00186			bNoTact = ( FRand() < 0.3 );
00187		}
00188	}
00189	
00190	// UpdateEyeHeight() called if Controller's pawn is viewtarget of a player
00191	function AdjustView(float DeltaTime)
00192	{
00193		local float TargetYaw, TargetPitch;
00194		local rotator OldViewRotation,ViewRotation;
00195	
00196		// update viewrotation
00197		ViewRotation = Rotation;
00198		OldViewRotation = Rotation;			
00199	
00200		if ( Enemy == None )
00201		{
00202			ViewRotation.Roll = 0;
00203			if ( DeltaTime < 0.2 )
00204			{
00205				OldViewRotation.Yaw = OldViewRotation.Yaw & 65535;
00206				OldViewRotation.Pitch = OldViewRotation.Pitch & 65535;
00207				TargetYaw = float(Rotation.Yaw & 65535);
00208				if ( Abs(TargetYaw - OldViewRotation.Yaw) > 32768 )
00209				{
00210					if ( TargetYaw < OldViewRotation.Yaw )
00211						TargetYaw += 65536;
00212					else
00213						TargetYaw -= 65536;
00214				}
00215				TargetYaw = float(OldViewRotation.Yaw) * (1 - 5 * DeltaTime) + TargetYaw * 5 * DeltaTime;
00216				ViewRotation.Yaw = int(TargetYaw);
00217	
00218				TargetPitch = float(Rotation.Pitch & 65535);
00219				if ( Abs(TargetPitch - OldViewRotation.Pitch) > 32768 )
00220				{
00221					if ( TargetPitch < OldViewRotation.Pitch )
00222						TargetPitch += 65536;
00223					else
00224						TargetPitch -= 65536;
00225				}
00226				TargetPitch = float(OldViewRotation.Pitch) * (1 - 5 * DeltaTime) + TargetPitch * 5 * DeltaTime;
00227				ViewRotation.Pitch = int(TargetPitch);
00228				SetRotation(ViewRotation);
00229			}
00230		}
00231	}
00232	
00233	function SetOrders(name NewOrders, Controller OrderGiver);
00234	
00235	function actor GetOrderObject()
00236	{
00237		return None;
00238	} 
00239	
00240	function name GetOrders()
00241	{
00242		return 'None';
00243	}
00244	
00245	/* PrepareForMove()
00246	Give controller a chance to prepare for a move along the navigation network, from
00247	Anchor (current node) to Goal, given the reachspec for that movement.
00248	
00249	Called if the reachspec doesn't support the pawn's current configuration.
00250	By default, the pawn will crouch when it hits an actual obstruction. However,
00251	Pawns with complex behaviors for setting up their smaller collision may want
00252	to call that behavior from here
00253	*/
00254	event PrepareForMove(NavigationPoint Goal, ReachSpec Path);
00255	
00256	/* WaitForMover()
00257	Wait for Mover M to tell me it has completed its move
00258	*/
00259	function WaitForMover(Mover M)
00260	{
00261	    PendingMover = M;
00262		bPreparingMove = true;
00263		Pawn.Acceleration = vect(0,0,0);
00264	}
00265	
00266	/* MoverFinished()
00267	Called by Mover when it finishes a move, and this pawn has the mover
00268	set as its PendingMover
00269	*/
00270	function MoverFinished()
00271	{
00272		if ( PendingMover.MyMarker.ProceedWithMove(Pawn) )
00273		{
00274			PendingMover = None;
00275			bPreparingMove = false;
00276		}
00277	}
00278	
00279	/* UnderLift()
00280	called by mover when it hits a pawn with that mover as its pendingmover while moving to its destination
00281	*/
00282	function UnderLift(Mover M)
00283	{
00284		local NavigationPoint N;
00285	
00286		bPreparingMove = false;
00287		PendingMover = None;
00288	
00289		// find nearest lift exit and go for that
00290		if ( (MoveTarget != None) && MoveTarget.IsA('LiftCenter') )
00291			for ( N=Level.NavigationPointList; N!=None; N=N.NextNavigationPoint )
00292				if ( N.IsA('LiftExit') && (LiftExit(N).LiftTag == M.Tag)
00293					&& ActorReachable(N) )
00294				{
00295					MoveTarget = N;
00296					return;
00297				}
00298	}
00299	
00300	defaultproperties
00301	{
00302	     bAdjustFromWalls=True
00303	     bCanOpenDoors=True
00304	     bCanDoSpecial=True
00305	     MinHitWall=-0.500000
00306	}

End Source Code