Skip to content

Commit

Permalink
Merge remote-tracking branch 'upstream/main' into ChopperSupport
Browse files Browse the repository at this point in the history
  • Loading branch information
pops64 committed Oct 25, 2023
2 parents 5bfb3d8 + a6f56c0 commit da3cd04
Show file tree
Hide file tree
Showing 49 changed files with 1,062 additions and 236 deletions.
2 changes: 2 additions & 0 deletions config/InfoTexts.xml
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@
<InfoText name="ERROR_GROUND_UNLOAD_NOT_SUPPORTED" text="errorGroundUnloadNotSupported" class="AIMessageErrorGroundUnloadNotSupported"/>
<InfoText name="ERROR_CUTTER_NOT_SUPPORTED" text="errorCutterNotSupported" class="AIMessageErrorCutterNotSupported"/>
<InfoText name="ERROR_AUTOMATIC_CUTTER_ATTACH_DISABLED" text="errorAutomaticCutterAttachNotActive" class="AIMessageErrorAutomaticCutterAttachNotActive" isOnlyShownOnPlayerStart="true"/>
<InfoText name="ERROR_WRONG_SEASON" text="errorWrongSeason" class="AIMessageErrorWrongSeason"/>
<InfoText name="ERROR_WRONG_MISSION_FRUIT_TYPE" text="errorWrongMissionFruitType" class="AIMessageErrorWrongMissionFruitType"/>

<InfoText name="IS_STUCK" text="isStuck"/>
<InfoText name="BLOCKED_BY_OBJECT" text="blockedByObject" class="AIMessageErrorBlockedByObject"/>
Expand Down
24 changes: 20 additions & 4 deletions config/MasterTranslations.xml
Original file line number Diff line number Diff line change
Expand Up @@ -385,6 +385,10 @@
<Text language="de"><![CDATA[Helfer %s hat die Arbeit gestoppt - automatisches Scheidwerk ankuppeln deaktiviert!]]></Text>
<Text language="en"><![CDATA[AI worker %s has stopped work unexpectedly - automatic cutter attach disabled!]]></Text>
</Translation>
<Translation name="CP_ai_messageErrorWrongMissionFruitType">
<Text language="de"><![CDATA[Helfer %s hat die Arbeit gestoppt - falsche Frucht für die Mission ausgewählt!]]></Text>
<Text language="en"><![CDATA[AI worker %s has stopped work unexpectedly - wrong fill type for mission selected!]]></Text>
</Translation>
</Category>
<Category name="AI fieldwork task descriptions">
<Translation name="CP_ai_taskDescriptionAttachHeader">
Expand Down Expand Up @@ -443,10 +447,6 @@
</Translation>
</Category>
<Category name="AI silo loader task descriptions">
<Translation name="CP_ai_taskDescriptionUnloadingToTrailer">
<Text language="de"><![CDATA[Entlädt zu einem Anhänger]]></Text>
<Text language="en"><![CDATA[Unloads to a trailer]]></Text>
</Translation>
<Translation name="CP_ai_taskDescriptionWaitsForTrailer">
<Text language="de"><![CDATA[Wartet auf einen Anhänger]]></Text>
<Text language="en"><![CDATA[Waits for a trailer]]></Text>
Expand Down Expand Up @@ -691,6 +691,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 Expand Up @@ -1614,6 +1622,14 @@ The course is saved automatically on closing of the editor and overrides the sel
<Text language="de"><![CDATA[Schneidwerk ankuppeln deaktiviert]]></Text>
<Text language="en"><![CDATA[Cutter attaching deactivated]]></Text>
</Translation>
<Translation name="CP_infoTexts_errorWrongSeason">
<Text language="de"><![CDATA[Falsche Jahreszeit]]></Text>
<Text language="en"><![CDATA[Wrong season for fruit]]></Text>
</Translation>
<Translation name="CP_infoTexts_errorWrongMissionFruitType">
<Text language="de"><![CDATA[Falsche Frucht für Mission ausgewählt]]></Text>
<Text language="en"><![CDATA[Wrong fruit for mission selected]]></Text>
</Translation>
</Category>
<Category name="Custom field manager">
<Translation name="CP_customFieldManager_confirm_save">
Expand Down
32 changes: 32 additions & 0 deletions config/VehicleConfigurations.xml
Original file line number Diff line number Diff line change
Expand Up @@ -361,10 +361,16 @@ You can define the following custom settings:

