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

View File

@@ -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);
};

View File

@@ -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);

View File

@@ -146,6 +146,9 @@ public:
static const vector<string>& getValuesById() {
return instance->subtypesList.getValuesById();
};
static const vector<string>& 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; };

View File

@@ -38,6 +38,7 @@ protected:
vector<string> valuesById;
vector<unsigned int> subtypesToType;
public:
vector<string> 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<string>& getValuesById();
const vector<string>& getCreatureValuesById();
const map<string, int>& getValuesByMap();
};
#endif

View File

@@ -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<MTGAbility *>();
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<string> values = MTGAllCards::getValuesById();
vector<string> 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);
}

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[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<string>& Subtypes::getValuesById()
{
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;
}