Added version number to challenges (I replaced all Challenge

declarations with ChallengeData - I don't see a good
reason to keep both classes).


git-svn-id: svn+ssh://svn.code.sf.net/p/supertuxkart/code/main/trunk@7610 178a84e3-b1eb-0310-8ba1-8eac791a3b58
This commit is contained in:
hikerstk 2011-02-04 10:53:58 +00:00
parent 4d8ecb3612
commit 7b09afcb24
29 changed files with 119 additions and 58 deletions

View File

@ -1,6 +1,7 @@
<?xml version="1.0"?>
<challenge
version="1"
id="worldsend"
name="Win the At World's End Grand Prix"
description="Come first in the At World's End Grand Prix with 3 Expert AI karts."

View File

@ -1,6 +1,7 @@
<?xml version="1.0"?>
<challenge
version="1"
id="islandfollow"
name="Follow the Leader on a Desert Island"
description="Win a Follow the Leader race with 3 AI karts on a Desert Island."

View File

@ -1,6 +1,7 @@
<?xml version="1.0"?>
<challenge
version="1"
id="tollway"
name="Win a race on Tux Tollway"
description="Win a 3 lap race on Tux Tollway against 4 Expert level AI karts."

View File

@ -1,6 +1,7 @@
<?xml version="1.0"?>
<challenge
version="1"
id="energymathclass"
name="Collect Nitro in Math Class"
description="Finish with at least 10 points of nitro on three laps of Oliver's Math Class in under 55 seconds."

View File

@ -1,6 +1,7 @@
<?xml version="1.0"?>
<challenge
version="1"
id="penguinplaygroundgp"
name="Win Penguin Playground Grand Prix"
description="Win Penguin Playground Grand Prix with 3 Expert Level AI karts."

View File

@ -1,6 +1,7 @@
<?xml version="1.0"?>
<challenge
version="1"
id="minestime"
name="Finish Mines in 3:00"
description="Finish 3 laps in mines with 3 expert AI karts in under 3:00 minutes."

View File

@ -1,6 +1,7 @@
<?xml version="1.0"?>
<challenge
version="1"
id="fortmagma"
name="Win a race on Fort Magma"
description="Win a 3 lap race on Fort Magma against 3 Expert level AI karts."

View File

@ -1,6 +1,7 @@
<?xml version="1.0"?>
<challenge
version="1"
id="farmtracktime"
name="Finish Farm in 2:30"
description="Finish 3 laps in Farm with 3 easy AI karts in under 2:30 minutes."

View File

@ -1,6 +1,7 @@
<?xml version="1.0"?>
<challenge
version="1"
id="snowmountain"
name="Win a race on Snow Mountain"
description="Win a 3 lap race on Snow Mountain under 3:05 against 3 medium AI karts."

View File

@ -1,6 +1,7 @@
<?xml version="1.0"?>
<challenge
version="1"
id="starfollow"
name="Follow the Leader around the Solar System"
description="Win a Follow the Leader race with 5 AI karts on Star track"

View File

@ -1,6 +1,7 @@
<?xml version="1.0"?>
<challenge
version="1"
id="energyxr591"
name="Collect fuel for your rocket"
description="Finish with at least 16 nitro points on 2 laps of XR591 in under 2:30 minutes."

View File

@ -1,6 +1,7 @@
<?xml version="1.0"?>
<challenge
version="1"
id="gardenhead"
name="Win a Head to Head in the Secret Garden"
description="Win a 1 lap Head to Head in the Secret Garden against 1 Expert level AI kart."

View File

@ -1,6 +1,7 @@
<?xml version="1.0"?>
<challenge
version="1"
id="tothemoonandbackgp"
name="Win To the Moon and Back Grand Prix"
description="Win the To the Moon and Back Grand Prix with 3 Expert Level AI karts."

View File

@ -1,6 +1,7 @@
<?xml version="1.0"?>
<challenge
version="1"
id="lighthousetime"
name="Finish Lighthouse in 1:30"
description="Finish 3 laps in Lighthouse with 3 Expert AI karts in under 1:30 minutes."

View File

@ -1,6 +1,7 @@
<?xml version="1.0"?>
<challenge
version="1"
id="energyshiftingsands"
name="Collect the Pharaohs Treasure"
description="Finish with at least 12 nitro points on 3 laps of Shifting Sands in under 2:20 minutes."

