From cb890d4f32c809b697326c89c6b9402a43afc9ae Mon Sep 17 00:00:00 2001 From: wardje Date: Sun, 25 Mar 2012 22:15:20 +0000 Subject: [PATCH] Add reverse track functionality for GPs. Fixes part of #503 (and #599 completely). git-svn-id: svn+ssh://svn.code.sf.net/p/supertuxkart/code/main/trunk@11019 178a84e3-b1eb-0310-8ba1-8eac791a3b58 --- data/grandprix/alltracks.grandprix | 40 +++++++++++----------- data/grandprix/atworldsend.grandprix | 10 +++--- data/grandprix/penguinplayground.grandprix | 10 +++--- data/grandprix/snagdrive.grandprix | 10 +++--- data/grandprix/tothemoonandback.grandprix | 10 +++--- src/race/grand_prix_data.cpp | 15 +++++--- src/race/grand_prix_data.hpp | 6 +++- src/race/race_manager.cpp | 8 +++-- 8 files changed, 60 insertions(+), 49 deletions(-) diff --git a/data/grandprix/alltracks.grandprix b/data/grandprix/alltracks.grandprix index cb1d5a211..cec6494eb 100644 --- a/data/grandprix/alltracks.grandprix +++ b/data/grandprix/alltracks.grandprix @@ -1,25 +1,25 @@ - - - - - - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + + + + + diff --git a/data/grandprix/atworldsend.grandprix b/data/grandprix/atworldsend.grandprix index 459b16bef..562c8fcae 100644 --- a/data/grandprix/atworldsend.grandprix +++ b/data/grandprix/atworldsend.grandprix @@ -1,11 +1,11 @@ - - - - - + + + + + diff --git a/data/grandprix/penguinplayground.grandprix b/data/grandprix/penguinplayground.grandprix index 85c8649b8..96972036f 100644 --- a/data/grandprix/penguinplayground.grandprix +++ b/data/grandprix/penguinplayground.grandprix @@ -1,10 +1,10 @@ - - - - - + + + + + diff --git a/data/grandprix/snagdrive.grandprix b/data/grandprix/snagdrive.grandprix index c039c49c8..5c579ba08 100644 --- a/data/grandprix/snagdrive.grandprix +++ b/data/grandprix/snagdrive.grandprix @@ -1,11 +1,11 @@ - - - - - + + + + + diff --git a/data/grandprix/tothemoonandback.grandprix b/data/grandprix/tothemoonandback.grandprix index 5e5e26bc2..91c4e6749 100644 --- a/data/grandprix/tothemoonandback.grandprix +++ b/data/grandprix/tothemoonandback.grandprix @@ -1,10 +1,10 @@ - - - - - + + + + + diff --git a/src/race/grand_prix_data.cpp b/src/race/grand_prix_data.cpp index 9a4e1929f..20c9d1fa4 100644 --- a/src/race/grand_prix_data.cpp +++ b/src/race/grand_prix_data.cpp @@ -73,22 +73,27 @@ GrandPrixData::GrandPrixData(const std::string filename) throw(std::logic_error) { std::string trackID; int numLaps; + bool reversed; - const int idFound = node->get("id", &trackID ); - const int lapFound = node->get("laps", &numLaps ); + const int idFound = node->get("id", &trackID ); + const int lapFound = node->get("laps", &numLaps ); + const int reverseFound = node->get("reverse", &reversed ); - if (!idFound || !lapFound) + if (!idFound || !lapFound || !reverseFound) { fprintf(stderr, "/!\\ Error while trying to read grandprix file '%s' : " - " tag does not have id and laps attributes. \n", filename.c_str()); + " tag does not have id, laps and reverse attributes. \n", + filename.c_str()); delete root; throw std::logic_error("File contents are incomplete or corrupt"); } m_tracks.push_back(trackID); m_laps.push_back(numLaps); + m_reversed.push_back(reversed); - assert(m_tracks.size() == m_laps.size()); + assert(m_tracks.size() == m_laps.size() ); + assert(m_laps.size() == m_reversed.size()); } else { diff --git a/src/race/grand_prix_data.hpp b/src/race/grand_prix_data.hpp index 459b31f9b..6ff70bbc7 100644 --- a/src/race/grand_prix_data.hpp +++ b/src/race/grand_prix_data.hpp @@ -48,6 +48,9 @@ class GrandPrixData /** The number of laps that each track should be raced, in the right order */ std::vector m_laps; + /** Whether the track in question should be done in reverse mode */ + std::vector m_reversed; + public: /** Load the GrandPrixData from the given filename */ @@ -63,7 +66,7 @@ public: /** @return the (potentially translated) user-visible description of the Grand Prix */ //const irr::core::stringw& getDescription () const { return m_description; } - /** @return the internale name identifier of the Grand Prix (not translated) */ + /** @return the internal name identifier of the Grand Prix (not translated) */ const std::string& getId () const { return m_id; } const std::string& getFilename () const { return m_filename; } @@ -71,6 +74,7 @@ public: return m_tracks[track_index]; } const std::vector& getTracks() const {return m_tracks; } const std::vector& getLaps() const {return m_laps; } + const std::vector& getReverse() const {return m_reversed; } size_t getTrackCount() const {return m_tracks.size(); } const int& getLaps(size_t lap_index) const {assert(lap_index < m_tracks.size()); return m_laps[lap_index];} diff --git a/src/race/race_manager.cpp b/src/race/race_manager.cpp index aa49af77b..1935faa2a 100644 --- a/src/race/race_manager.cpp +++ b/src/race/race_manager.cpp @@ -244,10 +244,12 @@ void RaceManager::computeRandomKartList() void RaceManager::startNew() { - if(m_major_mode==MAJOR_MODE_GRAND_PRIX) // GP: get tracks and laps from grand prix + if(m_major_mode==MAJOR_MODE_GRAND_PRIX) { - m_tracks = m_grand_prix.getTracks(); - m_num_laps = m_grand_prix.getLaps(); + // GP: get tracks, laps and reverse info from grand prix + m_tracks = m_grand_prix.getTracks(); + m_num_laps = m_grand_prix.getLaps(); + m_reverse_track = m_grand_prix.getReverse(); } assert(m_player_karts.size() > 0);