From 3ae91e8226b384c9d716740b5e957c095f4c9a4e Mon Sep 17 00:00:00 2001 From: "wagic.the.homebrew@gmail.com" Date: Wed, 20 May 2009 11:07:20 +0000 Subject: [PATCH] Erwan - Removed 4000 cards limitation - URGENT FIX NEEDED: Test Northern_paladin2.txt fails :( --- projects/mtg/include/MTGDeck.h | 3 ++- projects/mtg/include/MTGDefinitions.h | 3 --- projects/mtg/include/PriceList.h | 10 +------ projects/mtg/src/MTGDeck.cpp | 11 ++++---- projects/mtg/src/PriceList.cpp | 39 ++++++++------------------- 5 files changed, 20 insertions(+), 46 deletions(-) diff --git a/projects/mtg/include/MTGDeck.h b/projects/mtg/include/MTGDeck.h index c60d56a7f..94fba37b0 100644 --- a/projects/mtg/include/MTGDeck.h +++ b/projects/mtg/include/MTGDeck.h @@ -53,7 +53,8 @@ class MTGAllCards { TexturesCache * mCache; MTGCard * _(int i); - MTGCard * collection[Constants::TOTAL_NUMBER_OF_CARDS]; + vector collection; + //collection[Constants::TOTAL_NUMBER_OF_CARDS]; MTGAllCards(); ~MTGAllCards(); MTGAllCards(TexturesCache * cache); diff --git a/projects/mtg/include/MTGDefinitions.h b/projects/mtg/include/MTGDefinitions.h index 8b456bfc7..090604fad 100644 --- a/projects/mtg/include/MTGDefinitions.h +++ b/projects/mtg/include/MTGDefinitions.h @@ -10,9 +10,6 @@ class Constants public: enum { - TOTAL_NUMBER_OF_CARDS = 4000, - - MTG_COLOR_ARTIFACT = 0, MTG_COLOR_GREEN = 1, MTG_COLOR_BLUE = 2, diff --git a/projects/mtg/include/PriceList.h b/projects/mtg/include/PriceList.h index bc6b51478..0afee7e77 100644 --- a/projects/mtg/include/PriceList.h +++ b/projects/mtg/include/PriceList.h @@ -8,19 +8,11 @@ class MTGAllCards; -class Price{ - public: - int cardid; - int price; - Price(int _cardid, int _price); -}; - class PriceList{ private: MTGAllCards * collection; string filename; - Price * prices[Constants::TOTAL_NUMBER_OF_CARDS]; - int nbprices; + map prices; public: PriceList(const char * file, MTGAllCards * _collection); ~PriceList(); diff --git a/projects/mtg/src/MTGDeck.cpp b/projects/mtg/src/MTGDeck.cpp index 5049e18ed..057344640 100644 --- a/projects/mtg/src/MTGDeck.cpp +++ b/projects/mtg/src/MTGDeck.cpp @@ -268,7 +268,7 @@ int MTGAllCards::readConfLine(std::ifstream &file, int set_id){ switch(conf_read_mode) { case 0: if (s[0] == '['){ - collection[total_cards] = NEW MTGCard(mCache,set_id); + collection.push_back(NEW MTGCard(mCache,set_id)); conf_read_mode = 1; } break; @@ -381,7 +381,7 @@ int MTGDeck::addRandomCards(int howmany, int setId, int rarity, const char * _su sprintf(subtype, _subtype); - int subcollection[Constants::TOTAL_NUMBER_OF_CARDS]; + vector subcollection; int subtotal = 0; for (int i = 0; i < collectionTotal; i++){ MTGCard * card = allcards->_(i); @@ -389,7 +389,7 @@ int MTGDeck::addRandomCards(int howmany, int setId, int rarity, const char * _su (rarity == -1 || card->getRarity()==rarity) && (!_subtype || card->hasSubtype(subtype)) ){ - subcollection[subtotal] = i; + subcollection.push_back(i); subtotal++; } } @@ -409,7 +409,7 @@ int MTGDeck::add(int cardid){ int MTGDeck::add(MTGCard * card){ if (!card) return 0; - collection[total_cards] = card; + collection.push_back(card); ++total_cards; initCounters(); return total_cards; @@ -418,6 +418,7 @@ int MTGDeck::add(MTGCard * card){ int MTGDeck::removeAll(){ total_cards = 0; + collection.clear(); initCounters(); return 1; } @@ -430,7 +431,7 @@ int MTGDeck::remove(int cardid){ int MTGDeck::remove(MTGCard * card){ for (int i = 0; icardid, prices[i]->price); - file<::iterator it=prices.begin(); + while(it != prices.end()){ + sprintf(writer,"%i\n%i\n", (*it).first, (*it).second); + it++; + file<cardid == cardId){ - return prices[i]->price; - } - } + map::iterator it = prices.find(cardId); + if (it != prices.end()) return (*it).second; + char rarity = collection->getCardById(cardId)->getRarity(); switch(rarity){ case Constants::RARITY_M: @@ -76,13 +66,6 @@ int PriceList::getPrice(int cardId){ } int PriceList::setPrice(int cardId, int price){ - for(int i = 0; i < nbprices; i++){ - if (prices[i]->cardid == cardId){ - prices[i]->price = price; - return prices[i]->price; - } - } - prices[nbprices] = NEW Price(cardId, price); - nbprices++; - return prices[nbprices-1]->price; + prices[cardId] = price; + return price; }