Script v1.7.1.0
- AI
- Animals
- Contracts
- Debug
- Economy
- Effects
- Events
- Farms
- GUI
- Handtools
- I3d
- Materials
- Misc
- Objects
- Placeables
- Player
- Shop
- Sounds
- Specializations
- AIConveyorBelt
- AIImplement
- AIVehicle
- AnimatedVehicle
- ArticulatedAxis
- Attachable
- AttacherJointControl
- AttacherJoints
- BaleGrab
- BaleLoader
- Baler
- BaleWrapper
- BaseMaterial
- BunkerSiloCompacter
- BunkerSiloInteractor
- BuyableBale
- CCTDrivable
- Combine
- ConnectionHoses
- ConveyorBelt
- Cover
- CrabSteering
- Crawlers
- Cultivator
- Cutter
- Cylindered
- CylinderedFoldable
- Dashboard
- Dischargeable
- Drivable
- DynamicallyLoadedParts
- DynamicMountAttacher
- Enterable
- FertilizingCultivator
- FertilizingSowingMachine
- FillTriggerVehicle
- FillUnit
- FillVolume
- Foldable
- FoliageBending
- ForageWagon
- FrontloaderAttacher
- FruitPreparer
- GroundAdjustedNodes
- GroundReference
- Honk
- HookLiftContainer
- HookLiftTrailer
- IKChains
- JigglingParts
- Leveler
- Lights
- LivestockTrailer
- Locomotive
- LogGrab
- ManureBarrel
- MixerWagon
- Motorized
- Mountable
- Mower
- Pickup
- Pipe
- Plow
- PowerConsumer
- PowerTakeOffs
- RandomlyMovingParts
- ReceivingHopper
- ReverseDriving
- Rideable
- RidgeMarker
- Roller
- Ropes
- SemiTrailerFront
- Shovel
- SlopeCompensation
- SmartAttach
- SowingMachine
- SpeedRotatingParts
- SplineVehicle
- Sprayer
- StrawBlower
- StumpCutter
- Suspensions
- Tedder
- TensionBeltObject
- TensionBelts
- TipOccluder
- Trailer
- TreePlanter
- TreeSaw
- TurnOnVehicle
- Washable
- WaterTrailer
- Wearable
- Weeder
- Wheels
- Windrower
- Wipers
- WoodCrusher
- WoodHarvester
- WorkArea
- WorkMode
- WorkParticles
- Triggers
- Utils
- Vehicles
- Weather
Engine v1.7.1.0
- AI
- Animation
- Camera
- Entity
- Fillplanes
- General
- I3D
- Input
- Lighting
- Math
- Network
- Node
- Overlays
- Particle System
- Physics
- Rendering
- Scenegraph
- Shape
- Sound
- Spline
- String
- Terrain Detail
- Text Rendering
- Tire Track
- XML
- general
Foundation Reference
Wipers
DescriptionSpecialization for windscreen wipers managing animations and turn on/off during rainFunctions
- getIsActiveForWipers
- loadWiperFromXML
- onLoad
- onUpdateTick
- prerequisitesPresent
- registerEventListeners
- registerFunctions
getIsActiveForWipers
DescriptionDefinitiongetIsActiveForWipers()Code
163 | function Wipers:getIsActiveForWipers() |
164 | return true |
165 | end |
loadWiperFromXML
DescriptionDefinitionloadWiperFromXML()Code
109 | function Wipers:loadWiperFromXML(xmlFile, key, wiper) |
110 | local animName = getXMLString(xmlFile, key .. "#animName") |
111 | if animName ~= nil then |
112 | if self:getAnimationExists(animName) then |
113 | wiper.animName = animName |
114 | wiper.animDuration = self:getAnimationDuration(animName) |
115 | wiper.states = {} |
116 | local j = 0 |
117 | while true do |
118 | local stateKey = string.format("%s.state(%d)", key, j) |
119 | if not hasXMLProperty(xmlFile, stateKey) then |
120 | break |
121 | end |
122 | |
123 | local state = {} |
124 | state.animSpeed = getXMLFloat(xmlFile, stateKey .. "#animSpeed") |
125 | state.animPause = getXMLFloat(xmlFile, stateKey .. "#animPause") |
126 | if state.animSpeed ~= nil and state.animPause ~= nil then |
127 | state.animPause = state.animPause * 1000 |
128 | table.insert(wiper.states, state) |
129 | end |
130 | |
131 | j = j + 1 |
132 | end |
133 | else |
134 | g_logManager:xmlWarning(self.configFileName, "Animation '%s' not defined for wiper '%s'!", animName, key) |
135 | return false |
136 | end |
137 | else |
138 | g_logManager:xmlWarning(self.configFileName, "Missing animation for wiper '%s'!", key) |
139 | return false |
140 | end |
141 | |
142 | local numStates = #wiper.states |
143 | if numStates > 0 then |
144 | local stepSize = 1.0 / numStates |
145 | local curMax = stepSize |
146 | |
147 | for _,state in ipairs(wiper.states) do |
148 | state.maxRainValue = curMax |
149 | curMax = curMax + stepSize |
150 | end |
151 | |
152 | wiper.nextStartTime = nil |
153 | else |
154 | g_logManager:xmlWarning(self.configFileName, "No states defined for wiper '%s'!", key) |
155 | return false |
156 | end |
157 | |
158 | return true |
159 | end |
onLoad
DescriptionDefinitiononLoad()Code
36 | function Wipers:onLoad(savegame) |
37 | local spec = self.spec_wipers |
38 | |
39 | spec.wipers = {} |
40 | |
41 | local i = 0 |
42 | while true do |
43 | local key = string.format("vehicle.wipers.wiper(%d)", i) |
44 | if not hasXMLProperty(self.xmlFile, key) then |
45 | break |
46 | end |
47 | |
48 | local wiper = {} |
49 | if self:loadWiperFromXML(self.xmlFile, key, wiper) then |
50 | table.insert(spec.wipers, wiper) |
51 | end |
52 | |
53 | i = i + 1 |
54 | end |
55 | |
56 | spec.hasWipers = #spec.wipers > 0 |
57 | spec.lastRainScale = 0.0 |
58 | end |
onUpdateTick
DescriptionDefinitiononUpdateTick()Code
62 | function Wipers:onUpdateTick(dt, isActiveForInput, isActiveForInputIgnoreSelection, isSelected) |
63 | local spec = self.spec_wipers |
64 | |
65 | if spec.hasWipers and self:getIsControlled() then |
66 | spec.lastRainScale = g_currentMission.environment.weather:getRainFallScale() |
67 | |
68 | for _, wiper in pairs(spec.wipers) do |
69 | local stateIdToUse = 0 |
70 | if self:getIsActiveForWipers() then |
71 | if spec.lastRainScale > 0 then |
72 | for stateIndex,state in ipairs(wiper.states) do |
73 | if spec.lastRainScale <= state.maxRainValue then |
74 | stateIdToUse = stateIndex |
75 | break |
76 | end |
77 | end |
78 | end |
79 | end |
80 | |
81 | if Wipers.forcedState ~= 0 then |
82 | stateIdToUse = MathUtil.clamp(Wipers.forcedState, 1, #wiper.states) |
83 | end |
84 | |
85 | if stateIdToUse > 0 then |
86 | local currentState = wiper.states[stateIdToUse] |
87 | |
88 | if self:getAnimationTime(wiper.animName) == 1 then |
89 | self:playAnimation(wiper.animName, -currentState.animSpeed, 1, true) |
90 | end |
91 | |
92 | if wiper.nextStartTime == nil or wiper.nextStartTime < g_currentMission.time then |
93 | if not self:getIsAnimationPlaying(wiper.animName) then |
94 | self:playAnimation(wiper.animName, currentState.animSpeed, 0, true) |
95 | wiper.nextStartTime = nil |
96 | end |
97 | end |
98 | |
99 | if wiper.nextStartTime == nil then |
100 | wiper.nextStartTime = g_currentMission.time + (wiper.animDuration / currentState.animSpeed) + currentState.animPause |
101 | end |
102 | end |
103 | end |
104 | end |
105 | 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
29 | function Wipers.registerEventListeners(vehicleType) |
30 | SpecializationUtil.registerEventListener(vehicleType, "onLoad", Wipers) |
31 | SpecializationUtil.registerEventListener(vehicleType, "onUpdateTick", Wipers) |
32 | end |
registerFunctions
DescriptionDefinitionregisterFunctions()Code
22 | function Wipers.registerFunctions(vehicleType) |
23 | SpecializationUtil.registerFunction(vehicleType, "loadWiperFromXML", Wipers.loadWiperFromXML) |
24 | SpecializationUtil.registerFunction(vehicleType, "getIsActiveForWipers", Wipers.getIsActiveForWipers) |
25 | end |