Skip to content
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
1 change: 1 addition & 0 deletions docs/changelog.txt
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@ Template for new versions:
- `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
- `timestream`: fix potential crash in birthday tracking
- `logistics`: don't ignore rotten items when applying stockpile logistics operations (e.g. autodump, autoclaim, etc.)

## Misc Improvements
Expand Down
14 changes: 8 additions & 6 deletions plugins/timestream.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -121,13 +121,15 @@ static std::array<bool, NUM_COVERAGE_TICKS> tick_coverage;
// only throttle due to tick_coverage at most once per season tick to avoid clustering
static bool season_tick_throttled = false;

static const int32_t TICKS_PER_YEAR = 403200;

static void register_birthday(df::unit * unit) {
auto & btick = unit->birth_time;
if (btick < 0)
int32_t btick = unit->birth_time;
if (btick < 0 || btick > TICKS_PER_YEAR)
return;
for (size_t tick=btick; tick >= 0; --tick) {
if (birthday_triggers.size() <= tick)
birthday_triggers.resize(btick-1, INT32_MAX);
if (birthday_triggers.size() <= (size_t)btick)
birthday_triggers.resize(btick+1, INT32_MAX);
for (int32_t tick=btick; tick >= 0; --tick) {
if (birthday_triggers[tick] > btick)
birthday_triggers[tick] = btick;
else
Expand Down Expand Up @@ -286,7 +288,7 @@ static int32_t get_next_trigger_year_tick(int32_t next_tick) {
}

static int32_t get_next_birthday(int32_t next_tick) {
if (next_tick >= (int32_t)birthday_triggers.size())
if (next_tick < 0 || next_tick >= (int32_t)birthday_triggers.size())
return INT32_MAX;
return birthday_triggers[next_tick];
}
Expand Down