O'Reilly logo

Programming Game AI by Example by Mat Buckland

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

To get through the sliding door, the bot must follow these steps
1. Get the list of buttons that open the door (b1 and b2).
2. From the list, select the closest navigable button (b1).
3. Plan and follow a path to button b1 (the button will trigger, opening
the door).
4. Plan and follow a path to node A.
5. Traverse the edge AB.
Goal_NegotiateDoor addresses each of these steps in its Activate method,
adding the subgoals necessary to complete the task. The listing will help
clarify.
void Goal_NegotiateDoor::Activate()
{
m_iStatus = active;
//if this goal is reactivated then there may be some existing subgoals that
//must be removed
RemoveAllSubgoals();
//get the position of the closest navigable switch
Vector2D posSw = m_pOwner->GetWorld()->GetPosOfClosestSwitch(m_pOwner->Pos(),
m_PathEdge.GetDoorID());
//because goals are *pushed* onto the front of the subgoal list they must
//be added in reverse order.
//first, the goal to traverse the edge that passes through the door
AddSubgoal(new Goal_TraverseEdge(m_pOwner, m_PathEdge));
//next, the goal that will move the bot to the beginning of the edge that
//passes through the door
AddSubgoal(new Goal_MoveToPosition(m_pOwner, m_PathEdge.GetSource()));
//finally, the goal that will direct the bot to the location of the switch
AddSubgoal(new Goal_MoveToPosition(m_pOwner, posSw));
}
You can see Raven’s bots navigating doors by running Raven and loading
the map Raven_DM1_With_Doors.map. It uses a sparse navgraph so you
can clearly see how the NegotiateDoor goal works.
Command Queuing
Real-time strategy games have grown in complexity tremendously over the
last few years. Not only has the number of NPCs a player is able to control
increased, but also the number of commands he can instruct the NPCs to
follow. This has necessitated several improvements to the user interface,
one being the ability for a player to queue an NPC’s orders — something
that has become known as command queuing (or build queuing).
410 | Chapter 9
Spin-offs
One of the first uses of queuing was to position waypoints for an NPC to
follow as a path. To do this a player holds down a key while clicking on the
map to create a series of waypoints. The NPC stores the waypoints in a
FIFO (first in, first out) data structure and follows them in order, stopping
when its queue is empty. See Figure 9.14.
Designers quickly realized that with slight modification, the user could also
assign patrol points to an NPC. If the waypoints are assigned by the player
as patrol points (by holding down a different key while clicking), they are
returned to the back of the queue as the NPC reaches them. In this way an
Goal-Driven Agent Behavior | 411
Spin-offs
Figure 9.14. Queuing path waypoints
Figure 9.15. Queuing patrol waypoints

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required