api update

This commit is contained in:
Monica Moniot
2022-10-28 14:40:49 -04:00
parent 4887e3925d
commit d2bb9e2523
113 changed files with 432 additions and 222 deletions

View File

@@ -5,4 +5,5 @@ require("scripts.global")
require("scripts.controller")
require("scripts.layout")
require("scripts.gui")
require("scripts.alerts")
require("scripts.main")

View File

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.3 KiB

View File

Binary file not shown.

Before

Width:  |  Height:  |  Size: 2.5 KiB

After

Width:  |  Height:  |  Size: 1.2 KiB

View File

@@ -1,6 +1,6 @@
--By Mami
combinator_entity = flib.copy_prototype(data.raw["arithmetic-combinator"]["arithmetic-combinator"], COMBINATOR_NAME)
combinator_entity.icon = "__cybersyn__/graphics/icons/combinator.png"
combinator_entity.icon = "__cybersyn__/graphics/icons/area-of-effect.png"
combinator_entity.radius_visualisation_specification = {
sprite = {
filename = "__cybersyn__/graphics/icons/combinator.png",
@@ -10,6 +10,9 @@ combinator_entity.radius_visualisation_specification = {
},
distance = 1,
}
combinator_entity.active_energy_usage = "10KW"
combinator_entity.allow_copy_paste = false
combinator_out_entity = flib.copy_prototype(data.raw["constant-combinator"]["constant-combinator"], COMBINATOR_OUT_NAME)
combinator_out_entity.icon = nil

View File

@@ -3,4 +3,4 @@ combinator_item = flib.copy_prototype(data.raw["item"]["arithmetic-combinator"],
combinator_item.icon = "__cybersyn__/graphics/icons/combinator.png"
combinator_item.icon_size = 64
combinator_item.icon_mipmaps = 4
combinator_item.order = combinator_item.order.."-c"
combinator_item.order = data.raw["item"]["decider-combinator"].order.."-b"

View File

@@ -236,7 +236,7 @@ local function send_train_between(map_data, r_station_id, p_station_id, train, p
local item_type = v.signal.type
if item_name and item_type and item_type ~= "virtual" then
local effective_item_count = item_count + (p_station.deliveries[item_name] or 0)
local r_threshold, p_threshold = get_thresholds(map_data, r_station, v.signal)
local r_threshold, p_threshold = get_thresholds(map_data, p_station, v.signal)
if effective_item_count >= p_threshold then
local r = requests[item_name]
if r then
@@ -332,6 +332,7 @@ end
function tick(map_data, mod_settings)
local total_ticks = map_data.total_ticks
local stations = map_data.stations
---@type Economy
local economy = {
r_stations_all = {},
p_stations_all = {},
@@ -442,7 +443,7 @@ function tick(map_data, mod_settings)
if best_train then
send_train_between(map_data, r_station_id, p_stations[best], best_train, item_name, economy)
elseif could_have_been_serviced then
send_missing_train_alert_for_stops(stations[r_station_id].entity_stop, p_stations[best].entity_stop)
send_missing_train_alert_for_stops(stations[r_station_id].entity_stop, stations[p_stations[best]].entity_stop)
end
until #r_stations == 0
else
@@ -475,7 +476,7 @@ function tick(map_data, mod_settings)
if best_train then
send_train_between(map_data, r_stations[best], p_station_id, best_train, item_name, economy)
elseif could_have_been_serviced then
send_missing_train_alert_for_stops(stations[best].entity_stop, p_stations[p_station_id].entity_stop)
send_missing_train_alert_for_stops(stations[r_stations[best]].entity_stop, stations[p_station_id].entity_stop)
end
until #p_stations == 0
end

View File

@@ -68,5 +68,5 @@ global.layouts = {}
global.layout_train_count = {}
global.layout_top_id = 1
global.train_classes = {
[TRAIN_CLASS_ALL] = {},
--[TRAIN_CLASS_ALL.name] = {},
}

View File

@@ -15,7 +15,7 @@ function remove_train(map_data, train, train_id)
for station_id, station in pairs(map_data.stations) do
station.accepted_layouts[layout_id] = nil
end
map_data.train_classes[TRAIN_CLASS_ALL][layout_id] = nil
--map_data.train_classes[TRAIN_CLASS_ALL][layout_id] = nil
else
map_data.layout_train_count[layout_id] = count - 1
end
@@ -64,7 +64,7 @@ function update_train_layout(map_data, train)
station.accepted_layouts[layout_id] = true
end
end
map_data.train_classes[TRAIN_CLASS_ALL][layout_id] = true
--map_data.train_classes[TRAIN_CLASS_ALL][layout_id] = true
else
map_data.layout_train_count[layout_id] = map_data.layout_train_count[layout_id] + 1
end

View File

@@ -214,7 +214,7 @@ local function on_combinator_broken(map_data, comb)
station.entity_comb1 = comb1
else
on_station_broken(map_data, stop.unit_number, station)
map_data.depots[stop.unit_number] = search_for_station_combinator(map_data, stop, OPERATION_DEPOT, nil)
map_data.depots[stop.unit_number] = search_for_station_combinator(map_data, stop, OPERATION_DEPOT, comb)
end
elseif station.entity_comb2 == comb then
station.entity_comb2 = search_for_station_combinator(map_data, stop, OPERATION_SECONDARY_IO, comb)
@@ -290,7 +290,7 @@ local function on_stop_broken(map_data, stop)
}
local entities = stop.surface.find_entities(search_area)
for _, entity in pairs(entities) do
if map_data.to_stop[entity.unit_number] == stop then
if entity.valid and map_data.to_stop[entity.unit_number] == stop then
map_data.to_stop[entity.unit_number] = nil
end
end
@@ -307,7 +307,7 @@ local function on_station_rename(map_data, stop)
--search for trains coming to the renamed station
local station_id = stop.unit_number
local station = map_data.stations[station_id]
if station.deliveries_total > 0 then
if station and station.deliveries_total > 0 then
for train_id, train in pairs(map_data.trains) do
local is_p = train.p_station_id == station_id
local is_r = train.r_station_id == station_id
@@ -397,8 +397,9 @@ end
---@param stop LuaEntity
---@param train Train
local function on_train_arrives_buffer(map_data, stop, train)
local station_id = stop.unit_number
if train.manifest then
---@type uint
local station_id = stop.unit_number
if train.status == STATUS_D_TO_P then
if train.p_station_id == station_id then
train.status = STATUS_P
@@ -408,7 +409,7 @@ local function on_train_arrives_buffer(map_data, stop, train)
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.comb1, signals)
set_combinator_output(map_data, station.entity_comb1, signals)
if station.wagon_combs then
for i, entity in ipairs(station.wagon_combs) do
@@ -424,7 +425,7 @@ local function on_train_arrives_buffer(map_data, stop, train)
for i, item in ipairs(train.manifest) do
signals[i] = {index = i, signal = {type = item.type, name = item.name}, count = -1}
end
set_combinator_output(map_data, station.comb1, signals)
set_combinator_output(map_data, station.entity_comb1, signals)
end
else
on_failed_delivery(map_data, train)
@@ -547,7 +548,7 @@ local function on_train_changed(event)
local train = global.trains[train_e.id]
if train_e.state == defines.train_state.wait_station then
local stop = train_e.station
if stop and stop.name == "train-stop" then
if stop and stop.valid and stop.name == "train-stop" then
if global.stations[stop.unit_number] then
on_train_arrives_buffer(global, stop, train)
elseif global.depots[stop.unit_number] then
@@ -573,6 +574,15 @@ local function on_surface_removed(event)
end
end
local function on_paste(event)
local entity = event.destination
if not entity or not entity.valid then return end
if entity.name == COMBINATOR_NAME then
on_combinator_updated(global, entity)
end
end
local filter_built = {
{filter = "type", type = "train-stop"},
@@ -589,6 +599,9 @@ local filter_broken = {
{filter = "type", type = "straight-rail"},
{filter = "rolling-stock"},
}
local filter_comb = {
{filter = "type", type = "arithmetic-combinator"},
}
local function register_events()
--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)
@@ -602,6 +615,8 @@ local function register_events()
flib_event.register({defines.events.on_pre_surface_deleted, defines.events.on_pre_surface_cleared}, on_surface_removed)
flib_event.register(defines.events.on_entity_settings_pasted, on_paste)
local nth_tick = math.ceil(60/mod_settings.tps);
flib_event.on_nth_tick(nth_tick, on_tick)