Первый фикс

Пачки некоторых позиций увеличены
This commit is contained in:
2024-03-01 20:53:32 +03:00
commit 7c9c708c92
23653 changed files with 767936 additions and 0 deletions

View File

@@ -0,0 +1,35 @@
local util = require("scripts.util")
return function(database, metadata)
metadata.beacon_allowed_effects = {}
for name, prototype in pairs(global.prototypes.beacon) do
local size = util.get_size(prototype) --[[@as DisplayResolution]]
database.entity[name] = {
accepted_modules = {},
blueprintable = util.is_blueprintable(prototype),
class = "entity",
distribution_effectivity = prototype.distribution_effectivity,
effect_area = {
height = size.height + (prototype.supply_area_distance * 2),
width = size.width + (prototype.supply_area_distance * 2),
},
energy_usage = prototype.energy_usage,
entity_type = { class = "entity_type", name = prototype.type },
module_slots = prototype.module_inventory_size
and prototype.module_inventory_size > 0
and prototype.module_inventory_size
or nil,
placed_by = util.process_placed_by(prototype),
prototype_name = name,
science_packs = {},
size = size,
unlocked_by = {},
}
util.add_to_dictionary("entity", name, prototype.localised_name)
util.add_to_dictionary("entity_description", name, prototype.localised_description)
metadata.beacon_allowed_effects[name] = prototype.allowed_effects
end
end

View File

