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