LUADOC - Farming Simulator 22

Script v1_7_1_0

Engine v1_7_1_0

Foundation Reference

AIImplement

Description
Specialization for extending implements with AI functionality
Functions

addAIDensityHeightTypeRequirement

Description
Definition
addAIDensityHeightTypeRequirement()
Code
574function AIImplement:addAIDensityHeightTypeRequirement(fillType)
575 local spec = self.spec_aiImplement
576
577 table.insert(spec.requiredDensityHeightTypes, {fillType=fillType or 0})
578 self:updateFieldCropsQuery()
579end

addAIFruitProhibitions

Description
Definition
addAIFruitProhibitions()
Code
607function AIImplement:addAIFruitProhibitions(fruitType, minGrowthState, maxGrowthState, customMapId, customMapStartChannel, customMapNumChannels)
608 local spec = self.spec_aiImplement
609
610 table.insert(spec.prohibitedFruitTypes, {fruitType=fruitType or 0,
611 minGrowthState=minGrowthState or 0,
612 maxGrowthState=maxGrowthState or 0,
613 customMapId=customMapId,
614 customMapStartChannel=customMapStartChannel,
615 customMapNumChannels=customMapNumChannels})
616
617 self:updateFieldCropsQuery()
618end

addAIFruitRequirement

Description
Definition
addAIFruitRequirement()
Code
537function AIImplement:addAIFruitRequirement(fruitType, minGrowthState, maxGrowthState, customMapId, customMapStartChannel, customMapNumChannels)
538 local spec = self.spec_aiImplement
539
540 table.insert(spec.requiredFruitTypes, {fruitType=fruitType or 0,
541 minGrowthState=minGrowthState or 0,
542 maxGrowthState=maxGrowthState or 0,
543 customMapId=customMapId,
544 customMapStartChannel=customMapStartChannel,
545 customMapNumChannels=customMapNumChannels})
546 self:updateFieldCropsQuery()
547end

addAIGroundTypeRequirements

Description
Definition
addAIGroundTypeRequirements()
Code
647function AIImplement:addAIGroundTypeRequirements(groundTypes, excludedType1, excludedType2, excludedType3, excludedType4, excludedType5, excludedType6)
648 local spec = self.spec_aiImplement
649 for i=1, #groundTypes do
650 local groundType = groundTypes[i]
651 if groundType ~= excludedType1
652 and groundType ~= excludedType2
653 and groundType ~= excludedType3
654 and groundType ~= excludedType4
655 and groundType ~= excludedType5
656 and groundType ~= excludedType6 then
657 local value = spec.fieldGroundSystem:getFieldGroundValue(groundType)
658 table.insert(spec.terrainDetailRequiredValueRanges, {value, value, spec.groundTypeFirstChannel, spec.groundTypeNumChannels})
659 end
660 end
661
662 self:updateFieldCropsQuery()
663end

addAITerrainDetailProhibitedRange

Description
Definition
addAITerrainDetailProhibitedRange()
Code
693function AIImplement:addAITerrainDetailProhibitedRange(detailType1, detailType2, minState, maxState)
694 table.insert(self.spec_aiImplement.terrainDetailProhibitedValueRanges, {detailType1, detailType2, minState, maxState})
695 self:updateFieldCropsQuery()
696end

addAITerrainDetailRequiredRange

Description
Definition
addAITerrainDetailRequiredRange()
Code
639function AIImplement:addAITerrainDetailRequiredRange(detailType1, detailType2, minState, maxState)
640 local spec = self.spec_aiImplement
641 table.insert(spec.terrainDetailRequiredValueRanges, {detailType1, detailType2, minState or spec.groundTypeFirstChannel, maxState or spec.groundTypeNumChannels})
642 self:updateFieldCropsQuery()
643end

addNodeObjectMapping

Description
Add component nodes to list
Definition
addNodeObjectMapping(table list)
Arguments
tablelistlist
Code
345function AIImplement:addNodeObjectMapping(superFunc, list)
346 superFunc(self, list)
347
348 local spec = self.spec_aiImplement
349 if spec.collisionTrigger ~= nil then
350 list[spec.collisionTrigger] = self
351 end
352end

addVehicleToAIImplementList

Description
Definition
addVehicleToAIImplementList()
Code
334function AIImplement:addVehicleToAIImplementList(superFunc, list)
335 if self:getCanImplementBeUsedForAI() then
336 table.insert(list, {object=self})
337 end
338
339 superFunc(self, list)
340end

aiImplementEndLine

Description
Definition
aiImplementEndLine()
Code
820function AIImplement:aiImplementEndLine()
821 self.spec_aiImplement.isLineStarted = false
822 SpecializationUtil.raiseEvent(self, "onAIImplementEndLine")
823
824 local actionController = self.rootVehicle.actionController
825 if actionController ~= nil then
826 self.rootVehicle.actionController:onAIEvent(self, "onAIImplementEndLine")
827 end
828end

aiImplementStartLine

Description
Definition
aiImplementStartLine()
Code
808function AIImplement:aiImplementStartLine()
809 self.spec_aiImplement.isLineStarted = true
810 SpecializationUtil.raiseEvent(self, "onAIImplementStartLine")
811
812 local actionController = self.rootVehicle.actionController
813 if actionController ~= nil then
814 self.rootVehicle.actionController:onAIEvent(self, "onAIImplementStartLine")
815 end
816end

checkMovingPartDirtyUpdateNode

