From 5fb87c2ea941a8517763ee5cce708afd4d836704 Mon Sep 17 00:00:00 2001 From: Eric Wald Date: Fri, 18 Apr 2014 21:58:20 -0600 Subject: [PATCH] Now accepts the new enable/disable commands. --- plugins/stockflow.cpp | 33 ++++++++++++++++++++++++++++++--- 1 file changed, 30 insertions(+), 3 deletions(-) diff --git a/plugins/stockflow.cpp b/plugins/stockflow.cpp index 72e804507..b96faa47f 100644 --- a/plugins/stockflow.cpp +++ b/plugins/stockflow.cpp @@ -1,7 +1,7 @@ /* * Stockflow plugin. * For best effect, place "stockflow enable" in your dfhack.init configuration, - * or set `enabled` to true by default. + * or set AUTOENABLE to true. */ #include "uicommon.h" @@ -24,7 +24,13 @@ using df::building_stockpilest; DFHACK_PLUGIN("stockflow"); +#define AUTOENABLE false +#ifdef DFHACK_PLUGIN_IS_ENABLED +DFHACK_PLUGIN_IS_ENABLED(enabled); +#else bool enabled = false; +#endif + const char *tagline = "Allows the fortress bookkeeper to queue jobs through the manager."; const char *usage = ( " stockflow enable\n" @@ -371,13 +377,34 @@ DFhackCExport command_result plugin_onstatechange(color_ostream &out, state_chan return CR_OK; } +DFhackCExport command_result plugin_enable(color_ostream& out, bool enable) { + /* Accept the "enable stockflow"/"disable stockflow" syntax, where available. */ + /* Same as "stockflow enable"/"stockflow disable" except without the status line. */ + if (enable != enabled) { + if (!apply_hooks(out, enable)) { + return CR_FAILURE; + } + + enabled = enable; + } + + return CR_OK; +} + DFhackCExport command_result plugin_init(color_ostream &out, std::vector &commands) { helper.init(); - if (enabled) apply_hooks(out, true); + if (AUTOENABLE) { + if (!apply_hooks(out, true)) { + return CR_FAILURE; + } + + enabled = true; + } + commands.push_back(PluginCommand(name, tagline, stockflow_cmd, false, usage)); return CR_OK; } DFhackCExport command_result plugin_shutdown(color_ostream &out) { - return CR_OK; + return plugin_enable(out, false); }