Changeset 1953 for code/branches/objecthierarchy/src/orxonox/objects
- Timestamp:
- Oct 19, 2008, 9:50:36 PM (16 years ago)
- 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 34 34 #include "objects/infos/PlayerInfo.h" 35 35 36 #include "network/Host.h" 37 36 38 namespace orxonox 37 39 { … … 54 56 return (*it); 55 57 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 } 56 76 return 0; 57 77 } … … 112 132 void Gametype::playerJoined(PlayerInfo* player) 113 133 { 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); 115 137 } 116 138 117 139 void Gametype::playerLeft(PlayerInfo* player) 118 140 { 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); 120 144 } 121 145 … … 126 150 if (player->getName() != player->getOldName()) 127 151 { 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); 129 155 } 130 156 } -
code/branches/objecthierarchy/src/orxonox/objects/gametypes/Gametype.h
r1950 r1953 50 50 static void listPlayers(); 51 51 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 52 58 protected: 53 59 virtual void clientConnected(unsigned int clientID); -
code/branches/objecthierarchy/src/orxonox/objects/infos/PlayerInfo.cc
r1950 r1953 51 51 52 52 this->ping_ = -1; 53 this->clientID_ = (unsigned int)-1;53 this->clientID_ = network::CLIENTID_UNKNOWN; 54 54 this->bLocalPlayer_ = Core::isStandalone(); 55 55 this->bLocalPlayer_ = false; … … 60 60 this->registerVariables(); 61 61 62 62 //COUT(0) << "created PlayerInfo (" << this->getObjectID() << ")" << std::endl; 63 63 } 64 64 … … 68 68 if (gametype) 69 69 gametype->removePlayer(this); 70 70 //COUT(0) << "destroyed PlayerInfo (" << this->getObjectID() << ")" << std::endl; 71 71 } 72 72 73 73 void PlayerInfo::setConfigValues() 74 74 { 75 SetConfigValue( playerName_, "Player").callback(this, &PlayerInfo::checkName);75 SetConfigValue(nick_, "Player").callback(this, &PlayerInfo::checkNick); 76 76 } 77 77 78 void PlayerInfo::checkN ame()78 void PlayerInfo::checkNick() 79 79 { 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 } 83 88 } 84 89 85 90 void PlayerInfo::changedName() 86 91 { 87 std::cout << "# PI(" << this->getObjectID() << "): changedName to " << this->getName() << std::endl;92 //std::cout << "# PI(" << this->getObjectID() << "): changedName to " << this->getName() << std::endl; 88 93 Gametype* gametype = Gametype::getCurrentGametype(); 89 94 if (gametype) … … 103 108 void PlayerInfo::clientChangedName() 104 109 { 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; 106 111 this->setName(this->playerName_); 107 112 } … … 109 114 void PlayerInfo::checkClientID() 110 115 { 111 std::cout << "# PI(" << this->getObjectID() << "): checkClientID()" << std::endl;116 //std::cout << "# PI(" << this->getObjectID() << "): checkClientID()" << std::endl; 112 117 this->bHumanPlayer_ = true; 113 118 114 119 if (this->clientID_ == network::Host::getPlayerID()) 115 120 { 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; 117 122 this->bLocalPlayer_ = true; 123 this->playerName_ = this->nick_; 118 124 //std::cout << "# PI(" << this->getObjectID() << "): checkClientID(): name: " << this->getName() << std::endl; 119 125 120 126 if (Core::isClient()) 121 127 { 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; 123 129 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; 126 131 } 127 132 else 128 133 { 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; 130 135 this->clientChangedName(); 131 136 this->bFinishedSetup_ = true; … … 137 142 void PlayerInfo::finishedSetup() 138 143 { 139 std::cout << "# PI(" << this->getObjectID() << "): finishedSetup(): " << this->bFinishedSetup_ << std::endl;144 //std::cout << "# PI(" << this->getObjectID() << "): finishedSetup(): " << this->bFinishedSetup_ << std::endl; 140 145 if (Core::isClient()) 141 146 { 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; 143 148 this->bFinishedSetup_ = true; 144 149 } 145 150 else if (this->bFinishedSetup_) 146 151 { 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; 148 153 Gametype* gametype = Gametype::getCurrentGametype(); 149 154 if (gametype) … … 152 157 else 153 158 { 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; 155 160 } 156 161 } -
code/branches/objecthierarchy/src/orxonox/objects/infos/PlayerInfo.h
r1946 r1953 60 60 void checkClientID(); 61 61 void finishedSetup(); 62 void checkN ame();62 void checkNick(); 63 63 void clientChangedName(); 64 64 … … 70 70 71 71 std::string playerName_; 72 std::string nick_; 72 73 }; 73 74 }
Note: See TracChangeset
for help on using the changeset viewer.