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