removed calls to ManaCost::init() as all but two are actually necessary.

moved init() from ManaCost to a private call
changed ManaPool method init() to Empty() to better represent what it does.  
renamed ManaCost::reinit to resetCosts() as reinit sounds like your are returning the ManaCost object back to initial state which is not what happens.  Only the cost related members are reset, the bool isMulti is left alone
This commit is contained in:
techdragon.nguyen@gmail.com
2012-02-02 01:10:11 +00:00
parent e709497f2e
commit 228fe23e49
6 changed files with 17 additions and 23 deletions

View File

@@ -21,11 +21,12 @@ 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);
protected:
std::vector<int8_t> cost;
std::vector<ManaCostHybrid> hybrids;
virtual void init();
public:
enum
@@ -52,8 +53,7 @@ public:
string alternativeName;
bool isMulti;
static ManaCost * parseManaCost(string value, ManaCost * _manacost = NULL, MTGCardInstance * c = NULL);
virtual void init();
virtual void reinit();
virtual void resetCosts();
void x();
int hasX();
int hasAnotherCost();
@@ -108,7 +108,7 @@ class ManaPool:public ManaCost{
protected:
Player * player;
public:
void init();
void Empty();
ManaPool(Player * player);
ManaPool(ManaCost * _manaCost, Player * player);
int remove (int color, int value);

View File

@@ -70,7 +70,6 @@ AIHint * AIHints::getByCondition (string condition)
bool AIHints::HintSaysDontAttack(GameObserver* observer,MTGCardInstance * card)
{
int count = 0;
TargetChooserFactory tfc(observer);
TargetChooser * hintTc = NULL;
for(unsigned int i = 0; i < hints.size();i++)

View File

@@ -603,7 +603,7 @@ int OrderedAIAction::getEfficiency()
//Decrease chance of using ability if there is an extra cost to use the ability, ignore tap
}
}
if (MTGPutInPlayRule * pip = dynamic_cast<MTGPutInPlayRule *>(a))
if (dynamic_cast<MTGPutInPlayRule *>(a))
{
efficiency += 65;
}
@@ -931,10 +931,8 @@ vector<MTGAbility*> AIPlayerBaka::canPayMana(MTGCardInstance * target,ManaCost *
if (!used[card] && amp->isReactingToClick(card) && amp->output->getConvertedCost() >= 1)
{
ManaCost * check = NEW ManaCost();
check->init();
check->add(k,cost->getCost(k));
ManaCost * checkResult = NEW ManaCost();
checkResult->init();
checkResult->add(k,result->getCost(k));
if(!(checkResult->canAfford(check)))
{
@@ -979,10 +977,8 @@ vector<MTGAbility*> AIPlayerBaka::canPayMana(MTGCardInstance * target,ManaCost *
if (!used[card] && amp->isReactingToClick(card) && amp->output->getConvertedCost() >= 1)
{
ManaCost * check = NEW ManaCost();
check->init();
check->add(foundColor1?hybridCost->color1:hybridCost->color2,foundColor1?hybridCost->value1:hybridCost->value2);
ManaCost * checkResult = NEW ManaCost();
checkResult->init();
checkResult->add(foundColor1?hybridCost->color1:hybridCost->color2,result->getCost(foundColor1?hybridCost->color1:hybridCost->color2));
if(((foundColor1 && !foundColor2)||(!foundColor1 && foundColor2)) &&!(checkResult->canAfford(check)))
{
@@ -1004,8 +1000,6 @@ vector<MTGAbility*> AIPlayerBaka::canPayMana(MTGCardInstance * target,ManaCost *
{
ManaCost * check = NEW ManaCost();
ManaCost * checkResult = NEW ManaCost();
check->init();
checkResult->init();
for (int k = 1; k < Constants::NB_Colors; k++)
{
check->add(k,cost->getCost(k));
@@ -1104,10 +1098,8 @@ vector<MTGAbility*> AIPlayerBaka::canPaySunBurst(ManaCost * cost)
if (!used[card] && amp->isReactingToClick(card) && amp->output->getConvertedCost() >= 1)
{
ManaCost * check = NEW ManaCost();
check->init();
check->add(k,1);
ManaCost * checkResult = NEW ManaCost();
checkResult->init();
checkResult->add(k,result->getCost(k));
if(!(checkResult->canAfford(check)))
{
@@ -1340,7 +1332,6 @@ int AIPlayerBaka::selectAbility()
if (abilityPayment.size())
{
fullPayment = NEW ManaCost();
fullPayment->init();
for(int ch = 0; ch < int(abilityPayment.size());ch++)
{
AManaProducer * ampp = dynamic_cast<AManaProducer*> (abilityPayment[ch]);

View File

@@ -1064,7 +1064,7 @@ int AAFlip::resolve()
_target->types = myFlip->types;
_target->text = myFlip->text;
_target->formattedText = myFlip->formattedText;
ActionLayer * al = game->mLayers->actionLayer();
for(unsigned int i = 0;i < _target->cardsAbilities.size();i++)
{
MTGAbility * a = dynamic_cast<MTGAbility *>(_target->cardsAbilities[i]);
@@ -2123,7 +2123,7 @@ int AARemoveMana::resolve()
}
else //Remove all mana
{
manaPool->init();
manaPool->Empty();
}
}
else //remove a "standard" mana Description

View File

@@ -2854,7 +2854,7 @@ int AbilityFactory::getAbilities(vector<MTGAbility *> * v, Spell * spell, MTGCar
string cre = "Creature";
card->setType(cre.c_str());
card->basicAbilities.reset();
card->getManaCost()->reinit();
card->getManaCost()->resetCosts();
}
else if(card && !card->morphed && card->turningOver)
{
@@ -3315,7 +3315,7 @@ void AbilityFactory::addAbilities(int _id, Spell * spell)
if (current->hasType(Subtypes::TYPE_LAND))
current->tap();
}
player->getManaPool()->init();
player->getManaPool()->Empty();
}
break;
}

View File

@@ -388,11 +388,14 @@ int ManaCost::hasAnotherCost()
void ManaCost::init()
{
int i;
cost.erase(cost.begin(),cost.end());
cost.erase(cost.begin() ,cost.end());
for (i = 0; i <= Constants::NB_Colors; i++)
{
cost.push_back(0);
}
extraCosts = NULL;
kicker = NULL;
alternative = NULL;
@@ -404,7 +407,7 @@ void ManaCost::init()
isMulti = false;
}
void ManaCost::reinit()
void ManaCost::resetCosts()
{
int i;
@@ -414,6 +417,7 @@ void ManaCost::reinit()
{
cost.push_back(0);
}
SAFE_DELETE(extraCosts);
SAFE_DELETE(kicker);
SAFE_DELETE(alternative);
@@ -841,9 +845,9 @@ ostream& operator<<(ostream& out, ManaCost m)
return out << m.toString();
}
void ManaPool::init()
void ManaPool::Empty()
{
ManaCost::init();
init();
WEvent * e = NEW WEventEmptyManaPool(this);
player->getObserver()->receiveEvent(e);
}