From 7d3764d3ec1708e6b8d8feef3236914f60463983 Mon Sep 17 00:00:00 2001 From: Najeeb Al-Shabibi Date: Sat, 30 Sep 2023 14:42:29 +0100 Subject: [PATCH] removed option to set tickrate for preserve-tombs, fixed at 100 tick interval --- docs/plugins/preserve-tombs.rst | 12 +++++------- plugins/preserve-tombs.cpp | 27 +++++---------------------- 2 files changed, 10 insertions(+), 29 deletions(-) diff --git a/docs/plugins/preserve-tombs.rst b/docs/plugins/preserve-tombs.rst index 846c6c553..045d15a5a 100644 --- a/docs/plugins/preserve-tombs.rst +++ b/docs/plugins/preserve-tombs.rst @@ -13,13 +13,11 @@ Usage ``enable preserve-tombs`` enable the plugin -``preserve-tombs status`` +``preserve-tombs [status]`` check the status of the plugin, and if the plugin is enabled, - lists all tracked tomb assignments + lists all currently tracked tomb assignments ``preserve-tombs update`` - forces an immediate update of the tomb assignments. -``preserve-tombs freq [val]`` - changes the rate at which the plugin rechecks and updates - tomb assignments, in ticks (default is ``100``) + forces an immediate update of the tomb assignments. This plugin + automatically updates the tomb assignments once every 100 ticks. -This tool runs in the background. +This tool runs in the background. diff --git a/plugins/preserve-tombs.cpp b/plugins/preserve-tombs.cpp index 9216a5de4..3e5cea1d2 100644 --- a/plugins/preserve-tombs.cpp +++ b/plugins/preserve-tombs.cpp @@ -36,11 +36,10 @@ static const std::string CONFIG_KEY = std::string(plugin_name) + "/config"; static PersistentDataItem config; static int32_t cycle_timestamp; -static int32_t cycle_freq; +static constexpr int32_t cycle_freq = 100; enum ConfigValues { CONFIG_IS_ENABLED = 0, - CONFIG_CYCLES = 1 }; static std::unordered_map tomb_assignments; @@ -82,14 +81,13 @@ DFhackCExport command_result plugin_init(color_ostream &out, std::vector & params) { - if (params.size() == 0) { - out.print("%s wrong usage\n", plugin_name); - return CR_WRONG_USAGE; + if (!Core::getInstance().isWorldLoaded()) { + out.printerr("Cannot use %s without a loaded world.\n", plugin_name); + return CR_FAILURE; } - if (params[0] == "status") { + if (params.size() == 0 || params[0] == "status") { out.print("%s is currently %s\n", plugin_name, is_enabled ? "enabled" : "disabled"); if (is_enabled) { - out.print("Update frequency: %d ticks", cycle_freq); out.print("tracked tomb assignments:\n"); std::for_each(tomb_assignments.begin(), tomb_assignments.end(), [&out](const auto& p){ auto& [unit_id, building_id] = p; @@ -110,19 +108,6 @@ static command_result do_command(color_ostream& out, std::vector& p out.print("Updated tomb assignments\n"); return CR_OK; } - if (params.size() < 2) { - out.print("%s wrong usage\n", plugin_name); - return CR_WRONG_USAGE; - } - if (params[0] == "ticks" || params[0] == "freq" || params[0] == "rate") { - int new_tickrate = std::stoi(params[1]); - if (new_tickrate <= 0) { - out.print("new tickrate (%d) cannot be <= 0\n", new_tickrate); - return CR_WRONG_USAGE; - } - cycle_freq = new_tickrate; - set_config_val(config, CONFIG_CYCLES, cycle_freq); - } return CR_WRONG_USAGE; } @@ -170,11 +155,9 @@ DFhackCExport command_result plugin_load_data (color_ostream &out) { DEBUG(config,out).print("no config found in this save; initializing\n"); config = World::AddPersistentData(CONFIG_KEY); set_config_bool(config, CONFIG_IS_ENABLED, is_enabled); - set_config_val(config, CONFIG_CYCLES, 100); } is_enabled = get_config_bool(config, CONFIG_IS_ENABLED); - cycle_freq = get_config_val(config, CONFIG_CYCLES); DEBUG(config,out).print("loading persisted enabled state: %s\n", is_enabled ? "true" : "false");