2012-06-14 09:06:06 -04:00
# pragma once
class cItem ;
class cFurnaceRecipe
{
public :
2013-06-16 16:24:07 -04:00
cFurnaceRecipe ( void ) ;
2012-06-14 09:06:06 -04:00
~ cFurnaceRecipe ( ) ;
2013-06-16 16:24:07 -04:00
void ReloadRecipes ( void ) ;
2012-06-14 09:06:06 -04:00
struct Fuel
{
2013-06-16 16:24:07 -04:00
cItem * In ;
int BurnTime ; ///< How long this fuel burns, in ticks
2012-06-14 09:06:06 -04:00
} ;
struct Recipe
{
2013-06-16 16:24:07 -04:00
cItem * In ;
cItem * Out ;
int CookTime ; ///< How long this recipe takes to smelt, in ticks
2012-06-14 09:06:06 -04:00
} ;
2013-06-16 16:24:07 -04:00
/// Returns a recipe for the specified input, NULL if no recipe found
const Recipe * GetRecipeFrom ( const cItem & a_Ingredient ) const ;
/// Returns the amount of time that the specified fuel burns, in ticks
int GetBurnTime ( const cItem & a_Fuel ) const ;
2012-06-14 09:06:06 -04:00
private :
2013-06-16 16:24:07 -04:00
void ClearRecipes ( void ) ;
2012-06-14 09:06:06 -04:00
2014-06-26 12:18:41 -04:00
/** Parses the fuel contained in the line, adds it to m_pState's fuels.
Logs a warning to the console on input error . */
void AddFuelFromLine ( const AString & a_Line , int a_LineNum ) ;
/** Parses the recipe contained in the line, adds it to m_pState's recipes.
Logs a warning to the console on input error . */
void AddRecipeFromLine ( const AString & a_Line , int a_LineNum ) ;
2014-06-21 19:06:58 -04:00
/** Calls LOGWARN with the line, position, and error */
2014-06-22 16:51:21 -04:00
static void PrintParseError ( unsigned int a_Line , size_t a_Position , const AString & a_CharactersMissing ) ;
2014-06-21 15:33:23 -04:00
/** Reads a number from a string given, starting at a given position and ending at a delimiter given
Updates beginning position to the delimiter found + 1 , and updates the value to the one read
If it encounters a substring that is not fully numeric , it will call SetParseError ( ) and return false ; the caller should abort processing
Otherwise , the function will return true
*/
2014-06-21 19:06:58 -04:00
static bool ReadMandatoryNumber ( AString : : size_type & a_Begin , const AString & a_Delimiter , const AString & a_Text , unsigned int a_Line , int & a_Value , bool a_IsLastValue = false ) ;
2014-06-21 15:33:23 -04:00
/** Reads two numbers from a string given, starting at a given position and ending at the first delimiter given, then again (with an updated position) until the second delimiter given
Updates beginning position to the second delimiter found + 1 , and updates the values to the ones read
If it encounters a substring that is not fully numeric whilst reading the second value , it will call SetParseError ( ) and return false ; the caller should abort processing
If this happens whilst reading the first value , it will call ReadMandatoryNumber ( ) with the appropriate position , as this may legitimately occur with the optional value and AString : : find_first_of finding the incorrect delimiter . It will return the result of ReadMandatoryNumber ( )
True will be returned definitively for an optional value that is valid
*/
2014-06-21 19:06:58 -04:00
static bool ReadOptionalNumbers ( AString : : size_type & a_Begin , const AString & a_DelimiterOne , const AString & a_DelimiterTwo , const AString & a_Text , unsigned int a_Line , int & a_ValueOne , int & a_ValueTwo , bool a_IsLastValue = false ) ;
2014-06-21 15:33:23 -04:00
/** Uses std::all_of to determine if a string contains only digits */
2014-06-22 16:51:21 -04:00
static bool DoesStringContainOnlyNumbers ( const AString & a_String ) ;
2014-06-21 15:33:23 -04:00
2012-06-14 09:06:06 -04:00
struct sFurnaceRecipeState ;
2013-06-16 16:24:07 -04:00
sFurnaceRecipeState * m_pState ;
2012-06-14 09:06:06 -04:00
} ;