Erwan
- Removed 4000 cards limitation - URGENT FIX NEEDED: Test Northern_paladin2.txt fails :(
This commit is contained in:
@@ -53,7 +53,8 @@ class MTGAllCards {
|
||||
|
||||
TexturesCache * mCache;
|
||||
MTGCard * _(int i);
|
||||
MTGCard * collection[Constants::TOTAL_NUMBER_OF_CARDS];
|
||||
vector<MTGCard *> collection;
|
||||
//collection[Constants::TOTAL_NUMBER_OF_CARDS];
|
||||
MTGAllCards();
|
||||
~MTGAllCards();
|
||||
MTGAllCards(TexturesCache * cache);
|
||||
|
||||
@@ -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,
|
||||
|
||||
@@ -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<int,int> prices;
|
||||
public:
|
||||
PriceList(const char * file, MTGAllCards * _collection);
|
||||
~PriceList();
|
||||
|
||||
@@ -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<int> 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; i<total_cards; i++){
|
||||
if (collection[i] == card){
|
||||
collection[i] = collection[total_cards - 1];
|
||||
collection.erase(collection.begin()+i);
|
||||
total_cards--;
|
||||
initCounters();
|
||||
return 1;
|
||||
|
||||
@@ -2,13 +2,8 @@
|
||||
#include "../include/PriceList.h"
|
||||
|
||||
|
||||
Price::Price(int _cardid, int _price): cardid(_cardid),price(_price){
|
||||
}
|
||||
|
||||
|
||||
|
||||
PriceList::PriceList(const char * _filename, MTGAllCards * _collection):collection(_collection){
|
||||
nbprices = 0;
|
||||
filename = _filename;
|
||||
std::ifstream file(_filename);
|
||||
std::string cardid;
|
||||
@@ -16,8 +11,7 @@ PriceList::PriceList(const char * _filename, MTGAllCards * _collection):collecti
|
||||
if(file){
|
||||
while(std::getline(file,cardid)){
|
||||
std::getline(file,price);
|
||||
prices[nbprices]= NEW Price(atoi(cardid.c_str()), atoi(price.c_str()));
|
||||
nbprices++;
|
||||
prices[atoi(cardid.c_str())]= atoi(price.c_str());
|
||||
}
|
||||
file.close();
|
||||
}
|
||||
@@ -25,19 +19,17 @@ PriceList::PriceList(const char * _filename, MTGAllCards * _collection):collecti
|
||||
|
||||
|
||||
PriceList::~PriceList(){
|
||||
for (int i = 0; i < nbprices; i++){
|
||||
delete (prices[i]);
|
||||
}
|
||||
nbprices = 0;
|
||||
}
|
||||
|
||||
int PriceList::save(){
|
||||
std::ofstream file(filename.c_str());
|
||||
char writer[20];
|
||||
if (file){
|
||||
for (int i = 0; i<nbprices; i++){
|
||||
sprintf(writer,"%i\n%i\n", prices[i]->cardid, prices[i]->price);
|
||||
file<<writer;
|
||||
map<int,int>::iterator it=prices.begin();
|
||||
while(it != prices.end()){
|
||||
sprintf(writer,"%i\n%i\n", (*it).first, (*it).second);
|
||||
it++;
|
||||
file<<writer;
|
||||
}
|
||||
file.close();
|
||||
}
|
||||
@@ -45,11 +37,9 @@ int PriceList::save(){
|
||||
return 1;
|
||||
}
|
||||
int PriceList::getPrice(int cardId){
|
||||
for(int i = 0; i < nbprices; i++){
|
||||
if (prices[i]->cardid == cardId){
|
||||
return prices[i]->price;
|
||||
}
|
||||
}
|
||||
map<int,int>::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;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user