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 | |
---|
55 | namespace orxonox |
---|
56 | { |
---|
57 | RegisterUnloadableClass(SpaceRace); |
---|
58 | |
---|
59 | SpaceRace::SpaceRace(Context* context) : Gametype(context) |
---|
60 | { |
---|
61 | RegisterObject(SpaceRace); |
---|
62 | |
---|
63 | this->botclass_ = Class(SpaceRaceBot);//ClassByString("") |
---|
64 | this->cantMove_ = false; |
---|
65 | this->bTimeIsUp_ = false; |
---|
66 | this->setConfigValues(); |
---|
67 | |
---|
68 | // this->numberOfBots_ = 1; // quick fix: don't allow default-bots to enter the race |
---|
69 | // remove this line, if a raceBot has been created. |
---|
70 | } |
---|
71 | |
---|
72 | void SpaceRace::setConfigValues() |
---|
73 | { |
---|
74 | |
---|
75 | |
---|
76 | } |
---|
77 | |
---|
78 | void SpaceRace::start() |
---|
79 | { |
---|
80 | Gametype::start(); |
---|
81 | if (true) |
---|
82 | { |
---|
83 | this->spawnPlayersIfRequested(); |
---|
84 | this->cantMove_ = true; |
---|
85 | |
---|
86 | for (Engine* engine : ObjectList<Engine>()){ |
---|
87 | engine->setActive(false); |
---|
88 | |
---|
89 | |
---|
90 | } |
---|
91 | |
---|
92 | } |
---|
93 | |
---|
94 | |
---|
95 | |
---|
96 | std::string message("BE FAST BE FIRST"); |
---|
97 | this->getGametypeInfo()->sendAnnounceMessage(message); |
---|
98 | ChatManager::message(message); |
---|
99 | |
---|
100 | Timer* countdownTimer = new Timer(); |
---|
101 | countdownTimer->setTimer(11, false, createExecutor(createFunctor(&SpaceRace::countdownFinished, this))); |
---|
102 | } |
---|
103 | |
---|
104 | |
---|
105 | |
---|
106 | |
---|
107 | void SpaceRace::end() |
---|
108 | { |
---|
109 | this->clock_.capture(); |
---|
110 | int s = this->clock_.getSeconds(); |
---|
111 | int ms = static_cast<int>(this->clock_.getMilliseconds() - 1000*s); |
---|
112 | std::string message; |
---|
113 | |
---|
114 | if (this->bTimeIsUp_) |
---|
115 | { |
---|
116 | message = multi_cast<std::string>(s) + "." + multi_cast<std::string>(ms) + " seconds !!\n" |
---|
117 | + "You didn't reach the check point before the time limit. You lose!"; |
---|
118 | } |
---|
119 | else |
---|
120 | { |
---|
121 | message = "You win!! Final check point reached after "+ multi_cast<std::string>(s) |
---|
122 | + "." + multi_cast<std::string>(ms) + " seconds."; |
---|
123 | } |
---|
124 | if (!this->hasEnded()) |
---|
125 | { |
---|
126 | this->getGametypeInfo()->sendAnnounceMessage(message); |
---|
127 | ChatManager::message(message); |
---|
128 | } |
---|
129 | this->Gametype::end(); |
---|
130 | } |
---|
131 | |
---|
132 | |
---|
133 | void SpaceRace::tick(float dt) |
---|
134 | { |
---|
135 | SUPER(SpaceRace,tick,dt); |
---|
136 | |
---|
137 | |
---|
138 | |
---|
139 | /* // spawns the players when the countdown starts, but deactivates their engines |
---|
140 | if (this->isStartCountdownRunning() && !this->cantMove_) |
---|
141 | { |
---|
142 | this->spawnPlayersIfRequested(); |
---|
143 | this->cantMove_ = true; |
---|
144 | |
---|
145 | for (Engine* engine : ObjectList<Engine>()) |
---|
146 | engine->setActive(false); |
---|
147 | } |
---|
148 | |
---|
149 | |
---|
150 | gtinfo_->setStartCountdown(50.0); |
---|
151 | |
---|
152 | |
---|
153 | |
---|
154 | |
---|
155 | |
---|
156 | |
---|
157 | |
---|
158 | |
---|
159 | |
---|
160 | // activate the engines when the countdown ends |
---|
161 | if (!this->isStartCountdownRunning() && this->cantMove_) |
---|
162 | { |
---|
163 | for (Engine* engine : ObjectList<Engine>()) |
---|
164 | engine->setActive(true); |
---|
165 | |
---|
166 | this->cantMove_= false; |
---|
167 | |
---|
168 | |
---|
169 | |
---|
170 | std::string message = "RACE STARTED!"; |
---|
171 | this->getGametypeInfo()->sendAnnounceMessage(message); |
---|
172 | ChatManager::message(message); |
---|
173 | }*/ |
---|
174 | |
---|
175 | } |
---|
176 | |
---|
177 | void SpaceRace::newCheckpointReached(RaceCheckPoint* checkpoint, PlayerInfo* player) |
---|
178 | { |
---|
179 | this->checkpointReached_[player] = checkpoint; |
---|
180 | |
---|
181 | this->clock_.capture(); |
---|
182 | int s = this->clock_.getSeconds(); |
---|
183 | int ms = this->clock_.getMilliseconds() % 1000; |
---|
184 | |
---|
185 | |
---|
186 | |
---|
187 | const std::string& message = player->getName() + " reached the checkpoint " + multi_cast<std::string>(checkpoint->getCheckpointIndex() + 1) |
---|
188 | + "after " + multi_cast<std::string>(s) + "." + multi_cast<std::string>(ms) + " seconds."; |
---|
189 | this->getGametypeInfo()->sendAnnounceMessage(message); |
---|
190 | ChatManager::message(message); |
---|
191 | |
---|
192 | } |
---|
193 | |
---|
194 | void SpaceRace::countdownFinished() |
---|
195 | { |
---|
196 | |
---|
197 | std::string message("RACE STARTED "); |
---|
198 | this->getGametypeInfo()->sendAnnounceMessage(message); |
---|
199 | ChatManager::message(message); |
---|
200 | |
---|
201 | |
---|
202 | for (Engine* engine : ObjectList<Engine>()) |
---|
203 | engine->setActive(true); |
---|
204 | |
---|
205 | |
---|
206 | |
---|
207 | } |
---|
208 | |
---|
209 | void SpaceRace::playerEntered(PlayerInfo* player) |
---|
210 | { |
---|
211 | Gametype::playerEntered(player); |
---|
212 | |
---|
213 | const std::string& message = player->getName() + " entered the game"; |
---|
214 | ChatManager::message(message); |
---|
215 | } |
---|
216 | |
---|
217 | |
---|
218 | void SpaceRace::addBots(unsigned int amount) |
---|
219 | { |
---|
220 | for (unsigned int i = 0; i < amount; ++i) |
---|
221 | this->botclass_.fabricate(this->getContext()); |
---|
222 | |
---|
223 | |
---|
224 | |
---|
225 | |
---|
226 | } |
---|
227 | |
---|
228 | |
---|
229 | |
---|
230 | |
---|
231 | |
---|
232 | |
---|
233 | bool SpaceRace::allowPawnHit(Pawn* victim, Pawn* originator) |
---|
234 | { |
---|
235 | return true; |
---|
236 | } |
---|
237 | |
---|
238 | bool SpaceRace::allowPawnDamage(Pawn* victim, Pawn* originator) |
---|
239 | { |
---|
240 | return true; |
---|
241 | } |
---|
242 | |
---|
243 | bool SpaceRace::allowPawnDeath(Pawn* victim, Pawn* originator) |
---|
244 | { |
---|
245 | return true; |
---|
246 | } |
---|
247 | } |
---|