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

Tyrion.AI_SquadPatrol


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

class AI_SquadPatrol extends AI_SquadAction
	editinlinenew;

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

var(Parameters) editconst array<Name> patrolPointNames;
var(Parameters) Character.GroundMovementLevels groundMovement "Desired ground movement speed";
var(Parameters) bool bExecuteOnce "Go through the patrol nodes just once";

var array<Vector> patrolPoints;
var int patrolIndex;
var int closestIndex;
var float distSquared, closestDistSquared;
var Actor node;

var AI_Goal moveGoal;

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

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

function cleanup()
{
	super.cleanup();

	if ( moveGoal != None )
	{
		moveGoal.Release();
		moveGoal = None;
	}
}

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

state Running
{
Begin:
	if ( patrolPointNames.length == 0 )
	{
		log( "AI WARNING:" @ name @ "has no patrol points" );
		succeed();
	}

	// find closest patrolPoint; initialize patrolPoints array
	for ( patrolIndex = 0; patrolIndex < patrolPointNames.length; ++patrolIndex )
	{
		node = squad().findStaticByLabel( class'Pathfinding.PlacedNode', patrolPointNames[patrolIndex] );

		if ( node == None )
		{
			log( "AI WARNING:" @ name @ "(" @ squad().name @ ") can't find specified path node" @ patrolPointNames[patrolIndex] );
			fail( ACT_INVALID_PARAMETERS, true );
		}

		patrolPoints[patrolIndex] = node.Location;

		// todo: use the center of gravity of the squad instead of squad().Location
		//distSquared = VDistSquared( node.Location, squad().Location );

		//if ( distSquared < closestDistSquared )
		//{
		//	closestDistSquared = distSquared;
		//	closestIndex = patrolIndex;
		//}
	}

	patrolIndex = closestIndex;

	if ( squad().logTyrion )
		log( name @ "(" @ squad().name @ ") started patrolling at node" @ closestIndex );

	while ( !bExecuteOnce || patrolIndex != patrolPoints.length )
	{
		if ( patrolIndex == patrolPoints.length )
			patrolIndex = 0;

		moveGoal = (new class'AI_SquadMoveToGoal'( resource, achievingGoal.priority, patrolPoints[patrolIndex], ,,, groundMovement )).myAddRef();
		waitForGoal( moveGoal.postGoal( self ) );

		if ( !moveGoal.wasAchieved() )
		{
			if ( squad().logTyrion )
				log( name @ "(" @ squad().name @ ") aborted due to SquadMoveToGoal failing." );
			fail( ACT_CANT_REACH_DESTINATION );
		}

		patrolIndex++;
	}

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

	succeed();
}

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

defaultproperties
{
	satisfiesGoal = class'AI_SquadPatrolGoal'

	closestDistSquared = 99999999999999.9f
}

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