1 | /* |
---|
2 | * ORXONOX - the hottest 3D action shooter ever to exist |
---|
3 | * > www.orxonox.net < |
---|
4 | * |
---|
5 | * |
---|
6 | * License notice: |
---|
7 | * |
---|
8 | * This program is free software; you can redistribute it and/or |
---|
9 | * modify it under the terms of the GNU General Public License |
---|
10 | * as published by the Free Software Foundation; either version 2 |
---|
11 | * of the License, or (at your option) any later version. |
---|
12 | * |
---|
13 | * This program is distributed in the hope that it will be useful, |
---|
14 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
---|
15 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
---|
16 | * GNU General Public License for more details. |
---|
17 | * |
---|
18 | * You should have received a copy of the GNU General Public License |
---|
19 | * along with this program; if not, write to the Free Software |
---|
20 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. |
---|
21 | * |
---|
22 | * Author: |
---|
23 | * Fabian 'x3n' Landau |
---|
24 | * Co-authors: |
---|
25 | * ... |
---|
26 | * |
---|
27 | */ |
---|
28 | |
---|
29 | #ifndef _Gametype_H__ |
---|
30 | #define _Gametype_H__ |
---|
31 | |
---|
32 | #include "OrxonoxPrereqs.h" |
---|
33 | |
---|
34 | #include <map> |
---|
35 | #include <set> |
---|
36 | #include <string> |
---|
37 | |
---|
38 | #include "core/BaseObject.h" |
---|
39 | #include "core/class/SubclassIdentifier.h" |
---|
40 | #include "tools/interfaces/Tickable.h" |
---|
41 | #include "infos/GametypeInfo.h" |
---|
42 | |
---|
43 | namespace orxonox |
---|
44 | { |
---|
45 | namespace PlayerState |
---|
46 | { |
---|
47 | enum Value |
---|
48 | { |
---|
49 | Uninitialized, |
---|
50 | Joined, |
---|
51 | Alive, |
---|
52 | Dead |
---|
53 | }; |
---|
54 | } |
---|
55 | |
---|
56 | struct Player |
---|
57 | { |
---|
58 | PlayerInfo* info_; |
---|
59 | PlayerState::Value state_; |
---|
60 | int frags_; |
---|
61 | int killed_; |
---|
62 | }; |
---|
63 | |
---|
64 | class _OrxonoxExport Gametype : public BaseObject, public Tickable |
---|
65 | { |
---|
66 | friend class PlayerInfo; |
---|
67 | |
---|
68 | public: |
---|
69 | Gametype(Context* context); |
---|
70 | virtual ~Gametype(); |
---|
71 | |
---|
72 | void setConfigValues(); |
---|
73 | |
---|
74 | virtual void tick(float dt); |
---|
75 | |
---|
76 | inline const GametypeInfo* getGametypeInfo() const |
---|
77 | { return this->gtinfo_; } |
---|
78 | |
---|
79 | inline bool hasStarted() const |
---|
80 | { return this->gtinfo_->hasStarted(); } |
---|
81 | inline bool hasEnded() const |
---|
82 | { return this->gtinfo_->hasEnded(); } |
---|
83 | |
---|
84 | virtual void start(); |
---|
85 | virtual void end(); |
---|
86 | virtual void playerEntered(PlayerInfo* player); |
---|
87 | virtual bool playerLeft(PlayerInfo* player); |
---|
88 | virtual void playerSwitched(PlayerInfo* player, Gametype* newgametype); |
---|
89 | virtual void playerSwitchedBack(PlayerInfo* player, Gametype* oldgametype); |
---|
90 | virtual bool playerChangedName(PlayerInfo* player); |
---|
91 | |
---|
92 | virtual void playerScored(PlayerInfo* player, int score = 1); |
---|
93 | |
---|
94 | virtual bool allowPawnHit(Pawn* victim, Pawn* originator = 0); |
---|
95 | virtual bool allowPawnDamage(Pawn* victim, Pawn* originator = 0); |
---|
96 | virtual bool allowPawnDeath(Pawn* victim, Pawn* originator = 0); |
---|
97 | |
---|
98 | virtual void pawnKilled(Pawn* victim, Pawn* killer = 0); |
---|
99 | virtual void pawnPreSpawn(Pawn* pawn); |
---|
100 | virtual void pawnPostSpawn(Pawn* pawn); |
---|
101 | virtual void playerPreSpawn(PlayerInfo* player); |
---|
102 | virtual void playerPostSpawn(PlayerInfo* player); |
---|
103 | |
---|
104 | virtual void playerStartsControllingPawn(PlayerInfo* player, Pawn* pawn); |
---|
105 | virtual void playerStopsControllingPawn(PlayerInfo* player, Pawn* pawn); |
---|
106 | |
---|
107 | inline const std::map<PlayerInfo*, Player>& getPlayers() const |
---|
108 | { return this->players_; } |
---|
109 | |
---|
110 | int getScore(PlayerInfo* player) const; |
---|
111 | |
---|
112 | inline void registerSpawnPoint(SpawnPoint* spawnpoint) |
---|
113 | { this->spawnpoints_.insert(spawnpoint); } |
---|
114 | |
---|
115 | inline bool isStartCountdownRunning() const |
---|
116 | { return this->gtinfo_->isStartCountdownRunning(); } |
---|
117 | inline float getStartCountdown() const |
---|
118 | { return this->gtinfo_->getStartCountdown(); } |
---|
119 | |
---|
120 | inline void setHUDTemplate(const std::string& name) |
---|
121 | { this->gtinfo_->setHUDTemplate(name); } |
---|
122 | inline const std::string& getHUDTemplate() const |
---|
123 | { return this->gtinfo_->getHUDTemplate(); } |
---|
124 | |
---|
125 | virtual void addBots(unsigned int amount); |
---|
126 | void killBots(unsigned int amount = 0); |
---|
127 | |
---|
128 | virtual void addTime(float t); |
---|
129 | virtual void removeTime(float t); |
---|
130 | |
---|
131 | inline void startTimer() |
---|
132 | { |
---|
133 | this->time_ = this->timeLimit_; |
---|
134 | this->timerIsActive_ = true; |
---|
135 | } |
---|
136 | |
---|
137 | inline void stopTimer() |
---|
138 | { this->timerIsActive_ = false; } |
---|
139 | |
---|
140 | inline float getTime() |
---|
141 | { return this->time_; } |
---|
142 | |
---|
143 | inline bool getTimerIsActive() |
---|
144 | { return timerIsActive_; } |
---|
145 | |
---|
146 | inline void setTimeLimit(float t) |
---|
147 | { this->timeLimit_ = t; } |
---|
148 | |
---|
149 | //inline bool getForceSpawn() |
---|
150 | // { return this->bForceSpawn_; } |
---|
151 | |
---|
152 | virtual void resetTimer(); |
---|
153 | virtual void resetTimer(float t); |
---|
154 | |
---|
155 | /** |
---|
156 | @brief Get number of Players in game. |
---|
157 | */ |
---|
158 | inline unsigned int getNumberOfPlayers() const |
---|
159 | { return this->players_.size(); } |
---|
160 | |
---|
161 | |
---|
162 | |
---|
163 | protected: |
---|
164 | virtual SpawnPoint* getBestSpawnPoint(PlayerInfo* player) const; |
---|
165 | |
---|
166 | virtual void assignDefaultPawnsIfNeeded(); |
---|
167 | virtual void checkStart(); |
---|
168 | virtual void spawnPlayer(PlayerInfo* player); |
---|
169 | virtual void spawnPlayerAsDefaultPawn(PlayerInfo* player); |
---|
170 | virtual void spawnPlayersIfRequested(); |
---|
171 | virtual void spawnDeadPlayersIfRequested(); |
---|
172 | |
---|
173 | SmartPtr<GametypeInfo> gtinfo_; |
---|
174 | |
---|
175 | bool bAutoStart_; |
---|
176 | bool bForceSpawn_; |
---|
177 | |
---|
178 | float time_; |
---|
179 | float timeLimit_; |
---|
180 | bool timerIsActive_; |
---|
181 | |
---|
182 | float initialStartCountdown_; |
---|
183 | unsigned int numberOfBots_; |
---|
184 | SubclassIdentifier<Bot> botclass_; |
---|
185 | |
---|
186 | std::map<PlayerInfo*, Player> players_; |
---|
187 | std::set<SpawnPoint*> spawnpoints_; |
---|
188 | SubclassIdentifier<ControllableEntity> defaultControllableEntity_; |
---|
189 | |
---|
190 | OverlayGroup* scoreboard_; |
---|
191 | |
---|
192 | // Config Values |
---|
193 | std::string scoreboardTemplate_; |
---|
194 | |
---|
195 | /* HACK HACK HACK */ |
---|
196 | ConsoleCommand* dedicatedAddBots_; |
---|
197 | ConsoleCommand* dedicatedKillBots_; |
---|
198 | /* HACK HACK HACK */ |
---|
199 | |
---|
200 | }; |
---|
201 | } |
---|
202 | |
---|
203 | #endif /* _Gametype_H__ */ |
---|