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

AICommon.SquadInfo


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

class SquadInfo extends Engine.Actor
#if !IG_TRIBES3
	placeable
#endif
	native;

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

#if IG_TRIBES3
const MAX_TICKS_TO_PROCESS_PAIN = 5;	// upper bound on the number of AI ticks it will take to react to pain
#endif

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

#if IG_TRIBES3	// place for designers to put goals/abilities
var(AI) editinline array< class<Tyrion_GoalBase> > goals		"Goals the resource is trying to achieve";
var(AI)	editinline array< class<Tyrion_ActionBase> > abilities	"The actions this resource is capable of performing";
#endif

// AI resources - must be created by designers for AI characters
var Tyrion_ResourceBase SquadAI;

var array<Pawn> pawns;	// the pawns that make up this squad (not rooks in case SquadInfo gets moved into Engine for Boston)

var(AI) Tyrion_ResourceBase.AI_LOD_Levels AI_LOD_Level;	// AI Level of detail (LOD)

var float tickTime;				// when tickTime < 0, we tick the AI
var float tickTimeOrg;			// last generated tickTime value
var Range tickTimeUpdateRange;  // min and max time that will be used to make a random tickTime

var bool logTyrion;		// for debug: switch on Tyrion logs

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

//---------------------------------------------------------------------
// Called at start of gameplay
 
function PostBeginPlay()
{
#if IG_TRIBES3	
	local int i;
#endif

 	squadAI = new class<Tyrion_ResourceBase>( DynamicLoadObject( "Tyrion.AI_SquadResource", class'Class'));
	squadAI.setResourceOwner( self );

#if IG_TRIBES3	// process designer-specified goals/abilities
	// Move designer-assigned goals and abilities (actions) to the resource
	for ( i = 0; i < goals.length; i++ )
	{
		squadAI.assignGoal( goals[i] );
	}

	for ( i = 0; i < abilities.length; i++ )
	{
		squadAI.assignAbility( abilities[i] );
	}
#endif
}

function makeDormant( bool onOff )
{
	local int i;

	for ( i = 0; i < pawns.Length; ++i )
		pawns[i].makeDormant( onOff );
}

//---------------------------------------------------------------------
// a squad member was destroyed

function memberDestroyed( Pawn member )
{
	if ( class'Pawn'.static.checkAlive( member ))
		memberDied( member );	// so memberDied is called only once on pawns that die and are subsequently destroyed
}

//---------------------------------------------------------------------
// a squad member died

function memberDied( Pawn member, optional Pawn InstigatedBy, optional class<DamageType> damageType, optional vector HitLocation )
{
#if IG_TRIBES3
	local int i;
#endif

	// notify actions
	squadAI.pawnDied( member );

#if IG_TRIBES3
	for( i = 0; i < pawns.length; ++i )
	{
		if ( pawns[i] != member && class'Pawn'.static.checkAlive( pawns[i] ) )
		{
			pawns[i].setLimitedTimeLODActivation( MAX_TICKS_TO_PROCESS_PAIN );

			Level.AI_Setup.sendAllyDiedMessage( pawns[i], member, InstigatedBy, damageType, HitLocation );
		}
	}
#endif

	if ( !squadAI.isActive() )
	{
#if IG_TRIBES3
		dispatchMessage(new class'MessageSquadDeath'(label));
#endif
		cleanupAI();
	}
}

//---------------------------------------------------------------------
// cleanup AI when squad dead

function cleanupAI()
{
#if IG_TRIBES3
	local int i;

	// make sure the outer of any classes is no longer pointing to this (soon to be destroyed) actor
	for ( i = 0; i < goals.length; ++i )
	{
		level.AI_Setup.makeSafeOuter( self, goals[i] );
	}
#endif

	squadAI.cleanup();
	squadAI.deleteSensors();
	squadAI.deleteRemovedActions();
}

//---------------------------------------------------------------------
// Cause all resources attached to this pawn to re-check their goals

function rematchGoals()
{
	squadAI.bMatchGoals = true;
}

//---------------------------------------------------------------------
// number of living members in the squad
// (returns the first living pawn in the pawn list if there is one)

function int nActiveMembers( out Pawn livingPawn )
{
	local int i;
	local int n;

	// loop over all pawns p in the squad
	for ( i = pawns.length-1; i >= 0 ; --i )
		if ( class'Pawn'.static.checkAlive( pawns[i] ) )
		{
			livingPawn = pawns[i];
			n++;
		}

	return n;
}

//---------------------------------------------------------------------
// Add a pawn to this squad

function addToSquad( Pawn p )
{
	local int i;

	for ( i = 0; i < pawns.length; i++ )
		if ( pawns[i] == p )
			return;					// p already in the list

	pawns[pawns.length] = p;		// pawns.push(p)
}

//---------------------------------------------------------------------
// Remove a pawn from this squad

function removeFromSquad( Pawn p )
{
	local int i;

	for ( i = 0; i < pawns.length; i++ )
		if ( pawns[i] == p )
		{
			pawns.remove( i, 1 );	// removes element - shifts the rest
			break;
		}
}

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

defaultproperties
{
	logTyrion					= false
	bHidden						= true
	AI_LOD_Level				= AILOD_ALWAYS_ON
	tickTimeUpdateRange			= (Min=0.095,Max=0.105)
}

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