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