]> icculus.org git repositories - divverent/darkplaces.git/blob - menu.c
simplified explosion rendering a little (probably a very minor slowdown, but more...
[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%i.sav", 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                         key_dest = key_game;
1443                         Con_ToggleConsole_f ();
1444                         break;
1445                 case 2:
1446                         Cbuf_AddText ("exec default.cfg\n");
1447                         break;
1448                 case 3:
1449                         M_Menu_Video_f ();
1450                         break;
1451                 case 4:
1452                         M_Menu_Options_Effects_f ();
1453                         break;
1454                 case 5:
1455                         M_Menu_Options_ColorControl_f ();
1456                         break;
1457                 default:
1458                         M_Menu_Options_AdjustSliders (1);
1459                         break;
1460                 }
1461                 return;
1462
1463         case K_UPARROW:
1464                 S_LocalSound ("misc/menu1.wav");
1465                 options_cursor--;
1466                 if (options_cursor < 0)
1467                         options_cursor = OPTIONS_ITEMS-1;
1468                 break;
1469
1470         case K_DOWNARROW:
1471                 S_LocalSound ("misc/menu1.wav");
1472                 options_cursor++;
1473                 if (options_cursor >= OPTIONS_ITEMS)
1474                         options_cursor = 0;
1475                 break;
1476
1477         case K_LEFTARROW:
1478                 M_Menu_Options_AdjustSliders (-1);
1479                 break;
1480
1481         case K_RIGHTARROW:
1482                 M_Menu_Options_AdjustSliders (1);
1483                 break;
1484         }
1485 }
1486
1487 #define OPTIONS_EFFECTS_ITEMS   16
1488
1489 int options_effects_cursor;
1490
1491 void M_Menu_Options_Effects_f (void)
1492 {
1493         key_dest = key_menu;
1494         m_state = m_options_effects;
1495         m_entersound = true;
1496 }
1497
1498
1499 extern cvar_t r_detailtextures;
1500 extern cvar_t cl_particles;
1501 extern cvar_t cl_explosions;
1502 extern cvar_t cl_stainmaps;
1503 extern cvar_t r_explosionclip;
1504 extern cvar_t r_dlightmap;
1505 extern cvar_t r_modellights;
1506 extern cvar_t r_coronas;
1507 extern cvar_t gl_flashblend;
1508 extern cvar_t cl_particles_bulletimpacts;
1509 extern cvar_t cl_particles_smoke;
1510 extern cvar_t cl_particles_sparks;
1511 extern cvar_t cl_particles_bubbles;
1512 extern cvar_t cl_particles_blood;
1513 extern cvar_t cl_particles_blood_size;
1514 extern cvar_t cl_particles_blood_alpha;
1515
1516 void M_Menu_Options_Effects_AdjustSliders (int dir)
1517 {
1518         S_LocalSound ("misc/menu3.wav");
1519
1520         switch (options_effects_cursor)
1521         {
1522         case 0:
1523                 Cvar_SetValueQuick (&r_modellights, bound(0, r_modellights.value + dir, 8));
1524                 break;
1525         case 1:
1526                 Cvar_SetValueQuick (&r_dlightmap, !r_dlightmap.integer);
1527                 break;
1528         case 2:
1529                 Cvar_SetValueQuick (&r_coronas, !r_coronas.integer);
1530                 break;
1531         case 3:
1532                 Cvar_SetValueQuick (&gl_flashblend, !gl_flashblend.integer);
1533                 break;
1534         case 4:
1535                 Cvar_SetValueQuick (&cl_particles, !cl_particles.integer);
1536                 break;
1537         case 5:
1538                 Cvar_SetValueQuick (&cl_explosions, !cl_explosions.integer);
1539                 break;
1540         case 6:
1541                 Cvar_SetValueQuick (&r_explosionclip, !r_explosionclip.integer);
1542                 break;
1543         case 7:
1544                 Cvar_SetValueQuick (&cl_stainmaps, !cl_stainmaps.integer);
1545                 break;
1546         case 8:
1547                 Cvar_SetValueQuick (&r_detailtextures, !r_detailtextures.integer);
1548                 break;
1549         case 9:
1550                 Cvar_SetValueQuick (&cl_particles_bulletimpacts, !cl_particles_bulletimpacts.integer);
1551                 break;
1552         case 10:
1553                 Cvar_SetValueQuick (&cl_particles_smoke, !cl_particles_smoke.integer);
1554                 break;
1555         case 11:
1556                 Cvar_SetValueQuick (&cl_particles_sparks, !cl_particles_sparks.integer);
1557                 break;
1558         case 12:
1559                 Cvar_SetValueQuick (&cl_particles_bubbles, !cl_particles_bubbles.integer);
1560                 break;
1561         case 13:
1562                 Cvar_SetValueQuick (&cl_particles_blood, !cl_particles_blood.integer);
1563                 break;
1564         case 14:
1565                 Cvar_SetValueQuick (&cl_particles_blood_size, bound(2, cl_particles_blood_size.value + dir * 1, 20));
1566                 break;
1567         case 15:
1568                 Cvar_SetValueQuick (&cl_particles_blood_alpha, bound(0.2, cl_particles_blood_alpha.value + dir * 0.1, 1));
1569                 break;
1570         }
1571 }
1572
1573 void M_Options_Effects_Draw (void)
1574 {
1575         float y;
1576         cachepic_t      *p;
1577
1578         M_DrawPic(16, 4, "gfx/qplaque.lmp");
1579         p = Draw_CachePic("gfx/p_option.lmp");
1580         M_DrawPic((320-p->width)/2, 4, "gfx/p_option.lmp");
1581
1582         y = 32;
1583         M_Print(16, y, "      Lights Per Model");M_DrawSlider(220, y, r_modellights.value, 0, 8);y += 8;
1584         M_Print(16, y, " Fast Dynamic Lighting");M_DrawCheckbox(220, y, !r_dlightmap.integer);y += 8;
1585         M_Print(16, y, "               Coronas");M_DrawCheckbox(220, y, r_coronas.integer);y += 8;
1586         M_Print(16, y, "      Use Only Coronas");M_DrawCheckbox(220, y, gl_flashblend.integer);y += 8;
1587         M_Print(16, y, "             Particles");M_DrawCheckbox(220, y, cl_particles.integer);y += 8;
1588         M_Print(16, y, "            Explosions");M_DrawCheckbox(220, y, cl_explosions.integer);y += 8;
1589         M_Print(16, y, "    Explosion Clipping");M_DrawCheckbox(220, y, r_explosionclip.integer);y += 8;
1590         M_Print(16, y, "             Stainmaps");M_DrawCheckbox(220, y, cl_stainmaps.integer);y += 8;
1591         M_Print(16, y, "      Detail Texturing");M_DrawCheckbox(220, y, r_detailtextures.integer);y += 8;
1592         M_Print(16, y, "        Bullet Impacts");M_DrawCheckbox(220, y, cl_particles_bulletimpacts.integer);y += 8;
1593         M_Print(16, y, "                 Smoke");M_DrawCheckbox(220, y, cl_particles_smoke.integer);y += 8;
1594         M_Print(16, y, "                Sparks");M_DrawCheckbox(220, y, cl_particles_sparks.integer);y += 8;
1595         M_Print(16, y, "               Bubbles");M_DrawCheckbox(220, y, cl_particles_bubbles.integer);y += 8;
1596         M_Print(16, y, "                 Blood");M_DrawCheckbox(220, y, cl_particles_blood.integer);y += 8;
1597         M_Print(16, y, "            Blood Size");M_DrawSlider(220, y, cl_particles_blood_size.value, 2, 20);y += 8;
1598         M_Print(16, y, "         Blood Opacity");M_DrawSlider(220, y, cl_particles_blood_alpha.value, 0.2, 1);y += 8;
1599
1600         // cursor
1601         M_DrawCharacter(200, 32 + options_effects_cursor*8, 12+((int)(realtime*4)&1));
1602 }
1603
1604
1605 void M_Options_Effects_Key (int k)
1606 {
1607         switch (k)
1608         {
1609         case K_ESCAPE:
1610                 M_Menu_Options_f ();
1611                 break;
1612
1613         case K_ENTER:
1614                 M_Menu_Options_Effects_AdjustSliders (1);
1615                 break;
1616
1617         case K_UPARROW:
1618                 S_LocalSound ("misc/menu1.wav");
1619                 options_effects_cursor--;
1620                 if (options_effects_cursor < 0)
1621                         options_effects_cursor = OPTIONS_EFFECTS_ITEMS-1;
1622                 break;
1623
1624         case K_DOWNARROW:
1625                 S_LocalSound ("misc/menu1.wav");
1626                 options_effects_cursor++;
1627                 if (options_effects_cursor >= OPTIONS_EFFECTS_ITEMS)
1628                         options_effects_cursor = 0;
1629                 break;
1630
1631         case K_LEFTARROW:
1632                 M_Menu_Options_Effects_AdjustSliders (-1);
1633                 break;
1634
1635         case K_RIGHTARROW:
1636                 M_Menu_Options_Effects_AdjustSliders (1);
1637                 break;
1638         }
1639 }
1640
1641
1642
1643
1644
1645 #define OPTIONS_COLORCONTROL_ITEMS      18
1646
1647 int             options_colorcontrol_cursor;
1648
1649 // intensity value to match up to 50% dither to 'correct' quake
1650 cvar_t menu_options_colorcontrol_correctionvalue = {0, "menu_options_colorcontrol_correctionvalue", "0.25"};
1651
1652 void M_Menu_Options_ColorControl_f (void)
1653 {
1654         key_dest = key_menu;
1655         m_state = m_options_colorcontrol;
1656         m_entersound = true;
1657 }
1658
1659
1660 void M_Menu_Options_ColorControl_AdjustSliders (int dir)
1661 {
1662         float f;
1663         S_LocalSound ("misc/menu3.wav");
1664
1665         switch (options_colorcontrol_cursor)
1666         {
1667         case 1:
1668                 Cvar_SetValueQuick (&v_hwgamma, !v_hwgamma.integer);
1669                 break;
1670         case 2:
1671                 Cvar_SetValueQuick (&v_color_enable, 0);
1672                 Cvar_SetValueQuick (&v_gamma, bound(1, v_gamma.value + dir * 0.125, 5));
1673                 break;
1674         case 3:
1675                 Cvar_SetValueQuick (&v_color_enable, 0);
1676                 Cvar_SetValueQuick (&v_contrast, bound(1, v_contrast.value + dir * 0.125, 5));
1677                 break;
1678         case 4:
1679                 Cvar_SetValueQuick (&v_color_enable, 0);
1680                 Cvar_SetValueQuick (&v_brightness, bound(0, v_brightness.value + dir * 0.05, 0.8));
1681                 break;
1682         case 5:
1683                 Cvar_SetValueQuick (&v_color_enable, !v_color_enable.integer);
1684                 break;
1685         case 6:
1686                 Cvar_SetValueQuick (&v_color_enable, 1);
1687                 Cvar_SetValueQuick (&v_color_black_r, bound(0, v_color_black_r.value + dir * 0.0125, 0.8));
1688                 break;
1689         case 7:
1690                 Cvar_SetValueQuick (&v_color_enable, 1);
1691                 Cvar_SetValueQuick (&v_color_black_g, bound(0, v_color_black_g.value + dir * 0.0125, 0.8));
1692                 break;
1693         case 8:
1694                 Cvar_SetValueQuick (&v_color_enable, 1);
1695                 Cvar_SetValueQuick (&v_color_black_b, bound(0, v_color_black_b.value + dir * 0.0125, 0.8));
1696                 break;
1697         case 9:
1698                 Cvar_SetValueQuick (&v_color_enable, 1);
1699                 f = bound(0, (v_color_black_r.value + v_color_black_g.value + v_color_black_b.value) / 3 + dir * 0.0125, 0.8);
1700                 Cvar_SetValueQuick (&v_color_black_r, f);
1701                 Cvar_SetValueQuick (&v_color_black_g, f);
1702                 Cvar_SetValueQuick (&v_color_black_b, f);
1703                 break;
1704         case 10:
1705                 Cvar_SetValueQuick (&v_color_enable, 1);
1706                 Cvar_SetValueQuick (&v_color_grey_r, bound(0, v_color_grey_r.value + dir * 0.0125, 0.95));
1707                 break;
1708         case 11:
1709                 Cvar_SetValueQuick (&v_color_enable, 1);
1710                 Cvar_SetValueQuick (&v_color_grey_g, bound(0, v_color_grey_g.value + dir * 0.0125, 0.95));
1711                 break;
1712         case 12:
1713                 Cvar_SetValueQuick (&v_color_enable, 1);
1714                 Cvar_SetValueQuick (&v_color_grey_b, bound(0, v_color_grey_b.value + dir * 0.0125, 0.95));
1715                 break;
1716         case 13:
1717                 Cvar_SetValueQuick (&v_color_enable, 1);
1718                 f = bound(0, (v_color_grey_r.value + v_color_grey_g.value + v_color_grey_b.value) / 3 + dir * 0.0125, 0.95);
1719                 Cvar_SetValueQuick (&v_color_grey_r, f);
1720                 Cvar_SetValueQuick (&v_color_grey_g, f);
1721                 Cvar_SetValueQuick (&v_color_grey_b, f);
1722                 break;
1723         case 14:
1724                 Cvar_SetValueQuick (&v_color_enable, 1);
1725                 Cvar_SetValueQuick (&v_color_white_r, bound(1, v_color_white_r.value + dir * 0.125, 5));
1726                 break;
1727         case 15:
1728                 Cvar_SetValueQuick (&v_color_enable, 1);
1729                 Cvar_SetValueQuick (&v_color_white_g, bound(1, v_color_white_g.value + dir * 0.125, 5));
1730                 break;
1731         case 16:
1732                 Cvar_SetValueQuick (&v_color_enable, 1);
1733                 Cvar_SetValueQuick (&v_color_white_b, bound(1, v_color_white_b.value + dir * 0.125, 5));
1734                 break;
1735         case 17:
1736                 Cvar_SetValueQuick (&v_color_enable, 1);
1737                 f = bound(1, (v_color_white_r.value + v_color_white_g.value + v_color_white_b.value) / 3 + dir * 0.125, 5);
1738                 Cvar_SetValueQuick (&v_color_white_r, f);
1739                 Cvar_SetValueQuick (&v_color_white_g, f);
1740                 Cvar_SetValueQuick (&v_color_white_b, f);
1741                 break;
1742         }
1743 }
1744
1745 void M_Options_ColorControl_Draw (void)
1746 {
1747         float x, y, c, s, t, u, v;
1748         cachepic_t      *p;
1749
1750         M_DrawPic(16, 4, "gfx/qplaque.lmp");
1751         p = Draw_CachePic("gfx/p_option.lmp");
1752         M_DrawPic((320-p->width)/2, 4, "gfx/p_option.lmp");
1753
1754         y = 32;
1755         M_Print(16, y, "     Reset to defaults");y += 8;
1756         M_ItemPrint(16, y, "Hardware Gamma Control", vid_hardwaregammasupported);M_DrawCheckbox(220, y, v_hwgamma.integer);y += 8;
1757         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;
1758         M_ItemPrint(16, y, "              Contrast", !v_color_enable.integer);M_DrawSlider(220, y, v_contrast.value, 1, 5);y += 8;
1759         M_ItemPrint(16, y, "            Brightness", !v_color_enable.integer);M_DrawSlider(220, y, v_brightness.value, 0, 0.8);y += 8;
1760         M_Print(16, y, "  Color Level Controls");M_DrawCheckbox(220, y, v_color_enable.integer);y += 8;
1761         M_ItemPrint(16, y, "          Black: Red  ", v_color_enable.integer);M_DrawSlider(220, y, v_color_black_r.value, 0, 0.8);y += 8;
1762         M_ItemPrint(16, y, "          Black: Green", v_color_enable.integer);M_DrawSlider(220, y, v_color_black_g.value, 0, 0.8);y += 8;
1763         M_ItemPrint(16, y, "          Black: Blue ", v_color_enable.integer);M_DrawSlider(220, y, v_color_black_b.value, 0, 0.8);y += 8;
1764         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;
1765         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;
1766         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;
1767         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;
1768         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;
1769         M_ItemPrint(16, y, "          White: Red  ", v_color_enable.integer);M_DrawSlider(220, y, v_color_white_r.value, 1, 5);y += 8;
1770         M_ItemPrint(16, y, "          White: Green", v_color_enable.integer);M_DrawSlider(220, y, v_color_white_g.value, 1, 5);y += 8;
1771         M_ItemPrint(16, y, "          White: Blue ", v_color_enable.integer);M_DrawSlider(220, y, v_color_white_b.value, 1, 5);y += 8;
1772         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;
1773
1774         y += 4;
1775         DrawQ_Fill(menu_x, menu_y + y, 320, 4 + 64 + 8 + 64 + 4, 0, 0, 0, 1, 0);y += 4;
1776         s = (float) 312 / 2 * vid.realwidth / vid.conwidth;
1777         t = (float) 4 / 2 * vid.realheight / vid.conheight;
1778         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;
1779         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;
1780         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;
1781         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;
1782         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;
1783         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;
1784         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;
1785         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;
1786
1787         c = menu_options_colorcontrol_correctionvalue.value; // intensity value that should be matched up to a 50% dither to 'correct' quake
1788         s = (float) 48 / 2 * vid.realwidth / vid.conwidth;
1789         t = (float) 48 / 2 * vid.realheight / vid.conheight;
1790         u = s * 0.5;
1791         v = t * 0.5;
1792         y += 8;
1793         x = 4;
1794         DrawQ_Fill(menu_x + x, menu_y + y, 64, 48, c, 0, 0, 1, 0);
1795         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);
1796         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);
1797         x += 80;
1798         DrawQ_Fill(menu_x + x, menu_y + y, 64, 48, 0, c, 0, 1, 0);
1799         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);
1800         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);
1801         x += 80;
1802         DrawQ_Fill(menu_x + x, menu_y + y, 64, 48, 0, 0, c, 1, 0);
1803         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);
1804         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);
1805         x += 80;
1806         DrawQ_Fill(menu_x + x, menu_y + y, 64, 48, c, c, c, 1, 0);
1807         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);
1808         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);
1809
1810         // cursor
1811         M_DrawCharacter(200, 32 + options_colorcontrol_cursor*8, 12+((int)(realtime*4)&1));
1812 }
1813
1814
1815 void M_Options_ColorControl_Key (int k)
1816 {
1817         switch (k)
1818         {
1819         case K_ESCAPE:
1820                 M_Menu_Main_f ();
1821                 break;
1822
1823         case K_ENTER:
1824                 m_entersound = true;
1825                 switch (options_colorcontrol_cursor)
1826                 {
1827                 case 0:
1828                         Cvar_SetValueQuick(&v_hwgamma, 1);
1829                         Cvar_SetValueQuick(&v_gamma, 1);
1830                         Cvar_SetValueQuick(&v_contrast, 1);
1831                         Cvar_SetValueQuick(&v_brightness, 0);
1832                         Cvar_SetValueQuick(&v_color_enable, 0);
1833                         Cvar_SetValueQuick(&v_color_black_r, 0);
1834                         Cvar_SetValueQuick(&v_color_black_g, 0);
1835                         Cvar_SetValueQuick(&v_color_black_b, 0);
1836                         Cvar_SetValueQuick(&v_color_grey_r, 0);
1837                         Cvar_SetValueQuick(&v_color_grey_g, 0);
1838                         Cvar_SetValueQuick(&v_color_grey_b, 0);
1839                         Cvar_SetValueQuick(&v_color_white_r, 1);
1840                         Cvar_SetValueQuick(&v_color_white_g, 1);
1841                         Cvar_SetValueQuick(&v_color_white_b, 1);
1842                         Cbuf_AddText ("exec default.cfg\n");
1843                         break;
1844                 default:
1845                         M_Menu_Options_ColorControl_AdjustSliders (1);
1846                         break;
1847                 }
1848                 return;
1849
1850         case K_UPARROW:
1851                 S_LocalSound ("misc/menu1.wav");
1852                 options_colorcontrol_cursor--;
1853                 if (options_colorcontrol_cursor < 0)
1854                         options_colorcontrol_cursor = OPTIONS_COLORCONTROL_ITEMS-1;
1855                 break;
1856
1857         case K_DOWNARROW:
1858                 S_LocalSound ("misc/menu1.wav");
1859                 options_colorcontrol_cursor++;
1860                 if (options_colorcontrol_cursor >= OPTIONS_COLORCONTROL_ITEMS)
1861                         options_colorcontrol_cursor = 0;
1862                 break;
1863
1864         case K_LEFTARROW:
1865                 M_Menu_Options_ColorControl_AdjustSliders (-1);
1866                 break;
1867
1868         case K_RIGHTARROW:
1869                 M_Menu_Options_ColorControl_AdjustSliders (1);
1870                 break;
1871         }
1872 }
1873
1874
1875 //=============================================================================
1876 /* KEYS MENU */
1877
1878 char *quakebindnames[][2] =
1879 {
1880 {"+attack",             "attack"},
1881 {"impulse 10",          "next weapon"},
1882 {"impulse 12",          "previous weapon"},
1883 {"+jump",                       "jump / swim up"},
1884 {"+forward",            "walk forward"},
1885 {"+back",                       "backpedal"},
1886 {"+left",                       "turn left"},
1887 {"+right",                      "turn right"},
1888 {"+speed",                      "run"},
1889 {"+moveleft",           "step left"},
1890 {"+moveright",          "step right"},
1891 {"+strafe",             "sidestep"},
1892 {"+lookup",             "look up"},
1893 {"+lookdown",           "look down"},
1894 {"centerview",          "center view"},
1895 {"+mlook",                      "mouse look"},
1896 {"+klook",                      "keyboard look"},
1897 {"+moveup",                     "swim up"},
1898 {"+movedown",           "swim down"}
1899 };
1900
1901 char *transfusionbindnames[][2] =
1902 {
1903 {"+forward",            "walk forward"},
1904 {"+back",                       "backpedal"},
1905 {"+left",                       "turn left"},
1906 {"+right",                      "turn right"},
1907 {"+moveleft",           "step left"},
1908 {"+moveright",          "step right"},
1909 {"+jump",                       "jump / swim up"},
1910 {"+movedown",           "swim down"},
1911 {"+attack",             "attack"},
1912 {"+button3",            "altfire"},
1913 {"impulse 1",           "Pitch Fork"},
1914 {"impulse 2",           "Flare Gun"},
1915 {"impulse 3",           "Shotgun"},
1916 {"impulse 4",           "Machine Gun"},
1917 {"impulse 5",           "Incinerator"},
1918 {"impulse 6",           "Bombs"},
1919 {"impulse 7",           "Aerosol Can"},
1920 {"impulse 8",           "Tesla Cannon"},
1921 {"impulse 9",           "Life Leech"},
1922 {"impulse 17",          "Voodoo Doll"},
1923 {"impulse 11",          "previous weapon"},
1924 {"impulse 10",          "next weapon"},
1925 {"impulse 14",          "previous item"},
1926 {"impulse 15",          "next item"},
1927 {"impulse 13",          "use item"},
1928 {"impulse 100",         "add bot (red)"},
1929 {"impulse 101",         "add bot (blue)"},
1930 {"impulse 102",         "kick a bot"},
1931 {"impulse 50",          "voting menu"},
1932 {"impulse 141",         "identify player"},
1933 {"impulse 16",          "next armor type"},
1934 {"impulse 20",          "observer mode"}
1935 };
1936
1937 int numcommands;
1938 char *(*bindnames)[2];
1939
1940 /*
1941 typedef struct binditem_s
1942 {
1943         char *command, *description;
1944         struct binditem_s *next;
1945 }
1946 binditem_t;
1947
1948 typedef struct bindcategory_s
1949 {
1950         char *name;
1951         binditem_t *binds;
1952         struct bindcategory_s *next;
1953 }
1954 bindcategory_t;
1955
1956 bindcategory_t *bindcategories = NULL;
1957
1958 void M_ClearBinds (void)
1959 {
1960         for (c = bindcategories;c;c = cnext)
1961         {
1962                 cnext = c->next;
1963                 for (b = c->binds;b;b = bnext)
1964                 {
1965                         bnext = b->next;
1966                         Z_Free(b);
1967                 }
1968                 Z_Free(c);
1969         }
1970         bindcategories = NULL;
1971 }
1972
1973 void M_AddBindToCategory(bindcategory_t *c, char *command, char *description)
1974 {
1975         for (b = &c->binds;*b;*b = &(*b)->next);
1976         *b = Z_Alloc(sizeof(binditem_t) + strlen(command) + 1 + strlen(description) + 1);
1977         *b->command = (char *)((*b) + 1);
1978         *b->description = *b->command + strlen(command) + 1;
1979         strcpy(*b->command, command);
1980         strcpy(*b->description, description);
1981 }
1982
1983 void M_AddBind (char *category, char *command, char *description)
1984 {
1985         for (c = &bindcategories;*c;c = &(*c)->next)
1986         {
1987                 if (!strcmp(category, (*c)->name))
1988                 {
1989                         M_AddBindToCategory(*c, command, description);
1990                         return;
1991                 }
1992         }
1993         *c = Z_Alloc(sizeof(bindcategory_t));
1994         M_AddBindToCategory(*c, command, description);
1995 }
1996
1997 void M_DefaultBinds (void)
1998 {
1999         M_ClearBinds();
2000         M_AddBind("movement", "+jump", "jump / swim up");
2001         M_AddBind("movement", "+forward", "walk forward");
2002         M_AddBind("movement", "+back", "backpedal");
2003         M_AddBind("movement", "+left", "turn left");
2004         M_AddBind("movement", "+right", "turn right");
2005         M_AddBind("movement", "+speed", "run");
2006         M_AddBind("movement", "+moveleft", "step left");
2007         M_AddBind("movement", "+moveright", "step right");
2008         M_AddBind("movement", "+strafe", "sidestep");
2009         M_AddBind("movement", "+lookup", "look up");
2010         M_AddBind("movement", "+lookdown", "look down");
2011         M_AddBind("movement", "centerview", "center view");
2012         M_AddBind("movement", "+mlook", "mouse look");
2013         M_AddBind("movement", "+klook", "keyboard look");
2014         M_AddBind("movement", "+moveup", "swim up");
2015         M_AddBind("movement", "+movedown", "swim down");
2016         M_AddBind("weapons", "+attack", "attack");
2017         M_AddBind("weapons", "impulse 10", "next weapon");
2018         M_AddBind("weapons", "impulse 12", "previous weapon");
2019         M_AddBind("weapons", "impulse 1", "select weapon 1 (axe)");
2020         M_AddBind("weapons", "impulse 2", "select weapon 2 (shotgun)");
2021         M_AddBind("weapons", "impulse 3", "select weapon 3 (super )");
2022         M_AddBind("weapons", "impulse 4", "select weapon 4 (nailgun)");
2023         M_AddBind("weapons", "impulse 5", "select weapon 5 (super nailgun)");
2024         M_AddBind("weapons", "impulse 6", "select weapon 6 (grenade launcher)");
2025         M_AddBind("weapons", "impulse 7", "select weapon 7 (rocket launcher)");
2026         M_AddBind("weapons", "impulse 8", "select weapon 8 (lightning gun)");
2027 }
2028 */
2029
2030
2031 int             keys_cursor;
2032 int             bind_grab;
2033
2034 void M_Menu_Keys_f (void)
2035 {
2036         key_dest = key_menu;
2037         m_state = m_keys;
2038         m_entersound = true;
2039 }
2040
2041 #define NUMKEYS 5
2042
2043 void M_FindKeysForCommand (char *command, int *keys)
2044 {
2045         int             count;
2046         int             j;
2047         char    *b;
2048
2049         for (j = 0;j < NUMKEYS;j++)
2050                 keys[j] = -1;
2051
2052         count = 0;
2053
2054         for (j=0 ; j<256 ; j++)
2055         {
2056                 b = keybindings[j];
2057                 if (!b)
2058                         continue;
2059                 if (!strcmp (b, command) )
2060                 {
2061                         keys[count++] = j;
2062                         if (count == NUMKEYS)
2063                                 break;
2064                 }
2065         }
2066 }
2067
2068 void M_UnbindCommand (char *command)
2069 {
2070         int             j;
2071         char    *b;
2072
2073         for (j=0 ; j<256 ; j++)
2074         {
2075                 b = keybindings[j];
2076                 if (!b)
2077                         continue;
2078                 if (!strcmp (b, command))
2079                         Key_SetBinding (j, "");
2080         }
2081 }
2082
2083
2084 void M_Keys_Draw (void)
2085 {
2086         int             i, j;
2087         int             keys[NUMKEYS];
2088         int             y;
2089         cachepic_t      *p;
2090         char    keystring[1024];
2091
2092         p = Draw_CachePic ("gfx/ttl_cstm.lmp");
2093         M_DrawPic ( (320-p->width)/2, 4, "gfx/ttl_cstm.lmp");
2094
2095         if (bind_grab)
2096                 M_Print (12, 32, "Press a key or button for this action");
2097         else
2098                 M_Print (18, 32, "Enter to change, backspace to clear");
2099
2100 // search for known bindings
2101         for (i=0 ; i<numcommands ; i++)
2102         {
2103                 y = 48 + 8*i;
2104
2105                 M_Print (16, y, bindnames[i][1]);
2106
2107                 M_FindKeysForCommand (bindnames[i][0], keys);
2108
2109                 // LordHavoc: redesigned to print more than 2 keys, inspired by Tomaz's MiniRacer
2110                 if (keys[0] == -1)
2111                         strcpy(keystring, "???");
2112                 else
2113                 {
2114                         keystring[0] = 0;
2115                         for (j = 0;j < NUMKEYS;j++)
2116                         {
2117                                 if (keys[j] != -1)
2118                                 {
2119                                         if (j > 0)
2120                                                 strcat(keystring, " or ");
2121                                         strcat(keystring, Key_KeynumToString (keys[j]));
2122                                 }
2123                         }
2124                 }
2125                 M_Print (150, y, keystring);
2126         }
2127
2128         if (bind_grab)
2129                 M_DrawCharacter (140, 48 + keys_cursor*8, '=');
2130         else
2131                 M_DrawCharacter (140, 48 + keys_cursor*8, 12+((int)(realtime*4)&1));
2132 }
2133
2134
2135 void M_Keys_Key (int k)
2136 {
2137         char    cmd[80];
2138         int             keys[NUMKEYS];
2139
2140         if (bind_grab)
2141         {       // defining a key
2142                 S_LocalSound ("misc/menu1.wav");
2143                 if (k == K_ESCAPE)
2144                 {
2145                         bind_grab = false;
2146                 }
2147                 else //if (k != '`')
2148                 {
2149                         sprintf (cmd, "bind \"%s\" \"%s\"\n", Key_KeynumToString (k), bindnames[keys_cursor][0]);
2150                         Cbuf_InsertText (cmd);
2151                 }
2152
2153                 bind_grab = false;
2154                 return;
2155         }
2156
2157         switch (k)
2158         {
2159         case K_ESCAPE:
2160                 M_Menu_Options_f ();
2161                 break;
2162
2163         case K_LEFTARROW:
2164         case K_UPARROW:
2165                 S_LocalSound ("misc/menu1.wav");
2166                 keys_cursor--;
2167                 if (keys_cursor < 0)
2168                         keys_cursor = numcommands-1;
2169                 break;
2170
2171         case K_DOWNARROW:
2172         case K_RIGHTARROW:
2173                 S_LocalSound ("misc/menu1.wav");
2174                 keys_cursor++;
2175                 if (keys_cursor >= numcommands)
2176                         keys_cursor = 0;
2177                 break;
2178
2179         case K_ENTER:           // go into bind mode
2180                 M_FindKeysForCommand (bindnames[keys_cursor][0], keys);
2181                 S_LocalSound ("misc/menu2.wav");
2182                 if (keys[NUMKEYS - 1] != -1)
2183                         M_UnbindCommand (bindnames[keys_cursor][0]);
2184                 bind_grab = true;
2185                 break;
2186
2187         case K_BACKSPACE:               // delete bindings
2188         case K_DEL:                             // delete bindings
2189                 S_LocalSound ("misc/menu2.wav");
2190                 M_UnbindCommand (bindnames[keys_cursor][0]);
2191                 break;
2192         }
2193 }
2194
2195 //=============================================================================
2196 /* VIDEO MENU */
2197
2198 #define VIDEO_ITEMS 5
2199
2200 int video_cursor = 0;
2201 int video_cursor_table[] = {56, 68, 80, 92, 116};
2202 // note: if modes are added to the beginning of this list, update the
2203 // video_resolution = x; in M_Menu_Video_f below
2204 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}};
2205 int video_resolution;
2206
2207 extern int current_vid_fullscreen;
2208 extern int current_vid_width;
2209 extern int current_vid_height;
2210 extern int current_vid_bitsperpixel;
2211 extern int current_vid_stencil;
2212
2213
2214 void M_Menu_Video_f (void)
2215 {
2216         key_dest = key_menu;
2217         m_state = m_video;
2218         m_entersound = true;
2219
2220         // Look for the current resolution
2221         for (video_resolution = 0; video_resolution < (int) (sizeof (video_resolutions) / sizeof (video_resolutions[0])); video_resolution++)
2222         {
2223                 if (video_resolutions[video_resolution][0] == current_vid_width &&
2224                         video_resolutions[video_resolution][1] == current_vid_height)
2225                         break;
2226         }
2227
2228         // Default to 800x600 if we didn't find it
2229         if (video_resolution == sizeof (video_resolutions) / sizeof (video_resolutions[0]))
2230         {
2231                 // may need to update this number if mode list changes
2232                 video_resolution = 4;
2233                 Cvar_SetValueQuick (&vid_width, video_resolutions[video_resolution][0]);
2234                 Cvar_SetValueQuick (&vid_height, video_resolutions[video_resolution][1]);
2235         }
2236 }
2237
2238
2239 void M_Video_Draw (void)
2240 {
2241         cachepic_t      *p;
2242         const char* string;
2243
2244         M_DrawPic(16, 4, "gfx/qplaque.lmp");
2245         p = Draw_CachePic("gfx/vidmodes.lmp");
2246         M_DrawPic((320-p->width)/2, 4, "gfx/vidmodes.lmp");
2247
2248         // Resolution
2249         M_Print(16, video_cursor_table[0], "            Resolution");
2250         string = va("%dx%d", video_resolutions[video_resolution][0], video_resolutions[video_resolution][1]);
2251         M_Print (220, video_cursor_table[0], string);
2252
2253         // Bits per pixel
2254         M_Print(16, video_cursor_table[1], "        Bits per pixel");
2255         M_Print (220, video_cursor_table[1], (vid_bitsperpixel.integer == 32) ? "32" : "16");
2256
2257         // Fullscreen
2258         M_Print(16, video_cursor_table[2], "            Fullscreen");
2259         M_DrawCheckbox(220, video_cursor_table[2], vid_fullscreen.integer);
2260
2261         // Stencil
2262         M_Print(16, video_cursor_table[3], "               Stencil");
2263         M_DrawCheckbox(220, video_cursor_table[3], vid_stencil.integer);
2264
2265         // "Apply" button
2266         M_Print(220, video_cursor_table[4], "Apply");
2267
2268         // Cursor
2269         M_DrawCharacter(200, video_cursor_table[video_cursor], 12+((int)(realtime*4)&1));
2270 }
2271
2272
2273 void M_Menu_Video_AdjustSliders (int dir)
2274 {
2275         S_LocalSound ("misc/menu3.wav");
2276
2277         switch (video_cursor)
2278         {
2279                 // Resolution
2280                 case 0:
2281                 {
2282                         int new_resolution = video_resolution + dir;
2283                         if (new_resolution < 0)
2284                                 video_resolution = sizeof (video_resolutions) / sizeof (video_resolutions[0]) - 1;
2285                         else if (new_resolution > (int) (sizeof (video_resolutions) / sizeof (video_resolutions[0]) - 1))
2286                                 video_resolution = 0;
2287                         else
2288                                 video_resolution = new_resolution;
2289
2290                         Cvar_SetValueQuick (&vid_width, video_resolutions[video_resolution][0]);
2291                         Cvar_SetValueQuick (&vid_height, video_resolutions[video_resolution][1]);
2292                         break;
2293                 }
2294
2295                 // Bits per pixel
2296                 case 1:
2297                         Cvar_SetValueQuick (&vid_bitsperpixel, (vid_bitsperpixel.integer == 32) ? 16 : 32);
2298                         break;
2299                 case 2:
2300                         Cvar_SetValueQuick (&vid_fullscreen, !vid_fullscreen.integer);
2301                         break;
2302                 case 3:
2303                         Cvar_SetValueQuick (&vid_stencil, !vid_stencil.integer);
2304                         break;
2305         }
2306 }
2307
2308
2309 void M_Video_Key (int key)
2310 {
2311         switch (key)
2312         {
2313                 case K_ESCAPE:
2314                         // vid_shared.c has a copy of the current video config. We restore it
2315                         Cvar_SetValueQuick(&vid_fullscreen, current_vid_fullscreen);
2316                         Cvar_SetValueQuick(&vid_width, current_vid_width);
2317                         Cvar_SetValueQuick(&vid_height, current_vid_height);
2318                         Cvar_SetValueQuick(&vid_bitsperpixel, current_vid_bitsperpixel);
2319                         Cvar_SetValueQuick(&vid_stencil, current_vid_stencil);
2320
2321                         S_LocalSound ("misc/menu1.wav");
2322                         M_Menu_Options_f ();
2323                         break;
2324
2325                 case K_ENTER:
2326                         m_entersound = true;
2327                         switch (video_cursor)
2328                         {
2329                                 case 4:
2330                                         Cbuf_AddText ("vid_restart\n");
2331                                         M_Menu_Options_f ();
2332                                         break;
2333                                 default:
2334                                         M_Menu_Video_AdjustSliders (1);
2335                         }
2336                         break;
2337
2338                 case K_UPARROW:
2339                         S_LocalSound ("misc/menu1.wav");
2340                         video_cursor--;
2341                         if (video_cursor < 0)
2342                                 video_cursor = VIDEO_ITEMS-1;
2343                         break;
2344
2345                 case K_DOWNARROW:
2346                         S_LocalSound ("misc/menu1.wav");
2347                         video_cursor++;
2348                         if (video_cursor >= VIDEO_ITEMS)
2349                                 video_cursor = 0;
2350                         break;
2351
2352                 case K_LEFTARROW:
2353                         M_Menu_Video_AdjustSliders (-1);
2354                         break;
2355
2356                 case K_RIGHTARROW:
2357                         M_Menu_Video_AdjustSliders (1);
2358                         break;
2359         }
2360 }
2361
2362 //=============================================================================
2363 /* HELP MENU */
2364
2365 int             help_page;
2366 #define NUM_HELP_PAGES  6
2367
2368
2369 void M_Menu_Help_f (void)
2370 {
2371         key_dest = key_menu;
2372         m_state = m_help;
2373         m_entersound = true;
2374         help_page = 0;
2375 }
2376
2377
2378
2379 void M_Help_Draw (void)
2380 {
2381         M_DrawPic (0, 0, va("gfx/help%i.lmp", help_page));
2382 }
2383
2384
2385 void M_Help_Key (int key)
2386 {
2387         switch (key)
2388         {
2389         case K_ESCAPE:
2390                 M_Menu_Main_f ();
2391                 break;
2392
2393         case K_UPARROW:
2394         case K_RIGHTARROW:
2395                 m_entersound = true;
2396                 if (++help_page >= NUM_HELP_PAGES)
2397                         help_page = 0;
2398                 break;
2399
2400         case K_DOWNARROW:
2401         case K_LEFTARROW:
2402                 m_entersound = true;
2403                 if (--help_page < 0)
2404                         help_page = NUM_HELP_PAGES-1;
2405                 break;
2406         }
2407
2408 }
2409
2410 //=============================================================================
2411 /* QUIT MENU */
2412
2413 int             msgNumber;
2414 int             m_quit_prevstate;
2415 qboolean        wasInMenus;
2416
2417 char *quitMessage [] =
2418 {
2419 /* .........1.........2.... */
2420 /*
2421   "  Are you gonna quit    ",
2422   "  this game just like   ",
2423   "   everything else?     ",
2424   "                        ",
2425
2426   " Milord, methinks that  ",
2427   "   thou art a lowly     ",
2428   " quitter. Is this true? ",
2429   "                        ",
2430
2431   " Do I need to bust your ",
2432   "  face open for trying  ",
2433   "        to quit?        ",
2434   "                        ",
2435
2436   " Man, I oughta smack you",
2437   "   for trying to quit!  ",
2438   "     Press Y to get     ",
2439   "      smacked out.      ",
2440
2441   " Press Y to quit like a ",
2442   "   big loser in life.   ",
2443   "  Press N to stay proud ",
2444   "    and successful!     ",
2445
2446   "   If you press Y to    ",
2447   "  quit, I will summon   ",
2448   "  Satan all over your   ",
2449   "      hard drive!       ",
2450
2451   "  Um, Asmodeus dislikes ",
2452   " his children trying to ",
2453   " quit. Press Y to return",
2454   "   to your Tinkertoys.  ",
2455
2456   "  If you quit now, I'll ",
2457   "  throw a blanket-party ",
2458   "   for you next time!   ",
2459   "                        "
2460   */
2461
2462 /* .........1.........2.... */
2463   "                        ",
2464   "    Tired of fragging   ",
2465   "        already?        ",
2466   "                        ",
2467
2468   "                        ",
2469   "  Quit now and forfeit  ",
2470   "     your bodycount?    ",
2471   "                        ",
2472
2473   "                        ",
2474   "    Are you sure you    ",
2475   "      want to quit?     ",
2476   "                        ",
2477
2478   "                        ",
2479   "   Off to do something  ",
2480   "      constructive?     ",
2481   "                        ",
2482 };
2483
2484 void M_Menu_Quit_f (void)
2485 {
2486         if (m_state == m_quit)
2487                 return;
2488         wasInMenus = (key_dest == key_menu);
2489         key_dest = key_menu;
2490         m_quit_prevstate = m_state;
2491         m_state = m_quit;
2492         m_entersound = true;
2493         msgNumber = rand()&3; //&7;
2494 }
2495
2496
2497 void M_Quit_Key (int key)
2498 {
2499         switch (key)
2500         {
2501         case K_ESCAPE:
2502         case 'n':
2503         case 'N':
2504                 if (wasInMenus)
2505                 {
2506                         m_state = m_quit_prevstate;
2507                         m_entersound = true;
2508                 }
2509                 else
2510                 {
2511                         key_dest = key_game;
2512                         m_state = m_none;
2513                 }
2514                 break;
2515
2516         case 'Y':
2517         case 'y':
2518                 Host_Quit_f ();
2519                 break;
2520
2521         default:
2522                 break;
2523         }
2524
2525 }
2526
2527
2528 void M_Quit_Draw (void)
2529 {
2530         M_DrawTextBox (56, 76, 24, 4);
2531         M_Print (64, 84,  quitMessage[msgNumber*4+0]);
2532         M_Print (64, 92,  quitMessage[msgNumber*4+1]);
2533         M_Print (64, 100, quitMessage[msgNumber*4+2]);
2534         M_Print (64, 108, quitMessage[msgNumber*4+3]);
2535 }
2536
2537 //=============================================================================
2538 /* LAN CONFIG MENU */
2539
2540 int             lanConfig_cursor = -1;
2541 int             lanConfig_cursor_table [] = {72, 92, 112, 144};
2542 #define NUM_LANCONFIG_CMDS      4
2543
2544 int     lanConfig_port;
2545 char    lanConfig_portname[6];
2546 char    lanConfig_joinname[22];
2547
2548 void M_Menu_LanConfig_f (void)
2549 {
2550         key_dest = key_menu;
2551         m_state = m_lanconfig;
2552         m_entersound = true;
2553         if (lanConfig_cursor == -1)
2554         {
2555                 if (JoiningGame && TCPIPConfig)
2556                         lanConfig_cursor = 2;
2557                 else
2558                         lanConfig_cursor = 1;
2559         }
2560         if (StartingGame && lanConfig_cursor == 2)
2561                 lanConfig_cursor = 1;
2562         lanConfig_port = DEFAULTnet_hostport;
2563         sprintf(lanConfig_portname, "%u", lanConfig_port);
2564
2565         m_return_onerror = false;
2566         m_return_reason[0] = 0;
2567 }
2568
2569
2570 void M_LanConfig_Draw (void)
2571 {
2572         cachepic_t      *p;
2573         int             basex;
2574         char    *startJoin;
2575         char    *protocol;
2576
2577         M_DrawPic (16, 4, "gfx/qplaque.lmp");
2578         p = Draw_CachePic ("gfx/p_multi.lmp");
2579         basex = (320-p->width)/2;
2580         M_DrawPic (basex, 4, "gfx/p_multi.lmp");
2581
2582         if (StartingGame)
2583                 startJoin = "New Game";
2584         else
2585                 startJoin = "Join Game";
2586         if (IPXConfig)
2587                 protocol = "IPX";
2588         else
2589                 protocol = "TCP/IP";
2590         M_Print (basex, 32, va ("%s - %s", startJoin, protocol));
2591         basex += 8;
2592
2593         M_Print (basex, 52, "Address:");
2594         if (IPXConfig)
2595                 M_Print (basex+9*8, 52, my_ipx_address);
2596         else
2597                 M_Print (basex+9*8, 52, my_tcpip_address);
2598
2599         M_Print (basex, lanConfig_cursor_table[0], "Port");
2600         M_DrawTextBox (basex+8*8, lanConfig_cursor_table[0]-8, 6, 1);
2601         M_Print (basex+9*8, lanConfig_cursor_table[0], lanConfig_portname);
2602
2603         if (JoiningGame)
2604         {
2605                 M_Print (basex, lanConfig_cursor_table[1], "Search for local games...");
2606                 M_Print (basex, lanConfig_cursor_table[2], "Search for internet games...");
2607                 M_Print (basex, 128, "Join game at:");
2608                 M_DrawTextBox (basex+8, lanConfig_cursor_table[3]-8, 22, 1);
2609                 M_Print (basex+16, lanConfig_cursor_table[3], lanConfig_joinname);
2610         }
2611         else
2612         {
2613                 M_DrawTextBox (basex, lanConfig_cursor_table[1]-8, 2, 1);
2614                 M_Print (basex+8, lanConfig_cursor_table[1], "OK");
2615         }
2616
2617         M_DrawCharacter (basex-8, lanConfig_cursor_table [lanConfig_cursor], 12+((int)(realtime*4)&1));
2618
2619         if (lanConfig_cursor == 0)
2620                 M_DrawCharacter (basex+9*8 + 8*strlen(lanConfig_portname), lanConfig_cursor_table [0], 10+((int)(realtime*4)&1));
2621
2622         if (lanConfig_cursor == 3)
2623                 M_DrawCharacter (basex+16 + 8*strlen(lanConfig_joinname), lanConfig_cursor_table [3], 10+((int)(realtime*4)&1));
2624
2625         if (*m_return_reason)
2626                 M_PrintWhite (basex, 168, m_return_reason);
2627 }
2628
2629
2630 void M_LanConfig_Key (int key)
2631 {
2632         int             l;
2633
2634         switch (key)
2635         {
2636         case K_ESCAPE:
2637                 M_Menu_Net_f ();
2638                 break;
2639
2640         case K_UPARROW:
2641                 S_LocalSound ("misc/menu1.wav");
2642                 lanConfig_cursor--;
2643                 if (lanConfig_cursor < 0)
2644                         lanConfig_cursor = NUM_LANCONFIG_CMDS-1;
2645                 break;
2646
2647         case K_DOWNARROW:
2648                 S_LocalSound ("misc/menu1.wav");
2649                 lanConfig_cursor++;
2650                 if (lanConfig_cursor >= NUM_LANCONFIG_CMDS)
2651                         lanConfig_cursor = 0;
2652                 break;
2653
2654         case K_ENTER:
2655                 if (lanConfig_cursor == 0)
2656                         break;
2657
2658                 m_entersound = true;
2659
2660                 M_ConfigureNetSubsystem ();
2661
2662                 if (lanConfig_cursor == 1 || lanConfig_cursor == 2)
2663                 {
2664                         if (StartingGame)
2665                         {
2666                                 M_Menu_GameOptions_f ();
2667                                 break;
2668                         }
2669                         if (lanConfig_cursor == 1)
2670                                 M_Menu_Search_f();
2671                         else
2672                                 M_Menu_InetSearch_f();
2673                         break;
2674                 }
2675
2676                 if (lanConfig_cursor == 3)
2677                 {
2678                         m_return_state = m_state;
2679                         m_return_onerror = true;
2680                         key_dest = key_game;
2681                         m_state = m_none;
2682                         Cbuf_AddText ( va ("connect \"%s\"\n", lanConfig_joinname) );
2683                         break;
2684                 }
2685
2686                 break;
2687
2688         case K_BACKSPACE:
2689                 if (lanConfig_cursor == 0)
2690                 {
2691                         if (strlen(lanConfig_portname))
2692                                 lanConfig_portname[strlen(lanConfig_portname)-1] = 0;
2693                 }
2694
2695                 if (lanConfig_cursor == 3)
2696                 {
2697                         if (strlen(lanConfig_joinname))
2698                                 lanConfig_joinname[strlen(lanConfig_joinname)-1] = 0;
2699                 }
2700                 break;
2701
2702         default:
2703                 if (key < 32 || key > 127)
2704                         break;
2705
2706                 if (lanConfig_cursor == 3)
2707                 {
2708                         l = strlen(lanConfig_joinname);
2709                         if (l < 21)
2710                         {
2711                                 lanConfig_joinname[l+1] = 0;
2712                                 lanConfig_joinname[l] = key;
2713                         }
2714                 }
2715
2716                 if (key < '0' || key > '9')
2717                         break;
2718                 if (lanConfig_cursor == 0)
2719                 {
2720                         l = strlen(lanConfig_portname);
2721                         if (l < 5)
2722                         {
2723                                 lanConfig_portname[l+1] = 0;
2724                                 lanConfig_portname[l] = key;
2725                         }
2726                 }
2727         }
2728
2729         if (StartingGame && lanConfig_cursor == 3)
2730         {
2731                 if (key == K_UPARROW)
2732                         lanConfig_cursor = 1;
2733                 else
2734                         lanConfig_cursor = 0;
2735         }
2736
2737         l =  atoi(lanConfig_portname);
2738         if (l > 65535)
2739                 l = lanConfig_port;
2740         else
2741                 lanConfig_port = l;
2742         sprintf(lanConfig_portname, "%u", lanConfig_port);
2743 }
2744
2745 //=============================================================================
2746 /* GAME OPTIONS MENU */
2747
2748 typedef struct
2749 {
2750         char    *name;
2751         char    *description;
2752 } level_t;
2753
2754 typedef struct
2755 {
2756         char    *description;
2757         int             firstLevel;
2758         int             levels;
2759 } episode_t;
2760
2761 typedef struct
2762 {
2763         char *gamename;
2764         level_t *levels;
2765         episode_t *episodes;
2766         int numepisodes;
2767 }
2768 gamelevels_t;
2769
2770 level_t quakelevels[] =
2771 {
2772         {"start", "Entrance"},  // 0
2773
2774         {"e1m1", "Slipgate Complex"},                           // 1
2775         {"e1m2", "Castle of the Damned"},
2776         {"e1m3", "The Necropolis"},
2777         {"e1m4", "The Grisly Grotto"},
2778         {"e1m5", "Gloom Keep"},
2779         {"e1m6", "The Door To Chthon"},
2780         {"e1m7", "The House of Chthon"},
2781         {"e1m8", "Ziggurat Vertigo"},
2782
2783         {"e2m1", "The Installation"},                           // 9
2784         {"e2m2", "Ogre Citadel"},
2785         {"e2m3", "Crypt of Decay"},
2786         {"e2m4", "The Ebon Fortress"},
2787         {"e2m5", "The Wizard's Manse"},
2788         {"e2m6", "The Dismal Oubliette"},
2789         {"e2m7", "Underearth"},
2790
2791         {"e3m1", "Termination Central"},                        // 16
2792         {"e3m2", "The Vaults of Zin"},
2793         {"e3m3", "The Tomb of Terror"},
2794         {"e3m4", "Satan's Dark Delight"},
2795         {"e3m5", "Wind Tunnels"},
2796         {"e3m6", "Chambers of Torment"},
2797         {"e3m7", "The Haunted Halls"},
2798
2799         {"e4m1", "The Sewage System"},                          // 23
2800         {"e4m2", "The Tower of Despair"},
2801         {"e4m3", "The Elder God Shrine"},
2802         {"e4m4", "The Palace of Hate"},
2803         {"e4m5", "Hell's Atrium"},
2804         {"e4m6", "The Pain Maze"},
2805         {"e4m7", "Azure Agony"},
2806         {"e4m8", "The Nameless City"},
2807
2808         {"end", "Shub-Niggurath's Pit"},                        // 31
2809
2810         {"dm1", "Place of Two Deaths"},                         // 32
2811         {"dm2", "Claustrophobopolis"},
2812         {"dm3", "The Abandoned Base"},
2813         {"dm4", "The Bad Place"},
2814         {"dm5", "The Cistern"},
2815         {"dm6", "The Dark Zone"}
2816 };
2817
2818 episode_t quakeepisodes[] =
2819 {
2820         {"Welcome to Quake", 0, 1},
2821         {"Doomed Dimension", 1, 8},
2822         {"Realm of Black Magic", 9, 7},
2823         {"Netherworld", 16, 7},
2824         {"The Elder World", 23, 8},
2825         {"Final Level", 31, 1},
2826         {"Deathmatch Arena", 32, 6}
2827 };
2828
2829 //MED 01/06/97 added hipnotic levels
2830 level_t     hipnoticlevels[] =
2831 {
2832    {"start", "Command HQ"},  // 0
2833
2834    {"hip1m1", "The Pumping Station"},          // 1
2835    {"hip1m2", "Storage Facility"},
2836    {"hip1m3", "The Lost Mine"},
2837    {"hip1m4", "Research Facility"},
2838    {"hip1m5", "Military Complex"},
2839
2840    {"hip2m1", "Ancient Realms"},          // 6
2841    {"hip2m2", "The Black Cathedral"},
2842    {"hip2m3", "The Catacombs"},
2843    {"hip2m4", "The Crypt"},
2844    {"hip2m5", "Mortum's Keep"},
2845    {"hip2m6", "The Gremlin's Domain"},
2846
2847    {"hip3m1", "Tur Torment"},       // 12
2848    {"hip3m2", "Pandemonium"},
2849    {"hip3m3", "Limbo"},
2850    {"hip3m4", "The Gauntlet"},
2851
2852    {"hipend", "Armagon's Lair"},       // 16
2853
2854    {"hipdm1", "The Edge of Oblivion"}           // 17
2855 };
2856
2857 //MED 01/06/97  added hipnotic episodes
2858 episode_t   hipnoticepisodes[] =
2859 {
2860    {"Scourge of Armagon", 0, 1},
2861    {"Fortress of the Dead", 1, 5},
2862    {"Dominion of Darkness", 6, 6},
2863    {"The Rift", 12, 4},
2864    {"Final Level", 16, 1},
2865    {"Deathmatch Arena", 17, 1}
2866 };
2867
2868 //PGM 01/07/97 added rogue levels
2869 //PGM 03/02/97 added dmatch level
2870 level_t         roguelevels[] =
2871 {
2872         {"start",       "Split Decision"},
2873         {"r1m1",        "Deviant's Domain"},
2874         {"r1m2",        "Dread Portal"},
2875         {"r1m3",        "Judgement Call"},
2876         {"r1m4",        "Cave of Death"},
2877         {"r1m5",        "Towers of Wrath"},
2878         {"r1m6",        "Temple of Pain"},
2879         {"r1m7",        "Tomb of the Overlord"},
2880         {"r2m1",        "Tempus Fugit"},
2881         {"r2m2",        "Elemental Fury I"},
2882         {"r2m3",        "Elemental Fury II"},
2883         {"r2m4",        "Curse of Osiris"},
2884         {"r2m5",        "Wizard's Keep"},
2885         {"r2m6",        "Blood Sacrifice"},
2886         {"r2m7",        "Last Bastion"},
2887         {"r2m8",        "Source of Evil"},
2888         {"ctf1",    "Division of Change"}
2889 };
2890
2891 //PGM 01/07/97 added rogue episodes
2892 //PGM 03/02/97 added dmatch episode
2893 episode_t       rogueepisodes[] =
2894 {
2895         {"Introduction", 0, 1},
2896         {"Hell's Fortress", 1, 7},
2897         {"Corridors of Time", 8, 8},
2898         {"Deathmatch Arena", 16, 1}
2899 };
2900
2901 level_t         nehahralevels[] =
2902 {
2903         {"nehstart",    "Welcome to Nehahra"},
2904         {"neh1m1",      "Forge City1: Slipgates"},
2905         {"neh1m2",      "Forge City2: Boiler"},
2906         {"neh1m3",      "Forge City3: Escape"},
2907         {"neh1m4",      "Grind Core"},
2908         {"neh1m5",      "Industrial Silence"},
2909         {"neh1m6",      "Locked-Up Anger"},
2910         {"neh1m7",      "Wanderer of the Wastes"},
2911         {"neh1m8",      "Artemis System Net"},
2912         {"neh1m9",      "To the Death"},
2913         {"neh2m1",      "The Gates of Ghoro"},
2914         {"neh2m2",      "Sacred Trinity"},
2915         {"neh2m3",      "Realm of the Ancients"},
2916         {"neh2m4",      "Temple of the Ancients"},
2917         {"neh2m5",      "Dreams Made Flesh"},
2918         {"neh2m6",      "Your Last Cup of Sorrow"},
2919         {"nehsec",      "Ogre's Bane"},
2920         {"nehahra",     "Nehahra's Den"},
2921         {"nehend",      "Quintessence"}
2922 };
2923
2924 episode_t       nehahraepisodes[] =
2925 {
2926         {"Welcome to Nehahra", 0, 1},
2927         {"The Fall of Forge", 1, 9},
2928         {"The Outlands", 10, 7},
2929         {"Dimension of the Lost", 17, 2}
2930 };
2931
2932 // Map list for Transfusion
2933 level_t         transfusionlevels[] =
2934 {
2935         {"bb1",                 "The Stronghold"},
2936         {"bb2",                 "Winter Wonderland"},
2937         {"bb3",                 "Bodies"},
2938         {"bb4",                 "The Tower"},
2939         {"bb5",                 "Click!"},
2940         {"bb6",                 "Twin Fortress"},
2941         {"bb7",                 "Midgard"},
2942         {"bb8",                 "Fun With Heads"},
2943
2944         {"e1m1",                "Cradle to Grave"},
2945         {"e1m2",                "Wrong Side of the Tracks"},
2946         {"e1m7",                "Altar of Stone"},
2947         {"e2m8",                "The Lair of Shial"},
2948         {"e3m7",                "The Pit of Cerberus"},
2949         {"e4m8",                "The Hall of the Epiphany"},
2950         {"e4m9",                "Mall of the Dead"},
2951
2952         {"dm1",                 "Monolith Building 11"},
2953         {"dm2",                 "Power!"},
2954         {"dm3",                 "Area 15"},
2955         {"e6m1",                "Welcome to Your Life"},
2956         {"e6m8",                "Beauty and the Beast"},
2957
2958         {"cpbb01",              "Crypt of Despair"},
2959         {"cpbb03",              "Unholy Cathedral"},
2960
2961         {"b2a15",               "Area 15 (B2)"},
2962         {"barena",              "Blood Arena"},
2963         {"bkeep",               "Blood Keep"},
2964         {"bstar",               "Brown Star"},
2965         {"crypt",               "The Crypt"},
2966
2967         {"bb3_2k1",             "Bodies Infusion"},
2968         {"dcamp",               "DeathCamp"},
2969         {"highnoon",    "HighNoon"},
2970         {"qbb1",                "The Confluence"},
2971         {"qbb2",                "KathartiK"},
2972         {"qbb3",                "Caleb's Woodland Retreat"},
2973
2974         {"dranzbb6",    "Black Coffee"},
2975         {"fragm",               "Frag'M"},
2976         {"maim",                "Maim"},
2977         {"qe1m7",               "The House of Chthon"},
2978         {"simple",              "Dead Simple"}
2979 };
2980
2981 episode_t       transfusionepisodes[] =
2982 {
2983         {"Blood", 0, 8},
2984         {"Blood Single Player", 8, 7},
2985         {"Plasma Pack", 15, 5},
2986         {"Cryptic Passage", 20, 2},
2987         {"Blood 2", 22, 5},
2988         {"Transfusion", 27, 6},
2989         {"Conversions", 33, 5}
2990 };
2991
2992 gamelevels_t sharewarequakegame = {"Shareware Quake", quakelevels, quakeepisodes, 2};
2993 gamelevels_t registeredquakegame = {"Quake", quakelevels, quakeepisodes, 7};
2994 gamelevels_t hipnoticgame = {"Scourge of Armagon", hipnoticlevels, hipnoticepisodes, 6};
2995 gamelevels_t roguegame = {"Dissolution of Eternity", roguelevels, rogueepisodes, 4};
2996 gamelevels_t nehahragame = {"Nehahra", nehahralevels, nehahraepisodes, 4};
2997 gamelevels_t transfusiongame = {"Transfusion", transfusionlevels, transfusionepisodes, 7};
2998
2999 typedef struct
3000 {
3001         int gameid;
3002         gamelevels_t *notregistered;
3003         gamelevels_t *registered;
3004 }
3005 gameinfo_t;
3006
3007 gameinfo_t gamelist[] =
3008 {
3009         {GAME_NORMAL, &sharewarequakegame, &registeredquakegame},
3010         {GAME_HIPNOTIC, &hipnoticgame, &hipnoticgame},
3011         {GAME_ROGUE, &roguegame, &roguegame},
3012         {GAME_NEHAHRA, &nehahragame, &nehahragame},
3013         {GAME_TRANSFUSION, &transfusiongame, &transfusiongame},
3014         {-1, &sharewarequakegame, &registeredquakegame} // final fallback
3015 };
3016
3017 gamelevels_t *lookupgameinfo(void)
3018 {
3019         int i;
3020         for (i = 0;gamelist[i].gameid >= 0 && gamelist[i].gameid != gamemode;i++);
3021         if (registered.integer)
3022                 return gamelist[i].registered;
3023         else
3024                 return gamelist[i].notregistered;
3025 }
3026
3027 int     startepisode;
3028 int     startlevel;
3029 int maxplayers;
3030 qboolean m_serverInfoMessage = false;
3031 double m_serverInfoMessageTime;
3032
3033 extern cvar_t sv_public;
3034
3035 void M_Menu_GameOptions_f (void)
3036 {
3037         key_dest = key_menu;
3038         m_state = m_gameoptions;
3039         m_entersound = true;
3040         if (maxplayers == 0)
3041                 maxplayers = svs.maxclients;
3042         if (maxplayers < 2)
3043                 maxplayers = MAX_SCOREBOARD;
3044 }
3045
3046
3047 int gameoptions_cursor_table[] = {40, 56, 64, 72, 80, 88, 96, 104, 120, 128};
3048 #define NUM_GAMEOPTIONS 10
3049 int             gameoptions_cursor;
3050
3051 void M_GameOptions_Draw (void)
3052 {
3053         cachepic_t      *p;
3054         int             x;
3055         gamelevels_t *g;
3056
3057         M_DrawPic (16, 4, "gfx/qplaque.lmp");
3058         p = Draw_CachePic ("gfx/p_multi.lmp");
3059         M_DrawPic ( (320-p->width)/2, 4, "gfx/p_multi.lmp");
3060
3061         M_DrawTextBox (152, 32, 10, 1);
3062         M_Print (160, 40, "begin game");
3063
3064         M_Print (0, 56, "      Max players");
3065         M_Print (160, 56, va("%i", maxplayers) );
3066
3067         M_Print (0, 64, "        Game Type");
3068         if (gamemode == GAME_TRANSFUSION)
3069         {
3070                 if (!deathmatch.integer)
3071                         Cvar_SetValue("deathmatch", 1);
3072                 if (deathmatch.integer == 2)
3073                         M_Print (160, 64, "Capture the Flag");
3074                 else
3075                         M_Print (160, 64, "Blood Bath");
3076         }
3077         else
3078         {
3079                 if (!coop.integer && !deathmatch.integer)
3080                         Cvar_SetValue("deathmatch", 1);
3081                 if (coop.integer)
3082                         M_Print (160, 64, "Cooperative");
3083                 else
3084                         M_Print (160, 64, "Deathmatch");
3085         }
3086
3087         M_Print (0, 72, "        Teamplay");
3088         if (gamemode == GAME_ROGUE)
3089         {
3090                 char *msg;
3091
3092                 switch((int)teamplay.integer)
3093                 {
3094                         case 1: msg = "No Friendly Fire"; break;
3095                         case 2: msg = "Friendly Fire"; break;
3096                         case 3: msg = "Tag"; break;
3097                         case 4: msg = "Capture the Flag"; break;
3098                         case 5: msg = "One Flag CTF"; break;
3099                         case 6: msg = "Three Team CTF"; break;
3100                         default: msg = "Off"; break;
3101                 }
3102                 M_Print (160, 72, msg);
3103         }
3104         else if (gamemode == GAME_TRANSFUSION)
3105         {
3106                 char *msg;
3107
3108                 switch (teamplay.integer)
3109                 {
3110                         case 0: msg = "Off"; break;
3111                         case 2: msg = "Friendly Fire"; break;
3112                         default: msg = "No Friendly Fire"; break;
3113                 }
3114                 M_Print (160, 72, msg);
3115         }
3116         else
3117         {
3118                 char *msg;
3119
3120                 switch((int)teamplay.integer)
3121                 {
3122                         case 1: msg = "No Friendly Fire"; break;
3123                         case 2: msg = "Friendly Fire"; break;
3124                         default: msg = "Off"; break;
3125                 }
3126                 M_Print (160, 72, msg);
3127         }
3128
3129         M_Print (0, 80, "            Skill");
3130         if (skill.integer == 0)
3131                 M_Print (160, 80, "Easy difficulty");
3132         else if (skill.integer == 1)
3133                 M_Print (160, 80, "Normal difficulty");
3134         else if (skill.integer == 2)
3135                 M_Print (160, 80, "Hard difficulty");
3136         else
3137                 M_Print (160, 80, "Nightmare difficulty");
3138
3139         M_Print (0, 88, "       Frag Limit");
3140         if (fraglimit.integer == 0)
3141                 M_Print (160, 88, "none");
3142         else
3143                 M_Print (160, 88, va("%i frags", fraglimit.integer));
3144
3145         M_Print (0, 96, "       Time Limit");
3146         if (timelimit.integer == 0)
3147                 M_Print (160, 96, "none");
3148         else
3149                 M_Print (160, 96, va("%i minutes", timelimit.integer));
3150
3151         M_Print (0, 104, "    Public server");
3152         M_Print (160, 104, (sv_public.integer == 0) ? "no" : "yes");
3153
3154         g = lookupgameinfo();
3155
3156         M_Print (0, 120, "         Episode");
3157         M_Print (160, 120, g->episodes[startepisode].description);
3158
3159         M_Print (0, 128, "           Level");
3160         M_Print (160, 128, g->levels[g->episodes[startepisode].firstLevel + startlevel].description);
3161         M_Print (160, 136, g->levels[g->episodes[startepisode].firstLevel + startlevel].name);
3162
3163 // line cursor
3164         M_DrawCharacter (144, gameoptions_cursor_table[gameoptions_cursor], 12+((int)(realtime*4)&1));
3165
3166         if (m_serverInfoMessage)
3167         {
3168                 if ((realtime - m_serverInfoMessageTime) < 5.0)
3169                 {
3170                         x = (320-26*8)/2;
3171                         M_DrawTextBox (x, 138, 24, 4);
3172                         x += 8;
3173                         M_Print (x, 146, " More than 64 players?? ");
3174                         M_Print (x, 154, "  First, question your  ");
3175                         M_Print (x, 162, "   sanity, then email   ");
3176                         M_Print (x, 170, " havoc@telefragged.com  ");
3177                 }
3178                 else
3179                 {
3180                         m_serverInfoMessage = false;
3181                 }
3182         }
3183 }
3184
3185
3186 void M_NetStart_Change (int dir)
3187 {
3188         gamelevels_t *g;
3189         int count;
3190
3191         switch (gameoptions_cursor)
3192         {
3193         case 1:
3194                 maxplayers += dir;
3195                 if (maxplayers > MAX_SCOREBOARD)
3196                 {
3197                         maxplayers = MAX_SCOREBOARD;
3198                         m_serverInfoMessage = true;
3199                         m_serverInfoMessageTime = realtime;
3200                 }
3201                 if (maxplayers < 2)
3202                         maxplayers = 2;
3203                 break;
3204
3205         case 2:
3206                 if (gamemode == GAME_TRANSFUSION)
3207                 {
3208                         if (deathmatch.integer == 2) // changing from CTF to BloodBath
3209                                 Cvar_SetValueQuick (&deathmatch, 0);
3210                         else // changing from BloodBath to CTF
3211                                 Cvar_SetValueQuick (&deathmatch, 2);
3212                 }
3213                 else
3214                 {
3215                         if (deathmatch.integer) // changing from deathmatch to coop
3216                         {
3217                                 Cvar_SetValueQuick (&coop, 1);
3218                                 Cvar_SetValueQuick (&deathmatch, 0);
3219                         }
3220                         else // changing from coop to deathmatch
3221                         {
3222                                 Cvar_SetValueQuick (&coop, 0);
3223                                 Cvar_SetValueQuick (&deathmatch, 1);
3224                         }
3225                 }
3226                 break;
3227
3228         case 3:
3229                 if (gamemode == GAME_ROGUE)
3230                         count = 6;
3231                 else
3232                         count = 2;
3233
3234                 Cvar_SetValueQuick (&teamplay, teamplay.integer + dir);
3235                 if (teamplay.integer > count)
3236                         Cvar_SetValueQuick (&teamplay, 0);
3237                 else if (teamplay.integer < 0)
3238                         Cvar_SetValueQuick (&teamplay, count);
3239                 break;
3240
3241         case 4:
3242                 Cvar_SetValueQuick (&skill, skill.integer + dir);
3243                 if (skill.integer > 3)
3244                         Cvar_SetValueQuick (&skill, 0);
3245                 if (skill.integer < 0)
3246                         Cvar_SetValueQuick (&skill, 3);
3247                 break;
3248
3249         case 5:
3250                 Cvar_SetValueQuick (&fraglimit, fraglimit.integer + dir*10);
3251                 if (fraglimit.integer > 100)
3252                         Cvar_SetValueQuick (&fraglimit, 0);
3253                 if (fraglimit.integer < 0)
3254                         Cvar_SetValueQuick (&fraglimit, 100);
3255                 break;
3256
3257         case 6:
3258                 Cvar_SetValueQuick (&timelimit, timelimit.value + dir*5);
3259                 if (timelimit.value > 60)
3260                         Cvar_SetValueQuick (&timelimit, 0);
3261                 if (timelimit.value < 0)
3262                         Cvar_SetValueQuick (&timelimit, 60);
3263                 break;
3264
3265         case 7:
3266                 Cvar_SetValueQuick (&sv_public, !sv_public.integer);
3267                 break;
3268
3269         case 8:
3270                 startepisode += dir;
3271                 g = lookupgameinfo();
3272
3273                 if (startepisode < 0)
3274                         startepisode = g->numepisodes - 1;
3275
3276                 if (startepisode >= g->numepisodes)
3277                         startepisode = 0;
3278
3279                 startlevel = 0;
3280                 break;
3281
3282         case 9:
3283                 startlevel += dir;
3284                 g = lookupgameinfo();
3285
3286                 if (startlevel < 0)
3287                         startlevel = g->episodes[startepisode].levels - 1;
3288
3289                 if (startlevel >= g->episodes[startepisode].levels)
3290                         startlevel = 0;
3291                 break;
3292         }
3293 }
3294
3295 void M_GameOptions_Key (int key)
3296 {
3297         gamelevels_t *g;
3298
3299         switch (key)
3300         {
3301         case K_ESCAPE:
3302                 M_Menu_Net_f ();
3303                 break;
3304
3305         case K_UPARROW:
3306                 S_LocalSound ("misc/menu1.wav");
3307                 gameoptions_cursor--;
3308                 if (gameoptions_cursor < 0)
3309                         gameoptions_cursor = NUM_GAMEOPTIONS-1;
3310                 break;
3311
3312         case K_DOWNARROW:
3313                 S_LocalSound ("misc/menu1.wav");
3314                 gameoptions_cursor++;
3315                 if (gameoptions_cursor >= NUM_GAMEOPTIONS)
3316                         gameoptions_cursor = 0;
3317                 break;
3318
3319         case K_LEFTARROW:
3320                 if (gameoptions_cursor == 0)
3321                         break;
3322                 S_LocalSound ("misc/menu3.wav");
3323                 M_NetStart_Change (-1);
3324                 break;
3325
3326         case K_RIGHTARROW:
3327                 if (gameoptions_cursor == 0)
3328                         break;
3329                 S_LocalSound ("misc/menu3.wav");
3330                 M_NetStart_Change (1);
3331                 break;
3332
3333         case K_ENTER:
3334                 S_LocalSound ("misc/menu2.wav");
3335                 if (gameoptions_cursor == 0)
3336                 {
3337                         if (sv.active)
3338                                 Cbuf_AddText ("disconnect\n");
3339                         Cbuf_AddText ("listen 0\n");    // so host_netport will be re-examined
3340                         Cbuf_AddText ( va ("maxplayers %u\n", maxplayers) );
3341
3342                         g = lookupgameinfo();
3343                         Cbuf_AddText ( va ("map %s\n", g->levels[g->episodes[startepisode].firstLevel + startlevel].name) );
3344                         return;
3345                 }
3346
3347                 M_NetStart_Change (1);
3348                 break;
3349         }
3350 }
3351
3352 //=============================================================================
3353 /* SEARCH MENU */
3354
3355 qboolean        searchComplete = false;
3356 double          searchCompleteTime;
3357
3358 void M_Menu_Search_f (void)
3359 {
3360         key_dest = key_menu;
3361         m_state = m_search;
3362         m_entersound = false;
3363         slistSilent = true;
3364         slistLocal = false;
3365         searchComplete = false;
3366         NET_Slist_f();
3367
3368 }
3369
3370
3371 void M_Search_Draw (void)
3372 {
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         M_PrintWhite ((320/2) - ((22*8)/2), 64, va("No %s servers found", gamename));
3401         if ((realtime - searchCompleteTime) < 3.0)
3402                 return;
3403
3404         M_Menu_LanConfig_f ();
3405 }
3406
3407
3408 void M_Search_Key (int key)
3409 {
3410 }
3411
3412 //=============================================================================
3413 /* INTERNET SEARCH MENU */
3414
3415 void M_Menu_InetSearch_f (void)
3416 {
3417         key_dest = key_menu;
3418         m_state = m_search;
3419         m_entersound = false;
3420         slistSilent = true;
3421         slistLocal = false;
3422         searchComplete = false;
3423         NET_InetSlist_f();
3424
3425 }
3426
3427
3428 void M_InetSearch_Draw (void)
3429 {
3430         M_Search_Draw ();  // it's the same one, so why bother?
3431 }
3432
3433
3434 void M_InetSearch_Key (int key)
3435 {
3436 }
3437
3438 //=============================================================================
3439 /* SLIST MENU */
3440
3441 int             slist_cursor;
3442 qboolean slist_sorted;
3443
3444 void M_Menu_ServerList_f (void)
3445 {
3446         key_dest = key_menu;
3447         m_state = m_slist;
3448         m_entersound = true;
3449         slist_cursor = 0;
3450         m_return_onerror = false;
3451         m_return_reason[0] = 0;
3452         slist_sorted = false;
3453 }
3454
3455
3456 void M_ServerList_Draw (void)
3457 {
3458         int             n;
3459         char    string [64];
3460         cachepic_t      *p;
3461
3462         if (!slist_sorted)
3463         {
3464                 if (hostCacheCount > 1)
3465                 {
3466                         int     i,j;
3467                         hostcache_t temp;
3468                         for (i = 0; i < hostCacheCount; i++)
3469                                 for (j = i+1; j < hostCacheCount; j++)
3470                                         if (strcmp(hostcache[j].name, hostcache[i].name) < 0)
3471                                         {
3472                                                 memcpy(&temp, &hostcache[j], sizeof(hostcache_t));
3473                                                 memcpy(&hostcache[j], &hostcache[i], sizeof(hostcache_t));
3474                                                 memcpy(&hostcache[i], &temp, sizeof(hostcache_t));
3475                                         }
3476                 }
3477                 slist_sorted = true;
3478         }
3479
3480         p = Draw_CachePic ("gfx/p_multi.lmp");
3481         M_DrawPic ( (320-p->width)/2, 4, "gfx/p_multi.lmp");
3482         for (n = 0; n < hostCacheCount; n++)
3483         {
3484                 if (hostcache[n].maxusers)
3485                         sprintf(string, "%-15.15s %-15.15s %2u/%2u\n", hostcache[n].name, hostcache[n].map, hostcache[n].users, hostcache[n].maxusers);
3486                 else
3487                         sprintf(string, "%-15.15s %-15.15s\n", hostcache[n].name, hostcache[n].map);
3488                 M_Print (16, 32 + 8*n, string);
3489         }
3490         M_DrawCharacter (0, 32 + slist_cursor*8, 12+((int)(realtime*4)&1));
3491
3492         if (*m_return_reason)
3493                 M_PrintWhite (16, 168, m_return_reason);
3494 }
3495
3496
3497 void M_ServerList_Key (int k)
3498 {
3499         switch (k)
3500         {
3501         case K_ESCAPE:
3502                 M_Menu_LanConfig_f ();
3503                 break;
3504
3505         case K_SPACE:
3506                 M_Menu_Search_f ();
3507                 break;
3508
3509         case K_UPARROW:
3510         case K_LEFTARROW:
3511                 S_LocalSound ("misc/menu1.wav");
3512                 slist_cursor--;
3513                 if (slist_cursor < 0)
3514                         slist_cursor = hostCacheCount - 1;
3515                 break;
3516
3517         case K_DOWNARROW:
3518         case K_RIGHTARROW:
3519                 S_LocalSound ("misc/menu1.wav");
3520                 slist_cursor++;
3521                 if (slist_cursor >= hostCacheCount)
3522                         slist_cursor = 0;
3523                 break;
3524
3525         case K_ENTER:
3526                 S_LocalSound ("misc/menu2.wav");
3527                 m_return_state = m_state;
3528                 m_return_onerror = true;
3529                 slist_sorted = false;
3530                 key_dest = key_game;
3531                 m_state = m_none;
3532                 Cbuf_AddText ( va ("connect \"%s\"\n", hostcache[slist_cursor].cname) );
3533                 break;
3534
3535         default:
3536                 break;
3537         }
3538
3539 }
3540
3541 //=============================================================================
3542 /* Menu Subsystem */
3543
3544
3545 void M_Init (void)
3546 {
3547         Cmd_AddCommand ("togglemenu", M_ToggleMenu_f);
3548
3549         Cmd_AddCommand ("menu_main", M_Menu_Main_f);
3550         Cmd_AddCommand ("menu_singleplayer", M_Menu_SinglePlayer_f);
3551         Cmd_AddCommand ("menu_load", M_Menu_Load_f);
3552         Cmd_AddCommand ("menu_save", M_Menu_Save_f);
3553         Cmd_AddCommand ("menu_multiplayer", M_Menu_MultiPlayer_f);
3554         Cmd_AddCommand ("menu_setup", M_Menu_Setup_f);
3555         Cmd_AddCommand ("menu_options", M_Menu_Options_f);
3556         Cmd_AddCommand ("menu_options_effects", M_Menu_Options_Effects_f);
3557         Cmd_AddCommand ("menu_options_colorcontrol", M_Menu_Options_ColorControl_f);
3558         Cvar_RegisterVariable (&menu_options_colorcontrol_correctionvalue);
3559         Cmd_AddCommand ("menu_keys", M_Menu_Keys_f);
3560         Cmd_AddCommand ("menu_video", M_Menu_Video_f);
3561         Cmd_AddCommand ("help", M_Menu_Help_f);
3562         Cmd_AddCommand ("menu_quit", M_Menu_Quit_f);
3563
3564         if (gamemode == GAME_TRANSFUSION)
3565         {
3566                 numcommands = sizeof(transfusionbindnames) / sizeof(transfusionbindnames[0]);
3567                 bindnames = transfusionbindnames;
3568         }
3569         else
3570         {
3571                 numcommands = sizeof(quakebindnames) / sizeof(quakebindnames[0]);
3572                 bindnames = quakebindnames;
3573         }
3574
3575         if (gamemode == GAME_NEHAHRA)
3576         {
3577                 if (FS_FileExists("maps/neh1m4.bsp"))
3578                 {
3579                         if (FS_FileExists("hearing.dem"))
3580                         {
3581                                 Con_Printf("Nehahra movie and game detected.\n");
3582                                 NehGameType = TYPE_BOTH;
3583                         }
3584                         else
3585                         {
3586                                 Con_Printf("Nehahra game detected.\n");
3587                                 NehGameType = TYPE_GAME;
3588                         }
3589                 }
3590                 else
3591                 {
3592                         if (FS_FileExists("hearing.dem"))
3593                         {
3594                                 Con_Printf("Nehahra movie detected.\n");
3595                                 NehGameType = TYPE_DEMO;
3596                         }
3597                         else
3598                         {
3599                                 Con_Printf("Nehahra not found.\n");
3600                                 NehGameType = TYPE_GAME; // could just complain, but...
3601                         }
3602                 }
3603         }
3604 }
3605
3606 void M_Draw (void)
3607 {
3608         if (m_state == m_none || key_dest != key_menu)
3609                 return;
3610
3611         M_DrawBackground();
3612
3613         switch (m_state)
3614         {
3615         case m_none:
3616                 break;
3617
3618         case m_main:
3619                 M_Main_Draw ();
3620                 break;
3621
3622         case m_demo:
3623                 M_Demo_Draw ();
3624                 break;
3625
3626         case m_singleplayer:
3627                 M_SinglePlayer_Draw ();
3628                 break;
3629
3630         case m_load:
3631                 M_Load_Draw ();
3632                 break;
3633
3634         case m_save:
3635                 M_Save_Draw ();
3636                 break;
3637
3638         case m_multiplayer:
3639                 M_MultiPlayer_Draw ();
3640                 break;
3641
3642         case m_setup:
3643                 M_Setup_Draw ();
3644                 break;
3645
3646         case m_net:
3647                 M_Net_Draw ();
3648                 break;
3649
3650         case m_options:
3651                 M_Options_Draw ();
3652                 break;
3653
3654         case m_options_effects:
3655                 M_Options_Effects_Draw ();
3656                 break;
3657
3658         case m_options_colorcontrol:
3659                 M_Options_ColorControl_Draw ();
3660                 break;
3661
3662         case m_keys:
3663                 M_Keys_Draw ();
3664                 break;
3665
3666         case m_video:
3667                 M_Video_Draw ();
3668                 break;
3669
3670         case m_help:
3671                 M_Help_Draw ();
3672                 break;
3673
3674         case m_quit:
3675                 M_Quit_Draw ();
3676                 break;
3677
3678         case m_lanconfig:
3679                 M_LanConfig_Draw ();
3680                 break;
3681
3682         case m_gameoptions:
3683                 M_GameOptions_Draw ();
3684                 break;
3685
3686         case m_search:
3687                 M_Search_Draw ();
3688                 break;
3689
3690         case m_slist:
3691                 M_ServerList_Draw ();
3692                 break;
3693         }
3694
3695         if (m_entersound)
3696         {
3697                 S_LocalSound ("misc/menu2.wav");
3698                 m_entersound = false;
3699         }
3700
3701         S_ExtraUpdate ();
3702 }
3703
3704
3705 void M_Keydown (int key)
3706 {
3707         switch (m_state)
3708         {
3709         case m_none:
3710                 return;
3711
3712         case m_main:
3713                 M_Main_Key (key);
3714                 return;
3715
3716         case m_demo:
3717                 M_Demo_Key (key);
3718                 return;
3719
3720         case m_singleplayer:
3721                 M_SinglePlayer_Key (key);
3722                 return;
3723
3724         case m_load:
3725                 M_Load_Key (key);
3726                 return;
3727
3728         case m_save:
3729                 M_Save_Key (key);
3730                 return;
3731
3732         case m_multiplayer:
3733                 M_MultiPlayer_Key (key);
3734                 return;
3735
3736         case m_setup:
3737                 M_Setup_Key (key);
3738                 return;
3739
3740         case m_net:
3741                 M_Net_Key (key);
3742                 return;
3743
3744         case m_options:
3745                 M_Options_Key (key);
3746                 return;
3747
3748         case m_options_effects:
3749                 M_Options_Effects_Key (key);
3750                 return;
3751
3752         case m_options_colorcontrol:
3753                 M_Options_ColorControl_Key (key);
3754                 return;
3755
3756         case m_keys:
3757                 M_Keys_Key (key);
3758                 return;
3759
3760         case m_video:
3761                 M_Video_Key (key);
3762                 return;
3763
3764         case m_help:
3765                 M_Help_Key (key);
3766                 return;
3767
3768         case m_quit:
3769                 M_Quit_Key (key);
3770                 return;
3771
3772         case m_lanconfig:
3773                 M_LanConfig_Key (key);
3774                 return;
3775
3776         case m_gameoptions:
3777                 M_GameOptions_Key (key);
3778                 return;
3779
3780         case m_search:
3781                 M_Search_Key (key);
3782                 break;
3783
3784         case m_slist:
3785                 M_ServerList_Key (key);
3786                 return;
3787         }
3788 }
3789
3790
3791 void M_ConfigureNetSubsystem(void)
3792 {
3793 // enable/disable net systems to match desired config
3794
3795         Cbuf_AddText ("stopdemo\n");
3796
3797         if (IPXConfig || TCPIPConfig)
3798                 net_hostport = lanConfig_port;
3799 }
3800