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
Weeder
DescriptionSpecialization for weeder tool used to remove growing weeds on fieldsFunctions
- doCheckSpeedLimit
- getDefaultSpeedLimit
- getDirtMultiplier
- getIsWorkAreaActive
- getWearMultiplier
- initSpecialization
- loadGroundParticleMapping
- loadWorkAreaFromXML
- onDeactivate
- onDelete
- onEndWorkAreaProcessing
- onLoad
- onPostAttach
- onStartWorkAreaProcessing
- onUpdateTick
- prerequisitesPresent
- processWeederArea
- registerEventListeners
- registerFunctions
- registerOverwrittenFunctions
doCheckSpeedLimit
DescriptionReturns if speed limit should be checkedDefinition
doCheckSpeedLimit()Return Values
boolean | checkSpeedlimit | check speed limit |
199 | function Weeder:doCheckSpeedLimit(superFunc) |
200 | return superFunc(self) or self:getIsImplementChainLowered() |
201 | end |
getDefaultSpeedLimit
DescriptionReturns default speed limitDefinition
getDefaultSpeedLimit()Return Values
float | speedLimit | speed limit |
319 | function Weeder.getDefaultSpeedLimit() |
320 | return 15 |
321 | end |
getDirtMultiplier
DescriptionReturns current dirt multiplierDefinition
getDirtMultiplier()Return Values
float | dirtMultiplier | current dirt multiplier |
206 | function Weeder:getDirtMultiplier(superFunc) |
207 | local spec = self.spec_weeder |
208 | local multiplier = superFunc(self) |
209 | |
210 | if spec.isWorking then |
211 | multiplier = multiplier + self:getWorkDirtMultiplier() * self:getLastSpeed() / self.speedLimit |
212 | end |
213 | |
214 | return multiplier |
215 | end |
getIsWorkAreaActive
DescriptionReturns true if work area is activeDefinition
getIsWorkAreaActive(table workArea)Arguments
table | workArea | workArea |
boolean | isActive | work area is active |
181 | function Weeder:getIsWorkAreaActive(superFunc, workArea) |
182 | if workArea.type == WorkAreaType.WEEDER then |
183 | local isActive = true |
184 | if workArea.requiresGroundContact and workArea.groundReferenceNode ~= nil then |
185 | isActive = isActive and self:getIsGroundReferenceNodeActive(workArea.groundReferenceNode) |
186 | end |
187 | if isActive and workArea.disableBackwards then |
188 | isActive = isActive and self.movingDirection > 0 |
189 | end |
190 | return isActive |
191 | end |
192 | |
193 | return superFunc(self, workArea) |
194 | end |
getWearMultiplier
DescriptionReturns current wear multiplierDefinition
getWearMultiplier()Return Values
float | dirtMultiplier | current wear multiplier |
220 | function Weeder:getWearMultiplier(superFunc) |
221 | local spec = self.spec_weeder |
222 | local multiplier = superFunc(self) |
223 | |
224 | if spec.isWorking then |
225 | multiplier = multiplier + self:getWorkWearMultiplier() * self:getLastSpeed() / self.speedLimit |
226 | end |
227 | |
228 | return multiplier |
229 | end |
initSpecialization
DescriptionCalled on specialization initializingDefinition
initSpecialization()Code
15 | function Weeder.initSpecialization() |
16 | g_workAreaTypeManager:addWorkAreaType("weeder", true) |
17 | end |
loadGroundParticleMapping
DescriptionLoad ground particle mapping from xml fileDefinition
loadGroundParticleMapping(integer xmlFile, string key, table mapping, integer index, integer i3dNode)Arguments
integer | xmlFile | id of xml object |
string | key | key |
table | mapping | mapping |
integer | index | index |
integer | i3dNode | id of i3d node |
boolean | success | success |
239 | function Weeder:loadGroundParticleMapping(superFunc, xmlFile, key, mapping, index, i3dNode) |
240 | if not superFunc(self, xmlFile, key, mapping, index, i3dNode) then |
241 | return false |
242 | end |
243 | |
244 | mapping.adjustColor = Utils.getNoNil(getXMLBool(xmlFile, key.."#adjustColor"), false) |
245 | if mapping.adjustColor then |
246 | local spec = self.spec_weeder |
247 | if spec.colorParticleSystems == nil then |
248 | spec.colorParticleSystems = {} |
249 | end |
250 | mapping.lastColor = {} |
251 | |
252 | table.insert(spec.colorParticleSystems, mapping) |
253 | end |
254 | |
255 | return true |
256 | end |
loadWorkAreaFromXML
DescriptionLoads work areas from xmlDefinition
loadWorkAreaFromXML(table workArea, integer xmlFile, string key)Arguments
table | workArea | workArea |
integer | xmlFile | id of xml object |
string | key | key |
boolean | success | success |
169 | function Weeder:loadWorkAreaFromXML(superFunc, workArea, xmlFile, key) |
170 | if workArea.type == WorkAreaType.DEFAULT then |
171 | workArea.type = WorkAreaType.WEEDER |
172 | end |
173 | |
174 | return superFunc(self, workArea, xmlFile, key) |
175 | end |
onDeactivate
DescriptionDefinitiononDeactivate()Code
298 | function Weeder:onDeactivate() |
299 | if self.isClient then |
300 | local spec = self.spec_weeder |
301 | g_soundManager:stopSamples(spec.samples) |
302 | spec.isWorkSamplePlaying = false |
303 | end |
304 | end |
onDelete
DescriptionCalled on deletingDefinition
onDelete()Code
94 | function Weeder:onDelete() |
95 | if self.isClient then |
96 | local spec = self.spec_weeder |
97 | g_soundManager:deleteSamples(spec.samples) |
98 | end |
99 | end |
onEndWorkAreaProcessing
DescriptionDefinitiononEndWorkAreaProcessing()Code
269 | function Weeder:onEndWorkAreaProcessing(dt, hasProcessed) |
270 | local spec = self.spec_weeder |
271 | |
272 | if self.isServer then |
273 | if spec.workAreaParameters.lastStatsArea > 0 then |
274 | local ha = MathUtil.areaToHa(spec.workAreaParameters.lastStatsArea, g_currentMission:getFruitPixelsToSqm()) |
275 | local stats = g_currentMission:farmStats(self:getLastTouchedFarmlandFarmId()) |
276 | stats:updateStats("workedHectares", ha) |
277 | stats:updateStats("workedTime", dt/(1000*60)) |
278 | end |
279 | end |
280 | |
281 | if self.isClient then |
282 | if spec.isWorking then |
283 | if not spec.isWorkSamplePlaying then |
284 | g_soundManager:playSample(spec.samples.work) |
285 | spec.isWorkSamplePlaying = true |
286 | end |
287 | else |
288 | if spec.isWorkSamplePlaying then |
289 | g_soundManager:stopSample(spec.samples.work) |
290 | spec.isWorkSamplePlaying = false |
291 | end |
292 | end |
293 | end |
294 | end |
onLoad
DescriptionCalled on loadingDefinition
onLoad(table savegame)Arguments
table | savegame | savegame |
60 | function Weeder:onLoad(savegame) |
61 | local spec = self.spec_weeder |
62 | |
63 | if self.isClient then |
64 | spec.samples = {} |
65 | spec.samples.work = g_soundManager:loadSampleFromXML(self.xmlFile, "vehicle.weeder.sounds", "work", self.baseDirectory, self.components, 0, AudioGroup.VEHICLE, self.i3dMappings, self) |
66 | spec.isWorkSamplePlaying = false |
67 | end |
68 | |
69 | spec.startActivationTimeout = 2000 |
70 | spec.startActivationTime = 0 |
71 | |
72 | spec.maxGrowthState = Utils.getNoNil(getXMLInt(self.xmlFile, "vehicle.weeder.maxGrowthState"), 2) |
73 | |
74 | spec.workAreaParameters = {} |
75 | spec.workAreaParameters.lastArea = 0 |
76 | spec.workAreaParameters.lastStatsArea = 0 |
77 | |
78 | spec.isWorking = false |
79 | |
80 | -- ai setup |
81 | if self.addAITerrainDetailRequiredRange ~= nil then |
82 | self:addAITerrainDetailRequiredRange(g_currentMission.sowingValue, g_currentMission.sowingValue, g_currentMission.terrainDetailTypeFirstChannel, g_currentMission.terrainDetailTypeNumChannels) |
83 | self:addAITerrainDetailRequiredRange(g_currentMission.sowingWidthValue, g_currentMission.sowingWidthValue, g_currentMission.terrainDetailTypeFirstChannel, g_currentMission.terrainDetailTypeNumChannels) |
84 | end |
85 | |
86 | local fruitType = g_fruitTypeManager:getFruitTypeByName("weed") |
87 | if fruitType ~= nil then |
88 | self:setAIFruitRequirements(fruitType.index, 1, 1) |
89 | end |
90 | 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 |
311 | function Weeder:onPostAttach(attacherVehicle, inputJointDescIndex, jointDescIndex) |
312 | local spec = self.spec_weeder |
313 | spec.startActivationTime = g_currentMission.time + spec.startActivationTimeout |
314 | end |
onStartWorkAreaProcessing
DescriptionDefinitiononStartWorkAreaProcessing()Code
260 | function Weeder:onStartWorkAreaProcessing(dt) |
261 | local spec = self.spec_weeder |
262 | spec.isWorking = false |
263 | spec.workAreaParameters.lastArea = 0 |
264 | spec.workAreaParameters.lastStatsArea = 0 |
265 | end |
onUpdateTick
DescriptionDefinitiononUpdateTick()Code
103 | function Weeder:onUpdateTick(dt, isActiveForInput, isActiveForInputIgnoreSelection, isSelected) |
104 | local spec = self.spec_weeder |
105 | |
106 | if spec.isWorking then |
107 | if spec.colorParticleSystems ~= nil then |
108 | for _, mapping in ipairs(spec.colorParticleSystems) do |
109 | local wx, wy, wz = getWorldTranslation(mapping.node) |
110 | |
111 | local densityBits = getDensityAtWorldPos(g_currentMission.terrainDetailId, wx, wy, wz) |
112 | local isOnField = densityBits ~= 0 |
113 | |
114 | if isOnField then |
115 | mapping.lastColor[1], mapping.lastColor[2], mapping.lastColor[3], _ = FSDensityMapUtil.getTireTrackColorFromDensityBits(densityBits) |
116 | else |
117 | mapping.lastColor[1], mapping.lastColor[2], mapping.lastColor[3], _, _ = getTerrainAttributesAtWorldPos(g_currentMission.terrainRootNode, wx, wy, wz, true, true, true, true, false) |
118 | end |
119 | |
120 | -- interpolate between different ground colors to avoid unrealisitic particle color changes |
121 | if mapping.targetColor == nil then |
122 | mapping.targetColor = {mapping.lastColor[1],mapping.lastColor[2],mapping.lastColor[3]} |
123 | mapping.currentColor = {mapping.lastColor[1],mapping.lastColor[2],mapping.lastColor[3]} |
124 | mapping.alpha = 1 |
125 | end |
126 | |
127 | if mapping.alpha ~= 1 then |
128 | mapping.alpha = math.min(mapping.alpha + dt/1000, 1) |
129 | mapping.currentColor = {MathUtil.vector3ArrayLerp(mapping.lastColor, mapping.targetColor, mapping.alpha)} |
130 | if mapping.alpha == 1 then |
131 | mapping.lastColor = {mapping.currentColor[1], mapping.currentColor[2], mapping.currentColor[3]} |
132 | end |
133 | end |
134 | |
135 | if mapping.alpha == 1 and mapping.lastColor[1] ~= mapping.targetColor[1] and mapping.lastColor[2] ~= mapping.targetColor[2] and mapping.lastColor[3] ~= mapping.targetColor[3] then |
136 | mapping.alpha = 0 |
137 | mapping.targetColor = {mapping.lastColor[1], mapping.lastColor[2], mapping.lastColor[3]} |
138 | end |
139 | |
140 | setShaderParameter(mapping.particleSystem.shape, "psColor", mapping.currentColor[1], mapping.currentColor[2], mapping.currentColor[3], 1, false) |
141 | end |
142 | end |
143 | end |
144 | 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 |
23 | function Weeder.prerequisitesPresent(specializations) |
24 | return SpecializationUtil.hasSpecialization(WorkArea, specializations) and |
25 | SpecializationUtil.hasSpecialization(AttacherJoints, specializations) |
26 | end |
processWeederArea
DescriptionDefinitionprocessWeederArea()Code
148 | function Weeder:processWeederArea(workArea, dt) |
149 | local spec = self.spec_weeder |
150 | local xs,_,zs = getWorldTranslation(workArea.start) |
151 | local xw,_,zw = getWorldTranslation(workArea.width) |
152 | local xh,_,zh = getWorldTranslation(workArea.height) |
153 | local area = FSDensityMapUtil.updateWeederArea(xs,zs, xw,zw, xh,zh, spec.maxGrowthState) |
154 | |
155 | spec.workAreaParameters.lastArea = spec.workAreaParameters.lastArea + area |
156 | spec.workAreaParameters.lastStatsArea = spec.workAreaParameters.lastStatsArea + area |
157 | |
158 | spec.isWorking = self:getLastSpeed() > 0.5 |
159 | |
160 | return area, area |
161 | end |
registerEventListeners
DescriptionDefinitionregisterEventListeners()Code
47 | function Weeder.registerEventListeners(vehicleType) |
48 | SpecializationUtil.registerEventListener(vehicleType, "onLoad", Weeder) |
49 | SpecializationUtil.registerEventListener(vehicleType, "onDelete", Weeder) |
50 | SpecializationUtil.registerEventListener(vehicleType, "onUpdateTick", Weeder) |
51 | SpecializationUtil.registerEventListener(vehicleType, "onDeactivate", Weeder) |
52 | SpecializationUtil.registerEventListener(vehicleType, "onPostAttach", Weeder) |
53 | SpecializationUtil.registerEventListener(vehicleType, "onStartWorkAreaProcessing", Weeder) |
54 | SpecializationUtil.registerEventListener(vehicleType, "onEndWorkAreaProcessing", Weeder) |
55 | end |
registerFunctions
DescriptionDefinitionregisterFunctions()Code
30 | function Weeder.registerFunctions(vehicleType) |
31 | SpecializationUtil.registerFunction(vehicleType, "processWeederArea", Weeder.processWeederArea) |
32 | end |
registerOverwrittenFunctions
DescriptionDefinitionregisterOverwrittenFunctions()Code
36 | function Weeder.registerOverwrittenFunctions(vehicleType) |
37 | SpecializationUtil.registerOverwrittenFunction(vehicleType, "doCheckSpeedLimit", Weeder.doCheckSpeedLimit) |
38 | SpecializationUtil.registerOverwrittenFunction(vehicleType, "getDirtMultiplier", Weeder.getDirtMultiplier) |
39 | SpecializationUtil.registerOverwrittenFunction(vehicleType, "getWearMultiplier", Weeder.getWearMultiplier) |
40 | SpecializationUtil.registerOverwrittenFunction(vehicleType, "loadWorkAreaFromXML", Weeder.loadWorkAreaFromXML) |
41 | SpecializationUtil.registerOverwrittenFunction(vehicleType, "getIsWorkAreaActive", Weeder.getIsWorkAreaActive) |
42 | SpecializationUtil.registerOverwrittenFunction(vehicleType, "loadGroundParticleMapping", Weeder.loadGroundParticleMapping) |
43 | end |