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