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
Mulcher
DescriptionSpecialization for all mulchers, requires WorkArea specializationFunctions
- doCheckSpeedLimit
- getDefaultSpeedLimit
- getDirtMultiplier
- getDoGroundManipulation
- getWearMultiplier
- initSpecialization
- loadWorkAreaFromXML
- onDeactivate
- onDelete
- onEndWorkAreaProcessing
- onLoad
- onPostLoad
- onReadStream
- onReadUpdateStream
- onStartWorkAreaProcessing
- onUpdateTick
- onWriteStream
- onWriteUpdateStream
- prerequisitesPresent
- processMulcherArea
- registerEventListeners
- registerFunctions
- registerOverwrittenFunctions
doCheckSpeedLimit
DescriptionReturns if speed limit should be checkedDefinition
doCheckSpeedLimit()Return Values
boolean | checkSpeedlimit | check speed limit |
298 | function Mulcher:doCheckSpeedLimit(superFunc) |
299 | return superFunc(self) or self:getIsImplementChainLowered() |
300 | end |
getDefaultSpeedLimit
DescriptionReturns default speed limitDefinition
getDefaultSpeedLimit()Return Values
float | speedLimit | speed limit |
409 | function Mulcher.getDefaultSpeedLimit() |
410 | return 15 |
411 | end |
getDirtMultiplier
DescriptionReturns current dirt multiplierDefinition
getDirtMultiplier()Return Values
float | dirtMultiplier | current dirt multiplier |
318 | function Mulcher:getDirtMultiplier(superFunc) |
319 | local spec = self.spec_mulcher |
320 | |
321 | local multiplier = superFunc(self) |
322 | if spec.isWorking then |
323 | multiplier = multiplier + self:getWorkDirtMultiplier() * self:getLastSpeed() / spec.speedLimit |
324 | end |
325 | |
326 | return multiplier |
327 | end |
getDoGroundManipulation
DescriptionReturns if tool does ground manipulationDefinition
getDoGroundManipulation()Return Values
boolean | doGroundManipulation | do ground manipulation |
305 | function Mulcher:getDoGroundManipulation(superFunc) |
306 | local spec = self.spec_mulcher |
307 | |
308 | if not spec.isWorking then |
309 | return false |
310 | end |
311 | |
312 | return superFunc(self) |
313 | end |
getWearMultiplier
DescriptionReturns current wear multiplierDefinition
getWearMultiplier()Return Values
float | dirtMultiplier | current wear multiplier |
332 | function Mulcher:getWearMultiplier(superFunc) |
333 | local spec = self.spec_mulcher |
334 | local multiplier = superFunc(self) |
335 | |
336 | if spec.isWorking then |
337 | local stoneMultiplier = 1 |
338 | if spec.stoneLastState ~= 0 and spec.stoneWearMultiplierData ~= nil then |
339 | stoneMultiplier = spec.stoneWearMultiplierData[spec.stoneLastState] or 1 |
340 | end |
341 | |
342 | multiplier = multiplier + self:getWorkWearMultiplier() * self:getLastSpeed() / spec.speedLimit * stoneMultiplier |
343 | end |
344 | |
345 | return multiplier |
346 | end |
initSpecialization
DescriptionCalled on specialization initializingDefinition
initSpecialization()Code
24 | function Mulcher.initSpecialization() |
25 | g_workAreaTypeManager:addWorkAreaType("mulcher", true) |
26 | |
27 | local schema = Vehicle.xmlSchema |
28 | schema:setXMLSpecializationType("Mulcher") |
29 | |
30 | EffectManager.registerEffectXMLPaths(schema, "vehicle.mulcher.effects.effect(?)") |
31 | schema:register(XMLValueType.INT, "vehicle.mulcher.effects.effect(?)#workAreaIndex", "Work area index", 1) |
32 | schema:register(XMLValueType.INT, "vehicle.mulcher.effects.effect(?)#activeDirection", "If vehicle is driving into this direction the effect will be activated (0 = any direction)", 0) |
33 | |
34 | SoundManager.registerSampleXMLPaths(schema, "vehicle.mulcher.sounds", "work") |
35 | |
36 | schema:setXMLSpecializationType() |
37 | 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 |
354 | function Mulcher:loadWorkAreaFromXML(superFunc, workArea, xmlFile, key) |
355 | local retValue = superFunc(self, workArea, xmlFile, key) |
356 | |
357 | if workArea.type == WorkAreaType.DEFAULT then |
358 | workArea.type = WorkAreaType.MULCHER |
359 | end |
360 | |
361 | return retValue |
362 | end |
onDeactivate
DescriptionDefinitiononDeactivate()Code
366 | function Mulcher:onDeactivate() |
367 | local spec = self.spec_mulcher |
368 | if self.isClient then |
369 | g_soundManager:stopSamples(spec.samples) |
370 | spec.isWorkSamplePlaying = false |
371 | end |
372 | |
373 | for _, effect in ipairs(spec.effects) do |
374 | g_effectManager:stopEffects(effect.effects) |
375 | end |
376 | end |
onDelete
DescriptionCalled on deletingDefinition
onDelete()Code
171 | function Mulcher:onDelete() |
172 | local spec = self.spec_mulcher |
173 | g_soundManager:deleteSamples(spec.samples) |
174 | |
175 | if spec.effects ~= nil then |
176 | for _, effect in ipairs(spec.effects) do |
177 | g_effectManager:deleteEffects(effect.effects) |
178 | end |
179 | end |
180 | end |
onEndWorkAreaProcessing
DescriptionDefinitiononEndWorkAreaProcessing()Code
388 | function Mulcher:onEndWorkAreaProcessing(dt) |
389 | local spec = self.spec_mulcher |
390 | |
391 | if self.isClient then |
392 | if spec.isWorking then |
393 | if not spec.isWorkSamplePlaying then |
394 | g_soundManager:playSample(spec.samples.work) |
395 | spec.isWorkSamplePlaying = true |
396 | end |
397 | else |
398 | if spec.isWorkSamplePlaying then |
399 | g_soundManager:stopSample(spec.samples.work) |
400 | spec.isWorkSamplePlaying = false |
401 | end |
402 | end |
403 | end |
404 | end |
onLoad
DescriptionCalled on loadingDefinition
onLoad(table savegame)Arguments
table | savegame | savegame |
81 | function Mulcher:onLoad(savegame) |
82 | if self:getGroundReferenceNodeFromIndex(1) == nil then |
83 | print("Warning: No ground reference nodes in "..self.configFileName) |
84 | end |
85 | |
86 | local spec = self.spec_mulcher |
87 | |
88 | if self.isClient then |
89 | spec.samples = {} |
90 | spec.samples.work = g_soundManager:loadSampleFromXML(self.xmlFile, "vehicle.mulcher.sounds", "work", self.baseDirectory, self.components, 0, AudioGroup.VEHICLE, self.i3dMappings, self) |
91 | spec.isWorkSamplePlaying = false |
92 | end |
93 | |
94 | spec.effects = {} |
95 | spec.workAreaToEffects = {} |
96 | local i = 0 |
97 | while true do |
98 | local key = string.format("vehicle.mulcher.effects.effect(%d)", i) |
99 | if not self.xmlFile:hasProperty(key) then |
100 | break |
101 | end |
102 | |
103 | local effects = g_effectManager:loadEffect(self.xmlFile, key, self.components, self, self.i3dMappings) |
104 | if effects ~= nil then |
105 | local effect = {} |
106 | effect.effects = effects |
107 | effect.workAreaIndex = self.xmlFile:getValue(key .. "#workAreaIndex", 1) |
108 | effect.activeDirection = self.xmlFile:getValue(key .. "#activeDirection", 0) |
109 | effect.activeTime = -1 |
110 | effect.activeTimeDuration = 250 |
111 | effect.isActive = false |
112 | effect.isActiveSent = false |
113 | |
114 | table.insert(spec.effects, effect) |
115 | end |
116 | i = i + 1 |
117 | end |
118 | |
119 | spec.effectFillType = FillType.WHEAT |
120 | |
121 | if self.addAIGroundTypeRequirements ~= nil then |
122 | self:addAIGroundTypeRequirements(Mulcher.AI_REQUIRED_GROUND_TYPES) |
123 | |
124 | self:clearAIFruitRequirements() |
125 | for _, fruitType in ipairs(g_fruitTypeManager:getFruitTypes()) do |
126 | if fruitType.destruction.canBeDestroyed then |
127 | if fruitType.mulcher.state > fruitType.cutState then |
128 | self:addAIFruitRequirement(fruitType.index, 2, fruitType.mulcher.state - 1) |
129 | else |
130 | self:addAIFruitRequirement(fruitType.index, 2, 15) |
131 | end |
132 | end |
133 | end |
134 | end |
135 | |
136 | spec.isWorking = false |
137 | spec.lastWorkTime = -math.huge |
138 | |
139 | spec.stoneLastState = 0 |
140 | spec.stoneWearMultiplierData = g_currentMission.stoneSystem:getWearMultiplierByType("MULCHER") |
141 | |
142 | spec.effectDirtyFlag = self:getNextDirtyFlag() |
143 | |
144 | if not self.isClient or #spec.effects == 0 then |
145 | SpecializationUtil.removeEventListener(self, "onUpdateTick", Mulcher) |
146 | end |
147 | end |
onPostLoad
DescriptionDefinitiononPostLoad()Code
151 | function Mulcher:onPostLoad(savegame) |
152 | local spec = self.spec_mulcher |
153 | for i=#spec.effects, 1, -1 do |
154 | local effect = spec.effects[i] |
155 | local workArea = self:getWorkAreaByIndex(effect.workAreaIndex) |
156 | if workArea ~= nil then |
157 | if spec.workAreaToEffects[workArea.index] == nil then |
158 | spec.workAreaToEffects[workArea.index] = {} |
159 | end |
160 | table.insert(spec.workAreaToEffects[workArea.index], effect) |
161 | else |
162 | Logging.xmlWarning(self.xmlFile, "Invalid workAreaIndex '%d' for effect 'vehicle.mulcher.effects.effect(%d)'!", effect.workAreaIndex, i) |
163 | table.remove(spec.effects, i) |
164 | end |
165 | end |
166 | end |
onReadStream
DescriptionDefinitiononReadStream()Code
184 | function Mulcher:onReadStream(streamId, connection) |
185 | local spec = self.spec_mulcher |
186 | for _, effect in ipairs(spec.effects) do |
187 | if streamReadBool(streamId) then |
188 | g_effectManager:setFillType(effect.effects, spec.effectFillType) |
189 | g_effectManager:startEffects(effect.effects) |
190 | else |
191 | g_effectManager:stopEffects(effect.effects) |
192 | end |
193 | end |
194 | end |
onReadUpdateStream
DescriptionDefinitiononReadUpdateStream()Code
207 | function Mulcher:onReadUpdateStream(streamId, timestamp, connection) |
208 | if connection:getIsServer() then |
209 | local spec = self.spec_mulcher |
210 | if streamReadBool(streamId) then |
211 | for _, effect in ipairs(spec.effects) do |
212 | if streamReadBool(streamId) then |
213 | g_effectManager:setFillType(effect.effects, spec.effectFillType) |
214 | g_effectManager:startEffects(effect.effects) |
215 | else |
216 | g_effectManager:stopEffects(effect.effects) |
217 | end |
218 | end |
219 | end |
220 | end |
221 | end |
onStartWorkAreaProcessing
DescriptionDefinitiononStartWorkAreaProcessing()Code
380 | function Mulcher:onStartWorkAreaProcessing(dt) |
381 | local spec = self.spec_mulcher |
382 | |
383 | spec.isWorking = false |
384 | end |
onUpdateTick
DescriptionDefinitiononUpdateTick()Code
238 | function Mulcher:onUpdateTick(dt, isActiveForInput, isActiveForInputIgnoreSelection, isSelected) |
239 | if self.isServer then |
240 | local spec = self.spec_mulcher |
241 | for _, effect in ipairs(spec.effects) do |
242 | if effect.isActive and g_currentMission.time > effect.activeTime then |
243 | effect.isActive = false |
244 | self:raiseDirtyFlags(spec.effectDirtyFlag) |
245 | g_effectManager:stopEffects(effect.effects) |
246 | end |
247 | end |
248 | end |
249 | end |
onWriteStream
DescriptionDefinitiononWriteStream()Code
198 | function Mulcher:onWriteStream(streamId, connection) |
199 | local spec = self.spec_mulcher |
200 | for _, effect in ipairs(spec.effects) do |
201 | streamWriteBool(streamId, effect.isActive) |
202 | end |
203 | end |
onWriteUpdateStream
DescriptionDefinitiononWriteUpdateStream()Code
225 | function Mulcher:onWriteUpdateStream(streamId, connection, dirtyMask) |
226 | if not connection:getIsServer() then |
227 | local spec = self.spec_mulcher |
228 | if streamWriteBool(streamId, bitAND(dirtyMask, spec.effectDirtyFlag) ~= 0) then |
229 | for _, effect in ipairs(spec.effects) do |
230 | streamWriteBool(streamId, effect.isActive) |
231 | end |
232 | end |
233 | end |
234 | 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 |
43 | function Mulcher.prerequisitesPresent(specializations) |
44 | return SpecializationUtil.hasSpecialization(WorkArea, specializations) and SpecializationUtil.hasSpecialization(GroundReference, specializations) |
45 | end |
processMulcherArea
DescriptionDefinitionprocessMulcherArea()Code
253 | function Mulcher:processMulcherArea(workArea, dt) |
254 | local spec = self.spec_mulcher |
255 | |
256 | local xs,_,zs = getWorldTranslation(workArea.start) |
257 | local xw,_,zw = getWorldTranslation(workArea.width) |
258 | local xh,_,zh = getWorldTranslation(workArea.height) |
259 | |
260 | local realArea, area = FSDensityMapUtil.updateMulcherArea(xs,zs, xw,zw, xh,zh) |
261 | if realArea > 0 and self:getLastSpeed() > 0.5 then |
262 | local effects = spec.workAreaToEffects[workArea.index] |
263 | if effects ~= nil then |
264 | for _, effect in ipairs(effects) do |
265 | if effect.activeDirection == 0 or self.movingDirection == effect.activeDirection then |
266 | effect.activeTime = g_currentMission.time + effect.activeTimeDuration |
267 | |
268 | if not effect.isActive then |
269 | g_effectManager:setFillType(effect.effects, spec.effectFillType) |
270 | g_effectManager:startEffects(effect.effects) |
271 | |
272 | effect.isActive = true |
273 | self:raiseDirtyFlags(spec.effectDirtyFlag) |
274 | end |
275 | end |
276 | end |
277 | end |
278 | |
279 | spec.lastWorkTime = g_time |
280 | end |
281 | |
282 | FSDensityMapUtil.eraseTireTrack(xs,zs, xw,zw, xh,zh) |
283 | |
284 | spec.isWorking = (g_time - spec.lastWorkTime) < 500 |
285 | |
286 | if spec.isWorking then |
287 | spec.stoneLastState = FSDensityMapUtil.getStoneArea(xs, zs, xw, zw, xh, zh) |
288 | else |
289 | spec.stoneLastState = 0 |
290 | end |
291 | |
292 | return realArea, area |
293 | end |
registerEventListeners
DescriptionDefinitionregisterEventListeners()Code
64 | function Mulcher.registerEventListeners(vehicleType) |
65 | SpecializationUtil.registerEventListener(vehicleType, "onLoad", Mulcher) |
66 | SpecializationUtil.registerEventListener(vehicleType, "onPostLoad", Mulcher) |
67 | SpecializationUtil.registerEventListener(vehicleType, "onDelete", Mulcher) |
68 | SpecializationUtil.registerEventListener(vehicleType, "onReadStream", Mulcher) |
69 | SpecializationUtil.registerEventListener(vehicleType, "onWriteStream", Mulcher) |
70 | SpecializationUtil.registerEventListener(vehicleType, "onReadUpdateStream", Mulcher) |
71 | SpecializationUtil.registerEventListener(vehicleType, "onWriteUpdateStream", Mulcher) |
72 | SpecializationUtil.registerEventListener(vehicleType, "onUpdateTick", Mulcher) |
73 | SpecializationUtil.registerEventListener(vehicleType, "onDeactivate", Mulcher) |
74 | SpecializationUtil.registerEventListener(vehicleType, "onStartWorkAreaProcessing", Mulcher) |
75 | SpecializationUtil.registerEventListener(vehicleType, "onEndWorkAreaProcessing", Mulcher) |
76 | end |
registerFunctions
DescriptionDefinitionregisterFunctions()Code
49 | function Mulcher.registerFunctions(vehicleType) |
50 | SpecializationUtil.registerFunction(vehicleType, "processMulcherArea", Mulcher.processMulcherArea) |
51 | end |
registerOverwrittenFunctions
DescriptionDefinitionregisterOverwrittenFunctions()Code
55 | function Mulcher.registerOverwrittenFunctions(vehicleType) |
56 | SpecializationUtil.registerOverwrittenFunction(vehicleType, "doCheckSpeedLimit", Mulcher.doCheckSpeedLimit) |
57 | SpecializationUtil.registerOverwrittenFunction(vehicleType, "getDoGroundManipulation", Mulcher.getDoGroundManipulation) |
58 | SpecializationUtil.registerOverwrittenFunction(vehicleType, "getDirtMultiplier", Mulcher.getDirtMultiplier) |
59 | SpecializationUtil.registerOverwrittenFunction(vehicleType, "getWearMultiplier", Mulcher.getWearMultiplier) |
60 | end |