mirror of
https://github.com/Xevion/project-cybersyn.git
synced 2025-12-15 18:12:46 -06:00
fixed potential crash
This commit is contained in:
2
.vscode/launch.json
vendored
2
.vscode/launch.json
vendored
@@ -53,9 +53,7 @@
|
|||||||
"debugadapter": true,
|
"debugadapter": true,
|
||||||
"flib": true,
|
"flib": true,
|
||||||
"cybersyn": true,
|
"cybersyn": true,
|
||||||
"creative-mod": true,
|
|
||||||
},
|
},
|
||||||
"disableExtraMods": true
|
|
||||||
}
|
}
|
||||||
]
|
]
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -188,12 +188,15 @@ local function send_train_between(map_data, r_station_id, p_station_id, depot, p
|
|||||||
local item_network_name = network_name..":"..item.name
|
local item_network_name = network_name..":"..item.name
|
||||||
local r_stations = economy.all_r_stations[item_network_name]
|
local r_stations = economy.all_r_stations[item_network_name]
|
||||||
local p_stations = economy.all_p_stations[item_network_name]
|
local p_stations = economy.all_p_stations[item_network_name]
|
||||||
|
if r_stations then
|
||||||
for j, id in ipairs(r_stations) do
|
for j, id in ipairs(r_stations) do
|
||||||
if id == r_station_id then
|
if id == r_station_id then
|
||||||
table_remove(r_stations, j)
|
table_remove(r_stations, j)
|
||||||
break
|
break
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
end
|
||||||
|
if p_stations then
|
||||||
for j, id in ipairs(p_stations) do
|
for j, id in ipairs(p_stations) do
|
||||||
if id == p_station_id then
|
if id == p_station_id then
|
||||||
table_remove(p_stations, j)
|
table_remove(p_stations, j)
|
||||||
@@ -202,6 +205,7 @@ local function send_train_between(map_data, r_station_id, p_station_id, depot, p
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
end
|
||||||
|
|
||||||
remove_available_train(map_data, depot)
|
remove_available_train(map_data, depot)
|
||||||
train.status = STATUS_D_TO_P
|
train.status = STATUS_D_TO_P
|
||||||
@@ -407,25 +411,32 @@ local function tick_dispatch(map_data, mod_settings)
|
|||||||
table_sort(r_stations, function(a_id, b_id)
|
table_sort(r_stations, function(a_id, b_id)
|
||||||
local a = stations[a_id]
|
local a = stations[a_id]
|
||||||
local b = stations[b_id]
|
local b = stations[b_id]
|
||||||
|
if a and b then
|
||||||
if a.priority ~= b.priority then
|
if a.priority ~= b.priority then
|
||||||
return a.priority < b.priority
|
return a.priority < b.priority
|
||||||
else
|
else
|
||||||
return a.last_delivery_tick > b.last_delivery_tick
|
return a.last_delivery_tick > b.last_delivery_tick
|
||||||
end
|
end
|
||||||
|
else
|
||||||
|
return a == nil
|
||||||
|
end
|
||||||
end)
|
end)
|
||||||
break
|
break
|
||||||
else
|
else
|
||||||
for i, id in ipairs(r_stations) do
|
for i, id in ipairs(r_stations) do
|
||||||
local station = stations[id]
|
local station = stations[id]
|
||||||
|
if station then
|
||||||
station.display_failed_request = true
|
station.display_failed_request = true
|
||||||
station.display_update = true
|
station.display_update = true
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
end
|
||||||
|
|
||||||
local r_station_id = table_remove(r_stations--[[@as uint[] ]])
|
local r_station_id = table_remove(r_stations--[[@as uint[] ]])
|
||||||
local r_station = stations[r_station_id]
|
local r_station = stations[r_station_id]
|
||||||
|
if r_station then
|
||||||
local item_name = tick_data.item_name
|
local item_name = tick_data.item_name
|
||||||
local item_type = tick_data.item_type
|
local item_type = tick_data.item_type
|
||||||
local r_threshold = r_station.p_count_or_r_threshold_per_item[item_name]
|
local r_threshold = r_station.p_count_or_r_threshold_per_item[item_name]
|
||||||
@@ -437,7 +448,7 @@ local function tick_dispatch(map_data, mod_settings)
|
|||||||
local could_have_been_serviced = false
|
local could_have_been_serviced = false
|
||||||
for j, p_station_id in ipairs(p_stations) do
|
for j, p_station_id in ipairs(p_stations) do
|
||||||
local p_station = stations[p_station_id]
|
local p_station = stations[p_station_id]
|
||||||
if p_station.p_count_or_r_threshold_per_item[item_name] >= r_threshold then
|
if p_station and p_station.p_count_or_r_threshold_per_item[item_name] >= r_threshold then
|
||||||
local prior = p_station.priority
|
local prior = p_station.priority
|
||||||
local slot_threshold = item_type == "fluid" and r_threshold or ceil(r_threshold/get_stack_size(map_data, item_name))
|
local slot_threshold = item_type == "fluid" and r_threshold or ceil(r_threshold/get_stack_size(map_data, item_name))
|
||||||
local depot, d = get_valid_train(map_data, r_station_id, p_station_id, item_type, slot_threshold)
|
local depot, d = get_valid_train(map_data, r_station_id, p_station_id, item_type, slot_threshold)
|
||||||
@@ -463,6 +474,7 @@ local function tick_dispatch(map_data, mod_settings)
|
|||||||
r_station.display_failed_request = true
|
r_station.display_failed_request = true
|
||||||
r_station.display_update = true
|
r_station.display_update = true
|
||||||
end
|
end
|
||||||
|
end
|
||||||
return false
|
return false
|
||||||
end
|
end
|
||||||
---@param map_data MapData
|
---@param map_data MapData
|
||||||
|
|||||||
@@ -64,6 +64,7 @@
|
|||||||
---@alias cybersyn.global MapData
|
---@alias cybersyn.global MapData
|
||||||
|
|
||||||
---@class Economy
|
---@class Economy
|
||||||
|
---could contain invalid stations
|
||||||
---@field public all_r_stations {[string]: uint[]} --{[network_name:item_name]: count}
|
---@field public all_r_stations {[string]: uint[]} --{[network_name:item_name]: count}
|
||||||
---@field public all_p_stations {[string]: uint[]} --{[network_name:item_name]: count}
|
---@field public all_p_stations {[string]: uint[]} --{[network_name:item_name]: count}
|
||||||
---@field public all_names {[string]: uint[]} --{[network_name:item_name]: count}
|
---@field public all_names {[string]: uint[]} --{[network_name:item_name]: count}
|
||||||
|
|||||||
@@ -661,12 +661,7 @@ local function on_broken(event)
|
|||||||
local entity = event.entity
|
local entity = event.entity
|
||||||
if not entity or not entity.valid then return end
|
if not entity or not entity.valid then return end
|
||||||
|
|
||||||
if entity.train then
|
if entity.name == "train-stop" then
|
||||||
local train = global.trains[entity.train.id]
|
|
||||||
if train then
|
|
||||||
on_train_broken(global, train)
|
|
||||||
end
|
|
||||||
elseif entity.name == "train-stop" then
|
|
||||||
on_stop_broken(global, entity)
|
on_stop_broken(global, entity)
|
||||||
elseif entity.name == COMBINATOR_NAME then
|
elseif entity.name == COMBINATOR_NAME then
|
||||||
on_combinator_broken(global, entity)
|
on_combinator_broken(global, entity)
|
||||||
@@ -676,6 +671,11 @@ local function on_broken(event)
|
|||||||
update_station_from_pump(global, entity, entity)
|
update_station_from_pump(global, entity, entity)
|
||||||
elseif entity.type == "straight-rail" then
|
elseif entity.type == "straight-rail" then
|
||||||
update_station_from_rail(global, entity, nil)
|
update_station_from_rail(global, entity, nil)
|
||||||
|
elseif entity.train then
|
||||||
|
local train = global.trains[entity.train.id]
|
||||||
|
if train then
|
||||||
|
on_train_broken(global, train)
|
||||||
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
local function on_rename(event)
|
local function on_rename(event)
|
||||||
|
|||||||
Reference in New Issue
Block a user