X-Git-Url: https://git.artsoft.org/?a=blobdiff_plain;f=src%2Ffiles.c;h=d34f3fe30b298172ced69349277af3bff81e7845;hb=def7303f9655be9d5fba4c313c61544fa284af2d;hp=2ca9976684473f08bf0f9cbf1fe4954e79b0b1c5;hpb=5ac5eb15bb34f4c10a7146f05eae315d2b7cc12f;p=rocksndiamonds.git diff --git a/src/files.c b/src/files.c index 2ca99766..d34f3fe3 100644 --- a/src/files.c +++ b/src/files.c @@ -6792,8 +6792,8 @@ 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++) + 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 @@ -7623,9 +7623,10 @@ static int getTapePosSize(struct TapeInfo *tape) { int tape_pos_size = 0; - if (!tape->use_mouse) + if (tape->use_key_actions) tape_pos_size += tape->num_participating_players; - else + + if (tape->use_mouse_actions) tape_pos_size += 3; // x and y position and mouse button mask tape_pos_size += 1; // tape action delay value @@ -7633,6 +7634,27 @@ static int getTapePosSize(struct TapeInfo *tape) return tape_pos_size; } +static void setTapeActionFlags(struct TapeInfo *tape, int value) +{ + tape->use_key_actions = FALSE; + tape->use_mouse_actions = FALSE; + + if (value != TAPE_USE_MOUSE_ACTIONS_ONLY) + tape->use_key_actions = TRUE; + + if (value != TAPE_USE_KEY_ACTIONS_ONLY) + tape->use_mouse_actions = TRUE; +} + +static int getTapeActionValue(struct TapeInfo *tape) +{ + return (tape->use_key_actions && + tape->use_mouse_actions ? TAPE_USE_KEY_AND_MOUSE_ACTIONS : + tape->use_key_actions ? TAPE_USE_KEY_ACTIONS_ONLY : + tape->use_mouse_actions ? TAPE_USE_MOUSE_ACTIONS_ONLY : + TAPE_ACTIONS_DEFAULT); +} + static int LoadTape_VERS(File *file, int chunk_size, struct TapeInfo *tape) { tape->file_version = getFileVersion(file); @@ -7668,7 +7690,7 @@ static int LoadTape_HEAD(File *file, int chunk_size, struct TapeInfo *tape) } } - tape->use_mouse = (getFile8Bit(file) == 1 ? TRUE : FALSE); + setTapeActionFlags(tape, getFile8Bit(file)); ReadUnusedBytesFromFile(file, TAPE_CHUNK_HEAD_UNUSED); @@ -7728,15 +7750,7 @@ static int LoadTape_BODY(File *file, int chunk_size, struct TapeInfo *tape) 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 + if (tape->use_key_actions) { for (j = 0; j < MAX_PLAYERS; j++) { @@ -7747,6 +7761,13 @@ static int LoadTape_BODY(File *file, int chunk_size, struct TapeInfo *tape) } } + if (tape->use_mouse_actions) + { + 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].delay = getFile8Bit(file); if (tape->file_version == FILE_VERSION_1_0) @@ -8070,7 +8091,7 @@ static void SaveTape_HEAD(FILE *file, struct TapeInfo *tape) putFile8Bit(file, store_participating_players); - putFile8Bit(file, (tape->use_mouse ? 1 : 0)); + putFile8Bit(file, getTapeActionValue(tape)); // unused bytes not at the end here for 4-byte alignment of engine_version WriteUnusedBytesToFile(file, TAPE_CHUNK_HEAD_UNUSED); @@ -8097,19 +8118,20 @@ static void SaveTape_BODY(FILE *file, struct TapeInfo *tape) 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 + if (tape->use_key_actions) { for (j = 0; j < MAX_PLAYERS; j++) if (tape->player_participates[j]) putFile8Bit(file, tape->pos[i].action[j]); } + if (tape->use_mouse_actions) + { + 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]); + } + putFile8Bit(file, tape->pos[i].delay); } }