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

Tyrion.ActionBase


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
//=====================================================================
// ActionBase
//
// Base class for Tyrion (AI) and Cersei (Navigation System) actions
//=====================================================================

class ActionBase extends Engine.Tyrion_ActionBase
	native
	abstract
	native
	threaded;

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

// errorCodes; everything > 0 is a failure
enum ACT_ErrorCodes
{
   ACT_SUCCESS,
   ACT_GENERAL_FAILURE,
   ACT_RESOURCE_INACTIVE,		// resource became inactive (due to death, LODding, etc.)
   ACT_INTERRUPTED,				// the action was interrupted by a call to "InterruptAction"
   ACT_CANT_FIND_PATH,
   ACT_IRREVERSIBLY_OFF_COURSE,
   ACT_TIME_LIMIT_EXCEEDED,
   ACT_INVALID_PARAMETERS,		// parameters provided to the action don't make sense
   ACT_CANT_REACH_DESTINATION,
   ACT_ALL_RESOURCES_DIED,		// all the resources the action was running on died
   ACT_REQUIRED_RESOURCE_STOLEN,
   ACT_INSUFFICIENT_RESOURCES_AVAILABLE,
   ACT_INSUFFICIENT_ENERGY,
   ACT_DESTINATION_ENCROACHED,
   ACT_LOST_TARGET,				// lost target of action
   ACT_COULDNT_ENTER_VEHICLE,
   ACT_COULDNT_EXIT_VEHICLE,
   ACT_PARTIAL_SUCCESS
};

const DONT_CARE = -99999.0;			// "don't care" value for movement related action parameters

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

var bool bIdle;					// is this action idle?
var bool bCompleted;			// has this action completed?
var bool bWasTicked;			// true if action was ticked at least once
var bool bDeleted;				// set when this action has been deleted
var bool bSensorAction;			// is this action a sensorAction?

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

//---------------------------------------------------------------------
// Called when an action finished or is interrupted

function cleanup();

//---------------------------------------------------------------------
// Removes action from all the data structures it is in; terminates it

function removeAction();

//---------------------------------------------------------------------
// Removes the goal associated with the action (if any)

function removeGoal();

//---------------------------------------------------------------------
// action state query functions

// Note: idle state is undefined if action has completed
function bool isIdle()
{
	return bIdle;
}

function bool isRunning()
{
	return !bIdle;
}

function bool hasCompleted()
{
	return bCompleted;
}

// true if action was ticked at least once
function bool wasTicked()
{
	return bWasTicked;
}

//---------------------------------------------------------------------
// Pause an action (put it onto idle list)
// Typically called by the resource/controller

function pauseAction();

//---------------------------------------------------------------------
// Run an action
// Typically called by the resource/controller

event runAction();

//---------------------------------------------------------------------
// Inform an action that a particular pawn died
// (Actions should not assume they will only get one of these messages per pawn death)

function pawnDied( Pawn pawn );

//---------------------------------------------------------------------
// Called by an action when it has failed at accomplishing its goal

event instantFail( ACT_ErrorCodes errorCode, optional bool bRemoveGoal )
{
	removeAction();
}

#if IG_TRIBES3
//---------------------------------------------------------------------
// Add action to childAction list

function setChildReference( NS_Action child );

//---------------------------------------------------------------------
// Remove action from childAction list

function removeChildReference( NS_Action child );

//---------------------------------------------------------------------
// Return the Cersei child?

function NS_Action getChildReference();

//---------------------------------------------------------------------
// Callbacks from Navigation System actions
// (used when a Tyrion action wants to call a Cersei action)

function actionSucceededCB( NS_Action child )
{
	// If the child finishes and the parent was idle, start the parent up again
	if ( bIdle && child.bWakeUpParent )
	{
		runAction();
		//log( "-->" @ name @ "now knows that" @ child.name @ "succeeded!" );
	}
}

