SuperTuxKart
grand_prix_data.hpp
1 //
2 // SuperTuxKart - a fun racing game with go-kart
3 // Copyright (C) 2004-2015 Ingo Ruhnke <grumbel@gmx.de>
4 // Copyright (C) 2006-2015 Joerg Henrichs
5 //
6 // This program is free software; you can redistribute it and/or
7 // modify it under the terms of the GNU General Public License
8 // as published by the Free Software Foundation; either version 3
9 // of the License, or (at your option) any later version.
10 //
11 // This program is distributed in the hope that it will be useful,
12 // but WITHOUT ANY WARRANTY; without even the implied warranty of
13 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 // GNU General Public License for more details.
15 //
16 // You should have received a copy of the GNU General Public License
17 // along with this program; if not, write to the Free Software
18 // Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
19 
20 #ifndef HEADER_GRAND_PRIX_DATA_HPP
21 #define HEADER_GRAND_PRIX_DATA_HPP
22 
23 #include <irrString.h>
24 #include <string>
25 #include <vector>
26 #include "utils/types.hpp"
27 
28 using irr::core::stringw;
29 
30 class Track;
31 
37 {
38 protected:
42  std::vector<std::string> m_tracks;
43 
44 public:
47  {
48  GP_NONE = 0,
53  }; // GPGroupType
54 
55 private:
57  irr::core::stringw m_name;
58 
60  std::string m_id;
61 
63  std::string m_filename;
64 
66  std::vector<int> m_laps;
67 
69  // This is uint8_t instead of bool because of GitHub issue #5053
70  std::vector<uint8_t> m_reversed;
71 
73  bool m_editable;
74 
76  enum GPGroupType m_group;
77 
84  bool isTrackAvailable(const std::string &id, bool includeLocked) const;
85 
86 public:
91  {
92  GP_NO_REVERSE = 0,
93  GP_ALL_REVERSE = 1,
94  GP_RANDOM_REVERSE = 2,
95  GP_DEFAULT_REVERSE = 3
96  }; // GPReverseType
97 
98 private:
99  GPReverseType m_reverse_type;
100 
101 public:
102 #if (defined(WIN32) || defined(_WIN32)) && !defined(__MINGW32__)
103 # pragma warning(disable:4290)
104 #endif
106  GrandPrixData(const std::string& filename, enum GPGroupType group);
107 
110  {
111  m_editable = false;
112  m_group = GP_NONE;
113  m_reverse_type = GP_NO_REVERSE;
114  }
115 
116  virtual ~GrandPrixData() {}
117  virtual std::vector<std::string> getTrackNames(const bool includeLocked=false) const;
118  virtual unsigned int getNumberOfTracks(const bool includeLocked=false) const;
119 
120  void changeTrackNumber(const unsigned int number_of_tracks,
121  const std::string& track_group);
122  void changeReverse(const GPReverseType use_reverse);
123 
124  void createRandomGP(const unsigned int number_of_tracks,
125  const std::string& track_group,
126  const GPReverseType use_reverse,
127  bool new_tracks=false);
128 
129  // Methods for the GP editor
130  void setId(const std::string& id);
131  void setName(const irr::core::stringw& name);
132  void setFilename(const std::string& filename);
133  void setEditable(const bool editable);
134  void setGroup(const enum GPGroupType group);
137  void reload();
138  bool writeToFile();
139 
140  bool checkConsistency(bool log_error=true) const;
141  std::vector<int> getLaps(const bool includeLocked=false) const;
142  std::vector<uint8_t> getReverse(const bool includeLocked=false) const;
143  bool isEditable() const;
144  const std::string& getTrackId(const unsigned int track) const;
145  irr::core::stringw getTrackName(const unsigned int track) const;
146  bool containsUnavailableTracks() const;
147  unsigned int getLaps(const unsigned int track) const;
148  bool getReverse(const unsigned int track) const;
149  void moveUp(const unsigned int track);
150  void moveDown(const unsigned int track);
151  void addTrack(Track* track, unsigned int laps,
152  bool reverse, int position=-1);
153  void editTrack(unsigned int index, Track* track,
154  unsigned int laps, bool reverse);
155  void remove(const unsigned int track);
156 
157  // -------------------------------------------------------------------------
158  irr::core::stringw getName() const;
159 
160  // -------------------------------------------------------------------------
162  const std::string& getId() const { return m_id; }
163 
164  // -------------------------------------------------------------------------
166  bool isRandomGP() const { return m_id==getRandomGPID(); }
167  // -------------------------------------------------------------------------
169  const std::string& getFilename() const { return m_filename; }
170 
171  // ------------------------------------------------------------------------
172  enum GPGroupType getGroup() const { return m_group; }
173 
174  // -------------------------------------------------------------------------
175  enum GPReverseType getReverseType()
176  const { return m_reverse_type; }
177  static const char* getRandomGPID() { return "random"; }
178  static irr::core::stringw getRandomGPName();
179  static irr::core::stringw reverseTypeToString(GPReverseType reverse_type);
180 }; // GrandPrixData
181 
182 #endif
183 
184 /* EOF */
Simple class that hold the data relevant to a 'grand_prix', aka.
Definition: grand_prix_data.hpp:37
irr::core::stringw m_name
The name of the grand prix.
Definition: grand_prix_data.hpp:57
std::string m_id
Internal name of the grand prix, not translated.
Definition: grand_prix_data.hpp:60
bool writeToFile()
Saves the grand prix data to a file.
Definition: grand_prix_data.cpp:362
GrandPrixData()
Needed for simple creation of an instance of GrandPrixData.
Definition: grand_prix_data.hpp:109
std::vector< int > getLaps(const bool includeLocked=false) const
Returns the laps for each available track of the grand prix.
Definition: grand_prix_data.cpp:464
bool isEditable() const
Returns true if this grand prix can be edited.
Definition: grand_prix_data.cpp:492
GPReverseType
Used to define the reverse setting when creating a random GP: No reverse, all reverse (if available o...
Definition: grand_prix_data.hpp:91
void createRandomGP(const unsigned int number_of_tracks, const std::string &track_group, const GPReverseType use_reverse, bool new_tracks=false)
Creates a random grand prix from the specified parameters.
Definition: grand_prix_data.cpp:65
enum GPGroupType m_group
Group to which this GP belongs.
Definition: grand_prix_data.hpp:76
std::vector< uint8_t > getReverse(const bool includeLocked=false) const
Returns the reverse setting for each available grand prix.
Definition: grand_prix_data.cpp:479
std::vector< std::string > m_tracks
The ident of the tracks in this grand prix in their right order, ident means the filename of the ....
Definition: grand_prix_data.hpp:42
irr::core::stringw getName() const
Definition: grand_prix_data.cpp:629
bool isRandomGP() const
Returns true if this GP is a random GP.
Definition: grand_prix_data.hpp:166
bool m_editable
Wether the user can edit this grand prix or not.
Definition: grand_prix_data.hpp:73
virtual std::vector< std::string > getTrackNames(const bool includeLocked=false) const
Returns the list of tracks that is available (i.e.
Definition: grand_prix_data.cpp:448
const std::string & getFilename() const
Returns the filename of the grand prix xml file.
Definition: grand_prix_data.hpp:169
void setId(const std::string &id)
Sets the id of this grand prix.
Definition: grand_prix_data.cpp:206
GPGroupType
Used to classify GPs into groups.
Definition: grand_prix_data.hpp:47
@ GP_ADDONS
Add-on GP.
Definition: grand_prix_data.hpp:51
@ GP_GROUP_COUNT
Number of groups.
Definition: grand_prix_data.hpp:52
@ GP_NONE
No group.
Definition: grand_prix_data.hpp:48
@ GP_USER_DEFINED
Created by the user.
Definition: grand_prix_data.hpp:50
@ GP_STANDARD
Standard GP, included with the game.
Definition: grand_prix_data.hpp:49
void setFilename(const std::string &filename)
Sets the filename of this grand prix.
Definition: grand_prix_data.cpp:224
bool checkConsistency(bool log_error=true) const
Checks if the grand prix data are consistent.
Definition: grand_prix_data.cpp:401
void reload()
Load the grand prix from the file set by the constructor or the grand prix editor.
Definition: grand_prix_data.cpp:250
void changeTrackNumber(const unsigned int number_of_tracks, const std::string &track_group)
Either adds or removes tracks to get the requested numder of tracks in a random GP.
Definition: grand_prix_data.cpp:97
void setGroup(const enum GPGroupType group)
Sets the group of this grand prix.
Definition: grand_prix_data.cpp:242
void setEditable(const bool editable)
Sets if this grand prix can be edited.
Definition: grand_prix_data.cpp:233
virtual unsigned int getNumberOfTracks(const bool includeLocked=false) const
Returns the number of tracks in this grand prix.
Definition: grand_prix_data.cpp:501
void setName(const irr::core::stringw &name)
Sets the name of the grand prix.
Definition: grand_prix_data.cpp:215
irr::core::stringw getTrackName(const unsigned int track) const
Returns the (translated) name of the track with the specified index.
Definition: grand_prix_data.cpp:512
void changeReverse(const GPReverseType use_reverse)
Updates the GP data with newly decided reverse requirements.
Definition: grand_prix_data.cpp:179
std::string m_filename
Original filename, only for error handling needed.
Definition: grand_prix_data.hpp:63
std::vector< int > m_laps
The number of laps that each track will be raced, in the right order.
Definition: grand_prix_data.hpp:66
const std::string & getId() const
Definition: grand_prix_data.hpp:162
bool isTrackAvailable(const std::string &id, bool includeLocked) const
In the last GP Fort Magma can not be used untill the final challenge.
Definition: grand_prix_data.cpp:430
std::vector< uint8_t > m_reversed
Whether the track in question should be done in reverse mode.
Definition: grand_prix_data.hpp:70
Definition: track.hpp:115
Declares the general types that are used by the network.