summaryrefslogtreecommitdiffstats
path: root/source/FurnaceRecipe.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'source/FurnaceRecipe.cpp')
-rw-r--r--source/FurnaceRecipe.cpp64
1 files changed, 39 insertions, 25 deletions
diff --git a/source/FurnaceRecipe.cpp b/source/FurnaceRecipe.cpp
index a012c8c51..8b1ee09a2 100644
--- a/source/FurnaceRecipe.cpp
+++ b/source/FurnaceRecipe.cpp
@@ -48,7 +48,7 @@ cFurnaceRecipe::~cFurnaceRecipe()
-void cFurnaceRecipe::ReloadRecipes()
+void cFurnaceRecipe::ReloadRecipes(void)
{
ClearRecipes();
LOG("-- Loading furnace recipes --");
@@ -58,15 +58,16 @@ void cFurnaceRecipe::ReloadRecipes()
f.open(a_File, std::ios::in);
std::string input;
- if( !f.good() )
+ if (!f.good())
{
f.close();
- LOG("Could not open file for recipes: %s", a_File);
+ LOG("Could not open the furnace recipes file \"%s\"", a_File);
return;
}
+ // TODO: Replace this messy parse with a high-level-structured one (ReadLine / ProcessLine)
bool bSyntaxError = false;
- while( f.good() )
+ while (f.good())
{
char c;
@@ -88,7 +89,10 @@ void cFurnaceRecipe::ReloadRecipes()
// Line breaks
f.get( c );
while( f.good() && ( c == '\n' || c == '\r' ) ) { f.get( c ); }
- if( f.eof() ) break;
+ if (f.eof())
+ {
+ break;
+ }
f.unget();
//////////////////////////////////////////////////////////////////////////
@@ -112,7 +116,7 @@ void cFurnaceRecipe::ReloadRecipes()
}
// Burn time
- float BurnTime;
+ int BurnTime;
f >> c; if( c != '=' ) { bSyntaxError = true; break; }
f >> BurnTime;
@@ -141,7 +145,7 @@ void cFurnaceRecipe::ReloadRecipes()
f >> IItemHealth;
}
- float CookTime;
+ int CookTime;
f >> c; if( c != '@' ) { bSyntaxError = true; break; }
f >> CookTime;
@@ -167,22 +171,20 @@ void cFurnaceRecipe::ReloadRecipes()
R.CookTime = CookTime;
m_pState->Recipes.push_back( R );
}
- if( bSyntaxError )
+ if (bSyntaxError)
{
LOGERROR("ERROR: FurnaceRecipe, syntax error" );
}
- LOG("Got %i furnace recipes, and %i fuels.", m_pState->Recipes.size(), m_pState->Fuel.size() );
-
- LOG("-- Done loading furnace recipes --");
+ LOG("Got %u furnace recipes, and %u fuels.", m_pState->Recipes.size(), m_pState->Fuel.size());
}
-void cFurnaceRecipe::ClearRecipes()
+void cFurnaceRecipe::ClearRecipes(void)
{
- for( RecipeList::iterator itr = m_pState->Recipes.begin(); itr != m_pState->Recipes.end(); ++itr )
+ for (RecipeList::iterator itr = m_pState->Recipes.begin(); itr != m_pState->Recipes.end(); ++itr)
{
Recipe R = *itr;
delete R.In;
@@ -190,7 +192,7 @@ void cFurnaceRecipe::ClearRecipes()
}
m_pState->Recipes.clear();
- for( FuelList::iterator itr = m_pState->Fuel.begin(); itr != m_pState->Fuel.end(); ++itr )
+ for (FuelList::iterator itr = m_pState->Fuel.begin(); itr != m_pState->Fuel.end(); ++itr)
{
Fuel F = *itr;
delete F.In;
@@ -198,15 +200,19 @@ void cFurnaceRecipe::ClearRecipes()
m_pState->Fuel.clear();
}
-const cFurnaceRecipe::Recipe* cFurnaceRecipe::GetRecipeFrom( const cItem & a_Ingredient ) const
+
+
+
+
+const cFurnaceRecipe::Recipe * cFurnaceRecipe::GetRecipeFrom(const cItem & a_Ingredient) const
{
- const Recipe* BestRecipe = 0;
- for( RecipeList::const_iterator itr = m_pState->Recipes.begin(); itr != m_pState->Recipes.end(); ++itr )
+ const Recipe * BestRecipe = 0;
+ for (RecipeList::const_iterator itr = m_pState->Recipes.begin(); itr != m_pState->Recipes.end(); ++itr)
{
const Recipe & R = *itr;
- if( (R.In->m_ItemType == a_Ingredient.m_ItemType) && (R.In->m_ItemCount <= a_Ingredient.m_ItemCount ) )
+ if ((R.In->m_ItemType == a_Ingredient.m_ItemType) && (R.In->m_ItemCount <= a_Ingredient.m_ItemCount))
{
- if( BestRecipe && (BestRecipe->In->m_ItemCount > R.In->m_ItemCount) )
+ if (BestRecipe && (BestRecipe->In->m_ItemCount > R.In->m_ItemCount))
{
continue;
}
@@ -219,15 +225,19 @@ const cFurnaceRecipe::Recipe* cFurnaceRecipe::GetRecipeFrom( const cItem & a_Ing
return BestRecipe;
}
-float cFurnaceRecipe::GetBurnTime( const cItem & a_Fuel ) const
+
+
+
+
+int cFurnaceRecipe::GetBurnTime(const cItem & a_Fuel) const
{
- float BestFuel = 0.f;
- for( FuelList::const_iterator itr = m_pState->Fuel.begin(); itr != m_pState->Fuel.end(); ++itr )
+ int BestFuel = 0;
+ for (FuelList::const_iterator itr = m_pState->Fuel.begin(); itr != m_pState->Fuel.end(); ++itr)
{
const Fuel & F = *itr;
- if( (F.In->m_ItemType == a_Fuel.m_ItemType) && (F.In->m_ItemCount <= a_Fuel.m_ItemCount ) )
+ if ((F.In->m_ItemType == a_Fuel.m_ItemType) && (F.In->m_ItemCount <= a_Fuel.m_ItemCount))
{
- if( BestFuel > 0.f && (BestFuel > F.BurnTime ) )
+ if (BestFuel > 0 && (BestFuel > F.BurnTime))
{
continue;
}
@@ -238,4 +248,8 @@ float cFurnaceRecipe::GetBurnTime( const cItem & a_Fuel ) const
}
}
return BestFuel;
-} \ No newline at end of file
+}
+
+
+
+