#define FOREACH_ARRAY(arr, start, end, cond, body) \
MACRO_BEGIN \
{ \
- for (int i = start; i < end; ++i) \
+ for (int _i = start; _i < end; ++_i) \
{ \
+ const noref int i = _i; \
const noref entity it = arr[i]; \
if (cond) { LAMBDA(body) } \
} \
#define FOREACH_LIST(list, next, cond, body) \
MACRO_BEGIN \
{ \
- int i = 0; \
- for (entity it = list##_first; it; (it = it.next, ++i)) \
+ int _i = 0; \
+ for (entity _it = list##_first; _it; (_it = _it.next, ++_i)) \
{ \
+ const noref int i = _i; \
+ const noref entity it = _it; \
if (cond) { LAMBDA(body) } \
} \
} MACRO_END
MACRO_BEGIN \
{ \
string _words = words; \
- int i = 0; \
- for (string _it; (_it = car(_words)); (_words = cdr(_words), ++i)) \
+ int _i = 0; \
+ for (string _it; (_it = car(_words)); (_words = cdr(_words), ++_i)) \
{ \
+ const noref int i = _i; \
const noref string it = _it; \
if (cond) { LAMBDA(body) } \
} \
MACRO_BEGIN \
{ \
STRING_ITERATOR(iter, s, 0); \
- int it; \
- while ((it = STRING_ITERATOR_GET(iter)) > 0) \
+ int _it; \
+ while ((_it = STRING_ITERATOR_GET(iter)) > 0) \
{ \
+ const noref int it = _it; \
if (cond) { LAMBDA(body) } \
} \
} MACRO_END
#define FOREACH_ENTITY_UNORDERED(cond, body) \
MACRO_BEGIN { \
- int i = 0; \
- for (entity it = findchainentity_tofield(_FOREACH_ENTITY_fld, NULL, _FOREACH_ENTITY_next); it; (it = it._FOREACH_ENTITY_next, ++i)) \
+ int _i = 0; \
+ for (entity _it = findchainentity_tofield(_FOREACH_ENTITY_fld, NULL, _FOREACH_ENTITY_next); _it; (_it = _it._FOREACH_ENTITY_next, ++_i)) \
{ \
+ const noref int i = _i; \
+ const noref entity it = _it; \
if (cond) { LAMBDA(body) } \
} \
} MACRO_END
#define FOREACH_ENTITY_ORDERED(cond, body) \
MACRO_BEGIN { \
- int i = 0; \
- for (entity it = NULL; (it = nextent(it)); ++i) \
+ int _i = 0; \
+ for (entity _it = NULL; (_it = nextent(_it)); ++_i) \
{ \
+ const noref int i = _i; \
+ const noref entity it = _it; \
if (cond) { LAMBDA(body) } \
} \
} MACRO_END
#define FOREACH_ENTITY_FLOAT(fld, match, body) \
MACRO_BEGIN { \
- int i = 0; \
- for (entity it = _findchainfloat_tofield(fld, match, _FOREACH_ENTITY_next); it; (it = it._FOREACH_ENTITY_next, ++i)) \
+ int _i = 0; \
+ for (entity _it = _findchainfloat_tofield(fld, match, _FOREACH_ENTITY_next); _it; (_it = _it._FOREACH_ENTITY_next, ++_i)) \
{ \
+ const noref int i = _i; \
+ const noref entity it = _it; \
LAMBDA(body) \
} \
} MACRO_END
#define FOREACH_ENTITY_FLAGS(fld, match, body) \
MACRO_BEGIN { \
- int i = 0; \
- for (entity it = _findchainflags_tofield(fld, match, _FOREACH_ENTITY_next); it; (it = it._FOREACH_ENTITY_next, ++i)) \
+ int _i = 0; \
+ for (entity _it = _findchainflags_tofield(fld, match, _FOREACH_ENTITY_next); _it; (_it = _it._FOREACH_ENTITY_next, ++_i)) \
{ \
+ const noref int i = _i; \
+ const noref entity it = _it; \
LAMBDA(body) \
} \
} MACRO_END
#define FOREACH_ENTITY_CLASS(class, cond, body) \
MACRO_BEGIN { \
- int i = 0; \
- for (entity it = _findchainstring_tofield(classname, class, _FOREACH_ENTITY_next); it; (it = it._FOREACH_ENTITY_next, ++i)) \
+ int _i = 0; \
+ for (entity _it = _findchainstring_tofield(classname, class, _FOREACH_ENTITY_next); _it; (_it = _it._FOREACH_ENTITY_next, ++_i)) \
{ \
+ const noref int i = _i; \
+ const noref entity it = _it; \
if (cond) { LAMBDA(body) } \
} \
} MACRO_END
#define FOREACH_ENTITY_ENT(fld, match, body) \
do { \
- int i = 0; \
- for (entity it = findchainentity_tofield(fld, match, _FOREACH_ENTITY_next); it; (it = it._FOREACH_ENTITY_next, ++i)) \
+ int _i = 0; \
+ for (entity _it = findchainentity_tofield(fld, match, _FOREACH_ENTITY_next); _it; (_it = _it._FOREACH_ENTITY_next, ++_i)) \
{ \
- body \
+ const noref int i = _i; \
+ const noref entity it = _it; \
+ LAMBDA(body) \
} \
} \
while (0)
case CMD_REQUEST_COMMAND:
{
string reason = argv(1);
- float i = 0;
-
+ int n = 0;
FOREACH_CLIENT(IS_PLAYER(it) && IS_REAL_CLIENT(it), LAMBDA(
if (it.caplayer) it.caplayer = 0;
WITH(entity, self, it, PutObserverInServer());
- ++i;
+ ++n;
));
- if (i) bprint(strcat("Successfully forced all (", ftos(i), ") players to spectate", (reason ? strcat(" for reason: '", reason, "'") : ""), ".\n"));
+ if (n) bprint(strcat("Successfully forced all (", ftos(n), ") players to spectate", (reason ? strcat(" for reason: '", reason, "'") : ""), ".\n"));
else LOG_INFO("No players found to spectate.\n");
return;
}
{
case CMD_REQUEST_COMMAND:
{
- float i = 0;
+ int n = 0;
float argc;
FOREACH_CLIENT(true, LAMBDA(
argc = tokenize_console(strcat("defer_clear ", ftos(etof(it))));
GameCommand_defer_clear(CMD_REQUEST_COMMAND, argc);
- ++i;
+ ++n;
));
- if (i) LOG_INFO(strcat("Successfully stuffed defer clear to all clients (", ftos(i), ")\n")); // should a message be added if no players were found?
+ if (n) LOG_INFO(strcat("Successfully stuffed defer clear to all clients (", ftos(n), ")\n")); // should a message be added if no players were found?
return;
}
{
if (teamplay)
{
- int i;
float x, t_teams, t_players, team_color;
// count the total amount of players and total amount of teams
FOREACH_CLIENT(IS_PLAYER(it) || it.caplayer, LAMBDA(
for ( ; ; )
{
- i = bound(1, floor(random() * maxclients) + 1, maxclients);
+ int idx = bound(1, floor(random() * maxclients) + 1, maxclients);
- if (shuffleteams_players[i])
+ if (shuffleteams_players[idx])
{
continue; // a player is already assigned to this slot
}
else
{
- shuffleteams_players[i] = etof(it);
+ shuffleteams_players[idx] = etof(it);
break;
}
}
bprint("Successfully shuffled the players around randomly.\n");
// clear the buffers now
- for (i = 0; i < SHUFFLETEAMS_MAX_PLAYERS; ++i)
+ for (int i = 0; i < SHUFFLETEAMS_MAX_PLAYERS; ++i)
shuffleteams_players[i] = 0;
- for (i = 0; i < SHUFFLETEAMS_MAX_TEAMS; ++i)
+ for (int i = 0; i < SHUFFLETEAMS_MAX_TEAMS; ++i)
shuffleteams_teams[i] = 0;
}
else
void MapVote_CheckRules_1()
{
- int j;
-
- for(j = 0; j < mapvote_count; ++j)
- if( mapvote_maps_flags[j] & GTV_AVAILABLE )
+ for (int i = 0; i < mapvote_count; ++i)
+ if (mapvote_maps_flags[i] & GTV_AVAILABLE)
{
- //dprint("Map ", ftos(j), ": "); dprint(mapvote_maps[j], "\n");
- mapvote_selections[j] = 0;
+ //dprint("Map ", ftos(i), ": "); dprint(mapvote_maps[i], "\n");
+ mapvote_selections[i] = 0;
}
mapvote_voters = 0;
- FOREACH_CLIENT(IS_REAL_CLIENT(it), LAMBDA(
+ FOREACH_CLIENT(IS_REAL_CLIENT(it), {
++mapvote_voters;
- if(it.mapvote)
+ if (it.mapvote)
{
- j = it.mapvote - 1;
- //dprint("Player ", it.netname, " vote = ", ftos(it.mapvote - 1), "\n");
- mapvote_selections[j] = mapvote_selections[j] + 1;
+ int idx = it.mapvote - 1;
+ //dprint("Player ", it.netname, " vote = ", ftos(idx), "\n");
+ ++mapvote_selections[idx];
}
- ));
+ });
}
float MapVote_CheckRules_2()