Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: code/branches/core6/src/modules/gametypes/SpaceRace.cc @ 9629

Last change on this file since 9629 was 9629, checked in by landauf, 11 years ago

BaseObject now requires a Context instead of a creator (BaseObject*) in its constructor.
Namespace, Level, and Scene inherit from Context

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