From 2c9d029bdcb698eed7768707e1dbcd38ca74e75d Mon Sep 17 00:00:00 2001 From: "omegablast2002@yahoo.com" Date: Tue, 10 May 2011 18:52:51 +0000 Subject: [PATCH] fixed a memleak introduced in r3639.. i also changed the logic behind wololo "ueot " instant ability creator...instead of sending it directly to genericinstantability i created a new class called AGenericInstantWrapper...which handles the adding, cloning, removel ect, exactly how we have always handled "instant abilities"...this should correct any further "odd edge case" issues with the new "ueot " code... later i will varify if it works with every single ability we current build with a wrapper class...and see if i cant remove them all and convert "ueot " into the NEW until end of turn handling method....lets cross our fingers as it would remove ALOT of extra code if successful.... --- projects/mtg/include/AllAbilities.h | 15 ++++++++++++- projects/mtg/src/AllAbilities.cpp | 33 +++++++++++++++++++++++++++++ projects/mtg/src/MTGAbility.cpp | 2 +- 3 files changed, 48 insertions(+), 2 deletions(-) diff --git a/projects/mtg/include/AllAbilities.h b/projects/mtg/include/AllAbilities.h index ea0b890a3..f3d5833a3 100644 --- a/projects/mtg/include/AllAbilities.h +++ b/projects/mtg/include/AllAbilities.h @@ -825,6 +825,20 @@ public: 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 class AACounter: public ActivatedAbility { @@ -1766,7 +1780,6 @@ public: GenericInstantAbility * clone() const { GenericInstantAbility * a = NEW GenericInstantAbility(*this); - a->ability = ability->clone(); a->isClone = 1; return a; } diff --git a/projects/mtg/src/AllAbilities.cpp b/projects/mtg/src/AllAbilities.cpp index 698462046..92e028222 100644 --- a/projects/mtg/src/AllAbilities.cpp +++ b/projects/mtg/src/AllAbilities.cpp @@ -69,6 +69,39 @@ GenericActivatedAbility::~GenericActivatedAbility() 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 AAAlterPoison::AAAlterPoison(int _id, MTGCardInstance * _source, Targetable * _target, int poison, ManaCost * _cost, int who) : diff --git a/projects/mtg/src/MTGAbility.cpp b/projects/mtg/src/MTGAbility.cpp index 38bfa91f5..967aafbc5 100644 --- a/projects/mtg/src/MTGAbility.cpp +++ b/projects/mtg/src/MTGAbility.cpp @@ -909,7 +909,7 @@ MTGAbility * AbilityFactory::parseMagicLine(string s, int id, Spell * spell, MTG if (!a1) return NULL; - return NEW GenericInstantAbility(1, card, (Damageable *) target, a1); + return NEW AGenericInstantWrapper(1, card, (Damageable *) target, a1); } //Upkeep Cost