From 4419ed46371bda8b4036411aecd0a14daed744c4 Mon Sep 17 00:00:00 2001 From: "omegablast2002@yahoo.com" Date: Wed, 21 Sep 2011 20:27:29 +0000 Subject: [PATCH] changed some logic for getting the pre x without shellcasting(?) spell...the variable word "prex" now returns the difference between the cards cost and the curentmanapool...giving us the value of pre x.some cards might need updating, doc can confirm it.... --- projects/mtg/include/AllAbilities.h | 9 +++++- projects/mtg/src/AIPlayerBaka.cpp | 47 ++--------------------------- projects/mtg/src/ActionLayer.cpp | 18 ++++++----- projects/mtg/src/ActionStack.cpp | 6 ++-- projects/mtg/src/GuiLayers.cpp | 32 ++++++++++++++------ projects/mtg/src/MTGAbility.cpp | 3 +- projects/mtg/src/TargetChooser.cpp | 3 +- 7 files changed, 48 insertions(+), 70 deletions(-) diff --git a/projects/mtg/include/AllAbilities.h b/projects/mtg/include/AllAbilities.h index 8beb5c161..10bb5ecbc 100644 --- a/projects/mtg/include/AllAbilities.h +++ b/projects/mtg/include/AllAbilities.h @@ -71,7 +71,14 @@ public: size_t hD = s.find("halfdown"); s.erase(hD,hD + 8); } - if (s == "x" || s == "X") + if(s == "prex") + { + ManaCost * cX = NEW ManaCost(card->controller()->getManaPool()->Diff(card->getManaCost())); + int preX = + intValue = cX->getCost(Constants::MTG_NB_COLORS); + delete cX; + } + else if (s == "x" || s == "X") { intValue = computeX(spell, card); if(intValue < 0) diff --git a/projects/mtg/src/AIPlayerBaka.cpp b/projects/mtg/src/AIPlayerBaka.cpp index a5cbf4620..abf968fa8 100644 --- a/projects/mtg/src/AIPlayerBaka.cpp +++ b/projects/mtg/src/AIPlayerBaka.cpp @@ -321,50 +321,8 @@ int OrderedAIAction::getEfficiency() case MTGAbility::MANA_PRODUCER://only way to hit this condition is nested manaabilities, ai skips manaproducers by defualt when finding an ability to use. { efficiency = 0; - - if(!coreAbilityCardTarget) - break; - - AManaProducer * amp = dynamic_cast(a); - - //trying to encourage Ai to use his foreach manaproducers in first main - if (amp && amp->output && amp->output->getConvertedCost() && (g->getCurrentGamePhase() == Constants::MTG_PHASE_FIRSTMAIN - || g->getCurrentGamePhase() == Constants::MTG_PHASE_SECONDMAIN) && coreAbilityCardTarget->controller()->game->hand->nb_cards > 0) - { - for (int i = Constants::MTG_NB_COLORS - 1; i > 0; i--) - { - if ((p->game->hand->hasColor(i) || p->game->hand->hasColor(0)) - && amp->output->hasColor(i)) - { - efficiency = 100; - } - } - - if (amp->getCost() && amp->getCost()->getConvertedCost() && p->game->hand->hasX()) - efficiency = 100; - } - else - { - AbilityFactory af; - int suggestion = af.abilityEfficiency(a, p, MODE_ABILITY); - - if (target && a->naType != MTGAbility::MANA_PRODUCER && ((suggestion == BAKA_EFFECT_BAD && p == target->controller()) - || (suggestion == BAKA_EFFECT_GOOD && p != target->controller()))) - { - efficiency = 0; - } - else if (a->naType != MTGAbility::MANA_PRODUCER && (g->getCurrentGamePhase() == Constants::MTG_PHASE_FIRSTMAIN - || g->getCurrentGamePhase() == Constants::MTG_PHASE_SECONDMAIN)) - { - //if its not a manaproducing foreach, and its not targetted, its eff is 90. - //added this basically to cover the unknown foreachs, or untrained ones which were not targetted effects. - efficiency = 90; - } - - } break; } - case MTGAbility::STANDARDABILITYGRANT: { efficiency = 0; @@ -856,7 +814,7 @@ vector AIPlayerBaka::canPayMana(MTGCardInstance * target,ManaCost * AManaProducer * amp = dynamic_cast (a); if(amp && (amp->getCost() && amp->getCost()->extraCosts && !amp->getCost()->extraCosts->canPay())) continue; - if(fullColor == needColorConverted) + if(fullColor == needColorConverted && result->getConvertedCost() < cost->getConvertedCost()) { if(cost->hasColor(0) && amp)//find colorless after color mana. { @@ -878,8 +836,7 @@ vector AIPlayerBaka::canPayMana(MTGCardInstance * target,ManaCost * } } } - i = g->mLayers->actionLayer()->manaObjects.size(); - break; + continue; } GenericActivatedAbility * gmp = dynamic_cast(a); if(gmp && canHandleCost(gmp)) diff --git a/projects/mtg/src/ActionLayer.cpp b/projects/mtg/src/ActionLayer.cpp index 4d8dd2ccb..f57f821fa 100644 --- a/projects/mtg/src/ActionLayer.cpp +++ b/projects/mtg/src/ActionLayer.cpp @@ -34,14 +34,18 @@ int ActionLayer::removeFromGame(ActionElement * e) i = getIndexOf(e); //the destroy event might have changed the contents of mObjects, so we get the index again if (i == -1) return 0; //Should not happen, it means we deleted thesame object twice? - AManaProducer * manaObject = dynamic_cast(e); - if(manaObject) + AbilityFactory af; + if(MTGAbility * a = dynamic_cast(e)) { - for (size_t i = 0; i < manaObjects.size(); i++) - if (manaObjects[i] == e) - { - manaObjects.erase(manaObjects.begin() + i); - } + AManaProducer * manaObject = dynamic_cast(af.getCoreAbility((MTGAbility*)e)); + if(manaObject) + { + for (size_t i = 0; i < manaObjects.size(); i++) + if (manaObjects[i] == e) + { + manaObjects.erase(manaObjects.begin() + i); + } + } } mObjects.erase(mObjects.begin() + i); return 1; diff --git a/projects/mtg/src/ActionStack.cpp b/projects/mtg/src/ActionStack.cpp index 1284327c6..68e690077 100644 --- a/projects/mtg/src/ActionStack.cpp +++ b/projects/mtg/src/ActionStack.cpp @@ -243,8 +243,7 @@ Interruptible(id), tc(tc), cost(_cost), payResult(payResult) int Spell::computeX(MTGCardInstance * card) { - ManaCost * c = NULL; - cost? c = cost->Diff(card->getManaCost()) : c = card->controller()->getManaPool()->Diff(card->getManaCost()); + ManaCost * c = NEW ManaCost(cost->Diff(card->getManaCost())); int x = c->getCost(Constants::MTG_NB_COLORS); delete c; return x; @@ -589,7 +588,8 @@ int ActionStack::setIsInterrupting(Player * player) // Is it a valid interruption request, or is uninterruptible stuff going on in the game? if (game->getCurrentTargetChooser()) { - DebugTrace("ActionStack: WARNING - We were asked to interrupt, but some un-interruptible action is already going on"); + DebugTrace("ActionStack: WARNING - We were asked to interrupt, During Targetchoosing" << endl + << "source: " << (game->getCurrentTargetChooser()->source ? game->getCurrentTargetChooser()->source->name : "None" ) << endl ); return 0; } diff --git a/projects/mtg/src/GuiLayers.cpp b/projects/mtg/src/GuiLayers.cpp index 9fc4892d5..5404ec9ca 100644 --- a/projects/mtg/src/GuiLayers.cpp +++ b/projects/mtg/src/GuiLayers.cpp @@ -2,6 +2,7 @@ #include "GuiLayers.h" #include "Player.h" +#include "AllAbilities.h" GuiLayer::GuiLayer() { @@ -19,21 +20,32 @@ GuiLayer::~GuiLayer() void GuiLayer::Add(JGuiObject *object) { mObjects.push_back(object); - AManaProducer * manaObject = dynamic_cast(object); - if(manaObject) - manaObjects.push_back(object); + AbilityFactory af; + if(MTGAbility * a = dynamic_cast(object)) + { + AManaProducer * manaObject = dynamic_cast(af.getCoreAbility((MTGAbility*)object)); + if(manaObject) + { + manaObjects.push_back(object); + } + } } int GuiLayer::Remove(JGuiObject *object) { - AManaProducer * manaObject = dynamic_cast(object); - if(manaObject) + + AbilityFactory af; + if(MTGAbility * a = dynamic_cast(object)) { - for (size_t i = 0; i < manaObjects.size(); i++) - if (manaObjects[i] == object) - { - manaObjects.erase(manaObjects.begin() + i); - } + AManaProducer * manaObject = dynamic_cast(af.getCoreAbility((MTGAbility*)object)); + if(manaObject) + { + for (size_t i = 0; i < manaObjects.size(); i++) + if (manaObjects[i] == object) + { + manaObjects.erase(manaObjects.begin() + i); + } + } } for (size_t i = 0; i < mObjects.size(); i++) if (mObjects[i] == object) diff --git a/projects/mtg/src/MTGAbility.cpp b/projects/mtg/src/MTGAbility.cpp index b70826444..4fa7ffe46 100644 --- a/projects/mtg/src/MTGAbility.cpp +++ b/projects/mtg/src/MTGAbility.cpp @@ -168,8 +168,7 @@ int AbilityFactory::parseCastRestrictions(MTGCardInstance * card,Player * player } else if (i == 2) { - Spell * spellCard = (Spell*)card; - WParsedInt * secondA = NEW WParsedInt(comparasion[2].c_str(),spellCard?spellCard:NULL,card); + WParsedInt * secondA = NEW WParsedInt(comparasion[2].c_str(),NULL,card); secondAmount = secondA->getValue(); SAFE_DELETE(secondA); } diff --git a/projects/mtg/src/TargetChooser.cpp b/projects/mtg/src/TargetChooser.cpp index a4592c934..0842b649d 100644 --- a/projects/mtg/src/TargetChooser.cpp +++ b/projects/mtg/src/TargetChooser.cpp @@ -180,8 +180,7 @@ TargetChooser * TargetChooserFactory::createTargetChooser(string s, MTGCardInsta { targetMin = true;//if upto: is not found, then we need to have a minimum of the amount.... } - Spell * sCard = (Spell*)card; - WParsedInt * howmuch = NEW WParsedInt(howmany, sCard?sCard:NULL, card); + WParsedInt * howmuch = NEW WParsedInt(howmany, NULL, card); howmany.find("anyamount") != string::npos?maxtargets = TargetChooser::UNLITMITED_TARGETS:maxtargets = howmuch->getValue(); if(howmany.find("anyamount") != string::npos) targetMin = false;