LUADOC - Farming Simulator 22

Script v1_7_1_0

Engine v1_7_1_0

Foundation Reference

PlaceableHusbandryFeedingRobot

Description
Specialization for placeables
Functions

collectPickObjects

Description
Definition
collectPickObjects()
Code
264function PlaceableHusbandryFeedingRobot:collectPickObjects(superFunc, node)
265 local spec = self.spec_husbandryFeedingRobot
266 if spec.feedingRobot ~= nil then
267 if spec.feedingRobot:getIsNodeUsed(node) then
268 return
269 end
270 end
271
272 superFunc(self, node)
273end

loadFromXMLFile

Description
Definition
loadFromXMLFile()
Code
222function PlaceableHusbandryFeedingRobot:loadFromXMLFile(xmlFile, key)
223 local spec = self.spec_husbandryFeedingRobot
224 if spec.feedingRobot ~= nil then
225 spec.feedingRobot:loadFromXMLFile(xmlFile, key)
226 end
227end

onDelete

Description
Definition
onDelete()
Code
182function PlaceableHusbandryFeedingRobot:onDelete()
183 local spec = self.spec_husbandryFeedingRobot
184 if spec.feedingRobot ~= nil then
185 spec.feedingRobot:delete()
186 end
187end

onFeedingRobotLoaded

Description
Definition
onFeedingRobotLoaded()
Code
176function PlaceableHusbandryFeedingRobot:onFeedingRobotLoaded(robot, args)
177 self:finishLoadingTask(args.loadingTask)
178end

onFinalizePlacement

Description
Definition
onFinalizePlacement()
Code
191function PlaceableHusbandryFeedingRobot:onFinalizePlacement()
192 local spec = self.spec_husbandryFeedingRobot
193 if spec.feedingRobot ~= nil then
194 spec.feedingRobot:finalizePlacement()
195 end
196end

onLoad

Description
Definition
onLoad()
Code
83function PlaceableHusbandryFeedingRobot:onLoad(savegame)
84 local spec = self.spec_husbandryFeedingRobot
85
86 if not self.xmlFile:hasProperty("placeable.husbandry.feedingRobot") then
87 return
88 end
89
90 local filename = self.xmlFile:getValue("placeable.husbandry.feedingRobot#filename")
91 if filename == nil then
92 Logging.xmlError(self.xmlFile, "Feedingrobot filename missing")
93 self:setLoadingState(Placeable.LOADING_STATE_ERROR)
94 return
95 end
96
97 filename = Utils.getFilename(filename, self.baseDirectory)
98
99 local className = self.xmlFile:getValue("placeable.husbandry.feedingRobot#class", "")
100 local class = ClassUtil.getClassObject(className)
101 if class == nil then
102 Logging.xmlError(self.xmlFile, "Feedingrobot class '%s' not defined", className)
103 self:setLoadingState(Placeable.LOADING_STATE_ERROR)
104 return
105 end
106
107 local linkNode = self.xmlFile:getValue("placeable.husbandry.feedingRobot#linkNode", nil, self.components, self.i3dMappings)
108 if linkNode == nil then
109 Logging.xmlError(self.xmlFile, "Feedingrobot linkNode not defined")
110 self:setLoadingState(Placeable.LOADING_STATE_ERROR)
111 return
112 end
113
114 local loadingTask = self:createLoadingTask(self)
115 spec.feedingRobot = class.new(self.isServer, self.isClient, self, self.baseDirectory)
116 spec.feedingRobot:load(linkNode, filename, self.onFeedingRobotLoaded, self, {loadingTask=loadingTask})
117 spec.feedingRobot:register(true)
118
119 self.xmlFile:iterate("placeable.husbandry.feedingRobot.splines.spline", function(_, splineKey)
120 local spline = self.xmlFile:getValue(splineKey .. "#node", nil, self.components, self.i3dMappings)
121 if spline == nil then
122 Logging.xmlWarning(self.xmlFile, "Feedingrobot spline not defined for '%s'", splineKey)
123 return false
124 end
125 if not getHasClassId(getGeometry(spline), ClassIds.SPLINE) then
126 Logging.xmlWarning(self.xmlFile, "Given node is not a spline for '%s'", splineKey)
127 return false
128 end
129 local direction = self.xmlFile:getValue(splineKey .. "#direction", 1)
130 local isFeeding = self.xmlFile:getValue(splineKey .. "#isFeeding", false)
131
132 spec.feedingRobot:addSpline(spline, direction, isFeeding)
133 end)
134
135 spec.dependedAnimatedObjects = {}
136 self.xmlFile:iterate("placeable.husbandry.feedingRobot.animatedObjects.animatedObject", function(index, animationObjectKey)
137 local animatedObjectIndex = self.xmlFile:getInt(animationObjectKey.."#index")
138 local direction = self.xmlFile:getInt(animationObjectKey.."#direction", 1)
139
140 table.insert(spec.dependedAnimatedObjects, {animatedObjectIndex=animatedObjectIndex, direction=direction})
141 end)
142end

