From: TimePath Date: Sat, 12 Dec 2015 01:56:46 +0000 (+1100) Subject: String: cons X-Git-Tag: xonotic-v0.8.2~1504 X-Git-Url: https://git.rm.cloudns.org/?a=commitdiff_plain;h=e9cbe7ee0c59db8d43a80dcbf277983245907ed3;p=xonotic%2Fxonotic-data.pk3dir.git String: cons --- diff --git a/qcsrc/common/command/generic.qc b/qcsrc/common/command/generic.qc index 6fb73cf1e..6931a98c2 100644 --- a/qcsrc/common/command/generic.qc +++ b/qcsrc/common/command/generic.qc @@ -274,16 +274,9 @@ void GenericCommand_maplist(float request, float argc) { MapInfo_Enumerate(); MapInfo_FilterGametype(MapInfo_CurrentGametype(), MapInfo_CurrentFeatures(), MapInfo_RequiredFlags(), MapInfo_ForbiddenFlags(), 0); - argc = tokenizebyseparator(cvar_string("g_maplist"), " "); - - tmp_string = ""; - for(i = 0; i < argc; ++i) - if(MapInfo_CheckMap(argv(i))) - tmp_string = strcat(tmp_string, " ", argv(i)); - - tmp_string = substring(tmp_string, 1, strlen(tmp_string) - 1); - cvar_set("g_maplist", tmp_string); - + string filtered = ""; + FOREACH_WORD(cvar_string("g_maplist"), MapInfo_CheckMap(it), filtered = cons(filtered, it)); + cvar_set("g_maplist", filtered); return; } diff --git a/qcsrc/common/weapons/all.qh b/qcsrc/common/weapons/all.qh index 7972e7f0f..9bf60e94a 100644 --- a/qcsrc/common/weapons/all.qh +++ b/qcsrc/common/weapons/all.qh @@ -129,6 +129,11 @@ STATIC_INIT_LATE(W_PROP_reloader) REGISTER_WEAPON(Null, NEW(Weapon)); +Weapon Weapons_fromstr(string s) +{ + FOREACH(Weapons, it != WEP_Null && it.netname == s, return it); + return NULL; +} // legacy w_prop mappings diff --git a/qcsrc/lib/iter.qh b/qcsrc/lib/iter.qh index d0f77b553..f293aa149 100644 --- a/qcsrc/lib/iter.qh +++ b/qcsrc/lib/iter.qh @@ -7,7 +7,7 @@ for (int i = start; i < end; ++i) \ { \ const noref entity it = arr[i]; \ - if (cond) { body } \ + if (cond) { LAMBDA(body) } \ } \ } MACRO_END @@ -17,7 +17,7 @@ int i = 0; \ for (entity it = list##_first; it; (it = it.next, ++i)) \ { \ - if (cond) { body } \ + if (cond) { LAMBDA(body) } \ } \ } MACRO_END @@ -29,7 +29,7 @@ for (string _it; (_it = car(_words)); (_words = cdr(_words), ++i)) \ { \ const noref string it = _it; \ - if (cond) { body } \ + if (cond) { LAMBDA(body) } \ } \ } MACRO_END @@ -55,7 +55,7 @@ int i = 0; \ for (entity it = findchainentity_tofield(_FOREACH_ENTITY_fld, NULL, _FOREACH_ENTITY_next); it; (it = it._FOREACH_ENTITY_next, ++i)) \ { \ - if (cond) { body } \ + if (cond) { LAMBDA(body) } \ } \ } MACRO_END @@ -64,7 +64,7 @@ int i = 0; \ for (entity it = NULL; (it = nextent(it)); ++i) \ { \ - if (cond) { body } \ + if (cond) { LAMBDA(body) } \ } \ } MACRO_END @@ -73,7 +73,7 @@ int i = 0; \ for (entity it = _findchainflags_tofield(fld, flags, _FOREACH_ENTITY_next); it; (it = it._FOREACH_ENTITY_next, ++i)) \ { \ - body \ + LAMBDA(body) \ } \ } MACRO_END @@ -82,7 +82,7 @@ int i = 0; \ for (entity it = _findchainstring_tofield(classname, class, _FOREACH_ENTITY_next); it; (it = it._FOREACH_ENTITY_next, ++i)) \ { \ - if (cond) { body } \ + if (cond) { LAMBDA(body) } \ } \ } MACRO_END diff --git a/qcsrc/lib/string.qh b/qcsrc/lib/string.qh index 6f6115580..ef1c00c62 100644 --- a/qcsrc/lib/string.qh +++ b/qcsrc/lib/string.qh @@ -130,6 +130,13 @@ string cdr(string s) return substring(s, o + 1, strlen(s) - (o + 1)); } +string cons(string a, string b) +{ + if (a == "") return b; + if (b == "") return a; + return strcat(a, " ", b); +} + string substring_range(string s, float b, float e) { return substring(s, b, e - b); diff --git a/qcsrc/server/weapons/spawning.qc b/qcsrc/server/weapons/spawning.qc index cf78d0392..d6a108b52 100644 --- a/qcsrc/server/weapons/spawning.qc +++ b/qcsrc/server/weapons/spawning.qc @@ -7,30 +7,19 @@ string W_Apply_Weaponreplace(string in) { - float n = tokenize_console(in); - string out = "", s, replacement; - float i, j; - entity e; - for(i = 0; i < n; ++i) - { - replacement = ""; - s = argv(i); - - for(j = WEP_FIRST; j <= WEP_LAST; ++j) + string out = ""; + FOREACH_WORD(in, true, { + string replacement = ""; + Weapon w = Weapons_fromstr(it); + if (w) { - e = Weapons_from(j); - if(e.netname == s) - { - replacement = e.weaponreplace; - } + replacement = w.weaponreplace; + if (replacement == "") replacement = it; } - - if(replacement == "") - out = strcat(out, " ", s); - else if(replacement != "0") - out = strcat(out, " ", replacement); - } - return substring(out, 1, -1); + if (replacement == "0") continue; + out = cons(out, replacement); + }); + return out; } void weapon_defaultspawnfunc(entity this, Weapon e)