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
PlaceableSolarPanels
DescriptionSpecialization for placeablesFunctions
- getIncomePerHourFactor
- getNeedHourChanged
- loadFromXMLFile
- onFinalizePlacement
- onHourChanged
- onLoad
- onReadStream
- onUpdate
- onWriteStream
- prerequisitesPresent
- registerEventListeners
- registerFunctions
- registerOverwrittenFunctions
- registerSavegameXMLPaths
- registerXMLPaths
- saveToXMLFile
- updateHeadRotation
getIncomePerHourFactor
DescriptionDefinitiongetIncomePerHourFactor()Code
178 | function PlaceableSolarPanels:getIncomePerHourFactor(superFunc) |
179 | local environment = g_currentMission.environment |
180 | if not environment.isSunOn then |
181 | return 0 |
182 | end |
183 | |
184 | local factor = superFunc(self) |
185 | if environment.currentSeason == Environment.SEASON.WINTER then |
186 | factor = factor * 0.75 |
187 | end |
188 | |
189 | if environment.weather:getIsRaining() then |
190 | factor = factor * 0.1 |
191 | end |
192 | |
193 | return factor |
194 | end |
getNeedHourChanged
DescriptionDefinitiongetNeedHourChanged()Code
198 | function PlaceableSolarPanels:getNeedHourChanged(superFunc) |
199 | return true |
200 | end |
loadFromXMLFile
DescriptionDefinitionloadFromXMLFile()Code
92 | function PlaceableSolarPanels:loadFromXMLFile(xmlFile, key) |
93 | local spec = self.spec_solarPanels |
94 | |
95 | local headRotationRandom = xmlFile:getValue(key.."#headRotationRandom") |
96 | if headRotationRandom == nil then |
97 | spec.headRotationRandom = headRotationRandom |
98 | end |
99 | end |
onFinalizePlacement
DescriptionDefinitiononFinalizePlacement()Code
86 | function PlaceableSolarPanels:onFinalizePlacement() |
87 | self:updateHeadRotation() |
88 | end |
onHourChanged
DescriptionDefinitiononHourChanged()Code
152 | function PlaceableSolarPanels:onHourChanged() |
153 | self:updateHeadRotation() |
154 | end |
onLoad
DescriptionDefinitiononLoad()Code
66 | function PlaceableSolarPanels:onLoad(savegame) |
67 | local spec = self.spec_solarPanels |
68 | local xmlFile = self.xmlFile |
69 | |
70 | |
71 | spec.headNode = xmlFile:getValue("placeable.solarPanels#headNode", nil, self.components, self.i3dMappings) |
72 | spec.randomHeadOffsetRange = xmlFile:getValue("placeable.solarPanels#randomHeadOffsetRange", 15) |
73 | spec.rotationSpeed = xmlFile:getValue("placeable.solarPanels#rotationSpeed", 5) / 1000 |
74 | |
75 | if spec.headNode ~= nil then |
76 | local rotVariation = spec.randomHeadOffsetRange * 0.5 |
77 | spec.headRotationRandom = math.random(-1, 1) * rotVariation -- default random -7.5 - 7.5 degrees offset |
78 | |
79 | spec.currentRotation = spec.headRotationRandom |
80 | spec.targetRotation = spec.headRotationRandom |
81 | end |
82 | end |
onReadStream
DescriptionDefinitiononReadStream()Code
112 | function PlaceableSolarPanels:onReadStream(streamId, connection) |
113 | local spec = self.spec_solarPanels |
114 | if spec.headNode ~= nil then |
115 | spec.headRotationRandom = NetworkUtil.readCompressedAngle(streamId) |
116 | end |
117 | end |
onUpdate
DescriptionDefinitiononUpdate()Code
130 | function PlaceableSolarPanels:onUpdate(dt) |
131 | local spec = self.spec_solarPanels |
132 | if spec.targetRotation ~= spec.currentRotation then |
133 | local limitFunc = math.min |
134 | local direction = 1 |
135 | if spec.targetRotation < spec.currentRotation then |
136 | limitFunc = math.max |
137 | direction = -1 |
138 | end |
139 | |
140 | spec.currentRotation = limitFunc(spec.currentRotation + spec.rotationSpeed * dt * direction, spec.targetRotation) |
141 | local dx,_,dz = worldDirectionToLocal(getParent(spec.headNode), math.sin(spec.currentRotation), 0, math.cos(spec.currentRotation)) |
142 | setDirection(spec.headNode, dx, 0, dz, 0, 1, 0) |
143 | |
144 | if spec.targetRotation ~= spec.currentRotation then |
145 | self:raiseActive() |
146 | end |
147 | end |
148 | end |
onWriteStream
DescriptionDefinitiononWriteStream()Code
121 | function PlaceableSolarPanels:onWriteStream(streamId, connection) |
122 | local spec = self.spec_solarPanels |
123 | if spec.headNode ~= nil then |
124 | NetworkUtil.writeCompressedAngle(streamId, spec.headRotationRandom) |
125 | end |
126 | 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 PlaceableSolarPanels.prerequisitesPresent(specializations) |
19 | return SpecializationUtil.hasSpecialization(PlaceableIncomePerHour, specializations) |
20 | end |
registerEventListeners
DescriptionDefinitionregisterEventListeners()Code
37 | function PlaceableSolarPanels.registerEventListeners(placeableType) |
38 | SpecializationUtil.registerEventListener(placeableType, "onLoad", PlaceableSolarPanels) |
39 | SpecializationUtil.registerEventListener(placeableType, "onFinalizePlacement", PlaceableSolarPanels) |
40 | SpecializationUtil.registerEventListener(placeableType, "onReadStream", PlaceableSolarPanels) |
41 | SpecializationUtil.registerEventListener(placeableType, "onWriteStream", PlaceableSolarPanels) |
42 | SpecializationUtil.registerEventListener(placeableType, "onHourChanged", PlaceableSolarPanels) |
43 | SpecializationUtil.registerEventListener(placeableType, "onUpdate", PlaceableSolarPanels) |
44 | end |
registerFunctions
DescriptionDefinitionregisterFunctions()Code
31 | function PlaceableSolarPanels.registerFunctions(placeableType) |
32 | SpecializationUtil.registerFunction(placeableType, "updateHeadRotation", PlaceableSolarPanels.updateHeadRotation) |
33 | end |
registerOverwrittenFunctions
DescriptionDefinitionregisterOverwrittenFunctions()Code
24 | function PlaceableSolarPanels.registerOverwrittenFunctions(placeableType) |
25 | SpecializationUtil.registerOverwrittenFunction(placeableType, "getIncomePerHourFactor", PlaceableSolarPanels.getIncomePerHourFactor) |
26 | SpecializationUtil.registerOverwrittenFunction(placeableType, "getNeedHourChanged", PlaceableSolarPanels.getNeedHourChanged) |
27 | end |
registerSavegameXMLPaths
DescriptionDefinitionregisterSavegameXMLPaths()Code
58 | function PlaceableSolarPanels.registerSavegameXMLPaths(schema, basePath) |
59 | schema:setXMLSpecializationType("SolarPanels") |
60 | schema:register(XMLValueType.FLOAT, basePath .. "#headRotationRandom", "Head random rotation") |
61 | schema:setXMLSpecializationType() |
62 | end |
registerXMLPaths
DescriptionDefinitionregisterXMLPaths()Code
48 | function PlaceableSolarPanels.registerXMLPaths(schema, basePath) |
49 | schema:setXMLSpecializationType("SolarPanels") |
50 | schema:register(XMLValueType.NODE_INDEX, basePath .. ".solarPanels#headNode", "Head Node") |
51 | schema:register(XMLValueType.ANGLE, basePath .. ".solarPanels#randomHeadOffsetRange", "Range of random offset", 15) |
52 | schema:register(XMLValueType.ANGLE, basePath .. ".solarPanels#rotationSpeed", "Rotation Speed (deg/sec)", 5) |
53 | schema:setXMLSpecializationType() |
54 | end |
saveToXMLFile
DescriptionDefinitionsaveToXMLFile()Code
103 | function PlaceableSolarPanels:saveToXMLFile(xmlFile, key, usedModNames) |
104 | local spec = self.spec_solarPanels |
105 | if spec.headNode ~= nil then |
106 | xmlFile:setValue(key .. "#headRotationRandom", spec.headRotationRandom) |
107 | end |
108 | end |
updateHeadRotation
DescriptionDefinitionupdateHeadRotation()Code
158 | function PlaceableSolarPanels:updateHeadRotation() |
159 | local spec = self.spec_solarPanels |
160 | if spec.headNode ~= nil and g_currentMission ~= nil and g_currentMission.environment ~= nil then |
161 | |
162 | local sunLight = g_currentMission.environment.lighting.sunLightId |
163 | if sunLight ~= nil then |
164 | local dx, _, dz = localDirectionToWorld(sunLight, 0, 0, 1) |
165 | local headRotation = math.atan2(dx, dz) |
166 | if math.abs(dx) > 0.3 then |
167 | headRotation = headRotation + spec.headRotationRandom |
168 | |
169 | spec.targetRotation = headRotation |
170 | self:raiseActive() |
171 | end |
172 | end |
173 | end |
174 | end |