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