Add loader-1x1 support for auto station layout

This commit is contained in:
Will Berry
2023-01-30 12:29:22 -05:00
parent 35ac5006a9
commit e55b882fd2
2 changed files with 113 additions and 1 deletions

View File

@@ -467,7 +467,7 @@ function reset_stop_layout(map_data, stop, is_station_or_refueler, forbidden_ent
local length = 2 local length = 2
local pre_rail = stop_rail local pre_rail = stop_rail
local layout_pattern = {0} local layout_pattern = {0}
local type_filter = {"inserter", "pump", "arithmetic-combinator"} local type_filter = {"inserter", "pump", "arithmetic-combinator", "loader-1x1"}
local wagon_number = 0 local wagon_number = 0
for i = 1, 112 do for i = 1, 112 do
local rail, rail_direction, rail_connection_direction = pre_rail.get_connected_rail({rail_direction = rail_direction_from_stop, rail_connection_direction = defines.rail_connection_direction.straight}) local rail, rail_direction, rail_connection_direction = pre_rail.get_connected_rail({rail_direction = rail_direction_from_stop, rail_connection_direction = defines.rail_connection_direction.straight})
@@ -510,6 +510,17 @@ 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
if not supports_cargo then
local direction = entity.direction
if is_ver then
if direction == defines.direction.east or defines.direction.west then
supports_cargo = true
end
elseif direction == defines.direction.north or direction == defines.direction.south then
supports_cargo = true
end
end
elseif entity.type == "pump" then elseif entity.type == "pump" then
if not supports_fluid and entity.pump_rail_target then if not supports_fluid and entity.pump_rail_target then
local direction = entity.direction local direction = entity.direction
@@ -658,3 +669,98 @@ 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 loader LuaEntity
---@param forbidden_entity LuaEntity?
function update_stop_from_loader(map_data, loader, forbidden_entity)
local surface = loader.surface
local direction = loader.direction
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 direction == defines.direction.east then
position.x = position.x + 1 -- input and facing east -> move on X axis 1 to the right
local rails = surface.find_entities_filtered({
type = "straight-rail",
position = position,
radius = 1,
})
if rails[1] then
update_stop_from_rail(map_data, rails[1], forbidden_entity)
end
elseif direction == defines.direction.south then
position.y = position.y - 1 -- input and facing south -> move on Y axis down 1 unit
local rails = surface.find_entities_filtered({
type = "straight-rail",
position = position,
radius = 1,
})
if rails[1] then
update_stop_from_rail(map_data, rails[1], forbidden_entity)
end
elseif direction == defines.direction.west then
position.x = position.x - 1 -- input and facing west -> move on X axis 1 to the left
local rails = surface.find_entities_filtered({
type = "straight-rail",
position = position,
radius = 1,
})
if rails[1] then
update_stop_from_rail(map_data, rails[1], forbidden_entity)
end
elseif direction == defines.direction.north then
position.y = position.y + 1 -- input and facing south -> move on Y axis up 1 unit
local rails = surface.find_entities_filtered({
type = "straight-rail",
position = position,
radius = 1,
})
if rails[1] then
update_stop_from_rail(map_data, rails[1], forbidden_entity)
end
end
elseif loader_type == "output" then --unloading train
if direction == defines.direction.east then
position.x = position.x - 1 -- output and facing east -> move on X axis 1 to the left
local rails = surface.find_entities_filtered({
type = "straight-rail",
position = position,
radius = 1,
})
if rails[1] then
update_stop_from_rail(map_data, rails[1], forbidden_entity)
end
elseif direction == defines.direction.south then
position.y = position.y + 1 -- output and facing south -> move on Y axis up 1 unit
local rails = surface.find_entities_filtered({
type = "straight-rail",
position = position,
radius = 1,
})
if rails[1] then
update_stop_from_rail(map_data, rails[1], forbidden_entity)
end
elseif direction == defines.direction.west then
position.x = position.x + 1 -- output and facing west -> move on X axis 1 to the right
local rails = surface.find_entities_filtered({
type = "straight-rail",
position = position,
radius = 1,
})
if rails[1] then
update_stop_from_rail(map_data, rails[1], forbidden_entity)
end
elseif direction == defines.direction.north then
position.y = position.y - 1 -- output and facing south -> move on Y axis down 1 unit
local rails = surface.find_entities_filtered({
type = "straight-rail",
position = position,
radius = 1,
})
if rails[1] then
update_stop_from_rail(map_data, rails[1], forbidden_entity)
end
end
end
end

View File

@@ -617,6 +617,8 @@ local function on_built(event)
on_combinator_built(global, entity) on_combinator_built(global, entity)
elseif entity.type == "inserter" then elseif entity.type == "inserter" then
update_stop_from_inserter(global, entity) update_stop_from_inserter(global, entity)
elseif entity.type == "loader-1x1" then
update_stop_from_loader(global, entity)
elseif entity.type == "pump" then elseif entity.type == "pump" then
update_stop_from_pump(global, entity) update_stop_from_pump(global, entity)
elseif entity.type == "straight-rail" then elseif entity.type == "straight-rail" then
@@ -633,6 +635,8 @@ local function on_broken(event)
on_combinator_broken(global, entity) on_combinator_broken(global, entity)
elseif entity.type == "inserter" then elseif entity.type == "inserter" then
update_stop_from_inserter(global, entity, entity) update_stop_from_inserter(global, entity, entity)
elseif entity.type == "loader-1x1" then
update_stop_from_loader(global, entity)
elseif entity.type == "pump" then elseif entity.type == "pump" then
update_stop_from_pump(global, entity, entity) update_stop_from_pump(global, entity, entity)
elseif entity.type == "straight-rail" then elseif entity.type == "straight-rail" then
@@ -841,6 +845,7 @@ local filter_built = {
{filter = "type", type = "inserter"}, {filter = "type", type = "inserter"},
{filter = "type", type = "pump"}, {filter = "type", type = "pump"},
{filter = "type", type = "straight-rail"}, {filter = "type", type = "straight-rail"},
{filter = "type", type = "loader-1x1"},
} }
local filter_broken = { local filter_broken = {
{filter = "name", name = "train-stop"}, {filter = "name", name = "train-stop"},
@@ -848,6 +853,7 @@ local filter_broken = {
{filter = "type", type = "inserter"}, {filter = "type", type = "inserter"},
{filter = "type", type = "pump"}, {filter = "type", type = "pump"},
{filter = "type", type = "straight-rail"}, {filter = "type", type = "straight-rail"},
{filter = "type", type = "loader-1x1"},
{filter = "rolling-stock"}, {filter = "rolling-stock"},
} }
local function main() local function main()