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

failure. In the example given in this chapter, the entities will use an enu
-
merated value as their unique identifier. These can be found in the file
EntityNames.h as
ent_Miner_Bob and ent_Elsa.
The Miner Class
The Miner class is derived from the BaseGameEntity class and contains data
members representing the various attributes a
Miner possesses, such as its
health, its level of fatigue, its position, and so forth. Like the troll example
shown earlier in the chapter, a
Miner owns a pointer to an instance of a
State class in addition to a method for changing what State that pointer
points to.
class Miner : public BaseGameEntity
{
private:
//a pointer to an instance of a State
State* m_pCurrentState;
// the place where the miner is currently situated
location_type m_Location;
//how many nuggets the miner has in his pockets
int m_iGoldCarried;
//how much money the miner has deposited in the bank
int m_iMoneyInBank;
//the higher the value, the thirstier the miner
int m_iThirst;
//the higher the value, the more tired the miner
int m_iFatigue;
public:
Miner(int ID);
//this must be implemented
void Update();
//this method changes the current state to the new state
void ChangeState(State* pNewState);
/* bulk of interface omitted */
};
The Miner::Update method is straightforward; it simply increments the
m_iThirst value before calling the Execute method of the current state. It
looks like this:
State-Driven Agent Design | 53
The West World Project

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