Made workNow only check jobs when the game becomes paused instead of constantly when paused. Also made it enable/disable on command.

develop
expwnent 2012-12-08 12:50:33 -05:00
parent fe2257427f
commit 72921fbfd5
2 changed files with 36 additions and 9 deletions

@ -127,6 +127,7 @@ if (BUILD_SUPPORTED)
# not yet. busy with other crud again... # not yet. busy with other crud again...
#DFHACK_PLUGIN(versionosd versionosd.cpp) #DFHACK_PLUGIN(versionosd versionosd.cpp)
DFHACK_PLUGIN(misery misery.cpp) DFHACK_PLUGIN(misery misery.cpp)
DFHACK_PLUGIN(workNow workNow.cpp)
endif() endif()

@ -8,34 +8,60 @@
#include <vector> #include <vector>
using namespace std; using namespace std;
using namespace DFHack; using namespace DFHack;
DFHACK_PLUGIN("workNow"); DFHACK_PLUGIN("workNow");
static bool active = false; static bool active = false;
DFhackCExport command_result workNow(color_ostream& out, vector<string>& parameters);
DFhackCExport command_result plugin_init(color_ostream& out, std::vector<PluginCommand> &commands) {
commands.push_back(PluginCommand("workNow", "makes dwarves look for jobs every time you pause", workNow, false, "When workNow is active, every time the game pauses, DF will make dwarves perform any appropriate available jobs. This includes when you one step through the game using the pause menu.\n"
"workNow 1\n"
" activate workNow\n"
"workNow 0\n"
" deactivate workNow\n"));
return CR_OK;
}
DFhackCExport command_result plugin_shutdown ( color_ostream &out ) { DFhackCExport command_result plugin_shutdown ( color_ostream &out ) {
active = false;
return CR_OK; return CR_OK;
} }
DFhackCExport command_result plugin_onupdate ( color_ostream &out ) { DFhackCExport command_result plugin_onstatechange(color_ostream &out, state_change_event e) {
if ( !DFHack::Core::getInstance().getWorld()->ReadPauseState() ) if ( !active )
return CR_OK;
if ( e == DFHack::SC_WORLD_UNLOADED ) {
active = false;
return CR_OK;
}
if ( e != DFHack::SC_PAUSED )
return CR_OK; return CR_OK;
*df::global::process_jobs = true; *df::global::process_jobs = true;
return CR_OK; return CR_OK;
} }
DFhackCExport command_result workNow(color_ostream& out, vector<string>& parameters);
DFhackCExport command_result plugin_init(color_ostream& out, std::vector<PluginCommand> &commands) {
commands.push_back(PluginCommand("workNow", "makes dwarves look for jobs every time you pause", workNow, false, "Full help."));
return CR_OK;
}
DFhackCExport command_result workNow(color_ostream& out, vector<string>& parameters) { DFhackCExport command_result workNow(color_ostream& out, vector<string>& parameters) {
if ( parameters.size() == 0 ) {
out.print("workNow status = %s\n", active ? "active" : "inactive");
return CR_OK;
}
if ( parameters.size() > 1 ) {
return CR_WRONG_USAGE;
}
int32_t a = atoi(parameters[0].c_str());
if (a < 0 || a > 1)
return CR_WRONG_USAGE;
active = (bool)a;
return CR_OK; return CR_OK;
} }