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