mirror of
https://github.com/Xevion/project-cybersyn.git
synced 2025-12-10 10:08:18 -06:00
added missing items display
This commit is contained in:
@@ -19,6 +19,21 @@ local function get_stop_dist(stop0, stop1)
|
||||
end
|
||||
|
||||
|
||||
---@param map_data MapData
|
||||
---@param station Station
|
||||
---@param manifest Manifest
|
||||
function remove_manifest(map_data, station, manifest, sign)
|
||||
local deliveries = station.deliveries
|
||||
for i, item in ipairs(manifest) do
|
||||
deliveries[item.name] = deliveries[item.name] + sign*item.count
|
||||
if deliveries[item.name] == 0 then
|
||||
deliveries[item.name] = nil
|
||||
end
|
||||
end
|
||||
set_comb2(map_data, station)
|
||||
station.deliveries_total = station.deliveries_total - 1
|
||||
end
|
||||
|
||||
---@param map_data MapData
|
||||
---@param r_station_id uint
|
||||
---@param p_station_id uint
|
||||
@@ -206,7 +221,6 @@ local function send_train_between(map_data, r_station_id, p_station_id, depot, p
|
||||
end
|
||||
|
||||
|
||||
|
||||
---@param map_data MapData
|
||||
local function tick_poll_depot(map_data)
|
||||
local depot_id
|
||||
@@ -272,6 +286,11 @@ local function tick_poll_station(map_data, mod_settings)
|
||||
map_data.tick_state = STATE_DISPATCH
|
||||
return true
|
||||
end
|
||||
if station.display_update then
|
||||
update_combinator_display(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
|
||||
station.r_threshold = mod_settings.r_threshold
|
||||
@@ -380,7 +399,7 @@ local function tick_dispatch(map_data, mod_settings)
|
||||
|
||||
r_stations = all_r_stations[item_network_name]
|
||||
p_stations = all_p_stations[item_network_name]
|
||||
if p_stations and #r_stations > 0 and #p_stations > 0 then
|
||||
if p_stations then
|
||||
tick_data.r_stations = r_stations
|
||||
tick_data.p_stations = p_stations
|
||||
tick_data.item_name = signal.name
|
||||
@@ -395,6 +414,12 @@ local function tick_dispatch(map_data, mod_settings)
|
||||
end
|
||||
end)
|
||||
break
|
||||
else
|
||||
for i, id in ipairs(r_stations) do
|
||||
local station = stations[id]
|
||||
station.display_failed_request = true
|
||||
station.display_update = true
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
@@ -435,9 +460,8 @@ local function tick_dispatch(map_data, mod_settings)
|
||||
if could_have_been_serviced then
|
||||
send_missing_train_alert_for_stops(r_station.entity_stop, stations[p_stations[best]].entity_stop)
|
||||
end
|
||||
if r_station.entity_comb1.valid then
|
||||
set_combinator_operation(r_station.entity_comb1, OPERATION_PRIMARY_IO_NOT_FOUND)
|
||||
end
|
||||
r_station.display_failed_request = true
|
||||
r_station.display_update = true
|
||||
end
|
||||
return false
|
||||
end
|
||||
|
||||
@@ -14,8 +14,8 @@ COMBINATOR_CLOSE_SOUND = "entity-close/cybersyn-combinator"
|
||||
|
||||
OPERATION_DEFAULT = "*"
|
||||
OPERATION_PRIMARY_IO = "/"
|
||||
OPERATION_PRIMARY_IO_ACTIVE = "^"
|
||||
OPERATION_PRIMARY_IO_NOT_FOUND = "<<"
|
||||
OPERATION_PRIMARY_IO_REQUEST_FAILED = "^"
|
||||
OPERATION_PRIMARY_IO_ACTIVE = "<<"
|
||||
OPERATION_SECONDARY_IO = "%"
|
||||
OPERATION_DEPOT = "+"
|
||||
OPERATION_WAGON_MANIFEST = "-"
|
||||
|
||||
@@ -69,22 +69,6 @@ function create_manifest_schedule(depot_name, p_stop, r_stop, manifest)
|
||||
}}
|
||||
end
|
||||
|
||||
---@param map_data MapData
|
||||
---@param station Station
|
||||
---@param manifest Manifest
|
||||
function remove_manifest(map_data, station, manifest, sign)
|
||||
local deliveries = station.deliveries
|
||||
for i, item in ipairs(manifest) do
|
||||
deliveries[item.name] = deliveries[item.name] + sign*item.count
|
||||
if deliveries[item.name] == 0 then
|
||||
deliveries[item.name] = nil
|
||||
end
|
||||
end
|
||||
set_comb2(map_data, station)
|
||||
station.deliveries_total = station.deliveries_total - 1
|
||||
end
|
||||
|
||||
|
||||
|
||||
---@param param ArithmeticCombinatorParameters
|
||||
function get_comb_secondary_state(param)
|
||||
@@ -142,6 +126,21 @@ function set_combinator_operation(comb, op)
|
||||
control.operation = op
|
||||
a.parameters = control
|
||||
end
|
||||
---@param comb LuaEntity
|
||||
---@param is_failed boolean
|
||||
function update_combinator_display(comb, is_failed)
|
||||
local a = comb.get_or_create_control_behavior()--[[@as LuaArithmeticCombinatorControlBehavior]]
|
||||
local control = a.parameters
|
||||
if is_failed then
|
||||
if control.operation == OPERATION_PRIMARY_IO then
|
||||
control.operation = OPERATION_PRIMARY_IO_REQUEST_FAILED
|
||||
a.parameters = control
|
||||
end
|
||||
elseif control.operation == OPERATION_PRIMARY_IO_REQUEST_FAILED then
|
||||
control.operation = OPERATION_PRIMARY_IO
|
||||
a.parameters = control
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
---@param station Station
|
||||
@@ -190,12 +189,12 @@ local send_missing_train_alert_for_stop_icon = {name = MISSING_TRAIN_NAME, type
|
||||
function send_missing_train_alert_for_stops(r_stop, p_stop)
|
||||
for _, player in pairs(r_stop.force.players) do
|
||||
player.add_custom_alert(
|
||||
r_stop,
|
||||
send_missing_train_alert_for_stop_icon,
|
||||
{"cybersyn-messages.missing-trains", r_stop.backer_name, p_stop.backer_name},
|
||||
true
|
||||
)
|
||||
end
|
||||
r_stop,
|
||||
send_missing_train_alert_for_stop_icon,
|
||||
{"cybersyn-messages.missing-trains", r_stop.backer_name, p_stop.backer_name},
|
||||
true
|
||||
)
|
||||
end
|
||||
end
|
||||
|
||||
local send_lost_train_alert_icon = {name = LOST_TRAIN_NAME, type = "fluid"}
|
||||
@@ -205,15 +204,14 @@ function send_lost_train_alert(train)
|
||||
if loco then
|
||||
for _, player in pairs(loco.force.players) do
|
||||
player.add_custom_alert(
|
||||
loco,
|
||||
send_lost_train_alert_icon,
|
||||
{"cybersyn-messages.lost-train"},
|
||||
true
|
||||
)
|
||||
end
|
||||
loco,
|
||||
send_lost_train_alert_icon,
|
||||
{"cybersyn-messages.lost-train"},
|
||||
true
|
||||
)
|
||||
end
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
local send_nonempty_train_in_depot_alert_icon = {name = NONEMPTY_TRAIN_NAME, type = "fluid"}
|
||||
---@param train LuaTrain
|
||||
@@ -222,11 +220,11 @@ function send_nonempty_train_in_depot_alert(train)
|
||||
if loco then
|
||||
for _, player in pairs(loco.force.players) do
|
||||
player.add_custom_alert(
|
||||
loco,
|
||||
send_nonempty_train_in_depot_alert_icon,
|
||||
{"cybersyn-messages.nonempty-train"},
|
||||
true
|
||||
)
|
||||
end
|
||||
loco,
|
||||
send_nonempty_train_in_depot_alert_icon,
|
||||
{"cybersyn-messages.nonempty-train"},
|
||||
true
|
||||
)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
@@ -18,6 +18,7 @@
|
||||
---@class Station
|
||||
---@field public is_p boolean
|
||||
---@field public is_r boolean
|
||||
---@field public allows_all_trains boolean
|
||||
---@field public deliveries_total int
|
||||
---@field public last_delivery_tick int
|
||||
---@field public priority int --transient
|
||||
@@ -30,11 +31,12 @@
|
||||
---@field public deliveries {[string]: int}
|
||||
---@field public network_name string?
|
||||
---@field public network_flag int --transient
|
||||
---@field public allows_all_trains boolean
|
||||
---@field public accepted_layouts TrainClass
|
||||
---@field public layout_pattern string?
|
||||
---@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?
|
||||
|
||||
---@class Depot
|
||||
---@field public priority int --transient
|
||||
@@ -58,7 +60,7 @@
|
||||
---@field public has_filtered_wagon boolean
|
||||
|
||||
---@alias Manifest {}[]
|
||||
---@alias TrainClass {[uint]: boolean}
|
||||
---@alias TrainClass {[uint]: true}
|
||||
---@alias cybersyn.global MapData
|
||||
|
||||
---@class Economy
|
||||
|
||||
@@ -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_NOT_FOUND then
|
||||
if op == OPERATION_PRIMARY_IO or op == OPERATION_PRIMARY_IO_ACTIVE or op == OPERATION_PRIMARY_IO_REQUEST_FAILED then
|
||||
selected_index = 1
|
||||
elseif op == OPERATION_SECONDARY_IO then
|
||||
selected_index = 2
|
||||
|
||||
@@ -4,6 +4,7 @@ local flib_event = require("__flib__.event")
|
||||
|
||||
---@param map_data MapData
|
||||
---@param station Station
|
||||
---@param manifest Manifest
|
||||
---@param sign int?
|
||||
local function set_comb1(map_data, station, manifest, sign)
|
||||
local comb = station.entity_comb1
|
||||
@@ -254,7 +255,7 @@ local function on_combinator_built(map_data, comb)
|
||||
param.operation = op
|
||||
param.first_signal = NETWORK_SIGNAL_DEFAULT
|
||||
control.parameters = param
|
||||
elseif op == OPERATION_PRIMARY_IO_ACTIVE or op == OPERATION_PRIMARY_IO_NOT_FOUND then
|
||||
elseif op == OPERATION_PRIMARY_IO_ACTIVE or op == OPERATION_PRIMARY_IO_REQUEST_FAILED then
|
||||
op = OPERATION_PRIMARY_IO
|
||||
param.operation = op
|
||||
control.parameters = param
|
||||
@@ -403,7 +404,7 @@ local function on_stop_built(map_data, stop)
|
||||
map_data.to_stop[entity.unit_number] = stop
|
||||
local control = entity.get_or_create_control_behavior().parameters--[[@as ArithmeticCombinatorParameters]]
|
||||
local op = control.operation
|
||||
if op == OPERATION_PRIMARY_IO or op == OPERATION_PRIMARY_IO_ACTIVE or op == OPERATION_PRIMARY_IO_NOT_FOUND then
|
||||
if op == OPERATION_PRIMARY_IO or op == OPERATION_PRIMARY_IO_ACTIVE or op == OPERATION_PRIMARY_IO_REQUEST_FAILED then
|
||||
comb1 = entity
|
||||
elseif op == OPERATION_SECONDARY_IO then
|
||||
comb2 = entity
|
||||
|
||||
@@ -2,15 +2,15 @@ local flib_migration = require("__flib__.migration")
|
||||
|
||||
|
||||
local migrations_table = {
|
||||
["0.0.1"] = function()
|
||||
["0.2.0"] = function()
|
||||
---@type MapData
|
||||
local map_data = global
|
||||
for k, station in pairs(map_data.stations) do
|
||||
station.p_count_or_r_threshold_per_item = {}
|
||||
station.p_threshold = nil
|
||||
station.is_all = nil
|
||||
station.is_auto = nil
|
||||
set_station_from_comb_state(station)
|
||||
set_combinator_operation(station.entity_comb1, OPERATION_PRIMARY_IO)
|
||||
end
|
||||
map_data.tick_state = STATE_INIT
|
||||
end,
|
||||
|
||||
Reference in New Issue
Block a user