Can now unlock game modes too. Centralized a couple mode-related stuff to make code cleaner with new changes. Made challenges more robust, fixes a couple crashes that could happen because errors went undetected

git-svn-id: svn+ssh://svn.code.sf.net/p/supertuxkart/code/main/trunk@4929 178a84e3-b1eb-0310-8ba1-8eac791a3b58
This commit is contained in:
auria 2010-03-05 01:28:23 +00:00
parent cf7382700f
commit bdd985c88a
11 changed files with 73 additions and 33 deletions

View File

@ -82,7 +82,7 @@ void Challenge::addUnlockTrackReward(const std::string &track_name)
//-----------------------------------------------------------------------------
void Challenge::addUnlockModeReward(const std::string &internal_mode_name,
const irr::core::stringw &user_mode_name)
{
{
UnlockableFeature feature;
feature.name = internal_mode_name;
feature.type = UNLOCK_MODE;

View File

@ -142,6 +142,11 @@ ChallengeData::ChallengeData(const std::string& filename)
getUnlocks(root, "unlock-difficulty", UNLOCK_DIFFICULTY);
getUnlocks(root, "unlock-kart", UNLOCK_KART);
if (getFeatures().size() == 0)
{
error("missing unlocked features");
}
std::vector< std::string > deps;
root->get("depend-on", &deps);
for(unsigned int i=0; i<deps.size(); i++) addDependency(deps[i]);
@ -196,6 +201,7 @@ void ChallengeData::getUnlocks(const XMLNode *root, const std:: string type,
{
std:: string attrib;
root->get(type, &attrib);
if (attrib . empty()) return;
//std:: vector< std:: string > data;
@ -214,7 +220,9 @@ void ChallengeData::getUnlocks(const XMLNode *root, const std:: string type,
case UNLOCK_GP: addUnlockGPReward (attrib );
break;
case UNLOCK_MODE: addUnlockModeReward (attrib, RaceManager::getNameOf(attrib.c_str()));
case UNLOCK_MODE: const RaceManager::MinorRaceModeType mode =
RaceManager::getModeIDFromInternalName(attrib.c_str());
addUnlockModeReward (attrib, RaceManager::getNameOf(mode));
break;
case UNLOCK_DIFFICULTY:

View File

@ -42,7 +42,7 @@ private:
std::string m_track_name;
int m_energy;
std::vector<std::string> m_depends_on;
std::vector<UnlockableFeature> m_unlock;
//std::vector<UnlockableFeature> m_unlock;
std::string m_filename;
void getUnlocks(const XMLNode *root, const std:: string type, REWARD_TYPE reward);

View File

@ -357,7 +357,7 @@ const std::string& DynamicRibbonWidget::getSelectionIDString(const int playerID)
{
RibbonWidget* row = (RibbonWidget*)(m_rows.size() == 1 ? m_rows.get(0) : getSelectedRibbon(playerID));
if(row != NULL) return row->getSelectionIDString(playerID);
if (row != NULL) return row->getSelectionIDString(playerID);
static const std::string nothing = "";
return nothing;

View File

@ -378,6 +378,8 @@ const std::string& RibbonWidget::getSelectionIDString(const int playerID)
{
static std::string empty;
if (m_selection[playerID] == -1) return empty;
if (m_children.size() == 0) return empty;
return m_children[m_selection[playerID]].m_properties[PROP_ID];
}

View File

@ -32,6 +32,12 @@ class Kart;
class Kart;
class Track;
static const char* IDENT_STD = "STANDARD";
static const char* IDENT_TTRIAL = "STD_TIMETRIAL";
static const char* FTL_IDENT = "FOLLOW_LEADER";
static const char* STRIKES_IDENT = "BATTLE_3_STRIKES";
/** The race manager has two functions:
* 1) it stores information about the race the user selected (e.g. number
* of karts, track, race mode etc.). Most of the values are just stored
@ -82,18 +88,14 @@ public:
*/
enum MinorRaceModeType
{
MINOR_MODE_NONE = -1,
MINOR_MODE_NORMAL_RACE = LINEAR_RACE(0, true),
MINOR_MODE_TIME_TRIAL = LINEAR_RACE(1, true),
MINOR_MODE_FOLLOW_LEADER = LINEAR_RACE(2, false),
MINOR_MODE_3_STRIKES = BATTLE_ARENA(0)
};
// Stupid C++ doesn't accept string constants
#define IDENT_STD "STANDARD"
#define IDENT_TTRIAL "STD_TIMETRIAL"
#define FTL_IDENT "FOLLOW_LEADER"
#define STRIKES_IDENT "BATTLE_3_STRIKES"
static const char* getIdentOf(const MinorRaceModeType mode)
{
@ -106,6 +108,18 @@ public:
default: assert(false); return NULL;
}
}
static const char* getIconOf(const MinorRaceModeType mode)
{
switch (mode)
{
case MINOR_MODE_NORMAL_RACE: return "/gui/mode_normal.png";
case MINOR_MODE_TIME_TRIAL: return "/gui/mode_tt.png";
case MINOR_MODE_FOLLOW_LEADER: return "/gui/mode_ftl.png";
case MINOR_MODE_3_STRIKES: return "/gui/mode_3strikes.png";
default: assert(false); return NULL;
}
}
static const wchar_t* getNameOf(const MinorRaceModeType mode)
{
switch (mode)
@ -121,15 +135,16 @@ public:
default: assert(false); return NULL;
}
}
static const wchar_t* getNameOf(const char* name)
static const MinorRaceModeType getModeIDFromInternalName(const char* name)
{
if (strcmp(name, IDENT_STD) == 0) return getNameOf(MINOR_MODE_NORMAL_RACE);
else if (strcmp(name, IDENT_TTRIAL) == 0) return getNameOf(MINOR_MODE_TIME_TRIAL);
else if (strcmp(name, FTL_IDENT) == 0) return getNameOf(MINOR_MODE_FOLLOW_LEADER);
else if (strcmp(name, STRIKES_IDENT) == 0) return getNameOf(MINOR_MODE_3_STRIKES);
if (strcmp(name, IDENT_STD) == 0) return MINOR_MODE_NORMAL_RACE;
else if (strcmp(name, IDENT_TTRIAL) == 0) return MINOR_MODE_TIME_TRIAL;
else if (strcmp(name, FTL_IDENT) == 0) return MINOR_MODE_FOLLOW_LEADER;
else if (strcmp(name, STRIKES_IDENT) == 0) return MINOR_MODE_3_STRIKES;
assert(0);
return NULL;
return MINOR_MODE_NONE;
}
#undef LINEAR_RACE

View File

@ -110,7 +110,7 @@ namespace GUIEngine
{
unlock_manager->playLockSound();
}
else
else if (!selection.empty())
{
//FIXME: simplify and centralize race start sequence!!

View File

@ -405,7 +405,7 @@ GUIEngine::EventPropagation RaceOverDialog::processEvent(const std::string& even
Track* track = track_manager->getTrack(unlockedFeatures[i].name);
assert(track != NULL);
const std::string sshot = track->getScreenshotFile();
scene->addUnlockedPicture( irr_driver->getTexture(sshot.c_str()),
scene->addUnlockedPicture( irr_driver->getTexture(sshot.c_str()), 1.0f, 0.75f,
unlockedFeatures[i].getUnlockedMessage() );
break;
}
@ -416,7 +416,11 @@ GUIEngine::EventPropagation RaceOverDialog::processEvent(const std::string& even
}
case UNLOCK_MODE:
{
//TODO
const RaceManager::MinorRaceModeType mode =
RaceManager::getModeIDFromInternalName(unlockedFeatures[i].name.c_str());
const std::string icon = file_manager->getDataDir() + "/" + RaceManager::getIconOf(mode);
scene->addUnlockedPicture( irr_driver->getTexture(icon.c_str()), 0.8f, 0.8f,
unlockedFeatures[i].getUnlockedMessage() );
break;
}
case UNLOCK_KART:

View File

@ -35,11 +35,12 @@ void FeatureUnlockedCutScene::addUnlockedKart(KartProperties* unlocked_kart, irr
// -------------------------------------------------------------------------------------
void FeatureUnlockedCutScene::addUnlockedPicture(irr::video::ITexture* picture, irr::core::stringw msg)
void FeatureUnlockedCutScene::addUnlockedPicture(irr::video::ITexture* picture,
float w, float h, irr::core::stringw msg)
{
assert(picture != NULL);
m_unlocked_stuff.push_back( new UnlockedThing(picture, msg) );
m_unlocked_stuff.push_back( new UnlockedThing(picture, w, h, msg) );
}
// -------------------------------------------------------------------------------------
@ -105,13 +106,14 @@ void FeatureUnlockedCutScene::init()
else if (m_unlocked_stuff[n].m_picture != NULL)
{
video::SMaterial m;
m.MaterialType = video::EMT_TRANSPARENT_ALPHA_CHANNEL;
m.BackfaceCulling = false;
m.setTexture(0, m_unlocked_stuff[n].m_picture);
m.AmbientColor = SColor(255,255,255,255);
m.DiffuseColor = SColor(255,255,255,255);
m.SpecularColor = SColor(0,0,0,0);
m.AmbientColor = SColor(255,255,255,255);
m.DiffuseColor = SColor(255,255,255,255);
m.SpecularColor = SColor(0,0,0,0);
m.GouraudShading = false;
m.Shininess = 0;
m.Shininess = 0;
//m.setFlag(video::EMF_TEXTURE_WRAP, false);
#if (IRRLICHT_VERSION_MAJOR == 1) && (IRRLICHT_VERSION_MINOR >= 7)
@ -121,7 +123,9 @@ void FeatureUnlockedCutScene::init()
m.TextureLayer[0].TextureWrap = video::ETC_CLAMP_TO_EDGE;
#endif
scene::IMesh* mesh = irr_driver->createTexturedQuadMesh(&m, 1.0, 0.75);
scene::IMesh* mesh = irr_driver->createTexturedQuadMesh(&m,
m_unlocked_stuff[n].m_w,
m_unlocked_stuff[n].m_h);
m_unlocked_stuff[n].m_root_gift_node = irr_driver->addMesh(mesh);
}

View File

@ -17,8 +17,13 @@ class FeatureUnlockedCutScene : public GUIEngine::Screen, public GUIEngine::Scre
/** Whichever of these is non-null decides what comes out of the chest */
struct UnlockedThing
{
/** Will be non-null if this unlocked thing is a kart */
KartProperties* m_unlocked_kart;
/** Will be non-null if this unlocked thing is a picture */
irr::video::ITexture* m_picture;
/** Will be set if this unlocked thing is a picture */
float m_w, m_h;
/** Contains whatever is in the chest */
scene::ISceneNode* m_root_gift_node;
@ -31,10 +36,12 @@ class FeatureUnlockedCutScene : public GUIEngine::Screen, public GUIEngine::Scre
m_picture = NULL;
m_unlock_message = msg;
}
UnlockedThing(irr::video::ITexture* pict, irr::core::stringw msg)
UnlockedThing(irr::video::ITexture* pict, float w, float h, irr::core::stringw msg)
{
m_unlocked_kart = NULL;
m_picture = pict;
m_w = w;
m_h = h;
m_unlock_message = msg;
}
~UnlockedThing()
@ -80,7 +87,7 @@ public:
void addUnlockedKart(KartProperties* unlocked_kart, irr::core::stringw msg);
/** Call before showing up the screen to make a picture come out of the chest */
void addUnlockedPicture(irr::video::ITexture* picture, irr::core::stringw msg);
void addUnlockedPicture(irr::video::ITexture* picture, float w, float h, irr::core::stringw msg);
/** override from base class to handle escape press */
virtual bool onEscapePressed();

View File

@ -170,18 +170,18 @@ void RaceSetupScreen::init()
//FIXME: avoid duplicating descriptions from the help menu!
name1 += _("All blows allowed, so catch weapons and make clever use of them!");
w2->addItem( name1, "normal", "/gui/mode_normal.png");
w2->addItem( name1, "normal", RaceManager::getIconOf(RaceManager::MINOR_MODE_NORMAL_RACE));
irr::core::stringw name2 = irr::core::stringw(
RaceManager::getNameOf(RaceManager::MINOR_MODE_TIME_TRIAL)) + L"\n";
//FIXME: avoid duplicating descriptions from the help menu!
name2 += _("Contains no powerups, so only your driving skills matter!");
w2->addItem( name2, "timetrial", "/gui/mode_tt.png");
w2->addItem( name2, "timetrial", RaceManager::getIconOf(RaceManager::MINOR_MODE_TIME_TRIAL));
if (unlock_manager->isLocked("followtheleader"))
{
w2->addItem( _("Locked : solve active challenges to gain access to more!"),
"locked", "/gui/mode_ftl.png", true);
"locked", RaceManager::getIconOf(RaceManager::MINOR_MODE_FOLLOW_LEADER), true);
}
else
{
@ -189,7 +189,7 @@ void RaceSetupScreen::init()
RaceManager::getNameOf(RaceManager::MINOR_MODE_FOLLOW_LEADER)) + L"\n";
//FIXME: avoid duplicating descriptions from the help menu!
name3 += _("Run for second place, as the last kart will be disqualified every time the counter hits zero. Beware : going in front of the leader will get you eliminated too!");
w2->addItem(name3, "ftl", "/gui/mode_ftl.png", false);
w2->addItem(name3, "ftl", RaceManager::getIconOf(RaceManager::MINOR_MODE_FOLLOW_LEADER), false);
}
if (race_manager->getNumPlayers() > 1)
@ -198,7 +198,7 @@ void RaceSetupScreen::init()
RaceManager::getNameOf(RaceManager::MINOR_MODE_3_STRIKES)) + L"\n";
//FIXME: avoid duplicating descriptions from the help menu!
name4 += _("Hit others with weapons until they lose all their lives. (Only in multiplayer games)");
w2->addItem( name4, "3strikes", "/gui/mode_3strikes.png");
w2->addItem( name4, "3strikes", RaceManager::getIconOf(RaceManager::MINOR_MODE_3_STRIKES));
}