-
Notifications
You must be signed in to change notification settings - Fork 0
/
factroy_block_manager.ts
120 lines (103 loc) · 3.89 KB
/
factroy_block_manager.ts
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
export function factory_block_manager(produced_item: Value) {
// Wait until recipe is set
while (compareItem(produced_item, null)) {
wait(10);
}
// build workers
let position:Value = getLocation(self);
// left
let new_pos:Value = position - coord(2, 0);
build_factory_worker(new_pos, 1);
new_pos = new_pos - coord(0, 1);
build_factory_worker(new_pos, 1);
new_pos = new_pos - coord(0, 1);
build_factory_worker(new_pos, 1);
//right
new_pos = position + coord(1, 0);
build_factory_worker(new_pos, 3);
new_pos = new_pos - coord(0, 1);
build_factory_worker(new_pos, 3);
new_pos = new_pos - coord(0, 1);
build_factory_worker(new_pos, 3);
// top
new_pos = position - coord(0, 3);
build_factory_worker(new_pos, 4);
// build in, out Storages and power station in between those
new_pos = position + coord(0, 1);
build_power_station(new_pos, 4);
new_pos = new_pos - coord(1, 0);
build_factory_storage_in(new_pos, 4);
new_pos = new_pos + coord(2, 0);
build_factory_storage_out(new_pos, 4);
// end setup of other required buildings
// setup of inventory slots
lock_items_for_production(produced_item);
//work: handle in-factory logistic
const [my_x_pos,my_y_pos] = separateCoordinate(position)
let num_slots = self.countStorageSlots();
while (num_slots == self.countStorageSlots()) {
for (const building of entitiesInRange(1, "v_building")) {
const [their_x_pos,their_y_pos] = separateCoordinate(getLocation(building))
// storage has larger y position than the manager (>= is a worker)
for (const ingredient of recipieIngredients(produced_item)) {
if(my_y_pos<= their_y_pos){
// worker
orderTransfer(building, combineRegister(getMaxStack(ingredient), ingredient))
}
else{
//storage
}
}
if(my_y_pos<= their_y_pos){
// worker
}
else{
//storage
orderTransfer(building, combineRegister(getMaxStack(produced_item), produced_item))
}
}
}
notify("ERROR: number of slots changed");
exit();
}
// need to setup the correct blueprints for the buildings to build in-game
function build_factory_worker(position: Value, rotation: number) {
build(position, rotation);
}
// need to setup the correct blueprints for the buildings to build in-game
function build_factory_storage_in(position: Value, rotation: number) {
build(position, rotation);
}
// need to setup the correct blueprints for the buildings to build in-game
function build_factory_storage_out(position: Value, rotation: number) {
build(position, rotation);
}
// need to setup the correct blueprints for the buildings to build in-game
function build_power_station(position: Value, rotation: number) {
build(position, rotation);
}
function lock_items_for_production(produced_item){
let num_ingredients: number;
num_ingredients = 1; // 1 for the production result
for (const ingredient of recipieIngredients(produced_item)) { num_ingredients = num_ingredients + 1; }
let num_slots: number;
num_slots = self.countStorageSlots();
let slots_per_ingredient: number = num_slots / num_ingredients;
if (slots_per_ingredient == 0) {
notify("ERROR: not enough slots for ingredients");
return;
}
// lock relevant slots
let current_slot = 1;
for (const ingredient of recipieIngredients(produced_item)) {
for (var i=1; i <= slots_per_ingredient; i = i + 1) {
lockSlots(ingredient, current_slot);
current_slot = current_slot + 1
}
}
// for the result
for (var i=1; i <= slots_per_ingredient; i = i + 1) {
lockSlots(produced_item, current_slot);
current_slot = current_slot + 1
}
}