]> git.xonotic.org Git - xonotic/xonotic-data.pk3dir.git/blobdiff - qcsrc/client/miscfunctions.qc
Clean up macros
[xonotic/xonotic-data.pk3dir.git] / qcsrc / client / miscfunctions.qc
index eb91814f670bb2cfa707a1f25a32483874d1ce86..fcc248220d4af90ecdb4ad3131f66151e931d6c5 100644 (file)
@@ -1,5 +1,6 @@
 entity players;
 entity teams;
+float team_count; // real teams
 
 void AuditLists()
 {
@@ -81,6 +82,8 @@ float RegisterTeam(entity Team)
        if(teams.sort_next)
                teams.sort_next.sort_prev = Team;
        teams.sort_next = Team;
+       if(Team.team && Team.team != NUM_SPECTATOR)
+               ++team_count;
        AuditLists();
        return true;
 }
@@ -101,10 +104,12 @@ void RemoveTeam(entity Team)
        parent.sort_next = Team.sort_next;
        if(Team.sort_next)
                Team.sort_next.sort_prev = parent;
+       if(Team.team && Team.team != NUM_SPECTATOR)
+               --team_count;
        AuditLists();
 }
 
-entity GetTeam(float Team, float add)
+entity GetTeam(int Team, bool add)
 {
        float num;
        entity tm;
@@ -127,7 +132,7 @@ vector HUD_GetFontsize(string cvarname)
        if(v_x == 0)
                v = '8 8 0';
        if(v_y == 0)
-               v_y = v_x;
+               v_y = v.x;
        v_z = 0;
        return v;
 }
@@ -149,12 +154,12 @@ vector rotate(vector v, float a)
 {
        vector w = '0 0 0';
        // FTEQCC SUCKS AGAIN
-       w_x =      v_x * cos(a) + v_y * sin(a);
-       w_y = -1 * v_x * sin(a) + v_y * cos(a);
+       w_x =      v.x * cos(a) + v.y * sin(a);
+       w_y = -1 * v.x * sin(a) + v.y * cos(a);
        return w;
 }
 
-float ColorTranslateMode;
+int ColorTranslateMode;
 
 string ColorTranslateRGB(string s)
 {
@@ -192,8 +197,8 @@ vector project_3d_to_2d(vector vec)
        vec = cs_project(vec);
        if(cs_project_is_b0rked > 0)
        {
-               vec_x *= vid_conwidth / vid_width;
-               vec_y *= vid_conheight / vid_height;
+               vec.x *= vid_conwidth / vid_width;
+               vec.y *= vid_conheight / vid_height;
        }
        return vec;
 }
@@ -209,7 +214,7 @@ float expandingbox_sizefactor_from_fadelerp(float fadelerp)
 
 vector expandingbox_resize_centered_box_offset(float sz, vector boxsize, float boxxsizefactor)
 {
-       boxsize_x *= boxxsizefactor; // easier interface for text
+       boxsize.x *= boxxsizefactor; // easier interface for text
        return boxsize * (0.5 * (1 - sz));
 }
 
@@ -218,18 +223,18 @@ void drawborderlines(float thickness, vector pos, vector dim, vector color, floa
        vector line_dim = '0 0 0';
 
        // left and right lines
-       pos_x -= thickness;
+       pos.x -= thickness;
        line_dim_x = thickness;
-       line_dim_y = dim_y;
+       line_dim_y = dim.y;
        drawfill(pos, line_dim, color, theAlpha, drawflag);
-       drawfill(pos + (dim_x + thickness) * '1 0 0', line_dim, color, theAlpha, drawflag);
+       drawfill(pos + (dim.x + thickness) * '1 0 0', line_dim, color, theAlpha, drawflag);
 
        // upper and lower lines
-       pos_y -= thickness;
-       line_dim_x = dim_x + thickness * 2; // make upper and lower lines longer
+       pos.y -= thickness;
+       line_dim_x = dim.x + thickness * 2; // make upper and lower lines longer
        line_dim_y = thickness;
        drawfill(pos, line_dim, color, theAlpha, drawflag);
-       drawfill(pos + (dim_y + thickness) * '0 1 0', line_dim, color, theAlpha, drawflag);
+       drawfill(pos + (dim.y + thickness) * '0 1 0', line_dim, color, theAlpha, drawflag);
 }
 
 void drawpic_tiled(vector pos, string pic, vector sz, vector area, vector color, float theAlpha, float drawflag)
