Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

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

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

level Spacerace2

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