Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Mp bug fix and tasks improvement #2838

Merged
merged 6 commits into from
Oct 15, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
70 changes: 70 additions & 0 deletions config/MasterTranslations.xml
Original file line number Diff line number Diff line change
Expand Up @@ -382,6 +382,76 @@
<Text language="en"><![CDATA[AI worker %s has stopped work unexpectedly - automatic cutter attach disabled!]]></Text>
</Translation>
</Category>
<Category name="AI fieldwork task descriptions">
<Translation name="CP_ai_taskDescriptionAttachHeader">
<Text language="de"><![CDATA[Kuppelt das Schneidwerk an]]></Text>
<Text language="en"><![CDATA[Picks the header up]]></Text>
</Translation>
</Category>
<Category name="AI bale finder task descriptions">
<Translation name="CP_ai_taskDescriptionCollectsBales">
<Text language="de"><![CDATA[Sammelt Ballen auf dem Feld]]></Text>
<Text language="en"><![CDATA[Collects bales on the field]]></Text>
</Translation>
<Translation name="CP_ai_taskDescriptionWrapsBales">
<Text language="de"><![CDATA[Wickelt Ballen auf dem Feld]]></Text>
<Text language="en"><![CDATA[Wraps bales on the field]]></Text>
</Translation>
</Category>
<Category name="AI combine unloader task descriptions">
<Translation name="CP_ai_taskDescriptionUnloadCombine">
<Text language="de"><![CDATA[Entlädt Drescher]]></Text>
<Text language="en"><![CDATA[Unloads combine]]></Text>
</Translation>
<Translation name="CP_ai_taskDescriptionWaitsForTargetCombine">
<Text language="de"><![CDATA[Wartet auf Drescher]]></Text>
<Text language="en"><![CDATA[Waits for combine]]></Text>
</Translation>
<Translation name="CP_ai_taskDescriptionUnloadSiloLoader">
<Text language="de"><![CDATA[Entlädt Lade Fahrzeug]]></Text>
<Text language="en"><![CDATA[Unloads loader]]></Text>
</Translation>
<Translation name="CP_ai_taskDescriptionWaitsForTargetSiloLoader">
<Text language="de"><![CDATA[Wartet auf Lade Fahrzeug]]></Text>
<Text language="en"><![CDATA[Waits for loader]]></Text>
</Translation>
<Translation name="CP_ai_taskDescriptionUnloadingToHeap">
<Text language="de"><![CDATA[Entlädt auf einem Haufen]]></Text>
<Text language="en"><![CDATA[Unloads to a heap]]></Text>
</Translation>
<Translation name="CP_ai_taskDescriptionUnloadingToTrailer">
<Text language="de"><![CDATA[Entlädt in ein Anhänger]]></Text>
<Text language="en"><![CDATA[Unloads into trailer]]></Text>
</Translation>
<Translation name="CP_ai_taskDescriptionUnloadingWithGiants">
<Text language="de"><![CDATA[Entlädt mit Giants Helfer]]></Text>
<Text language="en"><![CDATA[Unloads with giants worker]]></Text>
</Translation>
</Category>
<Category name="AI silo worker task descriptions">
<Translation name="CP_ai_taskDescriptionWorksInTheSilo">
<Text language="de"><![CDATA[Arbeitet im Silo]]></Text>
<Text language="en"><![CDATA[Works in the silo]]></Text>
</Translation>
<Translation name="CP_ai_taskDescriptionWaitsForUnloaders">
<Text language="de"><![CDATA[Wartet auf Ablader]]></Text>
<Text language="en"><![CDATA[Waits for unloader]]></Text>
</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>
</Translation>
<Translation name="CP_ai_taskDescriptionUnloadingToTrigger">
<Text language="de"><![CDATA[Entlädt zu einer Abladestation]]></Text>
<Text language="en"><![CDATA[Unloads to an unload trigger]]></Text>
</Translation>
</Category>
<Category name="Vehicle settings">
<Translation name="CP_vehicle_setting_title">
<Text language="de"><![CDATA[Fahrzeugeinstellungen für (%s)]]></Text>
Expand Down
13 changes: 9 additions & 4 deletions scripts/ai/AIDriveStrategyCourse.lua
Original file line number Diff line number Diff line change
Expand Up @@ -640,10 +640,15 @@ function AIDriveStrategyCourse:isCloseToCourseStart(distance)
return self.course:getDistanceFromFirstWaypoint(self.ppc:getCurrentWaypointIx()) < distance
end

