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