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