From 95f6e6e5beab4ad2367b561dbd080dbafc22e8d4 Mon Sep 17 00:00:00 2001 From: Kelly Kinkade Date: Thu, 23 Mar 2023 16:21:14 -0500 Subject: [PATCH] tailor: fix material overrun issue properly track materials required for already-queued jobs fixes #3056 --- docs/changelog.txt | 2 +- library/xml | 2 +- plugins/tailor.cpp | 31 ++++++++++++++++++++++++------- 3 files changed, 26 insertions(+), 9 deletions(-) diff --git a/docs/changelog.txt b/docs/changelog.txt index 142b10e83..ca5b87255 100644 --- a/docs/changelog.txt +++ b/docs/changelog.txt @@ -37,8 +37,8 @@ changelog.txt uses a syntax similar to RST, with a few special sequences: - `prospector`: prospector tool in fort mode is now available. embark prospect is not yet available and is disabled at this time. ## Fixes -- `tailor`: now properly discriminates between dyed and undyed cloth and no longer defaults to using adamantine - `buildingplan`: upright spike traps are now placed extended rather than retracted +- `tailor`: now properly discriminates between dyed and undyed cloth, no longer defaults to using adamantine, and properly tracks material requirements for already queued orders ## Misc Improvements - `stockpiles`: support applying stockpile configurations with fully enabled categories to stockpiles in worlds other than the one where the configuration was exported from diff --git a/library/xml b/library/xml index 8b8ac2de0..0dc8ae877 160000 --- a/library/xml +++ b/library/xml @@ -1 +1 @@ -Subproject commit 8b8ac2de03ab5f8e5506864a751933059abfd03e +Subproject commit 0dc8ae87746e287538be01f01dc628662e756794 diff --git a/plugins/tailor.cpp b/plugins/tailor.cpp index 66e54dd60..2c5a1a027 100644 --- a/plugins/tailor.cpp +++ b/plugins/tailor.cpp @@ -383,6 +383,17 @@ public: auto sub = o->item_subtype; int race = o->hist_figure_id; + + for (auto& m : all_materials) + { + if (o->material_category.whole == m.job_material.whole) + { + supply[m] -= o->amount_left; + TRACE(cycle).print("tailor: supply of %s reduced by %d due to being required for an existing order\n", + m.name.c_str(), o->amount_left); + } + } + if (race == -1) continue; // -1 means that the race of the worker will determine the size made; we must ignore these jobs @@ -525,6 +536,18 @@ public: } return ordered; } + + int do_cycle() + { + reset(); + scan_clothing(); + scan_materials(); + scan_replacements(); + create_orders(); + scan_existing_orders(); + return place_orders(); + } + }; static std::unique_ptr tailor_instance; @@ -684,13 +707,7 @@ static int do_cycle(color_ostream &out) { DEBUG(cycle,out).print("running %s cycle\n", plugin_name); - tailor_instance->reset(); - tailor_instance->scan_clothing(); - tailor_instance->scan_materials(); - tailor_instance->scan_replacements(); - tailor_instance->create_orders(); - tailor_instance->scan_existing_orders(); - return tailor_instance->place_orders(); + return tailor_instance->do_cycle(); } /////////////////////////////////////////////////////