Script v1.4.4.0
- Handtools
- Events
- Objects
- Placeables
- Triggers
- Utils
- Vehicles
- Specializations
- AIVehicle
- AnimatedVehicle
- ArticulatedAxis
- Attachable
- AttacherJointControl
- AttacherJoints
- BaleGrab
- BaleLoader
- Baler
- BaleWrapper
- BuiltInCutterTrailer
- BunkerSiloCompacter
- Combine
- ConveyorBelt
- Cover
- CrabSteering
- Crawler
- Cultivator
- Cutter
- Cylindered
- Drivable
- DynamicMountAttacher
- Fillable
- FillActivatable
- FillVolume
- Foldable
- ForageWagon
- FrontloaderAttacher
- FruitPreparer
- FuelTrailer
- Honk
- HookLiftContainer
- HookLiftTrailer
- Leveler
- Lights
- LivestockTrailer
- ManureBarrel
- ManureSpreader
- MixerWagon
- Motorized
- Mountable
- Mower
- NonTabbable
- Overloading
- Pickup
- Pipe
- Plough
- PowerConsumer
- RandomlyMovingParts
- ReceivingHopper
- ReverseDriving
- RidgeMarker
- Roller
- Ropes
- RotorSpreader
- SemiTrailerFront
- Shovel
- SowingMachine
- SpeedRotatingParts
- Sprayer
- Steerable
- StrawBlower
- StumpCutter
- Tedder
- TensionBelts
- Trailer
- TreePlanter
- TreePlanterActivatable
- TreeSaw
- TurnOnVehicle
- Washable
- WaterTrailer
- Weeder
- WheelRotations
- Windrower
- WoodCrusher
- WoodHarvester
- WorkArea
- WorkParticles
Engine v7.0.0.2
- General
- Entity
- Node
- Scenegraph
- Lighting
- Camera
- Shape
- Particle System
- Physics
- Spline
- Animation
- Overlays
- Sound
- Input
- XML
- Network
- Callbacks
- Text Rendering
- Terrain Detail
- Tire Track
- Editor
- Rendering
- String
- Math
- I3D
- Fillplanes
Foundation Reference
Washable
DescriptionThis is the specialization for all washable vehiclesFunctions
- preLoad
- load
- postLoad
- readStream
- writeStream
- readUpdateStream
- writeUpdateStream
- delete
- updateTick
- setDirtAmount
- addWashableNode
- removeWashableNode
- getDirtAmount
- getDirtMultiplier
- getSaveAttributesAndNodes
- addWashingTrigger
- removeWashingTrigger
- getIntervalMultiplier
preLoad
DescriptionCalled before loadingDefinition
preLoad(table savegame)Arguments
table | savegame | savegame |
21 | function Washable:preLoad(savegame) |
22 | self.setDirtAmount = Washable.setDirtAmount; |
23 | self.getDirtAmount = Washable.getDirtAmount; |
24 | self.getDirtMultiplier = Washable.getDirtMultiplier; |
25 | self.addWashingTrigger = Washable.addWashingTrigger; |
26 | self.removeWashingTrigger = Washable.removeWashingTrigger; |
27 | self.addWashableNode = Washable.addWashableNode; |
28 | self.removeWashableNode = Washable.removeWashableNode; |
29 | end |
load
DescriptionCalled on loadingDefinition
load(table savegame)Arguments
table | savegame | savegame |
34 | function Washable:load(savegame) |
35 | |
36 | self.sentDirtAmount = 0; |
37 | self.washableDirtyFlag = self:getNextDirtyFlag(); |
38 | self.dirtAmount = 0; |
39 | |
40 | if hasXMLProperty(self.xmlFile, "vehicle.washable#dirtDuration") then |
41 | self.washableNodes = {}; |
42 | self.dirtDuration = Utils.getNoNil(getXMLFloat(self.xmlFile, "vehicle.washable#dirtDuration"), 1) * 60 * 1000; |
43 | if self.dirtDuration ~= 0 then |
44 | self.dirtDuration = 1 / self.dirtDuration; -- dirtDuration == 0 disables dirt effect |
45 | end |
46 | self.washDuration = math.max(Utils.getNoNil(getXMLFloat(self.xmlFile, "vehicle.washable#washDuration"), 1) * 60 * 1000, 0.00001); -- washDuration == 0 washes vehicle immediately |
47 | self.workMultiplier = Utils.getNoNil(getXMLFloat(self.xmlFile, "vehicle.washable#workMultiplier"), 1); |
48 | self.fieldMultiplier = Utils.getNoNil(getXMLFloat(self.xmlFile, "vehicle.washable#fieldMultiplier"), 2); |
49 | end |
50 | |
51 | self.washingTriggers = {}; |
52 | end |
postLoad
DescriptionCalled after loadingDefinition
postLoad(table savegame)Arguments
table | savegame | savegame |
57 | function Washable:postLoad(savegame) |
58 | -- getting als washable nodes in postLoad to make sure also linked nodes are washable |
59 | if self.washableNodes ~= nil then |
60 | for _, comp in pairs(self.components) do |
61 | self:addWashableNode(comp.node); |
62 | end |
63 | |
64 | if savegame ~= nil and Washable.getIntervalMultiplier() ~= 0 then |
65 | self:setDirtAmount(Utils.getNoNil(getXMLFloat(savegame.xmlFile, savegame.key.."#dirtAmount"), 0), true); |
66 | else |
67 | self:setDirtAmount(0, true); |
68 | end |
69 | end |
70 | end |
readStream
DescriptionCalled on client side on joinDefinition
readStream(integer streamId, integer connection)Arguments
integer | streamId | streamId |
integer | connection | connection |
76 | function Washable:readStream(streamId, connection) |
77 | if self.washableNodes ~= nil then |
78 | local dirtAmount = streamReadInt8(streamId) / 100; |
79 | self.sentDirtAmount = dirtAmount; |
80 | self:setDirtAmount(dirtAmount, true); |
81 | end |
82 | end |
writeStream
DescriptionCalled on server side on joinDefinition
writeStream(integer streamId, integer connection)Arguments
integer | streamId | streamId |
integer | connection | connection |
88 | function Washable:writeStream(streamId, connection) |
89 | if self.washableNodes ~= nil then |
90 | streamWriteInt8(streamId, math.floor(self:getDirtAmount()*100)); |
91 | end |
92 | end |
readUpdateStream
DescriptionCalled on on updateDefinition
readUpdateStream(integer streamId, integer timestamp, table connection)Arguments
integer | streamId | stream ID |
integer | timestamp | timestamp |
table | connection | connection |
99 | function Washable:readUpdateStream(streamId, timestamp, connection) |
100 | if connection:getIsServer() and self.washableNodes ~= nil then |
101 | local dirty = streamReadBool(streamId); |
102 | if dirty then |
103 | local dirtAmount = streamReadInt8(streamId) / 100; |
104 | self:setDirtAmount(dirtAmount, true); |
105 | end |
106 | end |
107 | end |
writeUpdateStream
DescriptionCalled on on updateDefinition
writeUpdateStream(integer streamId, table connection, integer dirtyMask)Arguments
integer | streamId | stream ID |
table | connection | connection |
integer | dirtyMask | dirty mask |
114 | function Washable:writeUpdateStream(streamId, connection, dirtyMask) |
115 | if not connection:getIsServer() and self.washableNodes ~= nil then |
116 | if streamWriteBool(streamId, bitAND(dirtyMask, self.washableDirtyFlag) ~= 0) then |
117 | streamWriteInt8(streamId, math.floor(self.sentDirtAmount*100)); |
118 | end |
119 | end |
120 | end |
delete
DescriptionCalled on deletingDefinition
delete()Code
124 | function Washable:delete() |
125 | for _, trigger in pairs(self.washingTriggers) do |
126 | trigger:onVehicleDeleted(self); |
127 | end |
128 | end |
updateTick
DescriptionCalled on update tickDefinition
updateTick(float dt)Arguments
float | dt | time since last call in ms |
142 | function Washable:updateTick(dt) |
143 | if self.washableNodes ~= nil then |
144 | if self.isServer then |
145 | if g_currentMission.environment.lastRainScale > 0.1 and g_currentMission.environment.timeSinceLastRain < 30 then |
146 | local amount = self:getDirtAmount(); |
147 | if amount > 0.5 then |
148 | amount = self:getDirtAmount() - (dt/self.washDuration); |
149 | end |
150 | self:setDirtAmount(amount); |
151 | else |
152 | if self:getIsActive() or self.isActive then |
153 | self:setDirtAmount(self:getDirtAmount() + (dt * self.dirtDuration)*self:getDirtMultiplier()*Washable.getIntervalMultiplier()); |
154 | end |
155 | end |
156 | end |
157 | end |
158 | end |
setDirtAmount
DescriptionSet dirt amountDefinition
setDirtAmount(float dirtAmount, boolean force)Arguments
float | dirtAmount | new dirt amount [0..1] |
boolean | force | force action |
167 | function Washable:setDirtAmount(dirtAmount, force) |
168 | if self.washableNodes ~= nil then |
169 | self.dirtAmount = Utils.clamp(Utils.getNoNil(dirtAmount, self.dirtAmount), 0, 1); |
170 | |
171 | -- only update shader if dirt change sum is about 1% |
172 | if math.abs(self.sentDirtAmount - self.dirtAmount) > 0.01 or force then |
173 | for _, node in pairs(self.washableNodes) do |
174 | local x,_,z,w = getShaderParameter(node, "RDT"); |
175 | setShaderParameter(node, "RDT", x, self.dirtAmount, z, w, false); |
176 | end |
177 | |
178 | if self.isServer then |
179 | -- use min threshold (0.01) for sync limitation |
180 | self:raiseDirtyFlags(self.washableDirtyFlag); |
181 | self.sentDirtAmount = self.dirtAmount; |
182 | end |
183 | end |
184 | end |
185 | end |
addWashableNode
DescriptionAdd node to washable nodesDefinition
addWashableNode(integer node)Arguments
integer | node | id of node to add |
190 | function Washable:addWashableNode(node) |
191 | if self.washableNodes ~= nil and node ~= nil then |
192 | Utils.getNodesByShaderParam(node, "RDT", self.washableNodes); |
193 | end |
194 | end |
removeWashableNode
DescriptionRemove node from washable nodesDefinition
removeWashableNode(integer node)Arguments
integer | node | id of node to remove |
199 | function Washable:removeWashableNode(node) |
200 | if self.washableNodes ~= nil and node ~= nil then |
201 | self.washableNodes[node] = nil; |
202 | end |
203 | end |
getDirtAmount
DescriptionReturns current dirt amountDefinition
getDirtAmount()Return Values
float | dirtAmount | dirt amount |
208 | function Washable:getDirtAmount(superFunc) |
209 | return self.dirtAmount; |
210 | end |
getDirtMultiplier
DescriptionReturns current dirt multiplierDefinition
getDirtMultiplier()Return Values
float | dirtMultiplier | current dirt multiplier |
215 | function Washable:getDirtMultiplier(superFunc) |
216 | local multiplier = 1; |
217 | if self:getLastSpeed() < 1 then |
218 | multiplier = 0; |
219 | end |
220 | |
221 | if self:getIsOnField() then |
222 | multiplier = multiplier * self.fieldMultiplier; |
223 | end |
224 | |
225 | if superFunc ~= nil then |
226 | multiplier = multiplier + superFunc(self); |
227 | end |
228 | return multiplier; |
229 | end |
getSaveAttributesAndNodes
DescriptionReturns attributes and nodes to saveDefinition
getSaveAttributesAndNodes(table nodeIdent)Arguments
table | nodeIdent | node ident |
string | attributes | attributes |
string | nodes | nodes |
236 | function Washable:getSaveAttributesAndNodes(nodeIdent) |
237 | local attributes = 'dirtAmount="'.. tostring(self.dirtAmount) .. '"'; |
238 | return attributes, nil; |
239 | end |
addWashingTrigger
DescriptionAdd trigger to washing triggersDefinition
addWashingTrigger(table trigger)Arguments
table | trigger | trigger to add |
244 | function Washable:addWashingTrigger(trigger) |
245 | table.insert(self.washingTriggers, trigger); |
246 | end |
removeWashingTrigger
DescriptionRemove trigger from washing triggersDefinition
removeWashingTrigger(table trigger)Arguments
table | trigger | trigger to remove |
251 | function Washable:removeWashingTrigger(trigger) |
252 | for i=1, table.getn(self.washingTriggers) do |
253 | if self.washingTriggers[i] == trigger then |
254 | table.remove(self.washingTriggers, i); |
255 | break; |
256 | end |
257 | end |
258 | end |
getIntervalMultiplier
DescriptionReturns dirt interval multiplier set by userDefinition
getIntervalMultiplier()Return Values
float | multiplier | multiplier |
263 | function Washable.getIntervalMultiplier() |
264 | if g_currentMission.missionInfo.dirtInterval == 1 then |
265 | return 0; |
266 | elseif g_currentMission.missionInfo.dirtInterval == 2 then |
267 | return 0.25; |
268 | elseif g_currentMission.missionInfo.dirtInterval == 3 then |
269 | return 0.5; |
270 | elseif g_currentMission.missionInfo.dirtInterval == 4 then |
271 | return 1; |
272 | end |
273 | end |