From 684034b10f4619bb092efa721dc7dd1aac9d9c0b Mon Sep 17 00:00:00 2001 From: Myk Taylor Date: Thu, 1 Aug 2024 16:32:17 -0700 Subject: [PATCH] better account for unit actions with small timers --- timestream.lua | 22 ++++++++++------------ 1 file changed, 10 insertions(+), 12 deletions(-) diff --git a/timestream.lua b/timestream.lua index 9550c620d..e41143e05 100644 --- a/timestream.lua +++ b/timestream.lua @@ -139,23 +139,21 @@ local function adjust_unit_counters(unit, timeskip) -- not materially affect gameplay end +-- 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 correct, since we're losing time when we subtract from the action timers +-- and cap the value so it never drops below 1. local function adjust_job_counter(unit, timeskip) local job = unit.job.current_job if not job then return end - local job_type = job.job_type - if job_type == df.job_type.Eat or - job_type == df.job_type.DrinkItem or - job_type == df.job_type.CollectSand - then - decrement_counter(job, 'completion_timer', timeskip) - elseif job.completion_timer > 1 then - -- for these job types, the decrement per tick is 1/11, but the counter on which - -- the decrement happens is unknown. it's not cur_year_tick - -- therefore, we decrement probabilistically - if math.random(11) <= timeskip then - decrement_counter(job, 'completion_timer', 1) + for _,action in ipairs(unit.actions) do + if action.type == df.unit_action_type.Job or action.type == df.unit_action_type.JobRecover then + return end end + decrement_counter(job, 'completion_timer', timeskip) end -- unit needs appear to be incremented on season ticks, so we don't need to worry about those