[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 | |
---|
[9348] | 33 | /** |
---|
| 34 | @brief |
---|
| 35 | Short Gaming Manual: |
---|
| 36 | There are three different parties a player can belong to: victim, chaser or killer |
---|
| 37 | 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. |
---|
| 38 | In order to win you have to earn as much points as possible: |
---|
| 39 | - as victim by escaping the chasers |
---|
| 40 | - as chaser by shooting the victim |
---|
| 41 | - as killer by killing the chasers |
---|
[6812] | 42 | |
---|
| 43 | |
---|
[9348] | 44 | What you shouldn't do is shooting at players of your own party. By doing so your score will decrease. |
---|
| 45 | P.S: If you don't want to be a victim: Get rid of your part by shooting a chaser. |
---|
[6812] | 46 | */ |
---|
[6586] | 47 | #include "Dynamicmatch.h" |
---|
| 48 | |
---|
[6686] | 49 | #include "util/Convert.h" |
---|
[6586] | 50 | #include "core/CoreIncludes.h" |
---|
[8729] | 51 | #include "core/command/Executor.h" |
---|
[8858] | 52 | #include "chat/ChatManager.h" |
---|
[6586] | 53 | #include "infos/PlayerInfo.h" |
---|
| 54 | #include "worldentities/pawns/Pawn.h" |
---|
[6697] | 55 | #include "worldentities/pawns/SpaceShip.h" |
---|
[9667] | 56 | #include "core/config/ConfigValueIncludes.h" |
---|
[6686] | 57 | #include "interfaces/TeamColourable.h" |
---|
[6697] | 58 | #include "items/Engine.h" |
---|
| 59 | #include "tools/Timer.h" |
---|
[6848] | 60 | #include "worldentities/TeamSpawnPoint.h" |
---|
[6697] | 61 | |
---|
[6586] | 62 | namespace orxonox |
---|
| 63 | { |
---|
[9667] | 64 | RegisterUnloadableClass(Dynamicmatch); |
---|
[6586] | 65 | |
---|
[9667] | 66 | Dynamicmatch::Dynamicmatch(Context* context) : Gametype(context) |
---|
[6586] | 67 | { |
---|
| 68 | RegisterObject(Dynamicmatch); |
---|
[6812] | 69 | this->gameTime_ = 180; |
---|
| 70 | this->setConfigValues(); |
---|
[6686] | 71 | this->chaser=0; |
---|
[6812] | 72 | this->piggy=1; |
---|
| 73 | this->killer=2; |
---|
| 74 | this->notEnoughPigs=false; |
---|
| 75 | this->notEnoughKillers=false; |
---|
| 76 | this->notEnoughChasers=false; |
---|
| 77 | this->gameEnded_ =false; |
---|
| 78 | this->timesequence_ = static_cast<int>(this->gameTime_); |
---|
| 79 | this->friendlyfire=true; |
---|
| 80 | this->numberOf[chaser]=0; |
---|
| 81 | this->numberOf[piggy]=0; |
---|
| 82 | this->numberOf[killer]=0; |
---|
| 83 | this->tutorial=true; |
---|
[9348] | 84 | this->pointsPerTime=1.0f; |
---|
[6921] | 85 | this->setHUDTemplate("DynamicmatchHUD"); |
---|
[6586] | 86 | } |
---|
| 87 | |
---|
[6697] | 88 | void Dynamicmatch::setConfigValues() |
---|
| 89 | { |
---|
[6812] | 90 | SetConfigValue(gameTime_, 180); |
---|
| 91 | SetConfigValue(friendlyfire, true); |
---|
| 92 | SetConfigValue(tutorial, true); |
---|
| 93 | static ColourValue colours[] = |
---|
[6697] | 94 | { |
---|
[7076] | 95 | ColourValue(1.0f, 0.3f, 0.3f), //chasercolour |
---|
| 96 | ColourValue(0.3f, 0.3f, 1.0f), //piggycolour |
---|
| 97 | ColourValue(0.3f, 1.0f, 0.3f) //killercolour what about black: 0.0f, 0.0f, 0.0f |
---|
[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 | { |
---|
[9348] | 113 | int target = playerParty_[victim->getPlayer()]; |
---|
| 114 | int source = playerParty_[originator->getPlayer()]; |
---|
[6812] | 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 |
---|
[9348] | 153 | SpaceShip* spaceship = orxonox_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 |
---|
[9348] | 247 | SpaceShip* spaceship = orxonox_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 | { |
---|
[9945] | 278 | this->playerScored(originator->getPlayer(), -1); |
---|
[6812] | 279 | } |
---|
[9348] | 280 | } |
---|
[6812] | 281 | return false; //default: no damage |
---|
[6686] | 282 | } |
---|
[6586] | 283 | |
---|
[6686] | 284 | |
---|
| 285 | |
---|
[6812] | 286 | bool Dynamicmatch::allowPawnDeath(Pawn* victim, Pawn* originator) |
---|
[7076] | 287 | { |
---|
[6812] | 288 | //killers can kill chasers and killers can be killed by chasers |
---|
| 289 | if ((playerParty_[originator->getPlayer()] == killer && playerParty_[victim->getPlayer()] == chaser)||(playerParty_[victim->getPlayer()] == killer && |
---|
| 290 | playerParty_[originator->getPlayer()] == chaser )) |
---|
| 291 | { |
---|
[7076] | 292 | if (playerParty_[originator->getPlayer()] == killer) //reward the killer |
---|
[6812] | 293 | { |
---|
[9945] | 294 | this->playerScored(originator->getPlayer(), 25); |
---|
[6812] | 295 | } |
---|
[9348] | 296 | return true; |
---|
[6812] | 297 | } |
---|
| 298 | else return false; |
---|
[6586] | 299 | } |
---|
[7076] | 300 | |
---|
[8727] | 301 | /** |
---|
| 302 | @brief |
---|
[9348] | 303 | Grant the victim a boost. |
---|
[8727] | 304 | @param spaceship |
---|
| 305 | The SpaceShip to give the boost. |
---|
| 306 | */ |
---|
| 307 | void Dynamicmatch::grantPigBoost(SpaceShip* spaceship) |
---|
[8706] | 308 | { |
---|
[9348] | 309 | // Give victim boost |
---|
[8706] | 310 | if (spaceship) |
---|
| 311 | { |
---|
[9348] | 312 | WeakPtr<SpaceShip>* ptr = new WeakPtr<SpaceShip>(spaceship); |
---|
| 313 | if(ptr == NULL) |
---|
| 314 | return; |
---|
[8727] | 315 | spaceship->addSpeedFactor(5); |
---|
[8706] | 316 | ExecutorPtr executor = createExecutor(createFunctor(&Dynamicmatch::resetSpeedFactor, this)); |
---|
| 317 | executor->setDefaultValue(0, ptr); |
---|
| 318 | new Timer(10, false, executor, true); |
---|
| 319 | } |
---|
| 320 | } |
---|
| 321 | |
---|
[6812] | 322 | void Dynamicmatch::playerStartsControllingPawn(PlayerInfo* player, Pawn* pawn) //set party + colouring |
---|
[6586] | 323 | { |
---|
[6686] | 324 | if (!player) |
---|
| 325 | return; |
---|
[7076] | 326 | |
---|
| 327 | Dynamicmatch::setPlayerColour(player); //Set playercolour |
---|
[6812] | 328 | evaluatePlayerParties(); |
---|
[6686] | 329 | } |
---|
| 330 | |
---|
[6692] | 331 | void Dynamicmatch::playerEntered(PlayerInfo* player) //standardfunction |
---|
[6686] | 332 | { |
---|
[6812] | 333 | if (!player)// only for safety |
---|
[6686] | 334 | return; |
---|
[7076] | 335 | playerParty_[player]=chaser; //Set playerparty |
---|
[6848] | 336 | numberOf[chaser]++; |
---|
[6586] | 337 | Gametype::playerEntered(player); |
---|
[8858] | 338 | const std::string& message = player->getName() + " entered the game"; |
---|
| 339 | ChatManager::message(message); |
---|
[6586] | 340 | } |
---|
| 341 | |
---|
[6686] | 342 | bool Dynamicmatch::playerLeft(PlayerInfo* player) //standardfunction |
---|
[6586] | 343 | { |
---|
| 344 | bool valid_player = Gametype::playerLeft(player); |
---|
| 345 | if (valid_player) |
---|
| 346 | { |
---|
[6812] | 347 | switch (playerParty_[player]) |
---|
| 348 | { |
---|
| 349 | case 0: numberOf[chaser]--; break; |
---|
| 350 | case 1: numberOf[piggy]--; break; |
---|
| 351 | case 2: numberOf[killer]--; break; |
---|
| 352 | } |
---|
[6586] | 353 | const std::string& message = player->getName() + " left the game"; |
---|
[8858] | 354 | ChatManager::message(message); |
---|
[7076] | 355 | //remove player from map |
---|
[6812] | 356 | playerParty_.erase (player); |
---|
[7076] | 357 | //adjust player parties |
---|
[6812] | 358 | evaluatePlayerParties(); |
---|
[6586] | 359 | } |
---|
| 360 | |
---|
| 361 | return valid_player; |
---|
| 362 | } |
---|
| 363 | |
---|
| 364 | |
---|
[6812] | 365 | void Dynamicmatch::tick(float dt) |
---|
[6586] | 366 | { |
---|
[6848] | 367 | SUPER(Dynamicmatch, tick, dt); |
---|
[6686] | 368 | |
---|
| 369 | if (this->hasStarted() && !gameEnded_) |
---|
[9348] | 370 | { |
---|
| 371 | pointsPerTime = pointsPerTime + dt; //increase points |
---|
| 372 | gameTime_ = gameTime_ - dt; // decrease game time |
---|
| 373 | if (pointsPerTime > 2.0f) //hard coded points for victim! should be changed |
---|
[6812] | 374 | { |
---|
[9348] | 375 | pointsPerTime = 0.0f; |
---|
[6921] | 376 | rewardPig(); |
---|
[6812] | 377 | } |
---|
[6686] | 378 | if (gameTime_<= 0) |
---|
[6586] | 379 | { |
---|
[6686] | 380 | this->gameEnded_ = true; |
---|
[7076] | 381 | this->end(); |
---|
[6586] | 382 | } |
---|
[7076] | 383 | if ( gameTime_ <= timesequence_ && gameTime_ > 0) |
---|
[6686] | 384 | { |
---|
| 385 | const std::string& message = multi_cast<std::string>(timesequence_) + " seconds left!"; |
---|
[6586] | 386 | |
---|
[6686] | 387 | this->gtinfo_->sendAnnounceMessage(message); |
---|
[6586] | 388 | |
---|
[6686] | 389 | if (timesequence_ >= 30 && timesequence_ <= 60) |
---|
| 390 | { |
---|
| 391 | timesequence_ = timesequence_ - 10; |
---|
| 392 | } |
---|
| 393 | else if (timesequence_ <= 30) |
---|
| 394 | { |
---|
| 395 | timesequence_ = timesequence_ - 5; |
---|
| 396 | } |
---|
| 397 | else |
---|
| 398 | { |
---|
| 399 | timesequence_ = timesequence_ - 30; |
---|
| 400 | } |
---|
| 401 | } |
---|
[7076] | 402 | } |
---|
[6586] | 403 | } |
---|
[6812] | 404 | |
---|
[9348] | 405 | /** |
---|
| 406 | @brief The reward function is called every 2 seconds via the tick function and makes the victim score points. |
---|
| 407 | */ |
---|
[6812] | 408 | void Dynamicmatch::rewardPig() |
---|
| 409 | { |
---|
[6921] | 410 | for (std::map< PlayerInfo*, int >::iterator it = this->playerParty_.begin(); it != this->playerParty_.end(); ++it) //durch alle Spieler iterieren und alle piggys finden |
---|
| 411 | { |
---|
[9348] | 412 | if (it->second==piggy)//Spieler mit der Pig-party frags++ |
---|
[6921] | 413 | { |
---|
[9945] | 414 | this->playerScored(it->first); |
---|
[6921] | 415 | } |
---|
| 416 | } |
---|
[6812] | 417 | } |
---|
[7062] | 418 | void Dynamicmatch::setPlayerColour(PlayerInfo* player) // sets a player's colour |
---|
[6812] | 419 | { |
---|
| 420 | std::map<PlayerInfo*, int>::const_iterator it_player = this->playerParty_.find(player); |
---|
[9348] | 421 | Pawn* pawn = orxonox_cast<Pawn*>(player->getControllableEntity()); |
---|
[6812] | 422 | if (pawn) |
---|
| 423 | { |
---|
[6921] | 424 | pawn->setRadarObjectColour(this->partyColours_[it_player->second]); |
---|
[6812] | 425 | |
---|
| 426 | std::set<WorldEntity*> pawnAttachments = pawn->getAttachedObjects(); |
---|
| 427 | for (std::set<WorldEntity*>::iterator it = pawnAttachments.begin(); it != pawnAttachments.end(); ++it) |
---|
| 428 | { |
---|
| 429 | if ((*it)->isA(Class(TeamColourable))) |
---|
| 430 | { |
---|
| 431 | TeamColourable* tc = orxonox_cast<TeamColourable*>(*it); |
---|
| 432 | tc->setTeamColour(this->partyColours_[it_player->second]); |
---|
| 433 | } |
---|
| 434 | } |
---|
| 435 | } |
---|
[7076] | 436 | } |
---|
[6812] | 437 | |
---|
| 438 | void Dynamicmatch::evaluatePlayerParties() //manages the notEnough booleans (here the percentage of special players is implemented) |
---|
| 439 | { |
---|
| 440 | //pigs: 1 + every 6th player is a pig |
---|
[9348] | 441 | if ( (1 + getPlayerCount()/6) > numberOf[piggy]) |
---|
[6921] | 442 | { |
---|
| 443 | notEnoughPigs=true; |
---|
| 444 | if (tutorial) // Announce selectionphase |
---|
| 445 | { |
---|
| 446 | for (std::map<PlayerInfo*, int>::iterator it = this->playerParty_.begin(); it != this->playerParty_.end(); ++it) |
---|
| 447 | { |
---|
| 448 | if (!it->first)//in order to catch nullpointer |
---|
| 449 | continue; |
---|
[8327] | 450 | if (it->first->getClientID() == NETWORK_PEER_ID_UNKNOWN) |
---|
[6921] | 451 | continue; |
---|
[7062] | 452 | this->gtinfo_->sendStaticMessage("Selection phase: Shoot at everything that moves.",it->first->getClientID(),ColourValue(1.0f, 1.0f, 0.5f)); |
---|
[6921] | 453 | } |
---|
| 454 | } |
---|
| 455 | } |
---|
| 456 | else |
---|
| 457 | { |
---|
| 458 | notEnoughPigs=false; |
---|
| 459 | if(tutorial&&(!notEnoughKillers)&&(!notEnoughChasers)) //Selection phase over |
---|
| 460 | { |
---|
| 461 | for (std::map<PlayerInfo*, int>::iterator it = this->playerParty_.begin(); it != this->playerParty_.end(); ++it) |
---|
| 462 | { |
---|
| 463 | if (!it->first)//in order to catch nullpointer |
---|
| 464 | continue; |
---|
[8327] | 465 | if (it->first->getClientID() == NETWORK_PEER_ID_UNKNOWN) |
---|
[6921] | 466 | continue; |
---|
| 467 | else if (it->second==chaser) |
---|
| 468 | { |
---|
| 469 | if (numberOf[killer]>0) |
---|
[7062] | 470 | this->gtinfo_->sendStaticMessage("Shoot at the victim as often as possible. Defend yourself against the killers.",it->first->getClientID(),partyColours_[piggy]); |
---|
[6921] | 471 | else |
---|
[7062] | 472 | this->gtinfo_->sendStaticMessage("Shoot at the victim as often as possible.",it->first->getClientID(),partyColours_[piggy]); |
---|
[6987] | 473 | //this->gtinfo_->sendFadingMessage("You're now a chaser.",it->first->getClientID()); |
---|
[6921] | 474 | } |
---|
| 475 | else if (it->second==piggy) |
---|
[6987] | 476 | { |
---|
[7062] | 477 | this->gtinfo_->sendStaticMessage("Either hide or shoot a chaser.",it->first->getClientID(),partyColours_[chaser]); |
---|
[6987] | 478 | //this->gtinfo_->sendFadingMessage("You're now a victim.",it->first->getClientID()); |
---|
| 479 | } |
---|
[6921] | 480 | else if (it->second==killer) |
---|
[6987] | 481 | { |
---|
[7062] | 482 | this->gtinfo_->sendStaticMessage("Take the chasers down.",it->first->getClientID(),partyColours_[chaser]); |
---|
[6987] | 483 | //this->gtinfo_->sendFadingMessage("You're now a killer.",it->first->getClientID()); |
---|
| 484 | } |
---|
[6921] | 485 | } |
---|
[7076] | 486 | |
---|
[6921] | 487 | } |
---|
| 488 | } |
---|
[6812] | 489 | //killers: every 4th player is a killer |
---|
[9348] | 490 | if ( static_cast<unsigned int>(getPlayerCount()/4) > numberOf[killer]) |
---|
[6921] | 491 | { |
---|
| 492 | notEnoughKillers=true; |
---|
| 493 | if (tutorial) // Announce selectionphase |
---|
| 494 | { |
---|
| 495 | for (std::map<PlayerInfo*, int>::iterator it = this->playerParty_.begin(); it != this->playerParty_.end(); ++it) |
---|
| 496 | { |
---|
| 497 | if (!it->first)//in order to catch nullpointer |
---|
| 498 | continue; |
---|
[8327] | 499 | if (it->first->getClientID() == NETWORK_PEER_ID_UNKNOWN) |
---|
[6921] | 500 | continue; |
---|
[7062] | 501 | this->gtinfo_->sendStaticMessage("Selection phase: Shoot at everything that moves.",it->first->getClientID(),ColourValue(1.0f, 1.0f, 0.5f)); |
---|
[6921] | 502 | } |
---|
| 503 | } |
---|
| 504 | } |
---|
| 505 | else |
---|
| 506 | { |
---|
| 507 | notEnoughKillers=false; |
---|
| 508 | if(tutorial&&(!notEnoughPigs)&&(!notEnoughChasers)) //Selection phase over |
---|
| 509 | { |
---|
| 510 | for (std::map<PlayerInfo*, int>::iterator it = this->playerParty_.begin(); it != this->playerParty_.end(); ++it) |
---|
| 511 | { |
---|
| 512 | if (!it->first) |
---|
| 513 | continue; |
---|
[8327] | 514 | if (it->first->getClientID() == NETWORK_PEER_ID_UNKNOWN) |
---|
[6921] | 515 | continue; |
---|
| 516 | else if (it->second==chaser) |
---|
| 517 | { |
---|
| 518 | if (numberOf[killer]>0) |
---|
[7062] | 519 | this->gtinfo_->sendStaticMessage("Shoot at the victim as often as possible. Defend yourself against the killers.",it->first->getClientID(),partyColours_[piggy]); |
---|
[6921] | 520 | else |
---|
[7062] | 521 | this->gtinfo_->sendStaticMessage("Shoot at the victim as often as possible.",it->first->getClientID(),partyColours_[piggy]); |
---|
[6987] | 522 | //this->gtinfo_->sendFadingMessage("You're now a chaser.",it->first->getClientID()); |
---|
[6921] | 523 | } |
---|
| 524 | else if (it->second==piggy) |
---|
[6987] | 525 | { |
---|
[7062] | 526 | this->gtinfo_->sendStaticMessage("Either hide or shoot a chaser.",it->first->getClientID(),partyColours_[piggy]); |
---|
[6987] | 527 | //this->gtinfo_->sendFadingMessage("You're now a victim.",it->first->getClientID()); |
---|
| 528 | } |
---|
[6921] | 529 | else if (it->second==killer) |
---|
[6987] | 530 | { |
---|
[7062] | 531 | this->gtinfo_->sendStaticMessage("Take the chasers down.",it->first->getClientID(),partyColours_[piggy]); |
---|
[6987] | 532 | //this->gtinfo_->sendFadingMessage("You're now a killer.",it->first->getClientID()); |
---|
| 533 | } |
---|
[6921] | 534 | } |
---|
[7076] | 535 | |
---|
[6921] | 536 | } |
---|
[7076] | 537 | |
---|
[6921] | 538 | } |
---|
[6812] | 539 | //chasers: there are more chasers than killers + pigs |
---|
[6921] | 540 | if (numberOf[piggy]+numberOf[killer] > numberOf[chaser]) |
---|
| 541 | { |
---|
| 542 | notEnoughChasers=true; |
---|
| 543 | if (tutorial) // Announce selectionphase |
---|
| 544 | { |
---|
| 545 | for (std::map<PlayerInfo*, int>::iterator it = this->playerParty_.begin(); it != this->playerParty_.end(); ++it) |
---|
| 546 | { |
---|
| 547 | if (!it->first)//in order to catch nullpointer |
---|
| 548 | continue; |
---|
[8327] | 549 | if (it->first->getClientID() == NETWORK_PEER_ID_UNKNOWN) |
---|
[6921] | 550 | continue; |
---|
[7062] | 551 | this->gtinfo_->sendStaticMessage("Selection phase: Shoot at everything that moves.",it->first->getClientID(),ColourValue(1.0f, 1.0f, 0.5f)); |
---|
[6921] | 552 | } |
---|
| 553 | } |
---|
| 554 | } |
---|
| 555 | else |
---|
| 556 | { |
---|
| 557 | notEnoughChasers=false; |
---|
| 558 | if(tutorial&&(!notEnoughPigs)&&(!notEnoughKillers)) //Selection phase over |
---|
| 559 | { |
---|
| 560 | for (std::map<PlayerInfo*, int>::iterator it = this->playerParty_.begin(); it != this->playerParty_.end(); ++it) |
---|
| 561 | { |
---|
| 562 | if (!it->first) |
---|
| 563 | continue; |
---|
[8327] | 564 | if (it->first->getClientID() == NETWORK_PEER_ID_UNKNOWN) |
---|
[6921] | 565 | continue; |
---|
| 566 | else if (it->second==chaser) |
---|
| 567 | { |
---|
| 568 | if (numberOf[killer]>0) |
---|
[7062] | 569 | this->gtinfo_->sendStaticMessage("Shoot at the victim as often as possible. Defend yourself against the killers.",it->first->getClientID(),partyColours_[piggy]); |
---|
[6921] | 570 | else |
---|
[7062] | 571 | this->gtinfo_->sendStaticMessage("Shoot at the victim as often as possible.",it->first->getClientID(),partyColours_[piggy]); |
---|
[6987] | 572 | //this->gtinfo_->sendFadingMessage("You're now a chaser.",it->first->getClientID()); |
---|
[6921] | 573 | } |
---|
| 574 | else if (it->second==piggy) |
---|
[6987] | 575 | { |
---|
[7062] | 576 | this->gtinfo_->sendStaticMessage("Either hide or shoot a chaser.",it->first->getClientID(),partyColours_[chaser]); |
---|
[6987] | 577 | //this->gtinfo_->sendFadingMessage("You're now a victim.",it->first->getClientID()); |
---|
| 578 | } |
---|
[6921] | 579 | else if (it->second==killer) |
---|
[6987] | 580 | { |
---|
[7062] | 581 | this->gtinfo_->sendStaticMessage("Take the chasers down.",it->first->getClientID(),partyColours_[chaser]); |
---|
[6987] | 582 | //this->gtinfo_->sendFadingMessage("You're now a killer.",it->first->getClientID()); |
---|
| 583 | } |
---|
[6921] | 584 | } |
---|
[7076] | 585 | |
---|
[6921] | 586 | } |
---|
[7076] | 587 | } |
---|
[6812] | 588 | } |
---|
| 589 | |
---|
| 590 | int Dynamicmatch::getParty(PlayerInfo* player) // helper function for ArtificialController |
---|
| 591 | { |
---|
| 592 | return this->playerParty_[player]; |
---|
| 593 | } |
---|
| 594 | |
---|
[8706] | 595 | void Dynamicmatch::resetSpeedFactor(WeakPtr<SpaceShip>* ptr)// helper function |
---|
[6812] | 596 | { |
---|
| 597 | if (*ptr) |
---|
| 598 | { |
---|
[8727] | 599 | (*ptr)->addSpeedFactor(1.0f/5.0f); |
---|
[6812] | 600 | } |
---|
| 601 | delete ptr; |
---|
| 602 | } |
---|
| 603 | |
---|
| 604 | bool Dynamicmatch::playerChangedName(PlayerInfo* player) //standardfunction |
---|
| 605 | { |
---|
| 606 | bool valid_player = Gametype::playerChangedName(player); |
---|
| 607 | if (valid_player) |
---|
| 608 | { |
---|
| 609 | const std::string& message = player->getOldName() + " changed name to " + player->getName(); |
---|
[8858] | 610 | ChatManager::message(message); |
---|
[6812] | 611 | } |
---|
| 612 | |
---|
| 613 | return valid_player; |
---|
| 614 | } |
---|
| 615 | |
---|
[7076] | 616 | void Dynamicmatch::start() |
---|
| 617 | { |
---|
[6812] | 618 | Gametype::start(); |
---|
| 619 | if(!tutorial) |
---|
| 620 | { |
---|
[6921] | 621 | std::string message("Dynamicmatch started!"); |
---|
[8858] | 622 | ChatManager::message(message); |
---|
[6812] | 623 | } |
---|
[6921] | 624 | else if(tutorial) // Announce selectionphase |
---|
[6812] | 625 | { |
---|
[6921] | 626 | for (std::map<PlayerInfo*, int>::iterator it = this->playerParty_.begin(); it != this->playerParty_.end(); ++it) |
---|
| 627 | { |
---|
[8327] | 628 | if (it->first->getClientID() == NETWORK_PEER_ID_UNKNOWN) |
---|
[6921] | 629 | continue; |
---|
[7062] | 630 | this->gtinfo_->sendStaticMessage("Selection phase: Shoot at everything that moves.",it->first->getClientID(),ColourValue(1.0f, 1.0f, 0.5f)); |
---|
[6921] | 631 | } |
---|
[6812] | 632 | } |
---|
[7076] | 633 | } |
---|
[6812] | 634 | |
---|
[6921] | 635 | /*void Dynamicmatch::instructions() |
---|
[6812] | 636 | { |
---|
| 637 | 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] | 638 | ChatManager::message(message); |
---|
[6812] | 639 | callInstructions_.setTimer(10, false, createExecutor(createFunctor(&Dynamicmatch::furtherInstructions, this))); |
---|
| 640 | } |
---|
| 641 | |
---|
| 642 | void Dynamicmatch::furtherInstructions() |
---|
| 643 | { |
---|
| 644 | std::string message("After 3 Minutes the game is over."); |
---|
[8858] | 645 | ChatManager::message(message); |
---|
[6921] | 646 | }*/ |
---|
[6812] | 647 | void Dynamicmatch::end() |
---|
| 648 | { |
---|
| 649 | Gametype::end(); |
---|
| 650 | |
---|
| 651 | std::string message("Time out. Press F2 to see the points you scored."); |
---|
[8858] | 652 | ChatManager::message(message); |
---|
[6812] | 653 | } |
---|
[6848] | 654 | SpawnPoint* Dynamicmatch::getBestSpawnPoint(PlayerInfo* player) const |
---|
| 655 | { |
---|
| 656 | int desiredTeamNr = -1; |
---|
| 657 | std::map<PlayerInfo*, int>::const_iterator it_player = this->playerParty_.find(player); |
---|
| 658 | if (it_player != this->playerParty_.end()) |
---|
| 659 | desiredTeamNr = it_player->second; |
---|
[6812] | 660 | |
---|
[6848] | 661 | // Only use spawnpoints of the own team (or non-team-spawnpoints) |
---|
| 662 | std::set<SpawnPoint*> teamSpawnPoints = this->spawnpoints_; |
---|
| 663 | for (std::set<SpawnPoint*>::iterator it = teamSpawnPoints.begin(); it != teamSpawnPoints.end(); ) |
---|
| 664 | { |
---|
| 665 | if ((*it)->isA(Class(TeamSpawnPoint))) |
---|
| 666 | { |
---|
| 667 | TeamSpawnPoint* tsp = orxonox_cast<TeamSpawnPoint*>(*it); |
---|
| 668 | if (tsp && static_cast<int>(tsp->getTeamNumber()) != desiredTeamNr)//getTeamNumber!! |
---|
| 669 | { |
---|
| 670 | teamSpawnPoints.erase(it++); |
---|
| 671 | continue; |
---|
| 672 | } |
---|
| 673 | } |
---|
| 674 | |
---|
| 675 | ++it; |
---|
| 676 | } |
---|
| 677 | |
---|
| 678 | if (teamSpawnPoints.size() > 0) |
---|
| 679 | { |
---|
| 680 | unsigned int randomspawn = static_cast<unsigned int>(rnd(static_cast<float>(teamSpawnPoints.size()))); |
---|
| 681 | unsigned int index = 0; |
---|
| 682 | for (std::set<SpawnPoint*>::const_iterator it = teamSpawnPoints.begin(); it != teamSpawnPoints.end(); ++it) |
---|
| 683 | { |
---|
| 684 | if (index == randomspawn) |
---|
| 685 | return (*it); |
---|
| 686 | |
---|
| 687 | ++index; |
---|
| 688 | } |
---|
| 689 | } |
---|
| 690 | |
---|
| 691 | return 0; |
---|
| 692 | } |
---|
| 693 | |
---|
[6586] | 694 | } |
---|