-
Notifications
You must be signed in to change notification settings - Fork 1
/
Raven_Game.h
202 lines (147 loc) · 6.47 KB
/
Raven_Game.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
#ifndef RAVEN_ENV
#define RAVEN_ENV
#pragma warning (disable:4786)
//-----------------------------------------------------------------------------
//
// Name: Raven_Game.h
//
// Author: Mat Buckland (www.ai-junkie.com)
//
// Desc: this class creates and stores all the entities that make up the
// Raven game environment. (walls, bots, health etc) and can read a
// Raven map file and recreate the necessary geometry.
//
// this class has methods for updating the game entities and for
// rendering them.
//-----------------------------------------------------------------------------
#include <vector>
#include <string>
#include <list>
#include "graph/SparseGraph.h"
#include "Raven_ObjectEnumerations.h"
#include "2d/Wall2D.h"
#include "misc/utils.h"
#include "game/EntityFunctionTemplates.h"
#include "Raven_Bot.h"
#include "Raven_TeamManager.h"
#include "navigation/pathmanager.h"
class BaseGameEntity;
class Raven_Projectile;
class Raven_Map;
class GraveMarkers;
class Raven_Game
{
private:
//the current game map
Raven_Map* m_pMap;
//a list of all the bots that are inhabiting the map
std::list<Raven_Bot*> m_Bots;
//the user can create a Raven bots team that will target an enemy bot
Raven_TeamManager* m_TeamA;
Raven_TeamManager* m_TeamB;
//the user may select a bot to control manually. This is a pointer to that
//bot
Raven_Bot* m_pSelectedBot;
//check if there is a human in the game
bool m_thereIsAHuman;
//this list contains any active projectiles (slugs, rockets,
//shotgun pellets, etc)
std::list<Raven_Projectile*> m_Projectiles;
//this class manages all the path planning requests
PathManager<Raven_PathPlanner>* m_pPathManager;
//if true the game will be paused
bool m_bPaused;
//if true a bot is removed from the game
bool m_bRemoveABot;
//if true a teammate bot is removed from the game
bool m_bRemoveATeammate;
bool m_bRemoveAFollower;
//if true a leader bot is removed from the game
bool m_bRemoveALeader;
//when a bot is killed a "grave" is displayed for a few seconds. This
//class manages the graves
GraveMarkers* m_pGraveMarkers;
//this iterates through each trigger, testing each one against each bot
void UpdateTriggers();
//deletes all entities, empties all containers and creates a new navgraph
void Clear();
//attempts to position a spawning bot at a free spawn point. returns false
//if unsuccessful
bool AttemptToAddBot(Raven_Bot* pBot);
//when a bot is removed from the game by a user all remaining bots
//must be notified so that they can remove any references to that bot from
//their memory
void NotifyAllBotsOfRemoval(Raven_Bot* pRemovedBot)const;
public:
Raven_Game();
~Raven_Game();
//the usual suspects
void Render();
void Update();
//loads an environment from a file
bool LoadMap(const std::string& FileName);
void CreateHumanBot(Raven_Bot* rb);
void AddBots(unsigned int NumBotsToAdd);
void AddTeammates(unsigned int NumBotsToAdd);
void AddOrRemoveLeader();
void AddFollowers(unsigned int NumBotsToAdd);
void AddRocket(Raven_Bot* shooter, Vector2D target);
void AddRailGunSlug(Raven_Bot* shooter, Vector2D target);
void AddShotGunPellet(Raven_Bot* shooter, Vector2D target);
void AddBolt(Raven_Bot* shooter, Vector2D target);
void AddGrenade(Raven_Bot* shooter, Vector2D target);
//removes the last bot to be added
void RemoveBot();
void RemoveTeammate();
void RemoveFollower();
void TeammateRemoval();
void FollowerRemoval();
bool isThereAHuman()const { return m_thereIsAHuman; }
//returns true if a bot of size BoundingRadius cannot move from A to B
//without bumping into world geometry
bool isPathObstructed(Vector2D A, Vector2D B, double BoundingRadius = 0)const;
//returns a vector of pointers to bots in the FOV of the given bot
std::vector<Raven_Bot*> GetAllBotsInFOV(const Raven_Bot* pBot)const;
//returns true if the second bot is unobstructed by walls and in the field
//of view of the first.
bool isSecondVisibleToFirst(const Raven_Bot* pFirst,
const Raven_Bot* pSecond)const;
//returns true if the ray between A and B is unobstructed.
bool isLOSOkay(Vector2D A, Vector2D B)const;
//starting from the given origin and moving in the direction Heading this
//method returns the distance to the closest wall
double GetDistanceToClosestWall(Vector2D Origin, Vector2D Heading)const;
//returns the position of the closest visible switch that triggers the
//door of the specified ID
Vector2D GetPosOfClosestSwitch(Vector2D botPos, unsigned int doorID)const;
//given a position on the map this method returns the bot found with its
//bounding radius of that position.If there is no bot at the position the
//method returns NULL
Raven_Bot* GetBotAtPosition(Vector2D CursorPos)const;
void TogglePause(){m_bPaused = !m_bPaused;}
//this method is called when the user clicks the right mouse button.
//The method checks to see if a bot is beneath the cursor. If so, the bot
//is recorded as selected.If the cursor is not over a bot then any selected
// bot/s will attempt to move to that position.
void ClickRightMouseButton(POINTS p);
//void ChangePositionHumanBot();
//this method is called when the user clicks the left mouse button. If there
//is a possessed bot, this fires the weapon, else does nothing
void ClickLeftMouseButton(POINTS p);
void ChangePositionHumanBot(Vector2D position);
//when called will release any possessed bot from user control
void ExorciseAnyPossessedBot();
//if a bot is possessed the keyboard is polled for user input and any
//relevant bot methods are called appropriately
void GetPlayerInput()const;
Raven_Bot* PossessedBot()const{return m_pSelectedBot;}
void ChangeWeaponOfPossessedBot(unsigned int weapon)const;
const Raven_Map* const GetMap()const{return m_pMap;}
Raven_Map* const GetMap(){return m_pMap;}
const std::list<Raven_Bot*>& GetAllBots()const{return m_Bots;}
PathManager<Raven_PathPlanner>* const GetPathManager(){return m_pPathManager;}
int GetNumBots()const{return m_Bots.size();}
void TagRaven_BotsWithinViewRange(BaseGameEntity* pRaven_Bot, double range)
{TagNeighbors(pRaven_Bot, m_Bots, range);}
};
#endif