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