Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

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

Last change on this file since 9348 was 9348, checked in by landauf, 12 years ago

merged branch presentation2012merge back to trunk

  • Property svn:eol-style set to native
File size: 4.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:
[9348]25 *      Celine Egger
[8182]26 *
27 */
28
29#include "SpaceRace.h"
30
[9016]31#include "items/Engine.h"
32
[8182]33#include "core/CoreIncludes.h"
[8858]34#include "chat/ChatManager.h"
[8428]35#include "util/Convert.h"
[8767]36#include "util/Math.h"
[8182]37
[9016]38#include "items/Engine.h"
39
[8250]40namespace orxonox
41{
[8182]42    CreateUnloadableFactory(SpaceRace);
[8767]43
[8182]44    SpaceRace::SpaceRace(BaseObject* creator) : Gametype(creator)
45    {
[8630]46        RegisterObject(SpaceRace);
[9260]47
48        this->cantMove_ = false;
[8630]49        this->bTimeIsUp_ = false;
[9348]50        this->numberOfBots_ = 0; // quick fix: don't allow default-bots to enter the race
51                                 // remove this line, if a raceBot has been created.
[8182]52    }
[8767]53
[8428]54    void SpaceRace::end()
55    {
[8630]56        this->Gametype::end();
[8767]57
[9260]58        this->clock_.capture();
59        int s = this->clock_.getSeconds();
60        int ms = static_cast<int>(this->clock_.getMilliseconds() - 1000*s);
61        std::string message;
62
[8630]63        if (this->bTimeIsUp_)
64        {
[9260]65            message = multi_cast<std::string>(s) + "." + multi_cast<std::string>(ms) + " seconds !!\n"
[9016]66                        + "You didn't reach the check point  before the time limit. You lose!";
[8630]67        }
68        else
69        {
[9260]70            message = "You win!! You have reached the last check point after "+ multi_cast<std::string>(s)
[8630]71                        + "." + multi_cast<std::string>(ms) + " seconds.";
[9260]72        }
[9016]73
[9348]74        this->getGametypeInfo()->sendAnnounceMessage(message);
[9260]75        ChatManager::message(message);
[8428]76    }
[8182]77
[9261]78    void SpaceRace::tick(float dt)
[8428]79    {
[9261]80        SUPER(SpaceRace,tick,dt);
[8630]81
[9262]82        // spawn the players already when the countdown starts, but deactivate their engines
[9261]83        if (this->isStartCountdownRunning() && !this->cantMove_)
84        {
85            this->spawnPlayersIfRequested();
86            this->cantMove_ = true;
[9260]87
[9261]88            for (ObjectList<Engine>::iterator it = ObjectList<Engine>::begin(); it; ++it)
89                it->setActive(false);
90        }
[9260]91
[9262]92        // activate the engines again if the countdown ends
[9260]93        if (!this->isStartCountdownRunning() && this->cantMove_)
[9016]94        {
[9260]95            for (ObjectList<Engine>::iterator it = ObjectList<Engine>::begin(); it; ++it)
[9016]96                it->setActive(true);
[9260]97
[9016]98            this->cantMove_= false;
[9260]99
100            std::string message = "The match has started! Reach the check points as quickly as possible!";
[9348]101            this->getGametypeInfo()->sendAnnounceMessage(message);
[9260]102            ChatManager::message(message);
[9016]103        }
104    }
[8767]105
[9260]106    void SpaceRace::newCheckpointReached(RaceCheckPoint* checkpoint, PlayerInfo* player)
[8428]107    {
[9263]108        this->checkpointReached_[player] = checkpoint;
[9262]109
[8630]110        this->clock_.capture();
111        int s = this->clock_.getSeconds();
[9260]112        int ms = this->clock_.getMilliseconds() % 1000;
[9262]113
[9263]114        const std::string& message = "Checkpoint " + multi_cast<std::string>(checkpoint->getCheckpointIndex() + 1)
[9260]115            + " reached after " + multi_cast<std::string>(s) + "." + multi_cast<std::string>(ms) + " seconds.";
[9348]116        this->getGametypeInfo()->sendAnnounceMessage(message);
[8858]117        ChatManager::message(message);
[8428]118    }
[9260]119
[9016]120    bool SpaceRace::allowPawnHit(Pawn* victim, Pawn* originator)
121    {
122        return false;
123    }
124
125    bool SpaceRace::allowPawnDamage(Pawn* victim, Pawn* originator)
126    {
127        return false;
128    }
129
130    bool SpaceRace::allowPawnDeath(Pawn* victim, Pawn* originator)
131    {
132        return false;
133    }
[8858]134}
Note: See TracBrowser for help on using the repository browser.