Description
Definition
checkMovingPartDirtyUpdateNode()
Code
388function AIImplement:checkMovingPartDirtyUpdateNode(superFunc, node, movingPart)
389 superFunc(self, node, movingPart)
390
391 local spec = self.spec_aiImplement
392 if node == spec.leftMarker or node == spec.rightMarker or node == spec.backMarker then
393 Logging.xmlError(self.xmlFile, "Found ai marker node '%s' in active dirty moving part '%s' with limited update distance. Remove limit or adjust hierarchy for correct function. (maxUpdateDistance='-')", getName(node), getName(movingPart.node))
394 end
395 if node == spec.sizeLeftMarker or node == spec.sizeRightMarker or node == spec.sizeBackMarker then
396 Logging.xmlError(self.xmlFile, "Found ai size marker node '%s' in active dirty moving part '%s' with limited update distance. Remove limit or adjust hierarchy for correct function. (maxUpdateDistance='-')", getName(node), getName(movingPart.node))
397 end
398 if spec.collisionTrigger ~= nil then
399 if node == spec.collisionTrigger.node then
400 Logging.xmlError(self.xmlFile, "Found ai collision trigger '%s' in active dirty moving part '%s' with limited update distance. Remove limit or adjust hierarchy for correct function. (maxUpdateDistance='-')", getName(node), getName(movingPart.node))
401 end
402 end
403end

clearAIDensityHeightTypeRequirements

Description
Definition
clearAIDensityHeightTypeRequirements()
Code
583function AIImplement:clearAIDensityHeightTypeRequirements()
584 local spec = self.spec_aiImplement
585 if #spec.requiredDensityHeightTypes > 0 then
586 spec.requiredDensityHeightTypes = {}
587 end
588 self:updateFieldCropsQuery()
589end

clearAIFruitProhibitions

Description
Definition
clearAIFruitProhibitions()
Code
622function AIImplement:clearAIFruitProhibitions()
623 local spec = self.spec_aiImplement
624 if #spec.prohibitedFruitTypes > 0 then
625 spec.prohibitedFruitTypes = {}
626 end
627 self:updateFieldCropsQuery()
628end

clearAIFruitRequirements

Description
Definition
clearAIFruitRequirements()
Code
551function AIImplement:clearAIFruitRequirements()
552 local spec = self.spec_aiImplement
553 if #spec.requiredFruitTypes > 0 then
554 spec.requiredFruitTypes = {}
555 end
556 self:updateFieldCropsQuery()
557end

clearAITerrainDetailProhibitedRange

Description
Definition
clearAITerrainDetailProhibitedRange()
Code
700function AIImplement:clearAITerrainDetailProhibitedRange()
701 self.spec_aiImplement.terrainDetailProhibitedValueRanges = {}
702 self:updateFieldCropsQuery()
703end

clearAITerrainDetailRequiredRange

Description
Definition
clearAITerrainDetailRequiredRange()
Code
667function AIImplement:clearAITerrainDetailRequiredRange()
668 self.spec_aiImplement.terrainDetailRequiredValueRanges = {}
669 self:updateFieldCropsQuery()
670end

createFieldCropsQuery

Description
Creates field crops query
Definition
createFieldCropsQuery()
Code
744function AIImplement:createFieldCropsQuery()
745 local mission = g_currentMission
746 local groundTypeMapId, groundTypeFirstChannel, groundTypeNumChannels = mission.fieldGroundSystem:getDensityMapData(FieldDensityMap.GROUND_TYPE)
747 if groundTypeMapId ~= nil then
748 local spec = self.spec_aiImplement
749 spec.fieldCropyQueryValid = false
750
751 local query = FieldCropsQuery.new(groundTypeMapId)
752 local fruitRequirements = self:getAIFruitRequirements()
753
754 for i=1, #fruitRequirements do
755 local fruitRequirement = fruitRequirements[i]
756 if fruitRequirement.customMapId == nil and fruitRequirement.fruitType ~= FruitType.UNKNOWN then
757 local desc = g_fruitTypeManager:getFruitTypeByIndex(fruitRequirement.fruitType)
758 query:addRequiredCropType(desc.terrainDataPlaneId, fruitRequirement.minGrowthState, fruitRequirement.maxGrowthState, desc.startStateChannel, desc.numStateChannels, groundTypeFirstChannel, groundTypeNumChannels)
759 elseif fruitRequirement.customMapId ~= nil then
760 query:addRequiredCropType(fruitRequirement.customMapId, fruitRequirement.minGrowthState, fruitRequirement.maxGrowthState, fruitRequirement.customMapStartChannel, fruitRequirement.customMapNumChannels, groundTypeFirstChannel, groundTypeNumChannels)
761 end
762 spec.fieldCropyQueryValid = true
763 end
764
765 local fruitProhibitions = self:getAIFruitProhibitions()
766 for i=1, #fruitProhibitions do
767 local fruitProhibition = fruitProhibitions[i]
768 if fruitProhibition.customMapId == nil and fruitProhibition.fruitType ~= FruitType.UNKNOWN then
769 local desc = g_fruitTypeManager:getFruitTypeByIndex(fruitProhibition.fruitType)
770 query:addProhibitedCropType(desc.terrainDataPlaneId, fruitProhibition.minGrowthState, fruitProhibition.maxGrowthState, desc.startStateChannel, desc.numStateChannels, groundTypeFirstChannel, groundTypeNumChannels)
771 elseif fruitProhibition.customMapId ~= nil then
772 query:addProhibitedCropType(fruitProhibition.customMapId, fruitProhibition.minGrowthState, fruitProhibition.maxGrowthState, fruitProhibition.customMapStartChannel, fruitProhibition.customMapNumChannels, groundTypeFirstChannel, groundTypeNumChannels)
773 end
774 spec.fieldCropyQueryValid = true
775 end
776
777 local terrainDetailRequiredValueRanges = self:getAITerrainDetailRequiredRange()
778 for i=1, #terrainDetailRequiredValueRanges do
779 local valueRange = terrainDetailRequiredValueRanges[i]
780 query:addRequiredGroundValue(valueRange[1], valueRange[2], valueRange[3], valueRange[4])
781 spec.fieldCropyQueryValid = true
782 end
783
784 local terrainDetailProhibitValueRanges = self:getAITerrainDetailProhibitedRange()
785 for i=1, #terrainDetailProhibitValueRanges do
786 local valueRange = terrainDetailProhibitValueRanges[i]
787 query:addProhibitedGroundValue(valueRange[1], valueRange[2], valueRange[3], valueRange[4])
788 spec.fieldCropyQueryValid = true
789 end
790
791 --#debug if spec.fieldCropyQueryValid then
792 --#debug spec.debugArea = DebugBitVectorMap.new(15, 0.5, 0.05, 0.1)
793 --#debug spec.debugArea:createWithAIVehicle(self)
794 --#debug end
795
796 spec.fieldCropyQuery = query
797 end
798end

