[2072] | 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 | * Fabian 'x3n' Landau |
---|
| 24 | * Co-authors: |
---|
| 25 | * ... |
---|
| 26 | * |
---|
| 27 | */ |
---|
| 28 | |
---|
| 29 | #include "Gametype.h" |
---|
| 30 | |
---|
[3196] | 31 | #include "util/Math.h" |
---|
[8079] | 32 | #include "core/Core.h" |
---|
[2072] | 33 | #include "core/CoreIncludes.h" |
---|
[9667] | 34 | #include "core/config/ConfigValueIncludes.h" |
---|
[2896] | 35 | #include "core/GameMode.h" |
---|
[7284] | 36 | #include "core/command/ConsoleCommand.h" |
---|
[9977] | 37 | #include "gamestates/GSLevel.h" |
---|
[3196] | 38 | |
---|
[5735] | 39 | #include "infos/PlayerInfo.h" |
---|
| 40 | #include "infos/Bot.h" |
---|
[5737] | 41 | #include "graphics/Camera.h" |
---|
[5735] | 42 | #include "worldentities/ControllableEntity.h" |
---|
| 43 | #include "worldentities/SpawnPoint.h" |
---|
| 44 | #include "worldentities/pawns/Spectator.h" |
---|
| 45 | #include "worldentities/pawns/Pawn.h" |
---|
[3196] | 46 | #include "overlays/OverlayGroup.h" |
---|
[2072] | 47 | |
---|
| 48 | namespace orxonox |
---|
| 49 | { |
---|
[9667] | 50 | RegisterUnloadableClass(Gametype); |
---|
[2072] | 51 | |
---|
[9667] | 52 | Gametype::Gametype(Context* context) : BaseObject(context) |
---|
[2072] | 53 | { |
---|
| 54 | RegisterObject(Gametype); |
---|
[6417] | 55 | |
---|
[9667] | 56 | this->gtinfo_ = new GametypeInfo(context); |
---|
[2072] | 57 | |
---|
[5929] | 58 | this->setGametype(SmartPtr<Gametype>(this, false)); |
---|
[2662] | 59 | |
---|
[2072] | 60 | this->defaultControllableEntity_ = Class(Spectator); |
---|
| 61 | |
---|
| 62 | this->bAutoStart_ = false; |
---|
| 63 | this->bForceSpawn_ = false; |
---|
[9977] | 64 | this->bAutoEnd_ = true; |
---|
[2662] | 65 | this->numberOfBots_ = 0; |
---|
[2072] | 66 | |
---|
[3033] | 67 | this->timeLimit_ = 0; |
---|
| 68 | this->time_ = 0; |
---|
| 69 | this->timerIsActive_ = false; |
---|
| 70 | |
---|
[2072] | 71 | this->initialStartCountdown_ = 3; |
---|
[2662] | 72 | |
---|
| 73 | this->setConfigValues(); |
---|
| 74 | |
---|
| 75 | // load the corresponding score board |
---|
[6417] | 76 | if (GameMode::showsGraphics() && !this->scoreboardTemplate_.empty()) |
---|
[2662] | 77 | { |
---|
[9667] | 78 | this->scoreboard_ = new OverlayGroup(context); |
---|
[2662] | 79 | this->scoreboard_->addTemplate(this->scoreboardTemplate_); |
---|
| 80 | this->scoreboard_->setGametype(this); |
---|
| 81 | } |
---|
| 82 | else |
---|
| 83 | this->scoreboard_ = 0; |
---|
[7801] | 84 | |
---|
| 85 | /* HACK HACK HACK */ |
---|
| 86 | this->dedicatedAddBots_ = createConsoleCommand( "dedicatedAddBots", createExecutor( createFunctor(&Gametype::addBots, this) ) ); |
---|
| 87 | this->dedicatedKillBots_ = createConsoleCommand( "dedicatedKillBots", createExecutor( createFunctor(&Gametype::killBots, this) ) ); |
---|
| 88 | /* HACK HACK HACK */ |
---|
[2072] | 89 | } |
---|
[6417] | 90 | |
---|
[5929] | 91 | Gametype::~Gametype() |
---|
| 92 | { |
---|
| 93 | if (this->isInitialized()) |
---|
| 94 | { |
---|
| 95 | this->gtinfo_->destroy(); |
---|
[7801] | 96 | if( this->dedicatedAddBots_ ) |
---|
| 97 | delete this->dedicatedAddBots_; |
---|
| 98 | if( this->dedicatedKillBots_ ) |
---|
| 99 | delete this->dedicatedKillBots_; |
---|
[5929] | 100 | } |
---|
| 101 | } |
---|
[2072] | 102 | |
---|
[2662] | 103 | void Gametype::setConfigValues() |
---|
| 104 | { |
---|
| 105 | SetConfigValue(initialStartCountdown_, 3.0f); |
---|
| 106 | SetConfigValue(bAutoStart_, false); |
---|
| 107 | SetConfigValue(bForceSpawn_, false); |
---|
[9977] | 108 | SetConfigValue(bAutoEnd_, true); |
---|
[2662] | 109 | SetConfigValue(numberOfBots_, 0); |
---|
| 110 | SetConfigValue(scoreboardTemplate_, "defaultScoreboard"); |
---|
| 111 | } |
---|
| 112 | |
---|
[2072] | 113 | void Gametype::tick(float dt) |
---|
| 114 | { |
---|
[2662] | 115 | SUPER(Gametype, tick, dt); |
---|
[2072] | 116 | |
---|
[3033] | 117 | //count timer |
---|
| 118 | if (timerIsActive_) |
---|
| 119 | { |
---|
| 120 | if (this->timeLimit_ == 0) |
---|
| 121 | this->time_ += dt; |
---|
| 122 | else |
---|
| 123 | this->time_ -= dt; |
---|
| 124 | } |
---|
| 125 | |
---|
[8706] | 126 | if (this->gtinfo_->isStartCountdownRunning() && !this->gtinfo_->hasStarted()) |
---|
| 127 | this->gtinfo_->countdownStartCountdown(dt); |
---|
[9260] | 128 | |
---|
[8706] | 129 | if (!this->gtinfo_->hasStarted()) |
---|
| 130 | { |
---|
| 131 | for (std::map<PlayerInfo*, Player>::iterator it = this->players_.begin(); it != this->players_.end(); ++it) |
---|
| 132 | { |
---|
| 133 | // Inform the GametypeInfo that the player is ready to spawn. |
---|
| 134 | if(it->first->isHumanPlayer() && it->first->isReadyToSpawn()) |
---|
| 135 | this->gtinfo_->playerReadyToSpawn(it->first); |
---|
| 136 | } |
---|
[9260] | 137 | |
---|
[2072] | 138 | this->checkStart(); |
---|
[8706] | 139 | } |
---|
| 140 | else if (!this->gtinfo_->hasEnded()) |
---|
[2171] | 141 | this->spawnDeadPlayersIfRequested(); |
---|
[2072] | 142 | |
---|
| 143 | this->assignDefaultPawnsIfNeeded(); |
---|
| 144 | } |
---|
| 145 | |
---|
| 146 | void Gametype::start() |
---|
| 147 | { |
---|
[2826] | 148 | this->addBots(this->numberOfBots_); |
---|
[8706] | 149 | this->gtinfo_->start(); |
---|
[2072] | 150 | this->spawnPlayersIfRequested(); |
---|
| 151 | } |
---|
| 152 | |
---|
| 153 | void Gametype::end() |
---|
| 154 | { |
---|
[8706] | 155 | this->gtinfo_->end(); |
---|
[9977] | 156 | if (this->bAutoEnd_) |
---|
[9980] | 157 | { |
---|
| 158 | this->showMenuTimer_.setTimer(3.0f, true, createExecutor(createFunctor(&Gametype::showMenu, this))); |
---|
[9977] | 159 | } |
---|
[3033] | 160 | |
---|
| 161 | for (std::map<PlayerInfo*, Player>::iterator it = this->players_.begin(); it != this->players_.end(); ++it) |
---|
| 162 | { |
---|
| 163 | if (it->first->getControllableEntity()) |
---|
| 164 | { |
---|
| 165 | ControllableEntity* oldentity = it->first->getControllableEntity(); |
---|
[3038] | 166 | |
---|
[9667] | 167 | ControllableEntity* entity = this->defaultControllableEntity_.fabricate(oldentity->getContext()); |
---|
[3033] | 168 | if (oldentity->getCamera()) |
---|
| 169 | { |
---|
| 170 | entity->setPosition(oldentity->getCamera()->getWorldPosition()); |
---|
| 171 | entity->setOrientation(oldentity->getCamera()->getWorldOrientation()); |
---|
| 172 | } |
---|
| 173 | else |
---|
| 174 | { |
---|
| 175 | entity->setPosition(oldentity->getWorldPosition()); |
---|
| 176 | entity->setOrientation(oldentity->getWorldOrientation()); |
---|
| 177 | } |
---|
| 178 | it->first->startControl(entity); |
---|
| 179 | } |
---|
| 180 | else |
---|
| 181 | this->spawnPlayerAsDefaultPawn(it->first); |
---|
| 182 | } |
---|
[2072] | 183 | } |
---|
| 184 | |
---|
| 185 | void Gametype::playerEntered(PlayerInfo* player) |
---|
| 186 | { |
---|
[2662] | 187 | this->players_[player].state_ = PlayerState::Joined; |
---|
[8706] | 188 | this->gtinfo_->playerEntered(player); |
---|
[2072] | 189 | } |
---|
| 190 | |
---|
[2826] | 191 | bool Gametype::playerLeft(PlayerInfo* player) |
---|
[2072] | 192 | { |
---|
[2662] | 193 | std::map<PlayerInfo*, Player>::iterator it = this->players_.find(player); |
---|
[2072] | 194 | if (it != this->players_.end()) |
---|
| 195 | { |
---|
| 196 | this->players_.erase(it); |
---|
[2826] | 197 | return true; |
---|
[2072] | 198 | } |
---|
[2826] | 199 | return false; |
---|
[2072] | 200 | } |
---|
| 201 | |
---|
| 202 | void Gametype::playerSwitched(PlayerInfo* player, Gametype* newgametype) |
---|
| 203 | { |
---|
| 204 | } |
---|
| 205 | |
---|
| 206 | void Gametype::playerSwitchedBack(PlayerInfo* player, Gametype* oldgametype) |
---|
| 207 | { |
---|
| 208 | } |
---|
| 209 | |
---|
[2826] | 210 | bool Gametype::playerChangedName(PlayerInfo* player) |
---|
[2072] | 211 | { |
---|
| 212 | if (this->players_.find(player) != this->players_.end()) |
---|
| 213 | { |
---|
| 214 | if (player->getName() != player->getOldName()) |
---|
| 215 | { |
---|
[2826] | 216 | return true; |
---|
[2072] | 217 | } |
---|
| 218 | } |
---|
[2826] | 219 | return false; |
---|
[2072] | 220 | } |
---|
| 221 | |
---|
| 222 | void Gametype::pawnPreSpawn(Pawn* pawn) |
---|
| 223 | { |
---|
| 224 | } |
---|
| 225 | |
---|
| 226 | void Gametype::pawnPostSpawn(Pawn* pawn) |
---|
| 227 | { |
---|
| 228 | } |
---|
| 229 | |
---|
[2826] | 230 | void Gametype::playerPreSpawn(PlayerInfo* player) |
---|
[2072] | 231 | { |
---|
[2826] | 232 | } |
---|
[2662] | 233 | |
---|
[2826] | 234 | void Gametype::playerPostSpawn(PlayerInfo* player) |
---|
| 235 | { |
---|
| 236 | } |
---|
[2662] | 237 | |
---|
[2826] | 238 | void Gametype::playerStartsControllingPawn(PlayerInfo* player, Pawn* pawn) |
---|
| 239 | { |
---|
| 240 | } |
---|
| 241 | |
---|
| 242 | void Gametype::playerStopsControllingPawn(PlayerInfo* player, Pawn* pawn) |
---|
| 243 | { |
---|
| 244 | } |
---|
| 245 | |
---|
| 246 | bool Gametype::allowPawnHit(Pawn* victim, Pawn* originator) |
---|
| 247 | { |
---|
| 248 | return true; |
---|
| 249 | } |
---|
| 250 | |
---|
| 251 | bool Gametype::allowPawnDamage(Pawn* victim, Pawn* originator) |
---|
| 252 | { |
---|
| 253 | return true; |
---|
| 254 | } |
---|
| 255 | |
---|
| 256 | bool Gametype::allowPawnDeath(Pawn* victim, Pawn* originator) |
---|
| 257 | { |
---|
| 258 | return true; |
---|
| 259 | } |
---|
| 260 | |
---|
| 261 | void Gametype::pawnKilled(Pawn* victim, Pawn* killer) |
---|
| 262 | { |
---|
[2662] | 263 | if (victim && victim->getPlayer()) |
---|
| 264 | { |
---|
| 265 | std::map<PlayerInfo*, Player>::iterator it = this->players_.find(victim->getPlayer()); |
---|
| 266 | if (it != this->players_.end()) |
---|
| 267 | { |
---|
| 268 | it->second.state_ = PlayerState::Dead; |
---|
| 269 | it->second.killed_++; |
---|
| 270 | |
---|
| 271 | // Reward killer |
---|
[3099] | 272 | if (killer && killer->getPlayer()) |
---|
[2839] | 273 | { |
---|
| 274 | std::map<PlayerInfo*, Player>::iterator it = this->players_.find(killer->getPlayer()); |
---|
| 275 | if (it != this->players_.end()) |
---|
[3099] | 276 | { |
---|
[2839] | 277 | it->second.frags_++; |
---|
[3099] | 278 | |
---|
[8327] | 279 | if (killer->getPlayer()->getClientID() != NETWORK_PEER_ID_UNKNOWN) |
---|
[5929] | 280 | this->gtinfo_->sendKillMessage("You killed " + victim->getPlayer()->getName(), killer->getPlayer()->getClientID()); |
---|
[8327] | 281 | if (victim->getPlayer()->getClientID() != NETWORK_PEER_ID_UNKNOWN) |
---|
[5929] | 282 | this->gtinfo_->sendDeathMessage("You were killed by " + killer->getPlayer()->getName(), victim->getPlayer()->getClientID()); |
---|
[3099] | 283 | } |
---|
[2839] | 284 | } |
---|
[2662] | 285 | |
---|
[8706] | 286 | if(victim->getPlayer()->isHumanPlayer()) |
---|
| 287 | this->gtinfo_->pawnKilled(victim->getPlayer()); |
---|
| 288 | |
---|
[9667] | 289 | ControllableEntity* entity = this->defaultControllableEntity_.fabricate(victim->getContext()); |
---|
[2662] | 290 | if (victim->getCamera()) |
---|
| 291 | { |
---|
| 292 | entity->setPosition(victim->getCamera()->getWorldPosition()); |
---|
| 293 | entity->setOrientation(victim->getCamera()->getWorldOrientation()); |
---|
| 294 | } |
---|
| 295 | else |
---|
| 296 | { |
---|
| 297 | entity->setPosition(victim->getWorldPosition()); |
---|
| 298 | entity->setOrientation(victim->getWorldOrientation()); |
---|
| 299 | } |
---|
| 300 | it->first->startControl(entity); |
---|
| 301 | } |
---|
| 302 | else |
---|
[8858] | 303 | orxout(internal_warning) << "Killed Pawn was not in the playerlist" << endl; |
---|
[2662] | 304 | } |
---|
[2072] | 305 | } |
---|
| 306 | |
---|
[9348] | 307 | void Gametype::playerScored(PlayerInfo* player, int score) |
---|
[2072] | 308 | { |
---|
[2826] | 309 | std::map<PlayerInfo*, Player>::iterator it = this->players_.find(player); |
---|
| 310 | if (it != this->players_.end()) |
---|
[9348] | 311 | it->second.frags_ += score; |
---|
[2072] | 312 | } |
---|
| 313 | |
---|
[2890] | 314 | int Gametype::getScore(PlayerInfo* player) const |
---|
| 315 | { |
---|
| 316 | std::map<PlayerInfo*, Player>::const_iterator it = this->players_.find(player); |
---|
| 317 | if (it != this->players_.end()) |
---|
| 318 | return it->second.frags_; |
---|
| 319 | else |
---|
| 320 | return 0; |
---|
| 321 | } |
---|
| 322 | |
---|
[2072] | 323 | SpawnPoint* Gametype::getBestSpawnPoint(PlayerInfo* player) const |
---|
| 324 | { |
---|
[8706] | 325 | // If there is at least one SpawnPoint. |
---|
[2072] | 326 | if (this->spawnpoints_.size() > 0) |
---|
| 327 | { |
---|
[8706] | 328 | // Fallback spawn point if there is no active one, choose a random one. |
---|
[7163] | 329 | SpawnPoint* fallbackSpawnPoint = NULL; |
---|
[3196] | 330 | unsigned int randomspawn = static_cast<unsigned int>(rnd(static_cast<float>(this->spawnpoints_.size()))); |
---|
[2072] | 331 | unsigned int index = 0; |
---|
[8706] | 332 | std::vector<SpawnPoint*> activeSpawnPoints; |
---|
[2072] | 333 | for (std::set<SpawnPoint*>::const_iterator it = this->spawnpoints_.begin(); it != this->spawnpoints_.end(); ++it) |
---|
| 334 | { |
---|
| 335 | if (index == randomspawn) |
---|
[7163] | 336 | fallbackSpawnPoint = (*it); |
---|
| 337 | |
---|
[8706] | 338 | if (*it != NULL && (*it)->isActive()) |
---|
| 339 | activeSpawnPoints.push_back(*it); |
---|
[7163] | 340 | |
---|
| 341 | ++index; |
---|
| 342 | } |
---|
| 343 | |
---|
[8706] | 344 | if(activeSpawnPoints.size() > 0) |
---|
[7163] | 345 | { |
---|
[8706] | 346 | randomspawn = static_cast<unsigned int>(rnd(static_cast<float>(activeSpawnPoints.size()))); |
---|
| 347 | return activeSpawnPoints[randomspawn]; |
---|
[2072] | 348 | } |
---|
[7163] | 349 | |
---|
[8858] | 350 | orxout(internal_warning) << "Fallback SpawnPoint was used because there were no active SpawnPoints." << endl; |
---|
[7163] | 351 | return fallbackSpawnPoint; |
---|
[2072] | 352 | } |
---|
| 353 | return 0; |
---|
| 354 | } |
---|
| 355 | |
---|
[2171] | 356 | void Gametype::assignDefaultPawnsIfNeeded() |
---|
[2072] | 357 | { |
---|
[2662] | 358 | for (std::map<PlayerInfo*, Player>::iterator it = this->players_.begin(); it != this->players_.end(); ++it) |
---|
[2072] | 359 | { |
---|
[2662] | 360 | if (!it->first->getControllableEntity()) |
---|
[2072] | 361 | { |
---|
[2662] | 362 | it->second.state_ = PlayerState::Dead; |
---|
| 363 | |
---|
[8706] | 364 | if (!it->first->isReadyToSpawn() || !this->gtinfo_->hasStarted()) |
---|
[2072] | 365 | { |
---|
[3033] | 366 | this->spawnPlayerAsDefaultPawn(it->first); |
---|
| 367 | it->second.state_ = PlayerState::Dead; |
---|
[2072] | 368 | } |
---|
| 369 | } |
---|
| 370 | } |
---|
| 371 | } |
---|
| 372 | |
---|
| 373 | void Gametype::checkStart() |
---|
| 374 | { |
---|
[8706] | 375 | if (!this->gtinfo_->hasStarted()) |
---|
[2072] | 376 | { |
---|
[8706] | 377 | if (this->gtinfo_->isStartCountdownRunning()) |
---|
[2072] | 378 | { |
---|
[8706] | 379 | if (this->gtinfo_->getStartCountdown() <= 0.0f) |
---|
[2072] | 380 | { |
---|
[8706] | 381 | this->gtinfo_->stopStartCountdown(); |
---|
[9016] | 382 | this->gtinfo_->setStartCountdown(0.0f); |
---|
[2072] | 383 | this->start(); |
---|
| 384 | } |
---|
| 385 | } |
---|
| 386 | else if (this->players_.size() > 0) |
---|
| 387 | { |
---|
| 388 | if (this->bAutoStart_) |
---|
| 389 | { |
---|
| 390 | this->start(); |
---|
| 391 | } |
---|
| 392 | else |
---|
| 393 | { |
---|
| 394 | bool allplayersready = true; |
---|
[2662] | 395 | bool hashumanplayers = false; |
---|
| 396 | for (std::map<PlayerInfo*, Player>::iterator it = this->players_.begin(); it != this->players_.end(); ++it) |
---|
[2072] | 397 | { |
---|
[2171] | 398 | if (!it->first->isReadyToSpawn()) |
---|
[2072] | 399 | allplayersready = false; |
---|
[2662] | 400 | if (it->first->isHumanPlayer()) |
---|
| 401 | hashumanplayers = true; |
---|
[2072] | 402 | } |
---|
[9260] | 403 | |
---|
[2662] | 404 | if (allplayersready && hashumanplayers) |
---|
[2072] | 405 | { |
---|
[8079] | 406 | // If in developer's mode, there is no start countdown. |
---|
| 407 | if(Core::getInstance().inDevMode()) |
---|
[8706] | 408 | this->start(); |
---|
[8079] | 409 | else |
---|
[9261] | 410 | { |
---|
[8706] | 411 | this->gtinfo_->setStartCountdown(this->initialStartCountdown_); |
---|
[9261] | 412 | this->gtinfo_->startStartCountdown(); |
---|
| 413 | } |
---|
[2072] | 414 | } |
---|
| 415 | } |
---|
| 416 | } |
---|
| 417 | } |
---|
| 418 | } |
---|
| 419 | |
---|
| 420 | void Gametype::spawnPlayersIfRequested() |
---|
| 421 | { |
---|
[2662] | 422 | for (std::map<PlayerInfo*, Player>::iterator it = this->players_.begin(); it != this->players_.end(); ++it) |
---|
[8706] | 423 | { |
---|
[2171] | 424 | if (it->first->isReadyToSpawn() || this->bForceSpawn_) |
---|
| 425 | this->spawnPlayer(it->first); |
---|
[8706] | 426 | } |
---|
[2072] | 427 | } |
---|
| 428 | |
---|
| 429 | void Gametype::spawnDeadPlayersIfRequested() |
---|
| 430 | { |
---|
[2662] | 431 | for (std::map<PlayerInfo*, Player>::iterator it = this->players_.begin(); it != this->players_.end(); ++it) |
---|
| 432 | if (it->second.state_ == PlayerState::Dead) |
---|
[2171] | 433 | if (it->first->isReadyToSpawn() || this->bForceSpawn_) |
---|
| 434 | this->spawnPlayer(it->first); |
---|
[2072] | 435 | } |
---|
| 436 | |
---|
| 437 | void Gametype::spawnPlayer(PlayerInfo* player) |
---|
| 438 | { |
---|
| 439 | SpawnPoint* spawnpoint = this->getBestSpawnPoint(player); |
---|
| 440 | if (spawnpoint) |
---|
| 441 | { |
---|
[2826] | 442 | this->playerPreSpawn(player); |
---|
[2072] | 443 | player->startControl(spawnpoint->spawn()); |
---|
[2662] | 444 | this->players_[player].state_ = PlayerState::Alive; |
---|
[8706] | 445 | |
---|
| 446 | if(player->isHumanPlayer()) |
---|
| 447 | this->gtinfo_->playerSpawned(player); |
---|
[9016] | 448 | |
---|
[2826] | 449 | this->playerPostSpawn(player); |
---|
[2072] | 450 | } |
---|
| 451 | else |
---|
| 452 | { |
---|
[8858] | 453 | orxout(user_error) << "No SpawnPoints in current Gametype" << endl; |
---|
[2072] | 454 | abort(); |
---|
| 455 | } |
---|
| 456 | } |
---|
[2662] | 457 | |
---|
[3033] | 458 | void Gametype::spawnPlayerAsDefaultPawn(PlayerInfo* player) |
---|
| 459 | { |
---|
| 460 | SpawnPoint* spawn = this->getBestSpawnPoint(player); |
---|
| 461 | if (spawn) |
---|
| 462 | { |
---|
| 463 | // force spawn at spawnpoint with default pawn |
---|
[9667] | 464 | ControllableEntity* entity = this->defaultControllableEntity_.fabricate(spawn->getContext()); |
---|
[3033] | 465 | spawn->spawn(entity); |
---|
| 466 | player->startControl(entity); |
---|
| 467 | } |
---|
| 468 | else |
---|
| 469 | { |
---|
[8858] | 470 | orxout(user_error) << "No SpawnPoints in current Gametype" << endl; |
---|
[3033] | 471 | abort(); |
---|
| 472 | } |
---|
| 473 | } |
---|
| 474 | |
---|
[2662] | 475 | void Gametype::addBots(unsigned int amount) |
---|
| 476 | { |
---|
| 477 | for (unsigned int i = 0; i < amount; ++i) |
---|
[9667] | 478 | this->botclass_.fabricate(this->getContext()); |
---|
[2662] | 479 | } |
---|
| 480 | |
---|
| 481 | void Gametype::killBots(unsigned int amount) |
---|
| 482 | { |
---|
| 483 | unsigned int i = 0; |
---|
| 484 | for (ObjectList<Bot>::iterator it = ObjectList<Bot>::begin(); (it != ObjectList<Bot>::end()) && ((amount == 0) || (i < amount)); ) |
---|
| 485 | { |
---|
| 486 | if (it->getGametype() == this) |
---|
| 487 | { |
---|
[5929] | 488 | (it++)->destroy(); |
---|
[2662] | 489 | ++i; |
---|
| 490 | } |
---|
[5929] | 491 | else |
---|
| 492 | ++it; |
---|
[2662] | 493 | } |
---|
| 494 | } |
---|
[3033] | 495 | |
---|
| 496 | void Gametype::addTime(float t) |
---|
[3038] | 497 | { |
---|
[3033] | 498 | if (this->timeLimit_ == 0) |
---|
| 499 | this->time_ -= t; |
---|
| 500 | else |
---|
| 501 | this->time_ += t; |
---|
| 502 | } |
---|
| 503 | |
---|
| 504 | void Gametype::removeTime(float t) |
---|
[3038] | 505 | { |
---|
[3033] | 506 | if (this->timeLimit_ == 0) |
---|
| 507 | this->time_ += t; |
---|
| 508 | else |
---|
| 509 | this->time_ -= t; |
---|
| 510 | } |
---|
| 511 | |
---|
| 512 | void Gametype::resetTimer() |
---|
[3038] | 513 | { |
---|
[3033] | 514 | this->resetTimer(timeLimit_); |
---|
| 515 | } |
---|
| 516 | |
---|
| 517 | void Gametype::resetTimer(float t) |
---|
[3038] | 518 | { |
---|
[3033] | 519 | this->timeLimit_ = t; |
---|
| 520 | this->time_ = t; |
---|
| 521 | } |
---|
[9969] | 522 | |
---|
[9977] | 523 | void Gametype::showMenu() |
---|
| 524 | { |
---|
[9984] | 525 | GSLevel::startMainMenu(); |
---|
[9977] | 526 | } |
---|
[2072] | 527 | } |
---|