From: Holger Schemel Date: Wed, 2 Dec 2009 22:26:29 +0000 (+0100) Subject: rnd-20091202-2-src X-Git-Tag: 3.3.0.0^2~58 X-Git-Url: https://git.artsoft.org/?a=commitdiff_plain;h=e3a53d28634c52a0b1de6d0609de911e5d01c344;p=rocksndiamonds.git rnd-20091202-2-src --- diff --git a/src/conftime.h b/src/conftime.h index 64b4e1f2..a3e35460 100644 --- a/src/conftime.h +++ b/src/conftime.h @@ -1 +1 @@ -#define COMPILE_DATE_STRING "2009-12-02 01:43" +#define COMPILE_DATE_STRING "2009-12-02 22:23" diff --git a/src/files.c b/src/files.c index 954fb3e4..78ef9ed7 100644 --- a/src/files.c +++ b/src/files.c @@ -6331,6 +6331,39 @@ static void LoadLevelFromFileInfo_DC(struct LevelInfo *level, /* functions for loading SB level */ /* ------------------------------------------------------------------------- */ +int getMappedElement_SB(int element_ascii, boolean use_special_1) +{ + static struct + { + int ascii; + int rnd; + int special_1; + } + sb_element_mapping[] = + { + { ' ', EL_EMPTY, EL_CUSTOM_1 }, /* floor (space) */ + { '#', EL_STEELWALL, EL_CUSTOM_2 }, /* wall */ + { '@', EL_PLAYER_1, EL_CUSTOM_3 }, /* player */ + { '$', EL_SOKOBAN_OBJECT, EL_CUSTOM_4 }, /* box */ + { '.', EL_SOKOBAN_FIELD_EMPTY, EL_CUSTOM_5 }, /* goal square */ + { '*', EL_SOKOBAN_FIELD_FULL, EL_CUSTOM_6 }, /* box on goal square */ + { '+', EL_SOKOBAN_FIELD_PLAYER, EL_CUSTOM_7 }, /* player on goal square */ + { '_', EL_INVISIBLE_STEELWALL, EL_CUSTOM_8 }, /* floor beyond border */ + + { 0, -1, -1 }, + }; + + int i; + + for (i = 0; sb_element_mapping[i].ascii != 0; i++) + if (element_ascii == sb_element_mapping[i].ascii) + return (use_special_1 ? + sb_element_mapping[i].special_1 : + sb_element_mapping[i].rnd); + + return EL_UNDEFINED; +} + static void LoadLevelFromFileInfo_SB(struct LevelInfo *level, struct LevelFileInfo *level_file_info) { @@ -6345,10 +6378,20 @@ static void LoadLevelFromFileInfo_SB(struct LevelInfo *level, boolean reading_playfield = FALSE; boolean got_valid_playfield_line = FALSE; boolean invalid_playfield_char = FALSE; + boolean convert_mode_special_1 = (global.convert_leveldir && + global.convert_mode_special_1); int file_level_nr = 0; int line_nr = 0; int x, y; +#if 0 + printf("::: looking for level number %d [%d]\n", + level_file_info->nr, num_levels_to_skip); +#endif + + last_comment[0] = '\0'; + level_name[0] = '\0'; + if (!(file = fopen(filename, MODE_READ))) { level->no_valid_file = TRUE; @@ -6358,14 +6401,6 @@ static void LoadLevelFromFileInfo_SB(struct LevelInfo *level, return; } -#if 0 - printf("::: looking for level number %d [%d]\n", - level_file_info->nr, num_levels_to_skip); -#endif - - last_comment[0] = '\0'; - level_name[0] = '\0'; - while (!feof(file)) { /* level successfully read, but next level may follow here */ @@ -6506,47 +6541,21 @@ static void LoadLevelFromFileInfo_SB(struct LevelInfo *level, /* read playfield elements from line */ for (line_ptr = line; *line_ptr; line_ptr++) { + int mapped_sb_element = getMappedElement_SB(*line_ptr, + convert_mode_special_1); + /* stop parsing playfield line if larger column than allowed */ if (x >= MAX_LEV_FIELDX) break; - switch (*line_ptr) + if (mapped_sb_element == EL_UNDEFINED) { - case '#': /* wall */ - level->field[x][y] = EL_STEELWALL; - break; - - case '@': /* player */ - level->field[x][y] = EL_PLAYER_1; - break; - - case '+': /* player on goal square */ - level->field[x][y] = EL_SOKOBAN_FIELD_PLAYER; - break; + invalid_playfield_char = TRUE; - case '$': /* box */ - level->field[x][y] = EL_SOKOBAN_OBJECT; - break; - - case '*': /* box on goal square */ - level->field[x][y] = EL_SOKOBAN_FIELD_FULL; - break; - - case '.': /* goal square */ - level->field[x][y] = EL_SOKOBAN_FIELD_EMPTY; - break; - - case ' ': /* floor (space) */ - level->field[x][y] = EL_EMPTY; - break; - - default: - invalid_playfield_char = TRUE; - break; + break; } - if (invalid_playfield_char) - break; + level->field[x][y] = mapped_sb_element; /* continue with next tile column */ x++; @@ -6567,13 +6576,13 @@ static void LoadLevelFromFileInfo_SB(struct LevelInfo *level, y++; } + fclose(file); + level->fieldy = y; level->fieldx = MIN(MAX(MIN_LEV_FIELDX, level->fieldx), MAX_LEV_FIELDX); level->fieldy = MIN(MAX(MIN_LEV_FIELDY, level->fieldy), MAX_LEV_FIELDY); - fclose(file); - if (!reading_playfield) { level->no_valid_file = TRUE; @@ -6605,6 +6614,15 @@ static void LoadLevelFromFileInfo_SB(struct LevelInfo *level, { sprintf(level->name, "--> Level %d <--", level_file_info->nr); } + + for (y = 0; y < level->fieldy; y++) for (x = 0; x < level->fieldx; x++) + { + if ((x == 0 || x == level->fieldx - 1 || + y == 0 || y == level->fieldy - 1) && + level->field[x][y] == getMappedElement_SB(' ', convert_mode_special_1)) + FloodFillLevel(x, y, getMappedElement_SB('_', convert_mode_special_1), + level->field, level->fieldx, level->fieldy); + } } @@ -7077,8 +7095,7 @@ static void LoadLevel_InitPlayfield(struct LevelInfo *level, char *filename) lev_fieldy = level->fieldy; /* determine border element for this level */ - if (level->file_info.type == LEVEL_FILE_TYPE_DC || - level->file_info.type == LEVEL_FILE_TYPE_SB) + if (level->file_info.type == LEVEL_FILE_TYPE_DC) BorderElement = EL_EMPTY; /* (in editor, SetBorderElement() is used) */ else SetBorderElement(); diff --git a/src/init.c b/src/init.c index 058590d9..c3c14af2 100644 --- a/src/init.c +++ b/src/init.c @@ -5132,7 +5132,7 @@ void Execute_Command(char *command) exit(0); } - else if (strncmp(command, "dump level ", 11) == 0) + else if (strPrefix(command, "dump level ")) { char *filename = &command[11]; @@ -5144,7 +5144,7 @@ void Execute_Command(char *command) exit(0); } - else if (strncmp(command, "dump tape ", 10) == 0) + else if (strPrefix(command, "dump tape ")) { char *filename = &command[10]; @@ -5156,7 +5156,7 @@ void Execute_Command(char *command) exit(0); } - else if (strncmp(command, "autoplay ", 9) == 0) + else if (strPrefix(command, "autoplay ")) { char *str_ptr = getStringCopy(&command[9]); /* read command parameters */ @@ -5192,13 +5192,15 @@ void Execute_Command(char *command) str_ptr++; } } - else if (strncmp(command, "convert ", 8) == 0) + else if (strPrefix(command, "convert ") || + strPrefix(command, "convert_special_1 ")) { char *str_copy = getStringCopy(&command[8]); char *str_ptr = strchr(str_copy, ' '); global.convert_leveldir = str_copy; global.convert_level_nr = -1; + global.convert_mode_special_1 = strPrefix(command, "convert_special_1 "); if (str_ptr != NULL) /* level number follows */ { @@ -5206,7 +5208,7 @@ void Execute_Command(char *command) global.convert_level_nr = atoi(str_ptr); /* get level_nr value */ } } - else if (strncmp(command, "create images ", 14) == 0) + else if (strPrefix(command, "create images ")) { #if defined(TARGET_SDL) global.create_images_dir = getStringCopy(&command[14]); diff --git a/src/libgame/misc.c b/src/libgame/misc.c index 7883f325..f3e19104 100644 --- a/src/libgame/misc.c +++ b/src/libgame/misc.c @@ -721,7 +721,7 @@ void GetOptions(char *argv[], void (*print_usage_function)(void)) if (strEqual(option, "--")) /* stop scanning arguments */ break; - if (strncmp(option, "--", 2) == 0) /* treat '--' like '-' */ + if (strPrefix(option, "--")) /* treat '--' like '-' */ option++; option_arg = strchr(option, '='); @@ -1429,7 +1429,7 @@ void translate_keyname(Key *keysym, char **x11name, char **name, int mode) Key key = KSYM_UNDEFINED; char *name_ptr = *x11name; - if (strncmp(name_ptr, "XK_", 3) == 0 && strlen(name_ptr) == 4) + if (strPrefix(name_ptr, "XK_") && strlen(name_ptr) == 4) { char c = name_ptr[3]; @@ -1440,14 +1440,14 @@ void translate_keyname(Key *keysym, char **x11name, char **name, int mode) else if (c >= '0' && c <= '9') key = KSYM_0 + (Key)(c - '0'); } - else if (strncmp(name_ptr, "XK_KP_", 6) == 0 && strlen(name_ptr) == 7) + else if (strPrefix(name_ptr, "XK_KP_") && strlen(name_ptr) == 7) { char c = name_ptr[6]; if (c >= '0' && c <= '9') key = KSYM_KP_0 + (Key)(c - '0'); } - else if (strncmp(name_ptr, "XK_F", 4) == 0 && strlen(name_ptr) <= 6) + else if (strPrefix(name_ptr, "XK_F") && strlen(name_ptr) <= 6) { char c1 = name_ptr[4]; char c2 = name_ptr[5]; @@ -1460,7 +1460,7 @@ void translate_keyname(Key *keysym, char **x11name, char **name, int mode) if (d >= 1 && d <= KSYM_NUM_FKEYS) key = KSYM_F1 + (Key)(d - 1); } - else if (strncmp(name_ptr, "XK_", 3) == 0) + else if (strPrefix(name_ptr, "XK_")) { i = 0; @@ -1474,7 +1474,7 @@ void translate_keyname(Key *keysym, char **x11name, char **name, int mode) } while (translate_key[++i].x11name); } - else if (strncmp(name_ptr, "0x", 2) == 0) + else if (strPrefix(name_ptr, "0x")) { unsigned long value = 0; diff --git a/src/main.h b/src/main.h index 2614bbb6..0e8871c9 100644 --- a/src/main.h +++ b/src/main.h @@ -2415,6 +2415,7 @@ struct GlobalInfo char *convert_leveldir; int convert_level_nr; + boolean convert_mode_special_1; char *create_images_dir;