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