SuperTuxKart
saved_grand_prix.hpp
1 //
2 // SuperTuxKart - a fun racing game with go-kart
3 // Copyright (C) 2010-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 
19 #ifndef HEADER_SAVED_GRAND_PRIX_HPP
20 #define HEADER_SAVED_GRAND_PRIX_HPP
21 
22 #include "config/user_config.hpp"
23 #include "race/race_manager.hpp"
24 #include "utils/ptr_vector.hpp"
25 
26 #include <algorithm>
27 #include <string>
28 
29 class RaceManager;
30 
31 // ============================================================================
32 
39 {
40 private:
42  {
43  friend class SavedGrandPrix;
44  GroupUserConfigParam m_group;
45  StringUserConfigParam m_ident;
46  IntUserConfigParam m_score, m_local_player_id, m_global_player_id;
47  FloatUserConfigParam m_overall_time;
48  public:
49  SavedGPKart(GroupUserConfigParam * group, const XMLNode* node);
51  const std::string &ident,
52  int score,
53  int local_player_id,
54  int global_player_id,
55  float overall_time);
56  }; // SavedGPKart
57 
58 protected:
59 
65  IntUserConfigParam m_player_id;
66 
69 
72 
75 
78 
81 
84 
87 
90 
93 
94  PtrVector<SavedGPKart> m_karts;
95 
96 public:
97 
101  SavedGrandPrix(unsigned int player_id,
102  const std::string &gp_id,
104  RaceManager::Difficulty difficulty,
105  int player_karts,
106  int last_track,
107  int reverse_type,
108  int skipped_tracks,
109  float time_target,
110  int player_total_laps,
111  const std::vector<RaceManager::KartStatus> &kart_list);
112 
116  SavedGrandPrix(const XMLNode* node);
117  void setKarts(const std::vector<RaceManager::KartStatus> &kart_list);
118  void clearKarts();
119  void loadKarts(std::vector<RaceManager::KartStatus> & kart_list);
120 
121  // ------------------------------------------------------------------------
123  unsigned int getPlayerID() const { return m_player_id; }
124 
125  // ------------------------------------------------------------------------
127  std::string getGPID() const { return m_gp_id; }
128 
129  // ------------------------------------------------------------------------
131  int getRaceType() const { return m_race_type; }
132 
133  // ------------------------------------------------------------------------
135  int getDifficulty() const { return m_difficulty; }
136 
137  // ------------------------------------------------------------------------
139  int getTotalKarts() const { return m_karts.size(); }
140 
141  // ------------------------------------------------------------------------
143  int getPlayerKarts() const { return m_player_karts; }
144 
145  // ------------------------------------------------------------------------
147  int getNextTrack() const { return m_next_track; }
148 
149  // ------------------------------------------------------------------------
151  int getReverseType() const { return m_reverse_type; }
152 
153  // ------------------------------------------------------------------------
155  int getSkippedTracks() const { return m_skipped_tracks; }
156 
157  // ------------------------------------------------------------------------
159  float getTimeTarget() const { return m_time_target; }
160 
161  // ------------------------------------------------------------------------
163  int getPlayerTotalLaps() const { return m_player_total_laps; }
164 
165  // ------------------------------------------------------------------------
167  void setNextTrack(int next_track) { m_next_track = next_track; }
168 
169  // ------------------------------------------------------------------------
172  void remove()
173  {
175  delete this;
176  } // remove
177 
178  // ------------------------------------------------------------------------
181  static SavedGrandPrix* getSavedGP(unsigned int player,
182  const std::string &gpid,
184  const unsigned int number_of_players)
185  {
186  for (unsigned int n=0; n<UserConfigParams::m_saved_grand_prix_list.size(); n++)
187  {
189  if (gp->getGPID() == gpid &&
190  gp->getRaceType() == race_type &&
191  gp->getPlayerID() == player &&
192  gp->getPlayerKarts() == (int)number_of_players)
193  return gp;
194  }
195  return NULL;
196  } // getSavedGP
197  // ------------------------------------------------------------------------
198 }; // class SavedGrandPrix
199 
200 #endif
201 
202 /*EOF*/
int getRaceType() const
Returns the race type of this GP.
Definition: saved_grand_prix.hpp:131
StringUserConfigParam m_gp_id
Identifier of this GP.
Definition: saved_grand_prix.hpp:68
Difficulty
Game difficulty.
Definition: race_manager.hpp:229
void setNextTrack(int next_track)
Sets the index of the last track finished.
Definition: saved_grand_prix.hpp:167
IntUserConfigParam m_race_type
Race type at which this GP was run.
Definition: saved_grand_prix.hpp:71
IntUserConfigParam m_reverse_type
GPReverseType of the GP as int.
Definition: saved_grand_prix.hpp:83
SavedGrandPrix(unsigned int player_id, const std::string &gp_id, RaceManager::MinorRaceModeType race_type, RaceManager::Difficulty difficulty, int player_karts, int last_track, int reverse_type, int skipped_tracks, float time_target, int player_total_laps, const std::vector< RaceManager::KartStatus > &kart_list)
Constructor to create a new entry.
Definition: saved_grand_prix.cpp:66
GroupUserConfigParam m_savedgp_group
For saving to config file.
Definition: saved_grand_prix.hpp:64
Definition: user_config.hpp:193
int getReverseType() const
Returns the reverse Type.
Definition: saved_grand_prix.hpp:151
int getPlayerKarts() const
Returns the number of player karts in this GP.
Definition: saved_grand_prix.hpp:143
Definition: user_config.hpp:328
static SavedGrandPrix * getSavedGP(unsigned int player, const std::string &gpid, RaceManager::MinorRaceModeType race_type, const unsigned int number_of_players)
Finds the right SavedGrandPrix given the specified data, or NULL if no matching GP was found...
Definition: saved_grand_prix.hpp:181
IntUserConfigParam m_skipped_tracks
Count of tracks that player skipped.
Definition: saved_grand_prix.hpp:86
IntUserConfigParam m_player_total_laps
Total laps count, used in Lap Trial mode.
Definition: saved_grand_prix.hpp:92
PARAM_PREFIX PtrVector< SavedGrandPrix > m_saved_grand_prix_list
List of all saved GPs.
Definition: user_config.hpp:1364
The race manager has two functions: 1) it stores information about the race the user selected (e...
Definition: race_manager.hpp:86
IntUserConfigParam m_next_track
Index of the next to run track.
Definition: saved_grand_prix.hpp:80
Definition: user_config.hpp:84
int getNextTrack() const
Returns the index of the last track finished when this GP was saved.
Definition: saved_grand_prix.hpp:147
IntUserConfigParam m_difficulty
Difficulty at which this GP was run.
Definition: saved_grand_prix.hpp:74
int getTotalKarts() const
Returns the total number of karts of this GP.
Definition: saved_grand_prix.hpp:139
Definition: ptr_vector.hpp:43
int getSkippedTracks() const
Returns skipped tracks count.
Definition: saved_grand_prix.hpp:155
utility class used to parse XML files
Definition: xml_node.hpp:47
FloatUserConfigParam m_time_target
Time target used in Lap Trial mode.
Definition: saved_grand_prix.hpp:89
Definition: saved_grand_prix.hpp:41
std::string getGPID() const
Returns the grand prix id.
Definition: saved_grand_prix.hpp:127
MinorRaceModeType
Minor variants to the major types of race.
Definition: race_manager.hpp:108
Definition: user_config.hpp:255
int getDifficulty() const
Returns the difficulty of this GP.
Definition: saved_grand_prix.hpp:135
unsigned int getPlayerID() const
Returns the player id for this saved GP.
Definition: saved_grand_prix.hpp:123
Class for managing saved Grand-Prix&#39;s A list of all possible resumable GP&#39;s is stored in the user con...
Definition: saved_grand_prix.hpp:38
float getTimeTarget() const
Returns time target used in Lap Trial mode.
Definition: saved_grand_prix.hpp:159
int getPlayerTotalLaps() const
Returns total laps in GP.
Definition: saved_grand_prix.hpp:163
IntUserConfigParam m_player_karts
Number of player karts used in this GP.
Definition: saved_grand_prix.hpp:77