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.

This commit is contained in:
omegablast2002@yahoo.com
2012-03-13 16:32:26 +00:00
parent 97bd418aac
commit 39e8bd1f30
6 changed files with 61 additions and 12 deletions
+1
View File
@@ -472,6 +472,7 @@ public:
void addAbilities(int _id, Spell * spell); void addAbilities(int _id, Spell * spell);
MTGAbility * parseUpkeepAbility(string s = "", MTGCardInstance * card = NULL, Spell * spell = NULL, int restrictions = 0, int id = -1); 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 * 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);
}; };
+5
View File
@@ -88,6 +88,9 @@ public:
bool graveEffects; bool graveEffects;
bool exileEffects; bool exileEffects;
bool suspended; bool suspended;
int chooseacolor;
string chooseasubtype;
int coinSide;//1 = tails
int stillInUse(); int stillInUse();
int didattacked; int didattacked;
@@ -104,6 +107,7 @@ public:
MTGCardInstance * previous; MTGCardInstance * previous;
MTGCardInstance * next; MTGCardInstance * next;
int doDamageTest; int doDamageTest;
bool skipDamageTestOnce;
int summoningSickness; int summoningSickness;
ManaCost reducedCost; ManaCost reducedCost;
ManaCost increasedCost; ManaCost increasedCost;
@@ -149,6 +153,7 @@ public:
int canBlock(MTGCardInstance * opponent); int canBlock(MTGCardInstance * opponent);
int canAttack(); int canAttack();
int isAttacker(); int isAttacker();
Targetable * isAttacking;
MTGCardInstance * isDefenser(); MTGCardInstance * isDefenser();
int initAttackersDefensers(); int initAttackersDefensers();
MTGCardInstance * getNextOpponent(MTGCardInstance * previous=NULL); MTGCardInstance * getNextOpponent(MTGCardInstance * previous=NULL);
+12
View File
@@ -146,6 +146,9 @@ public:
static const vector<string>& getValuesById() { static const vector<string>& getValuesById() {
return instance->subtypesList.getValuesById(); return instance->subtypesList.getValuesById();
}; };
static const vector<string>& getCreatureValuesById() {
return instance->subtypesList.getCreatureValuesById();
};
static bool isSubtypeOfType(unsigned int subtype, unsigned int type) { static bool isSubtypeOfType(unsigned int subtype, unsigned int type) {
return instance->subtypesList.isSubtypeOfType(subtype, type); return instance->subtypesList.isSubtypeOfType(subtype, type);
}; };
@@ -159,6 +162,15 @@ public:
return instance->subtypesList.isSubType(type); 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 loadInstance();
static void unloadAll(); static void unloadAll();
static inline MTGAllCards* getInstance() { return instance; }; static inline MTGAllCards* getInstance() { return instance; };
+4
View File
@@ -38,6 +38,7 @@ protected:
vector<string> valuesById; vector<string> valuesById;
vector<unsigned int> subtypesToType; vector<unsigned int> subtypesToType;
public: public:
vector<string> subtypesCreature;
Subtypes(); Subtypes();
int find(string subtype, bool forceAdd = true); int find(string subtype, bool forceAdd = true);
string find(unsigned int id); string find(unsigned int id);
@@ -45,8 +46,11 @@ public:
bool isSuperType(unsigned int type); bool isSuperType(unsigned int type);
bool isType(unsigned int type); bool isType(unsigned int type);
bool isSubType(unsigned int type); bool isSubType(unsigned int type);
void sortSubTypes();
int add(string value, unsigned int parentType); int add(string value, unsigned int parentType);
const vector<string>& getValuesById(); const vector<string>& getValuesById();
const vector<string>& getCreatureValuesById();
const map<string, int>& getValuesByMap();
}; };
#endif #endif
+19 -12
View File
@@ -107,6 +107,7 @@ int MTGCardInstance::init()
CardPrimitive::init(); CardPrimitive::init();
data = this; data = this;
X = 0; X = 0;
castX = 0;
return 1; return 1;
} }
@@ -117,6 +118,7 @@ void MTGCardInstance::initMTGCI()
isToken = false; isToken = false;
lifeOrig = 0; lifeOrig = 0;
doDamageTest = 1; doDamageTest = 1;
skipDamageTestOnce = false;
belongs_to = NULL; belongs_to = NULL;
tapped = 0; tapped = 0;
untapping = 0; untapping = 0;
@@ -150,7 +152,10 @@ void MTGCardInstance::initMTGCI()
mPropertiesChangedSinceLastUpdate = false; mPropertiesChangedSinceLastUpdate = false;
stillNeeded = true; stillNeeded = true;
kicked = 0; kicked = 0;
chooseacolor = -1;
chooseasubtype = "";
coinSide = -1;
isAttacking = NULL;
for (int i = 0; i < ManaCost::MANA_PAID_WITH_RETRACE +1; i++) for (int i = 0; i < ManaCost::MANA_PAID_WITH_RETRACE +1; i++)
alternateCostPaid[i] = 0; alternateCostPaid[i] = 0;
@@ -163,6 +168,7 @@ void MTGCardInstance::initMTGCI()
flanked = 0; flanked = 0;
target = NULL; target = NULL;
playerTarget = NULL; playerTarget = NULL;
playerTarget = NULL;
type_as_damageable = DAMAGEABLE_MTGCARDINSTANCE; type_as_damageable = DAMAGEABLE_MTGCARDINSTANCE;
banding = NULL; banding = NULL;
owner = NULL; owner = NULL;
@@ -177,16 +183,13 @@ void MTGCardInstance::initMTGCI()
cardsAbilities = vector<MTGAbility *>(); cardsAbilities = vector<MTGAbility *>();
data = this; //an MTGCardInstance point to itself for data, allows to update it without killing the underlying database item 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 {//if the card is a changeling, it gains all creature subtypes
const vector<string> values = MTGAllCards::getValuesById(); vector<string> values = MTGAllCards::getCreatureValuesById();
for (size_t i = 0; i < values.size(); ++i) for (size_t i = 0; i < values.size(); ++i)
{ {
if (!MTGAllCards::isSubtypeOfType(i,Subtypes::TYPE_CREATURE)) //Don' want to send any event to the gameObserver inside of initMCGI, so calling the parent setSubtype method instead of mine
continue; CardPrimitive::setSubtype(values[i].c_str());
//Don' want to send any event to the gameObserver inside of initMCGI, so calling the parent addType method instead of mine
CardPrimitive::addType(i);
} }
} }
@@ -292,6 +295,11 @@ int MTGCardInstance::isInPlay(GameObserver* game)
int MTGCardInstance::afterDamage() int MTGCardInstance::afterDamage()
{ {
if(skipDamageTestOnce)
{
skipDamageTestOnce = false;
return 0;
}
if (!doDamageTest) if (!doDamageTest)
return 0; return 0;
doDamageTest = 0; doDamageTest = 0;
@@ -520,9 +528,7 @@ int MTGCardInstance::hasSummoningSickness()
MTGCardInstance * MTGCardInstance::changeController(Player * newController) MTGCardInstance * MTGCardInstance::changeController(Player * newController)
{ {
Player * originalOwner = controller(); Player * originalOwner = controller();
if (originalOwner == newController) MTGCardInstance * copy = originalOwner->game->putInZone(this, this->currentZone, newController->game->inPlay);
return this;
MTGCardInstance * copy = originalOwner->game->putInZone(this, originalOwner->game->inPlay, newController->game->inPlay);
copy->summoningSickness = 1; copy->summoningSickness = 1;
return copy; return copy;
} }
@@ -738,6 +744,7 @@ int MTGCardInstance::toggleAttacker()
{ {
//untap(); //untap();
setAttacker(0); setAttacker(0);
isAttacking = NULL;
return 1; return 1;
} }
return 0; return 0;
@@ -1113,5 +1120,5 @@ std::ostream& operator<<(std::ostream& out, const MTGCardInstance& c)
MTGCardInstance* MTGCardInstance::clone() MTGCardInstance* MTGCardInstance::clone()
{ {
return new MTGCardInstance(model, owner->game); return NEW MTGCardInstance(model, owner->game);
} }
+20
View File
@@ -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.resize(1 + subtype * 2, 0); //multiplying by 2 to avoid resizing at every insertion
subtypesToType[subtype] = parentType; 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; return subtype;
} }
@@ -100,3 +105,18 @@ const vector<string>& Subtypes::getValuesById()
{ {
return valuesById; return valuesById;
} }
void Subtypes::sortSubTypes()
{
sort(subtypesCreature.begin(),subtypesCreature.end());
subtypesCreature.erase(unique(subtypesCreature.begin(),subtypesCreature.end()),subtypesCreature.end());
return;
}
const vector<string>& Subtypes::getCreatureValuesById()
{
sort(subtypesCreature.begin(),subtypesCreature.end());
subtypesCreature.erase(unique(subtypesCreature.begin(),subtypesCreature.end()),subtypesCreature.end());
return subtypesCreature;
}