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 | |
---|
40 | namespace orxonox |
---|
41 | { |
---|
42 | CreateUnloadableFactory(SpaceRace); |
---|
43 | |
---|
44 | SpaceRace::SpaceRace(BaseObject* creator) : Gametype(creator) |
---|
45 | { |
---|
46 | RegisterObject(SpaceRace); |
---|
47 | |
---|
48 | this->cantMove_ = false; |
---|
49 | this->bTimeIsUp_ = false; |
---|
50 | } |
---|
51 | |
---|
52 | void SpaceRace::end() |
---|
53 | { |
---|
54 | this->Gametype::end(); |
---|
55 | |
---|
56 | this->clock_.capture(); |
---|
57 | int s = this->clock_.getSeconds(); |
---|
58 | int ms = static_cast<int>(this->clock_.getMilliseconds() - 1000*s); |
---|
59 | std::string message; |
---|
60 | |
---|
61 | if (this->bTimeIsUp_) |
---|
62 | { |
---|
63 | message = multi_cast<std::string>(s) + "." + multi_cast<std::string>(ms) + " seconds !!\n" |
---|
64 | + "You didn't reach the check point before the time limit. You lose!"; |
---|
65 | } |
---|
66 | else |
---|
67 | { |
---|
68 | message = "You win!! You have reached the last check point after "+ multi_cast<std::string>(s) |
---|
69 | + "." + multi_cast<std::string>(ms) + " seconds."; |
---|
70 | } |
---|
71 | |
---|
72 | const_cast<GametypeInfo*>(this->getGametypeInfo())->sendAnnounceMessage(message); |
---|
73 | ChatManager::message(message); |
---|
74 | } |
---|
75 | |
---|
76 | void SpaceRace::tick(float dt) |
---|
77 | { |
---|
78 | SUPER(SpaceRace,tick,dt); |
---|
79 | |
---|
80 | // spawn the players already when the countdown starts, but deactivate their engines |
---|
81 | if (this->isStartCountdownRunning() && !this->cantMove_) |
---|
82 | { |
---|
83 | this->spawnPlayersIfRequested(); |
---|
84 | this->cantMove_ = true; |
---|
85 | |
---|
86 | for (ObjectList<Engine>::iterator it = ObjectList<Engine>::begin(); it; ++it) |
---|
87 | it->setActive(false); |
---|
88 | } |
---|
89 | |
---|
90 | // activate the engines again if the countdown ends |
---|
91 | if (!this->isStartCountdownRunning() && this->cantMove_) |
---|
92 | { |
---|
93 | for (ObjectList<Engine>::iterator it = ObjectList<Engine>::begin(); it; ++it) |
---|
94 | it->setActive(true); |
---|
95 | |
---|
96 | this->cantMove_= false; |
---|
97 | |
---|
98 | std::string message = "The match has started! Reach the check points as quickly as possible!"; |
---|
99 | const_cast<GametypeInfo*>(this->getGametypeInfo())->sendAnnounceMessage(message); |
---|
100 | ChatManager::message(message); |
---|
101 | } |
---|
102 | } |
---|
103 | |
---|
104 | void SpaceRace::newCheckpointReached(RaceCheckPoint* checkpoint, PlayerInfo* player) |
---|
105 | { |
---|
106 | this->checkpointReached_[player] = checkpoint; |
---|
107 | |
---|
108 | this->clock_.capture(); |
---|
109 | int s = this->clock_.getSeconds(); |
---|
110 | int ms = this->clock_.getMilliseconds() % 1000; |
---|
111 | |
---|
112 | const std::string& message = "Checkpoint " + multi_cast<std::string>(checkpoint->getCheckpointIndex() + 1) |
---|
113 | + " reached after " + multi_cast<std::string>(s) + "." + multi_cast<std::string>(ms) + " seconds."; |
---|
114 | const_cast<GametypeInfo*>(this->getGametypeInfo())->sendAnnounceMessage(message); |
---|
115 | ChatManager::message(message); |
---|
116 | } |
---|
117 | |
---|
118 | bool SpaceRace::allowPawnHit(Pawn* victim, Pawn* originator) |
---|
119 | { |
---|
120 | return false; |
---|
121 | } |
---|
122 | |
---|
123 | bool SpaceRace::allowPawnDamage(Pawn* victim, Pawn* originator) |
---|
124 | { |
---|
125 | return false; |
---|
126 | } |
---|
127 | |
---|
128 | bool SpaceRace::allowPawnDeath(Pawn* victim, Pawn* originator) |
---|
129 | { |
---|
130 | return false; |
---|
131 | } |
---|
132 | } |
---|