diff --git a/projects/mtg/include/Tasks.h b/projects/mtg/include/Tasks.h index be58b599d..c25b142d9 100644 --- a/projects/mtg/include/Tasks.h +++ b/projects/mtg/include/Tasks.h @@ -43,8 +43,8 @@ protected: public: // variable to store and method to obtain names of AI decks //!! Todo: This should _really_ be handled elsewhere (dedicated class?) - static vector AIDeckNames; - static void loadAIDeckNames(); + static vector sAIDeckNames; + static void LoadAIDeckNames(); static int getAIDeckCount(); static string getAIDeckName(int id); // End of AI deck buffering code diff --git a/projects/mtg/src/Tasks.cpp b/projects/mtg/src/Tasks.cpp index ab01caae7..dd1707620 100644 --- a/projects/mtg/src/Tasks.cpp +++ b/projects/mtg/src/Tasks.cpp @@ -9,7 +9,7 @@ #include #include -vector Task::AIDeckNames; +vector Task::sAIDeckNames; /*---------------- Utils -----------------*/ // TODO: Move to dedicated file @@ -187,42 +187,40 @@ void Task::passOneDay() // AI deck buffering code -void Task::loadAIDeckNames() +void Task::LoadAIDeckNames() { - //check if cache is up to date - if (AIDeckNames.size() == (unsigned int)(options[Options::AIDECKS_UNLOCKED].number)) return; - - AIDeckNames.clear(); - int found = 1; - int nbDecks = 0; - while (found && nbDecks < options[Options::AIDECKS_UNLOCKED].number) + if (sAIDeckNames.empty()) { - found = 0; - char buffer[512]; - sprintf(buffer, "%s/deck%i.txt", JGE_GET_RES("ai/baka").c_str(), nbDecks + 1); - - if (fileExists(buffer)) + int found = 1; + int nbDecks = 0; + while (found) { - found = 1; - nbDecks++; - // TODO: Creating MTGDeck only for getting decks name. Find an easier way. - MTGDeck * mtgd = NEW MTGDeck(buffer, NULL, 1); - AIDeckNames.push_back(mtgd->meta_name); - delete mtgd; + found = 0; + std::ostringstream stream; + stream << JGE_GET_RES("ai/baka") << "/deck" << nbDecks + 1 << ".txt"; + if (fileExists(stream.str().c_str())) + { + found = 1; + nbDecks++; + // TODO: Creating MTGDeck only for getting decks name. Find an easier way. + MTGDeck * mtgd = NEW MTGDeck(stream.str().c_str(), NULL, 1); + sAIDeckNames.push_back(mtgd->meta_name); + delete mtgd; + } } } } int Task::getAIDeckCount() { - loadAIDeckNames(); - return AIDeckNames.size(); + LoadAIDeckNames(); + return min((size_t) options[Options::AIDECKS_UNLOCKED].number, sAIDeckNames.size()); } string Task::getAIDeckName(int id) { - loadAIDeckNames(); - return ((unsigned int) id <= AIDeckNames.size()) ? AIDeckNames.at(id - 1) : ""; + LoadAIDeckNames(); + return ((unsigned int) id <= sAIDeckNames.size()) ? sAIDeckNames.at(id - 1) : ""; } // End of AI deck buffering code diff --git a/projects/mtg/template.vcxproj b/projects/mtg/template.vcxproj index 768ad8ab2..af8fd2675 100644 --- a/projects/mtg/template.vcxproj +++ b/projects/mtg/template.vcxproj @@ -426,6 +426,7 @@ + diff --git a/projects/mtg/template.vcxproj.filters b/projects/mtg/template.vcxproj.filters index 4dc205c89..61fc273ae 100644 --- a/projects/mtg/template.vcxproj.filters +++ b/projects/mtg/template.vcxproj.filters @@ -614,6 +614,9 @@ + + My Amplifier Results + @@ -622,5 +625,8 @@ {92d0309c-53b0-48a4-8b4d-07af74f87f0c} + + {0d64b46c-731f-4756-af96-7f2e050e91d2} + \ No newline at end of file