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 | * Mauro Salomon |
---|
24 | * Co-authors: |
---|
25 | * Celine Egger |
---|
26 | * |
---|
27 | */ |
---|
28 | |
---|
29 | #include "SpaceRace.h" |
---|
30 | |
---|
31 | #include "core/CoreIncludes.h" |
---|
32 | #include "chat/ChatManager.h" |
---|
33 | #include "util/Convert.h" |
---|
34 | #include "util/Math.h" |
---|
35 | #include "infos/Bot.h" |
---|
36 | #include "items/Engine.h" |
---|
37 | #include "controllers/HumanController.h" |
---|
38 | |
---|
39 | #include "core/CoreIncludes.h" |
---|
40 | #include "chat/ChatManager.h" |
---|
41 | #include "infos/PlayerInfo.h" |
---|
42 | #include "worldentities/pawns/Pawn.h" |
---|
43 | #include "core/config/ConfigValueIncludes.h" |
---|
44 | #include "infos/Bot.h" |
---|
45 | #include "SpaceRaceBot.h" |
---|
46 | #include "items/Engine.h" |
---|
47 | |
---|
48 | #include "core/CoreIncludes.h" |
---|
49 | #include "chat/ChatManager.h" |
---|
50 | #include "util/Convert.h" |
---|
51 | #include "util/Math.h" |
---|
52 | #include "SpaceRaceBot.h" |
---|
53 | #include "items/Engine.h" |
---|
54 | #include <vector> |
---|
55 | |
---|
56 | |
---|
57 | namespace orxonox |
---|
58 | { |
---|
59 | RegisterUnloadableClass(SpaceRace); |
---|
60 | |
---|
61 | SpaceRace::SpaceRace(Context* context) : Gametype(context) |
---|
62 | { |
---|
63 | RegisterObject(SpaceRace); |
---|
64 | |
---|
65 | this->botclass_ = Class(SpaceRaceBot);//ClassByString("") |
---|
66 | this->cantMove_ = false; |
---|
67 | this->bTimeIsUp_ = false; |
---|
68 | this->setConfigValues(); |
---|
69 | |
---|
70 | // this->numberOfBots_ = 1; // quick fix: don't allow default-bots to enter the race |
---|
71 | // remove this line, if a raceBot has been created. |
---|
72 | } |
---|
73 | |
---|
74 | void SpaceRace::setConfigValues() |
---|
75 | { |
---|
76 | |
---|
77 | |
---|
78 | } |
---|
79 | |
---|
80 | void SpaceRace::start() |
---|
81 | { |
---|
82 | |
---|
83 | |
---|
84 | /* std::vector<int> spawnpositions; |
---|
85 | |
---|
86 | spawnpositions.push_back(200); |
---|
87 | spawnpositions.push_back(0); |
---|
88 | spawnpositions.push_back(100); |
---|
89 | |
---|
90 | spawnpositions.push_back(200); |
---|
91 | spawnpositions.push_back(200); |
---|
92 | spawnpositions.push_back(0); |
---|
93 | |
---|
94 | spawnpositions.push_back(200); |
---|
95 | spawnpositions.push_back(0); |
---|
96 | spawnpositions.push_back(0); |
---|
97 | |
---|
98 | spawnpositions.push_back(100); |
---|
99 | spawnpositions.push_back(0); |
---|
100 | spawnpositions.push_back(0); |
---|
101 | |
---|
102 | spawnpositions.push_back(0); |
---|
103 | spawnpositions.push_back(100); |
---|
104 | spawnpositions.push_back(0); |
---|
105 | */ |
---|
106 | int startpos[15]; |
---|
107 | |
---|
108 | startpos[0] =100; |
---|
109 | startpos[1] =-40; |
---|
110 | startpos[2] =0; |
---|
111 | |
---|
112 | startpos[3] =100; |
---|
113 | startpos[4] =-40; |
---|
114 | startpos[5] =100; |
---|
115 | |
---|
116 | startpos[6] =100; |
---|
117 | startpos[7] =-40; |
---|
118 | startpos[8] =-100; |
---|
119 | |
---|
120 | startpos[9] =0; |
---|
121 | startpos[10] =-40; |
---|
122 | startpos[11] =-80; |
---|
123 | |
---|
124 | startpos[12] =0; |
---|
125 | startpos[13] =-40; |
---|
126 | startpos[14] =80; |
---|
127 | |
---|
128 | /*startpos[15] = |
---|
129 | startpos[0] = |
---|
130 | startpos[0] = |
---|
131 | startpos[0] = |
---|
132 | startpos[0] = |
---|
133 | startpos[0] =*/ |
---|
134 | |
---|
135 | |
---|
136 | |
---|
137 | Gametype::start(); |
---|
138 | if (true) |
---|
139 | { |
---|
140 | this->spawnPlayersIfRequested(); |
---|
141 | this->cantMove_ = true; |
---|
142 | |
---|
143 | for (Engine* engine : ObjectList<Engine>()){ |
---|
144 | engine->setActive(false); |
---|
145 | |
---|
146 | |
---|
147 | } |
---|
148 | |
---|
149 | int a,b,c; |
---|
150 | a=0; |
---|
151 | b=1; |
---|
152 | c=2; |
---|
153 | for (SpaceRaceBot* bot : ObjectList<SpaceRaceBot>()){ |
---|
154 | bot->getControllableEntity()->setPosition(startpos[a],startpos[b],startpos[c]); |
---|
155 | a= a+3; |
---|
156 | b = b+3; |
---|
157 | c+= 3; |
---|
158 | } |
---|
159 | |
---|
160 | |
---|
161 | } |
---|
162 | |
---|
163 | |
---|
164 | |
---|
165 | std::string message("BE FAST BE FIRST"); |
---|
166 | this->getGametypeInfo()->sendAnnounceMessage(message); |
---|
167 | ChatManager::message(message); |
---|
168 | |
---|
169 | Timer* countdownTimer = new Timer(); |
---|
170 | countdownTimer->setTimer(11, false, createExecutor(createFunctor(&SpaceRace::countdownFinished, this))); |
---|
171 | } |
---|
172 | |
---|
173 | |
---|
174 | |
---|
175 | |
---|
176 | void SpaceRace::end() |
---|
177 | { |
---|
178 | this->clock_.capture(); |
---|
179 | int s = this->clock_.getSeconds(); |
---|
180 | int ms = static_cast<int>(this->clock_.getMilliseconds() - 1000*s); |
---|
181 | std::string message; |
---|
182 | |
---|
183 | if (this->bTimeIsUp_) |
---|
184 | { |
---|
185 | message = multi_cast<std::string>(s) + "." + multi_cast<std::string>(ms) + " seconds !!\n" |
---|
186 | + "You didn't reach the check point before the time limit. You lose!"; |
---|
187 | } |
---|
188 | else |
---|
189 | { |
---|
190 | message = "You win!! Final check point reached after "+ multi_cast<std::string>(s) |
---|
191 | + "." + multi_cast<std::string>(ms) + " seconds."; |
---|
192 | } |
---|
193 | if (!this->hasEnded()) |
---|
194 | { |
---|
195 | this->getGametypeInfo()->sendAnnounceMessage(message); |
---|
196 | ChatManager::message(message); |
---|
197 | } |
---|
198 | this->Gametype::end(); |
---|
199 | } |
---|
200 | |
---|
201 | |
---|
202 | void SpaceRace::tick(float dt) |
---|
203 | { |
---|
204 | SUPER(SpaceRace,tick,dt); |
---|
205 | |
---|
206 | |
---|
207 | |
---|
208 | // spawns the players when the countdown starts, but deactivates their engines |
---|
209 | /* if (this->isStartCountdownRunning() && !this->cantMove_) |
---|
210 | { |
---|
211 | this->spawnPlayersIfRequested(); |
---|
212 | this->cantMove_ = true; |
---|
213 | |
---|
214 | for (Engine* engine : ObjectList<Engine>()) |
---|
215 | engine->setActive(false); |
---|
216 | }*/ |
---|
217 | |
---|
218 | |
---|
219 | //gtinfo_->setStartCountdown(50.0); |
---|
220 | |
---|
221 | |
---|
222 | |
---|
223 | |
---|
224 | |
---|
225 | |
---|
226 | |
---|
227 | |
---|
228 | |
---|
229 | // activate the engines when the countdown ends |
---|
230 | /* if (!this->isStartCountdownRunning() && this->cantMove_) |
---|
231 | { |
---|
232 | for (Engine* engine : ObjectList<Engine>()) |
---|
233 | engine->setActive(true); |
---|
234 | |
---|
235 | this->cantMove_= false; |
---|
236 | |
---|
237 | |
---|
238 | |
---|
239 | std::string message = "RACE STARTED!"; |
---|
240 | this->getGametypeInfo()->sendAnnounceMessage(message); |
---|
241 | ChatManager::message(message); |
---|
242 | }*/ |
---|
243 | |
---|
244 | } |
---|
245 | |
---|
246 | void SpaceRace::newCheckpointReached(RaceCheckPoint* checkpoint, PlayerInfo* player) |
---|
247 | { |
---|
248 | this->checkpointReached_[player] = checkpoint; |
---|
249 | |
---|
250 | this->clock_.capture(); |
---|
251 | int s = this->clock_.getSeconds(); |
---|
252 | int ms = this->clock_.getMilliseconds() % 1000; |
---|
253 | |
---|
254 | |
---|
255 | |
---|
256 | const std::string& message = player->getName() + " reached the checkpoint " + multi_cast<std::string>(checkpoint->getCheckpointIndex() + 1) |
---|
257 | + "after " + multi_cast<std::string>(s) + "." + multi_cast<std::string>(ms) + " seconds."; |
---|
258 | this->getGametypeInfo()->sendAnnounceMessage(message); |
---|
259 | ChatManager::message(message); |
---|
260 | |
---|
261 | } |
---|
262 | |
---|
263 | void SpaceRace::countdownFinished() |
---|
264 | { |
---|
265 | |
---|
266 | std::string message("RACE STARTED "); |
---|
267 | this->getGametypeInfo()->sendAnnounceMessage(message); |
---|
268 | ChatManager::message(message); |
---|
269 | |
---|
270 | |
---|
271 | for (Engine* engine : ObjectList<Engine>()) |
---|
272 | engine->setActive(true); |
---|
273 | |
---|
274 | |
---|
275 | |
---|
276 | } |
---|
277 | |
---|
278 | void SpaceRace::playerEntered(PlayerInfo* player) |
---|
279 | { |
---|
280 | Gametype::playerEntered(player); |
---|
281 | |
---|
282 | const std::string& message = player->getName() + " entered the game"; |
---|
283 | ChatManager::message(message); |
---|
284 | } |
---|
285 | |
---|
286 | |
---|
287 | void SpaceRace::addBots(unsigned int amount) |
---|
288 | { |
---|
289 | for (unsigned int i = 1; i <= amount; ++i){ |
---|
290 | this->botclass_.fabricate(this->getContext()); |
---|
291 | //SpaceRaceBot* bot = new SpaceRaceBot(this->getContext()); |
---|
292 | //bot->setPosition(-i*150,0,-i*100); |
---|
293 | } |
---|
294 | |
---|
295 | |
---|
296 | |
---|
297 | |
---|
298 | } |
---|
299 | |
---|
300 | |
---|
301 | |
---|
302 | |
---|
303 | |
---|
304 | |
---|
305 | bool SpaceRace::allowPawnHit(Pawn* victim, Pawn* originator) |
---|
306 | { |
---|
307 | return true; |
---|
308 | } |
---|
309 | |
---|
310 | bool SpaceRace::allowPawnDamage(Pawn* victim, Pawn* originator) |
---|
311 | { |
---|
312 | return true; |
---|
313 | } |
---|
314 | |
---|
315 | bool SpaceRace::allowPawnDeath(Pawn* victim, Pawn* originator) |
---|
316 | { |
---|
317 | return false; |
---|
318 | } |
---|
319 | } |
---|