fixed copy-paste

This commit is contained in:
Monica Moniot
2022-11-19 10:21:40 -05:00
parent c93d4bdcf8
commit 3a8e91b11d
7 changed files with 84 additions and 76 deletions

4
TODO
View File

@@ -1,9 +1,7 @@
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
do hardcore testing
models & art
space elevator compat
railloader compat
add missing items alert
lost train can be repurposed and rescheduled while alert is active
display when train is coming

View File

@@ -21,7 +21,7 @@ Date: 2022-11-13
- Added warmup period on just built stations
---------------------------------------------------------------------------------------------------
Version: 0.3.0
Date: 2022-11-13
Date: 2022-11-15
Features:
- Fixed copy-paste
- Added alert sounds

View File

@@ -33,7 +33,7 @@ function remove_manifest(map_data, station, manifest, sign)
set_comb2(map_data, station)
station.deliveries_total = station.deliveries_total - 1
if station.deliveries_total == 0 and station.entity_comb1.valid then
set_combinator_operation(station.entity_comb1, OPERATION_PRIMARY_IO)
map_data.to_comb_params[station.entity_comb1.unit_number] = set_combinator_operation(station.entity_comb1, OPERATION_PRIMARY_IO)
end
end
@@ -220,10 +220,10 @@ local function send_train_between(map_data, r_station_id, p_station_id, depot, p
set_comb2(map_data, p_station)
set_comb2(map_data, r_station)
if p_station.entity_comb1.valid then
set_combinator_operation(p_station.entity_comb1, OPERATION_PRIMARY_IO_ACTIVE)
map_data.to_comb_params[p_station.entity_comb1.unit_number] = set_combinator_operation(p_station.entity_comb1, OPERATION_PRIMARY_IO_ACTIVE)
end
if r_station.entity_comb1.valid then
set_combinator_operation(r_station.entity_comb1, OPERATION_PRIMARY_IO_ACTIVE)
map_data.to_comb_params[r_station.entity_comb1.unit_number] = set_combinator_operation(r_station.entity_comb1, OPERATION_PRIMARY_IO_ACTIVE)
end
end
@@ -275,7 +275,7 @@ local function tick_poll_station(map_data, mod_settings)
station = map_data.stations[station_id]
if station then
if station.display_update then
update_combinator_display(station.entity_comb1, station.display_failed_request)
map_data.to_comb_params[station.entity_comb1.unit_number] = update_combinator_display(station.entity_comb1, station.display_failed_request)
station.display_update = station.display_failed_request
station.display_failed_request = nil
end
@@ -439,43 +439,45 @@ local function tick_dispatch(map_data, mod_settings)
local item_type = tick_data.item_type
local r_threshold = r_station.p_count_or_r_threshold_per_item[item_name]
local best = 0
local best_depot = nil
local best_dist = INF
local highest_prior = -INF
local can_be_serviced = false
for j, p_station_id in ipairs(p_stations) do
local p_station = stations[p_station_id]
if p_station and p_station.p_count_or_r_threshold_per_item[item_name] >= r_threshold and p_station.deliveries_total < p_station.entity_stop.trains_limit then
local prior = p_station.priority
local slot_threshold = item_type == "fluid" and r_threshold or ceil(r_threshold/get_stack_size(map_data, item_name))
local depot, d = get_valid_train(map_data, r_station_id, p_station_id, item_type, slot_threshold)
if prior > highest_prior or (prior == highest_prior and d < best_dist) then
if depot then
best = j
best_dist = d
best_depot = depot
highest_prior = prior
can_be_serviced = true
elseif d < INF then
best = j
can_be_serviced = true
if r_threshold then
local best = 0
local best_depot = nil
local best_dist = INF
local highest_prior = -INF
local can_be_serviced = false
for j, p_station_id in ipairs(p_stations) do
local p_station = stations[p_station_id]
if p_station and (p_station.p_count_or_r_threshold_per_item[item_name] or -1) >= r_threshold and p_station.deliveries_total < p_station.entity_stop.trains_limit then
local prior = p_station.priority
local slot_threshold = item_type == "fluid" and r_threshold or ceil(r_threshold/get_stack_size(map_data, item_name))
local depot, d = get_valid_train(map_data, r_station_id, p_station_id, item_type, slot_threshold)
if prior > highest_prior or (prior == highest_prior and d < best_dist) then
if depot then
best = j
best_dist = d
best_depot = depot
highest_prior = prior
can_be_serviced = true
elseif d < INF then
best = j
can_be_serviced = true
end
end
end
end
end
if
best_depot and (
best_depot.entity_comb.status == defines.entity_status.working or
best_depot.entity_comb.status == defines.entity_status.low_power)
then
send_train_between(map_data, r_station_id, table_remove(p_stations--[[@as {}]], best), best_depot, item_name)
else
if can_be_serviced then
send_missing_train_alert_for_stops(r_station.entity_stop, stations[p_stations--[[@as {}]][best]].entity_stop)
if
best_depot and (
best_depot.entity_comb.status == defines.entity_status.working or
best_depot.entity_comb.status == defines.entity_status.low_power)
then
send_train_between(map_data, r_station_id, table_remove(p_stations--[[@as {}]], best), best_depot, item_name)
else
if can_be_serviced then
send_missing_train_alert_for_stops(r_station.entity_stop, stations[p_stations--[[@as {}]][best]].entity_stop)
end
r_station.display_failed_request = true
r_station.display_update = true
end
r_station.display_failed_request = true
r_station.display_update = true
end
end
return false

View File

@@ -15,7 +15,7 @@ ALERT_SOUND = "utility/console_message"
OPERATION_DEFAULT = "*"
OPERATION_PRIMARY_IO = "/"
OPERATION_PRIMARY_IO_REQUEST_FAILED = "^"
OPERATION_PRIMARY_IO_FAILED_REQUEST = "^"
OPERATION_PRIMARY_IO_ACTIVE = "<<"
OPERATION_SECONDARY_IO = "%"
OPERATION_DEPOT = "+"

View File

@@ -154,13 +154,14 @@ function update_combinator_display(comb, is_failed)
local param = control.parameters
if is_failed then
if param.operation == OPERATION_PRIMARY_IO then
param.operation = OPERATION_PRIMARY_IO_REQUEST_FAILED
param.operation = OPERATION_PRIMARY_IO_FAILED_REQUEST
control.parameters = param
end
elseif param.operation == OPERATION_PRIMARY_IO_REQUEST_FAILED then
elseif param.operation == OPERATION_PRIMARY_IO_FAILED_REQUEST then
param.operation = OPERATION_PRIMARY_IO
control.parameters = param
end
return param
end

View File

@@ -44,7 +44,7 @@ function gui_opened(comb, player)
switch_state = "right"
end
if op == OPERATION_PRIMARY_IO or op == OPERATION_PRIMARY_IO_ACTIVE or op == OPERATION_PRIMARY_IO_REQUEST_FAILED then
if op == OPERATION_PRIMARY_IO or op == OPERATION_PRIMARY_IO_ACTIVE or op == OPERATION_PRIMARY_IO_FAILED_REQUEST then
selected_index = 1
elseif op == OPERATION_SECONDARY_IO then
selected_index = 2

View File

@@ -248,21 +248,22 @@ local function on_combinator_built(map_data, comb)
local param = control.parameters
local op = param.operation
map_data.to_comb[comb.unit_number] = comb
map_data.to_output[comb.unit_number] = out
map_data.to_stop[comb.unit_number] = stop
map_data.to_comb_params[comb.unit_number] = param
if op == OPERATION_DEFAULT then
op = OPERATION_PRIMARY_IO
param.operation = op
param.first_signal = NETWORK_SIGNAL_DEFAULT
control.parameters = param
elseif op == OPERATION_PRIMARY_IO_ACTIVE or op == OPERATION_PRIMARY_IO_REQUEST_FAILED then
elseif op == OPERATION_PRIMARY_IO_ACTIVE or op == OPERATION_PRIMARY_IO_FAILED_REQUEST then
op = OPERATION_PRIMARY_IO
param.operation = op
control.parameters = param
end
map_data.to_comb[comb.unit_number] = comb
map_data.to_output[comb.unit_number] = out
map_data.to_stop[comb.unit_number] = stop
map_data.to_comb_params[comb.unit_number] = param
if op == OPERATION_WAGON_MANIFEST then
if rail then
force_update_station_from_rail(map_data, rail, nil)
@@ -392,35 +393,41 @@ end
function on_combinator_updated(map_data, comb, new_params)
local old_params = map_data.to_comb_params[comb.unit_number]
if new_params.operation ~= old_params.operation then
on_combinator_broken(map_data, comb)
on_combinator_built(map_data, comb)
else
local new_signal = new_params.first_signal
local old_signal = old_params.first_signal
local new_network = new_signal and new_signal.name or nil
local old_network = old_signal and old_signal.name or nil
if (new_network ~= old_network) then
on_combinator_network_updated(map_data, comb, new_network)
if (new_params.operation == OPERATION_PRIMARY_IO_ACTIVE or new_params.operation == OPERATION_PRIMARY_IO_FAILED_REQUEST or new_params.operation == OPERATION_PRIMARY_IO) and (old_params.operation == OPERATION_PRIMARY_IO_ACTIVE or old_params.operation == OPERATION_PRIMARY_IO_FAILED_REQUEST or old_params.operation == OPERATION_PRIMARY_IO) then
set_combinator_operation(comb, old_params.operation)
new_params.operation = old_params.operation
else
--NOTE: This is rather dangerous, we may need to actually implement operation changing
on_combinator_broken(map_data, comb)
on_combinator_built(map_data, comb)
return
end
if new_params.second_constant ~= old_params.second_constant then
local stop = global.to_stop[comb.unit_number]
if stop then
local station = global.stations[stop.unit_number]
if station then
local bits = new_params.second_constant
local is_pr_state = floor(bits/2)%3
station.is_p = is_pr_state == 0 or is_pr_state == 1
station.is_r = is_pr_state == 0 or is_pr_state == 2
local allow_all_trains = bits%2 == 1
if station.allow_all_trains ~= allow_all_trains then
station.allow_all_trains = allow_all_trains
update_station_if_auto(map_data, station)
end
end
local new_signal = new_params.first_signal
local old_signal = old_params.first_signal
local new_network = new_signal and new_signal.name or nil
local old_network = old_signal and old_signal.name or nil
if new_network ~= old_network then
on_combinator_network_updated(map_data, comb, new_network)
end
if new_params.second_constant ~= old_params.second_constant then
local stop = global.to_stop[comb.unit_number]
if stop then
local station = global.stations[stop.unit_number]
if station then
local bits = new_params.second_constant
local is_pr_state = floor(bits/2)%3
station.is_p = is_pr_state == 0 or is_pr_state == 1
station.is_r = is_pr_state == 0 or is_pr_state == 2
local allow_all_trains = bits%2 == 1
if station.allow_all_trains ~= allow_all_trains then
station.allow_all_trains = allow_all_trains
update_station_if_auto(map_data, station)
end
end
end
map_data.to_comb_params[comb.unit_number] = new_params
end
map_data.to_comb_params[comb.unit_number] = new_params
end
---@param map_data MapData
@@ -442,7 +449,7 @@ local function on_stop_built(map_data, stop)
map_data.to_stop[entity.unit_number] = stop
local param = get_comb_params(entity)
local op = param.operation
if op == OPERATION_PRIMARY_IO or op == OPERATION_PRIMARY_IO_ACTIVE or op == OPERATION_PRIMARY_IO_REQUEST_FAILED then
if op == OPERATION_PRIMARY_IO then
comb1 = entity
elseif op == OPERATION_SECONDARY_IO then
comb2 = entity