Skip to content

Commit edb8c50

Browse files
authored
Merge pull request #4990 from myk002/myk_eggs
[nestboxes, timestream] fix handling of eggs
2 parents f9a2bbf + 4577a9a commit edb8c50

File tree

3 files changed

+28
-9
lines changed

3 files changed

+28
-9
lines changed

docs/changelog.txt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,8 @@ Template for new versions:
5959
## Fixes
6060
- Fix mouse clicks bleeding through DFHack windows when clicking in the space between the frame and the window content in resizable windows
6161
- `autobutcher`: don't run a scanning and marking cycle on the first tick of a fortress to allow for all custom configuration to be set first
62+
- `nestboxes`: don't consider eggs to be infertile just because the mother has left the nest; eggs can still hatch in this situation
63+
- `timestream`: adjust the incubation counter on fertile eggs so they hatch at the expected time
6264
- `logistics`: don't ignore rotten items when applying stockpile logistics operations (e.g. autodump, autoclaim, etc.)
6365

6466
## Misc Improvements

plugins/nestboxes.cpp

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -118,15 +118,13 @@ static void do_cycle(color_ostream &out) {
118118
cycle_timestamp = world->frame_counter;
119119

120120
for (df::building_nest_boxst *nb : world->buildings.other.NEST_BOX) {
121-
bool fertile = false;
122-
if (nb->claimed_by != -1) {
123-
df::unit *u = df::unit::find(nb->claimed_by);
124-
if (u && u->pregnancy_timer > 0)
125-
fertile = true;
126-
}
127121
for (auto &contained_item : nb->contained_items) {
128-
auto *item = virtual_cast<df::item_eggst>(contained_item->item);
129-
if (item && item->flags.bits.forbid != fertile) {
122+
if (contained_item->use_mode == df::building_item_role_type::PERM)
123+
continue;
124+
if (auto *item = virtual_cast<df::item_eggst>(contained_item->item)) {
125+
bool fertile = item->egg_flags.bits.fertile;
126+
if (item->flags.bits.forbid == fertile)
127+
continue;
130128
item->flags.bits.forbid = fertile;
131129
if (fertile && item->flags.bits.in_job) {
132130
// cancel any job involving the egg
@@ -135,7 +133,7 @@ static void do_cycle(color_ostream &out) {
135133
if (sref && sref->data.job)
136134
Job::removeJob(sref->data.job);
137135
}
138-
out.print("%d eggs %s.\n", item->getStackSize(), fertile ? "forbidden" : "unforbidden");
136+
out.print("nestboxes: %d eggs %s\n", item->getStackSize(), fertile ? "forbidden" : "unforbidden");
139137
}
140138
}
141139
}

plugins/timestream.cpp

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,9 @@
2929
#include "df/activity_event_teach_topicst.h"
3030
#include "df/activity_event_writest.h"
3131
#include "df/activity_event_worshipst.h"
32+
#include "df/building_nest_boxst.h"
3233
#include "df/init.h"
34+
#include "df/item_eggst.h"
3335
#include "df/unit.h"
3436
#include "df/world.h"
3537

@@ -571,6 +573,22 @@ static void adjust_activities(color_ostream &out, int32_t timeskip) {
571573
}
572574
}
573575

576+
static void adjust_items(color_ostream &out, int32_t timeskip) {
577+
// increment incubation counters for fertile eggs in non-forbidden nestboxes
578+
for (df::building_nest_boxst *nb : world->buildings.other.NEST_BOX) {
579+
for (auto & contained_item : nb->contained_items) {
580+
if (contained_item->use_mode == df::building_item_role_type::PERM) {
581+
if (contained_item->item->flags.bits.forbid)
582+
break;
583+
else
584+
continue;
585+
}
586+
if (auto *egg = virtual_cast<df::item_eggst>(contained_item->item); egg && egg->egg_flags.bits.fertile)
587+
increment_counter(egg, &df::item_eggst::incubation_counter, timeskip);
588+
}
589+
}
590+
}
591+
574592
static void do_cycle(color_ostream &out) {
575593
DEBUG(cycle,out).print("running %s cycle\n", plugin_name);
576594

@@ -612,6 +630,7 @@ static void do_cycle(color_ostream &out) {
612630

613631
adjust_units(out, timeskip);
614632
adjust_activities(out, timeskip);
633+
adjust_items(out, timeskip);
615634
}
616635

617636
/////////////////////////////////////////////////////

0 commit comments

Comments
 (0)