View File

@ -1,6 +1,7 @@
<?xml version="1.0"?>
<challenge
version="1"
id="canyon"
name="Win a race on Canyon"
description="Win a 3 lap race on Canyon against 4 Expert level AI karts."

View File

@ -172,8 +172,6 @@ void Challenge::load(const XMLNode* challengesNode)
bool finished=false;
node->get("solved", &finished);
m_state = finished ? CH_SOLVED : CH_INACTIVE;
m_version = 0;
node->get("version", &m_version);
if(!finished) loadAdditionalInfo(node);
} // load
@ -181,7 +179,8 @@ void Challenge::load(const XMLNode* challengesNode)
//-----------------------------------------------------------------------------
void Challenge::save(std::ofstream& writer)
{
writer << " <" << getId() << " solved=\"" << (isSolved() ? "true" : "false") << "\"";
writer << " <" << getId() << " solved=\""
<< (isSolved() ? "true" : "false") << "\"";
if(!isSolved()) saveAdditionalInfo(writer);
writer << " />\n";
} // save

View File

@ -69,8 +69,6 @@ private:
std::vector<UnlockableFeature> m_feature;
/** What needs to be done before accessing this challenge. */
std::vector<std::string> m_prerequisites;
/** Version number of the challenge. */
int m_version;
public:
Challenge(const std::string &id, const std::string &name);

View File

@ -21,6 +21,7 @@
#include <stdexcept>
#include <sstream>
#include "challenges/unlock_manager.hpp"
#include "karts/kart.hpp"
#include "karts/kart_properties_manager.hpp"
#include "modes/linear_world.hpp"
@ -47,9 +48,9 @@ ChallengeData::ChallengeData(const std::string& filename)
m_track_name = "";
m_gp_id = "";
m_energy = -1;
m_version = 0;
XMLNode *root = new XMLNode( filename );
// if(!root || root->getName()!="challenges")
if(!root || root->getName()!="challenge")
{
delete root;
@ -58,6 +59,19 @@ ChallengeData::ChallengeData(const std::string& filename)
throw std::runtime_error(msg.str());
}
std::string s;
if(!root->get("id", &s) ) error("id");
setId(s);
root->get("version", &m_version);
// No need to get the rest of the data if this challenge
// is not supported anyway (id is needed for warning message)
if(!unlock_manager->isSupportedVersion(*this))
{
delete root;
return;
}
std::string mode;
root->get("major", &mode);
@ -78,14 +92,10 @@ ChallengeData::ChallengeData(const std::string& filename)
else
error("minor");
std::string s;
if(!root->get("name", &s) ) error("name");
//std::cout << " // Challenge name = <" << s.c_str() << ">\n";
setName( _(s.c_str()) );
if(!root->get("id", &s) ) error("id");
setId(s);
if(!root->get("description", &s) ) error("description");
setChallengeDescription( _(s.c_str()) );
//std::cout << " // Challenge description = <" << s.c_str() << ">\n";

View File

@ -45,6 +45,8 @@ private:
std::string m_track_name;
int m_energy;
std::string m_filename;
/** Version number of the challenge. */
int m_version;
void getUnlocks(const XMLNode *root, const std:: string type, REWARD_TYPE reward);
void error(const char *id) const;
@ -62,6 +64,8 @@ public:
virtual void check() const;
virtual bool raceFinished();
virtual bool grandPrixFinished();
/** Returns the version number of this challenge. */
int getVersion() const { return m_version; }
}; // ChallengeData
#endif // HEADER_CHALLENGE_DATA_HPP

View File

