From 228fe23e49fc94506e83c973b2b1d96e2368a663 Mon Sep 17 00:00:00 2001 From: "techdragon.nguyen@gmail.com" Date: Thu, 2 Feb 2012 01:10:11 +0000 Subject: [PATCH] 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 --- projects/mtg/include/ManaCost.h | 8 ++++---- projects/mtg/src/AIHints.cpp | 1 - projects/mtg/src/AIPlayerBaka.cpp | 11 +---------- projects/mtg/src/AllAbilities.cpp | 4 ++-- projects/mtg/src/MTGAbility.cpp | 4 ++-- projects/mtg/src/ManaCost.cpp | 12 ++++++++---- 6 files changed, 17 insertions(+), 23 deletions(-) diff --git a/projects/mtg/include/ManaCost.h b/projects/mtg/include/ManaCost.h index 7f229b19d..ab5dea2d0 100644 --- a/projects/mtg/include/ManaCost.h +++ b/projects/mtg/include/ManaCost.h @@ -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 cost; std::vector 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); diff --git a/projects/mtg/src/AIHints.cpp b/projects/mtg/src/AIHints.cpp index 4501cdd1a..c4f98c7e0 100644 --- a/projects/mtg/src/AIHints.cpp +++ b/projects/mtg/src/AIHints.cpp @@ -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++) diff --git a/projects/mtg/src/AIPlayerBaka.cpp b/projects/mtg/src/AIPlayerBaka.cpp index 5fdc5f5cb..ba0a1ecd7 100644 --- a/projects/mtg/src/AIPlayerBaka.cpp +++ b/projects/mtg/src/AIPlayerBaka.cpp @@ -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(a)) + if (dynamic_cast(a)) { efficiency += 65; } @@ -931,10 +931,8 @@ vector 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 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 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 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 (abilityPayment[ch]); diff --git a/projects/mtg/src/AllAbilities.cpp b/projects/mtg/src/AllAbilities.cpp index c116bd639..81a4ceea3 100644 --- a/projects/mtg/src/AllAbilities.cpp +++ b/projects/mtg/src/AllAbilities.cpp @@ -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(_target->cardsAbilities[i]); @@ -2123,7 +2123,7 @@ int AARemoveMana::resolve() } else //Remove all mana { - manaPool->init(); + manaPool->Empty(); } } else //remove a "standard" mana Description diff --git a/projects/mtg/src/MTGAbility.cpp b/projects/mtg/src/MTGAbility.cpp index 56def6f10..33d87657d 100644 --- a/projects/mtg/src/MTGAbility.cpp +++ b/projects/mtg/src/MTGAbility.cpp @@ -2854,7 +2854,7 @@ int AbilityFactory::getAbilities(vector * 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; } diff --git a/projects/mtg/src/ManaCost.cpp b/projects/mtg/src/ManaCost.cpp index fa75fd581..57352c80f 100644 --- a/projects/mtg/src/ManaCost.cpp +++ b/projects/mtg/src/ManaCost.cpp @@ -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); }