]> de.git.xonotic.org Git - xonotic/xonotic-data.pk3dir.git/blobdiff - qcsrc/client/mapvoting.qc
Turn mapvote availability into a flag
[xonotic/xonotic-data.pk3dir.git] / qcsrc / client / mapvoting.qc
index df008d5bf249acba46233b8cbf879f904f3d2de5..bcbf1863a6ac8b1dcb0daeaa54263a933d95ddd9 100644 (file)
@@ -1,6 +1,48 @@
 #include "mapvoting.qh"
+#include "_all.qh"
+
+#include "hud.qh"
 #include "scoreboard.qh"
 
+#include "../common/mapinfo.qh"
+#include "../common/util.qh"
+
+#include "../dpdefs/keycodes.qh"
+
+
+int mv_num_maps;
+
+float mv_active;
+string mv_maps[MAPVOTE_COUNT];
+string mv_pics[MAPVOTE_COUNT];
+string mv_pk3[MAPVOTE_COUNT];
+float mv_preview[MAPVOTE_COUNT];
+float mv_votes[MAPVOTE_COUNT];
+float mv_flags[MAPVOTE_COUNT];
+float mv_flags_start[MAPVOTE_COUNT];
+entity mv_pk3list;
+float mv_abstain;
+float mv_ownvote;
+float mv_detail;
+float mv_timeout;
+float mv_top2_time;
+float mv_top2_alpha;
+
+vector mv_mousepos;
+int mv_selection;
+int mv_columns;
+int mv_mouse_selection;
+int mv_selection_keyboard;
+
+float gametypevote;
+string mapvote_chosenmap;
+vector gtv_text_size;
+vector gtv_text_size_small;
+
+const int NUM_SSDIRS = 4;
+string ssdirs[NUM_SSDIRS];
+int n_ssdirs;
+
 string MapVote_FormatMapItem(int id, string map, float _count, float maxwidth, vector fontsize)
 {
        string pre, post;
@@ -9,7 +51,7 @@ string MapVote_FormatMapItem(int id, string map, float _count, float maxwidth, v
        {
                if(_count == 1)
                        post = _(" (1 vote)");
-               else if(_count >= 0 && mv_avail[id] == GTV_AVAILABLE)
+               else if(_count >= 0 && (mv_flags[id] & GTV_AVAILABLE))
                        post = sprintf(_(" (%d votes)"), _count);
                else
                        post = "";
@@ -21,14 +63,14 @@ string MapVote_FormatMapItem(int id, string map, float _count, float maxwidth, v
        return strcat(pre, map, post);
 }
 
-string GameTypeVote_DescriptionByID(float id)
+string GameTypeVote_DescriptionByID(int id)
 {
        return MapInfo_Type_Description(MapInfo_Type_FromString(mv_maps[id]));
 }
 
 vector MapVote_RGB(int id)
 {
-       if(mv_avail[id] != GTV_AVAILABLE)
+       if(!(mv_flags[id] & GTV_AVAILABLE))
                return '1 1 1';
        if(id == mv_ownvote)
                return '0 1 0';
@@ -50,15 +92,15 @@ void GameTypeVote_DrawGameTypeItem(vector pos, float maxh, float tsize, string g
        vector rgb = MapVote_RGB(id);
        vector offset = pos;
        float nlines = 0;
-       
-       if(mv_avail_start[id] != GTV_AVAILABLE)
+
+       if(!(mv_flags_start[id] & GTV_AVAILABLE))
                alpha = 0.2;
-       else if ( mv_avail[id] != GTV_AVAILABLE && mv_top2_alpha)
+       else if ( !(mv_flags[id] & GTV_AVAILABLE) && mv_top2_alpha)
                alpha = mv_top2_alpha;
        else
                alpha = 1;
-       
-       if(id == mv_selection && mv_avail[id] == GTV_AVAILABLE)
+
+       if(id == mv_selection && (mv_flags[id] & GTV_AVAILABLE))
        {
                drawfill(rect_pos, rect_size, '1 1 1', 0.1, DRAWFLAG_NORMAL);
        }
@@ -67,29 +109,29 @@ void GameTypeVote_DrawGameTypeItem(vector pos, float maxh, float tsize, string g
                drawfill(rect_pos, rect_size, rgb, 0.1*alpha, DRAWFLAG_NORMAL);
                drawborderlines(autocvar_scoreboard_border_thickness, rect_pos, rect_size, rgb, alpha, DRAWFLAG_NORMAL);
        }
-       
+
        entity title;
        title = spawn();
-       title.message = MapVote_FormatMapItem(id, MapInfo_Type_ToText(MapInfo_Type_FromString(gtype)), 
+       title.message = MapVote_FormatMapItem(id, MapInfo_Type_ToText(MapInfo_Type_FromString(gtype)),
                                                                                  _count, tsize, gtv_text_size);
        title.origin = pos-offset;
-       
+
        pos.y += gtv_text_size_small.y;
        pos.y += gtv_text_size.y/2;
-       
+
        maxh -= gtv_text_size.y;
-       
+
        entity picent = spawn();
        picent.origin = pos-offset;
        picent.maxs = '1 1 0 ' * min(maxh, desc_padding) * 0.8;
-       
+
        pos.x += desc_padding;
        tsize -= desc_padding;
-       
+
        string thelabel = GameTypeVote_DescriptionByID(id), ts;
        entity last = title;
        entity next = world;
-       if( thelabel != "") 
+       if( thelabel != "")
        {
                float i,n = tokenizebyseparator(thelabel, "\n");
                for(i = 0; i < n && maxh > (nlines+1)*gtv_text_size_small.y; ++i)
@@ -111,15 +153,15 @@ void GameTypeVote_DrawGameTypeItem(vector pos, float maxh, float tsize, string g
                        }
                }
        }
-       
+
        maxh -= max(nlines*gtv_text_size_small.y,picent.maxs.y);
        if ( maxh > 0 )
                offset.y += maxh/2;
-       drawstring(title.origin+offset, title.message, gtv_text_size, rgb, alpha, DRAWFLAG_NORMAL); 
-       
+       drawstring(title.origin+offset, title.message, gtv_text_size, rgb, alpha, DRAWFLAG_NORMAL);
+
        if(pic != "")
                drawpic(picent.origin+offset, pic, picent.maxs, '1 1 1', alpha, DRAWFLAG_NORMAL);
-       
+
        for ( last = title.chain; last ; )
        {
                drawstring(last.origin+offset, last.message, gtv_text_size_small, '1 1 1', alpha, DRAWFLAG_NORMAL);
@@ -127,7 +169,7 @@ void GameTypeVote_DrawGameTypeItem(vector pos, float maxh, float tsize, string g
                last = last.chain;
                remove(next);
        }
-       
+
        remove(picent);
        remove(title);
 }
@@ -153,7 +195,7 @@ void MapVote_DrawMapItem(vector pos, float isize, float tsize, string map, strin
        text_size = stringwidth(label, false, hud_fontsize);
 
        float theAlpha;
-       if (mv_avail[id] != GTV_AVAILABLE && mv_top2_alpha)
+       if (!(mv_flags[id] & GTV_AVAILABLE) && mv_top2_alpha)
                theAlpha = mv_top2_alpha;
        else
                theAlpha = 1;
@@ -183,7 +225,7 @@ void MapVote_DrawMapItem(vector pos, float isize, float tsize, string map, strin
        else
                drawborderlines(autocvar_scoreboard_border_thickness, pos, img_size, '0 0 0', theAlpha, DRAWFLAG_NORMAL);
 
-       if(id == mv_selection && mv_avail[id] == GTV_AVAILABLE)
+       if(id == mv_selection && (mv_flags[id] & GTV_AVAILABLE))
                drawfill(pos, img_size, '1 1 1', 0.1, DRAWFLAG_NORMAL);
 }
 
@@ -242,7 +284,7 @@ float MapVote_Selection(vector topleft, vector cellsize, float rows, float colum
 
        if ( mv_selection_keyboard )
                return mv_selection;
-       
+
        return mv_mouse_selection;
 }
 
@@ -266,7 +308,7 @@ void MapVote_Draw()
                vector mpos = mv_mousepos + getmousepos();
                mpos.x = bound(0, mpos.x, vid_conwidth);
                mpos.y = bound(0, mpos.y, vid_conheight);
-               
+
                if ( mpos.x != mv_mousepos.x || mpos.y != mv_mousepos.y )
                        mv_selection_keyboard = 0;
                mv_mousepos = mpos;
@@ -381,7 +423,6 @@ void MapVote_Draw()
 
 void Cmd_MapVote_MapDownload(float argc)
 {
-       float id;
        entity pak;
 
        if(argc != 2 || !mv_pk3list)
@@ -390,7 +431,7 @@ void Cmd_MapVote_MapDownload(float argc)
                return;
        }
 
-       id = stof(argv(1));
+       int id = stof(argv(1));
        for(pak = mv_pk3list; pak; pak = pak.chain)
                if(pak.sv_entnum == id)
                        break;
@@ -457,14 +498,19 @@ void MapVote_ReadMask()
                        mask = ReadShort();
                else
                        mask = ReadLong();
-               
+
                for(i = 0, power = 1; i < mv_num_maps; ++i, power *= 2)
-                       mv_avail[i] = (mask & power) ? GTV_AVAILABLE : GTV_FORBIDDEN;
+               {
+                       if ( mask & power )
+                               mv_flags[i] |= GTV_AVAILABLE;
+                       else
+                               mv_flags[i] &= ~GTV_AVAILABLE;
+               }
        }
        else
        {
                for(i = 0; i < mv_num_maps; ++i )
-                       mv_avail[i] = ReadByte();
+                       mv_flags[i] = ReadByte();
        }
 }
 
@@ -501,7 +547,7 @@ void MapVote_Init()
        mv_timeout = ReadCoord();
 
        gametypevote = ReadByte();
-       
+
        float mv_real_num_maps = mv_num_maps - mv_abstain;
 
        if(gametypevote)
@@ -512,7 +558,7 @@ void MapVote_Init()
 
                gtv_text_size = hud_fontsize*1.4;
                gtv_text_size_small = hud_fontsize*1.1;
-               
+
                if (mv_real_num_maps > 8 )
                        mv_columns = 3;
                else
@@ -532,7 +578,7 @@ void MapVote_Init()
 
        MapVote_ReadMask();
        for(i = 0; i < mv_num_maps; ++i )
-               mv_avail_start[i] = mv_avail[i];
+               mv_flags_start[i] = mv_flags[i];
 
        // Assume mv_pk3list is world, there should only be 1 mapvote per round
        mv_pk3list = world; // I'm still paranoid!
@@ -547,7 +593,7 @@ void MapVote_Init()
 
                mv_maps[i] = map;
                mv_pk3[i] = pk3;
-               mv_avail[i] = ReadByte();
+               mv_flags[i] = ReadByte();
 
                if(gametypevote)
                {
@@ -582,29 +628,29 @@ void MapVote_SendChoice(float index)
 int MapVote_MoveLeft(int pos)
 {
        int imp;
-       if ( pos < 0 ) 
+       if ( pos < 0 )
                imp = mv_num_maps - 1;
        else
                imp = pos < 1 ? mv_num_maps - 1 : pos - 1;
-       if ( mv_avail[imp] != GTV_AVAILABLE && imp != mv_ownvote )
+       if ( !(mv_flags[imp] & GTV_AVAILABLE) && imp != mv_ownvote )
                imp = MapVote_MoveLeft(imp);
        return imp;
 }
 int MapVote_MoveRight(int pos)
 {
        int imp;
-       if ( pos < 0 ) 
+       if ( pos < 0 )
                imp = 0;
        else
                imp = pos >= mv_num_maps - 1 ? 0 : pos + 1;
-       if ( mv_avail[imp] != GTV_AVAILABLE && imp != mv_ownvote )
+       if ( !(mv_flags[imp] & GTV_AVAILABLE) && imp != mv_ownvote )
                imp = MapVote_MoveRight(imp);
        return imp;
 }
 int MapVote_MoveUp(int pos)
 {
        int imp;
-       if ( pos < 0 ) 
+       if ( pos < 0 )
                imp = mv_num_maps - 1;
        else
        {
@@ -616,14 +662,14 @@ int MapVote_MoveUp(int pos)
                                imp -= mv_columns;
                }
        }
-       if ( mv_avail[imp] != GTV_AVAILABLE && imp != mv_ownvote )
+       if ( !(mv_flags[imp] & GTV_AVAILABLE) && imp != mv_ownvote )
                imp = MapVote_MoveUp(imp);
        return imp;
 }
 int MapVote_MoveDown(int pos)
 {
        int imp;
-       if ( pos < 0 ) 
+       if ( pos < 0 )
                imp = 0;
        else
        {
@@ -631,7 +677,7 @@ int MapVote_MoveDown(int pos)
                if ( imp >= mv_num_maps )
                        imp = imp % mv_columns;
        }
-       if ( mv_avail[imp] != GTV_AVAILABLE && imp != mv_ownvote )
+       if ( !(mv_flags[imp] & GTV_AVAILABLE) && imp != mv_ownvote )
                imp = MapVote_MoveDown(imp);
        return imp;
 }
@@ -724,7 +770,7 @@ void MapVote_UpdateVotes()
        int i;
        for(i = 0; i < mv_num_maps; ++i)
        {
-               if(mv_avail[i] == GTV_AVAILABLE)
+               if(mv_flags[i] & GTV_AVAILABLE)
                {
                        if(mv_detail)
                                mv_votes[i] = ReadByte();