Now accepts the new enable/disable commands.

develop
Eric Wald 2014-04-18 21:58:20 -06:00
parent 3288ab8895
commit 5fb87c2ea9
1 changed files with 30 additions and 3 deletions

@ -1,7 +1,7 @@
/* /*
* Stockflow plugin. * Stockflow plugin.
* For best effect, place "stockflow enable" in your dfhack.init configuration, * 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" #include "uicommon.h"
@ -24,7 +24,13 @@ using df::building_stockpilest;
DFHACK_PLUGIN("stockflow"); DFHACK_PLUGIN("stockflow");
#define AUTOENABLE false
#ifdef DFHACK_PLUGIN_IS_ENABLED
DFHACK_PLUGIN_IS_ENABLED(enabled);
#else
bool enabled = false; bool enabled = false;
#endif
const char *tagline = "Allows the fortress bookkeeper to queue jobs through the manager."; const char *tagline = "Allows the fortress bookkeeper to queue jobs through the manager.";
const char *usage = ( const char *usage = (
" stockflow enable\n" " stockflow enable\n"
@ -371,13 +377,34 @@ DFhackCExport command_result plugin_onstatechange(color_ostream &out, state_chan
return CR_OK; 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 <PluginCommand> &commands) { DFhackCExport command_result plugin_init(color_ostream &out, std::vector <PluginCommand> &commands) {
helper.init(); 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)); commands.push_back(PluginCommand(name, tagline, stockflow_cmd, false, usage));
return CR_OK; return CR_OK;
} }
DFhackCExport command_result plugin_shutdown(color_ostream &out) { DFhackCExport command_result plugin_shutdown(color_ostream &out) {
return CR_OK; return plugin_enable(out, false);
} }