+ // always start with reliable default values
+ setLevelInfoToDefaults(level, level_info_only, TRUE);
+
+ switch (level_file_info->type)
+ {
+ case LEVEL_FILE_TYPE_RND:
+ LoadLevelFromFileInfo_RND(level, level_file_info, level_info_only);
+ break;
+
+ case LEVEL_FILE_TYPE_EM:
+ LoadLevelFromFileInfo_EM(level, level_file_info, level_info_only);
+ level->game_engine_type = GAME_ENGINE_TYPE_EM;
+ break;
+
+ case LEVEL_FILE_TYPE_SP:
+ LoadLevelFromFileInfo_SP(level, level_file_info, level_info_only);
+ level->game_engine_type = GAME_ENGINE_TYPE_SP;
+ break;
+
+ case LEVEL_FILE_TYPE_MM:
+ LoadLevelFromFileInfo_MM(level, level_file_info, level_info_only);
+ level->game_engine_type = GAME_ENGINE_TYPE_MM;
+ break;
+
+ case LEVEL_FILE_TYPE_DC:
+ LoadLevelFromFileInfo_DC(level, level_file_info, level_info_only);
+ break;
+
+ case LEVEL_FILE_TYPE_SB:
+ LoadLevelFromFileInfo_SB(level, level_file_info, level_info_only);
+ break;
+
+ default:
+ LoadLevelFromFileInfo_RND(level, level_file_info, level_info_only);
+ break;
+ }
+
+ // if level file is invalid, restore level structure to default values
+ if (level->no_valid_file)
+ setLevelInfoToDefaults(level, level_info_only, FALSE);
+
+ if (level->game_engine_type == GAME_ENGINE_TYPE_UNKNOWN)
+ level->game_engine_type = GAME_ENGINE_TYPE_RND;
+
+ if (level_file_info->type != LEVEL_FILE_TYPE_RND)
+ CopyNativeLevel_Native_to_RND(level);
+}
+
+void LoadLevelFromFilename(struct LevelInfo *level, char *filename)
+{
+ static struct LevelFileInfo level_file_info;
+
+ // always start with reliable default values
+ setFileInfoToDefaults(&level_file_info);
+
+ level_file_info.nr = 0; // unknown level number
+ level_file_info.type = LEVEL_FILE_TYPE_RND; // no others supported yet
+
+ setString(&level_file_info.filename, filename);
+
+ LoadLevelFromFileInfo(level, &level_file_info, FALSE);
+}
+
+static void LoadLevel_InitVersion(struct LevelInfo *level)
+{
+ int i, j;
+
+ if (leveldir_current == NULL) // only when dumping level
+ return;
+
+ // all engine modifications also valid for levels which use latest engine
+ if (level->game_version < VERSION_IDENT(3,2,0,5))
+ {
+ // time bonus score was given for 10 s instead of 1 s before 3.2.0-5
+ level->score[SC_TIME_BONUS] /= 10;
+ }
+
+ if (leveldir_current->latest_engine)
+ {
+ // ---------- use latest game engine --------------------------------------
+
+ /* For all levels which are forced to use the latest game engine version
+ (normally all but user contributed, private and undefined levels), set
+ the game engine version to the actual version; this allows for actual
+ corrections in the game engine to take effect for existing, converted
+ levels (from "classic" or other existing games) to make the emulation
+ of the corresponding game more accurate, while (hopefully) not breaking
+ existing levels created from other players. */
+
+ level->game_version = GAME_VERSION_ACTUAL;
+
+ /* Set special EM style gems behaviour: EM style gems slip down from
+ normal, steel and growing wall. As this is a more fundamental change,
+ it seems better to set the default behaviour to "off" (as it is more
+ natural) and make it configurable in the level editor (as a property
+ of gem style elements). Already existing converted levels (neither
+ private nor contributed levels) are changed to the new behaviour. */
+
+ if (level->file_version < FILE_VERSION_2_0)
+ level->em_slippery_gems = TRUE;
+
+ return;
+ }
+
+ // ---------- use game engine the level was created with --------------------
+
+ /* For all levels which are not forced to use the latest game engine
+ version (normally user contributed, private and undefined levels),
+ use the version of the game engine the levels were created for.
+
+ Since 2.0.1, the game engine version is now directly stored
+ in the level file (chunk "VERS"), so there is no need anymore
+ to set the game version from the file version (except for old,
+ pre-2.0 levels, where the game version is still taken from the
+ file format version used to store the level -- see above). */
+
+ // player was faster than enemies in 1.0.0 and before
+ if (level->file_version == FILE_VERSION_1_0)
+ for (i = 0; i < MAX_PLAYERS; i++)
+ level->initial_player_stepsize[i] = STEPSIZE_FAST;
+
+ // default behaviour for EM style gems was "slippery" only in 2.0.1
+ if (level->game_version == VERSION_IDENT(2,0,1,0))
+ level->em_slippery_gems = TRUE;
+
+ // springs could be pushed over pits before (pre-release version) 2.2.0
+ if (level->game_version < VERSION_IDENT(2,2,0,0))
+ level->use_spring_bug = TRUE;
+
+ if (level->game_version < VERSION_IDENT(3,2,0,5))
+ {
+ // time orb caused limited time in endless time levels before 3.2.0-5
+ level->use_time_orb_bug = TRUE;
+
+ // default behaviour for snapping was "no snap delay" before 3.2.0-5
+ level->block_snap_field = FALSE;
+
+ // extra time score was same value as time left score before 3.2.0-5
+ level->extra_time_score = level->score[SC_TIME_BONUS];
+ }
+
+ if (level->game_version < VERSION_IDENT(3,2,0,7))
+ {
+ // default behaviour for snapping was "not continuous" before 3.2.0-7
+ level->continuous_snapping = FALSE;
+ }
+
+ // only few elements were able to actively move into acid before 3.1.0
+ // trigger settings did not exist before 3.1.0; set to default "any"
+ if (level->game_version < VERSION_IDENT(3,1,0,0))
+ {
+ // correct "can move into acid" settings (all zero in old levels)
+
+ level->can_move_into_acid_bits = 0; // nothing can move into acid
+ level->dont_collide_with_bits = 0; // nothing is deadly when colliding
+
+ setMoveIntoAcidProperty(level, EL_ROBOT, TRUE);
+ setMoveIntoAcidProperty(level, EL_SATELLITE, TRUE);
+ setMoveIntoAcidProperty(level, EL_PENGUIN, TRUE);
+ setMoveIntoAcidProperty(level, EL_BALLOON, TRUE);
+
+ for (i = 0; i < NUM_CUSTOM_ELEMENTS; i++)
+ SET_PROPERTY(EL_CUSTOM_START + i, EP_CAN_MOVE_INTO_ACID, TRUE);
+
+ // correct trigger settings (stored as zero == "none" in old levels)
+
+ for (i = 0; i < NUM_CUSTOM_ELEMENTS; i++)
+ {
+ int element = EL_CUSTOM_START + i;
+ struct ElementInfo *ei = &element_info[element];
+
+ for (j = 0; j < ei->num_change_pages; j++)
+ {
+ struct ElementChangeInfo *change = &ei->change_page[j];
+
+ change->trigger_player = CH_PLAYER_ANY;
+ change->trigger_page = CH_PAGE_ANY;
+ }
+ }
+ }
+
+ // try to detect and fix "Snake Bite" levels, which are broken with 3.2.0
+ {
+ int element = EL_CUSTOM_256;
+ struct ElementInfo *ei = &element_info[element];
+ struct ElementChangeInfo *change = &ei->change_page[0];
+
+ /* This is needed to fix a problem that was caused by a bugfix in function
+ game.c/CreateFieldExt() introduced with 3.2.0 that corrects the behaviour
+ when a custom element changes to EL_SOKOBAN_FIELD_PLAYER (before, it did
+ not replace walkable elements, but instead just placed the player on it,
+ without placing the Sokoban field under the player). Unfortunately, this
+ breaks "Snake Bite" style levels when the snake is halfway through a door
+ that just closes (the snake head is still alive and can be moved in this
+ case). This can be fixed by replacing the EL_SOKOBAN_FIELD_PLAYER by the
+ player (without Sokoban element) which then gets killed as designed). */
+
+ if ((strncmp(leveldir_current->identifier, "snake_bite", 10) == 0 ||
+ strncmp(ei->description, "pause b4 death", 14) == 0) &&
+ change->target_element == EL_SOKOBAN_FIELD_PLAYER)
+ change->target_element = EL_PLAYER_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;
+ }
+
+ // 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;
+
+ // levels were solved by the first player entering an exit up to 4.1.0.0
+ if (level->game_version <= VERSION_IDENT(4,1,0,0))
+ level->solved_by_one_player = TRUE;
+
+ // game logic of "game of life" and "biomaze" was buggy before 4.1.1.1
+ if (level->game_version < VERSION_IDENT(4,1,1,1))
+ level->use_life_bugs = TRUE;
+
+ // only Sokoban fields (but not objects) had to be solved before 4.1.1.1
+ if (level->game_version < VERSION_IDENT(4,1,1,1))
+ level->sb_objects_needed = FALSE;
+}
+
+static void LoadLevel_InitStandardElements(struct LevelInfo *level)
+{
+ int i, x, y;
+
+ // map elements that have changed in newer versions
+ level->amoeba_content = getMappedElementByVersion(level->amoeba_content,
+ level->game_version);
+ for (i = 0; i < MAX_ELEMENT_CONTENTS; i++)
+ for (x = 0; x < 3; x++)
+ for (y = 0; y < 3; y++)
+ level->yamyam_content[i].e[x][y] =
+ getMappedElementByVersion(level->yamyam_content[i].e[x][y],
+ level->game_version);
+
+}
+
+static void LoadLevel_InitCustomElements(struct LevelInfo *level)
+{
+ int i, j;
+
+ // map custom element change events that have changed in newer versions
+ // (these following values were accidentally changed in version 3.0.1)
+ // (this seems to be needed only for 'ab_levelset3' and 'ab_levelset4')
+ if (level->game_version <= VERSION_IDENT(3,0,0,0))
+ {
+ for (i = 0; i < NUM_CUSTOM_ELEMENTS; i++)
+ {
+ int element = EL_CUSTOM_START + i;
+
+ // order of checking and copying events to be mapped is important
+ // (do not change the start and end value -- they are constant)
+ for (j = CE_BY_OTHER_ACTION; j >= CE_VALUE_GETS_ZERO; j--)
+ {
+ if (HAS_CHANGE_EVENT(element, j - 2))
+ {
+ SET_CHANGE_EVENT(element, j - 2, FALSE);
+ SET_CHANGE_EVENT(element, j, TRUE);
+ }
+ }
+
+ // order of checking and copying events to be mapped is important
+ // (do not change the start and end value -- they are constant)
+ for (j = CE_PLAYER_COLLECTS_X; j >= CE_HITTING_SOMETHING; j--)
+ {
+ if (HAS_CHANGE_EVENT(element, j - 1))
+ {
+ SET_CHANGE_EVENT(element, j - 1, FALSE);
+ SET_CHANGE_EVENT(element, j, TRUE);
+ }
+ }
+ }
+ }
+
+ // initialize "can_change" field for old levels with only one change page
+ if (level->game_version <= VERSION_IDENT(3,0,2,0))
+ {
+ for (i = 0; i < NUM_CUSTOM_ELEMENTS; i++)
+ {
+ int element = EL_CUSTOM_START + i;
+
+ if (CAN_CHANGE(element))
+ element_info[element].change->can_change = TRUE;
+ }
+ }
+
+ // correct custom element values (for old levels without these options)
+ if (level->game_version < VERSION_IDENT(3,1,1,0))
+ {
+ for (i = 0; i < NUM_CUSTOM_ELEMENTS; i++)
+ {
+ int element = EL_CUSTOM_START + i;
+ struct ElementInfo *ei = &element_info[element];
+
+ if (ei->access_direction == MV_NO_DIRECTION)
+ ei->access_direction = MV_ALL_DIRECTIONS;
+ }
+ }
+
+ // correct custom element values (fix invalid values for all versions)
+ if (1)
+ {
+ for (i = 0; i < NUM_CUSTOM_ELEMENTS; i++)
+ {
+ int element = EL_CUSTOM_START + i;
+ struct ElementInfo *ei = &element_info[element];
+
+ for (j = 0; j < ei->num_change_pages; j++)
+ {
+ struct ElementChangeInfo *change = &ei->change_page[j];
+
+ if (change->trigger_player == CH_PLAYER_NONE)
+ change->trigger_player = CH_PLAYER_ANY;
+
+ if (change->trigger_side == CH_SIDE_NONE)
+ change->trigger_side = CH_SIDE_ANY;
+ }
+ }
+ }
+
+ // initialize "can_explode" field for old levels which did not store this
+ // !!! CHECK THIS -- "<= 3,1,0,0" IS PROBABLY WRONG !!!
+ if (level->game_version <= VERSION_IDENT(3,1,0,0))
+ {
+ for (i = 0; i < NUM_CUSTOM_ELEMENTS; i++)
+ {
+ int element = EL_CUSTOM_START + i;
+
+ if (EXPLODES_1X1_OLD(element))
+ element_info[element].explosion_type = EXPLODES_1X1;
+
+ SET_PROPERTY(element, EP_CAN_EXPLODE, (EXPLODES_BY_FIRE(element) ||
+ EXPLODES_SMASHED(element) ||
+ EXPLODES_IMPACT(element)));
+ }
+ }
+
+ // correct previously hard-coded move delay values for maze runner style
+ if (level->game_version < VERSION_IDENT(3,1,1,0))
+ {
+ for (i = 0; i < NUM_CUSTOM_ELEMENTS; i++)
+ {
+ int element = EL_CUSTOM_START + i;
+
+ if (element_info[element].move_pattern & MV_MAZE_RUNNER_STYLE)
+ {
+ // previously hard-coded and therefore ignored
+ element_info[element].move_delay_fixed = 9;
+ element_info[element].move_delay_random = 0;
+ }
+ }
+ }
+
+ // set some other uninitialized values of custom elements in older levels
+ if (level->game_version < VERSION_IDENT(3,1,0,0))
+ {
+ for (i = 0; i < NUM_CUSTOM_ELEMENTS; i++)
+ {
+ int element = EL_CUSTOM_START + i;
+
+ element_info[element].access_direction = MV_ALL_DIRECTIONS;
+
+ element_info[element].explosion_delay = 17;
+ element_info[element].ignition_delay = 8;
+ }
+ }
+}
+
+static void LoadLevel_InitElements(struct LevelInfo *level)
+{
+ LoadLevel_InitStandardElements(level);
+
+ if (level->file_has_custom_elements)
+ LoadLevel_InitCustomElements(level);
+
+ // initialize element properties for level editor etc.
+ InitElementPropertiesEngine(level->game_version);
+ InitElementPropertiesGfxElement();
+}
+
+static void LoadLevel_InitPlayfield(struct LevelInfo *level)
+{
+ int x, y;
+
+ // map elements that have changed in newer versions
+ for (y = 0; y < level->fieldy; y++)
+ for (x = 0; x < level->fieldx; x++)
+ level->field[x][y] = getMappedElementByVersion(level->field[x][y],
+ level->game_version);
+
+ // clear unused playfield data (nicer if level gets resized in editor)
+ for (x = 0; x < MAX_LEV_FIELDX; x++)
+ for (y = 0; y < MAX_LEV_FIELDY; y++)
+ if (x >= level->fieldx || y >= level->fieldy)
+ level->field[x][y] = EL_EMPTY;
+
+ // copy elements to runtime playfield array
+ for (x = 0; x < MAX_LEV_FIELDX; x++)
+ for (y = 0; y < MAX_LEV_FIELDY; y++)
+ Feld[x][y] = level->field[x][y];
+
+ // initialize level size variables for faster access
+ lev_fieldx = level->fieldx;
+ lev_fieldy = level->fieldy;
+
+ // determine border element for this level
+ if (level->file_info.type == LEVEL_FILE_TYPE_DC)
+ BorderElement = EL_EMPTY; // (in editor, SetBorderElement() is used)
+ else
+ SetBorderElement();
+}
+
+static void LoadLevel_InitNativeEngines(struct LevelInfo *level)
+{
+ struct LevelFileInfo *level_file_info = &level->file_info;
+
+ if (level_file_info->type == LEVEL_FILE_TYPE_RND)
+ CopyNativeLevel_RND_to_Native(level);
+}
+
+static void LoadLevelTemplate_LoadAndInit(void)
+{
+ LoadLevelFromFileInfo(&level_template, &level_template.file_info, FALSE);
+
+ LoadLevel_InitVersion(&level_template);
+ LoadLevel_InitElements(&level_template);
+
+ ActivateLevelTemplate();
+}
+
+void LoadLevelTemplate(int nr)
+{
+ if (!fileExists(getGlobalLevelTemplateFilename()))
+ {
+ Error(ERR_WARN, "no level template found for this level");
+
+ return;
+ }
+
+ setLevelFileInfo(&level_template.file_info, nr);
+
+ LoadLevelTemplate_LoadAndInit();
+}
+
+static void LoadNetworkLevelTemplate(struct NetworkLevelInfo *network_level)
+{
+ copyLevelFileInfo(&network_level->tmpl_info, &level_template.file_info);
+
+ LoadLevelTemplate_LoadAndInit();
+}
+
+static void LoadLevel_LoadAndInit(struct NetworkLevelInfo *network_level)
+{
+ LoadLevelFromFileInfo(&level, &level.file_info, FALSE);
+
+ if (level.use_custom_template)
+ {
+ if (network_level != NULL)
+ LoadNetworkLevelTemplate(network_level);
+ else
+ LoadLevelTemplate(-1);
+ }
+
+ LoadLevel_InitVersion(&level);
+ LoadLevel_InitElements(&level);
+ LoadLevel_InitPlayfield(&level);
+
+ LoadLevel_InitNativeEngines(&level);
+}
+
+void LoadLevel(int nr)
+{
+ SetLevelSetInfo(leveldir_current->identifier, nr);
+
+ setLevelFileInfo(&level.file_info, nr);
+
+ LoadLevel_LoadAndInit(NULL);
+}
+
+void LoadLevelInfoOnly(int nr)
+{
+ setLevelFileInfo(&level.file_info, nr);
+
+ LoadLevelFromFileInfo(&level, &level.file_info, TRUE);
+}
+
+void LoadNetworkLevel(struct NetworkLevelInfo *network_level)
+{
+ SetLevelSetInfo(network_level->leveldir_identifier,
+ network_level->file_info.nr);
+
+ copyLevelFileInfo(&network_level->file_info, &level.file_info);
+
+ LoadLevel_LoadAndInit(network_level);
+}
+
+static int SaveLevel_VERS(FILE *file, struct LevelInfo *level)
+{
+ int chunk_size = 0;
+
+ chunk_size += putFileVersion(file, level->file_version);
+ chunk_size += putFileVersion(file, level->game_version);
+
+ return chunk_size;
+}
+
+static int SaveLevel_DATE(FILE *file, struct LevelInfo *level)
+{
+ int chunk_size = 0;
+
+ chunk_size += putFile16BitBE(file, level->creation_date.year);
+ chunk_size += putFile8Bit(file, level->creation_date.month);
+ chunk_size += putFile8Bit(file, level->creation_date.day);
+
+ return chunk_size;
+}
+
+#if ENABLE_HISTORIC_CHUNKS
+static void SaveLevel_HEAD(FILE *file, struct LevelInfo *level)
+{
+ int i, x, y;
+
+ putFile8Bit(file, level->fieldx);
+ putFile8Bit(file, level->fieldy);
+
+ putFile16BitBE(file, level->time);
+ putFile16BitBE(file, level->gems_needed);
+
+ for (i = 0; i < MAX_LEVEL_NAME_LEN; i++)
+ putFile8Bit(file, level->name[i]);
+
+ for (i = 0; i < LEVEL_SCORE_ELEMENTS; i++)
+ putFile8Bit(file, level->score[i]);
+
+ for (i = 0; i < STD_ELEMENT_CONTENTS; i++)
+ for (y = 0; y < 3; y++)
+ for (x = 0; x < 3; x++)
+ putFile8Bit(file, (level->encoding_16bit_yamyam ? EL_EMPTY :
+ level->yamyam_content[i].e[x][y]));
+ putFile8Bit(file, level->amoeba_speed);
+ putFile8Bit(file, level->time_magic_wall);
+ putFile8Bit(file, level->time_wheel);
+ putFile8Bit(file, (level->encoding_16bit_amoeba ? EL_EMPTY :
+ level->amoeba_content));
+ putFile8Bit(file, (level->initial_player_stepsize == STEPSIZE_FAST ? 1 : 0));
+ putFile8Bit(file, (level->initial_gravity ? 1 : 0));
+ putFile8Bit(file, (level->encoding_16bit_field ? 1 : 0));
+ putFile8Bit(file, (level->em_slippery_gems ? 1 : 0));
+
+ putFile8Bit(file, (level->use_custom_template ? 1 : 0));
+
+ putFile8Bit(file, (level->block_last_field ? 1 : 0));
+ putFile8Bit(file, (level->sp_block_last_field ? 1 : 0));
+ putFile32BitBE(file, level->can_move_into_acid_bits);
+ putFile8Bit(file, level->dont_collide_with_bits);
+
+ putFile8Bit(file, (level->use_spring_bug ? 1 : 0));
+ putFile8Bit(file, (level->use_step_counter ? 1 : 0));
+
+ putFile8Bit(file, (level->instant_relocation ? 1 : 0));
+ putFile8Bit(file, (level->can_pass_to_walkable ? 1 : 0));
+ putFile8Bit(file, (level->grow_into_diggable ? 1 : 0));
+
+ putFile8Bit(file, level->game_engine_type);
+
+ WriteUnusedBytesToFile(file, LEVEL_CHUNK_HEAD_UNUSED);
+}
+#endif
+
+static int SaveLevel_NAME(FILE *file, struct LevelInfo *level)
+{
+ int chunk_size = 0;
+ int i;
+
+ for (i = 0; i < MAX_LEVEL_NAME_LEN; i++)
+ chunk_size += putFile8Bit(file, level->name[i]);
+
+ return chunk_size;
+}
+
+static int SaveLevel_AUTH(FILE *file, struct LevelInfo *level)
+{
+ int chunk_size = 0;
+ int i;
+
+ for (i = 0; i < MAX_LEVEL_AUTHOR_LEN; i++)
+ chunk_size += putFile8Bit(file, level->author[i]);
+
+ return chunk_size;
+}
+
+#if ENABLE_HISTORIC_CHUNKS
+static int SaveLevel_BODY(FILE *file, struct LevelInfo *level)
+{
+ int chunk_size = 0;
+ int x, y;
+
+ for (y = 0; y < level->fieldy; y++)
+ for (x = 0; x < level->fieldx; x++)
+ if (level->encoding_16bit_field)
+ chunk_size += putFile16BitBE(file, level->field[x][y]);
+ else
+ chunk_size += putFile8Bit(file, level->field[x][y]);
+
+ return chunk_size;
+}
+#endif
+
+static int SaveLevel_BODY(FILE *file, struct LevelInfo *level)
+{
+ int chunk_size = 0;
+ int x, y;
+
+ for (y = 0; y < level->fieldy; y++)
+ for (x = 0; x < level->fieldx; x++)
+ chunk_size += putFile16BitBE(file, level->field[x][y]);
+
+ return chunk_size;
+}
+
+#if ENABLE_HISTORIC_CHUNKS
+static void SaveLevel_CONT(FILE *file, struct LevelInfo *level)
+{
+ int i, x, y;
+
+ putFile8Bit(file, EL_YAMYAM);
+ putFile8Bit(file, level->num_yamyam_contents);
+ putFile8Bit(file, 0);
+ putFile8Bit(file, 0);
+
+ for (i = 0; i < MAX_ELEMENT_CONTENTS; i++)
+ for (y = 0; y < 3; y++)
+ for (x = 0; x < 3; x++)
+ if (level->encoding_16bit_field)
+ putFile16BitBE(file, level->yamyam_content[i].e[x][y]);
+ else
+ putFile8Bit(file, level->yamyam_content[i].e[x][y]);
+}
+#endif
+
+#if ENABLE_HISTORIC_CHUNKS
+static void SaveLevel_CNT2(FILE *file, struct LevelInfo *level, int element)
+{
+ int i, x, y;
+ int num_contents, content_xsize, content_ysize;
+ int content_array[MAX_ELEMENT_CONTENTS][3][3];
+
+ if (element == EL_YAMYAM)
+ {
+ num_contents = level->num_yamyam_contents;
+ content_xsize = 3;
+ content_ysize = 3;
+
+ for (i = 0; i < MAX_ELEMENT_CONTENTS; i++)
+ for (y = 0; y < 3; y++)
+ for (x = 0; x < 3; x++)
+ content_array[i][x][y] = level->yamyam_content[i].e[x][y];
+ }
+ else if (element == EL_BD_AMOEBA)
+ {
+ num_contents = 1;
+ content_xsize = 1;
+ content_ysize = 1;
+
+ for (i = 0; i < MAX_ELEMENT_CONTENTS; i++)
+ for (y = 0; y < 3; y++)
+ for (x = 0; x < 3; x++)
+ content_array[i][x][y] = EL_EMPTY;
+ content_array[0][0][0] = level->amoeba_content;
+ }
+ else
+ {
+ // chunk header already written -- write empty chunk data
+ WriteUnusedBytesToFile(file, LEVEL_CHUNK_CNT2_SIZE);
+
+ Error(ERR_WARN, "cannot save content for element '%d'", element);
+ return;
+ }
+
+ putFile16BitBE(file, element);
+ putFile8Bit(file, num_contents);
+ putFile8Bit(file, content_xsize);
+ putFile8Bit(file, content_ysize);
+
+ WriteUnusedBytesToFile(file, LEVEL_CHUNK_CNT2_UNUSED);
+
+ for (i = 0; i < MAX_ELEMENT_CONTENTS; i++)
+ for (y = 0; y < 3; y++)
+ for (x = 0; x < 3; x++)
+ putFile16BitBE(file, content_array[i][x][y]);
+}
+#endif
+
+#if ENABLE_HISTORIC_CHUNKS
+static int SaveLevel_CNT3(FILE *file, struct LevelInfo *level, int element)
+{
+ int envelope_nr = element - EL_ENVELOPE_1;
+ int envelope_len = strlen(level->envelope_text[envelope_nr]) + 1;
+ int chunk_size = 0;
+ int i;
+
+ chunk_size += putFile16BitBE(file, element);
+ chunk_size += putFile16BitBE(file, envelope_len);
+ chunk_size += putFile8Bit(file, level->envelope_xsize[envelope_nr]);
+ chunk_size += putFile8Bit(file, level->envelope_ysize[envelope_nr]);
+
+ WriteUnusedBytesToFile(file, LEVEL_CHUNK_CNT3_UNUSED);
+ chunk_size += LEVEL_CHUNK_CNT3_UNUSED;
+
+ for (i = 0; i < envelope_len; i++)
+ chunk_size += putFile8Bit(file, level->envelope_text[envelope_nr][i]);
+
+ return chunk_size;
+}
+#endif
+
+#if ENABLE_HISTORIC_CHUNKS
+static void SaveLevel_CUS1(FILE *file, struct LevelInfo *level,
+ int num_changed_custom_elements)
+{
+ int i, check = 0;
+
+ putFile16BitBE(file, num_changed_custom_elements);
+
+ for (i = 0; i < NUM_CUSTOM_ELEMENTS; i++)
+ {
+ int element = EL_CUSTOM_START + i;
+
+ struct ElementInfo *ei = &element_info[element];
+
+ if (ei->properties[EP_BITFIELD_BASE_NR] != EP_BITMASK_DEFAULT)
+ {
+ if (check < num_changed_custom_elements)
+ {
+ putFile16BitBE(file, element);
+ putFile32BitBE(file, ei->properties[EP_BITFIELD_BASE_NR]);
+ }
+
+ check++;
+ }
+ }
+
+ if (check != num_changed_custom_elements) // should not happen
+ Error(ERR_WARN, "inconsistent number of custom element properties");
+}
+#endif
+
+#if ENABLE_HISTORIC_CHUNKS
+static void SaveLevel_CUS2(FILE *file, struct LevelInfo *level,
+ int num_changed_custom_elements)
+{
+ int i, check = 0;
+
+ putFile16BitBE(file, num_changed_custom_elements);
+
+ for (i = 0; i < NUM_CUSTOM_ELEMENTS; i++)
+ {
+ int element = EL_CUSTOM_START + i;
+
+ if (element_info[element].change->target_element != EL_EMPTY_SPACE)
+ {
+ if (check < num_changed_custom_elements)
+ {
+ putFile16BitBE(file, element);
+ putFile16BitBE(file, element_info[element].change->target_element);
+ }
+
+ check++;
+ }
+ }
+
+ if (check != num_changed_custom_elements) // should not happen
+ Error(ERR_WARN, "inconsistent number of custom target elements");
+}
+#endif
+
+#if ENABLE_HISTORIC_CHUNKS
+static void SaveLevel_CUS3(FILE *file, struct LevelInfo *level,
+ int num_changed_custom_elements)
+{
+ int i, j, x, y, check = 0;
+
+ putFile16BitBE(file, num_changed_custom_elements);
+
+ for (i = 0; i < NUM_CUSTOM_ELEMENTS; i++)
+ {
+ int element = EL_CUSTOM_START + i;
+ struct ElementInfo *ei = &element_info[element];
+
+ if (ei->modified_settings)
+ {
+ if (check < num_changed_custom_elements)
+ {
+ putFile16BitBE(file, element);
+
+ for (j = 0; j < MAX_ELEMENT_NAME_LEN; j++)
+ putFile8Bit(file, ei->description[j]);
+
+ putFile32BitBE(file, ei->properties[EP_BITFIELD_BASE_NR]);
+
+ // some free bytes for future properties and padding
+ WriteUnusedBytesToFile(file, 7);
+
+ putFile8Bit(file, ei->use_gfx_element);
+ putFile16BitBE(file, ei->gfx_element_initial);
+
+ putFile8Bit(file, ei->collect_score_initial);
+ putFile8Bit(file, ei->collect_count_initial);
+
+ putFile16BitBE(file, ei->push_delay_fixed);
+ putFile16BitBE(file, ei->push_delay_random);
+ putFile16BitBE(file, ei->move_delay_fixed);
+ putFile16BitBE(file, ei->move_delay_random);
+
+ putFile16BitBE(file, ei->move_pattern);
+ putFile8Bit(file, ei->move_direction_initial);
+ putFile8Bit(file, ei->move_stepsize);
+
+ for (y = 0; y < 3; y++)
+ for (x = 0; x < 3; x++)
+ putFile16BitBE(file, ei->content.e[x][y]);
+
+ putFile32BitBE(file, ei->change->events);
+
+ putFile16BitBE(file, ei->change->target_element);
+
+ putFile16BitBE(file, ei->change->delay_fixed);
+ putFile16BitBE(file, ei->change->delay_random);
+ putFile16BitBE(file, ei->change->delay_frames);
+
+ putFile16BitBE(file, ei->change->initial_trigger_element);
+
+ putFile8Bit(file, ei->change->explode);
+ putFile8Bit(file, ei->change->use_target_content);
+ putFile8Bit(file, ei->change->only_if_complete);
+ putFile8Bit(file, ei->change->use_random_replace);
+
+ putFile8Bit(file, ei->change->random_percentage);
+ putFile8Bit(file, ei->change->replace_when);
+
+ for (y = 0; y < 3; y++)
+ for (x = 0; x < 3; x++)
+ putFile16BitBE(file, ei->change->content.e[x][y]);
+
+ putFile8Bit(file, ei->slippery_type);
+
+ // some free bytes for future properties and padding
+ WriteUnusedBytesToFile(file, LEVEL_CPART_CUS3_UNUSED);
+ }
+
+ check++;
+ }
+ }
+
+ if (check != num_changed_custom_elements) // should not happen
+ Error(ERR_WARN, "inconsistent number of custom element properties");
+}
+#endif
+
+#if ENABLE_HISTORIC_CHUNKS
+static void SaveLevel_CUS4(FILE *file, struct LevelInfo *level, int element)
+{
+ struct ElementInfo *ei = &element_info[element];
+ int i, j, x, y;
+
+ // ---------- custom element base property values (96 bytes) ----------------
+
+ putFile16BitBE(file, element);
+
+ for (i = 0; i < MAX_ELEMENT_NAME_LEN; i++)
+ putFile8Bit(file, ei->description[i]);
+
+ putFile32BitBE(file, ei->properties[EP_BITFIELD_BASE_NR]);
+
+ WriteUnusedBytesToFile(file, 4); // reserved for more base properties
+
+ putFile8Bit(file, ei->num_change_pages);
+
+ putFile16BitBE(file, ei->ce_value_fixed_initial);
+ putFile16BitBE(file, ei->ce_value_random_initial);
+ putFile8Bit(file, ei->use_last_ce_value);
+
+ putFile8Bit(file, ei->use_gfx_element);
+ putFile16BitBE(file, ei->gfx_element_initial);
+
+ putFile8Bit(file, ei->collect_score_initial);
+ putFile8Bit(file, ei->collect_count_initial);
+
+ putFile8Bit(file, ei->drop_delay_fixed);
+ putFile8Bit(file, ei->push_delay_fixed);
+ putFile8Bit(file, ei->drop_delay_random);
+ putFile8Bit(file, ei->push_delay_random);
+ putFile16BitBE(file, ei->move_delay_fixed);
+ putFile16BitBE(file, ei->move_delay_random);
+
+ // bits 0 - 15 of "move_pattern" ...
+ putFile16BitBE(file, ei->move_pattern & 0xffff);
+ putFile8Bit(file, ei->move_direction_initial);
+ putFile8Bit(file, ei->move_stepsize);
+
+ putFile8Bit(file, ei->slippery_type);
+
+ for (y = 0; y < 3; y++)
+ for (x = 0; x < 3; x++)
+ putFile16BitBE(file, ei->content.e[x][y]);
+
+ putFile16BitBE(file, ei->move_enter_element);
+ putFile16BitBE(file, ei->move_leave_element);
+ putFile8Bit(file, ei->move_leave_type);
+
+ // ... bits 16 - 31 of "move_pattern" (not nice, but downward compatible)
+ putFile16BitBE(file, (ei->move_pattern >> 16) & 0xffff);
+
+ putFile8Bit(file, ei->access_direction);
+
+ putFile8Bit(file, ei->explosion_delay);
+ putFile8Bit(file, ei->ignition_delay);
+ putFile8Bit(file, ei->explosion_type);
+
+ // some free bytes for future custom property values and padding
+ WriteUnusedBytesToFile(file, 1);
+
+ // ---------- change page property values (48 bytes) ------------------------
+
+ for (i = 0; i < ei->num_change_pages; i++)
+ {
+ struct ElementChangeInfo *change = &ei->change_page[i];
+ unsigned int event_bits;
+
+ // bits 0 - 31 of "has_event[]" ...
+ event_bits = 0;
+ for (j = 0; j < MIN(NUM_CHANGE_EVENTS, 32); j++)
+ if (change->has_event[j])
+ event_bits |= (1 << j);
+ putFile32BitBE(file, event_bits);
+
+ putFile16BitBE(file, change->target_element);
+
+ putFile16BitBE(file, change->delay_fixed);
+ putFile16BitBE(file, change->delay_random);
+ putFile16BitBE(file, change->delay_frames);
+
+ putFile16BitBE(file, change->initial_trigger_element);
+
+ putFile8Bit(file, change->explode);
+ putFile8Bit(file, change->use_target_content);
+ putFile8Bit(file, change->only_if_complete);
+ putFile8Bit(file, change->use_random_replace);
+
+ putFile8Bit(file, change->random_percentage);
+ putFile8Bit(file, change->replace_when);
+
+ for (y = 0; y < 3; y++)
+ for (x = 0; x < 3; x++)
+ putFile16BitBE(file, change->target_content.e[x][y]);
+
+ putFile8Bit(file, change->can_change);
+
+ putFile8Bit(file, change->trigger_side);
+
+ putFile8Bit(file, change->trigger_player);
+ putFile8Bit(file, (change->trigger_page == CH_PAGE_ANY ? CH_PAGE_ANY_FILE :
+ log_2(change->trigger_page)));
+
+ putFile8Bit(file, change->has_action);
+ putFile8Bit(file, change->action_type);
+ putFile8Bit(file, change->action_mode);
+ putFile16BitBE(file, change->action_arg);
+
+ // ... bits 32 - 39 of "has_event[]" (not nice, but downward compatible)
+ event_bits = 0;
+ for (j = 32; j < NUM_CHANGE_EVENTS; j++)
+ if (change->has_event[j])
+ event_bits |= (1 << (j - 32));
+ putFile8Bit(file, event_bits);
+ }
+}
+#endif
+
+#if ENABLE_HISTORIC_CHUNKS
+static void SaveLevel_GRP1(FILE *file, struct LevelInfo *level, int element)
+{
+ struct ElementInfo *ei = &element_info[element];
+ struct ElementGroupInfo *group = ei->group;
+ int i;
+
+ putFile16BitBE(file, element);
+
+ for (i = 0; i < MAX_ELEMENT_NAME_LEN; i++)
+ putFile8Bit(file, ei->description[i]);
+
+ putFile8Bit(file, group->num_elements);
+
+ putFile8Bit(file, ei->use_gfx_element);
+ putFile16BitBE(file, ei->gfx_element_initial);
+
+ putFile8Bit(file, group->choice_mode);
+
+ // some free bytes for future values and padding
+ WriteUnusedBytesToFile(file, 3);
+
+ for (i = 0; i < MAX_ELEMENTS_IN_GROUP; i++)
+ putFile16BitBE(file, group->element[i]);
+}
+#endif
+
+static int SaveLevel_MicroChunk(FILE *file, struct LevelFileConfigInfo *entry,
+ boolean write_element)
+{
+ int save_type = entry->save_type;
+ int data_type = entry->data_type;
+ int conf_type = entry->conf_type;
+ int byte_mask = conf_type & CONF_MASK_BYTES;
+ int element = entry->element;
+ int default_value = entry->default_value;
+ int num_bytes = 0;
+ boolean modified = FALSE;
+
+ if (byte_mask != CONF_MASK_MULTI_BYTES)
+ {
+ void *value_ptr = entry->value;
+ int value = (data_type == TYPE_BOOLEAN ? *(boolean *)value_ptr :
+ *(int *)value_ptr);
+
+ // check if any settings have been modified before saving them
+ if (value != default_value)
+ modified = TRUE;
+
+ // do not save if explicitly told or if unmodified default settings
+ if ((save_type == SAVE_CONF_NEVER) ||
+ (save_type == SAVE_CONF_WHEN_CHANGED && !modified))
+ return 0;
+
+ if (write_element)
+ num_bytes += putFile16BitBE(file, element);
+
+ num_bytes += putFile8Bit(file, conf_type);
+ num_bytes += (byte_mask == CONF_MASK_1_BYTE ? putFile8Bit (file, value) :
+ byte_mask == CONF_MASK_2_BYTE ? putFile16BitBE(file, value) :
+ byte_mask == CONF_MASK_4_BYTE ? putFile32BitBE(file, value) :
+ 0);
+ }
+ else if (data_type == TYPE_STRING)
+ {
+ char *default_string = entry->default_string;
+ char *string = (char *)(entry->value);
+ int string_length = strlen(string);
+ int i;
+
+ // check if any settings have been modified before saving them
+ if (!strEqual(string, default_string))
+ modified = TRUE;
+
+ // do not save if explicitly told or if unmodified default settings
+ if ((save_type == SAVE_CONF_NEVER) ||
+ (save_type == SAVE_CONF_WHEN_CHANGED && !modified))
+ return 0;
+
+ if (write_element)
+ num_bytes += putFile16BitBE(file, element);
+
+ num_bytes += putFile8Bit(file, conf_type);
+ num_bytes += putFile16BitBE(file, string_length);
+
+ for (i = 0; i < string_length; i++)
+ num_bytes += putFile8Bit(file, string[i]);
+ }
+ else if (data_type == TYPE_ELEMENT_LIST)
+ {
+ int *element_array = (int *)(entry->value);
+ int num_elements = *(int *)(entry->num_entities);
+ int i;
+
+ // check if any settings have been modified before saving them
+ for (i = 0; i < num_elements; i++)
+ if (element_array[i] != default_value)
+ modified = TRUE;
+
+ // do not save if explicitly told or if unmodified default settings
+ if ((save_type == SAVE_CONF_NEVER) ||
+ (save_type == SAVE_CONF_WHEN_CHANGED && !modified))
+ return 0;
+
+ if (write_element)
+ num_bytes += putFile16BitBE(file, element);
+
+ num_bytes += putFile8Bit(file, conf_type);
+ num_bytes += putFile16BitBE(file, num_elements * CONF_ELEMENT_NUM_BYTES);
+
+ for (i = 0; i < num_elements; i++)
+ num_bytes += putFile16BitBE(file, element_array[i]);
+ }
+ else if (data_type == TYPE_CONTENT_LIST)
+ {
+ struct Content *content = (struct Content *)(entry->value);
+ int num_contents = *(int *)(entry->num_entities);
+ int i, x, y;
+
+ // check if any settings have been modified before saving them
+ for (i = 0; i < num_contents; i++)
+ for (y = 0; y < 3; y++)
+ for (x = 0; x < 3; x++)
+ if (content[i].e[x][y] != default_value)
+ modified = TRUE;
+
+ // do not save if explicitly told or if unmodified default settings
+ if ((save_type == SAVE_CONF_NEVER) ||
+ (save_type == SAVE_CONF_WHEN_CHANGED && !modified))
+ return 0;
+
+ if (write_element)
+ num_bytes += putFile16BitBE(file, element);
+
+ num_bytes += putFile8Bit(file, conf_type);
+ num_bytes += putFile16BitBE(file, num_contents * CONF_CONTENT_NUM_BYTES);
+
+ for (i = 0; i < num_contents; i++)
+ for (y = 0; y < 3; y++)
+ for (x = 0; x < 3; x++)
+ num_bytes += putFile16BitBE(file, content[i].e[x][y]);
+ }
+
+ return num_bytes;
+}
+
+static int SaveLevel_INFO(FILE *file, struct LevelInfo *level)
+{
+ int chunk_size = 0;
+ int i;
+
+ li = *level; // copy level data into temporary buffer
+
+ for (i = 0; chunk_config_INFO[i].data_type != -1; i++)
+ chunk_size += SaveLevel_MicroChunk(file, &chunk_config_INFO[i], FALSE);
+
+ return chunk_size;
+}
+
+static int SaveLevel_ELEM(FILE *file, struct LevelInfo *level)
+{
+ int chunk_size = 0;
+ int i;
+
+ li = *level; // copy level data into temporary buffer
+
+ for (i = 0; chunk_config_ELEM[i].data_type != -1; i++)
+ chunk_size += SaveLevel_MicroChunk(file, &chunk_config_ELEM[i], TRUE);
+
+ return chunk_size;
+}
+
+static int SaveLevel_NOTE(FILE *file, struct LevelInfo *level, int element)
+{
+ int envelope_nr = element - EL_ENVELOPE_1;
+ int chunk_size = 0;
+ int i;
+
+ chunk_size += putFile16BitBE(file, element);
+
+ // copy envelope data into temporary buffer
+ xx_envelope = level->envelope[envelope_nr];
+
+ for (i = 0; chunk_config_NOTE[i].data_type != -1; i++)
+ chunk_size += SaveLevel_MicroChunk(file, &chunk_config_NOTE[i], FALSE);
+
+ return chunk_size;
+}
+
+static int SaveLevel_CUSX(FILE *file, struct LevelInfo *level, int element)
+{
+ struct ElementInfo *ei = &element_info[element];
+ int chunk_size = 0;
+ int i, j;
+
+ chunk_size += putFile16BitBE(file, element);
+
+ xx_ei = *ei; // copy element data into temporary buffer
+
+ // set default description string for this specific element
+ strcpy(xx_default_description, getDefaultElementDescription(ei));
+
+ for (i = 0; chunk_config_CUSX_base[i].data_type != -1; i++)
+ chunk_size += SaveLevel_MicroChunk(file, &chunk_config_CUSX_base[i], FALSE);
+
+ for (i = 0; i < ei->num_change_pages; i++)
+ {
+ struct ElementChangeInfo *change = &ei->change_page[i];
+
+ xx_current_change_page = i;
+
+ xx_change = *change; // copy change data into temporary buffer
+
+ resetEventBits();
+ setEventBitsFromEventFlags(change);
+
+ for (j = 0; chunk_config_CUSX_change[j].data_type != -1; j++)
+ chunk_size += SaveLevel_MicroChunk(file, &chunk_config_CUSX_change[j],
+ FALSE);
+ }
+
+ return chunk_size;
+}
+
+static int SaveLevel_GRPX(FILE *file, struct LevelInfo *level, int element)
+{
+ struct ElementInfo *ei = &element_info[element];
+ struct ElementGroupInfo *group = ei->group;
+ int chunk_size = 0;
+ int i;
+
+ chunk_size += putFile16BitBE(file, element);
+
+ xx_ei = *ei; // copy element data into temporary buffer
+ xx_group = *group; // copy group data into temporary buffer
+
+ // set default description string for this specific element
+ strcpy(xx_default_description, getDefaultElementDescription(ei));
+
+ for (i = 0; chunk_config_GRPX[i].data_type != -1; i++)
+ chunk_size += SaveLevel_MicroChunk(file, &chunk_config_GRPX[i], FALSE);
+
+ return chunk_size;
+}
+
+static void SaveLevelFromFilename(struct LevelInfo *level, char *filename,
+ boolean save_as_template)
+{
+ int chunk_size;
+ int i;
+ FILE *file;
+
+ if (!(file = fopen(filename, MODE_WRITE)))
+ {
+ Error(ERR_WARN, "cannot save level file '%s'", filename);
+ return;
+ }
+
+ level->file_version = FILE_VERSION_ACTUAL;
+ level->game_version = GAME_VERSION_ACTUAL;
+
+ level->creation_date = getCurrentDate();
+
+ putFileChunkBE(file, "RND1", CHUNK_SIZE_UNDEFINED);
+ putFileChunkBE(file, "CAVE", CHUNK_SIZE_NONE);
+
+ chunk_size = SaveLevel_VERS(NULL, level);
+ putFileChunkBE(file, "VERS", chunk_size);
+ SaveLevel_VERS(file, level);
+
+ chunk_size = SaveLevel_DATE(NULL, level);
+ putFileChunkBE(file, "DATE", chunk_size);
+ SaveLevel_DATE(file, level);
+
+ chunk_size = SaveLevel_NAME(NULL, level);
+ putFileChunkBE(file, "NAME", chunk_size);
+ SaveLevel_NAME(file, level);
+
+ chunk_size = SaveLevel_AUTH(NULL, level);
+ putFileChunkBE(file, "AUTH", chunk_size);
+ SaveLevel_AUTH(file, level);
+
+ chunk_size = SaveLevel_INFO(NULL, level);
+ putFileChunkBE(file, "INFO", chunk_size);
+ SaveLevel_INFO(file, level);
+
+ chunk_size = SaveLevel_BODY(NULL, level);
+ putFileChunkBE(file, "BODY", chunk_size);
+ SaveLevel_BODY(file, level);
+
+ chunk_size = SaveLevel_ELEM(NULL, level);
+ if (chunk_size > LEVEL_CHUNK_ELEM_UNCHANGED) // save if changed
+ {
+ putFileChunkBE(file, "ELEM", chunk_size);
+ SaveLevel_ELEM(file, level);
+ }
+
+ for (i = 0; i < NUM_ENVELOPES; i++)
+ {
+ int element = EL_ENVELOPE_1 + i;
+
+ chunk_size = SaveLevel_NOTE(NULL, level, element);
+ if (chunk_size > LEVEL_CHUNK_NOTE_UNCHANGED) // save if changed
+ {
+ putFileChunkBE(file, "NOTE", chunk_size);
+ SaveLevel_NOTE(file, level, element);
+ }
+ }
+
+ // if not using template level, check for non-default custom/group elements
+ if (!level->use_custom_template || save_as_template)
+ {
+ for (i = 0; i < NUM_CUSTOM_ELEMENTS; i++)
+ {
+ int element = EL_CUSTOM_START + i;
+
+ chunk_size = SaveLevel_CUSX(NULL, level, element);
+ if (chunk_size > LEVEL_CHUNK_CUSX_UNCHANGED) // save if changed
+ {
+ putFileChunkBE(file, "CUSX", chunk_size);
+ SaveLevel_CUSX(file, level, element);
+ }
+ }
+
+ for (i = 0; i < NUM_GROUP_ELEMENTS; i++)
+ {
+ int element = EL_GROUP_START + i;
+
+ chunk_size = SaveLevel_GRPX(NULL, level, element);
+ if (chunk_size > LEVEL_CHUNK_GRPX_UNCHANGED) // save if changed
+ {
+ putFileChunkBE(file, "GRPX", chunk_size);
+ SaveLevel_GRPX(file, level, element);
+ }
+ }
+ }
+
+ fclose(file);
+
+ SetFilePermissions(filename, PERMS_PRIVATE);
+}
+
+void SaveLevel(int nr)
+{
+ char *filename = getDefaultLevelFilename(nr);
+
+ SaveLevelFromFilename(&level, filename, FALSE);
+}
+
+void SaveLevelTemplate(void)
+{
+ char *filename = getLocalLevelTemplateFilename();
+
+ SaveLevelFromFilename(&level, filename, TRUE);
+}
+
+boolean SaveLevelChecked(int nr)
+{
+ char *filename = getDefaultLevelFilename(nr);
+ boolean new_level = !fileExists(filename);
+ boolean level_saved = FALSE;
+
+ if (new_level || Request("Save this level and kill the old?", REQ_ASK))
+ {
+ SaveLevel(nr);
+
+ if (new_level)
+ Request("Level saved!", REQ_CONFIRM);
+
+ level_saved = TRUE;
+ }
+
+ return level_saved;
+}
+
+void DumpLevel(struct LevelInfo *level)
+{
+ if (level->no_level_file || level->no_valid_file)
+ {
+ Error(ERR_WARN, "cannot dump -- no valid level file found");
+
+ return;
+ }
+
+ PrintLine("-", 79);
+ Print("Level xxx (file version %08d, game version %08d)\n",
+ level->file_version, level->game_version);
+ PrintLine("-", 79);
+
+ Print("Level author: '%s'\n", level->author);
+ Print("Level title: '%s'\n", level->name);
+ Print("\n");
+ Print("Playfield size: %d x %d\n", level->fieldx, level->fieldy);
+ Print("\n");
+ Print("Level time: %d seconds\n", level->time);
+ Print("Gems needed: %d\n", level->gems_needed);
+ Print("\n");
+ Print("Time for magic wall: %d seconds\n", level->time_magic_wall);
+ Print("Time for wheel: %d seconds\n", level->time_wheel);
+ Print("Time for light: %d seconds\n", level->time_light);
+ Print("Time for timegate: %d seconds\n", level->time_timegate);
+ Print("\n");
+ Print("Amoeba speed: %d\n", level->amoeba_speed);
+ Print("\n");
+
+ Print("EM style slippery gems: %s\n", (level->em_slippery_gems ? "yes" : "no"));
+ Print("Player blocks last field: %s\n", (level->block_last_field ? "yes" : "no"));
+ Print("SP player blocks last field: %s\n", (level->sp_block_last_field ? "yes" : "no"));
+ Print("use spring bug: %s\n", (level->use_spring_bug ? "yes" : "no"));
+ Print("use step counter: %s\n", (level->use_step_counter ? "yes" : "no"));
+
+ PrintLine("-", 79);
+}
+
+
+// ============================================================================
+// tape file functions
+// ============================================================================
+
+static void setTapeInfoToDefaults(void)
+{
+ int i;
+
+ // always start with reliable default values (empty tape)
+ TapeErase();
+
+ // default values (also for pre-1.2 tapes) with only the first player
+ tape.player_participates[0] = TRUE;
+ for (i = 1; i < MAX_PLAYERS; i++)
+ tape.player_participates[i] = FALSE;
+
+ // at least one (default: the first) player participates in every tape
+ tape.num_participating_players = 1;
+
+ tape.level_nr = level_nr;
+ tape.counter = 0;
+ tape.changed = FALSE;
+
+ tape.recording = FALSE;
+ tape.playing = FALSE;
+ tape.pausing = FALSE;
+
+ tape.no_valid_file = FALSE;
+}
+
+static int LoadTape_VERS(File *file, int chunk_size, struct TapeInfo *tape)
+{
+ tape->file_version = getFileVersion(file);
+ tape->game_version = getFileVersion(file);
+
+ return chunk_size;
+}
+
+static int LoadTape_HEAD(File *file, int chunk_size, struct TapeInfo *tape)
+{
+ int i;
+
+ tape->random_seed = getFile32BitBE(file);
+ tape->date = getFile32BitBE(file);
+ tape->length = getFile32BitBE(file);
+
+ // read header fields that are new since version 1.2
+ if (tape->file_version >= FILE_VERSION_1_2)
+ {
+ byte store_participating_players = getFile8Bit(file);
+ int engine_version;
+
+ // since version 1.2, tapes store which players participate in the tape
+ tape->num_participating_players = 0;
+ for (i = 0; i < MAX_PLAYERS; i++)
+ {
+ tape->player_participates[i] = FALSE;
+
+ if (store_participating_players & (1 << i))
+ {
+ tape->player_participates[i] = TRUE;
+ tape->num_participating_players++;
+ }
+ }
+
+ tape->use_mouse = (getFile8Bit(file) == 1 ? TRUE : FALSE);
+
+ ReadUnusedBytesFromFile(file, TAPE_CHUNK_HEAD_UNUSED);
+
+ engine_version = getFileVersion(file);
+ if (engine_version > 0)
+ tape->engine_version = engine_version;
+ else
+ tape->engine_version = tape->game_version;
+ }
+
+ return chunk_size;
+}
+
+static int LoadTape_INFO(File *file, int chunk_size, struct TapeInfo *tape)
+{
+ int level_identifier_size;
+ int i;
+
+ level_identifier_size = getFile16BitBE(file);
+
+ tape->level_identifier =
+ checked_realloc(tape->level_identifier, level_identifier_size);
+
+ for (i = 0; i < level_identifier_size; i++)
+ tape->level_identifier[i] = getFile8Bit(file);
+
+ tape->level_nr = getFile16BitBE(file);
+
+ chunk_size = 2 + level_identifier_size + 2;
+
+ return chunk_size;
+}
+
+static int LoadTape_BODY(File *file, int chunk_size, struct TapeInfo *tape)
+{
+ int i, j;
+ int tape_pos_size =
+ (tape->use_mouse ? 3 : tape->num_participating_players) + 1;
+ int chunk_size_expected = tape_pos_size * tape->length;
+
+ if (chunk_size_expected != chunk_size)
+ {
+ ReadUnusedBytesFromFile(file, chunk_size);
+ return chunk_size_expected;
+ }
+
+ for (i = 0; i < tape->length; i++)
+ {
+ if (i >= MAX_TAPE_LEN)
+ {
+ Error(ERR_WARN, "tape truncated -- size exceeds maximum tape size %d",
+ MAX_TAPE_LEN);
+
+ // tape too large; read and ignore remaining tape data from this chunk
+ for (;i < tape->length; i++)
+ ReadUnusedBytesFromFile(file, tape->num_participating_players + 1);
+
+ break;
+ }
+
+ if (tape->use_mouse)
+ {
+ tape->pos[i].action[TAPE_ACTION_LX] = getFile8Bit(file);
+ tape->pos[i].action[TAPE_ACTION_LY] = getFile8Bit(file);
+ tape->pos[i].action[TAPE_ACTION_BUTTON] = getFile8Bit(file);
+
+ tape->pos[i].action[TAPE_ACTION_UNUSED] = 0;
+ }
+ else
+ {
+ for (j = 0; j < MAX_PLAYERS; j++)
+ {
+ tape->pos[i].action[j] = MV_NONE;
+
+ if (tape->player_participates[j])
+ tape->pos[i].action[j] = getFile8Bit(file);
+ }
+ }
+
+ tape->pos[i].delay = getFile8Bit(file);
+
+ if (tape->file_version == FILE_VERSION_1_0)
+ {
+ // eliminate possible diagonal moves in old tapes
+ // this is only for backward compatibility
+
+ byte joy_dir[4] = { JOY_LEFT, JOY_RIGHT, JOY_UP, JOY_DOWN };
+ byte action = tape->pos[i].action[0];
+ int k, num_moves = 0;
+
+ for (k = 0; k<4; k++)
+ {
+ if (action & joy_dir[k])
+ {
+ tape->pos[i + num_moves].action[0] = joy_dir[k];
+ if (num_moves > 0)
+ tape->pos[i + num_moves].delay = 0;
+ num_moves++;
+ }
+ }
+
+ if (num_moves > 1)
+ {
+ num_moves--;
+ i += num_moves;
+ tape->length += num_moves;
+ }
+ }
+ else if (tape->file_version < FILE_VERSION_2_0)
+ {
+ // convert pre-2.0 tapes to new tape format
+
+ if (tape->pos[i].delay > 1)
+ {
+ // action part
+ tape->pos[i + 1] = tape->pos[i];
+ tape->pos[i + 1].delay = 1;
+
+ // delay part
+ for (j = 0; j < MAX_PLAYERS; j++)
+ tape->pos[i].action[j] = MV_NONE;
+ tape->pos[i].delay--;
+
+ i++;
+ tape->length++;
+ }
+ }
+
+ if (checkEndOfFile(file))
+ break;
+ }
+
+ if (i != tape->length)
+ chunk_size = tape_pos_size * i;
+
+ return chunk_size;
+}
+
+static void LoadTape_SokobanSolution(char *filename)
+{
+ File *file;
+ int move_delay = TILESIZE / level.initial_player_stepsize[0];
+
+ if (!(file = openFile(filename, MODE_READ)))
+ {
+ tape.no_valid_file = TRUE;
+
+ return;
+ }
+
+ while (!checkEndOfFile(file))
+ {
+ unsigned char c = getByteFromFile(file);
+
+ if (checkEndOfFile(file))
+ break;
+
+ switch (c)
+ {
+ case 'u':
+ case 'U':
+ tape.pos[tape.length].action[0] = MV_UP;
+ tape.pos[tape.length].delay = move_delay + (c < 'a' ? 2 : 0);
+ tape.length++;
+ break;
+
+ case 'd':
+ case 'D':
+ tape.pos[tape.length].action[0] = MV_DOWN;
+ tape.pos[tape.length].delay = move_delay + (c < 'a' ? 2 : 0);
+ tape.length++;
+ break;
+
+ case 'l':
+ case 'L':
+ tape.pos[tape.length].action[0] = MV_LEFT;
+ tape.pos[tape.length].delay = move_delay + (c < 'a' ? 2 : 0);
+ tape.length++;
+ break;
+
+ case 'r':
+ case 'R':
+ tape.pos[tape.length].action[0] = MV_RIGHT;
+ tape.pos[tape.length].delay = move_delay + (c < 'a' ? 2 : 0);
+ tape.length++;
+ break;
+
+ case '\n':
+ case '\r':
+ case '\t':
+ case ' ':
+ // ignore white-space characters
+ break;
+
+ default:
+ tape.no_valid_file = TRUE;
+
+ Error(ERR_WARN, "unsupported Sokoban solution file '%s' ['%d']", filename, c);
+
+ break;
+ }
+ }
+
+ closeFile(file);
+
+ if (tape.no_valid_file)
+ return;
+
+ tape.length_frames = GetTapeLengthFrames();
+ tape.length_seconds = GetTapeLengthSeconds();
+}
+
+void LoadTapeFromFilename(char *filename)
+{
+ char cookie[MAX_LINE_LEN];
+ char chunk_name[CHUNK_ID_LEN + 1];
+ File *file;
+ int chunk_size;
+
+ // always start with reliable default values
+ setTapeInfoToDefaults();
+
+ if (strSuffix(filename, ".sln"))
+ {
+ LoadTape_SokobanSolution(filename);
+
+ return;
+ }
+
+ if (!(file = openFile(filename, MODE_READ)))
+ {
+ tape.no_valid_file = TRUE;
+
+ return;
+ }
+
+ getFileChunkBE(file, chunk_name, NULL);
+ if (strEqual(chunk_name, "RND1"))
+ {
+ getFile32BitBE(file); // not used
+
+ getFileChunkBE(file, chunk_name, NULL);
+ if (!strEqual(chunk_name, "TAPE"))
+ {
+ tape.no_valid_file = TRUE;
+
+ Error(ERR_WARN, "unknown format of tape file '%s'", filename);
+
+ closeFile(file);
+
+ return;
+ }
+ }
+ else // check for pre-2.0 file format with cookie string
+ {
+ strcpy(cookie, chunk_name);
+ if (getStringFromFile(file, &cookie[4], MAX_LINE_LEN - 4) == NULL)
+ cookie[4] = '\0';
+ if (strlen(cookie) > 0 && cookie[strlen(cookie) - 1] == '\n')
+ cookie[strlen(cookie) - 1] = '\0';
+
+ if (!checkCookieString(cookie, TAPE_COOKIE_TMPL))
+ {
+ tape.no_valid_file = TRUE;
+
+ Error(ERR_WARN, "unknown format of tape file '%s'", filename);
+
+ closeFile(file);
+
+ return;
+ }
+
+ if ((tape.file_version = getFileVersionFromCookieString(cookie)) == -1)
+ {
+ tape.no_valid_file = TRUE;
+
+ Error(ERR_WARN, "unsupported version of tape file '%s'", filename);
+
+ closeFile(file);
+
+ return;
+ }
+
+ // pre-2.0 tape files have no game version, so use file version here
+ tape.game_version = tape.file_version;
+ }
+
+ if (tape.file_version < FILE_VERSION_1_2)
+ {
+ // tape files from versions before 1.2.0 without chunk structure
+ LoadTape_HEAD(file, TAPE_CHUNK_HEAD_SIZE, &tape);
+ LoadTape_BODY(file, 2 * tape.length, &tape);
+ }
+ else
+ {
+ static struct
+ {
+ char *name;
+ int size;
+ int (*loader)(File *, int, struct TapeInfo *);
+ }
+ chunk_info[] =
+ {
+ { "VERS", TAPE_CHUNK_VERS_SIZE, LoadTape_VERS },
+ { "HEAD", TAPE_CHUNK_HEAD_SIZE, LoadTape_HEAD },
+ { "INFO", -1, LoadTape_INFO },
+ { "BODY", -1, LoadTape_BODY },
+ { NULL, 0, NULL }
+ };
+
+ while (getFileChunkBE(file, chunk_name, &chunk_size))
+ {
+ int i = 0;
+
+ while (chunk_info[i].name != NULL &&
+ !strEqual(chunk_name, chunk_info[i].name))
+ i++;
+
+ if (chunk_info[i].name == NULL)
+ {
+ Error(ERR_WARN, "unknown chunk '%s' in tape file '%s'",
+ chunk_name, filename);
+ ReadUnusedBytesFromFile(file, chunk_size);
+ }
+ else if (chunk_info[i].size != -1 &&
+ chunk_info[i].size != chunk_size)
+ {
+ Error(ERR_WARN, "wrong size (%d) of chunk '%s' in tape file '%s'",
+ chunk_size, chunk_name, filename);
+ ReadUnusedBytesFromFile(file, chunk_size);
+ }
+ else
+ {
+ // call function to load this tape chunk
+ int chunk_size_expected =
+ (chunk_info[i].loader)(file, chunk_size, &tape);
+
+ // the size of some chunks cannot be checked before reading other
+ // chunks first (like "HEAD" and "BODY") that contain some header
+ // information, so check them here
+ if (chunk_size_expected != chunk_size)
+ {
+ Error(ERR_WARN, "wrong size (%d) of chunk '%s' in tape file '%s'",
+ chunk_size, chunk_name, filename);
+ }
+ }
+ }
+ }
+
+ closeFile(file);
+
+ tape.length_frames = GetTapeLengthFrames();
+ tape.length_seconds = GetTapeLengthSeconds();
+
+#if 0
+ printf("::: tape file version: %d\n", tape.file_version);
+ printf("::: tape game version: %d\n", tape.game_version);
+ printf("::: tape engine version: %d\n", tape.engine_version);
+#endif
+}
+
+void LoadTape(int nr)
+{
+ char *filename = getTapeFilename(nr);
+
+ LoadTapeFromFilename(filename);
+}
+
+void LoadSolutionTape(int nr)
+{
+ char *filename = getSolutionTapeFilename(nr);
+
+ LoadTapeFromFilename(filename);
+
+ 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);
+}
+
+static void SaveTape_VERS(FILE *file, struct TapeInfo *tape)
+{
+ putFileVersion(file, tape->file_version);
+ putFileVersion(file, tape->game_version);
+}
+
+static void SaveTape_HEAD(FILE *file, struct TapeInfo *tape)
+{
+ int i;
+ byte store_participating_players = 0;
+
+ // set bits for participating players for compact storage
+ for (i = 0; i < MAX_PLAYERS; i++)
+ if (tape->player_participates[i])
+ store_participating_players |= (1 << i);
+
+ putFile32BitBE(file, tape->random_seed);
+ putFile32BitBE(file, tape->date);
+ putFile32BitBE(file, tape->length);
+
+ putFile8Bit(file, store_participating_players);
+
+ putFile8Bit(file, (tape->use_mouse ? 1 : 0));
+
+ // unused bytes not at the end here for 4-byte alignment of engine_version
+ WriteUnusedBytesToFile(file, TAPE_CHUNK_HEAD_UNUSED);
+
+ putFileVersion(file, tape->engine_version);
+}
+
+static void SaveTape_INFO(FILE *file, struct TapeInfo *tape)
+{
+ int level_identifier_size = strlen(tape->level_identifier) + 1;
+ int i;
+
+ putFile16BitBE(file, level_identifier_size);
+
+ for (i = 0; i < level_identifier_size; i++)
+ putFile8Bit(file, tape->level_identifier[i]);
+
+ putFile16BitBE(file, tape->level_nr);
+}
+
+static void SaveTape_BODY(FILE *file, struct TapeInfo *tape)
+{
+ int i, j;
+
+ for (i = 0; i < tape->length; i++)
+ {
+ if (tape->use_mouse)
+ {
+ putFile8Bit(file, tape->pos[i].action[TAPE_ACTION_LX]);
+ putFile8Bit(file, tape->pos[i].action[TAPE_ACTION_LY]);
+ putFile8Bit(file, tape->pos[i].action[TAPE_ACTION_BUTTON]);
+ }
+ else
+ {
+ for (j = 0; j < MAX_PLAYERS; j++)
+ if (tape->player_participates[j])
+ putFile8Bit(file, tape->pos[i].action[j]);
+ }
+
+ putFile8Bit(file, tape->pos[i].delay);
+ }
+}
+
+void SaveTape(int nr)
+{
+ char *filename = getTapeFilename(nr);
+ FILE *file;
+ int num_participating_players = 0;
+ int tape_pos_size;
+ int info_chunk_size;
+ int body_chunk_size;
+ int i;
+
+ InitTapeDirectory(leveldir_current->subdir);
+
+ if (!(file = fopen(filename, MODE_WRITE)))
+ {
+ Error(ERR_WARN, "cannot save level recording file '%s'", filename);
+ return;
+ }
+
+ tape.file_version = FILE_VERSION_ACTUAL;
+ tape.game_version = GAME_VERSION_ACTUAL;
+
+ // count number of participating players
+ for (i = 0; i < MAX_PLAYERS; i++)
+ if (tape.player_participates[i])
+ num_participating_players++;
+
+ tape_pos_size = (tape.use_mouse ? 3 : num_participating_players) + 1;
+
+ info_chunk_size = 2 + (strlen(tape.level_identifier) + 1) + 2;
+ body_chunk_size = tape_pos_size * tape.length;
+
+ putFileChunkBE(file, "RND1", CHUNK_SIZE_UNDEFINED);
+ putFileChunkBE(file, "TAPE", CHUNK_SIZE_NONE);
+
+ putFileChunkBE(file, "VERS", TAPE_CHUNK_VERS_SIZE);
+ SaveTape_VERS(file, &tape);
+
+ putFileChunkBE(file, "HEAD", TAPE_CHUNK_HEAD_SIZE);
+ SaveTape_HEAD(file, &tape);
+
+ putFileChunkBE(file, "INFO", info_chunk_size);
+ SaveTape_INFO(file, &tape);
+
+ putFileChunkBE(file, "BODY", body_chunk_size);
+ SaveTape_BODY(file, &tape);
+
+ fclose(file);
+
+ SetFilePermissions(filename, PERMS_PRIVATE);
+
+ tape.changed = FALSE;
+}
+
+static boolean SaveTapeCheckedExt(int nr, char *msg_replace, char *msg_saved)
+{
+ char *filename = getTapeFilename(nr);
+ boolean new_tape = !fileExists(filename);
+ boolean tape_saved = FALSE;
+
+ if (new_tape || Request(msg_replace, REQ_ASK))
+ {
+ SaveTape(nr);
+
+ if (new_tape)
+ Request(msg_saved, REQ_CONFIRM);
+
+ tape_saved = TRUE;
+ }
+
+ return tape_saved;
+}
+
+boolean SaveTapeChecked(int nr)
+{
+ return SaveTapeCheckedExt(nr, "Replace old tape?", "Tape saved!");
+}
+
+boolean SaveTapeChecked_LevelSolved(int nr)
+{
+ return SaveTapeCheckedExt(nr, "Level solved! Replace old tape?",
+ "Level solved! Tape saved!");
+}
+
+void DumpTape(struct TapeInfo *tape)
+{
+ int tape_frame_counter;
+ int i, j;
+
+ if (tape->no_valid_file)
+ {
+ Error(ERR_WARN, "cannot dump -- no valid tape file found");
+
+ return;
+ }
+
+ PrintLine("-", 79);
+ Print("Tape of Level %03d (file version %08d, game version %08d)\n",
+ tape->level_nr, tape->file_version, tape->game_version);
+ Print(" (effective engine version %08d)\n",
+ tape->engine_version);
+ Print("Level series identifier: '%s'\n", tape->level_identifier);
+ PrintLine("-", 79);
+
+ tape_frame_counter = 0;
+
+ for (i = 0; i < tape->length; i++)
+ {
+ if (i >= MAX_TAPE_LEN)
+ break;
+
+ Print("%04d: ", i);
+
+ for (j = 0; j < MAX_PLAYERS; j++)
+ {
+ if (tape->player_participates[j])
+ {
+ int action = tape->pos[i].action[j];
+
+ Print("%d:%02x ", j, action);
+ Print("[%c%c%c%c|%c%c] - ",
+ (action & JOY_LEFT ? '<' : ' '),
+ (action & JOY_RIGHT ? '>' : ' '),
+ (action & JOY_UP ? '^' : ' '),
+ (action & JOY_DOWN ? 'v' : ' '),
+ (action & JOY_BUTTON_1 ? '1' : ' '),
+ (action & JOY_BUTTON_2 ? '2' : ' '));
+ }
+ }
+
+ Print("(%03d) ", tape->pos[i].delay);
+ Print("[%05d]\n", tape_frame_counter);
+
+ tape_frame_counter += tape->pos[i].delay;
+ }
+
+ PrintLine("-", 79);
+}
+
+
+// ============================================================================
+// score file functions
+// ============================================================================
+
+void LoadScore(int nr)
+{
+ int i;
+ char *filename = getScoreFilename(nr);
+ char cookie[MAX_LINE_LEN];
+ char line[MAX_LINE_LEN];
+ char *line_ptr;
+ FILE *file;
+
+ // always start with reliable default values
+ for (i = 0; i < MAX_SCORE_ENTRIES; i++)
+ {
+ strcpy(highscore[i].Name, EMPTY_PLAYER_NAME);
+ highscore[i].Score = 0;
+ }
+
+ if (!(file = fopen(filename, MODE_READ)))
+ return;
+
+ // check file identifier
+ if (fgets(cookie, MAX_LINE_LEN, file) == NULL)
+ cookie[0] = '\0';
+ if (strlen(cookie) > 0 && cookie[strlen(cookie) - 1] == '\n')
+ cookie[strlen(cookie) - 1] = '\0';
+
+ if (!checkCookieString(cookie, SCORE_COOKIE))
+ {
+ Error(ERR_WARN, "unknown format of score file '%s'", filename);
+ fclose(file);
+ return;
+ }
+
+ for (i = 0; i < MAX_SCORE_ENTRIES; i++)
+ {
+ if (fscanf(file, "%d", &highscore[i].Score) == EOF)
+ Error(ERR_WARN, "fscanf() failed; %s", strerror(errno));
+ if (fgets(line, MAX_LINE_LEN, file) == NULL)
+ line[0] = '\0';
+
+ if (strlen(line) > 0 && line[strlen(line) - 1] == '\n')
+ line[strlen(line) - 1] = '\0';
+
+ for (line_ptr = line; *line_ptr; line_ptr++)
+ {
+ if (*line_ptr != ' ' && *line_ptr != '\t' && *line_ptr != '\0')
+ {
+ strncpy(highscore[i].Name, line_ptr, MAX_PLAYER_NAME_LEN);
+ highscore[i].Name[MAX_PLAYER_NAME_LEN] = '\0';
+ break;
+ }
+ }
+ }
+
+ fclose(file);
+}
+
+void SaveScore(int nr)
+{
+ int i;
+ int permissions = (program.global_scores ? PERMS_PUBLIC : PERMS_PRIVATE);
+ char *filename = getScoreFilename(nr);
+ FILE *file;
+
+ // used instead of "leveldir_current->subdir" (for network games)
+ InitScoreDirectory(levelset.identifier);
+
+ if (!(file = fopen(filename, MODE_WRITE)))
+ {
+ Error(ERR_WARN, "cannot save score for level %d", nr);
+ return;
+ }
+
+ fprintf(file, "%s\n\n", SCORE_COOKIE);
+
+ for (i = 0; i < MAX_SCORE_ENTRIES; i++)
+ fprintf(file, "%d %s\n", highscore[i].Score, highscore[i].Name);
+
+ fclose(file);
+
+ SetFilePermissions(filename, permissions);
+}
+
+
+// ============================================================================
+// setup file functions
+// ============================================================================
+
+#define TOKEN_STR_PLAYER_PREFIX "player_"
+
+// global setup
+enum
+{
+ SETUP_TOKEN_PLAYER_NAME = 0,
+ SETUP_TOKEN_SOUND,
+ SETUP_TOKEN_SOUND_LOOPS,
+ SETUP_TOKEN_SOUND_MUSIC,
+ SETUP_TOKEN_SOUND_SIMPLE,
+ SETUP_TOKEN_TOONS,
+ SETUP_TOKEN_SCROLL_DELAY,
+ SETUP_TOKEN_SCROLL_DELAY_VALUE,
+ SETUP_TOKEN_ENGINE_SNAPSHOT_MODE,
+ SETUP_TOKEN_ENGINE_SNAPSHOT_MEMORY,
+ SETUP_TOKEN_FADE_SCREENS,
+ SETUP_TOKEN_AUTORECORD,
+ SETUP_TOKEN_SHOW_TITLESCREEN,
+ SETUP_TOKEN_QUICK_DOORS,
+ SETUP_TOKEN_TEAM_MODE,
+ SETUP_TOKEN_HANDICAP,
+ SETUP_TOKEN_SKIP_LEVELS,
+ SETUP_TOKEN_INCREMENT_LEVELS,
+ SETUP_TOKEN_AUTO_PLAY_NEXT_LEVEL,
+ SETUP_TOKEN_SKIP_SCORES_AFTER_GAME,
+ SETUP_TOKEN_TIME_LIMIT,
+ SETUP_TOKEN_FULLSCREEN,
+ SETUP_TOKEN_WINDOW_SCALING_PERCENT,
+ SETUP_TOKEN_WINDOW_SCALING_QUALITY,
+ SETUP_TOKEN_SCREEN_RENDERING_MODE,
+ SETUP_TOKEN_VSYNC_MODE,
+ SETUP_TOKEN_ASK_ON_ESCAPE,
+ SETUP_TOKEN_ASK_ON_ESCAPE_EDITOR,
+ SETUP_TOKEN_ASK_ON_GAME_OVER,
+ SETUP_TOKEN_QUICK_SWITCH,
+ SETUP_TOKEN_INPUT_ON_FOCUS,
+ SETUP_TOKEN_PREFER_AGA_GRAPHICS,
+ SETUP_TOKEN_GAME_SPEED_EXTENDED,
+ SETUP_TOKEN_GAME_FRAME_DELAY,
+ SETUP_TOKEN_SP_SHOW_BORDER_ELEMENTS,
+ SETUP_TOKEN_SMALL_GAME_GRAPHICS,
+ SETUP_TOKEN_SHOW_SNAPSHOT_BUTTONS,
+ SETUP_TOKEN_GRAPHICS_SET,
+ SETUP_TOKEN_SOUNDS_SET,
+ SETUP_TOKEN_MUSIC_SET,
+ SETUP_TOKEN_OVERRIDE_LEVEL_GRAPHICS,
+ SETUP_TOKEN_OVERRIDE_LEVEL_SOUNDS,
+ SETUP_TOKEN_OVERRIDE_LEVEL_MUSIC,
+ SETUP_TOKEN_VOLUME_SIMPLE,
+ SETUP_TOKEN_VOLUME_LOOPS,
+ SETUP_TOKEN_VOLUME_MUSIC,
+ SETUP_TOKEN_NETWORK_MODE,
+ SETUP_TOKEN_NETWORK_PLAYER_NR,
+ SETUP_TOKEN_NETWORK_SERVER_HOSTNAME,
+ SETUP_TOKEN_TOUCH_CONTROL_TYPE,
+ SETUP_TOKEN_TOUCH_MOVE_DISTANCE,
+ SETUP_TOKEN_TOUCH_DROP_DISTANCE,
+ SETUP_TOKEN_TOUCH_TRANSPARENCY,
+ SETUP_TOKEN_TOUCH_DRAW_OUTLINED,
+ SETUP_TOKEN_TOUCH_DRAW_PRESSED,
+ SETUP_TOKEN_TOUCH_GRID_XSIZE_0,
+ SETUP_TOKEN_TOUCH_GRID_YSIZE_0,
+ SETUP_TOKEN_TOUCH_GRID_XSIZE_1,
+ SETUP_TOKEN_TOUCH_GRID_YSIZE_1,
+
+ NUM_GLOBAL_SETUP_TOKENS
+};
+
+// auto setup
+enum
+{
+ SETUP_TOKEN_AUTO_EDITOR_ZOOM_TILESIZE = 0,
+
+ NUM_AUTO_SETUP_TOKENS
+};
+
+// editor setup
+enum
+{
+ SETUP_TOKEN_EDITOR_EL_CLASSIC = 0,
+ SETUP_TOKEN_EDITOR_EL_CUSTOM,
+ SETUP_TOKEN_EDITOR_EL_USER_DEFINED,
+ SETUP_TOKEN_EDITOR_EL_DYNAMIC,
+ SETUP_TOKEN_EDITOR_EL_HEADLINES,
+ SETUP_TOKEN_EDITOR_SHOW_ELEMENT_TOKEN,
+
+ NUM_EDITOR_SETUP_TOKENS
+};
+
+// editor cascade setup
+enum
+{
+ SETUP_TOKEN_EDITOR_CASCADE_BD = 0,
+ SETUP_TOKEN_EDITOR_CASCADE_EM,
+ SETUP_TOKEN_EDITOR_CASCADE_EMC,
+ SETUP_TOKEN_EDITOR_CASCADE_RND,
+ SETUP_TOKEN_EDITOR_CASCADE_SB,
+ SETUP_TOKEN_EDITOR_CASCADE_SP,
+ SETUP_TOKEN_EDITOR_CASCADE_DC,
+ SETUP_TOKEN_EDITOR_CASCADE_DX,
+ SETUP_TOKEN_EDITOR_CASCADE_TEXT,
+ SETUP_TOKEN_EDITOR_CASCADE_STEELTEXT,
+ SETUP_TOKEN_EDITOR_CASCADE_CE,
+ SETUP_TOKEN_EDITOR_CASCADE_GE,
+ SETUP_TOKEN_EDITOR_CASCADE_REF,
+ SETUP_TOKEN_EDITOR_CASCADE_USER,
+ SETUP_TOKEN_EDITOR_CASCADE_DYNAMIC,
+
+ NUM_EDITOR_CASCADE_SETUP_TOKENS
+};
+
+// shortcut setup
+enum
+{
+ SETUP_TOKEN_SHORTCUT_SAVE_GAME = 0,
+ SETUP_TOKEN_SHORTCUT_LOAD_GAME,
+ SETUP_TOKEN_SHORTCUT_TOGGLE_PAUSE,
+ SETUP_TOKEN_SHORTCUT_FOCUS_PLAYER_1,
+ SETUP_TOKEN_SHORTCUT_FOCUS_PLAYER_2,
+ SETUP_TOKEN_SHORTCUT_FOCUS_PLAYER_3,
+ SETUP_TOKEN_SHORTCUT_FOCUS_PLAYER_4,
+ SETUP_TOKEN_SHORTCUT_FOCUS_PLAYER_ALL,
+ SETUP_TOKEN_SHORTCUT_TAPE_EJECT,
+ SETUP_TOKEN_SHORTCUT_TAPE_EXTRA,
+ SETUP_TOKEN_SHORTCUT_TAPE_STOP,
+ SETUP_TOKEN_SHORTCUT_TAPE_PAUSE,
+ SETUP_TOKEN_SHORTCUT_TAPE_RECORD,
+ SETUP_TOKEN_SHORTCUT_TAPE_PLAY,
+ SETUP_TOKEN_SHORTCUT_SOUND_SIMPLE,
+ SETUP_TOKEN_SHORTCUT_SOUND_LOOPS,
+ SETUP_TOKEN_SHORTCUT_SOUND_MUSIC,
+ SETUP_TOKEN_SHORTCUT_SNAP_LEFT,
+ SETUP_TOKEN_SHORTCUT_SNAP_RIGHT,
+ SETUP_TOKEN_SHORTCUT_SNAP_UP,
+ SETUP_TOKEN_SHORTCUT_SNAP_DOWN,
+
+ NUM_SHORTCUT_SETUP_TOKENS
+};
+
+// player setup
+enum
+{
+ SETUP_TOKEN_PLAYER_USE_JOYSTICK = 0,
+ SETUP_TOKEN_PLAYER_JOY_DEVICE_NAME,
+ SETUP_TOKEN_PLAYER_JOY_XLEFT,
+ SETUP_TOKEN_PLAYER_JOY_XMIDDLE,
+ SETUP_TOKEN_PLAYER_JOY_XRIGHT,
+ SETUP_TOKEN_PLAYER_JOY_YUPPER,
+ SETUP_TOKEN_PLAYER_JOY_YMIDDLE,
+ SETUP_TOKEN_PLAYER_JOY_YLOWER,
+ SETUP_TOKEN_PLAYER_JOY_SNAP,
+ SETUP_TOKEN_PLAYER_JOY_DROP,
+ SETUP_TOKEN_PLAYER_KEY_LEFT,
+ SETUP_TOKEN_PLAYER_KEY_RIGHT,
+ SETUP_TOKEN_PLAYER_KEY_UP,
+ SETUP_TOKEN_PLAYER_KEY_DOWN,
+ SETUP_TOKEN_PLAYER_KEY_SNAP,
+ SETUP_TOKEN_PLAYER_KEY_DROP,
+
+ NUM_PLAYER_SETUP_TOKENS
+};
+
+// system setup
+enum
+{
+ SETUP_TOKEN_SYSTEM_SDL_VIDEODRIVER = 0,
+ SETUP_TOKEN_SYSTEM_SDL_AUDIODRIVER,
+ SETUP_TOKEN_SYSTEM_AUDIO_FRAGMENT_SIZE,
+
+ NUM_SYSTEM_SETUP_TOKENS
+};
+
+// internal setup
+enum
+{
+ SETUP_TOKEN_INT_PROGRAM_TITLE = 0,
+ SETUP_TOKEN_INT_PROGRAM_VERSION,
+ SETUP_TOKEN_INT_PROGRAM_AUTHOR,
+ SETUP_TOKEN_INT_PROGRAM_EMAIL,
+ SETUP_TOKEN_INT_PROGRAM_WEBSITE,
+ SETUP_TOKEN_INT_PROGRAM_COPYRIGHT,
+ SETUP_TOKEN_INT_PROGRAM_COMPANY,
+ SETUP_TOKEN_INT_PROGRAM_ICON_FILE,
+ SETUP_TOKEN_INT_DEFAULT_GRAPHICS_SET,
+ SETUP_TOKEN_INT_DEFAULT_SOUNDS_SET,
+ SETUP_TOKEN_INT_DEFAULT_MUSIC_SET,
+ SETUP_TOKEN_INT_FALLBACK_GRAPHICS_FILE,
+ SETUP_TOKEN_INT_FALLBACK_SOUNDS_FILE,
+ SETUP_TOKEN_INT_FALLBACK_MUSIC_FILE,
+ SETUP_TOKEN_INT_DEFAULT_LEVEL_SERIES,
+ SETUP_TOKEN_INT_CHOOSE_FROM_TOP_LEVELDIR,
+ SETUP_TOKEN_INT_SHOW_SCALING_IN_TITLE,
+ SETUP_TOKEN_INT_DEFAULT_WINDOW_WIDTH,
+ SETUP_TOKEN_INT_DEFAULT_WINDOW_HEIGHT,
+
+ NUM_INTERNAL_SETUP_TOKENS
+};
+
+// debug setup
+enum
+{
+ SETUP_TOKEN_DEBUG_FRAME_DELAY_0 = 0,
+ SETUP_TOKEN_DEBUG_FRAME_DELAY_1,
+ SETUP_TOKEN_DEBUG_FRAME_DELAY_2,
+ SETUP_TOKEN_DEBUG_FRAME_DELAY_3,
+ SETUP_TOKEN_DEBUG_FRAME_DELAY_4,
+ SETUP_TOKEN_DEBUG_FRAME_DELAY_5,
+ SETUP_TOKEN_DEBUG_FRAME_DELAY_6,
+ SETUP_TOKEN_DEBUG_FRAME_DELAY_7,
+ SETUP_TOKEN_DEBUG_FRAME_DELAY_8,
+ SETUP_TOKEN_DEBUG_FRAME_DELAY_9,
+ SETUP_TOKEN_DEBUG_FRAME_DELAY_KEY_0,
+ SETUP_TOKEN_DEBUG_FRAME_DELAY_KEY_1,
+ SETUP_TOKEN_DEBUG_FRAME_DELAY_KEY_2,
+ SETUP_TOKEN_DEBUG_FRAME_DELAY_KEY_3,
+ SETUP_TOKEN_DEBUG_FRAME_DELAY_KEY_4,
+ SETUP_TOKEN_DEBUG_FRAME_DELAY_KEY_5,
+ SETUP_TOKEN_DEBUG_FRAME_DELAY_KEY_6,
+ SETUP_TOKEN_DEBUG_FRAME_DELAY_KEY_7,
+ SETUP_TOKEN_DEBUG_FRAME_DELAY_KEY_8,
+ SETUP_TOKEN_DEBUG_FRAME_DELAY_KEY_9,
+ SETUP_TOKEN_DEBUG_FRAME_DELAY_USE_MOD_KEY,
+ SETUP_TOKEN_DEBUG_FRAME_DELAY_GAME_ONLY,
+ SETUP_TOKEN_DEBUG_SHOW_FRAMES_PER_SECOND,
+
+ NUM_DEBUG_SETUP_TOKENS
+};
+
+// options setup
+enum
+{
+ SETUP_TOKEN_OPTIONS_VERBOSE = 0,
+
+ NUM_OPTIONS_SETUP_TOKENS
+};
+
+
+static struct SetupInfo si;
+static struct SetupAutoSetupInfo sasi;
+static struct SetupEditorInfo sei;
+static struct SetupEditorCascadeInfo seci;
+static struct SetupShortcutInfo ssi;
+static struct SetupInputInfo sii;
+static struct SetupSystemInfo syi;
+static struct SetupInternalInfo sxi;
+static struct SetupDebugInfo sdi;
+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_STRING, &si.engine_snapshot_mode, "engine_snapshot_mode" },
+ { TYPE_INTEGER,&si.engine_snapshot_memory, "engine_snapshot_memory" },
+ { 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.increment_levels, "increment_levels" },
+ { TYPE_SWITCH, &si.auto_play_next_level, "auto_play_next_level" },
+ { TYPE_SWITCH, &si.skip_scores_after_game, "skip_scores_after_game" },
+ { TYPE_SWITCH, &si.time_limit, "time_limit" },
+ { TYPE_SWITCH, &si.fullscreen, "fullscreen" },
+ { TYPE_INTEGER,&si.window_scaling_percent, "window_scaling_percent" },
+ { TYPE_STRING, &si.window_scaling_quality, "window_scaling_quality" },
+ { TYPE_STRING, &si.screen_rendering_mode, "screen_rendering_mode" },
+ { TYPE_STRING, &si.vsync_mode, "vsync_mode" },
+ { TYPE_SWITCH, &si.ask_on_escape, "ask_on_escape" },
+ { TYPE_SWITCH, &si.ask_on_escape_editor, "ask_on_escape_editor" },
+ { TYPE_SWITCH, &si.ask_on_game_over, "ask_on_game_over" },
+ { 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_SWITCH, &si.game_speed_extended, "game_speed_extended" },
+ { TYPE_INTEGER,&si.game_frame_delay, "game_frame_delay" },
+ { TYPE_SWITCH, &si.sp_show_border_elements, "sp_show_border_elements" },
+ { TYPE_SWITCH, &si.small_game_graphics, "small_game_graphics" },
+ { TYPE_SWITCH, &si.show_snapshot_buttons, "show_snapshot_buttons" },
+ { 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" },
+ { TYPE_INTEGER,&si.volume_simple, "volume_simple" },
+ { TYPE_INTEGER,&si.volume_loops, "volume_loops" },
+ { TYPE_INTEGER,&si.volume_music, "volume_music" },
+ { TYPE_SWITCH, &si.network_mode, "network_mode" },
+ { TYPE_PLAYER, &si.network_player_nr, "network_player" },
+ { TYPE_STRING, &si.network_server_hostname, "network_server_hostname" },
+ { TYPE_STRING, &si.touch.control_type, "touch.control_type" },
+ { TYPE_INTEGER,&si.touch.move_distance, "touch.move_distance" },
+ { TYPE_INTEGER,&si.touch.drop_distance, "touch.drop_distance" },
+ { TYPE_INTEGER,&si.touch.transparency, "touch.transparency" },
+ { TYPE_INTEGER,&si.touch.draw_outlined, "touch.draw_outlined" },
+ { TYPE_INTEGER,&si.touch.draw_pressed, "touch.draw_pressed" },
+ { TYPE_INTEGER,&si.touch.grid_xsize[0], "touch.virtual_buttons.0.xsize" },
+ { TYPE_INTEGER,&si.touch.grid_ysize[0], "touch.virtual_buttons.0.ysize" },
+ { TYPE_INTEGER,&si.touch.grid_xsize[1], "touch.virtual_buttons.1.xsize" },
+ { TYPE_INTEGER,&si.touch.grid_ysize[1], "touch.virtual_buttons.1.ysize" },
+};
+
+static struct TokenInfo auto_setup_tokens[] =
+{
+ { TYPE_INTEGER,&sasi.editor_zoom_tilesize, "editor.zoom_tilesize" },
+};
+
+static struct TokenInfo editor_setup_tokens[] =
+{
+ { TYPE_SWITCH, &sei.el_classic, "editor.el_classic" },
+ { TYPE_SWITCH, &sei.el_custom, "editor.el_custom" },
+ { TYPE_SWITCH, &sei.el_user_defined, "editor.el_user_defined" },
+ { TYPE_SWITCH, &sei.el_dynamic, "editor.el_dynamic" },
+ { TYPE_SWITCH, &sei.el_headlines, "editor.el_headlines" },
+ { TYPE_SWITCH, &sei.show_element_token,"editor.show_element_token" },
+};
+
+static struct TokenInfo editor_cascade_setup_tokens[] =
+{
+ { TYPE_SWITCH, &seci.el_bd, "editor.cascade.el_bd" },
+ { TYPE_SWITCH, &seci.el_em, "editor.cascade.el_em" },
+ { TYPE_SWITCH, &seci.el_emc, "editor.cascade.el_emc" },
+ { TYPE_SWITCH, &seci.el_rnd, "editor.cascade.el_rnd" },
+ { TYPE_SWITCH, &seci.el_sb, "editor.cascade.el_sb" },
+ { TYPE_SWITCH, &seci.el_sp, "editor.cascade.el_sp" },
+ { TYPE_SWITCH, &seci.el_dc, "editor.cascade.el_dc" },
+ { TYPE_SWITCH, &seci.el_dx, "editor.cascade.el_dx" },
+ { TYPE_SWITCH, &seci.el_mm, "editor.cascade.el_mm" },
+ { TYPE_SWITCH, &seci.el_df, "editor.cascade.el_df" },
+ { TYPE_SWITCH, &seci.el_chars, "editor.cascade.el_chars" },
+ { TYPE_SWITCH, &seci.el_steel_chars, "editor.cascade.el_steel_chars" },
+ { TYPE_SWITCH, &seci.el_ce, "editor.cascade.el_ce" },
+ { TYPE_SWITCH, &seci.el_ge, "editor.cascade.el_ge" },
+ { TYPE_SWITCH, &seci.el_ref, "editor.cascade.el_ref" },
+ { TYPE_SWITCH, &seci.el_user, "editor.cascade.el_user" },
+ { TYPE_SWITCH, &seci.el_dynamic, "editor.cascade.el_dynamic" },
+};
+
+static struct TokenInfo shortcut_setup_tokens[] =
+{
+ { TYPE_KEY_X11, &ssi.save_game, "shortcut.save_game" },
+ { TYPE_KEY_X11, &ssi.load_game, "shortcut.load_game" },
+ { TYPE_KEY_X11, &ssi.toggle_pause, "shortcut.toggle_pause" },
+ { TYPE_KEY_X11, &ssi.focus_player[0], "shortcut.focus_player_1" },
+ { TYPE_KEY_X11, &ssi.focus_player[1], "shortcut.focus_player_2" },
+ { TYPE_KEY_X11, &ssi.focus_player[2], "shortcut.focus_player_3" },
+ { TYPE_KEY_X11, &ssi.focus_player[3], "shortcut.focus_player_4" },
+ { TYPE_KEY_X11, &ssi.focus_player_all,"shortcut.focus_player_all" },
+ { TYPE_KEY_X11, &ssi.tape_eject, "shortcut.tape_eject" },
+ { TYPE_KEY_X11, &ssi.tape_extra, "shortcut.tape_extra" },
+ { TYPE_KEY_X11, &ssi.tape_stop, "shortcut.tape_stop" },
+ { TYPE_KEY_X11, &ssi.tape_pause, "shortcut.tape_pause" },
+ { TYPE_KEY_X11, &ssi.tape_record, "shortcut.tape_record" },
+ { TYPE_KEY_X11, &ssi.tape_play, "shortcut.tape_play" },
+ { TYPE_KEY_X11, &ssi.sound_simple, "shortcut.sound_simple" },
+ { TYPE_KEY_X11, &ssi.sound_loops, "shortcut.sound_loops" },
+ { TYPE_KEY_X11, &ssi.sound_music, "shortcut.sound_music" },
+ { TYPE_KEY_X11, &ssi.snap_left, "shortcut.snap_left" },
+ { TYPE_KEY_X11, &ssi.snap_right, "shortcut.snap_right" },
+ { TYPE_KEY_X11, &ssi.snap_up, "shortcut.snap_up" },
+ { TYPE_KEY_X11, &ssi.snap_down, "shortcut.snap_down" },
+};
+
+static struct TokenInfo player_setup_tokens[] =
+{
+ { TYPE_BOOLEAN, &sii.use_joystick, ".use_joystick" },
+ { TYPE_STRING, &sii.joy.device_name, ".joy.device_name" },
+ { TYPE_INTEGER, &sii.joy.xleft, ".joy.xleft" },
+ { TYPE_INTEGER, &sii.joy.xmiddle, ".joy.xmiddle" },