From e78f1a334831159235ae2846dbef26f75784cd5e Mon Sep 17 00:00:00 2001
From: schwiti6190 <58079399+schwiti6190@users.noreply.github.com>
Date: Tue, 17 Oct 2023 11:47:54 +0200
Subject: [PATCH 1/7] WIP Improved row target selection based on closest row
with most filllevel
---
scripts/silo/BunkerSiloVehicleController.lua | 142 ++++++++++++++-----
1 file changed, 109 insertions(+), 33 deletions(-)
diff --git a/scripts/silo/BunkerSiloVehicleController.lua b/scripts/silo/BunkerSiloVehicleController.lua
index ff013ec0f..18478a098 100644
--- a/scripts/silo/BunkerSiloVehicleController.lua
+++ b/scripts/silo/BunkerSiloVehicleController.lua
@@ -95,7 +95,7 @@ function CpBunkerSiloVehicleController:getTarget(width)
widthCount = math.ceil(siloWidth/width)
local unitWidth = siloWidth/widthCount
self:debug('Bunker width: %.1f, working width: %.1f (passed in), unit width: %.1f', siloWidth, width, unitWidth)
- self:setupMap(width, unitWidth, widthCount)
+ self:generateMaps(width, unitWidth, widthCount)
local targetLine = self:getNextLine(widthCount, width)
self:debug("target line: %d", targetLine)
@@ -174,18 +174,6 @@ function CpBunkerSiloVehicleController:getFirstLineApproach(numLines, width)
return MathUtil.clamp(line, 1, numLines)
end
---- Setups a map with all lanes mostly for debugging for now.
----@param width number
----@param unitWidth number
----@param widthCount number
-function CpBunkerSiloVehicleController:setupMap(width, unitWidth, widthCount)
- self.map = {}
- local x, z, dx, dz
- for i = 1, widthCount do
- x, z, dx, dz = self:getPositionsForLine(i, width, widthCount, unitWidth)
- table.insert(self.map, {x, z, dx, dz})
- end
-end
function CpBunkerSiloVehicleController:debug(...)
CpUtil.debugVehicle(self.debugChannel, self.vehicle, ...)
@@ -199,11 +187,20 @@ end
function CpBunkerSiloVehicleController:draw()
if self:isDebugEnabled() then
if self.map then
- for _, line in pairs(self.map) do
+ for i, lineData in ipairs(self.map) do
+ local line = self.lineMap[i]
local x, z, dx, dz = unpack(line)
local y = getTerrainHeightAtWorldPos(g_currentMission.terrainRootNode, x, 0, z)
local dy = getTerrainHeightAtWorldPos(g_currentMission.terrainRootNode, dx, 0, dz)
drawDebugLine(x, y + 2, z, 1, 0, 1, dx, dy + 2, dz, 0, 1, 1)
+ local numRows = #lineData
+ for j, data in ipairs(lineData) do
+ local x1, z1, x2, z2, x3, z3 = unpack(data)
+ DebugUtil.drawDebugAreaRectangle(x1, y + 3, z1,
+ x2, y + 3, z2,
+ x3, y + 3, z3,
+ false, 0.5 , 0.5, j/numRows, 0.2)
+ end
end
end
end
@@ -228,6 +225,35 @@ function CpBunkerSiloVehicleController:isEndReached(node, margin)
return false, math.huge
end
+--- Generates a silo map with lines and a map with rectangle tiles.
+---@param width number
+---@param unitWidth number
+---@param widthCount number
+function CpBunkerSiloVehicleController:generateMaps(width, unitWidth, widthCount)
+ self.lineMap = {}
+ self.map = {}
+ local x, z, dx, dz
+ local x1, z1, x2, z2, x3, z3
+ local lengthCount = math.ceil(self.silo:getLength() / unitWidth)
+ local unitLength = self.silo:getLength() / lengthCount
+ local lenDirX, lenDirZ = self.silo:getLengthDirection()
+ local widthDirX, widthDirZ = self.silo:getWidthDirection()
+ local sx, sz = self.silo:getStartPosition()
+ for i = 1, widthCount do
+ x, z, dx, dz = self:getPositionsForLine(i, width,
+ widthCount, unitWidth)
+ table.insert(self.lineMap, {x, z, dx, dz})
+ self.map[i] = {}
+ for j=0, lengthCount - 1 do
+ x1 = sx + j * lenDirX * unitLength + (i - 1) * widthDirX * unitWidth
+ z1 = sz + j * lenDirZ * unitLength + (i - 1) * widthDirZ * unitWidth
+ x2, z2 = x1 + widthDirX * unitWidth, z1 + widthDirZ * unitWidth
+ x3, z3 = x1 + lenDirX * unitLength, z1 + lenDirZ * unitLength
+ table.insert(self.map[i], {x1, z1, x2, z2, x3, z3})
+ end
+ end
+end
+
--- Silo controller for a Bunker silo leveler driver.
--- Handles the bunker silo lines and the automatic
--- selection of the next line for a new approach.
@@ -314,7 +340,6 @@ function CpBunkerSiloLoaderController:init(silo, vehicle, driveStrategy)
CpBunkerSiloVehicleController.init(self, silo, vehicle,
driveStrategy, vehicle:getAIDirectionNode())
-
local sx, sz = self.silo:getStartPosition()
local hx, hz = self.silo:getHeightPosition()
local dx, _, dz = getWorldTranslation(vehicle:getAIDirectionNode())
@@ -333,29 +358,80 @@ function CpBunkerSiloLoaderController:init(silo, vehicle, driveStrategy)
end
+--- Gets the next line with the most fill level.
+---@param width number
+---@return number next lane to take.
+function CpBunkerSiloLoaderController:getLineWithTheMostFillLevel(width)
+ local bestLine, mostFillLevel, fillType, fillLevel = 1, 0, nil, 0
+ local numLengthTiles = #self.map[1]
+ self.bestLoadTarget = nil
+ local bestRow = math.huge
+ local firstRow, lastRow, deltaRow = 1, numLengthTiles, 1
+ if self.isInverted then
+ bestRow = 1
+ firstRow, lastRow, deltaRow = numLengthTiles, 1, -1
+ end
+ for row = firstRow, lastRow, deltaRow do
+ for line, lineData in ipairs(self.map) do
+ local sx, sz, wx, wz, hx, hz = unpack(lineData[row])
+ fillType = DensityMapHeightUtil.getFillTypeAtArea(sx, sz, wx, wz, hx, hz)
+ if fillType and fillType ~= 0 then
+ fillLevel = DensityMapHeightUtil.getFillLevelAtArea(
+ fillType, sx, sz, wx, wz, hx, hz)
+ self:debug("Line(%d) and row(%d) has %.2f of %s", line, row, fillLevel,
+ g_fillTypeManager:getFillTypeByIndex(fillType).title)
+ if fillLevel > mostFillLevel then
+ --- Searches for the closest row with the most fill level
+ if self.isInverted then
+ if row >= bestRow then
+ self:debug("New best line %d with row %d", line, row)
+ mostFillLevel = fillLevel
+ bestLine = line
+ bestRow = row
+ fillType = fillType
+ self.bestLoadTarget = {
+ sx, sz, wx, wz, hx, hz
+ }
+ end
+ elseif row <= bestRow then
+ self:debug("New best line %d with row %d", line, row)
+ mostFillLevel = fillLevel
+ bestLine = line
+ bestRow = row
+ fillType = fillType
+ self.bestLoadTarget = {
+ sx, sz, wx, wz, hx, hz
+ }
+ end
+ end
+
+ end
+ end
+ end
+ return bestLine
+end
+
--- Gets the next line with the most fill level.
---@param numLines number
---@param width number
---@return number next lane to take.
function CpBunkerSiloLoaderController:getNextLine(numLines, width)
- local dirXWidth, dirZWidth = self.silo:getWidthDirection()
- local bestLane, mostFillLevel, fillType = 1, 0
- for i, line in ipairs(self.map) do
-
- local sx, sz = line[1] + dirXWidth * - width/2, line[2] + dirZWidth * - width/2
- local wx, wz = line[1] + dirXWidth * width/2, line[2] + dirZWidth * width/2
- local hx, hz = line[3] + dirXWidth * - width/2 , line[4] + dirZWidth * - width/2
-
- local fillType = DensityMapHeightUtil.getFillTypeAtArea(sx, sz, wx, wz, hx, hz)
- if fillType and fillType ~= 0 then
- local fillLevel = DensityMapHeightUtil.getFillLevelAtArea(fillType, sx, sz, wx, wz, hx, hz)
- self:debug("Lane(%d) has %.2f of %s", i, fillLevel, g_fillTypeManager:getFillTypeByIndex(fillType).title)
- if fillLevel > mostFillLevel then
- mostFillLevel = fillLevel
- bestLane = i
- fillType = fillType
- end
+ return self:getLineWithTheMostFillLevel(width)
+end
+
+function CpBunkerSiloLoaderController:draw()
+ if self:isDebugEnabled() then
+ if self.bestLoadTarget then
+ local x1, z1, x2, z2, x3, z3 = unpack(self.bestLoadTarget)
+ local y = getTerrainHeightAtWorldPos(g_currentMission.terrainRootNode, x1, 0, z1)
+ DebugUtil.drawDebugAreaRectangle(x1, y + 3.5, z1,
+ x2, y + 3.5, z2,
+ x3, y + 3.5, z3,
+ false, 0 , 1, 0)
+ DebugUtil.drawDebugLine(x2, y + 3.5, z2,
+ x3, y + 3.5, z3,
+ 0, 1, 0)
end
end
- return bestLane
+ CpBunkerSiloVehicleController.draw(self)
end
\ No newline at end of file
From 425d780c7c0b1ebfcf2ffe882167890ef72ffba8 Mon Sep 17 00:00:00 2001
From: schwiti6190 <58079399+schwiti6190@users.noreply.github.com>
Date: Tue, 17 Oct 2023 15:35:48 +0200
Subject: [PATCH 2/7] Some more adjustements for loading inside of a bunker
silo
---
scripts/ai/AIDriveStrategyShovelSiloLoader.lua | 12 ++++++++----
scripts/silo/BunkerSiloVehicleController.lua | 15 +++++++++++++++
scripts/silo/BunkerSiloWrapper.lua | 4 +++-
3 files changed, 26 insertions(+), 5 deletions(-)
diff --git a/scripts/ai/AIDriveStrategyShovelSiloLoader.lua b/scripts/ai/AIDriveStrategyShovelSiloLoader.lua
index 4fb3a95c6..b73ee5e72 100644
--- a/scripts/ai/AIDriveStrategyShovelSiloLoader.lua
+++ b/scripts/ai/AIDriveStrategyShovelSiloLoader.lua
@@ -184,7 +184,7 @@ function AIDriveStrategyShovelSiloLoader:setAllStaticParameters()
Markers.setMarkerNodes(self.vehicle)
self.frontMarkerNode, self.backMarkerNode, self.frontMarkerDistance, self.backMarkerDistance =
Markers.getMarkerNodes(self.vehicle)
- self.siloEndProximitySensor = SingleForwardLookingProximitySensorPack(self.vehicle, self.shovelController:getShovelNode(), 5, 1)
+ self.siloEndProximitySensor = SingleForwardLookingProximitySensorPack(self.vehicle, self.shovelController:getShovelNode(), 1, 1)
self.heapNode = CpUtil.createNode("heapNode", 0, 0, 0, nil)
self.lastTrailerSearch = 0
self.isStuckTimer = Timer.new(self.isStuckMs)
@@ -275,9 +275,13 @@ function AIDriveStrategyShovelSiloLoader:getDriveData(dt, vX, vY, vZ)
self.isStuckTimer:startIfNotRunning()
end
local _, _, closestObject = self.siloEndProximitySensor:getClosestObjectDistanceAndRootVehicle()
- local isEndReached, maxSpeed = self.siloController:isEndReached(self.shovelController:getShovelNode(), 0)
- if self.silo:isTheSameSilo(closestObject) or isEndReached then
- self:debug("End wall detected or bunker silo end is reached.")
+ local isEndReached, maxSpeed = self.siloController:isEndReached(self.shovelController:getShovelNode(), 2)
+ self:setMaxSpeed(maxSpeed)
+ if isEndReached then
+ self:debug("End of the silo or heap was detected.")
+ self:startDrivingOutOfSilo()
+ elseif self.silo:isTheSameSilo(closestObject) and self.silo:isNodeInSilo(self.shovelController:getShovelNode()) then
+ self:debug("End wall of the silo was detected.")
self:startDrivingOutOfSilo()
end
if self.shovelController:isFull() then
diff --git a/scripts/silo/BunkerSiloVehicleController.lua b/scripts/silo/BunkerSiloVehicleController.lua
index 18478a098..9c29a5a51 100644
--- a/scripts/silo/BunkerSiloVehicleController.lua
+++ b/scripts/silo/BunkerSiloVehicleController.lua
@@ -419,6 +419,21 @@ function CpBunkerSiloLoaderController:getNextLine(numLines, width)
return self:getLineWithTheMostFillLevel(width)
end
+
+--- Is the end of the silo reached.
+---@param node number
+---@param margin number
+---@return boolean end reached?
+---@return number distance to the end
+function CpBunkerSiloLoaderController:isEndReached(node, margin)
+ if self.drivingTarget then
+ local dx, dz = unpack(self.drivingTarget[2])
+ local _, _, z = worldToLocal(node, dx, 0, dz)
+ return z < margin, MathUtil.clamp(z * 2, 5, math.huge)
+ end
+ return false, math.huge
+end
+
function CpBunkerSiloLoaderController:draw()
if self:isDebugEnabled() then
if self.bestLoadTarget then
diff --git a/scripts/silo/BunkerSiloWrapper.lua b/scripts/silo/BunkerSiloWrapper.lua
index c221111a5..000c0d66c 100644
--- a/scripts/silo/BunkerSiloWrapper.lua
+++ b/scripts/silo/BunkerSiloWrapper.lua
@@ -205,8 +205,9 @@ function CpSilo:getTotalFillLevel()
return 0
end
-function CpSilo:isTheSameSilo()
+function CpSilo:isTheSameSilo(object)
--- override
+ return false
end
--- Heap Bunker Silo
@@ -339,6 +340,7 @@ function CpBunkerSilo:isTheSameSilo(object)
end
end
end
+ return false
end
function CpBunkerSilo:getFrontArea(length, sideOffset)
From 4fcef26a5490be95bd780937f4f59074b8a62fac Mon Sep 17 00:00:00 2001
From: schwiti6190 <58079399+schwiti6190@users.noreply.github.com>
Date: Tue, 17 Oct 2023 16:07:11 +0200
Subject: [PATCH 3/7] Bug fix
---
scripts/silo/BunkerSiloVehicleController.lua | 6 ++++--
1 file changed, 4 insertions(+), 2 deletions(-)
diff --git a/scripts/silo/BunkerSiloVehicleController.lua b/scripts/silo/BunkerSiloVehicleController.lua
index 9c29a5a51..369e54c38 100644
--- a/scripts/silo/BunkerSiloVehicleController.lua
+++ b/scripts/silo/BunkerSiloVehicleController.lua
@@ -428,8 +428,10 @@ end
function CpBunkerSiloLoaderController:isEndReached(node, margin)
if self.drivingTarget then
local dx, dz = unpack(self.drivingTarget[2])
- local _, _, z = worldToLocal(node, dx, 0, dz)
- return z < margin, MathUtil.clamp(z * 2, 5, math.huge)
+ local _, _, zOffset = localToLocal(node, AIUtil.getDirectionNode(self.vehicle), 0, 0, 0)
+ local _, _, z = worldToLocal(AIUtil.getDirectionNode(self.vehicle), dx, 0, dz)
+ self:debug("Silo/heap end offset %.1f", z-zOffset)
+ return z - zOffset < margin, MathUtil.clamp(z * 2, 5, math.huge)
end
return false, math.huge
end
From 283df35456af4728aa7558b5e813a3eda3ac68d4 Mon Sep 17 00:00:00 2001
From: schwiti6190 <58079399+schwiti6190@users.noreply.github.com>
Date: Wed, 18 Oct 2023 12:08:53 +0200
Subject: [PATCH 4/7] Bug fix for bunker silo driver #2783
---
scripts/ai/AIDriveStrategyBunkerSilo.lua | 19 +++++--------------
scripts/ai/controllers/LevelerController.lua | 6 +++---
2 files changed, 8 insertions(+), 17 deletions(-)
diff --git a/scripts/ai/AIDriveStrategyBunkerSilo.lua b/scripts/ai/AIDriveStrategyBunkerSilo.lua
index c7de9ef7c..8880e1558 100644
--- a/scripts/ai/AIDriveStrategyBunkerSilo.lua
+++ b/scripts/ai/AIDriveStrategyBunkerSilo.lua
@@ -47,16 +47,11 @@ function AIDriveStrategyBunkerSilo.new(customMt)
AIDriveStrategyCourse.initStates(self, AIDriveStrategyBunkerSilo.myStates)
self.state = self.states.DRIVING_TO_SILO
- -- course offsets dynamically set by the AI and added to all tool and other offsets
- self.aiOffsetX, self.aiOffsetZ = 0, 0
self.debugChannel = CpDebug.DBG_SILO
- ---@type ImplementController[]
- self.controllers = {}
self.silo = nil
self.siloController = nil
self.drivingForwardsIntoSilo = true
self.turnNode = CpUtil.createNode("turnNode", 0, 0, 0)
-
self.isStuckTimer = Timer.new(self.isStuckMs)
self.driveIntoSiloAttempts = 0
@@ -177,7 +172,7 @@ function AIDriveStrategyBunkerSilo:setAllStaticParameters()
else
self:startDrivingTemporaryOutOfSilo()
end
- elseif self.siloController:hasNearbyUnloader() and self:isDrivingToParkPositionAllowed() then
+ elseif self.state == self.states.DRIVING_INTO_SILO and self.siloController:hasNearbyUnloader() and self:isDrivingToParkPositionAllowed() then
self:debug("Found an unloader nearby and is stuck, so immediately leave the silo.")
self:startDrivingOutOfSilo()
end
@@ -292,15 +287,11 @@ end
function AIDriveStrategyBunkerSilo:update(dt)
AIDriveStrategyBunkerSilo:superClass().update(self, dt)
self:updateImplementControllers(dt)
-
if CpDebug:isChannelActive(self.debugChannel, self.vehicle) then
- if self.course then
- -- TODO_22 check user setting
- if self.course:isTemporary() then
- self.course:draw()
- elseif self.ppc:getCourse():isTemporary() then
- self.ppc:getCourse():draw()
- end
+ if self.course and self.course:isTemporary() then
+ self.course:draw()
+ elseif self.ppc:getCourse():isTemporary() then
+ self.ppc:getCourse():draw()
end
if self.siloEndDetectionMarker ~= nil then
DebugUtil.drawDebugNode(self.siloEndDetectionMarker, "siloEndDetectionMarker", false, 1)
diff --git a/scripts/ai/controllers/LevelerController.lua b/scripts/ai/controllers/LevelerController.lua
index 24c0739b1..b72c8f3fb 100644
--- a/scripts/ai/controllers/LevelerController.lua
+++ b/scripts/ai/controllers/LevelerController.lua
@@ -112,13 +112,13 @@ function LevelerController:setCylinderedLevelerRotation(dt, offsetDeg)
local _, dy, _ = localToWorld(self.levelerTool.node, 0, 0, 0)
local dx, _, dz = localToWorld(self.levelerNode, 0, 0, 0)
local _, ny, _ = worldToLocal(self.levelerTool.node, dx, dy, dz)
- self:debug("dist: %.2f, ny: %.2f", dist, ny)
+-- self:debug("dist: %.2f, ny: %.2f", dist, ny)
local targetRot = math.asin(ny/dist) + math.rad(offsetDeg)
if ny > 0 then
targetRot = -math.asin(-ny/dist) + math.rad(offsetDeg)
end
- self:debug("curRot: %.2f, targetRot: %.2f, offset: %.2f, rotMin: %.2f, rotMax: %.2f",
- angle, targetRot, math.rad(offsetDeg), self.levelerTool.rotMin, self.levelerTool.rotMax)
+-- self:debug("curRot: %.2f, targetRot: %.2f, offset: %.2f, rotMin: %.2f, rotMax: %.2f",
+-- angle, targetRot, math.rad(offsetDeg), self.levelerTool.rotMin, self.levelerTool.rotMax)
return ImplementUtil.moveMovingToolToRotation(self.levelerToolVehicle, self.levelerTool, dt,
MathUtil.clamp(angle - targetRot, self.levelerTool.rotMin, self.levelerTool.rotMax))
From cb5983cdf17e4f7905c2dfdf93dfdd446a27eb66 Mon Sep 17 00:00:00 2001
From: schwiti6190 <58079399+schwiti6190@users.noreply.github.com>
Date: Wed, 18 Oct 2023 12:38:21 +0200
Subject: [PATCH 5/7] Added leveler height offset setting
---
config/MasterTranslations.xml | 8 ++++++++
config/VehicleSettingsSetup.xml | 2 ++
scripts/ai/controllers/LevelerController.lua | 12 +++++++++---
scripts/gui/hud/CpBunkerSiloWorkerHudPage.lua | 11 ++++++++++-
scripts/specializations/CpVehicleSettings.lua | 19 ++++++++++++++-----
5 files changed, 43 insertions(+), 9 deletions(-)
diff --git a/config/MasterTranslations.xml b/config/MasterTranslations.xml
index ca4f565f6..3fb809b63 100644
--- a/config/MasterTranslations.xml
+++ b/config/MasterTranslations.xml
@@ -687,6 +687,14 @@
+
+
+
+
+
+
+
+
diff --git a/config/VehicleSettingsSetup.xml b/config/VehicleSettingsSetup.xml
index cc2372857..6fb2f16f1 100644
--- a/config/VehicleSettingsSetup.xml
+++ b/config/VehicleSettingsSetup.xml
@@ -79,6 +79,8 @@
+
diff --git a/scripts/ai/controllers/LevelerController.lua b/scripts/ai/controllers/LevelerController.lua
index b72c8f3fb..d75380aaf 100644
--- a/scripts/ai/controllers/LevelerController.lua
+++ b/scripts/ai/controllers/LevelerController.lua
@@ -44,6 +44,13 @@ function LevelerController:getDriveData()
return nil, nil, nil, maxSpeed
end
+function LevelerController:getTargetTerrainHeight()
+ local x, y, z = getWorldTranslation(self.levelerNode)
+ local terrainHeight = getTerrainHeightAtWorldPos(g_currentMission.terrainRootNode, x, y, z)
+ --- Applies the setting offset, so the leveler is not directly on the ground.
+ return terrainHeight + self.settings.levelerHeightOffset:getValue()
+end
+
--- Used when a wheel loader or a snowcat is used.
--- Finds the correct cylindered axis.
function LevelerController:setupCylinderedHeight()
@@ -87,7 +94,7 @@ end
--- Used when a wheel loader or a snowcat is used.
function LevelerController:updateCylinderedHeight(dt)
local x, y, z = getWorldTranslation(self.levelerNode)
- local terrainHeight = getTerrainHeightAtWorldPos(g_currentMission.terrainRootNode, x, y, z)
+ local terrainHeight = self:getTargetTerrainHeight()
local nx, ny, nz = localToWorld(self.levelerNode, 0, 0, 1)
local nTerrainHeight = getTerrainHeightAtWorldPos(g_currentMission.terrainRootNode, nx, ny, nz)
local targetHeight = self:getTargetShieldHeight()
@@ -149,7 +156,7 @@ function LevelerController:updateHeight(dt)
local jointDesc = spec.jointDesc
if self.driveStrategy:isLevelerLoweringAllowed() then
local x, y, z = getWorldTranslation(self.levelerNode)
- local terrainHeight = getTerrainHeightAtWorldPos(g_currentMission.terrainRootNode, x, y, z)
+ local terrainHeight = self:getTargetTerrainHeight()
---target height of leveling, fill up is 0 by default
local targetHeight = self:getTargetShieldHeight()
@@ -225,7 +232,6 @@ end
function LevelerController:updateShieldHeightOffset()
--- A small reduction to the offset, as the shield should be lifted after a only a bit silage.
local smallOffsetReduction = 0.3
-
--self.shieldHeightOffset = MathUtil.clamp(-self.levelerSpec.lastForce/self.levelerSpec.maxForce - smallOffsetReduction, 0, 1)
end
diff --git a/scripts/gui/hud/CpBunkerSiloWorkerHudPage.lua b/scripts/gui/hud/CpBunkerSiloWorkerHudPage.lua
index 60e60011a..cb5187899 100644
--- a/scripts/gui/hud/CpBunkerSiloWorkerHudPage.lua
+++ b/scripts/gui/hud/CpBunkerSiloWorkerHudPage.lua
@@ -23,6 +23,10 @@ function CpBunkerSiloWorkerHudPageElement:setupElements(baseHud, vehicle, lines,
}
self.driveDirectionBtn:setCallback(callback, callback)
+ --- Leveler height offset.
+ self.levelerHeightOffsetBtn = baseHud:addLineTextButton(self, 4, CpBaseHud.defaultFontSize,
+ vehicle:getCpSettings().levelerHeightOffset)
+
--- Waiting at park position
local x, y = unpack(lines[1].left)
local xRight,_ = unpack(lines[1].right)
@@ -78,7 +82,12 @@ function CpBunkerSiloWorkerHudPageElement:updateContent(vehicle, status)
local driveDirection = vehicle:getCpBunkerSiloWorkerJobParameters().drivingForwardsIntoSilo
self.driveDirectionBtn:setTextDetails(driveDirection:getTitle(), driveDirection:getString())
self.driveDirectionBtn:setVisible(driveDirection:getIsVisible())
- self.driveDirectionBtn:setDisabled(driveDirection:getIsDisabled())
+ self.driveDirectionBtn:setDisabled(not driveDirection:getIsVisible())
+
+ local heightOffset = vehicle:getCpSettings().levelerHeightOffset
+ self.levelerHeightOffsetBtn:setTextDetails(heightOffset:getTitle(), heightOffset:getString())
+ self.levelerHeightOffsetBtn:setVisible(heightOffset:getIsVisible())
+ self.levelerHeightOffsetBtn:setDisabled(heightOffset:getIsDisabled())
local waitAt = vehicle:getCpBunkerSiloWorkerJobParameters().waitAtParkPosition
self.waitAtBtn:setTextDetails(waitAt:getTitle(), waitAt:getString())
diff --git a/scripts/specializations/CpVehicleSettings.lua b/scripts/specializations/CpVehicleSettings.lua
index 7d2e397c8..93c78ba80 100644
--- a/scripts/specializations/CpVehicleSettings.lua
+++ b/scripts/specializations/CpVehicleSettings.lua
@@ -393,7 +393,8 @@ function CpVehicleSettings:setAutomaticBaleCollectorOffset()
end
function CpVehicleSettings:isLoadingShovelOffsetSettingVisible()
- return self:getCanStartCpSiloLoaderWorker() and not AIUtil.hasChildVehicleWithSpecialization(self, ConveyorBelt)
+ return self:getCanStartCpSiloLoaderWorker() and not AIUtil.hasChildVehicleWithSpecialization(self, ConveyorBelt) or
+ AIUtil.hasChildVehicleWithSpecialization(self, Leveler)
end
function CpVehicleSettings:isLoadingShovelOffsetSettingDisabled()
@@ -402,10 +403,18 @@ end
function CpVehicleSettings:onCpLoadingShovelOffsetSettingChanged()
local shovels, found = AIUtil.getAllChildVehiclesWithSpecialization(self, Shovel)
- if not found then
- return false
- end
- shovels[1]:cpSetTemporaryLoadingShovelState()
+ if found then
+ shovels[1]:cpSetTemporaryLoadingShovelState()
+ end
+end
+
+function CpVehicleSettings:isLevelerHeightOffsetSettingDisabled()
+ return not AIUtil.isStopped(self)
+end
+
+function CpVehicleSettings:isLevelerHeightOffsetSettingVisible()
+ return AIUtil.hasChildVehicleWithSpecialization(self, Leveler) and not
+ AIUtil.hasChildVehicleWithSpecialization(self, Shovel)
end
--- Saves the user value changed on the server.
From cec93bfe082cc17a4aaf35cc51cdcc5d6cd5a728 Mon Sep 17 00:00:00 2001
From: schwiti6190
Date: Wed, 18 Oct 2023 10:38:46 +0000
Subject: [PATCH 6/7] Updated translations
---
translations/translation_br.xml | 2 ++
translations/translation_cs.xml | 2 ++
translations/translation_ct.xml | 2 ++
translations/translation_cz.xml | 2 ++
translations/translation_da.xml | 2 ++
translations/translation_de.xml | 2 ++
translations/translation_ea.xml | 2 ++
translations/translation_en.xml | 2 ++
translations/translation_es.xml | 2 ++
translations/translation_fc.xml | 2 ++
translations/translation_fi.xml | 2 ++
translations/translation_fr.xml | 2 ++
translations/translation_hu.xml | 2 ++
translations/translation_it.xml | 2 ++
translations/translation_jp.xml | 2 ++
translations/translation_kr.xml | 2 ++
translations/translation_nl.xml | 2 ++
translations/translation_no.xml | 2 ++
translations/translation_pl.xml | 2 ++
translations/translation_pt.xml | 2 ++
translations/translation_ro.xml | 2 ++
translations/translation_ru.xml | 2 ++
translations/translation_sv.xml | 2 ++
translations/translation_tr.xml | 2 ++
24 files changed, 48 insertions(+)
diff --git a/translations/translation_br.xml b/translations/translation_br.xml
index 20087664c..7b7b1ec2d 100644
--- a/translations/translation_br.xml
+++ b/translations/translation_br.xml
@@ -212,6 +212,8 @@
+
+
diff --git a/translations/translation_cs.xml b/translations/translation_cs.xml
index b61abc17f..bf7672f1a 100644
--- a/translations/translation_cs.xml
+++ b/translations/translation_cs.xml
@@ -212,6 +212,8 @@
+
+
diff --git a/translations/translation_ct.xml b/translations/translation_ct.xml
index 5cbb7537b..907d021c0 100644
--- a/translations/translation_ct.xml
+++ b/translations/translation_ct.xml
@@ -212,6 +212,8 @@
+
+
diff --git a/translations/translation_cz.xml b/translations/translation_cz.xml
index b82e3bc5b..04fa1a991 100644
--- a/translations/translation_cz.xml
+++ b/translations/translation_cz.xml
@@ -212,6 +212,8 @@
+
+
diff --git a/translations/translation_da.xml b/translations/translation_da.xml
index c54b6ebe8..8e8e9bcba 100644
--- a/translations/translation_da.xml
+++ b/translations/translation_da.xml
@@ -212,6 +212,8 @@
+
+
diff --git a/translations/translation_de.xml b/translations/translation_de.xml
index 6738e81e3..2b89d1cc4 100644
--- a/translations/translation_de.xml
+++ b/translations/translation_de.xml
@@ -212,6 +212,8 @@
+
+
diff --git a/translations/translation_ea.xml b/translations/translation_ea.xml
index 1081577fe..d32fd3c82 100644
--- a/translations/translation_ea.xml
+++ b/translations/translation_ea.xml
@@ -212,6 +212,8 @@
+
+
diff --git a/translations/translation_en.xml b/translations/translation_en.xml
index f73fc3a97..86f85b368 100644
--- a/translations/translation_en.xml
+++ b/translations/translation_en.xml
@@ -212,6 +212,8 @@
+
+
diff --git a/translations/translation_es.xml b/translations/translation_es.xml
index 992d20a3b..e29209ecc 100644
--- a/translations/translation_es.xml
+++ b/translations/translation_es.xml
@@ -212,6 +212,8 @@
+
+
diff --git a/translations/translation_fc.xml b/translations/translation_fc.xml
index c4caf412b..a69b2d6c3 100644
--- a/translations/translation_fc.xml
+++ b/translations/translation_fc.xml
@@ -212,6 +212,8 @@
+
+
diff --git a/translations/translation_fi.xml b/translations/translation_fi.xml
index 37bc8f055..e7d374429 100644
--- a/translations/translation_fi.xml
+++ b/translations/translation_fi.xml
@@ -212,6 +212,8 @@
+
+
diff --git a/translations/translation_fr.xml b/translations/translation_fr.xml
index e11d44757..ef64b61fe 100644
--- a/translations/translation_fr.xml
+++ b/translations/translation_fr.xml
@@ -212,6 +212,8 @@
+
+
diff --git a/translations/translation_hu.xml b/translations/translation_hu.xml
index ac3e581e0..fec3c2225 100644
--- a/translations/translation_hu.xml
+++ b/translations/translation_hu.xml
@@ -212,6 +212,8 @@
+
+
diff --git a/translations/translation_it.xml b/translations/translation_it.xml
index 910ac9386..38a80dc29 100644
--- a/translations/translation_it.xml
+++ b/translations/translation_it.xml
@@ -212,6 +212,8 @@
+
+
diff --git a/translations/translation_jp.xml b/translations/translation_jp.xml
index edeb60dda..3cf58f540 100644
--- a/translations/translation_jp.xml
+++ b/translations/translation_jp.xml
@@ -212,6 +212,8 @@
+
+
diff --git a/translations/translation_kr.xml b/translations/translation_kr.xml
index 20bb3a407..631e56bee 100644
--- a/translations/translation_kr.xml
+++ b/translations/translation_kr.xml
@@ -212,6 +212,8 @@
+
+
diff --git a/translations/translation_nl.xml b/translations/translation_nl.xml
index e38fb53cb..5be0885c9 100644
--- a/translations/translation_nl.xml
+++ b/translations/translation_nl.xml
@@ -212,6 +212,8 @@
+
+
diff --git a/translations/translation_no.xml b/translations/translation_no.xml
index f4b7a8455..f9718cf68 100644
--- a/translations/translation_no.xml
+++ b/translations/translation_no.xml
@@ -212,6 +212,8 @@
+
+
diff --git a/translations/translation_pl.xml b/translations/translation_pl.xml
index 3e7d5839e..baedca942 100644
--- a/translations/translation_pl.xml
+++ b/translations/translation_pl.xml
@@ -212,6 +212,8 @@
+
+
diff --git a/translations/translation_pt.xml b/translations/translation_pt.xml
index 09a4ad2f6..c3c22d169 100644
--- a/translations/translation_pt.xml
+++ b/translations/translation_pt.xml
@@ -212,6 +212,8 @@
+
+
diff --git a/translations/translation_ro.xml b/translations/translation_ro.xml
index 0a3f47be5..8aac9ac15 100644
--- a/translations/translation_ro.xml
+++ b/translations/translation_ro.xml
@@ -212,6 +212,8 @@
+
+
diff --git a/translations/translation_ru.xml b/translations/translation_ru.xml
index c94f861b4..08d3f1bc7 100644
--- a/translations/translation_ru.xml
+++ b/translations/translation_ru.xml
@@ -212,6 +212,8 @@
+
+
diff --git a/translations/translation_sv.xml b/translations/translation_sv.xml
index cfb91e7ce..918360a5f 100644
--- a/translations/translation_sv.xml
+++ b/translations/translation_sv.xml
@@ -212,6 +212,8 @@
+
+
diff --git a/translations/translation_tr.xml b/translations/translation_tr.xml
index 9665942be..756443cb7 100644
--- a/translations/translation_tr.xml
+++ b/translations/translation_tr.xml
@@ -212,6 +212,8 @@
+
+
From f43252ee713e175464d6934fa73d231d9bc5a6a9 Mon Sep 17 00:00:00 2001
From: schwiti6190 <58079399+schwiti6190@users.noreply.github.com>
Date: Wed, 18 Oct 2023 15:27:44 +0200
Subject: [PATCH 7/7] Changed shield height offset range
---
config/VehicleSettingsSetup.xml | 2 +-
scripts/CpSettingsUtil.lua | 11 +++++---
.../ai/parameters/AIParameterSettingList.lua | 28 +++++++++++--------
3 files changed, 24 insertions(+), 17 deletions(-)
diff --git a/config/VehicleSettingsSetup.xml b/config/VehicleSettingsSetup.xml
index 6fb2f16f1..6520f4aef 100644
--- a/config/VehicleSettingsSetup.xml
+++ b/config/VehicleSettingsSetup.xml
@@ -79,7 +79,7 @@
-
diff --git a/scripts/CpSettingsUtil.lua b/scripts/CpSettingsUtil.lua
index 945cf28e9..c3f695bc9 100644
--- a/scripts/CpSettingsUtil.lua
+++ b/scripts/CpSettingsUtil.lua
@@ -35,9 +35,10 @@ CpSettingsUtil = {}
- isExpertModeOnly(bool): is the setting visible in the expert version?, default = false
- generateValuesFunction(string): dynamically adds value, when the setting is created.
- - min (int): min value
- - max (int): max value
+ - min (float): min value
+ - max (float): max value
- incremental (float): increment (optional), default "1"
+ - precision (float): optional rounding precision
- text(string): string to format the setting value with in the gui element.
- unit (int) : 1 == km/h, 2 == meters, 3 == ha (optional), 4 = percent (%), 5 = degrees (°)
@@ -89,9 +90,10 @@ function CpSettingsUtil.init()
schema:register(XMLValueType.BOOL, key.."#isExpertModeOnly", "Is enabled in simple mode?", false) -- optional
schema:register(XMLValueType.STRING, key .. "#generateValuesFunction", "Function to generate values.")
- schema:register(XMLValueType.INT, key.."#min", "Setting min value")
- schema:register(XMLValueType.INT, key.."#max", "Setting max value")
+ schema:register(XMLValueType.FLOAT, key.."#min", "Setting min value")
+ schema:register(XMLValueType.FLOAT, key.."#max", "Setting max value")
schema:register(XMLValueType.FLOAT, key.."#incremental", "Setting incremental", 1) -- optional
+ schema:register(XMLValueType.FLOAT, key.."#precision", "Setting precision", 2) -- optional
schema:register(XMLValueType.STRING, key.."#text", "Setting text") -- optional
schema:register(XMLValueType.INT, key .. "#unit", "Setting value unit (km/h, m ...)") --optional
@@ -205,6 +207,7 @@ function CpSettingsUtil.loadSettingsFromSetup(class, filePath)
settingParameters.min = xmlFile:getValue(baseKey.."#min")
settingParameters.max = xmlFile:getValue(baseKey.."#max")
settingParameters.incremental = MathUtil.round(xmlFile:getValue(baseKey.."#incremental"), 3)
+ settingParameters.precision = xmlFile:getValue(baseKey.."#precision", 2)
settingParameters.textStr = xmlFile:getValue(baseKey.."#text")
settingParameters.unit = xmlFile:getValue(baseKey.."#unit")
diff --git a/scripts/ai/parameters/AIParameterSettingList.lua b/scripts/ai/parameters/AIParameterSettingList.lua
index edeed12ef..e8215dc42 100644
--- a/scripts/ai/parameters/AIParameterSettingList.lua
+++ b/scripts/ai/parameters/AIParameterSettingList.lua
@@ -22,7 +22,8 @@ function AIParameterSettingList:init(data, vehicle, class)
--- so we generate a series of float values and texts here.
self.data.values = {}
self.data.texts = {}
- AIParameterSettingList.generateValues(self, self.data.values, self.data.texts, data.min, data.max, data.incremental, data.unit)
+ AIParameterSettingList.generateValues(self, self.data.values, self.data.texts,
+ data.min, data.max, data.incremental, data.unit, data.precision)
--- Same as above, make sure the values are copied.
self.values = table.copy(self.data.values)
if self.data.texts ~= nil then
@@ -73,18 +74,19 @@ function AIParameterSettingList:init(data, vehicle, class)
end
-function AIParameterSettingList.getSpeedText(value)
+function AIParameterSettingList.getSpeedText(value, precision)
return string.format("%.1f %s", g_i18n:getSpeed(value), g_i18n:getSpeedMeasuringUnit())
end
-function AIParameterSettingList.getDistanceText(value)
+function AIParameterSettingList.getDistanceText(value, precision)
+ precision = precision or 1
if g_Courseplay.globalSettings and g_Courseplay.globalSettings.distanceUnit:getValue() == g_Courseplay.globalSettings.IMPERIAL_UNIT then
return string.format("%.1f %s", value*AIParameterSettingList.FOOT_FACTOR, g_i18n:getText("CP_unit_foot"))
end
- return string.format("%.1f %s", value, g_i18n:getText("CP_unit_meter"))
+ return string.format("%.".. tostring(precision) .. "f %s", value, g_i18n:getText("CP_unit_meter"))
end
-function AIParameterSettingList.getAreaText(value)
+function AIParameterSettingList.getAreaText(value, precision)
return g_i18n:formatArea(value, 1, true)
end
@@ -92,8 +94,8 @@ AIParameterSettingList.UNITS_TEXTS = {
AIParameterSettingList.getSpeedText, --- km/h
AIParameterSettingList.getDistanceText, --- m
AIParameterSettingList.getAreaText, --- ha/arcs
- function (value) return string.format("%d", value) .. "%" end, --- percent
- function (value) return string.format("%d", value) .. "°" end --- degrees
+ function (value, precision) return string.format("%d", value) .. "%" end, --- percent
+ function (value, precision) return string.format("%d", value) .. "°" end --- degrees
}
AIParameterSettingList.UNITS_CONVERSION = {
@@ -113,12 +115,13 @@ AIParameterSettingList.INPUT_VALUE_THRESHOLD = 2
---@param max number
---@param inc number
---@param unit number
-function AIParameterSettingList:generateValues(values, texts, min, max, inc, unit)
+function AIParameterSettingList:generateValues(values, texts, min, max, inc, unit, precision)
inc = inc or 1
+ precision = precision or 2
for i=min, max, inc do
table.insert(values, i)
- local value = MathUtil.round(i, 2)
- local text = unit and AIParameterSettingList.UNITS_TEXTS[unit] and AIParameterSettingList.UNITS_TEXTS[unit](value) or tostring(value)
+ local value = MathUtil.round(i, precision)
+ local text = unit and AIParameterSettingList.UNITS_TEXTS[unit] and AIParameterSettingList.UNITS_TEXTS[unit](value, precision - 1) or tostring(value)
table.insert(texts, text)
end
end
@@ -233,12 +236,13 @@ end
--- For all units that are not an SI unit ...
function AIParameterSettingList:validateTexts()
local unit = self.data.unit
+ local precision = self.data.precision or 2
if unit then
local unitStrFunc = AIParameterSettingList.UNITS_TEXTS[unit]
local fixedTexts = {}
for ix, value in ipairs(self.values) do
- local value = MathUtil.round(value, 2)
- local text = unitStrFunc(value)
+ local value = MathUtil.round(value, precision)
+ local text = unitStrFunc(value, precision - 1)
fixedTexts[ix] = text
end
self.texts = fixedTexts