- revert r3645
- fix memory leak in GenericInstantAbility
This commit is contained in:
@@ -825,20 +825,6 @@ public:
|
|||||||
return a;
|
return a;
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
//make instant ability out of anything
|
|
||||||
class AGenericInstantWrapper: public InstantAbility
|
|
||||||
{
|
|
||||||
public:
|
|
||||||
MTGAbility * ability;
|
|
||||||
|
|
||||||
AGenericInstantWrapper(int id, MTGCardInstance * source, Damageable * target,MTGAbility * wrapThis);
|
|
||||||
int resolve();
|
|
||||||
const char * getMenuText();
|
|
||||||
AGenericInstantWrapper * clone() const;
|
|
||||||
~AGenericInstantWrapper();
|
|
||||||
};
|
|
||||||
|
|
||||||
//counters
|
//counters
|
||||||
class AACounter: public ActivatedAbility
|
class AACounter: public ActivatedAbility
|
||||||
{
|
{
|
||||||
@@ -1773,16 +1759,25 @@ public:
|
|||||||
|
|
||||||
int destroy()
|
int destroy()
|
||||||
{
|
{
|
||||||
ability->forceDestroy = 1;
|
if (game->removeObserver(ability))
|
||||||
|
ability = NULL;
|
||||||
|
else
|
||||||
|
SAFE_DELETE(ability);
|
||||||
return InstantAbility::destroy();
|
return InstantAbility::destroy();
|
||||||
}
|
}
|
||||||
|
|
||||||
GenericInstantAbility * clone() const
|
GenericInstantAbility * clone() const
|
||||||
{
|
{
|
||||||
GenericInstantAbility * a = NEW GenericInstantAbility(*this);
|
GenericInstantAbility * a = NEW GenericInstantAbility(*this);
|
||||||
|
a->ability = ability->clone();
|
||||||
a->isClone = 1;
|
a->isClone = 1;
|
||||||
return a;
|
return a;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
~GenericInstantAbility()
|
||||||
|
{
|
||||||
|
SAFE_DELETE(ability);
|
||||||
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
//Circle of Protections
|
//Circle of Protections
|
||||||
|
|||||||
@@ -112,6 +112,14 @@ void ActionLayer::Update(float dt)
|
|||||||
GameObserver* game = GameObserver::GetInstance();
|
GameObserver* game = GameObserver::GetInstance();
|
||||||
for (int i = mCount - 1; i >= 0; i--)
|
for (int i = mCount - 1; i >= 0; i--)
|
||||||
{
|
{
|
||||||
|
//a dirty hack, there might be cases when the mObject array gets reshaped if an ability removes some of its children abilites
|
||||||
|
if ((int) mObjects.size() <= i)
|
||||||
|
{
|
||||||
|
i = (int) (mObjects.size()) - 1;
|
||||||
|
if (i<0)
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
if (mObjects[i] != NULL)
|
if (mObjects[i] != NULL)
|
||||||
{
|
{
|
||||||
ActionElement * currentAction = (ActionElement *) mObjects[i];
|
ActionElement * currentAction = (ActionElement *) mObjects[i];
|
||||||
@@ -364,10 +372,8 @@ ActionLayer::ActionLayer()
|
|||||||
|
|
||||||
ActionLayer::~ActionLayer()
|
ActionLayer::~ActionLayer()
|
||||||
{
|
{
|
||||||
for (int i = mCount - 1; i >= 0; i--)
|
while(mObjects.size())
|
||||||
{
|
moveToGarbage((ActionElement *) mObjects[mObjects.size() - 1]);
|
||||||
moveToGarbage((ActionElement *) mObjects[i]);
|
|
||||||
}
|
|
||||||
SAFE_DELETE(abilitiesMenu);
|
SAFE_DELETE(abilitiesMenu);
|
||||||
cleanGarbage();
|
cleanGarbage();
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -69,39 +69,6 @@ GenericActivatedAbility::~GenericActivatedAbility()
|
|||||||
SAFE_DELETE(ability);
|
SAFE_DELETE(ability);
|
||||||
}
|
}
|
||||||
|
|
||||||
//a generic instant wrapper
|
|
||||||
//this turns any MTGAbility object into an instant ability.
|
|
||||||
AGenericInstantWrapper::AGenericInstantWrapper(int id, MTGCardInstance * source, Damageable * target,MTGAbility * wrapThis) :
|
|
||||||
InstantAbility(id, source, target)
|
|
||||||
{
|
|
||||||
ability = wrapThis;
|
|
||||||
}
|
|
||||||
|
|
||||||
int AGenericInstantWrapper::resolve()
|
|
||||||
{
|
|
||||||
MTGAbility * a = ability->clone();
|
|
||||||
GenericInstantAbility * wrapper = NEW GenericInstantAbility(1, source, (Damageable *) (this->target), a);
|
|
||||||
wrapper->addToGame();
|
|
||||||
return 1;
|
|
||||||
}
|
|
||||||
const char * AGenericInstantWrapper::getMenuText()
|
|
||||||
{
|
|
||||||
return ability->getMenuText();
|
|
||||||
}
|
|
||||||
|
|
||||||
AGenericInstantWrapper * AGenericInstantWrapper::clone() const
|
|
||||||
{
|
|
||||||
AGenericInstantWrapper * a = NEW AGenericInstantWrapper(*this);
|
|
||||||
a->ability = this->ability->clone();
|
|
||||||
a->isClone = 1;
|
|
||||||
return a;
|
|
||||||
}
|
|
||||||
|
|
||||||
AGenericInstantWrapper::~AGenericInstantWrapper()
|
|
||||||
{
|
|
||||||
SAFE_DELETE(ability);
|
|
||||||
}
|
|
||||||
|
|
||||||
//AA Alter Poison
|
//AA Alter Poison
|
||||||
AAAlterPoison::AAAlterPoison(int _id, MTGCardInstance * _source, Targetable * _target, int poison, ManaCost * _cost,
|
AAAlterPoison::AAAlterPoison(int _id, MTGCardInstance * _source, Targetable * _target, int poison, ManaCost * _cost,
|
||||||
int who) :
|
int who) :
|
||||||
|
|||||||
@@ -909,7 +909,7 @@ MTGAbility * AbilityFactory::parseMagicLine(string s, int id, Spell * spell, MTG
|
|||||||
if (!a1)
|
if (!a1)
|
||||||
return NULL;
|
return NULL;
|
||||||
|
|
||||||
return NEW AGenericInstantWrapper(1, card, (Damageable *) target, a1);
|
return NEW GenericInstantAbility(1, card, (Damageable *) target, a1);
|
||||||
}
|
}
|
||||||
|
|
||||||
//Upkeep Cost
|
//Upkeep Cost
|
||||||
|
|||||||
Reference in New Issue
Block a user