getAIAllowTurnBackward

Description
Definition
getAIAllowTurnBackward()
Code
505function AIImplement:getAIAllowTurnBackward()
506 return self.spec_aiImplement.allowTurnBackward
507end

getAIAreaOverlap

Description
Definition
getAIAreaOverlap()
Code
466function AIImplement:getAIAreaOverlap()
467 return self.spec_aiImplement.overlap
468end

getAIBlockTurnBackward

Description
Definition
getAIBlockTurnBackward()
Code
511function AIImplement:getAIBlockTurnBackward()
512 return self.spec_aiImplement.blockTurnBackward
513end

getAIDensityHeightTypeRequirements

Description
Definition
getAIDensityHeightTypeRequirements()
Code
593function AIImplement:getAIDensityHeightTypeRequirements()
594 return self.spec_aiImplement.requiredDensityHeightTypes
595end

getAIFruitProhibitions

Description
Definition
getAIFruitProhibitions()
Code
632function AIImplement:getAIFruitProhibitions()
633 return self.spec_aiImplement.prohibitedFruitTypes
634end

getAIFruitRequirements

Description
Definition
getAIFruitRequirements()
Code
561function AIImplement:getAIFruitRequirements()
562 return self.spec_aiImplement.requiredFruitTypes
563end

getAIHasNoFullCoverageArea

Description
Definition
getAIHasNoFullCoverageArea()
Code
460function AIImplement:getAIHasNoFullCoverageArea()
461 return self.spec_aiImplement.hasNoFullCoverageArea, self.spec_aiImplement.hasNoFullCoverageAreaOffset
462end

getAIImplementCollisionTrigger

Description
Definition
getAIImplementCollisionTrigger()
Code
472function AIImplement:getAIImplementCollisionTrigger()
473 return self.spec_aiImplement.collisionTrigger
474end

getAIImplementCollisionTriggers

Description
Definition
getAIImplementCollisionTriggers()
Code
478function AIImplement:getAIImplementCollisionTriggers(collisionTriggers)
479 local collisionTrigger = self:getAIImplementCollisionTrigger()
480 if collisionTrigger ~= nil then
481 collisionTriggers[self] = collisionTrigger
482 end
483end

getAIInvertMarkersOnTurn

Description
Definition
getAIInvertMarkersOnTurn()
Code
441function AIImplement:getAIInvertMarkersOnTurn(turnLeft)
442 return false
443end

getAILookAheadSize

Description
Definition
getAILookAheadSize()
Code
454function AIImplement:getAILookAheadSize()
455 return self.spec_aiImplement.lookAheadSize
456end

getAILowerIfAnyIsLowered

Description
Definition
getAILowerIfAnyIsLowered()
Code
493function AIImplement:getAILowerIfAnyIsLowered()
494 return self.spec_aiImplement.lowerIfAnyIsLowered
495end

getAIMarkers

Description
Definition
getAIMarkers()
Code
413function AIImplement:getAIMarkers()
414 local spec = self.spec_aiImplement
415 if spec.useAttributesOfAttachedImplement then
416 if self.getAttachedImplements ~= nil then
417 for _, implement in ipairs(self:getAttachedImplements()) do
418 if implement.object.getAIMarkers ~= nil then
419 return implement.object:getAIMarkers()
420 end
421 end
422 end
423 end
424
425 if spec.aiMarkersInverted then
426 return spec.rightMarker, spec.leftMarker, spec.backMarker, true
427 else
428 return spec.leftMarker, spec.rightMarker, spec.backMarker, false
429 end
430end

getAIMinTurningRadius

Description
Definition
getAIMinTurningRadius()
Code
407function AIImplement:getAIMinTurningRadius()
408 return self.spec_aiImplement.minTurningRadius
409end

getAINeedsLowering

Description
Definition
getAINeedsLowering()
Code
487function AIImplement:getAINeedsLowering()
488 return self.spec_aiImplement.needsLowering
489end

getAINeedsRootAlignment

Description
Definition
getAINeedsRootAlignment()
Code
499function AIImplement:getAINeedsRootAlignment()
500 return self.spec_aiImplement.needsRootAlignment
501end

getAISizeMarkers

Description
Definition
getAISizeMarkers()
Code
447function AIImplement:getAISizeMarkers()
448 local spec = self.spec_aiImplement
449 return spec.sizeLeftMarker, spec.sizeRightMarker, spec.sizeBackMarker
450end

getAITerrainDetailProhibitedRange

Description
Definition
getAITerrainDetailProhibitedRange()
Code
707function AIImplement:getAITerrainDetailProhibitedRange()
708 local spec = self.spec_aiImplement
709
710 if spec.useAttributesOfAttachedImplement then
711 if self.getAttachedImplements ~= nil then
712 for _, implement in ipairs(self:getAttachedImplements()) do
713 if implement.object.getAITerrainDetailProhibitedRange ~= nil then
714 return implement.object:getAITerrainDetailProhibitedRange()
715 end
716 end
717 end
718 end
719
720 return spec.terrainDetailProhibitedValueRanges
721end

getAITerrainDetailRequiredRange

Description
Definition
getAITerrainDetailRequiredRange()
Code
674function AIImplement:getAITerrainDetailRequiredRange()
675 local spec = self.spec_aiImplement
676
677 if spec.useAttributesOfAttachedImplement then
678 if self.getAttachedImplements ~= nil then
679 for _, implement in ipairs(self:getAttachedImplements()) do
680 if implement.object.getAITerrainDetailRequiredRange ~= nil then
681 return implement.object:getAITerrainDetailRequiredRange()
682 end
683 end
684 end
685 end
686
687 return spec.terrainDetailRequiredValueRanges
688end

