Skip to content

Commit

Permalink
Merge pull request #3149 from Courseplay/Code-Improvements
Browse files Browse the repository at this point in the history
WIP diff code improvements
  • Loading branch information
Tensuko authored Mar 29, 2024
2 parents 85e0beb + 257035e commit 3d7fdb1
Show file tree
Hide file tree
Showing 50 changed files with 697 additions and 721 deletions.
44 changes: 22 additions & 22 deletions config/MasterTranslations.xml
Original file line number Diff line number Diff line change
Expand Up @@ -89,91 +89,91 @@
</Translation>
</Category>
<Category name="AI job parameters">
<Translation name="CP_jobParameters_fieldPosition_title">
<Translation name="CP_fieldWorkJobParameters_fieldPosition_title">
<Text language="de"><![CDATA[Feldposition:]]></Text>
<Text language="en"><![CDATA[Field position:]]></Text>
</Translation>
<Translation name="CP_jobParameters_bunkerSiloPosition_title">
<Translation name="CP_fieldWorkJobParameters_bunkerSiloPosition_title">
<Text language="de"><![CDATA[Siloposition:]]></Text>
<Text language="en"><![CDATA[Silo position:]]></Text>
</Translation>
<Translation name="CP_jobParameters_parkPosition_title">
<Translation name="CP_fieldWorkJobParameters_parkPosition_title">
<Text language="de"><![CDATA[Parkposition:]]></Text>
<Text language="en"><![CDATA[Park position:]]></Text>
</Translation>
<Translation name="CP_jobParameters_subTitle_startAt">
<Translation name="CP_fieldWorkJobParameters_subTitle_startAt">
<Text language="de"><![CDATA[Start am:]]></Text>
<Text language="en"><![CDATA[Start at:]]></Text>
</Translation>
<Translation name="CP_jobParameters_startAt_title">
<Translation name="CP_fieldWorkJobParameters_startAt_title">
<Text language="de"><![CDATA[Start am:]]></Text>
<Text language="en"><![CDATA[Start at:]]></Text>
</Translation>
<Translation name="CP_jobParameters_startAt_tooltip">
<Translation name="CP_fieldWorkJobParameters_startAt_tooltip">
<Text language="de"><![CDATA[Wo die Arbeit gestartet wird.]]></Text>
<Text language="en"><![CDATA[Where to start field work.]]></Text>
</Translation>
<Translation name="CP_jobParameters_startAt_nearest">
<Translation name="CP_fieldWorkJobParameters_startAt_nearest">
<Text language="de"><![CDATA[Nahester Wegpunkt]]></Text>
<Text language="en"><![CDATA[nearest waypoint]]></Text>
</Translation>
<Translation name="CP_jobParameters_startAt_first">
<Translation name="CP_fieldWorkJobParameters_startAt_first">
<Text language="de"><![CDATA[Erster Wegpunkt]]></Text>
<Text language="en"><![CDATA[first waypoint]]></Text>
</Translation>
<Translation name="CP_jobParameters_startAt_last">
<Translation name="CP_fieldWorkJobParameters_startAt_last">
<Text language="de"><![CDATA[Letzter Wegpunkt]]></Text>
<Text language="en"><![CDATA[last waypoint]]></Text>
</Translation>
<Translation name="CP_jobParameters_startAt_bunkerSilo">
<Translation name="CP_fieldWorkJobParameters_startAt_bunkerSilo">
<Text language="de"><![CDATA[Bunkersilo-Modus]]></Text>
<Text language="en"><![CDATA[Bunker silo mode]]></Text>
</Translation>
<Translation name="CP_jobParameters_startAt_siloLoader">
<Translation name="CP_fieldWorkJobParameters_startAt_siloLoader">
<Text language="de"><![CDATA[Silo laden]]></Text>
<Text language="en"><![CDATA[Silo load mode]]></Text>
</Translation>
<Translation name="CP_jobParameters_startAt_unload">
<Translation name="CP_fieldWorkJobParameters_startAt_unload">
<Text language="de"><![CDATA[Drescher entladen]]></Text>
<Text language="en"><![CDATA[unload combine]]></Text>
</Translation>
<Translation name="CP_jobParameters_startAt_unload_siloLoader">
<Translation name="CP_fieldWorkJobParameters_startAt_unload_siloLoader">
<Text language="de"><![CDATA[Silolader entladen]]></Text>
<Text language="en"><![CDATA[Unload Silo loader]]></Text>
</Translation>
<Translation name="CP_jobParameters_startAt_bales">
<Translation name="CP_fieldWorkJobParameters_startAt_bales">
<Text language="de"><![CDATA[Ballen sammeln/wickeln]]></Text>
<Text language="en"><![CDATA[collecting/wrapping bales]]></Text>
</Translation>
<Translation name="CP_jobParameters_subTitle_laneOffset">
<Translation name="CP_fieldWorkJobParameters_subTitle_laneOffset">
<Text language="de"><![CDATA[Bahn:]]></Text>
<Text language="en"><![CDATA[Lane offset:]]></Text>
</Translation>
<Translation name="CP_jobParameters_laneOffset_title">
<Translation name="CP_fieldWorkJobParameters_laneOffset_title">
<Text language="de"><![CDATA[Bahn:]]></Text>
<Text language="en"><![CDATA[Lane offset:]]></Text>
</Translation>
<Translation name="CP_jobParameters_laneOffset_tooltip">
<Translation name="CP_fieldWorkJobParameters_laneOffset_tooltip">
<Text language="de"><![CDATA[Bahnauswahl, wenn ein Multitoolkurs erstellt wurde.]]></Text>
<Text language="en"><![CDATA[Lane offset]]></Text>
</Translation>
<Translation name="CP_jobParameters_laneOffset_center">
<Translation name="CP_fieldWorkJobParameters_laneOffset_center">
<Text language="de"><![CDATA[Mitte]]></Text>
<Text language="en"><![CDATA[center]]></Text>
</Translation>
<Translation name="CP_jobParameters_laneOffset_left">
<Translation name="CP_fieldWorkJobParameters_laneOffset_left">
<Text language="de"><![CDATA[Links(1)]]></Text>
<Text language="en"><![CDATA[left(1)]]></Text>
</Translation>
<Translation name="CP_jobParameters_laneOffset_right">
<Translation name="CP_fieldWorkJobParameters_laneOffset_right">
<Text language="de"><![CDATA[Rechts(1)]]></Text>
<Text language="en"><![CDATA[right(1)]]></Text>
</Translation>
<Translation name="CP_jobParameters_laneOffset_left_2">
<Translation name="CP_fieldWorkJobParameters_laneOffset_left_2">
<Text language="de"><![CDATA[Links(2)]]></Text>
<Text language="en"><![CDATA[left(2)]]></Text>
</Translation>
<Translation name="CP_jobParameters_laneOffset_right_2">
<Translation name="CP_fieldWorkJobParameters_laneOffset_right_2">
<Text language="de"><![CDATA[Rechts(2)]]></Text>
<Text language="en"><![CDATA[right(2)]]></Text>
</Translation>
Expand Down
2 changes: 1 addition & 1 deletion config/gamePadHud/BaleLoaderGamePadHudPage.xml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

