diff --git a/docs/changelog.txt b/docs/changelog.txt index 0670232a5..85e94786f 100644 --- a/docs/changelog.txt +++ b/docs/changelog.txt @@ -61,6 +61,7 @@ Template for new versions: ## Misc Improvements - wherever units are listed in DFHack tools, properties like "agitated" or (-trained-) are now shown +- `work-now`: now saves its enabled status with the fort ## Documentation diff --git a/plugins/work-now.cpp b/plugins/work-now.cpp index bce2d9a73..ab6bd3b7d 100644 --- a/plugins/work-now.cpp +++ b/plugins/work-now.cpp @@ -2,6 +2,8 @@ #include "PluginManager.h" #include "modules/EventManager.h" +#include "modules/Persistence.h" +#include "modules/World.h" using std::string; using std::vector; @@ -9,6 +11,7 @@ using namespace DFHack; DFHACK_PLUGIN("work-now"); DFHACK_PLUGIN_IS_ENABLED(is_enabled); + REQUIRE_GLOBAL(process_jobs); REQUIRE_GLOBAL(process_dig); @@ -16,7 +19,30 @@ namespace DFHack { DBG_DECLARE(worknow, log, DebugCategory::LINFO); } -DFhackCExport command_result work_now(color_ostream& out, vector& parameters); +static const string CONFIG_KEY = string(plugin_name) + "/config"; +static PersistentDataItem config; + +enum ConfigValues { + CONFIG_IS_ENABLED = 0, +}; + +static int get_config_val(PersistentDataItem &c, int index) { + if (!c.isValid()) + return -1; + return c.ival(index); +} +static bool get_config_bool(PersistentDataItem &c, int index) { + return get_config_val(c, index) == 1; +} +static void set_config_val(PersistentDataItem &c, int index, int value) { + if (c.isValid()) + c.ival(index) = value; +} +static void set_config_bool(PersistentDataItem &c, int index, bool value) { + set_config_val(c, index, value ? 1 : 0); +} + +static command_result work_now(color_ostream& out, vector& parameters); static void jobCompletedHandler(color_ostream& out, void* ptr); EventManager::EventHandler handler(jobCompletedHandler,1); @@ -30,35 +56,76 @@ DFhackCExport command_result plugin_init(color_ostream& out, std::vector& parameters) { +static command_result work_now(color_ostream& out, vector& parameters) { if (parameters.empty() || parameters[0] == "status") { out.print("work_now is %sactively poking idle dwarves.\n", is_enabled ? "" : "not "); return CR_OK; @@ -69,6 +136,5 @@ DFhackCExport command_result work_now(color_ostream& out, vector& parame static void jobCompletedHandler(color_ostream& out, void* ptr) { DEBUG(log,out).print("job completed; poking idlers\n"); - *process_jobs = true; - *process_dig = true; + poke_idlers(); }