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
PlaceableWindTurbine
DescriptionSpecialization for placeablesFunctions
- getIncomePerHourFactor
- getWindTurbineLoad
- loadFromXMLFile
- onDelete
- onFinalizePlacement
- onLoad
- onReadStream
- onWriteStream
- prerequisitesPresent
- registerEventListeners
- registerFunctions
- registerOverwrittenFunctions
- registerSavegameXMLPaths
- registerXMLPaths
- saveToXMLFile
- setWindValues
- updateHeadRotation
- updateRotorRotSpeed
getIncomePerHourFactor
DescriptionDefinitiongetIncomePerHourFactor()Code
218 | function PlaceableWindTurbine:getIncomePerHourFactor(superFunc) |
219 | local factor = superFunc(self) |
220 | |
221 | return factor * self.spec_windTurbine.rotSpeedFactor |
222 | end |
getWindTurbineLoad
DescriptionDefinitiongetWindTurbineLoad()Code
210 | function PlaceableWindTurbine:getWindTurbineLoad() |
211 | local spec = self.spec_windTurbine |
212 | return spec.rotSpeedFactor |
213 | end |
loadFromXMLFile
DescriptionDefinitionloadFromXMLFile()Code
151 | function PlaceableWindTurbine:loadFromXMLFile(xmlFile, key) |
152 | local spec = self.spec_windTurbine |
153 | if spec.headNode ~= nil then |
154 | spec.headRotation = xmlFile:getValue(key.."#headRotation") |
155 | self:updateHeadRotation() |
156 | end |
157 | end |
onDelete
DescriptionDefinitiononDelete()Code
98 | function PlaceableWindTurbine:onDelete() |
99 | g_currentMission.environment.weather.windUpdater:removeWindChangedListener(self) |
100 | |
101 | local spec = self.spec_windTurbine |
102 | g_soundManager:deleteSamples(spec.samples) |
103 | g_animationManager:deleteAnimations(spec.animationNodes) |
104 | end |
onFinalizePlacement
DescriptionDefinitiononFinalizePlacement()Code
108 | function PlaceableWindTurbine:onFinalizePlacement() |
109 | local spec = self.spec_windTurbine |
110 | |
111 | local windUpdater = g_currentMission.environment.weather.windUpdater |
112 | windUpdater:addWindChangedListener(self) |
113 | |
114 | local windDirX, windDirZ, windVelocity = windUpdater:getCurrentValues() |
115 | |
116 | if spec.headNode ~= nil then |
117 | spec.headRotation = MathUtil.getYRotationFromDirection(windDirX, windDirZ) |
118 | if not spec.headAdjustToWind then |
119 | local rotVariation = 0.2 |
120 | spec.headRotation = 0.7 + math.random() * 2*rotVariation - rotVariation |
121 | end |
122 | |
123 | self:updateHeadRotation() |
124 | end |
125 | |
126 | self:updateRotorRotSpeed(windVelocity) |
127 | |
128 | g_animationManager:startAnimations(spec.animationNodes) |
129 | end |
onLoad
DescriptionCalled on loadingDefinition
onLoad(table savegame)Arguments
table | savegame | savegame |
71 | function PlaceableWindTurbine:onLoad(savegame) |
72 | local spec = self.spec_windTurbine |
73 | |
74 | local headNode = self.xmlFile:getValue("placeable.windTurbine#headNode", nil, self.components, self.i3dMappings) |
75 | if headNode ~= nil then |
76 | spec.headNode = headNode |
77 | spec.headAdjustToWind = self.xmlFile:getValue("placeable.windTurbine#headAdjustToWind", false) |
78 | spec.headRotation = 0 |
79 | end |
80 | |
81 | spec.rotorOptimalWindSpeed = self.xmlFile:getValue("placeable.windTurbine#optimalWindSpeed", 15) |
82 | spec.rotSpeedFactor = 1 |
83 | |
84 | if self.isClient then |
85 | spec.samples = {} |
86 | spec.samples.idle = g_soundManager:loadSampleFromXML(self.xmlFile, "placeable.windTurbine.sounds", "idle", self.baseDirectory, self.components, 1, AudioGroup.ENVIRONMENT, self.i3dMappings, self) |
87 | spec.animationNodes = g_animationManager:loadAnimations(self.xmlFile, "placeable.windTurbine.animationNodes", self.components, self, self.i3dMappings) |
88 | for _, anim in ipairs(spec.animationNodes) do |
89 | anim.speedFunc = function() |
90 | return spec.rotSpeedFactor |
91 | end |
92 | end |
93 | end |
94 | end |
onReadStream
DescriptionDefinitiononReadStream()Code
133 | function PlaceableWindTurbine:onReadStream(streamId, connection) |
134 | local spec = self.spec_windTurbine |
135 | if spec.headNode ~= nil then |
136 | spec.headRotation = NetworkUtil.readCompressedAngle(streamId) |
137 | end |
138 | end |
onWriteStream
DescriptionDefinitiononWriteStream()Code
142 | function PlaceableWindTurbine:onWriteStream(streamId, connection) |
143 | local spec = self.spec_windTurbine |
144 | if spec.headNode ~= nil then |
145 | NetworkUtil.writeCompressedAngle(streamId, spec.headRotation) |
146 | end |
147 | 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 |
18 | function PlaceableWindTurbine.prerequisitesPresent(specializations) |
19 | return SpecializationUtil.hasSpecialization(PlaceableIncomePerHour, specializations) |
20 | end |
registerEventListeners
DescriptionDefinitionregisterEventListeners()Code
39 | function PlaceableWindTurbine.registerEventListeners(placeableType) |
40 | SpecializationUtil.registerEventListener(placeableType, "onLoad", PlaceableWindTurbine) |
41 | SpecializationUtil.registerEventListener(placeableType, "onDelete", PlaceableWindTurbine) |
42 | SpecializationUtil.registerEventListener(placeableType, "onFinalizePlacement", PlaceableWindTurbine) |
43 | SpecializationUtil.registerEventListener(placeableType, "onReadStream", PlaceableWindTurbine) |
44 | SpecializationUtil.registerEventListener(placeableType, "onWriteStream", PlaceableWindTurbine) |
45 | end |
registerFunctions
DescriptionDefinitionregisterFunctions()Code
24 | function PlaceableWindTurbine.registerFunctions(placeableType) |
25 | SpecializationUtil.registerFunction(placeableType, "updateHeadRotation", PlaceableWindTurbine.updateHeadRotation) |
26 | SpecializationUtil.registerFunction(placeableType, "updateRotorRotSpeed", PlaceableWindTurbine.updateRotorRotSpeed) |
27 | SpecializationUtil.registerFunction(placeableType, "setWindValues", PlaceableWindTurbine.setWindValues) |
28 | SpecializationUtil.registerFunction(placeableType, "getWindTurbineLoad", PlaceableWindTurbine.getWindTurbineLoad) |
29 | end |
registerOverwrittenFunctions
DescriptionDefinitionregisterOverwrittenFunctions()Code
33 | function PlaceableWindTurbine.registerOverwrittenFunctions(placeableType) |
34 | SpecializationUtil.registerOverwrittenFunction(placeableType, "getIncomePerHourFactor", PlaceableWindTurbine.getIncomePerHourFactor) |
35 | end |
registerSavegameXMLPaths
DescriptionDefinitionregisterSavegameXMLPaths()Code
62 | function PlaceableWindTurbine.registerSavegameXMLPaths(schema, basePath) |
63 | schema:setXMLSpecializationType("WindTurbine") |
64 | schema:register(XMLValueType.ANGLE, basePath .. "#headRotation", "Current head rotation") |
65 | schema:setXMLSpecializationType() |
66 | end |
registerXMLPaths
DescriptionDefinitionregisterXMLPaths()Code
49 | function PlaceableWindTurbine.registerXMLPaths(schema, basePath) |
50 | schema:setXMLSpecializationType("WindTurbine") |
51 | schema:register(XMLValueType.NODE_INDEX, basePath .. ".windTurbine#headNode", "Head node") |
52 | schema:register(XMLValueType.BOOL, basePath .. ".windTurbine#headAdjustToWind", "Adjust head node to current wind direction") |
53 | schema:register(XMLValueType.NODE_INDEX, basePath .. ".windTurbine#rotationNode", "Rotor rotation node, rotated on z-axis") |
54 | schema:register(XMLValueType.FLOAT, basePath .. ".windTurbine#optimalWindSpeed", "Wind speed in m/s at which rotor reaches max rpm") |
55 | SoundManager.registerSampleXMLPaths(schema, basePath .. ".windTurbine.sounds", "idle") |
56 | AnimationManager.registerAnimationNodesXMLPaths(schema, basePath .. ".windTurbine.animationNodes") |
57 | schema:setXMLSpecializationType() |
58 | end |
saveToXMLFile
DescriptionDefinitionsaveToXMLFile()Code
161 | function PlaceableWindTurbine:saveToXMLFile(xmlFile, key, usedModNames) |
162 | local spec = self.spec_windTurbine |
163 | if spec.headNode ~= nil then |
164 | xmlFile:setValue(key.."#headRotation", spec.headRotation) |
165 | end |
166 | end |
setWindValues
DescriptionDefinitionsetWindValues()Code
198 | function PlaceableWindTurbine:setWindValues(windDirX, windDirZ, windVelocity, cirrusCloudSpeedFactor) |
199 | local spec = self.spec_windTurbine |
200 | if spec.headAdjustToWind and spec.headNode ~= nil then |
201 | spec.headRotation = MathUtil.getYRotationFromDirection(windDirX, windDirZ) |
202 | self:updateHeadRotation() |
203 | end |
204 | |
205 | self:updateRotorRotSpeed(windVelocity) |
206 | end |
updateHeadRotation
DescriptionDefinitionupdateHeadRotation()Code
170 | function PlaceableWindTurbine:updateHeadRotation() |
171 | local spec = self.spec_windTurbine |
172 | if spec.headNode ~= nil then |
173 | setWorldRotation(spec.headNode, 0, spec.headRotation, 0) |
174 | end |
175 | end |
updateRotorRotSpeed
DescriptionDefinitionupdateRotorRotSpeed()Code
179 | function PlaceableWindTurbine:updateRotorRotSpeed(windVelocity) |
180 | local spec = self.spec_windTurbine |
181 | spec.rotSpeedFactor = MathUtil.clamp(windVelocity / spec.rotorOptimalWindSpeed, 0, 1) |
182 | |
183 | if self.isClient then |
184 | if spec.rotSpeedFactor > 0 then |
185 | if not g_soundManager:getIsSamplePlaying(spec.samples.idle) then |
186 | g_soundManager:playSample(spec.samples.idle, 0) |
187 | end |
188 | else |
189 | if g_soundManager:getIsSamplePlaying(spec.samples.idle) then |
190 | g_soundManager:stopSample(spec.samples.idle) |
191 | end |
192 | end |
193 | end |
194 | end |