Converted CardPrimitive's basicAbilities from a map<int, int> to a bitset. With 92 abilities, that means our base container for abilities is now 16 bytes in size (down from 28), and is a fixed size, whereas the map would grow by 8 bytes per added ability.
This commit is contained in:
@@ -1311,12 +1311,12 @@ public:
|
|||||||
modifier : 1 to add the ability, 0 to remove it
|
modifier : 1 to add the ability, 0 to remove it
|
||||||
_ability : Id of the ability, as described in mtgdefinitions
|
_ability : Id of the ability, as described in mtgdefinitions
|
||||||
*/
|
*/
|
||||||
class ABasicAbilityModifier: public MTGAbility
|
class ABasicAbilityModifier : public MTGAbility
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
int modifier;
|
int modifier;
|
||||||
int ability;
|
int ability;
|
||||||
int value_before_modification;
|
bool value_before_modification;
|
||||||
ABasicAbilityModifier(int _id, MTGCardInstance * _source, MTGCardInstance * _target, int _ability, int _modifier = 1) :
|
ABasicAbilityModifier(int _id, MTGCardInstance * _source, MTGCardInstance * _target, int _ability, int _modifier = 1) :
|
||||||
MTGAbility(_id, _source, _target), modifier(_modifier), ability(_ability)
|
MTGAbility(_id, _source, _target), modifier(_modifier), ability(_ability)
|
||||||
{
|
{
|
||||||
@@ -1326,35 +1326,20 @@ public:
|
|||||||
|
|
||||||
int addToGame()
|
int addToGame()
|
||||||
{
|
{
|
||||||
value_before_modification = ((MTGCardInstance *) target)->basicAbilities[ability];
|
value_before_modification = ((MTGCardInstance *) target)->basicAbilities.test(ability);
|
||||||
if(ability != Constants::ABSORB && ability != Constants::FLANKING)
|
|
||||||
{
|
assert(modifier < 2);
|
||||||
((MTGCardInstance *) target)->basicAbilities[ability] = modifier;
|
((MTGCardInstance *) target)->basicAbilities.set(ability, modifier > 0);
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
((MTGCardInstance *) target)->basicAbilities[ability] += modifier;
|
|
||||||
}
|
|
||||||
return MTGAbility::addToGame();
|
return MTGAbility::addToGame();
|
||||||
}
|
}
|
||||||
|
|
||||||
int destroy()
|
int destroy()
|
||||||
{
|
{
|
||||||
if (((MTGCardInstance *) target)->basicAbilities[ability] == modifier && (ability != Constants::ABSORB && ability != Constants::FLANKING))
|
assert(modifier < 2);
|
||||||
{
|
((MTGCardInstance *) target)->basicAbilities.set(ability, value_before_modification);
|
||||||
((MTGCardInstance *) target)->basicAbilities[ability] = value_before_modification;
|
|
||||||
return 1;
|
return 1;
|
||||||
}
|
|
||||||
else if (ability == Constants::ABSORB || ability == Constants::FLANKING)
|
|
||||||
{
|
|
||||||
((MTGCardInstance *) target)->basicAbilities[ability] -= 1;
|
|
||||||
return 1;
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
//BUG !!!
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
const char * getMenuText()
|
const char * getMenuText()
|
||||||
@@ -1375,18 +1360,17 @@ public:
|
|||||||
a->isClone = 1;
|
a->isClone = 1;
|
||||||
return a;
|
return a;
|
||||||
}
|
}
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
/*Instants that modifies a basic ability until end of turn */
|
/*Instants that modifies a basic ability until end of turn */
|
||||||
class AInstantBasicAbilityModifierUntilEOT: public InstantAbility
|
class AInstantBasicAbilityModifierUntilEOT : public InstantAbility
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
int stateBeforeActivation;
|
bool stateBeforeActivation;
|
||||||
int ability;
|
int ability;
|
||||||
int value;
|
int value;
|
||||||
AInstantBasicAbilityModifierUntilEOT(int _id, MTGCardInstance * _source, MTGCardInstance * _target, int _ability, int value) :
|
AInstantBasicAbilityModifierUntilEOT(int _id, MTGCardInstance * _source, MTGCardInstance * _target, int _ability, int value)
|
||||||
InstantAbility(_id, _source, _target), ability(_ability), value(value)
|
: InstantAbility(_id, _source, _target), ability(_ability), value(value)
|
||||||
{
|
{
|
||||||
aType = MTGAbility::STANDARDABILITYGRANT;
|
aType = MTGAbility::STANDARDABILITYGRANT;
|
||||||
abilitygranted = ability;
|
abilitygranted = ability;
|
||||||
@@ -1395,15 +1379,10 @@ public:
|
|||||||
int addToGame()
|
int addToGame()
|
||||||
{
|
{
|
||||||
MTGCardInstance * _target = (MTGCardInstance *) target;
|
MTGCardInstance * _target = (MTGCardInstance *) target;
|
||||||
stateBeforeActivation = _target->basicAbilities[ability];
|
stateBeforeActivation = _target->basicAbilities.test(ability);
|
||||||
if(ability != Constants::ABSORB)
|
|
||||||
{
|
assert(value < 2);
|
||||||
_target->basicAbilities[ability] = value;
|
_target->basicAbilities.set(ability, value > 0);
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
_target->basicAbilities[ability] += value;
|
|
||||||
}
|
|
||||||
return InstantAbility::addToGame();
|
return InstantAbility::addToGame();
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -1415,9 +1394,11 @@ public:
|
|||||||
int destroy()
|
int destroy()
|
||||||
{
|
{
|
||||||
MTGCardInstance * _target = (MTGCardInstance *) target;
|
MTGCardInstance * _target = (MTGCardInstance *) target;
|
||||||
if (_target) _target->basicAbilities[ability] = stateBeforeActivation;
|
if (_target)
|
||||||
|
_target->basicAbilities.set(ability, stateBeforeActivation);
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
virtual ostream& toString(ostream& out) const
|
virtual ostream& toString(ostream& out) const
|
||||||
{
|
{
|
||||||
out << "ABasicAbilityModifierUntilEOT ::: stateBeforeActivation : " << stateBeforeActivation << " ability : " << ability
|
out << "ABasicAbilityModifierUntilEOT ::: stateBeforeActivation : " << stateBeforeActivation << " ability : " << ability
|
||||||
@@ -1431,7 +1412,6 @@ public:
|
|||||||
a->isClone = 1;
|
a->isClone = 1;
|
||||||
return a;
|
return a;
|
||||||
}
|
}
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
//Alteration of Ability until of turn (Aura)
|
//Alteration of Ability until of turn (Aura)
|
||||||
|
|||||||
@@ -5,6 +5,7 @@
|
|||||||
#include <string>
|
#include <string>
|
||||||
#include <vector>
|
#include <vector>
|
||||||
#include <map>
|
#include <map>
|
||||||
|
#include <bitset>
|
||||||
|
|
||||||
#include "ManaCost.h"
|
#include "ManaCost.h"
|
||||||
#include "ObjectAnalytics.h"
|
#include "ObjectAnalytics.h"
|
||||||
@@ -35,7 +36,8 @@ public:
|
|||||||
int init();
|
int init();
|
||||||
|
|
||||||
uint8_t colors;
|
uint8_t colors;
|
||||||
map<int,int> basicAbilities;
|
std::bitset<Constants::NB_BASIC_ABILITIES> basicAbilities;
|
||||||
|
|
||||||
map<string,string> magicTexts;
|
map<string,string> magicTexts;
|
||||||
string magicText;
|
string magicText;
|
||||||
int alias;
|
int alias;
|
||||||
|
|||||||
@@ -2406,17 +2406,21 @@ ATransformer::ATransformer(int id, MTGCardInstance * source, MTGCardInstance * t
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
for (it = colors.begin(); it != colors.end(); it++)
|
for (it = colors.begin(); it != colors.end(); it++)
|
||||||
{
|
{
|
||||||
_target->setColor(*it);
|
_target->setColor(*it);
|
||||||
}
|
}
|
||||||
|
|
||||||
for (it = abilities.begin(); it != abilities.end(); it++)
|
for (it = abilities.begin(); it != abilities.end(); it++)
|
||||||
{
|
{
|
||||||
_target->basicAbilities[*it]++;
|
_target->basicAbilities.set(*it);
|
||||||
}
|
}
|
||||||
|
|
||||||
for (it = oldcolors.begin(); it != oldcolors.end(); it++)
|
for (it = oldcolors.begin(); it != oldcolors.end(); it++)
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
if(newAbilityFound)
|
if(newAbilityFound)
|
||||||
{
|
{
|
||||||
for (unsigned int k = 0 ; k < newAbilitiesList.size();k++)
|
for (unsigned int k = 0 ; k < newAbilitiesList.size();k++)
|
||||||
@@ -2499,18 +2503,22 @@ int ATransformer::destroy()
|
|||||||
}
|
}
|
||||||
//iterators annoy me :/
|
//iterators annoy me :/
|
||||||
}
|
}
|
||||||
|
|
||||||
for (it = colors.begin(); it != colors.end(); it++)
|
for (it = colors.begin(); it != colors.end(); it++)
|
||||||
{
|
{
|
||||||
_target->removeColor(*it);
|
_target->removeColor(*it);
|
||||||
}
|
}
|
||||||
|
|
||||||
for (it = abilities.begin(); it != abilities.end(); it++)
|
for (it = abilities.begin(); it != abilities.end(); it++)
|
||||||
{
|
{
|
||||||
_target->basicAbilities[*it]--;
|
_target->basicAbilities.reset(*it);
|
||||||
}
|
}
|
||||||
|
|
||||||
for (it = oldcolors.begin(); it != oldcolors.end(); it++)
|
for (it = oldcolors.begin(); it != oldcolors.end(); it++)
|
||||||
{
|
{
|
||||||
_target->setColor(*it);
|
_target->setColor(*it);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (remove)
|
if (remove)
|
||||||
{
|
{
|
||||||
for (it = oldtypes.begin(); it != oldtypes.end(); it++)
|
for (it = oldtypes.begin(); it != oldtypes.end(); it++)
|
||||||
|
|||||||
@@ -208,13 +208,17 @@ MTGCardInstance * CardDescriptor::match(MTGCardInstance * card)
|
|||||||
}
|
}
|
||||||
|
|
||||||
//Abilities
|
//Abilities
|
||||||
for (map<int, int>::const_iterator it = basicAbilities.begin(); it != basicAbilities.end(); ++it)
|
std::bitset<Constants::NB_BASIC_ABILITIES> set = basicAbilities & card->basicAbilities;
|
||||||
|
|
||||||
|
if (mode == CD_NOT)
|
||||||
{
|
{
|
||||||
int j = it->first;
|
if (set.any())
|
||||||
if ((basicAbilities[j] == 1 && !card->basicAbilities[j]) || (basicAbilities[j] == -1 && card->basicAbilities[j]))
|
return NULL;
|
||||||
{
|
}
|
||||||
match = NULL;
|
else
|
||||||
}
|
{
|
||||||
|
if (set != basicAbilities)
|
||||||
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
if ((tapped == -1 && card->isTapped()) || (tapped == 1 && !card->isTapped()))
|
if ((tapped == -1 && card->isTapped()) || (tapped == 1 && !card->isTapped()))
|
||||||
|
|||||||
@@ -77,8 +77,7 @@ CardPrimitive::CardPrimitive()
|
|||||||
|
|
||||||
CardPrimitive::CardPrimitive(CardPrimitive * source)
|
CardPrimitive::CardPrimitive(CardPrimitive * source)
|
||||||
{
|
{
|
||||||
for (map<int, int>::const_iterator it = source->basicAbilities.begin(); it != source->basicAbilities.end(); ++it)
|
basicAbilities = source->basicAbilities;
|
||||||
basicAbilities[it->first] = source->basicAbilities[it->first];
|
|
||||||
|
|
||||||
for (size_t i = 0; i < source->types.size(); ++i)
|
for (size_t i = 0; i < source->types.size(); ++i)
|
||||||
types.push_back(source->types[i]);
|
types.push_back(source->types[i]);
|
||||||
@@ -111,7 +110,7 @@ CardPrimitive::~CardPrimitive()
|
|||||||
|
|
||||||
int CardPrimitive::init()
|
int CardPrimitive::init()
|
||||||
{
|
{
|
||||||
basicAbilities.clear();
|
basicAbilities.reset();
|
||||||
|
|
||||||
types.clear();
|
types.clear();
|
||||||
|
|
||||||
|
|||||||
@@ -3122,7 +3122,7 @@ int AbilityFactory::getAbilities(vector<MTGAbility *> * v, Spell * spell, MTGCar
|
|||||||
card->types.clear();
|
card->types.clear();
|
||||||
string cre = "Creature";
|
string cre = "Creature";
|
||||||
card->setType(cre.c_str());
|
card->setType(cre.c_str());
|
||||||
card->basicAbilities.clear();
|
card->basicAbilities.reset();
|
||||||
card->getManaCost()->remove(0,100);
|
card->getManaCost()->remove(0,100);
|
||||||
card->getManaCost()->remove(1,100);
|
card->getManaCost()->remove(1,100);
|
||||||
card->getManaCost()->remove(2,100);
|
card->getManaCost()->remove(2,100);
|
||||||
@@ -3139,11 +3139,9 @@ int AbilityFactory::getAbilities(vector<MTGAbility *> * v, Spell * spell, MTGCar
|
|||||||
card->name = card->model->data->name;
|
card->name = card->model->data->name;
|
||||||
card->types = card->model->data->types;
|
card->types = card->model->data->types;
|
||||||
card->colors = card->model->data->colors;
|
card->colors = card->model->data->colors;
|
||||||
for (map<int, int>::const_iterator it = card->model->data->basicAbilities.begin(); it != card->model->data->basicAbilities.end(); ++it)
|
|
||||||
{
|
card->basicAbilities |= card->model->data->basicAbilities;
|
||||||
int i = it->first;
|
|
||||||
card->basicAbilities[i] += card->model->data->basicAbilities[i];
|
|
||||||
}
|
|
||||||
ManaCost * copyCost = card->model->data->getManaCost();
|
ManaCost * copyCost = card->model->data->getManaCost();
|
||||||
card->getManaCost()->copy(copyCost);
|
card->getManaCost()->copy(copyCost);
|
||||||
magicText = card->model->data->magicText;
|
magicText = card->model->data->magicText;
|
||||||
|
|||||||
@@ -53,11 +53,8 @@ void MTGCardInstance::copy(MTGCardInstance * card)
|
|||||||
{
|
{
|
||||||
MTGCard * source = card->model;
|
MTGCard * source = card->model;
|
||||||
CardPrimitive * data = source->data;
|
CardPrimitive * data = source->data;
|
||||||
for (map<int, int>::const_iterator it = data->basicAbilities.begin(); it != data->basicAbilities.end(); ++it)
|
|
||||||
{
|
basicAbilities = card->basicAbilities;
|
||||||
int i = it->first;
|
|
||||||
basicAbilities[i] = data->basicAbilities[i];
|
|
||||||
}
|
|
||||||
for (size_t i = 0; i < data->types.size(); i++)
|
for (size_t i = 0; i < data->types.size(); i++)
|
||||||
{
|
{
|
||||||
types.push_back(data->types[i]);
|
types.push_back(data->types[i]);
|
||||||
@@ -1048,18 +1045,20 @@ JSample * MTGCardInstance::getSample()
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
for (map<int, int>::const_iterator it = basicAbilities.begin(); it != basicAbilities.end(); ++it)
|
if (basicAbilities.any())
|
||||||
{
|
{
|
||||||
int i = it->first;
|
for (size_t x = 0; x < basicAbilities.size(); ++x)
|
||||||
if (!basicAbilities[i])
|
|
||||||
continue;
|
|
||||||
string type = Constants::MTGBasicAbilities[i];
|
|
||||||
type = type + ".wav";
|
|
||||||
js = WResourceManager::Instance()->RetrieveSample(type);
|
|
||||||
if (js)
|
|
||||||
{
|
{
|
||||||
sample = string(type);
|
if (!basicAbilities.test(x))
|
||||||
return js;
|
continue;
|
||||||
|
string type = Constants::MTGBasicAbilities[x];
|
||||||
|
type = type + ".wav";
|
||||||
|
js = WResourceManager::Instance()->RetrieveSample(type);
|
||||||
|
if (js)
|
||||||
|
{
|
||||||
|
sample = string(type);
|
||||||
|
return js;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -1095,9 +1095,10 @@ void MTGDeck::printDetailedDeckText(std::ofstream& file )
|
|||||||
if ( card->data->hasRestriction )
|
if ( card->data->hasRestriction )
|
||||||
currentCard << ", " << card->data->otherrestriction;
|
currentCard << ", " << card->data->otherrestriction;
|
||||||
|
|
||||||
map<int,int>::iterator abilityIter;
|
for (size_t x = 0; card->data->basicAbilities.size(); ++x)
|
||||||
for ( abilityIter = card->data->basicAbilities.begin(); abilityIter != card->data->basicAbilities.end(); ++abilityIter )
|
{
|
||||||
currentCard << Constants::MTGBasicAbilities[ abilityIter->first ] << "; ";
|
currentCard << Constants::MTGBasicAbilities[x] << "; ";
|
||||||
|
}
|
||||||
currentCard <<endl;
|
currentCard <<endl;
|
||||||
|
|
||||||
for ( int i = 0; i < nbCards; i++ )
|
for ( int i = 0; i < nbCards; i++ )
|
||||||
|
|||||||
@@ -592,12 +592,9 @@ TargetChooser * TargetChooserFactory::createTargetChooser(string s, MTGCardInsta
|
|||||||
attributefound = 1;
|
attributefound = 1;
|
||||||
if (minus)
|
if (minus)
|
||||||
{
|
{
|
||||||
cd->basicAbilities[j] = -1;
|
cd->mode = CD_NOT;
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
cd->basicAbilities[j] = 1;
|
|
||||||
}
|
}
|
||||||
|
cd->basicAbilities.set(j);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -404,14 +404,10 @@ WCFilterRarity::WCFilterRarity(string arg)
|
|||||||
bool WCFilterAbility::isMatch(MTGCard * c)
|
bool WCFilterAbility::isMatch(MTGCard * c)
|
||||||
{
|
{
|
||||||
if (ability < 0) return false;
|
if (ability < 0) return false;
|
||||||
map<int, int>::iterator it = c->data->basicAbilities.find(ability);
|
|
||||||
|
return c->data->basicAbilities.test(ability);
|
||||||
if (it != c->data->basicAbilities.end())
|
|
||||||
{
|
|
||||||
if (it->second > 0) return true;
|
|
||||||
}
|
|
||||||
return false;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
WCFilterAbility::WCFilterAbility(string arg)
|
WCFilterAbility::WCFilterAbility(string arg)
|
||||||
{
|
{
|
||||||
std::transform(arg.begin(), arg.end(), arg.begin(), ::tolower);
|
std::transform(arg.begin(), arg.end(), arg.begin(), ::tolower);
|
||||||
|
|||||||
Reference in New Issue
Block a user