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

Adding Items to the Raven Navigation Graph
Most games include items an agent can pick up and use in some way.
These items can be added as nodes to the navigation graph, enabling the
path planning AI to easily search for the items and plan paths to them.
Where there are multiple instances of the same item, the AI can use the
navgraph to quickly determine which is the least costly to reach.
Remember back in Chapter 5 I showed you an example of a graph node
class designed specifically for use with navigation graphs? Just in case
your memory is as poor as mine, here’s the listing again:
template <class extra_info = void*>
class NavGraphNode : public GraphNode
{
protected:
//the node's position
Vector2D m_vPosition;
//often you will want a navgraph node to contain additional information.
//(for example a node might represent the position of an item type
//such as health, thereby enabling a search algorithm to search a graph
//for that item type)
extra_info m_ExtraInfo;
public:
//ctors
NavGraphNode():m_ExtraInfo(extra_info()){}
NavGraphNode(int idx,
Vector2D pos):GraphNode(idx),
m_vPosition(pos),
m_ExtraInfo(extra_info())
{}
virtual ~NavGraphNode(){}
Vector2D Pos()const;
void SetPos(Vector2D NewPosition);
extra_info ExtraInfo()const;
void SetExtraInfo(extra_info info);
/* EXTRANEOUS DETAIL OMMITTED */
};
This is the node class used by the Raven navigation graph. As mentioned in
the previous chapter, item types in Raven are derived from the
Trigger
class. When a giver-trigger is added to a map using the map editor, a graph
node is also added. That node’s
m_ExtraInfo member is assigned a pointer
to the item it’s twinned with, thereby enabling a modified search algorithm
Practical Path Planning | 341
The Raven Navigation Graph

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