SuperTuxKart
highscores.hpp
1 //
2 // SuperTuxKart - a fun racing game with go-kart
3 // Copyright (C) 2006-2015 Joerg Henrichs
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_HIGHSCORES_HPP
20 #define HEADER_HIGHSCORES_HPP
21 #include <array>
22 #include <string>
23 #include <vector>
24 #include <map>
25 
26 #include "race/race_manager.hpp"
27 
28 #include "irrString.h"
29 
30 using namespace irr::core;
31 
32 class XMLNode;
33 class UTFWriter;
34 
41 {
42 public:
44  enum SortOrder
45  {
46  SO_DEFAULT,
47  SO_TRACK, // Sorted by track name
48  SO_KART_NUM, // Sorted by amount of karts used
49  SO_DIFF, // Sorted by difficulty level
50  SO_LAPS, // Sorted by number of laps
51  SO_REV, // Sorted by reverse mode status
52  SO_REV_GP, // Sorted by reverse mode status (GP)
53  SO_GP_NAME, // Sorted by name (GP)
54  SO_MODE // Sorted by game mode (GP)
55  };
56 
57  typedef std::string HighscoreType;
58 
59  enum {HIGHSCORE_LEN = 5}; // It's a top 5 list
60  std::string m_track;
61  HighscoreType m_highscore_type;
62  int m_number_of_karts;
63  int m_difficulty;
64  int m_number_of_laps;
65  bool m_reverse;
66  int m_gp_reverse_type;
67  int m_gp_minor_mode;
68 
69 private:
70  std::array<std::string, HIGHSCORE_LEN> m_kart_name;
71  std::array<stringw, HIGHSCORE_LEN> m_name;
72  std::array<float, HIGHSCORE_LEN> m_time;
73 
74  static SortOrder m_sort_order;
75 
76  int findHighscorePosition(const std::string& kart_name,
77  const core::stringw& name, const float time);
78 
79 public:
80  bool operator < (const Highscores& hi) const;
81 
82  static bool compare(const std::unique_ptr<Highscores>& a, const std::unique_ptr<Highscores>& b) { return (*a < *b); }
85  Highscores (const Highscores::HighscoreType &highscore_type,
86  int num_karts, const RaceManager::Difficulty &difficulty,
87  const std::string &trackName, const int number_of_laps,
88  const bool reverse);
90  Highscores (int num_karts, const RaceManager::Difficulty &difficulty,
91  const std::string &trackName, const int target,
92  const GrandPrixData::GPReverseType reverse_type, RaceManager::MinorRaceModeType minor_mode);
95  Highscores (const XMLNode &node);
96  // ------------------------------------------------------------------------
97  void readEntry (const XMLNode &node);
98  // ------------------------------------------------------------------------
99  void writeEntry(UTFWriter &writer);
100  // ------------------------------------------------------------------------
101  int matches (const HighscoreType &highscore_type, int num_karts,
102  const RaceManager::Difficulty &difficulty,
103  const std::string &track, const int number_of_laps,
104  const bool reverse);
105  // ------------------------------------------------------------------------
107  int matches(int num_karts,
108  const RaceManager::Difficulty &difficulty,
109  const std::string &track, const int target,
110  const GrandPrixData::GPReverseType reverse_type, RaceManager::MinorRaceModeType minor_mode);
111  // ------------------------------------------------------------------------
112  int addData (const std::string& kart_name,
113  const irr::core::stringw& name, const float time);
114  int addGPData (const std::string& kart_name,
115  const irr::core::stringw& name, std::string gp_name, const float time);
116  // ------------------------------------------------------------------------
117  int getNumberEntries() const;
118  // ------------------------------------------------------------------------
119  void getEntry (int number, std::string &kart_name,
120  irr::core::stringw &name, float *const time) const;
121  // ------------------------------------------------------------------------
122  static void setSortOrder(SortOrder so) { m_sort_order = so; }
123 }; // Highscores
124 
125 #endif
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
Represents one highscore entry, i.e.
Definition: highscores.hpp:41
SortOrder
Order of sort for Highscores.
Definition: highscores.hpp:45
MinorRaceModeType
Minor variants to the major types of race.
Definition: race_manager.hpp:111
Difficulty
Game difficulty.
Definition: race_manager.hpp:231
utility class used to write wide (UTF-16 or UTF-32, depending of size of wchar_t) XML files
Definition: utf_writer.hpp:35
utility class used to parse XML files
Definition: xml_node.hpp:48