From 5ea40971f160ea37f126b16dc193834a81693ac4 Mon Sep 17 00:00:00 2001 From: Monica Moniot Date: Thu, 1 Dec 2022 14:18:13 -0500 Subject: [PATCH] fixed a crash relating to space elevators --- cybersyn/locale/en/base.cfg | 2 +- cybersyn/scripts/main.lua | 8 ++++++++ cybersyn/scripts/migrations.lua | 21 +++++++++++++++++++++ 3 files changed, 30 insertions(+), 1 deletion(-) diff --git a/cybersyn/locale/en/base.cfg b/cybersyn/locale/en/base.cfg index 76aa0e1..aa19734 100644 --- a/cybersyn/locale/en/base.cfg +++ b/cybersyn/locale/en/base.cfg @@ -41,7 +41,7 @@ cybersyn-request-threshold=Request threshold cybersyn-locked-slots=Locked slots per cargo wagon [cybersyn-messages] -missing-trains=No trains available to make a delivery from __2__ to __1__ +missing-trains=Could not find a train to make a delivery from __2__ to __1__ lost-train=A train from depot __1__ has become lost 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 diff --git a/cybersyn/scripts/main.lua b/cybersyn/scripts/main.lua index 41c0505..d502834 100644 --- a/cybersyn/scripts/main.lua +++ b/cybersyn/scripts/main.lua @@ -998,6 +998,14 @@ local function main() local train = map_data.trains[old_id] if not train then return end + if train.is_available then + local network = map_data.available_trains[train.network_name--[[@as string]]] + if network then + network[new_id] = true + network[old_id] = nil + end + end + map_data.trains[new_id] = train map_data.trains[old_id] = nil train.entity = train_entity diff --git a/cybersyn/scripts/migrations.lua b/cybersyn/scripts/migrations.lua index beb20ff..3c47f48 100644 --- a/cybersyn/scripts/migrations.lua +++ b/cybersyn/scripts/migrations.lua @@ -142,6 +142,27 @@ local migrations_table = { end end end, + ["1.0.7"] = function() + ---@type MapData + local map_data = global + map_data.tick_state = STATE_INIT + map_data.tick_data = {} + if IS_SE_PRESENT then + for k, v in pairs(map_data.available_trains) do + for id, _ in pairs(v) do + local train = map_data.trains[id] + if not train then + v[id] = nil + end + end + end + for id, v in pairs(map_data.trains) do + if v.is_available then + map_data.available_trains[v.network_name--[[@as string]]][id] = true + end + end + end + end, } ---@param data ConfigurationChangedData