--- Event raised when the driver has finished.
--- This gets called in the :stopCurrentAIJob(), as the giants code might stop the driver and not the active strategy.
function AIDriveStrategyCourse:onFinished()
self:raiseControllerEvent(self.onFinishedEvent)
--- Event raised when the driver was stopped.
---@param hasFinished boolean|nil flag passed by the info text
function AIDriveStrategyCourse:onFinished(hasFinished)
self:raiseControllerEvent(self.onFinishedEvent, hasFinished)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

hasFinished is not used in any onFinished() controller function, or is this for the future only?

if hasFinished and self.settings.foldImplementAtEnd:getValue() then
--- Folds implements at the end if the setting is active.
self:debug("Finished with folding implements of the implements.")
self.vehicle:prepareForAIDriving()
end
end

--- This is to set the offsets on the course at start, or update those values
Expand Down
4 changes: 2 additions & 2 deletions scripts/ai/AIDriveStrategyFieldWorkCourse.lua
Original file line number Diff line number Diff line change
Expand Up @@ -101,8 +101,8 @@ function AIDriveStrategyFieldWorkCourse:start(course, startIx, jobParameters)
end

--- Event raised when the driver has finished.
function AIDriveStrategyFieldWorkCourse:onFinished()
AIDriveStrategyFieldWorkCourse:superClass().onFinished(self)
function AIDriveStrategyFieldWorkCourse:onFinished(hasFinished)
AIDriveStrategyFieldWorkCourse:superClass().onFinished(self, hasFinished)
self.remainingTime:reset()
end

