mirror of
https://github.com/Xevion/project-cybersyn.git
synced 2025-12-08 18:08:21 -06:00
created alpha
This commit is contained in:
1
.vscode/launch.json
vendored
1
.vscode/launch.json
vendored
@@ -29,7 +29,6 @@
|
|||||||
"debugadapter": true,
|
"debugadapter": true,
|
||||||
"flib": true,
|
"flib": true,
|
||||||
"cybersyn": true,
|
"cybersyn": true,
|
||||||
"creative-mod": true,
|
|
||||||
},
|
},
|
||||||
"disableExtraMods": true
|
"disableExtraMods": true
|
||||||
},
|
},
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
close gui when the combinator is destroyed
|
close gui when the combinator is destroyed
|
||||||
play close sound when gui is closed
|
do not play close sound when a different gui is opened
|
||||||
improve localization
|
improve localization
|
||||||
support space elevator
|
support space elevator
|
||||||
do hardcore testing
|
do hardcore testing
|
||||||
|
|||||||
@@ -1,34 +1,34 @@
|
|||||||
[mod-setting-name]
|
[mod-setting-name]
|
||||||
cybersyn-ticks-per-second=Dispatcher ticks per second
|
cybersyn-ticks-per-second=Dispatcher updates per second
|
||||||
cybersyn-request-threshold=Default requester threshold
|
cybersyn-request-threshold=Default requester threshold
|
||||||
cybersyn-provide-threshold=Default provider threshold
|
cybersyn-provide-threshold=Default provider threshold
|
||||||
cybersyn-network-flag=Default network flags
|
cybersyn-network-flag=Default network flags
|
||||||
|
|
||||||
[mod-setting-description]
|
[mod-setting-description]
|
||||||
cybersyn-ticks-per-second=How many times per second to check all stations for possible deliveries. This value will be rounded up to a divisor of 60.
|
cybersyn-ticks-per-second=How many times per second the dispather should check for new deliveries. Deliveries are made one at a time per update. This value will be rounded up to a divisor of 60.
|
||||||
cybersyn-request-threshold=When a requester threshold signal is not recieved by a station it will default to this value.
|
cybersyn-request-threshold=The default request threshold when a request threshold signal is not given to a station. Huge values will prevent stations from taking requests from the network unless an explicit threshold is set.
|
||||||
cybersyn-provide-threshold=When a provider threshold signal is not recieved by a station it will default to this value.
|
cybersyn-provide-threshold=The default provide threshold when a provide threshold signal is not given to a station. Huge values will prevent stations from providing to the network unless an explicit threshold is set.
|
||||||
cybersyn-network-flag=Choose the default set of networks a station will service when no network signal is provided. This integer is interpretted bit-wise to give 32 possible networks to choose from.
|
cybersyn-network-flag=The default set of networks a station will service when no network signal is given to a station. This integer is interpretted bit-wise to give 32 possible network flags to choose from.
|
||||||
|
|
||||||
[item-name]
|
[item-name]
|
||||||
cybersyn-combinator=Cybernetic combinator
|
cybersyn-combinator=Cybernetic combinator
|
||||||
|
|
||||||
[item-description]
|
[item-description]
|
||||||
cybersyn-combinator=Cybernetic combinator
|
cybersyn-combinator=Place next to a train stop to add it to the cybersyn network. Adjacent stations can now request or provide items or fluids by train. Has 4 different operation modes.
|
||||||
|
|
||||||
[entity-name]
|
[entity-name]
|
||||||
cybersyn-combinator=Cybernetic combinator
|
cybersyn-combinator=Cybernetic combinator
|
||||||
cybersyn-combinator-output=NA
|
cybersyn-combinator-output=NA
|
||||||
|
|
||||||
[entity-description]
|
[entity-description]
|
||||||
cybersyn-combinator=Cybersyn depot
|
cybersyn-combinator=Place next to a train stop to add it to the cybersyn network. Has 4 different operation modes.
|
||||||
cybersyn-combinator-output=NA
|
cybersyn-combinator-output=NA
|
||||||
|
|
||||||
[technology-name]
|
[technology-name]
|
||||||
cybersyn-train-network=Cybernetic train network
|
cybersyn-train-network=Cybernetic train network
|
||||||
|
|
||||||
[technology-description]
|
[technology-description]
|
||||||
cybersyn-train-network=Cybernetic train network
|
cybersyn-train-network=Train station controllers capable of coordinating the inputs and outputs of an entire economy.
|
||||||
|
|
||||||
[virtual-signal-name]
|
[virtual-signal-name]
|
||||||
cybersyn-priority=Station priority
|
cybersyn-priority=Station priority
|
||||||
@@ -42,11 +42,11 @@ lost-train=A train has become lost
|
|||||||
nonempty-train=A train has parked in a depot while still containing items; it cannot be dispatched until it is empty
|
nonempty-train=A train has parked in a depot while still containing items; it cannot be dispatched until it is empty
|
||||||
|
|
||||||
[cybersyn-gui]
|
[cybersyn-gui]
|
||||||
operation=Combinator type
|
|
||||||
network=Network
|
|
||||||
comb1=Primary controller
|
|
||||||
comb2=Secondary station control
|
|
||||||
depot=Depot
|
|
||||||
wagon-manifest=Wagon
|
|
||||||
combinator-title=Cybernetic combinator
|
combinator-title=Cybernetic combinator
|
||||||
auto-description=Station automatically decides which trains in the network it can service
|
operation=Mode
|
||||||
|
comb1=Primary station control
|
||||||
|
comb2=Optional station control
|
||||||
|
depot=Depot control
|
||||||
|
wagon-manifest=Wagon control
|
||||||
|
network=Network
|
||||||
|
auto-description=Station automatically decides which trains in the network it can service (all trains are allowed by default)
|
||||||
|
|||||||
@@ -85,11 +85,7 @@ function set_combinator_output(map_data, comb, signals)
|
|||||||
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
|
||||||
else
|
|
||||||
--TODO: error logging?
|
|
||||||
end
|
end
|
||||||
else
|
|
||||||
--TODO: error logging?
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
@@ -101,7 +97,7 @@ local function set_comb2(map_data, station)
|
|||||||
local signals = {}
|
local signals = {}
|
||||||
for item_name, count in pairs(deliveries) do
|
for item_name, count in pairs(deliveries) do
|
||||||
local i = #signals + 1
|
local i = #signals + 1
|
||||||
local item_type = game.item_prototypes[item_name].type
|
local item_type = game.item_prototypes[item_name].type--NOTE: this is expensive
|
||||||
signals[i] = {index = i, signal = {type = item_type, name = item_name}, count = -count}
|
signals[i] = {index = i, signal = {type = item_type, name = item_name}, count = -count}
|
||||||
end
|
end
|
||||||
set_combinator_output(map_data, station.entity_comb2, signals)
|
set_combinator_output(map_data, station.entity_comb2, signals)
|
||||||
@@ -124,7 +120,6 @@ function remove_manifest(map_data, station, manifest, sign)
|
|||||||
end
|
end
|
||||||
|
|
||||||
---@param map_data MapData
|
---@param map_data MapData
|
||||||
---@param station Station
|
|
||||||
---@param signal SignalID
|
---@param signal SignalID
|
||||||
local function get_thresholds(map_data, station, signal)
|
local function get_thresholds(map_data, station, signal)
|
||||||
local comb2 = station.entity_comb2
|
local comb2 = station.entity_comb2
|
||||||
@@ -229,10 +224,8 @@ local function send_train_between(map_data, r_station_id, p_station_id, depot, p
|
|||||||
---@type string
|
---@type string
|
||||||
local item_name = v.signal.name
|
local item_name = v.signal.name
|
||||||
local item_count = v.count
|
local item_count = v.count
|
||||||
--local item_type = v.signal.type
|
|
||||||
local effective_item_count = item_count + (r_station.deliveries[item_name] or 0)
|
local effective_item_count = item_count + (r_station.deliveries[item_name] or 0)
|
||||||
local r_threshold, p_threshold = get_thresholds(map_data, r_station, v.signal)
|
if effective_item_count < 0 and item_count < 0 then
|
||||||
if -effective_item_count >= r_threshold then
|
|
||||||
requests[item_name] = -effective_item_count
|
requests[item_name] = -effective_item_count
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
@@ -245,8 +238,7 @@ local function send_train_between(map_data, r_station_id, p_station_id, depot, p
|
|||||||
local item_count = v.count
|
local item_count = v.count
|
||||||
local item_type = v.signal.type
|
local item_type = v.signal.type
|
||||||
local effective_item_count = item_count + (p_station.deliveries[item_name] or 0)
|
local effective_item_count = item_count + (p_station.deliveries[item_name] or 0)
|
||||||
local r_threshold, p_threshold = get_thresholds(map_data, p_station, v.signal)
|
if effective_item_count > 0 and item_count > 0 then
|
||||||
if effective_item_count >= p_threshold then
|
|
||||||
local r = requests[item_name]
|
local r = requests[item_name]
|
||||||
if r then
|
if r then
|
||||||
local item = {name = item_name, type = item_type, count = min(r, effective_item_count)}
|
local item = {name = item_name, type = item_type, count = min(r, effective_item_count)}
|
||||||
@@ -312,6 +304,7 @@ local function send_train_between(map_data, r_station_id, p_station_id, depot, p
|
|||||||
local item_network_name = network_name..":"..item.name
|
local item_network_name = network_name..":"..item.name
|
||||||
local r_stations = economy.all_r_stations[item_network_name]
|
local r_stations = economy.all_r_stations[item_network_name]
|
||||||
local p_stations = economy.all_p_stations[item_network_name]
|
local p_stations = economy.all_p_stations[item_network_name]
|
||||||
|
--NOTE: one of these will be redundant
|
||||||
for i, id in ipairs(r_stations) do
|
for i, id in ipairs(r_stations) do
|
||||||
if id == r_station_id then
|
if id == r_station_id then
|
||||||
table.remove(r_stations, i)
|
table.remove(r_stations, i)
|
||||||
@@ -422,9 +415,10 @@ local function tick_poll_station(map_data, mod_settings)
|
|||||||
if item_type == "virtual" then
|
if item_type == "virtual" then
|
||||||
if item_name == SIGNAL_PRIORITY then
|
if item_name == SIGNAL_PRIORITY then
|
||||||
station.priority = item_count
|
station.priority = item_count
|
||||||
elseif item_name == REQUEST_THRESHOLD then
|
elseif item_name == REQUEST_THRESHOLD and item_count ~= 0 then
|
||||||
|
--NOTE: thresholds must be >0 or they will cause a crash
|
||||||
station.r_threshold = abs(item_count)
|
station.r_threshold = abs(item_count)
|
||||||
elseif item_name == PROVIDE_THRESHOLD then
|
elseif item_name == PROVIDE_THRESHOLD and item_count ~= 0 then
|
||||||
station.p_threshold = abs(item_count)
|
station.p_threshold = abs(item_count)
|
||||||
elseif item_name == LOCKED_SLOTS then
|
elseif item_name == LOCKED_SLOTS then
|
||||||
station.locked_slots = max(item_count, 0)
|
station.locked_slots = max(item_count, 0)
|
||||||
@@ -444,7 +438,7 @@ local function tick_poll_station(map_data, mod_settings)
|
|||||||
local effective_item_count = item_count + (station.deliveries[item_name] or 0)
|
local effective_item_count = item_count + (station.deliveries[item_name] or 0)
|
||||||
local r_threshold, p_threshold = get_thresholds(map_data, station, v.signal)
|
local r_threshold, p_threshold = get_thresholds(map_data, station, v.signal)
|
||||||
|
|
||||||
if -effective_item_count >= r_threshold then
|
if -effective_item_count >= r_threshold and -item_count >= r_threshold then
|
||||||
local item_network_name = station.network_name..":"..item_name
|
local item_network_name = station.network_name..":"..item_name
|
||||||
local stations = all_r_stations[item_network_name]
|
local stations = all_r_stations[item_network_name]
|
||||||
if stations == nil then
|
if stations == nil then
|
||||||
@@ -454,7 +448,7 @@ local function tick_poll_station(map_data, mod_settings)
|
|||||||
all_names[#all_names + 1] = v.signal
|
all_names[#all_names + 1] = v.signal
|
||||||
end
|
end
|
||||||
stations[#stations + 1] = station_id
|
stations[#stations + 1] = station_id
|
||||||
elseif effective_item_count >= p_threshold then
|
elseif effective_item_count >= p_threshold and item_count >= p_threshold then
|
||||||
local item_network_name = station.network_name..":"..item_name
|
local item_network_name = station.network_name..":"..item_name
|
||||||
local stations = all_p_stations[item_network_name]
|
local stations = all_p_stations[item_network_name]
|
||||||
if stations == nil then
|
if stations == nil then
|
||||||
@@ -462,6 +456,8 @@ local function tick_poll_station(map_data, mod_settings)
|
|||||||
all_p_stations[item_network_name] = stations
|
all_p_stations[item_network_name] = stations
|
||||||
end
|
end
|
||||||
stations[#stations + 1] = station_id
|
stations[#stations + 1] = station_id
|
||||||
|
else
|
||||||
|
signals[k] = nil
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|||||||
@@ -11,6 +11,7 @@ LOCKED_SLOTS = "cybersyn-locked-slots"
|
|||||||
|
|
||||||
COMBINATOR_NAME = "cybersyn-combinator"
|
COMBINATOR_NAME = "cybersyn-combinator"
|
||||||
COMBINATOR_OUT_NAME = "cybersyn-combinator-output"
|
COMBINATOR_OUT_NAME = "cybersyn-combinator-output"
|
||||||
|
COMBINATOR_CLOSE_SOUND = "entity-close/cybersyn-combinator"
|
||||||
|
|
||||||
OPERATION_DEFAULT = "*"
|
OPERATION_DEFAULT = "*"
|
||||||
OPERATION_PRIMARY_IO = "/"
|
OPERATION_PRIMARY_IO = "/"
|
||||||
|
|||||||
@@ -32,7 +32,7 @@
|
|||||||
---@field public is_all boolean
|
---@field public is_all boolean
|
||||||
---@field public accepted_layouts TrainClass
|
---@field public accepted_layouts TrainClass
|
||||||
---@field public layout_pattern string?
|
---@field public layout_pattern string?
|
||||||
---@field public tick_signals Signal[]? --transient
|
---@field public tick_signals {[uint]: Signal}? --transient
|
||||||
|
|
||||||
---@class Depot
|
---@class Depot
|
||||||
---@field public priority int --transient
|
---@field public priority int --transient
|
||||||
@@ -69,15 +69,10 @@
|
|||||||
---@field public p_threshold int
|
---@field public p_threshold int
|
||||||
---@field public network_flag int
|
---@field public network_flag int
|
||||||
|
|
||||||
|
|
||||||
--TODO: only init once and move settings code
|
|
||||||
---@type CybersynModSettings
|
---@type CybersynModSettings
|
||||||
mod_settings = {}
|
mod_settings = {}
|
||||||
mod_settings.tps = settings.global["cybersyn-ticks-per-second"].value
|
|
||||||
mod_settings.r_threshold = settings.global["cybersyn-request-threshold"].value
|
|
||||||
mod_settings.p_threshold = settings.global["cybersyn-provide-threshold"].value
|
|
||||||
mod_settings.network_flag = settings.global["cybersyn-network-flag"].value
|
|
||||||
|
|
||||||
|
--TODO: guarantee this only inits once
|
||||||
global.total_ticks = 0
|
global.total_ticks = 0
|
||||||
global.tick_state = STATE_INIT
|
global.tick_state = STATE_INIT
|
||||||
global.tick_data = {}
|
global.tick_data = {}
|
||||||
|
|||||||
@@ -118,7 +118,7 @@ local function on_gui_closed(event)
|
|||||||
|
|
||||||
if rootgui[COMBINATOR_NAME] then
|
if rootgui[COMBINATOR_NAME] then
|
||||||
rootgui[COMBINATOR_NAME].destroy()
|
rootgui[COMBINATOR_NAME].destroy()
|
||||||
--TODO: play close sound to player
|
player.play_sound({path = COMBINATOR_CLOSE_SOUND})
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
@@ -133,7 +133,7 @@ function register_gui_actions()
|
|||||||
if msg[1] == "close" then
|
if msg[1] == "close" then
|
||||||
if rootgui[COMBINATOR_NAME] then
|
if rootgui[COMBINATOR_NAME] then
|
||||||
rootgui[COMBINATOR_NAME].destroy()
|
rootgui[COMBINATOR_NAME].destroy()
|
||||||
--TODO: play close sound to player
|
player.play_sound({path = COMBINATOR_CLOSE_SOUND})
|
||||||
end
|
end
|
||||||
elseif msg[1] == "drop-down" then
|
elseif msg[1] == "drop-down" then
|
||||||
local element = event.element
|
local element = event.element
|
||||||
|
|||||||
@@ -244,7 +244,6 @@ function set_r_wagon_combs(map_data, station, train)
|
|||||||
local stack = inv[stack_i]
|
local stack = inv[stack_i]
|
||||||
if stack.valid_for_read then
|
if stack.valid_for_read then
|
||||||
local i = #signals + 1
|
local i = #signals + 1
|
||||||
--TODO: does this work or do we need to aggregate signals?
|
|
||||||
signals[i] = {index = i, signal = {type = stack.type, name = stack.name}, count = -stack.count}
|
signals[i] = {index = i, signal = {type = stack.type, name = stack.name}, count = -stack.count}
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
@@ -406,7 +405,6 @@ local function reset_station_layout(map_data, station, forbidden_entity)
|
|||||||
if supports_fluid then
|
if supports_fluid then
|
||||||
layout_pattern = layout_pattern..STATION_LAYOUT_ALL
|
layout_pattern = layout_pattern..STATION_LAYOUT_ALL
|
||||||
else
|
else
|
||||||
--TODO: needs to allow misc wagons as well
|
|
||||||
layout_pattern = layout_pattern..STATION_LAYOUT_NOT_FLUID
|
layout_pattern = layout_pattern..STATION_LAYOUT_NOT_FLUID
|
||||||
end
|
end
|
||||||
pattern_length = #layout_pattern
|
pattern_length = #layout_pattern
|
||||||
@@ -456,7 +454,7 @@ end
|
|||||||
---@param rail LuaEntity
|
---@param rail LuaEntity
|
||||||
---@param forbidden_entity LuaEntity?
|
---@param forbidden_entity LuaEntity?
|
||||||
function update_station_from_rail(map_data, rail, forbidden_entity)
|
function update_station_from_rail(map_data, rail, forbidden_entity)
|
||||||
--TODO: search further or better?
|
--NOTE: should we search further or better? it would be more expensive
|
||||||
local entity = rail.get_rail_segment_entity(defines.rail_direction.back, false)
|
local entity = rail.get_rail_segment_entity(defines.rail_direction.back, false)
|
||||||
if entity and entity.valid and entity.name == "train-stop" then
|
if entity and entity.valid and entity.name == "train-stop" then
|
||||||
local station = map_data.stations[entity.unit_number]
|
local station = map_data.stations[entity.unit_number]
|
||||||
@@ -485,7 +483,6 @@ end
|
|||||||
---@param inserter LuaEntity
|
---@param inserter LuaEntity
|
||||||
---@param forbidden_entity LuaEntity?
|
---@param forbidden_entity LuaEntity?
|
||||||
function update_station_from_inserter(map_data, inserter, forbidden_entity)
|
function update_station_from_inserter(map_data, inserter, forbidden_entity)
|
||||||
--TODO: check if correct
|
|
||||||
local surface = inserter.surface
|
local surface = inserter.surface
|
||||||
|
|
||||||
local rail = surface.find_entity("straight-rail", inserter.pickup_position)
|
local rail = surface.find_entity("straight-rail", inserter.pickup_position)
|
||||||
|
|||||||
@@ -720,6 +720,12 @@ local filter_comb = {
|
|||||||
{filter = "type", type = "arithmetic-combinator"},
|
{filter = "type", type = "arithmetic-combinator"},
|
||||||
}
|
}
|
||||||
local function register_events()
|
local function register_events()
|
||||||
|
|
||||||
|
mod_settings.tps = settings.global["cybersyn-ticks-per-second"].value --[[@as int]]
|
||||||
|
mod_settings.r_threshold = settings.global["cybersyn-request-threshold"].value--[[@as int]]
|
||||||
|
mod_settings.p_threshold = settings.global["cybersyn-provide-threshold"].value--[[@as int]]
|
||||||
|
mod_settings.network_flag = settings.global["cybersyn-network-flag"].value--[[@as int]]
|
||||||
|
|
||||||
--NOTE: I have no idea if this correctly registers all events once in all situations
|
--NOTE: I have no idea if this correctly registers all events once in all situations
|
||||||
flib_event.register(defines.events.on_built_entity, on_built, filter_built)
|
flib_event.register(defines.events.on_built_entity, on_built, filter_built)
|
||||||
flib_event.register(defines.events.on_robot_built_entity, on_built, filter_built)
|
flib_event.register(defines.events.on_robot_built_entity, on_built, filter_built)
|
||||||
|
|||||||
@@ -14,7 +14,7 @@ data:extend({
|
|||||||
name = "cybersyn-request-threshold",
|
name = "cybersyn-request-threshold",
|
||||||
order = "ab",
|
order = "ab",
|
||||||
setting_type = "runtime-global",
|
setting_type = "runtime-global",
|
||||||
default_value = 1000000000,
|
default_value = 2000000000,
|
||||||
minimum_value = 1,
|
minimum_value = 1,
|
||||||
maximum_value = 2147483647,
|
maximum_value = 2147483647,
|
||||||
},
|
},
|
||||||
@@ -23,7 +23,7 @@ data:extend({
|
|||||||
name = "cybersyn-provide-threshold",
|
name = "cybersyn-provide-threshold",
|
||||||
order = "ac",
|
order = "ac",
|
||||||
setting_type = "runtime-global",
|
setting_type = "runtime-global",
|
||||||
default_value = 1000000000,
|
default_value = 2000000000,
|
||||||
minimum_value = 1,
|
minimum_value = 1,
|
||||||
maximum_value = 2147483647,
|
maximum_value = 2147483647,
|
||||||
},
|
},
|
||||||
|
|||||||
Reference in New Issue
Block a user