1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19 :(before "End recipe Fields")
20 int transformed_until;
21 :(before "End recipe Constructor")
22 transformed_until = -1;
23
24 :(before "End Types")
25 typedef void (*transform_fn)(const recipe_ordinal);
26
27 :(before "End Globals")
28 vector<transform_fn> Transform;
29
30 :(before "End One-time Setup")
31 initialize_transforms();
32 :(code)
33 void initialize_transforms() {
34
35
36
37
38
39
40
41
42
43
44 }
45
46 void transform_all() {
47 trace(9990, "transform") << "=== transform_all()" << end();
48 for (int t = 0; t < SIZE(Transform); ++t) {
49 for (map<recipe_ordinal, recipe>::iterator p = Recipe.begin(); p != Recipe.end(); ++p) {
50 recipe& r = p->second;
51 if (r.transformed_until != t-1) continue;
52
53 (*Transform.at(t))(p->first);
54 r.transformed_until = t;
55 }
56 }
57 parse_int_reagents();
58
59 }
60
61
62
63
64
65
66
67 :(before "End Globals")
68 int Num_calls_to_transform_all = 0;
69 :(after "void transform_all()")
70 ++Num_calls_to_transform_all;
71
72 :(code)
73 void parse_int_reagents() {
74 trace(9991, "transform") << "--- parsing any uninitialized reagents as integers" << end();
75 for (map<recipe_ordinal, recipe>::iterator p = Recipe.begin(); p != Recipe.end(); ++p) {
76 recipe& r = p->second;
77 if (r.steps.empty()) continue;
78 for (int index = 0; index < SIZE(r.steps); ++index) {
79 instruction& inst = r.steps.at(index);
80 for (int i = 0; i < SIZE(inst.ingredients); ++i) {
81 populate_value(inst.ingredients.at(i));
82 }
83 for (int i = 0; i < SIZE(inst.products); ++i) {
84 populate_value(inst.products.at(i));
85 }
86 }
87 }
88 }
89
90 void populate_value(reagent& r) {
91 if (r.initialized) return;
92
93 if (!is_integer(r.name)) return;
94 r.set_value(to_integer(r.name));
95 }
96
97
98 void transform(string form) {
99 load(form);
100 transform_all();
101 }