8 #define BREWING_RECIPE_FILE "brewing.txt"
26 LOGD(
"Loading brewing recipes...");
31 LOG(
"Could not open the brewing recipes file \"%s\". No brewing recipes are available.",
BREWING_RECIPE_FILE);
35 unsigned int LineNum = 0;
38 while (std::getline(f, ParsingLine))
42 size_t FirstCommentSymbol = ParsingLine.find(
'#');
43 if (FirstCommentSymbol != AString::npos)
45 ParsingLine.erase(FirstCommentSymbol);
65 a_Line.erase(std::remove_if(a_Line.begin(), a_Line.end(), isspace), a_Line.end());
67 auto Recipe = std::make_unique<cRecipe>();
71 if (InputAndIngredient.size() != 2)
73 LOGWARNING(
"brewing.txt: line %d: A line with '+' was expected", a_LineNum);
74 LOGINFO(
"Offending line: \"%s\"", a_Line.c_str());
79 if (IngredientAndOutput.size() != 2)
81 LOGWARNING(
"brewing.txt: line %d: A line with '=' was expected", a_LineNum);
82 LOGINFO(
"Offending line: \"%s\"", a_Line.c_str());
86 if (!
ParseItem(IngredientAndOutput[0], Recipe->Ingredient))
88 LOGWARNING(
"brewing.txt: Parsing of the item didn't worked.");
89 LOGINFO(
"Offending line: \"%s\"", a_Line.c_str());
93 if (!StringToInteger<short>(InputAndIngredient[0], Recipe->Input.m_ItemDamage))
95 LOGWARNING(
"brewing.txt: line %d: Cannot parse the damage value for the input item\"%s\".", a_LineNum, InputAndIngredient[0].c_str());
96 LOGINFO(
"Offending line: \"%s\"", a_Line.c_str());
100 if (!StringToInteger<short>(IngredientAndOutput[1], Recipe->Output.m_ItemDamage))
102 LOGWARNING(
"brewing.txt: line %d: Cannot parse the damage value for the output item\"%s\".", a_LineNum, IngredientAndOutput[1].c_str());
103 LOGINFO(
"Offending line: \"%s\"", a_Line.c_str());
136 if ((Recipe->Input.IsEqual(a_Input)) && (Recipe->Ingredient.IsEqual(a_Ingredient)))
148 auto Recipe = std::make_unique<cRecipe>();
151 Recipe->Output.m_ItemDamage = a_Input.
m_ItemDamage + 8192;
154 auto RecipePtr = Recipe.get();
167 auto FoundRecipe = std::find_if(
m_Recipes.cbegin(),
m_Recipes.cend(), [&](
const std::unique_ptr<cRecipe>& a_Recipe)
170 (a_Recipe->Input.m_ItemDamage == SplashItemDamage) &&
171 (a_Recipe->Ingredient.IsEqual(a_Ingredient))
181 auto Recipe = std::make_unique<cRecipe>();
184 Recipe->Output.m_ItemDamage = (*FoundRecipe)->Output.m_ItemDamage + 8192;
185 Recipe->Ingredient.m_ItemType = (*FoundRecipe)->Ingredient.m_ItemType;
187 auto RecipePtr = Recipe.get();
208 if (Recipe->Ingredient.IsEqual(a_Ingredient))
bool StringToItem(const AString &a_ItemTypeString, cItem &a_Item)
Translates an itemtype string into an item.
#define BREWING_RECIPE_FILE
void LOGWARNING(std::string_view a_Format, const Args &... args)
void LOG(std::string_view a_Format, const Args &... args)
void LOGINFO(std::string_view a_Format, const Args &... args)
AStringVector StringSplit(const AString &str, const AString &delim)
Split the string at any of the listed delimiters.
bool IsOnlyWhitespace(const AString &a_String)
Returns true if only whitespace characters are present in the string.
std::vector< AString > AStringVector
bool ParseItem(const AString &a_String, cItem &a_Item)
Parses an item string, returns true if successful.
const cRecipe * GetRecipeFrom(const cItem &a_Input, const cItem &a_Ingredient) const
Returns a recipe for the specified input, nullptr if no recipe found.
cRecipes m_Recipes
The collection of parsed recipes.
bool IsIngredient(const cItem &a_Ingredient) const
Returns true if the item is a ingredient, false if not.
void AddRecipeFromLine(AString a_Line, unsigned int a_LineNum)
Parses the recipe contained in the line, adds it to m_pState's recipes.
bool IsBottle(const cItem &a_Item) const
Returns true if the item is a bottle / potion, false if not.
bool IsFuel(const cItem &a_Item) const
Returns true if the item is the fuel, false if not.