LUADOC - Farming Simulator 19

BgaPlaceable

Description
Class for bga
Parent
Placeable
Functions

collectPickObjects

Description
Collect pick objects
Definition
collectPickObjects(integer node)
Arguments
integernodenode id
Code
159function BgaPlaceable:collectPickObjects(node)
160 local foundNode = false
161 for _, unloadTrigger in ipairs(self.bga.bunker.unloadingStation.unloadTriggers) do
162 if node == unloadTrigger.exactFillRootNode then
163 foundNode = true
164 break
165 end
166 end
167
168 if not foundNode then
169 for _, loadTrigger in ipairs(self.bga.digestateSilo.loadingStation.loadTriggers) do
170 if node == loadTrigger.triggerNode then
171 foundNode = true
172 break
173 end
174 end
175 end
176
177 if not foundNode then
178 BgaPlaceable:superClass().collectPickObjects(self, node)
179 end
180end

delete

Description
Deleting placeable silo
Definition
delete()
Code
32function BgaPlaceable:delete()
33 self.bga:delete()
34
35 for _, bunkerSilo in ipairs(self.bunkerSilos) do
36 bunkerSilo:delete()
37 end
38
39 unregisterObjectClassName(self)
40 BgaPlaceable:superClass().delete(self)
41end

finalizePlacement

Description
Called if placeable is placed
Definition
finalizePlacement()
Code
96function BgaPlaceable:finalizePlacement()
97 BgaPlaceable:superClass().finalizePlacement(self)
98
99 self.bga:register(true)
100
101 for _, bunkerSilo in ipairs(self.bunkerSilos) do
102 bunkerSilo:register(true)
103 end
104end

load

Description
Load silo
Definition
load(string xmlFilename, float x, float y, float z, float rx, float ry, float rz, boolean initRandom)
Arguments
stringxmlFilenamexml file name
floatxx world position
floatyz world position
floatzz world position
floatrxrx world rotation
floatryry world rotation
floatrzrz world rotation
booleaninitRandominitialize random
Return Values
booleansuccesssuccess
Code
54function BgaPlaceable:load(xmlFilename, x,y,z, rx,ry,rz, initRandom)
55 if not BgaPlaceable:superClass().load(self, xmlFilename, x,y,z, rx,ry,rz, initRandom) then
56 return false
57 end
58
59 local xmlFile = loadXMLFile("TempXML", xmlFilename)
60
61 self.boughtWithFarmland = true
62
63 self.bga = Bga:new(self.isServer, self.isClient)
64 if not self.bga:load(self.nodeId, xmlFile, "placeable.bga", self.customEnvironment) then
65 self.bga:delete()
66 delete(xmlFile)
67 return false
68 end
69
70 self.bunkerSilos = {}
71
72 local i = 0
73 while true do
74 local bunkerKey = string.format("placeable.bunkerSilos.bunkerSilo(%d)", i)
75 if not hasXMLProperty(xmlFile, bunkerKey) then
76 break
77 end
78
79 local bunkerSilo = BunkerSilo:new(self.isServer, self.isClient)
80 if bunkerSilo:load(self.nodeId, xmlFile, bunkerKey) then
81 table.insert(self.bunkerSilos, bunkerSilo)
82 else
83 bunkerSilo:delete()
84 end
85
86 i = i + 1
87 end
88
89 delete(xmlFile)
90
91 return true
92end

loadFromXMLFile

