Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

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

Last change on this file since 9016 was 9016, checked in by jo, 12 years ago

Merging presentation2011 branch to trunk. Please check for possible bugs.

  • Property svn:eol-style set to native
File size: 5.9 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:
25 *      ...
26 *
27 */
28
29#include "SpaceRace.h"
30
[9016]31
32#include "items/Engine.h"
33
[8182]34#include "core/CoreIncludes.h"
[8858]35#include "chat/ChatManager.h"
[8428]36#include "util/Convert.h"
[8767]37#include "util/Math.h"
[8182]38
[9016]39#include "items/Engine.h"
40
[8250]41namespace orxonox
42{
[8182]43    CreateUnloadableFactory(SpaceRace);
[8767]44
[8182]45    SpaceRace::SpaceRace(BaseObject* creator) : Gametype(creator)
46    {
[8630]47        RegisterObject(SpaceRace);
[9016]48       
[8630]49        this->bTimeIsUp_ = false;
50        this->numberOfBots_ = 0;
[9016]51        this->cantMove_=false;
52       
[8182]53    }
[9016]54       
55   
56  // void SpaceRace::SetConfigValues(){
57    //SUPER(Gametype,setConfigValues);
58    //this->Gametype::SetConfigValue(initialStartCountdown_, 3.0f);}
[8767]59
[8428]60    void SpaceRace::end()
61    {
[8630]62        this->Gametype::end();
[8767]63
[8630]64        if (this->bTimeIsUp_)
65        {
66            this->clock_.capture();
67            int s = this->clock_.getSeconds();
[8858]68            int ms = static_cast<int>(this->clock_.getMilliseconds()-1000*s);
[8630]69            const std::string& message = multi_cast<std::string>(s) + "." + multi_cast<std::string>(ms) + " seconds !!\n"
[9016]70                        + "You didn't reach the check point  before the time limit. You lose!";
[8630]71            const_cast<GametypeInfo*>(this->getGametypeInfo())->sendAnnounceMessage(message);
[8858]72            ChatManager::message(message);
[8630]73        }
74        else
75        {
76            this->clock_.capture();
77            int s = this->clock_.getSeconds();
[8858]78            int ms = static_cast<int>(this->clock_.getMilliseconds()-1000*s);
[8630]79            const std::string& message = "You win!! You have reached the last check point after "+ multi_cast<std::string>(s)
80                        + "." + multi_cast<std::string>(ms) + " seconds.";
81            const_cast<GametypeInfo*>(this->getGametypeInfo())->sendAnnounceMessage(message);
[8858]82            ChatManager::message(message);
[9016]83
[8630]84            float time = this->clock_.getSecondsPrecise();
85            this->scores_.insert(time);
86            std::set<float>::iterator it;
[9016]87           
88
[8630]89        }
[8428]90    }
[8182]91
[8428]92    void SpaceRace::start()
93    {
[8630]94
[9016]95        this->spawnPlayersIfRequested();
96        Gametype::checkStart(); 
97        this->cantMove_=true; 
98       
99        for(ObjectList<Engine>::iterator it = ObjectList<Engine>::begin(); it; ++it) 
100        {
101            it->setActive(false);
102           
103        } 
104        this->addBots(this->numberOfBots_); 
[8428]105    }
[9016]106   
107    void SpaceRace::tick(float dt)
108    {
109        SUPER(SpaceRace,tick,dt);
110   
111        if(!this->isStartCountdownRunning() && this->cantMove_)
112        {
113            for(ObjectList<Engine>::iterator it = ObjectList<Engine>::begin(); it; ++it) 
114            { 
115                it->setActive(true);
116               
117            }
118            this->cantMove_= false;
119           
120            std::string message("The match has started! Reach the check points as quickly as possible!");
121            const_cast<GametypeInfo*>(this->getGametypeInfo())->sendAnnounceMessage(message);
122            ChatManager::message(message);           
123        }
124   
125    }
[8767]126
[9016]127   
128   
129    void SpaceRace::newCheckpointReached(SpaceRaceManager* p, int index,PlayerInfo* pl)
[8428]130    {
[9016]131        this->checkpointReached_[pl]=index;
[8630]132        this->clock_.capture();
133        int s = this->clock_.getSeconds();
[8858]134        int ms = static_cast<int>(this->clock_.getMilliseconds()-1000*s);
[9016]135        const std::string& message = "Checkpoint " + multi_cast<std::string>(index)
136            + " reached after " + multi_cast<std::string>(s) + "." + multi_cast<std::string>(ms)
137            + " seconds.";// Message is too long for a normal screen.
[8630]138        const_cast<GametypeInfo*>(this->getGametypeInfo())->sendAnnounceMessage(message);
[8858]139        ChatManager::message(message);
[8428]140    }
[9016]141   
142    void SpaceRace::newCheckpointReached(RaceCheckPoint* p, PlayerInfo* pl)
143    {   
144        int index = p->getCheckpointIndex();
145        this->checkpointReached_[pl]=index;
146        this->clock_.capture();
147        int s = this->clock_.getSeconds();
148        int ms = static_cast<int>(this->clock_.getMilliseconds()-1000*s);
149        const std::string& message = "Checkpoint " + multi_cast<std::string>(index)
150            + " reached after " + multi_cast<std::string>(s) + "." + multi_cast<std::string>(ms)
151            + " seconds.";
152        const_cast<GametypeInfo*>(this->getGametypeInfo())->sendAnnounceMessage(message);
153        ChatManager::message(message);
154    }
155       
156   
157    void SpaceRace::playerEntered(PlayerInfo* player)
158    {
159        Gametype::playerEntered(player);
160   
161        this->checkpointReached_[player]=-1;
162        //this->playersAlive_++;
163    }
164   
165    bool SpaceRace::playerLeft(PlayerInfo* player)
166    {
167        return Gametype::playerLeft(player);
168        // bool valid_player = true;
169        //if (valid_player)
170       // {
171        //    this->playersAlive_--;
172        //}
[8428]173
[9016]174       // return valid_player;
175    }
176   
177    bool SpaceRace::allowPawnHit(Pawn* victim, Pawn* originator)
178    {
179        return false;
180    }
181
182    bool SpaceRace::allowPawnDamage(Pawn* victim, Pawn* originator)
183    {
184        return false;
185    }
186
187    bool SpaceRace::allowPawnDeath(Pawn* victim, Pawn* originator)
188    {
189        return false;
190    }
[8858]191}
Note: See TracBrowser for help on using the repository browser.