fixed bug

This commit is contained in:
Monica Moniot
2022-12-08 11:38:11 -05:00
parent 0f42615e9c
commit d45d0700c6
7 changed files with 53 additions and 45 deletions

View File

@@ -13,14 +13,14 @@ COMBINATOR_OUT_NAME = "cybersyn-combinator-output"
COMBINATOR_CLOSE_SOUND = "entity-close/cybersyn-combinator"
ALERT_SOUND = "utility/console_message"
OPERATION_DEFAULT = "*"
OPERATION_PRIMARY_IO = "/"
OPERATION_PRIMARY_IO_FAILED_REQUEST = "^"
OPERATION_PRIMARY_IO_ACTIVE = "<<"
OPERATION_SECONDARY_IO = "%"
OPERATION_DEPOT = "+"
OPERATION_WAGON_MANIFEST = "-"
OPERATION_REFUELER = ">>"
MODE_DEFAULT = "*"
MODE_PRIMARY_IO = "/"
MODE_PRIMARY_IO_FAILED_REQUEST = "^"
MODE_PRIMARY_IO_ACTIVE = "<<"
MODE_SECONDARY_IO = "%"
MODE_DEPOT = "+"
MODE_WAGON_MANIFEST = "-"
MODE_REFUELER = ">>"
NETWORK_SIGNAL_DEFAULT = {name="signal-A", type="virtual"}
INACTIVITY_TIME = 100

View File

@@ -268,15 +268,15 @@ function get_comb_gui_settings(comb)
switch_state = "right"
end
if op == OPERATION_PRIMARY_IO or op == OPERATION_PRIMARY_IO_ACTIVE or op == OPERATION_PRIMARY_IO_FAILED_REQUEST then
if op == MODE_PRIMARY_IO or op == MODE_PRIMARY_IO_ACTIVE or op == MODE_PRIMARY_IO_FAILED_REQUEST then
selected_index = 1
elseif op == OPERATION_SECONDARY_IO then
elseif op == MODE_SECONDARY_IO then
selected_index = 2
elseif op == OPERATION_DEPOT then
elseif op == MODE_DEPOT then
selected_index = 3
elseif op == OPERATION_REFUELER then
elseif op == MODE_REFUELER then
selected_index = 4
elseif op == OPERATION_WAGON_MANIFEST then
elseif op == MODE_WAGON_MANIFEST then
selected_index = 5
end
return selected_index, params.first_signal, not allows_all_trains, switch_state
@@ -336,13 +336,13 @@ function update_display(map_data, station)
local control = get_comb_control(comb)
local params = control.parameters
--NOTE: the following check can cause a bug where the display desyncs if the player changes the operation of the combinator and then changes it back before the mod can notice, however removing it causes a bug where the user's change is overwritten and ignored. Everything's bad we need an event to catch copy-paste by blueprint.
if params.operation == OPERATION_PRIMARY_IO or params.operation == OPERATION_PRIMARY_IO_ACTIVE or params.operation == OPERATION_PRIMARY_IO_FAILED_REQUEST then
if params.operation == MODE_PRIMARY_IO or params.operation == MODE_PRIMARY_IO_ACTIVE or params.operation == MODE_PRIMARY_IO_FAILED_REQUEST then
if station.display_state >= 2 then
params.operation = OPERATION_PRIMARY_IO_ACTIVE
params.operation = MODE_PRIMARY_IO_ACTIVE
elseif station.display_state == 1 then
params.operation = OPERATION_PRIMARY_IO_FAILED_REQUEST
params.operation = MODE_PRIMARY_IO_FAILED_REQUEST
else
params.operation = OPERATION_PRIMARY_IO
params.operation = MODE_PRIMARY_IO
end
control.parameters = params
end

View File

