X-Git-Url: https://git.artsoft.org/?a=blobdiff_plain;f=src%2Ffiles.c;h=d18122f270c1d03efadea0dd71fd0a6603ce2159;hb=9923c6ae90268ef53e0e7411d29115ef2568b182;hp=c60e08b45e80f88a623775853928bd937adbcd45;hpb=52e017626088f7b931acbb301f2234faa782de88;p=rocksndiamonds.git diff --git a/src/files.c b/src/files.c index c60e08b4..d18122f2 100644 --- a/src/files.c +++ b/src/files.c @@ -57,7 +57,7 @@ #define TAPE_CHUNK_VERS_SIZE 8 /* size of file version chunk */ #define TAPE_CHUNK_HEAD_SIZE 20 /* size of tape file header */ -#define TAPE_CHUNK_HEAD_UNUSED 3 /* unused tape header bytes */ +#define TAPE_CHUNK_HEAD_UNUSED 2 /* unused tape header bytes */ #define LEVEL_CHUNK_CNT3_SIZE(x) (LEVEL_CHUNK_CNT3_HEADER + (x)) #define LEVEL_CHUNK_CUS3_SIZE(x) (2 + (x) * LEVEL_CPART_CUS3_SIZE) @@ -244,6 +244,12 @@ static struct LevelFileConfigInfo chunk_config_INFO[] = &li.auto_exit_sokoban, FALSE }, + { + -1, -1, + TYPE_BOOLEAN, CONF_VALUE_8_BIT(10), + &li.auto_count_gems, FALSE + }, + { -1, -1, -1, -1, @@ -800,6 +806,44 @@ static struct LevelFileConfigInfo chunk_config_ELEM[] = &li.num_ball_contents, 4, MAX_ELEMENT_CONTENTS }, + { + EL_MM_MCDUFFIN, -1, + TYPE_BOOLEAN, CONF_VALUE_8_BIT(1), + &li.mm_laser_red, FALSE + }, + { + EL_MM_MCDUFFIN, -1, + TYPE_BOOLEAN, CONF_VALUE_8_BIT(2), + &li.mm_laser_green, FALSE + }, + { + EL_MM_MCDUFFIN, -1, + TYPE_BOOLEAN, CONF_VALUE_8_BIT(3), + &li.mm_laser_blue, TRUE + }, + + { + EL_DF_LASER, -1, + TYPE_BOOLEAN, CONF_VALUE_8_BIT(1), + &li.df_laser_red, TRUE + }, + { + EL_DF_LASER, -1, + TYPE_BOOLEAN, CONF_VALUE_8_BIT(2), + &li.df_laser_green, TRUE + }, + { + EL_DF_LASER, -1, + TYPE_BOOLEAN, CONF_VALUE_8_BIT(3), + &li.df_laser_blue, FALSE + }, + + { + EL_MM_FUSE, -1, + TYPE_INTEGER, CONF_VALUE_16_BIT(1), + &li.mm_time_fuse, 0 + }, + /* ---------- unused values ----------------------------------------------- */ { @@ -3941,10 +3985,11 @@ void CopyNativeLevel_RND_to_MM(struct LevelInfo *level) level_mm->time = level->time; level_mm->kettles_needed = level->gems_needed; - level_mm->auto_count_kettles = FALSE; - level_mm->laser_red = FALSE; - level_mm->laser_green = FALSE; - level_mm->laser_blue = TRUE; + level_mm->auto_count_kettles = level->auto_count_gems; + + level_mm->laser_red = level->mm_laser_red; + level_mm->laser_green = level->mm_laser_green; + level_mm->laser_blue = level->mm_laser_blue; strcpy(level_mm->name, level->name); strcpy(level_mm->author, level->author); @@ -3954,7 +3999,7 @@ void CopyNativeLevel_RND_to_MM(struct LevelInfo *level) level_mm->score[SC_TIME_BONUS] = level->score[SC_TIME_BONUS]; level_mm->amoeba_speed = level->amoeba_speed; - level_mm->time_fuse = 0; + level_mm->time_fuse = level->mm_time_fuse; for (x = 0; x < level->fieldx; x++) for (y = 0; y < level->fieldy; y++) @@ -3976,6 +4021,11 @@ void CopyNativeLevel_MM_to_RND(struct LevelInfo *level) level->time = level_mm->time; level->gems_needed = level_mm->kettles_needed; + level->auto_count_gems = level_mm->auto_count_kettles; + + level->mm_laser_red = level_mm->laser_red; + level->mm_laser_green = level_mm->laser_green; + level->mm_laser_blue = level_mm->laser_blue; strcpy(level->name, level_mm->name); @@ -3988,21 +4038,11 @@ void CopyNativeLevel_MM_to_RND(struct LevelInfo *level) level->score[SC_TIME_BONUS] = level_mm->score[SC_TIME_BONUS]; level->amoeba_speed = level_mm->amoeba_speed; + level->mm_time_fuse = level_mm->time_fuse; for (x = 0; x < level->fieldx; x++) for (y = 0; y < level->fieldy; y++) level->field[x][y] = map_element_MM_to_RND(level_mm->field[x][y]); - - if (level_mm->auto_count_kettles) - { - level->gems_needed = 0; - - for (x = 0; x < level->fieldx; x++) - for (y = 0; y < level->fieldy; y++) - if (level->field[x][y] == EL_MM_KETTLE || - level->field[x][y] == EL_DF_CELL) - level->gems_needed++; - } } @@ -7524,6 +7564,8 @@ static int LoadTape_HEAD(File *file, int chunk_size, struct TapeInfo *tape) } } + tape->use_mouse = (getFile8Bit(file) == 1 ? TRUE : FALSE); + ReadUnusedBytesFromFile(file, TAPE_CHUNK_HEAD_UNUSED); engine_version = getFileVersion(file); @@ -7559,8 +7601,9 @@ static int LoadTape_INFO(File *file, int chunk_size, struct TapeInfo *tape) static int LoadTape_BODY(File *file, int chunk_size, struct TapeInfo *tape) { int i, j; - int chunk_size_expected = - (tape->num_participating_players + 1) * tape->length; + 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) { @@ -7582,12 +7625,23 @@ static int LoadTape_BODY(File *file, int chunk_size, struct TapeInfo *tape) break; } - for (j = 0; j < MAX_PLAYERS; j++) + if (tape->use_mouse) { - tape->pos[i].action[j] = MV_NONE; + 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); - if (tape->player_participates[j]) - tape->pos[i].action[j] = 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); @@ -7644,7 +7698,7 @@ static int LoadTape_BODY(File *file, int chunk_size, struct TapeInfo *tape) } if (i != tape->length) - chunk_size = (tape->num_participating_players + 1) * i; + chunk_size = tape_pos_size * i; return chunk_size; } @@ -7913,6 +7967,8 @@ static void SaveTape_HEAD(FILE *file, struct TapeInfo *tape) 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); @@ -7938,9 +7994,18 @@ static void SaveTape_BODY(FILE *file, struct TapeInfo *tape) for (i = 0; i < tape->length; i++) { - for (j = 0; j < MAX_PLAYERS; j++) - if (tape->player_participates[j]) - putFile8Bit(file, tape->pos[i].action[j]); + 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); } @@ -7951,6 +8016,7 @@ 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; @@ -7971,8 +8037,10 @@ void SaveTape(int nr) 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 = (num_participating_players + 1) * tape.length; + body_chunk_size = tape_pos_size * tape.length; putFileChunkBE(file, "RND1", CHUNK_SIZE_UNDEFINED); putFileChunkBE(file, "TAPE", CHUNK_SIZE_NONE); @@ -8211,6 +8279,11 @@ void SaveScore(int nr) #define NUM_GLOBAL_SETUP_TOKENS 44 +/* auto setup */ +#define SETUP_TOKEN_AUTO_EDITOR_ZOOM_TILESIZE 0 + +#define NUM_AUTO_SETUP_TOKENS 1 + /* editor setup */ #define SETUP_TOKEN_EDITOR_EL_CLASSIC 0 #define SETUP_TOKEN_EDITOR_EL_CUSTOM 1 @@ -8349,6 +8422,7 @@ void SaveScore(int nr) static struct SetupInfo si; +static struct SetupAutoSetupInfo sasi; static struct SetupEditorInfo sei; static struct SetupEditorCascadeInfo seci; static struct SetupShortcutInfo ssi; @@ -8406,6 +8480,11 @@ static struct TokenInfo global_setup_tokens[] = { TYPE_INTEGER,&si.touch.drop_distance, "touch.drop_distance" }, }; +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" }, @@ -8749,6 +8828,11 @@ static void setSetupInfoToDefaults(struct SetupInfo *si) #endif } +static void setSetupInfoToDefaults_AutoSetup(struct SetupInfo *si) +{ + si->auto_setup.editor_zoom_tilesize = MINI_TILESIZE; +} + static void setSetupInfoToDefaults_EditorCascade(struct SetupInfo *si) { si->editor_cascade.el_bd = TRUE; @@ -8898,6 +8982,22 @@ static void decodeSetupFileHash(SetupFileHash *setup_file_hash) setup.options = soi; } +static void decodeSetupFileHash_AutoSetup(SetupFileHash *setup_file_hash) +{ + int i; + + if (!setup_file_hash) + return; + + /* auto setup */ + sasi = setup.auto_setup; + for (i = 0; i < NUM_AUTO_SETUP_TOKENS; i++) + setSetupInfo(auto_setup_tokens, i, + getHashEntry(setup_file_hash, + auto_setup_tokens[i].text)); + setup.auto_setup = sasi; +} + static void decodeSetupFileHash_EditorCascade(SetupFileHash *setup_file_hash) { int i; @@ -8972,6 +9072,26 @@ void LoadSetup() LoadSetup_SpecialPostProcessing(); } +void LoadSetup_AutoSetup() +{ + char *filename = getPath2(getSetupDir(), AUTOSETUP_FILENAME); + SetupFileHash *setup_file_hash = NULL; + + /* always start with reliable default values */ + setSetupInfoToDefaults_AutoSetup(&setup); + + setup_file_hash = loadSetupFileHash(filename); + + if (setup_file_hash) + { + decodeSetupFileHash_AutoSetup(setup_file_hash); + + freeSetupFileHash(setup_file_hash); + } + + free(filename); +} + void LoadSetup_EditorCascade() { char *filename = getPath2(getSetupDir(), EDITORCASCADE_FILENAME); @@ -9122,6 +9242,34 @@ void SaveSetup() SetFilePermissions(filename, PERMS_PRIVATE); } +void SaveSetup_AutoSetup() +{ + char *filename = getPath2(getSetupDir(), AUTOSETUP_FILENAME); + FILE *file; + int i; + + InitUserDataDirectory(); + + if (!(file = fopen(filename, MODE_WRITE))) + { + Error(ERR_WARN, "cannot write auto setup file '%s'", filename); + free(filename); + return; + } + + fprintFileHeader(file, AUTOSETUP_FILENAME); + + sasi = setup.auto_setup; + for (i = 0; i < NUM_AUTO_SETUP_TOKENS; i++) + fprintf(file, "%s\n", getSetupLine(auto_setup_tokens, "", i)); + + fclose(file); + + SetFilePermissions(filename, PERMS_PRIVATE); + + free(filename); +} + void SaveSetup_EditorCascade() { char *filename = getPath2(getSetupDir(), EDITORCASCADE_FILENAME);