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