commit
e4711801f3
@ -0,0 +1,19 @@
|
|||||||
|
.. _worknow:
|
||||||
|
|
||||||
|
work-now
|
||||||
|
========
|
||||||
|
|
||||||
|
.. dfhack-tool::
|
||||||
|
:summary: Reduce the time that dwarves idle after completing a job.
|
||||||
|
:tags: fort auto jobs
|
||||||
|
|
||||||
|
After finishing a job, dwarves will wander away for a while before picking up a
|
||||||
|
new job. This plugin will automatically poke them to pick up a new task quicker.
|
||||||
|
|
||||||
|
Usage
|
||||||
|
-----
|
||||||
|
|
||||||
|
::
|
||||||
|
|
||||||
|
enable work-now
|
||||||
|
work-now [status]
|
@ -1,22 +0,0 @@
|
|||||||
workNow
|
|
||||||
=======
|
|
||||||
|
|
||||||
.. dfhack-tool::
|
|
||||||
:summary: Reduce the time that dwarves idle after completing a job.
|
|
||||||
:tags: unavailable fort auto labors
|
|
||||||
|
|
||||||
After finishing a job, dwarves will wander away for a while before picking up a
|
|
||||||
new job. This plugin will automatically poke the game to assign dwarves to new
|
|
||||||
tasks.
|
|
||||||
|
|
||||||
Usage
|
|
||||||
-----
|
|
||||||
|
|
||||||
``workNow``
|
|
||||||
Print current plugin status.
|
|
||||||
``workNow 0``
|
|
||||||
Stop monitoring and poking.
|
|
||||||
``workNow 1``
|
|
||||||
Poke the game to assign dwarves to tasks whenever the game is paused.
|
|
||||||
``workNow 2``
|
|
||||||
Poke the game to assign dwarves to tasks whenever a dwarf finishes a job.
|
|
@ -0,0 +1,74 @@
|
|||||||
|
#include "Debug.h"
|
||||||
|
#include "PluginManager.h"
|
||||||
|
|
||||||
|
#include "modules/EventManager.h"
|
||||||
|
|
||||||
|
using std::string;
|
||||||
|
using std::vector;
|
||||||
|
using namespace DFHack;
|
||||||
|
|
||||||
|
DFHACK_PLUGIN("work-now");
|
||||||
|
DFHACK_PLUGIN_IS_ENABLED(is_enabled);
|
||||||
|
REQUIRE_GLOBAL(process_jobs);
|
||||||
|
REQUIRE_GLOBAL(process_dig);
|
||||||
|
|
||||||
|
namespace DFHack {
|
||||||
|
DBG_DECLARE(worknow, log, DebugCategory::LINFO);
|
||||||
|
}
|
||||||
|
|
||||||
|
DFhackCExport command_result work_now(color_ostream& out, vector<string>& parameters);
|
||||||
|
|
||||||
|
static void jobCompletedHandler(color_ostream& out, void* ptr);
|
||||||
|
EventManager::EventHandler handler(jobCompletedHandler,1);
|
||||||
|
|
||||||
|
DFhackCExport command_result plugin_init(color_ostream& out, std::vector<PluginCommand> &commands) {
|
||||||
|
commands.push_back(PluginCommand(
|
||||||
|
"work-now",
|
||||||
|
"Reduce the time that dwarves idle after completing a job.",
|
||||||
|
work_now));
|
||||||
|
|
||||||
|
return CR_OK;
|
||||||
|
}
|
||||||
|
|
||||||
|
DFhackCExport command_result plugin_enable(color_ostream &out, bool enable) {
|
||||||
|
if (enable != is_enabled)
|
||||||
|
{
|
||||||
|
if (enable)
|
||||||
|
EventManager::registerListener(EventManager::EventType::JOB_COMPLETED, handler, plugin_self);
|
||||||
|
else
|
||||||
|
EventManager::unregister(EventManager::EventType::JOB_COMPLETED, handler, plugin_self);
|
||||||
|
|
||||||
|
is_enabled = enable;
|
||||||
|
}
|
||||||
|
|
||||||
|
return CR_OK;
|
||||||
|
}
|
||||||
|
|
||||||
|
DFhackCExport command_result plugin_shutdown ( color_ostream &out ) {
|
||||||
|
return plugin_enable(out, false);
|
||||||
|
}
|
||||||
|
|
||||||
|
DFhackCExport command_result plugin_onstatechange(color_ostream &out, state_change_event e) {
|
||||||
|
if (e == SC_PAUSED) {
|
||||||
|
DEBUG(log,out).print("game paused; poking idlers\n");
|
||||||
|
*process_jobs = true;
|
||||||
|
*process_dig = true;
|
||||||
|
}
|
||||||
|
|
||||||
|
return CR_OK;
|
||||||
|
}
|
||||||
|
|
||||||
|
DFhackCExport command_result work_now(color_ostream& out, vector<string>& parameters) {
|
||||||
|
if (parameters.empty() || parameters[0] == "status") {
|
||||||
|
out.print("work_now is %sactively poking idle dwarves.\n", is_enabled ? "" : "not ");
|
||||||
|
return CR_OK;
|
||||||
|
}
|
||||||
|
|
||||||
|
return CR_WRONG_USAGE;
|
||||||
|
}
|
||||||
|
|
||||||
|
static void jobCompletedHandler(color_ostream& out, void* ptr) {
|
||||||
|
DEBUG(log,out).print("job completed; poking idlers\n");
|
||||||
|
*process_jobs = true;
|
||||||
|
*process_dig = true;
|
||||||
|
}
|
@ -1,92 +0,0 @@
|
|||||||
#include "Core.h"
|
|
||||||
#include "Console.h"
|
|
||||||
#include "Export.h"
|
|
||||||
#include "PluginManager.h"
|
|
||||||
#include "DataDefs.h"
|
|
||||||
|
|
||||||
#include "modules/EventManager.h"
|
|
||||||
#include "modules/World.h"
|
|
||||||
|
|
||||||
#include "df/global_objects.h"
|
|
||||||
|
|
||||||
#include <vector>
|
|
||||||
|
|
||||||
using namespace std;
|
|
||||||
using namespace DFHack;
|
|
||||||
|
|
||||||
DFHACK_PLUGIN("workNow");
|
|
||||||
REQUIRE_GLOBAL(process_jobs);
|
|
||||||
REQUIRE_GLOBAL(process_dig);
|
|
||||||
|
|
||||||
static int mode = 0;
|
|
||||||
|
|
||||||
DFhackCExport command_result workNow(color_ostream& out, vector<string>& parameters);
|
|
||||||
|
|
||||||
void jobCompletedHandler(color_ostream& out, void* ptr);
|
|
||||||
EventManager::EventHandler handler(jobCompletedHandler,1);
|
|
||||||
|
|
||||||
DFhackCExport command_result plugin_init(color_ostream& out, std::vector<PluginCommand> &commands) {
|
|
||||||
if (!process_jobs || !process_dig)
|
|
||||||
return CR_FAILURE;
|
|
||||||
|
|
||||||
commands.push_back(PluginCommand(
|
|
||||||
"workNow",
|
|
||||||
"Reduce the time that dwarves idle after completing a job.",
|
|
||||||
workNow));
|
|
||||||
|
|
||||||
return CR_OK;
|
|
||||||
}
|
|
||||||
|
|
||||||
DFhackCExport command_result plugin_shutdown ( color_ostream &out ) {
|
|
||||||
mode = 0;
|
|
||||||
return CR_OK;
|
|
||||||
}
|
|
||||||
|
|
||||||
DFhackCExport command_result plugin_onstatechange(color_ostream &out, state_change_event e) {
|
|
||||||
if ( !mode )
|
|
||||||
return CR_OK;
|
|
||||||
if ( e == DFHack::SC_WORLD_UNLOADED ) {
|
|
||||||
mode = 0;
|
|
||||||
return CR_OK;
|
|
||||||
}
|
|
||||||
if ( e != DFHack::SC_PAUSED )
|
|
||||||
return CR_OK;
|
|
||||||
|
|
||||||
*process_jobs = true;
|
|
||||||
*process_dig = true;
|
|
||||||
|
|
||||||
return CR_OK;
|
|
||||||
}
|
|
||||||
|
|
||||||
DFhackCExport command_result workNow(color_ostream& out, vector<string>& parameters) {
|
|
||||||
if ( parameters.size() == 0 ) {
|
|
||||||
out.print("workNow status = %d\n", mode);
|
|
||||||
return CR_OK;
|
|
||||||
}
|
|
||||||
if ( parameters.size() > 1 ) {
|
|
||||||
return CR_WRONG_USAGE;
|
|
||||||
}
|
|
||||||
int32_t a = atoi(parameters[0].c_str());
|
|
||||||
|
|
||||||
if (a < 0 || a > 2)
|
|
||||||
return CR_WRONG_USAGE;
|
|
||||||
|
|
||||||
if ( a == 2 && mode != 2 ) {
|
|
||||||
EventManager::registerListener(EventManager::EventType::JOB_COMPLETED, handler, plugin_self);
|
|
||||||
} else if ( mode == 2 && a != 2 ) {
|
|
||||||
EventManager::unregister(EventManager::EventType::JOB_COMPLETED, handler, plugin_self);
|
|
||||||
}
|
|
||||||
|
|
||||||
mode = a;
|
|
||||||
out.print("workNow status = %d\n", mode);
|
|
||||||
|
|
||||||
return CR_OK;
|
|
||||||
}
|
|
||||||
|
|
||||||
void jobCompletedHandler(color_ostream& out, void* ptr) {
|
|
||||||
if ( mode < 2 )
|
|
||||||
return;
|
|
||||||
|
|
||||||
*process_jobs = true;
|
|
||||||
*process_dig = true;
|
|
||||||
}
|
|
Loading…
Reference in New Issue