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