Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

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

Last change on this file since 11334 was 11334, checked in by meilel, 7 years ago

final changes

  • 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        Berkay Berabi
27        Louis Meile
28 *
29 */
30
31/*
32Todo:
33- improve AI (SpaceRaceController):
34i) so far bots arent able to evade obstacles. fix that!
35ii) bots should be able to use pickups
36- game crashes when bot wins the game
37- bots rotate while waiting for the countdown to end. make it stop!
38- add elements to level file to make it even more fun to play. be creative!
39*/
40
41
42#include "SpaceRace.h"
43
44#include "core/CoreIncludes.h"
45#include "chat/ChatManager.h"
46#include "util/Convert.h"
47#include "util/Math.h"
48#include "infos/Bot.h"
49#include "items/Engine.h"
50#include "controllers/HumanController.h"
51
52#include "core/CoreIncludes.h"
53#include "chat/ChatManager.h"
54#include "infos/PlayerInfo.h"
55#include "worldentities/pawns/Pawn.h"
56#include "core/config/ConfigValueIncludes.h"
57#include "infos/Bot.h"
58#include "SpaceRaceBot.h"
59#include "items/Engine.h"
60
61#include "core/CoreIncludes.h"
62#include "chat/ChatManager.h"
63#include "util/Convert.h"
64#include "util/Math.h"
65#include "SpaceRaceBot.h"
66#include "items/Engine.h"
67#include <vector>
68
69
70namespace orxonox
71{
72    RegisterUnloadableClass(SpaceRace);
73
74    SpaceRace::SpaceRace(Context* context) : Gametype(context)
75    {
76        RegisterObject(SpaceRace);
77
78        this->botclass_ = Class(SpaceRaceBot); //ClassByString("")
79        this->cantMove_ = false;
80        this->bTimeIsUp_ = false;
81        this->setConfigValues();
82
83        this->numberOfBots_ = 5; // quick fix: don't allow default-bots to enter the race
84    }
85
86  void SpaceRace::setConfigValues()
87    {
88       
89   
90    }
91
92    // define spawn positions of the 5 bots
93    void SpaceRace::start()
94    {
95
96        int startpos[15];
97       
98        startpos[0] =100;
99        startpos[1] =-40;
100        startpos[2] =0;
101       
102        startpos[3] =100;
103        startpos[4] =-40;
104        startpos[5] =100;
105       
106        startpos[6] =100;
107        startpos[7] =-40;
108        startpos[8] =-100;
109       
110        startpos[9] =0;
111        startpos[10] =-40;
112        startpos[11] =-80;
113       
114        startpos[12] =0;
115        startpos[13] =-40;
116        startpos[14] =80;
117       
118
119
120
121        Gametype::start();
122   if (true)
123        {
124            this->spawnPlayersIfRequested();
125            this->cantMove_ = true;
126            //bots unable to move while countdown is running
127            for (Engine* engine : ObjectList<Engine>()){
128                engine->setActive(false);
129               
130
131            }
132           //append spawn positions to bots
133           int a,b,c;
134            a=0;
135            b=1;
136            c=2;
137              for (SpaceRaceBot* bot : ObjectList<SpaceRaceBot>()){
138                bot->getControllableEntity()->setPosition(startpos[a],startpos[b],startpos[c]);
139               a= a+3;
140               b = b+3; 
141               c+= 3;
142            }
143
144
145        }
146
147                                               
148
149        std::string message("Use headphones to hear the countdown!");
150        this->getGametypeInfo()->sendAnnounceMessage(message);
151        ChatManager::message(message);
152
153//after 11 s, countdownFinished is called to activate bots` engines
154Timer* countdownTimer = new Timer();
155        countdownTimer->setTimer(11, false, createExecutor(createFunctor(&SpaceRace::countdownFinished, this)));
156    }
157
158
159
160
161    void SpaceRace::end()
162    {
163        this->clock_.capture();
164        int s = this->clock_.getSeconds();
165        int ms = static_cast<int>(this->clock_.getMilliseconds() - 1000*s);
166        std::string message;
167
168        if (this->bTimeIsUp_)
169        {
170            message = multi_cast<std::string>(s) + "." + multi_cast<std::string>(ms) + " seconds !!\n"
171                        + "You lose!";
172        }
173        else
174        {
175            message = "You win!! Final check point reached after "+ multi_cast<std::string>(s)
176                        + "." + multi_cast<std::string>(ms) + " seconds.";
177        }
178        if (!this->hasEnded())
179        {
180            this->getGametypeInfo()->sendAnnounceMessage(message);
181            ChatManager::message(message);
182        }
183        this->Gametype::end();
184    }
185
186
187void SpaceRace::tick(float dt)
188    {
189        SUPER(SpaceRace,tick,dt);
190}
191
192    void SpaceRace::newCheckpointReached(RaceCheckPoint* checkpoint, PlayerInfo* player)
193    {
194        this->checkpointReached_[player] = checkpoint;
195
196        this->clock_.capture();
197        int s = this->clock_.getSeconds();
198        int ms = this->clock_.getMilliseconds() % 1000;
199
200       
201   
202        const std::string& message = player->getName() + " reached the checkpoint " + multi_cast<std::string>(checkpoint->getCheckpointIndex() + 1) 
203        + "after " + multi_cast<std::string>(s) + "." + multi_cast<std::string>(ms) + " seconds.";
204 this->getGametypeInfo()->sendAnnounceMessage(message);
205        ChatManager::message(message);
206
207    }
208
209 void SpaceRace::countdownFinished()
210    {
211
212        std::string message("RACE STARTED ");
213        this->getGametypeInfo()->sendAnnounceMessage(message);
214        ChatManager::message(message);
215
216
217    for (Engine* engine : ObjectList<Engine>())
218                engine->setActive(true);
219
220
221   
222}
223
224 void SpaceRace::playerEntered(PlayerInfo* player)
225    {
226        Gametype::playerEntered(player);
227
228        const std::string& message = player->getName() + " entered the game";
229        ChatManager::message(message);
230    }
231
232
233 void SpaceRace::addBots(unsigned int amount)
234    {
235        for (unsigned int i = 1; i <= amount; ++i){
236            this->botclass_.fabricate(this->getContext());
237        }
238    }
239
240
241//set bot configurations
242    bool SpaceRace::allowPawnHit(Pawn* victim, Pawn* originator)
243    {
244        return true;
245    }
246
247    bool SpaceRace::allowPawnDamage(Pawn* victim, Pawn* originator)
248    {
249        return true;
250    }
251
252    bool SpaceRace::allowPawnDeath(Pawn* victim, Pawn* originator)
253    {
254        return false;
255    }
256}
Note: See TracBrowser for help on using the repository browser.