From 26f6820198eb42abf821c27723b7201eb5471f65 Mon Sep 17 00:00:00 2001 From: John Cosker Date: Sun, 29 Jan 2023 18:16:26 -0500 Subject: [PATCH] Address review comments, hopefully fix linux build --- docs/plugins/autoslab.rst | 4 ++-- plugins/autoslab.cpp | 35 ++++++----------------------------- 2 files changed, 8 insertions(+), 31 deletions(-) diff --git a/docs/plugins/autoslab.rst b/docs/plugins/autoslab.rst index e5db146cb..5e61e0938 100644 --- a/docs/plugins/autoslab.rst +++ b/docs/plugins/autoslab.rst @@ -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 diff --git a/plugins/autoslab.cpp b/plugins/autoslab.cpp index 5f7f25f6f..4e9220cf2 100644 --- a/plugins/autoslab.cpp +++ b/plugins/autoslab.cpp @@ -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 ¶meters); - 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 ¶meters); static void do_cycle(color_ostream &out); DFhackCExport command_result plugin_init(color_ostream &out, std::vector &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 ¶meters) -{ - // 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 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)