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

The Raven Map
The Raven_Map class owns containers of all the objects that make up the
game world geometry — walls, triggers, spawn points, etc. — and also
owns an instance of the map’s navigation graph. These items are created
when a file of the Raven map format is opened.
When Raven is run, the default map (Raven_DM1) and its correspond
-
ing navigation graph are read from file. A number of Raven bots are then
created at randomly selected, unoccupied spawn points.
Ü
NOTE The parameters for Raven are stored in the Lua script file params.lua.
Access to the scripts is made convenient through the use of a singleton class
Raven_Scriptor, which in turn is derived from the Scriptor class. This class
is simply an encapsulation of all the commonly used methods for accessing Lua
variables like
LuaPopNumber and LuaPopString. If you need further clarifica
-
tion, check out the file common/script/Scriptor.h.
Here is a partial listing of Raven_Maps declaration.
class Raven_Map
{
public:
typedef NavGraphNode<GraphEdge, Trigger<Raven_Bot>*> GraphNode;
typedef SparseGraph<GraphNode> NavGraph;
typedef TriggerSystem<Trigger<Raven_Bot> > Trigger_System;
private:
//the walls that comprise the current map's architecture.
std::vector<Wall2D*> m_Walls;
//triggers are objects that define a region of space. When a raven bot
//enters that area, it "triggers" an event. That event may be anything
//from increasing a bot's health to opening a door or requesting a lift.
Trigger_System m_TriggerSystem;
//this holds a number of spawn positions. When a bot is instantiated
//it will appear at a randomly selected point chosen from this vector.
std::vector<Vector2D> m_SpawnPoints;
//this map’s accompanying navigation graph
NavGraph* m_pNavGraph;
/* EXTRANEOUS DETAIL OMITTED */
public:
Raven_Map();
~Raven_Map();
void Render();
//loads an environment from a file
Raven: An Overview
| 299
Overview of the Game Architecture
bool LoadMap(const std::string& FileName);
void AddSoundTrigger(Raven_Bot* pSoundSource, double range);
double CalculateCostToTravelBetweenNodes(unsigned int nd1,
unsigned int nd2)const;
void UpdateTriggerSystem(std::list<Raven_Bot*>& bots);
/* EXTRANEOUS DETAIL OMITTED */
};
Raven map files are created in the editor that accompanies the project.
Although simple, it is more than adequate for creating Raven maps and
their accompanying navigation graphs. See the following sidebar.
The Raven Map Editor
I’ve coded a simple map editor to help create and edit Raven maps. See
Screenshot 7.2.
The editor is easy to use. Just click on the buttons at the bottom of the
window to select the object you want to add, then click in the display
window to add it. Save the map when it’s finished into the
Raven/Maps folder. Further instructions are provided by the
ReadMe.doc in the Map Editor folder.
300 | Chapter 7
Overview of the Game Architecture
Screenshot 7.2. The Raven Map Editor

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