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