Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix belt (backup) detection #5

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
49 changes: 33 additions & 16 deletions prototypes/technology/belts.lua
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,22 @@ for _, belt in pairs(data.raw["transport-belt"]) do
belt_names[belt.name] = true
end

print(serpent.line(belt_names))
-- Create an ordering of the belts by speed
-- to be used in the backup code
local belts_by_speed = {}
for belt_name, _ in pairs(belt_names) do
belts_by_speed[#belts_by_speed+1] = belt_name
end
local ordering = function (b1, b2)
return data.raw["transport-belt"][b1].speed < data.raw["transport-belt"][b2].speed
end
table.sort(belts_by_speed, ordering)


for _, tech in pairs(data.raw["technology"]) do
if tech.effects then
for _, effect in pairs(tech.effects) do
if effect.type == "unlock-recipe" then
if effect.type == "unlock-recipe" and data.raw.recipe[effect.recipe] then
local has_recipe = ""
-- the single recipe result is a string and it is the name of the belt
local result_name = data.raw.recipe[effect.recipe].result
Expand Down Expand Up @@ -65,29 +75,36 @@ for _, tech in pairs(data.raw["technology"]) do
end


-- for the remaining techs, we need to add the belts as level 0 techs, EXCEPT for the slowest one
local slowest_belt = nil
-- For belt types where we do not have a natural parent technology we
-- create a separate level 0 technology. Two special cases:
-- 1. We start with external connections using the slowest belt tech,
-- so no technology upgrading to this level is added.
-- 2. For the upgrade to the first tier there is no prerequisite, as we
-- do not know about a technology unlocking the belt itself, nor is
-- there a technology that upgrades the external connection to the
-- previous belt tier (as that is the starting tier)
for belt_name, _ in pairs(belt_names) do
if slowest_belt == nil then
slowest_belt = belt_name
else
if data.raw["transport-belt"][belt_name].speed < data.raw["transport-belt"][belt_name].speed then
slowest_belt = belt_name
end
-- Find speed index
local index = nil
for i, v in ipairs(belts_by_speed) do
if v == belt_name then index = i end
end
end

-- now for the remaining belts, add them as level 0 techs
for belt_name in pairs(belt_names) do
if belt_name ~= slowest_belt then
if index > 1 then -- Skip slowest belt
log("Adding tech for " .. belt_name)
prerequisites = {}
if index > 2 then
-- There is a tech upgrading to 1 tier lower belts
local prev_belt_name = belts_by_speed[index-1]
prerequisites = {"f2pl-belt-" .. prev_belt_name}
end
local item = data.raw.item[belt_name]
data:extend { {
type = "technology",
name = "f2pl-belt-" .. belt_name,
icon = item.icon,
icon_size = item.icon_size,
icon_mipmaps = item.icon_mipmaps,
prerequisites = { "f2pl-belt-" .. slowest_belt },
prerequisites = prerequisites,
unit = {
count = 100,
ingredients = { { "automation-science-pack", 1 } },
Expand Down