LUADOC - Farming Simulator 22

Script v1_7_1_0

Engine v1_7_1_0

Foundation Reference

PlaceableBeehivePalletSpawner

Description
Specialization for placeables
Functions

addFillLevel

Description
Definition
addFillLevel()
Code
161function PlaceableBeehivePalletSpawner:addFillLevel(fillLevel)
162 if self.isServer then
163 local spec = self.spec_beehivePalletSpawner
164
165 if fillLevel ~= nil then
166 spec.pendingLiters = spec.pendingLiters + fillLevel
167 end
168 end
169end

canBuy

Description
Definition
canBuy()
Code
225function PlaceableBeehivePalletSpawner:canBuy(superFunc)
226 local canBuy, warning = superFunc(self)
227 if not canBuy then
228 return false, warning
229 end
230
231 if g_currentMission.beehiveSystem:getFarmBeehivePalletSpawner(g_currentMission.player.farmId) ~= nil then
232 return false, g_i18n:getText("warning_onlyOneOfThisItemAllowedPerFarm")
233 end
234
235 return true, nil
236end

getPalletCallback

Description
Definition
getPalletCallback()
Code
186function PlaceableBeehivePalletSpawner:getPalletCallback(pallet, result, fillTypeIndex)
187 local spec = self.spec_beehivePalletSpawner
188 spec.spawnPending = false
189
190 if pallet ~= nil then
191 if result == PalletSpawner.RESULT_SUCCESS then
192 if spec.palletLimitReached then
193 spec.palletLimitReached = false
194 self:raiseDirtyFlags(spec.dirtyFlag)
195 end
196 pallet:emptyAllFillUnits(true)
197 end
198
199 local delta = pallet:addFillUnitFillLevel(self:getOwnerFarmId(), 1, spec.pendingLiters, fillTypeIndex, ToolType.UNDEFINED)
200
201 spec.pendingLiters = math.max(spec.pendingLiters - delta, 0)
202
203 elseif result == PalletSpawner.RESULT_NO_SPACE then
204 -- TODO: add cooldown or "pallet removed" callback to prevent overlap boxes in every frame
205 elseif result == PalletSpawner.PALLET_LIMITED_REACHED then
206 if not spec.palletLimitReached then
207 spec.palletLimitReached = true
208 self:raiseDirtyFlags(spec.dirtyFlag)
209 end
210 end
211end

loadFromXMLFile

Description
Definition
loadFromXMLFile()
Code
142function PlaceableBeehivePalletSpawner:loadFromXMLFile(xmlFile, key)
143 local spec = self.spec_beehivePalletSpawner
144
145 spec.pendingLiters = xmlFile:getValue(key..".beehivePalletSpawner#pendingLiters") or spec.pendingLiters
146end

onDelete

Description
Definition
onDelete()
Code
88function PlaceableBeehivePalletSpawner:onDelete()
89 local spec = self.spec_beehivePalletSpawner
90 if spec.palletSpawner ~= nil then
91 spec.palletSpawner:delete()
92 end
93 g_currentMission.beehiveSystem:removeBeehivePalletSpawner(self)
94end

onFinalizePlacement

Description
Definition
onFinalizePlacement()
Code
98function PlaceableBeehivePalletSpawner:onFinalizePlacement()
99 g_currentMission.beehiveSystem:addBeehivePalletSpawner(self)
100end

onLoad

Description
Called on loading
Definition
onLoad(table savegame)
Arguments
tablesavegamesavegame
Code
65function PlaceableBeehivePalletSpawner:onLoad(savegame)
66 local spec = self.spec_beehivePalletSpawner
67 local xmlFile = self.xmlFile
68
69 local palletSpawnerKey = "placeable.beehivePalletSpawner"
70 spec.palletSpawner = PalletSpawner.new(self.baseDirectory)
71 if not spec.palletSpawner:load(self.components, xmlFile, palletSpawnerKey, self.customEnvironment, self.i3dMappings) then
72 Logging.xmlError(xmlFile, "Unable to load pallet spawner %s", palletSpawnerKey)
73 self:setLoadingState(Placeable.LOADING_STATE_ERROR)
74 return
75 end
76
77 spec.pendingLiters = 0
78 spec.spawnPending = false
79 spec.palletLimitReached = false
80 spec.infoHudTooManyPallets = {title=g_i18n:getText("infohud_tooManyPallets")}
81 spec.fillType = g_fillTypeManager:getFillTypeIndexByName("HONEY")
82
83 spec.dirtyFlag = self:getNextDirtyFlag()
84end

onReadStream

Description
Definition
onReadStream()
Code
104function PlaceableBeehivePalletSpawner:onReadStream(streamId, connection)
105 if connection:getIsServer() then
106 local spec = self.spec_beehivePalletSpawner
107 spec.palletLimitReached = streamReadBool(streamId)
108 end
109end

onReadUpdateStream

Description
Definition
onReadUpdateStream()
Code
123function PlaceableBeehivePalletSpawner:onReadUpdateStream(streamId, timestamp, connection)
124 if connection:getIsServer() then
125 local spec = self.spec_beehivePalletSpawner
126 spec.palletLimitReached = streamReadBool(streamId)
127 end
128end

