From f8f691137746b187cca2f997604a2336882b5cd9 Mon Sep 17 00:00:00 2001 From: Holger Schemel Date: Thu, 30 Jun 2005 01:01:10 +0200 Subject: [PATCH] rnd-20050630-1-src * fixed bug with dynamite dropped on top of just dropped custom element (collect dynamite, collect CE, drop CE => dynamite was also dropped); dynamite can still be dropped, but drop key must be released before * fixed bug with wrong start directory when started from file browser (due to this bug, R'n'D could not be started from KDE's Konqueror) --- ChangeLog | 9 ++++ src/conftime.h | 2 +- src/game.c | 20 +++++++++ src/libgame/misc.c | 97 +++++++++++++++++++++++++++++++------------- src/libgame/misc.h | 3 ++ src/libgame/system.c | 19 +-------- src/main.h | 11 +++++ 7 files changed, 115 insertions(+), 46 deletions(-) diff --git a/ChangeLog b/ChangeLog index b37248b2..bbc96b9d 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,12 @@ +2005-06-27 + * fixed bug with dynamite dropped on top of just dropped custom element + (collect dynamite, collect CE, drop CE => dynamite was also dropped); + dynamite can still be dropped, but drop key must be released before + +2005-06-27 + * fixed bug with wrong start directory when started from file browser + (due to this bug, R'n'D could not be started from KDE's Konqueror) + 2005-06-26 * fixed bug causing "change when impact" on player not working * fixed wrong priority of "hitting something" over "hitting " diff --git a/src/conftime.h b/src/conftime.h index b8a6c3ad..cee54f4d 100644 --- a/src/conftime.h +++ b/src/conftime.h @@ -1 +1 @@ -#define COMPILE_DATE_STRING "[2005-06-27 21:21]" +#define COMPILE_DATE_STRING "[2005-06-30 00:18]" diff --git a/src/game.c b/src/game.c index dd8af0d3..34a57f74 100644 --- a/src/game.c +++ b/src/game.c @@ -54,6 +54,8 @@ #define USE_HITTING_SOMETHING_BUGFIX (TRUE * USE_NEW_STUFF * 1) #define USE_HIT_BY_SOMETHING_BUGFIX (TRUE * USE_NEW_STUFF * 1) +#define USE_DROP_BUGFIX (TRUE * USE_NEW_STUFF * 1) + /* for DigField() */ #define DF_NO_PUSH 0 @@ -1775,6 +1777,11 @@ void InitGame() player->switch_x = -1; player->switch_y = -1; +#if USE_DROP_BUGFIX + player->drop_x = -1; + player->drop_y = -1; +#endif + player->show_envelope = 0; player->move_delay = game.initial_move_delay; @@ -12361,6 +12368,15 @@ boolean DropElement(struct PlayerInfo *player) EL_DYNABOMB_PLAYER_1_ACTIVE + player->index_nr : EL_UNDEFINED); +#if USE_DROP_BUGFIX + /* do not drop an element on top of another element; when holding drop key + pressed without moving, dropped element must move away before the next + element can be dropped (this is especially important if the next element + is dynamite, which can be placed on background for historical reasons) */ + if (PLAYER_DROPPING(player, dropx, dropy) && Feld[dropx][dropy] != EL_EMPTY) + return MF_ACTION; +#endif + if (IS_THROWABLE(drop_element)) { dropx += GET_DX_FROM_DIR(drop_direction); @@ -12557,6 +12573,10 @@ boolean DropElement(struct PlayerInfo *player) player->is_dropping = TRUE; +#if USE_DROP_BUGFIX + player->drop_x = dropx; + player->drop_y = dropy; +#endif return TRUE; } diff --git a/src/libgame/misc.c b/src/libgame/misc.c index f90b2c23..a3c32479 100644 --- a/src/libgame/misc.c +++ b/src/libgame/misc.c @@ -456,6 +456,51 @@ char *getHomeDir() } +/* ------------------------------------------------------------------------- */ +/* path manipulation functions */ +/* ------------------------------------------------------------------------- */ + +static char *getLastPathSeparatorPtr(char *filename) +{ + char *last_separator = strrchr(filename, '/'); + +#if !defined(PLATFORM_UNIX) + if (last_separator == NULL) /* also try DOS/Windows variant */ + last_separator = strrchr(filename, '\\'); +#endif + + return last_separator; +} + +static char *getBaseNamePtr(char *filename) +{ + char *last_separator = getLastPathSeparatorPtr(filename); + + if (last_separator != NULL) + return last_separator + 1; /* separator found: strip base path */ + else + return filename; /* no separator found: filename has no path */ +} + +char *getBaseName(char *filename) +{ + return getStringCopy(getBaseNamePtr(filename)); +} + +char *getBasePath(char *filename) +{ + char *basepath = getStringCopy(filename); + char *last_separator = getLastPathSeparatorPtr(basepath); + + if (last_separator != NULL) + *last_separator = '\0'; /* separator found: strip basename */ + else + basepath = "."; /* no separator found: use current path */ + + return basepath; +} + + /* ------------------------------------------------------------------------- */ /* various string functions */ /* ------------------------------------------------------------------------- */ @@ -529,19 +574,26 @@ void setString(char **old_value, char *new_value) void GetOptions(char *argv[], void (*print_usage_function)(void)) { + char *ro_base_path = RO_BASE_PATH; + char *rw_base_path = RW_BASE_PATH; char **options_left = &argv[1]; + if (strcmp(ro_base_path, ".") == 0) + ro_base_path = program.command_basepath; + if (strcmp(rw_base_path, ".") == 0) + rw_base_path = program.command_basepath; + /* initialize global program options */ options.display_name = NULL; options.server_host = NULL; options.server_port = 0; - options.ro_base_directory = RO_BASE_PATH; - options.rw_base_directory = RW_BASE_PATH; - options.level_directory = RO_BASE_PATH "/" LEVELS_DIRECTORY; - options.graphics_directory = RO_BASE_PATH "/" GRAPHICS_DIRECTORY; - options.sounds_directory = RO_BASE_PATH "/" SOUNDS_DIRECTORY; - options.music_directory = RO_BASE_PATH "/" MUSIC_DIRECTORY; - options.docs_directory = RO_BASE_PATH "/" DOCS_DIRECTORY; + options.ro_base_directory = ro_base_path; + options.rw_base_directory = rw_base_path; + options.level_directory = getPath2(ro_base_path, LEVELS_DIRECTORY); + options.graphics_directory = getPath2(ro_base_path, GRAPHICS_DIRECTORY); + options.sounds_directory = getPath2(ro_base_path, SOUNDS_DIRECTORY); + options.music_directory = getPath2(ro_base_path, MUSIC_DIRECTORY); + options.docs_directory = getPath2(ro_base_path, DOCS_DIRECTORY); options.execute_command = NULL; options.serveronly = FALSE; options.network = FALSE; @@ -608,22 +660,17 @@ void GetOptions(char *argv[], void (*print_usage_function)(void)) Error(ERR_EXIT_HELP, "option '%s' requires an argument", option_str); /* this should be extended to separate options for ro and rw data */ - options.ro_base_directory = option_arg; - options.rw_base_directory = option_arg; + options.ro_base_directory = ro_base_path = option_arg; + options.rw_base_directory = rw_base_path = option_arg; if (option_arg == next_option) options_left++; /* adjust paths for sub-directories in base directory accordingly */ - options.level_directory = - getPath2(options.ro_base_directory, LEVELS_DIRECTORY); - options.graphics_directory = - getPath2(options.ro_base_directory, GRAPHICS_DIRECTORY); - options.sounds_directory = - getPath2(options.ro_base_directory, SOUNDS_DIRECTORY); - options.music_directory = - getPath2(options.ro_base_directory, MUSIC_DIRECTORY); - options.docs_directory = - getPath2(options.ro_base_directory, DOCS_DIRECTORY); + options.level_directory = getPath2(ro_base_path, LEVELS_DIRECTORY); + options.graphics_directory = getPath2(ro_base_path, GRAPHICS_DIRECTORY); + options.sounds_directory = getPath2(ro_base_path, SOUNDS_DIRECTORY); + options.music_directory = getPath2(ro_base_path, MUSIC_DIRECTORY); + options.docs_directory = getPath2(ro_base_path, DOCS_DIRECTORY); } else if (strncmp(option, "-levels", option_len) == 0) { @@ -1558,27 +1605,21 @@ boolean fileHasSuffix(char *basename, char *suffix) boolean FileIsGraphic(char *filename) { - char *basename = strrchr(filename, '/'); - - basename = (basename != NULL ? basename + 1 : filename); + char *basename = getBaseNamePtr(filename); return fileHasSuffix(basename, "pcx"); } boolean FileIsSound(char *filename) { - char *basename = strrchr(filename, '/'); - - basename = (basename != NULL ? basename + 1 : filename); + char *basename = getBaseNamePtr(filename); return fileHasSuffix(basename, "wav"); } boolean FileIsMusic(char *filename) { - char *basename = strrchr(filename, '/'); - - basename = (basename != NULL ? basename + 1 : filename); + char *basename = getBaseNamePtr(filename); if (FileIsSound(basename)) return TRUE; diff --git a/src/libgame/misc.h b/src/libgame/misc.h index db836823..b89be4e8 100644 --- a/src/libgame/misc.h +++ b/src/libgame/misc.h @@ -94,6 +94,9 @@ char *getLoginName(void); char *getRealName(void); char *getHomeDir(void); +char *getBasePath(char *); +char *getBaseName(char *); + char *getPath2(char *, char *); char *getPath3(char *, char *, char*); char *getStringCat2(char *, char *); diff --git a/src/libgame/system.c b/src/libgame/system.c index e3fbe001..8e65d970 100644 --- a/src/libgame/system.c +++ b/src/libgame/system.c @@ -75,23 +75,8 @@ void InitProgramInfo(char *argv0, char *cookie_prefix, char *filename_prefix, int program_version) { - char *argv0_copy = getStringCopy(argv0); - char *argv0_copy_last_slash = strrchr(argv0_copy, '/'); - - if (argv0_copy_last_slash != NULL) - { - program.command_basename = argv0_copy_last_slash + 1; - program.command_basepath = argv0_copy; - *argv0_copy_last_slash = '\0'; - } - else - { - program.command_basename = argv0_copy; - program.command_basepath = "."; - } - - printf("::: command_basepath == '%s'\n", program.command_basepath); - printf("::: command_basename == '%s'\n", program.command_basename); + program.command_basepath = getBasePath(argv0); + program.command_basename = getBaseName(argv0); program.userdata_directory = userdata_directory; program.program_title = program_title; diff --git a/src/main.h b/src/main.h index 52d7fb81..55aba370 100644 --- a/src/main.h +++ b/src/main.h @@ -550,6 +550,9 @@ #define PLAYER_SWITCHING(p,x,y) ((p)->is_switching && \ (p)->switch_x == (x) && (p)->switch_y == (y)) +#define PLAYER_DROPPING(p,x,y) ((p)->is_dropping && \ + (p)->drop_x == (x) && (p)->drop_y == (y)) + #define PLAYER_NR_GFX(g,i) ((g) + i * (IMG_PLAYER_2 - IMG_PLAYER_1)) #define ANIM_FRAMES(g) (graphic_info[g].anim_frames) @@ -1385,10 +1388,17 @@ /* program information and versioning definitions */ +#if 1 +#define PROGRAM_VERSION_MAJOR 3 +#define PROGRAM_VERSION_MINOR 1 +#define PROGRAM_VERSION_PATCH 1 +#define PROGRAM_VERSION_BUILD 0 +#else #define PROGRAM_VERSION_MAJOR 3 #define PROGRAM_VERSION_MINOR 2 #define PROGRAM_VERSION_PATCH 0 #define PROGRAM_VERSION_BUILD 3 +#endif #define PROGRAM_TITLE_STRING "Rocks'n'Diamonds" #define PROGRAM_AUTHOR_STRING "Holger Schemel" @@ -1551,6 +1561,7 @@ struct PlayerInfo int num_special_action_sleeping; int switch_x, switch_y; + int drop_x, drop_y; int show_envelope; -- 2.34.1