- _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

View File

@@ -21,7 +21,7 @@ class GameApp;
class MTGCard;
#define MAX_SETS 30
#define MAX_SETS 50

View File

@@ -19,7 +19,7 @@ class MTGGameZone {
public:
Player * owner;
//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;
int nb_cards;
MTGGameZone();

View File

@@ -238,9 +238,9 @@ int MTGAllCards::totalCards(){
int MTGAllCards::readConfLine(std::ifstream &file, int set_id){
string s;
int result = 0;
if(std::getline(file,s)) result = 1;
if (!s.size()) return 0;
int result = 1;
if(!std::getline(file,s)) return 0;
if (!s.size()) return -1;
if (s[s.size()-1] == '\r') s.erase(s.size()-1); //Handle DOS files
switch(conf_read_mode) {
case 0:

View File

@@ -24,6 +24,7 @@ MTGPlayerCards::MTGPlayerCards(MTGAllCards * _collection, int * idList, int idLi
library->addCard(newCard);
}
}
}
@@ -43,7 +44,8 @@ void MTGPlayerCards::setOwner(Player * player){
void MTGPlayerCards::initGame(int shuffle, int draw){
if (shuffle) library->shuffle();
if (draw){
for (int i=0;i<7;i++){
for (int i=0;i<7;i++){
OutputDebugString("draw\n");
drawFromLibrary();
}
}
@@ -167,18 +169,19 @@ MTGCardInstance * MTGGameZone::removeCard(MTGCardInstance * card, int createCopy
cardsMap.erase(card);
for (i=0; i<(nb_cards); i++) {
if (cards[i] == card){
cards[i] = cards[nb_cards -1];
//cards[i] = cards[nb_cards -1];
nb_cards--;
MTGCardInstance * copy = card;
cards.erase(cards.begin()+i);
MTGCardInstance * copy = card;
if (card->isToken){ //TODO better than this ?
return card;
}
card->lastController = card->controller();
if (createCopy) {
copy = NEW MTGCardInstance(card->model,card->owner->game);
copy->previous = card;
card->next = copy;
}
copy = NEW MTGCardInstance(card->model,card->owner->game);
copy->previous = card;
card->next = copy;
}
copy->previousZone = this;
return copy;
}
@@ -232,7 +235,7 @@ void MTGGameZone::shuffle(){
void MTGGameZone::addCard(MTGCardInstance * card){
if (!card) return;
cards[nb_cards] = card;
cards.push_back(card);
nb_cards++;
cardsMap[card] = 1;
@@ -242,8 +245,9 @@ MTGCardInstance * MTGGameZone::draw(){
if (!nb_cards) return NULL;
nb_cards--;
lastCardDrawn = cards[nb_cards];
cardsMap.erase(cards[nb_cards]);
return cards[nb_cards];
cards.pop_back();
cardsMap.erase( lastCardDrawn);
return lastCardDrawn;
}
MTGCardInstance * MTGLibrary::draw(){