From 3bac74cff73c76155b2f18860c63f7bd76453c6c Mon Sep 17 00:00:00 2001 From: Monica Moniot Date: Tue, 10 Oct 2023 20:05:37 -0400 Subject: [PATCH] made minor improvements --- cybersyn/changelog.txt | 1 + cybersyn/scripts/central-planning.lua | 43 ++++++++++++++------------- cybersyn/scripts/global.lua | 1 + cybersyn/scripts/layout.lua | 2 +- cybersyn/scripts/main.lua | 4 +-- 5 files changed, 28 insertions(+), 23 deletions(-) diff --git a/cybersyn/changelog.txt b/cybersyn/changelog.txt index 02d58ee..82b2e00 100644 --- a/cybersyn/changelog.txt +++ b/cybersyn/changelog.txt @@ -11,6 +11,7 @@ Date: 2023-10-10 - Stations with provider item thresholds can no longer generate empty train orders - contributed by svr8450 - Added missing loader entity type to the automatic allow-list - contributed by gillett-hernandez - Fixed a case where combinator changes not being applied for depots and refuelers - contributed by jagoly + - Fixed provide/request orders for the same item getting generated simultaneously - contributed by jagoly - Fixed a crash when opening the manager when adding cybersyn to an existing save - contributed by Mjonir - Fixed a crash when enabling the manager on an existing save - contributed by freyacodes Translation: diff --git a/cybersyn/scripts/central-planning.lua b/cybersyn/scripts/central-planning.lua index 2e52572..37d6617 100644 --- a/cybersyn/scripts/central-planning.lua +++ b/cybersyn/scripts/central-planning.lua @@ -287,6 +287,12 @@ local function tick_dispatch(map_data, mod_settings) goto continue end + --don't request when already providing + local item_deliveries = station.deliveries[item_name] + if item_deliveries and item_deliveries < 0 then + goto continue + end + local threshold = station.r_threshold local prior = station.priority local item_threshold = station.item_thresholds and station.item_thresholds[item_name] or nil @@ -300,16 +306,11 @@ local function tick_dispatch(map_data, mod_settings) goto continue end + --prioritize by last delivery time if priorities are equal if prior == best_r_prior and station.last_delivery_tick > best_timestamp then goto continue end - --don't request when already providing - local item_deliveries = station.deliveries[item_name] - if item_deliveries and item_deliveries < 0 then - goto continue - end - r_station_i = i r_threshold = threshold best_r_prior = prior @@ -362,6 +363,12 @@ local function tick_dispatch(map_data, mod_settings) goto p_continue end + --don't provide when already requesting + item_deliveries = p_station.deliveries[item_name] + if item_deliveries and item_deliveries > 0 then + goto p_continue + end + p_flag = get_network_mask(p_station, network_name) r_flag = get_network_mask(r_station, network_name) netand = band(p_flag, r_flag) @@ -489,12 +496,6 @@ local function tick_dispatch(map_data, mod_settings) goto p_continue end - --don't provide when already requesting - item_deliveries = p_station.deliveries[item_name] - if item_deliveries and item_deliveries > 0 then - goto p_continue - end - p_station_i = j best_train_id = best_p_train_id best_p_prior = p_prior @@ -510,14 +511,16 @@ local function tick_dispatch(map_data, mod_settings) create_delivery(map_data, r_station_id, p_station_id, best_train_id, manifest) return false else - if correctness == 1 then - send_alert_missing_train(r_station.entity_stop, closest_to_correct_p_station.entity_stop) - elseif correctness == 2 then - send_alert_no_train_has_capacity(r_station.entity_stop, closest_to_correct_p_station.entity_stop) - elseif correctness == 3 then - send_alert_no_train_matches_r_layout(r_station.entity_stop, closest_to_correct_p_station.entity_stop) - elseif correctness == 4 then - send_alert_no_train_matches_p_layout(r_station.entity_stop, closest_to_correct_p_station.entity_stop) + if closest_to_correct_p_station then + if correctness == 1 then + send_alert_missing_train(r_station.entity_stop, closest_to_correct_p_station.entity_stop) + elseif correctness == 2 then + send_alert_no_train_has_capacity(r_station.entity_stop, closest_to_correct_p_station.entity_stop) + elseif correctness == 3 then + send_alert_no_train_matches_r_layout(r_station.entity_stop, closest_to_correct_p_station.entity_stop) + elseif correctness == 4 then + send_alert_no_train_matches_p_layout(r_station.entity_stop, closest_to_correct_p_station.entity_stop) + end end if band(r_station.display_state, 2) == 0 then r_station.display_state = r_station.display_state + 2 diff --git a/cybersyn/scripts/global.lua b/cybersyn/scripts/global.lua index e50d3c9..69da833 100644 --- a/cybersyn/scripts/global.lua +++ b/cybersyn/scripts/global.lua @@ -131,6 +131,7 @@ ---@field public react_to_train_early_to_depot boolean --interface setting ---@field public enable_manager boolean ---@field public manager_ups double +---@field public manager_enabled boolean --if this is uncommented it means there are migrations to write diff --git a/cybersyn/scripts/layout.lua b/cybersyn/scripts/layout.lua index bfdea45..730fec7 100644 --- a/cybersyn/scripts/layout.lua +++ b/cybersyn/scripts/layout.lua @@ -215,7 +215,7 @@ function set_p_wagon_combs(map_data, station, train) if carriage.type == "cargo-wagon" then local inv = carriage.get_inventory(defines.inventory.cargo_wagon) if inv then - ---@type ConstantCombinatorParameters + ---@type ConstantCombinatorParameters[] local signals = {} local inv_filter_i = 1 diff --git a/cybersyn/scripts/main.lua b/cybersyn/scripts/main.lua index 50db145..badc983 100644 --- a/cybersyn/scripts/main.lua +++ b/cybersyn/scripts/main.lua @@ -115,7 +115,7 @@ end ---@param map_data MapData ---@param stop LuaEntity ---@param comb1 LuaEntity ----@param comb2 LuaEntity +---@param comb2 LuaEntity? local function on_station_built(map_data, stop, comb1, comb2) --NOTE: only place where new Station local station = { @@ -412,7 +412,7 @@ function combinator_update(map_data, comb, reset_display) local params = control.parameters local old_params = map_data.to_comb_params[unit_number] local has_changed = false - local type, id, entity = nil, nil, nil + local type, id, entity = nil, 0, nil local op = params.operation local is_mode_primary_io = op == MODE_PRIMARY_IO