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