SuperTuxKart
remote_kart_info.hpp
Go to the documentation of this file.
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 
22 #ifndef HEADER_REMOTE_KART_INFO_HPP
23 #define HEADER_REMOTE_KART_INFO_HPP
24 
25 #include "network/kart_data.hpp"
26 
27 #include <limits>
28 #include <memory>
29 #include <string>
30 #include <vector>
31 #include <irrString.h>
32 #include <cstdint>
33 
34 enum KartTeam : int8_t
35 {
36  KART_TEAM_NONE=-1,
37  KART_TEAM_RED=0,
38  KART_TEAM_BLUE=1,
39 };
40 
42 enum HandicapLevel : uint8_t
43 {
44  HANDICAP_NONE = 0,
45  HANDICAP_MEDIUM,
46  HANDICAP_COUNT
47 };
48 
50 
52 {
53  std::string m_kart_name;
54  irr::core::stringw m_user_name;
55  int m_local_player_id;
56  int m_global_player_id;
57  uint32_t m_host_id;
58  KartTeam m_kart_team;
59  bool m_network_player;
60  HandicapLevel m_handicap;
61  float m_default_kart_color;
62  uint32_t m_online_id;
63  std::string m_country_code;
64  std::weak_ptr<NetworkPlayerProfile> m_profile;
65  KartData m_kart_data;
66 public:
67  RemoteKartInfo(int player_id, const std::string& kart_name,
68  const irr::core::stringw& user_name, uint32_t host_id,
69  bool network)
70  : m_kart_name(kart_name), m_user_name(user_name),
71  m_local_player_id(player_id), m_global_player_id(-1),
72  m_host_id(host_id), m_kart_team(KART_TEAM_NONE),
73  m_network_player(network),
74  m_handicap(HANDICAP_NONE),
75  m_default_kart_color(0.0f), m_online_id(0)
76  {}
77  RemoteKartInfo(const std::string& kart_name) : m_kart_name(kart_name),
78  m_user_name(""), m_local_player_id(-1),
79  m_global_player_id(-1),
80  m_host_id(std::numeric_limits<uint32_t>::max()),
81  m_kart_team(KART_TEAM_NONE), m_network_player(false),
82  m_handicap(HANDICAP_NONE),
83  m_default_kart_color(0.0f), m_online_id(0)
84  {}
85  RemoteKartInfo() : m_kart_name(""), m_user_name(""),
86  m_local_player_id(-1), m_global_player_id(-1),
87  m_host_id(std::numeric_limits<uint32_t>::max()),
88  m_kart_team(KART_TEAM_NONE), m_network_player(false),
89  m_handicap(HANDICAP_NONE),
90  m_default_kart_color(0.0f), m_online_id(0)
91  {}
92  void setKartName(const std::string& n) { m_kart_name = n; }
93  void setPlayerName(const irr::core::stringw& u) { m_user_name = u; }
94  void setHostId(uint32_t id) { m_host_id = id; }
95  void setLocalPlayerId(int id) { m_local_player_id = id; }
96  void setGlobalPlayerId(int id) { m_global_player_id = id; }
97  void setKartTeam(KartTeam team) { m_kart_team = team; }
98  void setNetworkPlayer(bool value) { m_network_player = value; }
99  void setDefaultKartColor(float value) { m_default_kart_color = value; }
100  void setHandicap(HandicapLevel value) { m_handicap = value; }
101  void setOnlineId(uint32_t id) { m_online_id = id; }
102  uint32_t getHostId() const { return m_host_id; }
103  int getLocalPlayerId() const { return m_local_player_id; }
104  int getGlobalPlayerId() const { return m_global_player_id; }
105  bool isNetworkPlayer() const { return m_network_player; }
106  const std::string& getKartName() const { return m_kart_name; }
107  const irr::core::stringw& getPlayerName() const { return m_user_name; }
108  KartTeam getKartTeam() const { return m_kart_team; }
109  HandicapLevel getHandicap() const { return m_handicap; }
110  float getDefaultKartColor() const { return m_default_kart_color; }
111  uint32_t getOnlineId() const { return m_online_id; }
112  void setCountryCode(const std::string& id) { m_country_code = id; }
113  const std::string& getCountryCode() const { return m_country_code; }
114  void setKartData(const KartData& data) { m_kart_data = data; }
115  const KartData& getKartData() const { return m_kart_data; }
116  void setNetworkPlayerProfile(
117  std::weak_ptr<NetworkPlayerProfile> npp) { m_profile = npp; }
118  std::weak_ptr<NetworkPlayerProfile> getNetworkPlayerProfile() const
119  { return m_profile; }
120  bool disconnected() const { return m_profile.expired(); }
121  bool isReserved() const
122  { return m_host_id == std::numeric_limits<uint32_t>::max(); }
123  void makeReserved()
124  {
125  m_host_id = std::numeric_limits<uint32_t>::max();
126  m_profile.reset();
127  }
128  void copyFrom(std::shared_ptr<NetworkPlayerProfile> p,
129  unsigned local_id);
130  bool operator<(const RemoteKartInfo& other) const
131  {
132  return ((m_host_id<other.m_host_id) ||
133  (m_host_id==other.m_host_id && m_local_player_id<other.m_local_player_id));
134  }
135 }; // RemoteKartInfo
136 
137 typedef std::vector<RemoteKartInfo> RemoteKartInfoList;
138 
139 #endif
Definition: kart_data.hpp:12
Contains the profile of a player.
Definition: network_player_profile.hpp:42
Definition: remote_kart_info.hpp:52
HandicapLevel
Handicap per player.
Definition: remote_kart_info.hpp:43