Skip to content

Commit

Permalink
simplified the setItemFromName function
Browse files Browse the repository at this point in the history
  • Loading branch information
RosaryMala committed Apr 27, 2019
1 parent b2d59fd commit cae4f6d
Showing 1 changed file with 17 additions and 50 deletions.
67 changes: 17 additions & 50 deletions plugins/autoclothing.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -134,56 +134,23 @@ DFhackCExport command_result plugin_onupdate(color_ostream &out)

static bool setItemFromName(std::string name, ClothingRequirement* requirement)
{
for (auto&& itemdef : world->raws.itemdefs.armor)
{
if (itemdef->name == name)
{
requirement->job_type = job_type::MakeArmor;
requirement->item_type = item_type::ARMOR;
requirement->item_subtype = itemdef->subtype;
return true;
}
}
for (auto&& itemdef : world->raws.itemdefs.gloves)
{
if (itemdef->name == name)
{
requirement->job_type = job_type::MakeGloves;
requirement->item_type = item_type::GLOVES;
requirement->item_subtype = itemdef->subtype;
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;
}
}
#define SEARCH_ITEM_RAWS(rawType, jobType, itemType) \
for (auto&& itemdef : world->raws.itemdefs.rawType) \
{ \
if (itemdef->name == name) \
{ \
requirement->job_type = job_type::jobType; \
requirement->item_type = item_type::itemType; \
requirement->item_subtype = itemdef->subtype; \
return true; \
} \
}

SEARCH_ITEM_RAWS(armor, MakeArmor, ARMOR);
SEARCH_ITEM_RAWS(gloves, MakeGloves, GLOVES);
SEARCH_ITEM_RAWS(shoes, MakeShoes, SHOES);
SEARCH_ITEM_RAWS(helms, MakeHelm, HELM);
SEARCH_ITEM_RAWS(pants, MakePants, PANTS);
return false;
}

Expand Down

0 comments on commit cae4f6d

Please sign in to comment.