Applied Wardje's patch to have separate high scores for reverse mode.

Thanks a lot!


git-svn-id: svn+ssh://svn.code.sf.net/p/supertuxkart/code/main/trunk@10967 178a84e3-b1eb-0310-8ba1-8eac791a3b58
This commit is contained in:
hikerstk 2012-03-14 22:37:56 +00:00
parent 6783ab7d6f
commit bbb0954ae8
7 changed files with 41 additions and 18 deletions

View File

@ -358,7 +358,7 @@ int XMLNode::get(const std::string &attribute, bool *value) const
// FIXME: for some reason, missing attributes don't trigger that if???
if(!get(attribute, &s)) return 0;
*value = s[0]=='T' || s[0]=='t' || s[0]=='Y' || s[0]=='y' ||
s=="#t" || s =="#T";
s=="#t" || s =="#T" || s=="1";
return 1;
} // get(bool)

View File

@ -694,7 +694,8 @@ Highscores* World::getHighscores() const
getNumKarts(),
race_manager->getDifficulty(),
race_manager->getTrackName(),
race_manager->getNumLaps());
race_manager->getNumLaps(),
race_manager->getReverseTrack());
return highscores;
} // getHighscores

View File

@ -165,11 +165,15 @@ void HighscoreManager::saveHighscores()
// -----------------------------------------------------------------------------
/*
* Returns the high scores entry for a specific type of race. Creates one if none exists yet.
* Returns the high scores entry for a specific type of race.
* Creates one if none exists yet.
*/
Highscores* HighscoreManager::getHighscores(const Highscores::HighscoreType highscore_type,
int num_karts, const RaceManager::Difficulty difficulty,
const std::string trackName, const int number_of_laps)
int num_karts,
const RaceManager::Difficulty difficulty,
const std::string trackName,
const int number_of_laps,
const bool reverse)
{
Highscores *highscores = 0;
@ -177,7 +181,8 @@ Highscores* HighscoreManager::getHighscores(const Highscores::HighscoreType high
for(type_all_scores::iterator i = m_all_scores.begin();
i != m_all_scores.end(); i++)
{
if((*i)->matches(highscore_type, num_karts, difficulty, trackName, number_of_laps) )
if((*i)->matches(highscore_type, num_karts, difficulty, trackName,
number_of_laps, reverse) )
{
// we found one entry for this kind of race, return it
return (*i);
@ -185,7 +190,8 @@ Highscores* HighscoreManager::getHighscores(const Highscores::HighscoreType high
} // for i in m_all_scores
// we don't have an entry for such a race currently. Create one.
highscores = new Highscores(highscore_type, num_karts, difficulty, trackName, number_of_laps);
highscores = new Highscores(highscore_type, num_karts, difficulty,
trackName, number_of_laps, reverse);
m_all_scores.push_back(highscores);
return highscores;
} // getHighscores

View File

@ -35,7 +35,7 @@ class HighscoreManager
{
public:
private:
static const unsigned int CURRENT_HSCORE_FILE_VERSION = 1;
static const unsigned int CURRENT_HSCORE_FILE_VERSION = 2;
typedef std::vector<Highscores*> type_all_scores;
type_all_scores m_all_scores;
@ -53,7 +53,8 @@ public:
int num_karts,
const RaceManager::Difficulty difficulty,
const std::string trackName,
const int number_of_laps);
const int number_of_laps,
const bool reverse);
}; // HighscoreManager
extern HighscoreManager* highscore_manager;

View File

@ -30,13 +30,15 @@ Highscores::Highscores(const HighscoreType highscore_type,
int num_karts,
const RaceManager::Difficulty difficulty,
const std::string trackName,
const int number_of_laps)
const int number_of_laps,
const bool reverse)
{
m_track = trackName;
m_highscore_type = highscore_type;
m_number_of_karts = num_karts;
m_difficulty = difficulty;
m_number_of_laps = number_of_laps;
m_reverse = reverse;
for(int i=0; i<HIGHSCORE_LEN; i++)
{
@ -53,6 +55,7 @@ Highscores::Highscores(const XMLNode &node)
m_number_of_karts = -1;
m_difficulty = -1;
m_number_of_laps = -1;
m_reverse = false;
for(int i=0; i<HIGHSCORE_LEN; i++)
{
@ -74,6 +77,7 @@ void Highscores::readEntry(const XMLNode &node)
m_highscore_type = (HighscoreType)hst;
node.get("difficulty", &m_difficulty );
node.get("number-of-laps", &m_number_of_laps );
node.get("reverse", &m_reverse );
for(unsigned int i=0; i<node.getNumNodes(); i++)
{
@ -113,7 +117,8 @@ void Highscores::writeEntry(XMLWriter &writer)
writer << L" number-karts =\"" << m_number_of_karts << "\"\n";
writer << L" difficulty =\"" << m_difficulty << "\"\n";
writer << L" hscore-type =\"" << m_highscore_type.c_str() << "\"\n";
writer << L" number-of-laps=\"" << m_number_of_laps << "\">\n";
writer << L" number-of-laps=\"" << m_number_of_laps << "\"\n";
writer << L" reverse =\"" << m_reverse << "\">\n";
for(int i=0; i<HIGHSCORE_LEN; i++)
{
@ -132,13 +137,15 @@ void Highscores::writeEntry(XMLWriter &writer)
// -----------------------------------------------------------------------------
int Highscores::matches(HighscoreType highscore_type,
int num_karts, RaceManager::Difficulty difficulty,
const std::string track, const int number_of_laps)
const std::string track, const int number_of_laps,
const bool reverse)
{
return (m_highscore_type == highscore_type &&
m_track == track &&
m_difficulty == difficulty &&
m_number_of_laps == number_of_laps &&
m_number_of_karts == num_karts );
m_number_of_karts == num_karts &&
m_reverse == reverse );
} // matches
// -----------------------------------------------------------------------------
@ -180,6 +187,7 @@ int Highscores::addData(const std::string& kart_name,
m_number_of_karts = race_manager->getNumberOfKarts();
m_difficulty = race_manager->getDifficulty();
m_number_of_laps = race_manager->getNumLaps();
m_reverse = race_manager->getReverseTrack();
m_name[position] = name;
m_time[position] = time;
m_kart_name[position] = kart_name;

View File

@ -46,6 +46,7 @@ private:
int m_number_of_karts;
int m_difficulty;
int m_number_of_laps;
bool m_reverse;
std::string m_kart_name[HIGHSCORE_LEN];
irr::core::stringw m_name[HIGHSCORE_LEN];
float m_time[HIGHSCORE_LEN];
@ -54,7 +55,8 @@ public:
*/
Highscores (const Highscores::HighscoreType highscore_type,
int num_karts, const RaceManager::Difficulty difficulty,
const std::string trackName, const int number_of_laps);
const std::string trackName, const int number_of_laps,
const bool reverse);
/** Creates an entry from a file
*/
Highscores (const XMLNode &node);
@ -63,7 +65,8 @@ public:
void writeEntry(XMLWriter &writer);
int matches (HighscoreType highscore_type, int num_karts,
const RaceManager::Difficulty difficulty,
const std::string track, const int number_of_laps);
const std::string track, const int number_of_laps,
const bool reverse);
int addData (const std::string& kart_name,
const irr::core::stringw& name, const float time);
int getNumberEntries() const;

View File

@ -181,13 +181,14 @@ void TrackInfoDialog::updateHighScores()
{
std::string game_mode_ident = RaceManager::getIdentOf( race_manager->getMinorMode() );
const Highscores::HighscoreType type = "HST_" + game_mode_ident;
Highscores* highscores =
highscore_manager->getHighscores(type,
race_manager->getNumberOfKarts(),
race_manager->getDifficulty(),
m_track_ident,
race_manager->getNumLaps() );
race_manager->getNumLaps(),
race_manager->getReverseTrack() );
const int amount = highscores->getNumberEntries();
std::string kart_name;
@ -256,9 +257,12 @@ GUIEngine::EventPropagation TrackInfoDialog::processEvent(const std::string& eve
onEnterPressedInternal();
return GUIEngine::EVENT_BLOCK;
}
else if (eventSource == "reversecheckbox")
else if (eventSource == "reverse")
{
race_manager->setReverseTrack(m_checkbox->getState());
// Makes sure the highscores get swapped when clicking the 'reverse'
// checkbox.
updateHighScores();
}
else if (eventSource == "lapcountspinner")
{