added nullius compat

This commit is contained in:
mamoniot
2022-12-16 09:51:59 -05:00
parent f76c01614e
commit 71b21c9b3c
12 changed files with 104 additions and 77 deletions

View File

@@ -22,5 +22,8 @@
"~/.steam/steam/steamapps/common/Factorio/data",
"~/.steam/steam/steamapps/common/Factorio/data/core/lualib",
"./.vscode/factorio"
],
"Lua.workspace.userThirdParty": [
"/home/mami/.config/Code/User/workspaceStorage/9536dbf0665a54126a4b0958ecd5829f/justarandomgeek.factoriomod-debug/sumneko-3rd"
]
}

3
TODO
View File

@@ -2,10 +2,9 @@ bugs:
request threshold is being bypassed somehow (hasn't been seen in a long time)
major:
do hardcore testing
models & art
add a refueling option on depots
move to an event based algorithm
debug output
minor:
railloader compat

View File

@@ -1,4 +1,10 @@
---------------------------------------------------------------------------------------------------
Version: 1.1.5
Date: 2022-12-16
Changes:
- Added Nullius compat
- Replaced lost train alert with more detailed alerts
---------------------------------------------------------------------------------------------------
Version: 1.1.4
Date: 2022-12-9
Changes:

View File

@@ -1,8 +1,9 @@
if mods["nullius"] then
-- Place combinator in the same subgroup as the regular train stop
data.raw["recipe"][COMBINATOR_NAME].subgroup = data.raw["train-stop"]["train-stop"].subgroup
data.raw["item"][COMBINATOR_NAME].subgroup = data.raw["item"]["train-stop"].subgroup
-- Nullius makes modded technologies part of its research tree
-- Place combinator in the same place on the research tree as LTN
-- Place combinator in the same place on the research tree as LTN
table.insert(data.raw.technology["nullius-broadcasting-1"].prerequisites, "cybersyn-train-network")
end
end

View File

@@ -44,10 +44,14 @@ cybersyn-locked-slots=Locked slots per cargo wagon
[cybersyn-messages]
missing-trains=Could not find a train to make a delivery from __2__ to __1__
lost-train=A train from depot __1__ has become lost
nonempty-train=A train is being held in the depot because it still has cargo
unexpected-train=A train has unexpectedly returned to the depot before completing its delivery
stuck-train=A train from depot __1__ is stuck
cannot-path-between-surfaces=A train from depot __1__ is attempting to make a delivery between two unconnected surfaces, perhaps put them on separate networks
depot-broken=A train from depot __1__ is lost because its depot was broken.
refueler-broken=A train from depot __1__ is lost because its refueler was broken.
station-broken=A train from depot __1__ is lost because one of its delivery stations was broken.
train-at-incorrect=A train from depot __1__ is lost; it parked at a station it was not scheduled to delivered to.
[cybersyn-gui]
combinator-title=Cybernetic combinator

View File

@@ -5,27 +5,13 @@ combinator_recipe.ingredients = {
{"electronic-circuit", 10},
}
combinator_recipe.enabled = false
if (mods["nullius"]) then
-- Enable recipe and place it just after regular station
combinator_recipe.order = "nullius-eca"
-- In Nullius, most combinators are tiny crafts
combinator_recipe.category = "tiny-crafting"
combinator_recipe.always_show_made_in = true
-- Use the same costs (minus the train stop) as for LTN
combinator_recipe.energy_required = 3
combinator_recipe.ingredients = {
{"arithmetic-combinator", 2},
{"green-wire", 4}
}
end
cybersyn_tech = flib.copy_prototype(data.raw["technology"]["automated-rail-transportation"], "cybersyn-train-network")
cybersyn_tech.icon = "__cybersyn__/graphics/icons/tech.png"
cybersyn_tech.icon_size = 256
cybersyn_tech.prerequisites = {
"automated-rail-transportation",
"rail-signals",
"circuit-network",
}
cybersyn_tech.effects = {
@@ -37,14 +23,24 @@ cybersyn_tech.effects = {
cybersyn_tech.unit.count = 3*cybersyn_tech.unit.count
cybersyn_tech.order = "c-g-c"
if (mods["nullius"]) then
-- Enable recipe and place it just after regular station
combinator_recipe.order = "nullius-eca"
-- In Nullius, most combinators are tiny crafts
combinator_recipe.category = "tiny-crafting"
combinator_recipe.always_show_made_in = true
combinator_recipe.energy_required = 3
combinator_recipe.ingredients = {
{"arithmetic-combinator", 2},
{"copper-cable", 10}
}
-- Enable technology
cybersyn_tech.order = "nullius-" .. (cybersyn_tech.order or "")
cybersyn_tech.unit = {
count = 100,
ingredients = {
{ "nullius-geology-pack", 1 }, { "nullius-climatology-pack", 1 },
{ "nullius-mechanical-pack", 1 }, { "nullius-electrical-pack", 1 }
{"nullius-geology-pack", 1}, {"nullius-climatology-pack", 1}, {"nullius-mechanical-pack", 1}, {"nullius-electrical-pack", 1}
},
time = 25
}

View File

@@ -533,7 +533,7 @@ local function tick_poll_comb(map_data)
tick_data.last_comb = comb_id
if comb and comb.valid then
combinator_update(map_data, comb)
combinator_update(map_data, comb, true)
end
end
---@param map_data MapData

View File

@@ -137,7 +137,7 @@ function set_manifest_schedule(train, depot_name, d_surface_i, p_stop, r_stop, m
local is_r_on_t = t_surface_i == r_surface_i
local is_d_on_t = t_surface_i == d_surface_i
if is_p_on_t and is_r_on_t and is_d_on_t then
train.schedule = {current = start_at_depot and 1 or 2, records = {
train.schedule = {current = start_at_depot and 1 or 2--[[@as uint]], records = {
create_inactivity_order(depot_name),
create_direct_to_station_order(p_stop),
create_loading_order(p_stop, manifest),
@@ -153,8 +153,8 @@ function set_manifest_schedule(train, depot_name, d_surface_i, p_stop, r_stop, m
elseif IS_SE_PRESENT then
local other_surface_i = (not is_p_on_t and p_surface_i) or (not is_r_on_t and r_surface_i) or d_surface_i
if (is_p_on_t or p_surface_i == other_surface_i) and (is_r_on_t or r_surface_i == other_surface_i) and (is_d_on_t or d_surface_i == other_surface_i) then
local t_zone = remote.call("space-exploration", "get_zone_from_surface_index", {surface_index = t_surface_i})
local other_zone = remote.call("space-exploration", "get_zone_from_surface_index", {surface_index = other_surface_i})
local t_zone = remote.call("space-exploration", "get_zone_from_surface_index", {surface_index = t_surface_i})--[[@as {}]]
local other_zone = remote.call("space-exploration", "get_zone_from_surface_index", {surface_index = other_surface_i})--[[@as {}]]
local is_train_in_orbit = other_zone.orbit_index == t_zone.index
if is_train_in_orbit or t_zone.orbit_index == other_zone.index then
local elevator_name = se_get_space_elevator_name(t_surface)
@@ -180,7 +180,7 @@ function set_manifest_schedule(train, depot_name, d_surface_i, p_stop, r_stop, m
is_train_in_orbit = not is_train_in_orbit
end
train.schedule = {current = start_at_depot and 1 or 2, records = records}
train.schedule = {current = start_at_depot and 1 or 2--[[@as uint]], records = records}
if old_schedule and not train.has_path then
train.schedule = old_schedule
return false
@@ -198,7 +198,7 @@ function set_manifest_schedule(train, depot_name, d_surface_i, p_stop, r_stop, m
create_unloading_order(r_stop),
}}
lock_train(train)
send_lost_train_alert(train, depot_name)
send_cannot_path_between_surfaces_alert(train, depot_name)
return true
end
@@ -225,8 +225,8 @@ function add_refueler_schedule(train, stop, depot_name)
train.schedule = schedule
return
elseif IS_SE_PRESENT then
local t_zone = remote.call("space-exploration", "get_zone_from_surface_index", {surface_index = t_surface_i})
local other_zone = remote.call("space-exploration", "get_zone_from_surface_index", {surface_index = f_surface_i})
local t_zone = remote.call("space-exploration", "get_zone_from_surface_index", {surface_index = t_surface_i})--[[@as {}]]
local other_zone = remote.call("space-exploration", "get_zone_from_surface_index", {surface_index = f_surface_i})--[[@as {}]]
local is_train_in_orbit = other_zone.orbit_index == t_zone.index
if is_train_in_orbit or t_zone.orbit_index == other_zone.index then
local elevator_name = se_get_space_elevator_name(t_surface)
@@ -252,7 +252,7 @@ function add_refueler_schedule(train, stop, depot_name)
--create an order that probably cannot be fulfilled and alert the player
table_insert(schedule.records, i, create_inactivity_order(stop.backer_name))
lock_train(train)
send_lost_train_alert(train, depot_name)
send_cannot_path_between_surfaces_alert(train, depot_name)
train.schedule = schedule
end
@@ -457,6 +457,22 @@ end
--[[alerts]]--
------------------------------------------------------------------------------
---@param train LuaTrain
---@param icon {}
---@param message {}
local function send_alert_with_sound(train, icon, message)
local loco = train.front_stock or train.back_stock
if loco then
for _, player in pairs(loco.force.players) do
player.add_custom_alert(
loco,
icon,
message,
true)
player.play_sound({path = ALERT_SOUND})
end
end
end
local send_missing_train_alert_for_stop_icon = {name = MISSING_TRAIN_NAME, type = "fluid"}
---@param r_stop LuaEntity
@@ -474,19 +490,36 @@ end
local send_lost_train_alert_icon = {name = LOST_TRAIN_NAME, type = "fluid"}
---@param train LuaTrain
---@param depot_name string
function send_lost_train_alert(train, depot_name)
local loco = train.front_stock or train.back_stock
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", depot_name},
true)
player.play_sound({path = ALERT_SOUND})
end
end
function send_cannot_path_between_surfaces_alert(train, depot_name)
send_alert_with_sound(train, send_lost_train_alert_icon, {"cybersyn-messages.cannot-path-between-surfaces", depot_name})
end
---@param train LuaTrain
---@param depot_name string
function send_depot_of_train_broken_alert(train, depot_name)
send_alert_with_sound(train, send_lost_train_alert_icon, {"cybersyn-messages.depot-broken", depot_name})
end
---@param train LuaTrain
---@param depot_name string
function send_refueler_of_train_broken_alert(train, depot_name)
send_alert_with_sound(train, send_lost_train_alert_icon, {"cybersyn-messages.refueler-broken", depot_name})
end
---@param train LuaTrain
---@param depot_name string
function send_station_of_train_broken_alert(train, depot_name)
send_alert_with_sound(train, send_lost_train_alert_icon, {"cybersyn-messages.station-broken", depot_name})
end
---@param train LuaTrain
---@param depot_name string
function send_train_at_incorrect_station_alert(train, depot_name)
send_alert_with_sound(train, send_lost_train_alert_icon, {"cybersyn-messages.train-at-incorrect", depot_name})
end
local send_nonempty_train_in_depot_alert_icon = {name = NONEMPTY_TRAIN_NAME, type = "fluid"}
---@param train LuaTrain
function send_nonempty_train_in_depot_alert(train)
send_alert_with_sound(train, send_nonempty_train_in_depot_alert_icon, {"cybersyn-messages.nonempty-train"})
end
---@param train LuaTrain
function send_unexpected_train_alert(train)
local loco = train.front_stock or train.back_stock
@@ -500,25 +533,6 @@ function send_unexpected_train_alert(train)
end
end
end
local send_nonempty_train_in_depot_alert_icon = {name = NONEMPTY_TRAIN_NAME, type = "fluid"}
---@param train LuaTrain
function send_nonempty_train_in_depot_alert(train)
local loco = train.front_stock or train.back_stock
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)
player.play_sound({path = ALERT_SOUND})
end
end
end
local send_stuck_train_alert_icon = {name = LOST_TRAIN_NAME, type = "fluid"}
---@param train LuaTrain
---@param depot_name string

View File

@@ -29,7 +29,7 @@ STATUS_NAMES_DEFAULT = "entity-status.disabled"
---@param comb LuaEntity
---@param player LuaPlayer
function gui_opened(comb, player)
combinator_update(global, comb)
combinator_update(global, comb, true)
local rootgui = player.gui.screen
local selected_index, signal, check, switch_state = get_comb_gui_settings(comb)

View File

@@ -27,7 +27,7 @@ local function on_depot_broken(map_data, depot_id, depot)
if train_id then
local train = map_data.trains[train_id]
lock_train(train.entity)
send_lost_train_alert(train.entity, depot.entity_stop.backer_name)
send_depot_of_train_broken_alert(train.entity, depot.entity_stop.backer_name)
remove_train(map_data, train_id, train)
end
map_data.depots[depot_id] = nil
@@ -76,7 +76,7 @@ local function on_refueler_broken(map_data, refueler_id, refueler)
if not train.se_is_being_teleported then
remove_train(map_data, train_id, train)
lock_train(train.entity)
send_lost_train_alert(train.entity, train.depot_name)
send_refueler_of_train_broken_alert(train.entity, train.depot_name)
else
train.se_awaiting_removal = train_id
end
@@ -151,7 +151,7 @@ local function on_station_broken(map_data, station_id, station)
if not train.se_is_being_teleported then
remove_train(map_data, train_id, train)
lock_train(train.entity)
send_lost_train_alert(train.entity, train.depot_name)
send_station_of_train_broken_alert(train.entity, train.depot_name)
else
train.se_awaiting_removal = train_id
end
@@ -391,7 +391,8 @@ end
---@param map_data MapData
---@param comb LuaEntity
function combinator_update(map_data, comb)
---@param reset_display boolean?
function combinator_update(map_data, comb, reset_display)
local unit_number = comb.unit_number--[[@as uint]]
local control = get_comb_control(comb)
local params = control.parameters
@@ -399,7 +400,7 @@ function combinator_update(map_data, comb)
local has_changed = false
local stop = map_data.to_stop[comb.unit_number]
if stop then
if reset_display and stop then
id = stop.unit_number
station = map_data.stations[id]
if station then
@@ -414,7 +415,6 @@ function combinator_update(map_data, comb)
control.parameters = params
end
end
if params.operation == MODE_PRIMARY_IO_ACTIVE or params.operation == MODE_PRIMARY_IO_FAILED_REQUEST then
params.operation = MODE_PRIMARY_IO
end
@@ -652,7 +652,7 @@ local function on_paste(event)
if not entity or not entity.valid then return end
if entity.name == COMBINATOR_NAME then
combinator_update(global, entity)
combinator_update(global, entity, true)
end
end
@@ -689,8 +689,8 @@ local function setup_se_compat()
IS_SE_PRESENT = remote.interfaces["space-exploration"] ~= nil
if not IS_SE_PRESENT then return end
local se_on_train_teleport_finished_event = remote.call("space-exploration", "get_on_train_teleport_finished_event")
local se_on_train_teleport_started_event = remote.call("space-exploration", "get_on_train_teleport_started_event")
local se_on_train_teleport_finished_event = remote.call("space-exploration", "get_on_train_teleport_finished_event")--[[@as string]]
local se_on_train_teleport_started_event = remote.call("space-exploration", "get_on_train_teleport_started_event")--[[@as string]]
---@param event {}
script.on_event(se_on_train_teleport_started_event, function(event)
@@ -742,7 +742,7 @@ local function setup_se_compat()
if train.se_awaiting_removal then
remove_train(map_data, train.se_awaiting_removal, train)
lock_train(train.entity)
send_lost_train_alert(train.entity, train.depot_name)
send_station_of_train_broken_alert(train.entity, train.depot_name)
return
elseif train.se_awaiting_rename then
rename_manifest_schedule(train.entity, train.se_awaiting_rename[1], train.se_awaiting_rename[2])

View File

@@ -348,10 +348,14 @@ interface.add_refueler_schedule = add_refueler_schedule
------------------------------------------------------------------
interface.send_missing_train_alert = send_missing_train_alert
interface.send_lost_train_alert = send_lost_train_alert
interface.send_unexpected_train_alert = send_unexpected_train_alert
interface.send_nonempty_train_in_depot_alert = send_nonempty_train_in_depot_alert
interface.send_stuck_train_alert = send_stuck_train_alert
interface.send_cannot_path_between_surfaces_alert = send_cannot_path_between_surfaces_alert
interface.send_depot_of_train_broken_alert = send_depot_of_train_broken_alert
interface.send_refueler_of_train_broken_alert = send_refueler_of_train_broken_alert
interface.send_station_of_train_broken_alert = send_station_of_train_broken_alert
interface.send_train_at_incorrect_station_alert = send_train_at_incorrect_station_alert
remote.add_interface("cybersyn", interface)

View File

@@ -4,7 +4,7 @@ local INF = math.huge
---@param map_data MapData
---@param station Station
---@param manifest Manifest
---@param manifest Manifest?
---@param sign int?
local function set_comb1(map_data, station, manifest, sign)
local comb = station.entity_comb1
@@ -238,12 +238,12 @@ local function on_train_arrives_station(map_data, station_id, train_id, train)
on_failed_delivery(map_data, train_id, train)
remove_train(map_data, train_id, train)
lock_train(train.entity)
send_lost_train_alert(train.entity, train.depot_name)
send_train_at_incorrect_station_alert(train.entity, train.depot_name)
end
elseif mod_settings.react_to_train_at_incorrect_station then
--train is lost somehow, probably from player intervention
remove_train(map_data, train_id, train)
send_lost_train_alert(train.entity, train.depot_name)
send_train_at_incorrect_station_alert(train.entity, train.depot_name)
end
end