Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: code/branches/SpaceRace_HS16/src/modules/gametypes/SpaceRace.cc @ 11281

Last change on this file since 11281 was 11281, checked in by bberabi, 7 years ago

bots addiert checkpoint problem gelost

  • Property svn:eol-style set to native
File size: 6.6 KB
Line 
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
55namespace 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
82   if (true)
83        {
84            this->spawnPlayersIfRequested();
85            this->cantMove_ = true;
86
87            for (Engine* engine : ObjectList<Engine>()){
88                engine->setActive(false);
89               
90
91            }
92           
93        }
94
95
96
97        std::string message("BE FAST BE FIRST");
98        this->getGametypeInfo()->sendAnnounceMessage(message);
99        ChatManager::message(message);
100
101Timer* countdownTimer = new Timer();
102        countdownTimer->setTimer(11, false, createExecutor(createFunctor(&SpaceRace::countdownFinished, this)));
103    }
104
105
106
107
108    void SpaceRace::end()
109    {
110        this->clock_.capture();
111        int s = this->clock_.getSeconds();
112        int ms = static_cast<int>(this->clock_.getMilliseconds() - 1000*s);
113        std::string message;
114
115        if (this->bTimeIsUp_)
116        {
117            message = multi_cast<std::string>(s) + "." + multi_cast<std::string>(ms) + " seconds !!\n"
118                        + "You didn't reach the check point  before the time limit. You lose!";
119        }
120        else
121        {
122            message = "You win!! Final check point reached after "+ multi_cast<std::string>(s)
123                        + "." + multi_cast<std::string>(ms) + " seconds.";
124        }
125        if (!this->hasEnded())
126        {
127            this->getGametypeInfo()->sendAnnounceMessage(message);
128            ChatManager::message(message);
129        }
130        this->Gametype::end();
131    }
132
133
134void SpaceRace::tick(float dt)
135    {
136        SUPER(SpaceRace,tick,dt);
137
138
139
140        // spawns the players when the countdown starts, but deactivates their engines
141        if (this->isStartCountdownRunning() && !this->cantMove_)
142        {
143            this->spawnPlayersIfRequested();
144            this->cantMove_ = true;
145
146            for (Engine* engine : ObjectList<Engine>())
147                engine->setActive(false);
148        }
149
150
151gtInfo_->setStartCountdown(10.0);
152   
153       
154            /*this->spawnPlayersIfRequested();
155            this->cantMove_ = true;
156
157            for (Engine* engine : ObjectList<Engine>()){
158                engine->setActive(false);
159                }
160
161           
162           
163         std::string message("BE FAST BE FIRST");
164        this->getGametypeInfo()->sendAnnounceMessage(message);
165        ChatManager::message(message);
166
167Timer* countdownTimer = new Timer();
168        countdownTimer->setTimer(11, false, createExecutor(createFunctor(&SpaceRace::countdownFinished, this)));*/
169
170
171
172
173
174
175
176        // activate the engines when the countdown ends
177        if (!this->isStartCountdownRunning() && this->cantMove_)
178        {
179            for (Engine* engine : ObjectList<Engine>())
180                engine->setActive(true);
181
182            this->cantMove_= false;
183
184
185
186            std::string message = "RACE STARTED!";
187            this->getGametypeInfo()->sendAnnounceMessage(message);
188            ChatManager::message(message);
189        }
190   
191}
192
193    void SpaceRace::newCheckpointReached(RaceCheckPoint* checkpoint, PlayerInfo* player)
194    {
195        this->checkpointReached_[player] = checkpoint;
196
197        this->clock_.capture();
198        int s = this->clock_.getSeconds();
199        int ms = this->clock_.getMilliseconds() % 1000;
200
201        const std::string& message = "Checkpoint " + multi_cast<std::string>(checkpoint->getCheckpointIndex() + 1)
202            + " reached after " + multi_cast<std::string>(s) + "." + multi_cast<std::string>(ms) + " seconds.";
203        this->getGametypeInfo()->sendAnnounceMessage(message);
204        ChatManager::message(message);
205    }
206
207 void SpaceRace::countdownFinished()
208    {
209
210        std::string message("RACE STARTED ");
211        this->getGametypeInfo()->sendAnnounceMessage(message);
212        ChatManager::message(message);
213
214
215    for (Engine* engine : ObjectList<Engine>())
216                engine->setActive(true);
217   
218}
219
220 void SpaceRace::playerEntered(PlayerInfo* player)
221    {
222        Gametype::playerEntered(player);
223
224        const std::string& message = player->getName() + " entered the game";
225        ChatManager::message(message);
226    }
227
228
229 void SpaceRace::addBots(unsigned int amount)
230    {
231        for (unsigned int i = 0; i < amount; ++i)
232            this->botclass_.fabricate(this->getContext());
233    }
234
235
236
237
238
239
240
241    bool SpaceRace::allowPawnHit(Pawn* victim, Pawn* originator)
242    {
243        return true;
244    }
245
246    bool SpaceRace::allowPawnDamage(Pawn* victim, Pawn* originator)
247    {
248        return true;
249    }
250
251    bool SpaceRace::allowPawnDeath(Pawn* victim, Pawn* originator)
252    {
253        return true;
254    }
255}
Note: See TracBrowser for help on using the repository browser.