summaryrefslogtreecommitdiffstats
path: root/source/CraftingRecipes.h
diff options
context:
space:
mode:
authormadmaxoft@gmail.com <madmaxoft@gmail.com@0a769ca7-a7f5-676a-18bf-c427514a06d6>2012-06-04 14:08:20 +0200
committermadmaxoft@gmail.com <madmaxoft@gmail.com@0a769ca7-a7f5-676a-18bf-c427514a06d6>2012-06-04 14:08:20 +0200
commitb355bdeccecf727d30e48634df9b5d424db570bc (patch)
tree00489a1317e6ad22a28698f24bd9935160257789 /source/CraftingRecipes.h
parentFixed MSVC2010 projects for new zlib (diff)
downloadcuberite-b355bdeccecf727d30e48634df9b5d424db570bc.tar
cuberite-b355bdeccecf727d30e48634df9b5d424db570bc.tar.gz
cuberite-b355bdeccecf727d30e48634df9b5d424db570bc.tar.bz2
cuberite-b355bdeccecf727d30e48634df9b5d424db570bc.tar.lz
cuberite-b355bdeccecf727d30e48634df9b5d424db570bc.tar.xz
cuberite-b355bdeccecf727d30e48634df9b5d424db570bc.tar.zst
cuberite-b355bdeccecf727d30e48634df9b5d424db570bc.zip
Diffstat (limited to '')
-rw-r--r--source/CraftingRecipes.h82
1 files changed, 82 insertions, 0 deletions
diff --git a/source/CraftingRecipes.h b/source/CraftingRecipes.h
new file mode 100644
index 000000000..bf85534b1
--- /dev/null
+++ b/source/CraftingRecipes.h
@@ -0,0 +1,82 @@
+
+// CraftingRecipes.h
+
+// Interfaces to the cCraftingRecipes class representing the storage of crafting recipes
+
+
+
+
+#pragma once
+
+#include "cItem.h"
+
+
+
+
+
+class cCraftingRecipes
+{
+public:
+ static const int MAX_GRID_WIDTH = 3;
+ static const int MAX_GRID_HEIGHT = 3;
+
+ cCraftingRecipes(void);
+ ~cCraftingRecipes();
+
+ /// Offers an item resulting from the crafting grid setup. Doesn't modify the grid
+ cItem Offer(const cItem * a_CraftingGrid, int a_GridWidth, int a_GridHeight);
+
+ /// Crafts the item resulting from the crafting grid setup. Modifies the grid, returns the crafted item
+ cItem Craft(cItem * a_CraftingGrid, int a_GridWidth, int a_GridHeight);
+
+protected:
+
+ struct cRecipeSlot
+ {
+ cItem m_Item;
+ int x, y; // 1..3, or -1 for "any"
+ } ;
+ typedef std::vector<cRecipeSlot> cRecipeSlots;
+
+ // A single recipe, stored. Each recipe is normalized right after parsing (NormalizeIngredients())
+ struct cRecipe
+ {
+ cRecipeSlots m_Ingredients;
+ cItem m_Result;
+
+ // Size of the regular items in the recipe; "anywhere" items are excluded:
+ int m_Width;
+ int m_Height;
+ } ;
+ typedef std::vector<cRecipe *> cRecipes;
+
+ cRecipes m_Recipes;
+
+ void LoadRecipes(void);
+ void ClearRecipes(void);
+
+ /// Parses the recipe line and adds it into m_Recipes. a_LineNum is used for diagnostic warnings only
+ void AddRecipeLine(int a_LineNum, const AString & a_RecipeLine);
+
+ /// Parses an item string in the format "<ItemType>[^<Damage>]", returns true if successful.
+ bool ParseItem(const AString & a_String, cItem & a_Item);
+
+ /// Parses one ingredient and adds it to the specified recipe. Returns true if successful.
+ bool ParseIngredient(const AString & a_String, cRecipe * a_Recipe);
+
+ /// Moves the recipe to top-left corner, sets its MinWidth / MinHeight
+ void NormalizeIngredients(cRecipe * a_Recipe);
+
+ /// Finds a recipe matching the crafting grid. Returns a newly allocated recipe (with all its coords set) or NULL if not found. Caller must delete return value!
+ cRecipe * FindRecipe(const cItem * a_CraftingGrid, int a_GridWidth, int a_GridHeight);
+
+ /// Same as FindRecipe, but the grid is guaranteed to be of minimal dimensions needed
+ cRecipe * FindRecipeCropped(const cItem * a_CraftingGrid, int a_GridWidth, int a_GridHeight, int a_GridStride);
+
+ /// Checks if the grid matches the specified recipe, offset by the specified offsets. Returns a matched cRecipe * if so, or NULL if not matching. Caller must delete the return value!
+ cRecipe * MatchRecipe(const cItem * a_CraftingGrid, int a_GridWidth, int a_GridHeight, int a_GridStride, const cRecipe * a_Recipe, int a_OffsetX, int a_OffsetY);
+} ;
+
+
+
+