LUADOC - Farming Simulator 22

AIParameterUnloadingStation

Parent
AIParameter
Functions

getString

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

getUnloadingStation

Description
Definition
getUnloadingStation()
Code
100function AIParameterUnloadingStation:getUnloadingStation()
101 local unloadingStation = NetworkUtil.getObject(self.unloadingStationId)
102 if unloadingStation ~= nil and unloadingStation.owningPlaceable ~= nil and unloadingStation.owningPlaceable:getIsSynchronized() then
103 return unloadingStation
104 end
105
106 return nil
107end

loadFromXMLFile

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

new

Description
Definition
new()
Code
16function AIParameterUnloadingStation.new(customMt)
17 local self = AIParameter.new(customMt or AIParameterUnloadingStation_mt)
18
19 self.type = AIParameterType.UNLOADING_STATION
20
21 self.unloadingStationId = nil
22 self.unloadingStationIds = {}
23
24 return self
25end

onPlaceableLoaded

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

readStream

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

saveToXMLFile

Description
Definition
saveToXMLFile()
Code
29function AIParameterUnloadingStation:saveToXMLFile(xmlFile, key, usedModNames)
30 local unloadingStation = self:getUnloadingStation()
31 if unloadingStation ~= nil then
32 local owningPlaceable = unloadingStation.owningPlaceable
33 if owningPlaceable ~= nil and owningPlaceable.currentSavegameId ~= nil then
34 local index = g_currentMission.storageSystem:getPlaceableUnloadingStationIndex(owningPlaceable, unloadingStation)
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

setNextItem

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

setPreviousItem

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

setUnloadingStation

Description
Definition
setUnloadingStation()
Code
94function AIParameterUnloadingStation:setUnloadingStation(unloadingStation)
95 self.unloadingStationId = NetworkUtil.getObjectId(unloadingStation)
96end

setUnloadingStationFromSavegameId

Description
Definition
setUnloadingStationFromSavegameId()
Code
64function AIParameterUnloadingStation:setUnloadingStationFromSavegameId(savegameId, index)
65 local placeable = g_currentMission.placeableSystem:getPlaceableBySavegameId(savegameId)
66 if placeable ~= nil then
67 local unloadingStation = g_currentMission.storageSystem:getPlaceableUnloadingStation(placeable, index)
68 self:setUnloadingStation(unloadingStation)
69
70 return true
71 end
72
73 return false
74end

setValidUnloadingStations

Description
Definition
setValidUnloadingStations()
Code
122function AIParameterUnloadingStation:setValidUnloadingStations(unloadingStations)
123 self.unloadingStationIds = {}
124 local nextUnloadingStationId
125
126 for _, unloadingStation in ipairs(unloadingStations) do
127 local id = NetworkUtil.getObjectId(unloadingStation)
128 if id ~= nil then
129 if id == self.unloadingStationId then
130 nextUnloadingStationId = id
131 end
132 table.insert(self.unloadingStationIds, id)
133 end
134 end
135
136
137 self.unloadingStationId = nextUnloadingStationId or self.unloadingStationIds[1]
138end

validate

Description
Definition
validate()
Code
176function AIParameterUnloadingStation:validate(fillTypeIndex, farmId)
177 if self.unloadingStationId == nil then
178 return false, g_i18n:getText("ai_validationErrorNoUnloadingStation")
179 end
180
181 local unloadingStation = self:getUnloadingStation()
182 if unloadingStation == nil then
183 return false, g_i18n:getText("ai_validationErrorUnloadingStationDoesNotExistAnymore")
184 end
185
186 if fillTypeIndex ~= nil then
187 if not unloadingStation:getIsFillTypeAISupported(fillTypeIndex) then
188 return false, g_i18n:getText("ai_validationErrorFillTypeNotSupportedByUnloadingStation")
189 end
190 if unloadingStation:getFreeCapacity(fillTypeIndex, farmId) <= 0 then
191 return false, g_i18n:getText("ai_validationErrorUnloadingStationIsFull")
192 end
193 end
194
195 return true, nil
196end

writeStream

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