From b885123d4ea8ebe95536774a4798ddef3c67a6b1 Mon Sep 17 00:00:00 2001 From: Alexander Gavrilov Date: Mon, 26 Aug 2013 16:55:30 +0400 Subject: [PATCH] Fix a crash in beehive code if bees die with yet uncollected products. http://www.bay12games.com/dwarves/mantisbt/view.php?id=6368 --- NEWS | 2 ++ Readme.rst | 3 +++ dfhack.init-example | 3 +++ plugins/tweak.cpp | 48 +++++++++++++++++++++++++++++++++++++++++++++ 4 files changed, 56 insertions(+) diff --git a/NEWS b/NEWS index c8f8aee90..b41444586 100644 --- a/NEWS +++ b/NEWS @@ -15,6 +15,8 @@ DFHack future - ruby: add df.dfhack_run "somecommand" - magmasource: rename to 'source', allow water/magma sources/drains - core: fix SC_WORLD_(UN)LOADED event for arena mode + New tweaks: + - hive-crash: Prevent crash if bees die in a hive with ungathered products (bug 6368). New plugins: - buildingplan: Place furniture before it's built - resume: A plugin to help display and resume suspended constructions conveniently diff --git a/Readme.rst b/Readme.rst index cd9101aab..42ef41da3 100644 --- a/Readme.rst +++ b/Readme.rst @@ -1146,6 +1146,9 @@ Subcommands that persist until disabled or DF quit: (i.e. the more units you have, the slower it becomes), and making the units spar more. +:hive-crash: The hive code crashes if there are ungathered products in a hive without bees (bug 6368). + This tweak prevents it by auto-gathering the products if this happens. + fix-armory ---------- diff --git a/dfhack.init-example b/dfhack.init-example index 22d2c2972..b07603cc5 100644 --- a/dfhack.init-example +++ b/dfhack.init-example @@ -147,6 +147,9 @@ tweak military-color-assigned # remove inverse dependency of squad training speed on unit list size and use more sparring tweak military-training +# prevent crash if bees die in a hive with ungathered products by insta-gathering them +tweak hive-crash + # enable autoSyndrome autoSyndrome enable diff --git a/plugins/tweak.cpp b/plugins/tweak.cpp index 337759348..b9e6ea7f2 100644 --- a/plugins/tweak.cpp +++ b/plugins/tweak.cpp @@ -57,6 +57,7 @@ #include "df/activity_event_individual_skill_drillst.h" #include "df/activity_event_skill_demonstrationst.h" #include "df/activity_event_sparringst.h" +#include "df/building_hivest.h" #include @@ -136,6 +137,8 @@ DFhackCExport command_result plugin_init (color_ostream &out, std::vector item->getType() != item_type::VERMIN) + continue; + any_bees = true; + break; + } + + if (!any_bees) + { + bool any_products = false; + for (size_t i = 0; i < contained_items.size(); i++) + { + if (contained_items[i]->use_mode != 0 || + !contained_items[i]->item->flags.bits.in_building) + continue; + + contained_items[i]->item->flags.bits.in_building = false; + any_products = true; + } + + if (any_products) + { + color_ostream_proxy out(Core::getInstance().getConsole()); + out.print("Bees died in hive with products at (%d,%d,%d); preventing crash.\n", + centerx, centery, z); + } + } + + INTERPOSE_NEXT(updateAction)(); + } +}; + +IMPLEMENT_VMETHOD_INTERPOSE(hive_crash_hook, updateAction); + static void enable_hook(color_ostream &out, VMethodInterposeLinkBase &hook, vector ¶meters) { if (vector_get(parameters, 1) == "disable") @@ -1112,6 +1156,10 @@ static command_result tweak(color_ostream &out, vector ¶meters) enable_hook(out, INTERPOSE_HOOK(military_training_sp_hook, process), parameters); enable_hook(out, INTERPOSE_HOOK(military_training_id_hook, process), parameters); } + else if (cmd == "hive-crash") + { + enable_hook(out, INTERPOSE_HOOK(hive_crash_hook, updateAction), parameters); + } else return CR_WRONG_USAGE;