- fixed card id collisions in Legends, Ravnica, Portal
- Changed Deck and Database structures with better design (a bit faster, hopefully a lot cleaner)
- updated Windows project file
This commit is contained in:
wagic.the.homebrew@gmail.com
2009-06-06 04:46:54 +00:00
parent 01bd44025d
commit ab42e5db06
13 changed files with 166 additions and 145 deletions

View File

@@ -73,7 +73,7 @@ toughness=2
[/card]
[card]
text=Legendary
id=1516
id=1647
name=Barktooth Warbeard
color=Black,Red
rarity=U
@@ -138,7 +138,7 @@ toughness=1
[/card]
[card]
text=Forestwalk
id=1516
id=1517
name=Cat Warriors
color=Green
rarity=C
@@ -559,7 +559,7 @@ type=Enchantment
[/card]
[card]
text=Rampage 1 (Whenever this creature becomes blocked, it gets +1/+1 until end of turn for each creature blocking it beyond the first.)
id=1653
id=1657
auto=rampage(1/1,1)
name=Hunding Gjornersen
color=White,Blue
@@ -778,7 +778,7 @@ toughness=2
[/card]
[card]
text=Legendary {T}: Lady Caleria deals 3 damage to target attacking or blocking creature.
id=5771
id=1665
name=Lady Caleria
color=White,Green
rarity=R

View File

@@ -119,7 +119,7 @@ abilities=swampwalk
[/card]
[card]
text={B}{T}, Discard a card: Add {B}{B}{B} to your mana pool.
id=21332
id=19578
name=Bog Witch
color=Black
rarity=C
@@ -1171,7 +1171,7 @@ subtype=Swamp
[card]
text={T}: Add {B} to your mana pool.
auto={T}: Add {B}
id=20888
id=20889
name=Swamp
rarity=L
color=Land

View File

@@ -745,18 +745,6 @@ toughness=1
abilities=flying
[/card]
[card]
text=Flying
id=4306
name=Moon Sprite
rarity=U
mana={1}{G}
type=Creature
subtype=Faerie
power=1
toughness=1
abilities=flying
[/card]
[card]
text={T}: Add {R} to your mana pool.
auto={T}: Add {R}
id=4420
@@ -806,18 +794,6 @@ power=1
toughness=1
[/card]
[card]
text=Mountainwalk
id=4352
name=Mountain Goat
rarity=U
mana={R}
type=Creature
subtype=Goat
power=1
toughness=1
abilities=mountainwalk
[/card]
[card]
text=Counter target creature or sorcery spell.
target=creature,sorcery|stack
auto=fizzle
@@ -937,18 +913,6 @@ type=Basic Land
subtype=Plains
[/card]
[card]
text=Phantom Warrior is unblockable.
id=4272
name=Phantom Warrior
rarity=R
mana={1}{U}{U}
type=Creature
subtype=Illusion Warrior
power=2
toughness=2
abilities=unblockable
[/card]
[card]
text=Pyroclasm deals 2 damage to each creature.
id=4354
alias=2650
@@ -1045,7 +1009,7 @@ power=2
toughness=3
[/card]
[card]
id=4315
id=4316
name=Rowan Treefolk
rarity=C
mana={3}{G}

View File

@@ -851,7 +851,7 @@ subtype=Swamp
[/card]
[card]
text=Flying {B}: Regenerate Tattered Drake.
id=87986
id=87930
name=Tattered Drake
color=Blue
rarity=C

View File

