diff options
author | madmaxoft@gmail.com <madmaxoft@gmail.com@0a769ca7-a7f5-676a-18bf-c427514a06d6> | 2013-06-16 22:24:07 +0200 |
---|---|---|
committer | madmaxoft@gmail.com <madmaxoft@gmail.com@0a769ca7-a7f5-676a-18bf-c427514a06d6> | 2013-06-16 22:24:07 +0200 |
commit | 97eda34a9437abe732cf6b60711828bbe4f0cb2e (patch) | |
tree | f06f2a5bb2ad7efd0d09d9cba0b2f8fe586a53e0 /source/FurnaceRecipe.cpp | |
parent | Core: fixed a warning message when using the /item command (diff) | |
download | cuberite-97eda34a9437abe732cf6b60711828bbe4f0cb2e.tar cuberite-97eda34a9437abe732cf6b60711828bbe4f0cb2e.tar.gz cuberite-97eda34a9437abe732cf6b60711828bbe4f0cb2e.tar.bz2 cuberite-97eda34a9437abe732cf6b60711828bbe4f0cb2e.tar.lz cuberite-97eda34a9437abe732cf6b60711828bbe4f0cb2e.tar.xz cuberite-97eda34a9437abe732cf6b60711828bbe4f0cb2e.tar.zst cuberite-97eda34a9437abe732cf6b60711828bbe4f0cb2e.zip |
Diffstat (limited to 'source/FurnaceRecipe.cpp')
-rw-r--r-- | source/FurnaceRecipe.cpp | 64 |
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 +} + + + + |