[1940] | 1 | /* |
---|
| 2 | * ORXONOX - the hottest 3D action shooter ever to exist |
---|
| 3 | * > www.orxonox.net < |
---|
| 4 | * |
---|
| 5 | * |
---|
| 6 | * License notice: |
---|
| 7 | * |
---|
| 8 | * This program is free software; you can redistribute it and/or |
---|
| 9 | * modify it under the terms of the GNU General Public License |
---|
| 10 | * as published by the Free Software Foundation; either version 2 |
---|
| 11 | * of the License, or (at your option) any later version. |
---|
| 12 | * |
---|
| 13 | * This program is distributed in the hope that it will be useful, |
---|
| 14 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
---|
| 15 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
---|
| 16 | * GNU General Public License for more details. |
---|
| 17 | * |
---|
| 18 | * You should have received a copy of the GNU General Public License |
---|
| 19 | * along with this program; if not, write to the Free Software |
---|
| 20 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. |
---|
| 21 | * |
---|
| 22 | * Author: |
---|
| 23 | * Fabian 'x3n' Landau |
---|
| 24 | * Co-authors: |
---|
| 25 | * ... |
---|
| 26 | * |
---|
| 27 | */ |
---|
| 28 | |
---|
[1947] | 29 | #include "OrxonoxStableHeaders.h" |
---|
[1940] | 30 | #include "Gametype.h" |
---|
| 31 | |
---|
| 32 | #include "core/CoreIncludes.h" |
---|
| 33 | #include "objects/infos/PlayerInfo.h" |
---|
[1993] | 34 | #include "objects/worldentities/pawns/Spectator.h" |
---|
[1940] | 35 | |
---|
[1953] | 36 | #include "network/Host.h" |
---|
| 37 | |
---|
[1940] | 38 | namespace orxonox |
---|
| 39 | { |
---|
| 40 | CreateUnloadableFactory(Gametype); |
---|
| 41 | |
---|
| 42 | Gametype::Gametype() |
---|
| 43 | { |
---|
| 44 | RegisterObject(Gametype); |
---|
| 45 | |
---|
[1993] | 46 | this->defaultPawn_ = Class(Spectator); |
---|
[1940] | 47 | |
---|
| 48 | COUT(0) << "created Gametype" << std::endl; |
---|
| 49 | } |
---|
| 50 | |
---|
| 51 | void Gametype::addPlayer(PlayerInfo* player) |
---|
| 52 | { |
---|
| 53 | this->players_.insert(player); |
---|
| 54 | this->playerJoined(player); |
---|
[1989] | 55 | |
---|
| 56 | ControllableEntity* newpawn = this->defaultPawn_.fabricate(); |
---|
| 57 | player->startControl(newpawn); |
---|
[1940] | 58 | } |
---|
| 59 | |
---|
| 60 | void Gametype::removePlayer(PlayerInfo* player) |
---|
| 61 | { |
---|
[2006] | 62 | if (this->players_.find(player) != this->players_.end()) |
---|
| 63 | { |
---|
| 64 | player->stopControl(); |
---|
| 65 | this->players_.erase(player); |
---|
| 66 | this->playerLeft(player); |
---|
| 67 | } |
---|
[1940] | 68 | } |
---|
| 69 | |
---|
| 70 | void Gametype::playerJoined(PlayerInfo* player) |
---|
| 71 | { |
---|
[1953] | 72 | std::string message = player->getName() + " entered the game"; |
---|
| 73 | COUT(0) << message << std::endl; |
---|
| 74 | network::Host::Broadcast(message); |
---|
[1940] | 75 | } |
---|
| 76 | |
---|
| 77 | void Gametype::playerLeft(PlayerInfo* player) |
---|
| 78 | { |
---|
[1953] | 79 | std::string message = player->getName() + " left the game"; |
---|
| 80 | COUT(0) << message << std::endl; |
---|
| 81 | network::Host::Broadcast(message); |
---|
[1940] | 82 | } |
---|
[1950] | 83 | |
---|
| 84 | void Gametype::playerChangedName(PlayerInfo* player) |
---|
| 85 | { |
---|
| 86 | if (this->players_.find(player) != this->players_.end()) |
---|
| 87 | { |
---|
| 88 | if (player->getName() != player->getOldName()) |
---|
| 89 | { |
---|
[1953] | 90 | std::string message = player->getOldName() + " changed name to " + player->getName(); |
---|
| 91 | COUT(0) << message << std::endl; |
---|
| 92 | network::Host::Broadcast(message); |
---|
[1950] | 93 | } |
---|
| 94 | } |
---|
| 95 | } |
---|
[1940] | 96 | } |
---|