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

Tyrion.AI_VehicleReactToFire


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
//=====================================================================
// AI_VehicleReactToFire
//
// Note: This action will only be activated if the shooter isn't visible;
//       and if the shooter is friendly, will only be activated when hit
//=====================================================================

class AI_VehicleReactToFire extends AI_VehicleAction
	editinlinenew
	dependsOn(AI_ReactToFireSensor);

import enum TriggerCategories from AI_ReactToFireSensor;

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

var(Parameters) float nearHitDistance "Max distance to react to near hit";
var(Parameters) float allyShotDistance "Max distance to react to an ally getting shot";

var Rook ai;						// vehicle or turret
var BaseAICharacter controllingAI;	// vehicle/turret occupant
var Rook enemy;
var TriggerCategories trigger;	// what triggered ReactToFire?
var bool bFriendly;				// was shooter a friendly?
var bool bVisible;				// is shooter visible?

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

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

state Running
{
Begin:
	ai = rook();

	if ( ai.logTyrion )
		log( name @ "(" @ ai.name @ ") started." );

	// This bit of code assumes that the reactToFire action is started by the reactToFire sensor
	// (and consequently, that the sensor has meaningful values when this action runs). 
	// todo: Think of a way to formalize this dependency? The action could declare its interest in a value even though it doesn't require callbacks?)
	enemy = Rook(vehicleResource().vehicleSensorAction.reactToFireSensor.attacker);	// knowing who fired the shot is a bit a cheat, but the AI does have to spot the enemy before reacting

	if ( enemy == None )
	{
		log( "AI WARNING:" @ name $ ":" @ ai.name @ "has no enemy to react to" );
	}
	else if ( class'Pawn'.static.checkDead( enemy ) )
	{
		;	// enemy is dead
	}
	else
	{
		trigger = vehicleResource().vehicleSensorAction.reactToFireSensor.triggerCategory;
		bFriendly = ai.isFriendly( enemy );
		controllingAI = BaseAICharacter(ai.getControllingCharacter());

		if ( bFriendly )
		{
			//log( ai.name $ ": Stop shooting at me," @ enemy.name $ "! You dumbass!" );
			if ( controllingAI.scaleByWeaponRefireRate( enemy.firingMotor().getWeapon() ) )
				ai.level.speechManager.PlayDynamicSpeech( controllingAI, 'AllyHurtWeapon' );
		}
		else if ( class'Pawn'.static.checkAlive( enemy ) )
		{
			bVisible = ai.vision.isVisible( enemy );

			switch ( trigger )
			{
			case RTF_PAIN:
			case RTF_NEAR_MISS:
			case RTF_COMBAT_SOUND:
				ai.level.speechManager.PlayDynamicSpeech( controllingAI, 'SuspiciousCombat' );
				break;
			case RTF_MOVEMENT_SOUND:
				ai.level.speechManager.PlayDynamicSpeech( controllingAI, 'SuspiciousHear' );
				break;
			}

			// turn to enemy
			if ( !bVisible )
			{
				ai.firingMotor().setViewRotation( Rotator(enemy.Location - ai.Location) );
			}
		}
	}

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

	succeed();
}

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

defaultproperties
{
	satisfiesGoal = class'AI_VehicleReactToFireGoal'
}

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