]> de.git.xonotic.org Git - xonotic/darkplaces.git/blob - menu.c
fix for misnumbered video mode menu in menu key code (it should never be misnumbered...
[xonotic/darkplaces.git] / menu.c
1 /*
2 Copyright (C) 1996-1997 Id Software, Inc.
3
4 This program is free software; you can redistribute it and/or
5 modify it under the terms of the GNU General Public License
6 as published by the Free Software Foundation; either version 2
7 of the License, or (at your option) any later version.
8
9 This program is distributed in the hope that it will be useful,
10 but WITHOUT ANY WARRANTY; without even the implied warranty of
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  
12
13 See the GNU General Public License for more details.
14
15 You should have received a copy of the GNU General Public License
16 along with this program; if not, write to the Free Software
17 Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
18
19 */
20 #include "quakedef.h"
21
22 #ifdef _WIN32
23 #include "winquake.h"
24 #endif
25
26 void (*vid_menudrawfn)(void);
27 void (*vid_menukeyfn)(int key);
28
29 #define TYPE_DEMO 1
30 #define TYPE_GAME 2
31 #define TYPE_BOTH 3
32
33 int NehGameType;
34
35 enum m_state_e m_state;
36
37 void M_Menu_Main_f (void);
38         void M_Menu_SinglePlayer_f (void);
39                 void M_Menu_Load_f (void);
40                 void M_Menu_Save_f (void);
41         void M_Menu_MultiPlayer_f (void);
42                 void M_Menu_Setup_f (void);
43                 void M_Menu_Net_f (void);
44         void M_Menu_Options_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_Search_f (void);
52 void M_Menu_ServerList_f (void);
53
54 void M_Main_Draw (void);
55         void M_SinglePlayer_Draw (void);
56                 void M_Load_Draw (void);
57                 void M_Save_Draw (void);
58         void M_MultiPlayer_Draw (void);
59                 void M_Setup_Draw (void);
60                 void M_Net_Draw (void);
61         void M_Options_Draw (void);
62                 void M_Keys_Draw (void);
63                 void M_Video_Draw (void);
64         void M_Help_Draw (void);
65         void M_Quit_Draw (void);
66 void M_LanConfig_Draw (void);
67 void M_GameOptions_Draw (void);
68 void M_Search_Draw (void);
69 void M_ServerList_Draw (void);
70
71 void M_Main_Key (int key);
72         void M_SinglePlayer_Key (int key);
73                 void M_Load_Key (int key);
74                 void M_Save_Key (int key);
75         void M_MultiPlayer_Key (int key);
76                 void M_Setup_Key (int key);
77                 void M_Net_Key (int key);
78         void M_Options_Key (int key);
79                 void M_Keys_Key (int key);
80                 void M_Video_Key (int key);
81         void M_Help_Key (int key);
82         void M_Quit_Key (int key);
83 void M_LanConfig_Key (int key);
84 void M_GameOptions_Key (int key);
85 void M_Search_Key (int key);
86 void M_ServerList_Key (int key);
87
88 qboolean        m_entersound;           // play after drawing a frame, so caching
89                                                                 // won't disrupt the sound
90 //qboolean      m_recursiveDraw;
91
92 int                     m_return_state;
93 qboolean        m_return_onerror;
94 char            m_return_reason [32];
95
96 #define StartingGame    (m_multiplayer_cursor == 1)
97 #define JoiningGame             (m_multiplayer_cursor == 0)
98 #define IPXConfig               (m_net_cursor == 0)
99 #define TCPIPConfig             (m_net_cursor == 1)
100
101 void M_ConfigureNetSubsystem(void);
102
103 // Nehahra
104 int NumberOfDemos;
105 typedef struct
106 {
107         char name[50];
108         char desc[50];
109 } demonames_t;
110
111 demonames_t Demos[35];
112
113 /*
114 ================
115 M_DrawCharacter
116
117 Draws one solid graphics character
118 ================
119 */
120 void M_DrawCharacter (int cx, int line, int num)
121 {
122         Draw_Character ( cx + ((vid.width - 320)>>1), line, num);
123 }
124
125 void M_Print (int cx, int cy, char *str)
126 {
127         while (*str)
128         {
129                 M_DrawCharacter (cx, cy, (*str)+128);
130                 str++;
131                 cx += 8;
132         }
133 }
134
135 void M_PrintWhite (int cx, int cy, char *str)
136 {
137         while (*str)
138         {
139                 M_DrawCharacter (cx, cy, *str);
140                 str++;
141                 cx += 8;
142         }
143 }
144
145 void M_DrawPic (int x, int y, qpic_t *pic)
146 {
147         Draw_Pic (x + ((vid.width - 320)>>1), y, pic);
148 }
149
150 byte identityTable[256];
151 byte translationTable[256];
152
153 void M_BuildTranslationTable(int top, int bottom)
154 {
155         int             j;
156         byte    *dest, *source;
157
158         for (j = 0; j < 256; j++)
159                 identityTable[j] = j;
160         dest = translationTable;
161         source = identityTable;
162         memcpy (dest, source, 256);
163
164         // LordHavoc: corrected skin color ranges
165         if (top < 128 || (top >= 224 && top < 240))     // the artists made some backwards ranges.  sigh.
166                 memcpy (dest + TOP_RANGE, source + top, 16);
167         else
168                 for (j=0 ; j<16 ; j++)
169                         dest[TOP_RANGE+j] = source[top+15-j];
170
171         // LordHavoc: corrected skin color ranges
172         if (bottom < 128 || (bottom >= 224 && bottom < 240))
173                 memcpy (dest + BOTTOM_RANGE, source + bottom, 16);
174         else
175                 for (j=0 ; j<16 ; j++)
176                         dest[BOTTOM_RANGE+j] = source[bottom+15-j];
177 }
178
179
180 void M_DrawPicTranslate (int x, int y, qpic_t *pic)
181 {
182         Draw_PicTranslate (x + ((vid.width - 320)>>1), y, pic, translationTable);
183 }
184
185
186 void M_DrawTextBox (int x, int y, int width, int lines)
187 {
188         qpic_t  *p;
189         int             cx, cy;
190         int             n;
191
192         // draw left side
193         cx = x;
194         cy = y;
195         p = Draw_CachePic ("gfx/box_tl.lmp");
196         M_DrawPic (cx, cy, p);
197         p = Draw_CachePic ("gfx/box_ml.lmp");
198         for (n = 0; n < lines; n++)
199         {
200                 cy += 8;
201                 M_DrawPic (cx, cy, p);
202         }
203         p = Draw_CachePic ("gfx/box_bl.lmp");
204         M_DrawPic (cx, cy+8, p);
205
206         // draw middle
207         cx += 8;
208         while (width > 0)
209         {
210                 cy = y;
211                 p = Draw_CachePic ("gfx/box_tm.lmp");
212                 M_DrawPic (cx, cy, p);
213                 p = Draw_CachePic ("gfx/box_mm.lmp");
214                 for (n = 0; n < lines; n++)
215                 {
216                         cy += 8;
217                         if (n == 1)
218                                 p = Draw_CachePic ("gfx/box_mm2.lmp");
219                         M_DrawPic (cx, cy, p);
220                 }
221                 p = Draw_CachePic ("gfx/box_bm.lmp");
222                 M_DrawPic (cx, cy+8, p);
223                 width -= 2;
224                 cx += 16;
225         }
226
227         // draw right side
228         cy = y;
229         p = Draw_CachePic ("gfx/box_tr.lmp");
230         M_DrawPic (cx, cy, p);
231         p = Draw_CachePic ("gfx/box_mr.lmp");
232         for (n = 0; n < lines; n++)
233         {
234                 cy += 8;
235                 M_DrawPic (cx, cy, p);
236         }
237         p = Draw_CachePic ("gfx/box_br.lmp");
238         M_DrawPic (cx, cy+8, p);
239 }
240
241 //=============================================================================
242
243 int m_save_demonum;
244
245 /*
246 ================
247 M_ToggleMenu_f
248 ================
249 */
250 void M_ToggleMenu_f (void)
251 {
252         m_entersound = true;
253
254         if (key_dest == key_menu)
255         {
256                 if (m_state != m_main)
257                 {
258                         M_Menu_Main_f ();
259                         return;
260                 }
261                 key_dest = key_game;
262                 m_state = m_none;
263                 return;
264         }
265         if (key_dest == key_console)
266         {
267                 Con_ToggleConsole_f ();
268         }
269         else
270         {
271                 M_Menu_Main_f ();
272         }
273 }
274
275 // LordHavoc: FIXME: finish this menu stuff
276 #if 0
277 #define MAXMENUITEMS 128
278
279 typedef struct menuitem_s
280 {
281         char *string; // may be text, or an image to use, or a cvar name, depending on the functions used
282         char *description;
283         char *command; // used by command items mainly (when used, this command is executed)
284         cvar_t *cvar; // used for cvar items (sliders, number boxes), value is retrieved from the cvar itself
285         int selectable; // purely decorative if this is false
286         int selected; // true if this menu item is currently selected, used by funcs so they don't need to know anything but fields in the menuitem
287         float selecttime; // the time that this menu item was activated (copied from realtime), used for animating selection flashs and such
288         float color[4]; // current color for the item (may be different than base color, due to selection flash effects)
289         float basecolor[4]; // the base color
290         float x, y, width, height; // width and height are used for mouse selection
291         void(*drawfunc)(struct menuitem_s *item);
292         void(*activefunc)(struct menuitem_s *item);
293 //      void(*selectfunc)(struct menuitem_s *item);
294 //      void(*deselectfunc)(struct menuitem_s *item);
295         void(*usefunc)(struct menuitem_s *item);
296 }
297 menuitem_t;
298
299 menuitem_t menuitem[MAXMENUITEMS];
300 int menuitems;
301
302 void menuitem_text_drawfunc(struct menuitem_s *item)
303 {
304         // FIXME: handle color flashs and such when selected
305         M_Print (item->x, item->y, item->string);
306 }
307
308 void menuitem_image_drawfunc(struct menuitem_s *item)
309 {
310         qpic_t *p = Draw_CachePic (item->string);
311         // FIXME: handle color flashs and such when selected
312         M_DrawPic (item->x, item->y, p);
313 }
314
315 void menuitem_command_usefunc(struct menuitem_s *item)
316 {
317         Cbuf_AddText (item->command);
318 }
319 #endif
320
321 int demo_cursor;
322 void M_Demo_Draw (void)
323 {
324         int             i;
325
326         for (i=0; i < NumberOfDemos; i++)
327                 M_Print (16, 16 + 8*i, Demos[i].desc);
328
329         // line cursor
330         M_DrawCharacter (8, 16 + demo_cursor*8, 12+((int)(realtime*4)&1));
331 }
332
333
334 void M_Menu_Demos_f (void)
335 {
336         key_dest = key_menu;
337         m_state = m_demo;
338         m_entersound = true;
339
340
341         NumberOfDemos = 34;
342
343         strcpy(Demos[0].name,  "intro");         strcpy(Demos[0].desc,  "Prologue");
344         strcpy(Demos[1].name,  "genf");          strcpy(Demos[1].desc,  "The Beginning");
345         strcpy(Demos[2].name,  "genlab");        strcpy(Demos[2].desc,  "A Doomed Project");
346         strcpy(Demos[3].name,  "nehcre");        strcpy(Demos[3].desc,  "The New Recruits");
347         strcpy(Demos[4].name,  "maxneh");        strcpy(Demos[4].desc,  "Breakthrough");
348         strcpy(Demos[5].name,  "maxchar");       strcpy(Demos[5].desc,  "Renewal and Duty");
349         strcpy(Demos[6].name,  "crisis");        strcpy(Demos[6].desc,  "Worlds Collide");
350         strcpy(Demos[7].name,  "postcris");      strcpy(Demos[7].desc,  "Darkening Skies");
351         strcpy(Demos[8].name,  "hearing");       strcpy(Demos[8].desc,  "The Hearing");
352         strcpy(Demos[9].name,  "getjack");       strcpy(Demos[9].desc,  "On a Mexican Radio");
353         strcpy(Demos[10].name, "prelude");       strcpy(Demos[10].desc, "Honor and Justice");
354         strcpy(Demos[11].name, "abase");         strcpy(Demos[11].desc, "A Message Sent");
355         strcpy(Demos[12].name, "effect");        strcpy(Demos[12].desc, "The Other Side");
356         strcpy(Demos[13].name, "uhoh");          strcpy(Demos[13].desc, "Missing in Action");
357         strcpy(Demos[14].name, "prepare");       strcpy(Demos[14].desc, "The Response");
358         strcpy(Demos[15].name, "vision");        strcpy(Demos[15].desc, "Farsighted Eyes");
359         strcpy(Demos[16].name, "maxturns");      strcpy(Demos[16].desc, "Enter the Immortal");
360         strcpy(Demos[17].name, "backlot");       strcpy(Demos[17].desc, "Separate Ways");
361         strcpy(Demos[18].name, "maxside");       strcpy(Demos[18].desc, "The Ancient Runes");
362         strcpy(Demos[19].name, "counter");       strcpy(Demos[19].desc, "The New Initiative");
363         strcpy(Demos[20].name, "warprep");       strcpy(Demos[20].desc, "Ghosts to the World");
364         strcpy(Demos[21].name, "counter1");      strcpy(Demos[21].desc, "A Fate Worse Than Death");
365         strcpy(Demos[22].name, "counter2");      strcpy(Demos[22].desc, "Friendly Fire");
366         strcpy(Demos[23].name, "counter3");      strcpy(Demos[23].desc, "Minor Setback");
367         strcpy(Demos[24].name, "madmax");        strcpy(Demos[24].desc, "Scores to Settle");
368         strcpy(Demos[25].name, "quake");         strcpy(Demos[25].desc, "One Man");
369         strcpy(Demos[26].name, "cthmm");         strcpy(Demos[26].desc, "Shattered Masks");
370         strcpy(Demos[27].name, "shades");        strcpy(Demos[27].desc, "Deal with the Dead");
371         strcpy(Demos[28].name, "gophil");        strcpy(Demos[28].desc, "An Unlikely Hero");
372         strcpy(Demos[29].name, "cstrike");       strcpy(Demos[29].desc, "War in Hell");
373         strcpy(Demos[30].name, "shubset");       strcpy(Demos[30].desc, "The Conspiracy");
374         strcpy(Demos[31].name, "shubdie");       strcpy(Demos[31].desc, "Even Death May Die");
375         strcpy(Demos[32].name, "newranks");      strcpy(Demos[32].desc, "An Empty Throne");
376         strcpy(Demos[33].name, "seal");          strcpy(Demos[33].desc, "The Seal is Broken");
377 }
378
379 void M_Demo_Key (int k)
380 {
381         switch (k)
382         {
383         case K_ESCAPE:
384                 M_Menu_Main_f ();
385                 break;
386
387         case K_ENTER:
388                 S_LocalSound ("misc/menu2.wav");
389                 m_state = m_none;
390                 key_dest = key_game;
391 //              SCR_BeginLoadingPlaque ();
392                 Cbuf_AddText (va ("playdemo %s\n", Demos[demo_cursor].name));
393                 return;
394
395         case K_UPARROW:
396         case K_LEFTARROW:
397                 S_LocalSound ("misc/menu1.wav");
398                 demo_cursor--;
399                 if (demo_cursor < 0)
400                         demo_cursor = NumberOfDemos;
401                 break;
402
403         case K_DOWNARROW:
404         case K_RIGHTARROW:
405                 S_LocalSound ("misc/menu1.wav");
406                 demo_cursor++;
407                 if (demo_cursor > NumberOfDemos)
408                         demo_cursor = 0;
409                 break;
410         }
411 }
412
413 //=============================================================================
414 /* MAIN MENU */
415
416 int     m_main_cursor;
417 //#define       MAIN_ITEMS      5
418
419 int MAIN_ITEMS = 4; // Nehahra: Menu Disable
420
421 void M_Menu_Main_f (void)
422 {
423         if (nehahra)
424         {
425                 if (NehGameType == TYPE_DEMO)
426                         MAIN_ITEMS = 4;
427                 else if (NehGameType == TYPE_GAME)
428                         MAIN_ITEMS = 5;
429                 else
430                         MAIN_ITEMS = 6;
431         }
432         else
433                 MAIN_ITEMS = 5;
434
435         if (key_dest != key_menu)
436         {
437                 m_save_demonum = cls.demonum;
438                 cls.demonum = -1;
439         }
440         key_dest = key_menu;
441         m_state = m_main;
442         m_entersound = true;
443 }
444
445
446 void M_Main_Draw (void)
447 {
448         int             f;
449         qpic_t  *p;
450
451         M_DrawPic (16, 4, Draw_CachePic ("gfx/qplaque.lmp") );
452         p = Draw_CachePic ("gfx/ttl_main.lmp");
453         M_DrawPic ( (320-p->width)/2, 4, p);
454 // Nehahra
455         if (nehahra)
456         {
457                 if (NehGameType == TYPE_BOTH)
458                         M_DrawPic (72, 32, Draw_CachePic ("gfx/mainmenu.lmp"));
459                 else if (NehGameType == TYPE_GAME)
460                         M_DrawPic (72, 32, Draw_CachePic ("gfx/gamemenu.lmp"));
461                 else
462                         M_DrawPic (72, 32, Draw_CachePic ("gfx/demomenu.lmp"));
463         }
464         else
465                 M_DrawPic (72, 32, Draw_CachePic ("gfx/mainmenu.lmp"));
466
467         f = (int)(realtime * 10)%6;
468
469         M_DrawPic (54, 32 + m_main_cursor * 20,Draw_CachePic( va("gfx/menudot%i.lmp", f+1 ) ) );
470 }
471
472
473 void M_Main_Key (int key)
474 {
475         switch (key)
476         {
477         case K_ESCAPE:
478                 key_dest = key_game;
479                 m_state = m_none;
480                 cls.demonum = m_save_demonum;
481                 if (cls.demonum != -1 && !cls.demoplayback && cls.state != ca_connected)
482                         CL_NextDemo ();
483                 break;
484
485         case K_DOWNARROW:
486                 S_LocalSound ("misc/menu1.wav");
487                 if (++m_main_cursor >= MAIN_ITEMS)
488                         m_main_cursor = 0;
489                 break;
490
491         case K_UPARROW:
492                 S_LocalSound ("misc/menu1.wav");
493                 if (--m_main_cursor < 0)
494                         m_main_cursor = MAIN_ITEMS - 1;
495                 break;
496
497         case K_ENTER:
498                 m_entersound = true;
499
500                 if (nehahra)
501                 {
502                         switch (NehGameType)
503                         {
504                         case TYPE_BOTH:
505                                 switch (m_main_cursor)
506                                 {
507                                 case 0:
508                                         M_Menu_SinglePlayer_f ();
509                                         break;
510
511                                 case 1:
512                                         M_Menu_Demos_f ();
513                                         break;
514
515                                 case 2:
516                                         M_Menu_MultiPlayer_f ();
517                                         break;
518
519                                 case 3:
520                                         M_Menu_Options_f ();
521                                         break;
522
523                                 case 4:
524                                         key_dest = key_game;
525                                         if (sv.active)
526                                                 Cbuf_AddText ("disconnect\n");
527                                         Cbuf_AddText ("playdemo endcred\n");
528                                         break;
529
530                                 case 5:
531                                         M_Menu_Quit_f ();
532                                         break;
533                                 }
534                                 break;
535                         case TYPE_GAME:
536                                 switch (m_main_cursor)
537                                 {
538                                 case 0:
539                                         M_Menu_SinglePlayer_f ();
540                                         break;
541
542                                 case 1:
543                                         M_Menu_MultiPlayer_f ();
544                                         break;
545
546                                 case 2:
547                                         M_Menu_Options_f ();
548                                         break;
549
550                                 case 3:
551                                         key_dest = key_game;
552                                         if (sv.active)
553                                                 Cbuf_AddText ("disconnect\n");
554                                         Cbuf_AddText ("playdemo endcred\n");
555                                         break;
556
557                                 case 4:
558                                         M_Menu_Quit_f ();
559                                         break;
560                                 }
561                                 break;
562                         case TYPE_DEMO:
563                                 switch (m_main_cursor)
564                                 {
565                                 case 0:
566                                         M_Menu_Demos_f ();
567                                         break;
568
569                                 case 1:
570                                         key_dest = key_game;
571                                         if (sv.active)
572                                                 Cbuf_AddText ("disconnect\n");
573                                         Cbuf_AddText ("playdemo endcred\n");
574                                         break;
575
576                                 case 2:
577                                         M_Menu_Options_f ();
578                                         break;
579
580                                 case 3:
581                                         M_Menu_Quit_f ();
582                                         break;
583                                 }
584                                 break;
585                         }
586                 }
587                 else
588                 {
589                         switch (m_main_cursor)
590                         {
591                         case 0:
592                                 M_Menu_SinglePlayer_f ();
593                                 break;
594
595                         case 1:
596                                 M_Menu_MultiPlayer_f ();
597                                 break;
598
599                         case 2:
600                                 M_Menu_Options_f ();
601                                 break;
602
603                         case 3:
604                                 M_Menu_Help_f ();
605                                 break;
606
607                         case 4:
608                                 M_Menu_Quit_f ();
609                                 break;
610                         }
611                 }
612         }
613 }
614
615 //=============================================================================
616 /* SINGLE PLAYER MENU */
617
618 int     m_singleplayer_cursor;
619 #define SINGLEPLAYER_ITEMS      3
620
621
622 void M_Menu_SinglePlayer_f (void)
623 {
624         key_dest = key_menu;
625         m_state = m_singleplayer;
626         m_entersound = true;
627 }
628
629
630 void M_SinglePlayer_Draw (void)
631 {
632         int             f;
633         qpic_t  *p;
634
635         M_DrawPic (16, 4, Draw_CachePic ("gfx/qplaque.lmp") );
636         p = Draw_CachePic ("gfx/ttl_sgl.lmp");
637         M_DrawPic ( (320-p->width)/2, 4, p);
638         M_DrawPic (72, 32, Draw_CachePic ("gfx/sp_menu.lmp") );
639
640         f = (int)(realtime * 10)%6;
641
642         M_DrawPic (54, 32 + m_singleplayer_cursor * 20,Draw_CachePic( va("gfx/menudot%i.lmp", f+1 ) ) );
643 }
644
645
646 void M_SinglePlayer_Key (int key)
647 {
648         switch (key)
649         {
650         case K_ESCAPE:
651                 M_Menu_Main_f ();
652                 break;
653
654         case K_DOWNARROW:
655                 S_LocalSound ("misc/menu1.wav");
656                 if (++m_singleplayer_cursor >= SINGLEPLAYER_ITEMS)
657                         m_singleplayer_cursor = 0;
658                 break;
659
660         case K_UPARROW:
661                 S_LocalSound ("misc/menu1.wav");
662                 if (--m_singleplayer_cursor < 0)
663                         m_singleplayer_cursor = SINGLEPLAYER_ITEMS - 1;
664                 break;
665
666         case K_ENTER:
667                 m_entersound = true;
668
669                 switch (m_singleplayer_cursor)
670                 {
671                 case 0:
672                         key_dest = key_game;
673                         if (sv.active)
674                                 Cbuf_AddText ("disconnect\n");
675                         Cbuf_AddText ("maxplayers 1\n");
676                         if (nehahra)
677                                 Cbuf_AddText ("map nehstart\n");
678                         else
679                                 Cbuf_AddText ("map start\n");
680                         break;
681
682                 case 1:
683                         M_Menu_Load_f ();
684                         break;
685
686                 case 2:
687                         M_Menu_Save_f ();
688                         break;
689                 }
690         }
691 }
692
693 //=============================================================================
694 /* LOAD/SAVE MENU */
695
696 int             load_cursor;            // 0 < load_cursor < MAX_SAVEGAMES
697
698 #define MAX_SAVEGAMES           12
699 char    m_filenames[MAX_SAVEGAMES][SAVEGAME_COMMENT_LENGTH+1];
700 int             loadable[MAX_SAVEGAMES];
701
702 void M_ScanSaves (void)
703 {
704         int             i, j;
705         char    name[MAX_OSPATH];
706         char    *str;
707         QFile   *f;
708         int             version;
709
710         for (i=0 ; i<MAX_SAVEGAMES ; i++)
711         {
712                 strcpy (m_filenames[i], "--- UNUSED SLOT ---");
713                 loadable[i] = false;
714                 sprintf (name, "%s/s%i.sav", com_gamedir, i);
715                 f = Qopen (name, "rz");
716                 if (!f)
717                         continue;
718                 str = Qgetline (f);
719                 sscanf (str, "%i\n", &version);
720                 str = Qgetline (f);
721                 strncpy (m_filenames[i], str, sizeof(m_filenames[i])-1);
722
723         // change _ back to space
724                 for (j=0 ; j<SAVEGAME_COMMENT_LENGTH ; j++)
725                         if (m_filenames[i][j] == '_')
726                                 m_filenames[i][j] = ' ';
727                 loadable[i] = true;
728                 Qclose (f);
729         }
730 }
731
732 void M_Menu_Load_f (void)
733 {
734         m_entersound = true;
735         m_state = m_load;
736         key_dest = key_menu;
737         M_ScanSaves ();
738 }
739
740
741 void M_Menu_Save_f (void)
742 {
743         if (!sv.active)
744                 return;
745         if (cl.intermission)
746                 return;
747         if (svs.maxclients != 1)
748                 return;
749         m_entersound = true;
750         m_state = m_save;
751         key_dest = key_menu;
752         M_ScanSaves ();
753 }
754
755
756 void M_Load_Draw (void)
757 {
758         int             i;
759         qpic_t  *p;
760
761         p = Draw_CachePic ("gfx/p_load.lmp");
762         M_DrawPic ( (320-p->width)/2, 4, p);
763
764         for (i=0 ; i< MAX_SAVEGAMES; i++)
765                 M_Print (16, 32 + 8*i, m_filenames[i]);
766
767 // line cursor
768         M_DrawCharacter (8, 32 + load_cursor*8, 12+((int)(realtime*4)&1));
769 }
770
771
772 void M_Save_Draw (void)
773 {
774         int             i;
775         qpic_t  *p;
776
777         p = Draw_CachePic ("gfx/p_save.lmp");
778         M_DrawPic ( (320-p->width)/2, 4, p);
779
780         for (i=0 ; i<MAX_SAVEGAMES ; i++)
781                 M_Print (16, 32 + 8*i, m_filenames[i]);
782
783 // line cursor
784         M_DrawCharacter (8, 32 + load_cursor*8, 12+((int)(realtime*4)&1));
785 }
786
787
788 void M_Load_Key (int k)
789 {
790         switch (k)
791         {
792         case K_ESCAPE:
793                 M_Menu_SinglePlayer_f ();
794                 break;
795
796         case K_ENTER:
797                 S_LocalSound ("misc/menu2.wav");
798                 if (!loadable[load_cursor])
799                         return;
800                 m_state = m_none;
801                 key_dest = key_game;
802
803                 // LordHavoc: made SCR_UpdateScreen use a great deal less stack space, no longer an issue
804                 //// Host_Loadgame_f can't bring up the loading plaque because too much
805                 //// stack space has been used, so do it now
806 ////            SCR_BeginLoadingPlaque ();
807
808                 // issue the load command
809                 Cbuf_AddText (va ("load s%i\n", load_cursor) );
810                 return;
811
812         case K_UPARROW:
813         case K_LEFTARROW:
814                 S_LocalSound ("misc/menu1.wav");
815                 load_cursor--;
816                 if (load_cursor < 0)
817                         load_cursor = MAX_SAVEGAMES-1;
818                 break;
819
820         case K_DOWNARROW:
821         case K_RIGHTARROW:
822                 S_LocalSound ("misc/menu1.wav");
823                 load_cursor++;
824                 if (load_cursor >= MAX_SAVEGAMES)
825                         load_cursor = 0;
826                 break;
827         }
828 }
829
830
831 void M_Save_Key (int k)
832 {
833         switch (k)
834         {
835         case K_ESCAPE:
836                 M_Menu_SinglePlayer_f ();
837                 break;
838
839         case K_ENTER:
840                 m_state = m_none;
841                 key_dest = key_game;
842                 Cbuf_AddText (va("save s%i\n", load_cursor));
843                 return;
844
845         case K_UPARROW:
846         case K_LEFTARROW:
847                 S_LocalSound ("misc/menu1.wav");
848                 load_cursor--;
849                 if (load_cursor < 0)
850                         load_cursor = MAX_SAVEGAMES-1;
851                 break;
852
853         case K_DOWNARROW:
854         case K_RIGHTARROW:
855                 S_LocalSound ("misc/menu1.wav");
856                 load_cursor++;
857                 if (load_cursor >= MAX_SAVEGAMES)
858                         load_cursor = 0;
859                 break;
860         }
861 }
862
863 //=============================================================================
864 /* MULTIPLAYER MENU */
865
866 int     m_multiplayer_cursor;
867 #define MULTIPLAYER_ITEMS       3
868
869
870 void M_Menu_MultiPlayer_f (void)
871 {
872         key_dest = key_menu;
873         m_state = m_multiplayer;
874         m_entersound = true;
875 }
876
877
878 void M_MultiPlayer_Draw (void)
879 {
880         int             f;
881         qpic_t  *p;
882
883         M_DrawPic (16, 4, Draw_CachePic ("gfx/qplaque.lmp") );
884         p = Draw_CachePic ("gfx/p_multi.lmp");
885         M_DrawPic ( (320-p->width)/2, 4, p);
886         M_DrawPic (72, 32, Draw_CachePic ("gfx/mp_menu.lmp") );
887
888         f = (int)(realtime * 10)%6;
889
890         M_DrawPic (54, 32 + m_multiplayer_cursor * 20,Draw_CachePic( va("gfx/menudot%i.lmp", f+1 ) ) );
891
892         if (ipxAvailable || tcpipAvailable)
893                 return;
894         M_PrintWhite ((320/2) - ((27*8)/2), 148, "No Communications Available");
895 }
896
897
898 void M_MultiPlayer_Key (int key)
899 {
900         switch (key)
901         {
902         case K_ESCAPE:
903                 M_Menu_Main_f ();
904                 break;
905
906         case K_DOWNARROW:
907                 S_LocalSound ("misc/menu1.wav");
908                 if (++m_multiplayer_cursor >= MULTIPLAYER_ITEMS)
909                         m_multiplayer_cursor = 0;
910                 break;
911
912         case K_UPARROW:
913                 S_LocalSound ("misc/menu1.wav");
914                 if (--m_multiplayer_cursor < 0)
915                         m_multiplayer_cursor = MULTIPLAYER_ITEMS - 1;
916                 break;
917
918         case K_ENTER:
919                 m_entersound = true;
920                 switch (m_multiplayer_cursor)
921                 {
922                 case 0:
923                         if (ipxAvailable || tcpipAvailable)
924                                 M_Menu_Net_f ();
925                         break;
926
927                 case 1:
928                         if (ipxAvailable || tcpipAvailable)
929                                 M_Menu_Net_f ();
930                         break;
931
932                 case 2:
933                         M_Menu_Setup_f ();
934                         break;
935                 }
936         }
937 }
938
939 //=============================================================================
940 /* SETUP MENU */
941
942 int             setup_cursor = 4;
943 int             setup_cursor_table[] = {40, 56, 80, 104, 140};
944
945 char    setup_hostname[16];
946 char    setup_myname[16];
947 int             setup_oldtop;
948 int             setup_oldbottom;
949 int             setup_top;
950 int             setup_bottom;
951
952 #define NUM_SETUP_CMDS  5
953
954 void M_Menu_Setup_f (void)
955 {
956         key_dest = key_menu;
957         m_state = m_setup;
958         m_entersound = true;
959         strcpy(setup_myname, cl_name.string);
960         strcpy(setup_hostname, hostname.string);
961         setup_top = setup_oldtop = ((int)cl_color.value) >> 4;
962         setup_bottom = setup_oldbottom = ((int)cl_color.value) & 15;
963 }
964
965
966 void M_Setup_Draw (void)
967 {
968         qpic_t  *p;
969
970         M_DrawPic (16, 4, Draw_CachePic ("gfx/qplaque.lmp") );
971         p = Draw_CachePic ("gfx/p_multi.lmp");
972         M_DrawPic ( (320-p->width)/2, 4, p);
973
974         M_Print (64, 40, "Hostname");
975         M_DrawTextBox (160, 32, 16, 1);
976         M_Print (168, 40, setup_hostname);
977
978         M_Print (64, 56, "Your name");
979         M_DrawTextBox (160, 48, 16, 1);
980         M_Print (168, 56, setup_myname);
981
982         M_Print (64, 80, "Shirt color");
983         M_Print (64, 104, "Pants color");
984
985         M_DrawTextBox (64, 140-8, 14, 1);
986         M_Print (72, 140, "Accept Changes");
987
988         p = Draw_CachePic ("gfx/bigbox.lmp");
989         M_DrawPic (160, 64, p);
990         p = Draw_CachePic ("gfx/menuplyr.lmp");
991         M_BuildTranslationTable(setup_top*16, setup_bottom*16);
992         M_DrawPicTranslate (172, 72, p);
993
994         M_DrawCharacter (56, setup_cursor_table [setup_cursor], 12+((int)(realtime*4)&1));
995
996         if (setup_cursor == 0)
997                 M_DrawCharacter (168 + 8*strlen(setup_hostname), setup_cursor_table [setup_cursor], 10+((int)(realtime*4)&1));
998
999         if (setup_cursor == 1)
1000                 M_DrawCharacter (168 + 8*strlen(setup_myname), setup_cursor_table [setup_cursor], 10+((int)(realtime*4)&1));
1001 }
1002
1003
1004 void M_Setup_Key (int k)
1005 {
1006         int                     l;
1007
1008         switch (k)
1009         {
1010         case K_ESCAPE:
1011                 M_Menu_MultiPlayer_f ();
1012                 break;
1013
1014         case K_UPARROW:
1015                 S_LocalSound ("misc/menu1.wav");
1016                 setup_cursor--;
1017                 if (setup_cursor < 0)
1018                         setup_cursor = NUM_SETUP_CMDS-1;
1019                 break;
1020
1021         case K_DOWNARROW:
1022                 S_LocalSound ("misc/menu1.wav");
1023                 setup_cursor++;
1024                 if (setup_cursor >= NUM_SETUP_CMDS)
1025                         setup_cursor = 0;
1026                 break;
1027
1028         case K_LEFTARROW:
1029                 if (setup_cursor < 2)
1030                         return;
1031                 S_LocalSound ("misc/menu3.wav");
1032                 if (setup_cursor == 2)
1033                         setup_top = setup_top - 1;
1034                 if (setup_cursor == 3)
1035                         setup_bottom = setup_bottom - 1;
1036                 break;
1037         case K_RIGHTARROW:
1038                 if (setup_cursor < 2)
1039                         return;
1040 forward:
1041                 S_LocalSound ("misc/menu3.wav");
1042                 if (setup_cursor == 2)
1043                         setup_top = setup_top + 1;
1044                 if (setup_cursor == 3)
1045                         setup_bottom = setup_bottom + 1;
1046                 break;
1047
1048         case K_ENTER:
1049                 if (setup_cursor == 0 || setup_cursor == 1)
1050                         return;
1051
1052                 if (setup_cursor == 2 || setup_cursor == 3)
1053                         goto forward;
1054
1055                 // setup_cursor == 4 (OK)
1056                 if (strcmp(cl_name.string, setup_myname) != 0)
1057                         Cbuf_AddText ( va ("name \"%s\"\n", setup_myname) );
1058                 if (strcmp(hostname.string, setup_hostname) != 0)
1059                         Cvar_Set("hostname", setup_hostname);
1060                 if (setup_top != setup_oldtop || setup_bottom != setup_oldbottom)
1061                         Cbuf_AddText( va ("color %i %i\n", setup_top, setup_bottom) );
1062                 m_entersound = true;
1063                 M_Menu_MultiPlayer_f ();
1064                 break;
1065
1066         case K_BACKSPACE:
1067                 if (setup_cursor == 0)
1068                 {
1069                         if (strlen(setup_hostname))
1070                                 setup_hostname[strlen(setup_hostname)-1] = 0;
1071                 }
1072
1073                 if (setup_cursor == 1)
1074                 {
1075                         if (strlen(setup_myname))
1076                                 setup_myname[strlen(setup_myname)-1] = 0;
1077                 }
1078                 break;
1079
1080         default:
1081                 if (k < 32 || k > 127)
1082                         break;
1083                 if (setup_cursor == 0)
1084                 {
1085                         l = strlen(setup_hostname);
1086                         if (l < 15)
1087                         {
1088                                 setup_hostname[l+1] = 0;
1089                                 setup_hostname[l] = k;
1090                         }
1091                 }
1092                 if (setup_cursor == 1)
1093                 {
1094                         l = strlen(setup_myname);
1095                         if (l < 15)
1096                         {
1097                                 setup_myname[l+1] = 0;
1098                                 setup_myname[l] = k;
1099                         }
1100                 }
1101         }
1102
1103         if (setup_top > 13)
1104                 setup_top = 0;
1105         if (setup_top < 0)
1106                 setup_top = 13;
1107         if (setup_bottom > 13)
1108                 setup_bottom = 0;
1109         if (setup_bottom < 0)
1110                 setup_bottom = 13;
1111 }
1112
1113 //=============================================================================
1114 /* NET MENU */
1115
1116 int     m_net_cursor;
1117 int m_net_items;
1118 int m_net_saveHeight;
1119
1120 char *net_helpMessage [] =
1121 {
1122 /* .........1.........2.... */
1123   " Novell network LANs    ",
1124   " or Windows 95 DOS-box. ",
1125   "                        ",
1126   "(LAN=Local Area Network)",
1127
1128   " Commonly used to play  ",
1129   " over the Internet, but ",
1130   " also used on a Local   ",
1131   " Area Network.          "
1132 };
1133
1134 void M_Menu_Net_f (void)
1135 {
1136         key_dest = key_menu;
1137         m_state = m_net;
1138         m_entersound = true;
1139         m_net_items = 2;
1140
1141         if (m_net_cursor >= m_net_items)
1142                 m_net_cursor = 0;
1143         m_net_cursor--;
1144         M_Net_Key (K_DOWNARROW);
1145 }
1146
1147
1148 void M_Net_Draw (void)
1149 {
1150         int             f;
1151         qpic_t  *p;
1152
1153         M_DrawPic (16, 4, Draw_CachePic ("gfx/qplaque.lmp") );
1154         p = Draw_CachePic ("gfx/p_multi.lmp");
1155         M_DrawPic ( (320-p->width)/2, 4, p);
1156
1157         f = 32;
1158
1159         if (ipxAvailable)
1160                 p = Draw_CachePic ("gfx/netmen3.lmp");
1161         else
1162                 p = Draw_CachePic ("gfx/dim_ipx.lmp");
1163         M_DrawPic (72, f, p);
1164
1165         f += 19;
1166         if (tcpipAvailable)
1167                 p = Draw_CachePic ("gfx/netmen4.lmp");
1168         else
1169                 p = Draw_CachePic ("gfx/dim_tcp.lmp");
1170         M_DrawPic (72, f, p);
1171
1172         if (m_net_items == 5)   // JDC, could just be removed
1173         {
1174                 f += 19;
1175                 p = Draw_CachePic ("gfx/netmen5.lmp");
1176                 M_DrawPic (72, f, p);
1177         }
1178
1179         f = (320-26*8)/2;
1180         M_DrawTextBox (f, 134, 24, 4);
1181         f += 8;
1182         M_Print (f, 142, net_helpMessage[m_net_cursor*4+0]);
1183         M_Print (f, 150, net_helpMessage[m_net_cursor*4+1]);
1184
1185         f = (int)(realtime * 10)%6;
1186         M_DrawPic (54, 32 + m_net_cursor * 20,Draw_CachePic( va("gfx/menudot%i.lmp", f+1 ) ) );
1187 }
1188
1189
1190 void M_Net_Key (int k)
1191 {
1192 again:
1193         switch (k)
1194         {
1195         case K_ESCAPE:
1196                 M_Menu_MultiPlayer_f ();
1197                 break;
1198
1199         case K_DOWNARROW:
1200                 S_LocalSound ("misc/menu1.wav");
1201                 if (++m_net_cursor >= m_net_items)
1202                         m_net_cursor = 0;
1203                 break;
1204
1205         case K_UPARROW:
1206                 S_LocalSound ("misc/menu1.wav");
1207                 if (--m_net_cursor < 0)
1208                         m_net_cursor = m_net_items - 1;
1209                 break;
1210
1211         case K_ENTER:
1212                 m_entersound = true;
1213
1214                 switch (m_net_cursor)
1215                 {
1216                 case 0:
1217                         M_Menu_LanConfig_f ();
1218                         break;
1219
1220                 case 1:
1221                         M_Menu_LanConfig_f ();
1222                         break;
1223
1224                 case 2:
1225 // multiprotocol
1226                         break;
1227                 }
1228         }
1229
1230         if (m_net_cursor == 0 && !ipxAvailable)
1231                 goto again;
1232         if (m_net_cursor == 1 && !tcpipAvailable)
1233                 goto again;
1234 }
1235
1236 //=============================================================================
1237 /* OPTIONS MENU */
1238
1239 #define OPTIONS_ITEMS   (vid_menudrawfn ? 24 : 23)
1240
1241 #define SLIDER_RANGE    10
1242
1243 int             options_cursor;
1244
1245 void M_Menu_Options_f (void)
1246 {
1247         key_dest = key_menu;
1248         m_state = m_options;
1249         m_entersound = true;
1250 }
1251
1252
1253 void M_AdjustSliders (int dir)
1254 {
1255         S_LocalSound ("misc/menu3.wav");
1256
1257         switch (options_cursor)
1258         {
1259         case 3: // screen size
1260                 Cvar_SetValue ("viewsize", bound(30, scr_viewsize.value + dir * 10, 120));
1261                 break;
1262         case 4:
1263                 Cvar_SetValue ("r_ser", !r_ser.value);
1264                 break;
1265
1266         case 5: // overbright rendering
1267                 Cvar_SetValue ("gl_lightmode", !gl_lightmode.value);
1268                 break;
1269
1270         case 6: // sky quality
1271                 Cvar_SetValue ("r_skyquality", bound(0, r_skyquality.value + dir, 4));
1272                 break;
1273
1274         case 7: // hardware gamma
1275                 Cvar_SetValue ("vid_gamma", bound(1, vid_gamma.value + dir * 0.25, 5));
1276                 break;
1277
1278         case 8: // hardware brightness
1279                 Cvar_SetValue ("vid_brightness", bound(1, vid_brightness.value + dir * 0.25, 5));
1280                 break;
1281
1282         case 9: // hardware contrast
1283                 Cvar_SetValue ("vid_contrast", bound(0.2, vid_contrast.value + dir * 0.08, 1));
1284                 break;
1285
1286         case 10:        // software brightness
1287                 Cvar_SetValue ("r_brightness", bound(1, r_brightness.value + dir * 0.25, 5));
1288                 break;
1289
1290         case 11: // software base brightness
1291                 Cvar_SetValue ("r_contrast", bound(0.2, r_contrast.value + dir * 0.08, 1));
1292                 break;
1293
1294         case 12: // music volume
1295 #ifdef _WIN32
1296                 Cvar_SetValue ("bgmvolume", bound(0, bgmvolume.value + dir * 1.0, 1));
1297 #else
1298                 Cvar_SetValue ("bgmvolume", bound(0, bgmvolume.value + dir * 0.1, 1));
1299 #endif
1300                 break;
1301
1302         case 13: // sfx volume
1303                 Cvar_SetValue ("volume", bound(0, volume.value + dir * 0.1, 1));
1304                 break;
1305
1306         case 14: // always run
1307                 if (cl_forwardspeed.value > 200)
1308                 {
1309                         Cvar_SetValue ("cl_forwardspeed", 200);
1310                         Cvar_SetValue ("cl_backspeed", 200);
1311                 }
1312                 else
1313                 {
1314                         Cvar_SetValue ("cl_forwardspeed", 400);
1315                         Cvar_SetValue ("cl_backspeed", 400);
1316                 }
1317                 break;
1318
1319         case 15: // lookspring
1320                 Cvar_SetValue ("lookspring", !lookspring.value);
1321                 break;
1322
1323         case 16: // lookstrafe
1324                 Cvar_SetValue ("lookstrafe", !lookstrafe.value);
1325                 break;
1326
1327         case 17: // mouse speed
1328                 Cvar_SetValue ("sensitivity", bound(1, sensitivity.value + dir * 0.5, 50));
1329                 break;
1330
1331         case 18: // mouse look
1332                 Cvar_SetValue ("freelook", !freelook.value);
1333                 break;
1334
1335         case 19: // invert mouse
1336                 Cvar_SetValue ("m_pitch", -m_pitch.value);
1337                 break;
1338
1339         case 20: // windowed mouse
1340                 Cvar_SetValue ("vid_mouse", !vid_mouse.value);
1341                 break;
1342
1343         case 21:
1344                 Cvar_SetValue ("crosshair", bound(0, crosshair.value + dir, 5));
1345                 break;
1346
1347         case 22: // show framerate
1348                 Cvar_SetValue ("showfps", !showfps.value);
1349                 break;
1350         }
1351 }
1352
1353
1354 void M_DrawSlider (int x, int y, float range)
1355 {
1356         int     i;
1357
1358         if (range < 0)
1359                 range = 0;
1360         if (range > 1)
1361                 range = 1;
1362         M_DrawCharacter (x-8, y, 128);
1363         for (i=0 ; i<SLIDER_RANGE ; i++)
1364                 M_DrawCharacter (x + i*8, y, 129);
1365         M_DrawCharacter (x+i*8, y, 130);
1366         M_DrawCharacter (x + (SLIDER_RANGE-1)*8 * range, y, 131);
1367 }
1368
1369 void M_DrawCheckbox (int x, int y, int on)
1370 {
1371 #if 0
1372         if (on)
1373                 M_DrawCharacter (x, y, 131);
1374         else
1375                 M_DrawCharacter (x, y, 129);
1376 #endif
1377         if (on)
1378                 M_Print (x, y, "on");
1379         else
1380                 M_Print (x, y, "off");
1381 }
1382
1383 void M_Options_Draw (void)
1384 {
1385         float y;
1386         qpic_t  *p;
1387
1388         M_DrawPic(16, 4, Draw_CachePic("gfx/qplaque.lmp") );
1389         p = Draw_CachePic("gfx/p_option.lmp");
1390         M_DrawPic((320-p->width)/2, 4, p);
1391
1392         y = 32;
1393         M_Print(16, y, "    Customize controls");y += 8;
1394         M_Print(16, y, "         Go to console");y += 8;
1395         M_Print(16, y, "     Reset to defaults");y += 8;
1396         M_Print(16, y, "           Screen size");M_DrawSlider(220, y, (scr_viewsize.value - 30) /(120 - 30));y += 8;
1397         M_Print(16, y, "Hidden Surface Removal");M_DrawCheckbox(220, y, r_ser.value);y += 8;
1398         M_Print(16, y, "  Overbright Rendering");M_DrawCheckbox(220, y, gl_lightmode.value);y += 8;
1399         M_Print(16, y, "           Sky Quality");M_DrawSlider(220, y, r_skyquality.value / 4);y += 8;
1400         M_Print(16, y, "        Hardware Gamma");M_DrawSlider(220, y, (vid_gamma.value - 1) / 4);y += 8;
1401         M_Print(16, y, "   Hardware Brightness");M_DrawSlider(220, y, (vid_brightness.value - 1) / 4);y += 8;
1402         M_Print(16, y, "     Hardware Contrast");M_DrawSlider(220, y, (vid_contrast.value - 0.2) / 0.8);y += 8;
1403         M_Print(16, y, "   Software Brightness");M_DrawSlider(220, y, (r_brightness.value - 1) / 4);y += 8;
1404         M_Print(16, y, "     Software Contrast");M_DrawSlider(220, y, (r_contrast.value - 0.2) / 0.8);y += 8;
1405         M_Print(16, y, "       CD Music Volume");M_DrawSlider(220, y, bgmvolume.value);y += 8;
1406         M_Print(16, y, "          Sound Volume");M_DrawSlider(220, y, volume.value);y += 8;
1407         M_Print(16, y, "            Always Run");M_DrawCheckbox(220, y, cl_forwardspeed.value > 200);y += 8;
1408         M_Print(16, y, "            Lookspring");M_DrawCheckbox(220, y, lookspring.value);y += 8;
1409         M_Print(16, y, "            Lookstrafe");M_DrawCheckbox(220, y, lookstrafe.value);y += 8;
1410         M_Print(16, y, "           Mouse Speed");M_DrawSlider(220, y, (sensitivity.value - 1)/50);y += 8;
1411         M_Print(16, y, "            Mouse Look");M_DrawCheckbox(220, y, freelook.value);y += 8;
1412         M_Print(16, y, "          Invert Mouse");M_DrawCheckbox(220, y, m_pitch.value < 0);y += 8;
1413         M_Print(16, y, "             Use Mouse");M_DrawCheckbox(220, y, vid_mouse.value);y += 8;
1414         M_Print(16, y, "             Crosshair");M_DrawSlider(220, y, crosshair.value / 5);y += 8;
1415         M_Print(16, y, "        Show Framerate");M_DrawCheckbox(220, y, showfps.value);y += 8;
1416         if (vid_menudrawfn)
1417                 M_Print(16, y, "         Video Options");
1418         y += 8;
1419
1420         // cursor
1421         M_DrawCharacter(200, 32 + options_cursor*8, 12+((int)(realtime*4)&1));
1422 }
1423
1424
1425 void M_Options_Key (int k)
1426 {
1427         switch (k)
1428         {
1429         case K_ESCAPE:
1430                 M_Menu_Main_f ();
1431                 break;
1432
1433         case K_ENTER:
1434                 m_entersound = true;
1435                 switch (options_cursor)
1436                 {
1437                 case 0:
1438                         M_Menu_Keys_f ();
1439                         break;
1440                 case 1:
1441                         m_state = m_none;
1442                         Con_ToggleConsole_f ();
1443                         break;
1444                 case 2:
1445                         Cbuf_AddText ("exec default.cfg\n");
1446                         break;
1447                 default:
1448                         // this is really just another case, but since it is calculated...
1449                         if (vid_menudrawfn && options_cursor == (OPTIONS_ITEMS - 1))
1450                                 M_Menu_Video_f ();
1451                         else
1452                                 M_AdjustSliders (1);
1453                         break;
1454                 }
1455                 return;
1456
1457         case K_UPARROW:
1458                 S_LocalSound ("misc/menu1.wav");
1459                 options_cursor--;
1460                 if (options_cursor < 0)
1461                         options_cursor = OPTIONS_ITEMS-1;
1462                 break;
1463
1464         case K_DOWNARROW:
1465                 S_LocalSound ("misc/menu1.wav");
1466                 options_cursor++;
1467                 if (options_cursor >= OPTIONS_ITEMS)
1468                         options_cursor = 0;
1469                 break;
1470
1471         case K_LEFTARROW:
1472                 M_AdjustSliders (-1);
1473                 break;
1474
1475         case K_RIGHTARROW:
1476                 M_AdjustSliders (1);
1477                 break;
1478         }
1479 }
1480
1481 //=============================================================================
1482 /* KEYS MENU */
1483
1484 char *bindnames[][2] =
1485 {
1486 {"+attack",             "attack"},
1487 {"impulse 10",          "change weapon"},
1488 {"+jump",                       "jump / swim up"},
1489 {"+forward",            "walk forward"},
1490 {"+back",                       "backpedal"},
1491 {"+left",                       "turn left"},
1492 {"+right",                      "turn right"},
1493 {"+speed",                      "run"},
1494 {"+moveleft",           "step left"},
1495 {"+moveright",          "step right"},
1496 {"+strafe",             "sidestep"},
1497 {"+lookup",             "look up"},
1498 {"+lookdown",           "look down"},
1499 {"centerview",          "center view"},
1500 {"+mlook",                      "mouse look"},
1501 {"+klook",                      "keyboard look"},
1502 {"+moveup",                     "swim up"},
1503 {"+movedown",           "swim down"}
1504 };
1505
1506 #define NUMCOMMANDS     (sizeof(bindnames)/sizeof(bindnames[0]))
1507
1508 int             keys_cursor;
1509 int             bind_grab;
1510
1511 void M_Menu_Keys_f (void)
1512 {
1513         key_dest = key_menu;
1514         m_state = m_keys;
1515         m_entersound = true;
1516 }
1517
1518
1519 void M_FindKeysForCommand (char *command, int *twokeys)
1520 {
1521         int             count;
1522         int             j;
1523         int             l;
1524         char    *b;
1525
1526         twokeys[0] = twokeys[1] = -1;
1527         l = strlen(command);
1528         count = 0;
1529
1530         for (j=0 ; j<256 ; j++)
1531         {
1532                 b = keybindings[j];
1533                 if (!b)
1534                         continue;
1535                 if (!strncmp (b, command, l) )
1536                 {
1537                         twokeys[count] = j;
1538                         count++;
1539                         if (count == 2)
1540                                 break;
1541                 }
1542         }
1543 }
1544
1545 void M_UnbindCommand (char *command)
1546 {
1547         int             j;
1548         int             l;
1549         char    *b;
1550
1551         l = strlen(command);
1552
1553         for (j=0 ; j<256 ; j++)
1554         {
1555                 b = keybindings[j];
1556                 if (!b)
1557                         continue;
1558                 if (!strncmp (b, command, l) )
1559                         Key_SetBinding (j, "");
1560         }
1561 }
1562
1563
1564 void M_Keys_Draw (void)
1565 {
1566         int             i, l;
1567         int             keys[2];
1568         char    *name;
1569         int             x, y;
1570         qpic_t  *p;
1571
1572         p = Draw_CachePic ("gfx/ttl_cstm.lmp");
1573         M_DrawPic ( (320-p->width)/2, 4, p);
1574
1575         if (bind_grab)
1576                 M_Print (12, 32, "Press a key or button for this action");
1577         else
1578                 M_Print (18, 32, "Enter to change, backspace to clear");
1579
1580 // search for known bindings
1581         for (i=0 ; i<NUMCOMMANDS ; i++)
1582         {
1583                 y = 48 + 8*i;
1584
1585                 M_Print (16, y, bindnames[i][1]);
1586
1587                 l = strlen (bindnames[i][0]);
1588
1589                 M_FindKeysForCommand (bindnames[i][0], keys);
1590
1591                 if (keys[0] == -1)
1592                 {
1593                         M_Print (140, y, "???");
1594                 }
1595                 else
1596                 {
1597                         name = Key_KeynumToString (keys[0]);
1598                         M_Print (140, y, name);
1599                         x = strlen(name) * 8;
1600                         if (keys[1] != -1)
1601                         {
1602                                 M_Print (140 + x + 8, y, "or");
1603                                 M_Print (140 + x + 32, y, Key_KeynumToString (keys[1]));
1604                         }
1605                 }
1606         }
1607
1608         if (bind_grab)
1609                 M_DrawCharacter (130, 48 + keys_cursor*8, '=');
1610         else
1611                 M_DrawCharacter (130, 48 + keys_cursor*8, 12+((int)(realtime*4)&1));
1612 }
1613
1614
1615 void M_Keys_Key (int k)
1616 {
1617         char    cmd[80];
1618         int             keys[2];
1619
1620         if (bind_grab)
1621         {       // defining a key
1622                 S_LocalSound ("misc/menu1.wav");
1623                 if (k == K_ESCAPE)
1624                 {
1625                         bind_grab = false;
1626                 }
1627                 else if (k != '`')
1628                 {
1629                         sprintf (cmd, "bind \"%s\" \"%s\"\n", Key_KeynumToString (k), bindnames[keys_cursor][0]);
1630                         Cbuf_InsertText (cmd);
1631                 }
1632
1633                 bind_grab = false;
1634                 return;
1635         }
1636
1637         switch (k)
1638         {
1639         case K_ESCAPE:
1640                 M_Menu_Options_f ();
1641                 break;
1642
1643         case K_LEFTARROW:
1644         case K_UPARROW:
1645                 S_LocalSound ("misc/menu1.wav");
1646                 keys_cursor--;
1647                 if (keys_cursor < 0)
1648                         keys_cursor = NUMCOMMANDS-1;
1649                 break;
1650
1651         case K_DOWNARROW:
1652         case K_RIGHTARROW:
1653                 S_LocalSound ("misc/menu1.wav");
1654                 keys_cursor++;
1655                 if (keys_cursor >= NUMCOMMANDS)
1656                         keys_cursor = 0;
1657                 break;
1658
1659         case K_ENTER:           // go into bind mode
1660                 M_FindKeysForCommand (bindnames[keys_cursor][0], keys);
1661                 S_LocalSound ("misc/menu2.wav");
1662                 if (keys[1] != -1)
1663                         M_UnbindCommand (bindnames[keys_cursor][0]);
1664                 bind_grab = true;
1665                 break;
1666
1667         case K_BACKSPACE:               // delete bindings
1668         case K_DEL:                             // delete bindings
1669                 S_LocalSound ("misc/menu2.wav");
1670                 M_UnbindCommand (bindnames[keys_cursor][0]);
1671                 break;
1672         }
1673 }
1674
1675 //=============================================================================
1676 /* VIDEO MENU */
1677
1678 void M_Menu_Video_f (void)
1679 {
1680         key_dest = key_menu;
1681         m_state = m_video;
1682         m_entersound = true;
1683 }
1684
1685
1686 void M_Video_Draw (void)
1687 {
1688         (*vid_menudrawfn) ();
1689 }
1690
1691
1692 void M_Video_Key (int key)
1693 {
1694         (*vid_menukeyfn) (key);
1695 }
1696
1697 //=============================================================================
1698 /* HELP MENU */
1699
1700 int             help_page;
1701 #define NUM_HELP_PAGES  6
1702
1703
1704 void M_Menu_Help_f (void)
1705 {
1706         key_dest = key_menu;
1707         m_state = m_help;
1708         m_entersound = true;
1709         help_page = 0;
1710 }
1711
1712
1713
1714 void M_Help_Draw (void)
1715 {
1716         M_DrawPic (0, 0, Draw_CachePic ( va("gfx/help%i.lmp", help_page)) );
1717 }
1718
1719
1720 void M_Help_Key (int key)
1721 {
1722         switch (key)
1723         {
1724         case K_ESCAPE:
1725                 M_Menu_Main_f ();
1726                 break;
1727
1728         case K_UPARROW:
1729         case K_RIGHTARROW:
1730                 m_entersound = true;
1731                 if (++help_page >= NUM_HELP_PAGES)
1732                         help_page = 0;
1733                 break;
1734
1735         case K_DOWNARROW:
1736         case K_LEFTARROW:
1737                 m_entersound = true;
1738                 if (--help_page < 0)
1739                         help_page = NUM_HELP_PAGES-1;
1740                 break;
1741         }
1742
1743 }
1744
1745 //=============================================================================
1746 /* QUIT MENU */
1747
1748 int             msgNumber;
1749 int             m_quit_prevstate;
1750 qboolean        wasInMenus;
1751
1752 //#ifndef       _WIN32
1753 char *quitMessage [] = 
1754 {
1755 /* .........1.........2.... */
1756 /*
1757   "  Are you gonna quit    ",
1758   "  this game just like   ",
1759   "   everything else?     ",
1760   "                        ",
1761  
1762   " Milord, methinks that  ",
1763   "   thou art a lowly     ",
1764   " quitter. Is this true? ",
1765   "                        ",
1766
1767   " Do I need to bust your ",
1768   "  face open for trying  ",
1769   "        to quit?        ",
1770   "                        ",
1771
1772   " Man, I oughta smack you",
1773   "   for trying to quit!  ",
1774   "     Press Y to get     ",
1775   "      smacked out.      ",
1776  
1777   " Press Y to quit like a ",
1778   "   big loser in life.   ",
1779   "  Press N to stay proud ",
1780   "    and successful!     ",
1781  
1782   "   If you press Y to    ",
1783   "  quit, I will summon   ",
1784   "  Satan all over your   ",
1785   "      hard drive!       ",
1786  
1787   "  Um, Asmodeus dislikes ",
1788   " his children trying to ",
1789   " quit. Press Y to return",
1790   "   to your Tinkertoys.  ",
1791  
1792   "  If you quit now, I'll ",
1793   "  throw a blanket-party ",
1794   "   for you next time!   ",
1795   "                        "
1796   */
1797
1798 /* .........1.........2.... */
1799   "                        ",
1800   "    Tired of fragging   ",
1801   "        already?        ",
1802   "                        ",
1803
1804   "                        ",
1805   "  Quit now and forfeit  ",
1806   "     your bodycount?    ",
1807   "                        ",
1808
1809   "                        ",
1810   "    Are you sure you    ",
1811   "      want to quit?     ",
1812   "                        ",
1813
1814   "                        ",
1815   "   Off to do something  ",
1816   "      constructive?     ",
1817   "                        ",
1818 };
1819 //#endif
1820
1821 void M_Menu_Quit_f (void)
1822 {
1823         if (m_state == m_quit)
1824                 return;
1825         wasInMenus = (key_dest == key_menu);
1826         key_dest = key_menu;
1827         m_quit_prevstate = m_state;
1828         m_state = m_quit;
1829         m_entersound = true;
1830         msgNumber = rand()&3; //&7;
1831 }
1832
1833
1834 void M_Quit_Key (int key)
1835 {
1836         switch (key)
1837         {
1838         case K_ESCAPE:
1839         case 'n':
1840         case 'N':
1841                 if (wasInMenus)
1842                 {
1843                         m_state = m_quit_prevstate;
1844                         m_entersound = true;
1845                 }
1846                 else
1847                 {
1848                         key_dest = key_game;
1849                         m_state = m_none;
1850                 }
1851                 break;
1852
1853         case 'Y':
1854         case 'y':
1855                 key_dest = key_console;
1856                 Host_Quit_f ();
1857                 break;
1858
1859         default:
1860                 break;
1861         }
1862
1863 }
1864
1865
1866 void M_Quit_Draw (void)
1867 {
1868         if (wasInMenus)
1869         {
1870                 m_state = m_quit_prevstate;
1871 //              m_recursiveDraw = true;
1872                 M_Draw ();
1873                 m_state = m_quit;
1874         }
1875
1876 /*
1877 #ifdef _WIN32
1878         M_DrawTextBox (0, 0, 38, 23);
1879         M_PrintWhite (16, 12,  "  Quake version 1.09 by id Software\n\n");
1880         M_PrintWhite (16, 28,  "Programming        Art \n");
1881         M_Print (16, 36,  " John Carmack       Adrian Carmack\n");
1882         M_Print (16, 44,  " Michael Abrash     Kevin Cloud\n");
1883         M_Print (16, 52,  " John Cash          Paul Steed\n");
1884         M_Print (16, 60,  " Dave 'Zoid' Kirsch\n");
1885         M_PrintWhite (16, 68,  "Design             Biz\n");
1886         M_Print (16, 76,  " John Romero        Jay Wilbur\n");
1887         M_Print (16, 84,  " Sandy Petersen     Mike Wilson\n");
1888         M_Print (16, 92,  " American McGee     Donna Jackson\n");
1889         M_Print (16, 100,  " Tim Willits        Todd Hollenshead\n");
1890         M_PrintWhite (16, 108, "Support            Projects\n");
1891         M_Print (16, 116, " Barrett Alexander  Shawn Green\n");
1892         M_PrintWhite (16, 124, "Sound Effects\n");
1893         M_Print (16, 132, " Trent Reznor and Nine Inch Nails\n\n");
1894         M_PrintWhite (16, 140, "Quake is a trademark of Id Software,\n");
1895         M_PrintWhite (16, 148, "inc., (c)1996 Id Software, inc. All\n");
1896         M_PrintWhite (16, 156, "rights reserved. NIN logo is a\n");
1897         M_PrintWhite (16, 164, "registered trademark licensed to\n");
1898         M_PrintWhite (16, 172, "Nothing Interactive, Inc. All rights\n");
1899         M_PrintWhite (16, 180, "reserved. Press y to exit\n");
1900 #else
1901 */
1902         M_DrawTextBox (56, 76, 24, 4);
1903         M_Print (64, 84,  quitMessage[msgNumber*4+0]);
1904         M_Print (64, 92,  quitMessage[msgNumber*4+1]);
1905         M_Print (64, 100, quitMessage[msgNumber*4+2]);
1906         M_Print (64, 108, quitMessage[msgNumber*4+3]);
1907 //#endif
1908 }
1909
1910 //=============================================================================
1911 /* LAN CONFIG MENU */
1912
1913 int             lanConfig_cursor = -1;
1914 int             lanConfig_cursor_table [] = {72, 92, 124};
1915 #define NUM_LANCONFIG_CMDS      3
1916
1917 int     lanConfig_port;
1918 char    lanConfig_portname[6];
1919 char    lanConfig_joinname[22];
1920
1921 void M_Menu_LanConfig_f (void)
1922 {
1923         key_dest = key_menu;
1924         m_state = m_lanconfig;
1925         m_entersound = true;
1926         if (lanConfig_cursor == -1)
1927         {
1928                 if (JoiningGame && TCPIPConfig)
1929                         lanConfig_cursor = 2;
1930                 else
1931                         lanConfig_cursor = 1;
1932         }
1933         if (StartingGame && lanConfig_cursor == 2)
1934                 lanConfig_cursor = 1;
1935         lanConfig_port = DEFAULTnet_hostport;
1936         sprintf(lanConfig_portname, "%u", lanConfig_port);
1937
1938         m_return_onerror = false;
1939         m_return_reason[0] = 0;
1940 }
1941
1942
1943 void M_LanConfig_Draw (void)
1944 {
1945         qpic_t  *p;
1946         int             basex;
1947         char    *startJoin;
1948         char    *protocol;
1949
1950         M_DrawPic (16, 4, Draw_CachePic ("gfx/qplaque.lmp") );
1951         p = Draw_CachePic ("gfx/p_multi.lmp");
1952         basex = (320-p->width)/2;
1953         M_DrawPic (basex, 4, p);
1954
1955         if (StartingGame)
1956                 startJoin = "New Game";
1957         else
1958                 startJoin = "Join Game";
1959         if (IPXConfig)
1960                 protocol = "IPX";
1961         else
1962                 protocol = "TCP/IP";
1963         M_Print (basex, 32, va ("%s - %s", startJoin, protocol));
1964         basex += 8;
1965
1966         M_Print (basex, 52, "Address:");
1967         if (IPXConfig)
1968                 M_Print (basex+9*8, 52, my_ipx_address);
1969         else
1970                 M_Print (basex+9*8, 52, my_tcpip_address);
1971
1972         M_Print (basex, lanConfig_cursor_table[0], "Port");
1973         M_DrawTextBox (basex+8*8, lanConfig_cursor_table[0]-8, 6, 1);
1974         M_Print (basex+9*8, lanConfig_cursor_table[0], lanConfig_portname);
1975
1976         if (JoiningGame)
1977         {
1978                 M_Print (basex, lanConfig_cursor_table[1], "Search for local games...");
1979                 M_Print (basex, 108, "Join game at:");
1980                 M_DrawTextBox (basex+8, lanConfig_cursor_table[2]-8, 22, 1);
1981                 M_Print (basex+16, lanConfig_cursor_table[2], lanConfig_joinname);
1982         }
1983         else
1984         {
1985                 M_DrawTextBox (basex, lanConfig_cursor_table[1]-8, 2, 1);
1986                 M_Print (basex+8, lanConfig_cursor_table[1], "OK");
1987         }
1988
1989         M_DrawCharacter (basex-8, lanConfig_cursor_table [lanConfig_cursor], 12+((int)(realtime*4)&1));
1990
1991         if (lanConfig_cursor == 0)
1992                 M_DrawCharacter (basex+9*8 + 8*strlen(lanConfig_portname), lanConfig_cursor_table [0], 10+((int)(realtime*4)&1));
1993
1994         if (lanConfig_cursor == 2)
1995                 M_DrawCharacter (basex+16 + 8*strlen(lanConfig_joinname), lanConfig_cursor_table [2], 10+((int)(realtime*4)&1));
1996
1997         if (*m_return_reason)
1998                 M_PrintWhite (basex, 148, m_return_reason);
1999 }
2000
2001
2002 void M_LanConfig_Key (int key)
2003 {
2004         int             l;
2005
2006         switch (key)
2007         {
2008         case K_ESCAPE:
2009                 M_Menu_Net_f ();
2010                 break;
2011
2012         case K_UPARROW:
2013                 S_LocalSound ("misc/menu1.wav");
2014                 lanConfig_cursor--;
2015                 if (lanConfig_cursor < 0)
2016                         lanConfig_cursor = NUM_LANCONFIG_CMDS-1;
2017                 break;
2018
2019         case K_DOWNARROW:
2020                 S_LocalSound ("misc/menu1.wav");
2021                 lanConfig_cursor++;
2022                 if (lanConfig_cursor >= NUM_LANCONFIG_CMDS)
2023                         lanConfig_cursor = 0;
2024                 break;
2025
2026         case K_ENTER:
2027                 if (lanConfig_cursor == 0)
2028                         break;
2029
2030                 m_entersound = true;
2031
2032                 M_ConfigureNetSubsystem ();
2033
2034                 if (lanConfig_cursor == 1)
2035                 {
2036                         if (StartingGame)
2037                         {
2038                                 M_Menu_GameOptions_f ();
2039                                 break;
2040                         }
2041                         M_Menu_Search_f();
2042                         break;
2043                 }
2044
2045                 if (lanConfig_cursor == 2)
2046                 {
2047                         m_return_state = m_state;
2048                         m_return_onerror = true;
2049                         key_dest = key_game;
2050                         m_state = m_none;
2051                         Cbuf_AddText ( va ("connect \"%s\"\n", lanConfig_joinname) );
2052                         break;
2053                 }
2054
2055                 break;
2056
2057         case K_BACKSPACE:
2058                 if (lanConfig_cursor == 0)
2059                 {
2060                         if (strlen(lanConfig_portname))
2061                                 lanConfig_portname[strlen(lanConfig_portname)-1] = 0;
2062                 }
2063
2064                 if (lanConfig_cursor == 2)
2065                 {
2066                         if (strlen(lanConfig_joinname))
2067                                 lanConfig_joinname[strlen(lanConfig_joinname)-1] = 0;
2068                 }
2069                 break;
2070
2071         default:
2072                 if (key < 32 || key > 127)
2073                         break;
2074
2075                 if (lanConfig_cursor == 2)
2076                 {
2077                         l = strlen(lanConfig_joinname);
2078                         if (l < 21)
2079                         {
2080                                 lanConfig_joinname[l+1] = 0;
2081                                 lanConfig_joinname[l] = key;
2082                         }
2083                 }
2084
2085                 if (key < '0' || key > '9')
2086                         break;
2087                 if (lanConfig_cursor == 0)
2088                 {
2089                         l = strlen(lanConfig_portname);
2090                         if (l < 5)
2091                         {
2092                                 lanConfig_portname[l+1] = 0;
2093                                 lanConfig_portname[l] = key;
2094                         }
2095                 }
2096         }
2097
2098         if (StartingGame && lanConfig_cursor == 2)
2099         {
2100                 if (key == K_UPARROW)
2101                         lanConfig_cursor = 1;
2102                 else
2103                         lanConfig_cursor = 0;
2104         }
2105
2106         l =  atoi(lanConfig_portname);
2107         if (l > 65535)
2108                 l = lanConfig_port;
2109         else
2110                 lanConfig_port = l;
2111         sprintf(lanConfig_portname, "%u", lanConfig_port);
2112 }
2113
2114 //=============================================================================
2115 /* GAME OPTIONS MENU */
2116
2117 typedef struct
2118 {
2119         char    *name;
2120         char    *description;
2121 } level_t;
2122
2123 level_t         levels[] =
2124 {
2125         {"start", "Entrance"},  // 0
2126
2127         {"e1m1", "Slipgate Complex"},                           // 1
2128         {"e1m2", "Castle of the Damned"},
2129         {"e1m3", "The Necropolis"},
2130         {"e1m4", "The Grisly Grotto"},
2131         {"e1m5", "Gloom Keep"},
2132         {"e1m6", "The Door To Chthon"},
2133         {"e1m7", "The House of Chthon"},
2134         {"e1m8", "Ziggurat Vertigo"},
2135
2136         {"e2m1", "The Installation"},                           // 9
2137         {"e2m2", "Ogre Citadel"},
2138         {"e2m3", "Crypt of Decay"},
2139         {"e2m4", "The Ebon Fortress"},
2140         {"e2m5", "The Wizard's Manse"},
2141         {"e2m6", "The Dismal Oubliette"},
2142         {"e2m7", "Underearth"},
2143
2144         {"e3m1", "Termination Central"},                        // 16
2145         {"e3m2", "The Vaults of Zin"},
2146         {"e3m3", "The Tomb of Terror"},
2147         {"e3m4", "Satan's Dark Delight"},
2148         {"e3m5", "Wind Tunnels"},
2149         {"e3m6", "Chambers of Torment"},
2150         {"e3m7", "The Haunted Halls"},
2151
2152         {"e4m1", "The Sewage System"},                          // 23
2153         {"e4m2", "The Tower of Despair"},
2154         {"e4m3", "The Elder God Shrine"},
2155         {"e4m4", "The Palace of Hate"},
2156         {"e4m5", "Hell's Atrium"},
2157         {"e4m6", "The Pain Maze"},
2158         {"e4m7", "Azure Agony"},
2159         {"e4m8", "The Nameless City"},
2160
2161         {"end", "Shub-Niggurath's Pit"},                        // 31
2162
2163         {"dm1", "Place of Two Deaths"},                         // 32
2164         {"dm2", "Claustrophobopolis"},
2165         {"dm3", "The Abandoned Base"},
2166         {"dm4", "The Bad Place"},
2167         {"dm5", "The Cistern"},
2168         {"dm6", "The Dark Zone"}
2169 };
2170
2171 //MED 01/06/97 added hipnotic levels
2172 level_t     hipnoticlevels[] =
2173 {
2174    {"start", "Command HQ"},  // 0
2175
2176    {"hip1m1", "The Pumping Station"},          // 1
2177    {"hip1m2", "Storage Facility"},
2178    {"hip1m3", "The Lost Mine"},
2179    {"hip1m4", "Research Facility"},
2180    {"hip1m5", "Military Complex"},
2181
2182    {"hip2m1", "Ancient Realms"},          // 6
2183    {"hip2m2", "The Black Cathedral"},
2184    {"hip2m3", "The Catacombs"},
2185    {"hip2m4", "The Crypt"},
2186    {"hip2m5", "Mortum's Keep"},
2187    {"hip2m6", "The Gremlin's Domain"},
2188
2189    {"hip3m1", "Tur Torment"},       // 12
2190    {"hip3m2", "Pandemonium"},
2191    {"hip3m3", "Limbo"},
2192    {"hip3m4", "The Gauntlet"},
2193
2194    {"hipend", "Armagon's Lair"},       // 16
2195
2196    {"hipdm1", "The Edge of Oblivion"}           // 17
2197 };
2198
2199 //PGM 01/07/97 added rogue levels
2200 //PGM 03/02/97 added dmatch level
2201 level_t         roguelevels[] =
2202 {
2203         {"start",       "Split Decision"},
2204         {"r1m1",        "Deviant's Domain"},
2205         {"r1m2",        "Dread Portal"},
2206         {"r1m3",        "Judgement Call"},
2207         {"r1m4",        "Cave of Death"},
2208         {"r1m5",        "Towers of Wrath"},
2209         {"r1m6",        "Temple of Pain"},
2210         {"r1m7",        "Tomb of the Overlord"},
2211         {"r2m1",        "Tempus Fugit"},
2212         {"r2m2",        "Elemental Fury I"},
2213         {"r2m3",        "Elemental Fury II"},
2214         {"r2m4",        "Curse of Osiris"},
2215         {"r2m5",        "Wizard's Keep"},
2216         {"r2m6",        "Blood Sacrifice"},
2217         {"r2m7",        "Last Bastion"},
2218         {"r2m8",        "Source of Evil"},
2219         {"ctf1",    "Division of Change"}
2220 };
2221
2222 typedef struct
2223 {
2224         char    *description;
2225         int             firstLevel;
2226         int             levels;
2227 } episode_t;
2228
2229 episode_t       episodes[] =
2230 {
2231         {"Welcome to Quake", 0, 1},
2232         {"Doomed Dimension", 1, 8},
2233         {"Realm of Black Magic", 9, 7},
2234         {"Netherworld", 16, 7},
2235         {"The Elder World", 23, 8},
2236         {"Final Level", 31, 1},
2237         {"Deathmatch Arena", 32, 6}
2238 };
2239
2240 //MED 01/06/97  added hipnotic episodes
2241 episode_t   hipnoticepisodes[] =
2242 {
2243    {"Scourge of Armagon", 0, 1},
2244    {"Fortress of the Dead", 1, 5},
2245    {"Dominion of Darkness", 6, 6},
2246    {"The Rift", 12, 4},
2247    {"Final Level", 16, 1},
2248    {"Deathmatch Arena", 17, 1}
2249 };
2250
2251 //PGM 01/07/97 added rogue episodes
2252 //PGM 03/02/97 added dmatch episode
2253 episode_t       rogueepisodes[] =
2254 {
2255         {"Introduction", 0, 1},
2256         {"Hell's Fortress", 1, 7},
2257         {"Corridors of Time", 8, 8},
2258         {"Deathmatch Arena", 16, 1}
2259 };
2260
2261 level_t         nehahralevels[] =
2262 {
2263         {"nehstart",    "Welcome to Nehahra"},
2264         {"neh1m1",      "Forge City1: Slipgates"},
2265         {"neh1m2",      "Forge City2: Boiler"},
2266         {"neh1m3",      "Forge City3: Escape"},
2267         {"neh1m4",      "Grind Core"},
2268         {"neh1m5",      "Industrial Silence"},
2269         {"neh1m6",      "Locked-Up Anger"},
2270         {"neh1m7",      "Wanderer of the Wastes"},
2271         {"neh1m8",      "Artemis System Net"},
2272         {"neh1m9",      "To the Death"},
2273         {"neh2m1",      "The Gates of Ghoro"},
2274         {"neh2m2",      "Sacred Trinity"},
2275         {"neh2m3",      "Realm of the Ancients"},
2276         {"neh2m4",      "Temple of the Ancients"},
2277         {"neh2m5",      "Dreams Made Flesh"},
2278         {"neh2m6",      "Your Last Cup of Sorrow"},
2279         {"nehsec",      "Ogre's Bane"},
2280         {"nehahra",     "Nehahra's Den"},
2281         {"nehend",      "Quintessence"}
2282 };
2283
2284 episode_t       nehahraepisodes[] =
2285 {
2286         {"Welcome to Nehahra", 0, 1},
2287         {"The Fall of Forge", 1, 9},
2288         {"The Outlands", 10, 7},
2289         {"Dimension of the Lost", 17, 2}
2290 };
2291
2292 int     startepisode;
2293 int     startlevel;
2294 int maxplayers;
2295 qboolean m_serverInfoMessage = false;
2296 double m_serverInfoMessageTime;
2297
2298 void M_Menu_GameOptions_f (void)
2299 {
2300         key_dest = key_menu;
2301         m_state = m_gameoptions;
2302         m_entersound = true;
2303         if (maxplayers == 0)
2304                 maxplayers = svs.maxclients;
2305         if (maxplayers < 2)
2306                 maxplayers = svs.maxclientslimit;
2307 }
2308
2309
2310 int gameoptions_cursor_table[] = {40, 56, 64, 72, 80, 88, 96, 112, 120};
2311 #define NUM_GAMEOPTIONS 9
2312 int             gameoptions_cursor;
2313
2314 void M_GameOptions_Draw (void)
2315 {
2316         qpic_t  *p;
2317         int             x;
2318
2319         M_DrawPic (16, 4, Draw_CachePic ("gfx/qplaque.lmp") );
2320         p = Draw_CachePic ("gfx/p_multi.lmp");
2321         M_DrawPic ( (320-p->width)/2, 4, p);
2322
2323         M_DrawTextBox (152, 32, 10, 1);
2324         M_Print (160, 40, "begin game");
2325
2326         M_Print (0, 56, "      Max players");
2327         M_Print (160, 56, va("%i", maxplayers) );
2328
2329         M_Print (0, 64, "        Game Type");
2330         if (!coop.value && !deathmatch.value)
2331                 Cvar_SetValue("deathmatch", 1);
2332         if (coop.value)
2333                 M_Print (160, 64, "Cooperative");
2334         else
2335                 M_Print (160, 64, "Deathmatch");
2336
2337         M_Print (0, 72, "        Teamplay");
2338         if (rogue)
2339         {
2340                 char *msg;
2341
2342                 switch((int)teamplay.value)
2343                 {
2344                         case 1: msg = "No Friendly Fire"; break;
2345                         case 2: msg = "Friendly Fire"; break;
2346                         case 3: msg = "Tag"; break;
2347                         case 4: msg = "Capture the Flag"; break;
2348                         case 5: msg = "One Flag CTF"; break;
2349                         case 6: msg = "Three Team CTF"; break;
2350                         default: msg = "Off"; break;
2351                 }
2352                 M_Print (160, 72, msg);
2353         }
2354         else
2355         {
2356                 char *msg;
2357
2358                 switch((int)teamplay.value)
2359                 {
2360                         case 1: msg = "No Friendly Fire"; break;
2361                         case 2: msg = "Friendly Fire"; break;
2362                         default: msg = "Off"; break;
2363                 }
2364                 M_Print (160, 72, msg);
2365         }
2366
2367         M_Print (0, 80, "            Skill");
2368         if (skill.value == 0)
2369                 M_Print (160, 80, "Easy difficulty");
2370         else if (skill.value == 1)
2371                 M_Print (160, 80, "Normal difficulty");
2372         else if (skill.value == 2)
2373                 M_Print (160, 80, "Hard difficulty");
2374         else
2375                 M_Print (160, 80, "Nightmare difficulty");
2376
2377         M_Print (0, 88, "       Frag Limit");
2378         if (fraglimit.value == 0)
2379                 M_Print (160, 88, "none");
2380         else
2381                 M_Print (160, 88, va("%i frags", (int)fraglimit.value));
2382
2383         M_Print (0, 96, "       Time Limit");
2384         if (timelimit.value == 0)
2385                 M_Print (160, 96, "none");
2386         else
2387                 M_Print (160, 96, va("%i minutes", (int)timelimit.value));
2388
2389         M_Print (0, 112, "         Episode");
2390    //MED 01/06/97 added hipnotic episodes
2391    if (hipnotic)
2392       M_Print (160, 112, hipnoticepisodes[startepisode].description);
2393    //PGM 01/07/97 added rogue episodes
2394    else if (rogue)
2395       M_Print (160, 112, rogueepisodes[startepisode].description);
2396    else if (nehahra)
2397       M_Print (160, 112, nehahraepisodes[startepisode].description);
2398    else
2399       M_Print (160, 112, episodes[startepisode].description);
2400
2401         M_Print (0, 120, "           Level");
2402    //MED 01/06/97 added hipnotic episodes
2403    if (hipnotic)
2404    {
2405       M_Print (160, 120, hipnoticlevels[hipnoticepisodes[startepisode].firstLevel + startlevel].description);
2406       M_Print (160, 128, hipnoticlevels[hipnoticepisodes[startepisode].firstLevel + startlevel].name);
2407    }
2408    //PGM 01/07/97 added rogue episodes
2409    else if (rogue)
2410    {
2411       M_Print (160, 120, roguelevels[rogueepisodes[startepisode].firstLevel + startlevel].description);
2412       M_Print (160, 128, roguelevels[rogueepisodes[startepisode].firstLevel + startlevel].name);
2413    }
2414    else if (nehahra)
2415    {
2416       M_Print (160, 120, nehahralevels[nehahraepisodes[startepisode].firstLevel + startlevel].description);
2417       M_Print (160, 128, nehahralevels[nehahraepisodes[startepisode].firstLevel + startlevel].name);
2418    }
2419    else
2420    {
2421       M_Print (160, 120, levels[episodes[startepisode].firstLevel + startlevel].description);
2422       M_Print (160, 128, levels[episodes[startepisode].firstLevel + startlevel].name);
2423    }
2424
2425 // line cursor
2426         M_DrawCharacter (144, gameoptions_cursor_table[gameoptions_cursor], 12+((int)(realtime*4)&1));
2427
2428         if (m_serverInfoMessage)
2429         {
2430                 if ((realtime - m_serverInfoMessageTime) < 5.0)
2431                 {
2432                         x = (320-26*8)/2;
2433                         M_DrawTextBox (x, 138, 24, 4);
2434                         x += 8;
2435                         M_Print (x, 146, " More than 64 players?? ");
2436                         M_Print (x, 154, "  First, question your  ");
2437                         M_Print (x, 162, "   sanity, then email   ");
2438                         M_Print (x, 170, " havoc@gamevisions.com  ");
2439                         /*
2440                         M_Print (x, 146, "  More than 4 players   ");
2441                         M_Print (x, 154, " requires using command ");
2442                         M_Print (x, 162, "line parameters; please ");
2443                         M_Print (x, 170, "   see techinfo.txt.    ");
2444                         */
2445                 }
2446                 else
2447                 {
2448                         m_serverInfoMessage = false;
2449                 }
2450         }
2451 }
2452
2453
2454 void M_NetStart_Change (int dir)
2455 {
2456         int count;
2457
2458         switch (gameoptions_cursor)
2459         {
2460         case 1:
2461                 maxplayers += dir;
2462                 if (maxplayers > svs.maxclientslimit)
2463                 {
2464                         maxplayers = svs.maxclientslimit;
2465                         m_serverInfoMessage = true;
2466                         m_serverInfoMessageTime = realtime;
2467                 }
2468                 if (maxplayers < 2)
2469                         maxplayers = 2;
2470                 break;
2471
2472         case 2:
2473                 if (deathmatch.value) // changing from deathmatch to coop
2474                 {
2475                         Cvar_SetValue ("coop", 1);
2476                         Cvar_SetValue ("deathmatch", 0);
2477                 }
2478                 else // changing from coop to deathmatch
2479                 {
2480                         Cvar_SetValue ("coop", 0);
2481                         Cvar_SetValue ("deathmatch", 1);
2482                 }
2483                 break;
2484
2485         case 3:
2486                 if (rogue)
2487                         count = 6;
2488                 else
2489                         count = 2;
2490
2491                 Cvar_SetValue ("teamplay", teamplay.value + dir);
2492                 if (teamplay.value > count)
2493                         Cvar_SetValue ("teamplay", 0);
2494                 else if (teamplay.value < 0)
2495                         Cvar_SetValue ("teamplay", count);
2496                 break;
2497
2498         case 4:
2499                 Cvar_SetValue ("skill", skill.value + dir);
2500                 if (skill.value > 3)
2501                         Cvar_SetValue ("skill", 0);
2502                 if (skill.value < 0)
2503                         Cvar_SetValue ("skill", 3);
2504                 break;
2505
2506         case 5:
2507                 Cvar_SetValue ("fraglimit", fraglimit.value + dir*10);
2508                 if (fraglimit.value > 100)
2509                         Cvar_SetValue ("fraglimit", 0);
2510                 if (fraglimit.value < 0)
2511                         Cvar_SetValue ("fraglimit", 100);
2512                 break;
2513
2514         case 6:
2515                 Cvar_SetValue ("timelimit", timelimit.value + dir*5);
2516                 if (timelimit.value > 60)
2517                         Cvar_SetValue ("timelimit", 0);
2518                 if (timelimit.value < 0)
2519                         Cvar_SetValue ("timelimit", 60);
2520                 break;
2521
2522         case 7:
2523                 startepisode += dir;
2524         //MED 01/06/97 added hipnotic count
2525                 if (hipnotic)
2526                         count = 6;
2527         //PGM 01/07/97 added rogue count
2528         //PGM 03/02/97 added 1 for dmatch episode
2529                 else if (rogue)
2530                         count = 4;
2531                 else if (nehahra)
2532                         count = 4;
2533                 else if (registered.value)
2534                         count = 7;
2535                 else
2536                         count = 2;
2537
2538                 if (startepisode < 0)
2539                         startepisode = count - 1;
2540
2541                 if (startepisode >= count)
2542                         startepisode = 0;
2543
2544                 startlevel = 0;
2545                 break;
2546
2547         case 8:
2548                 startlevel += dir;
2549     //MED 01/06/97 added hipnotic episodes
2550                 if (hipnotic)
2551                         count = hipnoticepisodes[startepisode].levels;
2552         //PGM 01/06/97 added hipnotic episodes
2553                 else if (rogue)
2554                         count = rogueepisodes[startepisode].levels;
2555                 else if (nehahra)
2556                         count = nehahraepisodes[startepisode].levels;
2557                 else
2558                         count = episodes[startepisode].levels;
2559
2560                 if (startlevel < 0)
2561                         startlevel = count - 1;
2562
2563                 if (startlevel >= count)
2564                         startlevel = 0;
2565                 break;
2566         }
2567 }
2568
2569 void M_GameOptions_Key (int key)
2570 {
2571         switch (key)
2572         {
2573         case K_ESCAPE:
2574                 M_Menu_Net_f ();
2575                 break;
2576
2577         case K_UPARROW:
2578                 S_LocalSound ("misc/menu1.wav");
2579                 gameoptions_cursor--;
2580                 if (gameoptions_cursor < 0)
2581                         gameoptions_cursor = NUM_GAMEOPTIONS-1;
2582                 break;
2583
2584         case K_DOWNARROW:
2585                 S_LocalSound ("misc/menu1.wav");
2586                 gameoptions_cursor++;
2587                 if (gameoptions_cursor >= NUM_GAMEOPTIONS)
2588                         gameoptions_cursor = 0;
2589                 break;
2590
2591         case K_LEFTARROW:
2592                 if (gameoptions_cursor == 0)
2593                         break;
2594                 S_LocalSound ("misc/menu3.wav");
2595                 M_NetStart_Change (-1);
2596                 break;
2597
2598         case K_RIGHTARROW:
2599                 if (gameoptions_cursor == 0)
2600                         break;
2601                 S_LocalSound ("misc/menu3.wav");
2602                 M_NetStart_Change (1);
2603                 break;
2604
2605         case K_ENTER:
2606                 S_LocalSound ("misc/menu2.wav");
2607                 if (gameoptions_cursor == 0)
2608                 {
2609                         if (sv.active)
2610                                 Cbuf_AddText ("disconnect\n");
2611                         Cbuf_AddText ("listen 0\n");    // so host_netport will be re-examined
2612                         Cbuf_AddText ( va ("maxplayers %u\n", maxplayers) );
2613 //                      SCR_BeginLoadingPlaque ();
2614
2615                         if (hipnotic)
2616                                 Cbuf_AddText ( va ("map %s\n", hipnoticlevels[hipnoticepisodes[startepisode].firstLevel + startlevel].name) );
2617                         else if (rogue)
2618                                 Cbuf_AddText ( va ("map %s\n", roguelevels[rogueepisodes[startepisode].firstLevel + startlevel].name) );
2619                         else if (nehahra)
2620                                 Cbuf_AddText ( va ("map %s\n", nehahralevels[nehahraepisodes[startepisode].firstLevel + startlevel].name) );
2621                         else
2622                                 Cbuf_AddText ( va ("map %s\n", levels[episodes[startepisode].firstLevel + startlevel].name) );
2623
2624                         return;
2625                 }
2626
2627                 M_NetStart_Change (1);
2628                 break;
2629         }
2630 }
2631
2632 //=============================================================================
2633 /* SEARCH MENU */
2634
2635 qboolean        searchComplete = false;
2636 double          searchCompleteTime;
2637
2638 void M_Menu_Search_f (void)
2639 {
2640         key_dest = key_menu;
2641         m_state = m_search;
2642         m_entersound = false;
2643         slistSilent = true;
2644         slistLocal = false;
2645         searchComplete = false;
2646         NET_Slist_f();
2647
2648 }
2649
2650
2651 void M_Search_Draw (void)
2652 {
2653         qpic_t  *p;
2654         int x;
2655
2656         p = Draw_CachePic ("gfx/p_multi.lmp");
2657         M_DrawPic ( (320-p->width)/2, 4, p);
2658         x = (320/2) - ((12*8)/2) + 4;
2659         M_DrawTextBox (x-8, 32, 12, 1);
2660         M_Print (x, 40, "Searching...");
2661
2662         if(slistInProgress)
2663         {
2664                 NET_Poll();
2665                 return;
2666         }
2667
2668         if (! searchComplete)
2669         {
2670                 searchComplete = true;
2671                 searchCompleteTime = realtime;
2672         }
2673
2674         if (hostCacheCount)
2675         {
2676                 M_Menu_ServerList_f ();
2677                 return;
2678         }
2679
2680         M_PrintWhite ((320/2) - ((22*8)/2), 64, "No Quake servers found");
2681         if ((realtime - searchCompleteTime) < 3.0)
2682                 return;
2683
2684         M_Menu_LanConfig_f ();
2685 }
2686
2687
2688 void M_Search_Key (int key)
2689 {
2690 }
2691
2692 //=============================================================================
2693 /* SLIST MENU */
2694
2695 int             slist_cursor;
2696 qboolean slist_sorted;
2697
2698 void M_Menu_ServerList_f (void)
2699 {
2700         key_dest = key_menu;
2701         m_state = m_slist;
2702         m_entersound = true;
2703         slist_cursor = 0;
2704         m_return_onerror = false;
2705         m_return_reason[0] = 0;
2706         slist_sorted = false;
2707 }
2708
2709
2710 void M_ServerList_Draw (void)
2711 {
2712         int             n;
2713         char    string [64];
2714         qpic_t  *p;
2715
2716         if (!slist_sorted)
2717         {
2718                 if (hostCacheCount > 1)
2719                 {
2720                         int     i,j;
2721                         hostcache_t temp;
2722                         for (i = 0; i < hostCacheCount; i++)
2723                                 for (j = i+1; j < hostCacheCount; j++)
2724                                         if (strcmp(hostcache[j].name, hostcache[i].name) < 0)
2725                                         {
2726                                                 memcpy(&temp, &hostcache[j], sizeof(hostcache_t));
2727                                                 memcpy(&hostcache[j], &hostcache[i], sizeof(hostcache_t));
2728                                                 memcpy(&hostcache[i], &temp, sizeof(hostcache_t));
2729                                         }
2730                 }
2731                 slist_sorted = true;
2732         }
2733
2734         p = Draw_CachePic ("gfx/p_multi.lmp");
2735         M_DrawPic ( (320-p->width)/2, 4, p);
2736         for (n = 0; n < hostCacheCount; n++)
2737         {
2738                 if (hostcache[n].maxusers)
2739                         sprintf(string, "%-15.15s %-15.15s %2u/%2u\n", hostcache[n].name, hostcache[n].map, hostcache[n].users, hostcache[n].maxusers);
2740                 else
2741                         sprintf(string, "%-15.15s %-15.15s\n", hostcache[n].name, hostcache[n].map);
2742                 M_Print (16, 32 + 8*n, string);
2743         }
2744         M_DrawCharacter (0, 32 + slist_cursor*8, 12+((int)(realtime*4)&1));
2745
2746         if (*m_return_reason)
2747                 M_PrintWhite (16, 148, m_return_reason);
2748 }
2749
2750
2751 void M_ServerList_Key (int k)
2752 {
2753         switch (k)
2754         {
2755         case K_ESCAPE:
2756                 M_Menu_LanConfig_f ();
2757                 break;
2758
2759         case K_SPACE:
2760                 M_Menu_Search_f ();
2761                 break;
2762
2763         case K_UPARROW:
2764         case K_LEFTARROW:
2765                 S_LocalSound ("misc/menu1.wav");
2766                 slist_cursor--;
2767                 if (slist_cursor < 0)
2768                         slist_cursor = hostCacheCount - 1;
2769                 break;
2770
2771         case K_DOWNARROW:
2772         case K_RIGHTARROW:
2773                 S_LocalSound ("misc/menu1.wav");
2774                 slist_cursor++;
2775                 if (slist_cursor >= hostCacheCount)
2776                         slist_cursor = 0;
2777                 break;
2778
2779         case K_ENTER:
2780                 S_LocalSound ("misc/menu2.wav");
2781                 m_return_state = m_state;
2782                 m_return_onerror = true;
2783                 slist_sorted = false;
2784                 key_dest = key_game;
2785                 m_state = m_none;
2786                 Cbuf_AddText ( va ("connect \"%s\"\n", hostcache[slist_cursor].cname) );
2787                 break;
2788
2789         default:
2790                 break;
2791         }
2792
2793 }
2794
2795 //=============================================================================
2796 /* Menu Subsystem */
2797
2798
2799 void M_Init (void)
2800 {
2801         Cmd_AddCommand ("togglemenu", M_ToggleMenu_f);
2802
2803         Cmd_AddCommand ("menu_main", M_Menu_Main_f);
2804         Cmd_AddCommand ("menu_singleplayer", M_Menu_SinglePlayer_f);
2805         Cmd_AddCommand ("menu_load", M_Menu_Load_f);
2806         Cmd_AddCommand ("menu_save", M_Menu_Save_f);
2807         Cmd_AddCommand ("menu_multiplayer", M_Menu_MultiPlayer_f);
2808         Cmd_AddCommand ("menu_setup", M_Menu_Setup_f);
2809         Cmd_AddCommand ("menu_options", M_Menu_Options_f);
2810         Cmd_AddCommand ("menu_keys", M_Menu_Keys_f);
2811         Cmd_AddCommand ("menu_video", M_Menu_Video_f);
2812         Cmd_AddCommand ("help", M_Menu_Help_f);
2813         Cmd_AddCommand ("menu_quit", M_Menu_Quit_f);
2814
2815         if (nehahra)
2816         {
2817                 if (COM_FileExists("maps/neh1m4.bsp"))
2818                 {
2819                         if (COM_FileExists("hearing.dem"))
2820                         {
2821                                 Con_Printf("Nehahra movie and game detected.\n");
2822                                 NehGameType = TYPE_BOTH;
2823                         }
2824                         else
2825                         {
2826                                 Con_Printf("Nehahra game detected.\n");
2827                                 NehGameType = TYPE_GAME;
2828                         }
2829                 }
2830                 else
2831                 {
2832                         if (COM_FileExists("hearing.dem"))
2833                         {
2834                                 Con_Printf("Nehahra movie detected.\n");
2835                                 NehGameType = TYPE_DEMO;
2836                         }
2837                         else
2838                         {
2839                                 Con_Printf("Nehahra not found.\n");
2840                                 NehGameType = TYPE_GAME; // could just complain, but...
2841                         }
2842                 }
2843         }
2844 }
2845
2846
2847 void M_Draw (void)
2848 {
2849         if (m_state == m_none || key_dest != key_menu)
2850                 return;
2851
2852         /*
2853         if (!m_recursiveDraw)
2854         {
2855                 if (scr_con_current)
2856                 {
2857                         Draw_ConsoleBackground (vid.height);
2858                         S_ExtraUpdate ();
2859                 }
2860         }
2861         else
2862         {
2863                 m_recursiveDraw = false;
2864         }
2865         */
2866
2867         switch (m_state)
2868         {
2869         case m_none:
2870                 break;
2871
2872         case m_main:
2873                 M_Main_Draw ();
2874                 break;
2875
2876         case m_demo:
2877                 M_Demo_Draw ();
2878                 break;
2879
2880         case m_singleplayer:
2881                 M_SinglePlayer_Draw ();
2882                 break;
2883
2884         case m_load:
2885                 M_Load_Draw ();
2886                 break;
2887
2888         case m_save:
2889                 M_Save_Draw ();
2890                 break;
2891
2892         case m_multiplayer:
2893                 M_MultiPlayer_Draw ();
2894                 break;
2895
2896         case m_setup:
2897                 M_Setup_Draw ();
2898                 break;
2899
2900         case m_net:
2901                 M_Net_Draw ();
2902                 break;
2903
2904         case m_options:
2905                 M_Options_Draw ();
2906                 break;
2907
2908         case m_keys:
2909                 M_Keys_Draw ();
2910                 break;
2911
2912         case m_video:
2913                 M_Video_Draw ();
2914                 break;
2915
2916         case m_help:
2917                 M_Help_Draw ();
2918                 break;
2919
2920         case m_quit:
2921                 M_Quit_Draw ();
2922                 break;
2923
2924         case m_lanconfig:
2925                 M_LanConfig_Draw ();
2926                 break;
2927
2928         case m_gameoptions:
2929                 M_GameOptions_Draw ();
2930                 break;
2931
2932         case m_search:
2933                 M_Search_Draw ();
2934                 break;
2935
2936         case m_slist:
2937                 M_ServerList_Draw ();
2938                 break;
2939         }
2940
2941         if (m_entersound)
2942         {
2943                 S_LocalSound ("misc/menu2.wav");
2944                 m_entersound = false;
2945         }
2946
2947         S_ExtraUpdate ();
2948 }
2949
2950
2951 void M_Keydown (int key)
2952 {
2953         switch (m_state)
2954         {
2955         case m_none:
2956                 return;
2957
2958         case m_main:
2959                 M_Main_Key (key);
2960                 return;
2961
2962         case m_demo:
2963                 M_Demo_Key (key);
2964                 return;
2965
2966         case m_singleplayer:
2967                 M_SinglePlayer_Key (key);
2968                 return;
2969
2970         case m_load:
2971                 M_Load_Key (key);
2972                 return;
2973
2974         case m_save:
2975                 M_Save_Key (key);
2976                 return;
2977
2978         case m_multiplayer:
2979                 M_MultiPlayer_Key (key);
2980                 return;
2981
2982         case m_setup:
2983                 M_Setup_Key (key);
2984                 return;
2985
2986         case m_net:
2987                 M_Net_Key (key);
2988                 return;
2989
2990         case m_options:
2991                 M_Options_Key (key);
2992                 return;
2993
2994         case m_keys:
2995                 M_Keys_Key (key);
2996                 return;
2997
2998         case m_video:
2999                 M_Video_Key (key);
3000                 return;
3001
3002         case m_help:
3003                 M_Help_Key (key);
3004                 return;
3005
3006         case m_quit:
3007                 M_Quit_Key (key);
3008                 return;
3009
3010         case m_lanconfig:
3011                 M_LanConfig_Key (key);
3012                 return;
3013
3014         case m_gameoptions:
3015                 M_GameOptions_Key (key);
3016                 return;
3017
3018         case m_search:
3019                 M_Search_Key (key);
3020                 break;
3021
3022         case m_slist:
3023                 M_ServerList_Key (key);
3024                 return;
3025         }
3026 }
3027
3028
3029 void M_ConfigureNetSubsystem(void)
3030 {
3031 // enable/disable net systems to match desired config
3032
3033         Cbuf_AddText ("stopdemo\n");
3034
3035         if (IPXConfig || TCPIPConfig)
3036                 net_hostport = lanConfig_port;
3037 }