X-Git-Url: https://git.artsoft.org/?a=blobdiff_plain;f=src%2Fgame.c;h=0e84aa846bfd0dcc5fb94defd73f147919012f1b;hb=a047db7b385f7523ca97deb21fdc504f34a80c7e;hp=dfad329ef9c2b2e64d5df8fb4e1a4c6986edd595;hpb=c77e984eb41ae3473b474e9051b0a71afffeb73c;p=rocksndiamonds.git diff --git a/src/game.c b/src/game.c index dfad329e..0e84aa84 100644 --- a/src/game.c +++ b/src/game.c @@ -59,7 +59,8 @@ #define YY_KEYS 123 #define XX_SCORE 15 #define YY_SCORE 159 -#define XX_TIME 29 +#define XX_TIME1 29 +#define XX_TIME2 30 #define YY_TIME 194 /* special positions in the game control window (relative to main window) */ @@ -73,7 +74,8 @@ #define DY_KEYS (DY + YY_KEYS) #define DX_SCORE (DX + XX_SCORE) #define DY_SCORE (DY + YY_SCORE) -#define DX_TIME (DX + XX_TIME) +#define DX_TIME1 (DX + XX_TIME1) +#define DX_TIME2 (DX + XX_TIME2) #define DY_TIME (DY + YY_TIME) /* values for initial player move delay (initial delay counter value) */ @@ -101,85 +103,156 @@ #define GET_MAX_MOVE_DELAY(e) ( (element_info[e].move_delay_fixed) + \ (element_info[e].move_delay_random)) -#if 1 -#define ELEMENT_CAN_ENTER_FIELD_GENERIC(e, x, y, condition) \ +#define ELEMENT_CAN_ENTER_FIELD_BASE_X(x, y, condition) \ + (IN_LEV_FIELD(x, y) && (IS_FREE(x, y) || \ + (condition))) + +#define ELEMENT_CAN_ENTER_FIELD_BASE_2(e, x, y, condition) \ + (IN_LEV_FIELD(x, y) && (IS_FREE(x, y) || \ + (CAN_MOVE_INTO_ACID(e) && \ + Feld[x][y] == EL_ACID) || \ + (condition))) + +#define ELEMENT_CAN_ENTER_FIELD_BASE_3(e, x, y, condition) \ + (IN_LEV_FIELD(x, y) && (IS_FREE_OR_PLAYER(x, y) || \ + (CAN_MOVE_INTO_ACID(e) && \ + Feld[x][y] == EL_ACID) || \ + (condition))) + +#define ELEMENT_CAN_ENTER_FIELD_BASE_4(e, x, y, condition) \ (IN_LEV_FIELD(x, y) && (IS_FREE(x, y) || \ (condition) || \ + (CAN_MOVE_INTO_ACID(e) && \ + Feld[x][y] == EL_ACID) || \ (DONT_COLLIDE_WITH(e) && \ IS_PLAYER(x, y) && \ - !PLAYER_PROTECTED(x, y)))) -#else + !PLAYER_ENEMY_PROTECTED(x, y)))) + +#if 0 #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)))) + IS_PLAYER(x, y) && \ + !PLAYER_ENEMY_PROTECTED(x, y)))) #endif -#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) + ELEMENT_CAN_ENTER_FIELD_BASE_4(e, x, y, 0) + +#if 1 +#define SATELLITE_CAN_ENTER_FIELD(x, y) \ + ELEMENT_CAN_ENTER_FIELD_BASE_2(EL_SATELLITE, x, y, 0) +#else +#define SATELLITE_CAN_ENTER_FIELD(x, y) \ + ELEMENT_CAN_ENTER_FIELD_BASE_X(x, y, Feld[x][y] == EL_ACID) +#endif + +#if 0 +#define ENEMY_CAN_ENTER_FIELD(e, x, y) (IN_LEV_FIELD(x, y) && IS_FREE(x, y)) +#endif + +#define ENEMY_CAN_ENTER_FIELD(e, x, y) \ + ELEMENT_CAN_ENTER_FIELD_BASE_2(e, x, y, 0) + +#if 1 + +#define YAMYAM_CAN_ENTER_FIELD(e, x, y) \ + ELEMENT_CAN_ENTER_FIELD_BASE_3(e, x, y, Feld[x][y] == EL_DIAMOND) + +#define DARK_YAMYAM_CAN_ENTER_FIELD(e, x, y) \ + ELEMENT_CAN_ENTER_FIELD_BASE_3(e, x,y, IS_FOOD_DARK_YAMYAM(Feld[x][y])) + +#define PACMAN_CAN_ENTER_FIELD(e, x, y) \ + ELEMENT_CAN_ENTER_FIELD_BASE_3(e, x, y, IS_AMOEBOID(Feld[x][y])) + +#define PIG_CAN_ENTER_FIELD(e, x, y) \ + ELEMENT_CAN_ENTER_FIELD_BASE_2(e, x, y, IS_FOOD_PIG(Feld[x][y])) -#define ELEMENT_CAN_ENTER_FIELD_OR_ACID(e, x, y) \ - ELEMENT_CAN_ENTER_FIELD_GENERIC(e, x, y, (Feld[x][y] == EL_ACID)) +#define PENGUIN_CAN_ENTER_FIELD(e, x, y) \ + ELEMENT_CAN_ENTER_FIELD_BASE_2(e, x, y, (Feld[x][y] == EL_EXIT_OPEN ||\ + IS_FOOD_PENGUIN(Feld[x][y]))) +#define DRAGON_CAN_ENTER_FIELD(e, x, y) \ + ELEMENT_CAN_ENTER_FIELD_BASE_2(e, x, y, 0) -#define ELEMENT_CAN_ENTER_FIELD_OR_ACID_2(x, y) \ - ELEMENT_CAN_ENTER_FIELD_GENERIC_2(x, y, (Feld[x][y] == EL_ACID)) +#define MOLE_CAN_ENTER_FIELD(e, x, y, condition) \ + ELEMENT_CAN_ENTER_FIELD_BASE_2(e, x, y, (condition)) -#define ENEMY_CAN_ENTER_FIELD(x, y) (IN_LEV_FIELD(x, y) && IS_FREE(x, y)) +#define SPRING_CAN_ENTER_FIELD(e, x, y) \ + ELEMENT_CAN_ENTER_FIELD_BASE_2(e, x, y, 0) -#define YAMYAM_CAN_ENTER_FIELD(x, y) \ +#else + +#define YAMYAM_CAN_ENTER_FIELD(e, x, y) \ (IN_LEV_FIELD(x, y) && (IS_FREE_OR_PLAYER(x, y) || \ + (CAN_MOVE_INTO_ACID(e) && \ + Feld[x][y] == EL_ACID) || \ Feld[x][y] == EL_DIAMOND)) -#define DARK_YAMYAM_CAN_ENTER_FIELD(x, y) \ +#define DARK_YAMYAM_CAN_ENTER_FIELD(e, x, y) \ (IN_LEV_FIELD(x, y) && (IS_FREE_OR_PLAYER(x, y) || \ + (CAN_MOVE_INTO_ACID(e) && \ + Feld[x][y] == EL_ACID) || \ IS_FOOD_DARK_YAMYAM(Feld[x][y]))) -#define PACMAN_CAN_ENTER_FIELD(x, y) \ +#define PACMAN_CAN_ENTER_FIELD(e, x, y) \ (IN_LEV_FIELD(x, y) && (IS_FREE_OR_PLAYER(x, y) || \ + (CAN_MOVE_INTO_ACID(e) && \ + Feld[x][y] == EL_ACID) || \ IS_AMOEBOID(Feld[x][y]))) -#define PIG_CAN_ENTER_FIELD(x, y) \ +#define PIG_CAN_ENTER_FIELD(e, x, y) \ (IN_LEV_FIELD(x, y) && (IS_FREE(x, y) || \ + (CAN_MOVE_INTO_ACID(e) && \ + Feld[x][y] == EL_ACID) || \ IS_FOOD_PIG(Feld[x][y]))) -#define PENGUIN_CAN_ENTER_FIELD(x, y) \ +#define PENGUIN_CAN_ENTER_FIELD(e, x, y) \ (IN_LEV_FIELD(x, y) && (IS_FREE(x, y) || \ + (CAN_MOVE_INTO_ACID(e) && \ + Feld[x][y] == EL_ACID) || \ IS_FOOD_PENGUIN(Feld[x][y]) || \ - Feld[x][y] == EL_EXIT_OPEN || \ - Feld[x][y] == EL_ACID)) + Feld[x][y] == EL_EXIT_OPEN)) -#if 0 -#if 1 -#define MAZE_RUNNER_CAN_ENTER_FIELD(x, y) \ - (IN_LEV_FIELD(x, y) && IS_FREE(x, y)) -#else -#define MAZE_RUNNER_CAN_ENTER_FIELD(x, y) \ +#define DRAGON_CAN_ENTER_FIELD(e, x, y) \ (IN_LEV_FIELD(x, y) && (IS_FREE(x, y) || \ - IS_FOOD_DARK_YAMYAM(Feld[x][y]))) -#endif + (CAN_MOVE_INTO_ACID(e) && \ + Feld[x][y] == EL_ACID))) + +#define MOLE_CAN_ENTER_FIELD(e, x, y, condition) \ + (IN_LEV_FIELD(x, y) && (IS_FREE(x, y) || \ + (CAN_MOVE_INTO_ACID(e) && \ + Feld[x][y] == EL_ACID) || \ + (condition))) + +#define SPRING_CAN_ENTER_FIELD(e, x, y) \ + (IN_LEV_FIELD(x, y) && (IS_FREE(x, y) || \ + (CAN_MOVE_INTO_ACID(e) && \ + Feld[x][y] == EL_ACID))) + #endif +#define GROUP_NR(e) ((e) - EL_GROUP_START) #define MOVE_ENTER_EL(e) (element_info[e].move_enter_element) -#define IS_IN_GROUP(e, g) (element_info[e].in_group[g] == TRUE) +#define IS_IN_GROUP(e, nr) (element_info[e].in_group[nr] == TRUE) #define IS_IN_GROUP_EL(e, ge) (IS_IN_GROUP(e, (ge) - EL_GROUP_START)) +#define IS_EQUAL_OR_IN_GROUP(e, ge) \ + (IS_GROUP_ELEMENT(ge) ? IS_IN_GROUP(e, GROUP_NR(ge)) : (e) == (ge)) + +#if 0 #define CE_ENTER_FIELD_COND(e, x, y) \ (!IS_PLAYER(x, y) && \ (Feld[x][y] == EL_ACID || \ - Feld[x][y] == MOVE_ENTER_EL(e) || \ - (IS_GROUP_ELEMENT(MOVE_ENTER_EL(e)) && \ - IS_IN_GROUP_EL(Feld[x][y], MOVE_ENTER_EL(e))))) + IS_EQUAL_OR_IN_GROUP(Feld[x][y], MOVE_ENTER_EL(e)))) +#else +#define CE_ENTER_FIELD_COND(e, x, y) \ + (!IS_PLAYER(x, y) && \ + IS_EQUAL_OR_IN_GROUP(Feld[x][y], MOVE_ENTER_EL(e))) +#endif #define CUSTOM_ELEMENT_CAN_ENTER_FIELD(e, x, y) \ - ELEMENT_CAN_ENTER_FIELD_GENERIC(e, x, y, CE_ENTER_FIELD_COND(e, x, y)) - -#define MOLE_CAN_ENTER_FIELD(x, y, condition) \ - (IN_LEV_FIELD(x, y) && (IS_FREE(x, y) || (condition))) + ELEMENT_CAN_ENTER_FIELD_BASE_4(e, x, y, CE_ENTER_FIELD_COND(e, x, y)) #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)) @@ -202,20 +275,43 @@ static boolean MovePlayer(struct PlayerInfo *, int, int); static void ScrollPlayer(struct PlayerInfo *, int); static void ScrollScreen(struct PlayerInfo *, int); +int DigField(struct PlayerInfo *, int, int, int, int, int, int, int); + static void InitBeltMovement(void); static void CloseAllOpenTimegates(void); static void CheckGravityMovement(struct PlayerInfo *); -static void KillHeroUnlessProtected(int, int); +static void CheckGravityMovementWhenNotMoving(struct PlayerInfo *); +static void KillHeroUnlessEnemyProtected(int, int); +static void KillHeroUnlessExplosionProtected(int, int); static void TestIfPlayerTouchesCustomElement(int, int); static void TestIfElementTouchesCustomElement(int, int); static void TestIfElementHitsCustomElement(int, int, int); +#if 0 +static void TestIfElementSmashesCustomElement(int, int, int); +#endif static void ChangeElement(int, int, int); -static boolean CheckTriggeredElementSideChange(int, int, int, int, int); -static boolean CheckTriggeredElementChange(int, int, int, int); -static boolean CheckElementSideChange(int, int, int, int, int, int); -static boolean CheckElementChange(int, int, int, int); + +static boolean CheckTriggeredElementChangeExt(int, int, int, int, int,int,int); +#define CheckTriggeredElementChange(x, y, e, ev) \ + CheckTriggeredElementChangeExt(x, y, e, ev, -1, CH_SIDE_ANY, -1) +#define CheckTriggeredElementChangePlayer(x, y, e, ev, p, s) \ + CheckTriggeredElementChangeExt(x, y, e, ev, p, s, -1) +#define CheckTriggeredElementChangeSide(x, y, e, ev, s) \ + CheckTriggeredElementChangeExt(x, y, e, ev, -1, s, -1) +#define CheckTriggeredElementChangePage(x, y, e, ev, p) \ + CheckTriggeredElementChangeExt(x, y, e, ev, -1, CH_SIDE_ANY, p) + +static boolean CheckElementChangeExt(int, int, int, int, int, int, int); +#define CheckElementChange(x, y, e, ev) \ + CheckElementChangeExt(x, y, e, ev, -1, CH_SIDE_ANY, -1) +#define CheckElementChangePlayer(x, y, e, ev, p, s) \ + CheckElementChangeExt(x, y, e, ev, p, s, -1) +#define CheckElementChangeSide(x, y, e, ev, s) \ + CheckElementChangeExt(x, y, e, ev, -1, s, -1) +#define CheckElementChangePage(x, y, e, ev, p) \ + CheckElementChangeExt(x, y, e, ev, -1, CH_SIDE_ANY, p) static void PlayLevelSound(int, int, int); static void PlayLevelSoundNearest(int, int, int); @@ -485,6 +581,28 @@ collect_count_list[] = { EL_UNDEFINED, 0 }, }; +struct +{ + int element; + int direction; +} +tube_access[] = +{ + { EL_TUBE_ANY, MV_LEFT | MV_RIGHT | MV_UP | MV_DOWN }, + { EL_TUBE_VERTICAL, MV_UP | MV_DOWN }, + { EL_TUBE_HORIZONTAL, MV_LEFT | MV_RIGHT }, + { EL_TUBE_VERTICAL_LEFT, MV_LEFT | MV_UP | MV_DOWN }, + { EL_TUBE_VERTICAL_RIGHT, MV_RIGHT | MV_UP | MV_DOWN }, + { EL_TUBE_HORIZONTAL_UP, MV_LEFT | MV_RIGHT | MV_UP }, + { EL_TUBE_HORIZONTAL_DOWN, MV_LEFT | MV_RIGHT | MV_DOWN }, + { EL_TUBE_LEFT_UP, MV_LEFT | MV_UP }, + { EL_TUBE_LEFT_DOWN, MV_LEFT | MV_DOWN }, + { EL_TUBE_RIGHT_UP, MV_RIGHT | MV_UP }, + { EL_TUBE_RIGHT_DOWN, MV_RIGHT | MV_DOWN }, + + { EL_UNDEFINED, 0 } +}; + static unsigned long trigger_events[MAX_NUM_ELEMENTS]; #define IS_AUTO_CHANGING(e) (element_info[e].change_events & \ @@ -595,6 +713,10 @@ static void InitPlayerField(int x, int y, int element, boolean init_game) player->present = TRUE; + player->block_last_field = (element == EL_SP_MURPHY ? + level.sp_block_last_field : + level.block_last_field); + if (!options.network || player->connected) { player->active = TRUE; @@ -799,9 +921,22 @@ static void InitField(int x, int y, boolean init_game) else if (IS_GROUP_ELEMENT(element)) { struct ElementGroupInfo *group = element_info[element].group; - int random_pos = RND(group->num_elements_resolved); + int last_anim_random_frame = gfx.anim_random_frame; + int element_pos; + + if (group->choice_mode == ANIM_RANDOM) + gfx.anim_random_frame = RND(group->num_elements_resolved); + + element_pos = getAnimationFrame(group->num_elements_resolved, 1, + group->choice_mode, 0, + group->choice_pos); - Feld[x][y] = group->element_resolved[random_pos]; + if (group->choice_mode == ANIM_RANDOM) + gfx.anim_random_frame = last_anim_random_frame; + + group->choice_pos++; + + Feld[x][y] = group->element_resolved[element_pos]; InitField(x, y, init_game); } @@ -809,24 +944,106 @@ static void InitField(int x, int y, boolean init_game) } } +static inline void InitField_WithBug1(int x, int y, boolean init_game) +{ + InitField(x, y, init_game); + + /* not needed to call InitMovDir() -- already done by InitField()! */ + if (game.engine_version < VERSION_IDENT(3,1,0,0) && + CAN_MOVE(Feld[x][y])) + InitMovDir(x, y); +} + +static inline void InitField_WithBug2(int x, int y, boolean init_game) +{ + int old_element = Feld[x][y]; + + InitField(x, y, init_game); + + /* not needed to call InitMovDir() -- already done by InitField()! */ + if (game.engine_version < VERSION_IDENT(3,1,0,0) && + CAN_MOVE(old_element) && + (old_element < EL_MOLE_LEFT || old_element > EL_MOLE_DOWN)) + InitMovDir(x, y); + + /* this case is in fact a combination of not less than three bugs: + first, it calls InitMovDir() for elements that can move, although this is + already done by InitField(); then, it checks the element that was at this + field _before_ the call to InitField() (which can change it) + + */ +} + +inline void DrawGameValue_Emeralds(int value) +{ + DrawText(DX_EMERALDS, DY_EMERALDS, int2str(value, 3), FONT_TEXT_2); +} + +inline void DrawGameValue_Dynamite(int value) +{ + DrawText(DX_DYNAMITE, DY_DYNAMITE, int2str(value, 3), FONT_TEXT_2); +} + +inline void DrawGameValue_Keys(struct PlayerInfo *player) +{ + int i; + + for (i = 0; i < MAX_KEYS; i++) + if (player->key[i]) + DrawMiniGraphicExt(drawto, DX_KEYS + i * MINI_TILEX, DY_KEYS, + el2edimg(EL_KEY_1 + i)); +} + +inline void DrawGameValue_Score(int value) +{ + DrawText(DX_SCORE, DY_SCORE, int2str(value, 5), FONT_TEXT_2); +} + +inline void DrawGameValue_Time(int value) +{ + if (value < 1000) + DrawText(DX_TIME1, DY_TIME, int2str(value, 3), FONT_TEXT_2); + else + DrawText(DX_TIME2, DY_TIME, int2str(value, 4), FONT_LEVEL_NUMBER); +} + +inline void DrawGameValue_Level(int value) +{ + if (level_nr < 100) + DrawText(DX_LEVEL, DY_LEVEL, int2str(value, 2), FONT_TEXT_2); + else + { + /* misuse area for displaying emeralds to draw bigger level number */ + DrawTextExt(drawto, DX_EMERALDS, DY_EMERALDS, + int2str(value, 3), FONT_LEVEL_NUMBER, BLIT_OPAQUE); + + /* now copy it to the area for displaying level number */ + BlitBitmap(drawto, drawto, + DX_EMERALDS, DY_EMERALDS + 1, + getFontWidth(FONT_LEVEL_NUMBER) * 3, + getFontHeight(FONT_LEVEL_NUMBER) - 1, + DX_LEVEL - 1, DY_LEVEL + 1); + + /* restore the area for displaying emeralds */ + DrawGameValue_Emeralds(local_player->gems_still_needed); + + /* yes, this is all really ugly :-) */ + } +} + void DrawGameDoorValues() { - int i, j; + int i; + + DrawGameValue_Level(level_nr); for (i = 0; i < MAX_PLAYERS; i++) - for (j = 0; j < 4; j++) - if (stored_player[i].key[j]) - DrawMiniGraphicExt(drawto, DX_KEYS + j * MINI_TILEX, DY_KEYS, - el2edimg(EL_KEY_1 + j)); + DrawGameValue_Keys(&stored_player[i]); - DrawText(DX + XX_EMERALDS, DY + YY_EMERALDS, - int2str(local_player->gems_still_needed, 3), FONT_TEXT_2); - DrawText(DX + XX_DYNAMITE, DY + YY_DYNAMITE, - int2str(local_player->inventory_size, 3), FONT_TEXT_2); - DrawText(DX + XX_SCORE, DY + YY_SCORE, - int2str(local_player->score, 5), FONT_TEXT_2); - DrawText(DX + XX_TIME, DY + YY_TIME, - int2str(TimeLeft, 3), FONT_TEXT_2); + DrawGameValue_Emeralds(local_player->gems_still_needed); + DrawGameValue_Dynamite(local_player->inventory_size); + DrawGameValue_Score(local_player->score); + DrawGameValue_Time(TimeLeft); } static void resolve_group_element(int group_element, int recursion_depth) @@ -842,7 +1059,7 @@ static void resolve_group_element(int group_element, int recursion_depth) group_element - EL_GROUP_START + 1); /* replace element which caused too deep recursion by question mark */ - group->element_resolved[group->num_elements_resolved++] = EL_CHAR_QUESTION; + group->element_resolved[group->num_elements_resolved++] = EL_UNKNOWN; return; } @@ -850,8 +1067,10 @@ static void resolve_group_element(int group_element, int recursion_depth) if (recursion_depth == 0) /* initialization */ { group = element_info[group_element].group; - group->num_elements_resolved = 0; group_nr = group_element - EL_GROUP_START; + + group->num_elements_resolved = 0; + group->choice_pos = 0; } for (i = 0; i < actual_group->num_elements; i++) @@ -1037,7 +1256,16 @@ static void InitGameEngine() { int trigger_element = ei->change_page[j].trigger_element; - trigger_events[trigger_element] |= ei->change_page[j].events; + if (IS_GROUP_ELEMENT(trigger_element)) + { + struct ElementGroupInfo *group = element_info[trigger_element].group; + + for (k = 0; k < group->num_elements_resolved; k++) + trigger_events[group->element_resolved[k]] + |= ei->change_page[j].events; + } + else + trigger_events[trigger_element] |= ei->change_page[j].events; } } } @@ -1070,6 +1298,19 @@ static void InitGameEngine() element_info[e].push_delay_random = push_delay_list[i].push_delay_random; } + /* set push delay value for Supaplex elements for newer engine versions */ + if (game.engine_version >= VERSION_IDENT(3,1,0,0)) + { + for (i = 0; i < MAX_NUM_ELEMENTS; i++) + { + if (IS_SP_ELEMENT(i)) + { + element_info[i].push_delay_fixed = 6; /* just enough to escape ... */ + element_info[i].push_delay_random = 0; /* ... from falling zonk */ + } + } + } + /* ---------- initialize move stepsize ----------------------------------- */ /* initialize move stepsize values to default */ @@ -1085,6 +1326,14 @@ static void InitGameEngine() element_info[e].move_stepsize = move_stepsize_list[i].move_stepsize; } + /* ---------- initialize move dig/leave ---------------------------------- */ + + for (i = 0; i < MAX_NUM_ELEMENTS; i++) + { + element_info[i].can_leave_element = FALSE; + element_info[i].can_leave_element_last = FALSE; + } + /* ---------- initialize gem count --------------------------------------- */ /* initialize gem count values for each element */ @@ -1096,6 +1345,18 @@ static void InitGameEngine() for (i = 0; collect_count_list[i].element != EL_UNDEFINED; i++) element_info[collect_count_list[i].element].collect_count = collect_count_list[i].count; + + /* ---------- initialize access direction -------------------------------- */ + + /* initialize access direction values to default */ + for (i = 0; i < MAX_NUM_ELEMENTS; i++) + if (!IS_CUSTOM_ELEMENT(i)) + element_info[i].access_direction = MV_ALL_DIRECTIONS; + + /* set access direction value for certain elements from pre-defined list */ + for (i = 0; tube_access[i].element != EL_UNDEFINED; i++) + element_info[tube_access[i].element].access_direction = + tube_access[i].direction; } @@ -1134,6 +1395,7 @@ void InitGame() struct PlayerInfo *player = &stored_player[i]; player->index_nr = i; + player->index_bit = (1 << i); player->element_nr = EL_PLAYER_1 + i; player->present = FALSE; @@ -1149,7 +1411,7 @@ void InitGame() player->lights_still_needed = 0; player->friends_still_needed = 0; - for (j = 0; j < 4; j++) + for (j = 0; j < MAX_KEYS; j++) player->key[j] = FALSE; player->dynabomb_count = 0; @@ -1167,6 +1429,9 @@ void InitGame() player->use_murphy_graphic = FALSE; + player->block_last_field = FALSE; + player->can_fall_into_acid = CAN_MOVE_INTO_ACID(player->element_nr); + player->actual_frame_counter = 0; player->step_counter = 0; @@ -1250,9 +1515,10 @@ void InitGame() player->shield_normal_time_left = 0; player->shield_deadly_time_left = 0; + player->inventory_infinite_element = EL_UNDEFINED; player->inventory_size = 0; - DigField(player, 0, 0, 0, 0, DF_NO_PUSH); + DigField(player, 0, 0, 0, 0, 0, 0, DF_NO_PUSH); SnapField(player, 0, 0); player->LevelSolved = FALSE; @@ -1273,6 +1539,7 @@ void InitGame() TimeFrames = 0; TimePlayed = 0; TimeLeft = level.time; + TapeTime = 0; ScreenMovDir = MV_NO_MOVING; ScreenMovPos = 0; @@ -1294,7 +1561,7 @@ void InitGame() game.envelope_active = FALSE; - for (i = 0; i < 4; i++) + for (i = 0; i < NUM_BELTS; i++) { game.belt_dir[i] = MV_NO_MOVING; game.belt_dir_nr[i] = 3; /* not moving, next moving left */ @@ -1322,6 +1589,7 @@ void InitGame() ChangeEvent[x][y] = CE_BITMASK_DEFAULT; ExplodePhase[x][y] = 0; + ExplodeDelay[x][y] = 0; ExplodeField[x][y] = EX_NO_EXPLOSION; RunnerVisit[x][y] = 0; @@ -1356,8 +1624,41 @@ void InitGame() emulate_sb ? EMU_SOKOBAN : emulate_sp ? EMU_SUPAPLEX : EMU_NONE); + /* initialize explosion and ignition delay */ + for (i = 0; i < MAX_NUM_ELEMENTS; i++) + { + if (!IS_CUSTOM_ELEMENT(i)) + { + int num_phase = 8; + int delay = ((IS_SP_ELEMENT(i) && + game.engine_version >= VERSION_IDENT(3,1,0,0)) || + game.emulation == EMU_SUPAPLEX ? 3 : 2); + int last_phase = (num_phase + 1) * delay; + int half_phase = (num_phase / 2) * delay; + + element_info[i].explosion_delay = last_phase - 1; + element_info[i].ignition_delay = half_phase; + +#if 0 + if (i == EL_BLACK_ORB) + element_info[i].ignition_delay = 0; +#else + if (i == EL_BLACK_ORB) + element_info[i].ignition_delay = 1; +#endif + } + +#if 0 + if (element_info[i].explosion_delay < 1) /* !!! check again !!! */ + element_info[i].explosion_delay = 1; + + if (element_info[i].ignition_delay < 1) /* !!! check again !!! */ + element_info[i].ignition_delay = 1; +#endif + } + /* correct non-moving belts to start moving left */ - for (i = 0; i < 4; i++) + for (i = 0; i < NUM_BELTS; i++) if (game.belt_dir[i] == MV_NO_MOVING) game.belt_dir_nr[i] = 3; /* not moving, next moving left */ @@ -1378,7 +1679,13 @@ void InitGame() { player->present = TRUE; player->active = TRUE; + some_player->present = FALSE; + some_player->active = FALSE; + +#if 0 + player->element_nr = some_player->element_nr; +#endif StorePlayer[jx][jy] = player->element_nr; player->jx = player->last_jx = jx; @@ -1392,7 +1699,7 @@ void InitGame() if (tape.playing) { - /* when playing a tape, eliminate all players who do not participate */ + /* when playing a tape, eliminate all players which do not participate */ for (i = 0; i < MAX_PLAYERS; i++) { @@ -1423,6 +1730,8 @@ void InitGame() int jx = player->jx, jy = player->jy; player->active = FALSE; + player->present = FALSE; + StorePlayer[jx][jy] = 0; Feld[jx][jy] = EL_EMPTY; } @@ -1597,19 +1906,6 @@ void InitGame() BlitBitmap(graphic_info[IMG_GLOBAL_DOOR].bitmap, drawto, DOOR_GFX_PAGEX5, DOOR_GFX_PAGEY1, DXSIZE, DYSIZE, DX, DY); - if (level_nr < 100) - DrawText(DX + XX_LEVEL, DY + YY_LEVEL, int2str(level_nr, 2), FONT_TEXT_2); - else - { - DrawTextExt(drawto, DX + XX_EMERALDS, DY + YY_EMERALDS, - int2str(level_nr, 3), FONT_LEVEL_NUMBER, BLIT_OPAQUE); - BlitBitmap(drawto, drawto, - DX + XX_EMERALDS, DY + YY_EMERALDS + 1, - getFontWidth(FONT_LEVEL_NUMBER) * 3, - getFontHeight(FONT_LEVEL_NUMBER) - 1, - DX + XX_LEVEL - 1, DY + YY_LEVEL + 1); - } - DrawGameDoorValues(); UnmapGameButtons(); @@ -1635,7 +1931,7 @@ void InitGame() if (options.debug) { - for (i = 0; i < 4; i++) + for (i = 0; i < MAX_PLAYERS; i++) printf("Player %d %sactive.\n", i + 1, (stored_player[i].active ? "" : "not ")); } @@ -1727,18 +2023,19 @@ void InitMovDir(int x, int y) int move_direction_initial = ei->move_direction_initial; int move_pattern = ei->move_pattern; - if (move_direction_initial == MV_PREVIOUS) + if (move_direction_initial == MV_START_PREVIOUS) { if (MovDir[x][y] != MV_NO_MOVING) return; - move_direction_initial = MV_AUTOMATIC; + move_direction_initial = MV_START_AUTOMATIC; } - if (move_direction_initial & MV_ANY_DIRECTION) + if (move_direction_initial == MV_START_RANDOM) + MovDir[x][y] = 1 << RND(4); + else if (move_direction_initial & MV_ANY_DIRECTION) MovDir[x][y] = move_direction_initial; - else if (move_direction_initial == MV_RANDOM || - move_pattern == MV_ALL_DIRECTIONS || + else if (move_pattern == MV_ALL_DIRECTIONS || move_pattern == MV_TURNING_LEFT || move_pattern == MV_TURNING_RIGHT || move_pattern == MV_TURNING_LEFT_RIGHT || @@ -1754,7 +2051,7 @@ void InitMovDir(int x, int y) else if (move_pattern == MV_ALONG_LEFT_SIDE || move_pattern == MV_ALONG_RIGHT_SIDE) { - for (i = 0; i < 4; i++) + for (i = 0; i < NUM_DIRECTIONS; i++) { int x1 = x + xy[i][0]; int y1 = y + xy[i][1]; @@ -1781,7 +2078,7 @@ void InitMovDir(int x, int y) element != EL_BD_FIREFLY) break; - for (i = 0; i < 4; i++) + for (i = 0; i < NUM_DIRECTIONS; i++) { int x1 = x + xy[i][0]; int y1 = y + xy[i][1]; @@ -1866,7 +2163,9 @@ void GameWon() TimeLeft -= 10; else TimeLeft--; - DrawText(DX_TIME, DY_TIME, int2str(TimeLeft, 3), FONT_TEXT_2); + + DrawGameValue_Time(TimeLeft); + BackToFront(); if (!tape.playing) @@ -1892,7 +2191,9 @@ void GameWon() TimePlayed += 10; else TimePlayed++; - DrawText(DX_TIME, DY_TIME, int2str(TimePlayed, 3), FONT_TEXT_2); + + DrawGameValue_Time(TimePlayed); + BackToFront(); if (!tape.playing) @@ -2177,8 +2478,25 @@ void RemoveMovingField(int x, int y) if (IS_MOVING(x, y)) { Moving2Blocked(x, y, &newx, &newy); +#if 0 if (Feld[newx][newy] != EL_BLOCKED) return; +#else + if (Feld[newx][newy] != EL_BLOCKED) + { + /* element is moving, but target field is not free (blocked), but + already occupied by something different (example: acid pool); + in this case, only remove the moving field, but not the target */ + + RemoveField(oldx, oldy); + + Store[oldx][oldy] = Store2[oldx][oldy] = 0; + + DrawLevelField(oldx, oldy); + + return; + } +#endif } else if (element == EL_BLOCKED) { @@ -2268,9 +2586,17 @@ void CheckDynamite(int x, int y) Bang(x, y); } -void RelocatePlayer(int x, int y, int element) +void RelocatePlayer(int x, int y, int element_raw) { + int element = (element_raw == EL_SP_MURPHY ? EL_PLAYER_1 : element_raw); struct PlayerInfo *player = &stored_player[element - EL_PLAYER_1]; + boolean ffwd_delay = (tape.playing && tape.fast_forward); + boolean no_delay = (tape.index_search); + int frame_delay_value = (ffwd_delay ? FfwdFrameDelay : GameFrameDelay); + int wait_delay_value = (no_delay ? 0 : frame_delay_value); +#if 1 + int old_jx, old_jy; +#endif if (player->GameOver) /* do not reanimate dead player */ return; @@ -2291,7 +2617,7 @@ void RelocatePlayer(int x, int y, int element) DrawPlayer(player); BackToFront(); - Delay(GAME_FRAME_DELAY); + Delay(wait_delay_value); } DrawPlayer(player); /* needed here only to cleanup last field */ @@ -2300,9 +2626,49 @@ void RelocatePlayer(int x, int y, int element) player->is_moving = FALSE; } +#if 1 + old_jx = player->jx; + old_jy = player->jy; +#endif + Feld[x][y] = element; InitPlayerField(x, y, element, TRUE); +#if 0 + if (player == local_player) + { +#if 1 + + scroll_x += (local_player->jx - old_jx); + scroll_y += (local_player->jy - old_jy); + + /* don't scroll over playfield boundaries */ + if (scroll_x < SBX_Left || scroll_x > SBX_Right) + scroll_x = (scroll_x < SBX_Left ? SBX_Left : SBX_Right); + + /* don't scroll over playfield boundaries */ + if (scroll_y < SBY_Upper || scroll_y > SBY_Lower) + scroll_y = (scroll_y < SBY_Upper ? SBY_Upper : SBY_Lower); + +#else + scroll_x = (local_player->jx < SBX_Left + MIDPOSX ? SBX_Left : + local_player->jx > SBX_Right + MIDPOSX ? SBX_Right : + local_player->jx - MIDPOSX); + + scroll_y = (local_player->jy < SBY_Upper + MIDPOSY ? SBY_Upper : + local_player->jy > SBY_Lower + MIDPOSY ? SBY_Lower : + local_player->jy - MIDPOSY); +#endif + + RedrawPlayfield(TRUE, 0,0,0,0); +#if 0 + DrawAllPlayers(); + BackToFront(); +#endif + } + +#else + if (player == local_player) { int scroll_xx = -999, scroll_yy = -999; @@ -2335,23 +2701,34 @@ void RelocatePlayer(int x, int y, int element) /* scroll in two steps of half tile size to make things smoother */ BlitBitmap(drawto_field, window, fx, fy, SXSIZE, SYSIZE, SX, SY); FlushDisplay(); - Delay(GAME_FRAME_DELAY); + Delay(wait_delay_value); /* scroll second step to align at full tile size */ BackToFront(); - Delay(GAME_FRAME_DELAY); + Delay(wait_delay_value); } } +#endif } void Explode(int ex, int ey, int phase, int mode) { int x, y; +#if 0 int num_phase = 9; +#endif + + /* !!! eliminate this variable !!! */ int delay = (game.emulation == EMU_SUPAPLEX ? 3 : 2); + +#if 1 + int last_phase; +#else int last_phase = num_phase * delay; int half_phase = (num_phase / 2) * delay; int first_phase_after_start = EX_PHASE_START + 1; +#endif + int border_element; if (game.explosions_delayed) { @@ -2363,6 +2740,10 @@ void Explode(int ex, int ey, int phase, int mode) { int center_element = Feld[ex][ey]; +#if 0 + printf("::: start explosion %d,%d [%d]\n", ex, ey, FrameCounter); +#endif + #if 0 /* --- This is only really needed (and now handled) in "Impact()". --- */ /* do not explode moving elements that left the explode field in time */ @@ -2386,16 +2767,34 @@ void Explode(int ex, int ey, int phase, int mode) Feld[ex][ey] = center_element; } +#if 1 + +#if 1 + last_phase = element_info[center_element].explosion_delay + 1; +#else + last_phase = element_info[center_element].explosion_delay; +#endif + +#if 0 + printf("::: %d -> %d\n", center_element, last_phase); +#endif +#endif + for (y = ey - 1; y <= ey + 1; y++) for (x = ex - 1; x <= ex + 1; x++) { int xx = x - ex + 1; int yy = y - ey + 1; int element; +#if 1 + if (!IN_LEV_FIELD(x, y) || (mode != EX_NORMAL && (x != ex || y != ey))) + continue; +#else if (!IN_LEV_FIELD(x, y) || ((mode != EX_NORMAL || center_element == EL_AMOEBA_TO_DIAMOND) && (x != ex || y != ey))) continue; +#endif element = Feld[x][y]; @@ -2465,27 +2864,32 @@ void Explode(int ex, int ey, int phase, int mode) RemoveField(x, y); #endif - if (IS_PLAYER(ex, ey) && !PLAYER_PROTECTED(ex, ey)) + if (IS_PLAYER(ex, ey) && !PLAYER_EXPLOSION_PROTECTED(ex, ey)) { switch(StorePlayer[ex][ey]) { case EL_PLAYER_2: - Store[x][y] = EL_EMERALD_RED; + Store[x][y] = EL_PLAYER_IS_EXPLODING_2; break; case EL_PLAYER_3: - Store[x][y] = EL_EMERALD; + Store[x][y] = EL_PLAYER_IS_EXPLODING_3; break; case EL_PLAYER_4: - Store[x][y] = EL_EMERALD_PURPLE; + Store[x][y] = EL_PLAYER_IS_EXPLODING_4; break; case EL_PLAYER_1: default: - Store[x][y] = EL_EMERALD_YELLOW; + Store[x][y] = EL_PLAYER_IS_EXPLODING_1; break; } +#if 1 + if (PLAYERINFO(ex, ey)->use_murphy_graphic) + Store[x][y] = EL_EMPTY; +#else if (game.emulation == EMU_SUPAPLEX) Store[x][y] = EL_EMPTY; +#endif } else if (center_element == EL_MOLE) Store[x][y] = EL_EMERALD_RED; @@ -2556,6 +2960,18 @@ void Explode(int ex, int ey, int phase, int mode) #endif ExplodePhase[x][y] = 1; +#if 1 + ExplodeDelay[x][y] = last_phase; +#endif + +#if 0 +#if 1 + GfxFrame[x][y] = 0; /* animation does not start until next frame */ +#else + GfxFrame[x][y] = -1; /* animation does not start until next frame */ +#endif +#endif + Stop[x][y] = TRUE; } @@ -2572,7 +2988,20 @@ void Explode(int ex, int ey, int phase, int mode) x = ex; y = ey; - ExplodePhase[x][y] = (phase < last_phase ? phase + 1 : 0); +#if 1 + if (phase == 1) + GfxFrame[x][y] = 0; /* restart explosion animation */ +#endif + +#if 0 + printf(":X: phase == %d [%d]\n", phase, GfxFrame[x][y]); +#endif + +#if 1 + last_phase = ExplodeDelay[x][y]; +#endif + + ExplodePhase[x][y] = (phase < last_phase ? phase + 1 : 0); #ifdef DEBUG @@ -2592,6 +3021,73 @@ void Explode(int ex, int ey, int phase, int mode) } #endif +#if 1 + + border_element = Store2[x][y]; + if (IS_PLAYER(x, y)) + border_element = StorePlayer[x][y]; + +#if 0 + printf("::: phase == %d\n", phase); +#endif + + if (phase == element_info[border_element].ignition_delay || + phase == last_phase) + { + boolean border_explosion = FALSE; + +#if 1 + if (IS_PLAYER(x, y) && PLAYERINFO(x, y)->present) +#else + if (IS_PLAYER(x, y)) +#endif + { + KillHeroUnlessExplosionProtected(x, y); + border_explosion = TRUE; + +#if 0 + if (phase == last_phase) + printf("::: IS_PLAYER\n"); +#endif + } + else if (CAN_EXPLODE_BY_EXPLOSION(border_element)) + { + Feld[x][y] = Store2[x][y]; + Store2[x][y] = 0; + Bang(x, y); + border_explosion = TRUE; + +#if 0 + if (phase == last_phase) + printf("::: CAN_EXPLODE_BY_EXPLOSION\n"); +#endif + } + else if (border_element == EL_AMOEBA_TO_DIAMOND) + { + AmoebeUmwandeln(x, y); + Store2[x][y] = 0; + border_explosion = TRUE; + +#if 0 + if (phase == last_phase) + printf("::: EL_AMOEBA_TO_DIAMOND [%d, %d] [%d]\n", + element_info[border_element].explosion_delay, + element_info[border_element].ignition_delay, + phase); +#endif + } + +#if 1 + /* if an element just explodes due to another explosion (chain-reaction), + do not immediately end the new explosion when it was the last frame of + the explosion (as it would be done in the following "if"-statement!) */ + if (border_explosion && phase == last_phase) + return; +#endif + } + +#else + if (phase == first_phase_after_start) { int element = Store2[x][y]; @@ -2608,8 +3104,8 @@ void Explode(int ex, int ey, int phase, int mode) int element = Store2[x][y]; if (IS_PLAYER(x, y)) - KillHeroUnlessProtected(x, y); - else if (CAN_EXPLODE_BY_FIRE(element)) + KillHeroUnlessExplosionProtected(x, y); + else if (CAN_EXPLODE_BY_EXPLOSION(element)) { Feld[x][y] = Store2[x][y]; Store2[x][y] = 0; @@ -2618,15 +3114,31 @@ void Explode(int ex, int ey, int phase, int mode) else if (element == EL_AMOEBA_TO_DIAMOND) AmoebeUmwandeln(x, y); } +#endif if (phase == last_phase) { int element; +#if 0 + printf("::: explosion %d,%d done [%d]\n", x, y, FrameCounter); +#endif + element = Feld[x][y] = Store[x][y]; Store[x][y] = Store2[x][y] = 0; GfxElement[x][y] = EL_UNDEFINED; + /* player can escape from explosions and might therefore be still alive */ + if (element >= EL_PLAYER_IS_EXPLODING_1 && + element <= EL_PLAYER_IS_EXPLODING_4) + Feld[x][y] = (stored_player[element - EL_PLAYER_IS_EXPLODING_1].active ? + EL_EMPTY : + element == EL_PLAYER_IS_EXPLODING_1 ? EL_EMERALD_YELLOW : + element == EL_PLAYER_IS_EXPLODING_2 ? EL_EMERALD_RED : + element == EL_PLAYER_IS_EXPLODING_3 ? EL_EMERALD : + EL_EMERALD_PURPLE); + + /* restore probably existing indestructible background element */ if (Back[x][y] && IS_INDESTRUCTIBLE(Back[x][y])) element = Feld[x][y] = Back[x][y]; Back[x][y] = 0; @@ -2636,9 +3148,22 @@ void Explode(int ex, int ey, int phase, int mode) ChangeDelay[x][y] = 0; ChangePage[x][y] = -1; +#if 1 + InitField_WithBug2(x, y, FALSE); +#else InitField(x, y, FALSE); +#if 1 + /* !!! not needed !!! */ +#if 1 + if (game.engine_version < VERSION_IDENT(3,1,0,0) && + CAN_MOVE(Feld[x][y]) && Feld[x][y] != EL_MOLE) + InitMovDir(x, y); +#else if (CAN_MOVE(element)) InitMovDir(x, y); +#endif +#endif +#endif DrawLevelField(x, y); TestIfElementTouchesCustomElement(x, y); @@ -2646,13 +3171,17 @@ void Explode(int ex, int ey, int phase, int mode) if (GFX_CRUMBLED(element)) DrawLevelFieldCrumbledSandNeighbours(x, y); - if (IS_PLAYER(x, y) && !PLAYERINFO(x,y)->present) + if (IS_PLAYER(x, y) && !PLAYERINFO(x, y)->present) StorePlayer[x][y] = 0; if (ELEM_IS_PLAYER(element)) RelocatePlayer(x, y, element); } +#if 1 + else if (IN_SCR_FIELD(SCREENX(x), SCREENY(y))) +#else else if (phase >= delay && IN_SCR_FIELD(SCREENX(x), SCREENY(y))) +#endif { #if 1 int graphic = el_act2img(GfxElement[x][y], ACTION_EXPLODING); @@ -2662,7 +3191,20 @@ void Explode(int ex, int ey, int phase, int mode) stored == EL_SP_INFOTRON ? IMG_SP_EXPLOSION_INFOTRON : IMG_SP_EXPLOSION); #endif +#if 1 + int frame = getGraphicAnimationFrame(graphic, GfxFrame[x][y]); +#else int frame = getGraphicAnimationFrame(graphic, phase - delay); +#endif + +#if 0 + printf("::: phase == %d [%d]\n", phase, GfxFrame[x][y]); +#endif + +#if 0 + printf("::: %d / %d [%d - %d]\n", + GfxFrame[x][y], phase - delay, phase, delay); +#endif #if 0 printf("::: %d ['%s'] -> %d\n", GfxElement[x][y], @@ -2713,12 +3255,12 @@ void DynaExplode(int ex, int ey) Explode(ex, ey, EX_PHASE_START, EX_CENTER); - for (i = 0; i < 4; i++) + for (i = 0; i < NUM_DIRECTIONS; i++) { for (j = 1; j <= dynabomb_size; j++) { - int x = ex + j * xy[i % 4][0]; - int y = ey + j * xy[i % 4][1]; + int x = ex + j * xy[i][0]; + int y = ey + j * xy[i][1]; int element; if (!IN_LEV_FIELD(x, y) || IS_INDESTRUCTIBLE(Feld[x][y])) @@ -2751,7 +3293,7 @@ void Bang(int x, int y) #endif #if 1 - if (IS_PLAYER(x, y) && !PLAYER_PROTECTED(x, y)) + if (IS_PLAYER(x, y) && !PLAYER_EXPLOSION_PROTECTED(x, y)) #else if (IS_PLAYER(x, y)) #endif @@ -2804,6 +3346,9 @@ void Bang(int x, int y) case EL_PENGUIN: case EL_LAMP: case EL_LAMP_ACTIVE: +#if 1 + case EL_AMOEBA_TO_DIAMOND: +#endif if (IS_PLAYER(x, y)) Explode(x, y, EX_PHASE_START, EX_NORMAL); else @@ -2824,23 +3369,42 @@ void Bang(int x, int y) void SplashAcid(int x, int y) { +#if 1 + if (IN_LEV_FIELD(x - 1, y - 1) && IS_FREE(x - 1, y - 1) && + (!IN_LEV_FIELD(x - 1, y - 2) || + !CAN_FALL(MovingOrBlocked2Element(x - 1, y - 2)))) + Feld[x - 1][y - 1] = EL_ACID_SPLASH_LEFT; + + if (IN_LEV_FIELD(x + 1, y - 1) && IS_FREE(x + 1, y - 1) && + (!IN_LEV_FIELD(x + 1, y - 2) || + !CAN_FALL(MovingOrBlocked2Element(x + 1, y - 2)))) + Feld[x + 1][y - 1] = EL_ACID_SPLASH_RIGHT; + + PlayLevelSound(x, y, SND_ACID_SPLASHING); +#else + /* input: position of element entering acid (obsolete) */ + int element = Feld[x][y]; + if (!IN_LEV_FIELD(x, y + 1) || Feld[x][y + 1] != EL_ACID) + return; + if (element != EL_ACID_SPLASH_LEFT && element != EL_ACID_SPLASH_RIGHT) { PlayLevelSound(x, y, SND_ACID_SPLASHING); - if (IN_LEV_FIELD(x-1, y) && IS_FREE(x-1, y) && - (!IN_LEV_FIELD(x-1, y-1) || - !CAN_FALL(MovingOrBlocked2Element(x-1, y-1)))) - Feld[x-1][y] = EL_ACID_SPLASH_LEFT; + if (IN_LEV_FIELD(x - 1, y) && IS_FREE(x - 1, y) && + (!IN_LEV_FIELD(x - 1, y - 1) || + !CAN_FALL(MovingOrBlocked2Element(x - 1, y - 1)))) + Feld[x - 1][y] = EL_ACID_SPLASH_LEFT; - if (IN_LEV_FIELD(x+1, y) && IS_FREE(x+1, y) && - (!IN_LEV_FIELD(x+1, y-1) || - !CAN_FALL(MovingOrBlocked2Element(x+1, y-1)))) - Feld[x+1][y] = EL_ACID_SPLASH_RIGHT; + if (IN_LEV_FIELD(x + 1, y) && IS_FREE(x + 1, y) && + (!IN_LEV_FIELD(x + 1, y - 1) || + !CAN_FALL(MovingOrBlocked2Element(x + 1, y - 1)))) + Feld[x + 1][y] = EL_ACID_SPLASH_RIGHT; } +#endif } static void InitBeltMovement() @@ -2863,11 +3427,11 @@ static void InitBeltMovement() int x, y, i, j; /* set frame order for belt animation graphic according to belt direction */ - for (i = 0; i < 4; i++) + for (i = 0; i < NUM_BELTS; i++) { int belt_nr = i; - for (j = 0; j < 3; j++) + for (j = 0; j < NUM_BELT_PARTS; j++) { int element = belt_base_active_element[belt_nr] + j; int graphic = el2img(element); @@ -2885,7 +3449,7 @@ static void InitBeltMovement() { int element = Feld[x][y]; - for (i = 0; i < 4; i++) + for (i = 0; i < NUM_BELTS; i++) { if (IS_BELT(element) && game.belt_dir[i] != MV_NO_MOVING) { @@ -2951,7 +3515,7 @@ static void ToggleBeltSwitch(int x, int y) belt_dir_nr = 1; /* set frame order for belt animation graphic according to belt direction */ - for (i = 0; i < 3; i++) + for (i = 0; i < NUM_BELT_PARTS; i++) { int element = belt_base_active_element[belt_nr] + i; int graphic = el2img(element); @@ -3165,11 +3729,19 @@ inline static int getElementMoveStepsize(int x, int y) /* special values for move stepsize for spring and things on conveyor belt */ if (horiz_move) { +#if 0 + if (element == EL_SPRING) + step = sign * MOVE_STEPSIZE_NORMAL * 2; + else if (CAN_FALL(element) && !CAN_MOVE(element) && + y < lev_fieldy - 1 && IS_BELT_ACTIVE(Feld[x][y + 1])) + step = sign * MOVE_STEPSIZE_NORMAL / 2; +#else if (CAN_FALL(element) && y < lev_fieldy - 1 && IS_BELT_ACTIVE(Feld[x][y + 1])) step = sign * MOVE_STEPSIZE_NORMAL / 2; else if (element == EL_SPRING) step = sign * MOVE_STEPSIZE_NORMAL * 2; +#endif } return step; @@ -3209,7 +3781,7 @@ void Impact(int x, int y) if (!lastline && smashed == EL_ACID) /* element falls into acid */ { - SplashAcid(x, y); + SplashAcid(x, y + 1); return; } @@ -3242,7 +3814,7 @@ void Impact(int x, int y) if (impact && element == EL_AMOEBA_DROP) { if (object_hit && IS_PLAYER(x, y + 1)) - KillHeroUnlessProtected(x, y + 1); + KillHeroUnlessEnemyProtected(x, y + 1); else if (object_hit && smashed == EL_PENGUIN) Bang(x, y + 1); else @@ -3284,7 +3856,7 @@ void Impact(int x, int y) { if (CAN_SMASH_PLAYER(element)) { - KillHeroUnlessProtected(x, y + 1); + KillHeroUnlessEnemyProtected(x, y + 1); return; } } @@ -3304,11 +3876,13 @@ void Impact(int x, int y) return; } } - else if ((element == EL_SP_INFOTRON || - element == EL_SP_ZONK) && - (smashed == EL_SP_SNIKSNAK || - smashed == EL_SP_ELECTRON || - smashed == EL_SP_DISK_ORANGE)) + else if (((element == EL_SP_INFOTRON || + element == EL_SP_ZONK) && + (smashed == EL_SP_SNIKSNAK || + smashed == EL_SP_ELECTRON || + smashed == EL_SP_DISK_ORANGE)) || + (element == EL_SP_INFOTRON && + smashed == EL_SP_DISK_YELLOW)) { Bang(x, y + 1); return; @@ -3371,12 +3945,15 @@ void Impact(int x, int y) } else { +#if 0 + TestIfElementSmashesCustomElement(x, y, MV_DOWN); +#endif + CheckElementChange(x, y + 1, smashed, CE_SMASHED); - CheckTriggeredElementSideChange(x, y + 1, smashed, CH_SIDE_TOP, - CE_OTHER_IS_SWITCHING); - CheckElementSideChange(x, y + 1, smashed, CH_SIDE_TOP, - CE_SWITCHED, -1); + CheckTriggeredElementChangeSide(x, y + 1, smashed, + CE_OTHER_IS_SWITCHING, CH_SIDE_TOP); + CheckElementChangeSide(x, y + 1, smashed, CE_SWITCHED, CH_SIDE_TOP); } } else @@ -3458,9 +4035,9 @@ inline static void TurnRoundExt(int x, int y) { TestIfBadThingTouchesOtherBadThing(x, y); - if (ENEMY_CAN_ENTER_FIELD(right_x, right_y)) + if (ENEMY_CAN_ENTER_FIELD(element, right_x, right_y)) MovDir[x][y] = right_dir; - else if (!ENEMY_CAN_ENTER_FIELD(move_x, move_y)) + else if (!ENEMY_CAN_ENTER_FIELD(element, move_x, move_y)) MovDir[x][y] = left_dir; if (element == EL_BUG && MovDir[x][y] != old_move_dir) @@ -3468,14 +4045,15 @@ inline static void TurnRoundExt(int x, int y) else if (element == EL_BD_BUTTERFLY) /* && MovDir[x][y] == left_dir) */ MovDelay[x][y] = 1; } +#if 0 else if (element == EL_SPACESHIP || element == EL_BD_FIREFLY || element == EL_SP_SNIKSNAK || element == EL_SP_ELECTRON) { TestIfBadThingTouchesOtherBadThing(x, y); - if (ENEMY_CAN_ENTER_FIELD(left_x, left_y)) + if (ENEMY_CAN_ENTER_FIELD(element, left_x, left_y)) MovDir[x][y] = left_dir; - else if (!ENEMY_CAN_ENTER_FIELD(move_x, move_y)) + else if (!ENEMY_CAN_ENTER_FIELD(element, move_x, move_y)) MovDir[x][y] = right_dir; if ((element == EL_SPACESHIP || @@ -3486,10 +4064,38 @@ inline static void TurnRoundExt(int x, int y) else if (element == EL_BD_FIREFLY) /* && MovDir[x][y] == right_dir) */ MovDelay[x][y] = 1; } +#else + else if (element == EL_SPACESHIP || element == EL_BD_FIREFLY) + { + TestIfBadThingTouchesOtherBadThing(x, y); + + if (ENEMY_CAN_ENTER_FIELD(element, left_x, left_y)) + MovDir[x][y] = left_dir; + else if (!ENEMY_CAN_ENTER_FIELD(element, move_x, move_y)) + MovDir[x][y] = right_dir; + + if (element == EL_SPACESHIP && MovDir[x][y] != old_move_dir) + MovDelay[x][y] = 9; + else if (element == EL_BD_FIREFLY) /* && MovDir[x][y] == right_dir) */ + MovDelay[x][y] = 1; + } + else if (element == EL_SP_SNIKSNAK || element == EL_SP_ELECTRON) + { + TestIfBadThingTouchesOtherBadThing(x, y); + + if (ELEMENT_CAN_ENTER_FIELD_BASE_4(element, left_x, left_y, 0)) + MovDir[x][y] = left_dir; + else if (!ELEMENT_CAN_ENTER_FIELD_BASE_4(element, move_x, move_y, 0)) + MovDir[x][y] = right_dir; + + if (MovDir[x][y] != old_move_dir) + MovDelay[x][y] = 9; + } +#endif else if (element == EL_YAMYAM) { - boolean can_turn_left = YAMYAM_CAN_ENTER_FIELD(left_x, left_y); - boolean can_turn_right = YAMYAM_CAN_ENTER_FIELD(right_x, right_y); + boolean can_turn_left = YAMYAM_CAN_ENTER_FIELD(element, left_x, left_y); + boolean can_turn_right = YAMYAM_CAN_ENTER_FIELD(element, right_x, right_y); if (can_turn_left && can_turn_right) MovDir[x][y] = (RND(3) ? (RND(2) ? left_dir : right_dir) : back_dir); @@ -3504,8 +4110,10 @@ inline static void TurnRoundExt(int x, int y) } else if (element == EL_DARK_YAMYAM) { - 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); + boolean can_turn_left = DARK_YAMYAM_CAN_ENTER_FIELD(element, + left_x, left_y); + boolean can_turn_right = DARK_YAMYAM_CAN_ENTER_FIELD(element, + right_x, right_y); if (can_turn_left && can_turn_right) MovDir[x][y] = (RND(3) ? (RND(2) ? left_dir : right_dir) : back_dir); @@ -3520,8 +4128,8 @@ inline static void TurnRoundExt(int x, int y) } else if (element == EL_PACMAN) { - boolean can_turn_left = PACMAN_CAN_ENTER_FIELD(left_x, left_y); - boolean can_turn_right = PACMAN_CAN_ENTER_FIELD(right_x, right_y); + boolean can_turn_left = PACMAN_CAN_ENTER_FIELD(element, left_x, left_y); + boolean can_turn_right = PACMAN_CAN_ENTER_FIELD(element, right_x, right_y); if (can_turn_left && can_turn_right) MovDir[x][y] = (RND(3) ? (RND(2) ? left_dir : right_dir) : back_dir); @@ -3536,9 +4144,9 @@ inline static void TurnRoundExt(int x, int y) } else if (element == EL_PIG) { - 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 can_turn_left = PIG_CAN_ENTER_FIELD(element, left_x, left_y); + boolean can_turn_right = PIG_CAN_ENTER_FIELD(element, right_x, right_y); + boolean can_move_on = PIG_CAN_ENTER_FIELD(element, move_x, move_y); boolean should_turn_left, should_turn_right, should_move_on; int rnd_value = 24; int rnd = RND(rnd_value); @@ -3599,9 +4207,9 @@ inline static void TurnRoundExt(int x, int y) } else if (element == EL_DRAGON) { - 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); + boolean can_turn_left = DRAGON_CAN_ENTER_FIELD(element, left_x, left_y); + boolean can_turn_right = DRAGON_CAN_ENTER_FIELD(element, right_x, right_y); + boolean can_move_on = DRAGON_CAN_ENTER_FIELD(element, move_x, move_y); int rnd_value = 24; int rnd = RND(rnd_value); @@ -3649,17 +4257,17 @@ inline static void TurnRoundExt(int x, int y) else if (element == EL_MOLE) { boolean can_move_on = - (MOLE_CAN_ENTER_FIELD(move_x, move_y, + (MOLE_CAN_ENTER_FIELD(element, move_x, move_y, IS_AMOEBOID(Feld[move_x][move_y]) || Feld[move_x][move_y] == EL_AMOEBA_SHRINKING)); if (!can_move_on) { boolean can_turn_left = - (MOLE_CAN_ENTER_FIELD(left_x, left_y, + (MOLE_CAN_ENTER_FIELD(element, left_x, left_y, IS_AMOEBOID(Feld[left_x][left_y]))); boolean can_turn_right = - (MOLE_CAN_ENTER_FIELD(right_x, right_y, + (MOLE_CAN_ENTER_FIELD(element, right_x, right_y, IS_AMOEBOID(Feld[right_x][right_y]))); if (can_turn_left && can_turn_right) @@ -3680,10 +4288,16 @@ inline static void TurnRoundExt(int x, int y) } else if (element == EL_SPRING) { +#if 0 + if (MovDir[x][y] & MV_HORIZONTAL && + !SPRING_CAN_ENTER_FIELD(element, move_x, move_y)) + MovDir[x][y] = MV_NO_MOVING; +#else 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))) + (!SPRING_CAN_ENTER_FIELD(element, move_x, move_y) || + SPRING_CAN_ENTER_FIELD(element, x, y + 1))) MovDir[x][y] = MV_NO_MOVING; +#endif MovDelay[x][y] = 0; } @@ -3736,10 +4350,10 @@ inline static void TurnRoundExt(int x, int y) { 0, +1 } }; - for (i = 0; i < 4; i++) + for (i = 0; i < NUM_DIRECTIONS; i++) { - int ex = x + xy[i % 4][0]; - int ey = y + xy[i % 4][1]; + int ex = x + xy[i][0]; + int ey = y + xy[i][1]; if (IN_LEV_FIELD(ex, ey) && Feld[ex][ey] == EL_EXIT_OPEN) { @@ -3788,14 +4402,14 @@ inline static void TurnRoundExt(int x, int y) new_move_dir & (first_horiz ? MV_HORIZONTAL : MV_VERTICAL); Moving2Blocked(x, y, &newx, &newy); - if (PENGUIN_CAN_ENTER_FIELD(newx, newy)) + if (PENGUIN_CAN_ENTER_FIELD(EL_PENGUIN, newx, newy)) return; MovDir[x][y] = new_move_dir & (!first_horiz ? MV_HORIZONTAL : MV_VERTICAL); Moving2Blocked(x, y, &newx, &newy); - if (PENGUIN_CAN_ENTER_FIELD(newx, newy)) + if (PENGUIN_CAN_ENTER_FIELD(EL_PENGUIN, newx, newy)) return; MovDir[x][y] = old_move_dir; @@ -3817,14 +4431,14 @@ inline static void TurnRoundExt(int x, int 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)) + if (SATELLITE_CAN_ENTER_FIELD(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)) + if (SATELLITE_CAN_ENTER_FIELD(newx, newy)) return; MovDir[x][y] = old_move_dir; @@ -3974,7 +4588,7 @@ inline static void TurnRoundExt(int x, int y) else if (move_pattern == MV_WHEN_PUSHED || move_pattern == MV_WHEN_DROPPED) { - if (!IN_LEV_FIELD_AND_IS_FREE(move_x, move_y)) + if (!CUSTOM_ELEMENT_CAN_ENTER_FIELD(element, move_x, move_y)) MovDir[x][y] = MV_NO_MOVING; MovDelay[x][y] = 0; @@ -4007,7 +4621,7 @@ inline static void TurnRoundExt(int x, int y) int start_test = RND(4); int i; - for (i = 0; i < 4; i++) + for (i = 0; i < NUM_DIRECTIONS; i++) { int move_dir = test_dir[start_test + i]; int move_dir_preference; @@ -4100,7 +4714,9 @@ static boolean JustBeingPushed(int x, int y) void StartMoving(int x, int y) { +#if 0 boolean use_spring_bug = (game.engine_version < VERSION_IDENT(2,2,0,0)); +#endif boolean started_moving = FALSE; /* some elements can fall _and_ move */ int element = Feld[x][y]; @@ -4118,8 +4734,8 @@ void StartMoving(int x, int y) if (CAN_FALL(element) && y < lev_fieldy - 1) { - if ((x > 0 && IS_PLAYER(x - 1, y)) || - (x < lev_fieldx-1 && IS_PLAYER(x + 1, y))) + if ((x > 0 && IS_PLAYER(x - 1, y)) || + (x < lev_fieldx - 1 && IS_PLAYER(x + 1, y))) if (JustBeingPushed(x, y)) return; @@ -4249,7 +4865,7 @@ void StartMoving(int x, int y) else if (CAN_FALL(element) && Feld[x][y + 1] == EL_ACID) #endif { - SplashAcid(x, y); + SplashAcid(x, y + 1); InitMovingField(x, y, MV_DOWN); started_moving = TRUE; @@ -4297,7 +4913,7 @@ void StartMoving(int x, int y) Impact(x, y); } - else if (IS_FREE(x, y + 1) && element == EL_SPRING && use_spring_bug) + else if (IS_FREE(x, y + 1) && element == EL_SPRING && level.use_spring_bug) { if (MovDir[x][y] == MV_NO_MOVING) { @@ -4373,7 +4989,11 @@ void StartMoving(int x, int y) started_moving = TRUE; } } +#if 0 + else if (IS_BELT_ACTIVE(Feld[x][y + 1]) && !CAN_MOVE(element)) +#else else if (IS_BELT_ACTIVE(Feld[x][y + 1])) +#endif { boolean left_is_free = (x > 0 && IS_FREE(x - 1, y)); boolean right_is_free = (x < lev_fieldx - 1 && IS_FREE(x + 1, y)); @@ -4383,11 +5003,24 @@ void StartMoving(int x, int y) if ((belt_dir == MV_LEFT && left_is_free) || (belt_dir == MV_RIGHT && right_is_free)) { +#if 1 + int nextx = (belt_dir == MV_LEFT ? x - 1 : x + 1); +#endif + InitMovingField(x, y, belt_dir); started_moving = TRUE; +#if 1 + Pushed[x][y] = TRUE; + Pushed[nextx][y] = TRUE; +#endif + GfxAction[x][y] = ACTION_DEFAULT; } + else + { + MovDir[x][y] = 0; /* if element was moving, stop it */ + } } } @@ -4411,7 +5044,7 @@ void StartMoving(int x, int y) #endif #if 1 - if (game.engine_version >= VERSION_IDENT(3,0,9,0) && + if (game.engine_version >= VERSION_IDENT(3,1,0,0) && WasJustMoving[x][y] && IN_LEV_FIELD(newx, newy) && (Feld[newx][newy] == EL_BLOCKED || IS_PLAYER(newx, newy))) { @@ -4581,7 +5214,7 @@ void StartMoving(int x, int y) { int flamed = MovingOrBlocked2Element(xx, yy); - if (IS_CLASSIC_ENEMY(flamed) || CAN_EXPLODE_BY_FIRE(flamed)) + if (IS_CLASSIC_ENEMY(flamed) || CAN_EXPLODE_BY_DRAGONFIRE(flamed)) Bang(xx, yy); else RemoveMovingField(xx, yy); @@ -4623,7 +5256,7 @@ void StartMoving(int x, int y) if (DONT_COLLIDE_WITH(element) && IN_LEV_FIELD(newx, newy) && IS_PLAYER(newx, newy) && - !PLAYER_PROTECTED(newx, newy)) + !PLAYER_ENEMY_PROTECTED(newx, newy)) { #if 1 TestIfBadThingRunsIntoHero(x, y, MovDir[x][y]); @@ -4637,6 +5270,18 @@ void StartMoving(int x, int y) #endif } +#if 1 +#if 1 + else if (CAN_MOVE_INTO_ACID(element) && + IN_LEV_FIELD(newx, newy) && Feld[newx][newy] == EL_ACID && + (MovDir[x][y] == MV_DOWN || + game.engine_version >= VERSION_IDENT(3,1,0,0))) +#else + else if (CAN_MOVE_INTO_ACID(element) && MovDir[x][y] == MV_DOWN && + IN_LEV_FIELD(newx, newy) && Feld[newx][newy] == EL_ACID) +#endif +#else + else if ((element == EL_PENGUIN || element == EL_ROBOT || element == EL_SATELLITE || @@ -4644,8 +5289,9 @@ void StartMoving(int x, int y) IS_CUSTOM_ELEMENT(element)) && IN_LEV_FIELD(newx, newy) && MovDir[x][y] == MV_DOWN && Feld[newx][newy] == EL_ACID) +#endif { - SplashAcid(x, y); + SplashAcid(newx, newy); Store[x][y] = EL_ACID; } else if (element == EL_PENGUIN && IN_LEV_FIELD(newx, newy)) @@ -4673,7 +5319,7 @@ void StartMoving(int x, int y) } else if (IS_FOOD_PENGUIN(Feld[newx][newy])) { - if (DigField(local_player, newx, newy, 0, 0, DF_DIG) == MF_MOVING) + if (DigField(local_player, x, y, newx, newy, 0,0, DF_DIG) == MF_MOVING) DrawLevelField(newx, newy); else GfxDir[x][y] = MovDir[x][y] = MV_NO_MOVING; @@ -4731,6 +5377,8 @@ void StartMoving(int x, int y) ) { + int new_element = Feld[newx][newy]; + #if 0 printf("::: '%s' digs '%s' [%d]\n", element_info[element].token_name, @@ -4740,8 +5388,9 @@ void StartMoving(int x, int y) if (!IS_FREE(newx, newy)) { - int new_element = Feld[newx][newy]; - int sound; + int action = (IS_DIGGABLE(new_element) ? ACTION_DIGGING : + IS_COLLECTIBLE(new_element) ? ACTION_COLLECTING : + ACTION_BREAKING); /* no element can dig solid indestructible elements */ if (IS_INDESTRUCTIBLE(new_element) && @@ -4766,13 +5415,12 @@ void StartMoving(int x, int y) DrawLevelField(newx, newy); } - sound = (IS_DIGGABLE(new_element) ? ACTION_DIGGING : - IS_COLLECTIBLE(new_element) ? ACTION_COLLECTING : - ACTION_BREAKING); - - PlayLevelSoundAction(x, y, sound); + PlayLevelSoundAction(x, y, action); } + if (IS_EQUAL_OR_IN_GROUP(new_element, MOVE_ENTER_EL(element))) + element_info[element].can_leave_element = TRUE; + if (move_pattern & MV_MAZE_RUNNER_STYLE) { RunnerVisit[x][y] = FrameCounter; @@ -4858,8 +5506,15 @@ void StartMoving(int x, int y) AmoebaCnt[AmoebaNr[newx][newy]]--; } +#if 0 + /* !!! test !!! */ + if (IS_MOVING(newx, newy) || IS_BLOCKED(newx, newy)) +#else if (IS_MOVING(newx, newy)) +#endif + { RemoveMovingField(newx, newy); + } else { Feld[newx][newy] = EL_EMPTY; @@ -4953,6 +5608,7 @@ void StartMoving(int x, int y) void ContinueMoving(int x, int y) { int element = Feld[x][y]; + struct ElementInfo *ei = &element_info[element]; int direction = MovDir[x][y]; int dx = (direction == MV_LEFT ? -1 : direction == MV_RIGHT ? +1 : 0); int dy = (direction == MV_UP ? -1 : direction == MV_DOWN ? +1 : 0); @@ -4960,12 +5616,25 @@ void ContinueMoving(int x, int y) #if 0 int nextx = newx + dx, nexty = newy + dy; #endif - boolean pushed = Pushed[x][y]; +#if 1 + boolean pushed_by_player = (Pushed[x][y] && IS_PLAYER(x, y)); + boolean pushed_by_conveyor = (Pushed[x][y] && !IS_PLAYER(x, y)); +#else + boolean pushed_by_player = Pushed[x][y]; +#endif MovPos[x][y] += getElementMoveStepsize(x, y); - if (pushed) /* special case: moving object pushed by player */ +#if 0 + if (pushed_by_player && IS_PLAYER(x, y)) + { + /* special case: moving object pushed by player */ + MovPos[x][y] = SIGN(MovPos[x][y]) * (TILEX - ABS(PLAYERINFO(x,y)->MovPos)); + } +#else + if (pushed_by_player) /* special case: moving object pushed by player */ MovPos[x][y] = SIGN(MovPos[x][y]) * (TILEX - ABS(PLAYERINFO(x,y)->MovPos)); +#endif if (ABS(MovPos[x][y]) < TILEX) { @@ -5070,22 +5739,21 @@ void ContinueMoving(int x, int y) ResetGfxAnimation(x, y); /* reset animation values for old field */ #if 1 - if (IS_CUSTOM_ELEMENT(element) && !IS_PLAYER(x, y)) + /* some elements can leave other elements behind after moving */ + if (IS_CUSTOM_ELEMENT(element) && !IS_PLAYER(x, y) && + ei->move_leave_element != EL_EMPTY && + (ei->move_leave_type == LEAVE_TYPE_UNLIMITED || + ei->can_leave_element_last)) { - int new_element = element_info[element].move_leave_element; - - Feld[x][y] = new_element; - - if (new_element != EL_EMPTY) - { - InitField(x, y, FALSE); - - TestIfElementTouchesCustomElement(x, y); + Feld[x][y] = ei->move_leave_element; + InitField(x, y, FALSE); - if (GFX_CRUMBLED(new_element)) - DrawLevelFieldCrumbledSandNeighbours(x, y); - } + if (GFX_CRUMBLED(Feld[x][y])) + DrawLevelFieldCrumbledSandNeighbours(x, y); } + + ei->can_leave_element_last = ei->can_leave_element; + ei->can_leave_element = FALSE; #endif #if 0 @@ -5118,12 +5786,19 @@ void ContinueMoving(int x, int y) Stop[newx][newy] = TRUE; /* ignore this element until the next frame */ /* prevent pushed element from moving on in pushed direction */ - if (pushed && CAN_MOVE(element) && + if (pushed_by_player && CAN_MOVE(element) && element_info[element].move_pattern & MV_ANY_DIRECTION && !(element_info[element].move_pattern & direction)) TurnRound(newx, newy); - if (!pushed) /* special case: moving object pushed by player */ +#if 1 + /* prevent elements on conveyor belt from moving on in last direction */ + if (pushed_by_conveyor && CAN_FALL(element) && + direction & MV_HORIZONTAL) + MovDir[newx][newy] = 0; +#endif + + if (!pushed_by_player) { WasJustMoving[newx][newy] = 3; @@ -5147,7 +5822,7 @@ void ContinueMoving(int x, int y) Impact(x, newy); #if 1 - TestIfElementTouchesCustomElement(x, y); /* for empty space */ + TestIfElementTouchesCustomElement(x, y); /* empty or new element */ #endif #if 0 @@ -5166,21 +5841,13 @@ void ContinueMoving(int x, int y) int hitting_element = Feld[newx][newy]; /* !!! fix side (direction) orientation here and elsewhere !!! */ - CheckElementSideChange(newx, newy, hitting_element, - direction, CE_HITTING_SOMETHING, -1); + CheckElementChangeSide(newx, newy, hitting_element, CE_HITTING_SOMETHING, + direction); #if 0 if (IN_LEV_FIELD(nextx, nexty)) { - static int opposite_directions[] = - { - MV_RIGHT, - MV_LEFT, - MV_DOWN, - MV_UP - }; - int move_dir_bit = MV_DIR_BIT(direction); - int opposite_direction = opposite_directions[move_dir_bit]; + int opposite_direction = MV_DIR_OPPOSITE(direction); int hitting_side = direction; int touched_side = opposite_direction; int touched_element = MovingOrBlocked2Element(nextx, nexty); @@ -5192,8 +5859,8 @@ void ContinueMoving(int x, int y) { int i; - CheckElementSideChange(nextx, nexty, touched_element, - opposite_direction, CE_HIT_BY_SOMETHING, -1); + CheckElementChangeSide(nextx, nexty, touched_element, + CE_HIT_BY_SOMETHING, opposite_direction); if (IS_CUSTOM_ELEMENT(hitting_element) && HAS_ANY_CHANGE_EVENT(hitting_element, CE_OTHER_IS_HITTING)) @@ -5205,11 +5872,11 @@ void ContinueMoving(int x, int y) if (change->can_change && change->events & CH_EVENT_BIT(CE_OTHER_IS_HITTING) && - change->sides & touched_side && + change->trigger_side & touched_side && change->trigger_element == touched_element) { - CheckElementSideChange(newx, newy, hitting_element, - CH_SIDE_ANY, CE_OTHER_IS_HITTING, i); + CheckElementChangePage(newx, newy, hitting_element, + CE_OTHER_IS_HITTING, i); break; } } @@ -5225,11 +5892,11 @@ void ContinueMoving(int x, int y) if (change->can_change && change->events & CH_EVENT_BIT(CE_OTHER_GETS_HIT) && - change->sides & hitting_side && + change->trigger_side & hitting_side && change->trigger_element == hitting_element) { - CheckElementSideChange(nextx, nexty, touched_element, - CH_SIDE_ANY, CE_OTHER_GETS_HIT, i); + CheckElementChangePage(nextx, nexty, touched_element, + CE_OTHER_GETS_HIT, i); break; } } @@ -5257,7 +5924,7 @@ int AmoebeNachbarNr(int ax, int ay) { 0, +1 } }; - for (i = 0; i < 4; i++) + for (i = 0; i < NUM_DIRECTIONS; i++) { int x = ax + xy[i][0]; int y = ay + xy[i][1]; @@ -5287,7 +5954,7 @@ void AmoebenVereinigen(int ax, int ay) if (new_group_nr == 0) return; - for (i = 0; i < 4; i++) + for (i = 0; i < NUM_DIRECTIONS; i++) { x = ax + xy[i][0]; y = ay + xy[i][1]; @@ -5365,7 +6032,7 @@ void AmoebeUmwandeln(int ax, int ay) { 0, +1 } }; - for (i = 0; i < 4; i++) + for (i = 0; i < NUM_DIRECTIONS; i++) { x = ax + xy[i][0]; y = ay + xy[i][1]; @@ -5561,7 +6228,7 @@ void AmoebeAbleger(int ax, int ay) int start = RND(4); boolean waiting_for_player = FALSE; - for (i = 0; i < 4; i++) + for (i = 0; i < NUM_DIRECTIONS; i++) { int j = (start + i) % 4; int x = ax + xy[j][0]; @@ -6043,11 +6710,11 @@ void CheckForDragon(int x, int y) { 0, +1 } }; - for (i = 0; i < 4; i++) + for (i = 0; i < NUM_DIRECTIONS; i++) { for (j = 0; j < 4; j++) { - int xx = x + j*xy[i][0], yy = y + j*xy[i][1]; + int xx = x + j * xy[i][0], yy = y + j * xy[i][1]; if (IN_LEV_FIELD(xx, yy) && (Feld[xx][yy] == EL_FLAMES || Feld[xx][yy] == EL_DRAGON)) @@ -6062,11 +6729,11 @@ void CheckForDragon(int x, int y) if (!dragon_found) { - for (i = 0; i < 4; i++) + for (i = 0; i < NUM_DIRECTIONS; i++) { for (j = 0; j < 3; j++) { - int xx = x + j*xy[i][0], yy = y + j*xy[i][1]; + int xx = x + j * xy[i][0], yy = y + j * xy[i][1]; if (IN_LEV_FIELD(xx, yy) && Feld[xx][yy] == EL_FLAMES) { @@ -6105,7 +6772,7 @@ static void WarnBuggyBase(int x, int y) { 0, +1 } }; - for (i = 0; i < 4; i++) + for (i = 0; i < NUM_DIRECTIONS; i++) { int xx = x + xy[i][0], yy = y + xy[i][1]; @@ -6143,7 +6810,7 @@ static void ChangeElementNowExt(int x, int y, int target_element) /* check if element under player changes from accessible to unaccessible (needed for special case of dropping element which then changes) */ - if (IS_PLAYER(x, y) && !PLAYER_PROTECTED(x, y) && + if (IS_PLAYER(x, y) && !PLAYER_EXPLOSION_PROTECTED(x, y) && IS_ACCESSIBLE(Feld[x][y]) && !IS_ACCESSIBLE(target_element)) { Bang(x, y); @@ -6158,12 +6825,16 @@ static void ChangeElementNowExt(int x, int y, int target_element) ResetGfxAnimation(x, y); ResetRandomAnimationValue(x, y); - if (element_info[Feld[x][y]].move_direction_initial == MV_PREVIOUS) + if (element_info[Feld[x][y]].move_direction_initial == MV_START_PREVIOUS) MovDir[x][y] = previous_move_direction; +#if 1 + InitField_WithBug1(x, y, FALSE); +#else InitField(x, y, FALSE); if (CAN_MOVE(Feld[x][y])) InitMovDir(x, y); +#endif DrawLevelField(x, y); @@ -6197,7 +6868,7 @@ static boolean ChangeElementNow(int x, int y, int element, int page) Changed[x][y] |= ChangeEvent[x][y]; /* ignore same changes in this frame */ - CheckTriggeredElementChange(x, y, Feld[x][y], CE_OTHER_IS_CHANGING); + CheckTriggeredElementChangePage(x,y, Feld[x][y], CE_OTHER_IS_CHANGING, page); if (change->explode) { @@ -6371,10 +7042,12 @@ static void ChangeElement(int x, int y, int page) } } -static boolean CheckTriggeredElementSideChange(int lx, int ly, - int trigger_element, - int trigger_side, - int trigger_event) +static boolean CheckTriggeredElementChangeExt(int lx, int ly, + int trigger_element, + int trigger_event, + int trigger_player, + int trigger_side, + int trigger_page) { int i, j, x, y; @@ -6396,11 +7069,11 @@ static boolean CheckTriggeredElementSideChange(int lx, int ly, struct ElementChangeInfo *change = &element_info[element].change_page[j]; if (change->can_change && -#if 1 change->events & CH_EVENT_BIT(trigger_event) && -#endif - change->sides & trigger_side && - change->trigger_element == trigger_element) + change->trigger_side & trigger_side && + change->trigger_player & trigger_player && + change->trigger_page & (1 << trigger_page) && + IS_EQUAL_OR_IN_GROUP(trigger_element, change->trigger_element)) { #if 0 if (!(change->events & CH_EVENT_BIT(trigger_event))) @@ -6437,15 +7110,12 @@ static boolean CheckTriggeredElementSideChange(int lx, int ly, return TRUE; } -static boolean CheckTriggeredElementChange(int lx, int ly, int trigger_element, - int trigger_event) -{ - return CheckTriggeredElementSideChange(lx, ly, trigger_element, CH_SIDE_ANY, - trigger_event); -} - -static boolean CheckElementSideChange(int x, int y, int element, int side, - int trigger_event, int page) +static boolean CheckElementChangeExt(int x, int y, + int element, + int trigger_event, + int trigger_player, + int trigger_side, + int trigger_page) { if (!CAN_CHANGE(element) || !HAS_ANY_CHANGE_EVENT(element, trigger_event)) return FALSE; @@ -6456,24 +7126,50 @@ static boolean CheckElementSideChange(int x, int y, int element, int side, element = Feld[x][y]; } - if (page < 0) - page = element_info[element].event_page_nr[trigger_event]; +#if 1 + if (trigger_page < 0) + { + boolean change_element = FALSE; + int i; + + for (i = 0; i < element_info[element].num_change_pages; i++) + { + struct ElementChangeInfo *change = &element_info[element].change_page[i]; + + if (change->can_change && + change->events & CH_EVENT_BIT(trigger_event) && + change->trigger_side & trigger_side && + change->trigger_player & trigger_player) + { + change_element = TRUE; + trigger_page = i; + + break; + } + } + + if (!change_element) + return FALSE; + } + +#else + + /* !!! this check misses pages with same event, but different side !!! */ + + if (trigger_page < 0) + trigger_page = element_info[element].event_page_nr[trigger_event]; - if (!(element_info[element].change_page[page].sides & side)) + if (!(element_info[element].change_page[trigger_page].trigger_side & trigger_side)) return FALSE; +#endif ChangeDelay[x][y] = 1; ChangeEvent[x][y] = CH_EVENT_BIT(trigger_event); - ChangeElement(x, y, page); + ChangeElement(x, y, trigger_page); return TRUE; } -static boolean CheckElementChange(int x, int y, int element, int trigger_event) -{ - return CheckElementSideChange(x, y, element, CH_SIDE_ANY, trigger_event, -1); -} - static void PlayPlayerSound(struct PlayerInfo *player) { int jx = player->jx, jy = player->jy; @@ -6676,6 +7372,11 @@ static byte PlayerActions(struct PlayerInfo *player, byte player_action) printf("::: player %d acts [%d]\n", player->index_nr, FrameCounter); #endif +#if 0 + /* !!! TEST !!! */ + if (player->MovPos == 0) + CheckGravityMovement(player); +#endif if (button1) snapped = SnapField(player, dx, dy); else @@ -6711,9 +7412,9 @@ static byte PlayerActions(struct PlayerInfo *player, byte player_action) /* no actions for this player (no input at player's configured device) */ - DigField(player, 0, 0, 0, 0, DF_NO_PUSH); + DigField(player, 0, 0, 0, 0, 0, 0, DF_NO_PUSH); SnapField(player, 0, 0); - CheckGravityMovement(player); + CheckGravityMovementWhenNotMoving(player); if (player->MovPos == 0) SetPlayerWaiting(player, TRUE); @@ -6792,9 +7493,9 @@ static void PlayerActions(struct PlayerInfo *player, byte player_action) /* no actions for this player (no input at player's configured device) */ - DigField(player, 0, 0, 0, 0, DF_NO_PUSH); + DigField(player, 0, 0, 0, 0, 0, 0, DF_NO_PUSH); SnapField(player, 0, 0); - CheckGravityMovement(player); + CheckGravityMovementWhenNotMoving(player); if (player->MovPos == 0) InitPlayerGfxAnimation(player, ACTION_DEFAULT, player->MovDir); @@ -6874,6 +7575,21 @@ void GameActions() recorded_player_action = (tape.playing ? TapePlayAction() : NULL); +#if 1 + if (recorded_player_action == NULL && tape.pausing) + return; +#endif + +#if 0 + printf("::: %d\n", stored_player[0].action); +#endif + +#if 0 + if (recorded_player_action != NULL) + for (i = 0; i < MAX_PLAYERS; i++) + stored_player[i].action = recorded_player_action[i]; +#endif + for (i = 0; i < MAX_PLAYERS; i++) { summarized_player_action |= stored_player[i].action; @@ -6890,43 +7606,121 @@ void GameActions() if (!options.network && !setup.team_mode) local_player->effective_action = summarized_player_action; +#if 1 + if (recorded_player_action != NULL) + for (i = 0; i < MAX_PLAYERS; i++) + stored_player[i].effective_action = recorded_player_action[i]; +#endif + +#if 1 for (i = 0; i < MAX_PLAYERS; i++) { - int actual_player_action = stored_player[i].effective_action; - - if (stored_player[i].programmed_action) - actual_player_action = stored_player[i].programmed_action; - - if (recorded_player_action) - actual_player_action = recorded_player_action[i]; - - tape_action[i] = PlayerActions(&stored_player[i], actual_player_action); + tape_action[i] = stored_player[i].effective_action; if (tape.recording && tape_action[i] && !tape.player_participates[i]) tape.player_participates[i] = TRUE; /* player just appeared from CE */ - - ScrollPlayer(&stored_player[i], SCROLL_GO_ON); } -#if 1 + /* only save actions from input devices, but not programmed actions */ if (tape.recording) TapeRecordAction(tape_action); #endif - network_player_action_received = FALSE; - - ScrollScreen(NULL, SCROLL_GO_ON); - -#if 0 - FrameCounter++; - TimeFrames++; - for (i = 0; i < MAX_PLAYERS; i++) - stored_player[i].Frame++; + { + int actual_player_action = stored_player[i].effective_action; + +#if 1 + /* !!! THIS BREAKS THE FOLLOWING TAPES: !!! + - rnd_equinox_tetrachloride 048 + - rnd_equinox_tetrachloride_ii 096 + - rnd_emanuel_schmieg 002 + - doctor_sloan_ww 001, 020 + */ + if (stored_player[i].MovPos == 0) + CheckGravityMovement(&stored_player[i]); #endif #if 1 - if (game.engine_version < VERSION_IDENT(2,2,0,7)) + /* overwrite programmed action with tape action */ + if (stored_player[i].programmed_action) + actual_player_action = stored_player[i].programmed_action; +#endif + +#if 0 + if (stored_player[i].programmed_action) + printf("::: %d\n", stored_player[i].programmed_action); +#endif + + if (recorded_player_action) + { +#if 0 + if (stored_player[i].programmed_action && + stored_player[i].programmed_action != recorded_player_action[i]) + printf("::: %d: %d <-> %d\n", i, + stored_player[i].programmed_action, recorded_player_action[i]); +#endif + +#if 0 + actual_player_action = recorded_player_action[i]; +#endif + } + +#if 0 + /* overwrite tape action with programmed action */ + if (stored_player[i].programmed_action) + actual_player_action = stored_player[i].programmed_action; +#endif + +#if 0 + if (i == 0) + printf("::: action: %d: %x [%d]\n", + stored_player[i].MovPos, actual_player_action, FrameCounter); +#endif + +#if 1 + PlayerActions(&stored_player[i], actual_player_action); +#else + tape_action[i] = PlayerActions(&stored_player[i], actual_player_action); + + if (tape.recording && tape_action[i] && !tape.player_participates[i]) + tape.player_participates[i] = TRUE; /* player just appeared from CE */ +#endif + + ScrollPlayer(&stored_player[i], SCROLL_GO_ON); + } + +#if 0 + if (tape.recording) + TapeRecordAction(tape_action); +#endif + + network_player_action_received = FALSE; + + ScrollScreen(NULL, SCROLL_GO_ON); + +#if 0 + FrameCounter++; + TimeFrames++; + + for (i = 0; i < MAX_PLAYERS; i++) + stored_player[i].Frame++; +#endif + +#if 1 + /* for downwards compatibility, the following code emulates a fixed bug that + occured when pushing elements (causing elements that just made their last + pushing step to already (if possible) make their first falling step in the + same game frame, which is bad); this code is also needed to use the famous + "spring push bug" which is used in older levels and might be wanted to be + used also in newer levels, but in this case the buggy pushing code is only + affecting the "spring" element and no other elements */ + +#if 1 + if (game.engine_version < VERSION_IDENT(2,2,0,7) || level.use_spring_bug) +#else + if (game.engine_version < VERSION_IDENT(2,2,0,7)) +#endif { for (i = 0; i < MAX_PLAYERS; i++) { @@ -6934,8 +7728,15 @@ void GameActions() int x = player->jx; int y = player->jy; +#if 1 + if (player->active && player->is_pushing && player->is_moving && + IS_MOVING(x, y) && + (game.engine_version < VERSION_IDENT(2,2,0,7) || + Feld[x][y] == EL_SPRING)) +#else if (player->active && player->is_pushing && player->is_moving && IS_MOVING(x, y)) +#endif { ContinueMoving(x, y); @@ -7313,39 +8114,44 @@ void GameActions() if (TimeFrames >= FRAMES_PER_SECOND) { TimeFrames = 0; - TimePlayed++; + TapeTime++; - for (i = 0; i < MAX_PLAYERS; i++) + if (!level.use_step_counter) { - struct PlayerInfo *player = &stored_player[i]; + TimePlayed++; - if (SHIELD_ON(player)) + for (i = 0; i < MAX_PLAYERS; i++) { - player->shield_normal_time_left--; + struct PlayerInfo *player = &stored_player[i]; - if (player->shield_deadly_time_left > 0) - player->shield_deadly_time_left--; - } - } + if (SHIELD_ON(player)) + { + player->shield_normal_time_left--; - if (tape.recording || tape.playing) - DrawVideoDisplay(VIDEO_STATE_TIME_ON, TimePlayed); + if (player->shield_deadly_time_left > 0) + player->shield_deadly_time_left--; + } + } - if (TimeLeft > 0) - { - TimeLeft--; + if (TimeLeft > 0) + { + TimeLeft--; - if (TimeLeft <= 10 && setup.time_limit) - PlaySoundStereo(SND_GAME_RUNNING_OUT_OF_TIME, SOUND_MIDDLE); + if (TimeLeft <= 10 && setup.time_limit) + PlaySoundStereo(SND_GAME_RUNNING_OUT_OF_TIME, SOUND_MIDDLE); - DrawText(DX_TIME, DY_TIME, int2str(TimeLeft, 3), FONT_TEXT_2); + DrawGameValue_Time(TimeLeft); - if (!TimeLeft && setup.time_limit) - for (i = 0; i < MAX_PLAYERS; i++) - KillHero(&stored_player[i]); + if (!TimeLeft && setup.time_limit) + for (i = 0; i < MAX_PLAYERS; i++) + KillHero(&stored_player[i]); + } + else if (level.time == 0 && !AllPlayersGone) /* level w/o time limit */ + DrawGameValue_Time(TimePlayed); } - else if (level.time == 0 && !AllPlayersGone) /* level without time limit */ - DrawText(DX_TIME, DY_TIME, int2str(TimePlayed, 3), FONT_TEXT_2); + + if (tape.recording || tape.playing) + DrawVideoDisplay(VIDEO_STATE_TIME_ON, TapeTime); } DrawAllPlayers(); @@ -7479,31 +8285,119 @@ void ScrollLevel(int dx, int dy) redraw_mask |= REDRAW_FIELD; } +static boolean canEnterSupaplexPort(int x, int y, int dx, int dy) +{ + int nextx = x + dx, nexty = y + dy; + int element = Feld[x][y]; + + if ((dx == -1 && + element != EL_SP_PORT_LEFT && + element != EL_SP_GRAVITY_PORT_LEFT && + element != EL_SP_PORT_HORIZONTAL && + element != EL_SP_PORT_ANY) || + (dx == +1 && + element != EL_SP_PORT_RIGHT && + element != EL_SP_GRAVITY_PORT_RIGHT && + element != EL_SP_PORT_HORIZONTAL && + element != EL_SP_PORT_ANY) || + (dy == -1 && + element != EL_SP_PORT_UP && + element != EL_SP_GRAVITY_PORT_UP && + element != EL_SP_PORT_VERTICAL && + element != EL_SP_PORT_ANY) || + (dy == +1 && + element != EL_SP_PORT_DOWN && + element != EL_SP_GRAVITY_PORT_DOWN && + element != EL_SP_PORT_VERTICAL && + element != EL_SP_PORT_ANY) || + !IN_LEV_FIELD(nextx, nexty) || + !IS_FREE(nextx, nexty)) + return FALSE; + + return TRUE; +} + static void CheckGravityMovement(struct PlayerInfo *player) { if (game.gravity && !player->programmed_action) { - int move_dir_vertical = player->action & (MV_UP | MV_DOWN); - int move_dir_horizontal = player->action & (MV_LEFT | MV_RIGHT); + int move_dir_horizontal = player->action & MV_HORIZONTAL; + int move_dir_vertical = player->action & MV_VERTICAL; int move_dir = - (player->last_move_dir & (MV_LEFT | MV_RIGHT) ? + (player->last_move_dir & MV_HORIZONTAL ? (move_dir_vertical ? move_dir_vertical : move_dir_horizontal) : (move_dir_horizontal ? move_dir_horizontal : move_dir_vertical)); int jx = player->jx, jy = player->jy; int dx = (move_dir & MV_LEFT ? -1 : move_dir & MV_RIGHT ? +1 : 0); int dy = (move_dir & MV_UP ? -1 : move_dir & MV_DOWN ? +1 : 0); int new_jx = jx + dx, new_jy = jy + dy; - boolean field_under_player_is_free = - (IN_LEV_FIELD(jx, jy + 1) && IS_FREE(jx, jy + 1)); + boolean player_is_snapping = player->action & JOY_BUTTON_1; +#if 1 + boolean player_can_fall_down = + (IN_LEV_FIELD(jx, jy + 1) && + (IS_FREE(jx, jy + 1) || + (Feld[jx][jy + 1] == EL_ACID && player->can_fall_into_acid))); +#else + boolean player_can_fall_down = + (IN_LEV_FIELD(jx, jy + 1) && + (IS_FREE(jx, jy + 1))); +#endif boolean player_is_moving_to_valid_field = - (IN_LEV_FIELD(new_jx, new_jy) && + ( +#if 1 + !player_is_snapping && +#endif + IN_LEV_FIELD(new_jx, new_jy) && (Feld[new_jx][new_jy] == EL_SP_BASE || - Feld[new_jx][new_jy] == EL_SAND)); + Feld[new_jx][new_jy] == EL_SAND || + (IS_SP_PORT(Feld[new_jx][new_jy]) && + canEnterSupaplexPort(new_jx, new_jy, dx, dy)))); /* !!! extend EL_SAND to anything diggable !!! */ - if (field_under_player_is_free && - !player_is_moving_to_valid_field && - !IS_WALKABLE_INSIDE(Feld[jx][jy])) + boolean player_is_standing_on_valid_field = + (IS_WALKABLE_INSIDE(Feld[jx][jy]) || + (IS_WALKABLE(Feld[jx][jy]) && + !(element_info[Feld[jx][jy]].access_direction & MV_DOWN))); + +#if 0 + printf("::: checking gravity NOW [%d, %d, %d] [%d] ...\n", + player_can_fall_down, + player_is_standing_on_valid_field, + player_is_moving_to_valid_field, + (player_is_moving_to_valid_field ? Feld[new_jx][new_jy] : -1)); +#endif + + if (player_can_fall_down && + !player_is_standing_on_valid_field && + !player_is_moving_to_valid_field) + { +#if 0 + printf("::: setting programmed_action to MV_DOWN [%d,%d - %d] ...\n", + jx, jy, FrameCounter); +#endif + + player->programmed_action = MV_DOWN; + } + } +} + +static void CheckGravityMovementWhenNotMoving(struct PlayerInfo *player) +{ +#if 1 + return CheckGravityMovement(player); +#endif + + if (game.gravity && !player->programmed_action) + { + int jx = player->jx, jy = player->jy; + boolean field_under_player_is_free = + (IN_LEV_FIELD(jx, jy + 1) && IS_FREE(jx, jy + 1)); + boolean player_is_standing_on_valid_field = + (IS_WALKABLE_INSIDE(Feld[jx][jy]) || + (IS_WALKABLE(Feld[jx][jy]) && + !(element_info[Feld[jx][jy]].access_direction & MV_DOWN))); + + if (field_under_player_is_free && !player_is_standing_on_valid_field) player->programmed_action = MV_DOWN; } } @@ -7519,7 +8413,7 @@ boolean MovePlayerOneStep(struct PlayerInfo *player, int dx, int dy, int real_dx, int real_dy) { #if 0 - static int change_sides[4][2] = + static int trigger_sides[4][2] = { /* enter side leave side */ { CH_SIDE_RIGHT, CH_SIDE_LEFT }, /* moving left */ @@ -7531,8 +8425,8 @@ boolean MovePlayerOneStep(struct PlayerInfo *player, dx == +1 ? MV_RIGHT : dy == -1 ? MV_UP : dy == +1 ? MV_DOWN : MV_NO_MOVING); - int enter_side = change_sides[MV_DIR_BIT(move_direction)][0]; - int leave_side = change_sides[MV_DIR_BIT(move_direction)][1]; + int enter_side = trigger_sides[MV_DIR_BIT(move_direction)][0]; + int leave_side = trigger_sides[MV_DIR_BIT(move_direction)][1]; #endif int jx = player->jx, jy = player->jy; int new_jx = jx + dx, new_jy = jy + dy; @@ -7563,7 +8457,7 @@ boolean MovePlayerOneStep(struct PlayerInfo *player, { if (element == EL_ACID && dx == 0 && dy == 1) { - SplashAcid(jx, jy); + SplashAcid(new_jx, new_jy); Feld[jx][jy] = EL_PLAYER_1; InitMovingField(jx, jy, MV_DOWN); Store[jx][jy] = EL_ACID; @@ -7576,7 +8470,7 @@ boolean MovePlayerOneStep(struct PlayerInfo *player, return MF_MOVING; } - can_move = DigField(player, new_jx, new_jy, real_dx, real_dy, DF_DIG); + can_move = DigField(player, jx, jy, new_jx, new_jy, real_dx,real_dy, DF_DIG); if (can_move != MF_MOVING) return can_move; @@ -7605,18 +8499,17 @@ boolean MovePlayerOneStep(struct PlayerInfo *player, #if 0 if (IS_CUSTOM_ELEMENT(Feld[jx][jy])) { - CheckTriggeredElementSideChange(jx, jy, Feld[jx][jy], leave_side, - CE_OTHER_GETS_LEFT); - CheckElementSideChange(jx, jy, Feld[jx][jy], leave_side, - CE_LEFT_BY_PLAYER, -1); + CheckTriggeredElementChangeSide(jx, jy, Feld[jx][jy], CE_OTHER_GETS_LEFT, + leave_side); + CheckElementChangeSide(jx, jy, Feld[jx][jy], CE_LEFT_BY_PLAYER,leave_side); } if (IS_CUSTOM_ELEMENT(Feld[new_jx][new_jy])) { - CheckTriggeredElementSideChange(new_jx, new_jy, Feld[new_jx][new_jy], - enter_side, CE_OTHER_GETS_ENTERED); - CheckElementSideChange(new_jx, new_jy, Feld[new_jx][new_jy], enter_side, - CE_ENTERED_BY_PLAYER, -1); + CheckTriggeredElementChangeSide(new_jx, new_jy, Feld[new_jx][new_jy], + CE_OTHER_GETS_ENTERED, enter_side); + CheckElementChangeSide(new_jx, new_jy, Feld[new_jx][new_jy], + CE_ENTERED_BY_PLAYER, enter_side); } #endif @@ -7656,9 +8549,16 @@ boolean MovePlayer(struct PlayerInfo *player, int dx, int dy) !tape.playing) return FALSE; #else + +#if 1 + if (!FrameReached(&player->move_delay, player->move_delay_value)) + return FALSE; +#else if (!FrameReached(&player->move_delay, player->move_delay_value) && !(tape.playing && tape.file_version < FILE_VERSION_2_0)) return FALSE; +#endif + #endif /* remove the last programmed player action */ @@ -7691,7 +8591,7 @@ boolean MovePlayer(struct PlayerInfo *player, int dx, int dy) player->move_delay_value = original_move_delay_value; } - if (player->last_move_dir & (MV_LEFT | MV_RIGHT)) + if (player->last_move_dir & MV_HORIZONTAL) { if (!(moved |= MovePlayerOneStep(player, 0, dy, dx, dy))) moved |= MovePlayerOneStep(player, dx, 0, dx, dy); @@ -7809,7 +8709,7 @@ boolean MovePlayer(struct PlayerInfo *player, int dx, int dy) #if 1 { - static int change_sides[4][2] = + static int trigger_sides[4][2] = { /* enter side leave side */ { CH_SIDE_RIGHT, CH_SIDE_LEFT }, /* moving left */ @@ -7818,24 +8718,27 @@ boolean MovePlayer(struct PlayerInfo *player, int dx, int dy) { CH_SIDE_TOP, CH_SIDE_BOTTOM } /* moving down */ }; int move_direction = player->MovDir; - int enter_side = change_sides[MV_DIR_BIT(move_direction)][0]; - int leave_side = change_sides[MV_DIR_BIT(move_direction)][1]; + int enter_side = trigger_sides[MV_DIR_BIT(move_direction)][0]; + int leave_side = trigger_sides[MV_DIR_BIT(move_direction)][1]; #if 1 if (IS_CUSTOM_ELEMENT(Feld[old_jx][old_jy])) { - CheckTriggeredElementSideChange(old_jx, old_jy, Feld[old_jx][old_jy], - leave_side, CE_OTHER_GETS_LEFT); - CheckElementSideChange(old_jx, old_jy, Feld[old_jx][old_jy], - leave_side, CE_LEFT_BY_PLAYER, -1); + CheckTriggeredElementChangePlayer(old_jx, old_jy, Feld[old_jx][old_jy], + CE_OTHER_GETS_LEFT, + player->index_bit, leave_side); + CheckElementChangePlayer(old_jx, old_jy, Feld[old_jx][old_jy], + CE_LEFT_BY_PLAYER, + player->index_bit, leave_side); } if (IS_CUSTOM_ELEMENT(Feld[jx][jy])) { - CheckTriggeredElementSideChange(jx, jy, Feld[jx][jy], - enter_side, CE_OTHER_GETS_ENTERED); - CheckElementSideChange(jx, jy, Feld[jx][jy], - enter_side, CE_ENTERED_BY_PLAYER, -1); + CheckTriggeredElementChangePlayer(jx, jy, Feld[jx][jy], + CE_OTHER_GETS_ENTERED, + player->index_bit, enter_side); + CheckElementChangePlayer(jx, jy, Feld[jx][jy], CE_ENTERED_BY_PLAYER, + player->index_bit, enter_side); } #endif @@ -7846,7 +8749,7 @@ boolean MovePlayer(struct PlayerInfo *player, int dx, int dy) } else { - CheckGravityMovement(player); + CheckGravityMovementWhenNotMoving(player); /* player->last_move_dir = MV_NO_MOVING; @@ -7886,6 +8789,7 @@ void ScrollPlayer(struct PlayerInfo *player, int mode) #if 0 DrawPlayer(player); #endif + return; } else if (!FrameReached(&player->actual_frame_counter, 1)) @@ -7894,7 +8798,8 @@ void ScrollPlayer(struct PlayerInfo *player, int mode) player->MovPos += (player->MovPos > 0 ? -1 : 1) * move_stepsize; player->GfxPos = move_stepsize * (player->MovPos / move_stepsize); - if (Feld[last_jx][last_jy] == EL_PLAYER_IS_LEAVING) + if (!player->block_last_field && + Feld[last_jx][last_jy] == EL_PLAYER_IS_LEAVING) Feld[last_jx][last_jy] = EL_EMPTY; /* before DrawPlayer() to draw correct player graphic for this case */ @@ -7932,6 +8837,10 @@ void ScrollPlayer(struct PlayerInfo *player, int mode) } #endif + if (player->block_last_field && + Feld[last_jx][last_jy] == EL_PLAYER_IS_LEAVING) + Feld[last_jx][last_jy] = EL_EMPTY; + player->last_jx = jx; player->last_jy = jy; @@ -7947,6 +8856,47 @@ void ScrollPlayer(struct PlayerInfo *player, int mode) player->LevelSolved = player->GameOver = TRUE; } +#if 0 + /* !!! ENABLE THIS FOR NEW VERSIONS !!! */ + { + static int trigger_sides[4][2] = + { + /* enter side leave side */ + { CH_SIDE_RIGHT, CH_SIDE_LEFT }, /* moving left */ + { CH_SIDE_LEFT, CH_SIDE_RIGHT }, /* moving right */ + { CH_SIDE_BOTTOM, CH_SIDE_TOP }, /* moving up */ + { CH_SIDE_TOP, CH_SIDE_BOTTOM } /* moving down */ + }; + int move_direction = player->MovDir; + int enter_side = trigger_sides[MV_DIR_BIT(move_direction)][0]; + int leave_side = trigger_sides[MV_DIR_BIT(move_direction)][1]; + int old_jx = last_jx; + int old_jy = last_jy; + +#if 1 + if (IS_CUSTOM_ELEMENT(Feld[old_jx][old_jy])) + { + CheckTriggeredElementChangePlayer(old_jx, old_jy, Feld[old_jx][old_jy], + CE_OTHER_GETS_LEFT, + player->index_bit, leave_side); + CheckElementChangePlayer(old_jx, old_jy, Feld[old_jx][old_jy], + CE_LEFT_BY_PLAYER, + player->index_bit, leave_side); + } + + if (IS_CUSTOM_ELEMENT(Feld[jx][jy])) + { + CheckTriggeredElementChangePlayer(jx, jy, Feld[jx][jy], + CE_OTHER_GETS_ENTERED, + player->index_bit, enter_side); + CheckElementChangePlayer(jx, jy, Feld[jx][jy], CE_ENTERED_BY_PLAYER, + player->index_bit, enter_side); + } +#endif + + } +#endif + if (game.engine_version >= VERSION_IDENT(3,0,7,0)) { TestIfHeroTouchesBadThing(jx, jy); @@ -7959,6 +8909,42 @@ void ScrollPlayer(struct PlayerInfo *player, int mode) RemoveHero(player); } + if (level.use_step_counter) + { + int i; + + TimePlayed++; + + for (i = 0; i < MAX_PLAYERS; i++) + { + struct PlayerInfo *player = &stored_player[i]; + + if (SHIELD_ON(player)) + { + player->shield_normal_time_left--; + + if (player->shield_deadly_time_left > 0) + player->shield_deadly_time_left--; + } + } + + if (TimeLeft > 0) + { + TimeLeft--; + + if (TimeLeft <= 10 && setup.time_limit) + PlaySoundStereo(SND_GAME_RUNNING_OUT_OF_TIME, SOUND_MIDDLE); + + DrawGameValue_Time(TimeLeft); + + if (!TimeLeft && setup.time_limit) + for (i = 0; i < MAX_PLAYERS; i++) + KillHero(&stored_player[i]); + } + else if (level.time == 0 && !AllPlayersGone) /* level w/o time limit */ + DrawGameValue_Time(TimePlayed); + } + if (tape.single_step && tape.recording && !tape.pausing && !player->programmed_action) TapeTogglePause(TAPE_TOGGLE_AUTOMATIC); @@ -8002,7 +8988,7 @@ void TestIfPlayerTouchesCustomElement(int x, int y) { +1, 0 }, { 0, +1 } }; - static int change_sides[4][2] = + static int trigger_sides[4][2] = { /* center side border side */ { CH_SIDE_TOP, CH_SIDE_BOTTOM }, /* check top */ @@ -8020,12 +9006,12 @@ void TestIfPlayerTouchesCustomElement(int x, int y) int center_element = Feld[x][y]; /* should always be non-moving! */ int i; - for (i = 0; i < 4; i++) + for (i = 0; i < NUM_DIRECTIONS; i++) { int xx = x + xy[i][0]; int yy = y + xy[i][1]; - int center_side = change_sides[i][0]; - int border_side = change_sides[i][1]; + int center_side = trigger_sides[i][0]; + int border_side = trigger_sides[i][1]; int border_element; if (!IN_LEV_FIELD(xx, yy)) @@ -8033,6 +9019,8 @@ void TestIfPlayerTouchesCustomElement(int x, int y) if (IS_PLAYER(x, y)) { + struct PlayerInfo *player = PLAYERINFO(x, y); + if (game.engine_version < VERSION_IDENT(3,0,7,0)) border_element = Feld[xx][yy]; /* may be moving! */ else if (!IS_MOVING(xx, yy) && !IS_BLOCKED(xx, yy)) @@ -8042,25 +9030,27 @@ void TestIfPlayerTouchesCustomElement(int x, int y) else continue; /* center and border element do not touch */ - CheckTriggeredElementSideChange(xx, yy, border_element, border_side, - CE_OTHER_GETS_TOUCHED); - CheckElementSideChange(xx, yy, border_element, border_side, - CE_TOUCHED_BY_PLAYER, -1); + CheckTriggeredElementChangePlayer(xx, yy, border_element, + CE_OTHER_GETS_TOUCHED, + player->index_bit, border_side); + CheckElementChangePlayer(xx, yy, border_element, CE_TOUCHED_BY_PLAYER, + player->index_bit, border_side); } else if (IS_PLAYER(xx, yy)) { + struct PlayerInfo *player = PLAYERINFO(xx, yy); + if (game.engine_version >= VERSION_IDENT(3,0,7,0)) { - struct PlayerInfo *player = PLAYERINFO(xx, yy); - if (player->MovPos != 0 && !(player->MovDir & touch_dir[i])) continue; /* center and border element do not touch */ } - CheckTriggeredElementSideChange(x, y, center_element, center_side, - CE_OTHER_GETS_TOUCHED); - CheckElementSideChange(x, y, center_element, center_side, - CE_TOUCHED_BY_PLAYER, -1); + CheckTriggeredElementChangePlayer(x, y, center_element, + CE_OTHER_GETS_TOUCHED, + player->index_bit, center_side); + CheckElementChangePlayer(x, y, center_element, CE_TOUCHED_BY_PLAYER, + player->index_bit, center_side); break; } @@ -8076,7 +9066,7 @@ void TestIfElementTouchesCustomElement(int x, int y) { +1, 0 }, { 0, +1 } }; - static int change_sides[4][2] = + static int trigger_sides[4][2] = { /* center side border side */ { CH_SIDE_TOP, CH_SIDE_BOTTOM }, /* check top */ @@ -8096,12 +9086,12 @@ void TestIfElementTouchesCustomElement(int x, int y) int center_element = Feld[x][y]; /* should always be non-moving! */ int i, j; - for (i = 0; i < 4; i++) + for (i = 0; i < NUM_DIRECTIONS; i++) { int xx = x + xy[i][0]; int yy = y + xy[i][1]; - int center_side = change_sides[i][0]; - int border_side = change_sides[i][1]; + int center_side = trigger_sides[i][0]; + int border_side = trigger_sides[i][1]; int border_element; if (!IN_LEV_FIELD(xx, yy)) @@ -8128,8 +9118,13 @@ void TestIfElementTouchesCustomElement(int x, int y) if (change->can_change && change->events & CH_EVENT_BIT(CE_OTHER_IS_TOUCHING) && - change->sides & border_side && - change->trigger_element == border_element) + change->trigger_side & border_side && +#if 1 + IS_EQUAL_OR_IN_GROUP(border_element, change->trigger_element) +#else + change->trigger_element == border_element +#endif + ) { change_center_element = TRUE; center_element_change_page = j; @@ -8150,11 +9145,16 @@ void TestIfElementTouchesCustomElement(int x, int y) if (change->can_change && change->events & CH_EVENT_BIT(CE_OTHER_IS_TOUCHING) && - change->sides & center_side && - change->trigger_element == center_element) + change->trigger_side & center_side && +#if 1 + IS_EQUAL_OR_IN_GROUP(center_element, change->trigger_element) +#else + change->trigger_element == center_element +#endif + ) { - CheckElementSideChange(xx, yy, border_element, CH_SIDE_ANY, - CE_OTHER_IS_TOUCHING, j); + CheckElementChangePage(xx, yy, border_element, CE_OTHER_IS_TOUCHING, + j); break; } } @@ -8162,8 +9162,8 @@ void TestIfElementTouchesCustomElement(int x, int y) } if (change_center_element) - CheckElementSideChange(x, y, center_element, CH_SIDE_ANY, - CE_OTHER_IS_TOUCHING, center_element_change_page); + CheckElementChangePage(x, y, center_element, CE_OTHER_IS_TOUCHING, + center_element_change_page); } void TestIfElementHitsCustomElement(int x, int y, int direction) @@ -8188,20 +9188,12 @@ void TestIfElementHitsCustomElement(int x, int y, int direction) return; #endif - CheckElementSideChange(x, y, hitting_element, - direction, CE_HITTING_SOMETHING, -1); + CheckElementChangeSide(x, y, hitting_element, CE_HITTING_SOMETHING, + direction); if (IN_LEV_FIELD(hitx, hity)) { - static int opposite_directions[] = - { - MV_RIGHT, - MV_LEFT, - MV_DOWN, - MV_UP - }; - int move_dir_bit = MV_DIR_BIT(direction); - int opposite_direction = opposite_directions[move_dir_bit]; + int opposite_direction = MV_DIR_OPPOSITE(direction); int hitting_side = direction; int touched_side = opposite_direction; int touched_element = MovingOrBlocked2Element(hitx, hity); @@ -8217,8 +9209,8 @@ void TestIfElementHitsCustomElement(int x, int y, int direction) { int i; - CheckElementSideChange(hitx, hity, touched_element, - opposite_direction, CE_HIT_BY_SOMETHING, -1); + CheckElementChangeSide(hitx, hity, touched_element, CE_HIT_BY_SOMETHING, + opposite_direction); if (IS_CUSTOM_ELEMENT(hitting_element) && HAS_ANY_CHANGE_EVENT(hitting_element, CE_OTHER_IS_HITTING)) @@ -8230,11 +9222,17 @@ void TestIfElementHitsCustomElement(int x, int y, int direction) if (change->can_change && change->events & CH_EVENT_BIT(CE_OTHER_IS_HITTING) && - change->sides & touched_side && - change->trigger_element == touched_element) + change->trigger_side & touched_side && + +#if 1 + IS_EQUAL_OR_IN_GROUP(touched_element, change->trigger_element) +#else + change->trigger_element == touched_element +#endif + ) { - CheckElementSideChange(x, y, hitting_element, - CH_SIDE_ANY, CE_OTHER_IS_HITTING, i); + CheckElementChangePage(x, y, hitting_element, CE_OTHER_IS_HITTING, + i); break; } } @@ -8250,11 +9248,16 @@ void TestIfElementHitsCustomElement(int x, int y, int direction) if (change->can_change && change->events & CH_EVENT_BIT(CE_OTHER_GETS_HIT) && - change->sides & hitting_side && - change->trigger_element == hitting_element) + change->trigger_side & hitting_side && +#if 1 + IS_EQUAL_OR_IN_GROUP(hitting_element, change->trigger_element) +#else + change->trigger_element == hitting_element +#endif + ) { - CheckElementSideChange(hitx, hity, touched_element, - CH_SIDE_ANY, CE_OTHER_GETS_HIT, i); + CheckElementChangePage(hitx, hity, touched_element, + CE_OTHER_GETS_HIT, i); break; } } @@ -8263,6 +9266,108 @@ void TestIfElementHitsCustomElement(int x, int y, int direction) } } +#if 0 +void TestIfElementSmashesCustomElement(int x, int y, int direction) +{ + int dx = (direction == MV_LEFT ? -1 : direction == MV_RIGHT ? +1 : 0); + int dy = (direction == MV_UP ? -1 : direction == MV_DOWN ? +1 : 0); + int hitx = x + dx, hity = y + dy; + int hitting_element = Feld[x][y]; +#if 0 + boolean object_hit = (IN_LEV_FIELD(hitx, hity) && + !IS_FREE(hitx, hity) && + (!IS_MOVING(hitx, hity) || + MovDir[hitx][hity] != direction || + ABS(MovPos[hitx][hity]) <= TILEY / 2)); +#endif + + if (IN_LEV_FIELD(hitx, hity) && IS_FREE(hitx, hity)) + return; + +#if 0 + if (IN_LEV_FIELD(hitx, hity) && !object_hit) + return; +#endif + + CheckElementChangeSide(x, y, hitting_element, EP_CAN_SMASH_EVERYTHING, + direction); + + if (IN_LEV_FIELD(hitx, hity)) + { + int opposite_direction = MV_DIR_OPPOSITE(direction); + int hitting_side = direction; + int touched_side = opposite_direction; + int touched_element = MovingOrBlocked2Element(hitx, hity); +#if 1 + boolean object_hit = (!IS_MOVING(hitx, hity) || + MovDir[hitx][hity] != direction || + ABS(MovPos[hitx][hity]) <= TILEY / 2); + + object_hit = TRUE; +#endif + + if (object_hit) + { + int i; + + CheckElementChangeSide(hitx, hity, touched_element, + CE_SMASHED_BY_SOMETHING, opposite_direction); + + if (IS_CUSTOM_ELEMENT(hitting_element) && + HAS_ANY_CHANGE_EVENT(hitting_element, CE_OTHER_IS_SMASHING)) + { + for (i = 0; i < element_info[hitting_element].num_change_pages; i++) + { + struct ElementChangeInfo *change = + &element_info[hitting_element].change_page[i]; + + if (change->can_change && + change->events & CH_EVENT_BIT(CE_OTHER_IS_SMASHING) && + change->trigger_side & touched_side && + +#if 1 + IS_EQUAL_OR_IN_GROUP(touched_element, change->trigger_element) +#else + change->trigger_element == touched_element +#endif + ) + { + CheckElementChangePage(x, y, hitting_element, CE_OTHER_IS_SMASHING, + i); + break; + } + } + } + + if (IS_CUSTOM_ELEMENT(touched_element) && + HAS_ANY_CHANGE_EVENT(touched_element, CE_OTHER_GETS_SMASHED)) + { + for (i = 0; i < element_info[touched_element].num_change_pages; i++) + { + struct ElementChangeInfo *change = + &element_info[touched_element].change_page[i]; + + if (change->can_change && + change->events & CH_EVENT_BIT(CE_OTHER_GETS_SMASHED) && + change->trigger_side & hitting_side && +#if 1 + IS_EQUAL_OR_IN_GROUP(hitting_element, change->trigger_element) +#else + change->trigger_element == hitting_element +#endif + ) + { + CheckElementChangePage(hitx, hity, touched_element, + CE_OTHER_GETS_SMASHED, i); + break; + } + } + } + } + } +} +#endif + void TestIfGoodThingHitsBadThing(int good_x, int good_y, int good_move_dir) { int i, kill_x = -1, kill_y = -1; @@ -8281,7 +9386,7 @@ void TestIfGoodThingHitsBadThing(int good_x, int good_y, int good_move_dir) MV_DOWN }; - for (i = 0; i < 4; i++) + for (i = 0; i < NUM_DIRECTIONS; i++) { int test_x, test_y, test_move_dir, test_element; @@ -8319,7 +9424,7 @@ void TestIfGoodThingHitsBadThing(int good_x, int good_y, int good_move_dir) if (player->shield_deadly_time_left > 0) Bang(kill_x, kill_y); - else if (!PLAYER_PROTECTED(good_x, good_y)) + else if (!PLAYER_ENEMY_PROTECTED(good_x, good_y)) KillHero(player); } else @@ -8356,7 +9461,7 @@ void TestIfBadThingHitsGoodThing(int bad_x, int bad_y, int bad_move_dir) if (bad_element == EL_EXPLOSION) /* skip just exploding bad things */ return; - for (i = 0; i < 4; i++) + for (i = 0; i < NUM_DIRECTIONS; i++) { int test_x, test_y, test_move_dir, test_element; @@ -8411,7 +9516,7 @@ void TestIfBadThingHitsGoodThing(int bad_x, int bad_y, int bad_move_dir) if (player->shield_deadly_time_left > 0) Bang(bad_x, bad_y); - else if (!PLAYER_PROTECTED(kill_x, kill_y)) + else if (!PLAYER_ENEMY_PROTECTED(kill_x, kill_y)) KillHero(player); } else @@ -8460,7 +9565,7 @@ void TestIfBadThingTouchesOtherBadThing(int bad_x, int bad_y) { 0, +1 } }; - for (i = 0; i < 4; i++) + for (i = 0; i < NUM_DIRECTIONS; i++) { int x, y, element; @@ -8501,9 +9606,15 @@ void KillHero(struct PlayerInfo *player) BuryHero(player); } -static void KillHeroUnlessProtected(int x, int y) +static void KillHeroUnlessEnemyProtected(int x, int y) { - if (!PLAYER_PROTECTED(x, y)) + if (!PLAYER_ENEMY_PROTECTED(x, y)) + KillHero(PLAYERINFO(x, y)); +} + +static void KillHeroUnlessExplosionProtected(int x, int y) +{ + if (!PLAYER_EXPLOSION_PROTECTED(x, y)) KillHero(PLAYERINFO(x, y)); } @@ -8585,24 +9696,29 @@ static boolean checkDiagonalPushing(struct PlayerInfo *player, */ int DigField(struct PlayerInfo *player, - int x, int y, int real_dx, int real_dy, int mode) + int oldx, int oldy, int x, int y, + int real_dx, int real_dy, int mode) { - static int change_sides[4] = + static int trigger_sides[4] = { CH_SIDE_RIGHT, /* moving left */ CH_SIDE_LEFT, /* moving right */ CH_SIDE_BOTTOM, /* moving up */ CH_SIDE_TOP, /* moving down */ }; +#if 0 boolean use_spring_bug = (game.engine_version < VERSION_IDENT(2,2,0,0)); - int jx = player->jx, jy = player->jy; +#endif + int jx = oldx, jy = oldy; int dx = x - jx, dy = y - jy; int nextx = x + dx, nexty = y + dy; int move_direction = (dx == -1 ? MV_LEFT : dx == +1 ? MV_RIGHT : dy == -1 ? MV_UP : dy == +1 ? MV_DOWN : MV_NO_MOVING); - int dig_side = change_sides[MV_DIR_BIT(move_direction)]; + int opposite_direction = MV_DIR_OPPOSITE(move_direction); + int dig_side = trigger_sides[MV_DIR_BIT(move_direction)]; + int old_element = Feld[jx][jy]; int element; if (player->MovPos == 0) @@ -8625,6 +9741,8 @@ int DigField(struct PlayerInfo *player, if (IS_MOVING(x, y) || IS_PLAYER(x, y)) return MF_NO_ACTION; +#if 0 + #if 0 if (IS_TUBE(Feld[jx][jy]) || IS_TUBE(Back[jx][jy])) #else @@ -8661,6 +9779,17 @@ int DigField(struct PlayerInfo *player, return MF_NO_ACTION; /* tube has no opening in this direction */ } +#else + + if (IS_TUBE(Back[jx][jy]) && game.engine_version >= VERSION_IDENT(2,2,0,0)) + old_element = Back[jx][jy]; + +#endif + + if (IS_WALKABLE(old_element) && + !(element_info[old_element].access_direction & move_direction)) + return MF_NO_ACTION; /* field has no opening in this direction */ + element = Feld[x][y]; if (mode == DF_SNAP && !IS_SNAPPABLE(element) && @@ -8680,6 +9809,10 @@ int DigField(struct PlayerInfo *player, case EL_SP_GRAVITY_PORT_RIGHT: case EL_SP_GRAVITY_PORT_UP: case EL_SP_GRAVITY_PORT_DOWN: +#if 1 + if (!canEnterSupaplexPort(x, y, dx, dy)) + return MF_NO_ACTION; +#else if ((dx == -1 && element != EL_SP_PORT_LEFT && element != EL_SP_GRAVITY_PORT_LEFT && @@ -8703,6 +9836,7 @@ int DigField(struct PlayerInfo *player, !IN_LEV_FIELD(nextx, nexty) || !IS_FREE(nextx, nexty)) return MF_NO_ACTION; +#endif if (element == EL_SP_GRAVITY_PORT_LEFT || element == EL_SP_GRAVITY_PORT_RIGHT || @@ -8725,9 +9859,14 @@ int DigField(struct PlayerInfo *player, DOUBLE_PLAYER_SPEED(player); #endif +#if 0 + printf("::: passing port %d,%d [%d]\n", x, y, FrameCounter); +#endif + PlayLevelSound(x, y, SND_CLASS_SP_PORT_PASSING); break; +#if 0 case EL_TUBE_ANY: case EL_TUBE_VERTICAL: case EL_TUBE_HORIZONTAL: @@ -8770,6 +9909,7 @@ int DigField(struct PlayerInfo *player, PlayLevelSound(x, y, SND_CLASS_TUBE_WALKING); } break; +#endif default: @@ -8777,6 +9917,9 @@ int DigField(struct PlayerInfo *player, { int sound_action = ACTION_WALKING; + if (!(element_info[element].access_direction & opposite_direction)) + return MF_NO_ACTION; /* field not accessible from this direction */ + if (element >= EL_GATE_1 && element <= EL_GATE_4) { if (!player->key[element - EL_GATE_1]) @@ -8811,6 +9954,10 @@ int DigField(struct PlayerInfo *player, if (!IN_LEV_FIELD(nextx, nexty) || !IS_FREE(nextx, nexty)) return MF_NO_ACTION; + if (IS_CUSTOM_ELEMENT(element) && + !(element_info[element].access_direction & opposite_direction)) + return MF_NO_ACTION; /* field not accessible from this direction */ + #if 1 if (CAN_MOVE(element)) /* only fixed elements can be passed! */ return MF_NO_ACTION; @@ -8863,7 +10010,8 @@ int DigField(struct PlayerInfo *player, PlayLevelSoundElementAction(x, y, element, ACTION_DIGGING); - CheckTriggeredElementChange(x, y, element, CE_OTHER_GETS_DIGGED); + CheckTriggeredElementChangePlayer(x, y, element, CE_OTHER_GETS_DIGGED, + player->index_bit, CH_SIDE_ANY); #if 1 if (mode == DF_SNAP) @@ -8887,7 +10035,7 @@ int DigField(struct PlayerInfo *player, else if (element == EL_EXTRA_TIME && level.time > 0) { TimeLeft += 10; - DrawText(DX_TIME, DY_TIME, int2str(TimeLeft, 3), FONT_TEXT_2); + DrawGameValue_Time(TimeLeft); } else if (element == EL_SHIELD_NORMAL || element == EL_SHIELD_DEADLY) { @@ -8900,8 +10048,7 @@ int DigField(struct PlayerInfo *player, if (player->inventory_size < MAX_INVENTORY_SIZE) player->inventory_element[player->inventory_size++] = element; - DrawText(DX_DYNAMITE, DY_DYNAMITE, - int2str(local_player->inventory_size, 3), FONT_TEXT_2); + DrawGameValue_Dynamite(local_player->inventory_size); } else if (element == EL_DYNABOMB_INCREASE_NUMBER) { @@ -8924,8 +10071,8 @@ int DigField(struct PlayerInfo *player, player->key[key_nr] = TRUE; - DrawMiniGraphicExt(drawto, DX_KEYS + key_nr * MINI_TILEX, DY_KEYS, - el2edimg(EL_KEY_1 + key_nr)); + DrawGameValue_Keys(player); + redraw_mask |= REDRAW_DOOR_1; } else if (IS_ENVELOPE(element)) @@ -8940,12 +10087,14 @@ int DigField(struct PlayerInfo *player, { int i; - for (i = 0; i < element_info[element].collect_count; i++) - if (player->inventory_size < MAX_INVENTORY_SIZE) - player->inventory_element[player->inventory_size++] = element; + if (element_info[element].collect_count == 0) + player->inventory_infinite_element = element; + else + for (i = 0; i < element_info[element].collect_count; i++) + if (player->inventory_size < MAX_INVENTORY_SIZE) + player->inventory_element[player->inventory_size++] = element; - DrawText(DX_DYNAMITE, DY_DYNAMITE, - int2str(local_player->inventory_size, 3), FONT_TEXT_2); + DrawGameValue_Dynamite(local_player->inventory_size); } else if (element_info[element].collect_count > 0) { @@ -8954,14 +10103,15 @@ int DigField(struct PlayerInfo *player, if (local_player->gems_still_needed < 0) local_player->gems_still_needed = 0; - DrawText(DX_EMERALDS, DY_EMERALDS, - int2str(local_player->gems_still_needed, 3), FONT_TEXT_2); + DrawGameValue_Emeralds(local_player->gems_still_needed); } RaiseScoreElement(element); PlayLevelSoundElementAction(x, y, element, ACTION_COLLECTING); - CheckTriggeredElementChange(x, y, element, CE_OTHER_GETS_COLLECTED); + CheckTriggeredElementChangePlayer(x, y, element, + CE_OTHER_GETS_COLLECTED, + player->index_bit, CH_SIDE_ANY); #if 1 if (mode == DF_SNAP) @@ -8979,7 +10129,7 @@ int DigField(struct PlayerInfo *player, 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)) + !(element == EL_SPRING && level.use_spring_bug)) return MF_NO_ACTION; #if 1 @@ -9117,10 +10267,10 @@ int DigField(struct PlayerInfo *player, else player->push_delay_value = -1; /* get new value later */ - CheckTriggeredElementSideChange(x, y, element, dig_side, - CE_OTHER_GETS_PUSHED); - CheckElementSideChange(x, y, element, dig_side, - CE_PUSHED_BY_PLAYER, -1); + CheckTriggeredElementChangePlayer(x, y, element, CE_OTHER_GETS_PUSHED, + player->index_bit, dig_side); + CheckElementChangePlayer(x, y, element, CE_PUSHED_BY_PLAYER, + player->index_bit, dig_side); break; } @@ -9205,7 +10355,7 @@ int DigField(struct PlayerInfo *player, { Feld[x][y] = EL_TIME_ORB_EMPTY; TimeLeft += 10; - DrawText(DX_TIME, DY_TIME, int2str(TimeLeft, 3), FONT_TEXT_2); + DrawGameValue_Time(TimeLeft); DrawLevelField(x, y); @@ -9224,15 +10374,17 @@ int DigField(struct PlayerInfo *player, player->switch_x = x; player->switch_y = y; - CheckTriggeredElementSideChange(x, y, element, dig_side, - CE_OTHER_IS_SWITCHING); - CheckElementSideChange(x, y, element, dig_side, CE_SWITCHED, -1); + CheckTriggeredElementChangePlayer(x, y, element, + CE_OTHER_IS_SWITCHING, + player->index_bit, dig_side); + CheckElementChangePlayer(x, y, element, CE_SWITCHED, + player->index_bit, dig_side); } - CheckTriggeredElementSideChange(x, y, element, dig_side, - CE_OTHER_GETS_PRESSED); - CheckElementSideChange(x, y, element, dig_side, - CE_PRESSED_BY_PLAYER, -1); + CheckTriggeredElementChangePlayer(x, y, element, CE_OTHER_GETS_PRESSED, + player->index_bit, dig_side); + CheckElementChangePlayer(x, y, element, CE_PRESSED_BY_PLAYER, + player->index_bit, dig_side); } return MF_NO_ACTION; @@ -9255,8 +10407,13 @@ boolean SnapField(struct PlayerInfo *player, int dx, int dy) dy == -1 ? MV_UP : dy == +1 ? MV_DOWN : MV_NO_MOVING); +#if 0 + if (player->MovPos) + return FALSE; +#else if (player->MovPos && game.engine_version >= VERSION_IDENT(2,2,0,0)) return FALSE; +#endif if (!player->active || !IN_LEV_FIELD(x, y)) return FALSE; @@ -9297,7 +10454,7 @@ boolean SnapField(struct PlayerInfo *player, int dx, int dy) player->is_dropping = FALSE; - if (DigField(player, x, y, 0, 0, DF_SNAP) == MF_NO_ACTION) + if (DigField(player, jx, jy, x, y, 0, 0, DF_SNAP) == MF_NO_ACTION) return FALSE; player->is_snapping = TRUE; @@ -9321,25 +10478,43 @@ boolean DropElement(struct PlayerInfo *player) { int jx = player->jx, jy = player->jy; int old_element = Feld[jx][jy]; - int new_element; + int new_element = (player->inventory_size > 0 ? + player->inventory_element[player->inventory_size - 1] : + player->inventory_infinite_element != EL_UNDEFINED ? + player->inventory_infinite_element : + player->dynabombs_left > 0 ? + EL_DYNABOMB_PLAYER_1_ACTIVE + player->index_nr : + EL_UNDEFINED); /* check if player is active, not moving and ready to drop */ if (!player->active || player->MovPos || player->drop_delay > 0) return FALSE; /* check if player has anything that can be dropped */ - if (player->inventory_size == 0 && player->dynabombs_left == 0) +#if 1 + if (new_element == EL_UNDEFINED) return FALSE; +#else + if (player->inventory_size == 0 && + player->inventory_infinite_element == EL_UNDEFINED && + player->dynabombs_left == 0) + return FALSE; +#endif /* check if anything can be dropped at the current position */ if (IS_ACTIVE_BOMB(old_element) || old_element == EL_EXPLOSION) return FALSE; /* collected custom elements can only be dropped on empty fields */ +#if 1 + if (IS_CUSTOM_ELEMENT(new_element) && old_element != EL_EMPTY) + return FALSE; +#else if (player->inventory_size > 0 && IS_CUSTOM_ELEMENT(player->inventory_element[player->inventory_size - 1]) && old_element != EL_EMPTY) return FALSE; +#endif if (old_element != EL_EMPTY) Back[jx][jy] = old_element; /* store old element on this field */ @@ -9347,35 +10522,52 @@ boolean DropElement(struct PlayerInfo *player) ResetGfxAnimation(jx, jy); ResetRandomAnimationValue(jx, jy); - if (player->inventory_size > 0) + if (player->inventory_size > 0 || + player->inventory_infinite_element != EL_UNDEFINED) { - player->inventory_size--; - new_element = player->inventory_element[player->inventory_size]; + if (player->inventory_size > 0) + { + player->inventory_size--; + +#if 0 + new_element = player->inventory_element[player->inventory_size]; +#endif - if (new_element == EL_DYNAMITE) - new_element = EL_DYNAMITE_ACTIVE; - else if (new_element == EL_SP_DISK_RED) - new_element = EL_SP_DISK_RED_ACTIVE; + DrawGameValue_Dynamite(local_player->inventory_size); - Feld[jx][jy] = new_element; + if (new_element == EL_DYNAMITE) + new_element = EL_DYNAMITE_ACTIVE; + else if (new_element == EL_SP_DISK_RED) + new_element = EL_SP_DISK_RED_ACTIVE; + } - DrawText(DX_DYNAMITE, DY_DYNAMITE, - int2str(local_player->inventory_size, 3), FONT_TEXT_2); + Feld[jx][jy] = new_element; if (IN_SCR_FIELD(SCREENX(jx), SCREENY(jy))) DrawGraphicThruMask(SCREENX(jx), SCREENY(jy), el2img(Feld[jx][jy]), 0); PlayLevelSoundAction(jx, jy, ACTION_DROPPING); - CheckTriggeredElementChange(jx, jy, new_element, CE_OTHER_GETS_DROPPED); - CheckElementChange(jx, jy, new_element, CE_DROPPED_BY_PLAYER); +#if 1 + /* needed if previous element just changed to "empty" in the last frame */ + Changed[jx][jy] = 0; /* allow another change */ +#endif + + CheckTriggeredElementChangePlayer(jx, jy, new_element, + CE_OTHER_GETS_DROPPED, + player->index_bit, CH_SIDE_ANY); + CheckElementChangePlayer(jx, jy, new_element, CE_DROPPED_BY_PLAYER, + player->index_bit, CH_SIDE_ANY); TestIfElementTouchesCustomElement(jx, jy); } else /* player is dropping a dyna bomb */ { player->dynabombs_left--; + +#if 0 new_element = EL_DYNABOMB_PLAYER_1_ACTIVE + player->index_nr; +#endif Feld[jx][jy] = new_element; @@ -9391,9 +10583,13 @@ boolean DropElement(struct PlayerInfo *player) if (Feld[jx][jy] == new_element) /* uninitialized unless CE change */ { +#if 1 + InitField_WithBug1(jx, jy, FALSE); +#else InitField(jx, jy, FALSE); if (CAN_MOVE(Feld[jx][jy])) InitMovDir(jx, jy); +#endif } new_element = Feld[jx][jy]; @@ -9404,7 +10600,7 @@ boolean DropElement(struct PlayerInfo *player) int move_stepsize = element_info[new_element].move_stepsize; int direction, dx, dy, nextx, nexty; - if (element_info[new_element].move_direction_initial == MV_AUTOMATIC) + if (element_info[new_element].move_direction_initial == MV_START_AUTOMATIC) MovDir[jx][jy] = player->MovDir; direction = MovDir[jx][jy]; @@ -9424,13 +10620,13 @@ boolean DropElement(struct PlayerInfo *player) } else { - Changed[jx][jy] = 0; /* allow another change */ + Changed[jx][jy] = 0; /* allow another change */ #if 1 TestIfElementHitsCustomElement(jx, jy, direction); #else - CheckElementSideChange(jx, jy, new_element, - direction, CE_HITTING_SOMETHING, -1); + CheckElementChangeSide(jx, jy, new_element, CE_HITTING_SOMETHING, + direction); #endif } @@ -9570,7 +10766,8 @@ static void PlayLevelMusic() void RaiseScore(int value) { local_player->score += value; - DrawText(DX_SCORE, DY_SCORE, int2str(local_player->score, 5), FONT_TEXT_2); + + DrawGameValue_Score(local_player->score); } void RaiseScoreElement(int element) @@ -9663,7 +10860,25 @@ void RequestQuitGame(boolean ask_if_really_quit) } else { + +#if 1 + if (tape.playing && tape.index_search) + { + SetDrawDeactivationMask(REDRAW_NONE); + audio.sound_deactivated = FALSE; + } +#endif + OpenDoor(DOOR_OPEN_1 | DOOR_COPY_BACK); + +#if 1 + if (tape.playing && tape.index_search) + { + SetDrawDeactivationMask(REDRAW_FIELD); + audio.sound_deactivated = TRUE; + } +#endif + } }