Skip to content

Commit

Permalink
Merge pull request #4990 from myk002/myk_eggs
Browse files Browse the repository at this point in the history
[nestboxes, timestream] fix handling of eggs
  • Loading branch information
myk002 authored Oct 7, 2024
2 parents f9a2bbf + 4577a9a commit edb8c50
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 9 deletions.
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

0 comments on commit edb8c50

Please sign in to comment.