From dbe2de660747ca4eae679a2bfcf5d51d209af9e2 Mon Sep 17 00:00:00 2001 From: Myk Taylor Date: Tue, 2 Jan 2024 01:31:08 -0800 Subject: [PATCH 1/2] remove ticks config, document "now" command, run cycle on autowatch enable --- docs/plugins/autobutcher.rst | 24 +++++++++++------------- plugins/autobutcher.cpp | 30 ++++++++---------------------- plugins/lua/autobutcher.lua | 7 ------- 3 files changed, 19 insertions(+), 42 deletions(-) diff --git a/docs/plugins/autobutcher.rst b/docs/plugins/autobutcher.rst index 4a0d64ae1..54aafa539 100644 --- a/docs/plugins/autobutcher.rst +++ b/docs/plugins/autobutcher.rst @@ -6,12 +6,10 @@ autobutcher :tags: fort auto fps animals This plugin monitors how many pets you have of each gender and age and assigns -excess livestock for slaughter. It requires that you add the target race(s) to a -watch list. Units will be ignored if they are: +excess livestock for slaughter. Units will be ignored if they are: * Untamed -* Nicknamed (for custom protection; you can use the `rename` ``unit`` tool - individually, or `zone` ``nick`` for groups) +* Nicknamed * Caged, if and only if the cage is in a zone (to protect zoos) * Trained for war or hunting @@ -20,8 +18,7 @@ opposite sex or have been gelded) will be butchered before those who will. Older adults and younger children will be butchered first if the population is above the target (defaults are: 2 male kids, 4 female kids, 2 male adults, 4 female adults). Note that you may need to set a target above 1 to have a -reliable breeding population due to asexuality etc. See `fix-ster` if this is a -problem. +reliable breeding population due to asexuality etc. Usage ----- @@ -31,6 +28,9 @@ Usage no races are watched by default. You have to add the ones you want to monitor with ``autobutcher watch``, ``autobutcher target`` or ``autobutcher autowatch``. +``autobutcher [list]`` + Print status and current settings, including the watchlist. This is the + default command if autobutcher is run without parameters. ``autobutcher autowatch`` Automatically add all new races (animals you buy from merchants, tame yourself, or get from migrants) to the watch list using the default target @@ -50,9 +50,6 @@ Usage future watch commands without changing your current watchlist. Otherwise, all space separated races listed will be modified (or added to the watchlist if they aren't there already). -``autobutcher ticks `` - Change the number of ticks between scanning cycles when the plugin is - enabled. By default, a cycle happens every 6000 ticks (about 8 game days). ``autobutcher watch all| [ ...]`` Start watching the listed races. If they aren't already in your watchlist, then they will be added with the default target counts. If you specify the @@ -64,9 +61,10 @@ Usage ``autobutcher forget all| [ ...]`` Unwatch the specified race(s) (or all races on your watchlist if ``all`` is given) and forget target settings for it/them. -``autobutcher [list]`` - Print status and current settings, including the watchlist. This is the - default command if autobutcher is run without parameters. +``autobutcher now`` + Process all livestock according to the current watchlist configuration, + even if the plugin is not currently enabled, and thus not doing automatic + periodic scans. ``autobutcher list_export`` Print commands required to set the current settings in another fort. @@ -104,7 +102,7 @@ fortress:: enable autobutcher autobutcher target 2 2 2 2 DOG autobutcher target 1 1 2 2 CAT - autobutcher target 50 50 14 2 BIRD_GOOSE + autobutcher target 10 10 14 2 BIRD_GOOSE autobutcher target 2 2 4 2 ALPACA SHEEP LLAMA autobutcher target 5 5 6 2 PIG autobutcher target 0 0 0 0 new diff --git a/plugins/autobutcher.cpp b/plugins/autobutcher.cpp index d3d8487de..d089fcbc5 100644 --- a/plugins/autobutcher.cpp +++ b/plugins/autobutcher.cpp @@ -50,7 +50,7 @@ static PersistentDataItem config; enum ConfigValues { CONFIG_IS_ENABLED = 0, - CONFIG_CYCLE_TICKS = 1, + // CONFIG_CYCLE_TICKS = 1, deprecated; no longer configurable CONFIG_AUTOWATCH = 2, CONFIG_DEFAULT_FK = 3, CONFIG_DEFAULT_MK = 4, @@ -79,6 +79,8 @@ struct WatchedRace; // to ignore them for a while but still keep the target count settings static unordered_map watched_races; static unordered_map race_to_id; + +static const int32_t CYCLE_TICKS = 6000; static int32_t cycle_timestamp = 0; // world->frame_counter at last cycle static void init_autobutcher(color_ostream &out); @@ -129,7 +131,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, 6000); set_config_bool(CONFIG_AUTOWATCH, true); set_config_val(CONFIG_DEFAULT_FK, 4); set_config_val(CONFIG_DEFAULT_MK, 2); @@ -163,7 +164,7 @@ DFhackCExport command_result plugin_onstatechange(color_ostream &out, state_chan } DFhackCExport command_result plugin_onupdate(color_ostream &out) { - if (is_enabled && world->frame_counter - cycle_timestamp >= get_config_val(CONFIG_CYCLE_TICKS)) + if (is_enabled && world->frame_counter - cycle_timestamp >= CYCLE_TICKS) autobutcher_cycle(out); return CR_OK; } @@ -501,10 +502,6 @@ static command_result df_autobutcher(color_ostream &out, vector ¶met opts.command == "forget") { autobutcher_modify_watchlist(out, opts); } - else if (opts.command == "ticks") { - set_config_val(CONFIG_CYCLE_TICKS, opts.ticks); - INFO(status,out).print("New cycle timer: %d ticks.\n", opts.ticks); - } else { autobutcher_status(out); } @@ -532,7 +529,6 @@ static vector getSortedWatchList() { static void autobutcher_export(color_ostream &out) { out << "enable autobutcher" << endl; - out << "autobutcher ticks " << get_config_val(CONFIG_CYCLE_TICKS) << endl; out << "autobutcher " << (get_config_bool(CONFIG_AUTOWATCH) ? "" : "no") << "autowatch" << endl; out << "autobutcher target" @@ -558,8 +554,6 @@ static void autobutcher_export(color_ostream &out) { static void autobutcher_status(color_ostream &out) { out << "autobutcher is " << (is_enabled ? "" : "not ") << "enabled\n"; - if (is_enabled) - out << " running every " << get_config_val(CONFIG_CYCLE_TICKS) << " game ticks\n"; out << " " << (get_config_bool(CONFIG_AUTOWATCH) ? "" : "not ") << "autowatching for new races\n"; out << "\ndefault setting for new races:" @@ -756,6 +750,8 @@ static bool isProtectedUnit(df::unit *unit) { || !unit->name.nickname.empty(); } + + static void autobutcher_cycle(color_ostream &out) { // mark that we have recently run cycle_timestamp = world->frame_counter; @@ -919,18 +915,11 @@ static bool autowatch_isEnabled() { return get_config_bool(CONFIG_AUTOWATCH); } -static unsigned autobutcher_getSleep(color_ostream &out) { - return get_config_val(CONFIG_CYCLE_TICKS); -} - -static void autobutcher_setSleep(color_ostream &out, unsigned ticks) { - - set_config_val(CONFIG_CYCLE_TICKS, ticks); -} - static void autowatch_setEnabled(color_ostream &out, bool enable) { DEBUG(status,out).print("auto-adding to watchlist %s\n", enable ? "started" : "stopped"); set_config_bool(CONFIG_AUTOWATCH, enable); + if (get_config_bool(CONFIG_IS_ENABLED)) + autobutcher_cycle(out); } // set all data for a watchlist race in one go @@ -1036,7 +1025,6 @@ static int autobutcher_getSettings(lua_State *L) { Lua::SetField(L, get_config_val(CONFIG_DEFAULT_MK), ctable, "mk"); Lua::SetField(L, get_config_val(CONFIG_DEFAULT_FA), ctable, "fa"); Lua::SetField(L, get_config_val(CONFIG_DEFAULT_MA), ctable, "ma"); - Lua::SetField(L, get_config_val(CONFIG_CYCLE_TICKS), ctable, "sleep"); return 1; } @@ -1099,8 +1087,6 @@ static int autobutcher_getWatchList(lua_State *L) { DFHACK_PLUGIN_LUA_FUNCTIONS { DFHACK_LUA_FUNCTION(autowatch_isEnabled), DFHACK_LUA_FUNCTION(autowatch_setEnabled), - DFHACK_LUA_FUNCTION(autobutcher_getSleep), - DFHACK_LUA_FUNCTION(autobutcher_setSleep), DFHACK_LUA_FUNCTION(autobutcher_setWatchListRace), DFHACK_LUA_FUNCTION(autobutcher_setDefaultTargetNew), DFHACK_LUA_FUNCTION(autobutcher_setDefaultTargetAll), diff --git a/plugins/lua/autobutcher.lua b/plugins/lua/autobutcher.lua index 51417bf9f..476618f81 100644 --- a/plugins/lua/autobutcher.lua +++ b/plugins/lua/autobutcher.lua @@ -65,13 +65,6 @@ function parse_commandline(opts, ...) opts.fa = check_nonnegative_int(positionals[4]) opts.ma = check_nonnegative_int(positionals[5]) process_races(opts, positionals, 6) - elseif command == 'ticks' then - local ticks = tonumber(positionals[2]) - if not is_positive_int(ticks) then - qerror('number of ticks must be a positive integer: ' .. ticks) - else - opts.ticks = ticks - end else qerror(('unrecognized command: "%s"'):format(command)) end From 65b0b307ff7ac8c343012084e82cc6ad943b65ba Mon Sep 17 00:00:00 2001 From: Myk Taylor Date: Tue, 2 Jan 2024 07:22:03 -0800 Subject: [PATCH 2/2] update scripts ref --- scripts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/scripts b/scripts index b41f1ec48..d116a915e 160000 --- a/scripts +++ b/scripts @@ -1 +1 @@ -Subproject commit b41f1ec482255428166722bec6904a779a0ad02f +Subproject commit d116a915e4fdcaad8a6fcb81d511735ff8f34e69