Skip to content

Commit 9246ac9

Browse files
committed
Merge branch 'workNow' into recent
2 parents cf3ac48 + 5fc466e commit 9246ac9

2 files changed

Lines changed: 71 additions & 0 deletions

File tree

plugins/CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -131,6 +131,7 @@ if (BUILD_SUPPORTED)
131131
# not yet. busy with other crud again...
132132
#DFHACK_PLUGIN(versionosd versionosd.cpp)
133133
DFHACK_PLUGIN(misery misery.cpp)
134+
DFHACK_PLUGIN(workNow workNow.cpp)
134135
#DFHACK_PLUGIN(dfstream dfstream.cpp LINK_LIBRARIES clsocket dfhack-tinythread)
135136
DFHACK_PLUGIN(autoSyndrome autoSyndrome.cpp)
136137
DFHACK_PLUGIN(trueTransformation trueTransformation.cpp)

plugins/workNow.cpp

Lines changed: 70 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,70 @@
1+
#include "Core.h"
2+
#include "Console.h"
3+
#include "Export.h"
4+
#include "PluginManager.h"
5+
#include "DataDefs.h"
6+
#include "modules/World.h"
7+
#include "df/global_objects.h"
8+
9+
#include <vector>
10+
using namespace std;
11+
using namespace DFHack;
12+
13+
DFHACK_PLUGIN("workNow");
14+
15+
static bool active = false;
16+
17+
DFhackCExport command_result workNow(color_ostream& out, vector<string>& parameters);
18+
19+
DFhackCExport command_result plugin_init(color_ostream& out, std::vector<PluginCommand> &commands) {
20+
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"
21+
"workNow 1\n"
22+
" activate workNow\n"
23+
"workNow 0\n"
24+
" deactivate workNow\n"));
25+
26+
return CR_OK;
27+
}
28+
29+
DFhackCExport command_result plugin_shutdown ( color_ostream &out ) {
30+
active = false;
31+
return CR_OK;
32+
}
33+
34+
DFhackCExport command_result plugin_onstatechange(color_ostream &out, state_change_event e) {
35+
if ( !active )
36+
return CR_OK;
37+
if ( e == DFHack::SC_WORLD_UNLOADED ) {
38+
active = false;
39+
return CR_OK;
40+
}
41+
if ( e != DFHack::SC_PAUSED )
42+
return CR_OK;
43+
44+
*df::global::process_jobs = true;
45+
*df::global::process_dig = true;
46+
47+
return CR_OK;
48+
}
49+
50+
51+
52+
DFhackCExport command_result workNow(color_ostream& out, vector<string>& parameters) {
53+
if ( parameters.size() == 0 ) {
54+
out.print("workNow status = %s\n", active ? "active" : "inactive");
55+
return CR_OK;
56+
}
57+
if ( parameters.size() > 1 ) {
58+
return CR_WRONG_USAGE;
59+
}
60+
int32_t a = atoi(parameters[0].c_str());
61+
62+
if (a < 0 || a > 1)
63+
return CR_WRONG_USAGE;
64+
65+
active = (bool)a;
66+
67+
return CR_OK;
68+
}
69+
70+

0 commit comments

Comments
 (0)