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