]> git.rm.cloudns.org Git - xonotic/xonotic-data.pk3dir.git/commitdiff
String: cons
authorTimePath <andrew.hardaker1995@gmail.com>
Sat, 12 Dec 2015 01:56:46 +0000 (12:56 +1100)
committerTimePath <andrew.hardaker1995@gmail.com>
Sat, 12 Dec 2015 01:56:46 +0000 (12:56 +1100)
qcsrc/common/command/generic.qc
qcsrc/common/weapons/all.qh
qcsrc/lib/iter.qh
qcsrc/lib/string.qh
qcsrc/server/weapons/spawning.qc

index 6fb73cf1e41295f8da2d811615fa02e54e4488e5..6931a98c2d8fbb964696923564a838ca1a84646a 100644 (file)
@@ -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;
                                }
 
index 7972e7f0f2c90906d1ca09bd296d4c90a61c34e5..9bf60e94ab438dd62cdbce7d4e29cad94c96f8df 100644 (file)
@@ -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
index d0f77b553cb7bb061ab1096f697fa99e53774a09..f293aa1493ae11226504c928abd98511dba56573 100644 (file)
@@ -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
 
index 6f61155800d5af390011bd645b005655b61e14ae..ef1c00c62c3c5c0d2714327f8d649b16120fc5ef 100644 (file)
@@ -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);
index cf78d039240367ae6f048929caaccab42a0a5342..d6a108b52d6092e24ac79ae1b43998746849364f 100644 (file)
@@ -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)