<Vehicle name="torion1914.xml"
turnRadius = "12"
/>
<vehicle name="torion1511.xml"
turnRadius = "9"
/>
<Vehicle name="wheelLoaderShovel.xml"
shovelMovingToolIx = "1"
/>
<Vehicle name="overtippingBucket.xml"
shovelMovingToolIx = "1"
/>

<!--[DLC]-->

Expand Down Expand Up @@ -549,4 +555,30 @@ You can define the following custom settings:
disablePipeMovingToolCorrection = "true"
unloadOffsetX = "-3.56"
/>

<!--Mod: FS22_lizardHTB6000-->
<Vehicle name="HTB6000.xml"
shovelMovingToolIx = "1"
/>

<!--Mod: FS22_Liebherr_Xpower-->
<Vehicle name="highTipShovel.xml"
shovelMovingToolIx = "1"
/>

<!--Mod: FS22_bresselUndLadeHighTipShovelPack-->
<Vehicle name="bresselUndLadeL67.xml"
shovelMovingToolIx = "1"
/>

<!--Mod: FS22_bresselUndLadeHighTipShovelPack-->
<Vehicle name="bresselUndLadeL71.xml"
shovelMovingToolIx = "1"
/>

<!--Mod: FS22_bresselUndLadeHighTipShovelPack-->
<Vehicle name="bresselUndLadeL71.xml"
shovelMovingToolIx = "1"
/>

</VehicleConfigurations>
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="0.5" incremental="0.05" default="0" unit="2" precision="3"
isVisible="isLevelerHeightOffsetSettingVisible" isDisabled="isLevelerHeightOffsetSettingDisabled" />
</SettingSubTitle>

<SettingSubTitle title="combine" isVisible="areCombineSettingsVisible">
Expand Down
3 changes: 2 additions & 1 deletion modDesc.xml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?xml version="1.0" encoding="utf-8" standalone="no" ?>
<modDesc descVersion="76">
<version>7.3.1.2</version>
<version>7.3.1.3</version>
<author>Pops64</author>
<title>
<en>CoursePlay - Chopper Support</en>
Expand Down Expand Up @@ -276,6 +276,7 @@ Changelog 7.1.0.0:

<sourceFile filename="scripts/ai/AIUtil.lua"/>
<sourceFile filename="scripts/ai/ImplementUtil.lua"/>
<sourceFile filename="scripts/ai/PathfinderController.lua"/>
<sourceFile filename="scripts/ai/ProximityController.lua"/>
<sourceFile filename="scripts/ai/FieldWorkerProximityController.lua"/>
<sourceFile filename="scripts/ai/CollisionAvoidanceController.lua"/>
Expand Down
37 changes: 37 additions & 0 deletions scripts/CpObject.lua
Original file line number Diff line number Diff line change
Expand Up @@ -59,10 +59,47 @@ function CpObject(base, init)
end
return false
end
c.__tostring = function (self)
-- Default tostring function for printing all attributes and assigned functions.
local str = '[ '
for attribute, value in pairs(self) do
str = str .. string.format('%s: %s ', attribute, value)
end
str = str .. ']'
return str
end

setmetatable(c, mt)
return c
end

---@class CpObjectUtil
CpObjectUtil = {
BUILDER_API_NIL = "nil"
}

--- Registers a builder api for a class.
--- The attributes are set as private variables with "_" before the variable name
--- and the builder functions are named like the attribute.
--- Nil values have to be replaced with CpObjectUtil.BUILDER_API_NIL !!
---@param class table
---@param attributesToDefault table<attributeName, any>
function CpObjectUtil.registerBuilderAPI(class, attributesToDefault)
for attributeName, default in pairs(attributesToDefault) do
if default == CpObjectUtil.BUILDER_API_NIL then
default = nil
end
--- Applies the default value to the private variable
class["_" .. attributeName] = default
--- Creates the builder functions/ setters with the public variable name
class[attributeName] = function(self, value)
self["_" .. attributeName] = value
return self
end
end
end


