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

# Tyrion.AI_SquadGuard

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

    //=====================================================================
    // AI_SquadGuard
    //
    // Just a convenience action to set up guards on the members
    //=====================================================================

    class AI_SquadGuard extends AI_SquadAction
    	editinlinenew;

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

    const MAX_SQUAD_SIZE = 9;			// maximum number of pawns in a squad

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

    var(Parameters) Name engagementAreaCenterName "Label of the Actor that defines the center of the area to be guarded - any enemy within this area will be attacked; an empty label is taken to mean the AI itself";
    var(Parameters) float engagementAreaRadius "Radius of engagement area";
    var(Parameters) Name movementAreaCenterName "Label of the Actor that defines the center of the area the AI can move around in to defend; an empty label is taken to mean the AI's spawn location";
    var(Parameters) float movementAreaRadius "Radius of movement area (0 is taken to mean infinite/no restrictions)";
    var(Parameters) bool removeDefaultGuardGoals "Remove squad members' default guard goals?";

    var(InternalParameters) editconst Vector engagementAreaCenter;
    var(InternalParameters) editconst Actor engagementAreaTarget;
    var(InternalParameters) editconst Vector movementAreaCenter;
    var(InternalParameters) editconst Actor movementAreaTarget;

    var int i;
    var Pawn pawn;
    var AI_Goal goal;
    var AI_Goal guardGoals[MAX_SQUAD_SIZE];		// member's guard goals
    var Actor a;

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

    //---------------------------------------------------------------------
    // Inform an action that a particular pawn died

    function pawnDied( Pawn member )
    {
    	if ( squad().logTyrion )
    		log( name $ ": (" @ squad().name @ ")" @ member.name @ "died!" );

    	assert( member != None );

    	if ( !squad().squadAI.isActive() )
    	{
    		if ( squad().logTyrion )
    			log( name @ "stopped." );
    		instantFail( ACT_ALL_RESOURCES_DIED );
    	}
    }

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

    function cleanup()
    {
    	local int i;

    	super.cleanup();

    	// stop all the followers
    	for ( i = 0; i < squad().pawns.length; i++ )
    	{
    		if ( guardGoals[i] != None )
    		{
    			guardGoals[i].Release();
    			guardGoals[i] = None;
    		}
    	}
    }
    //=====================================================================
    // State code

    state Running
    {
    Begin:
    	// Gotta do assignments involving Names here since names are not passed down to Guard...
    	if ( engagementAreaCenter == default.engagementAreaCenter && engagementAreaCenterName == '' && engagementAreaTarget == None )
    	{
    		engagementAreaCenter = class'AI_GuardGoal'.default.engagementAreaCenter;
    		//log( name @ "resetting engagementAreaCenter to" @ engagementAreaCenter );
    	}

    	if ( engagementAreaCenterName != '' )
    	{
    		a = squad().findStaticByLabel( class'Actor', engagementAreaCenterName, true );
    		if ( a == None )
    		{
    			log( "AI ERROR:" @ name @ engagementAreaCenterName @ "not found!" );
    			fail( ACT_INVALID_PARAMETERS, true );
    		}
    		engagementAreaTarget = a;
    		engagementAreaCenter = a.Location;
    	}

    	if ( movementAreaCenter == default.movementAreaCenter && movementAreaCenterName == '' && movementAreaTarget == None )
    	{
    		movementAreaCenter = class'AI_GuardGoal'.default.movementAreaCenter;
    		//log( name @ "resetting engagementAreaCenter to" @ movementAreaCenter );
    	}

    	if ( movementAreaCenterName != '' )
    	{
    		a = squad().findStaticByLabel( class'Actor', movementAreaCenterName, true );
    		if ( a == None )
    		{
    			log( "AI ERROR:" @ name @ movementAreaCenterName @ "not found!" );
    			fail( ACT_INVALID_PARAMETERS, true );
    		}
    		movementAreaTarget = a;
    		movementAreaCenter = a.Location;
    	}

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

    	for ( i = 0; i < squad().pawns.length; ++i )
    	{
    		pawn = squad().pawns[i];

    		if ( class'Pawn'.static.checkAlive( pawn ) )
    		{
    			// Remove default guard goal if it exists
    			if ( removeDefaultGuardGoals )
    			{
    				goal = class'AI_Goal'.static.findGoalByName( pawn, "DefaultGuardGoal" );
    				if ( goal != None )
    				{
    					if ( squad().logTyrion )
    						log( name $ ": Removing 'DefaultGuardGoal' from" @ pawn.name );
    					goal.unPostGoal( None );
    				}
    			}
    			guardGoals[i] = (new class'AI_GuardGoal'( AI_CharacterResource(pawn.characterAI), achievingGoal.priority,
    										engagementAreaCenter, engagementAreaTarget, engagementAreaRadius,
    										movementAreaCenter, movementAreaTarget, movementAreaRadius,	).postGoal( self )).myAddRef();
    		}
    		else
    			guardGoals[i] = None;
    	}

    	pause();
    	succeed();
    }

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

    defaultproperties
    {
    	satisfiesGoal = class'AI_SquadGuardGoal'
    }

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

Class file time: ne 5.9.2004 15:54:02.000 - Creation time: st 23.5.2018 00:10:41.764 - Created with UnCodeX