aboutsummaryrefslogtreecommitdiff
path: root/src/craftdef.h
diff options
context:
space:
mode:
authorElias Fleckenstein <54945686+EliasFleckenstein03@users.noreply.github.com>2020-11-04 16:44:42 +0100
committerGitHub <noreply@github.com>2020-11-04 16:44:42 +0100
commit5d9ae5a91c544fc7fbd475decf47cef7e09ef8fc (patch)
treec980d614fec4a5495798be3e79e033229062c3cd /src/craftdef.h
parent28f6a79706b088c37268a59d90878220dc4ef9c7 (diff)
parent3af10766fd2b58b068e970266724d7eb10e9316b (diff)
downloaddragonfireclient-5d9ae5a91c544fc7fbd475decf47cef7e09ef8fc.tar.xz
Merge branch 'master' into master
Diffstat (limited to 'src/craftdef.h')
-rw-r--r--src/craftdef.h139
1 files changed, 67 insertions, 72 deletions
diff --git a/src/craftdef.h b/src/craftdef.h
index 7c14e702a..dcadabe78 100644
--- a/src/craftdef.h
+++ b/src/craftdef.h
@@ -57,12 +57,13 @@ 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
@@ -76,9 +77,11 @@ 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;
@@ -98,9 +101,7 @@ 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;
};
@@ -117,12 +118,14 @@ 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;
};
@@ -153,33 +156,30 @@ 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,15 +192,13 @@ 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;
@@ -209,7 +207,8 @@ 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;
@@ -237,14 +236,13 @@ 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;
@@ -253,7 +251,8 @@ 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;
@@ -280,7 +279,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;
@@ -293,14 +292,12 @@ 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;
@@ -317,15 +314,12 @@ 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;
@@ -334,7 +328,8 @@ 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;
@@ -361,14 +356,12 @@ 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;
@@ -377,7 +370,8 @@ 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;
@@ -420,14 +414,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
@@ -438,26 +432,27 @@ 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();