fixed a depot crash

This commit is contained in:
monica
2023-01-09 10:57:55 -05:00
parent 00850789a9
commit 73589b5c81
3 changed files with 21 additions and 16 deletions

View File

@@ -1,8 +1,11 @@
--------------------------------------------------------------------------------------------------- ---------------------------------------------------------------------------------------------------
Version: 1.3.0 Version: 1.3.0
Date: 2022-1-7 Date: 2022-1-7
Changes:
- Improved performance when fuel threshold is set to 1
Bugfixes: Bugfixes:
- Fixed a bug where it was possible for a single station to be updated twice per dispatch cycle, which could cause a crash - Fixed a bug where it was possible for a single station to be updated twice per dispatch cycle, which could cause a crash
- Fixed a crash where trains would sometimes think a destoyed depot still exists
--------------------------------------------------------------------------------------------------- ---------------------------------------------------------------------------------------------------
Version: 1.2.9 Version: 1.2.9
Date: 2022-1-7 Date: 2022-1-7

View File

@@ -31,7 +31,7 @@ function on_depot_broken(map_data, depot_id, depot)
local stops = e.force.get_train_stops({name = depot.entity_stop.backer_name, surface = e.surface}) local stops = e.force.get_train_stops({name = depot.entity_stop.backer_name, surface = e.surface})
for stop in rnext_consume, stops do for stop in rnext_consume, stops do
local new_depot_id = stop.unit_number local new_depot_id = stop.unit_number
if map_data.depots[new_depot_id] then if new_depot_id ~= depot_id and map_data.depots[new_depot_id] then
train.depot_id = new_depot_id--[[@as uint]] train.depot_id = new_depot_id--[[@as uint]]
goto continue goto continue
end end

View File

@@ -278,7 +278,8 @@ local function on_train_leaves_stop(map_data, mod_settings, train_id, train)
train.r_station_id = nil train.r_station_id = nil
train.manifest = nil train.manifest = nil
--add to available trains for depot bypass --add to available trains for depot bypass
local fuel_fill = INF local fuel_fill = 1
if mod_settings.fuel_threshold < 1 then
for _, v in pairs(train.entity.locomotives) do for _, v in pairs(train.entity.locomotives) do
for _, loco in pairs(v) do for _, loco in pairs(v) do
local inv = loco.get_fuel_inventory() local inv = loco.get_fuel_inventory()
@@ -298,8 +299,9 @@ local function on_train_leaves_stop(map_data, mod_settings, train_id, train)
end end
end end
end end
end
if fuel_fill > mod_settings.fuel_threshold then if fuel_fill > mod_settings.fuel_threshold then
--if fuel_fill == INF, it's probably a modded electric train --if fuel_fill == 1, it's probably a modded electric train
if not train.disable_bypass then if not train.disable_bypass then
train.status = STATUS_TO_D_BYPASS train.status = STATUS_TO_D_BYPASS
add_available_train(map_data, train_id, train) add_available_train(map_data, train_id, train)