]> icculus.org git repositories - divverent/darkplaces.git/blob - menu.c
Pure cleaning commit: removed "crc.[ch]" and "gl_warp_sin.h", removed dead functions...
[divverent/darkplaces.git] / menu.c
1 /*
2 Copyright (C) 1996-1997 Id Software, Inc.
3
4 This program is free software; you can redistribute it and/or
5 modify it under the terms of the GNU General Public License
6 as published by the Free Software Foundation; either version 2
7 of the License, or (at your option) any later version.
8
9 This program is distributed in the hope that it will be useful,
10 but WITHOUT ANY WARRANTY; without even the implied warranty of
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
12
13 See the GNU General Public License for more details.
14
15 You should have received a copy of the GNU General Public License
16 along with this program; if not, write to the Free Software
17 Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
18
19 */
20 #include "quakedef.h"
21 #include "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_particles;
1494 extern cvar_t cl_stainmaps;
1495 extern cvar_t cl_stainmapsclearonload;
1496 extern cvar_t cl_decals;
1497 extern cvar_t r_explosionclip;
1498 extern cvar_t r_modellights;
1499 extern cvar_t r_coronas;
1500 extern cvar_t gl_flashblend;
1501 extern cvar_t cl_particles_quality;
1502 extern cvar_t cl_particles_bulletimpacts;
1503 extern cvar_t cl_particles_smoke;
1504 extern cvar_t cl_particles_sparks;
1505 extern cvar_t cl_particles_bubbles;
1506 extern cvar_t cl_particles_blood;
1507 extern cvar_t cl_particles_blood_alpha;
1508 extern cvar_t cl_particles_blood_bloodhack;
1509 extern cvar_t cl_particles_explosions_shell;
1510 extern cvar_t cl_beams_polygon;
1511 extern cvar_t cl_beams_relative;
1512 extern cvar_t cl_beams_lightatend;
1513 extern cvar_t r_lightningbeam_thickness;
1514 extern cvar_t r_lightningbeam_scroll;
1515 extern cvar_t r_lightningbeam_repeatdistance;
1516 extern cvar_t r_lightningbeam_color_red;
1517 extern cvar_t r_lightningbeam_color_green;
1518 extern cvar_t r_lightningbeam_color_blue;
1519 extern cvar_t r_lightningbeam_qmbtexture;
1520
1521 void M_Menu_Options_Effects_AdjustSliders (int dir)
1522 {
1523         int optnum;
1524         S_LocalSound ("sound/misc/menu3.wav");
1525
1526         optnum = 0;
1527              if (options_effects_cursor == optnum++) Cvar_SetValueQuick (&r_modellights, bound(0, r_modellights.value + dir, 8));
1528         else if (options_effects_cursor == optnum++) Cvar_SetValueQuick (&r_coronas, bound(0, r_coronas.value + dir * 0.125, 4));
1529         else if (options_effects_cursor == optnum++) Cvar_SetValueQuick (&gl_flashblend, !gl_flashblend.integer);
1530         else if (options_effects_cursor == optnum++) Cvar_SetValueQuick (&cl_particles, !cl_particles.integer);
1531         else if (options_effects_cursor == optnum++) Cvar_SetValueQuick (&cl_particles_quality, bound(1, cl_particles_quality.value + dir * 0.5, 4));
1532         else if (options_effects_cursor == optnum++) Cvar_SetValueQuick (&cl_particles_explosions_shell, !cl_particles_explosions_shell.integer);
1533         else if (options_effects_cursor == optnum++) Cvar_SetValueQuick (&r_explosionclip, !r_explosionclip.integer);
1534         else if (options_effects_cursor == optnum++) Cvar_SetValueQuick (&cl_stainmaps, !cl_stainmaps.integer);
1535         else if (options_effects_cursor == optnum++) Cvar_SetValueQuick (&cl_stainmapsclearonload, !cl_stainmapsclearonload.integer);
1536         else if (options_effects_cursor == optnum++) Cvar_SetValueQuick (&cl_decals, !cl_decals.integer);
1537         else if (options_effects_cursor == optnum++) Cvar_SetValueQuick (&r_detailtextures, !r_detailtextures.integer);
1538         else if (options_effects_cursor == optnum++) Cvar_SetValueQuick (&cl_particles_bulletimpacts, !cl_particles_bulletimpacts.integer);
1539         else if (options_effects_cursor == optnum++) Cvar_SetValueQuick (&cl_particles_smoke, !cl_particles_smoke.integer);
1540         else if (options_effects_cursor == optnum++) Cvar_SetValueQuick (&cl_particles_sparks, !cl_particles_sparks.integer);
1541         else if (options_effects_cursor == optnum++) Cvar_SetValueQuick (&cl_particles_bubbles, !cl_particles_bubbles.integer);
1542         else if (options_effects_cursor == optnum++) Cvar_SetValueQuick (&cl_particles_blood, !cl_particles_blood.integer);
1543         else if (options_effects_cursor == optnum++) Cvar_SetValueQuick (&cl_particles_blood_alpha, bound(0.2, cl_particles_blood_alpha.value + dir * 0.1, 1));
1544         else if (options_effects_cursor == optnum++) Cvar_SetValueQuick (&cl_particles_blood_bloodhack, !cl_particles_blood_bloodhack.integer);
1545         else if (options_effects_cursor == optnum++) Cvar_SetValueQuick (&cl_beams_polygons, !cl_beams_polygons.integer);
1546         else if (options_effects_cursor == optnum++) Cvar_SetValueQuick (&cl_beams_relative, !cl_beams_relative.integer);
1547         else if (options_effects_cursor == optnum++) Cvar_SetValueQuick (&cl_beams_lightatend, !cl_beams_lightatend.integer);
1548         else if (options_effects_cursor == optnum++) Cvar_SetValueQuick (&r_lightningbeam_thickness, bound(1, r_lightningbeam_thickness.integer + dir, 10));
1549         else if (options_effects_cursor == optnum++) Cvar_SetValueQuick (&r_lightningbeam_scroll, bound(0, r_lightningbeam_scroll.integer + dir, 10));
1550         else if (options_effects_cursor == optnum++) Cvar_SetValueQuick (&r_lightningbeam_repeatdistance, bound(64, r_lightningbeam_repeatdistance.integer + dir * 64, 1024));
1551         else if (options_effects_cursor == optnum++) Cvar_SetValueQuick (&r_lightningbeam_color_red, bound(0, r_lightningbeam_color_red.value + dir * 0.1, 1));
1552         else if (options_effects_cursor == optnum++) Cvar_SetValueQuick (&r_lightningbeam_color_green, bound(0, r_lightningbeam_color_green.value + dir * 0.1, 1));
1553         else if (options_effects_cursor == optnum++) Cvar_SetValueQuick (&r_lightningbeam_color_blue, bound(0, r_lightningbeam_color_blue.value + dir * 0.1, 1));
1554         else if (options_effects_cursor == optnum++) Cvar_SetValueQuick (&r_lightningbeam_qmbtexture, !r_lightningbeam_qmbtexture.integer);
1555         else if (options_effects_cursor == optnum++) Cvar_SetValueQuick (&r_lerpmodels, !r_lerpmodels.integer);
1556         else if (options_effects_cursor == optnum++) Cvar_SetValueQuick (&r_lerpsprites, !r_lerpsprites.integer);
1557         else if (options_effects_cursor == optnum++) Cvar_SetValueQuick (&gl_polyblend, bound(0, gl_polyblend.value + dir * 0.1, 1));
1558         else if (options_effects_cursor == optnum++) Cvar_SetValueQuick (&r_skyscroll1, bound(-8, r_skyscroll1.value + dir * 0.1, 8));
1559         else if (options_effects_cursor == optnum++) Cvar_SetValueQuick (&r_skyscroll2, bound(-8, r_skyscroll2.value + dir * 0.1, 8));
1560         else if (options_effects_cursor == optnum++) Cvar_SetValueQuick (&r_waterwarp, bound(0, r_waterwarp.value + dir * 0.1, 1));
1561         else if (options_effects_cursor == optnum++) Cvar_SetValueQuick (&r_wateralpha, bound(0, r_wateralpha.value + dir * 0.1, 1));
1562         else if (options_effects_cursor == optnum++) Cvar_SetValueQuick (&r_waterscroll, bound(0, r_waterscroll.value + dir * 0.5, 10));
1563         else if (options_effects_cursor == optnum++) Cvar_SetValueQuick (&r_watershader, bound(0, r_watershader.value + dir * 0.25, 10));
1564 }
1565
1566 void M_Options_Effects_Draw (void)
1567 {
1568         int visible;
1569         cachepic_t      *p;
1570
1571         M_Background(320, 200);
1572
1573         M_DrawPic(16, 4, "gfx/qplaque.lmp");
1574         p = Draw_CachePic("gfx/p_option.lmp");
1575         M_DrawPic((320-p->width)/2, 4, "gfx/p_option.lmp");
1576
1577         optcursor = options_effects_cursor;
1578         optnum = 0;
1579         visible = (vid.conheight - 32) / 8;
1580         opty = 32 - bound(0, optcursor - (visible >> 1), max(0, OPTIONS_EFFECTS_ITEMS - visible)) * 8;
1581
1582         M_Options_PrintSlider(  "      Lights Per Model", true, r_modellights.value, 0, 8);
1583         M_Options_PrintSlider(  "      Corona Intensity", true, r_coronas.value, 0, 4);
1584         M_Options_PrintCheckbox("      Use Only Coronas", true, gl_flashblend.integer);
1585         M_Options_PrintCheckbox("             Particles", true, cl_particles.integer);
1586         M_Options_PrintSlider(  "     Particles Quality", true, cl_particles_quality.value, 1, 4);
1587         M_Options_PrintCheckbox("       Explosion Shell", true, cl_particles_explosions_shell.integer);
1588         M_Options_PrintCheckbox("  Explosion Shell Clip", true, r_explosionclip.integer);
1589         M_Options_PrintCheckbox("             Stainmaps", true, cl_stainmaps.integer);
1590         M_Options_PrintCheckbox("Onload Clear Stainmaps", true, cl_stainmapsclearonload.integer);
1591         M_Options_PrintCheckbox("                Decals", true, cl_decals.integer);
1592         M_Options_PrintCheckbox("      Detail Texturing", true, r_detailtextures.integer);
1593         M_Options_PrintCheckbox("        Bullet Impacts", true, cl_particles_bulletimpacts.integer);
1594         M_Options_PrintCheckbox("                 Smoke", true, cl_particles_smoke.integer);
1595         M_Options_PrintCheckbox("                Sparks", true, cl_particles_sparks.integer);
1596         M_Options_PrintCheckbox("               Bubbles", true, cl_particles_bubbles.integer);
1597         M_Options_PrintCheckbox("                 Blood", true, cl_particles_blood.integer);
1598         M_Options_PrintSlider(  "         Blood Opacity", true, cl_particles_blood_alpha.value, 0.2, 1);
1599         M_Options_PrintCheckbox("Force New Blood Effect", true, cl_particles_blood_bloodhack.integer);
1600         M_Options_PrintCheckbox("    Lightning Polygons", true, cl_beams_polygons.integer);
1601         M_Options_PrintCheckbox("Lightning Smooth Sweep", true, cl_beams_relative.integer);
1602         M_Options_PrintCheckbox("   Lightning End Light", true, cl_beams_lightatend.integer);
1603         M_Options_PrintSlider(  "   Lightning Thickness", cl_beams_polygons.integer, r_lightningbeam_thickness.integer, 1, 10);
1604         M_Options_PrintSlider(  "      Lightning Scroll", cl_beams_polygons.integer, r_lightningbeam_scroll.integer, 0, 10);
1605         M_Options_PrintSlider(  " Lightning Repeat Dist", cl_beams_polygons.integer, r_lightningbeam_repeatdistance.integer, 64, 1024);
1606         M_Options_PrintSlider(  "   Lightning Color Red", cl_beams_polygons.integer, r_lightningbeam_color_red.value, 0, 1);
1607         M_Options_PrintSlider(  " Lightning Color Green", cl_beams_polygons.integer, r_lightningbeam_color_green.value, 0, 1);
1608         M_Options_PrintSlider(  "  Lightning Color Blue", cl_beams_polygons.integer, r_lightningbeam_color_blue.value, 0, 1);
1609         M_Options_PrintCheckbox(" Lightning QMB Texture", cl_beams_polygons.integer, r_lightningbeam_qmbtexture.integer);
1610         M_Options_PrintCheckbox("   Model Interpolation", true, r_lerpmodels.integer);
1611         M_Options_PrintCheckbox("  Sprite Interpolation", true, r_lerpsprites.integer);
1612         M_Options_PrintSlider(  "            View Blend", true, gl_polyblend.value, 0, 1);
1613         M_Options_PrintSlider(  "Upper Sky Scroll Speed", true, r_skyscroll1.value, -8, 8);
1614         M_Options_PrintSlider(  "Lower Sky Scroll Speed", true, r_skyscroll2.value, -8, 8);
1615         M_Options_PrintSlider(  "  Underwater View Warp", true, r_waterwarp.value, 0, 1);
1616         M_Options_PrintSlider(  " Water Alpha (opacity)", true, r_wateralpha.value, 0, 1);
1617         M_Options_PrintSlider(  "        Water Movement", true, r_waterscroll.value, 0, 10);
1618         M_Options_PrintSlider(  " GeForce3 Water Shader", true, r_watershader.value, 0, 10);
1619 }
1620
1621
1622 void M_Options_Effects_Key (int k, char ascii)
1623 {
1624         switch (k)
1625         {
1626         case K_ESCAPE:
1627                 M_Menu_Options_f ();
1628                 break;
1629
1630         case K_ENTER:
1631                 M_Menu_Options_Effects_AdjustSliders (1);
1632                 break;
1633
1634         case K_UPARROW:
1635                 S_LocalSound ("sound/misc/menu1.wav");
1636                 options_effects_cursor--;
1637                 if (options_effects_cursor < 0)
1638                         options_effects_cursor = OPTIONS_EFFECTS_ITEMS-1;
1639                 break;
1640
1641         case K_DOWNARROW:
1642                 S_LocalSound ("sound/misc/menu1.wav");
1643                 options_effects_cursor++;
1644                 if (options_effects_cursor >= OPTIONS_EFFECTS_ITEMS)
1645                         options_effects_cursor = 0;
1646                 break;
1647
1648         case K_LEFTARROW:
1649                 M_Menu_Options_Effects_AdjustSliders (-1);
1650                 break;
1651
1652         case K_RIGHTARROW:
1653                 M_Menu_Options_Effects_AdjustSliders (1);
1654                 break;
1655         }
1656 }
1657
1658
1659 #define OPTIONS_GRAPHICS_ITEMS  7
1660
1661 int options_graphics_cursor;
1662
1663 void M_Menu_Options_Graphics_f (void)
1664 {
1665         key_dest = key_menu;
1666         m_state = m_options_graphics;
1667         m_entersound = true;
1668 }
1669
1670 extern cvar_t r_shadow_gloss;
1671 extern cvar_t r_shadow_realtime_dlight;
1672 extern cvar_t r_shadow_realtime_dlight_shadows;
1673 extern cvar_t r_shadow_realtime_world;
1674 extern cvar_t r_shadow_realtime_world_dlightshadows;
1675 extern cvar_t r_shadow_realtime_world_lightmaps;
1676 extern cvar_t r_shadow_realtime_world_shadows;
1677
1678 void M_Menu_Options_Graphics_AdjustSliders (int dir)
1679 {
1680         int optnum;
1681         S_LocalSound ("sound/misc/menu3.wav");
1682  
1683         optnum = 0;
1684
1685                  if (options_graphics_cursor == optnum++) Cvar_SetValueQuick (&r_shadow_gloss,                                                  bound(0, r_shadow_gloss.integer + dir, 2));
1686         else if (options_graphics_cursor == optnum++) Cvar_SetValueQuick (&r_shadow_realtime_dlight,                            !r_shadow_realtime_dlight.integer);
1687         else if (options_graphics_cursor == optnum++) Cvar_SetValueQuick (&r_shadow_realtime_dlight_shadows,            !r_shadow_realtime_dlight_shadows.integer);
1688         else if (options_graphics_cursor == optnum++) Cvar_SetValueQuick (&r_shadow_realtime_world,                                     !r_shadow_realtime_world.integer);
1689         else if (options_graphics_cursor == optnum++) Cvar_SetValueQuick (&r_shadow_realtime_world_dlightshadows,       !r_shadow_realtime_world_dlightshadows.integer);
1690         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));
1691         else if (options_graphics_cursor == optnum++) Cvar_SetValueQuick (&r_shadow_realtime_world_shadows,                     !r_shadow_realtime_world_shadows.integer);
1692 }
1693
1694
1695 void M_Options_Graphics_Draw (void)
1696 {
1697         int visible;
1698         cachepic_t      *p;
1699
1700         M_Background(320, 200);
1701
1702         M_DrawPic(16, 4, "gfx/qplaque.lmp");
1703         p = Draw_CachePic("gfx/p_option.lmp");
1704         M_DrawPic((320-p->width)/2, 4, "gfx/p_option.lmp");
1705
1706         optcursor = options_graphics_cursor;
1707         optnum = 0;
1708         visible = (vid.conheight - 32) / 8;
1709         opty = 32 - bound(0, optcursor - (visible >> 1), max(0, OPTIONS_GRAPHICS_ITEMS - visible)) * 8;
1710
1711         M_Options_PrintSlider(  "             Gloss Mode", true, r_shadow_gloss.integer, 0, 2);
1712         M_Options_PrintCheckbox("             RT DLights", true, r_shadow_realtime_dlight.integer);
1713         M_Options_PrintCheckbox("      RT DLight Shadows", true, r_shadow_realtime_dlight_shadows.integer);
1714         M_Options_PrintCheckbox("               RT World", true, r_shadow_realtime_world.integer);
1715         M_Options_PrintCheckbox("RT World DLight Shadows", true, r_shadow_realtime_world_dlightshadows.integer);
1716         M_Options_PrintSlider(  "     RT World Lightmaps", true, r_shadow_realtime_world_lightmaps.value, 0, 1);
1717         M_Options_PrintCheckbox("        RT World Shadow", true, r_shadow_realtime_world_shadows.integer);
1718 }
1719
1720
1721 void M_Options_Graphics_Key (int k, char ascii)
1722 {
1723         switch (k)
1724         {
1725         case K_ESCAPE:
1726                 M_Menu_Options_f ();
1727                 break;
1728
1729         case K_ENTER:
1730                 M_Menu_Options_Graphics_AdjustSliders (1);
1731                 break;
1732
1733         case K_UPARROW:
1734                 S_LocalSound ("sound/misc/menu1.wav");
1735                 options_graphics_cursor--;
1736                 if (options_graphics_cursor < 0)
1737                         options_graphics_cursor = OPTIONS_GRAPHICS_ITEMS-1;
1738                 break;
1739
1740         case K_DOWNARROW:
1741                 S_LocalSound ("sound/misc/menu1.wav");
1742                 options_graphics_cursor++;
1743                 if (options_graphics_cursor >= OPTIONS_GRAPHICS_ITEMS)
1744                         options_graphics_cursor = 0;
1745                 break;
1746
1747         case K_LEFTARROW:
1748                 M_Menu_Options_Graphics_AdjustSliders (-1);
1749                 break;
1750
1751         case K_RIGHTARROW:
1752                 M_Menu_Options_Graphics_AdjustSliders (1);
1753                 break;
1754         }
1755 }
1756
1757
1758 #define OPTIONS_COLORCONTROL_ITEMS      18
1759
1760 int             options_colorcontrol_cursor;
1761
1762 // intensity value to match up to 50% dither to 'correct' quake
1763 cvar_t menu_options_colorcontrol_correctionvalue = {0, "menu_options_colorcontrol_correctionvalue", "0.25"};
1764
1765 void M_Menu_Options_ColorControl_f (void)
1766 {
1767         key_dest = key_menu;
1768         m_state = m_options_colorcontrol;
1769         m_entersound = true;
1770 }
1771
1772
1773 void M_Menu_Options_ColorControl_AdjustSliders (int dir)
1774 {
1775         int optnum;
1776         float f;
1777         S_LocalSound ("sound/misc/menu3.wav");
1778
1779         optnum = 1;
1780         if (options_colorcontrol_cursor == optnum++)
1781                 Cvar_SetValueQuick (&v_hwgamma, !v_hwgamma.integer);
1782         else if (options_colorcontrol_cursor == optnum++)
1783         {
1784                 Cvar_SetValueQuick (&v_color_enable, 0);
1785                 Cvar_SetValueQuick (&v_gamma, bound(1, v_gamma.value + dir * 0.125, 5));
1786         }
1787         else if (options_colorcontrol_cursor == optnum++)
1788         {
1789                 Cvar_SetValueQuick (&v_color_enable, 0);
1790                 Cvar_SetValueQuick (&v_contrast, bound(1, v_contrast.value + dir * 0.125, 5));
1791         }
1792         else if (options_colorcontrol_cursor == optnum++)
1793         {
1794                 Cvar_SetValueQuick (&v_color_enable, 0);
1795                 Cvar_SetValueQuick (&v_brightness, bound(0, v_brightness.value + dir * 0.05, 0.8));
1796         }
1797         else if (options_colorcontrol_cursor == optnum++)
1798         {
1799                 Cvar_SetValueQuick (&v_color_enable, !v_color_enable.integer);
1800         }
1801         else if (options_colorcontrol_cursor == optnum++)
1802         {
1803                 Cvar_SetValueQuick (&v_color_enable, 1);
1804                 Cvar_SetValueQuick (&v_color_black_r, bound(0, v_color_black_r.value + dir * 0.0125, 0.8));
1805         }
1806         else if (options_colorcontrol_cursor == optnum++)
1807         {
1808                 Cvar_SetValueQuick (&v_color_enable, 1);
1809                 Cvar_SetValueQuick (&v_color_black_g, bound(0, v_color_black_g.value + dir * 0.0125, 0.8));
1810         }
1811         else if (options_colorcontrol_cursor == optnum++)
1812         {
1813                 Cvar_SetValueQuick (&v_color_enable, 1);
1814                 Cvar_SetValueQuick (&v_color_black_b, bound(0, v_color_black_b.value + dir * 0.0125, 0.8));
1815         }
1816         else if (options_colorcontrol_cursor == optnum++)
1817         {
1818                 Cvar_SetValueQuick (&v_color_enable, 1);
1819                 f = bound(0, (v_color_black_r.value + v_color_black_g.value + v_color_black_b.value) / 3 + dir * 0.0125, 0.8);
1820                 Cvar_SetValueQuick (&v_color_black_r, f);
1821                 Cvar_SetValueQuick (&v_color_black_g, f);
1822                 Cvar_SetValueQuick (&v_color_black_b, f);
1823         }
1824         else if (options_colorcontrol_cursor == optnum++)
1825         {
1826                 Cvar_SetValueQuick (&v_color_enable, 1);
1827                 Cvar_SetValueQuick (&v_color_grey_r, bound(0, v_color_grey_r.value + dir * 0.0125, 0.95));
1828         }
1829         else if (options_colorcontrol_cursor == optnum++)
1830         {
1831                 Cvar_SetValueQuick (&v_color_enable, 1);
1832                 Cvar_SetValueQuick (&v_color_grey_g, bound(0, v_color_grey_g.value + dir * 0.0125, 0.95));
1833         }
1834         else if (options_colorcontrol_cursor == optnum++)
1835         {
1836                 Cvar_SetValueQuick (&v_color_enable, 1);
1837                 Cvar_SetValueQuick (&v_color_grey_b, bound(0, v_color_grey_b.value + dir * 0.0125, 0.95));
1838         }
1839         else if (options_colorcontrol_cursor == optnum++)
1840         {
1841                 Cvar_SetValueQuick (&v_color_enable, 1);
1842                 f = bound(0, (v_color_grey_r.value + v_color_grey_g.value + v_color_grey_b.value) / 3 + dir * 0.0125, 0.95);
1843                 Cvar_SetValueQuick (&v_color_grey_r, f);
1844                 Cvar_SetValueQuick (&v_color_grey_g, f);
1845                 Cvar_SetValueQuick (&v_color_grey_b, f);
1846         }
1847         else if (options_colorcontrol_cursor == optnum++)
1848         {
1849                 Cvar_SetValueQuick (&v_color_enable, 1);
1850                 Cvar_SetValueQuick (&v_color_white_r, bound(1, v_color_white_r.value + dir * 0.125, 5));
1851         }
1852         else if (options_colorcontrol_cursor == optnum++)
1853         {
1854                 Cvar_SetValueQuick (&v_color_enable, 1);
1855                 Cvar_SetValueQuick (&v_color_white_g, bound(1, v_color_white_g.value + dir * 0.125, 5));
1856         }
1857         else if (options_colorcontrol_cursor == optnum++)
1858         {
1859                 Cvar_SetValueQuick (&v_color_enable, 1);
1860                 Cvar_SetValueQuick (&v_color_white_b, bound(1, v_color_white_b.value + dir * 0.125, 5));
1861         }
1862         else if (options_colorcontrol_cursor == optnum++)
1863         {
1864                 Cvar_SetValueQuick (&v_color_enable, 1);
1865                 f = bound(1, (v_color_white_r.value + v_color_white_g.value + v_color_white_b.value) / 3 + dir * 0.125, 5);
1866                 Cvar_SetValueQuick (&v_color_white_r, f);
1867                 Cvar_SetValueQuick (&v_color_white_g, f);
1868                 Cvar_SetValueQuick (&v_color_white_b, f);
1869         }
1870 }
1871
1872 void M_Options_ColorControl_Draw (void)
1873 {
1874         int visible;
1875         float x, c, s, t, u, v;
1876         cachepic_t      *p;
1877
1878         M_Background(320, 256);
1879
1880         M_DrawPic(16, 4, "gfx/qplaque.lmp");
1881         p = Draw_CachePic("gfx/p_option.lmp");
1882         M_DrawPic((320-p->width)/2, 4, "gfx/p_option.lmp");
1883
1884         optcursor = options_colorcontrol_cursor;
1885         optnum = 0;
1886         visible = (vid.conheight - 32) / 8;
1887         opty = 32 - bound(0, optcursor - (visible >> 1), max(0, OPTIONS_COLORCONTROL_ITEMS - visible)) * 8;
1888
1889         M_Options_PrintCommand( "     Reset to defaults", true);
1890         M_Options_PrintCheckbox("Hardware Gamma Control", vid_hardwaregammasupported.integer, v_hwgamma.integer);
1891         M_Options_PrintSlider(  "                 Gamma", !v_color_enable.integer && vid_hardwaregammasupported.integer && v_hwgamma.integer, v_gamma.value, 1, 5);
1892         M_Options_PrintSlider(  "              Contrast", !v_color_enable.integer, v_contrast.value, 1, 5);
1893         M_Options_PrintSlider(  "            Brightness", !v_color_enable.integer, v_brightness.value, 0, 0.8);
1894         M_Options_PrintCheckbox("  Color Level Controls", true, v_color_enable.integer);
1895         M_Options_PrintSlider(  "          Black: Red  ", v_color_enable.integer, v_color_black_r.value, 0, 0.8);
1896         M_Options_PrintSlider(  "          Black: Green", v_color_enable.integer, v_color_black_g.value, 0, 0.8);
1897         M_Options_PrintSlider(  "          Black: Blue ", v_color_enable.integer, v_color_black_b.value, 0, 0.8);
1898         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);
1899         M_Options_PrintSlider(  "           Grey: Red  ", v_color_enable.integer && vid_hardwaregammasupported.integer && v_hwgamma.integer, v_color_grey_r.value, 0, 0.95);
1900         M_Options_PrintSlider(  "           Grey: Green", v_color_enable.integer && vid_hardwaregammasupported.integer && v_hwgamma.integer, v_color_grey_g.value, 0, 0.95);
1901         M_Options_PrintSlider(  "           Grey: Blue ", v_color_enable.integer && vid_hardwaregammasupported.integer && v_hwgamma.integer, v_color_grey_b.value, 0, 0.95);
1902         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);
1903         M_Options_PrintSlider(  "          White: Red  ", v_color_enable.integer, v_color_white_r.value, 1, 5);
1904         M_Options_PrintSlider(  "          White: Green", v_color_enable.integer, v_color_white_g.value, 1, 5);
1905         M_Options_PrintSlider(  "          White: Blue ", v_color_enable.integer, v_color_white_b.value, 1, 5);
1906         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);
1907
1908         opty += 4;
1909         DrawQ_Fill(menu_x, menu_y + opty, 320, 4 + 64 + 8 + 64 + 4, 0, 0, 0, 1, 0);opty += 4;
1910         s = (float) 312 / 2 * vid.realwidth / vid.conwidth;
1911         t = (float) 4 / 2 * vid.realheight / vid.conheight;
1912         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;
1913         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;
1914         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;
1915         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;
1916         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;
1917         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;
1918         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;
1919         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;
1920
1921         c = menu_options_colorcontrol_correctionvalue.value; // intensity value that should be matched up to a 50% dither to 'correct' quake
1922         s = (float) 48 / 2 * vid.realwidth / vid.conwidth;
1923         t = (float) 48 / 2 * vid.realheight / vid.conheight;
1924         u = s * 0.5;
1925         v = t * 0.5;
1926         opty += 8;
1927         x = 4;
1928         DrawQ_Fill(menu_x + x, menu_y + opty, 64, 48, c, 0, 0, 1, 0);
1929         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);
1930         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);
1931         x += 80;
1932         DrawQ_Fill(menu_x + x, menu_y + opty, 64, 48, 0, c, 0, 1, 0);
1933         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);
1934         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);
1935         x += 80;
1936         DrawQ_Fill(menu_x + x, menu_y + opty, 64, 48, 0, 0, c, 1, 0);
1937         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);
1938         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);
1939         x += 80;
1940         DrawQ_Fill(menu_x + x, menu_y + opty, 64, 48, c, c, c, 1, 0);
1941         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);
1942         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);
1943 }
1944
1945
1946 void M_Options_ColorControl_Key (int k, char ascii)
1947 {
1948         switch (k)
1949         {
1950         case K_ESCAPE:
1951                 M_Menu_Options_f ();
1952                 break;
1953
1954         case K_ENTER:
1955                 m_entersound = true;
1956                 switch (options_colorcontrol_cursor)
1957                 {
1958                 case 0:
1959                         Cvar_SetValueQuick(&v_hwgamma, 1);
1960                         Cvar_SetValueQuick(&v_gamma, 1);
1961                         Cvar_SetValueQuick(&v_contrast, 1);
1962                         Cvar_SetValueQuick(&v_brightness, 0);
1963                         Cvar_SetValueQuick(&v_color_enable, 0);
1964                         Cvar_SetValueQuick(&v_color_black_r, 0);
1965                         Cvar_SetValueQuick(&v_color_black_g, 0);
1966                         Cvar_SetValueQuick(&v_color_black_b, 0);
1967                         Cvar_SetValueQuick(&v_color_grey_r, 0);
1968                         Cvar_SetValueQuick(&v_color_grey_g, 0);
1969                         Cvar_SetValueQuick(&v_color_grey_b, 0);
1970                         Cvar_SetValueQuick(&v_color_white_r, 1);
1971                         Cvar_SetValueQuick(&v_color_white_g, 1);
1972                         Cvar_SetValueQuick(&v_color_white_b, 1);
1973                         break;
1974                 default:
1975                         M_Menu_Options_ColorControl_AdjustSliders (1);
1976                         break;
1977                 }
1978                 return;
1979
1980         case K_UPARROW:
1981                 S_LocalSound ("sound/misc/menu1.wav");
1982                 options_colorcontrol_cursor--;
1983                 if (options_colorcontrol_cursor < 0)
1984                         options_colorcontrol_cursor = OPTIONS_COLORCONTROL_ITEMS-1;
1985                 break;
1986
1987         case K_DOWNARROW:
1988                 S_LocalSound ("sound/misc/menu1.wav");
1989                 options_colorcontrol_cursor++;
1990                 if (options_colorcontrol_cursor >= OPTIONS_COLORCONTROL_ITEMS)
1991                         options_colorcontrol_cursor = 0;
1992                 break;
1993
1994         case K_LEFTARROW:
1995                 M_Menu_Options_ColorControl_AdjustSliders (-1);
1996                 break;
1997
1998         case K_RIGHTARROW:
1999                 M_Menu_Options_ColorControl_AdjustSliders (1);
2000                 break;
2001         }
2002 }
2003
2004
2005 //=============================================================================
2006 /* KEYS MENU */
2007
2008 char *quakebindnames[][2] =
2009 {
2010 {"+attack",             "attack"},
2011 {"impulse 10",          "next weapon"},
2012 {"impulse 12",          "previous weapon"},
2013 {"+jump",                       "jump / swim up"},
2014 {"+forward",            "walk forward"},
2015 {"+back",                       "backpedal"},
2016 {"+left",                       "turn left"},
2017 {"+right",                      "turn right"},
2018 {"+speed",                      "run"},
2019 {"+moveleft",           "step left"},
2020 {"+moveright",          "step right"},
2021 {"+strafe",             "sidestep"},
2022 {"+lookup",             "look up"},
2023 {"+lookdown",           "look down"},
2024 {"centerview",          "center view"},
2025 {"+mlook",                      "mouse look"},
2026 {"+klook",                      "keyboard look"},
2027 {"+moveup",                     "swim up"},
2028 {"+movedown",           "swim down"}
2029 };
2030
2031 char *transfusionbindnames[][2] =
2032 {
2033 {"",                            "Movement"},            // Movement commands
2034 {"+forward",            "walk forward"},
2035 {"+back",                       "backpedal"},
2036 {"+left",                       "turn left"},
2037 {"+right",                      "turn right"},
2038 {"+moveleft",           "step left"},
2039 {"+moveright",          "step right"},
2040 {"+jump",                       "jump / swim up"},
2041 {"+movedown",           "swim down"},
2042 {"",                            "Combat"},                      // Combat commands
2043 {"impulse 1",           "Pitch Fork"},
2044 {"impulse 2",           "Flare Gun"},
2045 {"impulse 3",           "Shotgun"},
2046 {"impulse 4",           "Machine Gun"},
2047 {"impulse 5",           "Incinerator"},
2048 {"impulse 6",           "Bombs (TNT)"},
2049 {"impulse 35",          "Proximity Bomb"},
2050 {"impulse 36",          "Remote Detonator"},
2051 {"impulse 7",           "Aerosol Can"},
2052 {"impulse 8",           "Tesla Cannon"},
2053 {"impulse 9",           "Life Leech"},
2054 {"impulse 10",          "Voodoo Doll"},
2055 {"impulse 21",          "next weapon"},
2056 {"impulse 22",          "previous weapon"},
2057 {"+attack",             "attack"},
2058 {"+button3",            "altfire"},
2059 {"",                            "Inventory"},           // Inventory commands
2060 {"impulse 40",          "Dr.'s Bag"},
2061 {"impulse 41",          "Crystal Ball"},
2062 {"impulse 42",          "Beast Vision"},
2063 {"impulse 43",          "Jump Boots"},
2064 {"impulse 23",          "next item"},
2065 {"impulse 24",          "previous item"},
2066 {"impulse 25",          "use item"},
2067 {"",                            "Misc"},                        // Misc commands
2068 {"+button4",            "use"},
2069 {"impulse 50",          "add bot (red)"},
2070 {"impulse 51",          "add bot (blue)"},
2071 {"impulse 52",          "kick a bot"},
2072 {"impulse 26",          "next armor type"},
2073 {"impulse 27",          "identify player"},
2074 {"impulse 55",          "voting menu"},
2075 {"impulse 56",          "observer mode"},
2076 {"",                            "Taunts"},            // Taunts
2077 {"impulse 70",          "taunt 0"},
2078 {"impulse 71",          "taunt 1"},
2079 {"impulse 72",          "taunt 2"},
2080 {"impulse 73",          "taunt 3"},
2081 {"impulse 74",          "taunt 4"},
2082 {"impulse 75",          "taunt 5"},
2083 {"impulse 76",          "taunt 6"},
2084 {"impulse 77",          "taunt 7"},
2085 {"impulse 78",          "taunt 8"},
2086 {"impulse 79",          "taunt 9"}
2087 };
2088
2089 char *goodvsbad2bindnames[][2] =
2090 {
2091 {"impulse 69",          "Power 1"},
2092 {"impulse 70",          "Power 2"},
2093 {"impulse 71",          "Power 3"},
2094 {"+jump",                       "jump / swim up"},
2095 {"+forward",            "walk forward"},
2096 {"+back",                       "backpedal"},
2097 {"+left",                       "turn left"},
2098 {"+right",                      "turn right"},
2099 {"+speed",                      "run"},
2100 {"+moveleft",           "step left"},
2101 {"+moveright",          "step right"},
2102 {"+strafe",             "sidestep"},
2103 {"+lookup",             "look up"},
2104 {"+lookdown",           "look down"},
2105 {"centerview",          "center view"},
2106 {"+mlook",                      "mouse look"},
2107 {"kill",                        "kill yourself"},
2108 {"+moveup",                     "swim up"},
2109 {"+movedown",           "swim down"}
2110 };
2111
2112 int numcommands;
2113 char *(*bindnames)[2];
2114
2115 /*
2116 typedef struct binditem_s
2117 {
2118         char *command, *description;
2119         struct binditem_s *next;
2120 }
2121 binditem_t;
2122
2123 typedef struct bindcategory_s
2124 {
2125         char *name;
2126         binditem_t *binds;
2127         struct bindcategory_s *next;
2128 }
2129 bindcategory_t;
2130
2131 bindcategory_t *bindcategories = NULL;
2132
2133 void M_ClearBinds (void)
2134 {
2135         for (c = bindcategories;c;c = cnext)
2136         {
2137                 cnext = c->next;
2138                 for (b = c->binds;b;b = bnext)
2139                 {
2140                         bnext = b->next;
2141                         Z_Free(b);
2142                 }
2143                 Z_Free(c);
2144         }
2145         bindcategories = NULL;
2146 }
2147
2148 void M_AddBindToCategory(bindcategory_t *c, char *command, char *description)
2149 {
2150         for (b = &c->binds;*b;*b = &(*b)->next);
2151         *b = Z_Alloc(sizeof(binditem_t) + strlen(command) + 1 + strlen(description) + 1);
2152         *b->command = (char *)((*b) + 1);
2153         *b->description = *b->command + strlen(command) + 1;
2154         strcpy(*b->command, command);
2155         strcpy(*b->description, description);
2156 }
2157
2158 void M_AddBind (char *category, char *command, char *description)
2159 {
2160         for (c = &bindcategories;*c;c = &(*c)->next)
2161         {
2162                 if (!strcmp(category, (*c)->name))
2163                 {
2164                         M_AddBindToCategory(*c, command, description);
2165                         return;
2166                 }
2167         }
2168         *c = Z_Alloc(sizeof(bindcategory_t));
2169         M_AddBindToCategory(*c, command, description);
2170 }
2171
2172 void M_DefaultBinds (void)
2173 {
2174         M_ClearBinds();
2175         M_AddBind("movement", "+jump", "jump / swim up");
2176         M_AddBind("movement", "+forward", "walk forward");
2177         M_AddBind("movement", "+back", "backpedal");
2178         M_AddBind("movement", "+left", "turn left");
2179         M_AddBind("movement", "+right", "turn right");
2180         M_AddBind("movement", "+speed", "run");
2181         M_AddBind("movement", "+moveleft", "step left");
2182         M_AddBind("movement", "+moveright", "step right");
2183         M_AddBind("movement", "+strafe", "sidestep");
2184         M_AddBind("movement", "+lookup", "look up");
2185         M_AddBind("movement", "+lookdown", "look down");
2186         M_AddBind("movement", "centerview", "center view");
2187         M_AddBind("movement", "+mlook", "mouse look");
2188         M_AddBind("movement", "+klook", "keyboard look");
2189         M_AddBind("movement", "+moveup", "swim up");
2190         M_AddBind("movement", "+movedown", "swim down");
2191         M_AddBind("weapons", "+attack", "attack");
2192         M_AddBind("weapons", "impulse 10", "next weapon");
2193         M_AddBind("weapons", "impulse 12", "previous weapon");
2194         M_AddBind("weapons", "impulse 1", "select weapon 1 (axe)");
2195         M_AddBind("weapons", "impulse 2", "select weapon 2 (shotgun)");
2196         M_AddBind("weapons", "impulse 3", "select weapon 3 (super )");
2197         M_AddBind("weapons", "impulse 4", "select weapon 4 (nailgun)");
2198         M_AddBind("weapons", "impulse 5", "select weapon 5 (super nailgun)");
2199         M_AddBind("weapons", "impulse 6", "select weapon 6 (grenade launcher)");
2200         M_AddBind("weapons", "impulse 7", "select weapon 7 (rocket launcher)");
2201         M_AddBind("weapons", "impulse 8", "select weapon 8 (lightning gun)");
2202 }
2203 */
2204
2205
2206 int             keys_cursor;
2207 int             bind_grab;
2208
2209 void M_Menu_Keys_f (void)
2210 {
2211         key_dest = key_menu;
2212         m_state = m_keys;
2213         m_entersound = true;
2214 }
2215
2216 #define NUMKEYS 5
2217
2218 void M_FindKeysForCommand (char *command, int *keys)
2219 {
2220         int             count;
2221         int             j;
2222         char    *b;
2223
2224         for (j = 0;j < NUMKEYS;j++)
2225                 keys[j] = -1;
2226
2227         count = 0;
2228
2229         for (j = 0; j < (int)sizeof (keybindings[0]) / (int)sizeof (keybindings[0][0]); j++)
2230         {
2231                 b = keybindings[0][j];
2232                 if (!b)
2233                         continue;
2234                 if (!strcmp (b, command) )
2235                 {
2236                         keys[count++] = j;
2237                         if (count == NUMKEYS)
2238                                 break;
2239                 }
2240         }
2241 }
2242
2243 void M_UnbindCommand (char *command)
2244 {
2245         int             j;
2246         char    *b;
2247
2248         for (j = 0; j < (int)sizeof (keybindings[0]) / (int)sizeof (keybindings[0][0]); j++)
2249         {
2250                 b = keybindings[0][j];
2251                 if (!b)
2252                         continue;
2253                 if (!strcmp (b, command))
2254                         Key_SetBinding (j, 0, "");
2255         }
2256 }
2257
2258
2259 void M_Keys_Draw (void)
2260 {
2261         int             i, j;
2262         int             keys[NUMKEYS];
2263         int             y;
2264         cachepic_t      *p;
2265         char    keystring[1024];
2266
2267         M_Background(320, 48 + 8 * numcommands);
2268
2269         p = Draw_CachePic ("gfx/ttl_cstm.lmp");
2270         M_DrawPic ( (320-p->width)/2, 4, "gfx/ttl_cstm.lmp");
2271
2272         if (bind_grab)
2273                 M_Print(12, 32, "Press a key or button for this action");
2274         else
2275                 M_Print(18, 32, "Enter to change, backspace to clear");
2276
2277 // search for known bindings
2278         for (i=0 ; i<numcommands ; i++)
2279         {
2280                 y = 48 + 8*i;
2281
2282                 // If there's no command, it's just a section
2283                 if (bindnames[i][0][0] == '\0')
2284                 {
2285                         M_PrintRed (4, y, "\x0D");  // #13 is the little arrow pointing to the right
2286                         M_PrintRed (16, y, bindnames[i][1]);
2287                         continue;
2288                 }
2289                 else
2290                         M_Print(16, y, bindnames[i][1]);
2291
2292                 M_FindKeysForCommand (bindnames[i][0], keys);
2293
2294                 // LordHavoc: redesigned to print more than 2 keys, inspired by Tomaz's MiniRacer
2295                 if (keys[0] == -1)
2296                         strcpy(keystring, "???");
2297                 else
2298                 {
2299                         keystring[0] = 0;
2300                         for (j = 0;j < NUMKEYS;j++)
2301                         {
2302                                 if (keys[j] != -1)
2303                                 {
2304                                         if (j > 0)
2305                                                 strcat(keystring, " or ");
2306                                         strcat(keystring, Key_KeynumToString (keys[j]));
2307                                 }
2308                         }
2309                 }
2310                 M_Print(150, y, keystring);
2311         }
2312
2313         if (bind_grab)
2314                 M_DrawCharacter (140, 48 + keys_cursor*8, '=');
2315         else
2316                 M_DrawCharacter (140, 48 + keys_cursor*8, 12+((int)(realtime*4)&1));
2317 }
2318
2319
2320 void M_Keys_Key (int k, char ascii)
2321 {
2322         char    cmd[80];
2323         int             keys[NUMKEYS];
2324
2325         if (bind_grab)
2326         {       // defining a key
2327                 S_LocalSound ("sound/misc/menu1.wav");
2328                 if (k == K_ESCAPE)
2329                 {
2330                         bind_grab = false;
2331                 }
2332                 else //if (k != '`')
2333                 {
2334                         sprintf (cmd, "bind \"%s\" \"%s\"\n", Key_KeynumToString (k), bindnames[keys_cursor][0]);
2335                         Cbuf_InsertText (cmd);
2336                 }
2337
2338                 bind_grab = false;
2339                 return;
2340         }
2341
2342         switch (k)
2343         {
2344         case K_ESCAPE:
2345                 M_Menu_Options_f ();
2346                 break;
2347
2348         case K_LEFTARROW:
2349         case K_UPARROW:
2350                 S_LocalSound ("sound/misc/menu1.wav");
2351                 do
2352                 {
2353                         keys_cursor--;
2354                         if (keys_cursor < 0)
2355                                 keys_cursor = numcommands-1;
2356                 }
2357                 while (bindnames[keys_cursor][0][0] == '\0');  // skip sections
2358                 break;
2359
2360         case K_DOWNARROW:
2361         case K_RIGHTARROW:
2362                 S_LocalSound ("sound/misc/menu1.wav");
2363                 do
2364                 {
2365                         keys_cursor++;
2366                         if (keys_cursor >= numcommands)
2367                                 keys_cursor = 0;
2368                 }
2369                 while (bindnames[keys_cursor][0][0] == '\0');  // skip sections
2370                 break;
2371
2372         case K_ENTER:           // go into bind mode
2373                 M_FindKeysForCommand (bindnames[keys_cursor][0], keys);
2374                 S_LocalSound ("sound/misc/menu2.wav");
2375                 if (keys[NUMKEYS - 1] != -1)
2376                         M_UnbindCommand (bindnames[keys_cursor][0]);
2377                 bind_grab = true;
2378                 break;
2379
2380         case K_BACKSPACE:               // delete bindings
2381         case K_DEL:                             // delete bindings
2382                 S_LocalSound ("sound/misc/menu2.wav");
2383                 M_UnbindCommand (bindnames[keys_cursor][0]);
2384                 break;
2385         }
2386 }
2387
2388 void M_Menu_Reset_f (void)
2389 {
2390         key_dest = key_menu;
2391         m_state = m_reset;
2392         m_entersound = true;
2393 }
2394
2395
2396 void M_Reset_Key (int key, char ascii)
2397 {
2398         switch (key)
2399         {
2400         case K_ESCAPE:
2401         case 'n':
2402         case 'N':
2403                 m_state = m_options;
2404                 m_entersound = true;
2405                 break;
2406
2407         case 'Y':
2408         case 'y':
2409                 Cbuf_AddText ("exec default.cfg\n");
2410                 break;
2411
2412         default:
2413                 break;
2414         }
2415 }
2416
2417 void M_Reset_Draw (void)
2418 {
2419         int lines = 2, linelength = 20;
2420         M_Background(linelength * 8 + 16, lines * 8 + 16);
2421         M_DrawTextBox(0, 0, linelength, lines);
2422         M_Print(8 + 4 * (linelength - 19),  8, "Really wanna reset?");
2423         M_Print(8 + 4 * (linelength - 11), 16, "Press y / n");
2424 }
2425
2426 //=============================================================================
2427 /* VIDEO MENU */
2428
2429 #define VIDEO_ITEMS 5
2430
2431 int video_cursor = 0;
2432 int video_cursor_table[] = {56, 68, 80, 100, 120};
2433 // note: if modes are added to the beginning of this list, update the
2434 // video_resolution = x; in M_Menu_Video_f below
2435 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}};
2436 // this is the number of the 640x480 mode in the list
2437 #define VID_640 3
2438 #define VID_RES_COUNT ((int)(sizeof(video_resolutions) / sizeof(video_resolutions[0])) - 1)
2439 int video_resolution;
2440
2441 extern int current_vid_fullscreen;
2442 extern int current_vid_width;
2443 extern int current_vid_height;
2444 extern int current_vid_bitsperpixel;
2445
2446
2447 void M_Menu_Video_f (void)
2448 {
2449         key_dest = key_menu;
2450         m_state = m_video;
2451         m_entersound = true;
2452
2453         // Look for the current resolution
2454         for (video_resolution = 0; video_resolution < VID_RES_COUNT; video_resolution++)
2455         {
2456                 if (video_resolutions[video_resolution][0] == current_vid_width &&
2457                         video_resolutions[video_resolution][1] == current_vid_height)
2458                         break;
2459         }
2460
2461         // Default to VID_640 if we didn't find it
2462         if (video_resolution == VID_RES_COUNT)
2463         {
2464                 // may need to update this number if mode list changes
2465                 video_resolution = VID_640;
2466                 Cvar_SetValueQuick (&vid_width, video_resolutions[video_resolution][0]);
2467                 Cvar_SetValueQuick (&vid_height, video_resolutions[video_resolution][1]);
2468         }
2469 }
2470
2471
2472 void M_Video_Draw (void)
2473 {
2474         cachepic_t      *p;
2475         const char* string;
2476
2477         M_Background(320, 200);
2478
2479         M_DrawPic(16, 4, "gfx/qplaque.lmp");
2480         p = Draw_CachePic("gfx/vidmodes.lmp");
2481         M_DrawPic((320-p->width)/2, 4, "gfx/vidmodes.lmp");
2482
2483         // Resolution
2484         M_Print(16, video_cursor_table[0], "            Resolution");
2485         string = va("%dx%d", video_resolutions[video_resolution][0], video_resolutions[video_resolution][1]);
2486         M_Print(220, video_cursor_table[0], string);
2487
2488         // Bits per pixel
2489         M_Print(16, video_cursor_table[1], "        Bits per pixel");
2490         M_Print(220, video_cursor_table[1], (vid_bitsperpixel.integer == 32) ? "32" : "16");
2491
2492         // Fullscreen
2493         M_Print(16, video_cursor_table[2], "            Fullscreen");
2494         M_DrawCheckbox(220, video_cursor_table[2], vid_fullscreen.integer);
2495
2496         // "Apply" button
2497         M_Print(220, video_cursor_table[3], "Apply");
2498
2499         // Vertical Sync
2500         M_ItemPrint (0, video_cursor_table[4], "         Vertical Sync", gl_videosyncavailable);
2501         M_DrawCheckbox(220, video_cursor_table[4], vid_vsync.integer);
2502
2503         // Cursor
2504         M_DrawCharacter(200, video_cursor_table[video_cursor], 12+((int)(realtime*4)&1));
2505 }
2506
2507
2508 void M_Menu_Video_AdjustSliders (int dir)
2509 {
2510         S_LocalSound ("sound/misc/menu3.wav");
2511
2512         switch (video_cursor)
2513         {
2514                 // Resolution
2515                 case 0:
2516                 {
2517                         int new_resolution = video_resolution + dir;
2518                         if (gamemode == GAME_FNIGGIUM ? new_resolution < VID_640 : new_resolution < 0)
2519                                 video_resolution = VID_RES_COUNT - 1;
2520                         else if (new_resolution > VID_RES_COUNT - 1)
2521                                 video_resolution = gamemode == GAME_FNIGGIUM ? VID_640 : 0;
2522                         else
2523                                 video_resolution = new_resolution;
2524
2525                         Cvar_SetValueQuick (&vid_width, video_resolutions[video_resolution][0]);
2526                         Cvar_SetValueQuick (&vid_height, video_resolutions[video_resolution][1]);
2527                         break;
2528                 }
2529
2530                 // Bits per pixel
2531                 case 1:
2532                         Cvar_SetValueQuick (&vid_bitsperpixel, (vid_bitsperpixel.integer == 32) ? 16 : 32);
2533                         break;
2534                 case 2:
2535                         Cvar_SetValueQuick (&vid_fullscreen, !vid_fullscreen.integer);
2536                         break;
2537
2538                 case 4:
2539                         Cvar_SetValueQuick (&vid_vsync, !vid_vsync.integer);
2540                         break;
2541         }
2542 }
2543
2544
2545 void M_Video_Key (int key, char ascii)
2546 {
2547         switch (key)
2548         {
2549                 case K_ESCAPE:
2550                         // vid_shared.c has a copy of the current video config. We restore it
2551                         Cvar_SetValueQuick(&vid_fullscreen, current_vid_fullscreen);
2552                         Cvar_SetValueQuick(&vid_width, current_vid_width);
2553                         Cvar_SetValueQuick(&vid_height, current_vid_height);
2554                         Cvar_SetValueQuick(&vid_bitsperpixel, current_vid_bitsperpixel);
2555
2556                         S_LocalSound ("sound/misc/menu1.wav");
2557                         M_Menu_Options_f ();
2558                         break;
2559
2560                 case K_ENTER:
2561                         m_entersound = true;
2562                         switch (video_cursor)
2563                         {
2564                                 case 3:
2565                                         Cbuf_AddText ("vid_restart\n");
2566                                         M_Menu_Options_f ();
2567                                         break;
2568                                 default:
2569                                         M_Menu_Video_AdjustSliders (1);
2570                         }
2571                         break;
2572
2573                 case K_UPARROW:
2574                         S_LocalSound ("sound/misc/menu1.wav");
2575                         video_cursor--;
2576                         if (video_cursor < 0)
2577                                 video_cursor = VIDEO_ITEMS-1;
2578                         break;
2579
2580                 case K_DOWNARROW:
2581                         S_LocalSound ("sound/misc/menu1.wav");
2582                         video_cursor++;
2583                         if (video_cursor >= VIDEO_ITEMS)
2584                                 video_cursor = 0;
2585                         break;
2586
2587                 case K_LEFTARROW:
2588                         M_Menu_Video_AdjustSliders (-1);
2589                         break;
2590
2591                 case K_RIGHTARROW:
2592                         M_Menu_Video_AdjustSliders (1);
2593                         break;
2594         }
2595 }
2596
2597 //=============================================================================
2598 /* HELP MENU */
2599
2600 int             help_page;
2601 #define NUM_HELP_PAGES  6
2602
2603
2604 void M_Menu_Help_f (void)
2605 {
2606         key_dest = key_menu;
2607         m_state = m_help;
2608         m_entersound = true;
2609         help_page = 0;
2610 }
2611
2612
2613
2614 void M_Help_Draw (void)
2615 {
2616         M_Background(320, 200);
2617         M_DrawPic (0, 0, va("gfx/help%i.lmp", help_page));
2618 }
2619
2620
2621 void M_Help_Key (int key, char ascii)
2622 {
2623         switch (key)
2624         {
2625         case K_ESCAPE:
2626                 M_Menu_Main_f ();
2627                 break;
2628
2629         case K_UPARROW:
2630         case K_RIGHTARROW:
2631                 m_entersound = true;
2632                 if (++help_page >= NUM_HELP_PAGES)
2633                         help_page = 0;
2634                 break;
2635
2636         case K_DOWNARROW:
2637         case K_LEFTARROW:
2638                 m_entersound = true;
2639                 if (--help_page < 0)
2640                         help_page = NUM_HELP_PAGES-1;
2641                 break;
2642         }
2643
2644 }
2645
2646 //=============================================================================
2647 /* QUIT MENU */
2648
2649 char *m_quit_message[9];
2650 int             m_quit_prevstate;
2651 qboolean        wasInMenus;
2652
2653
2654 int M_QuitMessage(char *line1, char *line2, char *line3, char *line4, char *line5, char *line6, char *line7, char *line8)
2655 {
2656         m_quit_message[0] = line1;
2657         m_quit_message[1] = line2;
2658         m_quit_message[2] = line3;
2659         m_quit_message[3] = line4;
2660         m_quit_message[4] = line5;
2661         m_quit_message[5] = line6;
2662         m_quit_message[6] = line7;
2663         m_quit_message[7] = line8;
2664         m_quit_message[8] = NULL;
2665         return 1;
2666 }
2667
2668 int M_ChooseQuitMessage(int request)
2669 {
2670         switch (gamemode)
2671         {
2672         case GAME_NORMAL:
2673         case GAME_HIPNOTIC:
2674         case GAME_ROGUE:
2675         case GAME_NEHAHRA:
2676                 if (request-- == 0) return M_QuitMessage("Are you gonna quit","this game just like","everything else?",NULL,NULL,NULL,NULL,NULL);
2677                 if (request-- == 0) return M_QuitMessage("Milord, methinks that","thou art a lowly","quitter. Is this true?",NULL,NULL,NULL,NULL,NULL);
2678                 if (request-- == 0) return M_QuitMessage("Do I need to bust your","face open for trying","to quit?",NULL,NULL,NULL,NULL,NULL);
2679                 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);
2680                 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);
2681                 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);
2682                 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);
2683                 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);
2684                 break;
2685         case GAME_GOODVSBAD2:
2686                 if (request-- == 0) return M_QuitMessage("Press Yes To Quit","...","Yes",NULL,NULL,NULL,NULL,NULL);
2687                 if (request-- == 0) return M_QuitMessage("Do you really want to","Quit?","Play Good vs bad 3!",NULL,NULL,NULL,NULL,NULL);
2688                 if (request-- == 0) return M_QuitMessage("All your quit are","belong to long duck","dong",NULL,NULL,NULL,NULL,NULL);
2689                 if (request-- == 0) return M_QuitMessage("Press Y to quit","","But are you too legit?",NULL,NULL,NULL,NULL,NULL);
2690                 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);
2691                 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);
2692                 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);
2693                 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);
2694                 if (request-- == 0) return M_QuitMessage("Press Y like you","were waanderers","from Ys'",NULL,NULL,NULL,NULL,NULL);
2695                 if (request-- == 0) return M_QuitMessage("This game was made in","Nippon like the SS","announcer's saying ipon",NULL,NULL,NULL,NULL,NULL);
2696                 if (request-- == 0) return M_QuitMessage("you","want to quit?",NULL,NULL,NULL,NULL,NULL,NULL);
2697                 if (request-- == 0) return M_QuitMessage("Please stop playing","this stupid game",NULL,NULL,NULL,NULL,NULL,NULL);
2698                 break;
2699         case GAME_BATTLEMECH:
2700                 if (request-- == 0) return M_QuitMessage("? WHY ?","Press Y to quit, N to keep fraggin'",NULL,NULL,NULL,NULL,NULL,NULL);
2701                 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);
2702                 if (request-- == 0) return M_QuitMessage("Accept Defeat?","Press Y to quit, N to keep fraggin'",NULL,NULL,NULL,NULL,NULL,NULL);
2703                 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);
2704                 if (request-- == 0) return M_QuitMessage("Where's your bloodlust?","Press Y to quit, N to keep fraggin'",NULL,NULL,NULL,NULL,NULL,NULL);
2705                 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);
2706                 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);
2707                 break;
2708         case GAME_OPENQUARTZ:
2709                 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);
2710                 if (request-- == 0) return M_QuitMessage("GNU is not Unix!","Press Y to quit, N to stay",NULL,NULL,NULL,NULL,NULL,NULL);
2711                 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);
2712                 if (request-- == 0) return M_QuitMessage("Is OpenQuartz Propaganda?","Press Y to quit, N to stay",NULL,NULL,NULL,NULL,NULL,NULL);
2713                 break;
2714         default:
2715                 if (request-- == 0) return M_QuitMessage("Tired of fragging already?",NULL,NULL,NULL,NULL,NULL,NULL,NULL);
2716                 if (request-- == 0) return M_QuitMessage("Quit now and forfeit your bodycount?",NULL,NULL,NULL,NULL,NULL,NULL,NULL);
2717                 if (request-- == 0) return M_QuitMessage("Are you sure you want to quit?",NULL,NULL,NULL,NULL,NULL,NULL,NULL);
2718                 if (request-- == 0) return M_QuitMessage("Off to do something constructive?",NULL,NULL,NULL,NULL,NULL,NULL,NULL);
2719                 break;
2720         }
2721         return 0;
2722 };
2723
2724 void M_Menu_Quit_f (void)
2725 {
2726         int n;
2727         if (m_state == m_quit)
2728                 return;
2729         wasInMenus = (key_dest == key_menu);
2730         key_dest = key_menu;
2731         m_quit_prevstate = m_state;
2732         m_state = m_quit;
2733         m_entersound = true;
2734         // count how many there are
2735         for (n = 0;M_ChooseQuitMessage(n);n++);
2736         // choose one
2737         M_ChooseQuitMessage(rand() % n);
2738 }
2739
2740
2741 void M_Quit_Key (int key, char ascii)
2742 {
2743         switch (key)
2744         {
2745         case K_ESCAPE:
2746         case 'n':
2747         case 'N':
2748                 if (wasInMenus)
2749                 {
2750                         m_state = m_quit_prevstate;
2751                         m_entersound = true;
2752                 }
2753                 else
2754                 {
2755                         key_dest = key_game;
2756                         m_state = m_none;
2757                 }
2758                 break;
2759
2760         case 'Y':
2761         case 'y':
2762                 Host_Quit_f ();
2763                 break;
2764
2765         default:
2766                 break;
2767         }
2768 }
2769
2770 void M_Quit_Draw (void)
2771 {
2772         int i, l, linelength, firstline, lastline, lines;
2773         for (i = 0, linelength = 0, firstline = 9999, lastline = -1;m_quit_message[i];i++)
2774         {
2775                 if ((l = strlen(m_quit_message[i])))
2776                 {
2777                         if (firstline > i)
2778                                 firstline = i;
2779                         if (lastline < i)
2780                                 lastline = i;
2781                         if (linelength < l)
2782                                 linelength = l;
2783                 }
2784         }
2785         lines = (lastline - firstline) + 1;
2786         M_Background(linelength * 8 + 16, lines * 8 + 16);
2787         M_DrawTextBox(0, 0, linelength, lines);
2788         for (i = 0, l = firstline;i < lines;i++, l++)
2789                 M_Print(8 + 4 * (linelength - strlen(m_quit_message[l])), 8 + 8 * i, m_quit_message[l]);
2790 }
2791
2792 //=============================================================================
2793 /* LAN CONFIG MENU */
2794
2795 int             lanConfig_cursor = -1;
2796 int             lanConfig_cursor_table [] = {56, 76, 112};
2797 #define NUM_LANCONFIG_CMDS      3
2798
2799 int     lanConfig_port;
2800 char    lanConfig_portname[6];
2801 char    lanConfig_joinname[22];
2802
2803 void M_Menu_LanConfig_f (void)
2804 {
2805         key_dest = key_menu;
2806         m_state = m_lanconfig;
2807         m_entersound = true;
2808         if (lanConfig_cursor == -1)
2809         {
2810                 if (JoiningGame)
2811                         lanConfig_cursor = 1;
2812         }
2813         if (StartingGame)
2814                 lanConfig_cursor = 1;
2815         lanConfig_port = 26000;
2816         sprintf(lanConfig_portname, "%u", lanConfig_port);
2817
2818         M_Update_Return_Reason("");
2819 }
2820
2821
2822 void M_LanConfig_Draw (void)
2823 {
2824         cachepic_t      *p;
2825         int             basex;
2826         char    *startJoin;
2827         char    *protocol;
2828
2829         M_Background(320, 200);
2830
2831         M_DrawPic (16, 4, "gfx/qplaque.lmp");
2832         p = Draw_CachePic ("gfx/p_multi.lmp");
2833         basex = (320-p->width)/2;
2834         M_DrawPic (basex, 4, "gfx/p_multi.lmp");
2835
2836         if (StartingGame)
2837                 startJoin = "New Game";
2838         else
2839                 startJoin = "Join Game";
2840         protocol = "TCP/IP";
2841         M_Print(basex, 32, va ("%s - %s", startJoin, protocol));
2842         basex += 8;
2843
2844         M_Print(basex, lanConfig_cursor_table[0], "Port");
2845         M_DrawTextBox (basex+8*8, lanConfig_cursor_table[0]-8, 6, 1);
2846         M_Print(basex+9*8, lanConfig_cursor_table[0], lanConfig_portname);
2847
2848         if (JoiningGame)
2849         {
2850                 M_Print(basex, lanConfig_cursor_table[1], "Search for games...");
2851                 M_Print(basex, lanConfig_cursor_table[2]-16, "Join game at:");
2852                 M_DrawTextBox (basex+8, lanConfig_cursor_table[2]-8, 22, 1);
2853                 M_Print(basex+16, lanConfig_cursor_table[2], lanConfig_joinname);
2854         }
2855         else
2856         {
2857                 M_DrawTextBox (basex, lanConfig_cursor_table[1]-8, 2, 1);
2858                 M_Print(basex+8, lanConfig_cursor_table[1], "OK");
2859         }
2860
2861         M_DrawCharacter (basex-8, lanConfig_cursor_table [lanConfig_cursor], 12+((int)(realtime*4)&1));
2862
2863         if (lanConfig_cursor == 0)
2864                 M_DrawCharacter (basex+9*8 + 8*strlen(lanConfig_portname), lanConfig_cursor_table [0], 10+((int)(realtime*4)&1));
2865
2866         if (lanConfig_cursor == 2)
2867                 M_DrawCharacter (basex+16 + 8*strlen(lanConfig_joinname), lanConfig_cursor_table [2], 10+((int)(realtime*4)&1));
2868
2869         if (*m_return_reason)
2870                 M_Print(basex, 168, m_return_reason);
2871 }
2872
2873
2874 void M_LanConfig_Key (int key, char ascii)
2875 {
2876         int             l;
2877
2878         switch (key)
2879         {
2880         case K_ESCAPE:
2881                 M_Menu_MultiPlayer_f ();
2882                 break;
2883
2884         case K_UPARROW:
2885                 S_LocalSound ("sound/misc/menu1.wav");
2886                 lanConfig_cursor--;
2887                 if (lanConfig_cursor < 0)
2888                         lanConfig_cursor = NUM_LANCONFIG_CMDS-1;
2889                 break;
2890
2891         case K_DOWNARROW:
2892                 S_LocalSound ("sound/misc/menu1.wav");
2893                 lanConfig_cursor++;
2894                 if (lanConfig_cursor >= NUM_LANCONFIG_CMDS)
2895                         lanConfig_cursor = 0;
2896                 break;
2897
2898         case K_ENTER:
2899                 if (lanConfig_cursor == 0)
2900                         break;
2901
2902                 m_entersound = true;
2903
2904                 Cbuf_AddText ("stopdemo\n");
2905
2906                 Cvar_SetValue("port", lanConfig_port);
2907
2908                 if (lanConfig_cursor == 1)
2909                 {
2910                         if (StartingGame)
2911                         {
2912                                 M_Menu_GameOptions_f ();
2913                                 break;
2914                         }
2915                         M_Menu_ServerList_f();
2916                         break;
2917                 }
2918
2919                 if (lanConfig_cursor == 2)
2920                         Cbuf_AddText ( va ("connect \"%s\"\n", lanConfig_joinname) );
2921                 break;
2922
2923         case K_BACKSPACE:
2924                 if (lanConfig_cursor == 0)
2925                 {
2926                         if (strlen(lanConfig_portname))
2927                                 lanConfig_portname[strlen(lanConfig_portname)-1] = 0;
2928                 }
2929
2930                 if (lanConfig_cursor == 2)
2931                 {
2932                         if (strlen(lanConfig_joinname))
2933                                 lanConfig_joinname[strlen(lanConfig_joinname)-1] = 0;
2934                 }
2935                 break;
2936
2937         default:
2938                 if (ascii < 32 || ascii > 126)
2939                         break;
2940
2941                 if (lanConfig_cursor == 2)
2942                 {
2943                         l = strlen(lanConfig_joinname);
2944                         if (l < 21)
2945                         {
2946                                 lanConfig_joinname[l+1] = 0;
2947                                 lanConfig_joinname[l] = ascii;
2948                         }
2949                 }
2950
2951                 if (ascii < '0' || ascii > '9')
2952                         break;
2953                 if (lanConfig_cursor == 0)
2954                 {
2955                         l = strlen(lanConfig_portname);
2956                         if (l < 5)
2957                         {
2958                                 lanConfig_portname[l+1] = 0;
2959                                 lanConfig_portname[l] = ascii;
2960                         }
2961                 }
2962         }
2963
2964         if (StartingGame && lanConfig_cursor == 2)
2965         {
2966                 if (key == K_UPARROW)
2967                         lanConfig_cursor = 1;
2968                 else
2969                         lanConfig_cursor = 0;
2970         }
2971
2972         l =  atoi(lanConfig_portname);
2973         if (l <= 65535)
2974                 lanConfig_port = l;
2975         sprintf(lanConfig_portname, "%u", lanConfig_port);
2976 }
2977
2978 //=============================================================================
2979 /* GAME OPTIONS MENU */
2980
2981 typedef struct
2982 {
2983         char    *name;
2984         char    *description;
2985 } level_t;
2986
2987 typedef struct
2988 {
2989         char    *description;
2990         int             firstLevel;
2991         int             levels;
2992 } episode_t;
2993
2994 typedef struct
2995 {
2996         char *gamename;
2997         level_t *levels;
2998         episode_t *episodes;
2999         int numepisodes;
3000 }
3001 gamelevels_t;
3002
3003 level_t quakelevels[] =
3004 {
3005         {"start", "Entrance"},  // 0
3006
3007         {"e1m1", "Slipgate Complex"},                           // 1
3008         {"e1m2", "Castle of the Damned"},
3009         {"e1m3", "The Necropolis"},
3010         {"e1m4", "The Grisly Grotto"},
3011         {"e1m5", "Gloom Keep"},
3012         {"e1m6", "The Door To Chthon"},
3013         {"e1m7", "The House of Chthon"},
3014         {"e1m8", "Ziggurat Vertigo"},
3015
3016         {"e2m1", "The Installation"},                           // 9
3017         {"e2m2", "Ogre Citadel"},
3018         {"e2m3", "Crypt of Decay"},
3019         {"e2m4", "The Ebon Fortress"},
3020         {"e2m5", "The Wizard's Manse"},
3021         {"e2m6", "The Dismal Oubliette"},
3022         {"e2m7", "Underearth"},
3023
3024         {"e3m1", "Termination Central"},                        // 16
3025         {"e3m2", "The Vaults of Zin"},
3026         {"e3m3", "The Tomb of Terror"},
3027         {"e3m4", "Satan's Dark Delight"},
3028         {"e3m5", "Wind Tunnels"},
3029         {"e3m6", "Chambers of Torment"},
3030         {"e3m7", "The Haunted Halls"},
3031
3032         {"e4m1", "The Sewage System"},                          // 23
3033         {"e4m2", "The Tower of Despair"},
3034         {"e4m3", "The Elder God Shrine"},
3035         {"e4m4", "The Palace of Hate"},
3036         {"e4m5", "Hell's Atrium"},
3037         {"e4m6", "The Pain Maze"},
3038         {"e4m7", "Azure Agony"},
3039         {"e4m8", "The Nameless City"},
3040
3041         {"end", "Shub-Niggurath's Pit"},                        // 31
3042
3043         {"dm1", "Place of Two Deaths"},                         // 32
3044         {"dm2", "Claustrophobopolis"},
3045         {"dm3", "The Abandoned Base"},
3046         {"dm4", "The Bad Place"},
3047         {"dm5", "The Cistern"},
3048         {"dm6", "The Dark Zone"}
3049 };
3050
3051 episode_t quakeepisodes[] =
3052 {
3053         {"Welcome to Quake", 0, 1},
3054         {"Doomed Dimension", 1, 8},
3055         {"Realm of Black Magic", 9, 7},
3056         {"Netherworld", 16, 7},
3057         {"The Elder World", 23, 8},
3058         {"Final Level", 31, 1},
3059         {"Deathmatch Arena", 32, 6}
3060 };
3061
3062  //MED 01/06/97 added hipnotic levels
3063 level_t     hipnoticlevels[] =
3064 {
3065    {"start", "Command HQ"},  // 0
3066
3067    {"hip1m1", "The Pumping Station"},          // 1
3068    {"hip1m2", "Storage Facility"},
3069    {"hip1m3", "The Lost Mine"},
3070    {"hip1m4", "Research Facility"},
3071    {"hip1m5", "Military Complex"},
3072
3073    {"hip2m1", "Ancient Realms"},          // 6
3074    {"hip2m2", "The Black Cathedral"},
3075    {"hip2m3", "The Catacombs"},
3076    {"hip2m4", "The Crypt"},
3077    {"hip2m5", "Mortum's Keep"},
3078    {"hip2m6", "The Gremlin's Domain"},
3079
3080    {"hip3m1", "Tur Torment"},       // 12
3081    {"hip3m2", "Pandemonium"},
3082    {"hip3m3", "Limbo"},
3083    {"hip3m4", "The Gauntlet"},
3084
3085    {"hipend", "Armagon's Lair"},       // 16
3086
3087    {"hipdm1", "The Edge of Oblivion"}           // 17
3088 };
3089
3090 //MED 01/06/97  added hipnotic episodes
3091 episode_t   hipnoticepisodes[] =
3092 {
3093    {"Scourge of Armagon", 0, 1},
3094    {"Fortress of the Dead", 1, 5},
3095    {"Dominion of Darkness", 6, 6},
3096    {"The Rift", 12, 4},
3097    {"Final Level", 16, 1},
3098    {"Deathmatch Arena", 17, 1}
3099 };
3100
3101 //PGM 01/07/97 added rogue levels
3102 //PGM 03/02/97 added dmatch level
3103 level_t         roguelevels[] =
3104 {
3105         {"start",       "Split Decision"},
3106         {"r1m1",        "Deviant's Domain"},
3107         {"r1m2",        "Dread Portal"},
3108         {"r1m3",        "Judgement Call"},
3109         {"r1m4",        "Cave of Death"},
3110         {"r1m5",        "Towers of Wrath"},
3111         {"r1m6",        "Temple of Pain"},
3112         {"r1m7",        "Tomb of the Overlord"},
3113         {"r2m1",        "Tempus Fugit"},
3114         {"r2m2",        "Elemental Fury I"},
3115         {"r2m3",        "Elemental Fury II"},
3116         {"r2m4",        "Curse of Osiris"},
3117         {"r2m5",        "Wizard's Keep"},
3118         {"r2m6",        "Blood Sacrifice"},
3119         {"r2m7",        "Last Bastion"},
3120         {"r2m8",        "Source of Evil"},
3121         {"ctf1",    "Division of Change"}
3122 };
3123
3124 //PGM 01/07/97 added rogue episodes
3125 //PGM 03/02/97 added dmatch episode
3126 episode_t       rogueepisodes[] =
3127 {
3128         {"Introduction", 0, 1},
3129         {"Hell's Fortress", 1, 7},
3130         {"Corridors of Time", 8, 8},
3131         {"Deathmatch Arena", 16, 1}
3132 };
3133
3134 level_t         nehahralevels[] =
3135 {
3136         {"nehstart",    "Welcome to Nehahra"},
3137         {"neh1m1",      "Forge City1: Slipgates"},
3138         {"neh1m2",      "Forge City2: Boiler"},
3139         {"neh1m3",      "Forge City3: Escape"},
3140         {"neh1m4",      "Grind Core"},
3141         {"neh1m5",      "Industrial Silence"},
3142         {"neh1m6",      "Locked-Up Anger"},
3143         {"neh1m7",      "Wanderer of the Wastes"},
3144         {"neh1m8",      "Artemis System Net"},
3145         {"neh1m9",      "To the Death"},
3146         {"neh2m1",      "The Gates of Ghoro"},
3147         {"neh2m2",      "Sacred Trinity"},
3148         {"neh2m3",      "Realm of the Ancients"},
3149         {"neh2m4",      "Temple of the Ancients"},
3150         {"neh2m5",      "Dreams Made Flesh"},
3151         {"neh2m6",      "Your Last Cup of Sorrow"},
3152         {"nehsec",      "Ogre's Bane"},
3153         {"nehahra",     "Nehahra's Den"},
3154         {"nehend",      "Quintessence"}
3155 };
3156
3157 episode_t       nehahraepisodes[] =
3158 {
3159         {"Welcome to Nehahra", 0, 1},
3160         {"The Fall of Forge", 1, 9},
3161         {"The Outlands", 10, 7},
3162         {"Dimension of the Lost", 17, 2}
3163 };
3164
3165 // Map list for Transfusion
3166 level_t         transfusionlevels[] =
3167 {
3168         {"e1m1",                "Cradle to Grave"},
3169         {"e1m2",                "Wrong Side of the Tracks"},
3170         {"e1m3",                "Phantom Express"},
3171         {"e1m4",                "Dark Carnival"},
3172         {"e1m5",                "Hallowed Grounds"},
3173         {"e1m6",                "The Great Temple"},
3174         {"e1m7",                "Altar of Stone"},
3175         {"e1m8",                "House of Horrors"},
3176
3177         {"e2m1",                "Shipwrecked"},
3178         {"e2m2",                "The Lumber Mill"},
3179         {"e2m3",                "Rest for the Wicked"},
3180         {"e2m4",                "The Overlooked Hotel"},
3181         {"e2m5",                "The Haunting"},
3182         {"e2m6",                "The Cold Rush"},
3183         {"e2m7",                "Bowels of the Earth"},
3184         {"e2m8",                "The Lair of Shial"},
3185         {"e2m9",                "Thin Ice"},
3186
3187         {"e3m1",                "Ghost Town"},
3188         {"e3m2",                "The Siege"},
3189         {"e3m3",                "Raw Sewage"},
3190         {"e3m4",                "The Sick Ward"},
3191         {"e3m5",                "Spare Parts"},
3192         {"e3m6",                "Monster Bait"},
3193         {"e3m7",                "The Pit of Cerberus"},
3194         {"e3m8",                "Catacombs"},
3195
3196         {"e4m1",                "Butchery Loves Company"},
3197         {"e4m2",                "Breeding Grounds"},
3198         {"e4m3",                "Charnel House"},
3199         {"e4m4",                "Crystal Lake"},
3200         {"e4m5",                "Fire and Brimstone"},
3201         {"e4m6",                "The Ganglion Depths"},
3202         {"e4m7",                "In the Flesh"},
3203         {"e4m8",                "The Hall of the Epiphany"},
3204         {"e4m9",                "Mall of the Dead"},
3205
3206         {"bb1",                 "The Stronghold"},
3207         {"bb2",                 "Winter Wonderland"},
3208         {"bb3",                 "Bodies"},
3209         {"bb4",                 "The Tower"},
3210         {"bb5",                 "Click!"},
3211         {"bb6",                 "Twin Fortress"},
3212         {"bb7",                 "Midgard"},
3213         {"bb8",                 "Fun With Heads"},
3214         {"dm1",                 "Monolith Building 11"},
3215         {"dm2",                 "Power!"},
3216         {"dm3",                 "Area 15"},
3217
3218         {"e6m1",                "Welcome to Your Life"},
3219         {"e6m2",                "They Are Here"},
3220         {"e6m3",                "Public Storage"},
3221         {"e6m4",                "Aqueducts"},
3222         {"e6m5",                "The Ruined Temple"},
3223         {"e6m6",                "Forbidden Rituals"},
3224         {"e6m7",                "The Dungeon"},
3225         {"e6m8",                "Beauty and the Beast"},
3226         {"e6m9",                "Forgotten Catacombs"},
3227
3228         {"cp01",                "Boat Docks"},
3229         {"cp02",                "Old Opera House"},
3230         {"cp03",                "Gothic Library"},
3231         {"cp04",                "Lost Monastery"},
3232         {"cp05",                "Steamboat"},
3233         {"cp06",                "Graveyard"},
3234         {"cp07",                "Mountain Pass"},
3235         {"cp08",                "Abysmal Mine"},
3236         {"cp09",                "Castle"},
3237         {"cps1",                "Boggy Creek"},
3238
3239         {"cpbb01",              "Crypt of Despair"},
3240         {"cpbb02",              "Pits of Blood"},
3241         {"cpbb03",              "Unholy Cathedral"},
3242         {"cpbb04",              "Deadly Inspirations"},
3243
3244         {"b2a15",               "Area 15 (B2)"},
3245         {"barena",              "Blood Arena"},
3246         {"bkeep",               "Blood Keep"},
3247         {"bstar",               "Brown Star"},
3248         {"crypt",               "The Crypt"},
3249
3250         {"bb3_2k1",             "Bodies Infusion"},
3251         {"captasao",    "Captasao"},
3252         {"curandero",   "Curandero"},
3253         {"dcamp",               "DeathCamp"},
3254         {"highnoon",    "HighNoon"},
3255         {"qbb1",                "The Confluence"},
3256         {"qbb2",                "KathartiK"},
3257         {"qbb3",                "Caleb's Woodland Retreat"},
3258         {"zoo",                 "Zoo"},
3259
3260         {"dranzbb6",    "Black Coffee"},
3261         {"fragm",               "Frag'M"},
3262         {"maim",                "Maim"},
3263         {"qe1m7",               "The House of Chthon"},
3264         {"qmorbias",    "Dm-Morbias"},
3265         {"simple",              "Dead Simple"}
3266 };
3267
3268 episode_t       transfusionepisodes[] =
3269 {
3270         {"The Way of All Flesh", 0, 8},
3271         {"Even Death May Die", 8, 9},
3272         {"Farewell to Arms", 17, 8},
3273         {"Dead Reckoning", 25, 9},
3274         {"BloodBath", 34, 11},
3275         {"Post Mortem", 45, 9},
3276         {"Cryptic Passage", 54, 10},
3277         {"Cryptic BloodBath", 64, 4},
3278         {"Blood 2", 68, 5},
3279         {"Transfusion", 73, 9},
3280         {"Conversions", 82, 6}
3281 };
3282
3283 level_t goodvsbad2levels[] =
3284 {
3285         {"rts", "Many Paths"},  // 0
3286         {"chess", "Chess, Scott Hess"},                         // 1
3287         {"dot", "Big Wall"},
3288         {"city2", "The Big City"},
3289         {"bwall", "0 G like Psychic TV"},
3290         {"snow", "Wireframed"},
3291         {"telep", "Infinite Falling"},
3292         {"faces", "Facing Bases"},
3293         {"island", "Adventure Islands"},
3294 };
3295
3296 episode_t goodvsbad2episodes[] =
3297 {
3298         {"Levels? Bevels!", 0, 8},
3299 };
3300
3301 level_t battlemechlevels[] =
3302 {
3303         {"start", "Parking Level"},
3304         {"dm1", "Hot Dump"},                        // 1
3305         {"dm2", "The Pits"},
3306         {"dm3", "Dimber Died"},
3307         {"dm4", "Fire in the Hole"},
3308         {"dm5", "Clubhouses"},
3309         {"dm6", "Army go Underground"},
3310 };
3311
3312 episode_t battlemechepisodes[] =
3313 {
3314         {"Time for Battle", 0, 7},
3315 };
3316
3317 level_t openquartzlevels[] =
3318 {
3319         {"start", "Welcome to Openquartz"},
3320
3321         {"void1", "The center of nowhere"},                        // 1
3322         {"void2", "The place with no name"},
3323         {"void3", "The lost supply base"},
3324         {"void4", "Past the outer limits"},
3325         {"void5", "Into the nonexistance"},
3326         {"void6", "Void walk"},
3327
3328         {"vtest", "Warp Central"},
3329         {"box", "The deathmatch box"},
3330         {"bunkers", "Void command"},
3331         {"house", "House of chaos"},
3332         {"office", "Overnight office kill"},
3333         {"am1", "The nameless chambers"},
3334 };
3335
3336 episode_t openquartzepisodes[] =
3337 {
3338         {"Single Player", 0, 1},
3339         {"Void Deathmatch", 1, 6},
3340         {"Contrib", 7, 6},
3341 };
3342
3343 gamelevels_t sharewarequakegame = {"Shareware Quake", quakelevels, quakeepisodes, 2};
3344 gamelevels_t registeredquakegame = {"Quake", quakelevels, quakeepisodes, 7};
3345 gamelevels_t hipnoticgame = {"Scourge of Armagon", hipnoticlevels, hipnoticepisodes, 6};
3346 gamelevels_t roguegame = {"Dissolution of Eternity", roguelevels, rogueepisodes, 4};
3347 gamelevels_t nehahragame = {"Nehahra", nehahralevels, nehahraepisodes, 4};
3348 gamelevels_t transfusiongame = {"Transfusion", transfusionlevels, transfusionepisodes, 11};
3349 gamelevels_t goodvsbad2game = {"Good Vs. Bad 2", goodvsbad2levels, goodvsbad2episodes, 1};
3350 gamelevels_t battlemechgame = {"Battlemech", battlemechlevels, battlemechepisodes, 1};
3351 gamelevels_t openquartzgame = {"OpenQuartz", openquartzlevels, openquartzepisodes, 3};
3352
3353 typedef struct
3354 {
3355         int gameid;
3356         gamelevels_t *notregistered;
3357         gamelevels_t *registered;
3358 }
3359 gameinfo_t;
3360
3361 gameinfo_t gamelist[] =
3362 {
3363         {GAME_NORMAL, &sharewarequakegame, &registeredquakegame},
3364         {GAME_HIPNOTIC, &hipnoticgame, &hipnoticgame},
3365         {GAME_ROGUE, &roguegame, &roguegame},
3366         {GAME_NEHAHRA, &nehahragame, &nehahragame},
3367         {GAME_TRANSFUSION, &transfusiongame, &transfusiongame},
3368         {GAME_GOODVSBAD2, &goodvsbad2game, &goodvsbad2game},
3369         {GAME_BATTLEMECH, &battlemechgame, &battlemechgame},
3370         {GAME_OPENQUARTZ, &openquartzgame, &openquartzgame},
3371         {-1, &sharewarequakegame, &registeredquakegame} // final fallback
3372 };
3373
3374 gamelevels_t *lookupgameinfo(void)
3375 {
3376         int i;
3377         for (i = 0;gamelist[i].gameid >= 0 && gamelist[i].gameid != gamemode;i++);
3378         if (registered.integer)
3379                 return gamelist[i].registered;
3380         else
3381                 return gamelist[i].notregistered;
3382 }
3383
3384 int     startepisode;
3385 int     startlevel;
3386 int maxplayers;
3387 qboolean m_serverInfoMessage = false;
3388 double m_serverInfoMessageTime;
3389
3390 void M_Menu_GameOptions_f (void)
3391 {
3392         key_dest = key_menu;
3393         m_state = m_gameoptions;
3394         m_entersound = true;
3395         if (maxplayers == 0)
3396                 maxplayers = svs.maxclients;
3397         if (maxplayers < 2)
3398                 maxplayers = min(8, MAX_SCOREBOARD);
3399 }
3400
3401
3402 int gameoptions_cursor_table[] = {40, 56, 64, 72, 80, 88, 96, 104, 112, 140, 160, 168};
3403 #define NUM_GAMEOPTIONS 12
3404 int             gameoptions_cursor;
3405
3406 void M_GameOptions_Draw (void)
3407 {
3408         cachepic_t      *p;
3409         int             x;
3410         gamelevels_t *g;
3411
3412         M_Background(320, 200);
3413
3414         M_DrawPic (16, 4, "gfx/qplaque.lmp");
3415         p = Draw_CachePic ("gfx/p_multi.lmp");
3416         M_DrawPic ( (320-p->width)/2, 4, "gfx/p_multi.lmp");
3417
3418         M_DrawTextBox (152, 32, 10, 1);
3419         M_Print(160, 40, "begin game");
3420
3421         M_Print(0, 56, "      Max players");
3422         M_Print(160, 56, va("%i", maxplayers) );
3423
3424         if (gamemode != GAME_GOODVSBAD2)
3425         {
3426                 M_Print(0, 64, "        Game Type");
3427                 if (gamemode == GAME_TRANSFUSION)
3428                 {
3429                         if (!coop.integer && !deathmatch.integer)
3430                                 Cvar_SetValue("deathmatch", 1);
3431                         if (deathmatch.integer == 0)
3432                                 M_Print(160, 64, "Cooperative");
3433                         else if (deathmatch.integer == 2)
3434                                 M_Print(160, 64, "Capture the Flag");
3435                         else
3436                                 M_Print(160, 64, "Blood Bath");
3437                 }
3438                 else if (gamemode == GAME_BATTLEMECH)
3439                 {
3440                         if (!deathmatch.integer)
3441                                 Cvar_SetValue("deathmatch", 1);
3442                         if (deathmatch.integer == 2)
3443                                 M_Print(160, 64, "Rambo Match");
3444                         else
3445                                 M_Print(160, 64, "Deathmatch");
3446                 }
3447                 else
3448                 {
3449                         if (!coop.integer && !deathmatch.integer)
3450                                 Cvar_SetValue("deathmatch", 1);
3451                         if (coop.integer)
3452                                 M_Print(160, 64, "Cooperative");
3453                         else
3454                                 M_Print(160, 64, "Deathmatch");
3455                 }
3456
3457                 M_Print(0, 72, "        Teamplay");
3458                 if (gamemode == GAME_ROGUE)
3459                 {
3460                         char *msg;
3461
3462                         switch((int)teamplay.integer)
3463                         {
3464                                 case 1: msg = "No Friendly Fire"; break;
3465                                 case 2: msg = "Friendly Fire"; break;
3466                                 case 3: msg = "Tag"; break;
3467                                 case 4: msg = "Capture the Flag"; break;
3468                                 case 5: msg = "One Flag CTF"; break;
3469                                 case 6: msg = "Three Team CTF"; break;
3470                                 default: msg = "Off"; break;
3471                         }
3472                         M_Print(160, 72, msg);
3473                 }
3474                 else
3475                 {
3476                         char *msg;
3477
3478                         switch (teamplay.integer)
3479                         {
3480                                 case 0: msg = "Off"; break;
3481                                 case 2: msg = "Friendly Fire"; break;
3482                                 default: msg = "No Friendly Fire"; break;
3483                         }
3484                         M_Print(160, 72, msg);
3485                 }
3486
3487                 M_Print(0, 80, "            Skill");
3488                 if (skill.integer == 0)
3489                         M_Print(160, 80, "Easy difficulty");
3490                 else if (skill.integer == 1)
3491                         M_Print(160, 80, "Normal difficulty");
3492                 else if (skill.integer == 2)
3493                         M_Print(160, 80, "Hard difficulty");
3494                 else
3495                         M_Print(160, 80, "Nightmare difficulty");
3496
3497                 M_Print(0, 88, "       Frag Limit");
3498                 if (fraglimit.integer == 0)
3499                         M_Print(160, 88, "none");
3500                 else
3501                         M_Print(160, 88, va("%i frags", fraglimit.integer));
3502
3503                 M_Print(0, 96, "       Time Limit");
3504                 if (timelimit.integer == 0)
3505                         M_Print(160, 96, "none");
3506                 else
3507                         M_Print(160, 96, va("%i minutes", timelimit.integer));
3508         }
3509
3510         M_Print(0, 104, "    Public server");
3511         M_Print(160, 104, (sv_public.integer == 0) ? "no" : "yes");
3512
3513         M_Print(0, 112, "   Server maxrate");
3514         M_Print(160, 112, va("%i", sv_maxrate.integer));
3515
3516         M_Print(0, 128, "      Server name");
3517         M_DrawTextBox (0, 132, 38, 1);
3518         M_Print(8, 140, hostname.string);
3519
3520         g = lookupgameinfo();
3521
3522         if (gamemode != GAME_GOODVSBAD2)
3523         {
3524                 M_Print(0, 160, "         Episode");
3525                 M_Print(160, 160, g->episodes[startepisode].description);
3526         }
3527
3528         M_Print(0, 168, "           Level");
3529         M_Print(160, 168, g->levels[g->episodes[startepisode].firstLevel + startlevel].description);
3530         M_Print(160, 176, g->levels[g->episodes[startepisode].firstLevel + startlevel].name);
3531
3532 // line cursor
3533         if (gameoptions_cursor == 9)
3534                 M_DrawCharacter (8 + 8 * strlen(hostname.string), gameoptions_cursor_table[gameoptions_cursor], 10+((int)(realtime*4)&1));
3535         else
3536                 M_DrawCharacter (144, gameoptions_cursor_table[gameoptions_cursor], 12+((int)(realtime*4)&1));
3537
3538         if (m_serverInfoMessage)
3539         {
3540                 if ((realtime - m_serverInfoMessageTime) < 5.0)
3541                 {
3542                         x = (320-26*8)/2;
3543                         M_DrawTextBox (x, 138, 24, 4);
3544                         x += 8;
3545                         M_Print(x, 146, " More than 64 players?? ");
3546                         M_Print(x, 154, "  First, question your  ");
3547                         M_Print(x, 162, "   sanity, then email   ");
3548                         M_Print(x, 170, " havoc@telefragged.com  ");
3549                 }
3550                 else
3551                         m_serverInfoMessage = false;
3552         }
3553 }
3554
3555
3556 void M_NetStart_Change (int dir)
3557 {
3558         gamelevels_t *g;
3559         int count;
3560
3561         switch (gameoptions_cursor)
3562         {
3563         case 1:
3564                 maxplayers += dir;
3565                 if (maxplayers > MAX_SCOREBOARD)
3566                 {
3567                         maxplayers = MAX_SCOREBOARD;
3568                         m_serverInfoMessage = true;
3569                         m_serverInfoMessageTime = realtime;
3570                 }
3571                 if (maxplayers < 2)
3572                         maxplayers = 2;
3573                 break;
3574
3575         case 2:
3576                 if (gamemode == GAME_GOODVSBAD2)
3577                         break;
3578                 if (gamemode == GAME_TRANSFUSION)
3579                 {
3580                         switch (deathmatch.integer)
3581                         {
3582                                 // From Cooperative to BloodBath
3583                                 case 0:
3584                                         Cvar_SetValueQuick (&coop, 0);
3585                                         Cvar_SetValueQuick (&deathmatch, 1);
3586                                         break;
3587
3588                                 // From BloodBath to CTF
3589                                 case 1:
3590                                         Cvar_SetValueQuick (&coop, 0);
3591                                         Cvar_SetValueQuick (&deathmatch, 2);
3592                                         break;
3593
3594                                 // From CTF to Cooperative
3595                                 //case 2:
3596                                 default:
3597                                         Cvar_SetValueQuick (&coop, 1);
3598                                         Cvar_SetValueQuick (&deathmatch, 0);
3599                         }
3600                 }
3601                 else if (gamemode == GAME_BATTLEMECH)
3602                 {
3603                         if (deathmatch.integer == 2) // changing from Rambo to Deathmatch
3604                                 Cvar_SetValueQuick (&deathmatch, 0);
3605                         else // changing from Deathmatch to Rambo
3606                                 Cvar_SetValueQuick (&deathmatch, 2);
3607                 }
3608                 else
3609                 {
3610                         if (deathmatch.integer) // changing from deathmatch to coop
3611                         {
3612                                 Cvar_SetValueQuick (&coop, 1);
3613                                 Cvar_SetValueQuick (&deathmatch, 0);
3614                         }
3615                         else // changing from coop to deathmatch
3616                         {
3617                                 Cvar_SetValueQuick (&coop, 0);
3618                                 Cvar_SetValueQuick (&deathmatch, 1);
3619                         }
3620                 }
3621                 break;
3622
3623         case 3:
3624                 if (gamemode == GAME_GOODVSBAD2)
3625                         break;
3626                 if (gamemode == GAME_ROGUE)
3627                         count = 6;
3628                 else
3629                         count = 2;
3630
3631                 Cvar_SetValueQuick (&teamplay, teamplay.integer + dir);
3632                 if (teamplay.integer > count)
3633                         Cvar_SetValueQuick (&teamplay, 0);
3634                 else if (teamplay.integer < 0)
3635                         Cvar_SetValueQuick (&teamplay, count);
3636                 break;
3637
3638         case 4:
3639                 if (gamemode == GAME_GOODVSBAD2)
3640                         break;
3641                 Cvar_SetValueQuick (&skill, skill.integer + dir);
3642                 if (skill.integer > 3)
3643                         Cvar_SetValueQuick (&skill, 0);
3644                 if (skill.integer < 0)
3645                         Cvar_SetValueQuick (&skill, 3);
3646                 break;
3647
3648         case 5:
3649                 if (gamemode == GAME_GOODVSBAD2)
3650                         break;
3651                 Cvar_SetValueQuick (&fraglimit, fraglimit.integer + dir*10);
3652                 if (fraglimit.integer > 100)
3653                         Cvar_SetValueQuick (&fraglimit, 0);
3654                 if (fraglimit.integer < 0)
3655                         Cvar_SetValueQuick (&fraglimit, 100);
3656                 break;
3657
3658         case 6:
3659                 if (gamemode == GAME_GOODVSBAD2)
3660                         break;
3661                 Cvar_SetValueQuick (&timelimit, timelimit.value + dir*5);
3662                 if (timelimit.value > 60)
3663                         Cvar_SetValueQuick (&timelimit, 0);
3664                 if (timelimit.value < 0)
3665                         Cvar_SetValueQuick (&timelimit, 60);
3666                 break;
3667
3668         case 7:
3669                 Cvar_SetValueQuick (&sv_public, !sv_public.integer);
3670                 break;
3671
3672         case 8:
3673                 Cvar_SetValueQuick (&sv_maxrate, sv_maxrate.integer + dir*500);
3674                 if (sv_maxrate.integer > NET_MAXRATE)
3675                         Cvar_SetValueQuick (&sv_maxrate, NET_MAXRATE);
3676                 if (sv_maxrate.integer < NET_MINRATE)
3677                         Cvar_SetValueQuick (&sv_maxrate, NET_MINRATE);
3678                 break;
3679
3680         case 9:
3681                 break;
3682
3683         case 10:
3684                 if (gamemode == GAME_GOODVSBAD2)
3685                         break;
3686                 startepisode += dir;
3687                 g = lookupgameinfo();
3688
3689                 if (startepisode < 0)
3690                         startepisode = g->numepisodes - 1;
3691
3692                 if (startepisode >= g->numepisodes)
3693                         startepisode = 0;
3694
3695                 startlevel = 0;
3696                 break;
3697
3698         case 11:
3699                 startlevel += dir;
3700                 g = lookupgameinfo();
3701
3702                 if (startlevel < 0)
3703                         startlevel = g->episodes[startepisode].levels - 1;
3704
3705                 if (startlevel >= g->episodes[startepisode].levels)
3706                         startlevel = 0;
3707                 break;
3708         }
3709 }
3710
3711 void M_GameOptions_Key (int key, char ascii)
3712 {
3713         gamelevels_t *g;
3714         int l;
3715         char hostnamebuf[128];
3716
3717         switch (key)
3718         {
3719         case K_ESCAPE:
3720                 M_Menu_MultiPlayer_f ();
3721                 break;
3722
3723         case K_UPARROW:
3724                 S_LocalSound ("sound/misc/menu1.wav");
3725                 gameoptions_cursor--;
3726                 if (gameoptions_cursor < 0)
3727                         gameoptions_cursor = NUM_GAMEOPTIONS-1;
3728                 break;
3729
3730         case K_DOWNARROW:
3731                 S_LocalSound ("sound/misc/menu1.wav");
3732                 gameoptions_cursor++;
3733                 if (gameoptions_cursor >= NUM_GAMEOPTIONS)
3734                         gameoptions_cursor = 0;
3735                 break;
3736
3737         case K_LEFTARROW:
3738                 if (gameoptions_cursor == 0)
3739                         break;
3740                 S_LocalSound ("sound/misc/menu3.wav");
3741                 M_NetStart_Change (-1);
3742                 break;
3743
3744         case K_RIGHTARROW:
3745                 if (gameoptions_cursor == 0)
3746                         break;
3747                 S_LocalSound ("sound/misc/menu3.wav");
3748                 M_NetStart_Change (1);
3749                 break;
3750
3751         case K_ENTER:
3752                 S_LocalSound ("sound/misc/menu2.wav");
3753                 if (gameoptions_cursor == 0)
3754                 {
3755                         if (sv.active)
3756                                 Cbuf_AddText ("disconnect\n");
3757                         Cbuf_AddText ( va ("maxplayers %u\n", maxplayers) );
3758
3759                         g = lookupgameinfo();
3760                         Cbuf_AddText ( va ("map %s\n", g->levels[g->episodes[startepisode].firstLevel + startlevel].name) );
3761                         return;
3762                 }
3763
3764                 M_NetStart_Change (1);
3765                 break;
3766
3767         case K_BACKSPACE:
3768                 if (gameoptions_cursor == 9)
3769                 {
3770                         l = strlen(hostname.string);
3771                         if (l)
3772                         {
3773                                 l = min(l - 1, 37);
3774                                 memcpy(hostnamebuf, hostname.string, l);
3775                                 hostnamebuf[l] = 0;
3776                                 Cvar_Set("hostname", hostnamebuf);
3777                         }
3778                 }
3779                 break;
3780
3781         default:
3782                 if (ascii < 32 || ascii > 126)
3783                         break;
3784                 if (gameoptions_cursor == 9)
3785                 {
3786                         l = strlen(hostname.string);
3787                         if (l < 37)
3788                         {
3789                                 memcpy(hostnamebuf, hostname.string, l);
3790                                 hostnamebuf[l] = ascii;
3791                                 hostnamebuf[l+1] = 0;
3792                                 Cvar_Set("hostname", hostnamebuf);
3793                         }
3794                 }
3795         }
3796 }
3797
3798 //=============================================================================
3799 /* SLIST MENU */
3800
3801 int slist_cursor;
3802
3803 void M_Menu_ServerList_f (void)
3804 {
3805         key_dest = key_menu;
3806         m_state = m_slist;
3807         m_entersound = true;
3808         slist_cursor = 0;
3809         M_Update_Return_Reason("");
3810         Net_Slist_f();
3811 }
3812
3813
3814 void M_ServerList_Draw (void)
3815 {
3816         int n, y, visible, start, end;
3817         cachepic_t *p;
3818         const char *s;
3819
3820         // use as much vertical space as available
3821         M_Background(640, vid.conheight);
3822         // scroll the list as the cursor moves
3823         s = va("%i/%i masters %i/%i servers", masterreplycount, masterquerycount, serverreplycount, serverquerycount);
3824         M_PrintRed((640 - strlen(s) * 8) / 2, 32, s);
3825         if (*m_return_reason)
3826                 M_Print(16, vid.conheight - 8, m_return_reason);
3827         y = 48;
3828         visible = (vid.conheight - 16 - y) / 8;
3829         start = bound(0, slist_cursor - (visible >> 1), hostCacheCount - visible);
3830         end = min(start + visible, hostCacheCount);
3831
3832         p = Draw_CachePic("gfx/p_multi.lmp");
3833         M_DrawPic((640 - p->width) / 2, 4, "gfx/p_multi.lmp");
3834         if (end > start)
3835         {
3836                 for (n = start;n < end;n++)
3837                 {
3838                         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);
3839                         M_Print(0, y, hostcache[n].line1);y += 8;
3840                         M_Print(0, y, hostcache[n].line2);y += 8;
3841                 }
3842         }
3843         else if (realtime - masterquerytime < 3)
3844         {
3845                 if (masterquerycount)
3846                         M_Print(0, y, "No servers found");
3847                 else
3848                         M_Print(0, y, "No master servers found (network problem?)");
3849         }
3850 }
3851
3852
3853 void M_ServerList_Key(int k, char ascii)
3854 {
3855         switch (k)
3856         {
3857         case K_ESCAPE:
3858                 M_Menu_LanConfig_f();
3859                 break;
3860
3861         case K_SPACE:
3862                 Net_Slist_f();
3863                 break;
3864
3865         case K_UPARROW:
3866         case K_LEFTARROW:
3867                 S_LocalSound ("sound/misc/menu1.wav");
3868                 slist_cursor--;
3869                 if (slist_cursor < 0)
3870                         slist_cursor = hostCacheCount - 1;
3871                 break;
3872
3873         case K_DOWNARROW:
3874         case K_RIGHTARROW:
3875                 S_LocalSound ("sound/misc/menu1.wav");
3876                 slist_cursor++;
3877                 if (slist_cursor >= hostCacheCount)
3878                         slist_cursor = 0;
3879                 break;
3880
3881         case K_ENTER:
3882                 S_LocalSound ("sound/misc/menu2.wav");
3883                 Cbuf_AddText(va("connect \"%s\"\n", hostcache[slist_cursor].cname));
3884                 break;
3885
3886         default:
3887                 break;
3888         }
3889
3890 }
3891
3892 //=============================================================================
3893 /* Menu Subsystem */
3894
3895 void M_Keydown(int key, char ascii);
3896 void M_Draw(void);
3897 void M_ToggleMenu_f(void);
3898 void M_Shutdown(void);
3899
3900 void M_Init (void)
3901 {
3902         menu_mempool = Mem_AllocPool("Menu", 0, NULL);
3903         menuplyr_load = true;
3904         menuplyr_pixels = NULL;
3905
3906         Cmd_AddCommand ("menu_main", M_Menu_Main_f);
3907         Cmd_AddCommand ("menu_singleplayer", M_Menu_SinglePlayer_f);
3908         Cmd_AddCommand ("menu_load", M_Menu_Load_f);
3909         Cmd_AddCommand ("menu_save", M_Menu_Save_f);
3910         Cmd_AddCommand ("menu_multiplayer", M_Menu_MultiPlayer_f);
3911         Cmd_AddCommand ("menu_setup", M_Menu_Setup_f);
3912         Cmd_AddCommand ("menu_options", M_Menu_Options_f);
3913         Cmd_AddCommand ("menu_options_effects", M_Menu_Options_Effects_f);
3914         Cmd_AddCommand ("menu_options_graphics", M_Menu_Options_Graphics_f);
3915         Cmd_AddCommand ("menu_options_colorcontrol", M_Menu_Options_ColorControl_f);
3916         Cvar_RegisterVariable (&menu_options_colorcontrol_correctionvalue);
3917         Cmd_AddCommand ("menu_keys", M_Menu_Keys_f);
3918         Cmd_AddCommand ("menu_video", M_Menu_Video_f);
3919         Cmd_AddCommand ("menu_reset", M_Menu_Reset_f);
3920         Cmd_AddCommand ("help", M_Menu_Help_f);
3921         Cmd_AddCommand ("menu_quit", M_Menu_Quit_f);
3922
3923         if (gamemode == GAME_TRANSFUSION)
3924         {
3925                 numcommands = sizeof(transfusionbindnames) / sizeof(transfusionbindnames[0]);
3926                 bindnames = transfusionbindnames;
3927         }
3928         else if (gamemode == GAME_GOODVSBAD2)
3929         {
3930                 numcommands = sizeof(goodvsbad2bindnames) / sizeof(goodvsbad2bindnames[0]);
3931                 bindnames = goodvsbad2bindnames;
3932         }
3933         else
3934         {
3935                 numcommands = sizeof(quakebindnames) / sizeof(quakebindnames[0]);
3936                 bindnames = quakebindnames;
3937         }
3938
3939         // Make sure "keys_cursor" doesn't start on a section in the binding list
3940         keys_cursor = 0;
3941         while (bindnames[keys_cursor][0][0] == '\0')
3942         {
3943                 keys_cursor++;
3944
3945                 // Only sections? There may be a problem somewhere...
3946                 if (keys_cursor >= numcommands)
3947                         Sys_Error ("M_Init: The key binding list only contains sections");
3948         }
3949
3950
3951         if (gamemode == GAME_NEHAHRA)
3952         {
3953                 if (FS_FileExists("maps/neh1m4.bsp"))
3954                 {
3955                         if (FS_FileExists("hearing.dem"))
3956                         {
3957                                 Con_Print("Nehahra movie and game detected.\n");
3958                                 NehGameType = TYPE_BOTH;
3959                         }
3960                         else
3961                         {
3962                                 Con_Print("Nehahra game detected.\n");
3963                                 NehGameType = TYPE_GAME;
3964                         }
3965                 }
3966                 else
3967                 {
3968                         if (FS_FileExists("hearing.dem"))
3969                         {
3970                                 Con_Print("Nehahra movie detected.\n");
3971                                 NehGameType = TYPE_DEMO;
3972                         }
3973                         else
3974                         {
3975                                 Con_Print("Nehahra not found.\n");
3976                                 NehGameType = TYPE_GAME; // could just complain, but...
3977                         }
3978                 }
3979         }
3980 }
3981
3982 void M_Draw (void)
3983 {
3984         if (key_dest != key_menu)
3985                 m_state = m_none;
3986
3987         if (m_state == m_none)
3988                 return;
3989
3990         switch (m_state)
3991         {
3992         case m_none:
3993                 break;
3994
3995         case m_main:
3996                 M_Main_Draw ();
3997                 break;
3998
3999         case m_demo:
4000                 M_Demo_Draw ();
4001                 break;
4002
4003         case m_singleplayer:
4004                 M_SinglePlayer_Draw ();
4005                 break;
4006
4007         case m_load:
4008                 M_Load_Draw ();
4009                 break;
4010
4011         case m_save:
4012                 M_Save_Draw ();
4013                 break;
4014
4015         case m_multiplayer:
4016                 M_MultiPlayer_Draw ();
4017                 break;
4018
4019         case m_setup:
4020                 M_Setup_Draw ();
4021                 break;
4022
4023         case m_options:
4024                 M_Options_Draw ();
4025                 break;
4026
4027         case m_options_effects:
4028                 M_Options_Effects_Draw ();
4029                 break;
4030
4031         case m_options_graphics:
4032                 M_Options_Graphics_Draw ();
4033                 break;
4034
4035         case m_options_colorcontrol:
4036                 M_Options_ColorControl_Draw ();
4037                 break;
4038
4039         case m_keys:
4040                 M_Keys_Draw ();
4041                 break;
4042
4043         case m_reset:
4044                 M_Reset_Draw ();
4045                 break;
4046
4047         case m_video:
4048                 M_Video_Draw ();
4049                 break;
4050
4051         case m_help:
4052                 M_Help_Draw ();
4053                 break;
4054
4055         case m_quit:
4056                 M_Quit_Draw ();
4057                 break;
4058
4059         case m_lanconfig:
4060                 M_LanConfig_Draw ();
4061                 break;
4062
4063         case m_gameoptions:
4064                 M_GameOptions_Draw ();
4065                 break;
4066
4067         case m_slist:
4068                 M_ServerList_Draw ();
4069                 break;
4070         }
4071
4072         if (m_entersound)
4073         {
4074                 S_LocalSound ("sound/misc/menu2.wav");
4075                 m_entersound = false;
4076         }
4077
4078         S_ExtraUpdate ();
4079 }
4080
4081
4082 void M_Keydown (int key, char ascii)
4083 {
4084         switch (m_state)
4085         {
4086         case m_none:
4087                 return;
4088
4089         case m_main:
4090                 M_Main_Key (key, ascii);
4091                 return;
4092
4093         case m_demo:
4094                 M_Demo_Key (key, ascii);
4095                 return;
4096
4097         case m_singleplayer:
4098                 M_SinglePlayer_Key (key, ascii);
4099                 return;
4100
4101         case m_load:
4102                 M_Load_Key (key, ascii);
4103                 return;
4104
4105         case m_save:
4106                 M_Save_Key (key, ascii);
4107                 return;
4108
4109         case m_multiplayer:
4110                 M_MultiPlayer_Key (key, ascii);
4111                 return;
4112
4113         case m_setup:
4114                 M_Setup_Key (key, ascii);
4115                 return;
4116
4117         case m_options:
4118                 M_Options_Key (key, ascii);
4119                 return;
4120
4121         case m_options_effects:
4122                 M_Options_Effects_Key (key, ascii);
4123                 return;
4124
4125         case m_options_graphics:
4126                 M_Options_Graphics_Key (key, ascii);
4127                 return;
4128
4129         case m_options_colorcontrol:
4130                 M_Options_ColorControl_Key (key, ascii);
4131                 return;
4132
4133         case m_keys:
4134                 M_Keys_Key (key, ascii);
4135                 return;
4136
4137         case m_reset:
4138                 M_Reset_Key (key, ascii);
4139                 return;
4140
4141
4142         case m_video:
4143                 M_Video_Key (key, ascii);
4144                 return;
4145
4146         case m_help:
4147                 M_Help_Key (key, ascii);
4148                 return;
4149
4150         case m_quit:
4151                 M_Quit_Key (key, ascii);
4152                 return;
4153
4154         case m_lanconfig:
4155                 M_LanConfig_Key (key, ascii);
4156                 return;
4157
4158         case m_gameoptions:
4159                 M_GameOptions_Key (key, ascii);
4160                 return;
4161
4162         case m_slist:
4163                 M_ServerList_Key (key, ascii);
4164                 return;
4165         }
4166 }
4167
4168 void M_Shutdown(void)
4169 {
4170         // reset key_dest
4171         key_dest = key_game;
4172 }
4173
4174 void M_Restart(void)
4175 {
4176 }
4177
4178 //============================================================================
4179 // Menu prog handling
4180 mfunction_t *PRVM_ED_FindFunction(const char *);
4181
4182 #define M_F_INIT                "m_init"
4183 #define M_F_KEYDOWN             "m_keydown"
4184 #define M_F_DRAW                "m_draw"
4185 // ng_menu function names
4186 #define M_F_DISPLAY             "m_display"
4187 #define M_F_HIDE                "m_hide"
4188 // normal menu names (rest)
4189 #define M_F_TOGGLE              "m_toggle"
4190 #define M_F_SHUTDOWN    "m_shutdown"
4191 #undef NG_MENU
4192 static char *m_required_func[] = {
4193 M_F_INIT,
4194 M_F_KEYDOWN,
4195 M_F_DRAW,
4196 #ifdef NG_MENU
4197 M_F_DISPLAY,
4198 M_F_HIDE,
4199 #else
4200 M_F_TOGGLE,
4201 #endif
4202 M_F_SHUTDOWN,
4203 };
4204
4205 #ifdef NG_MENU
4206 qboolean m_displayed;
4207 #endif
4208
4209 static int m_numrequiredfunc = sizeof(m_required_func) / sizeof(char*);
4210
4211 static func_t m_draw, m_keydown;
4212
4213 void MR_SetRouting (qboolean forceold);
4214
4215 void MP_Error(void)
4216 {
4217         // fall back to the normal menu
4218
4219         // say it
4220         Con_Print("Falling back to normal menu\n");
4221
4222         key_dest = key_game;
4223
4224         //PRVM_ResetProg();
4225
4226         // init the normal menu now -> this will also correct the menu router pointers
4227         MR_SetRouting (TRUE);
4228 }
4229
4230 void MP_Keydown (int key, char ascii)
4231 {
4232         PRVM_Begin;
4233         PRVM_SetProg(PRVM_MENUPROG);
4234
4235         // set time
4236         *prog->time = realtime;
4237
4238         // pass key
4239         prog->globals[OFS_PARM0] = (float) key;
4240         prog->globals[OFS_PARM1] = (float) ascii;
4241         PRVM_ExecuteProgram(m_keydown, M_F_KEYDOWN"(float key, float ascii) required\n");
4242
4243         PRVM_End;
4244 }
4245
4246 void MP_Draw (void)
4247 {
4248         PRVM_Begin;
4249         PRVM_SetProg(PRVM_MENUPROG);
4250
4251         // set time
4252         *prog->time = realtime;
4253
4254         PRVM_ExecuteProgram(m_draw,"");
4255
4256         PRVM_End;
4257 }
4258
4259 void MP_ToggleMenu_f (void)
4260 {
4261         PRVM_Begin;
4262         PRVM_SetProg(PRVM_MENUPROG);
4263
4264         // set time
4265         *prog->time = realtime;
4266
4267 #ifdef NG_MENU
4268         m_displayed = !m_displayed;
4269         if( m_displayed )
4270                 PRVM_ExecuteProgram((func_t) (PRVM_ED_FindFunction(M_F_DISPLAY) - prog->functions),"");
4271         else
4272                 PRVM_ExecuteProgram((func_t) (PRVM_ED_FindFunction(M_F_HIDE) - prog->functions),"");
4273 #else
4274         PRVM_ExecuteProgram((func_t) (PRVM_ED_FindFunction(M_F_TOGGLE) - prog->functions),"");
4275 #endif
4276
4277         PRVM_End;
4278 }
4279
4280 void MP_Shutdown (void)
4281 {
4282         PRVM_Begin;
4283         PRVM_SetProg(PRVM_MENUPROG);
4284
4285         // set time
4286         *prog->time = realtime;
4287
4288         PRVM_ExecuteProgram((func_t) (PRVM_ED_FindFunction(M_F_SHUTDOWN) - prog->functions),"");
4289
4290         // reset key_dest
4291         key_dest = key_game;
4292
4293         // AK not using this cause Im not sure whether this is useful at all instead :
4294         PRVM_ResetProg();
4295
4296         PRVM_End;
4297 }
4298
4299 void MP_Init (void)
4300 {
4301         PRVM_Begin;
4302         PRVM_InitProg(PRVM_MENUPROG);
4303
4304         prog->crc = M_PROGHEADER_CRC;
4305         prog->edictprivate_size = 0; // no private struct used
4306         prog->name = M_NAME;
4307         prog->limit_edicts = M_MAX_EDICTS;
4308         prog->extensionstring = vm_m_extensions;
4309         prog->builtins = vm_m_builtins;
4310         prog->numbuiltins = vm_m_numbuiltins;
4311         prog->init_cmd = VM_M_Cmd_Init;
4312         prog->reset_cmd = VM_M_Cmd_Reset;
4313         prog->error_cmd = MP_Error;
4314
4315         // allocate the mempools
4316         prog->edicts_mempool = Mem_AllocPool(M_NAME " edicts mempool", 0, NULL);
4317         prog->edictstring_mempool = Mem_AllocPool( M_NAME " edict string mempool", 0, NULL);
4318         prog->progs_mempool = Mem_AllocPool(M_PROG_FILENAME, 0, NULL);
4319
4320         PRVM_LoadProgs(M_PROG_FILENAME, m_numrequiredfunc, m_required_func);
4321
4322         // set m_draw and m_keydown
4323         m_draw = (func_t) (PRVM_ED_FindFunction(M_F_DRAW) - prog->functions);
4324         m_keydown = (func_t) (PRVM_ED_FindFunction(M_F_KEYDOWN) - prog->functions);
4325
4326 #ifdef NG_MENU
4327         m_displayed = false;
4328 #endif
4329
4330         // set time
4331         *prog->time = realtime;
4332
4333         // call the prog init
4334         PRVM_ExecuteProgram((func_t) (PRVM_ED_FindFunction(M_F_INIT) - prog->functions),"");
4335
4336         PRVM_End;
4337 }
4338
4339 void MP_Restart(void)
4340 {
4341
4342         MP_Init();
4343 }
4344
4345 //============================================================================
4346 // Menu router
4347
4348 static cvar_t forceqmenu = { 0, "forceqmenu", "0" };
4349
4350 void MR_SetRouting(qboolean forceold)
4351 {
4352         static qboolean m_init = FALSE, mp_init = FALSE;
4353
4354         // if the menu prog isnt available or forceqmenu ist set, use the old menu
4355         if(!FS_FileExists(M_PROG_FILENAME) || forceqmenu.integer || forceold)
4356         {
4357                 // set menu router function pointers
4358                 MR_Keydown = M_Keydown;
4359                 MR_Draw = M_Draw;
4360                 MR_ToggleMenu_f = M_ToggleMenu_f;
4361                 MR_Shutdown = M_Shutdown;
4362
4363                 // init
4364                 if(!m_init)
4365                 {
4366                         M_Init();
4367                         m_init = TRUE;
4368                 }
4369                 else
4370                         M_Restart();
4371         }
4372         else
4373         {
4374                 // set menu router function pointers
4375                 MR_Keydown = MP_Keydown;
4376                 MR_Draw = MP_Draw;
4377                 MR_ToggleMenu_f = MP_ToggleMenu_f;
4378                 MR_Shutdown = MP_Shutdown;
4379
4380                 if(!mp_init)
4381                 {
4382                         MP_Init();
4383                         mp_init = TRUE;
4384                 }
4385                 else
4386                         MP_Restart();
4387         }
4388 }
4389
4390 void MR_Restart(void)
4391 {
4392         MR_Shutdown ();
4393         MR_SetRouting (FALSE);
4394 }
4395
4396 void Call_MR_ToggleMenu_f(void)
4397 {
4398         if(MR_ToggleMenu_f)
4399                 MR_ToggleMenu_f();
4400 }
4401
4402 void MR_Init_Commands(void)
4403 {
4404         // set router console commands
4405         Cvar_RegisterVariable (&forceqmenu);
4406         if (gamemode == GAME_NETHERWORLD)
4407                 Cmd_AddCommand ("menu_fallback", MP_Error); //Force to old-style menu
4408         Cmd_AddCommand ("menu_restart",MR_Restart);
4409         Cmd_AddCommand ("togglemenu", Call_MR_ToggleMenu_f);
4410 }
4411
4412 void MR_Init(void)
4413 {
4414         // use -forceqmenu to use always the normal quake menu (it sets forceqmenu to 1)
4415 // COMMANDLINEOPTION: Client: -forceqmenu disables menu.dat (same as +forceqmenu 1)
4416         if(COM_CheckParm("-forceqmenu"))
4417                 Cvar_SetValueQuick(&forceqmenu,1);
4418         // use -useqmenu for debugging proposes, cause it starts
4419         // the normal quake menu only the first time
4420 // 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)
4421         if(COM_CheckParm("-useqmenu"))
4422                 MR_SetRouting (TRUE);
4423         else 
4424                 MR_SetRouting (FALSE);
4425 }