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