]> icculus.org git repositories - divverent/darkplaces.git/blob - menu.c
364
[divverent/darkplaces.git] / menu.c
1 /*
2 Copyright (C) 1996-1997 Id Software, Inc.
3
4 This program is free software; you can redistribute it and/or
5 modify it under the terms of the GNU General Public License
6 as published by the Free Software Foundation; either version 2
7 of the License, or (at your option) any later version.
8
9 This program is distributed in the hope that it will be useful,
10 but WITHOUT ANY WARRANTY; without even the implied warranty of
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
12
13 See the GNU General Public License for more details.
14
15 You should have received a copy of the GNU General Public License
16 along with this program; if not, write to the Free Software
17 Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
18
19 */
20 #include "quakedef.h"
21 #include "image.h"
22
23 #include "mprogdefs.h"
24
25 #define TYPE_DEMO 1
26 #define TYPE_GAME 2
27 #define TYPE_BOTH 3
28
29 mempool_t *menu_mempool;
30
31 int NehGameType;
32
33 enum m_state_e m_state;
34
35 void M_Menu_Main_f (void);
36         void M_Menu_SinglePlayer_f (void);
37                 void M_Menu_Load_f (void);
38                 void M_Menu_Save_f (void);
39         void M_Menu_MultiPlayer_f (void);
40                 void M_Menu_Setup_f (void);
41         void M_Menu_Options_f (void);
42         void M_Menu_Options_Effects_f (void);
43         void M_Menu_Options_Graphics_f (void);
44         void M_Menu_Options_ColorControl_f (void);
45                 void M_Menu_Keys_f (void);
46                 void M_Menu_Video_f (void);
47         void M_Menu_Help_f (void);
48         void M_Menu_Quit_f (void);
49 void M_Menu_LanConfig_f (void);
50 void M_Menu_GameOptions_f (void);
51 void M_Menu_ServerList_f (void);
52
53 void M_Main_Draw (void);
54         void M_SinglePlayer_Draw (void);
55                 void M_Load_Draw (void);
56                 void M_Save_Draw (void);
57         void M_MultiPlayer_Draw (void);
58                 void M_Setup_Draw (void);
59         void M_Options_Draw (void);
60         void M_Options_Effects_Draw (void);
61         void M_Options_Graphics_Draw (void);
62         void M_Options_ColorControl_Draw (void);
63                 void M_Keys_Draw (void);
64                 void M_Video_Draw (void);
65         void M_Help_Draw (void);
66         void M_Quit_Draw (void);
67 void M_LanConfig_Draw (void);
68 void M_GameOptions_Draw (void);
69 void M_ServerList_Draw (void);
70
71 void M_Main_Key (int key, char ascii);
72         void M_SinglePlayer_Key (int key, char ascii);
73                 void M_Load_Key (int key, char ascii);
74                 void M_Save_Key (int key, char ascii);
75         void M_MultiPlayer_Key (int key, char ascii);
76                 void M_Setup_Key (int key, char ascii);
77         void M_Options_Key (int key, char ascii);
78         void M_Options_Effects_Key (int key, char ascii);
79         void M_Options_Graphics_Key (int key, char ascii);
80         void M_Options_ColorControl_Key (int key, char ascii);
81                 void M_Keys_Key (int key, char ascii);
82                 void M_Video_Key (int key, char ascii);
83         void M_Help_Key (int key, char ascii);
84         void M_Quit_Key (int key, char ascii);
85 void M_LanConfig_Key (int key, char ascii);
86 void M_GameOptions_Key (int key, char ascii);
87 void M_ServerList_Key (int key, char ascii);
88
89 qboolean        m_entersound;           // play after drawing a frame, so caching
90                                                                 // won't disrupt the sound
91
92 char            m_return_reason [32];
93
94 #define StartingGame    (m_multiplayer_cursor == 1)
95 #define JoiningGame             (m_multiplayer_cursor == 0)
96
97 // Nehahra
98 #define NumberOfNehahraDemos 34
99 typedef struct
100 {
101         char *name;
102         char *desc;
103 } nehahrademonames_t;
104
105 nehahrademonames_t NehahraDemos[NumberOfNehahraDemos] =
106 {
107         {"intro", "Prologue"},
108         {"genf", "The Beginning"},
109         {"genlab", "A Doomed Project"},
110         {"nehcre", "The New Recruits"},
111         {"maxneh", "Breakthrough"},
112         {"maxchar", "Renewal and Duty"},
113         {"crisis", "Worlds Collide"},
114         {"postcris", "Darkening Skies"},
115         {"hearing", "The Hearing"},
116         {"getjack", "On a Mexican Radio"},
117         {"prelude", "Honor and Justice"},
118         {"abase", "A Message Sent"},
119         {"effect", "The Other Side"},
120         {"uhoh", "Missing in Action"},
121         {"prepare", "The Response"},
122         {"vision", "Farsighted Eyes"},
123         {"maxturns", "Enter the Immortal"},
124         {"backlot", "Separate Ways"},
125         {"maxside", "The Ancient Runes"},
126         {"counter", "The New Initiative"},
127         {"warprep", "Ghosts to the World"},
128         {"counter1", "A Fate Worse Than Death"},
129         {"counter2", "Friendly Fire"},
130         {"counter3", "Minor Setback"},
131         {"madmax", "Scores to Settle"},
132         {"quake", "One Man"},
133         {"cthmm", "Shattered Masks"},
134         {"shades", "Deal with the Dead"},
135         {"gophil", "An Unlikely Hero"},
136         {"cstrike", "War in Hell"},
137         {"shubset", "The Conspiracy"},
138         {"shubdie", "Even Death May Die"},
139         {"newranks", "An Empty Throne"},
140         {"seal", "The Seal is Broken"}
141 };
142
143 float menu_x, menu_y, menu_width, menu_height;
144
145 void M_Background(int width, int height)
146 {
147         menu_width = width;
148         menu_height = height;
149         menu_x = (vid.conwidth - menu_width) * 0.5;
150         menu_y = (vid.conheight - menu_height) * 0.5;
151         //DrawQ_Fill(menu_x, menu_y, menu_width, menu_height, 0, 0, 0, 0.5, 0);
152         DrawQ_Fill(0, 0, vid.conwidth, vid.conheight, 0, 0, 0, 0.5, 0);
153 }
154
155 /*
156 ================
157 M_DrawCharacter
158
159 Draws one solid graphics character
160 ================
161 */
162 void M_DrawCharacter (float cx, float cy, int num)
163 {
164         char temp[2];
165         temp[0] = num;
166         temp[1] = 0;
167         DrawQ_String(menu_x + cx, menu_y + cy, temp, 1, 8, 8, 1, 1, 1, 1, 0);
168 }
169
170 void M_Print(float cx, float cy, const char *str)
171 {
172         DrawQ_String(menu_x + cx, menu_y + cy, str, 0, 8, 8, 1, 1, 1, 1, 0);
173 }
174
175 void M_PrintRed (float cx, float cy, const char *str)
176 {
177         DrawQ_String(menu_x + cx, menu_y + cy, str, 0, 8, 8, 1, 0, 0, 1, 0);
178 }
179
180 void M_ItemPrint(float cx, float cy, char *str, int unghosted)
181 {
182         if (unghosted)
183                 DrawQ_String(menu_x + cx, menu_y + cy, str, 0, 8, 8, 1, 1, 1, 1, 0);
184         else
185                 DrawQ_String(menu_x + cx, menu_y + cy, str, 0, 8, 8, 0.4, 0.4, 0.4, 1, 0);
186 }
187
188 void M_DrawPic (float cx, float cy, char *picname)
189 {
190         DrawQ_Pic (menu_x + cx, menu_y + cy, picname, 0, 0, 1, 1, 1, 1, 0);
191 }
192
193 qbyte identityTable[256];
194 qbyte translationTable[256];
195
196 void M_BuildTranslationTable(int top, int bottom)
197 {
198         int j;
199         qbyte *dest, *source;
200
201         for (j = 0; j < 256; j++)
202                 identityTable[j] = j;
203         dest = translationTable;
204         source = identityTable;
205         memcpy (dest, source, 256);
206
207         // LordHavoc: corrected skin color ranges
208         if (top < 128 || (top >= 224 && top < 240))     // the artists made some backwards ranges.  sigh.
209                 memcpy (dest + TOP_RANGE, source + top, 16);
210         else
211                 for (j=0 ; j<16 ; j++)
212                         dest[TOP_RANGE+j] = source[top+15-j];
213
214         // LordHavoc: corrected skin color ranges
215         if (bottom < 128 || (bottom >= 224 && bottom < 240))
216                 memcpy (dest + BOTTOM_RANGE, source + bottom, 16);
217         else
218                 for (j=0 ; j<16 ; j++)
219                         dest[BOTTOM_RANGE+j] = source[bottom+15-j];
220 }
221
222
223 void M_DrawTextBox (float x, float y, float width, float height)
224 {
225         int n;
226         float cx, cy;
227
228         // draw left side
229         cx = x;
230         cy = y;
231         M_DrawPic (cx, cy, "gfx/box_tl.lmp");
232         for (n = 0; n < height; n++)
233         {
234                 cy += 8;
235                 M_DrawPic (cx, cy, "gfx/box_ml.lmp");
236         }
237         M_DrawPic (cx, cy+8, "gfx/box_bl.lmp");
238
239         // draw middle
240         cx += 8;
241         while (width > 0)
242         {
243                 cy = y;
244                 M_DrawPic (cx, cy, "gfx/box_tm.lmp");
245                 for (n = 0; n < height; n++)
246                 {
247                         cy += 8;
248                         if (n >= 1)
249                                 M_DrawPic (cx, cy, "gfx/box_mm2.lmp");
250                         else
251                                 M_DrawPic (cx, cy, "gfx/box_mm.lmp");
252                 }
253                 M_DrawPic (cx, cy+8, "gfx/box_bm.lmp");
254                 width -= 2;
255                 cx += 16;
256         }
257
258         // draw right side
259         cy = y;
260         M_DrawPic (cx, cy, "gfx/box_tr.lmp");
261         for (n = 0; n < height; n++)
262         {
263                 cy += 8;
264                 M_DrawPic (cx, cy, "gfx/box_mr.lmp");
265         }
266         M_DrawPic (cx, cy+8, "gfx/box_br.lmp");
267 }
268
269 //=============================================================================
270
271 //int m_save_demonum;
272
273 /*
274 ================
275 M_ToggleMenu_f
276 ================
277 */
278 void M_ToggleMenu_f (void)
279 {
280         m_entersound = true;
281
282         if (key_dest != key_menu || m_state != m_main)
283                 M_Menu_Main_f ();
284         else
285         {
286                 key_dest = key_game;
287                 m_state = m_none;
288         }
289 }
290
291
292 int demo_cursor;
293 void M_Demo_Draw (void)
294 {
295         int i;
296
297         M_Background(320, 200);
298
299         for (i = 0;i < NumberOfNehahraDemos;i++)
300                 M_Print(16, 16 + 8*i, NehahraDemos[i].desc);
301
302         // line cursor
303         M_DrawCharacter (8, 16 + demo_cursor*8, 12+((int)(realtime*4)&1));
304 }
305
306
307 void M_Menu_Demos_f (void)
308 {
309         key_dest = key_menu;
310         m_state = m_demo;
311         m_entersound = true;
312 }
313
314 void M_Demo_Key (int k, char ascii)
315 {
316         switch (k)
317         {
318         case K_ESCAPE:
319                 M_Menu_Main_f ();
320                 break;
321
322         case K_ENTER:
323                 S_LocalSound ("misc/menu2.wav", true);
324                 m_state = m_none;
325                 key_dest = key_game;
326                 Cbuf_AddText (va ("playdemo %s\n", NehahraDemos[demo_cursor].name));
327                 return;
328
329         case K_UPARROW:
330         case K_LEFTARROW:
331                 S_LocalSound ("misc/menu1.wav", true);
332                 demo_cursor--;
333                 if (demo_cursor < 0)
334                         demo_cursor = NumberOfNehahraDemos-1;
335                 break;
336
337         case K_DOWNARROW:
338         case K_RIGHTARROW:
339                 S_LocalSound ("misc/menu1.wav", true);
340                 demo_cursor++;
341                 if (demo_cursor >= NumberOfNehahraDemos)
342                         demo_cursor = 0;
343                 break;
344         }
345 }
346
347 //=============================================================================
348 /* MAIN MENU */
349
350 int     m_main_cursor;
351
352 int MAIN_ITEMS = 4; // Nehahra: Menu Disable
353
354 void M_Menu_Main_f (void)
355 {
356         if (gamemode == GAME_NEHAHRA)
357         {
358                 if (NehGameType == TYPE_DEMO)
359                         MAIN_ITEMS = 4;
360                 else if (NehGameType == TYPE_GAME)
361                         MAIN_ITEMS = 5;
362                 else
363                         MAIN_ITEMS = 6;
364         }
365         else
366                 MAIN_ITEMS = 5;
367
368         /*
369         if (key_dest != key_menu)
370         {
371                 m_save_demonum = cls.demonum;
372                 cls.demonum = -1;
373         }
374         */
375         key_dest = key_menu;
376         m_state = m_main;
377         m_entersound = true;
378 }
379
380
381 void M_Main_Draw (void)
382 {
383         int             f;
384         cachepic_t      *p;
385
386         M_Background(320, 200);
387
388         M_DrawPic (16, 4, "gfx/qplaque.lmp");
389         p = Draw_CachePic ("gfx/ttl_main.lmp");
390         M_DrawPic ( (320-p->width)/2, 4, "gfx/ttl_main.lmp");
391 // Nehahra
392         if (gamemode == GAME_NEHAHRA)
393         {
394                 if (NehGameType == TYPE_BOTH)
395                         M_DrawPic (72, 32, "gfx/mainmenu.lmp");
396                 else if (NehGameType == TYPE_GAME)
397                         M_DrawPic (72, 32, "gfx/gamemenu.lmp");
398                 else
399                         M_DrawPic (72, 32, "gfx/demomenu.lmp");
400         }
401         else
402                 M_DrawPic (72, 32, "gfx/mainmenu.lmp");
403
404         f = (int)(realtime * 10)%6;
405
406         M_DrawPic (54, 32 + m_main_cursor * 20, va("gfx/menudot%i.lmp", f+1));
407 }
408
409
410 void M_Main_Key (int key, char ascii)
411 {
412         switch (key)
413         {
414         case K_ESCAPE:
415                 key_dest = key_game;
416                 m_state = m_none;
417                 //cls.demonum = m_save_demonum;
418                 //if (cls.demonum != -1 && !cls.demoplayback && cls.state != ca_connected)
419                 //      CL_NextDemo ();
420                 break;
421
422         case K_DOWNARROW:
423                 S_LocalSound ("misc/menu1.wav", true);
424                 if (++m_main_cursor >= MAIN_ITEMS)
425                         m_main_cursor = 0;
426                 break;
427
428         case K_UPARROW:
429                 S_LocalSound ("misc/menu1.wav", true);
430                 if (--m_main_cursor < 0)
431                         m_main_cursor = MAIN_ITEMS - 1;
432                 break;
433
434         case K_ENTER:
435                 m_entersound = true;
436
437                 if (gamemode == GAME_NEHAHRA)
438                 {
439                         switch (NehGameType)
440                         {
441                         case TYPE_BOTH:
442                                 switch (m_main_cursor)
443                                 {
444                                 case 0:
445                                         M_Menu_SinglePlayer_f ();
446                                         break;
447
448                                 case 1:
449                                         M_Menu_Demos_f ();
450                                         break;
451
452                                 case 2:
453                                         M_Menu_MultiPlayer_f ();
454                                         break;
455
456                                 case 3:
457                                         M_Menu_Options_f ();
458                                         break;
459
460                                 case 4:
461                                         key_dest = key_game;
462                                         if (sv.active)
463                                                 Cbuf_AddText ("disconnect\n");
464                                         Cbuf_AddText ("playdemo endcred\n");
465                                         break;
466
467                                 case 5:
468                                         M_Menu_Quit_f ();
469                                         break;
470                                 }
471                                 break;
472                         case TYPE_GAME:
473                                 switch (m_main_cursor)
474                                 {
475                                 case 0:
476                                         M_Menu_SinglePlayer_f ();
477                                         break;
478
479                                 case 1:
480                                         M_Menu_MultiPlayer_f ();
481                                         break;
482
483                                 case 2:
484                                         M_Menu_Options_f ();
485                                         break;
486
487                                 case 3:
488                                         key_dest = key_game;
489                                         if (sv.active)
490                                                 Cbuf_AddText ("disconnect\n");
491                                         Cbuf_AddText ("playdemo endcred\n");
492                                         break;
493
494                                 case 4:
495                                         M_Menu_Quit_f ();
496                                         break;
497                                 }
498                                 break;
499                         case TYPE_DEMO:
500                                 switch (m_main_cursor)
501                                 {
502                                 case 0:
503                                         M_Menu_Demos_f ();
504                                         break;
505
506                                 case 1:
507                                         key_dest = key_game;
508                                         if (sv.active)
509                                                 Cbuf_AddText ("disconnect\n");
510                                         Cbuf_AddText ("playdemo endcred\n");
511                                         break;
512
513                                 case 2:
514                                         M_Menu_Options_f ();
515                                         break;
516
517                                 case 3:
518                                         M_Menu_Quit_f ();
519                                         break;
520                                 }
521                                 break;
522                         }
523                 }
524                 else
525                 {
526                         switch (m_main_cursor)
527                         {
528                         case 0:
529                                 M_Menu_SinglePlayer_f ();
530                                 break;
531
532                         case 1:
533                                 M_Menu_MultiPlayer_f ();
534                                 break;
535
536                         case 2:
537                                 M_Menu_Options_f ();
538                                 break;
539
540                         case 3:
541                                 M_Menu_Help_f ();
542                                 break;
543
544                         case 4:
545                                 M_Menu_Quit_f ();
546                                 break;
547                         }
548                 }
549         }
550 }
551
552 //=============================================================================
553 /* SINGLE PLAYER MENU */
554
555 int     m_singleplayer_cursor;
556 #define SINGLEPLAYER_ITEMS      3
557
558
559 void M_Menu_SinglePlayer_f (void)
560 {
561         key_dest = key_menu;
562         m_state = m_singleplayer;
563         m_entersound = true;
564 }
565
566
567 void M_SinglePlayer_Draw (void)
568 {
569         cachepic_t      *p;
570
571         M_Background(320, 200);
572
573         M_DrawPic (16, 4, "gfx/qplaque.lmp");
574         p = Draw_CachePic ("gfx/ttl_sgl.lmp");
575
576         // Transfusion doesn't have a single player mode
577         if (gamemode == GAME_TRANSFUSION || gamemode == GAME_NEXUIZ || gamemode == GAME_GOODVSBAD2 || gamemode == GAME_BATTLEMECH)
578         {
579                 M_DrawPic ((320 - p->width) / 2, 4, "gfx/ttl_sgl.lmp");
580
581                 M_DrawTextBox (60, 8 * 8, 23, 4);
582                 if (gamemode == GAME_NEXUIZ)
583                         M_Print(95, 10 * 8, "Nexuiz is for");
584                 else if (gamemode == GAME_GOODVSBAD2)
585                         M_Print(95, 10 * 8, "Good Vs Bad 2 is for");
586                 else if (gamemode == GAME_BATTLEMECH)
587                         M_Print(95, 10 * 8, "Battlemech is for");
588                 else
589                         M_Print(95, 10 * 8, "Transfusion is for");
590                 M_Print(83, 11 * 8, "multiplayer play only");
591         }
592         else
593         {
594                 int             f;
595
596                 M_DrawPic ( (320-p->width)/2, 4, "gfx/ttl_sgl.lmp");
597                 M_DrawPic (72, 32, "gfx/sp_menu.lmp");
598
599                 f = (int)(realtime * 10)%6;
600
601                 M_DrawPic (54, 32 + m_singleplayer_cursor * 20, va("gfx/menudot%i.lmp", f+1));
602         }
603 }
604
605
606 void M_SinglePlayer_Key (int key, char ascii)
607 {
608         if (gamemode == GAME_TRANSFUSION || gamemode == GAME_NEXUIZ || gamemode == GAME_GOODVSBAD2 || gamemode == GAME_BATTLEMECH)
609         {
610                 if (key == K_ESCAPE || key == K_ENTER)
611                         m_state = m_main;
612                 return;
613         }
614
615         switch (key)
616         {
617         case K_ESCAPE:
618                 M_Menu_Main_f ();
619                 break;
620
621         case K_DOWNARROW:
622                 S_LocalSound ("misc/menu1.wav", true);
623                 if (++m_singleplayer_cursor >= SINGLEPLAYER_ITEMS)
624                         m_singleplayer_cursor = 0;
625                 break;
626
627         case K_UPARROW:
628                 S_LocalSound ("misc/menu1.wav", true);
629                 if (--m_singleplayer_cursor < 0)
630                         m_singleplayer_cursor = SINGLEPLAYER_ITEMS - 1;
631                 break;
632
633         case K_ENTER:
634                 m_entersound = true;
635
636                 switch (m_singleplayer_cursor)
637                 {
638                 case 0:
639                         key_dest = key_game;
640                         if (sv.active)
641                                 Cbuf_AddText ("disconnect\n");
642                         Cbuf_AddText ("maxplayers 1\n");
643                         Cbuf_AddText ("deathmatch 0\n");
644                         Cbuf_AddText ("coop 0\n");
645                         if (gamemode == GAME_NEHAHRA)
646                                 Cbuf_AddText ("map nehstart\n");
647                         else
648                                 Cbuf_AddText ("map start\n");
649                         break;
650
651                 case 1:
652                         M_Menu_Load_f ();
653                         break;
654
655                 case 2:
656                         M_Menu_Save_f ();
657                         break;
658                 }
659         }
660 }
661
662 //=============================================================================
663 /* LOAD/SAVE MENU */
664
665 int             load_cursor;            // 0 < load_cursor < MAX_SAVEGAMES
666
667 #define MAX_SAVEGAMES           12
668 char    m_filenames[MAX_SAVEGAMES][SAVEGAME_COMMENT_LENGTH+1];
669 int             loadable[MAX_SAVEGAMES];
670
671 void M_ScanSaves (void)
672 {
673         int             i, j;
674         char    name[MAX_OSPATH];
675         char    *str;
676         qfile_t *f;
677         int             version;
678
679         for (i=0 ; i<MAX_SAVEGAMES ; i++)
680         {
681                 strcpy (m_filenames[i], "--- UNUSED SLOT ---");
682                 loadable[i] = false;
683                 sprintf (name, "s%i.sav", i);
684                 f = FS_Open (name, "r", false);
685                 if (!f)
686                         continue;
687                 str = FS_Getline (f);
688                 sscanf (str, "%i\n", &version);
689                 str = FS_Getline (f);
690                 strlcpy (m_filenames[i], str, sizeof (m_filenames[i]));
691
692         // change _ back to space
693                 for (j=0 ; j<SAVEGAME_COMMENT_LENGTH ; j++)
694                         if (m_filenames[i][j] == '_')
695                                 m_filenames[i][j] = ' ';
696                 loadable[i] = true;
697                 FS_Close (f);
698         }
699 }
700
701 void M_Menu_Load_f (void)
702 {
703         m_entersound = true;
704         m_state = m_load;
705         key_dest = key_menu;
706         M_ScanSaves ();
707 }
708
709
710 void M_Menu_Save_f (void)
711 {
712         if (!sv.active)
713                 return;
714         if (cl.intermission)
715                 return;
716         if (!cl.islocalgame)
717                 return;
718         m_entersound = true;
719         m_state = m_save;
720         key_dest = key_menu;
721         M_ScanSaves ();
722 }
723
724
725 void M_Load_Draw (void)
726 {
727         int             i;
728         cachepic_t      *p;
729
730         M_Background(320, 200);
731
732         p = Draw_CachePic ("gfx/p_load.lmp");
733         M_DrawPic ( (320-p->width)/2, 4, "gfx/p_load.lmp");
734
735         for (i=0 ; i< MAX_SAVEGAMES; i++)
736                 M_Print(16, 32 + 8*i, m_filenames[i]);
737
738 // line cursor
739         M_DrawCharacter (8, 32 + load_cursor*8, 12+((int)(realtime*4)&1));
740 }
741
742
743 void M_Save_Draw (void)
744 {
745         int             i;
746         cachepic_t      *p;
747
748         M_Background(320, 200);
749
750         p = Draw_CachePic ("gfx/p_save.lmp");
751         M_DrawPic ( (320-p->width)/2, 4, "gfx/p_save.lmp");
752
753         for (i=0 ; i<MAX_SAVEGAMES ; i++)
754                 M_Print(16, 32 + 8*i, m_filenames[i]);
755
756 // line cursor
757         M_DrawCharacter (8, 32 + load_cursor*8, 12+((int)(realtime*4)&1));
758 }
759
760
761 void M_Load_Key (int k, char ascii)
762 {
763         switch (k)
764         {
765         case K_ESCAPE:
766                 M_Menu_SinglePlayer_f ();
767                 break;
768
769         case K_ENTER:
770                 S_LocalSound ("misc/menu2.wav", true);
771                 if (!loadable[load_cursor])
772                         return;
773                 m_state = m_none;
774                 key_dest = key_game;
775
776                 // issue the load command
777                 Cbuf_AddText (va ("load s%i\n", load_cursor) );
778                 return;
779
780         case K_UPARROW:
781         case K_LEFTARROW:
782                 S_LocalSound ("misc/menu1.wav", true);
783                 load_cursor--;
784                 if (load_cursor < 0)
785                         load_cursor = MAX_SAVEGAMES-1;
786                 break;
787
788         case K_DOWNARROW:
789         case K_RIGHTARROW:
790                 S_LocalSound ("misc/menu1.wav", true);
791                 load_cursor++;
792                 if (load_cursor >= MAX_SAVEGAMES)
793                         load_cursor = 0;
794                 break;
795         }
796 }
797
798
799 void M_Save_Key (int k, char ascii)
800 {
801         switch (k)
802         {
803         case K_ESCAPE:
804                 M_Menu_SinglePlayer_f ();
805                 break;
806
807         case K_ENTER:
808                 m_state = m_none;
809                 key_dest = key_game;
810                 Cbuf_AddText (va("save s%i\n", load_cursor));
811                 return;
812
813         case K_UPARROW:
814         case K_LEFTARROW:
815                 S_LocalSound ("misc/menu1.wav", true);
816                 load_cursor--;
817                 if (load_cursor < 0)
818                         load_cursor = MAX_SAVEGAMES-1;
819                 break;
820
821         case K_DOWNARROW:
822         case K_RIGHTARROW:
823                 S_LocalSound ("misc/menu1.wav", true);
824                 load_cursor++;
825                 if (load_cursor >= MAX_SAVEGAMES)
826                         load_cursor = 0;
827                 break;
828         }
829 }
830
831 //=============================================================================
832 /* MULTIPLAYER MENU */
833
834 int     m_multiplayer_cursor;
835 #define MULTIPLAYER_ITEMS       3
836
837
838 void M_Menu_MultiPlayer_f (void)
839 {
840         key_dest = key_menu;
841         m_state = m_multiplayer;
842         m_entersound = true;
843 }
844
845
846 void M_MultiPlayer_Draw (void)
847 {
848         int             f;
849         cachepic_t      *p;
850
851         M_Background(320, 200);
852
853         M_DrawPic (16, 4, "gfx/qplaque.lmp");
854         p = Draw_CachePic ("gfx/p_multi.lmp");
855         M_DrawPic ( (320-p->width)/2, 4, "gfx/p_multi.lmp");
856         M_DrawPic (72, 32, "gfx/mp_menu.lmp");
857
858         f = (int)(realtime * 10)%6;
859
860         M_DrawPic (54, 32 + m_multiplayer_cursor * 20, va("gfx/menudot%i.lmp", f+1));
861 }
862
863
864 void M_MultiPlayer_Key (int key, char ascii)
865 {
866         switch (key)
867         {
868         case K_ESCAPE:
869                 M_Menu_Main_f ();
870                 break;
871
872         case K_DOWNARROW:
873                 S_LocalSound ("misc/menu1.wav", true);
874                 if (++m_multiplayer_cursor >= MULTIPLAYER_ITEMS)
875                         m_multiplayer_cursor = 0;
876                 break;
877
878         case K_UPARROW:
879                 S_LocalSound ("misc/menu1.wav", true);
880                 if (--m_multiplayer_cursor < 0)
881                         m_multiplayer_cursor = MULTIPLAYER_ITEMS - 1;
882                 break;
883
884         case K_ENTER:
885                 m_entersound = true;
886                 switch (m_multiplayer_cursor)
887                 {
888                 case 0:
889                 case 1:
890                         M_Menu_LanConfig_f ();
891                         break;
892
893                 case 2:
894                         M_Menu_Setup_f ();
895                         break;
896                 }
897         }
898 }
899
900 //=============================================================================
901 /* SETUP MENU */
902
903 int             setup_cursor = 4;
904 int             setup_cursor_table[] = {40, 64, 88, 124, 140};
905
906 char    setup_myname[32];
907 int             setup_oldtop;
908 int             setup_oldbottom;
909 int             setup_top;
910 int             setup_bottom;
911 int             setup_rate;
912 int             setup_oldrate;
913
914 #define NUM_SETUP_CMDS  5
915
916 void M_Menu_Setup_f (void)
917 {
918         key_dest = key_menu;
919         m_state = m_setup;
920         m_entersound = true;
921         strcpy(setup_myname, cl_name.string);
922         setup_top = setup_oldtop = cl_color.integer >> 4;
923         setup_bottom = setup_oldbottom = cl_color.integer & 15;
924         setup_rate = cl_rate.integer;
925 }
926
927 static int menuplyr_width, menuplyr_height, menuplyr_top, menuplyr_bottom, menuplyr_load;
928 static qbyte *menuplyr_pixels;
929 static unsigned int *menuplyr_translated;
930
931 typedef struct ratetable_s
932 {
933         int rate;
934         char *name;
935 }
936 ratetable_t;
937
938 #define RATES ((int)(sizeof(setup_ratetable)/sizeof(setup_ratetable[0])))
939 static ratetable_t setup_ratetable[] =
940 {
941         {1000, "28.8 bad"},
942         {1500, "28.8 mediocre"},
943         {2000, "28.8 good"},
944         {2500, "33.6 mediocre"},
945         {3000, "33.6 good"},
946         {3500, "56k bad"},
947         {4000, "56k mediocre"},
948         {4500, "56k adequate"},
949         {5000, "56k good"},
950         {7000, "64k ISDN"},
951         {15000, "128k ISDN"},
952         {25000, "broadband"}
953 };
954
955 static int setup_rateindex(int rate)
956 {
957         int i;
958         for (i = 0;i < RATES;i++)
959                 if (setup_ratetable[i].rate > setup_rate)
960                         break;
961         return bound(1, i, RATES) - 1;
962 }
963
964 void M_Setup_Draw (void)
965 {
966         int i;
967         cachepic_t      *p;
968
969         M_Background(320, 200);
970
971         M_DrawPic (16, 4, "gfx/qplaque.lmp");
972         p = Draw_CachePic ("gfx/p_multi.lmp");
973         M_DrawPic ( (320-p->width)/2, 4, "gfx/p_multi.lmp");
974
975         M_Print(64, 40, "Your name");
976         M_DrawTextBox (160, 32, 16, 1);
977         M_Print(168, 40, setup_myname);
978
979         if (gamemode != GAME_GOODVSBAD2)
980         {
981                 M_Print(64, 64, "Shirt color");
982                 M_Print(64, 88, "Pants color");
983         }
984
985         M_Print(64, 124-8, "Network speed limit");
986         M_Print(168, 124, va("%i (%s)", setup_rate, setup_ratetable[setup_rateindex(setup_rate)].name));
987
988         M_DrawTextBox (64, 140-8, 14, 1);
989         M_Print(72, 140, "Accept Changes");
990
991         // LordHavoc: rewrote this code greatly
992         if (menuplyr_load)
993         {
994                 qbyte *data, *f;
995                 menuplyr_load = false;
996                 menuplyr_top = -1;
997                 menuplyr_bottom = -1;
998                 if ((f = FS_LoadFile("gfx/menuplyr.lmp", tempmempool, true)))
999                 {
1000                         data = LoadLMPAs8Bit (f, 0, 0);
1001                         menuplyr_width = image_width;
1002                         menuplyr_height = image_height;
1003                         Mem_Free(f);
1004                         menuplyr_pixels = Mem_Alloc(menu_mempool, menuplyr_width * menuplyr_height);
1005                         menuplyr_translated = Mem_Alloc(menu_mempool, menuplyr_width * menuplyr_height * 4);
1006                         memcpy(menuplyr_pixels, data, menuplyr_width * menuplyr_height);
1007                         Mem_Free(data);
1008                 }
1009         }
1010
1011         if (menuplyr_pixels)
1012         {
1013                 if (menuplyr_top != setup_top || menuplyr_bottom != setup_bottom)
1014                 {
1015                         menuplyr_top = setup_top;
1016                         menuplyr_bottom = setup_bottom;
1017                         M_BuildTranslationTable(menuplyr_top*16, menuplyr_bottom*16);
1018                         for (i = 0;i < menuplyr_width * menuplyr_height;i++)
1019                                 menuplyr_translated[i] = palette_complete[translationTable[menuplyr_pixels[i]]];
1020                         Draw_NewPic("gfx/menuplyr.lmp", menuplyr_width, menuplyr_height, true, (qbyte *)menuplyr_translated);
1021                 }
1022                 M_DrawPic(160, 48, "gfx/bigbox.lmp");
1023                 M_DrawPic(172, 56, "gfx/menuplyr.lmp");
1024         }
1025
1026         if (setup_cursor == 0)
1027                 M_DrawCharacter (168 + 8*strlen(setup_myname), setup_cursor_table [setup_cursor], 10+((int)(realtime*4)&1));
1028         else
1029                 M_DrawCharacter (56, setup_cursor_table [setup_cursor], 12+((int)(realtime*4)&1));
1030 }
1031
1032
1033 void M_Setup_Key (int k, char ascii)
1034 {
1035         int                     l;
1036
1037         switch (k)
1038         {
1039         case K_ESCAPE:
1040                 M_Menu_MultiPlayer_f ();
1041                 break;
1042
1043         case K_UPARROW:
1044                 S_LocalSound ("misc/menu1.wav", true);
1045                 setup_cursor--;
1046                 if (setup_cursor < 0)
1047                         setup_cursor = NUM_SETUP_CMDS-1;
1048                 break;
1049
1050         case K_DOWNARROW:
1051                 S_LocalSound ("misc/menu1.wav", true);
1052                 setup_cursor++;
1053                 if (setup_cursor >= NUM_SETUP_CMDS)
1054                         setup_cursor = 0;
1055                 break;
1056
1057         case K_LEFTARROW:
1058                 if (setup_cursor < 1)
1059                         return;
1060                 S_LocalSound ("misc/menu3.wav", true);
1061                 if (setup_cursor == 1)
1062                         setup_top = setup_top - 1;
1063                 if (setup_cursor == 2)
1064                         setup_bottom = setup_bottom - 1;
1065                 if (setup_cursor == 3)
1066                 {
1067                         l = setup_rateindex(setup_rate) - 1;
1068                         if (l < 0)
1069                                 l = RATES - 1;
1070                         setup_rate = setup_ratetable[l].rate;
1071                 }
1072                 break;
1073         case K_RIGHTARROW:
1074                 if (setup_cursor < 1)
1075                         return;
1076 forward:
1077                 S_LocalSound ("misc/menu3.wav", true);
1078                 if (setup_cursor == 1)
1079                         setup_top = setup_top + 1;
1080                 if (setup_cursor == 2)
1081                         setup_bottom = setup_bottom + 1;
1082                 if (setup_cursor == 3)
1083                 {
1084                         l = setup_rateindex(setup_rate) + 1;
1085                         if (l >= RATES)
1086                                 l = 0;
1087                         setup_rate = setup_ratetable[l].rate;
1088                 }
1089                 break;
1090
1091         case K_ENTER:
1092                 if (setup_cursor == 0)
1093                         return;
1094
1095                 if (setup_cursor == 1 || setup_cursor == 2 || setup_cursor == 3)
1096                         goto forward;
1097
1098                 // setup_cursor == 4 (Accept changes)
1099                 if (strcmp(cl_name.string, setup_myname) != 0)
1100                         Cbuf_AddText ( va ("name \"%s\"\n", setup_myname) );
1101                 if (setup_top != setup_oldtop || setup_bottom != setup_oldbottom)
1102                         Cbuf_AddText( va ("color %i %i\n", setup_top, setup_bottom) );
1103                 if (setup_rate != setup_oldrate)
1104                         Cbuf_AddText(va("rate %i\n", setup_rate));
1105
1106                 m_entersound = true;
1107                 M_Menu_MultiPlayer_f ();
1108                 break;
1109
1110         case K_BACKSPACE:
1111                 if (setup_cursor == 0)
1112                 {
1113                         if (strlen(setup_myname))
1114                                 setup_myname[strlen(setup_myname)-1] = 0;
1115                 }
1116                 break;
1117
1118         default:
1119                 if (ascii < 32 || ascii > 126)
1120                         break;
1121                 if (setup_cursor == 0)
1122                 {
1123                         l = strlen(setup_myname);
1124                         if (l < 15)
1125                         {
1126                                 setup_myname[l+1] = 0;
1127                                 setup_myname[l] = ascii;
1128                         }
1129                 }
1130         }
1131
1132         if (setup_top > 15)
1133                 setup_top = 0;
1134         if (setup_top < 0)
1135                 setup_top = 15;
1136         if (setup_bottom > 15)
1137                 setup_bottom = 0;
1138         if (setup_bottom < 0)
1139                 setup_bottom = 15;
1140 }
1141
1142 //=============================================================================
1143 /* OPTIONS MENU */
1144
1145 #define SLIDER_RANGE    10
1146
1147 void M_DrawSlider (int x, int y, float num, float rangemin, float rangemax)
1148 {
1149         char text[16];
1150         int i;
1151         float range;
1152         range = bound(0, (num - rangemin) / (rangemax - rangemin), 1);
1153         M_DrawCharacter (x-8, y, 128);
1154         for (i = 0;i < SLIDER_RANGE;i++)
1155                 M_DrawCharacter (x + i*8, y, 129);
1156         M_DrawCharacter (x+i*8, y, 130);
1157         M_DrawCharacter (x + (SLIDER_RANGE-1)*8 * range, y, 131);
1158         if (fabs((int)num - num) < 0.01)
1159                 sprintf(text, "%i", (int)num);
1160         else
1161                 sprintf(text, "%.2f", num);
1162         M_Print(x + (SLIDER_RANGE+2) * 8, y, text);
1163 }
1164
1165 void M_DrawCheckbox (int x, int y, int on)
1166 {
1167         if (on)
1168                 M_Print(x, y, "on");
1169         else
1170                 M_Print(x, y, "off");
1171 }
1172
1173
1174 #define OPTIONS_ITEMS 38
1175
1176 int options_cursor;
1177
1178 void M_Menu_Options_f (void)
1179 {
1180         key_dest = key_menu;
1181         m_state = m_options;
1182         m_entersound = true;
1183 }
1184
1185 extern cvar_t snd_staticvolume;
1186 extern cvar_t slowmo;
1187 extern dllhandle_t jpeg_dll;
1188 extern cvar_t gl_texture_anisotropy;
1189 extern cvar_t r_textshadow;
1190
1191 void M_Menu_Options_AdjustSliders (int dir)
1192 {
1193         int optnum;
1194         S_LocalSound ("misc/menu3.wav", true);
1195
1196         optnum = 7;
1197         if (options_cursor == optnum++)
1198                 Cvar_SetValueQuick (&vid_conwidth, bound(320, vid_conwidth.value + dir * 64, 2048));
1199         else if (options_cursor == optnum++)
1200                 Cvar_SetValueQuick (&vid_conheight, bound(240, vid_conheight.value + dir * 48, 1536));
1201         else if (options_cursor == optnum++)
1202                 Cvar_SetValueQuick (&scr_conspeed, bound(0, scr_conspeed.value + dir * 100, 1000));
1203         else if (options_cursor == optnum++)
1204                 Cvar_SetValueQuick (&scr_conalpha, bound(0, scr_conalpha.value + dir * 0.2, 1));
1205         else if (options_cursor == optnum++)
1206                 Cvar_SetValueQuick (&scr_conbrightness, bound(0, scr_conbrightness.value + dir * 0.2, 1));
1207         else if (options_cursor == optnum++)
1208                 Cvar_SetValueQuick (&scr_viewsize, bound(30, scr_viewsize.value + dir * 10, 120));
1209         else if (options_cursor == optnum++)
1210                 Cvar_SetValueQuick (&scr_fov, bound(1, scr_fov.integer + dir * 1, 170));
1211         else if (options_cursor == optnum++)
1212                 Cvar_SetValueQuick (&scr_screenshot_jpeg, !scr_screenshot_jpeg.integer);
1213         else if (options_cursor == optnum++)
1214                 Cvar_SetValueQuick (&scr_screenshot_jpeg_quality, bound(0, scr_screenshot_jpeg_quality.value + dir * 0.1, 1));
1215         else if (options_cursor == optnum++)
1216                 Cvar_SetValueQuick (&r_sky, !r_sky.integer);
1217         else if (options_cursor == optnum++)
1218                 Cvar_SetValueQuick (&gl_combine, !gl_combine.integer);
1219         else if (options_cursor == optnum++)
1220                 Cvar_SetValueQuick (&gl_dither, !gl_dither.integer);
1221         else if (options_cursor == optnum++)
1222                 Cvar_SetValueQuick (&gl_texture_anisotropy, bound(1, gl_texture_anisotropy.integer + dir, gl_max_anisotropy));
1223         else if (options_cursor == optnum++)
1224                 Cvar_SetValueQuick (&slowmo, bound(0, slowmo.value + dir * 0.25, 5));
1225         else if (options_cursor == optnum++)
1226                 Cvar_SetValueQuick (&bgmvolume, bound(0, bgmvolume.value + dir * 0.1, 1));
1227         else if (options_cursor == optnum++)
1228                 Cvar_SetValueQuick (&volume, bound(0, volume.value + dir * 0.1, 1));
1229         else if (options_cursor == optnum++)
1230                 Cvar_SetValueQuick (&snd_staticvolume, bound(0, snd_staticvolume.value + dir * 0.1, 1));
1231         else if (options_cursor == optnum++)
1232                 Cvar_SetValueQuick (&r_textshadow, !r_textshadow.integer);
1233         else if (options_cursor == optnum++)
1234                 Cvar_SetValueQuick (&crosshair, bound(0, crosshair.integer + dir, 5));
1235         else if (options_cursor == optnum++)
1236                 Cvar_SetValueQuick (&crosshair_size, bound(1, crosshair_size.value + dir, 5));
1237         else if (options_cursor == optnum++)
1238                 Cvar_SetValueQuick (&crosshair_static, !crosshair_static.integer);
1239         else if (options_cursor == optnum++)
1240                 Cvar_SetValueQuick (&showfps, !showfps.integer);
1241         else if (options_cursor == optnum++)
1242                 Cvar_SetValueQuick (&showtime, !showtime.integer);
1243         else if (options_cursor == optnum++)
1244                 Cvar_SetValueQuick (&showdate, !showdate.integer);
1245         else if (options_cursor == optnum++)
1246         {
1247                 if (cl_forwardspeed.value > 200)
1248                 {
1249                         Cvar_SetValueQuick (&cl_forwardspeed, 200);
1250                         Cvar_SetValueQuick (&cl_backspeed, 200);
1251                 }
1252                 else
1253                 {
1254                         Cvar_SetValueQuick (&cl_forwardspeed, 400);
1255                         Cvar_SetValueQuick (&cl_backspeed, 400);
1256                 }
1257         }
1258         else if (options_cursor == optnum++)
1259                 Cvar_SetValueQuick (&lookspring, !lookspring.integer);
1260         else if (options_cursor == optnum++)
1261                 Cvar_SetValueQuick (&lookstrafe, !lookstrafe.integer);
1262         else if (options_cursor == optnum++)
1263                 Cvar_SetValueQuick (&sensitivity, bound(1, sensitivity.value + dir * 0.5, 50));
1264         else if (options_cursor == optnum++)
1265                 Cvar_SetValueQuick (&freelook, !freelook.integer);
1266         else if (options_cursor == optnum++)
1267                 Cvar_SetValueQuick (&m_pitch, -m_pitch.value);
1268         else if (options_cursor == optnum++)
1269                 Cvar_SetValueQuick (&vid_mouse, !vid_mouse.integer);
1270 }
1271
1272 int optnum;
1273 int opty;
1274 int optcursor;
1275
1276 void M_Options_PrintCommand(char *s, int enabled)
1277 {
1278         if (opty >= 32)
1279         {
1280                 DrawQ_Fill(menu_x, menu_y + opty, 320, 8, optnum == optcursor ? (0.5 + 0.2 * sin(realtime * M_PI)) : 0, 0, 0, 0.5, 0);
1281                 M_ItemPrint(0, opty, s, enabled);
1282         }
1283         opty += 8;
1284         optnum++;
1285 }
1286
1287 void M_Options_PrintCheckbox(char *s, int enabled, int yes)
1288 {
1289         if (opty >= 32)
1290         {
1291                 DrawQ_Fill(menu_x, menu_y + opty, 320, 8, optnum == optcursor ? (0.5 + 0.2 * sin(realtime * M_PI)) : 0, 0, 0, 0.5, 0);
1292                 M_ItemPrint(0, opty, s, enabled);
1293                 M_DrawCheckbox(0 + strlen(s) * 8 + 8, opty, yes);
1294         }
1295         opty += 8;
1296         optnum++;
1297 }
1298
1299 void M_Options_PrintSlider(char *s, int enabled, float value, float minvalue, float maxvalue)
1300 {
1301         if (opty >= 32)
1302         {
1303                 DrawQ_Fill(menu_x, menu_y + opty, 320, 8, optnum == optcursor ? (0.5 + 0.2 * sin(realtime * M_PI)) : 0, 0, 0, 0.5, 0);
1304                 M_ItemPrint(0, opty, s, enabled);
1305                 M_DrawSlider(0 + strlen(s) * 8 + 8, opty, value, minvalue, maxvalue);
1306         }
1307         opty += 8;
1308         optnum++;
1309 }
1310
1311 void M_Options_Draw (void)
1312 {
1313         int visible;
1314         cachepic_t      *p;
1315
1316         M_Background(320, 240);
1317
1318         M_DrawPic(16, 4, "gfx/qplaque.lmp");
1319         p = Draw_CachePic("gfx/p_option.lmp");
1320         M_DrawPic((320-p->width)/2, 4, "gfx/p_option.lmp");
1321
1322         optnum = 0;
1323         optcursor = options_cursor;
1324         visible = (vid.conheight - 32) / 8;
1325         opty = 32 - bound(0, optcursor - (visible >> 1), max(0, OPTIONS_ITEMS - visible)) * 8;
1326
1327         M_Options_PrintCommand( "Customize controls", true);
1328         M_Options_PrintCommand( "     Go to console", true);
1329         M_Options_PrintCommand( " Reset to defaults", true);
1330         M_Options_PrintCommand( "             Video", true);
1331         M_Options_PrintCommand( "           Effects", true);
1332         M_Options_PrintCommand( "          Graphics", true);
1333         M_Options_PrintCommand( "     Color Control", true);
1334         M_Options_PrintSlider(  "  2D Screen Width ", true, vid_conwidth.value, 320, 2048);
1335         M_Options_PrintSlider(  "  2D Screen Height", true, vid_conheight.value, 240, 1536);
1336         M_Options_PrintSlider(  "     Console Speed", true, scr_conspeed.value, 0, 1000);
1337         M_Options_PrintSlider(  "     Console Alpha", true, scr_conalpha.value, 0, 1);
1338         M_Options_PrintSlider(  "Conback Brightness", true, scr_conbrightness.value, 0, 1);
1339         M_Options_PrintSlider(  "       Screen size", true, scr_viewsize.value, 30, 120);
1340         M_Options_PrintSlider(  "     Field of View", true, scr_fov.integer, 1, 170);
1341         M_Options_PrintCheckbox("  JPEG screenshots", jpeg_dll != NULL, scr_screenshot_jpeg.integer);
1342         M_Options_PrintSlider(  "      JPEG quality", jpeg_dll != NULL, scr_screenshot_jpeg_quality.value, 0, 1);
1343         M_Options_PrintCheckbox("               Sky", true, r_sky.integer);
1344         M_Options_PrintCheckbox("   Texture Combine", true, gl_combine.integer);
1345         M_Options_PrintCheckbox("         Dithering", true, gl_dither.integer);
1346         M_Options_PrintSlider(  "Anisotropic Filter", gl_support_anisotropy, gl_texture_anisotropy.integer, 1, gl_max_anisotropy);
1347         M_Options_PrintSlider(  "        Game Speed", sv.active, slowmo.value, 0, 5);
1348         M_Options_PrintSlider(  "   CD Music Volume", cdaudioinitialized.integer, bgmvolume.value, 0, 1);
1349         M_Options_PrintSlider(  "      Sound Volume", snd_initialized.integer, volume.value, 0, 1);
1350         M_Options_PrintSlider(gamemode == GAME_GOODVSBAD2 ? "      Music Volume" : "    Ambient Volume", snd_initialized.integer, snd_staticvolume.value, 0, 1);
1351         M_Options_PrintCheckbox("       Text Shadow", true, r_textshadow.integer);
1352         M_Options_PrintSlider(  "         Crosshair", true, crosshair.value, 0, 5);
1353         M_Options_PrintSlider(  "    Crosshair Size", true, crosshair_size.value, 1, 5);
1354         M_Options_PrintCheckbox("  Static Crosshair", true, crosshair_static.integer);
1355         M_Options_PrintCheckbox("    Show Framerate", true, showfps.integer);
1356         M_Options_PrintCheckbox("         Show Time", true, showtime.integer);
1357         M_Options_PrintCheckbox("         Show Date", true, showdate.integer);
1358         M_Options_PrintCheckbox("        Always Run", true, cl_forwardspeed.value > 200);
1359         M_Options_PrintCheckbox("        Lookspring", true, lookspring.integer);
1360         M_Options_PrintCheckbox("        Lookstrafe", true, lookstrafe.integer);
1361         M_Options_PrintSlider(  "       Mouse Speed", true, sensitivity.value, 1, 50);
1362         M_Options_PrintCheckbox("        Mouse Look", true, freelook.integer);
1363         M_Options_PrintCheckbox("      Invert Mouse", true, m_pitch.value < 0);
1364         M_Options_PrintCheckbox("         Use Mouse", true, vid_mouse.integer);
1365 }
1366
1367
1368 void M_Options_Key (int k, char ascii)
1369 {
1370         switch (k)
1371         {
1372         case K_ESCAPE:
1373                 M_Menu_Main_f ();
1374                 break;
1375
1376         case K_ENTER:
1377                 m_entersound = true;
1378                 switch (options_cursor)
1379                 {
1380                 case 0:
1381                         M_Menu_Keys_f ();
1382                         break;
1383                 case 1:
1384                         m_state = m_none;
1385                         key_dest = key_game;
1386                         Con_ToggleConsole_f ();
1387                         break;
1388                 case 2:
1389                         Cbuf_AddText ("exec default.cfg\n");
1390                         break;
1391                 case 3:
1392                         M_Menu_Video_f ();
1393                         break;
1394                 case 4:
1395                         M_Menu_Options_Effects_f ();
1396                         break;
1397                 case 5:
1398                         M_Menu_Options_Graphics_f ();
1399                         break;
1400                 case 6:
1401                         M_Menu_Options_ColorControl_f ();
1402                         break;
1403                 default:
1404                         M_Menu_Options_AdjustSliders (1);
1405                         break;
1406                 }
1407                 return;
1408
1409         case K_UPARROW:
1410                 S_LocalSound ("misc/menu1.wav", true);
1411                 options_cursor--;
1412                 if (options_cursor < 0)
1413                         options_cursor = OPTIONS_ITEMS-1;
1414                 break;
1415
1416         case K_DOWNARROW:
1417                 S_LocalSound ("misc/menu1.wav", true);
1418                 options_cursor++;
1419                 if (options_cursor >= OPTIONS_ITEMS)
1420                         options_cursor = 0;
1421                 break;
1422
1423         case K_LEFTARROW:
1424                 M_Menu_Options_AdjustSliders (-1);
1425                 break;
1426
1427         case K_RIGHTARROW:
1428                 M_Menu_Options_AdjustSliders (1);
1429                 break;
1430         }
1431 }
1432
1433 #define OPTIONS_EFFECTS_ITEMS   33
1434
1435 int options_effects_cursor;
1436
1437 void M_Menu_Options_Effects_f (void)
1438 {
1439         key_dest = key_menu;
1440         m_state = m_options_effects;
1441         m_entersound = true;
1442 }
1443
1444
1445 extern cvar_t r_detailtextures;
1446 extern cvar_t cl_particles;
1447 extern cvar_t cl_explosions;
1448 extern cvar_t cl_stainmaps;
1449 extern cvar_t cl_decals;
1450 extern cvar_t r_explosionclip;
1451 extern cvar_t r_modellights;
1452 extern cvar_t r_coronas;
1453 extern cvar_t gl_flashblend;
1454 extern cvar_t cl_particles_quality;
1455 extern cvar_t cl_particles_bulletimpacts;
1456 extern cvar_t cl_particles_smoke;
1457 extern cvar_t cl_particles_sparks;
1458 extern cvar_t cl_particles_bubbles;
1459 extern cvar_t cl_particles_blood;
1460 extern cvar_t cl_particles_blood_alpha;
1461 extern cvar_t cl_particles_blood_bloodhack;
1462 extern cvar_t r_lightningbeam_thickness;
1463 extern cvar_t r_lightningbeam_scroll;
1464 extern cvar_t r_lightningbeam_repeatdistance;
1465 extern cvar_t r_lightningbeam_color_red;
1466 extern cvar_t r_lightningbeam_color_green;
1467 extern cvar_t r_lightningbeam_color_blue;
1468 extern cvar_t r_lightningbeam_qmbtexture;
1469
1470 void M_Menu_Options_Effects_AdjustSliders (int dir)
1471 {
1472         int optnum;
1473         S_LocalSound ("misc/menu3.wav", true);
1474
1475         optnum = 0;
1476              if (options_effects_cursor == optnum++) Cvar_SetValueQuick (&r_modellights, bound(0, r_modellights.value + dir, 8));
1477         else if (options_effects_cursor == optnum++) Cvar_SetValueQuick (&r_coronas, bound(0, r_coronas.value + dir * 0.125, 4));
1478         else if (options_effects_cursor == optnum++) Cvar_SetValueQuick (&gl_flashblend, !gl_flashblend.integer);
1479         else if (options_effects_cursor == optnum++) Cvar_SetValueQuick (&cl_particles, !cl_particles.integer);
1480         else if (options_effects_cursor == optnum++) Cvar_SetValueQuick (&cl_particles_quality, bound(1, cl_particles_quality.value + dir * 0.5, 4));
1481         else if (options_effects_cursor == optnum++) Cvar_SetValueQuick (&cl_explosions, !cl_explosions.integer);
1482         else if (options_effects_cursor == optnum++) Cvar_SetValueQuick (&r_explosionclip, !r_explosionclip.integer);
1483         else if (options_effects_cursor == optnum++) Cvar_SetValueQuick (&cl_stainmaps, !cl_stainmaps.integer);
1484         else if (options_effects_cursor == optnum++) Cvar_SetValueQuick (&cl_decals, !cl_decals.integer);
1485         else if (options_effects_cursor == optnum++) Cvar_SetValueQuick (&r_detailtextures, !r_detailtextures.integer);
1486         else if (options_effects_cursor == optnum++) Cvar_SetValueQuick (&cl_particles_bulletimpacts, !cl_particles_bulletimpacts.integer);
1487         else if (options_effects_cursor == optnum++) Cvar_SetValueQuick (&cl_particles_smoke, !cl_particles_smoke.integer);
1488         else if (options_effects_cursor == optnum++) Cvar_SetValueQuick (&cl_particles_sparks, !cl_particles_sparks.integer);
1489         else if (options_effects_cursor == optnum++) Cvar_SetValueQuick (&cl_particles_bubbles, !cl_particles_bubbles.integer);
1490         else if (options_effects_cursor == optnum++) Cvar_SetValueQuick (&cl_particles_blood, !cl_particles_blood.integer);
1491         else if (options_effects_cursor == optnum++) Cvar_SetValueQuick (&cl_particles_blood_alpha, bound(0.2, cl_particles_blood_alpha.value + dir * 0.1, 1));
1492         else if (options_effects_cursor == optnum++) Cvar_SetValueQuick (&cl_particles_blood_bloodhack, !cl_particles_blood_bloodhack.integer);
1493         else if (options_effects_cursor == optnum++) Cvar_SetValueQuick (&r_lightningbeam_thickness, bound(1, r_lightningbeam_thickness.integer + dir, 10));
1494         else if (options_effects_cursor == optnum++) Cvar_SetValueQuick (&r_lightningbeam_scroll, bound(0, r_lightningbeam_scroll.integer + dir, 10));
1495         else if (options_effects_cursor == optnum++) Cvar_SetValueQuick (&r_lightningbeam_repeatdistance, bound(64, r_lightningbeam_repeatdistance.integer + dir * 64, 1024));
1496         else if (options_effects_cursor == optnum++) Cvar_SetValueQuick (&r_lightningbeam_color_red, bound(0, r_lightningbeam_color_red.value + dir * 0.1, 1));
1497         else if (options_effects_cursor == optnum++) Cvar_SetValueQuick (&r_lightningbeam_color_green, bound(0, r_lightningbeam_color_green.value + dir * 0.1, 1));
1498         else if (options_effects_cursor == optnum++) Cvar_SetValueQuick (&r_lightningbeam_color_blue, bound(0, r_lightningbeam_color_blue.value + dir * 0.1, 1));
1499         else if (options_effects_cursor == optnum++) Cvar_SetValueQuick (&r_lightningbeam_qmbtexture, !r_lightningbeam_qmbtexture.integer);
1500         else if (options_effects_cursor == optnum++) Cvar_SetValueQuick (&r_lerpmodels, !r_lerpmodels.integer);
1501         else if (options_effects_cursor == optnum++) Cvar_SetValueQuick (&r_lerpsprites, !r_lerpsprites.integer);
1502         else if (options_effects_cursor == optnum++) Cvar_SetValueQuick (&gl_polyblend, bound(0, gl_polyblend.value + dir * 0.1, 1));
1503         else if (options_effects_cursor == optnum++) Cvar_SetValueQuick (&r_skyscroll1, bound(-8, r_skyscroll1.value + dir * 0.1, 8));
1504         else if (options_effects_cursor == optnum++) Cvar_SetValueQuick (&r_skyscroll2, bound(-8, r_skyscroll2.value + dir * 0.1, 8));
1505         else if (options_effects_cursor == optnum++) Cvar_SetValueQuick (&r_waterwarp, bound(0, r_waterwarp.value + dir * 0.1, 1));
1506         else if (options_effects_cursor == optnum++) Cvar_SetValueQuick (&r_wateralpha, bound(0, r_wateralpha.value + dir * 0.1, 1));
1507         else if (options_effects_cursor == optnum++) Cvar_SetValueQuick (&r_waterscroll, bound(0, r_waterscroll.value + dir * 0.5, 10));
1508         else if (options_effects_cursor == optnum++) Cvar_SetValueQuick (&r_watershader, bound(0, r_watershader.value + dir * 0.25, 10));
1509 }
1510
1511 void M_Options_Effects_Draw (void)
1512 {
1513         int visible;
1514         cachepic_t      *p;
1515
1516         M_Background(320, 200);
1517
1518         M_DrawPic(16, 4, "gfx/qplaque.lmp");
1519         p = Draw_CachePic("gfx/p_option.lmp");
1520         M_DrawPic((320-p->width)/2, 4, "gfx/p_option.lmp");
1521
1522         optcursor = options_effects_cursor;
1523         optnum = 0;
1524         visible = (vid.conheight - 32) / 8;
1525         opty = 32 - bound(0, optcursor - (visible >> 1), max(0, OPTIONS_EFFECTS_ITEMS - visible)) * 8;
1526
1527         M_Options_PrintSlider(  "      Lights Per Model", true, r_modellights.value, 0, 8);
1528         M_Options_PrintSlider(  "      Corona Intensity", true, r_coronas.value, 0, 4);
1529         M_Options_PrintCheckbox("      Use Only Coronas", true, gl_flashblend.integer);
1530         M_Options_PrintCheckbox("             Particles", true, cl_particles.integer);
1531         M_Options_PrintSlider(  "     Particles Quality", true, cl_particles_quality.value, 1, 4);
1532         M_Options_PrintCheckbox("            Explosions", true, cl_explosions.integer);
1533         M_Options_PrintCheckbox("    Explosion Clipping", true, r_explosionclip.integer);
1534         M_Options_PrintCheckbox("             Stainmaps", true, cl_stainmaps.integer);
1535         M_Options_PrintCheckbox("                Decals", true, cl_decals.integer);
1536         M_Options_PrintCheckbox("      Detail Texturing", true, r_detailtextures.integer);
1537         M_Options_PrintCheckbox("        Bullet Impacts", true, cl_particles_bulletimpacts.integer);
1538         M_Options_PrintCheckbox("                 Smoke", true, cl_particles_smoke.integer);
1539         M_Options_PrintCheckbox("                Sparks", true, cl_particles_sparks.integer);
1540         M_Options_PrintCheckbox("               Bubbles", true, cl_particles_bubbles.integer);
1541         M_Options_PrintCheckbox("                 Blood", true, cl_particles_blood.integer);
1542         M_Options_PrintSlider(  "         Blood Opacity", true, cl_particles_blood_alpha.value, 0.2, 1);
1543         M_Options_PrintCheckbox("Force New Blood Effect", true, cl_particles_blood_bloodhack.integer);
1544         M_Options_PrintSlider(  "   Lightning Thickness", true, r_lightningbeam_thickness.integer, 1, 10);
1545         M_Options_PrintSlider(  "      Lightning Scroll", true, r_lightningbeam_scroll.integer, 0, 10);
1546         M_Options_PrintSlider(  " Lightning Repeat Dist", true, r_lightningbeam_repeatdistance.integer, 64, 1024);
1547         M_Options_PrintSlider(  "   Lightning Color Red", true, r_lightningbeam_color_red.value, 0, 1);
1548         M_Options_PrintSlider(  " Lightning Color Green", true, r_lightningbeam_color_green.value, 0, 1);
1549         M_Options_PrintSlider(  "  Lightning Color Blue", true, r_lightningbeam_color_blue.value, 0, 1);
1550         M_Options_PrintCheckbox(" Lightning QMB Texture", true, r_lightningbeam_qmbtexture.integer);
1551         M_Options_PrintCheckbox("   Model Interpolation", true, r_lerpmodels.integer);
1552         M_Options_PrintCheckbox("  Sprite Interpolation", true, r_lerpsprites.integer);
1553         M_Options_PrintSlider(  "            View Blend", true, gl_polyblend.value, 0, 1);
1554         M_Options_PrintSlider(  "Upper Sky Scroll Speed", true, r_skyscroll1.value, -8, 8);
1555         M_Options_PrintSlider(  "Lower Sky Scroll Speed", true, r_skyscroll2.value, -8, 8);
1556         M_Options_PrintSlider(  "  Underwater View Warp", true, r_waterwarp.value, 0, 1);
1557         M_Options_PrintSlider(  " Water Alpha (opacity)", true, r_wateralpha.value, 0, 1);
1558         M_Options_PrintSlider(  "        Water Movement", true, r_waterscroll.value, 0, 10);
1559         M_Options_PrintSlider(  " GeForce3 Water Shader", true, r_watershader.value, 0, 10);
1560 }
1561
1562
1563 void M_Options_Effects_Key (int k, char ascii)
1564 {
1565         switch (k)
1566         {
1567         case K_ESCAPE:
1568                 M_Menu_Options_f ();
1569                 break;
1570
1571         case K_ENTER:
1572                 M_Menu_Options_Effects_AdjustSliders (1);
1573                 break;
1574
1575         case K_UPARROW:
1576                 S_LocalSound ("misc/menu1.wav", true);
1577                 options_effects_cursor--;
1578                 if (options_effects_cursor < 0)
1579                         options_effects_cursor = OPTIONS_EFFECTS_ITEMS-1;
1580                 break;
1581
1582         case K_DOWNARROW:
1583                 S_LocalSound ("misc/menu1.wav", true);
1584                 options_effects_cursor++;
1585                 if (options_effects_cursor >= OPTIONS_EFFECTS_ITEMS)
1586                         options_effects_cursor = 0;
1587                 break;
1588
1589         case K_LEFTARROW:
1590                 M_Menu_Options_Effects_AdjustSliders (-1);
1591                 break;
1592
1593         case K_RIGHTARROW:
1594                 M_Menu_Options_Effects_AdjustSliders (1);
1595                 break;
1596         }
1597 }
1598
1599
1600 #define OPTIONS_GRAPHICS_ITEMS  7
1601
1602 int options_graphics_cursor;
1603
1604 void M_Menu_Options_Graphics_f (void)
1605 {
1606         key_dest = key_menu;
1607         m_state = m_options_graphics;
1608         m_entersound = true;
1609 }
1610
1611 extern cvar_t r_shadow_gloss;
1612 extern cvar_t r_shadow_realtime_dlight;
1613 extern cvar_t r_shadow_realtime_dlight_shadows;
1614 extern cvar_t r_shadow_realtime_world;
1615 extern cvar_t r_shadow_realtime_world_dlightshadows;
1616 extern cvar_t r_shadow_realtime_world_lightmaps;
1617 extern cvar_t r_shadow_realtime_world_shadows;
1618
1619 void M_Menu_Options_Graphics_AdjustSliders (int dir)
1620 {
1621         int optnum;
1622         S_LocalSound ("misc/menu3.wav", true);
1623  
1624         optnum = 0;
1625
1626                  if (options_graphics_cursor == optnum++) Cvar_SetValueQuick (&r_shadow_gloss,                                                  bound(0, r_shadow_gloss.integer + dir, 2));
1627         else if (options_graphics_cursor == optnum++) Cvar_SetValueQuick (&r_shadow_realtime_dlight,                            !r_shadow_realtime_dlight.integer);
1628         else if (options_graphics_cursor == optnum++) Cvar_SetValueQuick (&r_shadow_realtime_dlight_shadows,            !r_shadow_realtime_dlight_shadows.integer);
1629         else if (options_graphics_cursor == optnum++) Cvar_SetValueQuick (&r_shadow_realtime_world,                                     !r_shadow_realtime_world.integer);
1630         else if (options_graphics_cursor == optnum++) Cvar_SetValueQuick (&r_shadow_realtime_world_dlightshadows,       !r_shadow_realtime_world_dlightshadows.integer);
1631         else if (options_graphics_cursor == optnum++) Cvar_SetValueQuick (&r_shadow_realtime_world_lightmaps,           !r_shadow_realtime_world_lightmaps.integer);
1632         else if (options_graphics_cursor == optnum++) Cvar_SetValueQuick (&r_shadow_realtime_world_shadows,                     !r_shadow_realtime_world_shadows.integer);
1633 }
1634
1635
1636 void M_Options_Graphics_Draw (void)
1637 {
1638         int visible;
1639         cachepic_t      *p;
1640
1641         M_Background(320, 200);
1642
1643         M_DrawPic(16, 4, "gfx/qplaque.lmp");
1644         p = Draw_CachePic("gfx/p_option.lmp");
1645         M_DrawPic((320-p->width)/2, 4, "gfx/p_option.lmp");
1646
1647         optcursor = options_graphics_cursor;
1648         optnum = 0;
1649         visible = (vid.conheight - 32) / 8;
1650         opty = 32 - bound(0, optcursor - (visible >> 1), max(0, OPTIONS_GRAPHICS_ITEMS - visible)) * 8;
1651
1652         M_Options_PrintSlider(  "             Gloss Mode", true, r_shadow_gloss.integer, 0, 2);
1653         M_Options_PrintCheckbox("             RT DLights", true, r_shadow_realtime_dlight.integer);
1654         M_Options_PrintCheckbox("      RT DLight Shadows", true, r_shadow_realtime_dlight_shadows.integer);
1655         M_Options_PrintCheckbox("               RT World", true, r_shadow_realtime_world.integer);
1656         M_Options_PrintCheckbox("RT World DLight Shadows", true, r_shadow_realtime_world_dlightshadows.integer);
1657         M_Options_PrintCheckbox("     RT World Lightmaps", true, r_shadow_realtime_world_lightmaps.integer);
1658         M_Options_PrintCheckbox("        RT World Shadow", true, r_shadow_realtime_world_shadows.integer);
1659 }
1660
1661
1662 void M_Options_Graphics_Key (int k, char ascii)
1663 {
1664         switch (k)
1665         {
1666         case K_ESCAPE:
1667                 M_Menu_Options_f ();
1668                 break;
1669
1670         case K_ENTER:
1671                 M_Menu_Options_Graphics_AdjustSliders (1);
1672                 break;
1673
1674         case K_UPARROW:
1675                 S_LocalSound ("misc/menu1.wav", true);
1676                 options_graphics_cursor--;
1677                 if (options_graphics_cursor < 0)
1678                         options_graphics_cursor = OPTIONS_GRAPHICS_ITEMS-1;
1679                 break;
1680
1681         case K_DOWNARROW:
1682                 S_LocalSound ("misc/menu1.wav", true);
1683                 options_graphics_cursor++;
1684                 if (options_graphics_cursor >= OPTIONS_GRAPHICS_ITEMS)
1685                         options_graphics_cursor = 0;
1686                 break;
1687
1688         case K_LEFTARROW:
1689                 M_Menu_Options_Graphics_AdjustSliders (-1);
1690                 break;
1691
1692         case K_RIGHTARROW:
1693                 M_Menu_Options_Graphics_AdjustSliders (1);
1694                 break;
1695         }
1696 }
1697
1698
1699 #define OPTIONS_COLORCONTROL_ITEMS      18
1700
1701 int             options_colorcontrol_cursor;
1702
1703 // intensity value to match up to 50% dither to 'correct' quake
1704 cvar_t menu_options_colorcontrol_correctionvalue = {0, "menu_options_colorcontrol_correctionvalue", "0.25"};
1705
1706 void M_Menu_Options_ColorControl_f (void)
1707 {
1708         key_dest = key_menu;
1709         m_state = m_options_colorcontrol;
1710         m_entersound = true;
1711 }
1712
1713
1714 void M_Menu_Options_ColorControl_AdjustSliders (int dir)
1715 {
1716         int optnum;
1717         float f;
1718         S_LocalSound ("misc/menu3.wav", true);
1719
1720         optnum = 1;
1721         if (options_colorcontrol_cursor == optnum++)
1722                 Cvar_SetValueQuick (&v_hwgamma, !v_hwgamma.integer);
1723         else if (options_colorcontrol_cursor == optnum++)
1724         {
1725                 Cvar_SetValueQuick (&v_color_enable, 0);
1726                 Cvar_SetValueQuick (&v_gamma, bound(1, v_gamma.value + dir * 0.125, 5));
1727         }
1728         else if (options_colorcontrol_cursor == optnum++)
1729         {
1730                 Cvar_SetValueQuick (&v_color_enable, 0);
1731                 Cvar_SetValueQuick (&v_contrast, bound(1, v_contrast.value + dir * 0.125, 5));
1732         }
1733         else if (options_colorcontrol_cursor == optnum++)
1734         {
1735                 Cvar_SetValueQuick (&v_color_enable, 0);
1736                 Cvar_SetValueQuick (&v_brightness, bound(0, v_brightness.value + dir * 0.05, 0.8));
1737         }
1738         else if (options_colorcontrol_cursor == optnum++)
1739         {
1740                 Cvar_SetValueQuick (&v_color_enable, !v_color_enable.integer);
1741         }
1742         else if (options_colorcontrol_cursor == optnum++)
1743         {
1744                 Cvar_SetValueQuick (&v_color_enable, 1);
1745                 Cvar_SetValueQuick (&v_color_black_r, bound(0, v_color_black_r.value + dir * 0.0125, 0.8));
1746         }
1747         else if (options_colorcontrol_cursor == optnum++)
1748         {
1749                 Cvar_SetValueQuick (&v_color_enable, 1);
1750                 Cvar_SetValueQuick (&v_color_black_g, bound(0, v_color_black_g.value + dir * 0.0125, 0.8));
1751         }
1752         else if (options_colorcontrol_cursor == optnum++)
1753         {
1754                 Cvar_SetValueQuick (&v_color_enable, 1);
1755                 Cvar_SetValueQuick (&v_color_black_b, bound(0, v_color_black_b.value + dir * 0.0125, 0.8));
1756         }
1757         else if (options_colorcontrol_cursor == optnum++)
1758         {
1759                 Cvar_SetValueQuick (&v_color_enable, 1);
1760                 f = bound(0, (v_color_black_r.value + v_color_black_g.value + v_color_black_b.value) / 3 + dir * 0.0125, 0.8);
1761                 Cvar_SetValueQuick (&v_color_black_r, f);
1762                 Cvar_SetValueQuick (&v_color_black_g, f);
1763                 Cvar_SetValueQuick (&v_color_black_b, f);
1764         }
1765         else if (options_colorcontrol_cursor == optnum++)
1766         {
1767                 Cvar_SetValueQuick (&v_color_enable, 1);
1768                 Cvar_SetValueQuick (&v_color_grey_r, bound(0, v_color_grey_r.value + dir * 0.0125, 0.95));
1769         }
1770         else if (options_colorcontrol_cursor == optnum++)
1771         {
1772                 Cvar_SetValueQuick (&v_color_enable, 1);
1773                 Cvar_SetValueQuick (&v_color_grey_g, bound(0, v_color_grey_g.value + dir * 0.0125, 0.95));
1774         }
1775         else if (options_colorcontrol_cursor == optnum++)
1776         {
1777                 Cvar_SetValueQuick (&v_color_enable, 1);
1778                 Cvar_SetValueQuick (&v_color_grey_b, bound(0, v_color_grey_b.value + dir * 0.0125, 0.95));
1779         }
1780         else if (options_colorcontrol_cursor == optnum++)
1781         {
1782                 Cvar_SetValueQuick (&v_color_enable, 1);
1783                 f = bound(0, (v_color_grey_r.value + v_color_grey_g.value + v_color_grey_b.value) / 3 + dir * 0.0125, 0.95);
1784                 Cvar_SetValueQuick (&v_color_grey_r, f);
1785                 Cvar_SetValueQuick (&v_color_grey_g, f);
1786                 Cvar_SetValueQuick (&v_color_grey_b, f);
1787         }
1788         else if (options_colorcontrol_cursor == optnum++)
1789         {
1790                 Cvar_SetValueQuick (&v_color_enable, 1);
1791                 Cvar_SetValueQuick (&v_color_white_r, bound(1, v_color_white_r.value + dir * 0.125, 5));
1792         }
1793         else if (options_colorcontrol_cursor == optnum++)
1794         {
1795                 Cvar_SetValueQuick (&v_color_enable, 1);
1796                 Cvar_SetValueQuick (&v_color_white_g, bound(1, v_color_white_g.value + dir * 0.125, 5));
1797         }
1798         else if (options_colorcontrol_cursor == optnum++)
1799         {
1800                 Cvar_SetValueQuick (&v_color_enable, 1);
1801                 Cvar_SetValueQuick (&v_color_white_b, bound(1, v_color_white_b.value + dir * 0.125, 5));
1802         }
1803         else if (options_colorcontrol_cursor == optnum++)
1804         {
1805                 Cvar_SetValueQuick (&v_color_enable, 1);
1806                 f = bound(1, (v_color_white_r.value + v_color_white_g.value + v_color_white_b.value) / 3 + dir * 0.125, 5);
1807                 Cvar_SetValueQuick (&v_color_white_r, f);
1808                 Cvar_SetValueQuick (&v_color_white_g, f);
1809                 Cvar_SetValueQuick (&v_color_white_b, f);
1810         }
1811 }
1812
1813 void M_Options_ColorControl_Draw (void)
1814 {
1815         int visible;
1816         float x, c, s, t, u, v;
1817         cachepic_t      *p;
1818
1819         M_Background(320, 256);
1820
1821         M_DrawPic(16, 4, "gfx/qplaque.lmp");
1822         p = Draw_CachePic("gfx/p_option.lmp");
1823         M_DrawPic((320-p->width)/2, 4, "gfx/p_option.lmp");
1824
1825         optcursor = options_colorcontrol_cursor;
1826         optnum = 0;
1827         visible = (vid.conheight - 32) / 8;
1828         opty = 32 - bound(0, optcursor - (visible >> 1), max(0, OPTIONS_COLORCONTROL_ITEMS - visible)) * 8;
1829
1830         M_Options_PrintCommand( "     Reset to defaults", true);
1831         M_Options_PrintCheckbox("Hardware Gamma Control", vid_hardwaregammasupported.integer, v_hwgamma.integer);
1832         M_Options_PrintSlider(  "                 Gamma", !v_color_enable.integer && vid_hardwaregammasupported.integer && v_hwgamma.integer, v_gamma.value, 1, 5);
1833         M_Options_PrintSlider(  "              Contrast", !v_color_enable.integer, v_contrast.value, 1, 5);
1834         M_Options_PrintSlider(  "            Brightness", !v_color_enable.integer, v_brightness.value, 0, 0.8);
1835         M_Options_PrintCheckbox("  Color Level Controls", true, v_color_enable.integer);
1836         M_Options_PrintSlider(  "          Black: Red  ", v_color_enable.integer, v_color_black_r.value, 0, 0.8);
1837         M_Options_PrintSlider(  "          Black: Green", v_color_enable.integer, v_color_black_g.value, 0, 0.8);
1838         M_Options_PrintSlider(  "          Black: Blue ", v_color_enable.integer, v_color_black_b.value, 0, 0.8);
1839         M_Options_PrintSlider(  "          Black: Grey ", v_color_enable.integer, (v_color_black_r.value + v_color_black_g.value + v_color_black_b.value) / 3, 0, 0.8);
1840         M_Options_PrintSlider(  "           Grey: Red  ", v_color_enable.integer && vid_hardwaregammasupported.integer && v_hwgamma.integer, v_color_grey_r.value, 0, 0.95);
1841         M_Options_PrintSlider(  "           Grey: Green", v_color_enable.integer && vid_hardwaregammasupported.integer && v_hwgamma.integer, v_color_grey_g.value, 0, 0.95);
1842         M_Options_PrintSlider(  "           Grey: Blue ", v_color_enable.integer && vid_hardwaregammasupported.integer && v_hwgamma.integer, v_color_grey_b.value, 0, 0.95);
1843         M_Options_PrintSlider(  "           Grey: Grey ", v_color_enable.integer && vid_hardwaregammasupported.integer && v_hwgamma.integer, (v_color_grey_r.value + v_color_grey_g.value + v_color_grey_b.value) / 3, 0, 0.95);
1844         M_Options_PrintSlider(  "          White: Red  ", v_color_enable.integer, v_color_white_r.value, 1, 5);
1845         M_Options_PrintSlider(  "          White: Green", v_color_enable.integer, v_color_white_g.value, 1, 5);
1846         M_Options_PrintSlider(  "          White: Blue ", v_color_enable.integer, v_color_white_b.value, 1, 5);
1847         M_Options_PrintSlider(  "          White: Grey ", v_color_enable.integer, (v_color_white_r.value + v_color_white_g.value + v_color_white_b.value) / 3, 1, 5);
1848
1849         opty += 4;
1850         DrawQ_Fill(menu_x, menu_y + opty, 320, 4 + 64 + 8 + 64 + 4, 0, 0, 0, 1, 0);opty += 4;
1851         s = (float) 312 / 2 * vid.realwidth / vid.conwidth;
1852         t = (float) 4 / 2 * vid.realheight / vid.conheight;
1853         DrawQ_SuperPic(menu_x + 4, menu_y + opty, "gfx/colorcontrol/ditherpattern.tga", 312, 4, 0,0, 1,0,0,1, s,0, 1,0,0,1, 0,t, 1,0,0,1, s,t, 1,0,0,1, 0);opty += 4;
1854         DrawQ_SuperPic(menu_x + 4, menu_y + opty, NULL                                , 312, 4, 0,0, 0,0,0,1, 1,0, 1,0,0,1, 0,1, 0,0,0,1, 1,1, 1,0,0,1, 0);opty += 4;
1855         DrawQ_SuperPic(menu_x + 4, menu_y + opty, "gfx/colorcontrol/ditherpattern.tga", 312, 4, 0,0, 0,1,0,1, s,0, 0,1,0,1, 0,t, 0,1,0,1, s,t, 0,1,0,1, 0);opty += 4;
1856         DrawQ_SuperPic(menu_x + 4, menu_y + opty, NULL                                , 312, 4, 0,0, 0,0,0,1, 1,0, 0,1,0,1, 0,1, 0,0,0,1, 1,1, 0,1,0,1, 0);opty += 4;
1857         DrawQ_SuperPic(menu_x + 4, menu_y + opty, "gfx/colorcontrol/ditherpattern.tga", 312, 4, 0,0, 0,0,1,1, s,0, 0,0,1,1, 0,t, 0,0,1,1, s,t, 0,0,1,1, 0);opty += 4;
1858         DrawQ_SuperPic(menu_x + 4, menu_y + opty, NULL                                , 312, 4, 0,0, 0,0,0,1, 1,0, 0,0,1,1, 0,1, 0,0,0,1, 1,1, 0,0,1,1, 0);opty += 4;
1859         DrawQ_SuperPic(menu_x + 4, menu_y + opty, "gfx/colorcontrol/ditherpattern.tga", 312, 4, 0,0, 1,1,1,1, s,0, 1,1,1,1, 0,t, 1,1,1,1, s,t, 1,1,1,1, 0);opty += 4;
1860         DrawQ_SuperPic(menu_x + 4, menu_y + opty, NULL                                , 312, 4, 0,0, 0,0,0,1, 1,0, 1,1,1,1, 0,1, 0,0,0,1, 1,1, 1,1,1,1, 0);opty += 4;
1861
1862         c = menu_options_colorcontrol_correctionvalue.value; // intensity value that should be matched up to a 50% dither to 'correct' quake
1863         s = (float) 48 / 2 * vid.realwidth / vid.conwidth;
1864         t = (float) 48 / 2 * vid.realheight / vid.conheight;
1865         u = s * 0.5;
1866         v = t * 0.5;
1867         opty += 8;
1868         x = 4;
1869         DrawQ_Fill(menu_x + x, menu_y + opty, 64, 48, c, 0, 0, 1, 0);
1870         DrawQ_SuperPic(menu_x + x + 16, menu_y + opty + 16, "gfx/colorcontrol/ditherpattern.tga", 16, 16, 0,0, 1,0,0,1, s,0, 1,0,0,1, 0,t, 1,0,0,1, s,t, 1,0,0,1, 0);
1871         DrawQ_SuperPic(menu_x + x + 32, menu_y + opty + 16, "gfx/colorcontrol/ditherpattern.tga", 16, 16, 0,0, 1,0,0,1, u,0, 1,0,0,1, 0,v, 1,0,0,1, u,v, 1,0,0,1, 0);
1872         x += 80;
1873         DrawQ_Fill(menu_x + x, menu_y + opty, 64, 48, 0, c, 0, 1, 0);
1874         DrawQ_SuperPic(menu_x + x + 16, menu_y + opty + 16, "gfx/colorcontrol/ditherpattern.tga", 16, 16, 0,0, 0,1,0,1, s,0, 0,1,0,1, 0,t, 0,1,0,1, s,t, 0,1,0,1, 0);
1875         DrawQ_SuperPic(menu_x + x + 32, menu_y + opty + 16, "gfx/colorcontrol/ditherpattern.tga", 16, 16, 0,0, 0,1,0,1, u,0, 0,1,0,1, 0,v, 0,1,0,1, u,v, 0,1,0,1, 0);
1876         x += 80;
1877         DrawQ_Fill(menu_x + x, menu_y + opty, 64, 48, 0, 0, c, 1, 0);
1878         DrawQ_SuperPic(menu_x + x + 16, menu_y + opty + 16, "gfx/colorcontrol/ditherpattern.tga", 16, 16, 0,0, 0,0,1,1, s,0, 0,0,1,1, 0,t, 0,0,1,1, s,t, 0,0,1,1, 0);
1879         DrawQ_SuperPic(menu_x + x + 32, menu_y + opty + 16, "gfx/colorcontrol/ditherpattern.tga", 16, 16, 0,0, 0,0,1,1, u,0, 0,0,1,1, 0,v, 0,0,1,1, u,v, 0,0,1,1, 0);
1880         x += 80;
1881         DrawQ_Fill(menu_x + x, menu_y + opty, 64, 48, c, c, c, 1, 0);
1882         DrawQ_SuperPic(menu_x + x + 16, menu_y + opty + 16, "gfx/colorcontrol/ditherpattern.tga", 16, 16, 0,0, 1,1,1,1, s,0, 1,1,1,1, 0,t, 1,1,1,1, s,t, 1,1,1,1, 0);
1883         DrawQ_SuperPic(menu_x + x + 32, menu_y + opty + 16, "gfx/colorcontrol/ditherpattern.tga", 16, 16, 0,0, 1,1,1,1, u,0, 1,1,1,1, 0,v, 1,1,1,1, u,v, 1,1,1,1, 0);
1884 }
1885
1886
1887 void M_Options_ColorControl_Key (int k, char ascii)
1888 {
1889         switch (k)
1890         {
1891         case K_ESCAPE:
1892                 M_Menu_Options_f ();
1893                 break;
1894
1895         case K_ENTER:
1896                 m_entersound = true;
1897                 switch (options_colorcontrol_cursor)
1898                 {
1899                 case 0:
1900                         Cvar_SetValueQuick(&v_hwgamma, 1);
1901                         Cvar_SetValueQuick(&v_gamma, 1);
1902                         Cvar_SetValueQuick(&v_contrast, 1);
1903                         Cvar_SetValueQuick(&v_brightness, 0);
1904                         Cvar_SetValueQuick(&v_color_enable, 0);
1905                         Cvar_SetValueQuick(&v_color_black_r, 0);
1906                         Cvar_SetValueQuick(&v_color_black_g, 0);
1907                         Cvar_SetValueQuick(&v_color_black_b, 0);
1908                         Cvar_SetValueQuick(&v_color_grey_r, 0);
1909                         Cvar_SetValueQuick(&v_color_grey_g, 0);
1910                         Cvar_SetValueQuick(&v_color_grey_b, 0);
1911                         Cvar_SetValueQuick(&v_color_white_r, 1);
1912                         Cvar_SetValueQuick(&v_color_white_g, 1);
1913                         Cvar_SetValueQuick(&v_color_white_b, 1);
1914                         break;
1915                 default:
1916                         M_Menu_Options_ColorControl_AdjustSliders (1);
1917                         break;
1918                 }
1919                 return;
1920
1921         case K_UPARROW:
1922                 S_LocalSound ("misc/menu1.wav", true);
1923                 options_colorcontrol_cursor--;
1924                 if (options_colorcontrol_cursor < 0)
1925                         options_colorcontrol_cursor = OPTIONS_COLORCONTROL_ITEMS-1;
1926                 break;
1927
1928         case K_DOWNARROW:
1929                 S_LocalSound ("misc/menu1.wav", true);
1930                 options_colorcontrol_cursor++;
1931                 if (options_colorcontrol_cursor >= OPTIONS_COLORCONTROL_ITEMS)
1932                         options_colorcontrol_cursor = 0;
1933                 break;
1934
1935         case K_LEFTARROW:
1936                 M_Menu_Options_ColorControl_AdjustSliders (-1);
1937                 break;
1938
1939         case K_RIGHTARROW:
1940                 M_Menu_Options_ColorControl_AdjustSliders (1);
1941                 break;
1942         }
1943 }
1944
1945
1946 //=============================================================================
1947 /* KEYS MENU */
1948
1949 char *quakebindnames[][2] =
1950 {
1951 {"+attack",             "attack"},
1952 {"impulse 10",          "next weapon"},
1953 {"impulse 12",          "previous weapon"},
1954 {"+jump",                       "jump / swim up"},
1955 {"+forward",            "walk forward"},
1956 {"+back",                       "backpedal"},
1957 {"+left",                       "turn left"},
1958 {"+right",                      "turn right"},
1959 {"+speed",                      "run"},
1960 {"+moveleft",           "step left"},
1961 {"+moveright",          "step right"},
1962 {"+strafe",             "sidestep"},
1963 {"+lookup",             "look up"},
1964 {"+lookdown",           "look down"},
1965 {"centerview",          "center view"},
1966 {"+mlook",                      "mouse look"},
1967 {"+klook",                      "keyboard look"},
1968 {"+moveup",                     "swim up"},
1969 {"+movedown",           "swim down"}
1970 };
1971
1972 char *transfusionbindnames[][2] =
1973 {
1974 {"",                            "Movement"},            // Movement commands
1975 {"+forward",            "walk forward"},
1976 {"+back",                       "backpedal"},
1977 {"+left",                       "turn left"},
1978 {"+right",                      "turn right"},
1979 {"+moveleft",           "step left"},
1980 {"+moveright",          "step right"},
1981 {"+jump",                       "jump / swim up"},
1982 {"+movedown",           "swim down"},
1983 {"",                            "Combat"},                      // Combat commands
1984 {"impulse 1",           "Pitch Fork"},
1985 {"impulse 2",           "Flare Gun"},
1986 {"impulse 3",           "Shotgun"},
1987 {"impulse 4",           "Machine Gun"},
1988 {"impulse 5",           "Incinerator"},
1989 {"impulse 6",           "Bombs (TNT)"},
1990 {"impulse 35",          "Proximity Bomb"},
1991 {"impulse 36",          "Remote Detonator"},
1992 {"impulse 7",           "Aerosol Can"},
1993 {"impulse 8",           "Tesla Cannon"},
1994 {"impulse 9",           "Life Leech"},
1995 {"impulse 10",          "Voodoo Doll"},
1996 {"impulse 21",          "next weapon"},
1997 {"impulse 22",          "previous weapon"},
1998 {"+attack",             "attack"},
1999 {"+button3",            "altfire"},
2000 {"",                            "Inventory"},           // Inventory commands
2001 {"impulse 40",          "Dr.'s Bag"},
2002 {"impulse 41",          "Crystal Ball"},
2003 {"impulse 42",          "Beast Vision"},
2004 {"impulse 43",          "Jump Boots"},
2005 {"impulse 23",          "next item"},
2006 {"impulse 24",          "previous item"},
2007 {"impulse 25",          "use item"},
2008 {"",                            "Misc"},                        // Misc commands
2009 {"+button4",            "use"},
2010 {"impulse 50",          "add bot (red)"},
2011 {"impulse 51",          "add bot (blue)"},
2012 {"impulse 52",          "kick a bot"},
2013 {"impulse 26",          "next armor type"},
2014 {"impulse 27",          "identify player"},
2015 {"impulse 55",          "voting menu"},
2016 {"impulse 56",          "observer mode"},
2017 {"",                            "Taunts"},            // Taunts
2018 {"impulse 70",          "taunt 0"},
2019 {"impulse 71",          "taunt 1"},
2020 {"impulse 72",          "taunt 2"},
2021 {"impulse 73",          "taunt 3"},
2022 {"impulse 74",          "taunt 4"},
2023 {"impulse 75",          "taunt 5"},
2024 {"impulse 76",          "taunt 6"},
2025 {"impulse 77",          "taunt 7"},
2026 {"impulse 78",          "taunt 8"},
2027 {"impulse 79",          "taunt 9"}
2028 };
2029
2030 char *goodvsbad2bindnames[][2] =
2031 {
2032 {"impulse 69",          "Power 1"},
2033 {"impulse 70",          "Power 2"},
2034 {"impulse 71",          "Power 3"},
2035 {"+jump",                       "jump / swim up"},
2036 {"+forward",            "walk forward"},
2037 {"+back",                       "backpedal"},
2038 {"+left",                       "turn left"},
2039 {"+right",                      "turn right"},
2040 {"+speed",                      "run"},
2041 {"+moveleft",           "step left"},
2042 {"+moveright",          "step right"},
2043 {"+strafe",             "sidestep"},
2044 {"+lookup",             "look up"},
2045 {"+lookdown",           "look down"},
2046 {"centerview",          "center view"},
2047 {"+mlook",                      "mouse look"},
2048 {"kill",                        "kill yourself"},
2049 {"+moveup",                     "swim up"},
2050 {"+movedown",           "swim down"}
2051 };
2052
2053 int numcommands;
2054 char *(*bindnames)[2];
2055
2056 /*
2057 typedef struct binditem_s
2058 {
2059         char *command, *description;
2060         struct binditem_s *next;
2061 }
2062 binditem_t;
2063
2064 typedef struct bindcategory_s
2065 {
2066         char *name;
2067         binditem_t *binds;
2068         struct bindcategory_s *next;
2069 }
2070 bindcategory_t;
2071
2072 bindcategory_t *bindcategories = NULL;
2073
2074 void M_ClearBinds (void)
2075 {
2076         for (c = bindcategories;c;c = cnext)
2077         {
2078                 cnext = c->next;
2079                 for (b = c->binds;b;b = bnext)
2080                 {
2081                         bnext = b->next;
2082                         Z_Free(b);
2083                 }
2084                 Z_Free(c);
2085         }
2086         bindcategories = NULL;
2087 }
2088
2089 void M_AddBindToCategory(bindcategory_t *c, char *command, char *description)
2090 {
2091         for (b = &c->binds;*b;*b = &(*b)->next);
2092         *b = Z_Alloc(sizeof(binditem_t) + strlen(command) + 1 + strlen(description) + 1);
2093         *b->command = (char *)((*b) + 1);
2094         *b->description = *b->command + strlen(command) + 1;
2095         strcpy(*b->command, command);
2096         strcpy(*b->description, description);
2097 }
2098
2099 void M_AddBind (char *category, char *command, char *description)
2100 {
2101         for (c = &bindcategories;*c;c = &(*c)->next)
2102         {
2103                 if (!strcmp(category, (*c)->name))
2104                 {
2105                         M_AddBindToCategory(*c, command, description);
2106                         return;
2107                 }
2108         }
2109         *c = Z_Alloc(sizeof(bindcategory_t));
2110         M_AddBindToCategory(*c, command, description);
2111 }
2112
2113 void M_DefaultBinds (void)
2114 {
2115         M_ClearBinds();
2116         M_AddBind("movement", "+jump", "jump / swim up");
2117         M_AddBind("movement", "+forward", "walk forward");
2118         M_AddBind("movement", "+back", "backpedal");
2119         M_AddBind("movement", "+left", "turn left");
2120         M_AddBind("movement", "+right", "turn right");
2121         M_AddBind("movement", "+speed", "run");
2122         M_AddBind("movement", "+moveleft", "step left");
2123         M_AddBind("movement", "+moveright", "step right");
2124         M_AddBind("movement", "+strafe", "sidestep");
2125         M_AddBind("movement", "+lookup", "look up");
2126         M_AddBind("movement", "+lookdown", "look down");
2127         M_AddBind("movement", "centerview", "center view");
2128         M_AddBind("movement", "+mlook", "mouse look");
2129         M_AddBind("movement", "+klook", "keyboard look");
2130         M_AddBind("movement", "+moveup", "swim up");
2131         M_AddBind("movement", "+movedown", "swim down");
2132         M_AddBind("weapons", "+attack", "attack");
2133         M_AddBind("weapons", "impulse 10", "next weapon");
2134         M_AddBind("weapons", "impulse 12", "previous weapon");
2135         M_AddBind("weapons", "impulse 1", "select weapon 1 (axe)");
2136         M_AddBind("weapons", "impulse 2", "select weapon 2 (shotgun)");
2137         M_AddBind("weapons", "impulse 3", "select weapon 3 (super )");
2138         M_AddBind("weapons", "impulse 4", "select weapon 4 (nailgun)");
2139         M_AddBind("weapons", "impulse 5", "select weapon 5 (super nailgun)");
2140         M_AddBind("weapons", "impulse 6", "select weapon 6 (grenade launcher)");
2141         M_AddBind("weapons", "impulse 7", "select weapon 7 (rocket launcher)");
2142         M_AddBind("weapons", "impulse 8", "select weapon 8 (lightning gun)");
2143 }
2144 */
2145
2146
2147 int             keys_cursor;
2148 int             bind_grab;
2149
2150 void M_Menu_Keys_f (void)
2151 {
2152         key_dest = key_menu;
2153         m_state = m_keys;
2154         m_entersound = true;
2155 }
2156
2157 #define NUMKEYS 5
2158
2159 void M_FindKeysForCommand (char *command, int *keys)
2160 {
2161         int             count;
2162         int             j;
2163         char    *b;
2164
2165         for (j = 0;j < NUMKEYS;j++)
2166                 keys[j] = -1;
2167
2168         count = 0;
2169
2170         for (j = 0; j < (int)sizeof (keybindings[0]) / (int)sizeof (keybindings[0][0]); j++)
2171         {
2172                 b = keybindings[0][j];
2173                 if (!b)
2174                         continue;
2175                 if (!strcmp (b, command) )
2176                 {
2177                         keys[count++] = j;
2178                         if (count == NUMKEYS)
2179                                 break;
2180                 }
2181         }
2182 }
2183
2184 void M_UnbindCommand (char *command)
2185 {
2186         int             j;
2187         char    *b;
2188
2189         for (j = 0; j < (int)sizeof (keybindings[0]) / (int)sizeof (keybindings[0][0]); j++)
2190         {
2191                 b = keybindings[0][j];
2192                 if (!b)
2193                         continue;
2194                 if (!strcmp (b, command))
2195                         Key_SetBinding (j, 0, "");
2196         }
2197 }
2198
2199
2200 void M_Keys_Draw (void)
2201 {
2202         int             i, j;
2203         int             keys[NUMKEYS];
2204         int             y;
2205         cachepic_t      *p;
2206         char    keystring[1024];
2207
2208         M_Background(320, 48 + 8 * numcommands);
2209
2210         p = Draw_CachePic ("gfx/ttl_cstm.lmp");
2211         M_DrawPic ( (320-p->width)/2, 4, "gfx/ttl_cstm.lmp");
2212
2213         if (bind_grab)
2214                 M_Print(12, 32, "Press a key or button for this action");
2215         else
2216                 M_Print(18, 32, "Enter to change, backspace to clear");
2217
2218 // search for known bindings
2219         for (i=0 ; i<numcommands ; i++)
2220         {
2221                 y = 48 + 8*i;
2222
2223                 // If there's no command, it's just a section
2224                 if (bindnames[i][0][0] == '\0')
2225                 {
2226                         M_PrintRed (4, y, "\x0D");  // #13 is the little arrow pointing to the right
2227                         M_PrintRed (16, y, bindnames[i][1]);
2228                         continue;
2229                 }
2230                 else
2231                         M_Print(16, y, bindnames[i][1]);
2232
2233                 M_FindKeysForCommand (bindnames[i][0], keys);
2234
2235                 // LordHavoc: redesigned to print more than 2 keys, inspired by Tomaz's MiniRacer
2236                 if (keys[0] == -1)
2237                         strcpy(keystring, "???");
2238                 else
2239                 {
2240                         keystring[0] = 0;
2241                         for (j = 0;j < NUMKEYS;j++)
2242                         {
2243                                 if (keys[j] != -1)
2244                                 {
2245                                         if (j > 0)
2246                                                 strcat(keystring, " or ");
2247                                         strcat(keystring, Key_KeynumToString (keys[j]));
2248                                 }
2249                         }
2250                 }
2251                 M_Print(150, y, keystring);
2252         }
2253
2254         if (bind_grab)
2255                 M_DrawCharacter (140, 48 + keys_cursor*8, '=');
2256         else
2257                 M_DrawCharacter (140, 48 + keys_cursor*8, 12+((int)(realtime*4)&1));
2258 }
2259
2260
2261 void M_Keys_Key (int k, char ascii)
2262 {
2263         char    cmd[80];
2264         int             keys[NUMKEYS];
2265
2266         if (bind_grab)
2267         {       // defining a key
2268                 S_LocalSound ("misc/menu1.wav", true);
2269                 if (k == K_ESCAPE)
2270                 {
2271                         bind_grab = false;
2272                 }
2273                 else //if (k != '`')
2274                 {
2275                         sprintf (cmd, "bind \"%s\" \"%s\"\n", Key_KeynumToString (k), bindnames[keys_cursor][0]);
2276                         Cbuf_InsertText (cmd);
2277                 }
2278
2279                 bind_grab = false;
2280                 return;
2281         }
2282
2283         switch (k)
2284         {
2285         case K_ESCAPE:
2286                 M_Menu_Options_f ();
2287                 break;
2288
2289         case K_LEFTARROW:
2290         case K_UPARROW:
2291                 S_LocalSound ("misc/menu1.wav", true);
2292                 do
2293                 {
2294                         keys_cursor--;
2295                         if (keys_cursor < 0)
2296                                 keys_cursor = numcommands-1;
2297                 }
2298                 while (bindnames[keys_cursor][0][0] == '\0');  // skip sections
2299                 break;
2300
2301         case K_DOWNARROW:
2302         case K_RIGHTARROW:
2303                 S_LocalSound ("misc/menu1.wav", true);
2304                 do
2305                 {
2306                         keys_cursor++;
2307                         if (keys_cursor >= numcommands)
2308                                 keys_cursor = 0;
2309                 }
2310                 while (bindnames[keys_cursor][0][0] == '\0');  // skip sections
2311                 break;
2312
2313         case K_ENTER:           // go into bind mode
2314                 M_FindKeysForCommand (bindnames[keys_cursor][0], keys);
2315                 S_LocalSound ("misc/menu2.wav", true);
2316                 if (keys[NUMKEYS - 1] != -1)
2317                         M_UnbindCommand (bindnames[keys_cursor][0]);
2318                 bind_grab = true;
2319                 break;
2320
2321         case K_BACKSPACE:               // delete bindings
2322         case K_DEL:                             // delete bindings
2323                 S_LocalSound ("misc/menu2.wav", true);
2324                 M_UnbindCommand (bindnames[keys_cursor][0]);
2325                 break;
2326         }
2327 }
2328
2329 //=============================================================================
2330 /* VIDEO MENU */
2331
2332 #define VIDEO_ITEMS 4
2333
2334 int video_cursor = 0;
2335 int video_cursor_table[] = {56, 68, 80, 100};
2336 // note: if modes are added to the beginning of this list, update the
2337 // video_resolution = x; in M_Menu_Video_f below
2338 unsigned short video_resolutions[][2] = {{320,240}, {400,300}, {512,384}, {640,480}, {800,600}, {1024,768}, {1152,864}, {1280,960}, {1280,1024}, {1600,1200}, {1792,1344}, {1920,1440}, {2048,1536}, {0,0}};
2339 // this is the number of the 640x480 mode in the list
2340 #define VID_640 3
2341 #define VID_RES_COUNT ((int)(sizeof(video_resolutions) / sizeof(video_resolutions[0])) - 1)
2342 int video_resolution;
2343
2344 extern int current_vid_fullscreen;
2345 extern int current_vid_width;
2346 extern int current_vid_height;
2347 extern int current_vid_bitsperpixel;
2348
2349
2350 void M_Menu_Video_f (void)
2351 {
2352         key_dest = key_menu;
2353         m_state = m_video;
2354         m_entersound = true;
2355
2356         // Look for the current resolution
2357         for (video_resolution = 0; video_resolution < VID_RES_COUNT; video_resolution++)
2358         {
2359                 if (video_resolutions[video_resolution][0] == current_vid_width &&
2360                         video_resolutions[video_resolution][1] == current_vid_height)
2361                         break;
2362         }
2363
2364         // Default to VID_640 if we didn't find it
2365         if (video_resolution == VID_RES_COUNT)
2366         {
2367                 // may need to update this number if mode list changes
2368                 video_resolution = VID_640;
2369                 Cvar_SetValueQuick (&vid_width, video_resolutions[video_resolution][0]);
2370                 Cvar_SetValueQuick (&vid_height, video_resolutions[video_resolution][1]);
2371         }
2372 }
2373
2374
2375 void M_Video_Draw (void)
2376 {
2377         cachepic_t      *p;
2378         const char* string;
2379
2380         M_Background(320, 200);
2381
2382         M_DrawPic(16, 4, "gfx/qplaque.lmp");
2383         p = Draw_CachePic("gfx/vidmodes.lmp");
2384         M_DrawPic((320-p->width)/2, 4, "gfx/vidmodes.lmp");
2385
2386         // Resolution
2387         M_Print(16, video_cursor_table[0], "            Resolution");
2388         string = va("%dx%d", video_resolutions[video_resolution][0], video_resolutions[video_resolution][1]);
2389         M_Print(220, video_cursor_table[0], string);
2390
2391         // Bits per pixel
2392         M_Print(16, video_cursor_table[1], "        Bits per pixel");
2393         M_Print(220, video_cursor_table[1], (vid_bitsperpixel.integer == 32) ? "32" : "16");
2394
2395         // Fullscreen
2396         M_Print(16, video_cursor_table[2], "            Fullscreen");
2397         M_DrawCheckbox(220, video_cursor_table[2], vid_fullscreen.integer);
2398
2399         // "Apply" button
2400         M_Print(220, video_cursor_table[3], "Apply");
2401
2402         // Cursor
2403         M_DrawCharacter(200, video_cursor_table[video_cursor], 12+((int)(realtime*4)&1));
2404 }
2405
2406
2407 void M_Menu_Video_AdjustSliders (int dir)
2408 {
2409         S_LocalSound ("misc/menu3.wav", true);
2410
2411         switch (video_cursor)
2412         {
2413                 // Resolution
2414                 case 0:
2415                 {
2416                         int new_resolution = video_resolution + dir;
2417                         if (gamemode == GAME_FNIGGIUM ? new_resolution < VID_640 : new_resolution < 0)
2418                                 video_resolution = VID_RES_COUNT - 1;
2419                         else if (new_resolution > VID_RES_COUNT - 1)
2420                                 video_resolution = gamemode == GAME_FNIGGIUM ? VID_640 : 0;
2421                         else
2422                                 video_resolution = new_resolution;
2423
2424                         Cvar_SetValueQuick (&vid_width, video_resolutions[video_resolution][0]);
2425                         Cvar_SetValueQuick (&vid_height, video_resolutions[video_resolution][1]);
2426                         break;
2427                 }
2428
2429                 // Bits per pixel
2430                 case 1:
2431                         Cvar_SetValueQuick (&vid_bitsperpixel, (vid_bitsperpixel.integer == 32) ? 16 : 32);
2432                         break;
2433                 case 2:
2434                         Cvar_SetValueQuick (&vid_fullscreen, !vid_fullscreen.integer);
2435                         break;
2436         }
2437 }
2438
2439
2440 void M_Video_Key (int key, char ascii)
2441 {
2442         switch (key)
2443         {
2444                 case K_ESCAPE:
2445                         // vid_shared.c has a copy of the current video config. We restore it
2446                         Cvar_SetValueQuick(&vid_fullscreen, current_vid_fullscreen);
2447                         Cvar_SetValueQuick(&vid_width, current_vid_width);
2448                         Cvar_SetValueQuick(&vid_height, current_vid_height);
2449                         Cvar_SetValueQuick(&vid_bitsperpixel, current_vid_bitsperpixel);
2450
2451                         S_LocalSound ("misc/menu1.wav", true);
2452                         M_Menu_Options_f ();
2453                         break;
2454
2455                 case K_ENTER:
2456                         m_entersound = true;
2457                         switch (video_cursor)
2458                         {
2459                                 case 3:
2460                                         Cbuf_AddText ("vid_restart\n");
2461                                         M_Menu_Options_f ();
2462                                         break;
2463                                 default:
2464                                         M_Menu_Video_AdjustSliders (1);
2465                         }
2466                         break;
2467
2468                 case K_UPARROW:
2469                         S_LocalSound ("misc/menu1.wav", true);
2470                         video_cursor--;
2471                         if (video_cursor < 0)
2472                                 video_cursor = VIDEO_ITEMS-1;
2473                         break;
2474
2475                 case K_DOWNARROW:
2476                         S_LocalSound ("misc/menu1.wav", true);
2477                         video_cursor++;
2478                         if (video_cursor >= VIDEO_ITEMS)
2479                                 video_cursor = 0;
2480                         break;
2481
2482                 case K_LEFTARROW:
2483                         M_Menu_Video_AdjustSliders (-1);
2484                         break;
2485
2486                 case K_RIGHTARROW:
2487                         M_Menu_Video_AdjustSliders (1);
2488                         break;
2489         }
2490 }
2491
2492 //=============================================================================
2493 /* HELP MENU */
2494
2495 int             help_page;
2496 #define NUM_HELP_PAGES  6
2497
2498
2499 void M_Menu_Help_f (void)
2500 {
2501         key_dest = key_menu;
2502         m_state = m_help;
2503         m_entersound = true;
2504         help_page = 0;
2505 }
2506
2507
2508
2509 void M_Help_Draw (void)
2510 {
2511         M_Background(320, 200);
2512         M_DrawPic (0, 0, va("gfx/help%i.lmp", help_page));
2513 }
2514
2515
2516 void M_Help_Key (int key, char ascii)
2517 {
2518         switch (key)
2519         {
2520         case K_ESCAPE:
2521                 M_Menu_Main_f ();
2522                 break;
2523
2524         case K_UPARROW:
2525         case K_RIGHTARROW:
2526                 m_entersound = true;
2527                 if (++help_page >= NUM_HELP_PAGES)
2528                         help_page = 0;
2529                 break;
2530
2531         case K_DOWNARROW:
2532         case K_LEFTARROW:
2533                 m_entersound = true;
2534                 if (--help_page < 0)
2535                         help_page = NUM_HELP_PAGES-1;
2536                 break;
2537         }
2538
2539 }
2540
2541 //=============================================================================
2542 /* QUIT MENU */
2543
2544 char *m_quit_message[9];
2545 int             m_quit_prevstate;
2546 qboolean        wasInMenus;
2547
2548
2549 int M_QuitMessage(char *line1, char *line2, char *line3, char *line4, char *line5, char *line6, char *line7, char *line8)
2550 {
2551         m_quit_message[0] = line1;
2552         m_quit_message[1] = line2;
2553         m_quit_message[2] = line3;
2554         m_quit_message[3] = line4;
2555         m_quit_message[4] = line5;
2556         m_quit_message[5] = line6;
2557         m_quit_message[6] = line7;
2558         m_quit_message[7] = line8;
2559         m_quit_message[8] = NULL;
2560         return 1;
2561 }
2562
2563 int M_ChooseQuitMessage(int request)
2564 {
2565         switch (gamemode)
2566         {
2567         case GAME_NORMAL:
2568         case GAME_HIPNOTIC:
2569         case GAME_ROGUE:
2570         case GAME_NEHAHRA:
2571                 if (request-- == 0) return M_QuitMessage("Are you gonna quit","this game just like","everything else?",NULL,NULL,NULL,NULL,NULL);
2572                 if (request-- == 0) return M_QuitMessage("Milord, methinks that","thou art a lowly","quitter. Is this true?",NULL,NULL,NULL,NULL,NULL);
2573                 if (request-- == 0) return M_QuitMessage("Do I need to bust your","face open for trying","to quit?",NULL,NULL,NULL,NULL,NULL);
2574                 if (request-- == 0) return M_QuitMessage("Man, I oughta smack you","for trying to quit!","Press Y to get","smacked out.",NULL,NULL,NULL,NULL);
2575                 if (request-- == 0) return M_QuitMessage("Press Y to quit like a","big loser in life.","Press N to stay proud","and successful!",NULL,NULL,NULL,NULL);
2576                 if (request-- == 0) return M_QuitMessage("If you press Y to","quit, I will summon","Satan all over your","hard drive!",NULL,NULL,NULL,NULL);
2577                 if (request-- == 0) return M_QuitMessage("Um, Asmodeus dislikes","his children trying to","quit. Press Y to return","to your Tinkertoys.",NULL,NULL,NULL,NULL);
2578                 if (request-- == 0) return M_QuitMessage("If you quit now, I'll","throw a blanket-party","for you next time!",NULL,NULL,NULL,NULL,NULL);
2579                 break;
2580         case GAME_GOODVSBAD2:
2581                 if (request-- == 0) return M_QuitMessage("Press Yes To Quit","...","Yes",NULL,NULL,NULL,NULL,NULL);
2582                 if (request-- == 0) return M_QuitMessage("Do you really want to","Quit?","Play Good vs bad 3!",NULL,NULL,NULL,NULL,NULL);
2583                 if (request-- == 0) return M_QuitMessage("All your quit are","belong to long duck","dong",NULL,NULL,NULL,NULL,NULL);
2584                 if (request-- == 0) return M_QuitMessage("Press Y to quit","","But are you too legit?",NULL,NULL,NULL,NULL,NULL);
2585                 if (request-- == 0) return M_QuitMessage("This game was made by","e@chip-web.com","It is by far the best","game ever made.",NULL,NULL,NULL,NULL);
2586                 if (request-- == 0) return M_QuitMessage("Even I really dont","know of a game better","Press Y to quit","like rougue chedder",NULL,NULL,NULL,NULL);
2587                 if (request-- == 0) return M_QuitMessage("After you stop playing","tell the guys who made","counterstrike to just","kill themselves now",NULL,NULL,NULL,NULL);
2588                 if (request-- == 0) return M_QuitMessage("Press Y to exit to DOS","","SSH login as user Y","to exit to Linux",NULL,NULL,NULL,NULL);
2589                 if (request-- == 0) return M_QuitMessage("Press Y like you","were waanderers","from Ys'",NULL,NULL,NULL,NULL,NULL);
2590                 if (request-- == 0) return M_QuitMessage("This game was made in","Nippon like the SS","announcer's saying ipon",NULL,NULL,NULL,NULL,NULL);
2591                 if (request-- == 0) return M_QuitMessage("you","want to quit?",NULL,NULL,NULL,NULL,NULL,NULL);
2592                 if (request-- == 0) return M_QuitMessage("Please stop playing","this stupid game",NULL,NULL,NULL,NULL,NULL,NULL);
2593                 break;
2594         case GAME_BATTLEMECH:
2595                 if (request-- == 0) return M_QuitMessage("? WHY ?","Press Y to quit, N to keep fraggin'",NULL,NULL,NULL,NULL,NULL,NULL);
2596                 if (request-- == 0) return M_QuitMessage("Leave now and your mech is scrap!","Press Y to quit, N to keep fraggin'",NULL,NULL,NULL,NULL,NULL,NULL);
2597                 if (request-- == 0) return M_QuitMessage("Accept Defeat?","Press Y to quit, N to keep fraggin'",NULL,NULL,NULL,NULL,NULL,NULL);
2598                 if (request-- == 0) return M_QuitMessage("Wait! There are more mechs to destroy!","Press Y to quit, N to keep fraggin'",NULL,NULL,NULL,NULL,NULL,NULL);
2599                 if (request-- == 0) return M_QuitMessage("Where's your bloodlust?","Press Y to quit, N to keep fraggin'",NULL,NULL,NULL,NULL,NULL,NULL);
2600                 if (request-- == 0) return M_QuitMessage("Your mech here is way more impressive","than your car out there...","Press Y to quit, N to keep fraggin'",NULL,NULL,NULL,NULL,NULL);
2601                 if (request-- == 0) return M_QuitMessage("Quitting won't reduce your debt","Press Y to quit, N to keep fraggin'",NULL,NULL,NULL,NULL,NULL,NULL);
2602                 break;
2603         case GAME_OPENQUARTZ:
2604                 if (request-- == 0) return M_QuitMessage("There is nothing like free beer!","Press Y to quit, N to stay",NULL,NULL,NULL,NULL,NULL,NULL);
2605                 if (request-- == 0) return M_QuitMessage("GNU is not Unix!","Press Y to quit, N to stay",NULL,NULL,NULL,NULL,NULL,NULL);
2606                 if (request-- == 0) return M_QuitMessage("You prefer free beer over free speech?","Press Y to quit, N to stay",NULL,NULL,NULL,NULL,NULL,NULL);
2607                 if (request-- == 0) return M_QuitMessage("Is OpenQuartz Propaganda?","Press Y to quit, N to stay",NULL,NULL,NULL,NULL,NULL,NULL);
2608                 break;
2609         default:
2610                 if (request-- == 0) return M_QuitMessage("Tired of fragging already?",NULL,NULL,NULL,NULL,NULL,NULL,NULL);
2611                 if (request-- == 0) return M_QuitMessage("Quit now and forfeit your bodycount?",NULL,NULL,NULL,NULL,NULL,NULL,NULL);
2612                 if (request-- == 0) return M_QuitMessage("Are you sure you want to quit?",NULL,NULL,NULL,NULL,NULL,NULL,NULL);
2613                 if (request-- == 0) return M_QuitMessage("Off to do something constructive?",NULL,NULL,NULL,NULL,NULL,NULL,NULL);
2614                 break;
2615         }
2616         return 0;
2617 };
2618
2619 void M_Menu_Quit_f (void)
2620 {
2621         int n;
2622         if (m_state == m_quit)
2623                 return;
2624         wasInMenus = (key_dest == key_menu);
2625         key_dest = key_menu;
2626         m_quit_prevstate = m_state;
2627         m_state = m_quit;
2628         m_entersound = true;
2629         // count how many there are
2630         for (n = 0;M_ChooseQuitMessage(n);n++);
2631         // choose one
2632         M_ChooseQuitMessage(rand() % n);
2633 }
2634
2635
2636 void M_Quit_Key (int key, char ascii)
2637 {
2638         switch (key)
2639         {
2640         case K_ESCAPE:
2641         case 'n':
2642         case 'N':
2643                 if (wasInMenus)
2644                 {
2645                         m_state = m_quit_prevstate;
2646                         m_entersound = true;
2647                 }
2648                 else
2649                 {
2650                         key_dest = key_game;
2651                         m_state = m_none;
2652                 }
2653                 break;
2654
2655         case 'Y':
2656         case 'y':
2657                 Host_Quit_f ();
2658                 break;
2659
2660         default:
2661                 break;
2662         }
2663 }
2664
2665 void M_Quit_Draw (void)
2666 {
2667         int i, l, linelength, firstline, lastline, lines;
2668         for (i = 0, linelength = 0, firstline = 9999, lastline = -1;m_quit_message[i];i++)
2669         {
2670                 if ((l = strlen(m_quit_message[i])))
2671                 {
2672                         if (firstline > i)
2673                                 firstline = i;
2674                         if (lastline < i)
2675                                 lastline = i;
2676                         if (linelength < l)
2677                                 linelength = l;
2678                 }
2679         }
2680         lines = (lastline - firstline) + 1;
2681         M_Background(linelength * 8 + 16, lines * 8 + 16);
2682         M_DrawTextBox(0, 0, linelength, lines);
2683         for (i = 0, l = firstline;i < lines;i++, l++)
2684                 M_Print(8 + 4 * (linelength - strlen(m_quit_message[l])), 8 + 8 * i, m_quit_message[l]);
2685 }
2686
2687 //=============================================================================
2688 /* LAN CONFIG MENU */
2689
2690 int             lanConfig_cursor = -1;
2691 int             lanConfig_cursor_table [] = {56, 76, 112};
2692 #define NUM_LANCONFIG_CMDS      3
2693
2694 int     lanConfig_port;
2695 char    lanConfig_portname[6];
2696 char    lanConfig_joinname[22];
2697
2698 void M_Menu_LanConfig_f (void)
2699 {
2700         key_dest = key_menu;
2701         m_state = m_lanconfig;
2702         m_entersound = true;
2703         if (lanConfig_cursor == -1)
2704         {
2705                 if (JoiningGame)
2706                         lanConfig_cursor = 1;
2707         }
2708         if (StartingGame)
2709                 lanConfig_cursor = 1;
2710         lanConfig_port = 26000;
2711         sprintf(lanConfig_portname, "%u", lanConfig_port);
2712
2713         m_return_reason[0] = 0;
2714 }
2715
2716
2717 void M_LanConfig_Draw (void)
2718 {
2719         cachepic_t      *p;
2720         int             basex;
2721         char    *startJoin;
2722         char    *protocol;
2723
2724         M_Background(320, 200);
2725
2726         M_DrawPic (16, 4, "gfx/qplaque.lmp");
2727         p = Draw_CachePic ("gfx/p_multi.lmp");
2728         basex = (320-p->width)/2;
2729         M_DrawPic (basex, 4, "gfx/p_multi.lmp");
2730
2731         if (StartingGame)
2732                 startJoin = "New Game";
2733         else
2734                 startJoin = "Join Game";
2735         protocol = "TCP/IP";
2736         M_Print(basex, 32, va ("%s - %s", startJoin, protocol));
2737         basex += 8;
2738
2739         M_Print(basex, lanConfig_cursor_table[0], "Port");
2740         M_DrawTextBox (basex+8*8, lanConfig_cursor_table[0]-8, 6, 1);
2741         M_Print(basex+9*8, lanConfig_cursor_table[0], lanConfig_portname);
2742
2743         if (JoiningGame)
2744         {
2745                 M_Print(basex, lanConfig_cursor_table[1], "Search for games...");
2746                 M_Print(basex, lanConfig_cursor_table[2]-16, "Join game at:");
2747                 M_DrawTextBox (basex+8, lanConfig_cursor_table[2]-8, 22, 1);
2748                 M_Print(basex+16, lanConfig_cursor_table[2], lanConfig_joinname);
2749         }
2750         else
2751         {
2752                 M_DrawTextBox (basex, lanConfig_cursor_table[1]-8, 2, 1);
2753                 M_Print(basex+8, lanConfig_cursor_table[1], "OK");
2754         }
2755
2756         M_DrawCharacter (basex-8, lanConfig_cursor_table [lanConfig_cursor], 12+((int)(realtime*4)&1));
2757
2758         if (lanConfig_cursor == 0)
2759                 M_DrawCharacter (basex+9*8 + 8*strlen(lanConfig_portname), lanConfig_cursor_table [0], 10+((int)(realtime*4)&1));
2760
2761         if (lanConfig_cursor == 2)
2762                 M_DrawCharacter (basex+16 + 8*strlen(lanConfig_joinname), lanConfig_cursor_table [2], 10+((int)(realtime*4)&1));
2763
2764         if (*m_return_reason)
2765                 M_Print(basex, 168, m_return_reason);
2766 }
2767
2768
2769 void M_LanConfig_Key (int key, char ascii)
2770 {
2771         int             l;
2772
2773         switch (key)
2774         {
2775         case K_ESCAPE:
2776                 M_Menu_MultiPlayer_f ();
2777                 break;
2778
2779         case K_UPARROW:
2780                 S_LocalSound ("misc/menu1.wav", true);
2781                 lanConfig_cursor--;
2782                 if (lanConfig_cursor < 0)
2783                         lanConfig_cursor = NUM_LANCONFIG_CMDS-1;
2784                 break;
2785
2786         case K_DOWNARROW:
2787                 S_LocalSound ("misc/menu1.wav", true);
2788                 lanConfig_cursor++;
2789                 if (lanConfig_cursor >= NUM_LANCONFIG_CMDS)
2790                         lanConfig_cursor = 0;
2791                 break;
2792
2793         case K_ENTER:
2794                 if (lanConfig_cursor == 0)
2795                         break;
2796
2797                 m_entersound = true;
2798
2799                 Cbuf_AddText ("stopdemo\n");
2800
2801                 Cvar_SetValue("port", lanConfig_port);
2802
2803                 if (lanConfig_cursor == 1)
2804                 {
2805                         if (StartingGame)
2806                         {
2807                                 M_Menu_GameOptions_f ();
2808                                 break;
2809                         }
2810                         M_Menu_ServerList_f();
2811                         break;
2812                 }
2813
2814                 if (lanConfig_cursor == 2)
2815                         Cbuf_AddText ( va ("connect \"%s\"\n", lanConfig_joinname) );
2816                 break;
2817
2818         case K_BACKSPACE:
2819                 if (lanConfig_cursor == 0)
2820                 {
2821                         if (strlen(lanConfig_portname))
2822                                 lanConfig_portname[strlen(lanConfig_portname)-1] = 0;
2823                 }
2824
2825                 if (lanConfig_cursor == 2)
2826                 {
2827                         if (strlen(lanConfig_joinname))
2828                                 lanConfig_joinname[strlen(lanConfig_joinname)-1] = 0;
2829                 }
2830                 break;
2831
2832         default:
2833                 if (ascii < 32 || ascii > 126)
2834                         break;
2835
2836                 if (lanConfig_cursor == 2)
2837                 {
2838                         l = strlen(lanConfig_joinname);
2839                         if (l < 21)
2840                         {
2841                                 lanConfig_joinname[l+1] = 0;
2842                                 lanConfig_joinname[l] = ascii;
2843                         }
2844                 }
2845
2846                 if (ascii < '0' || ascii > '9')
2847                         break;
2848                 if (lanConfig_cursor == 0)
2849                 {
2850                         l = strlen(lanConfig_portname);
2851                         if (l < 5)
2852                         {
2853                                 lanConfig_portname[l+1] = 0;
2854                                 lanConfig_portname[l] = ascii;
2855                         }
2856                 }
2857         }
2858
2859         if (StartingGame && lanConfig_cursor == 2)
2860         {
2861                 if (key == K_UPARROW)
2862                         lanConfig_cursor = 1;
2863                 else
2864                         lanConfig_cursor = 0;
2865         }
2866
2867         l =  atoi(lanConfig_portname);
2868         if (l <= 65535)
2869                 lanConfig_port = l;
2870         sprintf(lanConfig_portname, "%u", lanConfig_port);
2871 }
2872
2873 //=============================================================================
2874 /* GAME OPTIONS MENU */
2875
2876 typedef struct
2877 {
2878         char    *name;
2879         char    *description;
2880 } level_t;
2881
2882 typedef struct
2883 {
2884         char    *description;
2885         int             firstLevel;
2886         int             levels;
2887 } episode_t;
2888
2889 typedef struct
2890 {
2891         char *gamename;
2892         level_t *levels;
2893         episode_t *episodes;
2894         int numepisodes;
2895 }
2896 gamelevels_t;
2897
2898 level_t quakelevels[] =
2899 {
2900         {"start", "Entrance"},  // 0
2901
2902         {"e1m1", "Slipgate Complex"},                           // 1
2903         {"e1m2", "Castle of the Damned"},
2904         {"e1m3", "The Necropolis"},
2905         {"e1m4", "The Grisly Grotto"},
2906         {"e1m5", "Gloom Keep"},
2907         {"e1m6", "The Door To Chthon"},
2908         {"e1m7", "The House of Chthon"},
2909         {"e1m8", "Ziggurat Vertigo"},
2910
2911         {"e2m1", "The Installation"},                           // 9
2912         {"e2m2", "Ogre Citadel"},
2913         {"e2m3", "Crypt of Decay"},
2914         {"e2m4", "The Ebon Fortress"},
2915         {"e2m5", "The Wizard's Manse"},
2916         {"e2m6", "The Dismal Oubliette"},
2917         {"e2m7", "Underearth"},
2918
2919         {"e3m1", "Termination Central"},                        // 16
2920         {"e3m2", "The Vaults of Zin"},
2921         {"e3m3", "The Tomb of Terror"},
2922         {"e3m4", "Satan's Dark Delight"},
2923         {"e3m5", "Wind Tunnels"},
2924         {"e3m6", "Chambers of Torment"},
2925         {"e3m7", "The Haunted Halls"},
2926
2927         {"e4m1", "The Sewage System"},                          // 23
2928         {"e4m2", "The Tower of Despair"},
2929         {"e4m3", "The Elder God Shrine"},
2930         {"e4m4", "The Palace of Hate"},
2931         {"e4m5", "Hell's Atrium"},
2932         {"e4m6", "The Pain Maze"},
2933         {"e4m7", "Azure Agony"},
2934         {"e4m8", "The Nameless City"},
2935
2936         {"end", "Shub-Niggurath's Pit"},                        // 31
2937
2938         {"dm1", "Place of Two Deaths"},                         // 32
2939         {"dm2", "Claustrophobopolis"},
2940         {"dm3", "The Abandoned Base"},
2941         {"dm4", "The Bad Place"},
2942         {"dm5", "The Cistern"},
2943         {"dm6", "The Dark Zone"}
2944 };
2945
2946 episode_t quakeepisodes[] =
2947 {
2948         {"Welcome to Quake", 0, 1},
2949         {"Doomed Dimension", 1, 8},
2950         {"Realm of Black Magic", 9, 7},
2951         {"Netherworld", 16, 7},
2952         {"The Elder World", 23, 8},
2953         {"Final Level", 31, 1},
2954         {"Deathmatch Arena", 32, 6}
2955 };
2956
2957  //MED 01/06/97 added hipnotic levels
2958 level_t     hipnoticlevels[] =
2959 {
2960    {"start", "Command HQ"},  // 0
2961
2962    {"hip1m1", "The Pumping Station"},          // 1
2963    {"hip1m2", "Storage Facility"},
2964    {"hip1m3", "The Lost Mine"},
2965    {"hip1m4", "Research Facility"},
2966    {"hip1m5", "Military Complex"},
2967
2968    {"hip2m1", "Ancient Realms"},          // 6
2969    {"hip2m2", "The Black Cathedral"},
2970    {"hip2m3", "The Catacombs"},
2971    {"hip2m4", "The Crypt"},
2972    {"hip2m5", "Mortum's Keep"},
2973    {"hip2m6", "The Gremlin's Domain"},
2974
2975    {"hip3m1", "Tur Torment"},       // 12
2976    {"hip3m2", "Pandemonium"},
2977    {"hip3m3", "Limbo"},
2978    {"hip3m4", "The Gauntlet"},
2979
2980    {"hipend", "Armagon's Lair"},       // 16
2981
2982    {"hipdm1", "The Edge of Oblivion"}           // 17
2983 };
2984
2985 //MED 01/06/97  added hipnotic episodes
2986 episode_t   hipnoticepisodes[] =
2987 {
2988    {"Scourge of Armagon", 0, 1},
2989    {"Fortress of the Dead", 1, 5},
2990    {"Dominion of Darkness", 6, 6},
2991    {"The Rift", 12, 4},
2992    {"Final Level", 16, 1},
2993    {"Deathmatch Arena", 17, 1}
2994 };
2995
2996 //PGM 01/07/97 added rogue levels
2997 //PGM 03/02/97 added dmatch level
2998 level_t         roguelevels[] =
2999 {
3000         {"start",       "Split Decision"},
3001         {"r1m1",        "Deviant's Domain"},
3002         {"r1m2",        "Dread Portal"},
3003         {"r1m3",        "Judgement Call"},
3004         {"r1m4",        "Cave of Death"},
3005         {"r1m5",        "Towers of Wrath"},
3006         {"r1m6",        "Temple of Pain"},
3007         {"r1m7",        "Tomb of the Overlord"},
3008         {"r2m1",        "Tempus Fugit"},
3009         {"r2m2",        "Elemental Fury I"},
3010         {"r2m3",        "Elemental Fury II"},
3011         {"r2m4",        "Curse of Osiris"},
3012         {"r2m5",        "Wizard's Keep"},
3013         {"r2m6",        "Blood Sacrifice"},
3014         {"r2m7",        "Last Bastion"},
3015         {"r2m8",        "Source of Evil"},
3016         {"ctf1",    "Division of Change"}
3017 };
3018
3019 //PGM 01/07/97 added rogue episodes
3020 //PGM 03/02/97 added dmatch episode
3021 episode_t       rogueepisodes[] =
3022 {
3023         {"Introduction", 0, 1},
3024         {"Hell's Fortress", 1, 7},
3025         {"Corridors of Time", 8, 8},
3026         {"Deathmatch Arena", 16, 1}
3027 };
3028
3029 level_t         nehahralevels[] =
3030 {
3031         {"nehstart",    "Welcome to Nehahra"},
3032         {"neh1m1",      "Forge City1: Slipgates"},
3033         {"neh1m2",      "Forge City2: Boiler"},
3034         {"neh1m3",      "Forge City3: Escape"},
3035         {"neh1m4",      "Grind Core"},
3036         {"neh1m5",      "Industrial Silence"},
3037         {"neh1m6",      "Locked-Up Anger"},
3038         {"neh1m7",      "Wanderer of the Wastes"},
3039         {"neh1m8",      "Artemis System Net"},
3040         {"neh1m9",      "To the Death"},
3041         {"neh2m1",      "The Gates of Ghoro"},
3042         {"neh2m2",      "Sacred Trinity"},
3043         {"neh2m3",      "Realm of the Ancients"},
3044         {"neh2m4",      "Temple of the Ancients"},
3045         {"neh2m5",      "Dreams Made Flesh"},
3046         {"neh2m6",      "Your Last Cup of Sorrow"},
3047         {"nehsec",      "Ogre's Bane"},
3048         {"nehahra",     "Nehahra's Den"},
3049         {"nehend",      "Quintessence"}
3050 };
3051
3052 episode_t       nehahraepisodes[] =
3053 {
3054         {"Welcome to Nehahra", 0, 1},
3055         {"The Fall of Forge", 1, 9},
3056         {"The Outlands", 10, 7},
3057         {"Dimension of the Lost", 17, 2}
3058 };
3059
3060 // Map list for Transfusion
3061 level_t         transfusionlevels[] =
3062 {
3063         {"bb1",                 "The Stronghold"},
3064         {"bb2",                 "Winter Wonderland"},
3065         {"bb3",                 "Bodies"},
3066         {"bb4",                 "The Tower"},
3067         {"bb5",                 "Click!"},
3068         {"bb6",                 "Twin Fortress"},
3069         {"bb7",                 "Midgard"},
3070         {"bb8",                 "Fun With Heads"},
3071
3072         {"e1m1",                "Cradle to Grave"},
3073         {"e1m2",                "Wrong Side of the Tracks"},
3074         {"e1m7",                "Altar of Stone"},
3075         {"e2m8",                "The Lair of Shial"},
3076         {"e3m1",                "Ghost Town"},
3077         {"e3m7",                "The Pit of Cerberus"},
3078         {"e4m1",                "Butchery Loves Company"},
3079         {"e4m7",                "In the Flesh"},
3080         {"e4m8",                "The Hall of the Epiphany"},
3081         {"e4m9",                "Mall of the Dead"},
3082
3083         {"dm1",                 "Monolith Building 11"},
3084         {"dm2",                 "Power!"},
3085         {"dm3",                 "Area 15"},
3086         {"e6m1",                "Welcome to Your Life"},
3087         {"e6m8",                "Beauty and the Beast"},
3088         {"e6m9",                "Forgotten Catacombs"},
3089
3090         {"cpbb01",              "Crypt of Despair"},
3091         {"cpbb03",              "Unholy Cathedral"},
3092
3093         {"b2a15",               "Area 15 (B2)"},
3094         {"barena",              "Blood Arena"},
3095         {"bkeep",               "Blood Keep"},
3096         {"bstar",               "Brown Star"},
3097         {"crypt",               "The Crypt"},
3098
3099         {"bb3_2k1",             "Bodies Infusion"},
3100         {"captasao",    "Captasao"},
3101         {"curandero",   "Curandero"},
3102         {"dcamp",               "DeathCamp"},
3103         {"highnoon",    "HighNoon"},
3104         {"qbb1",                "The Confluence"},
3105         {"qbb2",                "KathartiK"},
3106         {"qbb3",                "Caleb's Woodland Retreat"},
3107         {"zoo",                 "Zoo"},
3108
3109         {"dranzbb6",    "Black Coffee"},
3110         {"fragm",               "Frag'M"},
3111         {"maim",                "Maim"},
3112         {"qe1m7",               "The House of Chthon"},
3113         {"qmorbias",    "Dm-Morbias"},
3114         {"simple",              "Dead Simple"}
3115 };
3116
3117 episode_t       transfusionepisodes[] =
3118 {
3119         {"Blood", 0, 8},
3120         {"Blood Single Player", 8, 10},
3121         {"Plasma Pack", 18, 6},
3122         {"Cryptic Passage", 24, 2},
3123         {"Blood 2", 26, 5},
3124         {"Transfusion", 31, 9},
3125         {"Conversions", 40, 6}
3126 };
3127
3128 level_t goodvsbad2levels[] =
3129 {
3130         {"rts", "Many Paths"},  // 0
3131         {"chess", "Chess, Scott Hess"},                         // 1
3132         {"dot", "Big Wall"},
3133         {"city2", "The Big City"},
3134         {"bwall", "0 G like Psychic TV"},
3135         {"snow", "Wireframed"},
3136         {"telep", "Infinite Falling"},
3137         {"faces", "Facing Bases"},
3138         {"island", "Adventure Islands"},
3139 };
3140
3141 episode_t goodvsbad2episodes[] =
3142 {
3143         {"Levels? Bevels!", 0, 8},
3144 };
3145
3146 level_t battlemechlevels[] =
3147 {
3148         {"start", "Parking Level"},
3149         {"dm1", "Hot Dump"},                        // 1
3150         {"dm2", "The Pits"},
3151         {"dm3", "Dimber Died"},
3152         {"dm4", "Fire in the Hole"},
3153         {"dm5", "Clubhouses"},
3154         {"dm6", "Army go Underground"},
3155 };
3156
3157 episode_t battlemechepisodes[] =
3158 {
3159         {"Time for Battle", 0, 7},
3160 };
3161
3162 level_t openquartzlevels[] =
3163 {
3164         {"start", "Welcome to Openquartz"},
3165
3166         {"void1", "The center of nowhere"},                        // 1
3167         {"void2", "The place with no name"},
3168         {"void3", "The lost supply base"},
3169         {"void4", "Past the outer limits"},
3170         {"void5", "Into the nonexistance"},
3171         {"void6", "Void walk"},
3172
3173         {"vtest", "Warp Central"},
3174         {"box", "The deathmatch box"},
3175         {"bunkers", "Void command"},
3176         {"house", "House of chaos"},
3177         {"office", "Overnight office kill"},
3178         {"am1", "The nameless chambers"},
3179 };
3180
3181 episode_t openquartzepisodes[] =
3182 {
3183         {"Single Player", 0, 1},
3184         {"Void Deathmatch", 1, 6},
3185         {"Contrib", 7, 6},
3186 };
3187
3188 gamelevels_t sharewarequakegame = {"Shareware Quake", quakelevels, quakeepisodes, 2};
3189 gamelevels_t registeredquakegame = {"Quake", quakelevels, quakeepisodes, 7};
3190 gamelevels_t hipnoticgame = {"Scourge of Armagon", hipnoticlevels, hipnoticepisodes, 6};
3191 gamelevels_t roguegame = {"Dissolution of Eternity", roguelevels, rogueepisodes, 4};
3192 gamelevels_t nehahragame = {"Nehahra", nehahralevels, nehahraepisodes, 4};
3193 gamelevels_t transfusiongame = {"Transfusion", transfusionlevels, transfusionepisodes, 7};
3194 gamelevels_t goodvsbad2game = {"Good Vs. Bad 2", goodvsbad2levels, goodvsbad2episodes, 1};
3195 gamelevels_t battlemechgame = {"Battlemech", battlemechlevels, battlemechepisodes, 1};
3196 gamelevels_t openquartzgame = {"OpenQuartz", openquartzlevels, openquartzepisodes, 3};
3197
3198 typedef struct
3199 {
3200         int gameid;
3201         gamelevels_t *notregistered;
3202         gamelevels_t *registered;
3203 }
3204 gameinfo_t;
3205
3206 gameinfo_t gamelist[] =
3207 {
3208         {GAME_NORMAL, &sharewarequakegame, &registeredquakegame},
3209         {GAME_HIPNOTIC, &hipnoticgame, &hipnoticgame},
3210         {GAME_ROGUE, &roguegame, &roguegame},
3211         {GAME_NEHAHRA, &nehahragame, &nehahragame},
3212         {GAME_TRANSFUSION, &transfusiongame, &transfusiongame},
3213         {GAME_GOODVSBAD2, &goodvsbad2game, &goodvsbad2game},
3214         {GAME_BATTLEMECH, &battlemechgame, &battlemechgame},
3215         {GAME_OPENQUARTZ, &openquartzgame, &openquartzgame},
3216         {-1, &sharewarequakegame, &registeredquakegame} // final fallback
3217 };
3218
3219 gamelevels_t *lookupgameinfo(void)
3220 {
3221         int i;
3222         for (i = 0;gamelist[i].gameid >= 0 && gamelist[i].gameid != gamemode;i++);
3223         if (registered.integer)
3224                 return gamelist[i].registered;
3225         else
3226                 return gamelist[i].notregistered;
3227 }
3228
3229 int     startepisode;
3230 int     startlevel;
3231 int maxplayers;
3232 qboolean m_serverInfoMessage = false;
3233 double m_serverInfoMessageTime;
3234
3235 extern cvar_t sv_public;
3236 extern cvar_t sv_maxrate;
3237
3238 void M_Menu_GameOptions_f (void)
3239 {
3240         key_dest = key_menu;
3241         m_state = m_gameoptions;
3242         m_entersound = true;
3243         if (maxplayers == 0)
3244                 maxplayers = svs.maxclients;
3245         if (maxplayers < 2)
3246                 maxplayers = min(8, MAX_SCOREBOARD);
3247 }
3248
3249
3250 int gameoptions_cursor_table[] = {40, 56, 64, 72, 80, 88, 96, 104, 112, 140, 160, 168};
3251 #define NUM_GAMEOPTIONS 12
3252 int             gameoptions_cursor;
3253
3254 void M_GameOptions_Draw (void)
3255 {
3256         cachepic_t      *p;
3257         int             x;
3258         gamelevels_t *g;
3259
3260         M_Background(320, 200);
3261
3262         M_DrawPic (16, 4, "gfx/qplaque.lmp");
3263         p = Draw_CachePic ("gfx/p_multi.lmp");
3264         M_DrawPic ( (320-p->width)/2, 4, "gfx/p_multi.lmp");
3265
3266         M_DrawTextBox (152, 32, 10, 1);
3267         M_Print(160, 40, "begin game");
3268
3269         M_Print(0, 56, "      Max players");
3270         M_Print(160, 56, va("%i", maxplayers) );
3271
3272         if (gamemode != GAME_GOODVSBAD2)
3273         {
3274                 M_Print(0, 64, "        Game Type");
3275                 if (gamemode == GAME_TRANSFUSION)
3276                 {
3277                         if (!deathmatch.integer)
3278                                 Cvar_SetValue("deathmatch", 1);
3279                         if (deathmatch.integer == 2)
3280                                 M_Print(160, 64, "Capture the Flag");
3281                         else
3282                                 M_Print(160, 64, "Blood Bath");
3283                 }
3284                 else if (gamemode == GAME_BATTLEMECH)
3285                 {
3286                         if (!deathmatch.integer)
3287                                 Cvar_SetValue("deathmatch", 1);
3288                         if (deathmatch.integer == 2)
3289                                 M_Print(160, 64, "Rambo Match");
3290                         else
3291                                 M_Print(160, 64, "Deathmatch");
3292                 }
3293                 else
3294                 {
3295                         if (!coop.integer && !deathmatch.integer)
3296                                 Cvar_SetValue("deathmatch", 1);
3297                         if (coop.integer)
3298                                 M_Print(160, 64, "Cooperative");
3299                         else
3300                                 M_Print(160, 64, "Deathmatch");
3301                 }
3302
3303                 M_Print(0, 72, "        Teamplay");
3304                 if (gamemode == GAME_ROGUE)
3305                 {
3306                         char *msg;
3307
3308                         switch((int)teamplay.integer)
3309                         {
3310                                 case 1: msg = "No Friendly Fire"; break;
3311                                 case 2: msg = "Friendly Fire"; break;
3312                                 case 3: msg = "Tag"; break;
3313                                 case 4: msg = "Capture the Flag"; break;
3314                                 case 5: msg = "One Flag CTF"; break;
3315                                 case 6: msg = "Three Team CTF"; break;
3316                                 default: msg = "Off"; break;
3317                         }
3318                         M_Print(160, 72, msg);
3319                 }
3320                 else
3321                 {
3322                         char *msg;
3323
3324                         switch (teamplay.integer)
3325                         {
3326                                 case 0: msg = "Off"; break;
3327                                 case 2: msg = "Friendly Fire"; break;
3328                                 default: msg = "No Friendly Fire"; break;
3329                         }
3330                         M_Print(160, 72, msg);
3331                 }
3332
3333                 M_Print(0, 80, "            Skill");
3334                 if (skill.integer == 0)
3335                         M_Print(160, 80, "Easy difficulty");
3336                 else if (skill.integer == 1)
3337                         M_Print(160, 80, "Normal difficulty");
3338                 else if (skill.integer == 2)
3339                         M_Print(160, 80, "Hard difficulty");
3340                 else
3341                         M_Print(160, 80, "Nightmare difficulty");
3342
3343                 M_Print(0, 88, "       Frag Limit");
3344                 if (fraglimit.integer == 0)
3345                         M_Print(160, 88, "none");
3346                 else
3347                         M_Print(160, 88, va("%i frags", fraglimit.integer));
3348
3349                 M_Print(0, 96, "       Time Limit");
3350                 if (timelimit.integer == 0)
3351                         M_Print(160, 96, "none");
3352                 else
3353                         M_Print(160, 96, va("%i minutes", timelimit.integer));
3354         }
3355
3356         M_Print(0, 104, "    Public server");
3357         M_Print(160, 104, (sv_public.integer == 0) ? "no" : "yes");
3358
3359         M_Print(0, 112, "   Server maxrate");
3360         M_Print(160, 112, va("%i", sv_maxrate.integer));
3361
3362         M_Print(0, 128, "      Server name");
3363         M_DrawTextBox (0, 132, 38, 1);
3364         M_Print(8, 140, hostname.string);
3365
3366         g = lookupgameinfo();
3367
3368         if (gamemode != GAME_GOODVSBAD2)
3369         {
3370                 M_Print(0, 160, "         Episode");
3371                 M_Print(160, 160, g->episodes[startepisode].description);
3372         }
3373
3374         M_Print(0, 168, "           Level");
3375         M_Print(160, 168, g->levels[g->episodes[startepisode].firstLevel + startlevel].description);
3376         M_Print(160, 176, g->levels[g->episodes[startepisode].firstLevel + startlevel].name);
3377
3378 // line cursor
3379         if (gameoptions_cursor == 9)
3380                 M_DrawCharacter (8 + 8 * strlen(hostname.string), gameoptions_cursor_table[gameoptions_cursor], 10+((int)(realtime*4)&1));
3381         else
3382                 M_DrawCharacter (144, gameoptions_cursor_table[gameoptions_cursor], 12+((int)(realtime*4)&1));
3383
3384         if (m_serverInfoMessage)
3385         {
3386                 if ((realtime - m_serverInfoMessageTime) < 5.0)
3387                 {
3388                         x = (320-26*8)/2;
3389                         M_DrawTextBox (x, 138, 24, 4);
3390                         x += 8;
3391                         M_Print(x, 146, " More than 64 players?? ");
3392                         M_Print(x, 154, "  First, question your  ");
3393                         M_Print(x, 162, "   sanity, then email   ");
3394                         M_Print(x, 170, " havoc@telefragged.com  ");
3395                 }
3396                 else
3397                         m_serverInfoMessage = false;
3398         }
3399 }
3400
3401
3402 void M_NetStart_Change (int dir)
3403 {
3404         gamelevels_t *g;
3405         int count;
3406
3407         switch (gameoptions_cursor)
3408         {
3409         case 1:
3410                 maxplayers += dir;
3411                 if (maxplayers > MAX_SCOREBOARD)
3412                 {
3413                         maxplayers = MAX_SCOREBOARD;
3414                         m_serverInfoMessage = true;
3415                         m_serverInfoMessageTime = realtime;
3416                 }
3417                 if (maxplayers < 2)
3418                         maxplayers = 2;
3419                 break;
3420
3421         case 2:
3422                 if (gamemode == GAME_GOODVSBAD2)
3423                         break;
3424                 if (gamemode == GAME_TRANSFUSION)
3425                 {
3426                         if (deathmatch.integer == 2) // changing from CTF to BloodBath
3427                                 Cvar_SetValueQuick (&deathmatch, 0);
3428                         else // changing from BloodBath to CTF
3429                                 Cvar_SetValueQuick (&deathmatch, 2);
3430                 }
3431                 else if (gamemode == GAME_BATTLEMECH)
3432                 {
3433                         if (deathmatch.integer == 2) // changing from Rambo to Deathmatch
3434                                 Cvar_SetValueQuick (&deathmatch, 0);
3435                         else // changing from Deathmatch to Rambo
3436                                 Cvar_SetValueQuick (&deathmatch, 2);
3437                 }
3438                 else
3439                 {
3440                         if (deathmatch.integer) // changing from deathmatch to coop
3441                         {
3442                                 Cvar_SetValueQuick (&coop, 1);
3443                                 Cvar_SetValueQuick (&deathmatch, 0);
3444                         }
3445                         else // changing from coop to deathmatch
3446                         {
3447                                 Cvar_SetValueQuick (&coop, 0);
3448                                 Cvar_SetValueQuick (&deathmatch, 1);
3449                         }
3450                 }
3451                 break;
3452
3453         case 3:
3454                 if (gamemode == GAME_GOODVSBAD2)
3455                         break;
3456                 if (gamemode == GAME_ROGUE)
3457                         count = 6;
3458                 else
3459                         count = 2;
3460
3461                 Cvar_SetValueQuick (&teamplay, teamplay.integer + dir);
3462                 if (teamplay.integer > count)
3463                         Cvar_SetValueQuick (&teamplay, 0);
3464                 else if (teamplay.integer < 0)
3465                         Cvar_SetValueQuick (&teamplay, count);
3466                 break;
3467
3468         case 4:
3469                 if (gamemode == GAME_GOODVSBAD2)
3470                         break;
3471                 Cvar_SetValueQuick (&skill, skill.integer + dir);
3472                 if (skill.integer > 3)
3473                         Cvar_SetValueQuick (&skill, 0);
3474                 if (skill.integer < 0)
3475                         Cvar_SetValueQuick (&skill, 3);
3476                 break;
3477
3478         case 5:
3479                 if (gamemode == GAME_GOODVSBAD2)
3480                         break;
3481                 Cvar_SetValueQuick (&fraglimit, fraglimit.integer + dir*10);
3482                 if (fraglimit.integer > 100)
3483                         Cvar_SetValueQuick (&fraglimit, 0);
3484                 if (fraglimit.integer < 0)
3485                         Cvar_SetValueQuick (&fraglimit, 100);
3486                 break;
3487
3488         case 6:
3489                 if (gamemode == GAME_GOODVSBAD2)
3490                         break;
3491                 Cvar_SetValueQuick (&timelimit, timelimit.value + dir*5);
3492                 if (timelimit.value > 60)
3493                         Cvar_SetValueQuick (&timelimit, 0);
3494                 if (timelimit.value < 0)
3495                         Cvar_SetValueQuick (&timelimit, 60);
3496                 break;
3497
3498         case 7:
3499                 Cvar_SetValueQuick (&sv_public, !sv_public.integer);
3500                 break;
3501
3502         case 8:
3503                 Cvar_SetValueQuick (&sv_maxrate, sv_maxrate.integer + dir*500);
3504                 if (sv_maxrate.integer > NET_MAXRATE)
3505                         Cvar_SetValueQuick (&sv_maxrate, NET_MAXRATE);
3506                 if (sv_maxrate.integer < NET_MINRATE)
3507                         Cvar_SetValueQuick (&sv_maxrate, NET_MINRATE);
3508                 break;
3509
3510         case 9:
3511                 break;
3512
3513         case 10:
3514                 if (gamemode == GAME_GOODVSBAD2)
3515                         break;
3516                 startepisode += dir;
3517                 g = lookupgameinfo();
3518
3519                 if (startepisode < 0)
3520                         startepisode = g->numepisodes - 1;
3521
3522                 if (startepisode >= g->numepisodes)
3523                         startepisode = 0;
3524
3525                 startlevel = 0;
3526                 break;
3527
3528         case 11:
3529                 startlevel += dir;
3530                 g = lookupgameinfo();
3531
3532                 if (startlevel < 0)
3533                         startlevel = g->episodes[startepisode].levels - 1;
3534
3535                 if (startlevel >= g->episodes[startepisode].levels)
3536                         startlevel = 0;
3537                 break;
3538         }
3539 }
3540
3541 void M_GameOptions_Key (int key, char ascii)
3542 {
3543         gamelevels_t *g;
3544         int l;
3545         char hostnamebuf[128];
3546
3547         switch (key)
3548         {
3549         case K_ESCAPE:
3550                 M_Menu_MultiPlayer_f ();
3551                 break;
3552
3553         case K_UPARROW:
3554                 S_LocalSound ("misc/menu1.wav", true);
3555                 gameoptions_cursor--;
3556                 if (gameoptions_cursor < 0)
3557                         gameoptions_cursor = NUM_GAMEOPTIONS-1;
3558                 break;
3559
3560         case K_DOWNARROW:
3561                 S_LocalSound ("misc/menu1.wav", true);
3562                 gameoptions_cursor++;
3563                 if (gameoptions_cursor >= NUM_GAMEOPTIONS)
3564                         gameoptions_cursor = 0;
3565                 break;
3566
3567         case K_LEFTARROW:
3568                 if (gameoptions_cursor == 0)
3569                         break;
3570                 S_LocalSound ("misc/menu3.wav", true);
3571                 M_NetStart_Change (-1);
3572                 break;
3573
3574         case K_RIGHTARROW:
3575                 if (gameoptions_cursor == 0)
3576                         break;
3577                 S_LocalSound ("misc/menu3.wav", true);
3578                 M_NetStart_Change (1);
3579                 break;
3580
3581         case K_ENTER:
3582                 S_LocalSound ("misc/menu2.wav", true);
3583                 if (gameoptions_cursor == 0)
3584                 {
3585                         if (sv.active)
3586                                 Cbuf_AddText ("disconnect\n");
3587                         Cbuf_AddText ( va ("maxplayers %u\n", maxplayers) );
3588
3589                         g = lookupgameinfo();
3590                         Cbuf_AddText ( va ("map %s\n", g->levels[g->episodes[startepisode].firstLevel + startlevel].name) );
3591                         return;
3592                 }
3593
3594                 M_NetStart_Change (1);
3595                 break;
3596
3597         case K_BACKSPACE:
3598                 if (gameoptions_cursor == 9)
3599                 {
3600                         l = strlen(hostname.string);
3601                         if (l)
3602                         {
3603                                 l = min(l - 1, 37);
3604                                 memcpy(hostnamebuf, hostname.string, l);
3605                                 hostnamebuf[l] = 0;
3606                                 Cvar_Set("hostname", hostnamebuf);
3607                         }
3608                 }
3609                 break;
3610
3611         default:
3612                 if (ascii < 32 || ascii > 126)
3613                         break;
3614                 if (gameoptions_cursor == 9)
3615                 {
3616                         l = strlen(hostname.string);
3617                         if (l < 37)
3618                         {
3619                                 memcpy(hostnamebuf, hostname.string, l);
3620                                 hostnamebuf[l] = ascii;
3621                                 hostnamebuf[l+1] = 0;
3622                                 Cvar_Set("hostname", hostnamebuf);
3623                         }
3624                 }
3625         }
3626 }
3627
3628 //=============================================================================
3629 /* SLIST MENU */
3630
3631 int slist_cursor;
3632
3633 void M_Menu_ServerList_f (void)
3634 {
3635         key_dest = key_menu;
3636         m_state = m_slist;
3637         m_entersound = true;
3638         slist_cursor = 0;
3639         m_return_reason[0] = 0;
3640         Net_Slist_f();
3641 }
3642
3643
3644 void M_ServerList_Draw (void)
3645 {
3646         int n, y, visible, start, end;
3647         cachepic_t *p;
3648         const char *s;
3649
3650         // use as much vertical space as available
3651         M_Background(640, vid.conheight);
3652         // scroll the list as the cursor moves
3653         s = va("%i/%i masters %i/%i servers", masterreplycount, masterquerycount, serverreplycount, serverquerycount);
3654         M_PrintRed((640 - strlen(s) * 8) / 2, 32, s);
3655         if (*m_return_reason)
3656                 M_Print(16, vid.conheight - 8, m_return_reason);
3657         y = 48;
3658         visible = (vid.conheight - 16 - y) / 8;
3659         start = bound(0, slist_cursor - (visible >> 1), hostCacheCount - visible);
3660         end = min(start + visible, hostCacheCount);
3661
3662         p = Draw_CachePic("gfx/p_multi.lmp");
3663         M_DrawPic((640 - p->width) / 2, 4, "gfx/p_multi.lmp");
3664         if (end > start)
3665         {
3666                 for (n = start;n < end;n++)
3667                 {
3668                         DrawQ_Fill(menu_x, menu_y + y, 640, 16, n == slist_cursor ? (0.5 + 0.2 * sin(realtime * M_PI)) : 0, 0, 0, 0.5, 0);
3669                         M_Print(0, y, hostcache[n].line1);y += 8;
3670                         M_Print(0, y, hostcache[n].line2);y += 8;
3671                 }
3672         }
3673         else if (realtime - masterquerytime < 3)
3674         {
3675                 if (masterquerycount)
3676                         M_Print(0, y, "No servers found");
3677                 else
3678                         M_Print(0, y, "No master servers found (network problem?)");
3679         }
3680 }
3681
3682
3683 void M_ServerList_Key(int k, char ascii)
3684 {
3685         switch (k)
3686         {
3687         case K_ESCAPE:
3688                 M_Menu_LanConfig_f();
3689                 break;
3690
3691         case K_SPACE:
3692                 Net_Slist_f();
3693                 break;
3694
3695         case K_UPARROW:
3696         case K_LEFTARROW:
3697                 S_LocalSound("misc/menu1.wav", true);
3698                 slist_cursor--;
3699                 if (slist_cursor < 0)
3700                         slist_cursor = hostCacheCount - 1;
3701                 break;
3702
3703         case K_DOWNARROW:
3704         case K_RIGHTARROW:
3705                 S_LocalSound("misc/menu1.wav", true);
3706                 slist_cursor++;
3707                 if (slist_cursor >= hostCacheCount)
3708                         slist_cursor = 0;
3709                 break;
3710
3711         case K_ENTER:
3712                 S_LocalSound("misc/menu2.wav", true);
3713                 Cbuf_AddText(va("connect \"%s\"\n", hostcache[slist_cursor].cname));
3714                 break;
3715
3716         default:
3717                 break;
3718         }
3719
3720 }
3721
3722 //=============================================================================
3723 /* Menu Subsystem */
3724
3725 void M_Keydown(int key, char ascii);
3726 void M_Draw(void);
3727 void M_ToggleMenu_f(void);
3728 void M_Shutdown(void);
3729
3730 void M_Init (void)
3731 {
3732         menu_mempool = Mem_AllocPool("Menu", 0, NULL);
3733         menuplyr_load = true;
3734         menuplyr_pixels = NULL;
3735
3736         Cmd_AddCommand ("menu_main", M_Menu_Main_f);
3737         Cmd_AddCommand ("menu_singleplayer", M_Menu_SinglePlayer_f);
3738         Cmd_AddCommand ("menu_load", M_Menu_Load_f);
3739         Cmd_AddCommand ("menu_save", M_Menu_Save_f);
3740         Cmd_AddCommand ("menu_multiplayer", M_Menu_MultiPlayer_f);
3741         Cmd_AddCommand ("menu_setup", M_Menu_Setup_f);
3742         Cmd_AddCommand ("menu_options", M_Menu_Options_f);
3743         Cmd_AddCommand ("menu_options_effects", M_Menu_Options_Effects_f);
3744         Cmd_AddCommand ("menu_options_graphics", M_Menu_Options_Graphics_f);
3745         Cmd_AddCommand ("menu_options_colorcontrol", M_Menu_Options_ColorControl_f);
3746         Cvar_RegisterVariable (&menu_options_colorcontrol_correctionvalue);
3747         Cmd_AddCommand ("menu_keys", M_Menu_Keys_f);
3748         Cmd_AddCommand ("menu_video", M_Menu_Video_f);
3749         Cmd_AddCommand ("help", M_Menu_Help_f);
3750         Cmd_AddCommand ("menu_quit", M_Menu_Quit_f);
3751
3752         if (gamemode == GAME_TRANSFUSION)
3753         {
3754                 numcommands = sizeof(transfusionbindnames) / sizeof(transfusionbindnames[0]);
3755                 bindnames = transfusionbindnames;
3756         }
3757         else if (gamemode == GAME_GOODVSBAD2)
3758         {
3759                 numcommands = sizeof(goodvsbad2bindnames) / sizeof(goodvsbad2bindnames[0]);
3760                 bindnames = goodvsbad2bindnames;
3761         }
3762         else
3763         {
3764                 numcommands = sizeof(quakebindnames) / sizeof(quakebindnames[0]);
3765                 bindnames = quakebindnames;
3766         }
3767
3768         // Make sure "keys_cursor" doesn't start on a section in the binding list
3769         keys_cursor = 0;
3770         while (bindnames[keys_cursor][0][0] == '\0')
3771         {
3772                 keys_cursor++;
3773
3774                 // Only sections? There may be a problem somewhere...
3775                 if (keys_cursor >= numcommands)
3776                         Sys_Error ("M_Init: The key binding list only contains sections");
3777         }
3778
3779
3780         if (gamemode == GAME_NEHAHRA)
3781         {
3782                 if (FS_FileExists("maps/neh1m4.bsp"))
3783                 {
3784                         if (FS_FileExists("hearing.dem"))
3785                         {
3786                                 Con_Print("Nehahra movie and game detected.\n");
3787                                 NehGameType = TYPE_BOTH;
3788                         }
3789                         else
3790                         {
3791                                 Con_Print("Nehahra game detected.\n");
3792                                 NehGameType = TYPE_GAME;
3793                         }
3794                 }
3795                 else
3796                 {
3797                         if (FS_FileExists("hearing.dem"))
3798                         {
3799                                 Con_Print("Nehahra movie detected.\n");
3800                                 NehGameType = TYPE_DEMO;
3801                         }
3802                         else
3803                         {
3804                                 Con_Print("Nehahra not found.\n");
3805                                 NehGameType = TYPE_GAME; // could just complain, but...
3806                         }
3807                 }
3808         }
3809 }
3810
3811 void M_Draw (void)
3812 {
3813         if (key_dest != key_menu)
3814                 m_state = m_none;
3815
3816         if (m_state == m_none)
3817                 return;
3818
3819         switch (m_state)
3820         {
3821         case m_none:
3822                 break;
3823
3824         case m_main:
3825                 M_Main_Draw ();
3826                 break;
3827
3828         case m_demo:
3829                 M_Demo_Draw ();
3830                 break;
3831
3832         case m_singleplayer:
3833                 M_SinglePlayer_Draw ();
3834                 break;
3835
3836         case m_load:
3837                 M_Load_Draw ();
3838                 break;
3839
3840         case m_save:
3841                 M_Save_Draw ();
3842                 break;
3843
3844         case m_multiplayer:
3845                 M_MultiPlayer_Draw ();
3846                 break;
3847
3848         case m_setup:
3849                 M_Setup_Draw ();
3850                 break;
3851
3852         case m_options:
3853                 M_Options_Draw ();
3854                 break;
3855
3856         case m_options_effects:
3857                 M_Options_Effects_Draw ();
3858                 break;
3859
3860         case m_options_graphics:
3861                 M_Options_Graphics_Draw ();
3862                 break;
3863
3864         case m_options_colorcontrol:
3865                 M_Options_ColorControl_Draw ();
3866                 break;
3867
3868         case m_keys:
3869                 M_Keys_Draw ();
3870                 break;
3871
3872         case m_video:
3873                 M_Video_Draw ();
3874                 break;
3875
3876         case m_help:
3877                 M_Help_Draw ();
3878                 break;
3879
3880         case m_quit:
3881                 M_Quit_Draw ();
3882                 break;
3883
3884         case m_lanconfig:
3885                 M_LanConfig_Draw ();
3886                 break;
3887
3888         case m_gameoptions:
3889                 M_GameOptions_Draw ();
3890                 break;
3891
3892         case m_slist:
3893                 M_ServerList_Draw ();
3894                 break;
3895         }
3896
3897         if (m_entersound)
3898         {
3899                 S_LocalSound ("misc/menu2.wav", true);
3900                 m_entersound = false;
3901         }
3902
3903         S_ExtraUpdate ();
3904 }
3905
3906
3907 void M_Keydown (int key, char ascii)
3908 {
3909         switch (m_state)
3910         {
3911         case m_none:
3912                 return;
3913
3914         case m_main:
3915                 M_Main_Key (key, ascii);
3916                 return;
3917
3918         case m_demo:
3919                 M_Demo_Key (key, ascii);
3920                 return;
3921
3922         case m_singleplayer:
3923                 M_SinglePlayer_Key (key, ascii);
3924                 return;
3925
3926         case m_load:
3927                 M_Load_Key (key, ascii);
3928                 return;
3929
3930         case m_save:
3931                 M_Save_Key (key, ascii);
3932                 return;
3933
3934         case m_multiplayer:
3935                 M_MultiPlayer_Key (key, ascii);
3936                 return;
3937
3938         case m_setup:
3939                 M_Setup_Key (key, ascii);
3940                 return;
3941
3942         case m_options:
3943                 M_Options_Key (key, ascii);
3944                 return;
3945
3946         case m_options_effects:
3947                 M_Options_Effects_Key (key, ascii);
3948                 return;
3949
3950         case m_options_graphics:
3951                 M_Options_Graphics_Key (key, ascii);
3952                 return;
3953
3954         case m_options_colorcontrol:
3955                 M_Options_ColorControl_Key (key, ascii);
3956                 return;
3957
3958         case m_keys:
3959                 M_Keys_Key (key, ascii);
3960                 return;
3961
3962         case m_video:
3963                 M_Video_Key (key, ascii);
3964                 return;
3965
3966         case m_help:
3967                 M_Help_Key (key, ascii);
3968                 return;
3969
3970         case m_quit:
3971                 M_Quit_Key (key, ascii);
3972                 return;
3973
3974         case m_lanconfig:
3975                 M_LanConfig_Key (key, ascii);
3976                 return;
3977
3978         case m_gameoptions:
3979                 M_GameOptions_Key (key, ascii);
3980                 return;
3981
3982         case m_slist:
3983                 M_ServerList_Key (key, ascii);
3984                 return;
3985         }
3986 }
3987
3988 void M_Shutdown(void)
3989 {
3990         // reset key_dest
3991         key_dest = key_game;
3992 }
3993
3994 void M_Restart(void)
3995 {
3996 }
3997
3998 //============================================================================
3999 // Menu prog handling
4000 mfunction_t *PRVM_ED_FindFunction(const char *);
4001
4002 #define M_F_INIT                "m_init"
4003 #define M_F_KEYDOWN             "m_keydown"
4004 #define M_F_DRAW                "m_draw"
4005 // ng_menu function names
4006 #define M_F_DISPLAY             "m_display"
4007 #define M_F_HIDE                "m_hide"
4008 // normal menu names (rest)
4009 #define M_F_TOGGLE              "m_toggle"
4010 #define M_F_SHUTDOWN    "m_shutdown"
4011
4012 static char *m_required_func[] = {
4013 M_F_INIT,
4014 M_F_KEYDOWN,
4015 M_F_DRAW,
4016 #ifdef NG_MENU
4017 M_F_DISPLAY,
4018 M_F_HIDE,
4019 #else
4020 M_F_TOGGLE,
4021 #endif
4022 M_F_SHUTDOWN,
4023 };
4024
4025 #ifdef NG_MENU
4026 qboolean m_displayed;
4027 #endif
4028
4029 static int m_numrequiredfunc = sizeof(m_required_func) / sizeof(char*);
4030
4031 static func_t m_draw, m_keydown;
4032
4033 void MR_SetRouting (qboolean forceold);
4034
4035 void MP_Error(void)
4036 {
4037         // fall back to the normal menu
4038
4039         // say it
4040         Con_Print("Falling back to normal menu\n");
4041
4042         key_dest = key_game;
4043
4044         //PRVM_ResetProg();
4045
4046         // init the normal menu now -> this will also correct the menu router pointers
4047         MR_SetRouting (TRUE);
4048 }
4049
4050 void MP_Keydown (int key, char ascii)
4051 {
4052         PRVM_Begin;
4053         PRVM_SetProg(PRVM_MENUPROG);
4054
4055         // set time
4056         *prog->time = realtime;
4057
4058         // pass key
4059         prog->globals[OFS_PARM0] = (float) key;
4060         prog->globals[OFS_PARM1] = (float) ascii;
4061         PRVM_ExecuteProgram(m_keydown, M_F_KEYDOWN"(float key, float ascii) required\n");
4062
4063         PRVM_End;
4064 }
4065
4066 void MP_Draw (void)
4067 {
4068         PRVM_Begin;
4069         PRVM_SetProg(PRVM_MENUPROG);
4070
4071         // set time
4072         *prog->time = realtime;
4073
4074         PRVM_ExecuteProgram(m_draw,"");
4075
4076         PRVM_End;
4077 }
4078
4079 void MP_ToggleMenu_f (void)
4080 {
4081         PRVM_Begin;
4082         PRVM_SetProg(PRVM_MENUPROG);
4083
4084         // set time
4085         *prog->time = realtime;
4086
4087 #ifdef NG_MENU
4088         m_displayed = !m_displayed;
4089         if( m_displayed )
4090                 PRVM_ExecuteProgram((func_t) (PRVM_ED_FindFunction(M_F_DISPLAY) - prog->functions),"");
4091         else
4092                 PRVM_ExecuteProgram((func_t) (PRVM_ED_FindFunction(M_F_HIDE) - prog->functions),"");
4093 #else
4094         PRVM_ExecuteProgram((func_t) (PRVM_ED_FindFunction(M_F_TOGGLE) - prog->functions),"");
4095 #endif
4096
4097         PRVM_End;
4098 }
4099
4100 void MP_Shutdown (void)
4101 {
4102         PRVM_Begin;
4103         PRVM_SetProg(PRVM_MENUPROG);
4104
4105         // set time
4106         *prog->time = realtime;
4107
4108         PRVM_ExecuteProgram((func_t) (PRVM_ED_FindFunction(M_F_SHUTDOWN) - prog->functions),"");
4109
4110         // reset key_dest
4111         key_dest = key_game;
4112
4113         // AK not using this cause Im not sure whether this is useful at all instead :
4114         PRVM_ResetProg();
4115
4116         PRVM_End;
4117 }
4118
4119 void MP_Init (void)
4120 {
4121         PRVM_Begin;
4122         PRVM_InitProg(PRVM_MENUPROG);
4123
4124         prog->crc = M_PROGHEADER_CRC;
4125         prog->edictprivate_size = 0; // no private struct used
4126         prog->name = M_NAME;
4127         prog->limit_edicts = M_MAX_EDICTS;
4128         prog->extensionstring = vm_m_extensions;
4129         prog->builtins = vm_m_builtins;
4130         prog->numbuiltins = vm_m_numbuiltins;
4131         prog->init_cmd = VM_M_Cmd_Init;
4132         prog->reset_cmd = VM_M_Cmd_Reset;
4133         prog->error_cmd = MP_Error;
4134
4135         // allocate the mempools
4136         prog->edicts_mempool = Mem_AllocPool(M_NAME " edicts mempool", 0, NULL);
4137         prog->edictstring_mempool = Mem_AllocPool( M_NAME " edict string mempool", 0, NULL);
4138         prog->progs_mempool = Mem_AllocPool(M_PROG_FILENAME, 0, NULL);
4139
4140         PRVM_LoadProgs(M_PROG_FILENAME, m_numrequiredfunc, m_required_func);
4141
4142         // set m_draw and m_keydown
4143         m_draw = (func_t) (PRVM_ED_FindFunction(M_F_DRAW) - prog->functions);
4144         m_keydown = (func_t) (PRVM_ED_FindFunction(M_F_KEYDOWN) - prog->functions);
4145
4146 #ifdef NG_MENU
4147         m_displayed = false;
4148 #endif
4149
4150         // set time
4151         *prog->time = realtime;
4152
4153         // call the prog init
4154         PRVM_ExecuteProgram((func_t) (PRVM_ED_FindFunction(M_F_INIT) - prog->functions),"");
4155
4156         PRVM_End;
4157 }
4158
4159 void MP_Restart(void)
4160 {
4161
4162         MP_Init();
4163 }
4164
4165 //============================================================================
4166 // Menu router
4167
4168 static cvar_t forceqmenu = { 0, "forceqmenu", "0" };
4169
4170 void MR_SetRouting(qboolean forceold)
4171 {
4172         static qboolean m_init = FALSE, mp_init = FALSE;
4173
4174         // if the menu prog isnt available or forceqmenu ist set, use the old menu
4175         if(!FS_FileExists(M_PROG_FILENAME) || forceqmenu.integer || forceold)
4176         {
4177                 // set menu router function pointers
4178                 MR_Keydown = M_Keydown;
4179                 MR_Draw = M_Draw;
4180                 MR_ToggleMenu_f = M_ToggleMenu_f;
4181                 MR_Shutdown = M_Shutdown;
4182
4183                 // init
4184                 if(!m_init)
4185                 {
4186                         M_Init();
4187                         m_init = TRUE;
4188                 }
4189                 else
4190                         M_Restart();
4191         }
4192         else
4193         {
4194                 // set menu router function pointers
4195                 MR_Keydown = MP_Keydown;
4196                 MR_Draw = MP_Draw;
4197                 MR_ToggleMenu_f = MP_ToggleMenu_f;
4198                 MR_Shutdown = MP_Shutdown;
4199
4200                 if(!mp_init)
4201                 {
4202                         MP_Init();
4203                         mp_init = TRUE;
4204                 }
4205                 else
4206                         MP_Restart();
4207         }
4208 }
4209
4210 void MR_Restart(void)
4211 {
4212         MR_Shutdown ();
4213         MR_SetRouting (FALSE);
4214 }
4215
4216 void Call_MR_ToggleMenu_f(void)
4217 {
4218         if(MR_ToggleMenu_f)
4219                 MR_ToggleMenu_f();
4220 }
4221
4222 void MR_Init()
4223 {
4224         // set router console commands
4225         Cvar_RegisterVariable (&forceqmenu);
4226         Cmd_AddCommand ("menu_restart",MR_Restart);
4227         Cmd_AddCommand ("togglemenu", Call_MR_ToggleMenu_f);
4228
4229         // use -forceqmenu to use always the normal quake menu (it sets forceqmenu to 1)
4230         if(COM_CheckParm("-forceqmenu"))
4231                 Cvar_SetValueQuick(&forceqmenu,1);
4232         // use -useqmenu for debugging proposes, cause it starts
4233         // the normal quake menu only the first time
4234         if(COM_CheckParm("-useqmenu"))
4235                 MR_SetRouting (TRUE);
4236         else 
4237                 MR_SetRouting (FALSE);
4238 }