[6586] | 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 | * Johannes Ritz |
---|
| 24 | * Co-authors: |
---|
| 25 | * ... |
---|
| 26 | * |
---|
| 27 | */ |
---|
[6921] | 28 | //TODO: |
---|
[6812] | 29 | //pig punkte vergeben pro Zeit! |
---|
| 30 | //killerfarbe schwarz; evtl. eigenes Raumfahrzeug; |
---|
| 31 | //Low; Codeoptimierung und Dokumentation |
---|
[6586] | 32 | |
---|
[6812] | 33 | /* |
---|
| 34 | short gaming manual: |
---|
| 35 | There are three different parties a player can belong to: victim, chaser or killer |
---|
| 36 | Every player starts as chaser. As long as there are not enough victims and killers, you can change your and other player's parties by shooting them. |
---|
| 37 | In order to win you have to earn as much points as possible: |
---|
| 38 | - as victim by escaping the chasers |
---|
| 39 | - as chaser by shooting the victim |
---|
| 40 | - as killer by killing the chasers |
---|
| 41 | |
---|
| 42 | |
---|
| 43 | What you shouldn't do is shooting at players of your own party. By doing so your score will decrease. |
---|
| 44 | P.S: If you don't want to be a victim: Get rid of your part by shooting a chaser. |
---|
| 45 | */ |
---|
[6586] | 46 | #include "Dynamicmatch.h" |
---|
| 47 | |
---|
[6686] | 48 | #include "util/Convert.h" |
---|
[6586] | 49 | #include "core/CoreIncludes.h" |
---|
| 50 | #include "network/Host.h" |
---|
| 51 | #include "infos/PlayerInfo.h" |
---|
| 52 | #include "worldentities/pawns/Pawn.h" |
---|
[6697] | 53 | #include "worldentities/pawns/SpaceShip.h" |
---|
[6686] | 54 | #include "core/ConfigValueIncludes.h" |
---|
| 55 | #include "interfaces/TeamColourable.h" |
---|
[6697] | 56 | #include "items/Engine.h" |
---|
| 57 | #include "tools/Timer.h" |
---|
[6848] | 58 | #include "worldentities/TeamSpawnPoint.h" |
---|
[6697] | 59 | |
---|
[6586] | 60 | namespace orxonox |
---|
| 61 | { |
---|
| 62 | CreateUnloadableFactory(Dynamicmatch); |
---|
| 63 | |
---|
| 64 | Dynamicmatch::Dynamicmatch(BaseObject* creator) : Gametype(creator) |
---|
| 65 | { |
---|
| 66 | RegisterObject(Dynamicmatch); |
---|
[6812] | 67 | this->gameTime_ = 180; |
---|
| 68 | this->setConfigValues(); |
---|
[6686] | 69 | this->chaser=0; |
---|
[6812] | 70 | this->piggy=1; |
---|
| 71 | this->killer=2; |
---|
| 72 | this->notEnoughPigs=false; |
---|
| 73 | this->notEnoughKillers=false; |
---|
| 74 | this->notEnoughChasers=false; |
---|
| 75 | this->gameEnded_ =false; |
---|
| 76 | this->timesequence_ = static_cast<int>(this->gameTime_); |
---|
| 77 | this->friendlyfire=true; |
---|
| 78 | this->numberOf[chaser]=0; |
---|
| 79 | this->numberOf[piggy]=0; |
---|
| 80 | this->numberOf[killer]=0; |
---|
| 81 | this->tutorial=true; |
---|
[7076] | 82 | this->pointsPerTime=0.0f; |
---|
[6921] | 83 | this->setHUDTemplate("DynamicmatchHUD"); |
---|
[6586] | 84 | } |
---|
| 85 | |
---|
[6697] | 86 | void Dynamicmatch::setConfigValues() |
---|
| 87 | { |
---|
[6812] | 88 | SetConfigValue(gameTime_, 180); |
---|
| 89 | SetConfigValue(friendlyfire, true); |
---|
| 90 | SetConfigValue(tutorial, true); |
---|
| 91 | static ColourValue colours[] = |
---|
[6697] | 92 | { |
---|
[7076] | 93 | ColourValue(1.0f, 0.3f, 0.3f), //chasercolour |
---|
| 94 | ColourValue(0.3f, 0.3f, 1.0f), //piggycolour |
---|
| 95 | ColourValue(0.3f, 1.0f, 0.3f) //killercolour what about black: 0.0f, 0.0f, 0.0f |
---|
| 96 | |
---|
[6697] | 97 | }; |
---|
| 98 | static std::vector<ColourValue> defaultcolours(colours, colours + sizeof(colours) / sizeof(ColourValue)); |
---|
| 99 | |
---|
| 100 | SetConfigValue(partyColours_, defaultcolours); |
---|
| 101 | } |
---|
| 102 | |
---|
[6848] | 103 | bool Dynamicmatch::allowPawnDamage(Pawn* victim, Pawn* originator) |
---|
[7162] | 104 | { |
---|
| 105 | //TODO: static and fading message for the "human" player's |
---|
[6812] | 106 | if (!originator||!victim) |
---|
[6921] | 107 | return false; |
---|
[6959] | 108 | if (!originator->getPlayer()||!victim->getPlayer()) |
---|
[6921] | 109 | return false; |
---|
[6812] | 110 | if (victim && victim->getPlayer()) //&& originator && originator->getPlayer() ?? |
---|
| 111 | { |
---|
| 112 | int target= playerParty_[victim->getPlayer()]; |
---|
| 113 | int source= playerParty_[originator->getPlayer()]; |
---|
| 114 | |
---|
| 115 | //Case: Not Enough Pigs: party change (= party management) |
---|
| 116 | if (notEnoughPigs) |
---|
[6686] | 117 | { |
---|
[7076] | 118 | numberOf[target]--; //decrease numberof victims's party |
---|
| 119 | playerParty_[victim->getPlayer()]=piggy; //victim's new party: pig |
---|
| 120 | setPlayerColour(victim->getPlayer()); //victim's new colour |
---|
| 121 | numberOf[piggy]++; //party switch: number of players is not affected (decrease and increase) |
---|
[7062] | 122 | |
---|
[7076] | 123 | if(tutorial) //announce party switch |
---|
[6921] | 124 | { |
---|
| 125 | std::map<PlayerInfo*, Player>::iterator it2 = this->players_.find(victim->getPlayer()); |
---|
| 126 | if (it2 != this->players_.end()) |
---|
| 127 | { |
---|
[7062] | 128 | this->gtinfo_->sendStaticMessage("Either hide or shoot a chaser.",it2->first->getClientID(), partyColours_[chaser]); |
---|
[6987] | 129 | this->gtinfo_->sendFadingMessage("You're now a victim.",it2->first->getClientID()); |
---|
[6921] | 130 | } |
---|
| 131 | } |
---|
[7076] | 132 | if (notEnoughKillers) //reward the originator |
---|
[6686] | 133 | { |
---|
[7076] | 134 | numberOf[source]--; //decrease numberof originator's party |
---|
| 135 | playerParty_[originator->getPlayer()]=killer; //originator's new party: killer |
---|
| 136 | setPlayerColour(originator->getPlayer()); //originator's new colour |
---|
[6812] | 137 | numberOf[killer]++; |
---|
[7063] | 138 | |
---|
[7076] | 139 | if(tutorial) //announce party switch |
---|
[6921] | 140 | { |
---|
| 141 | std::map<PlayerInfo*, Player>::iterator it3 = this->players_.find(originator->getPlayer()); |
---|
| 142 | if (it3 != this->players_.end()) |
---|
| 143 | { |
---|
[7062] | 144 | this->gtinfo_->sendStaticMessage("Take the chasers down.",it3->first->getClientID(), partyColours_[chaser]); |
---|
[6987] | 145 | this->gtinfo_->sendFadingMessage("You're now a killer.",it3->first->getClientID()); |
---|
[6921] | 146 | } |
---|
| 147 | } |
---|
[6686] | 148 | } |
---|
[7076] | 149 | evaluatePlayerParties(); //check if the party change has to trigger futher party changes |
---|
| 150 | |
---|
[6812] | 151 | //Give new pig boost |
---|
| 152 | SpaceShip* spaceship = dynamic_cast<SpaceShip*>(victim); |
---|
| 153 | if (spaceship && spaceship->getEngine()) |
---|
| 154 | { |
---|
| 155 | spaceship->getEngine()->setSpeedFactor(5); |
---|
| 156 | WeakPtr<Engine>* ptr = new WeakPtr<Engine>(spaceship->getEngine()); |
---|
[7284] | 157 | ExecutorPtr executor = createExecutor(createFunctor(&Dynamicmatch::resetSpeedFactor, this)); |
---|
| 158 | executor->setDefaultValue(0, ptr); |
---|
| 159 | new Timer(10, false, executor, true); |
---|
[6686] | 160 | } |
---|
| 161 | } |
---|
[6586] | 162 | |
---|
[6812] | 163 | //Case: notEnoughKillers: party change |
---|
| 164 | else if (notEnoughKillers) |
---|
| 165 | { |
---|
[7076] | 166 | numberOf[source]--; //decrease numberof originator's party |
---|
| 167 | playerParty_[originator->getPlayer()]=killer; //originator's new party: killer |
---|
| 168 | setPlayerColour(originator->getPlayer()); //originator colour |
---|
| 169 | numberOf[killer]++; //party switch: number of players is not affected (decrease and increase) |
---|
[7062] | 170 | |
---|
[7063] | 171 | |
---|
[7076] | 172 | if(tutorial) //announce party switch |
---|
[6921] | 173 | { |
---|
| 174 | std::map<PlayerInfo*, Player>::iterator it3 = this->players_.find(originator->getPlayer()); |
---|
| 175 | if (it3 != this->players_.end()) |
---|
| 176 | { |
---|
[7062] | 177 | this->gtinfo_->sendStaticMessage("Take the chasers down.",it3->first->getClientID(),partyColours_[chaser]); |
---|
[6987] | 178 | this->gtinfo_->sendFadingMessage("You're now a killer.",it3->first->getClientID()); |
---|
[6921] | 179 | } |
---|
| 180 | } |
---|
[7076] | 181 | evaluatePlayerParties(); //check if the party change has to trigger futher party changes |
---|
[6812] | 182 | } |
---|
| 183 | //Case: notEnoughChasers: party change |
---|
| 184 | else if (notEnoughChasers) |
---|
| 185 | { |
---|
[7076] | 186 | numberOf[target]--; //decrease numberof victims's party |
---|
| 187 | playerParty_[victim->getPlayer()]=chaser; //victim's new party: chaser |
---|
| 188 | setPlayerColour(victim->getPlayer()); //victim colour |
---|
| 189 | numberOf[chaser]++; //party switch: number of players is not affected (decrease and increase) |
---|
[7062] | 190 | |
---|
[7076] | 191 | if(tutorial) //announce party switch |
---|
[6921] | 192 | { |
---|
| 193 | std::map<PlayerInfo*, Player>::iterator it3 = this->players_.find(originator->getPlayer()); |
---|
| 194 | if (it3 != this->players_.end()) |
---|
| 195 | { |
---|
| 196 | if (numberOf[killer]>0) |
---|
[7062] | 197 | this->gtinfo_->sendStaticMessage("Shoot at the victim as often as possible. Defend yourself against the killers.",it3->first->getClientID(),partyColours_[piggy]); |
---|
[7076] | 198 | |
---|
[6921] | 199 | else |
---|
[7062] | 200 | this->gtinfo_->sendStaticMessage("Shoot at the victim as often as possible.",it3->first->getClientID(),partyColours_[piggy]); |
---|
[6987] | 201 | this->gtinfo_->sendFadingMessage("You're now a chaser.",it3->first->getClientID()); |
---|
[6921] | 202 | } |
---|
| 203 | } |
---|
[7076] | 204 | evaluatePlayerParties(); //check if the party change has to trigger futher party changes |
---|
[6812] | 205 | } |
---|
[6586] | 206 | |
---|
[6812] | 207 | //Case: chaser vs. killer |
---|
| 208 | else if ((source == killer && target == chaser)||(target == killer && source == chaser )) |
---|
| 209 | { |
---|
| 210 | return true; |
---|
| 211 | } |
---|
[6586] | 212 | |
---|
[6812] | 213 | //Case: a chaser hits piggy |
---|
| 214 | else if ((source==chaser)&&(target==piggy)) |
---|
| 215 | { |
---|
| 216 | std::map<PlayerInfo*, Player>::iterator it = this->players_.find(originator->getPlayer()); |
---|
| 217 | if (it != this->players_.end()) |
---|
[6686] | 218 | { |
---|
| 219 | it->second.frags_++; |
---|
| 220 | } |
---|
[6812] | 221 | } |
---|
| 222 | //Case: piggy hits chaser |
---|
| 223 | else if (source==piggy&&target==chaser) |
---|
| 224 | { |
---|
| 225 | //partyswitch: victim bcomes piggy and the originator(piggy) becomes chaser |
---|
| 226 | playerParty_[victim->getPlayer()]=piggy; |
---|
| 227 | playerParty_[originator->getPlayer()]=chaser; |
---|
[6697] | 228 | |
---|
[7076] | 229 | //party switch -> colour switch |
---|
[6812] | 230 | setPlayerColour(victim->getPlayer()); //victim colour |
---|
| 231 | setPlayerColour(originator->getPlayer());//originator colour |
---|
[7076] | 232 | |
---|
[6921] | 233 | //Announce pary switch |
---|
| 234 | if(tutorial) |
---|
| 235 | { |
---|
| 236 | std::map<PlayerInfo*, Player>::iterator it = this->players_.find(originator->getPlayer()); |
---|
| 237 | if (it != this->players_.end()) |
---|
[7076] | 238 | { |
---|
[6921] | 239 | if (numberOf[killer]>0) |
---|
[7062] | 240 | this->gtinfo_->sendStaticMessage("Shoot at the victim as often as possible. Defend yourself against the killers.",it->first->getClientID(), partyColours_[piggy]); |
---|
[6921] | 241 | else |
---|
[7062] | 242 | this->gtinfo_->sendStaticMessage("Shoot at the victim as often as possible.",it->first->getClientID(),partyColours_[piggy]); |
---|
[6987] | 243 | this->gtinfo_->sendFadingMessage("You're now a chaser.",it->first->getClientID()); |
---|
[6921] | 244 | } |
---|
| 245 | std::map<PlayerInfo*, Player>::iterator it2 = this->players_.find(victim->getPlayer()); |
---|
| 246 | if (it2 != this->players_.end()) |
---|
| 247 | { |
---|
[7062] | 248 | this->gtinfo_->sendStaticMessage("Either hide or shoot a chaser.",it2->first->getClientID(),partyColours_[chaser]); |
---|
[6987] | 249 | this->gtinfo_->sendFadingMessage("You're now a victim.",it2->first->getClientID()); |
---|
[6921] | 250 | } |
---|
| 251 | } |
---|
[6812] | 252 | //Give new pig boost |
---|
| 253 | SpaceShip* spaceship = dynamic_cast<SpaceShip*>(victim); |
---|
| 254 | if (spaceship && spaceship->getEngine()) |
---|
| 255 | { |
---|
| 256 | spaceship->getEngine()->setSpeedFactor(5); |
---|
| 257 | WeakPtr<Engine>* ptr = new WeakPtr<Engine>(spaceship->getEngine()); |
---|
[7284] | 258 | ExecutorPtr executor = createExecutor(createFunctor(&Dynamicmatch::resetSpeedFactor, this)); |
---|
| 259 | executor->setDefaultValue(0, ptr); |
---|
| 260 | new Timer(10, false, executor, true); |
---|
[6812] | 261 | } |
---|
[6697] | 262 | |
---|
[6812] | 263 | } |
---|
[6848] | 264 | // killer vs piggy |
---|
[7076] | 265 | else if (source==killer &&target==piggy) //party and colour switch |
---|
[6812] | 266 | { |
---|
| 267 | playerParty_[victim->getPlayer()]=killer; |
---|
| 268 | playerParty_[originator->getPlayer()]=piggy; |
---|
[6697] | 269 | |
---|
[7076] | 270 | setPlayerColour(victim->getPlayer()); //victim colour |
---|
| 271 | setPlayerColour(originator->getPlayer()); //originator colour |
---|
[7062] | 272 | |
---|
[6921] | 273 | if(tutorial) //Announce pary switch |
---|
| 274 | { |
---|
| 275 | std::map<PlayerInfo*, Player>::iterator it = this->players_.find(originator->getPlayer()); |
---|
| 276 | if (it != this->players_.end()) |
---|
| 277 | { |
---|
[7062] | 278 | this->gtinfo_->sendStaticMessage("Either hide or shoot a chaser.",it->first->getClientID(),partyColours_[chaser]); |
---|
[6987] | 279 | this->gtinfo_->sendFadingMessage("You're now a victim.",it->first->getClientID()); |
---|
[6921] | 280 | } |
---|
| 281 | std::map<PlayerInfo*, Player>::iterator it2 = this->players_.find(victim->getPlayer()); |
---|
| 282 | if (it2 != this->players_.end()) |
---|
| 283 | { |
---|
[7062] | 284 | this->gtinfo_->sendStaticMessage("Take the chasers down.",it2->first->getClientID(),partyColours_[chaser]); |
---|
[6987] | 285 | this->gtinfo_->sendFadingMessage("You're now a killer.",it2->first->getClientID()); |
---|
[6921] | 286 | } |
---|
| 287 | } |
---|
[6812] | 288 | } |
---|
| 289 | //Case: friendly fire |
---|
| 290 | else if (friendlyfire && (source == target)) |
---|
| 291 | { |
---|
| 292 | std::map<PlayerInfo*, Player>::iterator it = this->players_.find(originator->getPlayer()); |
---|
| 293 | if (it != this->players_.end()) |
---|
[6686] | 294 | { |
---|
| 295 | it->second.frags_--; |
---|
| 296 | } |
---|
[6812] | 297 | } |
---|
| 298 | }// from far far away not to be removed! |
---|
| 299 | return false; //default: no damage |
---|
[6686] | 300 | } |
---|
[6586] | 301 | |
---|
[6686] | 302 | |
---|
| 303 | |
---|
[6812] | 304 | bool Dynamicmatch::allowPawnDeath(Pawn* victim, Pawn* originator) |
---|
[7076] | 305 | { |
---|
[6812] | 306 | //killers can kill chasers and killers can be killed by chasers |
---|
| 307 | if ((playerParty_[originator->getPlayer()] == killer && playerParty_[victim->getPlayer()] == chaser)||(playerParty_[victim->getPlayer()] == killer && |
---|
| 308 | playerParty_[originator->getPlayer()] == chaser )) |
---|
| 309 | { |
---|
[7076] | 310 | if (playerParty_[originator->getPlayer()] == killer) //reward the killer |
---|
[6812] | 311 | { |
---|
| 312 | std::map<PlayerInfo*, Player>::iterator it = this->players_.find(originator->getPlayer()); |
---|
| 313 | if (it != this->players_.end()) |
---|
[6686] | 314 | { |
---|
[7076] | 315 | it->second.frags_+=20; //value must be tested |
---|
[6812] | 316 | } |
---|
| 317 | } |
---|
| 318 | return true; |
---|
| 319 | } |
---|
| 320 | else return false; |
---|
[6586] | 321 | } |
---|
[7076] | 322 | |
---|
[6812] | 323 | void Dynamicmatch::playerStartsControllingPawn(PlayerInfo* player, Pawn* pawn) //set party + colouring |
---|
[6586] | 324 | { |
---|
[6686] | 325 | if (!player) |
---|
| 326 | return; |
---|
[7076] | 327 | |
---|
| 328 | Dynamicmatch::setPlayerColour(player); //Set playercolour |
---|
[6812] | 329 | evaluatePlayerParties(); |
---|
[6686] | 330 | } |
---|
| 331 | |
---|
[6692] | 332 | void Dynamicmatch::playerEntered(PlayerInfo* player) //standardfunction |
---|
[6686] | 333 | { |
---|
[6812] | 334 | if (!player)// only for safety |
---|
[6686] | 335 | return; |
---|
[7076] | 336 | playerParty_[player]=chaser; //Set playerparty |
---|
[6848] | 337 | numberOf[chaser]++; |
---|
[6586] | 338 | Gametype::playerEntered(player); |
---|
[6812] | 339 | const std::string& message6 = player->getName() + " entered the game"; |
---|
| 340 | COUT(0) << message6 << std::endl; |
---|
| 341 | Host::Broadcast(message6); |
---|
[6586] | 342 | } |
---|
| 343 | |
---|
[6686] | 344 | bool Dynamicmatch::playerLeft(PlayerInfo* player) //standardfunction |
---|
[6586] | 345 | { |
---|
| 346 | bool valid_player = Gametype::playerLeft(player); |
---|
| 347 | if (valid_player) |
---|
| 348 | { |
---|
[6812] | 349 | switch (playerParty_[player]) |
---|
| 350 | { |
---|
| 351 | case 0: numberOf[chaser]--; break; |
---|
| 352 | case 1: numberOf[piggy]--; break; |
---|
| 353 | case 2: numberOf[killer]--; break; |
---|
| 354 | } |
---|
[6586] | 355 | const std::string& message = player->getName() + " left the game"; |
---|
| 356 | COUT(0) << message << std::endl; |
---|
| 357 | Host::Broadcast(message); |
---|
[7076] | 358 | //remove player from map |
---|
[6812] | 359 | playerParty_.erase (player); |
---|
[7076] | 360 | //adjust player parties |
---|
[6812] | 361 | evaluatePlayerParties(); |
---|
[6586] | 362 | } |
---|
| 363 | |
---|
| 364 | return valid_player; |
---|
| 365 | } |
---|
| 366 | |
---|
| 367 | |
---|
[6812] | 368 | void Dynamicmatch::tick(float dt) |
---|
[6586] | 369 | { |
---|
[6848] | 370 | SUPER(Dynamicmatch, tick, dt); |
---|
[6686] | 371 | |
---|
| 372 | if (this->hasStarted() && !gameEnded_) |
---|
[6812] | 373 | { pointsPerTime =pointsPerTime + dt; |
---|
[6686] | 374 | gameTime_ = gameTime_ - dt; |
---|
[7063] | 375 | if (pointsPerTime > 2.0f)//hard coded!! should be changed |
---|
[6812] | 376 | { |
---|
| 377 | pointsPerTime=0.0f; |
---|
[6921] | 378 | rewardPig(); |
---|
[6812] | 379 | } |
---|
[6686] | 380 | if (gameTime_<= 0) |
---|
[6586] | 381 | { |
---|
[6686] | 382 | this->gameEnded_ = true; |
---|
[7076] | 383 | this->end(); |
---|
[6586] | 384 | } |
---|
[7076] | 385 | if ( gameTime_ <= timesequence_ && gameTime_ > 0) |
---|
[6686] | 386 | { |
---|
| 387 | const std::string& message = multi_cast<std::string>(timesequence_) + " seconds left!"; |
---|
[6586] | 388 | |
---|
[6686] | 389 | this->gtinfo_->sendAnnounceMessage(message); |
---|
[6586] | 390 | |
---|
[6686] | 391 | if (timesequence_ >= 30 && timesequence_ <= 60) |
---|
| 392 | { |
---|
| 393 | timesequence_ = timesequence_ - 10; |
---|
| 394 | } |
---|
| 395 | else if (timesequence_ <= 30) |
---|
| 396 | { |
---|
| 397 | timesequence_ = timesequence_ - 5; |
---|
| 398 | } |
---|
| 399 | else |
---|
| 400 | { |
---|
| 401 | timesequence_ = timesequence_ - 30; |
---|
| 402 | } |
---|
| 403 | } |
---|
[7076] | 404 | } |
---|
[6586] | 405 | } |
---|
[6812] | 406 | |
---|
| 407 | void Dynamicmatch::rewardPig() |
---|
| 408 | { |
---|
[6921] | 409 | for (std::map< PlayerInfo*, int >::iterator it = this->playerParty_.begin(); it != this->playerParty_.end(); ++it) //durch alle Spieler iterieren und alle piggys finden |
---|
| 410 | { |
---|
| 411 | if (it->second==piggy) |
---|
| 412 | { |
---|
| 413 | //Spieler mit der Pig-party frags++ |
---|
| 414 | std::map<PlayerInfo*, Player>::iterator it2 = this->players_.find(it->first);// still not sure if right syntax |
---|
| 415 | if (it2 != this->players_.end()) |
---|
| 416 | { |
---|
| 417 | it2->second.frags_++; |
---|
| 418 | } |
---|
| 419 | } |
---|
| 420 | } |
---|
[6812] | 421 | } |
---|
[7062] | 422 | void Dynamicmatch::setPlayerColour(PlayerInfo* player) // sets a player's colour |
---|
[6812] | 423 | { |
---|
| 424 | std::map<PlayerInfo*, int>::const_iterator it_player = this->playerParty_.find(player); |
---|
| 425 | Pawn* pawn = dynamic_cast<Pawn*>(player->getControllableEntity()); |
---|
| 426 | if (pawn) |
---|
| 427 | { |
---|
[6921] | 428 | pawn->setRadarObjectColour(this->partyColours_[it_player->second]); |
---|
[6812] | 429 | |
---|
| 430 | std::set<WorldEntity*> pawnAttachments = pawn->getAttachedObjects(); |
---|
| 431 | for (std::set<WorldEntity*>::iterator it = pawnAttachments.begin(); it != pawnAttachments.end(); ++it) |
---|
| 432 | { |
---|
| 433 | if ((*it)->isA(Class(TeamColourable))) |
---|
| 434 | { |
---|
| 435 | TeamColourable* tc = orxonox_cast<TeamColourable*>(*it); |
---|
| 436 | tc->setTeamColour(this->partyColours_[it_player->second]); |
---|
| 437 | } |
---|
| 438 | } |
---|
| 439 | } |
---|
[7076] | 440 | } |
---|
[6812] | 441 | |
---|
| 442 | void Dynamicmatch::evaluatePlayerParties() //manages the notEnough booleans (here the percentage of special players is implemented) |
---|
| 443 | { |
---|
| 444 | //pigs: 1 + every 6th player is a pig |
---|
[6921] | 445 | if ( (1+this->getNumberOfPlayers()/6) > numberOf[piggy]) |
---|
| 446 | { |
---|
| 447 | notEnoughPigs=true; |
---|
| 448 | if (tutorial) // Announce selectionphase |
---|
| 449 | { |
---|
| 450 | for (std::map<PlayerInfo*, int>::iterator it = this->playerParty_.begin(); it != this->playerParty_.end(); ++it) |
---|
| 451 | { |
---|
| 452 | if (!it->first)//in order to catch nullpointer |
---|
| 453 | continue; |
---|
| 454 | if (it->first->getClientID() == CLIENTID_UNKNOWN) |
---|
| 455 | continue; |
---|
[7062] | 456 | this->gtinfo_->sendStaticMessage("Selection phase: Shoot at everything that moves.",it->first->getClientID(),ColourValue(1.0f, 1.0f, 0.5f)); |
---|
[6921] | 457 | } |
---|
| 458 | } |
---|
| 459 | } |
---|
| 460 | else |
---|
| 461 | { |
---|
| 462 | notEnoughPigs=false; |
---|
| 463 | if(tutorial&&(!notEnoughKillers)&&(!notEnoughChasers)) //Selection phase over |
---|
| 464 | { |
---|
| 465 | for (std::map<PlayerInfo*, int>::iterator it = this->playerParty_.begin(); it != this->playerParty_.end(); ++it) |
---|
| 466 | { |
---|
| 467 | if (!it->first)//in order to catch nullpointer |
---|
| 468 | continue; |
---|
| 469 | if (it->first->getClientID() == CLIENTID_UNKNOWN) |
---|
| 470 | continue; |
---|
| 471 | else if (it->second==chaser) |
---|
| 472 | { |
---|
| 473 | if (numberOf[killer]>0) |
---|
[7062] | 474 | this->gtinfo_->sendStaticMessage("Shoot at the victim as often as possible. Defend yourself against the killers.",it->first->getClientID(),partyColours_[piggy]); |
---|
[6921] | 475 | else |
---|
[7062] | 476 | this->gtinfo_->sendStaticMessage("Shoot at the victim as often as possible.",it->first->getClientID(),partyColours_[piggy]); |
---|
[6987] | 477 | //this->gtinfo_->sendFadingMessage("You're now a chaser.",it->first->getClientID()); |
---|
[6921] | 478 | } |
---|
| 479 | else if (it->second==piggy) |
---|
[6987] | 480 | { |
---|
[7062] | 481 | this->gtinfo_->sendStaticMessage("Either hide or shoot a chaser.",it->first->getClientID(),partyColours_[chaser]); |
---|
[6987] | 482 | //this->gtinfo_->sendFadingMessage("You're now a victim.",it->first->getClientID()); |
---|
| 483 | } |
---|
[6921] | 484 | else if (it->second==killer) |
---|
[6987] | 485 | { |
---|
[7062] | 486 | this->gtinfo_->sendStaticMessage("Take the chasers down.",it->first->getClientID(),partyColours_[chaser]); |
---|
[6987] | 487 | //this->gtinfo_->sendFadingMessage("You're now a killer.",it->first->getClientID()); |
---|
| 488 | } |
---|
[6921] | 489 | } |
---|
[7076] | 490 | |
---|
[6921] | 491 | } |
---|
| 492 | } |
---|
[6812] | 493 | //killers: every 4th player is a killer |
---|
[6921] | 494 | if (getNumberOfPlayers()/4 > numberOf[killer]) |
---|
| 495 | { |
---|
| 496 | notEnoughKillers=true; |
---|
| 497 | if (tutorial) // Announce selectionphase |
---|
| 498 | { |
---|
| 499 | for (std::map<PlayerInfo*, int>::iterator it = this->playerParty_.begin(); it != this->playerParty_.end(); ++it) |
---|
| 500 | { |
---|
| 501 | if (!it->first)//in order to catch nullpointer |
---|
| 502 | continue; |
---|
| 503 | if (it->first->getClientID() == CLIENTID_UNKNOWN) |
---|
| 504 | continue; |
---|
[7062] | 505 | this->gtinfo_->sendStaticMessage("Selection phase: Shoot at everything that moves.",it->first->getClientID(),ColourValue(1.0f, 1.0f, 0.5f)); |
---|
[6921] | 506 | } |
---|
| 507 | } |
---|
| 508 | } |
---|
| 509 | else |
---|
| 510 | { |
---|
| 511 | notEnoughKillers=false; |
---|
| 512 | if(tutorial&&(!notEnoughPigs)&&(!notEnoughChasers)) //Selection phase over |
---|
| 513 | { |
---|
| 514 | for (std::map<PlayerInfo*, int>::iterator it = this->playerParty_.begin(); it != this->playerParty_.end(); ++it) |
---|
| 515 | { |
---|
| 516 | if (!it->first) |
---|
| 517 | continue; |
---|
| 518 | if (it->first->getClientID() == CLIENTID_UNKNOWN) |
---|
| 519 | continue; |
---|
| 520 | else if (it->second==chaser) |
---|
| 521 | { |
---|
| 522 | if (numberOf[killer]>0) |
---|
[7062] | 523 | this->gtinfo_->sendStaticMessage("Shoot at the victim as often as possible. Defend yourself against the killers.",it->first->getClientID(),partyColours_[piggy]); |
---|
[6921] | 524 | else |
---|
[7062] | 525 | this->gtinfo_->sendStaticMessage("Shoot at the victim as often as possible.",it->first->getClientID(),partyColours_[piggy]); |
---|
[6987] | 526 | //this->gtinfo_->sendFadingMessage("You're now a chaser.",it->first->getClientID()); |
---|
[6921] | 527 | } |
---|
| 528 | else if (it->second==piggy) |
---|
[6987] | 529 | { |
---|
[7062] | 530 | this->gtinfo_->sendStaticMessage("Either hide or shoot a chaser.",it->first->getClientID(),partyColours_[piggy]); |
---|
[6987] | 531 | //this->gtinfo_->sendFadingMessage("You're now a victim.",it->first->getClientID()); |
---|
| 532 | } |
---|
[6921] | 533 | else if (it->second==killer) |
---|
[6987] | 534 | { |
---|
[7062] | 535 | this->gtinfo_->sendStaticMessage("Take the chasers down.",it->first->getClientID(),partyColours_[piggy]); |
---|
[6987] | 536 | //this->gtinfo_->sendFadingMessage("You're now a killer.",it->first->getClientID()); |
---|
| 537 | } |
---|
[6921] | 538 | } |
---|
[7076] | 539 | |
---|
[6921] | 540 | } |
---|
[7076] | 541 | |
---|
[6921] | 542 | } |
---|
[6812] | 543 | //chasers: there are more chasers than killers + pigs |
---|
[6921] | 544 | if (numberOf[piggy]+numberOf[killer] > numberOf[chaser]) |
---|
| 545 | { |
---|
| 546 | notEnoughChasers=true; |
---|
| 547 | if (tutorial) // Announce selectionphase |
---|
| 548 | { |
---|
| 549 | for (std::map<PlayerInfo*, int>::iterator it = this->playerParty_.begin(); it != this->playerParty_.end(); ++it) |
---|
| 550 | { |
---|
| 551 | if (!it->first)//in order to catch nullpointer |
---|
| 552 | continue; |
---|
| 553 | if (it->first->getClientID() == CLIENTID_UNKNOWN) |
---|
| 554 | continue; |
---|
[7062] | 555 | this->gtinfo_->sendStaticMessage("Selection phase: Shoot at everything that moves.",it->first->getClientID(),ColourValue(1.0f, 1.0f, 0.5f)); |
---|
[6921] | 556 | } |
---|
| 557 | } |
---|
| 558 | } |
---|
| 559 | else |
---|
| 560 | { |
---|
| 561 | notEnoughChasers=false; |
---|
| 562 | if(tutorial&&(!notEnoughPigs)&&(!notEnoughKillers)) //Selection phase over |
---|
| 563 | { |
---|
| 564 | for (std::map<PlayerInfo*, int>::iterator it = this->playerParty_.begin(); it != this->playerParty_.end(); ++it) |
---|
| 565 | { |
---|
| 566 | if (!it->first) |
---|
| 567 | continue; |
---|
| 568 | if (it->first->getClientID() == CLIENTID_UNKNOWN) |
---|
| 569 | continue; |
---|
| 570 | else if (it->second==chaser) |
---|
| 571 | { |
---|
| 572 | if (numberOf[killer]>0) |
---|
[7062] | 573 | this->gtinfo_->sendStaticMessage("Shoot at the victim as often as possible. Defend yourself against the killers.",it->first->getClientID(),partyColours_[piggy]); |
---|
[6921] | 574 | else |
---|
[7062] | 575 | this->gtinfo_->sendStaticMessage("Shoot at the victim as often as possible.",it->first->getClientID(),partyColours_[piggy]); |
---|
[6987] | 576 | //this->gtinfo_->sendFadingMessage("You're now a chaser.",it->first->getClientID()); |
---|
[6921] | 577 | } |
---|
| 578 | else if (it->second==piggy) |
---|
[6987] | 579 | { |
---|
[7062] | 580 | this->gtinfo_->sendStaticMessage("Either hide or shoot a chaser.",it->first->getClientID(),partyColours_[chaser]); |
---|
[6987] | 581 | //this->gtinfo_->sendFadingMessage("You're now a victim.",it->first->getClientID()); |
---|
| 582 | } |
---|
[6921] | 583 | else if (it->second==killer) |
---|
[6987] | 584 | { |
---|
[7062] | 585 | this->gtinfo_->sendStaticMessage("Take the chasers down.",it->first->getClientID(),partyColours_[chaser]); |
---|
[6987] | 586 | //this->gtinfo_->sendFadingMessage("You're now a killer.",it->first->getClientID()); |
---|
| 587 | } |
---|
[6921] | 588 | } |
---|
[7076] | 589 | |
---|
[6921] | 590 | } |
---|
[7076] | 591 | } |
---|
[6812] | 592 | } |
---|
| 593 | |
---|
| 594 | int Dynamicmatch::getParty(PlayerInfo* player) // helper function for ArtificialController |
---|
| 595 | { |
---|
| 596 | return this->playerParty_[player]; |
---|
| 597 | } |
---|
| 598 | |
---|
| 599 | void Dynamicmatch::resetSpeedFactor(WeakPtr<Engine>* ptr)// helper function |
---|
| 600 | { |
---|
| 601 | if (*ptr) |
---|
| 602 | { |
---|
| 603 | (*ptr)->setSpeedFactor(1.0f); |
---|
| 604 | } |
---|
| 605 | delete ptr; |
---|
| 606 | } |
---|
| 607 | |
---|
| 608 | bool Dynamicmatch::playerChangedName(PlayerInfo* player) //standardfunction |
---|
| 609 | { |
---|
| 610 | bool valid_player = Gametype::playerChangedName(player); |
---|
| 611 | if (valid_player) |
---|
| 612 | { |
---|
| 613 | const std::string& message = player->getOldName() + " changed name to " + player->getName(); |
---|
| 614 | COUT(0) << message << std::endl; |
---|
| 615 | Host::Broadcast(message); |
---|
| 616 | } |
---|
| 617 | |
---|
| 618 | return valid_player; |
---|
| 619 | } |
---|
| 620 | |
---|
[7076] | 621 | void Dynamicmatch::start() |
---|
| 622 | { |
---|
[6812] | 623 | Gametype::start(); |
---|
| 624 | if(!tutorial) |
---|
| 625 | { |
---|
[6921] | 626 | std::string message("Dynamicmatch started!"); |
---|
[6812] | 627 | COUT(0) << message << std::endl; |
---|
| 628 | Host::Broadcast(message); |
---|
| 629 | } |
---|
[6921] | 630 | else if(tutorial) // Announce selectionphase |
---|
[6812] | 631 | { |
---|
[6921] | 632 | for (std::map<PlayerInfo*, int>::iterator it = this->playerParty_.begin(); it != this->playerParty_.end(); ++it) |
---|
| 633 | { |
---|
| 634 | if (it->first->getClientID() == CLIENTID_UNKNOWN) |
---|
| 635 | continue; |
---|
[7062] | 636 | this->gtinfo_->sendStaticMessage("Selection phase: Shoot at everything that moves.",it->first->getClientID(),ColourValue(1.0f, 1.0f, 0.5f)); |
---|
[6921] | 637 | } |
---|
[6812] | 638 | } |
---|
[7076] | 639 | } |
---|
[6812] | 640 | |
---|
[6921] | 641 | /*void Dynamicmatch::instructions() |
---|
[6812] | 642 | { |
---|
| 643 | std::string message("Earn points:\n\n\n\tIf you're red: Chase the blue player!\n\n\tIf you're blue shoot at a red player or hide.\n\n\tIf you're green: You've got the licence to kill red players!"); |
---|
| 644 | COUT(0) << message << std::endl; |
---|
| 645 | Host::Broadcast(message); |
---|
| 646 | callInstructions_.setTimer(10, false, createExecutor(createFunctor(&Dynamicmatch::furtherInstructions, this))); |
---|
| 647 | } |
---|
| 648 | |
---|
| 649 | void Dynamicmatch::furtherInstructions() |
---|
| 650 | { |
---|
| 651 | std::string message("After 3 Minutes the game is over."); |
---|
| 652 | COUT(0) << message << std::endl; |
---|
| 653 | Host::Broadcast(message); |
---|
[6921] | 654 | }*/ |
---|
[6812] | 655 | void Dynamicmatch::end() |
---|
| 656 | { |
---|
| 657 | Gametype::end(); |
---|
| 658 | |
---|
| 659 | std::string message("Time out. Press F2 to see the points you scored."); |
---|
| 660 | COUT(0) << message << std::endl; |
---|
| 661 | Host::Broadcast(message); |
---|
| 662 | } |
---|
[6848] | 663 | SpawnPoint* Dynamicmatch::getBestSpawnPoint(PlayerInfo* player) const |
---|
| 664 | { |
---|
| 665 | int desiredTeamNr = -1; |
---|
| 666 | std::map<PlayerInfo*, int>::const_iterator it_player = this->playerParty_.find(player); |
---|
| 667 | if (it_player != this->playerParty_.end()) |
---|
| 668 | desiredTeamNr = it_player->second; |
---|
[6812] | 669 | |
---|
[6848] | 670 | // Only use spawnpoints of the own team (or non-team-spawnpoints) |
---|
| 671 | std::set<SpawnPoint*> teamSpawnPoints = this->spawnpoints_; |
---|
| 672 | for (std::set<SpawnPoint*>::iterator it = teamSpawnPoints.begin(); it != teamSpawnPoints.end(); ) |
---|
| 673 | { |
---|
| 674 | if ((*it)->isA(Class(TeamSpawnPoint))) |
---|
| 675 | { |
---|
| 676 | TeamSpawnPoint* tsp = orxonox_cast<TeamSpawnPoint*>(*it); |
---|
| 677 | if (tsp && static_cast<int>(tsp->getTeamNumber()) != desiredTeamNr)//getTeamNumber!! |
---|
| 678 | { |
---|
| 679 | teamSpawnPoints.erase(it++); |
---|
| 680 | continue; |
---|
| 681 | } |
---|
| 682 | } |
---|
| 683 | |
---|
| 684 | ++it; |
---|
| 685 | } |
---|
| 686 | |
---|
| 687 | if (teamSpawnPoints.size() > 0) |
---|
| 688 | { |
---|
| 689 | unsigned int randomspawn = static_cast<unsigned int>(rnd(static_cast<float>(teamSpawnPoints.size()))); |
---|
| 690 | unsigned int index = 0; |
---|
| 691 | for (std::set<SpawnPoint*>::const_iterator it = teamSpawnPoints.begin(); it != teamSpawnPoints.end(); ++it) |
---|
| 692 | { |
---|
| 693 | if (index == randomspawn) |
---|
| 694 | return (*it); |
---|
| 695 | |
---|
| 696 | ++index; |
---|
| 697 | } |
---|
| 698 | } |
---|
| 699 | |
---|
| 700 | return 0; |
---|
| 701 | } |
---|
| 702 | |
---|
[6586] | 703 | } |
---|