Address review comments, hopefully fix linux build

develop
John Cosker 2023-01-29 18:16:26 -05:00
parent 1bc9c41762
commit 26f6820198
2 changed files with 8 additions and 31 deletions

@ -2,8 +2,8 @@ autoslab
========
.. dfhack-tool::
:summary: Automatically engrave slabs for ghostly citizens!
:tags: untested fort auto workorders
:summary: Automatically engrave slabs for ghostly citizens.
:tags: fort auto workorders
:no-command:
Automatically queue orders to engrave slabs of existing ghosts. Will only queue

@ -5,7 +5,8 @@
* Enhancement idea: Automatically place the slab. This seems like a tricky problem but maybe solveable with named zones?
* Might be made obsolete by people just using buildingplan to pre-place plans for slab?
* Enhancement idea: Optionally enable autoengraving for pets.
* Enhancement idea: Try to get ahead of ghosts by autoengraving for dead dwarves with no remains.
* Enhancement idea: Try to get ahead of ghosts by autoengraving for dead dwarves with no remains, or dwarves
* whose remains are unreachable.
*/
#include "Core.h"
@ -25,8 +26,6 @@
using namespace DFHack;
static command_result autoslab(color_ostream &out, std::vector<std::string> &parameters);
DFHACK_PLUGIN("autoslab");
DFHACK_PLUGIN_IS_ENABLED(is_enabled);
@ -70,19 +69,12 @@ static void set_config_bool(int index, bool value)
static int32_t cycle_timestamp = 0; // world->frame_counter at last cycle
static command_result do_command(color_ostream &out, std::vector<std::string> &parameters);
static void do_cycle(color_ostream &out);
DFhackCExport command_result plugin_init(color_ostream &out, std::vector<PluginCommand> &commands)
{
DEBUG(status, out).print("initializing %s\n", plugin_name);
// provide a configuration interface for the plugin
commands.push_back(PluginCommand(
plugin_name,
"Automatically engrave slabs of ghostly citizens!",
do_command));
return CR_OK;
}
@ -123,7 +115,6 @@ DFhackCExport command_result plugin_load_data(color_ostream &out)
DEBUG(status, out).print("no config found in this save; initializing\n");
config = World::AddPersistentData(CONFIG_KEY);
set_config_bool(CONFIG_IS_ENABLED, is_enabled);
set_config_val(CONFIG_CYCLE_TICKS, 1200);
}
// we have to copy our enabled flag into the global plugin variable, but
@ -147,30 +138,16 @@ DFhackCExport command_result plugin_onstatechange(color_ostream &out, state_chan
return CR_OK;
}
static const int32_t CYCLE_TICKS = 1200;
DFhackCExport command_result plugin_onupdate(color_ostream &out)
{
CoreSuspender suspend;
if (is_enabled && world->frame_counter - cycle_timestamp >= get_config_val(CONFIG_CYCLE_TICKS))
if (is_enabled && world->frame_counter - cycle_timestamp >= CYCLE_TICKS)
do_cycle(out);
return CR_OK;
}
static command_result do_command(color_ostream &out, std::vector<std::string> &parameters)
{
// be sure to suspend the core if any DF state is read or modified
CoreSuspender suspend;
if (!Core::getInstance().isWorldLoaded())
{
out.printerr("Cannot run %s without a loaded world.\n", plugin_name);
return CR_FAILURE;
}
// TODO: decide what, if any configuration should be here
return CR_OK;
}
// Name functions taken from manipulator.cpp
static std::string get_first_name(df::unit *unit)
{
@ -243,7 +220,7 @@ static void checkslabs(color_ostream &out)
std::vector<df::unit *> ghosts;
std::copy_if(world->units.all.begin(), world->units.all.end(),
std::back_inserter(ghosts),
[](const auto &unit)
[](const df::unit *unit)
{ return unit->flags3.bits.ghostly; });
for (auto ghost : ghosts)