SuperTuxKart
Loading...
Searching...
No Matches
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
27using irr::core::stringw;
28
29class Track;
30
36{
37protected:
41 std::vector<std::string> m_tracks;
42
43public:
46 {
47 GP_NONE = 0,
52 }; // GPGroupType
53
54private:
56 irr::core::stringw m_name;
57
59 std::string m_id;
60
62 std::string m_filename;
63
65 std::vector<int> m_laps;
66
68 std::vector<bool> m_reversed;
69
72
75
82 bool isTrackAvailable(const std::string &id, bool includeLocked) const;
83
84public:
89 {
90 GP_NO_REVERSE = 0,
91 GP_ALL_REVERSE = 1,
92 GP_RANDOM_REVERSE = 2,
93 GP_DEFAULT_REVERSE = 3
94 }; // GPReverseType
95
96private:
97 GPReverseType m_reverse_type;
98
99public:
100#if (defined(WIN32) || defined(_WIN32)) && !defined(__MINGW32__)
101# pragma warning(disable:4290)
102#endif
104 GrandPrixData(const std::string& filename, enum GPGroupType group);
105
108 {
109 m_editable = false;
111 m_reverse_type = GP_NO_REVERSE;
112 }
113
114 virtual ~GrandPrixData() {}
115 virtual std::vector<std::string> getTrackNames(const bool includeLocked=false) const;
116 virtual unsigned int getNumberOfTracks(const bool includeLocked=false) const;
117
118 void changeTrackNumber(const unsigned int number_of_tracks,
119 const std::string& track_group);
120 void changeReverse(const GPReverseType use_reverse);
121
122 void createRandomGP(const unsigned int number_of_tracks,
123 const std::string& track_group,
124 const GPReverseType use_reverse,
125 bool new_tracks=false);
126
127 // Methods for the GP editor
128 void setId(const std::string& id);
129 void setName(const irr::core::stringw& name);
130 void setFilename(const std::string& filename);
131 void setEditable(const bool editable);
132 void setGroup(const enum GPGroupType group);
135 void reload();
136 bool writeToFile();
137
138 bool checkConsistency(bool log_error=true) const;
139 std::vector<int> getLaps(const bool includeLocked=false) const;
140 std::vector<bool> getReverse(const bool includeLocked=false) const;
141 bool isEditable() const;
142 const std::string& getTrackId(const unsigned int track) const;
143 irr::core::stringw getTrackName(const unsigned int track) const;
144 bool containsUnavailableTracks() const;
145 unsigned int getLaps(const unsigned int track) const;
146 bool getReverse(const unsigned int track) const;
147 void moveUp(const unsigned int track);
148 void moveDown(const unsigned int track);
149 void addTrack(Track* track, unsigned int laps,
150 bool reverse, int position=-1);
151 void editTrack(unsigned int index, Track* track,
152 unsigned int laps, bool reverse);
153 void remove(const unsigned int track);
154
155 // -------------------------------------------------------------------------
156 irr::core::stringw getName() const;
157
158 // -------------------------------------------------------------------------
160 const std::string& getId() const { return m_id; }
161
162 // -------------------------------------------------------------------------
164 bool isRandomGP() const { return m_id==getRandomGPID(); }
165 // -------------------------------------------------------------------------
167 const std::string& getFilename() const { return m_filename; }
168
169 // ------------------------------------------------------------------------
170 enum GPGroupType getGroup() const { return m_group; }
171
172 // -------------------------------------------------------------------------
173 enum GPReverseType getReverseType()
174 const { return m_reverse_type; }
175 static const char* getRandomGPID() { return "random"; }
176 static irr::core::stringw getRandomGPName();
177 static irr::core::stringw reverseTypeToString(GPReverseType reverse_type);
178}; // GrandPrixData
179
180#endif
181
182/* EOF */
Simple class that hold the data relevant to a 'grand_prix', aka.
Definition: grand_prix_data.hpp:36
irr::core::stringw m_name
The name of the grand prix.
Definition: grand_prix_data.hpp:56
std::string m_id
Internal name of the grand prix, not translated.
Definition: grand_prix_data.hpp:59
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:107
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:89
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:74
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:41
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:164
bool m_editable
Wether the user can edit this grand prix or not.
Definition: grand_prix_data.hpp:71
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
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:46
@ GP_ADDONS
Add-on GP.
Definition: grand_prix_data.hpp:50
@ GP_GROUP_COUNT
Number of groups.
Definition: grand_prix_data.hpp:51
@ GP_NONE
No group.
Definition: grand_prix_data.hpp:47
@ GP_USER_DEFINED
Created by the user.
Definition: grand_prix_data.hpp:49
@ GP_STANDARD
Standard GP, included with the game.
Definition: grand_prix_data.hpp:48
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
const std::string & getFilename() const
Returns the filename of the grand prix xml file.
Definition: grand_prix_data.hpp:167
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
std::vector< bool > getReverse(const bool includeLocked=false) const
Returns the reverse setting for each available grand prix.
Definition: grand_prix_data.cpp:479
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
std::vector< bool > m_reversed
Whether the track in question should be done in reverse mode.
Definition: grand_prix_data.hpp:68
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:62
const std::string & getId() const
Definition: grand_prix_data.hpp:160
std::vector< int > m_laps
The number of laps that each track will be raced, in the right order.
Definition: grand_prix_data.hpp:65
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
Definition: track.hpp:114