getAIToolReverserDirectionNode

Description
Definition
getAIToolReverserDirectionNode()
Code
517function AIImplement:getAIToolReverserDirectionNode()
518 return self.spec_aiImplement.toolReverserDirectionNode
519end

getAITurnRadiusLimitation

Description
Definition
getAITurnRadiusLimitation()
Code
523function AIImplement:getAITurnRadiusLimitation()
524 local turningRadiusLimitation = self.spec_aiImplement.turningRadiusLimitation
525 return turningRadiusLimitation.radius, turningRadiusLimitation.rotationJoint, turningRadiusLimitation.wheels, turningRadiusLimitation.rotLimitFactor
526end

getAllowTireTracks

Description
Definition
getAllowTireTracks()
Code
368function AIImplement:getAllowTireTracks(superFunc)
369 return superFunc(self) and not self:getIsAIActive()
370end

getCanAIImplementContinueWork

Description
Definition
getCanAIImplementContinueWork()
Code
317function AIImplement:getCanAIImplementContinueWork()
318 return true, false, nil
319end

getCanImplementBeUsedForAI

Description
Definition
getCanImplementBeUsedForAI()
Code
323function AIImplement:getCanImplementBeUsedForAI()
324 local leftMarker, rightMarker, backMarker, _ = self:getAIMarkers()
325 if leftMarker == nil or rightMarker == nil or backMarker == nil then
326 return false
327 end
328
329 return true
330end

getDoConsumePtoPower

Description
Definition
getDoConsumePtoPower()
Code
374function AIImplement:getDoConsumePtoPower(superFunc)
375 -- do not consume power during headland to avoid slow turning
376 local rootVehicle = self.rootVehicle
377 if rootVehicle.getAIFieldWorkerIsTurning ~= nil then
378 if rootVehicle:getAIFieldWorkerIsTurning() then
379 return false
380 end
381 end
382
383 return superFunc(self)
384end

getFieldCropsQuery

Description
Returns field crops query and creates it on first run
Definition
getFieldCropsQuery()
Code
725function AIImplement:getFieldCropsQuery()
726 local spec = self.spec_aiImplement
727 if spec.fieldCropyQuery == nil then
728 self:createFieldCropsQuery()
729 end
730
731 return spec.fieldCropyQuery, spec.fieldCropyQueryValid
732end

getIsAIImplementInLine

Description
Definition
getIsAIImplementInLine()
Code
802function AIImplement:getIsAIImplementInLine()
803 return self.spec_aiImplement.isLineStarted
804end

initSpecialization

Description
Definition
initSpecialization()
Code
23function AIImplement.initSpecialization()
24 g_configurationManager:addConfigurationType("ai", g_i18n:getText("configuration_design"), "ai", nil, nil, nil, ConfigurationUtil.SELECTOR_MULTIOPTION)
25
26 local schema = Vehicle.xmlSchema
27 schema:setXMLSpecializationType("AIImplement")
28
29 AIImplement.registerAIImplementXMLPaths(schema, "vehicle.ai")
30 AIImplement.registerAIImplementXMLPaths(schema, "vehicle.ai.aiConfigurations.aiConfiguration(?)")
31
32 ObjectChangeUtil.registerObjectChangeXMLPaths(schema, "vehicle.ai.aiConfigurations.aiConfiguration(?)")
33
34 schema:setXMLSpecializationType()
35end

loadAICollisionTriggerFromXML

Description
Definition
loadAICollisionTriggerFromXML()
Code
297function AIImplement:loadAICollisionTriggerFromXML(xmlFile, key)
298 local collisionTrigger = {}
299 collisionTrigger.node = xmlFile:getValue(key .. ".collisionTrigger#node", nil, self.components, self.i3dMappings)
300 if collisionTrigger.node ~= nil then
301 if getHasClassId(collisionTrigger.node, ClassIds.SHAPE) then
302 Logging.xmlWarning(xmlFile, "Obsolete ai collision trigger ground. Please replace with empty transform group and add size attributes. '%s'", key .. ".collisionTrigger#node")
303 end
304
305 collisionTrigger.width = xmlFile:getValue(key .. ".collisionTrigger#width", 4)
306 collisionTrigger.height = xmlFile:getValue(key .. ".collisionTrigger#height", 3)
307 collisionTrigger.length = xmlFile:getValue(key .. ".collisionTrigger#length", 5)
308 else
309 return nil
310 end
311
312 return collisionTrigger
313end

onLoad

