mirror of
https://github.com/Xevion/project-cybersyn.git
synced 2025-12-08 02:08:12 -06:00
fix issue 106 and bump version
This commit is contained in:
@@ -9,7 +9,7 @@ local bit_extract = bit32.extract
|
||||
local defines_front = defines.rail_direction.front
|
||||
local defines_back = defines.rail_direction.back
|
||||
local defines_straight = defines.rail_connection_direction.straight
|
||||
local search_type = {"straight-rail", "curved-rail"}
|
||||
local search_type = { "straight-rail", "curved-rail" }
|
||||
|
||||
|
||||
---@param layout_pattern (0|1|2|3)[]
|
||||
@@ -33,6 +33,7 @@ function is_refuel_layout_accepted(layout_pattern, layout)
|
||||
end
|
||||
return valid
|
||||
end
|
||||
|
||||
---@param layout_pattern (0|1|2|3)[]
|
||||
---@param layout (0|1|2)[]
|
||||
function is_layout_accepted(layout_pattern, layout)
|
||||
@@ -83,7 +84,6 @@ function remove_train(map_data, train_id, train)
|
||||
interface_raise_train_removed(train_id, train)
|
||||
end
|
||||
|
||||
|
||||
---@param map_data MapData
|
||||
---@param train Train
|
||||
function set_train_layout(map_data, train)
|
||||
@@ -166,7 +166,7 @@ end
|
||||
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]]
|
||||
local manifest = train.manifest --[[@as Manifest]]
|
||||
if not manifest[1] then return end
|
||||
local sign = mod_settings.invert_sign and 1 or -1
|
||||
|
||||
@@ -178,7 +178,7 @@ function set_p_wagon_combs(map_data, station, train)
|
||||
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)
|
||||
total_item_slots = max(train.item_slot_capacity - total_cargo_wagons * locked_slots, 1)
|
||||
else
|
||||
total_item_slots = train.item_slot_capacity
|
||||
end
|
||||
@@ -186,10 +186,10 @@ function set_p_wagon_combs(map_data, station, train)
|
||||
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))
|
||||
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)
|
||||
percent_slots_to_use_per_wagon = min(to_be_used_item_slots / total_item_slots, 1.0)
|
||||
end
|
||||
|
||||
local item_i = 1
|
||||
@@ -219,16 +219,20 @@ function set_p_wagon_combs(map_data, station, train)
|
||||
local signals = {}
|
||||
|
||||
local inv_filter_i = 1
|
||||
local item_slots_capacity = max(ceil((#inv - locked_slots)*percent_slots_to_use_per_wagon), 1)
|
||||
local item_slots_capacity = max(ceil((#inv - locked_slots) * percent_slots_to_use_per_wagon), 1)
|
||||
while item_slots_capacity > 0 and item_i <= #manifest do
|
||||
local do_inc
|
||||
if item.type == "item" then
|
||||
local stack_size = get_stack_size(map_data, item.name)
|
||||
local i = #signals + 1
|
||||
local count_to_fill = min(item_slots_capacity*stack_size, item_count)
|
||||
local slots_to_fill = ceil(count_to_fill/stack_size)
|
||||
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}
|
||||
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
|
||||
if comb then
|
||||
@@ -255,7 +259,7 @@ function set_p_wagon_combs(map_data, station, train)
|
||||
|
||||
if comb then
|
||||
if bit_extract(get_comb_params(comb).second_constant, SETTING_ENABLE_SLOT_BARRING) > 0 then
|
||||
inv.set_bar(inv_filter_i--[[@as uint]])
|
||||
inv.set_bar(inv_filter_i --[[@as uint]])
|
||||
train.has_filtered_wagon = true
|
||||
end
|
||||
set_combinator_output(map_data, comb, signals)
|
||||
@@ -270,7 +274,11 @@ function set_p_wagon_combs(map_data, station, train)
|
||||
if fluid.type == "fluid" then
|
||||
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}
|
||||
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
|
||||
@@ -323,7 +331,12 @@ 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 = sign*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)
|
||||
@@ -334,14 +347,13 @@ 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 = sign*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
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
---@param map_data MapData
|
||||
---@param refueler Refueler
|
||||
---@param train Train
|
||||
@@ -379,7 +391,7 @@ function set_refueler_combs(map_data, refueler, train)
|
||||
name = a.name
|
||||
end
|
||||
if game.item_prototypes[name] then
|
||||
wagon_signals[1] = {index = 1, signal = {type = "item", name = a.name}, count = 1}
|
||||
wagon_signals[1] = { index = 1, signal = { type = "item", name = a.name }, count = 1 }
|
||||
end
|
||||
end
|
||||
end
|
||||
@@ -388,10 +400,14 @@ function set_refueler_combs(map_data, refueler, train)
|
||||
if stack.valid_for_read then
|
||||
if comb then
|
||||
local i = #wagon_signals + 1
|
||||
wagon_signals[i] = {index = i, signal = {type = "item", name = stack.name}, count = stack.count}
|
||||
wagon_signals[i] = {
|
||||
index = i,
|
||||
signal = { type = "item", name = stack.name },
|
||||
count = stack.count
|
||||
}
|
||||
end
|
||||
local j = #signals + 1
|
||||
signals[j] = {index = j, signal = {type = "item", name = stack.name}, count = stack.count}
|
||||
signals[j] = { index = j, signal = { type = "item", name = stack.name }, count = stack.count }
|
||||
end
|
||||
end
|
||||
if comb then
|
||||
@@ -403,7 +419,6 @@ function set_refueler_combs(map_data, refueler, train)
|
||||
set_combinator_output(map_data, refueler.entity_comb, signals)
|
||||
end
|
||||
|
||||
|
||||
---@param map_data MapData
|
||||
---@param stop Station|Refueler
|
||||
function unset_wagon_combs(map_data, stop)
|
||||
@@ -421,7 +436,7 @@ function unset_wagon_combs(map_data, stop)
|
||||
end
|
||||
end
|
||||
|
||||
local type_filter = {"inserter", "pump", "arithmetic-combinator", "loader-1x1"}
|
||||
local type_filter = { "inserter", "pump", "arithmetic-combinator", "loader-1x1", "loader" }
|
||||
---@param map_data MapData
|
||||
---@param stop Station|Refueler
|
||||
---@param is_station_or_refueler boolean
|
||||
@@ -450,20 +465,20 @@ function reset_stop_layout(map_data, stop, is_station_or_refueler, forbidden_ent
|
||||
local area_delta
|
||||
local is_ver
|
||||
if stop_direction == defines.direction.north then
|
||||
search_area = {{middle_x - reach, middle_y}, {middle_x + reach, middle_y + 6}}
|
||||
area_delta = {0, 7}
|
||||
search_area = { { middle_x - reach, middle_y }, { middle_x + reach, middle_y + 6 } }
|
||||
area_delta = { 0, 7 }
|
||||
is_ver = true
|
||||
elseif stop_direction == defines.direction.east then
|
||||
search_area = {{middle_x - 6, middle_y - reach}, {middle_x, middle_y + reach}}
|
||||
area_delta = {-7, 0}
|
||||
search_area = { { middle_x - 6, middle_y - reach }, { middle_x, middle_y + reach } }
|
||||
area_delta = { -7, 0 }
|
||||
is_ver = false
|
||||
elseif stop_direction == defines.direction.south then
|
||||
search_area = {{middle_x - reach, middle_y - 6}, {middle_x + reach, middle_y}}
|
||||
area_delta = {0, -7}
|
||||
search_area = { { middle_x - reach, middle_y - 6 }, { middle_x + reach, middle_y } }
|
||||
area_delta = { 0, -7 }
|
||||
is_ver = true
|
||||
elseif stop_direction == defines.direction.west then
|
||||
search_area = {{middle_x, middle_y - reach}, {middle_x + 6, middle_y + reach}}
|
||||
area_delta = {7, 0}
|
||||
search_area = { { middle_x, middle_y - reach }, { middle_x + 6, middle_y + reach } }
|
||||
area_delta = { 7, 0 }
|
||||
is_ver = false
|
||||
else
|
||||
assert(false, "cybersyn: invalid stop direction")
|
||||
@@ -471,11 +486,12 @@ function reset_stop_layout(map_data, stop, is_station_or_refueler, forbidden_ent
|
||||
local length = 1
|
||||
---@type LuaEntity?
|
||||
local pre_rail = stop_rail
|
||||
local layout_pattern = {0}
|
||||
local layout_pattern = { 0 }
|
||||
local wagon_number = 0
|
||||
for i = 1, 112 do
|
||||
if pre_rail then
|
||||
local rail, rail_direction, rail_connection_direction = pre_rail.get_connected_rail({rail_direction = rail_direction_from_stop, rail_connection_direction = defines_straight})
|
||||
local rail, rail_direction, rail_connection_direction = pre_rail.get_connected_rail({
|
||||
rail_direction = rail_direction_from_stop, rail_connection_direction = defines_straight })
|
||||
if not rail or rail_connection_direction ~= defines_straight then
|
||||
-- There is a curved rail or break in the tracks at this point
|
||||
-- We are assuming it's a curved rail, maybe that's a bad assumption
|
||||
@@ -543,7 +559,7 @@ function reset_stop_layout(map_data, stop, is_station_or_refueler, forbidden_ent
|
||||
end
|
||||
end
|
||||
end
|
||||
elseif entity.type == "loader-1x1" then
|
||||
elseif entity.type == "loader-1x1" or entity.type == "loader" then
|
||||
if not supports_cargo then
|
||||
local direction = entity.direction
|
||||
if is_ver then
|
||||
@@ -627,7 +643,7 @@ end
|
||||
---@param forbidden_entity LuaEntity?
|
||||
---@param force boolean?
|
||||
local function resolve_update_stop_from_rail(map_data, entity, forbidden_entity, force)
|
||||
local id = entity.unit_number--[[@as uint]]
|
||||
local id = entity.unit_number --[[@as uint]]
|
||||
local is_station = true
|
||||
---@type Station|Refueler
|
||||
local stop = map_data.stations[id]
|
||||
@@ -661,7 +677,10 @@ function update_stop_from_rail(map_data, rail, forbidden_entity, force)
|
||||
resolve_update_stop_from_rail(map_data, entity, forbidden_entity, force)
|
||||
return
|
||||
end
|
||||
rail_back = rail_back.get_connected_rail({rail_direction = defines_back, rail_connection_direction = defines_straight})
|
||||
rail_back = rail_back.get_connected_rail({
|
||||
rail_direction = defines_back,
|
||||
rail_connection_direction = defines_straight
|
||||
})
|
||||
end
|
||||
if rail_front then
|
||||
local entity = rail_front.get_rail_segment_entity(defines_front, false)
|
||||
@@ -669,7 +688,10 @@ function update_stop_from_rail(map_data, rail, forbidden_entity, force)
|
||||
resolve_update_stop_from_rail(map_data, entity, forbidden_entity, force)
|
||||
return
|
||||
end
|
||||
rail_front = rail_front.get_connected_rail({rail_direction = defines_front, rail_connection_direction = defines_straight})
|
||||
rail_front = rail_front.get_connected_rail({
|
||||
rail_direction = defines_front,
|
||||
rail_connection_direction = defines_straight
|
||||
})
|
||||
end
|
||||
end
|
||||
end
|
||||
@@ -682,6 +704,7 @@ function update_stop_from_pump(map_data, pump, forbidden_entity)
|
||||
update_stop_from_rail(map_data, pump.pump_rail_target, forbidden_entity)
|
||||
end
|
||||
end
|
||||
|
||||
---@param map_data MapData
|
||||
---@param inserter LuaEntity
|
||||
---@param forbidden_entity LuaEntity?
|
||||
@@ -713,10 +736,10 @@ function update_stop_from_inserter(map_data, inserter, forbidden_entity)
|
||||
end
|
||||
-- We need to check secondary positions because of weird modded inserters.
|
||||
-- Mostly because of miniloaders not aligning with the hitbox of a rail by default.
|
||||
pos1.x = pos1.x + 0.2*(pos1.x - pos0.x)
|
||||
pos1.y = pos1.y + 0.2*(pos1.y - pos0.y)
|
||||
pos2.x = pos2.x + 0.2*(pos2.x - pos0.x)
|
||||
pos2.y = pos2.y + 0.2*(pos2.y - pos0.y)
|
||||
pos1.x = pos1.x + 0.2 * (pos1.x - pos0.x)
|
||||
pos1.y = pos1.y + 0.2 * (pos1.y - pos0.y)
|
||||
pos2.x = pos2.x + 0.2 * (pos2.x - pos0.x)
|
||||
pos2.y = pos2.y + 0.2 * (pos2.y - pos0.y)
|
||||
rails = surface.find_entities_filtered({
|
||||
type = search_type,
|
||||
position = pos1,
|
||||
@@ -732,6 +755,7 @@ function update_stop_from_inserter(map_data, inserter, forbidden_entity)
|
||||
update_stop_from_rail(map_data, rails[1], forbidden_entity)
|
||||
end
|
||||
end
|
||||
|
||||
---@param map_data MapData
|
||||
---@param loader LuaEntity
|
||||
---@param forbidden_entity LuaEntity?
|
||||
@@ -741,7 +765,7 @@ function update_stop_from_loader(map_data, loader, forbidden_entity)
|
||||
local loader_type = loader.loader_type
|
||||
local position = loader.position
|
||||
--check input/output direction and loader position, and case position and modify x or y by +/- 1 for search
|
||||
if loader_type == "input" then --loading train
|
||||
if loader_type == "input" then --loading train
|
||||
if direction == defines.direction.east then
|
||||
position.x = position.x + 1 -- input and facing east -> move on X axis 1 to the right
|
||||
elseif direction == defines.direction.south then
|
||||
|
||||
Reference in New Issue
Block a user