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