Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: code/branches/mergeFS18/src/modules/gametypes/SpaceRace.cc

Last change on this file was 12029, checked in by merholzl, 6 years ago

added space race improvements

  • Property svn:eol-style set to native
File size: 8.2 KB
RevLine 
[8182]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:
[8250]23 *     Mauro Salomon
[8182]24 *   Co-authors:
[11358]25 *      Celine Egger*/
26       
[8182]27
[11358]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
[8182]46#include "SpaceRace.h"
47
[11358]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"
[9016]53#include "items/Engine.h"
[11358]54#include "controllers/HumanController.h"
[9016]55
[8182]56#include "core/CoreIncludes.h"
[8858]57#include "chat/ChatManager.h"
[11358]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"
[8428]67#include "util/Convert.h"
[8767]68#include "util/Math.h"
[9526]69#include "SpaceRaceBot.h"
[9016]70#include "items/Engine.h"
[12029]71#include <vector> 
72#include <iostream>
73#include <string>
[9016]74
[11358]75
[8250]76namespace orxonox
77{
[9667]78    RegisterUnloadableClass(SpaceRace);
[8767]79
[9667]80    SpaceRace::SpaceRace(Context* context) : Gametype(context)
[8182]81    {
[8630]82        RegisterObject(SpaceRace);
[9260]83
[11720]84        this->botclass_ = Class(SpaceRaceBot);
[9260]85        this->cantMove_ = false;
[8630]86        this->bTimeIsUp_ = false;
[11358]87        this->numberOfBots_ = 5; // quick fix: don't allow default-bots to enter the race
[12029]88        this->bLost =false;
[11358]89        //we fixed the number of bots in order to have the same starting position all the time !
[8182]90    }
[8767]91
[11358]92    void SpaceRace::start()
93    {
[11720]94        // define spawn positions of the 5 bots
[11358]95
[11721]96        float startpos[15];
[11358]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;
[12029]105         
[11358]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
[11720]118        Gametype::start();
[11358]119
[11720]120        this->spawnPlayersIfRequested();
[12029]121        this->countdown_mode=true;
[11720]122        this->cantMove_ = true;
123        //players are unable to move while countdown is running
124        for (Engine* engine : ObjectList<Engine>())
[11358]125        {
[11720]126            engine->setActive(false);
[12029]127            engine->addSpeedMultiply(1.7);
[11720]128        }
[11358]129
[11720]130        //append spawn positions to bots
131        int a,b,c;
132        a=0;
133        b=1;
134        c=2;
[11358]135
[11720]136        for (SpaceRaceBot* bot : ObjectList<SpaceRaceBot>())
137        {
138            bot->getControllableEntity()->setPosition(startpos[a], startpos[b], startpos[c]);
139            a += 3;
140            b += 3;
141            c += 3;
[11358]142        }
143
[12029]144        std::string message("Use headphones to hear the countdown! Press W for forward acceleration, press W+space for boost!");
145
[11358]146        this->getGametypeInfo()->sendAnnounceMessage(message);
147        ChatManager::message(message);
[12029]148       
[11358]149
[12029]150
151       
[11358]152    }
153
[12029]154    // Counter in the beginning of the game
155    void SpaceRace::tick(float dt) {
156        SUPER(SpaceRace, tick, dt);
157       
158        //countdown_mode is set true,when spawnIfRequested is called
159        if (countdown_mode) {
160            //10 seconds will be counted
161            this->time_passed -= dt;
[11358]162
[12029]163            //orxout() << "time: " <<(int) time_passed << "s" << endl;
[11358]164
[12029]165            std::string message=std::to_string((int)time_passed);
166            this->getGametypeInfo()->sendAnnounceMessage(message);
167            if (time_passed <= 1) {
[11358]168
[12029]169                this->countdownFinished();
170                this->countdown_mode = false;
171            }
172        }
173
174    }
175       
176    void SpaceRace::startmessage(int second){
177
178        std::string message=std::to_string(second);
179        this->getGametypeInfo()->sendAnnounceMessage(message);
180        ChatManager::message(message);
181       
182       
183
184    }
185
[8428]186    void SpaceRace::end()
187    {
[12029]188       
[9260]189        this->clock_.capture();
190        int s = this->clock_.getSeconds();
191        int ms = static_cast<int>(this->clock_.getMilliseconds() - 1000*s);
192        std::string message;
[8630]193        if (this->bTimeIsUp_)
194        {
[12029]195            message =  "TIME IS UP! YOU LOOSE!";
[8630]196        }
[12029]197       else if(this->bLost){
198            message = "YOU LOOSE!";
199
200       }       
201       
[8630]202        else
203        {
[11358]204            message = "You win!! Final check point reached after "+ multi_cast<std::string>(s)
[8630]205                        + "." + multi_cast<std::string>(ms) + " seconds.";
[9260]206        }
[12029]207       
[9804]208        if (!this->hasEnded())
209        {
[12029]210
[9804]211            this->getGametypeInfo()->sendAnnounceMessage(message);
212            ChatManager::message(message);
213        }
214        this->Gametype::end();
[8428]215    }
[8182]216
[9260]217    void SpaceRace::newCheckpointReached(RaceCheckPoint* checkpoint, PlayerInfo* player)
[8428]218    {
[9263]219        this->checkpointReached_[player] = checkpoint;
[9262]220
[8630]221        this->clock_.capture();
222        int s = this->clock_.getSeconds();
[9260]223        int ms = this->clock_.getMilliseconds() % 1000;
[9262]224
[12029]225
226        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
229        this->getGametypeInfo()->sendAnnounceMessage(message);
230        ChatManager::message(message);
231      /*  const std::string& message = player->getName() + " reached the checkpoint " + multi_cast<std::string>(checkpoint->getCheckpointIndex() + 1)
[11358]232        + "after " + multi_cast<std::string>(s) + "." + multi_cast<std::string>(ms) + " seconds.";
[11720]233        this->getGametypeInfo()->sendAnnounceMessage(message);
[12029]234        ChatManager::message(message);*/
235       
[11358]236
237    }
238
[11720]239    void SpaceRace::countdownFinished()//activates the engines of all players
[11358]240    {
241
[12029]242        std::string message("RACE STARTED");
[9348]243        this->getGametypeInfo()->sendAnnounceMessage(message);
[8858]244        ChatManager::message(message);
[12029]245       
[11358]246
247
[11720]248        for (Engine* engine : ObjectList<Engine>())
249            engine->setActive(true);
[12029]250
251        std::string message2("Press W for forward acceleration, press W+space for boost!");
252        this->getGametypeInfo()->sendAnnounceMessage(message2);
253        ChatManager::message(message2);
[11720]254    }
[11358]255
[11720]256    void SpaceRace::playerEntered(PlayerInfo* player)
[11358]257    {
258        Gametype::playerEntered(player);
259
260        const std::string& message = player->getName() + " entered the game";
261        ChatManager::message(message);
[8428]262    }
[9260]263
[11358]264
[11720]265    void SpaceRace::addBots(unsigned int amount) //function that add the bots to the game
[11358]266    {
267        for (unsigned int i = 1; i <= amount; ++i){
268            this->botclass_.fabricate(this->getContext());
269        }
270    }
271
272
[11720]273    //set bot configurations
[9016]274    bool SpaceRace::allowPawnHit(Pawn* victim, Pawn* originator)
275    {
[11358]276        return true;
[9016]277    }
278
279    bool SpaceRace::allowPawnDamage(Pawn* victim, Pawn* originator)
280    {
[11358]281        return true;
[9016]282    }
283
[11720]284    bool SpaceRace::allowPawnDeath(Pawn* victim, Pawn* originator)// false because the bots can not recognize the objects and die to earlyif they can
[9016]285    {
286        return false;
287    }
[8858]288}
Note: See TracBrowser for help on using the repository browser.