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