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
HeadlandAnimation
DescriptionSpecialization for playing animations when vehicle is on headlandFunctions
- initSpecialization
- onLoad
- onUpdate
- prerequisitesPresent
- registerEventListeners
- registerFunctions
- registerOverwrittenFunctions
initSpecialization
DescriptionDefinitioninitSpecialization()Code
23 | function HeadlandAnimation.initSpecialization() |
24 | local schema = Vehicle.xmlSchema |
25 | schema:setXMLSpecializationType("HeadlandAnimation") |
26 | |
27 | schema:register(XMLValueType.TIME, "vehicle.headlandAnimation#activationDelay", "Headland is activated after this time above activationAngle", 0.5) |
28 | schema:register(XMLValueType.TIME, "vehicle.headlandAnimation#deactivationDelay", "Headland is deactivated after this time below deactivationAngle", 4) |
29 | schema:register(XMLValueType.FLOAT, "vehicle.headlandAnimation#activationAngle", "Headland is activated above this steering percentage [0-1]", 0.2) |
30 | schema:register(XMLValueType.FLOAT, "vehicle.headlandAnimation#deactivationAngle", "Headland is deactivated below this steering percentage [0-1]", 0.13) |
31 | schema:register(XMLValueType.STRING, "vehicle.headlandAnimation#requiredGroundTypes", "Headland is only activated one of these ground types is below vehicle") |
32 | |
33 | schema:register(XMLValueType.STRING, "vehicle.headlandAnimation.animation(?)#name", "Animation name") |
34 | schema:register(XMLValueType.FLOAT, "vehicle.headlandAnimation.animation(?)#speed", "Animation speed") |
35 | |
36 | schema:setXMLSpecializationType() |
37 | end |
onLoad
DescriptionCalled on loadingDefinition
onLoad(table savegame)Arguments
table | savegame | savegame |
59 | function HeadlandAnimation:onLoad(savegame) |
60 | local spec = self.spec_headlandAnimation |
61 | |
62 | spec.isAvailable = self.xmlFile:hasProperty("vehicle.headlandAnimation") |
63 | if spec.isAvailable then |
64 | spec.headlandActivationDelay = self.xmlFile:getValue("vehicle.headlandAnimation#activationDelay", 0.5) |
65 | spec.headlandDeactivationDelay = self.xmlFile:getValue("vehicle.headlandAnimation#deactivationDelay", 4) |
66 | spec.headlandActivationAngle = self.xmlFile:getValue("vehicle.headlandAnimation#activationAngle", 0.2) |
67 | spec.headlandDeactivationAngle = self.xmlFile:getValue("vehicle.headlandAnimation#deactivationAngle", 0.13) |
68 | |
69 | local requiredGroundTypesStr = self.xmlFile:getValue("vehicle.headlandAnimation#requiredGroundTypes") |
70 | requiredGroundTypesStr = requiredGroundTypesStr:split(" ") |
71 | spec.requiredGroundTypes = {} |
72 | for i=1, #requiredGroundTypesStr do |
73 | local name = requiredGroundTypesStr[i] |
74 | if name ~= nil and name ~= "" then |
75 | local groundType = FieldGroundType[name] |
76 | if groundType ~= nil then |
77 | spec.requiredGroundTypes[groundType] = true |
78 | else |
79 | Logging.xmlWarning(self.xmlFile, "Unknown ground type '%s' defined for headland animation", name) |
80 | end |
81 | end |
82 | end |
83 | |
84 | spec.headlandDeactivationTime = 0 |
85 | spec.headlandState = false |
86 | spec.lastHeadlandState = false |
87 | |
88 | spec.animations = {} |
89 | |
90 | local i = 0 |
91 | while true do |
92 | local baseKey = string.format("vehicle.headlandAnimation.animation(%d)", i) |
93 | if not self.xmlFile:hasProperty(baseKey) then |
94 | break |
95 | end |
96 | |
97 | local animation = {} |
98 | animation.name = self.xmlFile:getValue(baseKey .. "#name") |
99 | animation.speed = self.xmlFile:getValue(baseKey .. "#speed") |
100 | if animation.name ~= nil then |
101 | table.insert(spec.animations, animation) |
102 | end |
103 | |
104 | i = i + 1 |
105 | end |
106 | else |
107 | SpecializationUtil.removeEventListener(self, "onUpdate", HeadlandAnimation) |
108 | end |
109 | end |
onUpdate
DescriptionCalled on updateDefinition
onUpdate(float dt, boolean isActive, boolean isActiveForInput, boolean isSelected)Arguments
float | dt | time since last call in ms |
boolean | isActive | true if vehicle is active |
boolean | isActiveForInput | true if vehicle is active for input |
boolean | isSelected | true if vehicle is selected |
117 | function HeadlandAnimation:onUpdate(dt, isActiveForInput, isActiveForInputIgnoreSelection, isSelected) |
118 | local spec = self.spec_headlandAnimation |
119 | |
120 | local validGround = true |
121 | if spec.headlandRequiredDensityBits ~= 0 then |
122 | local x, y, z = getWorldTranslation(self.components[1].node) |
123 | local _, _, groundType = FSDensityMapUtil.getFieldDataAtWorldPosition(x, y, z) |
124 | |
125 | if spec.requiredGroundTypes[groundType] ~= true then |
126 | validGround = false |
127 | end |
128 | end |
129 | |
130 | if validGround and math.abs(self.rotatedTime) > spec.headlandActivationAngle then |
131 | spec.headlandDeactivationTime = spec.headlandDeactivationTime + dt |
132 | if spec.headlandDeactivationTime > spec.headlandActivationDelay then |
133 | spec.headlandState = true |
134 | spec.headlandDeactivationTime = spec.headlandDeactivationDelay |
135 | end |
136 | elseif math.abs(self.rotatedTime) < spec.headlandDeactivationAngle then |
137 | spec.headlandDeactivationTime = math.max(spec.headlandDeactivationTime - dt, 0) |
138 | end |
139 | |
140 | if spec.headlandDeactivationTime == 0 then |
141 | spec.headlandState = false |
142 | end |
143 | |
144 | if spec.headlandState ~= spec.lastHeadlandState then |
145 | local direction = spec.headlandState and 1 or -1 |
146 | |
147 | for i=1, #spec.animations do |
148 | local animation = spec.animations[i] |
149 | self:playAnimation(animation.name, animation.speed * direction, self:getAnimationTime(animation.name)) |
150 | end |
151 | |
152 | spec.lastHeadlandState = spec.headlandState |
153 | end |
154 | end |
prerequisitesPresent
DescriptionChecks if all prerequisite specializations are loadedDefinition
prerequisitesPresent(table specializations)Arguments
table | specializations | specializations |
boolean | hasPrerequisite | true if all prerequisite specializations are loaded |
17 | function HeadlandAnimation.prerequisitesPresent(specializations) |
18 | return true |
19 | end |
registerEventListeners
DescriptionDefinitionregisterEventListeners()Code
51 | function HeadlandAnimation.registerEventListeners(vehicleType) |
52 | SpecializationUtil.registerEventListener(vehicleType, "onLoad", HeadlandAnimation) |
53 | SpecializationUtil.registerEventListener(vehicleType, "onUpdate", HeadlandAnimation) |
54 | end |
registerFunctions
DescriptionDefinitionregisterFunctions()Code
41 | function HeadlandAnimation.registerFunctions(vehicleType) |
42 | end |
registerOverwrittenFunctions
DescriptionDefinitionregisterOverwrittenFunctions()Code
46 | function HeadlandAnimation.registerOverwrittenFunctions(vehicleType) |
47 | end |