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