Added object analytics around ExtraCost & ManaCost; some formatting style cleanup.

This commit is contained in:
wrenczes@gmail.com
2011-04-24 10:33:38 +00:00
parent be2a4ee4ec
commit 6fbc019ecc
5 changed files with 133 additions and 81 deletions
+51 -18
View File
@@ -3,13 +3,19 @@
#include <vector> #include <vector>
#include "Counters.h" #include "Counters.h"
#include "ObjectAnalytics.h"
using std::vector; using std::vector;
class TargetChooser; class TargetChooser;
class MTGCardInstance; class MTGCardInstance;
class MTGAbility; class MTGAbility;
class ExtraCost{ class ExtraCost
#ifdef TRACK_OBJECT_USAGE
: public InstanceCounter<ExtraCost>
#endif
{
public: public:
TargetChooser * tc; TargetChooser * tc;
MTGCardInstance * source; MTGCardInstance * source;
@@ -18,8 +24,13 @@ public:
ExtraCost(const std::string& inCostRenderString, TargetChooser *_tc = NULL); ExtraCost(const std::string& inCostRenderString, TargetChooser *_tc = NULL);
virtual ~ExtraCost(); virtual ~ExtraCost();
virtual int setPayment(MTGCardInstance * card); virtual int setPayment(MTGCardInstance * card);
virtual int isPaymentSet() { return (target != NULL); } virtual int isPaymentSet()
{
return (target != NULL);
}
virtual int canPay() { return 1; } virtual int canPay() { return 1; }
virtual int doPay() = 0; virtual int doPay() = 0;
virtual void Render(); virtual void Render();
@@ -27,11 +38,13 @@ public:
virtual ExtraCost* clone() const = 0; virtual ExtraCost* clone() const = 0;
}; };
class ExtraCosts{ class ExtraCosts
{
public: public:
vector<ExtraCost *>costs; vector<ExtraCost *>costs;
MTGCardInstance * source; MTGCardInstance * source;
MTGAbility * action; MTGAbility * action;
ExtraCosts(); ExtraCosts();
~ExtraCosts(); ~ExtraCosts();
void Render(); void Render();
@@ -45,7 +58,8 @@ public:
ExtraCosts * clone() const; ExtraCosts * clone() const;
}; };
class SacrificeCost: public ExtraCost{ class SacrificeCost : public ExtraCost
{
public: public:
SacrificeCost(TargetChooser *_tc = NULL); SacrificeCost(TargetChooser *_tc = NULL);
virtual int doPay(); virtual int doPay();
@@ -53,15 +67,18 @@ public:
}; };
//life cost //life cost
class LifeCost: public ExtraCost{ class LifeCost : public ExtraCost
{
public: public:
LifeCost(TargetChooser *_tc = NULL); LifeCost(TargetChooser *_tc = NULL);
virtual int canPay(); virtual int canPay();
virtual int doPay(); virtual int doPay();
virtual LifeCost * clone() const; virtual LifeCost * clone() const;
}; };
//pyrhaixa mana //pyrhaixa mana
class LifeorManaCost: public ExtraCost{ class LifeorManaCost : public ExtraCost
{
public: public:
LifeorManaCost(TargetChooser *_tc = NULL,string manaType = ""); LifeorManaCost(TargetChooser *_tc = NULL,string manaType = "");
string manaType; string manaType;
@@ -69,8 +86,10 @@ public:
virtual int doPay(); virtual int doPay();
virtual LifeorManaCost * clone() const; virtual LifeorManaCost * clone() const;
}; };
//Discard a random card cost //Discard a random card cost
class DiscardRandomCost: public ExtraCost{ class DiscardRandomCost : public ExtraCost
{
public: public:
DiscardRandomCost(TargetChooser *_tc = NULL); DiscardRandomCost(TargetChooser *_tc = NULL);
virtual int canPay(); virtual int canPay();
@@ -79,7 +98,8 @@ public:
}; };
//a choosen discard //a choosen discard
class DiscardCost: public ExtraCost{ class DiscardCost : public ExtraCost
{
public: public:
DiscardCost(TargetChooser *_tc = NULL); DiscardCost(TargetChooser *_tc = NULL);
virtual int doPay(); virtual int doPay();
@@ -87,7 +107,8 @@ public:
}; };
//tolibrary cost //tolibrary cost
class ToLibraryCost: public ExtraCost{ class ToLibraryCost : public ExtraCost
{
public: public:
ToLibraryCost(TargetChooser *_tc = NULL); ToLibraryCost(TargetChooser *_tc = NULL);
virtual int doPay(); virtual int doPay();
@@ -95,7 +116,8 @@ public:
}; };
//Millyourself cost //Millyourself cost
class MillCost: public ExtraCost{ class MillCost : public ExtraCost
{
public: public:
MillCost(TargetChooser *_tc = NULL); MillCost(TargetChooser *_tc = NULL);
virtual int canPay(); virtual int canPay();
@@ -104,13 +126,16 @@ public:
}; };
//Mill to exile yourself cost //Mill to exile yourself cost
class MillExileCost: public MillCost{ class MillExileCost : public MillCost
{
public: public:
MillExileCost(TargetChooser *_tc = NULL); MillExileCost(TargetChooser *_tc = NULL);
virtual int doPay(); virtual int doPay();
}; };
//tap cost //tap cost
class TapCost: public ExtraCost{ class TapCost : public ExtraCost
{
public: public:
TapCost(); TapCost();
virtual int isPaymentSet(); virtual int isPaymentSet();
@@ -118,8 +143,10 @@ public:
virtual int doPay(); virtual int doPay();
virtual TapCost * clone() const; virtual TapCost * clone() const;
}; };
//untap cost //untap cost
class UnTapCost: public ExtraCost{ class UnTapCost : public ExtraCost
{
public: public:
UnTapCost(); UnTapCost();
virtual int isPaymentSet(); virtual int isPaymentSet();
@@ -127,8 +154,10 @@ public:
virtual int doPay(); virtual int doPay();
virtual UnTapCost * clone() const; virtual UnTapCost * clone() const;
}; };
//tap other cost //tap other cost
class TapTargetCost: public ExtraCost{ class TapTargetCost : public ExtraCost
{
public: public:
TapTargetCost(TargetChooser *_tc = NULL); TapTargetCost(TargetChooser *_tc = NULL);
virtual int isPaymentSet(); virtual int isPaymentSet();
@@ -137,7 +166,8 @@ public:
}; };
//exile as cost //exile as cost
class ExileTargetCost: public ExtraCost{ class ExileTargetCost : public ExtraCost
{
public: public:
ExileTargetCost(TargetChooser *_tc = NULL); ExileTargetCost(TargetChooser *_tc = NULL);
virtual int doPay(); virtual int doPay();
@@ -145,7 +175,8 @@ public:
}; };
//bounce cost //bounce cost
class BounceTargetCost: public ExtraCost{ class BounceTargetCost : public ExtraCost
{
public: public:
BounceTargetCost(TargetChooser *_tc = NULL); BounceTargetCost(TargetChooser *_tc = NULL);
virtual int doPay(); virtual int doPay();
@@ -153,7 +184,8 @@ public:
}; };
//bounce cost //bounce cost
class Ninja: public ExtraCost{ class Ninja : public ExtraCost
{
public: public:
Ninja(TargetChooser *_tc = NULL); Ninja(TargetChooser *_tc = NULL);
virtual int isPaymentSet(); virtual int isPaymentSet();
@@ -161,7 +193,8 @@ public:
virtual Ninja * clone() const; virtual Ninja * clone() const;
}; };
class CounterCost: public ExtraCost{ class CounterCost : public ExtraCost
{
public: public:
Counter * counter; Counter * counter;
int hasCounters; int hasCounters;
+6 -2
View File
@@ -3,7 +3,7 @@
#include "utils.h" #include "utils.h"
#include "MTGDefinitions.h" #include "MTGDefinitions.h"
#include "ObjectAnalytics.h"
class ManaCostHybrid; class ManaCostHybrid;
class ExtraCosts; class ExtraCosts;
@@ -12,7 +12,11 @@ class MTGAbility;
class MTGCardInstance; class MTGCardInstance;
class Player; class Player;
class ManaCost{ class ManaCost
#ifdef TRACK_OBJECT_USAGE
: public InstanceCounter<ManaCost>
#endif
{
friend std::ostream& operator<<(std::ostream& out, ManaCost& m); friend std::ostream& operator<<(std::ostream& out, ManaCost& m);
friend std::ostream& operator<<(std::ostream& out, ManaCost* m); friend std::ostream& operator<<(std::ostream& out, ManaCost* m);
+38 -36
View File
@@ -7,8 +7,10 @@
#include "Player.h" #include "Player.h"
#include "Counters.h" #include "Counters.h"
ExtraCost::ExtraCost(const std::string& inCostRenderString, TargetChooser *_tc) : SUPPORT_OBJECT_ANALYTICS(ExtraCost)
tc(_tc), source(NULL), target(NULL), mCostRenderString(inCostRenderString)
ExtraCost::ExtraCost(const std::string& inCostRenderString, TargetChooser *_tc)
: tc(_tc), source(NULL), target(NULL), mCostRenderString(inCostRenderString)
{ {
if (tc) if (tc)
tc->targetter = NULL; tc->targetter = NULL;
@@ -25,7 +27,7 @@ int ExtraCost::setSource(MTGCardInstance * _source)
if (tc) if (tc)
{ {
tc->source = _source; 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; tc->targetter = NULL;
} }
else else
@@ -69,20 +71,20 @@ LifeCost * LifeCost::clone() const
return ec; return ec;
} }
LifeCost::LifeCost(TargetChooser *_tc) : LifeCost::LifeCost(TargetChooser *_tc)
ExtraCost("Life", _tc) : ExtraCost("Life", _tc)
{ {
} }
int LifeCost::canPay() int LifeCost::canPay()
{ {
MTGCardInstance * _target = (MTGCardInstance *) target; MTGCardInstance * _target = (MTGCardInstance *) target;
if(_target->controller()->life <= 0) if(_target->controller()->life <= 0)
{ {
return 0; return 0;
} }
return 1; return 1;
} }
int LifeCost::doPay() int LifeCost::doPay()
{ {
@@ -97,6 +99,7 @@ int LifeCost::doPay()
tc->initTargets(); tc->initTargets();
return 1; return 1;
} }
//life or Mana cost //life or Mana cost
LifeorManaCost * LifeorManaCost::clone() const LifeorManaCost * LifeorManaCost::clone() const
{ {
@@ -106,13 +109,13 @@ LifeorManaCost * LifeorManaCost::clone() const
return ec; return ec;
} }
LifeorManaCost::LifeorManaCost(TargetChooser *_tc,string manaType) : LifeorManaCost::LifeorManaCost(TargetChooser *_tc,string manaType)
ExtraCost("Phyrexian Mana", _tc),manaType(manaType) : ExtraCost("Phyrexian Mana", _tc), manaType(manaType)
{ {
} }
int LifeorManaCost::canPay() int LifeorManaCost::canPay()
{ {
MTGCardInstance * _target = (MTGCardInstance *) target; MTGCardInstance * _target = (MTGCardInstance *) target;
string buildType ="{"; string buildType ="{";
buildType.append(manaType); buildType.append(manaType);
@@ -125,7 +128,7 @@ LifeorManaCost::LifeorManaCost(TargetChooser *_tc,string manaType) :
} }
SAFE_DELETE(newCost); SAFE_DELETE(newCost);
return 0; return 0;
} }
int LifeorManaCost::doPay() int LifeorManaCost::doPay()
{ {
@@ -161,8 +164,8 @@ DiscardRandomCost * DiscardRandomCost::clone() const
return ec; return ec;
} }
DiscardRandomCost::DiscardRandomCost(TargetChooser *_tc) : DiscardRandomCost::DiscardRandomCost(TargetChooser *_tc)
ExtraCost("Discard Random", _tc) : ExtraCost("Discard Random", _tc)
{ {
} }
@@ -201,7 +204,7 @@ DiscardCost * DiscardCost::clone() const
} }
DiscardCost::DiscardCost(TargetChooser *_tc) : 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; return ec;
} }
ToLibraryCost::ToLibraryCost(TargetChooser *_tc) : ToLibraryCost::ToLibraryCost(TargetChooser *_tc)
ExtraCost("Put a card on top of Library", _tc) : ExtraCost("Put a card on top of Library", _tc)
{ {
} }
@@ -259,8 +262,8 @@ MillCost * MillCost::clone() const
return ec; return ec;
} }
MillCost::MillCost(TargetChooser *_tc) : MillCost::MillCost(TargetChooser *_tc)
ExtraCost("Deplete", _tc) : ExtraCost("Deplete", _tc)
{ {
} }
@@ -289,8 +292,8 @@ int MillCost::doPay()
return 0; return 0;
} }
MillExileCost::MillExileCost(TargetChooser *_tc) : MillExileCost::MillExileCost(TargetChooser *_tc)
MillCost(_tc) : MillCost(_tc)
{ {
// override the base string here // override the base string here
mCostRenderString = "Deplete To Exile"; mCostRenderString = "Deplete To Exile";
@@ -319,8 +322,8 @@ TapCost * TapCost::clone() const
return ec; return ec;
} }
TapCost::TapCost() : TapCost::TapCost()
ExtraCost("Tap") : ExtraCost("Tap")
{ {
} }
@@ -356,7 +359,7 @@ UnTapCost * UnTapCost::clone() const
} }
UnTapCost::UnTapCost() : UnTapCost::UnTapCost() :
ExtraCost("UnTap") ExtraCost("UnTap")
{ {
} }
@@ -394,8 +397,8 @@ TapTargetCost * TapTargetCost::clone() const
return ec; return ec;
} }
TapTargetCost::TapTargetCost(TargetChooser *_tc) : TapTargetCost::TapTargetCost(TargetChooser *_tc)
ExtraCost("Tap Target", _tc) : ExtraCost("Tap Target", _tc)
{ {
} }
@@ -436,8 +439,8 @@ ExileTargetCost * ExileTargetCost::clone() const
return ec; return ec;
} }
ExileTargetCost::ExileTargetCost(TargetChooser *_tc) : ExileTargetCost::ExileTargetCost(TargetChooser *_tc)
ExtraCost("Exile Target", _tc) : ExtraCost("Exile Target", _tc)
{ {
} }
@@ -464,8 +467,8 @@ BounceTargetCost * BounceTargetCost::clone() const
return ec; return ec;
} }
BounceTargetCost::BounceTargetCost(TargetChooser *_tc) : BounceTargetCost::BounceTargetCost(TargetChooser *_tc)
ExtraCost("Return Target to Hand", _tc) : ExtraCost("Return Target to Hand", _tc)
{ {
} }
@@ -493,7 +496,7 @@ Ninja * Ninja::clone() const
} }
Ninja::Ninja(TargetChooser *_tc) : Ninja::Ninja(TargetChooser *_tc) :
ExtraCost("Select unblocked attacker", _tc) ExtraCost("Select unblocked attacker", _tc)
{ {
} }
@@ -515,7 +518,6 @@ int Ninja::isPaymentSet()
int Ninja::doPay() int Ninja::doPay()
{ {
if (target) if (target)
{ {
target->controller()->game->putInHand(target); target->controller()->game->putInHand(target);
@@ -538,8 +540,8 @@ SacrificeCost * SacrificeCost::clone() const
return ec; return ec;
} }
SacrificeCost::SacrificeCost(TargetChooser *_tc) : SacrificeCost::SacrificeCost(TargetChooser *_tc)
ExtraCost("Sacrifice", _tc) : ExtraCost("Sacrifice", _tc)
{ {
} }
@@ -573,7 +575,7 @@ CounterCost * CounterCost::clone() const
} }
CounterCost::CounterCost(Counter * _counter, TargetChooser *_tc) : CounterCost::CounterCost(Counter * _counter, TargetChooser *_tc) :
ExtraCost("Counters", _tc) ExtraCost("Counters", _tc)
{ {
counter = _counter; counter = _counter;
hasCounters = 0; hasCounters = 0;
+1
View File
@@ -9,6 +9,7 @@
#include "WEvent.h" #include "WEvent.h"
#include "MTGAbility.h" #include "MTGAbility.h"
SUPPORT_OBJECT_ANALYTICS(ManaCost)
ManaCost * ManaCost::parseManaCost(string s, ManaCost * _manaCost, MTGCardInstance * c) ManaCost * ManaCost::parseManaCost(string s, ManaCost * _manaCost, MTGCardInstance * c)
{ {
+12
View File
@@ -4,6 +4,8 @@
#include "CardPrimitive.h" #include "CardPrimitive.h"
#include "DebugRoutines.h" #include "DebugRoutines.h"
#include "ExtraCost.h"
#include "ManaCost.h"
#include "MTGCard.h" #include "MTGCard.h"
#include "MTGCardInstance.h" #include "MTGCardInstance.h"
@@ -30,6 +32,16 @@ namespace ObjectAnalytics
DebugTrace("MTGCardInstance max count: " << InstanceCounter<MTGCardInstance>::GetMaximumObjectCount()); DebugTrace("MTGCardInstance max count: " << InstanceCounter<MTGCardInstance>::GetMaximumObjectCount());
DebugTrace("MTGCardInstance max byte usage: " << InstanceCounter<MTGCardInstance>::GetMaximumByteCount() << std::endl); DebugTrace("MTGCardInstance max byte usage: " << InstanceCounter<MTGCardInstance>::GetMaximumByteCount() << std::endl);
DebugTrace("ManaCost current count: " << InstanceCounter<ManaCost>::GetCurrentObjectCount());
DebugTrace("ManaCost current byte usage: " << InstanceCounter<ManaCost>::GetCurrentByteCount());
DebugTrace("ManaCost max count: " << InstanceCounter<ManaCost>::GetMaximumObjectCount());
DebugTrace("ManaCost max byte usage: " << InstanceCounter<ManaCost>::GetMaximumByteCount() << std::endl);
DebugTrace("ExtraCost current count: " << InstanceCounter<ExtraCost>::GetCurrentObjectCount());
DebugTrace("ExtraCost current byte usage: " << InstanceCounter<ExtraCost>::GetCurrentByteCount());
DebugTrace("ExtraCost max count: " << InstanceCounter<ExtraCost>::GetMaximumObjectCount());
DebugTrace("ExtraCost max byte usage: " << InstanceCounter<ExtraCost>::GetMaximumByteCount() << std::endl);
DebugTrace("-----------------------------------------------------------"); DebugTrace("-----------------------------------------------------------");
#endif #endif