removed option to set tickrate for preserve-tombs, fixed at 100 tick interval

develop
Najeeb Al-Shabibi 2023-09-30 14:42:29 +01:00
parent e2dcced8ef
commit 7d3764d3ec
2 changed files with 10 additions and 29 deletions

@ -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.

@ -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<int32_t, int32_t> tomb_assignments;
@ -82,14 +81,13 @@ DFhackCExport command_result plugin_init(color_ostream &out, std::vector <Plugin
}
static command_result do_command(color_ostream& out, std::vector<std::string>& 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<std::string>& 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");