Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: code/branches/SpaceRace_HS16/src/modules/gametypes/SpaceRace.cc @ 11246

Last change on this file since 11246 was 11246, checked in by bberabi, 8 years ago

sound and countdown erledigt, flugzeuge konnen nicht mehr sich bewegen bevor countdown ends

  • Property svn:eol-style set to native
File size: 4.2 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    RegisterUnloadableClass(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_ = 1; // quick fix: don't allow default-bots to enter the race
52                                 // remove this line, if a raceBot has been created.
53    }
54
55
56
57
58
59
60
61    void SpaceRace::end()
62    {
63        this->clock_.capture();
64        int s = this->clock_.getSeconds();
65        int ms = static_cast<int>(this->clock_.getMilliseconds() - 1000*s);
66        std::string message;
67
68        if (this->bTimeIsUp_)
69        {
70            message = multi_cast<std::string>(s) + "." + multi_cast<std::string>(ms) + " seconds !!\n"
71                        + "You didn't reach the check point  before the time limit. You lose!";
72        }
73        else
74        {
75            message = "You win!! Final check point reached after "+ multi_cast<std::string>(s)
76                        + "." + multi_cast<std::string>(ms) + " seconds.";
77        }
78        if (!this->hasEnded())
79        {
80            this->getGametypeInfo()->sendAnnounceMessage(message);
81            ChatManager::message(message);
82        }
83        this->Gametype::end();
84    }
85
86   
87
88
89
90
91    void SpaceRace::tick(float dt)
92    {
93        SUPER(SpaceRace,tick,dt);
94
95        // spawns the players when the countdown starts, but deactivates their engines
96        if (this->isStartCountdownRunning() && !this->cantMove_)
97        {
98            this->spawnPlayersIfRequested();
99            this->cantMove_ = true;
100
101            for (Engine* engine : ObjectList<Engine>())
102                engine->setActive(false);
103        }
104
105        // activate the engines when the countdown ends
106        if (!this->isStartCountdownRunning() && this->cantMove_)
107        {
108            for (Engine* engine : ObjectList<Engine>())
109                engine->setActive(true);
110
111            this->cantMove_= false;
112
113
114
115            std::string message = "Hello!";
116            this->getGametypeInfo()->sendAnnounceMessage(message);
117            ChatManager::message(message);
118        }
119    }
120
121
122
123
124
125
126    void SpaceRace::newCheckpointReached(RaceCheckPoint* checkpoint, PlayerInfo* player)
127    {
128        this->checkpointReached_[player] = checkpoint;
129
130        this->clock_.capture();
131        int s = this->clock_.getSeconds();
132        int ms = this->clock_.getMilliseconds() % 1000;
133
134        const std::string& message = "Checkpoint " + multi_cast<std::string>(checkpoint->getCheckpointIndex() + 1)
135            + " reached after " + multi_cast<std::string>(s) + "." + multi_cast<std::string>(ms) + " seconds.";
136        this->getGametypeInfo()->sendAnnounceMessage(message);
137        ChatManager::message(message);
138    }
139
140    bool SpaceRace::allowPawnHit(Pawn* victim, Pawn* originator)
141    {
142        return true;
143    }
144
145    bool SpaceRace::allowPawnDamage(Pawn* victim, Pawn* originator)
146    {
147        return true;
148    }
149
150    bool SpaceRace::allowPawnDeath(Pawn* victim, Pawn* originator)
151    {
152        return true;
153    }
154}
Note: See TracBrowser for help on using the repository browser.