Bugfix: incorrect track name or GP in a challenge will not cause a crash
when trying to use to do the challenge, instead STK will abort with an error message indicating the problem at startup (see bug 2316973). git-svn-id: svn+ssh://svn.code.sf.net/p/supertuxkart/code/trunk/supertuxkart@2851 178a84e3-b1eb-0310-8ba1-8eac791a3b58
This commit is contained in:
parent
4c3834e4e2
commit
b643cfd599
@ -94,5 +94,7 @@ public:
|
|||||||
virtual bool raceFinished() {return false;} // end of a race
|
virtual bool raceFinished() {return false;} // end of a race
|
||||||
virtual bool grandPrixFinished() {return false;} // end of a GP
|
virtual bool grandPrixFinished() {return false;} // end of a GP
|
||||||
virtual void setRace() const = 0; // set race to use
|
virtual void setRace() const = 0; // set race to use
|
||||||
|
/** Checks if a challenge is valid. */
|
||||||
|
virtual void check() const = 0;
|
||||||
};
|
};
|
||||||
#endif
|
#endif
|
||||||
|
@ -24,6 +24,7 @@
|
|||||||
#include "translation.hpp"
|
#include "translation.hpp"
|
||||||
#include "grand_prix_data.hpp"
|
#include "grand_prix_data.hpp"
|
||||||
#include "grand_prix_manager.hpp"
|
#include "grand_prix_manager.hpp"
|
||||||
|
#include "track_manager.hpp"
|
||||||
#include "karts/kart.hpp"
|
#include "karts/kart.hpp"
|
||||||
#include "lisp/lisp.hpp"
|
#include "lisp/lisp.hpp"
|
||||||
#include "lisp/parser.hpp"
|
#include "lisp/parser.hpp"
|
||||||
@ -135,7 +136,7 @@ ChallengeData::ChallengeData(const std::string& filename)
|
|||||||
} // ChallengeData
|
} // ChallengeData
|
||||||
|
|
||||||
// ----------------------------------------------------------------------------
|
// ----------------------------------------------------------------------------
|
||||||
void ChallengeData::error(const char *id)
|
void ChallengeData::error(const char *id) const
|
||||||
{
|
{
|
||||||
char msg[MAX_ERROR_MESSAGE_LENGTH];
|
char msg[MAX_ERROR_MESSAGE_LENGTH];
|
||||||
snprintf(msg, sizeof(msg), "Undefined or incorrect value for '%s' in challenge file '%s'.",
|
snprintf(msg, sizeof(msg), "Undefined or incorrect value for '%s' in challenge file '%s'.",
|
||||||
@ -143,6 +144,33 @@ void ChallengeData::error(const char *id)
|
|||||||
throw std::runtime_error(msg);
|
throw std::runtime_error(msg);
|
||||||
} // error
|
} // error
|
||||||
// ----------------------------------------------------------------------------
|
// ----------------------------------------------------------------------------
|
||||||
|
/** Checks if this challenge is valid, i.e. contains a valid track or a valid
|
||||||
|
* GP. If incorrect data are found, STK is aborted with an error message.
|
||||||
|
* (otherwise STK aborts when trying to do this challenge, which is worse).
|
||||||
|
*/
|
||||||
|
void ChallengeData::check() const
|
||||||
|
{
|
||||||
|
if(m_major==RaceManager::MAJOR_MODE_SINGLE)
|
||||||
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
track_manager->getTrack(m_track_name);
|
||||||
|
}
|
||||||
|
catch(std::exception&)
|
||||||
|
{
|
||||||
|
error("track");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else if(m_major==RaceManager::MAJOR_MODE_GRAND_PRIX)
|
||||||
|
{
|
||||||
|
if(!grand_prix_manager->getGrandPrix(m_gp_id))
|
||||||
|
{
|
||||||
|
error("gp");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} // check
|
||||||
|
|
||||||
|
// ----------------------------------------------------------------------------
|
||||||
|
|
||||||
|
|
||||||
void ChallengeData::getUnlocks(const lisp::Lisp *lisp, const char* type,
|
void ChallengeData::getUnlocks(const lisp::Lisp *lisp, const char* type,
|
||||||
|
@ -45,11 +45,12 @@ private:
|
|||||||
|
|
||||||
std::string m_filename;
|
std::string m_filename;
|
||||||
void getUnlocks(const lisp::Lisp *lisp, const char* type, REWARD_TYPE reward);
|
void getUnlocks(const lisp::Lisp *lisp, const char* type, REWARD_TYPE reward);
|
||||||
void error(const char *id);
|
void error(const char *id) const;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
ChallengeData(const std::string& filename);
|
ChallengeData(const std::string& filename);
|
||||||
void setRace() const;
|
void setRace() const;
|
||||||
|
virtual void check() const;
|
||||||
virtual bool raceFinished();
|
virtual bool raceFinished();
|
||||||
virtual bool grandPrixFinished();
|
virtual bool grandPrixFinished();
|
||||||
}; // ChallengeData
|
}; // ChallengeData
|
||||||
|
@ -451,6 +451,8 @@ void InitTuxkart()
|
|||||||
grand_prix_manager = new GrandPrixManager ();
|
grand_prix_manager = new GrandPrixManager ();
|
||||||
network_manager = new NetworkManager ();
|
network_manager = new NetworkManager ();
|
||||||
track_manager->loadTrackList();
|
track_manager->loadTrackList();
|
||||||
|
// Check needs GP and track manager.
|
||||||
|
unlock_manager->check();
|
||||||
sound_manager->addMusicToTracks();
|
sound_manager->addMusicToTracks();
|
||||||
|
|
||||||
stk_config->load(file_manager->getConfigFile("stk_config.data"));
|
stk_config->load(file_manager->getConfigFile("stk_config.data"));
|
||||||
|
@ -128,6 +128,20 @@ void UnlockManager::addChallenge(const std::string& filename)
|
|||||||
{
|
{
|
||||||
addChallenge(new ChallengeData(filename));
|
addChallenge(new ChallengeData(filename));
|
||||||
} // addChallenge
|
} // addChallenge
|
||||||
|
//-----------------------------------------------------------------------------
|
||||||
|
/** Checks if all challenges are valid, i.e. contain a valid track or GP.
|
||||||
|
* If not, STK is aborted with an error message.
|
||||||
|
*/
|
||||||
|
void UnlockManager::check() const
|
||||||
|
{
|
||||||
|
for(AllChallengesType::const_iterator i =m_all_challenges.begin();
|
||||||
|
i!=m_all_challenges.end(); i++)
|
||||||
|
{
|
||||||
|
i->second->check();
|
||||||
|
} // for i
|
||||||
|
|
||||||
|
} // check
|
||||||
|
|
||||||
//-----------------------------------------------------------------------------
|
//-----------------------------------------------------------------------------
|
||||||
std::vector<const Challenge*> UnlockManager::getActiveChallenges()
|
std::vector<const Challenge*> UnlockManager::getActiveChallenges()
|
||||||
{
|
{
|
||||||
|
@ -53,6 +53,7 @@ public:
|
|||||||
void unlockFeature (Challenge* c, bool save=true);
|
void unlockFeature (Challenge* c, bool save=true);
|
||||||
void lockFeature (Challenge* challenge);
|
void lockFeature (Challenge* challenge);
|
||||||
bool isLocked (const std::string& feature);
|
bool isLocked (const std::string& feature);
|
||||||
|
void check () const;
|
||||||
}; // UnlockManager
|
}; // UnlockManager
|
||||||
|
|
||||||
extern UnlockManager* unlock_manager;
|
extern UnlockManager* unlock_manager;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user