Changeset 8706 for code/trunk/src/orxonox/gametypes
- Timestamp:
- Jun 14, 2011, 8:53:28 PM (13 years ago)
- Location:
- code/trunk
- Files:
-
- 6 edited
Legend:
- Unmodified
- Added
- Removed
-
code/trunk
- Property svn:mergeinfo changed
-
code/trunk/src/orxonox/gametypes/Dynamicmatch.cc
r8327 r8706 151 151 //Give new pig boost 152 152 SpaceShip* spaceship = dynamic_cast<SpaceShip*>(victim); 153 if (spaceship && spaceship->getEngine()) 154 { 155 spaceship->getEngine()->setSpeedFactor(5); 156 WeakPtr<Engine>* ptr = new WeakPtr<Engine>(spaceship->getEngine()); 157 ExecutorPtr executor = createExecutor(createFunctor(&Dynamicmatch::resetSpeedFactor, this)); 158 executor->setDefaultValue(0, ptr); 159 new Timer(10, false, executor, true); 160 } 153 grantPigBoost(spaceship); 161 154 } 162 155 … … 252 245 //Give new pig boost 253 246 SpaceShip* spaceship = dynamic_cast<SpaceShip*>(victim); 254 if (spaceship && spaceship->getEngine()) 255 { 256 spaceship->getEngine()->setSpeedFactor(5); 257 WeakPtr<Engine>* ptr = new WeakPtr<Engine>(spaceship->getEngine()); 258 ExecutorPtr executor = createExecutor(createFunctor(&Dynamicmatch::resetSpeedFactor, this)); 259 executor->setDefaultValue(0, ptr); 260 new Timer(10, false, executor, true); 261 } 262 247 grantPigBoost(spaceship); 263 248 } 264 249 // killer vs piggy … … 321 306 } 322 307 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 323 321 void Dynamicmatch::playerStartsControllingPawn(PlayerInfo* player, Pawn* pawn) //set party + colouring 324 322 { … … 597 595 } 598 596 599 void Dynamicmatch::resetSpeedFactor(WeakPtr< Engine>* ptr)// helper function597 void Dynamicmatch::resetSpeedFactor(WeakPtr<SpaceShip>* ptr)// helper function 600 598 { 601 599 if (*ptr) -
code/trunk/src/orxonox/gametypes/Dynamicmatch.h
r7163 r8706 73 73 virtual void furtherInstructions();*/ 74 74 virtual void rewardPig(); 75 void resetSpeedFactor(WeakPtr<Engine>* ptr); 75 void grantPigBoost(SpaceShip* spaceship); // Added this, since it's used twice on different occasions. 76 void resetSpeedFactor(WeakPtr<SpaceShip>* ptr); 76 77 void tick (float dt);// used to end the game 77 78 SpawnPoint* getBestSpawnPoint(PlayerInfo* player) const; -
code/trunk/src/orxonox/gametypes/Gametype.cc
r8327 r8706 121 121 } 122 122 123 if (this->gtinfo_->bStartCountdownRunning_ && !this->gtinfo_->bStarted_) 124 this->gtinfo_->startCountdown_ -= dt; 125 126 if (!this->gtinfo_->bStarted_) 123 if (this->gtinfo_->isStartCountdownRunning() && !this->gtinfo_->hasStarted()) 124 this->gtinfo_->countdownStartCountdown(dt); 125 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 127 135 this->checkStart(); 128 else if (!this->gtinfo_->bEnded_) 136 } 137 else if (!this->gtinfo_->hasEnded()) 129 138 this->spawnDeadPlayersIfRequested(); 130 139 … … 136 145 this->addBots(this->numberOfBots_); 137 146 138 this->gtinfo_-> bStarted_ = true;147 this->gtinfo_->start(); 139 148 140 149 this->spawnPlayersIfRequested(); … … 143 152 void Gametype::end() 144 153 { 145 this->gtinfo_-> bEnded_ = true;154 this->gtinfo_->end(); 146 155 147 156 for (std::map<PlayerInfo*, Player>::iterator it = this->players_.begin(); it != this->players_.end(); ++it) … … 173 182 { 174 183 this->players_[player].state_ = PlayerState::Joined; 184 this->gtinfo_->playerEntered(player); 175 185 } 176 186 … … 270 280 } 271 281 282 if(victim->getPlayer()->isHumanPlayer()) 283 this->gtinfo_->pawnKilled(victim->getPlayer()); 284 272 285 ControllableEntity* entity = this->defaultControllableEntity_.fabricate(victim->getCreator()); 273 286 if (victim->getCamera()) … … 306 319 SpawnPoint* Gametype::getBestSpawnPoint(PlayerInfo* player) const 307 320 { 321 // If there is at least one SpawnPoint. 308 322 if (this->spawnpoints_.size() > 0) 309 323 { 324 // Fallback spawn point if there is no active one, choose a random one. 310 325 SpawnPoint* fallbackSpawnPoint = NULL; 311 326 unsigned int randomspawn = static_cast<unsigned int>(rnd(static_cast<float>(this->spawnpoints_.size()))); 312 327 unsigned int index = 0; 313 std:: set<SpawnPoint*> activeSpawnPoints = this->spawnpoints_;328 std::vector<SpawnPoint*> activeSpawnPoints; 314 329 for (std::set<SpawnPoint*>::const_iterator it = this->spawnpoints_.begin(); it != this->spawnpoints_.end(); ++it) 315 330 { … … 317 332 fallbackSpawnPoint = (*it); 318 333 319 if ( !(*it)->isActive())320 activeSpawnPoints. erase(*it);334 if (*it != NULL && (*it)->isActive()) 335 activeSpawnPoints.push_back(*it); 321 336 322 337 ++index; 323 338 } 324 339 325 randomspawn = static_cast<unsigned int>(rnd(static_cast<float>(this->spawnpoints_.size()))); 326 index = 0; 327 for (std::set<SpawnPoint*>::const_iterator it = activeSpawnPoints.begin(); it != activeSpawnPoints.end(); ++it) 328 { 329 if (index == randomspawn) 330 return (*it); 331 332 ++index; 333 } 334 340 if(activeSpawnPoints.size() > 0) 341 { 342 randomspawn = static_cast<unsigned int>(rnd(static_cast<float>(activeSpawnPoints.size()))); 343 return activeSpawnPoints[randomspawn]; 344 } 345 346 COUT(2) << "Warning: Fallback SpawnPoint was used, because there were no active SpawnPoints." << endl; 335 347 return fallbackSpawnPoint; 336 348 } … … 346 358 it->second.state_ = PlayerState::Dead; 347 359 348 if (!it->first->isReadyToSpawn() || !this->gtinfo_-> bStarted_)360 if (!it->first->isReadyToSpawn() || !this->gtinfo_->hasStarted()) 349 361 { 350 362 this->spawnPlayerAsDefaultPawn(it->first); … … 357 369 void Gametype::checkStart() 358 370 { 359 if (!this->gtinfo_-> bStarted_)360 { 361 if (this->gtinfo_-> bStartCountdownRunning_)362 { 363 if (this->gtinfo_-> startCountdown_ <= 0)364 { 365 this->gtinfo_-> bStartCountdownRunning_ = false;366 this->gtinfo_->s tartCountdown_ = 0;371 if (!this->gtinfo_->hasStarted()) 372 { 373 if (this->gtinfo_->isStartCountdownRunning()) 374 { 375 if (this->gtinfo_->getStartCountdown() <= 0.0f) 376 { 377 this->gtinfo_->stopStartCountdown(); 378 this->gtinfo_->setStartCountdown(0.0f);; 367 379 this->start(); 368 380 } … … 389 401 // If in developer's mode, there is no start countdown. 390 402 if(Core::getInstance().inDevMode()) 391 this-> gtinfo_->startCountdown_ = 0;403 this->start(); 392 404 else 393 this->gtinfo_->s tartCountdown_ = this->initialStartCountdown_;394 this->gtinfo_-> bStartCountdownRunning_ = true;405 this->gtinfo_->setStartCountdown(this->initialStartCountdown_); 406 this->gtinfo_->startStartCountdown(); 395 407 } 396 408 } … … 402 414 { 403 415 for (std::map<PlayerInfo*, Player>::iterator it = this->players_.begin(); it != this->players_.end(); ++it) 416 { 404 417 if (it->first->isReadyToSpawn() || this->bForceSpawn_) 405 418 this->spawnPlayer(it->first); 419 } 406 420 } 407 421 … … 422 436 player->startControl(spawnpoint->spawn()); 423 437 this->players_[player].state_ = PlayerState::Alive; 438 439 if(player->isHumanPlayer()) 440 this->gtinfo_->playerSpawned(player); 441 424 442 this->playerPostSpawn(player); 425 443 } -
code/trunk/src/orxonox/gametypes/Gametype.h
r8178 r8706 78 78 79 79 inline bool hasStarted() const 80 { return this->gtinfo_-> bStarted_; }80 { return this->gtinfo_->hasStarted(); } 81 81 inline bool hasEnded() const 82 { return this->gtinfo_-> bEnded_; }82 { return this->gtinfo_->hasEnded(); } 83 83 84 84 virtual void start(); … … 114 114 115 115 inline bool isStartCountdownRunning() const 116 { return this->gtinfo_-> bStartCountdownRunning_; }116 { return this->gtinfo_->isStartCountdownRunning(); } 117 117 inline float getStartCountdown() const 118 { return this->gtinfo_-> startCountdown_; }118 { return this->gtinfo_->getStartCountdown(); } 119 119 120 120 inline void setHUDTemplate(const std::string& name) 121 { this->gtinfo_-> hudtemplate_ = name; }121 { this->gtinfo_->setHUDTemplate(name); } 122 122 inline const std::string& getHUDTemplate() const 123 { return this->gtinfo_-> hudtemplate_; }123 { return this->gtinfo_->getHUDTemplate(); } 124 124 125 125 void addBots(unsigned int amount); -
code/trunk/src/orxonox/gametypes/LastTeamStanding.cc
r8351 r8706 55 55 this->setHUDTemplate("lastTeamStandingHUD"); 56 56 } 57 57 58 58 LastTeamStanding::~LastTeamStanding() 59 59 { 60 } 60 } 61 61 62 62 void LastTeamStanding::playerEntered(PlayerInfo* player) … … 69 69 else 70 70 playerLives_[player]=getMinLives();//new players only get minimum of lives */ 71 71 72 72 this->timeToAct_[player] = timeRemaining; 73 73 this->playerDelayTime_[player] = respawnDelay; 74 74 this->inGame_[player] = true; 75 75 unsigned int team = getTeam(player); 76 if( team < 0|| team > teams_) // make sure getTeam returns a regular value76 if(team >= eachTeamsPlayers.size()) // make sure getTeam returns a regular value 77 77 return; 78 78 if(this->eachTeamsPlayers[team]==0) //if a player is the first in his group, a new team is alive … … 91 91 this->inGame_.erase(player); 92 92 unsigned int team = getTeam(player); 93 if( team < 0|| team > teams_) // make sure getTeam returns a regular value93 if(team >= eachTeamsPlayers.size()) // make sure getTeam returns a regular value 94 94 return valid_player; 95 95 this->eachTeamsPlayers[team]--; // a player left the team … … 107 107 bool allow = TeamDeathmatch::allowPawnDeath(victim, originator); 108 108 if(!allow) {return allow;} 109 109 110 110 playerLives_[victim->getPlayer()] = playerLives_[victim->getPlayer()] - 1; //player lost a live 111 111 this->inGame_[victim->getPlayer()] = false; //if player dies, he isn't allowed to respawn immediately … … 113 113 { 114 114 unsigned int team = getTeam(victim->getPlayer()); 115 if(team < 0|| team > teams_) // make sure getTeam returns a regular value115 if(team >= eachTeamsPlayers.size()) // make sure getTeam returns a regular value 116 116 return allow; 117 117 this->eachTeamsPlayers[team]--; … … 140 140 const std::string& message = ""; // resets Camper-Warning-message 141 141 this->gtinfo_->sendFadingMessage(message,it->first->getClientID()); 142 } 142 } 143 143 } 144 144 return allow; … … 163 163 return; 164 164 TeamDeathmatch::playerStartsControllingPawn(player,pawn); 165 165 166 166 this->timeToAct_[player] = timeRemaining + 3.0f + respawnDelay;//reset timer 167 167 this->playerDelayTime_[player] = respawnDelay; 168 168 169 169 std::map<PlayerInfo*, Player>::iterator it = this->players_.find(player); 170 170 if (it != this->players_.end()) … … 174 174 const std::string& message = ""; // resets Camper-Warning-message 175 175 this->gtinfo_->sendFadingMessage(message,it->first->getClientID()); 176 } 176 } 177 177 } 178 178 … … 187 187 } 188 188 for (std::map<PlayerInfo*, float>::iterator it = this->timeToAct_.begin(); it != this->timeToAct_.end(); ++it) 189 { 189 { 190 190 if (playerGetLives(it->first) <= 0)//Players without lives shouldn't be affected by time. 191 continue; 191 continue; 192 192 it->second -= dt;//Decreases punishment time. 193 if (!inGame_[it->first])//Manages respawn delay - player is forced to respawn after the delaytime is used up. 193 if (!inGame_[it->first])//Manages respawn delay - player is forced to respawn after the delaytime is used up. 194 194 { 195 195 playerDelayTime_[it->first] -= dt; … … 309 309 return 0; 310 310 } 311 311 312 312 void LastTeamStanding::setConfigValues() 313 313 {
Note: See TracChangeset
for help on using the changeset viewer.