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
VinePrepruner
DescriptionSpecialization for vine preprunersFunctions
- initSpecialization
- onDelete
- onLoad
- onReadStream
- onReadUpdateStream
- onUpdate
- onWriteStream
- onWriteUpdateStream
- prerequisitesPresent
- readPrePrunerFromStream
- registerEventListeners
- registerFunctions
- registerOverwrittenFunctions
- writePrePrunerToStream
initSpecialization
DescriptionDefinitioninitSpecialization()Code
18 | function VinePrepruner.initSpecialization() |
19 | local schema = Vehicle.xmlSchema |
20 | schema:setXMLSpecializationType("VinePrepruner") |
21 | schema:register(XMLValueType.STRING, "vehicle.vinePrepruner#fruitType", "Fruit type") |
22 | |
23 | local nodeKey = VinePrepruner.PRUNER_NODE_XML_KEY |
24 | schema:register(XMLValueType.NODE_INDEX, nodeKey .. "#node", "Pruner node that adjusts translation depending on raycast distance") |
25 | schema:register(XMLValueType.FLOAT, nodeKey .. "#offset", "Offset from raycast node to center of pruning unit", 0.5) |
26 | schema:register(XMLValueType.INT, nodeKey .. "#axis", "Move axis", 1) |
27 | schema:register(XMLValueType.INT, nodeKey .. "#direction", "Translation direction", 1) |
28 | schema:register(XMLValueType.FLOAT, nodeKey .. "#transMin", "Min. translation", 0) |
29 | schema:register(XMLValueType.FLOAT, nodeKey .. "#transMax", "Max. translation", 1) |
30 | schema:register(XMLValueType.FLOAT, nodeKey .. "#transSpeed", "Translation speed (m/sec)", 0.5) |
31 | schema:register(XMLValueType.INT, nodeKey .. "#numBits", "Number of bits to sync state in multiplayer", 8) |
32 | |
33 | schema:register(XMLValueType.STRING, "vehicle.vinePrepruner.poleAnimation#name", "Name of pole animation (will be triggered as soon as pole has been detected)") |
34 | schema:register(XMLValueType.FLOAT, "vehicle.vinePrepruner.poleAnimation#speedScale", "Animation speed scale", 1) |
35 | schema:register(XMLValueType.FLOAT, "vehicle.vinePrepruner.poleAnimation#poleThreshold", "Defines when the pole is detected as percentage of segment length", 0.1) |
36 | |
37 | EffectManager.registerEffectXMLPaths(schema, "vehicle.vinePrepruner.effect") |
38 | |
39 | schema:setXMLSpecializationType() |
40 | end |
onDelete
DescriptionCalled on deletingDefinition
onDelete()Code
116 | function VinePrepruner:onDelete() |
117 | local spec = self.spec_vinePrepruner |
118 | g_effectManager:deleteEffects(spec.effects) |
119 | end |
onLoad
DescriptionDefinitiononLoad()Code
80 | function VinePrepruner:onLoad(savegame) |
81 | local spec = self.spec_vinePrepruner |
82 | |
83 | local fruitTypeName = self.xmlFile:getValue("vehicle.vinePrepruner#fruitType") |
84 | local fruitType = g_fruitTypeManager:getFruitTypeByName(fruitTypeName) |
85 | if fruitType ~= nil then |
86 | spec.fruitTypeIndex = fruitType.index |
87 | else |
88 | spec.fruitTypeIndex = FruitType.GRAPE |
89 | end |
90 | |
91 | spec.prunerNodes = {} |
92 | self.xmlFile:iterate("vehicle.vinePrepruner.prunerNode", function(index, key) |
93 | local entry = {} |
94 | if self:loadPreprunerNodeFromXML(self.xmlFile, key, entry) then |
95 | table.insert(spec.prunerNodes, entry) |
96 | end |
97 | end) |
98 | |
99 | spec.poleAnimation = {} |
100 | spec.poleAnimation.name = self.xmlFile:getValue("vehicle.vinePrepruner.poleAnimation#name") |
101 | spec.poleAnimation.speedScale = self.xmlFile:getValue("vehicle.vinePrepruner.poleAnimation#speedScale", 1) |
102 | spec.poleAnimation.poleThreshold = 1 - self.xmlFile:getValue("vehicle.vinePrepruner.poleAnimation#poleThreshold", 0.1) |
103 | |
104 | spec.lastWorkTime = -10000 |
105 | spec.effectState = false |
106 | |
107 | if self.isClient then |
108 | spec.effects = g_effectManager:loadEffect(self.xmlFile, "vehicle.vinePrepruner.effect", self.components, self, self.i3dMappings) |
109 | end |
110 | |
111 | spec.dirtyFlag = self:getNextDirtyFlag() |
112 | end |
onReadStream
DescriptionDefinitiononReadStream()Code
123 | function VinePrepruner:onReadStream(streamId, connection) |
124 | VinePrepruner.readPrePrunerFromStream(self, streamId, true) |
125 | end |
onReadUpdateStream
DescriptionDefinitiononReadUpdateStream()Code
135 | function VinePrepruner:onReadUpdateStream(streamId, timestamp, connection) |
136 | if connection:getIsServer() then |
137 | if streamReadBool(streamId) then |
138 | VinePrepruner.readPrePrunerFromStream(self, streamId) |
139 | end |
140 | end |
141 | end |
onUpdate
DescriptionDefinitiononUpdate()Code
200 | function VinePrepruner:onUpdate(dt, isActive, isActiveForInput, isSelected) |
201 | local spec = self.spec_vinePrepruner |
202 | for i=1, #spec.prunerNodes do |
203 | local prunerNode = spec.prunerNodes[i] |
204 | if self:getIsPreprunerNodeActive(prunerNode) then |
205 | local curTrans = prunerNode.curTrans[prunerNode.axis] |
206 | if prunerNode.transTarget ~= curTrans then |
207 | local moveDirection = MathUtil.sign(prunerNode.transTarget - curTrans) |
208 | local func = moveDirection >= 0 and math.min or math.max |
209 | prunerNode.curTrans[prunerNode.axis] = func(curTrans + prunerNode.transSpeed * dt * moveDirection, prunerNode.transTarget) |
210 | setTranslation(prunerNode.node, prunerNode.curTrans[1], prunerNode.curTrans[2], prunerNode.curTrans[3]) |
211 | end |
212 | end |
213 | end |
214 | |
215 | if self.isServer then |
216 | local effectState = spec.lastWorkTime + 1000 > g_time |
217 | if effectState ~= spec.effectState then |
218 | spec.effectState = effectState |
219 | |
220 | if self.isClient then |
221 | if effectState then |
222 | g_effectManager:setFruitType(spec.effects, spec.fruitTypeIndex) |
223 | g_effectManager:startEffects(spec.effects) |
224 | else |
225 | g_effectManager:stopEffects(spec.effects) |
226 | end |
227 | end |
228 | |
229 | self:raiseDirtyFlags(spec.dirtyFlag) |
230 | end |
231 | end |
232 | end |
onWriteStream
DescriptionDefinitiononWriteStream()Code
129 | function VinePrepruner:onWriteStream(streamId, connection) |
130 | VinePrepruner.writePrePrunerToStream(self, streamId) |
131 | end |
onWriteUpdateStream
DescriptionDefinitiononWriteUpdateStream()Code
145 | function VinePrepruner:onWriteUpdateStream(streamId, connection, dirtyMask) |
146 | if not connection:getIsServer() then |
147 | local spec = self.spec_vinePrepruner |
148 | if streamWriteBool(streamId, bitAND(dirtyMask, spec.dirtyFlag) ~= 0) then |
149 | VinePrepruner.writePrePrunerToStream(self, streamId) |
150 | end |
151 | end |
152 | end |
prerequisitesPresent
DescriptionDefinitionprerequisitesPresent()Code
44 | function VinePrepruner.prerequisitesPresent(specializations) |
45 | return SpecializationUtil.hasSpecialization(VineDetector, specializations) |
46 | end |
readPrePrunerFromStream
DescriptionDefinitionreadPrePrunerFromStream()Code
156 | function VinePrepruner.readPrePrunerFromStream(self, streamId, forceState) |
157 | local spec = self.spec_vinePrepruner |
158 | for i=1, #spec.prunerNodes do |
159 | local prunerNode = spec.prunerNodes[i] |
160 | |
161 | local maxValue = (2 ^ prunerNode.numBits) - 1 |
162 | local rawValue = streamReadUIntN(streamId, prunerNode.numBits) |
163 | prunerNode.transTarget = rawValue / maxValue * (prunerNode.transMax - prunerNode.transMin) + prunerNode.transMin |
164 | if forceState then |
165 | prunerNode.curTrans[prunerNode.axis] = prunerNode.transTarget |
166 | setTranslation(prunerNode.node, prunerNode.curTrans[1], prunerNode.curTrans[2], prunerNode.curTrans[3]) |
167 | end |
168 | end |
169 | |
170 | local effectState = streamReadBool(streamId) |
171 | if effectState ~= spec.effectState then |
172 | spec.effectState = effectState |
173 | |
174 | if effectState then |
175 | g_effectManager:setFruitType(spec.effects, spec.fruitTypeIndex) |
176 | g_effectManager:startEffects(spec.effects) |
177 | else |
178 | g_effectManager:stopEffects(spec.effects) |
179 | end |
180 | end |
181 | end |
registerEventListeners
DescriptionDefinitionregisterEventListeners()Code
66 | function VinePrepruner.registerEventListeners(vehicleType) |
67 | SpecializationUtil.registerEventListener(vehicleType, "onLoad", VinePrepruner) |
68 | SpecializationUtil.registerEventListener(vehicleType, "onDelete", VinePrepruner) |
69 | SpecializationUtil.registerEventListener(vehicleType, "onReadStream", VinePrepruner) |
70 | SpecializationUtil.registerEventListener(vehicleType, "onWriteStream", VinePrepruner) |
71 | SpecializationUtil.registerEventListener(vehicleType, "onReadUpdateStream", VinePrepruner) |
72 | SpecializationUtil.registerEventListener(vehicleType, "onWriteUpdateStream", VinePrepruner) |
73 | SpecializationUtil.registerEventListener(vehicleType, "onUpdate", VinePrepruner) |
74 | SpecializationUtil.registerEventListener(vehicleType, "onTurnedOff", VinePrepruner) |
75 | SpecializationUtil.registerEventListener(vehicleType, "onAnimationPartChanged", VinePrepruner) |
76 | end |
registerFunctions
DescriptionDefinitionregisterFunctions()Code
50 | function VinePrepruner.registerFunctions(vehicleType) |
51 | SpecializationUtil.registerFunction(vehicleType, "loadPreprunerNodeFromXML", VinePrepruner.loadPreprunerNodeFromXML) |
52 | SpecializationUtil.registerFunction(vehicleType, "getIsPreprunerNodeActive", VinePrepruner.getIsPreprunerNodeActive) |
53 | end |
registerOverwrittenFunctions
DescriptionDefinitionregisterOverwrittenFunctions()Code
57 | function VinePrepruner.registerOverwrittenFunctions(vehicleType) |
58 | SpecializationUtil.registerOverwrittenFunction(vehicleType, "doCheckSpeedLimit", VinePrepruner.doCheckSpeedLimit) |
59 | SpecializationUtil.registerOverwrittenFunction(vehicleType, "getCanStartVineDetection", VinePrepruner.getCanStartVineDetection) |
60 | SpecializationUtil.registerOverwrittenFunction(vehicleType, "getIsValidVinePlaceable", VinePrepruner.getIsValidVinePlaceable) |
61 | SpecializationUtil.registerOverwrittenFunction(vehicleType, "handleVinePlaceable", VinePrepruner.handleVinePlaceable) |
62 | end |
writePrePrunerToStream
DescriptionDefinitionwritePrePrunerToStream()Code
185 | function VinePrepruner.writePrePrunerToStream(self, streamId) |
186 | local spec = self.spec_vinePrepruner |
187 | for i=1, #spec.prunerNodes do |
188 | local prunerNode = spec.prunerNodes[i] |
189 | |
190 | local maxValue = (2 ^ prunerNode.numBits) - 1 |
191 | local state = (prunerNode.transTarget - prunerNode.transMin) / (prunerNode.transMax - prunerNode.transMin) |
192 | streamWriteUIntN(streamId, state * maxValue, prunerNode.numBits) |
193 | end |
194 | |
195 | streamWriteBool(streamId, spec.effectState) |
196 | end |