SuperTuxKart
Loading...
Searching...
No Matches
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
30using namespace irr::core;
31
32class XMLNode;
33class UTFWriter;
34
41{
42public:
45 {
46 SO_DEFAULT,
47 SO_TRACK = SO_DEFAULT, // Sorted by internal 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 if using reverse mode
52 };
53
54 typedef std::string HighscoreType;
55
56 enum {HIGHSCORE_LEN = 5}; // It's a top 5 list
57 std::string m_track;
58 HighscoreType m_highscore_type;
59 int m_number_of_karts;
60 int m_difficulty;
61 int m_number_of_laps;
62 bool m_reverse;
63 int m_gp_reverse_type;
64 int m_gp_minor_mode;
65
66private:
67 std::array<std::string, HIGHSCORE_LEN> m_kart_name;
68 std::array<stringw, HIGHSCORE_LEN> m_name;
69 std::array<float, HIGHSCORE_LEN> m_time;
70
71 static SortOrder m_sort_order;
72
73 int findHighscorePosition(const std::string& kart_name,
74 const core::stringw& name, const float time);
75
76public:
77 bool operator < (const Highscores& hi) const;
78
79 static bool compare(const std::unique_ptr<Highscores>& a, const std::unique_ptr<Highscores>& b) { return (*a < *b); }
82 Highscores (const Highscores::HighscoreType &highscore_type,
83 int num_karts, const RaceManager::Difficulty &difficulty,
84 const std::string &trackName, const int number_of_laps,
85 const bool reverse);
87 Highscores (int num_karts, const RaceManager::Difficulty &difficulty,
88 const std::string &trackName, const int target,
92 Highscores (const XMLNode &node);
93 // ------------------------------------------------------------------------
94 void readEntry (const XMLNode &node);
95 // ------------------------------------------------------------------------
96 void writeEntry(UTFWriter &writer);
97 // ------------------------------------------------------------------------
98 int matches (const HighscoreType &highscore_type, int num_karts,
99 const RaceManager::Difficulty &difficulty,
100 const std::string &track, const int number_of_laps,
101 const bool reverse);
102 // ------------------------------------------------------------------------
104 int matches(int num_karts,
105 const RaceManager::Difficulty &difficulty,
106 const std::string &track, const int target,
107 const GrandPrixData::GPReverseType reverse_type, RaceManager::MinorRaceModeType minor_mode);
108 // ------------------------------------------------------------------------
109 int addData (const std::string& kart_name,
110 const irr::core::stringw& name, const float time);
111 int addGPData (const std::string& kart_name,
112 const irr::core::stringw& name, std::string gp_name, const float time);
113 // ------------------------------------------------------------------------
114 int getNumberEntries() const;
115 // ------------------------------------------------------------------------
116 void getEntry (int number, std::string &kart_name,
117 irr::core::stringw &name, float *const time) const;
118 // ------------------------------------------------------------------------
119 static void setSortOrder(SortOrder so) { m_sort_order = so; }
120}; // Highscores
121
122#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:89
Represents one highscore entry, i.e.
Definition: highscores.hpp:41
SortOrder
Order of sort for Highscores.
Definition: highscores.hpp:45
void writeEntry(UTFWriter &writer)
Writes the highscores in this entry to the writer.
Definition: highscores.cpp:151
int addData(const std::string &kart_name, const irr::core::stringw &name, const float time)
Inserts the data into the highscore list.
Definition: highscores.cpp:249
MinorRaceModeType
Minor variants to the major types of race.
Definition: race_manager.hpp:110
Difficulty
Game difficulty.
Definition: race_manager.hpp:230
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