diff --git a/cybersyn/changelog.txt b/cybersyn/changelog.txt index a563926..1ceff0f 100644 --- a/cybersyn/changelog.txt +++ b/cybersyn/changelog.txt @@ -9,9 +9,13 @@ Date: 2022-11-10 Features: - Removed provide-threshold - Added ability to specify station type on a cybernetic combinator - --------------------------------------------------------------------------------------------------- Version: 0.2.1 Date: 2022-11-11 Features: - Minor bugfixes and performance improvements +--------------------------------------------------------------------------------------------------- +Version: 0.3.0 +Date: 2022-11-13 + Features: + - Added warmup period on just built stations diff --git a/cybersyn/info.json b/cybersyn/info.json index 719e2ed..8dddfad 100644 --- a/cybersyn/info.json +++ b/cybersyn/info.json @@ -1,6 +1,6 @@ { "name": "cybersyn", - "version": "0.2.1", + "version": "0.3.0", "title": "Project Cybersyn", "author": "Mami", "factorio_version": "1.1", diff --git a/cybersyn/locale/en/base.cfg b/cybersyn/locale/en/base.cfg index 055c857..f0f8c42 100644 --- a/cybersyn/locale/en/base.cfg +++ b/cybersyn/locale/en/base.cfg @@ -2,11 +2,13 @@ cybersyn-ticks-per-second=Dispatcher updates per second cybersyn-request-threshold=Default requester threshold cybersyn-network-flag=Default network flags +cybersyn-warmup-time=Station warmup time [mod-setting-description] cybersyn-ticks-per-second=How many times per second the dispather should check for new deliveries. Deliveries are made one at a time per update. This value will be rounded up to a divisor of 60. cybersyn-request-threshold=The default request threshold when a request threshold signal is not given to a station. Huge values will prevent stations from taking requests from the network unless an explicit threshold is set. cybersyn-network-flag=The default set of networks a station will service when no network signal is given to a station. This integer is interpretted bit-wise to give 32 possible network flags to choose from. +cybersyn-warmup-time=How many seconds a cybernetic combinator will wait before connecting to the Cybersyn network. A grace period to modify or correct the circuit network before trains start dispatching to a newly blueprinted station. [item-name] cybersyn-combinator=Cybernetic combinator diff --git a/cybersyn/scripts/central-planning.lua b/cybersyn/scripts/central-planning.lua index 9e2b4d6..2da75b2 100644 --- a/cybersyn/scripts/central-planning.lua +++ b/cybersyn/scripts/central-planning.lua @@ -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 diff --git a/cybersyn/scripts/global.lua b/cybersyn/scripts/global.lua index 5ac47dd..19dfac3 100644 --- a/cybersyn/scripts/global.lua +++ b/cybersyn/scripts/global.lua @@ -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 = {} diff --git a/cybersyn/scripts/main.lua b/cybersyn/scripts/main.lua index ebd5730..4980bf7 100644 --- a/cybersyn/scripts/main.lua +++ b/cybersyn/scripts/main.lua @@ -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) diff --git a/cybersyn/scripts/migrations.lua b/cybersyn/scripts/migrations.lua index 8cc7149..d854087 100644 --- a/cybersyn/scripts/migrations.lua +++ b/cybersyn/scripts/migrations.lua @@ -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 diff --git a/cybersyn/settings.lua b/cybersyn/settings.lua index f25ed54..e60fd94 100644 --- a/cybersyn/settings.lua +++ b/cybersyn/settings.lua @@ -27,4 +27,13 @@ data:extend({ minimum_value = -2147483648, maximum_value = 2147483647, }, + { + type = "int-setting", + name = "cybersyn-warmup-time", + order = "ac", + setting_type = "runtime-global", + default_value = 20, + minimum_value = 0, + maximum_value = 2147483647, + }, })