X-Git-Url: https://git.artsoft.org/?p=rocksndiamonds.git;a=blobdiff_plain;f=src%2Ffiles.c;h=e1a4b80c42c4720fa256b2bffacbf186c29d4a9e;hp=1441cd0fe93892e88121433b541741fe8e31c7f4;hb=e5c5bf5c4a76a04f9bf64e92227bf2ef969fd25c;hpb=a5a03e15b395ba1942c180d1cd0d3a4f43b87f56 diff --git a/src/files.c b/src/files.c index 1441cd0f..e1a4b80c 100644 --- a/src/files.c +++ b/src/files.c @@ -1,13 +1,12 @@ /*********************************************************** * Rocks'n'Diamonds -- McDuffin Strikes Back! * *----------------------------------------------------------* -* ©1995 Artsoft Development * -* Holger Schemel * -* 33659 Bielefeld-Senne * -* Telefon: (0521) 493245 * -* eMail: aeglos@valinor.owl.de * -* aeglos@uni-paderborn.de * -* q99492@pbhrzx.uni-paderborn.de * +* (c) 1995-98 Artsoft Entertainment * +* Holger Schemel * +* Oststrasse 11a * +* 33604 Bielefeld * +* phone: ++49 +521 290471 * +* email: aeglos@valinor.owl.de * *----------------------------------------------------------* * files.h * ***********************************************************/ @@ -16,11 +15,12 @@ #include "tools.h" #include "misc.h" #include "tape.h" +#include "joystick.h" -BOOL CreateNewScoreFile() +boolean CreateNewScoreFile() { int i,j,k; - char filename[MAX_FILENAME]; + char filename[MAX_FILENAME_LEN]; char empty_alias[MAX_NAMELEN]; FILE *file; @@ -51,9 +51,9 @@ BOOL CreateNewScoreFile() return(TRUE); } -BOOL CreateNewNamesFile(int mode) +boolean CreateNewNamesFile(int mode) { - char filename[MAX_FILENAME]; + char filename[MAX_FILENAME_LEN]; FILE *file; if (mode==PLAYER_LEVEL) @@ -72,25 +72,25 @@ BOOL CreateNewNamesFile(int mode) return(TRUE); } -BOOL LoadLevelInfo() +boolean LoadLevelInfo() { int i; - char filename[MAX_FILENAME]; - char cookie[MAX_FILENAME]; + char filename[MAX_FILENAME_LEN]; + char cookie[MAX_FILENAME_LEN]; FILE *file; sprintf(filename,"%s/%s",level_directory,LEVDIR_FILENAME); if (!(file=fopen(filename,"r"))) { - fprintf(stderr,"%s: cannot load level info '%s'!\n",progname,filename); + Error(ERR_RETURN, "cannot load level info '%s'", filename); return(FALSE); } fscanf(file,"%s\n",cookie); if (strcmp(cookie,LEVELDIR_COOKIE)) /* ungültiges Format? */ { - fprintf(stderr,"%s: wrong format of level info file!\n",progname); + Error(ERR_RETURN, "wrong format of level info file"); fclose(file); return(FALSE); } @@ -111,7 +111,7 @@ BOOL LoadLevelInfo() if (!num_leveldirs) { - fprintf(stderr,"%s: empty level info '%s'!\n",progname,filename); + Error(ERR_RETURN, "empty level info '%s'", filename); return(FALSE); } @@ -121,19 +121,15 @@ BOOL LoadLevelInfo() void LoadLevel(int level_nr) { int i,x,y; - char filename[MAX_FILENAME]; - char cookie[MAX_FILENAME]; + char filename[MAX_FILENAME_LEN]; + char cookie[MAX_FILENAME_LEN]; FILE *file; sprintf(filename,"%s/%s/%d", level_directory,leveldir[leveldir_nr].filename,level_nr); - if (!(file=fopen(filename,"r"))) - { -/* - fprintf(stderr,"%s: cannot load level '%s'!\n",progname,filename); -*/ - } + if (!(file = fopen(filename,"r"))) + Error(ERR_RETURN, "cannot load level '%s' - creating new level", filename); else { fgets(cookie,LEVEL_COOKIE_LEN,file); @@ -141,8 +137,7 @@ void LoadLevel(int level_nr) if (strcmp(cookie,LEVEL_COOKIE)) /* ungültiges Format? */ { - fprintf(stderr,"%s: wrong format of level file '%s'!\n", - progname,filename); + Error(ERR_RETURN, "wrong format of level file '%s'", filename); fclose(file); file = NULL; } @@ -216,21 +211,28 @@ void LoadLevel(int level_nr) void LoadLevelTape(int level_nr) { int i; - char filename[MAX_FILENAME]; - char cookie[MAX_FILENAME]; + char filename[MAX_FILENAME_LEN]; + char cookie[MAX_FILENAME_LEN]; FILE *file; + boolean levelrec_10 = FALSE; +#ifndef MSDOS sprintf(filename,"%s/%s/%d.tape", level_directory,leveldir[leveldir_nr].filename,level_nr); +#else + sprintf(filename,"%s/%s/%d.tap", + level_directory,leveldir[leveldir_nr].filename,level_nr); +#endif if ((file=fopen(filename,"r"))) { fgets(cookie,LEVELREC_COOKIE_LEN,file); fgetc(file); - if (strcmp(cookie,LEVELREC_COOKIE)) /* ungültiges Format? */ + if (!strcmp(cookie,LEVELREC_COOKIE_10)) /* old 1.0 tape format */ + levelrec_10 = TRUE; + else if (strcmp(cookie,LEVELREC_COOKIE)) /* unknown tape format */ { - fprintf(stderr,"%s: wrong format of level recording file '%s'!\n", - progname,filename); + Error(ERR_RETURN, "wrong format of level recording file '%s'", filename); fclose(file); file = NULL; } @@ -256,10 +258,23 @@ void LoadLevelTape(int level_nr) for(i=0;i=MAX_TAPELEN) + int j; + + if (i >= MAX_TAPELEN) break; - tape.pos[i].joystickdata = fgetc(file); - tape.pos[i].delay = fgetc(file); + + for(j=0; j0) + { + tape.pos[i].action[j] = MV_NO_MOVING; + continue; + } + tape.pos[i].action[j] = fgetc(file); + } + + tape.pos[i].delay = fgetc(file); + if (feof(file)) break; } @@ -267,8 +282,7 @@ void LoadLevelTape(int level_nr) fclose(file); if (i != tape.length) - fprintf(stderr,"%s: level recording file '%s' corrupted!\n", - progname,filename); + Error(ERR_RETURN, "level recording file '%s' corrupted", filename); tape.length_seconds = GetTapeLength(); } @@ -276,25 +290,19 @@ void LoadLevelTape(int level_nr) void LoadScore(int level_nr) { int i,j; - char filename[MAX_FILENAME]; - char cookie[MAX_FILENAME]; + char filename[MAX_FILENAME_LEN]; + char cookie[MAX_FILENAME_LEN]; FILE *file; sprintf(filename,"%s/%s/%s", level_directory,leveldir[leveldir_nr].filename,SCORE_FILENAME); - if (!(file=fopen(filename,"r"))) + if (!(file = fopen(filename,"r"))) { if (!CreateNewScoreFile()) - { - fprintf(stderr,"%s: cannot create score file '%s'!\n", - progname,filename); - } - else if (!(file=fopen(filename,"r"))) - { - fprintf(stderr,"%s: cannot load score for level %d!\n", - progname,level_nr); - } + Error(ERR_RETURN, "cannot create score file '%s'", filename); + else if (!(file = fopen(filename,"r"))) + Error(ERR_RETURN, "cannot load score for level %d", level_nr); } if (file) @@ -302,7 +310,7 @@ void LoadScore(int level_nr) fgets(cookie,SCORE_COOKIE_LEN,file); if (strcmp(cookie,SCORE_COOKIE)) /* ungültiges Format? */ { - fprintf(stderr,"%s: wrong format of score file!\n",progname); + Error(ERR_RETURN, "wrong format of score file '%s'", filename); fclose(file); file = NULL; } @@ -334,8 +342,8 @@ void LoadScore(int level_nr) void LoadPlayerInfo(int mode) { int i; - char filename[MAX_FILENAME]; - char cookie[MAX_FILENAME]; + char filename[MAX_FILENAME_LEN]; + char cookie[MAX_FILENAME_LEN]; FILE *file; char *login_name = GetLoginName(); struct PlayerInfo default_player, new_player; @@ -358,18 +366,12 @@ void LoadPlayerInfo(int mode) new_player = default_player; - if (!(file=fopen(filename,"r"))) + if (!(file = fopen(filename,"r"))) { if (!CreateNewNamesFile(mode)) - { - fprintf(stderr,"%s: cannot create names file '%s'!\n", - progname,filename); - } - else if (!(file=fopen(filename,"r"))) - { - fprintf(stderr,"%s: cannot load player information '%s'!\n", - progname,filename); - } + Error(ERR_RETURN, "cannot create names file '%s'", filename); + else if (!(file = fopen(filename,"r"))) + Error(ERR_RETURN, "cannot load player information file '%s'", filename); } if (file) @@ -379,8 +381,7 @@ void LoadPlayerInfo(int mode) version_10_file = TRUE; else if (strcmp(cookie,NAMES_COOKIE)) /* ungültiges Format? */ { - fprintf(stderr,"%s: wrong format of names file '%s'!\n", - progname,filename); + Error(ERR_RETURN, "wrong format of names file '%s'", filename); fclose(file); file = NULL; } @@ -388,7 +389,7 @@ void LoadPlayerInfo(int mode) if (!file) { - player = default_player; + *local_player = default_player; level_nr = default_player.level_nr; return; } @@ -416,11 +417,9 @@ void LoadPlayerInfo(int mode) new_player = default_player; fclose(file); - if (!(file=fopen(filename,"a"))) - { - fprintf(stderr,"%s: cannot append new player to names file '%s'!\n", - progname,filename); - } + if (!(file = fopen(filename,"a"))) + Error(ERR_RETURN, "cannot append new player to names file '%s'", + filename); else { for(i=0;ileveldir_nr < num_leveldirs) + leveldir_nr = local_player->leveldir_nr; else leveldir_nr = 0; } else { - player.handicap = new_player.handicap; - player.level_nr = new_player.level_nr; + local_player->handicap = new_player.handicap; + local_player->level_nr = new_player.level_nr; } - level_nr = player.level_nr; - fclose(file); + level_nr = local_player->level_nr; + + if (file) + fclose(file); } void SaveLevel(int level_nr) { int i,x,y; - char filename[MAX_FILENAME]; + char filename[MAX_FILENAME_LEN]; FILE *file; sprintf(filename,"%s/%s/%d", @@ -474,7 +475,7 @@ void SaveLevel(int level_nr) if (!(file=fopen(filename,"w"))) { - fprintf(stderr,"%s: cannot save level file '%s'!\n",progname,filename); + Error(ERR_RETURN, "cannot save level file '%s'", filename); return; } @@ -516,12 +517,17 @@ void SaveLevel(int level_nr) void SaveLevelTape(int level_nr) { int i; - char filename[MAX_FILENAME]; + char filename[MAX_FILENAME_LEN]; FILE *file; - BOOL new_tape = TRUE; + boolean new_tape = TRUE; +#ifndef MSDOS sprintf(filename,"%s/%s/%d.tape", level_directory,leveldir[leveldir_nr].filename,level_nr); +#else + sprintf(filename,"%s/%s/%d.tap", + level_directory,leveldir[leveldir_nr].filename,level_nr); +#endif /* Testen, ob bereits eine Aufnahme existiert */ if ((file=fopen(filename,"r"))) @@ -529,14 +535,13 @@ void SaveLevelTape(int level_nr) new_tape = FALSE; fclose(file); - if (!AreYouSure("Replace old tape ?",AYS_ASK)) + if (!Request("Replace old tape ?",REQ_ASK)) return; } if (!(file=fopen(filename,"w"))) { - fprintf(stderr,"%s: cannot save level recording file '%s'!\n", - progname,filename); + Error(ERR_RETURN, "cannot save level recording file '%s'", filename); return; } @@ -560,7 +565,11 @@ void SaveLevelTape(int level_nr) for(i=0;ilogin_name, MAX_NAMELEN-1)) { fseek(file,-(2*MAX_NAMELEN+1+2+1+(version_10_file ? 0 : 11)),SEEK_CUR); break; } } - player.level_nr = level_nr; + local_player->level_nr = level_nr; for(i=0;ilogin_name[i],file); for(i=0;ialias_name[i],file); + fputc(local_player->handicap,file); + fputc(local_player->setup / 256,file); + fputc(local_player->setup % 256,file); + fputc(local_player->leveldir_nr,file); if (!version_10_file) { - fputc(player.level_nr,file); + fputc(local_player->level_nr,file); for(i=0;i<10;i++) /* currently unused bytes */ fputc(0,file); } @@ -693,13 +700,14 @@ void LoadJoystickData() if (joystick_status==JOYSTICK_OFF) return; +#ifndef MSDOS if (!(file=fopen(JOYDAT_FILE,"r"))) return; fscanf(file,"%s",cookie); if (strcmp(cookie,JOYSTICK_COOKIE)) /* ungültiges Format? */ { - fprintf(stderr,"%s: wrong format of joystick file!\n",progname); + Error(ERR_RETURN, "wrong format of joystick file '%s'", JOYDAT_FILE); fclose(file); return; } @@ -715,6 +723,9 @@ void LoadJoystickData() fclose(file); CheckJoystickData(); +#else + load_joystick_data(JOYDAT_FILE); +#endif } void SaveJoystickData() @@ -725,11 +736,13 @@ void SaveJoystickData() if (joystick_status==JOYSTICK_OFF) return; +#ifndef MSDOS CheckJoystickData(); if (!(file=fopen(JOYDAT_FILE,"w"))) { - fprintf(stderr,"%s: cannot save joystick calibration data!\n",progname); + Error(ERR_RETURN, "cannot save joystick calibration data to file '%s'", + JOYDAT_FILE); return; } @@ -745,4 +758,8 @@ void SaveJoystickData() fclose(file); chmod(JOYDAT_FILE, JOYDAT_PERMS); +#else + save_joystick_data(JOYDAT_FILE); +#endif + }