Esempio n. 1
0
void cBrewingRecipes::ReloadRecipes(void)
{
	ClearRecipes();
	LOGD("Loading brewing recipes...");

	std::ifstream f(BREWING_RECIPE_FILE, std::ios::in);
	if (!f.good())
	{
		LOG("Could not open the brewing recipes file \"%s\". No brewing recipes are available.", BREWING_RECIPE_FILE);
		return;
	}

	unsigned int LineNum = 0;
	AString ParsingLine;

	while (std::getline(f, ParsingLine))
	{
		LineNum++;
		// Remove comments from the line:
		size_t FirstCommentSymbol = ParsingLine.find('#');
		if (FirstCommentSymbol != AString::npos)
		{
			ParsingLine.erase(ParsingLine.begin() += static_cast<long>(FirstCommentSymbol), ParsingLine.end());
		}

		if (ParsingLine.empty())
		{
			continue;
		}
		AddRecipeFromLine(ParsingLine, LineNum);
	}  // while (getline(ParsingLine))

	LOG("Loaded " SIZE_T_FMT " brewing recipes", m_pState->Recipes.size());
}
Esempio n. 2
0
void cFurnaceRecipe::ReloadRecipes(void)
{
	ClearRecipes();
	LOGD("Loading furnace recipes...");

	std::ifstream f(FURNACE_RECIPE_FILE, std::ios::in);
	if (!f.good())
	{
		LOG("Could not open the furnace recipes file \"%s\". No furnace recipes are available.", FURNACE_RECIPE_FILE);
		return;
	}

	unsigned int LineNum = 0;
	AString ParsingLine;

	while (std::getline(f, ParsingLine))
	{
		LineNum++;
		if (ParsingLine.empty())
		{
			continue;
		}

		// Remove comments from the line:
		size_t FirstCommentSymbol = ParsingLine.find('#');
		if ((FirstCommentSymbol != AString::npos) && (FirstCommentSymbol != 0))
		{
			ParsingLine.erase(ParsingLine.begin() + static_cast<const long>(FirstCommentSymbol), ParsingLine.end());
		}

		switch (ParsingLine[0])
		{
			case '#':
			{
				// Comment
				break;
			}

			case '!':
			{
				AddFuelFromLine(ParsingLine, LineNum);
				break;
			}

			default:
			{
				AddRecipeFromLine(ParsingLine, LineNum);
				break;
			}
		}  // switch (ParsingLine[0])
	}  // while (getline(ParsingLine))

	LOG("Loaded " SIZE_T_FMT " furnace recipes and " SIZE_T_FMT " fuels", m_pState->Recipes.size(), m_pState->Fuel.size());
}
Esempio n. 3
0
void cCraftingRecipes::LoadRecipes(void)
{
	LOGD("Loading crafting recipes from crafting.txt...");
	ClearRecipes();
	
	// Load the crafting.txt file:
	cFile f;
	if (!f.Open("crafting.txt", cFile::fmRead))
	{
		LOGWARNING("Cannot open file \"crafting.txt\", no crafting recipes will be available!");
		return;
	}
	AString Everything;
	if (!f.ReadRestOfFile(Everything))
	{
		LOGWARNING("Cannot read file \"crafting.txt\", no crafting recipes will be available!");
		return;
	}
	f.Close();
	
	// Split it into lines, then process each line as a single recipe:
	AStringVector Split = StringSplit(Everything, "\n");
	int LineNum = 1;
	for (AStringVector::const_iterator itr = Split.begin(); itr != Split.end(); ++itr, ++LineNum)
	{
		// Remove anything after a '#' sign and trim away the whitespace:
		AString Recipe = TrimString(itr->substr(0, itr->find('#')));
		if (Recipe.empty())
		{
			// Empty recipe
			continue;
		}
		AddRecipeLine(LineNum, Recipe);
	}  // for itr - Split[]
	LOG("Loaded " SIZE_T_FMT " crafting recipes", m_Recipes.size());
}
Esempio n. 4
0
cFurnaceRecipe::~cFurnaceRecipe()
{
	ClearRecipes();
	delete m_pState;
	m_pState = nullptr;
}
Esempio n. 5
0
cCraftingRecipes::~cCraftingRecipes()
{
	ClearRecipes();
}
Esempio n. 6
0
cBrewingRecipes::~cBrewingRecipes()
{
	ClearRecipes();
}
Esempio n. 7
0
void cFurnaceRecipe::ReloadRecipes(void)
{
	ClearRecipes();
	LOG("-- Loading furnace recipes --");

	std::ifstream f;
	char a_File[] = "furnace.txt";
	f.open(a_File, std::ios::in);
	std::string input;

	if (!f.good())
	{
		f.close();
		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())
	{
		char c;

		//////////////////////////////////////////////////////////////////////////
		// comments
		f >> c;
		f.unget();
		if( c == '#' )
		{
			while( f.good() && c != '\n' )
			{
				f.get( c );
			}
			continue;
		}


		//////////////////////////////////////////////////////////////////////////
		// Line breaks
		f.get( c );
		while( f.good() && ( c == '\n' || c == '\r' ) ) { f.get( c ); }
		if (f.eof())
		{
			break;
		}
		f.unget();

		//////////////////////////////////////////////////////////////////////////
		// Check for fuel
		f >> c;
		if( c == '!' ) // It's fuel :)
		{
			// Read item
			int IItemID = 0, IItemCount = 0, IItemHealth = 0;
			f >> IItemID;
			f >> c; if( c != ':' ) { bSyntaxError = true; break; }
			f >> IItemCount;

			// Optional health
			f >> c; 
			if( c != ':' ) 
				f.unget();
			else
			{
				f >> IItemHealth;
			}

			// Burn time
			int BurnTime;
			f >> c; if( c != '=' ) { bSyntaxError = true; break; }
			f >> BurnTime;

			// Add to fuel list
			Fuel F;
			F.In = new cItem( (ENUM_ITEM_ID) IItemID, (char)IItemCount, (short)IItemHealth );
			F.BurnTime = BurnTime;
			m_pState->Fuel.push_back( F );
			continue;
		}
		f.unget();

		//////////////////////////////////////////////////////////////////////////
		// Read items
		int IItemID = 0, IItemCount = 0, IItemHealth = 0;
		f >> IItemID;
		f >> c; if( c != ':' ) { bSyntaxError = true; break; }
		f >> IItemCount;

		// Optional health
		f >> c; 
		if( c != ':' ) 
			f.unget();
		else
		{
			f >> IItemHealth;
		}

		int CookTime;
		f >> c; if( c != '@' ) { bSyntaxError = true; break; }
		f >> CookTime;

		int OItemID = 0, OItemCount = 0, OItemHealth = 0;
		f >> c; if( c != '=' ) { bSyntaxError = true; break; }
		f >> OItemID;
		f >> c; if( c != ':' ) { bSyntaxError = true; break; }
		f >> OItemCount;

		// Optional health
		f >> c; 
		if( c != ':' ) 
			f.unget();
		else
		{
			f >> OItemHealth;
		}

		// Add to recipe list
		Recipe R;
		R.In = new cItem( (ENUM_ITEM_ID)IItemID, (char)IItemCount, (short)IItemHealth );
		R.Out = new cItem( (ENUM_ITEM_ID)OItemID, (char)OItemCount, (short)OItemHealth );
		R.CookTime = CookTime;
		m_pState->Recipes.push_back( R );
	}
Esempio n. 8
0
cFurnaceRecipe::~cFurnaceRecipe()
{
	ClearRecipes();
	delete m_pState;
}