@@ -145,35 +145,35 @@ function register_gui_actions()
local bottom_flow = all_flow.bottom
local param
if element.selected_index == 1 then
set_comb_operation(comb, OPERATION_PRIMARY_IO)
set_comb_operation(comb, MODE_PRIMARY_IO)
top_flow["switch"].visible = true
all_flow["network_label"].visible = true
bottom_flow["network"].visible = true
bottom_flow["radio_button"].visible = true
bottom_flow["radio_label"].visible = true
elseif element.selected_index == 2 then
set_comb_operation(comb, OPERATION_SECONDARY_IO)
set_comb_operation(comb, MODE_SECONDARY_IO)
top_flow["switch"].visible = false
all_flow["network_label"].visible = false
bottom_flow["network"].visible = false
bottom_flow["radio_button"].visible = false
bottom_flow["radio_label"].visible = false
elseif element.selected_index == 3 then
set_comb_operation(comb, OPERATION_DEPOT)
set_comb_operation(comb, MODE_DEPOT)
top_flow["switch"].visible = false
all_flow["network_label"].visible = true
bottom_flow["network"].visible = true
bottom_flow["radio_button"].visible = false
bottom_flow["radio_label"].visible = false
elseif element.selected_index == 4 then
set_comb_operation(comb, OPERATION_REFUELER)
set_comb_operation(comb, MODE_REFUELER)
top_flow["switch"].visible = false
all_flow["network_label"].visible = true
bottom_flow["network"].visible = true
bottom_flow["radio_button"].visible = true
bottom_flow["radio_label"].visible = true
elseif element.selected_index == 5 then
set_comb_operation(comb, OPERATION_WAGON_MANIFEST)
set_comb_operation(comb, MODE_WAGON_MANIFEST)
top_flow["switch"].visible = false
all_flow["network_label"].visible = false
bottom_flow["network"].visible = false

View File

