FurnaceRecipe parser: Added an else branch, changed to a switch.
This commit is contained in:
parent
3216fbabfd
commit
b90b0a1dff
@ -68,64 +68,88 @@ void cFurnaceRecipe::ReloadRecipes(void)
|
|||||||
while (std::getline(f, ParsingLine))
|
while (std::getline(f, ParsingLine))
|
||||||
{
|
{
|
||||||
Line++;
|
Line++;
|
||||||
ParsingLine.erase(std::remove_if(ParsingLine.begin(), ParsingLine.end(), isspace), ParsingLine.end()); // Remove whitespace
|
TrimString(ParsingLine);
|
||||||
if (ParsingLine.empty())
|
if (ParsingLine.empty())
|
||||||
{
|
{
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Comments
|
switch (ParsingLine[0])
|
||||||
if (ParsingLine[0] == '#')
|
|
||||||
{
|
{
|
||||||
continue;
|
case '#':
|
||||||
}
|
|
||||||
|
|
||||||
if (ParsingLine[0] == '!') // Fuels start with a bang :)
|
|
||||||
{
|
|
||||||
int IItemID = 0, IItemCount = 0, IItemHealth = 0, IBurnTime = 0;
|
|
||||||
AString::size_type BeginPos = 1; // Begin at one after exclamation mark (bang)
|
|
||||||
|
|
||||||
if (
|
|
||||||
!ReadMandatoryNumber(BeginPos, ":", ParsingLine, Line, IItemID) || // Read item ID
|
|
||||||
!ReadOptionalNumbers(BeginPos, ":", "=", ParsingLine, Line, IItemCount, IItemHealth) || // Read item count (and optionally health)
|
|
||||||
!ReadMandatoryNumber(BeginPos, "0123456789", ParsingLine, Line, IBurnTime, true) // Read item burn time - last value
|
|
||||||
)
|
|
||||||
{
|
{
|
||||||
return;
|
// Comment
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Add to fuel list
|
case '!':
|
||||||
Fuel F;
|
|
||||||
F.In = new cItem((ENUM_ITEM_ID)IItemID, (char)IItemCount, (short)IItemHealth);
|
|
||||||
F.BurnTime = IBurnTime;
|
|
||||||
m_pState->Fuel.push_back(F);
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
else if (isdigit(ParsingLine[0])) // Recipes start with a numeral :)
|
|
||||||
{
|
|
||||||
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
|
|
||||||
|
|
||||||
if (
|
|
||||||
!ReadMandatoryNumber(BeginPos, ":", ParsingLine, Line, IItemID) || // Read item ID
|
|
||||||
!ReadOptionalNumbers(BeginPos, ":", "@", ParsingLine, Line, IItemCount, IItemHealth) || // Read item count (and optionally health)
|
|
||||||
!ReadMandatoryNumber(BeginPos, "=", ParsingLine, Line, IBurnTime) || // Read item burn time
|
|
||||||
!ReadMandatoryNumber(BeginPos, ":", ParsingLine, Line, OItemID) || // Read result ID
|
|
||||||
!ReadOptionalNumbers(BeginPos, ":", "012456789", ParsingLine, Line, OItemCount, OItemHealth, true) // Read result count (and optionally health) - last value
|
|
||||||
)
|
|
||||||
{
|
{
|
||||||
return;
|
// Fuel
|
||||||
|
int IItemID = 0, IItemCount = 0, IItemHealth = 0, IBurnTime = 0;
|
||||||
|
AString::size_type BeginPos = 1; // Begin at one after exclamation mark (bang)
|
||||||
|
|
||||||
|
if (
|
||||||
|
!ReadMandatoryNumber(BeginPos, ":", ParsingLine, Line, IItemID) || // Read item ID
|
||||||
|
!ReadOptionalNumbers(BeginPos, ":", "=", ParsingLine, Line, IItemCount, IItemHealth) || // Read item count (and optionally health)
|
||||||
|
!ReadMandatoryNumber(BeginPos, "0123456789", ParsingLine, Line, IBurnTime, true) // Read item burn time - last value
|
||||||
|
)
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
// 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);
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Add to recipe list
|
case '0':
|
||||||
Recipe R;
|
case '1':
|
||||||
R.In = new cItem((ENUM_ITEM_ID)IItemID, (char)IItemCount, (short)IItemHealth);
|
case '2':
|
||||||
R.Out = new cItem((ENUM_ITEM_ID)OItemID, (char)OItemCount, (short)OItemHealth);
|
case '3':
|
||||||
R.CookTime = IBurnTime;
|
case '4':
|
||||||
m_pState->Recipes.push_back(R);
|
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
|
||||||
|
|
||||||
|
if (
|
||||||
|
!ReadMandatoryNumber(BeginPos, ":", ParsingLine, Line, IItemID) || // Read item ID
|
||||||
|
!ReadOptionalNumbers(BeginPos, ":", "@", ParsingLine, Line, IItemCount, IItemHealth) || // Read item count (and optionally health)
|
||||||
|
!ReadMandatoryNumber(BeginPos, "=", ParsingLine, Line, IBurnTime) || // Read item burn time
|
||||||
|
!ReadMandatoryNumber(BeginPos, ":", ParsingLine, Line, OItemID) || // Read result ID
|
||||||
|
!ReadOptionalNumbers(BeginPos, ":", "012456789", ParsingLine, Line, OItemCount, OItemHealth, true) // Read result count (and optionally health) - last value
|
||||||
|
)
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
// 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 = 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());
|
LOG("Loaded " SIZE_T_FMT " furnace recipes and " SIZE_T_FMT " fuels", m_pState->Recipes.size(), m_pState->Fuel.size());
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user