Description
Called on loading
Definition
onLoad(table savegame)
Arguments
tablesavegamesavegame
Code
185function AIImplement:onLoad(savegame)
186 local spec = self.spec_aiImplement
187
188 local baseName = "vehicle.ai"
189
190 XMLUtil.checkDeprecatedXMLElements(self.xmlFile, baseName .. ".areaMarkers#leftIndex", baseName .. ".areaMarkers#leftNode") -- FS17 to FS 19
191 XMLUtil.checkDeprecatedXMLElements(self.xmlFile, baseName .. ".areaMarkers#rightIndex", baseName .. ".areaMarkers#rightNode") -- FS17 to FS 19
192 XMLUtil.checkDeprecatedXMLElements(self.xmlFile, baseName .. ".areaMarkers#backIndex", baseName .. ".areaMarkers#backNode") -- FS17 to FS 19
193
194 XMLUtil.checkDeprecatedXMLElements(self.xmlFile, baseName .. ".sizeMarkers#leftIndex", baseName .. ".sizeMarkers#leftNode") -- FS17 to FS 19
195 XMLUtil.checkDeprecatedXMLElements(self.xmlFile, baseName .. ".sizeMarkers#rightIndex", baseName .. ".sizeMarkers#rightNode") -- FS17 to FS 19
196 XMLUtil.checkDeprecatedXMLElements(self.xmlFile, baseName .. ".sizeMarkers#backIndex", baseName .. ".sizeMarkers#backNode") -- FS17 to FS 19
197
198 XMLUtil.checkDeprecatedXMLElements(self.xmlFile, baseName .. ".trafficCollisionTrigger#index", baseName .. ".collisionTrigger#node") -- FS17 to FS 19
199 XMLUtil.checkDeprecatedXMLElements(self.xmlFile, baseName .. ".trafficCollisionTrigger#node", baseName .. ".collisionTrigger#node") -- FS17 to FS 19
200 XMLUtil.checkDeprecatedXMLElements(self.xmlFile, baseName .. ".collisionTrigger#index", baseName .. ".collisionTrigger#node") -- FS17 to FS 19
201 XMLUtil.checkDeprecatedXMLElements(self.xmlFile, "vehicle.aiLookAheadSize#value", baseName .. ".lookAheadSize#value") -- FS17 to FS 19
202
203 XMLUtil.checkDeprecatedXMLElements(self.xmlFile, baseName .. ".toolReverserDirectionNode#index", baseName .. ".toolReverserDirectionNode#node") -- FS17 to FS 19
204 XMLUtil.checkDeprecatedXMLElements(self.xmlFile, baseName .. ".turningRadiusLimiation", baseName .. ".turningRadiusLimitation") -- FS17 to FS 19
205
206 XMLUtil.checkDeprecatedXMLElements(self.xmlFile, baseName .. ".forceTurnNoBackward#value", baseName .. ".allowTurnBackward#value (inverted)") -- FS17 to FS 19
207
208 XMLUtil.checkDeprecatedXMLElements(self.xmlFile, baseName .. ".needsLowering#lowerIfAnyIsLowerd", baseName .. ".allowTurnBackward#lowerIfAnyIsLowered") -- FS19 to FS22
209
210 local aiConfigurationId = Utils.getNoNil(self.configurations["ai"], 1)
211 local configKey = string.format("vehicle.ai.aiConfigurations.aiConfiguration(%d)", aiConfigurationId - 1)
212 ObjectChangeUtil.updateObjectChanges(self.xmlFile, "vehicle.ai.aiConfigurations.aiConfiguration", aiConfigurationId, self.components, self)
213
214 if self.xmlFile:hasProperty(configKey) then
215 baseName = configKey
216 end
217
218 spec.minTurningRadius = self.xmlFile:getValue(baseName .. ".minTurningRadius#value")
219
220 spec.leftMarker = self.xmlFile:getValue(baseName .. ".areaMarkers#leftNode", nil, self.components, self.i3dMappings)
221 spec.rightMarker = self.xmlFile:getValue(baseName .. ".areaMarkers#rightNode", nil, self.components, self.i3dMappings)
222 spec.backMarker = self.xmlFile:getValue(baseName .. ".areaMarkers#backNode", nil, self.components, self.i3dMappings)
223 spec.aiMarkersInverted = false
224
225 spec.sizeLeftMarker = self.xmlFile:getValue(baseName .. ".sizeMarkers#leftNode", nil, self.components, self.i3dMappings)
226 spec.sizeRightMarker = self.xmlFile:getValue(baseName .. ".sizeMarkers#rightNode", nil, self.components, self.i3dMappings)
227 spec.sizeBackMarker = self.xmlFile:getValue(baseName .. ".sizeMarkers#backNode", nil, self.components, self.i3dMappings)
228
229 spec.collisionTrigger = self:loadAICollisionTriggerFromXML(self.xmlFile, baseName)
230
231 spec.needsLowering = self.xmlFile:getValue(baseName .. ".needsLowering#value", true)
232 spec.lowerIfAnyIsLowered = self.xmlFile:getValue(baseName .. ".needsLowering#lowerIfAnyIsLowered", false)
233 spec.needsRootAlignment = self.xmlFile:getValue(baseName .. ".needsRootAlignment#value", true)
234
235 spec.allowTurnBackward = self.xmlFile:getValue(baseName .. ".allowTurnBackward#value", true)
236 spec.blockTurnBackward = self.xmlFile:getValue(baseName .. ".blockTurnBackward#value", false)
237
238 spec.toolReverserDirectionNode = self.xmlFile:getValue(baseName .. ".toolReverserDirectionNode#node", nil, self.components, self.i3dMappings)
239
240 spec.turningRadiusLimitation = {}
241 spec.turningRadiusLimitation.rotationJoint = self.xmlFile:getValue(baseName .. ".turningRadiusLimitation#rotationJointNode", nil, self.components, self.i3dMappings)
242 if spec.turningRadiusLimitation.rotationJoint ~= nil then
243 spec.turningRadiusLimitation.wheelIndices = self.xmlFile:getValue(baseName .. ".turningRadiusLimitation#wheelIndices", nil, true)
244 end
245
246 spec.turningRadiusLimitation.radius = self.xmlFile:getValue(baseName .. ".turningRadiusLimitation#radius")
247 spec.turningRadiusLimitation.rotLimitFactor = self.xmlFile:getValue(baseName .. ".turningRadiusLimitation#rotLimitFactor", 1)
248
249 spec.lookAheadSize = self.xmlFile:getValue(baseName .. ".lookAheadSize#value", 2)
250 spec.useAttributesOfAttachedImplement = self.xmlFile:getValue(baseName .. ".useAttributesOfAttachedImplement#value", false)
251
252 spec.hasNoFullCoverageArea = self.xmlFile:getValue(baseName .. ".hasNoFullCoverageArea#value", false)
253 spec.hasNoFullCoverageAreaOffset = self.xmlFile:getValue(baseName .. ".hasNoFullCoverageArea#offset", 0)
254
255 spec.overlap = self.xmlFile:getValue(baseName .. ".overlap#value")
256
257 spec.terrainDetailRequiredValueRanges = {}
258 spec.terrainDetailProhibitedValueRanges = {}
259
260 spec.requiredFruitTypes = {}
261 spec.prohibitedFruitTypes = {}
262
263 spec.requiredDensityHeightTypes = {}
264
265 local _
266 spec.fieldGroundSystem = g_currentMission.fieldGroundSystem
267 _, spec.groundTypeFirstChannel, spec.groundTypeNumChannels = spec.fieldGroundSystem:getDensityMapData(FieldDensityMap.GROUND_TYPE)
268
269 spec.fieldCropyQuery = nil
270 spec.fieldCropyQueryValid = false -- query is valid if at least one parameter is set, otherwise it will return always valid ground if nothing is set -> in this case we skip the query and directly return "0"
271
272 spec.isLineStarted = false
273end

