mirror of
https://github.com/Xevion/project-cybersyn.git
synced 2025-12-13 12:12:41 -06:00
improved fuel logic
This commit is contained in:
@@ -97,7 +97,8 @@
|
|||||||
---@field public all_p_stations {[string]: uint[]} --{["network_name:item_name"]: station_id}
|
---@field public all_p_stations {[string]: uint[]} --{["network_name:item_name"]: station_id}
|
||||||
---@field public all_names (string|SignalID)[]
|
---@field public all_names (string|SignalID)[]
|
||||||
|
|
||||||
--NOTE: any setting labeled as an interface setting can only be changed through the remote-interface, these settings are not save and have to be set at initialization
|
--NOTE: any setting labeled as an "interface setting" can only be changed through the remote-interface, these settings are not save and have to be set at initialization
|
||||||
|
--As a modder using the remote-interface, you may override any of these settings, including user settings. They will have to be overriden at initialization and whenever a user tries to change one.
|
||||||
---@class CybersynModSettings
|
---@class CybersynModSettings
|
||||||
---@field public tps double
|
---@field public tps double
|
||||||
---@field public update_rate int
|
---@field public update_rate int
|
||||||
|
|||||||
@@ -672,6 +672,7 @@ local function on_settings_changed(event)
|
|||||||
script.on_nth_tick(nil)
|
script.on_nth_tick(nil)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
interface_raise_on_mod_settings_changed(event)
|
||||||
end
|
end
|
||||||
|
|
||||||
local function setup_se_compat()
|
local function setup_se_compat()
|
||||||
|
|||||||
@@ -26,6 +26,7 @@ local on_train_stuck = nil
|
|||||||
local on_train_teleport_started = nil
|
local on_train_teleport_started = nil
|
||||||
local on_train_teleported = nil
|
local on_train_teleported = nil
|
||||||
local on_tick_init = nil
|
local on_tick_init = nil
|
||||||
|
local on_mod_settings_changed = nil
|
||||||
|
|
||||||
local interface = {}
|
local interface = {}
|
||||||
------------------------------------------------------------------
|
------------------------------------------------------------------
|
||||||
@@ -104,6 +105,10 @@ function interface.get_on_tick_init()
|
|||||||
if not on_tick_init then on_tick_init = script_generate_event_name() end
|
if not on_tick_init then on_tick_init = script_generate_event_name() end
|
||||||
return on_tick_init
|
return on_tick_init
|
||||||
end
|
end
|
||||||
|
function interface.get_on_mod_settings_changed()
|
||||||
|
if not on_mod_settings_changed then on_mod_settings_changed = script_generate_event_name() end
|
||||||
|
return on_mod_settings_changed
|
||||||
|
end
|
||||||
|
|
||||||
|
|
||||||
------------------------------------------------------------------
|
------------------------------------------------------------------
|
||||||
@@ -537,3 +542,8 @@ function interface_raise_tick_init()
|
|||||||
})
|
})
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
function interface_raise_on_mod_settings_changed(e)
|
||||||
|
if on_mod_settings_changed then
|
||||||
|
raise_event(on_mod_settings_changed, e)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|||||||
@@ -1,4 +1,5 @@
|
|||||||
--By Mami
|
--By Mami
|
||||||
|
local min = math.min
|
||||||
local INF = math.huge
|
local INF = math.huge
|
||||||
|
|
||||||
---@param map_data MapData
|
---@param map_data MapData
|
||||||
@@ -293,26 +294,28 @@ 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 = 0
|
local fuel_fill = INF
|
||||||
local total_slots = 0
|
for _, v in pairs(train.entity.locomotives) do
|
||||||
for k, v in pairs(train.entity.locomotives) do
|
for _, loco in pairs(v) do
|
||||||
if v[1] then
|
local inv = loco.get_fuel_inventory()
|
||||||
local inv = v[1].get_fuel_inventory()
|
|
||||||
if inv then
|
if inv then
|
||||||
local inv_size = #inv
|
local inv_size = #inv
|
||||||
total_slots = total_slots + inv_size
|
if inv_size > 0 then
|
||||||
|
local fuel_total = 0
|
||||||
|
---@type uint
|
||||||
for i = 1, inv_size do
|
for i = 1, inv_size do
|
||||||
local item = inv[i--[[@as uint]]]
|
local item = inv[i]
|
||||||
local count = item.count
|
if item.valid_for_read then
|
||||||
if count > 0 then
|
fuel_total = fuel_total + item.count/get_stack_size(map_data, item.name)
|
||||||
fuel_fill = fuel_fill + count/get_stack_size(map_data, item.name)
|
end
|
||||||
|
end
|
||||||
|
fuel_fill = min(fuel_fill, fuel_total/inv_size)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
if fuel_fill > mod_settings.fuel_threshold then
|
||||||
if total_slots == 0 or fuel_fill/total_slots > mod_settings.fuel_threshold then
|
--if fuel_fill == INF, it's probably a modded electric train
|
||||||
--if total_slots == 0, it's probably a modded electric train
|
|
||||||
if mod_settings.depot_bypass_enabled then
|
if mod_settings.depot_bypass_enabled 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)
|
||||||
|
|||||||
Reference in New Issue
Block a user