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