LUADOC - Farming Simulator 22

Script v1_7_1_0

Engine v1_7_1_0

Foundation Reference

BunkerSiloCompacter

Description
Specialization for increasing bunker silo compaction level and playing samples during the process
Functions

doCheckSpeedLimit

Description
Returns if speed limit should be checked
Definition
doCheckSpeedLimit()
Return Values
booleancheckSpeedlimitcheck speed limit
Code
153function BunkerSiloCompacter:doCheckSpeedLimit(superFunc)
154 local spec = self.spec_bunkerSiloCompacter
155 if spec.useSpeedLimit then
156 return superFunc(self) or spec.lastIsCompacting
157 end
158
159 return superFunc(self)
160end

getBunkerSiloCompacterScale

Description
Definition
getBunkerSiloCompacterScale()
Code
94function BunkerSiloCompacter:getBunkerSiloCompacterScale()
95 return self.spec_bunkerSiloCompacter.scale
96end

getDefaultSpeedLimit

Description
Returns default speed limit
Definition
getDefaultSpeedLimit()
Return Values
floatspeedLimitspeed limit
Code
165function BunkerSiloCompacter.getDefaultSpeedLimit()
166 return 5
167end

initSpecialization

Description
Definition
initSpecialization()
Code
23function BunkerSiloCompacter.initSpecialization()
24 local schema = Vehicle.xmlSchema
25 schema:setXMLSpecializationType("BunkerSiloCompacter")
26
27 schema:register(XMLValueType.FLOAT, BunkerSiloCompacter.XML_PATH .. "#compactingScale", "Compacting scale", 1)
28 schema:register(XMLValueType.BOOL, BunkerSiloCompacter.XML_PATH .. "#useSpeedLimit", "Defines if speed limit is used while compactor has contact with ground", false)
29
30 SoundManager.registerSampleXMLPaths(schema, BunkerSiloCompacter.XML_PATH .. ".sounds", "rolling")
31 SoundManager.registerSampleXMLPaths(schema, BunkerSiloCompacter.XML_PATH .. ".sounds", "compacting")
32
33 schema:setXMLSpecializationType()
34end

loadBunkerSiloCompactorFromXML

Description
Definition
loadBunkerSiloCompactorFromXML()
Code
86function BunkerSiloCompacter:loadBunkerSiloCompactorFromXML(xmlFile, key)
87 local spec = self.spec_bunkerSiloCompacter
88 spec.scale = xmlFile:getValue(key .. "#compactingScale", 1)
89 spec.useSpeedLimit = xmlFile:getValue(key .. "#useSpeedLimit", false)
90end

onDelete

Description
Definition
onDelete()
Code
79function BunkerSiloCompacter:onDelete()
80 local spec = self.spec_bunkerSiloCompacter
81 g_soundManager:deleteSamples(spec.samples)
82end

onLoad

Description
Definition
onLoad()
Code
59function BunkerSiloCompacter:onLoad(savegame)
60 local spec = self.spec_bunkerSiloCompacter
61
62 self:loadBunkerSiloCompactorFromXML(self.xmlFile, BunkerSiloCompacter.XML_PATH)
63
64 if self.isClient then
65 spec.samples = {}
66 spec.samples.rolling = g_soundManager:loadSampleFromXML(self.xmlFile, BunkerSiloCompacter.XML_PATH .. ".sounds", "rolling", self.baseDirectory, self.components, 0, AudioGroup.VEHICLE, self.i3dMappings, self)
67 spec.samples.compacting = g_soundManager:loadSampleFromXML(self.xmlFile, BunkerSiloCompacter.XML_PATH .. ".sounds", "compacting", self.baseDirectory, self.components, 0, AudioGroup.VEHICLE, self.i3dMappings, self)
68 spec.lastIsCompacting = false
69 spec.lastHasGroundContact = false
70 end
71
72 if self.getWheels == nil then
73 SpecializationUtil.removeEventListener(self, "onUpdate", BunkerSiloCompacter)
74 end
75end

onUpdate

Description
Called on update
Definition
onUpdate(float dt, boolean isActive, boolean isActiveForInput, boolean isSelected)
Arguments
floatdttime since last call in ms
booleanisActivetrue if vehicle is active
booleanisActiveForInputtrue if vehicle is active for input
booleanisSelectedtrue if vehicle is selected
Code
104function BunkerSiloCompacter:onUpdate(dt, isActiveForInput, isActiveForInputIgnoreSelection, isSelected)
105 local spec = self.spec_bunkerSiloCompacter
106 local hasGroundContact = false
107 local isCompacting = false
108
109 local wheels = self:getWheels()
110 for i=1, #wheels do
111 local wheel = wheels[i]
112 if wheel.contact ~= Wheels.WHEEL_NO_CONTACT then
113 hasGroundContact = true
114 if wheel.contact == Wheels.WHEEL_GROUND_HEIGHT_CONTACT then
115 isCompacting = true
116 break
117 end
118 end
119 end
120
121 if spec.lastHasGroundContact ~= hasGroundContact or spec.lastIsCompacting ~= isCompacting then
122 if hasGroundContact then
123 if isCompacting then
124 if not g_soundManager:getIsSamplePlaying(spec.samples.compacting) then
125 g_soundManager:playSample(spec.samples.compacting)
126 end
127 else
128 if g_soundManager:getIsSamplePlaying(spec.samples.compacting) then
129 g_soundManager:stopSample(spec.samples.compacting)
130 end
131 end
132
133 if not g_soundManager:getIsSamplePlaying(spec.samples.rolling) then
134 g_soundManager:playSample(spec.samples.rolling)
135 end
136 else
137 if g_soundManager:getIsSamplePlaying(spec.samples.compacting) then
138 g_soundManager:stopSample(spec.samples.compacting)
139 end
140 if g_soundManager:getIsSamplePlaying(spec.samples.rolling) then
141 g_soundManager:stopSample(spec.samples.rolling)
142 end
143 end
144
145 spec.lastHasGroundContact = hasGroundContact
146 spec.lastIsCompacting = isCompacting
147 end
148end

prerequisitesPresent

Description
Definition
prerequisitesPresent()
Code
17function BunkerSiloCompacter.prerequisitesPresent(specializations)
18 return true
19end

registerEventListeners

Description
Definition
registerEventListeners()
Code
51function BunkerSiloCompacter.registerEventListeners(vehicleType)
52 SpecializationUtil.registerEventListener(vehicleType, "onLoad", BunkerSiloCompacter)
53 SpecializationUtil.registerEventListener(vehicleType, "onUpdate", BunkerSiloCompacter)
54 SpecializationUtil.registerEventListener(vehicleType, "onDelete", BunkerSiloCompacter)
55end

registerFunctions

Description
Definition
registerFunctions()
Code
38function BunkerSiloCompacter.registerFunctions(vehicleType)
39 SpecializationUtil.registerFunction(vehicleType, "loadBunkerSiloCompactorFromXML", BunkerSiloCompacter.loadBunkerSiloCompactorFromXML)
40 SpecializationUtil.registerFunction(vehicleType, "getBunkerSiloCompacterScale", BunkerSiloCompacter.getBunkerSiloCompacterScale)
41end

registerOverwrittenFunctions

Description
Definition
registerOverwrittenFunctions()
Code
45function BunkerSiloCompacter.registerOverwrittenFunctions(vehicleType)
46 SpecializationUtil.registerOverwrittenFunction(vehicleType, "doCheckSpeedLimit", BunkerSiloCompacter.doCheckSpeedLimit)
47end