onPostLoad

Description
Definition
onPostLoad()
Code
277function AIImplement:onPostLoad(savegame)
278 if self.getWheels ~= nil then
279 local spec = self.spec_aiImplement
280 if spec.turningRadiusLimitation.wheelIndices ~= nil then
281 spec.turningRadiusLimitation.wheels = {}
282 local wheels = self:getWheels()
283 for _, index in ipairs(spec.turningRadiusLimitation.wheelIndices) do
284 local wheel = wheels[index]
285 if wheel ~= nil then
286 table.insert(spec.turningRadiusLimitation.wheels, wheels[index])
287 else
288 Logging.xmlWarning(self.xmlFile, "Unknown wheel index '%s' defined in '%s'", index, "vehicle.ai.turningRadiusLimitation#wheelIndices")
289 end
290 end
291 end
292 end
293end

prerequisitesPresent

Description
Checks if all prerequisite specializations are loaded
Definition
prerequisitesPresent(table specializations)
Arguments
tablespecializationsspecializations
Return Values
booleanhasPrerequisitetrue if all prerequisite specializations are loaded
Code
17function AIImplement.prerequisitesPresent(specializations)
18 return true
19end

registerAICollisionTriggerXMLPaths

Description
Definition
registerAICollisionTriggerXMLPaths()
Code
74function AIImplement.registerAICollisionTriggerXMLPaths(schema, basePath)
75 schema:register(XMLValueType.NODE_INDEX, basePath .. ".collisionTrigger#node", "Collision trigger node")
76 schema:register(XMLValueType.FLOAT, basePath .. ".collisionTrigger#width", "Width of ai collision trigger", 4)
77 schema:register(XMLValueType.FLOAT, basePath .. ".collisionTrigger#height", "Width of ai collision trigger", 3)
78 schema:register(XMLValueType.FLOAT, basePath .. ".collisionTrigger#length", "Max. length of ai collision trigger", 5)
79end

registerAIImplementXMLPaths

Description
Definition
registerAIImplementXMLPaths()
Code
39function AIImplement.registerAIImplementXMLPaths(schema, basePath)
40 schema:register(XMLValueType.FLOAT, basePath .. ".minTurningRadius#value", "Min turning radius")
41
42 schema:register(XMLValueType.NODE_INDEX, basePath .. ".areaMarkers#leftNode", "AI area left node")
43 schema:register(XMLValueType.NODE_INDEX, basePath .. ".areaMarkers#rightNode", "AI area right node")
44 schema:register(XMLValueType.NODE_INDEX, basePath .. ".areaMarkers#backNode", "AI area back node")
45
46 schema:register(XMLValueType.NODE_INDEX, basePath .. ".sizeMarkers#leftNode", "Size area left node")
47 schema:register(XMLValueType.NODE_INDEX, basePath .. ".sizeMarkers#rightNode", "Size area right node")
48 schema:register(XMLValueType.NODE_INDEX, basePath .. ".sizeMarkers#backNode", "Size area back node")
49
50 AIImplement.registerAICollisionTriggerXMLPaths(schema, basePath)
51
52 schema:register(XMLValueType.BOOL, basePath .. ".needsLowering#value", "AI needs to lower this tool", true)
53 schema:register(XMLValueType.BOOL, basePath .. ".needsLowering#lowerIfAnyIsLowered", "Lower tool of any attached ai tool is lowered", false)
54 schema:register(XMLValueType.BOOL, basePath .. ".needsRootAlignment#value", "Tool needs to point in the same direction as the root while working", true)
55 schema:register(XMLValueType.BOOL, basePath .. ".allowTurnBackward#value", "Worker is allowed the turn backward with this tool", true)
56 schema:register(XMLValueType.BOOL, basePath .. ".blockTurnBackward#value", "Can be used for non ai tools to block ai from driving backward", false)
57
58 schema:register(XMLValueType.NODE_INDEX, basePath .. ".toolReverserDirectionNode#node", "Reverser direction node, target node if driving backward")
59 schema:register(XMLValueType.NODE_INDEX, basePath .. ".turningRadiusLimitation#rotationJointNode", "Turn radius limitation joint node")
60 schema:register(XMLValueType.VECTOR_N, basePath .. ".turningRadiusLimitation#wheelIndices", "Turn radius limitation wheel indices")
61 schema:register(XMLValueType.FLOAT, basePath .. ".turningRadiusLimitation#radius", "Turn radius limitation radius")
62 schema:register(XMLValueType.FLOAT, basePath .. ".turningRadiusLimitation#rotLimitFactor", "Changes the rot limit of attacher joint or component joint for turning radius calculation", 1)
63
64 schema:register(XMLValueType.FLOAT, basePath .. ".lookAheadSize#value", "Look a head size to check ground in front of tool", 2)
65 schema:register(XMLValueType.BOOL, basePath .. ".useAttributesOfAttachedImplement#value", "Use AI attributes (area & fruit/ground requirements) of first attached implement", false)
66 schema:register(XMLValueType.BOOL, basePath .. ".hasNoFullCoverageArea#value", "Tool as a no full coverage area (e.g. plows)", false)
67 schema:register(XMLValueType.FLOAT, basePath .. ".hasNoFullCoverageArea#offset", "Non full coverage area offset", 0)
68
69 schema:register(XMLValueType.FLOAT, basePath .. ".overlap#value", "Defines the ai line to line overlap", AIVehicleUtil.AREA_OVERLAP)
70end

