Skip to content

Commit

Permalink
fix two-chamber balers which automatically overload
Browse files Browse the repository at this point in the history
  • Loading branch information
Timmeey86 committed Mar 18, 2024
1 parent 684eee8 commit 902af05
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 4 deletions.
2 changes: 2 additions & 0 deletions modDesc.xml
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ This mod is based on the idea of FS19's "UnfinishedBales" mod by mogli12 but was
Changelog:
v1.0.0.1:
- Added compatibility with Göweil DLC
- Added russian translation provided by nagor
]]></en>
<de><![CDATA[Diese Mod erlaubt das Abladen von Ballen ab einem konfigurierbaren Schwellenwert (Standard: 10%)
Expand All @@ -41,6 +42,7 @@ Diese Mod basiert auf der Idee der "UnfinishedBales" mod von FS19, wurde aber f
Changelog
v1.0.0.1:
- Kompatibilität mit Göweil DLC hergestellt
- Russische Übersetzung hinzugefügt (bereitgestellt von nagor)
]]></de>
</description>
Expand Down
20 changes: 16 additions & 4 deletions scripts/EarlyUnloadHandler.lua
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,13 @@ function EarlyUnloadHandler.onBalerLoad(baler, superFunc, savegame)
print(("%s: Forcing early unload possibility for %s %s '%s'"):format(MOD_NAME, baler.typeName, baler.brand.title, baler.configFileNameClean))
spec.canUnloadUnfinishedBale = true

-- TODO: Use for two-chamber cotton harvester
--spec.buffer.overloadingStartFillLevelPct = .1
-- Remember the original threshold at which overloading is supposed to start for two-chamber balers
if spec.buffer and spec.buffer.overloadingStartFillLevelPct then
spec.originalOverloadPct = spec.buffer.overloadingStartFillLevelPct
else
spec.originalOverloadPct = 1
end
spec.overloadingThresholdIsOverridden = false
end

---Unloads the bale after the player pressed the hotkey
Expand Down Expand Up @@ -65,6 +70,7 @@ function EarlyUnloadHandler.onActionEventUnloading(baler, superFunc, param1, par
if EarlyUnloadHandler.getCanOverloadBuffer(baler) then
--Two-chamber vehicles: Reduce the overloading percentage so the baler starts unloading
spec.buffer.overloadingStartFillLevelPct = g_currentMission.unloadBalesEarlySettings:getUnloadThresholdInPercent() / 100
spec.overloadingThresholdIsOverridden = true
-- Ignore the event in this case, don't forward it
else
-- Forward the event through base game mechanism in all other cases
Expand All @@ -78,8 +84,9 @@ end
function EarlyUnloadHandler.after_onUpdateTick(baler, ...)
-- Reset the overloading percentage when unloading has started
local spec = baler.spec_baler
if spec.buffer.unloadingStarted then
spec.buffer.overloadingStartFillLevelPct = 1
if spec.buffer.unloadingStarted and spec.overloadingThresholdIsOverridden then
spec.buffer.overloadingStartFillLevelPct = spec.originalOverloadPct
spec.overloadingThresholdIsOverridden = false
end
end

Expand Down Expand Up @@ -175,9 +182,14 @@ end
---@return boolean @True if overloading is possible right now
function EarlyUnloadHandler.getCanOverloadBuffer(baler)
local spec = baler.spec_baler
-- Do not offer the option to overload if it's not a two chamber baler
if spec.buffer.fillUnitIndex ~= 2 then
return false
end
-- Göweil DLC (and maybe others): Do not offer the option if the baler always automatically overloads
if spec.originalOverloadPct == 0 then
return false
end
local requiredLiters = math.max(1, EarlyUnloadHandler.getUnfinishedBaleThreshold(baler, 2))
return baler:getIsTurnedOn() and baler.spec_fillUnit.fillUnits[2].fillLevel >= requiredLiters
end
Expand Down

0 comments on commit 902af05

Please sign in to comment.