aboutsummaryrefslogtreecommitdiff
path: root/src/craftdef.h
diff options
context:
space:
mode:
Diffstat (limited to 'src/craftdef.h')
-rw-r--r--src/craftdef.h139
1 files changed, 72 insertions, 67 deletions
diff --git a/src/craftdef.h b/src/craftdef.h
index dcadabe78..7c14e702a 100644
--- a/src/craftdef.h
+++ b/src/craftdef.h
@@ -57,13 +57,12 @@ enum CraftHashType
// Counts the non-empty slots.
CRAFT_HASH_TYPE_COUNT,
- // This layer both spares an extra variable, and helps to retain (albeit rarely
- // used) functionality. Maps to 0. Before hashes are "initialized", all hashes
- // reside here, after initialisation, none are.
+ // This layer both spares an extra variable, and helps to retain (albeit rarely used) functionality. Maps to 0.
+ // Before hashes are "initialized", all hashes reside here, after initialisation, none are.
CRAFT_HASH_TYPE_UNHASHED
};
-const int craft_hash_type_max = (int)CRAFT_HASH_TYPE_UNHASHED;
+const int craft_hash_type_max = (int) CRAFT_HASH_TYPE_UNHASHED;
/*
Input: The contents of the crafting slots, arranged in matrix form
@@ -77,11 +76,9 @@ struct CraftInput
CraftInput() = default;
CraftInput(CraftMethod method_, unsigned int width_,
- const std::vector<ItemStack> &items_) :
- method(method_),
- width(width_), items(items_)
- {
- }
+ const std::vector<ItemStack> &items_):
+ method(method_), width(width_), items(items_)
+ {}
// Returns true if all items are empty.
bool empty() const;
@@ -101,7 +98,9 @@ struct CraftOutput
CraftOutput() = default;
- CraftOutput(const std::string &item_, float time_) : item(item_), time(time_) {}
+ CraftOutput(const std::string &item_, float time_):
+ item(item_), time(time_)
+ {}
std::string dump() const;
};
@@ -118,14 +117,12 @@ struct CraftOutput
struct CraftReplacements
{
// List of replacements
- std::vector<std::pair<std::string, std::string>> pairs;
+ std::vector<std::pair<std::string, std::string> > pairs;
CraftReplacements() = default;
- CraftReplacements(
- const std::vector<std::pair<std::string, std::string>> &pairs_) :
- pairs(pairs_)
- {
- }
+ CraftReplacements(const std::vector<std::pair<std::string, std::string> > &pairs_):
+ pairs(pairs_)
+ {}
std::string dump() const;
};
@@ -156,30 +153,33 @@ public:
virtual ~CraftDefinition() = default;
// Returns type of crafting definition
- virtual std::string getName() const = 0;
+ virtual std::string getName() const=0;
// Checks whether the recipe is applicable
- virtual bool check(const CraftInput &input, IGameDef *gamedef) const = 0;
- RecipePriority getPriority() const { return priority; }
+ virtual bool check(const CraftInput &input, IGameDef *gamedef) const=0;
+ RecipePriority getPriority() const
+ {
+ return priority;
+ }
// Returns the output structure, meaning depends on crafting method
// The implementation can assume that check(input) returns true
- virtual CraftOutput getOutput(
- const CraftInput &input, IGameDef *gamedef) const = 0;
+ virtual CraftOutput getOutput(const CraftInput &input, IGameDef *gamedef) const=0;
// the inverse of the above
- virtual CraftInput getInput(
- const CraftOutput &output, IGameDef *gamedef) const = 0;
+ virtual CraftInput getInput(const CraftOutput &output, IGameDef *gamedef) const=0;
// Decreases count of every input item
virtual void decrementInput(CraftInput &input,
- std::vector<ItemStack> &output_replacements,
- IGameDef *gamedef) const = 0;
+ std::vector<ItemStack> &output_replacements, IGameDef *gamedef) const=0;
- CraftHashType getHashType() const { return hash_type; }
+ CraftHashType getHashType() const
+ {
+ return hash_type;
+ }
virtual u64 getHash(CraftHashType type) const = 0;
// to be called after all mods are loaded, so that we catch all aliases
virtual void initHash(IGameDef *gamedef) = 0;
- virtual std::string dump() const = 0;
+ virtual std::string dump() const=0;
protected:
CraftHashType hash_type;
@@ -192,13 +192,15 @@ protected:
Supported crafting method: CRAFT_METHOD_NORMAL.
Requires the input items to be arranged exactly like in the recipe.
*/
-class CraftDefinitionShaped : public CraftDefinition
+class CraftDefinitionShaped: public CraftDefinition
{
public:
CraftDefinitionShaped() = delete;
- CraftDefinitionShaped(const std::string &output_, unsigned int width_,
- const std::vector<std::string> &recipe_,
- const CraftReplacements &replacements_);
+ CraftDefinitionShaped(
+ const std::string &output_,
+ unsigned int width_,
+ const std::vector<std::string> &recipe_,
+ const CraftReplacements &replacements_);
virtual ~CraftDefinitionShaped() = default;
@@ -207,8 +209,7 @@ public:
virtual CraftOutput getOutput(const CraftInput &input, IGameDef *gamedef) const;
virtual CraftInput getInput(const CraftOutput &output, IGameDef *gamedef) const;
virtual void decrementInput(CraftInput &input,
- std::vector<ItemStack> &output_replacements,
- IGameDef *gamedef) const;
+ std::vector<ItemStack> &output_replacements, IGameDef *gamedef) const;
virtual u64 getHash(CraftHashType type) const;
@@ -236,13 +237,14 @@ private:
Supported crafting method: CRAFT_METHOD_NORMAL.
Input items can arranged in any way.
*/
-class CraftDefinitionShapeless : public CraftDefinition
+class CraftDefinitionShapeless: public CraftDefinition
{
public:
CraftDefinitionShapeless() = delete;
- CraftDefinitionShapeless(const std::string &output_,
- const std::vector<std::string> &recipe_,
- const CraftReplacements &replacements_);
+ CraftDefinitionShapeless(
+ const std::string &output_,
+ const std::vector<std::string> &recipe_,
+ const CraftReplacements &replacements_);
virtual ~CraftDefinitionShapeless() = default;
@@ -251,8 +253,7 @@ public:
virtual CraftOutput getOutput(const CraftInput &input, IGameDef *gamedef) const;
virtual CraftInput getInput(const CraftOutput &output, IGameDef *gamedef) const;
virtual void decrementInput(CraftInput &input,
- std::vector<ItemStack> &output_replacements,
- IGameDef *gamedef) const;
+ std::vector<ItemStack> &output_replacements, IGameDef *gamedef) const;
virtual u64 getHash(CraftHashType type) const;
@@ -279,7 +280,7 @@ private:
Put two damaged tools into the crafting grid, get one tool back.
There should only be one crafting definition of this type.
*/
-class CraftDefinitionToolRepair : public CraftDefinition
+class CraftDefinitionToolRepair: public CraftDefinition
{
public:
CraftDefinitionToolRepair() = delete;
@@ -292,12 +293,14 @@ public:
virtual CraftOutput getOutput(const CraftInput &input, IGameDef *gamedef) const;
virtual CraftInput getInput(const CraftOutput &output, IGameDef *gamedef) const;
virtual void decrementInput(CraftInput &input,
- std::vector<ItemStack> &output_replacements,
- IGameDef *gamedef) const;
+ std::vector<ItemStack> &output_replacements, IGameDef *gamedef) const;
virtual u64 getHash(CraftHashType type) const { return 2; }
- virtual void initHash(IGameDef *gamedef) { hash_type = CRAFT_HASH_TYPE_COUNT; }
+ virtual void initHash(IGameDef *gamedef)
+ {
+ hash_type = CRAFT_HASH_TYPE_COUNT;
+ }
virtual std::string dump() const;
@@ -314,12 +317,15 @@ private:
A cooking (in furnace) definition
Supported crafting method: CRAFT_METHOD_COOKING.
*/
-class CraftDefinitionCooking : public CraftDefinition
+class CraftDefinitionCooking: public CraftDefinition
{
public:
CraftDefinitionCooking() = delete;
- CraftDefinitionCooking(const std::string &output_, const std::string &recipe_,
- float cooktime_, const CraftReplacements &replacements_);
+ CraftDefinitionCooking(
+ const std::string &output_,
+ const std::string &recipe_,
+ float cooktime_,
+ const CraftReplacements &replacements_);
virtual ~CraftDefinitionCooking() = default;
@@ -328,8 +334,7 @@ public:
virtual CraftOutput getOutput(const CraftInput &input, IGameDef *gamedef) const;
virtual CraftInput getInput(const CraftOutput &output, IGameDef *gamedef) const;
virtual void decrementInput(CraftInput &input,
- std::vector<ItemStack> &output_replacements,
- IGameDef *gamedef) const;
+ std::vector<ItemStack> &output_replacements, IGameDef *gamedef) const;
virtual u64 getHash(CraftHashType type) const;
@@ -356,12 +361,14 @@ private:
A fuel (for furnace) definition
Supported crafting method: CRAFT_METHOD_FUEL.
*/
-class CraftDefinitionFuel : public CraftDefinition
+class CraftDefinitionFuel: public CraftDefinition
{
public:
CraftDefinitionFuel() = delete;
- CraftDefinitionFuel(const std::string &recipe_, float burntime_,
- const CraftReplacements &replacements_);
+ CraftDefinitionFuel(
+ const std::string &recipe_,
+ float burntime_,
+ const CraftReplacements &replacements_);
virtual ~CraftDefinitionFuel() = default;
@@ -370,8 +377,7 @@ public:
virtual CraftOutput getOutput(const CraftInput &input, IGameDef *gamedef) const;
virtual CraftInput getInput(const CraftOutput &output, IGameDef *gamedef) const;
virtual void decrementInput(CraftInput &input,
- std::vector<ItemStack> &output_replacements,
- IGameDef *gamedef) const;
+ std::vector<ItemStack> &output_replacements, IGameDef *gamedef) const;
virtual u64 getHash(CraftHashType type) const;
@@ -414,14 +420,14 @@ public:
* @return true if a result was found, otherwise false.
*/
virtual bool getCraftResult(CraftInput &input, CraftOutput &output,
- std::vector<ItemStack> &output_replacements, bool decrementInput,
- IGameDef *gamedef) const = 0;
+ 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 std::vector<CraftDefinition*> getCraftRecipes(CraftOutput &output,
+ IGameDef *gamedef, unsigned limit=0) const=0;
// Print crafting recipes for debugging
- virtual std::string dump() const = 0;
+ virtual std::string dump() const=0;
};
class IWritableCraftDefManager : public ICraftDefManager
@@ -432,27 +438,26 @@ 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;
+ 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 clearCraftsByOutput(
- const CraftOutput &output, IGameDef *gamedef) = 0;
+ virtual bool clearCraftsByOutput(const CraftOutput &output, IGameDef *gamedef) = 0;
virtual bool clearCraftsByInput(const CraftInput &input, IGameDef *gamedef) = 0;
// Print crafting recipes for debugging
- virtual std::string dump() const = 0;
+ virtual std::string dump() const=0;
// Add a crafting definition.
// After calling this, the pointer belongs to the manager.
virtual void registerCraft(CraftDefinition *def, IGameDef *gamedef) = 0;
// Delete all crafting definitions
- virtual void clear() = 0;
+ virtual void clear()=0;
// To be called after all mods are loaded, so that we catch all aliases
virtual void initHashes(IGameDef *gamedef) = 0;
};
-IWritableCraftDefManager *createCraftDefManager();
+IWritableCraftDefManager* createCraftDefManager();