mirror of
https://github.com/Xevion/project-cybersyn.git
synced 2025-12-08 18:08:21 -06:00
improved automatic train blacklist logic
This commit is contained in:
@@ -41,4 +41,5 @@ Date: 2022-11-24
|
|||||||
Features:
|
Features:
|
||||||
- Added a stuck train alert
|
- Added a stuck train alert
|
||||||
- Improved localization
|
- Improved localization
|
||||||
- Fixed Bug with fluid cargo not being detected by depots
|
- Fixed bug with fluid cargo not being detected by depots
|
||||||
|
- Greatly improved automatic train blacklist logic
|
||||||
|
|||||||
@@ -351,9 +351,11 @@ local function reset_station_layout(map_data, station, forbidden_entity)
|
|||||||
local type_filter = {"inserter", "pump", "arithmetic-combinator"}
|
local type_filter = {"inserter", "pump", "arithmetic-combinator"}
|
||||||
local wagon_number = 0
|
local wagon_number = 0
|
||||||
local pattern_length = 1
|
local pattern_length = 1
|
||||||
|
local is_break = false
|
||||||
for i = 1, 100 do
|
for i = 1, 100 do
|
||||||
local rail, rail_direction, rail_connection_direction = pre_rail.get_connected_rail({rail_direction = rail_direction_from_station, 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_station, rail_connection_direction = defines.rail_connection_direction.straight})
|
||||||
if not rail or rail_connection_direction ~= defines.rail_connection_direction.straight or not rail.valid then
|
if not rail or rail_connection_direction ~= defines.rail_connection_direction.straight or not rail.valid then
|
||||||
|
is_break = true
|
||||||
break
|
break
|
||||||
end
|
end
|
||||||
pre_rail = rail
|
pre_rail = rail
|
||||||
@@ -433,7 +435,10 @@ local function reset_station_layout(map_data, station, forbidden_entity)
|
|||||||
search_area = area.move(search_area, area_delta)
|
search_area = area.move(search_area, area_delta)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
layout_pattern = string_sub(layout_pattern, 1, pattern_length)..STATION_LAYOUT_NA.."*$"
|
layout_pattern = string_sub(layout_pattern, 1, pattern_length)
|
||||||
|
if is_break then
|
||||||
|
layout_pattern = layout_pattern..STATION_LAYOUT_NA.."*$"
|
||||||
|
end
|
||||||
station.layout_pattern = layout_pattern
|
station.layout_pattern = layout_pattern
|
||||||
local accepted_layouts = station.accepted_layouts
|
local accepted_layouts = station.accepted_layouts
|
||||||
for id, layout in pairs(map_data.layouts) do
|
for id, layout in pairs(map_data.layouts) do
|
||||||
@@ -457,45 +462,40 @@ end
|
|||||||
---@param map_data MapData
|
---@param map_data MapData
|
||||||
---@param rail LuaEntity
|
---@param rail LuaEntity
|
||||||
---@param forbidden_entity LuaEntity?
|
---@param forbidden_entity LuaEntity?
|
||||||
function force_update_station_from_rail(map_data, rail, forbidden_entity)
|
---@param force boolean?
|
||||||
--NOTE: should we search further or better? it would be more expensive
|
function update_station_from_rail(map_data, rail, forbidden_entity, force)
|
||||||
local entity = rail.get_rail_segment_entity(defines.rail_direction.back, false)
|
--NOTE: is this a correct way to figure out the direction?
|
||||||
if entity and entity.valid and entity.name == "train-stop" then
|
---@type defines.rail_direction
|
||||||
local station = map_data.stations[entity.unit_number]
|
local rail_direction = defines.rail_direction.back
|
||||||
if station then
|
local entity = rail.get_rail_segment_entity(rail_direction, false)
|
||||||
reset_station_layout(map_data, station, forbidden_entity)
|
if not entity then
|
||||||
|
rail_direction = defines.rail_direction.front
|
||||||
|
entity = rail.get_rail_segment_entity(rail_direction, false)
|
||||||
|
end
|
||||||
|
for i = 1, 100 do
|
||||||
|
if not entity or not entity.valid then
|
||||||
|
return
|
||||||
end
|
end
|
||||||
else
|
if entity.name == "train-stop" then
|
||||||
entity = rail.get_rail_segment_entity(defines.rail_direction.front, false)
|
|
||||||
if entity and entity.valid and entity.name == "train-stop" then
|
|
||||||
local station = map_data.stations[entity.unit_number]
|
local station = map_data.stations[entity.unit_number]
|
||||||
if station then
|
if station then
|
||||||
reset_station_layout(map_data, station, forbidden_entity)
|
if force then
|
||||||
end
|
reset_station_layout(map_data, station, forbidden_entity)
|
||||||
end
|
else
|
||||||
end
|
update_station_if_auto(map_data, station, forbidden_entity)
|
||||||
end
|
end
|
||||||
---@param map_data MapData
|
|
||||||
---@param rail LuaEntity
|
|
||||||
---@param forbidden_entity LuaEntity?
|
|
||||||
function update_station_from_rail(map_data, rail, forbidden_entity)
|
|
||||||
--NOTE: should we search further or better? it would be more expensive
|
|
||||||
local entity = rail.get_rail_segment_entity(defines.rail_direction.back, false)
|
|
||||||
if entity and entity.valid and entity.name == "train-stop" then
|
|
||||||
local station = map_data.stations[entity.unit_number]
|
|
||||||
if station then
|
|
||||||
update_station_if_auto(map_data, station, forbidden_entity)
|
|
||||||
end
|
|
||||||
else
|
|
||||||
entity = rail.get_rail_segment_entity(defines.rail_direction.front, false)
|
|
||||||
if entity and entity.valid and entity.name == "train-stop" then
|
|
||||||
local station = map_data.stations[entity.unit_number]
|
|
||||||
if station then
|
|
||||||
update_station_if_auto(map_data, station, forbidden_entity)
|
|
||||||
end
|
end
|
||||||
|
return
|
||||||
end
|
end
|
||||||
|
|
||||||
|
rail = rail.get_connected_rail({rail_direction = rail_direction, rail_connection_direction = defines.rail_connection_direction.straight})--[[@as LuaEntity]]
|
||||||
|
if not rail or not rail.valid then
|
||||||
|
return
|
||||||
|
end
|
||||||
|
entity = rail.get_rail_segment_entity(rail_direction, false)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
---@param map_data MapData
|
---@param map_data MapData
|
||||||
---@param pump LuaEntity
|
---@param pump LuaEntity
|
||||||
---@param forbidden_entity LuaEntity?
|
---@param forbidden_entity LuaEntity?
|
||||||
|
|||||||
@@ -287,7 +287,7 @@ local function on_combinator_built(map_data, comb)
|
|||||||
|
|
||||||
if op == OPERATION_WAGON_MANIFEST then
|
if op == OPERATION_WAGON_MANIFEST then
|
||||||
if rail then
|
if rail then
|
||||||
force_update_station_from_rail(map_data, rail, nil)
|
update_station_from_rail(map_data, rail, nil, true)
|
||||||
end
|
end
|
||||||
elseif op == OPERATION_DEPOT then
|
elseif op == OPERATION_DEPOT then
|
||||||
if stop then
|
if stop then
|
||||||
|
|||||||
Reference in New Issue
Block a user