From 7f82b6d8424822456bd71f44de8bc7e5f71014a5 Mon Sep 17 00:00:00 2001 From: AmonFlorian Date: Thu, 16 Dec 2021 16:21:07 +0100 Subject: [PATCH] added conveyor+fieldwork fields customizable job types in helper-interface --- BaNe_main.lua | 15 ++++-- gui/BaNeMenuHelperFrame.xml | 25 +++++---- l10n/bane_l10n_de.xml | 6 +++ l10n/bane_l10n_en.xml | 6 +++ modDesc.xml | 2 +- scripts/BaNe_helper.lua | 83 +++++++++++++++++++++++++++-- scripts/gui/BaNeMenuHelperFrame.lua | 55 +++++++++++++++++-- 7 files changed, 168 insertions(+), 24 deletions(-) diff --git a/BaNe_main.lua b/BaNe_main.lua index 7a5109a..8edf2ef 100644 --- a/BaNe_main.lua +++ b/BaNe_main.lua @@ -1,11 +1,12 @@ -- Business administration & national economy (for FS22) -- main faile: BaNe_main.lua -local version = "1.0.0b" +local version = "1.0.1b" -- -- @author [kwa:m] --- @date 15.12.2021 +-- @date 16.12.2021 -- -- Copyright (c) [kwa:m] +-- v1.0.1b - added jobType branch in helper factors -- v1.0.0b - finished helper settings w/ working GUI (able to present as SP beta version) -- v0.6.0a - added customizable nighttime/overtime factors -- v0.5.0a - done GUI general layout, changed initialization process @@ -78,7 +79,9 @@ function BaNe:loadMap() -- wagePerHour helper.wageType = Utils.getNoNil(getXMLInt(xmlFile, key.."#wageType"), g_BaNe.settings.helper.wageType) helper.wageAbsolute = Utils.getNoNil(getXMLFloat(xmlFile, key.."#wageAbsolute"), g_BaNe.settings.helper.wageAbsolute) - helper.wagePercentile = Utils.getNoNil(getXMLFloat(xmlFile, key.."#wagePercentile"), g_BaNe.settings.helper.wagePercentile) + helper.wagePercentile = Utils.getNoNil(getXMLFloat(xmlFile, key.."#wagePercentile"), g_BaNe.settings.helper.wagePercentile) + helper.conveyorPercent = Utils.getNoNil(getXMLFloat(xmlFile, key.."#conveyorPercent"), g_BaNe.settings.helper.conveyorPercent) + helper.fieldworkPercent = Utils.getNoNil(getXMLFloat(xmlFile, key.."#fieldworkPercent"), g_BaNe.settings.helper.fieldworkPercent) -- nighttime factors helper.factorA["enable"] = Utils.getNoNil(getXMLBool(xmlFile, key.."#helper_enableFactor_A"), g_BaNe.settings.helper.factorA["enable"]) helper.factorA["factor"] = math.round(Utils.getNoNil(getXMLFloat(xmlFile, key.."#helper_nightFactor_A"), g_BaNe.settings.helper.factorA["factor"]), 0.1) @@ -253,6 +256,8 @@ function BaNe:saveSettings() setXMLInt(xmlFile, key.."#wageType", g_BaNe.settings.helper.wageType) setXMLFloat(xmlFile, key.."#wageAbsolute", g_BaNe.settings.helper.wageAbsolute) setXMLFloat(xmlFile, key.."#wagePercentile", g_BaNe.settings.helper.wagePercentile) + setXMLFloat(xmlFile, key.."#conveyorPercent", g_BaNe.settings.helper.conveyorPercent) + setXMLFloat(xmlFile, key.."#fieldworkPercent", g_BaNe.settings.helper.fieldworkPercent) -- nighttime factors setXMLBool(xmlFile, key.."#helper_enableFactor_A", g_BaNe.settings.helper.factorA["enable"]) setXMLFloat(xmlFile, key.."#helper_nightFactor_A", g_BaNe.settings.helper.factorA["factor"]) @@ -279,6 +284,8 @@ function BaNe:setDefaults() helper.wageType = 1 -- 1=absolute, 2=percentile helper.wageAbsolute = 800.0 -- 800.0 seems to be the smallest reasonable number (= 0.00022 per ms) helper.wagePercentile = 1.0 -- 1.0 = 100% + helper.conveyorPercent = 1.25 -- 1.25 = 125% + helper.fieldworkPercent = 1.25 -- 1.25 = 125% --helper.wagePerHour = BaNe:getWagePerHour(helper.wageType, helper.wageAbsolute, helper.wagePercentile) helper.factorA = {} helper.factorB = {} @@ -309,7 +316,7 @@ function BaNe:getWagePerHour(wageType,wageAbs,wagePer) if wageType == 1 then ret = wageAbs elseif wageType == 2 then - ret = 0.001 * 3600 * 1000 * wagePer + ret = 0.0004 * 3600 * 1000 * wagePer ret = math.round(ret, 0.1) else print("ooo BaNe:getWagePerHour: couldn't find valid wageType (="..tostring(wageType).." of type '"..tostring(type(wageType)).."')! falling back to 800.0 per Hour absolute! ooo") diff --git a/gui/BaNeMenuHelperFrame.xml b/gui/BaNeMenuHelperFrame.xml index 043f146..4be33c4 100644 --- a/gui/BaNeMenuHelperFrame.xml +++ b/gui/BaNeMenuHelperFrame.xml @@ -40,6 +40,20 @@ + + + + + + + + + + + + + + @@ -90,16 +104,7 @@ - - - + diff --git a/l10n/bane_l10n_de.xml b/l10n/bane_l10n_de.xml index e7ff0ac..edc69af 100644 --- a/l10n/bane_l10n_de.xml +++ b/l10n/bane_l10n_de.xml @@ -28,6 +28,12 @@ + + + + + + diff --git a/l10n/bane_l10n_en.xml b/l10n/bane_l10n_en.xml index 337e3bf..a4c6b25 100644 --- a/l10n/bane_l10n_en.xml +++ b/l10n/bane_l10n_en.xml @@ -28,6 +28,12 @@ + + + + + + diff --git a/modDesc.xml b/modDesc.xml index a3e807f..45ba24e 100644 --- a/modDesc.xml +++ b/modDesc.xml @@ -1,7 +1,7 @@ Florian T. aka kwa:m - 1.0.0b + 1.0.1b <de>BaNe</de> <en>BaNe</en> diff --git a/scripts/BaNe_helper.lua b/scripts/BaNe_helper.lua index f02ae00..648175d 100644 --- a/scripts/BaNe_helper.lua +++ b/scripts/BaNe_helper.lua @@ -15,12 +15,85 @@ -- v0.0.1a - initial alpha release for internal testing (021221) function BaNe:inject_helper() - AIJob.getPricePerMs = Utils.overwrittenFunction(AIJob.getPricePerMs, self.getWagePerMs) + self.AIJobOrigPrice = AIJob.getPricePerMs + self.AIJobConveyorOrigPrice = AIJobConveyor.getPricePerMs + self.AIJobFieldWorkOrigPrice = AIJobFieldWork.getPricePerMs + if AIJob:getPricePerMs() ~= nil then + AIJob.getPricePerMs = Utils.overwrittenFunction(AIJob.getPricePerMs, self.NormalWage) + else + if g_BaNe.debug then + print("ooo BaNe couldn't inject AIJob.getPricePerMs ooo") + end + end + if AIJobConveyor:getPricePerMs() ~= nil then + AIJobConveyor.getPricePerMs = Utils.overwrittenFunction(AIJobConveyor.getPricePerMs, self.ConveyorWage) + else + if g_BaNe.debug then + print("ooo BaNe couldn't inject AIJobConveyor.getPricePerMs ooo") + end + end + if AIJobFieldWork:getPricePerMs() ~= nil then + AIJobFieldWork.getPricePerMs = Utils.overwrittenFunction(AIJobFieldWork.getPricePerMs, self.FieldWorkWage) + else + if g_BaNe.debug then + print("ooo BaNe couldn't inject AIJobFieldWork.getPricePerMs ooo") + end + end end -function BaNe:getWagePerMs(superFunc, ...) +function BaNe:NormalWage(superFunc,...) + local ret = nil + ret = BaNe:getWagePerMs("normal") + if ret ~= nil then + return ret + else + if g_BaNe.debug then + print("ooo BaNe couldn't get the Wage for 'normal' jobs ooo") + end + return superFunc(self,...) + end +end + +function BaNe:ConveyorWage(superFunc,...) + local ret = nil + ret = BaNe:getWagePerMs("conveyor") + if ret ~= nil then + return ret + else + if g_BaNe.debug then + print("ooo BaNe couldn't get the Wage for 'conveyor' jobs ooo") + end + return superFunc(self,...) + end +end + +function BaNe:FieldWorkWage(superFunc,...) + local ret = nil + ret = BaNe:getWagePerMs("fieldwork") + if ret ~= nil then + return ret + else + if g_BaNe.debug then + print("ooo BaNe couldn't get the Wage for 'fieldwork' jobs ooo") + end + return superFunc(self,...) + end +end + +function BaNe:getWagePerMs(jobType) + local jobFactor = nil + if jobType == "normal" then + jobFactor = 1.0 + elseif jobType == "conveyor" then + jobFactor = g_BaNe.settings.helper.conveyorPercent + elseif jobType == "fieldwork" then + jobFactor = g_BaNe.settings.helper.fieldworkPercent + end local wagePerHour = BaNe:getWagePerHour(g_BaNe.settings.helper.wageType, g_BaNe.settings.helper.wageAbsolute, g_BaNe.settings.helper.wagePercentile) - local actPricePerMs = wagePerHour / 60 / 60 / 1000; + local actPricePerMs = nil + if jobFactor ~= nil then + actPricePerMs = jobFactor * wagePerHour / 60 / 60 / 1000 + end local facA, facB = g_BaNe.settings.helper.factorA, g_BaNe.settings.helper.factorB local eFac, nFac1, nFac2 = 1.0, facA["factor"], facB["factor"] local currentTime = g_currentMission.environment.dayTime / 3600000 @@ -110,7 +183,7 @@ function BaNe:getWagePerMs(superFunc, ...) end if g_BaNe.debug then - print("ooo BaNe Debug ... BaNe:getWagePerMs ++ wagePerHour="..tostring(wagePerHour).." ,nFac1="..tostring(nFac1).." ,nFac2="..tostring(nFac2).." ,actPricePerMs="..tostring(actPricePerMs)..", eFac="..tostring(eFac).." ooo") + print("ooo BaNe Debug ... BaNe:getWagePerMs ++ type="..tostring(jobType).." ,wagePerHour="..tostring(wagePerHour).." ,nFac1="..tostring(nFac1).." ,nFac2="..tostring(nFac2).." ,actPricePerMs="..tostring(actPricePerMs)..", eFac="..tostring(eFac).." ooo") print("ooo BaNe Debug ... BaNe:getWagePerMs ++ nFac1 valid from (included):"..string.format("%02d:%02d - %02d:%02d", fhrsA, fminA, thrsA, tminA).." ooo") print("ooo BaNe Debug ... BaNe:getWagePerMs ++ nFac2 valid from (included):"..string.format("%02d:%02d - %02d:%02d", fhrsB, fminB, thrsB, tminB).." ooo") end @@ -119,6 +192,6 @@ function BaNe:getWagePerMs(superFunc, ...) if g_BaNe.debug then print("ooo BaNe Debug ... BaNe:getPricePerMs ++ returning to superFunc() ooo") end - return superFunc(self, ...) + return nil end end \ No newline at end of file diff --git a/scripts/gui/BaNeMenuHelperFrame.lua b/scripts/gui/BaNeMenuHelperFrame.lua index 09c6898..24b037a 100644 --- a/scripts/gui/BaNeMenuHelperFrame.lua +++ b/scripts/gui/BaNeMenuHelperFrame.lua @@ -24,6 +24,8 @@ BaNeMenuHelperFrame.CONTROLS = { "textWageAbsolute", "checkHelperPercentile", "textWagePercentile", + "textConveyorPercentile", + "textFieldWorkPercentile", "checkHelperFactA", "textFactAval", "textFactAfrom", @@ -67,6 +69,9 @@ function BaNeMenuHelperFrame:InitSettings(helper) self.textWageAbsolute:setDisabled(true) self.textWagePercentile:setDisabled(false) end + local tCP, tFWP = self:factorizePercent(self.helper.conveyorPercent,1),self:factorizePercent(self.helper.fieldworkPercent,1) + self.textConveyorPercentile:setText(tCP) + self.textFieldWorkPercentile:setText(tFWP) self.checkHelperFactA:setIsChecked(self.helper.factorA["enable"]) self.textFactAval:setText(string.format("%.1f",self.helper.factorA["factor"])) self.textFactAfrom:setText(string.format("%02d:%02d",self.helper.factorA["from_hours"],self.helper.factorA["from_minutes"])) @@ -90,7 +95,7 @@ function BaNeMenuHelperFrame:factorizePercent(value, dir) local vstring = string.match(tostring(value),"(%d+)") if tonumber(vstring) ~= nil then vstring = tonumber(vstring) / 100 - ret = math.round(tonumber(vstring),0.1) + ret = math.round(tonumber(vstring),0.01) return ret else return nil @@ -246,7 +251,7 @@ function BaNeMenuHelperFrame:onEnterPressedWageValuePer() factor = factor:gsub("%%","") end if tonumber(factor) ~= self.helper.wagePercentile and tonumber(factor) ~= nil then - factor = math.round(tonumber(factor),0.1) + factor = math.round(tonumber(factor),0.01) self.helper.wagePercentile = factor self.textWagePercentile:setText(self:factorizePercent(self.helper.wagePercentile,1)) if g_BaNe.debug then @@ -260,6 +265,48 @@ function BaNeMenuHelperFrame:onEnterPressedWageValuePer() end end +function BaNeMenuHelperFrame:onEnterPressedConveyorValuePer() + local factor = self:factorizePercent(self.textConveyorPercentile.text,0) + local valid = validateString(factor,"%d+%%") + if valid then + factor = factor:gsub("%%","") + end + if tonumber(factor) ~= self.helper.conveyorPercent and tonumber(factor) ~= nil then + factor = math.round(tonumber(factor),0.01) + self.helper.conveyorPercent = factor + self.textConveyorPercentile:setText(self:factorizePercent(self.helper.conveyorPercent,1)) + if g_BaNe.debug then + print("ooo BaNeMenuHelperFrame:onEnterPressedConveyorValuePer, new wage value ="..tostring(self.helper.conveyorPercent).." ooo") + end + else + self.textConveyorPercentile:setText(self:factorizePercent(self.helper.conveyorPercent,1)) + if g_BaNe.debug then + print("ooo BaNeMenuHelperFrame:onEnterPressedConveyorValuePer, old factor value ="..tostring(self.helper.conveyorPercent).." vs new factor ="..tostring(factor).." ooo") + end + end +end + +function BaNeMenuHelperFrame:onEnterPressedFieldWorkValuePer() + local factor = self:factorizePercent(self.textFieldWorkPercentile.text,0) + local valid = validateString(factor,"%d+%%") + if valid then + factor = factor:gsub("%%","") + end + if tonumber(factor) ~= self.helper.fieldworkPercent and tonumber(factor) ~= nil then + factor = math.round(tonumber(factor),0.01) + self.helper.fieldworkPercent = factor + self.textFieldWorkPercentile:setText(self:factorizePercent(self.helper.fieldworkPercent,1)) + if g_BaNe.debug then + print("ooo BaNeMenuHelperFrame:onEnterPressedFieldWorkValuePer, new wage value ="..tostring(self.helper.fieldworkPercent).." ooo") + end + else + self.textFieldWorkPercentile:setText(self:factorizePercent(self.helper.fieldworkPercent,1)) + if g_BaNe.debug then + print("ooo BaNeMenuHelperFrame:onEnterPressedFieldWorkValuePer, old factor value ="..tostring(self.helper.fieldworkPercent).." vs new factor ="..tostring(factor).." ooo") + end + end +end + function BaNeMenuHelperFrame:onClickHelperFactA(state) self.helper.factorA["enable"] = self.checkHelperFactA:getIsChecked() if g_BaNe.debug then @@ -270,7 +317,7 @@ end function BaNeMenuHelperFrame:onEnterPressedFactAValue() local newVal = self.textFactAval.text if newVal ~= self.helper.factorA["factor"] and tonumber(newVal) ~= nil then - newVal = math.round(tonumber(newVal),0.1) + newVal = math.round(tonumber(newVal),0.01) self.helper.factorA["factor"] = newVal self.textFactAval:setText(string.format("%.1f",self.helper.factorA["factor"])) if g_BaNe.debug then @@ -340,7 +387,7 @@ end function BaNeMenuHelperFrame:onEnterPressedFactBValue() local newVal = self.textFactBval.text if newVal ~= self.helper.factorB["factor"] and tonumber(newVal) ~= nil then - newVal = math.round(tonumber(newVal),0.1) + newVal = math.round(tonumber(newVal),0.01) self.helper.factorB["factor"] = newVal self.textFactBval:setText(string.format("%.1f",self.helper.factorB["factor"])) if g_BaNe.debug then