mirror of
https://github.com/Xevion/project-cybersyn.git
synced 2025-12-11 08:08:15 -06:00
added capacity sorting
This commit is contained in:
1
.vscode/launch.json
vendored
1
.vscode/launch.json
vendored
@@ -28,7 +28,6 @@
|
|||||||
"debugadapter": true,
|
"debugadapter": true,
|
||||||
"flib": true,
|
"flib": true,
|
||||||
"cybersyn": true,
|
"cybersyn": true,
|
||||||
"creative-mod": true,
|
|
||||||
},
|
},
|
||||||
"disableExtraMods": false
|
"disableExtraMods": false
|
||||||
},
|
},
|
||||||
|
|||||||
@@ -170,6 +170,7 @@ local function get_valid_train(map_data, r_station_id, p_station_id, item_type)
|
|||||||
|
|
||||||
---@type Depot|nil
|
---@type Depot|nil
|
||||||
local best_depot = nil
|
local best_depot = nil
|
||||||
|
local best_capacity = 0
|
||||||
local best_dist = INF
|
local best_dist = INF
|
||||||
local valid_train_exists = false
|
local valid_train_exists = false
|
||||||
|
|
||||||
@@ -182,9 +183,10 @@ local function get_valid_train(map_data, r_station_id, p_station_id, item_type)
|
|||||||
local layout_id = train.layout_id
|
local layout_id = train.layout_id
|
||||||
--check cargo capabilities
|
--check cargo capabilities
|
||||||
--check layout validity for both stations
|
--check layout validity for both stations
|
||||||
|
local capacity = (is_fluid and train.fluid_capacity) or train.item_slot_capacity
|
||||||
if
|
if
|
||||||
|
capacity > 0 and
|
||||||
btest(netand, depot.network_flag) and
|
btest(netand, depot.network_flag) and
|
||||||
((is_fluid and train.fluid_capacity > 0) or (not is_fluid and train.item_slot_capacity > 0)) and
|
|
||||||
(r_station.is_all or r_station.accepted_layouts[layout_id]) and
|
(r_station.is_all or r_station.accepted_layouts[layout_id]) and
|
||||||
(p_station.is_all or p_station.accepted_layouts[layout_id])
|
(p_station.is_all or p_station.accepted_layouts[layout_id])
|
||||||
then
|
then
|
||||||
@@ -194,7 +196,8 @@ local function get_valid_train(map_data, r_station_id, p_station_id, item_type)
|
|||||||
local d_to_p_dist = get_stop_dist(depot.entity_stop, p_station.entity_stop) - DEPOT_PRIORITY_MULT*depot.priority
|
local d_to_p_dist = get_stop_dist(depot.entity_stop, p_station.entity_stop) - DEPOT_PRIORITY_MULT*depot.priority
|
||||||
|
|
||||||
local dist = d_to_p_dist
|
local dist = d_to_p_dist
|
||||||
if dist < best_dist then
|
if capacity > best_capacity or (capacity == best_capacity and dist < best_dist) then
|
||||||
|
best_capacity = capacity
|
||||||
best_dist = dist
|
best_dist = dist
|
||||||
best_depot = depot
|
best_depot = depot
|
||||||
end
|
end
|
||||||
|
|||||||
@@ -3,6 +3,8 @@ local area = require("__flib__.area")
|
|||||||
local abs = math.abs
|
local abs = math.abs
|
||||||
local floor = math.floor
|
local floor = math.floor
|
||||||
local ceil = math.ceil
|
local ceil = math.ceil
|
||||||
|
local string_find = string.find
|
||||||
|
local string_sub = string.sub
|
||||||
|
|
||||||
local function iterr(a, i)
|
local function iterr(a, i)
|
||||||
i = i + 1
|
i = i + 1
|
||||||
@@ -431,11 +433,11 @@ local function reset_station_layout(map_data, station, forbidden_entity)
|
|||||||
search_area = area.move(search_area, area_delta)
|
search_area = area.move(search_area, area_delta)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
layout_pattern = string.sub(layout_pattern, 1, pattern_length)..STATION_LAYOUT_NA.."*$"
|
layout_pattern = string_sub(layout_pattern, 1, pattern_length)..STATION_LAYOUT_NA.."*$"
|
||||||
station.layout_pattern = layout_pattern
|
station.layout_pattern = layout_pattern
|
||||||
local accepted_layouts = station.accepted_layouts
|
local accepted_layouts = station.accepted_layouts
|
||||||
for id, layout in pairs(map_data.layouts) do
|
for id, layout in pairs(map_data.layouts) do
|
||||||
if string.find(layout, layout_pattern) ~= nil then
|
if string_find(layout, layout_pattern) ~= nil then
|
||||||
accepted_layouts[id] = true
|
accepted_layouts[id] = true
|
||||||
else
|
else
|
||||||
accepted_layouts[id] = nil
|
accepted_layouts[id] = nil
|
||||||
|
|||||||
Reference in New Issue
Block a user