Experimental 1.2.2 (#21)

---------------------------------------------------------------------------------------------------
Version: 1.2.2
Date: 2022-12-29
  Features:
    - Added a station combinator setting to enable or disable the inactivity condition in a train's orders, disabled by default (but not in <=1.2.1 worlds)
    - Added a depot combinator setting to enable depot bypass, enabled by default
    - Added a depot combinator setting to force trains to park at the same depot, enabled by default
    - Added network "each" for depots
    - Added a map setting to modify the default locked slots per cargo wagon value
    - Added a map setting to modify the default priority value
    - Added a map setting to allow trains with cargo at depots, disabled by default
  Changes:
    - Inverted the sign of combinator outputs, a map setting has been added to maintain backwards compatibility with <=1.2.1 worlds
    - Overhauled the wagon control combinator algorithm to spread items out between cargo wagons
    - Trains with cargo held in the depot now check if they have been emptied and reset when they have
    - Cargo capacity is now prioritized over distance when choosing trains
    - Increased the default request threshold to 2000
    - Improved English localization
  Bugfixes:
    - Fixed a bug where trains with cargo sometimes weren't getting held at depots
    - Fixed a crash caused by changing a station combinator to the "each" network during a bad tick
    - Fixed a crash when changing a refueler away from network each
    - Multiple rare bugs and crashes relating to wagon control combinators are fixed
    - Fixed a bug with refueler direct orders not being applied after moving through a space elevator
    - Fixed a bug where filtered slots sometimes weren't being removed
---------------------------------------------------------------------------------------------------
This commit is contained in:
Monica Moniot
2022-12-29 10:02:07 -06:00
committed by GitHub
parent c48d1d3025
commit 7d2f0c2ccd
19 changed files with 833 additions and 511 deletions

View File

@@ -3,37 +3,10 @@ local area = require("__flib__.area")
local abs = math.abs
local floor = math.floor
local ceil = math.ceil
local min = math.min
local max = math.max
local function table_compare(t0, t1)
if #t0 ~= #t1 then
return false
end
for i = 0, #t0 do
if t0[i] ~= t1[i] then
return false
end
end
return true
end
---@param a any[]
---@param i uint
local function iterr(a, i)
i = i + 1
if i <= #a then
local r = a[#a - i + 1]
return i, r
else
return nil, nil
end
end
---@param a any[]
local function irpairs(a)
return iterr, a, 0
end
---@param layout_pattern (0|1|2|3)[]
---@param layout (0|1|2)[]
function is_refuel_layout_accepted(layout_pattern, layout)
@@ -81,11 +54,6 @@ end
---@param train_id uint
---@param train Train
function remove_train(map_data, train_id, train)
local parked_at_depot_id = train.parked_at_depot_id
if parked_at_depot_id then
local depot = map_data.depots[parked_at_depot_id]
depot.available_train_id = nil
end
remove_available_train(map_data, train_id, train)
local layout_id = train.layout_id
@@ -191,9 +159,31 @@ function set_p_wagon_combs(map_data, station, train)
if not station.wagon_combs or not next(station.wagon_combs) then return end
local carriages = train.entity.carriages
local manifest = train.manifest--[[@as Manifest]]
if not manifest[1] then return end
local sign = mod_settings.invert_sign and 1 or -1
local is_reversed = get_train_direction(station.entity_stop, train.entity)
local locked_slots = station.locked_slots
local percent_slots_to_use_per_wagon = 1.0
if train.item_slot_capacity > 0 then
local total_item_slots
if locked_slots > 0 then
local total_cargo_wagons = #train.entity.cargo_wagons
total_item_slots = max(train.item_slot_capacity - total_cargo_wagons*locked_slots, 1)
else
total_item_slots = train.item_slot_capacity
end
local to_be_used_item_slots = 0
for i, item in ipairs(train.manifest) do
if item.type == "item" then
to_be_used_item_slots = to_be_used_item_slots + ceil(item.count/get_stack_size(map_data, item.name))
end
end
percent_slots_to_use_per_wagon = min(to_be_used_item_slots/total_item_slots, 1.0)
end
local item_i = 1
local item = manifest[item_i]
local item_count = item.count
@@ -215,39 +205,29 @@ function set_p_wagon_combs(map_data, station, train)
end
end
if carriage.type == "cargo-wagon" and item_i <= #manifest then
local signals = {}
local inv = carriage.get_inventory(defines.inventory.cargo_wagon)
if inv then
local signals = {}
local inv_filter_i = 1
local item_slots_capacity = #inv - station.locked_slots
local item_slots_capacity = max(ceil((#inv - locked_slots)*percent_slots_to_use_per_wagon), 1)
while item_slots_capacity > 0 do
local do_inc = false
local do_inc
if item.type == "item" then
local stack_size = get_stack_size(map_data, item.name)
local item_slots = ceil(item_count/stack_size)
local i = #signals + 1
local slots_to_filter
if item_slots > item_slots_capacity then
if comb then
signals[i] = {index = i, signal = {type = item.type, name = item.name}, count = item_slots_capacity*stack_size}
end
item_slots_capacity = 0
item_count = item_count - item_slots_capacity*stack_size
slots_to_filter = item_slots_capacity
else
if comb then
signals[i] = {index = i, signal = {type = item.type, name = item.name}, count = item_count}
end
item_slots_capacity = item_slots_capacity - item_slots
do_inc = true
slots_to_filter = item_slots
end
for j = 1, slots_to_filter do
local count_to_fill = min(item_slots_capacity*stack_size, item_count)
local slots_to_fill = ceil(count_to_fill/stack_size)
signals[i] = {index = i, signal = {type = item.type, name = item.name}, count = sign*count_to_fill}
item_count = item_count - count_to_fill
item_slots_capacity = item_slots_capacity - slots_to_fill
for j = 1, slots_to_fill do
inv.set_filter(inv_filter_i, item.name)
inv_filter_i = inv_filter_i + 1
end
train.has_filtered_wagon = true
do_inc = item_count == 0
else
do_inc = true
end
@@ -271,27 +251,18 @@ function set_p_wagon_combs(map_data, station, train)
local signals = {}
while fluid_capacity > 0 do
local do_inc = false
local do_inc
if fluid.type == "fluid" then
if fluid_count > fluid_capacity then
if comb then
signals[1] = {index = 1, signal = {type = fluid.type, name = fluid.name}, count = fluid_capacity}
end
fluid_capacity = 0
fluid_count = fluid_count - fluid_capacity
else
if comb then
signals[1] = {index = 1, signal = {type = fluid.type, name = fluid.name}, count = item_count}
end
fluid_capacity = fluid_capacity - fluid_count
fluid_i = fluid_i + 1
if fluid_i <= #manifest then
fluid = manifest[fluid_i]
fluid_count = fluid.count
end
end
break
local count_to_fill = min(fluid_count, fluid_capacity)
signals[1] = {index = 1, signal = {type = fluid.type, name = fluid.name}, count = sign*count_to_fill}
fluid_count = fluid_count - count_to_fill
fluid_capacity = 0
do_inc = fluid_count == 0
else
do_inc = true
end
if do_inc then
fluid_i = fluid_i + 1
if fluid_i <= #manifest then
fluid = manifest[fluid_i]
@@ -315,6 +286,7 @@ function set_r_wagon_combs(map_data, station, train)
local carriages = train.entity.carriages
local is_reversed = get_train_direction(station.entity_stop, train.entity)
local sign = mod_settings.invert_sign and -1 or 1
local ivpairs = is_reversed and irpairs or ipairs
for carriage_i, carriage in ivpairs(carriages) do
@@ -336,7 +308,7 @@ function set_r_wagon_combs(map_data, station, train)
local stack = inv[stack_i]
if stack.valid_for_read then
local i = #signals + 1
signals[i] = {index = i, signal = {type = "item", name = stack.name}, count = -stack.count}
signals[i] = {index = i, signal = {type = "item", name = stack.name}, count = sign*stack.count}
end
end
set_combinator_output(map_data, comb, signals)
@@ -347,7 +319,7 @@ function set_r_wagon_combs(map_data, station, train)
local inv = carriage.get_fluid_contents()
for fluid_name, count in pairs(inv) do
local i = #signals + 1
signals[i] = {index = i, signal = {type = "fluid", name = fluid_name}, count = -floor(count)}
signals[i] = {index = i, signal = {type = "fluid", name = fluid_name}, count = sign*floor(count)}
end
set_combinator_output(map_data, comb, signals)
end