1
0

FurnaceRecipe parser: Added an else branch, changed to a switch.

This commit is contained in:
Mattes D 2014-06-26 17:51:19 +02:00
parent 3216fbabfd
commit b90b0a1dff

View File

@ -68,20 +68,23 @@ void cFurnaceRecipe::ReloadRecipes(void)
while (std::getline(f, ParsingLine))
{
Line++;
ParsingLine.erase(std::remove_if(ParsingLine.begin(), ParsingLine.end(), isspace), ParsingLine.end()); // Remove whitespace
TrimString(ParsingLine);
if (ParsingLine.empty())
{
continue;
}
// Comments
if (ParsingLine[0] == '#')
switch (ParsingLine[0])
{
continue;
case '#':
{
// Comment
break;
}
if (ParsingLine[0] == '!') // Fuels start with a bang :)
case '!':
{
// Fuel
int IItemID = 0, IItemCount = 0, IItemHealth = 0, IBurnTime = 0;
AString::size_type BeginPos = 1; // Begin at one after exclamation mark (bang)
@ -94,15 +97,26 @@ void cFurnaceRecipe::ReloadRecipes(void)
return;
}
// Add to fuel list
// Add to fuel list:
Fuel F;
F.In = new cItem((ENUM_ITEM_ID)IItemID, (char)IItemCount, (short)IItemHealth);
F.BurnTime = IBurnTime;
m_pState->Fuel.push_back(F);
continue;
break;
}
else if (isdigit(ParsingLine[0])) // Recipes start with a numeral :)
case '0':
case '1':
case '2':
case '3':
case '4':
case '5':
case '6':
case '7':
case '8':
case '9':
{
// Recipe
int IItemID = 0, IItemCount = 0, IItemHealth = 0, IBurnTime = 0;
int OItemID = 0, OItemCount = 0, OItemHealth = 0;
AString::size_type BeginPos = 0; // Begin at start of line
@ -124,8 +138,18 @@ void cFurnaceRecipe::ReloadRecipes(void)
R.Out = new cItem((ENUM_ITEM_ID)OItemID, (char)OItemCount, (short)OItemHealth);
R.CookTime = IBurnTime;
m_pState->Recipes.push_back(R);
break;
}
default:
{
LOGWARNING("Error in furnace recipes at line %d: Unexpected text: \"%s\". Ignoring line.",
Line, ParsingLine.c_str()
);
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());
}