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