diff --git a/projects/mtg/include/DeckEditorMenu.h b/projects/mtg/include/DeckEditorMenu.h index fc7d8d4d3..34f3fdef2 100644 --- a/projects/mtg/include/DeckEditorMenu.h +++ b/projects/mtg/include/DeckEditorMenu.h @@ -1,11 +1,22 @@ #pragma once #include "DeckMenu.h" +#include "DeckDataWrapper.h" +#include "DeckStats.h" class DeckEditorMenu : public DeckMenu { +protected: + string deckTitle; + +private: + void drawDeckStatistics(); + + DeckDataWrapper *selectedDeck; + StatsWrapper *stw; + public: - DeckEditorMenu(int id, JGuiListener* listener = NULL, int fontId = 1, const char * _title = ""); + DeckEditorMenu(int id, JGuiListener* listener = NULL, int fontId = 1, const char * _title = "", DeckDataWrapper *selectedDeck = NULL, StatsWrapper *stats = NULL); void Render(); ~DeckEditorMenu(); }; diff --git a/projects/mtg/include/DeckStats.h b/projects/mtg/include/DeckStats.h index 9ff50f0e9..efa577f9b 100644 --- a/projects/mtg/include/DeckStats.h +++ b/projects/mtg/include/DeckStats.h @@ -4,6 +4,8 @@ #include #include +#include +#include "MTGDefinitions.h" using namespace std; class Player; @@ -36,4 +38,52 @@ public: int nbGames(); }; + +class StatsWrapper { + +public: + + StatsWrapper( int deckId ); + ~StatsWrapper(); + + // Stats parameters and status + int currentPage; + int pageCount; + bool needUpdate; + + // Actual stats + int percentVictories; + int gamesPlayed; + int cardCount; + int countLands; + int totalPrice; + int totalManaCost; + float avgManaCost; + int totalCreatureCost; + float avgCreatureCost; + int totalSpellCost; + float avgSpellCost; + int countManaProducers; + + int countCreatures, countSpells, countInstants, countEnchantments, countSorceries, countArtifacts; + + float noLandsProbInTurn[Constants::STATS_FOR_TURNS]; + float noCreaturesProbInTurn[Constants::STATS_FOR_TURNS]; + + int countCardsPerCost[Constants::STATS_MAX_MANA_COST+1]; + int countCardsPerCostAndColor[Constants::STATS_MAX_MANA_COST+1][Constants::MTG_NB_COLORS+1]; + int countCreaturesPerCost[Constants::STATS_MAX_MANA_COST+1]; + int countCreaturesPerCostAndColor[Constants::STATS_MAX_MANA_COST+1][Constants::MTG_NB_COLORS+1]; + int countSpellsPerCost[Constants::STATS_MAX_MANA_COST+1]; + int countSpellsPerCostAndColor[Constants::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; + + vector aiDeckNames; + vector aiDeckStats; +}; + #endif diff --git a/projects/mtg/include/GameStateDeckViewer.h b/projects/mtg/include/GameStateDeckViewer.h index 21e2eec8a..dc738e848 100644 --- a/projects/mtg/include/GameStateDeckViewer.h +++ b/projects/mtg/include/GameStateDeckViewer.h @@ -78,51 +78,6 @@ enum DECK_VIEWER_MENU_ITEMS #define MAX_SAVED_FILTERS 8 -static const int STATS_FOR_TURNS = 8; -static const int STATS_MAX_MANA_COST = 9; - -// Struct to hold statistics-related stuff -struct StatsWrapper { - // Stats parameters and status - int currentPage; - int pageCount; - bool needUpdate; - - // Actual stats - int percentVictories; - int gamesPlayed; - int cardCount; - int countLands; - int totalPrice; - int totalManaCost; - float avgManaCost; - int totalCreatureCost; - float avgCreatureCost; - int totalSpellCost; - float avgSpellCost; - int countManaProducers; - - int countCreatures, countSpells, countInstants, countEnchantments, countSorceries, countArtifacts; - - float noLandsProbInTurn[STATS_FOR_TURNS]; - float noCreaturesProbInTurn[STATS_FOR_TURNS]; - - int countCardsPerCost[STATS_MAX_MANA_COST+1]; - int countCardsPerCostAndColor[STATS_MAX_MANA_COST+1][Constants::MTG_NB_COLORS+1]; - int countCreaturesPerCost[STATS_MAX_MANA_COST+1]; - 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; - - vector aiDeckNames; - vector aiDeckStats; -}; - class GameStateDeckViewer: public GameState, public JGuiListener { private: @@ -156,10 +111,11 @@ private: DeckDataWrapper * myDeck; DeckDataWrapper * myCollection; MTGCard * cardIndex[7]; + StatsWrapper *stw; + int hudAlpha; string newDeckname; bool isAIDeckSave; - StatsWrapper stw; bool mSwitching; void saveDeck(); //Saves the deck and additional necessary information void saveAsAIDeck(string deckName); // saves deck as an AI Deck @@ -185,7 +141,9 @@ public: virtual void renderCard(int id, float rotation); virtual void renderCard (int id); virtual void Render(); - int loadDeck(int deckid); + int loadDeck(int deckid); + void LoadDeckStatistics(int deckId); + void buildEditorMenu(); virtual void ButtonPressed(int controllerId, int controlId); void updateStats(); diff --git a/projects/mtg/include/MTGDefinitions.h b/projects/mtg/include/MTGDefinitions.h index 2cc4d763a..4c27aabef 100644 --- a/projects/mtg/include/MTGDefinitions.h +++ b/projects/mtg/include/MTGDefinitions.h @@ -34,7 +34,11 @@ class Constants static const string kRetraceKeyword; static const string kKickerKeyword; - enum + // used for deck statistics + static const int STATS_FOR_TURNS = 8; + static const int STATS_MAX_MANA_COST = 9; + + enum { MTG_COLOR_ARTIFACT = 0, MTG_COLOR_GREEN = 1, diff --git a/projects/mtg/src/DeckEditorMenu.cpp b/projects/mtg/src/DeckEditorMenu.cpp index fef9564cd..fe1f751c4 100644 --- a/projects/mtg/src/DeckEditorMenu.cpp +++ b/projects/mtg/src/DeckEditorMenu.cpp @@ -1,11 +1,21 @@ +<<<<<<< .mine +#include "PrecompiledHeader.h" +#include +#include "DeckEditorMenu.h" #include "PrecompiledHeader.h" #include "DeckEditorMenu.h" +#include "DeckDataWrapper.h" +#include "DeckStats.h" #include "JTypes.h" - -DeckEditorMenu::DeckEditorMenu(int id, JGuiListener* listener, int fontId, const char * _title) -: DeckMenu( id, listener, fontId, _title ) +#include "GameApp.h" + +DeckEditorMenu::DeckEditorMenu(int id, JGuiListener* listener, int fontId, const char * _title, DeckDataWrapper *_selectedDeck, StatsWrapper *stats) +: DeckMenu( id, listener, fontId, _title ), selectedDeck(_selectedDeck), stw( stats ) { backgroundName = "DeckEditorMenuBackdrop"; + + + deckTitle = selectedDeck ? selectedDeck->parent->meta_name : ""; mX = 120; mY = 70; @@ -37,10 +47,53 @@ void DeckEditorMenu::Render() { JRenderer *r = JRenderer::GetInstance(); r->FillRect(0,0,SCREEN_WIDTH,SCREEN_HEIGHT,ARGB(200,0,0,0)); - DeckMenu::Render(); -} -DeckEditorMenu::~DeckEditorMenu() -{ - SAFE_DELETE( scroller ); -} + DeckMenu::Render(); + WFont *mainFont = resources.GetWFont( Fonts::MAIN_FONT ); + mainFont->DrawString( deckTitle.c_str(), statsX, statsY ); + + if ( stw && selectedDeck ) + drawDeckStatistics(); + +} + +void DeckEditorMenu::drawDeckStatistics() +{ + ostringstream deckStatsString; + + deckStatsString + << "------- Deck Summary -----" << endl + << "Cards: "<< selectedDeck->getCount() << endl + << "Creatures: "<< setw(2) << stw->countCreatures + << " Enchantments: " << stw->countEnchantments << endl + << "Instants: " << setw(4) << stw->countInstants + << " Sorceries: " << setw(2) << stw->countSorceries << endl + << "Lands: " + << "A: " << setw(2) << left << stw->countLandsPerColor[ Constants::MTG_COLOR_ARTIFACT ] + stw->countBasicLandsPerColor[ Constants::MTG_COLOR_ARTIFACT ] << " " + << "G: " << setw(2) << left << stw->countLandsPerColor[ Constants::MTG_COLOR_GREEN ] + stw->countLandsPerColor[ Constants::MTG_COLOR_GREEN ] << " " + << "R: " << setw(2) << left << stw->countLandsPerColor[ Constants::MTG_COLOR_RED ] + stw->countBasicLandsPerColor[ Constants::MTG_COLOR_RED ] << " " + << "U: " << setw(2) << left << stw->countLandsPerColor[ Constants::MTG_COLOR_BLUE ] + stw->countBasicLandsPerColor[ Constants::MTG_COLOR_BLUE ] << " " + << "B: " << setw(2) << left << stw->countLandsPerColor[ Constants::MTG_COLOR_BLACK ] + stw->countBasicLandsPerColor[ Constants::MTG_COLOR_BLACK ] << " " + << "W: " << setw(2) << left << stw->countLandsPerColor[ Constants::MTG_COLOR_WHITE ] + stw->countBasicLandsPerColor[ Constants::MTG_COLOR_WHITE ] << endl + + << " --- Card color count --- " << endl + << "A: " << setw(2) << left << selectedDeck->getCount(Constants::MTG_COLOR_ARTIFACT) << " " + << "G: " << setw(2) << left << selectedDeck->getCount(Constants::MTG_COLOR_GREEN) << " " + << "U: " << setw(2) << left << selectedDeck->getCount(Constants::MTG_COLOR_BLUE) << " " + << "R: " << setw(2) << left << selectedDeck->getCount(Constants::MTG_COLOR_RED) << " " + << "B: " << setw(2) << left << selectedDeck->getCount(Constants::MTG_COLOR_BLACK) << " " + << "W: " << setw(2) << left << selectedDeck->getCount(Constants::MTG_COLOR_WHITE) << endl + + << " --- Average Cost --- " << endl + << "Creature: "<< setprecision(2) << stw->avgCreatureCost << endl + << "Mana: " << setprecision(2) << stw->avgManaCost << " " + << "Spell: " << setprecision(2) << stw->avgSpellCost << endl; + + WFont *mainFont = resources.GetWFont( Fonts::MAIN_FONT ); + mainFont->DrawString( deckStatsString.str().c_str(), descX, descY + 25 ); +} + +DeckEditorMenu::~DeckEditorMenu() +{ + SAFE_DELETE( scroller ); +} diff --git a/projects/mtg/src/DeckMenu.cpp b/projects/mtg/src/DeckMenu.cpp index a8198652d..a7700fc3e 100644 --- a/projects/mtg/src/DeckMenu.cpp +++ b/projects/mtg/src/DeckMenu.cpp @@ -17,6 +17,7 @@ namespace const float kDescriptionVerticalBoxPadding = 5; const float kDescriptionHorizontalBoxPadding = 5; } + #define ARGB(a, r, g, b) (((a) << 24) | ((r) << 16) | ((g) << 8) | (b)) hgeParticleSystem* DeckMenu::stars = NULL; diff --git a/projects/mtg/src/DeckStats.cpp b/projects/mtg/src/DeckStats.cpp index dd126e71a..6d7c3fd2c 100644 --- a/projects/mtg/src/DeckStats.cpp +++ b/projects/mtg/src/DeckStats.cpp @@ -144,3 +144,58 @@ void DeckStats::saveStats(Player *player, Player *opponent, GameObserver * game) } save(player); } + + +StatsWrapper::StatsWrapper( int deckId ) +{ + // Load deck statistics + char buffer[512]; + DeckStats * stats = DeckStats::GetInstance(); + aiDeckNames.clear(); + aiDeckStats.clear(); + + sprintf(buffer, "stats/player_deck%i.txt", deckId); + string deckstats = options.profileFile(buffer); + + if(fileExists(deckstats.c_str())){ + stats->load(deckstats.c_str()); + percentVictories = stats->percentVictories(); + gamesPlayed = stats->nbGames(); + + // Detailed deck statistics against AI + int found = 1; + int nbDecks = 0; + while (found){ + found = 0; + char buffer[512]; + char smallDeckName[512]; + sprintf(buffer, "%s/deck%i.txt",RESPATH"/ai/baka",nbDecks+1); + if(fileExists(buffer)){ + MTGDeck * mtgd = NEW MTGDeck(buffer,NULL,1); + found = 1; + nbDecks++; + + sprintf(smallDeckName, "%s_deck%i","ai_baka",nbDecks); + DeckStat* deckStat = stats->getDeckStat(string(smallDeckName)); + + if ((deckStat != NULL) && (deckStat->nbgames>0)) { + int percentVictories = stats->percentVictories(string(smallDeckName)); + aiDeckNames.push_back(string(mtgd->meta_name)); + aiDeckStats.push_back(deckStat); + } + + delete mtgd; + } + } + } + else { + gamesPlayed = 0; + percentVictories = 0; + } +} + +StatsWrapper::~StatsWrapper() +{ + aiDeckNames.clear(); + aiDeckStats.clear(); +} \ No newline at end of file diff --git a/projects/mtg/src/GameStateDeckViewer.cpp b/projects/mtg/src/GameStateDeckViewer.cpp index 8e12dae31..77ab566d8 100644 --- a/projects/mtg/src/GameStateDeckViewer.cpp +++ b/projects/mtg/src/GameStateDeckViewer.cpp @@ -53,6 +53,7 @@ GameStateDeckViewer::GameStateDeckViewer(GameApp* parent): GameState(parent) { mSlide = 0; mAlpha = 255; menu = NULL; + stw = NULL; } GameStateDeckViewer::~GameStateDeckViewer() { @@ -65,6 +66,7 @@ GameStateDeckViewer::~GameStateDeckViewer() { SAFE_DELETE(myCollection->parent); SAFE_DELETE(myCollection); } + SAFE_DELETE(stw); SAFE_DELETE(filterMenu); } @@ -157,42 +159,20 @@ void GameStateDeckViewer::updateDecks(){ void GameStateDeckViewer::buildEditorMenu() { - ostringstream aiDeckMsg; - - if ( myDeck ) { - aiDeckMsg - << "------- Deck Summary -----" << endl - << "# Cards: "<< myDeck->getCount() << endl - << "# Lands: "<< myDeck->getCount(Constants::MTG_COLOR_LAND ) << endl - << "# Creatures: "<< stw.countCreatures << endl - << "# Spells: " << stw.countSpells << endl - << "Avg. Creature Cost: " << setprecision(2) << stw.avgCreatureCost << endl - << "Avg. Mana Cost: " << setprecision(2) << stw.avgManaCost << endl - << "Avg. Spell Cost: " << setprecision(2) << stw.avgSpellCost << endl - << " --- Card color count --- " << endl - << "A: " << myDeck->getCount(Constants::MTG_COLOR_ARTIFACT) - << " G: " << myDeck->getCount(Constants::MTG_COLOR_GREEN) - << " U: " << myDeck->getCount(Constants::MTG_COLOR_BLUE) - << endl - << "R: " << myDeck->getCount(Constants::MTG_COLOR_RED) - << " B: " << myDeck->getCount(Constants::MTG_COLOR_BLACK) - << " W: " << myDeck->getCount(Constants::MTG_COLOR_WHITE) - << endl; - } - else - aiDeckMsg << "****WARNING*****" << endl << "All changes are final." << endl; + ostringstream deckSummaryInformation; + deckSummaryInformation << "All changes are final." << endl; if ( menu ) SAFE_DELETE( menu ); //Build menu. JRenderer::GetInstance()->FillRoundRect(0, 0, SCREEN_WIDTH, SCREEN_HEIGHT, 100, ARGB(0, 0, 0, 0) ); - menu = NEW DeckEditorMenu( MENU_DECK_BUILDER, this, Fonts::MAGIC_FONT, "Deck Editor"); + menu = NEW DeckEditorMenu( MENU_DECK_BUILDER, this, Fonts::MAGIC_FONT, "Deck Editor", myDeck, stw ); menu->Add( MENU_ITEM_FILTER_BY, "Filter By...", "Narrow down the list of cards. "); menu->Add( MENU_ITEM_SWITCH_DECKS_NO_SAVE, "Switch Decks", "Do not make any changes.\nView another deck."); menu->Add( MENU_ITEM_SAVE_RENAME, "Rename Deck", "Change the name of the deck"); menu->Add( MENU_ITEM_SAVE_RETURN_MAIN_MENU, "Save & Quit Editor", "Save changes.\nReturn to the main menu"); - menu->Add( MENU_ITEM_SAVE_AS_AI_DECK, "Save As AI Deck", aiDeckMsg.str() ); + menu->Add( MENU_ITEM_SAVE_AS_AI_DECK, "Save As AI Deck", deckSummaryInformation.str() ); menu->Add( MENU_ITEM_MAIN_MENU, "Quit Editor", "Do not make any changes to deck.\nReturn to the main menu."); menu->Add( MENU_ITEM_EDITOR_CANCEL, "Cancel", "Close menu."); @@ -290,7 +270,7 @@ void GameStateDeckViewer::addRemove(MTGCard * card){ } myCollection->validate(); myDeck->validate(); - stw.needUpdate = true; + stw->needUpdate = true; loadIndexes(); } @@ -416,7 +396,7 @@ void GameStateDeckViewer::Update(float dt) subMenu->Add( MENU_ITEM_NO,"No","",true); } } - stw.needUpdate = true; + stw->needUpdate = true; break; case JGE_BTN_MENU : @@ -437,14 +417,14 @@ void GameStateDeckViewer::Update(float dt) case JGE_BTN_PREV : if (last_user_activity < NO_USER_ACTIVITY_HELP_DELAY) last_user_activity = NO_USER_ACTIVITY_HELP_DELAY + 1; - else if ((mStage == STAGE_ONSCREEN_MENU) && (--stw.currentPage < 0)) - stw.currentPage = stw.pageCount; + else if ((mStage == STAGE_ONSCREEN_MENU) && (--stw->currentPage < 0)) + stw->currentPage = stw->pageCount; break; case JGE_BTN_NEXT : if (last_user_activity < NO_USER_ACTIVITY_HELP_DELAY) last_user_activity = NO_USER_ACTIVITY_HELP_DELAY + 1; - else if ((mStage == STAGE_ONSCREEN_MENU) && (++stw.currentPage > stw.pageCount)) - stw.currentPage = 0; + else if ((mStage == STAGE_ONSCREEN_MENU) && (++stw->currentPage > stw->pageCount)) + stw->currentPage = 0; break; default : // no keypress if (last_user_activity > NO_USER_ACTIVITY_HELP_DELAY){ @@ -654,7 +634,7 @@ void GameStateDeckViewer::renderOnScreenMenu(){ float rightPspY = SCREEN_HEIGHT/2 - 20 ; - if (stw.currentPage == 0) { + if (stw->currentPage == 0) { //FillRects r->FillRect(0-(onScreenTransition*84),0,84,SCREEN_HEIGHT,ARGB(128,0,0,0)); r->FillRect(SCREEN_WIDTH-204+(onScreenTransition*204),0,200,SCREEN_HEIGHT,ARGB(128,0,0,0)); @@ -725,7 +705,7 @@ void GameStateDeckViewer::renderOnScreenMenu(){ font->DrawString(_("deck statistics."), SCREEN_WIDTH-200+rightTransition, 5+fH*2); } else { - if (stw.needUpdate) { + if (stw->needUpdate) { updateStats(); } @@ -748,15 +728,15 @@ void GameStateDeckViewer::renderOnScreenMenu(){ graphColor = ARGB(200, 155, 155, 155); string STATS_TITLE_FORMAT = _("%i: %s"); - switch (stw.currentPage) { + switch (stw->currentPage) { case 1: // Counts, price // Title - sprintf(buffer, STATS_TITLE_FORMAT.c_str(), stw.currentPage, _("Statistics Summary").c_str()); + sprintf(buffer, STATS_TITLE_FORMAT.c_str(), stw->currentPage, _("Statistics Summary").c_str()); font->DrawString(buffer, 10+leftTransition, 10); posY = 30; posX = 180; - sprintf(buffer, _("Your Deck: %i cards").c_str(), stw.cardCount); + sprintf(buffer, _("Your Deck: %i cards").c_str(), stw->cardCount); font->DrawString(buffer, 20 + leftTransition, posY); posY += 10; @@ -779,43 +759,43 @@ void GameStateDeckViewer::renderOnScreenMenu(){ r->DrawLine(20 + leftTransition, posY - 1, posX + 40 + leftTransition, posY - 1, ARGB(128, 255, 255, 255)); font->DrawString(_("Lands"), 20 + leftTransition, posY); - sprintf(buffer, _("%i").c_str(), stw.countLands); + sprintf(buffer, _("%i").c_str(), stw->countLands); font->DrawString(buffer, posX + leftTransition, posY); posY += 14; r->DrawLine(20 + leftTransition, posY - 1, posX + 40 + leftTransition, posY - 1, ARGB(128, 255, 255, 255)); font->DrawString( _("Creatures"), 20 + leftTransition, posY); - sprintf(buffer, _("%i").c_str(), stw.countCreatures); + sprintf(buffer, _("%i").c_str(), stw->countCreatures); font->DrawString(buffer, posX + leftTransition, posY); posY += 14; r->DrawLine(20 + leftTransition, posY - 1, posX + 40 + leftTransition, posY - 1, ARGB(128, 255, 255, 255)); font->DrawString(_("Spells"), 20 + leftTransition, posY); - sprintf(buffer, _("%i").c_str(), stw.countSpells); + sprintf(buffer, _("%i").c_str(), stw->countSpells); font->DrawString(buffer, posX + leftTransition, posY); posY += 10; font->DrawString(_("Instants"), 30 + leftTransition, posY); - sprintf(buffer, _("%i").c_str(), stw.countInstants); + sprintf(buffer, _("%i").c_str(), stw->countInstants); font->DrawString(buffer, posX + leftTransition, posY); posY += 10; font->DrawString(_("Enchantments"), 30 + leftTransition, posY); - sprintf(buffer, _("%i").c_str(), stw.countEnchantments); + sprintf(buffer, _("%i").c_str(), stw->countEnchantments); font->DrawString(buffer, posX + leftTransition, posY); posY += 10; font->DrawString(_("Sorceries"), 30 + leftTransition, posY); - sprintf(buffer, _("%i").c_str(), stw.countSorceries); + sprintf(buffer, _("%i").c_str(), stw->countSorceries); font->DrawString(buffer, posX + leftTransition, posY); - //sprintf(buffer, "Artifacts: %i", stw.countArtifacts); + //sprintf(buffer, "Artifacts: %i", stw->countArtifacts); //mFont->DrawString(buffer, 20, 123); posY += 14; r->DrawLine(20 + leftTransition, posY - 1, posX + 40 + leftTransition, posY - 1, ARGB(128, 255, 255, 255)); font->DrawString(_("Average converted mana cost"), 20 + leftTransition, posY); - sprintf(buffer, _("%2.2f").c_str(), stw.avgManaCost); + sprintf(buffer, _("%2.2f").c_str(), stw->avgManaCost); font->DrawString(buffer, posX + leftTransition, posY); posY += 14; @@ -824,17 +804,17 @@ void GameStateDeckViewer::renderOnScreenMenu(){ posY += 10; font->DrawString(_("No land in 1st hand"), 30 + leftTransition, posY); - sprintf(buffer, _("%2.2f%%").c_str(), stw.noLandsProbInTurn[0]); + sprintf(buffer, _("%2.2f%%").c_str(), stw->noLandsProbInTurn[0]); font->DrawString(buffer, posX + leftTransition, posY); posY += 10; font->DrawString(_("No land in 9 cards"), 30 + leftTransition, posY); - sprintf(buffer, _("%2.2f%%").c_str(), stw.noLandsProbInTurn[2]); + sprintf(buffer, _("%2.2f%%").c_str(), stw->noLandsProbInTurn[2]); font->DrawString(buffer, posX + leftTransition, posY); posY += 10; font->DrawString(_("No creatures in 1st hand"), 30 + leftTransition, posY); - sprintf(buffer, _("%2.2f%%").c_str(), stw.noCreaturesProbInTurn[0]); + sprintf(buffer, _("%2.2f%%").c_str(), stw->noCreaturesProbInTurn[0]); font->DrawString(buffer, posX + leftTransition, posY); // Playgame Statistics @@ -844,25 +824,25 @@ void GameStateDeckViewer::renderOnScreenMenu(){ posY += 10; font->DrawString(_("Games played"), 30 + leftTransition, posY); - sprintf(buffer, _("%i").c_str(), stw.gamesPlayed); + sprintf(buffer, _("%i").c_str(), stw->gamesPlayed); font->DrawString(buffer, posX + leftTransition, posY); posY += 10; font->DrawString(_("Victory ratio"), 30 + leftTransition, posY); - sprintf(buffer, _("%i%%").c_str(), stw.percentVictories); + sprintf(buffer, _("%i%%").c_str(), stw->percentVictories); font->DrawString(buffer, posX + leftTransition, posY); posY += 15; r->DrawLine(20 + leftTransition, posY - 1, posX + 40 + leftTransition, posY - 1, ARGB(128, 255, 255, 255)); font->DrawString(_("Total price (credits)"), 20 + leftTransition, posY); - sprintf(buffer, _("%i ").c_str(), stw.totalPrice); + sprintf(buffer, _("%i ").c_str(), stw->totalPrice); font->DrawString(buffer, posX + leftTransition, posY); 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()); + 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); @@ -896,19 +876,19 @@ void GameStateDeckViewer::renderOnScreenMenu(){ int curCount; for (int j=0; jcountBasicLandsPerColor[j]; sprintf(buffer, (curCount==0?".":"%i"), curCount); font->DrawString(buffer, 49 + leftTransition + j*15, posY); - curCount = stw.countLandsPerColor[j]; + curCount = stw->countLandsPerColor[j]; sprintf(buffer, (curCount==0?".":"%i"), curCount); font->DrawString(buffer, 49 + leftTransition + j*15, posY+10); - curCount = stw.countNonLandProducersPerColor[j]; + 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]; + 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); } @@ -925,28 +905,28 @@ void GameStateDeckViewer::renderOnScreenMenu(){ break; case 6: // Land statistics - in symbols - sprintf(buffer, STATS_TITLE_FORMAT.c_str(), stw.currentPage, _("Mana production - in mana symbols").c_str()); + 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; icountLandsPerColor[i] + stw->countBasicLandsPerColor[i]; //!! Move to updatestats! } posY = 50; for (int i=1; i0) { - sprintf(buffer, _("%i").c_str(), stw.countLandsPerColor[i] + stw.countBasicLandsPerColor[i]); + if (stw->countLandsPerColor[i] + stw->countBasicLandsPerColor[i]>0) { + 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)); + 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; jcountLandsPerColor[i] + stw->countBasicLandsPerColor[i]; j++) { r->RenderQuad(mIcons[i], posX + leftTransition, posY+6, 0, 0.5, 0.5); posX += ((j+1)%10==0)?17:13; - if ((((j+1)%30)==0) && (jcountLandsPerColor[i] + stw->countBasicLandsPerColor[i]-1)) { posX = 72; posY += 15; } @@ -960,37 +940,37 @@ void GameStateDeckViewer::renderOnScreenMenu(){ case 2: // Mana cost detail case 3: case 4: - int (*countPerCost)[STATS_MAX_MANA_COST+1]; - int (*countPerCostAndColor)[STATS_MAX_MANA_COST+1][Constants::MTG_NB_COLORS+1]; + int (*countPerCost)[Constants::STATS_MAX_MANA_COST+1]; + int (*countPerCostAndColor)[Constants::STATS_MAX_MANA_COST+1][Constants::MTG_NB_COLORS+1]; float avgCost; - switch (stw.currentPage) { // Nested switch on the same variable. Oh yes. + switch (stw->currentPage) { // Nested switch on the same variable. Oh yes. case 2: // Total counts // Title - sprintf(buffer, STATS_TITLE_FORMAT.c_str(), stw.currentPage, _("Mana cost detail").c_str()); + sprintf(buffer, STATS_TITLE_FORMAT.c_str(), stw->currentPage, _("Mana cost detail").c_str()); font->DrawString(buffer, 10+leftTransition, 10); font->DrawString(_("Card counts per mana cost:"), 20 + leftTransition, 30); - avgCost = stw.avgManaCost; - countPerCost = &stw.countCardsPerCost; - countPerCostAndColor = &stw.countCardsPerCostAndColor; + avgCost = stw->avgManaCost; + countPerCost = &stw->countCardsPerCost; + countPerCostAndColor = &stw->countCardsPerCostAndColor; break; case 3: // Creature counts // Title - sprintf(buffer, STATS_TITLE_FORMAT.c_str(), stw.currentPage, _("Mana cost detail - Creatures").c_str()); + sprintf(buffer, STATS_TITLE_FORMAT.c_str(), stw->currentPage, _("Mana cost detail - Creatures").c_str()); font->DrawString(buffer, 10+leftTransition, 10); font->DrawString(_("Creature counts per mana cost:"), 20 + leftTransition, 30); - avgCost = stw.avgCreatureCost; - countPerCost = &stw.countCreaturesPerCost; - countPerCostAndColor = &stw.countCreaturesPerCostAndColor; + avgCost = stw->avgCreatureCost; + countPerCost = &stw->countCreaturesPerCost; + countPerCostAndColor = &stw->countCreaturesPerCostAndColor; break; case 4: // Spell counts // Title - sprintf(buffer, STATS_TITLE_FORMAT.c_str(), stw.currentPage, _("Mana cost detail - Spells").c_str()); + sprintf(buffer, STATS_TITLE_FORMAT.c_str(), stw->currentPage, _("Mana cost detail - Spells").c_str()); font->DrawString(buffer, 10+leftTransition, 10); font->DrawString(_("Non-creature spell counts per mana cost:"), 20 + leftTransition, 30); - avgCost = stw.avgSpellCost; - countPerCost = &stw.countSpellsPerCost; - countPerCostAndColor = &stw.countSpellsPerCostAndColor; + avgCost = stw->avgSpellCost; + countPerCost = &stw->countSpellsPerCost; + countPerCostAndColor = &stw->countSpellsPerCostAndColor; break; default: countPerCost = NULL; @@ -1012,15 +992,15 @@ void GameStateDeckViewer::renderOnScreenMenu(){ // Horizontal table lines r->DrawLine(27 + leftTransition, posY - 20, 75 + (Constants::MTG_NB_COLORS-2)*15 + leftTransition, posY - 20, ARGB(128, 255, 255, 255)); r->DrawLine(27 + leftTransition, posY - 1, 75 + (Constants::MTG_NB_COLORS-2)*15 + leftTransition, posY - 1, ARGB(128, 255, 255, 255)); - r->DrawLine(27 + leftTransition, STATS_MAX_MANA_COST*10 + posY + 12, 75 + (Constants::MTG_NB_COLORS-2)*15 + leftTransition, STATS_MAX_MANA_COST*10 + posY + 12, ARGB(128, 255, 255, 255)); + r->DrawLine(27 + leftTransition, Constants::STATS_MAX_MANA_COST*10 + posY + 12, 75 + (Constants::MTG_NB_COLORS-2)*15 + leftTransition, Constants::STATS_MAX_MANA_COST*10 + posY + 12, ARGB(128, 255, 255, 255)); // Vertical table lines - r->DrawLine(26 + leftTransition, posY - 20, 26 + leftTransition, STATS_MAX_MANA_COST*10 + posY + 12, ARGB(128, 255, 255, 255)); - r->DrawLine(41 + leftTransition, posY - 20, 41 + leftTransition, STATS_MAX_MANA_COST*10 + posY + 12, ARGB(128, 255, 255, 255)); - r->DrawLine(58 + leftTransition, posY - 20, 58 + leftTransition, STATS_MAX_MANA_COST*10 + posY + 12, ARGB(128, 255, 255, 255)); - r->DrawLine(75 + leftTransition + (Constants::MTG_NB_COLORS-2)*15, posY - 20, 75 + leftTransition + (Constants::MTG_NB_COLORS-2)*15, STATS_MAX_MANA_COST*10 + posY + 12, ARGB(128, 255, 255, 255)); + r->DrawLine(26 + leftTransition, posY - 20, 26 + leftTransition, Constants::STATS_MAX_MANA_COST*10 + posY + 12, ARGB(128, 255, 255, 255)); + r->DrawLine(41 + leftTransition, posY - 20, 41 + leftTransition, Constants::STATS_MAX_MANA_COST*10 + posY + 12, ARGB(128, 255, 255, 255)); + r->DrawLine(58 + leftTransition, posY - 20, 58 + leftTransition, Constants::STATS_MAX_MANA_COST*10 + posY + 12, ARGB(128, 255, 255, 255)); + r->DrawLine(75 + leftTransition + (Constants::MTG_NB_COLORS-2)*15, posY - 20, 75 + leftTransition + (Constants::MTG_NB_COLORS-2)*15, Constants::STATS_MAX_MANA_COST*10 + posY + 12, ARGB(128, 255, 255, 255)); - for (int i=0; i<=STATS_MAX_MANA_COST; i++) { + for (int i=0; i<=Constants::STATS_MAX_MANA_COST; i++) { sprintf(buffer, _("%i").c_str(), i); font->DrawString(buffer, 30 + leftTransition, posY); sprintf(buffer, ((*countPerCost)[i]>0)?_("%i").c_str():".", (*countPerCost)[i]); @@ -1037,7 +1017,7 @@ void GameStateDeckViewer::renderOnScreenMenu(){ sprintf(buffer, _("Average converted mana cost: %2.2f").c_str(), avgCost); font->DrawString(buffer, 20 + leftTransition, posY); posY += 15; - sprintf(buffer, _("C - Converted mana cost. Cards with cost>%i are included in the last row.").c_str(), STATS_MAX_MANA_COST); + sprintf(buffer, _("C - Converted mana cost. Cards with cost>%i are included in the last row.").c_str(), Constants::STATS_MAX_MANA_COST); font->DrawString(buffer, 20 + leftTransition, posY); posY += 10; font->DrawString(_("# - Total number of cards with given cost"), 20 + leftTransition, posY); @@ -1046,22 +1026,22 @@ void GameStateDeckViewer::renderOnScreenMenu(){ case 8: // Title - sprintf(buffer, STATS_TITLE_FORMAT.c_str(), stw.currentPage, _("Probabilities").c_str()); + sprintf(buffer, STATS_TITLE_FORMAT.c_str(), stw->currentPage, _("Probabilities").c_str()); font->DrawString(buffer, 10+leftTransition, 10); // No lands detail float graphScale, graphWidth; graphWidth = 100; - graphScale = (stw.noLandsProbInTurn[0]==0) ? 0:(graphWidth/stw.noLandsProbInTurn[0]); + graphScale = (stw->noLandsProbInTurn[0]==0) ? 0:(graphWidth/stw->noLandsProbInTurn[0]); font->DrawString( _("No lands in first n cards:"), 20 + leftTransition, 30); posY = 50; - for (int i=0; iDrawString(buffer, 30 + leftTransition, posY); - sprintf(buffer, _("%2.2f%%").c_str(), stw.noLandsProbInTurn[i]); + sprintf(buffer, _("%2.2f%%").c_str(), stw->noLandsProbInTurn[i]); font->DrawString(buffer, 45 + leftTransition, posY); - r->FillRect(84 + leftTransition, posY + 2, graphScale*stw.noLandsProbInTurn[i], 8, graphColor); + r->FillRect(84 + leftTransition, posY + 2, graphScale*stw->noLandsProbInTurn[i], 8, graphColor); posY += 10; } @@ -1069,14 +1049,14 @@ void GameStateDeckViewer::renderOnScreenMenu(){ posY += 10; font->DrawString( _("No creatures in first n cards:"), 20 + leftTransition, posY); posY += 20; - graphScale = (stw.noCreaturesProbInTurn[0]==0) ? 0:(graphWidth/stw.noCreaturesProbInTurn[0]); + graphScale = (stw->noCreaturesProbInTurn[0]==0) ? 0:(graphWidth/stw->noCreaturesProbInTurn[0]); - for (int i=0; iDrawString(buffer, 30 + leftTransition, posY); - sprintf(buffer, _("%2.2f%%").c_str(), stw.noCreaturesProbInTurn[i]); + sprintf(buffer, _("%2.2f%%").c_str(), stw->noCreaturesProbInTurn[i]); font->DrawString(buffer, 45 + leftTransition, posY); - r->FillRect(84 + leftTransition, posY + 2, graphScale*stw.noCreaturesProbInTurn[i], 8, graphColor); + r->FillRect(84 + leftTransition, posY + 2, graphScale*stw->noCreaturesProbInTurn[i], 8, graphColor); posY += 10; } @@ -1084,23 +1064,23 @@ void GameStateDeckViewer::renderOnScreenMenu(){ case 7: // Total mana cost per color // Title - sprintf(buffer, STATS_TITLE_FORMAT.c_str(), stw.currentPage, _("Mana cost per color").c_str()); + sprintf(buffer, STATS_TITLE_FORMAT.c_str(), stw->currentPage, _("Mana cost per color").c_str()); font->DrawString(buffer, 10+leftTransition, 10); font->DrawString(_("Total colored manasymbols in cards' casting costs:"), 20 + leftTransition, 30); posY = 50; for (int i=1; i0) { - sprintf(buffer, _("%i").c_str(), stw.totalCostPerColor[i]); + if (stw->totalCostPerColor[i]>0) { + sprintf(buffer, _("%i").c_str(), stw->totalCostPerColor[i]); font->DrawString(buffer, 20 + leftTransition, posY); - sprintf(buffer, _("(%i%%)").c_str(), (int)(100*(float)stw.totalCostPerColor[i]/stw.totalColoredSymbols)); + sprintf(buffer, _("(%i%%)").c_str(), (int)(100*(float)stw->totalCostPerColor[i]/stw->totalColoredSymbols)); font->DrawString(buffer, 33 + leftTransition, posY); posX = 72; - for (int j=0; jtotalCostPerColor[i]; j++) { r->RenderQuad(mIcons[i], posX + leftTransition, posY+6, 0, 0.5, 0.5); posX += ((j+1)%10==0)?17:13; - if ((((j+1)%30)==0) && (jtotalCostPerColor[i]-1)) { posX = 72; posY += 15; } @@ -1112,14 +1092,14 @@ void GameStateDeckViewer::renderOnScreenMenu(){ case 9: // Victory statistics // Title - sprintf(buffer, STATS_TITLE_FORMAT.c_str(), stw.currentPage, _("Victory statistics").c_str()); + sprintf(buffer, STATS_TITLE_FORMAT.c_str(), stw->currentPage, _("Victory statistics").c_str()); font->DrawString(buffer, 10+leftTransition, 10); font->DrawString(_("Victories against AI:"), 20 + leftTransition, 30); - sprintf(buffer, _("Games played: %i").c_str(), stw.gamesPlayed); + sprintf(buffer, _("Games played: %i").c_str(), stw->gamesPlayed); font->DrawString(buffer, 20 + leftTransition, 45); - sprintf(buffer, _("Victory ratio: %i%%").c_str(), stw.percentVictories); + sprintf(buffer, _("Victory ratio: %i%%").c_str(), stw->percentVictories); font->DrawString(buffer, 20 + leftTransition, 55); int AIsPerColumn = 19; @@ -1127,12 +1107,12 @@ void GameStateDeckViewer::renderOnScreenMenu(){ posX = 20; // ToDo: Multiple pages when too many AI decks are present - for (int i=0; i<(int)stw.aiDeckStats.size(); i++) { - sprintf(buffer, _("%.14s").c_str(), stw.aiDeckNames.at(i).c_str()); + for (int i=0; i<(int)stw->aiDeckStats.size(); i++) { + sprintf(buffer, _("%.14s").c_str(), stw->aiDeckNames.at(i).c_str()); font->DrawString(buffer, posX + (i < 2*AIsPerColumn ? leftTransition : rightTransition), posY); - sprintf(buffer, _("%i/%i").c_str(), stw.aiDeckStats.at(i)->victories, stw.aiDeckStats.at(i)->nbgames); + sprintf(buffer, _("%i/%i").c_str(), stw->aiDeckStats.at(i)->victories, stw->aiDeckStats.at(i)->nbgames); font->DrawString(buffer, posX + (i < AIsPerColumn ? leftTransition : rightTransition) + 80, posY); - sprintf(buffer, _("%i%%").c_str(), stw.aiDeckStats.at(i)->percentVictories()); + sprintf(buffer, _("%i%%").c_str(), stw->aiDeckStats.at(i)->percentVictories()); font->DrawString(buffer, posX + (i < AIsPerColumn ? leftTransition : rightTransition) + 110, posY); posY += 10; if (((i+1)%AIsPerColumn)==0) { @@ -1146,41 +1126,41 @@ void GameStateDeckViewer::renderOnScreenMenu(){ } void GameStateDeckViewer::updateStats() { - if (!stw.needUpdate || !myDeck) + if (!stw->needUpdate || !myDeck) return; - stw.needUpdate = false; - stw.cardCount = myDeck->getCount(WSrcDeck::UNFILTERED_COPIES); - stw.countLands = myDeck->getCount(Constants::MTG_COLOR_LAND); - stw.totalPrice = myDeck->totalPrice(); + stw->needUpdate = false; + stw->cardCount = myDeck->getCount(WSrcDeck::UNFILTERED_COPIES); + 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; - stw.totalManaCost = 0; - stw.totalCreatureCost = 0; - stw.totalSpellCost = 0; + stw->totalManaCost = 0; + stw->totalCreatureCost = 0; + stw->totalSpellCost = 0; MTGCard * current = myDeck->getCard(); // Clearing arrays - for (int i=0; i<=STATS_MAX_MANA_COST; i++) { - stw.countCardsPerCost[i] = 0; - stw.countCreaturesPerCost[i] = 0; - stw.countSpellsPerCost[i] = 0; + for (int i=0; i<=Constants::STATS_MAX_MANA_COST; i++) { + stw->countCardsPerCost[i] = 0; + stw->countCreaturesPerCost[i] = 0; + stw->countSpellsPerCost[i] = 0; } 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; + 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++) { + for (int i=0; i<=Constants::STATS_MAX_MANA_COST; i++) { for (int k=0; k<=Constants::MTG_NB_COLORS; k++) { - stw.countCardsPerCostAndColor[i][k] = 0; - stw.countCreaturesPerCostAndColor[i][k] = 0; - stw.countSpellsPerCostAndColor[i][k] = 0; + stw->countCardsPerCostAndColor[i][k] = 0; + stw->countCreaturesPerCostAndColor[i][k] = 0; + stw->countSpellsPerCostAndColor[i][k] = 0; } } @@ -1191,17 +1171,17 @@ void GameStateDeckViewer::updateStats() { currentCount = myDeck->count(current); // Add to the cards per cost counters - stw.totalManaCost += convertedCost * currentCount; - if (convertedCost > STATS_MAX_MANA_COST) { - convertedCost = STATS_MAX_MANA_COST; + stw->totalManaCost += convertedCost * currentCount; + if (convertedCost > Constants::STATS_MAX_MANA_COST) { + convertedCost = Constants::STATS_MAX_MANA_COST; } - stw.countCardsPerCost[convertedCost] += currentCount; + stw->countCardsPerCost[convertedCost] += currentCount; if (current->data->isCreature()) { - stw.countCreaturesPerCost[convertedCost] += currentCount; - stw.totalCreatureCost += convertedCost * currentCount; + stw->countCreaturesPerCost[convertedCost] += currentCount; + stw->totalCreatureCost += convertedCost * currentCount; } else if (current->data->isSpell()) { - stw.countSpellsPerCost[convertedCost] += currentCount; - stw.totalSpellCost += convertedCost * currentCount; + stw->countSpellsPerCost[convertedCost] += currentCount; + stw->totalSpellCost += convertedCost * currentCount; } // Lets look for mana producing abilities @@ -1220,12 +1200,12 @@ void GameStateDeckViewer::updateStats() { if(mc->hasColor(j)){ if (current->data->isLand()) { if (current->data->hasType("Basic")) { - stw.countBasicLandsPerColor[j] += currentCount; + stw->countBasicLandsPerColor[j] += currentCount; } else { - stw.countLandsPerColor[j] += currentCount; + stw->countLandsPerColor[j] += currentCount; } } else { - stw.countNonLandProducersPerColor[j] += currentCount; + stw->countNonLandProducersPerColor[j] += currentCount; } } } @@ -1236,14 +1216,14 @@ void GameStateDeckViewer::updateStats() { // Add to the per color counters // a. regular costs for (int j=0; jgetCost(j)*currentCount; + stw->totalCostPerColor[j] += currentCost->getCost(j)*currentCount; if (current->data->hasColor(j)) { // Add to the per cost and color counter - stw.countCardsPerCostAndColor[convertedCost][j] += currentCount; + stw->countCardsPerCostAndColor[convertedCost][j] += currentCount; if (current->data->isCreature()) { - stw.countCreaturesPerCostAndColor[convertedCost][j] += currentCount; + stw->countCreaturesPerCostAndColor[convertedCost][j] += currentCount; } else if (current->data->isSpell()) { - stw.countSpellsPerCostAndColor[convertedCost][j] += currentCount; + stw->countSpellsPerCostAndColor[convertedCost][j] += currentCount; } } } @@ -1254,36 +1234,36 @@ void GameStateDeckViewer::updateStats() { i = 0; while ((hybridCost = currentCost->getHybridCost(i++)) != NULL) { - stw.totalCostPerColor[hybridCost->color1] += hybridCost->value1*currentCount; - stw.totalCostPerColor[hybridCost->color2] += hybridCost->value2*currentCount; + stw->totalCostPerColor[hybridCost->color1] += hybridCost->value1*currentCount; + stw->totalCostPerColor[hybridCost->color2] += hybridCost->value2*currentCount; } } - stw.totalColoredSymbols = 0; + stw->totalColoredSymbols = 0; for (int j=1; jtotalColoredSymbols += stw->totalCostPerColor[j]; } - stw.countCardsPerCost[0] -= stw.countLands; + stw->countCardsPerCost[0] -= stw->countLands; // Counts by type - stw.countCreatures = countCardsByType("Creature"); - stw.countInstants = countCardsByType("Instant"); - stw.countEnchantments = countCardsByType("Enchantment"); - stw.countSorceries = countCardsByType("Sorcery"); - stw.countSpells = stw.countInstants + stw.countEnchantments + stw.countSorceries; - //stw.countArtifacts = countCardsByType("Artifact"); + stw->countCreatures = countCardsByType("Creature"); + stw->countInstants = countCardsByType("Instant"); + stw->countEnchantments = countCardsByType("Enchantment"); + stw->countSorceries = countCardsByType("Sorcery"); + stw->countSpells = stw->countInstants + stw->countEnchantments + stw->countSorceries; + //stw->countArtifacts = countCardsByType("Artifact"); // Average mana costs - stw.avgManaCost = ((stw.cardCount - stw.countLands) <= 0)?0:(float)stw.totalManaCost / (stw.cardCount - stw.countLands); - stw.avgCreatureCost = (stw.countCreatures <= 0)?0:(float)stw.totalCreatureCost / stw.countCreatures; - stw.avgSpellCost = (stw.countSpells <= 0)?0:(float)stw.totalSpellCost / stw.countSpells; + stw->avgManaCost = ((stw->cardCount - stw->countLands) <= 0)?0:(float)stw->totalManaCost / (stw->cardCount - stw->countLands); + stw->avgCreatureCost = (stw->countCreatures <= 0)?0:(float)stw->totalCreatureCost / stw->countCreatures; + stw->avgSpellCost = (stw->countSpells <= 0)?0:(float)stw->totalSpellCost / stw->countSpells; // Probabilities // TODO: this could be optimized by reusing results - for (int i=0; inoLandsProbInTurn[i] = noLuck(stw->cardCount, stw->countLands, 7+i)*100; + stw->noCreaturesProbInTurn[i] = noLuck(stw->cardCount, stw->countCreatures, 7+i)*100; } } @@ -1434,12 +1414,15 @@ void GameStateDeckViewer::Render() { } - + int GameStateDeckViewer::loadDeck(int deckid){ - stw.currentPage = 0; - stw.pageCount = 9; - stw.needUpdate = true; + if (!stw) + stw = new StatsWrapper( deckid ); + + stw->currentPage = 0; + stw->pageCount = 9; + stw->needUpdate = true; if(!playerdata) playerdata = NEW PlayerData(mParent->collection); @@ -1481,51 +1464,6 @@ int GameStateDeckViewer::loadDeck(int deckid){ myCollection->validate(); } - // Load deck statistics - // TODO: Code cleanup (Copypasted with slight changes from GameStateMenu.cpp) - char buffer[512]; - DeckStats * stats = DeckStats::GetInstance(); - stw.aiDeckNames.clear(); - stw.aiDeckStats.clear(); - - sprintf(buffer, "stats/player_deck%i.txt", deckid); - string deckstats = options.profileFile(buffer); - - if(fileExists(deckstats.c_str())){ - stats->load(deckstats.c_str()); - stw.percentVictories = stats->percentVictories(); - stw.gamesPlayed = stats->nbGames(); - - // Detailed deck statistics against AI - int found = 1; - int nbDecks = 0; - while (found){ - found = 0; - char buffer[512]; - char smallDeckName[512]; - sprintf(buffer, "%s/deck%i.txt",JGE_GET_RES("ai/baka").c_str(),nbDecks+1); - if(fileExists(buffer)){ - MTGDeck * mtgd = NEW MTGDeck(buffer,NULL,1); - found = 1; - nbDecks++; - - sprintf(smallDeckName, "%s_deck%i","ai_baka",nbDecks); - DeckStat* deckStat = stats->getDeckStat(string(smallDeckName)); - - if ((deckStat != NULL) && (deckStat->nbgames>0)) { - int percentVictories = stats->percentVictories(string(smallDeckName)); - stw.aiDeckNames.push_back(string(mtgd->meta_name)); - stw.aiDeckStats.push_back(deckStat); - } - - delete mtgd; - } - } - } else { - stw.gamesPlayed = 0; - stw.percentVictories = 0; - } - myDeck->Sort(WSrcCards::SORT_ALPHA); SAFE_DELETE(filterMenu); rebuildFilters(); @@ -1646,7 +1584,7 @@ void GameStateDeckViewer::ButtonPressed(int controllerId, int controlId) playerdata->collection->remove(card->getMTGId()); displayed_deck->Remove(card,1); displayed_deck->validate(); - stw.needUpdate = true; + stw->needUpdate = true; loadIndexes(); } }