LUADOC - Farming Simulator 22

Script v1_7_1_0

Engine v1_7_1_0

Foundation Reference

PlaceableManureHeap

Description
Specialization for placeables
Functions

collectPickObjects

Description
Definition
collectPickObjects()
Code
221function PlaceableManureHeap:collectPickObjects(superFunc, node)
222 local spec = self.spec_manureHeap
223
224 if spec.loadingStation ~= nil then
225 for _, loadTrigger in ipairs(spec.loadingStation.loadTriggers) do
226 if node == loadTrigger.triggerNode then
227 return
228 end
229 end
230 end
231
232 if spec.manureHeap ~= nil then
233 if node == spec.manureHeap.activationTriggerNode then
234 return
235 end
236 end
237
238 superFunc(self, node)
239end

getCanBePlacedAt

Description
Definition
getCanBePlacedAt()
Code
243function PlaceableManureHeap:getCanBePlacedAt(superFunc, x, y, z, farmId)
244 local spec = self.spec_manureHeap
245 if spec.manureHeap == nil then
246 return false
247 end
248
249 if spec.isExtension then
250 local storageSystem = g_currentMission.storageSystem
251
252 -- we also need to check farmId
253 local lastFoundUnloadingStations = storageSystem:getExtendableUnloadingStationsInRange(spec.manureHeap, farmId, x, y, z)
254 if #lastFoundUnloadingStations == 0 then
255 return false, g_i18n:getText("warning_manureHeapNotNearBarn")
256 end
257 end
258
259 return superFunc(self, x, y, z, farmId)
260end

getSpecValueCapacity

Description
Definition
getSpecValueCapacity()
Code
286function PlaceableManureHeap.getSpecValueCapacity(storeItem, realItem)
287 if storeItem.specs.manureHeapCapacity == nil then
288 return nil
289 end
290
291 return g_i18n:formatVolume(storeItem.specs.manureHeapCapacity)
292end

initSpecialization

Description
Definition
initSpecialization()
Code
61function PlaceableManureHeap.initSpecialization()
62 g_storeManager:addSpecType("manureHeapCapacity", "shopListAttributeIconCapacity", PlaceableManureHeap.loadSpecValueCapacity, PlaceableManureHeap.getSpecValueCapacity, "placeable")
63end

loadFromXMLFile

Description
Definition
loadFromXMLFile()
Code
190function PlaceableManureHeap:loadFromXMLFile(xmlFile, key)
191 local spec = self.spec_manureHeap
192 if spec.manureHeap ~= nil then
193 spec.manureHeap:loadFromXMLFile(xmlFile, key)
194 end
195end

loadSpecValueCapacity

Description
Definition
loadSpecValueCapacity()
Code
280function PlaceableManureHeap.loadSpecValueCapacity(xmlFile, customEnvironment, baseDir)
281 return xmlFile:getValue("placeable.manureHeap#capacity")
282end

onDelete

Description
Definition
onDelete()
Code
94function PlaceableManureHeap:onDelete()
95 local spec = self.spec_manureHeap
96 local storageSystem = g_currentMission.storageSystem
97
98 if spec.manureHeap ~= nil then
99 if storageSystem:hasStorage(spec.manureHeap) then
100 -- just remove storage from all registered unloading and loading stations
101 storageSystem:removeStorageFromUnloadingStations(spec.manureHeap, spec.manureHeap.unloadingStations)
102 storageSystem:removeStorageFromLoadingStations(spec.manureHeap, spec.manureHeap.loadingStations)
103
104 storageSystem:removeStorage(spec.manureHeap)
105 end
106 spec.manureHeap:delete()
107 spec.manureHeap = nil
108 end
109
110 if spec.loadingStation ~= nil then
111 if spec.loadingStation:getIsFillTypeSupported(FillType.MANURE) then
112 g_currentMission:removeManureLoadingStation(spec.loadingStation)
113 end
114
115 storageSystem:removeLoadingStation(spec.loadingStation, self)
116 spec.loadingStation:delete()
117 spec.loadingStation = nil
118 end
119end

onFinalizePlacement

