--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/no-productivity-modules/data-final-fixes.lua Wed Aug 27 10:26:12 2025 +0300 @@ -0,0 +1,184 @@ +---@param technology data.TechnologyPrototype +---@param x string +function remove_recipe_effect(technology, x) + ---@type (data.Modifier)[] + local list2 = {} + for k, v in pairs(technology.effects or {}) + do + if v.type ~= "unlock-recipe" or v.recipe ~= x + then + table.insert(list2, v) + end + end + technology.effects = list2 +end + +---@param technology data.TechnologyPrototype +---@param x data.Modifier +function remove_effect(technology, x) + ---@type (data.Modifier)[] + local list2 = {} + for _, technology_effect in pairs(technology.effects or {}) + do + local match = true + for key, value in pairs(x) + do + if technology_effect[key] ~= value + then + match = false + break + end + end + if not match + then + table.insert(list2, technology_effect) + end + end + technology.effects = list2 +end + +---@param technology data.TechnologyPrototype +---@param x string +function remove_prerequisite(technology, x) + if technology.prerequisites + then + local new_prerequisites = {} + local changed = false + for k, v in pairs(technology.prerequisites) + do + if v == x + then + changed = true + else + table.insert(new_prerequisites, v) + end + end + if changed + then + technology.prerequisites = new_prerequisites + end + end +end + +---@param recipe data.RecipePrototype +---@param ingredient_to_remove string +local function remove_ingredient(recipe, ingredient_to_remove) + local changed = false + local new_ingredients = {} + for _, ingredient in pairs(recipe.ingredients or {}) + do + if ingredient.name == ingredient_to_remove + then + changed = true + else + table.insert(new_ingredients, ingredient) + end + end + if changed + then + recipe.ingredients = new_ingredients + end +end + +local removed_technologies = {} + +---@param recipe data.RecipePrototype +local function recipe_results_in(recipe, x) + for _, result in pairs(recipe.results or {}) + do + if result.name == x + then + return true + end + end + return false +end + +---@param effect_name string +---@param effect_value number +local function is_effect_banned(effect_name, effect_value) + if effect_name == "consumption" + then + if effect_value > 0 + then + return settings.startup["banned-module-effect-consumption-increase"].value + else + return settings.startup["banned-module-effect-consumption-decrease"].value + end + else + return settings.startup["banned-module-effect-"..effect_name].value + end +end + +for _, module in pairs(data.raw["module"]) +do + local new_effects = {} + local changed = false + local empty = true + for effect_name, effect_value in pairs(module.effect) + do + if is_effect_banned(effect_name, effect_value) + then + changed = true + else + new_effects[effect_name] = effect_value + empty = false + end + end + if changed + then + if not empty + then + module.effect = new_effects + else + data.raw["module"][module.name].hidden = true + for _, technology in pairs(data.raw["technology"]) + do + if technology.effects + then + remove_recipe_effect(technology, module.name) + if #technology.effects == 0 + then + technology.hidden = true + log("Npm: removed technology "..technology.name) + table.insert(removed_technologies, technology.name) + end + end + end + for _, recipe in pairs(data.raw["recipe"]) + do + if recipe_results_in(recipe, module.name) + then + recipe.hidden = true + end + remove_ingredient(recipe, module.name) + end + end + end +end + +if settings.startup["banned-module-effect-quality"].value +then + ---@type data.UnlockQualityModifier + local unlock_uncommon = {type = "unlock-quality", quality = "uncommon"} + ---@type data.UnlockQualityModifier + local unlock_rare = {type = "unlock-quality", quality = "rare"} + if mods["quality"] + then + remove_effect(data.raw["technology"]["quality-module"], unlock_uncommon) + remove_effect(data.raw["technology"]["quality-module"], unlock_rare) + end + if mods["promethium-quality"] + then + table.insert(data.raw["technology"]["refinery"].effects, unlock_uncommon) + table.insert(data.raw["technology"]["refinery"].effects, unlock_rare) + end +end + +for _, technology in pairs(data.raw["technology"]) +do + for _, removed_tech in pairs(removed_technologies) + do + remove_prerequisite(technology, removed_tech) + end +end \ No newline at end of file