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