Game Development Reference
In-Depth Information
Listing 10-28. Setting the Patrol/Attack Tank Order
void SetTankOrder(Tank TankVehicle)
{
// Set Tank Route Index to cycle through all available routes
m_TankRouteIndex++;
if (m_TankRouteIndex >= m_NumberTankRoutes)
{
m_TankRouteIndex = 0;
}
// Set Patrol Order
Route SelectedRoute = m_TankRoutes[m_TankRouteIndex];
Vector3[] WayPoints = SelectedRoute.GetWayPoints();
int NumberWayPoints = SelectedRoute.GetNumberWayPoints();
AIVehicleObjectsAffected ObjectsAffected = AIVehicleObjectsAffected.PrimaryWeapon;
Vector3 Target = new Vector3(0,0,0);
Object3d TargetObj = null;
int NumberRoundToFire = 3;
int FiringDelay = 5000;
VehicleCommand Command = CreatePatrolAttackTankCommand(ObjectsAffected, NumberWayPoints,
WayPoints, Target, TargetObj,NumberRoundToFire,FiringDelay);
TankVehicle.GetDriver().SetOrder(Command);
}
The AddNewTank() function adds a tank object to the playfield. (See Listing 10-29.)
The function does the following:
Tries to retrieve a new available tank object by calling the GetAvailableTank()
function.
1.
2.
If a tank object was available, it
a. Resets the tank and its health to 100
b. Creates a location vector called Max that holds the maximum location of the tank
object along the x and z axes
c. Creates a location vector called Min that holds the minimum location of the tank
object along the x and z axes
d. Calls GenerateGridLocationRestricted() with the Max and Min locations to retrieve a
random location within the bounds of Max and Min
e.
Sets the position of the new tank object to the location generated from the
previous step
Creates and sets the tank object's order by calling SetTankOrder()
f.
3.
Returns true if a new tank object has been added to the game and false
otherwise
 
Search WWH ::




Custom Search