From 429ccb59b580c8925563d116ed132b55b6a58a80 Mon Sep 17 00:00:00 2001 From: "madmaxoft@gmail.com" Date: Sat, 9 Jun 2012 18:52:30 +0000 Subject: [PATCH] Fixed a bug in crafting recipes - would consume multiple items of asterisked ingredients (FS #205) git-svn-id: http://mc-server.googlecode.com/svn/trunk@593 0a769ca7-a7f5-676a-18bf-c427514a06d6 --- source/CraftingRecipes.cpp | 43 ++++++++++++++++++++++---------------- 1 file changed, 25 insertions(+), 18 deletions(-) diff --git a/source/CraftingRecipes.cpp b/source/CraftingRecipes.cpp index 391de691b..37d82965e 100644 --- a/source/CraftingRecipes.cpp +++ b/source/CraftingRecipes.cpp @@ -457,30 +457,37 @@ cCraftingRecipes::cRecipe * cCraftingRecipes::MatchRecipe(const cItem * a_Crafti EndY = itrS->y; } bool Found = false; - for (int x = StartX; x <= EndX; x++) for (int y = StartY; y <= EndY; y++) + for (int x = StartX; x <= EndX; x++) { - if (HasMatched[x][y]) + for (int y = StartY; y <= EndY; y++) { - // Already matched some other item - continue; - } - int GridIdx = x + a_GridStride * y; - if ( - (a_CraftingGrid[GridIdx].m_ItemID == itrS->m_Item.m_ItemID) && - ( - (itrS->m_Item.m_ItemHealth < 0) || // doesn't want damage comparison - (itrS->m_Item.m_ItemHealth == a_CraftingGrid[GridIdx].m_ItemHealth) // the damage matches + if (HasMatched[x][y]) + { + // Already matched some other item + continue; + } + int GridIdx = x + a_GridStride * y; + if ( + (a_CraftingGrid[GridIdx].m_ItemID == itrS->m_Item.m_ItemID) && + ( + (itrS->m_Item.m_ItemHealth < 0) || // doesn't want damage comparison + (itrS->m_Item.m_ItemHealth == a_CraftingGrid[GridIdx].m_ItemHealth) // the damage matches + ) ) - ) + { + HasMatched[x][y] = true; + Found = true; + MatchedSlots.push_back(*itrS); + MatchedSlots.back().x = x; + MatchedSlots.back().y = y; + break; + } + } // for y + if (Found) { - HasMatched[x][y] = true; - Found = true; - MatchedSlots.push_back(*itrS); - MatchedSlots.back().x = x; - MatchedSlots.back().y = y; break; } - } // for y, for x - "anywhere" + } // for x if (!Found) { return NULL;