function actionFailedCB( NS_Action child, ACT_ErrorCodes errorCode )
{
	// If the child finishes and the parent was idle, start the parent up again
	if ( bIdle && child.bWakeUpParent )
	{
		runAction();
		//log( "-->" @ name @ "now knows that" @ child.name @ "failed!" );
	}
}
#endif

//=====================================================================
// Action Idioms

//---------------------------------------------------------------------
// Action idiom: yield
// Continue execution on next tick at the position following 'yield()'

latent function yield()
{
	Sleep(0.0);
}

//---------------------------------------------------------------------
// Action idiom: pause
// Pause an action by taken it off the 'runningActions' list;
// When action is switched back to 'Running' it
// continues execution at the position following 'pause()'

latent function pause()
{
	pauseAction();
	yield();
}

//---------------------------------------------------------------------
// Action idiom: sleepForever

latent function sleepForever()
{
	while( true )
		pause();
}

#if IG_TRIBES3
//---------------------------------------------------------------------
// Action idiom: waitForAction
// Pauses parent until 'child' completes (fails or succeeds)
// (Note: only makes sense for NS_Action children)

latent function waitForAction( NS_Action child )
{
	child.bWakeUpParent = true;
	pause();
}

//---------------------------------------------------------------------
// Action idiom: interruptActionIf
// Parent runs in parallel with child, and interrupts 'child' if 'condition' is true
// If child releases while this function is running, "getChildReference" will return None

latent function interruptActionIf( NS_Action child, class<IBooleanActionCondition> condition )
{
	while ( child != None && !child.hasCompleted() )		// child is still running
	{
		if ( class'Pawn'.static.checkDead( child.controller.pawn ) || condition.static.actionTest( self, child ))	// interrupt child when condition is true
		{
			child.interruptAction();
			break;
		}
		else
		{
			yield();
		}
	}
}
#endif

//=====================================================================
// General utility functions

//---------------------------------------------------------------------
// rotate a vector around Z by "angle" radians
// todo: move to object?

static final function Vector rotateZ( Vector v, float angle )
{
	local Vector result;
	local float cosangle;
	local float sinAngle;

	sinangle = sin(angle);
	cosangle = cos(angle);

	result.X = cosangle * v.X - sinangle * v.Y;
	result.Y = sinangle * v.X + cosangle * v.Y;
	result.Z = v.Z;

	return result;
}

//---------------------------------------------------------------------
// what's the minimum distance between two objects on two trajectories?
// startA and velA define the trajectory of object A
// startB and velB define the trajectory of object B
// Function returns minimum distance and the time t to get to minimum distance (which will be 0
// if objects are moving away from one another)

static final function float minDistBetweenTrajectories( out float t, Vector startA, Vector velA, Vector startB, Vector velB )
{
	local Vector posDelta;
	local Vector velDelta;

	posDelta = startA - startB;
	velDelta = velA - velB;

	t = -posDelta.X * velDelta.X - posDelta.Y * velDelta.Y - posDelta.Z * velDelta.Z;
	t /= velDelta.X * velDelta.X + velDelta.Y * velDelta.Y + velDelta.Z * velDelta.Z;

	if ( t < 0 )
		t = 0;		// trajectories are diverging: t = 0 is the point in time where they are closest

	return VSize( posDelta + t * velDelta );
}

//---------------------------------------------------------------------
// what's the point on a line closest to a given point A?
// (solution taken from "Foley/van Dam/Feiner/Hughes: Computer Graphics - Principles and Practice", p. 1100)

static final function Vector closestPointOnALine( Vector A, Vector lineStart, Vector lineDir )
{
	return lineStart + (( A - lineStart ) Dot lineDir) / (lineDir Dot lineDir) * lineDir;
}

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

defaultproperties
{
	bIdle			= true
	bCompleted		= false
	bSensorAction	= false
}


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.023 - Created with UnCodeX