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