-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathprocess-recipes.lua
More file actions
364 lines (321 loc) · 10.6 KB
/
Copy pathprocess-recipes.lua
File metadata and controls
364 lines (321 loc) · 10.6 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
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
local iterate_collection = require("iterate-collection")
local process_categories = require("process-categories")
local recipes = require("recipes")
local state = require("state")
local utils = require("utils")
return function()
local function process_item_recipes(name, proto)
if proto.parameter then
return
end
if #proto.rocket_launch_products > 0 then
-- Rocket launch recipes
local product_proto = utils.first_product_proto(proto.rocket_launch_products)
local out, catalyst, total = recipes.products(proto.rocket_launch_products)
local first_out = next(out)
local item = state.item_map[first_out]
local id = "item-" .. name
for entity_name, info in pairs(state.machines.silo) do
local recipe_in = {[id] = 1}
for item_id, amount in pairs(info.recipe_in) do
if not recipe_in[item_id] then
recipe_in[item_id] = 0
end
recipe_in[item_id] = recipe_in[item_id] + amount
end
local recipe = {
id = "launch-" .. info.id .. "-" .. id,
icon = item.icon,
time = 40.6,
["in"] = recipe_in,
out = out,
catalyst = catalyst,
part = info.part,
producers = {info.id}
}
recipes.store_used_items(recipe)
table.insert(
state.recipes_meta,
{
recipe = recipe,
localised_name = {"factoriolab-export.launch-item", proto.localised_name},
proto = product_proto
}
)
end
end
if proto.burnt_result then
-- Burn recipes
local producers = state.producers.burner[proto.fuel_category]
if producers then
local item = state.item_map["item-" .. proto.burnt_result.name]
local recipe = {
id = "burn-" .. name,
icon = item.icon,
time = 1,
["in"] = {["item-" .. name] = 0},
out = {[item.id] = 0},
producers = producers,
flags = {"burn"}
}
recipes.store_used_items(recipe)
table.insert(
state.recipes_meta,
{
recipe = recipe,
localised_name = {"factoriolab-export.x-from-y", proto.burnt_result.localised_name, proto.localised_name},
proto = proto.burnt_result
}
)
end
end
if proto.spoil_result then
-- Spoil recipes
local item = state.item_map["item-" .. proto.spoil_result.name]
local recipe = {
id = "spoil-" .. name,
icon = item.icon,
time = 1,
["in"] = {["item-" .. name] = 1},
out = {[item.id] = 1}
}
recipes.store_used_items(recipe)
table.insert(
state.recipes_meta,
{
recipe = recipe,
localised_name = {"factoriolab-export.x-from-y", proto.spoil_result.localised_name, proto.localised_name},
proto = proto.spoil_result
}
)
end
if
proto.plant_result and proto.plant_result.mineable_properties.minable and
proto.plant_result.mineable_properties.products
then
-- Agriculture recipes
local product_proto = utils.first_product_proto(proto.plant_result.mineable_properties.products)
local out, catalyst, total = recipes.products(proto.plant_result.mineable_properties.products)
local first_out = next(out)
local item = state.item_map[first_out]
local sprite = "entity/" .. proto.plant_result.name
table.insert(state.icons, {sprite = sprite, scale = 2})
local recipe = {
id = "harvest-" .. proto.plant_result.name,
icon = sprite,
time = proto.plant_result.growth_ticks / 60,
["in"] = {["item-" .. name] = 1},
out = out,
catalyst = catalyst,
cost = 100 / total,
locations = utils.locations(proto.plant_result),
flags = {"showCount"}
}
recipes.store_used_items(recipe)
table.insert(
state.recipes_meta,
{
recipe = recipe,
localised_name = {"factoriolab-export.harvest-item", proto.plant_result.localised_name},
proto = product_proto
}
)
end
end
local function process_entity_recipes(name, proto)
if proto.parameter then
return
end
if proto.type == "resource" then
-- Resource recipes
if proto.mineable_properties.minable and proto.mineable_properties.products then
local product_proto = utils.first_product_proto(proto.mineable_properties.products)
local out, catalyst, total = recipes.products(proto.mineable_properties.products)
local first_out = next(out)
local item = state.item_map[first_out]
local producers = state.producers.resource[proto.resource_category]
local recipe_in = {}
if proto.mineable_properties.required_fluid and proto.mineable_properties.fluid_amount then
recipe_in["fluid-" .. proto.mineable_properties.required_fluid] = proto.mineable_properties.fluid_amount
producers = state.producers.resource_fluid[proto.resource_category]
end
local locations = {}
for surface_name, surface_proto in pairs(prototypes.space_location) do
if utils.has_resource(surface_proto, name) then
table.insert(locations, surface_name)
end
end
if item and #locations > 0 and #producers > 0 and total > 0 then
local recipe = {
id = "resource-" .. name,
icon = item.icon,
time = proto.mineable_properties.mining_time,
["in"] = recipe_in,
out = out,
catalyst = catalyst,
producers = producers,
cost = 100 / total,
flags = {"mining"},
locations = locations
}
if proto.infinite_resource then
table.insert(recipe.flags, "infinite")
end
recipes.store_used_items(recipe)
table.insert(
state.recipes_meta,
{
recipe = recipe,
localised_name = {"factoriolab-export.mining-item", proto.localised_name},
proto = product_proto
}
)
end
end
end
end
local function process_fluid_recipes(name, proto)
if proto.parameter then
return
end
local item = state.item_map["fluid-" .. name]
-- Offshore pump recipes
local locations = {}
for surface_name, surface_proto in pairs(prototypes.space_location) do
if utils.has_ocean(surface_proto, name) then
table.insert(locations, surface_name)
end
end
if #locations > 0 then
local producers = {}
for entity_name, info in pairs(state.machines.offshore_pump) do
if not info.output or info.output == name then
table.insert(producers, info.id)
end
end
if #producers > 0 then
local recipe = {
id = "offshore-pump-" .. name,
icon = item.icon,
time = 1,
["in"] = {},
out = {[item.id] = 1},
producers = producers,
locations = locations
}
recipes.store_used_items(recipe)
table.insert(
state.recipes_meta,
{
recipe = recipe,
localised_name = {"factoriolab-export.offshore-pump-item", proto.localised_name},
proto = proto
}
)
end
end
-- Boiler recipes
local input_producers = {}
for entity_name, info in pairs(state.machines.boiler) do
if info.output == name and info.input then
if not input_producers[info.input] then
input_producers[info.input] = {}
end
table.insert(input_producers[info.input], info.id)
end
end
for input, producers in pairs(input_producers) do
local input_id = "fluid-" .. input
local recipe = {
id = "boiler-" .. name,
icon = item.icon,
time = 1,
["in"] = {[input_id] = 1},
out = {[item.id] = 10},
producers = producers
}
recipes.store_used_items(recipe)
table.insert(
state.recipes_meta,
{
recipe = recipe,
localised_name = {"factoriolab-export.boil-item", prototypes.fluid[input].localised_name},
proto = proto
}
)
end
end
local function process_recipe(name, proto)
if proto.parameter or not recipes.included(proto) then
return
end
local sprite = "recipe/" .. name
local out, catalyst = recipes.products(proto.products)
local producer_map = {}
function add_category(category)
local producers = state.producers.crafting[category]
if not producers then
return
end
for _, producer in ipairs(producers) do
producer_map[producer] = true
end
end
local recycling = false
for _, category in ipairs(proto.categories) do
if category == "recycling" then
recycling = true
end
add_category(category)
end
local producers = {}
for producer, _ in pairs(producer_map) do
table.insert(producers, producer)
end
local recipe = {
id = name,
icon = sprite,
time = proto.energy,
["in"] = recipes.ingredients(proto),
out = out,
catalyst = catalyst,
disallowedEffects = utils.disallowed_effects(proto),
locations = utils.locations(proto)
}
local flags = {}
if recycling then
table.insert(flags, "recycling")
else
recipes.store_used_items(recipe)
end
if state.recipes_locked[name] then
table.insert(flags, "locked")
end
if next(producers) then
recipe.producers = producers
end
if next(flags) then
recipe.flags = flags
end
table.insert(state.recipes_meta, {recipe = recipe, sprite = sprite, scale = 2, proto = proto})
end
iterate_collection(
prototypes.recipe,
process_recipe,
function()
iterate_collection(
prototypes.item,
process_item_recipes,
function()
iterate_collection(
prototypes.entity,
process_entity_recipes,
function()
iterate_collection(prototypes.fluid, process_fluid_recipes, process_categories)
end
)
end
)
end
)
end