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
49 for (int t = 0; t < SIZE(Transform); ++t) {
50 for (map<recipe_ordinal, recipe>::iterator p = Recipe.begin(); p != Recipe.end(); ++p) {
51 recipe& r = p->second;
52 if (r.transformed_until != t-1) continue;
53
54 (*Transform.at(t))(p->first);
55 r.transformed_until = t;
56 }
57 }
58 parse_int_reagents();
59
60 }
61
62
63
64
65
66
67
68 :(before "End Globals")
69 int Num_calls_to_transform_all = 0;
70 :(after "void transform_all()")
71 ++Num_calls_to_transform_all;
72
73 :(code)
74 void parse_int_reagents() {
75 trace(9991, "transform") << "--- parsing any uninitialized reagents as integers" << end();
76 for (map<recipe_ordinal, recipe>::iterator p = Recipe.begin(); p != Recipe.end(); ++p) {
77 recipe& r = p->second;
78 if (r.steps.empty()) continue;
79 for (int index = 0; index < SIZE(r.steps); ++index) {
80 instruction& inst = r.steps.at(index);
81 for (int i = 0; i < SIZE(inst.ingredients); ++i) {
82 populate_value(inst.ingredients.at(i));
83 }
84 for (int i = 0; i < SIZE(inst.products); ++i) {
85 populate_value(inst.products.at(i));
86 }
87 }
88 }
89 }
90
91 void populate_value(reagent& r) {
92 if (r.initialized) return;
93
94 if (!is_integer(r.name)) return;
95 r.set_value(to_integer(r.name));
96 }
97
98
99 void transform(string form) {
100 load(form);
101 transform_all();
102 }