-- sort best matching train to top
table.sort(filtered_trains, function(a, b)
-- fix 2.5.0: attempt to index field 'surface' (a nil value)
if a.surface == nil or b.surface == nil then
return false
-- if A is on the same surface as the stop and B is not, return true
elseif a.surface.index == stop_surface_index and b.surface.index ~= stop_surface_index then
return true
-- if B is on the same surface as the stop and A is not, return false
elseif b.surface.index == stop_surface_index and a.surface.index ~= stop_surface_index then
return false
-- else do normal checks (either both stops are on the same or on a different surface)
elseif a.depot_priority ~= b.depot_priority then
--sort by priority
return a.depot_priority > b.depot_priority
elseif a.inventory_size ~= b.inventory_size and a.inventory_size >= size then
--sort inventories capable of whole deliveries
-- return not(b.inventory_size => size and a.inventory_size > b.inventory_size)
return b.inventory_size < size or a.inventory_size < b.inventory_size
elseif a.inventory_size ~= b.inventory_size and a.inventory_size < size then
--sort inventories for partial deliveries
-- return not(b.inventory_size >= size or b.inventory_size > a.inventory_size)
return b.inventory_size < size and b.inventory_size < a.inventory_size
else
-- if one stop is on the same surface and the other is not, return
if not a.provider_distance then return false end
if a.provider_distance and not b.provider_distance then return true end
return a.provider_distance < b.provider_distance
end
Just a polite suggestion for speeding up the fix. ;-)