51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
*/
-#ifndef CRAFTDEF_HEADER
-#define CRAFTDEF_HEADER
+#pragma once
#include <string>
#include <iostream>
*/
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() = default;
+
CraftInput(CraftMethod method_, unsigned int width_,
const std::vector<ItemStack> &items_):
method(method_), width(width_), items(items_)
{}
+
std::string dump() const;
};
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() = default;
+
+ CraftOutput(const std::string &item_, float time_):
item(item_), time(time_)
{}
std::string dump() const;
// List of replacements
std::vector<std::pair<std::string, std::string> > pairs;
- CraftReplacements():
- pairs()
- {}
- CraftReplacements(std::vector<std::pair<std::string, std::string> > pairs_):
+ CraftReplacements() = default;
+ CraftReplacements(const std::vector<std::pair<std::string, std::string> > &pairs_):
pairs(pairs_)
{}
std::string dump() const;
class CraftDefinition
{
public:
- CraftDefinition(){}
- virtual ~CraftDefinition(){}
+ CraftDefinition() = default;
+ virtual ~CraftDefinition() = default;
// Returns type of crafting definition
virtual std::string getName() const=0;
class CraftDefinitionShaped: public CraftDefinition
{
public:
- CraftDefinitionShaped():
- output(""), width(1), recipe(), hash_inited(false), replacements()
- {}
+ CraftDefinitionShaped() = delete;
+
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(){}
+ virtual ~CraftDefinitionShaped() = default;
virtual std::string getName() const;
virtual bool check(const CraftInput &input, IGameDef *gamedef) const;
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;
};
class CraftDefinitionShapeless: public CraftDefinition
{
public:
- CraftDefinitionShapeless():
- output(""), recipe(), hash_inited(false), replacements()
- {}
+ CraftDefinitionShapeless() = delete;
CraftDefinitionShapeless(
const std::string &output_,
const std::vector<std::string> &recipe_,
const CraftReplacements &replacements_):
- output(output_), recipe(recipe_),
- hash_inited(false), replacements(replacements_)
+ output(output_), recipe(recipe_), replacements(replacements_)
{}
- virtual ~CraftDefinitionShapeless(){}
+ virtual ~CraftDefinitionShapeless() = default;
virtual std::string getName() const;
virtual bool check(const CraftInput &input, IGameDef *gamedef) const;
// Recipe list (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;
};
class CraftDefinitionToolRepair: public CraftDefinition
{
public:
- CraftDefinitionToolRepair():
- additional_wear(0)
- {}
+ CraftDefinitionToolRepair() = delete;
CraftDefinitionToolRepair(float additional_wear_):
additional_wear(additional_wear_)
{}
- virtual ~CraftDefinitionToolRepair(){}
+ virtual ~CraftDefinitionToolRepair() = default;
virtual std::string getName() const;
virtual bool check(const CraftInput &input, IGameDef *gamedef) const;
// 1 = new tool is completely broken
// 0 = simply add remaining uses of both input tools
// -1 = new tool is completely pristine
- float additional_wear;
+ float additional_wear = 0.0f;
};
/*
class CraftDefinitionCooking: public CraftDefinition
{
public:
- CraftDefinitionCooking():
- output(""), recipe(""), hash_inited(false), cooktime()
- {}
+ CraftDefinitionCooking() = delete;
CraftDefinitionCooking(
const std::string &output_,
const std::string &recipe_,
float cooktime_,
const CraftReplacements &replacements_):
- output(output_), recipe(recipe_), hash_inited(false),
- cooktime(cooktime_), replacements(replacements_)
+ output(output_), recipe(recipe_), cooktime(cooktime_), replacements(replacements_)
{}
- virtual ~CraftDefinitionCooking(){}
+ virtual ~CraftDefinitionCooking() = default;
virtual std::string getName() const;
virtual bool check(const CraftInput &input, IGameDef *gamedef) const;
// Recipe item name
std::string recipe_name;
// bool indicating if initHash has been called already
- bool hash_inited;
+ bool hash_inited = false;
// Time in seconds
float cooktime;
// Replacement items for decrementInput()
class CraftDefinitionFuel: public CraftDefinition
{
public:
- CraftDefinitionFuel():
- recipe(""), hash_inited(false), burntime()
- {}
- CraftDefinitionFuel(std::string recipe_,
+ CraftDefinitionFuel() = delete;
+ CraftDefinitionFuel(const std::string &recipe_,
float burntime_,
const CraftReplacements &replacements_):
- recipe(recipe_), hash_inited(false), burntime(burntime_), replacements(replacements_)
+ recipe(recipe_), burntime(burntime_), replacements(replacements_)
{}
- virtual ~CraftDefinitionFuel(){}
+ virtual ~CraftDefinitionFuel() = default;
virtual std::string getName() const;
virtual bool check(const CraftInput &input, IGameDef *gamedef) const;
// Recipe item name
std::string recipe_name;
// bool indicating if initHash has been called already
- bool hash_inited;
+ bool hash_inited = false;
// Time in seconds
float burntime;
// Replacement items for decrementInput()
class ICraftDefManager
{
public:
- ICraftDefManager(){}
- virtual ~ICraftDefManager(){}
+ ICraftDefManager() = default;
+ virtual ~ICraftDefManager() = default;
// The main crafting function
virtual bool getCraftResult(CraftInput &input, CraftOutput &output,
class IWritableCraftDefManager : public ICraftDefManager
{
public:
- IWritableCraftDefManager(){}
- virtual ~IWritableCraftDefManager(){}
+ IWritableCraftDefManager() = default;
+ virtual ~IWritableCraftDefManager() = default;
// The main crafting function
virtual bool getCraftResult(CraftInput &input, CraftOutput &output,
};
IWritableCraftDefManager* createCraftDefManager();
-
-#endif
-