Fixed challenges to support multiple rewards. Made translation easier.
git-svn-id: svn+ssh://svn.code.sf.net/p/supertuxkart/code/trunk/supertuxkart@1878 178a84e3-b1eb-0310-8ba1-8eac791a3b58
This commit is contained in:
parent
e07416f898
commit
1047d5e184
@ -17,7 +17,11 @@
|
||||
// along with this program; if not, write to the Free Software
|
||||
// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
|
||||
|
||||
#include "translation.hpp"
|
||||
#include "challenges/challenge.hpp"
|
||||
#include "world.hpp"
|
||||
#include "race_manager.hpp"
|
||||
#include "track_manager.hpp"
|
||||
|
||||
Challenge::Challenge(std::string id, std::string name) :
|
||||
m_state(CH_INACTIVE), m_Id(id), m_Name(name)
|
||||
@ -51,3 +55,71 @@ void Challenge::save(lisp::Writer* writer)
|
||||
} // save
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
void Challenge::addUnlockTrackReward(std::string track_name)
|
||||
{
|
||||
UnlockableFeature feature;
|
||||
feature.name = track_name;
|
||||
feature.type = UNLOCK_TRACK;
|
||||
m_feature.push_back(feature);
|
||||
}
|
||||
//-----------------------------------------------------------------------------
|
||||
void Challenge::addUnlockModeReward(std::string internal_mode_name, std::string user_mode_name)
|
||||
{
|
||||
UnlockableFeature feature;
|
||||
feature.name = internal_mode_name;
|
||||
feature.type = UNLOCK_MODE;
|
||||
feature.user_name = user_mode_name;
|
||||
m_feature.push_back(feature);
|
||||
}
|
||||
//-----------------------------------------------------------------------------
|
||||
void Challenge::addUnlockGPReward(std::string gp_name)
|
||||
{
|
||||
UnlockableFeature feature;
|
||||
feature.name = gp_name;
|
||||
feature.type = UNLOCK_GP;
|
||||
m_feature.push_back(feature);
|
||||
}
|
||||
//-----------------------------------------------------------------------------
|
||||
void Challenge::addUnlockDifficultyReward(std::string internal_name, std::string user_name)
|
||||
{
|
||||
UnlockableFeature feature;
|
||||
feature.name = internal_name;
|
||||
feature.type = UNLOCK_DIFFICULTY;
|
||||
feature.user_name = user_name;
|
||||
m_feature.push_back(feature);
|
||||
}
|
||||
//-----------------------------------------------------------------------------
|
||||
const std::string Challenge::getUnlockedMessage() const
|
||||
{
|
||||
std::string unlocked_message;
|
||||
|
||||
const unsigned int amount = m_feature.size();
|
||||
for(unsigned int n=0; n<amount; n++)
|
||||
{
|
||||
// add line break if we are showing multiple messages
|
||||
if(n>0) unlocked_message+='\n';
|
||||
|
||||
char message[128];
|
||||
|
||||
// write message depending on feature type
|
||||
switch(m_feature[n].type)
|
||||
{
|
||||
case UNLOCK_TRACK:
|
||||
Track* track = track_manager->getTrack( m_feature[n].name );
|
||||
snprintf(message, 127, _("New track '%s'\nnow available"), gettext(track->getName()) );
|
||||
break;
|
||||
case UNLOCK_MODE:
|
||||
snprintf(message, 127, _("New game mode\n'%s'\nnow available"), m_feature[n].user_name.c_str() );
|
||||
break;
|
||||
case UNLOCK_GP:
|
||||
snprintf(message, 127, _("New Grand Prix '%s'\nnow available"), m_feature[n].name.c_str() );
|
||||
break;
|
||||
case UNLOCK_DIFFICULTY:
|
||||
snprintf(message, 127, _("New difficulty\n'%s'\nnow available"), m_feature[n].user_name.c_str() );
|
||||
break;
|
||||
}
|
||||
unlocked_message += message;
|
||||
}
|
||||
|
||||
return unlocked_message;
|
||||
}
|
@ -27,6 +27,18 @@
|
||||
#include "lisp/parser.hpp"
|
||||
#include "lisp/writer.hpp"
|
||||
|
||||
enum REWARD_TYPE
|
||||
{UNLOCK_TRACK,
|
||||
UNLOCK_GP,
|
||||
UNLOCK_MODE,
|
||||
UNLOCK_DIFFICULTY};
|
||||
|
||||
struct UnlockableFeature
|
||||
{
|
||||
std::string name; // itnernal name
|
||||
std::string user_name; // not all types of feature have one
|
||||
REWARD_TYPE type;
|
||||
};
|
||||
|
||||
// A base class for all challenges
|
||||
class Challenge
|
||||
@ -36,32 +48,34 @@ class Challenge
|
||||
CH_SOLVED} m_state; // challenge was solved
|
||||
std::string m_Id; // short, internal name for this challenge
|
||||
std::string m_Name; // name used in menu for this challenge
|
||||
std::string m_Description; // description
|
||||
std::string m_feature_description; // Description of feature to unlock
|
||||
std::string m_feature; // Feature to unlock
|
||||
std::vector<std::string> m_prerequisites;
|
||||
std::string m_challenge_description; // Message the user gets when the feature is not yet unlocked
|
||||
std::vector<UnlockableFeature> m_feature; // Features to unlock
|
||||
std::vector<std::string> m_prerequisites; // what needs to be done before accessing this challenge
|
||||
public:
|
||||
Challenge(std::string id, std::string name);
|
||||
virtual ~Challenge() {};
|
||||
const std::string& getId() const {return m_Id; }
|
||||
const std::string& getName() const {return m_Name; }
|
||||
void setFeatureDescription(const std::string& f)
|
||||
{m_feature_description=f; }
|
||||
const std::string&
|
||||
getFeatureDescription() const {return m_feature_description; }
|
||||
void setFeature(const std::string& s) {m_feature=s; }
|
||||
const std::string& getFeature() const {return m_feature; }
|
||||
|
||||
void addUnlockTrackReward(std::string track_name);
|
||||
void addUnlockModeReward(std::string internal_mode_name, std::string user_mode_name);
|
||||
void addUnlockGPReward(std::string gp_name);
|
||||
void addUnlockDifficultyReward(std::string internal_name, std::string user_name);
|
||||
|
||||
const std::string getUnlockedMessage() const;
|
||||
const std::vector<UnlockableFeature>&
|
||||
getFeatures() const {return m_feature; }
|
||||
void setChallengeDescription(const std::string& d)
|
||||
{m_Description=d; }
|
||||
{m_challenge_description=d; }
|
||||
const std::string&
|
||||
getChallengeDescription() const {return m_Description; }
|
||||
void addDependency(const std::string id) {m_prerequisites.push_back(id);}
|
||||
bool isSolved() const {return m_state==CH_SOLVED; }
|
||||
bool isActive() const {return m_state==CH_ACTIVE; }
|
||||
void setSolved() {m_state = CH_SOLVED; }
|
||||
void setActive() {m_state = CH_ACTIVE; }
|
||||
getChallengeDescription() const {return m_challenge_description; }
|
||||
void addDependency(const std::string id) {m_prerequisites.push_back(id); }
|
||||
bool isSolved() const {return m_state==CH_SOLVED; }
|
||||
bool isActive() const {return m_state==CH_ACTIVE; }
|
||||
void setSolved() {m_state = CH_SOLVED; }
|
||||
void setActive() {m_state = CH_ACTIVE; }
|
||||
const std::vector<std::string>&
|
||||
getPrerequisites() const {return m_prerequisites; }
|
||||
getPrerequisites() const {return m_prerequisites; }
|
||||
void load(const lisp::Lisp* config);
|
||||
void save(lisp::Writer* writer);
|
||||
|
||||
|
@ -25,8 +25,7 @@
|
||||
CityTime::CityTime() : Challenge("citytime", _("Finish the City track in 5:20"))
|
||||
{
|
||||
setChallengeDescription(_("Finish 3 laps on the City track\nwith 3 AI karts\nin under 5:20 minutes."));
|
||||
setFeatureDescription(_("New track: SnowTux Peak\nnow available"));
|
||||
setFeature("snowtuxpeak");
|
||||
addUnlockTrackReward("snowtuxpeak");
|
||||
addDependency("junglefollow");
|
||||
} // CityTime
|
||||
//-----------------------------------------------------------------------------
|
||||
|
@ -26,8 +26,7 @@
|
||||
EnergyMathClass::EnergyMathClass() : Challenge("energymathclass", _("Collect Coins in Math Class"))
|
||||
{
|
||||
setChallengeDescription(_("Collect at least 6 coins\non three laps of\nOliver's Math Class\nin under 1 minute."));
|
||||
setFeatureDescription(_("New game mode\n'Grand Prix'\nnow available"));
|
||||
setFeature("grandprix");
|
||||
addUnlockModeReward("grandprix", _("Grand Prix"));
|
||||
} // EnergyMathClass
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
|
@ -25,8 +25,7 @@
|
||||
EnergyShiftingSands::EnergyShiftingSands() : Challenge("energyshiftingsands", _("Collect the Pharaohs Treasure"))
|
||||
{
|
||||
setChallengeDescription(_("Collect at least 9 coins\non 3 laps of Shifting Sands\nin under 2:20 minutes."));
|
||||
setFeatureDescription(_("New Grand Prix:\nTo the Moon and Back\nnow available"));
|
||||
setFeature("To the Moon and Back");
|
||||
addUnlockGPReward("To the Moon and Back");
|
||||
// The energymathclass challenge must be done, otherwise GP can't be selected
|
||||
addDependency("energymathclass");
|
||||
addDependency("racetracktime");
|
||||
|
@ -25,8 +25,7 @@
|
||||
IslandFollow::IslandFollow() : Challenge("islandfollow", _("Follow the Leader on a\nDesert Island"))
|
||||
{
|
||||
setChallengeDescription(_("Win a Follow the Leader race\nwith 3 AI karts\non a Desert Island."));
|
||||
setFeatureDescription(_("New Grand Prix: At World's End\nnow available"));
|
||||
setFeature("At world's end");
|
||||
addUnlockGPReward("At world's end");
|
||||
addDependency("moonandbackgp");
|
||||
addDependency("tollwaytime");
|
||||
addDependency("citytime");
|
||||
|
@ -25,8 +25,7 @@
|
||||
JungleFollow::JungleFollow() : Challenge("junglefollow", _("Follow the Leader in the Jungle"))
|
||||
{
|
||||
setChallengeDescription(_("Win a Follow the Leader race\nwith 3 AI karts\nin the Amazonian Jungle."));
|
||||
setFeatureDescription(_("New track: City\nnow available"));
|
||||
setFeature("city");
|
||||
addUnlockTrackReward("city");
|
||||
addDependency("penguinplaygroundgp");
|
||||
addDependency("racetracktime");
|
||||
} // JungleFollow
|
||||
|
@ -25,8 +25,7 @@
|
||||
MoonAndBackGP::MoonAndBackGP() : Challenge("moonandbackgp",_("Win To the Moon and Back\nGrand Prix"))
|
||||
{
|
||||
setChallengeDescription(_("Win the To the Moon and Back\nGrand Prix with 3 'Racer'\nLevel AI karts."));
|
||||
setFeatureDescription(_("New Grand Prix: Snag Drive\nnow available"));
|
||||
setFeature("Snag Drive"); //gp3
|
||||
addUnlockGPReward("Snag Drive");
|
||||
// The energyshiftingsands challenge must be done, otherwise gp2 can't be selected
|
||||
// Thejunglefollow challenge must be done, to get city for gp3
|
||||
addDependency("energyshiftingsands");
|
||||
|
@ -25,8 +25,7 @@
|
||||
PenguinPlaygroundGP::PenguinPlaygroundGP() : Challenge("penguinplaygroundgp", _("Win Penguin Playground Grand\nPrix"))
|
||||
{
|
||||
setChallengeDescription(_("Win Penguin Playground Grand\nPrix with 3 'Racer' Level AI karts."));
|
||||
setFeatureDescription(_("New game mode\n'Follow Leader'\nnow available"));
|
||||
setFeature("followleader");
|
||||
addUnlockModeReward("followleader", _("Follow the Leader"));
|
||||
// The energymathclass challenge must be done, otherwise GP can't be selected
|
||||
addDependency("energymathclass");
|
||||
}
|
||||
|
@ -26,8 +26,7 @@
|
||||
RaceTrackTime::RaceTrackTime() : Challenge("racetracktime", _("Finish Race track in 1:15"))
|
||||
{
|
||||
setChallengeDescription(_("Finish 3 laps in the Race track\nwith 3 AI karts\nin under 1:15 minutes."));
|
||||
setFeatureDescription(_("New track: Amazonian Journey\nnow available"));
|
||||
setFeature("jungle");
|
||||
addUnlockTrackReward("jungle");
|
||||
} // RaceTrackTime
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
|
@ -25,9 +25,8 @@
|
||||
TollwayHead2Head::TollwayHead2Head() : Challenge("tollwayhead", _("Win a Head to Head on\nTux Tollway"))
|
||||
{
|
||||
setChallengeDescription(_("Win a 1 lap Head to Head\non Tux Tollway against 1 'Racer'\nlevel AI kart."));
|
||||
setFeatureDescription(_("New track: Fort Magma\nnow available"));
|
||||
setFeature("fortmagma");
|
||||
} // TollwayTime
|
||||
addUnlockTrackReward("fortmagma");
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
void TollwayHead2Head::setRace() const {
|
||||
|
@ -25,8 +25,7 @@
|
||||
TollwayTime::TollwayTime() : Challenge("tollwaytime", _("Finish Tux Tollway track in 3:00"))
|
||||
{
|
||||
setChallengeDescription(_("Finish 3 laps on the Tux Tollway\ntrack with 3 AI karts\nin under 3:00 minutes."));
|
||||
setFeatureDescription(_("New track: Canyon\nnow available"));
|
||||
setFeature("canyon");
|
||||
addUnlockTrackReward("canyon");
|
||||
} // TollwayTime
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
|
@ -25,9 +25,10 @@
|
||||
WorldsEndGP::WorldsEndGP() : Challenge("worldsendgp",_("Win the At World's End\nGrand Prix"))
|
||||
{
|
||||
setChallengeDescription(_("Come first in the At World's End\nGrand Prix with 3 'Racer'\nLevel AI karts."));
|
||||
setFeatureDescription(_("New Grand Prix: All Tracks GP\nand Bonus Preview: Skidding\nnow available.\nSelect 'skidding' as difficulty."));
|
||||
setFeature("All tracks");
|
||||
setFeature("skidding"); // Add Skidding Preview
|
||||
|
||||
addUnlockDifficultyReward("skidding","Skidding Preview");
|
||||
addUnlockGPReward("All tracks");
|
||||
|
||||
addDependency("islandfollow");
|
||||
addDependency("racetracktime");
|
||||
addDependency("tollwaytime");
|
||||
|
@ -41,7 +41,7 @@ FeatureUnlocked::FeatureUnlocked()
|
||||
unlock_manager->clearUnlocked();
|
||||
|
||||
widget_manager->addTextWgt( WTOK_DESCRIPTION, 60, 30,
|
||||
m_new_features[0]->getFeatureDescription());
|
||||
m_new_features[0]->getUnlockedMessage());
|
||||
|
||||
widget_manager->addTextButtonWgt(WTOK_CONTINUE, 50, 7,
|
||||
_("Continue"));
|
||||
@ -63,7 +63,7 @@ void FeatureUnlocked::select()
|
||||
m_new_features.erase(m_new_features.begin());
|
||||
if(m_new_features.size()>0)
|
||||
{
|
||||
widget_manager->setWgtText( WTOK_DESCRIPTION, m_new_features[0]->getFeature());
|
||||
widget_manager->setWgtText( WTOK_DESCRIPTION, m_new_features[0]->getUnlockedMessage() );
|
||||
}
|
||||
else
|
||||
{
|
||||
|
@ -116,14 +116,14 @@ void UnlockManager::computeActive()
|
||||
// The constructor calls computeActive, which actually locks
|
||||
// all features, so unlock the solved ones (and don't try to
|
||||
// save the state, since we are currently reading it)
|
||||
if (isLocked(i->second->getFeature()))
|
||||
unlockFeature(i->second, /*save*/ false);
|
||||
|
||||
unlockFeature(i->second, /*save*/ false);
|
||||
continue;
|
||||
}
|
||||
|
||||
// Otherwise lock the feature, and check if the challenge is active
|
||||
// ----------------------------------------------------------------
|
||||
lockFeature(i->second->getFeature());
|
||||
lockFeature(i->second);
|
||||
std::vector<std::string> pre_req=(i->second)->getPrerequisites();
|
||||
bool allSolved=true;
|
||||
for(std::vector<std::string>::iterator pre =pre_req.begin();
|
||||
@ -181,29 +181,36 @@ void UnlockManager::grandPrixFinished()
|
||||
} // grandPrixFinished
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
void UnlockManager::lockFeature(const std::string& feature)
|
||||
void UnlockManager::lockFeature(Challenge* challenge)
|
||||
{
|
||||
m_locked_features[feature]=true;
|
||||
const unsigned int amount = challenge->getFeatures().size();
|
||||
for(unsigned int n=0; n<amount; n++)
|
||||
m_locked_features[challenge->getFeatures()[n].name]=true;
|
||||
} // lockFeature
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
|
||||
void UnlockManager::unlockFeature(Challenge* c, bool save)
|
||||
{
|
||||
const std::string& feature=c->getFeature();
|
||||
std::map<std::string,bool>::iterator p=m_locked_features.find(feature);
|
||||
if(p==m_locked_features.end())
|
||||
const unsigned int amount = c->getFeatures().size();
|
||||
for(unsigned int n=0; n<amount; n++)
|
||||
{
|
||||
fprintf(stderr,"Unlocking feature '%s' failed: feature is not locked.\n",
|
||||
(feature).c_str());
|
||||
return;
|
||||
std::string feature = c->getFeatures()[n].name;
|
||||
std::map<std::string,bool>::iterator p=m_locked_features.find(feature);
|
||||
if(p==m_locked_features.end())
|
||||
{
|
||||
//fprintf(stderr,"Unlocking feature '%s' failed: feature is not locked.\n",
|
||||
// (feature).c_str());
|
||||
return;
|
||||
}
|
||||
m_locked_features.erase(p);
|
||||
}
|
||||
m_locked_features.erase(p);
|
||||
|
||||
|
||||
// Add to list of recently unlocked features
|
||||
m_unlocked_features.push_back(c);
|
||||
c->setSolved(); // reset isActive flag
|
||||
|
||||
// Save the new unlock informationxt
|
||||
|
||||
// Save the new unlock information
|
||||
if(save) user_config->saveConfig();
|
||||
} // unlockFeature
|
||||
|
||||
|
@ -49,7 +49,7 @@ public:
|
||||
void raceFinished ();
|
||||
void grandPrixFinished ();
|
||||
void unlockFeature (Challenge* c, bool save=true);
|
||||
void lockFeature (const std::string& feature);
|
||||
void lockFeature (Challenge* challenge);
|
||||
bool isLocked (const std::string& feature);
|
||||
}; // UnlockManager
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user