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