onWriteStream

Description
Definition
onWriteStream()
Code
113function PlaceableBeehivePalletSpawner:onWriteStream(streamId, connection)
114 if not connection:getIsServer() then
115 local spec = self.spec_beehivePalletSpawner
116 streamWriteBool(streamId, spec.palletLimitReached)
117 end
118end

onWriteUpdateStream

Description
Definition
onWriteUpdateStream()
Code
132function PlaceableBeehivePalletSpawner:onWriteUpdateStream(streamId, connection, dirtyMask)
133 if not connection:getIsServer() then
134 local spec = self.spec_beehivePalletSpawner
135 streamWriteBool(streamId, spec.palletLimitReached)
136 end
137end

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
17function PlaceableBeehivePalletSpawner.prerequisitesPresent(specializations)
18 return true
19end

registerEventListeners

Description
Definition
registerEventListeners()
Code
38function PlaceableBeehivePalletSpawner.registerEventListeners(placeableType)
39 SpecializationUtil.registerEventListener(placeableType, "onLoad", PlaceableBeehivePalletSpawner)
40 SpecializationUtil.registerEventListener(placeableType, "onDelete", PlaceableBeehivePalletSpawner)
41 SpecializationUtil.registerEventListener(placeableType, "onFinalizePlacement", PlaceableBeehivePalletSpawner)
42 SpecializationUtil.registerEventListener(placeableType, "onReadStream", PlaceableBeehivePalletSpawner)
43 SpecializationUtil.registerEventListener(placeableType, "onWriteStream", PlaceableBeehivePalletSpawner)
44 SpecializationUtil.registerEventListener(placeableType, "onReadUpdateStream", PlaceableBeehivePalletSpawner)
45 SpecializationUtil.registerEventListener(placeableType, "onWriteUpdateStream", PlaceableBeehivePalletSpawner)
46end

registerFunctions

Description
Definition
registerFunctions()
Code
23function PlaceableBeehivePalletSpawner.registerFunctions(placeableType)
24 SpecializationUtil.registerFunction(placeableType, "addFillLevel", PlaceableBeehivePalletSpawner.addFillLevel)
25 SpecializationUtil.registerFunction(placeableType, "updatePallets", PlaceableBeehivePalletSpawner.updatePallets)
26 SpecializationUtil.registerFunction(placeableType, "getPalletCallback", PlaceableBeehivePalletSpawner.getPalletCallback)
27end

registerOverwrittenFunctions

Description
Definition
registerOverwrittenFunctions()
Code
31function PlaceableBeehivePalletSpawner.registerOverwrittenFunctions(placeableType)
32 SpecializationUtil.registerOverwrittenFunction(placeableType, "canBuy", PlaceableBeehivePalletSpawner.canBuy)
33 SpecializationUtil.registerOverwrittenFunction(placeableType, "updateInfo", PlaceableBeehivePalletSpawner.updateInfo)
34end

registerSavegameXMLPaths

Description
Definition
registerSavegameXMLPaths()
Code
58function PlaceableBeehivePalletSpawner.registerSavegameXMLPaths(schema, basePath)
59 schema:register(XMLValueType.FLOAT, basePath .. ".beehivePalletSpawner#pendingLiters", "Pending liters to be spawned")
60end

registerXMLPaths

Description
Definition
registerXMLPaths()
Code
50function PlaceableBeehivePalletSpawner.registerXMLPaths(schema, basePath)
51 schema:setXMLSpecializationType("BeehivePalletSpawner")
52 PalletSpawner.registerXMLPaths(schema, basePath .. ".beehivePalletSpawner")
53 schema:setXMLSpecializationType()
54end

saveToXMLFile

Description
Definition
saveToXMLFile()
Code
150function PlaceableBeehivePalletSpawner:saveToXMLFile(xmlFile, key, usedModNames)
151 local spec = self.spec_beehivePalletSpawner
152
153 if spec.pendingLiters > 0 then
154 xmlFile:setValue(key..".beehivePalletSpawner#pendingLiters", spec.pendingLiters)
155 end
156end

updateInfo

Description
Definition
updateInfo()
Code
215function PlaceableBeehivePalletSpawner:updateInfo(superFunc, infoTable)
216 superFunc(self, infoTable)
217 local spec = self.spec_beehivePalletSpawner
218 if spec.palletLimitReached then
219 table.insert(infoTable, spec.infoHudTooManyPallets)
220 end
221end

updatePallets

Description
Definition
updatePallets()
Code
173function PlaceableBeehivePalletSpawner:updatePallets()
174 if self.isServer then
175 local spec = self.spec_beehivePalletSpawner
176
177 if not spec.spawnPending and spec.pendingLiters > 10 then
178 spec.spawnPending = true
179 spec.palletSpawner:getOrSpawnPallet(self:getOwnerFarmId(), spec.fillType, self.getPalletCallback, self)
180 end
181 end
182end