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