]> de.git.xonotic.org Git - xonotic/xonotic-data.pk3dir.git/blobdiff - qcsrc/common/util.qc
Merge remote-tracking branch 'origin/master' into samual/updatecommands
[xonotic/xonotic-data.pk3dir.git] / qcsrc / common / util.qc
index f38b1156bb120de75e05dde82a01577493a736fe..19339a36e99635908c379b21383ceff01d7dc42a 100644 (file)
@@ -195,21 +195,21 @@ vector colormapPaletteColor(float c, float isPants)
 {
        switch(c)
        {
-               case  0: return '0.800000 0.800000 0.800000';
-               case  1: return '0.600000 0.400000 0.000000';
+               case  0: return '1.000000 1.000000 1.000000';
+               case  1: return '1.000000 0.333333 0.000000';
                case  2: return '0.000000 1.000000 0.501961';
                case  3: return '0.000000 1.000000 0.000000';
                case  4: return '1.000000 0.000000 0.000000';
-               case  5: return '0.000000 0.658824 1.000000';
+               case  5: return '0.000000 0.666667 1.000000';
                case  6: return '0.000000 1.000000 1.000000';
                case  7: return '0.501961 1.000000 0.000000';
                case  8: return '0.501961 0.000000 1.000000';
                case  9: return '1.000000 0.000000 1.000000';
                case 10: return '1.000000 0.000000 0.501961';
-               case 11: return '0.600000 0.600000 0.600000';
+               case 11: return '0.000000 0.000000 1.000000';
                case 12: return '1.000000 1.000000 0.000000';
-               case 13: return '0.000000 0.313725 1.000000';
-               case 14: return '1.000000 0.501961 0.000000';
+               case 13: return '0.000000 0.333333 1.000000';
+               case 14: return '1.000000 0.666667 0.000000';
                case 15:
                        if(isPants)
                                return
@@ -396,27 +396,6 @@ void buf_save(float buf, string pFilename)
        fclose(fh);
 }
 
-string GametypeNameFromType(float g)
-{
-       if      (g == GAME_DEATHMATCH) return "dm";
-       else if (g == GAME_TEAM_DEATHMATCH) return "tdm";
-       else if (g == GAME_DOMINATION) return "dom";
-       else if (g == GAME_CTF) return "ctf";
-       else if (g == GAME_RUNEMATCH) return "rune";
-       else if (g == GAME_LMS) return "lms";
-       else if (g == GAME_ARENA) return "arena";
-       else if (g == GAME_CA) return "ca";
-       else if (g == GAME_KEYHUNT) return "kh";
-       else if (g == GAME_ONSLAUGHT) return "ons";
-       else if (g == GAME_ASSAULT) return "as";
-       else if (g == GAME_RACE) return "rc";
-       else if (g == GAME_NEXBALL) return "nexball";
-       else if (g == GAME_CTS) return "cts";
-       else if (g == GAME_FREEZETAG) return "freezetag";
-       else if (g == GAME_KEEPAWAY) return "ka";
-       return "dm";
-}
-
 string mmsss(float tenths)
 {
        float minutes;
@@ -863,28 +842,48 @@ void get_mi_min_max_texcoords(float mode)
 }
 #endif
 
-void cvar_settemp(string cv, string val)
+float cvar_settemp(string tmp_cvar, string tmp_value)
 {
+       float created_saved_value;
        entity e;
+       
+       if not(tmp_cvar || tmp_value)
+       {
+               dprint("Error: Invalid usage of cvar_settemp(string, string); !\n");
+               return FALSE;
+       }
+       
        for(e = world; (e = find(e, classname, "saved_cvar_value")); )
-               if(e.netname == cv)
-                       goto saved;
+               if(e.netname == tmp_cvar)
+                       goto saved; // skip creation
+                       
+       // creating a new entity to keep track of this cvar
        e = spawn();
        e.classname = "saved_cvar_value";
-       e.netname = strzone(cv);
-       e.message = strzone(cvar_string(cv));
-:saved
-       cvar_set(cv, val);
+       e.netname = strzone(tmp_cvar);
+       e.message = strzone(cvar_string(tmp_cvar));
+       created_saved_value = TRUE;
+       
+       // an entity for this cvar already exists
+       :saved
+       
+       // update the cvar to the value given
+       cvar_set(tmp_cvar, tmp_value);
+       
+       return created_saved_value;
 }
 
-void cvar_settemp_restore()
+float cvar_settemp_restore()
 {
+       float i;
        entity e;
        while((e = find(world, classname, "saved_cvar_value")))
        {
                cvar_set(e.netname, e.message);
                remove(e);
        }
+       
+       return i;
 }
 
 float almost_equals(float a, float b)
@@ -1410,7 +1409,7 @@ string textShortenToLength(string theText, float maxWidth, textLengthUpToLength_
 float isGametypeInFilter(float gt, float tp, float ts, string pattern)
 {
        string subpattern, subpattern2, subpattern3, subpattern4;
-       subpattern = strcat(",", GametypeNameFromType(gt), ",");
+       subpattern = strcat(",", MapInfo_Type_ToString(gt), ",");
        if(tp)
                subpattern2 = ",teams,";
        else
@@ -1419,7 +1418,7 @@ float isGametypeInFilter(float gt, float tp, float ts, string pattern)
                subpattern3 = ",teamspawns,";
        else
                subpattern3 = ",noteamspawns,";
-       if(gt == GAME_RACE || gt == GAME_CTS)
+       if(gt == MAPINFO_TYPE_RACE || gt == MAPINFO_TYPE_CTS)
                subpattern4 = ",race,";
        else
                subpattern4 = string_null;
@@ -2092,6 +2091,46 @@ float lowestbit(float f)
        return f;
 }
 
+/*
+string strlimitedlen(string input, string truncation, float strip_colors, float limit)
+{
+       if(strlen((strip_colors ? strdecolorize(input) : input)) <= limit)
+               return input;
+       else
+               return strcat(substring(input, 0, (strlen(input) - strlen(truncation))), truncation);
+}*/
+
+// escape the string to make it safe for consoles
+string MakeConsoleSafe(string input)
+{
+       input = strreplace("\n", "", input);
+       input = strreplace("\\", "\\\\", input);
+       input = strreplace("$", "$$", input);
+       input = strreplace("\"", "\\\"", input);
+       return input;
+}
+
+#ifndef MENUQC
+// get true/false value of a string with multiple different inputs
+float InterpretBoolean(string input)
+{
+       switch(strtolower(input))
+       {
+               case "yes":
+               case "true":
+               case "on":
+                       return TRUE;
+               
+               case "no":
+               case "false":
+               case "off":
+                       return FALSE;
+               
+               default: return stof(input);
+       }
+}
+#endif
+
 #ifdef CSQC
 entity ReadCSQCEntity()
 {