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