- Timestamp:
- Nov 16, 2011, 5:02:12 PM (12 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
code/branches/gamecontent/src/orxonox/gametypes/TeamGametype.cc
r8930 r8941 35 35 #include "worldentities/TeamSpawnPoint.h" 36 36 #include "worldentities/pawns/Pawn.h" 37 #include "controllers/ArtificialController.h" 37 38 38 39 namespace orxonox … … 70 71 { 71 72 Gametype::playerEntered(player); 73 if(player == NULL) return; 72 74 this->findAndSetTeam(player); 75 if( getNumberOfPlayers() < maxPlayers_ || maxPlayers_ == 0) 76 this->allowedInGame_[player]= true; 77 else 78 this->allowedInGame_[player]= false; 73 79 } 74 80 … … 108 114 void TeamGametype::spawnDeadPlayersIfRequested() 109 115 { 110 for (std::map<PlayerInfo*, Player>::iterator it = this->players_.begin(); it != this->players_.end(); 111 ++it) 112 if (it->second.state_ == PlayerState::Dead) 113 { 114 if ((it->first->isReadyToSpawn() || this->bForceSpawn_)) 115 { 116 this->spawnPlayer(it->first); 116 for (std::map<PlayerInfo*, Player>::iterator it = this->players_.begin(); it != this->players_.end(); ++it)\ 117 { 118 if(true)//check if dead player is allowed to enter -> if maximum nr of players is exceeded & player was not in game before: disallow 119 continue; 120 if (it->second.state_ == PlayerState::Dead) 121 { 122 if ((it->first->isReadyToSpawn() || this->bForceSpawn_)) 123 { 124 this->spawnPlayer(it->first); 125 } 117 126 } 118 127 } … … 209 218 return; 210 219 220 this->setTeamColour(player,pawn); 221 } 222 223 bool TeamGametype::pawnsAreInTheSameTeam(Pawn* pawn1, Pawn* pawn2) 224 { 225 if (pawn1 && pawn2) 226 { 227 std::map<PlayerInfo*, int>::const_iterator it1 = this->teamnumbers_.find(pawn1->getPlayer()); 228 std::map<PlayerInfo*, int>::const_iterator it2 = this->teamnumbers_.find(pawn2->getPlayer()); 229 230 if (it1 != this->teamnumbers_.end() && it2 != this->teamnumbers_.end()) 231 return (it1->second == it2->second); 232 } 233 return false; 234 } 235 236 int TeamGametype::getTeam(PlayerInfo* player) 237 { 238 std::map<PlayerInfo*, int>::const_iterator it_player = this->teamnumbers_.find(player); 239 if (it_player != this->teamnumbers_.end()) 240 return it_player->second; 241 else 242 return -1; 243 } 244 245 void TeamGametype::setTeamColour(PlayerInfo* player, Pawn* pawn) 246 { 211 247 // Set the team colour 212 248 std::map<PlayerInfo*, int>::const_iterator it_player = this->teamnumbers_.find(player); … … 230 266 } 231 267 232 bool TeamGametype::pawnsAreInTheSameTeam(Pawn* pawn1, Pawn* pawn2) 233 { 234 if (pawn1 && pawn2) 235 { 236 std::map<PlayerInfo*, int>::const_iterator it1 = this->teamnumbers_.find(pawn1->getPlayer()); 237 std::map<PlayerInfo*, int>::const_iterator it2 = this->teamnumbers_.find(pawn2->getPlayer()); 238 239 if (it1 != this->teamnumbers_.end() && it2 != this->teamnumbers_.end()) 240 return (it1->second == it2->second); 241 } 242 return false; 243 } 244 245 int TeamGametype::getTeam(PlayerInfo* player) 246 { 247 std::map<PlayerInfo*, int>::const_iterator it_player = this->teamnumbers_.find(player); 248 if (it_player != this->teamnumbers_.end()) 249 return it_player->second; 250 else 251 return -1; 252 } 268 void TeamGametype::setObjectColour(Pawn* pawn) 269 { 270 if(pawn == NULL) 271 return; 272 //get Pawn's controller 273 ArtificialController* controller = orxonox_cast<ArtificialController*>(pawn); 274 if(controller == NULL) 275 return; 276 //get Teamnumber - get the data 277 int teamnumber= controller->getTeam(); 278 if(teamnumber < 0) 279 return; 280 //set ObjectColour 281 pawn->setRadarObjectColour(this->teamcolours_[teamnumber]); 282 283 std::set<WorldEntity*> pawnAttachments = pawn->getAttachedObjects(); 284 for (std::set<WorldEntity*>::iterator it = pawnAttachments.begin(); it != pawnAttachments.end(); ++it) 285 { 286 if ((*it)->isA(Class(TeamColourable))) 287 { 288 TeamColourable* tc = orxonox_cast<TeamColourable*>(*it); 289 tc->setTeamColour(this->teamcolours_[teamnumber]); 290 } 291 } 292 } 293 294 253 295 }
Note: See TracChangeset
for help on using the changeset viewer.