From cae4f6d0912a5ec74242b6a76a106bb93309f2e6 Mon Sep 17 00:00:00 2001 From: JapaMala Date: Sat, 27 Apr 2019 12:41:25 -0500 Subject: [PATCH] simplified the setItemFromName function --- plugins/autoclothing.cpp | 67 ++++++++++------------------------------ 1 file changed, 17 insertions(+), 50 deletions(-) diff --git a/plugins/autoclothing.cpp b/plugins/autoclothing.cpp index 28bb9cfee..85cb6c728 100644 --- a/plugins/autoclothing.cpp +++ b/plugins/autoclothing.cpp @@ -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; }