/* THE COMPUTER CODE CONTAINED HEREIN IS THE SOLE PROPERTY OF PARALLAX SOFTWARE CORPORATION ("PARALLAX"). PARALLAX, IN DISTRIBUTING THE CODE TO END-USERS, AND SUBJECT TO ALL OF THE TERMS AND CONDITIONS HEREIN, GRANTS A ROYALTY-FREE, PERPETUAL LICENSE TO SUCH END-USERS FOR USE BY SUCH END-USERS IN USING, DISPLAYING, AND CREATING DERIVATIVE WORKS THEREOF, SO LONG AS SUCH USE, DISPLAY OR CREATION IS FOR NON-COMMERCIAL, ROYALTY OR REVENUE FREE PURPOSES. IN NO EVENT SHALL THE END-USER USE THE COMPUTER CODE CONTAINED HEREIN FOR REVENUE-BEARING PURPOSES. THE END-USER UNDERSTANDS AND AGREES TO THE TERMS HEREIN AND ACCEPTS THE SAME BY USE OF THIS FILE. COPYRIGHT 1993-1998 PARALLAX SOFTWARE CORPORATION. ALL RIGHTS RESERVED. */ /* * * Mine specific editing functions, such as load_mine, save_mine * */ #include #include #include #include #include "key.h" #include "gr.h" #include "bm.h" // for MAX_TEXTURES #include "inferno.h" #include "segment.h" #include "editor.h" #include "error.h" #include "textures.h" #include "object.h" #include "gamemine.h" #include "gameseg.h" #include "ui.h" // Because texpage.h need UI_WINDOW type #include "texpage.h" // For texpage_goto_first #include "medwall.h" #include "switch.h" #include "nocfile.h" #include "fuelcen.h" #define REMOVE_EXT(s) (*(strchr( (s), '.' ))='\0') int CreateDefaultNewSegment(); int save_mine_data(CFILE * SaveFile); int save_mine_data_compiled_new(FILE * SaveFile); static char current_tmap_list[MAX_TEXTURES][13]; // ----------------------------------------------------------------------------- // Save mine will: // 1. Write file info, header info, editor info, vertex data, segment data, // and new_segment in that order, marking their file offset. // 2. Go through all the fields and fill in the offset, size, and sizeof // values in the headers. int med_save_mine(char * filename) { FILE * SaveFile; char ErrorMessage[256]; SaveFile = cfopen( filename, CF_WRITE_MODE ); if (!SaveFile) { #ifndef __LINUX__ char fname[20]; _splitpath( filename, NULL, NULL, fname, NULL ); sprintf( ErrorMessage, \ "ERROR: Cannot write to '%s'.\nYou probably need to check out a locked\nversion of the file. You should save\nthis under a different filename, and then\ncheck out a locked copy by typing\n\'co -l %s.lvl'\nat the DOS prompt.\n" , filename, fname); #endif sprintf( ErrorMessage, "ERROR: Unable to open %s\n", filename ); MessageBox( -2, -2, 1, ErrorMessage, "Ok" ); return 1; } save_mine_data(SaveFile); //==================== CLOSE THE FILE ============================= cfclose(SaveFile); return 0; } // ----------------------------------------------------------------------------- // saves to an already-open file int save_mine_data(CFILE * SaveFile) { int header_offset, editor_offset, vertex_offset, segment_offset, doors_offset, texture_offset, walls_offset, triggers_offset; //, links_offset; int newseg_verts_offset; int newsegment_offset; int i; med_compress_mine(); warn_if_concave_segments(); for (i=0;i>nbits); if( int_value > 0x7fff ) { short_value = 0x7fff; } else if( int_value < -0x7fff ) { short_value = -0x7fff; } else short_value = (short)int_value; cfwrite( &short_value, sizeof(short_value), 1, SaveFile ); } //version of dump for unsigned values void dump_fix_as_ushort( fix value, int nbits, CFILE * SaveFile ) { uint int_value=0; ushort short_value; if (value < 0) { Int3(); //hey---show this to Matt value = 0; } else int_value = value >> nbits; if( int_value > 0xffff ) { short_value = 0xffff; } else short_value = int_value; cfwrite( &short_value, sizeof(short_value), 1, SaveFile ); } int New_file_format_save = 1; // ----------------------------------------------------------------------------- // saves compiled mine data to an already-open file... int save_mine_data_compiled(FILE * SaveFile) { short i,segnum,sidenum; ubyte version = COMPILED_MINE_VERSION; #ifndef SHAREWARE if (New_file_format_save) return save_mine_data_compiled_new(SaveFile); #endif med_compress_mine(); warn_if_concave_segments(); if (Highest_segment_index >= MAX_GAME_SEGMENTS) { char message[128]; sprintf(message, "Error: Too many segments (%i > %i) for game (not editor)", Highest_segment_index+1, MAX_GAME_SEGMENTS); MessageBox( -2, -2, 1, message, "Ok" ); } if (Highest_vertex_index >= MAX_GAME_VERTICES) { char message[128]; sprintf(message, "Error: Too many vertices (%i > %i) for game (not editor)", Highest_vertex_index+1, MAX_GAME_VERTICES); MessageBox( -2, -2, 1, message, "Ok" ); } //=============================== Writing part ============================== cfwrite( &version, sizeof(ubyte), 1, SaveFile ); // 1 byte = compiled version cfwrite( &Num_vertices, sizeof(int), 1, SaveFile ); // 4 bytes = Num_vertices cfwrite( &Num_segments, sizeof(int), 1, SaveFile ); // 4 bytes = Num_segments cfwrite( Vertices, sizeof(vms_vector), Num_vertices, SaveFile ); for (segnum=0; segnum>5, write as short, l>>1 write as short) for (i=0; i<4; i++ ) { dump_fix_as_short( Segments[segnum].sides[sidenum].uvls[i].u, 5, SaveFile ); dump_fix_as_short( Segments[segnum].sides[sidenum].uvls[i].v, 5, SaveFile ); dump_fix_as_ushort( Segments[segnum].sides[sidenum].uvls[i].l, 1, SaveFile ); //cfwrite( &Segments[segnum].sides[sidenum].uvls[i].l, sizeof(fix), 1, SaveFile ); } } } } return 0; } // ----------------------------------------------------------------------------- // saves compiled mine data to an already-open file... int save_mine_data_compiled_new(FILE * SaveFile) { short i, segnum, sidenum, temp_short; ubyte version = COMPILED_MINE_VERSION; ubyte bit_mask = 0; med_compress_mine(); warn_if_concave_segments(); if (Highest_segment_index >= MAX_GAME_SEGMENTS) { char message[128]; sprintf(message, "Error: Too many segments (%i > %i) for game (not editor)", Highest_segment_index+1, MAX_GAME_SEGMENTS); MessageBox( -2, -2, 1, message, "Ok" ); } if (Highest_vertex_index >= MAX_GAME_VERTICES) { char message[128]; sprintf(message, "Error: Too many vertices (%i > %i) for game (not editor)", Highest_vertex_index+1, MAX_GAME_VERTICES); MessageBox( -2, -2, 1, message, "Ok" ); } //=============================== Writing part ============================== cfwrite( &version, sizeof(ubyte), 1, SaveFile ); // 1 byte = compiled version temp_short = Num_vertices; cfwrite( &temp_short, sizeof(short), 1, SaveFile ); // 2 bytes = Num_vertices temp_short = Num_segments; cfwrite( &temp_short, sizeof(short), 1, SaveFile ); // 2 bytes = Num_segments cfwrite( Vertices, sizeof(vms_vector), Num_vertices, SaveFile ); for (segnum=0; segnum= 0) { bit_mask |= (1 << sidenum); wallnum = Segments[segnum].sides[sidenum].wall_num; Assert( wallnum < 255 ); // Get John or Mike.. can only store up to 255 walls!!! } } cfwrite( &bit_mask, sizeof(ubyte), 1, SaveFile ); for (sidenum=0; sidenum