mirror of
https://github.com/Xevion/project-cybersyn.git
synced 2025-12-13 00:12:37 -06:00
fixed scheduling bugs
This commit is contained in:
@@ -133,7 +133,10 @@ function set_manifest_schedule(train, depot_name, d_surface_i, p_stop, r_stop, m
|
|||||||
local t_surface_i = t_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 t_surface_i == p_surface_i and p_surface_i == r_surface_i and d_surface_i == t_surface_i then
|
local is_p_on_t = t_surface_i == p_surface_i
|
||||||
|
local is_r_on_t = t_surface_i == r_surface_i
|
||||||
|
local is_d_on_t = t_surface_i == d_surface_i
|
||||||
|
if is_p_on_t and is_r_on_t and is_d_on_t 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),
|
||||||
@@ -147,39 +150,43 @@ function set_manifest_schedule(train, depot_name, d_surface_i, p_stop, r_stop, m
|
|||||||
else
|
else
|
||||||
return true
|
return true
|
||||||
end
|
end
|
||||||
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
|
elseif IS_SE_PRESENT then
|
||||||
local t_zone = remote.call("space-exploration", "get_zone_from_surface_index", {surface_index = t_surface_i})
|
local other_surface_i = (not is_p_on_t and p_surface_i) or (not is_r_on_t and r_surface_i) or d_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})
|
if (is_p_on_t or p_surface_i == other_surface_i) and (is_r_on_t or r_surface_i == other_surface_i) and (is_d_on_t or d_surface_i == other_surface_i) then
|
||||||
local is_train_in_orbit = other_zone.orbit_index == t_zone.index
|
local t_zone = remote.call("space-exploration", "get_zone_from_surface_index", {surface_index = t_surface_i})
|
||||||
if is_train_in_orbit or t_zone.orbit_index == other_zone.index then
|
local other_zone = remote.call("space-exploration", "get_zone_from_surface_index", {surface_index = other_surface_i})
|
||||||
local elevator_name = se_get_space_elevator_name(t_surface)
|
local is_train_in_orbit = other_zone.orbit_index == t_zone.index
|
||||||
if elevator_name then
|
if is_train_in_orbit or t_zone.orbit_index == other_zone.index then
|
||||||
local records = {create_inactivity_order(depot_name)}
|
local elevator_name = se_get_space_elevator_name(t_surface)
|
||||||
if t_surface_i == p_surface_i then
|
if elevator_name then
|
||||||
records[#records + 1] = create_direct_to_station_order(p_stop)
|
local records = {create_inactivity_order(depot_name)}
|
||||||
else
|
if t_surface_i == p_surface_i then
|
||||||
records[#records + 1] = se_create_elevator_order(elevator_name, is_train_in_orbit)
|
records[#records + 1] = create_direct_to_station_order(p_stop)
|
||||||
is_train_in_orbit = not is_train_in_orbit
|
else
|
||||||
end
|
records[#records + 1] = se_create_elevator_order(elevator_name, is_train_in_orbit)
|
||||||
records[#records + 1] = create_loading_order(p_stop, manifest)
|
is_train_in_orbit = not is_train_in_orbit
|
||||||
if t_surface_i == r_surface_i then
|
end
|
||||||
records[#records + 1] = create_direct_to_station_order(r_stop)
|
records[#records + 1] = create_loading_order(p_stop, manifest)
|
||||||
elseif p_surface_i ~= r_surface_i then
|
|
||||||
records[#records + 1] = se_create_elevator_order(elevator_name, is_train_in_orbit)
|
|
||||||
is_train_in_orbit = not is_train_in_orbit
|
|
||||||
end
|
|
||||||
records[#records + 1] = create_unloading_order(r_stop)
|
|
||||||
if r_surface_i ~= d_surface_i then
|
|
||||||
records[#records + 1] = se_create_elevator_order(elevator_name, is_train_in_orbit)
|
|
||||||
is_train_in_orbit = not is_train_in_orbit
|
|
||||||
end
|
|
||||||
|
|
||||||
train.schedule = {current = start_at_depot and 1 or 2, records = records}
|
if p_surface_i ~= r_surface_i then
|
||||||
if old_schedule and not train.has_path then
|
records[#records + 1] = se_create_elevator_order(elevator_name, is_train_in_orbit)
|
||||||
train.schedule = old_schedule
|
is_train_in_orbit = not is_train_in_orbit
|
||||||
return false
|
elseif t_surface_i == r_surface_i then
|
||||||
else
|
records[#records + 1] = create_direct_to_station_order(r_stop)
|
||||||
return true
|
end
|
||||||
|
records[#records + 1] = create_unloading_order(r_stop)
|
||||||
|
if r_surface_i ~= d_surface_i then
|
||||||
|
records[#records + 1] = se_create_elevator_order(elevator_name, is_train_in_orbit)
|
||||||
|
is_train_in_orbit = not is_train_in_orbit
|
||||||
|
end
|
||||||
|
|
||||||
|
train.schedule = {current = start_at_depot and 1 or 2, records = records}
|
||||||
|
if old_schedule and not train.has_path then
|
||||||
|
train.schedule = old_schedule
|
||||||
|
return false
|
||||||
|
else
|
||||||
|
return true
|
||||||
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
@@ -197,7 +204,8 @@ end
|
|||||||
|
|
||||||
---@param train LuaTrain
|
---@param train LuaTrain
|
||||||
---@param stop LuaEntity
|
---@param stop LuaEntity
|
||||||
function add_refueler_schedule(train, stop)
|
---@param depot_name string
|
||||||
|
function add_refueler_schedule(train, stop, depot_name)
|
||||||
local schedule = train.schedule or {current = 1, records = {}}
|
local schedule = train.schedule or {current = 1, records = {}}
|
||||||
local i = schedule.current
|
local i = schedule.current
|
||||||
if i == 1 then
|
if i == 1 then
|
||||||
@@ -215,9 +223,10 @@ function add_refueler_schedule(train, stop)
|
|||||||
table_insert(schedule.records, i, create_inactivity_order(stop.backer_name))
|
table_insert(schedule.records, i, create_inactivity_order(stop.backer_name))
|
||||||
|
|
||||||
train.schedule = schedule
|
train.schedule = schedule
|
||||||
|
return
|
||||||
elseif IS_SE_PRESENT then
|
elseif IS_SE_PRESENT then
|
||||||
local t_zone = remote.call("space-exploration", "get_zone_from_surface_index", {surface_index = t_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 = f_surface})
|
local other_zone = remote.call("space-exploration", "get_zone_from_surface_index", {surface_index = f_surface_i})
|
||||||
local is_train_in_orbit = other_zone.orbit_index == t_zone.index
|
local is_train_in_orbit = other_zone.orbit_index == t_zone.index
|
||||||
if is_train_in_orbit or t_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(t_surface)
|
local elevator_name = se_get_space_elevator_name(t_surface)
|
||||||
@@ -235,8 +244,16 @@ function add_refueler_schedule(train, stop)
|
|||||||
i = i + 1
|
i = i + 1
|
||||||
is_train_in_orbit = not is_train_in_orbit
|
is_train_in_orbit = not is_train_in_orbit
|
||||||
end
|
end
|
||||||
|
|
||||||
|
train.schedule = schedule
|
||||||
|
return
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
--create an order that probably cannot be fulfilled and alert the player
|
||||||
|
table_insert(schedule.records, i, create_inactivity_order(stop.backer_name))
|
||||||
|
lock_train(train)
|
||||||
|
send_lost_train_alert(train, depot_name)
|
||||||
|
train.schedule = schedule
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -352,7 +352,7 @@ local function on_train_leaves_stop(map_data, mod_settings, train_id, train)
|
|||||||
train.refueler_id = best_refueler_id
|
train.refueler_id = best_refueler_id
|
||||||
local refueler = map_data.refuelers[best_refueler_id]
|
local refueler = map_data.refuelers[best_refueler_id]
|
||||||
refueler.trains_total = refueler.trains_total + 1
|
refueler.trains_total = refueler.trains_total + 1
|
||||||
add_refueler_schedule(train.entity, refueler.entity_stop)
|
add_refueler_schedule(train.entity, refueler.entity_stop, train.depot_name)
|
||||||
interface_raise_train_status_changed(train_id, STATUS_R, STATUS_TO_F)
|
interface_raise_train_status_changed(train_id, STATUS_R, STATUS_TO_F)
|
||||||
return
|
return
|
||||||
end
|
end
|
||||||
|
|||||||
Reference in New Issue
Block a user