1 //
2 //  SuperTuxKart - a fun racing game with go-kart
3 //  Copyright (C) 2013-2015 SuperTuxKart-Team
4 //
5 //  This program is free software; you can redistribute it and/or
6 //  modify it under the terms of the GNU General Public License
7 //  as published by the Free Software Foundation; either version 3
8 //  of the License, or (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 /*! \file remote_kart_info.hpp
20  */
21 
22 #ifndef HEADER_REMOTE_KART_INFO_HPP
23 #define HEADER_REMOTE_KART_INFO_HPP
24 
25 #include <limits>
26 #include <memory>
27 #include <string>
28 #include <vector>
29 #include <irrString.h>
30 
31 enum KartTeam : int8_t
32 {
33     KART_TEAM_NONE=-1,
34     KART_TEAM_RED=0,
35     KART_TEAM_BLUE=1,
36 };
37 
38 /** Handicap per player. */
39 enum HandicapLevel : uint8_t
40 {
41     HANDICAP_NONE = 0,
42     HANDICAP_MEDIUM,
43     HANDICAP_COUNT
44 };
45 
46 class NetworkPlayerProfile;
47 
48 class RemoteKartInfo
49 {
50         std::string         m_kart_name;
51         irr::core::stringw  m_user_name;
52         int                 m_local_player_id;
53         int                 m_global_player_id;
54         uint32_t            m_host_id;
55         KartTeam            m_kart_team;
56         bool                m_network_player;
57         HandicapLevel       m_handicap;
58         float               m_default_kart_color;
59         uint32_t            m_online_id;
60         std::string         m_country_code;
61         std::weak_ptr<NetworkPlayerProfile> m_profile;
62 public:
RemoteKartInfo(int player_id,const std::string & kart_name,const irr::core::stringw & user_name,uint32_t host_id,bool network)63      RemoteKartInfo(int player_id, const std::string& kart_name,
64                     const irr::core::stringw& user_name, uint32_t host_id,
65                     bool network)
66                   : m_kart_name(kart_name), m_user_name(user_name),
67                     m_local_player_id(player_id), m_global_player_id(-1),
68                     m_host_id(host_id), m_kart_team(KART_TEAM_NONE),
69                     m_network_player(network),
70                     m_handicap(HANDICAP_NONE),
71                     m_default_kart_color(0.0f), m_online_id(0)
72      {}
RemoteKartInfo(const std::string & kart_name)73      RemoteKartInfo(const std::string& kart_name) : m_kart_name(kart_name),
74                     m_user_name(""), m_local_player_id(-1),
75                     m_global_player_id(-1),
76                     m_host_id(std::numeric_limits<uint32_t>::max()),
77                     m_kart_team(KART_TEAM_NONE), m_network_player(false),
78                     m_handicap(HANDICAP_NONE),
79                     m_default_kart_color(0.0f), m_online_id(0)
80      {}
RemoteKartInfo()81      RemoteKartInfo() : m_kart_name(""), m_user_name(""),
82                     m_local_player_id(-1), m_global_player_id(-1),
83                     m_host_id(std::numeric_limits<uint32_t>::max()),
84                     m_kart_team(KART_TEAM_NONE), m_network_player(false),
85                     m_handicap(HANDICAP_NONE),
86                     m_default_kart_color(0.0f), m_online_id(0)
87      {}
setKartName(const std::string & n)88     void setKartName(const std::string& n)   { m_kart_name = n;           }
setPlayerName(const irr::core::stringw & u)89     void setPlayerName(const irr::core::stringw& u) { m_user_name = u;    }
setHostId(uint32_t id)90     void setHostId(uint32_t id)              { m_host_id = id;            }
setLocalPlayerId(int id)91     void setLocalPlayerId(int id)            { m_local_player_id = id;    }
setGlobalPlayerId(int id)92     void setGlobalPlayerId(int id)           { m_global_player_id = id;   }
setKartTeam(KartTeam team)93     void setKartTeam(KartTeam team)      { m_kart_team = team;      }
setNetworkPlayer(bool value)94     void setNetworkPlayer(bool value)        { m_network_player = value;  }
setDefaultKartColor(float value)95     void setDefaultKartColor(float value) { m_default_kart_color = value; }
setHandicap(HandicapLevel value)96     void setHandicap(HandicapLevel value)    { m_handicap = value;        }
setOnlineId(uint32_t id)97     void setOnlineId(uint32_t id)            { m_online_id = id;          }
getHostId() const98     uint32_t getHostId() const               { return m_host_id;          }
getLocalPlayerId() const99     int  getLocalPlayerId() const            { return m_local_player_id;  }
getGlobalPlayerId() const100     int  getGlobalPlayerId() const           { return m_global_player_id; }
isNetworkPlayer() const101     bool  isNetworkPlayer() const            { return m_network_player;   }
getKartName() const102     const std::string& getKartName() const   { return m_kart_name;        }
getPlayerName() const103     const irr::core::stringw& getPlayerName() const { return m_user_name; }
getKartTeam() const104     KartTeam getKartTeam() const               { return m_kart_team;      }
getHandicap() const105     HandicapLevel getHandicap() const        { return m_handicap;         }
getDefaultKartColor() const106     float getDefaultKartColor() const      { return m_default_kart_color; }
getOnlineId() const107     uint32_t getOnlineId() const           { return m_online_id;          }
setCountryCode(const std::string & id)108     void setCountryCode(const std::string& id) { m_country_code = id;     }
getCountryCode() const109     const std::string& getCountryCode() const { return m_country_code;    }
setNetworkPlayerProfile(std::weak_ptr<NetworkPlayerProfile> npp)110     void setNetworkPlayerProfile(
111         std::weak_ptr<NetworkPlayerProfile> npp)       { m_profile = npp; }
getNetworkPlayerProfile() const112     std::weak_ptr<NetworkPlayerProfile> getNetworkPlayerProfile() const
113                                                       { return m_profile; }
disconnected() const114     bool disconnected() const               { return m_profile.expired(); }
isReserved() const115     bool isReserved() const
116               { return m_host_id == std::numeric_limits<uint32_t>::max(); }
makeReserved()117     void makeReserved()
118     {
119         m_host_id = std::numeric_limits<uint32_t>::max();
120         m_profile.reset();
121     }
122     void copyFrom(std::shared_ptr<NetworkPlayerProfile> p,
123                   unsigned local_id);
operator <(const RemoteKartInfo & other) const124     bool operator<(const RemoteKartInfo& other) const
125     {
126         return ((m_host_id<other.m_host_id) ||
127                 (m_host_id==other.m_host_id && m_local_player_id<other.m_local_player_id));
128     }
129 };   // RemoteKartInfo
130 
131 typedef std::vector<RemoteKartInfo> RemoteKartInfoList;
132 
133 #endif
134