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