@@ -237,45 +242,45 @@ void drawpic_tiled(vector pos, string pic, vector sz, vector area, vector color,
        vector current_pos = '0 0 0', end_pos, new_size = '0 0 0', ratio = '0 0 0';
        end_pos = pos + area;
 
-       current_pos_y = pos_y;
-       while (current_pos_y < end_pos_y)
+       current_pos_y = pos.y;
+       while (current_pos.y < end_pos.y)
        {
-               current_pos_x = pos_x;
-               while (current_pos_x < end_pos_x)
+               current_pos_x = pos.x;
+               while (current_pos.x < end_pos.x)
                {
-                       new_size_x = min(sz_x, end_pos_x - current_pos_x);
-                       new_size_y = min(sz_y, end_pos_y - current_pos_y);
-                       ratio_x = new_size_x / sz_x;
-                       ratio_y = new_size_y / sz_y;
+                       new_size_x = min(sz.x, end_pos.x - current_pos.x);
+                       new_size_y = min(sz.y, end_pos.y - current_pos.y);
+                       ratio_x = new_size.x / sz.x;
+                       ratio_y = new_size.y / sz.y;
                        drawsubpic(current_pos, new_size, pic, '0 0 0', ratio, color, theAlpha, drawflag);
-                       current_pos_x += sz_x;
+                       current_pos.x += sz.x;
                }
-               current_pos_y += sz_y;
+               current_pos.y += sz.y;
        }
 }
 
 // drawpic wrapper to draw an image as large as possible with preserved aspect ratio into a box