--- Object that holds a value temporarily. You can tell when to set the value and how long it should keep that
--- value, in milliseconds. Great for timers.
---@class CpTemporaryObject
Expand Down
11 changes: 7 additions & 4 deletions scripts/CpSettingsUtil.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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 (°)
Expand Down Expand Up @@ -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

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

Expand Down
19 changes: 5 additions & 14 deletions scripts/ai/AIDriveStrategyBunkerSilo.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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)
Expand Down
25 changes: 24 additions & 1 deletion scripts/ai/AIDriveStrategyCourse.lua
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,10 @@ function AIDriveStrategyCourse:setAIVehicle(vehicle, jobParameters)
self:initializeImplementControllers(vehicle)
self.ppc = PurePursuitController(vehicle)
self.ppc:registerListeners(self, 'onWaypointPassed', 'onWaypointChange')

self.pathfinderController = PathfinderController(vehicle)
self.pathfinderController:registerListeners(self, self.onPathfindingFinished, self.onPathfindingRetry)

self.storage = vehicle.spec_cpAIWorker

self.settings = vehicle:getCpSettings()
Expand Down Expand Up @@ -428,8 +432,9 @@ function AIDriveStrategyCourse:getCurrentCourse()
return self.ppc:getCourse() or self.course
end

function AIDriveStrategyCourse:update()
function AIDriveStrategyCourse:update(dt)
self.ppc:update()
self.pathfinderController:update(dt)
self:updatePathfinding()
self:updateInfoTexts()
end
Expand Down Expand Up @@ -579,6 +584,24 @@ end
function AIDriveStrategyCourse:onWaypointPassed(ix, course)
end

--- Pathfinding has finished
---@param controller PathfinderController
---@param success boolean
---@param course Course|nil
---@param goalNodeInvalid boolean|nil
function AIDriveStrategyCourse:onPathfindingFinished(controller, success, course, goalNodeInvalid)
-- override
end

--- Pathfinding failed, but a retry attempt is leftover.
---@param controller PathfinderController
---@param lastContext PathfinderControllerContext
---@param wasLastRetry boolean
---@param currentRetryAttempt number
function AIDriveStrategyCourse:onPathfindingRetry(controller, lastContext, wasLastRetry, currentRetryAttempt)
-- override
end

------------------------------------------------------------------------------------------------------------------------
--- Pathfinding
---------------------------------------------------------------------------------------------------------------------------
Expand Down
8 changes: 4 additions & 4 deletions scripts/ai/AIDriveStrategyDriveToFieldWorkStart.lua
Original file line number Diff line number Diff line change
Expand Up @@ -84,11 +84,11 @@ function AIDriveStrategyDriveToFieldWorkStart:start(course, startIx, jobParamete
nVehicles > 1 and jobParameters.laneOffset:getValue() or 0,
course:getWorkWidth() / nVehicles)
local implement = AIUtil.getImplementWithSpecialization(self.vehicle, Cutter)
if self:giantsPreFoldHeaderWithWheelsFix(implement) then
if self.settings.foldImplementAtEnd:getValue() then
self.vehicle:prepareForAIDriving()
end
if self:giantsPreFoldHeaderWithWheelsFix(implement) then
self:giantsPostFoldHeaderWithWheelsFix(implement)
else
self.vehicle:prepareForAIDriving()
end
self:startCourseWithPathfinding(course, startIx)
end
Expand Down Expand Up @@ -130,7 +130,7 @@ function AIDriveStrategyDriveToFieldWorkStart:getDriveData(dt, vX, vY, vZ)
elseif self.state == self.states.PREPARE_TO_DRIVE then
self:setMaxSpeed(0)
local isReadyToDrive, blockingVehicle = self.vehicle:getIsAIReadyToDrive()
if isReadyToDrive then
if isReadyToDrive or not self.settings.foldImplementAtEnd:getValue() then
self.state = self.states.DRIVING_TO_WORK_START
self:debug('Ready to drive to work start')
else
Expand Down
Loading

0 comments on commit da3cd04

Please sign in to comment.