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