@@ -0,0 +1,51 @@
local table = require("__flib__.table")
local constants = require("constants")
return function(database)
-- Compatible fuels / burned in
for _, class in pairs(constants.burner_classes) do
for name, data in pairs(database[class]) do
local can_burn = data.can_burn
if can_burn then
-- Generators might have a fluid defined here already
for _, fuel_ident in pairs(can_burn) do
local fuel_data = database[fuel_ident.class][fuel_ident.name]
fuel_data.burned_in[#fuel_data.burned_in + 1] = { class = class, name = name }
end
local fuel_filter = data.fuel_filter
if fuel_filter then
data.can_burn = { fuel_filter }
data.fuel_filter = nil
local fuel_data = database[fuel_filter.class][fuel_filter.name]
fuel_data.burned_in[#fuel_data.burned_in + 1] = { class = class, name = name }
end
for i, category_ident in pairs(data.fuel_categories or {}) do
local category_data = database.fuel_category[category_ident.name]
if category_data then
-- Add fluids and items to the compatible fuels, and add the object to the material's burned in table
for _, objects in pairs({ category_data.fluids, category_data.items }) do
for _, obj_ident in pairs(objects) do
local obj_data = database[obj_ident.class][obj_ident.name]
obj_data.burned_in[#obj_data.burned_in + 1] = { class = class, name = name }
can_burn[#can_burn + 1] = table.shallow_copy(obj_ident)
end
end
else
-- Remove this category from the entity
table.remove(data.fuel_categories, i)
end
end
end
end
end
-- Burnt results
for item_name, item_data in pairs(database.item) do
local burnt_result = item_data.burnt_result
if burnt_result then
local result_data = database.item[burnt_result.name]
result_data.burnt_result_of[#result_data.burnt_result_of + 1] = { class = "item", name = item_name }
end
end
end

View File

@@ -0,0 +1,108 @@
local util = require("scripts.util")
return function(database, metadata)
-- Characters as crafters
for name, prototype in pairs(global.prototypes.character) do
local ingredient_limit = prototype.ingredient_count
if ingredient_limit == 255 then
ingredient_limit = nil
end
database.entity[name] = {
accepted_modules = {}, -- Always empty
blueprintable = false,
can_burn = {}, -- Always empty
can_craft = {},
class = "entity",
crafting_speed = 1,
enabled = true,
entity_type = { class = "entity_type", name = prototype.type },
hidden = false,
ingredient_limit = ingredient_limit,
is_character = true,
placed_by = util.process_placed_by(prototype),
prototype_name = name,
recipe_categories_lookup = prototype.crafting_categories or {},
recipe_categories = util.convert_categories(prototype.crafting_categories or {}, "recipe_category"),
science_packs = {},
unlocked_by = {},
}
util.add_to_dictionary("entity", name, prototype.localised_name)
util.add_to_dictionary("entity_description", name, prototype.localised_description)
end
-- Actual crafters
metadata.allowed_effects = {}
metadata.crafter_fluidbox_counts = {}
metadata.fixed_recipes = {}
local rocket_silo_categories = util.unique_obj_array()
for name, prototype in pairs(global.prototypes.crafter) do
-- Fixed recipe
local fixed_recipe
if prototype.fixed_recipe then
metadata.fixed_recipes[prototype.fixed_recipe] = true
fixed_recipe = { class = "recipe", name = prototype.fixed_recipe }
end
-- Rocket silo categories
if prototype.rocket_parts_required then
for category in pairs(prototype.crafting_categories) do
table.insert(rocket_silo_categories, { class = "recipe_category", name = category })
end
end
local ingredient_limit = prototype.ingredient_count
if ingredient_limit == 255 then
ingredient_limit = nil
end
metadata.allowed_effects[name] = prototype.allowed_effects
local fluidboxes = prototype.fluidbox_prototypes
if fluidboxes then
local fluidbox_counts = { inputs = 0, outputs = 0 }
for _, fluidbox in pairs(fluidboxes) do
local type = fluidbox.production_type
if string.find(type, "input") then
fluidbox_counts.inputs = fluidbox_counts.inputs + 1
end
if string.find(type, "output") then
fluidbox_counts.outputs = fluidbox_counts.outputs + 1
end
end
metadata.crafter_fluidbox_counts[name] = fluidbox_counts
end
local is_hidden = prototype.has_flag("hidden")
local fuel_categories, fuel_filter = util.process_energy_source(prototype)
database.entity[name] = {
accepted_modules = {},
blueprintable = util.is_blueprintable(prototype),
can_burn = {},
can_craft = {},
class = "entity",
crafting_speed = prototype.crafting_speed,
entity_type = { class = "entity_type", name = prototype.type },
fixed_recipe = fixed_recipe,
fuel_categories = fuel_categories,
fuel_filter = fuel_filter,
hidden = is_hidden,
ingredient_limit = ingredient_limit,
module_slots = prototype.module_inventory_size
and prototype.module_inventory_size > 0
and prototype.module_inventory_size
or nil,
placed_by = util.process_placed_by(prototype),
prototype_name = name,
recipe_categories_lookup = prototype.crafting_categories or {},
recipe_categories = util.convert_categories(prototype.crafting_categories or {}, "recipe_category"),
rocket_parts_required = prototype.rocket_parts_required,
science_packs = {},
size = util.get_size(prototype),
unlocked_by = {},
}
util.add_to_dictionary("entity", name, prototype.localised_name)
util.add_to_dictionary("entity_description", name, prototype.localised_description)
end
metadata.rocket_silo_categories = rocket_silo_categories
end

View File

@@ -0,0 +1,17 @@
return function(database)
for _, entity_data in pairs(database.entity) do
-- Hidden / disabled for entities
if not entity_data.is_character then
local placed_by_len = #(entity_data.placed_by or {})
if placed_by_len == 0 and not entity_data.expected_resources then
entity_data.enabled = false
elseif placed_by_len == 1 then
local item_ident = entity_data.placed_by[1]
local item_data = database.item[item_ident.name]
if item_data.hidden then
entity_data.hidden = true
end
end
end
end
end

View File

@@ -0,0 +1,26 @@
local constants = require("constants")
local util = require("scripts.util")
return function(database)
for class in pairs(constants.prototypes.filtered_entities) do
if class ~= "resource" then
for name, prototype in pairs(global.prototypes[class]) do
local type = prototype.type
local type_data = database.entity_type[type]
if not type_data then
type_data = {
class = "entity_type",
entities = {},
prototype_name = type,
}
database.entity_type[type] = type_data
util.add_to_dictionary("entity_type", type, { "entity-type." .. type })
util.add_to_dictionary("entity_type_description", type, { "entity-type-description." .. type })
end
table.insert(type_data.entities, { class = "entity", name = name })
end
end
end
end

View File

@@ -0,0 +1,70 @@
local table = require("__flib__.table")
local util = require("scripts.util")
return function(database, metadata)
metadata.gathered_from = {}
--- @type table<string, LuaEntityPrototype>
local prototypes = global.prototypes.entity
for name, prototype in pairs(prototypes) do
local equipment_categories = util.unique_obj_array()
local equipment = util.unique_obj_array()
local equipment_grid = prototype.grid_prototype
if equipment_grid then
for _, equipment_category in pairs(equipment_grid.equipment_categories) do
table.insert(equipment_categories, { class = "equipment_category", name = equipment_category })
local category_data = database.equipment_category[equipment_category]
if category_data then
for _, equipment_name in pairs(category_data.equipment) do
table.insert(equipment, equipment_name)
end
end
end
end
local fuel_categories, fuel_filter = util.process_energy_source(prototype)
local expected_resources
local mineable = prototype.mineable_properties
if
mineable
and mineable.minable
and mineable.products
and #mineable.products > 0
and mineable.products[1].name ~= name
then
expected_resources = table.map(mineable.products, function(product)
if not metadata.gathered_from[product.name] then
metadata.gathered_from[product.name] = {}
end
table.insert(metadata.gathered_from[product.name], { class = "entity", name = name })
return { class = product.type, name = product.name, amount_ident = util.build_amount_ident(product) }
end)
end
database.entity[name] = {
accepted_equipment = equipment,
blueprintable = util.is_blueprintable(prototype),
can_burn = {},
class = "entity",
enabled_at_start = expected_resources and true or false, -- FIXME: This is inaccurate
entity_type = { class = "entity_type", name = prototype.type },
equipment_categories = equipment_categories,
expected_resources = expected_resources,
fuel_categories = fuel_categories,
fuel_filter = fuel_filter,
module_slots = prototype.module_inventory_size
and prototype.module_inventory_size > 0
and prototype.module_inventory_size
or nil,
placed_by = util.process_placed_by(prototype),
prototype_name = name,
science_packs = {},
unlocked_by = {},
}
util.add_to_dictionary("entity", name, prototype.localised_name)
util.add_to_dictionary("entity_description", name, prototype.localised_description)
end
end

View File

@@ -0,0 +1,25 @@
local util = require("scripts.util")
local equipment_category_proc = {}
function equipment_category_proc.build(database)
for name, prototype in pairs(global.prototypes.equipment_category) do
database.equipment_category[name] = {
class = "equipment_category",
enabled_at_start = true,
equipment = {},
prototype_name = name,
}
util.add_to_dictionary("equipment_category", name, prototype.localised_name)
util.add_to_dictionary("equipment_category_description", name, prototype.localised_description)
end
end
-- When calling the module directly, call equipment_category_proc.build
setmetatable(equipment_category_proc, {
__call = function(_, ...)
return equipment_category_proc.build(...)
end,
})
return equipment_category_proc

View File

@@ -0,0 +1,87 @@
local table = require("__flib__.table")
local util = require("scripts.util")
local properties_by_type = {
["active-defense-equipment"] = { { "energy_consumption", "energy" } },
["battery-equipment"] = {},
["belt-immunity-equipment"] = { { "energy_consumption", "energy" } },
["energy-shield-equipment"] = {
{ "energy_consumption", "energy" },
{ "shield", "number", "shield_points" },
{ "energy_per_shield", "energy", "energy_per_shield_point" },
},
["generator-equipment"] = { { "energy_production", "energy" } },
["movement-bonus-equipment"] = { { "energy_consumption", "energy" }, { "movement_bonus", "percent" } },
["night-vision-equipment"] = { { "energy_consumption", "energy" } },
["roboport-equipment"] = { { "energy_consumption", "energy" } },
["solar-panel-equipment"] = { { "energy_production", "energy" } },
}
local function get_equipment_property(properties, source, name, formatter, label)
local value = source[name]
if value and value > 0 then
table.insert(properties, {
type = "plain",
label = label or name,
value = value,
formatter = formatter,
})
end
end
return function(database)
--- @type table<string, LuaEquipmentPrototype>
local prototypes = global.prototypes.equipment
for name, prototype in pairs(prototypes) do
local fuel_categories
local burner = prototype.burner_prototype
if burner then
fuel_categories = util.convert_categories(burner.fuel_categories, "fuel_category")
end
for _, category in pairs(prototype.equipment_categories) do
local category_data = database.equipment_category[category]
category_data.equipment[#category_data.equipment + 1] = { class = "equipment", name = name }
end
local equipment_type = prototype.type
local properties = {}
for _, property in pairs(properties_by_type[equipment_type]) do
get_equipment_property(properties, prototype, property[1], property[2], property[3])
end
local energy_source = prototype.energy_source
if energy_source then
get_equipment_property(properties, energy_source, "buffer_capacity", "energy_storage")
end
if equipment_type == "roboport-equipment" then
local logistic_parameters = prototype.logistic_parameters
get_equipment_property(properties, logistic_parameters, "logistic_radius", "number")
get_equipment_property(properties, logistic_parameters, "construction_radius", "number")
get_equipment_property(properties, logistic_parameters, "robot_limit", "number")
get_equipment_property(properties, logistic_parameters, "charging_energy", "energy")
end
database.equipment[name] = {
can_burn = {},
class = "equipment",
enabled = true,
equipment_categories = table.map(prototype.equipment_categories, function(category)
return { class = "equipment_category", name = category }
end),
equipment_properties = properties,
fuel_categories = fuel_categories,
hidden = false,
placed_in = util.unique_obj_array(),
prototype_name = name,
science_packs = {},
size = prototype.shape and prototype.shape.width or nil, -- Equipments can have irregular shapes
take_result = prototype.take_result and { class = "item", name = prototype.take_result.name } or nil,
unlocked_by = {},
}
util.add_to_dictionary("equipment", name, prototype.localised_name)
util.add_to_dictionary("equipment_description", name, prototype.localised_description)
end
end

View File

@@ -0,0 +1,238 @@
local table = require("__flib__.table")
local constants = require("constants")
local util = require("scripts.util")
local fluid_proc = {}
function fluid_proc.build(database, metadata)
local localised_fluids = {}
for name, prototype in pairs(global.prototypes.fluid) do
-- Group
local group = prototype.group
local group_data = database.group[group.name]
group_data.fluids[#group_data.fluids + 1] = { class = "fluid", name = name }
-- Fake fuel category
local fuel_category
if prototype.fuel_value > 0 then
fuel_category = { class = "fuel_category", name = constants.fake_fluid_fuel_category }
local fluids = database.fuel_category[constants.fake_fluid_fuel_category].fluids
fluids[#fluids + 1] = { class = "fluid", name = name }
end
-- Save to recipe book
database.fluid[name] = {
burned_in = {},
class = "fluid",
default_temperature = prototype.default_temperature,
fuel_category = fuel_category,
fuel_pollution = prototype.fuel_value > 0
and prototype.emissions_multiplier ~= 1
and prototype.emissions_multiplier
or nil,
fuel_value = prototype.fuel_value > 0 and prototype.fuel_value or nil,
group = { class = "group", name = group.name },
hidden = prototype.hidden,
ingredient_in = {},
mined_from = {},
product_of = {},
prototype_name = name,
pumped_by = {},
recipe_categories = util.unique_obj_array(),
science_packs = {},
subgroup = { class = "group", name = prototype.subgroup.name },
temperatures = {},
unlocked_by = util.unique_obj_array(),
}
-- Don't add strings yet - they will be added in process_temperatures() to improve the ordering
localised_fluids[name] = { name = prototype.localised_name, description = prototype.localised_description }
end
metadata.localised_fluids = localised_fluids
end
-- Adds a fluid temperature definition if one doesn't exist yet
function fluid_proc.add_temperature(fluid_data, temperature_ident)
local temperature_string = temperature_ident.string
local temperatures = fluid_data.temperatures
if not temperatures[temperature_string] then
temperatures[temperature_string] = {
base_fluid = { class = "fluid", name = fluid_data.prototype_name },
class = "fluid",
default_temperature = fluid_data.default_temperature,
fuel_pollution = fluid_data.fuel_pollution,
fuel_value = fluid_data.fuel_value,
group = fluid_data.group,
hidden = fluid_data.hidden,
ingredient_in = {},
mined_from = {},
name = fluid_data.prototype_name .. "." .. temperature_string,
product_of = {},
prototype_name = fluid_data.prototype_name,
recipe_categories = util.unique_obj_array(),
science_packs = {},
subgroup = fluid_data.subgroup,
temperature_ident = temperature_ident,
unlocked_by = util.unique_obj_array(),
}
end
end
-- Returns true if `comp` is within `base`
function fluid_proc.is_within_range(base, comp, flip)
if flip then
return base.min >= comp.min and base.max <= comp.max
else
return base.min <= comp.min and base.max >= comp.max
end
end
function fluid_proc.process_temperatures(database, metadata)
-- Create a new fluids table so insertion order will neatly organize the temperature variants
local new_fluid_table = {}
for fluid_name, fluid_data in pairs(database.fluid) do
new_fluid_table[fluid_name] = fluid_data
local localised = metadata.localised_fluids[fluid_name]
util.add_to_dictionary("fluid", fluid_name, localised.name)
util.add_to_dictionary("fluid_description", fluid_name, localised.description)
local temperatures = fluid_data.temperatures
if temperatures and next(temperatures) then
-- Step 1: Add a variant for the default temperature if one does not exist
local default_temperature = fluid_data.default_temperature
local default_temperature_ident = util.build_temperature_ident({ temperature = default_temperature })
if not temperatures[default_temperature_ident.string] then
fluid_proc.add_temperature(fluid_data, default_temperature_ident)
end
-- Step 2: Sort the temperature variants
local temp = {}
for _, temperature_data in pairs(temperatures) do
table.insert(temp, temperature_data)
end
table.sort(temp, function(temp_a, temp_b)
return util.get_sorting_number(temp_a.temperature_ident) < util.get_sorting_number(temp_b.temperature_ident)
end)
-- Create a new table and insert in order
temperatures = {}
for _, temperature_data in pairs(temp) do
temperatures[temperature_data.name] = temperature_data
-- Add to database and add translation
new_fluid_table[temperature_data.name] = temperature_data
util.add_to_dictionary("fluid", temperature_data.name, {
"",
localised.name,
" (",
{ "format-degrees-c-compact", temperature_data.temperature_ident.string },
")",
})
end
fluid_data.temperatures = temperatures
-- Step 3: Add researched properties to temperature variants
for _, temperature_data in pairs(temperatures) do
temperature_data.enabled_at_start = fluid_data.enabled_at_start
if fluid_data.researched_forces then
temperature_data.researched_forces = {}
end
end
-- Step 4: Add properties from base fluid to temperature variants
-- TODO: This is an idiotic way to do this
for fluid_tbl_name, obj_table_name in pairs({
ingredient_in = "ingredients",
product_of = "products",
mined_from = "products",
}) do
for _, obj_ident in pairs(fluid_data[fluid_tbl_name]) do
local obj_data = database[obj_ident.class][obj_ident.name]
-- Get the matching fluid
local fluid_ident
-- This is kind of a slow way to do it, but I don't really care
for _, material_ident in pairs(obj_data[obj_table_name]) do
if material_ident.name == fluid_name then
fluid_ident = material_ident
break
end
end
-- Get the temperature identifier from the material table
local temperature_ident = fluid_ident.temperature_ident
if temperature_ident then
-- Change the name of the material and remove the identifier
fluid_ident.name = fluid_ident.name .. "." .. temperature_ident.string
fluid_ident.temperature_ident = nil
elseif obj_table_name == "products" then
-- Change the name of the material to the default temperature
fluid_ident.name = fluid_ident.name .. "." .. default_temperature_ident.string
fluid_ident.temperature_ident = nil
-- Use the default temperature for matching
temperature_ident = default_temperature_ident
end
-- Iterate over all temperature variants and compare their constraints
for _, temperature_data in pairs(temperatures) do
if
not temperature_ident
or fluid_proc.is_within_range(
temperature_data.temperature_ident,
temperature_ident,
fluid_tbl_name == "ingredient_in"
)
then
-- Add to recipes table
temperature_data[fluid_tbl_name][#temperature_data[fluid_tbl_name] + 1] = obj_ident
-- Recipe-specific logic
if obj_ident.class == "recipe" then
-- Add recipe category
local recipe_categories = temperature_data.recipe_categories
recipe_categories[#recipe_categories + 1] = table.shallow_copy(obj_data.recipe_category)
-- If in product_of, append to unlocked_by
-- Also add this fluid to that tech's `unlocks fluids` table
-- This is to avoid variants being "unlocked" when you can't actually get them
-- If this is an "empty X barrel" recipe, ignore it
if fluid_tbl_name == "product_of" and not string.find(obj_ident.name, "^empty%-.+%-barrel$") then
local temp_unlocked_by = temperature_data.unlocked_by
for _, technology_ident in pairs(obj_data.unlocked_by) do
temp_unlocked_by[#temp_unlocked_by + 1] = technology_ident
local technology_data = database.technology[technology_ident.name]
-- Don't use fluid_ident becuase it has an amount
technology_data.unlocks_fluids[#technology_data.unlocks_fluids + 1] = {
class = "fluid",
name = temperature_data.name,
}
end
end
end
end
end
end
end
-- Step 5: If this variant is not produced by anything, unlock with the base fluid
for _, temperature_data in pairs(temperatures) do
if #temperature_data.product_of == 0 and #temperature_data.unlocked_by == 0 then
temperature_data.unlocked_by = table.deep_copy(fluid_data.unlocked_by)
for _, technology_ident in pairs(fluid_data.unlocked_by) do
local technology_data = database.technology[technology_ident.name]
-- Don't use fluid_ident becuase it has an amount
technology_data.unlocks_fluids[#technology_data.unlocks_fluids + 1] = {
class = "fluid",
name = temperature_data.name,
}
end
end
end
end
end
database.fluid = new_fluid_table
end
-- When calling the module directly, call fluid_proc.build
setmetatable(fluid_proc, {
__call = function(_, ...)
return fluid_proc.build(...)
end,
})
return fluid_proc

View File

@@ -0,0 +1,51 @@
local constants = require("constants")
local fake_name = constants.fake_fluid_fuel_category
local util = require("scripts.util")
local fuel_category_proc = {}
function fuel_category_proc.build(database)
-- Add the actual fuel categories
for name, prototype in pairs(global.prototypes.fuel_category) do
database.fuel_category[name] = {
class = "fuel_category",
enabled_at_start = true,
fluids = {}, -- Will always be empty
items = util.unique_obj_array({}),
prototype_name = name,
}
util.add_to_dictionary("fuel_category", name, prototype.localised_name)
util.add_to_dictionary("fuel_category_description", name, prototype.localised_description)
end
-- Add our fake fuel category for fluids
database.fuel_category[fake_name] = {
class = "fuel_category",
enabled_at_start = true,
fluids = util.unique_obj_array({}),
items = {}, -- Will always be empty
prototype_name = fake_name,
}
end
function fuel_category_proc.check_fake_category(database)
local category = database.fuel_category[fake_name]
if #category.fluids > 0 then
-- Add translations
util.add_to_dictionary("fuel_category", fake_name, { "fuel-category-name." .. fake_name })
util.add_to_dictionary("fuel_category_description", fake_name, { "fuel-category-description." .. fake_name })
else
-- Remove the category
database.fuel_category[fake_name] = nil
end
end
-- When calling the module directly, call fuel_category_proc.build
setmetatable(fuel_category_proc, {
__call = function(_, ...)
return fuel_category_proc.build(...)
end,
})
return fuel_category_proc

View File

@@ -0,0 +1,34 @@
local util = require("scripts.util")
return function(database)
for name, prototype in pairs(global.prototypes.generator) do
local fluid_box = prototype.fluidbox_prototypes[1]
local can_burn = {}
local fuel_categories = {}
if fluid_box.filter then
can_burn = { { class = "fluid", name = fluid_box.filter.name } }
else
fuel_categories = { { class = "fuel_category", name = "burnable-fluid" } }
end
database.entity[name] = {
base_pollution = prototype.emissions_per_second > 0 and prototype.emissions_per_second or nil,
blueprintable = util.is_blueprintable(prototype),
can_burn = can_burn,
class = "entity",
entity_type = { class = "entity_type", name = prototype.type },
fluid_consumption = prototype.fluid_usage_per_tick * 60,
fuel_categories = fuel_categories,
max_energy_production = prototype.max_energy_production,
maximum_temperature = prototype.maximum_temperature,
minimum_temperature = fluid_box.minimum_temperature,
placed_by = util.process_placed_by(prototype),
prototype_name = name,
science_packs = {},
unlocked_by = {},
}
util.add_to_dictionary("entity", name, prototype.localised_name)
util.add_to_dictionary("entity_description", name, prototype.localised_description)
end
end

View File

@@ -0,0 +1,16 @@
local util = require("scripts.util")
return function(database)
for name, prototype in pairs(global.prototypes.item_group) do
database.group[name] = {
class = "group",
enabled_at_start = true,
fluids = util.unique_obj_array({}),
items = util.unique_obj_array({}),
prototype_name = name,
recipes = util.unique_obj_array({}),
}
util.add_to_dictionary("group", name, prototype.localised_name)
-- NOTE: Groups do not have descriptions
end
end

View File

@@ -0,0 +1,20 @@
local util = require("scripts.util")
return function(database)
for name, prototype in pairs(global.prototypes.item) do
local type = prototype.type
local type_data = database.item_type[type]
if not type_data then
type_data = {
class = "item_type",
items = {},
prototype_name = type,
}
database.item_type[type] = type_data
util.add_to_dictionary("item_type", type, { "item-type." .. type })
util.add_to_dictionary("item_type_description", type, { "item-type-description." .. type })
end
table.insert(type_data.items, { class = "item", name = name })
end
end

View File

@@ -0,0 +1,210 @@
local table = require("__flib__.table")
local util = require("scripts.util")
local item_proc = {}
function item_proc.build(database, metadata)
local modules = {}
local place_as_equipment_results = {}
local place_results = {}
local rocket_launch_payloads = {}
for name, prototype in pairs(global.prototypes.item) do
-- Group
local group = prototype.group
local group_data = database.group[group.name]
group_data.items[#group_data.items + 1] = { class = "item", name = name }
-- Rocket launch products
local launch_products = {}
for i, product in ipairs(prototype.rocket_launch_products or {}) do
-- Add to products table w/ amount string
local amount_ident = util.build_amount_ident(product)
launch_products[i] = {
class = product.type,
name = product.name,
amount_ident = amount_ident,
}
-- Add to payloads table
local product_payloads = rocket_launch_payloads[product.name]
local ident = { class = "item", name = name }
if product_payloads then
product_payloads[#product_payloads + 1] = ident
else
rocket_launch_payloads[product.name] = { ident }
end
end
local default_categories =
util.unique_string_array(#launch_products > 0 and table.shallow_copy(metadata.rocket_silo_categories) or {})
local place_as_equipment_result = prototype.place_as_equipment_result
if place_as_equipment_result then
place_as_equipment_result = { class = "equipment", name = place_as_equipment_result.name }
place_as_equipment_results[name] = place_as_equipment_result
end
local place_result = prototype.place_result
if place_result and database.entity[place_result.name] then
place_result = { class = "entity", name = place_result.name }
place_results[name] = place_result
else
place_result = nil
end
local burnt_result = prototype.burnt_result
if burnt_result then
burnt_result = { class = "item", name = burnt_result.name }
end
local equipment_categories = util.unique_obj_array()
local equipment = util.unique_obj_array()
local equipment_grid = prototype.equipment_grid
if equipment_grid then
for _, equipment_category in pairs(equipment_grid.equipment_categories) do
table.insert(equipment_categories, { class = "equipment_category", name = equipment_category })
local category_data = database.equipment_category[equipment_category]
if category_data then
for _, equipment_ident in pairs(category_data.equipment) do
table.insert(equipment, equipment_ident)
local equipment_data = database.equipment[equipment_ident.name]
if equipment_data then
equipment_data.placed_in[#equipment_data.placed_in + 1] = { class = "item", name = name }
end
end
end
end
end
local fuel_value = prototype.fuel_value
local has_fuel_value = prototype.fuel_value > 0
local fuel_acceleration_multiplier = prototype.fuel_acceleration_multiplier
local fuel_emissions_multiplier = prototype.fuel_emissions_multiplier
local fuel_top_speed_multiplier = prototype.fuel_top_speed_multiplier
local module_effects = {}
if prototype.type == "module" then
-- Add to internal list of modules
modules[name] = table.invert(prototype.limitations)
-- Process effects
for effect_name, effect in pairs(prototype.module_effects or {}) do
module_effects[#module_effects + 1] = {
type = "plain",
label = effect_name .. "_bonus",
value = effect.bonus,
formatter = "percent",
}
end
-- Process which beacons this module is compatible with
for beacon_name in pairs(global.prototypes.beacon) do
local beacon_data = database.entity[beacon_name]
local allowed_effects = metadata.beacon_allowed_effects[beacon_name]
local compatible = true
if allowed_effects then
for effect_name in pairs(prototype.module_effects or {}) do
if not allowed_effects[effect_name] then
compatible = false
break
end
end
end
if compatible then
beacon_data.accepted_modules[#beacon_data.accepted_modules + 1] = { class = "item", name = name }
end
end
-- Process which crafters this module is compatible with
for crafter_name in pairs(global.prototypes.crafter) do
local crafter_data = database.entity[crafter_name]
local allowed_effects = metadata.allowed_effects[crafter_name]
local compatible = true
if allowed_effects then
for effect_name in pairs(prototype.module_effects or {}) do
if not allowed_effects[effect_name] then
compatible = false
break
end
end
end
if compatible then
crafter_data.accepted_modules[#crafter_data.accepted_modules + 1] = { class = "item", name = name }
end
end
end
local fuel_category = util.convert_to_ident("fuel_category", prototype.fuel_category)
if fuel_category then
local items = database.fuel_category[fuel_category.name].items
items[#items + 1] = { class = "item", name = name }
end
--- @class ItemData
database.item[name] = {
accepted_equipment = equipment,
affects_recipes = {},
burned_in = {},
burnt_result = burnt_result,
burnt_result_of = {},
class = "item",
enabled_at_start = metadata.gathered_from[name] and true or false,
equipment_categories = equipment_categories,
fuel_acceleration_multiplier = has_fuel_value
and fuel_acceleration_multiplier ~= 1
and fuel_acceleration_multiplier
or nil,
fuel_category = fuel_category,
fuel_emissions_multiplier = has_fuel_value and fuel_emissions_multiplier ~= 1 and fuel_emissions_multiplier
or nil,
fuel_top_speed_multiplier = has_fuel_value and fuel_top_speed_multiplier ~= 1 and fuel_top_speed_multiplier
or nil,
fuel_value = has_fuel_value and fuel_value or nil,
gathered_from = metadata.gathered_from[name],
group = { class = "group", name = group.name },
hidden = prototype.has_flag("hidden"),
ingredient_in = {},
item_type = { class = "item_type", name = prototype.type },
mined_from = {},
module_category = util.convert_to_ident("module_category", prototype.category),
module_effects = module_effects,
place_as_equipment_result = place_as_equipment_result,
place_result = place_result,
product_of = {},
prototype_name = name,
recipe_categories = default_categories,
researched_in = {},
rocket_launch_product_of = {},
rocket_launch_products = launch_products,
science_packs = {},
stack_size = prototype.stack_size,
subgroup = { class = "group", name = prototype.subgroup.name },
unlocked_by = util.unique_obj_array(),
}
util.add_to_dictionary("item", name, prototype.localised_name)
util.add_to_dictionary("item_description", name, prototype.localised_description)
end
-- Add rocket launch payloads to their material tables
for product, payloads in pairs(rocket_launch_payloads) do
local product_data = database.item[product]
product_data.rocket_launch_product_of = table.array_copy(payloads)
for i = 1, #payloads do
local payload = payloads[i]
local payload_data = database.item[payload.name]
local payload_unlocked_by = payload_data.unlocked_by
for j = 1, #payload_unlocked_by do
product_data.unlocked_by[#product_data.unlocked_by + 1] = payload_unlocked_by[j]
end
end
end
metadata.modules = modules
metadata.place_as_equipment_results = place_as_equipment_results
metadata.place_results = place_results
end
-- When calling the module directly, call fluid_proc.build
setmetatable(item_proc, {
__call = function(_, ...)
return item_proc.build(...)
end,
})
return item_proc

View File

@@ -0,0 +1,41 @@
local table = require("__flib__.table")
local util = require("scripts.util")
return function(database)
for name, prototype in pairs(global.prototypes.lab) do
-- Add to items
for _, item_name in ipairs(prototype.lab_inputs) do
local item_data = database.item[item_name]
if item_data then
item_data.researched_in[#item_data.researched_in + 1] = { class = "entity", name = name }
end
end
local fuel_categories, fuel_filter = util.process_energy_source(prototype)
database.entity[name] = {
blueprintable = util.is_blueprintable(prototype),
can_burn = {},
class = "entity",
entity_type = { class = "entity_type", name = prototype.type },
fuel_categories = fuel_categories,
fuel_filter = fuel_filter,
hidden = prototype.has_flag("hidden"),
inputs = table.map(prototype.lab_inputs, function(v)
return { class = "item", name = v }
end),
module_slots = prototype.module_inventory_size
and prototype.module_inventory_size > 0
and prototype.module_inventory_size
or nil,
placed_by = util.process_placed_by(prototype),
prototype_name = name,
researching_speed = prototype.researching_speed,
science_packs = {},
size = util.get_size(prototype),
unlocked_by = {},
}
util.add_to_dictionary("entity", name, prototype.localised_name)
util.add_to_dictionary("entity_description", name, prototype.localised_description)
end
end

View File

@@ -0,0 +1,65 @@
local util = require("scripts.util")
local mining_drill_proc = {}
function mining_drill_proc.build(database)
for name, prototype in pairs(global.prototypes.mining_drill) do
for category in pairs(prototype.resource_categories) do
local category_data = database.resource_category[category]
category_data.mining_drills[#category_data.mining_drills + 1] = { class = "entity", name = name }
end
local fuel_categories, fuel_filter = util.process_energy_source(prototype)
database.entity[name] = {
blueprintable = util.is_blueprintable(prototype),
can_burn = {},
class = "entity",
enabled = true,
entity_type = { class = "entity_type", name = prototype.type },
fuel_categories = fuel_categories,
fuel_filter = fuel_filter,
mining_area = math.ceil(prototype.mining_drill_radius * 2),
mining_speed = prototype.mining_speed,
module_slots = prototype.module_inventory_size
and prototype.module_inventory_size > 0
and prototype.module_inventory_size
or nil,
placed_by = util.process_placed_by(prototype),
prototype_name = name,
resource_categories_lookup = prototype.resource_categories,
resource_categories = util.convert_categories(prototype.resource_categories, "resource_category"),
science_packs = {},
size = util.get_size(prototype),
supports_fluid = #prototype.fluidbox_prototypes > 0,
unlocked_by = {},
}
util.add_to_dictionary("entity", name, prototype.localised_name)
util.add_to_dictionary("entity_description", name, prototype.localised_description)
end
end
function mining_drill_proc.add_resources(database)
for name in pairs(global.prototypes.mining_drill) do
local drill_data = database.entity[name]
local can_mine = util.unique_obj_array()
for category in pairs(drill_data.resource_categories_lookup) do
local category_data = database.resource_category[category]
for _, resource_ident in pairs(category_data.resources) do
local resource_data = database.resource[resource_ident.name]
if not resource_data.required_fluid or drill_data.supports_fluid then
can_mine[#can_mine + 1] = resource_ident
end
end
end
drill_data.can_mine = can_mine
end
end
-- When calling the module directly, call fluid_proc.build
setmetatable(mining_drill_proc, {
__call = function(_, ...)
return mining_drill_proc.build(...)
end,
})
return mining_drill_proc

View File

@@ -0,0 +1,53 @@
local util = require("scripts.util")
local offshore_pump_proc = {}
function offshore_pump_proc.build(database)
-- Iterate offshore pumps
for name, prototype in pairs(global.prototypes.offshore_pump) do
-- Add to material
local fluid = prototype.fluid
local fluid_data = database.fluid[fluid.name]
if fluid_data then
fluid_data.pumped_by[#fluid_data.pumped_by + 1] = { class = "entity", name = name }
end
database.entity[name] = {
blueprintable = util.is_blueprintable(prototype),
class = "entity",
enabled = true,
entity_type = { class = "entity_type", name = prototype.type },
fluid = { class = "fluid", name = fluid.name },
hidden = prototype.has_flag("hidden"),
placed_by = util.process_placed_by(prototype),
prototype_name = name,
pumping_speed = prototype.pumping_speed * 60,
science_packs = {},
size = util.get_size(prototype),
unlocked_by = {},
}
util.add_to_dictionary("entity", name, prototype.localised_name)
util.add_to_dictionary("entity_description", name, prototype.localised_description)
end
end
function offshore_pump_proc.check_enabled_at_start(database)
for name in pairs(global.prototypes.offshore_pump) do
local pump_data = database.entity[name]
if not pump_data.researched_forces then
local fluid_data = database.fluid[pump_data.fluid.name]
fluid_data.researched_forces = nil
fluid_data.science_packs = {}
fluid_data.unlocked_by = {}
end
end
end
-- When calling the module directly, call fluid_proc.build
setmetatable(offshore_pump_proc, {
__call = function(_, ...)
return offshore_pump_proc.build(...)
end,
})
return offshore_pump_proc

View File

@@ -0,0 +1,16 @@
local util = require("scripts.util")
return function(database)
for name, prototype in pairs(global.prototypes.recipe_category) do
database.recipe_category[name] = {
class = "recipe_category",
enabled_at_start = true,
fluids = util.unique_obj_array({}),
items = util.unique_obj_array({}),
prototype_name = name,
recipes = util.unique_obj_array({}),
}
util.add_to_dictionary("recipe_category", name, prototype.localised_name)
util.add_to_dictionary("recipe_category_description", name, prototype.localised_description)
end
end

View File

@@ -0,0 +1,126 @@
local math = require("__flib__.math")
local constants = require("constants")
local util = require("scripts.util")
local fluid_proc = require("scripts.database.fluid")
return function(database, metadata)
for name, prototype in pairs(global.prototypes.recipe) do
local category = prototype.category
local group = prototype.group
local enabled_at_start = prototype.enabled
-- Add to recipe category
local category_data = database.recipe_category[category]
category_data.recipes[#category_data.recipes + 1] = { class = "recipe", name = name }
-- Add to group
local group_data = database.group[group.name]
group_data.recipes[#group_data.recipes + 1] = { class = "recipe", name = name }
local data = {
accepted_modules = {},
class = "recipe",
enabled_at_start = enabled_at_start,
energy = prototype.energy,
group = { class = "group", name = group.name },
hidden = prototype.hidden,
made_in = {},
pollution_multiplier = prototype.emissions_multiplier ~= 1 and prototype.emissions_multiplier or nil,
prototype_name = name,
recipe_category = { class = "recipe_category", name = category },
science_packs = {},
subgroup = { class = "group", name = prototype.subgroup.name },
unlocked_by = {},
used_as_fixed_recipe = metadata.fixed_recipes[name],
}
-- Ingredients / products
local fluids = { ingredients = 0, products = 0 }
for lookup_type, io_type in pairs({ ingredient_in = "ingredients", product_of = "products" }) do
local output = {}
for i, material in ipairs(prototype[io_type]) do
local amount_ident = util.build_amount_ident(material)
local material_io_data = {
class = material.type,
name = material.name,
amount_ident = amount_ident,
}
local material_data = database[material.type][material.name]
local lookup_table = material_data[lookup_type]
lookup_table[#lookup_table + 1] = { class = "recipe", name = name }
output[i] = material_io_data
material_data.recipe_categories[#material_data.recipe_categories + 1] = {
class = "recipe_category",
name = category,
}
-- Don't set enabled at start if this is an ignored recipe
local disabled = constants.disabled_categories.recipe_category[category]
if io_type == "products" and (not disabled or disabled ~= 0) then
local subtable = category_data[material.type .. "s"]
subtable[#subtable + 1] = { class = material.type, name = material.name }
if enabled_at_start then
material_data.enabled_at_start = true
end
end
if material.type == "fluid" then
-- Fluid temperatures
local temperature_ident = util.build_temperature_ident(material)
if temperature_ident then
material_io_data.temperature_ident = temperature_ident
fluid_proc.add_temperature(database.fluid[material.name], temperature_ident)
end
-- Add to aggregate
fluids[io_type] = fluids[io_type] + 1
end
end
data[io_type] = output
end
-- Made in
local num_item_ingredients = 0
for _, ingredient in pairs(prototype.ingredients) do
if ingredient.type == "item" then
num_item_ingredients = num_item_ingredients + 1
end
end
for _, crafters in pairs({ global.prototypes.character, global.prototypes.crafter }) do
for crafter_name in pairs(crafters) do
local crafter_data = database.entity[crafter_name]
local fluidbox_counts = metadata.crafter_fluidbox_counts[crafter_name] or { inputs = 0, outputs = 0 }
if
(crafter_data.ingredient_limit or 255) >= num_item_ingredients
and crafter_data.recipe_categories_lookup[category]
and fluidbox_counts.inputs >= fluids.ingredients
and fluidbox_counts.outputs >= fluids.products
then
local crafting_time = math.round(prototype.energy / crafter_data.crafting_speed, 0.01)
data.made_in[#data.made_in + 1] = {
class = "entity",
name = crafter_name,
amount_ident = util.build_amount_ident({ amount = crafting_time, format = "format_seconds_parenthesis" }),
}
crafter_data.can_craft[#crafter_data.can_craft + 1] = { class = "recipe", name = name }
end
end
end
-- Compatible modules
for module_name, module_limitations in pairs(metadata.modules) do
if not next(module_limitations) or module_limitations[name] then
data.accepted_modules[#data.accepted_modules + 1] = { class = "item", name = module_name }
table.insert(database.item[module_name].affects_recipes, { class = "recipe", name = name })
end
end
database.recipe[name] = data
util.add_to_dictionary("recipe", name, prototype.localised_name)
util.add_to_dictionary("recipe_description", name, prototype.localised_description)
end
end

View File

@@ -0,0 +1,15 @@
local util = require("scripts.util")
return function(database)
for name, prototype in pairs(global.prototypes.resource_category) do
database.resource_category[name] = {
class = "resource_category",
enabled_at_start = true,
mining_drills = {},
prototype_name = name,
resources = util.unique_obj_array({}),
}
util.add_to_dictionary("resource_category", name, prototype.localised_name)
util.add_to_dictionary("resource_category_description", name, prototype.localised_description)
end
end

View File

@@ -0,0 +1,79 @@
local fluid_proc = require("scripts.database.fluid")
local util = require("scripts.util")
return function(database)
--- @type LuaCustomTable<string, LuaEntityPrototype>
local prototypes = global.prototypes.resource
for name, prototype in pairs(prototypes) do
local products = prototype.mineable_properties.products
if products then
for _, product in ipairs(products) do
local product_data = database[product.type][product.name]
if product_data then
product_data.mined_from[#product_data.mined_from + 1] = { class = "resource", name = name }
end
end
end
local required_fluid
local mineable_properties = prototype.mineable_properties
if mineable_properties.required_fluid then
required_fluid = {
class = "fluid",
name = mineable_properties.required_fluid,
-- Ten mining operations per amount consumed, so divide by 10 to get the actual number
amount_ident = util.build_amount_ident({ amount = mineable_properties.fluid_amount / 10 }),
}
else
-- TODO: Validate that it's hand-mineable by checking character mineable categories (requires an API addition)
-- Enable resource items that are hand-minable
for _, product in ipairs(mineable_properties.products or {}) do
if product.type == "item" then
local product_data = database[product.type][product.name]
product_data.enabled_at_start = true
end
end
end
local products = {}
for i, product in pairs(mineable_properties.products or {}) do
products[i] = {
class = product.type,
name = product.name,
amount_ident = util.build_amount_ident(product),
}
-- Fluid temperatures
local temperature_ident = product.type == "fluid" and util.build_temperature_ident(product) or nil
if temperature_ident then
products[i].temperature_ident = temperature_ident
fluid_proc.add_temperature(database.fluid[product.name], temperature_ident)
end
end
local mined_by = {}
local resource_category = prototype.resource_category
for drill_name in pairs(global.prototypes.mining_drill) do
local drill_data = database.entity[drill_name]
if
drill_data.resource_categories_lookup[resource_category]
and (not required_fluid or drill_data.supports_fluid)
then
mined_by[#mined_by + 1] = { class = "entity", name = drill_name }
end
end
local resource_category_data = database.resource_category[resource_category]
resource_category_data.resources[#resource_category_data.resources + 1] = { class = "resource", name = name }
database.resource[name] = {
class = "resource",
mined_by = mined_by,
mining_time = mineable_properties.mining_time,
products = products,
prototype_name = name,
resource_category = { class = "resource_category", name = resource_category },
required_fluid = required_fluid,
}
util.add_to_dictionary("resource", name, prototype.localised_name)
util.add_to_dictionary("resource_description", name, prototype.localised_description)
end
end

View File

@@ -0,0 +1,17 @@
local util = require("scripts.util")
return function(database)
--- @type table<string, LuaItemPrototype>
local prototypes = global.prototypes.item
for name, prototype in pairs(prototypes) do
if prototype.type == "tool" then
database.science_pack[name] = {
class = "science_pack",
order = prototype.order,
prototype_name = name,
}
util.add_to_dictionary("science_pack", name, prototype.localised_name)
util.add_to_dictionary("science_pack_description", name, prototype.localised_description)
end
end
end

View File

@@ -0,0 +1,180 @@
local math = require("__flib__.math")
local table = require("__flib__.table")
local constants = require("constants")
local util = require("scripts.util")
local function insert_science_packs(database, obj_data, science_packs)
if #science_packs == 0 then
return
end
local existing = obj_data.science_packs
local existing_len = #existing
-- If there are no existing science packs
if #obj_data.science_packs == 0 then
obj_data.science_packs = science_packs
return
end
local existing_highest_ident = existing[existing_len]
local existing_highest_data = database.science_pack[existing_highest_ident.name]
local new_highest_ident = science_packs[#science_packs]
local new_highest_data = database.science_pack[new_highest_ident.name]
-- The object should show when the fewest possible science packs are enabled
if existing_highest_data.order > new_highest_data.order then
obj_data.science_packs = science_packs
end
end
return function(database, metadata)
for name, prototype in pairs(global.prototypes.technology) do
local unlocks_equipment = util.unique_obj_array()
local unlocks_fluids = util.unique_obj_array()
local unlocks_items = util.unique_obj_array()
local unlocks_entities = util.unique_obj_array()
local unlocks_recipes = util.unique_obj_array()
local research_ingredients_per_unit = {}
-- Research units and ingredients per unit
for _, ingredient in ipairs(prototype.research_unit_ingredients) do
research_ingredients_per_unit[#research_ingredients_per_unit + 1] = {
class = ingredient.type,
name = ingredient.name,
amount_ident = util.build_amount_ident({ amount = ingredient.amount }),
}
end
local research_unit_count
local formula = prototype.research_unit_count_formula
if not formula then
research_unit_count = prototype.research_unit_count
end
local science_packs = table.map(prototype.research_unit_ingredients, function(pack)
return { class = "science_pack", name = pack.name }
end)
-- Unlocks recipes, materials, entities
for _, modifier in ipairs(prototype.effects) do
if modifier.type == "unlock-recipe" then
local recipe_data = database.recipe[modifier.recipe]
-- Check if the category should be ignored for recipe availability
local disabled = constants.disabled_categories.recipe_category[recipe_data.recipe_category.name]
if not disabled or disabled ~= 0 then
insert_science_packs(database, recipe_data, science_packs)
recipe_data.unlocked_by[#recipe_data.unlocked_by + 1] = { class = "technology", name = name }
recipe_data.researched_forces = {}
unlocks_recipes[#unlocks_recipes + 1] = { class = "recipe", name = modifier.recipe }
for _, product in pairs(recipe_data.products) do
local product_name = product.name
local product_data = database[product.class][product_name]
local product_ident = { class = product_data.class, name = product_data.prototype_name }
-- For "empty X barrel" recipes, do not unlock the fluid with the recipe
-- This is to avoid fluids getting "unlocked" when they are in reality still 100 hours away
local is_empty_barrel_recipe = string.find(modifier.recipe, "^empty%-.+%-barrel$")
if product_data.class ~= "fluid" or not is_empty_barrel_recipe then
product_data.researched_forces = {}
insert_science_packs(database, product_data, science_packs)
product_data.unlocked_by[#product_data.unlocked_by + 1] = { class = "technology", name = name }
end
-- Materials
if product_data.class == "item" then
unlocks_items[#unlocks_items + 1] = product_ident
elseif product_data.class == "fluid" and not is_empty_barrel_recipe then
unlocks_fluids[#unlocks_fluids + 1] = product_ident
end
-- Entities
local place_result = metadata.place_results[product_name]
if place_result then
local entity_data = database.entity[place_result.name]
if entity_data then
entity_data.researched_forces = {}
insert_science_packs(database, entity_data, science_packs)
entity_data.unlocked_by[#entity_data.unlocked_by + 1] = { class = "technology", name = name }
unlocks_entities[#unlocks_entities + 1] = place_result
end
end
-- Equipment
local place_as_equipment_result = metadata.place_as_equipment_results[product_name]
if place_as_equipment_result then
local equipment_data = database.equipment[place_as_equipment_result.name]
if equipment_data then
equipment_data.researched_forces = {}
insert_science_packs(database, equipment_data, science_packs)
equipment_data.unlocked_by[#equipment_data.unlocked_by + 1] = { class = "technology", name = name }
unlocks_equipment[#unlocks_equipment + 1] = place_as_equipment_result
end
end
end
end
end
end
local level = prototype.level
local max_level = prototype.max_level
database.technology[name] = {
class = "technology",
hidden = prototype.hidden,
max_level = max_level,
min_level = level,
prerequisite_of = {},
prerequisites = {},
prototype_name = name,
researched_forces = {},
research_ingredients_per_unit = research_ingredients_per_unit,
research_unit_count_formula = formula,
research_unit_count = research_unit_count,
research_unit_energy = prototype.research_unit_energy / 60,
science_packs = science_packs,
unlocks_entities = unlocks_entities,
unlocks_equipment = unlocks_equipment,
unlocks_fluids = unlocks_fluids,
unlocks_items = unlocks_items,
unlocks_recipes = unlocks_recipes,
upgrade = prototype.upgrade,
}
-- Assemble name
local localised_name
if level ~= max_level then
localised_name = {
"",
prototype.localised_name,
" (" .. level .. "-" .. (max_level == math.max_uint and "" or max_level) .. ")",
}
else
localised_name = prototype.localised_name
end
util.add_to_dictionary("technology", prototype.name, localised_name)
util.add_to_dictionary("technology_description", name, prototype.localised_description)
end
-- Generate prerequisites and prerequisite_of
for name, technology in pairs(database.technology) do
local prototype = global.prototypes.technology[name]
if prototype.prerequisites then
for prerequisite_name in pairs(prototype.prerequisites) do
technology.prerequisites[#technology.prerequisites + 1] = { class = "technology", name = prerequisite_name }
local prerequisite_data = database.technology[prerequisite_name]
prerequisite_data.prerequisite_of[#prerequisite_data.prerequisite_of + 1] = {
class = "technology",
name = name,
}
end
end
end
end