From 902af053fa05faa06e252c949ef475d6e7625785 Mon Sep 17 00:00:00 2001 From: Timmeey86 Date: Mon, 18 Mar 2024 09:45:21 +0100 Subject: [PATCH] fix two-chamber balers which automatically overload --- modDesc.xml | 2 ++ scripts/EarlyUnloadHandler.lua | 20 ++++++++++++++++---- 2 files changed, 18 insertions(+), 4 deletions(-) diff --git a/modDesc.xml b/modDesc.xml index 9f725d1..4c24abc 100644 --- a/modDesc.xml +++ b/modDesc.xml @@ -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 ]]> diff --git a/scripts/EarlyUnloadHandler.lua b/scripts/EarlyUnloadHandler.lua index 1d3cf5c..718690f 100644 --- a/scripts/EarlyUnloadHandler.lua +++ b/scripts/EarlyUnloadHandler.lua @@ -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 @@ -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 @@ -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 @@ -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