Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Ignore:
Timestamp:
May 28, 2011, 11:19:02 AM (13 years ago)
Author:
dafrick
Message:

Gametype status notifications now working.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • code/branches/tutoriallevel3/src/orxonox/infos/GametypeInfo.cc

    r8453 r8634  
    4040#include "util/Convert.h"
    4141
     42#include "controllers/HumanController.h"
    4243#include "interfaces/GametypeMessageListener.h"
    4344#include "interfaces/NotificationListener.h"
     
    5556    registerMemberNetworkFunction(GametypeInfo, dispatchFadingMessage);
    5657
     58    registerMemberNetworkFunction(GametypeInfo, changedReadyToSpawn);
     59    registerMemberNetworkFunction(GametypeInfo, changedSpawned);
     60
    5761    /*static*/ const std::string GametypeInfo::NOTIFICATION_SENDER("gameinfo");
    5862
     
    6468    {
    6569        RegisterObject(GametypeInfo);
    66 
    67         this->bActive_ = false; // At first the GametypeInfo is inactive.
    6870       
    6971        this->bStarted_ = false;
     
    7274        this->bStartCountdownRunning_ = false;
    7375        this->counter_ = 0;
     76        this->spawned_ = false;
     77        this->readyToSpawn_ = false;
    7478
    7579        this->registerVariables();
     
    9296    /**
    9397    @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     @brief
    10798        Is called when the game has changed to started.
    10899    */
     
    129120    void GametypeInfo::changedStartCountdownRunning(void)
    130121    {
    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);
    134122        // 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())
    136124            NotificationListener::sendNotification(multi_cast<std::string>(this->counter_), GametypeInfo::NOTIFICATION_SENDER);
    137125    }
     
    144132    {
    145133        // 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())
    147135            NotificationListener::sendNotification(multi_cast<std::string>(this->counter_), GametypeInfo::NOTIFICATION_SENDER);
    148136    }
     
    150138    /**
    151139    @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);
    164157    }
    165158
     
    241234    void GametypeInfo::startStartCountdown(void)
    242235    {
    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        }
    248244    }
    249245
     
    254250    void GametypeInfo::stopStartCountdown(void)
    255251    {
    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        }
    261260    }
    262261
     
    269268    void GametypeInfo::playerReadyToSpawn(PlayerInfo* player)
    270269    {
    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        }
    277279    }
    278280
     
    285287    void GametypeInfo::pawnKilled(PlayerInfo* player)
    286288    {
    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        }
    290297    }
    291298
     
    298305    void GametypeInfo::playerSpawned(PlayerInfo* player)
    299306    {
    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.
    303393
    304394    void GametypeInfo::sendAnnounceMessage(const std::string& message)
Note: See TracChangeset for help on using the changeset viewer.