X-Git-Url: https://git.artsoft.org/?a=blobdiff_plain;f=src%2Fgame_bd%2Fbd_caveengine.c;h=4d528a4100830ef34ead812e8255cb300e896e52;hb=27f82f7887886eee23bdf5da0f4e248b46d7f257;hp=5f97940a9b6af721de585fb51ede95fcdc455d1e;hpb=c94cdac2a1cda58ac0e3640e14d3635b797c597a;p=rocksndiamonds.git diff --git a/src/game_bd/bd_caveengine.c b/src/game_bd/bd_caveengine.c index 5f97940a..4d528a41 100644 --- a/src/game_bd/bd_caveengine.c +++ b/src/game_bd/bd_caveengine.c @@ -526,6 +526,19 @@ static inline boolean is_space_dir(const GdCave *cave, const int x, const int y, return (e == O_SPACE || e == O_LAVA); } +static inline void store_dir_buffer(GdCave *cave, const int x, const int y, const GdDirection dir) +{ + /* raw values without range correction */ + int raw_x = x + gd_dx[dir]; + int raw_y = y + gd_dy[dir]; + /* final values with range correction */ + int new_x = getx(cave, raw_x, raw_y); + 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; +} + /* store an element at the given position */ static inline void store(GdCave *cave, const int x, const int y, const GdElement element) { @@ -551,6 +564,7 @@ static inline void store_sc(GdCave *cave, const int x, const int y, const GdElem static inline void store_dir(GdCave *cave, const int x, const int y, const GdDirection dir, const GdElement element) { + store_dir_buffer(cave, x, y, dir); store(cave, x + gd_dx[dir], y + gd_dy[dir], element | SCANNED); } @@ -558,6 +572,7 @@ static inline void store_dir(GdCave *cave, const int x, const int y, static inline void store_dir_no_scanned(GdCave *cave, const int x, const int y, const GdDirection dir, const GdElement element) { + store_dir_buffer(cave, x, y, dir); store(cave, x + gd_dx[dir], y + gd_dy[dir], element); } @@ -1332,10 +1347,10 @@ static boolean do_fall_try_magic(GdCave *cave, int x, int y, { play_sound_of_element(cave, O_DIAMOND, x, y); /* always play diamond sound */ - if (cave->magic_wall_state==GD_MW_DORMANT) + if (cave->magic_wall_state == GD_MW_DORMANT) cave->magic_wall_state = GD_MW_ACTIVE; - if (cave->magic_wall_state==GD_MW_ACTIVE && + if (cave->magic_wall_state == GD_MW_ACTIVE && is_space_dir(cave, x, y, GD_MV_TWICE+fall_dir)) { /* if magic wall active and place underneath, it turns element @@ -1594,7 +1609,7 @@ void gd_cave_iterate(GdCave *cave, GdDirection player_move, boolean player_fire, for (x = 0; x < cave->w; x++) { /* timer for the cell > 0? */ - if (cave->hammered_reappear[y][x]>0) + if (cave->hammered_reappear[y][x] > 0) { /* decrease timer */ cave->hammered_reappear[y][x]--; @@ -1665,7 +1680,7 @@ void gd_cave_iterate(GdCave *cave, GdDirection player_move, boolean player_fire, 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) + if (cave->player_state != GD_PL_EXITED) cave->player_state = GD_PL_LIVING; /* check for pneumatic hammer things */ @@ -1709,8 +1724,11 @@ void gd_cave_iterate(GdCave *cave, GdDirection player_move, boolean player_fire, /* try to push element; if successful, break */ push = do_push(cave, x, y, player_move, player_fire); if (push) + { remains = O_SPACE; + } else + { switch (what) { case O_BOMB: @@ -1758,9 +1776,10 @@ void gd_cave_iterate(GdCave *cave, GdDirection player_move, boolean player_fire, default: /* get element - process others. if cannot get, player_get_element will return the same */ - remains = player_get_element (cave, what, x, y); + remains = player_get_element(cave, what, x, y); break; } + } if (remains != what || remains == O_SPACE) { @@ -1825,7 +1844,9 @@ void gd_cave_iterate(GdCave *cave, GdDirection player_move, boolean player_fire, /* player fire is false... */ if (do_push(cave, x, y, player_move, FALSE)) + { remains = O_SPACE; + } else { switch (what) @@ -1835,10 +1856,10 @@ void gd_cave_iterate(GdCave *cave, GdDirection player_move, boolean player_fire, player_move parameter) */ /* only allow changing direction if the new dir is not diagonal */ if (cave->gravity_switch_active && - (player_move==GD_MV_LEFT || - player_move==GD_MV_RIGHT || - player_move==GD_MV_UP || - player_move==GD_MV_DOWN)) + (player_move == GD_MV_LEFT || + player_move == GD_MV_RIGHT || + player_move == GD_MV_UP || + player_move == GD_MV_DOWN)) { gd_sound_play(cave, GD_S_SWITCH_GRAVITY, what, x, y); cave->gravity_will_change = @@ -1877,7 +1898,7 @@ void gd_cave_iterate(GdCave *cave, GdDirection player_move, boolean player_fire, 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) + if (cave->player_state != GD_PL_EXITED) cave->player_state = GD_PL_LIVING; if (player_fire) @@ -1900,7 +1921,7 @@ void gd_cave_iterate(GdCave *cave, GdDirection player_move, boolean player_fire, } cave->player_seen_ago = 0; - if (cave->player_state!=GD_PL_EXITED) + if (cave->player_state != GD_PL_EXITED) cave->player_state = GD_PL_LIVING; /* if hammering time is up, becomes a normal player again. */ @@ -2239,7 +2260,7 @@ void gd_cave_iterate(GdCave *cave, GdDirection player_move, boolean player_fire, { const GdDirection *creature_move; boolean ccw = rotates_ccw(cave, x, y); /* check if default is counterclockwise */ - GdElement base; /* base element number (which is like O_***_1) */ + GdElement base = -1; /* base element number (which is like O_***_1) */ int dir, dirn, dirp; /* direction */ if (get(cave, x, y) >= O_FIREFLY_1 && @@ -2258,7 +2279,7 @@ void gd_cave_iterate(GdCave *cave, GdDirection player_move, boolean player_fire, get(cave, x, y) <= O_ALT_BUTTER_4) base = O_ALT_BUTTER_1; - dir = get(cave, x, y)-base; /* facing where */ + dir = get(cave, x, y) - base; /* facing where */ creature_move = cave->creatures_backwards ? creature_chdir : creature_dir; /* now change direction if backwards */ @@ -2615,7 +2636,7 @@ void gd_cave_iterate(GdCave *cave, GdDirection player_move, boolean player_fire, /* is space over the bladder? */ if (is_space_dir(cave, x, y, opposite[grav_compat])) { - if (get(cave, x, y)==O_BLADDER_8) + if (get(cave, x, y) == O_BLADDER_8) { /* if it is a bladder 8, really move up */ move(cave, x, y, opposite[grav_compat], O_BLADDER_1); @@ -2733,7 +2754,7 @@ void gd_cave_iterate(GdCave *cave, GdDirection player_move, boolean player_fire, } /* if alive, check in which dir to grow (or not) */ - if (cave->amoeba_state==GD_AM_AWAKE) + if (cave->amoeba_state == GD_AM_AWAKE) { if (g_rand_int_range(cave->random, 0, 1000000) < cave->amoeba_growth_prob) { @@ -2897,8 +2918,8 @@ void gd_cave_iterate(GdCave *cave, GdDirection player_move, boolean player_fire, if (((get(cave, x, y) == O_H_EXPANDING_WALL || get(cave, x, y) == O_H_EXPANDING_STEEL_WALL) && !cave->expanding_wall_changed) || - ((get(cave, x, y)==O_V_EXPANDING_WALL || - get(cave, x, y)==O_V_EXPANDING_STEEL_WALL) && + ((get(cave, x, y) == O_V_EXPANDING_WALL || + get(cave, x, y) == O_V_EXPANDING_STEEL_WALL) && cave->expanding_wall_changed)) { if (is_space_dir(cave, x, y, GD_MV_LEFT)) @@ -3023,13 +3044,13 @@ void gd_cave_iterate(GdCave *cave, GdDirection player_move, boolean player_fire, store_dir(cave, x, y, oppos, O_BLADDER_1); play_sound_of_element(cave, O_SLIME, x, y); } - else if (get_dir(cave, x, y, grav)==O_FLYING_STONE) + else if (get_dir(cave, x, y, grav) == O_FLYING_STONE) { store_dir(cave, x, y, grav, O_SPACE); store_dir(cave, x, y, oppos, O_FLYING_STONE_F); play_sound_of_element(cave, O_SLIME, x, y); } - else if (get_dir(cave, x, y, grav)==O_FLYING_DIAMOND) + else if (get_dir(cave, x, y, grav) == O_FLYING_DIAMOND) { store_dir(cave, x, y, grav, O_SPACE); store_dir(cave, x, y, oppos, O_FLYING_DIAMOND_F); @@ -3346,7 +3367,7 @@ void gd_cave_iterate(GdCave *cave, GdDirection player_move, boolean player_fire, /* this loop finds the coordinates of the player. needed for scrolling and chasing stone.*/ /* but we only do this, if a living player was found. if not yet, the setup routine coordinates are used */ - if (cave->player_state==GD_PL_LIVING) + if (cave->player_state == GD_PL_LIVING) { if (cave->active_is_first_found) {