@ -106,10 +106,10 @@ void UnlockManager::readAllChallengesInDirs(const std::vector<std::string>* all_
if (f)
{
fclose(f);
ChallengeData* newChallenge = NULL;
ChallengeData* new_challenge = NULL;
try
{
newChallenge = new ChallengeData(filename);
new_challenge = new ChallengeData(filename);
}
catch (std::runtime_error& ex)
{
@ -117,7 +117,7 @@ void UnlockManager::readAllChallengesInDirs(const std::vector<std::string>* all_
<< ex.what() << " : challenge will be ignored.\n\n";
continue;
}
addChallenge(newChallenge);
addOrFreeChallenge(new_challenge);
} // if file
} // for file in files
@ -125,37 +125,52 @@ void UnlockManager::readAllChallengesInDirs(const std::vector<std::string>* all_
}
//-----------------------------------------------------------------------------
void UnlockManager::addChallenge(Challenge *c)
/** If a challenge is supported by this binary (i.e. has an appropriate
* challenge version number), add this challenge to the set of all challenges,
* otherwise free the memory for this challenge.
* \param c The challenge that is either stored or freed.
*/
void UnlockManager::addOrFreeChallenge(ChallengeData *c)
{
m_all_challenges[c->getId()]=c;
} // addChallenge
if(isSupportedVersion(*c))
m_all_challenges[c->getId()]=c;
else
{
printf("[challenge] Challenge '%s' is not supported - ignored.\n",
c->getId().c_str());
delete c;
}
} // addOrFreeChallenge
//-----------------------------------------------------------------------------
/** Reads a challenge from the given filename. The challenge will then either
* be stored, or (if the challenge version is not supported anymore
* \param filename Name of the challenge file to read.
*/
void UnlockManager::addChallenge(const std::string& filename)
{
ChallengeData* newChallenge = NULL;
ChallengeData* new_challenge = NULL;
try
{
newChallenge = new ChallengeData(filename);
newChallenge->check();
new_challenge = new ChallengeData(filename);
new_challenge->check();
}
catch (std::runtime_error& ex)
{
std::cerr << "\n/!\\ An error occurred while loading challenge file '" << filename << "' : "
<< ex.what() << " : challenge will be ignored.\n\n";
if (newChallenge != NULL) delete newChallenge;
if (new_challenge != NULL) delete new_challenge;
return;
}
addChallenge(newChallenge);
addOrFreeChallenge(new_challenge);
} // addChallenge
//-----------------------------------------------------------------------------
std::vector<const Challenge*> UnlockManager::getActiveChallenges()
std::vector<const ChallengeData*> UnlockManager::getActiveChallenges()
{
computeActive();
std::vector<const Challenge*> all_active;
std::vector<const ChallengeData*> all_active;
for(AllChallengesType::iterator i =m_all_challenges.begin();
i!=m_all_challenges.end(); i++)
{
@ -165,7 +180,7 @@ std::vector<const Challenge*> UnlockManager::getActiveChallenges()
} // getActiveChallenges
//-----------------------------------------------------------------------------
const Challenge* UnlockManager::getChallenge(const std::string& id)
const ChallengeData* UnlockManager::getChallenge(const std::string& id)
{
if(m_all_challenges.find(id)==m_all_challenges.end()) return NULL;
return m_all_challenges[id];
@ -224,10 +239,22 @@ void UnlockManager::save()
challenge_file.close();
} // save
//-----------------------------------------------------------------------------
void UnlockManager::playLockSound() const
{
m_locked_sound->play();
}
} // playLockSound
//-----------------------------------------------------------------------------
/** Test if the given challenge is supported by this binary.
* \param challenge The challenge to test.
*/
bool UnlockManager::isSupportedVersion(const ChallengeData &challenge)
{
// Test if challenge version number is in between minimum
// and maximum supported version.
return (challenge.getVersion()>=1 && challenge.getVersion()<=1);
} // isSupportedVersion
//-----------------------------------------------------------------------------
void UnlockManager::computeActive()
@ -255,7 +282,7 @@ void UnlockManager::computeActive()
for(std::vector<std::string>::iterator pre =pre_req.begin();
pre!=pre_req.end(); pre++)
{
const Challenge*p = getChallenge(*pre);
const ChallengeData *p = getChallenge(*pre);
if(!p)
{
fprintf(stderr,"Challenge prerequisite '%s' of '%s' not found - ignored\n",
@ -310,7 +337,7 @@ void UnlockManager::grandPrixFinished()
} // grandPrixFinished
//-----------------------------------------------------------------------------
void UnlockManager::lockFeature(Challenge* challenge)
void UnlockManager::lockFeature(const ChallengeData *challenge)
{
const unsigned int amount = (unsigned int)challenge->getFeatures().size();
for(unsigned int n=0; n<amount; n++)
@ -319,7 +346,7 @@ void UnlockManager::lockFeature(Challenge* challenge)
//-----------------------------------------------------------------------------
void UnlockManager::unlockFeature(Challenge* c, bool do_save)
void UnlockManager::unlockFeature(ChallengeData* c, bool do_save)
{
const unsigned int amount = (unsigned int)c->getFeatures().size();
for(unsigned int n=0; n<amount; n++)
@ -349,9 +376,9 @@ bool UnlockManager::isLocked(const std::string& feature)
return m_locked_features.find(feature)!=m_locked_features.end();
} // featureIsLocked
//-----------------------------------------------------------------------------
const std::vector<const Challenge*> UnlockManager::getUnlockedFeatures()
const std::vector<const ChallengeData*> UnlockManager::getUnlockedFeatures()
{
std::vector<const Challenge*> out;
std::vector<const ChallengeData*> out;
for(AllChallengesType::const_iterator i =m_all_challenges.begin();
i!=m_all_challenges.end(); i++)
@ -362,9 +389,9 @@ const std::vector<const Challenge*> UnlockManager::getUnlockedFeatures()
return out;
}
//-----------------------------------------------------------------------------
const std::vector<const Challenge*> UnlockManager::getLockedChallenges()
const std::vector<const ChallengeData*> UnlockManager::getLockedChallenges()
{
std::vector<const Challenge*> out;
std::vector<const ChallengeData*> out;
for(AllChallengesType::const_iterator i =m_all_challenges.begin();
i!=m_all_challenges.end(); i++)

View File

@ -22,7 +22,7 @@
#include <map>
#include "challenges/challenge.hpp"
#include "challenges/challenge_data.hpp"
#include "utils/no_copy.hpp"
#include <fstream>
@ -38,45 +38,46 @@ class UnlockManager : public NoCopy
{
private:
SFXBase *m_locked_sound;
typedef std::map<std::string, Challenge*> AllChallengesType;
typedef std::map<std::string, ChallengeData*> AllChallengesType;
AllChallengesType m_all_challenges;
std::map<std::string, bool> m_locked_features;
std::vector<const Challenge*> m_unlocked_features;
std::vector<const ChallengeData*> m_unlocked_features;
void computeActive ();
void load ();
void unlockFeature (Challenge* c, bool do_save=true);
void unlockFeature (ChallengeData* c, bool do_save=true);
void readAllChallengesInDirs(const std::vector<std::string>* all_dirs);
public:
UnlockManager ();
~UnlockManager ();
void addChallenge (Challenge *c);
void addOrFreeChallenge(ChallengeData *c);
void addChallenge (const std::string& filename);
void save ();
std::vector<const Challenge*>
std::vector<const ChallengeData*>
getActiveChallenges();
/** Returns the list of recently unlocked features (e.g. call at the end of a
race to know if any features were unlocked) */
const std::vector<const Challenge*>
const std::vector<const ChallengeData*>
getRecentlyUnlockedFeatures() {return m_unlocked_features;}
/** Clear the list of recently unlocked challenges */
void clearUnlocked () {m_unlocked_features.clear(); }
/** Returns a complete list of all solved challenges */
const std::vector<const Challenge*> getUnlockedFeatures();
const std::vector<const ChallengeData*> getUnlockedFeatures();
/** Returns the list of currently inaccessible (locked) challenges */
const std::vector<const Challenge*> getLockedChallenges();
const std::vector<const ChallengeData*> getLockedChallenges();
const Challenge *getChallenge (const std::string& id);
const ChallengeData *getChallenge (const std::string& id);
void raceFinished ();
void grandPrixFinished ();
void lockFeature (Challenge* challenge);
void lockFeature (const ChallengeData *challenge);
bool isLocked (const std::string& feature);
bool isSupportedVersion(const ChallengeData &challenge);
/** Eye- (or rather ear-) candy. Play a sound when user tries to access a locked area */
void playLockSound() const;

View File

@ -72,9 +72,9 @@ void ChallengesScreen::init()
// Re-build track list everytime (accounts for locking changes, etc.)
w->clearItems();
const std::vector<const Challenge*>& activeChallenges = unlock_manager->getActiveChallenges();
const std::vector<const Challenge*>& solvedChallenges = unlock_manager->getUnlockedFeatures();
const std::vector<const Challenge*>& lockedChallenges = unlock_manager->getLockedChallenges();
const std::vector<const ChallengeData*>& activeChallenges = unlock_manager->getActiveChallenges();
const std::vector<const ChallengeData*>& solvedChallenges = unlock_manager->getUnlockedFeatures();
const std::vector<const ChallengeData*>& lockedChallenges = unlock_manager->getLockedChallenges();
const int activeChallengeAmount = activeChallenges.size();
const int solvedChallengeAmount = solvedChallenges.size();

View File

@ -476,10 +476,12 @@ GUIEngine::EventPropagation RaceOverDialog::processEvent(const std::string& even
}
else if (eventSource == "seeunlocked")
{
std::vector<const Challenge*> unlocked = unlock_manager->getRecentlyUnlockedFeatures();
std::vector<const ChallengeData*> unlocked =
unlock_manager->getRecentlyUnlockedFeatures();
unlock_manager->clearUnlocked();
FeatureUnlockedCutScene* scene = FeatureUnlockedCutScene::getInstance();
FeatureUnlockedCutScene* scene =
FeatureUnlockedCutScene::getInstance();
/*
scene->addUnlockedKart( const_cast<KartProperties*>(kart_properties_manager->getKart("gnu")),

View File

@ -21,7 +21,7 @@
#include <SColor.h>
#include "challenges/challenge.hpp"
#include "challenges/challenge_data.hpp"
#include "guiengine/engine.hpp"
#include "guiengine/scalable_font.hpp"
#include "io/file_manager.hpp"
@ -484,7 +484,7 @@ void FeatureUnlockedCutScene::onUpdate(float dt,
// ----------------------------------------------------------------------------
void FeatureUnlockedCutScene::addUnlockedThings(const std::vector<const Challenge*> unlocked)
void FeatureUnlockedCutScene::addUnlockedThings(const std::vector<const ChallengeData*> unlocked)
{
for (unsigned int n=0; n<unlocked.size(); n++)
{

View File

@ -26,7 +26,7 @@
namespace irr { namespace scene { class ISceneNode; class ICameraSceneNode; class ILightSceneNode; } }
class KartProperties;
class Challenge;
class ChallengeData;
/**
* \brief Screen shown when a feature has been unlocked
@ -146,7 +146,7 @@ public:
/** Call before showing up the screen to make whatever the passed challenges unlocked
* come out of the chest */
void addUnlockedThings(const std::vector<const Challenge*> unlocked);
void addUnlockedThings(const std::vector<const ChallengeData*> unlocked);
/** override from base class to handle escape press */

View File

@ -267,10 +267,12 @@ void GrandPrixLose::eventCallback(GUIEngine::Widget* widget,
if (unlock_manager->getRecentlyUnlockedFeatures().size() > 0)
{
std::vector<const Challenge*> unlocked = unlock_manager->getRecentlyUnlockedFeatures();
std::vector<const ChallengeData*> unlocked =
unlock_manager->getRecentlyUnlockedFeatures();
unlock_manager->clearUnlocked();
FeatureUnlockedCutScene* scene = FeatureUnlockedCutScene::getInstance();
FeatureUnlockedCutScene* scene =
FeatureUnlockedCutScene::getInstance();
assert(unlocked.size() > 0);
scene->addUnlockedThings(unlocked);

View File

@ -394,10 +394,12 @@ void GrandPrixWin::eventCallback(GUIEngine::Widget* widget,
if (unlock_manager->getRecentlyUnlockedFeatures().size() > 0)
{
std::vector<const Challenge*> unlocked = unlock_manager->getRecentlyUnlockedFeatures();
std::vector<const ChallengeData*> unlocked =
unlock_manager->getRecentlyUnlockedFeatures();
unlock_manager->clearUnlocked();
FeatureUnlockedCutScene* scene = FeatureUnlockedCutScene::getInstance();
FeatureUnlockedCutScene* scene =
FeatureUnlockedCutScene::getInstance();
assert(unlocked.size() > 0);
scene->addUnlockedThings(unlocked);

View File

@ -130,7 +130,7 @@ void RaceResultGUI::eventCallback(GUIEngine::Widget* widget,
{
if(name=="top")
{
std::vector<const Challenge*> unlocked =
std::vector<const ChallengeData*> unlocked =
unlock_manager->getRecentlyUnlockedFeatures();
unlock_manager->clearUnlocked();
FeatureUnlockedCutScene* scene = FeatureUnlockedCutScene::getInstance();