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