Wed, 27 Aug 2025 10:26:12 +0300
Lots of stuff
19 | 1 | ---@param technology data.TechnologyPrototype |
2 | ---@param x string | |
3 | function remove_recipe_effect(technology, x) | |
4 | ---@type (data.Modifier)[] | |
5 | local list2 = {} | |
6 | for k, v in pairs(technology.effects or {}) | |
7 | do | |
8 | if v.type ~= "unlock-recipe" or v.recipe ~= x | |
9 | then | |
10 | table.insert(list2, v) | |
11 | end | |
12 | end | |
13 | technology.effects = list2 | |
14 | end | |
15 | ||
16 | ---@param technology data.TechnologyPrototype | |
17 | ---@param x data.Modifier | |
18 | function remove_effect(technology, x) | |
19 | ---@type (data.Modifier)[] | |
20 | local list2 = {} | |
21 | for _, technology_effect in pairs(technology.effects or {}) | |
22 | do | |
23 | local match = true | |
24 | for key, value in pairs(x) | |
25 | do | |
26 | if technology_effect[key] ~= value | |
27 | then | |
28 | match = false | |
29 | break | |
30 | end | |
31 | end | |
32 | if not match | |
33 | then | |
34 | table.insert(list2, technology_effect) | |
35 | end | |
36 | end | |
37 | technology.effects = list2 | |
38 | end | |
39 | ||
40 | ---@param technology data.TechnologyPrototype | |
41 | ---@param x string | |
42 | function remove_prerequisite(technology, x) | |
43 | if technology.prerequisites | |
44 | then | |
45 | local new_prerequisites = {} | |
46 | local changed = false | |
47 | for k, v in pairs(technology.prerequisites) | |
48 | do | |
49 | if v == x | |
50 | then | |
51 | changed = true | |
52 | else | |
53 | table.insert(new_prerequisites, v) | |
54 | end | |
55 | end | |
56 | if changed | |
57 | then | |
58 | technology.prerequisites = new_prerequisites | |
59 | end | |
60 | end | |
61 | end | |
62 | ||
63 | ---@param recipe data.RecipePrototype | |
64 | ---@param ingredient_to_remove string | |
65 | local function remove_ingredient(recipe, ingredient_to_remove) | |
66 | local changed = false | |
67 | local new_ingredients = {} | |
68 | for _, ingredient in pairs(recipe.ingredients or {}) | |
69 | do | |
70 | if ingredient.name == ingredient_to_remove | |
71 | then | |
72 | changed = true | |
73 | else | |
74 | table.insert(new_ingredients, ingredient) | |
75 | end | |
76 | end | |
77 | if changed | |
78 | then | |
79 | recipe.ingredients = new_ingredients | |
80 | end | |
81 | end | |
82 | ||
83 | local removed_technologies = {} | |
84 | ||
85 | ---@param recipe data.RecipePrototype | |
86 | local function recipe_results_in(recipe, x) | |
87 | for _, result in pairs(recipe.results or {}) | |
88 | do | |
89 | if result.name == x | |
90 | then | |
91 | return true | |
92 | end | |
93 | end | |
94 | return false | |
95 | end | |
96 | ||
97 | ---@param effect_name string | |
98 | ---@param effect_value number | |
99 | local function is_effect_banned(effect_name, effect_value) | |
100 | if effect_name == "consumption" | |
101 | then | |
102 | if effect_value > 0 | |
103 | then | |
104 | return settings.startup["banned-module-effect-consumption-increase"].value | |
105 | else | |
106 | return settings.startup["banned-module-effect-consumption-decrease"].value | |
107 | end | |
108 | else | |
109 | return settings.startup["banned-module-effect-"..effect_name].value | |
110 | end | |
111 | end | |
112 | ||
113 | for _, module in pairs(data.raw["module"]) | |
114 | do | |
115 | local new_effects = {} | |
116 | local changed = false | |
117 | local empty = true | |
118 | for effect_name, effect_value in pairs(module.effect) | |
119 | do | |
120 | if is_effect_banned(effect_name, effect_value) | |
121 | then | |
122 | changed = true | |
123 | else | |
124 | new_effects[effect_name] = effect_value | |
125 | empty = false | |
126 | end | |
127 | end | |
128 | if changed | |
129 | then | |
130 | if not empty | |
131 | then | |
132 | module.effect = new_effects | |
133 | else | |
134 | data.raw["module"][module.name].hidden = true | |
135 | for _, technology in pairs(data.raw["technology"]) | |
136 | do | |
137 | if technology.effects | |
138 | then | |
139 | remove_recipe_effect(technology, module.name) | |
140 | if #technology.effects == 0 | |
141 | then | |
142 | technology.hidden = true | |
143 | log("Npm: removed technology "..technology.name) | |
144 | table.insert(removed_technologies, technology.name) | |
145 | end | |
146 | end | |
147 | end | |
148 | for _, recipe in pairs(data.raw["recipe"]) | |
149 | do | |
150 | if recipe_results_in(recipe, module.name) | |
151 | then | |
152 | recipe.hidden = true | |
153 | end | |
154 | remove_ingredient(recipe, module.name) | |
155 | end | |
156 | end | |
157 | end | |
158 | end | |
159 | ||
160 | if settings.startup["banned-module-effect-quality"].value | |
161 | then | |
162 | ---@type data.UnlockQualityModifier | |
163 | local unlock_uncommon = {type = "unlock-quality", quality = "uncommon"} | |
164 | ---@type data.UnlockQualityModifier | |
165 | local unlock_rare = {type = "unlock-quality", quality = "rare"} | |
166 | if mods["quality"] | |
167 | then | |
168 | remove_effect(data.raw["technology"]["quality-module"], unlock_uncommon) | |
169 | remove_effect(data.raw["technology"]["quality-module"], unlock_rare) | |
170 | end | |
171 | if mods["promethium-quality"] | |
172 | then | |
173 | table.insert(data.raw["technology"]["refinery"].effects, unlock_uncommon) | |
174 | table.insert(data.raw["technology"]["refinery"].effects, unlock_rare) | |
175 | end | |
176 | end | |
177 | ||
178 | for _, technology in pairs(data.raw["technology"]) | |
179 | do | |
180 | for _, removed_tech in pairs(removed_technologies) | |
181 | do | |
182 | remove_prerequisite(technology, removed_tech) | |
183 | end | |
184 | end |