LocalPlayer::accelerateHorizontal: cleanups
[oweals/minetest.git] / src / craftdef.h
index f62ad3313b7a50504a3c38864aedc76f0cbfecd5..fddff6cef8c5e240e8a1e1c7eba5e26bb21e3c44 100644 (file)
@@ -70,17 +70,17 @@ const int craft_hash_type_max = (int) CRAFT_HASH_TYPE_UNHASHED;
 */
 struct CraftInput
 {
-       CraftMethod method;
-       unsigned int width;
+       CraftMethod method = CRAFT_METHOD_NORMAL;
+       unsigned int width = 0;
        std::vector<ItemStack> items;
 
-       CraftInput():
-               method(CRAFT_METHOD_NORMAL), width(0), items()
-       {}
+       CraftInput() {}
+
        CraftInput(CraftMethod method_, unsigned int width_,
                        const std::vector<ItemStack> &items_):
                method(method_), width(width_), items(items_)
        {}
+
        std::string dump() const;
 };
 
@@ -90,14 +90,13 @@ struct CraftInput
 struct CraftOutput
 {
        // Used for normal crafting and cooking, itemstring
-       std::string item;
+       std::string item = "";
        // Used for cooking (cook time) and fuel (burn time), seconds
-       float time;
+       float time = 0.0f;
 
-       CraftOutput():
-               item(""), time(0)
-       {}
-       CraftOutput(std::string item_, float time_):
+       CraftOutput() {}
+
+       CraftOutput(const std::string &item_, float time_):
                item(item_), time(time_)
        {}
        std::string dump() const;
@@ -124,7 +123,7 @@ struct CraftReplacements
        CraftReplacements():
                pairs()
        {}
-       CraftReplacements(std::vector<std::pair<std::string, std::string> > pairs_):
+       CraftReplacements(const std::vector<std::pair<std::string, std::string> > &pairs_):
                pairs(pairs_)
        {}
        std::string dump() const;
@@ -150,7 +149,8 @@ public:
        // the inverse of the above
        virtual CraftInput getInput(const CraftOutput &output, IGameDef *gamedef) const=0;
        // Decreases count of every input item
-       virtual void decrementInput(CraftInput &input, IGameDef *gamedef) const=0;
+       virtual void decrementInput(CraftInput &input,
+               std::vector<ItemStack> &output_replacements, IGameDef *gamedef) const=0;
 
        virtual CraftHashType getHashType() const = 0;
        virtual u64 getHash(CraftHashType type) const = 0;
@@ -170,16 +170,15 @@ public:
 class CraftDefinitionShaped: public CraftDefinition
 {
 public:
-       CraftDefinitionShaped():
-               output(""), width(1), recipe(), hash_inited(false), replacements()
-       {}
+       CraftDefinitionShaped() {}
+
        CraftDefinitionShaped(
                        const std::string &output_,
                        unsigned int width_,
                        const std::vector<std::string> &recipe_,
                        const CraftReplacements &replacements_):
                output(output_), width(width_), recipe(recipe_),
-               hash_inited(false), replacements(replacements_)
+               replacements(replacements_)
        {}
        virtual ~CraftDefinitionShaped(){}
 
@@ -187,7 +186,8 @@ public:
        virtual bool check(const CraftInput &input, IGameDef *gamedef) const;
        virtual CraftOutput getOutput(const CraftInput &input, IGameDef *gamedef) const;
        virtual CraftInput getInput(const CraftOutput &output, IGameDef *gamedef) const;
-       virtual void decrementInput(CraftInput &input, IGameDef *gamedef) const;
+       virtual void decrementInput(CraftInput &input,
+               std::vector<ItemStack> &output_replacements, IGameDef *gamedef) const;
 
        virtual CraftHashType getHashType() const;
        virtual u64 getHash(CraftHashType type) const;
@@ -198,15 +198,15 @@ public:
 
 private:
        // Output itemstring
-       std::string output;
+       std::string output = "";
        // Width of recipe
-       unsigned int width;
+       unsigned int width = 1;
        // Recipe matrix (itemstrings)
        std::vector<std::string> recipe;
        // Recipe matrix (item names)
        std::vector<std::string> recipe_names;
        // bool indicating if initHash has been called already
-       bool hash_inited;
+       bool hash_inited = false;
        // Replacement items for decrementInput()
        CraftReplacements replacements;
 };
@@ -235,7 +235,8 @@ public:
        virtual bool check(const CraftInput &input, IGameDef *gamedef) const;
        virtual CraftOutput getOutput(const CraftInput &input, IGameDef *gamedef) const;
        virtual CraftInput getInput(const CraftOutput &output, IGameDef *gamedef) const;
-       virtual void decrementInput(CraftInput &input, IGameDef *gamedef) const;
+       virtual void decrementInput(CraftInput &input,
+               std::vector<ItemStack> &output_replacements, IGameDef *gamedef) const;
 
        virtual CraftHashType getHashType() const;
        virtual u64 getHash(CraftHashType type) const;
@@ -278,7 +279,8 @@ public:
        virtual bool check(const CraftInput &input, IGameDef *gamedef) const;
        virtual CraftOutput getOutput(const CraftInput &input, IGameDef *gamedef) const;
        virtual CraftInput getInput(const CraftOutput &output, IGameDef *gamedef) const;
-       virtual void decrementInput(CraftInput &input, IGameDef *gamedef) const;
+       virtual void decrementInput(CraftInput &input,
+               std::vector<ItemStack> &output_replacements, IGameDef *gamedef) const;
 
        virtual CraftHashType getHashType() const { return CRAFT_HASH_TYPE_COUNT; }
        virtual u64 getHash(CraftHashType type) const { return 2; }
@@ -320,7 +322,8 @@ public:
        virtual bool check(const CraftInput &input, IGameDef *gamedef) const;
        virtual CraftOutput getOutput(const CraftInput &input, IGameDef *gamedef) const;
        virtual CraftInput getInput(const CraftOutput &output, IGameDef *gamedef) const;
-       virtual void decrementInput(CraftInput &input, IGameDef *gamedef) const;
+       virtual void decrementInput(CraftInput &input,
+               std::vector<ItemStack> &output_replacements, IGameDef *gamedef) const;
 
        virtual CraftHashType getHashType() const;
        virtual u64 getHash(CraftHashType type) const;
@@ -354,10 +357,13 @@ public:
        CraftDefinitionFuel():
                recipe(""), hash_inited(false), burntime()
        {}
-       CraftDefinitionFuel(std::string recipe_,
+       CraftDefinitionFuel(const std::string &recipe_,
                        float burntime_,
                        const CraftReplacements &replacements_):
-               recipe(recipe_), hash_inited(false), burntime(burntime_), replacements(replacements_)
+               recipe(recipe_),
+               hash_inited(false),
+               burntime(burntime_),
+               replacements(replacements_)
        {}
        virtual ~CraftDefinitionFuel(){}
 
@@ -365,7 +371,8 @@ public:
        virtual bool check(const CraftInput &input, IGameDef *gamedef) const;
        virtual CraftOutput getOutput(const CraftInput &input, IGameDef *gamedef) const;
        virtual CraftInput getInput(const CraftOutput &output, IGameDef *gamedef) const;
-       virtual void decrementInput(CraftInput &input, IGameDef *gamedef) const;
+       virtual void decrementInput(CraftInput &input,
+               std::vector<ItemStack> &output_replacements, IGameDef *gamedef) const;
 
        virtual CraftHashType getHashType() const;
        virtual u64 getHash(CraftHashType type) const;
@@ -398,6 +405,7 @@ public:
 
        // The main crafting function
        virtual bool getCraftResult(CraftInput &input, CraftOutput &output,
+                       std::vector<ItemStack> &output_replacements,
                        bool decrementInput, IGameDef *gamedef) const=0;
        virtual std::vector<CraftDefinition*> getCraftRecipes(CraftOutput &output,
                        IGameDef *gamedef, unsigned limit=0) const=0;
@@ -414,10 +422,15 @@ public:
 
        // The main crafting function
        virtual bool getCraftResult(CraftInput &input, CraftOutput &output,
+                       std::vector<ItemStack> &output_replacements,
                        bool decrementInput, IGameDef *gamedef) const=0;
        virtual std::vector<CraftDefinition*> getCraftRecipes(CraftOutput &output,
                        IGameDef *gamedef, unsigned limit=0) const=0;
 
+       virtual bool clearCraftRecipesByOutput(const CraftOutput &output, IGameDef *gamedef) = 0;
+       virtual bool clearCraftRecipesByInput(CraftMethod craft_method,
+                       unsigned int craft_grid_width, const std::vector<std::string> &recipe, IGameDef *gamedef) = 0;
+
        // Print crafting recipes for debugging
        virtual std::string dump() const=0;