From 1390e724b6c55f725e29f2218af11a369f101011 Mon Sep 17 00:00:00 2001 From: lethosor Date: Fri, 10 Feb 2023 22:52:01 -0500 Subject: [PATCH] nestboxes: avoid forbidding non-eggs The rewrite in #2773 introduced a bug (identified by KMFrench on Discord) where nestboxes themselves would be forbidden, which prevents egglaying citizens from using them since the nestboxes would be claimed before use. The previous version of the plugin handled this by skipping the first item in `contained_items`, which is the building material (in this case, the nestbox). This fix limits the `forbid` flag manipulation to egg items only, which should be a reasonable limitation that still allows the plugin to serve its purpose. --- plugins/nestboxes.cpp | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/plugins/nestboxes.cpp b/plugins/nestboxes.cpp index d723f8a5c..f8758a0d9 100644 --- a/plugins/nestboxes.cpp +++ b/plugins/nestboxes.cpp @@ -9,6 +9,7 @@ #include "df/world.h" #include "df/building_nest_boxst.h" #include "df/item.h" +#include "df/item_eggst.h" #include "df/unit.h" using std::string; @@ -140,8 +141,8 @@ static void do_cycle(color_ostream &out) { fertile = true; } for (auto &contained_item : nb->contained_items) { - df::item *item = contained_item->item; - if (item->flags.bits.forbid != fertile) { + auto *item = virtual_cast(contained_item->item); + if (item && item->flags.bits.forbid != fertile) { item->flags.bits.forbid = fertile; if (fertile && item->flags.bits.in_job) { // cancel any job involving the egg