Skip to content

Commit

Permalink
added conveyor+fieldwork fields
Browse files Browse the repository at this point in the history
customizable job types in helper-interface
  • Loading branch information
AmonFlorian committed Dec 16, 2021
1 parent dd4463c commit 7f82b6d
Show file tree
Hide file tree
Showing 7 changed files with 168 additions and 24 deletions.
15 changes: 11 additions & 4 deletions BaNe_main.lua
Original file line number Diff line number Diff line change
@@ -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
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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"])
Expand All @@ -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 = {}
Expand Down Expand Up @@ -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")
Expand Down
25 changes: 15 additions & 10 deletions gui/BaNeMenuHelperFrame.xml
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,20 @@
<GuiElement type="text" baneTextID="uiBaNe_tt_helperWagePercentile" profile="multiTextOptionSettingsTooltip" text="tt_helperWagePercentile" />
</GuiElement>

<GuiElement type="text" profile="settingsMenuSubtitle" baneTextID="uiBaNe_helperJobTypes" text="helperJobTypes" />

<GuiElement type="empty" profile="ingameMenuGameSettingsTextInputWrapper">
<GuiElement type="textInput" profile="ingameMenuGameSettingsTextInput" id="textConveyorPercentile" onEnterPressed="onEnterPressedConveyorValuePer" imeKeyboardType="normal" />
<GuiElement type="text" baneTextID="uiBaNe_helperConveyorPercentile" profile="multiTextOptionSettingsTitle" text="helperConveyorPercentile"/>
<GuiElement type="text" baneTextID="uiBaNe_tt_helperConveyorPercentile" profile="multiTextOptionSettingsTooltip" text="tt_helperConveyorPercentile" />
</GuiElement>

<GuiElement type="empty" profile="ingameMenuGameSettingsTextInputWrapper">
<GuiElement type="textInput" profile="ingameMenuGameSettingsTextInput" id="textFieldWorkPercentile" onEnterPressed="onEnterPressedFieldWorkValuePer" imeKeyboardType="normal" />
<GuiElement type="text" baneTextID="uiBaNe_helperFieldWorkPercentile" profile="multiTextOptionSettingsTitle" text="helperFieldWorkPercentile"/>
<GuiElement type="text" baneTextID="uiBaNe_tt_helperFieldWorkPercentile" profile="multiTextOptionSettingsTooltip" text="tt_helperFieldworkPercentile" />
</GuiElement>

<GuiElement type="text" profile="settingsMenuSubtitle" baneTextID="uiBaNe_helperOTFactA" text="helperOTFactA" />

<GuiElement type="checkedOption" profile="multiTextOptionSettings" onClick="onClickHelperFactA" id="checkHelperFactA">
Expand Down Expand Up @@ -90,16 +104,7 @@
<GuiElement type="textInput" profile="ingameMenuGameSettingsTextInput" id="textFactBto" onEnterPressed="onEnterPressedFactBTimeTo" imeKeyboardType="normal" />
<GuiElement type="text" baneTextID="uiBaNe_helperFactBto" profile="multiTextOptionSettingsTitle" text="helperFactBto"/>
<GuiElement type="text" baneTextID="uiBaNe_tt_helperFactBto" profile="multiTextOptionSettingsTooltip" text="tt_helperFactBto" />
</GuiElement>

<!-- <GuiElement type="checkedOption" profile="multiTextOptionSettings" onClick="onClickCheckbox" id="checkHelpIcons">
<GuiElement type="button" profile="multiTextOptionSettingsLeft" />
<GuiElement type="button" profile="multiTextOptionSettingsRight"/>
<GuiElement type="text" profile="multiTextOptionSettingsText" />
<GuiElement type="text" profile="multiTextOptionSettingsTitle" text="$l10n_setting_helpIconsOnMap"/>
<GuiElement type="bitmap" profile="multiTextOptionSettingsBg" />
<GuiElement type="text" profile="multiTextOptionSettingsTooltip" text="$l10n_toolTip_helpIcons" />
</GuiElement> -->
</GuiElement>
</GuiElement>
</GuiElement>
</GuiElement>
Expand Down
6 changes: 6 additions & 0 deletions l10n/bane_l10n_de.xml
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,12 @@
<text name="uiBaNe_helperWagePercentile" text="Arbeitslohn in Prozent."/>
<text name="uiBaNe_tt_helperWagePercentile" text="Gezahlter Arbeitslohn in Prozent vom Originalwert. (!FORMAT: ohne %-Zeichen!)"/>

<text name="uiBaNe_helperJobTypes" text="Arbeitstyp-Faktoren"/>
<text name="uiBaNe_helperConveyorPercentile" text="Förderbänder"/>
<text name="uiBaNe_tt_helperConveyorPercentile" text="Arbeitslohn für Förderbänder in Prozent. (Std: 125%)"/>
<text name="uiBaNe_helperFieldWorkPercentile" text="Feldarbeit"/>
<text name="uiBaNe_tt_helperFieldWorkPercentile" text="Arbeitslohn für Feldarbeit in Prozent. (Std: 125%)"/>

<text name="uiBaNe_helperOTFactA" text="Faktor für Arbeitszeit (A)"/>
<text name="uiBaNe_helperFactAen" text="Aktivieren"/>
<text name="uiBaNe_tt_helperFactAen" text="Aktiviert die unten angegebenen Einstellungen."/>
Expand Down
6 changes: 6 additions & 0 deletions l10n/bane_l10n_en.xml
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,12 @@
<text name="uiBaNe_helperWagePercentile" text="Wage in Percent"/>
<text name="uiBaNe_tt_helperWagePercentile" text="Paid wage per hour in percent of default value. (!FORMAT: without %-char!)"/>

<text name="uiBaNe_helperJobTypes" text="Job Type Factors"/>
<text name="uiBaNe_helperConveyorPercentile" text="Conveyors"/>
<text name="uiBaNe_tt_helperConveyorPercentile" text="Accounted wage for conveyors in percent. (Def: 125%)"/>
<text name="uiBaNe_helperFieldWorkPercentile" text="Field Work"/>
<text name="uiBaNe_tt_helperFieldWorkPercentile" text="Accounted wage for conveyors in percent. (Def: 125%)"/>

<text name="uiBaNe_helperOTFactA" text="Factor for Working Hours (A)"/>
<text name="uiBaNe_helperFactAen" text="Enable"/>
<text name="uiBaNe_tt_helperFactAen" text="Enables the set parameters below."/>
Expand Down
2 changes: 1 addition & 1 deletion modDesc.xml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<?xml version="1.0" encoding="utf-8" standalone="no" ?>
<modDesc descVersion="61">
<author>Florian T. aka kwa:m</author>
<version>1.0.0b</version>
<version>1.0.1b</version>
<title>
<de>BaNe</de>
<en>BaNe</en>
Expand Down
83 changes: 78 additions & 5 deletions scripts/BaNe_helper.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand All @@ -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
55 changes: 51 additions & 4 deletions scripts/gui/BaNeMenuHelperFrame.lua
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@ BaNeMenuHelperFrame.CONTROLS = {
"textWageAbsolute",
"checkHelperPercentile",
"textWagePercentile",
"textConveyorPercentile",
"textFieldWorkPercentile",
"checkHelperFactA",
"textFactAval",
"textFactAfrom",
Expand Down Expand Up @@ -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"]))
Expand All @@ -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
Expand Down Expand Up @@ -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
Expand All @@ -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
Expand All @@ -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
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit 7f82b6d

Please sign in to comment.