@@ -519,7 +519,7 @@ function reset_stop_layout(map_data, stop, is_station_or_refueler, forbidden_ent
end
elseif entity.name == COMBINATOR_NAME then
local param = map_data.to_comb_params[entity.unit_number]
if param.operation == OPERATION_WAGON_MANIFEST then
if param.operation == MODE_WAGON_MANIFEST then
local pos = entity.position
local is_there
if is_ver then

View File

@@ -54,6 +54,14 @@ local function on_refueler_built(map_data, stop, comb)
local id = stop.unit_number--[[@as uint]]
map_data.refuelers[id] = refueler
update_stop_if_auto(map_data, refueler, false)
if refueler.network_name then
local network = map_data.to_refuelers[refueler.network_name]
if not network then
network = {}
map_data.to_refuelers[refueler.network_name] = network
end
network[id] = true
end
interface_raise_refueler_created(id)
end
---@param map_data MapData
@@ -233,13 +241,13 @@ local function on_combinator_built(map_data, comb)
local params = control.parameters
local op = params.operation
if op == OPERATION_DEFAULT then
op = OPERATION_PRIMARY_IO
if op == MODE_DEFAULT then
op = MODE_PRIMARY_IO
params.operation = op
params.first_signal = NETWORK_SIGNAL_DEFAULT
control.parameters = params
elseif op ~= OPERATION_PRIMARY_IO and op ~= OPERATION_SECONDARY_IO and op ~= OPERATION_DEPOT and op ~= OPERATION_WAGON_MANIFEST then
op = OPERATION_PRIMARY_IO
elseif op ~= MODE_PRIMARY_IO and op ~= MODE_SECONDARY_IO and op ~= MODE_DEPOT and op ~= MODE_REFUELER and op ~= MODE_WAGON_MANIFEST then
op = MODE_PRIMARY_IO
params.operation = op
control.parameters = params
end
@@ -249,7 +257,7 @@ local function on_combinator_built(map_data, comb)
map_data.to_output[comb.unit_number] = out
map_data.to_stop[comb.unit_number] = stop
if op == OPERATION_WAGON_MANIFEST then
if op == MODE_WAGON_MANIFEST then
if rail then
update_stop_from_rail(map_data, rail, nil, true)
end
@@ -258,22 +266,22 @@ local function on_combinator_built(map_data, comb)
local station = map_data.stations[id]
local depot = map_data.depots[id]
local refueler = map_data.refuelers[id]
if op == OPERATION_DEPOT then
if op == MODE_DEPOT then
if refueler then
on_refueler_broken(map_data, id, refueler)
end
if not station and not depot then
on_depot_built(map_data, stop, comb)
end
elseif op == OPERATION_REFUELER then
elseif op == MODE_REFUELER then
if not station and not depot and not refueler then
on_depot_built(map_data, stop, comb)
on_refueler_built(map_data, stop, comb)
end
elseif op == OPERATION_SECONDARY_IO then
elseif op == MODE_SECONDARY_IO then
if station and not station.entity_comb2 then
station.entity_comb2 = comb
end
elseif op == OPERATION_PRIMARY_IO then
elseif op == MODE_PRIMARY_IO then
if refueler then
on_refueler_broken(map_data, id, refueler)
end
@@ -281,7 +289,7 @@ local function on_combinator_built(map_data, comb)
on_depot_broken(map_data, id, depot)
end
if not station then
local comb2 = search_for_station_combinator(map_data, stop, OPERATION_SECONDARY_IO, comb)
local comb2 = search_for_station_combinator(map_data, stop, MODE_SECONDARY_IO, comb)
on_station_built(map_data, stop, comb, comb2)
end
end
@@ -353,7 +361,7 @@ function on_combinator_broken(map_data, comb)
on_station_broken(map_data, id, station)
on_stop_built(map_data, stop, comb)
elseif station.entity_comb2 == comb then
station.entity_comb2 = search_for_station_combinator(map_data, stop, OPERATION_SECONDARY_IO, comb)
station.entity_comb2 = search_for_station_combinator(map_data, stop, MODE_SECONDARY_IO, comb)
end
else
local depot = map_data.depots[id]
@@ -391,9 +399,9 @@ function combinator_update(map_data, comb)
local has_changed = false
if params.operation ~= old_params.operation then
if (old_params.operation == OPERATION_PRIMARY_IO) and (params.operation == OPERATION_PRIMARY_IO_ACTIVE or params.operation == OPERATION_PRIMARY_IO_FAILED_REQUEST) then
--make sure only OPERATION_PRIMARY_IO gets stored on map_data.to_comb_params
params.operation = OPERATION_PRIMARY_IO
if (old_params.operation == MODE_PRIMARY_IO) and (params.operation == MODE_PRIMARY_IO_ACTIVE or params.operation == MODE_PRIMARY_IO_FAILED_REQUEST) then
--make sure only MODE_PRIMARY_IO gets stored on map_data.to_comb_params
params.operation = MODE_PRIMARY_IO
else
--NOTE: This is rather dangerous, we may need to actually implement operation changing
on_combinator_broken(map_data, comb)
@@ -461,13 +469,13 @@ function on_stop_built(map_data, stop, comb_forbidden)
map_data.to_stop[entity.unit_number] = stop
local param = get_comb_params(entity)
local op = param.operation
if op == OPERATION_PRIMARY_IO then
if op == MODE_PRIMARY_IO then
comb1 = entity
elseif op == OPERATION_SECONDARY_IO then
elseif op == MODE_SECONDARY_IO then
comb2 = entity
elseif op == OPERATION_DEPOT then
elseif op == MODE_DEPOT then
depot_comb = entity
elseif op == OPERATION_REFUELER then
elseif op == MODE_REFUELER then
refueler_comb = entity
end
end

View File

@@ -57,9 +57,9 @@ local migrations_table = {
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
if params.operation == MODE_PRIMARY_IO_FAILED_REQUEST then
station.display_state = 1
elseif params.operation == OPERATION_PRIMARY_IO_ACTIVE then
elseif params.operation == MODE_PRIMARY_IO_ACTIVE then
station.display_state = 2
else
station.display_state = 0

View File

@@ -330,7 +330,7 @@ local function on_train_leaves_stop(map_data, mod_settings, train_id, train)
local best_refueler_id = nil
local best_dist = INF
local best_prior = -INF
for i, id in ipairs(refuelers) do
for id, _ in pairs(refuelers) do
local refueler = map_data.refuelers[id]
set_refueler_from_comb(mod_settings, refueler)
if bit32.btest(train.network_flag, refueler.network_flag) and (refueler.allows_all_trains or refueler.accepted_layouts[train.layout_id]) and refueler.trains_total < refueler.entity_stop.trains_limit then