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; +}