LUADOC - Farming Simulator 19

HusbandryModuleLiquidManure

Description
This class handles liquid manure in husbandry
Parent
HusbandryModuleBase
Functions

delete

Description
Deletes instance
Definition
delete()
Code
26function HusbandryModuleLiquidManure:delete()
27
28 g_currentMission:removeLiquidManureSilo(self)
29
30 HusbandryModuleLiquidManure:superClass().delete(self)
31 if self.loadPlace ~= nil then
32 self.loadPlace:delete()
33 self.loadPlace = nil
34 end
35 if self.fillPlane ~= nil then
36 self.fillPlane:delete()
37 self.fillPlane = nil
38 end
39end

getFilltypeInfos

Description
Definition
getFilltypeInfos()
Code
146function HusbandryModuleLiquidManure:getFilltypeInfos()
147 local result = {}
148
149 for fillTypeIndex, _ in pairs(self.loadPlace.fillTypes) do
150 local fillType = g_fillTypeManager:getFillTypeByIndex(fillTypeIndex)
151 local capacity = self:getCapacity()
152 local fillLevel = self:getFillLevel(fillTypeIndex)
153
154 table.insert(result, {fillType=fillType, fillLevel=fillLevel, capacity=capacity})
155 end
156 return result
157end

load

Description
Loads data from xml
Definition
load(table xmlFile, string xmlKey, table rootNode)
Arguments
tablexmlFilehandle
stringxmlKeyfrom which to read the configuration
tablerootNodeof the husbandry
Return Values
booleantrueif loading was successful else false
Code
47function HusbandryModuleLiquidManure:load(xmlFile, configKey, rootNode, owner, baseDirectory)
48 if not HusbandryModuleLiquidManure:superClass().load(self, xmlFile, configKey, rootNode, owner, baseDirectory) then
49 return false
50 end
51
52 if not hasXMLProperty(xmlFile, configKey) then
53 return false
54 end
55
56 local liquidManureNodeId = I3DUtil.indexToObject(rootNode, getXMLString(xmlFile, configKey .. "#node"))
57 if liquidManureNodeId ~= nil then
58 local loadPlace = LoadTrigger:new(self.owner.isServer, self.owner.isClient)
59
60 if loadPlace:load(liquidManureNodeId, xmlFile, configKey) then
61 loadPlace:setSource(self)
62 loadPlace:register(true)
63
64 self.stationName = self.owner:getName()
65 self.loadPlace = loadPlace
66 self.fillPlane = FillPlane:new()
67 self.fillPlane:load(rootNode, xmlFile, configKey..".fillPlane")
68
69 for fillTypeIndex, state in pairs(loadPlace.fillTypes) do
70 self.fillLevels[fillTypeIndex] = 0.0
71 self.providedFillTypes[fillTypeIndex] = state
72 self:setCapacity(0.0)
73 end
74
75 return true
76 else
77 loadPlace:delete()
78 end
79 end
80
81 return false
82end

new

Description
Creating manager
Definition
new()
Return Values
tableinstanceinstance of object
Code
20function HusbandryModuleLiquidManure:new(customMt)
21 return HusbandryModuleBase:new(customMt or HusbandryModuleLiquidManure_mt)
22end

onIntervalUpdate

Description
Update water usage
Definition
onIntervalUpdate(float dayToInterval)
Arguments
floatdayToInterval
Code
122function HusbandryModuleLiquidManure:onIntervalUpdate(dayToInterval)
123 HusbandryModuleLiquidManure:superClass().onIntervalUpdate(self, dayToInterval)
124
125 if self.singleAnimalUsagePerDay > 0 then
126 local totalNumAnimals = self.owner:getNumOfAnimals()
127 local hasWater = self.owner:hasWater()
128
129 if hasWater then
130 local newLiquidManure = totalNumAnimals * self.singleAnimalUsagePerDay * dayToInterval
131
132 if newLiquidManure > 0 then
133 for fillTypeIndex, _ in pairs(self.fillLevels) do
134 self:changeFillLevels(newLiquidManure, fillTypeIndex)
135 end
136 if self.fillPlane ~= nil then
137 self.fillPlane:setState(self:getFillProgress())
138 end
139 end
140 end
141 end
142end

readStream

Description
Called on client side on join
Definition
readStream(integer streamId, table connection)
Arguments
integerstreamIdstream ID
tableconnectionconnection
Code
95function HusbandryModuleLiquidManure:readStream(streamId, connection)
96 HusbandryModuleLiquidManure:superClass().readStream(self, streamId, connection)
97
98 if self.loadPlace ~= nil then
99 local loadPlaceId = NetworkUtil.readNodeObjectId(streamId)
100 self.loadPlace:readStream(streamId, connection)
101 g_client:finishRegisterObject(self.loadPlace, loadPlaceId)
102 end
103end

writeStream

Description
Called on server side on join
Definition
writeStream(integer streamId, table connection)
Arguments
integerstreamIdstream ID
tableconnectionconnection
Code
109function HusbandryModuleLiquidManure:writeStream(streamId, connection)
110 HusbandryModuleLiquidManure:superClass().writeStream(self, streamId, connection)
111
112 if self.loadPlace ~= nil then
113 NetworkUtil.writeNodeObjectId(streamId, NetworkUtil.getObjectId(self.loadPlace))
114 self.loadPlace:writeStream(streamId, connection)
115 g_server:registerObjectInStream(connection, self.loadPlace)
116 end
117end