4 #define FOREACH_ARRAY(arr, start, end, cond, body) \
7 for (int _i = start; _i < end; ++_i) \
9 const noref int i = _i; \
10 const noref entity it = arr[i]; \
11 if (cond) { LAMBDA(body) } \
15 #define FOREACH_LIST(list, next, cond, body) \
19 for (entity _it = list##_first; _it; (_it = _it.next, ++_i)) \
21 const noref int i = _i; \
22 const noref entity it = _it; \
23 if (cond) { LAMBDA(body) } \
27 #define FOREACH_WORD(words, cond, body) \
30 string _words = words; \
32 for (string _it; (_it = car(_words)); (_words = cdr(_words), ++_i)) \
34 const noref int i = _i; \
35 const noref string it = _it; \
36 if (cond) { LAMBDA(body) } \
40 #define STRING_ITERATOR(this, s, i) \
41 string this##_s = s; \
44 #define STRING_ITERATOR_SET(this, s, i) \
50 #define STRING_ITERATOR_GET(this) str2chr(this##_s, this##_i++)
52 #define FOREACH_CHAR(s, cond, body) \
55 STRING_ITERATOR(iter, s, 0); \
57 while ((_it = STRING_ITERATOR_GET(iter)) > 0) \
59 const noref int it = _it; \
60 if (cond) { LAMBDA(body) } \
65 entity(.string fld, string match, .entity tofield) _findchainstring_tofield = #402;
66 entity(.entity fld, entity match, .entity tofield) findchainentity_tofield = #403;
67 entity(.float fld, float match, .entity tofield) _findchainfloat_tofield = #403;
68 entity(.float fld, float match, .entity tofield) _findchainflags_tofield = #450;
70 entity(.string fld, string match, .entity tofield) _findchainstring_tofield = #402;
71 entity(.entity fld, entity match, .entity tofield) findchainentity_tofield = #403;
72 entity(.float fld, float match, .entity tofield) _findchainfloat_tofield = #403;
73 entity(.float fld, float match, .entity tofield) _findchainflags_tofield = #450;
75 entity(.string fld, string match, .entity tofield) _findchainstring_tofield = #26;
76 entity(.entity fld, entity match, .entity tofield) findchainentity_tofield = #27;
77 entity(.float fld, float match, .entity tofield) _findchainfloat_tofield = #27;
78 entity(.float fld, float match, .entity tofield) _findchainflags_tofield = #88;
81 .entity _FOREACH_ENTITY_fld;
82 .entity _FOREACH_ENTITY_next;
84 #define FOREACH_ENTITY_UNORDERED(cond, body) \
87 for (entity _it = findchainentity_tofield(_FOREACH_ENTITY_fld, NULL, _FOREACH_ENTITY_next); _it; (_it = _it._FOREACH_ENTITY_next, ++_i)) \
89 const noref int i = _i; \
90 const noref entity it = _it; \
91 if (cond) { LAMBDA(body) } \
95 #define FOREACH_ENTITY_ORDERED(cond, body) \
98 for (entity _it = NULL; (_it = nextent(_it)); ++_i) \
100 const noref int i = _i; \
101 const noref entity it = _it; \
102 if (cond) { LAMBDA(body) } \
106 #define FOREACH_ENTITY_FLOAT(fld, match, body) \
109 for (entity _it = _findchainfloat_tofield(fld, match, _FOREACH_ENTITY_next); _it; (_it = _it._FOREACH_ENTITY_next, ++_i)) \
111 const noref int i = _i; \
112 const noref entity it = _it; \
117 #define FOREACH_ENTITY_FLAGS(fld, match, body) \
120 for (entity _it = _findchainflags_tofield(fld, match, _FOREACH_ENTITY_next); _it; (_it = _it._FOREACH_ENTITY_next, ++_i)) \
122 const noref int i = _i; \
123 const noref entity it = _it; \
128 #define FOREACH_ENTITY_CLASS(class, cond, body) \
131 for (entity _it = _findchainstring_tofield(classname, class, _FOREACH_ENTITY_next); _it; (_it = _it._FOREACH_ENTITY_next, ++_i)) \
133 const noref int i = _i; \
134 const noref entity it = _it; \
135 if (cond) { LAMBDA(body) } \
139 #define FOREACH_ENTITY_ENT(fld, match, body) \
142 for (entity _it = findchainentity_tofield(fld, match, _FOREACH_ENTITY_next); _it; (_it = _it._FOREACH_ENTITY_next, ++_i)) \
144 const noref int i = _i; \
145 const noref entity it = _it; \
151 #define FOREACH_ENTITY(cond, body) FOREACH_ENTITY_UNORDERED(cond, body)
153 #define FOREACH(list, cond, body) FOREACH_LIST(list, enemy, cond, body)