Game Development Reference
In-Depth Information
Creating the Tank State to Process Commands
The state that processes the tank commands is the StateTankProcessCommand class that is
derived from the StateTank class.
public class StateTankProcessCommand extends StateTank
The ProcessAIVehicleCommand() function sets the next tank state based on the command given the
tank. (See Listing 8-20.)
Listing 8-20. Processing the AI Vehicle Command
void ProcessAIVehicleCommand()
{
VehicleCommand CurrentOrder = GetParent().GetCurrentOrder();
if (CurrentOrder == null)
{
return;
}
if (CurrentOrder.GetCommand() == AIVehicleCommand.None)
{
return;
}
AIVehicleCommand Command = CurrentOrder.GetCommand();
// Process Commands
if (Command == AIVehicleCommand.Patrol)
{
m_NextState = FSM_StatesTank.FSM_STATE_STEER_WAYPOINT;
}
else
{
m_NextState = FSM_StatesTank.FSM_STATE_PROCESS_COMMAND;
}
}
The function does the following:
1.
It gets the current order for this vehicle.
If the order is nonexistent or the command is none ( AIVehicleCommand.None ),
the function returns.
2.
3.
If there is a valid order, the command is retrieved. If the command is to
patrol the arena ( AIVehicleCommand.Patrol ), then set the tank's state to the
patrol/attack state, which has the state id of FSM_STATE_STEER_WAYPOINT .
Otherwise, set the tank's state to the process command state to wait for a
command that can be executed by the tank.
 
Search WWH ::




Custom Search