diff --git a/projects/mtg/include/ActionElement.h b/projects/mtg/include/ActionElement.h index 952cc0c5e..5e5b09511 100644 --- a/projects/mtg/include/ActionElement.h +++ b/projects/mtg/include/ActionElement.h @@ -22,7 +22,6 @@ class ActionElement: public JGuiObject { protected: int activeState; - int isClone; public: TargetChooser * tc; int currentPhase; @@ -48,6 +47,7 @@ public: } ; ActionElement(int id); + ActionElement(const ActionElement& copyFromMe); virtual ~ActionElement(); virtual int isReactingToTargetClick(Targetable * card); virtual int reactToTargetClick(Targetable * card); diff --git a/projects/mtg/include/AllAbilities.h b/projects/mtg/include/AllAbilities.h index 3b82857d1..6f8508916 100644 --- a/projects/mtg/include/AllAbilities.h +++ b/projects/mtg/include/AllAbilities.h @@ -313,9 +313,7 @@ public: TrCardAddedToZone * clone() const { - TrCardAddedToZone * a = NEW TrCardAddedToZone(*this); - a->isClone = 1; - return a; + return NEW TrCardAddedToZone(*this); } }; @@ -357,9 +355,7 @@ public: TrCardTapped * clone() const { - TrCardTapped * a = NEW TrCardTapped(*this); - a->isClone = 1; - return a; + return NEW TrCardTapped(*this); } }; @@ -401,9 +397,7 @@ public: TrCardTappedformana * clone() const { - TrCardTappedformana * a = NEW TrCardTappedformana(*this); - a->isClone = 1; - return a; + return NEW TrCardTappedformana(*this); } }; @@ -538,9 +532,7 @@ public: TrCombatTrigger * clone() const { - TrCombatTrigger * a = NEW TrCombatTrigger(*this); - a->isClone = 1; - return a; + return NEW TrCombatTrigger(*this); } }; @@ -579,9 +571,7 @@ public: TrcardDrawn * clone() const { - TrcardDrawn * a = NEW TrcardDrawn(*this); - a->isClone = 1; - return a; + return NEW TrcardDrawn(*this); } }; @@ -620,9 +610,7 @@ public: TrCardSacrificed * clone() const { - TrCardSacrificed * a = NEW TrCardSacrificed(*this); - a->isClone = 1; - return a; + return NEW TrCardSacrificed(*this); } }; @@ -658,9 +646,7 @@ public: } TrCardDiscarded * clone() const { - TrCardDiscarded * a = NEW TrCardDiscarded(*this); - a->isClone = 1; - return a; + return NEW TrCardDiscarded(*this); } }; @@ -718,9 +704,7 @@ public: TrDamaged * clone() const { - TrDamaged * a = NEW TrDamaged(*this); - a->isClone = 1; - return a; + return NEW TrDamaged(*this); } }; @@ -770,9 +754,7 @@ public: TrLifeGained * clone() const { - TrLifeGained * a = NEW TrLifeGained(*this); - a->isClone = 1; - return a; + return NEW TrLifeGained(*this); } }; @@ -823,9 +805,7 @@ public: TrVampired * clone() const { - TrVampired * a = NEW TrVampired(*this); - a->isClone = 1; - return a; + return NEW TrVampired(*this); } }; @@ -869,9 +849,7 @@ public: TrTargeted * clone() const { - TrTargeted * a = NEW TrTargeted(*this); - a->isClone = 1; - return a; + return NEW TrTargeted(*this); } }; @@ -1184,9 +1162,7 @@ public: ACycle * clone() const { - ACycle * a = NEW ACycle(*this); - a->isClone = 1; - return a; + return NEW ACycle(*this); } }; @@ -1226,9 +1202,7 @@ public: ANinja * clone() const { - ANinja * a = NEW ANinja(*this); - a->isClone = 1; - return a; + return NEW ANinja(*this); } }; @@ -1260,9 +1234,7 @@ public: ACombatRemoval * clone() const { - ACombatRemoval * a = NEW ACombatRemoval(*this); - a->isClone = 1; - return a; + return NEW ACombatRemoval(*this); } }; @@ -1393,9 +1365,7 @@ public: ABasicAbilityModifier * clone() const { - ABasicAbilityModifier * a = NEW ABasicAbilityModifier(*this); - a->isClone = 1; - return a; + return NEW ABasicAbilityModifier(*this); } }; @@ -1445,9 +1415,7 @@ public: AInstantBasicAbilityModifierUntilEOT * clone() const { - AInstantBasicAbilityModifierUntilEOT * a = NEW AInstantBasicAbilityModifierUntilEOT(*this); - a->isClone = 1; - return a; + return NEW AInstantBasicAbilityModifierUntilEOT(*this); } }; @@ -1494,13 +1462,12 @@ public: ABasicAbilityAuraModifierUntilEOT * clone() const { ABasicAbilityAuraModifierUntilEOT * a = NEW ABasicAbilityAuraModifierUntilEOT(*this); - a->isClone = 1; + a->ability = ability->clone(); return a; } ~ABasicAbilityAuraModifierUntilEOT() { - if (!isClone) SAFE_DELETE(ability); } }; @@ -1565,9 +1532,7 @@ public: ASpellCastLife * clone() const { - ASpellCastLife * a = NEW ASpellCastLife(*this); - a->isClone = 1; - return a; + return NEW ASpellCastLife(*this); } ~ASpellCastLife() @@ -1615,9 +1580,7 @@ public: AUnBlocker * clone() const { - AUnBlocker * a = NEW AUnBlocker(*this); - a->isClone = 1; - return a; + return NEW AUnBlocker(*this); } }; @@ -1657,7 +1620,6 @@ public: { AProtectionFrom * a = NEW AProtectionFrom(*this); a->fromTc = fromTc->clone(); - a->isClone = 1; return a; } @@ -1696,7 +1658,6 @@ public: { ACantBeTargetFrom * a = NEW ACantBeTargetFrom(*this); a->fromTc = fromTc->clone(); - a->isClone = 1; return a; } @@ -1734,7 +1695,6 @@ public: { ACantBeBlockedBy * a = NEW ACantBeBlockedBy(*this); a->fromTc = fromTc->clone(); - a->isClone = 1; return a; } @@ -1806,7 +1766,6 @@ public: { APowerToughnessModifier * a = NEW APowerToughnessModifier(*this); a->wppt = NEW WParsedPT(*(a->wppt)); - a->isClone = 1; return a; } @@ -1847,7 +1806,6 @@ public: { GenericInstantAbility * a = NEW GenericInstantAbility(*this); a->ability = ability->clone(); - a->isClone = 1; return a; } @@ -1866,7 +1824,7 @@ public: ACircleOfProtection(int _id, MTGCardInstance * source, int _color) : TargetAbility(_id, source, NEW SpellOrPermanentTargetChooser(source, _color), NEW ManaCost(), 0) { - cost->add(Constants::MTG_COLOR_ARTIFACT, 1); + getCost()->add(Constants::MTG_COLOR_ARTIFACT, 1); tc->targetter = NULL; //Circle of Protection doesn't use the word "source" } @@ -1915,9 +1873,7 @@ public: } ACircleOfProtection * clone() const { - ACircleOfProtection * a = NEW ACircleOfProtection(*this); - a->isClone = 1; - return a; + return NEW ACircleOfProtection(*this); } }; @@ -1952,9 +1908,7 @@ public: } AStandardRegenerate * clone() const { - AStandardRegenerate * a = NEW AStandardRegenerate(*this); - a->isClone = 1; - return a; + return NEW AStandardRegenerate(*this); } }; @@ -1996,9 +1950,7 @@ public: } ARegularLifeModifierAura * clone() const { - ARegularLifeModifierAura * a = NEW ARegularLifeModifierAura(*this); - a->isClone = 1; - return a; + return NEW ARegularLifeModifierAura(*this); } }; @@ -2063,9 +2015,7 @@ public: AExalted * clone() const { - AExalted * a = NEW AExalted(*this); - a->isClone = 1; - return a; + return NEW AExalted(*this); } }; @@ -2216,8 +2166,7 @@ public: /////////////////////////////////////////////////////// ~AAsLongAs() { - if (!isClone) - SAFE_DELETE(ability); + SAFE_DELETE(ability); } const char * getMenuText() @@ -2235,7 +2184,7 @@ public: AAsLongAs * clone() const { AAsLongAs * a = NEW AAsLongAs(*this); - a->isClone = 1; + a->ability = ability->clone(); return a; } }; @@ -2340,7 +2289,6 @@ public: ~ALord() { - if (!isClone) SAFE_DELETE(ability); } @@ -2356,7 +2304,7 @@ public: ALord * clone() const { ALord * a = NEW ALord(*this); - a->isClone = 1; + a->ability = ability->clone(); return a; } }; @@ -2449,14 +2397,13 @@ public: } ~ATeach() { - if (!isClone) SAFE_DELETE(ability); } ATeach * clone() const { - ATeach * a = NEW ATeach(*this); - a->isClone = 1; + ATeach * a = NEW ATeach(*this); + a->ability = ability->clone(); return a; } @@ -2552,9 +2499,7 @@ public: AEquip * clone() const { - AEquip * a = NEW AEquip(*this); - a->isClone = 1; - return a; + return NEW AEquip(*this); } }; @@ -2781,7 +2726,6 @@ public: { ATokenCreator * a = NEW ATokenCreator(*this); a->multiplier = NEW WParsedInt(*(multiplier)); - a->isClone = 1; return a; } @@ -2859,7 +2803,7 @@ public: AForeach * clone() const { AForeach * a = NEW AForeach(*this); - a->isClone = 1; + a->ability = ability->clone(); return a; } @@ -2874,7 +2818,6 @@ public: ~AForeach() { - if (!isClone) SAFE_DELETE(ability); } @@ -2953,15 +2896,15 @@ public: ~AThis() { - if (!isClone) SAFE_DELETE(ability); SAFE_DELETE(td); } AThis * clone() const { - AThis * a = NEW AThis(*this); - a->isClone = 1; + AThis * a = NEW AThis(*this); + a->ability = ability->clone(); + a->td = td->clone(); return a; } }; @@ -3048,11 +2991,9 @@ public: ~AThisForEach() { - if (!isClone) - { - SAFE_DELETE(ability); - SAFE_DELETE(td); - } + SAFE_DELETE(ability); + SAFE_DELETE(td); + if (abilities.size()) { removeAbilityFromGame(); @@ -3066,8 +3007,9 @@ public: AThisForEach * clone() const { - AThisForEach * a = NEW AThisForEach(*this); - a->isClone = 1; + AThisForEach * a = NEW AThisForEach(*this); + a->ability = ability->clone(); + a->td = td->clone(); return a; } }; @@ -3157,9 +3099,7 @@ public: TADamager * clone() const { - TADamager * a = NEW TADamager(*this); - a->isClone = 1; - return a; + return NEW TADamager(*this); } }; @@ -3343,9 +3283,7 @@ public: } ASwapPT * clone() const { - ASwapPT * a = NEW ASwapPT(*this); - a->isClone = 1; - return a; + return NEW ASwapPT(*this); } }; @@ -3413,9 +3351,7 @@ public: } ALifeZoneLink * clone() const { - ALifeZoneLink * a = NEW ALifeZoneLink(*this); - a->isClone = 1; - return a; + return NEW ALifeZoneLink(*this); } }; @@ -3457,9 +3393,7 @@ public: } AStrongLandLinkCreature * clone() const { - AStrongLandLinkCreature * a = NEW AStrongLandLinkCreature(*this); - a->isClone = 1; - return a; + return NEW AStrongLandLinkCreature(*this); } }; @@ -3495,9 +3429,7 @@ public: } AControlStealAura * clone() const { - AControlStealAura * a = NEW AControlStealAura(*this); - a->isClone = 1; - return a; + return NEW AControlStealAura(*this); } }; //bloodthirst ability------------------------------------------ @@ -3526,9 +3458,7 @@ public: ABloodThirst * clone() const { - ABloodThirst * a = NEW ABloodThirst(*this); - a->isClone = 1; - return a; + return NEW ABloodThirst(*this); } ~ABloodThirst() @@ -3820,8 +3750,8 @@ public: AAladdinsLamp(int id, MTGCardInstance * card) : TargetAbility(id, card) { - cost = NEW ManaCost(); - cost->x(); + setCost(NEW ManaCost(), true); + getCost()->x(); cd = CardDisplay(1, game, SCREEN_WIDTH / 2, SCREEN_HEIGHT / 2, NULL); int zones[] = { MTGGameZone::MY_LIBRARY }; tc = NEW TargetZoneChooser(zones, 1, source); @@ -3837,7 +3767,7 @@ public: { cd.resetObjects(); int wished = game->currentlyActing()->getManaPool()->getConvertedCost(); - game->currentlyActing()->getManaPool()->pay(cost); + game->currentlyActing()->getManaPool()->pay(getCost()); nbcards = 0; MTGGameZone * library = game->currentlyActing()->game->library; while (nbcards < wished) @@ -3887,9 +3817,7 @@ public: } AAladdinsLamp * clone() const { - AAladdinsLamp * a = NEW AAladdinsLamp(*this); - a->isClone = 1; - return a; + return NEW AAladdinsLamp(*this); } }; @@ -3951,9 +3879,7 @@ public: } AArmageddonClock * clone() const { - AArmageddonClock * a = NEW AArmageddonClock(*this); - a->isClone = 1; - return a; + return NEW AArmageddonClock(*this); } }; @@ -4049,9 +3975,7 @@ public: } AConservator * clone() const { - AConservator * a = NEW AConservator(*this); - a->isClone = 1; - return a; + return NEW AConservator(*this); } }; @@ -4064,7 +3988,7 @@ public: ActivatedAbility(_id, source, 0, 1) { int8_t _cost[] = { Constants::MTG_COLOR_WHITE, 2 }; - cost = NEW ManaCost(_cost, 1); + setCost(NEW ManaCost(_cost, 1), true); target = _target; usedThisTurn = 0; } @@ -4100,9 +4024,7 @@ public: } AFarmstead * clone() const { - AFarmstead * a = NEW AFarmstead(*this); - a->isClone = 1; - return a; + return NEW AFarmstead(*this); } }; @@ -4162,9 +4084,7 @@ public: } AKjeldoranFrostbeast * clone() const { - AKjeldoranFrostbeast * a = NEW AKjeldoranFrostbeast(*this); - a->isClone = 1; - return a; + return NEW AKjeldoranFrostbeast(*this); } }; @@ -4205,9 +4125,7 @@ public: } AAnimateDead * clone() const { - AAnimateDead * a = NEW AAnimateDead(*this); - a->isClone = 1; - return a; + return NEW AAnimateDead(*this); } }; @@ -4256,9 +4174,7 @@ public: AErgRaiders * clone() const { - AErgRaiders * a = NEW AErgRaiders(*this); - a->isClone = 1; - return a; + return NEW AErgRaiders(*this); } }; @@ -4325,9 +4241,7 @@ public: } AFastbond * clone() const { - AFastbond * a = NEW AFastbond(*this); - a->isClone = 1; - return a; + return NEW AFastbond(*this); } ~AFastbond() @@ -4343,7 +4257,7 @@ public: AJandorsRing(int _id, MTGCardInstance * _source) : ActivatedAbility(_id, _source, NEW ManaCost()) { - cost->add(Constants::MTG_COLOR_ARTIFACT, 2); + getCost()->add(Constants::MTG_COLOR_ARTIFACT, 2); } int isReactingToClick(MTGCardInstance * card, ManaCost * mana = NULL) @@ -4366,9 +4280,7 @@ public: } AJandorsRing * clone() const { - AJandorsRing * a = NEW AJandorsRing(*this); - a->isClone = 1; - return a; + return NEW AJandorsRing(*this); } }; @@ -4442,9 +4354,7 @@ public: AKudzu * clone() const { - AKudzu * a = NEW AKudzu(*this); - a->isClone = 1; - return a; + return NEW AKudzu(*this); } }; @@ -4513,9 +4423,7 @@ public: } APowerLeak * clone() const { - APowerLeak * a = NEW APowerLeak(*this); - a->isClone = 1; - return a; + return NEW APowerLeak(*this); } }; @@ -4548,9 +4456,7 @@ public: } ASacrifice * clone() const { - ASacrifice * a = NEW ASacrifice(*this); - a->isClone = 1; - return a; + return NEW ASacrifice(*this); } }; @@ -4575,9 +4481,7 @@ public: } AEarthbind * clone() const { - AEarthbind * a = NEW AEarthbind(*this); - a->isClone = 1; - return a; + return NEW AEarthbind(*this); } }; @@ -4607,9 +4511,7 @@ public: } AFireball * clone() const { - AFireball * a = NEW AFireball(*this); - a->isClone = 1; - return a; + return NEW AFireball(*this); } }; @@ -4677,9 +4579,7 @@ public: } AIslandSanctuary * clone() const { - AIslandSanctuary * a = NEW AIslandSanctuary(*this); - a->isClone = 1; - return a; + return NEW AIslandSanctuary(*this); } }; @@ -4692,7 +4592,7 @@ public: ActivatedAbility(_id, card, NEW ManaCost(), 0) { paidThisTurn = 1; - cost->add(Constants::MTG_COLOR_BLUE, 1); + getCost()->add(Constants::MTG_COLOR_BLUE, 1); } void Update(float dt) @@ -4748,9 +4648,7 @@ public: } AStasis * clone() const { - AStasis * a = NEW AStasis(*this); - a->isClone = 1; - return a; + return NEW AStasis(*this); } }; @@ -4800,9 +4698,7 @@ public: } ABasilik * clone() const { - ABasilik * a = NEW ABasilik(*this); - a->isClone = 1; - return a; + return NEW ABasilik(*this); } }; @@ -4912,9 +4808,7 @@ public: AMinionofLeshrac * clone() const { - AMinionofLeshrac * a = NEW AMinionofLeshrac(*this); - a->isClone = 1; - return a; + return NEW AMinionofLeshrac(*this); } }; @@ -4958,9 +4852,7 @@ public: ARampageAbility * clone() const { - ARampageAbility * a = NEW ARampageAbility(*this); - a->isClone = 1; - return a; + return NEW ARampageAbility(*this); } }; @@ -5009,9 +4901,7 @@ public: AFlankerAbility * clone() const { - AFlankerAbility * a = NEW AFlankerAbility(*this); - a->isClone = 1; - return a; + return NEW AFlankerAbility(*this); } }; @@ -5066,9 +4956,7 @@ public: ABushidoAbility * clone() const { - ABushidoAbility * a = NEW ABushidoAbility(*this); - a->isClone = 1; - return a; + return NEW ABushidoAbility(*this); } }; @@ -5101,9 +4989,7 @@ public: } ASpiritLinkAbility * clone() const { - ASpiritLinkAbility * a = NEW ASpiritLinkAbility(*this); - a->isClone = 1; - return a; + return NEW ASpiritLinkAbility(*this); } }; @@ -5143,9 +5029,7 @@ public: AInstantControlSteal * clone() const { - AInstantControlSteal * a = NEW AInstantControlSteal(*this); - a->isClone = 1; - return a; + return NEW AInstantControlSteal(*this); } }; diff --git a/projects/mtg/include/MTGAbility.h b/projects/mtg/include/MTGAbility.h index 6d9e8cba5..b1073070f 100644 --- a/projects/mtg/include/MTGAbility.h +++ b/projects/mtg/include/MTGAbility.h @@ -42,6 +42,8 @@ using std::map; class MTGAbility : public ActionElement { +private: + ManaCost* mCost; protected: char menuText[50]; @@ -104,14 +106,10 @@ public: }; - int parseCastRestrictions(MTGCardInstance* card, Player* player, string restrictions, string otherRestrictions); - int allowedToCast(MTGCardInstance* card, Player* player); - int allowedToAltCast(MTGCardInstance* card, Player* player); bool oneShot; int forceDestroy; int forcedAlive; bool canBeInterrupted; - ManaCost* cost; ManaCost* alternative; ManaCost* BuyBack; ManaCost* FlashBack; @@ -124,10 +122,17 @@ public: int naType; int abilitygranted; MTGCardInstance * source; + + int parseCastRestrictions(MTGCardInstance* card, Player* player, string restrictions, string otherRestrictions); + int allowedToCast(MTGCardInstance* card, Player* player); + int allowedToAltCast(MTGCardInstance* card, Player* player); MTGAbility(int id, MTGCardInstance * card); MTGAbility(int id, MTGCardInstance * _source, Targetable * _target); + MTGAbility(const MTGAbility& copyFromMe); virtual int testDestroy(); virtual ~MTGAbility(); + ManaCost * getCost() {return mCost;}; + void setCost(ManaCost * cost, bool forceDelete = 0); virtual void Render() { diff --git a/projects/mtg/include/ThisDescriptor.h b/projects/mtg/include/ThisDescriptor.h index e1b68ae03..acd66330e 100644 --- a/projects/mtg/include/ThisDescriptor.h +++ b/projects/mtg/include/ThisDescriptor.h @@ -1,142 +1,159 @@ -/* - Filter-like system for determining if a card meats certain criteria, for this and thisforeach autos -*/ - -#ifndef _THISDESCRIPTOR_H_ -#define _THISDESCRIPTOR_H_ - -#include "Counters.h" -#include "MTGGameZones.h" -#include "MTGCardInstance.h" -#include "CardDescriptor.h" - -class ThisDescriptor{ - public: - int comparisonMode; - int comparisonCriterion; - virtual int match(MTGCardInstance * card) = 0; - int matchValue(int value); - virtual ~ThisDescriptor(); -}; - -class ThisDescriptorFactory{ -public: - ThisDescriptor * createThisDescriptor(string s); -}; - -class ThisCounter:public ThisDescriptor{ - public: - Counter * counter; - virtual int match(MTGCardInstance * card); - - ThisCounter(Counter * _counter); - ThisCounter(int power, int toughness, int nb, const char * name); - ~ThisCounter(); -}; - -class ThisCounterAny:public ThisDescriptor{ - public: - virtual int match(MTGCardInstance *card); - - ThisCounterAny(int nb); -}; - -class ThisControllerlife:public ThisDescriptor{ - public: - virtual int match(MTGCardInstance * card); - - ThisControllerlife(int life); -}; - -class ThisOpponentlife:public ThisDescriptor{ - public: - virtual int match(MTGCardInstance * card); - - ThisOpponentlife(int olife); -}; - -class ThisEquip:public ThisDescriptor{ - public: - virtual int match(MTGCardInstance * card); - - ThisEquip(int equipment); -}; - -class ThisAuras:public ThisDescriptor{ - public: - virtual int match(MTGCardInstance * card); - - ThisAuras(int auras); -}; - -class ThisOpponentDamageAmount:public ThisDescriptor{ - public: - virtual int match(MTGCardInstance * card); - - ThisOpponentDamageAmount(int damagecount); -}; - -class ThisUntapped:public ThisDescriptor{ - public: - virtual int match(MTGCardInstance * card); - - ThisUntapped(int untapped); -}; - -class ThisTapped:public ThisDescriptor{ - public: - virtual int match(MTGCardInstance * card); - - ThisTapped(int tapped); -}; - - -class ThisAttacked:public ThisDescriptor{ - public: - virtual int match(MTGCardInstance * card); - - ThisAttacked(int attack); -}; - -class ThisBlocked:public ThisDescriptor{ - public: - virtual int match(MTGCardInstance * card); - - ThisBlocked(int block); -}; - -class ThisNotBlocked:public ThisDescriptor{ - public: - virtual int match(MTGCardInstance * card); - - ThisNotBlocked(int unblocked); -}; - -class ThisDamaged:public ThisDescriptor{ - public: - virtual int match(MTGCardInstance * card); - - ThisDamaged(int wasDealtDamage); -}; - -class ThisPower:public ThisDescriptor{ - public: - virtual int match(MTGCardInstance * card); - - ThisPower(int power); -}; - -class ThisToughness:public ThisDescriptor{ - public: - virtual int match(MTGCardInstance * card); - - ThisToughness(int toughness); -}; - -class ThisX:public ThisDescriptor{ - public: - virtual int match(MTGCardInstance * card); - ThisX(int x); -}; - +/* + Filter-like system for determining if a card meets certain criteria, for this and thisforeach autos +*/ + +#ifndef _THISDESCRIPTOR_H_ +#define _THISDESCRIPTOR_H_ + +#include "Counters.h" +#include "MTGGameZones.h" +#include "MTGCardInstance.h" +#include "CardDescriptor.h" + +class ThisDescriptor{ + public: + int comparisonMode; + int comparisonCriterion; + virtual int match(MTGCardInstance * card) = 0; + int matchValue(int value); + virtual ~ThisDescriptor(); + virtual ThisDescriptor * clone() const = 0; +}; + +class ThisDescriptorFactory{ +public: + ThisDescriptor * createThisDescriptor(string s); +}; + +class ThisCounter:public ThisDescriptor{ + public: + Counter * counter; + virtual int match(MTGCardInstance * card); + + ThisCounter(Counter * _counter); + ThisCounter(int power, int toughness, int nb, const char * name); + ~ThisCounter(); + ThisCounter * clone() const; +}; + +class ThisCounterAny:public ThisDescriptor{ + public: + virtual int match(MTGCardInstance *card); + + ThisCounterAny(int nb); + ThisCounterAny * clone() const; +}; + +class ThisControllerlife:public ThisDescriptor{ + public: + virtual int match(MTGCardInstance * card); + + ThisControllerlife(int life); + ThisControllerlife * clone() const; +}; + +class ThisOpponentlife:public ThisDescriptor{ + public: + virtual int match(MTGCardInstance * card); + + ThisOpponentlife(int olife); + ThisOpponentlife * clone() const; +}; + +class ThisEquip:public ThisDescriptor{ + public: + virtual int match(MTGCardInstance * card); + + ThisEquip(int equipment); + ThisEquip * clone() const; +}; + +class ThisAuras:public ThisDescriptor{ + public: + virtual int match(MTGCardInstance * card); + + ThisAuras(int auras); + ThisAuras * clone() const; +}; + +class ThisOpponentDamageAmount:public ThisDescriptor{ + public: + virtual int match(MTGCardInstance * card); + + ThisOpponentDamageAmount(int damagecount); + ThisOpponentDamageAmount * clone() const; +}; + +class ThisUntapped:public ThisDescriptor{ + public: + virtual int match(MTGCardInstance * card); + + ThisUntapped(int untapped); + ThisUntapped * clone() const; +}; + +class ThisTapped:public ThisDescriptor{ + public: + virtual int match(MTGCardInstance * card); + + ThisTapped(int tapped); + ThisTapped * clone() const; +}; + + +class ThisAttacked:public ThisDescriptor{ + public: + virtual int match(MTGCardInstance * card); + + ThisAttacked(int attack); + ThisAttacked * clone() const; +}; + +class ThisBlocked:public ThisDescriptor{ + public: + virtual int match(MTGCardInstance * card); + + ThisBlocked(int block); + ThisBlocked * clone() const; +}; + +class ThisNotBlocked:public ThisDescriptor{ + public: + virtual int match(MTGCardInstance * card); + + ThisNotBlocked(int unblocked); + ThisNotBlocked * clone() const; +}; + +class ThisDamaged:public ThisDescriptor{ + public: + virtual int match(MTGCardInstance * card); + + ThisDamaged(int wasDealtDamage); + ThisDamaged * clone() const; +}; + +class ThisPower:public ThisDescriptor{ + public: + virtual int match(MTGCardInstance * card); + + ThisPower(int power); + ThisPower * clone() const; +}; + +class ThisToughness:public ThisDescriptor{ + public: + virtual int match(MTGCardInstance * card); + + ThisToughness(int toughness); + ThisToughness * clone() const; +}; + +class ThisX:public ThisDescriptor{ + public: + virtual int match(MTGCardInstance * card); + ThisX(int x); + ThisX * clone() const; +}; + #endif diff --git a/projects/mtg/src/AIHints.cpp b/projects/mtg/src/AIHints.cpp index 8646ed89a..548a37eed 100644 --- a/projects/mtg/src/AIHints.cpp +++ b/projects/mtg/src/AIHints.cpp @@ -130,7 +130,7 @@ RankingContainer AIHints::findActions(AIHint * hint) for (int j = 0; j < mPlayer->game->inPlay->nb_cards; j++) { MTGCardInstance * card = mPlayer->game->inPlay->cards[j]; - if (a->isReactingToClick(card, a->cost)) + if (a->isReactingToClick(card, a->getCost())) { mPlayer->createAbilityTargets(a, card, ranking); //TODO make that function static? break; //For performance... ? @@ -177,7 +177,7 @@ string AIHints::constraintsNotFulfilled(AIAction * action, AIHint * hint, ManaCo return "not supported"; //dummy test: would the ability work if we were sure to fulfill its mana requirements? - if (!a->isReactingToClick(card, a->cost)) + if (!a->isReactingToClick(card, a->getCost())) { DebugTrace("This shouldn't happen, this AIAction doesn't seem like a good choice"); return "not supported"; @@ -186,7 +186,7 @@ string AIHints::constraintsNotFulfilled(AIAction * action, AIHint * hint, ManaCo if (!a->isReactingToClick(card, potentialMana)) { //Not enough Mana, try to find which mana we should get in priority - ManaCost * diff = potentialMana->Diff(a->cost); + ManaCost * diff = potentialMana->Diff(a->getCost()); for (int i = 0; i < Constants::MTG_NB_COLORS; i++) { if(diff->getCost(i) < 0) diff --git a/projects/mtg/src/AIMomirPlayer.cpp b/projects/mtg/src/AIMomirPlayer.cpp index 11b851566..4716f7436 100644 --- a/projects/mtg/src/AIMomirPlayer.cpp +++ b/projects/mtg/src/AIMomirPlayer.cpp @@ -18,7 +18,8 @@ AIMomirPlayer::AIMomirPlayer(string file, string fileSmall, string avatarFile, M int AIMomirPlayer::getEfficiency(AIAction * action) { MTGAbility * ability = action->ability; - if (ability->cost && !(ability->cost->isExtraPaymentSet())) return 0; //Does not handle abilities with sacrifice yet + ManaCost * cost = ability->getCost(); + if (cost && !(cost->isExtraPaymentSet())) return 0; //Does not handle abilities with sacrifice yet int efficiency = AIPlayerBaka::getEfficiency(action); GameObserver * g = GameObserver::GetInstance(); diff --git a/projects/mtg/src/AIPlayer.cpp b/projects/mtg/src/AIPlayer.cpp index b34c18198..047383398 100644 --- a/projects/mtg/src/AIPlayer.cpp +++ b/projects/mtg/src/AIPlayer.cpp @@ -242,7 +242,7 @@ int AIPlayer::CanHandleCost(ManaCost * cost) int AIPlayer::canHandleCost(MTGAbility * ability) { - return CanHandleCost(ability->cost); + return CanHandleCost(ability->getCost()); } // In this function, target represents the target of the currentAIAction object, while _target is the target of the ability of this AIAction object @@ -753,9 +753,10 @@ int AIAction::getEfficiency() if (p->game->hand->nb_cards == 0) efficiency = (int) ((float) efficiency * 1.3); //increase chance of using ability if hand is empty - if (ability->cost) + ManaCost * cost = ability->getCost(); + if (cost) { - ExtraCosts * ec = ability->cost->extraCosts; + ExtraCosts * ec = cost->extraCosts; if (ec) { for(unsigned int i = 0; i < ec->costs.size();i++) @@ -816,7 +817,7 @@ int AIPlayer::selectHintAbility() if (!clickstream.size()) { DebugTrace("AIPlayer:Using Activated ability"); - if (tapLandsForMana(action->ability->cost, action->click)) + if (tapLandsForMana(action->ability->getCost(), action->click)) { clickstream.push(action); SAFE_DELETE(totalPotentialMana); @@ -890,7 +891,7 @@ int AIPlayer::selectAbility() if (!clickstream.size()) { DebugTrace("AIPlayer:Using Activated ability"); - if (tapLandsForMana(action.ability->cost, action.click)) + if (tapLandsForMana(action.ability->getCost(), action.click)) clickstream.push(NEW AIAction(action)); } } diff --git a/projects/mtg/src/ActionElement.cpp b/projects/mtg/src/ActionElement.cpp index 0ba8c375d..39c5f3785 100644 --- a/projects/mtg/src/ActionElement.cpp +++ b/projects/mtg/src/ActionElement.cpp @@ -14,15 +14,22 @@ ActionElement::ActionElement(int id) : currentPhase = -1; newPhase = -1; tc = NULL; - isClone = 0; +} + +ActionElement::ActionElement(const ActionElement& a): JGuiObject(a) +{ + activeState = a.activeState; + tc = a.tc ? a.tc->clone() : NULL; + currentPhase = a.currentPhase; + newPhase = a.newPhase; + modal = a.modal; + waitingForAnswer = a.waitingForAnswer; } ActionElement::~ActionElement() { - if (!isClone) - { - SAFE_DELETE(tc); - } + SAFE_DELETE(tc); + } int ActionElement::getActivity() diff --git a/projects/mtg/src/AllAbilities.cpp b/projects/mtg/src/AllAbilities.cpp index c0edcc5ac..078de790d 100644 --- a/projects/mtg/src/AllAbilities.cpp +++ b/projects/mtg/src/AllAbilities.cpp @@ -16,10 +16,14 @@ GenericActivatedAbility::GenericActivatedAbility(string newName,int _id, MTGCard int GenericActivatedAbility::resolve() { - ManaCost * diff = abilityCost->Diff(cost); - source->X = diff->hasX(); - SAFE_DELETE(diff); - //SAFE_DELETE(abilityCost); this line has been reported as a bug. removing it doesn't seem to break anything, although I didn't get any error in the test suite by leaving it either, so... leaving it for now as a comment, in case. + //Note: I've seen a similar block in some other MTGAbility, can this be refactored . + source->X = 0; + if (abilityCost) + { + ManaCost * diff = abilityCost->Diff(getCost()); + source->X = diff->hasX(); + SAFE_DELETE(diff); + } ability->target = target; //may have been updated... if (ability) return ability->resolve(); @@ -60,8 +64,8 @@ int GenericActivatedAbility::testDestroy() GenericActivatedAbility * GenericActivatedAbility::clone() const { GenericActivatedAbility * a = NEW GenericActivatedAbility(*this); - a->cost = NEW ManaCost(); - a->cost->copy(cost); + //a->getCost() = NEW ManaCost(); + //a->getCost()->copy(cost); a->ability = ability->clone(); return a; } @@ -95,9 +99,7 @@ const char * AAAlterPoison::getMenuText() AAAlterPoison * AAAlterPoison::clone() const { - AAAlterPoison * a = NEW AAAlterPoison(*this); - a->isClone = 1; - return a; + return NEW AAAlterPoison(*this); } AAAlterPoison::~AAAlterPoison() @@ -129,9 +131,7 @@ const char * AADamagePrevent::getMenuText() AADamagePrevent * AADamagePrevent::clone() const { - AADamagePrevent * a = NEW AADamagePrevent(*this); - a->isClone = 1; - return a; + return NEW AADamagePrevent(*this); } AADamagePrevent::~AADamagePrevent() @@ -172,9 +172,7 @@ AADamager::AADamager(int _id, MTGCardInstance * _source, Targetable * _target, s AADamager * AADamager::clone() const { - AADamager * a = NEW AADamager(*this); - a->isClone = 1; - return a; + return NEW AADamager(*this); } @@ -217,9 +215,7 @@ const char * AADepleter::getMenuText() AADepleter * AADepleter::clone() const { - AADepleter * a = NEW AADepleter(*this); - a->isClone = 1; - return a; + return NEW AADepleter(*this); } //AACopier @@ -247,9 +243,7 @@ const char * AACopier::getMenuText() AACopier * AACopier::clone() const { - AACopier * a = NEW AACopier(*this); - a->isClone = 1; - return a; + return NEW AACopier(*this); } //phaser @@ -282,9 +276,7 @@ const char * AAPhaseOut::getMenuText() AAPhaseOut * AAPhaseOut::clone() const { - AAPhaseOut * a = NEW AAPhaseOut(*this); - a->isClone = 1; - return a; + return NEW AAPhaseOut(*this); } //Counters @@ -378,9 +370,7 @@ const char* AACounter::getMenuText() AACounter * AACounter::clone() const { - AACounter * a = NEW AACounter(*this); - a->isClone = 1; - return a; + return NEW AACounter(*this); } //Counters @@ -460,9 +450,7 @@ const char* AARemoveAllCounter::getMenuText() AARemoveAllCounter * AARemoveAllCounter::clone() const { - AARemoveAllCounter * a = NEW AARemoveAllCounter(*this); - a->isClone = 1; - return a; + return NEW AARemoveAllCounter(*this); } //Reset Damage on creatures @@ -485,9 +473,7 @@ const char* AAResetDamage::getMenuText() AAResetDamage * AAResetDamage::clone() const { - AAResetDamage * a = NEW AAResetDamage(*this); - a->isClone = 1; - return a; + return NEW AAResetDamage(*this); } @@ -528,9 +514,7 @@ const char * AAFizzler::getMenuText() AAFizzler* AAFizzler::clone() const { - AAFizzler * a = NEW AAFizzler(*this); - a->isClone = 1; - return a; + return NEW AAFizzler(*this); } // BanishCard implementations // Bury @@ -558,9 +542,7 @@ const char * AABuryCard::getMenuText() AABuryCard * AABuryCard::clone() const { - AABuryCard * a = NEW AABuryCard(*this); - a->isClone = 1; - return a; + return NEW AABuryCard(*this); } // Destroy @@ -588,9 +570,7 @@ const char * AADestroyCard::getMenuText() AADestroyCard * AADestroyCard::clone() const { - AADestroyCard * a = NEW AADestroyCard(*this); - a->isClone = 1; - return a; + return NEW AADestroyCard(*this); } // Sacrifice @@ -622,9 +602,7 @@ const char * AASacrificeCard::getMenuText() AASacrificeCard * AASacrificeCard::clone() const { - AASacrificeCard * a = NEW AASacrificeCard(*this); - a->isClone = 1; - return a; + return NEW AASacrificeCard(*this); } // Discard @@ -657,9 +635,7 @@ const char * AADiscardCard::getMenuText() AADiscardCard * AADiscardCard::clone() const { - AADiscardCard * a = NEW AADiscardCard(*this); - a->isClone = 1; - return a; + return NEW AADiscardCard(*this); } AADrawer::AADrawer(int _id, MTGCardInstance * card, Targetable * _target, ManaCost * _cost, string nbcardsStr, @@ -709,9 +685,7 @@ const char * AADrawer::getMenuText() AADrawer * AADrawer::clone() const { - AADrawer * a = NEW AADrawer(*this); - a->isClone = 1; - return a; + return NEW AADrawer(*this); } // AAFrozen: Prevent a card from untapping during next untap phase @@ -740,9 +714,7 @@ const char * AAFrozen::getMenuText() AAFrozen * AAFrozen::clone() const { - AAFrozen * a = NEW AAFrozen(*this); - a->isClone = 1; - return a; + return NEW AAFrozen(*this); } // chose a new target for an aura or enchantment and equip it note: VERY basic right now. @@ -809,7 +781,6 @@ const char * AANewTarget::getMenuText() AANewTarget * AANewTarget::clone() const { AANewTarget * a = NEW AANewTarget(*this); - a->isClone = 1; a->oneShot = 1; return a; } @@ -888,7 +859,6 @@ const char * AAMorph::getMenuText() AAMorph * AAMorph::clone() const { AAMorph * a = NEW AAMorph(*this); - a->isClone = 1; a->forceDestroy = 1; return a; } @@ -1299,14 +1269,13 @@ const char * AADynamic::getMenuText() AADynamic * AADynamic::clone() const { AADynamic * a = NEW AADynamic(*this); - a->isClone = 1; + a->storedAbility = storedAbility? storedAbility->clone() : NULL; return a; } AADynamic::~AADynamic() { - if (!isClone) - SAFE_DELETE(storedAbility); + SAFE_DELETE(storedAbility); } //AALifer @@ -1348,9 +1317,7 @@ const char * AALifer::getMenuText() AALifer * AALifer::clone() const { - AALifer * a = NEW AALifer(*this); - a->isClone = 1; - return a; + return NEW AALifer(*this); } @@ -1389,9 +1356,7 @@ const char * AASetHand::getMenuText() AASetHand * AASetHand::clone() const { - AASetHand * a = NEW AASetHand(*this); - a->isClone = 1; - return a; + return NEW AASetHand(*this); } //Lifeset @@ -1432,7 +1397,6 @@ AALifeSet * AALifeSet::clone() const { AALifeSet * a = NEW AALifeSet(*this); a->life = NEW WParsedInt(*(a->life)); - a->isClone = 1; return a; } @@ -1518,9 +1482,7 @@ ostream& AACloner::toString(ostream& out) const AACloner * AACloner::clone() const { - AACloner * a = NEW AACloner(*this); - a->isClone = 1; - return a; + return NEW AACloner(*this); } AACloner::~AACloner() { @@ -1599,7 +1561,6 @@ ACastRestriction * ACastRestriction::clone() const ACastRestriction * a = NEW ACastRestriction(*this); a->value = NEW WParsedInt(*(a->value)); a->restrictionsScope = restrictionsScope->clone(); - a->isClone = 1; return a; } @@ -1632,7 +1593,6 @@ AInstantCastRestrictionUEOT * AInstantCastRestrictionUEOT::clone() const { AInstantCastRestrictionUEOT * a = NEW AInstantCastRestrictionUEOT(*this); a->ability = this->ability->clone(); - a->isClone = 1; return a; } @@ -1756,9 +1716,7 @@ const char * AAMover::getMenuText(TargetChooser * tc) AAMover * AAMover::clone() const { - AAMover * a = NEW AAMover(*this); - a->isClone = 1; - return a; + return NEW AAMover(*this); } //Random Discard @@ -1801,9 +1759,7 @@ const char * AARandomDiscarder::getMenuText() AARandomDiscarder * AARandomDiscarder::clone() const { - AARandomDiscarder * a = NEW AARandomDiscarder(*this); - a->isClone = 1; - return a; + return NEW AARandomDiscarder(*this); } // Shuffle @@ -1839,9 +1795,7 @@ const char * AAShuffle::getMenuText() AAShuffle * AAShuffle::clone() const { - AAShuffle * a = NEW AAShuffle(*this); - a->isClone = 1; - return a; + return NEW AAShuffle(*this); } // Remove Mana From ManaPool @@ -1910,7 +1864,6 @@ AARemoveMana * AARemoveMana::clone() const { AARemoveMana * a = NEW AARemoveMana(*this); a->mManaDesc = mManaDesc ? NEW ManaCost(mManaDesc) : NULL; - a->isClone = 1; return a; } @@ -1946,9 +1899,7 @@ const char * AATapper::getMenuText() AATapper * AATapper::clone() const { - AATapper * a = NEW AATapper(*this); - a->isClone = 1; - return a; + return NEW AATapper(*this); } //AA Untapper @@ -1978,9 +1929,7 @@ const char * AAUntapper::getMenuText() AAUntapper * AAUntapper::clone() const { - AAUntapper * a = NEW AAUntapper(*this); - a->isClone = 1; - return a; + return NEW AAUntapper(*this); } AAWhatsMax::AAWhatsMax(int id, MTGCardInstance * card, MTGCardInstance * source, ManaCost * _cost, int value) : @@ -2001,9 +1950,7 @@ int AAWhatsMax::resolve() AAWhatsMax * AAWhatsMax::clone() const { - AAWhatsMax * a = NEW AAWhatsMax(*this); - a->isClone = 1; - return a; + return NEW AAWhatsMax(*this); } // Win Game @@ -2058,9 +2005,7 @@ const char * AAWinGame::getMenuText() AAWinGame * AAWinGame::clone() const { - AAWinGame * a = NEW AAWinGame(*this); - a->isClone = 1; - return a; + return NEW AAWinGame(*this); } //Generic Abilities @@ -2101,9 +2046,7 @@ const char * IfThenAbility::getMenuText() IfThenAbility * IfThenAbility::clone() const { - IfThenAbility * a = NEW IfThenAbility(*this); - a->isClone = 1; - return a; + return NEW IfThenAbility(*this); } // @@ -2171,7 +2114,6 @@ MayAbility * MayAbility::clone() const { MayAbility * a = NEW MayAbility(*this); a->ability = ability->clone(); - a->isClone = 1; return a; } @@ -2254,20 +2196,24 @@ const char * MultiAbility::getMenuText() MultiAbility * MultiAbility::clone() const { MultiAbility * a = NEW MultiAbility(*this); - a->isClone = 1; + a->abilities.clear(); + vector::size_type sz = abilities.size(); + for (size_t i = 0; i < sz; i++) + { + a->abilities.push_back(abilities[i]->clone()); + } return a; } MultiAbility::~MultiAbility() { - if (!isClone) + + vector::size_type sz = abilities.size(); + for (size_t i = 0; i < sz; i++) { - vector::size_type sz = abilities.size(); - for (size_t i = 0; i < sz; i++) - { - SAFE_DELETE(abilities[i]); - } + SAFE_DELETE(abilities[i]); } + abilities.clear(); } @@ -2342,10 +2288,6 @@ GenericTargetAbility * GenericTargetAbility::clone() const { GenericTargetAbility * a = NEW GenericTargetAbility(*this); a->ability = ability->clone(); - a->cost = NEW ManaCost(); - a->cost->copy(cost); - if (tc) - a->tc = tc->clone(); return a; } @@ -2466,9 +2408,7 @@ void AAlterCost::decreaseTheCost(MTGCardInstance * card) AAlterCost * AAlterCost::clone() const { - AAlterCost * a = NEW AAlterCost(*this); - a->isClone = 1; - return a; + return NEW AAlterCost(*this); } AAlterCost::~AAlterCost() @@ -2770,9 +2710,7 @@ const char * ATransformer::getMenuText() ATransformer * ATransformer::clone() const { - ATransformer * a = NEW ATransformer(*this); - a->isClone = 1; - return a; + return NEW ATransformer(*this); } ATransformer::~ATransformer() @@ -2803,7 +2741,6 @@ ATransformerInstant * ATransformerInstant::clone() const { ATransformerInstant * a = NEW ATransformerInstant(*this); a->ability = this->ability->clone(); - a->isClone = 1; return a; } @@ -2835,7 +2772,6 @@ PTInstant * PTInstant::clone() const { PTInstant * a = NEW PTInstant(*this); a->ability = this->ability->clone(); - a->isClone = 1; return a; } @@ -2868,7 +2804,6 @@ ASwapPTUEOT * ASwapPTUEOT::clone() const { ASwapPTUEOT * a = NEW ASwapPTUEOT(*this); a->ability = this->ability->clone(); - a->isClone = 1; return a; } @@ -2980,9 +2915,7 @@ int ALoseAbilities::destroy() ALoseAbilities * ALoseAbilities::clone() const { - ALoseAbilities * a = NEW ALoseAbilities(*this); - a->isClone = 1; - return a; + return NEW ALoseAbilities(*this); } //ALoseSubtypes @@ -3025,9 +2958,7 @@ int ALoseSubtypes::destroy() ALoseSubtypes * ALoseSubtypes::clone() const { - ALoseSubtypes * a = NEW ALoseSubtypes(*this); - a->isClone = 1; - return a; + return NEW ALoseSubtypes(*this); } //APreventDamageTypes @@ -3077,7 +3008,7 @@ int APreventDamageTypes::destroy() APreventDamageTypes * APreventDamageTypes::clone() const { APreventDamageTypes * a = NEW APreventDamageTypes(*this); - a->isClone = 1; + a->re = NULL; return a; } @@ -3120,7 +3051,6 @@ APreventDamageTypesUEOT * APreventDamageTypesUEOT::clone() const { APreventDamageTypesUEOT * a = NEW APreventDamageTypesUEOT(*this); a->ability = this->ability->clone(); - a->isClone = 1; return a; } @@ -3194,9 +3124,7 @@ return "Fading"; AVanishing * AVanishing::clone() const { - AVanishing * a = NEW AVanishing(*this); - a->isClone = 1; - return a; + return NEW AVanishing(*this); } AVanishing::~AVanishing() @@ -3283,14 +3211,13 @@ ostream& AUpkeep::toString(ostream& out) const AUpkeep * AUpkeep::clone() const { AUpkeep * a = NEW AUpkeep(*this); - a->isClone = 1; + a->ability = ability->clone(); return a; } AUpkeep::~AUpkeep() { - if (!isClone) - SAFE_DELETE(ability); + SAFE_DELETE(ability); } //A Phase based Action @@ -3372,7 +3299,6 @@ APhaseAction * APhaseAction::clone() const APhaseAction * a = NEW APhaseAction(*this); if(forcedestroy == false) a->forceDestroy = -1;// we want this ability to stay alive until it resolves. - a->isClone = 1; return a; } @@ -3407,7 +3333,6 @@ APhaseActionGeneric * APhaseActionGeneric::clone() const APhaseActionGeneric * a = NEW APhaseActionGeneric(*this); a->ability = this->ability->clone(); a->oneShot = 1; - a->isClone = 1; return a; } @@ -3617,14 +3542,13 @@ const char * ABlink::getMenuText() ABlink * ABlink::clone() const { ABlink * a = NEW ABlink(*this); - a->isClone = 1; + a->stored = stored ? stored->clone() : NULL; a->forceDestroy = -1; return a; }; ABlink::~ABlink() { - if (!isClone) - SAFE_DELETE(stored); + SAFE_DELETE(stored); } ABlinkGeneric::ABlinkGeneric(int _id, MTGCardInstance * card, MTGCardInstance * _target,bool blinkueot,bool blinkForSource,bool blinkhand,MTGAbility * stored) : @@ -3651,7 +3575,6 @@ ABlinkGeneric * ABlinkGeneric::clone() const ABlinkGeneric * a = NEW ABlinkGeneric(*this); a->ability = this->ability->clone(); a->oneShot = 1; - a->isClone = 1; return a; } diff --git a/projects/mtg/src/MTGAbility.cpp b/projects/mtg/src/MTGAbility.cpp index 1adb7207b..dccd68144 100644 --- a/projects/mtg/src/MTGAbility.cpp +++ b/projects/mtg/src/MTGAbility.cpp @@ -858,7 +858,7 @@ MTGAbility * AbilityFactory::parseMagicLine(string s, int id, Spell * spell, MTG AManaProducer * amp = dynamic_cast (a); if (amp) { - amp->cost = cost; + amp->setCost(cost); if (cost && card->typeAsTarget() == TARGET_CARD) cost->setExtraCostsAction(a, card); amp->oneShot = 0; @@ -873,7 +873,7 @@ MTGAbility * AbilityFactory::parseMagicLine(string s, int id, Spell * spell, MTG AEquip *ae = dynamic_cast (a); if (ae) { - ae->cost = cost; + ae->setCost(cost); if (!tc) { TargetChooserFactory tcf; @@ -3302,6 +3302,42 @@ MTGAbility * AbilityFactory::getManaReduxAbility(string s, int id, Spell *spell, return NEW AAlterCost(id, card, target, amount, color); } +MTGAbility::MTGAbility(const MTGAbility& a): ActionElement(a) +{ + //Todo get rid of menuText, it is only used as a placeholder in getMenuText, for something that could be a string + for (int i = 0; i < 50; ++i) + { + menuText[i] = a.menuText[i]; + } + + game = a.game; + + oneShot = a.oneShot; + forceDestroy = a.forceDestroy; + forcedAlive = a.forcedAlive; + canBeInterrupted = a.canBeInterrupted; + + //costs get copied, and will be deleted in the destructor + mCost = a.mCost ? NEW ManaCost(a.mCost) : NULL; + + //alternative costs are not deleted in the destructor...who deletes them??? + alternative = a.alternative; // ? NEW ManaCost(a.alternative) : NULL; + BuyBack = a.BuyBack; //? NEW ManaCost(a.BuyBack) : NULL; + FlashBack = a.FlashBack; // ? NEW ManaCost(a.FlashBack) : NULL; + Retrace = a.Retrace;// ? NEW ManaCost(a.Retrace) : NULL; + morph = a.morph; //? NEW ManaCost(a.morph) : NULL; + suspend = a.suspend;// ? NEW ManaCost(a.suspend) : NULL; + + //Those two are pointers, but we don't delete them in the destructor, no need to copy them + target = a.target; + source = a.source; + + aType = a.aType; + naType = a.naType; + abilitygranted = a.abilitygranted; + +}; + MTGAbility::MTGAbility(int id, MTGCardInstance * card) : ActionElement(id) { @@ -3309,7 +3345,7 @@ MTGAbility::MTGAbility(int id, MTGCardInstance * card) : source = card; target = card; aType = MTGAbility::UNKNOWN; - cost = NULL; + mCost = NULL; forceDestroy = 0; oneShot = 0; canBeInterrupted = true; @@ -3322,12 +3358,22 @@ MTGAbility::MTGAbility(int id, MTGCardInstance * _source, Targetable * _target) source = _source; target = _target; aType = MTGAbility::UNKNOWN; - cost = NULL; + mCost = NULL; forceDestroy = 0; oneShot = 0; canBeInterrupted = true; } +void MTGAbility::setCost(ManaCost * cost, bool forceDelete) +{ + if (mCost) { + DebugTrace("WARNING: Mtgability.cpp, attempt to set cost when previous cost is not null"); + if (forceDelete) + delete(mCost); + } + mCost = cost; +} + int MTGAbility::stillInUse(MTGCardInstance * card) { if (card == source || card == target) @@ -3337,10 +3383,7 @@ int MTGAbility::stillInUse(MTGCardInstance * card) MTGAbility::~MTGAbility() { - if (!isClone) - { - SAFE_DELETE(cost); - } + SAFE_DELETE(mCost); } int MTGAbility::addToGame() @@ -3392,7 +3435,7 @@ int MTGAbility::fireAbility() ostream& MTGAbility::toString(ostream& out) const { return out << "MTGAbility ::: menuText : " << menuText << " ; game : " << game << " ; forceDestroy : " << forceDestroy - << " ; cost : " << cost << " ; target : " << target << " ; aType : " << aType << " ; source : " << source; + << " ; mCost : " << mCost << " ; target : " << target << " ; aType : " << aType << " ; source : " << source; } NestedAbility::NestedAbility(MTGAbility * _ability) @@ -3406,7 +3449,7 @@ ActivatedAbility::ActivatedAbility(int id, MTGCardInstance * card, ManaCost * _c MTGAbility(id, card), restrictions(restrictions), needsTapping(0),limit(limit),sideEffect(sideEffect),usesBeforeSideEffects(usesBeforeSideEffects) { counters = 0; - cost = _cost; + setCost(_cost); abilityCost = 0; sa = NULL; } @@ -3473,6 +3516,7 @@ int ActivatedAbility::isReactingToClick(MTGCardInstance * card, ManaCost * mana) if (card == source && source->controller() == player && (!needsTapping || (!source->isTapped() && !source->hasSummoningSickness()))) { + ManaCost * cost = getCost(); if (!cost) return 1; cost->setExtraCostsAction(this, card); @@ -3492,6 +3536,7 @@ int ActivatedAbility::reactToClick(MTGCardInstance * card) if (!isReactingToClick(card)) return 0; Player * player = game->currentlyActing(); + ManaCost * cost = getCost(); if (cost) { if (!cost->isExtraPaymentSet()) @@ -3514,6 +3559,7 @@ int ActivatedAbility::reactToTargetClick(Targetable * object) if (!isReactingToTargetClick(object)) return 0; Player * player = game->currentlyActing(); + ManaCost * cost = getCost(); if (cost) { if (object->typeAsTarget() == TARGET_CARD) @@ -3542,6 +3588,7 @@ int ActivatedAbility::activateAbility() fmp = af.getCoreAbility(this); AManaProducer * amp = dynamic_cast (this); AManaProducer * femp = dynamic_cast (fmp); + ManaCost * cost = getCost(); if((amp||femp) && cost && cost->extraCosts) { for(unsigned int i = 0; i < cost->extraCosts->costs.size();i++) @@ -3612,14 +3659,9 @@ void ActivatedAbility::activateSideEffect() ActivatedAbility::~ActivatedAbility() { - //Ok, this will probably lead to crashes, maybe with lord abilities involving "X" costs. - // If that's the case, we need to improve the clone() method of GenericActivatedAbility and GenericTargetAbility, I think - // Erwan 2004/04/25 - //if (!isClone){ SAFE_DELETE(abilityCost); SAFE_DELETE(sideEffect); SAFE_DELETE(sa); - //} } ostream& ActivatedAbility::toString(ostream& out) const @@ -3663,6 +3705,7 @@ int TargetAbility::reactToClick(MTGCardInstance * card) { if (isReactingToClick(card)) { + ManaCost * cost = getCost(); if (cost && !cost->isExtraPaymentSet()) { game->mExtraPayment = cost->extraCosts; @@ -3716,9 +3759,14 @@ int TargetAbility::resolve() Targetable * t = tc->getNextTarget(); if (t && ability) { - ManaCost * diff = abilityCost->Diff(cost); - source->X = diff->hasX(); - delete (diff); + source->X = 0; + if (abilityCost) + { + ManaCost * diff = abilityCost->Diff(getCost()); + source->X = diff->hasX(); + delete (diff); + } + ability->target = t; //do nothing if the target controller responded by phasing out the target. if (t->typeAsTarget() == TARGET_CARD && ((MTGCardInstance*)t)->isPhased) @@ -3740,8 +3788,7 @@ const char * TargetAbility::getMenuText() TargetAbility::~TargetAbility() { - if (!isClone) - SAFE_DELETE(ability); + SAFE_DELETE(ability); } ostream& TargetAbility::toString(ostream& out) const @@ -4009,9 +4056,7 @@ TriggerAtPhase::TriggerAtPhase(int id, MTGCardInstance * source, Targetable * ta TriggerAtPhase* TriggerAtPhase::clone() const { - TriggerAtPhase * a = NEW TriggerAtPhase(*this); - a->isClone = 1; - return a; + return NEW TriggerAtPhase(*this); } TriggerNextPhase::TriggerNextPhase(int id, MTGCardInstance * source, Targetable * target, int _phaseId, int who,bool sourceUntapped, bool sourceTap,bool once) : @@ -4036,9 +4081,7 @@ int TriggerNextPhase::testDestroy() TriggerNextPhase* TriggerNextPhase::clone() const { - TriggerNextPhase * a = NEW TriggerNextPhase(*this); - a->isClone = 1; - return a; + return NEW TriggerNextPhase(*this); } GenericTriggeredAbility::GenericTriggeredAbility(int id, MTGCardInstance * _source, TriggeredAbility * _t, MTGAbility * a, @@ -4156,12 +4199,9 @@ int GenericTriggeredAbility::testDestroy() GenericTriggeredAbility::~GenericTriggeredAbility() { - if (!isClone) - { - delete t; - delete ability; - SAFE_DELETE(destroyCondition); - } + delete t; + delete ability; + SAFE_DELETE(destroyCondition); } const char * GenericTriggeredAbility::getMenuText() @@ -4171,8 +4211,10 @@ const char * GenericTriggeredAbility::getMenuText() GenericTriggeredAbility* GenericTriggeredAbility::clone() const { - GenericTriggeredAbility * a = NEW GenericTriggeredAbility(*this); - a->isClone = 1; + GenericTriggeredAbility * a = NEW GenericTriggeredAbility(*this); + a->t = t->clone(); + a->ability = ability->clone(); + a->destroyCondition = destroyCondition->clone(); return a; } @@ -4188,7 +4230,7 @@ AManaProducer::AManaProducer(int id, MTGCardInstance * card, Targetable * t, Man { aType = MTGAbility::MANA_PRODUCER; - cost = _cost; + setCost(_cost); output = _output; menutext = ""; @@ -4202,6 +4244,7 @@ int AManaProducer::isReactingToClick(MTGCardInstance * _card, ManaCost * mana) if (_card == source && (!tap || !source->isTapped()) && game->currentlyActing()->game->inPlay->hasCard(source) && (source->hasType(Subtypes::TYPE_LAND) || !tap || !source->hasSummoningSickness()) && !source->isPhased) { + ManaCost * cost = getCost(); if (!cost || mana->canAfford(cost)) { result = 1; @@ -4236,6 +4279,8 @@ int AManaProducer::reactToClick(MTGCardInstance * _card) return 0; if(!ActivatedAbility::isReactingToClick(_card)) return 0; + + ManaCost * cost = getCost(); if (cost) { cost->setExtraCostsAction(this, _card); @@ -4302,18 +4347,14 @@ const char * AManaProducer::getMenuText() AManaProducer::~AManaProducer() { - SAFE_DELETE(cost); SAFE_DELETE(output); } AManaProducer * AManaProducer::clone() const { AManaProducer * a = NEW AManaProducer(*this); - a->cost = NEW ManaCost(); a->output = NEW ManaCost(); - a->cost->copy(cost); a->output->copy(output); - a->isClone = 1; return a; } diff --git a/projects/mtg/src/MTGGamePhase.cpp b/projects/mtg/src/MTGGamePhase.cpp index 955329b41..1deba8394 100644 --- a/projects/mtg/src/MTGGamePhase.cpp +++ b/projects/mtg/src/MTGGamePhase.cpp @@ -53,9 +53,7 @@ bool MTGGamePhase::CheckUserInput(JButton key) MTGGamePhase * MTGGamePhase::clone() const { - MTGGamePhase * a = NEW MTGGamePhase(*this); - a->isClone = 1; - return a; + return NEW MTGGamePhase(*this); } ostream& MTGGamePhase::toString(ostream& out) const diff --git a/projects/mtg/src/MTGRules.cpp b/projects/mtg/src/MTGRules.cpp index 68d31c6e4..3637531dd 100644 --- a/projects/mtg/src/MTGRules.cpp +++ b/projects/mtg/src/MTGRules.cpp @@ -278,9 +278,7 @@ void MTGEventBonus::Render() MTGEventBonus * MTGEventBonus::clone() const { - MTGEventBonus * a = NEW MTGEventBonus(*this); - a->isClone = 1; - return a; + return NEW MTGEventBonus(*this); } // @@ -469,9 +467,7 @@ ostream& MTGPutInPlayRule::toString(ostream& out) const MTGPutInPlayRule * MTGPutInPlayRule::clone() const { - MTGPutInPlayRule * a = NEW MTGPutInPlayRule(*this); - a->isClone = 1; - return a; + return NEW MTGPutInPlayRule(*this); } @@ -593,9 +589,7 @@ ostream& MTGKickerRule::toString(ostream& out) const MTGKickerRule * MTGKickerRule::clone() const { - MTGKickerRule * a = NEW MTGKickerRule(*this); - a->isClone = 1; - return a; + return NEW MTGKickerRule(*this); } @@ -757,9 +751,7 @@ ostream& MTGAlternativeCostRule::toString(ostream& out) const MTGAlternativeCostRule * MTGAlternativeCostRule::clone() const { - MTGAlternativeCostRule * a = NEW MTGAlternativeCostRule(*this); - a->isClone = 1; - return a; + return NEW MTGAlternativeCostRule(*this); } //------------------------------------------------------------------------- @@ -811,9 +803,7 @@ ostream& MTGBuyBackRule::toString(ostream& out) const MTGBuyBackRule * MTGBuyBackRule::clone() const { - MTGBuyBackRule * a = NEW MTGBuyBackRule(*this); - a->isClone = 1; - return a; + return NEW MTGBuyBackRule(*this); } //------------------------------------------------------------------------- @@ -860,9 +850,7 @@ ostream& MTGFlashBackRule::toString(ostream& out) const } MTGFlashBackRule * MTGFlashBackRule::clone() const { - MTGFlashBackRule * a = NEW MTGFlashBackRule(*this); - a->isClone = 1; - return a; + return NEW MTGFlashBackRule(*this); } //------------------------------------------------------------------------- @@ -915,9 +903,7 @@ ostream& MTGRetraceRule::toString(ostream& out) const } MTGRetraceRule * MTGRetraceRule::clone() const { - MTGRetraceRule * a = NEW MTGRetraceRule(*this); - a->isClone = 1; - return a; + return NEW MTGRetraceRule(*this); } //------------------------------------------------------------------------- @@ -985,7 +971,7 @@ int MTGSuspendRule::reactToClick(MTGCardInstance * card) else { alternateCost->setExtraCostsAction(this, card); - game->mExtraPayment = cost->suspend->extraCosts; + game->mExtraPayment = getCost()->suspend->extraCosts; return 0; } card->paymenttype = MTGAbility::SUSPEND_COST; @@ -1016,9 +1002,7 @@ ostream& MTGSuspendRule::toString(ostream& out) const } MTGSuspendRule * MTGSuspendRule::clone() const { - MTGSuspendRule * a = NEW MTGSuspendRule(*this); - a->isClone = 1; - return a; + return NEW MTGSuspendRule(*this); } //------------------------------------------------------------------------- @@ -1146,9 +1130,7 @@ ostream& MTGMorphCostRule::toString(ostream& out) const MTGMorphCostRule * MTGMorphCostRule::clone() const { - MTGMorphCostRule * a = NEW MTGMorphCostRule(*this); - a->isClone = 1; - return a; + return NEW MTGMorphCostRule(*this); } //------------------------------------------------------------------------- @@ -1252,9 +1234,7 @@ ostream& MTGAttackRule::toString(ostream& out) const MTGAttackRule * MTGAttackRule::clone() const { - MTGAttackRule * a = NEW MTGAttackRule(*this); - a->isClone = 1; - return a; + return NEW MTGAttackRule(*this); } //this rules handles returning cards to combat triggers for activations. @@ -1372,9 +1352,7 @@ ostream& MTGCombatTriggersRule::toString(ostream& out) const MTGCombatTriggersRule * MTGCombatTriggersRule::clone() const { - MTGCombatTriggersRule * a = NEW MTGCombatTriggersRule(*this); - a->isClone = 1; - return a; + return NEW MTGCombatTriggersRule(*this); } ///------------ @@ -1410,9 +1388,7 @@ int OtherAbilitiesEventReceiver::testDestroy() OtherAbilitiesEventReceiver * OtherAbilitiesEventReceiver::clone() const { - OtherAbilitiesEventReceiver * a = NEW OtherAbilitiesEventReceiver(*this); - a->isClone = 1; - return a; + return NEW OtherAbilitiesEventReceiver(*this); } MTGBlockRule::MTGBlockRule(int _id) : @@ -1467,9 +1443,7 @@ ostream& MTGBlockRule::toString(ostream& out) const MTGBlockRule * MTGBlockRule::clone() const { - MTGBlockRule * a = NEW MTGBlockRule(*this); - a->isClone = 1; - return a; + return NEW MTGBlockRule(*this); } // // Attacker chooses blockers order @@ -1625,9 +1599,7 @@ ostream& MTGMomirRule::toString(ostream& out) const MTGMomirRule * MTGMomirRule::clone() const { - MTGMomirRule * a = NEW MTGMomirRule(*this); - a->isClone = 1; - return a; + return NEW MTGMomirRule(*this); } //stone hewer game mode @@ -1735,9 +1707,7 @@ ostream& MTGStoneHewerRule::toString(ostream& out) const MTGStoneHewerRule * MTGStoneHewerRule::clone() const { - MTGStoneHewerRule * a = NEW MTGStoneHewerRule(*this); - a->isClone = 1; - return a; + return NEW MTGStoneHewerRule(*this); } //------------------ @@ -1782,9 +1752,7 @@ int MTGHermitRule::testDestroy() MTGHermitRule * MTGHermitRule::clone() const { - MTGHermitRule * a = NEW MTGHermitRule(*this); - a->isClone = 1; - return a; + return NEW MTGHermitRule(*this); } //-------------------- @@ -1903,9 +1871,7 @@ HUDDisplay::~HUDDisplay() HUDDisplay * HUDDisplay::clone() const { - HUDDisplay * a = NEW HUDDisplay(*this); - a->isClone = 1; - return a; + return NEW HUDDisplay(*this); } /* Persist */ @@ -1966,9 +1932,7 @@ int MTGPersistRule::testDestroy() } MTGPersistRule * MTGPersistRule::clone() const { - MTGPersistRule * a = NEW MTGPersistRule(*this); - a->isClone = 1; - return a; + return NEW MTGPersistRule(*this); } //vampires rule @@ -2044,9 +2008,7 @@ int MTGVampireRule::testDestroy() } MTGVampireRule * MTGVampireRule::clone() const { - MTGVampireRule * a = NEW MTGVampireRule(*this); - a->isClone = 1; - return a; + return NEW MTGVampireRule(*this); } ///////////////////////////////////////////////// //unearth rule---------------------------------- @@ -2108,9 +2070,7 @@ int MTGUnearthRule::testDestroy() } MTGUnearthRule * MTGUnearthRule::clone() const { - MTGUnearthRule * a = NEW MTGUnearthRule(*this); - a->isClone = 1; - return a; + return NEW MTGUnearthRule(*this); } //token clean up MTGTokensCleanup::MTGTokensCleanup(int _id) : @@ -2142,9 +2102,7 @@ int MTGTokensCleanup::testDestroy() MTGTokensCleanup * MTGTokensCleanup::clone() const { - MTGTokensCleanup * a = NEW MTGTokensCleanup(*this); - a->isClone = 1; - return a; + return NEW MTGTokensCleanup(*this); } /* Legend Rule */ @@ -2201,9 +2159,7 @@ ostream& MTGLegendRule::toString(ostream& out) const } MTGLegendRule * MTGLegendRule::clone() const { - MTGLegendRule * a = NEW MTGLegendRule(*this); - a->isClone = 1; - return a; + return NEW MTGLegendRule(*this); } /* PlaneWalker Rule */ @@ -2260,9 +2216,7 @@ ostream& MTGPlaneWalkerRule::toString(ostream& out) const } MTGPlaneWalkerRule * MTGPlaneWalkerRule::clone() const { - MTGPlaneWalkerRule * a = NEW MTGPlaneWalkerRule(*this); - a->isClone = 1; - return a; + return NEW MTGPlaneWalkerRule(*this); } /* Lifelink */ @@ -2300,9 +2254,7 @@ ostream& MTGLifelinkRule::toString(ostream& out) const } MTGLifelinkRule * MTGLifelinkRule::clone() const { - MTGLifelinkRule * a = NEW MTGLifelinkRule(*this); - a->isClone = 1; - return a; + return NEW MTGLifelinkRule(*this); } /* Deathtouch */ @@ -2346,7 +2298,5 @@ int MTGDeathtouchRule::testDestroy() MTGDeathtouchRule * MTGDeathtouchRule::clone() const { - MTGDeathtouchRule * a = NEW MTGDeathtouchRule(*this); - a->isClone = 1; - return a; + return NEW MTGDeathtouchRule(*this); } diff --git a/projects/mtg/src/ManaCost.cpp b/projects/mtg/src/ManaCost.cpp index 70766f955..a04e4d19b 100644 --- a/projects/mtg/src/ManaCost.cpp +++ b/projects/mtg/src/ManaCost.cpp @@ -274,8 +274,7 @@ ManaCost::ManaCost(ManaCost * manaCost) morph = NEW ManaCost( manaCost->morph ); suspend = NEW ManaCost( manaCost->suspend ); - // TODO: Need to figure out if a deep copy is necessary - extraCosts = manaCost->extraCosts; + extraCosts = manaCost->extraCosts ? manaCost->extraCosts->clone() : NULL; } // Copy Constructor @@ -301,8 +300,7 @@ ManaCost::ManaCost(const ManaCost& manaCost) morph = NEW ManaCost( manaCost.morph ); suspend = NEW ManaCost( manaCost.suspend ); - // TODO: Need to figure out if a deep copy is necessary - extraCosts = manaCost.extraCosts; + extraCosts = manaCost.extraCosts ? manaCost.extraCosts->clone() : NULL; } // operator= @@ -674,6 +672,9 @@ int ManaCost::tryToPayHybrids(std::vector& _hybrids, int _nbhybr //compute the difference between two mana costs ManaCost * ManaCost::Diff(ManaCost * _cost) { + if (!_cost) + return NEW ManaCost(*this); //diff with null is equivalent to diff with 0 + int8_t diff[(Constants::MTG_NB_COLORS + 1) * 2]; diff[Constants::MTG_NB_COLORS * 2] = Constants::MTG_NB_COLORS; for (int i = 0; i < Constants::MTG_NB_COLORS; i++) diff --git a/projects/mtg/src/ThisDescriptor.cpp b/projects/mtg/src/ThisDescriptor.cpp index 0db634d5a..fb4c5c11e 100644 --- a/projects/mtg/src/ThisDescriptor.cpp +++ b/projects/mtg/src/ThisDescriptor.cpp @@ -369,6 +369,13 @@ ThisCounter::~ThisCounter() SAFE_DELETE(counter); } +ThisCounter* ThisCounter::clone() const +{ + ThisCounter * a = NEW ThisCounter(*this); + a->counter = NEW Counter(NULL, counter->name.c_str(), counter->power, counter->toughness); + return a; +} + ThisOpponentlife::ThisOpponentlife(int olife) { comparisonCriterion = olife; @@ -379,6 +386,11 @@ int ThisOpponentlife::match(MTGCardInstance * card) return matchValue(card->controller()->opponent()->life); } +ThisOpponentlife* ThisOpponentlife::clone() const +{ + return NEW ThisOpponentlife(*this); +} + ThisControllerlife::ThisControllerlife(int life) { comparisonCriterion = life; @@ -389,6 +401,11 @@ int ThisControllerlife::match(MTGCardInstance * card) return matchValue(card->controller()->life); } +ThisControllerlife* ThisControllerlife::clone() const +{ + return NEW ThisControllerlife(*this); +} + ThisPower::ThisPower(int power) { comparisonCriterion = power; @@ -399,6 +416,11 @@ int ThisPower::match(MTGCardInstance * card) return matchValue(card->power); } +ThisPower* ThisPower::clone() const +{ + return NEW ThisPower(*this); +} + ThisEquip::ThisEquip(int equipment) { comparisonCriterion = equipment; @@ -408,6 +430,11 @@ int ThisEquip::match(MTGCardInstance * card) return matchValue(card->equipment); } +ThisEquip* ThisEquip::clone() const +{ + return NEW ThisEquip(*this); +} + ThisAuras::ThisAuras(int auras) { comparisonCriterion = auras; @@ -417,6 +444,11 @@ int ThisAuras::match(MTGCardInstance * card) return matchValue(card->auras); } +ThisAuras* ThisAuras::clone() const +{ + return NEW ThisAuras(*this); +} + ThisOpponentDamageAmount::ThisOpponentDamageAmount(int damagecount) { comparisonCriterion = damagecount; @@ -426,6 +458,11 @@ int ThisOpponentDamageAmount::match(MTGCardInstance * card) return matchValue(card->controller()->opponent()->damageCount); } +ThisOpponentDamageAmount* ThisOpponentDamageAmount::clone() const +{ + return NEW ThisOpponentDamageAmount(*this); +} + ThisUntapped::ThisUntapped(int untapped) { comparisonCriterion = untapped; @@ -435,6 +472,11 @@ int ThisUntapped::match(MTGCardInstance * card) return matchValue(!card->isTapped()); } +ThisUntapped* ThisUntapped::clone() const +{ + return NEW ThisUntapped(*this); +} + ThisTapped::ThisTapped(int tapped) { comparisonCriterion = tapped; @@ -444,6 +486,11 @@ int ThisTapped::match(MTGCardInstance * card) return matchValue(card->isTapped()); } +ThisTapped* ThisTapped::clone() const +{ + return NEW ThisTapped(*this); +} + ThisAttacked::ThisAttacked(int attack) { @@ -456,6 +503,11 @@ int ThisAttacked::match(MTGCardInstance * card) return matchValue(card->didattacked); } +ThisAttacked* ThisAttacked::clone() const +{ + return NEW ThisAttacked(*this); +} + ThisBlocked::ThisBlocked(int block) { @@ -468,6 +520,11 @@ int ThisBlocked::match(MTGCardInstance * card) return matchValue(card->didblocked); } +ThisBlocked* ThisBlocked::clone() const +{ + return NEW ThisBlocked(*this); +} + ThisNotBlocked::ThisNotBlocked(int unblocked) { @@ -480,6 +537,11 @@ int ThisNotBlocked::match(MTGCardInstance * card) return matchValue(card->notblocked); } +ThisNotBlocked* ThisNotBlocked::clone() const +{ + return NEW ThisNotBlocked(*this); +} + ThisDamaged::ThisDamaged(int wasDealtDamage) { @@ -494,6 +556,11 @@ result = 1; return matchValue(result); } +ThisDamaged* ThisDamaged::clone() const +{ + return NEW ThisDamaged(*this); +} + ThisToughness::ThisToughness(int toughness) { comparisonCriterion = toughness; @@ -504,6 +571,11 @@ int ThisToughness::match(MTGCardInstance * card) return matchValue(card->toughness); } +ThisToughness* ThisToughness::clone() const +{ + return NEW ThisToughness(*this); +} + ThisCounterAny::ThisCounterAny(int nb) { comparisonCriterion = nb; @@ -519,6 +591,11 @@ int ThisCounterAny::match(MTGCardInstance * card) return matchValue(result); } +ThisCounterAny * ThisCounterAny::clone() const +{ + return NEW ThisCounterAny(*this); +} + ThisX::ThisX(int x) { comparisonCriterion = x; @@ -528,3 +605,8 @@ int ThisX::match(MTGCardInstance * card) { return matchValue(card->X); } + +ThisX * ThisX::clone() const +{ + return NEW ThisX(*this); +}