This commit was manufactured by cvs2svn to create branch
[btb/d2x.git] / main / menu.c
1 /* $Id: menu.c,v 1.24 2003-04-12 02:52:38 btb Exp $ */
2 /*
3 THE COMPUTER CODE CONTAINED HEREIN IS THE SOLE PROPERTY OF PARALLAX
4 SOFTWARE CORPORATION ("PARALLAX").  PARALLAX, IN DISTRIBUTING THE CODE TO
5 END-USERS, AND SUBJECT TO ALL OF THE TERMS AND CONDITIONS HEREIN, GRANTS A
6 ROYALTY-FREE, PERPETUAL LICENSE TO SUCH END-USERS FOR USE BY SUCH END-USERS
7 IN USING, DISPLAYING,  AND CREATING DERIVATIVE WORKS THEREOF, SO LONG AS
8 SUCH USE, DISPLAY OR CREATION IS FOR NON-COMMERCIAL, ROYALTY OR REVENUE
9 FREE PURPOSES.  IN NO EVENT SHALL THE END-USER USE THE COMPUTER CODE
10 CONTAINED HEREIN FOR REVENUE-BEARING PURPOSES.  THE END-USER UNDERSTANDS
11 AND AGREES TO THE TERMS HEREIN AND ACCEPTS THE SAME BY USE OF THIS FILE.
12 COPYRIGHT 1993-1999 PARALLAX SOFTWARE CORPORATION.  ALL RIGHTS RESERVED.
13 */
14
15 /*
16  *
17  * Inferno main menu.
18  *
19  */
20
21 #ifdef HAVE_CONFIG_H
22 #include <conf.h>
23 #endif
24
25 #ifdef WINDOWS
26 #include "desw.h"
27 #endif
28
29 #include <stdio.h>
30 #include <string.h>
31
32 #include "pa_enabl.h"                   //$$POLY_ACC
33
34 #include "menu.h"
35 #include "inferno.h"
36 #include "game.h"
37 #include "gr.h"
38 #include "key.h"
39 #include "iff.h"
40 #include "u_mem.h"
41 #include "error.h"
42 #include "bm.h"
43 #include "screens.h"
44 #include "mono.h"
45 #include "joy.h"
46 #include "vecmat.h"
47 #include "effects.h"
48 #include "slew.h"
49 #include "gamemine.h"
50 #include "gamesave.h"
51 #include "palette.h"
52 #include "args.h"
53 #include "newdemo.h"
54 #include "timer.h"
55 #include "sounds.h"
56 #include "gameseq.h"
57 #include "text.h"
58 #include "gamefont.h"
59 #include "newmenu.h"
60 #ifdef NETWORK
61 #include "network.h"
62 #endif
63 #include "scores.h"
64 #include "joydefs.h"
65 #include "modem.h"
66 #include "playsave.h"
67 #include "multi.h"
68 #include "kconfig.h"
69 #include "titles.h"
70 #include "credits.h"
71 #include "texmap.h"
72 #include "polyobj.h"
73 #include "state.h"
74 #include "mission.h"
75 #include "songs.h"
76 #include "config.h"
77 #include "movie.h"
78 #include "gamepal.h"
79 #include "gauges.h"
80 #include "powerup.h"
81 #include "strutil.h"
82 #include "reorder.h"
83
84 #ifdef MACINTOSH
85         #include "resource.h"
86         #include "isp.h"
87         #include <Dialogs.h>
88 #endif
89
90 #ifdef EDITOR
91 #include "editor/editor.h"
92 #endif
93
94 #if defined(POLY_ACC)
95 #include "poly_acc.h"
96 #endif
97
98 //char *menu_difficulty_text[] = { "Trainee", "Rookie", "Fighter", "Hotshot", "Insane" };
99 //char *menu_detail_text[] = { "Lowest", "Low", "Medium", "High", "Highest", "", "Custom..." };
100
101 #define MENU_NEW_GAME                   0
102 #define MENU_GAME                       1 
103 #define MENU_EDITOR                     2
104 #define MENU_VIEW_SCORES                3
105 #define MENU_QUIT                       4
106 #define MENU_LOAD_GAME                  5
107 #define MENU_SAVE_GAME                  6
108 #define MENU_DEMO_PLAY                  8
109 #define MENU_LOAD_LEVEL                 9
110 #define MENU_START_IPX_NETGAME          10
111 #define MENU_JOIN_IPX_NETGAME           11
112 #define MENU_CONFIG                     13
113 #define MENU_REJOIN_NETGAME             14
114 #define MENU_DIFFICULTY                 15
115 #define MENU_START_SERIAL               18
116 #define MENU_HELP                       19
117 #define MENU_NEW_PLAYER                 20
118 #define MENU_MULTIPLAYER                21
119 #define MENU_STOP_MODEM                 22
120 #define MENU_SHOW_CREDITS               23
121 #define MENU_ORDER_INFO                 24
122 #define MENU_PLAY_SONG                  25
123 #define MENU_START_TCP_NETGAME          26
124 #define MENU_JOIN_TCP_NETGAME           27
125 #define MENU_START_APPLETALK_NETGAME    28
126 #define MENU_JOIN_APPLETALK_NETGAME     30
127
128 //ADD_ITEM("Start netgame...", MENU_START_NETGAME, -1 );
129 //ADD_ITEM("Send net message...", MENU_SEND_NET_MESSAGE, -1 );
130
131 #define ADD_ITEM(t,value,key)  do { m[num_options].type=NM_TYPE_MENU; m[num_options].text=t; menu_choice[num_options]=value;num_options++; } while (0)
132
133 //unused - extern int last_joy_time;               //last time the joystick was used
134 #ifndef NDEBUG
135 extern int Speedtest_on;
136 #else
137 #define Speedtest_on 0
138 #endif
139
140 void do_sound_menu();
141 void do_toggles_menu();
142
143 ubyte do_auto_demo = 1;                 // Flag used to enable auto demo starting in main menu.
144 int Player_default_difficulty; // Last difficulty level chosen by the player
145 int Auto_leveling_on = 1;
146 int Guided_in_big_window = 0;
147 int Menu_draw_copyright = 0;
148 int EscortHotKeys=1;
149
150 // Function Prototypes added after LINTING
151 void do_option(int select);
152 void do_detail_level_menu_custon(void);
153 void do_multi_player_menu(void);
154 void do_detail_level_menu_custom(void);
155 void do_new_game_menu(void);
156
157 //returns the number of demo files on the disk
158 int newdemo_count_demos();
159 extern ubyte Version_major,Version_minor;
160
161 // ------------------------------------------------------------------------
162 void autodemo_menu_check(int nitems, newmenu_item * items, int *last_key, int citem )
163 {
164         int curtime;
165
166         nitems = nitems;
167         items=items;
168         citem = citem;
169
170         //draw copyright message
171         if ( Menu_draw_copyright )              {
172                 int w,h,aw;
173
174                 Menu_draw_copyright = 0;
175                 WINDOS( dd_gr_set_current_canvas(NULL),
176                                         gr_set_current_canvas(NULL));
177                 gr_set_curfont(GAME_FONT);
178                 gr_set_fontcolor(BM_XRGB(6,6,6),-1);
179
180                 gr_get_string_size("V2.2", &w, &h, &aw );
181         
182                 WIN(DDGRLOCK(dd_grd_curcanv));
183                         gr_printf(0x8000,grd_curcanv->cv_bitmap.bm_h-GAME_FONT->ft_h-2,TXT_COPYRIGHT);
184                         #ifdef MACINTOSH        // print out fix level as well if it exists
185                                 if (Version_fix != 0)
186                                 {
187                                         gr_get_string_size("V2.2.2", &w, &h, &aw );
188                                         gr_printf(grd_curcanv->cv_bitmap.bm_w-w-2,
189                                                           grd_curcanv->cv_bitmap.bm_h-GAME_FONT->ft_h-2,
190                                                           "V%d.%d.%d",
191                                                           Version_major,Version_minor,Version_fix);
192                                 }
193                                 else
194                                 {
195                                         gr_printf(grd_curcanv->cv_bitmap.bm_w-w-2,
196                                                           grd_curcanv->cv_bitmap.bm_h-GAME_FONT->ft_h-2,
197                                                           "V%d.%d",
198                                                           Version_major,Version_minor);
199                                 }
200                         #else
201                                 gr_printf(grd_curcanv->cv_bitmap.bm_w-w-2,grd_curcanv->cv_bitmap.bm_h-GAME_FONT->ft_h-2,"V%d.%d",Version_major,Version_minor);
202                         #endif
203
204                 //say this is vertigo version
205                 if (cfexist(MISSION_DIR "d2x.hog")) {
206                         gr_set_curfont(MEDIUM2_FONT);
207                         gr_printf(MenuHires?495:248, MenuHires?88:37, "Vertigo");
208                 }
209
210                 WIN(DDGRUNLOCK(dd_grd_curcanv));
211         }
212         
213         // Don't allow them to hit ESC in the main menu.
214         if (*last_key==KEY_ESC) *last_key = 0;
215
216         if ( do_auto_demo )     {
217                 curtime = timer_get_approx_seconds();
218                 //if ( ((keyd_time_when_last_pressed+i2f(20)) < curtime) && ((last_joy_time+i2f(20)) < curtime) && (!Speedtest_on)  ) {
219                 #ifndef MACINTOSH               // for now only!!!!
220                 if ( ((keyd_time_when_last_pressed+i2f(25)) < curtime) && (!Speedtest_on)  ) {
221                 #else
222                 if ( (keyd_time_when_last_pressed+i2f(40)) < curtime ) {
223                 #endif
224                         int n_demos;
225
226                         n_demos = newdemo_count_demos();
227
228 try_again:;
229
230                         if ((d_rand() % (n_demos+1)) == 0)
231                         {
232                                 #ifndef SHAREWARE
233                                         #ifdef WINDOWS
234                                         mouse_set_mode(1);                              //re-enable centering mode
235                                         HideCursorW();
236                                         #endif
237 #ifdef OGL
238                                         Screen_mode = -1;
239 #endif
240                                         PlayMovie("intro.mve",0);
241                                         songs_play_song(SONG_TITLE,1);
242                                         *last_key = -3; //exit menu to force redraw even if not going to game mode. -3 tells menu system not to restore
243                                         set_screen_mode(SCREEN_MENU);
244                                         #ifdef WINDOWS
245                                         mouse_set_mode(0);                              //disenable centering mode
246                                         ShowCursorW();
247                                         #endif
248                                 #endif // end of ifndef shareware
249                         }
250                         else {
251                                 WIN(HideCursorW());
252                                 keyd_time_when_last_pressed = curtime;                  // Reset timer so that disk won't thrash if no demos.
253                                 newdemo_start_playback(NULL);           // Randomly pick a file
254                                 if (Newdemo_state == ND_STATE_PLAYBACK) {
255                                         Function_mode = FMODE_GAME;
256                                         *last_key = -3; //exit menu to get into game mode. -3 tells menu system not to restore
257                                 }
258                                 else
259                                         goto try_again; //keep trying until we get a demo that works
260                         }
261                 }
262         }
263 }
264
265 //static int First_time = 1;
266 static int main_menu_choice = 0;
267
268 //      -----------------------------------------------------------------------------
269 //      Create the main menu.
270 void create_main_menu(newmenu_item *m, int *menu_choice, int *callers_num_options)
271 {
272         int     num_options;
273
274         #ifndef DEMO_ONLY
275         num_options = 0;
276
277         set_screen_mode (SCREEN_MENU);
278
279         ADD_ITEM(TXT_NEW_GAME,MENU_NEW_GAME,KEY_N);
280
281         ADD_ITEM(TXT_LOAD_GAME,MENU_LOAD_GAME,KEY_L);
282
283 #ifdef NETWORK
284         ADD_ITEM(TXT_MULTIPLAYER_,MENU_MULTIPLAYER,-1);
285 #endif
286
287         ADD_ITEM(TXT_OPTIONS_, MENU_CONFIG, -1 );
288         ADD_ITEM(TXT_CHANGE_PILOTS,MENU_NEW_PLAYER,unused);
289         ADD_ITEM(TXT_VIEW_DEMO,MENU_DEMO_PLAY,0);
290         ADD_ITEM(TXT_VIEW_SCORES,MENU_VIEW_SCORES,KEY_V);
291         #ifdef SHAREWARE
292         ADD_ITEM(TXT_ORDERING_INFO,MENU_ORDER_INFO,-1);
293         #endif
294         ADD_ITEM(TXT_CREDITS,MENU_SHOW_CREDITS,-1);
295         #endif
296         ADD_ITEM(TXT_QUIT,MENU_QUIT,KEY_Q);
297
298         #ifndef RELEASE
299         if (!(Game_mode & GM_MULTI ))   {
300                 //m[num_options].type=NM_TYPE_TEXT;
301                 //m[num_options++].text=" Debug options:";
302
303                 ADD_ITEM("  Load level...",MENU_LOAD_LEVEL ,KEY_N);
304                 #ifdef EDITOR
305                 ADD_ITEM("  Editor", MENU_EDITOR, KEY_E);
306                 #endif
307         }
308
309         //ADD_ITEM( "  Play song", MENU_PLAY_SONG, -1 );
310         #endif
311
312         *callers_num_options = num_options;
313 }
314
315 //returns number of item chosen
316 int DoMenu() 
317 {
318         int menu_choice[25];
319         newmenu_item m[25];
320         int num_options = 0;
321
322         load_palette(MENU_PALETTE,0,1);         //get correct palette
323
324         if ( Players[Player_num].callsign[0]==0 )       {
325                 RegisterPlayer();
326                 return 0;
327         }
328         
329         if ((Game_mode & GM_SERIAL) || (Game_mode & GM_MODEM)) {
330                 do_option(MENU_START_SERIAL);
331                 return 0;
332         }
333
334         create_main_menu(m, menu_choice, &num_options);
335
336         do {
337                 keyd_time_when_last_pressed = timer_get_fixed_seconds();                // .. 20 seconds from now!
338                 if (main_menu_choice < 0 )
339                         main_menu_choice = 0;
340                 Menu_draw_copyright = 1;
341                 main_menu_choice = newmenu_do2( "", NULL, num_options, m, autodemo_menu_check, main_menu_choice, Menu_pcx_name);
342                 if ( main_menu_choice > -1 ) do_option(menu_choice[main_menu_choice]);
343                 create_main_menu(m, menu_choice, &num_options); //      may have to change, eg, maybe selected pilot and no save games.
344         } while( Function_mode==FMODE_MENU );
345
346 //      if (main_menu_choice != -2)
347 //              do_auto_demo = 0;               // No more auto demos
348         if ( Function_mode==FMODE_GAME )
349                 gr_palette_fade_out( gr_palette, 32, 0 );
350
351         return main_menu_choice;
352 }
353
354 extern void show_order_form(void);      // John didn't want this in inferno.h so I just externed it.
355
356 #ifdef WINDOWS
357 #undef TXT_SELECT_DEMO
358 #define TXT_SELECT_DEMO "Select Demo\n<Ctrl-D> or Right-click\nto delete"
359 #endif
360
361 //returns flag, true means quit menu
362 void do_option ( int select) 
363 {
364         switch (select) {
365                 case MENU_NEW_GAME:
366                         do_new_game_menu();
367                         break;
368                 case MENU_GAME:
369                         break;
370                 case MENU_DEMO_PLAY:
371                 {
372                         char demo_file[16];
373                         if (newmenu_get_filename( TXT_SELECT_DEMO, DEMO_DIR "*.dem", demo_file, 1 ))
374                                 newdemo_start_playback(demo_file);
375                         break;
376                 }
377                 case MENU_LOAD_GAME:
378                         state_restore_all(0, 0, NULL);
379                         break;
380                 #ifdef EDITOR
381                 case MENU_EDITOR:
382                         Function_mode = FMODE_EDITOR;
383                         init_cockpit();
384                         break;
385                 #endif
386                 case MENU_VIEW_SCORES:
387                         gr_palette_fade_out( gr_palette,32,0 );
388                         scores_view(-1);
389                         break;
390                 #ifdef SHAREWARE
391                 case MENU_ORDER_INFO:
392                         show_order_form();
393                         break;
394                 #endif
395                 case MENU_QUIT:
396                         #ifdef EDITOR
397                         if (! SafetyCheck()) break;
398                         #endif
399                         gr_palette_fade_out( gr_palette,32,0);
400                         Function_mode = FMODE_EXIT;
401                         break;
402                 case MENU_NEW_PLAYER:
403                         RegisterPlayer();               //1 == allow escape out of menu
404                         break;
405
406                 case MENU_HELP:
407                         do_show_help();
408                         break;
409
410                 #ifndef RELEASE
411
412                 case MENU_PLAY_SONG:    {
413                                 int i;
414                                 char * m[MAX_NUM_SONGS];
415
416                                 for (i=0;i<Num_songs;i++) {
417                                         m[i] = Songs[i].filename;
418                                 }
419                                 i = newmenu_listbox( "Select Song", Num_songs, m, 1, NULL );
420
421                                 if ( i > -1 )   {
422                                         songs_play_song( i, 0 );
423                                 }
424                         }
425                         break;
426                 case MENU_LOAD_LEVEL: {
427                         newmenu_item m;
428                         char text[10]="";
429                         int new_level_num;
430
431                         m.type=NM_TYPE_INPUT; m.text_len = 10; m.text = text;
432
433                         newmenu_do( NULL, "Enter level to load", 1, &m, NULL );
434
435                         new_level_num = atoi(m.text);
436
437                         if (new_level_num!=0 && new_level_num>=Last_secret_level && new_level_num<=Last_level)  {
438                                 gr_palette_fade_out( gr_palette, 32, 0 );
439                                 StartNewGame(new_level_num);
440                         }
441
442                         break;
443                 }
444                 #endif
445
446
447 #ifdef NETWORK
448                 case MENU_START_IPX_NETGAME:
449                 case MENU_START_TCP_NETGAME:
450                         load_mission(Builtin_mission_num);
451                         #ifdef MACINTOSH
452                         Network_game_type = IPX_GAME;
453                         #endif
454 //                      WIN(ipx_create_read_thread());
455                         network_start_game();
456                         break;
457
458                 case MENU_JOIN_IPX_NETGAME:
459                 case MENU_JOIN_TCP_NETGAME:
460                         load_mission(Builtin_mission_num);
461                         #ifdef MACINTOSH
462                         Network_game_type = IPX_GAME;
463                         #endif
464 //                      WIN(ipx_create_read_thread());
465                         network_join_game();
466                         break;
467
468 #ifdef MACINTOSH
469                 case MENU_START_APPLETALK_NETGAME:
470                         load_mission(Builtin_mission_num);
471                         #ifdef MACINTOSH
472                         Network_game_type = APPLETALK_GAME;
473                         #endif
474                         network_start_game();
475                         break;
476
477                 case MENU_JOIN_APPLETALK_NETGAME:
478                         load_mission(Builtin_mission_num);
479                         #ifdef MACINTOSH
480                         Network_game_type = APPLETALK_GAME;
481                         #endif
482                         network_join_game();
483                         break;
484 #endif
485 #if 0
486                 case MENU_START_TCP_NETGAME:
487                 case MENU_JOIN_TCP_NETGAME:
488                         nm_messagebox (TXT_SORRY,1,TXT_OK,"Not available in shareware version!");
489                         // DoNewIPAddress();
490                         break;
491 #endif
492                 case MENU_START_SERIAL:
493                         com_main_menu();
494                         break;
495                 case MENU_MULTIPLAYER:
496                         do_multi_player_menu();
497                         break;
498 #endif //NETWORK
499                 case MENU_CONFIG:
500                         do_options_menu();
501                         break;
502                 case MENU_SHOW_CREDITS:
503                         gr_palette_fade_out( gr_palette,32,0);
504                         songs_stop_all();
505                         credits_show(NULL); 
506                         break;
507                 default:
508                         Error("Unknown option %d in do_option",select);
509                         break;
510         }
511
512 }
513
514 int do_difficulty_menu()
515 {
516         int s;
517         newmenu_item m[5];
518
519         m[0].type=NM_TYPE_MENU; m[0].text=MENU_DIFFICULTY_TEXT(0);
520         m[1].type=NM_TYPE_MENU; m[1].text=MENU_DIFFICULTY_TEXT(1);
521         m[2].type=NM_TYPE_MENU; m[2].text=MENU_DIFFICULTY_TEXT(2);
522         m[3].type=NM_TYPE_MENU; m[3].text=MENU_DIFFICULTY_TEXT(3);
523         m[4].type=NM_TYPE_MENU; m[4].text=MENU_DIFFICULTY_TEXT(4);
524
525         s = newmenu_do1( NULL, TXT_DIFFICULTY_LEVEL, NDL, m, NULL, Difficulty_level);
526
527         if (s > -1 )    {
528                 if (s != Difficulty_level)
529                 {       
530                         Player_default_difficulty = s;
531                         write_player_file();
532                 }
533                 Difficulty_level = s;
534                 mprintf((0, "%s %s %i\n", TXT_DIFFICULTY_LEVEL, TXT_SET_TO, Difficulty_level));
535                 return 1;
536         }
537         return 0;
538 }
539
540 int     Max_debris_objects, Max_objects_onscreen_detailed;
541 int     Max_linear_depth_objects;
542
543 byte    Object_complexity=2, Object_detail=2;
544 byte    Wall_detail=2, Wall_render_depth=2, Debris_amount=2, SoundChannels = 2;
545
546 byte    Render_depths[NUM_DETAIL_LEVELS-1] =                        { 6,  9, 12, 15, 50};
547 byte    Max_perspective_depths[NUM_DETAIL_LEVELS-1] =               { 1,  2,  3,  5,  8};
548 byte    Max_linear_depths[NUM_DETAIL_LEVELS-1] =                    { 3,  5,  7, 10, 50};
549 byte    Max_linear_depths_objects[NUM_DETAIL_LEVELS-1] =            { 1,  2,  3,  7, 20};
550 byte    Max_debris_objects_list[NUM_DETAIL_LEVELS-1] =              { 2,  4,  7, 10, 15};
551 byte    Max_objects_onscreen_detailed_list[NUM_DETAIL_LEVELS-1] =   { 2,  4,  7, 10, 15};
552 byte    Smts_list[NUM_DETAIL_LEVELS-1] =                            { 2,  4,  8, 16, 50};   //      threshold for models to go to lower detail model, gets multiplied by obj->size
553 byte    Max_sound_channels[NUM_DETAIL_LEVELS-1] =                   { 2,  4,  8, 12, 16};
554
555 //      -----------------------------------------------------------------------------
556 //      Set detail level based stuff.
557 //      Note: Highest detail level (detail_level == NUM_DETAIL_LEVELS-1) is custom detail level.
558 void set_detail_level_parameters(int detail_level)
559 {
560         Assert((detail_level >= 0) && (detail_level < NUM_DETAIL_LEVELS));
561
562         if (detail_level < NUM_DETAIL_LEVELS-1) {
563                 Render_depth = Render_depths[detail_level];
564                 Max_perspective_depth = Max_perspective_depths[detail_level];
565                 Max_linear_depth = Max_linear_depths[detail_level];
566                 Max_linear_depth_objects = Max_linear_depths_objects[detail_level];
567
568                 Max_debris_objects = Max_debris_objects_list[detail_level];
569                 Max_objects_onscreen_detailed = Max_objects_onscreen_detailed_list[detail_level];
570
571                 Simple_model_threshhold_scale = Smts_list[detail_level];
572
573                 digi_set_max_channels( Max_sound_channels[ detail_level ] );
574
575                 //      Set custom menu defaults.
576                 Object_complexity = detail_level;
577                 Wall_render_depth = detail_level;
578                 Object_detail = detail_level;
579                 Wall_detail = detail_level;
580                 Debris_amount = detail_level;
581                 SoundChannels = detail_level;
582
583 #if defined(POLY_ACC)
584
585                 #ifdef MACINTOSH
586                         if (detail_level < 2)
587                         {
588                                 pa_set_filtering(0);
589                         }
590                         else if (detail_level < 4)
591                         {
592                                 pa_set_filtering(1);
593                         }
594                         else if (detail_level == 4)
595                         {
596                                 pa_set_filtering(2);
597                         }
598                 #else
599                         pa_filter_mode = detail_level;
600                 #endif
601 #endif
602
603         }
604 }
605
606 //      -----------------------------------------------------------------------------
607 void do_detail_level_menu(void)
608 {
609         int s;
610         newmenu_item m[8];
611
612         m[0].type=NM_TYPE_MENU; m[0].text=MENU_DETAIL_TEXT(0);
613         m[1].type=NM_TYPE_MENU; m[1].text=MENU_DETAIL_TEXT(1);
614         m[2].type=NM_TYPE_MENU; m[2].text=MENU_DETAIL_TEXT(2);
615         m[3].type=NM_TYPE_MENU; m[3].text=MENU_DETAIL_TEXT(3);
616         m[4].type=NM_TYPE_MENU; m[4].text=MENU_DETAIL_TEXT(4);
617         m[5].type=NM_TYPE_TEXT; m[5].text="";
618         m[6].type=NM_TYPE_MENU; m[6].text=MENU_DETAIL_TEXT(5);
619         m[7].type=NM_TYPE_CHECK; m[7].text="Show High Res movies"; m[7].value=MovieHires;
620
621         s = newmenu_do1( NULL, TXT_DETAIL_LEVEL , NDL+3, m, NULL, Detail_level);
622
623         if (s > -1 )    {
624                 switch (s)      {
625                         case 0:
626                         case 1:
627                         case 2:
628                         case 3:
629                         case 4:
630                                 Detail_level = s;
631                                 mprintf((0, "Detail level set to %i\n", Detail_level));
632                                 set_detail_level_parameters(Detail_level);
633                                 break;
634                         case 6:
635                                 Detail_level = 5;
636                                 do_detail_level_menu_custom();
637                                 break;
638                 }
639         }
640         MovieHires = m[7].value;
641 }
642
643 //      -----------------------------------------------------------------------------
644 void do_detail_level_menu_custom_menuset(int nitems, newmenu_item * items, int *last_key, int citem )
645 {
646         nitems = nitems;
647         *last_key = *last_key;
648         citem = citem;
649
650         Object_complexity = items[0].value;
651         Object_detail = items[1].value;
652         Wall_detail = items[2].value;
653         Wall_render_depth = items[3].value;
654         Debris_amount = items[4].value;
655         SoundChannels = items[5].value;
656 #if defined(POLY_ACC)
657         pa_filter_mode = items[6].value;
658 #endif
659
660 }
661
662 void set_custom_detail_vars(void)
663 {
664         Render_depth = Render_depths[Wall_render_depth];
665
666         Max_perspective_depth = Max_perspective_depths[Wall_detail];
667         Max_linear_depth = Max_linear_depths[Wall_detail];
668
669         Max_debris_objects = Max_debris_objects_list[Debris_amount];
670
671         Max_objects_onscreen_detailed = Max_objects_onscreen_detailed_list[Object_complexity];
672         Simple_model_threshhold_scale = Smts_list[Object_complexity];
673         Max_linear_depth_objects = Max_linear_depths_objects[Object_detail];
674
675         digi_set_max_channels( Max_sound_channels[ SoundChannels ] );
676         
677 }
678
679 #define DL_MAX  10
680
681 //      -----------------------------------------------------------------------------
682
683 void do_detail_level_menu_custom(void)
684 {
685         int     count;
686         int     s=0;
687         newmenu_item m[DL_MAX];
688         #if defined(POLY_ACC)
689         int filtering_id;
690         #endif
691
692         do {
693                 count = 0;
694                 m[count].type = NM_TYPE_SLIDER;
695                 m[count].text = TXT_OBJ_COMPLEXITY;
696                 m[count].value = Object_complexity;
697                 m[count].min_value = 0;
698                 m[count++].max_value = NDL-1;
699
700                 m[count].type = NM_TYPE_SLIDER;
701                 m[count].text = TXT_OBJ_DETAIL;
702                 m[count].value = Object_detail;
703                 m[count].min_value = 0;
704                 m[count++].max_value = NDL-1;
705
706                 m[count].type = NM_TYPE_SLIDER;
707                 m[count].text = TXT_WALL_DETAIL;
708                 m[count].value = Wall_detail;
709                 m[count].min_value = 0;
710                 m[count++].max_value = NDL-1;
711
712                 m[count].type = NM_TYPE_SLIDER;
713                 m[count].text = TXT_WALL_RENDER_DEPTH;
714                 m[count].value = Wall_render_depth;
715                 m[count].min_value = 0;
716                 m[count++].max_value = NDL-1;
717
718                 m[count].type = NM_TYPE_SLIDER;
719                 m[count].text= TXT_DEBRIS_AMOUNT;
720                 m[count].value = Debris_amount;
721                 m[count].min_value = 0;
722                 m[count++].max_value = NDL-1;
723
724                 m[count].type = NM_TYPE_SLIDER;
725                 m[count].text= TXT_SOUND_CHANNELS;
726                 m[count].value = SoundChannels;
727                 m[count].min_value = 0;
728                 m[count++].max_value = NDL-1;
729
730                 #if defined(POLY_ACC)
731                 MAC( if(PAEnabled){ )
732                         filtering_id = count;
733                         m[count].type = NM_TYPE_SLIDER;
734                         m[count].text= "FILTERING";
735                         m[count].value = pa_filter_mode;
736                         m[count].min_value = 0;
737                         #ifdef MACINTOSH
738                         m[count++].max_value = 2;
739                         #else
740                         m[count++].max_value = NDL-1;
741                         #endif
742                 MAC(})
743                 #endif
744
745                 m[count].type = NM_TYPE_TEXT;
746                 m[count++].text= TXT_LO_HI;
747
748                 Assert(count < DL_MAX);
749
750                 s = newmenu_do1( NULL, TXT_DETAIL_CUSTOM, count, m, do_detail_level_menu_custom_menuset, s);
751         } while (s > -1);
752
753         set_custom_detail_vars();
754
755         #if defined(MACINTOSH) && defined(POLY_ACC)
756         if ( PAEnabled )
757                 pa_set_filtering( m[filtering_id].value );
758         #endif
759 }
760
761 #ifndef MACINTOSH
762 int Default_display_mode=0;
763 int Current_display_mode=0;
764 #else
765 int Default_display_mode=1;
766 int Current_display_mode=1;
767 #endif
768
769 extern int MenuHiresAvailable;
770
771 typedef struct {
772         int     VGA_mode;
773         short   w,h;
774         short   render_method;
775         short   flags;
776 } dmi;
777
778 dmi display_mode_info[7] = {
779                 #ifdef WINDOWS
780                         {SM95_320x200x8X, 320, 200, VR_NONE, VRF_ALLOW_COCKPIT},
781                         {SM95_640x480x8, 640, 480, VR_NONE, VRF_COMPATIBLE_MENUS+VRF_ALLOW_COCKPIT},
782                         {SM95_640x400x8, 640, 400, VR_NONE, VRF_COMPATIBLE_MENUS }, 
783                         {SM95_800x600x8, 800, 600, VR_NONE, VRF_COMPATIBLE_MENUS },
784                         {SM95_1024x768x8, 1024, 768, VR_NONE, VRF_COMPATIBLE_MENUS }, 
785                 #else
786                         {SM(320,200),    320,   200, VR_NONE, VRF_ALLOW_COCKPIT+VRF_COMPATIBLE_MENUS}, 
787                         {SM(640,480),    640, 480, VR_NONE, VRF_COMPATIBLE_MENUS+VRF_ALLOW_COCKPIT},
788                         {SM(320,400),    320, 400, VR_NONE, VRF_USE_PAGING},
789                         {SM(640,400),    640, 400, VR_NONE, VRF_COMPATIBLE_MENUS}, 
790                         {SM(800,600),    800, 600, VR_NONE, VRF_COMPATIBLE_MENUS}, 
791                         {SM(1024,768),  1024,   768, VR_NONE, VRF_COMPATIBLE_MENUS},    
792                         {SM(1280,1024),1280,1024, VR_NONE, VRF_COMPATIBLE_MENUS}, 
793                 #endif
794 };
795  
796 WIN(extern int DD_Emulation);
797
798
799 void set_display_mode(int mode)
800 {
801         dmi *dmi;
802
803         if ((Current_display_mode == -1)||(VR_render_mode != VR_NONE))  //special VR mode
804                 return;                                                         //...don't change
805
806         #if !defined(MACINTOSH) && !defined(WINDOWS)
807         if (0) // (mode >= 5 && !FindArg("-superhires"))
808                 mode = 4;
809         #endif
810
811         if (!MenuHiresAvailable && (mode != 2))
812                 mode = 0;
813
814 #ifndef WINDOWS
815
816         if (gr_check_mode(display_mode_info[mode].VGA_mode) != 0)               //can't do mode
817                 #ifndef MACINTOSH
818                 mode = 0;
819                 #else
820                 mode = 1;
821                 #endif
822
823         Current_display_mode = mode;
824 #else
825         if (mode == 2) mode = 3;                                        // 320x400 -> 640x400.
826         Current_display_mode = mode;
827         if (mode >= 3) mode--;                                          // Match to Windows dmi.
828         if (DDCheckMode(display_mode_info[mode].VGA_mode)) {
829                 if (Platform_system == WINNT_PLATFORM || DD_Emulation) mode = 1;
830                 else mode = 0;
831                 Current_display_mode = mode;
832         }
833 #endif
834
835         dmi = &display_mode_info[mode];
836
837         if (Current_display_mode != -1) {
838
839                 game_init_render_buffers(dmi->VGA_mode,dmi->w,dmi->h,dmi->render_method,dmi->flags);
840                 Default_display_mode = Current_display_mode;
841         }
842
843         Screen_mode = -1;               //force screen reset
844 }
845
846 #ifdef MACINTOSH        // use Mac version of do_screen_res_menu
847
848 void do_screen_res_menu()
849 {
850         #define N_SCREENRES_ITEMS 6
851         
852         newmenu_item m[N_SCREENRES_ITEMS];
853         int citem, i, n_items, odisplay_mode, result;
854
855         if ((Current_display_mode == -1)||(VR_render_mode != VR_NONE))          //special VR mode
856         {                               
857                 nm_messagebox(TXT_SORRY, 1, TXT_OK, 
858                                 "You may not change screen\n"
859                                 "resolution when VR modes enabled.");
860                 return;
861         }
862
863         m[0].type=NM_TYPE_TEXT;  m[0].value=0; m[0].text="Modes w/ Cockpit:";
864         m[1].type=NM_TYPE_RADIO; m[1].value=0; m[1].group=0; m[1].text=" 640x480";
865         m[2].type=NM_TYPE_TEXT;  m[2].value=0; m[2].text="Modes w/o Cockpit:";
866         m[3].type=NM_TYPE_RADIO; m[3].value=0; m[3].group=0; m[3].text=" 800x600";
867 //      m[4].type=NM_TYPE_RADIO; m[4].value=0; m[4].group=0; m[4].text=" 1024x768";
868 //      m[5].type=NM_TYPE_RADIO; m[5].value=0; m[5].group=0; m[5].text=" 1280x1024";
869         n_items = 4;
870
871         odisplay_mode = VGA_current_mode;
872         citem = Current_display_mode;
873         if (Current_display_mode >= 2)
874                 citem--;
875
876         if (citem >= n_items)
877                 citem = n_items-1;
878
879         m[citem].value = 1;
880
881         newmenu_do1( NULL, "Select screen mode", n_items, m, NULL, citem);
882
883         for (i=0;i<n_items;i++)
884                 if (m[i].value)
885                         break;
886         if (i >= 3)
887                 i++;
888
889 #ifdef SHAREWARE
890         if (i > 1)
891                 nm_messagebox(TXT_SORRY, 1, TXT_OK, 
892                         "High resolution modes are\n"
893                         "only available in the\n"
894                         "Commercial version of Descent 2.");
895         return;
896 #else
897         result = vga_check_mode(display_mode_info[i].VGA_mode);
898         
899         if (result) {
900                 nm_messagebox(TXT_SORRY, 1, TXT_OK, 
901                                 "Cannot set requested\n"
902                                 "mode on this video card.");
903                 return;
904         }
905         
906         set_display_mode(i);
907         reset_cockpit();
908 #endif
909
910 }
911
912 #else   // PC version of do_screen_res_menu is below
913
914 void do_screen_res_menu()
915 {
916 #ifdef GR_SUPPORTS_FULLSCREEN_TOGGLE
917 #define N_SCREENRES_ITEMS 10
918         int fullscreenc;
919 #else
920         #define N_SCREENRES_ITEMS 9
921 #endif
922         newmenu_item m[N_SCREENRES_ITEMS];
923         int citem;
924         int i;
925         int n_items;
926
927         if ((Current_display_mode == -1)||(VR_render_mode != VR_NONE)) {                                //special VR mode
928                 nm_messagebox(TXT_SORRY, 1, TXT_OK, 
929                                 "You may not change screen\n"
930                                 "resolution when VR modes enabled.");
931                 return;
932         }
933
934         m[0].type=NM_TYPE_TEXT;  m[0].value=0;                            m[0].text="Modes w/ Cockpit:";
935         
936 #ifdef WINDOWS
937         if (Platform_system == WINNT_PLATFORM || DD_Emulation) {
938                 m[1].type=NM_TYPE_TEXT; m[1].value=0; m[1].text=" 320x200 N/A";
939         } else
940 #endif
941                 //NOTE LINK TO ABOVE IF
942                 m[1].type=NM_TYPE_RADIO; m[1].value=0; m[1].group=0; m[1].text=" 320x200";
943
944         m[2].type=NM_TYPE_RADIO; m[2].value=0; m[2].group=0; m[2].text=" 640x480";
945         m[3].type=NM_TYPE_TEXT;  m[3].value=0;                                    m[3].text="Modes w/o Cockpit:";
946 #ifdef WINDOWS
947         m[4].type=NM_TYPE_RADIO; m[4].value=0; m[4].group=0; m[4].text=" 640x400";
948         m[5].type=NM_TYPE_RADIO; m[5].value=0; m[5].group=0; m[5].text=" 800x600";
949 //      m[6].type=NM_TYPE_RADIO; m[6].value=0; m[6].group=0; m[6].text=" 1024x768";
950         n_items = 6;
951 #else
952         m[4].type=NM_TYPE_RADIO; m[4].value=0; m[4].group=0; m[4].text=" 320x400";
953         m[5].type=NM_TYPE_RADIO; m[5].value=0; m[5].group=0; m[5].text=" 640x400";
954         m[6].type=NM_TYPE_RADIO; m[6].value=0; m[6].group=0; m[6].text=" 800x600";
955         n_items = 7;
956         if (1) { //(FindArg("-superhires")) {
957                 m[7].type=NM_TYPE_RADIO; m[7].value=0; m[7].group=0; m[7].text=" 1024x768";
958                 m[8].type=NM_TYPE_RADIO; m[8].value=0; m[8].group=0; m[8].text=" 1280x1024";
959                 n_items += 2;
960         }
961 #endif
962
963 #ifdef GR_SUPPORTS_FULLSCREEN_TOGGLE
964         m[n_items].type = NM_TYPE_CHECK; m[n_items].text = "Fullscreen";
965         m[n_items].value = gr_check_fullscreen();
966         fullscreenc=n_items++;
967 #endif
968
969         citem = Current_display_mode+1;
970         
971 #ifdef WINDOWS
972         if (citem == 3) citem++;                                // if 320x400 in DOS, make it look like 640x400
973 #else
974         if (Current_display_mode >= 2)
975                 citem++;
976 #endif
977
978         if (citem >= n_items)
979                 citem = n_items-1;
980
981         m[citem].value = 1;
982
983         newmenu_do1( NULL, "Select screen mode", n_items, m, NULL, citem);
984
985 #ifdef GR_SUPPORTS_FULLSCREEN_TOGGLE
986         if (m[fullscreenc].value != gr_check_fullscreen()){
987             gr_toggle_fullscreen();
988         }
989 #endif
990
991         for (i=0;i<n_items;i++)
992                 if (m[i].value)
993                         break;
994
995 #ifndef WINDOWS                                                                 // if i >= 4 keep it that way since we skip 320x400
996         if (i >= 4)
997                 i--;
998 #endif
999
1000         i--;
1001
1002 #ifndef WINDOWS
1003         if (((i != 0) && (i != 2) && !MenuHiresAvailable) || gr_check_mode(display_mode_info[i].VGA_mode)) {
1004                 nm_messagebox(TXT_SORRY, 1, TXT_OK, 
1005                                 "Cannot set requested\n"
1006                                 "mode on this video card.");
1007                 return;
1008         }
1009 #else
1010         if (i >= 3) 
1011                 result = DDCheckMode(display_mode_info[i-1].VGA_mode);
1012         else 
1013                 result = DDCheckMode(display_mode_info[i].VGA_mode);
1014
1015         if (result) {
1016                 nm_messagebox(TXT_SORRY, 1, TXT_OK, 
1017                                 "Mode not supported by your\n"
1018                                 "DirectDraw driver.\n", 
1019                                 "Using default mode for gameplay.\n");
1020                 return;
1021         }
1022
1023 #endif
1024 #ifdef SHAREWARE
1025                 if (i != 0)
1026                         nm_messagebox(TXT_SORRY, 1, TXT_OK, 
1027                                 "High resolution modes are\n"
1028                                 "only available in the\n"
1029                                 "Commercial version of Descent 2.");
1030                 return;
1031 #else
1032                 if (i != Current_display_mode)
1033                         set_display_mode(i);
1034 #endif
1035
1036 }
1037 #endif  // end of PC version of do_screen_res_menu()
1038
1039
1040
1041 void do_new_game_menu()
1042 {
1043         int new_level_num,player_highest_level;
1044
1045 #ifndef SHAREWARE
1046         int n_missions;
1047
1048         n_missions = build_mission_list(0);
1049
1050         if (n_missions <= 1) {
1051                 load_mission(0);
1052         } else {
1053                 int new_mission_num,i, default_mission;
1054                 char * m[MAX_MISSIONS];
1055
1056                 default_mission = 0;
1057                 for (i=0;i<n_missions;i++) {
1058                         m[i] = Mission_list[i].mission_name;
1059                         if ( !stricmp( m[i], config_last_mission ) )
1060                                 default_mission = i;
1061                 }
1062
1063                 new_mission_num = newmenu_listbox1( "New Game\n\nSelect mission", n_missions, m, 1, default_mission, NULL );
1064
1065                 if (new_mission_num == -1)
1066                         return;         //abort!
1067
1068                 strcpy(config_last_mission, m[new_mission_num]  );
1069
1070                 if (!load_mission(new_mission_num)) {
1071                         nm_messagebox( NULL, 1, TXT_OK, "Error in Mission file"); 
1072                         return;
1073                 }
1074         }
1075 #endif
1076
1077         new_level_num = 1;
1078
1079         player_highest_level = get_highest_level();
1080
1081         if (player_highest_level > Last_level)
1082                 player_highest_level = Last_level;
1083
1084         if (player_highest_level > 1) {
1085                 newmenu_item m[4];
1086                 char info_text[80];
1087                 char num_text[10];
1088                 int choice;
1089                 int n_items;
1090
1091 try_again:
1092                 sprintf(info_text,"%s %d",TXT_START_ANY_LEVEL, player_highest_level);
1093
1094                 m[0].type=NM_TYPE_TEXT; m[0].text = info_text;
1095                 m[1].type=NM_TYPE_INPUT; m[1].text_len = 10; m[1].text = num_text;
1096                 n_items = 2;
1097
1098                 #ifdef WINDOWS
1099                 m[2].type = NM_TYPE_TEXT; m[2].text = "";
1100                 m[3].type = NM_TYPE_MENU; m[3].text = "          Ok";
1101                 n_items = 4;
1102                 #endif
1103
1104                 strcpy(num_text,"1");
1105
1106                 choice = newmenu_do( NULL, TXT_SELECT_START_LEV, n_items, m, NULL );
1107
1108                 if (choice==-1 || m[1].text[0]==0)
1109                         return;
1110
1111                 new_level_num = atoi(m[1].text);
1112
1113                 if (!(new_level_num>0 && new_level_num<=player_highest_level)) {
1114                         m[0].text = TXT_ENTER_TO_CONT;
1115                         nm_messagebox( NULL, 1, TXT_OK, TXT_INVALID_LEVEL); 
1116                         goto try_again;
1117                 }
1118         }
1119
1120         Difficulty_level = Player_default_difficulty;
1121
1122         if (!do_difficulty_menu())
1123                 return;
1124
1125         gr_palette_fade_out( gr_palette, 32, 0 );
1126         StartNewGame(new_level_num);
1127
1128 }
1129
1130 extern void GameLoop(int, int );
1131
1132 extern int Redbook_enabled;
1133
1134 void options_menuset(int nitems, newmenu_item * items, int *last_key, int citem )
1135 {
1136         if ( citem==5)
1137         {
1138                 gr_palette_set_gamma(items[5].value);
1139         }
1140
1141         nitems++;               //kill warning
1142         last_key++;             //kill warning
1143 }
1144
1145
1146 //added on 8/18/98 by Victor Rachels to add d1x options menu, maxfps setting
1147 //added/edited on 8/18/98 by Victor Rachels to set maxfps always on, max=80
1148 //added/edited on 9/7/98 by Victor Rachels to attempt dir browsing.  failed.
1149
1150 void d2x_options_menu_poll(int nitems, newmenu_item * menus, int * key, int citem)
1151 {
1152 }
1153
1154
1155 void d2x_options_menu()
1156 {
1157         newmenu_item m[14];
1158         int i=0;
1159         int opt = 0;
1160         int inputs, commands;
1161 #if 0
1162         int checks;
1163 #endif
1164
1165         char smaxfps[4];
1166 #if 0
1167         char shudmaxnumdisp[4];
1168         char thogdir[64];
1169         extern int gr_message_color_level;
1170
1171         sprintf(thogdir,AltHogDir);
1172 #endif
1173         sprintf(smaxfps,"%d",maxfps);
1174 #if 0
1175         sprintf(shudmaxnumdisp,"%d",HUD_max_num_disp);
1176
1177         m[opt].type = NM_TYPE_MENU;  m[opt].text = "Primary autoselect ordering...";   opt++;
1178         m[opt].type = NM_TYPE_MENU;  m[opt].text = "Secondary autoselect ordering..."; opt++;
1179 #endif
1180
1181         //added on 2/4/99 by Victor Rachels for new key menu
1182         m[opt].type = NM_TYPE_MENU;  m[opt].text = "D2X Keys"; opt++;
1183         //end this section addition - VR
1184
1185 #if 0
1186         //enabled 3/24/99 - Owen Evans
1187         m[opt].type = NM_TYPE_MENU;  m[opt].text = "Change Screen Resolution";         opt++;
1188         //end enabled stuff - OE
1189 #endif
1190
1191         commands=opt;
1192 #if 0
1193         //added on 2/2/99 by Victor Rachels for bans
1194 #ifdef NETWORK
1195         m[opt].type = NM_TYPE_MENU; m[opt].text = "Save bans now"; opt++;
1196 #endif
1197         //end this section addition - VR
1198 #endif // 0
1199
1200         m[opt].type = NM_TYPE_TEXT;  m[opt].text = "Maximum Framerate (1-80):";       opt++;
1201
1202
1203         inputs=opt;
1204         m[opt].type = NM_TYPE_INPUT; m[opt].text = smaxfps; m[opt].text_len=3;         opt++;
1205 #if 0
1206         m[opt].type = NM_TYPE_TEXT;  m[opt].text = "Mission Directory";                opt++;
1207         m[opt].type = NM_TYPE_INPUT; m[opt].text = thogdir; m[opt].text_len=64;        opt++;
1208         m[opt].type = NM_TYPE_TEXT;  m[opt].text = "Hud Messages lines (1-80):";       opt++;
1209         m[opt].type = NM_TYPE_INPUT; m[opt].text = shudmaxnumdisp; m[opt].text_len=3;  opt++;
1210         m[opt].type = NM_TYPE_SLIDER; m[opt].text = "Message colorization level"; m[opt].value=gr_message_color_level;m[opt].min_value=0;m[opt].max_value=3;  opt++;
1211         checks=opt;
1212 #ifdef __MSDOS__
1213         m[opt].type = NM_TYPE_CHECK; m[opt].text = "Joy is sidewinder"; m[opt].value=Joy_is_Sidewinder;  opt++;
1214 #endif
1215 #ifdef SUPPORTS_NICEFPS
1216         m[opt].type = NM_TYPE_CHECK; m[opt].text = "Nice FPS (free cpu cycles)"; m[opt].value = use_nice_fps; opt++;
1217 #endif
1218 #endif // 0
1219
1220         for(;;)
1221         {
1222         i=newmenu_do1( NULL, "D2X options", opt, m, &d2x_options_menu_poll, i);
1223
1224                 if(i>-1)
1225                 {
1226             if(i<commands)
1227                         {
1228                                 switch(i)
1229                                 {
1230 #if 0
1231                 case 0: reorder_primary(); break;
1232                 case 1: reorder_secondary(); break;
1233 #endif
1234                                         //added on 2/4/99 by Victor Rachels for new key menu
1235                 case 0: kconfig(4,"D2X Keys"); break;
1236                                         //end this section addition - VR
1237 #if 0
1238                                         //enabled 3/24/99 - Owen Evans
1239                 case 3: change_res(); break;
1240                                         //end enabled stuff - OE
1241 #endif
1242                                 }
1243                         }
1244
1245 #if 0
1246             //added on 2/4/99 by Victor Rachels for bans
1247 #ifdef NETWORK
1248             if(i==commands+0)
1249                         {              
1250
1251                                 nm_messagebox(NULL,1,TXT_OK, "%i Bans saved",writebans());
1252
1253                         }
1254 #endif
1255             //end this section addition - VR
1256 #endif // 0
1257
1258             if(i == inputs+0)
1259                         {
1260                                 maxfps = atoi(smaxfps);
1261                 if(maxfps < 1 || maxfps>80)
1262                                 {
1263                                         nm_messagebox(TXT_ERROR, 1, TXT_OK, "Invalid value for maximum framerate");
1264                                         maxfps = 80;
1265                                         i = (inputs+0);
1266                                 }
1267                         }
1268 #if 0
1269             else if(i==inputs+2)
1270                                 cfile_use_alternate_hogdir(thogdir);
1271                         else if(i==inputs+4)
1272                         {
1273                                 HUD_max_num_disp = atoi(shudmaxnumdisp);
1274                 if(HUD_max_num_disp < 1||HUD_max_num_disp>HUD_MAX_NUM)
1275                                 {
1276                                         nm_messagebox(TXT_ERROR, 1, TXT_OK, "Invalid value for hud lines");
1277                                         HUD_max_num_disp=4;
1278                                         //                   i=(inputs+4);//???
1279                                 }
1280                         }
1281                         gr_message_color_level=m[inputs+5].value;
1282
1283                         sprintf(shudmaxnumdisp,"%d",HUD_max_num_disp);
1284 #endif // 0
1285                         sprintf(smaxfps,"%d",maxfps);
1286                         //           m[inputs+0].text=smaxfps;//redundant.. its not going anywhere
1287 #if 0
1288                         sprintf(thogdir,AltHogDir);
1289                         //           m[inputs+2].text=thogdir;//redundant
1290 #endif
1291                 }
1292                 else
1293                         break;
1294         }
1295
1296 #if 0
1297         write_player_file();
1298
1299 #ifdef __MSDOS__
1300         Joy_is_Sidewinder=m[(checks+0)].value;
1301 #endif
1302 #ifdef __LINUX__
1303         Joy_is_Sidewinder=0;
1304 #endif
1305 #ifdef SUPPORTS_NICEFPS
1306         use_nice_fps=m[(checks+0)].value;
1307 #else
1308         use_nice_fps=0;
1309 #endif
1310 #endif // 0
1311 }
1312
1313 //end edit - Victor Rachels
1314 //end addition - Victor Rachels
1315
1316
1317 void do_options_menu()
1318 {
1319         newmenu_item m[13];
1320         int i = 0;
1321
1322         do {
1323                 m[ 0].type = NM_TYPE_MENU;   m[ 0].text="Sound effects & music...";
1324                 m[ 1].type = NM_TYPE_TEXT;   m[ 1].text="";
1325                 #if defined(MACINTOSH) && defined(APPLE_DEMO)
1326                 m [2].type = NM_TYPE_TEXT;   m[ 2].text="";
1327                 #else
1328                 m[ 2].type = NM_TYPE_MENU;   m[ 2].text=TXT_CONTROLS_;
1329                 #endif
1330         #ifdef WINDOWS
1331                 m[ 3].type = NM_TYPE_MENU;   m[ 3].text="INVOKE JOYSTICK CONTROL PANEL";
1332         #else
1333                 m[ 3].type = NM_TYPE_MENU;   m[ 3].text=TXT_CAL_JOYSTICK;
1334         #endif
1335                 m[ 4].type = NM_TYPE_TEXT;   m[ 4].text="";
1336
1337 #if defined(POLY_ACC)
1338         #ifdef MACINTOSH
1339
1340                 if ( !PAEnabled )
1341                 {
1342                         m[5].type               = NM_TYPE_SLIDER;
1343                         m[5].text               = TXT_BRIGHTNESS;
1344                         m[5].value              = gr_palette_get_gamma();
1345                         m[5].min_value  = 0;
1346                         m[5].max_value  = 8; 
1347                 }
1348                 else
1349                 {
1350                         m[ 5].type = NM_TYPE_TEXT;   m[ 5].text="";
1351                 }
1352         
1353         #else
1354                 m[ 5].type = NM_TYPE_TEXT;   m[ 5].text="";
1355         #endif
1356 #else
1357                 m[5].type = NM_TYPE_SLIDER;
1358                 m[5].text = TXT_BRIGHTNESS;
1359                 m[5].value = gr_palette_get_gamma();
1360                 m[5].min_value = 0;
1361                 m[5].max_value = 16; // CCA too dim, was 8;
1362 #endif
1363
1364
1365 #ifdef PA_3DFX_VOODOO
1366                 m[ 6].type = NM_TYPE_TEXT;   m[ 6].text="";
1367 #else
1368                 m[ 6].type = NM_TYPE_MENU;   m[ 6].text=TXT_DETAIL_LEVELS;
1369 #endif
1370
1371 #if defined(POLY_ACC)
1372                 m[ 7].type = NM_TYPE_TEXT;   m[ 7].text="";
1373 #else
1374                 #ifdef MACINTOSH
1375                         if ( gConfigInfo.mChangeResolution && !PAEnabled )
1376                         {
1377                                 m[ 7].type = NM_TYPE_MENU;   m[ 7].text="Screen resolution...";
1378                         }
1379                         else    // for when we are on a mac and no resolution switching allowed
1380                         {
1381                                 m[ 7].type = NM_TYPE_TEXT;   m[ 7].text="";
1382                         }
1383                 #else   // for PC's
1384                         m[ 7].type = NM_TYPE_MENU;   m[ 7].text="Screen resolution...";
1385                 #endif  // end of #ifdef macintosh
1386
1387 #endif
1388
1389                 m[ 8].type = NM_TYPE_TEXT;   m[ 8].text="";
1390                 m[ 9].type = NM_TYPE_MENU;   m[ 9].text="Primary autoselect ordering...";
1391                 m[10].type = NM_TYPE_MENU;   m[10].text="Secondary autoselect ordering...";
1392                 m[11].type = NM_TYPE_MENU;   m[11].text="Toggles...";
1393
1394                 m[12].type = NM_TYPE_MENU;   m[12].text="D2X options...";
1395
1396                 i = newmenu_do1( NULL, TXT_OPTIONS, sizeof(m)/sizeof(*m), m, options_menuset, i );
1397                         
1398                 switch(i)       {
1399                         case  0: do_sound_menu();                       break;
1400                         case  2: joydefs_config();                      break;
1401                         case  3: joydefs_calibrate();           break;
1402                         case  6: do_detail_level_menu();        break;
1403                         case  7: do_screen_res_menu();          break;
1404                         case  9: ReorderPrimary();                      break;
1405                         case 10: ReorderSecondary();            break;
1406                         case 11: do_toggles_menu();                     break;
1407                         case 12: d2x_options_menu();        break;
1408                 }
1409
1410         } while( i>-1 );
1411
1412         write_player_file();
1413 }
1414
1415 extern int Redbook_playing;
1416 void set_redbook_volume(int volume);
1417
1418 WIN(extern int RBCDROM_State);
1419 WIN(static BOOL windigi_driver_off=FALSE);
1420
1421 void sound_menuset(int nitems, newmenu_item * items, int *last_key, int citem )
1422 {
1423         nitems=nitems;          
1424         *last_key = *last_key;
1425
1426         if ( Config_digi_volume != items[0].value )     {
1427                 Config_digi_volume = items[0].value;
1428
1429                 #ifdef WINDOWS
1430                         if (windigi_driver_off) {
1431                                 digi_midi_wait();
1432                                 digi_init_digi();
1433                                 Sleep(500);
1434                                 windigi_driver_off = FALSE;
1435                         }
1436                 #endif                  
1437                 
1438                 #ifndef MACINTOSH
1439                         digi_set_digi_volume( (Config_digi_volume*32768)/8 );
1440                 #else
1441                         digi_set_digi_volume( (Config_digi_volume*256)/8 );
1442                 #endif
1443                 digi_play_sample_once( SOUND_DROP_BOMB, F1_0 );
1444         }
1445
1446 #ifdef WINDOWS
1447         if (!wmidi_support_volchange()) {
1448                 if (!items[1].value && Config_midi_volume) {
1449                         Config_midi_volume = 0;
1450                         digi_set_midi_volume(0);
1451                         digi_play_midi_song( NULL, NULL, NULL, 0 );
1452                 }
1453                 else if (Config_midi_volume == 0 && items[1].value) {
1454                         digi_set_midi_volume(64);
1455                         Config_midi_volume = 4;
1456                 }
1457         }
1458         else     // LINK TO BELOW IF
1459 #endif
1460         if (Config_midi_volume != items[1].value )   {
1461                 Config_midi_volume = items[1].value;
1462                 #ifdef WINDOWS
1463                         if (!windigi_driver_off) {
1464                                 Sleep(200);
1465                                 digi_close_digi();
1466                                 Sleep(100);
1467                                 windigi_driver_off = TRUE;
1468                         }
1469                 #endif
1470                 #ifndef MACINTOSH
1471                         digi_set_midi_volume( (Config_midi_volume*128)/8 );
1472                 #else
1473                         digi_set_midi_volume( (Config_midi_volume*256)/8 );
1474                 #endif
1475         }
1476 #ifdef MACINTOSH
1477         if (Config_master_volume != items[3].value ) {
1478                 Config_master_volume = items[3].value;
1479                 digi_set_master_volume( Config_master_volume );
1480                 digi_play_sample_once( SOUND_DROP_BOMB, F1_0 );
1481         }
1482 #endif
1483
1484         // don't enable redbook for a non-apple demo version of the shareware demo
1485         #if !defined(SHAREWARE) || ( defined(SHAREWARE) && defined(APPLE_DEMO) )
1486
1487         if (Config_redbook_volume != items[2].value )   {
1488                 Config_redbook_volume = items[2].value;
1489                 set_redbook_volume(Config_redbook_volume);
1490         }
1491
1492         if (items[4].value != (Redbook_playing!=0)) {
1493
1494                 if (items[4].value && FindArg("-noredbook")) {
1495                         nm_messagebox (TXT_SORRY,1,TXT_OK,"Redbook audio has been disabled\non the command line");
1496                         items[4].value = 0;
1497                         items[4].redraw = 1;
1498                 }
1499                 else {
1500                         Redbook_enabled = items[4].value;
1501
1502                         mprintf((1, "Redbook_enabled = %d\n", Redbook_enabled));
1503
1504                         if (Function_mode == FMODE_MENU)
1505                                 songs_play_song(SONG_TITLE,1);
1506                         else if (Function_mode == FMODE_GAME)
1507                                 songs_play_level_song( Current_level_num );
1508                         else
1509                                 Int3();
1510
1511                         if (items[4].value && !Redbook_playing) {
1512                         #ifdef WINDOWS
1513                                 if (RBCDROM_State == -1) 
1514                                         nm_messagebox (TXT_SORRY,1,TXT_OK,"Cannot start CD Music.\nAnother application is\nusing the CD player.\n");
1515                                 else // link to next code line!
1516                         #endif
1517                                 nm_messagebox (TXT_SORRY,1,TXT_OK,"Cannot start CD Music.  Insert\nyour Descent II CD and try again");
1518                                 items[4].value = 0;
1519                                 items[4].redraw = 1;
1520                         }
1521
1522                         items[1].type = (Redbook_playing?NM_TYPE_TEXT:NM_TYPE_SLIDER);
1523                         items[1].redraw = 1;
1524                         items[2].type = (Redbook_playing?NM_TYPE_SLIDER:NM_TYPE_TEXT);
1525                         items[2].redraw = 1;
1526
1527                 }
1528         }
1529
1530         #endif
1531
1532         citem++;                //kill warning
1533 }
1534
1535 void do_sound_menu()
1536 {
1537    newmenu_item m[6];
1538         int i = 0;
1539
1540  #ifdef WINDOWS
1541         extern BOOL DIGIDriverInit;
1542         if (!DIGIDriverInit) windigi_driver_off = TRUE;
1543         else windigi_driver_off = FALSE;
1544  #endif
1545
1546         do {
1547                 m[ 0].type = NM_TYPE_SLIDER; m[ 0].text=TXT_FX_VOLUME; m[0].value=Config_digi_volume;m[0].min_value=0; m[0].max_value=8; 
1548                 m[ 1].type = (Redbook_playing?NM_TYPE_TEXT:NM_TYPE_SLIDER); m[ 1].text="MIDI music volume"; m[1].value=Config_midi_volume;m[1].min_value=0; m[1].max_value=8;
1549
1550         #ifdef WINDOWS
1551                 if (!wmidi_support_volchange() && !Redbook_playing) {
1552                         m[1].type = NM_TYPE_CHECK;
1553                         m[1].text = "MIDI MUSIC";
1554                         if (Config_midi_volume) m[1].value = 1;
1555                 }
1556         #endif
1557
1558                 #ifdef SHAREWARE
1559                         m[ 2].type = NM_TYPE_TEXT; m[ 2].text="";
1560                         m[ 3].type = NM_TYPE_TEXT; m[ 3].text="";
1561                         m[ 4].type = NM_TYPE_TEXT; m[ 4].text="";
1562                         #ifdef MACINTOSH
1563                                 m[ 3].type = NM_TYPE_SLIDER; m[ 3].text="Sound Manager Volume"; m[3].value=Config_master_volume;m[3].min_value=0; m[3].max_value=8;
1564
1565                                 #ifdef APPLE_DEMO
1566                                         m[ 2].type = (Redbook_playing?NM_TYPE_SLIDER:NM_TYPE_TEXT); m[ 2].text="CD music volume"; m[2].value=Config_redbook_volume;m[2].min_value=0; m[2].max_value=8;
1567                                         m[ 4].type = NM_TYPE_CHECK;  m[ 4].text="CD Music (Redbook) enabled"; m[4].value=(Redbook_playing!=0);
1568                                 #endif
1569
1570                         #endif
1571
1572                 #else           // ifdef SHAREWARE
1573                         m[ 2].type = (Redbook_playing?NM_TYPE_SLIDER:NM_TYPE_TEXT); m[ 2].text="CD music volume"; m[2].value=Config_redbook_volume;m[2].min_value=0; m[2].max_value=8;
1574
1575                         #ifndef MACINTOSH
1576                                 m[ 3].type = NM_TYPE_TEXT; m[ 3].text="";
1577                         #else
1578                                 m[ 3].type = NM_TYPE_SLIDER; m[ 3].text="Sound Manager Volume"; m[3].value=Config_master_volume;m[3].min_value=0; m[3].max_value=8; 
1579                         #endif
1580                 
1581                         m[ 4].type = NM_TYPE_CHECK;  m[ 4].text="CD Music (Redbook) enabled"; m[4].value=(Redbook_playing!=0);
1582                 #endif
1583         
1584                 m[ 5].type = NM_TYPE_CHECK;  m[ 5].text=TXT_REVERSE_STEREO; m[5].value=Config_channels_reversed; 
1585                                 
1586                 i = newmenu_do1( NULL, "Sound Effects & Music", sizeof(m)/sizeof(*m), m, sound_menuset, i );
1587
1588                 Redbook_enabled = m[4].value;
1589                 Config_channels_reversed = m[5].value;
1590
1591         } while( i>-1 );
1592
1593 #ifdef WINDOWS
1594         if (windigi_driver_off) {
1595                 digi_midi_wait();
1596                 Sleep(500);
1597                 digi_init_digi();
1598                 windigi_driver_off=FALSE;
1599         }
1600 #endif
1601
1602
1603         if ( Config_midi_volume < 1 )   {
1604                 #ifndef MACINTOSH
1605                         digi_play_midi_song( NULL, NULL, NULL, 0 );
1606                 #else
1607                         digi_play_midi_song(-1, 0);
1608                 #endif
1609         }
1610
1611 }
1612
1613
1614 extern int Automap_always_hires;
1615
1616 #define ADD_CHECK(n,txt,v)  do { m[n].type=NM_TYPE_CHECK; m[n].text=txt; m[n].value=v;} while (0)
1617
1618 void do_toggles_menu()
1619 {
1620 #ifndef MACINTOSH
1621 #if defined(POLY_ACC)
1622         #define N_TOGGLE_ITEMS 6        // get rid of automap hi-res.
1623 #else
1624         #define N_TOGGLE_ITEMS 7
1625 #endif
1626 #else
1627         #define N_TOGGLE_ITEMS 7
1628 #endif
1629         newmenu_item m[N_TOGGLE_ITEMS];
1630         int i = 0;
1631
1632         do {
1633                 #if defined(MACINTOSH) && defined(USE_ISP)
1634                         if (ISpEnabled())
1635                         {
1636                                 m[0].type = NM_TYPE_TEXT; m[0].text = "";
1637                         }
1638                         else
1639                         {
1640                                 ADD_CHECK(0, "Ship auto-leveling", Auto_leveling_on);
1641                         }
1642                 #else 
1643                         ADD_CHECK(0, "Ship auto-leveling", Auto_leveling_on);
1644                 #endif
1645                 ADD_CHECK(1, "Show reticle", Reticle_on);
1646                 ADD_CHECK(2, "Missile view", Missile_view_enabled);
1647                 ADD_CHECK(3, "Headlight on when picked up", Headlight_active_default );
1648                 ADD_CHECK(4, "Show guided missile in main display", Guided_in_big_window );
1649                 ADD_CHECK(5, "Escort robot hot keys",EscortHotKeys);
1650                 #ifdef MACINTOSH
1651                         if ( !PAEnabled ) {
1652                                 ADD_CHECK(6, "Pixel Double", Scanline_double);
1653                         }
1654                 #else
1655 #if !defined(POLY_ACC)
1656                         ADD_CHECK(6, "Always show HighRes Automap", min(MenuHiresAvailable,Automap_always_hires));
1657 #endif
1658                 #endif
1659                 //when adding more options, change N_TOGGLE_ITEMS above
1660
1661                 #ifdef MACINTOSH
1662                 if ( PAEnabled )                // when doing RAVE, no pixel doubling
1663                         i = newmenu_do1( NULL, "Toggles", N_TOGGLE_ITEMS-1, m, NULL, i );
1664                 else
1665                 #endif          // note link to if
1666                         i = newmenu_do1( NULL, "Toggles", N_TOGGLE_ITEMS, m, NULL, i );
1667                         
1668                 Auto_leveling_on                        = m[0].value;
1669                 Reticle_on                                      = m[1].value;
1670                 Missile_view_enabled            = m[2].value;
1671                 Headlight_active_default        = m[3].value;
1672                 Guided_in_big_window            = m[4].value;
1673                 EscortHotKeys                           = m[5].value;
1674
1675
1676                 #ifdef MACINTOSH
1677                         if ( !PAEnabled )
1678                                 Scanline_double = m[6].value;
1679                 #else
1680 #if !defined(POLY_ACC)
1681                         if (MenuHiresAvailable)
1682                                 Automap_always_hires = m[6].value;
1683                         else if (m[6].value)
1684                                 nm_messagebox(TXT_SORRY,1,"OK","High Resolution modes are\nnot available on this video card");
1685 #endif
1686                 #endif
1687
1688         } while( i>-1 );
1689
1690 }
1691
1692 void do_multi_player_menu()
1693 {
1694         int menu_choice[5];
1695         newmenu_item m[5];
1696         int choice = 0, num_options = 0;
1697         int old_game_mode;
1698
1699         do {
1700 //              WIN(ipx_destroy_read_thread());
1701
1702                 old_game_mode = Game_mode;
1703                 num_options = 0;
1704
1705                 if (!FindArg("-udp")) {
1706                         ADD_ITEM(TXT_START_IPX_NET_GAME, MENU_START_IPX_NETGAME, -1 );
1707                         ADD_ITEM(TXT_JOIN_IPX_NET_GAME, MENU_JOIN_IPX_NETGAME, -1 );
1708                 } else {
1709                         ADD_ITEM(TXT_START_TCP_NET_GAME, MENU_START_TCP_NETGAME, -1 );
1710                         ADD_ITEM(TXT_JOIN_TCP_NET_GAME, MENU_JOIN_TCP_NETGAME, -1 );
1711                 }
1712
1713         #ifdef MACINTOSH
1714                 ADD_ITEM("Start Appletalk Netgame", MENU_START_APPLETALK_NETGAME, -1 );
1715                 ADD_ITEM("Join Appletalk Netgame\n", MENU_JOIN_APPLETALK_NETGAME, -1 );
1716         #endif
1717
1718                 ADD_ITEM(TXT_MODEM_GAME, MENU_START_SERIAL, -1);
1719
1720                 choice = newmenu_do1( NULL, TXT_MULTIPLAYER, num_options, m, NULL, choice );
1721                 
1722                 if ( choice > -1 )      
1723                         do_option(menu_choice[choice]);
1724         
1725                 if (old_game_mode != Game_mode)
1726                         break;          // leave menu
1727
1728         } while( choice > -1 );
1729
1730 }
1731
1732 void DoNewIPAddress ()
1733  {
1734   newmenu_item m[4];
1735   char IPText[30];
1736   int choice;
1737
1738   m[0].type=NM_TYPE_TEXT; m[0].text = "Enter an address or hostname:";
1739   m[1].type=NM_TYPE_INPUT; m[1].text_len = 50; m[1].text = IPText;
1740   IPText[0]=0;
1741
1742   choice = newmenu_do( NULL, "Join a TCPIP game", 2, m, NULL );
1743
1744   if (choice==-1 || m[1].text[0]==0)
1745    return;
1746
1747   nm_messagebox (TXT_SORRY,1,TXT_OK,"That address is not valid!");
1748  }