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