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;
|
TexturesCache * mCache;
|
||||||
MTGCard * _(int i);
|
MTGCard * _(int i);
|
||||||
MTGCard * collection[Constants::TOTAL_NUMBER_OF_CARDS];
|
vector<MTGCard *> collection;
|
||||||
|
//collection[Constants::TOTAL_NUMBER_OF_CARDS];
|
||||||
MTGAllCards();
|
MTGAllCards();
|
||||||
~MTGAllCards();
|
~MTGAllCards();
|
||||||
MTGAllCards(TexturesCache * cache);
|
MTGAllCards(TexturesCache * cache);
|
||||||
|
|||||||
@@ -10,9 +10,6 @@ class Constants
|
|||||||
public:
|
public:
|
||||||
enum
|
enum
|
||||||
{
|
{
|
||||||
TOTAL_NUMBER_OF_CARDS = 4000,
|
|
||||||
|
|
||||||
|
|
||||||
MTG_COLOR_ARTIFACT = 0,
|
MTG_COLOR_ARTIFACT = 0,
|
||||||
MTG_COLOR_GREEN = 1,
|
MTG_COLOR_GREEN = 1,
|
||||||
MTG_COLOR_BLUE = 2,
|
MTG_COLOR_BLUE = 2,
|
||||||
|
|||||||
@@ -8,19 +8,11 @@
|
|||||||
|
|
||||||
class MTGAllCards;
|
class MTGAllCards;
|
||||||
|
|
||||||
class Price{
|
|
||||||
public:
|
|
||||||
int cardid;
|
|
||||||
int price;
|
|
||||||
Price(int _cardid, int _price);
|
|
||||||
};
|
|
||||||
|
|
||||||
class PriceList{
|
class PriceList{
|
||||||
private:
|
private:
|
||||||
MTGAllCards * collection;
|
MTGAllCards * collection;
|
||||||
string filename;
|
string filename;
|
||||||
Price * prices[Constants::TOTAL_NUMBER_OF_CARDS];
|
map<int,int> prices;
|
||||||
int nbprices;
|
|
||||||
public:
|
public:
|
||||||
PriceList(const char * file, MTGAllCards * _collection);
|
PriceList(const char * file, MTGAllCards * _collection);
|
||||||
~PriceList();
|
~PriceList();
|
||||||
|
|||||||
@@ -268,7 +268,7 @@ int MTGAllCards::readConfLine(std::ifstream &file, int set_id){
|
|||||||
switch(conf_read_mode) {
|
switch(conf_read_mode) {
|
||||||
case 0:
|
case 0:
|
||||||
if (s[0] == '['){
|
if (s[0] == '['){
|
||||||
collection[total_cards] = NEW MTGCard(mCache,set_id);
|
collection.push_back(NEW MTGCard(mCache,set_id));
|
||||||
conf_read_mode = 1;
|
conf_read_mode = 1;
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
@@ -381,7 +381,7 @@ int MTGDeck::addRandomCards(int howmany, int setId, int rarity, const char * _su
|
|||||||
sprintf(subtype, _subtype);
|
sprintf(subtype, _subtype);
|
||||||
|
|
||||||
|
|
||||||
int subcollection[Constants::TOTAL_NUMBER_OF_CARDS];
|
vector<int> subcollection;
|
||||||
int subtotal = 0;
|
int subtotal = 0;
|
||||||
for (int i = 0; i < collectionTotal; i++){
|
for (int i = 0; i < collectionTotal; i++){
|
||||||
MTGCard * card = allcards->_(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) &&
|
(rarity == -1 || card->getRarity()==rarity) &&
|
||||||
(!_subtype || card->hasSubtype(subtype))
|
(!_subtype || card->hasSubtype(subtype))
|
||||||
){
|
){
|
||||||
subcollection[subtotal] = i;
|
subcollection.push_back(i);
|
||||||
subtotal++;
|
subtotal++;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -409,7 +409,7 @@ int MTGDeck::add(int cardid){
|
|||||||
|
|
||||||
int MTGDeck::add(MTGCard * card){
|
int MTGDeck::add(MTGCard * card){
|
||||||
if (!card) return 0;
|
if (!card) return 0;
|
||||||
collection[total_cards] = card;
|
collection.push_back(card);
|
||||||
++total_cards;
|
++total_cards;
|
||||||
initCounters();
|
initCounters();
|
||||||
return total_cards;
|
return total_cards;
|
||||||
@@ -418,6 +418,7 @@ int MTGDeck::add(MTGCard * card){
|
|||||||
|
|
||||||
int MTGDeck::removeAll(){
|
int MTGDeck::removeAll(){
|
||||||
total_cards = 0;
|
total_cards = 0;
|
||||||
|
collection.clear();
|
||||||
initCounters();
|
initCounters();
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
@@ -430,7 +431,7 @@ int MTGDeck::remove(int cardid){
|
|||||||
int MTGDeck::remove(MTGCard * card){
|
int MTGDeck::remove(MTGCard * card){
|
||||||
for (int i = 0; i<total_cards; i++){
|
for (int i = 0; i<total_cards; i++){
|
||||||
if (collection[i] == card){
|
if (collection[i] == card){
|
||||||
collection[i] = collection[total_cards - 1];
|
collection.erase(collection.begin()+i);
|
||||||
total_cards--;
|
total_cards--;
|
||||||
initCounters();
|
initCounters();
|
||||||
return 1;
|
return 1;
|
||||||
|
|||||||
@@ -2,13 +2,8 @@
|
|||||||
#include "../include/PriceList.h"
|
#include "../include/PriceList.h"
|
||||||
|
|
||||||
|
|
||||||
Price::Price(int _cardid, int _price): cardid(_cardid),price(_price){
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
PriceList::PriceList(const char * _filename, MTGAllCards * _collection):collection(_collection){
|
PriceList::PriceList(const char * _filename, MTGAllCards * _collection):collection(_collection){
|
||||||
nbprices = 0;
|
|
||||||
filename = _filename;
|
filename = _filename;
|
||||||
std::ifstream file(_filename);
|
std::ifstream file(_filename);
|
||||||
std::string cardid;
|
std::string cardid;
|
||||||
@@ -16,8 +11,7 @@ PriceList::PriceList(const char * _filename, MTGAllCards * _collection):collecti
|
|||||||
if(file){
|
if(file){
|
||||||
while(std::getline(file,cardid)){
|
while(std::getline(file,cardid)){
|
||||||
std::getline(file,price);
|
std::getline(file,price);
|
||||||
prices[nbprices]= NEW Price(atoi(cardid.c_str()), atoi(price.c_str()));
|
prices[atoi(cardid.c_str())]= atoi(price.c_str());
|
||||||
nbprices++;
|
|
||||||
}
|
}
|
||||||
file.close();
|
file.close();
|
||||||
}
|
}
|
||||||
@@ -25,18 +19,16 @@ PriceList::PriceList(const char * _filename, MTGAllCards * _collection):collecti
|
|||||||
|
|
||||||
|
|
||||||
PriceList::~PriceList(){
|
PriceList::~PriceList(){
|
||||||
for (int i = 0; i < nbprices; i++){
|
|
||||||
delete (prices[i]);
|
|
||||||
}
|
|
||||||
nbprices = 0;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
int PriceList::save(){
|
int PriceList::save(){
|
||||||
std::ofstream file(filename.c_str());
|
std::ofstream file(filename.c_str());
|
||||||
char writer[20];
|
char writer[20];
|
||||||
if (file){
|
if (file){
|
||||||
for (int i = 0; i<nbprices; i++){
|
map<int,int>::iterator it=prices.begin();
|
||||||
sprintf(writer,"%i\n%i\n", prices[i]->cardid, prices[i]->price);
|
while(it != prices.end()){
|
||||||
|
sprintf(writer,"%i\n%i\n", (*it).first, (*it).second);
|
||||||
|
it++;
|
||||||
file<<writer;
|
file<<writer;
|
||||||
}
|
}
|
||||||
file.close();
|
file.close();
|
||||||
@@ -45,11 +37,9 @@ int PriceList::save(){
|
|||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
int PriceList::getPrice(int cardId){
|
int PriceList::getPrice(int cardId){
|
||||||
for(int i = 0; i < nbprices; i++){
|
map<int,int>::iterator it = prices.find(cardId);
|
||||||
if (prices[i]->cardid == cardId){
|
if (it != prices.end()) return (*it).second;
|
||||||
return prices[i]->price;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
char rarity = collection->getCardById(cardId)->getRarity();
|
char rarity = collection->getCardById(cardId)->getRarity();
|
||||||
switch(rarity){
|
switch(rarity){
|
||||||
case Constants::RARITY_M:
|
case Constants::RARITY_M:
|
||||||
@@ -76,13 +66,6 @@ int PriceList::getPrice(int cardId){
|
|||||||
}
|
}
|
||||||
|
|
||||||
int PriceList::setPrice(int cardId, int price){
|
int PriceList::setPrice(int cardId, int price){
|
||||||
for(int i = 0; i < nbprices; i++){
|
prices[cardId] = price;
|
||||||
if (prices[i]->cardid == cardId){
|
return price;
|
||||||
prices[i]->price = price;
|
|
||||||
return prices[i]->price;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
prices[nbprices] = NEW Price(cardId, price);
|
|
||||||
nbprices++;
|
|
||||||
return prices[nbprices-1]->price;
|
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user