X-Git-Url: https://git.artsoft.org/?a=blobdiff_plain;f=src%2Fgame_bd%2Fbd_caveengine.c;h=9df249eba1fba020e9ef53063c92c0aed0b8dbe7;hb=ac8ca29d0e4dec7b621225457f6eb5179655ea14;hp=03722b801ca1e62f9943f583685a8ea07d2745ea;hpb=cb248074b0649eb65f48a414935bf64b92b0fb9c;p=rocksndiamonds.git diff --git a/src/game_bd/bd_caveengine.c b/src/game_bd/bd_caveengine.c index 03722b80..9df249eb 100644 --- a/src/game_bd/bd_caveengine.c +++ b/src/game_bd/bd_caveengine.c @@ -126,9 +126,19 @@ void gd_cave_set_seconds_sound(GdCave *cave) } } +// returns true if the element can fall +static inline boolean el_can_fall(const int element) +{ + return (gd_elements[element & O_MASK].properties & P_CAN_FALL) != 0; +} + // play diamond or stone sound of given element. static void play_sound_of_element(GdCave *cave, GdElement element, int x, int y) { + // check if sound should be skipped for falling elements (and only be played on impact) + if (el_can_fall(element) && !use_bd_falling_sounds()) + return; + // stone and diamond fall sounds. switch (element) { @@ -449,7 +459,7 @@ static inline boolean rotates_ccw (const GdCave *cave, const int x, const int y) } // returns true if the element is a player -static inline boolean is_player(const GdCave *cave, const int x, const int y) +boolean is_player(const GdCave *cave, const int x, const int y) { return (gd_elements[get(cave, x, y) & O_MASK].properties & P_PLAYER) != 0; } @@ -467,6 +477,13 @@ static inline boolean can_be_hammered_dir(const GdCave *cave, const int x, const return (gd_elements[get_dir(cave, x, y, dir) & O_MASK].properties & P_CAN_BE_HAMMERED) != 0; } +// returns true if the element can be pushed +boolean can_be_pushed_dir(const GdCave *cave, const int x, const int y, + const GdDirection dir) +{ + return (gd_elements[get_dir(cave, x, y, dir) & O_MASK].properties & P_PUSHABLE) != 0; +} + // returns true if the element is explodable and explodes to space, for example the player static inline boolean is_first_stage_of_explosion(const GdCave *cave, const int x, const int y) { @@ -526,6 +543,9 @@ static inline boolean is_space_dir(const GdCave *cave, const int x, const int y, static inline void store_dir_buffer(GdCave *cave, const int x, const int y, const GdDirection dir) { + int old_x = x; + int old_y = y; + // raw values without range correction int raw_x = x + gd_dx[dir]; int raw_y = y + gd_dy[dir]; @@ -535,7 +555,18 @@ static inline void store_dir_buffer(GdCave *cave, const int x, const int y, cons int new_y = gety(cave, raw_x, raw_y); int new_dir = (dir > GD_MV_TWICE ? dir - GD_MV_TWICE : dir); - game_bd.game->dir_buffer[new_y][new_x] = new_dir; + // if tile is moving two steps at once, correct old position + if (dir > GD_MV_TWICE) + { + raw_x = x + gd_dx[new_dir]; + raw_y = y + gd_dy[new_dir]; + + old_x = getx(cave, raw_x, raw_y); + old_y = gety(cave, raw_x, raw_y); + } + + game_bd.game->dir_buffer_from[old_y][old_x] = new_dir; + game_bd.game->dir_buffer_to[new_y][new_x] = new_dir; } // store an element at the given position @@ -748,6 +779,13 @@ static void explode(GdCave *cave, int x, int y) creature_explode(cave, x, y, O_EXPLODE_1); break; + case O_ROCKET_1: + case O_ROCKET_2: + case O_ROCKET_3: + case O_ROCKET_4: + creature_explode(cave, x, y, O_EXPLODE_1); + break; + case O_BUTTER_1: case O_BUTTER_2: case O_BUTTER_3: @@ -780,6 +818,7 @@ static void explode(GdCave *cave, int x, int y) case O_PLAYER_BOMB: case O_PLAYER_GLUED: case O_PLAYER_STIRRING: + case O_PLAYER_ROCKET_LAUNCHER: case O_PLAYER_PNEUMATIC_LEFT: case O_PLAYER_PNEUMATIC_RIGHT: creature_explode(cave, x, y, O_EXPLODE_1); @@ -1363,6 +1402,9 @@ static boolean do_fall_try_magic(GdCave *cave, int x, int y, // active or non-active or anything, element falling in will always disappear store(cave, x, y, O_SPACE); + if (cave->magic_wall_breakscan && cave->amoeba_state == GD_AM_AWAKE) + cave->convert_amoeba_this_frame = TRUE; + return TRUE; } else @@ -1542,6 +1584,9 @@ void gd_cave_iterate(GdCave *cave, GdDirection player_move, boolean player_fire, gd_cave_clear_sounds(cave); + game_bd.player_moving = FALSE; + game_bd.player_snapping = FALSE; + // if diagonal movements not allowed, // horizontal movements have precedence. [BROADRIBB] if (!cave->diagonal_movements) @@ -1596,6 +1641,9 @@ void gd_cave_iterate(GdCave *cave, GdDirection player_move, boolean player_fire, // score collected this frame cave->score = 0; + // to implement buggy bd1 amoeba+magic wall behaviour + cave->convert_amoeba_this_frame = FALSE; + // suicide only kills the active player // player_x, player_y was set by the previous iterate routine, or the cave setup. // we must check if there is a player or not - he may have exploded or something like that @@ -1747,6 +1795,19 @@ void gd_cave_iterate(GdCave *cave, GdDirection player_move, boolean player_fire, move(cave, x, y, player_move, O_PLAYER_BOMB); break; + case O_ROCKET_LAUNCHER: + // if its a rocket launcher, remember he now has one. + // we do not change the "remains" and "what" variables, + // so that part of the code will be ineffective + gd_sound_play(cave, GD_S_BOMB_COLLECTING, what, x, y); + store_dir(cave, x, y, player_move, O_SPACE); + + if (player_fire) + store(cave, x, y, O_PLAYER_ROCKET_LAUNCHER); + else + move(cave, x, y, player_move, O_PLAYER_ROCKET_LAUNCHER); + break; + case O_POT: // we do not change the "remains" and "what" variables, // so that part of the code will be ineffective @@ -1791,15 +1852,25 @@ void gd_cave_iterate(GdCave *cave, GdDirection player_move, boolean player_fire, // if snapping anything and we have snapping explosions set. // but these is not true for pushing. if (remains == O_SPACE && player_fire && !push) + { remains = cave->snap_element; + game_bd.player_snapping = TRUE; + } + if (remains != O_SPACE || player_fire) + { // if any other element than space, player cannot move. // also if pressing fire, will not move. store_dir(cave, x, y, player_move, remains); + } else + { // if space remains there, the player moves. move(cave, x, y, player_move, O_PLAYER); + + game_bd.player_moving = TRUE; + } } } break; @@ -1888,6 +1959,98 @@ void gd_cave_iterate(GdCave *cave, GdDirection player_move, boolean player_fire, } break; + case O_PLAYER_ROCKET_LAUNCHER: + // much simpler; cannot snap-push stones + if (cave->kill_player) + { + explode(cave, x, y); + break; + } + + cave->player_seen_ago = 0; + // bd4 intermission caves have many players. so if one of them has exited, + // do not change the flag anymore. so this if () is needed + if (cave->player_state != GD_PL_EXITED) + cave->player_state = GD_PL_LIVING; + + // firing a rocket? + if (player_move != GD_MV_STILL) + { + // if the player does not move, nothing to do + GdElement what = get_dir(cave, x, y, player_move); + GdElement remains = what; + + // to fire a rocket, diagonal movement should not be allowed. + // so either x or y must be zero + if (player_fire) + { + // placing a rocket into empty space + if (is_space_dir(cave, x, y, player_move)) + { + switch (player_move) + { + case GD_MV_RIGHT: + store_dir(cave, x, y, player_move, O_ROCKET_1); + if (!cave->infinite_rockets) + store(cave, x, y, O_PLAYER); + break; + + case GD_MV_UP: + store_dir(cave, x, y, player_move, O_ROCKET_2); + if (!cave->infinite_rockets) + store(cave, x, y, O_PLAYER); + break; + + case GD_MV_LEFT: + store_dir(cave, x, y, player_move, O_ROCKET_3); + if (!cave->infinite_rockets) + store(cave, x, y, O_PLAYER); + break; + + case GD_MV_DOWN: + store_dir(cave, x, y, player_move, O_ROCKET_4); + if (!cave->infinite_rockets) + store(cave, x, y, O_PLAYER); + break; + + default: + // cannot fire in other directions + break; + } + + gd_sound_play(cave, GD_S_BOMB_PLACING, O_BOMB, x, y); + } + + // a player with rocket launcher cannot snap elements, so stop here + break; + } + + // pushing and collecting + // if we are 'eating' a teleporter, and the function returns true + // (teleporting worked), break here + if (what == O_TELEPORTER && do_teleporter(cave, x, y, player_move)) + break; + + // player fire is false... + if (do_push(cave, x, y, player_move, FALSE)) + { + remains = O_SPACE; + } + else + { + // get element. if cannot get, player_get_element will return the same + remains = player_get_element(cave, what, x, y); + } + + // if something changed, OR there is space, move. + if (remains != what || remains == O_SPACE) + { + // if anything changed, apply the change. + move(cave, x, y, player_move, O_PLAYER_ROCKET_LAUNCHER); + } + } + break; + case O_PLAYER_STIRRING: if (cave->kill_player) { @@ -2734,6 +2897,13 @@ void gd_cave_iterate(GdCave *cave, GdDirection player_move, boolean player_fire, // ============================================================================ case O_AMOEBA: + // emulating BD1 amoeba+magic wall bug + if (cave->convert_amoeba_this_frame && amoeba_found_enclosed) + { + store(cave, x, y, cave->amoeba_enclosed_effect); + break; + } + amoeba_count++; switch (cave->amoeba_state) { @@ -3169,6 +3339,38 @@ void gd_cave_iterate(GdCave *cave, GdDirection player_move, boolean player_fire, } break; + // ============================================================================ + // R O C K E T S + // ============================================================================ + + case O_ROCKET_1: + if (is_space_dir(cave, x, y, GD_MV_RIGHT)) + move(cave, x, y, GD_MV_RIGHT, O_ROCKET_1); + else + explode(cave, x, y); + break; + + case O_ROCKET_2: + if (is_space_dir(cave, x, y, GD_MV_UP)) + move(cave, x, y, GD_MV_UP, O_ROCKET_2); + else + explode(cave, x, y); + break; + + case O_ROCKET_3: + if (is_space_dir(cave, x, y, GD_MV_LEFT)) + move(cave, x, y, GD_MV_LEFT, O_ROCKET_3); + else + explode(cave, x, y); + break; + + case O_ROCKET_4: + if (is_space_dir(cave, x, y, GD_MV_DOWN)) + move(cave, x, y, GD_MV_DOWN, O_ROCKET_4); + else + explode(cave, x, y); + break; + // ============================================================================ // S I M P L E C H A N G I N G; E X P L O S I O N S // ============================================================================ @@ -3458,7 +3660,7 @@ void gd_cave_iterate(GdCave *cave, GdDirection player_move, boolean player_fire, { if ((amoeba_count > 0 && cave->amoeba_state == GD_AM_AWAKE) || (amoeba_2_count > 0 && cave->amoeba_2_state == GD_AM_AWAKE)) - play_sound_of_element(cave, O_AMOEBA, x, y); + play_sound_of_element(cave, O_AMOEBA, -1, -1); } // pneumatic hammer sound - overrides everything. @@ -3568,7 +3770,8 @@ void gd_cave_iterate(GdCave *cave, GdDirection player_move, boolean player_fire, // magic wall; if active&wait or not wait for hatching if (cave->magic_wall_state == GD_MW_ACTIVE && - (cave->hatched || !cave->magic_timer_wait_for_hatching)) + (cave->hatched || !cave->magic_timer_wait_for_hatching) && + !(cave->magic_wall_time == 0 && cave->magic_timer_zero_is_infinite)) { cave->magic_wall_time -= cave->speed; if (cave->magic_wall_time < 0)