From 416617fc0d28dd599807174a37ee2e929fcb8822 Mon Sep 17 00:00:00 2001 From: "wagic.the.homebrew@gmail.com" Date: Sun, 7 Nov 2010 02:27:54 +0000 Subject: [PATCH] Erwan - fixed memory leak in AEquip/ATeach - Test suite now trims strings correctly (allows to have space between comma-separated card names) - Added Paradise Mantle (for ATeach test) - removed a missing wallpaper from wallpapers list --- projects/mtg/bin/Res/graphics/wallpapers.txt | 1 - projects/mtg/bin/Res/sets/primitives/mtg.txt | 12 ++++ projects/mtg/bin/Res/test/_tests.txt | 1 + projects/mtg/bin/Res/test/paradise_mantle.txt | 20 ++++++ projects/mtg/include/AllAbilities.h | 2 +- projects/mtg/src/TestSuiteAI.cpp | 4 +- projects/mtg/src/utils.cpp | 72 +++++++++---------- 7 files changed, 72 insertions(+), 40 deletions(-) create mode 100644 projects/mtg/bin/Res/test/paradise_mantle.txt diff --git a/projects/mtg/bin/Res/graphics/wallpapers.txt b/projects/mtg/bin/Res/graphics/wallpapers.txt index c356449c8..d820084cc 100644 --- a/projects/mtg/bin/Res/graphics/wallpapers.txt +++ b/projects/mtg/bin/Res/graphics/wallpapers.txt @@ -6,5 +6,4 @@ wallpapers/kaioshin_garruk.jpg wallpapers/kaioshin_jace.jpg graphics/shop.jpg themes/Classic/backdrop.jpg -themes/Jade/backdrop.jpg wallpapers/kaioshin_ravager.jpg diff --git a/projects/mtg/bin/Res/sets/primitives/mtg.txt b/projects/mtg/bin/Res/sets/primitives/mtg.txt index 4f71e6fec..7181f2276 100644 --- a/projects/mtg/bin/Res/sets/primitives/mtg.txt +++ b/projects/mtg/bin/Res/sets/primitives/mtg.txt @@ -38929,6 +38929,18 @@ power=6 toughness=3 [/card] [card] +name=Paradise Mantle +auto=teach(creature) {t}:add{r} +auto=teach(creature) {t}:add{w} +auto=teach(creature) {t}:add{b} +auto=teach(creature) {t}:add{u} +auto=teach(creature) {t}:add{g} +auto={1}:equip +type=artifact +subtype=equipment +mana={0} +[/card] +[card] name=Paradise Plume auto=choice name(White) && counter(0/0,1,White) all(this) auto=choice name(Blue) && counter(0/0,1,Blue) all(this) diff --git a/projects/mtg/bin/Res/test/_tests.txt b/projects/mtg/bin/Res/test/_tests.txt index 433e502eb..dde6bb68f 100644 --- a/projects/mtg/bin/Res/test/_tests.txt +++ b/projects/mtg/bin/Res/test/_tests.txt @@ -391,6 +391,7 @@ OneDozenEyes.txt orcish_artillery.txt orcish_lumberjack.txt overrun.txt +paradise_mantle.txt paralysis.txt paralysis2.txt persuasion.txt diff --git a/projects/mtg/bin/Res/test/paradise_mantle.txt b/projects/mtg/bin/Res/test/paradise_mantle.txt new file mode 100644 index 000000000..d8fd4d1b2 --- /dev/null +++ b/projects/mtg/bin/Res/test/paradise_mantle.txt @@ -0,0 +1,20 @@ +#Bug: "Teach" functionality has a memory leak whenever it equips a creature +[INIT] +FIRSTMAIN +[PLAYER1] +inplay:grizzly bears,raging goblin +hand:paradise mantle +manapool:{2} +[PLAYER2] +[DO] +paradise mantle +paradise mantle +grizzly bears +paradise mantle +raging goblin +[ASSERT] +FIRSTMAIN +[PLAYER1] +inplay:grizzly bears,raging goblin, paradise mantle +[PLAYER2] +[END] \ No newline at end of file diff --git a/projects/mtg/include/AllAbilities.h b/projects/mtg/include/AllAbilities.h index 6b0e73d6a..e0453733e 100644 --- a/projects/mtg/include/AllAbilities.h +++ b/projects/mtg/include/AllAbilities.h @@ -2469,7 +2469,7 @@ public: source->target = NULL; for (size_t i = 0; i < currentAbilities.size(); ++i){ MTGAbility * a = currentAbilities[i]; - if(dynamic_cast(a)){ + if(dynamic_cast(a) || dynamic_cast(a)){ SAFE_DELETE(a); continue; } diff --git a/projects/mtg/src/TestSuiteAI.cpp b/projects/mtg/src/TestSuiteAI.cpp index ab547eafe..d046780b1 100644 --- a/projects/mtg/src/TestSuiteAI.cpp +++ b/projects/mtg/src/TestSuiteAI.cpp @@ -232,10 +232,10 @@ void TestSuiteState::parsePlayerState(int playerId, string s){ unsigned int value; limiter = s.find(","); if (limiter != string::npos){ - value = Rules::getMTGId(s.substr(0,limiter)); + value = Rules::getMTGId(trim(s.substr(0,limiter))); s = s.substr(limiter+1); }else{ - value = Rules::getMTGId(s); + value = Rules::getMTGId(trim(s)); s = ""; } if (value) playerData[playerId].zones[area].add(value); diff --git a/projects/mtg/src/utils.cpp b/projects/mtg/src/utils.cpp index 6510b9297..707cd8cc0 100644 --- a/projects/mtg/src/utils.cpp +++ b/projects/mtg/src/utils.cpp @@ -219,40 +219,40 @@ std::vector split(const std::string &s, char delim) { } -std::string wordWrap(std::string sentence, int width) -{ - std::string::iterator it = sentence.begin(); - - //remember how long next word is - int nextWordLength = 0; - int distanceFromWidth = width; - - while (it != sentence.end()) - { - while (*it != ' ') - { - nextWordLength++; - distanceFromWidth--; - - ++it; - - // check if done - if (it == sentence.end()) - { - return sentence; - } - } - - if (nextWordLength > distanceFromWidth) - { - *it = '\n'; - distanceFromWidth = width; - nextWordLength = 0; - } - - //skip the space - ++it; - } - - return sentence; +std::string wordWrap(std::string sentence, int width) +{ + std::string::iterator it = sentence.begin(); + + //remember how long next word is + int nextWordLength = 0; + int distanceFromWidth = width; + + while (it != sentence.end()) + { + while (*it != ' ') + { + nextWordLength++; + distanceFromWidth--; + + ++it; + + // check if done + if (it == sentence.end()) + { + return sentence; + } + } + + if (nextWordLength > distanceFromWidth) + { + *it = '\n'; + distanceFromWidth = width; + nextWordLength = 0; + } + + //skip the space + ++it; + } + + return sentence; } \ No newline at end of file