Changeset 8634
- Timestamp:
- May 28, 2011, 11:19:02 AM (14 years ago)
- Location:
- code/branches/tutoriallevel3/src/orxonox
- Files:
-
- 5 edited
Legend:
- Unmodified
- Added
- Removed
-
code/branches/tutoriallevel3/src/orxonox/gametypes/Gametype.cc
r8453 r8634 58 58 59 59 this->defaultControllableEntity_ = Class(Spectator); 60 61 this->bFirstTick_ = true;62 60 63 61 this->bAutoStart_ = false; … … 114 112 SUPER(Gametype, tick, dt); 115 113 116 // Activate the GametypeInfo.117 if(this->bFirstTick_)118 {119 this->gtinfo_->setActive(true);120 this->bFirstTick_ = false;121 }122 123 114 //count timer 124 115 if (timerIsActive_) … … 134 125 135 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 136 135 this->checkStart(); 136 } 137 137 else if (!this->gtinfo_->hasEnded()) 138 138 this->spawnDeadPlayersIfRequested(); … … 182 182 { 183 183 this->players_[player].state_ = PlayerState::Joined; 184 this->gtinfo_->playerEntered(player); 184 185 } 185 186 … … 396 397 if (it->first->isHumanPlayer()) 397 398 hashumanplayers = true; 398 399 // Inform the GametypeInfo that the player is ready to spawn.400 // TODO: Can it happen, that that changes?401 if(it->first->isHumanPlayer() && it->first->isReadyToSpawn())402 this->gtinfo_->playerReadyToSpawn(it->first);403 399 } 404 400 if (allplayersready && hashumanplayers) -
code/branches/tutoriallevel3/src/orxonox/gametypes/Gametype.h
r8453 r8634 167 167 168 168 SmartPtr<GametypeInfo> gtinfo_; 169 170 bool bFirstTick_; //!< Whether this is the first tick or not.171 169 172 170 bool bAutoStart_; -
code/branches/tutoriallevel3/src/orxonox/infos/GametypeInfo.cc
r8453 r8634 40 40 #include "util/Convert.h" 41 41 42 #include "controllers/HumanController.h" 42 43 #include "interfaces/GametypeMessageListener.h" 43 44 #include "interfaces/NotificationListener.h" … … 55 56 registerMemberNetworkFunction(GametypeInfo, dispatchFadingMessage); 56 57 58 registerMemberNetworkFunction(GametypeInfo, changedReadyToSpawn); 59 registerMemberNetworkFunction(GametypeInfo, changedSpawned); 60 57 61 /*static*/ const std::string GametypeInfo::NOTIFICATION_SENDER("gameinfo"); 58 62 … … 64 68 { 65 69 RegisterObject(GametypeInfo); 66 67 this->bActive_ = false; // At first the GametypeInfo is inactive.68 70 69 71 this->bStarted_ = false; … … 72 74 this->bStartCountdownRunning_ = false; 73 75 this->counter_ = 0; 76 this->spawned_ = false; 77 this->readyToSpawn_ = false; 74 78 75 79 this->registerVariables(); … … 92 96 /** 93 97 @brief 94 Is called when the activity has changed.95 */96 void GametypeInfo::changedActivity(void)97 {98 SUPER(GametypeInfo, changedActivity);99 100 // If the GametypeInfo has become active the "Press [Fire] to start the match" notification is sent.101 if(this->isActive())102 NotificationListener::sendNotification("Press [Fire] to start the match", GametypeInfo::NOTIFICATION_SENDER);103 }104 105 /**106 @brief107 98 Is called when the game has changed to started. 108 99 */ … … 129 120 void GametypeInfo::changedStartCountdownRunning(void) 130 121 { 131 // Clear the notifications if the countdown has stopped running.132 if(!this->hasStarted() && !this->isStartCountdownRunning() && !this->hasEnded())133 NotificationListener::sendCommand("clear", GametypeInfo::NOTIFICATION_SENDER);134 122 // Send first countdown notification if the countdown has started. 135 if( !this->hasStarted() && this->isStartCountdownRunning() && !this->hasEnded())123 if(this->isReadyToSpawn() && !this->hasStarted() && this->isStartCountdownRunning() && !this->hasEnded()) 136 124 NotificationListener::sendNotification(multi_cast<std::string>(this->counter_), GametypeInfo::NOTIFICATION_SENDER); 137 125 } … … 144 132 { 145 133 // Send countdown notification if the counter has gone down. 146 if( !this->hasStarted() && this->isStartCountdownRunning() && !this->hasEnded())134 if(this->isReadyToSpawn() && !this->hasStarted() && this->isStartCountdownRunning() && !this->hasEnded()) 147 135 NotificationListener::sendNotification(multi_cast<std::string>(this->counter_), GametypeInfo::NOTIFICATION_SENDER); 148 136 } … … 150 138 /** 151 139 @brief 152 Is called when a player has become ready to spawn. 153 @param player 154 The player that has become ready to spawn. 155 */ 156 void GametypeInfo::changedReadyToSpawn(PlayerInfo* player) 157 { 158 // Send "Waiting for other players" over the network to the right player if a player has become ready to spawn. 159 if(!this->hasStarted() && !this->isStartCountdownRunning() && !this->hasEnded()) 160 NotificationListener::sendNotification("Waiting for other players", GametypeInfo::NOTIFICATION_SENDER, notificationMessageType::info, notificationSendMode::network, player->getClientID()); 161 // Clear the notifications if the player has respawned. 162 if(this->hasStarted() && !this->hasEnded()) 163 NotificationListener::sendCommand("clear", GametypeInfo::NOTIFICATION_SENDER, notificationSendMode::network, player->getClientID()); 140 Inform the GametypeInfo that the local player has changed its ready to spawn status. 141 @param ready 142 Whether the player has become ready to spawn or not. 143 */ 144 void GametypeInfo::changedReadyToSpawn(bool ready) 145 { 146 if(this->readyToSpawn_ == ready) 147 return; 148 149 this->readyToSpawn_ = ready; 150 151 // Send "Waiting for other players" if the player is ready to spawn but the game has not yet started nor is the countdown running. 152 if(this->readyToSpawn_ && !this->hasStarted() && !this->isStartCountdownRunning() && !this->hasEnded()) 153 NotificationListener::sendNotification("Waiting for other players", GametypeInfo::NOTIFICATION_SENDER); 154 // Send current countdown if the player is ready to spawn and the countdown has already started. 155 else if(this->readyToSpawn_ && !this->hasStarted() && this->isStartCountdownRunning() && !this->hasEnded()) 156 NotificationListener::sendNotification(multi_cast<std::string>(this->counter_), GametypeInfo::NOTIFICATION_SENDER); 164 157 } 165 158 … … 241 234 void GametypeInfo::startStartCountdown(void) 242 235 { 243 if(this->bStartCountdownRunning_) 244 return; 245 246 this->bStartCountdownRunning_ = true; 247 this->changedStartCountdownRunning(); 236 if(GameMode::isMaster()) 237 { 238 if(this->bStartCountdownRunning_) 239 return; 240 241 this->bStartCountdownRunning_ = true; 242 this->changedStartCountdownRunning(); 243 } 248 244 } 249 245 … … 254 250 void GametypeInfo::stopStartCountdown(void) 255 251 { 256 if(!this->bStartCountdownRunning_) 257 return; 258 259 this->bStartCountdownRunning_ = false; 260 this->changedStartCountdownRunning(); 252 if(GameMode::isMaster()) 253 { 254 if(!this->bStartCountdownRunning_) 255 return; 256 257 this->bStartCountdownRunning_ = false; 258 this->changedStartCountdownRunning(); 259 } 261 260 } 262 261 … … 269 268 void GametypeInfo::playerReadyToSpawn(PlayerInfo* player) 270 269 { 271 // If the player has spawned already. 272 if(this->spawned_.find(player) != this->spawned_.end()) 273 return; 274 275 this->spawned_.insert(player); 276 this->changedReadyToSpawn(player); 270 if(GameMode::isMaster()) 271 { 272 // If the player has spawned already. 273 if(this->spawnedPlayers_.find(player) != this->spawnedPlayers_.end()) 274 return; 275 276 this->spawnedPlayers_.insert(player); 277 this->setReadyToSpawnHelper(player, true); 278 } 277 279 } 278 280 … … 285 287 void GametypeInfo::pawnKilled(PlayerInfo* player) 286 288 { 287 NotificationListener::sendNotification("Press [Fire] to respawn", GametypeInfo::NOTIFICATION_SENDER, notificationMessageType::info, notificationSendMode::network, player->getClientID()); 288 // Remove the player from the list of players that have spawned, since it currently is not. 289 this->spawned_.erase(player); 289 if(GameMode::isMaster()) 290 { 291 NotificationListener::sendNotification("Press [Fire] to respawn", GametypeInfo::NOTIFICATION_SENDER, notificationMessageType::info, notificationSendMode::network, player->getClientID()); 292 // Remove the player from the list of players that have spawned, since it currently is not. 293 this->spawnedPlayers_.erase(player); 294 this->setReadyToSpawnHelper(player, false); 295 this->setSpawnedHelper(player, false); 296 } 290 297 } 291 298 … … 298 305 void GametypeInfo::playerSpawned(PlayerInfo* player) 299 306 { 300 if(this->hasStarted() && !this->hasEnded()) 301 NotificationListener::sendCommand("clear", GametypeInfo::NOTIFICATION_SENDER, notificationSendMode::network, player->getClientID()); 302 } 307 if(GameMode::isMaster()) 308 { 309 if(this->hasStarted() && !this->hasEnded()) 310 { 311 //NotificationListener::sendCommand("clear", GametypeInfo::NOTIFICATION_SENDER, notificationSendMode::network, player->getClientID()); 312 this->setSpawnedHelper(player, true); 313 } 314 } 315 } 316 317 /** 318 @brief 319 Inform the GametypeInfo that the local player has changed its spawned status. 320 @param spawned 321 Whether the local player has changed to spawned or to not spawned. 322 */ 323 void GametypeInfo::changedSpawned(bool spawned) 324 { 325 if(this->spawned_ == spawned) 326 return; 327 328 this->spawned_ = spawned; 329 // Clear the notifications if the Player has spawned. 330 if(this->spawned_ && !this->hasEnded()) 331 NotificationListener::sendCommand("clear", GametypeInfo::NOTIFICATION_SENDER); 332 } 333 334 /** 335 @brief 336 Inform the GametypeInfo about a player that has entered, 337 @param player 338 The player that has entered. 339 */ 340 void GametypeInfo::playerEntered(PlayerInfo* player) 341 { 342 if(GameMode::isMaster()) 343 { 344 // Display "Press [Fire] to start the match" if the game has not yet ended. 345 if(!this->hasEnded()) 346 NotificationListener::sendNotification("Press [Fire] to start the match", GametypeInfo::NOTIFICATION_SENDER, notificationMessageType::info, notificationSendMode::network, player->getClientID()); 347 // Else display "Game has ended". 348 else 349 NotificationListener::sendNotification("Game has ended", GametypeInfo::NOTIFICATION_SENDER, notificationMessageType::info, notificationSendMode::network, player->getClientID()); 350 } 351 } 352 353 /** 354 @brief 355 Helper method. Sends changedReadyToSpawn notifiers over the network. 356 @param player 357 The player that has changed its ready to spawn status. 358 @param ready 359 The new ready to spawn status. 360 */ 361 void GametypeInfo::setReadyToSpawnHelper(PlayerInfo* player, bool ready) 362 { 363 if(GameMode::isMaster()) 364 { 365 if(player->getClientID() == CLIENTID_SERVER) 366 this->changedReadyToSpawn(ready); 367 else 368 callMemberNetworkFunction(GametypeInfo, changedReadyToSpawn, this->getObjectID(), player->getClientID(), ready); 369 } 370 } 371 372 /** 373 @brief 374 Helper method. Sends changedSpawned notifiers over the network. 375 @param player 376 The player that has changed its spawned status. 377 @param ready 378 The new spawned status. 379 */ 380 void GametypeInfo::setSpawnedHelper(PlayerInfo* player, bool spawned) 381 { 382 if(GameMode::isMaster()) 383 { 384 if(player->getClientID() == CLIENTID_SERVER) 385 this->changedSpawned(spawned); 386 else 387 callMemberNetworkFunction(GametypeInfo, changedSpawned, this->getObjectID(), player->getClientID(), spawned); 388 } 389 } 390 391 // Announce messages. 392 // TODO: Replace with notifications. 303 393 304 394 void GametypeInfo::sendAnnounceMessage(const std::string& message) -
code/branches/tutoriallevel3/src/orxonox/infos/GametypeInfo.h
r8453 r8634 61 61 virtual ~GametypeInfo(); 62 62 63 virtual void changedActivity(void); // Is called when the activity has changed.64 65 63 /** 66 64 @brief Get whether the game has started yet. … … 103 101 void changedCountdownCounter(void); // Is called when the start countdown counter has changed. 104 102 103 /** 104 @brief Get whether the local player is ready to spawn. 105 @return Returns true if the player is ready to spawn, false if not. 106 */ 107 inline bool isReadyToSpawn() const 108 { return this->readyToSpawn_; } 109 void changedReadyToSpawn(bool ready); // Inform the GametypeInfo that the local player has changed its spawned status. 110 111 /** 112 @brief Get whether the local player is spawned. 113 @return Returns true if the local player is currently spawned, false if not. 114 */ 115 inline bool isSpawned() const 116 { return this->spawned_; } 117 void changedSpawned(bool spawned); // Inform the GametypeInfo that the local player has changed its spawned status. 118 105 119 inline const std::string& getHUDTemplate() const 106 120 { return this->hudtemplate_; } … … 120 134 121 135 protected: 122 void changedReadyToSpawn(PlayerInfo* player); // Is called when a player has become ready to spawn.123 124 136 void start(void); // Inform the GametypeInfo that the game has started. 125 137 void end(void); // Inform the GametypeInfo that the game has ended. … … 132 144 void pawnKilled(PlayerInfo* player); // Inform the GametypeInfo about a player whose Pawn has been killed. 133 145 void playerSpawned(PlayerInfo* player); // Inform the GametypeInfo about a player that has spawned. 146 void playerEntered(PlayerInfo* player); // Inform the GametypeInfo about a player that has entered, 134 147 135 148 inline void setHUDTemplate(const std::string& templateName) … … 138 151 private: 139 152 void registerVariables(); 153 void setSpawnedHelper(PlayerInfo* player, bool spawned); // Helper method. Sends changedReadyToSpawn notifiers over the network. 154 void setReadyToSpawnHelper(PlayerInfo* player, bool ready); // Helper method. Sends changedSpawned notifiers over the network. 140 155 141 156 static const std::string NOTIFICATION_SENDER; //!< The name of the sender for the sending of notifications. … … 148 163 std::string hudtemplate_; 149 164 150 std::set<PlayerInfo*> spawned_; //!< A set of players that are currently spawned. 165 std::set<PlayerInfo*> spawnedPlayers_; //!< A set of players that are currently spawned. 166 bool spawned_; //!< Whether the local Player is currently spawned. 167 bool readyToSpawn_; //!< Whether the local Player is ready to spawn. 151 168 }; 152 169 } -
code/branches/tutoriallevel3/src/orxonox/interfaces/NotificationListener.cc
r8453 r8634 82 82 else if(GameMode::isServer() && sendMode == notificationSendMode::network && Host::getPlayerID() != clientId) 83 83 { 84 callStaticNetworkFunction(NotificationListener::sendHelper, clientId, message, sender, (unsigned int)messageType);84 callStaticNetworkFunction(NotificationListener::sendHelper, clientId, message, sender, isCommand, (unsigned int)messageType); 85 85 } 86 86 else if(GameMode::isServer() && sendMode == notificationSendMode::broadcast) 87 87 { 88 88 // TODO: Works as intended? 89 callStaticNetworkFunction(NotificationListener::sendHelper, NETWORK_PEER_ID_BROADCAST, message, sender, (unsigned int)messageType);89 callStaticNetworkFunction(NotificationListener::sendHelper, NETWORK_PEER_ID_BROADCAST, message, sender, isCommand, (unsigned int)messageType); 90 90 } 91 91 }
Note: See TracChangeset
for help on using the changeset viewer.