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
WindBending
DescriptionSpecialization for controlling wind bending nodesFunctions
initSpecialization
DescriptionDefinitioninitSpecialization()Code
23 | function WindBending.initSpecialization() |
24 | local schema = Vehicle.xmlSchema |
25 | schema:setXMLSpecializationType("WindBending") |
26 | |
27 | schema:register(XMLValueType.NODE_INDEX, "vehicle.windBending.windBendingNodes.windBendingNode(?)#node", "Shader node") |
28 | schema:register(XMLValueType.NODE_INDEX, "vehicle.windBending.windBendingNodes.windBendingNode(?)#decalNode", "Extra node that gets the exact same shader parameters") |
29 | schema:register(XMLValueType.NODE_INDEX, "vehicle.windBending.windBendingNodes.windBendingNode(?)#speedReferenceNode", "Reference node to calculate speed of wind") |
30 | schema:register(XMLValueType.FLOAT, "vehicle.windBending.windBendingNodes.windBendingNode(?)#maxBending", "Bending in meters", 0.15) |
31 | schema:register(XMLValueType.FLOAT, "vehicle.windBending.windBendingNodes.windBendingNode(?)#maxBendingNeg", "Negative bending in meters (used if the vehicle drives in reverse)", "same as #maxBending") |
32 | schema:register(XMLValueType.FLOAT, "vehicle.windBending.windBendingNodes.windBendingNode(?)#maxBendingSpeed", "Speed at which max bending state is reached in kmph", 20) |
33 | |
34 | schema:setXMLSpecializationType() |
35 | end |
onLoad
DescriptionCalled on loadingDefinition
onLoad(table savegame)Arguments
table | savegame | savegame |
52 | function WindBending:onLoad(savegame) |
53 | local spec = self.spec_windBending |
54 | |
55 | if self.isClient then |
56 | spec.windBending = {} |
57 | |
58 | self.xmlFile:iterate("vehicle.windBending.windBendingNodes.windBendingNode", function(_, key) |
59 | local entry = {} |
60 | entry.node = self.xmlFile:getValue(key .. "#node", nil, self.components, self.i3dMappings) |
61 | if entry.node ~= nil then |
62 | if getHasClassId(entry.node, ClassIds.SHAPE) and getHasShaderParameter(entry.node, "directionBend") then |
63 | entry.speedReferenceNode = self.xmlFile:getValue(key .. "#speedReferenceNode", entry.node, self.components, self.i3dMappings) |
64 | entry.parentComponent = self:getParentComponent(entry.speedReferenceNode) |
65 | |
66 | entry.maxBending = self.xmlFile:getValue(key .. "#maxBending", 0.15) |
67 | entry.maxBendingNeg = self.xmlFile:getValue(key .. "#maxBendingNeg", entry.maxBending) |
68 | entry.maxBendingSpeed = self.xmlFile:getValue(key .. "#maxBendingSpeed", 20) |
69 | |
70 | entry.decalNode = self.xmlFile:getValue(key .. "#decalNode", nil, self.components, self.i3dMappings) |
71 | |
72 | entry.lastPosition = nil |
73 | |
74 | table.insert(spec.windBending, entry) |
75 | else |
76 | Logging.xmlError(self.xmlFile, "Unable to load wind bending node from xml. Node has not shader parameter 'directionBend'. '%s'", key) |
77 | end |
78 | else |
79 | Logging.xmlError(self.xmlFile, "Unable to load wind bending node from xml. Node not found. '%s'", key) |
80 | end |
81 | end) |
82 | end |
83 | |
84 | if not self.isClient or #spec.windBending == 0 then |
85 | SpecializationUtil.removeEventListener(self, "onUpdate", WindBending) |
86 | end |
87 | end |
onUpdate
DescriptionCalled on updateDefinition
onUpdate(float dt, boolean isActiveForInput, boolean isSelected)Arguments
float | dt | time since last call in ms |
boolean | isActiveForInput | true if vehicle is active for input |
boolean | isSelected | true if vehicle is selected |
94 | function WindBending:onUpdate(dt, isActiveForInput, isActiveForInputIgnoreSelection, isSelected) |
95 | local spec = self.spec_windBending |
96 | |
97 | local lastSpeed = self:getLastSpeed() |
98 | for i=1, #spec.windBending do |
99 | local windBendingNode = spec.windBending[i] |
100 | |
101 | local x, y, z = localToWorld(windBendingNode.speedReferenceNode, 0, 0, 0) |
102 | if windBendingNode.lastPosition == nil then |
103 | windBendingNode.lastPosition = {x, y, z} |
104 | end |
105 | |
106 | local vx = (x - windBendingNode.lastPosition[1]) * 10 |
107 | local vy = (y - windBendingNode.lastPosition[2]) * 10 |
108 | local vz = (z - windBendingNode.lastPosition[3]) * 10 |
109 | |
110 | if vx ~= 0 or vy ~= 0 or vz ~= 0 then |
111 | vx, vy, vz = worldDirectionToLocal(getParent(windBendingNode.node), vx, vy, vz) |
112 | vx, vy, vz = MathUtil.vector3Normalize(vx, vy, vz) |
113 | |
114 | local maxBending = self.movingDirection >= 0 and windBendingNode.maxBending or windBendingNode.maxBendingNeg |
115 | local bendingAmount = maxBending * (lastSpeed / windBendingNode.maxBendingSpeed) |
116 | g_animationManager:setPrevShaderParameter(windBendingNode.node, "directionBend", vx, vy, vz, bendingAmount, false, "prevDirectionBend") |
117 | |
118 | if windBendingNode.decalNode ~= nil then |
119 | g_animationManager:setPrevShaderParameter(windBendingNode.decalNode, "directionBend", vx, vy, vz, bendingAmount, false, "prevDirectionBend") |
120 | end |
121 | end |
122 | |
123 | windBendingNode.lastPosition[1] = x |
124 | windBendingNode.lastPosition[2] = y |
125 | windBendingNode.lastPosition[3] = z |
126 | end |
127 | 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 WindBending.prerequisitesPresent(specializations) |
18 | return true |
19 | end |
registerEventListeners
DescriptionDefinitionregisterEventListeners()Code
44 | function WindBending.registerEventListeners(vehicleType) |
45 | SpecializationUtil.registerEventListener(vehicleType, "onLoad", WindBending) |
46 | SpecializationUtil.registerEventListener(vehicleType, "onUpdate", WindBending) |
47 | end |
registerFunctions
DescriptionDefinitionregisterFunctions()Code
39 | function WindBending.registerFunctions(vehicleType) |
40 | end |