Script v1.7.1.0
- AI
- Animals
- Contracts
- Debug
- Economy
- Effects
- Events
- Farms
- GUI
- Handtools
- I3d
- Materials
- Misc
- Objects
- Placeables
- Player
- Shop
- Sounds
- Specializations
- AIConveyorBelt
- AIImplement
- AIVehicle
- AnimatedVehicle
- ArticulatedAxis
- Attachable
- AttacherJointControl
- AttacherJoints
- BaleGrab
- BaleLoader
- Baler
- BaleWrapper
- BaseMaterial
- BunkerSiloCompacter
- BunkerSiloInteractor
- BuyableBale
- CCTDrivable
- Combine
- ConnectionHoses
- ConveyorBelt
- Cover
- CrabSteering
- Crawlers
- Cultivator
- Cutter
- Cylindered
- CylinderedFoldable
- Dashboard
- Dischargeable
- Drivable
- DynamicallyLoadedParts
- DynamicMountAttacher
- Enterable
- FertilizingCultivator
- FertilizingSowingMachine
- FillTriggerVehicle
- FillUnit
- FillVolume
- Foldable
- FoliageBending
- ForageWagon
- FrontloaderAttacher
- FruitPreparer
- GroundAdjustedNodes
- GroundReference
- Honk
- HookLiftContainer
- HookLiftTrailer
- IKChains
- JigglingParts
- Leveler
- Lights
- LivestockTrailer
- Locomotive
- LogGrab
- ManureBarrel
- MixerWagon
- Motorized
- Mountable
- Mower
- Pickup
- Pipe
- Plow
- PowerConsumer
- PowerTakeOffs
- RandomlyMovingParts
- ReceivingHopper
- ReverseDriving
- Rideable
- RidgeMarker
- Roller
- Ropes
- SemiTrailerFront
- Shovel
- SlopeCompensation
- SmartAttach
- SowingMachine
- SpeedRotatingParts
- SplineVehicle
- Sprayer
- StrawBlower
- StumpCutter
- Suspensions
- Tedder
- TensionBeltObject
- TensionBelts
- TipOccluder
- Trailer
- TreePlanter
- TreeSaw
- TurnOnVehicle
- Washable
- WaterTrailer
- Wearable
- Weeder
- Wheels
- Windrower
- Wipers
- WoodCrusher
- WoodHarvester
- WorkArea
- WorkMode
- WorkParticles
- Triggers
- Utils
- Vehicles
- Weather
Engine v1.7.1.0
- AI
- Animation
- Camera
- Entity
- Fillplanes
- General
- I3D
- Input
- Lighting
- Math
- Network
- Node
- Overlays
- Particle System
- Physics
- Rendering
- Scenegraph
- Shape
- Sound
- Spline
- String
- Terrain Detail
- Text Rendering
- Tire Track
- XML
- general
Foundation Reference
FertilizingSowingMachine
DescriptionSpecialization for sowing machines which also have a fertilizing functionFunctions
- getAreEffectsVisible
- getUseSprayerAIRequirements
- onLoad
- prerequisitesPresent
- processSowingMachineArea
- registerEventListeners
- registerOverwrittenFunctions
getAreEffectsVisible
DescriptionDefinitiongetAreEffectsVisible()Code
146 | function FertilizingSowingMachine:getAreEffectsVisible(superFunc) |
147 | return superFunc(self) and self:getFillUnitFillType(self:getSprayerFillUnitIndex()) ~= FillType.UNKNOWN |
148 | end |
getUseSprayerAIRequirements
DescriptionDefinitiongetUseSprayerAIRequirements()Code
140 | function FertilizingSowingMachine:getUseSprayerAIRequirements(superFunc) |
141 | return false |
142 | end |
onLoad
DescriptionDefinitiononLoad()Code
37 | function FertilizingSowingMachine:onLoad(savegame) |
38 | local spec = self.spec_fertilizingSowingMachine |
39 | spec.needsSetIsTurnedOn = Utils.getNoNil(getXMLBool(self.xmlFile, "vehicle.fertilizingSowingMachine#needsSetIsTurnedOn"), false) |
40 | |
41 | self.spec_sprayer.needsToBeFilledToTurnOn = false |
42 | self.spec_sprayer.useSpeedLimit = false |
43 | 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 FertilizingSowingMachine.prerequisitesPresent(specializations) |
18 | return SpecializationUtil.hasSpecialization(SowingMachine, specializations) and SpecializationUtil.hasSpecialization(Sprayer, specializations) |
19 | end |
processSowingMachineArea
DescriptionDefinitionprocessSowingMachineArea()Code
47 | function FertilizingSowingMachine:processSowingMachineArea(superFunc, workArea, dt) |
48 | local spec = self.spec_fertilizingSowingMachine |
49 | local specSowingMachine = self.spec_sowingMachine |
50 | local specSpray = self.spec_sprayer |
51 | |
52 | local sprayerParams = specSpray.workAreaParameters |
53 | local sowingParams = specSowingMachine.workAreaParameters |
54 | local changedArea, totalArea |
55 | |
56 | self.spec_sowingMachine.isWorking = self:getLastSpeed() > 0.5 |
57 | |
58 | if not sowingParams.isActive then |
59 | return 0, 0 |
60 | end |
61 | |
62 | if not self:getIsAIActive() or not g_currentMission.missionInfo.helperBuySeeds then |
63 | if sowingParams.seedsVehicle == nil then |
64 | if self:getIsAIActive() then |
65 | local rootVehicle = self:getRootVehicle() |
66 | rootVehicle:stopAIVehicle(AIVehicle.STOP_REASON_OUT_OF_FILL) |
67 | end |
68 | |
69 | return 0, 0 |
70 | end |
71 | end |
72 | |
73 | -- stop the sowing machine if the fertilizer tank was filled and got empty |
74 | -- do not stop if the tank was all the time empty |
75 | if not g_currentMission.missionInfo.helperBuyFertilizer then |
76 | if self:getIsAIActive() then |
77 | if sprayerParams.sprayFillType == nil or sprayerParams.sprayFillType == FillType.UNKNOWN then |
78 | if sprayerParams.lastAIHasSprayed ~= nil then |
79 | local rootVehicle = self:getRootVehicle() |
80 | rootVehicle:stopAIVehicle(AIVehicle.STOP_REASON_OUT_OF_FILL) |
81 | sprayerParams.lastAIHasSprayed = nil |
82 | end |
83 | else |
84 | sprayerParams.lastAIHasSprayed = true |
85 | end |
86 | end |
87 | end |
88 | |
89 | if not sowingParams.canFruitBePlanted then |
90 | return 0, 0 |
91 | end |
92 | |
93 | -- we need to use fertilizer as spraying type because fertilizer is the final blocking value |
94 | local sprayTypeIndex = SprayType.FERTILIZER |
95 | if sprayerParams.sprayFillLevel <= 0 or (spec.needsSetIsTurnedOn and not self:getIsTurnedOn()) then |
96 | sprayTypeIndex = nil |
97 | end |
98 | |
99 | local startX,_,startZ = getWorldTranslation(workArea.start) |
100 | local widthX,_,widthZ = getWorldTranslation(workArea.width) |
101 | local heightX,_,heightZ = getWorldTranslation(workArea.height) |
102 | |
103 | if not specSowingMachine.useDirectPlanting then |
104 | changedArea, totalArea = FSDensityMapUtil.updateSowingArea(sowingParams.seedsFruitType, startX, startZ, widthX, widthZ, heightX, heightZ, sowingParams.angle, nil, sprayTypeIndex) |
105 | else |
106 | changedArea, totalArea = FSDensityMapUtil.updateDirectSowingArea(sowingParams.seedsFruitType, startX, startZ, widthX, widthZ, heightX, heightZ, sowingParams.angle, nil, sprayTypeIndex) |
107 | end |
108 | |
109 | self.spec_sowingMachine.isProcessing = self.spec_sowingMachine.isWorking |
110 | |
111 | if sprayTypeIndex ~= nil then |
112 | local sprayChangedArea, sprayTotalArea = FSDensityMapUtil.updateSprayArea(startX, startZ, widthX, widthZ, heightX, heightZ, sprayTypeIndex) |
113 | |
114 | sprayerParams.lastChangedArea = sprayerParams.lastChangedArea + sprayChangedArea |
115 | sprayerParams.lastTotalArea = sprayerParams.lastTotalArea + sprayTotalArea |
116 | sprayerParams.lastStatsArea = 0 |
117 | sprayerParams.isActive = true |
118 | |
119 | local stats = g_currentMission:farmStats(self:getLastTouchedFarmlandFarmId()) |
120 | local ha = MathUtil.areaToHa(sprayerParams.lastChangedArea, g_currentMission:getFruitPixelsToSqm()) |
121 | stats:updateStats("fertilizedHectares", ha) |
122 | stats:updateStats("fertilizedTime", dt/(1000*60)) |
123 | stats:updateStats("sprayUsage", sprayerParams.usage) |
124 | end |
125 | |
126 | sowingParams.lastChangedArea = sowingParams.lastChangedArea + changedArea |
127 | sowingParams.lastStatsArea = sowingParams.lastStatsArea + changedArea |
128 | sowingParams.lastTotalArea = sowingParams.lastTotalArea + totalArea |
129 | |
130 | -- remove tireTracks |
131 | FSDensityMapUtil.eraseTireTrack(startX, startZ, widthX, widthZ, heightX, heightZ) |
132 | |
133 | self:updateMissionSowingWarning(startX, startZ) |
134 | |
135 | return changedArea, totalArea |
136 | end |
registerEventListeners
DescriptionDefinitionregisterEventListeners()Code
31 | function FertilizingSowingMachine.registerEventListeners(vehicleType) |
32 | SpecializationUtil.registerEventListener(vehicleType, "onLoad", FertilizingSowingMachine) |
33 | end |
registerOverwrittenFunctions
DescriptionDefinitionregisterOverwrittenFunctions()Code
23 | function FertilizingSowingMachine.registerOverwrittenFunctions(vehicleType) |
24 | SpecializationUtil.registerOverwrittenFunction(vehicleType, "processSowingMachineArea", FertilizingSowingMachine.processSowingMachineArea) |
25 | SpecializationUtil.registerOverwrittenFunction(vehicleType, "getUseSprayerAIRequirements", FertilizingSowingMachine.getUseSprayerAIRequirements) |
26 | SpecializationUtil.registerOverwrittenFunction(vehicleType, "getAreEffectsVisible", FertilizingSowingMachine.getAreEffectsVisible) |
27 | end |