LUADOC - Farming Simulator 19

HusbandryModuleMilk

Description
This class handles milk in husbandry
Parent
HusbandryModuleBase
Functions

delete

Description
Deletes instance
Definition
delete()
Code
31function HusbandryModuleMilk:delete()
32 HusbandryModuleMilk:superClass().delete(self)
33 if self.loadPlace ~= nil then
34 self.loadPlace:delete()
35 self.loadPlace = nil
36 end
37end

getFilltypeInfos

Description
Definition
getFilltypeInfos()
Code
132function HusbandryModuleMilk:getFilltypeInfos()
133 local result = {}
134
135 for fillTypeIndex, _ in pairs(self.loadPlace.fillTypes) do
136 local fillType = g_fillTypeManager:getFillTypeByIndex(fillTypeIndex)
137 local capacity = self:getCapacity()
138 local fillLevel = self:getFillLevel(fillTypeIndex)
139
140 table.insert(result, {fillType=fillType, fillLevel=fillLevel, capacity=capacity})
141 end
142 return result
143end

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
45function HusbandryModuleMilk:load(xmlFile, configKey, rootNode, owner, baseDirectory)
46 local result = HusbandryModuleMilk:superClass().load(self, xmlFile, configKey, rootNode, owner, baseDirectory)
47
48 if result ~= true then
49 return false
50 end
51 if not hasXMLProperty(xmlFile, configKey) then
52 return false
53 end
54
55 local milkTankNodeId = I3DUtil.indexToObject(rootNode, getXMLString(xmlFile, configKey .. "#node"))
56 if milkTankNodeId ~= nil then
57 local loadPlace = LoadTrigger:new(self.owner.isServer, self.owner.isClient)
58 self.stationName = self.owner:getName() -- used in the silo dialog
59
60 if loadPlace:load(milkTankNodeId, xmlFile, configKey) then
61 loadPlace:setSource(self)
62 loadPlace:register(true)
63
64 self.loadPlace = loadPlace
65
66 for fillTypeIndex, state in pairs(loadPlace.fillTypes) do
67 self.fillLevels[fillTypeIndex] = 0.0
68 self.providedFillTypes[fillTypeIndex] = state
69 end
70 self:setCapacity(0.0)
71
72 return true
73 else
74 loadPlace:delete()
75 end
76 end
77 return false
78end

new

Description
Creating manager
Definition
new()
Return Values
tableinstanceinstance of object
Code
21function HusbandryModuleMilk:new(customMt)
22 if customMt == nil then
23 customMt = HusbandryModuleMilk_mt
24 end
25 local self = HusbandryModuleBase:new(customMt)
26 return self
27end

onIntervalUpdate

Description
Update milk usage
Definition
onIntervalUpdate(float dayToInterval)
Arguments
floatdayToInterval
Code
111function HusbandryModuleMilk:onIntervalUpdate(dayToInterval)
112 HusbandryModuleMilk:superClass().onIntervalUpdate(self, dayToInterval)
113
114 if self.singleAnimalUsagePerDay > 0.0 then
115 local hasWater = self.owner:hasWater()
116
117 if hasWater then
118 local totalNumAnimals = self.owner:getNumOfAnimals()
119 local newMilk = self.owner:getGlobalProductionFactor() * totalNumAnimals * self.singleAnimalUsagePerDay * dayToInterval
120
121 if newMilk > 0 then
122 for fillTypeIndex, state in pairs(self.loadPlace.fillTypes) do
123 self:changeFillLevels(newMilk, fillTypeIndex)
124 end
125 end
126 end
127 end
128end

readStream

Description
Called on client side on join
Definition
readStream(integer streamId, table connection)
Arguments
integerstreamIdstream ID
tableconnectionconnection
Code
84function HusbandryModuleMilk:readStream(streamId, connection)
85 HusbandryModuleMilk:superClass().readStream(self, streamId, connection)
86
87 if self.loadPlace ~= nil then
88 local loadPlaceId = NetworkUtil.readNodeObjectId(streamId)
89 self.loadPlace:readStream(streamId, connection)
90 g_client:finishRegisterObject(self.loadPlace, loadPlaceId)
91 end
92end

writeStream

Description
Called on server side on join
Definition
writeStream(integer streamId, table connection)
Arguments
integerstreamIdstream ID
tableconnectionconnection
Code
98function HusbandryModuleMilk:writeStream(streamId, connection)
99 HusbandryModuleMilk:superClass().writeStream(self, streamId, connection)
100
101 if self.loadPlace ~= nil then
102 NetworkUtil.writeNodeObjectId(streamId, NetworkUtil.getObjectId(self.loadPlace))
103 self.loadPlace:writeStream(streamId, connection)
104 g_server:registerObjectInStream(connection, self.loadPlace)
105 end
106end