Adding a way to mark decks as "locked" based on options requirements (option on or off). Can be used for example to lock a deck until a specific set is not unlocked. Works for both player decks (could be used for premade?) and AI decks.

This commit is contained in:
wagic.the.homebrew
2011-05-06 06:40:00 +00:00
parent efad3f652f
commit 7beb958067
5 changed files with 57 additions and 21 deletions
+2
View File
@@ -20,6 +20,7 @@ private:
string mFilename; string mFilename;
string mDescription; string mDescription;
string mName; string mName;
vector<int> mUnlockRequirements;
int mDeckId; int mDeckId;
string mAvatarFilename; string mAvatarFilename;
string mColorIndex; string mColorIndex;
@@ -44,6 +45,7 @@ public:
string getAvatarFilename(); string getAvatarFilename();
string getColorIndex(); string getColorIndex();
string getStatsSummary(); string getStatsSummary();
vector<int> getUnlockRequirements();
int getDeckId(); int getDeckId();
int getGamesPlayed(); int getGamesPlayed();
+1
View File
@@ -157,6 +157,7 @@ public:
string meta_desc; string meta_desc;
string meta_name; string meta_name;
vector<string> meta_AIHints; vector<string> meta_AIHints;
string meta_unlockRequirements;
int meta_id; int meta_id;
int totalCards(); int totalCards();
+13
View File
@@ -30,6 +30,13 @@ void DeckMetaData::LoadDeck()
mName = trim(deck.meta_name); mName = trim(deck.meta_name);
mDescription = trim(deck.meta_desc); mDescription = trim(deck.meta_desc);
mDeckId = atoi((mFilename.substr(mFilename.find("deck") + 4, mFilename.find(".txt"))).c_str()); mDeckId = atoi((mFilename.substr(mFilename.find("deck") + 4, mFilename.find(".txt"))).c_str());
vector<string> requirements = split(deck.meta_unlockRequirements, ',');
for(size_t i = 0; i < requirements.size(); ++i)
{
mUnlockRequirements.push_back(Options::getID(requirements[i]));
}
mDeckLoaded = true; mDeckLoaded = true;
if (!mIsAI) if (!mIsAI)
mAvatarFilename = "avatar.jpg"; mAvatarFilename = "avatar.jpg";
@@ -115,6 +122,12 @@ int DeckMetaData::getDeckId()
return mDeckId; return mDeckId;
} }
vector<int> DeckMetaData::getUnlockRequirements()
{
return mUnlockRequirements;
}
string DeckMetaData::getAvatarFilename() string DeckMetaData::getAvatarFilename()
{ {
return mAvatarFilename; return mAvatarFilename;
+15
View File
@@ -50,6 +50,20 @@ vector<DeckMetaData *> GameState::BuildDeckList(const string& path, const string
DeckMetaData * meta = deckManager->getDeckMetaDataByFilename(filename.str(), isAI); DeckMetaData * meta = deckManager->getDeckMetaDataByFilename(filename.str(), isAI);
if (meta) if (meta)
{
//Check if the deck is unlocked based on sets etc...
bool unlocked = true;
vector<int> unlockRequirements = meta->getUnlockRequirements();
for (size_t i = 0; i < unlockRequirements.size(); ++i)
{
if (! options[unlockRequirements[i]].number)
{
unlocked = false;
break;
}
}
if (unlocked)
{ {
found = 1; found = 1;
if (statsPlayer) if (statsPlayer)
@@ -75,6 +89,7 @@ vector<DeckMetaData *> GameState::BuildDeckList(const string& path, const string
retList.push_back(meta); retList.push_back(meta);
nbDecks++; nbDecks++;
} }
}
meta = NULL; meta = NULL;
} }
+6 -1
View File
@@ -698,7 +698,6 @@ MTGDeck::MTGDeck(const char * config_file, MTGAllCards * _allcards, int meta_onl
meta_id = atoi(meta_name.substr(4).c_str()); meta_id = atoi(meta_name.substr(4).c_str());
wagic::ifstream file(config_file); wagic::ifstream file(config_file);
std::string s; std::string s;
if (file) if (file)
{ {
while (std::getline(file, s)) while (std::getline(file, s))
@@ -726,6 +725,12 @@ MTGDeck::MTGDeck(const char * config_file, MTGAllCards * _allcards, int meta_onl
meta_AIHints.push_back(s.substr(found + 5)); meta_AIHints.push_back(s.substr(found + 5));
continue; continue;
} }
found = s.find("UNLOCK:");
if (found != string::npos)
{
meta_unlockRequirements = s.substr(found + 7);
continue;
}
continue; continue;
} }
if (meta_only) break; if (meta_only) break;