Changeset 11071 for code/trunk/src/orxonox/gametypes/TeamGametype.cc
- Timestamp:
- Jan 17, 2016, 10:29:21 PM (8 years ago)
- Location:
- code/trunk
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
code/trunk
- Property svn:mergeinfo changed
-
code/trunk/src/orxonox/gametypes/TeamGametype.cc
r9941 r11071 75 75 void TeamGametype::playerEntered(PlayerInfo* player) 76 76 { 77 if(player == NULL) return; // catch null pointers77 if(player == nullptr) return; // catch null pointers 78 78 Gametype::playerEntered(player); 79 79 this->findAndSetTeam(player); … … 96 96 void TeamGametype::findAndSetTeam(PlayerInfo* player) 97 97 { 98 if(player == NULL) return; // catch null pointers98 if(player == nullptr) return; // catch null pointers 99 99 std::vector<unsigned int> playersperteam(this->teams_, 0); 100 100 101 for ( std::map<PlayerInfo*, int>::iterator it = this->teamnumbers_.begin(); it != this->teamnumbers_.end(); ++it)102 if ( it->second < static_cast<int>(this->teams_) && it->second >= 0)103 playersperteam[ it->second]++;101 for (const auto& mapEntry : this->teamnumbers_) 102 if (mapEntry.second < static_cast<int>(this->teams_) && mapEntry.second >= 0) 103 playersperteam[mapEntry.second]++; 104 104 105 105 unsigned int minplayers = static_cast<unsigned int>(-1); … … 123 123 if( (this->players_.size() >= maxPlayers_) && (allowedInGame_[player] == true) ) // if there's a "waiting list" 124 124 { 125 for ( std::map<PlayerInfo*, bool>::iterator it = this->allowedInGame_.begin(); it != this->allowedInGame_.end(); ++it)126 { 127 if( it->second == false) // waiting player found128 { it->second = true; break;} // allow player to enter125 for (auto& mapEntry : this->allowedInGame_) 126 { 127 if(mapEntry.second == false) // waiting player found 128 {mapEntry.second = true; break;} // allow player to enter 129 129 } 130 130 } … … 141 141 void TeamGametype::spawnDeadPlayersIfRequested() 142 142 { 143 for ( std::map<PlayerInfo*, Player>::iterator it = this->players_.begin(); it != this->players_.end(); ++it)\144 { 145 if(allowedInGame_[ it->first] == false)//check if dead player is allowed to enter143 for (const auto& mapEntry : this->players_)\ 144 { 145 if(allowedInGame_[mapEntry.first] == false)//check if dead player is allowed to enter 146 146 { 147 147 continue; 148 148 } 149 if ( it->second.state_ == PlayerState::Dead)150 { 151 if (( it->first->isReadyToSpawn() || this->bForceSpawn_))149 if (mapEntry.second.state_ == PlayerState::Dead) 150 { 151 if ((mapEntry.first->isReadyToSpawn() || this->bForceSpawn_)) 152 152 { 153 this->spawnPlayer( it->first);153 this->spawnPlayer(mapEntry.first); 154 154 } 155 155 } … … 178 178 if(!player || this->getTeam(player) == -1) 179 179 return 0; 180 for ( std::map<PlayerInfo*, Player>::iterator it = this->players_.begin(); it != this->players_.end(); ++it)181 { 182 if ( this->getTeam( it->first) == this->getTeam(player) )183 { 184 teamscore += it->second.frags_;180 for (const auto& mapEntry : this->players_) 181 { 182 if ( this->getTeam(mapEntry.first) == this->getTeam(player) ) 183 { 184 teamscore += mapEntry.second.frags_; 185 185 } 186 186 } … … 191 191 { 192 192 int teamSize = 0; 193 for ( std::map<PlayerInfo*, int>::iterator it = this->teamnumbers_.begin(); it != this->teamnumbers_.end(); ++it)194 { 195 if ( it->second == team)193 for (const auto& mapEntry : this->teamnumbers_) 194 { 195 if (mapEntry.second == team) 196 196 teamSize++; 197 197 } … … 202 202 { 203 203 int teamSize = 0; 204 for ( std::map<PlayerInfo*, int>::iterator it = this->teamnumbers_.begin(); it != this->teamnumbers_.end(); ++it)205 { 206 if ( it->second == team && it->first->isHumanPlayer())204 for (const auto& mapEntry : this->teamnumbers_) 205 { 206 if (mapEntry.second == team && mapEntry.first->isHumanPlayer()) 207 207 teamSize++; 208 208 } … … 235 235 } 236 236 237 SpawnPoint* fallbackSpawnPoint = NULL;237 SpawnPoint* fallbackSpawnPoint = nullptr; 238 238 if (teamSpawnPoints.size() > 0) 239 239 { … … 241 241 unsigned int index = 0; 242 242 // Get random fallback spawnpoint in case there is no active SpawnPoint. 243 for ( std::set<SpawnPoint*>::const_iterator it = teamSpawnPoints.begin(); it != teamSpawnPoints.end(); ++it)243 for (SpawnPoint* teamSpawnPoint : teamSpawnPoints) 244 244 { 245 245 if (index == randomspawn) 246 246 { 247 fallbackSpawnPoint = (*it);247 fallbackSpawnPoint = teamSpawnPoint; 248 248 break; 249 249 } … … 266 266 randomspawn = static_cast<unsigned int>(rnd(static_cast<float>(teamSpawnPoints.size()))); 267 267 index = 0; 268 for ( std::set<SpawnPoint*>::const_iterator it = teamSpawnPoints.begin(); it != teamSpawnPoints.end(); ++it)268 for (SpawnPoint* teamSpawnPoint : teamSpawnPoints) 269 269 { 270 270 if (index == randomspawn) 271 return (*it);271 return teamSpawnPoint; 272 272 273 273 ++index; … … 277 277 } 278 278 279 return 0;279 return nullptr; 280 280 } 281 281 … … 328 328 void TeamGametype::setDefaultObjectColour(Pawn* pawn) 329 329 { 330 if(pawn == NULL)330 if(pawn == nullptr) 331 331 return; 332 332 … … 340 340 ControllableEntity* entity = orxonox_cast<ControllableEntity*>(pawn); 341 341 342 Controller* controller = 0;342 Controller* controller = nullptr; 343 343 if (entity->getController()) 344 344 controller = entity->getController(); … … 350 350 ArtificialController* artificial = orxonox_cast<ArtificialController*>(controller); 351 351 //get Teamnumber - get the data 352 if(artificial == NULL)352 if(artificial == nullptr) 353 353 return; 354 354 teamnumber= artificial->getTeam(); … … 360 360 void TeamGametype::colourPawn(Pawn* pawn, int teamNr) 361 361 {// catch: no-colouring-case and wrong input 362 if(teamNr < 0 || teamNr+1 > int(this->teamcolours_.size()) ||pawn == NULL) return;362 if(teamNr < 0 || teamNr+1 > int(this->teamcolours_.size()) ||pawn == nullptr) return; 363 363 pawn->setRadarObjectColour(this->teamcolours_[teamNr]); 364 364 365 365 std::set<WorldEntity*> pawnAttachments = pawn->getAttachedObjects(); 366 for ( std::set<WorldEntity*>::iterator it = pawnAttachments.begin(); it != pawnAttachments.end(); ++it)367 { 368 if ( (*it)->isA(Class(TeamColourable)))369 { 370 TeamColourable* tc = orxonox_cast<TeamColourable*>( *it);366 for (WorldEntity* pawnAttachment : pawnAttachments) 367 { 368 if (pawnAttachment->isA(Class(TeamColourable))) 369 { 370 TeamColourable* tc = orxonox_cast<TeamColourable*>(pawnAttachment); 371 371 tc->setTeamColour(this->teamcolours_[teamNr]); 372 372 } … … 376 376 void TeamGametype::announceTeamWin(int winnerTeam) 377 377 { 378 for ( std::map<PlayerInfo*, int>::iterator it3 = this->teamnumbers_.begin(); it3 != this->teamnumbers_.end(); ++it3)379 { 380 if ( it3->first->getClientID() == NETWORK_PEER_ID_UNKNOWN)378 for (const auto& mapEntry : this->teamnumbers_) 379 { 380 if (mapEntry.first->getClientID() == NETWORK_PEER_ID_UNKNOWN) 381 381 continue; 382 if ( it3->second == winnerTeam)383 { 384 this->gtinfo_->sendAnnounceMessage("Your team has won the match!", it3->first->getClientID());382 if (mapEntry.second == winnerTeam) 383 { 384 this->gtinfo_->sendAnnounceMessage("Your team has won the match!", mapEntry.first->getClientID()); 385 385 } 386 386 else 387 387 { 388 this->gtinfo_->sendAnnounceMessage("Your team has lost the match!", it3->first->getClientID());388 this->gtinfo_->sendAnnounceMessage("Your team has lost the match!", mapEntry.first->getClientID()); 389 389 } 390 390 }
Note: See TracChangeset
for help on using the changeset viewer.