<Settings title="CP_vehicle_setting_display">
<Setting type="vehicleSettings" name = "showCourse" />
<Setting type="jobParameters" name = "startAt" />
<Setting type="fieldWorkJobParameters" name = "startAt" />
<Setting type="baleFinderJobParameters" name = "baleWrapType" />
<Setting type="vehicleSettings" name = "baleCollectorOffset" />
</Settings>
2 changes: 1 addition & 1 deletion config/gamePadHud/BunkerSiloGamePadHudPage.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
-->

<Settings title="CP_vehicle_setting_display">
<Setting type="jobParameters" name = "startAt" />
<Setting type="fieldWorkJobParameters" name = "startAt" />
<Setting type="vehicleSettings" name="bunkerSiloWorkWidth"/>
<Setting type="bunkerSiloJobParameters" name = "drivingForwardsIntoSilo" />
<Setting type="bunkerSiloJobParameters" name = "waitAtParkPosition" />
Expand Down
4 changes: 2 additions & 2 deletions config/gamePadHud/FieldworkGamePadHudPage.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,9 @@
-->

<Settings title="CP_vehicle_setting_display">
<Setting type="jobParameters" name = "startAt" />
<Setting type="fieldWorkJobParameters" name = "startAt" />
<Setting type="vehicleSettings" name = "showCourse" />
<Setting type="jobParameters" name = "laneOffset" />
<Setting type="fieldWorkJobParameters" name = "laneOffset" />
<Setting type="courseGeneratorSettings" name = "workWidth" />
<Setting type="vehicleSettings" name = "toolOffsetX" />
</Settings>
2 changes: 1 addition & 1 deletion config/gamePadHud/SiloLoaderGamePadHudPage.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
-->

