- _cards.dat parsing error fixes on erroneous files
- replaced cards array with a vector for MTGGameZones
This commit is contained in:
wagic.the.homebrew@gmail.com
2009-03-25 13:53:19 +00:00
parent 579c9e7d6f
commit e8d32b2c6d
4 changed files with 19 additions and 15 deletions
+1 -1
View File
@@ -21,7 +21,7 @@ class GameApp;
class MTGCard; class MTGCard;
#define MAX_SETS 30 #define MAX_SETS 50
+1 -1
View File
@@ -19,7 +19,7 @@ class MTGGameZone {
public: public:
Player * owner; Player * owner;
//Both cards and cardsMap contain the cards of a zone. The long term objective is to get rid of the array //Both cards and cardsMap contain the cards of a zone. The long term objective is to get rid of the array
MTGCardInstance * cards[MTG_MAX_PLAYER_CARDS]; vector<MTGCardInstance *> cards; //[MTG_MAX_PLAYER_CARDS];
map<MTGCardInstance *,int> cardsMap; map<MTGCardInstance *,int> cardsMap;
int nb_cards; int nb_cards;
MTGGameZone(); MTGGameZone();
+3 -3
View File
@@ -238,9 +238,9 @@ int MTGAllCards::totalCards(){
int MTGAllCards::readConfLine(std::ifstream &file, int set_id){ int MTGAllCards::readConfLine(std::ifstream &file, int set_id){
string s; string s;
int result = 0; int result = 1;
if(std::getline(file,s)) result = 1; if(!std::getline(file,s)) return 0;
if (!s.size()) return 0; if (!s.size()) return -1;
if (s[s.size()-1] == '\r') s.erase(s.size()-1); //Handle DOS files if (s[s.size()-1] == '\r') s.erase(s.size()-1); //Handle DOS files
switch(conf_read_mode) { switch(conf_read_mode) {
case 0: case 0:
+8 -4
View File
@@ -26,6 +26,7 @@ MTGPlayerCards::MTGPlayerCards(MTGAllCards * _collection, int * idList, int idLi
} }
} }
MTGPlayerCards::~MTGPlayerCards(){ MTGPlayerCards::~MTGPlayerCards(){
@@ -44,6 +45,7 @@ void MTGPlayerCards::initGame(int shuffle, int draw){
if (shuffle) library->shuffle(); if (shuffle) library->shuffle();
if (draw){ if (draw){
for (int i=0;i<7;i++){ for (int i=0;i<7;i++){
OutputDebugString("draw\n");
drawFromLibrary(); drawFromLibrary();
} }
} }
@@ -167,8 +169,9 @@ MTGCardInstance * MTGGameZone::removeCard(MTGCardInstance * card, int createCopy
cardsMap.erase(card); cardsMap.erase(card);
for (i=0; i<(nb_cards); i++) { for (i=0; i<(nb_cards); i++) {
if (cards[i] == card){ if (cards[i] == card){
cards[i] = cards[nb_cards -1]; //cards[i] = cards[nb_cards -1];
nb_cards--; nb_cards--;
cards.erase(cards.begin()+i);
MTGCardInstance * copy = card; MTGCardInstance * copy = card;
if (card->isToken){ //TODO better than this ? if (card->isToken){ //TODO better than this ?
return card; return card;
@@ -232,7 +235,7 @@ void MTGGameZone::shuffle(){
void MTGGameZone::addCard(MTGCardInstance * card){ void MTGGameZone::addCard(MTGCardInstance * card){
if (!card) return; if (!card) return;
cards[nb_cards] = card; cards.push_back(card);
nb_cards++; nb_cards++;
cardsMap[card] = 1; cardsMap[card] = 1;
@@ -242,8 +245,9 @@ MTGCardInstance * MTGGameZone::draw(){
if (!nb_cards) return NULL; if (!nb_cards) return NULL;
nb_cards--; nb_cards--;
lastCardDrawn = cards[nb_cards]; lastCardDrawn = cards[nb_cards];
cardsMap.erase(cards[nb_cards]); cards.pop_back();
return cards[nb_cards]; cardsMap.erase( lastCardDrawn);
return lastCardDrawn;
} }
MTGCardInstance * MTGLibrary::draw(){ MTGCardInstance * MTGLibrary::draw(){