MCPcopy Create free account
hub / github.com/DFHack/dfhack / adjust_job_counter

Function adjust_job_counter

plugins/timestream.cpp:469–478  ·  view source on GitHub ↗

need to manually adjust job completion_timer values for jobs that are controlled by unit actions with a timer of 1, which are destroyed immediately after they are created. longer-lived unit actions are already sufficiently handled by dfhack.units.subtractGroupActionTimers(). this will also decrement timers for jobs with actions that have just expired, but on average, this should balance out to be

Source from the content-addressed store, hash-verified

467// should balance out to be correct, since we're losing time when we subtract from the action timers
468// and cap the value so it never drops below 1.
469static void adjust_job_counter(df::unit * unit, int32_t timeskip) {
470 auto job = unit->job.current_job;
471 if (!job)
472 return;
473 for (auto action : unit->actions) {
474 if (action->type == df::unit_action_type::Job || action->type == df::unit_action_type::JobRecover)
475 return;
476 }
477 decrement_counter(job, &df::job::completion_timer, timeskip);
478}
479
480// unit needs appear to be incremented on season ticks, so we don't need to worry about those
481// since the TICK_TRIGGERS check makes sure that we never skip season ticks

Callers 1

adjust_unitsFunction · 0.85

Calls 1

decrement_counterFunction · 0.85

Tested by

no test coverage detected