- Timestamp:
- Nov 8, 2008, 10:05:06 PM (16 years ago)
- Location:
- code/branches/objecthierarchy/src/orxonox/objects
- Files:
-
- 6 edited
Legend:
- Unmodified
- Added
- Removed
-
code/branches/objecthierarchy/src/orxonox/objects/gametypes/Gametype.cc
r2112 r2160 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"; … … 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 { … … 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/branches/objecthierarchy/src/orxonox/objects/gametypes/Gametype.h
r2072 r2160 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_; -
code/branches/objecthierarchy/src/orxonox/objects/infos/HumanPlayer.cc
r2112 r2160 46 46 RegisterObject(HumanPlayer); 47 47 48 this->server_ ready_ = Core::isMaster();49 this->client_ ready_ = false;48 this->server_initialized_ = Core::isMaster(); 49 this->client_initialized_ = false; 50 50 51 51 this->bHumanPlayer_ = true; … … 70 70 71 71 REGISTERDATA(this->clientID_, direction::toclient, new NetworkCallback<HumanPlayer>(this, &HumanPlayer::networkcallback_clientIDchanged)); 72 REGISTERDATA(this->server_ ready_, direction::toclient, new NetworkCallback<HumanPlayer>(this, &HumanPlayer::networkcallback_server_ready));73 REGISTERDATA(this->client_ ready_, direction::toserver, new NetworkCallback<HumanPlayer>(this, &HumanPlayer::networkcallback_client_ready));72 REGISTERDATA(this->server_initialized_, direction::toclient, new NetworkCallback<HumanPlayer>(this, &HumanPlayer::networkcallback_server_initialized)); 73 REGISTERDATA(this->client_initialized_, direction::toserver, new NetworkCallback<HumanPlayer>(this, &HumanPlayer::networkcallback_client_initialized)); 74 74 } 75 75 … … 96 96 this->bLocalPlayer_ = true; 97 97 this->synchronize_nick_ = this->nick_; 98 this->client_ ready_ = true;98 this->client_initialized_ = true; 99 99 100 100 if (!Core::isMaster()) … … 107 107 } 108 108 109 void HumanPlayer::networkcallback_server_ ready()109 void HumanPlayer::networkcallback_server_initialized() 110 110 { 111 this->client_ ready_ = true;111 this->client_initialized_ = true; 112 112 } 113 113 114 void HumanPlayer::networkcallback_client_ ready()114 void HumanPlayer::networkcallback_client_initialized() 115 115 { 116 116 if (this->getGametype()) … … 118 118 } 119 119 120 bool HumanPlayer::is Ready() const120 bool HumanPlayer::isInitialized() const 121 121 { 122 return (this->server_ ready_ && this->client_ready_);122 return (this->server_initialized_ && this->client_initialized_); 123 123 } 124 124 -
code/branches/objecthierarchy/src/orxonox/objects/infos/HumanPlayer.h
r2072 r2160 47 47 void setConfigValues(); 48 48 49 bool is Ready() const;49 bool isInitialized() const; 50 50 float getPing() const; 51 51 float getPacketLossRatio() const; … … 57 57 void networkcallback_changednick(); 58 58 void networkcallback_clientIDchanged(); 59 void networkcallback_server_ ready();60 void networkcallback_client_ ready();59 void networkcallback_server_initialized(); 60 void networkcallback_client_initialized(); 61 61 62 62 std::string nick_; 63 63 std::string synchronize_nick_; 64 bool server_ ready_;65 bool client_ ready_;64 bool server_initialized_; 65 bool client_initialized_; 66 66 }; 67 67 } -
code/branches/objecthierarchy/src/orxonox/objects/infos/PlayerInfo.cc
r2112 r2160 55 55 PlayerInfo::~PlayerInfo() 56 56 { 57 if (this-> isInitialized())57 if (this->BaseObject::isInitialized()) 58 58 { 59 59 this->stopControl(this->controllableEntity_); … … 76 76 void PlayerInfo::changedName() 77 77 { 78 if (this->is Ready() && this->getGametype())78 if (this->isInitialized() && this->getGametype()) 79 79 this->getGametype()->playerChangedName(this); 80 80 } … … 82 82 void PlayerInfo::changedGametype() 83 83 { 84 if (this->is Ready())84 if (this->isInitialized()) 85 85 { 86 86 if (this->getOldGametype()) -
code/branches/objecthierarchy/src/orxonox/objects/infos/PlayerInfo.h
r2072 r2160 55 55 inline unsigned int getClientID() const 56 56 { return this->clientID_; } 57 inline bool isReadyToSpawn() const58 { return this->bReadyToSpawn_; }59 57 60 virtual bool is Ready() const = 0;58 virtual bool isInitialized() const = 0; 61 59 virtual float getPing() const = 0; 62 60 virtual float getPacketLossRatio() const = 0; … … 64 62 inline void setReadyToSpawn(bool bReady) 65 63 { this->bReadyToSpawn_ = bReady; } 64 inline bool isReadyToSpawn() const 65 { return this->bReadyToSpawn_; } 66 66 67 67 void startControl(ControllableEntity* entity);
Note: See TracChangeset
for help on using the changeset viewer.