<Settings title="CP_vehicle_setting_display">
<Setting type="jobParameters" name = "startAt" />
<Setting type="fieldWorkJobParameters" name = "startAt" />
<Setting type="vehicleSettings" name="bunkerSiloWorkWidth"/>
<Setting type="vehicleSettings" name="loadingShovelHeightOffset"/>
</Settings>
4 changes: 2 additions & 2 deletions config/jobParameters/BaleFinderJobParameterSetup.xml
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,11 @@
<SettingSubTitle title="ai_parameterGroupTitlePosition" prefix="false">
<Setting classType="CpAIParameterPositionAngle" name="startPosition" positionParameterType="DRIVE_TO"/>
</SettingSubTitle>
<SettingSubTitle title="CP_jobParameters_fieldPosition_title" prefix="false">
<SettingSubTitle title="CP_fieldWorkJobParameters_fieldPosition_title" prefix="false">
<Setting classType="CpAIParameterPosition" name="fieldPosition" positionParameterType="FIELD_OR_SILO"/>
</SettingSubTitle>
<SettingSubTitle title="baleWrapType">
<Setting classType="AIParameterSettingList" name="baleWrapType" isVisible="isBaleWrapSettingVisible" onChangeCallback="onCpWrapTypeSettingChanged">
<Setting classType="AIParameterSettingList" name="baleWrapType" isVisible="hasBaleLoader" onChangeCallback="onCpWrapTypeSettingChanged">
<Values>
<Value name="ALL_BALES">1</Value>
<Value name="ONLY_WRAPPED_BALES">2</Value>
Expand Down
2 changes: 1 addition & 1 deletion config/jobParameters/BunkerSiloJobParameterSetup.xml
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
<SettingSubTitle title="ai_parameterGroupTitlePosition" prefix="false">
<Setting classType="CpAIParameterPositionAngle" name="startPosition" positionParameterType="DRIVE_TO"/>
</SettingSubTitle>
<SettingSubTitle title="CP_jobParameters_bunkerSiloPosition_title" prefix="false">
<SettingSubTitle title="CP_fieldWorkJobParameters_fieldPosition_title" prefix="false">
<Setting classType="CpAIParameterPosition" name="siloPosition" positionParameterType="FIELD_OR_SILO"/>
</SettingSubTitle>
<SettingSubTitle title="drivingForwardsIntoSilo">
Expand Down
2 changes: 1 addition & 1 deletion config/jobParameters/CombineUnloaderJobParameterSetup.xml
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
<SettingSubTitle title="ai_parameterGroupTitlePosition" prefix="false">
<Setting classType="CpAIParameterPositionAngle" name="startPosition" positionParameterType="DRIVE_TO"/>
</SettingSubTitle>
<SettingSubTitle title="CP_jobParameters_fieldPosition_title" prefix="false">
<SettingSubTitle title="CP_fieldWorkJobParameters_fieldPosition_title" prefix="false">
<Setting classType="CpAIParameterPosition" name="fieldPosition" positionParameterType="FIELD_OR_SILO"/>
</SettingSubTitle>
<SettingSubTitle title="unloadTarget">
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,11 @@
For documentation look up the CpSettingUtil.lua.
-->

<Settings prefixText="CP_jobParameters_">
<Settings prefixText="CP_fieldWorkJobParameters_">
<SettingSubTitle title="ai_parameterGroupTitlePosition" prefix="false">
<Setting classType="CpAIParameterPositionAngle" name="startPosition" positionParameterType="DRIVE_TO"/>
</SettingSubTitle>
<SettingSubTitle title="CP_jobParameters_fieldPosition_title" prefix="false">
<SettingSubTitle title="CP_fieldWorkJobParameters_fieldPosition_title" prefix="false">
<Setting classType="CpAIParameterPosition" name="fieldPosition" positionParameterType="FIELD_OR_SILO"/>
</SettingSubTitle>
<SettingSubTitle title="startAt">
Expand Down
4 changes: 2 additions & 2 deletions scripts/ai/AIDriveStrategyCourse.lua
Original file line number Diff line number Diff line change
Expand Up @@ -187,11 +187,11 @@ function AIDriveStrategyCourse:getGeneratedCourse(jobParameters)
end

