3 #define FOREACH_ARRAY(arr, start, end, cond, body) \
6 for (int _i = start; _i < end; ++_i) \
8 const noref int i = _i; \
9 const noref entity it = arr[i]; \
10 if (cond) { LAMBDA(body) } \
14 #define FOREACH_LIST(list, next, cond, body) \
18 for (entity _it = list##_first; _it; (_it = _it.next, ++_i)) \
20 const noref int i = _i; \
21 const noref entity it = _it; \
22 if (cond) { LAMBDA(body) } \
26 #define FOREACH_WORD(words, cond, body) \
29 string _words = words; \
31 for (string _it; (_it = car(_words)); (_words = cdr(_words), ++_i)) \
33 const noref int i = _i; \
34 const noref string it = _it; \
35 if (cond) { LAMBDA(body) } \
39 #define STRING_ITERATOR(this, s, i) \
40 string this##_s = s; \
43 #define STRING_ITERATOR_SET(this, s, i) \
49 #define STRING_ITERATOR_GET(this) str2chr(this##_s, this##_i++)
51 #define FOREACH_CHAR(s, cond, body) \
54 STRING_ITERATOR(iter, s, 0); \
56 while ((_it = STRING_ITERATOR_GET(iter)) > 0) \
58 const noref int it = _it; \
59 if (cond) { LAMBDA(body) } \
64 entity(.string fld, string match, .entity tofield) _findchainstring_tofield = #402;
65 entity(.entity fld, entity match, .entity tofield) findchainentity_tofield = #403;
66 entity(.float fld, float match, .entity tofield) _findchainfloat_tofield = #403;
67 entity(.float fld, float match, .entity tofield) _findchainflags_tofield = #450;
69 entity(.string fld, string match, .entity tofield) _findchainstring_tofield = #402;
70 entity(.entity fld, entity match, .entity tofield) findchainentity_tofield = #403;
71 entity(.float fld, float match, .entity tofield) _findchainfloat_tofield = #403;
72 entity(.float fld, float match, .entity tofield) _findchainflags_tofield = #450;
74 entity(.string fld, string match, .entity tofield) _findchainstring_tofield = #26;
75 entity(.entity fld, entity match, .entity tofield) findchainentity_tofield = #27;
76 entity(.float fld, float match, .entity tofield) _findchainfloat_tofield = #27;
77 entity(.float fld, float match, .entity tofield) _findchainflags_tofield = #88;
80 .entity _FOREACH_ENTITY_fld;
81 .entity _FOREACH_ENTITY_next;
83 #define FOREACH_ENTITY_UNORDERED(cond, body) \
86 for (entity _it = findchainentity_tofield(_FOREACH_ENTITY_fld, NULL, _FOREACH_ENTITY_next); _it; (_it = _it._FOREACH_ENTITY_next, ++_i)) \
88 const noref int i = _i; \
89 const noref entity it = _it; \
90 if (cond) { LAMBDA(body) } \
94 #define FOREACH_ENTITY_ORDERED(cond, body) \
97 for (entity _it = NULL; (_it = nextent(_it)); ++_i) \
99 const noref int i = _i; \
100 const noref entity it = _it; \
101 if (cond) { LAMBDA(body) } \
105 #define FOREACH_ENTITY_FLOAT(fld, match, body) \
108 for (entity _it = _findchainfloat_tofield(fld, match, _FOREACH_ENTITY_next); _it; (_it = _it._FOREACH_ENTITY_next, ++_i)) \
110 const noref int i = _i; \
111 const noref entity it = _it; \
116 #define FOREACH_ENTITY_FLAGS(fld, match, body) \
119 for (entity _it = _findchainflags_tofield(fld, match, _FOREACH_ENTITY_next); _it; (_it = _it._FOREACH_ENTITY_next, ++_i)) \
121 const noref int i = _i; \
122 const noref entity it = _it; \
127 #define FOREACH_ENTITY_CLASS(class, cond, body) \
130 for (entity _it = _findchainstring_tofield(classname, class, _FOREACH_ENTITY_next); _it; (_it = _it._FOREACH_ENTITY_next, ++_i)) \
132 const noref int i = _i; \
133 const noref entity it = _it; \
134 if (cond) { LAMBDA(body) } \
138 #define FOREACH_ENTITY_ENT(fld, match, body) \
141 for (entity _it = findchainentity_tofield(fld, match, _FOREACH_ENTITY_next); _it; (_it = _it._FOREACH_ENTITY_next, ++_i)) \
143 const noref int i = _i; \
144 const noref entity it = _it; \
150 #define FOREACH_ENTITY(cond, body) FOREACH_ENTITY_UNORDERED(cond, body)
152 #define FOREACH(list, cond, body) FOREACH_LIST(list, enemy, cond, body)