Code: Select all
function create_Tech(level, parent_name, linear, exponent)
--some name calculation
local post = "-" .. (level-1)
local new_post = "-" .. level
parent_name = parent_name .. post
local base_tech = data.raw["technology"][parent_name]
if base_tech == nil then
error(serpent.block("Could not create level " .. level .. " of tech, parent '" .. parent_name .. "' does not exist.")) --equivalent to 'throw new RuntimeException(sg)', since print, aka System.out.println(sg), does not work
end
local idx = base_tech.name:match'^.*()-' --equivalent to 'lastIndexOf('-')'
local new_name = string.sub(base_tech.name, 1, idx-1) .. new_post --equivalent to 'base_tech.substring(0, idx-1)'
-- if tech exists (eg a mod) do not override it
if data.raw["technology"][new_name] then
return nil
end
--actual tech
local result =
{
type = "technology",
name = new_name,
icon = base_tech.icon,
effects = base_tech.effects,
prerequisites = base_tech,
unit =
{
ingredients = base_tech.unit.ingredients,
time = math.floor(base_tech.unit.time*(1+(exponent-1)/4)),
count = math.floor(base_tech.unit.count*exponent+linear),
},
upgrade = true,
order = "e-p-b-c"
}
--debug line
--error(serpent.block("Created tech level " .. level .. ", name = " .. new_name))
print("Created tech level " .. level .. ", name = " .. new_name .. ": ") --only prints if run from command line
return result
end
-- require("functions")
local max = 25--1000--50
for i=21,max do
local tech = create_Tech(i, "follower-robot-count", 200, 1)
if tech ~= nil then
data:extend(
{
tech
})
end
end
for i=5,max do
local tech = create_Tech(i, "research-effectivity", 0, 2)
if tech ~= nil then
data:extend(
{
tech
})
end
end
for i=5,max do
local tech = create_Tech(i, "inserter-stack-size-bonus", 100, 1.1)
if tech ~= nil then
data:extend(
{
tech
})
end
end
for i=6,max do
local tech = create_Tech(i, "logistic-robot-speed", 250, 2)
if tech ~= nil then
data:extend(
{
tech
})
end
end
for i=4,max do
local tech = create_Tech(i, "logistic-robot-storage", 150, 1.25)
if tech ~= nil then
data:extend(
{
tech
})
end
end
for i=6,max do
local tech = create_Tech(i, "character-logistic-slots", 100, 2.5)
if tech ~= nil then
data:extend(
{
tech
})
end
end