Document dwarfmonitor and allow date format to be modified

develop
lethosor 2015-04-19 12:38:37 -04:00
parent a4a2b2f1de
commit a1fd1d9219
5 changed files with 81 additions and 5 deletions

@ -10,6 +10,7 @@ DFHack Future
view-item-info: adds information and customisable descriptions to item viewscreens
New tweaks
New features
dwarfmonitor date format can be modified (see Readme)
Fixes
steam-engine: fixed a crash on arena load
Plugins with vmethod hooks can now be reloaded on OS X

@ -1685,6 +1685,34 @@ Maintain 10-100 locally-made crafts of exceptional quality::
Fortress activity management
============================
dwarfmonitor
------------
Records dwarf activity to measure fort efficiency.
Options:
``dwarfmonitor enable <mode>``:
Start monitoring ``mode``. ``mode`` can be "work", "misery", or "all".
``dwarfmonitor disable <mode>``:
Stop monitoring ``mode`` (see above)
``dwarfmonitor stats``:
Show statistics summary
``dwarfmonitor prefs``:
Show dwarf preferences summary
``dwarfmonitor reload``:
Reload configuration file (``hack/config/dwarfmonitor.json``)
Configuration options:
``date_format``:
Date format
Example configuration::
{
"date_format": "y-m-d"
}
seedwatch
---------
Watches the numbers of seeds available and enables/disables seed and plant cooking.

@ -112,7 +112,7 @@ if (BUILD_SUPPORTED)
DFHACK_PLUGIN(digFlood digFlood.cpp)
add_subdirectory(diggingInvaders)
DFHACK_PLUGIN(drybuckets drybuckets.cpp)
DFHACK_PLUGIN(dwarfmonitor dwarfmonitor.cpp)
DFHACK_PLUGIN(dwarfmonitor dwarfmonitor.cpp LINK_LIBRARIES jsonxx)
DFHACK_PLUGIN(embark-tools embark-tools.cpp)
DFHACK_PLUGIN(eventful eventful.cpp LINK_LIBRARIES lua)
DFHACK_PLUGIN(fastdwarf fastdwarf.cpp)

@ -41,6 +41,8 @@
#include "df/descriptor_shape.h"
#include "df/descriptor_color.h"
#include "jsonxx.h"
using std::deque;
DFHACK_PLUGIN("dwarfmonitor");
@ -67,6 +69,11 @@ struct less_second {
}
};
struct dwarfmonitor_configst {
std::string date_format;
};
static dwarfmonitor_configst dwarfmonitor_config;
static bool monitor_jobs = false;
static bool monitor_misery = true;
static bool monitor_date = true;
@ -1720,9 +1727,29 @@ struct dwarf_monitor_hook : public df::viewscreen_dwarfmodest
ostringstream date_str;
auto month = World::ReadCurrentMonth() + 1;
auto day = World::ReadCurrentDay();
date_str << "Date:" << World::ReadCurrentYear() << "-" <<
((month < 10) ? "0" : "") << month << "-" <<
((day < 10) ? "0" : "") << day;
date_str << "Date:";
for (size_t i = 0; i < dwarfmonitor_config.date_format.size(); i++)
{
char c = dwarfmonitor_config.date_format[i];
switch (c)
{
case 'Y':
case 'y':
date_str << World::ReadCurrentYear();
break;
case 'M':
case 'm':
date_str << ((month < 10) ? "0" : "") << month;
break;
case 'D':
case 'd':
date_str << ((day < 10) ? "0" : "") << day;
break;
default:
date_str << c;
break;
}
}
OutputString(COLOR_GREY, x, y, date_str.str());
@ -1819,6 +1846,19 @@ DFhackCExport command_result plugin_enable(color_ostream &out, bool enable)
return CR_OK;
}
static bool load_config (color_ostream &out)
{
jsonxx::Object o;
std::ifstream infile("hack/config/dwarfmonitor.json");
if (infile.good())
{
std::string contents((std::istreambuf_iterator<char>(infile)), (std::istreambuf_iterator<char>()));
if (!o.parse(contents))
out.printerr("dwarfmonitor: invalid JSON\n");
}
dwarfmonitor_config.date_format = o.get<jsonxx::String>("date_format", "y-m-d");
}
static command_result dwarfmonitor_cmd(color_ostream &out, vector <string> & parameters)
{
bool show_help = false;
@ -1869,6 +1909,10 @@ static command_result dwarfmonitor_cmd(color_ostream &out, vector <string> & par
if(Maps::IsValid())
Screen::show(new ViewscreenPreferences());
}
else if (cmd == 'r' || cmd == 'R')
{
load_config(out);
}
else
{
show_help = true;
@ -1883,6 +1927,7 @@ static command_result dwarfmonitor_cmd(color_ostream &out, vector <string> & par
DFhackCExport command_result plugin_init(color_ostream &out, std::vector <PluginCommand> &commands)
{
load_config(out);
activity_labels[JOB_IDLE] = "Idle";
activity_labels[JOB_MILITARY] = "Military Duty";
activity_labels[JOB_LEISURE] = "Leisure";
@ -1914,6 +1959,8 @@ DFhackCExport command_result plugin_init(color_ostream &out, std::vector <Plugin
" Show statistics summary\n"
"dwarfmonitor prefs\n"
" Show dwarf preferences summary\n\n"
"dwarfmonitor reload\n"
" Reload configuration file (hack/config/dwarfmonitor.json)\n"
));
return CR_OK;