summaryrefslogtreecommitdiffstats
path: root/src/CraftingRecipes.h
diff options
context:
space:
mode:
Diffstat (limited to '')
-rw-r--r--src/CraftingRecipes.h52
1 files changed, 43 insertions, 9 deletions
diff --git a/src/CraftingRecipes.h b/src/CraftingRecipes.h
index 9659e53fc..7e4ac86ae 100644
--- a/src/CraftingRecipes.h
+++ b/src/CraftingRecipes.h
@@ -10,10 +10,6 @@
#include "Item.h"
-
-
-
-
// fwd: cPlayer.h
class cPlayer;
@@ -104,7 +100,20 @@ protected:
+/**
+The crafting recipes are the configurations to build a result item out of a set
+of ingredient items.
+
+The recipes are configured in the `crafting.txt`. When populating the crafting
+grid in game (inventory or crafting table), the items are compared to the
+ingredients to find a matching recipe and show and craft the result.
+Each recipe is defined via the result, the ingredients and the minecraft recipe
+name.
+
+To handle the crafting recipes internally efficient the vector index of the
+`cRecipes` is used as `RecipeId`.
+*/
class cCraftingRecipes
{
public:
@@ -117,7 +126,8 @@ public:
/** Returns the recipe for current crafting grid. Doesn't modify the grid. Clears a_Recipe if no recipe found. */
void GetRecipe(cPlayer & a_Player, cCraftingGrid & a_CraftingGrid, cCraftingRecipe & a_Recipe);
-protected:
+ /** Find recipes and returns the RecipeIds which contain the new item and all ingredients are in the known items */
+ std::vector<UInt32> FindNewRecipesForItem(const cItem & a_Item, const std::set<cItem, cItem::sItemCompare> & a_KnownItems);
struct cRecipeSlot
{
@@ -132,11 +142,21 @@ protected:
{
cRecipeSlots m_Ingredients;
cItem m_Result;
+ AString m_RecipeName;
// Size of the regular items in the recipe; "anywhere" items are excluded:
int m_Width;
int m_Height;
} ;
+
+ /** Returns the recipe by id */
+ cRecipe * GetRecipeById(UInt32 a_RecipeId);
+
+ /** Gets a map of all recipes with name and recipe id */
+ const std::map<AString, UInt32> & GetRecipeNameMap();
+
+protected:
+
typedef std::vector<cRecipe *> cRecipes;
cRecipes m_Recipes;
@@ -170,8 +190,22 @@ protected:
/** Searches for anything dye related for leather, calculates the appropriate color value, and sets the resulting value. */
void HandleDyedLeather(const cItem * a_CraftingGrid, cCraftingRecipes::cRecipe * a_Recipe, int a_GridStride, int a_GridWidth, int a_GridHeight);
-} ;
-
-
-
+private:
+ /** Mapping the minecraft recipe names to the internal cuberite recipe Ids */
+ std::map<AString, UInt32> m_RecipeNameMap;
+
+ /**
+ Checks if all ingredients of the a_Recipe are within the a_KnownItems list and
+ if the a_NewItem is part of the ingredients.
+ This makes sure to only find 'newly discovered' recipes.
+ */
+ bool IsNewCraftableRecipe(
+ const cRecipe * a_Recipe,
+ const cItem & a_NewItem,
+ const std::set<cItem, cItem::sItemCompare> & a_KnownItems
+ );
+
+ /** Populates the RecipeNameMap */
+ void PopulateRecipeNameMap(void);
+} ;