LUADOC - Farming Simulator 19

HusbandryModuleStraw

Description
This class handles straw in husbandry
Parent
HusbandryModuleBase
Functions

addFillLevelFromTool

Description
Definition
addFillLevelFromTool()
Code
151function HusbandryModuleStraw:addFillLevelFromTool(farmId, deltaFillLevel, fillType)
152 local changed = HusbandryModuleStraw:superClass().addFillLevelFromTool(self, farmId, deltaFillLevel, fillType)
153
154 if deltaFillLevel > 0 and changed ~= 0 then
155 self.owner:updateGlobalProductionFactor()
156 end
157
158 if changed > 0 and self.unloadPlace ~= nil then
159 if self.unloadPlace:getIsFillTypeSupported(fillType) then
160 self.unloadPlace:raiseActive()
161 self:updateFillPlane()
162 end
163 end
164
165 return changed
166end

delete

Description
Deletes instance
Definition
delete()
Code
27function HusbandryModuleStraw: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
182function HusbandryModuleStraw:getFilltypeInfos()
183 local result = {}
184
185 for filltypeIndex, val in pairs(self.fillLevels) do
186 local fillType = g_fillTypeManager:getFillTypeByIndex(filltypeIndex)
187 local capacity = self.unloadPlace.target:getCapacity()
188 local fillLevel = self.unloadPlace.target:getFillLevel(filltypeIndex)
189
190 table.insert(result, {fillType=fillType, fillLevel=fillLevel, capacity=capacity})
191 end
192
193 return result
194end

hasStraw

Description
Definition
hasStraw()
Code
170function HusbandryModuleStraw:hasStraw()
171 local totalStraw = 0.0
172
173 for _, fillLevel in pairs(self.fillLevels) do
174 totalStraw = totalStraw + fillLevel
175 end
176
177 return totalStraw > 0.0
178end

initDataStructures

Description
Initialize data structures
Definition
initDataStructures()
Code
40function HusbandryModuleStraw:initDataStructures()
41 HusbandryModuleStraw: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 HusbandryModuleStraw:load(xmlFile, configKey, rootNode, owner, baseDirectory)
52 if not HusbandryModuleStraw: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 strawNodeId = I3DUtil.indexToObject(rootNode, getXMLString(xmlFile, configKey .. "#node"))
61 if strawNodeId ~= nil then
62 local unloadPlace = UnloadTrigger:new(self.owner.isServer, self.owner.isClient)
63
64 if unloadPlace:load(strawNodeId, xmlFile, configKey, self) then
65 unloadPlace:register(true)
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 HusbandryModuleStraw:loadFromXMLFile(xmlFile, key)
91 HusbandryModuleStraw:superClass().loadFromXMLFile(self, xmlFile, key)
92
93 if self.fillPlane ~= nil then
94 self.fillPlane:setState(self:getFillProgress())
95 end
96end

new

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

onIntervalUpdate

Description
Update straw usage
Definition
onIntervalUpdate(float dayToInterval)
Arguments
floatdayToInterval
Code
131function HusbandryModuleStraw:onIntervalUpdate(dayToInterval)
132 HusbandryModuleStraw:superClass().onIntervalUpdate(self, dayToInterval)
133
134 if self.singleAnimalUsagePerDay > 0.0 then
135 local totalNumAnimals = self.owner:getNumOfAnimals()
136 local strawNeeded = totalNumAnimals * self.singleAnimalUsagePerDay * dayToInterval
137
138 if strawNeeded > 0.0 then
139 for fillTypeIndex, fillLevel in pairs(self.fillLevels) do
140 if fillLevel > 0.0 then
141 self:changeFillLevels(-math.min(strawNeeded, fillLevel), fillTypeIndex)
142 self:updateFillPlane()
143 end
144 end
145 end
146 end
147end

readStream

Description
Called on client side on join
Definition
readStream(integer streamId, table connection)
Arguments
integerstreamIdstream ID
tableconnectionconnection
Code
102function HusbandryModuleStraw:readStream(streamId, connection)
103 HusbandryModuleStraw:superClass().readStream(self, streamId, connection)
104
105 if self.unloadPlace ~= nil then
106 local unloadPlaceId = NetworkUtil.readNodeObjectId(streamId)
107 self.unloadPlace:readStream(streamId, connection)
108 g_client:finishRegisterObject(self.unloadPlace, unloadPlaceId)
109 end
110
111 self:updateFillPlane()
112end

writeStream

Description
Called on server side on join
Definition
writeStream(integer streamId, table connection)
Arguments
integerstreamIdstream ID
tableconnectionconnection
Code
118function HusbandryModuleStraw:writeStream(streamId, connection)
119 HusbandryModuleStraw:superClass().writeStream(self, streamId, connection)
120
121 if self.unloadPlace ~= nil then
122 NetworkUtil.writeNodeObjectId(streamId, NetworkUtil.getObjectId(self.unloadPlace))
123 self.unloadPlace:writeStream(streamId, connection)
124 g_server:registerObjectInStream(connection, self.unloadPlace)
125 end
126end