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 | |
---|
49 | |
---|
50 | this->bTimeIsUp_ = false; |
---|
51 | this->numberOfBots_ = 0; |
---|
52 | this->cantMove_=false; |
---|
53 | |
---|
54 | |
---|
55 | for (std::map<PlayerInfo*, Player>::iterator it = this->players_.begin(); it != this->players_.end(); ++it) |
---|
56 | {this->checkpointReached_[it->first]=0;} |
---|
57 | |
---|
58 | |
---|
59 | } |
---|
60 | |
---|
61 | // void SpaceRace::SetConfigValues(){ |
---|
62 | //SUPER(Gametype,setConfigValues); |
---|
63 | //this->Gametype::SetConfigValue(initialStartCountdown_, 3.0f);} |
---|
64 | |
---|
65 | void SpaceRace::end() |
---|
66 | { |
---|
67 | this->Gametype::end(); |
---|
68 | |
---|
69 | if (this->bTimeIsUp_) |
---|
70 | { |
---|
71 | this->clock_.capture(); |
---|
72 | int s = this->clock_.getSeconds(); |
---|
73 | int ms = static_cast<int>(this->clock_.getMilliseconds()-1000*s); |
---|
74 | const std::string& message = multi_cast<std::string>(s) + "." + multi_cast<std::string>(ms) + " seconds !!\n" |
---|
75 | + "You didn't reach the check point before the time limit. You lose!"; |
---|
76 | const_cast<GametypeInfo*>(this->getGametypeInfo())->sendAnnounceMessage(message); |
---|
77 | ChatManager::message(message); |
---|
78 | } |
---|
79 | else |
---|
80 | { |
---|
81 | this->clock_.capture(); |
---|
82 | int s = this->clock_.getSeconds(); |
---|
83 | int ms = static_cast<int>(this->clock_.getMilliseconds()-1000*s); |
---|
84 | const std::string& message = "You win!! You have reached the last check point after "+ multi_cast<std::string>(s) |
---|
85 | + "." + multi_cast<std::string>(ms) + " seconds."; |
---|
86 | const_cast<GametypeInfo*>(this->getGametypeInfo())->sendAnnounceMessage(message); |
---|
87 | ChatManager::message(message); |
---|
88 | /* |
---|
89 | float time = this->clock_.getSecondsPrecise(); |
---|
90 | this->scores_.insert(time); |
---|
91 | std::set<float>::iterator it; |
---|
92 | for (it=this->scores_.begin(); it!=this->scores_.end(); it++) |
---|
93 | orxout(level::message) << multi_cast<std::string>(*it) << endl; |
---|
94 | */ |
---|
95 | } |
---|
96 | } |
---|
97 | |
---|
98 | void SpaceRace::start() |
---|
99 | { |
---|
100 | //Gametype::start(); |
---|
101 | this->spawnPlayersIfRequested(); Gametype::checkStart(); |
---|
102 | this->cantMove_=true; |
---|
103 | |
---|
104 | for(ObjectList<Engine>::iterator it = ObjectList<Engine>::begin(); it; ++it) |
---|
105 | {if(it->getMaxSpeedFront()>0){this->maxSpeedBack_=it->getMaxSpeedBack(); |
---|
106 | this->maxSpeedFront_=it->getMaxSpeedFront(); |
---|
107 | this->maxSpeedLeftRight_=it->getMaxSpeedLeftRight(); |
---|
108 | this->maxSpeedUpDown_=(it->getMaxSpeedUpDown()); |
---|
109 | } |
---|
110 | it->setMaxSpeedBack(0); |
---|
111 | it->setMaxSpeedFront(0); |
---|
112 | it->setMaxSpeedLeftRight(0); |
---|
113 | it->setMaxSpeedUpDown(0); |
---|
114 | |
---|
115 | |
---|
116 | } |
---|
117 | |
---|
118 | this->addBots(this->numberOfBots_); |
---|
119 | |
---|
120 | } |
---|
121 | |
---|
122 | void SpaceRace::tick(float dt){ |
---|
123 | SUPER(SpaceRace,tick,dt); |
---|
124 | |
---|
125 | if(!this->isStartCountdownRunning() && this->cantMove_){ |
---|
126 | |
---|
127 | for(ObjectList<Engine>::iterator it = ObjectList<Engine>::begin(); it; ++it) |
---|
128 | { |
---|
129 | it->setMaxSpeedBack(this->maxSpeedBack_); |
---|
130 | it->setMaxSpeedFront(this->maxSpeedFront_); |
---|
131 | it->setMaxSpeedLeftRight(this->maxSpeedLeftRight_); |
---|
132 | it->setMaxSpeedUpDown(this->maxSpeedUpDown_); |
---|
133 | } |
---|
134 | this->cantMove_= false; |
---|
135 | |
---|
136 | std::string message("The match has started! Reach the check points as quickly as possible!"); |
---|
137 | const_cast<GametypeInfo*>(this->getGametypeInfo())->sendAnnounceMessage(message); |
---|
138 | ChatManager::message(message); |
---|
139 | |
---|
140 | } |
---|
141 | |
---|
142 | |
---|
143 | } |
---|
144 | |
---|
145 | void SpaceRace::setV(SpaceRaceManager* m){ |
---|
146 | /*Vector3 v =Vector3(0,0,0); |
---|
147 | int j=0; |
---|
148 | for (std::map<PlayerInfo*, Player>::iterator it = this->players_.begin(); it != this->players_.end(); ++it) |
---|
149 | { |
---|
150 | j=this->getCheckpointReached(it->first); |
---|
151 | RaceCheckPoint* r=m->getCheckpoint(j); |
---|
152 | v=r->getNextcheckpoint(); |
---|
153 | for(int i=1;i<4;i++){ |
---|
154 | if(v[i]==0){ |
---|
155 | RaceCheckPoint* n=m->getCheckpoint(v[i]); |
---|
156 | n->setV(true); |
---|
157 | }} |
---|
158 | }*/ |
---|
159 | } |
---|
160 | |
---|
161 | void SpaceRace::newCheckpointReached(SpaceRaceManager* p, int index,PlayerInfo* pl) |
---|
162 | { |
---|
163 | this->checkpointReached_[pl]=index; |
---|
164 | this->clock_.capture(); |
---|
165 | int s = this->clock_.getSeconds(); |
---|
166 | int ms = static_cast<int>(this->clock_.getMilliseconds()-1000*s); |
---|
167 | const std::string& message = "Checkpoint " + multi_cast<std::string>(index) |
---|
168 | + " reached after " + multi_cast<std::string>(s) + "." + multi_cast<std::string>(ms) |
---|
169 | + " seconds."; |
---|
170 | const_cast<GametypeInfo*>(this->getGametypeInfo())->sendAnnounceMessage(message); |
---|
171 | ChatManager::message(message); |
---|
172 | |
---|
173 | |
---|
174 | } |
---|
175 | |
---|
176 | void SpaceRace::newCheckpointReached(RaceCheckPoint* p, PlayerInfo* pl) |
---|
177 | { int index = p->getCheckpointIndex(); |
---|
178 | this->checkpointReached_[pl]=index; |
---|
179 | this->clock_.capture(); |
---|
180 | int s = this->clock_.getSeconds(); |
---|
181 | int ms = static_cast<int>(this->clock_.getMilliseconds()-1000*s); |
---|
182 | const std::string& message = "Checkpoint " + multi_cast<std::string>(index) |
---|
183 | + " reached after " + multi_cast<std::string>(s) + "." + multi_cast<std::string>(ms) |
---|
184 | + " seconds."; |
---|
185 | const_cast<GametypeInfo*>(this->getGametypeInfo())->sendAnnounceMessage(message); |
---|
186 | ChatManager::message(message); |
---|
187 | |
---|
188 | |
---|
189 | } |
---|
190 | |
---|
191 | |
---|
192 | |
---|
193 | void SpaceRace::playerEntered(PlayerInfo* player){ |
---|
194 | Gametype::playerEntered(player); |
---|
195 | //this->checkpointReached_[player]=0; |
---|
196 | //this->playersAlive_++; |
---|
197 | } |
---|
198 | |
---|
199 | bool SpaceRace::playerLeft(PlayerInfo* player){ |
---|
200 | return Gametype::playerLeft(player); |
---|
201 | // bool valid_player = true; |
---|
202 | //if (valid_player) |
---|
203 | // { |
---|
204 | // this->playersAlive_--; |
---|
205 | //} |
---|
206 | |
---|
207 | // return valid_player; |
---|
208 | } |
---|
209 | } |
---|