-
Notifications
You must be signed in to change notification settings - Fork 10
/
Copy pathrecipes.lua
289 lines (267 loc) · 9.81 KB
/
recipes.lua
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
-- Factorio recipe tree
require "utils"
-- Recipes to load
RECIPE_FILES = {
"ammo.lua",
"capsule.lua",
"demo-furnace-recipe.lua",
"demo-recipe.lua",
"demo-turret.lua",
"equipment.lua",
"fluid-recipe.lua",
"furnace-recipe.lua",
"inserter.lua",
"module.lua",
"recipe.lua",
"turret.lua",
}
-- Which string translation sections to use (now always in base.cfg)
LANGUAGE_SECTIONS = {
["item-name"] = true,
["entity-name"] = true,
["fluid-name"] = true,
["equipment-name"] = true,
}
-- Recipes to exclude from graph
RECIPE_EXCLUDE = {
-- Recipes that have better alternatives
["basic-armor"] = true,
["basic-bullet-magazine"] = true,
["heavy-armor"] = true,
["iron-axe"] = true,
["iron-chest"] = true,
["shotgun"] = true,
["shotgun-shell"] = true,
["small-electric-pole"] = true,
["wooden-chest"] = true,
["power-armor"] = true,
["basic-modular-armor"] = true,
-- Outdated tech
["burner-mining-drill"] = true,
["pistol"] = true,
["steel-furnace"] = true,
["stone-furnace"] = true,
-- Unknown Use
["player-port"] = true,
["railgun-dart"] = true,
["railgun"] = true,
["small-plane"] = true,
-- Filter away for factory plan
["wood"] = true,
["combat-shotgun"] = true,
["basic-oil-processing"] = true,
["fill-crude-oil-barrel"] = true,
["iron-plate"] = true,
["copper-plate"] = true,
["flame-thrower-ammo"] = true,
["steel-axe"] = true,
["storage-tank"] = true,
["boiler"] = true,
["cargo-wagon"] = true,
["steel-chest"] = true,
["oil-refinery"] = true,
["flame-thrower"] = true,
["chemical-plant"] = true,
["small-lamp"] = true,
["steam-engine"] = true,
["pumpjack"] = true,
["train-stop"] = true,
["offshore-pump"] = true,
["combat-shotgun"] = true,
["rocket-launcher"] = true,
["basic-mining-drill"] = true,
["radar"] = true,
["submachine-gun"] = true,
["assembling-machine-1"] = true,
["gun-turret"] = true,
["basic-electric-discharge-defense-remote"] = true,
["green-wire"] = true,
["red-wire"] = true,
["rail-signal"] = true,
["car"] = true,
["basic-transport-belt-to-ground"] = true,
["diesel-locomotive"] = true,
["smart-chest"] = true,
["lab"] = true,
["basic-splitter"] = true,
["assembling-machine-2"] = true,
["land-mine"] = true,
["electric-furnace"] = true,
["fast-transport-belt-to-ground"] = true,
["roboport"] = true,
--["substation"] = true,
["basic-beacon"] = true,
["energy-shield-equipment"] = true,
["deconstruction-planner"] = true,
["blueprint"] = true,
["night-vision-equipment"] = true,
["logistic-chest-requester"] = true,
["logistic-chest-storage"] = true,
["logistic-chest-active-provider"] = true,
["logistic-chest-passive-provider"] = true,
["fast-splitter"] = true,
["small-pump"] = true,
["basic-exoskeleton-equipment"] = true,
["solar-panel-equipment"] = true,
["express-transport-belt-to-ground"] = true,
["energy-shield-mk2-equipment"] = true,
["express-splitter"] = true,
["battery-equipment"] = true,
["assembling-machine-3"] = true,
["fusion-reactor-equipment"] = true,
["battery-mk2-equipment"] = true,
["basic-laser-defense-equipment"] = true,
["basic-electric-discharge-defense-equipment"] = true,
["power-armor-mk2"] = true,
["rocket-defense"] = true,
["arithmetic-combinator"] = true,
["decider-combinator"] = true,
["constant-combinator"] = true,
["arithmetic-combinator"] = true,
["arithmetic-combinator"] = true,
["arithmetic-combinator"] = true,
["arithmetic-combinator"] = true,
}
-- Ingredients that are basic resources
RESOURCES = {
["copper-ore"] = true,
["crude-oil"] = true,
["iron-ore"] = true,
["stone"] = true,
["raw-wood"] = true,
["water"] = true,
}
-- Try and map recipe categories to the (minimum) type of crafting station needed
CATEGORY_LABEL = {
default = Img(FACTORIO_ROOT.."data/base/graphics/icons/assembling-machine-1.png"),
crafting = Img(FACTORIO_ROOT.."data/base/graphics/icons/assembling-machine-1.png"),
["crafting-with-fluid"] = Img(FACTORIO_ROOT.."data/base/graphics/icons/assembling-machine-2.png"),
["advanced-crafting"] = Img(FACTORIO_ROOT.."data/base/graphics/icons/assembling-machine-2.png"),
smelting = Img(FACTORIO_ROOT.."data/base/graphics/icons/stone-furnace.png"),
["oil-processing"] = Img(FACTORIO_ROOT.."data/base/graphics/icons/oil-refinery.png"),
chemistry = Img(FACTORIO_ROOT.."data/base/graphics/icons/chemical-plant.png"),
}
load_data(RECIPE_FILES, "data/base/prototypes/recipe/")
load_translations(LANGUAGE_SECTIONS)
-- Graphviz output
print('strict digraph factorio {')
-- Change rankdir to LR or TB to change direction of graph
print('layout=dot; splines=polyline; rankdir=LR; color="#ffffff"; bgcolor="#332200"; ratio=auto; ranksep=2.0; nodesep=0.15;')
-- Node default attributes
node_default = {}
node_default.color = '"#e4e4e4"'
node_default.fontname = '"TitilliumWeb-SemiBold"'
node_default.fontcolor = '"#ffffff"'
node_default.shape = 'box'
node_default.style = 'filled'
print(string.format('node [%s]', VizAttr(node_default)))
-- Edge default attributes
edge_default = {}
edge_default.penwidth = 2
edge_default.color = '"#DDDD22"'
edge_default.fontname = node_default.fontname
edge_default.fontcolor = node_default.fontcolor
print(string.format('edge [%s]', VizAttr(edge_default)))
-- Raw resources go on the top/leftmost rank on their own
print('{ rank=source;')
for res in pairs(RESOURCES) do
print(string.format('"%s";', res))
end
print('}')
for id, recipe in pairs(data) do
-- First do a few sanity checks
if recipe.type ~= "recipe" then
io.stderr:write(string.format('Found unknown type "%s" instead of "recipe" for %s', recipe.type, recipe.name), "\n")
os.exit(1)
end
if recipe.enabled ~= "false" then
print("// ENABLED:", recipe.name) -- Initially unlocked recipes?
end
if not FILTER or (FILTER and not RECIPE_EXCLUDE[recipe.name]) then
-- Some recipes have multiple sets of ingredients based on difficulty level.
if recipe.ingredients == nil then
-- Assume "normal"" difficulty instead of "expensive"
recipe.ingredients = recipe.normal.ingredients
recipe.result = recipe.normal.result
end
-- Recipe has .result data, convert to new .results format for easier handling
if recipe.result ~= nil then
recipe.results = {{name = recipe.result, amount = recipe.result_count}}
end
-- Define the recipe node first
attr = {}
-- If energy_required isn't specified, it defaults to 0.5
if recipe.energy_required == nil then recipe.energy_required = 0.5 end
attr.label = HtmlLabel(CATEGORY_LABEL[recipe.category or 'default'], nil, recipe.energy_required)
attr.tooltip = string.format('"%s"', recipe.name) -- Put the untranslated name into the tooltip
attr.fillcolor = '"#6d7235"'
attr.color = attr.fillcolor
attr.shape = "cds"
print(string.format('"Recipe: %s" [%s];', recipe.name, VizAttr(attr)))
-- Make edges from each ingredient to the recipe
print(string.format(" // Ingredients"))
for ing_id, ing in pairs(recipe.ingredients) do
-- Convert old array syntax into new descriptive one
if ing.type == nil then
ing.name = ing[1]
ing.amount = ing[2]
end
-- Define ingredient node
attr = {}
attr.label = HtmlLabel(T(ing.name), GetIcon(ing))
if ing.type == "fluid" then
attr.shape = "ellipse"
attr.fillcolor = '"#3d3c6e"'
else
attr.fillcolor = '"#8f8f90"'
end
attr.color = attr.fillcolor
print(string.format('"%s" [%s];', ing.name, VizAttr(attr)))
-- Ingredient -> Recipe edge
attr = {}
attr.label = string.format('"x%d"', ing.amount)
if ing.type == "fluid" then
attr.color = '"#45A7F3"'
elseif ing.name == "copper-plate" then
attr.color = '"#C77362"'
elseif ing.name == "iron-plate" then
attr.color = '"#838588"'
elseif ing.name == "steel-plate" then
attr.color = '"#96ff8B"'
else
attr.color = edge_default.color
end
-- For raw resources, set fixed rank
if RESOURCES[ing.name] ~= nil then
attr.rank="source"
end
print(string.format(' "%s" -> "Recipe: %s" [%s];', ing.name, recipe.name, VizAttr(attr)))
end
-- And from the recipe to each result
print(" // Results")
for res_id, res in pairs(recipe.results) do
-- Define result node
attr = {}
attr.label = HtmlLabel(T(res.name), GetIcon(res))
if res.type == "fluid" then
attr.fillcolor = '"#3d3c6e"'
else
attr.fillcolor = '"#8f8f90"'
end
attr.color = attr.fillcolor
print(string.format('"%s" [%s];', res.name, VizAttr(attr)))
-- Recipe -> Result edge
attr = {}
attr.weight = 100 -- Shorten result edges so results are close to recipe/factory
attr.label = string.format('x%d', res.amount or 1)
if res.type == "fluid" then
attr.color = '"#9999ff"'
else
attr.color = edge_default.color
end
print(string.format(' "Recipe: %s" -> "%s" [%s];', recipe.name, res.name, VizAttr(attr)))
end
print("")
end
end
print("}") -- Done!