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