Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[nestboxes, timestream] fix handling of eggs #4990

Merged
merged 1 commit into from
Oct 7, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions docs/changelog.txt
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,8 @@ Template for new versions:
## Fixes
- Fix mouse clicks bleeding through DFHack windows when clicking in the space between the frame and the window content in resizable windows
- `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
- `nestboxes`: don't consider eggs to be infertile just because the mother has left the nest; eggs can still hatch in this situation
- `timestream`: adjust the incubation counter on fertile eggs so they hatch at the expected time
- `logistics`: don't ignore rotten items when applying stockpile logistics operations (e.g. autodump, autoclaim, etc.)

## Misc Improvements
Expand Down
16 changes: 7 additions & 9 deletions plugins/nestboxes.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -118,15 +118,13 @@ static void do_cycle(color_ostream &out) {
cycle_timestamp = world->frame_counter;

for (df::building_nest_boxst *nb : world->buildings.other.NEST_BOX) {
bool fertile = false;
if (nb->claimed_by != -1) {
df::unit *u = df::unit::find(nb->claimed_by);
if (u && u->pregnancy_timer > 0)
fertile = true;
}
for (auto &contained_item : nb->contained_items) {
auto *item = virtual_cast<df::item_eggst>(contained_item->item);
if (item && item->flags.bits.forbid != fertile) {
if (contained_item->use_mode == df::building_item_role_type::PERM)
continue;
if (auto *item = virtual_cast<df::item_eggst>(contained_item->item)) {
bool fertile = item->egg_flags.bits.fertile;
if (item->flags.bits.forbid == fertile)
continue;
item->flags.bits.forbid = fertile;
if (fertile && item->flags.bits.in_job) {
// cancel any job involving the egg
Expand All @@ -135,7 +133,7 @@ static void do_cycle(color_ostream &out) {
if (sref && sref->data.job)
Job::removeJob(sref->data.job);
}
out.print("%d eggs %s.\n", item->getStackSize(), fertile ? "forbidden" : "unforbidden");
out.print("nestboxes: %d eggs %s\n", item->getStackSize(), fertile ? "forbidden" : "unforbidden");
}
}
}
Expand Down
19 changes: 19 additions & 0 deletions plugins/timestream.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,9 @@
#include "df/activity_event_teach_topicst.h"
#include "df/activity_event_writest.h"
#include "df/activity_event_worshipst.h"
#include "df/building_nest_boxst.h"
#include "df/init.h"
#include "df/item_eggst.h"
#include "df/unit.h"
#include "df/world.h"

Expand Down Expand Up @@ -571,6 +573,22 @@ static void adjust_activities(color_ostream &out, int32_t timeskip) {
}
}

static void adjust_items(color_ostream &out, int32_t timeskip) {
// increment incubation counters for fertile eggs in non-forbidden nestboxes
for (df::building_nest_boxst *nb : world->buildings.other.NEST_BOX) {
for (auto & contained_item : nb->contained_items) {
if (contained_item->use_mode == df::building_item_role_type::PERM) {
if (contained_item->item->flags.bits.forbid)
break;
else
continue;
}
if (auto *egg = virtual_cast<df::item_eggst>(contained_item->item); egg && egg->egg_flags.bits.fertile)
increment_counter(egg, &df::item_eggst::incubation_counter, timeskip);
}
}
}

static void do_cycle(color_ostream &out) {
DEBUG(cycle,out).print("running %s cycle\n", plugin_name);

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

adjust_units(out, timeskip);
adjust_activities(out, timeskip);
adjust_items(out, timeskip);
}

/////////////////////////////////////////////////////
Expand Down