mirror of
https://github.com/Xevion/project-cybersyn.git
synced 2025-12-15 06:12:50 -06:00
added a warmup time on stations
This commit is contained in:
@@ -266,12 +266,12 @@ local function tick_poll_station(map_data, mod_settings)
|
||||
local station
|
||||
while true do--choose a station
|
||||
tick_data.i = (tick_data.i or 0) + 1
|
||||
if tick_data.i > #map_data.all_station_ids then
|
||||
if tick_data.i > #map_data.active_station_ids then
|
||||
tick_data.i = nil
|
||||
map_data.tick_state = STATE_DISPATCH
|
||||
return true
|
||||
end
|
||||
station_id = map_data.all_station_ids[tick_data.i]
|
||||
station_id = map_data.active_station_ids[tick_data.i]
|
||||
station = map_data.stations[station_id]
|
||||
if station then
|
||||
if station.display_update then
|
||||
@@ -284,7 +284,7 @@ local function tick_poll_station(map_data, mod_settings)
|
||||
end
|
||||
else
|
||||
--lazy delete removed stations
|
||||
table_remove(map_data.all_station_ids, tick_data.i)
|
||||
table_remove(map_data.active_station_ids, tick_data.i)
|
||||
tick_data.i = tick_data.i - 1
|
||||
end
|
||||
end
|
||||
@@ -489,6 +489,17 @@ function tick(map_data, mod_settings)
|
||||
map_data.economy.all_r_stations = {}
|
||||
map_data.economy.all_names = {}
|
||||
map_data.tick_state = STATE_POLL_STATIONS
|
||||
for i, id in pairs(map_data.warmup_station_ids) do
|
||||
local station = map_data.stations[id]
|
||||
if station then
|
||||
if station.last_delivery_tick + mod_settings.warmup_time*mod_settings.tps >= map_data.total_ticks then
|
||||
map_data.active_station_ids[#map_data.active_station_ids + 1] = id
|
||||
map_data.warmup_station_ids[i] = nil
|
||||
end
|
||||
else
|
||||
map_data.warmup_station_ids[i] = nil
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
if map_data.tick_state == STATE_POLL_STATIONS then
|
||||
|
||||
@@ -6,7 +6,8 @@
|
||||
---@field public to_output {[uint]: LuaEntity}
|
||||
---@field public to_stop {[uint]: LuaEntity}
|
||||
---@field public stations {[uint]: Station}
|
||||
---@field public all_station_ids uint[]
|
||||
---@field public active_station_ids uint[]
|
||||
---@field public warmup_station_ids uint[]
|
||||
---@field public depots {[uint]: Depot}
|
||||
---@field public trains {[uint]: Train}
|
||||
---@field public trains_available {[string]: {[uint]: uint}} --{[network_name]: {[train_id]: depot_id}}
|
||||
@@ -74,6 +75,7 @@
|
||||
---@field public tps int
|
||||
---@field public r_threshold int
|
||||
---@field public network_flag int
|
||||
---@field public warmup_time int
|
||||
|
||||
---@type CybersynModSettings
|
||||
mod_settings = {}
|
||||
@@ -91,7 +93,8 @@ function init_global()
|
||||
global.to_output = {}
|
||||
global.to_stop = {}
|
||||
global.stations = {}
|
||||
global.all_station_ids = {}
|
||||
global.active_station_ids = {}
|
||||
global.warmup_station_ids = {}
|
||||
global.depots = {}
|
||||
global.trains = {}
|
||||
global.trains_available = {}
|
||||
|
||||
@@ -125,7 +125,7 @@ local function on_station_built(map_data, stop, comb1, comb2)
|
||||
entity_comb2 = comb2,
|
||||
wagon_combs = nil,
|
||||
deliveries_total = 0,
|
||||
last_delivery_tick = 0,
|
||||
last_delivery_tick = map_data.total_ticks,
|
||||
priority = 0,
|
||||
r_threshold = 0,
|
||||
locked_slots = 0,
|
||||
@@ -140,7 +140,7 @@ local function on_station_built(map_data, stop, comb1, comb2)
|
||||
set_station_from_comb_state(station)
|
||||
local id = stop.unit_number--[[@as uint]]
|
||||
map_data.stations[id] = station
|
||||
map_data.all_station_ids[#map_data.all_station_ids + 1] = id
|
||||
map_data.warmup_station_ids[#map_data.warmup_station_ids + 1] = id
|
||||
|
||||
update_station_if_auto(map_data, station, nil)
|
||||
end
|
||||
@@ -747,6 +747,7 @@ local function on_settings_changed(event)
|
||||
mod_settings.tps = settings.global["cybersyn-ticks-per-second"].value --[[@as int]]
|
||||
mod_settings.r_threshold = settings.global["cybersyn-request-threshold"].value--[[@as int]]
|
||||
mod_settings.network_flag = settings.global["cybersyn-network-flag"].value--[[@as int]]
|
||||
mod_settings.warmup_time = settings.global["cybersyn-warmup-time"].value--[[@as int]]
|
||||
if event.setting == "cybersyn-ticks-per-second" then
|
||||
local nth_tick = math.ceil(60/mod_settings.tps);
|
||||
flib_event.on_nth_tick(nil)
|
||||
@@ -776,6 +777,7 @@ local function main()
|
||||
mod_settings.tps = settings.global["cybersyn-ticks-per-second"].value --[[@as int]]
|
||||
mod_settings.r_threshold = settings.global["cybersyn-request-threshold"].value--[[@as int]]
|
||||
mod_settings.network_flag = settings.global["cybersyn-network-flag"].value--[[@as int]]
|
||||
mod_settings.warmup_time = settings.global["cybersyn-warmup-time"].value--[[@as int]]
|
||||
|
||||
--NOTE: There is a concern that it is possible to build or destroy important entities without one of these events being triggered, in which case the mod will have undefined behavior
|
||||
flib_event.register(defines.events.on_built_entity, on_built, filter_built)
|
||||
|
||||
@@ -23,6 +23,14 @@ local migrations_table = {
|
||||
station.p_threshold = nil
|
||||
end
|
||||
end,
|
||||
["0.3.0"] = function()
|
||||
---@type MapData
|
||||
local map_data = global
|
||||
map_data.warmup_station_ids = {}
|
||||
map_data.active_station_ids = map_data.all_station_ids
|
||||
map_data.all_station_ids = nil
|
||||
mod_settings.warmup_time = settings.global["cybersyn-warmup-time"].value--[[@as int]]
|
||||
end,
|
||||
}
|
||||
|
||||
---@param data ConfigurationChangedData
|
||||
|
||||
Reference in New Issue
Block a user