added copy constructor with operator=
updated constructor for ManaCost* TODO: May have to look at ManaPool in case that needs updates as well.
This commit is contained in:
@@ -14,76 +14,79 @@ class Player;
|
|||||||
|
|
||||||
class ManaCost{
|
class ManaCost{
|
||||||
|
|
||||||
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);
|
||||||
friend std::ostream& operator<<(std::ostream& out, ManaCost m);
|
friend std::ostream& operator<<(std::ostream& out, ManaCost m);
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
int cost[Constants::MTG_NB_COLORS+1];
|
int cost[Constants::MTG_NB_COLORS+1];
|
||||||
ManaCostHybrid * hybrids[10];
|
ManaCostHybrid * hybrids[10];
|
||||||
unsigned int nbhybrids;
|
unsigned int nbhybrids;
|
||||||
int extraCostsIsCopy;
|
int extraCostsIsCopy;
|
||||||
|
|
||||||
public:
|
|
||||||
enum{
|
|
||||||
MANA_UNPAID = 0,
|
|
||||||
MANA_PAID = 1,
|
|
||||||
MANA_PAID_WITH_KICKER = 2,
|
|
||||||
MANA_PAID_WITH_ALTERNATIVE = 3,
|
|
||||||
MANA_PAID_WITH_BUYBACK = 4,
|
|
||||||
MANA_PAID_WITH_FLASHBACK = 5,
|
|
||||||
MANA_PAID_WITH_RETRACE = 6,
|
|
||||||
MANA_PAID_WITH_MORPH = 7
|
|
||||||
|
|
||||||
};
|
public:
|
||||||
ExtraCosts * extraCosts;
|
enum{
|
||||||
ManaCost * kicker;
|
MANA_UNPAID = 0,
|
||||||
ManaCost * alternative;
|
MANA_PAID = 1,
|
||||||
ManaCost * BuyBack;
|
MANA_PAID_WITH_KICKER = 2,
|
||||||
ManaCost * FlashBack;
|
MANA_PAID_WITH_ALTERNATIVE = 3,
|
||||||
ManaCost * Retrace;
|
MANA_PAID_WITH_BUYBACK = 4,
|
||||||
ManaCost * morph;
|
MANA_PAID_WITH_FLASHBACK = 5,
|
||||||
static ManaCost * parseManaCost(string value, ManaCost * _manacost = NULL, MTGCardInstance * c = NULL);
|
MANA_PAID_WITH_RETRACE = 6,
|
||||||
virtual void init();
|
MANA_PAID_WITH_MORPH = 7
|
||||||
void x();
|
|
||||||
int hasX();
|
|
||||||
ManaCost(int _cost[], int nb_elems = 1);
|
|
||||||
ManaCost();
|
|
||||||
~ManaCost();
|
|
||||||
ManaCost(ManaCost * _manaCost);
|
|
||||||
void copy (ManaCost * _manaCost);
|
|
||||||
int isNull();
|
|
||||||
int getConvertedCost();
|
|
||||||
string toString();
|
|
||||||
int getCost(int color);
|
|
||||||
//Returns NULL if i is greater than nbhybrids
|
|
||||||
ManaCostHybrid * getHybridCost(unsigned int i);
|
|
||||||
int hasColor(int color);
|
|
||||||
int remove (int color, int value);
|
|
||||||
int add(int color, int value);
|
|
||||||
|
|
||||||
//
|
};
|
||||||
// Extra Costs (sacrifice,counters...)
|
ExtraCosts * extraCosts;
|
||||||
//
|
ManaCost * kicker;
|
||||||
int addExtraCost(ExtraCost * _cost);
|
ManaCost * alternative;
|
||||||
int setExtraCostsAction(MTGAbility * action, MTGCardInstance * card);
|
ManaCost * BuyBack;
|
||||||
int isExtraPaymentSet();
|
ManaCost * FlashBack;
|
||||||
int canPayExtra();
|
ManaCost * Retrace;
|
||||||
int doPayExtra();
|
ManaCost * morph;
|
||||||
|
static ManaCost * parseManaCost(string value, ManaCost * _manacost = NULL, MTGCardInstance * c = NULL);
|
||||||
|
virtual void init();
|
||||||
|
void x();
|
||||||
|
int hasX();
|
||||||
|
ManaCost(int _cost[], int nb_elems = 1);
|
||||||
|
ManaCost();
|
||||||
|
~ManaCost();
|
||||||
|
ManaCost(ManaCost * _manaCost);
|
||||||
|
ManaCost(const ManaCost& manaCost);
|
||||||
|
ManaCost& operator= (const ManaCost& manaCost);
|
||||||
|
void copy (ManaCost * _manaCost);
|
||||||
|
int isNull();
|
||||||
|
int getConvertedCost();
|
||||||
|
string toString();
|
||||||
|
int getCost(int color);
|
||||||
|
//Returns NULL if i is greater than nbhybrids
|
||||||
|
ManaCostHybrid * getHybridCost(unsigned int i);
|
||||||
|
int hasColor(int color);
|
||||||
|
int remove (int color, int value);
|
||||||
|
int add(int color, int value);
|
||||||
|
|
||||||
int addHybrid(int c1, int v1, int c2, int v2);
|
//
|
||||||
int tryToPayHybrids(ManaCostHybrid * _hybrids[], int _nbhybrids, int diff[]);
|
// Extra Costs (sacrifice,counters...)
|
||||||
void randomDiffHybrids(ManaCost * _cost, int diff[]);
|
//
|
||||||
int add(ManaCost * _cost);
|
int addExtraCost(ExtraCost * _cost);
|
||||||
int pay (ManaCost * _cost);
|
int setExtraCostsAction(MTGAbility * action, MTGCardInstance * card);
|
||||||
|
int isExtraPaymentSet();
|
||||||
|
int canPayExtra();
|
||||||
|
int doPayExtra();
|
||||||
|
|
||||||
//return 1 if _cost can be paid with current data, 0 otherwise
|
int addHybrid(int c1, int v1, int c2, int v2);
|
||||||
int canAfford(ManaCost * _cost);
|
int tryToPayHybrids(ManaCostHybrid * _hybrids[], int _nbhybrids, int diff[]);
|
||||||
|
int tryToPayHybrids(vector<ManaCostHybrid *> hybridList, int diff[]);
|
||||||
|
void randomDiffHybrids(ManaCost * _cost, int diff[]);
|
||||||
|
int add(ManaCost * _cost);
|
||||||
|
int pay (ManaCost * _cost);
|
||||||
|
|
||||||
int isPositive();
|
//return 1 if _cost can be paid with current data, 0 otherwise
|
||||||
ManaCost * Diff(ManaCost * _cost);
|
int canAfford(ManaCost * _cost);
|
||||||
|
|
||||||
|
int isPositive();
|
||||||
|
ManaCost * Diff(ManaCost * _cost);
|
||||||
#ifdef WIN32
|
#ifdef WIN32
|
||||||
void Dump();
|
void Dump();
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
|
||||||
@@ -91,15 +94,15 @@ class ManaCost{
|
|||||||
|
|
||||||
class ManaPool:public ManaCost{
|
class ManaPool:public ManaCost{
|
||||||
protected:
|
protected:
|
||||||
Player * player;
|
Player * player;
|
||||||
public:
|
public:
|
||||||
void init();
|
void init();
|
||||||
ManaPool(Player * player);
|
ManaPool(Player * player);
|
||||||
ManaPool(ManaCost * _manaCost, Player * player);
|
ManaPool(ManaCost * _manaCost, Player * player);
|
||||||
int remove (int color, int value);
|
int remove (int color, int value);
|
||||||
int add(int color, int value, MTGCardInstance * source = NULL);
|
int add(int color, int value, MTGCardInstance * source = NULL);
|
||||||
int add(ManaCost * _cost, MTGCardInstance * source = NULL);
|
int add(ManaCost * _cost, MTGCardInstance * source = NULL);
|
||||||
int pay (ManaCost * _cost);
|
int pay (ManaCost * _cost);
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|||||||
@@ -234,13 +234,72 @@ ManaCost::ManaCost(int _cost[], int nb_elems)
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
ManaCost::ManaCost(ManaCost * _manaCost)
|
ManaCost::ManaCost(ManaCost * manaCost)
|
||||||
{
|
{
|
||||||
init();
|
init();
|
||||||
for (int i = 0; i <= Constants::MTG_NB_COLORS; i++)
|
for (int i = 0; i <= Constants::MTG_NB_COLORS; i++)
|
||||||
{
|
{
|
||||||
cost[i] = _manaCost->getCost(i);
|
cost[i] = manaCost->getCost(i);
|
||||||
}
|
}
|
||||||
|
for (int i = 0 ; i < 10; i++)
|
||||||
|
hybrids[i] = manaCost->hybrids[i];
|
||||||
|
|
||||||
|
nbhybrids = manaCost->nbhybrids;
|
||||||
|
kicker = manaCost->kicker;
|
||||||
|
Retrace = manaCost->Retrace;
|
||||||
|
BuyBack = manaCost->BuyBack;
|
||||||
|
alternative = manaCost->alternative;
|
||||||
|
FlashBack = manaCost->FlashBack;
|
||||||
|
extraCosts = manaCost->extraCosts;
|
||||||
|
morph = manaCost->morph;
|
||||||
|
extraCostsIsCopy = manaCost->extraCostsIsCopy;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Copy Constructor
|
||||||
|
|
||||||
|
ManaCost::ManaCost(const ManaCost& manaCost)
|
||||||
|
{
|
||||||
|
|
||||||
|
for (int i = 0; i <= Constants::MTG_NB_COLORS; i++)
|
||||||
|
{
|
||||||
|
cost[i] = manaCost.cost[i];
|
||||||
|
}
|
||||||
|
for (int i = 0 ; i < 10; i++)
|
||||||
|
hybrids[i] = manaCost.hybrids[i];
|
||||||
|
|
||||||
|
nbhybrids = manaCost.nbhybrids;
|
||||||
|
kicker = manaCost.kicker;
|
||||||
|
Retrace = manaCost.Retrace;
|
||||||
|
BuyBack = manaCost.BuyBack;
|
||||||
|
alternative = manaCost.alternative;
|
||||||
|
FlashBack = manaCost.FlashBack;
|
||||||
|
morph = manaCost.morph;
|
||||||
|
extraCosts = manaCost.extraCosts;
|
||||||
|
extraCostsIsCopy = manaCost.extraCostsIsCopy;
|
||||||
|
}
|
||||||
|
|
||||||
|
// operator=
|
||||||
|
ManaCost & ManaCost::operator= (const ManaCost & manaCost)
|
||||||
|
{
|
||||||
|
if ( this != &manaCost )
|
||||||
|
{
|
||||||
|
int * new_array = new int[Constants::MTG_NB_COLORS];
|
||||||
|
std::memcpy(cost, manaCost.cost, sizeof(new_array));
|
||||||
|
for (int i = 0 ; i < 10; i++)
|
||||||
|
hybrids[i] = manaCost.hybrids[i];
|
||||||
|
SAFE_DELETE_ARRAY( new_array );
|
||||||
|
|
||||||
|
nbhybrids = manaCost.nbhybrids;
|
||||||
|
kicker = manaCost.kicker;
|
||||||
|
Retrace = manaCost.Retrace;
|
||||||
|
BuyBack = manaCost.BuyBack;
|
||||||
|
alternative = manaCost.alternative;
|
||||||
|
FlashBack = manaCost.FlashBack;
|
||||||
|
morph = manaCost.morph;
|
||||||
|
extraCosts = manaCost.extraCosts;
|
||||||
|
extraCostsIsCopy = manaCost.extraCostsIsCopy;
|
||||||
|
}
|
||||||
|
return *this;
|
||||||
}
|
}
|
||||||
|
|
||||||
ManaCost::~ManaCost()
|
ManaCost::~ManaCost()
|
||||||
@@ -249,6 +308,7 @@ ManaCost::~ManaCost()
|
|||||||
{
|
{
|
||||||
SAFE_DELETE(hybrids[i]);
|
SAFE_DELETE(hybrids[i]);
|
||||||
}
|
}
|
||||||
|
|
||||||
SAFE_DELETE(extraCosts);
|
SAFE_DELETE(extraCosts);
|
||||||
SAFE_DELETE(kicker);
|
SAFE_DELETE(kicker);
|
||||||
SAFE_DELETE(alternative);
|
SAFE_DELETE(alternative);
|
||||||
@@ -543,7 +603,16 @@ void ManaCost::randomDiffHybrids(ManaCost * _cost, int diff[])
|
|||||||
diff[h->color1 * 2 + 1] -= h->value1;
|
diff[h->color1 * 2 + 1] -= h->value1;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
int ManaCost::tryToPayHybrids(vector<ManaCostHybrid *> hybridList, int diff[])
|
||||||
|
{
|
||||||
|
if (hybridList.empty())
|
||||||
|
return 1;
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
starting from the end of the array (diff)
|
||||||
|
*/
|
||||||
int ManaCost::tryToPayHybrids(ManaCostHybrid * _hybrids[], int _nbhybrids, int diff[])
|
int ManaCost::tryToPayHybrids(ManaCostHybrid * _hybrids[], int _nbhybrids, int diff[])
|
||||||
{
|
{
|
||||||
if (!_nbhybrids)
|
if (!_nbhybrids)
|
||||||
|
|||||||
Reference in New Issue
Block a user