/* 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)
{
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;
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 */
/* 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++;
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;
{
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);
+ }
}
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();
exit(0);
}
- else if (strncmp(command, "dump level ", 11) == 0)
+ else if (strPrefix(command, "dump level "))
{
char *filename = &command[11];
exit(0);
}
- else if (strncmp(command, "dump tape ", 10) == 0)
+ else if (strPrefix(command, "dump tape "))
{
char *filename = &command[10];
exit(0);
}
- else if (strncmp(command, "autoplay ", 9) == 0)
+ else if (strPrefix(command, "autoplay "))
{
char *str_ptr = getStringCopy(&command[9]); /* read command parameters */
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 */
{
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]);
if (strEqual(option, "--")) /* stop scanning arguments */
break;
- if (strncmp(option, "--", 2) == 0) /* treat '--' like '-' */
+ if (strPrefix(option, "--")) /* treat '--' like '-' */
option++;
option_arg = strchr(option, '=');
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];
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];
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;
}
while (translate_key[++i].x11name);
}
- else if (strncmp(name_ptr, "0x", 2) == 0)
+ else if (strPrefix(name_ptr, "0x"))
{
unsigned long value = 0;