mirror of
https://github.com/Xevion/project-cybersyn.git
synced 2025-12-08 04:08:07 -06:00
fixed copy-paste
This commit is contained in:
4
TODO
4
TODO
@@ -1,9 +1,7 @@
|
|||||||
close gui when the combinator is destroyed
|
close gui when the combinator is destroyed
|
||||||
do not play close sound when a different gui is opened
|
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
|
do hardcore testing
|
||||||
models & art
|
models & art
|
||||||
space elevator compat
|
space elevator compat
|
||||||
railloader compat
|
railloader compat
|
||||||
add missing items alert
|
|
||||||
lost train can be repurposed and rescheduled while alert is active
|
|
||||||
display when train is coming
|
|
||||||
|
|||||||
@@ -21,7 +21,7 @@ Date: 2022-11-13
|
|||||||
- Added warmup period on just built stations
|
- Added warmup period on just built stations
|
||||||
---------------------------------------------------------------------------------------------------
|
---------------------------------------------------------------------------------------------------
|
||||||
Version: 0.3.0
|
Version: 0.3.0
|
||||||
Date: 2022-11-13
|
Date: 2022-11-15
|
||||||
Features:
|
Features:
|
||||||
- Fixed copy-paste
|
- Fixed copy-paste
|
||||||
- Added alert sounds
|
- Added alert sounds
|
||||||
|
|||||||
@@ -33,7 +33,7 @@ function remove_manifest(map_data, station, manifest, sign)
|
|||||||
set_comb2(map_data, station)
|
set_comb2(map_data, station)
|
||||||
station.deliveries_total = station.deliveries_total - 1
|
station.deliveries_total = station.deliveries_total - 1
|
||||||
if station.deliveries_total == 0 and station.entity_comb1.valid then
|
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
|
||||||
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, p_station)
|
||||||
set_comb2(map_data, r_station)
|
set_comb2(map_data, r_station)
|
||||||
if p_station.entity_comb1.valid then
|
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
|
end
|
||||||
if r_station.entity_comb1.valid then
|
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
|
||||||
end
|
end
|
||||||
|
|
||||||
@@ -275,7 +275,7 @@ local function tick_poll_station(map_data, mod_settings)
|
|||||||
station = map_data.stations[station_id]
|
station = map_data.stations[station_id]
|
||||||
if station then
|
if station then
|
||||||
if station.display_update 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_update = station.display_failed_request
|
||||||
station.display_failed_request = nil
|
station.display_failed_request = nil
|
||||||
end
|
end
|
||||||
@@ -439,43 +439,45 @@ local function tick_dispatch(map_data, mod_settings)
|
|||||||
local item_type = tick_data.item_type
|
local item_type = tick_data.item_type
|
||||||
local r_threshold = r_station.p_count_or_r_threshold_per_item[item_name]
|
local r_threshold = r_station.p_count_or_r_threshold_per_item[item_name]
|
||||||
|
|
||||||
local best = 0
|
if r_threshold then
|
||||||
local best_depot = nil
|
local best = 0
|
||||||
local best_dist = INF
|
local best_depot = nil
|
||||||
local highest_prior = -INF
|
local best_dist = INF
|
||||||
local can_be_serviced = false
|
local highest_prior = -INF
|
||||||
for j, p_station_id in ipairs(p_stations) do
|
local can_be_serviced = false
|
||||||
local p_station = stations[p_station_id]
|
for j, p_station_id in ipairs(p_stations) do
|
||||||
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 p_station = stations[p_station_id]
|
||||||
local prior = p_station.priority
|
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 slot_threshold = item_type == "fluid" and r_threshold or ceil(r_threshold/get_stack_size(map_data, item_name))
|
local prior = p_station.priority
|
||||||
local depot, d = get_valid_train(map_data, r_station_id, p_station_id, item_type, slot_threshold)
|
local slot_threshold = item_type == "fluid" and r_threshold or ceil(r_threshold/get_stack_size(map_data, item_name))
|
||||||
if prior > highest_prior or (prior == highest_prior and d < best_dist) then
|
local depot, d = get_valid_train(map_data, r_station_id, p_station_id, item_type, slot_threshold)
|
||||||
if depot then
|
if prior > highest_prior or (prior == highest_prior and d < best_dist) then
|
||||||
best = j
|
if depot then
|
||||||
best_dist = d
|
best = j
|
||||||
best_depot = depot
|
best_dist = d
|
||||||
highest_prior = prior
|
best_depot = depot
|
||||||
can_be_serviced = true
|
highest_prior = prior
|
||||||
elseif d < INF then
|
can_be_serviced = true
|
||||||
best = j
|
elseif d < INF then
|
||||||
can_be_serviced = true
|
best = j
|
||||||
|
can_be_serviced = true
|
||||||
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
if
|
||||||
if
|
best_depot and (
|
||||||
best_depot and (
|
best_depot.entity_comb.status == defines.entity_status.working or
|
||||||
best_depot.entity_comb.status == defines.entity_status.working or
|
best_depot.entity_comb.status == defines.entity_status.low_power)
|
||||||
best_depot.entity_comb.status == defines.entity_status.low_power)
|
then
|
||||||
then
|
send_train_between(map_data, r_station_id, table_remove(p_stations--[[@as {}]], best), best_depot, item_name)
|
||||||
send_train_between(map_data, r_station_id, table_remove(p_stations--[[@as {}]], best), best_depot, item_name)
|
else
|
||||||
else
|
if can_be_serviced then
|
||||||
if can_be_serviced then
|
send_missing_train_alert_for_stops(r_station.entity_stop, stations[p_stations--[[@as {}]][best]].entity_stop)
|
||||||
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
|
end
|
||||||
r_station.display_failed_request = true
|
|
||||||
r_station.display_update = true
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
return false
|
return false
|
||||||
|
|||||||
@@ -15,7 +15,7 @@ ALERT_SOUND = "utility/console_message"
|
|||||||
|
|
||||||
OPERATION_DEFAULT = "*"
|
OPERATION_DEFAULT = "*"
|
||||||
OPERATION_PRIMARY_IO = "/"
|
OPERATION_PRIMARY_IO = "/"
|
||||||
OPERATION_PRIMARY_IO_REQUEST_FAILED = "^"
|
OPERATION_PRIMARY_IO_FAILED_REQUEST = "^"
|
||||||
OPERATION_PRIMARY_IO_ACTIVE = "<<"
|
OPERATION_PRIMARY_IO_ACTIVE = "<<"
|
||||||
OPERATION_SECONDARY_IO = "%"
|
OPERATION_SECONDARY_IO = "%"
|
||||||
OPERATION_DEPOT = "+"
|
OPERATION_DEPOT = "+"
|
||||||
|
|||||||
@@ -154,13 +154,14 @@ function update_combinator_display(comb, is_failed)
|
|||||||
local param = control.parameters
|
local param = control.parameters
|
||||||
if is_failed then
|
if is_failed then
|
||||||
if param.operation == OPERATION_PRIMARY_IO 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
|
control.parameters = param
|
||||||
end
|
end
|
||||||
elseif param.operation == OPERATION_PRIMARY_IO_REQUEST_FAILED then
|
elseif param.operation == OPERATION_PRIMARY_IO_FAILED_REQUEST then
|
||||||
param.operation = OPERATION_PRIMARY_IO
|
param.operation = OPERATION_PRIMARY_IO
|
||||||
control.parameters = param
|
control.parameters = param
|
||||||
end
|
end
|
||||||
|
return param
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -44,7 +44,7 @@ function gui_opened(comb, player)
|
|||||||
switch_state = "right"
|
switch_state = "right"
|
||||||
end
|
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
|
selected_index = 1
|
||||||
elseif op == OPERATION_SECONDARY_IO then
|
elseif op == OPERATION_SECONDARY_IO then
|
||||||
selected_index = 2
|
selected_index = 2
|
||||||
|
|||||||
@@ -248,21 +248,22 @@ local function on_combinator_built(map_data, comb)
|
|||||||
local param = control.parameters
|
local param = control.parameters
|
||||||
local op = param.operation
|
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
|
if op == OPERATION_DEFAULT then
|
||||||
op = OPERATION_PRIMARY_IO
|
op = OPERATION_PRIMARY_IO
|
||||||
param.operation = op
|
param.operation = op
|
||||||
param.first_signal = NETWORK_SIGNAL_DEFAULT
|
param.first_signal = NETWORK_SIGNAL_DEFAULT
|
||||||
control.parameters = param
|
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
|
op = OPERATION_PRIMARY_IO
|
||||||
param.operation = op
|
param.operation = op
|
||||||
control.parameters = param
|
control.parameters = param
|
||||||
end
|
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 op == OPERATION_WAGON_MANIFEST then
|
||||||
if rail then
|
if rail then
|
||||||
force_update_station_from_rail(map_data, rail, nil)
|
force_update_station_from_rail(map_data, rail, nil)
|
||||||
@@ -392,35 +393,41 @@ end
|
|||||||
function on_combinator_updated(map_data, comb, new_params)
|
function on_combinator_updated(map_data, comb, new_params)
|
||||||
local old_params = map_data.to_comb_params[comb.unit_number]
|
local old_params = map_data.to_comb_params[comb.unit_number]
|
||||||
if new_params.operation ~= old_params.operation then
|
if new_params.operation ~= old_params.operation then
|
||||||
on_combinator_broken(map_data, comb)
|
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
|
||||||
on_combinator_built(map_data, comb)
|
set_combinator_operation(comb, old_params.operation)
|
||||||
else
|
new_params.operation = old_params.operation
|
||||||
local new_signal = new_params.first_signal
|
else
|
||||||
local old_signal = old_params.first_signal
|
--NOTE: This is rather dangerous, we may need to actually implement operation changing
|
||||||
local new_network = new_signal and new_signal.name or nil
|
on_combinator_broken(map_data, comb)
|
||||||
local old_network = old_signal and old_signal.name or nil
|
on_combinator_built(map_data, comb)
|
||||||
if (new_network ~= old_network) then
|
return
|
||||||
on_combinator_network_updated(map_data, comb, new_network)
|
|
||||||
end
|
end
|
||||||
if new_params.second_constant ~= old_params.second_constant then
|
end
|
||||||
local stop = global.to_stop[comb.unit_number]
|
local new_signal = new_params.first_signal
|
||||||
if stop then
|
local old_signal = old_params.first_signal
|
||||||
local station = global.stations[stop.unit_number]
|
local new_network = new_signal and new_signal.name or nil
|
||||||
if station then
|
local old_network = old_signal and old_signal.name or nil
|
||||||
local bits = new_params.second_constant
|
if new_network ~= old_network then
|
||||||
local is_pr_state = floor(bits/2)%3
|
on_combinator_network_updated(map_data, comb, new_network)
|
||||||
station.is_p = is_pr_state == 0 or is_pr_state == 1
|
end
|
||||||
station.is_r = is_pr_state == 0 or is_pr_state == 2
|
if new_params.second_constant ~= old_params.second_constant then
|
||||||
local allow_all_trains = bits%2 == 1
|
local stop = global.to_stop[comb.unit_number]
|
||||||
if station.allow_all_trains ~= allow_all_trains then
|
if stop then
|
||||||
station.allow_all_trains = allow_all_trains
|
local station = global.stations[stop.unit_number]
|
||||||
update_station_if_auto(map_data, station)
|
if station then
|
||||||
end
|
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
|
end
|
||||||
end
|
end
|
||||||
map_data.to_comb_params[comb.unit_number] = new_params
|
|
||||||
end
|
end
|
||||||
|
map_data.to_comb_params[comb.unit_number] = new_params
|
||||||
end
|
end
|
||||||
|
|
||||||
---@param map_data MapData
|
---@param map_data MapData
|
||||||
@@ -442,7 +449,7 @@ local function on_stop_built(map_data, stop)
|
|||||||
map_data.to_stop[entity.unit_number] = stop
|
map_data.to_stop[entity.unit_number] = stop
|
||||||
local param = get_comb_params(entity)
|
local param = get_comb_params(entity)
|
||||||
local op = param.operation
|
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
|
comb1 = entity
|
||||||
elseif op == OPERATION_SECONDARY_IO then
|
elseif op == OPERATION_SECONDARY_IO then
|
||||||
comb2 = entity
|
comb2 = entity
|
||||||
|
|||||||
Reference in New Issue
Block a user