SuperTuxKart
Loading...
Searching...
No Matches
game_setup.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 GAME_SETUP_HPP
23#define GAME_SETUP_HPP
24
25#include <irrString.h>
26
27#include <atomic>
28#include <cassert>
29#include <memory>
30#include <string>
31#include <vector>
32
34class NetworkString;
35class PeerVote;
36
37// ============================================================================
43{
44private:
45 std::vector<std::string> m_tracks;
46
47 unsigned m_laps;
48
49 int m_extra_server_info;
50
51 int m_hit_capture_limit;
52
53 float m_battle_time_limit;
54
55 bool m_reverse;
56
57 std::atomic_bool m_is_grand_prix;
58
59 irr::core::stringw m_message_of_today;
60
62 std::string m_server_name_utf8;
63
64public:
65 // ------------------------------------------------------------------------
66 GameSetup();
67 // ------------------------------------------------------------------------
68 ~GameSetup() {}
69 // ------------------------------------------------------------------------
70 void setRace(const PeerVote &vote);
71 // ------------------------------------------------------------------------
72 void reset()
73 {
74 if (!isGrandPrixStarted())
75 m_tracks.clear();
76 m_laps = 0;
77 m_reverse = false;
78 m_hit_capture_limit = 0;
79 m_battle_time_limit = 0.0f;
80 }
81 // ------------------------------------------------------------------------
82 void resetExtraServerInfo()
83 {
84 m_is_grand_prix.store(false);
85 m_extra_server_info = -1;
86 }
87 // ------------------------------------------------------------------------
88 void setGrandPrixTrack(int tracks_no)
89 {
90 m_is_grand_prix.store(true);
91 m_extra_server_info = tracks_no;
92 }
93 // ------------------------------------------------------------------------
94 void addServerInfo(NetworkString* ns);
95 // ------------------------------------------------------------------------
96 void loadWorld();
97 // ------------------------------------------------------------------------
98 bool isGrandPrix() const { return m_is_grand_prix.load(); }
99 // ------------------------------------------------------------------------
100 bool hasExtraSeverInfo() const { return m_extra_server_info != -1; }
101 // ------------------------------------------------------------------------
102 uint8_t getExtraServerInfo() const
103 {
104 assert(hasExtraSeverInfo());
105 return (uint8_t)m_extra_server_info;
106 }
107 // ------------------------------------------------------------------------
108 unsigned getTotalGrandPrixTracks() const
109 {
110 assert(isGrandPrix());
111 return m_extra_server_info;
112 }
113 // ------------------------------------------------------------------------
114 void setSoccerGoalTarget(bool val) { m_extra_server_info = (int)val; }
115 // ------------------------------------------------------------------------
116 bool isSoccerGoalTarget() const
117 {
118 assert(hasExtraSeverInfo());
119 return m_extra_server_info != 0;
120 }
121 // ------------------------------------------------------------------------
122 bool isGrandPrixStarted() const
123 {
124 return isGrandPrix() && !m_tracks.empty() &&
125 m_tracks.size() != getTotalGrandPrixTracks();
126 }
127 // ------------------------------------------------------------------------
128 void stopGrandPrix() { m_tracks.clear(); }
129 // ------------------------------------------------------------------------
130 const std::vector<std::string>& getAllTracks() const { return m_tracks; }
131 // ------------------------------------------------------------------------
132 const std::string& getCurrentTrack() const { return m_tracks.back(); }
133 // ------------------------------------------------------------------------
134 void sortPlayersForGrandPrix(
135 std::vector<std::shared_ptr<NetworkPlayerProfile> >& players) const;
136 // ------------------------------------------------------------------------
137 void sortPlayersForGame(
138 std::vector<std::shared_ptr<NetworkPlayerProfile> >& players) const;
139 // ------------------------------------------------------------------------
140 void setHitCaptureTime(int hc, float time)
141 {
142 m_hit_capture_limit = hc;
143 m_battle_time_limit = time;
144 }
145 // ------------------------------------------------------------------------
146 const std::string& getServerNameUtf8() const { return m_server_name_utf8; }
147};
148
149#endif // GAME_SETUP_HPP
Used to store the needed data about the players that join a game. This class stores all the possible ...
Definition: game_setup.hpp:43
std::string m_server_name_utf8
Utf8 server name (with xml decoded)
Definition: game_setup.hpp:62
Contains the profile of a player.
Definition: network_player_profile.hpp:42
A new implementation of NetworkString, which has a fixed format: Byte 0: The type of the message,...
Definition: network_string.hpp:422
A simple structure to store a vote from a client: track name, number of laps and reverse or not.
Definition: peer_vote.hpp:30