Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Ignore:
Timestamp:
Oct 19, 2008, 9:50:36 PM (16 years ago)
Author:
landauf
Message:

added chat overlay

Location:
code/branches/objecthierarchy/src/orxonox/objects
Files:
4 edited

Legend:

Unmodified
Added
Removed
  • code/branches/objecthierarchy/src/orxonox/objects/gametypes/Gametype.cc

    r1950 r1953  
    3434#include "objects/infos/PlayerInfo.h"
    3535
     36#include "network/Host.h"
     37
    3638namespace orxonox
    3739{
     
    5456            return (*it);
    5557
     58        return 0;
     59    }
     60
     61    PlayerInfo* Gametype::getClient(unsigned int clientID)
     62    {
     63        Gametype* gametype = Gametype::getCurrentGametype();
     64        if (gametype)
     65        {
     66            std::map<unsigned int, PlayerInfo*>::const_iterator it = gametype->clients_.find(clientID);
     67            if (it != gametype->clients_.end())
     68                return it->second;
     69        }
     70        else
     71        {
     72            for (ObjectList<PlayerInfo>::iterator it = ObjectList<PlayerInfo>::begin(); it != ObjectList<PlayerInfo>::end(); ++it)
     73                if (it->getClientID() == clientID)
     74                    return (*it);
     75        }
    5676        return 0;
    5777    }
     
    112132    void Gametype::playerJoined(PlayerInfo* player)
    113133    {
    114         COUT(0) << "player " << player->getName() << " joined" << std::endl;
     134        std::string message = player->getName() + " entered the game";
     135        COUT(0) << message << std::endl;
     136        network::Host::Broadcast(message);
    115137    }
    116138
    117139    void Gametype::playerLeft(PlayerInfo* player)
    118140    {
    119         COUT(0) << "player " << player->getName() << " left" << std::endl;
     141        std::string message = player->getName() + " left the game";
     142        COUT(0) << message << std::endl;
     143        network::Host::Broadcast(message);
    120144    }
    121145
     
    126150            if (player->getName() != player->getOldName())
    127151            {
    128                 COUT(0) << "player " << player->getOldName() << " changed name to " << player->getName() << std::endl;
     152                std::string message = player->getOldName() + " changed name to " + player->getName();
     153                COUT(0) << message << std::endl;
     154                network::Host::Broadcast(message);
    129155            }
    130156        }
  • code/branches/objecthierarchy/src/orxonox/objects/gametypes/Gametype.h

    r1950 r1953  
    5050            static void listPlayers();
    5151
     52            inline const std::map<unsigned int, PlayerInfo*>& getClients() const
     53                { return this->clients_; }
     54            inline const std::set<PlayerInfo*>& getPlayers() const
     55                { return this->players_; }
     56            static PlayerInfo* getClient(unsigned int clientID);
     57
    5258        protected:
    5359            virtual void clientConnected(unsigned int clientID);
  • code/branches/objecthierarchy/src/orxonox/objects/infos/PlayerInfo.cc

    r1950 r1953  
    5151
    5252        this->ping_ = -1;
    53         this->clientID_ = (unsigned int)-1;
     53        this->clientID_ = network::CLIENTID_UNKNOWN;
    5454        this->bLocalPlayer_ = Core::isStandalone();
    5555        this->bLocalPlayer_ = false;
     
    6060        this->registerVariables();
    6161
    62         COUT(0) << "created PlayerInfo (" << this->getObjectID() << ")" << std::endl;
     62//COUT(0) << "created PlayerInfo (" << this->getObjectID() << ")" << std::endl;
    6363    }
    6464
     
    6868        if (gametype)
    6969            gametype->removePlayer(this);
    70         COUT(0) << "destroyed PlayerInfo (" << this->getObjectID() << ")" << std::endl;
     70//COUT(0) << "destroyed PlayerInfo (" << this->getObjectID() << ")" << std::endl;
    7171    }
    7272
    7373    void PlayerInfo::setConfigValues()
    7474    {
    75         SetConfigValue(playerName_, "Player").callback(this, &PlayerInfo::checkName);
     75        SetConfigValue(nick_, "Player").callback(this, &PlayerInfo::checkNick);
    7676    }
    7777
    78     void PlayerInfo::checkName()
     78    void PlayerInfo::checkNick()
    7979    {
    80 std::cout << "# PI(" << this->getObjectID() << "): checkName: " << this->bLocalPlayer_ << std::endl;
    81         if (this->bLocalPlayer_ && Core::isMaster())
    82             this->setName(this->playerName_);
     80//std::cout << "# PI(" << this->getObjectID() << "): checkName: " << this->bLocalPlayer_ << std::endl;
     81        if (this->bLocalPlayer_)
     82        {
     83            this->playerName_ = this->nick_;
     84
     85            if (Core::isMaster())
     86                this->setName(this->playerName_);
     87        }
    8388    }
    8489
    8590    void PlayerInfo::changedName()
    8691    {
    87 std::cout << "# PI(" << this->getObjectID() << "): changedName to " << this->getName() << std::endl;
     92//std::cout << "# PI(" << this->getObjectID() << "): changedName to " << this->getName() << std::endl;
    8893        Gametype* gametype = Gametype::getCurrentGametype();
    8994        if (gametype)
     
    103108    void PlayerInfo::clientChangedName()
    104109    {
    105 std::cout << "# PI(" << this->getObjectID() << "): clientChangedName() to " << this->playerName_ << std::endl;
     110//std::cout << "# PI(" << this->getObjectID() << "): clientChangedName() from " << this->getName() << " to " << this->playerName_ << std::endl;
    106111        this->setName(this->playerName_);
    107112    }
     
    109114    void PlayerInfo::checkClientID()
    110115    {
    111 std::cout << "# PI(" << this->getObjectID() << "): checkClientID()" << std::endl;
     116//std::cout << "# PI(" << this->getObjectID() << "): checkClientID()" << std::endl;
    112117        this->bHumanPlayer_ = true;
    113118
    114119        if (this->clientID_ == network::Host::getPlayerID())
    115120        {
    116 std::cout << "# PI(" << this->getObjectID() << "): checkClientID(): it's the client's ID" << std::endl;
     121//std::cout << "# PI(" << this->getObjectID() << "): checkClientID(): it's the client's ID" << std::endl;
    117122            this->bLocalPlayer_ = true;
     123            this->playerName_ = this->nick_;
    118124//std::cout << "# PI(" << this->getObjectID() << "): checkClientID(): name: " << this->getName() << std::endl;
    119125
    120126            if (Core::isClient())
    121127            {
    122 std::cout << "# PI(" << this->getObjectID() << "): checkClientID(): we're on a client: set object mode to bidirectional" << std::endl;
     128//std::cout << "# PI(" << this->getObjectID() << "): checkClientID(): we're on a client: set object mode to bidirectional" << std::endl;
    123129                this->setObjectMode(network::direction::bidirectional);
    124                 this->playerName_ += "blub";
    125 std::cout << "# PI(" << this->getObjectID() << "): checkClientID(): proposed name: " << this->playerName_ << std::endl;
     130//std::cout << "# PI(" << this->getObjectID() << "): checkClientID(): proposed name: " << this->playerName_ << std::endl;
    126131            }
    127132            else
    128133            {
    129 std::cout << "# PI(" << this->getObjectID() << "): checkClientID(): we're not on a client: finish setup" << std::endl;
     134//std::cout << "# PI(" << this->getObjectID() << "): checkClientID(): we're not on a client: finish setup" << std::endl;
    130135                this->clientChangedName();
    131136                this->bFinishedSetup_ = true;
     
    137142    void PlayerInfo::finishedSetup()
    138143    {
    139 std::cout << "# PI(" << this->getObjectID() << "): finishedSetup(): " << this->bFinishedSetup_ << std::endl;
     144//std::cout << "# PI(" << this->getObjectID() << "): finishedSetup(): " << this->bFinishedSetup_ << std::endl;
    140145        if (Core::isClient())
    141146        {
    142 std::cout << "# PI(" << this->getObjectID() << "): finishedSetup(): we're a client: finish setup" << std::endl;
     147//std::cout << "# PI(" << this->getObjectID() << "): finishedSetup(): we're a client: finish setup" << std::endl;
    143148            this->bFinishedSetup_ = true;
    144149        }
    145150        else if (this->bFinishedSetup_)
    146151        {
    147 std::cout << "# PI(" << this->getObjectID() << "): finishedSetup(): we're a server: add player" << std::endl;
     152//std::cout << "# PI(" << this->getObjectID() << "): finishedSetup(): we're a server: add player" << std::endl;
    148153            Gametype* gametype = Gametype::getCurrentGametype();
    149154            if (gametype)
     
    152157        else
    153158        {
    154 std::cout << "# PI(" << this->getObjectID() << "): finishedSetup(): we're a server: client not yet finished" << std::endl;
     159//std::cout << "# PI(" << this->getObjectID() << "): finishedSetup(): we're a server: client not yet finished" << std::endl;
    155160        }
    156161    }
  • code/branches/objecthierarchy/src/orxonox/objects/infos/PlayerInfo.h

    r1946 r1953  
    6060            void checkClientID();
    6161            void finishedSetup();
    62             void checkName();
     62            void checkNick();
    6363            void clientChangedName();
    6464
     
    7070
    7171            std::string playerName_;
     72            std::string nick_;
    7273    };
    7374}
Note: See TracChangeset for help on using the changeset viewer.