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

Tyrion.AI_Guard


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
//=====================================================================
// AI_Guard
// Engages any enemies within a specified area
// Doesn't require movement resource
//
// This is the manager action for GuardAttack
//
// What happens if multiple guard actions are posted on the same AI?
// Should work - if there are conflicts the one with the higher priority should prevail
//=====================================================================

class AI_Guard extends AI_CharacterAction implements IFollowFunction
	editinlinenew;

//=====================================================================
// Constants

const GUARDMOVEMENT_PRIORITY = 29;
const DEFAULT_GUARD_DISTANCE = 1500.0f;		// default distance to follow guarded target

//=====================================================================
// Variables

var(Parameters) Name engagementAreaCenterName "Label of the Actor that defines the center of the area to be guarded - any enemy within this area will be attacked; On Protectors this denotes the thing to be protected; an empty label is taken to mean the AI itself";
var(Parameters) float engagementAreaRadius "Radius of engagement area";
var(Parameters) Name movementAreaCenterName "Label of the Actor that defines the center of the area the AI can move around in to defend; an empty label is taken to mean the AI's spawn location";
var(Parameters) float movementAreaRadius "Radius of movement area (0 is taken to mean infinite/no restrictions)";
var(Parameters) class<Weapon> preferredWeaponClass "AI will use this weapon if at all possible";

var(InternalParameters) editconst Vector engagementAreaCenter;
var(InternalParameters) editconst Actor engagementAreaTarget;
var(InternalParameters) editconst Vector movementAreaCenter;
var(InternalParameters) editconst Actor movementAreaTarget;
var(InternalParameters) editconst IWeaponSelectionFunction weaponSelection;

var Rook movementAreaTargetRook;
var Pawn lastGuardTarget;
var float guardDistance;
var Actor a;

//=====================================================================
// Functions

//---------------------------------------------------------------------
// IFollowFunction interface: should offset be updated?

function bool updateOffset( Pawn follower, Pawn leader, int positionIndex )
{
	return false;
}

//---------------------------------------------------------------------
// IFollowFunction interface: offset from leader pawn to actual location follower wants to go to

function Vector offset( Pawn leader, int positionIndex )
{
	return vect(0,0,0);
}

//---------------------------------------------------------------------
// IFollowFunction interface: is a given location a valid place to follow to?

function bool validDestination( Vector point )
{
	return movementAreaRadius == 0 || movementAreaTarget == pawn ||
			// if movement target isn't friendly you can always move
			(movementAreaTargetRook != None && !movementAreaTargetRook.isFriendly(Rook(pawn))) || 
			VSizeSquared2D( point - getMovementAreaCenter() ) <= movementAreaRadius * movementAreaRadius; 
}

//---------------------------------------------------------------------
// IFollowFunction interface: how close do you want to get to the target?
// (gets overridden by attack function)

function float proximityFunction()
{
	return class'AI_DirectAttack'.const.DEFAULT_PROXIMITY;
}

//---------------------------------------------------------------------
// get the center Location of the engagement area
// (not used)

function Vector getEngagementAreaCenter()
{
	if ( engagementAreaTarget == None )
		return engagementAreaCenter;
	else
		return engagementAreaTarget.Location;
}

//---------------------------------------------------------------------
// get the center Location of the movement area

function Vector getMovementAreaCenter()
{
	if ( movementAreaTarget == None )
		return movementAreaCenter;
	else
		return movementAreaTarget.Location;
}

//---------------------------------------------------------------------
// return pertinent information about an action for debugging

function string actionDebuggingString()
{
	return String(name) @ "eng:" $ getEngagementString() $ "," $ engagementAreaRadius @ "mov:" $ getMovementString() $ "," $ movementAreaRadius;
}

final function string getEngagementString()
{
	if ( engagementAreaTarget != None )
		return String(engagementAreaTarget.label);
	else if ( engagementAreaCenterName != '' )
		return String(engagementAreaCenterName);
	else
		return "static";
}

final function string getMovementString()
{
	if ( movementAreaTarget != None )
		return String(movementAreaTarget.label);
	else if ( movementAreaCenterName != '' )
		return String(movementAreaCenterName);
	else
		return "static";
}

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

function cleanup()
{
	super.cleanup();

	weaponSelection = None;
}

//=====================================================================
// State code