Description
Definition
onFinalizePlacement()
Code
123function PlaceableManureHeap:onFinalizePlacement()
124 local spec = self.spec_manureHeap
125 local storageSystem = g_currentMission.storageSystem
126 local ownerFarmId = self:getOwnerFarmId()
127
128 if spec.loadingStation ~= nil and spec.manureHeap ~= nil then
129 spec.loadingStation:register(true)
130 storageSystem:addLoadingStation(spec.loadingStation, self)
131
132 spec.manureHeap:finalize()
133 spec.manureHeap:register(true)
134 spec.manureHeap:setOwnerFarmId(ownerFarmId, true)
135 storageSystem:addStorage(spec.manureHeap)
136 storageSystem:addStorageToLoadingStation(spec.manureHeap, spec.loadingStation)
137
138 if spec.loadingStation:getIsFillTypeSupported(FillType.MANURE) then
139 g_currentMission:addManureLoadingStation(spec.loadingStation)
140 end
141
142 local storagesInRange = storageSystem:getStorageExtensionsInRange(spec.loadingStation, ownerFarmId)
143 for _, storage in ipairs(storagesInRange) do
144 if spec.loadingStation.sourceStorages[storage] == nil then
145 storageSystem:addStorageToLoadingStation(storage, spec.loadingStation)
146 end
147 end
148
149 local lastFoundUnloadingStations = storageSystem:getExtendableUnloadingStationsInRange(spec.manureHeap, ownerFarmId)
150 local lastFoundLoadingStations = storageSystem:getExtendableLoadingStationsInRange(spec.manureHeap, ownerFarmId)
151 storageSystem:addStorageToUnloadingStations(spec.manureHeap, lastFoundUnloadingStations)
152 storageSystem:addStorageToLoadingStations(spec.manureHeap, lastFoundLoadingStations)
153 end
154end

onLoad

Description
Called on loading
Definition
onLoad(table savegame)
Arguments
tablesavegamesavegame
Code
68function PlaceableManureHeap:onLoad(savegame)
69 local spec = self.spec_manureHeap
70 local xmlFile = self.xmlFile
71
72 spec.loadingStation = LoadingStation.new(self.isServer, self.isClient)
73 if not spec.loadingStation:load(spec.components, xmlFile, "placeable.manureHeap.loadingStation", self.customEnvironment, self.i3dMappings, self.components[1].node) then
74 spec.loadingStation:delete()
75 spec.loadingStation = nil
76 return false
77 end
78 spec.loadingStation.owningPlaceable = self
79 spec.loadingStation.hasStoragePerFarm = false
80
81 spec.manureHeap = ManureHeap.new(spec.isServer, self.isClient)
82 if not spec.manureHeap:load(spec.components, xmlFile, "placeable.manureHeap", self.customEnvironment, self.i3dMappings, self.components[1].node) then
83 spec.manureHeap:delete()
84 spec.manureHeap = nil
85 end
86
87 spec.isExtension = xmlFile:getValue("placeable.manureHeap#isExtension", true)
88
89 spec.infoFillLevel = {title=g_i18n:getText("fillType_manure"), text=""}
90end

onReadStream

Description
Definition
onReadStream()
Code
158function PlaceableManureHeap:onReadStream(streamId, connection)
159 local spec = self.spec_manureHeap
160
161 if spec.loadingStation ~= nil and spec.manureHeap ~= nil then
162 local loadingStationId = NetworkUtil.readNodeObjectId(streamId)
163 spec.loadingStation:readStream(streamId, connection)
164 g_client:finishRegisterObject(spec.loadingStation, loadingStationId)
165
166 local manureHeapId = NetworkUtil.readNodeObjectId(streamId)
167 spec.manureHeap:readStream(streamId, connection)
168 g_client:finishRegisterObject(spec.manureHeap, manureHeapId)
169 end
170end

onWriteStream

Description
Definition
onWriteStream()
Code
174function PlaceableManureHeap:onWriteStream(streamId, connection)
175 local spec = self.spec_manureHeap
176
177 if spec.loadingStation ~= nil and spec.manureHeap ~= nil then
178 NetworkUtil.writeNodeObjectId(streamId, NetworkUtil.getObjectId(spec.loadingStation))
179 spec.loadingStation:writeStream(streamId, connection)
180 g_server:registerObjectInStream(connection, spec.loadingStation)
181
182 NetworkUtil.writeNodeObjectId(streamId, NetworkUtil.getObjectId(spec.manureHeap))
183 spec.manureHeap:writeStream(streamId, connection)
184 g_server:registerObjectInStream(connection, spec.manureHeap)
185 end
186end

