X-Git-Url: https://git.artsoft.org/?a=blobdiff_plain;f=src%2Ffiles.c;h=d38858203b8fb2a5e527bedd43e22a28c9cbb18b;hb=6460301d715f72f7247b3070a5d98c0b56cfdb67;hp=981411f0a9a171d1cd266232412766f2c1a4e299;hpb=216bac7a443561781916af1b643d14a15007db42;p=rocksndiamonds.git diff --git a/src/files.c b/src/files.c index 981411f0..d3885820 100644 --- a/src/files.c +++ b/src/files.c @@ -7619,6 +7619,56 @@ static void setTapeInfoToDefaults(void) tape.no_valid_file = FALSE; } +static int getTapePosSize(struct TapeInfo *tape) +{ + int tape_pos_size = 0; + + if (tape->event_mask == GAME_EVENTS_KEYS) + tape_pos_size += tape->num_participating_players; + else + tape_pos_size += 3; // x and y position and mouse button mask + + tape_pos_size += 1; // tape action delay value + + return tape_pos_size; +} + +static int getGameEventMaskFromTapeEventValue(int value) +{ + switch (value) + { + case TAPE_EVENTS_KEYS_ONLY: + return GAME_EVENTS_KEYS; + + case TAPE_EVENTS_MOUSE_ONLY: + return GAME_EVENTS_MOUSE; + + case TAPE_EVENTS_KEYS_AND_MOUSE: + return GAME_EVENTS_KEYS | GAME_EVENTS_MOUSE; + + default: + return GAME_EVENTS_DEFAULT; + } +} + +static int getTapeEventValueFromGameEventMask(int mask) +{ + switch (mask) + { + case GAME_EVENTS_KEYS: + return TAPE_EVENTS_KEYS_ONLY; + + case GAME_EVENTS_MOUSE: + return TAPE_EVENTS_MOUSE_ONLY; + + case GAME_EVENTS_KEYS | GAME_EVENTS_MOUSE: + return TAPE_EVENTS_KEYS_AND_MOUSE; + + default: + return TAPE_EVENTS_DEFAULT; + } +} + static int LoadTape_VERS(File *file, int chunk_size, struct TapeInfo *tape) { tape->file_version = getFileVersion(file); @@ -7654,7 +7704,7 @@ static int LoadTape_HEAD(File *file, int chunk_size, struct TapeInfo *tape) } } - tape->use_mouse = (getFile8Bit(file) == 1 ? TRUE : FALSE); + tape->event_mask = getGameEventMaskFromTapeEventValue(getFile8Bit(file)); ReadUnusedBytesFromFile(file, TAPE_CHUNK_HEAD_UNUSED); @@ -7691,8 +7741,7 @@ 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 tape_pos_size = - (tape->use_mouse ? 3 : tape->num_participating_players) + 1; + int tape_pos_size = getTapePosSize(tape); int chunk_size_expected = tape_pos_size * tape->length; if (chunk_size_expected != chunk_size) @@ -7710,12 +7759,12 @@ static int LoadTape_BODY(File *file, int chunk_size, struct TapeInfo *tape) // tape too large; read and ignore remaining tape data from this chunk for (;i < tape->length; i++) - ReadUnusedBytesFromFile(file, tape->num_participating_players + 1); + ReadUnusedBytesFromFile(file, tape_pos_size); break; } - if (tape->use_mouse) + if (tape->event_mask == GAME_EVENTS_MOUSE) { tape->pos[i].action[TAPE_ACTION_LX] = getFile8Bit(file); tape->pos[i].action[TAPE_ACTION_LY] = getFile8Bit(file); @@ -8057,7 +8106,7 @@ static void SaveTape_HEAD(FILE *file, struct TapeInfo *tape) putFile8Bit(file, store_participating_players); - putFile8Bit(file, (tape->use_mouse ? 1 : 0)); + putFile8Bit(file, getTapeEventValueFromGameEventMask(tape->event_mask)); // unused bytes not at the end here for 4-byte alignment of engine_version WriteUnusedBytesToFile(file, TAPE_CHUNK_HEAD_UNUSED); @@ -8084,7 +8133,7 @@ static void SaveTape_BODY(FILE *file, struct TapeInfo *tape) for (i = 0; i < tape->length; i++) { - if (tape->use_mouse) + if (tape->event_mask == GAME_EVENTS_MOUSE) { putFile8Bit(file, tape->pos[i].action[TAPE_ACTION_LX]); putFile8Bit(file, tape->pos[i].action[TAPE_ACTION_LY]); @@ -8105,7 +8154,6 @@ 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; @@ -8122,12 +8170,14 @@ void SaveTape(int nr) tape.file_version = FILE_VERSION_ACTUAL; tape.game_version = GAME_VERSION_ACTUAL; + tape.num_participating_players = 0; + // count number of participating players for (i = 0; i < MAX_PLAYERS; i++) if (tape.player_participates[i]) - num_participating_players++; + tape.num_participating_players++; - tape_pos_size = (tape.use_mouse ? 3 : num_participating_players) + 1; + tape_pos_size = getTapePosSize(&tape); info_chunk_size = 2 + (strlen(tape.level_identifier) + 1) + 2; body_chunk_size = tape_pos_size * tape.length;