Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: code/branches/spaceraceTwo/src/modules/gametypes/SpaceRace.cc @ 8959

Last change on this file since 8959 was 8959, checked in by eceline, 12 years ago

RaceCheckPoint::fire doesn't work

  • Property svn:eol-style set to native
File size: 7.3 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
[8959]31//#include "SpaceRaceManager.h"
32
[8911]33#include "items/Engine.h"
34
[8182]35#include "core/CoreIncludes.h"
[8858]36#include "chat/ChatManager.h"
[8428]37#include "util/Convert.h"
[8767]38#include "util/Math.h"
[8182]39
[8898]40#include "items/Engine.h"
41
[8250]42namespace orxonox
43{
[8182]44    CreateUnloadableFactory(SpaceRace);
[8767]45
[8182]46    SpaceRace::SpaceRace(BaseObject* creator) : Gametype(creator)
47    {
[8630]48        RegisterObject(SpaceRace);
[8940]49       
[8949]50       
[8944]51   
[8630]52        this->bTimeIsUp_ = false;
53        this->numberOfBots_ = 0;
[8911]54        this->cantMove_=false;
[8928]55       
[8949]56       
[8940]57       for (std::map<PlayerInfo*, Player>::iterator it = this->players_.begin(); it != this->players_.end(); ++it)
[8959]58        {this->checkpointReached_[it->first]=-1;}
[8944]59       
60       
[8182]61    }
[8898]62   
63  // void SpaceRace::SetConfigValues(){
64    //SUPER(Gametype,setConfigValues);
65    //this->Gametype::SetConfigValue(initialStartCountdown_, 3.0f);}
[8767]66
[8428]67    void SpaceRace::end()
68    {
[8630]69        this->Gametype::end();
[8767]70
[8630]71        if (this->bTimeIsUp_)
72        {
73            this->clock_.capture();
74            int s = this->clock_.getSeconds();
[8858]75            int ms = static_cast<int>(this->clock_.getMilliseconds()-1000*s);
[8630]76            const std::string& message = multi_cast<std::string>(s) + "." + multi_cast<std::string>(ms) + " seconds !!\n"
[8928]77                        + "You didn't reach the check point  before the time limit. You lose!";
[8630]78            const_cast<GametypeInfo*>(this->getGametypeInfo())->sendAnnounceMessage(message);
[8858]79            ChatManager::message(message);
[8630]80        }
81        else
82        {
83            this->clock_.capture();
84            int s = this->clock_.getSeconds();
[8858]85            int ms = static_cast<int>(this->clock_.getMilliseconds()-1000*s);
[8630]86            const std::string& message = "You win!! You have reached the last check point after "+ multi_cast<std::string>(s)
87                        + "." + multi_cast<std::string>(ms) + " seconds.";
88            const_cast<GametypeInfo*>(this->getGametypeInfo())->sendAnnounceMessage(message);
[8858]89            ChatManager::message(message);
90/*
[8630]91            float time = this->clock_.getSecondsPrecise();
92            this->scores_.insert(time);
93            std::set<float>::iterator it;
94            for (it=this->scores_.begin(); it!=this->scores_.end(); it++)
[8858]95                orxout(level::message) << multi_cast<std::string>(*it) << endl;
96*/
[8630]97        }
[8428]98    }
[8182]99
[8428]100    void SpaceRace::start()
[8949]101    {
102                //Gametype::start();
103                           this->spawnPlayersIfRequested(); Gametype::checkStart(); 
[8911]104                           this->cantMove_=true; 
105         
106                 for(ObjectList<Engine>::iterator it = ObjectList<Engine>::begin(); it; ++it) 
107                                {if(it->getMaxSpeedFront()>0){this->maxSpeedBack_=it->getMaxSpeedBack(); 
108                                this->maxSpeedFront_=it->getMaxSpeedFront(); 
109                                this->maxSpeedLeftRight_=it->getMaxSpeedLeftRight(); 
110                                this->maxSpeedUpDown_=(it->getMaxSpeedUpDown()); 
111                                 }
112                                it->setMaxSpeedBack(0); 
113                                it->setMaxSpeedFront(0); 
114                        it->setMaxSpeedLeftRight(0); 
115                                it->setMaxSpeedUpDown(0); 
116                                 
117                               
118                                } 
119                               
120                               this->addBots(this->numberOfBots_); 
[8954]121                               
[8949]122     
[8911]123    }
124   
125    void SpaceRace::tick(float dt){
126    SUPER(SpaceRace,tick,dt);
127   
128    if(!this->isStartCountdownRunning() && this->cantMove_){
129   
130        for(ObjectList<Engine>::iterator it = ObjectList<Engine>::begin(); it; ++it) 
131                                { 
132                                it->setMaxSpeedBack(this->maxSpeedBack_); 
133                                 it->setMaxSpeedFront(this->maxSpeedFront_); 
134                                 it->setMaxSpeedLeftRight(this->maxSpeedLeftRight_); 
135                                 it->setMaxSpeedUpDown(this->maxSpeedUpDown_); 
136                }
137                this->cantMove_= false;
138               
139                std::string message("The match has started! Reach the check points as quickly as possible!");
[8767]140        const_cast<GametypeInfo*>(this->getGametypeInfo())->sendAnnounceMessage(message);
[8911]141        ChatManager::message(message);         
[8898]142     
[8428]143    }
[8959]144    // for (std::map<PlayerInfo*, Player>::iterator it = this->players_.begin(); it != this->players_.end(); ++it)
145      //  {if(this->getCheckpointReached(it->first)==-1) orxout()<<"index -1"<<endl;}
146   
[8911]147    }
[8767]148
[8959]149        void SpaceRace::setV(SpaceRaceManager* m){/*
150                Vector3 v =Vector3(0,0,0);
[8940]151        int j=0;
152        for (std::map<PlayerInfo*, Player>::iterator it = this->players_.begin(); it != this->players_.end(); ++it)
153        {
154                j=this->getCheckpointReached(it->first);
155                RaceCheckPoint* r=m->getCheckpoint(j);
156                v=r->getNextcheckpoint();
157                for(int i=1;i<4;i++){
[8949]158                if(v[i]==0){
159                 RaceCheckPoint* n=m->getCheckpoint(v[i]);
[8940]160                 n->setV(true);
[8949]161                 }}
162        }*/
[8940]163        }
[8898]164
[8940]165    void SpaceRace::newCheckpointReached(SpaceRaceManager* p, int index,PlayerInfo* pl)
[8959]166    {/*
[8940]167        this->checkpointReached_[pl]=index;
[8630]168        this->clock_.capture();
169        int s = this->clock_.getSeconds();
[8858]170        int ms = static_cast<int>(this->clock_.getMilliseconds()-1000*s);
[8934]171        const std::string& message = "Checkpoint " + multi_cast<std::string>(index)
[8630]172                        + " reached after " + multi_cast<std::string>(s) + "." + multi_cast<std::string>(ms)
[8858]173                        + " seconds.";
[8630]174        const_cast<GametypeInfo*>(this->getGametypeInfo())->sendAnnounceMessage(message);
[8858]175        ChatManager::message(message);
[8959]176       */ 
[8928]177       
[8428]178    }
[8928]179   
[8940]180     void SpaceRace::newCheckpointReached(RaceCheckPoint* p, PlayerInfo* pl)
[8934]181    {   int index = p->getCheckpointIndex();
[8940]182        this->checkpointReached_[pl]=index;
[8934]183        this->clock_.capture();
184        int s = this->clock_.getSeconds();
185        int ms = static_cast<int>(this->clock_.getMilliseconds()-1000*s);
186        const std::string& message = "Checkpoint " + multi_cast<std::string>(index)
187                        + " reached after " + multi_cast<std::string>(s) + "." + multi_cast<std::string>(ms)
188                        + " seconds.";
189        const_cast<GametypeInfo*>(this->getGametypeInfo())->sendAnnounceMessage(message);
190        ChatManager::message(message);
191       
192       
193    }
194   
[8940]195   
[8428]196
[8928]197void SpaceRace::playerEntered(PlayerInfo* player){
[8949]198        Gametype::playerEntered(player);
[8959]199       
200        this->checkpointReached_[player]=-1;
[8949]201        //this->playersAlive_++;
[8928]202    }
203   
204        bool SpaceRace::playerLeft(PlayerInfo* player){
[8949]205        return Gametype::playerLeft(player);
206                // bool valid_player = true;
207        //if (valid_player)
208       // {
209        //    this->playersAlive_--;
210        //}
[8928]211
[8949]212       // return valid_player;
[8928]213        }
[8858]214}
Note: See TracBrowser for help on using the repository browser.