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