Skip to content

Commit

Permalink
Merge pull request #1213 from myk002/myk_timestream
Browse files Browse the repository at this point in the history
[timestream] fixes
  • Loading branch information
myk002 authored Jun 29, 2024
2 parents c572568 + ee5b3f2 commit e8a1e6e
Showing 1 changed file with 76 additions and 7 deletions.
83 changes: 76 additions & 7 deletions timestream.lua
Original file line number Diff line number Diff line change
Expand Up @@ -106,30 +106,99 @@ local function adjust_units(timeskip)
end
end
dfhack.units.subtractGroupActionTimers(unit, timeskip, df.unit_action_type_group.All)
local job = unit.job.current_job
local c2 = unit.counters2
if job and job.job_type == df.job_type.Rest then
c2.sleepiness_timer = math.max(0, c2.sleepiness_timer - timeskip * 200)
end
if not dfhack.units.isCitizen(unit, true) then goto continue end
if not has_caste_flag(unit, 'NO_EAT') then
c2.hunger_timer = c2.hunger_timer + timeskip
end
if not has_caste_flag(unit, 'NO_DRINK') then
c2.thirst_timer = c2.thirst_timer + timeskip
end
local job = unit.job.current_job
if not has_caste_flag(unit, 'NO_SLEEP') then
if job and job.job_type == df.job_type.Sleep then
c2.sleepiness_timer = math.max(0, c2.sleepiness_timer - timeskip * 19)
else
c2.sleepiness_timer = c2.sleepiness_timer + timeskip
end
end
if job and job.job_type == df.job_type.Rest then
c2.sleepiness_timer = math.max(0, c2.sleepiness_timer - timeskip * 200)
end
-- TODO: c2.stomach_content, c2.stomach_food, and c2.stored_fat
-- TODO: needs
::continue::
end
end

local function adjust_armies(timeskip)
-- TODO
local function increment_counter(ev, counter_name, timeskip)
if ev[counter_name] <= 0 then return end
ev[counter_name] = ev[counter_name] + timeskip
end

local function decrement_counter(ev, counter_name, timeskip)
if ev[counter_name] <= 0 then return end
ev[counter_name] = math.max(1, ev[counter_name] - timeskip)
end

local function adjust_activities(timeskip)
for i, act in ipairs(df.global.world.activities.all) do
for _, ev in ipairs(act.events) do
if df.activity_event_training_sessionst:is_instance(ev) then
-- noop
elseif df.activity_event_combat_trainingst:is_instance(ev) then
elseif df.activity_event_skill_demonstrationst:is_instance(ev) then
-- can be negative or positive, but always counts towards 0
if ev.organize_counter < 0 then
ev.organize_counter = math.min(-1, ev.organize_counter + timeskip)
else
decrement_counter(ev, 'organize_counter', timeskip)
end
decrement_counter(ev, 'train_countdown', timeskip)
elseif df.activity_event_fill_service_orderst:is_instance(ev) then
elseif df.activity_event_individual_skill_drillst:is_instance(ev) then
-- only counts down on season ticks, nothing to do here
elseif df.activity_event_sparringst:is_instance(ev) then
elseif df.activity_event_ranged_practicest:is_instance(ev) then
decrement_counter(ev, 'countdown', timeskip)
elseif df.activity_event_harassmentst:is_instance(ev) then
elseif df.activity_event_encounterst:is_instance(ev) then
elseif df.activity_event_reunionst:is_instance(ev) then
elseif df.activity_event_conversationst:is_instance(ev) then
increment_counter(ev, 'pause', timeskip)
elseif df.activity_event_guardst:is_instance(ev) then
elseif df.activity_event_conflictst:is_instance(ev) then
increment_counter(ev, 'inactivity_timer', timeskip)
increment_counter(ev, 'attack_inactivity_timer', timeskip)
increment_counter(ev, 'stop_fort_fights_timer', timeskip)
elseif df.activity_event_prayerst:is_instance(ev) then
decrement_counter(ev, 'timer', timeskip)
elseif df.activity_event_researchst:is_instance(ev) then
-- noop
elseif df.activity_event_playst:is_instance(ev) then
increment_counter(ev, 'down_time_counter', timeskip)
elseif df.activity_event_worshipst:is_instance(ev) then
increment_counter(ev, 'down_time_counter', timeskip)
elseif df.activity_event_socializest:is_instance(ev) then
increment_counter(ev, 'down_time_counter', timeskip)
elseif df.activity_event_ponder_topicst:is_instance(ev) then
elseif df.activity_event_discuss_topicst:is_instance(ev) then
decrement_counter(ev, 'timer', timeskip)
elseif df.activity_event_teach_topicst:is_instance(ev) then
elseif df.activity_event_readst:is_instance(ev) then
decrement_counter(ev, 'timer', timeskip)
elseif df.activity_event_writest:is_instance(ev) then
decrement_counter(ev, 'timer', timeskip)
elseif df.activity_event_copy_written_contentst:is_instance(ev) then
elseif df.activity_event_make_believest:is_instance(ev) then
decrement_counter(ev, 'time_left', timeskip)
elseif df.activity_event_play_with_toyst:is_instance(ev) then
elseif df.activity_event_performancest:is_instance(ev) then
increment_counter(ev, 'current_position', timeskip)
elseif df.activity_event_store_objectst:is_instance(ev) then
end
end
end
end

local function on_tick()
Expand Down Expand Up @@ -166,7 +235,7 @@ local function on_tick()
df.global.cur_year_tick = df.global.cur_year_tick + calendar_timeskip

adjust_units(timeskip)
adjust_armies(timeskip)
adjust_activities(timeskip)
end

------------------------------------
Expand Down

0 comments on commit e8a1e6e

Please sign in to comment.