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