]> de.git.xonotic.org Git - xonotic/darkplaces.git/blobdiff - common.c
fix crash with predicted player locations
[xonotic/darkplaces.git] / common.c
index aac01fba3709b022bdb7ce0b2c8dc1a6ec4a9f3b..9fa0968825ec5e5297c814f5bdde49b7208ea842 100644 (file)
--- a/common.c
+++ b/common.c
@@ -1492,6 +1492,9 @@ static const gamemode_info_t gamemode_info [GAME_COUNT] =
 // GAME_PROPHECY
 // COMMANDLINEOPTION: Game: -prophecy runs the game Quake (default)
 { "prophecy",                          "-prophecy",            "Prophecy",             "data",         NULL,                   "prophecy",                     "prophecy" },
+// GAME_BLOODOMNICIDE
+// COMMANDLINEOPTION: Game: -omnicide runs the game Blood Omnicide
+{ "omnicide", "-omnicide", "Blood Omnicide", "kain", NULL, "omnicide", "omnicide" },
 };
 
 void COM_InitGameType (void)
@@ -1777,7 +1780,7 @@ COM_StringLengthNoColors(const char *s, size_t size_s, qboolean *valid)
                                ++s;
                                switch((s == end) ? 0 : *s)
                                {
-                                       case STRING_COLOR_RGB_DEFAULT:
+                                       case STRING_COLOR_RGB_TAG_CHAR:
                                                if (s+1 != end && isxdigit(s[1]) &&
                                                        s+2 != end && isxdigit(s[2]) &&
                                                        s+3 != end && isxdigit(s[3]) )
@@ -1786,17 +1789,8 @@ COM_StringLengthNoColors(const char *s, size_t size_s, qboolean *valid)
                                                        break;
                                                }
                                                ++len; // STRING_COLOR_TAG
-                                               ++len; // STRING_COLOR_RGB_DEFAULT
+                                               ++len; // STRING_COLOR_RGB_TAG_CHAR
                                                break;
-                                       /*case 'a':
-                                               if ( s+1 != end && ( isxdigit(s[1]) || (s[1] == '+' || s[1] == '-') ) )
-                                               {
-                                                       s++;
-                                                       break;
-                                               }
-                                               ++len; // STRING_COLOR_TAG
-                                               ++len; // STRING_COLOR_RGB_DEFAULT
-                                               break;*/
                                        case 0: // ends with unfinished color code!
                                                ++len;
                                                if(valid)
@@ -1835,7 +1829,7 @@ for example).
 
 If the output buffer size did not suffice for converting, the function returns
 FALSE. Generally, if escape_carets is false, the output buffer needs
-strlen(str)+1 bytes, and if escape_carets is true, it can need strlen(str)+2
+strlen(str)+1 bytes, and if escape_carets is true, it can need strlen(str)*1.5+2
 bytes. In any case, the function makes sure that the resulting string is
 zero terminated.
 
@@ -1861,7 +1855,7 @@ COM_StringDecolorize(const char *in, size_t size_in, char *out, size_t size_out,
                                ++in;
                                switch((in == end) ? 0 : *in)
                                {
-                                       case STRING_COLOR_RGB_DEFAULT:
+                                       case STRING_COLOR_RGB_TAG_CHAR:
                                                if (in+1 != end && isxdigit(in[1]) &&
                                                        in+2 != end && isxdigit(in[2]) &&
                                                        in+3 != end && isxdigit(in[3]) )
@@ -1869,12 +1863,11 @@ COM_StringDecolorize(const char *in, size_t size_in, char *out, size_t size_out,
                                                        in+=3;
                                                        break;
                                                }
-                                       /*case 'a':
-                                               if ( in+1 != end && ( isxdigit(in[1]) || (in[1] == '+' || in[1] == '-') ) )
-                                               {
-                                                       in++;
-                                                       break;
-                                               }*/
+                                               APPEND(STRING_COLOR_TAG);
+                                               if(escape_carets)
+                                                       APPEND(STRING_COLOR_TAG);
+                                               APPEND(STRING_COLOR_RGB_TAG_CHAR);
+                                               break;
                                        case 0: // ends with unfinished color code!
                                                APPEND(STRING_COLOR_TAG);
                                                // finish the code by appending another caret when escaping
@@ -2185,3 +2178,25 @@ strlcpy(char *dst, const char *src, size_t siz)
 }
 
 #endif  // #ifndef HAVE_STRLCPY
+
+void FindFraction(double val, int *num, int *denom, int denomMax)
+{
+       int i;
+       double bestdiff;
+       // initialize
+       bestdiff = fabs(val);
+       *num = 0;
+       *denom = 1;
+
+       for(i = 1; i <= denomMax; ++i)
+       {
+               int inum = (int) floor(0.5 + val * i);
+               double diff = fabs(val - inum / (double)i);
+               if(diff < bestdiff)
+               {
+                       bestdiff = diff;
+                       *num = inum;
+                       *denom = i;
+               }
+       }
+}