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

Tyrion.Setup


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
//=====================================================================
// Setup
// Performs one-time initializations/setup for Tyrion AI
//=====================================================================

class Setup extends Engine.Tyrion_Setup
	native;

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

const TARGET_DURATION = 0.5f;	// minimum time the player has to target an for the AI to think it's in the way
const MAX_TARGET_CHECK_RANGE = 10000.0f;	// maximum range for target detection ray traces 
const TIMETOHIT_FUDGE_TERM = 1.0f;			// added to timeToHit to get upper bound on impact time

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

var Tyrion_ResourceBase sensorResource;	// resource that sensors are attached to

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

native static final function Tyrion_ResourceBase GetStaticSensorResource();
native static final function SetStaticSensorResource(Tyrion_ResourceBase sr);

//---------------------------------------------------------------------
// Called at start of gameplay.

function postBeginPlay()
{
	sensorResource = new class'AI_SensorResource';
	SetStaticSensorResource(sensorResource);
	sensorResource.init();	// global sensors set up before resource ticks (other sensors rely on it)

	//log( "AI_SensorResource created!" );
}

function PostLoadGame()
{
	assert(sensorResource != None);
	SetStaticSensorResource(sensorResource);
}

//---------------------------------------------------------------------
// Called whenever time passes

function Tick( float deltaTime )
{
	sensorResource.Tick( deltaTime );
}

//---------------------------------------------------------------------
// Hook in Tyrion for the rook to call into at every tick
// The purpose of this function is to collect in place all
// general AI-related rook processing

event doRookRelatedAIProcessing( float deltaSeconds, Pawn pawn )
{
	local Rook rook;
	rook = Rook(pawn);	// will always be a rook; a pawn is passed in because this function has to be declared in engine

	rook.updatePastPositions( deltaSeconds );

	// more rook-specific processing to come...
}

//---------------------------------------------------------------------
// Hook in Tyrion for the Player to call into at every tick

function doPlayerRelatedAIProcessing( float deltaSeconds, Pawn pawn )
{
	local PlayerCharacterController pcc;
	local BaseAICharacter target;

	pcc = PlayerCharacterController(pawn.controller);
	assert( pcc != None );
	target = BaseAICharacter(pcc.lastIdentified);

	// Is an AI blocking the player's shot?
	if ( class'Pawn'.static.checkAlive( target ) &&
		pcc.lastIdentifiedDuration >= TARGET_DURATION &&
		target.isFriendly( Rook(pawn) ) &&
		enemyBehindTarget( Rook(pawn), target, pcc.lastIdentifiedHitLocation ) != None )
	{
		AI_CharacterResource(target.characterAI).commonSenseSensorAction.getOutOfWaySensor.setValue( pawn, target.Location );
	}
}

//---------------------------------------------------------------------
// stop all movement actions

event stopActions( Pawn pawn )
{
	if ( pawn.controller != None )
		AI_Controller(pawn.controller).stopActions();
}

//---------------------------------------------------------------------
// Continue a ray trace from "shooter" beyond the first target hit ("hitRook");
// return any enemy character hit

function Character enemyBehindTarget( Rook shooter, Rook hitRook, Vector startTrace )
{
	local Vector endTrace;
	local Character hit;

	endTrace = startTrace + Vector(shooter.firingMotor().getViewRotation()) * MAX_TARGET_CHECK_RANGE;
	hit = Character(hitRook.AITrace( endTrace, startTrace, Vect(32, 32, 32) ));

	if ( hit != None && !shooter.isFriendly( hit ) )
		return hit;
	else
		return None;
}

//---------------------------------------------------------------------
// Sends a message to GetOutOfWaySensor when a pawn was bumped by a friendly
// (this function is necessary because gameplay code calls this)

function sendGetOutOfWayMessage( Pawn bumpedPawn, Vector bumpDirection )
{
	AI_CharacterResource(bumpedPawn.characterAI).commonSenseSensorAction.getOutOfWaySensor.setValue( bumpedPawn, bumpDirection );
}