prerequisitesPresent

Description
Checks if all prerequisite specializations are loaded
Definition
prerequisitesPresent(table specializations)
Arguments
tablespecializationsspecializations
Return Values
booleanhasPrerequisitetrue if all prerequisite specializations are loaded
Code
18function PlaceableManureHeap.prerequisitesPresent(specializations)
19 return true
20end

registerEventListeners

Description
Definition
registerEventListeners()
Code
33function PlaceableManureHeap.registerEventListeners(placeableType)
34 SpecializationUtil.registerEventListener(placeableType, "onLoad", PlaceableManureHeap)
35 SpecializationUtil.registerEventListener(placeableType, "onDelete", PlaceableManureHeap)
36 SpecializationUtil.registerEventListener(placeableType, "onFinalizePlacement", PlaceableManureHeap)
37 SpecializationUtil.registerEventListener(placeableType, "onReadStream", PlaceableManureHeap)
38 SpecializationUtil.registerEventListener(placeableType, "onWriteStream", PlaceableManureHeap)
39end

registerOverwrittenFunctions

Description
Definition
registerOverwrittenFunctions()
Code
24function PlaceableManureHeap.registerOverwrittenFunctions(placeableType)
25 SpecializationUtil.registerOverwrittenFunction(placeableType, "setOwnerFarmId", PlaceableManureHeap.setOwnerFarmId)
26 SpecializationUtil.registerOverwrittenFunction(placeableType, "collectPickObjects", PlaceableManureHeap.collectPickObjects)
27 SpecializationUtil.registerOverwrittenFunction(placeableType, "getCanBePlacedAt", PlaceableManureHeap.getCanBePlacedAt)
28 SpecializationUtil.registerOverwrittenFunction(placeableType, "updateInfo", PlaceableManureHeap.updateInfo)
29end

registerSavegameXMLPaths

Description
Definition
registerSavegameXMLPaths()
Code
53function PlaceableManureHeap.registerSavegameXMLPaths(schema, basePath)
54 schema:setXMLSpecializationType("ManureHeap")
55 ManureHeap.registerSavegameXMLPaths(schema, basePath)
56 schema:setXMLSpecializationType(XMLManager.XML_SPECIALIZATION_NONE)
57end

registerXMLPaths

Description
Definition
registerXMLPaths()
Code
43function PlaceableManureHeap.registerXMLPaths(schema, basePath)
44 schema:setXMLSpecializationType("ManureHeap")
45 ManureHeap.registerXMLPaths(schema, basePath .. ".manureHeap")
46 schema:register(XMLValueType.BOOL, basePath .. ".manureHeap#isExtension", "Is extension and can only be placed next to storages", true)
47 LoadingStation.registerXMLPaths(schema, basePath .. ".manureHeap.loadingStation")
48 schema:setXMLSpecializationType(XMLManager.XML_SPECIALIZATION_NONE)
49end

saveToXMLFile

Description
Definition
saveToXMLFile()
Code
199function PlaceableManureHeap:saveToXMLFile(xmlFile, key, usedModNames)
200 local spec = self.spec_manureHeap
201 if spec.manureHeap ~= nil then
202 spec.manureHeap:saveToXMLFile(xmlFile, key, usedModNames)
203 end
204end

setOwnerFarmId

Description
Definition
setOwnerFarmId()
Code
208function PlaceableManureHeap:setOwnerFarmId(superFunc, farmId, noEventSend)
209 superFunc(self, farmId, noEventSend)
210
211 if self.isServer then
212 local spec = self.spec_manureHeap
213 if spec.manureHeap ~= nil then
214 spec.manureHeap:setOwnerFarmId(farmId, true)
215 end
216 end
217end

updateInfo

Description
Definition
updateInfo()
Code
264function PlaceableManureHeap:updateInfo(superFunc, infoTable)
265 superFunc(self, infoTable)
266
267 local spec = self.spec_manureHeap
268 if spec.manureHeap == nil then
269 return
270 end
271
272 local fillLevel = spec.manureHeap:getFillLevel(spec.manureHeap.fillTypeIndex)
273
274 spec.infoFillLevel.text = string.format("%d l", fillLevel)
275 table.insert(infoTable, spec.infoFillLevel)
276end