Script v1_7_1_0
- AI
- Animals
- Collections
- Contracts
- Debug
- Economy
- Elements
- EnvironmentalScore
- Errors
- Events
- GUI
- Handtools
- Hud
- I3d
- Input
- Jobs
- Maps
- Materials
- Misc
- Objects
- Parameters
- Placeables
- Placement
- Player
- Shop
- Sounds
- Specialization
- Specializations
- AIConveyorBelt
- AIDrivable
- AIFieldWorker
- AIImplement
- AIJobVehicle
- AIVehicle
- AIVehicleObstacle
- AnimatedVehicle
- ArticulatedAxis
- Attachable
- AttacherJointControl
- AttacherJoints
- AutoLoader
- BaleGrab
- BaleLoader
- Baler
- BaleWrapper
- BaseMaterial
- BigBag
- BunkerSiloCompacter
- BunkerSiloInteractor
- CCTDrivable
- Combine
- ConnectionHoses
- ConveyorBelt
- Cover
- CrabSteering
- Crawlers
- CropSensor
- Cultivator
- Cutter
- Cylindered
- CylinderedFoldable
- Dashboard
- Dischargeable
- Drivable
- DynamicallyLoadedParts
- DynamicMountAttacher
- Enterable
- ExtendedAIVehicle
- ExtendedCombine
- ExtendedMotorized
- ExtendedMower
- ExtendedSowingMachine
- ExtendedSprayer
- ExtendedWearable
- FertilizingCultivator
- FertilizingSowingMachine
- FillTriggerVehicle
- FillUnit
- FillVolume
- Foldable
- FoliageBending
- ForageWagon
- FrontloaderAttacher
- FruitPreparer
- GroundAdjustedNodes
- GroundReference
- HeadlandAnimation
- Honk
- HookLiftContainer
- HookLiftTrailer
- IKChains
- InlineWrapper
- JigglingParts
- Leveler
- LicensePlates
- Lights
- LivestockTrailer
- Locomotive
- LogGrab
- ManureBarrel
- ManureSensor
- MixerWagon
- Motorized
- Mountable
- Mower
- Mulcher
- MultipleItemPurchase
- Pallet
- Pickup
- Pipe
- PlaceableAI
- PlaceableAnimatedObjects
- PlaceableBeehive
- PlaceableBeehivePalletSpa...
- PlaceableBunkerSilo
- PlaceableBuyingStation
- PlaceableCartridgePlayer
- PlaceableChargingStation
- PlaceableClearAreas
- PlaceableColorable
- PlaceableDeletedNodes
- PlaceableDoghouse
- PlaceableDynamicallyLoade...
- PlaceableFarmhouse
- PlaceableFence
- PlaceableFoliageAreas
- PlaceableGreenhouse
- PlaceableHighPressureWash...
- PlaceableHotspots
- PlaceableHusbandry
- PlaceableHusbandryAnimals
- PlaceableHusbandryFeeding...
- PlaceableHusbandryFence
- PlaceableHusbandryFood
- PlaceableHusbandryLiquidM...
- PlaceableHusbandryMilk
- PlaceableHusbandryPallets
- PlaceableHusbandryStraw
- PlaceableHusbandryWater
- PlaceableIncomePerHour
- PlaceableIndoorAreas
- PlaceableInfoTrigger
- PlaceableLeveling
- PlaceableLights
- PlaceableManureHeap
- PlaceablePlacement
- PlaceableProductionPoint
- PlaceableSellingStation
- PlaceableSilo
- PlaceableSiloExtension
- PlaceableSolarPanels
- PlaceableTipOcclusionArea...
- PlaceableTrainSystem
- PlaceableTriggerMarkers
- PlaceableVine
- PlaceableWardrobe
- PlaceableWeatherStation
- PlaceableWeighingStation
- PlaceableWindTurbine
- PlaceableWorkshop
- Plow
- PlowPacker
- PowerConsumer
- PowerTakeOffs
- PrecisionFarmingStatistic
- PushHandTool
- RandomlyMovingParts
- ReceivingHopper
- ReverseDriving
- Rideable
- RidgeMarker
- Roller
- Ropes
- RTKStation
- SaltSpreader
- SemiTrailerFront
- Shovel
- SlopeCompensation
- SmartAttach
- SoilSampler
- SowingMachine
- SpeedRotatingParts
- SplineVehicle
- Sprayer
- StonePicker
- StrawBlower
- StumpCutter
- SupportVehicle
- Suspensions
- Tedder
- TensionBeltObject
- TensionBelts
- TestAreas
- TipOccluder
- Trailer
- TreePlanter
- TreeSaplingPallet
- TreeSaw
- TurnOnVehicle
- VariableWorkWidth
- VehicleSettings
- VineCutter
- VineDetector
- VinePrepruner
- Washable
- WaterTrailer
- Wearable
- Weeder
- WeedSpotSpray
- Wheels
- WindBending
- Windrower
- Wipers
- WoodCrusher
- WoodHarvester
- WorkArea
- WorkMode
- WorkParticles
- StateMachine
- Statistics
- Tasks
- Triggers
- Utils
- Vehicles
Engine v1_7_1_0
- AI
- Animation
- Camera
- Entity
- Fillplanes
- general
- General
- I3D
- Input
- Lighting
- Math
- Network
- Node
- NoteNode
- Overlays
- Particle System
- Physics
- Rendering
- Scenegraph
- Shape
- Sound
- Spline
- String
- Terrain Detail
- Text Rendering
- Tire Track
- VoiceChat
- XML
Foundation Reference
Plow
DescriptionSpecialization for plows providing additional folding/rotating functionalityFunctions
- actionControllerRotateEvent
- actionEventLimitToField
- actionEventTurn
- doCheckSpeedLimit
- getAIInvertMarkersOnTurn
- getAllowsLowering
- getCanAIImplementContinueWork
- getCanBeSelected
- getDefaultSpeedLimit
- getDirtMultiplier
- getIsAIPreparingToDrive
- getIsAIReadyToDrive
- getIsFoldAllowed
- getIsFoldMiddleAllowed
- getIsPlowRotationAllowed
- getIsSpeedRotatingPartActive
- getIsWorkAreaActive
- getPlowForceLimitToField
- getPlowLimitToField
- getSpeedRotatingPartDirection
- getWearMultiplier
- initSpecialization
- isDetachAllowed
- loadSpeedRotatingPartFromXML
- loadWorkAreaFromXML
- onAIImplementStartTurn
- onAIImplementTurnProgress
- onDeactivate
- onDelete
- onEndWorkAreaProcessing
- onFinishAnimation
- onLoad
- onPostAttach
- onPostLoad
- onPreDetach
- onReadStream
- onRegisterActionEvents
- onRootVehicleChanged
- onStartAnimation
- onStartWorkAreaProcessing
- onUpdate
- onWriteStream
- prerequisitesPresent
- processPlowArea
- registerEventListeners
- registerFunctions
- registerOverwrittenFunctions
- registerXMLPaths
- saveToXMLFile
- setPlowAIRequirements
- setPlowLimitToField
- setRotationCenter
- setRotationMax
actionControllerRotateEvent
DescriptionDefinitionactionControllerRotateEvent()Code
947 | function Plow.actionControllerRotateEvent(self, direction) |
948 | local spec = self.spec_plow |
949 | if spec.rotationPart.turnAnimation ~= nil then |
950 | if self:getIsPlowRotationAllowed() then |
951 | if spec.rotationMax then |
952 | self:setRotationMax(false) |
953 | end |
954 | end |
955 | end |
956 | |
957 | return true |
958 | end |
actionEventLimitToField
DescriptionDefinitionactionEventLimitToField()Code
938 | function Plow.actionEventLimitToField(self, actionName, inputValue, callbackState, isAnalog) |
939 | local spec = self.spec_plow |
940 | if not self:getPlowForceLimitToField() then |
941 | self:setPlowLimitToField(not spec.limitToField) |
942 | end |
943 | end |
actionEventTurn
DescriptionDefinitionactionEventTurn()Code
927 | function Plow.actionEventTurn(self, actionName, inputValue, callbackState, isAnalog) |
928 | local spec = self.spec_plow |
929 | if spec.rotationPart.turnAnimation ~= nil then |
930 | if self:getIsPlowRotationAllowed() then |
931 | self:setRotationMax(not spec.rotationMax) |
932 | end |
933 | end |
934 | end |
doCheckSpeedLimit
DescriptionDefinitiondoCheckSpeedLimit()Code
609 | function Plow:doCheckSpeedLimit(superFunc) |
610 | return superFunc(self) or (self.spec_plow.onlyActiveWhenLowered and self:getIsImplementChainLowered()) |
611 | end |
getAIInvertMarkersOnTurn
DescriptionDefinitiongetAIInvertMarkersOnTurn()Code
666 | function Plow:getAIInvertMarkersOnTurn(superFunc, turnLeft) |
667 | local spec = self.spec_plow |
668 | if spec.rotationPart.turnAnimation ~= nil then |
669 | if turnLeft then |
670 | return spec.rotationMax == spec.rotateLeftToMax |
671 | else |
672 | return spec.rotationMax ~= spec.rotateLeftToMax |
673 | end |
674 | end |
675 | |
676 | return false |
677 | end |
getAllowsLowering
DescriptionReturns true if lowering is allowedDefinition
getAllowsLowering()Return Values
boolean | allowed | lowering is allowed |
707 | function Plow:getAllowsLowering(superFunc) |
708 | local spec = self.spec_plow |
709 | if self:getIsAnimationPlaying(spec.rotationPart.turnAnimation) then |
710 | return false |
711 | end |
712 | |
713 | return superFunc(self) |
714 | end |
getCanAIImplementContinueWork
DescriptionDefinitiongetCanAIImplementContinueWork()Code
655 | function Plow:getCanAIImplementContinueWork(superFunc) |
656 | local canContinue, stopAI, stopReason = superFunc(self) |
657 | if not canContinue then |
658 | return false, stopAI, stopReason |
659 | end |
660 | |
661 | return not self:getIsAnimationPlaying(self.spec_plow.rotationPart.turnAnimation) |
662 | end |
getCanBeSelected
DescriptionDefinitiongetCanBeSelected()Code
681 | function Plow:getCanBeSelected(superFunc) |
682 | return true |
683 | end |
getDefaultSpeedLimit
DescriptionDefinitiongetDefaultSpeedLimit()Code
627 | function Plow.getDefaultSpeedLimit() |
628 | return 15 |
629 | end |
getDirtMultiplier
DescriptionDefinitiongetDirtMultiplier()Code
527 | function Plow:getDirtMultiplier(superFunc) |
528 | local multiplier = superFunc(self) |
529 | |
530 | local spec = self.spec_plow |
531 | if spec.isWorking then |
532 | multiplier = multiplier + self:getWorkDirtMultiplier() * self:getLastSpeed() / self.speedLimit |
533 | end |
534 | |
535 | return multiplier |
536 | end |
getIsAIPreparingToDrive
DescriptionDefinitiongetIsAIPreparingToDrive()Code
729 | function Plow:getIsAIPreparingToDrive(superFunc) |
730 | local spec = self.spec_plow |
731 | if self:getIsAnimationPlaying(spec.rotationPart.turnAnimation) then |
732 | return true |
733 | end |
734 | |
735 | return superFunc(self) |
736 | end |
getIsAIReadyToDrive
DescriptionDefinitiongetIsAIReadyToDrive()Code
718 | function Plow:getIsAIReadyToDrive(superFunc) |
719 | local spec = self.spec_plow |
720 | if spec.rotationMax or self:getIsAnimationPlaying(spec.rotationPart.turnAnimation) then |
721 | return false |
722 | end |
723 | |
724 | return superFunc(self) |
725 | end |
getIsFoldAllowed
DescriptionDefinitiongetIsFoldAllowed()Code
487 | function Plow:getIsFoldAllowed(superFunc, direction, onAiTurnOn) |
488 | local spec = self.spec_plow |
489 | |
490 | if spec.rotationPart.limitFoldRotationMax ~= nil and spec.rotationPart.limitFoldRotationMax == spec.rotationMax then |
491 | return false, spec.texts.warningFoldingPlowTurned |
492 | end |
493 | |
494 | if spec.rotationPart.turnAnimation ~= nil and self.getAnimationTime ~= nil then |
495 | local rotationTime = self:getAnimationTime(spec.rotationPart.turnAnimation) |
496 | if rotationTime > spec.rotationPart.foldRotationMaxLimit or rotationTime < spec.rotationPart.foldRotationMinLimit then |
497 | return false, spec.texts.warningFoldingPlowTurned |
498 | end |
499 | end |
500 | |
501 | if not spec.rotationPart.rotationAllowedIfLowered and self.getIsLowered ~= nil and self:getIsLowered() then |
502 | return false, spec.texts.warningFoldingLowered |
503 | end |
504 | |
505 | return superFunc(self, direction, onAiTurnOn) |
506 | end |
getIsFoldMiddleAllowed
DescriptionDefinitiongetIsFoldMiddleAllowed()Code
510 | function Plow:getIsFoldMiddleAllowed(superFunc) |
511 | local spec = self.spec_plow |
512 | |
513 | if spec.rotationPart.limitFoldRotationMax ~= nil and spec.rotationPart.limitFoldRotationMax == spec.rotationMax then |
514 | return false |
515 | end |
516 | if spec.rotationPart.turnAnimation ~= nil and self.getAnimationTime ~= nil then |
517 | local rotationTime = self:getAnimationTime(spec.rotationPart.turnAnimation) |
518 | if rotationTime > spec.rotationPart.foldRotationMaxLimit or rotationTime < spec.rotationPart.foldRotationMinLimit then |
519 | return false |
520 | end |
521 | end |
522 | return superFunc(self) |
523 | end |
getIsPlowRotationAllowed
DescriptionDefinitiongetIsPlowRotationAllowed()Code
439 | function Plow:getIsPlowRotationAllowed() |
440 | local spec = self.spec_plow |
441 | |
442 | if self.getFoldAnimTime ~= nil then |
443 | local foldAnimTime = self:getFoldAnimTime() |
444 | if foldAnimTime > spec.rotationPart.rotationFoldMaxLimit or foldAnimTime < spec.rotationPart.rotationFoldMinLimit then |
445 | return false |
446 | end |
447 | end |
448 | |
449 | if not spec.rotationPart.rotationAllowedIfLowered and self.getIsLowered ~= nil and self:getIsLowered() then |
450 | return false |
451 | end |
452 | |
453 | return true |
454 | end |
getIsSpeedRotatingPartActive
DescriptionDefinitiongetIsSpeedRotatingPartActive()Code
569 | function Plow:getIsSpeedRotatingPartActive(superFunc, speedRotatingPart) |
570 | local spec = self.spec_plow |
571 | |
572 | if spec.rotationPart.turnAnimation ~= nil and speedRotatingPart.disableOnTurn then |
573 | local turnAnimTime = self:getAnimationTime(spec.rotationPart.turnAnimation) |
574 | if turnAnimTime ~= nil then |
575 | local enabled |
576 | if speedRotatingPart.turnAnimLimitSide < 0 then |
577 | enabled = (turnAnimTime <= speedRotatingPart.turnAnimLimit) |
578 | elseif speedRotatingPart.turnAnimLimitSide > 0 then |
579 | enabled = (1-turnAnimTime <= speedRotatingPart.turnAnimLimit) |
580 | else |
581 | enabled = (turnAnimTime <= speedRotatingPart.turnAnimLimit or 1-turnAnimTime <= speedRotatingPart.turnAnimLimit) |
582 | end |
583 | if not enabled then |
584 | return false |
585 | end |
586 | end |
587 | end |
588 | |
589 | return superFunc(self, speedRotatingPart) |
590 | end |
getIsWorkAreaActive
DescriptionDefinitiongetIsWorkAreaActive()Code
633 | function Plow:getIsWorkAreaActive(superFunc, workArea) |
634 | if not superFunc(self, workArea) then |
635 | return false |
636 | end |
637 | |
638 | local spec = self.spec_plow |
639 | |
640 | if spec.startActivationTime > g_currentMission.time then |
641 | return false |
642 | end |
643 | |
644 | if spec.onlyActiveWhenLowered and self.getIsLowered ~= nil then |
645 | if not self:getIsLowered(false) then |
646 | return false |
647 | end |
648 | end |
649 | |
650 | return true |
651 | end |
getPlowForceLimitToField
DescriptionReturns if plow limit to field is forced and not changeableDefinition
getPlowForceLimitToField()Return Values
boolean | isForced | is forced |
466 | function Plow:getPlowForceLimitToField() |
467 | return self.spec_plow.forceLimitToField |
468 | end |
getPlowLimitToField
DescriptionReturns if plow is limited to the fieldDefinition
getPlowLimitToField()Return Values
boolean | isLimited | is limited to field |
459 | function Plow:getPlowLimitToField() |
460 | return self.spec_plow.limitToField |
461 | end |
getSpeedRotatingPartDirection
DescriptionDefinitiongetSpeedRotatingPartDirection()Code
594 | function Plow:getSpeedRotatingPartDirection(superFunc, speedRotatingPart) |
595 | local spec = self.spec_plow |
596 | |
597 | if spec.rotationPart.turnAnimation ~= nil then |
598 | local turnAnimTime = self:getAnimationTime(spec.rotationPart.turnAnimation) |
599 | if turnAnimTime > 0.5 and speedRotatingPart.invertDirectionOnRotation then |
600 | return -1 |
601 | end |
602 | end |
603 | |
604 | return superFunc(self, speedRotatingPart) |
605 | end |
getWearMultiplier
DescriptionReturns current wear multiplierDefinition
getWearMultiplier()Return Values
float | dirtMultiplier | current wear multiplier |
541 | function Plow:getWearMultiplier(superFunc) |
542 | local multiplier = superFunc(self) |
543 | |
544 | local spec = self.spec_plow |
545 | if spec.isWorking then |
546 | multiplier = multiplier + self:getWorkWearMultiplier() * self:getLastSpeed() / self.speedLimit |
547 | end |
548 | |
549 | return multiplier |
550 | end |
initSpecialization
DescriptionDefinitioninitSpecialization()Code
35 | function Plow.initSpecialization() |
36 | g_configurationManager:addConfigurationType("plow", g_i18n:getText("configuration_design"), "plow", nil, nil, nil, ConfigurationUtil.SELECTOR_MULTIOPTION) |
37 | g_workAreaTypeManager:addWorkAreaType("plow", true) |
38 | |
39 | local schema = Vehicle.xmlSchema |
40 | schema:setXMLSpecializationType("Plow") |
41 | |
42 | Plow.registerXMLPaths(schema, "vehicle.plow") |
43 | Plow.registerXMLPaths(schema, "vehicle.plow.plowConfigurations.plowConfiguration(?)") |
44 | |
45 | ObjectChangeUtil.registerObjectChangeXMLPaths(schema, "vehicle.plow.plowConfigurations.plowConfiguration(?)") |
46 | |
47 | schema:register(XMLValueType.BOOL, SpeedRotatingParts.SPEED_ROTATING_PART_XML_KEY .. "#disableOnTurn", "Disable while turning", true) |
48 | schema:register(XMLValueType.FLOAT, SpeedRotatingParts.SPEED_ROTATING_PART_XML_KEY .. "#turnAnimLimit", "Turn animation limit", 0) |
49 | schema:register(XMLValueType.FLOAT, SpeedRotatingParts.SPEED_ROTATING_PART_XML_KEY .. "#turnAnimLimitSide", "Turn animation limit side", 0) |
50 | schema:register(XMLValueType.BOOL, SpeedRotatingParts.SPEED_ROTATING_PART_XML_KEY .. "#invertDirectionOnRotation", "Invert direction on rotation", true) |
51 | |
52 | schema:setXMLSpecializationType() |
53 | |
54 | local schemaSavegame = Vehicle.xmlSchemaSavegame |
55 | schemaSavegame:register(XMLValueType.BOOL, "vehicles.vehicle(?).plow#rotationMax", "Rotation max.") |
56 | schemaSavegame:register(XMLValueType.FLOAT, "vehicles.vehicle(?).plow#turnAnimTime", "Turn animation time") |
57 | end |
isDetachAllowed
DescriptionReturns true if detach is allowedDefinition
isDetachAllowed()Return Values
boolean | detachAllowed | detach is allowed |
688 | function Plow:isDetachAllowed(superFunc) |
689 | local spec = self.spec_plow |
690 | if self:getIsAnimationPlaying(spec.rotationPart.turnAnimation) then |
691 | return false |
692 | end |
693 | |
694 | if spec.rotationPart.turnAnimation ~= nil then |
695 | local animTime = self:getAnimationTime(spec.rotationPart.turnAnimation) |
696 | if animTime < spec.rotationPart.detachMinLimit or animTime > spec.rotationPart.detachMaxLimit then |
697 | return false, spec.rotationPart.detachWarning, true |
698 | end |
699 | end |
700 | |
701 | return superFunc(self) |
702 | end |
loadSpeedRotatingPartFromXML
DescriptionDefinitionloadSpeedRotatingPartFromXML()Code
554 | function Plow:loadSpeedRotatingPartFromXML(superFunc, speedRotatingPart, xmlFile, key) |
555 | if not superFunc(self, speedRotatingPart, xmlFile, key) then |
556 | return false |
557 | end |
558 | |
559 | speedRotatingPart.disableOnTurn = xmlFile:getValue(key .. "#disableOnTurn", true) |
560 | speedRotatingPart.turnAnimLimit = xmlFile:getValue(key .. "#turnAnimLimit", 0) |
561 | speedRotatingPart.turnAnimLimitSide = xmlFile:getValue(key .. "#turnAnimLimitSide", 0) |
562 | speedRotatingPart.invertDirectionOnRotation = xmlFile:getValue(key .. "#invertDirectionOnRotation", true) |
563 | |
564 | return true |
565 | end |
loadWorkAreaFromXML
DescriptionDefinitionloadWorkAreaFromXML()Code
615 | function Plow:loadWorkAreaFromXML(superFunc, workArea, xmlFile, key) |
616 | local retValue = superFunc(self, workArea, xmlFile, key) |
617 | |
618 | if workArea.type == WorkAreaType.DEFAULT then |
619 | workArea.type = WorkAreaType.PLOW |
620 | end |
621 | |
622 | return retValue |
623 | end |
onAIImplementStartTurn
DescriptionDefinitiononAIImplementStartTurn()Code
863 | function Plow:onAIImplementStartTurn() |
864 | self.spec_plow.ai.lastHeadlandPosition = 0 |
865 | end |
onAIImplementTurnProgress
DescriptionDefinitiononAIImplementTurnProgress()Code
869 | function Plow:onAIImplementTurnProgress(progress, left) |
870 | local spec = self.spec_plow |
871 | |
872 | if spec.ai.lastHeadlandPosition < spec.ai.rotateToCenterHeadlandPos and progress > spec.ai.rotateToCenterHeadlandPos |
873 | and progress < spec.ai.rotateCompletelyHeadlandPos then |
874 | self:setRotationCenter() |
875 | elseif spec.ai.lastHeadlandPosition < spec.ai.rotateCompletelyHeadlandPos and progress > spec.ai.rotateCompletelyHeadlandPos then |
876 | self:setRotationMax(left) |
877 | end |
878 | |
879 | spec.ai.lastHeadlandPosition = progress |
880 | end |
onDeactivate
DescriptionDefinitiononDeactivate()Code
853 | function Plow:onDeactivate() |
854 | if self.isClient then |
855 | local spec = self.spec_plow |
856 | g_soundManager:stopSamples(spec.samples) |
857 | spec.isWorkSamplePlaying = false |
858 | end |
859 | end |
onDelete
DescriptionDefinitiononDelete()Code
260 | function Plow:onDelete() |
261 | local spec = self.spec_plow |
262 | g_soundManager:deleteSamples(spec.samples) |
263 | end |
onEndWorkAreaProcessing
DescriptionDefinitiononEndWorkAreaProcessing()Code
785 | function Plow:onEndWorkAreaProcessing(dt) |
786 | local spec = self.spec_plow |
787 | |
788 | if self.isServer then |
789 | local stats = g_currentMission:farmStats(self:getLastTouchedFarmlandFarmId()) |
790 | |
791 | local lastStatsArea = spec.workAreaParameters.lastStatsArea |
792 | if lastStatsArea > 0 then |
793 | local ha = MathUtil.areaToHa(lastStatsArea, g_currentMission:getFruitPixelsToSqm()) -- 4096px are mapped to 2048m |
794 | stats:updateStats("plowedHectares", ha) |
795 | self:updateLastWorkedArea(lastStatsArea) |
796 | end |
797 | |
798 | if spec.isWorking then |
799 | stats:updateStats("plowedTime", dt/(1000*60)) |
800 | end |
801 | end |
802 | |
803 | if self.isClient then |
804 | if spec.isWorking then |
805 | if not spec.isWorkSamplePlaying then |
806 | g_soundManager:playSample(spec.samples.work) |
807 | spec.isWorkSamplePlaying = true |
808 | end |
809 | else |
810 | if spec.isWorkSamplePlaying then |
811 | g_soundManager:stopSample(spec.samples.work) |
812 | spec.isWorkSamplePlaying = false |
813 | end |
814 | end |
815 | end |
816 | end |
onFinishAnimation
DescriptionDefinitiononFinishAnimation()Code
893 | function Plow:onFinishAnimation(animName) |
894 | local spec = self.spec_plow |
895 | if animName == spec.rotationPart.turnAnimation then |
896 | g_soundManager:stopSample(spec.samples.turn) |
897 | end |
898 | end |
onLoad
DescriptionDefinitiononLoad()Code
154 | function Plow:onLoad(savegame) |
155 | |
156 | if self:getGroundReferenceNodeFromIndex(1) == nil then |
157 | print("Warning: No ground reference nodes in "..self.configFileName) |
158 | end |
159 | |
160 | XMLUtil.checkDeprecatedXMLElements(self.xmlFile, "vehicle.rotationPart", "vehicle.plow.rotationPart") --FS17 to FS19 |
161 | XMLUtil.checkDeprecatedXMLElements(self.xmlFile, "vehicle.ploughDirectionNode#index", "vehicle.plow.directionNode#node") --FS17 to FS19 |
162 | XMLUtil.checkDeprecatedXMLElements(self.xmlFile, "vehicle.rotateLeftToMax#value", "vehicle.plow.rotateLeftToMax#value") --FS17 to FS19 |
163 | XMLUtil.checkDeprecatedXMLElements(self.xmlFile, "vehicle.animTimeCenterPosition#value", "vehicle.plow.ai#centerPosition") --FS17 to FS19 |
164 | XMLUtil.checkDeprecatedXMLElements(self.xmlFile, "vehicle.aiPlough#rotateEarly", "vehicle.plow.ai#rotateCompletelyHeadlandPos") --FS17 to FS19 |
165 | XMLUtil.checkDeprecatedXMLElements(self.xmlFile, "vehicle.onlyActiveWhenLowered#value", "vehicle.plow.onlyActiveWhenLowered#value") --FS17 to FS19 |
166 | |
167 | local plowConfigurationId = self.configurations["plow"] or 1 |
168 | local configKey = string.format("vehicle.plow.plowConfigurations.plowConfiguration(%d)", plowConfigurationId - 1) |
169 | ObjectChangeUtil.updateObjectChanges(self.xmlFile, "vehicle.plow.plowConfigurations.plowConfiguration", plowConfigurationId, self.components, self) |
170 | |
171 | if not self.xmlFile:hasProperty(configKey) then |
172 | configKey = "vehicle.plow" |
173 | end |
174 | |
175 | local spec = self.spec_plow |
176 | |
177 | spec.rotationPart = {} |
178 | spec.rotationPart.turnAnimation = self.xmlFile:getValue(configKey .. ".rotationPart#turnAnimationName") |
179 | spec.rotationPart.foldMinLimit = self.xmlFile:getValue(configKey .. ".rotationPart#foldMinLimit", 0) |
180 | spec.rotationPart.foldMaxLimit = self.xmlFile:getValue(configKey .. ".rotationPart#foldMaxLimit", 1) |
181 | spec.rotationPart.limitFoldRotationMax = self.xmlFile:getValue(configKey .. ".rotationPart#limitFoldRotationMax") |
182 | spec.rotationPart.foldRotationMinLimit = self.xmlFile:getValue(configKey .. ".rotationPart#foldRotationMinLimit", 0) |
183 | spec.rotationPart.foldRotationMaxLimit = self.xmlFile:getValue(configKey .. ".rotationPart#foldRotationMaxLimit", 1) |
184 | spec.rotationPart.rotationFoldMinLimit = self.xmlFile:getValue(configKey .. ".rotationPart#rotationFoldMinLimit", 0) |
185 | spec.rotationPart.rotationFoldMaxLimit = self.xmlFile:getValue(configKey .. ".rotationPart#rotationFoldMaxLimit", 1) |
186 | spec.rotationPart.detachMinLimit = self.xmlFile:getValue(configKey .. ".rotationPart#detachMinLimit", 0) |
187 | spec.rotationPart.detachMaxLimit = self.xmlFile:getValue(configKey .. ".rotationPart#detachMaxLimit", 1) |
188 | spec.rotationPart.rotationAllowedIfLowered = self.xmlFile:getValue(configKey .. ".rotationPart#rotationAllowedIfLowered", true) |
189 | |
190 | spec.rotationPart.detachWarning = string.format(self.xmlFile:getValue(configKey .. ".rotationPart#detachWarning", "warning_detachNotAllowedPlowTurn", self.customEnvironment, false)) |
191 | |
192 | spec.directionNode = self.xmlFile:getValue(configKey .. ".directionNode#node", self.components[1].node, self.components, self.i3dMappings) |
193 | |
194 | self:setPlowAIRequirements() |
195 | |
196 | spec.ai = {} |
197 | spec.ai.centerPosition = self.xmlFile:getValue(configKey .. ".ai#centerPosition", 0.5) |
198 | spec.ai.rotateToCenterHeadlandPos = self.xmlFile:getValue(configKey .. ".ai#rotateToCenterHeadlandPos", 0.5) |
199 | spec.ai.rotateCompletelyHeadlandPos = self.xmlFile:getValue(configKey .. ".ai#rotateCompletelyHeadlandPos", 0.5) |
200 | spec.ai.lastHeadlandPosition = 0 |
201 | |
202 | spec.rotateLeftToMax = self.xmlFile:getValue(configKey .. ".rotateLeftToMax#value", true) |
203 | spec.onlyActiveWhenLowered = self.xmlFile:getValue(configKey .. ".onlyActiveWhenLowered#value", true) |
204 | spec.rotationMax = false |
205 | spec.startActivationTimeout = 2000 |
206 | spec.startActivationTime = 0 |
207 | spec.lastPlowArea = 0 |
208 | spec.limitToField = true |
209 | spec.forceLimitToField = false |
210 | spec.wasTurnAnimationStopped = false |
211 | spec.isWorking = false |
212 | |
213 | if self.isClient then |
214 | spec.samples = {} |
215 | spec.samples.turn = g_soundManager:loadSampleFromXML(self.xmlFile, configKey .. ".sounds", "turn", self.baseDirectory, self.components, 0, AudioGroup.VEHICLE, self.i3dMappings, self) |
216 | spec.samples.work = g_soundManager:loadSampleFromXML(self.xmlFile, configKey .. ".sounds", "work", self.baseDirectory, self.components, 0, AudioGroup.VEHICLE, self.i3dMappings, self) |
217 | spec.isWorkSamplePlaying = false |
218 | end |
219 | |
220 | spec.texts = {} |
221 | spec.texts.warningFoldingLowered = g_i18n:getText("warning_foldingNotWhileLowered") |
222 | spec.texts.warningFoldingPlowTurned = g_i18n:getText("warning_foldingNotWhilePlowTurned") |
223 | spec.texts.turnPlow = g_i18n:getText("action_turnPlow") |
224 | spec.texts.allowCreateFields = g_i18n:getText("action_allowCreateFields") |
225 | spec.texts.limitToFields = g_i18n:getText("action_limitToFields") |
226 | |
227 | spec.workAreaParameters = {} |
228 | spec.workAreaParameters.limitToField = self:getPlowLimitToField() |
229 | spec.workAreaParameters.forceLimitToField = self:getPlowForceLimitToField() |
230 | spec.workAreaParameters.angle = 0 |
231 | spec.workAreaParameters.lastChangedArea = 0 |
232 | spec.workAreaParameters.lastStatsArea = 0 |
233 | spec.workAreaParameters.lastTotalArea = 0 |
234 | |
235 | if not self.isClient then |
236 | SpecializationUtil.removeEventListener(self, "onUpdate", Plow) |
237 | end |
238 | end |
onPostAttach
DescriptionCalled if vehicle gets attachedDefinition
onPostAttach(table attacherVehicle, integer inputJointDescIndex, integer jointDescIndex)Arguments
table | attacherVehicle | attacher vehicle |
integer | inputJointDescIndex | index of input attacher joint |
integer | jointDescIndex | index of attacher joint it gets attached to |
823 | function Plow:onPostAttach(attacherVehicle, inputJointDescIndex, jointDescIndex) |
824 | local spec = self.spec_plow |
825 | |
826 | spec.startActivationTime = g_currentMission.time + spec.startActivationTimeout |
827 | if spec.wasTurnAnimationStopped then |
828 | local dir = 1 |
829 | if not spec.rotationMax then |
830 | dir = -1 |
831 | end |
832 | self:playAnimation(spec.rotationPart.turnAnimation, dir, self:getAnimationTime(spec.rotationPart.turnAnimation), true) |
833 | spec.wasTurnAnimationStopped = false |
834 | end |
835 | end |
onPostLoad
DescriptionDefinitiononPostLoad()Code
242 | function Plow:onPostLoad(savegame) |
243 | if savegame ~= nil and not savegame.resetVehicles then |
244 | local rotationMax = savegame.xmlFile:getValue(savegame.key..".plow#rotationMax") |
245 | if rotationMax ~= nil then |
246 | if self:getIsPlowRotationAllowed() then |
247 | local plowTurnAnimTime = savegame.xmlFile:getValue(savegame.key..".plow#turnAnimTime") |
248 | self:setRotationMax(rotationMax, true, plowTurnAnimTime) |
249 | |
250 | if self.updateCylinderedInitial ~= nil then |
251 | self:updateCylinderedInitial(false) |
252 | end |
253 | end |
254 | end |
255 | end |
256 | end |
onPreDetach
DescriptionCalled if vehicle gets detachedDefinition
onPreDetach(table attacherVehicle, table implement)Arguments
table | attacherVehicle | attacher vehicle |
table | implement | implement |
841 | function Plow:onPreDetach(attacherVehicle, implement) |
842 | local spec = self.spec_plow |
843 | |
844 | spec.limitToField = true |
845 | if self:getIsAnimationPlaying(spec.rotationPart.turnAnimation) then |
846 | self:stopAnimation(spec.rotationPart.turnAnimation, true) |
847 | spec.wasTurnAnimationStopped = true |
848 | end |
849 | end |
onReadStream
DescriptionDefinitiononReadStream()Code
278 | function Plow:onReadStream(streamId, connection) |
279 | local spec = self.spec_plow |
280 | |
281 | local rotationMax = streamReadBool(streamId) |
282 | local turnAnimTime |
283 | if spec.rotationPart.turnAnimation ~= nil and self.playAnimation ~= nil then |
284 | turnAnimTime = streamReadFloat32(streamId) |
285 | end |
286 | |
287 | self:setRotationMax(rotationMax, true, turnAnimTime) |
288 | |
289 | if self.updateCylinderedInitial ~= nil then |
290 | self:updateCylinderedInitial(false) |
291 | end |
292 | end |
onRegisterActionEvents
DescriptionDefinitiononRegisterActionEvents()Code
740 | function Plow:onRegisterActionEvents(isActiveForInput, isActiveForInputIgnoreSelection) |
741 | if self.isClient then |
742 | local spec = self.spec_plow |
743 | self:clearActionEventsTable(spec.actionEvents) |
744 | |
745 | if isActiveForInputIgnoreSelection then |
746 | if spec.rotationPart.turnAnimation ~= nil then |
747 | local _, actionEventId = self:addPoweredActionEvent(spec.actionEvents, InputAction.IMPLEMENT_EXTRA, self, Plow.actionEventTurn, false, true, false, true, nil) |
748 | g_inputBinding:setActionEventTextPriority(actionEventId, GS_PRIO_HIGH) |
749 | g_inputBinding:setActionEventText(actionEventId, spec.texts.turnPlow) |
750 | end |
751 | |
752 | local _, actionEventId = self:addActionEvent(spec.actionEvents, InputAction.IMPLEMENT_EXTRA3, self, Plow.actionEventLimitToField, false, true, false, true, nil) |
753 | g_inputBinding:setActionEventTextPriority(actionEventId, GS_PRIO_NORMAL) |
754 | end |
755 | end |
756 | end |
onRootVehicleChanged
DescriptionCalled if root vehicle changesDefinition
onRootVehicleChanged(table rootVehicle)Arguments
table | rootVehicle | root vehicle |
903 | function Plow:onRootVehicleChanged(rootVehicle) |
904 | local spec = self.spec_foldable |
905 | if #spec.foldingParts > 0 then |
906 | local actionController = rootVehicle.actionController |
907 | if actionController ~= nil then |
908 | if spec.controlledActionRotate ~= nil then |
909 | spec.controlledActionRotate:updateParent(actionController) |
910 | return |
911 | end |
912 | |
913 | spec.controlledActionRotate = actionController:registerAction("rotatePlow", nil, 3) |
914 | spec.controlledActionRotate:setCallback(self, Plow.actionControllerRotateEvent) |
915 | spec.controlledActionRotate:setFinishedFunctions(self, function(vehicle) return not vehicle.spec_foldable.rotationMax end, false, false) |
916 | spec.controlledActionRotate:addAIEventListener(self, "onAIImplementPrepare", -1, true) |
917 | else |
918 | if spec.controlledActionRotate ~= nil then |
919 | spec.controlledActionRotate:remove() |
920 | end |
921 | end |
922 | end |
923 | end |
onStartAnimation
DescriptionDefinitiononStartAnimation()Code
884 | function Plow:onStartAnimation(animName) |
885 | local spec = self.spec_plow |
886 | if animName == spec.rotationPart.turnAnimation then |
887 | g_soundManager:playSample(spec.samples.turn) |
888 | end |
889 | end |
onStartWorkAreaProcessing
DescriptionDefinitiononStartWorkAreaProcessing()Code
760 | function Plow:onStartWorkAreaProcessing(dt) |
761 | local spec = self.spec_plow |
762 | |
763 | spec.isWorking = false |
764 | |
765 | local limitToField = self:getPlowLimitToField() |
766 | local limitFruitDestructionToField = limitToField |
767 | if not g_currentMission:getHasPlayerPermission("createFields", self:getOwner(), nil, true) then |
768 | limitToField = true |
769 | limitFruitDestructionToField = true |
770 | end |
771 | |
772 | local dx,_,dz = localDirectionToWorld(spec.directionNode, 0, 0, 1) |
773 | local angle = FSDensityMapUtil.convertToDensityMapAngle(MathUtil.getYRotationFromDirection(dx, dz), g_currentMission.fieldGroundSystem:getGroundAngleMaxValue()) |
774 | |
775 | spec.workAreaParameters.limitToField = limitToField |
776 | spec.workAreaParameters.limitFruitDestructionToField = limitFruitDestructionToField |
777 | spec.workAreaParameters.angle = angle |
778 | spec.workAreaParameters.lastChangedArea = 0 |
779 | spec.workAreaParameters.lastStatsArea = 0 |
780 | spec.workAreaParameters.lastTotalArea = 0 |
781 | end |
onUpdate
DescriptionDefinitiononUpdate()Code
308 | function Plow:onUpdate(dt, isActiveForInput, isActiveForInputIgnoreSelection, isSelected) |
309 | if self.isClient then |
310 | local spec = self.spec_plow |
311 | |
312 | local actionEvent = spec.actionEvents[InputAction.IMPLEMENT_EXTRA3] |
313 | if actionEvent ~= nil then |
314 | if not self:getPlowForceLimitToField() and g_currentMission:getHasPlayerPermission("createFields", self:getOwner()) then |
315 | g_inputBinding:setActionEventActive(actionEvent.actionEventId, true) |
316 | |
317 | if self:getPlowLimitToField() then |
318 | g_inputBinding:setActionEventText(actionEvent.actionEventId, spec.texts.allowCreateFields) |
319 | else |
320 | g_inputBinding:setActionEventText(actionEvent.actionEventId, spec.texts.limitToFields) |
321 | end |
322 | else |
323 | g_inputBinding:setActionEventActive(actionEvent.actionEventId, false) |
324 | end |
325 | end |
326 | |
327 | if spec.rotationPart.turnAnimation ~= nil then |
328 | actionEvent = spec.actionEvents[InputAction.IMPLEMENT_EXTRA] |
329 | if actionEvent ~= nil then |
330 | g_inputBinding:setActionEventActive(actionEvent.actionEventId, self:getIsPlowRotationAllowed()) |
331 | end |
332 | end |
333 | end |
334 | end |
onWriteStream
DescriptionDefinitiononWriteStream()Code
296 | function Plow:onWriteStream(streamId, connection) |
297 | local spec = self.spec_plow |
298 | |
299 | streamWriteBool(streamId, spec.rotationMax) |
300 | if spec.rotationPart.turnAnimation ~= nil and self.playAnimation ~= nil then |
301 | local turnAnimTime = self:getAnimationTime(spec.rotationPart.turnAnimation) |
302 | streamWriteFloat32(streamId, turnAnimTime) |
303 | end |
304 | end |
prerequisitesPresent
DescriptionDefinitionprerequisitesPresent()Code
91 | function Plow.prerequisitesPresent(specializations) |
92 | return SpecializationUtil.hasSpecialization(WorkArea, specializations) |
93 | end |
processPlowArea
DescriptionDefinitionprocessPlowArea()Code
338 | function Plow:processPlowArea(workArea, dt) |
339 | local spec = self.spec_plow |
340 | |
341 | local xs,_,zs = getWorldTranslation(workArea.start) |
342 | local xw,_,zw = getWorldTranslation(workArea.width) |
343 | local xh,_,zh = getWorldTranslation(workArea.height) |
344 | |
345 | local params = spec.workAreaParameters |
346 | local changedArea, totalArea = 0, 0 |
347 | |
348 | if self.tailwaterDepth < 0.1 then |
349 | changedArea, totalArea = FSDensityMapUtil.updatePlowArea(xs,zs, xw,zw, xh,zh, not params.limitToField, params.limitFruitDestructionToField, params.angle) |
350 | changedArea = changedArea + FSDensityMapUtil.updateVineCultivatorArea(xs, zs, xw, zw, xh, zh) |
351 | end |
352 | |
353 | params.lastChangedArea = params.lastChangedArea + changedArea |
354 | params.lastStatsArea = params.lastStatsArea + changedArea |
355 | params.lastTotalArea = params.lastTotalArea + totalArea |
356 | |
357 | FSDensityMapUtil.eraseTireTrack(xs,zs, xw,zw, xh,zh) |
358 | |
359 | spec.isWorking = self:getLastSpeed() > 0.5 |
360 | |
361 | return changedArea, totalArea |
362 | end |
registerEventListeners
DescriptionDefinitionregisterEventListeners()Code
132 | function Plow.registerEventListeners(vehicleType) |
133 | SpecializationUtil.registerEventListener(vehicleType, "onLoad", Plow) |
134 | SpecializationUtil.registerEventListener(vehicleType, "onPostLoad", Plow) |
135 | SpecializationUtil.registerEventListener(vehicleType, "onDelete", Plow) |
136 | SpecializationUtil.registerEventListener(vehicleType, "onReadStream", Plow) |
137 | SpecializationUtil.registerEventListener(vehicleType, "onWriteStream", Plow) |
138 | SpecializationUtil.registerEventListener(vehicleType, "onUpdate", Plow) |
139 | SpecializationUtil.registerEventListener(vehicleType, "onRegisterActionEvents", Plow) |
140 | SpecializationUtil.registerEventListener(vehicleType, "onStartWorkAreaProcessing", Plow) |
141 | SpecializationUtil.registerEventListener(vehicleType, "onEndWorkAreaProcessing", Plow) |
142 | SpecializationUtil.registerEventListener(vehicleType, "onPostAttach", Plow) |
143 | SpecializationUtil.registerEventListener(vehicleType, "onPreDetach", Plow) |
144 | SpecializationUtil.registerEventListener(vehicleType, "onDeactivate", Plow) |
145 | SpecializationUtil.registerEventListener(vehicleType, "onAIImplementStartTurn", Plow) |
146 | SpecializationUtil.registerEventListener(vehicleType, "onAIImplementTurnProgress", Plow) |
147 | SpecializationUtil.registerEventListener(vehicleType, "onStartAnimation", Plow) |
148 | SpecializationUtil.registerEventListener(vehicleType, "onFinishAnimation", Plow) |
149 | SpecializationUtil.registerEventListener(vehicleType, "onRootVehicleChanged", Plow) |
150 | end |
registerFunctions
DescriptionDefinitionregisterFunctions()Code
97 | function Plow.registerFunctions(vehicleType) |
98 | SpecializationUtil.registerFunction(vehicleType, "processPlowArea", Plow.processPlowArea) |
99 | SpecializationUtil.registerFunction(vehicleType, "setRotationMax", Plow.setRotationMax) |
100 | SpecializationUtil.registerFunction(vehicleType, "setRotationCenter", Plow.setRotationCenter) |
101 | SpecializationUtil.registerFunction(vehicleType, "setPlowLimitToField", Plow.setPlowLimitToField) |
102 | SpecializationUtil.registerFunction(vehicleType, "getIsPlowRotationAllowed", Plow.getIsPlowRotationAllowed) |
103 | SpecializationUtil.registerFunction(vehicleType, "getPlowLimitToField", Plow.getPlowLimitToField) |
104 | SpecializationUtil.registerFunction(vehicleType, "getPlowForceLimitToField", Plow.getPlowForceLimitToField) |
105 | SpecializationUtil.registerFunction(vehicleType, "setPlowAIRequirements", Plow.setPlowAIRequirements) |
106 | end |
registerOverwrittenFunctions
DescriptionDefinitionregisterOverwrittenFunctions()Code
110 | function Plow.registerOverwrittenFunctions(vehicleType) |
111 | SpecializationUtil.registerOverwrittenFunction(vehicleType, "getIsFoldAllowed", Plow.getIsFoldAllowed) |
112 | SpecializationUtil.registerOverwrittenFunction(vehicleType, "getIsFoldMiddleAllowed", Plow.getIsFoldMiddleAllowed) |
113 | SpecializationUtil.registerOverwrittenFunction(vehicleType, "getDirtMultiplier", Plow.getDirtMultiplier) |
114 | SpecializationUtil.registerOverwrittenFunction(vehicleType, "getWearMultiplier", Plow.getWearMultiplier) |
115 | SpecializationUtil.registerOverwrittenFunction(vehicleType, "loadSpeedRotatingPartFromXML", Plow.loadSpeedRotatingPartFromXML) |
116 | SpecializationUtil.registerOverwrittenFunction(vehicleType, "getIsSpeedRotatingPartActive", Plow.getIsSpeedRotatingPartActive) |
117 | SpecializationUtil.registerOverwrittenFunction(vehicleType, "getSpeedRotatingPartDirection", Plow.getSpeedRotatingPartDirection) |
118 | SpecializationUtil.registerOverwrittenFunction(vehicleType, "doCheckSpeedLimit", Plow.doCheckSpeedLimit) |
119 | SpecializationUtil.registerOverwrittenFunction(vehicleType, "loadWorkAreaFromXML", Plow.loadWorkAreaFromXML) |
120 | SpecializationUtil.registerOverwrittenFunction(vehicleType, "getIsWorkAreaActive", Plow.getIsWorkAreaActive) |
121 | SpecializationUtil.registerOverwrittenFunction(vehicleType, "getCanAIImplementContinueWork", Plow.getCanAIImplementContinueWork) |
122 | SpecializationUtil.registerOverwrittenFunction(vehicleType, "getAIInvertMarkersOnTurn", Plow.getAIInvertMarkersOnTurn) |
123 | SpecializationUtil.registerOverwrittenFunction(vehicleType, "getCanBeSelected", Plow.getCanBeSelected) |
124 | SpecializationUtil.registerOverwrittenFunction(vehicleType, "isDetachAllowed", Plow.isDetachAllowed) |
125 | SpecializationUtil.registerOverwrittenFunction(vehicleType, "getAllowsLowering", Plow.getAllowsLowering) |
126 | SpecializationUtil.registerOverwrittenFunction(vehicleType, "getIsAIReadyToDrive", Plow.getIsAIReadyToDrive) |
127 | SpecializationUtil.registerOverwrittenFunction(vehicleType, "getIsAIPreparingToDrive", Plow.getIsAIPreparingToDrive) |
128 | end |
registerXMLPaths
DescriptionDefinitionregisterXMLPaths()Code
61 | function Plow.registerXMLPaths(schema, basePath) |
62 | schema:register(XMLValueType.STRING, basePath .. ".rotationPart#turnAnimationName", "Turn animation name") |
63 | schema:register(XMLValueType.FLOAT, basePath .. ".rotationPart#foldMinLimit", "Fold min. limit", 0) |
64 | schema:register(XMLValueType.FLOAT, basePath .. ".rotationPart#foldMaxLimit", "Fold max. limit", 1) |
65 | schema:register(XMLValueType.BOOL, basePath .. ".rotationPart#limitFoldRotationMax", "Block folding if in max state") |
66 | schema:register(XMLValueType.FLOAT, basePath .. ".rotationPart#foldRotationMinLimit", "Fold allow if inbetween this limit", 0) |
67 | schema:register(XMLValueType.FLOAT, basePath .. ".rotationPart#foldRotationMaxLimit", "Fold allow if inbetween this limit", 1) |
68 | schema:register(XMLValueType.FLOAT, basePath .. ".rotationPart#rotationFoldMinLimit", "Rotation allow if fold time inbetween this limit", 0) |
69 | schema:register(XMLValueType.FLOAT, basePath .. ".rotationPart#rotationFoldMaxLimit", "Rotation allow if fold time inbetween this limit", 1) |
70 | schema:register(XMLValueType.FLOAT, basePath .. ".rotationPart#detachMinLimit", "Detach is allowed if turn animation between these values", 0) |
71 | schema:register(XMLValueType.FLOAT, basePath .. ".rotationPart#detachMaxLimit", "Detach is allowed if turn animation between these values", 1) |
72 | schema:register(XMLValueType.BOOL, basePath .. ".rotationPart#rotationAllowedIfLowered", "Allow plow rotation if lowered", true) |
73 | |
74 | schema:register(XMLValueType.L10N_STRING, basePath .. ".rotationPart#detachWarning", "Warning to be displayed if not in correct turn state for detach", "warning_detachNotAllowedPlowTurn") |
75 | |
76 | schema:register(XMLValueType.NODE_INDEX, basePath .. ".directionNode#node", "Plow direction node") |
77 | |
78 | schema:register(XMLValueType.FLOAT, basePath .. ".ai#centerPosition", "Center position", 0.5) |
79 | schema:register(XMLValueType.FLOAT, basePath .. ".ai#rotateToCenterHeadlandPos", "Rotate to center headland position", 0.5) |
80 | schema:register(XMLValueType.FLOAT, basePath .. ".ai#rotateCompletelyHeadlandPos", "Rotate completely headland position", 0.5) |
81 | |
82 | schema:register(XMLValueType.BOOL, basePath .. ".rotateLeftToMax#value", "Rotate left to max", true) |
83 | schema:register(XMLValueType.BOOL, basePath .. ".onlyActiveWhenLowered#value", "Only active when lowered", true) |
84 | |
85 | SoundManager.registerSampleXMLPaths(schema, basePath .. ".sounds", "turn") |
86 | SoundManager.registerSampleXMLPaths(schema, basePath .. ".sounds", "work") |
87 | end |
saveToXMLFile
DescriptionDefinitionsaveToXMLFile()Code
267 | function Plow:saveToXMLFile(xmlFile, key, usedModNames) |
268 | local spec = self.spec_plow |
269 | xmlFile:setValue(key.."#rotationMax", spec.rotationMax) |
270 | if spec.rotationPart.turnAnimation ~= nil and self.playAnimation ~= nil then |
271 | local turnAnimTime = self:getAnimationTime(spec.rotationPart.turnAnimation) |
272 | xmlFile:setValue(key.."#turnAnimTime", turnAnimTime) |
273 | end |
274 | end |
setPlowAIRequirements
DescriptionSets plow ai requirements and optional exclude the given ground typeDefinition
setPlowAIRequirements(table excludedGroundTypes)Arguments
table | excludedGroundTypes | these ground types will be excluded |
473 | function Plow:setPlowAIRequirements(excludedGroundTypes) |
474 | if self.clearAITerrainDetailRequiredRange ~= nil then |
475 | self:clearAITerrainDetailRequiredRange() |
476 | |
477 | if excludedGroundTypes ~= nil then |
478 | self:addAIGroundTypeRequirements(Plow.AI_REQUIRED_GROUND_TYPES, unpack(excludedGroundTypes)) |
479 | else |
480 | self:addAIGroundTypeRequirements(Plow.AI_REQUIRED_GROUND_TYPES) |
481 | end |
482 | end |
483 | end |
setPlowLimitToField
DescriptionDefinitionsetPlowLimitToField()Code
411 | function Plow:setPlowLimitToField(plowLimitToField, noEventSend) |
412 | local spec = self.spec_plow |
413 | |
414 | if spec.limitToField ~= plowLimitToField then |
415 | if noEventSend == nil or noEventSend == false then |
416 | if g_server ~= nil then |
417 | g_server:broadcastEvent(PlowLimitToFieldEvent.new(self, plowLimitToField), nil, nil, self) |
418 | else |
419 | g_client:getServerConnection():sendEvent(PlowLimitToFieldEvent.new(self, plowLimitToField)) |
420 | end |
421 | end |
422 | spec.limitToField = plowLimitToField |
423 | |
424 | local actionEvent = spec.actionEvents[InputAction.IMPLEMENT_EXTRA3] |
425 | if actionEvent ~= nil then |
426 | local text |
427 | if spec.limitToField then |
428 | text = spec.texts.allowCreateFields |
429 | else |
430 | text = spec.texts.limitToFields |
431 | end |
432 | g_inputBinding:setActionEventText(actionEvent.actionEventId, text) |
433 | end |
434 | end |
435 | end |
setRotationCenter
DescriptionDefinitionsetRotationCenter()Code
394 | function Plow:setRotationCenter() |
395 | local spec = self.spec_plow |
396 | |
397 | if spec.rotationPart.turnAnimation ~= nil then |
398 | self:setAnimationStopTime(spec.rotationPart.turnAnimation, spec.ai.centerPosition) |
399 | |
400 | local animTime = self:getAnimationTime(spec.rotationPart.turnAnimation) |
401 | if animTime < spec.ai.centerPosition then |
402 | self:playAnimation(spec.rotationPart.turnAnimation, 1, animTime, true) |
403 | elseif animTime > spec.ai.centerPosition then |
404 | self:playAnimation(spec.rotationPart.turnAnimation, -1, animTime, true) |
405 | end |
406 | end |
407 | end |
setRotationMax
DescriptionDefinitionsetRotationMax()Code
366 | function Plow:setRotationMax(rotationMax, noEventSend, turnAnimationTime) |
367 | if noEventSend == nil or noEventSend == false then |
368 | if g_server ~= nil then |
369 | g_server:broadcastEvent(PlowRotationEvent.new(self, rotationMax), nil, nil, self) |
370 | else |
371 | g_client:getServerConnection():sendEvent(PlowRotationEvent.new(self, rotationMax)) |
372 | end |
373 | end |
374 | local spec = self.spec_plow |
375 | |
376 | spec.rotationMax = rotationMax |
377 | |
378 | if spec.rotationPart.turnAnimation ~= nil then |
379 | if turnAnimationTime == nil then |
380 | local animTime = self:getAnimationTime(spec.rotationPart.turnAnimation) |
381 | if spec.rotationMax then |
382 | self:playAnimation(spec.rotationPart.turnAnimation, 1, animTime, true) |
383 | else |
384 | self:playAnimation(spec.rotationPart.turnAnimation, -1, animTime, true) |
385 | end |
386 | else |
387 | self:setAnimationTime(spec.rotationPart.turnAnimation, turnAnimationTime, true) |
388 | end |
389 | end |
390 | end |