]> de.git.xonotic.org Git - xonotic/darkplaces.git/blob - menu.c
moved light matrix generation out of the render code and into the light creation...
[xonotic/darkplaces.git] / menu.c
1 /*
2 Copyright (C) 1996-1997 Id Software, Inc.
3
4 This program is free software; you can redistribute it and/or
5 modify it under the terms of the GNU General Public License
6 as published by the Free Software Foundation; either version 2
7 of the License, or (at your option) any later version.
8
9 This program is distributed in the hope that it will be useful,
10 but WITHOUT ANY WARRANTY; without even the implied warranty of
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
12
13 See the GNU General Public License for more details.
14
15 You should have received a copy of the GNU General Public License
16 along with this program; if not, write to the Free Software
17 Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
18
19 */
20 #include "quakedef.h"
21 #include "image.h"
22
23 #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 34
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 (&scr_screenshot_jpeg_quality, bound(0, scr_screenshot_jpeg_quality.value + dir * 0.1, 1));
1154         else if (options_cursor == optnum++)
1155                 Cvar_SetValueQuick (&r_sky, !r_sky.integer);
1156         else if (options_cursor == optnum++)
1157                 Cvar_SetValueQuick (&gl_combine, !gl_combine.integer);
1158         else if (options_cursor == optnum++)
1159                 Cvar_SetValueQuick (&gl_dither, !gl_dither.integer);
1160         else if (options_cursor == optnum++)
1161                 Cvar_SetValueQuick (&gl_delayfinish, !gl_delayfinish.integer);
1162         else if (options_cursor == optnum++)
1163                 Cvar_SetValueQuick (&gl_texture_anisotropy, bound(0, gl_texture_anisotropy.value + dir, 8));
1164         else if (options_cursor == optnum++)
1165                 Cvar_SetValueQuick (&slowmo, bound(0, slowmo.value + dir * 0.25, 5));
1166         else if (options_cursor == optnum++)
1167 #ifdef _WIN32
1168                 Cvar_SetValueQuick (&bgmvolume, bound(0, bgmvolume.value + dir * 1.0, 1));
1169 #else
1170                 Cvar_SetValueQuick (&bgmvolume, bound(0, bgmvolume.value + dir * 0.1, 1));
1171 #endif
1172         else if (options_cursor == optnum++)
1173                 Cvar_SetValueQuick (&volume, bound(0, volume.value + dir * 0.1, 1));
1174         else if (options_cursor == optnum++)
1175                 Cvar_SetValueQuick (&snd_staticvolume, bound(0, snd_staticvolume.value + dir * 0.1, 1));
1176         else if (options_cursor == optnum++)
1177                 Cvar_SetValueQuick (&crosshair, bound(0, crosshair.integer + dir, 5));
1178         else if (options_cursor == optnum++)
1179                 Cvar_SetValueQuick (&crosshair_size, bound(1, crosshair_size.value + dir, 5));
1180         else if (options_cursor == optnum++)
1181                 Cvar_SetValueQuick (&crosshair_static, !crosshair_static.integer);
1182         else if (options_cursor == optnum++)
1183                 Cvar_SetValueQuick (&showfps, !showfps.integer);
1184         else if (options_cursor == optnum++)
1185         {
1186                 if (cl_forwardspeed.value > 200)
1187                 {
1188                         Cvar_SetValueQuick (&cl_forwardspeed, 200);
1189                         Cvar_SetValueQuick (&cl_backspeed, 200);
1190                 }
1191                 else
1192                 {
1193                         Cvar_SetValueQuick (&cl_forwardspeed, 400);
1194                         Cvar_SetValueQuick (&cl_backspeed, 400);
1195                 }
1196         }
1197         else if (options_cursor == optnum++)
1198                 Cvar_SetValueQuick (&lookspring, !lookspring.integer);
1199         else if (options_cursor == optnum++)
1200                 Cvar_SetValueQuick (&lookstrafe, !lookstrafe.integer);
1201         else if (options_cursor == optnum++)
1202                 Cvar_SetValueQuick (&sensitivity, bound(1, sensitivity.value + dir * 0.5, 50));
1203         else if (options_cursor == optnum++)
1204                 Cvar_SetValueQuick (&freelook, !freelook.integer);
1205         else if (options_cursor == optnum++)
1206                 Cvar_SetValueQuick (&m_pitch, -m_pitch.value);
1207         else if (options_cursor == optnum++)
1208                 Cvar_SetValueQuick (&vid_mouse, !vid_mouse.integer);
1209 }
1210
1211 int optnum;
1212 int opty;
1213 int optcursor;
1214
1215 void M_Options_PrintCommand(char *s, int enabled)
1216 {
1217         if (opty >= 32)
1218         {
1219                 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);
1220                 M_ItemPrint(0, opty, s, enabled);
1221         }
1222         opty += 8;
1223         optnum++;
1224 }
1225
1226 void M_Options_PrintCheckbox(char *s, int enabled, int yes)
1227 {
1228         if (opty >= 32)
1229         {
1230                 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);
1231                 M_ItemPrint(0, opty, s, enabled);
1232                 M_DrawCheckbox(0 + strlen(s) * 8 + 8, opty, yes);
1233         }
1234         opty += 8;
1235         optnum++;
1236 }
1237
1238 void M_Options_PrintSlider(char *s, int enabled, float value, float minvalue, float maxvalue)
1239 {
1240         if (opty >= 32)
1241         {
1242                 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);
1243                 M_ItemPrint(0, opty, s, enabled);
1244                 M_DrawSlider(0 + strlen(s) * 8 + 8, opty, value, minvalue, maxvalue);
1245         }
1246         opty += 8;
1247         optnum++;
1248 }
1249
1250 void M_Options_Draw (void)
1251 {
1252         int visible;
1253         cachepic_t      *p;
1254
1255         M_Background(320, 240);
1256
1257         M_DrawPic(16, 4, "gfx/qplaque.lmp");
1258         p = Draw_CachePic("gfx/p_option.lmp");
1259         M_DrawPic((320-p->width)/2, 4, "gfx/p_option.lmp");
1260
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_PrintSlider(  "      JPEG quality", jpeg_dll != NULL, scr_screenshot_jpeg_quality.value, 0, 1);
1280         M_Options_PrintCheckbox("               Sky", true, r_sky.integer);
1281         M_Options_PrintCheckbox("   Texture Combine", true, gl_combine.integer);
1282         M_Options_PrintCheckbox("         Dithering", true, gl_dither.integer);
1283         M_Options_PrintCheckbox("Delay gfx (faster)", true, gl_delayfinish.integer);
1284         M_Options_PrintSlider(  "Anisotropic Filter", gl_support_anisotropy, gl_texture_anisotropy.value, 0, 8);
1285         M_Options_PrintSlider(  "        Game Speed", sv.active, slowmo.value, 0, 5);
1286         M_Options_PrintSlider(  "   CD Music Volume", cdaudioinitialized.integer, bgmvolume.value, 0, 1);
1287         M_Options_PrintSlider(  "      Sound Volume", snd_initialized.integer, volume.value, 0, 1);
1288         M_Options_PrintSlider(gamemode == GAME_GOODVSBAD2 ? "      Music Volume" : "    Ambient Volume", snd_initialized.integer, snd_staticvolume.value, 0, 1);
1289         M_Options_PrintSlider(  "         Crosshair", true, crosshair.value, 0, 5);
1290         M_Options_PrintSlider(  "    Crosshair Size", true, crosshair_size.value, 1, 5);
1291         M_Options_PrintCheckbox("  Static Crosshair", true, crosshair_static.integer);
1292         M_Options_PrintCheckbox("    Show Framerate", true, showfps.integer);
1293         M_Options_PrintCheckbox("        Always Run", true, cl_forwardspeed.value > 200);
1294         M_Options_PrintCheckbox("        Lookspring", true, lookspring.integer);
1295         M_Options_PrintCheckbox("        Lookstrafe", true, lookstrafe.integer);
1296         M_Options_PrintSlider(  "       Mouse Speed", true, sensitivity.value, 1, 50);
1297         M_Options_PrintCheckbox("        Mouse Look", true, freelook.integer);
1298         M_Options_PrintCheckbox("      Invert Mouse", true, m_pitch.value < 0);
1299         M_Options_PrintCheckbox("         Use Mouse", true, vid_mouse.integer);
1300 }
1301
1302
1303 void M_Options_Key (int k, char ascii)
1304 {
1305         switch (k)
1306         {
1307         case K_ESCAPE:
1308                 M_Menu_Main_f ();
1309                 break;
1310
1311         case K_ENTER:
1312                 m_entersound = true;
1313                 switch (options_cursor)
1314                 {
1315                 case 0:
1316                         M_Menu_Keys_f ();
1317                         break;
1318                 case 1:
1319                         m_state = m_none;
1320                         key_dest = key_game;
1321                         Con_ToggleConsole_f ();
1322                         break;
1323                 case 2:
1324                         Cbuf_AddText ("exec default.cfg\n");
1325                         break;
1326                 case 3:
1327                         M_Menu_Video_f ();
1328                         break;
1329                 case 4:
1330                         M_Menu_Options_Effects_f ();
1331                         break;
1332                 case 5:
1333                         M_Menu_Options_ColorControl_f ();
1334                         break;
1335                 default:
1336                         M_Menu_Options_AdjustSliders (1);
1337                         break;
1338                 }
1339                 return;
1340
1341         case K_UPARROW:
1342                 S_LocalSound ("misc/menu1.wav");
1343                 options_cursor--;
1344                 if (options_cursor < 0)
1345                         options_cursor = OPTIONS_ITEMS-1;
1346                 break;
1347
1348         case K_DOWNARROW:
1349                 S_LocalSound ("misc/menu1.wav");
1350                 options_cursor++;
1351                 if (options_cursor >= OPTIONS_ITEMS)
1352                         options_cursor = 0;
1353                 break;
1354
1355         case K_LEFTARROW:
1356                 M_Menu_Options_AdjustSliders (-1);
1357                 break;
1358
1359         case K_RIGHTARROW:
1360                 M_Menu_Options_AdjustSliders (1);
1361                 break;
1362         }
1363 }
1364
1365 #define OPTIONS_EFFECTS_ITEMS   22
1366
1367 int options_effects_cursor;
1368
1369 void M_Menu_Options_Effects_f (void)
1370 {
1371         key_dest = key_menu;
1372         m_state = m_options_effects;
1373         m_entersound = true;
1374 }
1375
1376
1377 extern cvar_t r_detailtextures;
1378 extern cvar_t cl_particles;
1379 extern cvar_t cl_explosions;
1380 extern cvar_t cl_stainmaps;
1381 extern cvar_t cl_decals;
1382 extern cvar_t r_explosionclip;
1383 extern cvar_t r_modellights;
1384 extern cvar_t r_coronas;
1385 extern cvar_t gl_flashblend;
1386 extern cvar_t cl_particles_quality;
1387 extern cvar_t cl_particles_bulletimpacts;
1388 extern cvar_t cl_particles_smoke;
1389 extern cvar_t cl_particles_sparks;
1390 extern cvar_t cl_particles_bubbles;
1391 extern cvar_t cl_particles_blood;
1392 extern cvar_t cl_particles_blood_alpha;
1393 extern cvar_t cl_particles_blood_bloodhack;
1394
1395 void M_Menu_Options_Effects_AdjustSliders (int dir)
1396 {
1397         int optnum;
1398         S_LocalSound ("misc/menu3.wav");
1399
1400         optnum = 0;
1401              if (options_effects_cursor == optnum++) Cvar_SetValueQuick (&r_modellights, bound(0, r_modellights.value + dir, 8));
1402         else if (options_effects_cursor == optnum++) Cvar_SetValueQuick (&r_coronas, bound(0, r_coronas.value + dir * 0.125, 4));
1403         else if (options_effects_cursor == optnum++) Cvar_SetValueQuick (&gl_flashblend, !gl_flashblend.integer);
1404         else if (options_effects_cursor == optnum++) Cvar_SetValueQuick (&cl_particles, !cl_particles.integer);
1405         else if (options_effects_cursor == optnum++) Cvar_SetValueQuick (&cl_particles_quality, bound(1, cl_particles_quality.value + dir * 0.5, 4));
1406         else if (options_effects_cursor == optnum++) Cvar_SetValueQuick (&cl_explosions, !cl_explosions.integer);
1407         else if (options_effects_cursor == optnum++) Cvar_SetValueQuick (&r_explosionclip, !r_explosionclip.integer);
1408         else if (options_effects_cursor == optnum++) Cvar_SetValueQuick (&cl_stainmaps, !cl_stainmaps.integer);
1409         else if (options_effects_cursor == optnum++) Cvar_SetValueQuick (&cl_decals, !cl_decals.integer);
1410         else if (options_effects_cursor == optnum++) Cvar_SetValueQuick (&r_detailtextures, !r_detailtextures.integer);
1411         else if (options_effects_cursor == optnum++) Cvar_SetValueQuick (&cl_particles_bulletimpacts, !cl_particles_bulletimpacts.integer);
1412         else if (options_effects_cursor == optnum++) Cvar_SetValueQuick (&cl_particles_smoke, !cl_particles_smoke.integer);
1413         else if (options_effects_cursor == optnum++) Cvar_SetValueQuick (&cl_particles_sparks, !cl_particles_sparks.integer);
1414         else if (options_effects_cursor == optnum++) Cvar_SetValueQuick (&cl_particles_bubbles, !cl_particles_bubbles.integer);
1415         else if (options_effects_cursor == optnum++) Cvar_SetValueQuick (&cl_particles_blood, !cl_particles_blood.integer);
1416         else if (options_effects_cursor == optnum++) Cvar_SetValueQuick (&cl_particles_blood_alpha, bound(0.2, cl_particles_blood_alpha.value + dir * 0.1, 1));
1417         else if (options_effects_cursor == optnum++) Cvar_SetValueQuick (&cl_particles_blood_bloodhack, !cl_particles_blood_bloodhack.integer);
1418         else if (options_effects_cursor == optnum++) Cvar_SetValueQuick (&r_lerpmodels, !r_lerpmodels.integer);
1419         else if (options_effects_cursor == optnum++) Cvar_SetValueQuick (&r_lerpsprites, !r_lerpsprites.integer);
1420         else if (options_effects_cursor == optnum++) Cvar_SetValueQuick (&r_wateralpha, bound(0, r_wateralpha.value + dir * 0.1, 1));
1421         else if (options_effects_cursor == optnum++) Cvar_SetValueQuick (&r_waterscroll, bound(0, r_waterscroll.value + dir * 0.5, 10));
1422         else if (options_effects_cursor == optnum++) Cvar_SetValueQuick (&r_watershader, bound(0, r_watershader.value + dir * 0.25, 10));
1423 }
1424
1425 void M_Options_Effects_Draw (void)
1426 {
1427         int visible;
1428         cachepic_t      *p;
1429
1430         M_Background(320, 200);
1431
1432         M_DrawPic(16, 4, "gfx/qplaque.lmp");
1433         p = Draw_CachePic("gfx/p_option.lmp");
1434         M_DrawPic((320-p->width)/2, 4, "gfx/p_option.lmp");
1435
1436         optcursor = options_effects_cursor;
1437         optnum = 0;
1438         visible = (vid.conheight - 32) / 8;
1439         opty = 32 - bound(0, optcursor - (visible >> 1), max(0, OPTIONS_EFFECTS_ITEMS - visible)) * 8;
1440
1441         M_Options_PrintSlider(  "      Lights Per Model", true, r_modellights.value, 0, 8);
1442         M_Options_PrintSlider(  "      Corona Intensity", true, r_coronas.value, 0, 4);
1443         M_Options_PrintCheckbox("      Use Only Coronas", true, gl_flashblend.integer);
1444         M_Options_PrintCheckbox("             Particles", true, cl_particles.integer);
1445         M_Options_PrintSlider(  "     Particles Quality", true, cl_particles_quality.value, 1, 4);
1446         M_Options_PrintCheckbox("            Explosions", true, cl_explosions.integer);
1447         M_Options_PrintCheckbox("    Explosion Clipping", true, r_explosionclip.integer);
1448         M_Options_PrintCheckbox("             Stainmaps", true, cl_stainmaps.integer);
1449         M_Options_PrintCheckbox("                Decals", true, cl_decals.integer);
1450         M_Options_PrintCheckbox("      Detail Texturing", true, r_detailtextures.integer);
1451         M_Options_PrintCheckbox("        Bullet Impacts", true, cl_particles_bulletimpacts.integer);
1452         M_Options_PrintCheckbox("                 Smoke", true, cl_particles_smoke.integer);
1453         M_Options_PrintCheckbox("                Sparks", true, cl_particles_sparks.integer);
1454         M_Options_PrintCheckbox("               Bubbles", true, cl_particles_bubbles.integer);
1455         M_Options_PrintCheckbox("                 Blood", true, cl_particles_blood.integer);
1456         M_Options_PrintSlider(  "         Blood Opacity", true, cl_particles_blood_alpha.value, 0.2, 1);
1457         M_Options_PrintCheckbox("Force New Blood Effect", true, cl_particles_blood_bloodhack.integer);
1458         M_Options_PrintCheckbox("   Model Interpolation", true, r_lerpmodels.integer);
1459         M_Options_PrintCheckbox("  Sprite Interpolation", true, r_lerpsprites.integer);
1460         M_Options_PrintSlider(  " Water Alpha (opacity)", true, r_wateralpha.value, 0, 1);
1461         M_Options_PrintSlider(  "        Water Movement", true, r_waterscroll.value, 0, 10);
1462         M_Options_PrintSlider(  " GeForce3 Water Shader", true, r_watershader.value, 0, 10);
1463 }
1464
1465
1466 void M_Options_Effects_Key (int k, char ascii)
1467 {
1468         switch (k)
1469         {
1470         case K_ESCAPE:
1471                 M_Menu_Options_f ();
1472                 break;
1473
1474         case K_ENTER:
1475                 M_Menu_Options_Effects_AdjustSliders (1);
1476                 break;
1477
1478         case K_UPARROW:
1479                 S_LocalSound ("misc/menu1.wav");
1480                 options_effects_cursor--;
1481                 if (options_effects_cursor < 0)
1482                         options_effects_cursor = OPTIONS_EFFECTS_ITEMS-1;
1483                 break;
1484
1485         case K_DOWNARROW:
1486                 S_LocalSound ("misc/menu1.wav");
1487                 options_effects_cursor++;
1488                 if (options_effects_cursor >= OPTIONS_EFFECTS_ITEMS)
1489                         options_effects_cursor = 0;
1490                 break;
1491
1492         case K_LEFTARROW:
1493                 M_Menu_Options_Effects_AdjustSliders (-1);
1494                 break;
1495
1496         case K_RIGHTARROW:
1497                 M_Menu_Options_Effects_AdjustSliders (1);
1498                 break;
1499         }
1500 }
1501
1502
1503
1504
1505
1506 #define OPTIONS_COLORCONTROL_ITEMS      18
1507
1508 int             options_colorcontrol_cursor;
1509
1510 // intensity value to match up to 50% dither to 'correct' quake
1511 cvar_t menu_options_colorcontrol_correctionvalue = {0, "menu_options_colorcontrol_correctionvalue", "0.25"};
1512
1513 void M_Menu_Options_ColorControl_f (void)
1514 {
1515         key_dest = key_menu;
1516         m_state = m_options_colorcontrol;
1517         m_entersound = true;
1518 }
1519
1520
1521 void M_Menu_Options_ColorControl_AdjustSliders (int dir)
1522 {
1523         int optnum;
1524         float f;
1525         S_LocalSound ("misc/menu3.wav");
1526
1527         optnum = 1;
1528         if (options_colorcontrol_cursor == optnum++)
1529                 Cvar_SetValueQuick (&v_hwgamma, !v_hwgamma.integer);
1530         else if (options_colorcontrol_cursor == optnum++)
1531         {
1532                 Cvar_SetValueQuick (&v_color_enable, 0);
1533                 Cvar_SetValueQuick (&v_gamma, bound(1, v_gamma.value + dir * 0.125, 5));
1534         }
1535         else if (options_colorcontrol_cursor == optnum++)
1536         {
1537                 Cvar_SetValueQuick (&v_color_enable, 0);
1538                 Cvar_SetValueQuick (&v_contrast, bound(1, v_contrast.value + dir * 0.125, 5));
1539         }
1540         else if (options_colorcontrol_cursor == optnum++)
1541         {
1542                 Cvar_SetValueQuick (&v_color_enable, 0);
1543                 Cvar_SetValueQuick (&v_brightness, bound(0, v_brightness.value + dir * 0.05, 0.8));
1544         }
1545         else if (options_colorcontrol_cursor == optnum++)
1546         {
1547                 Cvar_SetValueQuick (&v_color_enable, !v_color_enable.integer);
1548         }
1549         else if (options_colorcontrol_cursor == optnum++)
1550         {
1551                 Cvar_SetValueQuick (&v_color_enable, 1);
1552                 Cvar_SetValueQuick (&v_color_black_r, bound(0, v_color_black_r.value + dir * 0.0125, 0.8));
1553         }
1554         else if (options_colorcontrol_cursor == optnum++)
1555         {
1556                 Cvar_SetValueQuick (&v_color_enable, 1);
1557                 Cvar_SetValueQuick (&v_color_black_g, bound(0, v_color_black_g.value + dir * 0.0125, 0.8));
1558         }
1559         else if (options_colorcontrol_cursor == optnum++)
1560         {
1561                 Cvar_SetValueQuick (&v_color_enable, 1);
1562                 Cvar_SetValueQuick (&v_color_black_b, bound(0, v_color_black_b.value + dir * 0.0125, 0.8));
1563         }
1564         else if (options_colorcontrol_cursor == optnum++)
1565         {
1566                 Cvar_SetValueQuick (&v_color_enable, 1);
1567                 f = bound(0, (v_color_black_r.value + v_color_black_g.value + v_color_black_b.value) / 3 + dir * 0.0125, 0.8);
1568                 Cvar_SetValueQuick (&v_color_black_r, f);
1569                 Cvar_SetValueQuick (&v_color_black_g, f);
1570                 Cvar_SetValueQuick (&v_color_black_b, f);
1571         }
1572         else if (options_colorcontrol_cursor == optnum++)
1573         {
1574                 Cvar_SetValueQuick (&v_color_enable, 1);
1575                 Cvar_SetValueQuick (&v_color_grey_r, bound(0, v_color_grey_r.value + dir * 0.0125, 0.95));
1576         }
1577         else if (options_colorcontrol_cursor == optnum++)
1578         {
1579                 Cvar_SetValueQuick (&v_color_enable, 1);
1580                 Cvar_SetValueQuick (&v_color_grey_g, bound(0, v_color_grey_g.value + dir * 0.0125, 0.95));
1581         }
1582         else if (options_colorcontrol_cursor == optnum++)
1583         {
1584                 Cvar_SetValueQuick (&v_color_enable, 1);
1585                 Cvar_SetValueQuick (&v_color_grey_b, bound(0, v_color_grey_b.value + dir * 0.0125, 0.95));
1586         }
1587         else if (options_colorcontrol_cursor == optnum++)
1588         {
1589                 Cvar_SetValueQuick (&v_color_enable, 1);
1590                 f = bound(0, (v_color_grey_r.value + v_color_grey_g.value + v_color_grey_b.value) / 3 + dir * 0.0125, 0.95);
1591                 Cvar_SetValueQuick (&v_color_grey_r, f);
1592                 Cvar_SetValueQuick (&v_color_grey_g, f);
1593                 Cvar_SetValueQuick (&v_color_grey_b, f);
1594         }
1595         else if (options_colorcontrol_cursor == optnum++)
1596         {
1597                 Cvar_SetValueQuick (&v_color_enable, 1);
1598                 Cvar_SetValueQuick (&v_color_white_r, bound(1, v_color_white_r.value + dir * 0.125, 5));
1599         }
1600         else if (options_colorcontrol_cursor == optnum++)
1601         {
1602                 Cvar_SetValueQuick (&v_color_enable, 1);
1603                 Cvar_SetValueQuick (&v_color_white_g, bound(1, v_color_white_g.value + dir * 0.125, 5));
1604         }
1605         else if (options_colorcontrol_cursor == optnum++)
1606         {
1607                 Cvar_SetValueQuick (&v_color_enable, 1);
1608                 Cvar_SetValueQuick (&v_color_white_b, bound(1, v_color_white_b.value + dir * 0.125, 5));
1609         }
1610         else if (options_colorcontrol_cursor == optnum++)
1611         {
1612                 Cvar_SetValueQuick (&v_color_enable, 1);
1613                 f = bound(1, (v_color_white_r.value + v_color_white_g.value + v_color_white_b.value) / 3 + dir * 0.125, 5);
1614                 Cvar_SetValueQuick (&v_color_white_r, f);
1615                 Cvar_SetValueQuick (&v_color_white_g, f);
1616                 Cvar_SetValueQuick (&v_color_white_b, f);
1617         }
1618 }
1619
1620 void M_Options_ColorControl_Draw (void)
1621 {
1622         int visible;
1623         float x, c, s, t, u, v;
1624         cachepic_t      *p;
1625
1626         M_Background(320, 256);
1627
1628         M_DrawPic(16, 4, "gfx/qplaque.lmp");
1629         p = Draw_CachePic("gfx/p_option.lmp");
1630         M_DrawPic((320-p->width)/2, 4, "gfx/p_option.lmp");
1631
1632         optcursor = options_colorcontrol_cursor;
1633         optnum = 0;
1634         visible = (vid.conheight - 32) / 8;
1635         opty = 32 - bound(0, optcursor - (visible >> 1), max(0, OPTIONS_COLORCONTROL_ITEMS - visible)) * 8;
1636
1637         M_Options_PrintCommand( "     Reset to defaults", true);
1638         M_Options_PrintCheckbox("Hardware Gamma Control", vid_hardwaregammasupported.integer, v_hwgamma.integer);
1639         M_Options_PrintSlider(  "                 Gamma", !v_color_enable.integer && vid_hardwaregammasupported.integer && v_hwgamma.integer, v_gamma.value, 1, 5);
1640         M_Options_PrintSlider(  "              Contrast", !v_color_enable.integer, v_contrast.value, 1, 5);
1641         M_Options_PrintSlider(  "            Brightness", !v_color_enable.integer, v_brightness.value, 0, 0.8);
1642         M_Options_PrintCheckbox("  Color Level Controls", true, v_color_enable.integer);
1643         M_Options_PrintSlider(  "          Black: Red  ", v_color_enable.integer, v_color_black_r.value, 0, 0.8);
1644         M_Options_PrintSlider(  "          Black: Green", v_color_enable.integer, v_color_black_g.value, 0, 0.8);
1645         M_Options_PrintSlider(  "          Black: Blue ", v_color_enable.integer, v_color_black_b.value, 0, 0.8);
1646         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);
1647         M_Options_PrintSlider(  "           Grey: Red  ", v_color_enable.integer && vid_hardwaregammasupported.integer && v_hwgamma.integer, v_color_grey_r.value, 0, 0.95);
1648         M_Options_PrintSlider(  "           Grey: Green", v_color_enable.integer && vid_hardwaregammasupported.integer && v_hwgamma.integer, v_color_grey_g.value, 0, 0.95);
1649         M_Options_PrintSlider(  "           Grey: Blue ", v_color_enable.integer && vid_hardwaregammasupported.integer && v_hwgamma.integer, v_color_grey_b.value, 0, 0.95);
1650         M_Options_PrintSlider(  "           Grey: Grey ", v_color_enable.integer && vid_hardwaregammasupported.integer && v_hwgamma.integer, (v_color_grey_r.value + v_color_grey_g.value + v_color_grey_b.value) / 3, 0, 0.95);
1651         M_Options_PrintSlider(  "          White: Red  ", v_color_enable.integer, v_color_white_r.value, 1, 5);
1652         M_Options_PrintSlider(  "          White: Green", v_color_enable.integer, v_color_white_g.value, 1, 5);
1653         M_Options_PrintSlider(  "          White: Blue ", v_color_enable.integer, v_color_white_b.value, 1, 5);
1654         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);
1655
1656         opty += 4;
1657         DrawQ_Fill(menu_x, menu_y + opty, 320, 4 + 64 + 8 + 64 + 4, 0, 0, 0, 1, 0);opty += 4;
1658         s = (float) 312 / 2 * vid.realwidth / vid.conwidth;
1659         t = (float) 4 / 2 * vid.realheight / vid.conheight;
1660         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;
1661         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;
1662         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;
1663         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;
1664         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;
1665         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;
1666         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;
1667         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;
1668
1669         c = menu_options_colorcontrol_correctionvalue.value; // intensity value that should be matched up to a 50% dither to 'correct' quake
1670         s = (float) 48 / 2 * vid.realwidth / vid.conwidth;
1671         t = (float) 48 / 2 * vid.realheight / vid.conheight;
1672         u = s * 0.5;
1673         v = t * 0.5;
1674         opty += 8;
1675         x = 4;
1676         DrawQ_Fill(menu_x + x, menu_y + opty, 64, 48, c, 0, 0, 1, 0);
1677         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);
1678         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);
1679         x += 80;
1680         DrawQ_Fill(menu_x + x, menu_y + opty, 64, 48, 0, c, 0, 1, 0);
1681         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);
1682         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);
1683         x += 80;
1684         DrawQ_Fill(menu_x + x, menu_y + opty, 64, 48, 0, 0, c, 1, 0);
1685         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);
1686         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);
1687         x += 80;
1688         DrawQ_Fill(menu_x + x, menu_y + opty, 64, 48, c, c, c, 1, 0);
1689         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);
1690         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);
1691 }
1692
1693
1694 void M_Options_ColorControl_Key (int k, char ascii)
1695 {
1696         switch (k)
1697         {
1698         case K_ESCAPE:
1699                 M_Menu_Options_f ();
1700                 break;
1701
1702         case K_ENTER:
1703                 m_entersound = true;
1704                 switch (options_colorcontrol_cursor)
1705                 {
1706                 case 0:
1707                         Cvar_SetValueQuick(&v_hwgamma, 1);
1708                         Cvar_SetValueQuick(&v_gamma, 1);
1709                         Cvar_SetValueQuick(&v_contrast, 1);
1710                         Cvar_SetValueQuick(&v_brightness, 0);
1711                         Cvar_SetValueQuick(&v_color_enable, 0);
1712                         Cvar_SetValueQuick(&v_color_black_r, 0);
1713                         Cvar_SetValueQuick(&v_color_black_g, 0);
1714                         Cvar_SetValueQuick(&v_color_black_b, 0);
1715                         Cvar_SetValueQuick(&v_color_grey_r, 0);
1716                         Cvar_SetValueQuick(&v_color_grey_g, 0);
1717                         Cvar_SetValueQuick(&v_color_grey_b, 0);
1718                         Cvar_SetValueQuick(&v_color_white_r, 1);
1719                         Cvar_SetValueQuick(&v_color_white_g, 1);
1720                         Cvar_SetValueQuick(&v_color_white_b, 1);
1721                         break;
1722                 default:
1723                         M_Menu_Options_ColorControl_AdjustSliders (1);
1724                         break;
1725                 }
1726                 return;
1727
1728         case K_UPARROW:
1729                 S_LocalSound ("misc/menu1.wav");
1730                 options_colorcontrol_cursor--;
1731                 if (options_colorcontrol_cursor < 0)
1732                         options_colorcontrol_cursor = OPTIONS_COLORCONTROL_ITEMS-1;
1733                 break;
1734
1735         case K_DOWNARROW:
1736                 S_LocalSound ("misc/menu1.wav");
1737                 options_colorcontrol_cursor++;
1738                 if (options_colorcontrol_cursor >= OPTIONS_COLORCONTROL_ITEMS)
1739                         options_colorcontrol_cursor = 0;
1740                 break;
1741
1742         case K_LEFTARROW:
1743                 M_Menu_Options_ColorControl_AdjustSliders (-1);
1744                 break;
1745
1746         case K_RIGHTARROW:
1747                 M_Menu_Options_ColorControl_AdjustSliders (1);
1748                 break;
1749         }
1750 }
1751
1752
1753 //=============================================================================
1754 /* KEYS MENU */
1755
1756 char *quakebindnames[][2] =
1757 {
1758 {"+attack",             "attack"},
1759 {"impulse 10",          "next weapon"},
1760 {"impulse 12",          "previous weapon"},
1761 {"+jump",                       "jump / swim up"},
1762 {"+forward",            "walk forward"},
1763 {"+back",                       "backpedal"},
1764 {"+left",                       "turn left"},
1765 {"+right",                      "turn right"},
1766 {"+speed",                      "run"},
1767 {"+moveleft",           "step left"},
1768 {"+moveright",          "step right"},
1769 {"+strafe",             "sidestep"},
1770 {"+lookup",             "look up"},
1771 {"+lookdown",           "look down"},
1772 {"centerview",          "center view"},
1773 {"+mlook",                      "mouse look"},
1774 {"+klook",                      "keyboard look"},
1775 {"+moveup",                     "swim up"},
1776 {"+movedown",           "swim down"}
1777 };
1778
1779 char *transfusionbindnames[][2] =
1780 {
1781 {"",                            "Movement"},            // Movement commands
1782 {"+forward",            "walk forward"},
1783 {"+back",                       "backpedal"},
1784 {"+left",                       "turn left"},
1785 {"+right",                      "turn right"},
1786 {"+moveleft",           "step left"},
1787 {"+moveright",          "step right"},
1788 {"+jump",                       "jump / swim up"},
1789 {"+movedown",           "swim down"},
1790 {"",                            "Combat"},                      // Combat commands
1791 {"impulse 1",           "Pitch Fork"},
1792 {"impulse 2",           "Flare Gun"},
1793 {"impulse 3",           "Shotgun"},
1794 {"impulse 4",           "Machine Gun"},
1795 {"impulse 5",           "Incinerator"},
1796 {"impulse 6",           "Bombs (TNT)"},
1797 {"impulse 35",          "Proximity Bomb"},
1798 {"impulse 36",          "Remote Detonator"},
1799 {"impulse 7",           "Aerosol Can"},
1800 {"impulse 8",           "Tesla Cannon"},
1801 {"impulse 9",           "Life Leech"},
1802 {"impulse 10",          "Voodoo Doll"},
1803 {"impulse 21",          "next weapon"},
1804 {"impulse 22",          "previous weapon"},
1805 {"+attack",             "attack"},
1806 {"+button3",            "altfire"},
1807 {"",                            "Inventory"},           // Inventory commands
1808 {"impulse 40",          "Dr.'s Bag"},
1809 {"impulse 41",          "Crystal Ball"},
1810 {"impulse 42",          "Beast Vision"},
1811 {"impulse 43",          "Jump Boots"},
1812 {"impulse 23",          "next item"},
1813 {"impulse 24",          "previous item"},
1814 {"impulse 25",          "use item"},
1815 {"",                            "Misc"},                        // Misc commands
1816 {"+button4",            "use"},
1817 {"impulse 50",          "add bot (red)"},
1818 {"impulse 51",          "add bot (blue)"},
1819 {"impulse 52",          "kick a bot"},
1820 {"impulse 26",          "next armor type"},
1821 {"impulse 27",          "identify player"},
1822 {"impulse 55",          "voting menu"},
1823 {"impulse 56",          "observer mode"}
1824 };
1825
1826 char *goodvsbad2bindnames[][2] =
1827 {
1828 {"impulse 69",          "Power 1"},
1829 {"impulse 70",          "Power 2"},
1830 {"impulse 71",          "Power 3"},
1831 {"+jump",                       "jump / swim up"},
1832 {"+forward",            "walk forward"},
1833 {"+back",                       "backpedal"},
1834 {"+left",                       "turn left"},
1835 {"+right",                      "turn right"},
1836 {"+speed",                      "run"},
1837 {"+moveleft",           "step left"},
1838 {"+moveright",          "step right"},
1839 {"+strafe",             "sidestep"},
1840 {"+lookup",             "look up"},
1841 {"+lookdown",           "look down"},
1842 {"centerview",          "center view"},
1843 {"+mlook",                      "mouse look"},
1844 {"kill",                        "kill yourself"},
1845 {"+moveup",                     "swim up"},
1846 {"+movedown",           "swim down"}
1847 };
1848
1849 int numcommands;
1850 char *(*bindnames)[2];
1851
1852 /*
1853 typedef struct binditem_s
1854 {
1855         char *command, *description;
1856         struct binditem_s *next;
1857 }
1858 binditem_t;
1859
1860 typedef struct bindcategory_s
1861 {
1862         char *name;
1863         binditem_t *binds;
1864         struct bindcategory_s *next;
1865 }
1866 bindcategory_t;
1867
1868 bindcategory_t *bindcategories = NULL;
1869
1870 void M_ClearBinds (void)
1871 {
1872         for (c = bindcategories;c;c = cnext)
1873         {
1874                 cnext = c->next;
1875                 for (b = c->binds;b;b = bnext)
1876                 {
1877                         bnext = b->next;
1878                         Z_Free(b);
1879                 }
1880                 Z_Free(c);
1881         }
1882         bindcategories = NULL;
1883 }
1884
1885 void M_AddBindToCategory(bindcategory_t *c, char *command, char *description)
1886 {
1887         for (b = &c->binds;*b;*b = &(*b)->next);
1888         *b = Z_Alloc(sizeof(binditem_t) + strlen(command) + 1 + strlen(description) + 1);
1889         *b->command = (char *)((*b) + 1);
1890         *b->description = *b->command + strlen(command) + 1;
1891         strcpy(*b->command, command);
1892         strcpy(*b->description, description);
1893 }
1894
1895 void M_AddBind (char *category, char *command, char *description)
1896 {
1897         for (c = &bindcategories;*c;c = &(*c)->next)
1898         {
1899                 if (!strcmp(category, (*c)->name))
1900                 {
1901                         M_AddBindToCategory(*c, command, description);
1902                         return;
1903                 }
1904         }
1905         *c = Z_Alloc(sizeof(bindcategory_t));
1906         M_AddBindToCategory(*c, command, description);
1907 }
1908
1909 void M_DefaultBinds (void)
1910 {
1911         M_ClearBinds();
1912         M_AddBind("movement", "+jump", "jump / swim up");
1913         M_AddBind("movement", "+forward", "walk forward");
1914         M_AddBind("movement", "+back", "backpedal");
1915         M_AddBind("movement", "+left", "turn left");
1916         M_AddBind("movement", "+right", "turn right");
1917         M_AddBind("movement", "+speed", "run");
1918         M_AddBind("movement", "+moveleft", "step left");
1919         M_AddBind("movement", "+moveright", "step right");
1920         M_AddBind("movement", "+strafe", "sidestep");
1921         M_AddBind("movement", "+lookup", "look up");
1922         M_AddBind("movement", "+lookdown", "look down");
1923         M_AddBind("movement", "centerview", "center view");
1924         M_AddBind("movement", "+mlook", "mouse look");
1925         M_AddBind("movement", "+klook", "keyboard look");
1926         M_AddBind("movement", "+moveup", "swim up");
1927         M_AddBind("movement", "+movedown", "swim down");
1928         M_AddBind("weapons", "+attack", "attack");
1929         M_AddBind("weapons", "impulse 10", "next weapon");
1930         M_AddBind("weapons", "impulse 12", "previous weapon");
1931         M_AddBind("weapons", "impulse 1", "select weapon 1 (axe)");
1932         M_AddBind("weapons", "impulse 2", "select weapon 2 (shotgun)");
1933         M_AddBind("weapons", "impulse 3", "select weapon 3 (super )");
1934         M_AddBind("weapons", "impulse 4", "select weapon 4 (nailgun)");
1935         M_AddBind("weapons", "impulse 5", "select weapon 5 (super nailgun)");
1936         M_AddBind("weapons", "impulse 6", "select weapon 6 (grenade launcher)");
1937         M_AddBind("weapons", "impulse 7", "select weapon 7 (rocket launcher)");
1938         M_AddBind("weapons", "impulse 8", "select weapon 8 (lightning gun)");
1939 }
1940 */
1941
1942
1943 int             keys_cursor;
1944 int             bind_grab;
1945
1946 void M_Menu_Keys_f (void)
1947 {
1948         key_dest = key_menu;
1949         m_state = m_keys;
1950         m_entersound = true;
1951 }
1952
1953 #define NUMKEYS 5
1954
1955 void M_FindKeysForCommand (char *command, int *keys)
1956 {
1957         int             count;
1958         int             j;
1959         char    *b;
1960
1961         for (j = 0;j < NUMKEYS;j++)
1962                 keys[j] = -1;
1963
1964         count = 0;
1965
1966         for (j=0 ; j<256 ; j++)
1967         {
1968                 b = keybindings[0][j];
1969                 if (!b)
1970                         continue;
1971                 if (!strcmp (b, command) )
1972                 {
1973                         keys[count++] = j;
1974                         if (count == NUMKEYS)
1975                                 break;
1976                 }
1977         }
1978 }
1979
1980 void M_UnbindCommand (char *command)
1981 {
1982         int             j;
1983         char    *b;
1984
1985         for (j=0 ; j<256 ; j++)
1986         {
1987                 b = keybindings[0][j];
1988                 if (!b)
1989                         continue;
1990                 if (!strcmp (b, command))
1991                         Key_SetBinding (j, 0, "");
1992         }
1993 }
1994
1995
1996 void M_Keys_Draw (void)
1997 {
1998         int             i, j;
1999         int             keys[NUMKEYS];
2000         int             y;
2001         cachepic_t      *p;
2002         char    keystring[1024];
2003
2004         M_Background(320, 48 + 8 * numcommands);
2005
2006         p = Draw_CachePic ("gfx/ttl_cstm.lmp");
2007         M_DrawPic ( (320-p->width)/2, 4, "gfx/ttl_cstm.lmp");
2008
2009         if (bind_grab)
2010                 M_Print (12, 32, "Press a key or button for this action");
2011         else
2012                 M_Print (18, 32, "Enter to change, backspace to clear");
2013
2014 // search for known bindings
2015         for (i=0 ; i<numcommands ; i++)
2016         {
2017                 y = 48 + 8*i;
2018
2019                 // If there's no command, it's just a section
2020                 if (bindnames[i][0][0] == '\0')
2021                 {
2022                         M_PrintRed (4, y, "\x0D");  // #13 is the little arrow pointing to the right
2023                         M_PrintRed (16, y, bindnames[i][1]);
2024                         continue;
2025                 }
2026                 else
2027                         M_Print (16, y, bindnames[i][1]);
2028
2029                 M_FindKeysForCommand (bindnames[i][0], keys);
2030
2031                 // LordHavoc: redesigned to print more than 2 keys, inspired by Tomaz's MiniRacer
2032                 if (keys[0] == -1)
2033                         strcpy(keystring, "???");
2034                 else
2035                 {
2036                         keystring[0] = 0;
2037                         for (j = 0;j < NUMKEYS;j++)
2038                         {
2039                                 if (keys[j] != -1)
2040                                 {
2041                                         if (j > 0)
2042                                                 strcat(keystring, " or ");
2043                                         strcat(keystring, Key_KeynumToString (keys[j]));
2044                                 }
2045                         }
2046                 }
2047                 M_Print (150, y, keystring);
2048         }
2049
2050         if (bind_grab)
2051                 M_DrawCharacter (140, 48 + keys_cursor*8, '=');
2052         else
2053                 M_DrawCharacter (140, 48 + keys_cursor*8, 12+((int)(realtime*4)&1));
2054 }
2055
2056
2057 void M_Keys_Key (int k, char ascii)
2058 {
2059         char    cmd[80];
2060         int             keys[NUMKEYS];
2061
2062         if (bind_grab)
2063         {       // defining a key
2064                 S_LocalSound ("misc/menu1.wav");
2065                 if (k == K_ESCAPE)
2066                 {
2067                         bind_grab = false;
2068                 }
2069                 else //if (k != '`')
2070                 {
2071                         sprintf (cmd, "bind \"%s\" \"%s\"\n", Key_KeynumToString (k), bindnames[keys_cursor][0]);
2072                         Cbuf_InsertText (cmd);
2073                 }
2074
2075                 bind_grab = false;
2076                 return;
2077         }
2078
2079         switch (k)
2080         {
2081         case K_ESCAPE:
2082                 M_Menu_Options_f ();
2083                 break;
2084
2085         case K_LEFTARROW:
2086         case K_UPARROW:
2087                 S_LocalSound ("misc/menu1.wav");
2088                 do
2089                 {
2090                         keys_cursor--;
2091                         if (keys_cursor < 0)
2092                                 keys_cursor = numcommands-1;
2093                 }
2094                 while (bindnames[keys_cursor][0][0] == '\0');  // skip sections
2095                 break;
2096
2097         case K_DOWNARROW:
2098         case K_RIGHTARROW:
2099                 S_LocalSound ("misc/menu1.wav");
2100                 do
2101                 {
2102                         keys_cursor++;
2103                         if (keys_cursor >= numcommands)
2104                                 keys_cursor = 0;
2105                 }
2106                 while (bindnames[keys_cursor][0][0] == '\0');  // skip sections
2107                 break;
2108
2109         case K_ENTER:           // go into bind mode
2110                 M_FindKeysForCommand (bindnames[keys_cursor][0], keys);
2111                 S_LocalSound ("misc/menu2.wav");
2112                 if (keys[NUMKEYS - 1] != -1)
2113                         M_UnbindCommand (bindnames[keys_cursor][0]);
2114                 bind_grab = true;
2115                 break;
2116
2117         case K_BACKSPACE:               // delete bindings
2118         case K_DEL:                             // delete bindings
2119                 S_LocalSound ("misc/menu2.wav");
2120                 M_UnbindCommand (bindnames[keys_cursor][0]);
2121                 break;
2122         }
2123 }
2124
2125 //=============================================================================
2126 /* VIDEO MENU */
2127
2128 #define VIDEO_ITEMS 4
2129
2130 int video_cursor = 0;
2131 int video_cursor_table[] = {56, 68, 80, 100};
2132 // note: if modes are added to the beginning of this list, update the
2133 // video_resolution = x; in M_Menu_Video_f below
2134 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}};
2135 // this is the number of the 640x480 mode in the list
2136 #define VID_640 3
2137 #define VID_RES_COUNT ((int)(sizeof(video_resolutions) / sizeof(video_resolutions[0])) - 1)
2138 int video_resolution;
2139
2140 extern int current_vid_fullscreen;
2141 extern int current_vid_width;
2142 extern int current_vid_height;
2143 extern int current_vid_bitsperpixel;
2144
2145
2146 void M_Menu_Video_f (void)
2147 {
2148         key_dest = key_menu;
2149         m_state = m_video;
2150         m_entersound = true;
2151
2152         // Look for the current resolution
2153         for (video_resolution = 0; video_resolution < VID_RES_COUNT; video_resolution++)
2154         {
2155                 if (video_resolutions[video_resolution][0] == current_vid_width &&
2156                         video_resolutions[video_resolution][1] == current_vid_height)
2157                         break;
2158         }
2159
2160         // Default to VID_640 if we didn't find it
2161         if (video_resolution == VID_RES_COUNT)
2162         {
2163                 // may need to update this number if mode list changes
2164                 video_resolution = VID_640;
2165                 Cvar_SetValueQuick (&vid_width, video_resolutions[video_resolution][0]);
2166                 Cvar_SetValueQuick (&vid_height, video_resolutions[video_resolution][1]);
2167         }
2168 }
2169
2170
2171 void M_Video_Draw (void)
2172 {
2173         cachepic_t      *p;
2174         const char* string;
2175
2176         M_Background(320, 200);
2177
2178         M_DrawPic(16, 4, "gfx/qplaque.lmp");
2179         p = Draw_CachePic("gfx/vidmodes.lmp");
2180         M_DrawPic((320-p->width)/2, 4, "gfx/vidmodes.lmp");
2181
2182         // Resolution
2183         M_Print(16, video_cursor_table[0], "            Resolution");
2184         string = va("%dx%d", video_resolutions[video_resolution][0], video_resolutions[video_resolution][1]);
2185         M_Print (220, video_cursor_table[0], string);
2186
2187         // Bits per pixel
2188         M_Print(16, video_cursor_table[1], "        Bits per pixel");
2189         M_Print (220, video_cursor_table[1], (vid_bitsperpixel.integer == 32) ? "32" : "16");
2190
2191         // Fullscreen
2192         M_Print(16, video_cursor_table[2], "            Fullscreen");
2193         M_DrawCheckbox(220, video_cursor_table[2], vid_fullscreen.integer);
2194
2195         // "Apply" button
2196         M_Print(220, video_cursor_table[3], "Apply");
2197
2198         // Cursor
2199         M_DrawCharacter(200, video_cursor_table[video_cursor], 12+((int)(realtime*4)&1));
2200 }
2201
2202
2203 void M_Menu_Video_AdjustSliders (int dir)
2204 {
2205         S_LocalSound ("misc/menu3.wav");
2206
2207         switch (video_cursor)
2208         {
2209                 // Resolution
2210                 case 0:
2211                 {
2212                         int new_resolution = video_resolution + dir;
2213                         if (gamemode == GAME_FNIGGIUM ? new_resolution < VID_640 : new_resolution < 0)
2214                                 video_resolution = VID_RES_COUNT - 1;
2215                         else if (new_resolution > VID_RES_COUNT - 1)
2216                                 video_resolution = gamemode == GAME_FNIGGIUM ? VID_640 : 0;
2217                         else
2218                                 video_resolution = new_resolution;
2219
2220                         Cvar_SetValueQuick (&vid_width, video_resolutions[video_resolution][0]);
2221                         Cvar_SetValueQuick (&vid_height, video_resolutions[video_resolution][1]);
2222                         break;
2223                 }
2224
2225                 // Bits per pixel
2226                 case 1:
2227                         Cvar_SetValueQuick (&vid_bitsperpixel, (vid_bitsperpixel.integer == 32) ? 16 : 32);
2228                         break;
2229                 case 2:
2230                         Cvar_SetValueQuick (&vid_fullscreen, !vid_fullscreen.integer);
2231                         break;
2232         }
2233 }
2234
2235
2236 void M_Video_Key (int key, char ascii)
2237 {
2238         switch (key)
2239         {
2240                 case K_ESCAPE:
2241                         // vid_shared.c has a copy of the current video config. We restore it
2242                         Cvar_SetValueQuick(&vid_fullscreen, current_vid_fullscreen);
2243                         Cvar_SetValueQuick(&vid_width, current_vid_width);
2244                         Cvar_SetValueQuick(&vid_height, current_vid_height);
2245                         Cvar_SetValueQuick(&vid_bitsperpixel, current_vid_bitsperpixel);
2246
2247                         S_LocalSound ("misc/menu1.wav");
2248                         M_Menu_Options_f ();
2249                         break;
2250
2251                 case K_ENTER:
2252                         m_entersound = true;
2253                         switch (video_cursor)
2254                         {
2255                                 case 3:
2256                                         Cbuf_AddText ("vid_restart\n");
2257                                         M_Menu_Options_f ();
2258                                         break;
2259                                 default:
2260                                         M_Menu_Video_AdjustSliders (1);
2261                         }
2262                         break;
2263
2264                 case K_UPARROW:
2265                         S_LocalSound ("misc/menu1.wav");
2266                         video_cursor--;
2267                         if (video_cursor < 0)
2268                                 video_cursor = VIDEO_ITEMS-1;
2269                         break;
2270
2271                 case K_DOWNARROW:
2272                         S_LocalSound ("misc/menu1.wav");
2273                         video_cursor++;
2274                         if (video_cursor >= VIDEO_ITEMS)
2275                                 video_cursor = 0;
2276                         break;
2277
2278                 case K_LEFTARROW:
2279                         M_Menu_Video_AdjustSliders (-1);
2280                         break;
2281
2282                 case K_RIGHTARROW:
2283                         M_Menu_Video_AdjustSliders (1);
2284                         break;
2285         }
2286 }
2287
2288 //=============================================================================
2289 /* HELP MENU */
2290
2291 int             help_page;
2292 #define NUM_HELP_PAGES  6
2293
2294
2295 void M_Menu_Help_f (void)
2296 {
2297         key_dest = key_menu;
2298         m_state = m_help;
2299         m_entersound = true;
2300         help_page = 0;
2301 }
2302
2303
2304
2305 void M_Help_Draw (void)
2306 {
2307         M_Background(320, 200);
2308         M_DrawPic (0, 0, va("gfx/help%i.lmp", help_page));
2309 }
2310
2311
2312 void M_Help_Key (int key, char ascii)
2313 {
2314         switch (key)
2315         {
2316         case K_ESCAPE:
2317                 M_Menu_Main_f ();
2318                 break;
2319
2320         case K_UPARROW:
2321         case K_RIGHTARROW:
2322                 m_entersound = true;
2323                 if (++help_page >= NUM_HELP_PAGES)
2324                         help_page = 0;
2325                 break;
2326
2327         case K_DOWNARROW:
2328         case K_LEFTARROW:
2329                 m_entersound = true;
2330                 if (--help_page < 0)
2331                         help_page = NUM_HELP_PAGES-1;
2332                 break;
2333         }
2334
2335 }
2336
2337 //=============================================================================
2338 /* QUIT MENU */
2339
2340 char *m_quit_message[9];
2341 int             m_quit_prevstate;
2342 qboolean        wasInMenus;
2343
2344
2345 int M_QuitMessage(char *line1, char *line2, char *line3, char *line4, char *line5, char *line6, char *line7, char *line8)
2346 {
2347         m_quit_message[0] = line1;
2348         m_quit_message[1] = line2;
2349         m_quit_message[2] = line3;
2350         m_quit_message[3] = line4;
2351         m_quit_message[4] = line5;
2352         m_quit_message[5] = line6;
2353         m_quit_message[6] = line7;
2354         m_quit_message[7] = line8;
2355         m_quit_message[8] = NULL;
2356         return 1;
2357 }
2358
2359 int M_ChooseQuitMessage(int request)
2360 {
2361         switch (gamemode)
2362         {
2363         case GAME_NORMAL:
2364         case GAME_HIPNOTIC:
2365         case GAME_ROGUE:
2366         case GAME_NEHAHRA:
2367                 if (request-- == 0) return M_QuitMessage("Are you gonna quit","this game just like","everything else?",NULL,NULL,NULL,NULL,NULL);
2368                 if (request-- == 0) return M_QuitMessage("Milord, methinks that","thou art a lowly","quitter. Is this true?",NULL,NULL,NULL,NULL,NULL);
2369                 if (request-- == 0) return M_QuitMessage("Do I need to bust your","face open for trying","to quit?",NULL,NULL,NULL,NULL,NULL);
2370                 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);
2371                 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);
2372                 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);
2373                 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);
2374                 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);
2375                 break;
2376         case GAME_GOODVSBAD2:
2377                 if (request-- == 0) return M_QuitMessage("Press Yes To Quit","...","Yes",NULL,NULL,NULL,NULL,NULL);
2378                 if (request-- == 0) return M_QuitMessage("Do you really want to","Quit?","Play Good vs bad 3!",NULL,NULL,NULL,NULL,NULL);
2379                 if (request-- == 0) return M_QuitMessage("All your quit are","belong to long duck","dong",NULL,NULL,NULL,NULL,NULL);
2380                 if (request-- == 0) return M_QuitMessage("Press Y to quit","","But are you too legit?",NULL,NULL,NULL,NULL,NULL);
2381                 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);
2382                 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);
2383                 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);
2384                 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);
2385                 if (request-- == 0) return M_QuitMessage("Press Y like you","were waanderers","from Ys'",NULL,NULL,NULL,NULL,NULL);
2386                 if (request-- == 0) return M_QuitMessage("This game was made in","Nippon like the SS","announcer's saying ipon",NULL,NULL,NULL,NULL,NULL);
2387                 if (request-- == 0) return M_QuitMessage("you","want to quit?",NULL,NULL,NULL,NULL,NULL,NULL);
2388                 if (request-- == 0) return M_QuitMessage("Please stop playing","this stupid game",NULL,NULL,NULL,NULL,NULL,NULL);
2389                 break;
2390         case GAME_BATTLEMECH:
2391                 if (request-- == 0) return M_QuitMessage("? WHY ?","Press Y to quit, N to keep fraggin'",NULL,NULL,NULL,NULL,NULL,NULL);
2392                 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);
2393                 if (request-- == 0) return M_QuitMessage("Accept Defeat?","Press Y to quit, N to keep fraggin'",NULL,NULL,NULL,NULL,NULL,NULL);
2394                 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);
2395                 if (request-- == 0) return M_QuitMessage("Where's your bloodlust?","Press Y to quit, N to keep fraggin'",NULL,NULL,NULL,NULL,NULL,NULL);
2396                 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);
2397                 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);
2398                 break;
2399         default:
2400                 if (request-- == 0) return M_QuitMessage("Tired of fragging already?",NULL,NULL,NULL,NULL,NULL,NULL,NULL);
2401                 if (request-- == 0) return M_QuitMessage("Quit now and forfeit your bodycount?",NULL,NULL,NULL,NULL,NULL,NULL,NULL);
2402                 if (request-- == 0) return M_QuitMessage("Are you sure you want to quit?",NULL,NULL,NULL,NULL,NULL,NULL,NULL);
2403                 if (request-- == 0) return M_QuitMessage("Off to do something constructive?",NULL,NULL,NULL,NULL,NULL,NULL,NULL);
2404                 break;
2405         }
2406         return 0;
2407 };
2408
2409 void M_Menu_Quit_f (void)
2410 {
2411         int n;
2412         if (m_state == m_quit)
2413                 return;
2414         wasInMenus = (key_dest == key_menu);
2415         key_dest = key_menu;
2416         m_quit_prevstate = m_state;
2417         m_state = m_quit;
2418         m_entersound = true;
2419         // count how many there are
2420         for (n = 0;M_ChooseQuitMessage(n);n++);
2421         // choose one
2422         M_ChooseQuitMessage(rand() % n);
2423 }
2424
2425
2426 void M_Quit_Key (int key, char ascii)
2427 {
2428         switch (key)
2429         {
2430         case K_ESCAPE:
2431         case 'n':
2432         case 'N':
2433                 if (wasInMenus)
2434                 {
2435                         m_state = m_quit_prevstate;
2436                         m_entersound = true;
2437                 }
2438                 else
2439                 {
2440                         key_dest = key_game;
2441                         m_state = m_none;
2442                 }
2443                 break;
2444
2445         case 'Y':
2446         case 'y':
2447                 Host_Quit_f ();
2448                 break;
2449
2450         default:
2451                 break;
2452         }
2453 }
2454
2455 void M_Quit_Draw (void)
2456 {
2457         int i, l, linelength, firstline, lastline, lines;
2458         for (i = 0, linelength = 0, firstline = 9999, lastline = -1;m_quit_message[i];i++)
2459         {
2460                 if ((l = strlen(m_quit_message[i])))
2461                 {
2462                         if (firstline > i)
2463                                 firstline = i;
2464                         if (lastline < i)
2465                                 lastline = i;
2466                         if (linelength < l)
2467                                 linelength = l;
2468                 }
2469         }
2470         lines = (lastline - firstline) + 1;
2471         M_Background(linelength * 8 + 16, lines * 8 + 16);
2472         M_DrawTextBox(0, 0, linelength, lines);
2473         for (i = 0, l = firstline;i < lines;i++, l++)
2474                 M_Print(8 + 4 * (linelength - strlen(m_quit_message[l])), 8 + 8 * i, m_quit_message[l]);
2475 }
2476
2477 //=============================================================================
2478 /* LAN CONFIG MENU */
2479
2480 int             lanConfig_cursor = -1;
2481 int             lanConfig_cursor_table [] = {56, 76, 112};
2482 #define NUM_LANCONFIG_CMDS      3
2483
2484 int     lanConfig_port;
2485 char    lanConfig_portname[6];
2486 char    lanConfig_joinname[22];
2487
2488 void M_Menu_LanConfig_f (void)
2489 {
2490         key_dest = key_menu;
2491         m_state = m_lanconfig;
2492         m_entersound = true;
2493         if (lanConfig_cursor == -1)
2494         {
2495                 if (JoiningGame)
2496                         lanConfig_cursor = 1;
2497         }
2498         if (StartingGame)
2499                 lanConfig_cursor = 1;
2500         lanConfig_port = 26000;
2501         sprintf(lanConfig_portname, "%u", lanConfig_port);
2502
2503         m_return_reason[0] = 0;
2504 }
2505
2506
2507 void M_LanConfig_Draw (void)
2508 {
2509         cachepic_t      *p;
2510         int             basex;
2511         char    *startJoin;
2512         char    *protocol;
2513
2514         M_Background(320, 200);
2515
2516         M_DrawPic (16, 4, "gfx/qplaque.lmp");
2517         p = Draw_CachePic ("gfx/p_multi.lmp");
2518         basex = (320-p->width)/2;
2519         M_DrawPic (basex, 4, "gfx/p_multi.lmp");
2520
2521         if (StartingGame)
2522                 startJoin = "New Game";
2523         else
2524                 startJoin = "Join Game";
2525         protocol = "TCP/IP";
2526         M_Print (basex, 32, va ("%s - %s", startJoin, protocol));
2527         basex += 8;
2528
2529         M_Print (basex, lanConfig_cursor_table[0], "Port");
2530         M_DrawTextBox (basex+8*8, lanConfig_cursor_table[0]-8, 6, 1);
2531         M_Print (basex+9*8, lanConfig_cursor_table[0], lanConfig_portname);
2532
2533         if (JoiningGame)
2534         {
2535                 M_Print (basex, lanConfig_cursor_table[1], "Search for games...");
2536                 M_Print (basex, lanConfig_cursor_table[2]-16, "Join game at:");
2537                 M_DrawTextBox (basex+8, lanConfig_cursor_table[2]-8, 22, 1);
2538                 M_Print (basex+16, lanConfig_cursor_table[2], lanConfig_joinname);
2539         }
2540         else
2541         {
2542                 M_DrawTextBox (basex, lanConfig_cursor_table[1]-8, 2, 1);
2543                 M_Print (basex+8, lanConfig_cursor_table[1], "OK");
2544         }
2545
2546         M_DrawCharacter (basex-8, lanConfig_cursor_table [lanConfig_cursor], 12+((int)(realtime*4)&1));
2547
2548         if (lanConfig_cursor == 0)
2549                 M_DrawCharacter (basex+9*8 + 8*strlen(lanConfig_portname), lanConfig_cursor_table [0], 10+((int)(realtime*4)&1));
2550
2551         if (lanConfig_cursor == 2)
2552                 M_DrawCharacter (basex+16 + 8*strlen(lanConfig_joinname), lanConfig_cursor_table [2], 10+((int)(realtime*4)&1));
2553
2554         if (*m_return_reason)
2555                 M_Print (basex, 168, m_return_reason);
2556 }
2557
2558
2559 void M_LanConfig_Key (int key, char ascii)
2560 {
2561         int             l;
2562
2563         switch (key)
2564         {
2565         case K_ESCAPE:
2566                 M_Menu_MultiPlayer_f ();
2567                 break;
2568
2569         case K_UPARROW:
2570                 S_LocalSound ("misc/menu1.wav");
2571                 lanConfig_cursor--;
2572                 if (lanConfig_cursor < 0)
2573                         lanConfig_cursor = NUM_LANCONFIG_CMDS-1;
2574                 break;
2575
2576         case K_DOWNARROW:
2577                 S_LocalSound ("misc/menu1.wav");
2578                 lanConfig_cursor++;
2579                 if (lanConfig_cursor >= NUM_LANCONFIG_CMDS)
2580                         lanConfig_cursor = 0;
2581                 break;
2582
2583         case K_ENTER:
2584                 if (lanConfig_cursor == 0)
2585                         break;
2586
2587                 m_entersound = true;
2588
2589                 Cbuf_AddText ("stopdemo\n");
2590
2591                 Cvar_SetValue("port", lanConfig_port);
2592
2593                 if (lanConfig_cursor == 1)
2594                 {
2595                         if (StartingGame)
2596                         {
2597                                 M_Menu_GameOptions_f ();
2598                                 break;
2599                         }
2600                         M_Menu_ServerList_f();
2601                         break;
2602                 }
2603
2604                 if (lanConfig_cursor == 2)
2605                         Cbuf_AddText ( va ("connect \"%s\"\n", lanConfig_joinname) );
2606                 break;
2607
2608         case K_BACKSPACE:
2609                 if (lanConfig_cursor == 0)
2610                 {
2611                         if (strlen(lanConfig_portname))
2612                                 lanConfig_portname[strlen(lanConfig_portname)-1] = 0;
2613                 }
2614
2615                 if (lanConfig_cursor == 2)
2616                 {
2617                         if (strlen(lanConfig_joinname))
2618                                 lanConfig_joinname[strlen(lanConfig_joinname)-1] = 0;
2619                 }
2620                 break;
2621
2622         default:
2623                 if (ascii < 32 || ascii > 126)
2624                         break;
2625
2626                 if (lanConfig_cursor == 2)
2627                 {
2628                         l = strlen(lanConfig_joinname);
2629                         if (l < 21)
2630                         {
2631                                 lanConfig_joinname[l+1] = 0;
2632                                 lanConfig_joinname[l] = ascii;
2633                         }
2634                 }
2635
2636                 if (ascii < '0' || ascii > '9')
2637                         break;
2638                 if (lanConfig_cursor == 0)
2639                 {
2640                         l = strlen(lanConfig_portname);
2641                         if (l < 5)
2642                         {
2643                                 lanConfig_portname[l+1] = 0;
2644                                 lanConfig_portname[l] = ascii;
2645                         }
2646                 }
2647         }
2648
2649         if (StartingGame && lanConfig_cursor == 2)
2650         {
2651                 if (key == K_UPARROW)
2652                         lanConfig_cursor = 1;
2653                 else
2654                         lanConfig_cursor = 0;
2655         }
2656
2657         l =  atoi(lanConfig_portname);
2658         if (l <= 65535)
2659                 lanConfig_port = l;
2660         sprintf(lanConfig_portname, "%u", lanConfig_port);
2661 }
2662
2663 //=============================================================================
2664 /* GAME OPTIONS MENU */
2665
2666 typedef struct
2667 {
2668         char    *name;
2669         char    *description;
2670 } level_t;
2671
2672 typedef struct
2673 {
2674         char    *description;
2675         int             firstLevel;
2676         int             levels;
2677 } episode_t;
2678
2679 typedef struct
2680 {
2681         char *gamename;
2682         level_t *levels;
2683         episode_t *episodes;
2684         int numepisodes;
2685 }
2686 gamelevels_t;
2687
2688 level_t quakelevels[] =
2689 {
2690         {"start", "Entrance"},  // 0
2691
2692         {"e1m1", "Slipgate Complex"},                           // 1
2693         {"e1m2", "Castle of the Damned"},
2694         {"e1m3", "The Necropolis"},
2695         {"e1m4", "The Grisly Grotto"},
2696         {"e1m5", "Gloom Keep"},
2697         {"e1m6", "The Door To Chthon"},
2698         {"e1m7", "The House of Chthon"},
2699         {"e1m8", "Ziggurat Vertigo"},
2700
2701         {"e2m1", "The Installation"},                           // 9
2702         {"e2m2", "Ogre Citadel"},
2703         {"e2m3", "Crypt of Decay"},
2704         {"e2m4", "The Ebon Fortress"},
2705         {"e2m5", "The Wizard's Manse"},
2706         {"e2m6", "The Dismal Oubliette"},
2707         {"e2m7", "Underearth"},
2708
2709         {"e3m1", "Termination Central"},                        // 16
2710         {"e3m2", "The Vaults of Zin"},
2711         {"e3m3", "The Tomb of Terror"},
2712         {"e3m4", "Satan's Dark Delight"},
2713         {"e3m5", "Wind Tunnels"},
2714         {"e3m6", "Chambers of Torment"},
2715         {"e3m7", "The Haunted Halls"},
2716
2717         {"e4m1", "The Sewage System"},                          // 23
2718         {"e4m2", "The Tower of Despair"},
2719         {"e4m3", "The Elder God Shrine"},
2720         {"e4m4", "The Palace of Hate"},
2721         {"e4m5", "Hell's Atrium"},
2722         {"e4m6", "The Pain Maze"},
2723         {"e4m7", "Azure Agony"},
2724         {"e4m8", "The Nameless City"},
2725
2726         {"end", "Shub-Niggurath's Pit"},                        // 31
2727
2728         {"dm1", "Place of Two Deaths"},                         // 32
2729         {"dm2", "Claustrophobopolis"},
2730         {"dm3", "The Abandoned Base"},
2731         {"dm4", "The Bad Place"},
2732         {"dm5", "The Cistern"},
2733         {"dm6", "The Dark Zone"}
2734 };
2735
2736 episode_t quakeepisodes[] =
2737 {
2738         {"Welcome to Quake", 0, 1},
2739         {"Doomed Dimension", 1, 8},
2740         {"Realm of Black Magic", 9, 7},
2741         {"Netherworld", 16, 7},
2742         {"The Elder World", 23, 8},
2743         {"Final Level", 31, 1},
2744         {"Deathmatch Arena", 32, 6}
2745 };
2746
2747  //MED 01/06/97 added hipnotic levels
2748 level_t     hipnoticlevels[] =
2749 {
2750    {"start", "Command HQ"},  // 0
2751
2752    {"hip1m1", "The Pumping Station"},          // 1
2753    {"hip1m2", "Storage Facility"},
2754    {"hip1m3", "The Lost Mine"},
2755    {"hip1m4", "Research Facility"},
2756    {"hip1m5", "Military Complex"},
2757
2758    {"hip2m1", "Ancient Realms"},          // 6
2759    {"hip2m2", "The Black Cathedral"},
2760    {"hip2m3", "The Catacombs"},
2761    {"hip2m4", "The Crypt"},
2762    {"hip2m5", "Mortum's Keep"},
2763    {"hip2m6", "The Gremlin's Domain"},
2764
2765    {"hip3m1", "Tur Torment"},       // 12
2766    {"hip3m2", "Pandemonium"},
2767    {"hip3m3", "Limbo"},
2768    {"hip3m4", "The Gauntlet"},
2769
2770    {"hipend", "Armagon's Lair"},       // 16
2771
2772    {"hipdm1", "The Edge of Oblivion"}           // 17
2773 };
2774
2775 //MED 01/06/97  added hipnotic episodes
2776 episode_t   hipnoticepisodes[] =
2777 {
2778    {"Scourge of Armagon", 0, 1},
2779    {"Fortress of the Dead", 1, 5},
2780    {"Dominion of Darkness", 6, 6},
2781    {"The Rift", 12, 4},
2782    {"Final Level", 16, 1},
2783    {"Deathmatch Arena", 17, 1}
2784 };
2785
2786 //PGM 01/07/97 added rogue levels
2787 //PGM 03/02/97 added dmatch level
2788 level_t         roguelevels[] =
2789 {
2790         {"start",       "Split Decision"},
2791         {"r1m1",        "Deviant's Domain"},
2792         {"r1m2",        "Dread Portal"},
2793         {"r1m3",        "Judgement Call"},
2794         {"r1m4",        "Cave of Death"},
2795         {"r1m5",        "Towers of Wrath"},
2796         {"r1m6",        "Temple of Pain"},
2797         {"r1m7",        "Tomb of the Overlord"},
2798         {"r2m1",        "Tempus Fugit"},
2799         {"r2m2",        "Elemental Fury I"},
2800         {"r2m3",        "Elemental Fury II"},
2801         {"r2m4",        "Curse of Osiris"},
2802         {"r2m5",        "Wizard's Keep"},
2803         {"r2m6",        "Blood Sacrifice"},
2804         {"r2m7",        "Last Bastion"},
2805         {"r2m8",        "Source of Evil"},
2806         {"ctf1",    "Division of Change"}
2807 };
2808
2809 //PGM 01/07/97 added rogue episodes
2810 //PGM 03/02/97 added dmatch episode
2811 episode_t       rogueepisodes[] =
2812 {
2813         {"Introduction", 0, 1},
2814         {"Hell's Fortress", 1, 7},
2815         {"Corridors of Time", 8, 8},
2816         {"Deathmatch Arena", 16, 1}
2817 };
2818
2819 level_t         nehahralevels[] =
2820 {
2821         {"nehstart",    "Welcome to Nehahra"},
2822         {"neh1m1",      "Forge City1: Slipgates"},
2823         {"neh1m2",      "Forge City2: Boiler"},
2824         {"neh1m3",      "Forge City3: Escape"},
2825         {"neh1m4",      "Grind Core"},
2826         {"neh1m5",      "Industrial Silence"},
2827         {"neh1m6",      "Locked-Up Anger"},
2828         {"neh1m7",      "Wanderer of the Wastes"},
2829         {"neh1m8",      "Artemis System Net"},
2830         {"neh1m9",      "To the Death"},
2831         {"neh2m1",      "The Gates of Ghoro"},
2832         {"neh2m2",      "Sacred Trinity"},
2833         {"neh2m3",      "Realm of the Ancients"},
2834         {"neh2m4",      "Temple of the Ancients"},
2835         {"neh2m5",      "Dreams Made Flesh"},
2836         {"neh2m6",      "Your Last Cup of Sorrow"},
2837         {"nehsec",      "Ogre's Bane"},
2838         {"nehahra",     "Nehahra's Den"},
2839         {"nehend",      "Quintessence"}
2840 };
2841
2842 episode_t       nehahraepisodes[] =
2843 {
2844         {"Welcome to Nehahra", 0, 1},
2845         {"The Fall of Forge", 1, 9},
2846         {"The Outlands", 10, 7},
2847         {"Dimension of the Lost", 17, 2}
2848 };
2849
2850 // Map list for Transfusion
2851 level_t         transfusionlevels[] =
2852 {
2853         {"bb1",                 "The Stronghold"},
2854         {"bb2",                 "Winter Wonderland"},
2855         {"bb3",                 "Bodies"},
2856         {"bb4",                 "The Tower"},
2857         {"bb5",                 "Click!"},
2858         {"bb6",                 "Twin Fortress"},
2859         {"bb7",                 "Midgard"},
2860         {"bb8",                 "Fun With Heads"},
2861
2862         {"e1m1",                "Cradle to Grave"},
2863         {"e1m2",                "Wrong Side of the Tracks"},
2864         {"e1m7",                "Altar of Stone"},
2865         {"e2m8",                "The Lair of Shial"},
2866         {"e3m7",                "The Pit of Cerberus"},
2867         {"e4m1",                "Butchery Loves Company"},
2868         {"e4m7",                "In the Flesh"},
2869         {"e4m8",                "The Hall of the Epiphany"},
2870         {"e4m9",                "Mall of the Dead"},
2871
2872         {"dm1",                 "Monolith Building 11"},
2873         {"dm2",                 "Power!"},
2874         {"dm3",                 "Area 15"},
2875         {"e6m1",                "Welcome to Your Life"},
2876         {"e6m8",                "Beauty and the Beast"},
2877         {"e6m9",                "Forgotten Catacombs"},
2878
2879         {"cpbb01",              "Crypt of Despair"},
2880         {"cpbb03",              "Unholy Cathedral"},
2881
2882         {"b2a15",               "Area 15 (B2)"},
2883         {"barena",              "Blood Arena"},
2884         {"bkeep",               "Blood Keep"},
2885         {"bstar",               "Brown Star"},
2886         {"crypt",               "The Crypt"},
2887
2888         {"bb3_2k1",             "Bodies Infusion"},
2889         {"captasao",    "Captasao"},
2890         {"curandero",   "Curandero"},
2891         {"dcamp",               "DeathCamp"},
2892         {"highnoon",    "HighNoon"},
2893         {"qbb1",                "The Confluence"},
2894         {"qbb2",                "KathartiK"},
2895         {"qbb3",                "Caleb's Woodland Retreat"},
2896
2897         {"dranzbb6",    "Black Coffee"},
2898         {"fragm",               "Frag'M"},
2899         {"maim",                "Maim"},
2900         {"qe1m7",               "The House of Chthon"},
2901         {"qmorbias",    "Dm-Morbias"},
2902         {"simple",              "Dead Simple"}
2903 };
2904
2905 episode_t       transfusionepisodes[] =
2906 {
2907         {"Blood", 0, 8},
2908         {"Blood Single Player", 8, 9},
2909         {"Plasma Pack", 17, 6},
2910         {"Cryptic Passage", 23, 2},
2911         {"Blood 2", 25, 5},
2912         {"Transfusion", 30, 8},
2913         {"Conversions", 38, 6}
2914 };
2915
2916 level_t goodvsbad2levels[] =
2917 {
2918         {"rts", "Many Paths"},  // 0
2919         {"chess", "Chess, Scott Hess"},                         // 1
2920         {"dot", "Big Wall"},
2921         {"city2", "The Big City"},
2922         {"bwall", "0 G like Psychic TV"},
2923         {"snow", "Wireframed"},
2924         {"telep", "Infinite Falling"},
2925         {"faces", "Facing Bases"},
2926         {"island", "Adventure Islands"},
2927 };
2928
2929 episode_t goodvsbad2episodes[] =
2930 {
2931         {"Levels? Bevels!", 0, 8},
2932 };
2933
2934 level_t battlemechlevels[] =
2935 {
2936         {"start", "Parking Level"},
2937         {"dm1", "Hot Dump"},                        // 1
2938         {"dm2", "The Pits"},
2939         {"dm3", "Dimber Died"},
2940         {"dm4", "Fire in the Hole"},
2941         {"dm5", "Clubhouses"},
2942         {"dm6", "Army go Underground"},
2943 };
2944
2945 episode_t battlemechepisodes[] =
2946 {
2947         {"Time for Battle", 0, 7},
2948 };
2949
2950 gamelevels_t sharewarequakegame = {"Shareware Quake", quakelevels, quakeepisodes, 2};
2951 gamelevels_t registeredquakegame = {"Quake", quakelevels, quakeepisodes, 7};
2952 gamelevels_t hipnoticgame = {"Scourge of Armagon", hipnoticlevels, hipnoticepisodes, 6};
2953 gamelevels_t roguegame = {"Dissolution of Eternity", roguelevels, rogueepisodes, 4};
2954 gamelevels_t nehahragame = {"Nehahra", nehahralevels, nehahraepisodes, 4};
2955 gamelevels_t transfusiongame = {"Transfusion", transfusionlevels, transfusionepisodes, 7};
2956 gamelevels_t goodvsbad2game = {"Good Vs. Bad 2", goodvsbad2levels, goodvsbad2episodes, 1};
2957 gamelevels_t battlemechgame = {"Battlemech", battlemechlevels, battlemechepisodes, 1};
2958
2959 typedef struct
2960 {
2961         int gameid;
2962         gamelevels_t *notregistered;
2963         gamelevels_t *registered;
2964 }
2965 gameinfo_t;
2966
2967 gameinfo_t gamelist[] =
2968 {
2969         {GAME_NORMAL, &sharewarequakegame, &registeredquakegame},
2970         {GAME_HIPNOTIC, &hipnoticgame, &hipnoticgame},
2971         {GAME_ROGUE, &roguegame, &roguegame},
2972         {GAME_NEHAHRA, &nehahragame, &nehahragame},
2973         {GAME_TRANSFUSION, &transfusiongame, &transfusiongame},
2974         {GAME_GOODVSBAD2, &goodvsbad2game, &goodvsbad2game},
2975         {GAME_BATTLEMECH, &battlemechgame, &battlemechgame},
2976         {-1, &sharewarequakegame, &registeredquakegame} // final fallback
2977 };
2978
2979 gamelevels_t *lookupgameinfo(void)
2980 {
2981         int i;
2982         for (i = 0;gamelist[i].gameid >= 0 && gamelist[i].gameid != gamemode;i++);
2983         if (registered.integer)
2984                 return gamelist[i].registered;
2985         else
2986                 return gamelist[i].notregistered;
2987 }
2988
2989 int     startepisode;
2990 int     startlevel;
2991 int maxplayers;
2992 qboolean m_serverInfoMessage = false;
2993 double m_serverInfoMessageTime;
2994
2995 extern cvar_t sv_public;
2996
2997 void M_Menu_GameOptions_f (void)
2998 {
2999         key_dest = key_menu;
3000         m_state = m_gameoptions;
3001         m_entersound = true;
3002         if (maxplayers == 0)
3003                 maxplayers = svs.maxclients;
3004         if (maxplayers < 2)
3005                 maxplayers = min(8, MAX_SCOREBOARD);
3006 }
3007
3008
3009 int gameoptions_cursor_table[] = {40, 56, 64, 72, 80, 88, 96, 104, 132, 152, 160};
3010 #define NUM_GAMEOPTIONS 11
3011 int             gameoptions_cursor;
3012
3013 void M_GameOptions_Draw (void)
3014 {
3015         cachepic_t      *p;
3016         int             x;
3017         gamelevels_t *g;
3018
3019         M_Background(320, 200);
3020
3021         M_DrawPic (16, 4, "gfx/qplaque.lmp");
3022         p = Draw_CachePic ("gfx/p_multi.lmp");
3023         M_DrawPic ( (320-p->width)/2, 4, "gfx/p_multi.lmp");
3024
3025         M_DrawTextBox (152, 32, 10, 1);
3026         M_Print (160, 40, "begin game");
3027
3028         M_Print (0, 56, "      Max players");
3029         M_Print (160, 56, va("%i", maxplayers) );
3030
3031         if (gamemode != GAME_GOODVSBAD2)
3032         {
3033                 M_Print (0, 64, "        Game Type");
3034                 if (gamemode == GAME_TRANSFUSION)
3035                 {
3036                         if (!deathmatch.integer)
3037                                 Cvar_SetValue("deathmatch", 1);
3038                         if (deathmatch.integer == 2)
3039                                 M_Print (160, 64, "Capture the Flag");
3040                         else
3041                                 M_Print (160, 64, "Blood Bath");
3042                 }
3043                 else if (gamemode == GAME_BATTLEMECH)
3044                 {
3045                         if (!deathmatch.integer)
3046                                 Cvar_SetValue("deathmatch", 1);
3047                         if (deathmatch.integer == 2)
3048                                 M_Print (160, 64, "Rambo Match");
3049                         else
3050                                 M_Print (160, 64, "Deathmatch");
3051                 }
3052                 else
3053                 {
3054                         if (!coop.integer && !deathmatch.integer)
3055                                 Cvar_SetValue("deathmatch", 1);
3056                         if (coop.integer)
3057                                 M_Print (160, 64, "Cooperative");
3058                         else
3059                                 M_Print (160, 64, "Deathmatch");
3060                 }
3061
3062                 M_Print (0, 72, "        Teamplay");
3063                 if (gamemode == GAME_ROGUE)
3064                 {
3065                         char *msg;
3066
3067                         switch((int)teamplay.integer)
3068                         {
3069                                 case 1: msg = "No Friendly Fire"; break;
3070                                 case 2: msg = "Friendly Fire"; break;
3071                                 case 3: msg = "Tag"; break;
3072                                 case 4: msg = "Capture the Flag"; break;
3073                                 case 5: msg = "One Flag CTF"; break;
3074                                 case 6: msg = "Three Team CTF"; break;
3075                                 default: msg = "Off"; break;
3076                         }
3077                         M_Print (160, 72, msg);
3078                 }
3079                 else
3080                 {
3081                         char *msg;
3082
3083                         switch (teamplay.integer)
3084                         {
3085                                 case 0: msg = "Off"; break;
3086                                 case 2: msg = "Friendly Fire"; break;
3087                                 default: msg = "No Friendly Fire"; break;
3088                         }
3089                         M_Print (160, 72, msg);
3090                 }
3091
3092                 M_Print (0, 80, "            Skill");
3093                 if (skill.integer == 0)
3094                         M_Print (160, 80, "Easy difficulty");
3095                 else if (skill.integer == 1)
3096                         M_Print (160, 80, "Normal difficulty");
3097                 else if (skill.integer == 2)
3098                         M_Print (160, 80, "Hard difficulty");
3099                 else
3100                         M_Print (160, 80, "Nightmare difficulty");
3101
3102                 M_Print (0, 88, "       Frag Limit");
3103                 if (fraglimit.integer == 0)
3104                         M_Print (160, 88, "none");
3105                 else
3106                         M_Print (160, 88, va("%i frags", fraglimit.integer));
3107
3108                 M_Print (0, 96, "       Time Limit");
3109                 if (timelimit.integer == 0)
3110                         M_Print (160, 96, "none");
3111                 else
3112                         M_Print (160, 96, va("%i minutes", timelimit.integer));
3113         }
3114
3115         M_Print (0, 104, "    Public server");
3116         M_Print (160, 104, (sv_public.integer == 0) ? "no" : "yes");
3117
3118         M_Print (0, 120, "      Server name");
3119         M_DrawTextBox (0, 124, 38, 1);
3120         M_Print (8, 132, hostname.string);
3121
3122         g = lookupgameinfo();
3123
3124         if (gamemode != GAME_GOODVSBAD2)
3125         {
3126                 M_Print (0, 152, "         Episode");
3127                 M_Print (160, 152, g->episodes[startepisode].description);
3128         }
3129
3130         M_Print (0, 160, "           Level");
3131         M_Print (160, 160, g->levels[g->episodes[startepisode].firstLevel + startlevel].description);
3132         M_Print (160, 168, g->levels[g->episodes[startepisode].firstLevel + startlevel].name);
3133
3134 // line cursor
3135         if (gameoptions_cursor == 8)
3136                 M_DrawCharacter (8 + 8 * strlen(hostname.string), gameoptions_cursor_table[gameoptions_cursor], 10+((int)(realtime*4)&1));
3137         else
3138                 M_DrawCharacter (144, gameoptions_cursor_table[gameoptions_cursor], 12+((int)(realtime*4)&1));
3139
3140         if (m_serverInfoMessage)
3141         {
3142                 if ((realtime - m_serverInfoMessageTime) < 5.0)
3143                 {
3144                         x = (320-26*8)/2;
3145                         M_DrawTextBox (x, 138, 24, 4);
3146                         x += 8;
3147                         M_Print (x, 146, " More than 64 players?? ");
3148                         M_Print (x, 154, "  First, question your  ");
3149                         M_Print (x, 162, "   sanity, then email   ");
3150                         M_Print (x, 170, " havoc@telefragged.com  ");
3151                 }
3152                 else
3153                         m_serverInfoMessage = false;
3154         }
3155 }
3156
3157
3158 void M_NetStart_Change (int dir)
3159 {
3160         gamelevels_t *g;
3161         int count;
3162
3163         switch (gameoptions_cursor)
3164         {
3165         case 1:
3166                 maxplayers += dir;
3167                 if (maxplayers > MAX_SCOREBOARD)
3168                 {
3169                         maxplayers = MAX_SCOREBOARD;
3170                         m_serverInfoMessage = true;
3171                         m_serverInfoMessageTime = realtime;
3172                 }
3173                 if (maxplayers < 2)
3174                         maxplayers = 2;
3175                 break;
3176
3177         case 2:
3178                 if (gamemode == GAME_GOODVSBAD2)
3179                         break;
3180                 if (gamemode == GAME_TRANSFUSION)
3181                 {
3182                         if (deathmatch.integer == 2) // changing from CTF to BloodBath
3183                                 Cvar_SetValueQuick (&deathmatch, 0);
3184                         else // changing from BloodBath to CTF
3185                                 Cvar_SetValueQuick (&deathmatch, 2);
3186                 }
3187                 else if (gamemode == GAME_BATTLEMECH)
3188                 {
3189                         if (deathmatch.integer == 2) // changing from Rambo to Deathmatch
3190                                 Cvar_SetValueQuick (&deathmatch, 0);
3191                         else // changing from Deathmatch to Rambo
3192                                 Cvar_SetValueQuick (&deathmatch, 2);
3193                 }
3194                 else
3195                 {
3196                         if (deathmatch.integer) // changing from deathmatch to coop
3197                         {
3198                                 Cvar_SetValueQuick (&coop, 1);
3199                                 Cvar_SetValueQuick (&deathmatch, 0);
3200                         }
3201                         else // changing from coop to deathmatch
3202                         {
3203                                 Cvar_SetValueQuick (&coop, 0);
3204                                 Cvar_SetValueQuick (&deathmatch, 1);
3205                         }
3206                 }
3207                 break;
3208
3209         case 3:
3210                 if (gamemode == GAME_GOODVSBAD2)
3211                         break;
3212                 if (gamemode == GAME_ROGUE)
3213                         count = 6;
3214                 else
3215                         count = 2;
3216
3217                 Cvar_SetValueQuick (&teamplay, teamplay.integer + dir);
3218                 if (teamplay.integer > count)
3219                         Cvar_SetValueQuick (&teamplay, 0);
3220                 else if (teamplay.integer < 0)
3221                         Cvar_SetValueQuick (&teamplay, count);
3222                 break;
3223
3224         case 4:
3225                 if (gamemode == GAME_GOODVSBAD2)
3226                         break;
3227                 Cvar_SetValueQuick (&skill, skill.integer + dir);
3228                 if (skill.integer > 3)
3229                         Cvar_SetValueQuick (&skill, 0);
3230                 if (skill.integer < 0)
3231                         Cvar_SetValueQuick (&skill, 3);
3232                 break;
3233
3234         case 5:
3235                 if (gamemode == GAME_GOODVSBAD2)
3236                         break;
3237                 Cvar_SetValueQuick (&fraglimit, fraglimit.integer + dir*10);
3238                 if (fraglimit.integer > 100)
3239                         Cvar_SetValueQuick (&fraglimit, 0);
3240                 if (fraglimit.integer < 0)
3241                         Cvar_SetValueQuick (&fraglimit, 100);
3242                 break;
3243
3244         case 6:
3245                 if (gamemode == GAME_GOODVSBAD2)
3246                         break;
3247                 Cvar_SetValueQuick (&timelimit, timelimit.value + dir*5);
3248                 if (timelimit.value > 60)
3249                         Cvar_SetValueQuick (&timelimit, 0);
3250                 if (timelimit.value < 0)
3251                         Cvar_SetValueQuick (&timelimit, 60);
3252                 break;
3253
3254         case 7:
3255                 Cvar_SetValueQuick (&sv_public, !sv_public.integer);
3256                 break;
3257
3258         case 8:
3259                 break;
3260
3261         case 9:
3262                 if (gamemode == GAME_GOODVSBAD2)
3263                         break;
3264                 startepisode += dir;
3265                 g = lookupgameinfo();
3266
3267                 if (startepisode < 0)
3268                         startepisode = g->numepisodes - 1;
3269
3270                 if (startepisode >= g->numepisodes)
3271                         startepisode = 0;
3272
3273                 startlevel = 0;
3274                 break;
3275
3276         case 10:
3277                 startlevel += dir;
3278                 g = lookupgameinfo();
3279
3280                 if (startlevel < 0)
3281                         startlevel = g->episodes[startepisode].levels - 1;
3282
3283                 if (startlevel >= g->episodes[startepisode].levels)
3284                         startlevel = 0;
3285                 break;
3286         }
3287 }
3288
3289 void M_GameOptions_Key (int key, char ascii)
3290 {
3291         gamelevels_t *g;
3292         int l;
3293         char hostnamebuf[128];
3294
3295         switch (key)
3296         {
3297         case K_ESCAPE:
3298                 M_Menu_MultiPlayer_f ();
3299                 break;
3300
3301         case K_UPARROW:
3302                 S_LocalSound ("misc/menu1.wav");
3303                 gameoptions_cursor--;
3304                 if (gameoptions_cursor < 0)
3305                         gameoptions_cursor = NUM_GAMEOPTIONS-1;
3306                 break;
3307
3308         case K_DOWNARROW:
3309                 S_LocalSound ("misc/menu1.wav");
3310                 gameoptions_cursor++;
3311                 if (gameoptions_cursor >= NUM_GAMEOPTIONS)
3312                         gameoptions_cursor = 0;
3313                 break;
3314
3315         case K_LEFTARROW:
3316                 if (gameoptions_cursor == 0)
3317                         break;
3318                 S_LocalSound ("misc/menu3.wav");
3319                 M_NetStart_Change (-1);
3320                 break;
3321
3322         case K_RIGHTARROW:
3323                 if (gameoptions_cursor == 0)
3324                         break;
3325                 S_LocalSound ("misc/menu3.wav");
3326                 M_NetStart_Change (1);
3327                 break;
3328
3329         case K_ENTER:
3330                 S_LocalSound ("misc/menu2.wav");
3331                 if (gameoptions_cursor == 0)
3332                 {
3333                         if (sv.active)
3334                                 Cbuf_AddText ("disconnect\n");
3335                         Cbuf_AddText ( va ("maxplayers %u\n", maxplayers) );
3336
3337                         g = lookupgameinfo();
3338                         Cbuf_AddText ( va ("map %s\n", g->levels[g->episodes[startepisode].firstLevel + startlevel].name) );
3339                         return;
3340                 }
3341
3342                 M_NetStart_Change (1);
3343                 break;
3344
3345         case K_BACKSPACE:
3346                 if (gameoptions_cursor == 8)
3347                 {
3348                         l = strlen(hostname.string);
3349                         if (l)
3350                         {
3351                                 l = min(l - 1, 37);
3352                                 memcpy(hostnamebuf, hostname.string, l);
3353                                 hostnamebuf[l] = 0;
3354                                 Cvar_Set("hostname", hostnamebuf);
3355                         }
3356                 }
3357                 break;
3358
3359         default:
3360                 if (ascii < 32 || ascii > 126)
3361                         break;
3362                 if (gameoptions_cursor == 8)
3363                 {
3364                         l = strlen(hostname.string);
3365                         if (l < 37)
3366                         {
3367                                 memcpy(hostnamebuf, hostname.string, l);
3368                                 hostnamebuf[l] = ascii;
3369                                 hostnamebuf[l+1] = 0;
3370                                 Cvar_Set("hostname", hostnamebuf);
3371                         }
3372                 }
3373         }
3374 }
3375
3376 //=============================================================================
3377 /* SLIST MENU */
3378
3379 int slist_cursor;
3380
3381 void M_Menu_ServerList_f (void)
3382 {
3383         key_dest = key_menu;
3384         m_state = m_slist;
3385         m_entersound = true;
3386         slist_cursor = 0;
3387         m_return_reason[0] = 0;
3388         Net_Slist_f();
3389 }
3390
3391
3392 void M_ServerList_Draw (void)
3393 {
3394         int n, y, visible, start, end;
3395         cachepic_t *p;
3396         const char *s;
3397
3398         // use as much vertical space as available
3399         M_Background(640, vid.conheight);
3400         // scroll the list as the cursor moves
3401         s = va("%i/%i masters %i/%i servers", masterreplycount, masterquerycount, serverreplycount, serverquerycount);
3402         M_PrintRed((640 - strlen(s) * 8) / 2, 32, s);
3403         if (*m_return_reason)
3404                 M_Print(16, vid.conheight - 8, m_return_reason);
3405         y = 48;
3406         visible = (vid.conheight - 16 - y) / 8;
3407         start = bound(0, slist_cursor - (visible >> 1), hostCacheCount - visible);
3408         end = min(start + visible, hostCacheCount);
3409
3410         p = Draw_CachePic("gfx/p_multi.lmp");
3411         M_DrawPic((640 - p->width) / 2, 4, "gfx/p_multi.lmp");
3412         if (end > start)
3413         {
3414                 for (n = start;n < end;n++)
3415                 {
3416                         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);
3417                         M_Print(0, y, hostcache[n].line1);y += 8;
3418                         M_Print(0, y, hostcache[n].line2);y += 8;
3419                 }
3420         }
3421         else if (realtime - masterquerytime < 3)
3422         {
3423                 if (masterquerycount)
3424                         M_Print(0, y, "No servers found");
3425                 else
3426                         M_Print(0, y, "No master servers found (network problem?)");
3427         }
3428 }
3429
3430
3431 void M_ServerList_Key(int k, char ascii)
3432 {
3433         switch (k)
3434         {
3435         case K_ESCAPE:
3436                 M_Menu_LanConfig_f();
3437                 break;
3438
3439         case K_SPACE:
3440                 Net_Slist_f();
3441                 break;
3442
3443         case K_UPARROW:
3444         case K_LEFTARROW:
3445                 S_LocalSound("misc/menu1.wav");
3446                 slist_cursor--;
3447                 if (slist_cursor < 0)
3448                         slist_cursor = hostCacheCount - 1;
3449                 break;
3450
3451         case K_DOWNARROW:
3452         case K_RIGHTARROW:
3453                 S_LocalSound("misc/menu1.wav");
3454                 slist_cursor++;
3455                 if (slist_cursor >= hostCacheCount)
3456                         slist_cursor = 0;
3457                 break;
3458
3459         case K_ENTER:
3460                 S_LocalSound("misc/menu2.wav");
3461                 Cbuf_AddText(va("connect \"%s\"\n", hostcache[slist_cursor].cname));
3462                 break;
3463
3464         default:
3465                 break;
3466         }
3467
3468 }
3469
3470 //=============================================================================
3471 /* Menu Subsystem */
3472
3473 void M_Keydown(int key, char ascii);
3474 void M_Draw(void);
3475 void M_ToggleMenu_f(void);
3476 void M_Shutdown(void);
3477
3478 void M_Init (void)
3479 {
3480         menu_mempool = Mem_AllocPool("Menu");
3481         menuplyr_load = true;
3482         menuplyr_pixels = NULL;
3483
3484         Cmd_AddCommand ("menu_main", M_Menu_Main_f);
3485         Cmd_AddCommand ("menu_singleplayer", M_Menu_SinglePlayer_f);
3486         Cmd_AddCommand ("menu_load", M_Menu_Load_f);
3487         Cmd_AddCommand ("menu_save", M_Menu_Save_f);
3488         Cmd_AddCommand ("menu_multiplayer", M_Menu_MultiPlayer_f);
3489         Cmd_AddCommand ("menu_setup", M_Menu_Setup_f);
3490         Cmd_AddCommand ("menu_options", M_Menu_Options_f);
3491         Cmd_AddCommand ("menu_options_effects", M_Menu_Options_Effects_f);
3492         Cmd_AddCommand ("menu_options_colorcontrol", M_Menu_Options_ColorControl_f);
3493         Cvar_RegisterVariable (&menu_options_colorcontrol_correctionvalue);
3494         Cmd_AddCommand ("menu_keys", M_Menu_Keys_f);
3495         Cmd_AddCommand ("menu_video", M_Menu_Video_f);
3496         Cmd_AddCommand ("help", M_Menu_Help_f);
3497         Cmd_AddCommand ("menu_quit", M_Menu_Quit_f);
3498
3499         if (gamemode == GAME_TRANSFUSION)
3500         {
3501                 numcommands = sizeof(transfusionbindnames) / sizeof(transfusionbindnames[0]);
3502                 bindnames = transfusionbindnames;
3503         }
3504         else if (gamemode == GAME_GOODVSBAD2)
3505         {
3506                 numcommands = sizeof(goodvsbad2bindnames) / sizeof(goodvsbad2bindnames[0]);
3507                 bindnames = goodvsbad2bindnames;
3508         }
3509         else
3510         {
3511                 numcommands = sizeof(quakebindnames) / sizeof(quakebindnames[0]);
3512                 bindnames = quakebindnames;
3513         }
3514
3515         // Make sure "keys_cursor" doesn't start on a section in the binding list
3516         keys_cursor = 0;
3517         while (bindnames[keys_cursor][0][0] == '\0')
3518         {
3519                 keys_cursor++;
3520
3521                 // Only sections? There may be a problem somewhere...
3522                 if (keys_cursor >= numcommands)
3523                         Sys_Error ("M_Init: The key binding list only contains sections");
3524         }
3525
3526
3527         if (gamemode == GAME_NEHAHRA)
3528         {
3529                 if (FS_FileExists("maps/neh1m4.bsp"))
3530                 {
3531                         if (FS_FileExists("hearing.dem"))
3532                         {
3533                                 Con_Printf("Nehahra movie and game detected.\n");
3534                                 NehGameType = TYPE_BOTH;
3535                         }
3536                         else
3537                         {
3538                                 Con_Printf("Nehahra game detected.\n");
3539                                 NehGameType = TYPE_GAME;
3540                         }
3541                 }
3542                 else
3543                 {
3544                         if (FS_FileExists("hearing.dem"))
3545                         {
3546                                 Con_Printf("Nehahra movie detected.\n");
3547                                 NehGameType = TYPE_DEMO;
3548                         }
3549                         else
3550                         {
3551                                 Con_Printf("Nehahra not found.\n");
3552                                 NehGameType = TYPE_GAME; // could just complain, but...
3553                         }
3554                 }
3555         }
3556 }
3557
3558 void M_Draw (void)
3559 {
3560         if (key_dest != key_menu)
3561                 m_state = m_none;
3562
3563         if (m_state == m_none)
3564                 return;
3565
3566         switch (m_state)
3567         {
3568         case m_none:
3569                 break;
3570
3571         case m_main:
3572                 M_Main_Draw ();
3573                 break;
3574
3575         case m_demo:
3576                 M_Demo_Draw ();
3577                 break;
3578
3579         case m_singleplayer:
3580                 M_SinglePlayer_Draw ();
3581                 break;
3582
3583         case m_load:
3584                 M_Load_Draw ();
3585                 break;
3586
3587         case m_save:
3588                 M_Save_Draw ();
3589                 break;
3590
3591         case m_multiplayer:
3592                 M_MultiPlayer_Draw ();
3593                 break;
3594
3595         case m_setup:
3596                 M_Setup_Draw ();
3597                 break;
3598
3599         case m_options:
3600                 M_Options_Draw ();
3601                 break;
3602
3603         case m_options_effects:
3604                 M_Options_Effects_Draw ();
3605                 break;
3606
3607         case m_options_colorcontrol:
3608                 M_Options_ColorControl_Draw ();
3609                 break;
3610
3611         case m_keys:
3612                 M_Keys_Draw ();
3613                 break;
3614
3615         case m_video:
3616                 M_Video_Draw ();
3617                 break;
3618
3619         case m_help:
3620                 M_Help_Draw ();
3621                 break;
3622
3623         case m_quit:
3624                 M_Quit_Draw ();
3625                 break;
3626
3627         case m_lanconfig:
3628                 M_LanConfig_Draw ();
3629                 break;
3630
3631         case m_gameoptions:
3632                 M_GameOptions_Draw ();
3633                 break;
3634
3635         case m_slist:
3636                 M_ServerList_Draw ();
3637                 break;
3638         }
3639
3640         if (m_entersound)
3641         {
3642                 S_LocalSound ("misc/menu2.wav");
3643                 m_entersound = false;
3644         }
3645
3646         S_ExtraUpdate ();
3647 }
3648
3649
3650 void M_Keydown (int key, char ascii)
3651 {
3652         switch (m_state)
3653         {
3654         case m_none:
3655                 return;
3656
3657         case m_main:
3658                 M_Main_Key (key, ascii);
3659                 return;
3660
3661         case m_demo:
3662                 M_Demo_Key (key, ascii);
3663                 return;
3664
3665         case m_singleplayer:
3666                 M_SinglePlayer_Key (key, ascii);
3667                 return;
3668
3669         case m_load:
3670                 M_Load_Key (key, ascii);
3671                 return;
3672
3673         case m_save:
3674                 M_Save_Key (key, ascii);
3675                 return;
3676
3677         case m_multiplayer:
3678                 M_MultiPlayer_Key (key, ascii);
3679                 return;
3680
3681         case m_setup:
3682                 M_Setup_Key (key, ascii);
3683                 return;
3684
3685         case m_options:
3686                 M_Options_Key (key, ascii);
3687                 return;
3688
3689         case m_options_effects:
3690                 M_Options_Effects_Key (key, ascii);
3691                 return;
3692
3693         case m_options_colorcontrol:
3694                 M_Options_ColorControl_Key (key, ascii);
3695                 return;
3696
3697         case m_keys:
3698                 M_Keys_Key (key, ascii);
3699                 return;
3700
3701         case m_video:
3702                 M_Video_Key (key, ascii);
3703                 return;
3704
3705         case m_help:
3706                 M_Help_Key (key, ascii);
3707                 return;
3708
3709         case m_quit:
3710                 M_Quit_Key (key, ascii);
3711                 return;
3712
3713         case m_lanconfig:
3714                 M_LanConfig_Key (key, ascii);
3715                 return;
3716
3717         case m_gameoptions:
3718                 M_GameOptions_Key (key, ascii);
3719                 return;
3720
3721         case m_slist:
3722                 M_ServerList_Key (key, ascii);
3723                 return;
3724         }
3725 }
3726
3727 void M_Shutdown(void)
3728 {
3729         // reset key_dest
3730         key_dest = key_game;
3731 }
3732
3733 void M_Restart(void)
3734 {
3735 }
3736
3737 //============================================================================
3738 // Menu prog handling
3739 mfunction_t *PRVM_ED_FindFunction(const char *);
3740
3741 #define M_F_INIT                "m_init"
3742 #define M_F_KEYDOWN             "m_keydown"
3743 #define M_F_DRAW                "m_draw"
3744 #define M_F_TOGGLE              "m_toggle"
3745 #define M_F_SHUTDOWN    "m_shutdown"
3746
3747 static char *m_required_func[] = {
3748 M_F_INIT,
3749 M_F_KEYDOWN,
3750 M_F_DRAW,
3751 M_F_TOGGLE,
3752 M_F_SHUTDOWN,
3753 };
3754
3755 static int m_numrequiredfunc = sizeof(m_required_func) / sizeof(char*);
3756
3757 static func_t m_draw,m_keydown;
3758
3759 void MR_SetRouting (qboolean forceold);
3760
3761 void MP_Error(void)
3762 {
3763         // fall back to the normal menu
3764
3765         // say it
3766         Con_Printf("Falling back to normal menu\n");
3767
3768         key_dest = key_game;
3769
3770         //PRVM_ResetProg();
3771
3772         // init the normal menu now -> this will also correct the menu router pointers
3773         MR_SetRouting (TRUE);
3774 }
3775
3776 void MP_Keydown (int key, char ascii)
3777 {
3778         PRVM_Begin;
3779         PRVM_SetProg(PRVM_MENUPROG);
3780
3781         // set time
3782         *prog->time = realtime;
3783
3784         // pass key
3785         prog->globals[OFS_PARM0] = (float) key;
3786         prog->globals[OFS_PARM1] = (float) ascii;
3787         PRVM_ExecuteProgram(m_keydown, M_F_KEYDOWN"(float key, float ascii) required\n");
3788
3789         PRVM_End;
3790 }
3791
3792 void MP_Draw (void)
3793 {
3794         PRVM_Begin;
3795         PRVM_SetProg(PRVM_MENUPROG);
3796
3797         // set time
3798         *prog->time = realtime;
3799
3800         PRVM_ExecuteProgram(m_draw,"");
3801
3802         PRVM_End;
3803 }
3804
3805 void MP_ToggleMenu_f (void)
3806 {
3807         PRVM_Begin;
3808         PRVM_SetProg(PRVM_MENUPROG);
3809
3810         // set time
3811         *prog->time = realtime;
3812
3813         PRVM_ExecuteProgram((func_t) (PRVM_ED_FindFunction(M_F_TOGGLE) - prog->functions),"");
3814
3815         PRVM_End;
3816 }
3817
3818 void MP_Shutdown (void)
3819 {
3820         PRVM_Begin;
3821         PRVM_SetProg(PRVM_MENUPROG);
3822
3823         // set time
3824         *prog->time = realtime;
3825
3826         PRVM_ExecuteProgram((func_t) (PRVM_ED_FindFunction(M_F_SHUTDOWN) - prog->functions),"");
3827
3828         // reset key_dest
3829         key_dest = key_game;
3830
3831         // AK not using this cause Im not sure whether this is useful at all instead :
3832         PRVM_ResetProg();
3833
3834         PRVM_End;
3835 }
3836
3837 void MP_Init (void)
3838 {
3839         PRVM_Begin;
3840         PRVM_InitProg(PRVM_MENUPROG);
3841
3842         prog->crc = M_PROGHEADER_CRC;
3843         prog->edictprivate_size = 0; // no private struct used
3844         prog->name = M_NAME;
3845         prog->limit_edicts = M_MAX_EDICTS;
3846         prog->extensionstring = vm_m_extensions;
3847         prog->builtins = vm_m_builtins;
3848         prog->numbuiltins = vm_m_numbuiltins;
3849         prog->init_cmd = VM_M_Cmd_Init;
3850         prog->reset_cmd = VM_M_Cmd_Reset;
3851         prog->error_cmd = MP_Error;
3852
3853         // allocate the mempools
3854         prog->edicts_mempool = Mem_AllocPool(M_NAME " edicts mempool");
3855         prog->edictstring_mempool = Mem_AllocPool( M_NAME " edict string mempool");
3856         prog->progs_mempool = Mem_AllocPool(M_PROG_FILENAME);
3857
3858         PRVM_LoadProgs(M_PROG_FILENAME, m_numrequiredfunc, m_required_func);
3859
3860         // set m_draw and m_keydown
3861         m_draw = (func_t) (PRVM_ED_FindFunction(M_F_DRAW) - prog->functions);
3862         m_keydown = (func_t) (PRVM_ED_FindFunction(M_F_KEYDOWN) - prog->functions);
3863
3864         // set time
3865         *prog->time = realtime;
3866
3867         // call the prog init
3868         PRVM_ExecuteProgram((func_t) (PRVM_ED_FindFunction(M_F_INIT) - prog->functions),"");
3869
3870         PRVM_End;
3871 }
3872
3873 void MP_Restart(void)
3874 {
3875
3876         MP_Init();
3877 }
3878
3879 //============================================================================
3880 // Menu router
3881
3882 static cvar_t forceqmenu = { 0, "forceqmenu", "0" };
3883
3884 void MR_SetRouting(qboolean forceold)
3885 {
3886         static qboolean m_init = FALSE, mp_init = FALSE;
3887
3888         // if the menu prog isnt available or forceqmenu ist set, use the old menu
3889         if(!FS_FileExists(M_PROG_FILENAME) || forceqmenu.integer || forceold)
3890         {
3891                 // set menu router function pointers
3892                 MR_Keydown = M_Keydown;
3893                 MR_Draw = M_Draw;
3894                 MR_ToggleMenu_f = M_ToggleMenu_f;
3895                 MR_Shutdown = M_Shutdown;
3896
3897                 // init
3898                 if(!m_init)
3899                 {
3900                         M_Init();
3901                         m_init = TRUE;
3902                 }
3903                 else
3904                         M_Restart();
3905         }
3906         else
3907         {
3908                 // set menu router function pointers
3909                 MR_Keydown = MP_Keydown;
3910                 MR_Draw = MP_Draw;
3911                 MR_ToggleMenu_f = MP_ToggleMenu_f;
3912                 MR_Shutdown = MP_Shutdown;
3913
3914                 if(!mp_init)
3915                 {
3916                         MP_Init();
3917                         mp_init = TRUE;
3918                 }
3919                 else
3920                         MP_Restart();
3921         }
3922 }
3923
3924 void MR_Restart(void)
3925 {
3926         MR_Shutdown ();
3927         MR_SetRouting (FALSE);
3928 }
3929
3930 void Call_MR_ToggleMenu_f(void)
3931 {
3932         if(MR_ToggleMenu_f)
3933                 MR_ToggleMenu_f();
3934 }
3935
3936 void MR_Init()
3937 {
3938         // set router console commands
3939         Cvar_RegisterVariable (&forceqmenu);
3940         Cmd_AddCommand ("menu_restart",MR_Restart);
3941         Cmd_AddCommand ("togglemenu", Call_MR_ToggleMenu_f);
3942
3943         // use -forceqmenu to use always the normal quake menu (it sets forceqmenu to 1)
3944         if(COM_CheckParm("-forceqmenu"))
3945                 Cvar_SetValueQuick(&forceqmenu,1);
3946         // use -useqmenu for debugging proposes, cause it starts
3947         // the normal quake menu only the first time
3948         else if(COM_CheckParm("-useqmenu"))
3949                 MR_SetRouting (TRUE);
3950         else
3951                 MR_SetRouting (FALSE);
3952 }
3953
3954
3955
3956