X-Git-Url: https://git.artsoft.org/?a=blobdiff_plain;f=src%2Fgame.c;h=30af0fcbbd7a50affb604b234f7da58d87e9e1bd;hb=842f9050c68d9c9f0741e444a052e00cf81ee90b;hp=99cbfbbdfdf76adb0848ece543ecf5eda3ddf29c;hpb=c9bb6e0a6eecbf84320be79b121bd957a938a08c;p=rocksndiamonds.git diff --git a/src/game.c b/src/game.c index 99cbfbbd..30af0fcb 100644 --- a/src/game.c +++ b/src/game.c @@ -96,6 +96,55 @@ #define GET_NEW_MOVE_DELAY(e) ( (element_info[e].move_delay_fixed) + \ RND(element_info[e].move_delay_random)) +#define ELEMENT_CAN_ENTER_FIELD_GENERIC(e, x, y, condition) \ + (IN_LEV_FIELD(x, y) && (IS_FREE(x, y) || \ + (condition) || \ + (DONT_COLLIDE_WITH(e) && \ + IS_FREE_OR_PLAYER(x, y)))) + +#define ELEMENT_CAN_ENTER_FIELD_GENERIC_2(x, y, condition) \ + (IN_LEV_FIELD(x, y) && (IS_FREE(x, y) || \ + (condition))) + +#define ELEMENT_CAN_ENTER_FIELD(e, x, y) \ + ELEMENT_CAN_ENTER_FIELD_GENERIC(e, x, y, 0) + +#define ELEMENT_CAN_ENTER_FIELD_OR_ACID(e, x, y) \ + ELEMENT_CAN_ENTER_FIELD_GENERIC(e, x, y, (Feld[x][y] == EL_ACID)) + +#define ELEMENT_CAN_ENTER_FIELD_OR_ACID_2(x, y) \ + ELEMENT_CAN_ENTER_FIELD_GENERIC_2(x, y, (Feld[x][y] == EL_ACID)) + +#define ENEMY_CAN_ENTER_FIELD(x, y) (IN_LEV_FIELD(x, y) && IS_FREE(x, y)) + +#define YAMYAM_CAN_ENTER_FIELD(x, y) \ + (IN_LEV_FIELD(x, y) && (IS_FREE_OR_PLAYER(x, y) || \ + Feld[x][y] == EL_DIAMOND)) + +#define DARK_YAMYAM_CAN_ENTER_FIELD(x, y) \ + (IN_LEV_FIELD(x, y) && (IS_FREE_OR_PLAYER(x, y) || \ + IS_FOOD_DARK_YAMYAM(Feld[x][y]))) + +#define PACMAN_CAN_ENTER_FIELD(x, y) \ + (IN_LEV_FIELD(x, y) && (IS_FREE_OR_PLAYER(x, y) || \ + IS_AMOEBOID(Feld[x][y]))) + +#define PIG_CAN_ENTER_FIELD(x, y) \ + (IN_LEV_FIELD(x, y) && (IS_FREE(x, y) || \ + IS_FOOD_PIG(Feld[x][y]))) + +#define PENGUIN_CAN_ENTER_FIELD(x, y) \ + (IN_LEV_FIELD(x, y) && (IS_FREE(x, y) || \ + IS_FOOD_PENGUIN(Feld[x][y]) || \ + Feld[x][y] == EL_EXIT_OPEN || \ + Feld[x][y] == EL_ACID)) + +#define MOLE_CAN_ENTER_FIELD(x, y, condition) \ + (IN_LEV_FIELD(x, y) && (IS_FREE(x, y) || (condition))) + +#define IN_LEV_FIELD_AND_IS_FREE(x, y) (IN_LEV_FIELD(x, y) && IS_FREE(x, y)) +#define IN_LEV_FIELD_AND_NOT_FREE(x, y) (IN_LEV_FIELD(x, y) && !IS_FREE(x, y)) + /* game button identifiers */ #define GAME_CTRL_ID_STOP 0 #define GAME_CTRL_ID_PAUSE 1 @@ -114,6 +163,8 @@ static void CloseAllOpenTimegates(void); static void CheckGravityMovement(struct PlayerInfo *); static void KillHeroUnlessProtected(int, int); +static void CheckTriggeredElementChange(int, int); +static void CheckPlayerElementChange(int, int, int, int); static void ChangeElementDoIt(int, int, int); static void PlaySoundLevel(int, int, int); @@ -302,8 +353,13 @@ static struct ChangingElementInfo changing_element_list[] = }; static struct ChangingElementInfo changing_element[MAX_NUM_ELEMENTS]; +static unsigned long trigger_events[MAX_NUM_ELEMENTS]; #define IS_AUTO_CHANGING(e) (changing_element[e].base_element != EL_UNDEFINED) +#define IS_JUST_CHANGING(x, y) (ChangeDelay[x][y] != 0) +#define IS_CHANGING(x, y) (IS_AUTO_CHANGING(Feld[x][y]) || \ + IS_JUST_CHANGING(x, y)) +#define TRIGGERS_BY_COLLECTING(e) (trigger_events[e] & CE_OTHER_COLLECTING) void GetPlayerConfig() @@ -684,6 +740,43 @@ static void InitGameEngine() changing_element[element].change_delay = (change->delay_fixed * change->delay_frames); } + + /* initialize trigger events information */ + for (i=0; iactual_frame_counter = 0; player->last_move_dir = MV_NO_MOVING; - player->is_moving = FALSE; player->is_moving = FALSE; player->is_waiting = FALSE; @@ -842,6 +934,7 @@ void InitGame() AmoebaNr[x][y] = 0; JustStopped[x][y] = 0; Stop[x][y] = FALSE; + Pushed[x][y] = FALSE; ExplodePhase[x][y] = 0; ExplodeField[x][y] = EX_NO_EXPLOSION; @@ -1146,7 +1239,9 @@ void InitMovDir(int x, int y) { if (element_info[element].move_direction_initial != MV_NO_MOVING) MovDir[x][y] = element_info[element].move_direction_initial; - else if (element_info[element].move_pattern == MV_ALL_DIRECTIONS) + else if (element_info[element].move_pattern == MV_ALL_DIRECTIONS || + element_info[element].move_pattern == MV_TURNING_LEFT || + element_info[element].move_pattern == MV_TURNING_RIGHT) MovDir[x][y] = 1 << RND(4); else if (element_info[element].move_pattern == MV_HORIZONTAL) MovDir[x][y] = (RND(2) ? MV_LEFT : MV_RIGHT); @@ -1439,8 +1534,10 @@ static void ResetGfxAnimation(int x, int y) void InitMovingField(int x, int y, int direction) { int element = Feld[x][y]; - int newx = x + (direction == MV_LEFT ? -1 : direction == MV_RIGHT ? +1 : 0); - int newy = y + (direction == MV_UP ? -1 : direction == MV_DOWN ? +1 : 0); + int dx = (direction == MV_LEFT ? -1 : direction == MV_RIGHT ? +1 : 0); + int dy = (direction == MV_UP ? -1 : direction == MV_DOWN ? +1 : 0); + int newx = x + dx; + int newy = y + dy; if (!JustStopped[x][y] || direction != MovDir[x][y]) ResetGfxAnimation(x, y); @@ -1534,6 +1631,7 @@ static void RemoveField(int x, int y) MovDir[x][y] = 0; MovDelay[x][y] = 0; ChangeDelay[x][y] = 0; + Pushed[x][y] = FALSE; } void RemoveMovingField(int x, int y) @@ -2008,6 +2106,8 @@ void Bang(int x, int y) Explode(x, y, EX_PHASE_START, EX_NORMAL); break; } + + CheckTriggeredElementChange(element, CE_OTHER_EXPLODING); } void SplashAcid(int x, int y) @@ -2372,14 +2472,7 @@ void Impact(int x, int y) DrawLevelField(x, y); } -#if 1 if (impact && CAN_EXPLODE_IMPACT(element)) -#else - if ((element == EL_BOMB || - element == EL_SP_DISK_ORANGE || - element == EL_DX_SUPABOMB) && - (lastline || object_hit)) /* element is bomb */ -#endif { Bang(x, y); return; @@ -2416,11 +2509,7 @@ void Impact(int x, int y) return; } -#if 1 if (object_hit) /* check which object was hit */ -#else - if (!lastline && object_hit) /* check which object was hit */ -#endif { if (CAN_PASS_MAGIC_WALL(element) && (smashed == EL_MAGIC_WALL || @@ -2478,35 +2567,15 @@ void Impact(int x, int y) Bang(x, y + 1); return; } -#if 1 else if (CAN_SMASH_EVERYTHING(element)) -#else - else if (element == EL_ROCK || - element == EL_SP_ZONK || - element == EL_BD_ROCK) -#endif { if (IS_CLASSIC_ENEMY(smashed) || -#if 1 CAN_EXPLODE_SMASHED(smashed)) -#else - smashed == EL_BOMB || - smashed == EL_SP_DISK_ORANGE || - smashed == EL_DX_SUPABOMB || - smashed == EL_SATELLITE || - smashed == EL_PIG || - smashed == EL_DRAGON || - smashed == EL_MOLE) -#endif { Bang(x, y + 1); return; } -#if 1 else if (!IS_MOVING(x, y + 1) && !IS_BLOCKED(x, y + 1)) -#else - else if (!IS_MOVING(x, y + 1)) -#endif { if (smashed == EL_LAMP || smashed == EL_LAMP_ACTIVE) @@ -2529,11 +2598,7 @@ void Impact(int x, int y) } else if (smashed == EL_DIAMOND) { -#if 1 Feld[x][y + 1] = EL_DIAMOND_BREAKING; -#else - Feld[x][y + 1] = EL_EMPTY; -#endif PlaySoundLevel(x, y, SND_DIAMOND_BREAKING); return; } @@ -2603,7 +2668,9 @@ void TurnRound(int x, int y) { MV_UP, MV_DOWN, MV_LEFT }, { 0, 0, 0 }, { MV_LEFT, MV_RIGHT, MV_DOWN }, - { 0,0,0 }, { 0,0,0 }, { 0,0,0 }, + { 0, 0, 0 }, + { 0, 0, 0 }, + { 0, 0, 0 }, { MV_RIGHT, MV_LEFT, MV_UP } }; @@ -2622,15 +2689,15 @@ void TurnRound(int x, int y) int right_x = x + right_dx, right_y = y + right_dy; int move_x = x + move_dx, move_y = y + move_dy; + int xx, yy; + if (element == EL_BUG || element == EL_BD_BUTTERFLY) { TestIfBadThingTouchesOtherBadThing(x, y); - if (IN_LEV_FIELD(right_x, right_y) && - IS_FREE(right_x, right_y)) + if (ENEMY_CAN_ENTER_FIELD(right_x, right_y)) MovDir[x][y] = right_dir; - else if (!IN_LEV_FIELD(move_x, move_y) || - !IS_FREE(move_x, move_y)) + else if (!ENEMY_CAN_ENTER_FIELD(move_x, move_y)) MovDir[x][y] = left_dir; if (element == EL_BUG && MovDir[x][y] != old_move_dir) @@ -2643,15 +2710,14 @@ void TurnRound(int x, int y) { TestIfBadThingTouchesOtherBadThing(x, y); - if (IN_LEV_FIELD(left_x, left_y) && - IS_FREE(left_x, left_y)) + if (ENEMY_CAN_ENTER_FIELD(left_x, left_y)) MovDir[x][y] = left_dir; - else if (!IN_LEV_FIELD(move_x, move_y) || - !IS_FREE(move_x, move_y)) + else if (!ENEMY_CAN_ENTER_FIELD(move_x, move_y)) MovDir[x][y] = right_dir; if ((element == EL_SPACESHIP || - element == EL_SP_SNIKSNAK || element == EL_SP_ELECTRON) + element == EL_SP_SNIKSNAK || + element == EL_SP_ELECTRON) && MovDir[x][y] != old_move_dir) MovDelay[x][y] = 9; else if (element == EL_BD_FIREFLY) /* && MovDir[x][y] == right_dir) */ @@ -2659,16 +2725,8 @@ void TurnRound(int x, int y) } else if (element == EL_YAMYAM) { - boolean can_turn_left = FALSE, can_turn_right = FALSE; - - if (IN_LEV_FIELD(left_x, left_y) && - (IS_FREE_OR_PLAYER(left_x, left_y) || - Feld[left_x][left_y] == EL_DIAMOND)) - can_turn_left = TRUE; - if (IN_LEV_FIELD(right_x, right_y) && - (IS_FREE_OR_PLAYER(right_x, right_y) || - Feld[right_x][right_y] == EL_DIAMOND)) - can_turn_right = TRUE; + boolean can_turn_left = YAMYAM_CAN_ENTER_FIELD(left_x, left_y); + boolean can_turn_right = YAMYAM_CAN_ENTER_FIELD(right_x, right_y); if (can_turn_left && can_turn_right) MovDir[x][y] = (RND(3) ? (RND(2) ? left_dir : right_dir) : back_dir); @@ -2679,20 +2737,12 @@ void TurnRound(int x, int y) else MovDir[x][y] = back_dir; - MovDelay[x][y] = 16+16*RND(3); + MovDelay[x][y] = 16 + 16 * RND(3); } else if (element == EL_DARK_YAMYAM) { - boolean can_turn_left = FALSE, can_turn_right = FALSE; - - if (IN_LEV_FIELD(left_x, left_y) && - (IS_FREE_OR_PLAYER(left_x, left_y) || - IS_FOOD_DARK_YAMYAM(Feld[left_x][left_y]))) - can_turn_left = TRUE; - if (IN_LEV_FIELD(right_x, right_y) && - (IS_FREE_OR_PLAYER(right_x, right_y) || - IS_FOOD_DARK_YAMYAM(Feld[right_x][right_y]))) - can_turn_right = TRUE; + boolean can_turn_left = DARK_YAMYAM_CAN_ENTER_FIELD(left_x, left_y); + boolean can_turn_right = DARK_YAMYAM_CAN_ENTER_FIELD(right_x, right_y); if (can_turn_left && can_turn_right) MovDir[x][y] = (RND(3) ? (RND(2) ? left_dir : right_dir) : back_dir); @@ -2703,20 +2753,12 @@ void TurnRound(int x, int y) else MovDir[x][y] = back_dir; - MovDelay[x][y] = 16+16*RND(3); + MovDelay[x][y] = 16 + 16 * RND(3); } else if (element == EL_PACMAN) { - boolean can_turn_left = FALSE, can_turn_right = FALSE; - - if (IN_LEV_FIELD(left_x, left_y) && - (IS_FREE_OR_PLAYER(left_x, left_y) || - IS_AMOEBOID(Feld[left_x][left_y]))) - can_turn_left = TRUE; - if (IN_LEV_FIELD(right_x, right_y) && - (IS_FREE_OR_PLAYER(right_x, right_y) || - IS_AMOEBOID(Feld[right_x][right_y]))) - can_turn_right = TRUE; + boolean can_turn_left = PACMAN_CAN_ENTER_FIELD(left_x, left_y); + boolean can_turn_right = PACMAN_CAN_ENTER_FIELD(right_x, right_y); if (can_turn_left && can_turn_right) MovDir[x][y] = (RND(3) ? (RND(2) ? left_dir : right_dir) : back_dir); @@ -2727,56 +2769,45 @@ void TurnRound(int x, int y) else MovDir[x][y] = back_dir; - MovDelay[x][y] = 6+RND(40); + MovDelay[x][y] = 6 + RND(40); } else if (element == EL_PIG) { - boolean can_turn_left = FALSE, can_turn_right = FALSE, can_move_on = FALSE; - boolean should_turn_left = FALSE, should_turn_right = FALSE; - boolean should_move_on = FALSE; + boolean can_turn_left = PIG_CAN_ENTER_FIELD(left_x, left_y); + boolean can_turn_right = PIG_CAN_ENTER_FIELD(right_x, right_y); + boolean can_move_on = PIG_CAN_ENTER_FIELD(move_x, move_y); + boolean should_turn_left, should_turn_right, should_move_on; int rnd_value = 24; int rnd = RND(rnd_value); - if (IN_LEV_FIELD(left_x, left_y) && - (IS_FREE(left_x, left_y) || IS_FOOD_PIG(Feld[left_x][left_y]))) - can_turn_left = TRUE; - if (IN_LEV_FIELD(right_x, right_y) && - (IS_FREE(right_x, right_y) || IS_FOOD_PIG(Feld[right_x][right_y]))) - can_turn_right = TRUE; - if (IN_LEV_FIELD(move_x, move_y) && - (IS_FREE(move_x, move_y) || IS_FOOD_PIG(Feld[move_x][move_y]))) - can_move_on = TRUE; - - if (can_turn_left && - (!can_move_on || - (IN_LEV_FIELD(x+back_dx+left_dx, y+back_dy+left_dy) && - !IS_FREE(x+back_dx+left_dx, y+back_dy+left_dy)))) - should_turn_left = TRUE; - if (can_turn_right && - (!can_move_on || - (IN_LEV_FIELD(x+back_dx+right_dx, y+back_dy+right_dy) && - !IS_FREE(x+back_dx+right_dx, y+back_dy+right_dy)))) - should_turn_right = TRUE; - if (can_move_on && - (!can_turn_left || !can_turn_right || - (IN_LEV_FIELD(x+move_dx+left_dx, y+move_dy+left_dy) && - !IS_FREE(x+move_dx+left_dx, y+move_dy+left_dy)) || - (IN_LEV_FIELD(x+move_dx+right_dx, y+move_dy+right_dy) && - !IS_FREE(x+move_dx+right_dx, y+move_dy+right_dy)))) - should_move_on = TRUE; + should_turn_left = (can_turn_left && + (!can_move_on || + IN_LEV_FIELD_AND_NOT_FREE(x + back_dx + left_dx, + y + back_dy + left_dy))); + should_turn_right = (can_turn_right && + (!can_move_on || + IN_LEV_FIELD_AND_NOT_FREE(x + back_dx + right_dx, + y + back_dy + right_dy))); + should_move_on = (can_move_on && + (!can_turn_left || + !can_turn_right || + IN_LEV_FIELD_AND_NOT_FREE(x + move_dx + left_dx, + y + move_dy + left_dy) || + IN_LEV_FIELD_AND_NOT_FREE(x + move_dx + right_dx, + y + move_dy + right_dy))); if (should_turn_left || should_turn_right || should_move_on) { if (should_turn_left && should_turn_right && should_move_on) - MovDir[x][y] = (rnd < rnd_value/3 ? left_dir : - rnd < 2*rnd_value/3 ? right_dir : + MovDir[x][y] = (rnd < rnd_value / 3 ? left_dir : + rnd < 2 * rnd_value / 3 ? right_dir : old_move_dir); else if (should_turn_left && should_turn_right) - MovDir[x][y] = (rnd < rnd_value/2 ? left_dir : right_dir); + MovDir[x][y] = (rnd < rnd_value / 2 ? left_dir : right_dir); else if (should_turn_left && should_move_on) - MovDir[x][y] = (rnd < rnd_value/2 ? left_dir : old_move_dir); + MovDir[x][y] = (rnd < rnd_value / 2 ? left_dir : old_move_dir); else if (should_turn_right && should_move_on) - MovDir[x][y] = (rnd < rnd_value/2 ? right_dir : old_move_dir); + MovDir[x][y] = (rnd < rnd_value / 2 ? right_dir : old_move_dir); else if (should_turn_left) MovDir[x][y] = left_dir; else if (should_turn_right) @@ -2784,69 +2815,67 @@ void TurnRound(int x, int y) else if (should_move_on) MovDir[x][y] = old_move_dir; } - else if (can_move_on && rnd > rnd_value/8) + else if (can_move_on && rnd > rnd_value / 8) MovDir[x][y] = old_move_dir; else if (can_turn_left && can_turn_right) - MovDir[x][y] = (rnd < rnd_value/2 ? left_dir : right_dir); - else if (can_turn_left && rnd > rnd_value/8) + MovDir[x][y] = (rnd < rnd_value / 2 ? left_dir : right_dir); + else if (can_turn_left && rnd > rnd_value / 8) MovDir[x][y] = left_dir; else if (can_turn_right && rnd > rnd_value/8) MovDir[x][y] = right_dir; else MovDir[x][y] = back_dir; - if (!IS_FREE(x+move_xy[MovDir[x][y]].x, y+move_xy[MovDir[x][y]].y) && - !IS_FOOD_PIG(Feld[x+move_xy[MovDir[x][y]].x][y+move_xy[MovDir[x][y]].y])) + xx = x + move_xy[MovDir[x][y]].x; + yy = y + move_xy[MovDir[x][y]].y; + + if (!IS_FREE(xx, yy) && !IS_FOOD_PIG(Feld[xx][yy])) MovDir[x][y] = old_move_dir; MovDelay[x][y] = 0; } else if (element == EL_DRAGON) { - boolean can_turn_left = FALSE, can_turn_right = FALSE, can_move_on = FALSE; + boolean can_turn_left = IN_LEV_FIELD_AND_IS_FREE(left_x, left_y); + boolean can_turn_right = IN_LEV_FIELD_AND_IS_FREE(right_x, right_y); + boolean can_move_on = IN_LEV_FIELD_AND_IS_FREE(move_x, move_y); int rnd_value = 24; int rnd = RND(rnd_value); - if (IN_LEV_FIELD(left_x, left_y) && IS_FREE(left_x, left_y)) - can_turn_left = TRUE; - if (IN_LEV_FIELD(right_x, right_y) && IS_FREE(right_x, right_y)) - can_turn_right = TRUE; - if (IN_LEV_FIELD(move_x, move_y) && IS_FREE(move_x, move_y)) - can_move_on = TRUE; - - if (can_move_on && rnd > rnd_value/8) + if (can_move_on && rnd > rnd_value / 8) MovDir[x][y] = old_move_dir; else if (can_turn_left && can_turn_right) - MovDir[x][y] = (rnd < rnd_value/2 ? left_dir : right_dir); - else if (can_turn_left && rnd > rnd_value/8) + MovDir[x][y] = (rnd < rnd_value / 2 ? left_dir : right_dir); + else if (can_turn_left && rnd > rnd_value / 8) MovDir[x][y] = left_dir; - else if (can_turn_right && rnd > rnd_value/8) + else if (can_turn_right && rnd > rnd_value / 8) MovDir[x][y] = right_dir; else MovDir[x][y] = back_dir; - if (!IS_FREE(x+move_xy[MovDir[x][y]].x, y+move_xy[MovDir[x][y]].y)) + xx = x + move_xy[MovDir[x][y]].x; + yy = y + move_xy[MovDir[x][y]].y; + + if (!IS_FREE(xx, yy)) MovDir[x][y] = old_move_dir; MovDelay[x][y] = 0; } else if (element == EL_MOLE) { - boolean can_turn_left = FALSE, can_turn_right = FALSE, can_move_on = FALSE; - - if (IN_LEV_FIELD(move_x, move_y) && - (IS_FREE(move_x, move_y) || IS_AMOEBOID(Feld[move_x][move_y]) || - Feld[move_x][move_y] == EL_AMOEBA_SHRINKING)) - can_move_on = TRUE; - + boolean can_move_on = + (MOLE_CAN_ENTER_FIELD(move_x, move_y, + IS_AMOEBOID(Feld[move_x][move_y]) || + Feld[move_x][move_y] == EL_AMOEBA_SHRINKING)); if (!can_move_on) { - if (IN_LEV_FIELD(left_x, left_y) && - (IS_FREE(left_x, left_y) || IS_AMOEBOID(Feld[left_x][left_y]))) - can_turn_left = TRUE; - if (IN_LEV_FIELD(right_x, right_y) && - (IS_FREE(right_x, right_y) || IS_AMOEBOID(Feld[right_x][right_y]))) - can_turn_right = TRUE; + boolean can_turn_left = + (MOLE_CAN_ENTER_FIELD(left_x, left_y, + IS_AMOEBOID(Feld[left_x][left_y]))); + + boolean can_turn_right = + (MOLE_CAN_ENTER_FIELD(right_x, right_y, + IS_AMOEBOID(Feld[right_x][right_y]))); if (can_turn_left && can_turn_right) MovDir[x][y] = (RND(2) ? left_dir : right_dir); @@ -2866,9 +2895,9 @@ void TurnRound(int x, int y) } else if (element == EL_SPRING) { - if ((MovDir[x][y] == MV_LEFT || MovDir[x][y] == MV_RIGHT) && - (!IN_LEV_FIELD(move_x, move_y) || !IS_FREE(move_x, move_y) || - (IN_LEV_FIELD(x, y + 1) && IS_FREE(x, y + 1)))) + if (MovDir[x][y] & MV_HORIZONTAL && + (!IN_LEV_FIELD_AND_IS_FREE(move_x, move_y) || + IN_LEV_FIELD_AND_IS_FREE(x, y + 1))) MovDir[x][y] = MV_NO_MOVING; MovDelay[x][y] = 0; @@ -2896,7 +2925,8 @@ void TurnRound(int x, int y) if (!player->active) continue; - if (attr_x == -1 || ABS(jx-x)+ABS(jy-y) < ABS(attr_x-x)+ABS(attr_y-y)) + if (attr_x == -1 || + ABS(jx - x) + ABS(jy - y) < ABS(attr_x - x) + ABS(attr_y - y)) { attr_x = jx; attr_y = jy; @@ -2954,11 +2984,11 @@ void TurnRound(int x, int y) Moving2Blocked(x, y, &newx, &newy); if (IN_LEV_FIELD(newx, newy) && IS_FREE_OR_PLAYER(newx, newy)) - MovDelay[x][y] = 8+8*!RND(3); + MovDelay[x][y] = 8 + 8 * !RND(3); else MovDelay[x][y] = 16; } - else + else if (element == EL_PENGUIN) { int newx, newy; @@ -2973,24 +3003,43 @@ void TurnRound(int x, int y) new_move_dir & (first_horiz ? MV_HORIZONTAL : MV_VERTICAL); Moving2Blocked(x, y, &newx, &newy); - if (IN_LEV_FIELD(newx, newy) && - (IS_FREE(newx, newy) || - Feld[newx][newy] == EL_ACID || - (element == EL_PENGUIN && - (Feld[newx][newy] == EL_EXIT_OPEN || - IS_FOOD_PENGUIN(Feld[newx][newy]))))) + if (PENGUIN_CAN_ENTER_FIELD(newx, newy)) return; MovDir[x][y] = new_move_dir & (!first_horiz ? MV_HORIZONTAL : MV_VERTICAL); Moving2Blocked(x, y, &newx, &newy); - if (IN_LEV_FIELD(newx, newy) && - (IS_FREE(newx, newy) || - Feld[newx][newy] == EL_ACID || - (element == EL_PENGUIN && - (Feld[newx][newy] == EL_EXIT_OPEN || - IS_FOOD_PENGUIN(Feld[newx][newy]))))) + if (PENGUIN_CAN_ENTER_FIELD(newx, newy)) + return; + + MovDir[x][y] = old_move_dir; + return; + } + } + else /* (element == EL_SATELLITE) */ + { + int newx, newy; + + MovDelay[x][y] = 1; + + if (MovDir[x][y] & MV_HORIZONTAL && MovDir[x][y] & MV_VERTICAL) + { + boolean first_horiz = RND(2); + int new_move_dir = MovDir[x][y]; + + MovDir[x][y] = + new_move_dir & (first_horiz ? MV_HORIZONTAL : MV_VERTICAL); + Moving2Blocked(x, y, &newx, &newy); + + if (ELEMENT_CAN_ENTER_FIELD_OR_ACID_2(newx, newy)) + return; + + MovDir[x][y] = + new_move_dir & (!first_horiz ? MV_HORIZONTAL : MV_VERTICAL); + Moving2Blocked(x, y, &newx, &newy); + + if (ELEMENT_CAN_ENTER_FIELD_OR_ACID_2(newx, newy)) return; MovDir[x][y] = old_move_dir; @@ -2998,20 +3047,18 @@ void TurnRound(int x, int y) } } } - else if (element_info[element].move_pattern == MV_ALL_DIRECTIONS) + else if (element_info[element].move_pattern == MV_ALL_DIRECTIONS || + element_info[element].move_pattern == MV_TURNING_LEFT || + element_info[element].move_pattern == MV_TURNING_RIGHT) { - boolean can_turn_left = FALSE, can_turn_right = FALSE; - - if (IN_LEV_FIELD(left_x, left_y) && - (IS_FREE(left_x, left_y) || - (DONT_COLLIDE_WITH(element) && IS_FREE_OR_PLAYER(left_x, left_y)))) - can_turn_left = TRUE; - if (IN_LEV_FIELD(right_x, right_y) && - (IS_FREE(right_x, right_y) || - (DONT_COLLIDE_WITH(element) && IS_FREE_OR_PLAYER(right_x, right_y)))) - can_turn_right = TRUE; + boolean can_turn_left = ELEMENT_CAN_ENTER_FIELD(element, left_x, left_y); + boolean can_turn_right = ELEMENT_CAN_ENTER_FIELD(element, right_x,right_y); - if (can_turn_left && can_turn_right) + if (element_info[element].move_pattern == MV_TURNING_LEFT) + MovDir[x][y] = left_dir; + else if (element_info[element].move_pattern == MV_TURNING_RIGHT) + MovDir[x][y] = right_dir; + else if (can_turn_left && can_turn_right) MovDir[x][y] = (RND(3) ? (RND(2) ? left_dir : right_dir) : back_dir); else if (can_turn_left) MovDir[x][y] = (RND(2) ? left_dir : back_dir); @@ -3041,13 +3088,9 @@ void TurnRound(int x, int y) } else if (element_info[element].move_pattern == MV_ALONG_LEFT_SIDE) { - if (IN_LEV_FIELD(left_x, left_y) && - (IS_FREE(left_x, left_y) || - (DONT_COLLIDE_WITH(element) && IS_FREE_OR_PLAYER(left_x, left_y)))) + if (ELEMENT_CAN_ENTER_FIELD(element, left_x, left_y)) MovDir[x][y] = left_dir; - else if (!IN_LEV_FIELD(move_x, move_y) || - (!IS_FREE(move_x, move_y) && - (!DONT_COLLIDE_WITH(element) || !IS_FREE_OR_PLAYER(move_x, move_y)))) + else if (!ELEMENT_CAN_ENTER_FIELD(element, move_x, move_y)) MovDir[x][y] = right_dir; if (MovDir[x][y] != old_move_dir) @@ -3055,13 +3098,9 @@ void TurnRound(int x, int y) } else if (element_info[element].move_pattern == MV_ALONG_RIGHT_SIDE) { - if (IN_LEV_FIELD(right_x, right_y) && - (IS_FREE(right_x, right_y) || - (DONT_COLLIDE_WITH(element) && IS_FREE_OR_PLAYER(right_x, right_y)))) + if (ELEMENT_CAN_ENTER_FIELD(element, right_x, right_y)) MovDir[x][y] = right_dir; - else if (!IN_LEV_FIELD(move_x, move_y) || - (!IS_FREE(move_x, move_y) && - (!DONT_COLLIDE_WITH(element) || !IS_FREE_OR_PLAYER(move_x, move_y)))) + else if (!ELEMENT_CAN_ENTER_FIELD(element, move_x, move_y)) MovDir[x][y] = left_dir; if (MovDir[x][y] != old_move_dir) @@ -3092,7 +3131,8 @@ void TurnRound(int x, int y) if (!player->active) continue; - if (attr_x == -1 || ABS(jx-x)+ABS(jy-y) < ABS(attr_x-x)+ABS(attr_y-y)) + if (attr_x == -1 || + ABS(jx - x) + ABS(jy - y) < ABS(attr_x - x) + ABS(attr_y - y)) { attr_x = jx; attr_y = jy; @@ -3121,20 +3161,14 @@ void TurnRound(int x, int y) new_move_dir & (first_horiz ? MV_HORIZONTAL : MV_VERTICAL); Moving2Blocked(x, y, &newx, &newy); - if (IN_LEV_FIELD(newx, newy) && (IS_FREE(newx, newy) || - (DONT_COLLIDE_WITH(element) && - IS_FREE_OR_PLAYER(newx, newy)) || - Feld[newx][newy] == EL_ACID)) + if (ELEMENT_CAN_ENTER_FIELD_OR_ACID(element, newx, newy)) return; MovDir[x][y] = new_move_dir & (!first_horiz ? MV_HORIZONTAL : MV_VERTICAL); Moving2Blocked(x, y, &newx, &newy); - if (IN_LEV_FIELD(newx, newy) && (IS_FREE(newx, newy) || - (DONT_COLLIDE_WITH(element) && - IS_FREE_OR_PLAYER(newx, newy)) || - Feld[newx][newy] == EL_ACID)) + if (ELEMENT_CAN_ENTER_FIELD_OR_ACID(element, newx, newy)) return; MovDir[x][y] = old_move_dir; @@ -3317,11 +3351,26 @@ void StartMoving(int x, int y) GfxAction[x][y + 1] = ACTION_ACTIVE; #endif } +#if 1 +#if 1 + else if (game.engine_version < RELEASE_IDENT(2,2,0,7) && + CAN_SMASH(element) && Feld[x][y + 1] == EL_BLOCKED && + JustStopped[x][y] && !Pushed[x][y + 1]) +#else else if (CAN_SMASH(element) && Feld[x][y + 1] == EL_BLOCKED && JustStopped[x][y]) +#endif { + /* calling "Impact()" here is not only completely unneccessary + (because it already gets called from "ContinueMoving()" in + all relevant situations), but also completely bullshit, because + "JustStopped" also indicates a finished *horizontal* movement; + we must keep this trash for backwards compatibility with older + tapes */ + Impact(x, y); } +#endif else if (IS_FREE(x, y + 1) && element == EL_SPRING && use_spring_bug) { if (MovDir[x][y] == MV_NO_MOVING) @@ -3355,7 +3404,7 @@ void StartMoving(int x, int y) element != EL_DX_SUPABOMB) #endif #else - else if ((IS_SLIPPERY(Feld[x][y + 1]) || + else if (((IS_SLIPPERY(Feld[x][y + 1]) && !IS_PLAYER(x, y + 1)) || (IS_EM_SLIPPERY_WALL(Feld[x][y + 1]) && IS_GEM(element))) && !IS_FALLING(x, y + 1) && !JustStopped[x][y + 1] && element != EL_DX_SUPABOMB && element != EL_SP_DISK_ORANGE) @@ -3375,6 +3424,11 @@ void StartMoving(int x, int y) InitMovingField(x, y, left ? MV_LEFT : MV_RIGHT); started_moving = TRUE; + +#if 0 + if (element == EL_BOMB) + printf("::: SLIP DOWN [%d]\n", FrameCounter); +#endif } } else if (IS_BELT_ACTIVE(Feld[x][y + 1])) @@ -3395,7 +3449,7 @@ void StartMoving(int x, int y) } } - /* not "else if" because of EL_SPRING */ + /* not "else if" because of elements that can fall and move (EL_SPRING) */ if (CAN_MOVE(element) && !started_moving) { int newx, newy; @@ -3428,7 +3482,9 @@ void StartMoving(int x, int y) if (element != EL_YAMYAM && element != EL_DARK_YAMYAM && element != EL_PACMAN && - !(element_info[element].move_pattern & MV_ANY_DIRECTION)) + !(element_info[element].move_pattern & MV_ANY_DIRECTION) && + element_info[element].move_pattern != MV_TURNING_LEFT && + element_info[element].move_pattern != MV_TURNING_RIGHT) { TurnRound(x, y); @@ -3782,6 +3838,17 @@ void ContinueMoving(int x, int y) int horiz_move = (dx != 0); int newx = x + dx, newy = y + dy; int step = (horiz_move ? dx : dy) * TILEX / MOVE_DELAY_NORMAL_SPEED; + struct PlayerInfo *player = (IS_PLAYER(x, y) ? PLAYERINFO(x, y) : NULL); +#if 0 + boolean pushing = (player != NULL && player->Pushing && player->MovPos != 0); +#else + boolean pushing = (player != NULL && player->Pushing && player->is_moving); +#endif + +#if 0 + if (player && player->is_moving && player->MovPos == 0) + printf("::: !!!\n"); +#endif if (element == EL_AMOEBA_DROP || element == EL_AMOEBA_DROPPING) step /= 2; @@ -3808,6 +3875,30 @@ void ContinueMoving(int x, int y) MovPos[x][y] += step; +#if 1 +#if 1 + if (Pushed[x][y]) /* special case: moving object pushed by player */ +#else + if (pushing) /* special case: moving object pushed by player */ +#endif +#if 1 + MovPos[x][y] = SIGN(MovPos[x][y]) * (TILEX - ABS(PLAYERINFO(x,y)->MovPos)); +#else + MovPos[x][y] = SIGN(MovPos[x][y]) * (TILEX - ABS(PLAYERINFO(x,y)->GfxPos)); +#endif +#endif + +#if 0 + if (element == EL_SPRING) + printf("::: spring moves %d [%d: %d, %d, %d/%d]\n", + MovPos[x][y], + pushing, + (player?player->Pushing:-42), + (player?player->is_moving:-42), + (player?player->MovPos:-42), + (player?player->GfxPos:-42)); +#endif + if (ABS(MovPos[x][y]) >= TILEX) /* object reached its destination */ { Feld[x][y] = EL_EMPTY; @@ -3883,6 +3974,16 @@ void ContinueMoving(int x, int y) Feld[x][y] = get_next_element(element); element = Feld[newx][newy] = Store[x][y]; } + else if (element == EL_SOKOBAN_OBJECT) + { + if (Back[x][y]) + Feld[x][y] = Back[x][y]; + + if (Back[newx][newy]) + Feld[newx][newy] = EL_SOKOBAN_FIELD_FULL; + + Back[x][y] = Back[newx][newy] = 0; + } else if (Store[x][y] == EL_ACID) { element = Feld[newx][newy] = EL_ACID; @@ -3900,29 +4001,47 @@ void ContinueMoving(int x, int y) GfxAction[newx][newy] = GfxAction[x][y]; /* keep action one frame */ GfxRandom[newx][newy] = GfxRandom[x][y]; /* keep same random value */ + Pushed[x][y] = Pushed[newx][newy] = FALSE; + ResetGfxAnimation(x, y); /* reset animation values for old field */ #if 1 #if 0 + /* 2.1.1 (does not work correctly for spring) */ if (!CAN_MOVE(element)) MovDir[newx][newy] = 0; #else - /* + +#if 0 + /* (does not work for falling objects that slide horizontally) */ if (CAN_FALL(element) && MovDir[newx][newy] == MV_DOWN) MovDir[newx][newy] = 0; +#else + /* + if (!CAN_MOVE(element) || + (element == EL_SPRING && MovDir[newx][newy] == MV_DOWN)) + MovDir[newx][newy] = 0; */ if (!CAN_MOVE(element) || - (element == EL_SPRING && MovDir[newx][newy] == MV_DOWN)) + (CAN_FALL(element) && MovDir[newx][newy] == MV_DOWN)) MovDir[newx][newy] = 0; #endif + +#endif #endif DrawLevelField(x, y); DrawLevelField(newx, newy); - Stop[newx][newy] = TRUE; - JustStopped[newx][newy] = 3; +#if 0 + if (game.engine_version >= RELEASE_IDENT(2,2,0,7) || !pushing) +#endif + Stop[newx][newy] = TRUE; /* ignore this element until the next frame */ +#if 1 + if (!pushing) +#endif + JustStopped[newx][newy] = 3; if (DONT_TOUCH(element)) /* object may be nasty to player or others */ { @@ -4833,10 +4952,12 @@ static void ChangeActiveTrap(int x, int y) DrawLevelFieldCrumbledSand(x, y); } -static void ChangeElementDoIt(int x, int y, int element) +static void ChangeElementDoIt(int x, int y, int element_new) { + CheckTriggeredElementChange(Feld[x][y], CE_OTHER_CHANGING); + RemoveField(x, y); - Feld[x][y] = element; + Feld[x][y] = element_new; ResetGfxAnimation(x, y); ResetRandomAnimationValue(x, y); @@ -4914,6 +5035,8 @@ static void ChangeElement(int x, int y) } else /* finish element change */ { + int next_element = changing_element[element].next_element; + if (IS_MOVING(x, y)) /* never change a running system ;-) */ { ChangeDelay[x][y] = 1; /* try change after next move step */ @@ -4921,56 +5044,54 @@ static void ChangeElement(int x, int y) return; } -#if 1 - ChangeElementDoIt(x, y, changing_element[element].next_element); -#else - RemoveField(x, y); - Feld[x][y] = changing_element[element].next_element; + if (next_element != EL_UNDEFINED) + ChangeElementDoIt(x, y, next_element); + else + ChangeElementDoIt(x, y, element_info[element].change.successor); - ResetGfxAnimation(x, y); - ResetRandomAnimationValue(x, y); + if (changing_element[element].post_change_function) + changing_element[element].post_change_function(x, y); + } +} - InitField(x, y, FALSE); - if (CAN_MOVE(Feld[x][y])) - InitMovDir(x, y); +static void CheckTriggeredElementChange(int trigger_element, int trigger_event) +{ + int i, x, y; - DrawLevelField(x, y); + if (!(trigger_events[trigger_element] & CH_EVENT_BIT(trigger_event))) + return; - if (CAN_BE_CRUMBLED(Feld[x][y])) - { - int sx = SCREENX(x), sy = SCREENY(y); - static int xy[4][2] = - { - { 0, -1 }, - { -1, 0 }, - { +1, 0 }, - { 0, +1 } - }; - int i; + for (i=0; ijx; + int y = player->jy; + + if (player->active && player->Pushing && player->is_moving && + IS_MOVING(x, y)) + { + ContinueMoving(x, y); + + /* continue moving after pushing (this is actually a bug) */ + if (!IS_MOVING(x, y)) + { + Stop[x][y] = FALSE; + } + } + } + } +#endif + for (y=0; yjx, jy = player->jy; int dx = x - jx, dy = y - jy; int move_direction = (dx == -1 ? MV_LEFT : @@ -6326,7 +6472,14 @@ int DigField(struct PlayerInfo *player, } if (IS_MOVING(x, y) || IS_PLAYER(x, y)) + { +#if 0 + if (FrameCounter == 437) + printf("::: ---> IS_MOVING %d\n", MovDir[x][y]); +#endif + return MF_NO_ACTION; + } #if 0 if (IS_TUBE(Feld[jx][jy]) || IS_TUBE(Back[jx][jy])) @@ -6374,7 +6527,13 @@ int DigField(struct PlayerInfo *player, switch (element) { +#if 0 case EL_EMPTY: + PlaySoundLevelElementAction(x, y, player->element_nr, ACTION_MOVING); + break; +#endif + +#if 0 case EL_SAND: case EL_INVISIBLE_SAND: case EL_INVISIBLE_SAND_ACTIVE: @@ -6383,15 +6542,16 @@ int DigField(struct PlayerInfo *player, case EL_SP_BUGGY_BASE: case EL_SP_BUGGY_BASE_ACTIVATING: RemoveField(x, y); -#if 1 + if (mode != DF_SNAP && element != EL_EMPTY) { GfxElement[x][y] = (CAN_BE_CRUMBLED(element) ? EL_SAND : element); player->is_digging = TRUE; } -#endif + PlaySoundLevelElementAction(x, y, element, ACTION_DIGGING); break; +#endif case EL_EMERALD: case EL_BD_DIAMOND: @@ -6403,13 +6563,13 @@ int DigField(struct PlayerInfo *player, case EL_PEARL: case EL_CRYSTAL: RemoveField(x, y); -#if 1 + if (mode != DF_SNAP) { GfxElement[x][y] = element; player->is_collecting = TRUE; } -#endif + local_player->gems_still_needed -= (element == EL_DIAMOND ? 3 : element == EL_PEARL ? 5 : element == EL_CRYSTAL ? 8 : 1); @@ -6419,18 +6579,31 @@ int DigField(struct PlayerInfo *player, DrawText(DX_EMERALDS, DY_EMERALDS, int2str(local_player->gems_still_needed, 3), FONT_TEXT_2); PlaySoundLevelElementAction(x, y, element, ACTION_COLLECTING); + CheckTriggeredElementChange(element, CE_OTHER_COLLECTING); break; case EL_SPEED_PILL: RemoveField(x, y); player->move_delay_value = MOVE_DELAY_HIGH_SPEED; +#if 1 + PlaySoundLevelElementAction(x, y, element, ACTION_COLLECTING); +#else PlaySoundLevel(x, y, SND_SPEED_PILL_COLLECTING); +#endif + CheckTriggeredElementChange(element, CE_OTHER_COLLECTING); break; +#if 0 case EL_ENVELOPE: Feld[x][y] = EL_EMPTY; +#if 1 + PlaySoundLevelElementAction(x, y, element, ACTION_COLLECTING); +#else PlaySoundLevel(x, y, SND_ENVELOPE_COLLECTING); +#endif + CheckTriggeredElementChange(element, CE_OTHER_COLLECTING); break; +#endif case EL_EXTRA_TIME: RemoveField(x, y); @@ -6439,20 +6612,35 @@ int DigField(struct PlayerInfo *player, TimeLeft += 10; DrawText(DX_TIME, DY_TIME, int2str(TimeLeft, 3), FONT_TEXT_2); } +#if 1 + PlaySoundLevelElementAction(x, y, element, ACTION_COLLECTING); +#else PlaySoundStereo(SND_EXTRA_TIME_COLLECTING, SOUND_MIDDLE); +#endif + CheckTriggeredElementChange(element, CE_OTHER_COLLECTING); break; case EL_SHIELD_NORMAL: RemoveField(x, y); player->shield_normal_time_left += 10; +#if 1 + PlaySoundLevelElementAction(x, y, element, ACTION_COLLECTING); +#else PlaySoundLevel(x, y, SND_SHIELD_NORMAL_COLLECTING); +#endif + CheckTriggeredElementChange(element, CE_OTHER_COLLECTING); break; case EL_SHIELD_DEADLY: RemoveField(x, y); player->shield_normal_time_left += 10; player->shield_deadly_time_left += 10; +#if 1 + PlaySoundLevelElementAction(x, y, element, ACTION_COLLECTING); +#else PlaySoundLevel(x, y, SND_SHIELD_DEADLY_COLLECTING); +#endif + CheckTriggeredElementChange(element, CE_OTHER_COLLECTING); break; case EL_DYNAMITE: @@ -6464,6 +6652,7 @@ int DigField(struct PlayerInfo *player, DrawText(DX_DYNAMITE, DY_DYNAMITE, int2str(local_player->dynamite, 3), FONT_TEXT_2); PlaySoundLevelElementAction(x, y, element, ACTION_COLLECTING); + CheckTriggeredElementChange(element, CE_OTHER_COLLECTING); break; case EL_DYNABOMB_INCREASE_NUMBER: @@ -6471,21 +6660,36 @@ int DigField(struct PlayerInfo *player, player->dynabomb_count++; player->dynabombs_left++; RaiseScoreElement(EL_DYNAMITE); +#if 1 + PlaySoundLevelElementAction(x, y, element, ACTION_COLLECTING); +#else PlaySoundLevel(x, y, SND_DYNABOMB_INCREASE_NUMBER_COLLECTING); +#endif + CheckTriggeredElementChange(element, CE_OTHER_COLLECTING); break; case EL_DYNABOMB_INCREASE_SIZE: RemoveField(x, y); player->dynabomb_size++; RaiseScoreElement(EL_DYNAMITE); +#if 1 + PlaySoundLevelElementAction(x, y, element, ACTION_COLLECTING); +#else PlaySoundLevel(x, y, SND_DYNABOMB_INCREASE_SIZE_COLLECTING); +#endif + CheckTriggeredElementChange(element, CE_OTHER_COLLECTING); break; case EL_DYNABOMB_INCREASE_POWER: RemoveField(x, y); player->dynabomb_xl = TRUE; RaiseScoreElement(EL_DYNAMITE); +#if 1 + PlaySoundLevelElementAction(x, y, element, ACTION_COLLECTING); +#else PlaySoundLevel(x, y, SND_DYNABOMB_INCREASE_POWER_COLLECTING); +#endif + CheckTriggeredElementChange(element, CE_OTHER_COLLECTING); break; case EL_KEY_1: @@ -6503,7 +6707,12 @@ int DigField(struct PlayerInfo *player, graphic); DrawMiniGraphicExt(window, DX_KEYS + key_nr * MINI_TILEX, DY_KEYS, graphic); +#if 1 + PlaySoundLevelElementAction(x, y, element, ACTION_COLLECTING); +#else PlaySoundLevel(x, y, SND_CLASS_KEY_COLLECTING); +#endif + CheckTriggeredElementChange(element, CE_OTHER_COLLECTING); break; } @@ -6522,7 +6731,12 @@ int DigField(struct PlayerInfo *player, graphic); DrawMiniGraphicExt(window, DX_KEYS + key_nr * MINI_TILEX, DY_KEYS, graphic); +#if 1 + PlaySoundLevelElementAction(x, y, element, ACTION_COLLECTING); +#else PlaySoundLevel(x, y, SND_CLASS_KEY_COLLECTING); +#endif + CheckTriggeredElementChange(element, CE_OTHER_COLLECTING); break; } @@ -6626,6 +6840,8 @@ int DigField(struct PlayerInfo *player, return MF_ACTION; break; +#if 0 + /* the following elements cannot be pushed by "snapping" */ case EL_ROCK: case EL_BOMB: @@ -6645,6 +6861,10 @@ int DigField(struct PlayerInfo *player, if (dy) return MF_NO_ACTION; + if (CAN_FALL(element) && IN_LEV_FIELD(x, y + 1) && IS_FREE(x, y + 1) && + !(element == EL_SPRING && use_spring_bug)) + return MF_NO_ACTION; + player->Pushing = TRUE; #if 0 @@ -6659,8 +6879,14 @@ int DigField(struct PlayerInfo *player, if (!checkDiagonalPushing(player, x, y, real_dx, real_dy)) return MF_NO_ACTION; + if (player->push_delay == 0) player->push_delay = FrameCounter; + +#if 0 + printf("want push... %d [%d]\n", FrameCounter, player->push_delay_value); +#endif + #if 0 if (!FrameReached(&player->push_delay, player->push_delay_value) && !tape.playing && @@ -6680,22 +6906,41 @@ int DigField(struct PlayerInfo *player, } else { +#if 1 + InitMovingField(x, y, (dx < 0 ? MV_LEFT : + dx > 0 ? MV_RIGHT : + dy < 0 ? MV_UP : MV_DOWN)); + MovPos[x][y] = (dx != 0 ? dx : dy); +#else RemoveField(x, y); Feld[x + dx][y + dy] = element; +#endif } +#if 0 + printf("pushing %d/%d ... %d [%d]\n", dx, dy, + FrameCounter, player->push_delay_value); +#endif + +#if 0 if (element == EL_SPRING) { Feld[x + dx][y + dy] = EL_SPRING; MovDir[x + dx][y + dy] = move_direction; } +#endif player->push_delay_value = (element == EL_SPRING ? 0 : 2 + RND(8)); DrawLevelField(x + dx, y + dy); PlaySoundLevelElementAction(x, y, element, ACTION_PUSHING); + + CheckTriggeredElementChange(element, CE_OTHER_PUSHING); + break; +#endif + case EL_GATE_1: case EL_GATE_2: case EL_GATE_3: @@ -6880,8 +7125,12 @@ int DigField(struct PlayerInfo *player, return MF_ACTION; break; +#if 0 + +#if 0 case EL_SOKOBAN_FIELD_EMPTY: break; +#endif case EL_SOKOBAN_OBJECT: case EL_SOKOBAN_FIELD_FULL: @@ -6917,6 +7166,44 @@ int DigField(struct PlayerInfo *player, if (IS_SB_ELEMENT(element)) { +#if 1 + if (element == EL_SOKOBAN_FIELD_FULL) + { + Back[x][y] = EL_SOKOBAN_FIELD_EMPTY; + local_player->sokobanfields_still_needed++; + } + + if (Feld[x + dx][y + dy] == EL_SOKOBAN_FIELD_EMPTY) + { + Back[x + dx][y + dy] = EL_SOKOBAN_FIELD_EMPTY; + local_player->sokobanfields_still_needed--; + } + + Feld[x][y] = EL_SOKOBAN_OBJECT; + + if (Back[x][y] == Back[x + dx][y + dy]) + PlaySoundLevelAction(x, y, ACTION_PUSHING); + else if (Back[x][y] != 0) + PlaySoundLevelElementAction(x, y, EL_SOKOBAN_FIELD_FULL, + ACTION_EMPTYING); + else + PlaySoundLevelElementAction(x + dx, y + dy, EL_SOKOBAN_FIELD_EMPTY, + ACTION_FILLING); + + InitMovingField(x, y, (dx < 0 ? MV_LEFT : + dx > 0 ? MV_RIGHT : + dy < 0 ? MV_UP : MV_DOWN)); + MovPos[x][y] = (dx != 0 ? dx : dy); + +#if 0 + printf("::: %s -> %s [%s -> %s]\n", + element_info[Feld[x][y]].token_name, + element_info[Feld[x + dx][y + dy]].token_name, + element_info[Back[x][y]].token_name, + element_info[Back[x + dx][y + dy]].token_name); +#endif + +#else if (element == EL_SOKOBAN_FIELD_FULL) { Feld[x][y] = EL_SOKOBAN_FIELD_EMPTY; @@ -6958,11 +7245,19 @@ int DigField(struct PlayerInfo *player, PlaySoundLevel(x, y, SND_SOKOBAN_OBJECT_PUSHING); #endif } +#endif } else { +#if 1 + InitMovingField(x, y, (dx < 0 ? MV_LEFT : + dx > 0 ? MV_RIGHT : + dy < 0 ? MV_UP : MV_DOWN)); + MovPos[x][y] = (dx != 0 ? dx : dy); +#else RemoveField(x, y); - Feld[x+dx][y+dy] = element; + Feld[x + dx][y + dy] = element; +#endif PlaySoundLevelElementAction(x, y, element, ACTION_PUSHING); } @@ -6979,8 +7274,12 @@ int DigField(struct PlayerInfo *player, PlaySoundLevel(x, y, SND_GAME_SOKOBAN_SOLVING); } + CheckTriggeredElementChange(element, CE_OTHER_PUSHING); + break; +#endif + case EL_PENGUIN: case EL_PIG: case EL_DRAGON: @@ -6990,19 +7289,20 @@ int DigField(struct PlayerInfo *player, if (IS_WALKABLE(element)) { + PlaySoundLevelElementAction(x, y, player->element_nr, ACTION_MOVING); break; } else if (IS_DIGGABLE(element)) { RemoveField(x, y); -#if 1 + if (mode != DF_SNAP) { GfxElement[x][y] = (CAN_BE_CRUMBLED(element) ? EL_SAND : GFX_ELEMENT(element)); player->is_digging = TRUE; } -#endif + PlaySoundLevelElementAction(x, y, element, ACTION_DIGGING); break; @@ -7010,32 +7310,46 @@ int DigField(struct PlayerInfo *player, else if (IS_COLLECTIBLE(element)) { RemoveField(x, y); -#if 1 + if (mode != DF_SNAP) { GfxElement[x][y] = element; player->is_collecting = TRUE; } -#endif + + RaiseScoreElement(element); + PlaySoundLevelElementAction(x, y, element, ACTION_COLLECTING); + CheckTriggeredElementChange(element, CE_OTHER_COLLECTING); + break; } else if (IS_PUSHABLE(element)) { - if (mode == DF_SNAP) + if (mode == DF_SNAP && element != EL_BD_ROCK) return MF_NO_ACTION; if (CAN_FALL(element) && dy) return MF_NO_ACTION; + if (CAN_FALL(element) && IN_LEV_FIELD(x, y + 1) && IS_FREE(x, y + 1) && + !(element == EL_SPRING && use_spring_bug)) + return MF_NO_ACTION; + + if (element == EL_SPRING && MovDir[x][y] != MV_NO_MOVING) + return MF_NO_ACTION; + if (!player->Pushing && game.engine_version >= RELEASE_IDENT(2,2,0,7)) player->push_delay_value = GET_NEW_PUSH_DELAY(element); player->Pushing = TRUE; - if (!IN_LEV_FIELD(x + dx, y + dy) || !IS_FREE(x + dx, y + dy)) + if (!(IN_LEV_FIELD(x + dx, y + dy) && + (IS_FREE(x + dx, y + dy) || + (Feld[x + dx][y + dy] == EL_SOKOBAN_FIELD_EMPTY && + IS_SB_ELEMENT(element))))) return MF_NO_ACTION; if (!checkDiagonalPushing(player, x, y, real_dx, real_dy)) @@ -7045,24 +7359,67 @@ int DigField(struct PlayerInfo *player, player->push_delay = FrameCounter; if (!FrameReached(&player->push_delay, player->push_delay_value) && - !(tape.playing && tape.file_version < FILE_VERSION_2_0)) + !(tape.playing && tape.file_version < FILE_VERSION_2_0) && + element != EL_SPRING && element != EL_BALLOON) return MF_NO_ACTION; - RemoveField(x, y); - Feld[x + dx][y + dy] = element; + if (IS_SB_ELEMENT(element)) + { + if (element == EL_SOKOBAN_FIELD_FULL) + { + Back[x][y] = EL_SOKOBAN_FIELD_EMPTY; + local_player->sokobanfields_still_needed++; + } + + if (Feld[x + dx][y + dy] == EL_SOKOBAN_FIELD_EMPTY) + { + Back[x + dx][y + dy] = EL_SOKOBAN_FIELD_EMPTY; + local_player->sokobanfields_still_needed--; + } + + Feld[x][y] = EL_SOKOBAN_OBJECT; + + if (Back[x][y] == Back[x + dx][y + dy]) + PlaySoundLevelAction(x, y, ACTION_PUSHING); + else if (Back[x][y] != 0) + PlaySoundLevelElementAction(x, y, EL_SOKOBAN_FIELD_FULL, + ACTION_EMPTYING); + else + PlaySoundLevelElementAction(x + dx, y + dy, EL_SOKOBAN_FIELD_EMPTY, + ACTION_FILLING); + + if (local_player->sokobanfields_still_needed == 0 && + game.emulation == EMU_SOKOBAN) + { + player->LevelSolved = player->GameOver = TRUE; + PlaySoundLevel(x, y, SND_GAME_SOKOBAN_SOLVING); + } + } + else + PlaySoundLevelElementAction(x, y, element, ACTION_PUSHING); + + InitMovingField(x, y, move_direction); + + if (mode == DF_SNAP) + ContinueMoving(x, y); + else + MovPos[x][y] = (dx != 0 ? dx : dy); + + Pushed[x][y] = TRUE; + Pushed[x + dx][y + dy] = TRUE; -#if 1 if (game.engine_version < RELEASE_IDENT(2,2,0,7)) player->push_delay_value = GET_NEW_PUSH_DELAY(element); -#else - player->push_delay_value = 2 + RND(8); -#endif - DrawLevelField(x + dx, y + dy); - PlaySoundLevelElementAction(x, y, element, ACTION_PUSHING); + CheckTriggeredElementChange(element, CE_OTHER_PUSHING); + CheckPlayerElementChange(x, y, element, CE_PUSHED_BY_PLAYER); break; } + else + { + CheckPlayerElementChange(x, y, element, CE_PRESSED_BY_PLAYER); + } return MF_NO_ACTION; } @@ -7370,6 +7727,7 @@ void RaiseScoreElement(int element) RaiseScore(level.score[SC_KEY]); break; default: + RaiseScore(element_info[element].score); break; } }