This commit is contained in:
Brevven 2022-12-23 17:15:48 -08:00
parent 11e74fbdc4
commit ba19e1546b

View file

@ -1,6 +1,7 @@
-- WARNING WARNING WARNING
-- This file will be overwritten in mod zipfiles, edit bzlib/data-util.lua
-- WARNING WARNING WARNING
--
local me = require("me")
local util = {}
@ -234,6 +235,18 @@ function util.se_matter(params)
end
end
-- Get the normal prototype for a recipe -- either .normal or the recipe itself
function util.get_normal(recipe_name)
if data.raw.recipe[recipe_name] then
recipe = data.raw.recipe[recipe_name]
if recipe.normal and recipe.normal.ingredients then
return recipe.normal
elseif recipe.ingredients then
return recipe
end
end
end
-- Set/override a technology's prerequisites
function util.set_prerequisite(technology_name, prerequisites)
local technology = data.raw.technology[technology_name]
@ -1149,4 +1162,36 @@ function util.add_unlock_force(technology_name, recipe)
util.add_unlock(technology_name, recipe)
end
-- sum the products of a recipe
function util.sum_products(recipe_name)
-- this is going to end up approximate in some cases, integer division is probs fine
if data.raw.recipe[recipe_name] then
local recipe = data.raw.recipe[recipe_name]
if not recipe.results then return recipe.result_count end
local sum = 0
for i, result in pairs(recipe.results) do
local amt = 0
if result[2] then amt = result[2]
elseif result.amount then amt = result.amount
elseif result.amount_min then amt = (result.amount_min + result.amount_max)/2
end
if result.probability then amt = amt * result.probability end
sum = sum + amt
end
return sum
end
return 0
end
function util.set_vtk_dcm_ingredients()
if mods["vtk-deep-core-mining"] then
local sum = util.sum_products("vtk-deepcore-mining-ore-chunk-refining")
log("setting vtk deepcore based on " .. serpent.dump(sum) .. " to " ..serpent.dump(sum*0.8))
util.set_ingredient("vtk-deepcore-mining-ore-chunk-refining", "vtk-deepcore-mining-ore-chunk", sum * 0.8)
local sum = 1+util.sum_products("vtk-deepcore-mining-ore-chunk-refining-no-uranium")
log("setting vtk deepcore no uranium to " .. serpent.dump(sum))
util.set_ingredient("vtk-deepcore-mining-ore-chunk-refining-no-uranium", "vtk-deepcore-mining-ore-chunk", sum)
end
end
return util