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
ExtendedSowingMachine
DescriptionSpecialization to track seed usageFunctions
- actionEventChangeSeedRate
- actionEventToggleAuto
- onEndWorkAreaProcessing
- onRegisterActionEvents
- onUpdate
- prerequisitesPresent
- processSowingMachineArea
- setManualSeedRate
- setSeedRateAutoMode
- updateActionEventState
actionEventChangeSeedRate
DescriptionDefinitionactionEventChangeSeedRate()Code
236 | function ExtendedSowingMachine.actionEventChangeSeedRate(self, actionName, inputValue, callbackState, isAnalog, ...) |
237 | self:setManualSeedRate(self.spec_extendedSowingMachine.manualSeedRate + MathUtil.sign(inputValue)) |
238 | end |
actionEventToggleAuto
DescriptionDefinitionactionEventToggleAuto()Code
230 | function ExtendedSowingMachine.actionEventToggleAuto(self, actionName, inputValue, callbackState, isAnalog) |
231 | self:setSeedRateAutoMode() |
232 | end |
onEndWorkAreaProcessing
DescriptionDefinitiononEndWorkAreaProcessing()Code
116 | function ExtendedSowingMachine:onEndWorkAreaProcessing(dt, hasProcessed) |
117 | local spec = self.spec_sowingMachine |
118 | if self.isServer then |
119 | if spec.workAreaParameters.lastChangedArea > 0 then |
120 | local fruitDesc = g_fruitTypeManager:getFruitTypeByIndex(spec.workAreaParameters.seedsFruitType) |
121 | local realHa = MathUtil.areaToHa(self.spec_extendedSowingMachine.lastRealChangedArea, g_currentMission:getFruitPixelsToSqm()) |
122 | local lastHa = MathUtil.areaToHa(spec.workAreaParameters.lastChangedArea, g_currentMission:getFruitPixelsToSqm()) |
123 | local usage = fruitDesc.seedUsagePerSqm * lastHa * 10000 |
124 | local usageRegular = fruitDesc.seedUsagePerSqm * realHa * 10000 |
125 | |
126 | local damage = self:getVehicleDamage() |
127 | if damage > 0 then |
128 | usage = usage * (1 + damage * SowingMachine.DAMAGED_USAGE_INCREASE) |
129 | usageRegular = usageRegular * (1 + damage * SowingMachine.DAMAGED_USAGE_INCREASE) |
130 | end |
131 | |
132 | local farmlandStatistics, _, farmlandId = self:getPFStatisticInfo() |
133 | if farmlandStatistics ~= nil then |
134 | if farmlandId ~= nil then |
135 | farmlandStatistics:updateStatistic(farmlandId, "usedSeeds", usage) |
136 | farmlandStatistics:updateStatistic(farmlandId, "usedSeedsRegular", usageRegular) |
137 | end |
138 | end |
139 | end |
140 | end |
141 | end |
onRegisterActionEvents
DescriptionDefinitiononRegisterActionEvents()Code
145 | function ExtendedSowingMachine:onRegisterActionEvents(isActiveForInput, isActiveForInputIgnoreSelection) |
146 | if self.isClient then |
147 | local spec = self.spec_extendedSowingMachine |
148 | self:clearActionEventsTable(spec.actionEvents) |
149 | |
150 | if isActiveForInputIgnoreSelection then |
151 | local _, actionEventId = self:addActionEvent(spec.actionEvents, spec.inputActionToggleAuto, self, ExtendedSowingMachine.actionEventToggleAuto, false, true, false, true, nil) |
152 | g_inputBinding:setActionEventTextPriority(actionEventId, GS_PRIO_HIGH) |
153 | |
154 | _, actionEventId = self:addActionEvent(spec.actionEvents, spec.inputActionToggleRate, self, ExtendedSowingMachine.actionEventChangeSeedRate, false, true, false, true, nil) |
155 | g_inputBinding:setActionEventTextPriority(actionEventId, GS_PRIO_HIGH) |
156 | g_inputBinding:setActionEventText(actionEventId, spec.texts.inputChangeSeedRate) |
157 | |
158 | ExtendedSowingMachine.updateActionEventState(self) |
159 | end |
160 | |
161 | spec.attachStateChanged = true |
162 | end |
163 | end |
onUpdate
DescriptionDefinitiononUpdate()Code
78 | function ExtendedSowingMachine:onUpdate(dt, isActiveForInput, isActiveForInputIgnoreSelection, isSelected) |
79 | local spec = self.spec_extendedSowingMachine |
80 | spec.lastGroundUpdateDistance = spec.lastGroundUpdateDistance + self.lastMovedDistance |
81 | if spec.lastGroundUpdateDistance > spec.groundUpdateDistance then |
82 | spec.lastGroundUpdateDistance = 0 |
83 | |
84 | local workArea = self:getWorkAreaByIndex(1) |
85 | if workArea ~= nil then |
86 | local x, z |
87 | |
88 | -- if the work area starts in the middle of the vehicle we use the start node, otherwise the middle between start and width |
89 | local lx, _, _ = localToLocal(workArea.start, self.rootNode, 0, 0, 0) |
90 | if math.abs(lx) < 0.5 then |
91 | x, _, z = getWorldTranslation(workArea.start) |
92 | else |
93 | local x1, _, z1 = getWorldTranslation(workArea.start) |
94 | local x2, _, z2 = getWorldTranslation(workArea.width) |
95 | x, z = (x1 + x2) * 0.5, (z1 + z2) * 0.5 |
96 | end |
97 | |
98 | local isOnField, _ = FSDensityMapUtil.getFieldDataAtWorldPosition(x, 0, z) |
99 | if isOnField then |
100 | local soilTypeIndex = spec.soilMap:getTypeIndexAtWorldPos(x, z) |
101 | if soilTypeIndex > 0 then |
102 | local fruitTypeIndex = self.spec_sowingMachine.seeds[self.spec_sowingMachine.currentSeed] |
103 | spec.seedRateRecommendation = spec.seedRateMap:getOptimalSeedRateByFruitTypeAndSoiltype(fruitTypeIndex, soilTypeIndex) |
104 | else |
105 | spec.seedRateRecommendation = nil |
106 | end |
107 | else |
108 | spec.seedRateRecommendation = nil |
109 | end |
110 | end |
111 | end |
112 | 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 |
27 | function ExtendedSowingMachine.prerequisitesPresent(specializations) |
28 | return SpecializationUtil.hasSpecialization(SowingMachine, specializations) and SpecializationUtil.hasSpecialization(PrecisionFarmingStatistic, specializations) |
29 | end |
processSowingMachineArea
DescriptionDefinitionprocessSowingMachineArea()Code
198 | function ExtendedSowingMachine:processSowingMachineArea(superFunc, workArea, dt) |
199 | local changedArea, totalArea = superFunc(self, workArea, dt) |
200 | if changedArea > 0 then |
201 | local spec = self.spec_extendedSowingMachine |
202 | local specSowingMachine = self.spec_sowingMachine |
203 | local workAreaParameters = specSowingMachine.workAreaParameters |
204 | |
205 | local sx, _, sz = getWorldTranslation(workArea.start) |
206 | local wx, _, wz = getWorldTranslation(workArea.width) |
207 | local hx, _, hz = getWorldTranslation(workArea.height) |
208 | |
209 | local fruitType = workAreaParameters.seedsFruitType |
210 | |
211 | local realUsage, realSeedRate, realSeedRateIndex = spec.seedRateMap:updateSeedArea(sx, sz, wx, wz, hx, hz, fruitType, spec.seedRateAutoMode, spec.manualSeedRate) |
212 | |
213 | if realSeedRateIndex ~= nil then |
214 | local fruitDesc = g_fruitTypeManager:getFruitTypeByIndex(fruitType) |
215 | local usageOffset = realUsage / fruitDesc.seedUsagePerSqm |
216 | |
217 | spec.lastRealChangedArea = workAreaParameters.lastChangedArea |
218 | workAreaParameters.lastChangedArea = workAreaParameters.lastChangedArea * usageOffset |
219 | |
220 | spec.lastSeedRate = realSeedRate |
221 | spec.lastSeedRateIndex = realSeedRateIndex |
222 | end |
223 | end |
224 | |
225 | return changedArea, totalArea |
226 | end |
setManualSeedRate
DescriptionDefinitionsetManualSeedRate()Code
186 | function ExtendedSowingMachine:setManualSeedRate(seedRate, noEventSend) |
187 | local spec = self.spec_extendedSowingMachine |
188 | seedRate = MathUtil.clamp(seedRate, ExtendedSowingMachine.MIN_SEED_RATE, ExtendedSowingMachine.MAX_SEED_RATE) |
189 | if seedRate ~= spec.manualSeedRate then |
190 | spec.manualSeedRate = seedRate |
191 | |
192 | ExtendedSowingMachineRateEvent.sendEvent(self, spec.seedRateAutoMode, spec.manualSeedRate, noEventSend) |
193 | end |
194 | end |
setSeedRateAutoMode
DescriptionDefinitionsetSeedRateAutoMode()Code
167 | function ExtendedSowingMachine:setSeedRateAutoMode(state, noEventSend) |
168 | local spec = self.spec_extendedSowingMachine |
169 | if state == nil then |
170 | state = not spec.seedRateAutoMode |
171 | end |
172 | |
173 | if state ~= spec.seedRateAutoMode then |
174 | spec.seedRateAutoMode = state |
175 | |
176 | if self.isClient then |
177 | ExtendedSowingMachine.updateActionEventState(self) |
178 | end |
179 | |
180 | ExtendedSowingMachineRateEvent.sendEvent(self, spec.seedRateAutoMode, spec.manualSeedRate, noEventSend) |
181 | end |
182 | end |
updateActionEventState
DescriptionDefinitionupdateActionEventState()Code
242 | function ExtendedSowingMachine.updateActionEventState(self) |
243 | local spec = self.spec_extendedSowingMachine |
244 | local actionEventToggleAuto = spec.actionEvents[spec.inputActionToggleAuto] |
245 | if actionEventToggleAuto ~= nil then |
246 | g_inputBinding:setActionEventText(actionEventToggleAuto.actionEventId, spec.seedRateAutoMode and spec.texts.inputToggleAutoModeNeg or spec.texts.inputToggleAutoModePos) |
247 | end |
248 | |
249 | local actionEventToggleRate = spec.actionEvents[spec.inputActionToggleRate] |
250 | if actionEventToggleRate ~= nil then |
251 | g_inputBinding:setActionEventActive(actionEventToggleRate.actionEventId, not spec.seedRateAutoMode) |
252 | end |
253 | end |