Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

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

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

we found how to set starpositions

  • Property svn:eol-style set to native
File size: 7.2 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#include <vector>
55
56
57namespace 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
107        Gametype::start();
108   if (true)
109        {
110            this->spawnPlayersIfRequested();
111            this->cantMove_ = true;
112
113            for (Engine* engine : ObjectList<Engine>()){
114                engine->setActive(false);
115               
116
117            }
118           
119           int a,b,c;
120            a=0;
121            b=1;
122            c=2;
123              for (SpaceRaceBot* bot : ObjectList<SpaceRaceBot>()){
124                bot->getControllableEntity()->setPosition(spawnpositions.at(a),spawnpositions.at(b),spawnpositions.at(c));
125               a= a+3;
126               b = b+3; 
127               c+= 3;
128            }
129
130
131        }
132
133
134               
135        std::string message("BE FAST BE FIRST");
136        this->getGametypeInfo()->sendAnnounceMessage(message);
137        ChatManager::message(message);
138
139Timer* countdownTimer = new Timer();
140        countdownTimer->setTimer(11, false, createExecutor(createFunctor(&SpaceRace::countdownFinished, this)));
141    }
142
143
144
145
146    void SpaceRace::end()
147    {
148        this->clock_.capture();
149        int s = this->clock_.getSeconds();
150        int ms = static_cast<int>(this->clock_.getMilliseconds() - 1000*s);
151        std::string message;
152
153        if (this->bTimeIsUp_)
154        {
155            message = multi_cast<std::string>(s) + "." + multi_cast<std::string>(ms) + " seconds !!\n"
156                        + "You didn't reach the check point  before the time limit. You lose!";
157        }
158        else
159        {
160            message = "You win!! Final check point reached after "+ multi_cast<std::string>(s)
161                        + "." + multi_cast<std::string>(ms) + " seconds.";
162        }
163        if (!this->hasEnded())
164        {
165            this->getGametypeInfo()->sendAnnounceMessage(message);
166            ChatManager::message(message);
167        }
168        this->Gametype::end();
169    }
170
171
172void SpaceRace::tick(float dt)
173    {
174        SUPER(SpaceRace,tick,dt);
175
176
177
178        // spawns the players when the countdown starts, but deactivates their engines
179       /* if (this->isStartCountdownRunning() && !this->cantMove_)
180        {
181            this->spawnPlayersIfRequested();
182            this->cantMove_ = true;
183
184            for (Engine* engine : ObjectList<Engine>())
185                engine->setActive(false);
186        }*/
187
188
189//gtinfo_->setStartCountdown(50.0);
190   
191       
192
193
194
195
196
197
198
199        // activate the engines when the countdown ends
200      /*  if (!this->isStartCountdownRunning() && this->cantMove_)
201        {
202            for (Engine* engine : ObjectList<Engine>())
203                engine->setActive(true);
204
205            this->cantMove_= false;
206
207
208
209            std::string message = "RACE STARTED!";
210            this->getGametypeInfo()->sendAnnounceMessage(message);
211            ChatManager::message(message);
212        }*/
213   
214}
215
216    void SpaceRace::newCheckpointReached(RaceCheckPoint* checkpoint, PlayerInfo* player)
217    {
218        this->checkpointReached_[player] = checkpoint;
219
220        this->clock_.capture();
221        int s = this->clock_.getSeconds();
222        int ms = this->clock_.getMilliseconds() % 1000;
223
224       
225   
226        const std::string& message = player->getName() + " reached the checkpoint " + multi_cast<std::string>(checkpoint->getCheckpointIndex() + 1) 
227        + "after " + multi_cast<std::string>(s) + "." + multi_cast<std::string>(ms) + " seconds.";
228 this->getGametypeInfo()->sendAnnounceMessage(message);
229        ChatManager::message(message);
230
231    }
232
233 void SpaceRace::countdownFinished()
234    {
235
236        std::string message("RACE STARTED ");
237        this->getGametypeInfo()->sendAnnounceMessage(message);
238        ChatManager::message(message);
239
240
241    for (Engine* engine : ObjectList<Engine>())
242                engine->setActive(true);
243
244
245   
246}
247
248 void SpaceRace::playerEntered(PlayerInfo* player)
249    {
250        Gametype::playerEntered(player);
251
252        const std::string& message = player->getName() + " entered the game";
253        ChatManager::message(message);
254    }
255
256
257 void SpaceRace::addBots(unsigned int amount)
258    {
259        for (unsigned int i = 1; i <= amount; ++i){
260            this->botclass_.fabricate(this->getContext());
261            //SpaceRaceBot* bot = new SpaceRaceBot(this->getContext());
262            //bot->setPosition(-i*150,0,-i*100);
263        }
264
265
266
267
268    }
269
270
271
272
273
274
275    bool SpaceRace::allowPawnHit(Pawn* victim, Pawn* originator)
276    {
277        return true;
278    }
279
280    bool SpaceRace::allowPawnDamage(Pawn* victim, Pawn* originator)
281    {
282        return true;
283    }
284
285    bool SpaceRace::allowPawnDeath(Pawn* victim, Pawn* originator)
286    {
287        return true;
288    }
289}
Note: See TracBrowser for help on using the repository browser.