Replaced most FILE operations with a cFile object
git-svn-id: http://mc-server.googlecode.com/svn/trunk@196 0a769ca7-a7f5-676a-18bf-c427514a06d6
This commit is contained in:
@@ -19,35 +19,56 @@
|
||||
|
||||
|
||||
typedef std::list< cRecipeChecker::Recipe* > RecipeList;
|
||||
|
||||
struct cRecipeChecker::sRecipeCheckerState
|
||||
{
|
||||
RecipeList Recipes;
|
||||
};
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
cRecipeChecker* cRecipeChecker::GetRecipeChecker()
|
||||
{
|
||||
LOGWARN("WARNING: Using deprecated function cRecipeChecker::GetRecipeChecker() use cRoot::Get()->GetRecipeChecker() instead!");
|
||||
return cRoot::Get()->GetRecipeChecker();
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
cRecipeChecker::Recipe::~Recipe()
|
||||
{
|
||||
delete [] Slots;
|
||||
Slots = 0;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
cRecipeChecker::~cRecipeChecker()
|
||||
{
|
||||
ClearRecipes();
|
||||
delete m_pState;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
cRecipeChecker::cRecipeChecker()
|
||||
: m_pState( new sRecipeCheckerState )
|
||||
{
|
||||
ReloadRecipes();
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
void cRecipeChecker::ClearRecipes()
|
||||
{
|
||||
while( m_pState->Recipes.size() > 0 )
|
||||
@@ -57,6 +78,10 @@ void cRecipeChecker::ClearRecipes()
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
void PrintRecipe( std::vector< cRecipeChecker::RecipeSlot > & RecipeSlots )
|
||||
{
|
||||
LOG("Recipe:");
|
||||
@@ -67,6 +92,10 @@ void PrintRecipe( std::vector< cRecipeChecker::RecipeSlot > & RecipeSlots )
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
void PrintNear( std::ifstream & f, int a_History = 64 )
|
||||
{
|
||||
f.clear();
|
||||
@@ -91,35 +120,15 @@ void PrintNear( std::ifstream & f, int a_History = 64 )
|
||||
LOGERROR("Error near: \"%s\"", Near.c_str() );
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
void cRecipeChecker::ReloadRecipes()
|
||||
{
|
||||
LOG("--Loading recipes--");
|
||||
ClearRecipes();
|
||||
|
||||
/*
|
||||
char a_File[] = "recipes.txt";
|
||||
|
||||
FILE* f = 0;
|
||||
#ifdef _WIN32
|
||||
if( fopen_s(&f, a_File, "rb" ) == 0 ) // no error
|
||||
#else
|
||||
if( (f = fopen(a_File, "rb" )) != 0 ) // no error
|
||||
#endif
|
||||
{
|
||||
char c;
|
||||
while( fread( &c, sizeof(char), 1, f) == 1 )
|
||||
{
|
||||
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
LOG("Could not open file for recipes: %s", a_File);
|
||||
return;
|
||||
}
|
||||
*/
|
||||
|
||||
|
||||
std::ifstream f;
|
||||
|
||||
char a_File[] = "recipes.txt";
|
||||
@@ -361,19 +370,13 @@ void cRecipeChecker::ReloadRecipes()
|
||||
}
|
||||
f.close();
|
||||
|
||||
LOG("Found %i recipes", m_pState->Recipes.size() );
|
||||
// for(RecipeList::iterator itr = m_pState->Recipes.begin(); itr != m_pState->Recipes.end(); ++itr )
|
||||
// {
|
||||
// LOG("Recipe for %i times %i", (*itr)->Result.m_ItemCount, (*itr)->Result.m_ItemID );
|
||||
// for(unsigned int j = 0; j < (*itr)->NumItems; j++)
|
||||
// {
|
||||
// RecipeSlot Slot = (*itr)->Slots[j];
|
||||
// LOG("%i %i %i %i", Slot.x, Slot.y, Slot.Item.m_ItemID, Slot.Item.m_ItemCount );
|
||||
// }
|
||||
// }
|
||||
LOG("--Done loading recipes--");
|
||||
LOG("--Done loading recipes, found %i recipes", m_pState->Recipes.size() );
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
cItem cRecipeChecker::CookIngredients( cItem* a_Items, int a_Width, int a_Height, bool a_bConsumeIngredients /* = false */ )
|
||||
{
|
||||
int iLeft = 999, iTop = 999;
|
||||
@@ -459,3 +462,7 @@ cItem cRecipeChecker::CookIngredients( cItem* a_Items, int a_Width, int a_Height
|
||||
}
|
||||
return cItem();
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user