LUADOC - Farming Simulator 22

AIParameterLoadingStation

Parent
AIParameter
Functions

getLoadingStation

Description
Definition
getLoadingStation()
Code
100function AIParameterLoadingStation:getLoadingStation()
101 local loadingStation = NetworkUtil.getObject(self.loadingStationId)
102 if loadingStation ~= nil and loadingStation.owningPlaceable ~= nil and loadingStation.owningPlaceable:getIsSynchronized() then
103 return loadingStation
104 end
105
106 return nil
107end

getString

Description
Definition
getString()
Code
111function AIParameterLoadingStation:getString()
112 local loadingStation = NetworkUtil.getObject(self.loadingStationId)
113 if loadingStation ~= nil then
114 return loadingStation:getName()
115 end
116
117 return ""
118end

loadFromXMLFile

Description
Definition
loadFromXMLFile()
Code
45function AIParameterLoadingStation:loadFromXMLFile(xmlFile, key)
46 local loadingStationSavegameId = xmlFile:getInt(key .. "#stationId")
47 local stationIndex = xmlFile:getInt(key .. "#stationIndex")
48
49 if loadingStationSavegameId ~= nil and stationIndex ~= nil then
50 if not self:setLoadingStationFromSavegameId(loadingStationSavegameId, stationIndex) then
51 g_messageCenter:subscribeOneshot(MessageType.LOADED_ALL_SAVEGAME_PLACEABLES, self.onPlaceableLoaded, self, {loadingStationSavegameId, stationIndex})
52 end
53 end
54end

new

Description
Definition
new()
Code
16function AIParameterLoadingStation.new(customMt)
17 local self = AIParameter.new(customMt or AIParameterLoadingStation_mt)
18
19 self.type = AIParameterType.LOADING_STATION
20
21 self.loadingStationId = nil
22 self.loadingStationIds = {}
23
24 return self
25end

onPlaceableLoaded

Description
Definition
onPlaceableLoaded()
Code
58function AIParameterLoadingStation:onPlaceableLoaded(args)
59 self:setLoadingStationFromSavegameId(args[1], args[2])
60end

readStream

Description
Definition
readStream()
Code
78function AIParameterLoadingStation:readStream(streamId, connection)
79 if streamReadBool(streamId) then
80 self.loadingStationId = NetworkUtil.readNodeObjectId(streamId)
81 end
82end

saveToXMLFile

Description
Definition
saveToXMLFile()
Code
29function AIParameterLoadingStation:saveToXMLFile(xmlFile, key, usedModNames)
30 local loadingStation = self:getLoadingStation()
31 if loadingStation ~= nil then
32 local owningPlaceable = loadingStation.owningPlaceable
33 if owningPlaceable ~= nil and owningPlaceable.currentSavegameId ~= nil then
34 local index = g_currentMission.storageSystem:getPlaceableLoadingStationIndex(owningPlaceable, loadingStation)
35 if index ~= nil then
36 xmlFile:setInt(key .. "#stationId", owningPlaceable.currentSavegameId)
37 xmlFile:setInt(key .. "#stationIndex", index)
38 end
39 end
40 end
41end

setLoadingStation

Description
Definition
setLoadingStation()
Code
94function AIParameterLoadingStation:setLoadingStation(loadingStation)
95 self.loadingStationId = NetworkUtil.getObjectId(loadingStation)
96end

setLoadingStationFromSavegameId

Description
Definition
setLoadingStationFromSavegameId()
Code
64function AIParameterLoadingStation:setLoadingStationFromSavegameId(savegameId, index)
65 local placeable = g_currentMission.placeableSystem:getPlaceableBySavegameId(savegameId)
66 if placeable ~= nil then
67 local loadingStation = g_currentMission.storageSystem:getPlaceableLoadingStation(placeable, index)
68 self:setLoadingStation(loadingStation)
69
70 return true
71 end
72
73 return false
74end

setNextItem

Description
Definition
setNextItem()
Code
141function AIParameterLoadingStation:setNextItem()
142 local nextIndex = 0
143 for k, loadingStationId in ipairs(self.loadingStationIds) do
144 if loadingStationId == self.loadingStationId then
145 nextIndex = k + 1
146 end
147 end
148
149 if nextIndex > #self.loadingStationIds then
150 nextIndex = 1
151 end
152
153 self.loadingStationId = self.loadingStationIds[nextIndex]
154end

setPreviousItem

Description
Definition
setPreviousItem()
Code
158function AIParameterLoadingStation:setPreviousItem()
159 local previousIndex = 0
160 for k, loadingStationId in ipairs(self.loadingStationIds) do
161 if loadingStationId == self.loadingStationId then
162 previousIndex = k - 1
163 end
164 end
165
166 if previousIndex < 1 then
167 previousIndex = #self.loadingStationIds
168 end
169
170 self.loadingStationId = self.loadingStationIds[previousIndex]
171end

setValidLoadingStations

Description
Definition
setValidLoadingStations()
Code
122function AIParameterLoadingStation:setValidLoadingStations(loadingStationIds)
123 self.loadingStationIds = {}
124 local nextLoadingStationId
125
126 for _, loadingStation in ipairs(loadingStationIds) do
127 local id = NetworkUtil.getObjectId(loadingStation)
128 if id ~= nil then
129 if id == self.loadingStationId then
130 nextLoadingStationId = id
131 end
132 table.insert(self.loadingStationIds, id)
133 end
134 end
135
136 self.loadingStationId = nextLoadingStationId or self.loadingStationIds[1]
137end

validate

Description
Definition
validate()
Code
175function AIParameterLoadingStation:validate(fillTypeIndex, farmId)
176 if self.loadingStationId == nil then
177 return false, g_i18n:getText("ai_validationErrorNoLoadingStation")
178 end
179
180 local loadingStation = self:getLoadingStation()
181 if loadingStation == nil then
182 return false, g_i18n:getText("ai_validationErrorLoadingStationDoesNotExistAnymore")
183 end
184
185 if fillTypeIndex ~= nil then
186 if not loadingStation:getIsFillTypeAISupported(fillTypeIndex) then
187 return false, g_i18n:getText("ai_validationErrorFillTypeNotSupportedByLoadingStation")
188 elseif loadingStation:getFillLevel(fillTypeIndex, farmId) <= 0 then
189 return false, g_i18n:getText("ai_validationErrorLoadingStationIsEmpty")
190 end
191 end
192
193 return true, nil
194end

writeStream

Description
Definition
writeStream()
Code
86function AIParameterLoadingStation:writeStream(streamId, connection)
87 if streamWriteBool(streamId, self.loadingStationId ~= nil) then
88 NetworkUtil.writeNodeObjectId(streamId, self.loadingStationId)
89 end
90end