-var float _drawpic_imgaspect;
-var vector _drawpic_imgsize;
-var vector _drawpic_sz;
-var float _drawpic_oldsz;
-var string _drawpic_picpath;
+float _drawpic_imgaspect;
+vector _drawpic_imgsize;
+vector _drawpic_sz;
+float _drawpic_oldsz;
+string _drawpic_picpath;
 #define drawpic_aspect(pos,pic,mySize,color,theAlpha,drawflag)\
        do {\
                _drawpic_imgsize = draw_getimagesize(pic);\
                if(_drawpic_imgsize != '0 0 0') {\
-                       _drawpic_imgaspect = _drawpic_imgsize_x/_drawpic_imgsize_y;\
+                       _drawpic_imgaspect = _drawpic_imgsize.x/_drawpic_imgsize.y;\
                        _drawpic_sz = mySize;\
-                       if(_drawpic_sz_x/_drawpic_sz_y > _drawpic_imgaspect) {\
-                               _drawpic_oldsz = _drawpic_sz_x;\
-                               _drawpic_sz_x = _drawpic_sz_y * _drawpic_imgaspect;\
-                               if(_drawpic_sz_x)\
-                                       drawpic(pos + eX * (_drawpic_oldsz - _drawpic_sz_x) * 0.5, pic, _drawpic_sz, color, theAlpha, drawflag);\
+                       if(_drawpic_sz.x/_drawpic_sz.y > _drawpic_imgaspect) {\
+                               _drawpic_oldsz = _drawpic_sz.x;\
+                               _drawpic_sz_x = _drawpic_sz.y * _drawpic_imgaspect;\
+                               if(_drawpic_sz.x)\
+                                       drawpic(pos + eX * (_drawpic_oldsz - _drawpic_sz.x) * 0.5, pic, _drawpic_sz, color, theAlpha, drawflag);\
                        } else {\
-                               _drawpic_oldsz = _drawpic_sz_y;\
-                               _drawpic_sz_y = _drawpic_sz_x / _drawpic_imgaspect;\
-                               if(_drawpic_sz_y)\
-                                       drawpic(pos + eY * (_drawpic_oldsz - _drawpic_sz_y) * 0.5, pic, _drawpic_sz, color, theAlpha, drawflag);\
+                               _drawpic_oldsz = _drawpic_sz.y;\
+                               _drawpic_sz_y = _drawpic_sz.x / _drawpic_imgaspect;\
+                               if(_drawpic_sz.y)\
+                                       drawpic(pos + eY * (_drawpic_oldsz - _drawpic_sz.y) * 0.5, pic, _drawpic_sz, color, theAlpha, drawflag);\
                        }\
                }\
        } while(0)
@@ -315,29 +320,30 @@ void drawpic_aspect_skin_expanding_two(vector position, string pic, vector theSc
        drawpic_aspect_skin_expanding(position, pic, theScale, rgb, theAlpha, flag, fadelerp);
        drawpic_skin(position, pic, theScale, rgb, theAlpha * fadelerp, flag);
 }
-#define SET_POS_AND_SZ_Y_ASPECT(allow_colors)\
-       float textaspect, oldsz;\
-       textaspect = stringwidth(text, allow_colors, '1 1 1' * sz_y) / sz_y;\
-       if(sz_x/sz_y > textaspect) {\
-               oldsz = sz_x;\
-               sz_x = sz_y * textaspect;\
-               pos_x += (oldsz - sz_x) * 0.5;\
-       } else {\
-               oldsz = sz_y;\
-               sz_y = sz_x / textaspect; \
-               pos_y += (oldsz - sz_y) * 0.5;\
-       }
+#define SET_POS_AND_SZ_Y_ASPECT(allow_colors) do {                                                                                                                                     \
+       float textaspect, oldsz;                                                                                                                                                                                \
+       textaspect = stringwidth(text, allow_colors, '1 1 1' * sz.y) / sz.y;                                                                                    \
+       if(sz.x/sz.y > textaspect) {                                                                                                                                                                    \
+               oldsz = sz.x;                                                                                                                                                                                           \
+               sz_x = sz.y * textaspect;                                                                                                                                                                       \
+               pos.x += (oldsz - sz.x) * 0.5;                                                                                                                                                          \
+       } else {                                                                                                                                                                                                                \
+               oldsz = sz.y;                                                                                                                                                                                           \
+               sz_y = sz.x / textaspect;                                                                                                                                                                       \
+               pos.y += (oldsz - sz.y) * 0.5;                                                                                                                                                          \
+       }                                                                                                                                                                                                                               \
+} while(0)
 
 // drawstring wrapper to draw a string as large as possible with preserved aspect ratio into a box
 void drawstring_aspect(vector pos, string text, vector sz, vector color, float theAlpha, float drawflag) {
-       SET_POS_AND_SZ_Y_ASPECT(FALSE)
-       drawstring(pos, text, '1 1 0' * sz_y, color, theAlpha, drawflag);
+       SET_POS_AND_SZ_Y_ASPECT(false);
+       drawstring(pos, text, '1 1 0' * sz.y, color, theAlpha, drawflag);
 }
 
 // drawstring wrapper to draw a colorcodedstring as large as possible with preserved aspect ratio into a box
 void drawcolorcodedstring_aspect(vector pos, string text, vector sz, float theAlpha, float drawflag) {
-       SET_POS_AND_SZ_Y_ASPECT(TRUE)
-       drawcolorcodedstring(pos, text, '1 1 0' * sz_y, theAlpha, drawflag);
+       SET_POS_AND_SZ_Y_ASPECT(true);
+       drawcolorcodedstring(pos, text, '1 1 0' * sz.y, theAlpha, drawflag);
 }
 
 vector drawfontscale;
