@@ -646,6 +646,18 @@ function resmon.tick_deposit_count(site)
646
646
site .iter_key = index
647
647
end
648
648
649
+ -- as a default case, takes a diff between two values and returns a smoothed
650
+ -- easing step. however to force convergence, it does *not* smooth diffs below 1
651
+ -- and clamps smoothed diffs below 10 to be at least 1.
652
+ function resmon .smooth_clamp_diff (diff )
653
+ if math.abs (diff ) < 1 then
654
+ return diff
655
+ elseif math.abs (diff ) < 10 then
656
+ return math.abs (diff ) / diff
657
+ end
658
+
659
+ return 0.1 * diff
660
+ end
649
661
650
662
function resmon .finish_deposit_count (site )
651
663
site .iter_key = nil
@@ -658,14 +670,15 @@ function resmon.finish_deposit_count(site)
658
670
site .last_modified_tick = site .last_ore_check --
659
671
end
660
672
local delta_ore_since_last_update = site .last_modified_amount - site .amount
661
- if delta_ore_since_last_update ~= 0 then -- only store the amount and tick from last update if it actually changed
673
+ if delta_ore_since_last_update ~= 0 then -- only store the amount and tick from last update if it actually changed
662
674
site .last_modified_tick = site .last_ore_check --
663
675
site .last_modified_amount = site .amount --
664
676
end
665
677
local delta_ore_since_last_change = site .update_amount - site .last_modified_amount -- use final amount and tick to calculate
666
678
local delta_ticks = game .tick - site .last_modified_tick --
667
- local new_ore_per_minute = math.floor (delta_ore_since_last_change * 3600 / delta_ticks ) -- ease the per minute value over time
668
- site .ore_per_minute = site .ore_per_minute + (0.1 * (new_ore_per_minute - site .ore_per_minute )) --
679
+ local new_ore_per_minute = delta_ore_since_last_change * 3600 / delta_ticks -- ease the per minute value over time
680
+ local diff_step = resmon .smooth_clamp_diff (new_ore_per_minute - site .ore_per_minute ) --
681
+ site .ore_per_minute = site .ore_per_minute + diff_step --
669
682
end
670
683
671
684
site .amount = site .update_amount
0 commit comments