-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathexample_spider_and_armor_BobMod.py
More file actions
189 lines (162 loc) · 5.66 KB
/
example_spider_and_armor_BobMod.py
File metadata and controls
189 lines (162 loc) · 5.66 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
from bp_from_json import blueprint
from bp_from_json import dict_bp
from bp_from_json import get_recipes_with_one_product
from bp_from_json import get_items
import math
import sys
from fractions import Fraction
from bp_functions import add_machine
from bp_functions import add_inserter
from bp_functions import add_entity
par_debugging = False
# ====================================
def debug(*args, end="\n"):
global par_debugging
if par_debugging:
print(*args, end=end, file=sys.stderr, flush=True)
# ====================================
def new_request(name, amount):
return {"name": name, "amount": Fraction(amount, 1)}
# ====================================
def get_requests(requests, request, final_ingredients):
debug("get_requests")
debug("\t:{}".format(request))
debug()
for ingredient in recipes[request["name"]]["ingredients"]:
if ingredient["name"] not in final_ingredients:
amount = request["amount"] * ingredient["amount"]
name = ingredient["name"]
requests += dict_bp({name: amount})
get_requests(requests, new_request(name, amount), final_ingredients)
# ====================================
def add_assembly_machine_ver2(bp, x0, y0, item, amount):
slots = 0
for ingredient in recipes[item]["ingredients"]:
a = int(amount * ingredient["amount"])
n = ingredient["name"]
stack_size = items[n]
slots += math.ceil(a / stack_size)
chests = math.ceil(slots / 48)
if chests > 2:
raise Exception("{}={}: chest={} > 2".format(item, amount, chests))
add_machine(bp, "assembling-machine-1", x0 + 1.5, y0 + 1.5, item)
add_entity(bp, "steel-chest", x0 + 2.5, y0 + 4.5)
add_inserter(bp, "inserter", x0 + 2.5, y0 + 3.5, 1)
steel_chests = []
for chest in range(chests):
steel_chests.append(add_entity(bp, "steel-chest", x0 + 0.5 + chest, y0 + 4.5))
# add_inserter(bp, "inserter", x0 + 0.5 + chest, y0 + 3.5, 4)
for ingredient in recipes[item]["ingredients"]:
if ingredient["name"] in final_ingredients or True:
a = math.ceil((amount * ingredient["amount"] / chests))
n = ingredient["name"]
for chest in range(chests):
steel_chests[chest].update_items({n: a}, name_verification=False)
else:
print("")
print("Error !!!")
print("item = ", ingredient["name"])
raise Exception("Неверный рецепт в запросе")
# ====================================
def get_bp(recipe, amount, requests):
bp = blueprint.new_blueprint()
item = recipes[recipe]["product"]
bp.set_icons(1, "item", item)
try:
tier = int(item.split("-")[-1])
except ValueError:
tier = 1
bp.set_label("{}x[item={}]-{}".format(amount, item, tier))
bp.set_description("{}x{}".format(amount, recipe))
count = 0
x = y = 0
for item, amount in requests.items():
if count == 1:
x += 4
else:
x += 3
add_assembly_machine_ver2(bp, x, y, item, amount)
count += 1
return bp
######################################
#
# main
if __name__ == "__main__":
recipes = get_recipes_with_one_product("BobMod.json")
items = get_items("BobMod.json")
final_ingredients = (
"oxygen",
"stone",
"stone-brick",
"iron-plate",
"copper-plate",
"steel-plate",
"zinc-plate",
"aluminium-plate",
"brass-alloy",
"invar-alloy",
"nickel-plate",
"stone-furnace",
"pipe",
)
request_for_production = (
("steam-engine-2", 40, 0),
("steam-engine-3", 40, 1),
("steam-engine-4", 40, 2),
("steam-engine-2", 108, 6),
("steam-engine-3", 108, 7),
("steam-engine-4", 108, 8),
("fluid-reactor-from-fluid-furnace", 12, 12),
("fluid-reactor-2", 12, 13),
("heat-exchanger", 27, 14),
("heat-exchanger-2", 27, 15),
("heat-exchanger-3", 27, 16),
("bob-gun-turret-3", 300, 20),
("bob-gun-turret-4", 300, 21),
)
par_debugging = False
book = blueprint.new_blueprint_book()
book.set_label("mall-on-construction-bots")
book.set_description("by flame_Sla")
for item, amount, index in request_for_production:
# print()
# print("==================")
# print(item)
# print()
requests = dict_bp({item: amount})
# get_requests(requests, new_request(item, amount), final_ingredients)
debug(requests)
book.append_bp(get_bp(item, amount, requests), index)
print()
print("==================")
print("book")
print()
print(book.to_str())
print("==================")
request_for_production2 = (
("steam-engine-2", 56, 0, False),
("steam-engine-3", 56, 1, False),
("heat-exchanger-2", 14, 2, True),
("heat-pipe", 43, 3, False),
("burner-reactor", 15, 4, True),
)
par_debugging = False
book = blueprint.new_blueprint_book()
book.set_label("mall-on-construction-bots")
book.set_description("by flame_Sla")
for item, amount, index, go_to_final_ingredient in request_for_production2:
debug()
debug("==================")
debug(item)
debug()
requests = dict_bp({item: amount})
if go_to_final_ingredient:
get_requests(requests, new_request(item, amount), final_ingredients)
debug(requests)
book.append_bp(get_bp(item, amount, requests), index)
print()
print("==================")
print("book")
print()
print(book.to_str())
print("==================")