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