]> de.git.xonotic.org Git - xonotic/darkplaces.git/blob - menu.c
044dcf8fa02265452b3ec2ad6399764f29956d5b
[xonotic/darkplaces.git] / menu.c
1 /*
2 Copyright (C) 1996-1997 Id Software, Inc.
3
4 This program is free software; you can redistribute it and/or
5 modify it under the terms of the GNU General Public License
6 as published by the Free Software Foundation; either version 2
7 of the License, or (at your option) any later version.
8
9 This program is distributed in the hope that it will be useful,
10 but WITHOUT ANY WARRANTY; without even the implied warranty of
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
12
13 See the GNU General Public License for more details.
14
15 You should have received a copy of the GNU General Public License
16 along with this program; if not, write to the Free Software
17 Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
18
19 */
20 #include "quakedef.h"
21 #include "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         if (fabs((int)num - num) < 0.01)
1099                 sprintf(text, "%i", (int)num);
1100         else
1101                 sprintf(text, "%.2f", num);
1102         M_Print(x + (SLIDER_RANGE+2) * 8, y, text);
1103 }
1104
1105 void M_DrawCheckbox (int x, int y, int on)
1106 {
1107         if (on)
1108                 M_Print (x, y, "on");
1109         else
1110                 M_Print (x, y, "off");
1111 }
1112
1113
1114 #define OPTIONS_ITEMS 33
1115
1116 int options_cursor;
1117
1118 void M_Menu_Options_f (void)
1119 {
1120         key_dest = key_menu;
1121         m_state = m_options;
1122         m_entersound = true;
1123 }
1124
1125 extern cvar_t snd_staticvolume;
1126 extern cvar_t gl_delayfinish;
1127 extern cvar_t slowmo;
1128 extern dllhandle_t jpeg_dll;
1129
1130 void M_Menu_Options_AdjustSliders (int dir)
1131 {
1132         int optnum;
1133         S_LocalSound ("misc/menu3.wav");
1134
1135         optnum = 6;
1136         if (options_cursor == optnum++)
1137                 Cvar_SetValueQuick (&vid_conwidth, bound(320, vid_conwidth.value + dir * 64, 2048));
1138         else if (options_cursor == optnum++)
1139                 Cvar_SetValueQuick (&vid_conheight, bound(240, vid_conheight.value + dir * 48, 1536));
1140         else if (options_cursor == optnum++)
1141                 Cvar_SetValueQuick (&scr_conspeed, bound(0, scr_conspeed.value + dir * 100, 1000));
1142         else if (options_cursor == optnum++)
1143                 Cvar_SetValueQuick (&scr_conalpha, bound(0, scr_conalpha.value + dir * 0.2, 1));
1144         else if (options_cursor == optnum++)
1145                 Cvar_SetValueQuick (&scr_conbrightness, bound(0, scr_conbrightness.value + dir * 0.2, 1));
1146         else if (options_cursor == optnum++)
1147                 Cvar_SetValueQuick (&scr_viewsize, bound(30, scr_viewsize.value + dir * 10, 120));
1148         else if (options_cursor == optnum++)
1149                 Cvar_SetValueQuick (&scr_screenshot_jpeg, !scr_screenshot_jpeg.integer);
1150         else if (options_cursor == optnum++)
1151                 Cvar_SetValueQuick (&r_sky, !r_sky.integer);
1152         else if (options_cursor == optnum++)
1153                 Cvar_SetValueQuick (&v_overbrightbits, bound(0, v_overbrightbits.integer + dir, 4));
1154         else if (options_cursor == optnum++)
1155                 Cvar_SetValueQuick (&gl_combine, !gl_combine.integer);
1156         else if (options_cursor == optnum++)
1157                 Cvar_SetValueQuick (&gl_dither, !gl_dither.integer);
1158         else if (options_cursor == optnum++)
1159                 Cvar_SetValueQuick (&gl_delayfinish, !gl_delayfinish.integer);
1160         else if (options_cursor == optnum++)
1161                 Cvar_SetValueQuick (&slowmo, bound(0, slowmo.value + dir * 0.25, 5));
1162         else if (options_cursor == optnum++)
1163 #ifdef _WIN32
1164                 Cvar_SetValueQuick (&bgmvolume, bound(0, bgmvolume.value + dir * 1.0, 1));
1165 #else
1166                 Cvar_SetValueQuick (&bgmvolume, bound(0, bgmvolume.value + dir * 0.1, 1));
1167 #endif
1168         else if (options_cursor == optnum++)
1169                 Cvar_SetValueQuick (&volume, bound(0, volume.value + dir * 0.1, 1));
1170         else if (options_cursor == optnum++)
1171                 Cvar_SetValueQuick (&snd_staticvolume, bound(0, snd_staticvolume.value + dir * 0.1, 1));
1172         else if (options_cursor == optnum++)
1173                 Cvar_SetValueQuick (&crosshair, bound(0, crosshair.integer + dir, 5));
1174         else if (options_cursor == optnum++)
1175                 Cvar_SetValueQuick (&crosshair_size, bound(1, crosshair_size.value + dir, 5));
1176         else if (options_cursor == optnum++)
1177                 Cvar_SetValueQuick (&crosshair_static, !crosshair_static.integer);
1178         else if (options_cursor == optnum++)
1179                 Cvar_SetValueQuick (&showfps, !showfps.integer);
1180         else if (options_cursor == optnum++)
1181         {
1182                 if (cl_forwardspeed.value > 200)
1183                 {
1184                         Cvar_SetValueQuick (&cl_forwardspeed, 200);
1185                         Cvar_SetValueQuick (&cl_backspeed, 200);
1186                 }
1187                 else
1188                 {
1189                         Cvar_SetValueQuick (&cl_forwardspeed, 400);
1190                         Cvar_SetValueQuick (&cl_backspeed, 400);
1191                 }
1192         }
1193         else if (options_cursor == optnum++)
1194                 Cvar_SetValueQuick (&lookspring, !lookspring.integer);
1195         else if (options_cursor == optnum++)
1196                 Cvar_SetValueQuick (&lookstrafe, !lookstrafe.integer);
1197         else if (options_cursor == optnum++)
1198                 Cvar_SetValueQuick (&sensitivity, bound(1, sensitivity.value + dir * 0.5, 50));
1199         else if (options_cursor == optnum++)
1200                 Cvar_SetValueQuick (&freelook, !freelook.integer);
1201         else if (options_cursor == optnum++)
1202                 Cvar_SetValueQuick (&m_pitch, -m_pitch.value);
1203         else if (options_cursor == optnum++)
1204                 Cvar_SetValueQuick (&vid_mouse, !vid_mouse.integer);
1205 }
1206
1207 int optnum;
1208 int opty;
1209 int optcursor;
1210
1211 void M_Options_PrintCommand(char *s, int enabled)
1212 {
1213         if (opty >= 32)
1214         {
1215                 DrawQ_Fill(menu_x, menu_y + opty, 640, 8, optnum == optcursor ? (0.5 + 0.2 * sin(realtime * M_PI)) : 0, 0, 0, 0.5, 0);
1216                 M_ItemPrint(0, opty, s, enabled);
1217         }
1218         opty += 8;
1219         optnum++;
1220 }
1221
1222 void M_Options_PrintCheckbox(char *s, int enabled, int yes)
1223 {
1224         if (opty >= 32)
1225         {
1226                 DrawQ_Fill(menu_x, menu_y + opty, 640, 8, optnum == optcursor ? (0.5 + 0.2 * sin(realtime * M_PI)) : 0, 0, 0, 0.5, 0);
1227                 M_ItemPrint(0, opty, s, enabled);
1228                 M_DrawCheckbox(0 + strlen(s) * 8 + 8, opty, yes);
1229         }
1230         opty += 8;
1231         optnum++;
1232 }
1233
1234 void M_Options_PrintSlider(char *s, int enabled, float value, float minvalue, float maxvalue)
1235 {
1236         if (opty >= 32)
1237         {
1238                 DrawQ_Fill(menu_x, menu_y + opty, 640, 8, optnum == optcursor ? (0.5 + 0.2 * sin(realtime * M_PI)) : 0, 0, 0, 0.5, 0);
1239                 M_ItemPrint(0, opty, s, enabled);
1240                 M_DrawSlider(0 + strlen(s) * 8 + 8, opty, value, minvalue, maxvalue);
1241         }
1242         opty += 8;
1243         optnum++;
1244 }
1245
1246 void M_Options_Draw (void)
1247 {
1248         int visible;
1249         cachepic_t      *p;
1250
1251         M_Background(320, 240);
1252
1253         M_DrawPic(16, 4, "gfx/qplaque.lmp");
1254         p = Draw_CachePic("gfx/p_option.lmp");
1255         M_DrawPic((320-p->width)/2, 4, "gfx/p_option.lmp");
1256
1257         // LordHavoc: FIXME: overbright needs to be disabled in GAME_GOODVSBAD2 but combine should not be disabled
1258         // LordHavoc: perhaps it's time for Overbright Bits to die, and a r_lightmapintensity option to be added?
1259         optnum = 0;
1260         optcursor = options_cursor;
1261         visible = (vid.conheight - 32) / 8;
1262         opty = 32 - bound(0, optcursor - (visible >> 1), max(0, OPTIONS_ITEMS - visible)) * 8;
1263
1264         M_Options_PrintCommand( "Customize controls", true);
1265         M_Options_PrintCommand( "     Go to console", true);
1266         M_Options_PrintCommand( " Reset to defaults", true);
1267         M_Options_PrintCommand( "             Video", true);
1268         M_Options_PrintCommand( "           Effects", true);
1269         M_Options_PrintCommand( "     Color Control", true);
1270         M_Options_PrintSlider(  "  2D Screen Width ", true, vid_conwidth.value, 320, 2048);
1271         M_Options_PrintSlider(  "  2D Screen Height", true, vid_conheight.value, 240, 1536);
1272         M_Options_PrintSlider(  "     Console Speed", true, scr_conspeed.value, 0, 1000);
1273         M_Options_PrintSlider(  "     Console Alpha", true, scr_conalpha.value, 0, 1);
1274         M_Options_PrintSlider(  "Conback Brightness", true, scr_conbrightness.value, 0, 1);
1275         M_Options_PrintSlider(  "       Screen size", true, scr_viewsize.value, 30, 120);
1276         M_Options_PrintCheckbox("  JPEG screenshots", jpeg_dll != NULL, scr_screenshot_jpeg.integer);
1277         M_Options_PrintCheckbox("               Sky", true, r_sky.integer);
1278         M_Options_PrintSlider(  "   Overbright Bits", true, v_overbrightbits.value, 0, 4);
1279         M_Options_PrintCheckbox("   Texture Combine", true, gl_combine.integer);
1280         M_Options_PrintCheckbox("         Dithering", true, gl_dither.integer);
1281         M_Options_PrintCheckbox("Delay gfx (faster)", true, gl_delayfinish.integer);
1282         M_Options_PrintSlider(  "        Game Speed", sv.active, slowmo.value, 0, 5);
1283         M_Options_PrintSlider(  "   CD Music Volume", cdaudioinitialized, bgmvolume.value, 0, 1);
1284         M_Options_PrintSlider(  "      Sound Volume", snd_initialized, volume.value, 0, 1);
1285         M_Options_PrintSlider(gamemode == GAME_GOODVSBAD2 ? "      Music Volume" : "    Ambient Volume", snd_initialized, snd_staticvolume.value, 0, 1);
1286         M_Options_PrintSlider(  "         Crosshair", true, crosshair.value, 0, 5);
1287         M_Options_PrintSlider(  "    Crosshair Size", true, crosshair_size.value, 1, 5);
1288         M_Options_PrintCheckbox("  Static Crosshair", true, crosshair_static.integer);
1289         M_Options_PrintCheckbox("    Show Framerate", true, showfps.integer);
1290         M_Options_PrintCheckbox("        Always Run", true, cl_forwardspeed.value > 200);
1291         M_Options_PrintCheckbox("        Lookspring", true, lookspring.integer);
1292         M_Options_PrintCheckbox("        Lookstrafe", true, lookstrafe.integer);
1293         M_Options_PrintSlider(  "       Mouse Speed", true, sensitivity.value, 1, 50);
1294         M_Options_PrintCheckbox("        Mouse Look", true, freelook.integer);
1295         M_Options_PrintCheckbox("      Invert Mouse", true, m_pitch.value < 0);
1296         M_Options_PrintCheckbox("         Use Mouse", true, vid_mouse.integer);
1297 }
1298
1299
1300 void M_Options_Key (int k)
1301 {
1302         switch (k)
1303         {
1304         case K_ESCAPE:
1305                 M_Menu_Main_f ();
1306                 break;
1307
1308         case K_ENTER:
1309                 m_entersound = true;
1310                 switch (options_cursor)
1311                 {
1312                 case 0:
1313                         M_Menu_Keys_f ();
1314                         break;
1315                 case 1:
1316                         m_state = m_none;
1317                         key_dest = key_game;
1318                         Con_ToggleConsole_f ();
1319                         break;
1320                 case 2:
1321                         Cbuf_AddText ("exec default.cfg\n");
1322                         break;
1323                 case 3:
1324                         M_Menu_Video_f ();
1325                         break;
1326                 case 4:
1327                         M_Menu_Options_Effects_f ();
1328                         break;
1329                 case 5:
1330                         M_Menu_Options_ColorControl_f ();
1331                         break;
1332                 default:
1333                         M_Menu_Options_AdjustSliders (1);
1334                         break;
1335                 }
1336                 return;
1337
1338         case K_UPARROW:
1339                 S_LocalSound ("misc/menu1.wav");
1340                 options_cursor--;
1341                 if (options_cursor < 0)
1342                         options_cursor = OPTIONS_ITEMS-1;
1343                 break;
1344
1345         case K_DOWNARROW:
1346                 S_LocalSound ("misc/menu1.wav");
1347                 options_cursor++;
1348                 if (options_cursor >= OPTIONS_ITEMS)
1349                         options_cursor = 0;
1350                 break;
1351
1352         case K_LEFTARROW:
1353                 M_Menu_Options_AdjustSliders (-1);
1354                 break;
1355
1356         case K_RIGHTARROW:
1357                 M_Menu_Options_AdjustSliders (1);
1358                 break;
1359         }
1360 }
1361
1362 #define OPTIONS_EFFECTS_ITEMS   20
1363
1364 int options_effects_cursor;
1365
1366 void M_Menu_Options_Effects_f (void)
1367 {
1368         key_dest = key_menu;
1369         m_state = m_options_effects;
1370         m_entersound = true;
1371 }
1372
1373
1374 extern cvar_t r_detailtextures;
1375 extern cvar_t cl_particles;
1376 extern cvar_t cl_explosions;
1377 extern cvar_t cl_stainmaps;
1378 extern cvar_t cl_decals;
1379 extern cvar_t r_explosionclip;
1380 extern cvar_t r_dlightmap;
1381 extern cvar_t r_modellights;
1382 extern cvar_t r_coronas;
1383 extern cvar_t gl_flashblend;
1384 extern cvar_t cl_particles_quality;
1385 extern cvar_t cl_particles_bulletimpacts;
1386 extern cvar_t cl_particles_smoke;
1387 extern cvar_t cl_particles_sparks;
1388 extern cvar_t cl_particles_bubbles;
1389 extern cvar_t cl_particles_blood;
1390 extern cvar_t cl_particles_blood_alpha;
1391
1392 void M_Menu_Options_Effects_AdjustSliders (int dir)
1393 {
1394         int optnum;
1395         S_LocalSound ("misc/menu3.wav");
1396
1397         optnum = 0;
1398         if (options_effects_cursor == optnum++)
1399                 Cvar_SetValueQuick (&r_modellights, bound(0, r_modellights.value + dir, 8));
1400         else if (options_effects_cursor == optnum++)
1401                 Cvar_SetValueQuick (&r_dlightmap, !r_dlightmap.integer);
1402         else if (options_effects_cursor == optnum++)
1403                 Cvar_SetValueQuick (&r_coronas, !r_coronas.integer);
1404         else if (options_effects_cursor == optnum++)
1405                 Cvar_SetValueQuick (&gl_flashblend, !gl_flashblend.integer);
1406         else if (options_effects_cursor == optnum++)
1407                 Cvar_SetValueQuick (&cl_particles, !cl_particles.integer);
1408         else if (options_effects_cursor == optnum++)
1409                 Cvar_SetValueQuick (&cl_particles_quality, bound(1, cl_particles_quality.value + dir * 0.5, 4));
1410         else if (options_effects_cursor == optnum++)
1411                 Cvar_SetValueQuick (&cl_explosions, !cl_explosions.integer);
1412         else if (options_effects_cursor == optnum++)
1413                 Cvar_SetValueQuick (&r_explosionclip, !r_explosionclip.integer);
1414         else if (options_effects_cursor == optnum++)
1415                 Cvar_SetValueQuick (&cl_stainmaps, !cl_stainmaps.integer);
1416         else if (options_effects_cursor == optnum++)
1417                 Cvar_SetValueQuick (&cl_decals, !cl_decals.integer);
1418         else if (options_effects_cursor == optnum++)
1419                 Cvar_SetValueQuick (&r_detailtextures, !r_detailtextures.integer);
1420         else if (options_effects_cursor == optnum++)
1421                 Cvar_SetValueQuick (&cl_particles_bulletimpacts, !cl_particles_bulletimpacts.integer);
1422         else if (options_effects_cursor == optnum++)
1423                 Cvar_SetValueQuick (&cl_particles_smoke, !cl_particles_smoke.integer);
1424         else if (options_effects_cursor == optnum++)
1425                 Cvar_SetValueQuick (&cl_particles_sparks, !cl_particles_sparks.integer);
1426         else if (options_effects_cursor == optnum++)
1427                 Cvar_SetValueQuick (&cl_particles_bubbles, !cl_particles_bubbles.integer);
1428         else if (options_effects_cursor == optnum++)
1429                 Cvar_SetValueQuick (&cl_particles_blood, !cl_particles_blood.integer);
1430         else if (options_effects_cursor == optnum++)
1431                 Cvar_SetValueQuick (&cl_particles_blood_alpha, bound(0.2, cl_particles_blood_alpha.value + dir * 0.1, 1));
1432         else if (options_effects_cursor == optnum++)
1433                 Cvar_SetValueQuick (&r_lerpmodels, !r_lerpmodels.integer);
1434         else if (options_effects_cursor == optnum++)
1435                 Cvar_SetValueQuick (&r_lerpsprites, !r_lerpsprites.integer);
1436         else if (options_effects_cursor == optnum++)
1437                 Cvar_SetValueQuick (&r_waterscroll, bound(0, r_waterscroll.value + dir * 0.5, 10));
1438 }
1439
1440 void M_Options_Effects_Draw (void)
1441 {
1442         int visible;
1443         cachepic_t      *p;
1444
1445         M_Background(320, 200);
1446
1447         M_DrawPic(16, 4, "gfx/qplaque.lmp");
1448         p = Draw_CachePic("gfx/p_option.lmp");
1449         M_DrawPic((320-p->width)/2, 4, "gfx/p_option.lmp");
1450
1451         optcursor = options_effects_cursor;
1452         optnum = 0;
1453         visible = (vid.conheight - 32) / 8;
1454         opty = 32 - bound(0, optcursor - (visible >> 1), max(0, OPTIONS_EFFECTS_ITEMS - visible)) * 8;
1455
1456         M_Options_PrintSlider(  "      Lights Per Model", true, r_modellights.value, 0, 8);
1457         M_Options_PrintCheckbox(" Fast Dynamic Lighting", true, !r_dlightmap.integer);
1458         M_Options_PrintCheckbox("               Coronas", true, r_coronas.integer);
1459         M_Options_PrintCheckbox("      Use Only Coronas", true, gl_flashblend.integer);
1460         M_Options_PrintCheckbox("             Particles", true, cl_particles.integer);
1461         M_Options_PrintSlider(  "     Particles Quality", true, cl_particles_quality.value, 1, 4);
1462         M_Options_PrintCheckbox("            Explosions", true, cl_explosions.integer);
1463         M_Options_PrintCheckbox("    Explosion Clipping", true, r_explosionclip.integer);
1464         M_Options_PrintCheckbox("             Stainmaps", true, cl_stainmaps.integer);
1465         M_Options_PrintCheckbox("                Decals", true, cl_decals.integer);
1466         M_Options_PrintCheckbox("      Detail Texturing", true, r_detailtextures.integer);
1467         M_Options_PrintCheckbox("        Bullet Impacts", true, cl_particles_bulletimpacts.integer);
1468         M_Options_PrintCheckbox("                 Smoke", true, cl_particles_smoke.integer);
1469         M_Options_PrintCheckbox("                Sparks", true, cl_particles_sparks.integer);
1470         M_Options_PrintCheckbox("               Bubbles", true, cl_particles_bubbles.integer);
1471         M_Options_PrintCheckbox("                 Blood", true, cl_particles_blood.integer);
1472         M_Options_PrintSlider(  "         Blood Opacity", true, cl_particles_blood_alpha.value, 0.2, 1);
1473         M_Options_PrintCheckbox("   Model Interpolation", true, r_lerpmodels.integer);
1474         M_Options_PrintCheckbox("  Sprite Interpolation", true, r_lerpsprites.integer);
1475         M_Options_PrintSlider(  "        Water Movement", true, r_waterscroll.value, 0, 10);
1476 }
1477
1478
1479 void M_Options_Effects_Key (int k)
1480 {
1481         switch (k)
1482         {
1483         case K_ESCAPE:
1484                 M_Menu_Options_f ();
1485                 break;
1486
1487         case K_ENTER:
1488                 M_Menu_Options_Effects_AdjustSliders (1);
1489                 break;
1490
1491         case K_UPARROW:
1492                 S_LocalSound ("misc/menu1.wav");
1493                 options_effects_cursor--;
1494                 if (options_effects_cursor < 0)
1495                         options_effects_cursor = OPTIONS_EFFECTS_ITEMS-1;
1496                 break;
1497
1498         case K_DOWNARROW:
1499                 S_LocalSound ("misc/menu1.wav");
1500                 options_effects_cursor++;
1501                 if (options_effects_cursor >= OPTIONS_EFFECTS_ITEMS)
1502                         options_effects_cursor = 0;
1503                 break;
1504
1505         case K_LEFTARROW:
1506                 M_Menu_Options_Effects_AdjustSliders (-1);
1507                 break;
1508
1509         case K_RIGHTARROW:
1510                 M_Menu_Options_Effects_AdjustSliders (1);
1511                 break;
1512         }
1513 }
1514
1515
1516
1517
1518
1519 #define OPTIONS_COLORCONTROL_ITEMS      18
1520
1521 int             options_colorcontrol_cursor;
1522
1523 // intensity value to match up to 50% dither to 'correct' quake
1524 cvar_t menu_options_colorcontrol_correctionvalue = {0, "menu_options_colorcontrol_correctionvalue", "0.25"};
1525
1526 void M_Menu_Options_ColorControl_f (void)
1527 {
1528         key_dest = key_menu;
1529         m_state = m_options_colorcontrol;
1530         m_entersound = true;
1531 }
1532
1533
1534 void M_Menu_Options_ColorControl_AdjustSliders (int dir)
1535 {
1536         int optnum;
1537         float f;
1538         S_LocalSound ("misc/menu3.wav");
1539
1540         optnum = 1;
1541         if (options_colorcontrol_cursor == optnum++)
1542                 Cvar_SetValueQuick (&v_hwgamma, !v_hwgamma.integer);
1543         else if (options_colorcontrol_cursor == optnum++)
1544         {
1545                 Cvar_SetValueQuick (&v_color_enable, 0);
1546                 Cvar_SetValueQuick (&v_gamma, bound(1, v_gamma.value + dir * 0.125, 5));
1547         }
1548         else if (options_colorcontrol_cursor == optnum++)
1549         {
1550                 Cvar_SetValueQuick (&v_color_enable, 0);
1551                 Cvar_SetValueQuick (&v_contrast, bound(1, v_contrast.value + dir * 0.125, 5));
1552         }
1553         else if (options_colorcontrol_cursor == optnum++)
1554         {
1555                 Cvar_SetValueQuick (&v_color_enable, 0);
1556                 Cvar_SetValueQuick (&v_brightness, bound(0, v_brightness.value + dir * 0.05, 0.8));
1557         }
1558         else if (options_colorcontrol_cursor == optnum++)
1559         {
1560                 Cvar_SetValueQuick (&v_color_enable, !v_color_enable.integer);
1561         }
1562         else if (options_colorcontrol_cursor == optnum++)
1563         {
1564                 Cvar_SetValueQuick (&v_color_enable, 1);
1565                 Cvar_SetValueQuick (&v_color_black_r, bound(0, v_color_black_r.value + dir * 0.0125, 0.8));
1566         }
1567         else if (options_colorcontrol_cursor == optnum++)
1568         {
1569                 Cvar_SetValueQuick (&v_color_enable, 1);
1570                 Cvar_SetValueQuick (&v_color_black_g, bound(0, v_color_black_g.value + dir * 0.0125, 0.8));
1571         }
1572         else if (options_colorcontrol_cursor == optnum++)
1573         {
1574                 Cvar_SetValueQuick (&v_color_enable, 1);
1575                 Cvar_SetValueQuick (&v_color_black_b, bound(0, v_color_black_b.value + dir * 0.0125, 0.8));
1576         }
1577         else if (options_colorcontrol_cursor == optnum++)
1578         {
1579                 Cvar_SetValueQuick (&v_color_enable, 1);
1580                 f = bound(0, (v_color_black_r.value + v_color_black_g.value + v_color_black_b.value) / 3 + dir * 0.0125, 0.8);
1581                 Cvar_SetValueQuick (&v_color_black_r, f);
1582                 Cvar_SetValueQuick (&v_color_black_g, f);
1583                 Cvar_SetValueQuick (&v_color_black_b, f);
1584         }
1585         else if (options_colorcontrol_cursor == optnum++)
1586         {
1587                 Cvar_SetValueQuick (&v_color_enable, 1);
1588                 Cvar_SetValueQuick (&v_color_grey_r, bound(0, v_color_grey_r.value + dir * 0.0125, 0.95));
1589         }
1590         else if (options_colorcontrol_cursor == optnum++)
1591         {
1592                 Cvar_SetValueQuick (&v_color_enable, 1);
1593                 Cvar_SetValueQuick (&v_color_grey_g, bound(0, v_color_grey_g.value + dir * 0.0125, 0.95));
1594         }
1595         else if (options_colorcontrol_cursor == optnum++)
1596         {
1597                 Cvar_SetValueQuick (&v_color_enable, 1);
1598                 Cvar_SetValueQuick (&v_color_grey_b, bound(0, v_color_grey_b.value + dir * 0.0125, 0.95));
1599         }
1600         else if (options_colorcontrol_cursor == optnum++)
1601         {
1602                 Cvar_SetValueQuick (&v_color_enable, 1);
1603                 f = bound(0, (v_color_grey_r.value + v_color_grey_g.value + v_color_grey_b.value) / 3 + dir * 0.0125, 0.95);
1604                 Cvar_SetValueQuick (&v_color_grey_r, f);
1605                 Cvar_SetValueQuick (&v_color_grey_g, f);
1606                 Cvar_SetValueQuick (&v_color_grey_b, f);
1607         }
1608         else if (options_colorcontrol_cursor == optnum++)
1609         {
1610                 Cvar_SetValueQuick (&v_color_enable, 1);
1611                 Cvar_SetValueQuick (&v_color_white_r, bound(1, v_color_white_r.value + dir * 0.125, 5));
1612         }
1613         else if (options_colorcontrol_cursor == optnum++)
1614         {
1615                 Cvar_SetValueQuick (&v_color_enable, 1);
1616                 Cvar_SetValueQuick (&v_color_white_g, bound(1, v_color_white_g.value + dir * 0.125, 5));
1617         }
1618         else if (options_colorcontrol_cursor == optnum++)
1619         {
1620                 Cvar_SetValueQuick (&v_color_enable, 1);
1621                 Cvar_SetValueQuick (&v_color_white_b, bound(1, v_color_white_b.value + dir * 0.125, 5));
1622         }
1623         else if (options_colorcontrol_cursor == optnum++)
1624         {
1625                 Cvar_SetValueQuick (&v_color_enable, 1);
1626                 f = bound(1, (v_color_white_r.value + v_color_white_g.value + v_color_white_b.value) / 3 + dir * 0.125, 5);
1627                 Cvar_SetValueQuick (&v_color_white_r, f);
1628                 Cvar_SetValueQuick (&v_color_white_g, f);
1629                 Cvar_SetValueQuick (&v_color_white_b, f);
1630         }
1631 }
1632
1633 void M_Options_ColorControl_Draw (void)
1634 {
1635         int visible;
1636         float x, c, s, t, u, v;
1637         cachepic_t      *p;
1638
1639         M_Background(320, 256);
1640
1641         M_DrawPic(16, 4, "gfx/qplaque.lmp");
1642         p = Draw_CachePic("gfx/p_option.lmp");
1643         M_DrawPic((320-p->width)/2, 4, "gfx/p_option.lmp");
1644
1645         optcursor = options_colorcontrol_cursor;
1646         optnum = 0;
1647         visible = (vid.conheight - 32) / 8;
1648         opty = 32 - bound(0, optcursor - (visible >> 1), max(0, OPTIONS_COLORCONTROL_ITEMS - visible)) * 8;
1649
1650         M_Options_PrintCommand( "     Reset to defaults", true);
1651         M_Options_PrintCheckbox("Hardware Gamma Control", vid_hardwaregammasupported, v_hwgamma.integer);
1652         M_Options_PrintSlider(  "                 Gamma", !v_color_enable.integer && vid_hardwaregammasupported && v_hwgamma.integer, v_gamma.value, 1, 5);
1653         M_Options_PrintSlider(  "              Contrast", !v_color_enable.integer, v_contrast.value, 1, 5);
1654         M_Options_PrintSlider(  "            Brightness", !v_color_enable.integer, v_brightness.value, 0, 0.8);
1655         M_Options_PrintCheckbox("  Color Level Controls", true, v_color_enable.integer);
1656         M_Options_PrintSlider(  "          Black: Red  ", v_color_enable.integer, v_color_black_r.value, 0, 0.8);
1657         M_Options_PrintSlider(  "          Black: Green", v_color_enable.integer, v_color_black_g.value, 0, 0.8);
1658         M_Options_PrintSlider(  "          Black: Blue ", v_color_enable.integer, v_color_black_b.value, 0, 0.8);
1659         M_Options_PrintSlider(  "          Black: Grey ", v_color_enable.integer, (v_color_black_r.value + v_color_black_g.value + v_color_black_b.value) / 3, 0, 0.8);
1660         M_Options_PrintSlider(  "           Grey: Red  ", v_color_enable.integer && vid_hardwaregammasupported && v_hwgamma.integer, v_color_grey_r.value, 0, 0.95);
1661         M_Options_PrintSlider(  "           Grey: Green", v_color_enable.integer && vid_hardwaregammasupported && v_hwgamma.integer, v_color_grey_g.value, 0, 0.95);
1662         M_Options_PrintSlider(  "           Grey: Blue ", v_color_enable.integer && vid_hardwaregammasupported && v_hwgamma.integer, v_color_grey_b.value, 0, 0.95);
1663         M_Options_PrintSlider(  "           Grey: Grey ", v_color_enable.integer && vid_hardwaregammasupported && v_hwgamma.integer, (v_color_grey_r.value + v_color_grey_g.value + v_color_grey_b.value) / 3, 0, 0.95);
1664         M_Options_PrintSlider(  "          White: Red  ", v_color_enable.integer, v_color_white_r.value, 1, 5);
1665         M_Options_PrintSlider(  "          White: Green", v_color_enable.integer, v_color_white_g.value, 1, 5);
1666         M_Options_PrintSlider(  "          White: Blue ", v_color_enable.integer, v_color_white_b.value, 1, 5);
1667         M_Options_PrintSlider(  "          White: Grey ", v_color_enable.integer, (v_color_white_r.value + v_color_white_g.value + v_color_white_b.value) / 3, 1, 5);
1668
1669         opty += 4;
1670         DrawQ_Fill(menu_x, menu_y + opty, 320, 4 + 64 + 8 + 64 + 4, 0, 0, 0, 1, 0);opty += 4;
1671         s = (float) 312 / 2 * vid.realwidth / vid.conwidth;
1672         t = (float) 4 / 2 * vid.realheight / vid.conheight;
1673         DrawQ_SuperPic(menu_x + 4, menu_y + opty, "gfx/colorcontrol/ditherpattern.tga", 312, 4, 0,0, 1,0,0,1, s,0, 1,0,0,1, 0,t, 1,0,0,1, s,t, 1,0,0,1, 0);opty += 4;
1674         DrawQ_SuperPic(menu_x + 4, menu_y + opty, NULL                                , 312, 4, 0,0, 0,0,0,1, 1,0, 1,0,0,1, 0,1, 0,0,0,1, 1,1, 1,0,0,1, 0);opty += 4;
1675         DrawQ_SuperPic(menu_x + 4, menu_y + opty, "gfx/colorcontrol/ditherpattern.tga", 312, 4, 0,0, 0,1,0,1, s,0, 0,1,0,1, 0,t, 0,1,0,1, s,t, 0,1,0,1, 0);opty += 4;
1676         DrawQ_SuperPic(menu_x + 4, menu_y + opty, NULL                                , 312, 4, 0,0, 0,0,0,1, 1,0, 0,1,0,1, 0,1, 0,0,0,1, 1,1, 0,1,0,1, 0);opty += 4;
1677         DrawQ_SuperPic(menu_x + 4, menu_y + opty, "gfx/colorcontrol/ditherpattern.tga", 312, 4, 0,0, 0,0,1,1, s,0, 0,0,1,1, 0,t, 0,0,1,1, s,t, 0,0,1,1, 0);opty += 4;
1678         DrawQ_SuperPic(menu_x + 4, menu_y + opty, NULL                                , 312, 4, 0,0, 0,0,0,1, 1,0, 0,0,1,1, 0,1, 0,0,0,1, 1,1, 0,0,1,1, 0);opty += 4;
1679         DrawQ_SuperPic(menu_x + 4, menu_y + opty, "gfx/colorcontrol/ditherpattern.tga", 312, 4, 0,0, 1,1,1,1, s,0, 1,1,1,1, 0,t, 1,1,1,1, s,t, 1,1,1,1, 0);opty += 4;
1680         DrawQ_SuperPic(menu_x + 4, menu_y + opty, NULL                                , 312, 4, 0,0, 0,0,0,1, 1,0, 1,1,1,1, 0,1, 0,0,0,1, 1,1, 1,1,1,1, 0);opty += 4;
1681
1682         c = menu_options_colorcontrol_correctionvalue.value; // intensity value that should be matched up to a 50% dither to 'correct' quake
1683         s = (float) 48 / 2 * vid.realwidth / vid.conwidth;
1684         t = (float) 48 / 2 * vid.realheight / vid.conheight;
1685         u = s * 0.5;
1686         v = t * 0.5;
1687         opty += 8;
1688         x = 4;
1689         DrawQ_Fill(menu_x + x, menu_y + opty, 64, 48, c, 0, 0, 1, 0);
1690         DrawQ_SuperPic(menu_x + x + 16, menu_y + opty + 16, "gfx/colorcontrol/ditherpattern.tga", 16, 16, 0,0, 1,0,0,1, s,0, 1,0,0,1, 0,t, 1,0,0,1, s,t, 1,0,0,1, 0);
1691         DrawQ_SuperPic(menu_x + x + 32, menu_y + opty + 16, "gfx/colorcontrol/ditherpattern.tga", 16, 16, 0,0, 1,0,0,1, u,0, 1,0,0,1, 0,v, 1,0,0,1, u,v, 1,0,0,1, 0);
1692         x += 80;
1693         DrawQ_Fill(menu_x + x, menu_y + opty, 64, 48, 0, c, 0, 1, 0);
1694         DrawQ_SuperPic(menu_x + x + 16, menu_y + opty + 16, "gfx/colorcontrol/ditherpattern.tga", 16, 16, 0,0, 0,1,0,1, s,0, 0,1,0,1, 0,t, 0,1,0,1, s,t, 0,1,0,1, 0);
1695         DrawQ_SuperPic(menu_x + x + 32, menu_y + opty + 16, "gfx/colorcontrol/ditherpattern.tga", 16, 16, 0,0, 0,1,0,1, u,0, 0,1,0,1, 0,v, 0,1,0,1, u,v, 0,1,0,1, 0);
1696         x += 80;
1697         DrawQ_Fill(menu_x + x, menu_y + opty, 64, 48, 0, 0, c, 1, 0);
1698         DrawQ_SuperPic(menu_x + x + 16, menu_y + opty + 16, "gfx/colorcontrol/ditherpattern.tga", 16, 16, 0,0, 0,0,1,1, s,0, 0,0,1,1, 0,t, 0,0,1,1, s,t, 0,0,1,1, 0);
1699         DrawQ_SuperPic(menu_x + x + 32, menu_y + opty + 16, "gfx/colorcontrol/ditherpattern.tga", 16, 16, 0,0, 0,0,1,1, u,0, 0,0,1,1, 0,v, 0,0,1,1, u,v, 0,0,1,1, 0);
1700         x += 80;
1701         DrawQ_Fill(menu_x + x, menu_y + opty, 64, 48, c, c, c, 1, 0);
1702         DrawQ_SuperPic(menu_x + x + 16, menu_y + opty + 16, "gfx/colorcontrol/ditherpattern.tga", 16, 16, 0,0, 1,1,1,1, s,0, 1,1,1,1, 0,t, 1,1,1,1, s,t, 1,1,1,1, 0);
1703         DrawQ_SuperPic(menu_x + x + 32, menu_y + opty + 16, "gfx/colorcontrol/ditherpattern.tga", 16, 16, 0,0, 1,1,1,1, u,0, 1,1,1,1, 0,v, 1,1,1,1, u,v, 1,1,1,1, 0);
1704 }
1705
1706
1707 void M_Options_ColorControl_Key (int k)
1708 {
1709         switch (k)
1710         {
1711         case K_ESCAPE:
1712                 M_Menu_Main_f ();
1713                 break;
1714
1715         case K_ENTER:
1716                 m_entersound = true;
1717                 switch (options_colorcontrol_cursor)
1718                 {
1719                 case 0:
1720                         Cvar_SetValueQuick(&v_hwgamma, 1);
1721                         Cvar_SetValueQuick(&v_gamma, 1);
1722                         Cvar_SetValueQuick(&v_contrast, 1);
1723                         Cvar_SetValueQuick(&v_brightness, 0);
1724                         Cvar_SetValueQuick(&v_color_enable, 0);
1725                         Cvar_SetValueQuick(&v_color_black_r, 0);
1726                         Cvar_SetValueQuick(&v_color_black_g, 0);
1727                         Cvar_SetValueQuick(&v_color_black_b, 0);
1728                         Cvar_SetValueQuick(&v_color_grey_r, 0);
1729                         Cvar_SetValueQuick(&v_color_grey_g, 0);
1730                         Cvar_SetValueQuick(&v_color_grey_b, 0);
1731                         Cvar_SetValueQuick(&v_color_white_r, 1);
1732                         Cvar_SetValueQuick(&v_color_white_g, 1);
1733                         Cvar_SetValueQuick(&v_color_white_b, 1);
1734                         Cbuf_AddText ("exec default.cfg\n");
1735                         break;
1736                 default:
1737                         M_Menu_Options_ColorControl_AdjustSliders (1);
1738                         break;
1739                 }
1740                 return;
1741
1742         case K_UPARROW:
1743                 S_LocalSound ("misc/menu1.wav");
1744                 options_colorcontrol_cursor--;
1745                 if (options_colorcontrol_cursor < 0)
1746                         options_colorcontrol_cursor = OPTIONS_COLORCONTROL_ITEMS-1;
1747                 break;
1748
1749         case K_DOWNARROW:
1750                 S_LocalSound ("misc/menu1.wav");
1751                 options_colorcontrol_cursor++;
1752                 if (options_colorcontrol_cursor >= OPTIONS_COLORCONTROL_ITEMS)
1753                         options_colorcontrol_cursor = 0;
1754                 break;
1755
1756         case K_LEFTARROW:
1757                 M_Menu_Options_ColorControl_AdjustSliders (-1);
1758                 break;
1759
1760         case K_RIGHTARROW:
1761                 M_Menu_Options_ColorControl_AdjustSliders (1);
1762                 break;
1763         }
1764 }
1765
1766
1767 //=============================================================================
1768 /* KEYS MENU */
1769
1770 char *quakebindnames[][2] =
1771 {
1772 {"+attack",             "attack"},
1773 {"impulse 10",          "next weapon"},
1774 {"impulse 12",          "previous weapon"},
1775 {"+jump",                       "jump / swim up"},
1776 {"+forward",            "walk forward"},
1777 {"+back",                       "backpedal"},
1778 {"+left",                       "turn left"},
1779 {"+right",                      "turn right"},
1780 {"+speed",                      "run"},
1781 {"+moveleft",           "step left"},
1782 {"+moveright",          "step right"},
1783 {"+strafe",             "sidestep"},
1784 {"+lookup",             "look up"},
1785 {"+lookdown",           "look down"},
1786 {"centerview",          "center view"},
1787 {"+mlook",                      "mouse look"},
1788 {"+klook",                      "keyboard look"},
1789 {"+moveup",                     "swim up"},
1790 {"+movedown",           "swim down"}
1791 };
1792
1793 char *transfusionbindnames[][2] =
1794 {
1795 {"",                            "Movement"},            // Movement commands
1796 {"+forward",            "walk forward"},
1797 {"+back",                       "backpedal"},
1798 {"+left",                       "turn left"},
1799 {"+right",                      "turn right"},
1800 {"+moveleft",           "step left"},
1801 {"+moveright",          "step right"},
1802 {"+jump",                       "jump / swim up"},
1803 {"+movedown",           "swim down"},
1804 {"",                            "Combat"},                      // Combat commands
1805 {"impulse 1",           "Pitch Fork"},
1806 {"impulse 2",           "Flare Gun"},
1807 {"impulse 3",           "Shotgun"},
1808 {"impulse 4",           "Machine Gun"},
1809 {"impulse 5",           "Incinerator"},
1810 {"impulse 6",           "Bombs (TNT)"},
1811 {"impulse 35",          "Proximity Bomb"},
1812 {"impulse 36",          "Remote Detonator"},
1813 {"impulse 7",           "Aerosol Can"},
1814 {"impulse 8",           "Tesla Cannon"},
1815 {"impulse 9",           "Life Leech"},
1816 {"impulse 10",          "Voodoo Doll"},
1817 {"impulse 21",          "next weapon"},
1818 {"impulse 22",          "previous weapon"},
1819 {"+attack",             "attack"},
1820 {"+button3",            "altfire"},
1821 {"",                            "Inventory"},           // Inventory commands
1822 {"impulse 40",          "Dr.'s Bag"},
1823 {"impulse 41",          "Crystal Ball"},
1824 {"impulse 42",          "Beast Vision"},
1825 {"impulse 43",          "Jump Boots"},
1826 {"impulse 23",          "next item"},
1827 {"impulse 24",          "previous item"},
1828 {"impulse 25",          "use item"},
1829 {"",                            "Misc"},                        // Misc commands
1830 {"+button4",            "use"},
1831 {"impulse 50",          "add bot (red)"},
1832 {"impulse 51",          "add bot (blue)"},
1833 {"impulse 52",          "kick a bot"},
1834 {"impulse 26",          "next armor type"},
1835 {"impulse 27",          "identify player"},
1836 {"impulse 55",          "voting menu"},
1837 {"impulse 56",          "observer mode"}
1838 };
1839
1840 char *goodvsbad2bindnames[][2] =
1841 {
1842 {"impulse 69",          "Power 1"},
1843 {"impulse 70",          "Power 2"},
1844 {"impulse 71",          "Power 3"},
1845 {"+jump",                       "jump / swim up"},
1846 {"+forward",            "walk forward"},
1847 {"+back",                       "backpedal"},
1848 {"+left",                       "turn left"},
1849 {"+right",                      "turn right"},
1850 {"+speed",                      "run"},
1851 {"+moveleft",           "step left"},
1852 {"+moveright",          "step right"},
1853 {"+strafe",             "sidestep"},
1854 {"+lookup",             "look up"},
1855 {"+lookdown",           "look down"},
1856 {"centerview",          "center view"},
1857 {"+mlook",                      "mouse look"},
1858 {"kill",                        "kill yourself"},
1859 {"+moveup",                     "swim up"},
1860 {"+movedown",           "swim down"}
1861 };
1862
1863 int numcommands;
1864 char *(*bindnames)[2];
1865
1866 /*
1867 typedef struct binditem_s
1868 {
1869         char *command, *description;
1870         struct binditem_s *next;
1871 }
1872 binditem_t;
1873
1874 typedef struct bindcategory_s
1875 {
1876         char *name;
1877         binditem_t *binds;
1878         struct bindcategory_s *next;
1879 }
1880 bindcategory_t;
1881
1882 bindcategory_t *bindcategories = NULL;
1883
1884 void M_ClearBinds (void)
1885 {
1886         for (c = bindcategories;c;c = cnext)
1887         {
1888                 cnext = c->next;
1889                 for (b = c->binds;b;b = bnext)
1890                 {
1891                         bnext = b->next;
1892                         Z_Free(b);
1893                 }
1894                 Z_Free(c);
1895         }
1896         bindcategories = NULL;
1897 }
1898
1899 void M_AddBindToCategory(bindcategory_t *c, char *command, char *description)
1900 {
1901         for (b = &c->binds;*b;*b = &(*b)->next);
1902         *b = Z_Alloc(sizeof(binditem_t) + strlen(command) + 1 + strlen(description) + 1);
1903         *b->command = (char *)((*b) + 1);
1904         *b->description = *b->command + strlen(command) + 1;
1905         strcpy(*b->command, command);
1906         strcpy(*b->description, description);
1907 }
1908
1909 void M_AddBind (char *category, char *command, char *description)
1910 {
1911         for (c = &bindcategories;*c;c = &(*c)->next)
1912         {
1913                 if (!strcmp(category, (*c)->name))
1914                 {
1915                         M_AddBindToCategory(*c, command, description);
1916                         return;
1917                 }
1918         }
1919         *c = Z_Alloc(sizeof(bindcategory_t));
1920         M_AddBindToCategory(*c, command, description);
1921 }
1922
1923 void M_DefaultBinds (void)
1924 {
1925         M_ClearBinds();
1926         M_AddBind("movement", "+jump", "jump / swim up");
1927         M_AddBind("movement", "+forward", "walk forward");
1928         M_AddBind("movement", "+back", "backpedal");
1929         M_AddBind("movement", "+left", "turn left");
1930         M_AddBind("movement", "+right", "turn right");
1931         M_AddBind("movement", "+speed", "run");
1932         M_AddBind("movement", "+moveleft", "step left");
1933         M_AddBind("movement", "+moveright", "step right");
1934         M_AddBind("movement", "+strafe", "sidestep");
1935         M_AddBind("movement", "+lookup", "look up");
1936         M_AddBind("movement", "+lookdown", "look down");
1937         M_AddBind("movement", "centerview", "center view");
1938         M_AddBind("movement", "+mlook", "mouse look");
1939         M_AddBind("movement", "+klook", "keyboard look");
1940         M_AddBind("movement", "+moveup", "swim up");
1941         M_AddBind("movement", "+movedown", "swim down");
1942         M_AddBind("weapons", "+attack", "attack");
1943         M_AddBind("weapons", "impulse 10", "next weapon");
1944         M_AddBind("weapons", "impulse 12", "previous weapon");
1945         M_AddBind("weapons", "impulse 1", "select weapon 1 (axe)");
1946         M_AddBind("weapons", "impulse 2", "select weapon 2 (shotgun)");
1947         M_AddBind("weapons", "impulse 3", "select weapon 3 (super )");
1948         M_AddBind("weapons", "impulse 4", "select weapon 4 (nailgun)");
1949         M_AddBind("weapons", "impulse 5", "select weapon 5 (super nailgun)");
1950         M_AddBind("weapons", "impulse 6", "select weapon 6 (grenade launcher)");
1951         M_AddBind("weapons", "impulse 7", "select weapon 7 (rocket launcher)");
1952         M_AddBind("weapons", "impulse 8", "select weapon 8 (lightning gun)");
1953 }
1954 */
1955
1956
1957 int             keys_cursor;
1958 int             bind_grab;
1959
1960 void M_Menu_Keys_f (void)
1961 {
1962         key_dest = key_menu;
1963         m_state = m_keys;
1964         m_entersound = true;
1965 }
1966
1967 #define NUMKEYS 5
1968
1969 void M_FindKeysForCommand (char *command, int *keys)
1970 {
1971         int             count;
1972         int             j;
1973         char    *b;
1974
1975         for (j = 0;j < NUMKEYS;j++)
1976                 keys[j] = -1;
1977
1978         count = 0;
1979
1980         for (j=0 ; j<256 ; j++)
1981         {
1982                 b = keybindings[j];
1983                 if (!b)
1984                         continue;
1985                 if (!strcmp (b, command) )
1986                 {
1987                         keys[count++] = j;
1988                         if (count == NUMKEYS)
1989                                 break;
1990                 }
1991         }
1992 }
1993
1994 void M_UnbindCommand (char *command)
1995 {
1996         int             j;
1997         char    *b;
1998
1999         for (j=0 ; j<256 ; j++)
2000         {
2001                 b = keybindings[j];
2002                 if (!b)
2003                         continue;
2004                 if (!strcmp (b, command))
2005                         Key_SetBinding (j, "");
2006         }
2007 }
2008
2009
2010 void M_Keys_Draw (void)
2011 {
2012         int             i, j;
2013         int             keys[NUMKEYS];
2014         int             y;
2015         cachepic_t      *p;
2016         char    keystring[1024];
2017
2018         M_Background(320, 48 + 8 * numcommands);
2019
2020         p = Draw_CachePic ("gfx/ttl_cstm.lmp");
2021         M_DrawPic ( (320-p->width)/2, 4, "gfx/ttl_cstm.lmp");
2022
2023         if (bind_grab)
2024                 M_Print (12, 32, "Press a key or button for this action");
2025         else
2026                 M_Print (18, 32, "Enter to change, backspace to clear");
2027
2028 // search for known bindings
2029         for (i=0 ; i<numcommands ; i++)
2030         {
2031                 y = 48 + 8*i;
2032
2033                 // If there's no command, it's just a section
2034                 if (bindnames[i][0][0] == '\0')
2035                 {
2036                         M_PrintRed (4, y, "\x0D");  // #13 is the little arrow pointing to the right
2037                         M_PrintRed (16, y, bindnames[i][1]);
2038                         continue;
2039                 }
2040                 else
2041                         M_Print (16, y, bindnames[i][1]);
2042
2043                 M_FindKeysForCommand (bindnames[i][0], keys);
2044
2045                 // LordHavoc: redesigned to print more than 2 keys, inspired by Tomaz's MiniRacer
2046                 if (keys[0] == -1)
2047                         strcpy(keystring, "???");
2048                 else
2049                 {
2050                         keystring[0] = 0;
2051                         for (j = 0;j < NUMKEYS;j++)
2052                         {
2053                                 if (keys[j] != -1)
2054                                 {
2055                                         if (j > 0)
2056                                                 strcat(keystring, " or ");
2057                                         strcat(keystring, Key_KeynumToString (keys[j]));
2058                                 }
2059                         }
2060                 }
2061                 M_Print (150, y, keystring);
2062         }
2063
2064         if (bind_grab)
2065                 M_DrawCharacter (140, 48 + keys_cursor*8, '=');
2066         else
2067                 M_DrawCharacter (140, 48 + keys_cursor*8, 12+((int)(realtime*4)&1));
2068 }
2069
2070
2071 void M_Keys_Key (int k)
2072 {
2073         char    cmd[80];
2074         int             keys[NUMKEYS];
2075
2076         if (bind_grab)
2077         {       // defining a key
2078                 S_LocalSound ("misc/menu1.wav");
2079                 if (k == K_ESCAPE)
2080                 {
2081                         bind_grab = false;
2082                 }
2083                 else //if (k != '`')
2084                 {
2085                         sprintf (cmd, "bind \"%s\" \"%s\"\n", Key_KeynumToString (k), bindnames[keys_cursor][0]);
2086                         Cbuf_InsertText (cmd);
2087                 }
2088
2089                 bind_grab = false;
2090                 return;
2091         }
2092
2093         switch (k)
2094         {
2095         case K_ESCAPE:
2096                 M_Menu_Options_f ();
2097                 break;
2098
2099         case K_LEFTARROW:
2100         case K_UPARROW:
2101                 S_LocalSound ("misc/menu1.wav");
2102                 do
2103                 {
2104                         keys_cursor--;
2105                         if (keys_cursor < 0)
2106                                 keys_cursor = numcommands-1;
2107                 }
2108                 while (bindnames[keys_cursor][0][0] == '\0');  // skip sections
2109                 break;
2110
2111         case K_DOWNARROW:
2112         case K_RIGHTARROW:
2113                 S_LocalSound ("misc/menu1.wav");
2114                 do
2115                 {
2116                         keys_cursor++;
2117                         if (keys_cursor >= numcommands)
2118                                 keys_cursor = 0;
2119                 }
2120                 while (bindnames[keys_cursor][0][0] == '\0');  // skip sections
2121                 break;
2122
2123         case K_ENTER:           // go into bind mode
2124                 M_FindKeysForCommand (bindnames[keys_cursor][0], keys);
2125                 S_LocalSound ("misc/menu2.wav");
2126                 if (keys[NUMKEYS - 1] != -1)
2127                         M_UnbindCommand (bindnames[keys_cursor][0]);
2128                 bind_grab = true;
2129                 break;
2130
2131         case K_BACKSPACE:               // delete bindings
2132         case K_DEL:                             // delete bindings
2133                 S_LocalSound ("misc/menu2.wav");
2134                 M_UnbindCommand (bindnames[keys_cursor][0]);
2135                 break;
2136         }
2137 }
2138
2139 //=============================================================================
2140 /* VIDEO MENU */
2141
2142 #define VIDEO_ITEMS 5
2143
2144 int video_cursor = 0;
2145 int video_cursor_table[] = {56, 68, 80, 92, 116};
2146 // note: if modes are added to the beginning of this list, update the
2147 // video_resolution = x; in M_Menu_Video_f below
2148 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}};
2149 int video_resolution;
2150
2151 extern int current_vid_fullscreen;
2152 extern int current_vid_width;
2153 extern int current_vid_height;
2154 extern int current_vid_bitsperpixel;
2155 extern int current_vid_stencil;
2156
2157
2158 void M_Menu_Video_f (void)
2159 {
2160         key_dest = key_menu;
2161         m_state = m_video;
2162         m_entersound = true;
2163
2164         // Look for the current resolution
2165         for (video_resolution = 0; video_resolution < (int) (sizeof (video_resolutions) / sizeof (video_resolutions[0])); video_resolution++)
2166         {
2167                 if (video_resolutions[video_resolution][0] == current_vid_width &&
2168                         video_resolutions[video_resolution][1] == current_vid_height)
2169                         break;
2170         }
2171
2172         // Default to 800x600 if we didn't find it
2173         if (video_resolution == sizeof (video_resolutions) / sizeof (video_resolutions[0]))
2174         {
2175                 // may need to update this number if mode list changes
2176                 video_resolution = 4;
2177                 Cvar_SetValueQuick (&vid_width, video_resolutions[video_resolution][0]);
2178                 Cvar_SetValueQuick (&vid_height, video_resolutions[video_resolution][1]);
2179         }
2180 }
2181
2182
2183 void M_Video_Draw (void)
2184 {
2185         cachepic_t      *p;
2186         const char* string;
2187
2188         M_Background(320, 200);
2189
2190         M_DrawPic(16, 4, "gfx/qplaque.lmp");
2191         p = Draw_CachePic("gfx/vidmodes.lmp");
2192         M_DrawPic((320-p->width)/2, 4, "gfx/vidmodes.lmp");
2193
2194         // Resolution
2195         M_Print(16, video_cursor_table[0], "            Resolution");
2196         string = va("%dx%d", video_resolutions[video_resolution][0], video_resolutions[video_resolution][1]);
2197         M_Print (220, video_cursor_table[0], string);
2198
2199         // Bits per pixel
2200         M_Print(16, video_cursor_table[1], "        Bits per pixel");
2201         M_Print (220, video_cursor_table[1], (vid_bitsperpixel.integer == 32) ? "32" : "16");
2202
2203         // Fullscreen
2204         M_Print(16, video_cursor_table[2], "            Fullscreen");
2205         M_DrawCheckbox(220, video_cursor_table[2], vid_fullscreen.integer);
2206
2207         // Stencil
2208         M_Print(16, video_cursor_table[3], "               Stencil");
2209         M_DrawCheckbox(220, video_cursor_table[3], vid_stencil.integer);
2210
2211         // "Apply" button
2212         M_Print(220, video_cursor_table[4], "Apply");
2213
2214         // Cursor
2215         M_DrawCharacter(200, video_cursor_table[video_cursor], 12+((int)(realtime*4)&1));
2216 }
2217
2218
2219 void M_Menu_Video_AdjustSliders (int dir)
2220 {
2221         S_LocalSound ("misc/menu3.wav");
2222
2223         switch (video_cursor)
2224         {
2225                 // Resolution
2226                 case 0:
2227                 {
2228                         int new_resolution = video_resolution + dir;
2229                         if (new_resolution < 0)
2230                                 video_resolution = sizeof (video_resolutions) / sizeof (video_resolutions[0]) - 1;
2231                         else if (new_resolution > (int) (sizeof (video_resolutions) / sizeof (video_resolutions[0]) - 1))
2232                                 video_resolution = 0;
2233                         else
2234                                 video_resolution = new_resolution;
2235
2236                         Cvar_SetValueQuick (&vid_width, video_resolutions[video_resolution][0]);
2237                         Cvar_SetValueQuick (&vid_height, video_resolutions[video_resolution][1]);
2238                         break;
2239                 }
2240
2241                 // Bits per pixel
2242                 case 1:
2243                         Cvar_SetValueQuick (&vid_bitsperpixel, (vid_bitsperpixel.integer == 32) ? 16 : 32);
2244                         break;
2245                 case 2:
2246                         Cvar_SetValueQuick (&vid_fullscreen, !vid_fullscreen.integer);
2247                         break;
2248                 case 3:
2249                         Cvar_SetValueQuick (&vid_stencil, !vid_stencil.integer);
2250                         break;
2251         }
2252 }
2253
2254
2255 void M_Video_Key (int key)
2256 {
2257         switch (key)
2258         {
2259                 case K_ESCAPE:
2260                         // vid_shared.c has a copy of the current video config. We restore it
2261                         Cvar_SetValueQuick(&vid_fullscreen, current_vid_fullscreen);
2262                         Cvar_SetValueQuick(&vid_width, current_vid_width);
2263                         Cvar_SetValueQuick(&vid_height, current_vid_height);
2264                         Cvar_SetValueQuick(&vid_bitsperpixel, current_vid_bitsperpixel);
2265                         Cvar_SetValueQuick(&vid_stencil, current_vid_stencil);
2266
2267                         S_LocalSound ("misc/menu1.wav");
2268                         M_Menu_Options_f ();
2269                         break;
2270
2271                 case K_ENTER:
2272                         m_entersound = true;
2273                         switch (video_cursor)
2274                         {
2275                                 case 4:
2276                                         Cbuf_AddText ("vid_restart\n");
2277                                         M_Menu_Options_f ();
2278                                         break;
2279                                 default:
2280                                         M_Menu_Video_AdjustSliders (1);
2281                         }
2282                         break;
2283
2284                 case K_UPARROW:
2285                         S_LocalSound ("misc/menu1.wav");
2286                         video_cursor--;
2287                         if (video_cursor < 0)
2288                                 video_cursor = VIDEO_ITEMS-1;
2289                         break;
2290
2291                 case K_DOWNARROW:
2292                         S_LocalSound ("misc/menu1.wav");
2293                         video_cursor++;
2294                         if (video_cursor >= VIDEO_ITEMS)
2295                                 video_cursor = 0;
2296                         break;
2297
2298                 case K_LEFTARROW:
2299                         M_Menu_Video_AdjustSliders (-1);
2300                         break;
2301
2302                 case K_RIGHTARROW:
2303                         M_Menu_Video_AdjustSliders (1);
2304                         break;
2305         }
2306 }
2307
2308 //=============================================================================
2309 /* HELP MENU */
2310
2311 int             help_page;
2312 #define NUM_HELP_PAGES  6
2313
2314
2315 void M_Menu_Help_f (void)
2316 {
2317         key_dest = key_menu;
2318         m_state = m_help;
2319         m_entersound = true;
2320         help_page = 0;
2321 }
2322
2323
2324
2325 void M_Help_Draw (void)
2326 {
2327         M_Background(320, 200);
2328         M_DrawPic (0, 0, va("gfx/help%i.lmp", help_page));
2329 }
2330
2331
2332 void M_Help_Key (int key)
2333 {
2334         switch (key)
2335         {
2336         case K_ESCAPE:
2337                 M_Menu_Main_f ();
2338                 break;
2339
2340         case K_UPARROW:
2341         case K_RIGHTARROW:
2342                 m_entersound = true;
2343                 if (++help_page >= NUM_HELP_PAGES)
2344                         help_page = 0;
2345                 break;
2346
2347         case K_DOWNARROW:
2348         case K_LEFTARROW:
2349                 m_entersound = true;
2350                 if (--help_page < 0)
2351                         help_page = NUM_HELP_PAGES-1;
2352                 break;
2353         }
2354
2355 }
2356
2357 //=============================================================================
2358 /* QUIT MENU */
2359
2360 char *m_quit_message[9];
2361 int             m_quit_prevstate;
2362 qboolean        wasInMenus;
2363
2364
2365 int M_QuitMessage(char *line1, char *line2, char *line3, char *line4, char *line5, char *line6, char *line7, char *line8)
2366 {
2367         m_quit_message[0] = line1;
2368         m_quit_message[1] = line2;
2369         m_quit_message[2] = line3;
2370         m_quit_message[3] = line4;
2371         m_quit_message[4] = line5;
2372         m_quit_message[5] = line6;
2373         m_quit_message[6] = line7;
2374         m_quit_message[7] = line8;
2375         m_quit_message[8] = NULL;
2376         return 1;
2377 }
2378
2379 int M_ChooseQuitMessage(int request)
2380 {
2381         switch (gamemode)
2382         {
2383         case GAME_NORMAL:
2384         case GAME_HIPNOTIC:
2385         case GAME_ROGUE:
2386         case GAME_NEHAHRA:
2387                 if (request-- == 0) return M_QuitMessage("Are you gonna quit","this game just like","everything else?",NULL,NULL,NULL,NULL,NULL);
2388                 if (request-- == 0) return M_QuitMessage("Milord, methinks that","thou art a lowly","quitter. Is this true?",NULL,NULL,NULL,NULL,NULL);
2389                 if (request-- == 0) return M_QuitMessage("Do I need to bust your","face open for trying","to quit?",NULL,NULL,NULL,NULL,NULL);
2390                 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);
2391                 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);
2392                 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);
2393                 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);
2394                 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);
2395                 break;
2396         case GAME_GOODVSBAD2:
2397                 if (request-- == 0) return M_QuitMessage("Press Yes To Quit","...","Yes",NULL,NULL,NULL,NULL,NULL);
2398                 if (request-- == 0) return M_QuitMessage("Do you really want to","Quit?","Play Good vs bad 3!",NULL,NULL,NULL,NULL,NULL);
2399                 if (request-- == 0) return M_QuitMessage("All your quit are","belong to long duck","dong",NULL,NULL,NULL,NULL,NULL);
2400                 if (request-- == 0) return M_QuitMessage("Press Y to quit","","But are you too legit?",NULL,NULL,NULL,NULL,NULL);
2401                 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);
2402                 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);
2403                 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);
2404                 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);
2405                 if (request-- == 0) return M_QuitMessage("Press Y like you","were waanderers","from Ys'",NULL,NULL,NULL,NULL,NULL);
2406                 if (request-- == 0) return M_QuitMessage("This game was made in","Nippon like the SS","announcer's saying ipon",NULL,NULL,NULL,NULL,NULL);
2407                 if (request-- == 0) return M_QuitMessage("you","want to quit?",NULL,NULL,NULL,NULL,NULL,NULL);
2408                 if (request-- == 0) return M_QuitMessage("Please stop playing","this stupid game",NULL,NULL,NULL,NULL,NULL,NULL);
2409                 break;
2410         case GAME_BATTLEMECH:
2411                 if (request-- == 0) return M_QuitMessage("? WHY ?","Press Y to quit, N to keep fraggin'",NULL,NULL,NULL,NULL,NULL,NULL);
2412                 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);
2413                 if (request-- == 0) return M_QuitMessage("Accept Defeat?","Press Y to quit, N to keep fraggin'",NULL,NULL,NULL,NULL,NULL,NULL);
2414                 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);
2415                 if (request-- == 0) return M_QuitMessage("Where's your bloodlust?","Press Y to quit, N to keep fraggin'",NULL,NULL,NULL,NULL,NULL,NULL);
2416                 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);
2417                 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);
2418                 break;
2419         default:
2420                 if (request-- == 0) return M_QuitMessage("Tired of fragging already?",NULL,NULL,NULL,NULL,NULL,NULL,NULL);
2421                 if (request-- == 0) return M_QuitMessage("Quit now and forfeit your bodycount?",NULL,NULL,NULL,NULL,NULL,NULL,NULL);
2422                 if (request-- == 0) return M_QuitMessage("Are you sure you want to quit?",NULL,NULL,NULL,NULL,NULL,NULL,NULL);
2423                 if (request-- == 0) return M_QuitMessage("Off to do something constructive?",NULL,NULL,NULL,NULL,NULL,NULL,NULL);
2424                 break;
2425         }
2426         return 0;
2427 };
2428
2429 void M_Menu_Quit_f (void)
2430 {
2431         int n;
2432         if (m_state == m_quit)
2433                 return;
2434         wasInMenus = (key_dest == key_menu);
2435         key_dest = key_menu;
2436         m_quit_prevstate = m_state;
2437         m_state = m_quit;
2438         m_entersound = true;
2439         // count how many there are
2440         for (n = 0;M_ChooseQuitMessage(n);n++);
2441         // choose one
2442         M_ChooseQuitMessage(rand() % n);
2443 }
2444
2445
2446 void M_Quit_Key (int key)
2447 {
2448         switch (key)
2449         {
2450         case K_ESCAPE:
2451         case 'n':
2452         case 'N':
2453                 if (wasInMenus)
2454                 {
2455                         m_state = m_quit_prevstate;
2456                         m_entersound = true;
2457                 }
2458                 else
2459                 {
2460                         key_dest = key_game;
2461                         m_state = m_none;
2462                 }
2463                 break;
2464
2465         case 'Y':
2466         case 'y':
2467                 Host_Quit_f ();
2468                 break;
2469
2470         default:
2471                 break;
2472         }
2473 }
2474
2475 void M_Quit_Draw (void)
2476 {
2477         int i, l, linelength, firstline, lastline, lines;
2478         for (i = 0, linelength = 0, firstline = 9999, lastline = -1;m_quit_message[i];i++)
2479         {
2480                 if ((l = strlen(m_quit_message[i])))
2481                 {
2482                         if (firstline > i)
2483                                 firstline = i;
2484                         if (lastline < i)
2485                                 lastline = i;
2486                         if (linelength < l)
2487                                 linelength = l;
2488                 }
2489         }
2490         lines = (lastline - firstline) + 1;
2491         M_Background(linelength * 8 + 16, lines * 8 + 16);
2492         M_DrawTextBox(0, 0, linelength, lines);
2493         for (i = 0, l = firstline;i < lines;i++, l++)
2494                 M_Print(8 + 4 * (linelength - strlen(m_quit_message[l])), 8 + 8 * i, m_quit_message[l]);
2495 }
2496
2497 //=============================================================================
2498 /* LAN CONFIG MENU */
2499
2500 int             lanConfig_cursor = -1;
2501 int             lanConfig_cursor_table [] = {56, 76, 112};
2502 #define NUM_LANCONFIG_CMDS      3
2503
2504 int     lanConfig_port;
2505 char    lanConfig_portname[6];
2506 char    lanConfig_joinname[22];
2507
2508 void M_Menu_LanConfig_f (void)
2509 {
2510         key_dest = key_menu;
2511         m_state = m_lanconfig;
2512         m_entersound = true;
2513         if (lanConfig_cursor == -1)
2514         {
2515                 if (JoiningGame)
2516                         lanConfig_cursor = 1;
2517         }
2518         if (StartingGame)
2519                 lanConfig_cursor = 1;
2520         lanConfig_port = 26000;
2521         sprintf(lanConfig_portname, "%u", lanConfig_port);
2522
2523         m_return_reason[0] = 0;
2524 }
2525
2526
2527 void M_LanConfig_Draw (void)
2528 {
2529         cachepic_t      *p;
2530         int             basex;
2531         char    *startJoin;
2532         char    *protocol;
2533
2534         M_Background(320, 200);
2535
2536         M_DrawPic (16, 4, "gfx/qplaque.lmp");
2537         p = Draw_CachePic ("gfx/p_multi.lmp");
2538         basex = (320-p->width)/2;
2539         M_DrawPic (basex, 4, "gfx/p_multi.lmp");
2540
2541         if (StartingGame)
2542                 startJoin = "New Game";
2543         else
2544                 startJoin = "Join Game";
2545         protocol = "TCP/IP";
2546         M_Print (basex, 32, va ("%s - %s", startJoin, protocol));
2547         basex += 8;
2548
2549         M_Print (basex, lanConfig_cursor_table[0], "Port");
2550         M_DrawTextBox (basex+8*8, lanConfig_cursor_table[0]-8, 6, 1);
2551         M_Print (basex+9*8, lanConfig_cursor_table[0], lanConfig_portname);
2552
2553         if (JoiningGame)
2554         {
2555                 M_Print (basex, lanConfig_cursor_table[1], "Search for games...");
2556                 M_Print (basex, lanConfig_cursor_table[2]-16, "Join game at:");
2557                 M_DrawTextBox (basex+8, lanConfig_cursor_table[2]-8, 22, 1);
2558                 M_Print (basex+16, lanConfig_cursor_table[2], lanConfig_joinname);
2559         }
2560         else
2561         {
2562                 M_DrawTextBox (basex, lanConfig_cursor_table[1]-8, 2, 1);
2563                 M_Print (basex+8, lanConfig_cursor_table[1], "OK");
2564         }
2565
2566         M_DrawCharacter (basex-8, lanConfig_cursor_table [lanConfig_cursor], 12+((int)(realtime*4)&1));
2567
2568         if (lanConfig_cursor == 0)
2569                 M_DrawCharacter (basex+9*8 + 8*strlen(lanConfig_portname), lanConfig_cursor_table [0], 10+((int)(realtime*4)&1));
2570
2571         if (lanConfig_cursor == 2)
2572                 M_DrawCharacter (basex+16 + 8*strlen(lanConfig_joinname), lanConfig_cursor_table [2], 10+((int)(realtime*4)&1));
2573
2574         if (*m_return_reason)
2575                 M_Print (basex, 168, m_return_reason);
2576 }
2577
2578
2579 void M_LanConfig_Key (int key)
2580 {
2581         int             l;
2582
2583         switch (key)
2584         {
2585         case K_ESCAPE:
2586                 M_Menu_MultiPlayer_f ();
2587                 break;
2588
2589         case K_UPARROW:
2590                 S_LocalSound ("misc/menu1.wav");
2591                 lanConfig_cursor--;
2592                 if (lanConfig_cursor < 0)
2593                         lanConfig_cursor = NUM_LANCONFIG_CMDS-1;
2594                 break;
2595
2596         case K_DOWNARROW:
2597                 S_LocalSound ("misc/menu1.wav");
2598                 lanConfig_cursor++;
2599                 if (lanConfig_cursor >= NUM_LANCONFIG_CMDS)
2600                         lanConfig_cursor = 0;
2601                 break;
2602
2603         case K_ENTER:
2604                 if (lanConfig_cursor == 0)
2605                         break;
2606
2607                 m_entersound = true;
2608
2609                 Cbuf_AddText ("stopdemo\n");
2610
2611                 Cvar_SetValue("port", lanConfig_port);
2612
2613                 if (lanConfig_cursor == 1)
2614                 {
2615                         if (StartingGame)
2616                         {
2617                                 M_Menu_GameOptions_f ();
2618                                 break;
2619                         }
2620                         M_Menu_ServerList_f();
2621                         break;
2622                 }
2623
2624                 if (lanConfig_cursor == 2)
2625                         Cbuf_AddText ( va ("connect \"%s\"\n", lanConfig_joinname) );
2626                 break;
2627
2628         case K_BACKSPACE:
2629                 if (lanConfig_cursor == 0)
2630                 {
2631                         if (strlen(lanConfig_portname))
2632                                 lanConfig_portname[strlen(lanConfig_portname)-1] = 0;
2633                 }
2634
2635                 if (lanConfig_cursor == 2)
2636                 {
2637                         if (strlen(lanConfig_joinname))
2638                                 lanConfig_joinname[strlen(lanConfig_joinname)-1] = 0;
2639                 }
2640                 break;
2641
2642         default:
2643                 if (key < 32 || key > 127)
2644                         break;
2645
2646                 if (lanConfig_cursor == 2)
2647                 {
2648                         l = strlen(lanConfig_joinname);
2649                         if (l < 21)
2650                         {
2651                                 lanConfig_joinname[l+1] = 0;
2652                                 lanConfig_joinname[l] = key;
2653                         }
2654                 }
2655
2656                 if (key < '0' || key > '9')
2657                         break;
2658                 if (lanConfig_cursor == 0)
2659                 {
2660                         l = strlen(lanConfig_portname);
2661                         if (l < 5)
2662                         {
2663                                 lanConfig_portname[l+1] = 0;
2664                                 lanConfig_portname[l] = key;
2665                         }
2666                 }
2667         }
2668
2669         if (StartingGame && lanConfig_cursor == 2)
2670         {
2671                 if (key == K_UPARROW)
2672                         lanConfig_cursor = 1;
2673                 else
2674                         lanConfig_cursor = 0;
2675         }
2676
2677         l =  atoi(lanConfig_portname);
2678         if (l <= 65535)
2679                 lanConfig_port = l;
2680         sprintf(lanConfig_portname, "%u", lanConfig_port);
2681 }
2682
2683 //=============================================================================
2684 /* GAME OPTIONS MENU */
2685
2686 typedef struct
2687 {
2688         char    *name;
2689         char    *description;
2690 } level_t;
2691
2692 typedef struct
2693 {
2694         char    *description;
2695         int             firstLevel;
2696         int             levels;
2697 } episode_t;
2698
2699 typedef struct
2700 {
2701         char *gamename;
2702         level_t *levels;
2703         episode_t *episodes;
2704         int numepisodes;
2705 }
2706 gamelevels_t;
2707
2708 level_t quakelevels[] =
2709 {
2710         {"start", "Entrance"},  // 0
2711
2712         {"e1m1", "Slipgate Complex"},                           // 1
2713         {"e1m2", "Castle of the Damned"},
2714         {"e1m3", "The Necropolis"},
2715         {"e1m4", "The Grisly Grotto"},
2716         {"e1m5", "Gloom Keep"},
2717         {"e1m6", "The Door To Chthon"},
2718         {"e1m7", "The House of Chthon"},
2719         {"e1m8", "Ziggurat Vertigo"},
2720
2721         {"e2m1", "The Installation"},                           // 9
2722         {"e2m2", "Ogre Citadel"},
2723         {"e2m3", "Crypt of Decay"},
2724         {"e2m4", "The Ebon Fortress"},
2725         {"e2m5", "The Wizard's Manse"},
2726         {"e2m6", "The Dismal Oubliette"},
2727         {"e2m7", "Underearth"},
2728
2729         {"e3m1", "Termination Central"},                        // 16
2730         {"e3m2", "The Vaults of Zin"},
2731         {"e3m3", "The Tomb of Terror"},
2732         {"e3m4", "Satan's Dark Delight"},
2733         {"e3m5", "Wind Tunnels"},
2734         {"e3m6", "Chambers of Torment"},
2735         {"e3m7", "The Haunted Halls"},
2736
2737         {"e4m1", "The Sewage System"},                          // 23
2738         {"e4m2", "The Tower of Despair"},
2739         {"e4m3", "The Elder God Shrine"},
2740         {"e4m4", "The Palace of Hate"},
2741         {"e4m5", "Hell's Atrium"},
2742         {"e4m6", "The Pain Maze"},
2743         {"e4m7", "Azure Agony"},
2744         {"e4m8", "The Nameless City"},
2745
2746         {"end", "Shub-Niggurath's Pit"},                        // 31
2747
2748         {"dm1", "Place of Two Deaths"},                         // 32
2749         {"dm2", "Claustrophobopolis"},
2750         {"dm3", "The Abandoned Base"},
2751         {"dm4", "The Bad Place"},
2752         {"dm5", "The Cistern"},
2753         {"dm6", "The Dark Zone"}
2754 };
2755
2756 episode_t quakeepisodes[] =
2757 {
2758         {"Welcome to Quake", 0, 1},
2759         {"Doomed Dimension", 1, 8},
2760         {"Realm of Black Magic", 9, 7},
2761         {"Netherworld", 16, 7},
2762         {"The Elder World", 23, 8},
2763         {"Final Level", 31, 1},
2764         {"Deathmatch Arena", 32, 6}
2765 };
2766
2767  //MED 01/06/97 added hipnotic levels
2768 level_t     hipnoticlevels[] =
2769 {
2770    {"start", "Command HQ"},  // 0
2771
2772    {"hip1m1", "The Pumping Station"},          // 1
2773    {"hip1m2", "Storage Facility"},
2774    {"hip1m3", "The Lost Mine"},
2775    {"hip1m4", "Research Facility"},
2776    {"hip1m5", "Military Complex"},
2777
2778    {"hip2m1", "Ancient Realms"},          // 6
2779    {"hip2m2", "The Black Cathedral"},
2780    {"hip2m3", "The Catacombs"},
2781    {"hip2m4", "The Crypt"},
2782    {"hip2m5", "Mortum's Keep"},
2783    {"hip2m6", "The Gremlin's Domain"},
2784
2785    {"hip3m1", "Tur Torment"},       // 12
2786    {"hip3m2", "Pandemonium"},
2787    {"hip3m3", "Limbo"},
2788    {"hip3m4", "The Gauntlet"},
2789
2790    {"hipend", "Armagon's Lair"},       // 16
2791
2792    {"hipdm1", "The Edge of Oblivion"}           // 17
2793 };
2794
2795 //MED 01/06/97  added hipnotic episodes
2796 episode_t   hipnoticepisodes[] =
2797 {
2798    {"Scourge of Armagon", 0, 1},
2799    {"Fortress of the Dead", 1, 5},
2800    {"Dominion of Darkness", 6, 6},
2801    {"The Rift", 12, 4},
2802    {"Final Level", 16, 1},
2803    {"Deathmatch Arena", 17, 1}
2804 };
2805
2806 //PGM 01/07/97 added rogue levels
2807 //PGM 03/02/97 added dmatch level
2808 level_t         roguelevels[] =
2809 {
2810         {"start",       "Split Decision"},
2811         {"r1m1",        "Deviant's Domain"},
2812         {"r1m2",        "Dread Portal"},
2813         {"r1m3",        "Judgement Call"},
2814         {"r1m4",        "Cave of Death"},
2815         {"r1m5",        "Towers of Wrath"},
2816         {"r1m6",        "Temple of Pain"},
2817         {"r1m7",        "Tomb of the Overlord"},
2818         {"r2m1",        "Tempus Fugit"},
2819         {"r2m2",        "Elemental Fury I"},
2820         {"r2m3",        "Elemental Fury II"},
2821         {"r2m4",        "Curse of Osiris"},
2822         {"r2m5",        "Wizard's Keep"},
2823         {"r2m6",        "Blood Sacrifice"},
2824         {"r2m7",        "Last Bastion"},
2825         {"r2m8",        "Source of Evil"},
2826         {"ctf1",    "Division of Change"}
2827 };
2828
2829 //PGM 01/07/97 added rogue episodes
2830 //PGM 03/02/97 added dmatch episode
2831 episode_t       rogueepisodes[] =
2832 {
2833         {"Introduction", 0, 1},
2834         {"Hell's Fortress", 1, 7},
2835         {"Corridors of Time", 8, 8},
2836         {"Deathmatch Arena", 16, 1}
2837 };
2838
2839 level_t         nehahralevels[] =
2840 {
2841         {"nehstart",    "Welcome to Nehahra"},
2842         {"neh1m1",      "Forge City1: Slipgates"},
2843         {"neh1m2",      "Forge City2: Boiler"},
2844         {"neh1m3",      "Forge City3: Escape"},
2845         {"neh1m4",      "Grind Core"},
2846         {"neh1m5",      "Industrial Silence"},
2847         {"neh1m6",      "Locked-Up Anger"},
2848         {"neh1m7",      "Wanderer of the Wastes"},
2849         {"neh1m8",      "Artemis System Net"},
2850         {"neh1m9",      "To the Death"},
2851         {"neh2m1",      "The Gates of Ghoro"},
2852         {"neh2m2",      "Sacred Trinity"},
2853         {"neh2m3",      "Realm of the Ancients"},
2854         {"neh2m4",      "Temple of the Ancients"},
2855         {"neh2m5",      "Dreams Made Flesh"},
2856         {"neh2m6",      "Your Last Cup of Sorrow"},
2857         {"nehsec",      "Ogre's Bane"},
2858         {"nehahra",     "Nehahra's Den"},
2859         {"nehend",      "Quintessence"}
2860 };
2861
2862 episode_t       nehahraepisodes[] =
2863 {
2864         {"Welcome to Nehahra", 0, 1},
2865         {"The Fall of Forge", 1, 9},
2866         {"The Outlands", 10, 7},
2867         {"Dimension of the Lost", 17, 2}
2868 };
2869
2870 // Map list for Transfusion
2871 level_t         transfusionlevels[] =
2872 {
2873         {"bb1",                 "The Stronghold"},
2874         {"bb2",                 "Winter Wonderland"},
2875         {"bb3",                 "Bodies"},
2876         {"bb4",                 "The Tower"},
2877         {"bb5",                 "Click!"},
2878         {"bb6",                 "Twin Fortress"},
2879         {"bb7",                 "Midgard"},
2880         {"bb8",                 "Fun With Heads"},
2881
2882         {"e1m1",                "Cradle to Grave"},
2883         {"e1m2",                "Wrong Side of the Tracks"},
2884         {"e1m7",                "Altar of Stone"},
2885         {"e2m8",                "The Lair of Shial"},
2886         {"e3m7",                "The Pit of Cerberus"},
2887         {"e4m8",                "The Hall of the Epiphany"},
2888         {"e4m9",                "Mall of the Dead"},
2889
2890         {"dm1",                 "Monolith Building 11"},
2891         {"dm2",                 "Power!"},
2892         {"dm3",                 "Area 15"},
2893         {"e6m1",                "Welcome to Your Life"},
2894         {"e6m8",                "Beauty and the Beast"},
2895
2896         {"cpbb01",              "Crypt of Despair"},
2897         {"cpbb03",              "Unholy Cathedral"},
2898
2899         {"b2a15",               "Area 15 (B2)"},
2900         {"barena",              "Blood Arena"},
2901         {"bkeep",               "Blood Keep"},
2902         {"bstar",               "Brown Star"},
2903         {"crypt",               "The Crypt"},
2904
2905         {"bb3_2k1",             "Bodies Infusion"},
2906         {"dcamp",               "DeathCamp"},
2907         {"highnoon",    "HighNoon"},
2908         {"qbb1",                "The Confluence"},
2909         {"qbb2",                "KathartiK"},
2910         {"qbb3",                "Caleb's Woodland Retreat"},
2911
2912         {"dranzbb6",    "Black Coffee"},
2913         {"fragm",               "Frag'M"},
2914         {"maim",                "Maim"},
2915         {"qe1m7",               "The House of Chthon"},
2916         {"simple",              "Dead Simple"}
2917 };
2918
2919 episode_t       transfusionepisodes[] =
2920 {
2921         {"Blood", 0, 8},
2922         {"Blood Single Player", 8, 7},
2923         {"Plasma Pack", 15, 5},
2924         {"Cryptic Passage", 20, 2},
2925         {"Blood 2", 22, 5},
2926         {"Transfusion", 27, 6},
2927         {"Conversions", 33, 5}
2928 };
2929
2930 level_t goodvsbad2levels[] =
2931 {
2932         {"rts", "Many Paths"},  // 0
2933         {"chess", "Chess, Scott Hess"},                         // 1
2934         {"dot", "Big Wall"},
2935         {"city2", "The Big City"},
2936         {"bwall", "0 G like Psychic TV"},
2937         {"snow", "Wireframed"},
2938         {"telep", "Infinite Falling"},
2939         {"faces", "Facing Bases"},
2940         {"island", "Adventure Islands"},
2941 };
2942
2943 episode_t goodvsbad2episodes[] =
2944 {
2945         {"Levels? Bevels!", 0, 8},
2946 };
2947
2948 level_t battlemechlevels[] =
2949 {
2950         {"start", "Parking Level"},
2951         {"dm1", "Hot Dump"},                        // 1
2952         {"dm2", "The Pits"},
2953         {"dm3", "Dimber Died"},
2954         {"dm4", "Fire in the Hole"},
2955         {"dm5", "Clubhouses"},
2956         {"dm6", "Army go Underground"},
2957 };
2958
2959 episode_t battlemechepisodes[] =
2960 {
2961         {"Time for Battle", 0, 7},
2962 };
2963
2964 gamelevels_t sharewarequakegame = {"Shareware Quake", quakelevels, quakeepisodes, 2};
2965 gamelevels_t registeredquakegame = {"Quake", quakelevels, quakeepisodes, 7};
2966 gamelevels_t hipnoticgame = {"Scourge of Armagon", hipnoticlevels, hipnoticepisodes, 6};
2967 gamelevels_t roguegame = {"Dissolution of Eternity", roguelevels, rogueepisodes, 4};
2968 gamelevels_t nehahragame = {"Nehahra", nehahralevels, nehahraepisodes, 4};
2969 gamelevels_t transfusiongame = {"Transfusion", transfusionlevels, transfusionepisodes, 7};
2970 gamelevels_t goodvsbad2game = {"Good Vs. Bad 2", goodvsbad2levels, goodvsbad2episodes, 1};
2971 gamelevels_t battlemechgame = {"Battlemech", battlemechlevels, battlemechepisodes, 1};
2972
2973 typedef struct
2974 {
2975         int gameid;
2976         gamelevels_t *notregistered;
2977         gamelevels_t *registered;
2978 }
2979 gameinfo_t;
2980
2981 gameinfo_t gamelist[] =
2982 {
2983         {GAME_NORMAL, &sharewarequakegame, &registeredquakegame},
2984         {GAME_HIPNOTIC, &hipnoticgame, &hipnoticgame},
2985         {GAME_ROGUE, &roguegame, &roguegame},
2986         {GAME_NEHAHRA, &nehahragame, &nehahragame},
2987         {GAME_TRANSFUSION, &transfusiongame, &transfusiongame},
2988         {GAME_GOODVSBAD2, &goodvsbad2game, &goodvsbad2game},
2989         {GAME_BATTLEMECH, &battlemechgame, &battlemechgame},
2990         {-1, &sharewarequakegame, &registeredquakegame} // final fallback
2991 };
2992
2993 gamelevels_t *lookupgameinfo(void)
2994 {
2995         int i;
2996         for (i = 0;gamelist[i].gameid >= 0 && gamelist[i].gameid != gamemode;i++);
2997         if (registered.integer)
2998                 return gamelist[i].registered;
2999         else
3000                 return gamelist[i].notregistered;
3001 }
3002
3003 int     startepisode;
3004 int     startlevel;
3005 int maxplayers;
3006 qboolean m_serverInfoMessage = false;
3007 double m_serverInfoMessageTime;
3008
3009 extern cvar_t sv_public;
3010
3011 void M_Menu_GameOptions_f (void)
3012 {
3013         key_dest = key_menu;
3014         m_state = m_gameoptions;
3015         m_entersound = true;
3016         if (maxplayers == 0)
3017                 maxplayers = svs.maxclients;
3018         if (maxplayers < 2)
3019                 maxplayers = min(8, MAX_SCOREBOARD);
3020 }
3021
3022
3023 int gameoptions_cursor_table[] = {40, 56, 64, 72, 80, 88, 96, 104, 132, 152, 160};
3024 #define NUM_GAMEOPTIONS 11
3025 int             gameoptions_cursor;
3026
3027 void M_GameOptions_Draw (void)
3028 {
3029         cachepic_t      *p;
3030         int             x;
3031         gamelevels_t *g;
3032
3033         M_Background(320, 200);
3034
3035         M_DrawPic (16, 4, "gfx/qplaque.lmp");
3036         p = Draw_CachePic ("gfx/p_multi.lmp");
3037         M_DrawPic ( (320-p->width)/2, 4, "gfx/p_multi.lmp");
3038
3039         M_DrawTextBox (152, 32, 10, 1);
3040         M_Print (160, 40, "begin game");
3041
3042         M_Print (0, 56, "      Max players");
3043         M_Print (160, 56, va("%i", maxplayers) );
3044
3045         if (gamemode != GAME_GOODVSBAD2)
3046         {
3047                 M_Print (0, 64, "        Game Type");
3048                 if (gamemode == GAME_TRANSFUSION)
3049                 {
3050                         if (!deathmatch.integer)
3051                                 Cvar_SetValue("deathmatch", 1);
3052                         if (deathmatch.integer == 2)
3053                                 M_Print (160, 64, "Capture the Flag");
3054                         else
3055                                 M_Print (160, 64, "Blood Bath");
3056                 }
3057                 else if (gamemode == GAME_BATTLEMECH)
3058                 {
3059                         if (!deathmatch.integer)
3060                                 Cvar_SetValue("deathmatch", 1);
3061                         if (deathmatch.integer == 2)
3062                                 M_Print (160, 64, "Rambo Match");
3063                         else
3064                                 M_Print (160, 64, "Deathmatch");
3065                 }
3066                 else
3067                 {
3068                         if (!coop.integer && !deathmatch.integer)
3069                                 Cvar_SetValue("deathmatch", 1);
3070                         if (coop.integer)
3071                                 M_Print (160, 64, "Cooperative");
3072                         else
3073                                 M_Print (160, 64, "Deathmatch");
3074                 }
3075
3076                 M_Print (0, 72, "        Teamplay");
3077                 if (gamemode == GAME_ROGUE)
3078                 {
3079                         char *msg;
3080
3081                         switch((int)teamplay.integer)
3082                         {
3083                                 case 1: msg = "No Friendly Fire"; break;
3084                                 case 2: msg = "Friendly Fire"; break;
3085                                 case 3: msg = "Tag"; break;
3086                                 case 4: msg = "Capture the Flag"; break;
3087                                 case 5: msg = "One Flag CTF"; break;
3088                                 case 6: msg = "Three Team CTF"; break;
3089                                 default: msg = "Off"; break;
3090                         }
3091                         M_Print (160, 72, msg);
3092                 }
3093                 else
3094                 {
3095                         char *msg;
3096
3097                         switch (teamplay.integer)
3098                         {
3099                                 case 0: msg = "Off"; break;
3100                                 case 2: msg = "Friendly Fire"; break;
3101                                 default: msg = "No Friendly Fire"; break;
3102                         }
3103                         M_Print (160, 72, msg);
3104                 }
3105
3106                 M_Print (0, 80, "            Skill");
3107                 if (skill.integer == 0)
3108                         M_Print (160, 80, "Easy difficulty");
3109                 else if (skill.integer == 1)
3110                         M_Print (160, 80, "Normal difficulty");
3111                 else if (skill.integer == 2)
3112                         M_Print (160, 80, "Hard difficulty");
3113                 else
3114                         M_Print (160, 80, "Nightmare difficulty");
3115
3116                 M_Print (0, 88, "       Frag Limit");
3117                 if (fraglimit.integer == 0)
3118                         M_Print (160, 88, "none");
3119                 else
3120                         M_Print (160, 88, va("%i frags", fraglimit.integer));
3121
3122                 M_Print (0, 96, "       Time Limit");
3123                 if (timelimit.integer == 0)
3124                         M_Print (160, 96, "none");
3125                 else
3126                         M_Print (160, 96, va("%i minutes", timelimit.integer));
3127         }
3128
3129         M_Print (0, 104, "    Public server");
3130         M_Print (160, 104, (sv_public.integer == 0) ? "no" : "yes");
3131
3132         M_Print (0, 120, "      Server name");
3133         M_DrawTextBox (0, 124, 38, 1);
3134         M_Print (8, 132, hostname.string);
3135
3136         g = lookupgameinfo();
3137
3138         if (gamemode != GAME_GOODVSBAD2)
3139         {
3140                 M_Print (0, 152, "         Episode");
3141                 M_Print (160, 152, g->episodes[startepisode].description);
3142         }
3143
3144         M_Print (0, 160, "           Level");
3145         M_Print (160, 160, g->levels[g->episodes[startepisode].firstLevel + startlevel].description);
3146         M_Print (160, 168, g->levels[g->episodes[startepisode].firstLevel + startlevel].name);
3147
3148 // line cursor
3149         if (gameoptions_cursor == 8)
3150                 M_DrawCharacter (8 + 8 * strlen(hostname.string), gameoptions_cursor_table[gameoptions_cursor], 10+((int)(realtime*4)&1));
3151         else
3152                 M_DrawCharacter (144, gameoptions_cursor_table[gameoptions_cursor], 12+((int)(realtime*4)&1));
3153
3154         if (m_serverInfoMessage)
3155         {
3156                 if ((realtime - m_serverInfoMessageTime) < 5.0)
3157                 {
3158                         x = (320-26*8)/2;
3159                         M_DrawTextBox (x, 138, 24, 4);
3160                         x += 8;
3161                         M_Print (x, 146, " More than 64 players?? ");
3162                         M_Print (x, 154, "  First, question your  ");
3163                         M_Print (x, 162, "   sanity, then email   ");
3164                         M_Print (x, 170, " havoc@telefragged.com  ");
3165                 }
3166                 else
3167                         m_serverInfoMessage = false;
3168         }
3169 }
3170
3171
3172 void M_NetStart_Change (int dir)
3173 {
3174         gamelevels_t *g;
3175         int count;
3176
3177         switch (gameoptions_cursor)
3178         {
3179         case 1:
3180                 maxplayers += dir;
3181                 if (maxplayers > MAX_SCOREBOARD)
3182                 {
3183                         maxplayers = MAX_SCOREBOARD;
3184                         m_serverInfoMessage = true;
3185                         m_serverInfoMessageTime = realtime;
3186                 }
3187                 if (maxplayers < 2)
3188                         maxplayers = 2;
3189                 break;
3190
3191         case 2:
3192                 if (gamemode == GAME_GOODVSBAD2)
3193                         break;
3194                 if (gamemode == GAME_TRANSFUSION)
3195                 {
3196                         if (deathmatch.integer == 2) // changing from CTF to BloodBath
3197                                 Cvar_SetValueQuick (&deathmatch, 0);
3198                         else // changing from BloodBath to CTF
3199                                 Cvar_SetValueQuick (&deathmatch, 2);
3200                 }
3201                 else if (gamemode == GAME_BATTLEMECH)
3202                 {
3203                         if (deathmatch.integer == 2) // changing from Rambo to Deathmatch
3204                                 Cvar_SetValueQuick (&deathmatch, 0);
3205                         else // changing from Deathmatch to Rambo
3206                                 Cvar_SetValueQuick (&deathmatch, 2);
3207                 }
3208                 else
3209                 {
3210                         if (deathmatch.integer) // changing from deathmatch to coop
3211                         {
3212                                 Cvar_SetValueQuick (&coop, 1);
3213                                 Cvar_SetValueQuick (&deathmatch, 0);
3214                         }
3215                         else // changing from coop to deathmatch
3216                         {
3217                                 Cvar_SetValueQuick (&coop, 0);
3218                                 Cvar_SetValueQuick (&deathmatch, 1);
3219                         }
3220                 }
3221                 break;
3222
3223         case 3:
3224                 if (gamemode == GAME_GOODVSBAD2)
3225                         break;
3226                 if (gamemode == GAME_ROGUE)
3227                         count = 6;
3228                 else
3229                         count = 2;
3230
3231                 Cvar_SetValueQuick (&teamplay, teamplay.integer + dir);
3232                 if (teamplay.integer > count)
3233                         Cvar_SetValueQuick (&teamplay, 0);
3234                 else if (teamplay.integer < 0)
3235                         Cvar_SetValueQuick (&teamplay, count);
3236                 break;
3237
3238         case 4:
3239                 if (gamemode == GAME_GOODVSBAD2)
3240                         break;
3241                 Cvar_SetValueQuick (&skill, skill.integer + dir);
3242                 if (skill.integer > 3)
3243                         Cvar_SetValueQuick (&skill, 0);
3244                 if (skill.integer < 0)
3245                         Cvar_SetValueQuick (&skill, 3);
3246                 break;
3247
3248         case 5:
3249                 if (gamemode == GAME_GOODVSBAD2)
3250                         break;
3251                 Cvar_SetValueQuick (&fraglimit, fraglimit.integer + dir*10);
3252                 if (fraglimit.integer > 100)
3253                         Cvar_SetValueQuick (&fraglimit, 0);
3254                 if (fraglimit.integer < 0)
3255                         Cvar_SetValueQuick (&fraglimit, 100);
3256                 break;
3257
3258         case 6:
3259                 if (gamemode == GAME_GOODVSBAD2)
3260                         break;
3261                 Cvar_SetValueQuick (&timelimit, timelimit.value + dir*5);
3262                 if (timelimit.value > 60)
3263                         Cvar_SetValueQuick (&timelimit, 0);
3264                 if (timelimit.value < 0)
3265                         Cvar_SetValueQuick (&timelimit, 60);
3266                 break;
3267
3268         case 7:
3269                 Cvar_SetValueQuick (&sv_public, !sv_public.integer);
3270                 break;
3271
3272         case 8:
3273                 break;
3274
3275         case 9:
3276                 if (gamemode == GAME_GOODVSBAD2)
3277                         break;
3278                 startepisode += dir;
3279                 g = lookupgameinfo();
3280
3281                 if (startepisode < 0)
3282                         startepisode = g->numepisodes - 1;
3283
3284                 if (startepisode >= g->numepisodes)
3285                         startepisode = 0;
3286
3287                 startlevel = 0;
3288                 break;
3289
3290         case 10:
3291                 startlevel += dir;
3292                 g = lookupgameinfo();
3293
3294                 if (startlevel < 0)
3295                         startlevel = g->episodes[startepisode].levels - 1;
3296
3297                 if (startlevel >= g->episodes[startepisode].levels)
3298                         startlevel = 0;
3299                 break;
3300         }
3301 }
3302
3303 void M_GameOptions_Key (int key)
3304 {
3305         gamelevels_t *g;
3306         int l;
3307         char hostnamebuf[128];
3308
3309         switch (key)
3310         {
3311         case K_ESCAPE:
3312                 M_Menu_MultiPlayer_f ();
3313                 break;
3314
3315         case K_UPARROW:
3316                 S_LocalSound ("misc/menu1.wav");
3317                 gameoptions_cursor--;
3318                 if (gameoptions_cursor < 0)
3319                         gameoptions_cursor = NUM_GAMEOPTIONS-1;
3320                 break;
3321
3322         case K_DOWNARROW:
3323                 S_LocalSound ("misc/menu1.wav");
3324                 gameoptions_cursor++;
3325                 if (gameoptions_cursor >= NUM_GAMEOPTIONS)
3326                         gameoptions_cursor = 0;
3327                 break;
3328
3329         case K_LEFTARROW:
3330                 if (gameoptions_cursor == 0)
3331                         break;
3332                 S_LocalSound ("misc/menu3.wav");
3333                 M_NetStart_Change (-1);
3334                 break;
3335
3336         case K_RIGHTARROW:
3337                 if (gameoptions_cursor == 0)
3338                         break;
3339                 S_LocalSound ("misc/menu3.wav");
3340                 M_NetStart_Change (1);
3341                 break;
3342
3343         case K_ENTER:
3344                 S_LocalSound ("misc/menu2.wav");
3345                 if (gameoptions_cursor == 0)
3346                 {
3347                         if (sv.active)
3348                                 Cbuf_AddText ("disconnect\n");
3349                         Cbuf_AddText ( va ("maxplayers %u\n", maxplayers) );
3350
3351                         g = lookupgameinfo();
3352                         Cbuf_AddText ( va ("map %s\n", g->levels[g->episodes[startepisode].firstLevel + startlevel].name) );
3353                         return;
3354                 }
3355
3356                 M_NetStart_Change (1);
3357                 break;
3358
3359         case K_BACKSPACE:
3360                 if (gameoptions_cursor == 8)
3361                 {
3362                         l = strlen(hostname.string);
3363                         if (l)
3364                         {
3365                                 l = min(l - 1, 37);
3366                                 memcpy(hostnamebuf, hostname.string, l);
3367                                 hostnamebuf[l] = 0;
3368                                 Cvar_Set("hostname", hostnamebuf);
3369                         }
3370                 }
3371                 break;
3372
3373         default:
3374                 if (key < 32 || key > 127)
3375                         break;
3376                 if (gameoptions_cursor == 8)
3377                 {
3378                         l = strlen(hostname.string);
3379                         if (l < 37)
3380                         {
3381                                 memcpy(hostnamebuf, hostname.string, l);
3382                                 hostnamebuf[l] = key;
3383                                 hostnamebuf[l+1] = 0;
3384                                 Cvar_Set("hostname", hostnamebuf);
3385                         }
3386                 }
3387         }
3388 }
3389
3390 //=============================================================================
3391 /* SLIST MENU */
3392
3393 int slist_cursor;
3394
3395 void M_Menu_ServerList_f (void)
3396 {
3397         key_dest = key_menu;
3398         m_state = m_slist;
3399         m_entersound = true;
3400         slist_cursor = 0;
3401         m_return_reason[0] = 0;
3402         Net_Slist_f();
3403 }
3404
3405
3406 void M_ServerList_Draw (void)
3407 {
3408         int n, y, visible, start, end;
3409         cachepic_t *p;
3410         const char *s;
3411
3412         // use as much vertical space as available
3413         M_Background(640, vid.conheight);
3414         // scroll the list as the cursor moves
3415         s = va("%i/%i masters %i/%i servers", masterreplycount, masterquerycount, serverreplycount, serverquerycount);
3416         M_PrintRed((640 - strlen(s) * 8) / 2, 32, s);
3417         if (*m_return_reason)
3418                 M_Print(16, vid.conheight - 8, m_return_reason);
3419         y = 48;
3420         visible = (vid.conheight - 16 - y) / 8;
3421         start = bound(0, slist_cursor - (visible >> 1), hostCacheCount - visible);
3422         end = min(start + visible, hostCacheCount);
3423
3424         p = Draw_CachePic("gfx/p_multi.lmp");
3425         M_DrawPic((640 - p->width) / 2, 4, "gfx/p_multi.lmp");
3426         if (end > start)
3427         {
3428                 for (n = start;n < end;n++)
3429                 {
3430                         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);
3431                         M_Print(0, y, hostcache[n].line1);y += 8;
3432                         M_Print(0, y, hostcache[n].line2);y += 8;
3433                 }
3434         }
3435         else if (realtime - masterquerytime < 3)
3436         {
3437                 if (masterquerycount)
3438                         M_Print(0, y, "No servers found");
3439                 else
3440                         M_Print(0, y, "No master servers found (network problem?)");
3441         }
3442 }
3443
3444
3445 void M_ServerList_Key(int k)
3446 {
3447         switch (k)
3448         {
3449         case K_ESCAPE:
3450                 M_Menu_LanConfig_f();
3451                 break;
3452
3453         case K_SPACE:
3454                 Net_Slist_f();
3455                 break;
3456
3457         case K_UPARROW:
3458         case K_LEFTARROW:
3459                 S_LocalSound("misc/menu1.wav");
3460                 slist_cursor--;
3461                 if (slist_cursor < 0)
3462                         slist_cursor = hostCacheCount - 1;
3463                 break;
3464
3465         case K_DOWNARROW:
3466         case K_RIGHTARROW:
3467                 S_LocalSound("misc/menu1.wav");
3468                 slist_cursor++;
3469                 if (slist_cursor >= hostCacheCount)
3470                         slist_cursor = 0;
3471                 break;
3472
3473         case K_ENTER:
3474                 S_LocalSound("misc/menu2.wav");
3475                 Cbuf_AddText(va("connect \"%s\"\n", hostcache[slist_cursor].cname));
3476                 break;
3477
3478         default:
3479                 break;
3480         }
3481
3482 }
3483
3484 //=============================================================================
3485 /* Menu Subsystem */
3486
3487
3488 void M_Init (void)
3489 {
3490         menu_mempool = Mem_AllocPool("Menu");
3491         menuplyr_load = true;
3492         menuplyr_pixels = NULL;
3493
3494         Cmd_AddCommand ("togglemenu", M_ToggleMenu_f);
3495
3496         Cmd_AddCommand ("menu_main", M_Menu_Main_f);
3497         Cmd_AddCommand ("menu_singleplayer", M_Menu_SinglePlayer_f);
3498         Cmd_AddCommand ("menu_load", M_Menu_Load_f);
3499         Cmd_AddCommand ("menu_save", M_Menu_Save_f);
3500         Cmd_AddCommand ("menu_multiplayer", M_Menu_MultiPlayer_f);
3501         Cmd_AddCommand ("menu_setup", M_Menu_Setup_f);
3502         Cmd_AddCommand ("menu_options", M_Menu_Options_f);
3503         Cmd_AddCommand ("menu_options_effects", M_Menu_Options_Effects_f);
3504         Cmd_AddCommand ("menu_options_colorcontrol", M_Menu_Options_ColorControl_f);
3505         Cvar_RegisterVariable (&menu_options_colorcontrol_correctionvalue);
3506         Cmd_AddCommand ("menu_keys", M_Menu_Keys_f);
3507         Cmd_AddCommand ("menu_video", M_Menu_Video_f);
3508         Cmd_AddCommand ("help", M_Menu_Help_f);
3509         Cmd_AddCommand ("menu_quit", M_Menu_Quit_f);
3510
3511         if (gamemode == GAME_TRANSFUSION)
3512         {
3513                 numcommands = sizeof(transfusionbindnames) / sizeof(transfusionbindnames[0]);
3514                 bindnames = transfusionbindnames;
3515         }
3516         else if (gamemode == GAME_GOODVSBAD2)
3517         {
3518                 numcommands = sizeof(goodvsbad2bindnames) / sizeof(goodvsbad2bindnames[0]);
3519                 bindnames = goodvsbad2bindnames;
3520         }
3521         else
3522         {
3523                 numcommands = sizeof(quakebindnames) / sizeof(quakebindnames[0]);
3524                 bindnames = quakebindnames;
3525         }
3526
3527         // Make sure "keys_cursor" doesn't start on a section in the binding list
3528         keys_cursor = 0;
3529         while (bindnames[keys_cursor][0][0] == '\0')
3530         {
3531                 keys_cursor++;
3532
3533                 // Only sections? There may be a problem somewhere...
3534                 if (keys_cursor >= numcommands)
3535                         Sys_Error ("M_Init: The key binding list only contains sections");
3536         }
3537
3538
3539         if (gamemode == GAME_NEHAHRA)
3540         {
3541                 if (FS_FileExists("maps/neh1m4.bsp"))
3542                 {
3543                         if (FS_FileExists("hearing.dem"))
3544                         {
3545                                 Con_Printf("Nehahra movie and game detected.\n");
3546                                 NehGameType = TYPE_BOTH;
3547                         }
3548                         else
3549                         {
3550                                 Con_Printf("Nehahra game detected.\n");
3551                                 NehGameType = TYPE_GAME;
3552                         }
3553                 }
3554                 else
3555                 {
3556                         if (FS_FileExists("hearing.dem"))
3557                         {
3558                                 Con_Printf("Nehahra movie detected.\n");
3559                                 NehGameType = TYPE_DEMO;
3560                         }
3561                         else
3562                         {
3563                                 Con_Printf("Nehahra not found.\n");
3564                                 NehGameType = TYPE_GAME; // could just complain, but...
3565                         }
3566                 }
3567         }
3568 }
3569
3570 void M_Draw (void)
3571 {
3572         if (key_dest != key_menu)
3573                 m_state = m_none;
3574         if (m_state == m_none)
3575                 return;
3576
3577         switch (m_state)
3578         {
3579         case m_none:
3580                 break;
3581
3582         case m_main:
3583                 M_Main_Draw ();
3584                 break;
3585
3586         case m_demo:
3587                 M_Demo_Draw ();
3588                 break;
3589
3590         case m_singleplayer:
3591                 M_SinglePlayer_Draw ();
3592                 break;
3593
3594         case m_load:
3595                 M_Load_Draw ();
3596                 break;
3597
3598         case m_save:
3599                 M_Save_Draw ();
3600                 break;
3601
3602         case m_multiplayer:
3603                 M_MultiPlayer_Draw ();
3604                 break;
3605
3606         case m_setup:
3607                 M_Setup_Draw ();
3608                 break;
3609
3610         case m_options:
3611                 M_Options_Draw ();
3612                 break;
3613
3614         case m_options_effects:
3615                 M_Options_Effects_Draw ();
3616                 break;
3617
3618         case m_options_colorcontrol:
3619                 M_Options_ColorControl_Draw ();
3620                 break;
3621
3622         case m_keys:
3623                 M_Keys_Draw ();
3624                 break;
3625
3626         case m_video:
3627                 M_Video_Draw ();
3628                 break;
3629
3630         case m_help:
3631                 M_Help_Draw ();
3632                 break;
3633
3634         case m_quit:
3635                 M_Quit_Draw ();
3636                 break;
3637
3638         case m_lanconfig:
3639                 M_LanConfig_Draw ();
3640                 break;
3641
3642         case m_gameoptions:
3643                 M_GameOptions_Draw ();
3644                 break;
3645
3646         case m_slist:
3647                 M_ServerList_Draw ();
3648                 break;
3649         }
3650
3651         if (m_entersound)
3652         {
3653                 S_LocalSound ("misc/menu2.wav");
3654                 m_entersound = false;
3655         }
3656
3657         S_ExtraUpdate ();
3658 }
3659
3660
3661 void M_Keydown (int key)
3662 {
3663         switch (m_state)
3664         {
3665         case m_none:
3666                 return;
3667
3668         case m_main:
3669                 M_Main_Key (key);
3670                 return;
3671
3672         case m_demo:
3673                 M_Demo_Key (key);
3674                 return;
3675
3676         case m_singleplayer:
3677                 M_SinglePlayer_Key (key);
3678                 return;
3679
3680         case m_load:
3681                 M_Load_Key (key);
3682                 return;
3683
3684         case m_save:
3685                 M_Save_Key (key);
3686                 return;
3687
3688         case m_multiplayer:
3689                 M_MultiPlayer_Key (key);
3690                 return;
3691
3692         case m_setup:
3693                 M_Setup_Key (key);
3694                 return;
3695
3696         case m_options:
3697                 M_Options_Key (key);
3698                 return;
3699
3700         case m_options_effects:
3701                 M_Options_Effects_Key (key);
3702                 return;
3703
3704         case m_options_colorcontrol:
3705                 M_Options_ColorControl_Key (key);
3706                 return;
3707
3708         case m_keys:
3709                 M_Keys_Key (key);
3710                 return;
3711
3712         case m_video:
3713                 M_Video_Key (key);
3714                 return;
3715
3716         case m_help:
3717                 M_Help_Key (key);
3718                 return;
3719
3720         case m_quit:
3721                 M_Quit_Key (key);
3722                 return;
3723
3724         case m_lanconfig:
3725                 M_LanConfig_Key (key);
3726                 return;
3727
3728         case m_gameoptions:
3729                 M_GameOptions_Key (key);
3730                 return;
3731
3732         case m_slist:
3733                 M_ServerList_Key (key);
3734                 return;
3735         }
3736 }
3737