mirror of
https://github.com/Xevion/project-cybersyn.git
synced 2025-12-13 18:12:40 -06:00
fix issue 106 and bump version
This commit is contained in:
@@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"name": "cybersyn",
|
"name": "cybersyn",
|
||||||
"version": "1.2.16",
|
"version": "1.2.17",
|
||||||
"title": "Project Cybersyn",
|
"title": "Project Cybersyn",
|
||||||
"author": "Mami",
|
"author": "Mami",
|
||||||
"factorio_version": "1.1",
|
"factorio_version": "1.1",
|
||||||
|
|||||||
@@ -9,7 +9,7 @@ local bit_extract = bit32.extract
|
|||||||
local defines_front = defines.rail_direction.front
|
local defines_front = defines.rail_direction.front
|
||||||
local defines_back = defines.rail_direction.back
|
local defines_back = defines.rail_direction.back
|
||||||
local defines_straight = defines.rail_connection_direction.straight
|
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)[]
|
---@param layout_pattern (0|1|2|3)[]
|
||||||
@@ -33,6 +33,7 @@ function is_refuel_layout_accepted(layout_pattern, layout)
|
|||||||
end
|
end
|
||||||
return valid
|
return valid
|
||||||
end
|
end
|
||||||
|
|
||||||
---@param layout_pattern (0|1|2|3)[]
|
---@param layout_pattern (0|1|2|3)[]
|
||||||
---@param layout (0|1|2)[]
|
---@param layout (0|1|2)[]
|
||||||
function is_layout_accepted(layout_pattern, layout)
|
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)
|
interface_raise_train_removed(train_id, train)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
||||||
---@param map_data MapData
|
---@param map_data MapData
|
||||||
---@param train Train
|
---@param train Train
|
||||||
function set_train_layout(map_data, train)
|
function set_train_layout(map_data, train)
|
||||||
@@ -166,7 +166,7 @@ end
|
|||||||
function set_p_wagon_combs(map_data, station, train)
|
function set_p_wagon_combs(map_data, station, train)
|
||||||
if not station.wagon_combs or not next(station.wagon_combs) then return end
|
if not station.wagon_combs or not next(station.wagon_combs) then return end
|
||||||
local carriages = train.entity.carriages
|
local carriages = train.entity.carriages
|
||||||
local manifest = train.manifest--[[@as Manifest]]
|
local manifest = train.manifest --[[@as Manifest]]
|
||||||
if not manifest[1] then return end
|
if not manifest[1] then return end
|
||||||
local sign = mod_settings.invert_sign and 1 or -1
|
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
|
local total_item_slots
|
||||||
if locked_slots > 0 then
|
if locked_slots > 0 then
|
||||||
local total_cargo_wagons = #train.entity.cargo_wagons
|
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
|
else
|
||||||
total_item_slots = train.item_slot_capacity
|
total_item_slots = train.item_slot_capacity
|
||||||
end
|
end
|
||||||
@@ -186,10 +186,10 @@ function set_p_wagon_combs(map_data, station, train)
|
|||||||
local to_be_used_item_slots = 0
|
local to_be_used_item_slots = 0
|
||||||
for i, item in ipairs(train.manifest) do
|
for i, item in ipairs(train.manifest) do
|
||||||
if item.type == "item" then
|
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
|
||||||
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
|
end
|
||||||
|
|
||||||
local item_i = 1
|
local item_i = 1
|
||||||
@@ -219,16 +219,20 @@ function set_p_wagon_combs(map_data, station, train)
|
|||||||
local signals = {}
|
local signals = {}
|
||||||
|
|
||||||
local inv_filter_i = 1
|
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
|
while item_slots_capacity > 0 and item_i <= #manifest do
|
||||||
local do_inc
|
local do_inc
|
||||||
if item.type == "item" then
|
if item.type == "item" then
|
||||||
local stack_size = get_stack_size(map_data, item.name)
|
local stack_size = get_stack_size(map_data, item.name)
|
||||||
local i = #signals + 1
|
local i = #signals + 1
|
||||||
local count_to_fill = min(item_slots_capacity*stack_size, item_count)
|
local count_to_fill = min(item_slots_capacity * stack_size, item_count)
|
||||||
local slots_to_fill = ceil(count_to_fill/stack_size)
|
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_count = item_count - count_to_fill
|
||||||
item_slots_capacity = item_slots_capacity - slots_to_fill
|
item_slots_capacity = item_slots_capacity - slots_to_fill
|
||||||
if comb then
|
if comb then
|
||||||
@@ -255,7 +259,7 @@ function set_p_wagon_combs(map_data, station, train)
|
|||||||
|
|
||||||
if comb then
|
if comb then
|
||||||
if bit_extract(get_comb_params(comb).second_constant, SETTING_ENABLE_SLOT_BARRING) > 0 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
|
train.has_filtered_wagon = true
|
||||||
end
|
end
|
||||||
set_combinator_output(map_data, comb, signals)
|
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
|
if fluid.type == "fluid" then
|
||||||
local count_to_fill = min(fluid_count, fluid_capacity)
|
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_count = fluid_count - count_to_fill
|
||||||
fluid_capacity = 0
|
fluid_capacity = 0
|
||||||
do_inc = fluid_count == 0
|
do_inc = fluid_count == 0
|
||||||
@@ -323,7 +331,12 @@ function set_r_wagon_combs(map_data, station, train)
|
|||||||
local stack = inv[stack_i]
|
local stack = inv[stack_i]
|
||||||
if stack.valid_for_read then
|
if stack.valid_for_read then
|
||||||
local i = #signals + 1
|
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
|
||||||
end
|
end
|
||||||
set_combinator_output(map_data, comb, signals)
|
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()
|
local inv = carriage.get_fluid_contents()
|
||||||
for fluid_name, count in pairs(inv) do
|
for fluid_name, count in pairs(inv) do
|
||||||
local i = #signals + 1
|
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
|
end
|
||||||
set_combinator_output(map_data, comb, signals)
|
set_combinator_output(map_data, comb, signals)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
||||||
---@param map_data MapData
|
---@param map_data MapData
|
||||||
---@param refueler Refueler
|
---@param refueler Refueler
|
||||||
---@param train Train
|
---@param train Train
|
||||||
@@ -379,7 +391,7 @@ function set_refueler_combs(map_data, refueler, train)
|
|||||||
name = a.name
|
name = a.name
|
||||||
end
|
end
|
||||||
if game.item_prototypes[name] then
|
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
|
end
|
||||||
end
|
end
|
||||||
@@ -388,10 +400,14 @@ function set_refueler_combs(map_data, refueler, train)
|
|||||||
if stack.valid_for_read then
|
if stack.valid_for_read then
|
||||||
if comb then
|
if comb then
|
||||||
local i = #wagon_signals + 1
|
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
|
end
|
||||||
local j = #signals + 1
|
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
|
||||||
end
|
end
|
||||||
if comb then
|
if comb then
|
||||||
@@ -403,7 +419,6 @@ function set_refueler_combs(map_data, refueler, train)
|
|||||||
set_combinator_output(map_data, refueler.entity_comb, signals)
|
set_combinator_output(map_data, refueler.entity_comb, signals)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
||||||
---@param map_data MapData
|
---@param map_data MapData
|
||||||
---@param stop Station|Refueler
|
---@param stop Station|Refueler
|
||||||
function unset_wagon_combs(map_data, stop)
|
function unset_wagon_combs(map_data, stop)
|
||||||
@@ -421,7 +436,7 @@ function unset_wagon_combs(map_data, stop)
|
|||||||
end
|
end
|
||||||
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 map_data MapData
|
||||||
---@param stop Station|Refueler
|
---@param stop Station|Refueler
|
||||||
---@param is_station_or_refueler boolean
|
---@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 area_delta
|
||||||
local is_ver
|
local is_ver
|
||||||
if stop_direction == defines.direction.north then
|
if stop_direction == defines.direction.north then
|
||||||
search_area = {{middle_x - reach, middle_y}, {middle_x + reach, middle_y + 6}}
|
search_area = { { middle_x - reach, middle_y }, { middle_x + reach, middle_y + 6 } }
|
||||||
area_delta = {0, 7}
|
area_delta = { 0, 7 }
|
||||||
is_ver = true
|
is_ver = true
|
||||||
elseif stop_direction == defines.direction.east then
|
elseif stop_direction == defines.direction.east then
|
||||||
search_area = {{middle_x - 6, middle_y - reach}, {middle_x, middle_y + reach}}
|
search_area = { { middle_x - 6, middle_y - reach }, { middle_x, middle_y + reach } }
|
||||||
area_delta = {-7, 0}
|
area_delta = { -7, 0 }
|
||||||
is_ver = false
|
is_ver = false
|
||||||
elseif stop_direction == defines.direction.south then
|
elseif stop_direction == defines.direction.south then
|
||||||
search_area = {{middle_x - reach, middle_y - 6}, {middle_x + reach, middle_y}}
|
search_area = { { middle_x - reach, middle_y - 6 }, { middle_x + reach, middle_y } }
|
||||||
area_delta = {0, -7}
|
area_delta = { 0, -7 }
|
||||||
is_ver = true
|
is_ver = true
|
||||||
elseif stop_direction == defines.direction.west then
|
elseif stop_direction == defines.direction.west then
|
||||||
search_area = {{middle_x, middle_y - reach}, {middle_x + 6, middle_y + reach}}
|
search_area = { { middle_x, middle_y - reach }, { middle_x + 6, middle_y + reach } }
|
||||||
area_delta = {7, 0}
|
area_delta = { 7, 0 }
|
||||||
is_ver = false
|
is_ver = false
|
||||||
else
|
else
|
||||||
assert(false, "cybersyn: invalid stop direction")
|
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
|
local length = 1
|
||||||
---@type LuaEntity?
|
---@type LuaEntity?
|
||||||
local pre_rail = stop_rail
|
local pre_rail = stop_rail
|
||||||
local layout_pattern = {0}
|
local layout_pattern = { 0 }
|
||||||
local wagon_number = 0
|
local wagon_number = 0
|
||||||
for i = 1, 112 do
|
for i = 1, 112 do
|
||||||
if pre_rail then
|
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
|
if not rail or rail_connection_direction ~= defines_straight then
|
||||||
-- There is a curved rail or break in the tracks at this point
|
-- 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
|
-- 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
|
end
|
||||||
end
|
end
|
||||||
elseif entity.type == "loader-1x1" then
|
elseif entity.type == "loader-1x1" or entity.type == "loader" then
|
||||||
if not supports_cargo then
|
if not supports_cargo then
|
||||||
local direction = entity.direction
|
local direction = entity.direction
|
||||||
if is_ver then
|
if is_ver then
|
||||||
@@ -627,7 +643,7 @@ end
|
|||||||
---@param forbidden_entity LuaEntity?
|
---@param forbidden_entity LuaEntity?
|
||||||
---@param force boolean?
|
---@param force boolean?
|
||||||
local function resolve_update_stop_from_rail(map_data, entity, forbidden_entity, force)
|
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
|
local is_station = true
|
||||||
---@type Station|Refueler
|
---@type Station|Refueler
|
||||||
local stop = map_data.stations[id]
|
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)
|
resolve_update_stop_from_rail(map_data, entity, forbidden_entity, force)
|
||||||
return
|
return
|
||||||
end
|
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
|
end
|
||||||
if rail_front then
|
if rail_front then
|
||||||
local entity = rail_front.get_rail_segment_entity(defines_front, false)
|
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)
|
resolve_update_stop_from_rail(map_data, entity, forbidden_entity, force)
|
||||||
return
|
return
|
||||||
end
|
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
|
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)
|
update_stop_from_rail(map_data, pump.pump_rail_target, forbidden_entity)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
---@param map_data MapData
|
---@param map_data MapData
|
||||||
---@param inserter LuaEntity
|
---@param inserter LuaEntity
|
||||||
---@param forbidden_entity LuaEntity?
|
---@param forbidden_entity LuaEntity?
|
||||||
@@ -713,10 +736,10 @@ function update_stop_from_inserter(map_data, inserter, forbidden_entity)
|
|||||||
end
|
end
|
||||||
-- We need to check secondary positions because of weird modded inserters.
|
-- 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.
|
-- 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.x = pos1.x + 0.2 * (pos1.x - pos0.x)
|
||||||
pos1.y = pos1.y + 0.2*(pos1.y - pos0.y)
|
pos1.y = pos1.y + 0.2 * (pos1.y - pos0.y)
|
||||||
pos2.x = pos2.x + 0.2*(pos2.x - pos0.x)
|
pos2.x = pos2.x + 0.2 * (pos2.x - pos0.x)
|
||||||
pos2.y = pos2.y + 0.2*(pos2.y - pos0.y)
|
pos2.y = pos2.y + 0.2 * (pos2.y - pos0.y)
|
||||||
rails = surface.find_entities_filtered({
|
rails = surface.find_entities_filtered({
|
||||||
type = search_type,
|
type = search_type,
|
||||||
position = pos1,
|
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)
|
update_stop_from_rail(map_data, rails[1], forbidden_entity)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
---@param map_data MapData
|
---@param map_data MapData
|
||||||
---@param loader LuaEntity
|
---@param loader LuaEntity
|
||||||
---@param forbidden_entity 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 loader_type = loader.loader_type
|
||||||
local position = loader.position
|
local position = loader.position
|
||||||
--check input/output direction and loader position, and case position and modify x or y by +/- 1 for search
|
--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
|
if direction == defines.direction.east then
|
||||||
position.x = position.x + 1 -- input and facing east -> move on X axis 1 to the right
|
position.x = position.x + 1 -- input and facing east -> move on X axis 1 to the right
|
||||||
elseif direction == defines.direction.south then
|
elseif direction == defines.direction.south then
|
||||||
|
|||||||
Reference in New Issue
Block a user