-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathrecipes.lua
More file actions
136 lines (107 loc) · 2.94 KB
/
Copy pathrecipes.lua
File metadata and controls
136 lines (107 loc) · 2.94 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
local state = require("state")
local recipes = {}
function recipes.ingredients(recipe)
local result = {}
for _, ingredient in ipairs(recipe.ingredients) do
local id = ingredient.type .. "-" .. ingredient.name
result[id] = ingredient.amount
end
return result
end
function recipes.included(recipe)
if
not state.recipes_fixed[recipe.name] and recipe.enabled == false and
(not state.recipes_locked[recipe.name] or recipe.hidden)
then
return false
end
if #recipe.ingredients == 0 and #recipe.products == 0 then
return false
end
return true
end
function recipes.products(products)
local result = {}
local catalyst
local total = 0
for _, product in ipairs(products) do
local id = product.type .. "-" .. product.name
local amount = product.amount
if not amount then
amount = (product.amount_max + product.amount_min) / 2
end
if product.independent_probability then
amount = amount * product.independent_probability
end
if product.shared_probability then
amount = amount * (product.shared_probability.max - product.shared_probability.min)
end
if product.extra_count_fraction then
amount = amount + product.extra_count_fraction
end
if not result[id] then
result[id] = 0
end
result[id] = result[id] + amount
total = total + amount
if product.ignored_by_productivity then
if not catalyst then
catalyst = {}
end
if not catalyst[id] then
catalyst[id] = 0
end
catalyst[id] = catalyst[id] + product.ignored_by_productivity
end
end
return result, catalyst, total
end
function recipes.save(recipe, localised_name, sprite, scale)
local recycling = false
if proto then
for _, category in ipairs(proto.categories) do
if category == "recycling" then
recycling = true
end
end
end
if not proto or recycling then
for id, _ in pairs(recipe["in"]) do
state.items_used[id] = true
end
for id, _ in pairs(recipe["out"]) do
state.items_used[id] = true
end
end
table.insert(
state.recipes_meta,
{recipe = recipe, localised_name = localised_name, sprite = sprite, scale = scale, proto = proto}
)
end
function recipes.store_used_items(recipe)
for id, _ in pairs(recipe["in"]) do
state.items_used[id] = true
end
for id, _ in pairs(recipe["out"]) do
state.items_used[id] = true
end
end
function recipes.add_value(entity, key, value)
if not entity[key] then
entity[key] = value
else
entity[key] = entity[key] + value
end
end
function recipes.as_percentage(entity)
local total = 0
for _, value in pairs(entity) do
total = total + value
end
local result = {}
for key, value in pairs(entity) do
result[key] = value / total
end
return result
end
return recipes