From c953803f1390b8bafd968d94bf0aa89e77a2f631 Mon Sep 17 00:00:00 2001 From: auria Date: Thu, 23 Feb 2012 01:36:24 +0000 Subject: [PATCH] Start refactor to turn around a bad design decision regarding challenges. Oops. Number of required trophies moved from scene.xml to .challenge file. git-svn-id: svn+ssh://svn.code.sf.net/p/supertuxkart/code/main/trunk@10885 178a84e3-b1eb-0310-8ba1-8eac791a3b58 --- data/challenges/city.challenge | 1 + data/challenges/farm.challenge | 1 + data/challenges/fortmagma.challenge | 1 + data/challenges/hacienda.challenge | 1 + data/challenges/islandtrack.challenge | 1 + data/challenges/jungle.challenge | 1 + data/challenges/lighthouse.challenge | 1 + data/challenges/mines.challenge | 3 +- data/challenges/minigolf.challenge | 1 + data/challenges/olivermath.challenge | 1 + data/challenges/sandtrack.challenge | 1 + data/challenges/scotland.challenge | 1 + data/challenges/snowmountain.challenge | 1 + data/challenges/snowpeak.challenge | 1 + data/challenges/startrack.challenge | 1 + data/challenges/subsea.challenge | 1 + data/challenges/tuxtollway.challenge | 1 + data/challenges/xr591.challenge | 1 + data/challenges/zengarden.challenge | 1 + src/challenges/challenge_data.cpp | 24 +++-- src/challenges/challenge_data.hpp | 6 ++ src/modes/overworld.cpp | 2 +- src/states_screens/race_gui_overworld.cpp | 4 +- src/tracks/track.cpp | 115 ++++++++++------------ src/tracks/track.hpp | 26 ++++- 25 files changed, 122 insertions(+), 76 deletions(-) diff --git a/data/challenges/city.challenge b/data/challenges/city.challenge index 37348b775..e62d0a8ec 100644 --- a/data/challenges/city.challenge +++ b/data/challenges/city.challenge @@ -2,6 +2,7 @@ + diff --git a/data/challenges/farm.challenge b/data/challenges/farm.challenge index c6120038e..85caeaedf 100644 --- a/data/challenges/farm.challenge +++ b/data/challenges/farm.challenge @@ -2,6 +2,7 @@ + diff --git a/data/challenges/fortmagma.challenge b/data/challenges/fortmagma.challenge index 238c89ff1..0879a9f9a 100644 --- a/data/challenges/fortmagma.challenge +++ b/data/challenges/fortmagma.challenge @@ -2,6 +2,7 @@ + diff --git a/data/challenges/hacienda.challenge b/data/challenges/hacienda.challenge index ab96b6194..bf357c2bd 100644 --- a/data/challenges/hacienda.challenge +++ b/data/challenges/hacienda.challenge @@ -2,6 +2,7 @@ + diff --git a/data/challenges/islandtrack.challenge b/data/challenges/islandtrack.challenge index 98588abf9..28b462c6a 100644 --- a/data/challenges/islandtrack.challenge +++ b/data/challenges/islandtrack.challenge @@ -2,6 +2,7 @@ + diff --git a/data/challenges/jungle.challenge b/data/challenges/jungle.challenge index 8ec1ebddf..28c7cb476 100644 --- a/data/challenges/jungle.challenge +++ b/data/challenges/jungle.challenge @@ -2,6 +2,7 @@ + diff --git a/data/challenges/lighthouse.challenge b/data/challenges/lighthouse.challenge index 7311f2a16..299343046 100644 --- a/data/challenges/lighthouse.challenge +++ b/data/challenges/lighthouse.challenge @@ -2,6 +2,7 @@ + diff --git a/data/challenges/mines.challenge b/data/challenges/mines.challenge index 6d3dc5ea7..bb9db83b7 100644 --- a/data/challenges/mines.challenge +++ b/data/challenges/mines.challenge @@ -2,7 +2,8 @@ - + + diff --git a/data/challenges/minigolf.challenge b/data/challenges/minigolf.challenge index 0327aeec0..c334ec84c 100644 --- a/data/challenges/minigolf.challenge +++ b/data/challenges/minigolf.challenge @@ -2,6 +2,7 @@ + diff --git a/data/challenges/olivermath.challenge b/data/challenges/olivermath.challenge index 1bee991ad..ae6a90f35 100644 --- a/data/challenges/olivermath.challenge +++ b/data/challenges/olivermath.challenge @@ -2,6 +2,7 @@ + diff --git a/data/challenges/sandtrack.challenge b/data/challenges/sandtrack.challenge index 89c535b6d..e00fb106f 100644 --- a/data/challenges/sandtrack.challenge +++ b/data/challenges/sandtrack.challenge @@ -2,6 +2,7 @@ + diff --git a/data/challenges/scotland.challenge b/data/challenges/scotland.challenge index 617cc6225..1bfa4344a 100644 --- a/data/challenges/scotland.challenge +++ b/data/challenges/scotland.challenge @@ -2,6 +2,7 @@ + diff --git a/data/challenges/snowmountain.challenge b/data/challenges/snowmountain.challenge index 85ea426e0..4769b1032 100644 --- a/data/challenges/snowmountain.challenge +++ b/data/challenges/snowmountain.challenge @@ -2,6 +2,7 @@ + diff --git a/data/challenges/snowpeak.challenge b/data/challenges/snowpeak.challenge index 97f20c71e..64cea8748 100644 --- a/data/challenges/snowpeak.challenge +++ b/data/challenges/snowpeak.challenge @@ -2,6 +2,7 @@ + diff --git a/data/challenges/startrack.challenge b/data/challenges/startrack.challenge index b6e49a1c3..684331834 100644 --- a/data/challenges/startrack.challenge +++ b/data/challenges/startrack.challenge @@ -2,6 +2,7 @@ + diff --git a/data/challenges/subsea.challenge b/data/challenges/subsea.challenge index fe144af8f..aa1d42cda 100644 --- a/data/challenges/subsea.challenge +++ b/data/challenges/subsea.challenge @@ -2,6 +2,7 @@ + diff --git a/data/challenges/tuxtollway.challenge b/data/challenges/tuxtollway.challenge index c31e412f9..1a9ecb6d2 100644 --- a/data/challenges/tuxtollway.challenge +++ b/data/challenges/tuxtollway.challenge @@ -2,6 +2,7 @@ + diff --git a/data/challenges/xr591.challenge b/data/challenges/xr591.challenge index caf8a3c33..9402d8ad7 100644 --- a/data/challenges/xr591.challenge +++ b/data/challenges/xr591.challenge @@ -2,6 +2,7 @@ + diff --git a/data/challenges/zengarden.challenge b/data/challenges/zengarden.challenge index c99e2e929..84571a03d 100644 --- a/data/challenges/zengarden.challenge +++ b/data/challenges/zengarden.challenge @@ -2,6 +2,7 @@ + diff --git a/src/challenges/challenge_data.cpp b/src/challenges/challenge_data.cpp index d076d7f79..6d643d01b 100644 --- a/src/challenges/challenge_data.cpp +++ b/src/challenges/challenge_data.cpp @@ -35,13 +35,14 @@ ChallengeData::ChallengeData(const std::string& filename) throw(std::runtime_error) #endif { - m_filename = filename; - m_major = RaceManager::MAJOR_MODE_SINGLE; - m_minor = RaceManager::MINOR_MODE_NORMAL_RACE; - m_num_laps = -1; - m_track_id = ""; - m_gp_id = ""; - m_version = 0; + m_filename = filename; + m_major = RaceManager::MAJOR_MODE_SINGLE; + m_minor = RaceManager::MINOR_MODE_NORMAL_RACE; + m_num_laps = -1; + m_track_id = ""; + m_gp_id = ""; + m_version = 0; + m_num_trophies = 0; for (int d=0; dgetNode("requirements"); + if (requirements_node == NULL) + { + throw std::runtime_error("Challenge file " + filename + " has no node!"); + } + requirements_node->get("trophies", &m_num_trophies); + + const XMLNode* mode_node = root->getNode("mode"); if (mode_node == NULL) { diff --git a/src/challenges/challenge_data.hpp b/src/challenges/challenge_data.hpp index 36bfcb164..4887c8928 100644 --- a/src/challenges/challenge_data.hpp +++ b/src/challenges/challenge_data.hpp @@ -76,6 +76,9 @@ private: /** Features to unlock. */ std::vector m_feature; + /** Number of trophies required to access this challenge */ + int m_num_trophies; + irr::core::stringw m_challenge_description; public: @@ -110,6 +113,9 @@ public: int getNumLaps() const { return m_num_laps; } + /** get number of required trophies to start this challenge */ + int getNumTrophies() const { return m_num_trophies; } + void addUnlockTrackReward(const std::string &track_name); void addUnlockModeReward(const std::string &internal_mode_name, const irr::core::stringw &user_mode_name); diff --git a/src/modes/overworld.cpp b/src/modes/overworld.cpp index 12f8299df..c92034cc5 100644 --- a/src/modes/overworld.cpp +++ b/src/modes/overworld.cpp @@ -141,7 +141,7 @@ void OverWorld::onFirePressed(Controller* who) Vec3 kart_xyz = getKart(0)->getXYZ(); for (unsigned int n=0; ngetChallenge(challenges[n].m_challenge_id); // bool locked = (m_locked_challenges.find(c) != m_locked_challenges.end()); - int state = (challenges[n].m_force_field.m_is_locked ? LOCKED : OPEN); + int state = (challenges[n].getForceField().m_is_locked ? LOCKED : OPEN); const Challenge* c = unlock_manager->getCurrentSlot()->getChallenge(challenges[n].m_challenge_id); if (c->isSolved(RaceManager::RD_HARD)) state = COMPLETED_HARD; @@ -340,7 +340,7 @@ void RaceGUIOverworld::drawGlobalMiniMap() // ---- Draw nearby challenge if any for (unsigned int n=0; nsupportsSplatting()) continue; } - else if (condition.find("trophies") == 0) - { - std::vector split = StringUtils::split(condition, ' '); - if (split.size() != 3) + else if (condition == "trophies") + { + // Associate force fields and challenges + // FIXME: this assumes that challenges will appear before force fields in scene.xml + // (which however seems to be the case atm) + int f = m_force_fields.size() - 1; + int closest_challenge_id = -1; + float closest_distance = 99999.0f; + for (unsigned int c=0; c= 0); + assert(closest_challenge_id < (int)m_challenges.size()); + + const ChallengeData* challenge = unlock_manager->getChallenge(m_challenges[closest_challenge_id].m_challenge_id); + if (challenge == NULL) + { + fprintf(stderr, "[Track] WARNING: Cannot find challenge named '%s'\n", + m_challenges[closest_challenge_id].m_challenge_id.c_str()); continue; } - const std::string& op = split[1]; - int val = -1; - if (StringUtils::fromString(split[2], val)) - { - // only 'lt' is supported atm - if (op != "lt") - { - fprintf(stderr, "[Track] WARNING: operator '%s' not supported in '%s'\n", op.c_str(), - condition.c_str()); - } - - bool shown = (unlock_manager->getCurrentSlot()->getPoints() < val); - - m_force_fields.push_back(OverworldForceField(xyz, shown, val)); - - core::stringw msg = StringUtils::toWString(val); - core::dimension2d textsize = GUIEngine::getHighresDigitFont()->getDimension(msg.c_str()); - scene::ISceneManager* sm = irr_driver->getSceneManager(); - - assert(GUIEngine::getHighresDigitFont() != NULL); - - scene::ISceneNode* sn = - sm->addBillboardTextSceneNode(GUIEngine::getHighresDigitFont(), - msg.c_str(), - NULL, - core::dimension2df(textsize.Width/45.0f, - textsize.Height/45.0f), - xyz, - -1 /* id */, - video::SColor(255, 255, 225, 0), - video::SColor(255, 255, 89, 0)); - m_all_nodes.push_back(sn); - if (!shown) continue; - } - else - { - fprintf(stderr, "[Track] WARNING: token '%s' in '%s' should have been a number\n", - split[2].c_str(), condition.c_str()); - } + + const int val = challenge->getNumTrophies(); + bool shown = (unlock_manager->getCurrentSlot()->getPoints() < val); + m_force_fields.push_back(OverworldForceField(xyz, shown, val)); + + m_challenges[closest_challenge_id].setForceField(m_force_fields[f]); + + core::stringw msg = StringUtils::toWString(val); + core::dimension2d textsize = GUIEngine::getHighresDigitFont()->getDimension(msg.c_str()); + scene::ISceneManager* sm = irr_driver->getSceneManager(); + + assert(GUIEngine::getHighresDigitFont() != NULL); + + scene::ISceneNode* sn = + sm->addBillboardTextSceneNode(GUIEngine::getHighresDigitFont(), + msg.c_str(), + NULL, + core::dimension2df(textsize.Width/45.0f, + textsize.Height/45.0f), + xyz, + -1 /* id */, + video::SColor(255, 255, 225, 0), + video::SColor(255, 255, 89, 0)); + m_all_nodes.push_back(sn); + if (!shown) continue; } else if (condition.size() > 0) { @@ -968,26 +975,6 @@ bool Track::loadMainTrack(const XMLNode &root) } // for i - // Associate force fields and challenges - for (unsigned int c=0; c= 0); - assert(closest_field_id < (int)m_force_fields.size()); - m_challenges[c].m_force_field = m_force_fields[closest_field_id]; - } - // Create LOD nodes std::vector lod_nodes; lodLoader.done(m_root, m_all_cached_meshes, lod_nodes); diff --git a/src/tracks/track.hpp b/src/tracks/track.hpp index 05d02fe89..cd2252bd6 100644 --- a/src/tracks/track.hpp +++ b/src/tracks/track.hpp @@ -83,14 +83,38 @@ struct OverworldForceField }; struct OverworldChallenge { +private: + OverworldForceField m_force_field; + bool m_force_field_set; +public: + core::vector3df m_position; std::string m_challenge_id; - OverworldForceField m_force_field; OverworldChallenge(core::vector3df position, std::string challenge_id) { m_position = position; m_challenge_id = challenge_id; + m_force_field_set = false; + } + + void setForceField(OverworldForceField f) + { + m_force_field = f; + m_force_field_set = true; + } + + OverworldForceField& getForceField() + { + assert(m_force_field_set); + return m_force_field; + } + + + const OverworldForceField& getForceField() const + { + assert(m_force_field_set); + return m_force_field; } };