Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: code/branches/RacingBots_FS18/src/modules/gametypes/SpaceRace.cc @ 11938

Last change on this file since 11938 was 11938, checked in by arismu, 6 years ago

checkpoints, boost, AI

  • Property svn:eol-style set to native
File size: 7.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
30/*
31Edited, Renewed and Revised by
32        Berkay Berabi
33        Louis Meile
34 
35 
36To-do- list by Louis Meile and Berkay Berabi for future projects :
37- improve AI (SpaceRaceController):
38i) so far bots arent able to evade obstacles. fix that!
39ii) bots should be able to use pickups
40- game crashes when bot wins the game(this is a huge problem you should work with the log file to find out what the errors are )
41- bots rotate while waiting for the countdown to end. make it stop!
42- add elements to level file to make it even more fun to play. be creative!
43*/
44
45
46#include "SpaceRace.h"
47
48#include "core/CoreIncludes.h"
49#include "chat/ChatManager.h"
50#include "util/Convert.h"
51#include "util/Math.h"
52#include "infos/Bot.h"
53#include "items/Engine.h"
54#include "controllers/HumanController.h"
55
56#include "core/CoreIncludes.h"
57#include "chat/ChatManager.h"
58#include "infos/PlayerInfo.h"
59#include "worldentities/pawns/Pawn.h"
60#include "core/config/ConfigValueIncludes.h"
61#include "infos/Bot.h"
62#include "SpaceRaceBot.h"
63#include "items/Engine.h"
64
65#include "core/CoreIncludes.h"
66#include "chat/ChatManager.h"
67#include "util/Convert.h"
68#include "util/Math.h"
69#include "SpaceRaceBot.h"
70#include "items/Engine.h"
71#include <vector> 
72#include <iostream>
73#include <string>
74
75
76namespace orxonox
77{
78    RegisterUnloadableClass(SpaceRace);
79
80    SpaceRace::SpaceRace(Context* context) : Gametype(context)
81    {
82        RegisterObject(SpaceRace);
83
84        this->botclass_ = Class(SpaceRaceBot);
85        this->cantMove_ = false;
86        this->bTimeIsUp_ = false;
87
88        this->numberOfBots_ = 5; // quick fix: don't allow default-bots to enter the race
89        //we fixed the number of bots in order to have the same starting position all the time !
90    }
91
92    void SpaceRace::start()
93    {
94        // define spawn positions of the 5 bots
95
96        float 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        Gametype::start();
119
120        this->spawnPlayersIfRequested();
121        this->countdown_mode=true;
122        this->cantMove_ = true;
123        //players are unable to move while countdown is running
124        for (Engine* engine : ObjectList<Engine>())
125        {
126            engine->setActive(false);
127            engine->addSpeedMultiply(1.7);
128
129           
130        }
131
132
133        //append spawn positions to bots
134        int a,b,c;
135        a=0;
136        b=1;
137        c=2;
138
139        for (SpaceRaceBot* bot : ObjectList<SpaceRaceBot>())
140        {
141            bot->getControllableEntity()->setPosition(startpos[a], startpos[b], startpos[c]);
142            a += 3;
143            b += 3;
144            c += 3;
145        }
146
147        std::string message("Use headphones to hear the countdown! It is useful to start with a boost!");
148
149        this->getGametypeInfo()->sendAnnounceMessage(message);
150        ChatManager::message(message);
151       
152
153
154       
155    }
156
157    // Counter in the beginning of the game
158    void SpaceRace::tick(float dt) {
159        SUPER(SpaceRace, tick, dt);
160       
161        //countdown_mode is set true,when spawnIfRequested is called
162        if (countdown_mode) {
163            //10 seconds will be counted
164            this->time_passed -= dt;
165
166            //orxout() << "time: " <<(int) time_passed << "s" << endl;
167
168            std::string message=std::to_string((int)time_passed);
169            this->getGametypeInfo()->sendAnnounceMessage(message);
170            if (time_passed <= 1) {
171
172                this->countdownFinished();
173                this->countdown_mode = false;
174            }
175        }
176
177    }
178       
179    void SpaceRace::startmessage(int second){
180
181        std::string message=std::to_string(second);
182        this->getGametypeInfo()->sendAnnounceMessage(message);
183        ChatManager::message(message);
184       
185       
186
187    }
188
189    void SpaceRace::end()
190    {
191        this->clock_.capture();
192        int s = this->clock_.getSeconds();
193        int ms = static_cast<int>(this->clock_.getMilliseconds() - 1000*s);
194        std::string message;
195
196        if (this->bTimeIsUp_)
197        {
198            message = multi_cast<std::string>(s) + "." + multi_cast<std::string>(ms) + " seconds !!\n"
199                        + "You lose!";
200        }
201        else
202        {
203            message = "You win!! Final check point reached after "+ multi_cast<std::string>(s)
204                        + "." + multi_cast<std::string>(ms) + " seconds.";
205        }
206        if (!this->hasEnded())
207        {
208            this->getGametypeInfo()->sendAnnounceMessage(message);
209            ChatManager::message(message);
210        }
211        this->Gametype::end();
212    }
213
214    void SpaceRace::newCheckpointReached(RaceCheckPoint* checkpoint, PlayerInfo* player)
215    {
216        this->checkpointReached_[player] = checkpoint;
217
218        this->clock_.capture();
219        int s = this->clock_.getSeconds();
220        int ms = this->clock_.getMilliseconds() % 1000;
221
222       
223   
224        const std::string& message = player->getName() + " reached the checkpoint " + multi_cast<std::string>(checkpoint->getCheckpointIndex() + 1) 
225        + "after " + multi_cast<std::string>(s) + "." + multi_cast<std::string>(ms) + " seconds.";
226        this->getGametypeInfo()->sendAnnounceMessage(message);
227        ChatManager::message(message);
228
229    }
230
231    void SpaceRace::countdownFinished()//activates the engines of all players
232    {
233
234        std::string message("RACE STARTED ");
235        this->getGametypeInfo()->sendAnnounceMessage(message);
236        ChatManager::message(message);
237
238
239        for (Engine* engine : ObjectList<Engine>())
240            engine->setActive(true);
241    }
242
243    void SpaceRace::playerEntered(PlayerInfo* player)
244    {
245        Gametype::playerEntered(player);
246
247        const std::string& message = player->getName() + " entered the game";
248        ChatManager::message(message);
249    }
250
251
252    void SpaceRace::addBots(unsigned int amount) //function that add the bots to the game
253    {
254        for (unsigned int i = 1; i <= amount; ++i){
255            this->botclass_.fabricate(this->getContext());
256        }
257    }
258
259
260    //set bot configurations
261    bool SpaceRace::allowPawnHit(Pawn* victim, Pawn* originator)
262    {
263        return true;
264    }
265
266    bool SpaceRace::allowPawnDamage(Pawn* victim, Pawn* originator)
267    {
268        return true;
269    }
270
271    bool SpaceRace::allowPawnDeath(Pawn* victim, Pawn* originator)// false because the bots can not recognize the objects and die to earlyif they can
272    {
273        return false;
274    }
275}
Note: See TracBrowser for help on using the repository browser.