function AIDriveStrategyCourse:getStartingPointWaypointIx(course, startAt)
if startAt == CpJobParameters.START_AT_NEAREST_POINT then
if startAt == CpFieldWorkJobParameters.START_AT_NEAREST_POINT then
local _, _, ixClosestRightDirection, _ = course:getNearestWaypoints(self.vehicle:getAIDirectionNode())
self:debug('Starting course at the closest waypoint in the right direction %d', ixClosestRightDirection)
return ixClosestRightDirection
elseif startAt == CpJobParameters.START_AT_LAST_POINT then
elseif startAt == CpFieldWorkJobParameters.START_AT_LAST_POINT then
local lastWpIx = self.vehicle:getCpLastRememberedWaypointIx()
if lastWpIx then
self:debug('Starting course at the last waypoint %d', lastWpIx)
Expand Down
54 changes: 13 additions & 41 deletions scripts/ai/jobs/CpAIJob.lua
Original file line number Diff line number Diff line change
Expand Up @@ -23,12 +23,7 @@ CpAIJob = {
local AIJobCp_mt = Class(CpAIJob, AIJob)

function CpAIJob.new(isServer, customMt)
local mt = customMt or AIJobCp_mt
mt.__tostring = function(_self)
CpUtil.info("Job: %s", g_currentMission.aiJobTypeManager:getJobTypeByIndex(_self.jobTypeIndex).name)
return string.format("%d Job parameters", tostring(_self.cpJobParameters))
end
local self = AIJob.new(isServer, mt)
local self = AIJob.new(isServer, customMt or AIJobCp_mt)
self.isDirectStart = false
self.debugChannel = CpDebug.DBG_FIELDWORK

Expand Down Expand Up @@ -274,6 +269,10 @@ function CpAIJob.getIsStartErrorText(state)
return g_i18n:getText("ai_startStateSuccess")
end

function CpAIJob:draw(map, isOverviewMap)

end


function CpAIJob:writeStream(streamId, connection)
streamWriteBool(streamId, self.isDirectStart)
Expand Down Expand Up @@ -469,41 +468,14 @@ AIJobTypeManager.getJobTypeIndex = Utils.overwrittenFunction(AIJobTypeManager.ge

--- Registers additional jobs.
function CpAIJob.registerJob(AIJobTypeManager)
AIJobTypeManager:registerJobType(CpAIJobBaleFinder.name, CpAIJobBaleFinder.jobName, CpAIJobBaleFinder)
AIJobTypeManager:registerJobType(CpAIJobFieldWork.name, CpAIJobFieldWork.jobName, CpAIJobFieldWork)
AIJobTypeManager:registerJobType(CpAIJobCombineUnloader.name, CpAIJobCombineUnloader.jobName, CpAIJobCombineUnloader)
AIJobTypeManager:registerJobType(CpAIJobSiloLoader.name, CpAIJobSiloLoader.jobName, CpAIJobSiloLoader)
AIJobTypeManager:registerJobType(CpAIJobBunkerSilo.name, CpAIJobBunkerSilo.jobName, CpAIJobBunkerSilo)
end


--- for reload, messing with the internals of the job type manager so it uses the reloaded job
if g_currentMission then
local myJobTypeIndex = g_currentMission.aiJobTypeManager:getJobTypeIndexByName(AIJob.name)
if myJobTypeIndex then
local myJobType = g_currentMission.aiJobTypeManager:getJobTypeByIndex(myJobTypeIndex)
myJobType.classObject = AIJob
end
local myJobTypeIndex = g_currentMission.aiJobTypeManager:getJobTypeIndexByName(CpAIJobFieldWork.name)
if myJobTypeIndex then
local myJobType = g_currentMission.aiJobTypeManager:getJobTypeByIndex(myJobTypeIndex)
myJobType.classObject = CpAIJobFieldWork
end
local myJobTypeIndex = g_currentMission.aiJobTypeManager:getJobTypeIndexByName(CpAIJobBaleFinder.name)
if myJobTypeIndex then
local myJobType = g_currentMission.aiJobTypeManager:getJobTypeByIndex(myJobTypeIndex)
myJobType.classObject = CpAIJobBaleFinder
end
local myJobTypeIndex = g_currentMission.aiJobTypeManager:getJobTypeIndexByName(CpAIJobBunkerSilo.name)
if myJobTypeIndex then
local myJobType = g_currentMission.aiJobTypeManager:getJobTypeByIndex(myJobTypeIndex)
myJobType.classObject = CpAIJobBunkerSilo
end
local myJobTypeIndex = g_currentMission.aiJobTypeManager:getJobTypeIndexByName(CpAIJobSiloLoader.name)
if myJobTypeIndex then
local myJobType = g_currentMission.aiJobTypeManager:getJobTypeByIndex(myJobTypeIndex)
myJobType.classObject = CpAIJobSiloLoader
end
local function register(class)
AIJobTypeManager:registerJobType(class.name, class.jobName, class)
end
register(CpAIJobBaleFinder)
register(CpAIJobFieldWork)
register(CpAIJobCombineUnloader)
register(CpAIJobSiloLoader)
register(CpAIJobBunkerSilo)
end

AIJobTypeManager.loadMapData = Utils.appendedFunction(AIJobTypeManager.loadMapData,CpAIJob.registerJob)
Expand Down
7 changes: 5 additions & 2 deletions scripts/ai/jobs/CpAIJobBaleFinder.lua
Original file line number Diff line number Diff line change
Expand Up @@ -107,8 +107,11 @@ function CpAIJobBaleFinder:validateFieldPosition(isValid, errorMessage)
return isValid, errorMessage
end

function CpAIJobBaleFinder:drawSelectedField(map)
self.selectedFieldPlot:draw(map)
function CpAIJobBaleFinder:draw(map, isOverviewMap)
CpAIJob.draw(self, map, isOverviewMap)
if not isOverviewMap then
self.selectedFieldPlot:draw(map)
end
end

--- Gets the additional task description shown.
Expand Down
11 changes: 7 additions & 4 deletions scripts/ai/jobs/CpAIJobBunkerSilo.lua
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@
CpAIJobBunkerSilo = {
name = "BUNKER_SILO_CP",
jobName = "CP_job_bunkerSilo",
fieldPositionParameterText = "CP_jobParameters_bunkerSiloPosition_title",
targetPositionParameterText = "CP_jobParameters_parkPosition_title",
fieldPositionParameterText = "CP_fieldWorkJobParameters_bunkerSiloPosition_title",
targetPositionParameterText = "CP_fieldWorkJobParameters_parkPosition_title",
}
local CpAIJobBunkerSilo_mt = Class(CpAIJobBunkerSilo, CpAIJob)

Expand Down Expand Up @@ -109,8 +109,11 @@ function CpAIJobBunkerSilo:validate(farmId)
return true, ''
end

function CpAIJobBunkerSilo:drawSilos(map)
g_bunkerSiloManager:drawSilos(map, self.bunkerSilo)
function CpAIJobBunkerSilo:draw(map, isOverviewMap)
CpAIJob.draw(self, map, isOverviewMap)
if not isOverviewMap then
g_bunkerSiloManager:drawSilos(map, self.bunkerSilo)
end
end

function CpAIJobBunkerSilo:readStream(streamId, connection)
Expand Down
9 changes: 6 additions & 3 deletions scripts/ai/jobs/CpAIJobCombineUnloader.lua
Original file line number Diff line number Diff line change
Expand Up @@ -228,9 +228,12 @@ function CpAIJobCombineUnloader:validate(farmId)
return isValid, errorMessage
end

function CpAIJobCombineUnloader:drawSelectedField(map)
self.selectedFieldPlot:draw(map)
self.heapPlot:draw(map)
function CpAIJobCombineUnloader:draw(map, isOverviewMap)
CpAIJob.draw(self, map, isOverviewMap)
if not isOverviewMap then
self.selectedFieldPlot:draw(map)
self.heapPlot:draw(map)
end
end

------------------------------------
Expand Down
13 changes: 8 additions & 5 deletions scripts/ai/jobs/CpAIJobFieldWork.lua
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ CpAIJobFieldWork = {
name = "FIELDWORK_CP",
jobName = "CP_job_fieldWork",
GenerateButton = "FIELDWORK_BUTTON",
fieldPositionParameterText = "CP_jobParameters_fieldPosition_title"
fieldPositionParameterText = "CP_fieldWorkJobParameters_fieldPosition_title"
}
local AIJobFieldWorkCp_mt = Class(CpAIJobFieldWork, CpAIJob)

Expand Down Expand Up @@ -45,7 +45,7 @@ end

function CpAIJobFieldWork:setupJobParameters()
CpAIJob.setupJobParameters(self)
self:setupCpJobParameters(CpJobParameters(self))
self:setupCpJobParameters(CpFieldWorkJobParameters(self))
end

---@param vehicle table
Expand Down Expand Up @@ -149,9 +149,12 @@ function CpAIJobFieldWork:validate(farmId)
return true, ''
end

function CpAIJobFieldWork:drawSelectedField(map)
if self.selectedFieldPlot then
self.selectedFieldPlot:draw(map)
function CpAIJobFieldWork:draw(map, isOverviewMap)
CpAIJob.draw(self, map, isOverviewMap)
if not isOverviewMap then
if self.selectedFieldPlot then
self.selectedFieldPlot:draw(map)
end
end
end

Expand Down
Loading

0 comments on commit 3d7fdb1

Please sign in to comment.