@@ -348,7 +354,7 @@ void drawstring_expanding(vector position, string text, vector theScale, vector
 
        drawfontscale = sz * '1 1 0';
        dummyfunction(0, 0, 0, 0, 0, 0, 0, 0);
-       drawstring(position + expandingbox_resize_centered_box_offset(sz, theScale, stringwidth(text, FALSE, theScale * (sz / drawfontscale_x)) / (theScale_x * sz)), text, theScale * (sz / drawfontscale_x), rgb, theAlpha * (1 - fadelerp), flag);
+       drawstring(position + expandingbox_resize_centered_box_offset(sz, theScale, stringwidth(text, false, theScale * (sz / drawfontscale.x)) / (theScale.x * sz)), text, theScale * (sz / drawfontscale.x), rgb, theAlpha * (1 - fadelerp), flag);
        // width parameter:
        //    (scale_x * sz / drawfontscale_x) * drawfontscale_x * SIZE1 / (scale_x * sz)
        //    SIZE1
@@ -357,8 +363,8 @@ void drawstring_expanding(vector position, string text, vector theScale, vector
 
 // drawstring wrapper to draw a string as large as possible with preserved aspect ratio into a box
 void drawstring_aspect_expanding(vector pos, string text, vector sz, vector color, float theAlpha, float drawflag, float fadelerp) {
-       SET_POS_AND_SZ_Y_ASPECT(FALSE)
-       drawstring_expanding(pos, text, '1 1 0' * sz_y, color, theAlpha, drawflag, fadelerp);
+       SET_POS_AND_SZ_Y_ASPECT(false);
+       drawstring_expanding(pos, text, '1 1 0' * sz.y, color, theAlpha, drawflag, fadelerp);
 }
 
 void drawcolorcodedstring_expanding(vector position, string text, vector theScale, float theAlpha, float flag, float fadelerp)
@@ -368,13 +374,13 @@ void drawcolorcodedstring_expanding(vector position, string text, vector theScal
 
        drawfontscale = sz * '1 1 0';
        dummyfunction(0, 0, 0, 0, 0, 0, 0, 0);
-       drawcolorcodedstring(position + expandingbox_resize_centered_box_offset(sz, theScale, stringwidth(text, TRUE, theScale * (sz / drawfontscale_x)) / (theScale_x * sz)), text, theScale * (sz / drawfontscale_x), theAlpha * (1 - fadelerp), flag);
+       drawcolorcodedstring(position + expandingbox_resize_centered_box_offset(sz, theScale, stringwidth(text, true, theScale * (sz / drawfontscale.x)) / (theScale.x * sz)), text, theScale * (sz / drawfontscale.x), theAlpha * (1 - fadelerp), flag);
        drawfontscale = '1 1 0';
 }
 
 void drawcolorcodedstring_aspect_expanding(vector pos, string text, vector sz, float theAlpha, float drawflag, float fadelerp) {
-       SET_POS_AND_SZ_Y_ASPECT(TRUE)
-       drawcolorcodedstring_expanding(pos, text, '1 1 0' * sz_y, theAlpha, drawflag, fadelerp);
+       SET_POS_AND_SZ_Y_ASPECT(true);
+       drawcolorcodedstring_expanding(pos, text, '1 1 0' * sz.y, theAlpha, drawflag, fadelerp);
 }
 
 // this draws the triangles of a model DIRECTLY. Don't expect high performance, really...
@@ -392,9 +398,9 @@ float PolyDrawModelSurface(entity e, float i_s)
        {
                tri = getsurfacetriangle(e, i_s, i_t);
                R_BeginPolygon(tex, 0);
-               R_PolygonVertex(getsurfacepoint(e, i_s, tri_x), getsurfacepointattribute(e, i_s, tri_x, SPA_TEXCOORDS0), '1 1 1', 1);
-               R_PolygonVertex(getsurfacepoint(e, i_s, tri_y), getsurfacepointattribute(e, i_s, tri_y, SPA_TEXCOORDS0), '1 1 1', 1);
-               R_PolygonVertex(getsurfacepoint(e, i_s, tri_z), getsurfacepointattribute(e, i_s, tri_z, SPA_TEXCOORDS0), '1 1 1', 1);
+               R_PolygonVertex(getsurfacepoint(e, i_s, tri.x), getsurfacepointattribute(e, i_s, tri.x, SPA_TEXCOORDS0), '1 1 1', 1);
+               R_PolygonVertex(getsurfacepoint(e, i_s, tri.y), getsurfacepointattribute(e, i_s, tri.y, SPA_TEXCOORDS0), '1 1 1', 1);
+               R_PolygonVertex(getsurfacepoint(e, i_s, tri.z), getsurfacepointattribute(e, i_s, tri.z, SPA_TEXCOORDS0), '1 1 1', 1);
                R_EndPolygon();
        }
        return 1;
@@ -424,19 +430,19 @@ void DrawCircleClippedPic(vector centre, float radius, string pic, float f, vect
                // draw full rectangle
                R_BeginPolygon(pic, drawflag);
                        v = centre;                     t = '0.5 0.5 0';
-                       v_x += 0.5 * ringsize_x;        t += '0.5 0.5 0';
+                       v.x += 0.5 * ringsize.x;        t += '0.5 0.5 0';
                        R_PolygonVertex(v, t, rgb, a);
 
                        v = centre;                     t = '0.5 0.5 0';
-                       v_y += 0.5 * ringsize_y;        t += '0.5 -0.5 0';
+                       v.y += 0.5 * ringsize.y;        t += '0.5 -0.5 0';
                        R_PolygonVertex(v, t, rgb, a);
 
                        v = centre;                     t = '0.5 0.5 0';
-                       v_x -= 0.5 * ringsize_x;        t -= '0.5 0.5 0';
+                       v.x -= 0.5 * ringsize.x;        t -= '0.5 0.5 0';
                        R_PolygonVertex(v, t, rgb, a);
 
                        v = centre;                     t = '0.5 0.5 0';
-                       v_y -= 0.5 * ringsize_y;        t -= '0.5 -0.5 0';
+                       v.y -= 0.5 * ringsize.y;        t -= '0.5 -0.5 0';
                        R_PolygonVertex(v, t, rgb, a);
                R_EndPolygon();
 
@@ -448,7 +454,7 @@ void DrawCircleClippedPic(vector centre, float radius, string pic, float f, vect
                                R_PolygonVertex(v, t, rgb, a);
 
                                v = centre;                     t = '0.5 0.5 0';
-                               v_x += 0.5 * ringsize_x;        t += '0.5 0.5 0';
+                               v.x += 0.5 * ringsize.x;        t += '0.5 0.5 0';
                                R_PolygonVertex(v, t, rgb, a);
                }
        }
@@ -457,15 +463,15 @@ void DrawCircleClippedPic(vector centre, float radius, string pic, float f, vect
                // draw upper and first triangle
                R_BeginPolygon(pic, drawflag);
                        v = centre;                     t = '0.5 0.5 0';
-                       v_x += 0.5 * ringsize_x;        t += '0.5 0.5 0';
+                       v.x += 0.5 * ringsize.x;        t += '0.5 0.5 0';
                        R_PolygonVertex(v, t, rgb, a);
 
                        v = centre;                     t = '0.5 0.5 0';
-                       v_y += 0.5 * ringsize_y;        t += '0.5 -0.5 0';
+                       v.y += 0.5 * ringsize.y;        t += '0.5 -0.5 0';
                        R_PolygonVertex(v, t, rgb, a);
 
                        v = centre;                     t = '0.5 0.5 0';
-                       v_x -= 0.5 * ringsize_x;        t -= '0.5 0.5 0';
+                       v.x -= 0.5 * ringsize.x;        t -= '0.5 0.5 0';
                        R_PolygonVertex(v, t, rgb, a);
                R_EndPolygon();
                R_BeginPolygon(pic, drawflag);
@@ -473,11 +479,11 @@ void DrawCircleClippedPic(vector centre, float radius, string pic, float f, vect
                        R_PolygonVertex(v, t, rgb, a);
 
                        v = centre;                     t = '0.5 0.5 0';
-                       v_x -= 0.5 * ringsize_x;        t -= '0.5 0.5 0';
+                       v.x -= 0.5 * ringsize.x;        t -= '0.5 0.5 0';
                        R_PolygonVertex(v, t, rgb, a);
 
                        v = centre;                     t = '0.5 0.5 0';
-                       v_y -= 0.5 * ringsize_y;        t -= '0.5 -0.5 0';
+                       v.y -= 0.5 * ringsize.y;        t -= '0.5 -0.5 0';
                        R_PolygonVertex(v, t, rgb, a);
 
                d = q - 0.75;
@@ -489,15 +495,15 @@ void DrawCircleClippedPic(vector centre, float radius, string pic, float f, vect
                // draw upper triangle
                R_BeginPolygon(pic, drawflag);
                        v = centre;                     t = '0.5 0.5 0';
-                       v_x += 0.5 * ringsize_x;        t += '0.5 0.5 0';
+                       v.x += 0.5 * ringsize.x;        t += '0.5 0.5 0';
                        R_PolygonVertex(v, t, rgb, a);
 
                        v = centre;                     t = '0.5 0.5 0';
-                       v_y += 0.5 * ringsize_y;        t += '0.5 -0.5 0';
+                       v.y += 0.5 * ringsize.y;        t += '0.5 -0.5 0';
                        R_PolygonVertex(v, t, rgb, a);
 
                        v = centre;                     t = '0.5 0.5 0';
-                       v_x -= 0.5 * ringsize_x;        t -= '0.5 0.5 0';
+                       v.x -= 0.5 * ringsize.x;        t -= '0.5 0.5 0';
                        R_PolygonVertex(v, t, rgb, a);
                R_EndPolygon();
 
@@ -509,7 +515,7 @@ void DrawCircleClippedPic(vector centre, float radius, string pic, float f, vect
                                R_PolygonVertex(v, t, rgb, a);
 
                                v = centre;                     t = '0.5 0.5 0';
-                               v_x -= 0.5 * ringsize_x;        t -= '0.5 0.5 0';
+                               v.x -= 0.5 * ringsize.x;        t -= '0.5 0.5 0';
                                R_PolygonVertex(v, t, rgb, a);
                }
        }
@@ -521,11 +527,11 @@ void DrawCircleClippedPic(vector centre, float radius, string pic, float f, vect
                        R_PolygonVertex(v, t, rgb, a);
 
                        v = centre;                     t = '0.5 0.5 0';
-                       v_x += 0.5 * ringsize_x;        t += '0.5 0.5 0';
+                       v.x += 0.5 * ringsize.x;        t += '0.5 0.5 0';
                        R_PolygonVertex(v, t, rgb, a);
 
                        v = centre;                     t = '0.5 0.5 0';
-                       v_y += 0.5 * ringsize_y;        t += '0.5 -0.5 0';
+                       v.y += 0.5 * ringsize.y;        t += '0.5 -0.5 0';
                        R_PolygonVertex(v, t, rgb, a);
 
                d = q - 0.25;
@@ -542,7 +548,7 @@ void DrawCircleClippedPic(vector centre, float radius, string pic, float f, vect
                                R_PolygonVertex(v, t, rgb, a);
 
                                v = centre;                     t = '0.5 0.5 0';
-                               v_x += 0.5 * ringsize_x;        t += '0.5 0.5 0';
+                               v.x += 0.5 * ringsize.x;        t += '0.5 0.5 0';
                                R_PolygonVertex(v, t, rgb, a);
                }
        }
@@ -550,15 +556,15 @@ void DrawCircleClippedPic(vector centre, float radius, string pic, float f, vect
        if(d > 0)
        {
                        v = centre;                     t = '0.5 0.5 0';
-                       v_x += x * 0.5 * ringsize_x;    t += x * '0.5 0.5 0';
-                       v_y += y * 0.5 * ringsize_y;    t += y * '0.5 -0.5 0';
+                       v.x += x * 0.5 * ringsize.x;    t += x * '0.5 0.5 0';
+                       v.y += y * 0.5 * ringsize.y;    t += y * '0.5 -0.5 0';
                        R_PolygonVertex(v, t, rgb, a);
                R_EndPolygon();
        }
 }
 
 const vector GETPLAYERORIGIN_ERROR = '1123581321 2357111317 3141592653'; // way out of bounds for anything on the map
-vector getplayerorigin(float pl)
+vector getplayerorigin(int pl)
 {
        entity e;
 
@@ -573,15 +579,40 @@ vector getplayerorigin(float pl)
        return GETPLAYERORIGIN_ERROR;
 }
 
+float getplayeralpha(float pl)
+{
+       entity e;
+
+       e = CSQCModel_server2csqc(pl + 1);
+       if(e)
+               return e.alpha;
+
+       return 1;
+}
+
+vector getcsqcplayercolor(float pl)
+{
+       entity e;
+
+       e = CSQCModel_server2csqc(pl);
+       if(e)
+       {
+               if(e.colormap > 0)
+                       return colormapPaletteColor(((e.colormap >= 1024) ? e.colormap : stof(getplayerkeyvalue(e.colormap - 1, "colors"))) & 0x0F, true);
+       }
+
+       return '1 1 1';
+}
+
 float getplayerisdead(float pl)
 {
        entity e;
-       
+
        e = CSQCModel_server2csqc(pl + 1);
        if(e)
                return e.csqcmodel_isdead;
-       
-       return FALSE;
+
+       return false;
 }
 
 void URI_Get_Callback(float id, float status, string data)
@@ -601,7 +632,7 @@ void URI_Get_Callback(float id, float status, string data)
        }
        else
        {
-               print(sprintf("Received HTTP request data for an invalid id %d.\n", id));
+               printf("Received HTTP request data for an invalid id %d.\n", id);
        }
 }
 
@@ -616,15 +647,14 @@ void draw_endBoldFont()
 }
 
 
-#define MAX_ACCURACY_LEVELS 10
+const float MAX_ACCURACY_LEVELS = 10;
 float acc_lev[MAX_ACCURACY_LEVELS];
 vector acc_col[MAX_ACCURACY_LEVELS];
 float acc_col_loadtime;
-float acc_levels;
+int acc_levels;
 string acc_color_levels;
 void Accuracy_LoadLevels()
 {
-       float i;
        if(autocvar_accuracy_color_levels != acc_color_levels)
        {
                if(acc_color_levels)
@@ -636,6 +666,7 @@ void Accuracy_LoadLevels()
                if(acc_levels < 2)
                        print("Warning: accuracy_color_levels must contain at least 2 values\n");
 
+               int i;
                for(i = 0; i < acc_levels; ++i)
                        acc_lev[i] = stof(argv(i)) / 100.0;
        }
@@ -643,10 +674,10 @@ void Accuracy_LoadLevels()
 
 void Accuracy_LoadColors()
 {
-       float i;
        if(time > acc_col_loadtime)
        if(acc_levels >= 2)
        {
+               int i;
                for(i = 0; i < acc_levels; ++i)
                        acc_col[i] = stov(cvar_string(strcat("accuracy_color", ftos(i))));
                acc_col_loadtime = time + 2;
@@ -655,13 +686,13 @@ void Accuracy_LoadColors()
 
 vector Accuracy_GetColor(float accuracy)
 {
-       float j, factor;
+       float factor;
        vector color;
        if(acc_levels < 2)
                return '0 0 0'; // return black, can't determine the right color
 
        // find the max level lower than acc
-       j = acc_levels-1;
+       int j = acc_levels-1;
        while(j && accuracy < acc_lev[j])
                --j;