diff --git a/projects/mtg/include/GameStateDeckViewer.h b/projects/mtg/include/GameStateDeckViewer.h index 2029eb64a..645e84acf 100644 --- a/projects/mtg/include/GameStateDeckViewer.h +++ b/projects/mtg/include/GameStateDeckViewer.h @@ -63,6 +63,7 @@ struct StatsWrapper { float avgCreatureCost; int totalSpellCost; float avgSpellCost; + int countManaProducers; int countCreatures, countSpells, countInstants, countEnchantments, countSorceries, countArtifacts; @@ -75,6 +76,9 @@ struct StatsWrapper { int countCreaturesPerCostAndColor[STATS_MAX_MANA_COST+1][Constants::MTG_NB_COLORS+1]; int countSpellsPerCost[STATS_MAX_MANA_COST+1]; int countSpellsPerCostAndColor[STATS_MAX_MANA_COST+1][Constants::MTG_NB_COLORS+1]; + int countLandsPerColor[Constants::MTG_NB_COLORS+1]; + int countBasicLandsPerColor[Constants::MTG_NB_COLORS+1]; + int countNonLandProducersPerColor[Constants::MTG_NB_COLORS+1]; int totalCostPerColor[Constants::MTG_NB_COLORS+1]; int totalColoredSymbols; diff --git a/projects/mtg/include/MTGAbility.h b/projects/mtg/include/MTGAbility.h index 91cf91717..e372e16e4 100644 --- a/projects/mtg/include/MTGAbility.h +++ b/projects/mtg/include/MTGAbility.h @@ -202,8 +202,8 @@ class AbilityFactory{ int countCards(TargetChooser * tc, Player * player = NULL, int option = 0); int parsePowerToughness(string s, int *power, int *toughness); TriggeredAbility * parseTrigger(string s, int id, Spell * spell, MTGCardInstance *card, Targetable * target); - MTGAbility * parseMagicLine(string s, int id, Spell * spell, MTGCardInstance *card, int activated = 0, int forceUEOT = 0); public: + MTGAbility * parseMagicLine(string s, int id, Spell * spell, MTGCardInstance *card, int activated = 0, int forceUEOT = 0); int abilityEfficiency(MTGAbility * a, Player * p, int mode = MODE_ABILITY); int magicText(int id, Spell * spell, MTGCardInstance * card = NULL, int mode = MODE_PUTINTOPLAY); static int computeX(Spell * spell, MTGCardInstance * card); diff --git a/projects/mtg/src/GameStateDeckViewer.cpp b/projects/mtg/src/GameStateDeckViewer.cpp index 94e1eac5d..b19494810 100644 --- a/projects/mtg/src/GameStateDeckViewer.cpp +++ b/projects/mtg/src/GameStateDeckViewer.cpp @@ -6,8 +6,28 @@ #include "../include/GameStateDeckViewer.h" #include "../include/Translate.h" #include "../include/ManaCostHybrid.h" +#include "../include/MTGCardInstance.h" +#include "../include/MTGCardInstance.h" #include + +//!! helper function; this is probably handled somewhere in the code already. +// If not, should be placed in general library +void StringExplode(string str, string separator, vector* results){ + int found; + found = str.find_first_of(separator); + while(found != (int)string::npos){ + if(found > 0){ + results->push_back(str.substr(0,found)); + } + str = str.substr(found+1); + found = str.find_first_of(separator); + } + if(str.length() > 0){ + results->push_back(str); + } +} + GameStateDeckViewer::GameStateDeckViewer(GameApp* parent): GameState(parent) { bgMusic = NULL; scrollSpeed = MED_SPEED; @@ -690,7 +710,103 @@ void GameStateDeckViewer::renderOnScreenMenu(){ r->DrawLine(20 + leftTransition, posY + 13, posX + 40 + leftTransition, posY + 13, ARGB(128, 255, 255, 255)); break; + + case 5: // Land statistics + sprintf(buffer, STATS_TITLE_FORMAT.c_str(), stw.currentPage, _("Mana production").c_str()); + font->DrawString(buffer, 10+leftTransition, 10); + + font->DrawString(_("Counts of manasources per type and color:"), 20 + leftTransition, 30); + + posY = 70; + // Column titles + for (int j=0; jRenderQuad(mIcons[j], 52 + j*15 + leftTransition, posY - 10,0,0.5,0.5); + } + + //font->DrawString(_("C"), 30 + leftTransition, posY-16); + //font->DrawString(_("Ty"), 27 + leftTransition, posY-16); + + // Horizontal table lines + r->DrawLine(27 + leftTransition, posY - 20, 60 + (Constants::MTG_NB_COLORS-2)*15 + leftTransition, posY - 20, ARGB(128, 255, 255, 255)); + r->DrawLine(27 + leftTransition, posY - 1, 60 + (Constants::MTG_NB_COLORS-2)*15 + leftTransition, posY - 1, ARGB(128, 255, 255, 255)); + r->DrawLine(27 + leftTransition, 2*10 + posY + 12, 60 + (Constants::MTG_NB_COLORS-2)*15 + leftTransition, 2*10 + posY + 12, ARGB(128, 255, 255, 255)); + r->DrawLine(27 + leftTransition, 3*10 + posY + 14, 60 + (Constants::MTG_NB_COLORS-2)*15 + leftTransition, 3*10 + posY + 14, ARGB(128, 255, 255, 255)); + + // Vertical table lines + r->DrawLine(26 + leftTransition, posY - 20, 26 + leftTransition, 3*10 + posY + 14, ARGB(128, 255, 255, 255)); + r->DrawLine(43 + leftTransition, posY - 20, 43 + leftTransition, 3*10 + posY + 14, ARGB(128, 255, 255, 255)); + r->DrawLine(60 + leftTransition + (Constants::MTG_NB_COLORS-2)*15, posY - 20, 60 + leftTransition + (Constants::MTG_NB_COLORS-2)*15, 3*10 + posY + 14, ARGB(128, 255, 255, 255)); + + font->DrawString(_("BL"), 27 + leftTransition, posY); + font->DrawString(_("NB"), 27 + leftTransition, posY+10); + font->DrawString(_("O"), 30 + leftTransition, posY+20); + font->DrawString(_("T"), 30 + leftTransition, posY+33); + + int curCount; + + for (int j=0; jDrawString(buffer, 49 + leftTransition + j*15, posY); + + curCount = stw.countLandsPerColor[j]; + sprintf(buffer, (curCount==0?".":"%i"), curCount); + font->DrawString(buffer, 49 + leftTransition + j*15, posY+10); + + curCount = stw.countNonLandProducersPerColor[j]; + sprintf(buffer, (curCount==0?".":"%i"), curCount); + font->DrawString(buffer, 49 + leftTransition + j*15, posY+20); + + curCount = stw.countLandsPerColor[j] + stw.countBasicLandsPerColor[j] + stw.countNonLandProducersPerColor[j]; + sprintf(buffer, (curCount==0?".":"%i"), curCount); + font->DrawString(buffer, 49 + leftTransition + j*15, posY+33); + } + + posY += 55; + font->DrawString(_("BL - Basic lands"), 20 + leftTransition, posY); + posY += 10; + font->DrawString(_("NB - Non-basic lands"), 20 + leftTransition, posY); + posY += 10; + font->DrawString(_("O - Other (non-land) manasources"), 26 + leftTransition, posY); + posY += 10; + font->DrawString(_("T - Totals"), 26 + leftTransition, posY); + + break; + + case 6: // Land statistics - in symbols + sprintf(buffer, STATS_TITLE_FORMAT.c_str(), stw.currentPage, _("Mana production - in mana symbols").c_str()); + font->DrawString(buffer, 10+leftTransition, 10); + font->DrawString(_("Total colored manasymbols in lands' production:"), 20 + leftTransition, 30); + + int totalProducedSymbols; + totalProducedSymbols = 0; + for (int i=1; i0) { + sprintf(buffer, _("%i").c_str(), stw.countLandsPerColor[i] + stw.countBasicLandsPerColor[i]); + font->DrawString(buffer, 20 + leftTransition, posY); + sprintf(buffer, _("(%i%%)").c_str(), (int)(100*(float)(stw.countLandsPerColor[i] + stw.countBasicLandsPerColor[i])/totalProducedSymbols)); + font->DrawString(buffer, 33 + leftTransition, posY); + posX = 72; + for (int j=0; jRenderQuad(mIcons[i], posX + leftTransition, posY+6, 0, 0.5, 0.5); + posX += ((j+1)%10==0)?17:13; + if ((((j+1)%30)==0) && (jRenderQuad(mIcons[j], 67 + j*15 + leftTransition, posY - 11,0,0.5,0.5); + r->RenderQuad(mIcons[j], 67 + j*15 + leftTransition, posY - 10,0,0.5,0.5); } font->DrawString(_("C"), 30 + leftTransition, posY-16); @@ -760,7 +876,7 @@ void GameStateDeckViewer::renderOnScreenMenu(){ sprintf(buffer, _("%i").c_str(), (*countPerCost)[i]); font->DrawString(buffer, 45 + leftTransition, posY); for (int j=0; j0)?_("%i").c_str():" ", (*countPerCostAndColor)[i][j]); + sprintf(buffer, ((*countPerCostAndColor)[i][j]>0)?_("%i").c_str():".", (*countPerCostAndColor)[i][j]); font->DrawString(buffer, 64 + leftTransition + j*15, posY); } r->FillRect(77 + leftTransition + (Constants::MTG_NB_COLORS-2)*15, posY + 2, (*countPerCost)[i]*5, 8, graphColor); @@ -778,7 +894,7 @@ void GameStateDeckViewer::renderOnScreenMenu(){ break; - case 6: + case 8: // Title sprintf(buffer, STATS_TITLE_FORMAT.c_str(), stw.currentPage, _("Probabilities").c_str()); font->DrawString(buffer, 10+leftTransition, 10); @@ -816,7 +932,7 @@ void GameStateDeckViewer::renderOnScreenMenu(){ break; - case 5: // Total mana cost per color + case 7: // Total mana cost per color // Title sprintf(buffer, STATS_TITLE_FORMAT.c_str(), stw.currentPage, _("Mana cost per color").c_str()); font->DrawString(buffer, 10+leftTransition, 10); @@ -830,12 +946,12 @@ void GameStateDeckViewer::renderOnScreenMenu(){ font->DrawString(buffer, 20 + leftTransition, posY); sprintf(buffer, _("(%i%%)").c_str(), (int)(100*(float)stw.totalCostPerColor[i]/stw.totalColoredSymbols)); font->DrawString(buffer, 33 + leftTransition, posY); - posX = 70; + posX = 72; for (int j=0; jRenderQuad(mIcons[i], posX + leftTransition, posY+6, 0, 0.5, 0.5); posX += ((j+1)%10==0)?17:13; if ((((j+1)%30)==0) && (jDrawString(buffer, 10+leftTransition, 10); @@ -882,12 +998,18 @@ void GameStateDeckViewer::updateStats() { if (!stw.needUpdate) { return; } + + AbilityFactory * af; + af = NEW AbilityFactory(); + stw.needUpdate = false; stw.cardCount = myDeck->getCount(); stw.countLands = myDeck->getCount(Constants::MTG_COLOR_LAND); stw.totalPrice = myDeck->totalPrice(); + stw.countManaProducers = 0; + stw.countManaProducers = 0; // Mana cost int currentCount, convertedCost; ManaCost * currentCost; @@ -905,6 +1027,9 @@ void GameStateDeckViewer::updateStats() { for (int i=0; i<=Constants::MTG_NB_COLORS; i++) { stw.totalCostPerColor[i] = 0; + stw.countLandsPerColor[i] = 0; + stw.countBasicLandsPerColor[i] = 0; + stw.countNonLandProducersPerColor[i] = 0; } for (int i=0; i<=STATS_MAX_MANA_COST; i++) { @@ -932,8 +1057,53 @@ void GameStateDeckViewer::updateStats() { } else if (current->isSpell()) { stw.countSpellsPerCost[convertedCost] += currentCount; stw.totalSpellCost += convertedCost * currentCount; - } + } + //if (current->isLand()) { + // Lets look for mana producing abilities + MTGCardInstance * cin; + MTGAbility * ab = NULL; + int found; + + // TODO: Creating card instance for the sole purpose of getting the card abilities is dirty. Do something about it. + cin = new MTGCardInstance(current, NULL); + + vector abilityStrings; + string thisstring = current->magicText; + StringExplode(thisstring, "\n", &abilityStrings); + + /*char buf[4096]; + sprintf(buf, "Card: %s Ability count:%i Iterating....", (current->name).c_str(),(int)abilityStrings.size()); + OutputDebugString(buf);*/ + + for (int i=0; i<(int)abilityStrings.size(); i++) { + found = abilityStrings.at(i).find("add"); + if (found != (int)string::npos){ //Parse only mana abilities + ab = af->parseMagicLine(abilityStrings.at(i),0,0,cin); + AManaProducer * amp = dynamic_cast(ab); + + if (amp){ + //OutputDebugString("M "); + for (int j=0; joutput->hasColor(j)) { + if (current->isLand()) { + if (current->hasType("Basic")) { + stw.countBasicLandsPerColor[j] += currentCount; + } else { + stw.countLandsPerColor[j] += currentCount; + } + } else { + stw.countNonLandProducersPerColor[j] += currentCount; + } + } + } + } + SAFE_DELETE(ab); + } + } + SAFE_DELETE(cin); + //OutputDebugString("...Done\n"); + //} // Add to the per color counters // a. regular costs for (int j=0; j