changed args_find to FindArg
[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         #define N_SCREENRES_ITEMS 9
901         newmenu_item m[N_SCREENRES_ITEMS];
902         int citem;
903         int i;
904         int n_items;
905
906         if ((Current_display_mode == -1)||(VR_render_mode != VR_NONE)) {                                //special VR mode
907                 nm_messagebox(TXT_SORRY, 1, TXT_OK, 
908                                 "You may not change screen\n"
909                                 "resolution when VR modes enabled.");
910                 return;
911         }
912
913         m[0].type=NM_TYPE_TEXT;  m[0].value=0;                            m[0].text="Modes w/ Cockpit:";
914         
915 #ifdef WINDOWS
916         if (Platform_system == WINNT_PLATFORM || DD_Emulation) {
917                 m[1].type=NM_TYPE_TEXT; m[1].value=0; m[1].text=" 320x200 N/A";
918         } else
919 #endif
920                 //NOTE LINK TO ABOVE IF
921                 m[1].type=NM_TYPE_RADIO; m[1].value=0; m[1].group=0; m[1].text=" 320x200";
922
923         m[2].type=NM_TYPE_RADIO; m[2].value=0; m[2].group=0; m[2].text=" 640x480";
924         m[3].type=NM_TYPE_TEXT;  m[3].value=0;                                    m[3].text="Modes w/o Cockpit:";
925 #ifdef WINDOWS
926         m[4].type=NM_TYPE_RADIO; m[4].value=0; m[4].group=0; m[4].text=" 640x400";
927         m[5].type=NM_TYPE_RADIO; m[5].value=0; m[5].group=0; m[5].text=" 800x600";
928 //      m[6].type=NM_TYPE_RADIO; m[6].value=0; m[6].group=0; m[6].text=" 1024x768";
929         n_items = 6;
930 #else
931         m[4].type=NM_TYPE_RADIO; m[4].value=0; m[4].group=0; m[4].text=" 320x400";
932         m[5].type=NM_TYPE_RADIO; m[5].value=0; m[5].group=0; m[5].text=" 640x480";
933         m[6].type=NM_TYPE_RADIO; m[6].value=0; m[6].group=0; m[6].text=" 800x600";
934         n_items = 7;
935         if (FindArg("-superhires")) {
936                 m[7].type=NM_TYPE_RADIO; m[7].value=0; m[7].group=0; m[7].text=" 1024x768";
937                 m[8].type=NM_TYPE_RADIO; m[8].value=0; m[8].group=0; m[8].text=" 1280x1024";
938                 n_items += 2;
939         }
940 #endif
941
942         citem = Current_display_mode+1;
943         
944 #ifdef WINDOWS
945         if (citem == 3) citem++;                                // if 320x400 in DOS, make it look like 640x400
946 #else
947         if (Current_display_mode >= 2)
948                 citem++;
949 #endif
950
951         if (citem >= n_items)
952                 citem = n_items-1;
953
954         m[citem].value = 1;
955
956         newmenu_do1( NULL, "Select screen mode", n_items, m, NULL, citem);
957
958         for (i=0;i<n_items;i++)
959                 if (m[i].value)
960                         break;
961
962 #ifndef WINDOWS                                                                 // if i >= 4 keep it that way since we skip 320x400
963         if (i >= 4)
964                 i--;
965 #endif
966
967         i--;
968
969 #ifndef WINDOWS
970         if (((i != 0) && (i != 2) && !MenuHiresAvailable) || gr_check_mode(display_mode_info[i].VGA_mode)) {
971                 nm_messagebox(TXT_SORRY, 1, TXT_OK, 
972                                 "Cannot set requested\n"
973                                 "mode on this video card.");
974                 return;
975         }
976 #else
977         if (i >= 3) 
978                 result = DDCheckMode(display_mode_info[i-1].VGA_mode);
979         else 
980                 result = DDCheckMode(display_mode_info[i].VGA_mode);
981
982         if (result) {
983                 nm_messagebox(TXT_SORRY, 1, TXT_OK, 
984                                 "Mode not supported by your\n"
985                                 "DirectDraw driver.\n", 
986                                 "Using default mode for gameplay.\n");
987                 return;
988         }
989
990 #endif
991         #ifdef SHAREWARE
992                 if (i != 0)
993                         nm_messagebox(TXT_SORRY, 1, TXT_OK, 
994                                 "High resolution modes are\n"
995                                 "only available in the\n"
996                                 "Commercial version of Descent 2.");
997                 return;
998         #else
999                 if (i != Current_display_mode)
1000                         set_display_mode(i);
1001         #endif
1002
1003 }
1004 #endif  // end of PC version of do_screen_res_menu()
1005
1006
1007
1008 void do_new_game_menu()
1009 {
1010         int new_level_num,player_highest_level;
1011
1012 #ifndef SHAREWARE
1013         int n_missions;
1014
1015         n_missions = build_mission_list(0);
1016
1017         if (n_missions > 1) {
1018                 int new_mission_num,i, default_mission;
1019                 char * m[MAX_MISSIONS];
1020
1021                 default_mission = 0;
1022                 for (i=0;i<n_missions;i++) {
1023                         m[i] = Mission_list[i].mission_name;
1024                         if ( !stricmp( m[i], config_last_mission ) )    
1025                                 default_mission = i;
1026                 }
1027
1028                 new_mission_num = newmenu_listbox1( "New Game\n\nSelect mission", n_missions, m, 1, default_mission, NULL );
1029
1030                 if (new_mission_num == -1)
1031                         return;         //abort!
1032
1033                 strcpy(config_last_mission, m[new_mission_num]  );
1034                 
1035                 if (!load_mission(new_mission_num)) {
1036                         nm_messagebox( NULL, 1, TXT_OK, "Error in Mission file"); 
1037                         return;
1038                 }
1039         }
1040 #endif
1041
1042         new_level_num = 1;
1043
1044         player_highest_level = get_highest_level();
1045
1046         if (player_highest_level > Last_level)
1047                 player_highest_level = Last_level;
1048
1049         if (player_highest_level > 1) {
1050                 newmenu_item m[4];
1051                 char info_text[80];
1052                 char num_text[10];
1053                 int choice;
1054                 int n_items;
1055
1056 try_again:
1057                 sprintf(info_text,"%s %d",TXT_START_ANY_LEVEL, player_highest_level);
1058
1059                 m[0].type=NM_TYPE_TEXT; m[0].text = info_text;
1060                 m[1].type=NM_TYPE_INPUT; m[1].text_len = 10; m[1].text = num_text;
1061                 n_items = 2;
1062
1063                 #ifdef WINDOWS
1064                 m[2].type = NM_TYPE_TEXT; m[2].text = "";
1065                 m[3].type = NM_TYPE_MENU; m[3].text = "          Ok";
1066                 n_items = 4;
1067                 #endif
1068
1069                 strcpy(num_text,"1");
1070
1071                 choice = newmenu_do( NULL, TXT_SELECT_START_LEV, n_items, m, NULL );
1072
1073                 if (choice==-1 || m[1].text[0]==0)
1074                         return;
1075
1076                 new_level_num = atoi(m[1].text);
1077
1078                 if (!(new_level_num>0 && new_level_num<=player_highest_level)) {
1079                         m[0].text = TXT_ENTER_TO_CONT;
1080                         nm_messagebox( NULL, 1, TXT_OK, TXT_INVALID_LEVEL); 
1081                         goto try_again;
1082                 }
1083         }
1084
1085         Difficulty_level = Player_default_difficulty;
1086
1087         if (!do_difficulty_menu())
1088                 return;
1089
1090         gr_palette_fade_out( gr_palette, 32, 0 );
1091         StartNewGame(new_level_num);
1092
1093 }
1094
1095 extern void GameLoop(int, int );
1096
1097 extern int Redbook_enabled;
1098
1099 void options_menuset(int nitems, newmenu_item * items, int *last_key, int citem )
1100 {
1101         if ( citem==5)
1102         {
1103                 gr_palette_set_gamma(items[5].value);
1104         }
1105
1106         nitems++;               //kill warning
1107         last_key++;             //kill warning
1108 }
1109
1110 void do_options_menu()
1111 {
1112    newmenu_item m[12];
1113         int i = 0;
1114
1115         do {
1116                 m[ 0].type = NM_TYPE_MENU;   m[ 0].text="Sound effects & music...";
1117                 m[ 1].type = NM_TYPE_TEXT;   m[ 1].text="";
1118                 #if defined(MACINTOSH) && defined(APPLE_DEMO)
1119                 m [2].type = NM_TYPE_TEXT;   m[ 2].text="";
1120                 #else
1121                 m[ 2].type = NM_TYPE_MENU;   m[ 2].text=TXT_CONTROLS_;
1122                 #endif
1123         #ifdef WINDOWS
1124                 m[ 3].type = NM_TYPE_MENU;   m[ 3].text="INVOKE JOYSTICK CONTROL PANEL";
1125         #else
1126                 m[ 3].type = NM_TYPE_MENU;   m[ 3].text=TXT_CAL_JOYSTICK;
1127         #endif
1128                 m[ 4].type = NM_TYPE_TEXT;   m[ 4].text="";
1129
1130 #if defined(POLY_ACC)
1131         #ifdef MACINTOSH
1132
1133                 if ( !PAEnabled )
1134                 {
1135                         m[5].type               = NM_TYPE_SLIDER;
1136                         m[5].text               = TXT_BRIGHTNESS;
1137                         m[5].value              = gr_palette_get_gamma();
1138                         m[5].min_value  = 0;
1139                         m[5].max_value  = 8; 
1140                 }
1141                 else
1142                 {
1143                         m[ 5].type = NM_TYPE_TEXT;   m[ 5].text="";
1144                 }
1145         
1146         #else
1147                 m[ 5].type = NM_TYPE_TEXT;   m[ 5].text="";
1148         #endif
1149 #else
1150                 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; 
1151 #endif
1152
1153
1154 #ifdef PA_3DFX_VOODOO
1155                 m[ 6].type = NM_TYPE_TEXT;   m[ 6].text="";
1156 #else
1157                 m[ 6].type = NM_TYPE_MENU;   m[ 6].text=TXT_DETAIL_LEVELS;
1158 #endif
1159
1160 #if defined(POLY_ACC)
1161                 m[ 7].type = NM_TYPE_TEXT;   m[ 7].text="";
1162 #else
1163                 #ifdef MACINTOSH
1164                         if ( gConfigInfo.mChangeResolution && !PAEnabled )
1165                         {
1166                                 m[ 7].type = NM_TYPE_MENU;   m[ 7].text="Screen resolution...";
1167                         }
1168                         else    // for when we are on a mac and no resolution switching allowed
1169                         {
1170                                 m[ 7].type = NM_TYPE_TEXT;   m[ 7].text="";
1171                         }
1172                 #else   // for PC's
1173                         m[ 7].type = NM_TYPE_MENU;   m[ 7].text="Screen resolution...";
1174                 #endif  // end of #ifdef macintosh
1175
1176 #endif
1177
1178                 m[ 8].type = NM_TYPE_TEXT;   m[ 8].text="";
1179                 m[ 9].type = NM_TYPE_MENU;   m[ 9].text="Primary autoselect ordering...";
1180                 m[10].type = NM_TYPE_MENU;   m[10].text="Secondary autoselect ordering...";
1181                 m[11].type = NM_TYPE_MENU;   m[11].text="Toggles...";
1182                                 
1183                 i = newmenu_do1( NULL, TXT_OPTIONS, sizeof(m)/sizeof(*m), m, options_menuset, i );
1184                         
1185                 switch(i)       {
1186                         case  0: do_sound_menu();                       break;
1187                         case  2: joydefs_config();                      break;
1188                         case  3: joydefs_calibrate();           break;
1189                         case  6: do_detail_level_menu();        break;
1190                         case  7: do_screen_res_menu();          break;
1191                         case  9: ReorderPrimary();                      break;
1192                         case 10: ReorderSecondary();            break;
1193                         case 11: do_toggles_menu();                     break;
1194                 }
1195
1196         } while( i>-1 );
1197
1198         write_player_file();
1199 }
1200
1201 extern int Redbook_playing;
1202 void set_redbook_volume(int volume);
1203
1204 WIN(extern int RBCDROM_State);
1205 WIN(static BOOL windigi_driver_off=FALSE);
1206
1207 void sound_menuset(int nitems, newmenu_item * items, int *last_key, int citem )
1208 {
1209         nitems=nitems;          
1210         *last_key = *last_key;
1211
1212         if ( Config_digi_volume != items[0].value )     {
1213                 Config_digi_volume = items[0].value;
1214
1215                 #ifdef WINDOWS
1216                         if (windigi_driver_off) {
1217                                 digi_midi_wait();
1218                                 digi_init_digi();
1219                                 Sleep(500);
1220                                 windigi_driver_off = FALSE;
1221                         }
1222                 #endif                  
1223                 
1224                 #ifndef MACINTOSH
1225                         digi_set_digi_volume( (Config_digi_volume*32768)/8 );
1226                 #else
1227                         digi_set_digi_volume( (Config_digi_volume*256)/8 );
1228                 #endif
1229                 digi_play_sample_once( SOUND_DROP_BOMB, F1_0 );
1230         }
1231
1232 #ifdef WINDOWS
1233         if (!wmidi_support_volchange()) {
1234                 if (!items[1].value && Config_midi_volume) {
1235                         Config_midi_volume = 0;
1236                         digi_set_midi_volume(0);
1237                         digi_play_midi_song( NULL, NULL, NULL, 0 );
1238                 }
1239                 else if (Config_midi_volume == 0 && items[1].value) {
1240                         digi_set_midi_volume(64);
1241                         Config_midi_volume = 4;
1242                 }
1243         }
1244         else     // LINK TO BELOW IF
1245 #endif
1246         if (Config_midi_volume != items[1].value )   {
1247                 Config_midi_volume = items[1].value;
1248                 #ifdef WINDOWS
1249                         if (!windigi_driver_off) {
1250                                 Sleep(200);
1251                                 digi_close_digi();
1252                                 Sleep(100);
1253                                 windigi_driver_off = TRUE;
1254                         }
1255                 #endif
1256                 #ifndef MACINTOSH
1257                         digi_set_midi_volume( (Config_midi_volume*128)/8 );
1258                 #else
1259                         digi_set_midi_volume( (Config_midi_volume*256)/8 );
1260                 #endif
1261         }
1262 #ifdef MACINTOSH
1263         if (Config_master_volume != items[3].value ) {
1264                 Config_master_volume = items[3].value;
1265                 digi_set_master_volume( Config_master_volume );
1266                 digi_play_sample_once( SOUND_DROP_BOMB, F1_0 );
1267         }
1268 #endif
1269
1270         // don't enable redbook for a non-apple demo version of the shareware demo
1271         #if !defined(SHAREWARE) || ( defined(SHAREWARE) && defined(APPLE_DEMO) )
1272                 
1273         if (Config_redbook_volume != items[2].value )   {
1274                 Config_redbook_volume = items[2].value;
1275                 set_redbook_volume(Config_redbook_volume);
1276         }
1277
1278         if (items[4].value != (Redbook_playing!=0)) {
1279
1280                 if (items[4].value && FindArg("-noredbook")) {
1281                         nm_messagebox (TXT_SORRY,1,TXT_OK,"Redbook audio has been disabled\non the command line");
1282                         items[4].value = 0;
1283                         items[4].redraw = 1;
1284                 }
1285                 else {
1286                         Redbook_enabled = items[4].value;
1287
1288                         mprintf((1, "Redbook_enabled = %d\n", Redbook_enabled));
1289
1290                         if (Function_mode == FMODE_MENU)
1291                                 songs_play_song(SONG_TITLE,1);
1292                         else if (Function_mode == FMODE_GAME)
1293                                 songs_play_level_song( Current_level_num );
1294                         else
1295                                 Int3();
1296
1297                         if (items[4].value && !Redbook_playing) {
1298                         #ifdef WINDOWS
1299                                 if (RBCDROM_State == -1) 
1300                                         nm_messagebox (TXT_SORRY,1,TXT_OK,"Cannot start CD Music.\nAnother application is\nusing the CD player.\n");
1301                                 else // link to next code line!
1302                         #endif
1303                                 nm_messagebox (TXT_SORRY,1,TXT_OK,"Cannot start CD Music.  Insert\nyour Descent II CD and try again");
1304                                 items[4].value = 0;
1305                                 items[4].redraw = 1;
1306                         }
1307
1308                         items[1].type = (Redbook_playing?NM_TYPE_TEXT:NM_TYPE_SLIDER);
1309                         items[1].redraw = 1;
1310                         items[2].type = (Redbook_playing?NM_TYPE_SLIDER:NM_TYPE_TEXT);
1311                         items[2].redraw = 1;
1312
1313                 }
1314         }
1315
1316         #endif
1317
1318         citem++;                //kill warning
1319 }
1320
1321 void do_sound_menu()
1322 {
1323    newmenu_item m[6];
1324         int i = 0;
1325
1326  #ifdef WINDOWS
1327         extern BOOL DIGIDriverInit;
1328         if (!DIGIDriverInit) windigi_driver_off = TRUE;
1329         else windigi_driver_off = FALSE;
1330  #endif
1331
1332         do {
1333                 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; 
1334                 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; 
1335
1336         #ifdef WINDOWS
1337                 if (!wmidi_support_volchange() && !Redbook_playing) {
1338                         m[1].type = NM_TYPE_CHECK; 
1339                         m[1].text = "MIDI MUSIC";
1340                         if (Config_midi_volume) m[1].value = 1;
1341                 }
1342         #endif
1343
1344                 #ifdef SHAREWARE
1345                         m[ 2].type = NM_TYPE_TEXT; m[ 2].text="";
1346                         m[ 3].type = NM_TYPE_TEXT; m[ 3].text="";
1347                         m[ 4].type = NM_TYPE_TEXT; m[ 4].text="";
1348                         #ifdef MACINTOSH
1349                                 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; 
1350                 
1351                                 #ifdef APPLE_DEMO
1352                                         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;
1353                                         m[ 4].type = NM_TYPE_CHECK;  m[ 4].text="CD Music (Redbook) enabled"; m[4].value=(Redbook_playing!=0);
1354                                 #endif
1355                 
1356                         #endif
1357
1358                 #else           // ifdef SHAREWARE
1359                         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;
1360
1361                         #ifndef MACINTOSH
1362                                 m[ 3].type = NM_TYPE_TEXT; m[ 3].text="";
1363                         #else
1364                                 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; 
1365                         #endif
1366                 
1367                         m[ 4].type = NM_TYPE_CHECK;  m[ 4].text="CD Music (Redbook) enabled"; m[4].value=(Redbook_playing!=0);
1368                 #endif
1369         
1370                 m[ 5].type = NM_TYPE_CHECK;  m[ 5].text=TXT_REVERSE_STEREO; m[5].value=Config_channels_reversed; 
1371                                 
1372                 i = newmenu_do1( NULL, "Sound Effects & Music", sizeof(m)/sizeof(*m), m, sound_menuset, i );
1373
1374                 Redbook_enabled = m[4].value;
1375                 Config_channels_reversed = m[5].value;
1376
1377         } while( i>-1 );
1378
1379 #ifdef WINDOWS
1380         if (windigi_driver_off) {
1381                 digi_midi_wait();
1382                 Sleep(500);
1383                 digi_init_digi();
1384                 windigi_driver_off=FALSE;
1385         }
1386 #endif
1387
1388
1389         if ( Config_midi_volume < 1 )   {
1390                 #ifndef MACINTOSH
1391                         digi_play_midi_song( NULL, NULL, NULL, 0 );
1392                 #else
1393                         digi_play_midi_song(-1, 0);
1394                 #endif
1395         }
1396
1397 }
1398
1399
1400 extern int Automap_always_hires;
1401
1402 #define ADD_CHECK(n,txt,v)  do { m[n].type=NM_TYPE_CHECK; m[n].text=txt; m[n].value=v;} while (0)
1403
1404 void do_toggles_menu()
1405 {
1406 #ifndef MACINTOSH
1407 #if defined(POLY_ACC)
1408         #define N_TOGGLE_ITEMS 6        // get rid of automap hi-res.
1409 #else
1410         #define N_TOGGLE_ITEMS 7
1411 #endif
1412 #else
1413         #define N_TOGGLE_ITEMS 7
1414 #endif
1415         newmenu_item m[N_TOGGLE_ITEMS];
1416         int i = 0;
1417
1418         do {
1419                 #if defined(MACINTOSH) && defined(USE_ISP)
1420                         if (ISpEnabled())
1421                         {
1422                                 m[0].type = NM_TYPE_TEXT; m[0].text = "";
1423                         }
1424                         else
1425                         {
1426                                 ADD_CHECK(0, "Ship auto-leveling", Auto_leveling_on);
1427                         }
1428                 #else 
1429                         ADD_CHECK(0, "Ship auto-leveling", Auto_leveling_on);
1430                 #endif
1431                 ADD_CHECK(1, "Show reticle", Reticle_on);
1432                 ADD_CHECK(2, "Missile view", Missile_view_enabled);
1433                 ADD_CHECK(3, "Headlight on when picked up", Headlight_active_default );
1434                 ADD_CHECK(4, "Show guided missile in main display", Guided_in_big_window );
1435                 ADD_CHECK(5, "Escort robot hot keys",EscortHotKeys);
1436                 #ifdef MACINTOSH
1437                         if ( !PAEnabled ) {
1438                                 ADD_CHECK(6, "Pixel Double", Scanline_double);
1439                         }
1440                 #else
1441 #if !defined(POLY_ACC)
1442                         ADD_CHECK(6, "Always show HighRes Automap", min(MenuHiresAvailable,Automap_always_hires));
1443 #endif
1444                 #endif
1445                 //when adding more options, change N_TOGGLE_ITEMS above
1446
1447                 #ifdef MACINTOSH
1448                 if ( PAEnabled )                // when doing RAVE, no pixel doubling
1449                         i = newmenu_do1( NULL, "Toggles", N_TOGGLE_ITEMS-1, m, NULL, i );
1450                 else
1451                 #endif          // note link to if
1452                         i = newmenu_do1( NULL, "Toggles", N_TOGGLE_ITEMS, m, NULL, i );
1453                         
1454                 Auto_leveling_on                        = m[0].value;
1455                 Reticle_on                                      = m[1].value;
1456                 Missile_view_enabled            = m[2].value;
1457                 Headlight_active_default        = m[3].value;
1458                 Guided_in_big_window            = m[4].value;
1459                 EscortHotKeys                           = m[5].value;
1460
1461
1462                 #ifdef MACINTOSH
1463                         if ( !PAEnabled )
1464                                 Scanline_double = m[6].value;
1465                 #else
1466 #if !defined(POLY_ACC)
1467                         if (MenuHiresAvailable)
1468                                 Automap_always_hires = m[6].value;
1469                         else if (m[6].value)
1470                                 nm_messagebox(TXT_SORRY,1,"OK","High Resolution modes are\nnot available on this video card");
1471 #endif
1472                 #endif
1473
1474         } while( i>-1 );
1475
1476 }
1477
1478 void do_multi_player_menu()
1479 {
1480         int menu_choice[5];
1481         newmenu_item m[5];
1482         int choice = 0, num_options = 0;
1483         int old_game_mode;
1484
1485         do {
1486 //              WIN(ipx_destroy_read_thread());
1487
1488                 old_game_mode = Game_mode;
1489                 num_options = 0;
1490
1491                 ADD_ITEM(TXT_START_IPX_NET_GAME, MENU_START_IPX_NETGAME, -1 );
1492                 ADD_ITEM(TXT_JOIN_IPX_NET_GAME, MENU_JOIN_IPX_NETGAME, -1 );
1493               //  ADD_ITEM(TXT_START_TCP_NET_GAME, MENU_START_TCP_NETGAME, -1 );
1494               //  ADD_ITEM(TXT_JOIN_TCP_NET_GAME, MENU_JOIN_TCP_NETGAME, -1 );
1495
1496         #ifdef MACINTOSH
1497                 ADD_ITEM("Start Appletalk Netgame", MENU_START_APPLETALK_NETGAME, -1 );
1498                 ADD_ITEM("Join Appletalk Netgame\n", MENU_JOIN_APPLETALK_NETGAME, -1 );
1499         #endif
1500
1501                 ADD_ITEM(TXT_MODEM_GAME, MENU_START_SERIAL, -1);
1502
1503                 choice = newmenu_do1( NULL, TXT_MULTIPLAYER, num_options, m, NULL, choice );
1504                 
1505                 if ( choice > -1 )      
1506                         do_option(menu_choice[choice]);
1507         
1508                 if (old_game_mode != Game_mode)
1509                         break;          // leave menu
1510
1511         } while( choice > -1 );
1512
1513 }
1514
1515 void DoNewIPAddress ()
1516  {
1517   newmenu_item m[4];
1518   char IPText[30];
1519   int choice;
1520
1521   m[0].type=NM_TYPE_TEXT; m[0].text = "Enter an address or hostname:";
1522   m[1].type=NM_TYPE_INPUT; m[1].text_len = 50; m[1].text = IPText;
1523   IPText[0]=0;
1524
1525   choice = newmenu_do( NULL, "Join a TCPIP game", 2, m, NULL );
1526
1527   if (choice==-1 || m[1].text[0]==0)
1528    return;
1529
1530   nm_messagebox (TXT_SORRY,1,TXT_OK,"That address is not valid!");
1531  }
1532
1533
1534   
1535