diff --git a/projects/mtg/bin/Res/test/_tests.txt b/projects/mtg/bin/Res/test/_tests.txt index 8dc7ce29d..1caa963c7 100644 --- a/projects/mtg/bin/Res/test/_tests.txt +++ b/projects/mtg/bin/Res/test/_tests.txt @@ -540,6 +540,7 @@ threaten.txt throne_of_bone.txt thunder-thrash_elder.txt tidal_warrior_i646.txt +tidal_warrior_i650.txt titanic_ultimatum.txt tolsimir_wolfblood.txt torture.txt diff --git a/projects/mtg/bin/Res/test/tidal_warrior_i650.txt b/projects/mtg/bin/Res/test/tidal_warrior_i650.txt new file mode 100644 index 000000000..58e3a9947 --- /dev/null +++ b/projects/mtg/bin/Res/test/tidal_warrior_i650.txt @@ -0,0 +1,21 @@ +#Testing Tidal Warrior's "target becomes island" ability, +# Make sure it only lasts until end of turn +#see http://code.google.com/p/wagic/issues/detail?id=650 +[INIT] +FIRSTMAIN +[PLAYER1] +inplay:Forest, Tidal Warrior +[PLAYER2] +[DO] +Tidal Warrior +Forest +eot +eot +Forest +[ASSERT] +UNTAP +[PLAYER1] +inplay:Forest, Tidal Warrior +manapool:{G} +[PLAYER2] +[END] \ No newline at end of file diff --git a/projects/mtg/include/AllAbilities.h b/projects/mtg/include/AllAbilities.h index ce5721aed..91f016d35 100644 --- a/projects/mtg/include/AllAbilities.h +++ b/projects/mtg/include/AllAbilities.h @@ -918,11 +918,14 @@ class MultiAbility: public ActivatedAbility { public: vector abilities; + //Maintains abilities created by this instance, for cleanup + vector clones; MultiAbility(int _id, MTGCardInstance * card, Targetable * _target, ManaCost * _cost); int Add(MTGAbility * ability); int resolve(); int addToGame(); + int destroy(); const char * getMenuText(); MultiAbility * clone() const; ~MultiAbility(); diff --git a/projects/mtg/src/ActionLayer.cpp b/projects/mtg/src/ActionLayer.cpp index 05793a57d..75d282135 100644 --- a/projects/mtg/src/ActionLayer.cpp +++ b/projects/mtg/src/ActionLayer.cpp @@ -28,6 +28,11 @@ int ActionLayer::removeFromGame(ActionElement * e) if (isWaitingForAnswer() == e) setCurrentWaitingAction(NULL); e->destroy(); + + 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? + mObjects.erase(mObjects.begin() + i); mCount--; return 1; diff --git a/projects/mtg/src/AllAbilities.cpp b/projects/mtg/src/AllAbilities.cpp index 6b86d0e18..044a7bf70 100644 --- a/projects/mtg/src/AllAbilities.cpp +++ b/projects/mtg/src/AllAbilities.cpp @@ -2163,11 +2163,23 @@ int MultiAbility::addToGame() MTGAbility * a = abilities[i]->clone(); a->target = target; a->addToGame(); + clones.push_back(a); } MTGAbility::addToGame(); return 1; } +int MultiAbility::destroy() +{ + for (size_t i = 0; i < clones.size(); ++i) + { + //I'd like to call game->removeObserver here instead of using forceDestroy, but I get a weird crash after that, need to investigate a bit + clones[i]->forceDestroy = 1; + } + clones.clear(); + return ActivatedAbility::destroy(); +} + const char * MultiAbility::getMenuText() { if (abilities.size()) diff --git a/projects/mtg/src/DeckStats.cpp b/projects/mtg/src/DeckStats.cpp index b38e622aa..a2cb57312 100644 --- a/projects/mtg/src/DeckStats.cpp +++ b/projects/mtg/src/DeckStats.cpp @@ -448,7 +448,7 @@ void StatsWrapper::updateStats(DeckDataWrapper *myDeck) //but through a rule that is outside of the primitives. This block is a hack to address this const int colors[] = {Constants::MTG_COLOR_GREEN, Constants::MTG_COLOR_BLUE, Constants::MTG_COLOR_RED, Constants::MTG_COLOR_BLACK, Constants::MTG_COLOR_WHITE}; const string lands[] = { "forest", "island", "mountain", "swamp", "plains" }; - for (int i = 0; i < sizeof(colors)/sizeof(colors[0]); ++i) + for (unsigned int i = 0; i < sizeof(colors)/sizeof(colors[0]); ++i) { int colorId = colors[i]; string type = lands[i]; diff --git a/projects/mtg/src/TestSuiteAI.cpp b/projects/mtg/src/TestSuiteAI.cpp index 31985a136..b434f3070 100644 --- a/projects/mtg/src/TestSuiteAI.cpp +++ b/projects/mtg/src/TestSuiteAI.cpp @@ -491,6 +491,12 @@ int TestSuite::assertGame() sprintf(result, "==Mana problem. Was expecting %i but got %i for player %i==
", endState.playerData[i].manapool->getConvertedCost(), p->getManaPool()->getConvertedCost(), i); Log(result); + + if ( endState.playerData[i].manapool->getConvertedCost() == p->getManaPool()->getConvertedCost()) + { + sprintf(result, "====(Apparently Mana Color issues since converted cost is the same)==
"); + Log(result); + } error++; } diff --git a/projects/mtg/src/WFilter.cpp b/projects/mtg/src/WFilter.cpp index 81ff7a11a..2f11c6699 100644 --- a/projects/mtg/src/WFilter.cpp +++ b/projects/mtg/src/WFilter.cpp @@ -264,7 +264,7 @@ bool WCFilterProducesColor::isMatch(MTGCard * c) //Basic lands are not producing their mana through regular abilities anymore, //but through a rule that is outside of the primitives. This block is a hack to address this const string lands[] = { "dummy(colorless)", "forest", "island", "mountain", "swamp", "plains" }; - if ((color < sizeof(lands)/sizeof(lands[0])) && c->data->hasType(lands[color].c_str())) + if ((color < (int)(sizeof(lands)/sizeof(lands[0]))) && c->data->hasType(lands[color].c_str())) return true; //Retrieve non basic Mana abilities