fixed multiple issues

This commit is contained in:
mamoniot
2022-12-23 18:52:44 -05:00
parent 9282c09267
commit 33cd647042
9 changed files with 55 additions and 45 deletions

View File

@@ -1,6 +1,6 @@
--------------------------------------------------------------------------------------------------- ---------------------------------------------------------------------------------------------------
Version: 1.1.8 Version: 1.2.0
Date: 2022-12-22 Date: 2022-12-23
Changes: Changes:
- Forced provide stations to wait until they can service the highest priority request station - Forced provide stations to wait until they can service the highest priority request station
- Provide stations now override request thresholds with the per-item thresholds set by their station info combinator - Provide stations now override request thresholds with the per-item thresholds set by their station info combinator

View File

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

View File

@@ -45,12 +45,12 @@ cybersyn-locked-slots=Locked slots per cargo wagon
[cybersyn-messages] [cybersyn-messages]
nonempty-train=A train is being held in the depot because it still has cargo nonempty-train=A train is being held in the depot because it still has cargo
unexpected-train=A train has unexpectedly returned to the depot before completing its delivery unexpected-train=A train has unexpectedly returned to the depot before completing its delivery
stuck-train=A train from depot __1__ is stuck stuck-train=A train is stuck
cannot-path-between-surfaces=A train from depot __1__ is attempting to make a delivery between two unconnected surfaces, perhaps put them on separate networks cannot-path-between-surfaces=A train is attempting to make a delivery between two unconnected surfaces, perhaps put them on separate networks
depot-broken=A train from depot __1__ is lost because its depot was broken. depot-broken=A train is lost because its depot was broken
refueler-broken=A train from depot __1__ is lost because its refueler was broken. refueler-broken=A train is lost because its fuel loader was broken
station-broken=A train from depot __1__ is lost because one of its delivery stations was broken. station-broken=A train is lost because one of its delivery stations was broken
train-at-incorrect=A train from depot __1__ is lost; it parked at a station it was not scheduled to delivered to. train-at-incorrect=A train parked at a station it was not scheduled to delivered to
missing-train=Could not find any train on the correct network to make a delivery from __2__ to __1__ missing-train=Could not find any train on the correct network to make a delivery from __2__ to __1__
no-train-has-capacity=Could not find a train with enough cargo capacity to make a delivery from __2__ to __1__ no-train-has-capacity=Could not find a train with enough cargo capacity to make a delivery from __2__ to __1__
no-train-matches-r-layout=Could not find a train on the allow-list of __1__ to make a delivery no-train-matches-r-layout=Could not find a train on the allow-list of __1__ to make a delivery

View File

@@ -300,7 +300,7 @@ local function tick_dispatch(map_data, mod_settings)
---@type string ---@type string
local network_name local network_name
if r_station.network_name == NETWORK_EACH then if r_station.network_name == NETWORK_EACH then
_, _, network_name = string.find(item_network_name, "(^.*):") _, _, network_name = string.find(item_network_name, "^(.*):")
else else
network_name = r_station.network_name network_name = r_station.network_name
end end
@@ -337,8 +337,8 @@ local function tick_dispatch(map_data, mod_settings)
goto p_continue goto p_continue
end end
p_flag = p_station.network_name == NETWORK_EACH and (p_station.network_flag[item_name] or 0) or p_station.network_flag p_flag = p_station.network_name == NETWORK_EACH and (p_station.network_flag[network_name] or 0) or p_station.network_flag
r_flag = r_station.network_name == NETWORK_EACH and (r_station.network_flag[item_name] or 0) or r_station.network_flag r_flag = r_station.network_name == NETWORK_EACH and (r_station.network_flag[network_name] or 0) or r_station.network_flag
netand = band(p_flag, r_flag) netand = band(p_flag, r_flag)
if netand == 0 then if netand == 0 then
goto p_continue goto p_continue
@@ -680,7 +680,7 @@ function tick(map_data, mod_settings)
map_data.total_ticks = map_data.total_ticks + 1 map_data.total_ticks = map_data.total_ticks + 1
if map_data.active_alerts then if map_data.active_alerts then
if map_data.total_ticks%(9*mod_settings.tps) < 1 then if map_data.total_ticks%(10*mod_settings.tps) < 1 then
process_active_alerts(map_data) process_active_alerts(map_data)
end end
end end

