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