From 39e8bd1f30c3bf728ba211a1693381e36d18a776 Mon Sep 17 00:00:00 2001 From: "omegablast2002@yahoo.com" Date: Tue, 13 Mar 2012 16:32:26 +0000 Subject: [PATCH] in this commit i added a creature subtype specific vector, added a couple variables for new abilities, and a sort for the creature variable to avoid the long lag out everytime we play a card or ability that needs this vector. --- projects/mtg/include/MTGAbility.h | 1 + projects/mtg/include/MTGCardInstance.h | 5 +++++ projects/mtg/include/MTGDeck.h | 12 ++++++++++ projects/mtg/include/Subtypes.h | 4 ++++ projects/mtg/src/MTGCardInstance.cpp | 31 ++++++++++++++++---------- projects/mtg/src/Subtypes.cpp | 20 +++++++++++++++++ 6 files changed, 61 insertions(+), 12 deletions(-) diff --git a/projects/mtg/include/MTGAbility.h b/projects/mtg/include/MTGAbility.h index b93e4bb6c..33c91539b 100644 --- a/projects/mtg/include/MTGAbility.h +++ b/projects/mtg/include/MTGAbility.h @@ -472,6 +472,7 @@ public: void addAbilities(int _id, Spell * spell); MTGAbility * parseUpkeepAbility(string s = "", MTGCardInstance * card = NULL, Spell * spell = NULL, int restrictions = 0, int id = -1); MTGAbility * parsePhaseActionAbility(string s = "", MTGCardInstance * card = NULL, Spell * spell = NULL,MTGCardInstance * target = NULL, int restrictions = 0, int id = -1); + MTGAbility * parseChooseActionAbility(string s = "", MTGCardInstance * card = NULL, Spell * spell = NULL,MTGCardInstance * target = NULL, int restrictions = 0, int id = -1); }; diff --git a/projects/mtg/include/MTGCardInstance.h b/projects/mtg/include/MTGCardInstance.h index 31c1d5a34..c2c36a3eb 100644 --- a/projects/mtg/include/MTGCardInstance.h +++ b/projects/mtg/include/MTGCardInstance.h @@ -88,6 +88,9 @@ public: bool graveEffects; bool exileEffects; bool suspended; + int chooseacolor; + string chooseasubtype; + int coinSide;//1 = tails int stillInUse(); int didattacked; @@ -104,6 +107,7 @@ public: MTGCardInstance * previous; MTGCardInstance * next; int doDamageTest; + bool skipDamageTestOnce; int summoningSickness; ManaCost reducedCost; ManaCost increasedCost; @@ -149,6 +153,7 @@ public: int canBlock(MTGCardInstance * opponent); int canAttack(); int isAttacker(); + Targetable * isAttacking; MTGCardInstance * isDefenser(); int initAttackersDefensers(); MTGCardInstance * getNextOpponent(MTGCardInstance * previous=NULL); diff --git a/projects/mtg/include/MTGDeck.h b/projects/mtg/include/MTGDeck.h index 4318cf560..a21e44795 100644 --- a/projects/mtg/include/MTGDeck.h +++ b/projects/mtg/include/MTGDeck.h @@ -146,6 +146,9 @@ public: static const vector& getValuesById() { return instance->subtypesList.getValuesById(); }; + static const vector& getCreatureValuesById() { + return instance->subtypesList.getCreatureValuesById(); + }; static bool isSubtypeOfType(unsigned int subtype, unsigned int type) { return instance->subtypesList.isSubtypeOfType(subtype, type); }; @@ -159,6 +162,15 @@ public: return instance->subtypesList.isSubType(type); }; + static void sortSubtypeList() + { + return instance->subtypesList.sortSubTypes(); + } + + static int findSubtypeId(string value){ + return instance->subtypesList.find(value,false); + } + static void loadInstance(); static void unloadAll(); static inline MTGAllCards* getInstance() { return instance; }; diff --git a/projects/mtg/include/Subtypes.h b/projects/mtg/include/Subtypes.h index e61923977..227ef7a50 100644 --- a/projects/mtg/include/Subtypes.h +++ b/projects/mtg/include/Subtypes.h @@ -38,6 +38,7 @@ protected: vector valuesById; vector subtypesToType; public: + vector subtypesCreature; Subtypes(); int find(string subtype, bool forceAdd = true); string find(unsigned int id); @@ -45,8 +46,11 @@ public: bool isSuperType(unsigned int type); bool isType(unsigned int type); bool isSubType(unsigned int type); + void sortSubTypes(); int add(string value, unsigned int parentType); const vector& getValuesById(); + const vector& getCreatureValuesById(); + const map& getValuesByMap(); }; #endif diff --git a/projects/mtg/src/MTGCardInstance.cpp b/projects/mtg/src/MTGCardInstance.cpp index b36f5de50..781dd681a 100644 --- a/projects/mtg/src/MTGCardInstance.cpp +++ b/projects/mtg/src/MTGCardInstance.cpp @@ -107,6 +107,7 @@ int MTGCardInstance::init() CardPrimitive::init(); data = this; X = 0; + castX = 0; return 1; } @@ -117,6 +118,7 @@ void MTGCardInstance::initMTGCI() isToken = false; lifeOrig = 0; doDamageTest = 1; + skipDamageTestOnce = false; belongs_to = NULL; tapped = 0; untapping = 0; @@ -150,7 +152,10 @@ void MTGCardInstance::initMTGCI() mPropertiesChangedSinceLastUpdate = false; stillNeeded = true; kicked = 0; - + chooseacolor = -1; + chooseasubtype = ""; + coinSide = -1; + isAttacking = NULL; for (int i = 0; i < ManaCost::MANA_PAID_WITH_RETRACE +1; i++) alternateCostPaid[i] = 0; @@ -163,6 +168,7 @@ void MTGCardInstance::initMTGCI() flanked = 0; target = NULL; playerTarget = NULL; + playerTarget = NULL; type_as_damageable = DAMAGEABLE_MTGCARDINSTANCE; banding = NULL; owner = NULL; @@ -177,16 +183,13 @@ void MTGCardInstance::initMTGCI() cardsAbilities = vector(); data = this; //an MTGCardInstance point to itself for data, allows to update it without killing the underlying database item - if (basicAbilities[(int)Constants::CHANGELING]) + if (observer && basicAbilities[(int)Constants::CHANGELING]) {//if the card is a changeling, it gains all creature subtypes - const vector values = MTGAllCards::getValuesById(); + vector values = MTGAllCards::getCreatureValuesById(); for (size_t i = 0; i < values.size(); ++i) { - if (!MTGAllCards::isSubtypeOfType(i,Subtypes::TYPE_CREATURE)) - continue; - - //Don' want to send any event to the gameObserver inside of initMCGI, so calling the parent addType method instead of mine - CardPrimitive::addType(i); + //Don' want to send any event to the gameObserver inside of initMCGI, so calling the parent setSubtype method instead of mine + CardPrimitive::setSubtype(values[i].c_str()); } } @@ -292,6 +295,11 @@ int MTGCardInstance::isInPlay(GameObserver* game) int MTGCardInstance::afterDamage() { + if(skipDamageTestOnce) + { + skipDamageTestOnce = false; + return 0; + } if (!doDamageTest) return 0; doDamageTest = 0; @@ -520,9 +528,7 @@ int MTGCardInstance::hasSummoningSickness() MTGCardInstance * MTGCardInstance::changeController(Player * newController) { Player * originalOwner = controller(); - if (originalOwner == newController) - return this; - MTGCardInstance * copy = originalOwner->game->putInZone(this, originalOwner->game->inPlay, newController->game->inPlay); + MTGCardInstance * copy = originalOwner->game->putInZone(this, this->currentZone, newController->game->inPlay); copy->summoningSickness = 1; return copy; } @@ -738,6 +744,7 @@ int MTGCardInstance::toggleAttacker() { //untap(); setAttacker(0); + isAttacking = NULL; return 1; } return 0; @@ -1113,5 +1120,5 @@ std::ostream& operator<<(std::ostream& out, const MTGCardInstance& c) MTGCardInstance* MTGCardInstance::clone() { - return new MTGCardInstance(model, owner->game); + return NEW MTGCardInstance(model, owner->game); } diff --git a/projects/mtg/src/Subtypes.cpp b/projects/mtg/src/Subtypes.cpp index f319c9f10..c8a9d170e 100644 --- a/projects/mtg/src/Subtypes.cpp +++ b/projects/mtg/src/Subtypes.cpp @@ -52,6 +52,11 @@ int Subtypes::add(string value, unsigned int parentType) subtypesToType.resize(1 + subtype * 2, 0); //multiplying by 2 to avoid resizing at every insertion subtypesToType[subtype] = parentType; } + if (isSubType(subtype) && (parentType == TYPE_CREATURE)) + { + if(value != "forest" && value != "Forest")//http://gatherer.wizards.com/Pages/Card/Details.aspx?multiverseid=136196 one creature with a land subtype exist, but the card has special ruling. + subtypesCreature.push_back(value); + } return subtype; } @@ -100,3 +105,18 @@ const vector& Subtypes::getValuesById() { return valuesById; } + +void Subtypes::sortSubTypes() +{ + sort(subtypesCreature.begin(),subtypesCreature.end()); + subtypesCreature.erase(unique(subtypesCreature.begin(),subtypesCreature.end()),subtypesCreature.end()); + return; +} + +const vector& Subtypes::getCreatureValuesById() +{ + sort(subtypesCreature.begin(),subtypesCreature.end()); + subtypesCreature.erase(unique(subtypesCreature.begin(),subtypesCreature.end()),subtypesCreature.end()); + return subtypesCreature; +} +