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

U2.GameAIControllerImpl


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
//=============================================================================
// GameAIControllerImpl.uc
// Created By: Mike Fox
// Created On: 08/07/01
// $Author: Mfox $
// $Date: 9/13/02 10:55a $
// $Revision: 4 $
//=============================================================================

class GameAIControllerImpl extends GameAIControllerInterf within U2GameInfo;

const UpdateGameAITimerName			= 'UpdateGameAITimer';

// generic game event constants (apply to any game types?)
const GameEventDamage				= 'Damage';
const GameEventDeath  				= 'Death';
const GameEventPickup				= 'Pickup';
const GameEventSpawnSpecial			= 'SpawnSpecial';
const GameEventPlayerAdded			= 'PlayerAdded';
const GameEventPlayerRemoved		= 'PlayerRemoved';

//const GameEventInit  				= 'Init';

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

var int TeamIndex; // index of associated team

var float UpdateGameAIRate;

//-----------------------------------------------------------------------------
// External Interface
//-----------------------------------------------------------------------------

function Initialize( int NewTeamIndex )
{
	TeamIndex = NewTeamIndex;
	AddTimer( UpdateGameAITimerName, UpdateGameAIRate, true );
}

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

function Cleanup()
{
	RemoveAllTimers();
}

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

function UpdateGameAITimer()
{
	UpdateGameAI();
}

//-----------------------------------------------------------------------------
// Subclasses can handle events that they know about or events that they want 
// to handle and call this version for other events.

function GameEvent( name EventName, Actor Instigator, optional Actor OtherActor, optional name OtherInfo )
{
	switch( EventName )
	{
		/*
		case GameEventDamage:
		case GameEventDeath:
		case GameEventPickup:
		case GameEventSpawnSpecial:
		case GameEventPlayerAdded:
		case GameEventPlayerRemoved:
			// !!mdf-tbi:
			break;
		*/

		default:
			GameEventError( "game event not handled", EventName, Instigator, OtherActor, OtherInfo );
			break;
	}

	// !!mdf-tbr:
	DMTN( "GameEvent -- EventName: " $ EventName $ " Instigator: " $ Instigator $ " OtherInfo: " $ OtherInfo );
}

//-----------------------------------------------------------------------------
// MAIN
//-----------------------------------------------------------------------------

function protected GameEventError( coerce string Msg, name EventName, Actor Instigator, optional Actor OtherActor, optional name OtherInfo )
{
	DMTN( "(warning) " $ Msg $ " EventName: " $ EventName $ " Instigator: " $ Instigator $ " OtherActor: " $ OtherActor $ " OtherInfo: " $ OtherInfo );
}

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

function protected UpdateGameAI();

//-----------------------------------------------------------------------------
// HELPERS
//-----------------------------------------------------------------------------

//-----------------------------------------------------------------------------
// Can the game controller control this NPC? In order for true to be returned,
// the given NPC must be valid (not dead), orderable and on the same team as 
// the game controller's team.

function protected bool CanControlNPC( U2NPCController U2NPC )
{
	/*
	DM( "Self              " $ Self );
	DM( "U2NPC             " $ U2NPC );
	DM( "U2NPC.Pawn        " $ U2NPC.Pawn );
	DM( "U2NPC.Pawn.Health " $ U2NPC.Pawn.Health );
	DM( "U2NPC.Orders      " $ U2NPC.GetOrders() );
	DM( "U2NPC.OrderGiver  " $ U2NPC.GetOrderGiver() );
	DM( "U2NPC.PRI         " $ U2NPC.PlayerReplicationInfo );
	DM( "U2NPC.PRI.Team    " $ U2NPC.PlayerReplicationInfo.Team );
	DM( "GAI TeamIndex     " $ TeamIndex );
	DM( "GAI Team          " $ GetTeam( TeamIndex ) );
	*/

	// !!mdf-tbd: ignore Pawn == None and Health <= 0?
	//  otherwise event could be ignored because bot currently dead (not yet respawned)
	// !!mdf-tbd: support non-player (no PRI) NPCs? Not sure how this would work yet.
	return( U2NPC != None &&
			//U2NPC.Pawn != None &&
			//U2NPC.Pawn.Health > 0 &&
			(U2NPC.GetOrders() == U2NPCController.OrdersNone || U2NPC.GetOrderGiver() == Self) &&
			U2NPC.PlayerReplicationInfo != None &&
			U2NPC.PlayerReplicationInfo.Team == GetTeam( TeamIndex ) );
}

//-----------------------------------------------------------------------------
// tbd: calculate as bots added/removed so this just returns an existing count?

function protected int NumTeamPlayers()
{
	local int Count;
	local Controller C;

	for( C=Level.ControllerList; C!=None; C=C.NextController )
		if( C.PlayerReplicationInfo != None && C.PlayerReplicationInfo.Team == GetTeam( TeamIndex ) )
			Count++;

	return Count;
}

/*
//-----------------------------------------------------------------------------
// Return true if the given NPC already has the given orders and order object.

function protected bool AlreadyHasOrders( U2NPCController U2NPC, name DesiredOrders, Actor DesiredOrdersObject )
{
	return ( U2NPC.GetOrders() == DesiredOrders && U2NPC.GetOrdersObject() == DesiredOrdersObject );
}
*/

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

function protected SetNPCSpecialGoal( U2NPCController U2NPC, Actor NewSpecialGoal )
{
	//DMTNS( "SetNPCSpecialGoal for " $ U2NPC $ " to " $ NewSpecialGoal );
	U2NPC.SetSpecialGoal( NewSpecialGoal );
}

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

defaultproperties
{
	UpdateGameAIRate=10.000000
}

Overview Package Class Source Class tree Glossary
previous class      next class frames      no frames
Class file time: sk 3-1-2016 10:38:42.000 - Creation time: sk 3-1-2016 10:48:38.941 - Created with UnCodeX