mirror of
https://github.com/Xevion/project-cybersyn.git
synced 2025-12-10 08:08:14 -06:00
added active delivery icon
This commit is contained in:
@@ -84,13 +84,19 @@ end
|
|||||||
---@param comb LuaEntity
|
---@param comb LuaEntity
|
||||||
---@param signals ConstantCombinatorParameters[]?
|
---@param signals ConstantCombinatorParameters[]?
|
||||||
function set_combinator_output(map_data, comb, signals)
|
function set_combinator_output(map_data, comb, signals)
|
||||||
if comb.valid then
|
local out = map_data.to_output[comb.unit_number]
|
||||||
local out = map_data.to_output[comb.unit_number]
|
if out.valid then
|
||||||
if out.valid then
|
out.get_or_create_control_behavior().parameters = signals
|
||||||
out.get_or_create_control_behavior().parameters = signals
|
|
||||||
end
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
---@param comb LuaEntity
|
||||||
|
---@param op string
|
||||||
|
function set_combinator_operation(comb, op)
|
||||||
|
local a = comb.get_or_create_control_behavior()--[[@as LuaArithmeticCombinatorControlBehavior]]
|
||||||
|
local control = a.parameters
|
||||||
|
control.operation = op
|
||||||
|
a.parameters = control
|
||||||
|
end
|
||||||
|
|
||||||
---@param map_data MapData
|
---@param map_data MapData
|
||||||
---@param station Station
|
---@param station Station
|
||||||
@@ -333,6 +339,12 @@ local function send_train_between(map_data, r_station_id, p_station_id, depot, p
|
|||||||
train.entity.schedule = create_manifest_schedule(train.depot_name, p_station.entity_stop, r_station.entity_stop, manifest)
|
train.entity.schedule = create_manifest_schedule(train.depot_name, p_station.entity_stop, r_station.entity_stop, manifest)
|
||||||
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
|
||||||
|
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)
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -32,13 +32,14 @@ function gui_opened(comb, player)
|
|||||||
local rootgui = player.gui.screen
|
local rootgui = player.gui.screen
|
||||||
local selected_index = 0
|
local selected_index = 0
|
||||||
local control = comb.get_or_create_control_behavior().parameters--[[@as ArithmeticCombinatorParameters]]
|
local control = comb.get_or_create_control_behavior().parameters--[[@as ArithmeticCombinatorParameters]]
|
||||||
if control.operation == OPERATION_PRIMARY_IO then
|
local op = control.operation
|
||||||
|
if op == OPERATION_PRIMARY_IO or op == OPERATION_PRIMARY_IO_ACTIVE then
|
||||||
selected_index = 1
|
selected_index = 1
|
||||||
elseif control.operation == OPERATION_SECONDARY_IO then
|
elseif op == OPERATION_SECONDARY_IO then
|
||||||
selected_index = 2
|
selected_index = 2
|
||||||
elseif control.operation == OPERATION_DEPOT then
|
elseif op == OPERATION_DEPOT then
|
||||||
selected_index = 3
|
selected_index = 3
|
||||||
elseif control.operation == OPERATION_WAGON_MANIFEST then
|
elseif op == OPERATION_WAGON_MANIFEST then
|
||||||
selected_index = 4
|
selected_index = 4
|
||||||
end
|
end
|
||||||
|
|
||||||
@@ -142,28 +143,26 @@ function register_gui_actions()
|
|||||||
if not comb or not comb.valid then return end
|
if not comb or not comb.valid then return end
|
||||||
|
|
||||||
local parent = element.parent.bottom
|
local parent = element.parent.bottom
|
||||||
local a = comb.get_or_create_control_behavior() --[[@as LuaArithmeticCombinatorControlBehavior]]
|
|
||||||
local control = a.parameters
|
|
||||||
if element.selected_index == 1 then
|
if element.selected_index == 1 then
|
||||||
control.operation = OPERATION_PRIMARY_IO
|
set_combinator_operation(comb, OPERATION_PRIMARY_IO)
|
||||||
element.parent["network_label"].visible = true
|
element.parent["network_label"].visible = true
|
||||||
parent["network"].visible = true
|
parent["network"].visible = true
|
||||||
parent["radiobutton"].visible = true
|
parent["radiobutton"].visible = true
|
||||||
parent["radiolabel"].visible = true
|
parent["radiolabel"].visible = true
|
||||||
elseif element.selected_index == 2 then
|
elseif element.selected_index == 2 then
|
||||||
control.operation = OPERATION_SECONDARY_IO
|
set_combinator_operation(comb, OPERATION_SECONDARY_IO)
|
||||||
element.parent["network_label"].visible = false
|
element.parent["network_label"].visible = false
|
||||||
parent["network"].visible = false
|
parent["network"].visible = false
|
||||||
parent["radiobutton"].visible = false
|
parent["radiobutton"].visible = false
|
||||||
parent["radiolabel"].visible = false
|
parent["radiolabel"].visible = false
|
||||||
elseif element.selected_index == 3 then
|
elseif element.selected_index == 3 then
|
||||||
control.operation = OPERATION_DEPOT
|
set_combinator_operation(comb, OPERATION_DEPOT)
|
||||||
element.parent["network_label"].visible = true
|
element.parent["network_label"].visible = true
|
||||||
parent["network"].visible = true
|
parent["network"].visible = true
|
||||||
parent["radiobutton"].visible = false
|
parent["radiobutton"].visible = false
|
||||||
parent["radiolabel"].visible = false
|
parent["radiolabel"].visible = false
|
||||||
elseif element.selected_index == 4 then
|
elseif element.selected_index == 4 then
|
||||||
control.operation = OPERATION_WAGON_MANIFEST
|
set_combinator_operation(comb, OPERATION_WAGON_MANIFEST)
|
||||||
element.parent["network_label"].visible = false
|
element.parent["network_label"].visible = false
|
||||||
parent["network"].visible = false
|
parent["network"].visible = false
|
||||||
parent["radiobutton"].visible = false
|
parent["radiobutton"].visible = false
|
||||||
@@ -172,7 +171,6 @@ function register_gui_actions()
|
|||||||
return
|
return
|
||||||
end
|
end
|
||||||
|
|
||||||
a.parameters = control
|
|
||||||
on_combinator_updated(global, comb)
|
on_combinator_updated(global, comb)
|
||||||
elseif msg[1] == "choose-elem-button" then
|
elseif msg[1] == "choose-elem-button" then
|
||||||
local element = event.element
|
local element = event.element
|
||||||
|
|||||||
@@ -1,6 +1,28 @@
|
|||||||
--By Mami
|
--By Mami
|
||||||
local flib_event = require("__flib__.event")
|
local flib_event = require("__flib__.event")
|
||||||
|
|
||||||
|
|
||||||
|
---@param map_data MapData
|
||||||
|
---@param station Station
|
||||||
|
---@param sign int?
|
||||||
|
local function set_comb1(map_data, station, manifest, sign)
|
||||||
|
local comb = station.entity_comb1
|
||||||
|
if comb.valid then
|
||||||
|
if manifest then
|
||||||
|
local signals = {}
|
||||||
|
for i, item in ipairs(manifest) do
|
||||||
|
signals[i] = {index = i, signal = {type = item.type, name = item.name}, count = sign*item.count}
|
||||||
|
end
|
||||||
|
set_combinator_output(map_data, comb, signals)
|
||||||
|
else
|
||||||
|
if station.deliveries_total == 0 then
|
||||||
|
set_combinator_operation(comb, OPERATION_PRIMARY_IO)
|
||||||
|
end
|
||||||
|
set_combinator_output(map_data, comb, nil)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
---@param map_data MapData
|
---@param map_data MapData
|
||||||
---@param train Train
|
---@param train Train
|
||||||
local function on_failed_delivery(map_data, train)
|
local function on_failed_delivery(map_data, train)
|
||||||
@@ -10,7 +32,7 @@ local function on_failed_delivery(map_data, train)
|
|||||||
local station = map_data.stations[train.p_station_id]
|
local station = map_data.stations[train.p_station_id]
|
||||||
remove_manifest(map_data, station, train.manifest, 1)
|
remove_manifest(map_data, station, train.manifest, 1)
|
||||||
if train.status == STATUS_P then
|
if train.status == STATUS_P then
|
||||||
set_combinator_output(map_data, station.entity_comb1, nil)
|
set_comb1(map_data, station, nil)
|
||||||
unset_wagon_combs(map_data, station)
|
unset_wagon_combs(map_data, station)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
@@ -19,7 +41,7 @@ local function on_failed_delivery(map_data, train)
|
|||||||
local station = map_data.stations[train.r_station_id]
|
local station = map_data.stations[train.r_station_id]
|
||||||
remove_manifest(map_data, station, train.manifest, -1)
|
remove_manifest(map_data, station, train.manifest, -1)
|
||||||
if train.status == STATUS_R then
|
if train.status == STATUS_R then
|
||||||
set_combinator_output(map_data, station.entity_comb1, nil)
|
set_comb1(map_data, station, nil)
|
||||||
unset_wagon_combs(map_data, station)
|
unset_wagon_combs(map_data, station)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
@@ -224,16 +246,22 @@ local function on_combinator_built(map_data, comb)
|
|||||||
|
|
||||||
local a = comb.get_or_create_control_behavior()--[[@as LuaArithmeticCombinatorControlBehavior]]
|
local a = comb.get_or_create_control_behavior()--[[@as LuaArithmeticCombinatorControlBehavior]]
|
||||||
local control = a.parameters
|
local control = a.parameters
|
||||||
if control.operation == OPERATION_DEFAULT then
|
local op = control.operation
|
||||||
control.operation = OPERATION_PRIMARY_IO
|
if op == OPERATION_DEFAULT then
|
||||||
|
op = OPERATION_PRIMARY_IO
|
||||||
|
control.operation = op
|
||||||
control.first_signal = NETWORK_SIGNAL_DEFAULT
|
control.first_signal = NETWORK_SIGNAL_DEFAULT
|
||||||
a.parameters = control
|
a.parameters = control
|
||||||
|
elseif op == OPERATION_PRIMARY_IO_ACTIVE then
|
||||||
|
op = OPERATION_PRIMARY_IO
|
||||||
|
control.operation = op
|
||||||
|
a.parameters = control
|
||||||
end
|
end
|
||||||
if control.operation == 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)
|
||||||
end
|
end
|
||||||
elseif control.operation == OPERATION_DEPOT then
|
elseif op == OPERATION_DEPOT then
|
||||||
if stop then
|
if stop then
|
||||||
local station = map_data.stations[stop.unit_number]
|
local station = map_data.stations[stop.unit_number]
|
||||||
---@type Depot
|
---@type Depot
|
||||||
@@ -244,7 +272,7 @@ local function on_combinator_built(map_data, comb)
|
|||||||
on_depot_built(map_data, stop, comb, control)
|
on_depot_built(map_data, stop, comb, control)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
elseif control.operation == OPERATION_SECONDARY_IO then
|
elseif op == OPERATION_SECONDARY_IO then
|
||||||
if stop then
|
if stop then
|
||||||
local station = map_data.stations[stop.unit_number]
|
local station = map_data.stations[stop.unit_number]
|
||||||
if station and not station.entity_comb2 then
|
if station and not station.entity_comb2 then
|
||||||
@@ -375,11 +403,12 @@ local function on_stop_built(map_data, stop)
|
|||||||
if entity.valid and entity.name == COMBINATOR_NAME and map_data.to_stop[entity.unit_number] == nil then
|
if entity.valid and entity.name == COMBINATOR_NAME and map_data.to_stop[entity.unit_number] == nil then
|
||||||
map_data.to_stop[entity.unit_number] = stop
|
map_data.to_stop[entity.unit_number] = stop
|
||||||
local control = entity.get_or_create_control_behavior().parameters--[[@as ArithmeticCombinatorParameters]]
|
local control = entity.get_or_create_control_behavior().parameters--[[@as ArithmeticCombinatorParameters]]
|
||||||
if control.operation == OPERATION_PRIMARY_IO then
|
local op = control.operation
|
||||||
|
if op == OPERATION_PRIMARY_IO then
|
||||||
comb1 = entity
|
comb1 = entity
|
||||||
elseif control.operation == OPERATION_SECONDARY_IO then
|
elseif op == OPERATION_SECONDARY_IO then
|
||||||
comb2 = entity
|
comb2 = entity
|
||||||
elseif control.operation == OPERATION_DEPOT then
|
elseif op == OPERATION_DEPOT then
|
||||||
depot_comb = entity
|
depot_comb = entity
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
@@ -525,25 +554,15 @@ local function on_train_arrives_buffer(map_data, stop, train)
|
|||||||
if train.status == STATUS_D_TO_P then
|
if train.status == STATUS_D_TO_P then
|
||||||
if train.p_station_id == station_id then
|
if train.p_station_id == station_id then
|
||||||
train.status = STATUS_P
|
train.status = STATUS_P
|
||||||
--change circuit outputs
|
|
||||||
local station = map_data.stations[station_id]
|
local station = map_data.stations[station_id]
|
||||||
local signals = {}
|
set_comb1(map_data, station, train.manifest, 1)
|
||||||
for i, item in ipairs(train.manifest) do
|
|
||||||
signals[i] = {index = i, signal = {type = item.type, name = item.name}, count = item.count}
|
|
||||||
end
|
|
||||||
set_combinator_output(map_data, station.entity_comb1, signals)
|
|
||||||
set_p_wagon_combs(map_data, station, train)
|
set_p_wagon_combs(map_data, station, train)
|
||||||
end
|
end
|
||||||
elseif train.status == STATUS_P_TO_R then
|
elseif train.status == STATUS_P_TO_R then
|
||||||
if train.r_station_id == station_id then
|
if train.r_station_id == station_id then
|
||||||
train.status = STATUS_R
|
train.status = STATUS_R
|
||||||
--change circuit outputs
|
|
||||||
local station = map_data.stations[station_id]
|
local station = map_data.stations[station_id]
|
||||||
local signals = {}
|
set_comb1(map_data, station, train.manifest, -1)
|
||||||
for i, item in ipairs(train.manifest) do
|
|
||||||
signals[i] = {index = i, signal = {type = item.type, name = item.name}, count = -item.count}
|
|
||||||
end
|
|
||||||
set_combinator_output(map_data, station.entity_comb1, signals)
|
|
||||||
set_r_wagon_combs(map_data, station, train)
|
set_r_wagon_combs(map_data, station, train)
|
||||||
end
|
end
|
||||||
else
|
else
|
||||||
@@ -562,6 +581,11 @@ end
|
|||||||
local function on_train_leaves_station(map_data, train)
|
local function on_train_leaves_station(map_data, train)
|
||||||
if train.manifest then
|
if train.manifest then
|
||||||
if train.status == STATUS_P then
|
if train.status == STATUS_P then
|
||||||
|
train.status = STATUS_P_TO_R
|
||||||
|
local station = map_data.stations[train.p_station_id]
|
||||||
|
remove_manifest(map_data, station, train.manifest, 1)
|
||||||
|
set_comb1(map_data, station, nil)
|
||||||
|
unset_wagon_combs(map_data, station)
|
||||||
if train.has_filtered_wagon then
|
if train.has_filtered_wagon then
|
||||||
train.has_filtered_wagon = false
|
train.has_filtered_wagon = false
|
||||||
for carriage_i, carriage in ipairs(train.entity.carriages) do
|
for carriage_i, carriage in ipairs(train.entity.carriages) do
|
||||||
@@ -576,16 +600,11 @@ local function on_train_leaves_station(map_data, train)
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
train.status = STATUS_P_TO_R
|
|
||||||
local station = map_data.stations[train.p_station_id]
|
|
||||||
remove_manifest(map_data, station, train.manifest, 1)
|
|
||||||
set_combinator_output(map_data, station.entity_comb1, nil)
|
|
||||||
unset_wagon_combs(map_data, station)
|
|
||||||
elseif train.status == STATUS_R then
|
elseif train.status == STATUS_R then
|
||||||
train.status = STATUS_R_TO_D
|
train.status = STATUS_R_TO_D
|
||||||
local station = map_data.stations[train.r_station_id]
|
local station = map_data.stations[train.r_station_id]
|
||||||
remove_manifest(map_data, station, train.manifest, -1)
|
remove_manifest(map_data, station, train.manifest, -1)
|
||||||
set_combinator_output(map_data, station.entity_comb1, nil)
|
set_comb1(map_data, station, nil)
|
||||||
unset_wagon_combs(map_data, station)
|
unset_wagon_combs(map_data, station)
|
||||||
end
|
end
|
||||||
elseif train.depot then
|
elseif train.depot then
|
||||||
|
|||||||
Reference in New Issue
Block a user