1
0

Rewritten furnaces

Furnaces now smelt the correct number of items.
Furnaces store their contents in a cItemGrid.
Furnace window is updated with correct items and progressbars.
Furnace recipes now use ticks instead of milliseconds.
Furnaces save and load their state completely, not missing a smelt operation.
Hoppers take items out of furnaces.
Dropped the cSlotAreaDropSpenser class, replaced it with generic cSlotAreaItemGrid

git-svn-id: http://mc-server.googlecode.com/svn/trunk@1601 0a769ca7-a7f5-676a-18bf-c427514a06d6
This commit is contained in:
madmaxoft@gmail.com
2013-06-16 20:24:07 +00:00
parent 64f70c2e2c
commit 97eda34a94
16 changed files with 1105 additions and 445 deletions

View File

@@ -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;
}
}