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