Skip to content

Commit

Permalink
Added leveler height offset setting
Browse files Browse the repository at this point in the history
  • Loading branch information
schwiti6190 committed Oct 18, 2023
1 parent 283df35 commit cb5983c
Show file tree
Hide file tree
Showing 5 changed files with 43 additions and 9 deletions.
8 changes: 8 additions & 0 deletions config/MasterTranslations.xml
Original file line number Diff line number Diff line change
Expand Up @@ -687,6 +687,14 @@
<Text language="de"><![CDATA[Arbeitsbreite. Wert: 0 - 50]]></Text>
<Text language="en"><![CDATA[Work width. Value: 0 - 50]]></Text>
</Translation>
<Translation name="CP_vehicle_setting_levelerHeightOffset_title">
<Text language="de"><![CDATA[Versatz Schildhöhe]]></Text>
<Text language="en"><![CDATA[Shield height offset]]></Text>
</Translation>
<Translation name="CP_vehicle_setting_levelerHeightOffset_tooltip">
<Text language="de"><![CDATA[Höhenversatz vom Schild zum Boden. Wert: 0 - 1]]></Text>
<Text language="en"><![CDATA[Offset of the shield form the ground. Value: 0 - 1]]></Text>
</Translation>
<Translation name="CP_vehicle_setting_loadingShovelHeightOffset_title">
<Text language="de"><![CDATA[Versatz Schaufelhöhe.]]></Text>
<Text language="en"><![CDATA[Shovel hight offset.]]></Text>
Expand Down
2 changes: 2 additions & 0 deletions config/VehicleSettingsSetup.xml
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,8 @@
<Setting classType="AIParameterSettingList" name="loadingShovelHeightOffset" min="-1" max="1" incremental="0.1" default="0" unit="2"
isVisible="isLoadingShovelOffsetSettingVisible" isDisabled="isLoadingShovelOffsetSettingDisabled"
onChangeCallback="onCpLoadingShovelOffsetSettingChanged" vehicleConfiguration="loadingShovelOffset"/>
<Setting classType="AIParameterSettingList" name="levelerHeightOffset" min="0" max="1" incremental="0.1" default="0" unit="2"
isVisible="isLevelerHeightOffsetSettingVisible" isDisabled="isLevelerHeightOffsetSettingDisabled" />
</SettingSubTitle>

<SettingSubTitle title="combine" isVisible="areCombineSettingsVisible">
Expand Down
12 changes: 9 additions & 3 deletions scripts/ai/controllers/LevelerController.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down Expand Up @@ -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()
Expand Down Expand Up @@ -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()

Expand Down Expand Up @@ -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

Expand Down
11 changes: 10 additions & 1 deletion scripts/gui/hud/CpBunkerSiloWorkerHudPage.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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())
Expand Down
19 changes: 14 additions & 5 deletions scripts/specializations/CpVehicleSettings.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand All @@ -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.
Expand Down

0 comments on commit cb5983c

Please sign in to comment.