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