also look in shared data dir for demos
[btb/d2x.git] / main / menu.c
1 /* $Id: menu.c,v 1.22 2003-03-17 07:59:11 btb Exp $ */
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, DEMO_DIR "*.dem", demo_file, 1 ))
374                                 newdemo_start_playback(demo_file);
375                         break;
376                 }
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                 case MENU_START_TCP_NETGAME:
450                         load_mission(Builtin_mission_num);
451                         #ifdef MACINTOSH
452                         Network_game_type = IPX_GAME;
453                         #endif
454 //                      WIN(ipx_create_read_thread());
455                         network_start_game();
456                         break;
457
458                 case MENU_JOIN_IPX_NETGAME:
459                 case MENU_JOIN_TCP_NETGAME:
460                         load_mission(Builtin_mission_num);
461                         #ifdef MACINTOSH
462                         Network_game_type = IPX_GAME;
463                         #endif
464 //                      WIN(ipx_create_read_thread());
465                         network_join_game();
466                         break;
467
468 #ifdef MACINTOSH
469                 case MENU_START_APPLETALK_NETGAME:
470                         load_mission(Builtin_mission_num);
471                         #ifdef MACINTOSH
472                         Network_game_type = APPLETALK_GAME;
473                         #endif
474                         network_start_game();
475                         break;
476
477                 case MENU_JOIN_APPLETALK_NETGAME:
478                         load_mission(Builtin_mission_num);
479                         #ifdef MACINTOSH
480                         Network_game_type = APPLETALK_GAME;
481                         #endif
482                         network_join_game();
483                         break;
484 #endif
485 #if 0
486                 case MENU_START_TCP_NETGAME:
487                 case MENU_JOIN_TCP_NETGAME:
488                         nm_messagebox (TXT_SORRY,1,TXT_OK,"Not available in shareware version!");
489                         // DoNewIPAddress();
490                         break;
491 #endif
492                 case MENU_START_SERIAL:
493                         com_main_menu();
494                         break;
495                 case MENU_MULTIPLAYER:
496                         do_multi_player_menu();
497                         break;
498 #endif //NETWORK
499                 case MENU_CONFIG:
500                         do_options_menu();
501                         break;
502                 case MENU_SHOW_CREDITS:
503                         gr_palette_fade_out( gr_palette,32,0);
504                         songs_stop_all();
505                         credits_show(NULL); 
506                         break;
507                 default:
508                         Error("Unknown option %d in do_option",select);
509                         break;
510         }
511
512 }
513
514 int do_difficulty_menu()
515 {
516         int s;
517         newmenu_item m[5];
518
519         m[0].type=NM_TYPE_MENU; m[0].text=MENU_DIFFICULTY_TEXT(0);
520         m[1].type=NM_TYPE_MENU; m[1].text=MENU_DIFFICULTY_TEXT(1);
521         m[2].type=NM_TYPE_MENU; m[2].text=MENU_DIFFICULTY_TEXT(2);
522         m[3].type=NM_TYPE_MENU; m[3].text=MENU_DIFFICULTY_TEXT(3);
523         m[4].type=NM_TYPE_MENU; m[4].text=MENU_DIFFICULTY_TEXT(4);
524
525         s = newmenu_do1( NULL, TXT_DIFFICULTY_LEVEL, NDL, m, NULL, Difficulty_level);
526
527         if (s > -1 )    {
528                 if (s != Difficulty_level)
529                 {       
530                         Player_default_difficulty = s;
531                         write_player_file();
532                 }
533                 Difficulty_level = s;
534                 mprintf((0, "%s %s %i\n", TXT_DIFFICULTY_LEVEL, TXT_SET_TO, Difficulty_level));
535                 return 1;
536         }
537         return 0;
538 }
539
540 int     Max_debris_objects, Max_objects_onscreen_detailed;
541 int     Max_linear_depth_objects;
542
543 byte    Object_complexity=2, Object_detail=2;
544 byte    Wall_detail=2, Wall_render_depth=2, Debris_amount=2, SoundChannels = 2;
545
546 byte    Render_depths[NUM_DETAIL_LEVELS-1] =                        { 6,  9, 12, 15, 50};
547 byte    Max_perspective_depths[NUM_DETAIL_LEVELS-1] =               { 1,  2,  3,  5,  8};
548 byte    Max_linear_depths[NUM_DETAIL_LEVELS-1] =                    { 3,  5,  7, 10, 50};
549 byte    Max_linear_depths_objects[NUM_DETAIL_LEVELS-1] =            { 1,  2,  3,  7, 20};
550 byte    Max_debris_objects_list[NUM_DETAIL_LEVELS-1] =              { 2,  4,  7, 10, 15};
551 byte    Max_objects_onscreen_detailed_list[NUM_DETAIL_LEVELS-1] =   { 2,  4,  7, 10, 15};
552 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
553 byte    Max_sound_channels[NUM_DETAIL_LEVELS-1] =                   { 2,  4,  8, 12, 16};
554
555 //      -----------------------------------------------------------------------------
556 //      Set detail level based stuff.
557 //      Note: Highest detail level (detail_level == NUM_DETAIL_LEVELS-1) is custom detail level.
558 void set_detail_level_parameters(int detail_level)
559 {
560         Assert((detail_level >= 0) && (detail_level < NUM_DETAIL_LEVELS));
561
562         if (detail_level < NUM_DETAIL_LEVELS-1) {
563                 Render_depth = Render_depths[detail_level];
564                 Max_perspective_depth = Max_perspective_depths[detail_level];
565                 Max_linear_depth = Max_linear_depths[detail_level];
566                 Max_linear_depth_objects = Max_linear_depths_objects[detail_level];
567
568                 Max_debris_objects = Max_debris_objects_list[detail_level];
569                 Max_objects_onscreen_detailed = Max_objects_onscreen_detailed_list[detail_level];
570
571                 Simple_model_threshhold_scale = Smts_list[detail_level];
572
573                 digi_set_max_channels( Max_sound_channels[ detail_level ] );
574
575                 //      Set custom menu defaults.
576                 Object_complexity = detail_level;
577                 Wall_render_depth = detail_level;
578                 Object_detail = detail_level;
579                 Wall_detail = detail_level;
580                 Debris_amount = detail_level;
581                 SoundChannels = detail_level;
582
583 #if defined(POLY_ACC)
584
585                 #ifdef MACINTOSH
586                         if (detail_level < 2)
587                         {
588                                 pa_set_filtering(0);
589                         }
590                         else if (detail_level < 4)
591                         {
592                                 pa_set_filtering(1);
593                         }
594                         else if (detail_level == 4)
595                         {
596                                 pa_set_filtering(2);
597                         }
598                 #else
599                         pa_filter_mode = detail_level;
600                 #endif
601 #endif
602
603         }
604 }
605
606 //      -----------------------------------------------------------------------------
607 void do_detail_level_menu(void)
608 {
609         int s;
610         newmenu_item m[7];
611
612         m[0].type=NM_TYPE_MENU; m[0].text=MENU_DETAIL_TEXT(0);
613         m[1].type=NM_TYPE_MENU; m[1].text=MENU_DETAIL_TEXT(1);
614         m[2].type=NM_TYPE_MENU; m[2].text=MENU_DETAIL_TEXT(2);
615         m[3].type=NM_TYPE_MENU; m[3].text=MENU_DETAIL_TEXT(3);
616         m[4].type=NM_TYPE_MENU; m[4].text=MENU_DETAIL_TEXT(4);
617         m[5].type=NM_TYPE_TEXT; m[5].text="";
618         m[6].type=NM_TYPE_MENU; m[6].text=MENU_DETAIL_TEXT(5);
619
620         s = newmenu_do1( NULL, TXT_DETAIL_LEVEL , NDL+2, m, NULL, Detail_level);
621
622         if (s > -1 )    {
623                 switch (s)      {
624                         case 0:
625                         case 1:
626                         case 2:
627                         case 3:
628                         case 4:
629                                 Detail_level = s;
630                                 mprintf((0, "Detail level set to %i\n", Detail_level));
631                                 set_detail_level_parameters(Detail_level);
632                                 break;
633                         case 6:
634                                 Detail_level = 5;
635                                 do_detail_level_menu_custom();
636                                 break;
637                 }
638         }
639
640 }
641
642 //      -----------------------------------------------------------------------------
643 void do_detail_level_menu_custom_menuset(int nitems, newmenu_item * items, int *last_key, int citem )
644 {
645         nitems = nitems;
646         *last_key = *last_key;
647         citem = citem;
648
649         Object_complexity = items[0].value;
650         Object_detail = items[1].value;
651         Wall_detail = items[2].value;
652         Wall_render_depth = items[3].value;
653         Debris_amount = items[4].value;
654         SoundChannels = items[5].value;
655 #if defined(POLY_ACC)
656         pa_filter_mode = items[6].value;
657 #endif
658
659 }
660
661 void set_custom_detail_vars(void)
662 {
663         Render_depth = Render_depths[Wall_render_depth];
664
665         Max_perspective_depth = Max_perspective_depths[Wall_detail];
666         Max_linear_depth = Max_linear_depths[Wall_detail];
667
668         Max_debris_objects = Max_debris_objects_list[Debris_amount];
669
670         Max_objects_onscreen_detailed = Max_objects_onscreen_detailed_list[Object_complexity];
671         Simple_model_threshhold_scale = Smts_list[Object_complexity];
672         Max_linear_depth_objects = Max_linear_depths_objects[Object_detail];
673
674         digi_set_max_channels( Max_sound_channels[ SoundChannels ] );
675         
676 }
677
678 #define DL_MAX  10
679
680 //      -----------------------------------------------------------------------------
681
682 void do_detail_level_menu_custom(void)
683 {
684         int     count;
685         int     s=0;
686         newmenu_item m[DL_MAX];
687         #if defined(POLY_ACC)
688         int filtering_id;
689         #endif
690
691         do {
692                 count = 0;
693                 m[count].type = NM_TYPE_SLIDER;
694                 m[count].text = TXT_OBJ_COMPLEXITY;
695                 m[count].value = Object_complexity;
696                 m[count].min_value = 0;
697                 m[count++].max_value = NDL-1;
698
699                 m[count].type = NM_TYPE_SLIDER;
700                 m[count].text = TXT_OBJ_DETAIL;
701                 m[count].value = Object_detail;
702                 m[count].min_value = 0;
703                 m[count++].max_value = NDL-1;
704
705                 m[count].type = NM_TYPE_SLIDER;
706                 m[count].text = TXT_WALL_DETAIL;
707                 m[count].value = Wall_detail;
708                 m[count].min_value = 0;
709                 m[count++].max_value = NDL-1;
710
711                 m[count].type = NM_TYPE_SLIDER;
712                 m[count].text = TXT_WALL_RENDER_DEPTH;
713                 m[count].value = Wall_render_depth;
714                 m[count].min_value = 0;
715                 m[count++].max_value = NDL-1;
716
717                 m[count].type = NM_TYPE_SLIDER;
718                 m[count].text= TXT_DEBRIS_AMOUNT;
719                 m[count].value = Debris_amount;
720                 m[count].min_value = 0;
721                 m[count++].max_value = NDL-1;
722
723                 m[count].type = NM_TYPE_SLIDER;
724                 m[count].text= TXT_SOUND_CHANNELS;
725                 m[count].value = SoundChannels;
726                 m[count].min_value = 0;
727                 m[count++].max_value = NDL-1;
728
729                 #if defined(POLY_ACC)
730                 MAC( if(PAEnabled){ )
731                         filtering_id = count;
732                         m[count].type = NM_TYPE_SLIDER;
733                         m[count].text= "FILTERING";
734                         m[count].value = pa_filter_mode;
735                         m[count].min_value = 0;
736                         #ifdef MACINTOSH
737                         m[count++].max_value = 2;
738                         #else
739                         m[count++].max_value = NDL-1;
740                         #endif
741                 MAC(})
742                 #endif
743
744                 m[count].type = NM_TYPE_TEXT;
745                 m[count++].text= TXT_LO_HI;
746
747                 Assert(count < DL_MAX);
748
749                 s = newmenu_do1( NULL, TXT_DETAIL_CUSTOM, count, m, do_detail_level_menu_custom_menuset, s);
750         } while (s > -1);
751
752         set_custom_detail_vars();
753
754         #if defined(MACINTOSH) && defined(POLY_ACC)
755         if ( PAEnabled )
756                 pa_set_filtering( m[filtering_id].value );
757         #endif
758 }
759
760 #ifndef MACINTOSH
761 int Default_display_mode=0;
762 int Current_display_mode=0;
763 #else
764 int Default_display_mode=1;
765 int Current_display_mode=1;
766 #endif
767
768 extern int MenuHiresAvailable;
769
770 typedef struct {
771         int     VGA_mode;
772         short   w,h;
773         short   render_method;
774         short   flags;
775 } dmi;
776
777 dmi display_mode_info[7] = {
778                 #ifdef WINDOWS
779                         {SM95_320x200x8X, 320, 200, VR_NONE, VRF_ALLOW_COCKPIT},
780                         {SM95_640x480x8, 640, 480, VR_NONE, VRF_COMPATIBLE_MENUS+VRF_ALLOW_COCKPIT},
781                         {SM95_640x400x8, 640, 400, VR_NONE, VRF_COMPATIBLE_MENUS }, 
782                         {SM95_800x600x8, 800, 600, VR_NONE, VRF_COMPATIBLE_MENUS },
783                         {SM95_1024x768x8, 1024, 768, VR_NONE, VRF_COMPATIBLE_MENUS }, 
784                 #else
785                         {SM(320,200),    320,   200, VR_NONE, VRF_ALLOW_COCKPIT+VRF_COMPATIBLE_MENUS}, 
786                         {SM(640,480),    640, 480, VR_NONE, VRF_COMPATIBLE_MENUS+VRF_ALLOW_COCKPIT},
787                         {SM(320,400),    320, 400, VR_NONE, VRF_USE_PAGING},
788                         {SM(640,400),    640, 400, VR_NONE, VRF_COMPATIBLE_MENUS}, 
789                         {SM(800,600),    800, 600, VR_NONE, VRF_COMPATIBLE_MENUS}, 
790                         {SM(1024,768),  1024,   768, VR_NONE, VRF_COMPATIBLE_MENUS},    
791                         {SM(1280,1024),1280,1024, VR_NONE, VRF_COMPATIBLE_MENUS}, 
792                 #endif
793 };
794  
795 WIN(extern int DD_Emulation);
796
797
798 void set_display_mode(int mode)
799 {
800         dmi *dmi;
801
802         if ((Current_display_mode == -1)||(VR_render_mode != VR_NONE))  //special VR mode
803                 return;                                                         //...don't change
804
805         #if !defined(MACINTOSH) && !defined(WINDOWS)
806         if (0) // (mode >= 5 && !FindArg("-superhires"))
807                 mode = 4;
808         #endif
809
810         if (!MenuHiresAvailable && (mode != 2))
811                 mode = 0;
812
813 #ifndef WINDOWS
814
815         if (gr_check_mode(display_mode_info[mode].VGA_mode) != 0)               //can't do mode
816                 #ifndef MACINTOSH
817                 mode = 0;
818                 #else
819                 mode = 1;
820                 #endif
821
822         Current_display_mode = mode;
823 #else
824         if (mode == 2) mode = 3;                                        // 320x400 -> 640x400.
825         Current_display_mode = mode;
826         if (mode >= 3) mode--;                                          // Match to Windows dmi.
827         if (DDCheckMode(display_mode_info[mode].VGA_mode)) {
828                 if (Platform_system == WINNT_PLATFORM || DD_Emulation) mode = 1;
829                 else mode = 0;
830                 Current_display_mode = mode;
831         }
832 #endif
833
834         dmi = &display_mode_info[mode];
835
836         if (Current_display_mode != -1) {
837
838                 game_init_render_buffers(dmi->VGA_mode,dmi->w,dmi->h,dmi->render_method,dmi->flags);
839                 Default_display_mode = Current_display_mode;
840         }
841
842         Screen_mode = -1;               //force screen reset
843 }
844
845 #ifdef MACINTOSH        // use Mac version of do_screen_res_menu
846
847 void do_screen_res_menu()
848 {
849         #define N_SCREENRES_ITEMS 6
850         
851         newmenu_item m[N_SCREENRES_ITEMS];
852         int citem, i, n_items, odisplay_mode, result;
853
854         if ((Current_display_mode == -1)||(VR_render_mode != VR_NONE))          //special VR mode
855         {                               
856                 nm_messagebox(TXT_SORRY, 1, TXT_OK, 
857                                 "You may not change screen\n"
858                                 "resolution when VR modes enabled.");
859                 return;
860         }
861
862         m[0].type=NM_TYPE_TEXT;  m[0].value=0; m[0].text="Modes w/ Cockpit:";
863         m[1].type=NM_TYPE_RADIO; m[1].value=0; m[1].group=0; m[1].text=" 640x480";
864         m[2].type=NM_TYPE_TEXT;  m[2].value=0; m[2].text="Modes w/o Cockpit:";
865         m[3].type=NM_TYPE_RADIO; m[3].value=0; m[3].group=0; m[3].text=" 800x600";
866 //      m[4].type=NM_TYPE_RADIO; m[4].value=0; m[4].group=0; m[4].text=" 1024x768";
867 //      m[5].type=NM_TYPE_RADIO; m[5].value=0; m[5].group=0; m[5].text=" 1280x1024";
868         n_items = 4;
869
870         odisplay_mode = VGA_current_mode;
871         citem = Current_display_mode;
872         if (Current_display_mode >= 2)
873                 citem--;
874
875         if (citem >= n_items)
876                 citem = n_items-1;
877
878         m[citem].value = 1;
879
880         newmenu_do1( NULL, "Select screen mode", n_items, m, NULL, citem);
881
882         for (i=0;i<n_items;i++)
883                 if (m[i].value)
884                         break;
885         if (i >= 3)
886                 i++;
887
888 #ifdef SHAREWARE
889         if (i > 1)
890                 nm_messagebox(TXT_SORRY, 1, TXT_OK, 
891                         "High resolution modes are\n"
892                         "only available in the\n"
893                         "Commercial version of Descent 2.");
894         return;
895 #else
896         result = vga_check_mode(display_mode_info[i].VGA_mode);
897         
898         if (result) {
899                 nm_messagebox(TXT_SORRY, 1, TXT_OK, 
900                                 "Cannot set requested\n"
901                                 "mode on this video card.");
902                 return;
903         }
904         
905         set_display_mode(i);
906         reset_cockpit();
907 #endif
908
909 }
910
911 #else   // PC version of do_screen_res_menu is below
912
913 void do_screen_res_menu()
914 {
915 #ifdef GR_SUPPORTS_FULLSCREEN_TOGGLE
916 #define N_SCREENRES_ITEMS 10
917         int fullscreenc;
918 #else
919         #define N_SCREENRES_ITEMS 9
920 #endif
921         newmenu_item m[N_SCREENRES_ITEMS];
922         int citem;
923         int i;
924         int n_items;
925
926         if ((Current_display_mode == -1)||(VR_render_mode != VR_NONE)) {                                //special VR mode
927                 nm_messagebox(TXT_SORRY, 1, TXT_OK, 
928                                 "You may not change screen\n"
929                                 "resolution when VR modes enabled.");
930                 return;
931         }
932
933         m[0].type=NM_TYPE_TEXT;  m[0].value=0;                            m[0].text="Modes w/ Cockpit:";
934         
935 #ifdef WINDOWS
936         if (Platform_system == WINNT_PLATFORM || DD_Emulation) {
937                 m[1].type=NM_TYPE_TEXT; m[1].value=0; m[1].text=" 320x200 N/A";
938         } else
939 #endif
940                 //NOTE LINK TO ABOVE IF
941                 m[1].type=NM_TYPE_RADIO; m[1].value=0; m[1].group=0; m[1].text=" 320x200";
942
943         m[2].type=NM_TYPE_RADIO; m[2].value=0; m[2].group=0; m[2].text=" 640x480";
944         m[3].type=NM_TYPE_TEXT;  m[3].value=0;                                    m[3].text="Modes w/o Cockpit:";
945 #ifdef WINDOWS
946         m[4].type=NM_TYPE_RADIO; m[4].value=0; m[4].group=0; m[4].text=" 640x400";
947         m[5].type=NM_TYPE_RADIO; m[5].value=0; m[5].group=0; m[5].text=" 800x600";
948 //      m[6].type=NM_TYPE_RADIO; m[6].value=0; m[6].group=0; m[6].text=" 1024x768";
949         n_items = 6;
950 #else
951         m[4].type=NM_TYPE_RADIO; m[4].value=0; m[4].group=0; m[4].text=" 320x400";
952         m[5].type=NM_TYPE_RADIO; m[5].value=0; m[5].group=0; m[5].text=" 640x400";
953         m[6].type=NM_TYPE_RADIO; m[6].value=0; m[6].group=0; m[6].text=" 800x600";
954         n_items = 7;
955         if (1) { //(FindArg("-superhires")) {
956                 m[7].type=NM_TYPE_RADIO; m[7].value=0; m[7].group=0; m[7].text=" 1024x768";
957                 m[8].type=NM_TYPE_RADIO; m[8].value=0; m[8].group=0; m[8].text=" 1280x1024";
958                 n_items += 2;
959         }
960 #endif
961
962 #ifdef GR_SUPPORTS_FULLSCREEN_TOGGLE
963         m[n_items].type = NM_TYPE_CHECK; m[n_items].text = "Fullscreen";
964         m[n_items].value = gr_check_fullscreen();
965         fullscreenc=n_items++;
966 #endif
967
968         citem = Current_display_mode+1;
969         
970 #ifdef WINDOWS
971         if (citem == 3) citem++;                                // if 320x400 in DOS, make it look like 640x400
972 #else
973         if (Current_display_mode >= 2)
974                 citem++;
975 #endif
976
977         if (citem >= n_items)
978                 citem = n_items-1;
979
980         m[citem].value = 1;
981
982         newmenu_do1( NULL, "Select screen mode", n_items, m, NULL, citem);
983
984 #ifdef GR_SUPPORTS_FULLSCREEN_TOGGLE
985         if (m[fullscreenc].value != gr_check_fullscreen()){
986             gr_toggle_fullscreen();
987         }
988 #endif
989
990         for (i=0;i<n_items;i++)
991                 if (m[i].value)
992                         break;
993
994 #ifndef WINDOWS                                                                 // if i >= 4 keep it that way since we skip 320x400
995         if (i >= 4)
996                 i--;
997 #endif
998
999         i--;
1000
1001 #ifndef WINDOWS
1002         if (((i != 0) && (i != 2) && !MenuHiresAvailable) || gr_check_mode(display_mode_info[i].VGA_mode)) {
1003                 nm_messagebox(TXT_SORRY, 1, TXT_OK, 
1004                                 "Cannot set requested\n"
1005                                 "mode on this video card.");
1006                 return;
1007         }
1008 #else
1009         if (i >= 3) 
1010                 result = DDCheckMode(display_mode_info[i-1].VGA_mode);
1011         else 
1012                 result = DDCheckMode(display_mode_info[i].VGA_mode);
1013
1014         if (result) {
1015                 nm_messagebox(TXT_SORRY, 1, TXT_OK, 
1016                                 "Mode not supported by your\n"
1017                                 "DirectDraw driver.\n", 
1018                                 "Using default mode for gameplay.\n");
1019                 return;
1020         }
1021
1022 #endif
1023 #ifdef SHAREWARE
1024                 if (i != 0)
1025                         nm_messagebox(TXT_SORRY, 1, TXT_OK, 
1026                                 "High resolution modes are\n"
1027                                 "only available in the\n"
1028                                 "Commercial version of Descent 2.");
1029                 return;
1030 #else
1031                 if (i != Current_display_mode)
1032                         set_display_mode(i);
1033 #endif
1034
1035 }
1036 #endif  // end of PC version of do_screen_res_menu()
1037
1038
1039
1040 void do_new_game_menu()
1041 {
1042         int new_level_num,player_highest_level;
1043
1044 #ifndef SHAREWARE
1045         int n_missions;
1046
1047         n_missions = build_mission_list(0);
1048
1049         if (n_missions <= 1) {
1050                 load_mission(0);
1051         } else {
1052                 int new_mission_num,i, default_mission;
1053                 char * m[MAX_MISSIONS];
1054
1055                 default_mission = 0;
1056                 for (i=0;i<n_missions;i++) {
1057                         m[i] = Mission_list[i].mission_name;
1058                         if ( !stricmp( m[i], config_last_mission ) )
1059                                 default_mission = i;
1060                 }
1061
1062                 new_mission_num = newmenu_listbox1( "New Game\n\nSelect mission", n_missions, m, 1, default_mission, NULL );
1063
1064                 if (new_mission_num == -1)
1065                         return;         //abort!
1066
1067                 strcpy(config_last_mission, m[new_mission_num]  );
1068
1069                 if (!load_mission(new_mission_num)) {
1070                         nm_messagebox( NULL, 1, TXT_OK, "Error in Mission file"); 
1071                         return;
1072                 }
1073         }
1074 #endif
1075
1076         new_level_num = 1;
1077
1078         player_highest_level = get_highest_level();
1079
1080         if (player_highest_level > Last_level)
1081                 player_highest_level = Last_level;
1082
1083         if (player_highest_level > 1) {
1084                 newmenu_item m[4];
1085                 char info_text[80];
1086                 char num_text[10];
1087                 int choice;
1088                 int n_items;
1089
1090 try_again:
1091                 sprintf(info_text,"%s %d",TXT_START_ANY_LEVEL, player_highest_level);
1092
1093                 m[0].type=NM_TYPE_TEXT; m[0].text = info_text;
1094                 m[1].type=NM_TYPE_INPUT; m[1].text_len = 10; m[1].text = num_text;
1095                 n_items = 2;
1096
1097                 #ifdef WINDOWS
1098                 m[2].type = NM_TYPE_TEXT; m[2].text = "";
1099                 m[3].type = NM_TYPE_MENU; m[3].text = "          Ok";
1100                 n_items = 4;
1101                 #endif
1102
1103                 strcpy(num_text,"1");
1104
1105                 choice = newmenu_do( NULL, TXT_SELECT_START_LEV, n_items, m, NULL );
1106
1107                 if (choice==-1 || m[1].text[0]==0)
1108                         return;
1109
1110                 new_level_num = atoi(m[1].text);
1111
1112                 if (!(new_level_num>0 && new_level_num<=player_highest_level)) {
1113                         m[0].text = TXT_ENTER_TO_CONT;
1114                         nm_messagebox( NULL, 1, TXT_OK, TXT_INVALID_LEVEL); 
1115                         goto try_again;
1116                 }
1117         }
1118
1119         Difficulty_level = Player_default_difficulty;
1120
1121         if (!do_difficulty_menu())
1122                 return;
1123
1124         gr_palette_fade_out( gr_palette, 32, 0 );
1125         StartNewGame(new_level_num);
1126
1127 }
1128
1129 extern void GameLoop(int, int );
1130
1131 extern int Redbook_enabled;
1132
1133 void options_menuset(int nitems, newmenu_item * items, int *last_key, int citem )
1134 {
1135         if ( citem==5)
1136         {
1137                 gr_palette_set_gamma(items[5].value);
1138         }
1139
1140         nitems++;               //kill warning
1141         last_key++;             //kill warning
1142 }
1143
1144
1145 //added on 8/18/98 by Victor Rachels to add d1x options menu, maxfps setting
1146 //added/edited on 8/18/98 by Victor Rachels to set maxfps always on, max=80
1147 //added/edited on 9/7/98 by Victor Rachels to attempt dir browsing.  failed.
1148
1149 void d2x_options_menu_poll(int nitems, newmenu_item * menus, int * key, int citem)
1150 {
1151 }
1152
1153
1154 void d2x_options_menu()
1155 {
1156         newmenu_item m[14];
1157         int i=0;
1158         int opt = 0;
1159         int inputs, commands;
1160 #if 0
1161         int checks;
1162 #endif
1163
1164         char smaxfps[4];
1165 #if 0
1166         char shudmaxnumdisp[4];
1167         char thogdir[64];
1168         extern int gr_message_color_level;
1169
1170         sprintf(thogdir,AltHogDir);
1171 #endif
1172         sprintf(smaxfps,"%d",maxfps);
1173 #if 0
1174         sprintf(shudmaxnumdisp,"%d",HUD_max_num_disp);
1175
1176         m[opt].type = NM_TYPE_MENU;  m[opt].text = "Primary autoselect ordering...";   opt++;
1177         m[opt].type = NM_TYPE_MENU;  m[opt].text = "Secondary autoselect ordering..."; opt++;
1178 #endif
1179
1180         //added on 2/4/99 by Victor Rachels for new key menu
1181         m[opt].type = NM_TYPE_MENU;  m[opt].text = "D2X Keys"; opt++;
1182         //end this section addition - VR
1183
1184 #if 0
1185         //enabled 3/24/99 - Owen Evans
1186         m[opt].type = NM_TYPE_MENU;  m[opt].text = "Change Screen Resolution";         opt++;
1187         //end enabled stuff - OE
1188
1189         commands=opt;
1190         //added on 2/2/99 by Victor Rachels for bans
1191 #ifdef NETWORK
1192         m[opt].type = NM_TYPE_MENU; m[opt].text = "Save bans now"; opt++;
1193 #endif
1194         //end this section addition - VR
1195 #endif // 0
1196
1197         m[opt].type = NM_TYPE_TEXT;  m[opt].text = "Maximum Framerate (1-80):";       opt++;
1198
1199
1200         inputs=opt;
1201         m[opt].type = NM_TYPE_INPUT; m[opt].text = smaxfps; m[opt].text_len=3;         opt++;
1202 #if 0
1203         m[opt].type = NM_TYPE_TEXT;  m[opt].text = "Mission Directory";                opt++;
1204         m[opt].type = NM_TYPE_INPUT; m[opt].text = thogdir; m[opt].text_len=64;        opt++;
1205         m[opt].type = NM_TYPE_TEXT;  m[opt].text = "Hud Messages lines (1-80):";       opt++;
1206         m[opt].type = NM_TYPE_INPUT; m[opt].text = shudmaxnumdisp; m[opt].text_len=3;  opt++;
1207         m[opt].type = NM_TYPE_SLIDER; m[opt].text = "Message colorization level"; m[opt].value=gr_message_color_level;m[opt].min_value=0;m[opt].max_value=3;  opt++;
1208         checks=opt;
1209 #ifdef __MSDOS__
1210         m[opt].type = NM_TYPE_CHECK; m[opt].text = "Joy is sidewinder"; m[opt].value=Joy_is_Sidewinder;  opt++;
1211 #endif
1212 #ifdef SUPPORTS_NICEFPS
1213         m[opt].type = NM_TYPE_CHECK; m[opt].text = "Nice FPS (free cpu cycles)"; m[opt].value = use_nice_fps; opt++;
1214 #endif
1215 #endif // 0
1216
1217         for(;;)
1218         {
1219         i=newmenu_do1( NULL, "D2X options", opt, m, &d2x_options_menu_poll, i);
1220
1221                 if(i>-1)
1222                 {
1223             if(i<commands)
1224                         {
1225                                 switch(i)
1226                                 {
1227 #if 0
1228                 case 0: reorder_primary(); break;
1229                 case 1: reorder_secondary(); break;
1230 #endif
1231                                         //added on 2/4/99 by Victor Rachels for new key menu
1232                 case 0: kconfig(4,"D2X Keys"); break;
1233                                         //end this section addition - VR
1234 #if 0
1235                                         //enabled 3/24/99 - Owen Evans
1236                 case 3: change_res(); break;
1237                                         //end enabled stuff - OE
1238 #endif
1239                                 }
1240                         }
1241
1242 #if 0
1243             //added on 2/4/99 by Victor Rachels for bans
1244 #ifdef NETWORK
1245             if(i==commands+0)
1246                         {              
1247
1248                                 nm_messagebox(NULL,1,TXT_OK, "%i Bans saved",writebans());
1249
1250                         }
1251 #endif
1252             //end this section addition - VR
1253 #endif // 0
1254
1255             if(i == inputs+0)
1256                         {
1257                                 maxfps = atoi(smaxfps);
1258                 if(maxfps < 1 || maxfps>80)
1259                                 {
1260                                         nm_messagebox(TXT_ERROR, 1, TXT_OK, "Invalid value for maximum framerate");
1261                                         maxfps = 80;
1262                                         i = (inputs+0);
1263                                 }
1264                         }
1265 #if 0
1266             else if(i==inputs+2)
1267                                 cfile_use_alternate_hogdir(thogdir);
1268                         else if(i==inputs+4)
1269                         {
1270                                 HUD_max_num_disp = atoi(shudmaxnumdisp);
1271                 if(HUD_max_num_disp < 1||HUD_max_num_disp>HUD_MAX_NUM)
1272                                 {
1273                                         nm_messagebox(TXT_ERROR, 1, TXT_OK, "Invalid value for hud lines");
1274                                         HUD_max_num_disp=4;
1275                                         //                   i=(inputs+4);//???
1276                                 }
1277                         }
1278                         gr_message_color_level=m[inputs+5].value;
1279
1280                         sprintf(shudmaxnumdisp,"%d",HUD_max_num_disp);
1281 #endif // 0
1282                         sprintf(smaxfps,"%d",maxfps);
1283                         //           m[inputs+0].text=smaxfps;//redundant.. its not going anywhere
1284 #if 0
1285                         sprintf(thogdir,AltHogDir);
1286                         //           m[inputs+2].text=thogdir;//redundant
1287 #endif
1288                 }
1289                 else
1290                         break;
1291         }
1292
1293 #if 0
1294         write_player_file();
1295
1296 #ifdef __MSDOS__
1297         Joy_is_Sidewinder=m[(checks+0)].value;
1298 #endif
1299 #ifdef __LINUX__
1300         Joy_is_Sidewinder=0;
1301 #endif
1302 #ifdef SUPPORTS_NICEFPS
1303         use_nice_fps=m[(checks+0)].value;
1304 #else
1305         use_nice_fps=0;
1306 #endif
1307 #endif // 0
1308 }
1309
1310 //end edit - Victor Rachels
1311 //end addition - Victor Rachels
1312
1313
1314 void do_options_menu()
1315 {
1316         newmenu_item m[13];
1317         int i = 0;
1318
1319         do {
1320                 m[ 0].type = NM_TYPE_MENU;   m[ 0].text="Sound effects & music...";
1321                 m[ 1].type = NM_TYPE_TEXT;   m[ 1].text="";
1322                 #if defined(MACINTOSH) && defined(APPLE_DEMO)
1323                 m [2].type = NM_TYPE_TEXT;   m[ 2].text="";
1324                 #else
1325                 m[ 2].type = NM_TYPE_MENU;   m[ 2].text=TXT_CONTROLS_;
1326                 #endif
1327         #ifdef WINDOWS
1328                 m[ 3].type = NM_TYPE_MENU;   m[ 3].text="INVOKE JOYSTICK CONTROL PANEL";
1329         #else
1330                 m[ 3].type = NM_TYPE_MENU;   m[ 3].text=TXT_CAL_JOYSTICK;
1331         #endif
1332                 m[ 4].type = NM_TYPE_TEXT;   m[ 4].text="";
1333
1334 #if defined(POLY_ACC)
1335         #ifdef MACINTOSH
1336
1337                 if ( !PAEnabled )
1338                 {
1339                         m[5].type               = NM_TYPE_SLIDER;
1340                         m[5].text               = TXT_BRIGHTNESS;
1341                         m[5].value              = gr_palette_get_gamma();
1342                         m[5].min_value  = 0;
1343                         m[5].max_value  = 8; 
1344                 }
1345                 else
1346                 {
1347                         m[ 5].type = NM_TYPE_TEXT;   m[ 5].text="";
1348                 }
1349         
1350         #else
1351                 m[ 5].type = NM_TYPE_TEXT;   m[ 5].text="";
1352         #endif
1353 #else
1354                 m[5].type = NM_TYPE_SLIDER;
1355                 m[5].text = TXT_BRIGHTNESS;
1356                 m[5].value = gr_palette_get_gamma();
1357                 m[5].min_value = 0;
1358                 m[5].max_value = 16; // CCA too dim, was 8;
1359 #endif
1360
1361
1362 #ifdef PA_3DFX_VOODOO
1363                 m[ 6].type = NM_TYPE_TEXT;   m[ 6].text="";
1364 #else
1365                 m[ 6].type = NM_TYPE_MENU;   m[ 6].text=TXT_DETAIL_LEVELS;
1366 #endif
1367
1368 #if defined(POLY_ACC)
1369                 m[ 7].type = NM_TYPE_TEXT;   m[ 7].text="";
1370 #else
1371                 #ifdef MACINTOSH
1372                         if ( gConfigInfo.mChangeResolution && !PAEnabled )
1373                         {
1374                                 m[ 7].type = NM_TYPE_MENU;   m[ 7].text="Screen resolution...";
1375                         }
1376                         else    // for when we are on a mac and no resolution switching allowed
1377                         {
1378                                 m[ 7].type = NM_TYPE_TEXT;   m[ 7].text="";
1379                         }
1380                 #else   // for PC's
1381                         m[ 7].type = NM_TYPE_MENU;   m[ 7].text="Screen resolution...";
1382                 #endif  // end of #ifdef macintosh
1383
1384 #endif
1385
1386                 m[ 8].type = NM_TYPE_TEXT;   m[ 8].text="";
1387                 m[ 9].type = NM_TYPE_MENU;   m[ 9].text="Primary autoselect ordering...";
1388                 m[10].type = NM_TYPE_MENU;   m[10].text="Secondary autoselect ordering...";
1389                 m[11].type = NM_TYPE_MENU;   m[11].text="Toggles...";
1390
1391                 m[12].type = NM_TYPE_MENU;   m[12].text="D2X options...";
1392
1393                 i = newmenu_do1( NULL, TXT_OPTIONS, sizeof(m)/sizeof(*m), m, options_menuset, i );
1394                         
1395                 switch(i)       {
1396                         case  0: do_sound_menu();                       break;
1397                         case  2: joydefs_config();                      break;
1398                         case  3: joydefs_calibrate();           break;
1399                         case  6: do_detail_level_menu();        break;
1400                         case  7: do_screen_res_menu();          break;
1401                         case  9: ReorderPrimary();                      break;
1402                         case 10: ReorderSecondary();            break;
1403                         case 11: do_toggles_menu();                     break;
1404                         case 12: d2x_options_menu();        break;
1405                 }
1406
1407         } while( i>-1 );
1408
1409         write_player_file();
1410 }
1411
1412 extern int Redbook_playing;
1413 void set_redbook_volume(int volume);
1414
1415 WIN(extern int RBCDROM_State);
1416 WIN(static BOOL windigi_driver_off=FALSE);
1417
1418 void sound_menuset(int nitems, newmenu_item * items, int *last_key, int citem )
1419 {
1420         nitems=nitems;          
1421         *last_key = *last_key;
1422
1423         if ( Config_digi_volume != items[0].value )     {
1424                 Config_digi_volume = items[0].value;
1425
1426                 #ifdef WINDOWS
1427                         if (windigi_driver_off) {
1428                                 digi_midi_wait();
1429                                 digi_init_digi();
1430                                 Sleep(500);
1431                                 windigi_driver_off = FALSE;
1432                         }
1433                 #endif                  
1434                 
1435                 #ifndef MACINTOSH
1436                         digi_set_digi_volume( (Config_digi_volume*32768)/8 );
1437                 #else
1438                         digi_set_digi_volume( (Config_digi_volume*256)/8 );
1439                 #endif
1440                 digi_play_sample_once( SOUND_DROP_BOMB, F1_0 );
1441         }
1442
1443 #ifdef WINDOWS
1444         if (!wmidi_support_volchange()) {
1445                 if (!items[1].value && Config_midi_volume) {
1446                         Config_midi_volume = 0;
1447                         digi_set_midi_volume(0);
1448                         digi_play_midi_song( NULL, NULL, NULL, 0 );
1449                 }
1450                 else if (Config_midi_volume == 0 && items[1].value) {
1451                         digi_set_midi_volume(64);
1452                         Config_midi_volume = 4;
1453                 }
1454         }
1455         else     // LINK TO BELOW IF
1456 #endif
1457         if (Config_midi_volume != items[1].value )   {
1458                 Config_midi_volume = items[1].value;
1459                 #ifdef WINDOWS
1460                         if (!windigi_driver_off) {
1461                                 Sleep(200);
1462                                 digi_close_digi();
1463                                 Sleep(100);
1464                                 windigi_driver_off = TRUE;
1465                         }
1466                 #endif
1467                 #ifndef MACINTOSH
1468                         digi_set_midi_volume( (Config_midi_volume*128)/8 );
1469                 #else
1470                         digi_set_midi_volume( (Config_midi_volume*256)/8 );
1471                 #endif
1472         }
1473 #ifdef MACINTOSH
1474         if (Config_master_volume != items[3].value ) {
1475                 Config_master_volume = items[3].value;
1476                 digi_set_master_volume( Config_master_volume );
1477                 digi_play_sample_once( SOUND_DROP_BOMB, F1_0 );
1478         }
1479 #endif
1480
1481         // don't enable redbook for a non-apple demo version of the shareware demo
1482         #if !defined(SHAREWARE) || ( defined(SHAREWARE) && defined(APPLE_DEMO) )
1483
1484         if (Config_redbook_volume != items[2].value )   {
1485                 Config_redbook_volume = items[2].value;
1486                 set_redbook_volume(Config_redbook_volume);
1487         }
1488
1489         if (items[4].value != (Redbook_playing!=0)) {
1490
1491                 if (items[4].value && FindArg("-noredbook")) {
1492                         nm_messagebox (TXT_SORRY,1,TXT_OK,"Redbook audio has been disabled\non the command line");
1493                         items[4].value = 0;
1494                         items[4].redraw = 1;
1495                 }
1496                 else {
1497                         Redbook_enabled = items[4].value;
1498
1499                         mprintf((1, "Redbook_enabled = %d\n", Redbook_enabled));
1500
1501                         if (Function_mode == FMODE_MENU)
1502                                 songs_play_song(SONG_TITLE,1);
1503                         else if (Function_mode == FMODE_GAME)
1504                                 songs_play_level_song( Current_level_num );
1505                         else
1506                                 Int3();
1507
1508                         if (items[4].value && !Redbook_playing) {
1509                         #ifdef WINDOWS
1510                                 if (RBCDROM_State == -1) 
1511                                         nm_messagebox (TXT_SORRY,1,TXT_OK,"Cannot start CD Music.\nAnother application is\nusing the CD player.\n");
1512                                 else // link to next code line!
1513                         #endif
1514                                 nm_messagebox (TXT_SORRY,1,TXT_OK,"Cannot start CD Music.  Insert\nyour Descent II CD and try again");
1515                                 items[4].value = 0;
1516                                 items[4].redraw = 1;
1517                         }
1518
1519                         items[1].type = (Redbook_playing?NM_TYPE_TEXT:NM_TYPE_SLIDER);
1520                         items[1].redraw = 1;
1521                         items[2].type = (Redbook_playing?NM_TYPE_SLIDER:NM_TYPE_TEXT);
1522                         items[2].redraw = 1;
1523
1524                 }
1525         }
1526
1527         #endif
1528
1529         citem++;                //kill warning
1530 }
1531
1532 void do_sound_menu()
1533 {
1534    newmenu_item m[6];
1535         int i = 0;
1536
1537  #ifdef WINDOWS
1538         extern BOOL DIGIDriverInit;
1539         if (!DIGIDriverInit) windigi_driver_off = TRUE;
1540         else windigi_driver_off = FALSE;
1541  #endif
1542
1543         do {
1544                 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; 
1545                 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;
1546
1547         #ifdef WINDOWS
1548                 if (!wmidi_support_volchange() && !Redbook_playing) {
1549                         m[1].type = NM_TYPE_CHECK;
1550                         m[1].text = "MIDI MUSIC";
1551                         if (Config_midi_volume) m[1].value = 1;
1552                 }
1553         #endif
1554
1555                 #ifdef SHAREWARE
1556                         m[ 2].type = NM_TYPE_TEXT; m[ 2].text="";
1557                         m[ 3].type = NM_TYPE_TEXT; m[ 3].text="";
1558                         m[ 4].type = NM_TYPE_TEXT; m[ 4].text="";
1559                         #ifdef MACINTOSH
1560                                 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;
1561
1562                                 #ifdef APPLE_DEMO
1563                                         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;
1564                                         m[ 4].type = NM_TYPE_CHECK;  m[ 4].text="CD Music (Redbook) enabled"; m[4].value=(Redbook_playing!=0);
1565                                 #endif
1566
1567                         #endif
1568
1569                 #else           // ifdef SHAREWARE
1570                         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;
1571
1572                         #ifndef MACINTOSH
1573                                 m[ 3].type = NM_TYPE_TEXT; m[ 3].text="";
1574                         #else
1575                                 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; 
1576                         #endif
1577                 
1578                         m[ 4].type = NM_TYPE_CHECK;  m[ 4].text="CD Music (Redbook) enabled"; m[4].value=(Redbook_playing!=0);
1579                 #endif
1580         
1581                 m[ 5].type = NM_TYPE_CHECK;  m[ 5].text=TXT_REVERSE_STEREO; m[5].value=Config_channels_reversed; 
1582                                 
1583                 i = newmenu_do1( NULL, "Sound Effects & Music", sizeof(m)/sizeof(*m), m, sound_menuset, i );
1584
1585                 Redbook_enabled = m[4].value;
1586                 Config_channels_reversed = m[5].value;
1587
1588         } while( i>-1 );
1589
1590 #ifdef WINDOWS
1591         if (windigi_driver_off) {
1592                 digi_midi_wait();
1593                 Sleep(500);
1594                 digi_init_digi();
1595                 windigi_driver_off=FALSE;
1596         }
1597 #endif
1598
1599
1600         if ( Config_midi_volume < 1 )   {
1601                 #ifndef MACINTOSH
1602                         digi_play_midi_song( NULL, NULL, NULL, 0 );
1603                 #else
1604                         digi_play_midi_song(-1, 0);
1605                 #endif
1606         }
1607
1608 }
1609
1610
1611 extern int Automap_always_hires;
1612
1613 #define ADD_CHECK(n,txt,v)  do { m[n].type=NM_TYPE_CHECK; m[n].text=txt; m[n].value=v;} while (0)
1614
1615 void do_toggles_menu()
1616 {
1617 #ifndef MACINTOSH
1618 #if defined(POLY_ACC)
1619         #define N_TOGGLE_ITEMS 6        // get rid of automap hi-res.
1620 #else
1621         #define N_TOGGLE_ITEMS 7
1622 #endif
1623 #else
1624         #define N_TOGGLE_ITEMS 7
1625 #endif
1626         newmenu_item m[N_TOGGLE_ITEMS];
1627         int i = 0;
1628
1629         do {
1630                 #if defined(MACINTOSH) && defined(USE_ISP)
1631                         if (ISpEnabled())
1632                         {
1633                                 m[0].type = NM_TYPE_TEXT; m[0].text = "";
1634                         }
1635                         else
1636                         {
1637                                 ADD_CHECK(0, "Ship auto-leveling", Auto_leveling_on);
1638                         }
1639                 #else 
1640                         ADD_CHECK(0, "Ship auto-leveling", Auto_leveling_on);
1641                 #endif
1642                 ADD_CHECK(1, "Show reticle", Reticle_on);
1643                 ADD_CHECK(2, "Missile view", Missile_view_enabled);
1644                 ADD_CHECK(3, "Headlight on when picked up", Headlight_active_default );
1645                 ADD_CHECK(4, "Show guided missile in main display", Guided_in_big_window );
1646                 ADD_CHECK(5, "Escort robot hot keys",EscortHotKeys);
1647                 #ifdef MACINTOSH
1648                         if ( !PAEnabled ) {
1649                                 ADD_CHECK(6, "Pixel Double", Scanline_double);
1650                         }
1651                 #else
1652 #if !defined(POLY_ACC)
1653                         ADD_CHECK(6, "Always show HighRes Automap", min(MenuHiresAvailable,Automap_always_hires));
1654 #endif
1655                 #endif
1656                 //when adding more options, change N_TOGGLE_ITEMS above
1657
1658                 #ifdef MACINTOSH
1659                 if ( PAEnabled )                // when doing RAVE, no pixel doubling
1660                         i = newmenu_do1( NULL, "Toggles", N_TOGGLE_ITEMS-1, m, NULL, i );
1661                 else
1662                 #endif          // note link to if
1663                         i = newmenu_do1( NULL, "Toggles", N_TOGGLE_ITEMS, m, NULL, i );
1664                         
1665                 Auto_leveling_on                        = m[0].value;
1666                 Reticle_on                                      = m[1].value;
1667                 Missile_view_enabled            = m[2].value;
1668                 Headlight_active_default        = m[3].value;
1669                 Guided_in_big_window            = m[4].value;
1670                 EscortHotKeys                           = m[5].value;
1671
1672
1673                 #ifdef MACINTOSH
1674                         if ( !PAEnabled )
1675                                 Scanline_double = m[6].value;
1676                 #else
1677 #if !defined(POLY_ACC)
1678                         if (MenuHiresAvailable)
1679                                 Automap_always_hires = m[6].value;
1680                         else if (m[6].value)
1681                                 nm_messagebox(TXT_SORRY,1,"OK","High Resolution modes are\nnot available on this video card");
1682 #endif
1683                 #endif
1684
1685         } while( i>-1 );
1686
1687 }
1688
1689 void do_multi_player_menu()
1690 {
1691         int menu_choice[5];
1692         newmenu_item m[5];
1693         int choice = 0, num_options = 0;
1694         int old_game_mode;
1695
1696         do {
1697 //              WIN(ipx_destroy_read_thread());
1698
1699                 old_game_mode = Game_mode;
1700                 num_options = 0;
1701
1702                 if (!FindArg("-udp")) {
1703                         ADD_ITEM(TXT_START_IPX_NET_GAME, MENU_START_IPX_NETGAME, -1 );
1704                         ADD_ITEM(TXT_JOIN_IPX_NET_GAME, MENU_JOIN_IPX_NETGAME, -1 );
1705                 } else {
1706                         ADD_ITEM(TXT_START_TCP_NET_GAME, MENU_START_TCP_NETGAME, -1 );
1707                         ADD_ITEM(TXT_JOIN_TCP_NET_GAME, MENU_JOIN_TCP_NETGAME, -1 );
1708                 }
1709
1710         #ifdef MACINTOSH
1711                 ADD_ITEM("Start Appletalk Netgame", MENU_START_APPLETALK_NETGAME, -1 );
1712                 ADD_ITEM("Join Appletalk Netgame\n", MENU_JOIN_APPLETALK_NETGAME, -1 );
1713         #endif
1714
1715                 ADD_ITEM(TXT_MODEM_GAME, MENU_START_SERIAL, -1);
1716
1717                 choice = newmenu_do1( NULL, TXT_MULTIPLAYER, num_options, m, NULL, choice );
1718                 
1719                 if ( choice > -1 )      
1720                         do_option(menu_choice[choice]);
1721         
1722                 if (old_game_mode != Game_mode)
1723                         break;          // leave menu
1724
1725         } while( choice > -1 );
1726
1727 }
1728
1729 void DoNewIPAddress ()
1730  {
1731   newmenu_item m[4];
1732   char IPText[30];
1733   int choice;
1734
1735   m[0].type=NM_TYPE_TEXT; m[0].text = "Enter an address or hostname:";
1736   m[1].type=NM_TYPE_INPUT; m[1].text_len = 50; m[1].text = IPText;
1737   IPText[0]=0;
1738
1739   choice = newmenu_do( NULL, "Join a TCPIP game", 2, m, NULL );
1740
1741   if (choice==-1 || m[1].text[0]==0)
1742    return;
1743
1744   nm_messagebox (TXT_SORRY,1,TXT_OK,"That address is not valid!");
1745  }