From e8f67c7b620026369d7c1c03b312c5cc16eeebe1 Mon Sep 17 00:00:00 2001 From: Kelly Kinkade Date: Fri, 20 Jan 2023 15:21:45 -0600 Subject: [PATCH] add support for using undyed cloth also improved debugging messages --- docs/changelog.txt | 1 + plugins/tailor.cpp | 31 +++++++++++++++++++++++++++++-- 2 files changed, 30 insertions(+), 2 deletions(-) diff --git a/docs/changelog.txt b/docs/changelog.txt index c119e0c89..240ea0bec 100644 --- a/docs/changelog.txt +++ b/docs/changelog.txt @@ -38,6 +38,7 @@ changelog.txt uses a syntax similar to RST, with a few special sequences: ## Fixes - `autofarm`: don't duplicate status line entries for crops with no current supply - `orders`: allow the orders library to be listed and imported properly (if you previously copied the orders library into your ``dfhack-config/orders`` directory to work around this bug, you can remove those files now) +- `tailor`: now respects the setting of the "used dyed clothing" standing order toggle ## Misc Improvements diff --git a/plugins/tailor.cpp b/plugins/tailor.cpp index 2b1d0c63c..4e750cb3f 100644 --- a/plugins/tailor.cpp +++ b/plugins/tailor.cpp @@ -41,6 +41,7 @@ DFHACK_PLUGIN_IS_ENABLED(enabled); REQUIRE_GLOBAL(world); REQUIRE_GLOBAL(plotinfo); +REQUIRE_GLOBAL(standing_orders_use_dyed_cloth); namespace DFHack { DBG_DECLARE(tailor, cycle, DebugCategory::LINFO); @@ -159,12 +160,21 @@ private: void scan_materials() { + bool require_dyed = df::global::standing_orders_use_dyed_cloth ? (*df::global::standing_orders_use_dyed_cloth) : false; + for (auto i : world->items.other[df::items_other_id::CLOTH]) { if (i->flags.whole & bad_flags.whole) continue; - if (!i->hasImprovements()) // only count dyed + + if (require_dyed && !i->hasImprovements()) + { + // only count dyed + std::string d; + i->getItemDescription(&d, 0); + TRACE(cycle).print("tailor: skipping undyed %s\n", d.c_str()); continue; + } MaterialInfo mat(i); int ss = i->getStackSize(); @@ -176,6 +186,12 @@ private: supply[M_CLOTH] += ss; else if (mat.material->flags.is_set(df::material_flags::YARN)) supply[M_YARN] += ss; + else + { + std::string d; + i->getItemDescription(&d, 0); + WARN(cycle).print("tailor: weird cloth item found: %s (%d)\n", d.c_str(), i->id); + } } } @@ -266,7 +282,7 @@ private: } else { - DEBUG(cycle).print ("%s worn by %s needs replacement, but none available\n", + DEBUG(cycle).print ("tailor: %s worn by %s needs replacement, but none available\n", description.c_str(), Translation::TranslateName(&u->name, false).c_str()); orders[std::make_tuple(o, w->getSubtype(), size)] += 1; @@ -407,6 +423,8 @@ private: continue; } + DEBUG(cycle).print("tailor: ordering %d %s\n", count, name_p.c_str()); + for (auto& m : material_order) { if (count <= 0) @@ -418,7 +436,11 @@ private: if (supply[m] > res && fl->is_set(m.armor_flag)) { int c = count; if (supply[m] < count + res) + { c = supply[m] - res; + TRACE(cycle).print("tailor: order reduced from %d to %d to protect reserves of %s\n", + count, c, m.name.c_str()); + } supply[m] -= c; auto order = new df::manager_order; @@ -447,6 +469,11 @@ private: count -= c; } + else + { + TRACE(cycle).print("tailor: material %s skipped due to lack of reserves, %d available\n", m.name.c_str(), supply[m]); + } + } } }