From: Holger Schemel Date: Sun, 8 Nov 1998 11:59:33 +0000 (+0100) Subject: rnd-19981108-1 X-Git-Tag: 1.2.0^2~36 X-Git-Url: https://git.artsoft.org/?a=commitdiff_plain;h=21c25c56356db2138816a0716d73934ac3893e89;p=rocksndiamonds.git rnd-19981108-1 --- diff --git a/src/events.c b/src/events.c index ed76f9a6..15f72051 100644 --- a/src/events.c +++ b/src/events.c @@ -272,23 +272,23 @@ void HandleButton(int mx, int my, int button) old_mx = mx; old_my = my; - HandleVideoButtons(mx,my,button); - HandleSoundButtons(mx,my,button); - HandleGameButtons(mx,my,button); + HandleVideoButtons(mx,my, button); + HandleSoundButtons(mx,my, button); + HandleGameButtons(mx,my, button); } switch(game_status) { case MAINMENU: - HandleMainMenu(mx,my,0,0,button); + HandleMainMenu(mx,my, 0,0, button); break; case TYPENAME: - HandleTypeName(0,XK_Return); + HandleTypeName(0, XK_Return); break; case CHOOSELEVEL: - HandleChooseLevel(mx,my,0,0,button); + HandleChooseLevel(mx,my, 0,0, button); break; case HALLOFFAME: @@ -296,7 +296,7 @@ void HandleButton(int mx, int my, int button) break; case LEVELED: - LevelEd(mx,my,button); + LevelEd(mx,my, button); break; case HELPSCREEN: @@ -304,11 +304,11 @@ void HandleButton(int mx, int my, int button) break; case SETUP: - HandleSetupScreen(mx,my,0,0,button); + HandleSetupScreen(mx,my, 0,0, button); break; case SETUPINPUT: - HandleSetupInputScreen(mx,my,0,0,button); + HandleSetupInputScreen(mx,my, 0,0, button); break; case PLAYING: @@ -545,80 +545,6 @@ void HandleKey(KeySym key, int key_status) #if 0 - case XK_x: - - { - int i,j,k, num_steps = 8, step_size = TILEX / num_steps; - static long scroll_delay=0; - long scroll_delay_value = 4*4 / num_steps; - - printf("Scroll test\n"); - - for(i=0;i<3;i++) - { - for(j=0;j 0 ? "/" : ""), level_subdir); + + return tape_dir; +} + +static void createDirectory(char *dir, char *text) +{ + if (access(dir, F_OK) != 0) + if (mkdir(dir, USERDATA_DIR_MODE) != 0) + Error(ERR_WARN, "cannot create %s directory '%s'", text, dir); +} + +void InitUserdataDirectory() +{ + createDirectory(getUserdataDir(), "user data"); +} + +static void InitTapeDirectory(char *level_subdir) +{ + createDirectory(getTapeDir(""), "main tape data"); + createDirectory(getTapeDir(level_subdir), "level tape data"); +} + boolean LoadLevelInfo() { int i; @@ -213,21 +269,17 @@ void LoadLevelTape(int level_nr) 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 + sprintf(filename, "%s/%d.%s", + getTapeDir(leveldir[leveldir_nr].filename), + level_nr, TAPEFILE_EXTENSION); - if ((file=fopen(filename,"r"))) + if ((file = fopen(filename, "r"))) { - fgets(cookie,LEVELREC_COOKIE_LEN,file); + fgets(cookie, LEVELREC_COOKIE_LEN, file); fgetc(file); - if (!strcmp(cookie,LEVELREC_COOKIE_10)) /* old 1.0 tape format */ + if (!strcmp(cookie, LEVELREC_COOKIE_10)) /* old 1.0 tape format */ levelrec_10 = TRUE; - else if (strcmp(cookie,LEVELREC_COOKIE)) /* unknown tape format */ + else if (strcmp(cookie, LEVELREC_COOKIE)) /* unknown tape format */ { Error(ERR_WARN, "wrong format of level recording file '%s'", filename); fclose(file); @@ -253,7 +305,7 @@ void LoadLevelTape(int level_nr) tape.playing = FALSE; tape.pausing = FALSE; - for(i=0;i> 24) & 0xff,file); fputc((tape.random_seed >> 16) & 0xff,file); @@ -361,14 +411,14 @@ void SaveLevelTape(int level_nr) fputc((tape.length >> 8) & 0xff,file); fputc((tape.length >> 0) & 0xff,file); - for(i=0;iautorecord = FALSE; si->quick_doors = FALSE; - strncpy(si->login_name, GetLoginName(), MAX_NAMELEN-1); + strncpy(si->login_name, getLoginName(), MAX_NAMELEN-1); si->login_name[MAX_NAMELEN-1] = '\0'; - strncpy(si->alias_name, GetLoginName(), MAX_NAMELEN-1); + strncpy(si->alias_name, getLoginName(), MAX_NAMELEN-1); si->alias_name[MAX_NAMELEN-1] = '\0'; for (i=0; i lev_fieldx - SCR_FIELDX + 2) - scroll_x = (scroll_x < -1 ? -1 : lev_fieldx - SCR_FIELDX + 2); + if (scroll_x < -1 || scroll_x > lev_fieldx - SCR_FIELDX + 1) + scroll_x = (scroll_x < -1 ? -1 : lev_fieldx - SCR_FIELDX + 1); /* don't scroll more than one field at a time */ scroll_x = old_scroll_x + SIGN(scroll_x - old_scroll_x); @@ -3391,8 +3391,8 @@ boolean MoveFigure(struct PlayerInfo *player, int dx, int dy) scroll_y = jy-MIDPOSY + (scroll_y < jy-MIDPOSY ? -offset : +offset); /* don't scroll over playfield boundaries */ - if (scroll_y < -1 || scroll_y > lev_fieldy - SCR_FIELDY + 2) - scroll_y = (scroll_y < -1 ? -1 : lev_fieldy - SCR_FIELDY + 2); + if (scroll_y < -1 || scroll_y > lev_fieldy - SCR_FIELDY + 1) + scroll_y = (scroll_y < -1 ? -1 : lev_fieldy - SCR_FIELDY + 1); /* don't scroll more than one field at a time */ scroll_y = old_scroll_y + SIGN(scroll_y - old_scroll_y); diff --git a/src/init.c b/src/init.c index 7a5f5eeb..52facada 100644 --- a/src/init.c +++ b/src/init.c @@ -65,6 +65,7 @@ void OpenAll(int argc, char *argv[]) exit(0); } + InitUserdataDirectory(); InitLevelAndPlayerInfo(); InitCounter(); @@ -139,7 +140,7 @@ void InitSound() return; #ifndef MSDOS - if (access(sound_device_name,W_OK)<0) + if (access(sound_device_name, W_OK) != 0) { Error(ERR_WARN, "cannot access sound device - no sounds"); sound_status = SOUND_OFF; @@ -245,7 +246,7 @@ void InitJoysticks() if (!setup.input[i].use_joystick) continue; - if (access(device_name, R_OK) < 0) + if (access(device_name, R_OK) != 0) { Error(ERR_WARN, "cannot access joystick device '%s'", device_name); continue; diff --git a/src/main.h b/src/main.h index 955cf84a..d63a289f 100644 --- a/src/main.h +++ b/src/main.h @@ -1099,24 +1099,32 @@ extern int num_bg_loops; #endif #ifndef MSDOS +#define USERDATA_DIRECTORY ".rocksndiamonds" +#define TAPEDATA_DIRECTORY "tapes" #define SCORE_FILENAME "ROCKS.score" -#define NAMES_FILENAME "ROCKS.names" #define LEVDIR_FILENAME "ROCKS.levelinfo" #define JOYDAT_FILENAME "ROCKS.joystick" -#define SETUP_FILENAME "ROCKS.setup" -#define LEVELSETUP_FILENAME "ROCKS.levelsetup" +#define SETUP_FILENAME "setup" +#define LEVELSETUP_FILENAME "setup.level" +#define TAPEFILE_EXTENSION "tape" #else +#define USERDATA_DIRECTORY "userdata" +#define TAPEDATA_DIRECTORY "tapes" #define SCORE_FILENAME "ROCKS.sco" -#define NAMES_FILENAME "ROCKS.nam" #define LEVDIR_FILENAME "ROCKS.lev" #define JOYDAT_FILENAME "ROCKS.joy" -#define SETUP_FILENAME "ROCKS.set" -#define LEVELSETUP_FILENAME "ROCKS.lvs" +#define SETUP_FILENAME "setup" +#define LEVELSETUP_FILENAME "setup.lev" +#define TAPEFILE_EXTENSION "rec" #endif #define JOYDAT_FILE JOYDAT_PATH "/" JOYDAT_FILENAME -#define LEVEL_PERMS (S_IRUSR|S_IWUSR | S_IRGRP|S_IWGRP | S_IROTH|S_IWOTH) +#define MODE_R_ALL (S_IRUSR | S_IRGRP | S_IROTH) +#define MODE_W_ALL (S_IWUSR | S_IWGRP | S_IWOTH) +#define MODE_X_ALL (S_IXUSR | S_IXGRP | S_IXOTH) +#define USERDATA_DIR_MODE (MODE_R_ALL | MODE_X_ALL | S_IWUSR) +#define LEVEL_PERMS (MODE_R_ALL | MODE_W_ALL) #define SCORE_PERMS LEVEL_PERMS #define NAMES_PERMS LEVEL_PERMS #define LEVDIR_PERMS LEVEL_PERMS @@ -1145,7 +1153,7 @@ extern int num_bg_loops; #define SETUP_COOKIE_LEN (strlen(SETUP_COOKIE)+1) #define LEVELSETUP_COOKIE_LEN (strlen(LEVELSETUP_COOKIE)+1) -#define VERSION_STRING "1.2" +#define VERSION_STRING "1.2 preview 1" #define GAMETITLE_STRING "Rocks'n'Diamonds" #define WINDOWTITLE_STRING GAMETITLE_STRING " " VERSION_STRING #define COPYRIGHT_STRING "Copyright ^1995-98 by Holger Schemel" diff --git a/src/misc.c b/src/misc.c index c037e959..7d0a7fde 100644 --- a/src/misc.c +++ b/src/misc.c @@ -155,39 +155,59 @@ unsigned int SimpleRND(unsigned int max) gettimeofday(¤t_time,NULL); root = root * 4253261 + current_time.tv_sec + current_time.tv_usec; - return(root % max); + return (root % max); } unsigned int RND(unsigned int max) { - return(random_linux_libc() % max); + return (random_linux_libc() % max); } unsigned int InitRND(long seed) { struct timeval current_time; - if (seed==NEW_RANDOMIZE) + if (seed == NEW_RANDOMIZE) { gettimeofday(¤t_time,NULL); srandom_linux_libc((unsigned int) current_time.tv_usec); - return((unsigned int) current_time.tv_usec); + return (unsigned int)current_time.tv_usec; } else { srandom_linux_libc((unsigned int) seed); - return((unsigned int) seed); + return (unsigned int)seed; } } -char *GetLoginName() +char *getLoginName() { struct passwd *pwd; - if (!(pwd=getpwuid(getuid()))) - return("ANONYMOUS"); + if (!(pwd = getpwuid(getuid()))) + return "ANONYMOUS"; else - return(pwd->pw_name); + return pwd->pw_name; +} + +char *getHomeDir() +{ + static char *home_dir = NULL; + + if (!home_dir) + { + if (!(home_dir = getenv("HOME"))) + { + struct passwd *pwd; + + if ((pwd = getpwuid(getuid()))) + home_dir = pwd->pw_dir; + else + home_dir = "."; + } + } + + return home_dir; } void MarkTileDirty(int x, int y) diff --git a/src/misc.h b/src/misc.h index 10aae9ce..798e61ef 100644 --- a/src/misc.h +++ b/src/misc.h @@ -39,7 +39,8 @@ char *int2str(int, int); unsigned int SimpleRND(unsigned int); unsigned int RND(unsigned int); unsigned int InitRND(long); -char *GetLoginName(void); +char *getLoginName(void); +char *getHomeDir(void); void MarkTileDirty(int, int); void GetOptions(char **); void Error(int, char *, ...); diff --git a/src/screens.c b/src/screens.c index 31967046..a0a06dbc 100644 --- a/src/screens.c +++ b/src/screens.c @@ -71,14 +71,8 @@ void DrawMainMenu() DrawGraphic(10,3,GFX_PFEIL_L); DrawGraphic(14,3,GFX_PFEIL_R); - DrawText(SX+40+16,SY+326,"A Game by Artsoft Entertainment",FS_SMALL,FC_BLUE); - - /* - DrawText(SX+40+16,SY+344,"Graphics: Deluxe Paint IV Amiga", - FS_SMALL,FC_BLUE); - DrawText(SX+60+16,SY+362,"Sounds: AudioMaster IV Amiga", - FS_SMALL,FC_BLUE); - */ + DrawText(SX+56, SY+326, "A Game by Artsoft Entertainment", + FS_SMALL, FC_RED); if (leveldir[leveldir_nr].name) {