1 /****************************************************************************** 2 * Warmux is a convivial mass murder game. 3 * Copyright (C) 2001-2011 Warmux Team. 4 * 5 * This program is free software; you can redistribute it and/or modify 6 * it under the terms of the GNU General Public License as published by 7 * the Free Software Foundation; either version 2 of the License, or 8 * (at your option) any later version. 9 * 10 * This program is distributed in the hope that it will be useful, 11 * but WITHOUT ANY WARRANTY; without even the implied warranty of 12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 * GNU General Public License for more details. 14 * 15 * You should have received a copy of the GNU General Public License 16 * along with this program; if not, write to the Free Software 17 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA 18 ****************************************************************************** 19 * A network player (local or remote) 20 *****************************************************************************/ 21 22 #ifndef WARMUX_PLAYER_H 23 #define WARMUX_PLAYER_H 24 //----------------------------------------------------------------------------- 25 #include <list> 26 #include <string> 27 #include <WARMUX_types.h> 28 #include <WARMUX_team_config.h> 29 //----------------------------------------------------------------------------- 30 31 class Player 32 { 33 friend void WARMUX_DisconnectPlayer(Player& player); 34 public: 35 typedef enum { 36 STATE_ERROR, 37 STATE_NOT_INITIALIZED, 38 STATE_INITIALIZED, 39 STATE_READY, 40 STATE_CHECKED, 41 STATE_NEXT_GAME 42 } State; 43 private: 44 uint player_id; 45 std::string nickname; 46 std::list<ConfigTeam> owned_teams; 47 void UpdateNickname(); 48 std::list<ConfigTeam>::iterator FindTeamWithId(const std::string team_id); 49 State state; 50 public: 51 Player(uint player_id, const std::string& nickname); 52 Player(); ~Player()53 ~Player() { Disconnect(); } 54 // This is misleading: it is assumed this doesn't use the network, check ~DistantComputer() Disconnect()55 void Disconnect() 56 { 57 // It's up to the program using class Player to define WARMUX_DisconnectPlayer() 58 WARMUX_DisconnectPlayer(*this); 59 } 60 SetId(uint _player_id)61 void SetId(uint _player_id) { player_id = _player_id; } GetId()62 uint GetId() const { return player_id; } 63 SetNickname(const std::string & _nickname)64 void SetNickname(const std::string& _nickname) { nickname = _nickname; } GetNickname()65 const std::string& GetNickname() const { return nickname; } 66 67 bool AddTeam(const ConfigTeam& team_conf); 68 bool RemoveTeam(const std::string& team_id); 69 bool UpdateTeam(const std::string& old_team_id, const ConfigTeam& team_conf); 70 GetNbTeams()71 uint GetNbTeams() const { return owned_teams.size(); } GetTeams()72 const std::list<ConfigTeam> & GetTeams() const { return owned_teams; } 73 SetState(State _state)74 void SetState(State _state) { state = _state; } GetState()75 State GetState() const { return state; } 76 77 static std::string GetDefaultNickname(); 78 }; 79 80 // It's up to the program using class Player to define WARMUX_DisconnectPlayer(); 81 // Currently it is expected not to use the network: check ~DistantComputer() 82 extern void WARMUX_DisconnectPlayer(Player& player); 83 84 #endif 85 86