LUADOC - Farming Simulator 19

BunkerSiloPlaceable

Description
Class for bga
Functions

collectPickObjects

Description
Collect pick objects
Definition
collectPickObjects(integer node)
Arguments
integernodenode id
Code
134function BunkerSiloPlaceable:collectPickObjects(node)
135-- local foundNode = false
136-- for _, unloadTrigger in ipairs(self.bga.bunker.unloadingStation.unloadTriggers) do
137-- if node == unloadTrigger.exactFillRootNode then
138-- foundNode = true
139-- break
140-- end
141-- end
142
143 if not foundNode then
144 BunkerSiloPlaceable:superClass().collectPickObjects(self, node)
145 end
146end

delete

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

finalizePlacement

Description
Called if placeable is placed
Definition
finalizePlacement()
Code
85function BunkerSiloPlaceable:finalizePlacement()
86 BunkerSiloPlaceable:superClass().finalizePlacement(self)
87
88 for _, bunkerSilo in ipairs(self.bunkerSilos) do
89 bunkerSilo:register(true)
90 end
91end

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
52function BunkerSiloPlaceable:load(xmlFilename, x,y,z, rx,ry,rz, initRandom)
53 if not BunkerSiloPlaceable:superClass().load(self, xmlFilename, x,y,z, rx,ry,rz, initRandom) then
54 return false
55 end
56
57 local xmlFile = loadXMLFile("TempXML", xmlFilename)
58
59 self.bunkerSilos = {}
60
61 local i = 0
62 while true do
63 local bunkerKey = string.format("placeable.bunkerSilos.bunkerSilo(%d)", i)
64 if not hasXMLProperty(xmlFile, bunkerKey) then
65 break
66 end
67
68 local bunkerSilo = BunkerSilo:new(self.isServer, self.isClient)
69 if bunkerSilo:load(self.nodeId, xmlFile, bunkerKey) then
70 table.insert(self.bunkerSilos, bunkerSilo)
71 else
72 bunkerSilo:delete()
73 end
74
75 i = i + 1
76 end
77
78 delete(xmlFile)
79
80 return true
81end

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
154function BunkerSiloPlaceable:loadFromXMLFile(xmlFile, key, resetVehicles)
155 if not BunkerSiloPlaceable:superClass().loadFromXMLFile(self, xmlFile, key, resetVehicles) then
156 return false
157 end
158
159 local i = 0
160 while true do
161 local bunkerKey = string.format("%s.bunkerSilo(%d)", key, i)
162 if not hasXMLProperty(xmlFile, bunkerKey) then
163 break
164 end
165
166 local index = getXMLInt(xmlFile, bunkerKey.."#index")
167
168 if index ~= nil then
169 if self.bunkerSilos[index] ~= nil then
170 if not self.bunkerSilos[index]:loadFromXMLFile(xmlFile, bunkerKey) then
171 return false
172 end
173 else
174 g_logManager:warning("Could not load bunkersilo. Given 'index' '%d' is not defined!", index)
175 end
176 end
177
178 i = i + 1
179 end
180
181 return true
182end

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 BunkerSiloPlaceable:new(isServer, isClient, customMt)
23 local self = Placeable:new(isServer, isClient, customMt or BgaPlaceable_mt)
24
25 registerObjectClassName(self, "BunkerSiloPlaceable")
26
27 return self
28end

readStream

Description
Called on client side on join
Definition
readStream(integer streamId, table connection)
Arguments
integerstreamIdstream ID
tableconnectionconnection
Code
105function BunkerSiloPlaceable:readStream(streamId, connection)
106 BunkerSiloPlaceable:superClass().readStream(self, streamId, connection)
107 if connection:getIsServer() then
108 for _, bunkerSilo in ipairs(self.bunkerSilos) do
109 local bunkerSiloId = NetworkUtil.readNodeObjectId(streamId)
110 bunkerSilo:readStream(streamId, connection)
111 g_client:finishRegisterObject(bunkerSilo, bunkerSiloId)
112 end
113 end
114end

saveToXMLFile

Description
Get save attributes and nodes
Definition
saveToXMLFile(string nodeIdent)
Arguments
stringnodeIdentnode ident
Return Values
stringattributesattributes
stringnodesnodes
Code
189function BunkerSiloPlaceable:saveToXMLFile(xmlFile, key, usedModNames)
190 BunkerSiloPlaceable:superClass().saveToXMLFile(self, xmlFile, key, usedModNames)
191
192 for k, bunkerSilo in ipairs(self.bunkerSilos) do
193 local bunkerKey = string.format("%s.bunkerSilo(%d)", key, k-1)
194 setXMLInt(xmlFile, bunkerKey .. "#index", k)
195 bunkerSilo:saveToXMLFile(xmlFile, bunkerKey, usedModNames)
196 end
197end

writeStream

Description
Called on server side on join
Definition
writeStream(integer streamId, table connection)
Arguments
integerstreamIdstream ID
tableconnectionconnection
Code
120function BunkerSiloPlaceable:writeStream(streamId, connection)
121 BunkerSiloPlaceable:superClass().writeStream(self, streamId, connection)
122 if not connection:getIsServer() then
123 for _, bunkerSilo in ipairs(self.bunkerSilos) do
124 NetworkUtil.writeNodeObjectId(streamId, NetworkUtil.getObjectId(bunkerSilo))
125 bunkerSilo:writeStream(streamId, connection)
126 g_server:registerObjectInStream(connection, bunkerSilo)
127 end
128 end
129end