]> de.git.xonotic.org Git - xonotic/xonotic-data.pk3dir.git/blob - qcsrc/client/mapvoting.qc
Merge remote-tracking branch 'origin/TimePath/experiments/csqc_prediction' into TimeP...
[xonotic/xonotic-data.pk3dir.git] / qcsrc / client / mapvoting.qc
1 #include "mapvoting.qh"
2 #include "scoreboard.qh"
3
4 string MapVote_FormatMapItem(int id, string map, float _count, float maxwidth, vector fontsize)
5 {
6         string pre, post;
7         pre = sprintf("%d. ", id+1);
8         if(mv_detail)
9         {
10                 if(_count == 1)
11                         post = _(" (1 vote)");
12                 else if(_count >= 0 && mv_avail[id] == GTV_AVAILABLE)
13                         post = sprintf(_(" (%d votes)"), _count);
14                 else
15                         post = "";
16         }
17         else
18                 post = "";
19         maxwidth -= stringwidth(pre, false, fontsize) + stringwidth(post, false, fontsize);
20         map = textShortenToWidth(map, maxwidth, fontsize, stringwidth_nocolors);
21         return strcat(pre, map, post);
22 }
23
24 string GameTypeVote_DescriptionByID(int id)
25 {
26         return MapInfo_Type_Description(MapInfo_Type_FromString(mv_maps[id]));
27 }
28
29 vector MapVote_RGB(int id)
30 {
31         if(mv_avail[id] != GTV_AVAILABLE)
32                 return '1 1 1';
33         if(id == mv_ownvote)
34                 return '0 1 0';
35         else if (id == mv_selection)
36                 return '1 1 0';
37         else
38                 return '1 1 1';
39 }
40
41 void GameTypeVote_DrawGameTypeItem(vector pos, float maxh, float tsize, string gtype, string pic, float _count, int id)
42 {
43         float alpha;
44         float desc_padding = gtv_text_size.x * 3;
45         float rect_margin = hud_fontsize.y / 2;
46         vector rect_pos = pos - '0.5 0.5 0' * rect_margin;
47         vector rect_size = '1 1 0';
48         rect_size.x = tsize + rect_margin;
49         rect_size.y = maxh + rect_margin;
50         vector rgb = MapVote_RGB(id);
51         vector offset = pos;
52         float nlines = 0;
53
54         if(mv_avail_start[id] != GTV_AVAILABLE)
55                 alpha = 0.2;
56         else if ( mv_avail[id] != GTV_AVAILABLE && mv_top2_alpha)
57                 alpha = mv_top2_alpha;
58         else
59                 alpha = 1;
60
61         if(id == mv_selection && mv_avail[id] == GTV_AVAILABLE)
62         {
63                 drawfill(rect_pos, rect_size, '1 1 1', 0.1, DRAWFLAG_NORMAL);
64         }
65         if(id == mv_ownvote)
66         {
67                 drawfill(rect_pos, rect_size, rgb, 0.1*alpha, DRAWFLAG_NORMAL);
68                 drawborderlines(autocvar_scoreboard_border_thickness, rect_pos, rect_size, rgb, alpha, DRAWFLAG_NORMAL);
69         }
70
71         entity title;
72         title = spawn();
73         title.message = MapVote_FormatMapItem(id, MapInfo_Type_ToText(MapInfo_Type_FromString(gtype)),
74                                                                                   _count, tsize, gtv_text_size);
75         title.origin = pos-offset;
76
77         pos.y += gtv_text_size_small.y;
78         pos.y += gtv_text_size.y/2;
79
80         maxh -= gtv_text_size.y;
81
82         entity picent = spawn();
83         picent.origin = pos-offset;
84         picent.maxs = '1 1 0 ' * min(maxh, desc_padding) * 0.8;
85
86         pos.x += desc_padding;
87         tsize -= desc_padding;
88
89         string thelabel = GameTypeVote_DescriptionByID(id), ts;
90         entity last = title;
91         entity next = world;
92         if( thelabel != "")
93         {
94                 float i,n = tokenizebyseparator(thelabel, "\n");
95                 for(i = 0; i < n && maxh > (nlines+1)*gtv_text_size_small.y; ++i)
96                 {
97                         getWrappedLine_remaining = argv(i);
98                         while(getWrappedLine_remaining && maxh > (nlines+1)*gtv_text_size_small.y)
99                         {
100                                 ts = getWrappedLine(tsize, gtv_text_size_small, stringwidth_colors);
101                                 if (ts != "")
102                                 {
103                                         next = spawn();
104                                         next.message = ts;
105                                         next.origin = pos-offset;
106                                         last.chain = next;
107                                         last = next;
108                                         pos.y += gtv_text_size_small.y;
109                                         nlines++;
110                                 }
111                         }
112                 }
113         }
114
115         maxh -= max(nlines*gtv_text_size_small.y,picent.maxs.y);
116         if ( maxh > 0 )
117                 offset.y += maxh/2;
118         drawstring(title.origin+offset, title.message, gtv_text_size, rgb, alpha, DRAWFLAG_NORMAL);
119
120         if(pic != "")
121                 drawpic(picent.origin+offset, pic, picent.maxs, '1 1 1', alpha, DRAWFLAG_NORMAL);
122
123         for ( last = title.chain; last ; )
124         {
125                 drawstring(last.origin+offset, last.message, gtv_text_size_small, '1 1 1', alpha, DRAWFLAG_NORMAL);
126                 next = last;
127                 last = last.chain;
128                 remove(next);
129         }
130
131         remove(picent);
132         remove(title);
133 }
134
135 void MapVote_DrawMapItem(vector pos, float isize, float tsize, string map, string pic, float _count, int id)
136 {
137         vector img_size = '0 0 0';
138         vector rgb;
139         string label;
140         float text_size;
141
142         isize -= hud_fontsize.y; // respect the text when calculating the image size
143
144         rgb = MapVote_RGB(id);
145
146         img_size.y = isize;
147         img_size.x = isize / 0.75; // 4:3 x can be stretched easily, height is defined in isize
148
149         pos.y = pos.y + img_size.y;
150
151         label = MapVote_FormatMapItem(id, map, _count, tsize, hud_fontsize);
152
153         text_size = stringwidth(label, false, hud_fontsize);
154
155         float theAlpha;
156         if (mv_avail[id] != GTV_AVAILABLE && mv_top2_alpha)
157                 theAlpha = mv_top2_alpha;
158         else
159                 theAlpha = 1;
160
161         pos.x -= text_size*0.5;
162         drawstring(pos, label, hud_fontsize, rgb, theAlpha, DRAWFLAG_NORMAL);
163
164         pos.x = pos.x + text_size*0.5 - img_size.x*0.5;
165         pos.y = pos.y - img_size.y;
166
167         pos += autocvar_scoreboard_border_thickness * '1 1 0';
168         img_size -= (autocvar_scoreboard_border_thickness * 2) * '1 1 0';
169         if(pic == "")
170         {
171                 drawfill(pos, img_size, '.5 .5 .5', .7 * theAlpha, DRAWFLAG_NORMAL);
172         }
173         else
174         {
175                 if(drawgetimagesize(pic) == '0 0 0')
176                         drawpic(pos, draw_UseSkinFor("nopreview_map"), img_size, '1 1 1', theAlpha, DRAWFLAG_NORMAL);
177                 else
178                         drawpic(pos, pic, img_size, '1 1 1', theAlpha, DRAWFLAG_NORMAL);
179         }
180
181         if(id == mv_ownvote)
182                 drawborderlines(autocvar_scoreboard_border_thickness, pos, img_size, rgb, theAlpha, DRAWFLAG_NORMAL);
183         else
184                 drawborderlines(autocvar_scoreboard_border_thickness, pos, img_size, '0 0 0', theAlpha, DRAWFLAG_NORMAL);
185
186         if(id == mv_selection && mv_avail[id] == GTV_AVAILABLE)
187                 drawfill(pos, img_size, '1 1 1', 0.1, DRAWFLAG_NORMAL);
188 }
189
190 void MapVote_DrawAbstain(vector pos, float isize, float tsize, float _count, int id)
191 {
192         vector rgb;
193         float text_size;
194         string label;
195
196         rgb = MapVote_RGB(id);
197
198         pos.y = pos.y + hud_fontsize.y;
199
200         label = MapVote_FormatMapItem(id, _("Don't care"), _count, tsize, hud_fontsize);
201
202         text_size = stringwidth(label, false, hud_fontsize);
203
204         pos.x -= text_size*0.5;
205         drawstring(pos, label, hud_fontsize, rgb, 1, DRAWFLAG_NORMAL);
206 }
207
208 vector MapVote_GridVec(vector gridspec, int i, int m)
209 {
210         int r = i % m;
211         return
212                 '1 0 0' * (gridspec.x * r)
213                 +
214                 '0 1 0' * (gridspec.y * (i - r) / m);
215 }
216
217 float MapVote_Selection(vector topleft, vector cellsize, float rows, float columns)
218 {
219
220         float c, r;
221
222         mv_mouse_selection = -1;
223
224         for (r = 0; r < rows; ++r)
225                 for (c = 0; c < columns; ++c)
226                 {
227                         if (mv_mousepos.x >= topleft.x + cellsize.x *  c &&
228                                 mv_mousepos.x <= topleft.x + cellsize.x * (c + 1) &&
229                                 mv_mousepos.y >= topleft.y + cellsize.y *  r &&
230                                 mv_mousepos.y <= topleft.y + cellsize.y * (r + 1))
231                         {
232                                 mv_mouse_selection = r * columns + c;
233                                 break;
234                         }
235                 }
236
237         if (mv_mouse_selection >= mv_num_maps)
238                 mv_mouse_selection = -1;
239
240         if (mv_abstain && mv_mouse_selection < 0)
241                 mv_mouse_selection = mv_num_maps;
242
243         if ( mv_selection_keyboard )
244                 return mv_selection;
245
246         return mv_mouse_selection;
247 }
248
249 void MapVote_Draw()
250 {
251         string map;
252         int i;
253         float tmp;
254         vector pos;
255         float isize;
256         float center;
257         float rows;
258         float tsize;
259         vector dist = '0 0 0';
260
261         if(!mv_active)
262                 return;
263
264         if (!autocvar_hud_cursormode)
265         {
266                 vector mpos = mv_mousepos + getmousepos();
267                 mpos.x = bound(0, mpos.x, vid_conwidth);
268                 mpos.y = bound(0, mpos.y, vid_conheight);
269
270                 if ( mpos.x != mv_mousepos.x || mpos.y != mv_mousepos.y )
271                         mv_selection_keyboard = 0;
272                 mv_mousepos = mpos;
273
274         }
275
276         center = (vid_conwidth - 1)/2;
277         xmin = vid_conwidth*0.05; // 5% border must suffice
278         xmax = vid_conwidth - xmin;
279         ymin = 20;
280         i = autocvar_con_chatpos; //*autocvar_con_chatsize;
281         if(i < 0)
282                 ymax = vid_conheight + (i - autocvar_con_chat) * autocvar_con_chatsize;
283         if(i >= 0 || ymax < (vid_conheight*0.5))
284                 ymax = vid_conheight - ymin;
285
286         hud_fontsize = HUD_GetFontsize("hud_fontsize");
287
288         pos.y = ymin;
289         pos.z = 0;
290
291         draw_beginBoldFont();
292         map = ((gametypevote) ? _("Decide the gametype") : _("Vote for a map"));
293         pos.x = center - stringwidth(map, false, '12 0 0');
294         drawstring(pos, map, '24 24 0', '1 1 1', 1, DRAWFLAG_NORMAL);
295         pos.y += 26;
296
297         if( mapvote_chosenmap != "" )
298         {
299                 pos.x = center - stringwidth(mapvote_chosenmap, false, hud_fontsize*1.5/2);
300                 drawstring(pos, mapvote_chosenmap, hud_fontsize*1.5, '1 1 1', 1, DRAWFLAG_NORMAL);
301                 pos.y += hud_fontsize.y*2;
302         }
303
304         i = ceil(max(0, mv_timeout - time));
305         map = sprintf(_("%d seconds left"), i);
306         pos.x = center - stringwidth(map, false, '8 0 0');
307         drawstring(pos, map, '16 16 0', '0 1 0', 1, DRAWFLAG_NORMAL);
308         pos.y += 22;
309         pos.x = xmin;
310         draw_endBoldFont();
311
312         // base for multi-column stuff...
313         ymin = pos.y;
314         if(mv_abstain)
315                 mv_num_maps -= 1;
316
317         rows = ceil(mv_num_maps / mv_columns);
318
319         dist.x = (xmax - xmin) / mv_columns;
320         dist.y = (ymax - pos.y) / rows;
321
322         if ( gametypevote )
323         {
324                 tsize = dist.x - hud_fontsize.y;
325                 isize = dist.y;
326                 float maxheight = (ymax - pos.y) / 3;
327                 if ( isize > maxheight )
328                 {
329                         pos.x += (isize - maxheight)/2;
330                         isize = maxheight;
331                 }
332                 else
333                         dist.y += hud_fontsize.y;
334                 pos.x = ( vid_conwidth - dist.x * mv_columns ) / 2;
335         }
336         else
337         {
338                 tsize = dist.x - 10;
339                 isize = min(dist.y - 10, 0.75 * tsize);
340         }
341
342         mv_selection = MapVote_Selection(pos, dist, rows, mv_columns);
343
344         if ( !gametypevote )
345                 pos.x += dist.x / 2;
346         pos.y += (dist.y - isize) / 2;
347         ymax -= isize;
348
349         if (mv_top2_time)
350                 mv_top2_alpha = max(0.2, 1 - (time - mv_top2_time)*(time - mv_top2_time));
351
352         void (vector, float, float, string, string, float, float) DrawItem;
353
354         if(gametypevote)
355                 DrawItem = GameTypeVote_DrawGameTypeItem;
356         else
357                 DrawItem = MapVote_DrawMapItem;
358
359         for(i = 0; i < mv_num_maps; ++i)
360         {
361                 tmp = mv_votes[i]; // FTEQCC bug: too many array accesses in the function call screw it up
362                 map = mv_maps[i];
363                 if(mv_preview[i])
364                         DrawItem(pos + MapVote_GridVec(dist, i, mv_columns), isize, tsize, map, mv_pics[i], tmp, i);
365                 else
366                         DrawItem(pos + MapVote_GridVec(dist, i, mv_columns), isize, tsize, map, "", tmp, i);
367         }
368
369         if(mv_abstain)
370                 ++mv_num_maps;
371
372         if(mv_abstain && i < mv_num_maps) {
373                 tmp = mv_votes[i];
374                 pos.y = ymax + isize - hud_fontsize.y;
375                 pos.x = (xmax+xmin)*0.5;
376                 MapVote_DrawAbstain(pos, isize, xmax - xmin, tmp, i);
377         }
378
379         drawpic(mv_mousepos, strcat("gfx/menu/", autocvar_menu_skin, "/cursor.tga"), '32 32 0', '1 1 1', 1 - autocvar__menu_alpha, DRAWFLAG_NORMAL);
380 }
381
382 void Cmd_MapVote_MapDownload(float argc)
383 {
384         entity pak;
385
386         if(argc != 2 || !mv_pk3list)
387         {
388                 print(_("mv_mapdownload: ^3You're not supposed to use this command on your own!\n"));
389                 return;
390         }
391
392         int id = stof(argv(1));
393         for(pak = mv_pk3list; pak; pak = pak.chain)
394                 if(pak.sv_entnum == id)
395                         break;
396
397         if(!pak || pak.sv_entnum != id) {
398                 print(_("^1Error:^7 Couldn't find pak index.\n"));
399                 return;
400         }
401
402         if(PreviewExists(pak.message))
403         {
404                 mv_preview[id] = true;
405                 return;
406         } else {
407                 print(_("Requesting preview...\n"));
408                 localcmd(strcat("\ncmd mv_getpicture ", ftos(id), "\n"));
409         }
410 }
411
412 void MapVote_CheckPK3(string pic, string pk3, int id)
413 {
414         entity pak;
415         pak = spawn();
416         pak.netname = pk3;
417         pak.message = pic;
418         pak.sv_entnum = id;
419
420         pak.chain = mv_pk3list;
421         mv_pk3list = pak;
422
423         if(pk3 != "")
424         {
425                 localcmd(strcat("\ncurl --pak ", pk3, "; wait; cl_cmd mv_download ", ftos(id), "\n"));
426         }
427         else
428         {
429                 Cmd_MapVote_MapDownload(tokenize_console(strcat("mv_download ", ftos(id))));
430         }
431 }
432
433 void MapVote_CheckPic(string pic, string pk3, int id)
434 {
435         // never try to retrieve a pic for the "don't care" 'map'
436         if(mv_abstain && id == mv_num_maps - 1)
437                 return;
438
439         if(PreviewExists(pic))
440         {
441                 mv_preview[id] = true;
442                 return;
443         }
444         MapVote_CheckPK3(pic, pk3, id);
445 }
446
447 void MapVote_ReadMask()
448 {
449         int i;
450         if ( mv_num_maps < 24 )
451         {
452                 int mask, power;
453                 if(mv_num_maps < 8)
454                         mask = ReadByte();
455                 else if(mv_num_maps < 16)
456                         mask = ReadShort();
457                 else
458                         mask = ReadLong();
459
460                 for(i = 0, power = 1; i < mv_num_maps; ++i, power *= 2)
461                         mv_avail[i] = (mask & power) ? GTV_AVAILABLE : GTV_FORBIDDEN;
462         }
463         else
464         {
465                 for(i = 0; i < mv_num_maps; ++i )
466                         mv_avail[i] = ReadByte();
467         }
468 }
469
470 void MapVote_Init()
471 {
472         int i, j;
473         string map, pk3, s;
474
475         precache_sound ("misc/invshot.wav");
476
477         mv_active = 1;
478         if(autocvar_hud_cursormode) { setcursormode(1); }
479         else { mv_mousepos = '0.5 0 0' * vid_conwidth + '0 0.5 0' * vid_conheight; }
480         mv_selection = -1;
481         mv_selection_keyboard = 0;
482
483         for(n_ssdirs = 0; ; ++n_ssdirs)
484         {
485                 s = ReadString();
486                 if(s == "")
487                         break;
488                 if(n_ssdirs < NUM_SSDIRS)
489                         ssdirs[n_ssdirs] = s;
490         }
491         n_ssdirs = min(n_ssdirs, NUM_SSDIRS);
492
493         mv_num_maps = min(MAPVOTE_COUNT, ReadByte());
494         mv_abstain = ReadByte();
495         if(mv_abstain)
496                 mv_abstain = 1; // must be 1 for bool-true, makes stuff easier
497         mv_detail = ReadByte();
498
499         mv_ownvote = -1;
500         mv_timeout = ReadCoord();
501
502         gametypevote = ReadByte();
503
504         float mv_real_num_maps = mv_num_maps - mv_abstain;
505
506         if(gametypevote)
507         {
508                 mapvote_chosenmap = strzone(ReadString());
509                 if ( gametypevote == 2 )
510                         gametypevote = 0;
511
512                 gtv_text_size = hud_fontsize*1.4;
513                 gtv_text_size_small = hud_fontsize*1.1;
514
515                 if (mv_real_num_maps > 8 )
516                         mv_columns = 3;
517                 else
518                         mv_columns = min(2, mv_real_num_maps);
519     }
520     else
521         {
522                 if (mv_real_num_maps > 16)
523                         mv_columns = 5;
524                 else if (mv_real_num_maps > 9)
525                         mv_columns = 4;
526                 else if(mv_real_num_maps > 3)
527                         mv_columns = 3;
528                 else
529                         mv_columns = mv_real_num_maps;
530         }
531
532         MapVote_ReadMask();
533         for(i = 0; i < mv_num_maps; ++i )
534                 mv_avail_start[i] = mv_avail[i];
535
536         // Assume mv_pk3list is world, there should only be 1 mapvote per round
537         mv_pk3list = world; // I'm still paranoid!
538
539         for(i = 0; i < mv_num_maps; ++i)
540         {
541                 mv_votes[i] = 0;
542
543                 map = strzone(ReadString());
544                 pk3 = strzone(ReadString());
545                 j = bound(0, ReadByte(), n_ssdirs - 1);
546
547                 mv_maps[i] = map;
548                 mv_pk3[i] = pk3;
549                 mv_avail[i] = ReadByte();
550
551                 if(gametypevote)
552                 {
553                         //map = strzone(strcat("gfx/menu/default/gametype_", map));
554                         //map = strzone(sprintf("gfx/menu/%s/gametype_%s", autocvar_menu_skin, map));
555                         string mv_picpath = sprintf("gfx/menu/%s/gametype_%s", autocvar_menu_skin, map);
556                         if(precache_pic(mv_picpath) == "")
557                                 mv_picpath = strcat("gfx/menu/default/gametype_", map);
558                         map = strzone(mv_picpath);
559                         mv_pics[i] = map;
560                         mv_preview[i] = PreviewExists(map);
561                 }
562                 else
563                 {
564                         map = strzone(strcat(ssdirs[j], "/", map));
565                         mv_pics[i] = map;
566                         mv_preview[i] = false;
567                         MapVote_CheckPic(map, pk3, i);
568                 }
569         }
570
571         for(i = 0; i < n_ssdirs; ++i)
572                 ssdirs[n_ssdirs] = string_null;
573         n_ssdirs = 0;
574 }
575
576 void MapVote_SendChoice(float index)
577 {
578         localcmd(strcat("\nimpulse ", ftos(index+1), "\n"));
579 }
580
581 int MapVote_MoveLeft(int pos)
582 {
583         int imp;
584         if ( pos < 0 )
585                 imp = mv_num_maps - 1;
586         else
587                 imp = pos < 1 ? mv_num_maps - 1 : pos - 1;
588         if ( mv_avail[imp] != GTV_AVAILABLE && imp != mv_ownvote )
589                 imp = MapVote_MoveLeft(imp);
590         return imp;
591 }
592 int MapVote_MoveRight(int pos)
593 {
594         int imp;
595         if ( pos < 0 )
596                 imp = 0;
597         else
598                 imp = pos >= mv_num_maps - 1 ? 0 : pos + 1;
599         if ( mv_avail[imp] != GTV_AVAILABLE && imp != mv_ownvote )
600                 imp = MapVote_MoveRight(imp);
601         return imp;
602 }
603 int MapVote_MoveUp(int pos)
604 {
605         int imp;
606         if ( pos < 0 )
607                 imp = mv_num_maps - 1;
608         else
609         {
610                 imp = pos - mv_columns;
611                 if ( imp < 0 )
612                 {
613                         imp = floor(mv_num_maps/mv_columns)*mv_columns + pos % mv_columns;
614                         if ( imp >= mv_num_maps )
615                                 imp -= mv_columns;
616                 }
617         }
618         if ( mv_avail[imp] != GTV_AVAILABLE && imp != mv_ownvote )
619                 imp = MapVote_MoveUp(imp);
620         return imp;
621 }
622 int MapVote_MoveDown(int pos)
623 {
624         int imp;
625         if ( pos < 0 )
626                 imp = 0;
627         else
628         {
629                 imp = pos + mv_columns;
630                 if ( imp >= mv_num_maps )
631                         imp = imp % mv_columns;
632         }
633         if ( mv_avail[imp] != GTV_AVAILABLE && imp != mv_ownvote )
634                 imp = MapVote_MoveDown(imp);
635         return imp;
636 }
637
638 float MapVote_InputEvent(float bInputType, float nPrimary, float nSecondary)
639 {
640         float imp;
641
642         if (!mv_active)
643                 return false;
644
645         if(bInputType == 3)
646         {
647                 mv_mousepos.x = nPrimary;
648                 mv_mousepos.y = nSecondary;
649                 mv_selection_keyboard = 0;
650                 return true;
651         }
652
653         if (bInputType != 0)
654                 return false;
655
656         if ('0' <= nPrimary && nPrimary <= '9')
657         {
658                 imp = nPrimary - '0';
659                 if (imp == 0) imp = 10;
660                 localcmd(strcat("\nimpulse ", ftos(imp), "\n"));
661                 return true;
662         }
663         switch(nPrimary)
664         {
665                 case K_KP_1: localcmd("\nimpulse 1\n"); return true;
666                 case K_KP_2: localcmd("\nimpulse 2\n"); return true;
667                 case K_KP_3: localcmd("\nimpulse 3\n"); return true;
668                 case K_KP_4: localcmd("\nimpulse 4\n"); return true;
669                 case K_KP_5: localcmd("\nimpulse 5\n"); return true;
670                 case K_KP_6: localcmd("\nimpulse 6\n"); return true;
671                 case K_KP_7: localcmd("\nimpulse 7\n"); return true;
672                 case K_KP_8: localcmd("\nimpulse 8\n"); return true;
673                 case K_KP_9: localcmd("\nimpulse 9\n"); return true;
674                 case K_KP_0: localcmd("\nimpulse 10\n"); return true;
675
676                 case K_RIGHTARROW:
677                         mv_selection_keyboard = 1;
678                         mv_selection = MapVote_MoveRight(mv_selection);
679                         return true;
680                 case K_LEFTARROW:
681                         mv_selection_keyboard = 1;
682                         mv_selection = MapVote_MoveLeft(mv_selection);
683                         return true;
684                 case K_DOWNARROW:
685                         mv_selection_keyboard = 1;
686                         mv_selection = MapVote_MoveDown(mv_selection);
687                         return true;
688                 case K_UPARROW:
689                         mv_selection_keyboard = 1;
690                         mv_selection = MapVote_MoveUp(mv_selection);
691                         return true;
692                 case K_KP_ENTER:
693                 case K_ENTER:
694                 case K_SPACE:
695                         if ( mv_selection_keyboard )
696                                 MapVote_SendChoice(mv_selection);
697                         return true;
698         }
699
700         if (nPrimary == K_MOUSE1)
701         {
702                 mv_selection_keyboard = 0;
703                 mv_selection = mv_mouse_selection;
704                 if (mv_selection >= 0)
705                 {
706                         imp = min(mv_selection + 1, mv_num_maps);
707                         localcmd(strcat("\nimpulse ", ftos(imp), "\n"));
708                         return true;
709                 }
710         }
711
712         return false;
713 }
714
715 void MapVote_UpdateMask()
716 {
717         MapVote_ReadMask();
718         mv_top2_time = time;
719 }
720
721 void MapVote_UpdateVotes()
722 {
723         int i;
724         for(i = 0; i < mv_num_maps; ++i)
725         {
726                 if(mv_avail[i] == GTV_AVAILABLE)
727                 {
728                         if(mv_detail)
729                                 mv_votes[i] = ReadByte();
730                         else
731                                 mv_votes[i] = 0;
732                 }
733                 else
734                         mv_votes[i] = -1;
735         }
736
737         mv_ownvote = ReadByte()-1;
738 }
739
740 void Ent_MapVote()
741 {
742         int sf = ReadByte();
743
744         if(sf & 1)
745                 MapVote_Init();
746
747         if(sf & 2)
748                 MapVote_UpdateMask();
749
750         if(sf & 4)
751                 MapVote_UpdateVotes();
752 }
753
754 void Net_MapVote_Picture()
755 {
756         int type = ReadByte();
757         mv_preview[type] = true;
758         mv_pics[type] = strzone(ReadPicture());
759 }