onPostLoad

Description
Definition
onPostLoad()
Code
146function PlaceableHusbandryFeedingRobot:onPostLoad(savegame)
147 local spec = self.spec_husbandryFeedingRobot
148 if spec.dependedAnimatedObjects ~= nil and self.spec_animatedObjects ~= nil then
149 local animatedObjects = self.spec_animatedObjects.animatedObjects
150
151 for _, data in ipairs(spec.dependedAnimatedObjects) do
152 local animatedObject = animatedObjects[data.animatedObjectIndex]
153 if animatedObject ~= nil then
154 animatedObject.getCanBeTriggered = Utils.overwrittenFunction(animatedObject.getCanBeTriggered, function(_, superFunc)
155 if not superFunc(animatedObject) then
156 return false
157 end
158
159 return not spec.feedingRobot:getIsDriving()
160 end)
161
162 spec.feedingRobot:addStateChangedListener(function(state)
163 if spec.feedingRobot:getIsDriving() then
164 if animatedObject.animation.direction ~= data.direction then
165 animatedObject:setDirection(data.direction)
166 end
167 end
168 end)
169 end
170 end
171 end
172end

onReadStream

Description
Definition
onReadStream()
Code
200function PlaceableHusbandryFeedingRobot:onReadStream(streamId, connection)
201 local spec = self.spec_husbandryFeedingRobot
202 if spec.feedingRobot ~= nil then
203 local feedingRobotId = NetworkUtil.readNodeObjectId(streamId)
204 spec.feedingRobot:readStream(streamId, connection)
205 g_client:finishRegisterObject(spec.feedingRobot, feedingRobotId)
206 end
207end

onWriteStream

Description
Definition
onWriteStream()
Code
211function PlaceableHusbandryFeedingRobot:onWriteStream(streamId, connection)
212 local spec = self.spec_husbandryFeedingRobot
213 if spec.feedingRobot ~= nil then
214 NetworkUtil.writeNodeObjectId(streamId, NetworkUtil.getObjectId(spec.feedingRobot))
215 spec.feedingRobot:writeStream(streamId, connection)
216 g_server:registerObjectInStream(connection, spec.feedingRobot)
217 end
218end

prerequisitesPresent

Description
Checks if all prerequisite specializations are loaded
Definition
prerequisitesPresent(table specializations)
Arguments
tablespecializationsspecializations
Return Values
booleanhasPrerequisitetrue if all prerequisite specializations are loaded
Code
27function PlaceableHusbandryFeedingRobot.prerequisitesPresent(specializations)
28 return SpecializationUtil.hasSpecialization(PlaceableHusbandryFood, specializations)
29end

registerEventListeners

Description
Definition
registerEventListeners()
Code
48function PlaceableHusbandryFeedingRobot.registerEventListeners(placeableType)
49 SpecializationUtil.registerEventListener(placeableType, "onLoad", PlaceableHusbandryFeedingRobot)
50 SpecializationUtil.registerEventListener(placeableType, "onPostLoad", PlaceableHusbandryFeedingRobot)
51 SpecializationUtil.registerEventListener(placeableType, "onDelete", PlaceableHusbandryFeedingRobot)
52 SpecializationUtil.registerEventListener(placeableType, "onFinalizePlacement", PlaceableHusbandryFeedingRobot)
53 SpecializationUtil.registerEventListener(placeableType, "onReadStream", PlaceableHusbandryFeedingRobot)
54 SpecializationUtil.registerEventListener(placeableType, "onWriteStream", PlaceableHusbandryFeedingRobot)
55end

registerFunctions

