void title_save_game() { grs_canvas * save_canv; grs_canvas * save_canv_data; grs_font * save_font; ubyte palette[768]; if ( Next_level_num == 0 ) return; save_canv = grd_curcanv; save_font = grd_curcanv->cv_font; save_canv_data = gr_create_canvas( grd_curcanv->cv_bitmap.bm_w, grd_curcanv->cv_bitmap.bm_h ); gr_set_current_canvas(save_canv_data); gr_ubitmap(0,0,&save_canv->cv_bitmap); gr_set_current_canvas(save_canv); gr_clear_canvas(gr_find_closest_color_current( 0, 0, 0)); gr_palette_read( palette ); gr_palette_load( gr_palette ); #ifndef SHAREWARE state_save_all(1); #endif gr_palette_clear(); gr_set_current_canvas(save_canv); gr_ubitmap(0,0,&save_canv_data->cv_bitmap); gr_palette_load( palette ); gr_set_curfont(save_font); }
static void show_title_screen(const char * filename, int allow_keys, int from_hog_only ) { int pcx_error; char new_filename[PATH_MAX] = ""; auto ts = make_unique<title_screen>(); ts->allow_keys = allow_keys; #ifdef RELEASE if (from_hog_only) strcpy(new_filename,"\x01"); //only read from hog file #else (void)from_hog_only; #endif strcat(new_filename,filename); filename = new_filename; if ((pcx_error=pcx_read_bitmap( filename, ts->title_bm, gr_palette ))!=PCX_ERROR_NONE) { Error( "Error loading briefing screen <%s>, PCX load error: %s (%i)\n",filename, pcx_errormsg(pcx_error), pcx_error); } ts->timer = timer_query() + i2f(3); gr_palette_load( gr_palette ); const auto wind = window_create(grd_curscreen->sc_canvas, 0, 0, SWIDTH, SHEIGHT, title_handler, ts.get()); if (!wind) { return; } event_process_all(); }
void kmatrix_redraw_coop() { int i, color; int sorted[MAX_PLAYERS]; multi_sort_kill_list(); grd_curcanv->cv_font = MEDIUM3_FONT; gr_string( 0x8000, FSPACY(10), "COOPERATIVE SUMMARY"); grd_curcanv->cv_font = GAME_FONT; multi_get_kill_list(sorted); kmatrix_draw_coop_names(sorted); for (i=0; i<N_players; i++ ) { color = sorted[i]; if (Players[sorted[i]].connected==CONNECT_DISCONNECTED) gr_set_fontcolor(gr_find_closest_color(31,31,31),-1); else gr_set_fontcolor(BM_XRGB(player_rgb[color].r,player_rgb[color].g,player_rgb[color].b),-1 ); kmatrix_draw_coop_item( i, sorted ); } gr_palette_load(gr_palette); }
int gr_palette_fade_in(ubyte *pal, int nsteps, int allow_keys) { int i,j; ubyte c; fix fade_palette[768]; fix fade_palette_delta[768]; allow_keys = allow_keys; if (!gr_palette_faded_out) return 0; #ifndef NDEBUG if (grd_fades_disabled) { gr_palette_load(pal); return 0; } #endif #if defined(POLY_ACC) gr_palette_load(pal); return 0; #endif for (i=0; i<768; i++ ) { gr_current_pal[i] = pal[i]; fade_palette[i] = 0; fade_palette_delta[i] = i2f(pal[i]+gr_palette_gamma) / nsteps; } for (j=0; j<nsteps; j++ ) { gr_sync_display(); outp( 0x3c6, 0xff ); outp( 0x3c8, 0 ); for (i=0; i<768; i++ ) { fade_palette[i] += fade_palette_delta[i]; if (fade_palette[i] > i2f(pal[i]+gr_palette_gamma) ) fade_palette[i] = i2f(pal[i]+gr_palette_gamma); c = f2i(fade_palette[i]); if ( c > 63 ) c = 63; outp( 0x3c9, c ); } } gr_palette_faded_out = 0; return 0; }
int show_title_screen( char * filename, int allow_keys ) { fix timer; int pcx_error; grs_bitmap title_bm; gr_init_bitmap_data (&title_bm); if ((pcx_error=pcx_read_bitmap( filename, &title_bm, BM_LINEAR, New_pal ))!=PCX_ERROR_NONE) { printf( "File '%s', PCX load error: %s (%i)\n (No big deal, just no title screen.)\n",filename, pcx_errormsg(pcx_error), pcx_error); mprintf((0, "File '%s', PCX load error: %s (%i)\n (No big deal, just no title screen.)\n",filename, pcx_errormsg(pcx_error), pcx_error)); Int3(); gr_free_bitmap_data (&title_bm); return 0; } // vfx_set_palette_sub( New_pal ); #ifdef OGL gr_palette_load(New_pal); #else gr_palette_clear(); #endif gr_set_current_canvas( NULL ); show_fullscr(&title_bm); //added on 9/13/98 by adb to make update-needing arch's work gr_update(); //end addition - adb gr_free_bitmap_data (&title_bm); if (allow_keys > 2 || gr_palette_fade_in( New_pal, 32, allow_keys ) || allow_keys > 1) { return 1; } gr_palette_load( New_pal ); timer = timer_get_fixed_seconds() + i2f(3); while (1) { if ( local_key_inkey() && allow_keys ) break; if ( timer_get_fixed_seconds() > timer ) break; } if (gr_palette_fade_out( New_pal, 32, allow_keys )) return 1; return 0; }
void gr_palette_set_gamma( int gamma ) { if ( gamma < 0 ) gamma = 0; if ( gamma > 16 ) gamma = 16; //was 8 if (gr_palette_gamma_param != gamma ) { gr_palette_gamma_param = gamma; gr_palette_gamma = gamma; gr_palette_load( gr_palette ); } }
void gr_palette_set_gamma( int gamma ) { if ( gamma < 0 ) gamma = 0; if ( gamma > 8 ) gamma = 8; if (gr_palette_gamma_param != gamma ) { gr_palette_gamma_param = gamma; gr_palette_gamma = gamma; if (!gr_palette_faded_out) gr_palette_load( gr_palette ); } }
void kmatrix_redraw(kmatrix_screen *km) { int i, color; int sorted[MAX_PLAYERS]; gr_set_current_canvas(NULL); show_fullscr(&km->background); if(Netgame.FairColors) selected_player_rgb = player_rgb_all_blue; else if(Netgame.BlackAndWhitePyros) selected_player_rgb = player_rgb_alt; else selected_player_rgb = player_rgb; if (Game_mode & GM_MULTI_COOP) { kmatrix_redraw_coop(); } else { multi_sort_kill_list(); grd_curcanv->cv_font = MEDIUM3_FONT; if (Game_mode & GM_CAPTURE) gr_string( 0x8000, FSPACY(10), "CAPTURE THE FLAG SUMMARY"); else if (Game_mode & GM_HOARD) gr_string( 0x8000, FSPACY(10), "HOARD SUMMARY"); else gr_string( 0x8000, FSPACY(10), TXT_KILL_MATRIX_TITLE); grd_curcanv->cv_font = GAME_FONT; multi_get_kill_list(sorted); kmatrix_draw_names(sorted); for (i=0; i<N_players; i++ ) { if (Game_mode & GM_TEAM) color = get_team(sorted[i]); else color = sorted[i]; if (Players[sorted[i]].connected==CONNECT_DISCONNECTED) gr_set_fontcolor(gr_find_closest_color(31,31,31),-1); else gr_set_fontcolor(BM_XRGB(selected_player_rgb[color].r,selected_player_rgb[color].g,selected_player_rgb[color].b),-1 ); kmatrix_draw_item( i, sorted ); } } gr_palette_load(gr_palette); }
void gr_palette_set_gamma( int gamma ) { if ( gamma < 0 ) gamma = 0; if ( gamma > 8 ) gamma = 8; if (gr_palette_gamma_param != gamma ) { gr_palette_gamma_param = gamma; gr_palette_gamma = gamma; gr_build_mac_gamma(gamma_corrections[gr_palette_gamma]); if (!gr_palette_faded_out) gr_palette_load( gr_palette ); } }
void gr_palette_set_gamma( int gamma ) { if ( gamma < 0 ) gamma = 0; //added/changed on 10/27/98 by Victor Rachels to increase brightness slider if ( gamma > 16 ) gamma = 16; //was 8 //end this section change - Victor Rachels if (gr_palette_gamma_param != gamma ) { gr_palette_gamma_param = gamma; cvar_setint(&gr_palette_gamma, gamma); if (!gr_palette_faded_out) gr_palette_load( gr_palette ); } }
void piggy_critical_error() { grs_canvas * save_canv; grs_font * save_font; int i; save_canv = grd_curcanv; save_font = grd_curcanv->cv_font; gr_palette_load( gr_palette ); i = nm_messagebox( "Disk Error", 2, "Retry", "Exit", "%s\non drive %c:", crit_errors[descent_critical_errcode&0xf], (descent_critical_deverror&0xf)+'A' ); if ( i == 1 ) exit(1); gr_set_current_canvas(save_canv); grd_curcanv->cv_font = save_font; }
//load a level off disk. level numbers start at 1. Secret levels are -1,-2,-3 void LoadLevel(int level_num,int page_in_textures) { char *level_name; player save_player; save_player = Players[Player_num]; Assert(level_num <= Last_level && level_num >= Last_secret_level && level_num != 0); level_name = get_level_file(level_num); if (!load_level(level_name)) Current_level_num=level_num; gr_use_palette_table( "palette.256" ); show_boxed_message(TXT_LOADING, 0); #ifdef RELEASE timer_delay(F1_0); #endif #ifdef NETWORK my_segments_checksum = netmisc_calc_checksum(); #endif load_endlevel_data(level_num); load_custom_data(level_name); #ifdef NETWORK reset_network_objects(); #endif Players[Player_num] = save_player; set_sound_sources(); songs_play_level_song( Current_level_num, 0 ); gr_palette_load(gr_palette); //actually load the palette if ( page_in_textures ) piggy_load_level_data(); }
// ----------------------------------------------------------------------------- void say_totals_all(void) { int i; FILE *my_file; my_file = fopen( "levels.all", "wt" ); // -- mprintf((1, "Fileno = %i\n", fileno(my_file))); if (!my_file) { char ErrorMessage[200]; sprintf( ErrorMessage, "ERROR: Unable to open levels.all\nErrno=%i", errno ); stop_time(); gr_palette_load(gr_palette); nm_messagebox( NULL, 1, "Ok", ErrorMessage ); start_time(); return; } for (i=First_dump_level; i<=Last_dump_level; i++) { mprintf((0, "Level %i\n", i+1)); load_level(Adam_level_names[i]); say_totals(my_file, Adam_level_names[i]); } //--05/17/95-- for (i=0; i<NUM_SHAREWARE_LEVELS; i++) { //--05/17/95-- mprintf((0, "Level %i\n", i+1)); //--05/17/95-- load_level(Shareware_level_names[i]); //--05/17/95-- say_totals(my_file, Shareware_level_names[i]); //--05/17/95-- } //--05/17/95-- //--05/17/95-- for (i=0; i<NUM_REGISTERED_LEVELS; i++) { //--05/17/95-- mprintf((0, "Level %i\n", i+1+NUM_SHAREWARE_LEVELS)); //--05/17/95-- load_level(Registered_level_names[i]); //--05/17/95-- say_totals(my_file, Registered_level_names[i]); //--05/17/95-- } fclose(my_file); }
void kmatrix_view(int network) { kmatrix_screen *km; window *wind; int i = 0; MALLOC(km, kmatrix_screen, 1); if (!km) return; gr_init_bitmap_data(&km->background); if (pcx_read_bitmap(STARS_BACKGROUND, &km->background, BM_LINEAR, gr_palette) != PCX_ERROR_NONE) { d_free(km); return; } gr_palette_load(gr_palette); km->network = network; km->end_time = -1; km->playing = 0; set_screen_mode( SCREEN_MENU ); game_flush_inputs(); for (i=0;i<MAX_PLAYERS;i++) digi_kill_sound_linked_to_object (Players[i].objnum); wind = window_create(&grd_curscreen->sc_canvas, 0, 0, SWIDTH, SHEIGHT, (int (*)(window *, d_event *, void *))kmatrix_handler, km); if (!wind) { d_free(km); return; } while (window_exists(wind)) event_process(); gr_free_bitmap_data(&km->background); d_free(km); }
static void credits_show_common(RAIIPHYSFS_File file, const int have_bin_file) { palette_array_t backdrop_palette; auto cr = make_unique<credits>(); *cr = {}; cr->file = std::move(file); cr->have_bin_file = have_bin_file; set_screen_mode(SCREEN_MENU); #if defined(DXX_BUILD_DESCENT_II) gr_use_palette_table( "credits.256" ); #endif cr->backdrop.bm_data=NULL; const auto pcx_error = pcx_read_bitmap(STARS_BACKGROUND, cr->backdrop,backdrop_palette); if (pcx_error != PCX_ERROR_NONE) { return; } songs_play_song( SONG_CREDITS, 1 ); gr_remap_bitmap_good(cr->backdrop,backdrop_palette, -1, -1); gr_set_current_canvas(NULL); show_fullscr(cr->backdrop); gr_palette_load( gr_palette ); key_flush(); credits *pcr = cr.get(); const auto wind = window_create(grd_curscreen->sc_canvas, 0, 0, SWIDTH, SHEIGHT, credits_handler, cr.release()); if (!wind) { d_event event = { EVENT_WINDOW_CLOSE }; credits_handler(NULL, event, pcr); return; } event_process_all(); }
void do_screen_message(char *fmt, ...) { va_list arglist; grs_bitmap background; char msg[1024]; if (Game_mode & GM_MULTI) return; gr_init_bitmap_data(&background); if (pcx_read_bitmap(Menu_pcx_name, &background, BM_LINEAR, gr_palette) != PCX_ERROR_NONE) return; gr_palette_load(gr_palette); va_start(arglist, fmt); vsprintf(msg, fmt, arglist); va_end(arglist); nm_messagebox1(NULL, (int (*)(newmenu *, d_event *, void *))draw_rock, &background, 1, TXT_OK, msg); gr_free_bitmap_data(&background); }
main(int argc, char * argv[] ) { int x, y; grs_bitmap bmp; grs_bitmap bmp1; ubyte palette[768]; minit(); printf( "Reading %s...\n", "john.pcx" ); gr_init( SM_320x200U ); bmp.bm_data = NULL; pcx_read_bitmap( "big.pcx", &bmp, BM_LINEAR, palette ); gr_palette_load( palette ); key_init(); x = y = 0; while(!keyd_pressed[KEY_ESC]) { y += keyd_pressed[KEY_UP] - keyd_pressed[KEY_DOWN]; x += keyd_pressed[KEY_LEFT] - keyd_pressed[KEY_RIGHT]; gr_bitmap( x, y, &bmp ); } }
//loads a level (.LVL) file from disk //returns 0 if success, else error code int load_level(const char * filename_passed) { #ifdef EDITOR int use_compiled_level=1; #endif PHYSFS_file * LoadFile; char filename[PATH_MAX]; int sig, minedata_offset, gamedata_offset, hostagetext_offset; int mine_err, game_err; #ifdef NETWORK int i; #endif #ifdef NETWORK if (Game_mode & GM_NETWORK) { for (i=0;i<MAX_POWERUP_TYPES;i++) { MaxPowerupsAllowed[i]=0; PowerupsInMine[i]=0; } } #endif #ifdef COMPACT_SEGS ncache_flush(); #endif #ifndef RELEASE Level_being_loaded = filename_passed; #endif strcpy(filename,filename_passed); #ifdef EDITOR //if we have the editor, try the LVL first, no matter what was passed. //if we don't have an LVL, try what was passed or SDL/RDL //if we don't have the editor, we just use what was passed change_filename_extension(filename,filename_passed,".lvl"); use_compiled_level = 0; if (!PHYSFSX_exists(filename,1)) { char *p = strrchr(filename_passed, '.'); if (d_stricmp(p, ".lvl")) strcpy(filename, filename_passed); // set to what was passed else change_filename_extension(filename, filename, ".rdl"); use_compiled_level = 1; } #endif if (!PHYSFSX_exists(filename,1)) sprintf(filename,"%s%s",MISSION_DIR,filename_passed); LoadFile = PHYSFSX_openReadBuffered( filename ); if (!LoadFile) { #ifdef EDITOR return 1; #else Error("Can't open file <%s>\n",filename); #endif } strcpy( Gamesave_current_filename, filename ); sig = PHYSFSX_readInt(LoadFile); Gamesave_current_version = PHYSFSX_readInt(LoadFile); minedata_offset = PHYSFSX_readInt(LoadFile); gamedata_offset = PHYSFSX_readInt(LoadFile); Assert(sig == MAKE_SIG('P','L','V','L')); (void)sig; if (Gamesave_current_version < 5) hostagetext_offset = PHYSFSX_readInt(LoadFile); PHYSFSX_fseek(LoadFile,minedata_offset,SEEK_SET); #ifdef EDITOR if (!use_compiled_level) mine_err = load_mine_data(LoadFile); else #endif //NOTE LINK TO ABOVE!! mine_err = load_mine_data_compiled(LoadFile); /* !!!HACK!!! * Descent 1 - Level 19: OBERON MINE has some ugly overlapping rooms (segment 484). * HACK to make this issue less visible by moving one vertex a little. */ if (Current_mission && !d_stricmp("Descent: First Strike",Current_mission_longname) && !d_stricmp("level19.rdl",filename) && PHYSFS_fileLength(LoadFile) == 136706) Vertices[1905].z =-385*F1_0; if (mine_err == -1) { //error!! PHYSFS_close(LoadFile); return 2; } PHYSFSX_fseek(LoadFile,gamedata_offset,SEEK_SET); game_err = load_game_data(LoadFile); if (game_err == -1) { //error!! PHYSFS_close(LoadFile); return 3; } (void)hostagetext_offset; //======================== CLOSE FILE ============================= PHYSFS_close( LoadFile ); #if 0 //def EDITOR #ifndef RELEASE write_game_text_file(filename); if (Errors_in_mine) { if (is_real_level(filename)) { char ErrorMessage[200]; sprintf( ErrorMessage, "Warning: %i errors in %s!\n", Errors_in_mine, Level_being_loaded ); stop_time(); gr_palette_load(gr_palette); nm_messagebox( NULL, 1, "Continue", ErrorMessage ); start_time(); } } #endif #endif #ifdef EDITOR //If an old version, ask the use if he wants to save as new version if (((LEVEL_FILE_VERSION>1) && Gamesave_current_version<LEVEL_FILE_VERSION) || mine_err==1 || game_err==1) { char ErrorMessage[200]; sprintf( ErrorMessage, "You just loaded a old version level. Would\n" "you like to save it as a current version level?"); gr_palette_load(gr_palette); if (nm_messagebox( NULL, 2, "Don't Save", "Save", ErrorMessage )==1) save_level(filename); } #endif #ifdef EDITOR if (EditorWindow) editor_status_fmt("Loaded NEW mine %s, \"%s\"",filename,Current_level_name); #endif #if !defined(NDEBUG) && !defined(COMPACT_SEGS) if (check_segment_connections()) nm_messagebox( "ERROR", 1, "Ok", "Connectivity errors detected in\n" "mine. See monochrome screen for\n" "details, and contact Matt or Mike." ); #endif return 0; }
//called when the player has died void DoPlayerDead() { int cycle_window_vis = 1; #ifdef NETWORK if ( (Game_mode & GM_MULTI) && (Netgame.SpawnStyle == SPAWN_STYLE_PREVIEW)) { cycle_window_vis = 0; } #endif if (Game_wind && cycle_window_vis) window_set_visible(Game_wind, 0); reset_palette_add(); gr_palette_load (gr_palette); dead_player_end(); //terminate death sequence (if playing) #ifdef EDITOR if (Game_mode == GM_EDITOR) { //test mine, not real level object * player = &Objects[Players[Player_num].objnum]; //nm_messagebox( "You're Dead!", 1, "Continue", "Not a real game, though." ); if (Game_wind) window_set_visible(Game_wind, 1); load_level("gamesave.lvl"); init_player_stats_new_ship(Player_num); player->flags &= ~OF_SHOULD_BE_DEAD; StartLevel(0); return; } #endif #ifdef NETWORK if ( Game_mode&GM_MULTI ) { multi_do_death(Players[Player_num].objnum); } else #endif { //Note link to above else! Players[Player_num].lives--; if (Players[Player_num].lives == 0) { DoGameOver(); return; } } if ( Control_center_destroyed ) { int rval; //clear out stuff so no bonus Players[Player_num].hostages_on_board = 0; Players[Player_num].energy = 0; Players[Player_num].shields = 0; #ifdef NETWORK Players[Player_num].connected = CONNECT_DIED_IN_MINE; #endif do_screen_message(TXT_DIED_IN_MINE); // Give them some indication of what happened if (Current_level_num == Last_level) { #ifdef NETWORK if ((Game_mode & GM_MULTI) && !(Game_mode & GM_MULTI_COOP)) { multi_endlevel_score(); rval = AdvanceLevel(0); //if finished, go on to next level } else #endif { // Note link to above else! rval = AdvanceLevel(0); //if finished, go on to next level DoEndLevelScoreGlitz(0); } init_player_stats_new_ship(Player_num); last_drawn_cockpit = -1; } else { #ifdef NETWORK if (Game_mode & GM_MULTI) multi_endlevel_score(); else #endif DoEndLevelScoreGlitz(0); // Note above link! rval = AdvanceLevel(0); //if finished, go on to next level init_player_stats_new_ship(Player_num); last_drawn_cockpit = -1; } if (rval) { #ifndef SHAREWARE if (PLAYING_BUILTIN_MISSION) #endif scores_maybe_add_player(0); if (Game_wind) window_close(Game_wind); // Exit out of game loop } } else { init_player_stats_new_ship(Player_num); StartLevel(1); } if (Game_wind && cycle_window_vis) window_set_visible(Game_wind, 1); reset_time(); }
// ----------------------------------------------------------------------------- // Does the bonus scoring. // Call with dead_flag = 1 if player died, but deserves some portion of bonus (only skill points), anyway. void DoEndLevelScoreGlitz(int network) { int level_points, skill_points, energy_points, shield_points, hostage_points; int all_hostage_points; int endgame_points; char all_hostage_text[64]; char endgame_text[64]; #define N_GLITZITEMS 9 char m_str[N_GLITZITEMS][30]; newmenu_item m[9]; int i,c; char title[128]; int is_last_level; gr_palette_load( gr_palette ); level_points = Players[Player_num].score-Players[Player_num].last_score; if (!cheats.enabled) { if (Difficulty_level > 1) { skill_points = level_points*(Difficulty_level-1)/2; skill_points -= skill_points % 100; } else skill_points = 0; shield_points = f2i(Players[Player_num].shields) * 10 * (Difficulty_level+1); energy_points = f2i(Players[Player_num].energy) * 5 * (Difficulty_level+1); hostage_points = Players[Player_num].hostages_on_board * 500 * (Difficulty_level+1); } else { skill_points = 0; shield_points = 0; energy_points = 0; hostage_points = 0; } all_hostage_text[0] = 0; endgame_text[0] = 0; if (!cheats.enabled && (Players[Player_num].hostages_on_board == Players[Player_num].hostages_level)) { all_hostage_points = Players[Player_num].hostages_on_board * 1000 * (Difficulty_level+1); sprintf(all_hostage_text, "%s%i\n", TXT_FULL_RESCUE_BONUS, all_hostage_points); } else all_hostage_points = 0; if (!cheats.enabled && !(Game_mode & GM_MULTI) && (Players[Player_num].lives) && (Current_level_num == Last_level)) { //player has finished the game! endgame_points = Players[Player_num].lives * 10000; sprintf(endgame_text, "%s%i\n", TXT_SHIP_BONUS, endgame_points); is_last_level=1; } else endgame_points = is_last_level = 0; add_bonus_points_to_score(skill_points + energy_points + shield_points + hostage_points + all_hostage_points + endgame_points); c = 0; sprintf(m_str[c++], "%s%i", TXT_SHIELD_BONUS, shield_points); // Return at start to lower menu... sprintf(m_str[c++], "%s%i", TXT_ENERGY_BONUS, energy_points); sprintf(m_str[c++], "%s%i", TXT_HOSTAGE_BONUS, hostage_points); sprintf(m_str[c++], "%s%i", TXT_SKILL_BONUS, skill_points); sprintf(m_str[c++], "%s", all_hostage_text); if (!(Game_mode & GM_MULTI) && (Players[Player_num].lives) && (Current_level_num == Last_level)) sprintf(m_str[c++], "%s", endgame_text); sprintf(m_str[c++], "%s%i\n", TXT_TOTAL_BONUS, shield_points+energy_points+hostage_points+skill_points+all_hostage_points+endgame_points); sprintf(m_str[c++], "%s%i", TXT_TOTAL_SCORE, Players[Player_num].score); for (i=0; i<c; i++) { m[i].type = NM_TYPE_TEXT; m[i].text = m_str[i]; } // m[c].type = NM_TYPE_MENU; m[c++].text = "Ok"; if (Current_level_num < 0) sprintf(title,"%s%s %d %s\n %s %s",is_last_level?"\n\n\n":"\n",TXT_SECRET_LEVEL, -Current_level_num, TXT_COMPLETE, Current_level_name, TXT_DESTROYED); else sprintf(title,"%s%s %d %s\n%s %s",is_last_level?"\n\n\n":"\n",TXT_LEVEL, Current_level_num, TXT_COMPLETE, Current_level_name, TXT_DESTROYED); Assert(c <= N_GLITZITEMS); #ifdef NETWORK if ( network && (Game_mode & GM_NETWORK) ) newmenu_do2(NULL, title, c, m, multi_endlevel_poll1, NULL, 0, Menu_pcx_name); else #endif // Note link! newmenu_do2(NULL, title, c, m, NULL, NULL, 0, Menu_pcx_name); }
//called when the player is starting a new level for normal game mode and restore state void StartNewLevelSub(int level_num, int page_in_textures, int secret_flag) { /* * This flag is present for compatibility with D2X. Set it to zero * so the optimizer deletes all reference to it. */ secret_flag = 0; if (!(Game_mode & GM_MULTI)) { last_drawn_cockpit = -1; } if (Newdemo_state == ND_STATE_PAUSED) Newdemo_state = ND_STATE_RECORDING; if (Newdemo_state == ND_STATE_RECORDING) { newdemo_set_new_level(level_num); newdemo_record_start_frame(FrameTime ); } LoadLevel(level_num, page_in_textures); Assert(Current_level_num == level_num); //make sure level set right gameseq_init_network_players(); // Initialize the Players array for // this level #ifdef NETWORK if (Game_mode & GM_NETWORK) { if(multi_level_sync()) // After calling this, Player_num is set { songs_play_song( SONG_TITLE, 1 ); // level song already plays but we fail to start level... return; } } #endif HUD_clear_messages(); automap_clear_visited(); init_player_stats_level(secret_flag); gr_use_palette_table( "palette.256" ); gr_palette_load(gr_palette); #ifndef SHAREWARE #ifdef NETWORK if ((Game_mode & GM_MULTI_COOP) && Network_rejoined) { int i; for (i = 0; i < N_players; i++) Players[i].flags |= Netgame.player_flags[i]; } #endif #endif Viewer = &Objects[Players[Player_num].objnum]; #ifdef NETWORK if (Game_mode & GM_MULTI) { multi_prep_level(); // Removes robots from level if necessary } #endif gameseq_remove_unused_players(); Game_suspended = 0; Control_center_destroyed = 0; init_cockpit(); init_robots_for_level(); init_ai_objects(); init_morphs(); init_all_matcens(); reset_palette_add(); if (!(Game_mode & GM_MULTI) && !cheats.enabled) set_highest_level(Current_level_num); reset_special_effects(); #ifdef OGL ogl_cache_level_textures(); #endif #ifdef NETWORK if (Network_rejoined == 1) { Network_rejoined = 0; StartLevel(1); } else #endif StartLevel(0); // Note link to above if! copy_defaults_to_robot_all(); init_controlcen_for_level(); // Say player can use FLASH cheat to mark path to exit. Last_level_path_created = -1; // Initialise for palette_restore() if (!((Game_mode & GM_MULTI) && (Newdemo_state != ND_STATE_PLAYBACK))) palette_save(); if (!Game_wind) game(); }
main(int argc,char **argv) { int ret; grs_bitmap my_bitmap; ubyte my_palette[256*3]; grs_bitmap *bm_list[100]; int n_bitmaps; char key; #if 0 { int new_len,i; new_len=rle_span(new_span,test_span,sizeof(test_span)); printf("old span (%d): ",sizeof(test_span)); for (i=0;i<sizeof(test_span);i++) printf("%d ",test_span[i]); printf("\nnew span (%d): ",new_len); for (i=0;i<new_len;i++) printf("%d ",new_span[i]); exit(0); } #endif #ifdef ANIM_TEST ret = iff_read_animbrush(argv[1],bm_list,100,&n_bitmaps,&my_palette); #else ret = iff_read_bitmap(argv[1],&my_bitmap,BM_LINEAR,&my_palette); bm_list[0] = &my_bitmap; n_bitmaps = 1; #endif printf("ret = %d\n",ret); printf("error message = <%s>",iff_errormsg(ret)); if (ret == IFF_NO_ERROR) { int i; vga_init(); gr_init(); vga_set_mode(SM_320x200C); for (i=0;i<n_bitmaps;) { if (argc>2) { ret = iff_write_bitmap(argv[2],bm_list[i],&my_palette); printf("ret = %d\n",ret); } //gr_pal_setblock(0,256,&my_palette); gr_palette_load(&my_palette); //gr_pal_fade_in(grd_curscreen->pal); //in case palette is blacked gr_ubitmap(0,0,bm_list[i]); key = getch(); if (key=='-') {if (i) i--;} else i++; } gr_close(); for (i=0;i<n_bitmaps;i++) { free(bm_list[i]->bm_data); #ifdef ANIM_TEST free(bm_list[i]); #endif } } }
//load a palette by name. returns 1 if new palette loaded, else 0 //if used_for_level is set, load pig, etc. //if no_change_screen is set, the current screen does not get remapped, //and the hardware palette does not get changed int load_palette(char *name,int used_for_level,int no_change_screen) { char pigname[FILENAME_LEN]; ubyte old_pal[256*3]; //special hack to tell that palette system about a pig that's been loaded elsewhere if (used_for_level == -2) { strncpy(last_palette_loaded_pig,name,sizeof(last_palette_loaded_pig)); return 1; } if (name==NULL) name = last_palette_loaded_pig; if (used_for_level && stricmp(last_palette_loaded_pig,name) != 0) { _splitpath(name,NULL,NULL,pigname,NULL); strcat(pigname,".pig"); //if not editor, load pig first so small install message can come //up in old palette. If editor version, we must load the pig after //the palette is loaded so we can remap new textures. #ifndef EDITOR piggy_new_pigfile(pigname); #endif } if (stricmp(last_palette_loaded,name) != 0) { memcpy(old_pal,gr_palette,sizeof(old_pal)); strncpy(last_palette_loaded,name,sizeof(last_palette_loaded)); gr_use_palette_table(name); if (Function_mode == FMODE_GAME && !no_change_screen) gr_remap_bitmap_good( &grd_curscreen->sc_canvas.cv_bitmap, old_pal, -1, -1 ); #if defined(POLY_ACC) if (bg.bmp && bg.bmp->bm_type == BM_LINEAR) #else if (bg.bmp) #endif gr_remap_bitmap_good( bg.bmp, old_pal, -1, -1 ); if (!gr_palette_faded_out && !no_change_screen) gr_palette_load(gr_palette); remap_fonts_and_menus(0); Color_0_31_0 = -1; //for gauges HUD_color = -1; load_background_bitmap(); g3_remap_interp_colors(); } if (used_for_level && stricmp(last_palette_loaded_pig,name) != 0) { strncpy(last_palette_loaded_pig,name,sizeof(last_palette_loaded_pig)); #ifdef EDITOR piggy_new_pigfile(pigname); #endif texmerge_flush(); rle_cache_flush(); } return 1; }
//called when the player has died void DoPlayerDead() { reset_palette_add(); gr_palette_load (gr_palette); dead_player_end(); //terminate death sequence (if playing) #ifdef HOSTAGE_FACES stop_all_hostage_clips(); #endif #ifdef EDITOR if (Game_mode == GM_EDITOR) { //test mine, not real level object * player = &Objects[Players[Player_num].objnum]; //nm_messagebox( "You're Dead!", 1, "Continue", "Not a real game, though." ); load_level("gamesave.lvl"); init_player_stats_new_ship(); player->flags &= ~OF_SHOULD_BE_DEAD; StartLevel(0); return; } #endif #ifdef NETWORK if ( Game_mode&GM_MULTI ) { multi_do_death(Players[Player_num].objnum); } else #endif { //Note link to above else! Players[Player_num].lives--; if (Players[Player_num].lives == 0) { DoGameOver(); return; } } if ( Fuelcen_control_center_destroyed ) { int rval; //clear out stuff so no bonus Players[Player_num].hostages_on_board = 0; Players[Player_num].energy = 0; Players[Player_num].shields = 0; Players[Player_num].connected = 3; died_in_mine_message(); // Give them some indication of what happened if (Current_level_num == Last_level) { #ifdef NETWORK if ((Game_mode & GM_MULTI) && !(Game_mode & GM_MULTI_COOP)) { multi_endlevel_score(); rval = AdvanceLevel(0); //if finished, go on to next level } else #endif { // Note link to above else! rval = AdvanceLevel(0); //if finished, go on to next level DoEndLevelScoreGlitz(0); } init_player_stats_new_ship(); last_drawn_cockpit = -1; } else { #ifdef NETWORK if (Game_mode & GM_MULTI) multi_endlevel_score(); else #endif DoEndLevelScoreGlitz(0); // Note above link! rval = AdvanceLevel(0); //if finished, go on to next level init_player_stats_new_ship(); last_drawn_cockpit = -1; } if (rval) { #ifndef SHAREWARE if (PLAYING_BUILTIN_MISSION) #endif scores_maybe_add_player(0); longjmp( LeaveGame, 1 ); // Exit out of game loop } } else { init_player_stats_new_ship(); StartLevel(1); } }
int gr_palette_fade_in(ubyte *pal, int nsteps, int allow_keys) { int i, j, k, ncolors; ubyte c; fix fade_palette[768]; fix fade_palette_delta[768]; SDL_Palette *palette; SDL_Color fade_colors[256]; if (!gr_palette_faded_out) return 0; palette = screen->format->palette; if (palette == NULL) { return -1; // Display is not palettised } ncolors = palette->ncolors; for (i=0; i<768; i++ ) { gr_current_pal[i] = pal[i]; fade_palette[i] = 0; fade_palette_delta[i] = i2f(pal[i]) / nsteps; } for (j=0; j<nsteps; j++ ) { for (i=0, k = 0; k<256; k++ ) { fade_palette[i] += fade_palette_delta[i]; if (fade_palette[i] > i2f(pal[i] + gr_palette_gamma) ) fade_palette[i] = i2f(pal[i] + gr_palette_gamma); c = f2i(fade_palette[i]); if (c > 63) c = 63; fade_colors[k].r = c * 4; i++; fade_palette[i] += fade_palette_delta[i]; if (fade_palette[i] > i2f(pal[i] + gr_palette_gamma) ) fade_palette[i] = i2f(pal[i] + gr_palette_gamma); c = f2i(fade_palette[i]); if (c > 63) c = 63; fade_colors[k].g = c * 4; i++; fade_palette[i] += fade_palette_delta[i]; if (fade_palette[i] > i2f(pal[i] + gr_palette_gamma) ) fade_palette[i] = i2f(pal[i] + gr_palette_gamma); c = f2i(fade_palette[i]); if (c > 63) c = 63; fade_colors[k].b = c * 4; i++; } SDL_SetColors(screen, fade_colors, 0, 256); } //added on 980913 by adb to fix palette problems gr_palette_load(pal); //end changes by adb gr_palette_faded_out = 0; return 0; }
void init_editor() { void med_show_warning(char *s); // first, make sure we can find the files we need PHYSFSX_addRelToSearchPath("editor/data", 1); // look in source directory first (for work in progress) PHYSFSX_addRelToSearchPath("editor", 1); // then in editor directory PHYSFSX_addRelToSearchPath("editor.zip", 1); // then in a zip file ui_init(); init_med_functions(); // Must be called before medlisp_init ui_pad_read( 0, "segmove.pad" ); ui_pad_read( 1, "segsize.pad" ); ui_pad_read( 2, "curve.pad" ); ui_pad_read( 3, "texture.pad" ); ui_pad_read( 4, "object.pad" ); ui_pad_read( 5, "objmov.pad" ); ui_pad_read( 6, "group.pad" ); ui_pad_read( 7, "lighting.pad" ); ui_pad_read( 8, "test.pad" ); medkey_init(); game_flush_inputs(); editor_font = gr_init_font( "pc8x16.fnt" ); menubar_init( "MED.MNU" ); Draw_all_segments = 1; // Say draw all segments, not just connected ones if (!Cursegp) Cursegp = &Segments[0]; init_autosave(); // atexit(close_editor); Clear_window = 1; // do full window clear. InitCurve(); restore_effect_bitmap_icons(); if (!set_screen_mode(SCREEN_EDITOR)) { set_screen_mode(SCREEN_MENU); show_menus(); //force back into menu return; } gr_use_palette_table( "palette.256" ); gr_palette_load( gr_palette ); //Editor renders into full (320x200) game screen game_init_render_buffers(320, 200, VR_NONE); gr_init_sub_canvas( &VR_editor_canvas, &grd_curscreen->sc_canvas, 0, 0, SWIDTH, SHEIGHT ); Canv_editor = &VR_editor_canvas; gr_set_current_canvas( Canv_editor ); init_editor_screen(); // load the main editor dialog gr_set_current_canvas( NULL ); gr_set_curfont(editor_font); set_warn_func(med_show_warning); // _MARK_("start of editor");//Nuked to compile -KRB //@@ //create a camera for viewing in the editor. copy position from ConsoleObject //@@ camera_objnum = obj_create(OBJ_CAMERA,0,ConsoleObject->segnum,&ConsoleObject->pos,&ConsoleObject->orient,0); //@@ Viewer = &Objects[camera_objnum]; //@@ slew_init(Viewer); //camera is slewing Viewer = ConsoleObject; slew_init(ConsoleObject); init_player_object(); Update_flags = UF_ALL; //set the wire-frame window to be the current view current_view = &LargeView; if (faded_in==0) { faded_in = 1; //gr_pal_fade_in( grd_curscreen->pal ); } gr_set_current_canvas( GameViewBox->canvas ); gr_set_curfont(editor_font); //gr_setcolor( CBLACK ); //gr_deaccent_canvas(); //gr_grey_canvas(); gr_set_curfont(editor_font); FNTScaleX = FNTScaleY = 1; // No font scaling! ui_pad_goto(padnum); ModeFlag = 0; gamestate_restore_check(); }
void modex_print_message(int x, int y, char *str) { #ifndef AUTOMAP_DIRECT_RENDER #ifndef AUTOMAP_NO_PAGING int i; for (i=0; i<2; i++ ) { gr_set_current_canvas(&Pages[i]); #else { gr_set_current_canvas(OffscreenPage); #endif #endif modex_printf(x, y, str, GFONT_MEDIUM_1); #ifndef AUTOMAP_DIRECT_RENDER } gr_set_current_canvas(&DrawingPages[current_page]); #endif } extern void GameLoop(int, int ); extern int set_segment_depths(int start_seg, ubyte *segbuf); u_int32_t automap_mode = SM(640,480); int automap_width = 640; int automap_height = 480; int automap_use_game_res=0; int nice_automap=0; void do_automap( int key_code ) { int done=0; vms_matrix tempm; vms_angvec tangles; int leave_mode=0; int first_time=1; // int pcx_error; int c; // char filename[] = "MAP.PCX"; fix entry_time; int pause_game=1; // Set to 1 if everything is paused during automap...No pause during net. fix t1, t2; control_info saved_control_info; grs_bitmap Automap_background; int Max_segments_away = 0; int SegmentLimit = 1; //added on 10/28/98 by adb to fix compile versions #if !defined (NDEBUG) || (!defined(AUTOMAP_NO_PAGING) && !defined(AUTOMAP_DIRECT_RENDER)) int i; #endif key_code = key_code; // disable warning... if ((Game_mode & GM_MULTI) && (Function_mode == FMODE_GAME) && (!Endlevel_sequence)) pause_game = 0; if (pause_game) stop_time(); create_name_canv(); Max_edges = min(MAX_EDGES_FROM_VERTS(Num_vertices),MAX_EDGES); //make maybe smaller than max //Edges = malloc( sizeof(Edge_info)*Max_edges); //if ( Edges == NULL ) { // mprintf((0, "Couldn't get %dK for automap!", sizeof(Edge_info)*Max_edges/1024)); // return; //} //DrawingListBright = malloc( sizeof(short)*Max_edges); //if ( DrawingListBright == NULL ) { // mprintf((0, "Couldn't get %dK for automap!", sizeof(short)*Max_edges/1024)); // return; //} mprintf( (0, "Num_vertices=%d, Max_edges=%d, (MAX:%d)\n", Num_vertices, Max_edges, MAX_EDGES )); mprintf( (0, "Allocated %d K for automap edge list\n", (sizeof(Edge_info)+sizeof(short))*Max_edges/1024 )); //edit 4/23/99 Matt Mueller - don't switch res unless we need to if (grd_curscreen->sc_mode != AUTOMAP_MODE) gr_set_mode( AUTOMAP_MODE ); else gr_set_current_canvas(NULL); //end edit -MM automap_width=grd_curscreen->sc_canvas.cv_bitmap.bm_w; automap_height=grd_curscreen->sc_canvas.cv_bitmap.bm_h; gr_palette_clear(); #ifndef AUTOMAP_DIRECT_RENDER gr_init_sub_canvas(&Pages[0],grd_curcanv,0,0,automap_width,automap_height); #ifndef AUTOMAP_NO_PAGING // NOTICE: should be 0,401! FIXME! gr_init_sub_canvas(&Pages[1],grd_curcanv,0,0,automap_width,automap_height); gr_init_sub_canvas(&DrawingPages[0],&Pages[0],0,0,automap_width,automap_height); gr_init_sub_canvas(&DrawingPages[1],&Pages[1],0,0,automap_width,automap_height); #else OffscreenPage = gr_create_canvas( automap_width,automap_height ); if (!OffscreenPage) { nm_messagebox("No memory for automap", 1, "Ok"); return; } gr_init_sub_canvas(&DrawingPages[0],OffscreenPage,0,0,automap_width,automap_height); #endif #endif gr_init_bitmap_data (&Automap_background); // pcx_error = pcx_read_bitmap(filename,&Automap_background,BM_LINEAR,NULL); // if ( pcx_error != PCX_ERROR_NONE ) { // printf("File %s - PCX error: %s",filename,pcx_errormsg(pcx_error)); // Error("File %s - PCX error: %s",filename,pcx_errormsg(pcx_error)); // return; // } #ifndef AUTOMAP_DIRECT_RENDER #ifndef AUTOMAP_NO_PAGING for (i=0; i<2; i++ ) { gr_set_current_canvas(&Pages[i]); #else { gr_set_current_canvas(OffscreenPage); #endif // gr_bitmap( 0, 0, &Automap_background ); // modex_printf( 40, 22,TXT_AUTOMAP,GFONT_BIG_1); // modex_printf( 70,353,TXT_TURN_SHIP,GFONT_SMALL); // modex_printf( 70,369,TXT_SLIDE_UPDOWN,GFONT_SMALL); // modex_printf( 70,385,TXT_VIEWING_DISTANCE,GFONT_SMALL); } #ifdef AUTOMAP_NO_PAGING //killed 05/17/99 Matt Mueller - this seems to merely copy undefined bytes around.. not needed //--killed-- gr_bm_ubitblt(automap_width,automap_height, 0, 0, 0, 0, &OffscreenPage->cv_bitmap,&Pages[0].cv_bitmap); //end kill -MM #endif gr_free_bitmap_data (&Automap_background); gr_set_current_canvas(&DrawingPages[current_page]); #endif automap_build_edge_list(); if ( ViewDist==0 ) ViewDist = ZOOM_DEFAULT; ViewMatrix = Objects[Players[Player_num].objnum].orient; tangles.p = PITCH_DEFAULT; tangles.h = 0; tangles.b = 0; done = 0; view_target = Objects[Players[Player_num].objnum].pos; t1 = entry_time = timer_get_fixed_seconds(); t2 = t1; //Fill in Automap_visited from Objects[Players[Player_num].objnum].segnum Max_segments_away = set_segment_depths(Objects[Players[Player_num].objnum].segnum, Automap_visited); SegmentLimit = Max_segments_away; adjust_segment_limit(SegmentLimit); while(!done) { if ( leave_mode==0 && Controls.automap_state && (timer_get_fixed_seconds()-entry_time)>LEAVE_TIME) leave_mode = 1; if ( !Controls.automap_state && (leave_mode==1) ) done=1; if (!pause_game) { ushort old_wiggle; saved_control_info = Controls; // Save controls so we can zero them memset(&Controls,0,sizeof(control_info)); // Clear everything... old_wiggle = ConsoleObject->mtype.phys_info.flags & PF_WIGGLE; // Save old wiggle ConsoleObject->mtype.phys_info.flags &= ~PF_WIGGLE; // Turn off wiggle #ifdef NETWORK if (multi_menu_poll()) done = 1; #endif // GameLoop( 0, 0 ); // Do game loop with no rendering and no reading controls. ConsoleObject->mtype.phys_info.flags |= old_wiggle; // Restore wiggle Controls = saved_control_info; } controls_read_all(); if ( Controls.automap_down_count ) { if (leave_mode==0) done = 1; c = 0; } while( (c=key_inkey()) ) { switch( c ) { #ifndef NDEBUG case KEY_BACKSP: Int3(); break; #endif case KEY_PRINT_SCREEN: save_screen_shot(1); break; case KEY_ESC: if (leave_mode==0) done = 1; break; case KEY_ALTED+KEY_F: // Alt+F shows full map, if cheats enabled if (Cheats_enabled) { uint t; t = Players[Player_num].flags; Players[Player_num].flags |= PLAYER_FLAGS_MAP_ALL_CHEAT; automap_build_edge_list(); Players[Player_num].flags=t; } break; #ifndef NDEBUG case KEY_DEBUGGED+KEY_F: { for (i=0; i<=Highest_segment_index; i++ ) Automap_visited[i] = 1; automap_build_edge_list(); Max_segments_away = set_segment_depths(Objects[Players[Player_num].objnum].segnum, Automap_visited); SegmentLimit = Max_segments_away; adjust_segment_limit(SegmentLimit); } break; #endif case KEY_MINUS: if (SegmentLimit > 1) { SegmentLimit--; adjust_segment_limit(SegmentLimit); } break; case KEY_EQUAL: if (SegmentLimit < Max_segments_away) { SegmentLimit++; adjust_segment_limit(SegmentLimit); } break; } } if ( Controls.fire_primary_down_count ) { // Reset orientation ViewDist = ZOOM_DEFAULT; tangles.p = PITCH_DEFAULT; tangles.h = 0; tangles.b = 0; view_target = Objects[Players[Player_num].objnum].pos; } ViewDist -= Controls.forward_thrust_time*ZOOM_SPEED_FACTOR; tangles.p += fixdiv( Controls.pitch_time, ROT_SPEED_DIVISOR ); tangles.h += fixdiv( Controls.heading_time, ROT_SPEED_DIVISOR ); tangles.b += fixdiv( Controls.bank_time, ROT_SPEED_DIVISOR*2 ); if ( Controls.vertical_thrust_time || Controls.sideways_thrust_time ) { vms_angvec tangles1; vms_vector old_vt; old_vt = view_target; tangles1 = tangles; vm_angles_2_matrix(&tempm,&tangles1); vm_matrix_x_matrix(&ViewMatrix,&Objects[Players[Player_num].objnum].orient,&tempm); vm_vec_scale_add2( &view_target, &ViewMatrix.uvec, Controls.vertical_thrust_time*SLIDE_SPEED ); vm_vec_scale_add2( &view_target, &ViewMatrix.rvec, Controls.sideways_thrust_time*SLIDE_SPEED ); if ( vm_vec_dist_quick( &view_target, &Objects[Players[Player_num].objnum].pos) > i2f(1000) ) { view_target = old_vt; } } vm_angles_2_matrix(&tempm,&tangles); vm_matrix_x_matrix(&ViewMatrix,&Objects[Players[Player_num].objnum].orient,&tempm); if ( ViewDist < ZOOM_MIN_VALUE ) ViewDist = ZOOM_MIN_VALUE; if ( ViewDist > ZOOM_MAX_VALUE ) ViewDist = ZOOM_MAX_VALUE; draw_automap(); if ( first_time ) { first_time = 0; gr_palette_load( gr_palette ); } t2 = timer_get_fixed_seconds(); while (t2-t1<F1_0/100){//ogl is fast enough that the automap can read the input too fast and you start to turn really slow. So delay a bit (and free up some cpu :) if (nice_automap) d_delay(1); t2 = timer_get_fixed_seconds(); } if (pause_game) FrameTime=t2-t1; t1 = t2; } //free(Edges); //free(DrawingListBright); gr_free_canvas(name_canv); name_canv=NULL; #ifdef AUTOMAP_NO_PAGING gr_free_canvas(OffscreenPage); OffscreenPage = NULL; #endif mprintf( (0, "Automap memory freed\n" )); game_flush_inputs(); if (pause_game) start_time(); } void adjust_segment_limit(int SegmentLimit) { int i,e1; Edge_info * e; mprintf(( 0, "Seglimit: %d\n", SegmentLimit )); for (i=0; i<=Highest_edge_index; i++ ) { e = &Edges[i]; e->flags |= EF_TOO_FAR; for (e1=0; e1<e->num_faces; e1++ ) { if ( Automap_visited[e->segnum[e1]] <= SegmentLimit ) { e->flags &= (~EF_TOO_FAR); break; } } } }
void do_automap( int key_code ) { int pcx_error; ubyte pal[256*3]; window *automap_wind = NULL; automap *am; CALLOC(am, automap, 1); if (am) { automap_wind = window_create(&grd_curscreen->sc_canvas, 0, 0, SWIDTH, SHEIGHT, (int (*)(window *, d_event *, void *)) automap_handler, am); } if (automap_wind == NULL) { Warning("Out of memory"); return; } am->leave_mode = 0; am->pause_game = 1; // Set to 1 if everything is paused during automap...No pause during net. am->max_segments_away = 0; am->segment_limit = 1; am->num_edges = 0; am->highest_edge_index = -1; am->max_edges = Num_segments*12; MALLOC(am->edges, Edge_info, am->max_edges); MALLOC(am->drawingListBright, int, am->max_edges); if (!am->edges || !am->drawingListBright) { if (am->edges) d_free(am->edges); if (am->drawingListBright) d_free(am->drawingListBright); Warning("Out of memory"); return; } am->zoom = 0x9000; am->farthest_dist = (F1_0 * 20 * 50); // 50 segments away am->viewDist = 0; init_automap_colors(am); key_code = key_code; // disable warning... if ((Game_mode & GM_MULTI) && (!Endlevel_sequence)) am->pause_game = 0; if (am->pause_game) { window_set_visible(Game_wind, 0); } if (!am->pause_game) { am->old_wiggle = ConsoleObject->mtype.phys_info.flags & PF_WIGGLE; // Save old wiggle ConsoleObject->mtype.phys_info.flags &= ~PF_WIGGLE; // Turn off wiggle } //Max_edges = min(MAX_EDGES_FROM_VERTS(Num_vertices),MAX_EDGES); //make maybe smaller than max gr_set_current_canvas(NULL); automap_build_edge_list(am); if ( am->viewDist==0 ) am->viewDist = ZOOM_DEFAULT; am->viewMatrix = Objects[Players[Player_num].objnum].orient; am->tangles.p = PITCH_DEFAULT; am->tangles.h = 0; am->tangles.b = 0; am->view_target = Objects[Players[Player_num].objnum].pos; if (PlayerCfg.AutomapFreeFlight) vm_vec_scale_add(&am->view_position, &Objects[Players[Player_num].objnum].pos, &am->viewMatrix.fvec, -ZOOM_DEFAULT ); am->t1 = am->entry_time = timer_query(); am->t2 = am->t1; //Fill in Automap_visited from Objects[Players[Player_num].objnum].segnum am->max_segments_away = set_segment_depths(Objects[Players[Player_num].objnum].segnum, Automap_visited); am->segment_limit = am->max_segments_away; adjust_segment_limit(am, am->segment_limit); // ZICO - code from above to show frame in OGL correctly. Redundant, but better readable. // KREATOR - Now applies to all platforms so double buffering is supported gr_init_bitmap_data (&am->automap_background); pcx_error = pcx_read_bitmap(MAP_BACKGROUND_FILENAME, &am->automap_background, BM_LINEAR, pal); if (pcx_error != PCX_ERROR_NONE) Error("File %s - PCX error: %s", MAP_BACKGROUND_FILENAME, pcx_errormsg(pcx_error)); gr_remap_bitmap_good(&am->automap_background, pal, -1, -1); gr_init_sub_canvas(&am->automap_view, &grd_curscreen->sc_canvas, (SWIDTH/23), (SHEIGHT/6), (SWIDTH/1.1), (SHEIGHT/1.45)); gr_palette_load( gr_palette ); Automap_active = 1; }
// ----------------------------------------------------------------------------- // Save game int save_level_sub(char * filename, int compiled_version) { PHYSFS_file * SaveFile; char temp_filename[PATH_MAX]; int minedata_offset=0,gamedata_offset=0,hostagetext_offset=0; // if ( !compiled_version ) { write_game_text_file(filename); if (Errors_in_mine) { if (is_real_level(filename)) { char ErrorMessage[200]; sprintf( ErrorMessage, "Warning: %i errors in this mine!\n", Errors_in_mine ); gr_palette_load(gr_palette); if (nm_messagebox( NULL, 2, "Cancel Save", "Save", ErrorMessage )!=1) { return 1; } } } // change_filename_extension(temp_filename,filename,".LVL"); } // else { change_filename_extension(temp_filename, filename, ".RDL"); } SaveFile = PHYSFSX_openWriteBuffered(temp_filename); if (!SaveFile) { char ErrorMessage[256]; snprintf( ErrorMessage, sizeof(ErrorMessage), "ERROR: Cannot write to '%s'.", temp_filename); gr_palette_load(gr_palette); nm_messagebox( NULL, 1, "Ok", ErrorMessage ); return 1; } if (Current_level_name[0] == 0) strcpy(Current_level_name,"Untitled"); clear_transient_objects(1); //1 means clear proximity bombs compress_objects(); //after this, Highest_object_index == num objects //make sure player is in a segment if (update_object_seg(&Objects[Players[0].objnum]) == 0) { if (ConsoleObject->segnum > Highest_segment_index) ConsoleObject->segnum = 0; compute_segment_center(&ConsoleObject->pos,&(Segments[ConsoleObject->segnum])); } fix_object_segs(); //Write the header PHYSFS_writeSLE32(SaveFile, MAKE_SIG('P','L','V','L')); PHYSFS_writeSLE32(SaveFile, Gamesave_current_version); //save placeholders PHYSFS_writeSLE32(SaveFile, minedata_offset); PHYSFS_writeSLE32(SaveFile, gamedata_offset); PHYSFS_writeSLE32(SaveFile, hostagetext_offset); //Now write the damn data minedata_offset = PHYSFS_tell(SaveFile); #if 0 // only save compiled mine data if ( !compiled_version ) save_mine_data(SaveFile); else #endif save_mine_data_compiled(SaveFile); gamedata_offset = PHYSFS_tell(SaveFile); save_game_data(SaveFile); hostagetext_offset = PHYSFS_tell(SaveFile); PHYSFS_seek(SaveFile, sizeof(int) + sizeof(Gamesave_current_version)); PHYSFS_writeSLE32(SaveFile, minedata_offset); PHYSFS_writeSLE32(SaveFile, gamedata_offset); PHYSFS_writeSLE32(SaveFile, hostagetext_offset); //==================== CLOSE THE FILE ============================= PHYSFS_close(SaveFile); // if ( !compiled_version ) { if (EditorWindow) editor_status_fmt("Saved mine %s, \"%s\"",filename,Current_level_name); } return 0; }
//load a level off disk. level numbers start at 1. Secret levels are -1,-2,-3 void LoadLevel(int level_num) { char *level_name; player save_player; #ifdef REQUIRE_CD { FILE *fp; int i; char fname[128]; strcpy( fname, destsat_cdpath ); #ifdef DEST_SAT strcat( fname, "saturn.hog" ); #else strcat( fname, "descent.hog" ); #endif do { descent_critical_error = 0; fp = fopen( fname, "rb" ); if ( fp==NULL || descent_critical_error ) { if ( fp ) { fclose(fp); fp = NULL; } gr_set_current_canvas(NULL); gr_clear_canvas( gr_find_closest_color_current(0,0,0) ); gr_palette_load( gr_palette ); i = nm_messagebox( "Insert CD", 2, "Retry", "Exit", "Please put the\nDescent CD\nin your CD-ROM drive!\n" ); if ( i==1 ) exit(0); } } while ( fp == NULL ); fclose( fp ); } #endif save_player = Players[Player_num]; Assert(level_num <= Last_level && level_num >= Last_secret_level && level_num != 0); #ifdef SHAREWARE { static char t[13]; sprintf(t, "LEVEL%02d.SDL", level_num); level_name = t; } #else if (level_num<0) //secret level level_name = Secret_level_names[-level_num-1]; else //normal level level_name = Level_names[level_num-1]; #endif show_boxed_message(TXT_LOADING); if (!load_level(level_name)) Current_level_num=level_num; #ifdef NETWORK my_segments_checksum = netmisc_calc_checksum(Segments, sizeof(segment)*(Highest_segment_index+1)); #endif load_endlevel_data(level_num); clear_boxed_message(); #ifdef NETWORK reset_network_objects(); #endif Players[Player_num] = save_player; set_sound_sources(); songs_play_level_song( Current_level_num ); }