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
PlaceableChargingStation
DescriptionSpecialization for placeablesFunctions
getChargeState
DescriptionDefinitiongetChargeState()Code
101 | function PlaceableChargingStation:getChargeState() |
102 | local spec = self.spec_chargingStation |
103 | if spec.loadTrigger ~= nil then |
104 | local index = next(spec.loadTrigger.fillableObjects) |
105 | if index ~= nil then |
106 | local vehicle = spec.loadTrigger.fillableObjects[index].object |
107 | if vehicle.getConsumerFillUnitIndex ~= nil then |
108 | local fillUnitIndex = vehicle:getConsumerFillUnitIndex(FillType.ELECTRICCHARGE) |
109 | if fillUnitIndex ~= nil then |
110 | return vehicle:getFillUnitFillLevel(fillUnitIndex), vehicle:getFillUnitCapacity(fillUnitIndex) |
111 | end |
112 | end |
113 | end |
114 | end |
115 | |
116 | return 0, 1 |
117 | end |
onLoad
DescriptionCalled on loadingDefinition
onLoad(table savegame)Arguments
table | savegame | savegame |
57 | function PlaceableChargingStation:onLoad(savegame) |
58 | local spec = self.spec_chargingStation |
59 | |
60 | spec.chargeIndicatorIntensity = self.xmlFile:getValue("placeable.chargingStation.chargeIndicator#intensity", 20) |
61 | spec.chargeIndicatorBlinkSpeed = self.xmlFile:getValue("placeable.chargingStation.chargeIndicator#blinkSpeed", 5) |
62 | |
63 | spec.chargeIndicatorNode = self.xmlFile:getValue("placeable.chargingStation.chargeIndicator#node", nil, self.components, self.i3dMappings) |
64 | if spec.chargeIndicatorNode ~= nil then |
65 | setShaderParameter(spec.chargeIndicatorNode, "lightControl", spec.chargeIndicatorIntensity, 0, 0, 0, false) |
66 | setShaderParameter(spec.chargeIndicatorNode, "emitColor", 1, 1, 0, 0, false) |
67 | end |
68 | |
69 | spec.chargeIndicatorLight = self.xmlFile:getValue("placeable.chargingStation.chargeIndicator#light", nil, self.components, self.i3dMappings) |
70 | if spec.chargeIndicatorLight then |
71 | setLightColor(spec.chargeIndicatorLight, 0, 0, 0) |
72 | end |
73 | |
74 | spec.chargeIndicatorColorFull = self.xmlFile:getValue("placeable.chargingStation.chargeIndicator#colorFull", "0 1 0 1", true) |
75 | spec.chargeIndicatorColorEmpty = self.xmlFile:getValue("placeable.chargingStation.chargeIndicator#colorEmpty", "1 1 0 1", true) |
76 | spec.chargeIndicatorLightColor = spec.chargeIndicatorColorFull |
77 | |
78 | spec.interactionRadius = self.xmlFile:getValue("placeable.chargingStation#interactionRadius", 5) |
79 | |
80 | spec.loadTrigger = nil |
81 | |
82 | spec.buyingStation = self:getBuyingStation() |
83 | if spec.buyingStation ~= nil then |
84 | for j=1, #spec.buyingStation.loadTriggers do |
85 | local loadTrigger = spec.buyingStation.loadTriggers[j] |
86 | |
87 | spec.loadTrigger = loadTrigger |
88 | |
89 | spec.fillSample = g_soundManager:loadSampleFromXML(self.xmlFile, "placeable.chargingStation.sounds", "fill", self.baseDirectory, self.components, 0, AudioGroup.ENVIRONMENT, self.i3dMappings, nil) |
90 | if spec.fillSample ~= nil then |
91 | if loadTrigger.samples.load == nil then |
92 | loadTrigger.samples.load = spec.fillSample |
93 | end |
94 | end |
95 | end |
96 | end |
97 | end |
onUpdate
DescriptionUpdateDefinition
onUpdate(float dt)Arguments
float | dt | time since last call in ms |
122 | function PlaceableChargingStation:onUpdate(dt) |
123 | local spec = self.spec_chargingStation |
124 | |
125 | if spec.loadTrigger ~= nil then |
126 | local isActive = next(spec.loadTrigger.fillableObjects) ~= nil |
127 | |
128 | if spec.chargeIndicatorNode ~= nil then |
129 | if isActive then |
130 | local color = spec.chargeIndicatorColorEmpty |
131 | local fillLevel, capacity = self:getChargeState() |
132 | if fillLevel / capacity > 0.95 then |
133 | color = spec.chargeIndicatorColorFull |
134 | end |
135 | |
136 | setShaderParameter(spec.chargeIndicatorNode, "colorScale", color[1], color[2], color[3], color[4], false) |
137 | spec.chargeIndicatorLightColor = color |
138 | end |
139 | |
140 | local blinkSpeed = spec.loadTrigger.isLoading and spec.chargeIndicatorBlinkSpeed or 0 |
141 | setShaderParameter(spec.chargeIndicatorNode, "blinkSpeed", blinkSpeed, 0, 0, 0, false) |
142 | setShaderParameter(spec.chargeIndicatorNode, "lightControl", isActive and spec.chargeIndicatorIntensity or 0, 0, 0, 0, false) |
143 | |
144 | if spec.chargeIndicatorLight ~= nil then |
145 | local alpha = 0 |
146 | if isActive then |
147 | local x, y, z, _ = getShaderParameter(spec.chargeIndicatorNode, "blinkOffset") |
148 | alpha = MathUtil.clamp(math.cos(blinkSpeed * z * (getShaderTimeSec() - y) + 2 * math.pi * x) + 0.2, 0, 1) |
149 | end |
150 | |
151 | setLightColor(spec.chargeIndicatorLight, spec.chargeIndicatorLightColor[1]*alpha, spec.chargeIndicatorLightColor[2]*alpha, spec.chargeIndicatorLightColor[3]*alpha) |
152 | end |
153 | end |
154 | |
155 | if spec.loadTrigger.isLoading then |
156 | local allowDisplay = false |
157 | if g_currentMission.controlPlayer and g_currentMission.player ~= nil then |
158 | local distance = calcDistanceFrom(g_currentMission.player.rootNode, self.rootNode) |
159 | if distance < spec.interactionRadius then |
160 | allowDisplay = true |
161 | end |
162 | else |
163 | if g_currentMission.controlledVehicle ~= nil then |
164 | for _, object in pairs(spec.loadTrigger.fillableObjects) do |
165 | if object.object == g_currentMission.controlledVehicle then |
166 | allowDisplay = true |
167 | end |
168 | end |
169 | end |
170 | end |
171 | |
172 | if allowDisplay then |
173 | local fillLevel, capacity = self:getChargeState() |
174 | local fillLevelToFill = capacity - fillLevel |
175 | local literPerSecond = spec.loadTrigger.fillLitersPerMS * 1000 |
176 | local seconds = fillLevelToFill / literPerSecond |
177 | if seconds >= 1 then |
178 | local minutes = math.floor(seconds / 60) |
179 | seconds = seconds - (minutes * 60) |
180 | |
181 | g_currentMission:addExtraPrintText(string.format(g_i18n:getText("info_chargeTime"), minutes, seconds, fillLevel / capacity * 100)) |
182 | end |
183 | end |
184 | end |
185 | end |
186 | |
187 | self:raiseActive() |
188 | 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 PlaceableChargingStation.prerequisitesPresent(specializations) |
19 | return SpecializationUtil.hasSpecialization(PlaceableBuyingStation, specializations) |
20 | end |
registerFunctions
DescriptionDefinitionregisterFunctions()Code
24 | function PlaceableChargingStation.registerFunctions(placeableType) |
25 | SpecializationUtil.registerFunction(placeableType, "getChargeState", PlaceableChargingStation.getChargeState) |
26 | end |