just cleaning up a memleak i created, moving the parsing of the "newability" in transforms into the resolve rather then creating an object that might not be used.

This commit is contained in:
omegablast2002@yahoo.com
2011-03-30 22:10:45 +00:00
parent 3f39b19c87
commit 257de9962a
3 changed files with 33 additions and 34 deletions

View File

@@ -3928,11 +3928,11 @@ public:
bool newtoughnessfound;
int oldtoughness;
map<Damageable *, vector<MTGAbility *> > newAbilities;
vector<MTGAbility *> newAbilitiesList;
vector<string> newAbilitiesList;
bool newAbilityFound;
ATransformer(int id, MTGCardInstance * source, MTGCardInstance * target, string stypes, string sabilities,string newpower,bool newpowerfound,string newtoughness,bool newtoughnessfound,vector<MTGAbility *> newAbilitiesList,bool newAbilityFound = false);
ATransformer(int id, MTGCardInstance * source, MTGCardInstance * target, string stypes, string sabilities,string newpower,bool newpowerfound,string newtoughness,bool newtoughnessfound,vector<string> newAbilitiesList,bool newAbilityFound = false);
int addToGame();
int destroy();
const char * getMenuText();
@@ -3955,11 +3955,11 @@ public:
bool newtoughnessfound;
int oldtoughness;
bool remove;
vector<MTGAbility *> newAbilitiesList;
vector<string> newAbilitiesList;
map<Damageable *, vector<MTGAbility *> > newAbilities;
bool newAbilityFound;
AForeverTransformer(int id, MTGCardInstance * source, MTGCardInstance * target, string stypes, string sabilities,string newpower = "",bool newpowerfound = false,string newtoughness = "",bool newtoughnessfound = false,vector<MTGAbility*>newAbilitiesList = vector<MTGAbility*>(),bool newAbilityFound = false);
AForeverTransformer(int id, MTGCardInstance * source, MTGCardInstance * target, string stypes, string sabilities,string newpower = "",bool newpowerfound = false,string newtoughness = "",bool newtoughnessfound = false,vector<string>newAbilitiesList = vector<string>(),bool newAbilityFound = false);
int addToGame();
const char * getMenuText();
AForeverTransformer * clone() const;
@@ -3975,11 +3975,11 @@ public:
bool newpowerfound;
string newtoughness;
bool newtoughnessfound;
vector<MTGAbility *> newAbilitiesList;
vector<string> newAbilitiesList;
map<Damageable *, vector<MTGAbility *> > newAbilities;
bool newAbilityFound;
ATransformerUEOT(int id, MTGCardInstance * source, MTGCardInstance * target, string types = "", string abilities = "",string newpower = "",bool newpowerfound = false,string newtoughness = "",bool newtoughnessfound = false,vector<MTGAbility*>newAbilitiesList = vector<MTGAbility*>(),bool newAbilityFound = false);
ATransformerUEOT(int id, MTGCardInstance * source, MTGCardInstance * target, string types = "", string abilities = "",string newpower = "",bool newpowerfound = false,string newtoughness = "",bool newtoughnessfound = false,vector<string>newAbilitiesList = vector<string>(),bool newAbilityFound = false);
int resolve();
const char * getMenuText();
ATransformerUEOT * clone() const;
@@ -3995,11 +3995,11 @@ public:
bool newpowerfound;
string newtoughness;
bool newtoughnessfound;
vector<MTGAbility *> newAbilitiesList;
vector<string> newAbilitiesList;
map<Damageable *, vector<MTGAbility *> > newAbilities;
bool newAbilityFound;
ATransformerFOREVER(int id, MTGCardInstance * source, MTGCardInstance * target, string types, string abilities,string newpower = "",bool newpowerfound = false,string newtoughness = "",bool newtoughnessfound = false,vector<MTGAbility*>newAbilitiesList = vector<MTGAbility*>(),bool newAbilityFound = false);
ATransformerFOREVER(int id, MTGCardInstance * source, MTGCardInstance * target, string types, string abilities,string newpower = "",bool newpowerfound = false,string newtoughness = "",bool newtoughnessfound = false,vector<string>newAbilitiesList = vector<string>(),bool newAbilityFound = false);
int resolve();
const char * getMenuText();
ATransformerFOREVER * clone() const;

