fixed scheduling for SE

This commit is contained in:
Monica Moniot
2022-12-01 14:36:21 -05:00
parent 5ea40971f1
commit a049b56bb0
7 changed files with 35 additions and 19 deletions

View File

@@ -94,3 +94,8 @@ Date: 2022-11-30
Features: Features:
- Added depot bypass - Added depot bypass
- Increased inactivity time so burner inserters are fast enough to trigger it - Increased inactivity time so burner inserters are fast enough to trigger it
---------------------------------------------------------------------------------------------------
Version: 1.0.7
Date: 2022-11-30
Features:
- Fixed a crash relating to depot bypass through space elevators

View File

@@ -1,6 +1,6 @@
{ {
"name": "cybersyn", "name": "cybersyn",
"version": "1.0.6", "version": "1.0.7",
"title": "Project Cybersyn", "title": "Project Cybersyn",
"author": "Mami", "author": "Mami",
"factorio_version": "1.1", "factorio_version": "1.1",

View File

@@ -203,7 +203,7 @@ local function send_train_between(map_data, r_station_id, p_station_id, train_id
train.manifest = manifest train.manifest = manifest
train.last_manifest_tick = map_data.total_ticks train.last_manifest_tick = map_data.total_ticks
set_manifest_schedule(train.entity, train.depot_name, p_station.entity_stop, r_station.entity_stop, manifest, depot_id ~= nil) set_manifest_schedule(train.entity, train.depot_name, train.se_depot_surface_i, p_station.entity_stop, r_station.entity_stop, manifest, depot_id ~= nil)
set_comb2(map_data, p_station) set_comb2(map_data, p_station)
set_comb2(map_data, r_station) set_comb2(map_data, r_station)
if p_station.entity_comb1.valid then if p_station.entity_comb1.valid then

View File

@@ -106,21 +106,27 @@ function rename_manifest_schedule(train, stop, old_name)
train.schedule = schedule train.schedule = schedule
end end
---@param elevator_name string
---@param is_train_in_orbit boolean
local function se_create_elevator_order(elevator_name, is_train_in_orbit)
return {station = elevator_name..(is_train_in_orbit and SE_ELEVATOR_ORBIT_SUFFIX or SE_ELEVATOR_PLANET_SUFFIX)}
end
---@param train LuaTrain ---@param train LuaTrain
---@param depot_name string ---@param depot_name string
---@param d_surface_i int
---@param p_stop LuaEntity ---@param p_stop LuaEntity
---@param r_stop LuaEntity ---@param r_stop LuaEntity
---@param manifest Manifest ---@param manifest Manifest
---@param start_at_depot boolean? ---@param start_at_depot boolean?
function set_manifest_schedule(train, depot_name, p_stop, r_stop, manifest, start_at_depot) function set_manifest_schedule(train, depot_name, d_surface_i, p_stop, r_stop, manifest, start_at_depot)
--NOTE: train must be on same surface as depot_stop --NOTE: train must be on same surface as depot_stop
local d_surface = train.front_stock.surface local t_surface = train.front_stock.surface
local p_surface = p_stop.surface local p_surface = p_stop.surface
local r_surface = r_stop.surface local r_surface = r_stop.surface
local d_surface_i = d_surface.index local t_surface_i = t_surface.index
local p_surface_i = p_surface.index local p_surface_i = p_surface.index
local r_surface_i = r_surface.index local r_surface_i = r_surface.index
if d_surface_i == p_surface_i and p_surface_i == r_surface_i then if t_surface_i == p_surface_i and p_surface_i == r_surface_i then
train.schedule = {current = start_at_depot and 1 or 2, records = { train.schedule = {current = start_at_depot and 1 or 2, records = {
create_inactivity_order(depot_name), create_inactivity_order(depot_name),
create_direct_to_station_order(p_stop), create_direct_to_station_order(p_stop),
@@ -129,32 +135,32 @@ function set_manifest_schedule(train, depot_name, p_stop, r_stop, manifest, star
create_unloading_order(r_stop), create_unloading_order(r_stop),
}} }}
return return
elseif IS_SE_PRESENT and (d_surface_i == p_surface_i or p_surface_i == r_surface_i or r_surface_i == d_surface_i) then elseif IS_SE_PRESENT and (t_surface_i == p_surface_i or p_surface_i == r_surface_i or r_surface_i == t_surface_i) then
local d_zone = remote.call("space-exploration", "get_zone_from_surface_index", {surface_index = d_surface_i}) local t_zone = remote.call("space-exploration", "get_zone_from_surface_index", {surface_index = t_surface_i})
local other_zone = remote.call("space-exploration", "get_zone_from_surface_index", {surface_index = (d_surface_i == p_surface_i) and r_surface_i or p_surface_i}) local other_zone = remote.call("space-exploration", "get_zone_from_surface_index", {surface_index = (t_surface_i == p_surface_i) and r_surface_i or p_surface_i})
local is_train_in_orbit = other_zone.orbit_index == d_zone.index local is_train_in_orbit = other_zone.orbit_index == t_zone.index
if is_train_in_orbit or d_zone.orbit_index == other_zone.index then if is_train_in_orbit or t_zone.orbit_index == other_zone.index then
local elevator_name = se_get_space_elevator_name(d_surface) local elevator_name = se_get_space_elevator_name(t_surface)
if elevator_name then if elevator_name then
local records = {create_inactivity_order(depot_name)} local records = {create_inactivity_order(depot_name)}
if d_surface_i == p_surface_i then if t_surface_i == p_surface_i then
records[#records + 1] = create_direct_to_station_order(p_stop) records[#records + 1] = create_direct_to_station_order(p_stop)
else else
records[#records + 1] = {station = elevator_name..(is_train_in_orbit and SE_ELEVATOR_ORBIT_SUFFIX or SE_ELEVATOR_PLANET_SUFFIX)} records[#records + 1] = se_create_elevator_order(elevator_name, is_train_in_orbit)
is_train_in_orbit = not is_train_in_orbit is_train_in_orbit = not is_train_in_orbit
end end
records[#records + 1] = create_loading_order(p_stop, manifest) records[#records + 1] = create_loading_order(p_stop, manifest)
if p_surface_i ~= r_surface_i then if p_surface_i ~= r_surface_i then
records[#records + 1] = {station = elevator_name..(is_train_in_orbit and SE_ELEVATOR_ORBIT_SUFFIX or SE_ELEVATOR_PLANET_SUFFIX)} records[#records + 1] = se_create_elevator_order(elevator_name, is_train_in_orbit)
is_train_in_orbit = not is_train_in_orbit is_train_in_orbit = not is_train_in_orbit
end end
records[#records + 1] = create_unloading_order(r_stop) records[#records + 1] = create_unloading_order(r_stop)
if r_surface_i ~= d_surface_i then if r_surface_i ~= d_surface_i then
records[#records + 1] = {station = elevator_name..(is_train_in_orbit and SE_ELEVATOR_ORBIT_SUFFIX or SE_ELEVATOR_PLANET_SUFFIX)} records[#records + 1] = se_create_elevator_order(elevator_name, is_train_in_orbit)
is_train_in_orbit = not is_train_in_orbit is_train_in_orbit = not is_train_in_orbit
end end
train.schedule = {current = 1, records = records} train.schedule = {current = start_at_depot and 1 or 2, records = records}
return return
end end
end end

View File

@@ -61,11 +61,12 @@
---@field public is_available true? ---@field public is_available true?
---@field public depot_id uint? ---@field public depot_id uint?
---@field public depot_name string ---@field public depot_name string
---@field public se_depot_surface_i uint --se only
---@field public network_name string? ---@field public network_name string?
---@field public network_flag int ---@field public network_flag int
---@field public priority int ---@field public priority int
---@field public se_awaiting_removal any? ---@field public se_awaiting_removal any? --se only
---@field public se_awaiting_rename any? ---@field public se_awaiting_rename any? --se only
---@alias Manifest {}[] ---@alias Manifest {}[]
---@alias cybersyn.global MapData ---@alias cybersyn.global MapData

View File

@@ -89,6 +89,7 @@ local function add_available_train_to_depot(map_data, train_id, train, depot_id,
train.status = STATUS_D train.status = STATUS_D
train.depot_id = depot_id train.depot_id = depot_id
train.depot_name = depot.entity_stop.backer_name train.depot_name = depot.entity_stop.backer_name
train.se_depot_surface_i = depot.entity_stop.surface.index
train.network_name = network_name train.network_name = network_name
train.network_flag = mod_settings.network_flag train.network_flag = mod_settings.network_flag
train.priority = 0 train.priority = 0
@@ -568,6 +569,7 @@ local function on_station_rename(map_data, stop, old_name)
if depot and depot.available_train_id then if depot and depot.available_train_id then
local train = map_data.trains[depot.available_train_id--[[@as uint]]] local train = map_data.trains[depot.available_train_id--[[@as uint]]]
train.depot_name = stop.backer_name train.depot_name = stop.backer_name
--train.se_depot_surface_i = stop.surface.index
end end
end end
end end

View File

@@ -160,6 +160,8 @@ local migrations_table = {
if v.is_available then if v.is_available then
map_data.available_trains[v.network_name--[[@as string]]][id] = true map_data.available_trains[v.network_name--[[@as string]]][id] = true
end end
--NOTE: we are guessing here because this information was never saved
v.se_depot_surface_i = v.entity.front_stock.surface.index
end end
end end
end, end,