diff --git a/projects/mtg/include/ExtraCost.h b/projects/mtg/include/ExtraCost.h index 6f7296a38..6d98ebdbb 100644 --- a/projects/mtg/include/ExtraCost.h +++ b/projects/mtg/include/ExtraCost.h @@ -3,13 +3,19 @@ #include #include "Counters.h" +#include "ObjectAnalytics.h" + using std::vector; class TargetChooser; class MTGCardInstance; class MTGAbility; -class ExtraCost{ +class ExtraCost +#ifdef TRACK_OBJECT_USAGE + : public InstanceCounter +#endif +{ public: TargetChooser * tc; MTGCardInstance * source; @@ -18,8 +24,13 @@ public: ExtraCost(const std::string& inCostRenderString, TargetChooser *_tc = NULL); virtual ~ExtraCost(); + virtual int setPayment(MTGCardInstance * card); - virtual int isPaymentSet() { return (target != NULL); } + virtual int isPaymentSet() + { + return (target != NULL); + } + virtual int canPay() { return 1; } virtual int doPay() = 0; virtual void Render(); @@ -27,11 +38,13 @@ public: virtual ExtraCost* clone() const = 0; }; -class ExtraCosts{ +class ExtraCosts +{ public: vectorcosts; MTGCardInstance * source; MTGAbility * action; + ExtraCosts(); ~ExtraCosts(); void Render(); @@ -45,7 +58,8 @@ public: ExtraCosts * clone() const; }; -class SacrificeCost: public ExtraCost{ +class SacrificeCost : public ExtraCost +{ public: SacrificeCost(TargetChooser *_tc = NULL); virtual int doPay(); @@ -53,15 +67,18 @@ public: }; //life cost -class LifeCost: public ExtraCost{ +class LifeCost : public ExtraCost +{ public: LifeCost(TargetChooser *_tc = NULL); virtual int canPay(); virtual int doPay(); virtual LifeCost * clone() const; }; + //pyrhaixa mana -class LifeorManaCost: public ExtraCost{ +class LifeorManaCost : public ExtraCost +{ public: LifeorManaCost(TargetChooser *_tc = NULL,string manaType = ""); string manaType; @@ -69,8 +86,10 @@ public: virtual int doPay(); virtual LifeorManaCost * clone() const; }; + //Discard a random card cost -class DiscardRandomCost: public ExtraCost{ +class DiscardRandomCost : public ExtraCost +{ public: DiscardRandomCost(TargetChooser *_tc = NULL); virtual int canPay(); @@ -79,7 +98,8 @@ public: }; //a choosen discard -class DiscardCost: public ExtraCost{ +class DiscardCost : public ExtraCost +{ public: DiscardCost(TargetChooser *_tc = NULL); virtual int doPay(); @@ -87,7 +107,8 @@ public: }; //tolibrary cost -class ToLibraryCost: public ExtraCost{ +class ToLibraryCost : public ExtraCost +{ public: ToLibraryCost(TargetChooser *_tc = NULL); virtual int doPay(); @@ -95,7 +116,8 @@ public: }; //Millyourself cost -class MillCost: public ExtraCost{ +class MillCost : public ExtraCost +{ public: MillCost(TargetChooser *_tc = NULL); virtual int canPay(); @@ -104,13 +126,16 @@ public: }; //Mill to exile yourself cost -class MillExileCost: public MillCost{ +class MillExileCost : public MillCost +{ public: MillExileCost(TargetChooser *_tc = NULL); virtual int doPay(); }; + //tap cost -class TapCost: public ExtraCost{ +class TapCost : public ExtraCost +{ public: TapCost(); virtual int isPaymentSet(); @@ -118,8 +143,10 @@ public: virtual int doPay(); virtual TapCost * clone() const; }; + //untap cost -class UnTapCost: public ExtraCost{ +class UnTapCost : public ExtraCost +{ public: UnTapCost(); virtual int isPaymentSet(); @@ -127,8 +154,10 @@ public: virtual int doPay(); virtual UnTapCost * clone() const; }; + //tap other cost -class TapTargetCost: public ExtraCost{ +class TapTargetCost : public ExtraCost +{ public: TapTargetCost(TargetChooser *_tc = NULL); virtual int isPaymentSet(); @@ -137,7 +166,8 @@ public: }; //exile as cost -class ExileTargetCost: public ExtraCost{ +class ExileTargetCost : public ExtraCost +{ public: ExileTargetCost(TargetChooser *_tc = NULL); virtual int doPay(); @@ -145,7 +175,8 @@ public: }; //bounce cost -class BounceTargetCost: public ExtraCost{ +class BounceTargetCost : public ExtraCost +{ public: BounceTargetCost(TargetChooser *_tc = NULL); virtual int doPay(); @@ -153,7 +184,8 @@ public: }; //bounce cost -class Ninja: public ExtraCost{ +class Ninja : public ExtraCost +{ public: Ninja(TargetChooser *_tc = NULL); virtual int isPaymentSet(); @@ -161,7 +193,8 @@ public: virtual Ninja * clone() const; }; -class CounterCost: public ExtraCost{ +class CounterCost : public ExtraCost +{ public: Counter * counter; int hasCounters; diff --git a/projects/mtg/include/ManaCost.h b/projects/mtg/include/ManaCost.h index feb665f84..5bb6556f3 100644 --- a/projects/mtg/include/ManaCost.h +++ b/projects/mtg/include/ManaCost.h @@ -3,7 +3,7 @@ #include "utils.h" #include "MTGDefinitions.h" - +#include "ObjectAnalytics.h" class ManaCostHybrid; class ExtraCosts; @@ -12,7 +12,11 @@ class MTGAbility; class MTGCardInstance; class Player; -class ManaCost{ +class ManaCost +#ifdef TRACK_OBJECT_USAGE + : public InstanceCounter +#endif +{ friend std::ostream& operator<<(std::ostream& out, ManaCost& m); friend std::ostream& operator<<(std::ostream& out, ManaCost* m); diff --git a/projects/mtg/src/ExtraCost.cpp b/projects/mtg/src/ExtraCost.cpp index 140625832..8f51205af 100644 --- a/projects/mtg/src/ExtraCost.cpp +++ b/projects/mtg/src/ExtraCost.cpp @@ -7,8 +7,10 @@ #include "Player.h" #include "Counters.h" -ExtraCost::ExtraCost(const std::string& inCostRenderString, TargetChooser *_tc) : - tc(_tc), source(NULL), target(NULL), mCostRenderString(inCostRenderString) +SUPPORT_OBJECT_ANALYTICS(ExtraCost) + +ExtraCost::ExtraCost(const std::string& inCostRenderString, TargetChooser *_tc) + : tc(_tc), source(NULL), target(NULL), mCostRenderString(inCostRenderString) { if (tc) tc->targetter = NULL; @@ -25,7 +27,7 @@ int ExtraCost::setSource(MTGCardInstance * _source) if (tc) { tc->source = _source; - // "extra cost is not targetting, protections do not apply" this is not cryptic at all :) make an ability you will understand it then. this keeps the target chooser from being unable to select a creature with shroud/protections. + // this keeps the target chooser from being unable to select a creature with shroud/protections. tc->targetter = NULL; } else @@ -69,20 +71,20 @@ LifeCost * LifeCost::clone() const return ec; } -LifeCost::LifeCost(TargetChooser *_tc) : - ExtraCost("Life", _tc) +LifeCost::LifeCost(TargetChooser *_tc) + : ExtraCost("Life", _tc) { } - int LifeCost::canPay() +int LifeCost::canPay() +{ + MTGCardInstance * _target = (MTGCardInstance *) target; + if(_target->controller()->life <= 0) { - MTGCardInstance * _target = (MTGCardInstance *) target; - if(_target->controller()->life <= 0) - { - return 0; - } - return 1; + return 0; } + return 1; +} int LifeCost::doPay() { @@ -97,6 +99,7 @@ int LifeCost::doPay() tc->initTargets(); return 1; } + //life or Mana cost LifeorManaCost * LifeorManaCost::clone() const { @@ -106,26 +109,26 @@ LifeorManaCost * LifeorManaCost::clone() const return ec; } -LifeorManaCost::LifeorManaCost(TargetChooser *_tc,string manaType) : - ExtraCost("Phyrexian Mana", _tc),manaType(manaType) +LifeorManaCost::LifeorManaCost(TargetChooser *_tc,string manaType) + : ExtraCost("Phyrexian Mana", _tc), manaType(manaType) { } - int LifeorManaCost::canPay() +int LifeorManaCost::canPay() +{ + MTGCardInstance * _target = (MTGCardInstance *) target; + string buildType ="{"; + buildType.append(manaType); + buildType.append("}"); + ManaCost * newCost = ManaCost::parseManaCost(buildType); + if(_target->controller()->getManaPool()->canAfford(newCost) || _target->controller()->life > 1) { - MTGCardInstance * _target = (MTGCardInstance *) target; - string buildType ="{"; - buildType.append(manaType); - buildType.append("}"); - ManaCost * newCost = ManaCost::parseManaCost(buildType); - if(_target->controller()->getManaPool()->canAfford(newCost) || _target->controller()->life > 1) - { - SAFE_DELETE(newCost); - return 1; - } - SAFE_DELETE(newCost); - return 0; + SAFE_DELETE(newCost); + return 1; } + SAFE_DELETE(newCost); + return 0; +} int LifeorManaCost::doPay() { @@ -161,8 +164,8 @@ DiscardRandomCost * DiscardRandomCost::clone() const return ec; } -DiscardRandomCost::DiscardRandomCost(TargetChooser *_tc) : - ExtraCost("Discard Random", _tc) +DiscardRandomCost::DiscardRandomCost(TargetChooser *_tc) + : ExtraCost("Discard Random", _tc) { } @@ -201,7 +204,7 @@ DiscardCost * DiscardCost::clone() const } DiscardCost::DiscardCost(TargetChooser *_tc) : - ExtraCost("Choose card to Discard", _tc) +ExtraCost("Choose card to Discard", _tc) { } @@ -231,8 +234,8 @@ ToLibraryCost * ToLibraryCost::clone() const return ec; } -ToLibraryCost::ToLibraryCost(TargetChooser *_tc) : - ExtraCost("Put a card on top of Library", _tc) +ToLibraryCost::ToLibraryCost(TargetChooser *_tc) + : ExtraCost("Put a card on top of Library", _tc) { } @@ -259,8 +262,8 @@ MillCost * MillCost::clone() const return ec; } -MillCost::MillCost(TargetChooser *_tc) : - ExtraCost("Deplete", _tc) +MillCost::MillCost(TargetChooser *_tc) + : ExtraCost("Deplete", _tc) { } @@ -279,8 +282,8 @@ int MillCost::doPay() if (target) { _target->controller()->game->putInZone( - _target->controller()->game->library->cards[_target->controller()->game->library->nb_cards - 1], - _target->controller()->game->library, _target->controller()->game->graveyard); + _target->controller()->game->library->cards[_target->controller()->game->library->nb_cards - 1], + _target->controller()->game->library, _target->controller()->game->graveyard); target = NULL; if (tc) tc->initTargets(); @@ -289,8 +292,8 @@ int MillCost::doPay() return 0; } -MillExileCost::MillExileCost(TargetChooser *_tc) : - MillCost(_tc) +MillExileCost::MillExileCost(TargetChooser *_tc) + : MillCost(_tc) { // override the base string here mCostRenderString = "Deplete To Exile"; @@ -302,8 +305,8 @@ int MillExileCost::doPay() if (target) { _target->controller()->game->putInZone( - _target->controller()->game->library->cards[_target->controller()->game->library->nb_cards - 1], - _target->controller()->game->library, _target->controller()->game->exile); + _target->controller()->game->library->cards[_target->controller()->game->library->nb_cards - 1], + _target->controller()->game->library, _target->controller()->game->exile); target = NULL; if (tc) tc->initTargets(); @@ -319,8 +322,8 @@ TapCost * TapCost::clone() const return ec; } -TapCost::TapCost() : - ExtraCost("Tap") +TapCost::TapCost() + : ExtraCost("Tap") { } @@ -356,7 +359,7 @@ UnTapCost * UnTapCost::clone() const } UnTapCost::UnTapCost() : - ExtraCost("UnTap") +ExtraCost("UnTap") { } @@ -394,8 +397,8 @@ TapTargetCost * TapTargetCost::clone() const return ec; } -TapTargetCost::TapTargetCost(TargetChooser *_tc) : - ExtraCost("Tap Target", _tc) +TapTargetCost::TapTargetCost(TargetChooser *_tc) + : ExtraCost("Tap Target", _tc) { } @@ -436,8 +439,8 @@ ExileTargetCost * ExileTargetCost::clone() const return ec; } -ExileTargetCost::ExileTargetCost(TargetChooser *_tc) : - ExtraCost("Exile Target", _tc) +ExileTargetCost::ExileTargetCost(TargetChooser *_tc) + : ExtraCost("Exile Target", _tc) { } @@ -464,8 +467,8 @@ BounceTargetCost * BounceTargetCost::clone() const return ec; } -BounceTargetCost::BounceTargetCost(TargetChooser *_tc) : - ExtraCost("Return Target to Hand", _tc) +BounceTargetCost::BounceTargetCost(TargetChooser *_tc) + : ExtraCost("Return Target to Hand", _tc) { } @@ -493,7 +496,7 @@ Ninja * Ninja::clone() const } Ninja::Ninja(TargetChooser *_tc) : - ExtraCost("Select unblocked attacker", _tc) +ExtraCost("Select unblocked attacker", _tc) { } @@ -502,7 +505,7 @@ int Ninja::isPaymentSet() GameObserver * g = GameObserver::GetInstance(); int currentPhase = g->getCurrentGamePhase(); if (target && ((target->isAttacker() && target->blocked) || target->isAttacker() < 1 || currentPhase - != Constants::MTG_PHASE_COMBATBLOCKERS)) + != Constants::MTG_PHASE_COMBATBLOCKERS)) { tc->removeTarget(target); target = NULL; @@ -515,7 +518,6 @@ int Ninja::isPaymentSet() int Ninja::doPay() { - if (target) { target->controller()->game->putInHand(target); @@ -538,8 +540,8 @@ SacrificeCost * SacrificeCost::clone() const return ec; } -SacrificeCost::SacrificeCost(TargetChooser *_tc) : - ExtraCost("Sacrifice", _tc) +SacrificeCost::SacrificeCost(TargetChooser *_tc) + : ExtraCost("Sacrifice", _tc) { } @@ -568,12 +570,12 @@ CounterCost * CounterCost::clone() const ec->tc = tc->clone(); if (counter) ec->counter = NEW Counter(counter->target, counter->name.c_str(), counter->power, counter->toughness); - ec->counter->nb = counter->nb; + ec->counter->nb = counter->nb; return ec; } CounterCost::CounterCost(Counter * _counter, TargetChooser *_tc) : - ExtraCost("Counters", _tc) +ExtraCost("Counters", _tc) { counter = _counter; hasCounters = 0; @@ -759,8 +761,8 @@ int ExtraCosts::doPay() int result = 0; for (size_t i = 0; i < costs.size(); i++) { - if(costs[i]->target) - costs[i]->target->isExtraCostTarget = false; + if(costs[i]->target) + costs[i]->target->isExtraCostTarget = false; result += costs[i]->doPay(); } return result; diff --git a/projects/mtg/src/ManaCost.cpp b/projects/mtg/src/ManaCost.cpp index f7b3f0f50..6dfca60be 100644 --- a/projects/mtg/src/ManaCost.cpp +++ b/projects/mtg/src/ManaCost.cpp @@ -9,6 +9,7 @@ #include "WEvent.h" #include "MTGAbility.h" +SUPPORT_OBJECT_ANALYTICS(ManaCost) ManaCost * ManaCost::parseManaCost(string s, ManaCost * _manaCost, MTGCardInstance * c) { diff --git a/projects/mtg/src/ObjectAnalytics.cpp b/projects/mtg/src/ObjectAnalytics.cpp index 852f8e681..2ae2e6bba 100644 --- a/projects/mtg/src/ObjectAnalytics.cpp +++ b/projects/mtg/src/ObjectAnalytics.cpp @@ -1,9 +1,11 @@ -#include "PrecompiledHeader.h" - -#include "ObjectAnalytics.h" +#include "PrecompiledHeader.h" + +#include "ObjectAnalytics.h" #include "CardPrimitive.h" #include "DebugRoutines.h" +#include "ExtraCost.h" +#include "ManaCost.h" #include "MTGCard.h" #include "MTGCardInstance.h" @@ -30,6 +32,16 @@ namespace ObjectAnalytics DebugTrace("MTGCardInstance max count: " << InstanceCounter::GetMaximumObjectCount()); DebugTrace("MTGCardInstance max byte usage: " << InstanceCounter::GetMaximumByteCount() << std::endl); + DebugTrace("ManaCost current count: " << InstanceCounter::GetCurrentObjectCount()); + DebugTrace("ManaCost current byte usage: " << InstanceCounter::GetCurrentByteCount()); + DebugTrace("ManaCost max count: " << InstanceCounter::GetMaximumObjectCount()); + DebugTrace("ManaCost max byte usage: " << InstanceCounter::GetMaximumByteCount() << std::endl); + + DebugTrace("ExtraCost current count: " << InstanceCounter::GetCurrentObjectCount()); + DebugTrace("ExtraCost current byte usage: " << InstanceCounter::GetCurrentByteCount()); + DebugTrace("ExtraCost max count: " << InstanceCounter::GetMaximumObjectCount()); + DebugTrace("ExtraCost max byte usage: " << InstanceCounter::GetMaximumByteCount() << std::endl); + DebugTrace("-----------------------------------------------------------"); #endif