state Running
{
Begin:
	if ( engagementAreaCenter == default.engagementAreaCenter && engagementAreaCenterName == '' && engagementAreaTarget == None )
	{
		engagementAreaTarget = pawn;
		engagementAreaCenter = pawn.Location;
		//log( name @ "resetting engagementAreaCenter to" @ engagementAreaCenter );
	}

	if ( engagementAreaCenterName != '' )
	{
		do
		{
			a = pawn.findStaticByLabel( class'Actor', engagementAreaCenterName, true );
			if ( a == None )
			{
				if ( engagementAreaCenterName != 'Player' )
				{
					log( "AI ERROR:" @ name $ ":" @ engagementAreaCenterName @ "not found!" );
					fail( ACT_INVALID_PARAMETERS, true );
				}
				else
					Sleep(1.0f);	// if Player can't be found: try again in a little bit
			}
		} until ( a != None );

		engagementAreaTarget = a;
		engagementAreaCenter = a.Location;
	}

	if ( movementAreaCenter == default.movementAreaCenter && movementAreaCenterName == '' && movementAreaTarget == None )
	{
		movementAreaCenter = pawn.Location;
		//log( name @ "resetting engagementAreaCenter to" @ movementAreaCenter );
	}

	if ( movementAreaCenterName != '' )
	{
		do
		{
			a = pawn.findStaticByLabel( class'Actor', movementAreaCenterName, true );
			if ( a == None )
			{
				if ( movementAreaCenterName != 'Player' )
				{
					log( "AI ERROR:" @ name $ ":" @ movementAreaCenterName @ "not found!" );
					fail( ACT_INVALID_PARAMETERS, true );
				}
				else
					Sleep(1.0f);	// if Player can't be found: try again in a little bit
			}
		} until ( a != None );

		movementAreaTarget = a;
		movementAreaTargetRook = Rook(a);
		movementAreaCenter = a.Location;
	}

	//movementAreaRadius == 0  =>  ignore movement restrictions

	if ( pawn.logTyrion )
		log( name @ "started on" @ pawn.name @ 
			"( movement:" @ getMovementString() $ ", engagement:" @ getEngagementString() @ ")" );

	(new class'AI_GuardAttackGoal'( characterResource(), achievingGoal.priority, 
									engagementAreaCenter, engagementAreaTarget, engagementAreaRadius,
									movementAreaCenter, movementAreaTarget, movementAreaRadius,						  
									weaponSelection, preferredWeaponClass, self )).postGoal( self );

	// Problem: FollowGoal posted below never stops, so even if no enemies are present and the target is stationary,
	//          lower priority goals won't get a chance to run
	// Idea:    Revamp guardMovement to handle following, and to stop following if within movement area and target
	//          isn't moving
	// Idea2:   A more general way to go would be to have follow be triggered off a sensor and free its resources
	//          when within proximity of the target (would have to make all parents of follow can deal with
	//          Follow only being achieved part of the time)

	// Separate issue: Even if they can't shoot, AI's should face their opponent and move to an appropriate
	//          place in their movement area (guardAttack doesn't do this)
	// Idea:    post "if you see a suspicious enemy but can't attack it keep turned to it" goal ?

	if ( movementAreaTarget == None )
	{
		// stationary movement area
		// return to movement area center when no enemies present
		(new class'AI_GuardMovementGoal'( movementResource(), Min(GUARDMOVEMENT_PRIORITY, achievingGoal.priority-1), movementAreaCenter )).postGoal( self );
	}
	else if ( movementAreaTarget != pawn )
	{
		if ( pawn.logTyrion )
			log( name @ "(" @ pawn.name @ ") movementAreaTarget" @ movementAreaTarget.name );

		// moving movement area
		if ( movementAreaRadius == 0 )
			guardDistance = DEFAULT_GUARD_DISTANCE;
		else
			guardDistance = FMin( DEFAULT_GUARD_DISTANCE, 0.75f * movementAreaRadius );

		(new class'AI_NonblockingFollowGoal'( resource,
									achievingGoal.priority-1, movementAreaTarget, guardDistance )).postGoal( self );
		//(new class'AI_FollowGoal'( AI_MovementResource(pawn.movementAI),
		//							achievingGoal.priority-1, movementAreaTarget, guardDistance )).postGoal( self );
	}

	pause();
	succeed();
}

//=====================================================================

defaultproperties
{
	satisfiesGoal = class'AI_GuardGoal'
}

Overview Package Class Source Class tree Glossary
previous class      next class frames      no frames
Class file time: ne 5.9.2004 15:54:00.000 - Creation time: st 23.5.2018 00:10:41.262 - Created with UnCodeX