Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: code/trunk/src/modules/gametypes/SpaceRace.cc @ 11720

Last change on this file since 11720 was 11720, checked in by landauf, 6 years ago

[SpaceRace_HS16] reverted some unwanted changes and fixed formatting a little bit

  • Property svn:eol-style set to native
File size: 6.7 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
73
74namespace orxonox
75{
76    RegisterUnloadableClass(SpaceRace);
77
78    SpaceRace::SpaceRace(Context* context) : Gametype(context)
79    {
80        RegisterObject(SpaceRace);
81
82        this->botclass_ = Class(SpaceRaceBot);
83        this->cantMove_ = false;
84        this->bTimeIsUp_ = false;
85
86        this->numberOfBots_ = 5; // quick fix: don't allow default-bots to enter the race
87        //we fixed the number of bots in order to have the same starting position all the time !
88    }
89
90    void SpaceRace::start()
91    {
92        // define spawn positions of the 5 bots
93
94        int startpos[15];
95       
96        startpos[0] =100;
97        startpos[1] =-40;
98        startpos[2] =0;
99       
100        startpos[3] =100;
101        startpos[4] =-40;
102        startpos[5] =100;
103       
104        startpos[6] =100;
105        startpos[7] =-40;
106        startpos[8] =-100;
107       
108        startpos[9] =0;
109        startpos[10] =-40;
110        startpos[11] =-80;
111       
112        startpos[12] =0;
113        startpos[13] =-40;
114        startpos[14] =80;
115
116        Gametype::start();
117
118        this->spawnPlayersIfRequested();
119        this->cantMove_ = true;
120        //players are unable to move while countdown is running
121        for (Engine* engine : ObjectList<Engine>())
122        {
123            engine->setActive(false);
124        }
125
126        //append spawn positions to bots
127        int a,b,c;
128        a=0;
129        b=1;
130        c=2;
131
132        for (SpaceRaceBot* bot : ObjectList<SpaceRaceBot>())
133        {
134            bot->getControllableEntity()->setPosition(startpos[a], startpos[b], startpos[c]);
135            a += 3;
136            b += 3;
137            c += 3;
138        }
139
140        std::string message("Use headphones to hear the countdown!");
141        this->getGametypeInfo()->sendAnnounceMessage(message);
142        ChatManager::message(message);
143
144        //after 11 seconds , countdownFinished function is called to activate bots` engines
145        Timer* countdownTimer = new Timer();
146        countdownTimer->setTimer(11, false, createExecutor(createFunctor(&SpaceRace::countdownFinished, this)));
147    }
148
149
150
151
152    void SpaceRace::end()
153    {
154        this->clock_.capture();
155        int s = this->clock_.getSeconds();
156        int ms = static_cast<int>(this->clock_.getMilliseconds() - 1000*s);
157        std::string message;
158
159        if (this->bTimeIsUp_)
160        {
161            message = multi_cast<std::string>(s) + "." + multi_cast<std::string>(ms) + " seconds !!\n"
162                        + "You lose!";
163        }
164        else
165        {
166            message = "You win!! Final check point reached after "+ multi_cast<std::string>(s)
167                        + "." + multi_cast<std::string>(ms) + " seconds.";
168        }
169        if (!this->hasEnded())
170        {
171            this->getGametypeInfo()->sendAnnounceMessage(message);
172            ChatManager::message(message);
173        }
174        this->Gametype::end();
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()//activates the engines of all players
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    void SpaceRace::playerEntered(PlayerInfo* player)
207    {
208        Gametype::playerEntered(player);
209
210        const std::string& message = player->getName() + " entered the game";
211        ChatManager::message(message);
212    }
213
214
215    void SpaceRace::addBots(unsigned int amount) //function that add the bots to the game
216    {
217        for (unsigned int i = 1; i <= amount; ++i){
218            this->botclass_.fabricate(this->getContext());
219        }
220    }
221
222
223    //set bot configurations
224    bool SpaceRace::allowPawnHit(Pawn* victim, Pawn* originator)
225    {
226        return true;
227    }
228
229    bool SpaceRace::allowPawnDamage(Pawn* victim, Pawn* originator)
230    {
231        return true;
232    }
233
234    bool SpaceRace::allowPawnDeath(Pawn* victim, Pawn* originator)// false because the bots can not recognize the objects and die to earlyif they can
235    {
236        return false;
237    }
238}
Note: See TracBrowser for help on using the repository browser.