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