Fix a crash in beehive code if bees die with yet uncollected products.

http://www.bay12games.com/dwarves/mantisbt/view.php?id=6368
develop
Alexander Gavrilov 2013-08-26 16:55:30 +04:00
parent 896cd11fe9
commit b885123d4e
4 changed files with 56 additions and 0 deletions

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

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

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

@ -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 <stdlib.h>
@ -136,6 +137,8 @@ DFhackCExport command_result plugin_init (color_ostream &out, std::vector <Plugi
" to make them stand out more in the list.\n"
" tweak military-training [disable]\n"
" Speed up melee squad training, removing inverse dependency on unit count.\n"
" tweak hive-crash [disable]\n"
" Prevents crash if bees die in a hive with uncollected products (bug 6368).\n"
));
return CR_OK;
}
@ -932,6 +935,47 @@ struct military_training_id_hook : df::activity_event_individual_skill_drillst {
IMPLEMENT_VMETHOD_INTERPOSE(military_training_id_hook, process);
struct hive_crash_hook : df::building_hivest {
typedef df::building_hivest interpose_base;
DEFINE_VMETHOD_INTERPOSE(void, updateAction, ())
{
bool any_bees = false;
for (size_t i = 0; i < contained_items.size(); i++)
{
if (contained_items[i]->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 <string> &parameters)
{
if (vector_get(parameters, 1) == "disable")
@ -1112,6 +1156,10 @@ static command_result tweak(color_ostream &out, vector <string> &parameters)
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;