diff options
Diffstat (limited to 'src/CraftingRecipes.h')
-rw-r--r-- | src/CraftingRecipes.h | 124 |
1 files changed, 71 insertions, 53 deletions
diff --git a/src/CraftingRecipes.h b/src/CraftingRecipes.h index 7e4ac86ae..38936636b 100644 --- a/src/CraftingRecipes.h +++ b/src/CraftingRecipes.h @@ -19,19 +19,19 @@ class cPlayer; class cCraftingGrid // tolua_export { // tolua_export -public: + public: cCraftingGrid(const cCraftingGrid & a_Original); cCraftingGrid(int a_Width, int a_Height); // tolua_export cCraftingGrid(const cItem * a_Items, int a_Width, int a_Height); ~cCraftingGrid(); // tolua_begin - int GetWidth (void) const {return m_Width; } - int GetHeight(void) const {return m_Height; } - cItem & GetItem (int x, int y) const; - void SetItem (int x, int y, ENUM_ITEM_TYPE a_ItemType, char a_ItemCount, short a_ItemHealth); - void SetItem (int x, int y, const cItem & a_Item); - void Clear (void); + int GetWidth(void) const { return m_Width; } + int GetHeight(void) const { return m_Height; } + cItem & GetItem(int x, int y) const; + void SetItem(int x, int y, ENUM_ITEM_TYPE a_ItemType, char a_ItemCount, short a_ItemHealth); + void SetItem(int x, int y, const cItem & a_Item); + void Clear(void); /** Removes items in a_Grid from m_Items[] (used by cCraftingRecipe::ConsumeIngredients()) */ void ConsumeGrid(const cCraftingGrid & a_Grid); @@ -41,17 +41,17 @@ public: // tolua_end - cItem * GetItems(void) const {return m_Items; } + cItem * GetItems(void) const { return m_Items; } - /** Copies internal contents into the item array specified. Assumes that the array has the same dimensions as self */ - void CopyToItems(cItem * a_Items) const; + /** Copies internal contents into the item array specified. Assumes that the array has the same dimensions as self + */ + void CopyToItems(cItem * a_Items) const; -protected: - - int m_Width; - int m_Height; + protected: + int m_Width; + int m_Height; cItem * m_Items; -} ; // tolua_export +}; // tolua_export @@ -59,30 +59,24 @@ protected: class cCraftingRecipe // tolua_export { // tolua_export -public: + public: cCraftingRecipe(const cCraftingGrid & a_CraftingGrid); // tolua_begin - void Clear (void); - int GetIngredientsWidth (void) const {return m_Ingredients.GetWidth(); } - int GetIngredientsHeight(void) const {return m_Ingredients.GetHeight(); } - cItem & GetIngredient (int x, int y) const {return m_Ingredients.GetItem(x, y); } - const cItem & GetResult (void) const {return m_Result; } - void SetResult (ENUM_ITEM_TYPE a_ItemType, char a_ItemCount, short a_ItemHealth); - void SetResult (const cItem & a_Item) - { - m_Result = a_Item; - } - - void SetIngredient (int x, int y, ENUM_ITEM_TYPE a_ItemType, char a_ItemCount, short a_ItemHealth) + void Clear(void); + int GetIngredientsWidth(void) const { return m_Ingredients.GetWidth(); } + int GetIngredientsHeight(void) const { return m_Ingredients.GetHeight(); } + cItem & GetIngredient(int x, int y) const { return m_Ingredients.GetItem(x, y); } + const cItem & GetResult(void) const { return m_Result; } + void SetResult(ENUM_ITEM_TYPE a_ItemType, char a_ItemCount, short a_ItemHealth); + void SetResult(const cItem & a_Item) { m_Result = a_Item; } + + void SetIngredient(int x, int y, ENUM_ITEM_TYPE a_ItemType, char a_ItemCount, short a_ItemHealth) { m_Ingredients.SetItem(x, y, a_ItemType, a_ItemCount, a_ItemHealth); } - void SetIngredient (int x, int y, const cItem & a_Item) - { - m_Ingredients.SetItem(x, y, a_Item); - } + void SetIngredient(int x, int y, const cItem & a_Item) { m_Ingredients.SetItem(x, y, a_Item); } /** Consumes ingredients from the crafting grid specified */ void ConsumeIngredients(cCraftingGrid & a_CraftingGrid); @@ -91,11 +85,10 @@ public: void Dump(void); // tolua_end -protected: - + protected: cCraftingGrid m_Ingredients; // Adjusted to correspond to the input crafting grid! - cItem m_Result; -} ; // tolua_export + cItem m_Result; +}; // tolua_export @@ -116,8 +109,8 @@ To handle the crafting recipes internally efficient the vector index of the */ class cCraftingRecipes { -public: - static const int MAX_GRID_WIDTH = 3; + public: + static const int MAX_GRID_WIDTH = 3; static const int MAX_GRID_HEIGHT = 3; cCraftingRecipes(void); @@ -127,13 +120,16 @@ public: void GetRecipe(cPlayer & a_Player, cCraftingGrid & a_CraftingGrid, cCraftingRecipe & a_Recipe); /** 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); + std::vector<UInt32> FindNewRecipesForItem( + const cItem & a_Item, + const std::set<cItem, cItem::sItemCompare> & a_KnownItems + ); 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()) @@ -141,13 +137,13 @@ public: struct cRecipe { cRecipeSlots m_Ingredients; - cItem m_Result; - AString m_RecipeName; + 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); @@ -155,8 +151,7 @@ public: /** Gets a map of all recipes with name and recipe id */ const std::map<AString, UInt32> & GetRecipeNameMap(); -protected: - + protected: typedef std::vector<cRecipe *> cRecipes; cRecipes m_Recipes; @@ -176,22 +171,45 @@ protected: /** 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 nullptr if not found. Caller must delete return value! */ + /** Finds a recipe matching the crafting grid. Returns a newly allocated recipe (with all its coords set) or nullptr + * 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 nullptr 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); + /** Checks if the grid matches the specified recipe, offset by the specified offsets. Returns a matched cRecipe * if + * so, or nullptr 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 + ); /** Searches for anything firework related, and does the data setting if appropriate */ - void HandleFireworks(const cItem * a_CraftingGrid, cCraftingRecipes::cRecipe * a_Recipe, int a_GridStride, int a_OffsetX, int a_OffsetY); + void HandleFireworks( + const cItem * a_CraftingGrid, + cCraftingRecipes::cRecipe * a_Recipe, + int a_GridStride, + int a_OffsetX, + int a_OffsetY + ); - /** 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); + /** 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: + private: /** Mapping the minecraft recipe names to the internal cuberite recipe Ids */ std::map<AString, UInt32> m_RecipeNameMap; @@ -208,4 +226,4 @@ private: /** Populates the RecipeNameMap */ void PopulateRecipeNameMap(void); -} ; +}; |