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

Tyrion.AI_CharacterAction


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
//=====================================================================
// AI_CharacterAction
// Actions that involve "character" resources (rooks, vehicles)
//=====================================================================

class AI_CharacterAction extends AI_Action
	abstract;

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

var Pawn pawn;
var AI_MovementResource movementResourceStorage;
var AI_WeaponResource weaponResourceStorage;
var AI_HeadResource headResourceStorage;

var AI_Goal DummyMovementGoal;
var AI_Goal DummyWeaponGoal;
var AI_Goal DummyHeadGoal;

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

function cleanup()
{
	super.cleanup();

	if (DummyMovementGoal != None)
	{
		DummyMovementGoal.Release();
		DummyMovementGoal = None;
	}

	if (DummyWeaponGoal != None)
	{
		DummyWeaponGoal.Release();
		DummyWeaponGoal = None;
	}

	if (DummyHeadGoal != None)
	{
		DummyHeadGoal.Release();
		DummyHeadGoal = None;
	}
}

function clearDummyMovementGoal()
{
	if (DummyMovementGoal != None)
	{
		DummyMovementGoal.unPostGoal(self);
		DummyMovementGoal.Release();
		DummyMovementGoal = None;
	}
}

function clearDummyWeaponGoal()
{
	if (DummyWeaponGoal != None)
	{
		DummyWeaponGoal.unPostGoal(self);
		DummyWeaponGoal.Release();
		DummyWeaponGoal = None;
	}
}

function clearDummyHeadGoal()
{
	if (DummyHeadGoal != None)
	{
		DummyHeadGoal.unPostGoal(self);
		DummyHeadGoal.Release();
		DummyHeadGoal = None;
	}
}

function clearDummyGoals()
{
	clearDummyMovementGoal();
	clearDummyWeaponGoal();
	clearDummyHeadGoal();
}

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

//---------------------------------------------------------------------
// Marks the specified resources as being "in use" by this action
// If any of the specified resources are stolen by another action, the action that called this
// function will terminate with a ACT_REQUIRED_RESOURCE_STOLEN message
// resourceBits: Using RU_x constants, specified which leaf resources a dummy action should be created for

latent function useResources( int resourceBits )
{
	local int priority;
	local ACT_ErrorCodes errorCode;
	local AI_Goal movementGoal;
	local AI_Goal weaponGoal;
	local AI_Goal headGoal;

	priority = achievingGoal.priorityFn();

	if ( (resourceBits & resourceUsage & class'AI_Resource'.const.RU_ARMS) != 0 )
	{
		weaponGoal =   (new class'AI_DummyWeaponGoal'( weaponResource(), priority )).postGoal( self ).myAddRef();
		weaponGoal.bTerminateIfStolen = true;
		if ( pawn.logTyrion )
			log( "useResources:" @ weaponGoal.name @ "posted for" @ name );

		DummyWeaponGoal = weaponGoal;
		DummyWeaponGoal.addRef();
	}

	if ( (resourceBits & resourceUsage & class'AI_Resource'.const.RU_LEGS) != 0 )
	{
		movementGoal = (new class'AI_DummyMovementGoal'( movementResource(), priority )).postGoal( self ).myAddRef();
		movementGoal.bTerminateIfStolen = true;
		if ( pawn.logTyrion )
			log( "useResources:" @ movementGoal.name @ "posted for" @ name );

		DummyMovementGoal = movementGoal;
		DummyMovementGoal.addRef();
	}

	if ( (resourceBits & resourceUsage & class'AI_Resource'.const.RU_HEAD) != 0 )
	{
		headGoal = (new class'AI_DummyHeadGoal'( headResource(), priority )).postGoal( self ).myAddRef();
		headGoal.bTerminateIfStolen = true;
		if ( pawn.logTyrion )
			log( "useResources:" @ headGoal.name @ "posted for" @ name );

		DummyHeadGoal = headGoal;
		DummyHeadGoal.addRef();
	}


	if ( weaponGoal != None )
		waitForAllGoalsConsidered( weaponGoal, movementGoal, headGoal );
	else
		waitForAllGoalsConsidered( movementGoal, headGoal );

	if ( ( weaponGoal != None && !weaponGoal.beingAchieved() ) ||
		 ( movementGoal != None && !movementGoal.beingAchieved() ) ||
		 ( headGoal != None && !headGoal.beingAchieved() ))
	{
		if ( pawn.logTyrion )
			log( "useResources:" @ name @ "failing because resources unavailable" );

		// hack to handle the fact that Tyrion assumes character actions can never be blocked by resource contention
		// ideally, resource checking would be done before the character action is matched (one day...)
		resource.bMatchGoals = true;
		errorCode = ACT_INSUFFICIENT_RESOURCES_AVAILABLE;
	}

	if ( weaponGoal != None )
		weaponGoal.Release();

	if ( movementGoal != None )
		movementGoal.Release();

	if ( headGoal != None )
		headGoal.Release();

	if ( errorCode != ACT_SUCCESS )
		Fail( errorCode );
}

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

//---------------------------------------------------------------------
// Initialize a new action 
// 'goal' is the AI_Goal the action is achieving
// 'r' is the resource the action is running on
// Typically called by the resource - sets achievingAction

function initAction(AI_Resource r, AI_Goal goal)
{
	super.initAction( r, goal );

	pawn = AI_CharacterResource(r).m_pawn;
	movementResourceStorage = AI_MovementResource(pawn.movementAI);
	weaponResourceStorage = AI_WeaponResource(pawn.weaponAI);
	headResourceStorage = AI_HeadResource(pawn.headAI);
}

//---------------------------------------------------------------------
// Accessor function for resources

#if IG_TRIBES3
function Rook rook()
{
	return Rook(pawn);
}

function Character character()
{
	return Character(pawn);
}

function BaseAICharacter baseAIcharacter()
{
	return BaseAICharacter(pawn);
}
#endif

function AI_CharacterResource characterResource()
{
	return AI_CharacterResource(resource);
}

function AI_MovementResource movementResource()
{
	return movementResourceStorage;
}

function AI_WeaponResource weaponResource()
{
	return weaponResourceStorage;
}

function AI_HeadResource headResource()
{
	return headResourceStorage;
}

//---------------------------------------------------------------------
// Return the resource class for this action

static function class<Tyrion_ResourceBase> getResourceClass()
{
	return class'AI_CharacterResource';
}

//---------------------------------------------------------------------
// Depending on the type of action, find the resource the action should
// be attached to

static function Tyrion_ResourceBase findResource( Pawn p )
{
	return p.characterAI;
}

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

function classConstruct()
{
	// character actions use all of a character's sub-resources by default
	resourceUsage = class'AI_Resource'.const.RU_ARMS | class'AI_Resource'.const.RU_LEGS | class'AI_Resource'.const.RU_HEAD;
}

defaultproperties
{
	//resourceUsage = 7 // should be RU_HEAD | RU_ARMS | RU_LEGS - can't access or use or's here;
}

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