View File

@@ -566,7 +566,6 @@ local function send_alert_for_train(train, icon, message)
icon, icon,
{message}, {message},
true) true)
player.play_sound({path = ALERT_SOUND})
end end
end end
end end
@@ -623,7 +622,7 @@ local send_stuck_train_alert_icon = {name = LOST_TRAIN_NAME, type = "fluid"}
function send_alert_stuck_train(map_data, train) function send_alert_stuck_train(map_data, train)
send_alert_for_train(train, send_stuck_train_alert_icon, "cybersyn-messages.stuck-train") send_alert_for_train(train, send_stuck_train_alert_icon, "cybersyn-messages.stuck-train")
map_data.active_alerts = map_data.active_alerts or {} map_data.active_alerts = map_data.active_alerts or {}
map_data.active_alerts[train] = 1 map_data.active_alerts[train.id] = {train, 1}
end end
local send_nonempty_train_in_depot_alert_icon = {name = NONEMPTY_TRAIN_NAME, type = "fluid"} local send_nonempty_train_in_depot_alert_icon = {name = NONEMPTY_TRAIN_NAME, type = "fluid"}
@@ -631,8 +630,9 @@ local send_nonempty_train_in_depot_alert_icon = {name = NONEMPTY_TRAIN_NAME, typ
---@param train LuaTrain ---@param train LuaTrain
function send_alert_nonempty_train_in_depot(map_data, train) function send_alert_nonempty_train_in_depot(map_data, train)
send_alert_for_train(train, send_nonempty_train_in_depot_alert_icon, "cybersyn-messages.nonempty-train") send_alert_for_train(train, send_nonempty_train_in_depot_alert_icon, "cybersyn-messages.nonempty-train")
send_alert_sounds(train)
map_data.active_alerts = map_data.active_alerts or {} map_data.active_alerts = map_data.active_alerts or {}
map_data.active_alerts[train] = 2 map_data.active_alerts[train.id] = {train, 2}
end end
local send_lost_train_alert_icon = {name = LOST_TRAIN_NAME, type = "fluid"} local send_lost_train_alert_icon = {name = LOST_TRAIN_NAME, type = "fluid"}
@@ -640,36 +640,41 @@ local send_lost_train_alert_icon = {name = LOST_TRAIN_NAME, type = "fluid"}
---@param train LuaTrain ---@param train LuaTrain
function send_alert_depot_of_train_broken(map_data, train) function send_alert_depot_of_train_broken(map_data, train)
send_alert_for_train(train, send_lost_train_alert_icon, "cybersyn-messages.depot-broken") send_alert_for_train(train, send_lost_train_alert_icon, "cybersyn-messages.depot-broken")
send_alert_sounds(train)
map_data.active_alerts = map_data.active_alerts or {} map_data.active_alerts = map_data.active_alerts or {}
map_data.active_alerts[train] = 3 map_data.active_alerts[train.id] = {train, 3}
end end
---@param map_data MapData ---@param map_data MapData
---@param train LuaTrain ---@param train LuaTrain
function send_alert_station_of_train_broken(map_data, train) function send_alert_station_of_train_broken(map_data, train)
send_alert_for_train(train, send_lost_train_alert_icon, "cybersyn-messages.station-broken") send_alert_for_train(train, send_lost_train_alert_icon, "cybersyn-messages.station-broken")
send_alert_sounds(train)
map_data.active_alerts = map_data.active_alerts or {} map_data.active_alerts = map_data.active_alerts or {}
map_data.active_alerts[train] = 4 map_data.active_alerts[train.id] = {train, 4}
end end
---@param map_data MapData ---@param map_data MapData
---@param train LuaTrain ---@param train LuaTrain
function send_alert_refueler_of_train_broken(map_data, train) function send_alert_refueler_of_train_broken(map_data, train)
send_alert_for_train(train, send_lost_train_alert_icon, "cybersyn-messages.refueler-broken") send_alert_for_train(train, send_lost_train_alert_icon, "cybersyn-messages.refueler-broken")
send_alert_sounds(train)
map_data.active_alerts = map_data.active_alerts or {} map_data.active_alerts = map_data.active_alerts or {}
map_data.active_alerts[train] = 5 map_data.active_alerts[train.id] = {train, 5}
end end
---@param map_data MapData ---@param map_data MapData
---@param train LuaTrain ---@param train LuaTrain
function send_alert_train_at_incorrect_station(map_data, train) function send_alert_train_at_incorrect_station(map_data, train)
send_alert_for_train(train, send_lost_train_alert_icon, "cybersyn-messages.train-at-incorrect") send_alert_for_train(train, send_lost_train_alert_icon, "cybersyn-messages.train-at-incorrect")
send_alert_sounds(train)
map_data.active_alerts = map_data.active_alerts or {} map_data.active_alerts = map_data.active_alerts or {}
map_data.active_alerts[train] = 6 map_data.active_alerts[train.id] = {train, 6}
end end
---@param map_data MapData ---@param map_data MapData
---@param train LuaTrain ---@param train LuaTrain
function send_alert_cannot_path_between_surfaces(map_data, train) function send_alert_cannot_path_between_surfaces(map_data, train)
send_alert_for_train(train, send_lost_train_alert_icon, "cybersyn-messages.cannot-path-between-surfaces") send_alert_for_train(train, send_lost_train_alert_icon, "cybersyn-messages.cannot-path-between-surfaces")
send_alert_sounds(train)
map_data.active_alerts = map_data.active_alerts or {} map_data.active_alerts = map_data.active_alerts or {}
map_data.active_alerts[train] = 7 map_data.active_alerts[train.id] = {train, 7}
end end
---@param train LuaTrain ---@param train LuaTrain
@@ -680,21 +685,27 @@ end
---@param map_data MapData ---@param map_data MapData
function process_active_alerts(map_data) function process_active_alerts(map_data)
for train, id in pairs(map_data.active_alerts) do for train_id, data in pairs(map_data.active_alerts) do
if id == 1 then local train = data[1]
send_alert_for_train(train, send_stuck_train_alert_icon, "cybersyn-messages.stuck-train") if train.valid then
elseif id == 2 then local id = data[2]
send_alert_for_train(train, send_nonempty_train_in_depot_alert_icon, "cybersyn-messages.nonempty-train") if id == 1 then
elseif id == 3 then send_alert_for_train(train, send_stuck_train_alert_icon, "cybersyn-messages.stuck-train")
send_alert_for_train(train, send_lost_train_alert_icon, "cybersyn-messages.depot-broken") elseif id == 2 then
elseif id == 4 then send_alert_for_train(train, send_nonempty_train_in_depot_alert_icon, "cybersyn-messages.nonempty-train")
send_alert_for_train(train, send_lost_train_alert_icon, "cybersyn-messages.station-broken") elseif id == 3 then
elseif id == 5 then send_alert_for_train(train, send_lost_train_alert_icon, "cybersyn-messages.depot-broken")
send_alert_for_train(train, send_lost_train_alert_icon, "cybersyn-messages.refueler-broken") elseif id == 4 then
elseif id == 6 then send_alert_for_train(train, send_lost_train_alert_icon, "cybersyn-messages.station-broken")
send_alert_for_train(train, send_lost_train_alert_icon, "cybersyn-messages.train-at-incorrect") elseif id == 5 then
elseif id == 7 then send_alert_for_train(train, send_lost_train_alert_icon, "cybersyn-messages.refueler-broken")
send_alert_for_train(train, send_lost_train_alert_icon, "cybersyn-messages.cannot-path-between-surfaces") elseif id == 6 then
send_alert_for_train(train, send_lost_train_alert_icon, "cybersyn-messages.train-at-incorrect")
elseif id == 7 then
send_alert_for_train(train, send_lost_train_alert_icon, "cybersyn-messages.cannot-path-between-surfaces")
end
else
map_data.active_alerts[train_id] = nil
end end
end end
end end

View File

@@ -20,7 +20,7 @@
---@field public tick_data {} ---@field public tick_data {}
---@field public economy Economy ---@field public economy Economy
---@field public each_refuelers {[uint]: true} ---@field public each_refuelers {[uint]: true}
---@field public active_alerts {[LuaTrain]: int}? ---@field public active_alerts {[uint]: {[1]: LuaTrain, [2]: int}}?
---@field public se_tele_old_id {[string]: uint} ---@field public se_tele_old_id {[string]: uint}
---@class Station ---@class Station

View File

@@ -65,7 +65,7 @@ function gui_opened(comb, player)
on_click = {"close", comb.unit_number} on_click = {"close", comb.unit_number}
}} }}
}}, }},
{type="frame", name="frame", style="inside_shallow_frame_with_padding", style_mods={padding=12, bottom_padding=10}, children={ {type="frame", name="frame", style="inside_shallow_frame_with_padding", style_mods={padding=12, bottom_padding=9}, children={
{type="flow", name="vflow", direction="vertical", style_mods={horizontal_align="left"}, children={ {type="flow", name="vflow", direction="vertical", style_mods={horizontal_align="left"}, children={
--status --status
{type="flow", style="status_flow", direction="horizontal", style_mods={vertical_align="center", horizontally_stretchable=true, bottom_padding=4}, children={ {type="flow", style="status_flow", direction="horizontal", style_mods={vertical_align="center", horizontally_stretchable=true, bottom_padding=4}, children={
@@ -196,11 +196,10 @@ function register_gui_actions()
if signal and (signal.name == "signal-everything" or signal.name == "signal-anything" or signal.name == "signal-each") then if signal and (signal.name == "signal-everything" or signal.name == "signal-anything" or signal.name == "signal-each") then
if param.operation == MODE_PRIMARY_IO or param.operation == MODE_PRIMARY_IO_ACTIVE or param.operation == MODE_PRIMARY_IO_FAILED_REQUEST or param.operation == MODE_REFUELER then if param.operation == MODE_PRIMARY_IO or param.operation == MODE_PRIMARY_IO_ACTIVE or param.operation == MODE_PRIMARY_IO_FAILED_REQUEST or param.operation == MODE_REFUELER then
signal.name = NETWORK_EACH signal.name = NETWORK_EACH
element.elem_value.name = NETWORK_EACH
else else
signal = nil signal = nil
element.elem_value = nil
end end
element.elem_value = signal
end end
set_comb_network_name(comb, signal) set_comb_network_name(comb, signal)

View File

@@ -114,7 +114,7 @@ local migrations_table = {
end end
end end
end, end,
["1.1.8"] = function() ["1.2.0"] = function()
---@type MapData ---@type MapData
local map_data = global local map_data = global
map_data.tick_state = STATE_INIT map_data.tick_state = STATE_INIT

View File

@@ -332,7 +332,7 @@ local function on_train_leaves_stop(map_data, mod_settings, train_id, train)
local refueler = map_data.refuelers[id] local refueler = map_data.refuelers[id]
set_refueler_from_comb(map_data, mod_settings, id) set_refueler_from_comb(map_data, mod_settings, id)
local refueler_network_flag = refueler.network_name == NETWORK_EACH and refueler.network_flag[train.network_name] or refueler.network_flag local refueler_network_flag = refueler.network_name == NETWORK_EACH and (refueler.network_flag[train.network_name] or 0) or refueler.network_flag
if btest(train.network_flag, refueler_network_flag) and (refueler.allows_all_trains or refueler.accepted_layouts[train.layout_id]) and refueler.trains_total < refueler.entity_stop.trains_limit then if btest(train.network_flag, refueler_network_flag) and (refueler.allows_all_trains or refueler.accepted_layouts[train.layout_id]) and refueler.trains_total < refueler.entity_stop.trains_limit then
local accepted = false local accepted = false
local dist = nil local dist = nil
@@ -419,15 +419,15 @@ end
function on_train_changed(event) function on_train_changed(event)
local train_e = event.train--[[@as LuaTrain]] local train_e = event.train--[[@as LuaTrain]]
if not train_e.valid then return end if not train_e.valid then return end
local train_id = train_e.id
if global.active_alerts and global.active_alerts[train_e] then if global.active_alerts and global.active_alerts[train_id] then
global.active_alerts[train_e] = nil global.active_alerts[train_id] = nil
if next(global.active_alerts) == nil then if next(global.active_alerts) == nil then
global.active_alerts = nil global.active_alerts = nil
end end
end end
local train_id = train_e.id
if train_e.state == defines.train_state.wait_station then if train_e.state == defines.train_state.wait_station then
local stop = train_e.station local stop = train_e.station
if stop and stop.valid and stop.name == "train-stop" then if stop and stop.valid and stop.name == "train-stop" then