LUADOC - Farming Simulator 19

HusbandryModuleWater

Description
This class handles water in husbandry
Parent
HusbandryModuleBase
Functions

addFillLevelFromTool

Description
Definition
addFillLevelFromTool()
Code
146function HusbandryModuleWater:addFillLevelFromTool(farmId, deltaFillLevel, fillType)
147 local changed = HusbandryModuleWater:superClass().addFillLevelFromTool(self, farmId, deltaFillLevel, fillType)
148
149 if deltaFillLevel > 0 and changed ~= 0 then
150 self.owner:updateGlobalProductionFactor()
151 end
152
153 if changed > 0 and self.unloadPlace ~= nil then
154 if self.unloadPlace:getIsFillTypeSupported(fillType) then
155 self.unloadPlace:raiseActive()
156 self:updateFillPlane()
157 end
158 end
159
160 return changed
161end

delete

Description
Deletes instance
Definition
delete()
Code
27function HusbandryModuleWater:delete()
28 if self.unloadPlace ~= nil then
29 self.unloadPlace:delete()
30 self.unloadPlace = nil
31 end
32 if self.fillPlane ~= nil then
33 self.fillPlane:delete()
34 self.fillPlane = nil
35 end
36end

getFilltypeInfos

Description
Definition
getFilltypeInfos()
Code
176function HusbandryModuleWater:getFilltypeInfos()
177 local result = {}
178
179 for filltypeIndex, val in pairs(self.fillLevels) do
180 local fillType = g_fillTypeManager:getFillTypeByIndex(filltypeIndex)
181 local capacity = self.unloadPlace.target:getCapacity()
182 local fillLevel = self.unloadPlace.target:getFillLevel(filltypeIndex)
183
184 table.insert(result, {fillType=fillType, fillLevel=fillLevel, capacity=capacity})
185 end
186 return result
187end

hasWater

Description
Get a water multiplier
Definition
hasWater(float between)
Arguments
floatbetween0 and 1
Code
166function HusbandryModuleWater:hasWater()
167 local totalWater = 0.0
168 for _, fillLevel in pairs(self.fillLevels) do
169 totalWater = totalWater + fillLevel
170 end
171 return totalWater > 0.0
172end

initDataStructures

Description
Initialize data structures
Definition
initDataStructures()
Code
40function HusbandryModuleWater:initDataStructures()
41 HusbandryModuleWater:superClass().initDataStructures(self)
42 self.unloadPlace = nil
43end

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
51function HusbandryModuleWater:load(xmlFile, configKey, rootNode, owner, baseDirectory)
52 if not HusbandryModuleWater:superClass().load(self, xmlFile, configKey, rootNode, owner, baseDirectory) then
53 return false
54 end
55
56 if not hasXMLProperty(xmlFile, configKey) then
57 return false
58 end
59
60 local waterNodeId = I3DUtil.indexToObject(rootNode, getXMLString(xmlFile, configKey .. "#node"))
61 if waterNodeId ~= nil then
62 local unloadPlace = UnloadTrigger:new(self.owner.isServer, self.owner.isClient)
63 if unloadPlace:load(waterNodeId, xmlFile, configKey, self) then
64 unloadPlace:register(true)
65
66 self.unloadPlace = unloadPlace
67 self.fillPlane = FillPlane:new()
68 self.fillPlane:load(rootNode, xmlFile, configKey..".fillPlane")
69
70 for fillTypeIndex, state in pairs(unloadPlace.fillTypes) do
71 self.fillLevels[fillTypeIndex] = 0.0
72 self.providedFillTypes[fillTypeIndex] = state
73 end
74 self:setCapacity(0.0)
75
76 return true
77 else
78 unloadPlace:delete()
79 return false
80 end
81 end
82
83 return false
84end

loadFromXMLFile

Description
Loads information from attributes and node. Retrives from xml file information.
Definition
loadFromXMLFile(table xmlFile, string key)
Arguments
tablexmlFileXML file handler
stringkeyXML base key
Code
90function HusbandryModuleWater:loadFromXMLFile(xmlFile, key)
91 HusbandryModuleWater:superClass().loadFromXMLFile(self, xmlFile, key)
92 self:updateFillPlane()
93end

new

Description
Creating manager
Definition
new()
Return Values
tableinstanceinstance of object
Code
21function HusbandryModuleWater:new(customMt)
22 return HusbandryModuleBase:new(customMt or HusbandryModuleWater_mt)
23end

onIntervalUpdate

Description
Update water usage
Definition
onIntervalUpdate(float dayToInterval)
Arguments
floatdayToInterval
Code
126function HusbandryModuleWater:onIntervalUpdate(dayToInterval)
127 HusbandryModuleWater:superClass().onIntervalUpdate(self, dayToInterval)
128
129 if self.singleAnimalUsagePerDay > 0.0 then
130 local totalNumAnimals = self.owner:getNumOfAnimals()
131 local waterNeeded = totalNumAnimals * self.singleAnimalUsagePerDay * dayToInterval
132
133 if waterNeeded > 0.0 then
134 for fillTypeIndex, fillLevel in pairs(self.fillLevels) do
135 if fillLevel > 0.0 then
136 self:changeFillLevels(-math.min(waterNeeded, fillLevel), fillTypeIndex)
137 self:updateFillPlane()
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
99function HusbandryModuleWater:readStream(streamId, connection)
100 HusbandryModuleWater:superClass().readStream(self, streamId, connection)
101
102 if self.unloadPlace ~= nil then
103 local unloadPlaceId = NetworkUtil.readNodeObjectId(streamId)
104 self.unloadPlace:readStream(streamId, connection)
105 g_client:finishRegisterObject(self.unloadPlace, unloadPlaceId)
106 end
107end

writeStream

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