Expand Down
5 changes: 3 additions & 2 deletions scripts/ai/InfoTextsManager.lua
Original file line number Diff line number Diff line change
Expand Up @@ -34,14 +34,15 @@ function CpInfoTextElement:init(name, text, id, hasFinished, event, aiMessageCla
self.hasFinished = hasFinished
self.event = event
self.isOnlyShownOnPlayerStart = isOnlyShownOnPlayerStart
self.aiMessageClassName = aiMessageClass
if aiMessageClass then
self.aiMessageClass = CpUtil.getClassObject(aiMessageClass)
end
end

function CpInfoTextElement:__tostring()
return string.format("name: %s, id: %d, text: %s \n => hasFinished: %s, event: %s, hasClass: %s",
self.name, self.id, self.text, tostring(self.hasFinished), tostring(self.event), tostring(self.aiMessageClass))
return string.format("name: %s, id: %d, text: %s => hasFinished: %s, event: %s, hasClass: %s",
self.name, self.id, self.text, tostring(self.hasFinished), tostring(self.event), tostring(self.aiMessageClassName))
end

--- Checks if the given message is assigned to this info text.
Expand Down
6 changes: 4 additions & 2 deletions scripts/ai/controllers/BalerController.lua
Original file line number Diff line number Diff line change
Expand Up @@ -118,9 +118,11 @@ function BalerController:onStart()
end
end

function BalerController:onFinished()
function BalerController:onFinished(hasFinished)
-- TODO: not working, as this probably needs to be called, before the drive is released.
-- Baler.actionEventUnloading(self.implement)
-- if hasFinished and not self.balerSpec.automaticDrop or not self.balerSpec.platformAutomaticDrop then
-- Baler.actionEventUnloading(self.implement)
-- end
end

function BalerController:isThisMyBale(baleObject)
Expand Down
4 changes: 3 additions & 1 deletion scripts/ai/controllers/ImplementController.lua
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,9 @@ function ImplementController:onStart()
--- override
end

function ImplementController:onFinished()
--- Event raised when the driver was stopped.
---@param hasFinished boolean|nil flag passed by the info text.
function ImplementController:onFinished(hasFinished)
--- override
end

Expand Down
49 changes: 34 additions & 15 deletions scripts/ai/jobs/CpAIJob.lua
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,9 @@
--- Every cp job should be derived from this job.
---@class CpAIJob : AIJob
---@field jobTypeIndex number
---@field getTaskByIndex function
---@field currentTaskIndex number
---@field superClass function
CpAIJob = {
name = "",
jobName = "",
Expand Down Expand Up @@ -93,11 +96,35 @@ end
function CpAIJob:stop(aiMessage)
if self.isServer then
local vehicle = self.vehicleParameter:getVehicle()

vehicle:deleteAgent()
vehicle:aiJobFinished()

vehicle:resetCpAllActiveInfoTexts()
local driveStrategy = vehicle:getCpDriveStrategy()
if not aiMessage then
self:debug("No valid ai message given!")
if driveStrategy then
driveStrategy:onFinished()
end
return
end
local releaseMessage, hasFinished, event, isOnlyShownOnPlayerStart =
g_infoTextManager:getInfoTextDataByAIMessage(aiMessage)
if releaseMessage then
self:debug("Stopped with release message %s", tostring(releaseMessage))
end
if driveStrategy then
driveStrategy:onFinished(hasFinished)
end
if event then
SpecializationUtil.raiseEvent(vehicle, event)
end
if releaseMessage and not vehicle:getIsControlled() and not isOnlyShownOnPlayerStart then
--- Only shows the info text, if the vehicle is not entered.
--- TODO: Add check if passing to ad is active maybe?
vehicle:setCpInfoTextActive(releaseMessage)
end
end

CpAIJob:superClass().stop(self, aiMessage)
end

Expand Down Expand Up @@ -177,19 +204,6 @@ function CpAIJob:validate(farmId)
return isValid, errorMessage
end

function CpAIJob:getDescription()
local desc = CpAIJob:superClass().getDescription(self)
local nextTask = self:getTaskByIndex(self.currentTaskIndex)

if nextTask == self.driveToTask then
desc = desc .. " - " .. g_i18n:getText("ai_taskDescriptionDriveToField")
elseif nextTask == self.fieldWorkTask then
desc = desc .. " - " .. g_i18n:getText("ai_taskDescriptionFieldWork")
end

return desc
end

function CpAIJob:getIsStartable(connection)

local vehicle = self.vehicleParameter:getVehicle()
Expand Down Expand Up @@ -337,6 +351,11 @@ function CpAIJob:showNotification(aiMessage)
return
end
local releaseMessage, hasFinished, event = g_infoTextManager:getInfoTextDataByAIMessage(aiMessage)
if not releaseMessage and not aiMessage:isa(AIMessageSuccessStoppedByUser) then
self:debug("No release message found, so we use the giants notification!")
CpAIJob:superClass().showNotification(self, aiMessage)
return
end
local vehicle = self:getVehicle()
--- Makes sure the message is shown, when a player is in the vehicle.
if releaseMessage and vehicle:getIsEntered() then
Expand Down
17 changes: 17 additions & 0 deletions scripts/ai/jobs/CpAIJobBaleFinder.lua
Original file line number Diff line number Diff line change
Expand Up @@ -113,3 +113,20 @@ end
function CpAIJobBaleFinder:drawSelectedField(map)
self.selectedFieldPlot:draw(map)
end

--- Gets the additional task description shown.
function CpAIJobBaleFinder:getDescription()
local desc = CpAIJob:superClass().getDescription(self)
local currentTask = self:getTaskByIndex(self.currentTaskIndex)
if currentTask == self.driveToTask then
desc = desc .. " - " .. g_i18n:getText("ai_taskDescriptionDriveToField")
elseif currentTask == self.baleFinderTask then
local vehicle = self:getVehicle()
if AIUtil.hasChildVehicleWithSpecialization(vehicle, BaleWrapper) then
desc = desc .. " - " .. g_i18n:getText("CP_ai_taskDescriptionWrapsBales")
else
desc = desc .. " - " .. g_i18n:getText("CP_ai_taskDescriptionCollectsBales")
end
end
return desc
end
12 changes: 12 additions & 0 deletions scripts/ai/jobs/CpAIJobBunkerSilo.lua
Original file line number Diff line number Diff line change
Expand Up @@ -130,3 +130,15 @@ function CpAIJobBunkerSilo:readStream(streamId, connection)
local dirX, dirZ = self.cpJobParameters.startPosition:getDirection()
self.bunkerSiloTask:setParkPosition(x, z, angle, dirX, dirZ)
end

--- Gets the additional task description shown.
function CpAIJobBunkerSilo:getDescription()
local desc = CpAIJob:superClass().getDescription(self)
local currentTask = self:getTaskByIndex(self.currentTaskIndex)
if currentTask == self.driveToTask then
desc = desc .. " - " .. g_i18n:getText("ai_taskDescriptionDriveToField")
elseif currentTask == self.bunkerSiloTask then
desc = desc .. " - " .. g_i18n:getText("CP_ai_taskDescriptionWorksInTheSilo")
end
return desc
end
20 changes: 20 additions & 0 deletions scripts/ai/jobs/CpAIJobCombineUnloader.lua
Original file line number Diff line number Diff line change
Expand Up @@ -360,4 +360,24 @@ end

function CpAIJobCombineUnloader:getIsLooping()
return true
end

--- Gets the additional task description shown.
--- TODO: Add the missing description once the task system is better implemented.
---@return unknown
function CpAIJobCombineUnloader:getDescription()
local desc = CpAIJob:superClass().getDescription(self)
local currentTask = self:getTaskByIndex(self.currentTaskIndex)
if currentTask == self.driveToTask then
desc = desc .. " - " .. g_i18n:getText("ai_taskDescriptionDriveToField")
elseif currentTask == self.combineUnloaderTask then
if self.cpJobParameters.unloadTarget:getValue() == CpCombineUnloaderJobParameters.UNLOAD_COMBINE then
desc = desc .. " - " .. g_i18n:getText("CP_ai_taskDescriptionUnloadCombine")
else
desc = desc .. " - " .. g_i18n:getText("CP_ai_taskDescriptionUnloadSiloLoader")
end
elseif currentTask == self.driveToUnloadingTask or currentTask == self.dischargeTask then
desc = desc .. " - " .. g_i18n:getText("CP_ai_taskDescriptionUnloadingWithGiants")
end
return desc
end
16 changes: 15 additions & 1 deletion scripts/ai/jobs/CpAIJobFieldWork.lua
Original file line number Diff line number Diff line change
Expand Up @@ -307,4 +307,18 @@ end
function CpAIJobFieldWork:onFinishAttachCutter()
--- Finished attaching a given header.
self.attachHeaderTask:skip()
end
end

--- Gets the additional task description shown.
function CpAIJobFieldWork:getDescription()
local desc = CpAIJob:superClass().getDescription(self)
local currentTask = self:getTaskByIndex(self.currentTaskIndex)
if currentTask == self.driveToTask then
desc = desc .. " - " .. g_i18n:getText("ai_taskDescriptionDriveToField")
elseif currentTask == self.fieldWorkTask then
desc = desc .. " - " .. g_i18n:getText("ai_taskDescriptionFieldWork")
elseif currentTask == self.attachHeaderTask then
desc = desc .. " - " .. g_i18n:getText("CP_ai_taskDescriptionAttachHeader")
end
return desc
end
13 changes: 13 additions & 0 deletions scripts/ai/jobs/CpAIJobSiloLoader.lua
Original file line number Diff line number Diff line change
Expand Up @@ -364,4 +364,17 @@ function CpAIJobSiloLoader:getConvertedFillTypes()
end
end
return fillTypes
end

--- Gets the additional task description shown.
--- TODO: Add the missing task descriptions
function CpAIJobSiloLoader:getDescription()
local desc = CpAIJob:superClass().getDescription(self)
local currentTask = self:getTaskByIndex(self.currentTaskIndex)
if currentTask == self.driveToTask then
desc = desc .. " - " .. g_i18n:getText("ai_taskDescriptionDriveToField")
elseif currentTask == self.siloLoaderTask then
desc = desc .. " - " .. g_i18n:getText("CP_ai_taskDescriptionWorksInTheSilo")
end
return desc
end
22 changes: 2 additions & 20 deletions scripts/specializations/CpAIWorker.lua
Original file line number Diff line number Diff line change
Expand Up @@ -306,10 +306,7 @@ function CpAIWorker:stopCurrentAIJob(superFunc, message, ...)
CpUtil.infoVehicle(self, "no stop message was given.")
return superFunc(self, message, ...)
end
local releaseMessage, hasFinished, event, isOnlyShownOnPlayerStart = g_infoTextManager:getInfoTextDataByAIMessage(message)

CpUtil.debugVehicle(CpDebug.DBG_FIELDWORK, self, "finished: %s, event: %s",
tostring(hasFinished), tostring(event))

local wasCpActive = self:getIsCpActive()
if wasCpActive then
local driveStrategy = self:getCpDriveStrategy()
Expand All @@ -330,24 +327,9 @@ function CpAIWorker:stopCurrentAIJob(superFunc, message, ...)
end
end
end
driveStrategy:onFinished()
end
end
self:resetCpAllActiveInfoTexts()
--- Only add the info text, if it's available and nobody is in the vehicle.
if not self:getIsControlled() and releaseMessage and not isOnlyShownOnPlayerStart then
self:setCpInfoTextActive(releaseMessage)
end
superFunc(self, message, ...)
if wasCpActive then
if event then
SpecializationUtil.raiseEvent(self, event)
end
if hasFinished and self:getCpSettings().foldImplementAtEnd:getValue() then
--- Folds implements at the end if the setting is active.
self:prepareForAIDriving()
end
end
superFunc(self, message,...)
end

function CpAIWorker:startCpDriveTo(task, jobParameters)
Expand Down
Loading