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
Wipers
DescriptionSpecialization for windscreen wipers managing animations and turn on/off during rainFunctions
- consoleSetWiperState
- getIsActiveForWipers
- initSpecialization
- loadWiperFromXML
- onFinishAnimation
- onLoad
- onUpdateTick
- prerequisitesPresent
- registerEventListeners
- registerFunctions
consoleSetWiperState
DescriptionDefinitionconsoleSetWiperState()Code
198 | function Wipers:consoleSetWiperState(state) |
199 | local usage = "Usage: gsWiperStateSet <state> (-1 = use state from weather; 0..n = force specific wiper state)" |
200 | if state == nil then |
201 | return "Error: No arguments given! " .. usage |
202 | end |
203 | |
204 | state = tonumber(state) |
205 | if state == nil then |
206 | return "Error: Argument is not a number! " .. usage |
207 | end |
208 | Wipers.forcedState = MathUtil.clamp(state, -1, 999) |
209 | |
210 | return(Wipers.forcedState == -1 and " Reset global wiper state, now using weather state") or string.format("Set global wiper states to %d.", Wipers.forcedState) |
211 | end |
getIsActiveForWipers
DescriptionDefinitiongetIsActiveForWipers()Code
192 | function Wipers:getIsActiveForWipers() |
193 | return true |
194 | end |
initSpecialization
DescriptionDefinitioninitSpecialization()Code
22 | function Wipers.initSpecialization() |
23 | local schema = Vehicle.xmlSchema |
24 | schema:setXMLSpecializationType("Wipers") |
25 | |
26 | schema:register(XMLValueType.STRING, "vehicle.wipers.wiper(?)#animName", "Animation name") |
27 | schema:register(XMLValueType.FLOAT, "vehicle.wipers.wiper(?).state(?)#animSpeed", "Animation speed") |
28 | schema:register(XMLValueType.FLOAT, "vehicle.wipers.wiper(?).state(?)#animPause", "Animation pause time (sec.)") |
29 | |
30 | schema:setXMLSpecializationType() |
31 | end |
loadWiperFromXML
DescriptionDefinitionloadWiperFromXML()Code
138 | function Wipers:loadWiperFromXML(xmlFile, key, wiper) |
139 | local animName = xmlFile:getValue(key .. "#animName") |
140 | if animName ~= nil then |
141 | if self:getAnimationExists(animName) then |
142 | wiper.animName = animName |
143 | wiper.animDuration = self:getAnimationDuration(animName) |
144 | wiper.states = {} |
145 | local j = 0 |
146 | while true do |
147 | local stateKey = string.format("%s.state(%d)", key, j) |
148 | if not xmlFile:hasProperty(stateKey) then |
149 | break |
150 | end |
151 | |
152 | local state = {} |
153 | state.animSpeed = xmlFile:getValue(stateKey .. "#animSpeed") |
154 | state.animPause = xmlFile:getValue(stateKey .. "#animPause") |
155 | if state.animSpeed ~= nil and state.animPause ~= nil then |
156 | state.animPause = state.animPause * 1000 |
157 | table.insert(wiper.states, state) |
158 | end |
159 | |
160 | j = j + 1 |
161 | end |
162 | else |
163 | Logging.xmlWarning(self.xmlFile, "Animation '%s' not defined for wiper '%s'!", animName, key) |
164 | return false |
165 | end |
166 | else |
167 | Logging.xmlWarning(self.xmlFile, "Missing animation for wiper '%s'!", key) |
168 | return false |
169 | end |
170 | |
171 | local numStates = #wiper.states |
172 | if numStates > 0 then |
173 | local stepSize = 1.0 / numStates |
174 | local curMax = stepSize |
175 | |
176 | for _,state in ipairs(wiper.states) do |
177 | state.maxRainValue = curMax |
178 | curMax = curMax + stepSize |
179 | end |
180 | |
181 | wiper.nextStartTime = nil |
182 | else |
183 | Logging.xmlWarning(self.xmlFile, "No states defined for wiper '%s'!", key) |
184 | return false |
185 | end |
186 | |
187 | return true |
188 | end |
onFinishAnimation
DescriptionDefinitiononFinishAnimation()Code
126 | function Wipers:onFinishAnimation(name) |
127 | local spec = self.spec_wipers |
128 | for _, wiper in pairs(spec.wipers) do |
129 | if wiper.animName == name and self:getAnimationTime(wiper.animName) == 1 then |
130 | local lastValidState = wiper.states[wiper.lastValidState] |
131 | self:playAnimation(wiper.animName, -lastValidState.animSpeed, 1, true) |
132 | end |
133 | end |
134 | end |
onLoad
DescriptionDefinitiononLoad()Code
50 | function Wipers:onLoad(savegame) |
51 | local spec = self.spec_wipers |
52 | |
53 | spec.wipers = {} |
54 | |
55 | local i = 0 |
56 | while true do |
57 | local key = string.format("vehicle.wipers.wiper(%d)", i) |
58 | if not self.xmlFile:hasProperty(key) then |
59 | break |
60 | end |
61 | |
62 | local wiper = {} |
63 | if self:loadWiperFromXML(self.xmlFile, key, wiper) then |
64 | wiper.lastValidState = 1 |
65 | table.insert(spec.wipers, wiper) |
66 | end |
67 | |
68 | i = i + 1 |
69 | end |
70 | |
71 | spec.hasWipers = #spec.wipers > 0 |
72 | spec.lastRainScale = 0.0 |
73 | |
74 | if not spec.hasWipers then |
75 | SpecializationUtil.removeEventListener(self, "onUpdateTick", Wipers) |
76 | end |
77 | end |
onUpdateTick
DescriptionDefinitiononUpdateTick()Code
81 | function Wipers:onUpdateTick(dt, isActiveForInput, isActiveForInputIgnoreSelection, isSelected) |
82 | local spec = self.spec_wipers |
83 | |
84 | if self:getIsControlled() then |
85 | spec.lastRainScale = g_currentMission.environment.weather:getRainFallScale() |
86 | |
87 | for _, wiper in pairs(spec.wipers) do |
88 | local stateIdToUse = 0 |
89 | if self:getIsActiveForWipers() then |
90 | if spec.lastRainScale > 0.01 then -- small etha for the long tail |
91 | for stateIndex,state in ipairs(wiper.states) do |
92 | if spec.lastRainScale <= state.maxRainValue then |
93 | stateIdToUse = stateIndex |
94 | break |
95 | end |
96 | end |
97 | end |
98 | end |
99 | |
100 | if Wipers.forcedState ~= -1 then |
101 | stateIdToUse = MathUtil.clamp(Wipers.forcedState, 0, #wiper.states) |
102 | end |
103 | |
104 | if stateIdToUse > 0 then |
105 | local currentState = wiper.states[stateIdToUse] |
106 | |
107 | if wiper.nextStartTime == nil or wiper.nextStartTime < g_currentMission.time then |
108 | if not self:getIsAnimationPlaying(wiper.animName) then |
109 | self:playAnimation(wiper.animName, currentState.animSpeed, 0, true) |
110 | wiper.nextStartTime = nil |
111 | end |
112 | end |
113 | |
114 | if wiper.nextStartTime == nil then |
115 | wiper.nextStartTime = g_currentMission.time + (wiper.animDuration / currentState.animSpeed) * 2 + currentState.animPause |
116 | end |
117 | |
118 | wiper.lastValidState = stateIdToUse |
119 | end |
120 | end |
121 | end |
122 | end |
prerequisitesPresent
DescriptionDefinitionprerequisitesPresent()Code
16 | function Wipers.prerequisitesPresent(specializations) |
17 | return SpecializationUtil.hasSpecialization(Enterable, specializations) and SpecializationUtil.hasSpecialization(AnimatedVehicle, specializations) |
18 | end |
registerEventListeners
DescriptionDefinitionregisterEventListeners()Code
42 | function Wipers.registerEventListeners(vehicleType) |
43 | SpecializationUtil.registerEventListener(vehicleType, "onLoad", Wipers) |
44 | SpecializationUtil.registerEventListener(vehicleType, "onUpdateTick", Wipers) |
45 | SpecializationUtil.registerEventListener(vehicleType, "onFinishAnimation", Wipers) |
46 | end |
registerFunctions
DescriptionDefinitionregisterFunctions()Code
35 | function Wipers.registerFunctions(vehicleType) |
36 | SpecializationUtil.registerFunction(vehicleType, "loadWiperFromXML", Wipers.loadWiperFromXML) |
37 | SpecializationUtil.registerFunction(vehicleType, "getIsActiveForWipers", Wipers.getIsActiveForWipers) |
38 | end |