Overview | Package | Class | Source | Class tree | Glossary | UnrealScript Documentation
previous class next class | frames no frames

# Tyrion.AI_CivilianGuard

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

    //=====================================================================
    // AI_CivilianGuard
    // Panics and cowers if any enemies are seen in the engagement area
    //=====================================================================

    class AI_CivilianGuard extends AI_CharacterAction
    	editinlinenew;

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

    const UNPANIC_DIST = 3000.0f;		// closest the enemy who caused the panic can be before I stop cowering
    const COWER_DURATION = 10;			// minimum time to cower for (seconds)

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

    var(InternalParameters) float engagementAreaRadius "Radius of engagement area";
    var(InternalParameters) float movementAreaRadius "Radius of movement area";
    var(InternalParameters) class<Weapon> preferredWeaponClass "AI will use this weapon if at all possible";

    var(InternalParameters) editconst Vector engagementAreaCenter;
    var(InternalParameters) editconst Actor engagementAreaTarget;
    var(InternalParameters) editconst Vector movementAreaCenter;
    var(InternalParameters) editconst Actor movementAreaTarget;
    var(InternalParameters) editconst IWeaponSelectionFunction weaponSelection;
    var(InternalParameters) editconst IFollowFunction followFunction;

    var BaseAICharacter ai;
    var Pawn target;

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

    //---------------------------------------------------------------------
    // Selection Heuristic
    // Returns a value in the range [0, 1], indicating how suitable this action is for achieving this goal

    static function float selectionHeuristic( AI_Goal goal )
    {
    	return 1.0;				// higher than normal GuardAttack
    }

    //---------------------------------------------------------------------
    // Make the AI cower for a specified time - even if he gets bumped

    latent function cower( BaseAICharacter ai, float time )
    {
    	local int i;

    	// wait for movement to stop or animation will be clobbered
    	AI_Controller(ai.controller).stopMove();

    	while ( !isZero( ai.Velocity ) )
    		yield();
    	ai.LoopAnimation( "A_Cower" );

    	// wait "time" seconds - restart animation if it was interrupted
    	for ( i = 0; i < time; ++i )
    	{
    		if ( !ai.isLoopingAnimation() )
    			ai.LoopAnimation( "A_Cower" );
    		Sleep( 1.0f );
    	}
    }

    //---------------------------------------------------------------------

    function cleanup()
    {
    	super.cleanup();

    	// clear GuardSensor value so action can be activated again
    	// (also important because GuardSensor doesn't terminate when LOS is lost - it relies on the action to do this)
    	if ( achievingGoal.activationSentinel.sensor != None )
    		achievingGoal.activationSentinel.sensor.setObjectValue( None );

    	weaponSelection = None;
    	followFunction = None;
    }

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

    state Running
    {
    Begin:
    	ai = BaseAICharacter(pawn);
    	target = Pawn(achievingGoal.activationSentinel.sensor.queryObjectValue());
    	AI_Guard(achievingGoal.parentAction).lastGuardTarget = target;

    	if ( target == None )
    	{
    		log( "AI WARNING:" @ name $ ":" @ ai.name @ "has no guard target" );
    	}
    	else
    	{
    		if ( ai.logTyrion )
    			log( name @ "started on" @ ai.name $ ". Spotted" @ target.name );

    		if ( FRand() < 1.0f )	// <- panicChance
    		{
    			// Panic
    			waitForGoal( (new class'AI_PanicGoal'( resource, 99 )).postGoal( self ), true );
    		}

    		if ( class'Pawn'.static.checkAlive( target ))
    			waitForGoal( (new class'AI_TurnGoal'( movementResource(), 99, Rotator( target.Location - ai.Location ) )).postGoal( self ), true );

    		// Cower
    		if ( ai.logTyrion )
    			log( name @ "(" @ ai.name @ ") cowering." );

    		pawn.level.speechManager.PlayDynamicSpeech( pawn, 'Cower' );
    		useResources( class'AI_Resource'.const.RU_LEGS );		// don't move while cowering

    		// cower for COWER_DURATION seconds
    		cower( ai, COWER_DURATION );

    		//log( "Cower sleep finished!" @ characterResource().commonSenseSensorAction.enemySensor.queryIntegerValue() );

    		// continue cowering until enemy has vanished
    		while ( class'Pawn'.static.checkAlive( ai ) && class'Pawn'.static.checkAlive( target ) &&
    				(VDistSquared( target.Location, ai.Location ) < UNPANIC_DIST * UNPANIC_DIST ||
    					characterResource().commonSenseSensorAction.enemySensor.queryIntegerValue() != 0 ))
    		{
    			if ( !ai.isLoopingAnimation() )
    				ai.LoopAnimation( "A_Cower" );
    			yield();
    		}

    		//waitForGoal( (new class'AI_MoveToGoal'( movementResource(), achievingGoal.priority, orgLocation )).postGoal( self ), true );
    	}

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

    	succeed();
    }

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

    defaultproperties
    {
    	satisfiesGoal = class'AI_GuardAttackGoal'
    }

Overview | Package | Class | Source | Class tree | Glossary | UnrealScript Documentation
previous class next class | frames no frames

Class file time: ne 5.9.2004 15:53:58.000 - Creation time: st 23.5.2018 00:10:40.986 - Created with UnCodeX