View File

@@ -2210,7 +2210,7 @@ AAlterCost::~AAlterCost()
}
// ATransformer
ATransformer::ATransformer(int id, MTGCardInstance * source, MTGCardInstance * target, string stypes, string sabilities,string newpower,bool newpowerfound,string newtoughness,bool newtoughnessfound,vector<MTGAbility *> newAbilitiesList,bool newAbilityFound) :
ATransformer::ATransformer(int id, MTGCardInstance * source, MTGCardInstance * target, string stypes, string sabilities,string newpower,bool newpowerfound,string newtoughness,bool newtoughnessfound,vector<string> newAbilitiesList,bool newAbilityFound) :
MTGAbility(id, source, target),newpower(newpower),newpowerfound(newpowerfound),newtoughness(newtoughness),newtoughnessfound(newtoughnessfound),newAbilitiesList(newAbilitiesList),newAbilityFound(newAbilityFound)
{
@@ -2307,9 +2307,9 @@ ATransformer::ATransformer(int id, MTGCardInstance * source, MTGCardInstance * t
{
for (unsigned int k = 0 ; k < newAbilitiesList.size();k++)
{
MTGAbility * aNew = newAbilitiesList[k]->clone();
AbilityFactory af;
MTGAbility * aNew = af.parseMagicLine(newAbilitiesList[k],NULL, NULL, _target);
aNew->isClone = 1;
GenericTargetAbility * gta = dynamic_cast<GenericTargetAbility*> (aNew);
if (gta)
{
@@ -2329,7 +2329,13 @@ ATransformer::ATransformer(int id, MTGCardInstance * source, MTGCardInstance * t
}
aNew->target = _target;
aNew->source = (MTGCardInstance *) _target;
aNew->addToGame();
if(aNew->oneShot)
{
aNew->resolve();
delete aNew;
}
else
aNew->addToGame();
newAbilities[_target].push_back(aNew);
}
}
@@ -2426,18 +2432,11 @@ ATransformer * ATransformer::clone() const
ATransformer::~ATransformer()
{
if(!isClone)
{
for (unsigned int k = 0; k < newAbilitiesList.size();k++)
{
SAFE_DELETE(newAbilitiesList[k]);
}
}
}
// AForeverTransformer
AForeverTransformer::AForeverTransformer(int id, MTGCardInstance * source, MTGCardInstance * target, string stypes,
string sabilities,string newpower,bool newpowerfound, string newtoughness,bool newtoughnessfound,vector<MTGAbility*> newAbilitiesList,bool newAbilityFound) :
string sabilities,string newpower,bool newpowerfound, string newtoughness,bool newtoughnessfound,vector<string> newAbilitiesList,bool newAbilityFound) :
MTGAbility(id, source, target),newpower(newpower),newpowerfound(newpowerfound),newtoughness(newtoughness),newtoughnessfound(newtoughnessfound),newAbilitiesList(newAbilitiesList),newAbilityFound(newAbilityFound)
{
aType = MTGAbility::STANDARD_BECOMES;
@@ -2492,8 +2491,9 @@ int AForeverTransformer::addToGame()
{
for (unsigned int k = 0 ; k < newAbilitiesList.size();k++)
{
MTGAbility * aNew = newAbilitiesList[k]->clone();
AbilityFactory af;
MTGAbility * aNew = af.parseMagicLine(newAbilitiesList[k],NULL, NULL, _target);
aNew->isClone = 1;
GenericTargetAbility * gta = dynamic_cast<GenericTargetAbility*> (aNew);
if (gta)
@@ -2514,6 +2514,12 @@ int AForeverTransformer::addToGame()
}
aNew->target = _target;
aNew->source = (MTGCardInstance *) _target;
if(aNew->oneShot)
{
aNew->resolve();
delete aNew;
}
else
aNew->addToGame();
newAbilities[_target].push_back(aNew);
}
@@ -2553,17 +2559,10 @@ AForeverTransformer * AForeverTransformer::clone() const
}
AForeverTransformer::~AForeverTransformer()
{
if(!isClone)
{
for (unsigned int k = 0; k < newAbilitiesList.size();k++)
{
SAFE_DELETE(newAbilitiesList[k]);
}
}
}
//ATransformerUEOT
ATransformerUEOT::ATransformerUEOT(int id, MTGCardInstance * source, MTGCardInstance * target, string types, string abilities,string newpower,bool newpowerfound,string newtoughness,bool newtoughnessfound,vector<MTGAbility*>newAbilitiesList,bool newAbilityFound) :
ATransformerUEOT::ATransformerUEOT(int id, MTGCardInstance * source, MTGCardInstance * target, string types, string abilities,string newpower,bool newpowerfound,string newtoughness,bool newtoughnessfound,vector<string>newAbilitiesList,bool newAbilityFound) :
InstantAbility(id, source, target),newpower(newpower),newpowerfound(newpowerfound),newtoughness(newtoughness),newtoughnessfound(newtoughnessfound),newAbilitiesList(newAbilitiesList),newAbilityFound(newAbilityFound)
{
ability = NEW ATransformer(id, source, target, types, abilities,newpower,newpowerfound,newtoughness,newtoughnessfound,newAbilitiesList,newAbilityFound);
@@ -2596,7 +2595,7 @@ ATransformerUEOT::~ATransformerUEOT()
}
// ATransformerFOREVER
ATransformerFOREVER::ATransformerFOREVER(int id, MTGCardInstance * source, MTGCardInstance * target, string types, string abilities,string newpower,bool newpowerfound,string newtoughness,bool newtoughnessfound,vector<MTGAbility*>newAbilitiesList,bool newAbilityFound) :
ATransformerFOREVER::ATransformerFOREVER(int id, MTGCardInstance * source, MTGCardInstance * target, string types, string abilities,string newpower,bool newpowerfound,string newtoughness,bool newtoughnessfound,vector<string>newAbilitiesList,bool newAbilityFound) :
InstantAbility(id, source, target),newpower(newpower),newpowerfound(newpowerfound),newtoughness(newtoughness),newtoughnessfound(newtoughnessfound),newAbilitiesList(newAbilitiesList),newAbilityFound(newAbilityFound)
{
ability = NEW AForeverTransformer(id, source, target, types, abilities,newpower,newpowerfound,newtoughness,newtoughnessfound,newAbilitiesList,newAbilityFound);

View File

@@ -2548,7 +2548,7 @@ MTGAbility * AbilityFactory::parseMagicLine(string s, int id, Spell * spell, MTG
string newtoughness = "";
vector <string> abilities = split(sabilities, ',');
bool newAbilityFound = false;
vector<MTGAbility *> newAbilitiesList;
vector<string> newAbilitiesList;
storedString.erase();
storedString.append(extraTransforms);
extraTransforms.erase();
@@ -2571,7 +2571,7 @@ MTGAbility * AbilityFactory::parseMagicLine(string s, int id, Spell * spell, MTG
newAbilityFound = true;
size_t NewSkill = abilities[j].find("[");
string newAbilities = abilities[j].substr(NewSkill + 1,abilities[j].find(']') - 1);
newAbilitiesList.push_back(parseMagicLine(newAbilities, id, spell, card));
newAbilitiesList.push_back(newAbilities.c_str());
}
}
MTGAbility * a;