Description
Definition
registerFunctions()
Code
33function PlaceableHusbandryFeedingRobot.registerFunctions(placeableType)
34 SpecializationUtil.registerFunction(placeableType, "onFeedingRobotLoaded", PlaceableHusbandryFeedingRobot.onFeedingRobotLoaded)
35end

registerOverwrittenFunctions

Description
Definition
registerOverwrittenFunctions()
Code
39function PlaceableHusbandryFeedingRobot.registerOverwrittenFunctions(placeableType)
40 SpecializationUtil.registerOverwrittenFunction(placeableType, "setOwnerFarmId", PlaceableHusbandryFeedingRobot.setOwnerFarmId)
41 SpecializationUtil.registerOverwrittenFunction(placeableType, "updateFeeding", PlaceableHusbandryFeedingRobot.updateFeeding)
42 SpecializationUtil.registerOverwrittenFunction(placeableType, "collectPickObjects", PlaceableHusbandryFeedingRobot.collectPickObjects)
43 SpecializationUtil.registerOverwrittenFunction(placeableType, "updateInfo", PlaceableHusbandryFeedingRobot.updateInfo)
44end

registerSavegameXMLPaths

Description
Definition
registerSavegameXMLPaths()
Code
75function PlaceableHusbandryFeedingRobot.registerSavegameXMLPaths(schema, basePath)
76 schema:setXMLSpecializationType("Husbandry")
77 FeedingRobot.registerSavegameXMLPaths(schema, basePath)
78 schema:setXMLSpecializationType()
79end

registerXMLPaths

Description
Definition
registerXMLPaths()
Code
59function PlaceableHusbandryFeedingRobot.registerXMLPaths(schema, basePath)
60 schema:setXMLSpecializationType("Husbandry")
61 basePath = basePath .. ".husbandry.feedingRobot"
62 schema:register(XMLValueType.NODE_INDEX, basePath .. "#linkNode", "Feedingrobot link node")
63 schema:register(XMLValueType.STRING, basePath .. "#class", "Feedingrobot class name")
64 schema:register(XMLValueType.STRING, basePath .. "#filename", "Feedingrobot config file")
65 schema:register(XMLValueType.NODE_INDEX, basePath .. ".splines.spline(?)#node", "Feedingrobot spline")
66 schema:register(XMLValueType.INT, basePath .. ".splines.spline(?)#direction", "Feedingrobot spline direction")
67 schema:register(XMLValueType.BOOL, basePath .. ".splines.spline(?)#isFeeding", "Feedingrobot spline feeding part")
68 schema:register(XMLValueType.INT, basePath .. ".animatedObjects.animatedObject(?)#index", "Dependend animated object index")
69 schema:register(XMLValueType.INT, basePath .. ".animatedObjects.animatedObject(?)#direction", "Dependend animated object direction")
70 schema:setXMLSpecializationType()
71end

saveToXMLFile

Description
Definition
saveToXMLFile()
Code
231function PlaceableHusbandryFeedingRobot:saveToXMLFile(xmlFile, key, usedModNames)
232 local spec = self.spec_husbandryFeedingRobot
233 if spec.feedingRobot ~= nil then
234 spec.feedingRobot:saveToXMLFile(xmlFile, key, usedModNames)
235 end
236end

setOwnerFarmId

Description
Definition
setOwnerFarmId()
Code
240function PlaceableHusbandryFeedingRobot:setOwnerFarmId(superFunc, farmId)
241 superFunc(self, farmId)
242
243 local spec = self.spec_husbandryFeedingRobot
244 if spec.feedingRobot ~= nil then
245 spec.feedingRobot:setOwnerFarmId(farmId, true)
246 end
247end

updateFeeding

Description
Definition
updateFeeding()
Code
251function PlaceableHusbandryFeedingRobot:updateFeeding(superFunc)
252 local spec = self.spec_husbandryFeedingRobot
253 if self.isServer then
254 if spec.feedingRobot ~= nil then
255 spec.feedingRobot:createFoodMixture()
256 end
257 end
258
259 return superFunc(self)
260end

updateInfo

Description
Definition
updateInfo()
Code
277function PlaceableHusbandryFeedingRobot:updateInfo(superFunc, infoTable)
278 superFunc(self, infoTable)
279
280 local spec = self.spec_husbandryFeedingRobot
281
282 if spec.feedingRobot ~= nil then
283 spec.feedingRobot:updateInfo(infoTable)
284 end
285end