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

Tyrion.AI_BucklerKnock


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
//=====================================================================
// AI_BucklerKnock
// Tries to ram a target with the buckler
//=====================================================================

class AI_BucklerKnock extends AI_CharacterAction implements IBooleanActionCondition
	editinlinenew;

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

const TIME_OUT_DURATION = 4.0f;			// how long to try ramming your target
const SPRINT_SPEED = 777.0f;			// ( 35.0f * 80.0f / 3.6f )

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

var(Parameters) editinline Name targetName "Label of target (should be Player)";
var(Parameters) float knockDistance "max ramming distance";

var(InternalParameters) Pawn target;	// pawn I want to ram

var BaseAICharacter ai;
var AI_Controller c;
var ACT_ErrorCodes errorCode;			// errorcode from child action
var Vector destination;
var float startTime;					// when did ramming movement start
var float endTime;						// timeOut for knocking
var Weapon w;
var float terminalHeight;
var array<Actor> ignore;
var Vector lastValidLocation;

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

//---------------------------------------------------------------------
// Selection Heuristic
// Returns a value in the range [0, 1], indicating how suitable this action is for achieving this goal

static function float selectionHeuristic( AI_Goal goal )
{
	local BaseAICharacter ai;

	ai = BaseAICharacter(goal.resource.pawn());

	if ( ai.pack != None && ai.bUsePackActiveEffect && ClassIsChildOf( ai.pack.class, class'SpeedPack' ) )
		return 1.0;
	else
		return 0.0;
}

//---------------------------------------------------------------------
// The test used to figure out when to interrupt Follow

static function bool actionTest( ActionBase parent, NS_Action child )
{
	local AI_BucklerKnock bucklerKnock;
	local BaseAICharacter ai;

	bucklerKnock = AI_BucklerKnock(parent);
	ai = bucklerKnock.ai;

	// interrupt action when target dies
	if ( class'Pawn'.static.checkDead( bucklerKnock.target ) )
		return true;

	if ( ai.level.timeSeconds >= bucklerKnock.endTime ||	// timed out *or*
		(ai.lastBumpActor == bucklerKnock.target &&			// hit the target
		 ai.firstBumpTime >= bucklerKnock.startTime ) )
	{
		//log( ai.name @ "ended" @ bucklerKnock.name @ ai.level.timeSeconds >= bucklerKnock.endTime );
		return true;
	}
	else
		return false;
}

//---------------------------------------------------------------------
// Callbacks from Navigation System actions

function actionSucceededCB( NS_Action child )
{
	super.actionSucceededCB( child );
	errorCode = ACT_SUCCESS;
}

function actionFailedCB( NS_Action child, ACT_ErrorCodes anErrorCode )
{
	super.actionFailedCB( child, anErrorCode );
	errorCode = anErrorCode;
}

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

function cleanup()
{
	local AI_Controller c;

	super.cleanup();

	c = AI_Controller(resource.pawn().controller);

	if ( c != None )
	{
		c.bNoLOA = false;
		c.stopMove();
	}
}

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

state Running
{
Begin:
	if ( target == None && targetName == '' )
	{
		log( "AI WARNING:" @ name @ "(" @ pawn.name @ ") has no target" );
		fail( ACT_INVALID_PARAMETERS, true );
	}

	if ( target == None )
		target = Pawn(pawn.findByLabel( class'Pawn', targetName, true ));

	if ( pawn.logTyrion )
		log( name @ "started on" @ pawn.name $ ". Target:" @ target.name );

	if ( target == None )
	{
		log( "AI WARNING:" @ name @ "can't find specified pawn" );
		fail( ACT_INVALID_PARAMETERS, true );
	}

	if ( pawn.controller == None )
	{
		log( "AI WARNING:" @ name @ "doesn't have a controller. This shouldn't be" );
		fail( ACT_GENERAL_FAILURE );
	}

	ai = baseAICharacter();
	c = AI_Controller(ai.Controller);

	while ( class'Pawn'.static.checkAlive( ai ) && class'Pawn'.static.checkAlive( target ) )
	{
		w = Buckler(ai.weapon);

		// don't block if no buckler equipped or buckler is flying 
		if ( w != None && w.hasAmmo() && ai.pack.IsInState( 'Charged' ) )
		{
			destination = target.predictedLocation( VSize2D( target.Location - ai.Location ) / SPRINT_SPEED );
			// make sure target can actually get to the predicted location...
			c.canPointBeReached( target.Location, destination, target, ignore, lastValidLocation );
			destination = lastValidLocation;

			if ( VSizeSquared2D( ai.Location - destination ) < knockDistance * knockDistance &&
				c.canJetToPoint( ai, ai.Location, destination, ai.energy ) >= 0 )
			{
				// claim legs; stop arms from firing buckler
				useResources( class'AI_Resource'.const.RU_ARMS | class'AI_Resource'.const.RU_LEGS );

				//todo: if legs weren't claimed, quit (can't really happen since this action goal has high default priority)

				// activate speed pack (has to be charged)
				ai.level.speechManager.PlayDynamicSpeech( ai, 'UsePackSpeed' );
				ai.pack.activate();

				startTime = ai.level.timeSeconds;
				endTime = startTime + TIME_OUT_DURATION;

				terminalHeight = target.Location.Z - c.getTerrainHeight( target.Location );
				if ( terminalHeight < 2.0f * target.CollisionHeight )
					terminalHeight = 0;	// no need to jetpack if target barely above the ground
				else
					terminalHeight -= class'AI_TakeCover'.const.BASE_NODE_GAP;

				//log( "KNOCK!  predicted-delta:" @ VSize2D( destination - target.Location ) );
				c.bNoLOA = true;
				interruptActionIf( class'NS_DoLocalMove'.static.startAction( c, self, destination, false,,,,,
									0,, terminalHeight, 50 ), class'AI_BucklerKnock' );
				c.bNoLOA = false;

				clearDummyWeaponGoal();			// resume regular firing behavior
				clearDummyMovementGoal();		// free up legs
			}
		}

		yield();
	}

	if ( pawn.logTyrion )
		log( name @ "(" @ pawn.name @ ") stopped." );

	succeed();
}

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

defaultproperties
{
	satisfiesGoal = class'AI_BucklerKnockGoal'
}

Overview Package Class Source Class tree Glossary
previous class      next class frames      no frames
Class file time: čt 9.9.2004 16:25:32.000 - Creation time: st 23.5.2018 00:10:40.955 - Created with UnCodeX