From 8546f3dff83dca01d74a95ae65f6759bc3b51d50 Mon Sep 17 00:00:00 2001 From: "wagic.the.homebrew" Date: Sat, 9 Jul 2011 09:25:31 +0000 Subject: [PATCH] Fix for issue 700 (Basic Lands randomly stop working) --- projects/mtg/bin/Res/test/_tests.txt | 2 +- ...arrior_i650.txt => tidal_warrior_i649.txt} | 0 projects/mtg/include/AllAbilities.h | 22 ++++------ projects/mtg/src/AllAbilities.cpp | 40 ++++++++++++++++++- projects/mtg/src/MTGAbility.cpp | 2 +- 5 files changed, 48 insertions(+), 18 deletions(-) rename projects/mtg/bin/Res/test/{tidal_warrior_i650.txt => tidal_warrior_i649.txt} (100%) diff --git a/projects/mtg/bin/Res/test/_tests.txt b/projects/mtg/bin/Res/test/_tests.txt index d201c09cd..707da9af3 100644 --- a/projects/mtg/bin/Res/test/_tests.txt +++ b/projects/mtg/bin/Res/test/_tests.txt @@ -563,7 +563,7 @@ threaten.txt throne_of_bone.txt thunder-thrash_elder.txt tidal_warrior_i646.txt -tidal_warrior_i650.txt +tidal_warrior_i649.txt tidal_warrior_i652.txt titanic_ultimatum.txt tolsimir_wolfblood.txt diff --git a/projects/mtg/bin/Res/test/tidal_warrior_i650.txt b/projects/mtg/bin/Res/test/tidal_warrior_i649.txt similarity index 100% rename from projects/mtg/bin/Res/test/tidal_warrior_i650.txt rename to projects/mtg/bin/Res/test/tidal_warrior_i649.txt diff --git a/projects/mtg/include/AllAbilities.h b/projects/mtg/include/AllAbilities.h index 6d42a7682..8878d6b8b 100644 --- a/projects/mtg/include/AllAbilities.h +++ b/projects/mtg/include/AllAbilities.h @@ -2232,7 +2232,6 @@ class ALord: public ListMaintainerAbility, public NestedAbility public: int includeSelf; map abilities; - vector bermudaTriangle; //Hack: Lost abilities that need to be properly removed if they reappear ALord(int _id, MTGCardInstance * card, TargetChooser * _tc, int _includeSelf, MTGAbility * a) : ListMaintainerAbility(_id, card), NestedAbility(a) @@ -2241,19 +2240,15 @@ public: tc->targetter = NULL; includeSelf = _includeSelf; if(ability->aType == MTGAbility::STANDARD_PREVENT) - aType = MTGAbility::STANDARD_PREVENT; + aType = MTGAbility::STANDARD_PREVENT; } - void Update(float dt) + //returns true if it is me who created ability a attached to Damageable d + bool isParentOf(Damageable * d, MTGAbility * a) { - ListMaintainerAbility::Update(dt); - - //This is a hack to avoid some abilities "combing back from the dead" because of the loseAbility keyword :/ - for (int i = (int)(bermudaTriangle.size()) - 1 ; i >= 0 ; --i) - { - if (game->removeObserver(bermudaTriangle[i])) - bermudaTriangle.erase(bermudaTriangle.begin()+i); - } + if (abilities.find(d) != abilities.end()) + return (abilities[d] == a); + return false; } int canBeInList(Player *p) @@ -2267,7 +2262,7 @@ public: if(card->isPhased || source->isPhased) return 0; if ((includeSelf || card != source) && tc->canTarget(card)) - return 1; + return 1; return 0; } @@ -2323,8 +2318,7 @@ public: { if (abilities.find(card) != abilities.end()) { - if (!game->removeObserver(abilities[card])) - bermudaTriangle.push_back(abilities[card]); + game->removeObserver(abilities[card]); abilities.erase(card); } return 1; diff --git a/projects/mtg/src/AllAbilities.cpp b/projects/mtg/src/AllAbilities.cpp index 6e393a3d5..be94518d3 100644 --- a/projects/mtg/src/AllAbilities.cpp +++ b/projects/mtg/src/AllAbilities.cpp @@ -2847,6 +2847,20 @@ int ALoseAbilities::addToGame() ActionLayer * al = game->mLayers->actionLayer(); + + //Build a list of Lords in game, this is a hack mostly for lands, see below + vector lordsInGame; + for (int i = (int)(al->mObjects.size()) - 1; i > 0; i--) //0 is not a mtgability...hackish + { + if (al->mObjects[i]) + { + MTGAbility * currentAction = (MTGAbility *) al->mObjects[i]; + ALord * l = dynamic_cast (currentAction); + if(l) + lordsInGame.push_back(l); + } + } + for (int i = (int)(al->mObjects.size()) - 1; i > 0; i--) //0 is not a mtgability...hackish { if (al->mObjects[i]) @@ -2857,8 +2871,30 @@ int ALoseAbilities::addToGame() continue; if (currentAction->source == _target) { - storedAbilities.push_back(currentAction); - al->removeFromGame(currentAction); + bool canRemove = true; + + //Hack: we don't remove abilities on the card if they are provided by an external lord ability. + //This is partly to solve the following issues: + // http://code.google.com/p/wagic/issues/detail?id=647 + // http://code.google.com/p/wagic/issues/detail?id=700 + // But also because "most" abilities granted by lords will actually go away by themselves, + // based on the fact that we usually remove abilities AND change the type of the card + //Also in a general way we don't want to remove the card's abilities if it is provided by a Lord, + //although there is also a problem with us not handling the P/T layer correctly + for (size_t i = 0; i < lordsInGame.size(); ++i) + { + if (lordsInGame[i]->isParentOf(_target, currentAction)) + { + canRemove = false; + break; + } + } + + if (canRemove) + { + storedAbilities.push_back(currentAction); + al->removeFromGame(currentAction); + } } } } diff --git a/projects/mtg/src/MTGAbility.cpp b/projects/mtg/src/MTGAbility.cpp index 8100ae45a..cab069c6e 100644 --- a/projects/mtg/src/MTGAbility.cpp +++ b/projects/mtg/src/MTGAbility.cpp @@ -3903,7 +3903,7 @@ TriggerAtPhase::TriggerAtPhase(int id, MTGCardInstance * source, Targetable * ta newPhase = g->getCurrentGamePhase(); currentPhase = newPhase; } - } +} int TriggerAtPhase::trigger() {