-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdata-final-fixes.lua
More file actions
217 lines (188 loc) · 8.88 KB
/
data-final-fixes.lua
File metadata and controls
217 lines (188 loc) · 8.88 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
-- This file runs in the settings-final-fixes phase to update recipes based on mod settings
-- Get setting values
local linear_scaling = settings.startup["science-conversion-linear-scaling"].value
local upgrade_base = settings.startup["science-conversion-upgrade-base-ratio"].value
local downgrade_base = settings.startup["science-conversion-downgrade-base-ratio"].value
local product_mult = settings.startup["science-conversion-product-multiplier"].value
local energy_time = settings.startup["science-conversion-energy-time"].value
local pollution_mult = settings.startup["science-conversion-pollution-multiplier"].value
-- Get bidirectional toggle settings
local upgrades_enabled = settings.startup["science-conversion-enable-upgrades"].value
local downgrades_enabled = settings.startup["science-conversion-enable-downgrades"].value
-- Get tier enable/disable settings
local tier_enabled = {
[1] = settings.startup["science-conversion-enable-tier-1"].value, -- Red <-> Green
[2] = settings.startup["science-conversion-enable-tier-2"].value, -- Green <-> Blue
[3] = settings.startup["science-conversion-enable-tier-3"].value, -- Blue <-> Purple
[4] = settings.startup["science-conversion-enable-tier-4"].value, -- Purple <-> Yellow
[5] = settings.startup["science-conversion-enable-tier-5"].value, -- White <-> Orange
[6] = settings.startup["science-conversion-enable-tier-6"].value, -- White <-> Pink
[7] = settings.startup["science-conversion-enable-tier-7"].value, -- White <-> Lime
[8] = settings.startup["science-conversion-enable-tier-8"].value, -- White <-> Dark Blue
[9] = settings.startup["science-conversion-enable-tier-9"].value -- White <-> Black
}
-- Define the science tier hierarchy and their multipliers for linear scaling
-- Tier 1: Red (automation), Tier 2: Green (logistic), Tier 3: Blue (chemical)
-- Tier 4: Purple (production), Tier 5: Yellow (utility), Tier 6: White (space)
-- Tier 7: Orange/Pink/Lime/Dark-blue (planet sciences), Tier 8: Black (promethium)
-- Base game conversion data (always available)
local base_conversion_data = {
-- Format: {recipe_name, tier_difference, is_upgrade, tier_number, technology_name}
-- Tier 1: Red <-> Green
{"red-to-green", 1, true, 1, "science-conversion-one"},
{"green-to-red", 1, false, 1, "science-conversion-one"},
-- Tier 2: Green <-> Blue
{"green-to-blue", 1, true, 2, "science-conversion-two"},
{"blue-to-green", 1, false, 2, "science-conversion-two"},
-- Tier 3: Blue <-> Purple
{"blue-to-purple", 1, true, 3, "science-conversion-three"},
{"purple-to-blue", 1, false, 3, "science-conversion-three"},
-- Tier 4: Purple <-> Yellow
{"purple-to-yellow", 1, true, 4, "science-conversion-four"},
{"yellow-to-purple", 1, false, 4, "science-conversion-four"}
}
-- Space Age conversion data (only if Space Age is installed)
local space_age_conversion_data = {
-- Tier 5: White <-> Orange
{"white-to-orange", 1, true, 5, "science-conversion-five"},
{"orange-to-white", 1, false, 5, "science-conversion-five"},
-- Tier 6: White <-> Pink
{"white-to-pink", 1, true, 6, "science-conversion-six"},
{"pink-to-white", 1, false, 6, "science-conversion-six"},
-- Tier 7: White <-> Lime
{"white-to-lime", 1, true, 7, "science-conversion-seven"},
{"lime-to-white", 1, false, 7, "science-conversion-seven"},
-- Tier 8: White <-> Dark Blue
{"white-to-dark-blue", 1, true, 8, "science-conversion-eight"},
{"dark-blue-to-white", 1, false, 8, "science-conversion-eight"},
-- Tier 9: White <-> Black
{"white-to-black", 2, true, 9, "science-conversion-nine"},
{"black-to-white", 2, false, 9, "science-conversion-nine"}
}
-- Combine conversion data based on available mods
local conversion_data = {}
for _, v in pairs(base_conversion_data) do
table.insert(conversion_data, v)
end
if mods["space-age"] then
for _, v in pairs(space_age_conversion_data) do
table.insert(conversion_data, v)
end
end
-- Function to calculate ingredient amount based on settings
local function calculate_ingredient_amount(tier_diff, is_upgrade)
if is_upgrade then
if linear_scaling then
-- Linear scaling: multiply base by tier difference and a scaling factor
-- Original: 10, 20, 30, 50, 100 (roughly 10 * tier_position)
-- We'll use tier_diff to scale: tier 1->2 = 10, 2->3 = 20, 3->4 = 30, etc.
local scale_factor = tier_diff
if tier_diff == 2 then
scale_factor = 10 -- For white-to-black (special case, was 100)
end
return upgrade_base * scale_factor
else
-- Uniform: same ratio for all upgrades
return upgrade_base
end
else
-- Downgrade always uses the downgrade base ratio
return downgrade_base
end
end
-- Update all conversion recipes
for _, conversion in pairs(conversion_data) do
local recipe_name = conversion[1]
local tier_diff = conversion[2]
local is_upgrade = conversion[3]
local tier_number = conversion[4]
local tech_name = conversion[5]
local recipe = data.raw.recipe[recipe_name]
local technology = data.raw.technology[tech_name]
-- Check if this tier is enabled AND if the direction (upgrade/downgrade) is enabled
local direction_enabled = (is_upgrade and upgrades_enabled) or (not is_upgrade and downgrades_enabled)
local should_enable = tier_enabled[tier_number] and direction_enabled
if should_enable then
-- Tier and direction are enabled - update recipe with settings
if recipe then
-- Calculate ingredient amount
local ingredient_amount = calculate_ingredient_amount(tier_diff, is_upgrade)
-- Update recipe
recipe.energy_required = energy_time
recipe.ingredients = {
{type = "item", name = recipe.ingredients[1].name, amount = ingredient_amount}
}
recipe.results = {
{type = "item", name = recipe.results[1].name, amount = product_mult}
}
-- Set pollution multiplier (0 = no pollution, 1 = normal, >1 = more pollution)
if pollution_mult > 0 then
recipe.emissions_multiplier = pollution_mult
else
-- Setting to 0 means no pollution
recipe.emissions_multiplier = 0
end
end
else
-- Tier or direction is disabled - disable the recipe and remove from technology
if recipe then
recipe.enabled = false
recipe.hidden = true
end
-- Remove recipe unlock from technology
if technology and technology.effects then
local new_effects = {}
for _, effect in pairs(technology.effects) do
if not (effect.type == "unlock-recipe" and effect.recipe == recipe_name) then
table.insert(new_effects, effect)
end
end
technology.effects = new_effects
-- If technology has no effects left, hide it
if #technology.effects == 0 then
technology.hidden = true
technology.enabled = false
end
end
end
end
-- Special handling for linear scaling with more granular tier differences
if linear_scaling then
-- Base game special scaling
local base_special_scaling = {
["red-to-green"] = {scale = 1, tier = 1}, -- 10 * 1 = 10
["green-to-blue"] = {scale = 2, tier = 2}, -- 10 * 2 = 20
["blue-to-purple"] = {scale = 3, tier = 3}, -- 10 * 3 = 30
["purple-to-yellow"] = {scale = 5, tier = 4} -- 10 * 5 = 50
}
-- Space Age special scaling (only if Space Age is installed)
local space_age_special_scaling = {
["white-to-orange"] = {scale = 10, tier = 5}, -- 10 * 10 = 100
["white-to-pink"] = {scale = 10, tier = 6},
["white-to-lime"] = {scale = 10, tier = 7},
["white-to-dark-blue"] = {scale = 10, tier = 8},
["white-to-black"] = {scale = 10, tier = 9}
}
-- Combine special scaling based on available mods
local special_scaling = {}
for k, v in pairs(base_special_scaling) do
special_scaling[k] = v
end
if mods["space-age"] then
for k, v in pairs(space_age_special_scaling) do
special_scaling[k] = v
end
end
-- Apply special scaling
for recipe_name, scaling_data in pairs(special_scaling) do
-- Only apply if tier is enabled
if tier_enabled[scaling_data.tier] then
local recipe = data.raw.recipe[recipe_name]
if recipe and not recipe.hidden then
recipe.ingredients = {
{type = "item", name = recipe.ingredients[1].name, amount = upgrade_base * scaling_data.scale}
}
end
end
end
end