//---------------------------------------------------------------------
// Sends a message to painSensor of squad members when a member dies
// (this function is necessary because gameplay code calls this)

function sendAllyDiedMessage( Pawn ally, Pawn deadPawn, Pawn InstigatedBy, class<DamageType> damageType, vector HitLocation )
{
	if ( ally.characterAI != None )
		AI_CharacterResource(ally.characterAI).commonSenseSensorAction.painSensor.setValue( 100, InstigatedBy, HitLocation, damageType, lastTick );
}

//---------------------------------------------------------------------
// set the expected time this projectile will impact (for miss speech events)

static final function setTarget( Pawn attacker, Rook target, float timeToHit )
{
	// don't overwrite info for previous shot
	if ( target.expectedImpactTime < attacker.level.TimeSeconds )
	{
		//log( "Setting new attacker:" @ ai.name @ "Weapon:" @ BaseAICharacter(ai).weapon.name @ "impact:" @ timeToHit );
		target.attacker = attacker;
		target.expectedImpactTime = attacker.level.TimeSeconds + timeToHit + TIMETOHIT_FUDGE_TERM;
	}
}

//---------------------------------------------------------------------
// gets enemy list from the enemy sensor

function array<Pawn> getEnemyListFromSensor( Pawn ai )
{
	local AI_EnemySensor enemySensor;
	local int i;
	local array<Pawn> result;

	if ( ai.characterAI == None || Rook(ai).vision == None || AI_CharacterResource(ai.characterAI).commonSenseSensorAction == None )
		return result;

	enemySensor = AI_CharacterResource(ai.characterAI).commonSenseSensorAction.enemySensor;
	if ( enemySensor == None || enemySensor.queryUsage() == 0 )
		return result;

	for ( i = 0; i < enemySensor.enemies.length; i++ )
	{
		result[result.length] = enemySensor.enemies[i];
	}

	return result;
}

//---------------------------------------------------------------------
// Checks integrity of ai's enemies list (debug only)

event enemyListSanityCheck( Pawn ai )
{
	local AI_EnemySensor enemySensor;
	local int i, j;
	local array<Pawn> seenList;
	local Rook seenRook;
	local bool bFoundEnemy;

	if ( ai.characterAI == None || Rook(ai).vision == None || AI_CharacterResource(ai.characterAI).commonSenseSensorAction == None )
		return;

	enemySensor = AI_CharacterResource(ai.characterAI).commonSenseSensorAction.enemySensor;
	if ( enemySensor == None || enemySensor.queryUsage() == 0 )
		return;

	seenList = Rook(ai).vision.getSeenList();

	for ( i = 0; i < enemySensor.enemies.length; i++ )
	{
		if ( enemySensor.enemies[i] == None )
		{
			log( "ENEMY LIST sanity check failed for" @ ai.name $ ": contains None entry" );
			assert( enemySensor.enemies[i] != None );
		}
	}

	for ( i = 0; i < enemySensor.enemies.length; i++ )
	{
		if ( !Rook(ai).vision.isVisible( enemySensor.enemies[i] ) )
		{
			log( "ENEMY LIST sanity check failed for" @ ai.name $ ":" @ enemySensor.enemies[i].name @ "is in enemiesList but not in seenList" );
			assert( false );	
		}
	}

	for ( i = 0; i < seenList.length; i++ )
	{
		seenRook = Rook(seenList[i]);
		if ( !Rook(ai).isFriendly(seenRook) )
		{
			bFoundEnemy = false;
			for ( j = 0; j < enemySensor.enemies.length; j++ )
				if ( seenRook == enemySensor.enemies[j] )
					bFoundEnemy = true;

			if ( !bFoundEnemy )
			{
				log( "ENEMY LIST sanity check failed for" @ ai.name $ ":" @ seenRook.name @ "is in seenList but not in enemyList" );
				assert( bFoundEnemy );	
			}
		}
	}
}

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