@@ -32,11 +32,11 @@ class DeckDataWrapper{
DeckDataWrapper(MTGDeck * deck);
~DeckDataWrapper();
int Add(MTGCard * card);
int Add(MTGCard * card, int quantity = 1);
int Remove(MTGCard * card);
MTGCard * getNext(MTGCard * previous = NULL, int color = -1);
MTGCard * getPrevious(MTGCard * next = NULL, int color = -1);
void updateCounts(MTGCard * card = NULL, int removed = 0);
void updateCounts(MTGCard * card = NULL, int quantity = 1);
int getCount(int color = -1);
int totalPrice();
void save();

View File

@@ -42,6 +42,8 @@ class MtgSets{
class MTGAllCards {
private:
MTGCard * tempCard;
protected:
int conf_read_mode;
int colorsCount[Constants::MTG_NB_COLORS];
@@ -52,12 +54,12 @@ class MTGAllCards {
public:
TexturesCache * mCache;
MTGCard * _(int i);
vector<MTGCard *> collection;
//collection[Constants::TOTAL_NUMBER_OF_CARDS];
vector<int> ids;
map<int, MTGCard *> collection;
MTGAllCards();
~MTGAllCards();
MTGAllCards(TexturesCache * cache);
MTGCard * _(int id);
void destroyAllCards();
MTGAllCards(const char * config_file, const char * set_name);
MTGAllCards(const char * config_file, const char * set_name, TexturesCache * cache);
@@ -75,22 +77,31 @@ class MTGAllCards {
};
class MTGDeck:public MTGAllCards{
class MTGDeck{
protected:
string filename;
MTGAllCards * allcards;
int total_cards;
public:
TexturesCache * mCache;
MTGAllCards * database;
map <int,int> cards;
string meta_desc;
string meta_name;
int totalCards();
MTGDeck(TexturesCache * cache, MTGAllCards * _allcards);
MTGDeck(const char * config_file, TexturesCache * cache, MTGAllCards * _allcards, int meta_only = 0);
int addRandomCards(int howmany, int setId = -1, int rarity = -1, const char * subtype = NULL);
int add(int cardid);
int add(MTGDeck * deck); // adds the contents of "deck" into myself
int remove(int cardid);
int removeAll();
int add(MTGCard * card);
int remove(MTGCard * card);
int save();
MTGCard * getCardById(int id);
};

View File

@@ -8,10 +8,10 @@ DeckDataWrapper::DeckDataWrapper(MTGDeck * deck){
for (int i = 0; i <= Constants::MTG_NB_COLORS; i++){
colors[i] = 0;
}
for (int i = 0; i < deck->totalCards(); i++){
MTGCard * card = deck->_(i);
Add(card);
map<int,int>::iterator it;
for (it = deck->cards.begin(); it!=deck->cards.end(); it++){
MTGCard * card = deck->getCardById(it->first);
Add(card,it->second);
}
currentColor = -1;
}
@@ -33,7 +33,7 @@ DeckDataWrapper::~DeckDataWrapper(){
SAFE_DELETE(parent);
}
void DeckDataWrapper::updateCounts(MTGCard * card, int removed){
void DeckDataWrapper::updateCounts(MTGCard * card, int increment){
if (!card){
for (int i = 0; i < Constants::MTG_NB_COLORS+1; i++){
colors[i] = 0;
@@ -47,8 +47,6 @@ void DeckDataWrapper::updateCounts(MTGCard * card, int removed){
}
}
}else{
int increment = 1;
if (removed) increment = -1;
colors[Constants::MTG_NB_COLORS] += increment;
for (int i = 0; i < Constants::MTG_NB_COLORS; i++){
if (card->hasColor(i)) colors[i]+=increment;
@@ -56,20 +54,20 @@ void DeckDataWrapper::updateCounts(MTGCard * card, int removed){
}
}
int DeckDataWrapper::Add(MTGCard * card){
int DeckDataWrapper::Add(MTGCard * card, int quantity){
if(cards.find(card) == cards.end()){
cards[card] = 1;
cards[card] = quantity;
}else{
cards[card]++;
cards[card]+= quantity;
}
updateCounts(card);
updateCounts(card,quantity);
return cards[card];
}
int DeckDataWrapper::Remove(MTGCard * card){
if(cards.find(card) == cards.end() || cards[card] == 0) return 0;
if(cards.find(card) == cards.end() || cards[card] <= 0) return 0;
cards[card]--;
updateCounts(card,1);
updateCounts(card,-1);
return 1;
}
@@ -165,7 +163,7 @@ int DeckDataWrapper::getCount(int color){
int DeckDataWrapper::totalPrice(){
int total = 0;
PriceList * pricelist = NEW PriceList(RESPATH"/settings/prices.dat",this->parent);
PriceList * pricelist = NEW PriceList(RESPATH"/settings/prices.dat",this->parent->database);
map<MTGCard *,int,Cmp1>::iterator it;
for ( it=cards.begin() ; it != cards.end(); it++ ){
MTGCard * current = (*it).first;

View File

@@ -222,7 +222,7 @@ void GameStateMenu::fillScroller(){
scroller->Add(buff2);
}
delete ddw;
PlayerData * playerdata = NEW PlayerData(mParent->collection);
sprintf(buff2, "You currently have %i credits",playerdata->credits);
delete playerdata;

View File

@@ -304,3 +304,4 @@ void MTGCard::setToughness(int _toughness){
int MTGCard::getToughness(){
return toughness;
}

View File

@@ -153,6 +153,7 @@ void MTGAllCards::initCounters(){
}
void MTGAllCards::init(){
tempCard = NULL;
mCache = NULL;
total_cards = 0;
initCounters();
@@ -179,12 +180,16 @@ MTGAllCards::MTGAllCards(){
}
MTGAllCards::~MTGAllCards(){
//Why don't we call destroyAllCards from here ???
}
void MTGAllCards::destroyAllCards(){
for (int i= 0; i < total_cards; i++){
SAFE_DELETE(collection[i]);
};
map<int,MTGCard *>::iterator it;
for (it = collection.begin(); it!=collection.end(); it++) delete(it->second);
collection.clear();
ids.clear();
}
@@ -204,23 +209,21 @@ MTGAllCards::MTGAllCards(const char * config_file, const char * set_name, Textur
}
MTGCard * MTGAllCards::_(int i){
if (i < total_cards) return collection[i];
return NULL;
}
int MTGAllCards::randomCardId(){
int id = (rand() % total_cards);
return collection[id]->getMTGId();
int id = (rand() % ids.size());
return ids[id];
}
int MTGAllCards::countBySet(int setId){
int result = 0;
for (int i=0; i< total_cards; i++){
if(collection[i]->setId == setId){
map<int,MTGCard *>::iterator it;
for (it = collection.begin(); it!=collection.end(); it++){
MTGCard * c = it->second;
if( c->setId == setId){
result++;
}
}
@@ -230,8 +233,10 @@ int MTGAllCards::countBySet(int setId){
//TODO more efficient way ?
int MTGAllCards::countByType(const char * _type){
int result = 0;
for (int i=0; i< total_cards; i++){
if(collection[i]->hasType(_type)){
map<int,MTGCard *>::iterator it;
for (it = collection.begin(); it!=collection.end(); it++){
MTGCard * c = it->second;
if(c->hasType(_type)){
result++;
}
}
@@ -244,8 +249,10 @@ int MTGAllCards::countByColor(int color){
for (int i=0; i< Constants::MTG_NB_COLORS; i++){
colorsCount[i] = 0;
}
for (int i=0; i< total_cards; i++){
int j = collection[i]->getColor();
map<int,MTGCard *>::iterator it;
for (it = collection.begin(); it!=collection.end(); it++){
MTGCard * c = it->second;
int j = c->getColor();
colorsCount[j]++;
}
@@ -268,16 +275,26 @@ int MTGAllCards::readConfLine(std::ifstream &file, int set_id){
switch(conf_read_mode) {
case 0:
if (s[0] == '['){
collection.push_back(NEW MTGCard(mCache,set_id));
tempCard = NEW MTGCard(mCache,set_id);
conf_read_mode = 1;
}
break;
case 1:
if (s[0] == '[' && s[1] == '/'){
conf_read_mode = 0;
total_cards++;
int newId = tempCard->getId();
if (collection.find(newId) != collection.end()){
char outBuf[4096];
sprintf(outBuf,"warning, card id collision! : %i - %s\n", newId, tempCard->name.c_str());
OutputDebugString (outBuf);
delete tempCard;
}else{
ids.push_back(newId);
collection[newId] = tempCard;
total_cards++;
}
}else{
processConfLine(s, collection[total_cards]);
processConfLine(s, tempCard);
}
break;
default:
@@ -292,16 +309,18 @@ int MTGAllCards::readConfLine(std::ifstream &file, int set_id){
MTGCard * MTGAllCards::getCardById(int id){
int i;
for (i=0; i<total_cards; i++){
int cardId = collection[i]->getMTGId();
if (cardId == id){
return collection[i];
}
map<int, MTGCard *>::iterator it = collection.find(id);
if ( it != collection.end()){
return (it->second);
}
return 0;
}
MTGCard * MTGAllCards::_(int index){
if (index >= total_cards) return NULL;
return getCardById(ids[index]);
}
MTGCard * MTGAllCards::getCardByName(string name){
if (!name.size()) return NULL;
if (name[0] == '#') return NULL;
@@ -314,11 +333,13 @@ MTGCard * MTGAllCards::getCardByName(string name){
name = name.substr(0,found);
setId = MtgSets::SetsList->find(setName);
}
for (int i=0; i<total_cards; i++){
if (setId!=-1 && setId != collection[i]->setId) continue;
string cardName = collection[i]->name;
map<int,MTGCard *>::iterator it;
for (it = collection.begin(); it!=collection.end(); it++){
MTGCard * c = it->second;
if (setId!=-1 && setId != c->setId) continue;
string cardName = c->name;
std::transform(cardName.begin(), cardName.end(), cardName.begin(),::tolower );
if (cardName.compare(name) == 0) return collection[i];
if (cardName.compare(name) == 0) return c;
}
return NULL;
@@ -326,11 +347,16 @@ MTGCard * MTGAllCards::getCardByName(string name){
MTGDeck::MTGDeck(TexturesCache * cache, MTGAllCards * _allcards){
mCache = cache;
total_cards = 0;
database = _allcards;
}
MTGDeck::MTGDeck(const char * config_file, TexturesCache * cache, MTGAllCards * _allcards, int meta_only){
mCache = cache;
total_cards = 0;
allcards = _allcards;
database = _allcards;
filename = config_file;
size_t slash = filename.find_last_of("/");
size_t dot = filename.find(".");
@@ -368,7 +394,7 @@ MTGDeck::MTGDeck(const char * config_file, TexturesCache * cache, MTGAllCards *
s=s.substr(0,found);
OutputDebugString(s.c_str());
}
MTGCard * card = allcards->getCardByName(s);
MTGCard * card = database->getCardByName(s);
if (card){
for (int i = 0; i < nb; i++){
add(card);
@@ -384,15 +410,20 @@ MTGDeck::MTGDeck(const char * config_file, TexturesCache * cache, MTGAllCards *
}
int MTGDeck::totalCards(){
return total_cards;
}
MTGCard * MTGDeck::getCardById(int mtgId){
return database->getCardById(mtgId);
}
int MTGDeck::addRandomCards(int howmany, int setId, int rarity, const char * _subtype){
int collectionTotal = allcards->totalCards();
int collectionTotal = database->totalCards();
if (!collectionTotal) return 0;
if (setId == -1 && rarity == -1 && !_subtype){
for (int i = 0; i < howmany; i++){
int id = (rand() % collectionTotal);
add(allcards->_(id));
add(database->randomCardId());
}
return 1;
}
@@ -404,60 +435,69 @@ int MTGDeck::addRandomCards(int howmany, int setId, int rarity, const char * _su
vector<int> subcollection;
int subtotal = 0;
for (int i = 0; i < collectionTotal; i++){
MTGCard * card = allcards->_(i);
MTGCard * card = database->_(i);
if ((setId == -1 || card->setId == setId) &&
(rarity == -1 || card->getRarity()==rarity) &&
(!_subtype || card->hasSubtype(subtype))
){
subcollection.push_back(i);
subcollection.push_back(card->getId());
subtotal++;
}
}
if (subtotal == 0) return 0;
for (int i = 0; i < howmany; i++){
int id = (rand() % subtotal);
add(allcards->_(subcollection[id]));
add(subcollection[id]);
}
return 1;
}
int MTGDeck::add(MTGDeck * deck){
map<int,int>::iterator it;
for (it = deck->cards.begin(); it!=deck->cards.end(); it++){
for (int i = 0; i < it->second; i++){
add(it->first);
}
}
return deck->totalCards();
}
int MTGDeck::add(int cardid){
MTGCard * card = allcards->getCardById(cardid);
add(card);
if (!database->getCardById(cardid)) return 0;
if(cards.find(cardid) == cards.end()){
cards[cardid] = 1;
}else{
cards[cardid]++;
}
++total_cards;
//initCounters();
return total_cards;
}
int MTGDeck::add(MTGCard * card){
if (!card) return 0;
collection.push_back(card);
++total_cards;
initCounters();
return total_cards;
return (add(card->getId()));
}
int MTGDeck::removeAll(){
total_cards = 0;
collection.clear();
initCounters();
cards.clear();
//initCounters();
return 1;
}
int MTGDeck::remove(int cardid){
MTGCard * card = getCardById(cardid);
return remove(card);
if(cards.find(cardid) == cards.end() || cards[cardid] == 0) return 0;
cards[cardid]--;
total_cards--;
//initCounters();
return 1;
}
int MTGDeck::remove(MTGCard * card){
for (int i = 0; i<total_cards; i++){
if (collection[i] == card){
collection.erase(collection.begin()+i);
total_cards--;
initCounters();
return 1;
}
}
return 0;
if (!card) return 0;
return (remove(card->getId()));
}
int MTGDeck::save(){
@@ -467,9 +507,12 @@ int MTGDeck::save(){
#if defined (WIN32) || defined (LINUX)
OutputDebugString("saving");
#endif
for (int i = 0; i<total_cards; i++){
sprintf(writer,"%i\n", collection[i]->getMTGId());
file<<writer;
map<int,int>::iterator it;
for (it = cards.begin(); it!=cards.end(); it++){
sprintf(writer,"%i\n", it->first);
for (int j = 0; j<it->second; j++){
file<<writer;
}
}
file.close();
}

View File

@@ -35,16 +35,16 @@ MTGPlayerCards::MTGPlayerCards(MTGAllCards * _collection, int * idList, int idLi
MTGPlayerCards::MTGPlayerCards(MTGAllCards * _collection,MTGDeck * deck){
init();
collection = _collection;
for (int i=0; i<deck->totalCards(); i++){
MTGCard * card = deck->collection[i];
map<int,int>::iterator it;
for (it = deck->cards.begin(); it!=deck->cards.end(); it++){
MTGCard * card = deck->getCardById(it->first);
if (card){
MTGCardInstance * newCard = NEW MTGCardInstance(card, this);
library->addCard(newCard);
for (int i = 0; i < it->second; i++){
MTGCardInstance * newCard = NEW MTGCardInstance(card, this);
library->addCard(newCard);
}
}
}
}
MTGPlayerCards::~MTGPlayerCards(){

View File

@@ -251,17 +251,25 @@ void ShopItems::ButtonPressed(int controllerId, int controlId){
safeDeleteDisplay();
display = NEW CardDisplay(12,NULL, SCREEN_WIDTH - 200, SCREEN_HEIGHT/2,this,NULL,5);
int curNbcards = playerdata->collection->totalCards();
MTGDeck * tempDeck = NEW MTGDeck(NULL,playerdata->collection->database);
playerdata->collection->addRandomCards(1, setIds[showPriceDialog],Constants::RARITY_R);
playerdata->collection->addRandomCards(3, setIds[showPriceDialog],Constants::RARITY_U);
playerdata->collection->addRandomCards(11, setIds[showPriceDialog],Constants::RARITY_C);
tempDeck->addRandomCards(1, setIds[showPriceDialog],Constants::RARITY_R);
tempDeck->addRandomCards(3, setIds[showPriceDialog],Constants::RARITY_U);
tempDeck->addRandomCards(11, setIds[showPriceDialog],Constants::RARITY_C);
playerdata->collection->add(tempDeck);
int newNbCards = playerdata->collection->totalCards();;
for (int i = curNbcards; i < newNbCards ; i++){
MTGCardInstance * card = NEW MTGCardInstance(playerdata->collection->_(i), NULL);
displayCards[i-curNbcards] = card;
display->AddCard(card);
}
int i = 0;
for (map<int,int>::iterator it = tempDeck->cards.begin(); it!=tempDeck->cards.end(); it++){
MTGCard * c = tempDeck->getCardById(it->first);
for (int j = 0; j < it->second; j++){
MTGCardInstance * card = NEW MTGCardInstance(c, NULL);
displayCards[i] = card;
display->AddCard(card);
i++;
}
}
delete tempDeck;
}
//Remove(showPriceDialog);
showPriceDialog = -1;

View File

@@ -252,10 +252,6 @@
RelativePath=".\src\CardDisplay.cpp"
>
</File>
<File
RelativePath=".\src\CardEffect.cpp"
>
</File>
<File
RelativePath=".\src\CardGui.cpp"
>