registerEventListeners

Description
Definition
registerEventListeners()
Code
177function AIImplement.registerEventListeners(vehicleType)
178 SpecializationUtil.registerEventListener(vehicleType, "onLoad", AIImplement)
179 SpecializationUtil.registerEventListener(vehicleType, "onPostLoad", AIImplement)
180end

registerEvents

Description
Definition
registerEvents()
Code
83function AIImplement.registerEvents(vehicleType)
84 SpecializationUtil.registerEvent(vehicleType, "onAIImplementStart")
85 SpecializationUtil.registerEvent(vehicleType, "onAIImplementActive")
86 SpecializationUtil.registerEvent(vehicleType, "onAIImplementEnd")
87
88 SpecializationUtil.registerEvent(vehicleType, "onAIImplementStartLine")
89 SpecializationUtil.registerEvent(vehicleType, "onAIImplementEndLine")
90
91 SpecializationUtil.registerEvent(vehicleType, "onAIImplementStartTurn")
92 SpecializationUtil.registerEvent(vehicleType, "onAIImplementTurnProgress")
93 SpecializationUtil.registerEvent(vehicleType, "onAIImplementEndTurn")
94
95 SpecializationUtil.registerEvent(vehicleType, "onAIImplementBlock")
96 SpecializationUtil.registerEvent(vehicleType, "onAIImplementContinue")
97
98 SpecializationUtil.registerEvent(vehicleType, "onAIImplementPrepare")
99
100 SpecializationUtil.registerEvent(vehicleType, "onAIImplementJobVehicleBlock")
101 SpecializationUtil.registerEvent(vehicleType, "onAIImplementJobVehicleContinue")
102end

registerFunctions

Description
Definition
registerFunctions()
Code
106function AIImplement.registerFunctions(vehicleType)
107 SpecializationUtil.registerFunction(vehicleType, "loadAICollisionTriggerFromXML", AIImplement.loadAICollisionTriggerFromXML)
108 SpecializationUtil.registerFunction(vehicleType, "getCanAIImplementContinueWork", AIImplement.getCanAIImplementContinueWork)
109 SpecializationUtil.registerFunction(vehicleType, "getCanImplementBeUsedForAI", AIImplement.getCanImplementBeUsedForAI)
110 SpecializationUtil.registerFunction(vehicleType, "getAIMinTurningRadius", AIImplement.getAIMinTurningRadius)
111 SpecializationUtil.registerFunction(vehicleType, "getAIMarkers", AIImplement.getAIMarkers)
112 SpecializationUtil.registerFunction(vehicleType, "setAIMarkersInverted", AIImplement.setAIMarkersInverted)
113 SpecializationUtil.registerFunction(vehicleType, "getAIInvertMarkersOnTurn", AIImplement.getAIInvertMarkersOnTurn)
114 SpecializationUtil.registerFunction(vehicleType, "getAISizeMarkers", AIImplement.getAISizeMarkers)
115 SpecializationUtil.registerFunction(vehicleType, "getAILookAheadSize", AIImplement.getAILookAheadSize)
116 SpecializationUtil.registerFunction(vehicleType, "getAIHasNoFullCoverageArea", AIImplement.getAIHasNoFullCoverageArea)
117 SpecializationUtil.registerFunction(vehicleType, "getAIAreaOverlap", AIImplement.getAIAreaOverlap)
118
119 SpecializationUtil.registerFunction(vehicleType, "getAIImplementCollisionTrigger", AIImplement.getAIImplementCollisionTrigger)
120 SpecializationUtil.registerFunction(vehicleType, "getAIImplementCollisionTriggers", AIImplement.getAIImplementCollisionTriggers)
121
122 SpecializationUtil.registerFunction(vehicleType, "getAINeedsLowering", AIImplement.getAINeedsLowering)
123 SpecializationUtil.registerFunction(vehicleType, "getAILowerIfAnyIsLowered", AIImplement.getAILowerIfAnyIsLowered)
124 SpecializationUtil.registerFunction(vehicleType, "getAINeedsRootAlignment", AIImplement.getAINeedsRootAlignment)
125 SpecializationUtil.registerFunction(vehicleType, "getAIAllowTurnBackward", AIImplement.getAIAllowTurnBackward)
126 SpecializationUtil.registerFunction(vehicleType, "getAIBlockTurnBackward", AIImplement.getAIBlockTurnBackward)
127 SpecializationUtil.registerFunction(vehicleType, "getAIToolReverserDirectionNode", AIImplement.getAIToolReverserDirectionNode)
128 SpecializationUtil.registerFunction(vehicleType, "getAITurnRadiusLimitation", AIImplement.getAITurnRadiusLimitation)
129
130 SpecializationUtil.registerFunction(vehicleType, "setAIFruitProhibitions", AIImplement.setAIFruitProhibitions)
131 SpecializationUtil.registerFunction(vehicleType, "addAIFruitProhibitions", AIImplement.addAIFruitProhibitions)
132 SpecializationUtil.registerFunction(vehicleType, "clearAIFruitProhibitions", AIImplement.clearAIFruitProhibitions)
133 SpecializationUtil.registerFunction(vehicleType, "getAIFruitProhibitions", AIImplement.getAIFruitProhibitions)
134
135 SpecializationUtil.registerFunction(vehicleType, "setAIFruitRequirements", AIImplement.setAIFruitRequirements)
136 SpecializationUtil.registerFunction(vehicleType, "addAIFruitRequirement", AIImplement.addAIFruitRequirement)
137 SpecializationUtil.registerFunction(vehicleType, "clearAIFruitRequirements", AIImplement.clearAIFruitRequirements)
138 SpecializationUtil.registerFunction(vehicleType, "getAIFruitRequirements", AIImplement.getAIFruitRequirements)
139
140 SpecializationUtil.registerFunction(vehicleType, "setAIDensityHeightTypeRequirements", AIImplement.setAIDensityHeightTypeRequirements)
141 SpecializationUtil.registerFunction(vehicleType, "addAIDensityHeightTypeRequirement", AIImplement.addAIDensityHeightTypeRequirement)
142 SpecializationUtil.registerFunction(vehicleType, "clearAIDensityHeightTypeRequirements", AIImplement.clearAIDensityHeightTypeRequirements)
143 SpecializationUtil.registerFunction(vehicleType, "getAIDensityHeightTypeRequirements", AIImplement.getAIDensityHeightTypeRequirements)
144
145 SpecializationUtil.registerFunction(vehicleType, "addAITerrainDetailRequiredRange", AIImplement.addAITerrainDetailRequiredRange)
146 SpecializationUtil.registerFunction(vehicleType, "addAIGroundTypeRequirements", AIImplement.addAIGroundTypeRequirements)
147 SpecializationUtil.registerFunction(vehicleType, "clearAITerrainDetailRequiredRange", AIImplement.clearAITerrainDetailRequiredRange)
148 SpecializationUtil.registerFunction(vehicleType, "getAITerrainDetailRequiredRange", AIImplement.getAITerrainDetailRequiredRange)
149
150 SpecializationUtil.registerFunction(vehicleType, "addAITerrainDetailProhibitedRange", AIImplement.addAITerrainDetailProhibitedRange)
151 SpecializationUtil.registerFunction(vehicleType, "clearAITerrainDetailProhibitedRange", AIImplement.clearAITerrainDetailProhibitedRange)
152 SpecializationUtil.registerFunction(vehicleType, "getAITerrainDetailProhibitedRange", AIImplement.getAITerrainDetailProhibitedRange)
153
154 SpecializationUtil.registerFunction(vehicleType, "getFieldCropsQuery", AIImplement.getFieldCropsQuery)
155 SpecializationUtil.registerFunction(vehicleType, "updateFieldCropsQuery", AIImplement.updateFieldCropsQuery)
156 SpecializationUtil.registerFunction(vehicleType, "createFieldCropsQuery", AIImplement.createFieldCropsQuery)
157
158 SpecializationUtil.registerFunction(vehicleType, "getIsAIImplementInLine", AIImplement.getIsAIImplementInLine)
159
160 SpecializationUtil.registerFunction(vehicleType, "aiImplementStartLine", AIImplement.aiImplementStartLine)
161 SpecializationUtil.registerFunction(vehicleType, "aiImplementEndLine", AIImplement.aiImplementEndLine)
162end

