LUADOC - Farming Simulator 19

SiloExtensionPlaceable

Parent
Placeable
Functions

finalizePlacement

Description
Called if placeable is placed
Definition
finalizePlacement()
Code
80function SiloExtensionPlaceable:finalizePlacement()
81 SiloExtensionPlaceable:superClass().finalizePlacement(self)
82
83 local storageSystem = g_currentMission.storageSystem
84 local ownerFarmId = self:getOwnerFarmId()
85 local lastFoundUnloadingStations = storageSystem:getUnloadingStationsInRange(nil, self.storage, ownerFarmId)
86 local lastFoundLoadingStations = storageSystem:getLoadingStationsInRange(nil, self.storage, ownerFarmId)
87
88 self.storage:setOwnerFarmId(self:getOwnerFarmId(), true)
89 storageSystem:addStorage(self.storage)
90 self.storage:register(true)
91
92 storageSystem:addStorageToUnloadingStations(self.storage, lastFoundUnloadingStations)
93 storageSystem:addStorageToLoadingStations(self.storage, lastFoundLoadingStations)
94end

getSpecValueVolume

Description
Returns value of income per hour
Definition
getSpecValueVolume(table storeItem, table realItem)
Arguments
tablestoreItemstore item
tablerealItemreal item
Return Values
integerincomePerHourincome per hour
Code
253function SiloExtensionPlaceable.getSpecValueVolume(storeItem, realItem)
254 if storeItem.specs.siloExtensionVolume == nil then
255 return nil
256 end
257
258 return g_i18n:formatVolume(storeItem.specs.siloExtensionVolume)
259end

load

Description
Load silo extension
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
50function SiloExtensionPlaceable:load(xmlFilename, x,y,z, rx,ry,rz, initRandom)
51 if not SiloExtensionPlaceable:superClass().load(self, xmlFilename, x,y,z, rx,ry,rz, initRandom) then
52 return false
53 end
54
55 local xmlFile = loadXMLFile("TempXML", xmlFilename)
56 local storageKey = "placeable.storage"
57
58 self.foreignSilo = Utils.getNoNil(getXMLBool(xmlFile, storageKey.."#foreignSilo"), false) -- Shows as foreign silo in the menu
59
60 if hasXMLProperty(xmlFile, storageKey) then
61 local storageNode = I3DUtil.indexToObject(self.nodeId, getXMLString(xmlFile, storageKey.."#node"))
62 if storageNode ~= nil then
63 self.storage = Storage:new(self.isServer, self.isClient)
64 self.storage:load(storageNode, xmlFile, storageKey)
65 self.storage.foreignSilo = self.foreignSilo
66 else
67 g_logManager:xmlWarning(xmlFilename, "Missing 'node' for storage '%s'!", storageKey)
68 end
69 else
70 g_logManager:xmlWarning(xmlFilename, "Missing 'storage' for siloExtension '%s'!", xmlFilename)
71 end
72
73 delete(xmlFile)
74
75 return true
76end

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
136function SiloExtensionPlaceable:loadFromXMLFile(xmlFile, key, resetVehicles)
137 if not SiloExtensionPlaceable:superClass().loadFromXMLFile(self, xmlFile, key, resetVehicles) then
138 return false
139 end
140
141 if not self.storage:loadFromXMLFile(xmlFile, key..".storage") then
142 return false
143 end
144
145 return true
146end

loadSpecValueVolume

Description
Loads capacity spec value
Definition
loadSpecValueVolume(integer xmlFile, string customEnvironment)
Arguments
integerxmlFileid of xml object
stringcustomEnvironmentcustom environment
Return Values
tablecapacityAndUnitcapacity and unit
Code
244function SiloExtensionPlaceable.loadSpecValueVolume(xmlFile, customEnvironment)
245 return getXMLInt(xmlFile, "placeable.storage#capacityPerFillType")
246end

readStream

Description
Called on client side on join
Definition
readStream(integer streamId, table connection)
Arguments
integerstreamIdstream ID
tableconnectionconnection
Code
100function SiloExtensionPlaceable:readStream(streamId, connection)
101 SiloExtensionPlaceable:superClass().readStream(self, streamId, connection)
102 if connection:getIsServer() then
103 local storageId = NetworkUtil.readNodeObjectId(streamId)
104 self.storage:readStream(streamId, connection)
105 g_client:finishRegisterObject(self.storage, storageId)
106 end
107end

saveToXMLFile

Description
Get save attributes and nodes
Definition
saveToXMLFile(string nodeIdent)
Arguments
stringnodeIdentnode ident
Return Values
stringattributesattributes
stringnodesnodes
Code
153function SiloExtensionPlaceable:saveToXMLFile(xmlFile, key, usedModNames)
154 SiloExtensionPlaceable:superClass().saveToXMLFile(self, xmlFile, key, usedModNames)
155
156 self.storage:saveToXMLFile(xmlFile, key..".storage", usedModNames)
157end

writeStream

Description
Called on server side on join
Definition
writeStream(integer streamId, table connection)
Arguments
integerstreamIdstream ID
tableconnectionconnection
Code
113function SiloExtensionPlaceable:writeStream(streamId, connection)
114 SiloExtensionPlaceable:superClass().writeStream(self, streamId, connection)
115 if not connection:getIsServer() then
116 NetworkUtil.writeNodeObjectId(streamId, NetworkUtil.getObjectId(self.storage))
117 self.storage:writeStream(streamId, connection)
118 g_server:registerObjectInStream(connection, self.storage)
119 end
120end