
/*
 * Copyright 2011-2022 Cuberite Contributors
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 * 
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

#pragma once





class cItem;





class cFurnaceRecipe
{
public:
	cFurnaceRecipe(void);
	~cFurnaceRecipe();

	void ReloadRecipes(void);

	struct cFuel
	{
		cItem * In;
		int BurnTime;  ///< How long this fuel burns, in ticks
	};

	struct cRecipe
	{
		cItem * In;
		cItem * Out;
		int CookTime;  ///< How long this recipe takes to smelt, in ticks
		float Reward;  ///< Experience reward for creating 1 of this item
	};

	/** Returns a recipe for the specified input, nullptr if no recipe found */
	const cRecipe * GetRecipeFrom(const cItem & a_Ingredient) const;

	/** Returns true if the item is a fuel, false if not. */
	bool IsFuel(const cItem & a_Item) const;

	/** Returns the amount of time that the specified fuel burns, in ticks */
	int GetBurnTime(const cItem & a_Fuel) const;

private:
	void ClearRecipes(void);

	/** Parses the fuel contained in the line, adds it to m_pState's fuels.
	Logs a warning to the console on input error. */
	void AddFuelFromLine(const AString & a_Line, unsigned int a_LineNum);

	/** Parses the recipe contained in the line, adds it to m_pState's recipes.
	Logs a warning to the console on input error. */
	void AddRecipeFromLine(const AString & a_Line, unsigned int a_LineNum);

	/** Parses an item string in the format "<ItemType>[: <Damage>][, <Amount>]", returns true if successful. */
	bool ParseItem(const AString & a_String, cItem & a_Item);

	struct sFurnaceRecipeState;
	sFurnaceRecipeState * m_pState;
};




