Changeset 2171 for code/trunk/src/orxonox/objects/gametypes
- Timestamp:
- Nov 10, 2008, 12:05:03 AM (16 years ago)
- Location:
- code/trunk
- Files:
-
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
code/trunk
- Property svn:mergeinfo changed
/code/branches/objecthierarchy merged: 2111-2115,2123,2132-2134,2143-2144,2153-2158,2160-2169
- Property svn:mergeinfo changed
-
code/trunk/src/orxonox/objects/gametypes/Gametype.cc
r2087 r2171 67 67 if (!this->bStarted_) 68 68 this->checkStart(); 69 else 70 this->spawnDeadPlayersIfRequested(); 69 71 70 72 this->assignDefaultPawnsIfNeeded(); 71 this->spawnDeadPlayersIfRequested();72 73 } 73 74 … … 88 89 void Gametype::playerEntered(PlayerInfo* player) 89 90 { 90 this->players_ .insert(player);91 this->players_[player] = PlayerState::Joined; 91 92 92 93 std::string message = player->getName() + " entered the game"; 93 94 COUT(0) << message << std::endl; 94 network::Host::Broadcast(message);95 Host::Broadcast(message); 95 96 } 96 97 97 98 void Gametype::playerLeft(PlayerInfo* player) 98 99 { 99 std:: set<PlayerInfo*>::iterator it = this->players_.find(player);100 std::map<PlayerInfo*, PlayerState::Enum>::iterator it = this->players_.find(player); 100 101 if (it != this->players_.end()) 101 102 { … … 104 105 std::string message = player->getName() + " left the game"; 105 106 COUT(0) << message << std::endl; 106 network::Host::Broadcast(message);107 Host::Broadcast(message); 107 108 } 108 109 } … … 124 125 std::string message = player->getOldName() + " changed name to " + player->getName(); 125 126 COUT(0) << message << std::endl; 126 network::Host::Broadcast(message);127 Host::Broadcast(message); 127 128 } 128 129 } … … 165 166 } 166 167 167 void Gametype::assignDefaultPawnsIfNeeded() const168 { 169 for (std:: set<PlayerInfo*>::const_iterator it = this->players_.begin(); it != this->players_.end(); ++it)170 { 171 if (! (*it)->getControllableEntity() && (!(*it)->isReadyToSpawn() || !this->bStarted_))172 { 173 SpawnPoint* spawn = this->getBestSpawnPoint( *it);168 void Gametype::assignDefaultPawnsIfNeeded() 169 { 170 for (std::map<PlayerInfo*, PlayerState::Enum>::iterator it = this->players_.begin(); it != this->players_.end(); ++it) 171 { 172 if (!it->first->getControllableEntity() && (!it->first->isReadyToSpawn() || !this->bStarted_)) 173 { 174 SpawnPoint* spawn = this->getBestSpawnPoint(it->first); 174 175 if (spawn) 175 176 { … … 177 178 ControllableEntity* entity = this->defaultControllableEntity_.fabricate(spawn); 178 179 spawn->spawn(entity); 179 (*it)->startControl(entity); 180 it->first->startControl(entity); 181 it->second = PlayerState::Dead; 180 182 } 181 183 else … … 210 212 { 211 213 bool allplayersready = true; 212 for (std:: set<PlayerInfo*>::iterator it = this->players_.begin(); it != this->players_.end(); ++it)214 for (std::map<PlayerInfo*, PlayerState::Enum>::iterator it = this->players_.begin(); it != this->players_.end(); ++it) 213 215 { 214 if (! (*it)->isReadyToSpawn())216 if (!it->first->isReadyToSpawn()) 215 217 allplayersready = false; 216 218 } … … 227 229 void Gametype::spawnPlayersIfRequested() 228 230 { 229 for (std:: set<PlayerInfo*>::iterator it = this->players_.begin(); it != this->players_.end(); ++it)230 if ( (*it)->isReadyToSpawn() || this->bForceSpawn_)231 this->spawnPlayer( *it);231 for (std::map<PlayerInfo*, PlayerState::Enum>::iterator it = this->players_.begin(); it != this->players_.end(); ++it) 232 if (it->first->isReadyToSpawn() || this->bForceSpawn_) 233 this->spawnPlayer(it->first); 232 234 } 233 235 234 236 void Gametype::spawnDeadPlayersIfRequested() 235 237 { 236 for (std:: set<PlayerInfo*>::iterator it = this->players_.begin(); it != this->players_.end(); ++it)237 if ( !(*it)->getControllableEntity())238 if ( (*it)->isReadyToSpawn() || this->bForceSpawn_)239 this->spawnPlayer( *it);238 for (std::map<PlayerInfo*, PlayerState::Enum>::iterator it = this->players_.begin(); it != this->players_.end(); ++it) 239 if (it->second == PlayerState::Dead) 240 if (it->first->isReadyToSpawn() || this->bForceSpawn_) 241 this->spawnPlayer(it->first); 240 242 } 241 243 … … 246 248 { 247 249 player->startControl(spawnpoint->spawn()); 250 this->players_[player] = PlayerState::Alive; 248 251 } 249 252 else -
code/trunk/src/orxonox/objects/gametypes/Gametype.h
r2087 r2171 41 41 namespace orxonox 42 42 { 43 namespace PlayerState 44 { 45 enum Enum 46 { 47 Uninitialized, 48 Joined, 49 Alive, 50 Dead 51 }; 52 } 53 43 54 class _OrxonoxExport Gametype : public BaseObject, public Tickable 44 55 { … … 70 81 virtual void pawnPostSpawn(Pawn* pawn); 71 82 72 inline const std:: set<PlayerInfo*>& getPlayers() const83 inline const std::map<PlayerInfo*, PlayerState::Enum>& getPlayers() const 73 84 { return this->players_; } 74 85 … … 87 98 void removePlayer(PlayerInfo* player); 88 99 89 void assignDefaultPawnsIfNeeded() const;100 void assignDefaultPawnsIfNeeded(); 90 101 void checkStart(); 91 102 void spawnPlayer(PlayerInfo* player); … … 102 113 bool bStartCountdownRunning_; 103 114 104 std:: set<PlayerInfo*> players_;115 std::map<PlayerInfo*, PlayerState::Enum> players_; 105 116 std::set<SpawnPoint*> spawnpoints_; 106 117 SubclassIdentifier<ControllableEntity> defaultControllableEntity_;
Note: See TracChangeset
for help on using the changeset viewer.