From 42d3620ef6e551d0bf9aeb1e238dd833d1cbf7a1 Mon Sep 17 00:00:00 2001 From: myk002 Date: Wed, 1 Sep 2021 13:04:13 -0700 Subject: [PATCH 1/4] update changelog --- docs/changelog.txt | 1 + 1 file changed, 1 insertion(+) diff --git a/docs/changelog.txt b/docs/changelog.txt index 225eddd75..28475eae8 100644 --- a/docs/changelog.txt +++ b/docs/changelog.txt @@ -45,6 +45,7 @@ changelog.txt uses a syntax similar to RST, with a few special sequences: ## Misc Improvements - `buildingplan`: now displays which items are attached and which items are still missing for planned buildings - `orders`: support importing and exporting reaction-specific item conditions, like "lye-containing" for soap production orders +- `orders`: new ``sort`` command. sorts orders according to their repeat frequency. this prevents daily orders from blocking other orders for simlar items from ever getting completed. - `tiletypes-here`, `tiletypes-here-point`: add ``--cursor`` and ``--quiet`` options to support non-interactive use cases - `quickfort`: Dreamfort blueprint set improvements: extensive revision based on playtesting and feedback. includes updated ``onMapLoad_dreamfort.init`` settings file, enhanced automation orders, and premade profession definitions. see full changelog at https://github.com/DFHack/dfhack/pull/1921 and https://github.com/DFHack/dfhack/pull/1925 From f21ba5c8aa92f73c73405f7599011ff60acf2533 Mon Sep 17 00:00:00 2001 From: myk002 Date: Wed, 1 Sep 2021 13:04:23 -0700 Subject: [PATCH 2/4] implement orders sort, document, and add to init --- data/examples/init/onMapLoad_dreamfort.init | 1 + docs/Plugins.rst | 8 ++++++ plugins/orders.cpp | 28 +++++++++++++++++++++ 3 files changed, 37 insertions(+) diff --git a/data/examples/init/onMapLoad_dreamfort.init b/data/examples/init/onMapLoad_dreamfort.init index 7bd280357..4b64925ea 100644 --- a/data/examples/init/onMapLoad_dreamfort.init +++ b/data/examples/init/onMapLoad_dreamfort.init @@ -17,6 +17,7 @@ repeat -name feeding-timers -time 1 -timeUnits months -command [ fix/feeding-tim repeat -name stuckdoors -time 1 -timeUnits months -command [ fix/stuckdoors ] repeat -name autoShearCreature -time 14 -timeUnits days -command [ workorder ShearCreature ] repeat -name autoMilkCreature -time 14 -timeUnits days -command [ workorder "{\"job\":\"MilkCreature\",\"item_conditions\":[{\"condition\":\"AtLeast\",\"value\":2,\"flags\":[\"empty\"],\"item_type\":\"BUCKET\"}]}" ] +repeat -name orders-sort -time 1 -timeUnits days -command [ orders sort ] tweak fast-heat 100 tweak do-job-now diff --git a/docs/Plugins.rst b/docs/Plugins.rst index eb1ca6f1b..d80216396 100644 --- a/docs/Plugins.rst +++ b/docs/Plugins.rst @@ -1968,6 +1968,14 @@ Subcommands: :export NAME: Exports the current list of manager orders to a file named ``dfhack-config/orders/NAME.json``. :import NAME: Imports manager orders from a file named ``dfhack-config/orders/NAME.json``. :clear: Deletes all manager orders in the current embark. +:sort: Sorts current manager orders by repeat frequency so daily orders don't + prevent other orders from ever being completed: one-time orders first, then + yearly, seasonally, monthly, then finally daily. + +You can keep your orders automatically sorted by adding the following command to +your ``onMapLoad.init`` file:: + + repeat -name orders-sort -time 1 -timeUnits days -command [ orders sort ] .. _nestboxes: diff --git a/plugins/orders.cpp b/plugins/orders.cpp index 2a90e7e69..81e6f1c5d 100644 --- a/plugins/orders.cpp +++ b/plugins/orders.cpp @@ -56,6 +56,8 @@ DFhackCExport command_result plugin_init(color_ostream & out, std::vector & parameters) { @@ -100,6 +103,11 @@ static command_result orders_command(color_ostream & out, std::vectorfrequency == df::manager_order::T_frequency::OneTime + || b->frequency == df::manager_order::T_frequency::OneTime) + return a->frequency < b->frequency; + return a->frequency > b->frequency; +} + +static command_result orders_sort_command(color_ostream & out) +{ + CoreSuspender suspend; + + std::stable_sort(world->manager_orders.begin(), world->manager_orders.end(), + compare_freq); + + out << "Sorted " << world->manager_orders.size() << " manager orders." << std::endl; + + return CR_OK; +} From 2249b42506326a977e649633b46fe93a2769127e Mon Sep 17 00:00:00 2001 From: myk002 Date: Wed, 1 Sep 2021 13:06:07 -0700 Subject: [PATCH 3/4] update examples docs --- docs/guides/examples-guide.rst | 2 ++ 1 file changed, 2 insertions(+) diff --git a/docs/guides/examples-guide.rst b/docs/guides/examples-guide.rst index 1f8930212..2eba5ea3a 100644 --- a/docs/guides/examples-guide.rst +++ b/docs/guides/examples-guide.rst @@ -29,6 +29,8 @@ it is useful (and customizable) for any fort. It includes the following config: started, so later manual changes will not be overridden. - Automates calling of various fort maintenance and `scripts-fix`, like `cleanowned` and `fix/stuckdoors`. +- Keeps your manager orders intelligently ordered with `orders` ``sort`` so no + orders block other orders from ever getting completed. - Periodically enqueues orders to shear and milk shearable and milkable pets. - Sets up `autofarm` to grow 30 units of every crop, except for pig tails, which is set to 150 units to support the textile industry. From bd0a2e38770eb74ac968f4d0b48f3d1d1dffb6be Mon Sep 17 00:00:00 2001 From: myk002 Date: Wed, 1 Sep 2021 16:52:11 -0700 Subject: [PATCH 4/4] only output when changes are made avoids spamming the console when `orders sort` is run on repeat --- plugins/orders.cpp | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/plugins/orders.cpp b/plugins/orders.cpp index 81e6f1c5d..fca55713e 100644 --- a/plugins/orders.cpp +++ b/plugins/orders.cpp @@ -945,10 +945,15 @@ static command_result orders_sort_command(color_ostream & out) { CoreSuspender suspend; - std::stable_sort(world->manager_orders.begin(), world->manager_orders.end(), - compare_freq); - - out << "Sorted " << world->manager_orders.size() << " manager orders." << std::endl; + if (!std::is_sorted(world->manager_orders.begin(), + world->manager_orders.end(), + compare_freq)) + { + std::stable_sort(world->manager_orders.begin(), + world->manager_orders.end(), + compare_freq); + out << "Fixed priority of manager orders." << std::endl; + } return CR_OK; }