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