From f4583fda98b578966969db7d94a0bae3c87b0c80 Mon Sep 17 00:00:00 2001 From: "madmaxoft@gmail.com" Date: Mon, 30 Jan 2012 22:48:38 +0000 Subject: Replaced most FILE operations with a cFile object git-svn-id: http://mc-server.googlecode.com/svn/trunk@196 0a769ca7-a7f5-676a-18bf-c427514a06d6 --- source/cRecipeChecker.cpp | 77 ++++++++++++++++++++++++++--------------------- 1 file changed, 42 insertions(+), 35 deletions(-) (limited to 'source/cRecipeChecker.cpp') diff --git a/source/cRecipeChecker.cpp b/source/cRecipeChecker.cpp index d26d8d9df..ac90c7a00 100644 --- a/source/cRecipeChecker.cpp +++ b/source/cRecipeChecker.cpp @@ -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,34 +120,14 @@ 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; - } - */ +void cRecipeChecker::ReloadRecipes() +{ + LOG("--Loading recipes--"); + ClearRecipes(); std::ifstream f; @@ -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(); } + + + + -- cgit v1.2.3