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.
develop
lethosor 2023-02-10 22:52:01 -05:00
parent 9434cd3d64
commit 1390e724b6
No known key found for this signature in database
GPG Key ID: 76A269552F4F58C1
1 changed files with 3 additions and 2 deletions

@ -9,6 +9,7 @@
#include "df/world.h" #include "df/world.h"
#include "df/building_nest_boxst.h" #include "df/building_nest_boxst.h"
#include "df/item.h" #include "df/item.h"
#include "df/item_eggst.h"
#include "df/unit.h" #include "df/unit.h"
using std::string; using std::string;
@ -140,8 +141,8 @@ static void do_cycle(color_ostream &out) {
fertile = true; fertile = true;
} }
for (auto &contained_item : nb->contained_items) { for (auto &contained_item : nb->contained_items) {
df::item *item = contained_item->item; auto *item = virtual_cast<df::item_eggst>(contained_item->item);
if (item->flags.bits.forbid != fertile) { if (item && item->flags.bits.forbid != fertile) {
item->flags.bits.forbid = fertile; item->flags.bits.forbid = fertile;
if (fertile && item->flags.bits.in_job) { if (fertile && item->flags.bits.in_job) {
// cancel any job involving the egg // cancel any job involving the egg