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
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
32#include "items/Engine.h"
33
34#include "core/CoreIncludes.h"
35#include "chat/ChatManager.h"
36#include "util/Convert.h"
37#include "util/Math.h"
38
39#include "items/Engine.h"
40
41namespace orxonox
42{
43    CreateUnloadableFactory(SpaceRace);
44
45    SpaceRace::SpaceRace(BaseObject* creator) : Gametype(creator)
46    {
47        RegisterObject(SpaceRace);
48       
49        this->bTimeIsUp_ = false;
50        this->numberOfBots_ = 0;
51        this->cantMove_=false;
52       
53    }
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           
88
89        }
90    }
91
92    void SpaceRace::start()
93    {
94
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_); 
105    }
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    }
126
127   
128   
129    void SpaceRace::newCheckpointReached(SpaceRaceManager* p, int index,PlayerInfo* pl)
130    {
131        this->checkpointReached_[pl]=index;
132        this->clock_.capture();
133        int s = this->clock_.getSeconds();
134        int ms = static_cast<int>(this->clock_.getMilliseconds()-1000*s);
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.
138        const_cast<GametypeInfo*>(this->getGametypeInfo())->sendAnnounceMessage(message);
139        ChatManager::message(message);
140    }
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        //}
173
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    }
191}
Note: See TracBrowser for help on using the repository browser.