mirror of
https://github.com/Xevion/project-cybersyn.git
synced 2025-12-11 08:08:15 -06:00
Fixed combinator displays
This commit is contained in:
4
TODO
4
TODO
@@ -1,6 +1,5 @@
|
||||
bugs:
|
||||
request threshold is being bypassed somehow
|
||||
wagon control combinators don't work parallel to the tracks
|
||||
request threshold is being bypassed somehow (hasn't been seen in a long time)
|
||||
|
||||
major:
|
||||
do hardcore testing
|
||||
@@ -12,4 +11,3 @@ minor:
|
||||
close gui when the combinator is destroyed
|
||||
do not play close sound when a different gui is opened
|
||||
gui can desync if settings are changed outside of it while it is open
|
||||
go over init and make it agree with type info
|
||||
|
||||
@@ -99,3 +99,9 @@ Version: 1.0.7
|
||||
Date: 2022-12-1
|
||||
Features:
|
||||
- Fixed a crash relating to depot bypass through space elevators
|
||||
---------------------------------------------------------------------------------------------------
|
||||
Version: 1.0.8
|
||||
Date: 2022-12-1
|
||||
Features:
|
||||
- Fixed a bug with combinator displays not updating correctly
|
||||
- Improved combinator display performance
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "cybersyn",
|
||||
"version": "1.0.7",
|
||||
"version": "1.0.8",
|
||||
"title": "Project Cybersyn",
|
||||
"author": "Mami",
|
||||
"factorio_version": "1.1",
|
||||
|
||||
@@ -9,8 +9,6 @@ local band = bit32.band
|
||||
local table_remove = table.remove
|
||||
local random = math.random
|
||||
|
||||
|
||||
|
||||
---@param map_data MapData
|
||||
---@param station Station
|
||||
---@param manifest Manifest
|
||||
@@ -24,8 +22,9 @@ function remove_manifest(map_data, station, manifest, sign)
|
||||
end
|
||||
set_comb2(map_data, station)
|
||||
station.deliveries_total = station.deliveries_total - 1
|
||||
if station.deliveries_total == 0 and station.entity_comb1.valid then
|
||||
set_comb_operation_with_check(map_data, station.entity_comb1, OPERATION_PRIMARY_IO)
|
||||
if station.deliveries_total == 0 and station.display_state >= 2 then
|
||||
station.display_state = station.display_state - 2
|
||||
update_display(map_data, station)
|
||||
end
|
||||
end
|
||||
|
||||
@@ -206,11 +205,14 @@ local function send_train_between(map_data, r_station_id, p_station_id, train_id
|
||||
|
||||
set_comb2(map_data, p_station)
|
||||
set_comb2(map_data, r_station)
|
||||
if p_station.entity_comb1.valid then
|
||||
set_comb_operation_with_check(map_data, p_station.entity_comb1, OPERATION_PRIMARY_IO_ACTIVE)
|
||||
|
||||
if p_station.display_state < 2 then
|
||||
p_station.display_state = 2
|
||||
update_display(map_data, p_station)
|
||||
end
|
||||
if r_station.entity_comb1.valid then
|
||||
set_comb_operation_with_check(map_data, r_station.entity_comb1, OPERATION_PRIMARY_IO_ACTIVE)
|
||||
if r_station.display_state < 2 then
|
||||
r_station.display_state = 2
|
||||
update_display(map_data, r_station)
|
||||
end
|
||||
end
|
||||
end
|
||||
@@ -258,11 +260,6 @@ local function tick_poll_station(map_data, mod_settings)
|
||||
station_id = map_data.active_station_ids[tick_data.i]
|
||||
station = map_data.stations[station_id]
|
||||
if station then
|
||||
if station.display_update then
|
||||
update_combinator_display(map_data, station.entity_comb1, station.display_failed_request)
|
||||
station.display_update = station.display_failed_request
|
||||
station.display_failed_request = nil
|
||||
end
|
||||
if station.network_name and station.deliveries_total < station.entity_stop.trains_limit then
|
||||
break
|
||||
end
|
||||
@@ -325,6 +322,9 @@ local function tick_poll_station(map_data, mod_settings)
|
||||
end
|
||||
stations[#stations + 1] = station_id
|
||||
station.p_count_or_r_threshold_per_item[item_name] = r_threshold
|
||||
elseif station.display_state%2 == 1 then
|
||||
station.display_state = station.display_state - 1
|
||||
update_display(map_data, station)
|
||||
end
|
||||
end
|
||||
if flag then
|
||||
@@ -391,9 +391,9 @@ local function tick_dispatch(map_data, mod_settings)
|
||||
else
|
||||
for i, id in ipairs(r_stations) do
|
||||
local station = stations[id]
|
||||
if station then
|
||||
station.display_failed_request = true
|
||||
station.display_update = true
|
||||
if station and station.display_state%2 == 0 then
|
||||
station.display_state = station.display_state + 1
|
||||
update_display(map_data, station)
|
||||
end
|
||||
end
|
||||
end
|
||||
@@ -419,6 +419,13 @@ local function tick_dispatch(map_data, mod_settings)
|
||||
end
|
||||
end
|
||||
if not r_station_i then
|
||||
for i, id in ipairs(r_stations) do
|
||||
local station = stations[id]
|
||||
if station and station.display_state%2 == 0 then
|
||||
station.display_state = station.display_state + 1
|
||||
update_display(map_data, station)
|
||||
end
|
||||
end
|
||||
return false
|
||||
end
|
||||
|
||||
@@ -464,8 +471,10 @@ local function tick_dispatch(map_data, mod_settings)
|
||||
if can_be_serviced then
|
||||
send_missing_train_alert_for_stops(r_station.entity_stop, stations[p_stations[best_i]].entity_stop)
|
||||
end
|
||||
r_station.display_failed_request = true
|
||||
r_station.display_update = true
|
||||
if r_station.display_state%2 == 0 then
|
||||
r_station.display_state = r_station.display_state + 1
|
||||
update_display(map_data, r_station)
|
||||
end
|
||||
end
|
||||
|
||||
table_remove(r_stations, r_station_i)
|
||||
|
||||
@@ -256,7 +256,7 @@ end
|
||||
---@param map_data MapData
|
||||
---@param unit_number uint
|
||||
---@param params ArithmeticCombinatorParameters
|
||||
function has_comb_params_changed(map_data, unit_number, params)
|
||||
local function has_comb_params_changed(map_data, unit_number, params)
|
||||
local old_params = map_data.to_comb_params[unit_number]
|
||||
|
||||
if params.operation ~= old_params.operation then
|
||||
@@ -278,41 +278,26 @@ function has_comb_params_changed(map_data, unit_number, params)
|
||||
return false
|
||||
end
|
||||
---@param map_data MapData
|
||||
---@param comb LuaEntity
|
||||
---@param op string
|
||||
function set_comb_operation_with_check(map_data, comb, op)
|
||||
---@type uint
|
||||
local unit_number = comb.unit_number
|
||||
local control = get_comb_control(comb)
|
||||
local params = control.parameters
|
||||
if not has_comb_params_changed(map_data, unit_number, params) then
|
||||
params.operation = op
|
||||
control.parameters = params
|
||||
if (op == OPERATION_PRIMARY_IO_ACTIVE or op == OPERATION_PRIMARY_IO_FAILED_REQUEST) then
|
||||
params.operation = OPERATION_PRIMARY_IO
|
||||
end
|
||||
map_data.to_comb_params[unit_number] = params
|
||||
end
|
||||
end
|
||||
---@param map_data MapData
|
||||
---@param comb LuaEntity
|
||||
---@param is_failed boolean
|
||||
function update_combinator_display(map_data, comb, is_failed)
|
||||
---@type uint
|
||||
local unit_number = comb.unit_number
|
||||
local control = get_comb_control(comb)
|
||||
local params = control.parameters
|
||||
if not has_comb_params_changed(map_data, unit_number, params) then
|
||||
if is_failed then
|
||||
if params.operation == OPERATION_PRIMARY_IO then
|
||||
---@param station Station
|
||||
function update_display(map_data, station)
|
||||
local comb = station.entity_comb1
|
||||
if comb.valid then
|
||||
local unit_number = comb.unit_number--[[@as uint]]
|
||||
local control = get_comb_control(comb)
|
||||
local params = control.parameters
|
||||
if not has_comb_params_changed(map_data, unit_number, params) then
|
||||
if station.display_state >= 2 then
|
||||
params.operation = OPERATION_PRIMARY_IO_ACTIVE
|
||||
control.parameters = params
|
||||
params.operation = OPERATION_PRIMARY_IO
|
||||
elseif station.display_state == 1 then
|
||||
params.operation = OPERATION_PRIMARY_IO_FAILED_REQUEST
|
||||
control.parameters = params
|
||||
params.operation = OPERATION_PRIMARY_IO
|
||||
map_data.to_comb_params[unit_number] = params
|
||||
else
|
||||
params.operation = OPERATION_PRIMARY_IO
|
||||
control.parameters = params
|
||||
end
|
||||
elseif params.operation == OPERATION_PRIMARY_IO_FAILED_REQUEST then
|
||||
params.operation = OPERATION_PRIMARY_IO
|
||||
control.parameters = params
|
||||
map_data.to_comb_params[unit_number] = params
|
||||
end
|
||||
end
|
||||
|
||||
@@ -20,6 +20,9 @@
|
||||
---@field public se_tele_old_id {[any]: uint}
|
||||
|
||||
---@class Station
|
||||
---@field public entity_stop LuaEntity
|
||||
---@field public entity_comb1 LuaEntity
|
||||
---@field public entity_comb2 LuaEntity?
|
||||
---@field public is_p boolean
|
||||
---@field public is_r boolean
|
||||
---@field public allows_all_trains boolean
|
||||
@@ -28,19 +31,15 @@
|
||||
---@field public priority int --transient
|
||||
---@field public r_threshold int >= 0 --transient
|
||||
---@field public locked_slots int >= 0 --transient
|
||||
---@field public entity_stop LuaEntity
|
||||
---@field public entity_comb1 LuaEntity
|
||||
---@field public entity_comb2 LuaEntity?
|
||||
---@field public wagon_combs {[int]: LuaEntity}?--NOTE: allowed to be invalid entities or combinators with the wrong operation, these must be checked and lazy deleted when found
|
||||
---@field public deliveries {[string]: int}
|
||||
---@field public network_name string?
|
||||
---@field public network_flag int --transient
|
||||
---@field public wagon_combs {[int]: LuaEntity}?--NOTE: allowed to be invalid entities or combinators with the wrong operation, these must be checked and lazy deleted when found
|
||||
---@field public deliveries {[string]: int}
|
||||
---@field public accepted_layouts {[uint]: true?}
|
||||
---@field public layout_pattern {[uint]: int}
|
||||
---@field public tick_signals {[uint]: Signal}? --transient
|
||||
---@field public p_count_or_r_threshold_per_item {[string]: int} --transient
|
||||
---@field public display_failed_request true?
|
||||
---@field public display_update true?
|
||||
---@field public display_state 0|1|2|3 --low bit is if this station's request has failed, high bit is if a train is heading to this station
|
||||
|
||||
---@class Depot
|
||||
---@field public entity_stop LuaEntity
|
||||
@@ -57,7 +56,7 @@
|
||||
---@field public r_station_id uint
|
||||
---@field public manifest Manifest
|
||||
---@field public last_manifest_tick int
|
||||
---@field public has_filtered_wagon boolean
|
||||
---@field public has_filtered_wagon true?
|
||||
---@field public is_available true?
|
||||
---@field public parked_at_depot_id uint?
|
||||
---@field public depot_name string
|
||||
@@ -73,7 +72,7 @@
|
||||
---@alias cybersyn.global MapData
|
||||
|
||||
---@class Economy
|
||||
---could contain invalid stations
|
||||
---could contain invalid stations or stations with modified settings from when they were first appended
|
||||
---@field public all_r_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)[]
|
||||
|
||||
@@ -69,11 +69,12 @@ local function add_available_train(map_data, train_id, train)
|
||||
end
|
||||
end
|
||||
---@param map_data MapData
|
||||
---@param mod_settings CybersynModSettings
|
||||
---@param depot_id uint
|
||||
---@param depot Depot
|
||||
---@param train_id uint
|
||||
---@param train Train
|
||||
local function add_available_train_to_depot(map_data, train_id, train, depot_id, depot)
|
||||
local function add_available_train_to_depot(map_data, mod_settings, train_id, train, depot_id, depot)
|
||||
local comb = depot.entity_comb
|
||||
local network_name = get_comb_network_name(comb)
|
||||
if network_name then
|
||||
@@ -133,10 +134,11 @@ end
|
||||
---@param stop LuaEntity
|
||||
---@param comb LuaEntity
|
||||
local function on_depot_built(map_data, stop, comb)
|
||||
--NOTE: only place where new Depot
|
||||
local depot = {
|
||||
entity_stop = stop,
|
||||
entity_comb = comb,
|
||||
--available_train = nil,
|
||||
available_train_id = nil,
|
||||
}
|
||||
map_data.depots[stop.unit_number] = depot
|
||||
end
|
||||
@@ -159,21 +161,28 @@ end
|
||||
---@param comb1 LuaEntity
|
||||
---@param comb2 LuaEntity
|
||||
local function on_station_built(map_data, stop, comb1, comb2)
|
||||
--NOTE: only place where new Station
|
||||
local station = {
|
||||
entity_stop = stop,
|
||||
entity_comb1 = comb1,
|
||||
entity_comb2 = comb2,
|
||||
wagon_combs = nil,
|
||||
--is_p = set_station_from_comb_state,
|
||||
--is_r = set_station_from_comb_state,
|
||||
--allows_all_trains = set_station_from_comb_state,
|
||||
deliveries_total = 0,
|
||||
last_delivery_tick = map_data.total_ticks,
|
||||
priority = 0,
|
||||
r_threshold = 0,
|
||||
locked_slots = 0,
|
||||
--network_name = set_station_from_comb_state,
|
||||
network_flag = 0,
|
||||
wagon_combs = nil,
|
||||
deliveries = {},
|
||||
accepted_layouts = {},
|
||||
layout_pattern = nil,
|
||||
tick_signals = nil,
|
||||
p_count_or_r_threshold_per_item = {},
|
||||
display_state = 0,
|
||||
}
|
||||
set_station_from_comb_state(station)
|
||||
local id = stop.unit_number--[[@as uint]]
|
||||
@@ -367,7 +376,7 @@ function on_combinator_network_updated(map_data, comb, network_name)
|
||||
if train_id then
|
||||
local train = map_data.trains[train_id]
|
||||
remove_available_train(map_data, train_id, train)
|
||||
add_available_train_to_depot(map_data, train_id, train, depot_id, depot)
|
||||
add_available_train_to_depot(map_data, mod_settings, train_id, train, depot_id, depot)
|
||||
end
|
||||
end
|
||||
end
|
||||
@@ -611,7 +620,7 @@ local function on_train_arrives_depot(map_data, depot_id, train_entity)
|
||||
end
|
||||
if is_train_empty then
|
||||
remove_available_train(map_data, train_id, train)
|
||||
add_available_train_to_depot(map_data, train_id, train, depot_id, map_data.depots[depot_id])
|
||||
add_available_train_to_depot(map_data, mod_settings, train_id, train, depot_id, map_data.depots[depot_id])
|
||||
set_depot_schedule(train_entity, train.depot_name)
|
||||
else
|
||||
--train still has cargo
|
||||
@@ -620,20 +629,28 @@ local function on_train_arrives_depot(map_data, depot_id, train_entity)
|
||||
send_nonempty_train_in_depot_alert(train_entity)
|
||||
end
|
||||
elseif is_train_empty then
|
||||
--NOTE: only place where new Train
|
||||
train = {
|
||||
status = STATUS_D,
|
||||
entity = train_entity,
|
||||
layout_id = 0,
|
||||
item_slot_capacity = 0,
|
||||
fluid_capacity = 0,
|
||||
--layout_id = update_train_layout,
|
||||
--item_slot_capacity = update_train_layout,
|
||||
--fluid_capacity = update_train_layout,
|
||||
--status = add_available_train_to_depot,
|
||||
p_station_id = 0,
|
||||
r_station_id = 0,
|
||||
manifest = nil,
|
||||
last_manifest_tick = map_data.total_ticks,
|
||||
--manifest = nil,
|
||||
has_filtered_wagon = nil,
|
||||
--is_available = add_available_train_to_depot,
|
||||
--parked_at_depot_id = add_available_train_to_depot,
|
||||
--depot_name = add_available_train_to_depot,
|
||||
--network_name = add_available_train_to_depot,
|
||||
--network_flag = add_available_train_to_depot,
|
||||
--priority = add_available_train_to_depot,
|
||||
}
|
||||
update_train_layout(map_data, train)
|
||||
map_data.trains[train_id] = train
|
||||
add_available_train_to_depot(map_data, train_id, train, depot_id, map_data.depots[depot_id])
|
||||
add_available_train_to_depot(map_data, mod_settings, train_id, train, depot_id, map_data.depots[depot_id])
|
||||
|
||||
set_depot_schedule(train_entity, train.depot_name)
|
||||
else
|
||||
@@ -691,7 +708,7 @@ local function on_train_leaves_station(map_data, mod_settings, train_id, train)
|
||||
set_comb1(map_data, station, nil)
|
||||
unset_wagon_combs(map_data, station)
|
||||
if train.has_filtered_wagon then
|
||||
train.has_filtered_wagon = false
|
||||
train.has_filtered_wagon = nil
|
||||
for carriage_i, carriage in ipairs(train.entity.cargo_wagons) do
|
||||
local inv = carriage.get_inventory(defines.inventory.cargo_wagon)
|
||||
if inv and inv.is_filtered() then
|
||||
|
||||
@@ -166,6 +166,24 @@ local migrations_table = {
|
||||
end
|
||||
end
|
||||
end,
|
||||
["1.0.8"] = function()
|
||||
---@type MapData
|
||||
local map_data = global
|
||||
map_data.tick_state = STATE_INIT
|
||||
map_data.tick_data = {}
|
||||
for id, station in pairs(map_data.stations) do
|
||||
local params = get_comb_params(station.entity_comb1)
|
||||
if params.operation == OPERATION_PRIMARY_IO_FAILED_REQUEST then
|
||||
station.display_state = 1
|
||||
elseif params.operation == OPERATION_PRIMARY_IO_ACTIVE then
|
||||
station.display_state = 2
|
||||
else
|
||||
station.display_state = 0
|
||||
end
|
||||
station.display_failed_request = nil
|
||||
station.update_display = nil
|
||||
end
|
||||
end,
|
||||
}
|
||||
|
||||
---@param data ConfigurationChangedData
|
||||
|
||||
Reference in New Issue
Block a user