LUADOC - Farming Simulator 19

StorageSystem

Functions

addLoadingStation

Description
Definition
addLoadingStation()
Code
83function StorageSystem:addLoadingStation(station)
84 if station ~= nil then
85 self.loadingStations[station] = station
86 return true
87 end
88
89 return false
90end

addStorage

Description
Definition
addStorage()
Code
30function StorageSystem:addStorage(storage)
31 if storage ~= nil then
32 self.storages[storage] = storage
33 return true
34 end
35
36 return false
37end

addStorageToLoadingStations

Description
Definition
addStorageToLoadingStations()
Code
111function StorageSystem:addStorageToLoadingStations(storage, loadingStations, farmId)
112 local success = false
113 for _, loadingStation in pairs(loadingStations) do
114 if loadingStation:addSourceStorage(storage) then
115 success = true
116 end
117 end
118
119 return success
120end

addStorageToUnloadingStations

Description
Definition
addStorageToUnloadingStations()
Code
182function StorageSystem:addStorageToUnloadingStations(storage, unloadingStations)
183 local success = false
184 for _, unloadingStation in pairs(unloadingStations) do
185 if unloadingStation:addTargetStorage(storage) then
186 success = true;
187 end
188 end
189
190 return success
191end

addUnloadingStation

Description
Definition
addUnloadingStation()
Code
152function StorageSystem:addUnloadingStation(station)
153 if station ~= nil then
154 self.unloadingStations[station] = station
155 g_messageCenter:publish(MessageType.UNLOADING_STATIONS_CHANGED)
156 return true
157 end
158
159 return false
160end

getIsStationCompatible

Description
Definition
getIsStationCompatible()
Code
222function StorageSystem:getIsStationCompatible(station, storage, farmId)
223 local hasRadius = station.storageRadius ~= nil
224 local supportsExtension = station.supportsExtension == nil or station.supportsExtension
225 local canAccessTarget = self.accessHandler:canFarmAccess(farmId, station)
226
227 if hasRadius and supportsExtension and canAccessTarget then
228 local distance = calcDistanceFrom(storage.rootNode, station.rootNode)
229
230 if distance < station.storageRadius then
231 return true
232 end
233 end
234
235 return false
236end

getLoadingStations

Description
Definition
getLoadingStations()
Code
105function StorageSystem:getLoadingStations()
106 return self.loadingStations
107end

getLoadingStationsInRange

Description
Definition
getLoadingStationsInRange()
Code
137function StorageSystem:getLoadingStationsInRange(stations, storage, farmId)
138 stations = stations or self.loadingStations
139 local stationsInRange = {}
140
141 for station, _ in pairs(stations) do
142 if self:getIsStationCompatible(station, storage, farmId) and not station.isBuyingPoint then
143 table.insert(stationsInRange, station)
144 end
145 end
146
147 return stationsInRange
148end

getStorages

Description
Definition
getStorages()
Code
62function StorageSystem:getStorages()
63 return self.storages
64end

getStoragesInRange

Description
Definition
getStoragesInRange()
Code
68function StorageSystem:getStoragesInRange(station, storages, farmId)
69 storages = storages or self.storages
70 local storagesInRange = {}
71
72 for storage, _ in pairs(storages) do
73 if self:getIsStationCompatible(station, storage, farmId) then
74 table.insert(storagesInRange, storage)
75 end
76 end
77
78 return storagesInRange
79end

getUnloadingStations

Description
Definition
getUnloadingStations()
Code
176function StorageSystem:getUnloadingStations()
177 return self.unloadingStations
178end

getUnloadingStationsInRange

Description
Definition
getUnloadingStationsInRange()
Code
208function StorageSystem:getUnloadingStationsInRange(stations, storage, farmId)
209 stations = stations or self.unloadingStations
210 local stationsInRange = {}
211 for station, _ in pairs(stations) do
212 if self:getIsStationCompatible(station, storage, farmId) then
213 table.insert(stationsInRange, station)
214 end
215 end
216
217 return stationsInRange
218end

hasStorage

Description
Definition
hasStorage()
Code
52function StorageSystem:hasStorage(storage)
53 if storage ~= nil then
54 return self.storages[storage] ~= nil
55 end
56
57 return false
58end

new

Description
Definition
new()
Code
17function StorageSystem:new(accessHandler, customMt)
18 local self = setmetatable({}, customMt or StorageSystem_mt)
19
20 self.accessHandler = accessHandler
21 self.loadingStations = {}
22 self.unloadingStations = {}
23 self.storages = {}
24
25 return self
26end

removeLoadingStation

Description
Definition
removeLoadingStation()
Code
94function StorageSystem:removeLoadingStation(station)
95 if station ~= nil then
96 self.loadingStations[station] = nil
97 return true
98 end
99
100 return false
101end

removeStorage

Description
Definition
removeStorage()
Code
41function StorageSystem:removeStorage(storage)
42 if storage ~= nil then
43 self.storages[storage] = nil
44 return true
45 end
46
47 return false
48end

removeStorageFromLoadingStations

Description
Definition
removeStorageFromLoadingStations()
Code
124function StorageSystem:removeStorageFromLoadingStations(storage, loadingStations)
125 local success = false
126 for _, loadingStation in pairs(loadingStations) do
127 if loadingStation:removeSourceStorage(storage) then
128 success = true
129 end
130 end
131
132 return success
133end

removeStorageFromUnloadingStations

Description
Definition
removeStorageFromUnloadingStations()
Code
195function StorageSystem:removeStorageFromUnloadingStations(storage, unloadingStations)
196 local success = false
197 for _, unloadingStation in pairs(unloadingStations) do
198 if unloadingStation:removeTargetStorage(storage) then
199 success = true;
200 end
201 end
202
203 return success
204end

removeUnloadingStation

Description
Definition
removeUnloadingStation()
Code
164function StorageSystem:removeUnloadingStation(station)
165 if station ~= nil then
166 self.unloadingStations[station] = nil
167 g_messageCenter:publish(MessageType.UNLOADING_STATIONS_CHANGED)
168 return true
169 end
170
171 return false
172end