Description
Loading from attributes and nodes
Definition
loadFromXMLFile(integer xmlFile, string key, boolean resetVehicles)
Arguments
integerxmlFileid of xml object
stringkeykey
booleanresetVehiclesreset vehicles
Return Values
booleansuccesssuccess
Code
188function BgaPlaceable:loadFromXMLFile(xmlFile, key, resetVehicles)
189 if not BgaPlaceable:superClass().loadFromXMLFile(self, xmlFile, key, resetVehicles) then
190 return false
191 end
192
193 self.bga:loadFromXMLFile(xmlFile, key..".bga", resetVehicles)
194
195 local i = 0
196 while true do
197 local bunkerKey = string.format("%s.bunkerSilo(%d)", key, i)
198 if not hasXMLProperty(xmlFile, bunkerKey) then
199 break
200 end
201
202 local index = getXMLInt(xmlFile, bunkerKey.."#index")
203
204 if index ~= nil then
205 if self.bunkerSilos[index] ~= nil then
206 if not self.bunkerSilos[index]:loadFromXMLFile(xmlFile, bunkerKey) then
207 return false
208 end
209 else
210 g_logManager:warning("Could not load bunkersilo. Given 'index' '%d' is not defined!", index)
211 end
212 end
213
214 i = i + 1
215 end
216
217 return true
218end

new

Description
Creating placeable silo
Definition
new(boolean isServer, boolean isClient, table customMt)
Arguments
booleanisServeris server
booleanisClientis client
tablecustomMtcustom metatable
Return Values
tableinstanceInstance of object
Code
22function BgaPlaceable:new(isServer, isClient, customMt)
23 local self = Placeable:new(isServer, isClient, customMt or BgaPlaceable_mt)
24
25 registerObjectClassName(self, "BgaPlaceable")
26
27 return self
28end

readStream

Description
Called on client side on join
Definition
readStream(integer streamId, table connection)
Arguments
integerstreamIdstream ID
tableconnectionconnection
Code
110function BgaPlaceable:readStream(streamId, connection)
111 BgaPlaceable:superClass().readStream(self, streamId, connection)
112 if connection:getIsServer() then
113 local bgaId = NetworkUtil.readNodeObjectId(streamId)
114 self.bga:readStream(streamId, connection)
115 g_client:finishRegisterObject(self.bga, bgaId)
116
117 for _, bunkerSilo in ipairs(self.bunkerSilos) do
118 local bunkerSiloId = NetworkUtil.readNodeObjectId(streamId)
119 bunkerSilo:readStream(streamId, connection)
120 g_client:finishRegisterObject(bunkerSilo, bunkerSiloId)
121 end
122 end
123end

saveToXMLFile

Description
Get save attributes and nodes
Definition
saveToXMLFile(string nodeIdent)
Arguments
stringnodeIdentnode ident
Return Values
stringattributesattributes
stringnodesnodes
Code
225function BgaPlaceable:saveToXMLFile(xmlFile, key, usedModNames)
226 BgaPlaceable:superClass().saveToXMLFile(self, xmlFile, key, usedModNames)
227
228 self.bga:saveToXMLFile(xmlFile, key..".bga", usedModNames)
229
230 for k, bunkerSilo in ipairs(self.bunkerSilos) do
231 local bunkerKey = string.format("%s.bunkerSilo(%d)", key, k-1)
232 setXMLInt(xmlFile, bunkerKey .. "#index", k)
233 bunkerSilo:saveToXMLFile(xmlFile, bunkerKey, usedModNames)
234 end
235end

writeStream

Description
Called on server side on join
Definition
writeStream(integer streamId, table connection)
Arguments
integerstreamIdstream ID
tableconnectionconnection
Code
129function BgaPlaceable:writeStream(streamId, connection)
130 BgaPlaceable:superClass().writeStream(self, streamId, connection)
131 if not connection:getIsServer() then
132 NetworkUtil.writeNodeObjectId(streamId, NetworkUtil.getObjectId(self.bga))
133 self.bga:writeStream(streamId, connection)
134 g_server:registerObjectInStream(connection, self.bga)
135
136 for _, bunkerSilo in ipairs(self.bunkerSilos) do
137 NetworkUtil.writeNodeObjectId(streamId, NetworkUtil.getObjectId(bunkerSilo))
138 bunkerSilo:writeStream(streamId, connection)
139 g_server:registerObjectInStream(connection, bunkerSilo)
140 end
141 end
142end