9 #define FURNACE_RECIPE_FILE "furnace.txt"
16 typedef std::list<cFurnaceRecipe::cFuel>
FuelList;
56 LOGD(
"Loading furnace recipes...");
61 LOG(
"Could not open the furnace recipes file \"%s\". No furnace recipes are available.",
FURNACE_RECIPE_FILE);
65 unsigned int LineNum = 0;
68 while (std::getline(f, ParsingLine))
73 size_t FirstCommentSymbol = ParsingLine.find(
'#');
74 if ((FirstCommentSymbol != AString::npos) && (FirstCommentSymbol != 0))
76 ParsingLine.erase(ParsingLine.begin() +
static_cast<long>(FirstCommentSymbol), ParsingLine.end());
85 switch (ParsingLine[0])
117 Line.erase(Line.begin());
118 Line.erase(std::remove_if(Line.begin(), Line.end(), isspace), Line.end());
120 std::unique_ptr<cItem>
Item = std::make_unique<cItem>();
124 if (Sides.size() != 2)
126 LOGWARNING(
"furnace.txt: line %d: A single '=' was expected, got %zu", a_LineNum, Sides.size() - 1);
127 LOGINFO(
"Offending line: \"%s\"", a_Line.c_str());
133 LOGWARNING(
"furnace.txt: line %d: Cannot parse item \"%s\".", a_LineNum, Sides[0].c_str());
134 LOGINFO(
"Offending line: \"%s\"", a_Line.c_str());
138 if (!StringToInteger<int>(Sides[1], BurnTime))
140 LOGWARNING(
"furnace.txt: line %d: Cannot parse burn time.", a_LineNum);
141 LOGINFO(
"Offending line: \"%s\"", a_Line.c_str());
159 Line.erase(std::remove_if(Line.begin(), Line.end(), isspace), Line.end());
163 std::unique_ptr<cItem> InputItem = std::make_unique<cItem>();
164 std::unique_ptr<cItem> OutputItem = std::make_unique<cItem>();
167 if (Sides.size() != 2)
169 LOGWARNING(
"furnace.txt: line %d: A single '=' was expected, got %zu", a_LineNum, Sides.size() - 1);
170 LOGINFO(
"Offending line: \"%s\"", a_Line.c_str());
175 if (!
ParseItem(InputSplit[0], *InputItem))
177 LOGWARNING(
"furnace.txt: line %d: Cannot parse input item \"%s\".", a_LineNum, InputSplit[0].c_str());
178 LOGINFO(
"Offending line: \"%s\"", a_Line.c_str());
182 if (InputSplit.size() > 1)
184 if (!StringToInteger<int>(InputSplit[1], CookTime))
186 LOGWARNING(
"furnace.txt: line %d: Cannot parse cook time \"%s\".", a_LineNum, InputSplit[1].c_str());
187 LOGINFO(
"Offending line: \"%s\"", a_Line.c_str());
192 if (!
ParseItem(OutputSplit[0], *OutputItem))
194 LOGWARNING(
"furnace.txt: line %d: Cannot parse output item \"%s\".", a_LineNum, OutputSplit[0].c_str());
195 LOGINFO(
"Offending line: \"%s\"", a_Line.c_str());
198 if (OutputSplit.size() > 1)
202 LOGWARNING(
"furnace.txt: line %d: Cannot parse reward \"%s\".", a_LineNum, OutputSplit[1].c_str());
203 LOGINFO(
"Offending line: \"%s\"", a_Line.c_str());
208 Recipe.
In = InputItem.release();
209 Recipe.
Out = OutputItem.release();
224 ItemString = SplitAmount[0];
227 ItemString = SplitMeta[0];
234 if (SplitAmount.size() > 1)
236 if (!StringToInteger<char>(SplitAmount[1], a_Item.
m_ItemCount))
242 if (SplitMeta.size() > 1)
244 if (!StringToInteger<short>(SplitMeta[1], a_Item.
m_ItemDamage))
264 Recipe.
Out =
nullptr;
283 const cRecipe * BestRecipe =
nullptr;
295 BestRecipe = &Recipe;
327 const cFuel & Fuel = *itr;
330 if (BestFuel > 0 && (BestFuel > Fuel.
BurnTime))
bool StringToItem(const AString &a_ItemTypeString, cItem &a_Item)
Translates an itemtype string into an item.
std::list< cFurnaceRecipe::cRecipe > RecipeList
std::list< cFurnaceRecipe::cFuel > FuelList
#define FURNACE_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 StringToFloat(const AString &a_String, float &a_Num)
Converts a string into a float.
bool IsOnlyWhitespace(const AString &a_String)
Returns true if only whitespace characters are present in the string.
std::vector< AString > AStringVector
const cRecipe * GetRecipeFrom(const cItem &a_Ingredient) const
Returns a recipe for the specified input, nullptr if no recipe found.
int GetBurnTime(const cItem &a_Fuel) const
Returns the amount of time that the specified fuel burns, in ticks.
bool ParseItem(const AString &a_String, cItem &a_Item)
Parses an item string in the format "<ItemType>[: <Damage>][, <Amount>]", returns true if successful.
sFurnaceRecipeState * m_pState
bool IsFuel(const cItem &a_Item) const
Returns true if the item is a fuel, false if not.
void AddRecipeFromLine(const AString &a_Line, unsigned int a_LineNum)
Parses the recipe contained in the line, adds it to m_pState's recipes.
void AddFuelFromLine(const AString &a_Line, unsigned int a_LineNum)
Parses the fuel contained in the line, adds it to m_pState's fuels.
int BurnTime
How long this fuel burns, in ticks.
int CookTime
How long this recipe takes to smelt, in ticks.
float Reward
Experience reward for creating 1 of this item.