simplified the setItemFromName function

develop
JapaMala 2019-04-27 12:41:25 -05:00
parent b2d59fd143
commit cae4f6d091
1 changed files with 17 additions and 50 deletions

@ -134,56 +134,23 @@ DFhackCExport command_result plugin_onupdate(color_ostream &out)
static bool setItemFromName(std::string name, ClothingRequirement* requirement) static bool setItemFromName(std::string name, ClothingRequirement* requirement)
{ {
for (auto&& itemdef : world->raws.itemdefs.armor) #define SEARCH_ITEM_RAWS(rawType, jobType, itemType) \
{ for (auto&& itemdef : world->raws.itemdefs.rawType) \
if (itemdef->name == name) { \
{ if (itemdef->name == name) \
requirement->job_type = job_type::MakeArmor; { \
requirement->item_type = item_type::ARMOR; requirement->job_type = job_type::jobType; \
requirement->item_subtype = itemdef->subtype; requirement->item_type = item_type::itemType; \
return true; requirement->item_subtype = itemdef->subtype; \
} return true; \
} } \
for (auto&& itemdef : world->raws.itemdefs.gloves) }
{
if (itemdef->name == name) SEARCH_ITEM_RAWS(armor, MakeArmor, ARMOR);
{ SEARCH_ITEM_RAWS(gloves, MakeGloves, GLOVES);
requirement->job_type = job_type::MakeGloves; SEARCH_ITEM_RAWS(shoes, MakeShoes, SHOES);
requirement->item_type = item_type::GLOVES; SEARCH_ITEM_RAWS(helms, MakeHelm, HELM);
requirement->item_subtype = itemdef->subtype; SEARCH_ITEM_RAWS(pants, MakePants, PANTS);
return true;
}
}
for (auto&& itemdef : world->raws.itemdefs.shoes)
{
if (itemdef->name == name)
{
requirement->job_type = job_type::MakeShoes;
requirement->item_type = item_type::SHOES;
requirement->item_subtype = itemdef->subtype;
return true;
}
}
for (auto&& itemdef : world->raws.itemdefs.helms)
{
if (itemdef->name == name)
{
requirement->job_type = job_type::MakeHelm;
requirement->item_type = item_type::HELM;
requirement->item_subtype = itemdef->subtype;
return true;
}
}
for (auto&& itemdef : world->raws.itemdefs.pants)
{
if (itemdef->name == name)
{
requirement->job_type = job_type::MakePants;
requirement->item_type = item_type::PANTS;
requirement->item_subtype = itemdef->subtype;
return true;
}
}
return false; return false;
} }