int credits_handler(window *wind, d_event *event, credits *cr) { int j, l, y; char * tempp; switch (event->type) { case EVENT_KEY_COMMAND: if (!call_default_handler(event)) // if not print screen, debug etc window_close(wind); return 1; case EVENT_MOUSE_BUTTON_DOWN: case EVENT_MOUSE_BUTTON_UP: if (event_mouse_get_button(event) == MBTN_LEFT || event_mouse_get_button(event) == MBTN_RIGHT) { window_close(wind); return 1; } break; case EVENT_IDLE: if (cr->done>NUM_LINES) { window_close(wind); return 0; } break; case EVENT_WINDOW_DRAW: timer_delay(F1_0/28); if (cr->row == 0) { do { cr->buffer_line = (cr->buffer_line+1) % NUM_LINES; get_line:; if (PHYSFSX_fgets( cr->buffer[cr->buffer_line], 80, cr->file )) { char *p; if (cr->have_bin_file) // is this a binary tbl file decode_text_line (cr->buffer[cr->buffer_line]); p = cr->buffer[cr->buffer_line]; if (p[0] == ';') goto get_line; if (p[0] == '%') { if (p[1] == ALLOWED_CHAR) { int i = 0, len = strlen(p); for (i = 0; i < len; i++) p[i] = p[i+2]; } else goto get_line; } } else { //fseek( file, 0, SEEK_SET); cr->buffer[cr->buffer_line][0] = 0; cr->done++; } } while (cr->extra_inc--); cr->extra_inc = 0; } // cheap but effective: towards end of credits sequence, fade out the music volume if (cr->done >= NUM_LINES-16) { static int curvol = -10; if (curvol == -10) curvol = GameCfg.MusicVolume; if (curvol > (NUM_LINES-cr->done)/2) { curvol = (NUM_LINES-cr->done)/2; songs_set_volume(curvol); } } y = cr->first_line_offset - cr->row; show_fullscr(&cr->backdrop); for (j=0; j<NUM_LINES; j++ ) { char *s; l = (cr->buffer_line + j + 1 ) % NUM_LINES; s = cr->buffer[l]; if ( s[0] == '!' ) { s++; } else if ( s[0] == '$' ) { gr_set_curfont( HUGE_FONT ); s++; } else if ( s[0] == '*' ) { gr_set_curfont( MEDIUM3_FONT ); s++; } else gr_set_curfont( MEDIUM2_FONT ); tempp = strchr( s, '\t' ); if ( !tempp ) { // Wacky Fast Credits thing int w, h, aw; gr_get_string_size( s, &w, &h, &aw); gr_string( 0x8000, y, s ); } y += ROW_SPACING; } cr->row += SHEIGHT/200; if (cr->row >= ROW_SPACING) cr->row = 0; break; case EVENT_WINDOW_CLOSE: gr_free_bitmap_data (&cr->backdrop); PHYSFS_close(cr->file); songs_set_volume(GameCfg.MusicVolume); songs_play_song( SONG_TITLE, 1 ); d_free(cr); break; default: break; } return 0; }
//called for each level to load & setup the exit sequence void load_endlevel_data(int level_num) { char filename[13]; char line[LINE_LEN],*p; CFILE *ifile; int var,segnum,sidenum; int exit_side=0; int have_binary = 0; endlevel_data_loaded = 0; //not loaded yet try_again: ; #ifdef SHAREWARE sprintf(filename,"level%02d.sdl", level_num); #else if (level_num<0) //secret level strcpy(filename,Secret_level_names[-level_num-1]); else //normal level strcpy(filename,Level_names[level_num-1]); #endif if (!convert_ext(filename,"end")) return; ifile = cfopen(filename,"rb"); if (!ifile) { convert_ext(filename,"txb"); if (!strcmp(filename, Briefing_text_filename) || !strcmp(filename, Ending_text_filename)) return; // Don't want to interpret the briefing as an end level sequence! ifile = cfopen(filename,"rb"); if (!ifile) { if (level_num==1) { return; //abort //Error("Cannot load file text of binary version of <%s>",filename); } else { level_num = 1; goto try_again; } } have_binary = 1; } //ok...this parser is pretty simple. It ignores comments, but //everything else must be in the right place var = 0; while (cfgets(line,LINE_LEN,ifile)) { if (have_binary) decode_text_line (line); if ((p=strchr(line,';'))!=NULL) *p = 0; //cut off comment for (p=line+strlen(line)-1;p>line && isspace(*p);*p--=0); for (p=line;isspace(*p);p++); if (!*p) //empty line continue; switch (var) { case 0: { //ground terrain int iff_error; ubyte pal[768]; gr_free_bitmap_data (&terrain_bm_instance); iff_error = iff_read_bitmap(p,&terrain_bm_instance,BM_LINEAR,pal); if (iff_error != IFF_NO_ERROR) { con_printf(CON_DEBUG, "Can't load exit terrain from file %s: IFF error: %s\n", p, iff_errormsg(iff_error)); endlevel_data_loaded = 0; // won't be able to play endlevel sequence cfclose(ifile); return; } terrain_bitmap = &terrain_bm_instance; gr_remap_bitmap_good( terrain_bitmap, pal, iff_transparent_color, -1); break; } case 1: //height map load_terrain(p); break; case 2: sscanf(p,"%d,%d",&exit_point_bmx,&exit_point_bmy); break; case 3: //exit heading exit_angles.h = i2f(atoi(p))/360; break; case 4: { //planet bitmap int iff_error; ubyte pal[768]; gr_free_bitmap_data (&satellite_bm_instance); iff_error = iff_read_bitmap(p,&satellite_bm_instance,BM_LINEAR,pal); if (iff_error != IFF_NO_ERROR) { con_printf(CON_DEBUG, "Can't load exit satellite from file %s: IFF error: %s\n", p, iff_errormsg(iff_error)); endlevel_data_loaded = 0; // won't be able to play endlevel sequence cfclose(ifile); return; } satellite_bitmap = &satellite_bm_instance; gr_remap_bitmap_good( satellite_bitmap, pal, iff_transparent_color, -1); break; } case 5: //earth pos case 7: { //station pos vms_matrix tm; vms_angvec ta; int pitch,head; sscanf(p,"%d,%d",&head,&pitch); ta.h = i2f(head)/360; ta.p = -i2f(pitch)/360; ta.b = 0; vm_angles_2_matrix(&tm,&ta); if (var==5) satellite_pos = tm.fvec; //vm_vec_copy_scale(&satellite_pos,&tm.fvec,SATELLITE_DIST); else station_pos = tm.fvec; break; } case 6: //planet size satellite_size = i2f(atoi(p)); break; } var++; } Assert(var == NUM_VARS); // OK, now the data is loaded. Initialize everything //find the exit sequence by searching all segments for a side with //children == -2 for (segnum=0,exit_segnum=-1;exit_segnum==-1 && segnum<=Highest_segment_index;segnum++) for (sidenum=0;sidenum<6;sidenum++) if (Segments[segnum].children[sidenum] == -2) { exit_segnum = segnum; exit_side = sidenum; break; } Assert(exit_segnum!=-1); compute_segment_center(&mine_exit_point,&Segments[exit_segnum]); extract_orient_from_segment(&mine_exit_orient,&Segments[exit_segnum]); compute_center_point_on_side(&mine_side_exit_point,&Segments[exit_segnum],exit_side); vm_vec_scale_add(&mine_ground_exit_point,&mine_exit_point,&mine_exit_orient.uvec,-i2f(20)); //compute orientation of surface { vms_vector tv; vms_matrix exit_orient,tm; vm_angles_2_matrix(&exit_orient,&exit_angles); vm_transpose_matrix(&exit_orient); vm_matrix_x_matrix(&surface_orient,&mine_exit_orient,&exit_orient); vm_copy_transpose_matrix(&tm,&surface_orient); vm_vec_rotate(&tv,&station_pos,&tm); vm_vec_scale_add(&station_pos,&mine_exit_point,&tv,STATION_DIST); vm_vec_rotate(&tv,&satellite_pos,&tm); vm_vec_scale_add(&satellite_pos,&mine_exit_point,&tv,SATELLITE_DIST); vm_vector_2_matrix(&tm,&tv,&surface_orient.uvec,NULL); vm_vec_copy_scale(&satellite_upvec,&tm.uvec,SATELLITE_HEIGHT); } cfclose(ifile); endlevel_data_loaded = 1; }
static window_event_result credits_handler(window *, const d_event &event, credits *cr) { int l, y; window_event_result result; switch (event.type) { case EVENT_KEY_COMMAND: if ((result = call_default_handler(event)) == window_event_result::ignored) // if not print screen, debug etc { return window_event_result::close; } return result; case EVENT_MOUSE_BUTTON_DOWN: case EVENT_MOUSE_BUTTON_UP: if (event_mouse_get_button(event) == MBTN_LEFT || event_mouse_get_button(event) == MBTN_RIGHT) { return window_event_result::close; } break; case EVENT_IDLE: if (cr->done>NUM_LINES) { return window_event_result::close; } break; case EVENT_WINDOW_DRAW: #if defined(DXX_BUILD_DESCENT_I) timer_delay(F1_0/17); #elif defined(DXX_BUILD_DESCENT_II) timer_delay(F1_0/28); #endif if (cr->row == 0) { do { cr->buffer_line = (cr->buffer_line+1) % NUM_LINES; #if defined(DXX_BUILD_DESCENT_II) get_line:; #endif if (PHYSFSX_fgets( cr->buffer[cr->buffer_line], cr->file )) { char *p; if (cr->have_bin_file) // is this a binary tbl file decode_text_line (cr->buffer[cr->buffer_line]); #if defined(DXX_BUILD_DESCENT_I) p = strchr(&cr->buffer[cr->buffer_line][0],'\n'); if (p) *p = '\0'; #elif defined(DXX_BUILD_DESCENT_II) p = cr->buffer[cr->buffer_line]; if (p[0] == ';') goto get_line; if (p[0] == '%') { if (p[1] == ALLOWED_CHAR) { for (int i = 0; p[i]; i++) p[i] = p[i+2]; } else goto get_line; } #endif } else { //fseek( file, 0, SEEK_SET); cr->buffer[cr->buffer_line][0] = 0; cr->done++; } } while (cr->extra_inc--); cr->extra_inc = 0; } // cheap but effective: towards end of credits sequence, fade out the music volume if (cr->done >= NUM_LINES-16) { static int curvol = -10; if (curvol == -10) curvol = GameCfg.MusicVolume; if (curvol > (NUM_LINES-cr->done)/2) { curvol = (NUM_LINES-cr->done)/2; songs_set_volume(curvol); } } y = cr->first_line_offset - cr->row; show_fullscr(cr->backdrop); for (uint_fast32_t j=0; j != NUM_LINES; ++j, y += ROW_SPACING) { l = (cr->buffer_line + j + 1 ) % NUM_LINES; const char *s = cr->buffer[l]; if (!s) continue; if ( s[0] == '!' ) { s++; } else if ( s[0] == '$' ) { gr_set_curfont( HUGE_FONT ); s++; } else if ( s[0] == '*' ) { gr_set_curfont( MEDIUM3_FONT ); s++; } else gr_set_curfont( MEDIUM2_FONT ); const auto tempp = strchr( s, '\t' ); if ( !tempp ) { // Wacky Fast Credits thing gr_string( 0x8000, y, s ); } } cr->row += SHEIGHT/200; if (cr->row >= ROW_SPACING) cr->row = 0; break; case EVENT_WINDOW_CLOSE: songs_set_volume(GameCfg.MusicVolume); songs_play_song( SONG_TITLE, 1 ); std::default_delete<credits>()(cr); break; default: break; } return window_event_result::ignored; }