From 31327f50f981e018361b5ec9822d70e1a6e6e85f Mon Sep 17 00:00:00 2001 From: Bradley Bell Date: Thu, 1 Aug 2002 23:28:57 +0000 Subject: [PATCH] load d1 levels --- NEWS | 3 +- cfile/cfile.c | 80 +++++++++++++++++++++--------------------- main/console.c | 16 +++++---- main/gamemine.c | 93 ++++++++++++++++++++++++++----------------------- main/gamemine.h | 5 +++ main/gamesave.c | 19 ++++------ 6 files changed, 115 insertions(+), 101 deletions(-) diff --git a/NEWS b/NEWS index 02c2f755..eeacb55b 100644 --- a/NEWS +++ b/NEWS @@ -2,8 +2,9 @@ - mve support :-) - Lots of portability fixes - OS X support! -- Other bigendian linux/unix support? +- Other bigendian linux/unix support. - Shareware data files support! +- Descent 1 level support! thanks to Martin Schaffner --- Version 0.1.3 --- - deb and rpm support added diff --git a/cfile/cfile.c b/cfile/cfile.c index 2baca72d..c86847e9 100644 --- a/cfile/cfile.c +++ b/cfile/cfile.c @@ -1,3 +1,4 @@ +/* $Id: cfile.c,v 1.6 2002-08-01 23:28:57 btb Exp $ */ /* THE COMPUTER CODE CONTAINED HEREIN IS THE SOLE PROPERTY OF PARALLAX SOFTWARE CORPORATION ("PARALLAX"). PARALLAX, IN DISTRIBUTING THE CODE TO @@ -7,7 +8,7 @@ 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. +AND AGREES TO THE TERMS HEREIN AND ACCEPTS THE SAME BY USE OF THIS FILE. COPYRIGHT 1993-1999 PARALLAX SOFTWARE CORPORATION. ALL RIGHTS RESERVED. */ @@ -56,16 +57,16 @@ char AltHogdir_initialized = 0; void macify_dospath(char *dos_path, char *mac_path) { char *p; - + if (!strncmp(dos_path, ".\\", 2)) { strcpy(mac_path, ":"); strcat(mac_path, &(dos_path[2]) ); } else strcpy(mac_path, dos_path); - + while ( (p = strchr(mac_path, '\\')) != NULL) *p = ':'; - + } #endif @@ -85,7 +86,7 @@ int default_error_counter=0; //ptr to counter of how many critical errors int *critical_error_counter_ptr=&default_error_counter; -//tell cfile about your critical error counter +//tell cfile about your critical error counter void cfile_set_critical_error_counter_ptr(int *ptr) { critical_error_counter_ptr = ptr; @@ -114,7 +115,7 @@ FILE * cfile_get_filehandle( char * filename, char * mode ) fclose(fp); fp = NULL; } - } + } return fp; } @@ -136,8 +137,8 @@ int cfile_init_hogfile(char *fname, hogfile * hog_files, int * nfiles ) return 0; } - while( 1 ) - { + while( 1 ) + { if ( *nfiles >= MAX_HOGFILES ) { fclose(fp); Error( "HOGFILE is limited to %d files.\n", MAX_HOGFILES ); @@ -165,10 +166,10 @@ int cfile_init(char *hogname) { #ifdef MACINTOSH char mac_path[255]; - + macify_dospath(hogname, mac_path); #endif - + Assert(Hogfile_initialized == 0); #ifndef MACINTOSH @@ -177,7 +178,7 @@ int cfile_init(char *hogname) #else if (cfile_init_hogfile(mac_path, HogFiles, &Num_hogfiles )) { strcpy( HogFilename, mac_path ); - #endif + #endif Hogfile_initialized = 1; return 1; } @@ -227,7 +228,7 @@ int cfile_use_alternate_hogfile( char * name ) if ( name ) { #ifdef MACINTOSH char mac_path[255]; - + macify_dospath(name, mac_path); strcpy( AltHogFilename, mac_path); #else @@ -270,12 +271,12 @@ int cfexist( char * filename ) } -CFILE * cfopen(char * filename, char * mode ) +CFILE * cfopen(char * filename, char * mode ) { int length; FILE * fp; CFILE *cfile; - + if (stricmp( mode, "rb")) { Error( "cfiles can only be opened with mode==rb\n" ); } @@ -283,7 +284,7 @@ CFILE * cfopen(char * filename, char * mode ) if (filename[0] != '\x01') { #ifdef MACINTOSH char mac_path[255]; - + macify_dospath(filename, mac_path); fp = cfile_get_filehandle( mac_path, mode); #else @@ -327,14 +328,14 @@ int cfilelength( CFILE *fp ) return fp->size; } -int cfgetc( CFILE * fp ) +int cfgetc( CFILE * fp ) { int c; if (fp->raw_position >= fp->size ) return EOF; c = getc( fp->file ); - if (c!=EOF) + if (c!=EOF) fp->raw_position++; // Assert( fp->raw_position==(ftell(fp->file)-fp->lib_offset) ); @@ -342,6 +343,15 @@ int cfgetc( CFILE * fp ) return c; } +/* + * read string terminated by zero or a platform's line ending. + * Martin: cleaned up line ending mess, and made it read + * zero-terminated strings (for descent 1 levels). + * assumed that no string has any zero's or other platform's line + * endings inside + * platform's line endings reference: UN*X: LF (10), Mac: CR (13), + * DOS: CR,LF + */ char * cfgets( char * buf, size_t n, CFILE * fp ) { char * t = buf; @@ -349,32 +359,24 @@ char * cfgets( char * buf, size_t n, CFILE * fp ) int c; for (i=0; iraw_position >= fp->size ) { - *buf = 0; - return NULL; - } + if (fp->raw_position >= fp->size ) { + *buf = 0; + return NULL; + } + c = fgetc( fp->file ); + fp->raw_position++; + if (c == 0 || c == 10) // UN*X line ending or zero + break; + if (c == 13) { // it could be Mac or DOS line ending c = fgetc( fp->file ); - fp->raw_position++; -#ifdef MACINTOSH - if (c == 13) { - int c1; - - c1 = fgetc( fp->file ); + if ( c == 10 ) { // DOS line ending + break; + } else { // Mac line ending, undo last character read fseek( fp->file, -1, SEEK_CUR); - if ( c1 == 10 ) - continue; - else - break; + break; } -#endif - } while ( c == 13 ); -#ifdef MACINTOSH // because cr-lf is a bad thing on the mac - if ( c == 13 ) // and anyway -- 0xod is CR on mac, not 0x0a - c = '\n'; -#endif + } *buf++ = c; - if ( c=='\n' ) break; } *buf++ = 0; return t; diff --git a/main/console.c b/main/console.c index 165f4244..fdc06625 100644 --- a/main/console.c +++ b/main/console.c @@ -1,4 +1,4 @@ -/* $ Id: $ */ +/* $Id: console.c,v 1.8 2002-08-01 23:28:57 btb Exp $ */ /* * * FIXME: put description here @@ -57,7 +57,7 @@ int con_init(void) /* Initialise the cvars */ cvar_registervariable (&con_threshold); - return 0; + return 0; } /* ====== @@ -72,13 +72,17 @@ void con_printf(int priority, char *fmt, ...) if (priority <= ((int)con_threshold.value)) { va_start (arglist, fmt); - vsprintf (buffer, fmt, arglist); - if (text_console_enabled) vprintf(fmt, arglist); + vsprintf (buffer, fmt, arglist); va_end (arglist); + if (text_console_enabled) { + va_start (arglist, fmt); + vprintf(fmt, arglist); + va_end (arglist); + } /* for (i=0; inext = NULL; diff --git a/main/gamemine.c b/main/gamemine.c index f937992b..d1a87bdd 100644 --- a/main/gamemine.c +++ b/main/gamemine.c @@ -16,7 +16,7 @@ COPYRIGHT 1993-1999 PARALLAX SOFTWARE CORPORATION. ALL RIGHTS RESERVED. #endif #ifdef RCS -static char rcsid[] = "$Id: gamemine.c,v 1.7 2002-07-30 11:05:53 btb Exp $"; +static char rcsid[] = "$Id: gamemine.c,v 1.8 2002-08-01 23:28:57 btb Exp $"; #endif #include @@ -161,7 +161,7 @@ int load_mine_data(CFILE *LoadFile) for (i=0; i 1) + segment2_read(&Segment2s[i], LoadFile); #endif fuelcen_activate( &Segments[i], Segment2s[i].special ); } diff --git a/main/gamemine.h b/main/gamemine.h index fa097f52..a3ac8399 100644 --- a/main/gamemine.h +++ b/main/gamemine.h @@ -109,6 +109,11 @@ extern struct me mine_editor; // returns 1 if error, else 0 int game_load_mine(char * filename); +//loads from an already-open file +// returns 0=everything ok, 1=old version, -1=error +int load_mine_data(CFILE *LoadFile); +int load_mine_data_compiled(CFILE *LoadFile, int file_version); + extern short tmap_xlate_table[]; extern fix Level_shake_frequency, Level_shake_duration; extern int Secret_return_segment; diff --git a/main/gamesave.c b/main/gamesave.c index c955a57f..9dc93976 100644 --- a/main/gamesave.c +++ b/main/gamesave.c @@ -8,7 +8,7 @@ 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. +AND AGREES TO THE TERMS HEREIN AND ACCEPTS THE SAME BY USE OF THIS FILE. COPYRIGHT 1993-1999 PARALLAX SOFTWARE CORPORATION. ALL RIGHTS RESERVED. */ @@ -24,7 +24,7 @@ COPYRIGHT 1993-1999 PARALLAX SOFTWARE CORPORATION. ALL RIGHTS RESERVED. #endif #ifdef RCS -char gamesave_rcsid[] = "$Id: gamesave.c,v 1.8 2002-07-27 22:39:57 btb Exp $"; +char gamesave_rcsid[] = "$Id: gamesave.c,v 1.9 2002-08-01 23:28:57 btb Exp $"; #endif #include @@ -1356,11 +1356,7 @@ int check_segment_connections(void); extern void set_ambient_sound_flags(void); -// ----------------------------------------------------------------------------- -//loads from an already-open file -// returns 0=everything ok, 1=old version, -1=error -int load_mine_data(CFILE *LoadFile); -int load_mine_data_compiled(CFILE *LoadFile); +// ---------------------------------------------------------------------------- #define LEVEL_FILE_VERSION 8 //1 -> 2 add palette name @@ -1486,12 +1482,14 @@ int load_level(char * filename_passed) if (Current_level_palette[strlen(Current_level_palette)-1] == '\n') Current_level_palette[strlen(Current_level_palette)-1] = 0; } + if (version <= 1 || Current_level_palette[0]==0) // descent 1 level + strcpy(Current_level_palette,"groupa.256"); if (version >= 3) Base_control_center_explosion_time = cfile_read_int(LoadFile); else Base_control_center_explosion_time = DEFAULT_CONTROL_CENTER_EXPLOSION_TIME; - + if (version >= 4) Reactor_strength = cfile_read_int(LoadFile); else @@ -1508,9 +1506,6 @@ int load_level(char * filename_passed) else Num_flickering_lights = 0; - if (version <= 1 || Current_level_palette[0]==0) - strcpy(Current_level_palette,"groupa.256"); - if (version < 6) { Secret_return_segment = 0; Secret_return_orient.rvec.x = F1_0; Secret_return_orient.rvec.y = 0; Secret_return_orient.rvec.z = 0; @@ -1540,7 +1535,7 @@ int load_level(char * filename_passed) } else #endif //NOTE LINK TO ABOVE!! - mine_err = load_mine_data_compiled(LoadFile); + mine_err = load_mine_data_compiled(LoadFile, version); if (mine_err == -1) { //error!! cfclose(LoadFile); -- 2.39.2