registerOverwrittenFunctions

Description
Definition
registerOverwrittenFunctions()
Code
166function AIImplement.registerOverwrittenFunctions(vehicleType)
167 SpecializationUtil.registerOverwrittenFunction(vehicleType, "addVehicleToAIImplementList", AIImplement.addVehicleToAIImplementList)
168 SpecializationUtil.registerOverwrittenFunction(vehicleType, "addNodeObjectMapping", AIImplement.addNodeObjectMapping)
169 SpecializationUtil.registerOverwrittenFunction(vehicleType, "removeNodeObjectMapping", AIImplement.removeNodeObjectMapping)
170 SpecializationUtil.registerOverwrittenFunction(vehicleType, "getAllowTireTracks", AIImplement.getAllowTireTracks)
171 SpecializationUtil.registerOverwrittenFunction(vehicleType, "getDoConsumePtoPower", AIImplement.getDoConsumePtoPower)
172 SpecializationUtil.registerOverwrittenFunction(vehicleType, "checkMovingPartDirtyUpdateNode", AIImplement.checkMovingPartDirtyUpdateNode)
173end

removeNodeObjectMapping

Description
Remove component nodes from list
Definition
removeNodeObjectMapping(table list)
Arguments
tablelistlist
Code
357function AIImplement:removeNodeObjectMapping(superFunc, list)
358 superFunc(self, list)
359
360 local spec = self.spec_aiImplement
361 if spec.collisionTrigger ~= nil then
362 list[spec.collisionTrigger] = nil
363 end
364end

setAIDensityHeightTypeRequirements

Description
Definition
setAIDensityHeightTypeRequirements()
Code
567function AIImplement:setAIDensityHeightTypeRequirements(fillType)
568 self:clearAIDensityHeightTypeRequirements()
569 self:addAIDensityHeightTypeRequirement(fillType)
570end

setAIFruitProhibitions

Description
Definition
setAIFruitProhibitions()
Code
599function AIImplement:setAIFruitProhibitions(fruitType, minGrowthState, maxGrowthState)
600 self:clearAIFruitProhibitions()
601 self:addAIFruitProhibitions(fruitType, minGrowthState, maxGrowthState)
602 self:updateFieldCropsQuery()
603end

setAIFruitRequirements

Description
Definition
setAIFruitRequirements()
Code
530function AIImplement:setAIFruitRequirements(fruitType, minGrowthState, maxGrowthState)
531 self:clearAIFruitRequirements()
532 self:addAIFruitRequirement(fruitType, minGrowthState, maxGrowthState)
533end

setAIMarkersInverted

Description
Definition
setAIMarkersInverted()
Code
434function AIImplement:setAIMarkersInverted(state)
435 local spec = self.spec_aiImplement
436 spec.aiMarkersInverted = not spec.aiMarkersInverted
437end

updateFieldCropsQuery

Description
Recreate if the Field crops query already exists (= if it was already used)
Definition
updateFieldCropsQuery()
Code
736function AIImplement:updateFieldCropsQuery()
737 if self.spec_aiImplement.fieldCropyQuery ~= nil then
738 self:createFieldCropsQuery()
739 end
740end