From d9464f53c284485ee464f4b7775d628f6167c5c6 Mon Sep 17 00:00:00 2001 From: "wagic.the.homebrew@gmail.com" Date: Mon, 28 Sep 2009 14:12:50 +0000 Subject: [PATCH] Erwan -fix a crash when the AI tries to use a spell with X in the manacost --- .../Res/test/manual/howl_from_beyond_ai.txt | 20 +++++++++++++++++++ .../Res/test/manual/serpent_assassin_ai.txt | 19 ++++++++++++++++++ projects/mtg/include/ActionStack.h | 1 + projects/mtg/include/AllAbilities.h | 6 ++---- projects/mtg/src/ActionStack.cpp | 7 +++++++ projects/mtg/src/MTGAbility.cpp | 6 ++---- 6 files changed, 51 insertions(+), 8 deletions(-) create mode 100644 projects/mtg/bin/Res/test/manual/howl_from_beyond_ai.txt create mode 100644 projects/mtg/bin/Res/test/manual/serpent_assassin_ai.txt diff --git a/projects/mtg/bin/Res/test/manual/howl_from_beyond_ai.txt b/projects/mtg/bin/Res/test/manual/howl_from_beyond_ai.txt new file mode 100644 index 000000000..4b89ff9f0 --- /dev/null +++ b/projects/mtg/bin/Res/test/manual/howl_from_beyond_ai.txt @@ -0,0 +1,20 @@ +#Bug:Does ai correctly cast Howl From Beyond on its creatures ? +[INIT] +SECONDMAIN +[PLAYER1] +inplay:grizzly bears,raging goblin,goblin king +[PLAYER2] +hand:howl from beyond +inplay:air elemental,swamp,plains,swamp,mountain,forest +[DO] +ai +ai +[ASSERT] +COMBATEND +[PLAYER1] +inplay:Wildslayer Elves,Armadillo Cloak +life:25 +[PLAYER2] +graveyard:grizzly bears +life:17 +[END] \ No newline at end of file diff --git a/projects/mtg/bin/Res/test/manual/serpent_assassin_ai.txt b/projects/mtg/bin/Res/test/manual/serpent_assassin_ai.txt new file mode 100644 index 000000000..ecc24fe40 --- /dev/null +++ b/projects/mtg/bin/Res/test/manual/serpent_assassin_ai.txt @@ -0,0 +1,19 @@ +#Bug:Does ai correctly cast Serpent Assassin on opponent's creatures ? +[INIT] +SECONDMAIN +[PLAYER1] +[PLAYER2] +hand:serpent assassin +inplay:air elemental,swamp,plains,swamp,mountain,forest,raging goblin,goblin king +[DO] +ai +ai +[ASSERT] +COMBATEND +[PLAYER1] +inplay:Wildslayer Elves,Armadillo Cloak +life:25 +[PLAYER2] +graveyard:grizzly bears +life:17 +[END] \ No newline at end of file diff --git a/projects/mtg/include/ActionStack.h b/projects/mtg/include/ActionStack.h index 4b9d3a366..a7e57766a 100644 --- a/projects/mtg/include/ActionStack.h +++ b/projects/mtg/include/ActionStack.h @@ -80,6 +80,7 @@ class Spell: public Interruptible { TargetChooser * tc; ManaCost * cost; int payResult; + int computeX(MTGCardInstance * card); Spell(MTGCardInstance* _source); Spell(int id, MTGCardInstance* _source, TargetChooser *_tc, ManaCost * _cost, int payResult); ~Spell(); diff --git a/projects/mtg/include/AllAbilities.h b/projects/mtg/include/AllAbilities.h index 5d009b383..b7b5e6f39 100644 --- a/projects/mtg/include/AllAbilities.h +++ b/projects/mtg/include/AllAbilities.h @@ -30,10 +30,8 @@ public: int intValue; int computeX(Spell * spell, MTGCardInstance * card){ - ManaCost * c = spell->cost->Diff(card->getManaCost()); - int x = c->getCost(Constants::MTG_NB_COLORS); - delete c; - return x; + if (spell) return spell->computeX(card); + return 1; //this should only hapen when the ai calls the ability. This is to give it an idea of the "direction" of X (positive/negative) } WParsedInt(int value = 0){ intValue = value; diff --git a/projects/mtg/src/ActionStack.cpp b/projects/mtg/src/ActionStack.cpp index b2ba297d2..5998af275 100644 --- a/projects/mtg/src/ActionStack.cpp +++ b/projects/mtg/src/ActionStack.cpp @@ -121,6 +121,13 @@ Spell::Spell(int id, MTGCardInstance * _source, TargetChooser * tc, ManaCost * _ from = _source->getCurrentZone(); } +int Spell::computeX(MTGCardInstance * card){ + ManaCost * c = cost->Diff(card->getManaCost()); + int x = c->getCost(Constants::MTG_NB_COLORS); + delete c; + return x; +} + bool Spell::kickerWasPaid(){ return (payResult == ManaCost::MANA_PAID_WITH_KICKER); } diff --git a/projects/mtg/src/MTGAbility.cpp b/projects/mtg/src/MTGAbility.cpp index 22f142c12..a809a0892 100644 --- a/projects/mtg/src/MTGAbility.cpp +++ b/projects/mtg/src/MTGAbility.cpp @@ -699,10 +699,8 @@ int AbilityFactory::abilityEfficiency(MTGAbility * a, Player * p, int mode){ //Returns the "X" cost that was paid for a spell int AbilityFactory::computeX(Spell * spell, MTGCardInstance * card){ - ManaCost * c = spell->cost->Diff(card->getManaCost()); - int x = c->getCost(Constants::MTG_NB_COLORS); - delete c; - return x; + if (spell) return spell->computeX(card); + return 0; } //Some basic functionalities that can be added automatically in the text file