From b0a15b2e8a5319fb896cd927ee2b63ad00ba3775 Mon Sep 17 00:00:00 2001 From: Najeeb Al-Shabibi Date: Fri, 29 Sep 2023 13:38:52 +0100 Subject: [PATCH] added command to show status of preservetombs (is enabled or disabled) --- plugins/preserve-tombs.cpp | 29 ++++++++++++++++++++++------- 1 file changed, 22 insertions(+), 7 deletions(-) diff --git a/plugins/preserve-tombs.cpp b/plugins/preserve-tombs.cpp index 245ce5949..d80ca3b03 100644 --- a/plugins/preserve-tombs.cpp +++ b/plugins/preserve-tombs.cpp @@ -68,12 +68,27 @@ static void set_config_bool(PersistentDataItem &c, int index, bool value) { static bool assign_to_tomb(int32_t unit_id, int32_t building_id); static void update_tomb_assignments(color_ostream& out); void onUnitDeath(color_ostream& out, void* ptr); +static command_result do_command(color_ostream& out, std::vector& params); DFhackCExport command_result plugin_init(color_ostream &out, std::vector &commands) { - tomb_assignments.clear(); + commands.push_back(PluginCommand( + plugin_name, + "Preserves tomb assignments to units when they die.", + do_command)); return CR_OK; } +static command_result do_command(color_ostream& out, std::vector& params) { + if (params.size() != 1 || params[0] != "status") { + out.print("%s wrong usage", plugin_name); + return CR_WRONG_USAGE; + } + else { + out.print("%s is currently %s", plugin_name, is_enabled ? "enabled" : "disabled"); + return CR_OK; + } +} + // event listener EventManager::EventHandler assign_tomb_handler(onUnitDeath, 0); @@ -154,7 +169,7 @@ DFhackCExport command_result plugin_onupdate(color_ostream &out) { void onUnitDeath(color_ostream& out, void* ptr) { // input is void* that contains the unit id int32_t unit_id = reinterpret_cast(ptr); - + // check if unit was assigned a tomb in life auto it = tomb_assignments.find(unit_id); if (it == tomb_assignments.end()) return; @@ -199,10 +214,10 @@ static void update_tomb_assignments(color_ostream &out) { } - // now check our civzones for unassignment / deleted zone / + // now check our civzones for unassignment / deleted zone / for (auto it = tomb_assignments.begin(); it != tomb_assignments.end(); ++it){ auto &[unit_id, building_id] = *it; - + const size_t tomb_idx = binsearch_index(world->buildings.other.ZONE_TOMB, building_id); if (tomb_idx == -1) { out.print("%s tomb missing: %d - removing\n", plugin_name, building_id); @@ -229,13 +244,13 @@ static void update_tomb_assignments(color_ostream &out) { // // static bool assign_to_tomb(int32_t unit_id, int32_t building_id) { - + size_t unit_idx = Units::findIndexById(unit_id); if (unit_idx == -1) return false; - + df::unit* unit = world->units.all[unit_idx]; if (!Units::isDead(unit)) return false; - + size_t tomb_idx = binsearch_index(world->buildings.other.ZONE_TOMB, building_id); if (tomb_idx == -1) return false;