X-Git-Url: https://git.artsoft.org/?p=rocksndiamonds.git;a=blobdiff_plain;f=src%2Ffiles.c;h=b16bc6ca5162f709f799680056cdc331ca62ba17;hp=7a29e1eebac839ff06d01b1bc3a068a3404a3c38;hb=a312d80612bb9a448cdc1abbde690b296fa92b17;hpb=7992b03de18aad8527835dfa03375f3a30a7e673 diff --git a/src/files.c b/src/files.c index 7a29e1ee..b16bc6ca 100644 --- a/src/files.c +++ b/src/files.c @@ -182,6 +182,12 @@ static struct LevelFileConfigInfo chunk_config_INFO[] = &li.gems_needed, 0 }, + { + -1, -1, + TYPE_INTEGER, CONF_VALUE_32_BIT(2), + &li.random_seed, 0 + }, + { -1, -1, TYPE_BOOLEAN, CONF_VALUE_8_BIT(2), @@ -218,6 +224,12 @@ static struct LevelFileConfigInfo chunk_config_INFO[] = &li.dont_collide_with_bits, ~0 /* default: always deadly */ }, + { + -1, -1, + TYPE_BOOLEAN, CONF_VALUE_8_BIT(8), + &li.em_explodes_by_fire, FALSE + }, + { -1, -1, TYPE_INTEGER, CONF_VALUE_16_BIT(5), @@ -870,8 +882,8 @@ static struct LevelFileConfigInfo chunk_config_CUSX_base[] = { -1, -1, TYPE_ELEMENT, CONF_VALUE_16_BIT(1), - &xx_ei.gfx_element, EL_EMPTY_SPACE, - &yy_ei.gfx_element + &xx_ei.gfx_element_initial, EL_EMPTY_SPACE, + &yy_ei.gfx_element_initial }, { @@ -1202,7 +1214,7 @@ static struct LevelFileConfigInfo chunk_config_GRPX[] = { -1, -1, TYPE_ELEMENT, CONF_VALUE_16_BIT(1), - &xx_ei.gfx_element, EL_EMPTY_SPACE + &xx_ei.gfx_element_initial, EL_EMPTY_SPACE }, { @@ -1575,8 +1587,10 @@ static void setLevelInfoToDefaults(struct LevelInfo *level) *level = li; /* copy temporary buffer back to level data */ setLevelInfoToDefaults_EM(); + setLevelInfoToDefaults_SP(); level->native_em_level = &native_em_level; + level->native_sp_level = &native_sp_level; level->file_version = FILE_VERSION_ACTUAL; level->game_version = GAME_VERSION_ACTUAL; @@ -1756,21 +1770,33 @@ static char *getLevelFilenameFromBasename(char *basename) static int getFileTypeFromBasename(char *basename) { + /* !!! ALSO SEE COMMENT IN checkForPackageFromBasename() !!! */ + static char *filename = NULL; struct stat file_status; /* ---------- try to determine file type from filename ---------- */ /* check for typical filename of a Supaplex level package file */ +#if 1 + if (strlen(basename) == 10 && strPrefixLower(basename, "levels.d")) + return LEVEL_FILE_TYPE_SP; +#else if (strlen(basename) == 10 && (strncmp(basename, "levels.d", 8) == 0 || strncmp(basename, "LEVELS.D", 8) == 0)) return LEVEL_FILE_TYPE_SP; +#endif /* check for typical filename of a Diamond Caves II level package file */ - if (strSuffix(basename, ".dc") || - strSuffix(basename, ".dc2")) + if (strSuffixLower(basename, ".dc") || + strSuffixLower(basename, ".dc2")) return LEVEL_FILE_TYPE_DC; + /* check for typical filename of a Sokoban level package file */ + if (strSuffixLower(basename, ".xsb") && + strchr(basename, '%') == NULL) + return LEVEL_FILE_TYPE_SB; + /* ---------- try to determine file type from filesize ---------- */ checked_free(filename); @@ -1786,6 +1812,14 @@ static int getFileTypeFromBasename(char *basename) return LEVEL_FILE_TYPE_UNKNOWN; } +static boolean checkForPackageFromBasename(char *basename) +{ + /* !!! WON'T WORK ANYMORE IF getFileTypeFromBasename() ALSO DETECTS !!! + !!! SINGLE LEVELS (CURRENTLY ONLY DETECTS LEVEL PACKAGES !!! */ + + return (getFileTypeFromBasename(basename) != LEVEL_FILE_TYPE_UNKNOWN); +} + static char *getSingleLevelBasename(int nr) { static char basename[MAX_FILENAME_LEN]; @@ -1939,6 +1973,9 @@ static void determineLevelFileInfo_Filename(struct LevelFileInfo *lfi) setLevelFileInfo_FormatLevelFilename(lfi, filetype, leveldir_current->level_filename, nr); + + lfi->packed = checkForPackageFromBasename(leveldir_current->level_filename); + if (fileExists(lfi->filename)) return; } @@ -2023,6 +2060,7 @@ int getMappedElement(int element) case EL_KEY_OBSOLETE: element = EL_KEY_1; + break; case EL_EM_KEY_1_FILE_OBSOLETE: element = EL_EM_KEY_1; @@ -2428,7 +2466,7 @@ static int LoadLevel_CUS3(FILE *file, int chunk_size, struct LevelInfo *level) ReadUnusedBytesFromFile(file, 7); ei->use_gfx_element = getFile8Bit(file); - ei->gfx_element = getMappedElement(getFile16BitBE(file)); + ei->gfx_element_initial = getMappedElement(getFile16BitBE(file)); ei->collect_score_initial = getFile8Bit(file); ei->collect_count_initial = getFile8Bit(file); @@ -2527,7 +2565,7 @@ static int LoadLevel_CUS4(FILE *file, int chunk_size, struct LevelInfo *level) ei->use_last_ce_value = getFile8Bit(file); ei->use_gfx_element = getFile8Bit(file); - ei->gfx_element = getMappedElement(getFile16BitBE(file)); + ei->gfx_element_initial = getMappedElement(getFile16BitBE(file)); ei->collect_score_initial = getFile8Bit(file); ei->collect_count_initial = getFile8Bit(file); @@ -2660,7 +2698,7 @@ static int LoadLevel_GRP1(FILE *file, int chunk_size, struct LevelInfo *level) group->num_elements = getFile8Bit(file); ei->use_gfx_element = getFile8Bit(file); - ei->gfx_element = getMappedElement(getFile16BitBE(file)); + ei->gfx_element_initial = getMappedElement(getFile16BitBE(file)); group->choice_mode = getFile8Bit(file); @@ -3786,30 +3824,13 @@ void CopyNativeLevel_EM_to_RND(struct LevelInfo *level) } } -static void LoadLevelFromFileInfo_EM(struct LevelInfo *level, - struct LevelFileInfo *level_file_info) -{ - if (!LoadNativeLevel_EM(level_file_info->filename)) - level->no_valid_file = TRUE; -} - -void CopyNativeLevel_RND_to_Native(struct LevelInfo *level) -{ - if (level->game_engine_type == GAME_ENGINE_TYPE_EM) - CopyNativeLevel_RND_to_EM(level); -} - -void CopyNativeLevel_Native_to_RND(struct LevelInfo *level) -{ - if (level->game_engine_type == GAME_ENGINE_TYPE_EM) - CopyNativeLevel_EM_to_RND(level); -} - /* ------------------------------------------------------------------------- */ /* functions for loading SP level */ /* ------------------------------------------------------------------------- */ +#if 0 + #define NUM_SUPAPLEX_LEVELS_PER_PACKAGE 111 #define SP_LEVEL_SIZE 1536 #define SP_LEVEL_XSIZE 60 @@ -4000,7 +4021,8 @@ static void LoadLevelFromFileInfo_SP(struct LevelInfo *level, } /* position file stream to the requested level inside the level package */ - if (fseek(file, nr * SP_LEVEL_SIZE, SEEK_SET) != 0) + if (level_file_info->packed && + fseek(file, nr * SP_LEVEL_SIZE, SEEK_SET) != 0) { level->no_valid_file = TRUE; @@ -4154,6 +4176,187 @@ static void LoadLevelFromFileInfo_SP(struct LevelInfo *level, *level = multipart_level; } +#endif + +void CopyNativeLevel_RND_to_SP(struct LevelInfo *level) +{ + struct LevelInfo_SP *level_sp = level->native_sp_level; + LevelInfoType *header = &level_sp->header; + int i, x, y; + + level_sp->width = level->fieldx; + level_sp->height = level->fieldy; + + for (x = 0; x < level->fieldx; x++) + { + for (y = 0; y < level->fieldy; y++) + { + int element_old = level->field[x][y]; + int element_new; + + if (element_old >= EL_SP_START && + element_old <= EL_SP_END) + element_new = element_old - EL_SP_START; + else if (element_old == EL_EMPTY_SPACE) + element_new = 0x00; + else if (element_old == EL_INVISIBLE_WALL) + element_new = 0x28; + else + element_new = 0x20; /* map unknown elements to yellow "hardware" */ + + level_sp->playfield[x][y] = element_new; + } + } + + header->InitialGravity = (level->initial_player_gravity[0] ? 1 : 0); + + for (i = 0; i < SP_LEVEL_NAME_LEN; i++) + header->LevelTitle[i] = level->name[i]; + /* !!! NO STRING TERMINATION IN SUPAPLEX VB CODE YET -- FIX THIS !!! */ + + header->InfotronsNeeded = level->gems_needed; + + /* !!! ADD SPECIAL PORT DATABASE STUFF !!! */ +} + +void CopyNativeLevel_SP_to_RND(struct LevelInfo *level) +{ + struct LevelInfo_SP *level_sp = level->native_sp_level; + LevelInfoType *header = &level_sp->header; + int i, x, y; + + level->fieldx = level_sp->width; + level->fieldy = level_sp->height; + + for (x = 0; x < level->fieldx; x++) + { + for (y = 0; y < level->fieldy; y++) + { + int element_old = level_sp->playfield[x][y]; + int element_new; + + if (element_old <= 0x27) + element_new = getMappedElement(EL_SP_START + element_old); + else if (element_old == 0x28) + element_new = EL_INVISIBLE_WALL; + else + { + Error(ERR_WARN, "invalid element %d at position %d, %d", + element_old, x, y); + + element_new = EL_UNKNOWN; + } + + level->field[x][y] = element_new; + } + } + + for (i = 0; i < MAX_PLAYERS; i++) + level->initial_player_gravity[i] = + (header->InitialGravity == 1 ? TRUE : FALSE); + + for (i = 0; i < SP_LEVEL_NAME_LEN; i++) + level->name[i] = header->LevelTitle[i]; + level->name[SP_LEVEL_NAME_LEN] = '\0'; + + level->gems_needed = header->InfotronsNeeded; + + for (i = 0; i < header->SpecialPortCount; i++) + { + SpecialPortType *port = &header->SpecialPort[i]; + int port_location = port->PortLocation; + int gravity = port->Gravity; + int port_x, port_y, port_element; + + port_x = (port_location / 2) % level->fieldx; + port_y = (port_location / 2) / level->fieldx; + + if (port_x < 0 || port_x >= level->fieldx || + port_y < 0 || port_y >= level->fieldy) + { + Error(ERR_WARN, "special port position (%d, %d) out of bounds", + port_x, port_y); + + continue; + } + + port_element = level->field[port_x][port_y]; + + if (port_element < EL_SP_GRAVITY_PORT_RIGHT || + port_element > EL_SP_GRAVITY_PORT_UP) + { + Error(ERR_WARN, "no special port at position (%d, %d)", port_x, port_y); + + continue; + } + + /* change previous (wrong) gravity inverting special port to either + gravity enabling special port or gravity disabling special port */ + level->field[port_x][port_y] += + (gravity == 1 ? EL_SP_GRAVITY_ON_PORT_RIGHT : + EL_SP_GRAVITY_OFF_PORT_RIGHT) - EL_SP_GRAVITY_PORT_RIGHT; + } + + /* change special gravity ports without database entries to normal ports */ + for (x = 0; x < level->fieldx; x++) + for (y = 0; y < level->fieldy; y++) + if (level->field[x][y] >= EL_SP_GRAVITY_PORT_RIGHT && + level->field[x][y] <= EL_SP_GRAVITY_PORT_UP) + level->field[x][y] += EL_SP_PORT_RIGHT - EL_SP_GRAVITY_PORT_RIGHT; + + level->time = 0; /* no time limit */ + level->amoeba_speed = 0; + level->time_magic_wall = 0; + level->time_wheel = 0; + level->amoeba_content = EL_EMPTY; + +#if 1 + /* original Supaplex does not use score values -- use default values */ +#else + for (i = 0; i < LEVEL_SCORE_ELEMENTS; i++) + level->score[i] = 0; +#endif + + /* there are no yamyams in supaplex levels */ + for (i = 0; i < level->num_yamyam_contents; i++) + for (x = 0; x < 3; x++) + for (y = 0; y < 3; y++) + level->yamyam_content[i].e[x][y] = EL_EMPTY; +} + +static void setTapeInfoToDefaults(); + +static void CopyNativeTape_SP_to_RND(struct LevelInfo *level) +{ + struct LevelInfo_SP *level_sp = level->native_sp_level; + struct DemoInfo_SP *demo = &level_sp->demo; + int i; + + /* always start with reliable default values */ + setTapeInfoToDefaults(); + + tape.level_nr = demo->level_nr; /* (currently not used) */ + tape.length = demo->length - 1; /* without "end of demo" byte */ + tape.random_seed = level_sp->header.DemoRandomSeed; + + // tape.date = + + for (i = 0; i < demo->length - 1; i++) + { + int demo_action = demo->data[i] & 0x0f; + int demo_repeat = (demo->data[i] & 0xf0) >> 4; + + tape.pos[i].action[0] = map_key_SP_to_RND(demo_action); + tape.pos[i].delay = demo_repeat + 1; + } + + tape.length_seconds = GetTapeLength(); +} + + +/* ------------------------------------------------------------------------- */ +/* functions for loading DC level */ +/* ------------------------------------------------------------------------- */ #define DC_LEVEL_HEADER_SIZE 344 @@ -6124,6 +6327,391 @@ static void LoadLevelFromFileInfo_DC(struct LevelInfo *level, #endif +/* ------------------------------------------------------------------------- */ +/* functions for loading SB level */ +/* ------------------------------------------------------------------------- */ + +#if 1 + +static boolean check_special_flags(char *flag) +{ +#if 0 + printf("::: '%s', '%s', '%s'\n", + flag, + options.special_flags, + leveldir_current->special_flags); +#endif + + if (strEqual(options.special_flags, flag) || + strEqual(leveldir_current->special_flags, flag)) + return TRUE; + + return FALSE; +} + +#else + +#define SPECIAL_FLAG_LOAD_XSB_TO_CES (1 << 0) + +static unsigned long get_special_flags(char *flags_string) +{ + unsigned long flags_value = 0; + + if (strEqual(flags_string, "load_xsb_to_ces")) + flags_value = SPECIAL_FLAG_LOAD_XSB_TO_CES; + + return flags_value; +} + +#endif + +int getMappedElement_SB(int element_ascii, boolean use_ces) +{ + static struct + { + int ascii; + int sb; + int ce; + } + 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_ces ? sb_element_mapping[i].ce : sb_element_mapping[i].sb); + + return EL_UNDEFINED; +} + +static void LoadLevelFromFileInfo_SB(struct LevelInfo *level, + struct LevelFileInfo *level_file_info) +{ + char *filename = level_file_info->filename; + char line[MAX_LINE_LEN], line_raw[MAX_LINE_LEN], previous_line[MAX_LINE_LEN]; + char last_comment[MAX_LINE_LEN]; + char level_name[MAX_LINE_LEN]; + char *line_ptr; + FILE *file; + int num_levels_to_skip = level_file_info->nr - leveldir_current->first_level; + boolean read_continued_line = FALSE; + boolean reading_playfield = FALSE; + boolean got_valid_playfield_line = FALSE; + boolean invalid_playfield_char = FALSE; +#if 1 + boolean load_xsb_to_ces = check_special_flags("load_xsb_to_ces"); +#else + boolean load_xsb_to_ces = options.special_flags & SPECIAL_FLAG_LOAD_XSB_TO_CES; +#endif + 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; + + Error(ERR_WARN, "cannot read level '%s' -- using empty level", filename); + + return; + } + + while (!feof(file)) + { + /* level successfully read, but next level may follow here */ + if (!got_valid_playfield_line && reading_playfield) + { +#if 0 + printf("::: read complete playfield\n"); +#endif + + /* read playfield from single level file -- skip remaining file */ + if (!level_file_info->packed) + break; + + if (file_level_nr >= num_levels_to_skip) + break; + + file_level_nr++; + + last_comment[0] = '\0'; + level_name[0] = '\0'; + + reading_playfield = FALSE; + } + + got_valid_playfield_line = FALSE; + + /* read next line of input file */ + if (!fgets(line, MAX_LINE_LEN, file)) + break; + + /* check if line was completely read and is terminated by line break */ + if (strlen(line) > 0 && line[strlen(line) - 1] == '\n') + line_nr++; + + /* cut trailing line break (this can be newline and/or carriage return) */ + for (line_ptr = &line[strlen(line)]; line_ptr >= line; line_ptr--) + if ((*line_ptr == '\n' || *line_ptr == '\r') && *(line_ptr + 1) == '\0') + *line_ptr = '\0'; + + /* copy raw input line for later use (mainly debugging output) */ + strcpy(line_raw, line); + + if (read_continued_line) + { + /* append new line to existing line, if there is enough space */ + if (strlen(previous_line) + strlen(line_ptr) < MAX_LINE_LEN) + strcat(previous_line, line_ptr); + + strcpy(line, previous_line); /* copy storage buffer to line */ + + read_continued_line = FALSE; + } + + /* if the last character is '\', continue at next line */ + if (strlen(line) > 0 && line[strlen(line) - 1] == '\\') + { + line[strlen(line) - 1] = '\0'; /* cut off trailing backslash */ + strcpy(previous_line, line); /* copy line to storage buffer */ + + read_continued_line = TRUE; + + continue; + } + + /* skip empty lines */ + if (line[0] == '\0') + continue; + + /* extract comment text from comment line */ + if (line[0] == ';') + { + for (line_ptr = line; *line_ptr; line_ptr++) + if (*line_ptr != ' ' && *line_ptr != '\t' && *line_ptr != ';') + break; + + strcpy(last_comment, line_ptr); + +#if 0 + printf("::: found comment '%s' in line %d\n", last_comment, line_nr); +#endif + + continue; + } + + /* extract level title text from line containing level title */ + if (line[0] == '\'') + { + strcpy(level_name, &line[1]); + + if (strlen(level_name) > 0 && level_name[strlen(level_name) - 1] == '\'') + level_name[strlen(level_name) - 1] = '\0'; + +#if 0 + printf("::: found level name '%s' in line %d\n", level_name, line_nr); +#endif + + continue; + } + + /* skip lines containing only spaces (or empty lines) */ + for (line_ptr = line; *line_ptr; line_ptr++) + if (*line_ptr != ' ') + break; + if (*line_ptr == '\0') + continue; + + /* at this point, we have found a line containing part of a playfield */ + +#if 0 + printf("::: found playfield row in line %d\n", line_nr); +#endif + + got_valid_playfield_line = TRUE; + + if (!reading_playfield) + { + reading_playfield = TRUE; + invalid_playfield_char = FALSE; + + for (x = 0; x < MAX_LEV_FIELDX; x++) + for (y = 0; y < MAX_LEV_FIELDY; y++) + level->field[x][y] = getMappedElement_SB(' ', load_xsb_to_ces); + + level->fieldx = 0; + level->fieldy = 0; + + /* start with topmost tile row */ + y = 0; + } + + /* skip playfield line if larger row than allowed */ + if (y >= MAX_LEV_FIELDY) + continue; + + /* start with leftmost tile column */ + x = 0; + + /* read playfield elements from line */ + for (line_ptr = line; *line_ptr; line_ptr++) + { + int mapped_sb_element = getMappedElement_SB(*line_ptr, load_xsb_to_ces); + + /* stop parsing playfield line if larger column than allowed */ + if (x >= MAX_LEV_FIELDX) + break; + + if (mapped_sb_element == EL_UNDEFINED) + { + invalid_playfield_char = TRUE; + + break; + } + + level->field[x][y] = mapped_sb_element; + + /* continue with next tile column */ + x++; + + level->fieldx = MAX(x, level->fieldx); + } + + if (invalid_playfield_char) + { + /* if first playfield line, treat invalid lines as comment lines */ + if (y == 0) + reading_playfield = FALSE; + + continue; + } + + /* continue with next tile row */ + 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); + + if (!reading_playfield) + { + level->no_valid_file = TRUE; + + Error(ERR_WARN, "cannot read level '%s' -- using empty level", filename); + + return; + } + + if (*level_name != '\0') + { + strncpy(level->name, level_name, MAX_LEVEL_NAME_LEN); + level->name[MAX_LEVEL_NAME_LEN] = '\0'; + +#if 0 + printf(":1: level name: '%s'\n", level->name); +#endif + } + else if (*last_comment != '\0') + { + strncpy(level->name, last_comment, MAX_LEVEL_NAME_LEN); + level->name[MAX_LEVEL_NAME_LEN] = '\0'; + +#if 0 + printf(":2: level name: '%s'\n", level->name); +#endif + } + else + { + sprintf(level->name, "--> Level %d <--", level_file_info->nr); + } + + /* set all empty fields beyond the border walls to invisible steel wall */ + 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(' ', load_xsb_to_ces)) + FloodFillLevel(x, y, getMappedElement_SB('_', load_xsb_to_ces), + level->field, level->fieldx, level->fieldy); + } + + if (load_xsb_to_ces) + { + level->time = 0; + level->use_step_counter = TRUE; + + level->initial_player_stepsize[0] = STEPSIZE_SLOW; + + level->use_custom_template = TRUE; + } +} + + +/* ------------------------------------------------------------------------- */ +/* functions for handling native levels */ +/* ------------------------------------------------------------------------- */ + +static void LoadLevelFromFileInfo_EM(struct LevelInfo *level, + struct LevelFileInfo *level_file_info) +{ + if (!LoadNativeLevel_EM(level_file_info->filename)) + level->no_valid_file = TRUE; +} + +static void LoadLevelFromFileInfo_SP(struct LevelInfo *level, + struct LevelFileInfo *level_file_info) +{ + int pos = 0; + + /* determine position of requested level inside level package */ + if (level_file_info->packed) + pos = level_file_info->nr - leveldir_current->first_level; + + if (!LoadNativeLevel_SP(level_file_info->filename, pos)) + level->no_valid_file = TRUE; +} + +void CopyNativeLevel_RND_to_Native(struct LevelInfo *level) +{ + if (level->game_engine_type == GAME_ENGINE_TYPE_EM) + CopyNativeLevel_RND_to_EM(level); + else if (level->game_engine_type == GAME_ENGINE_TYPE_SP) + CopyNativeLevel_RND_to_SP(level); +} + +void CopyNativeLevel_Native_to_RND(struct LevelInfo *level) +{ + if (level->game_engine_type == GAME_ENGINE_TYPE_EM) + CopyNativeLevel_EM_to_RND(level); + else if (level->game_engine_type == GAME_ENGINE_TYPE_SP) + CopyNativeLevel_SP_to_RND(level); +} + + /* ------------------------------------------------------------------------- */ /* functions for loading generic level */ /* ------------------------------------------------------------------------- */ @@ -6147,12 +6735,17 @@ void LoadLevelFromFileInfo(struct LevelInfo *level, case LEVEL_FILE_TYPE_SP: LoadLevelFromFileInfo_SP(level, level_file_info); + level->game_engine_type = GAME_ENGINE_TYPE_SP; break; case LEVEL_FILE_TYPE_DC: LoadLevelFromFileInfo_DC(level, level_file_info); break; + case LEVEL_FILE_TYPE_SB: + LoadLevelFromFileInfo_SB(level, level_file_info); + break; + default: LoadLevelFromFileInfo_RND(level, level_file_info); break; @@ -6332,6 +6925,32 @@ static void LoadLevel_InitVersion(struct LevelInfo *level, char *filename) change->target_element = EL_PLAYER_1; } +#if 1 + /* try to detect and fix "Zelda" style levels, which are broken with 3.2.5 */ + if (level->game_version < VERSION_IDENT(3,2,5,0)) + { + /* This is needed to fix a problem that was caused by a bugfix in function + game.c/CheckTriggeredElementChangeExt() introduced with 3.2.5 that + corrects the behaviour when a custom element changes to another custom + element with a higher element number that has change actions defined. + Normally, only one change per frame is allowed for custom elements. + Therefore, it is checked if a custom element already changed in the + current frame; if it did, subsequent changes are suppressed. + Unfortunately, this is only checked for element changes, but not for + change actions, which are still executed. As the function above loops + through all custom elements from lower to higher, an element change + resulting in a lower CE number won't be checked again, while a target + element with a higher number will also be checked, and potential change + actions will get executed for this CE, too (which is wrong), while + further changes are ignored (which is correct). As this bugfix breaks + Zelda II (and introduces graphical bugs to Zelda I, and also breaks a + few other levels like Alan Bond's "FMV"), allow the previous, incorrect + behaviour for existing levels and tapes that make use of this bug */ + + level->use_action_after_change_bug = TRUE; + } +#else + /* !!! THIS DOES NOT FIX "Zelda I" (GRAPHICALLY) AND "Alan's FMV" LEVELS */ /* try to detect and fix "Zelda II" levels, which are broken with 3.2.5 */ { int element = EL_CUSTOM_16; @@ -6358,10 +6977,15 @@ static void LoadLevel_InitVersion(struct LevelInfo *level, char *filename) strncmp(ei->description, "scanline - row 1", 16) == 0) level->use_action_after_change_bug = TRUE; } +#endif /* not centering level after relocating player was default only in 3.2.3 */ if (level->game_version == VERSION_IDENT(3,2,3,0)) /* (no pre-releases) */ level->shifted_relocation = TRUE; + + /* EM style elements always chain-exploded in R'n'D engine before 3.2.6 */ + if (level->game_version < VERSION_IDENT(3,2,6,0)) + level->em_explodes_by_fire = TRUE; } static void LoadLevel_InitElements(struct LevelInfo *level, char *filename) @@ -6493,6 +7117,7 @@ static void LoadLevel_InitElements(struct LevelInfo *level, char *filename) /* initialize element properties for level editor etc. */ InitElementPropertiesEngine(level->game_version); InitElementPropertiesAfterLoading(level->game_version); + InitElementPropertiesGfxElement(); } static void LoadLevel_InitPlayfield(struct LevelInfo *level, char *filename) @@ -6871,7 +7496,7 @@ static void SaveLevel_CUS3(FILE *file, struct LevelInfo *level, WriteUnusedBytesToFile(file, 7); putFile8Bit(file, ei->use_gfx_element); - putFile16BitBE(file, ei->gfx_element); + putFile16BitBE(file, ei->gfx_element_initial); putFile8Bit(file, ei->collect_score_initial); putFile8Bit(file, ei->collect_count_initial); @@ -6950,7 +7575,7 @@ static void SaveLevel_CUS4(FILE *file, struct LevelInfo *level, int element) putFile8Bit(file, ei->use_last_ce_value); putFile8Bit(file, ei->use_gfx_element); - putFile16BitBE(file, ei->gfx_element); + putFile16BitBE(file, ei->gfx_element_initial); putFile8Bit(file, ei->collect_score_initial); putFile8Bit(file, ei->collect_count_initial); @@ -7061,7 +7686,7 @@ static void SaveLevel_GRP1(FILE *file, struct LevelInfo *level, int element) putFile8Bit(file, group->num_elements); putFile8Bit(file, ei->use_gfx_element); - putFile16BitBE(file, ei->gfx_element); + putFile16BitBE(file, ei->gfx_element_initial); putFile8Bit(file, group->choice_mode); @@ -7793,6 +8418,13 @@ void LoadSolutionTape(int nr) char *filename = getSolutionTapeFilename(nr); LoadTapeFromFilename(filename); + +#if 1 + if (TAPE_IS_EMPTY(tape) && + level.game_engine_type == GAME_ENGINE_TYPE_SP && + level.native_sp_level->demo.is_available) + CopyNativeTape_SP_to_RND(&level); +#endif } static void SaveTape_VERS(FILE *file, struct TapeInfo *tape) @@ -8107,14 +8739,15 @@ void SaveScore(int nr) #define SETUP_TOKEN_INPUT_ON_FOCUS 22 #define SETUP_TOKEN_PREFER_AGA_GRAPHICS 23 #define SETUP_TOKEN_GAME_FRAME_DELAY 24 -#define SETUP_TOKEN_GRAPHICS_SET 25 -#define SETUP_TOKEN_SOUNDS_SET 26 -#define SETUP_TOKEN_MUSIC_SET 27 -#define SETUP_TOKEN_OVERRIDE_LEVEL_GRAPHICS 28 -#define SETUP_TOKEN_OVERRIDE_LEVEL_SOUNDS 29 -#define SETUP_TOKEN_OVERRIDE_LEVEL_MUSIC 30 +#define SETUP_TOKEN_SP_SHOW_BORDER_ELEMENTS 25 +#define SETUP_TOKEN_GRAPHICS_SET 26 +#define SETUP_TOKEN_SOUNDS_SET 27 +#define SETUP_TOKEN_MUSIC_SET 28 +#define SETUP_TOKEN_OVERRIDE_LEVEL_GRAPHICS 29 +#define SETUP_TOKEN_OVERRIDE_LEVEL_SOUNDS 30 +#define SETUP_TOKEN_OVERRIDE_LEVEL_MUSIC 31 -#define NUM_GLOBAL_SETUP_TOKENS 31 +#define NUM_GLOBAL_SETUP_TOKENS 32 /* editor setup */ #define SETUP_TOKEN_EDITOR_EL_BOULDERDASH 0 @@ -8211,34 +8844,35 @@ static struct OptionInfo soi; static struct TokenInfo global_setup_tokens[] = { - { TYPE_STRING, &si.player_name, "player_name" }, - { TYPE_SWITCH, &si.sound, "sound" }, - { TYPE_SWITCH, &si.sound_loops, "repeating_sound_loops" }, - { TYPE_SWITCH, &si.sound_music, "background_music" }, - { TYPE_SWITCH, &si.sound_simple, "simple_sound_effects" }, - { TYPE_SWITCH, &si.toons, "toons" }, - { TYPE_SWITCH, &si.scroll_delay, "scroll_delay" }, - { TYPE_INTEGER,&si.scroll_delay_value,"scroll_delay_value" }, - { TYPE_SWITCH, &si.soft_scrolling, "soft_scrolling" }, - { TYPE_SWITCH, &si.fade_screens, "fade_screens" }, - { TYPE_SWITCH, &si.autorecord, "automatic_tape_recording" }, - { TYPE_SWITCH, &si.show_titlescreen, "show_titlescreen" }, - { TYPE_SWITCH, &si.quick_doors, "quick_doors" }, - { TYPE_SWITCH, &si.team_mode, "team_mode" }, - { TYPE_SWITCH, &si.handicap, "handicap" }, - { TYPE_SWITCH, &si.skip_levels, "skip_levels" }, - { TYPE_SWITCH, &si.time_limit, "time_limit" }, - { TYPE_SWITCH, &si.fullscreen, "fullscreen" }, - { TYPE_STRING, &si.fullscreen_mode, "fullscreen_mode" }, - { TYPE_SWITCH, &si.ask_on_escape, "ask_on_escape" }, - { TYPE_SWITCH, &si.ask_on_escape_editor, "ask_on_escape_editor" }, - { TYPE_SWITCH, &si.quick_switch, "quick_player_switch" }, - { TYPE_SWITCH, &si.input_on_focus, "input_on_focus" }, - { TYPE_SWITCH, &si.prefer_aga_graphics, "prefer_aga_graphics" }, - { TYPE_INTEGER,&si.game_frame_delay, "game_frame_delay" }, - { TYPE_STRING, &si.graphics_set, "graphics_set" }, - { TYPE_STRING, &si.sounds_set, "sounds_set" }, - { TYPE_STRING, &si.music_set, "music_set" }, + { TYPE_STRING, &si.player_name, "player_name" }, + { TYPE_SWITCH, &si.sound, "sound" }, + { TYPE_SWITCH, &si.sound_loops, "repeating_sound_loops" }, + { TYPE_SWITCH, &si.sound_music, "background_music" }, + { TYPE_SWITCH, &si.sound_simple, "simple_sound_effects" }, + { TYPE_SWITCH, &si.toons, "toons" }, + { TYPE_SWITCH, &si.scroll_delay, "scroll_delay" }, + { TYPE_INTEGER,&si.scroll_delay_value, "scroll_delay_value" }, + { TYPE_SWITCH, &si.soft_scrolling, "soft_scrolling" }, + { TYPE_SWITCH, &si.fade_screens, "fade_screens" }, + { TYPE_SWITCH, &si.autorecord, "automatic_tape_recording"}, + { TYPE_SWITCH, &si.show_titlescreen, "show_titlescreen" }, + { TYPE_SWITCH, &si.quick_doors, "quick_doors" }, + { TYPE_SWITCH, &si.team_mode, "team_mode" }, + { TYPE_SWITCH, &si.handicap, "handicap" }, + { TYPE_SWITCH, &si.skip_levels, "skip_levels" }, + { TYPE_SWITCH, &si.time_limit, "time_limit" }, + { TYPE_SWITCH, &si.fullscreen, "fullscreen" }, + { TYPE_STRING, &si.fullscreen_mode, "fullscreen_mode" }, + { TYPE_SWITCH, &si.ask_on_escape, "ask_on_escape" }, + { TYPE_SWITCH, &si.ask_on_escape_editor, "ask_on_escape_editor" }, + { TYPE_SWITCH, &si.quick_switch, "quick_player_switch" }, + { TYPE_SWITCH, &si.input_on_focus, "input_on_focus" }, + { TYPE_SWITCH, &si.prefer_aga_graphics, "prefer_aga_graphics" }, + { TYPE_INTEGER,&si.game_frame_delay, "game_frame_delay" }, + { TYPE_SWITCH, &si.sp_show_border_elements, "sp_show_border_elements" }, + { TYPE_STRING, &si.graphics_set, "graphics_set" }, + { TYPE_STRING, &si.sounds_set, "sounds_set" }, + { TYPE_STRING, &si.music_set, "music_set" }, { TYPE_SWITCH3,&si.override_level_graphics, "override_level_graphics" }, { TYPE_SWITCH3,&si.override_level_sounds, "override_level_sounds" }, { TYPE_SWITCH3,&si.override_level_music, "override_level_music" }, @@ -8389,6 +9023,7 @@ static void setSetupInfoToDefaults(struct SetupInfo *si) si->input_on_focus = FALSE; si->prefer_aga_graphics = TRUE; si->game_frame_delay = GAME_FRAME_DELAY; + si->sp_show_border_elements = FALSE; si->graphics_set = getStringCopy(GFX_DEFAULT_SUBDIR); si->sounds_set = getStringCopy(SND_DEFAULT_SUBDIR); @@ -9850,6 +10485,8 @@ void CreateLevelSketchImages() Bitmap *bitmap2; int i; + InitElementPropertiesGfxElement(); + bitmap1 = CreateBitmap(TILEX, TILEY, DEFAULT_DEPTH); bitmap2 = CreateBitmap(MINI_TILEX, MINI_TILEY, DEFAULT_DEPTH); @@ -9857,7 +10494,8 @@ void CreateLevelSketchImages() { Bitmap *src_bitmap; int src_x, src_y; - int graphic = el2edimg(i); + int element = getMappedElement(i); + int graphic = el2edimg(element); char basename1[16]; char basename2[16]; char *filename1;