1 /***********************************************************
2 * Rocks'n'Diamonds -- McDuffin Strikes Back! *
3 *----------------------------------------------------------*
4 * (c) 1995-2002 Artsoft Entertainment *
6 * Detmolder Strasse 189 *
9 * e-mail: info@artsoft.org *
10 *----------------------------------------------------------*
12 ***********************************************************/
14 #include "libgame/libgame.h"
24 /* this switch controls how rocks move horizontally */
25 #define OLD_GAME_BEHAVIOUR FALSE
27 /* EXPERIMENTAL STUFF */
28 #define USE_NEW_AMOEBA_CODE FALSE
35 /* for MovePlayer() */
36 #define MF_NO_ACTION 0
40 /* for ScrollPlayer() */
42 #define SCROLL_GO_ON 1
45 #define EX_PHASE_START 0
46 #define EX_TYPE_NONE 0
47 #define EX_TYPE_NORMAL (1 << 0)
48 #define EX_TYPE_CENTER (1 << 1)
49 #define EX_TYPE_BORDER (1 << 2)
50 #define EX_TYPE_CROSS (1 << 3)
51 #define EX_TYPE_SINGLE_TILE (EX_TYPE_CENTER | EX_TYPE_BORDER)
53 /* special positions in the game control window (relative to control window) */
56 #define XX_EMERALDS 29
57 #define YY_EMERALDS 54
58 #define XX_DYNAMITE 29
59 #define YY_DYNAMITE 89
68 /* special positions in the game control window (relative to main window) */
69 #define DX_LEVEL (DX + XX_LEVEL)
70 #define DY_LEVEL (DY + YY_LEVEL)
71 #define DX_EMERALDS (DX + XX_EMERALDS)
72 #define DY_EMERALDS (DY + YY_EMERALDS)
73 #define DX_DYNAMITE (DX + XX_DYNAMITE)
74 #define DY_DYNAMITE (DY + YY_DYNAMITE)
75 #define DX_KEYS (DX + XX_KEYS)
76 #define DY_KEYS (DY + YY_KEYS)
77 #define DX_SCORE (DX + XX_SCORE)
78 #define DY_SCORE (DY + YY_SCORE)
79 #define DX_TIME1 (DX + XX_TIME1)
80 #define DX_TIME2 (DX + XX_TIME2)
81 #define DY_TIME (DY + YY_TIME)
83 /* values for initial player move delay (initial delay counter value) */
84 #define INITIAL_MOVE_DELAY_OFF -1
85 #define INITIAL_MOVE_DELAY_ON 0
87 /* values for player movement speed (which is in fact a delay value) */
88 #define MOVE_DELAY_NORMAL_SPEED 8
89 #define MOVE_DELAY_HIGH_SPEED 4
91 #define DOUBLE_MOVE_DELAY(x) (x = (x <= MOVE_DELAY_HIGH_SPEED ? x * 2 : x))
92 #define HALVE_MOVE_DELAY(x) (x = (x >= MOVE_DELAY_HIGH_SPEED ? x / 2 : x))
93 #define DOUBLE_PLAYER_SPEED(p) (HALVE_MOVE_DELAY((p)->move_delay_value))
94 #define HALVE_PLAYER_SPEED(p) (DOUBLE_MOVE_DELAY((p)->move_delay_value))
96 /* values for other actions */
97 #define MOVE_STEPSIZE_NORMAL (TILEX / MOVE_DELAY_NORMAL_SPEED)
99 #define INIT_GFX_RANDOM() (SimpleRND(1000000))
101 #define GET_NEW_PUSH_DELAY(e) ( (element_info[e].push_delay_fixed) + \
102 RND(element_info[e].push_delay_random))
103 #define GET_NEW_DROP_DELAY(e) ( (element_info[e].drop_delay_fixed) + \
104 RND(element_info[e].drop_delay_random))
105 #define GET_NEW_MOVE_DELAY(e) ( (element_info[e].move_delay_fixed) + \
106 RND(element_info[e].move_delay_random))
107 #define GET_MAX_MOVE_DELAY(e) ( (element_info[e].move_delay_fixed) + \
108 (element_info[e].move_delay_random))
110 #define GET_TARGET_ELEMENT(e, ch) \
111 ((e) == EL_TRIGGER_ELEMENT ? (ch)->actual_trigger_element : \
112 (e) == EL_TRIGGER_PLAYER ? (ch)->actual_trigger_player : (e))
114 #define ELEMENT_CAN_ENTER_FIELD_BASE_X(x, y, condition) \
115 (IN_LEV_FIELD(x, y) && (IS_FREE(x, y) || \
118 #define ELEMENT_CAN_ENTER_FIELD_BASE_2(e, x, y, condition) \
119 (IN_LEV_FIELD(x, y) && (IS_FREE(x, y) || \
120 (CAN_MOVE_INTO_ACID(e) && \
121 Feld[x][y] == EL_ACID) || \
124 #define ELEMENT_CAN_ENTER_FIELD_BASE_3(e, x, y, condition) \
125 (IN_LEV_FIELD(x, y) && (IS_FREE_OR_PLAYER(x, y) || \
126 (CAN_MOVE_INTO_ACID(e) && \
127 Feld[x][y] == EL_ACID) || \
130 #define ELEMENT_CAN_ENTER_FIELD_BASE_4(e, x, y, condition) \
131 (IN_LEV_FIELD(x, y) && (IS_FREE(x, y) || \
133 (CAN_MOVE_INTO_ACID(e) && \
134 Feld[x][y] == EL_ACID) || \
135 (DONT_COLLIDE_WITH(e) && \
137 !PLAYER_ENEMY_PROTECTED(x, y))))
140 #define ELEMENT_CAN_ENTER_FIELD_GENERIC(e, x, y, condition) \
141 (IN_LEV_FIELD(x, y) && (IS_FREE(x, y) || \
143 (DONT_COLLIDE_WITH(e) && \
145 !PLAYER_ENEMY_PROTECTED(x, y))))
148 #define ELEMENT_CAN_ENTER_FIELD(e, x, y) \
149 ELEMENT_CAN_ENTER_FIELD_BASE_4(e, x, y, 0)
152 #define SATELLITE_CAN_ENTER_FIELD(x, y) \
153 ELEMENT_CAN_ENTER_FIELD_BASE_2(EL_SATELLITE, x, y, 0)
155 #define SATELLITE_CAN_ENTER_FIELD(x, y) \
156 ELEMENT_CAN_ENTER_FIELD_BASE_X(x, y, Feld[x][y] == EL_ACID)
160 #define ENEMY_CAN_ENTER_FIELD(e, x, y) (IN_LEV_FIELD(x, y) && IS_FREE(x, y))
163 #define ENEMY_CAN_ENTER_FIELD(e, x, y) \
164 ELEMENT_CAN_ENTER_FIELD_BASE_2(e, x, y, 0)
168 #define YAMYAM_CAN_ENTER_FIELD(e, x, y) \
169 ELEMENT_CAN_ENTER_FIELD_BASE_3(e, x, y, Feld[x][y] == EL_DIAMOND)
171 #define DARK_YAMYAM_CAN_ENTER_FIELD(e, x, y) \
172 ELEMENT_CAN_ENTER_FIELD_BASE_3(e, x,y, IS_FOOD_DARK_YAMYAM(Feld[x][y]))
174 #define PACMAN_CAN_ENTER_FIELD(e, x, y) \
175 ELEMENT_CAN_ENTER_FIELD_BASE_3(e, x, y, IS_AMOEBOID(Feld[x][y]))
177 #define PIG_CAN_ENTER_FIELD(e, x, y) \
178 ELEMENT_CAN_ENTER_FIELD_BASE_2(e, x, y, IS_FOOD_PIG(Feld[x][y]))
180 #define PENGUIN_CAN_ENTER_FIELD(e, x, y) \
181 ELEMENT_CAN_ENTER_FIELD_BASE_2(e, x, y, (Feld[x][y] == EL_EXIT_OPEN ||\
182 IS_FOOD_PENGUIN(Feld[x][y])))
183 #define DRAGON_CAN_ENTER_FIELD(e, x, y) \
184 ELEMENT_CAN_ENTER_FIELD_BASE_2(e, x, y, 0)
186 #define MOLE_CAN_ENTER_FIELD(e, x, y, condition) \
187 ELEMENT_CAN_ENTER_FIELD_BASE_2(e, x, y, (condition))
189 #define SPRING_CAN_ENTER_FIELD(e, x, y) \
190 ELEMENT_CAN_ENTER_FIELD_BASE_2(e, x, y, 0)
194 #define YAMYAM_CAN_ENTER_FIELD(e, x, y) \
195 (IN_LEV_FIELD(x, y) && (IS_FREE_OR_PLAYER(x, y) || \
196 (CAN_MOVE_INTO_ACID(e) && \
197 Feld[x][y] == EL_ACID) || \
198 Feld[x][y] == EL_DIAMOND))
200 #define DARK_YAMYAM_CAN_ENTER_FIELD(e, x, y) \
201 (IN_LEV_FIELD(x, y) && (IS_FREE_OR_PLAYER(x, y) || \
202 (CAN_MOVE_INTO_ACID(e) && \
203 Feld[x][y] == EL_ACID) || \
204 IS_FOOD_DARK_YAMYAM(Feld[x][y])))
206 #define PACMAN_CAN_ENTER_FIELD(e, x, y) \
207 (IN_LEV_FIELD(x, y) && (IS_FREE_OR_PLAYER(x, y) || \
208 (CAN_MOVE_INTO_ACID(e) && \
209 Feld[x][y] == EL_ACID) || \
210 IS_AMOEBOID(Feld[x][y])))
212 #define PIG_CAN_ENTER_FIELD(e, x, y) \
213 (IN_LEV_FIELD(x, y) && (IS_FREE(x, y) || \
214 (CAN_MOVE_INTO_ACID(e) && \
215 Feld[x][y] == EL_ACID) || \
216 IS_FOOD_PIG(Feld[x][y])))
218 #define PENGUIN_CAN_ENTER_FIELD(e, x, y) \
219 (IN_LEV_FIELD(x, y) && (IS_FREE(x, y) || \
220 (CAN_MOVE_INTO_ACID(e) && \
221 Feld[x][y] == EL_ACID) || \
222 IS_FOOD_PENGUIN(Feld[x][y]) || \
223 Feld[x][y] == EL_EXIT_OPEN))
225 #define DRAGON_CAN_ENTER_FIELD(e, x, y) \
226 (IN_LEV_FIELD(x, y) && (IS_FREE(x, y) || \
227 (CAN_MOVE_INTO_ACID(e) && \
228 Feld[x][y] == EL_ACID)))
230 #define MOLE_CAN_ENTER_FIELD(e, x, y, condition) \
231 (IN_LEV_FIELD(x, y) && (IS_FREE(x, y) || \
232 (CAN_MOVE_INTO_ACID(e) && \
233 Feld[x][y] == EL_ACID) || \
236 #define SPRING_CAN_ENTER_FIELD(e, x, y) \
237 (IN_LEV_FIELD(x, y) && (IS_FREE(x, y) || \
238 (CAN_MOVE_INTO_ACID(e) && \
239 Feld[x][y] == EL_ACID)))
243 #define GROUP_NR(e) ((e) - EL_GROUP_START)
244 #define MOVE_ENTER_EL(e) (element_info[e].move_enter_element)
245 #define IS_IN_GROUP(e, nr) (element_info[e].in_group[nr] == TRUE)
246 #define IS_IN_GROUP_EL(e, ge) (IS_IN_GROUP(e, (ge) - EL_GROUP_START))
248 #define IS_EQUAL_OR_IN_GROUP(e, ge) \
249 (IS_GROUP_ELEMENT(ge) ? IS_IN_GROUP(e, GROUP_NR(ge)) : (e) == (ge))
252 #define CE_ENTER_FIELD_COND(e, x, y) \
253 (!IS_PLAYER(x, y) && \
254 (Feld[x][y] == EL_ACID || \
255 IS_EQUAL_OR_IN_GROUP(Feld[x][y], MOVE_ENTER_EL(e))))
257 #define CE_ENTER_FIELD_COND(e, x, y) \
258 (!IS_PLAYER(x, y) && \
259 IS_EQUAL_OR_IN_GROUP(Feld[x][y], MOVE_ENTER_EL(e)))
262 #define CUSTOM_ELEMENT_CAN_ENTER_FIELD(e, x, y) \
263 ELEMENT_CAN_ENTER_FIELD_BASE_4(e, x, y, CE_ENTER_FIELD_COND(e, x, y))
265 #define IN_LEV_FIELD_AND_IS_FREE(x, y) (IN_LEV_FIELD(x, y) && IS_FREE(x, y))
266 #define IN_LEV_FIELD_AND_NOT_FREE(x, y) (IN_LEV_FIELD(x, y) && !IS_FREE(x, y))
268 #define ACCESS_FROM(e, d) (element_info[e].access_direction &(d))
269 #define IS_WALKABLE_FROM(e, d) (IS_WALKABLE(e) && ACCESS_FROM(e, d))
270 #define IS_PASSABLE_FROM(e, d) (IS_PASSABLE(e) && ACCESS_FROM(e, d))
271 #define IS_ACCESSIBLE_FROM(e, d) (IS_ACCESSIBLE(e) && ACCESS_FROM(e, d))
273 /* game button identifiers */
274 #define GAME_CTRL_ID_STOP 0
275 #define GAME_CTRL_ID_PAUSE 1
276 #define GAME_CTRL_ID_PLAY 2
277 #define SOUND_CTRL_ID_MUSIC 3
278 #define SOUND_CTRL_ID_LOOPS 4
279 #define SOUND_CTRL_ID_SIMPLE 5
281 #define NUM_GAME_BUTTONS 6
284 /* forward declaration for internal use */
286 static boolean MovePlayerOneStep(struct PlayerInfo *, int, int, int, int);
287 static boolean MovePlayer(struct PlayerInfo *, int, int);
288 static void ScrollPlayer(struct PlayerInfo *, int);
289 static void ScrollScreen(struct PlayerInfo *, int);
291 int DigField(struct PlayerInfo *, int, int, int, int, int, int, int);
293 static void InitBeltMovement(void);
294 static void CloseAllOpenTimegates(void);
295 static void CheckGravityMovement(struct PlayerInfo *);
296 static void CheckGravityMovementWhenNotMoving(struct PlayerInfo *);
297 static void KillHeroUnlessEnemyProtected(int, int);
298 static void KillHeroUnlessExplosionProtected(int, int);
300 static void TestIfPlayerTouchesCustomElement(int, int);
301 static void TestIfElementTouchesCustomElement(int, int);
302 static void TestIfElementHitsCustomElement(int, int, int);
304 static void TestIfElementSmashesCustomElement(int, int, int);
307 static void ChangeElement(int, int, int);
309 static boolean CheckTriggeredElementChangeExt(int, int, int, int, int,int,int);
310 #define CheckTriggeredElementChange(x, y, e, ev) \
311 CheckTriggeredElementChangeExt(x, y, e, ev, CH_PLAYER_ANY, \
313 #define CheckTriggeredElementChangePlayer(x, y, e, ev, p, s) \
314 CheckTriggeredElementChangeExt(x, y, e, ev, p, s, -1)
315 #define CheckTriggeredElementChangeSide(x, y, e, ev, s) \
316 CheckTriggeredElementChangeExt(x, y, e, ev, CH_PLAYER_ANY, s, -1)
317 #define CheckTriggeredElementChangePage(x, y, e, ev, p) \
318 CheckTriggeredElementChangeExt(x, y, e, ev, CH_PLAYER_ANY, \
321 static boolean CheckElementChangeExt(int, int, int, int, int, int, int, int);
322 #define CheckElementChange(x, y, e, te, ev) \
323 CheckElementChangeExt(x, y, e, te, ev, CH_PLAYER_ANY, CH_SIDE_ANY, -1)
324 #define CheckElementChangePlayer(x, y, e, ev, p, s) \
325 CheckElementChangeExt(x, y, e, EL_EMPTY, ev, p, s, CH_PAGE_ANY)
326 #define CheckElementChangeSide(x, y, e, te, ev, s) \
327 CheckElementChangeExt(x, y, e, te, ev, CH_PLAYER_ANY, s, CH_PAGE_ANY)
328 #define CheckElementChangePage(x, y, e, te, ev, p) \
329 CheckElementChangeExt(x, y, e, te, ev, CH_PLAYER_ANY, CH_SIDE_ANY, p)
331 static void PlayLevelSound(int, int, int);
332 static void PlayLevelSoundNearest(int, int, int);
333 static void PlayLevelSoundAction(int, int, int);
334 static void PlayLevelSoundElementAction(int, int, int, int);
335 static void PlayLevelSoundElementActionIfLoop(int, int, int, int);
336 static void PlayLevelSoundActionIfLoop(int, int, int);
337 static void StopLevelSoundActionIfLoop(int, int, int);
338 static void PlayLevelMusic();
340 static void MapGameButtons();
341 static void HandleGameButtons(struct GadgetInfo *);
343 static struct GadgetInfo *game_gadget[NUM_GAME_BUTTONS];
346 /* ------------------------------------------------------------------------- */
347 /* definition of elements that automatically change to other elements after */
348 /* a specified time, eventually calling a function when changing */
349 /* ------------------------------------------------------------------------- */
351 /* forward declaration for changer functions */
352 static void InitBuggyBase(int x, int y);
353 static void WarnBuggyBase(int x, int y);
355 static void InitTrap(int x, int y);
356 static void ActivateTrap(int x, int y);
357 static void ChangeActiveTrap(int x, int y);
359 static void InitRobotWheel(int x, int y);
360 static void RunRobotWheel(int x, int y);
361 static void StopRobotWheel(int x, int y);
363 static void InitTimegateWheel(int x, int y);
364 static void RunTimegateWheel(int x, int y);
366 struct ChangingElementInfo
371 void (*pre_change_function)(int x, int y);
372 void (*change_function)(int x, int y);
373 void (*post_change_function)(int x, int y);
376 static struct ChangingElementInfo change_delay_list[] =
427 EL_SWITCHGATE_OPENING,
435 EL_SWITCHGATE_CLOSING,
436 EL_SWITCHGATE_CLOSED,
468 EL_ACID_SPLASH_RIGHT,
477 EL_SP_BUGGY_BASE_ACTIVATING,
484 EL_SP_BUGGY_BASE_ACTIVATING,
485 EL_SP_BUGGY_BASE_ACTIVE,
492 EL_SP_BUGGY_BASE_ACTIVE,
516 EL_ROBOT_WHEEL_ACTIVE,
524 EL_TIMEGATE_SWITCH_ACTIVE,
545 int push_delay_fixed, push_delay_random;
550 { EL_BALLOON, 0, 0 },
552 { EL_SOKOBAN_OBJECT, 2, 0 },
553 { EL_SOKOBAN_FIELD_FULL, 2, 0 },
554 { EL_SATELLITE, 2, 0 },
555 { EL_SP_DISK_YELLOW, 2, 0 },
557 { EL_UNDEFINED, 0, 0 },
565 move_stepsize_list[] =
567 { EL_AMOEBA_DROP, 2 },
568 { EL_AMOEBA_DROPPING, 2 },
569 { EL_QUICKSAND_FILLING, 1 },
570 { EL_QUICKSAND_EMPTYING, 1 },
571 { EL_MAGIC_WALL_FILLING, 2 },
572 { EL_BD_MAGIC_WALL_FILLING, 2 },
573 { EL_MAGIC_WALL_EMPTYING, 2 },
574 { EL_BD_MAGIC_WALL_EMPTYING, 2 },
584 collect_count_list[] =
587 { EL_BD_DIAMOND, 1 },
588 { EL_EMERALD_YELLOW, 1 },
589 { EL_EMERALD_RED, 1 },
590 { EL_EMERALD_PURPLE, 1 },
592 { EL_SP_INFOTRON, 1 },
604 access_direction_list[] =
606 { EL_TUBE_ANY, MV_LEFT | MV_RIGHT | MV_UP | MV_DOWN },
607 { EL_TUBE_VERTICAL, MV_UP | MV_DOWN },
608 { EL_TUBE_HORIZONTAL, MV_LEFT | MV_RIGHT },
609 { EL_TUBE_VERTICAL_LEFT, MV_LEFT | MV_UP | MV_DOWN },
610 { EL_TUBE_VERTICAL_RIGHT, MV_RIGHT | MV_UP | MV_DOWN },
611 { EL_TUBE_HORIZONTAL_UP, MV_LEFT | MV_RIGHT | MV_UP },
612 { EL_TUBE_HORIZONTAL_DOWN, MV_LEFT | MV_RIGHT | MV_DOWN },
613 { EL_TUBE_LEFT_UP, MV_LEFT | MV_UP },
614 { EL_TUBE_LEFT_DOWN, MV_LEFT | MV_DOWN },
615 { EL_TUBE_RIGHT_UP, MV_RIGHT | MV_UP },
616 { EL_TUBE_RIGHT_DOWN, MV_RIGHT | MV_DOWN },
618 { EL_SP_PORT_LEFT, MV_RIGHT },
619 { EL_SP_PORT_RIGHT, MV_LEFT },
620 { EL_SP_PORT_UP, MV_DOWN },
621 { EL_SP_PORT_DOWN, MV_UP },
622 { EL_SP_PORT_HORIZONTAL, MV_LEFT | MV_RIGHT },
623 { EL_SP_PORT_VERTICAL, MV_UP | MV_DOWN },
624 { EL_SP_PORT_ANY, MV_LEFT | MV_RIGHT | MV_UP | MV_DOWN },
625 { EL_SP_GRAVITY_PORT_LEFT, MV_RIGHT },
626 { EL_SP_GRAVITY_PORT_RIGHT, MV_LEFT },
627 { EL_SP_GRAVITY_PORT_UP, MV_DOWN },
628 { EL_SP_GRAVITY_PORT_DOWN, MV_UP },
630 { EL_UNDEFINED, MV_NO_MOVING }
633 static unsigned long trigger_events[MAX_NUM_ELEMENTS];
635 #define IS_AUTO_CHANGING(e) (element_info[e].change_events & \
636 CH_EVENT_BIT(CE_DELAY))
637 #define IS_JUST_CHANGING(x, y) (ChangeDelay[x][y] != 0)
638 #define IS_CHANGING(x, y) (IS_AUTO_CHANGING(Feld[x][y]) || \
639 IS_JUST_CHANGING(x, y))
641 #define CE_PAGE(e, ce) (element_info[e].event_page[ce])
644 void GetPlayerConfig()
646 if (!audio.sound_available)
647 setup.sound_simple = FALSE;
649 if (!audio.loops_available)
650 setup.sound_loops = FALSE;
652 if (!audio.music_available)
653 setup.sound_music = FALSE;
655 if (!video.fullscreen_available)
656 setup.fullscreen = FALSE;
658 setup.sound = (setup.sound_simple || setup.sound_loops || setup.sound_music);
660 SetAudioMode(setup.sound);
664 static int getBeltNrFromBeltElement(int element)
666 return (element < EL_CONVEYOR_BELT_2_LEFT ? 0 :
667 element < EL_CONVEYOR_BELT_3_LEFT ? 1 :
668 element < EL_CONVEYOR_BELT_4_LEFT ? 2 : 3);
671 static int getBeltNrFromBeltActiveElement(int element)
673 return (element < EL_CONVEYOR_BELT_2_LEFT_ACTIVE ? 0 :
674 element < EL_CONVEYOR_BELT_3_LEFT_ACTIVE ? 1 :
675 element < EL_CONVEYOR_BELT_4_LEFT_ACTIVE ? 2 : 3);
678 static int getBeltNrFromBeltSwitchElement(int element)
680 return (element < EL_CONVEYOR_BELT_2_SWITCH_LEFT ? 0 :
681 element < EL_CONVEYOR_BELT_3_SWITCH_LEFT ? 1 :
682 element < EL_CONVEYOR_BELT_4_SWITCH_LEFT ? 2 : 3);
685 static int getBeltDirNrFromBeltSwitchElement(int element)
687 static int belt_base_element[4] =
689 EL_CONVEYOR_BELT_1_SWITCH_LEFT,
690 EL_CONVEYOR_BELT_2_SWITCH_LEFT,
691 EL_CONVEYOR_BELT_3_SWITCH_LEFT,
692 EL_CONVEYOR_BELT_4_SWITCH_LEFT
695 int belt_nr = getBeltNrFromBeltSwitchElement(element);
696 int belt_dir_nr = element - belt_base_element[belt_nr];
698 return (belt_dir_nr % 3);
701 static int getBeltDirFromBeltSwitchElement(int element)
703 static int belt_move_dir[3] =
710 int belt_dir_nr = getBeltDirNrFromBeltSwitchElement(element);
712 return belt_move_dir[belt_dir_nr];
715 static void InitPlayerField(int x, int y, int element, boolean init_game)
717 if (element == EL_SP_MURPHY)
721 if (stored_player[0].present)
723 Feld[x][y] = EL_SP_MURPHY_CLONE;
729 stored_player[0].use_murphy_graphic = TRUE;
732 Feld[x][y] = EL_PLAYER_1;
738 struct PlayerInfo *player = &stored_player[Feld[x][y] - EL_PLAYER_1];
739 int jx = player->jx, jy = player->jy;
741 player->present = TRUE;
743 player->block_last_field = (element == EL_SP_MURPHY ?
744 level.sp_block_last_field :
745 level.block_last_field);
747 if (!options.network || player->connected)
749 player->active = TRUE;
751 /* remove potentially duplicate players */
752 if (StorePlayer[jx][jy] == Feld[x][y])
753 StorePlayer[jx][jy] = 0;
755 StorePlayer[x][y] = Feld[x][y];
759 printf("Player %d activated.\n", player->element_nr);
760 printf("[Local player is %d and currently %s.]\n",
761 local_player->element_nr,
762 local_player->active ? "active" : "not active");
766 Feld[x][y] = EL_EMPTY;
767 player->jx = player->last_jx = x;
768 player->jy = player->last_jy = y;
772 static void InitField(int x, int y, boolean init_game)
774 int element = Feld[x][y];
783 InitPlayerField(x, y, element, init_game);
786 case EL_SOKOBAN_FIELD_PLAYER:
787 element = Feld[x][y] = EL_PLAYER_1;
788 InitField(x, y, init_game);
790 element = Feld[x][y] = EL_SOKOBAN_FIELD_EMPTY;
791 InitField(x, y, init_game);
794 case EL_SOKOBAN_FIELD_EMPTY:
795 local_player->sokobanfields_still_needed++;
799 if (x < lev_fieldx-1 && Feld[x+1][y] == EL_ACID)
800 Feld[x][y] = EL_ACID_POOL_TOPLEFT;
801 else if (x > 0 && Feld[x-1][y] == EL_ACID)
802 Feld[x][y] = EL_ACID_POOL_TOPRIGHT;
803 else if (y > 0 && Feld[x][y-1] == EL_ACID_POOL_TOPLEFT)
804 Feld[x][y] = EL_ACID_POOL_BOTTOMLEFT;
805 else if (y > 0 && Feld[x][y-1] == EL_ACID)
806 Feld[x][y] = EL_ACID_POOL_BOTTOM;
807 else if (y > 0 && Feld[x][y-1] == EL_ACID_POOL_TOPRIGHT)
808 Feld[x][y] = EL_ACID_POOL_BOTTOMRIGHT;
816 case EL_SPACESHIP_RIGHT:
817 case EL_SPACESHIP_UP:
818 case EL_SPACESHIP_LEFT:
819 case EL_SPACESHIP_DOWN:
821 case EL_BD_BUTTERFLY_RIGHT:
822 case EL_BD_BUTTERFLY_UP:
823 case EL_BD_BUTTERFLY_LEFT:
824 case EL_BD_BUTTERFLY_DOWN:
825 case EL_BD_BUTTERFLY:
826 case EL_BD_FIREFLY_RIGHT:
827 case EL_BD_FIREFLY_UP:
828 case EL_BD_FIREFLY_LEFT:
829 case EL_BD_FIREFLY_DOWN:
831 case EL_PACMAN_RIGHT:
855 if (y == lev_fieldy - 1)
857 Feld[x][y] = EL_AMOEBA_GROWING;
858 Store[x][y] = EL_AMOEBA_WET;
862 case EL_DYNAMITE_ACTIVE:
863 case EL_SP_DISK_RED_ACTIVE:
864 case EL_DYNABOMB_PLAYER_1_ACTIVE:
865 case EL_DYNABOMB_PLAYER_2_ACTIVE:
866 case EL_DYNABOMB_PLAYER_3_ACTIVE:
867 case EL_DYNABOMB_PLAYER_4_ACTIVE:
872 local_player->lights_still_needed++;
876 local_player->friends_still_needed++;
881 GfxDir[x][y] = MovDir[x][y] = 1 << RND(4);
886 Feld[x][y] = EL_EMPTY;
891 case EL_EM_KEY_1_FILE:
892 Feld[x][y] = EL_EM_KEY_1;
894 case EL_EM_KEY_2_FILE:
895 Feld[x][y] = EL_EM_KEY_2;
897 case EL_EM_KEY_3_FILE:
898 Feld[x][y] = EL_EM_KEY_3;
900 case EL_EM_KEY_4_FILE:
901 Feld[x][y] = EL_EM_KEY_4;
905 case EL_CONVEYOR_BELT_1_SWITCH_LEFT:
906 case EL_CONVEYOR_BELT_1_SWITCH_MIDDLE:
907 case EL_CONVEYOR_BELT_1_SWITCH_RIGHT:
908 case EL_CONVEYOR_BELT_2_SWITCH_LEFT:
909 case EL_CONVEYOR_BELT_2_SWITCH_MIDDLE:
910 case EL_CONVEYOR_BELT_2_SWITCH_RIGHT:
911 case EL_CONVEYOR_BELT_3_SWITCH_LEFT:
912 case EL_CONVEYOR_BELT_3_SWITCH_MIDDLE:
913 case EL_CONVEYOR_BELT_3_SWITCH_RIGHT:
914 case EL_CONVEYOR_BELT_4_SWITCH_LEFT:
915 case EL_CONVEYOR_BELT_4_SWITCH_MIDDLE:
916 case EL_CONVEYOR_BELT_4_SWITCH_RIGHT:
919 int belt_nr = getBeltNrFromBeltSwitchElement(Feld[x][y]);
920 int belt_dir = getBeltDirFromBeltSwitchElement(Feld[x][y]);
921 int belt_dir_nr = getBeltDirNrFromBeltSwitchElement(Feld[x][y]);
923 if (game.belt_dir_nr[belt_nr] == 3) /* initial value */
925 game.belt_dir[belt_nr] = belt_dir;
926 game.belt_dir_nr[belt_nr] = belt_dir_nr;
928 else /* more than one switch -- set it like the first switch */
930 Feld[x][y] = Feld[x][y] - belt_dir_nr + game.belt_dir_nr[belt_nr];
935 case EL_SWITCHGATE_SWITCH_DOWN: /* always start with same switch pos */
937 Feld[x][y] = EL_SWITCHGATE_SWITCH_UP;
940 case EL_LIGHT_SWITCH_ACTIVE:
942 game.light_time_left = level.time_light * FRAMES_PER_SECOND;
946 if (IS_CUSTOM_ELEMENT(element) && CAN_MOVE(element))
948 else if (IS_GROUP_ELEMENT(element))
950 struct ElementGroupInfo *group = element_info[element].group;
951 int last_anim_random_frame = gfx.anim_random_frame;
954 if (group->choice_mode == ANIM_RANDOM)
955 gfx.anim_random_frame = RND(group->num_elements_resolved);
957 element_pos = getAnimationFrame(group->num_elements_resolved, 1,
958 group->choice_mode, 0,
961 if (group->choice_mode == ANIM_RANDOM)
962 gfx.anim_random_frame = last_anim_random_frame;
966 Feld[x][y] = group->element_resolved[element_pos];
968 InitField(x, y, init_game);
974 static inline void InitField_WithBug1(int x, int y, boolean init_game)
976 InitField(x, y, init_game);
978 /* not needed to call InitMovDir() -- already done by InitField()! */
979 if (game.engine_version < VERSION_IDENT(3,1,0,0) &&
980 CAN_MOVE(Feld[x][y]))
984 static inline void InitField_WithBug2(int x, int y, boolean init_game)
986 int old_element = Feld[x][y];
988 InitField(x, y, init_game);
990 /* not needed to call InitMovDir() -- already done by InitField()! */
991 if (game.engine_version < VERSION_IDENT(3,1,0,0) &&
992 CAN_MOVE(old_element) &&
993 (old_element < EL_MOLE_LEFT || old_element > EL_MOLE_DOWN))
996 /* this case is in fact a combination of not less than three bugs:
997 first, it calls InitMovDir() for elements that can move, although this is
998 already done by InitField(); then, it checks the element that was at this
999 field _before_ the call to InitField() (which can change it)
1004 inline void DrawGameValue_Emeralds(int value)
1006 DrawText(DX_EMERALDS, DY_EMERALDS, int2str(value, 3), FONT_TEXT_2);
1009 inline void DrawGameValue_Dynamite(int value)
1011 DrawText(DX_DYNAMITE, DY_DYNAMITE, int2str(value, 3), FONT_TEXT_2);
1014 inline void DrawGameValue_Keys(struct PlayerInfo *player)
1018 for (i = 0; i < MAX_KEYS; i++)
1020 DrawMiniGraphicExt(drawto, DX_KEYS + i * MINI_TILEX, DY_KEYS,
1021 el2edimg(EL_KEY_1 + i));
1024 inline void DrawGameValue_Score(int value)
1026 DrawText(DX_SCORE, DY_SCORE, int2str(value, 5), FONT_TEXT_2);
1029 inline void DrawGameValue_Time(int value)
1032 DrawText(DX_TIME1, DY_TIME, int2str(value, 3), FONT_TEXT_2);
1034 DrawText(DX_TIME2, DY_TIME, int2str(value, 4), FONT_LEVEL_NUMBER);
1037 inline void DrawGameValue_Level(int value)
1040 DrawText(DX_LEVEL, DY_LEVEL, int2str(value, 2), FONT_TEXT_2);
1043 /* misuse area for displaying emeralds to draw bigger level number */
1044 DrawTextExt(drawto, DX_EMERALDS, DY_EMERALDS,
1045 int2str(value, 3), FONT_LEVEL_NUMBER, BLIT_OPAQUE);
1047 /* now copy it to the area for displaying level number */
1048 BlitBitmap(drawto, drawto,
1049 DX_EMERALDS, DY_EMERALDS + 1,
1050 getFontWidth(FONT_LEVEL_NUMBER) * 3,
1051 getFontHeight(FONT_LEVEL_NUMBER) - 1,
1052 DX_LEVEL - 1, DY_LEVEL + 1);
1054 /* restore the area for displaying emeralds */
1055 DrawGameValue_Emeralds(local_player->gems_still_needed);
1057 /* yes, this is all really ugly :-) */
1061 void DrawGameDoorValues()
1065 DrawGameValue_Level(level_nr);
1067 for (i = 0; i < MAX_PLAYERS; i++)
1068 DrawGameValue_Keys(&stored_player[i]);
1070 DrawGameValue_Emeralds(local_player->gems_still_needed);
1071 DrawGameValue_Dynamite(local_player->inventory_size);
1072 DrawGameValue_Score(local_player->score);
1073 DrawGameValue_Time(TimeLeft);
1076 static void resolve_group_element(int group_element, int recursion_depth)
1078 static int group_nr;
1079 static struct ElementGroupInfo *group;
1080 struct ElementGroupInfo *actual_group = element_info[group_element].group;
1083 if (recursion_depth > NUM_GROUP_ELEMENTS) /* recursion too deep */
1085 Error(ERR_WARN, "recursion too deep when resolving group element %d",
1086 group_element - EL_GROUP_START + 1);
1088 /* replace element which caused too deep recursion by question mark */
1089 group->element_resolved[group->num_elements_resolved++] = EL_UNKNOWN;
1094 if (recursion_depth == 0) /* initialization */
1096 group = element_info[group_element].group;
1097 group_nr = group_element - EL_GROUP_START;
1099 group->num_elements_resolved = 0;
1100 group->choice_pos = 0;
1103 for (i = 0; i < actual_group->num_elements; i++)
1105 int element = actual_group->element[i];
1107 if (group->num_elements_resolved == NUM_FILE_ELEMENTS)
1110 if (IS_GROUP_ELEMENT(element))
1111 resolve_group_element(element, recursion_depth + 1);
1114 group->element_resolved[group->num_elements_resolved++] = element;
1115 element_info[element].in_group[group_nr] = TRUE;
1120 if (recursion_depth == 0 && group_element <= EL_GROUP_4)
1122 printf("::: group %d: %d resolved elements\n",
1123 group_element - EL_GROUP_START, group->num_elements_resolved);
1124 for (i = 0; i < group->num_elements_resolved; i++)
1125 printf("::: - %d ['%s']\n", group->element_resolved[i],
1126 element_info[group->element_resolved[i]].token_name);
1133 =============================================================================
1135 -----------------------------------------------------------------------------
1136 initialize game engine due to level / tape version number
1137 =============================================================================
1140 static void InitGameEngine()
1144 /* set game engine from tape file when re-playing, else from level file */
1145 game.engine_version = (tape.playing ? tape.engine_version :
1146 level.game_version);
1148 /* dynamically adjust element properties according to game engine version */
1149 InitElementPropertiesEngine(game.engine_version);
1152 printf("level %d: level version == %06d\n", level_nr, level.game_version);
1153 printf(" tape version == %06d [%s] [file: %06d]\n",
1154 tape.engine_version, (tape.playing ? "PLAYING" : "RECORDING"),
1156 printf(" => game.engine_version == %06d\n", game.engine_version);
1159 /* ---------- recursively resolve group elements ------------------------- */
1161 for (i = 0; i < MAX_NUM_ELEMENTS; i++)
1162 for (j = 0; j < NUM_GROUP_ELEMENTS; j++)
1163 element_info[i].in_group[j] = FALSE;
1165 for (i = 0; i < NUM_GROUP_ELEMENTS; i++)
1166 resolve_group_element(EL_GROUP_START + i, 0);
1168 /* ---------- initialize player's initial move delay --------------------- */
1170 /* dynamically adjust player properties according to game engine version */
1171 game.initial_move_delay =
1172 (game.engine_version <= VERSION_IDENT(2,0,1,0) ? INITIAL_MOVE_DELAY_ON :
1173 INITIAL_MOVE_DELAY_OFF);
1175 /* dynamically adjust player properties according to level information */
1176 game.initial_move_delay_value =
1177 (level.double_speed ? MOVE_DELAY_HIGH_SPEED : MOVE_DELAY_NORMAL_SPEED);
1179 /* ---------- initialize player's initial push delay --------------------- */
1181 /* dynamically adjust player properties according to game engine version */
1182 game.initial_push_delay_value =
1183 (game.engine_version < VERSION_IDENT(3,0,7,1) ? 5 : -1);
1185 /* ---------- initialize changing elements ------------------------------- */
1187 /* initialize changing elements information */
1188 for (i = 0; i < MAX_NUM_ELEMENTS; i++)
1190 struct ElementInfo *ei = &element_info[i];
1192 /* this pointer might have been changed in the level editor */
1193 ei->change = &ei->change_page[0];
1195 if (!IS_CUSTOM_ELEMENT(i))
1197 ei->change->target_element = EL_EMPTY_SPACE;
1198 ei->change->delay_fixed = 0;
1199 ei->change->delay_random = 0;
1200 ei->change->delay_frames = 1;
1203 ei->change_events = CE_BITMASK_DEFAULT;
1204 for (j = 0; j < NUM_CHANGE_EVENTS; j++)
1206 ei->event_page_nr[j] = 0;
1207 ei->event_page[j] = &ei->change_page[0];
1211 /* add changing elements from pre-defined list */
1212 for (i = 0; change_delay_list[i].element != EL_UNDEFINED; i++)
1214 struct ChangingElementInfo *ch_delay = &change_delay_list[i];
1215 struct ElementInfo *ei = &element_info[ch_delay->element];
1217 ei->change->target_element = ch_delay->target_element;
1218 ei->change->delay_fixed = ch_delay->change_delay;
1220 ei->change->pre_change_function = ch_delay->pre_change_function;
1221 ei->change->change_function = ch_delay->change_function;
1222 ei->change->post_change_function = ch_delay->post_change_function;
1224 ei->change_events |= CH_EVENT_BIT(CE_DELAY);
1227 SET_PROPERTY(ch_delay->element, EP_CAN_CHANGE, TRUE);
1232 /* add change events from custom element configuration */
1233 for (i = 0; i < NUM_CUSTOM_ELEMENTS; i++)
1235 struct ElementInfo *ei = &element_info[EL_CUSTOM_START + i];
1237 for (j = 0; j < ei->num_change_pages; j++)
1239 if (!ei->change_page[j].can_change)
1242 for (k = 0; k < NUM_CHANGE_EVENTS; k++)
1244 /* only add event page for the first page found with this event */
1245 if (ei->change_page[j].events & CH_EVENT_BIT(k) &&
1246 !(ei->change_events & CH_EVENT_BIT(k)))
1248 ei->change_events |= CH_EVENT_BIT(k);
1249 ei->event_page_nr[k] = j;
1250 ei->event_page[k] = &ei->change_page[j];
1258 /* add change events from custom element configuration */
1259 for (i = 0; i < NUM_CUSTOM_ELEMENTS; i++)
1261 int element = EL_CUSTOM_START + i;
1263 /* only add custom elements that change after fixed/random frame delay */
1264 if (CAN_CHANGE(element) && HAS_CHANGE_EVENT(element, CE_DELAY))
1265 element_info[element].change_events |= CH_EVENT_BIT(CE_DELAY);
1269 /* ---------- initialize run-time trigger player and element ------------- */
1271 for (i = 0; i < NUM_CUSTOM_ELEMENTS; i++)
1273 struct ElementInfo *ei = &element_info[EL_CUSTOM_START + i];
1275 for (j = 0; j < ei->num_change_pages; j++)
1277 ei->change_page[j].actual_trigger_element = EL_EMPTY;
1278 ei->change_page[j].actual_trigger_player = EL_PLAYER_1;
1282 /* ---------- initialize trigger events ---------------------------------- */
1284 /* initialize trigger events information */
1285 for (i = 0; i < MAX_NUM_ELEMENTS; i++)
1286 trigger_events[i] = EP_BITMASK_DEFAULT;
1289 /* add trigger events from element change event properties */
1290 for (i = 0; i < MAX_NUM_ELEMENTS; i++)
1292 struct ElementInfo *ei = &element_info[i];
1294 for (j = 0; j < ei->num_change_pages; j++)
1296 if (!ei->change_page[j].can_change)
1299 if (ei->change_page[j].events & CH_EVENT_BIT(CE_BY_OTHER_ACTION))
1301 int trigger_element = ei->change_page[j].trigger_element;
1303 if (IS_GROUP_ELEMENT(trigger_element))
1305 struct ElementGroupInfo *group = element_info[trigger_element].group;
1307 for (k = 0; k < group->num_elements_resolved; k++)
1308 trigger_events[group->element_resolved[k]]
1309 |= ei->change_page[j].events;
1312 trigger_events[trigger_element] |= ei->change_page[j].events;
1317 /* add trigger events from element change event properties */
1318 for (i = 0; i < MAX_NUM_ELEMENTS; i++)
1319 if (HAS_CHANGE_EVENT(i, CE_BY_OTHER_ACTION))
1320 trigger_events[element_info[i].change->trigger_element] |=
1321 element_info[i].change->events;
1324 /* ---------- initialize push delay -------------------------------------- */
1326 /* initialize push delay values to default */
1327 for (i = 0; i < MAX_NUM_ELEMENTS; i++)
1329 if (!IS_CUSTOM_ELEMENT(i))
1331 element_info[i].push_delay_fixed = game.default_push_delay_fixed;
1332 element_info[i].push_delay_random = game.default_push_delay_random;
1336 /* set push delay value for certain elements from pre-defined list */
1337 for (i = 0; push_delay_list[i].element != EL_UNDEFINED; i++)
1339 int e = push_delay_list[i].element;
1341 element_info[e].push_delay_fixed = push_delay_list[i].push_delay_fixed;
1342 element_info[e].push_delay_random = push_delay_list[i].push_delay_random;
1345 /* set push delay value for Supaplex elements for newer engine versions */
1346 if (game.engine_version >= VERSION_IDENT(3,1,0,0))
1348 for (i = 0; i < MAX_NUM_ELEMENTS; i++)
1350 if (IS_SP_ELEMENT(i))
1352 element_info[i].push_delay_fixed = 6; /* just enough to escape ... */
1353 element_info[i].push_delay_random = 0; /* ... from falling zonk */
1358 /* ---------- initialize move stepsize ----------------------------------- */
1360 /* initialize move stepsize values to default */
1361 for (i = 0; i < MAX_NUM_ELEMENTS; i++)
1362 if (!IS_CUSTOM_ELEMENT(i))
1363 element_info[i].move_stepsize = MOVE_STEPSIZE_NORMAL;
1365 /* set move stepsize value for certain elements from pre-defined list */
1366 for (i = 0; move_stepsize_list[i].element != EL_UNDEFINED; i++)
1368 int e = move_stepsize_list[i].element;
1370 element_info[e].move_stepsize = move_stepsize_list[i].move_stepsize;
1374 /* ---------- initialize move dig/leave ---------------------------------- */
1376 for (i = 0; i < MAX_NUM_ELEMENTS; i++)
1378 element_info[i].can_leave_element = FALSE;
1379 element_info[i].can_leave_element_last = FALSE;
1383 /* ---------- initialize gem count --------------------------------------- */
1385 /* initialize gem count values for each element */
1386 for (i = 0; i < MAX_NUM_ELEMENTS; i++)
1387 if (!IS_CUSTOM_ELEMENT(i))
1388 element_info[i].collect_count = 0;
1390 /* add gem count values for all elements from pre-defined list */
1391 for (i = 0; collect_count_list[i].element != EL_UNDEFINED; i++)
1392 element_info[collect_count_list[i].element].collect_count =
1393 collect_count_list[i].count;
1395 /* ---------- initialize access direction -------------------------------- */
1397 /* initialize access direction values to default (access from every side) */
1398 for (i = 0; i < MAX_NUM_ELEMENTS; i++)
1399 if (!IS_CUSTOM_ELEMENT(i))
1400 element_info[i].access_direction = MV_ALL_DIRECTIONS;
1402 /* set access direction value for certain elements from pre-defined list */
1403 for (i = 0; access_direction_list[i].element != EL_UNDEFINED; i++)
1404 element_info[access_direction_list[i].element].access_direction =
1405 access_direction_list[i].direction;
1410 =============================================================================
1412 -----------------------------------------------------------------------------
1413 initialize and start new game
1414 =============================================================================
1419 boolean emulate_bd = TRUE; /* unless non-BOULDERDASH elements found */
1420 boolean emulate_sb = TRUE; /* unless non-SOKOBAN elements found */
1421 boolean emulate_sp = TRUE; /* unless non-SUPAPLEX elements found */
1428 #if USE_NEW_AMOEBA_CODE
1429 printf("Using new amoeba code.\n");
1431 printf("Using old amoeba code.\n");
1436 /* don't play tapes over network */
1437 network_playing = (options.network && !tape.playing);
1439 for (i = 0; i < MAX_PLAYERS; i++)
1441 struct PlayerInfo *player = &stored_player[i];
1443 player->index_nr = i;
1444 player->index_bit = (1 << i);
1445 player->element_nr = EL_PLAYER_1 + i;
1447 player->present = FALSE;
1448 player->active = FALSE;
1451 player->effective_action = 0;
1452 player->programmed_action = 0;
1455 player->gems_still_needed = level.gems_needed;
1456 player->sokobanfields_still_needed = 0;
1457 player->lights_still_needed = 0;
1458 player->friends_still_needed = 0;
1460 for (j = 0; j < MAX_KEYS; j++)
1461 player->key[j] = FALSE;
1463 player->dynabomb_count = 0;
1464 player->dynabomb_size = 1;
1465 player->dynabombs_left = 0;
1466 player->dynabomb_xl = FALSE;
1468 player->MovDir = MV_NO_MOVING;
1471 player->GfxDir = MV_NO_MOVING;
1472 player->GfxAction = ACTION_DEFAULT;
1474 player->StepFrame = 0;
1476 player->use_murphy_graphic = FALSE;
1478 player->block_last_field = FALSE;
1479 player->can_fall_into_acid = CAN_MOVE_INTO_ACID(player->element_nr);
1481 player->actual_frame_counter = 0;
1483 player->step_counter = 0;
1485 player->last_move_dir = MV_NO_MOVING;
1487 player->is_waiting = FALSE;
1488 player->is_moving = FALSE;
1489 player->is_auto_moving = FALSE;
1490 player->is_digging = FALSE;
1491 player->is_snapping = FALSE;
1492 player->is_collecting = FALSE;
1493 player->is_pushing = FALSE;
1494 player->is_switching = FALSE;
1495 player->is_dropping = FALSE;
1497 player->is_bored = FALSE;
1498 player->is_sleeping = FALSE;
1500 player->frame_counter_bored = -1;
1501 player->frame_counter_sleeping = -1;
1503 player->anim_delay_counter = 0;
1504 player->post_delay_counter = 0;
1506 player->action_waiting = ACTION_DEFAULT;
1507 player->last_action_waiting = ACTION_DEFAULT;
1508 player->special_action_bored = ACTION_DEFAULT;
1509 player->special_action_sleeping = ACTION_DEFAULT;
1511 player->num_special_action_bored = 0;
1512 player->num_special_action_sleeping = 0;
1514 /* determine number of special actions for bored and sleeping animation */
1515 for (j = ACTION_BORING_1; j <= ACTION_BORING_LAST; j++)
1517 boolean found = FALSE;
1519 for (k = 0; k < NUM_DIRECTIONS; k++)
1520 if (el_act_dir2img(player->element_nr, j, k) !=
1521 el_act_dir2img(player->element_nr, ACTION_DEFAULT, k))
1525 player->num_special_action_bored++;
1529 for (j = ACTION_SLEEPING_1; j <= ACTION_SLEEPING_LAST; j++)
1531 boolean found = FALSE;
1533 for (k = 0; k < NUM_DIRECTIONS; k++)
1534 if (el_act_dir2img(player->element_nr, j, k) !=
1535 el_act_dir2img(player->element_nr, ACTION_DEFAULT, k))
1539 player->num_special_action_sleeping++;
1544 player->switch_x = -1;
1545 player->switch_y = -1;
1547 player->show_envelope = 0;
1549 player->move_delay = game.initial_move_delay;
1550 player->move_delay_value = game.initial_move_delay_value;
1552 player->move_delay_reset_counter = 0;
1554 player->push_delay = 0;
1555 player->push_delay_value = game.initial_push_delay_value;
1557 player->drop_delay = 0;
1559 player->last_jx = player->last_jy = 0;
1560 player->jx = player->jy = 0;
1562 player->shield_normal_time_left = 0;
1563 player->shield_deadly_time_left = 0;
1565 player->inventory_infinite_element = EL_UNDEFINED;
1566 player->inventory_size = 0;
1568 DigField(player, 0, 0, 0, 0, 0, 0, DF_NO_PUSH);
1569 SnapField(player, 0, 0);
1571 player->LevelSolved = FALSE;
1572 player->GameOver = FALSE;
1575 network_player_action_received = FALSE;
1577 #if defined(PLATFORM_UNIX)
1578 /* initial null action */
1579 if (network_playing)
1580 SendToServer_MovePlayer(MV_NO_MOVING);
1588 TimeLeft = level.time;
1591 ScreenMovDir = MV_NO_MOVING;
1595 ScrollStepSize = 0; /* will be correctly initialized by ScrollScreen() */
1597 AllPlayersGone = FALSE;
1599 game.yamyam_content_nr = 0;
1600 game.magic_wall_active = FALSE;
1601 game.magic_wall_time_left = 0;
1602 game.light_time_left = 0;
1603 game.timegate_time_left = 0;
1604 game.switchgate_pos = 0;
1605 game.balloon_dir = MV_NO_MOVING;
1606 game.gravity = level.initial_gravity;
1607 game.explosions_delayed = TRUE;
1609 game.envelope_active = FALSE;
1611 for (i = 0; i < NUM_BELTS; i++)
1613 game.belt_dir[i] = MV_NO_MOVING;
1614 game.belt_dir_nr[i] = 3; /* not moving, next moving left */
1617 for (i = 0; i < MAX_NUM_AMOEBA; i++)
1618 AmoebaCnt[i] = AmoebaCnt2[i] = 0;
1620 for (x = 0; x < lev_fieldx; x++)
1622 for (y = 0; y < lev_fieldy; y++)
1624 Feld[x][y] = level.field[x][y];
1625 MovPos[x][y] = MovDir[x][y] = MovDelay[x][y] = 0;
1626 ChangeDelay[x][y] = 0;
1627 ChangePage[x][y] = -1;
1628 Store[x][y] = Store2[x][y] = StorePlayer[x][y] = Back[x][y] = 0;
1630 WasJustMoving[x][y] = 0;
1631 WasJustFalling[x][y] = 0;
1633 Pushed[x][y] = FALSE;
1635 Changed[x][y] = CE_BITMASK_DEFAULT;
1636 ChangeEvent[x][y] = CE_BITMASK_DEFAULT;
1638 ExplodePhase[x][y] = 0;
1639 ExplodeDelay[x][y] = 0;
1640 ExplodeField[x][y] = EX_TYPE_NONE;
1642 RunnerVisit[x][y] = 0;
1643 PlayerVisit[x][y] = 0;
1646 GfxRandom[x][y] = INIT_GFX_RANDOM();
1647 GfxElement[x][y] = EL_UNDEFINED;
1648 GfxAction[x][y] = ACTION_DEFAULT;
1649 GfxDir[x][y] = MV_NO_MOVING;
1653 for (y = 0; y < lev_fieldy; y++)
1655 for (x = 0; x < lev_fieldx; x++)
1657 if (emulate_bd && !IS_BD_ELEMENT(Feld[x][y]))
1659 if (emulate_sb && !IS_SB_ELEMENT(Feld[x][y]))
1661 if (emulate_sp && !IS_SP_ELEMENT(Feld[x][y]))
1664 InitField(x, y, TRUE);
1670 game.emulation = (emulate_bd ? EMU_BOULDERDASH :
1671 emulate_sb ? EMU_SOKOBAN :
1672 emulate_sp ? EMU_SUPAPLEX : EMU_NONE);
1674 /* initialize explosion and ignition delay */
1675 for (i = 0; i < MAX_NUM_ELEMENTS; i++)
1677 if (!IS_CUSTOM_ELEMENT(i))
1680 int delay = (((IS_SP_ELEMENT(i) && i != EL_EMPTY_SPACE) &&
1681 game.engine_version >= VERSION_IDENT(3,1,0,0)) ||
1682 game.emulation == EMU_SUPAPLEX ? 3 : 2);
1683 int last_phase = (num_phase + 1) * delay;
1684 int half_phase = (num_phase / 2) * delay;
1686 element_info[i].explosion_delay = last_phase - 1;
1687 element_info[i].ignition_delay = half_phase;
1690 if (i == EL_BLACK_ORB)
1691 element_info[i].ignition_delay = 0;
1693 if (i == EL_BLACK_ORB)
1694 element_info[i].ignition_delay = 1;
1699 if (element_info[i].explosion_delay < 1) /* !!! check again !!! */
1700 element_info[i].explosion_delay = 1;
1702 if (element_info[i].ignition_delay < 1) /* !!! check again !!! */
1703 element_info[i].ignition_delay = 1;
1707 /* correct non-moving belts to start moving left */
1708 for (i = 0; i < NUM_BELTS; i++)
1709 if (game.belt_dir[i] == MV_NO_MOVING)
1710 game.belt_dir_nr[i] = 3; /* not moving, next moving left */
1712 /* check if any connected player was not found in playfield */
1713 for (i = 0; i < MAX_PLAYERS; i++)
1715 struct PlayerInfo *player = &stored_player[i];
1717 if (player->connected && !player->present)
1719 for (j = 0; j < MAX_PLAYERS; j++)
1721 struct PlayerInfo *some_player = &stored_player[j];
1722 int jx = some_player->jx, jy = some_player->jy;
1724 /* assign first free player found that is present in the playfield */
1725 if (some_player->present && !some_player->connected)
1727 player->present = TRUE;
1728 player->active = TRUE;
1730 some_player->present = FALSE;
1731 some_player->active = FALSE;
1734 player->element_nr = some_player->element_nr;
1737 StorePlayer[jx][jy] = player->element_nr;
1738 player->jx = player->last_jx = jx;
1739 player->jy = player->last_jy = jy;
1749 /* when playing a tape, eliminate all players which do not participate */
1751 for (i = 0; i < MAX_PLAYERS; i++)
1753 if (stored_player[i].active && !tape.player_participates[i])
1755 struct PlayerInfo *player = &stored_player[i];
1756 int jx = player->jx, jy = player->jy;
1758 player->active = FALSE;
1759 StorePlayer[jx][jy] = 0;
1760 Feld[jx][jy] = EL_EMPTY;
1764 else if (!options.network && !setup.team_mode) /* && !tape.playing */
1766 /* when in single player mode, eliminate all but the first active player */
1768 for (i = 0; i < MAX_PLAYERS; i++)
1770 if (stored_player[i].active)
1772 for (j = i + 1; j < MAX_PLAYERS; j++)
1774 if (stored_player[j].active)
1776 struct PlayerInfo *player = &stored_player[j];
1777 int jx = player->jx, jy = player->jy;
1779 player->active = FALSE;
1780 player->present = FALSE;
1782 StorePlayer[jx][jy] = 0;
1783 Feld[jx][jy] = EL_EMPTY;
1790 /* when recording the game, store which players take part in the game */
1793 for (i = 0; i < MAX_PLAYERS; i++)
1794 if (stored_player[i].active)
1795 tape.player_participates[i] = TRUE;
1800 for (i = 0; i < MAX_PLAYERS; i++)
1802 struct PlayerInfo *player = &stored_player[i];
1804 printf("Player %d: present == %d, connected == %d, active == %d.\n",
1809 if (local_player == player)
1810 printf("Player %d is local player.\n", i+1);
1814 if (BorderElement == EL_EMPTY)
1817 SBX_Right = lev_fieldx - SCR_FIELDX;
1819 SBY_Lower = lev_fieldy - SCR_FIELDY;
1824 SBX_Right = lev_fieldx - SCR_FIELDX + 1;
1826 SBY_Lower = lev_fieldy - SCR_FIELDY + 1;
1829 if (lev_fieldx + (SBX_Left == -1 ? 2 : 0) <= SCR_FIELDX)
1830 SBX_Left = SBX_Right = -1 * (SCR_FIELDX - lev_fieldx) / 2;
1832 if (lev_fieldy + (SBY_Upper == -1 ? 2 : 0) <= SCR_FIELDY)
1833 SBY_Upper = SBY_Lower = -1 * (SCR_FIELDY - lev_fieldy) / 2;
1835 /* if local player not found, look for custom element that might create
1836 the player (make some assumptions about the right custom element) */
1837 if (!local_player->present)
1839 int start_x = 0, start_y = 0;
1840 int found_rating = 0;
1841 int found_element = EL_UNDEFINED;
1843 for (y = 0; y < lev_fieldy; y++) for (x = 0; x < lev_fieldx; x++)
1845 int element = Feld[x][y];
1850 if (!IS_CUSTOM_ELEMENT(element))
1853 if (CAN_CHANGE(element))
1855 for (i = 0; i < element_info[element].num_change_pages; i++)
1857 content = element_info[element].change_page[i].target_element;
1858 is_player = ELEM_IS_PLAYER(content);
1860 if (is_player && (found_rating < 3 || element < found_element))
1866 found_element = element;
1871 for (yy = 0; yy < 3; yy++) for (xx = 0; xx < 3; xx++)
1873 content = element_info[element].content[xx][yy];
1874 is_player = ELEM_IS_PLAYER(content);
1876 if (is_player && (found_rating < 2 || element < found_element))
1878 start_x = x + xx - 1;
1879 start_y = y + yy - 1;
1882 found_element = element;
1885 if (!CAN_CHANGE(element))
1888 for (i = 0; i < element_info[element].num_change_pages; i++)
1890 content= element_info[element].change_page[i].target_content[xx][yy];
1891 is_player = ELEM_IS_PLAYER(content);
1893 if (is_player && (found_rating < 1 || element < found_element))
1895 start_x = x + xx - 1;
1896 start_y = y + yy - 1;
1899 found_element = element;
1905 scroll_x = (start_x < SBX_Left + MIDPOSX ? SBX_Left :
1906 start_x > SBX_Right + MIDPOSX ? SBX_Right :
1909 scroll_y = (start_y < SBY_Upper + MIDPOSY ? SBY_Upper :
1910 start_y > SBY_Lower + MIDPOSY ? SBY_Lower :
1916 scroll_x = (local_player->jx < SBX_Left + MIDPOSX ? SBX_Left :
1917 local_player->jx > SBX_Right + MIDPOSX ? SBX_Right :
1918 local_player->jx - MIDPOSX);
1920 scroll_y = (local_player->jy < SBY_Upper + MIDPOSY ? SBY_Upper :
1921 local_player->jy > SBY_Lower + MIDPOSY ? SBY_Lower :
1922 local_player->jy - MIDPOSY);
1924 scroll_x = SBX_Left;
1925 scroll_y = SBY_Upper;
1926 if (local_player->jx >= SBX_Left + MIDPOSX)
1927 scroll_x = (local_player->jx <= SBX_Right + MIDPOSX ?
1928 local_player->jx - MIDPOSX :
1930 if (local_player->jy >= SBY_Upper + MIDPOSY)
1931 scroll_y = (local_player->jy <= SBY_Lower + MIDPOSY ?
1932 local_player->jy - MIDPOSY :
1937 CloseDoor(DOOR_CLOSE_1);
1942 /* after drawing the level, correct some elements */
1943 if (game.timegate_time_left == 0)
1944 CloseAllOpenTimegates();
1946 if (setup.soft_scrolling)
1947 BlitBitmap(fieldbuffer, backbuffer, FX, FY, SXSIZE, SYSIZE, SX, SY);
1949 redraw_mask |= REDRAW_FROM_BACKBUFFER;
1952 /* copy default game door content to main double buffer */
1953 BlitBitmap(graphic_info[IMG_GLOBAL_DOOR].bitmap, drawto,
1954 DOOR_GFX_PAGEX5, DOOR_GFX_PAGEY1, DXSIZE, DYSIZE, DX, DY);
1956 DrawGameDoorValues();
1960 game_gadget[SOUND_CTRL_ID_MUSIC]->checked = setup.sound_music;
1961 game_gadget[SOUND_CTRL_ID_LOOPS]->checked = setup.sound_loops;
1962 game_gadget[SOUND_CTRL_ID_SIMPLE]->checked = setup.sound_simple;
1966 /* copy actual game door content to door double buffer for OpenDoor() */
1967 BlitBitmap(drawto, bitmap_db_door,
1968 DX, DY, DXSIZE, DYSIZE, DOOR_GFX_PAGEX1, DOOR_GFX_PAGEY1);
1970 OpenDoor(DOOR_OPEN_ALL);
1972 PlaySoundStereo(SND_GAME_STARTING, SOUND_MIDDLE);
1974 if (setup.sound_music)
1977 KeyboardAutoRepeatOffUnlessAutoplay();
1981 for (i = 0; i < MAX_PLAYERS; i++)
1982 printf("Player %d %sactive.\n",
1983 i + 1, (stored_player[i].active ? "" : "not "));
1987 printf("::: starting game [%d]\n", FrameCounter);
1991 void InitMovDir(int x, int y)
1993 int i, element = Feld[x][y];
1994 static int xy[4][2] =
2001 static int direction[3][4] =
2003 { MV_RIGHT, MV_UP, MV_LEFT, MV_DOWN },
2004 { MV_LEFT, MV_DOWN, MV_RIGHT, MV_UP },
2005 { MV_LEFT, MV_RIGHT, MV_UP, MV_DOWN }
2014 Feld[x][y] = EL_BUG;
2015 MovDir[x][y] = direction[0][element - EL_BUG_RIGHT];
2018 case EL_SPACESHIP_RIGHT:
2019 case EL_SPACESHIP_UP:
2020 case EL_SPACESHIP_LEFT:
2021 case EL_SPACESHIP_DOWN:
2022 Feld[x][y] = EL_SPACESHIP;
2023 MovDir[x][y] = direction[0][element - EL_SPACESHIP_RIGHT];
2026 case EL_BD_BUTTERFLY_RIGHT:
2027 case EL_BD_BUTTERFLY_UP:
2028 case EL_BD_BUTTERFLY_LEFT:
2029 case EL_BD_BUTTERFLY_DOWN:
2030 Feld[x][y] = EL_BD_BUTTERFLY;
2031 MovDir[x][y] = direction[0][element - EL_BD_BUTTERFLY_RIGHT];
2034 case EL_BD_FIREFLY_RIGHT:
2035 case EL_BD_FIREFLY_UP:
2036 case EL_BD_FIREFLY_LEFT:
2037 case EL_BD_FIREFLY_DOWN:
2038 Feld[x][y] = EL_BD_FIREFLY;
2039 MovDir[x][y] = direction[0][element - EL_BD_FIREFLY_RIGHT];
2042 case EL_PACMAN_RIGHT:
2044 case EL_PACMAN_LEFT:
2045 case EL_PACMAN_DOWN:
2046 Feld[x][y] = EL_PACMAN;
2047 MovDir[x][y] = direction[0][element - EL_PACMAN_RIGHT];
2050 case EL_SP_SNIKSNAK:
2051 MovDir[x][y] = MV_UP;
2054 case EL_SP_ELECTRON:
2055 MovDir[x][y] = MV_LEFT;
2062 Feld[x][y] = EL_MOLE;
2063 MovDir[x][y] = direction[2][element - EL_MOLE_LEFT];
2067 if (IS_CUSTOM_ELEMENT(element))
2069 struct ElementInfo *ei = &element_info[element];
2070 int move_direction_initial = ei->move_direction_initial;
2071 int move_pattern = ei->move_pattern;
2073 if (move_direction_initial == MV_START_PREVIOUS)
2075 if (MovDir[x][y] != MV_NO_MOVING)
2078 move_direction_initial = MV_START_AUTOMATIC;
2081 if (move_direction_initial == MV_START_RANDOM)
2082 MovDir[x][y] = 1 << RND(4);
2083 else if (move_direction_initial & MV_ANY_DIRECTION)
2084 MovDir[x][y] = move_direction_initial;
2085 else if (move_pattern == MV_ALL_DIRECTIONS ||
2086 move_pattern == MV_TURNING_LEFT ||
2087 move_pattern == MV_TURNING_RIGHT ||
2088 move_pattern == MV_TURNING_LEFT_RIGHT ||
2089 move_pattern == MV_TURNING_RIGHT_LEFT ||
2090 move_pattern == MV_TURNING_RANDOM)
2091 MovDir[x][y] = 1 << RND(4);
2092 else if (move_pattern == MV_HORIZONTAL)
2093 MovDir[x][y] = (RND(2) ? MV_LEFT : MV_RIGHT);
2094 else if (move_pattern == MV_VERTICAL)
2095 MovDir[x][y] = (RND(2) ? MV_UP : MV_DOWN);
2096 else if (move_pattern & MV_ANY_DIRECTION)
2097 MovDir[x][y] = element_info[element].move_pattern;
2098 else if (move_pattern == MV_ALONG_LEFT_SIDE ||
2099 move_pattern == MV_ALONG_RIGHT_SIDE)
2102 /* use random direction as default start direction */
2103 if (game.engine_version >= VERSION_IDENT(3,1,0,2))
2104 MovDir[x][y] = 1 << RND(4);
2107 for (i = 0; i < NUM_DIRECTIONS; i++)
2109 int x1 = x + xy[i][0];
2110 int y1 = y + xy[i][1];
2112 if (!IN_LEV_FIELD(x1, y1) || !IS_FREE(x1, y1))
2114 if (move_pattern == MV_ALONG_RIGHT_SIDE)
2115 MovDir[x][y] = direction[0][i];
2117 MovDir[x][y] = direction[1][i];
2126 MovDir[x][y] = 1 << RND(4);
2128 if (element != EL_BUG &&
2129 element != EL_SPACESHIP &&
2130 element != EL_BD_BUTTERFLY &&
2131 element != EL_BD_FIREFLY)
2134 for (i = 0; i < NUM_DIRECTIONS; i++)
2136 int x1 = x + xy[i][0];
2137 int y1 = y + xy[i][1];
2139 if (!IN_LEV_FIELD(x1, y1) || !IS_FREE(x1, y1))
2141 if (element == EL_BUG || element == EL_BD_BUTTERFLY)
2143 MovDir[x][y] = direction[0][i];
2146 else if (element == EL_SPACESHIP || element == EL_BD_FIREFLY ||
2147 element == EL_SP_SNIKSNAK || element == EL_SP_ELECTRON)
2149 MovDir[x][y] = direction[1][i];
2158 GfxDir[x][y] = MovDir[x][y];
2161 void InitAmoebaNr(int x, int y)
2164 int group_nr = AmoebeNachbarNr(x, y);
2168 for (i = 1; i < MAX_NUM_AMOEBA; i++)
2170 if (AmoebaCnt[i] == 0)
2178 AmoebaNr[x][y] = group_nr;
2179 AmoebaCnt[group_nr]++;
2180 AmoebaCnt2[group_nr]++;
2186 boolean raise_level = FALSE;
2188 if (local_player->MovPos)
2192 if (tape.auto_play) /* tape might already be stopped here */
2193 tape.auto_play_level_solved = TRUE;
2195 if (tape.playing && tape.auto_play)
2196 tape.auto_play_level_solved = TRUE;
2199 local_player->LevelSolved = FALSE;
2201 PlaySoundStereo(SND_GAME_WINNING, SOUND_MIDDLE);
2205 if (!tape.playing && setup.sound_loops)
2206 PlaySoundExt(SND_GAME_LEVELTIME_BONUS, SOUND_MAX_VOLUME, SOUND_MIDDLE,
2207 SND_CTRL_PLAY_LOOP);
2209 while (TimeLeft > 0)
2211 if (!tape.playing && !setup.sound_loops)
2212 PlaySoundStereo(SND_GAME_LEVELTIME_BONUS, SOUND_MIDDLE);
2213 if (TimeLeft > 0 && !(TimeLeft % 10))
2214 RaiseScore(level.score[SC_TIME_BONUS]);
2215 if (TimeLeft > 100 && !(TimeLeft % 10))
2220 DrawGameValue_Time(TimeLeft);
2228 if (!tape.playing && setup.sound_loops)
2229 StopSound(SND_GAME_LEVELTIME_BONUS);
2231 else if (level.time == 0) /* level without time limit */
2233 if (!tape.playing && setup.sound_loops)
2234 PlaySoundExt(SND_GAME_LEVELTIME_BONUS, SOUND_MAX_VOLUME, SOUND_MIDDLE,
2235 SND_CTRL_PLAY_LOOP);
2237 while (TimePlayed < 999)
2239 if (!tape.playing && !setup.sound_loops)
2240 PlaySoundStereo(SND_GAME_LEVELTIME_BONUS, SOUND_MIDDLE);
2241 if (TimePlayed < 999 && !(TimePlayed % 10))
2242 RaiseScore(level.score[SC_TIME_BONUS]);
2243 if (TimePlayed < 900 && !(TimePlayed % 10))
2248 DrawGameValue_Time(TimePlayed);
2256 if (!tape.playing && setup.sound_loops)
2257 StopSound(SND_GAME_LEVELTIME_BONUS);
2260 /* close exit door after last player */
2261 if ((Feld[ExitX][ExitY] == EL_EXIT_OPEN ||
2262 Feld[ExitX][ExitY] == EL_SP_EXIT_OPEN) && AllPlayersGone)
2264 int element = Feld[ExitX][ExitY];
2266 Feld[ExitX][ExitY] = (element == EL_EXIT_OPEN ? EL_EXIT_CLOSING :
2267 EL_SP_EXIT_CLOSING);
2269 PlayLevelSoundElementAction(ExitX, ExitY, element, ACTION_CLOSING);
2272 /* Hero disappears */
2273 DrawLevelField(ExitX, ExitY);
2279 CloseDoor(DOOR_CLOSE_1);
2284 SaveTape(tape.level_nr); /* Ask to save tape */
2287 if (level_nr == leveldir_current->handicap_level)
2289 leveldir_current->handicap_level++;
2290 SaveLevelSetup_SeriesInfo();
2293 if (level_editor_test_game)
2294 local_player->score = -1; /* no highscore when playing from editor */
2295 else if (level_nr < leveldir_current->last_level)
2296 raise_level = TRUE; /* advance to next level */
2298 if ((hi_pos = NewHiScore()) >= 0)
2300 game_status = GAME_MODE_SCORES;
2301 DrawHallOfFame(hi_pos);
2310 game_status = GAME_MODE_MAIN;
2327 LoadScore(level_nr);
2329 if (strcmp(setup.player_name, EMPTY_PLAYER_NAME) == 0 ||
2330 local_player->score < highscore[MAX_SCORE_ENTRIES - 1].Score)
2333 for (k = 0; k < MAX_SCORE_ENTRIES; k++)
2335 if (local_player->score > highscore[k].Score)
2337 /* player has made it to the hall of fame */
2339 if (k < MAX_SCORE_ENTRIES - 1)
2341 int m = MAX_SCORE_ENTRIES - 1;
2344 for (l = k; l < MAX_SCORE_ENTRIES; l++)
2345 if (!strcmp(setup.player_name, highscore[l].Name))
2347 if (m == k) /* player's new highscore overwrites his old one */
2351 for (l = m; l > k; l--)
2353 strcpy(highscore[l].Name, highscore[l - 1].Name);
2354 highscore[l].Score = highscore[l - 1].Score;
2361 strncpy(highscore[k].Name, setup.player_name, MAX_PLAYER_NAME_LEN);
2362 highscore[k].Name[MAX_PLAYER_NAME_LEN] = '\0';
2363 highscore[k].Score = local_player->score;
2369 else if (!strncmp(setup.player_name, highscore[k].Name,
2370 MAX_PLAYER_NAME_LEN))
2371 break; /* player already there with a higher score */
2377 SaveScore(level_nr);
2382 void InitPlayerGfxAnimation(struct PlayerInfo *player, int action, int dir)
2384 if (player->GfxAction != action || player->GfxDir != dir)
2387 printf("Player frame reset! (%d => %d, %d => %d)\n",
2388 player->GfxAction, action, player->GfxDir, dir);
2391 player->GfxAction = action;
2392 player->GfxDir = dir;
2394 player->StepFrame = 0;
2398 static void ResetRandomAnimationValue(int x, int y)
2400 GfxRandom[x][y] = INIT_GFX_RANDOM();
2403 static void ResetGfxAnimation(int x, int y)
2406 GfxAction[x][y] = ACTION_DEFAULT;
2407 GfxDir[x][y] = MovDir[x][y];
2410 void InitMovingField(int x, int y, int direction)
2412 int element = Feld[x][y];
2413 int dx = (direction == MV_LEFT ? -1 : direction == MV_RIGHT ? +1 : 0);
2414 int dy = (direction == MV_UP ? -1 : direction == MV_DOWN ? +1 : 0);
2418 if (!WasJustMoving[x][y] || direction != MovDir[x][y])
2419 ResetGfxAnimation(x, y);
2421 MovDir[newx][newy] = MovDir[x][y] = direction;
2422 GfxDir[x][y] = direction;
2424 if (Feld[newx][newy] == EL_EMPTY)
2425 Feld[newx][newy] = EL_BLOCKED;
2427 if (direction == MV_DOWN && CAN_FALL(element))
2428 GfxAction[x][y] = ACTION_FALLING;
2430 GfxAction[x][y] = ACTION_MOVING;
2432 GfxFrame[newx][newy] = GfxFrame[x][y];
2433 GfxRandom[newx][newy] = GfxRandom[x][y];
2434 GfxAction[newx][newy] = GfxAction[x][y];
2435 GfxDir[newx][newy] = GfxDir[x][y];
2438 void Moving2Blocked(int x, int y, int *goes_to_x, int *goes_to_y)
2440 int direction = MovDir[x][y];
2441 int newx = x + (direction == MV_LEFT ? -1 : direction == MV_RIGHT ? +1 : 0);
2442 int newy = y + (direction == MV_UP ? -1 : direction == MV_DOWN ? +1 : 0);
2448 void Blocked2Moving(int x, int y, int *comes_from_x, int *comes_from_y)
2450 int oldx = x, oldy = y;
2451 int direction = MovDir[x][y];
2453 if (direction == MV_LEFT)
2455 else if (direction == MV_RIGHT)
2457 else if (direction == MV_UP)
2459 else if (direction == MV_DOWN)
2462 *comes_from_x = oldx;
2463 *comes_from_y = oldy;
2466 int MovingOrBlocked2Element(int x, int y)
2468 int element = Feld[x][y];
2470 if (element == EL_BLOCKED)
2474 Blocked2Moving(x, y, &oldx, &oldy);
2475 return Feld[oldx][oldy];
2481 static int MovingOrBlocked2ElementIfNotLeaving(int x, int y)
2483 /* like MovingOrBlocked2Element(), but if element is moving
2484 and (x,y) is the field the moving element is just leaving,
2485 return EL_BLOCKED instead of the element value */
2486 int element = Feld[x][y];
2488 if (IS_MOVING(x, y))
2490 if (element == EL_BLOCKED)
2494 Blocked2Moving(x, y, &oldx, &oldy);
2495 return Feld[oldx][oldy];
2504 static void RemoveField(int x, int y)
2506 Feld[x][y] = EL_EMPTY;
2513 ChangeDelay[x][y] = 0;
2514 ChangePage[x][y] = -1;
2515 Pushed[x][y] = FALSE;
2517 GfxElement[x][y] = EL_UNDEFINED;
2518 GfxAction[x][y] = ACTION_DEFAULT;
2519 GfxDir[x][y] = MV_NO_MOVING;
2522 void RemoveMovingField(int x, int y)
2524 int oldx = x, oldy = y, newx = x, newy = y;
2525 int element = Feld[x][y];
2526 int next_element = EL_UNDEFINED;
2528 if (element != EL_BLOCKED && !IS_MOVING(x, y))
2531 if (IS_MOVING(x, y))
2533 Moving2Blocked(x, y, &newx, &newy);
2535 if (Feld[newx][newy] != EL_BLOCKED)
2538 if (Feld[newx][newy] != EL_BLOCKED)
2540 /* element is moving, but target field is not free (blocked), but
2541 already occupied by something different (example: acid pool);
2542 in this case, only remove the moving field, but not the target */
2544 RemoveField(oldx, oldy);
2546 Store[oldx][oldy] = Store2[oldx][oldy] = 0;
2548 DrawLevelField(oldx, oldy);
2554 else if (element == EL_BLOCKED)
2556 Blocked2Moving(x, y, &oldx, &oldy);
2557 if (!IS_MOVING(oldx, oldy))
2561 if (element == EL_BLOCKED &&
2562 (Feld[oldx][oldy] == EL_QUICKSAND_EMPTYING ||
2563 Feld[oldx][oldy] == EL_MAGIC_WALL_EMPTYING ||
2564 Feld[oldx][oldy] == EL_BD_MAGIC_WALL_EMPTYING ||
2565 Feld[oldx][oldy] == EL_AMOEBA_DROPPING))
2566 next_element = get_next_element(Feld[oldx][oldy]);
2568 RemoveField(oldx, oldy);
2569 RemoveField(newx, newy);
2571 Store[oldx][oldy] = Store2[oldx][oldy] = 0;
2573 if (next_element != EL_UNDEFINED)
2574 Feld[oldx][oldy] = next_element;
2576 DrawLevelField(oldx, oldy);
2577 DrawLevelField(newx, newy);
2580 void DrawDynamite(int x, int y)
2582 int sx = SCREENX(x), sy = SCREENY(y);
2583 int graphic = el2img(Feld[x][y]);
2586 if (!IN_SCR_FIELD(sx, sy) || IS_PLAYER(x, y))
2589 if (IS_WALKABLE_INSIDE(Back[x][y]))
2593 DrawGraphic(sx, sy, el2img(Back[x][y]), 0);
2594 else if (Store[x][y])
2595 DrawGraphic(sx, sy, el2img(Store[x][y]), 0);
2597 frame = getGraphicAnimationFrame(graphic, GfxFrame[x][y]);
2600 if (Back[x][y] || Store[x][y])
2601 DrawGraphicThruMask(sx, sy, graphic, frame);
2603 DrawGraphic(sx, sy, graphic, frame);
2605 if (game.emulation == EMU_SUPAPLEX)
2606 DrawGraphic(sx, sy, IMG_SP_DISK_RED, frame);
2607 else if (Store[x][y])
2608 DrawGraphicThruMask(sx, sy, graphic, frame);
2610 DrawGraphic(sx, sy, graphic, frame);
2614 void CheckDynamite(int x, int y)
2616 if (MovDelay[x][y] != 0) /* dynamite is still waiting to explode */
2620 if (MovDelay[x][y] != 0)
2623 PlayLevelSoundActionIfLoop(x, y, ACTION_ACTIVE);
2630 StopLevelSoundActionIfLoop(x, y, ACTION_ACTIVE);
2632 if (Feld[x][y] == EL_DYNAMITE_ACTIVE ||
2633 Feld[x][y] == EL_SP_DISK_RED_ACTIVE)
2634 StopSound(SND_DYNAMITE_ACTIVE);
2636 StopSound(SND_DYNABOMB_ACTIVE);
2642 void RelocatePlayer(int x, int y, int element_raw)
2644 int element = (element_raw == EL_SP_MURPHY ? EL_PLAYER_1 : element_raw);
2645 struct PlayerInfo *player = &stored_player[element - EL_PLAYER_1];
2646 boolean ffwd_delay = (tape.playing && tape.fast_forward);
2647 boolean no_delay = (tape.warp_forward);
2648 int frame_delay_value = (ffwd_delay ? FfwdFrameDelay : GameFrameDelay);
2649 int wait_delay_value = (no_delay ? 0 : frame_delay_value);
2652 if (player->GameOver) /* do not reanimate dead player */
2655 RemoveField(x, y); /* temporarily remove newly placed player */
2656 DrawLevelField(x, y);
2658 if (player->present)
2660 while (player->MovPos)
2662 ScrollPlayer(player, SCROLL_GO_ON);
2663 ScrollScreen(NULL, SCROLL_GO_ON);
2669 Delay(wait_delay_value);
2672 DrawPlayer(player); /* needed here only to cleanup last field */
2673 DrawLevelField(player->jx, player->jy); /* remove player graphic */
2675 player->is_moving = FALSE;
2678 old_jx = player->jx;
2679 old_jy = player->jy;
2681 Feld[x][y] = element;
2682 InitPlayerField(x, y, element, TRUE);
2684 if (player != local_player) /* do not visually relocate other players */
2687 if (level.instant_relocation)
2690 int offset = (setup.scroll_delay ? 3 : 0);
2691 int jx = local_player->jx;
2692 int jy = local_player->jy;
2694 if (!IN_VIS_FIELD(SCREENX(jx), SCREENY(jy)))
2696 scroll_x = (local_player->jx < SBX_Left + MIDPOSX ? SBX_Left :
2697 local_player->jx > SBX_Right + MIDPOSX ? SBX_Right :
2698 local_player->jx - MIDPOSX);
2700 scroll_y = (local_player->jy < SBY_Upper + MIDPOSY ? SBY_Upper :
2701 local_player->jy > SBY_Lower + MIDPOSY ? SBY_Lower :
2702 local_player->jy - MIDPOSY);
2706 if ((player->MovDir == MV_LEFT && scroll_x > jx - MIDPOSX + offset) ||
2707 (player->MovDir == MV_RIGHT && scroll_x < jx - MIDPOSX - offset))
2708 scroll_x = jx - MIDPOSX + (scroll_x < jx-MIDPOSX ? -offset : +offset);
2710 if ((player->MovDir == MV_UP && scroll_y > jy - MIDPOSY + offset) ||
2711 (player->MovDir == MV_DOWN && scroll_y < jy - MIDPOSY - offset))
2712 scroll_y = jy - MIDPOSY + (scroll_y < jy-MIDPOSY ? -offset : +offset);
2714 /* don't scroll over playfield boundaries */
2715 if (scroll_x < SBX_Left || scroll_x > SBX_Right)
2716 scroll_x = (scroll_x < SBX_Left ? SBX_Left : SBX_Right);
2718 /* don't scroll over playfield boundaries */
2719 if (scroll_y < SBY_Upper || scroll_y > SBY_Lower)
2720 scroll_y = (scroll_y < SBY_Upper ? SBY_Upper : SBY_Lower);
2723 scroll_x += (local_player->jx - old_jx);
2724 scroll_y += (local_player->jy - old_jy);
2726 /* don't scroll over playfield boundaries */
2727 if (scroll_x < SBX_Left || scroll_x > SBX_Right)
2728 scroll_x = (scroll_x < SBX_Left ? SBX_Left : SBX_Right);
2730 /* don't scroll over playfield boundaries */
2731 if (scroll_y < SBY_Upper || scroll_y > SBY_Lower)
2732 scroll_y = (scroll_y < SBY_Upper ? SBY_Upper : SBY_Lower);
2735 RedrawPlayfield(TRUE, 0,0,0,0);
2741 int offset = (setup.scroll_delay ? 3 : 0);
2742 int jx = local_player->jx;
2743 int jy = local_player->jy;
2745 int scroll_xx = -999, scroll_yy = -999;
2747 ScrollScreen(NULL, SCROLL_GO_ON); /* scroll last frame to full tile */
2749 while (scroll_xx != scroll_x || scroll_yy != scroll_y)
2752 int fx = FX, fy = FY;
2754 scroll_xx = (local_player->jx < SBX_Left + MIDPOSX ? SBX_Left :
2755 local_player->jx > SBX_Right + MIDPOSX ? SBX_Right :
2756 local_player->jx - MIDPOSX);
2758 scroll_yy = (local_player->jy < SBY_Upper + MIDPOSY ? SBY_Upper :
2759 local_player->jy > SBY_Lower + MIDPOSY ? SBY_Lower :
2760 local_player->jy - MIDPOSY);
2762 dx = (scroll_xx < scroll_x ? +1 : scroll_xx > scroll_x ? -1 : 0);
2763 dy = (scroll_yy < scroll_y ? +1 : scroll_yy > scroll_y ? -1 : 0);
2766 if (dx == 0 && dy == 0) /* no scrolling needed at all */
2769 if (scroll_xx == scroll_x && scroll_yy == scroll_y)
2776 fx += dx * TILEX / 2;
2777 fy += dy * TILEY / 2;
2779 ScrollLevel(dx, dy);
2782 /* scroll in two steps of half tile size to make things smoother */
2783 BlitBitmap(drawto_field, window, fx, fy, SXSIZE, SYSIZE, SX, SY);
2785 Delay(wait_delay_value);
2787 /* scroll second step to align at full tile size */
2789 Delay(wait_delay_value);
2792 int scroll_xx = -999, scroll_yy = -999;
2794 ScrollScreen(NULL, SCROLL_GO_ON); /* scroll last frame to full tile */
2796 while (scroll_xx != scroll_x || scroll_yy != scroll_y)
2799 int fx = FX, fy = FY;
2801 scroll_xx = (local_player->jx < SBX_Left + MIDPOSX ? SBX_Left :
2802 local_player->jx > SBX_Right + MIDPOSX ? SBX_Right :
2803 local_player->jx - MIDPOSX);
2805 scroll_yy = (local_player->jy < SBY_Upper + MIDPOSY ? SBY_Upper :
2806 local_player->jy > SBY_Lower + MIDPOSY ? SBY_Lower :
2807 local_player->jy - MIDPOSY);
2809 dx = (scroll_xx < scroll_x ? +1 : scroll_xx > scroll_x ? -1 : 0);
2810 dy = (scroll_yy < scroll_y ? +1 : scroll_yy > scroll_y ? -1 : 0);
2813 if (dx == 0 && dy == 0) /* no scrolling needed at all */
2816 if (scroll_xx == scroll_x && scroll_yy == scroll_y)
2823 fx += dx * TILEX / 2;
2824 fy += dy * TILEY / 2;
2826 ScrollLevel(dx, dy);
2829 /* scroll in two steps of half tile size to make things smoother */
2830 BlitBitmap(drawto_field, window, fx, fy, SXSIZE, SYSIZE, SX, SY);
2832 Delay(wait_delay_value);
2834 /* scroll second step to align at full tile size */
2836 Delay(wait_delay_value);
2842 void Explode(int ex, int ey, int phase, int mode)
2849 /* !!! eliminate this variable !!! */
2850 int delay = (game.emulation == EMU_SUPAPLEX ? 3 : 2);
2855 int last_phase = num_phase * delay;
2856 int half_phase = (num_phase / 2) * delay;
2857 int first_phase_after_start = EX_PHASE_START + 1;
2861 if (game.explosions_delayed)
2863 ExplodeField[ex][ey] = mode;
2867 if (phase == EX_PHASE_START) /* initialize 'Store[][]' field */
2869 int center_element = Feld[ex][ey];
2872 printf("::: start explosion %d,%d [%d]\n", ex, ey, FrameCounter);
2876 /* --- This is only really needed (and now handled) in "Impact()". --- */
2877 /* do not explode moving elements that left the explode field in time */
2878 if (game.engine_version >= VERSION_IDENT(2,2,0,7) &&
2879 center_element == EL_EMPTY &&
2880 (mode == EX_TYPE_NORMAL || mode == EX_TYPE_CENTER))
2884 if (mode == EX_TYPE_NORMAL || mode == EX_TYPE_CENTER)
2885 PlayLevelSoundAction(ex, ey, ACTION_EXPLODING);
2887 /* remove things displayed in background while burning dynamite */
2888 if (Back[ex][ey] != EL_EMPTY && !IS_INDESTRUCTIBLE(Back[ex][ey]))
2891 if (IS_MOVING(ex, ey) || IS_BLOCKED(ex, ey))
2893 /* put moving element to center field (and let it explode there) */
2894 center_element = MovingOrBlocked2Element(ex, ey);
2895 RemoveMovingField(ex, ey);
2896 Feld[ex][ey] = center_element;
2902 last_phase = element_info[center_element].explosion_delay + 1;
2904 last_phase = element_info[center_element].explosion_delay;
2908 printf("::: %d -> %d\n", center_element, last_phase);
2912 for (y = ey - 1; y <= ey + 1; y++) for (x = ex - 1; x <= ex + 1; x++)
2914 int xx = x - ex + 1;
2915 int yy = y - ey + 1;
2920 if (!IN_LEV_FIELD(x, y) ||
2921 (mode & EX_TYPE_SINGLE_TILE && (x != ex || y != ey)) ||
2922 (mode == EX_TYPE_CROSS && (x != ex && y != ey)))
2925 if (!IN_LEV_FIELD(x, y) ||
2926 (mode != EX_TYPE_NORMAL && (x != ex || y != ey)))
2930 if (!IN_LEV_FIELD(x, y) ||
2931 ((mode != EX_TYPE_NORMAL ||
2932 center_element == EL_AMOEBA_TO_DIAMOND) &&
2933 (x != ex || y != ey)))
2937 element = Feld[x][y];
2939 if (IS_MOVING(x, y) || IS_BLOCKED(x, y))
2941 element = MovingOrBlocked2Element(x, y);
2943 if (!IS_EXPLOSION_PROOF(element))
2944 RemoveMovingField(x, y);
2950 if (IS_EXPLOSION_PROOF(element))
2953 /* indestructible elements can only explode in center (but not flames) */
2954 if ((IS_EXPLOSION_PROOF(element) && (x != ex || y != ey)) ||
2955 element == EL_FLAMES)
2960 if ((IS_INDESTRUCTIBLE(element) &&
2961 (game.engine_version < VERSION_IDENT(2,2,0,0) ||
2962 (!IS_WALKABLE_OVER(element) && !IS_WALKABLE_UNDER(element)))) ||
2963 element == EL_FLAMES)
2967 if (IS_PLAYER(x, y) && SHIELD_ON(PLAYERINFO(x, y)))
2969 if (IS_ACTIVE_BOMB(element))
2971 /* re-activate things under the bomb like gate or penguin */
2972 Feld[x][y] = (Store[x][y] ? Store[x][y] : EL_EMPTY);
2979 /* save walkable background elements while explosion on same tile */
2981 if (IS_INDESTRUCTIBLE(element))
2982 Back[x][y] = element;
2984 if (IS_WALKABLE(element) && IS_INDESTRUCTIBLE(element))
2985 Back[x][y] = element;
2988 /* ignite explodable elements reached by other explosion */
2989 if (element == EL_EXPLOSION)
2990 element = Store2[x][y];
2993 if (AmoebaNr[x][y] &&
2994 (element == EL_AMOEBA_FULL ||
2995 element == EL_BD_AMOEBA ||
2996 element == EL_AMOEBA_GROWING))
2998 AmoebaCnt[AmoebaNr[x][y]]--;
2999 AmoebaCnt2[AmoebaNr[x][y]]--;
3005 if (IS_PLAYER(ex, ey) && !PLAYER_EXPLOSION_PROTECTED(ex, ey))
3007 switch(StorePlayer[ex][ey])
3010 Store[x][y] = EL_PLAYER_IS_EXPLODING_2;
3013 Store[x][y] = EL_PLAYER_IS_EXPLODING_3;
3016 Store[x][y] = EL_PLAYER_IS_EXPLODING_4;
3020 Store[x][y] = EL_PLAYER_IS_EXPLODING_1;
3025 if (PLAYERINFO(ex, ey)->use_murphy_graphic)
3026 Store[x][y] = EL_EMPTY;
3028 if (game.emulation == EMU_SUPAPLEX)
3029 Store[x][y] = EL_EMPTY;
3032 else if (center_element == EL_MOLE)
3033 Store[x][y] = EL_EMERALD_RED;
3034 else if (center_element == EL_PENGUIN)
3035 Store[x][y] = EL_EMERALD_PURPLE;
3036 else if (center_element == EL_BUG)
3037 Store[x][y] = ((x == ex && y == ey) ? EL_DIAMOND : EL_EMERALD);
3038 else if (center_element == EL_BD_BUTTERFLY)
3039 Store[x][y] = EL_BD_DIAMOND;
3040 else if (center_element == EL_SP_ELECTRON)
3041 Store[x][y] = EL_SP_INFOTRON;
3042 else if (center_element == EL_AMOEBA_TO_DIAMOND)
3043 Store[x][y] = level.amoeba_content;
3044 else if (center_element == EL_YAMYAM)
3045 Store[x][y] = level.yamyam_content[game.yamyam_content_nr][xx][yy];
3046 else if (IS_CUSTOM_ELEMENT(center_element) &&
3047 element_info[center_element].content[xx][yy] != EL_EMPTY)
3048 Store[x][y] = element_info[center_element].content[xx][yy];
3049 else if (element == EL_WALL_EMERALD)
3050 Store[x][y] = EL_EMERALD;
3051 else if (element == EL_WALL_DIAMOND)
3052 Store[x][y] = EL_DIAMOND;
3053 else if (element == EL_WALL_BD_DIAMOND)
3054 Store[x][y] = EL_BD_DIAMOND;
3055 else if (element == EL_WALL_EMERALD_YELLOW)
3056 Store[x][y] = EL_EMERALD_YELLOW;
3057 else if (element == EL_WALL_EMERALD_RED)
3058 Store[x][y] = EL_EMERALD_RED;
3059 else if (element == EL_WALL_EMERALD_PURPLE)
3060 Store[x][y] = EL_EMERALD_PURPLE;
3061 else if (element == EL_WALL_PEARL)
3062 Store[x][y] = EL_PEARL;
3063 else if (element == EL_WALL_CRYSTAL)
3064 Store[x][y] = EL_CRYSTAL;
3065 else if (IS_CUSTOM_ELEMENT(element) && !CAN_EXPLODE(element))
3066 Store[x][y] = element_info[element].content[1][1];
3068 Store[x][y] = EL_EMPTY;
3070 if (x != ex || y != ey ||
3071 center_element == EL_AMOEBA_TO_DIAMOND || mode == EX_TYPE_BORDER)
3072 Store2[x][y] = element;
3075 if (AmoebaNr[x][y] &&
3076 (element == EL_AMOEBA_FULL ||
3077 element == EL_BD_AMOEBA ||
3078 element == EL_AMOEBA_GROWING))
3080 AmoebaCnt[AmoebaNr[x][y]]--;
3081 AmoebaCnt2[AmoebaNr[x][y]]--;
3087 MovDir[x][y] = MovPos[x][y] = 0;
3088 GfxDir[x][y] = MovDir[x][y];
3093 Feld[x][y] = EL_EXPLOSION;
3095 GfxElement[x][y] = center_element;
3097 GfxElement[x][y] = EL_UNDEFINED;
3100 ExplodePhase[x][y] = 1;
3102 ExplodeDelay[x][y] = last_phase;
3107 GfxFrame[x][y] = 0; /* animation does not start until next frame */
3109 GfxFrame[x][y] = -1; /* animation does not start until next frame */
3116 if (center_element == EL_YAMYAM)
3117 game.yamyam_content_nr =
3118 (game.yamyam_content_nr + 1) % level.num_yamyam_contents;
3131 GfxFrame[x][y] = 0; /* restart explosion animation */
3135 printf(":X: phase == %d [%d]\n", phase, GfxFrame[x][y]);
3139 last_phase = ExplodeDelay[x][y];
3142 ExplodePhase[x][y] = (phase < last_phase ? phase + 1 : 0);
3146 /* activate this even in non-DEBUG version until cause for crash in
3147 getGraphicAnimationFrame() (see below) is found and eliminated */
3151 if (GfxElement[x][y] == EL_UNDEFINED)
3154 printf("Explode(): x = %d, y = %d: GfxElement == EL_UNDEFINED\n", x, y);
3155 printf("Explode(): This should never happen!\n");
3158 GfxElement[x][y] = EL_EMPTY;
3164 border_element = Store2[x][y];
3165 if (IS_PLAYER(x, y))
3166 border_element = StorePlayer[x][y];
3169 printf("::: phase == %d\n", phase);
3172 if (phase == element_info[border_element].ignition_delay ||
3173 phase == last_phase)
3175 boolean border_explosion = FALSE;
3178 if (IS_PLAYER(x, y) && PLAYERINFO(x, y)->present)
3180 if (IS_PLAYER(x, y))
3183 KillHeroUnlessExplosionProtected(x, y);
3184 border_explosion = TRUE;
3187 if (phase == last_phase)
3188 printf("::: IS_PLAYER\n");
3191 else if (CAN_EXPLODE_BY_EXPLOSION(border_element))
3193 Feld[x][y] = Store2[x][y];
3196 border_explosion = TRUE;
3199 if (phase == last_phase)
3200 printf("::: CAN_EXPLODE_BY_EXPLOSION\n");
3203 else if (border_element == EL_AMOEBA_TO_DIAMOND)
3205 AmoebeUmwandeln(x, y);
3207 border_explosion = TRUE;
3210 if (phase == last_phase)
3211 printf("::: EL_AMOEBA_TO_DIAMOND [%d, %d] [%d]\n",
3212 element_info[border_element].explosion_delay,
3213 element_info[border_element].ignition_delay,
3219 /* if an element just explodes due to another explosion (chain-reaction),
3220 do not immediately end the new explosion when it was the last frame of
3221 the explosion (as it would be done in the following "if"-statement!) */
3222 if (border_explosion && phase == last_phase)
3229 if (phase == first_phase_after_start)
3231 int element = Store2[x][y];
3233 if (element == EL_BLACK_ORB)
3235 Feld[x][y] = Store2[x][y];
3240 else if (phase == half_phase)
3242 int element = Store2[x][y];
3244 if (IS_PLAYER(x, y))
3245 KillHeroUnlessExplosionProtected(x, y);
3246 else if (CAN_EXPLODE_BY_EXPLOSION(element))
3248 Feld[x][y] = Store2[x][y];
3252 else if (element == EL_AMOEBA_TO_DIAMOND)
3253 AmoebeUmwandeln(x, y);
3257 if (phase == last_phase)
3262 printf("::: done: phase == %d\n", phase);
3266 printf("::: explosion %d,%d done [%d]\n", x, y, FrameCounter);
3269 element = Feld[x][y] = Store[x][y];
3270 Store[x][y] = Store2[x][y] = 0;
3271 GfxElement[x][y] = EL_UNDEFINED;
3273 /* player can escape from explosions and might therefore be still alive */
3274 if (element >= EL_PLAYER_IS_EXPLODING_1 &&
3275 element <= EL_PLAYER_IS_EXPLODING_4)
3276 Feld[x][y] = (stored_player[element - EL_PLAYER_IS_EXPLODING_1].active ?
3278 element == EL_PLAYER_IS_EXPLODING_1 ? EL_EMERALD_YELLOW :
3279 element == EL_PLAYER_IS_EXPLODING_2 ? EL_EMERALD_RED :
3280 element == EL_PLAYER_IS_EXPLODING_3 ? EL_EMERALD :
3283 /* restore probably existing indestructible background element */
3284 if (Back[x][y] && IS_INDESTRUCTIBLE(Back[x][y]))
3285 element = Feld[x][y] = Back[x][y];
3288 MovDir[x][y] = MovPos[x][y] = MovDelay[x][y] = 0;
3289 GfxDir[x][y] = MV_NO_MOVING;
3290 ChangeDelay[x][y] = 0;
3291 ChangePage[x][y] = -1;
3294 InitField_WithBug2(x, y, FALSE);
3296 InitField(x, y, FALSE);
3298 /* !!! not needed !!! */
3300 if (game.engine_version < VERSION_IDENT(3,1,0,0) &&
3301 CAN_MOVE(Feld[x][y]) && Feld[x][y] != EL_MOLE)
3304 if (CAN_MOVE(element))
3309 DrawLevelField(x, y);
3311 TestIfElementTouchesCustomElement(x, y);
3313 if (GFX_CRUMBLED(element))
3314 DrawLevelFieldCrumbledSandNeighbours(x, y);
3316 if (IS_PLAYER(x, y) && !PLAYERINFO(x, y)->present)
3317 StorePlayer[x][y] = 0;
3319 if (ELEM_IS_PLAYER(element))
3320 RelocatePlayer(x, y, element);
3323 else if (IN_SCR_FIELD(SCREENX(x), SCREENY(y)))
3325 else if (phase >= delay && IN_SCR_FIELD(SCREENX(x), SCREENY(y)))
3329 int graphic = el_act2img(GfxElement[x][y], ACTION_EXPLODING);
3331 int stored = Store[x][y];
3332 int graphic = (game.emulation != EMU_SUPAPLEX ? IMG_EXPLOSION :
3333 stored == EL_SP_INFOTRON ? IMG_SP_EXPLOSION_INFOTRON :
3337 int frame = getGraphicAnimationFrame(graphic, GfxFrame[x][y]);
3339 int frame = getGraphicAnimationFrame(graphic, phase - delay);
3343 printf("::: phase == %d [%d]\n", phase, GfxFrame[x][y]);
3347 printf("::: %d / %d [%d - %d]\n",
3348 GfxFrame[x][y], phase - delay, phase, delay);
3352 printf("::: %d ['%s'] -> %d\n", GfxElement[x][y],
3353 element_info[GfxElement[x][y]].token_name,
3358 DrawLevelFieldCrumbledSand(x, y);
3360 if (IS_WALKABLE_OVER(Back[x][y]) && Back[x][y] != EL_EMPTY)
3362 DrawLevelElement(x, y, Back[x][y]);
3363 DrawGraphicThruMask(SCREENX(x), SCREENY(y), graphic, frame);
3365 else if (IS_WALKABLE_UNDER(Back[x][y]))
3367 DrawGraphic(SCREENX(x), SCREENY(y), graphic, frame);
3368 DrawLevelElementThruMask(x, y, Back[x][y]);
3370 else if (!IS_WALKABLE_INSIDE(Back[x][y]))
3371 DrawGraphic(SCREENX(x), SCREENY(y), graphic, frame);
3375 void DynaExplode(int ex, int ey)
3378 int dynabomb_element = Feld[ex][ey];
3379 int dynabomb_size = 1;
3380 boolean dynabomb_xl = FALSE;
3381 struct PlayerInfo *player;
3382 static int xy[4][2] =
3390 if (IS_ACTIVE_BOMB(dynabomb_element))
3392 player = &stored_player[dynabomb_element - EL_DYNABOMB_PLAYER_1_ACTIVE];
3393 dynabomb_size = player->dynabomb_size;
3394 dynabomb_xl = player->dynabomb_xl;
3395 player->dynabombs_left++;
3398 Explode(ex, ey, EX_PHASE_START, EX_TYPE_CENTER);
3400 for (i = 0; i < NUM_DIRECTIONS; i++)
3402 for (j = 1; j <= dynabomb_size; j++)
3404 int x = ex + j * xy[i][0];
3405 int y = ey + j * xy[i][1];
3408 if (!IN_LEV_FIELD(x, y) || IS_INDESTRUCTIBLE(Feld[x][y]))
3411 element = Feld[x][y];
3413 /* do not restart explosions of fields with active bombs */
3414 if (element == EL_EXPLOSION && IS_ACTIVE_BOMB(Store2[x][y]))
3417 Explode(x, y, EX_PHASE_START, EX_TYPE_BORDER);
3419 /* !!! extend EL_SAND to anything diggable (but maybe not SP_BASE) !!! */
3420 if (element != EL_EMPTY &&
3421 element != EL_SAND &&
3422 element != EL_EXPLOSION &&
3429 void Bang(int x, int y)
3432 int element = MovingOrBlocked2Element(x, y);
3434 int element = Feld[x][y];
3438 if (IS_PLAYER(x, y) && !PLAYER_EXPLOSION_PROTECTED(x, y))
3440 if (IS_PLAYER(x, y))
3443 struct PlayerInfo *player = PLAYERINFO(x, y);
3445 element = Feld[x][y] = (player->use_murphy_graphic ? EL_SP_MURPHY :
3446 player->element_nr);
3451 PlayLevelSoundAction(x, y, ACTION_EXPLODING);
3453 if (game.emulation == EMU_SUPAPLEX)
3454 PlayLevelSound(x, y, SND_SP_ELEMENT_EXPLODING);
3456 PlayLevelSound(x, y, SND_ELEMENT_EXPLODING);
3461 if (IS_PLAYER(x, y)) /* remove objects that might cause smaller explosion */
3469 case EL_BD_BUTTERFLY:
3472 case EL_DARK_YAMYAM:
3476 RaiseScoreElement(element);
3477 Explode(x, y, EX_PHASE_START, EX_TYPE_NORMAL);
3479 case EL_DYNABOMB_PLAYER_1_ACTIVE:
3480 case EL_DYNABOMB_PLAYER_2_ACTIVE:
3481 case EL_DYNABOMB_PLAYER_3_ACTIVE:
3482 case EL_DYNABOMB_PLAYER_4_ACTIVE:
3483 case EL_DYNABOMB_INCREASE_NUMBER:
3484 case EL_DYNABOMB_INCREASE_SIZE:
3485 case EL_DYNABOMB_INCREASE_POWER:
3490 case EL_LAMP_ACTIVE:
3492 case EL_AMOEBA_TO_DIAMOND:
3494 if (IS_PLAYER(x, y))
3495 Explode(x, y, EX_PHASE_START, EX_TYPE_NORMAL);
3497 Explode(x, y, EX_PHASE_START, EX_TYPE_CENTER);
3500 if (CAN_EXPLODE_CROSS(element))
3502 Explode(x, y, EX_PHASE_START, EX_TYPE_CROSS);
3506 else if (CAN_EXPLODE_1X1(element))
3507 Explode(x, y, EX_PHASE_START, EX_TYPE_CENTER);
3509 Explode(x, y, EX_PHASE_START, EX_TYPE_NORMAL);
3513 CheckTriggeredElementChange(x, y, element, CE_OTHER_IS_EXPLODING);
3516 void SplashAcid(int x, int y)
3519 if (IN_LEV_FIELD(x - 1, y - 1) && IS_FREE(x - 1, y - 1) &&
3520 (!IN_LEV_FIELD(x - 1, y - 2) ||
3521 !CAN_FALL(MovingOrBlocked2Element(x - 1, y - 2))))
3522 Feld[x - 1][y - 1] = EL_ACID_SPLASH_LEFT;
3524 if (IN_LEV_FIELD(x + 1, y - 1) && IS_FREE(x + 1, y - 1) &&
3525 (!IN_LEV_FIELD(x + 1, y - 2) ||
3526 !CAN_FALL(MovingOrBlocked2Element(x + 1, y - 2))))
3527 Feld[x + 1][y - 1] = EL_ACID_SPLASH_RIGHT;
3529 PlayLevelSound(x, y, SND_ACID_SPLASHING);
3531 /* input: position of element entering acid (obsolete) */
3533 int element = Feld[x][y];
3535 if (!IN_LEV_FIELD(x, y + 1) || Feld[x][y + 1] != EL_ACID)
3538 if (element != EL_ACID_SPLASH_LEFT &&
3539 element != EL_ACID_SPLASH_RIGHT)
3541 PlayLevelSound(x, y, SND_ACID_SPLASHING);
3543 if (IN_LEV_FIELD(x - 1, y) && IS_FREE(x - 1, y) &&
3544 (!IN_LEV_FIELD(x - 1, y - 1) ||
3545 !CAN_FALL(MovingOrBlocked2Element(x - 1, y - 1))))
3546 Feld[x - 1][y] = EL_ACID_SPLASH_LEFT;
3548 if (IN_LEV_FIELD(x + 1, y) && IS_FREE(x + 1, y) &&
3549 (!IN_LEV_FIELD(x + 1, y - 1) ||
3550 !CAN_FALL(MovingOrBlocked2Element(x + 1, y - 1))))
3551 Feld[x + 1][y] = EL_ACID_SPLASH_RIGHT;
3556 static void InitBeltMovement()
3558 static int belt_base_element[4] =
3560 EL_CONVEYOR_BELT_1_LEFT,
3561 EL_CONVEYOR_BELT_2_LEFT,
3562 EL_CONVEYOR_BELT_3_LEFT,
3563 EL_CONVEYOR_BELT_4_LEFT
3565 static int belt_base_active_element[4] =
3567 EL_CONVEYOR_BELT_1_LEFT_ACTIVE,
3568 EL_CONVEYOR_BELT_2_LEFT_ACTIVE,
3569 EL_CONVEYOR_BELT_3_LEFT_ACTIVE,
3570 EL_CONVEYOR_BELT_4_LEFT_ACTIVE
3575 /* set frame order for belt animation graphic according to belt direction */
3576 for (i = 0; i < NUM_BELTS; i++)
3580 for (j = 0; j < NUM_BELT_PARTS; j++)
3582 int element = belt_base_active_element[belt_nr] + j;
3583 int graphic = el2img(element);
3585 if (game.belt_dir[i] == MV_LEFT)
3586 graphic_info[graphic].anim_mode &= ~ANIM_REVERSE;
3588 graphic_info[graphic].anim_mode |= ANIM_REVERSE;
3592 for (y = 0; y < lev_fieldy; y++)
3594 for (x = 0; x < lev_fieldx; x++)
3596 int element = Feld[x][y];
3598 for (i = 0; i < NUM_BELTS; i++)
3600 if (IS_BELT(element) && game.belt_dir[i] != MV_NO_MOVING)
3602 int e_belt_nr = getBeltNrFromBeltElement(element);
3605 if (e_belt_nr == belt_nr)
3607 int belt_part = Feld[x][y] - belt_base_element[belt_nr];
3609 Feld[x][y] = belt_base_active_element[belt_nr] + belt_part;
3617 static void ToggleBeltSwitch(int x, int y)
3619 static int belt_base_element[4] =
3621 EL_CONVEYOR_BELT_1_LEFT,
3622 EL_CONVEYOR_BELT_2_LEFT,
3623 EL_CONVEYOR_BELT_3_LEFT,
3624 EL_CONVEYOR_BELT_4_LEFT
3626 static int belt_base_active_element[4] =
3628 EL_CONVEYOR_BELT_1_LEFT_ACTIVE,
3629 EL_CONVEYOR_BELT_2_LEFT_ACTIVE,
3630 EL_CONVEYOR_BELT_3_LEFT_ACTIVE,
3631 EL_CONVEYOR_BELT_4_LEFT_ACTIVE
3633 static int belt_base_switch_element[4] =
3635 EL_CONVEYOR_BELT_1_SWITCH_LEFT,
3636 EL_CONVEYOR_BELT_2_SWITCH_LEFT,
3637 EL_CONVEYOR_BELT_3_SWITCH_LEFT,
3638 EL_CONVEYOR_BELT_4_SWITCH_LEFT
3640 static int belt_move_dir[4] =
3648 int element = Feld[x][y];
3649 int belt_nr = getBeltNrFromBeltSwitchElement(element);
3650 int belt_dir_nr = (game.belt_dir_nr[belt_nr] + 1) % 4;
3651 int belt_dir = belt_move_dir[belt_dir_nr];
3654 if (!IS_BELT_SWITCH(element))
3657 game.belt_dir_nr[belt_nr] = belt_dir_nr;
3658 game.belt_dir[belt_nr] = belt_dir;
3660 if (belt_dir_nr == 3)
3663 /* set frame order for belt animation graphic according to belt direction */
3664 for (i = 0; i < NUM_BELT_PARTS; i++)
3666 int element = belt_base_active_element[belt_nr] + i;
3667 int graphic = el2img(element);
3669 if (belt_dir == MV_LEFT)
3670 graphic_info[graphic].anim_mode &= ~ANIM_REVERSE;
3672 graphic_info[graphic].anim_mode |= ANIM_REVERSE;
3675 for (yy = 0; yy < lev_fieldy; yy++)
3677 for (xx = 0; xx < lev_fieldx; xx++)
3679 int element = Feld[xx][yy];
3681 if (IS_BELT_SWITCH(element))
3683 int e_belt_nr = getBeltNrFromBeltSwitchElement(element);
3685 if (e_belt_nr == belt_nr)
3687 Feld[xx][yy] = belt_base_switch_element[belt_nr] + belt_dir_nr;
3688 DrawLevelField(xx, yy);
3691 else if (IS_BELT(element) && belt_dir != MV_NO_MOVING)
3693 int e_belt_nr = getBeltNrFromBeltElement(element);
3695 if (e_belt_nr == belt_nr)
3697 int belt_part = Feld[xx][yy] - belt_base_element[belt_nr];
3699 Feld[xx][yy] = belt_base_active_element[belt_nr] + belt_part;
3700 DrawLevelField(xx, yy);
3703 else if (IS_BELT_ACTIVE(element) && belt_dir == MV_NO_MOVING)
3705 int e_belt_nr = getBeltNrFromBeltActiveElement(element);
3707 if (e_belt_nr == belt_nr)
3709 int belt_part = Feld[xx][yy] - belt_base_active_element[belt_nr];
3711 Feld[xx][yy] = belt_base_element[belt_nr] + belt_part;
3712 DrawLevelField(xx, yy);
3719 static void ToggleSwitchgateSwitch(int x, int y)
3723 game.switchgate_pos = !game.switchgate_pos;
3725 for (yy = 0; yy < lev_fieldy; yy++)
3727 for (xx = 0; xx < lev_fieldx; xx++)
3729 int element = Feld[xx][yy];
3731 if (element == EL_SWITCHGATE_SWITCH_UP ||
3732 element == EL_SWITCHGATE_SWITCH_DOWN)
3734 Feld[xx][yy] = EL_SWITCHGATE_SWITCH_UP + game.switchgate_pos;
3735 DrawLevelField(xx, yy);
3737 else if (element == EL_SWITCHGATE_OPEN ||
3738 element == EL_SWITCHGATE_OPENING)
3740 Feld[xx][yy] = EL_SWITCHGATE_CLOSING;
3742 PlayLevelSoundAction(xx, yy, ACTION_CLOSING);
3744 PlayLevelSound(xx, yy, SND_SWITCHGATE_CLOSING);
3747 else if (element == EL_SWITCHGATE_CLOSED ||
3748 element == EL_SWITCHGATE_CLOSING)
3750 Feld[xx][yy] = EL_SWITCHGATE_OPENING;
3752 PlayLevelSoundAction(xx, yy, ACTION_OPENING);
3754 PlayLevelSound(xx, yy, SND_SWITCHGATE_OPENING);
3761 static int getInvisibleActiveFromInvisibleElement(int element)
3763 return (element == EL_INVISIBLE_STEELWALL ? EL_INVISIBLE_STEELWALL_ACTIVE :
3764 element == EL_INVISIBLE_WALL ? EL_INVISIBLE_WALL_ACTIVE :
3765 element == EL_INVISIBLE_SAND ? EL_INVISIBLE_SAND_ACTIVE :
3769 static int getInvisibleFromInvisibleActiveElement(int element)
3771 return (element == EL_INVISIBLE_STEELWALL_ACTIVE ? EL_INVISIBLE_STEELWALL :
3772 element == EL_INVISIBLE_WALL_ACTIVE ? EL_INVISIBLE_WALL :
3773 element == EL_INVISIBLE_SAND_ACTIVE ? EL_INVISIBLE_SAND :
3777 static void RedrawAllLightSwitchesAndInvisibleElements()
3781 for (y = 0; y < lev_fieldy; y++)
3783 for (x = 0; x < lev_fieldx; x++)
3785 int element = Feld[x][y];
3787 if (element == EL_LIGHT_SWITCH &&
3788 game.light_time_left > 0)
3790 Feld[x][y] = EL_LIGHT_SWITCH_ACTIVE;
3791 DrawLevelField(x, y);
3793 else if (element == EL_LIGHT_SWITCH_ACTIVE &&
3794 game.light_time_left == 0)
3796 Feld[x][y] = EL_LIGHT_SWITCH;
3797 DrawLevelField(x, y);
3799 else if (element == EL_INVISIBLE_STEELWALL ||
3800 element == EL_INVISIBLE_WALL ||
3801 element == EL_INVISIBLE_SAND)
3803 if (game.light_time_left > 0)
3804 Feld[x][y] = getInvisibleActiveFromInvisibleElement(element);
3806 DrawLevelField(x, y);
3808 else if (element == EL_INVISIBLE_STEELWALL_ACTIVE ||
3809 element == EL_INVISIBLE_WALL_ACTIVE ||
3810 element == EL_INVISIBLE_SAND_ACTIVE)
3812 if (game.light_time_left == 0)
3813 Feld[x][y] = getInvisibleFromInvisibleActiveElement(element);
3815 DrawLevelField(x, y);
3821 static void ToggleLightSwitch(int x, int y)
3823 int element = Feld[x][y];
3825 game.light_time_left =
3826 (element == EL_LIGHT_SWITCH ?
3827 level.time_light * FRAMES_PER_SECOND : 0);
3829 RedrawAllLightSwitchesAndInvisibleElements();
3832 static void ActivateTimegateSwitch(int x, int y)
3836 game.timegate_time_left = level.time_timegate * FRAMES_PER_SECOND;
3838 for (yy = 0; yy < lev_fieldy; yy++)
3840 for (xx = 0; xx < lev_fieldx; xx++)
3842 int element = Feld[xx][yy];
3844 if (element == EL_TIMEGATE_CLOSED ||
3845 element == EL_TIMEGATE_CLOSING)
3847 Feld[xx][yy] = EL_TIMEGATE_OPENING;
3848 PlayLevelSound(xx, yy, SND_TIMEGATE_OPENING);
3852 else if (element == EL_TIMEGATE_SWITCH_ACTIVE)
3854 Feld[xx][yy] = EL_TIMEGATE_SWITCH;
3855 DrawLevelField(xx, yy);
3862 Feld[x][y] = EL_TIMEGATE_SWITCH_ACTIVE;
3865 inline static int getElementMoveStepsize(int x, int y)
3867 int element = Feld[x][y];
3868 int direction = MovDir[x][y];
3869 int dx = (direction == MV_LEFT ? -1 : direction == MV_RIGHT ? +1 : 0);
3870 int dy = (direction == MV_UP ? -1 : direction == MV_DOWN ? +1 : 0);
3871 int horiz_move = (dx != 0);
3872 int sign = (horiz_move ? dx : dy);
3873 int step = sign * element_info[element].move_stepsize;
3875 /* special values for move stepsize for spring and things on conveyor belt */
3879 if (element == EL_SPRING)
3880 step = sign * MOVE_STEPSIZE_NORMAL * 2;
3881 else if (CAN_FALL(element) && !CAN_MOVE(element) &&
3882 y < lev_fieldy - 1 && IS_BELT_ACTIVE(Feld[x][y + 1]))
3883 step = sign * MOVE_STEPSIZE_NORMAL / 2;
3885 if (CAN_FALL(element) &&
3886 y < lev_fieldy - 1 && IS_BELT_ACTIVE(Feld[x][y + 1]))
3887 step = sign * MOVE_STEPSIZE_NORMAL / 2;
3888 else if (element == EL_SPRING)
3889 step = sign * MOVE_STEPSIZE_NORMAL * 2;
3896 void Impact(int x, int y)
3898 boolean lastline = (y == lev_fieldy-1);
3899 boolean object_hit = FALSE;
3900 boolean impact = (lastline || object_hit);
3901 int element = Feld[x][y];
3902 int smashed = EL_STEELWALL;
3904 if (!lastline) /* check if element below was hit */
3906 if (Feld[x][y + 1] == EL_PLAYER_IS_LEAVING)
3909 object_hit = (!IS_FREE(x, y + 1) && (!IS_MOVING(x, y + 1) ||
3910 MovDir[x][y + 1] != MV_DOWN ||
3911 MovPos[x][y + 1] <= TILEY / 2));
3914 object_hit = !IS_FREE(x, y + 1);
3917 /* do not smash moving elements that left the smashed field in time */
3918 if (game.engine_version >= VERSION_IDENT(2,2,0,7) && IS_MOVING(x, y + 1) &&
3919 ABS(MovPos[x][y + 1] + getElementMoveStepsize(x, y + 1)) >= TILEX)
3923 smashed = MovingOrBlocked2Element(x, y + 1);
3925 impact = (lastline || object_hit);
3928 if (!lastline && smashed == EL_ACID) /* element falls into acid */
3930 SplashAcid(x, y + 1);
3934 /* only reset graphic animation if graphic really changes after impact */
3936 el_act_dir2img(element, GfxAction[x][y], MV_DOWN) != el2img(element))
3938 ResetGfxAnimation(x, y);
3939 DrawLevelField(x, y);
3942 if (impact && CAN_EXPLODE_IMPACT(element))
3947 else if (impact && element == EL_PEARL)
3949 Feld[x][y] = EL_PEARL_BREAKING;
3950 PlayLevelSound(x, y, SND_PEARL_BREAKING);
3953 else if (impact && CheckElementChange(x, y, element, smashed, CE_IMPACT))
3955 PlayLevelSoundElementAction(x, y, element, ACTION_IMPACT);
3960 if (impact && element == EL_AMOEBA_DROP)
3962 if (object_hit && IS_PLAYER(x, y + 1))
3963 KillHeroUnlessEnemyProtected(x, y + 1);
3964 else if (object_hit && smashed == EL_PENGUIN)
3968 Feld[x][y] = EL_AMOEBA_GROWING;
3969 Store[x][y] = EL_AMOEBA_WET;
3971 ResetRandomAnimationValue(x, y);
3976 if (object_hit) /* check which object was hit */
3978 if (CAN_PASS_MAGIC_WALL(element) &&
3979 (smashed == EL_MAGIC_WALL ||
3980 smashed == EL_BD_MAGIC_WALL))
3983 int activated_magic_wall =
3984 (smashed == EL_MAGIC_WALL ? EL_MAGIC_WALL_ACTIVE :
3985 EL_BD_MAGIC_WALL_ACTIVE);
3987 /* activate magic wall / mill */
3988 for (yy = 0; yy < lev_fieldy; yy++)
3989 for (xx = 0; xx < lev_fieldx; xx++)
3990 if (Feld[xx][yy] == smashed)
3991 Feld[xx][yy] = activated_magic_wall;
3993 game.magic_wall_time_left = level.time_magic_wall * FRAMES_PER_SECOND;
3994 game.magic_wall_active = TRUE;
3996 PlayLevelSound(x, y, (smashed == EL_MAGIC_WALL ?
3997 SND_MAGIC_WALL_ACTIVATING :
3998 SND_BD_MAGIC_WALL_ACTIVATING));
4001 if (IS_PLAYER(x, y + 1))
4003 if (CAN_SMASH_PLAYER(element))
4005 KillHeroUnlessEnemyProtected(x, y + 1);
4009 else if (smashed == EL_PENGUIN)
4011 if (CAN_SMASH_PLAYER(element))
4017 else if (element == EL_BD_DIAMOND)
4019 if (IS_CLASSIC_ENEMY(smashed) && IS_BD_ELEMENT(smashed))
4025 else if (((element == EL_SP_INFOTRON ||
4026 element == EL_SP_ZONK) &&
4027 (smashed == EL_SP_SNIKSNAK ||
4028 smashed == EL_SP_ELECTRON ||
4029 smashed == EL_SP_DISK_ORANGE)) ||
4030 (element == EL_SP_INFOTRON &&
4031 smashed == EL_SP_DISK_YELLOW))
4037 else if (CAN_SMASH_ENEMIES(element) && IS_CLASSIC_ENEMY(smashed))
4043 else if (CAN_SMASH_EVERYTHING(element))
4045 if (IS_CLASSIC_ENEMY(smashed) ||
4046 CAN_EXPLODE_SMASHED(smashed))
4051 else if (!IS_MOVING(x, y + 1) && !IS_BLOCKED(x, y + 1))
4053 if (smashed == EL_LAMP ||
4054 smashed == EL_LAMP_ACTIVE)
4059 else if (smashed == EL_NUT)
4061 Feld[x][y + 1] = EL_NUT_BREAKING;
4062 PlayLevelSound(x, y, SND_NUT_BREAKING);
4063 RaiseScoreElement(EL_NUT);
4066 else if (smashed == EL_PEARL)
4068 Feld[x][y + 1] = EL_PEARL_BREAKING;
4069 PlayLevelSound(x, y, SND_PEARL_BREAKING);
4072 else if (smashed == EL_DIAMOND)
4074 Feld[x][y + 1] = EL_DIAMOND_BREAKING;
4075 PlayLevelSound(x, y, SND_DIAMOND_BREAKING);
4078 else if (IS_BELT_SWITCH(smashed))
4080 ToggleBeltSwitch(x, y + 1);
4082 else if (smashed == EL_SWITCHGATE_SWITCH_UP ||
4083 smashed == EL_SWITCHGATE_SWITCH_DOWN)
4085 ToggleSwitchgateSwitch(x, y + 1);
4087 else if (smashed == EL_LIGHT_SWITCH ||
4088 smashed == EL_LIGHT_SWITCH_ACTIVE)
4090 ToggleLightSwitch(x, y + 1);
4095 TestIfElementSmashesCustomElement(x, y, MV_DOWN);
4098 CheckElementChange(x, y + 1, smashed, element, CE_SMASHED);
4100 CheckTriggeredElementChangeSide(x, y + 1, smashed,
4101 CE_OTHER_IS_SWITCHING, CH_SIDE_TOP);
4102 CheckElementChangeSide(x, y + 1, smashed, element,
4103 CE_SWITCHED, CH_SIDE_TOP);
4108 CheckElementChange(x, y + 1, smashed, element, CE_SMASHED);
4113 /* play sound of magic wall / mill */
4115 (Feld[x][y + 1] == EL_MAGIC_WALL_ACTIVE ||
4116 Feld[x][y + 1] == EL_BD_MAGIC_WALL_ACTIVE))
4118 if (Feld[x][y + 1] == EL_MAGIC_WALL_ACTIVE)
4119 PlayLevelSound(x, y, SND_MAGIC_WALL_FILLING);
4120 else if (Feld[x][y + 1] == EL_BD_MAGIC_WALL_ACTIVE)
4121 PlayLevelSound(x, y, SND_BD_MAGIC_WALL_FILLING);
4126 /* play sound of object that hits the ground */
4127 if (lastline || object_hit)
4128 PlayLevelSoundElementAction(x, y, element, ACTION_IMPACT);
4131 inline static void TurnRoundExt(int x, int y)
4143 { 0, 0 }, { 0, 0 }, { 0, 0 },
4148 int left, right, back;
4152 { MV_DOWN, MV_UP, MV_RIGHT },
4153 { MV_UP, MV_DOWN, MV_LEFT },
4155 { MV_LEFT, MV_RIGHT, MV_DOWN },
4159 { MV_RIGHT, MV_LEFT, MV_UP }
4162 int element = Feld[x][y];
4163 int move_pattern = element_info[element].move_pattern;
4165 int old_move_dir = MovDir[x][y];
4166 int left_dir = turn[old_move_dir].left;
4167 int right_dir = turn[old_move_dir].right;
4168 int back_dir = turn[old_move_dir].back;
4170 int left_dx = move_xy[left_dir].x, left_dy = move_xy[left_dir].y;
4171 int right_dx = move_xy[right_dir].x, right_dy = move_xy[right_dir].y;
4172 int move_dx = move_xy[old_move_dir].x, move_dy = move_xy[old_move_dir].y;
4173 int back_dx = move_xy[back_dir].x, back_dy = move_xy[back_dir].y;
4175 int left_x = x + left_dx, left_y = y + left_dy;
4176 int right_x = x + right_dx, right_y = y + right_dy;
4177 int move_x = x + move_dx, move_y = y + move_dy;
4181 if (element == EL_BUG || element == EL_BD_BUTTERFLY)
4183 TestIfBadThingTouchesOtherBadThing(x, y);
4185 if (ENEMY_CAN_ENTER_FIELD(element, right_x, right_y))
4186 MovDir[x][y] = right_dir;
4187 else if (!ENEMY_CAN_ENTER_FIELD(element, move_x, move_y))
4188 MovDir[x][y] = left_dir;
4190 if (element == EL_BUG && MovDir[x][y] != old_move_dir)
4192 else if (element == EL_BD_BUTTERFLY) /* && MovDir[x][y] == left_dir) */
4196 else if (element == EL_SPACESHIP || element == EL_BD_FIREFLY ||
4197 element == EL_SP_SNIKSNAK || element == EL_SP_ELECTRON)
4199 TestIfBadThingTouchesOtherBadThing(x, y);
4201 if (ENEMY_CAN_ENTER_FIELD(element, left_x, left_y))
4202 MovDir[x][y] = left_dir;
4203 else if (!ENEMY_CAN_ENTER_FIELD(element, move_x, move_y))
4204 MovDir[x][y] = right_dir;
4206 if ((element == EL_SPACESHIP ||
4207 element == EL_SP_SNIKSNAK ||
4208 element == EL_SP_ELECTRON)
4209 && MovDir[x][y] != old_move_dir)
4211 else if (element == EL_BD_FIREFLY) /* && MovDir[x][y] == right_dir) */
4215 else if (element == EL_SPACESHIP || element == EL_BD_FIREFLY)
4217 TestIfBadThingTouchesOtherBadThing(x, y);
4219 if (ENEMY_CAN_ENTER_FIELD(element, left_x, left_y))
4220 MovDir[x][y] = left_dir;
4221 else if (!ENEMY_CAN_ENTER_FIELD(element, move_x, move_y))
4222 MovDir[x][y] = right_dir;
4224 if (element == EL_SPACESHIP && MovDir[x][y] != old_move_dir)
4226 else if (element == EL_BD_FIREFLY) /* && MovDir[x][y] == right_dir) */
4229 else if (element == EL_SP_SNIKSNAK || element == EL_SP_ELECTRON)
4231 TestIfBadThingTouchesOtherBadThing(x, y);
4233 if (ELEMENT_CAN_ENTER_FIELD_BASE_4(element, left_x, left_y, 0))
4234 MovDir[x][y] = left_dir;
4235 else if (!ELEMENT_CAN_ENTER_FIELD_BASE_4(element, move_x, move_y, 0))
4236 MovDir[x][y] = right_dir;
4238 if (MovDir[x][y] != old_move_dir)
4242 else if (element == EL_YAMYAM)
4244 boolean can_turn_left = YAMYAM_CAN_ENTER_FIELD(element, left_x, left_y);
4245 boolean can_turn_right = YAMYAM_CAN_ENTER_FIELD(element, right_x, right_y);
4247 if (can_turn_left && can_turn_right)
4248 MovDir[x][y] = (RND(3) ? (RND(2) ? left_dir : right_dir) : back_dir);
4249 else if (can_turn_left)
4250 MovDir[x][y] = (RND(2) ? left_dir : back_dir);
4251 else if (can_turn_right)
4252 MovDir[x][y] = (RND(2) ? right_dir : back_dir);
4254 MovDir[x][y] = back_dir;
4256 MovDelay[x][y] = 16 + 16 * RND(3);
4258 else if (element == EL_DARK_YAMYAM)
4260 boolean can_turn_left = DARK_YAMYAM_CAN_ENTER_FIELD(element,
4262 boolean can_turn_right = DARK_YAMYAM_CAN_ENTER_FIELD(element,
4265 if (can_turn_left && can_turn_right)
4266 MovDir[x][y] = (RND(3) ? (RND(2) ? left_dir : right_dir) : back_dir);
4267 else if (can_turn_left)
4268 MovDir[x][y] = (RND(2) ? left_dir : back_dir);
4269 else if (can_turn_right)
4270 MovDir[x][y] = (RND(2) ? right_dir : back_dir);
4272 MovDir[x][y] = back_dir;
4274 MovDelay[x][y] = 16 + 16 * RND(3);
4276 else if (element == EL_PACMAN)
4278 boolean can_turn_left = PACMAN_CAN_ENTER_FIELD(element, left_x, left_y);
4279 boolean can_turn_right = PACMAN_CAN_ENTER_FIELD(element, right_x, right_y);
4281 if (can_turn_left && can_turn_right)
4282 MovDir[x][y] = (RND(3) ? (RND(2) ? left_dir : right_dir) : back_dir);
4283 else if (can_turn_left)
4284 MovDir[x][y] = (RND(2) ? left_dir : back_dir);
4285 else if (can_turn_right)
4286 MovDir[x][y] = (RND(2) ? right_dir : back_dir);
4288 MovDir[x][y] = back_dir;
4290 MovDelay[x][y] = 6 + RND(40);
4292 else if (element == EL_PIG)
4294 boolean can_turn_left = PIG_CAN_ENTER_FIELD(element, left_x, left_y);
4295 boolean can_turn_right = PIG_CAN_ENTER_FIELD(element, right_x, right_y);
4296 boolean can_move_on = PIG_CAN_ENTER_FIELD(element, move_x, move_y);
4297 boolean should_turn_left, should_turn_right, should_move_on;
4299 int rnd = RND(rnd_value);
4301 should_turn_left = (can_turn_left &&
4303 IN_LEV_FIELD_AND_NOT_FREE(x + back_dx + left_dx,
4304 y + back_dy + left_dy)));
4305 should_turn_right = (can_turn_right &&
4307 IN_LEV_FIELD_AND_NOT_FREE(x + back_dx + right_dx,
4308 y + back_dy + right_dy)));
4309 should_move_on = (can_move_on &&
4312 IN_LEV_FIELD_AND_NOT_FREE(x + move_dx + left_dx,
4313 y + move_dy + left_dy) ||
4314 IN_LEV_FIELD_AND_NOT_FREE(x + move_dx + right_dx,
4315 y + move_dy + right_dy)));
4317 if (should_turn_left || should_turn_right || should_move_on)
4319 if (should_turn_left && should_turn_right && should_move_on)
4320 MovDir[x][y] = (rnd < rnd_value / 3 ? left_dir :
4321 rnd < 2 * rnd_value / 3 ? right_dir :
4323 else if (should_turn_left && should_turn_right)
4324 MovDir[x][y] = (rnd < rnd_value / 2 ? left_dir : right_dir);
4325 else if (should_turn_left && should_move_on)
4326 MovDir[x][y] = (rnd < rnd_value / 2 ? left_dir : old_move_dir);
4327 else if (should_turn_right && should_move_on)
4328 MovDir[x][y] = (rnd < rnd_value / 2 ? right_dir : old_move_dir);
4329 else if (should_turn_left)
4330 MovDir[x][y] = left_dir;
4331 else if (should_turn_right)
4332 MovDir[x][y] = right_dir;
4333 else if (should_move_on)
4334 MovDir[x][y] = old_move_dir;
4336 else if (can_move_on && rnd > rnd_value / 8)
4337 MovDir[x][y] = old_move_dir;
4338 else if (can_turn_left && can_turn_right)
4339 MovDir[x][y] = (rnd < rnd_value / 2 ? left_dir : right_dir);
4340 else if (can_turn_left && rnd > rnd_value / 8)
4341 MovDir[x][y] = left_dir;
4342 else if (can_turn_right && rnd > rnd_value/8)
4343 MovDir[x][y] = right_dir;
4345 MovDir[x][y] = back_dir;
4347 xx = x + move_xy[MovDir[x][y]].x;
4348 yy = y + move_xy[MovDir[x][y]].y;
4350 if (!IS_FREE(xx, yy) && !IS_FOOD_PIG(Feld[xx][yy]))
4351 MovDir[x][y] = old_move_dir;
4355 else if (element == EL_DRAGON)
4357 boolean can_turn_left = DRAGON_CAN_ENTER_FIELD(element, left_x, left_y);
4358 boolean can_turn_right = DRAGON_CAN_ENTER_FIELD(element, right_x, right_y);
4359 boolean can_move_on = DRAGON_CAN_ENTER_FIELD(element, move_x, move_y);
4361 int rnd = RND(rnd_value);
4364 if (FrameCounter < 1 && x == 0 && y == 29)
4365 printf(":2: %d/%d: %d [%d]\n", x, y, MovDir[x][y], FrameCounter);
4368 if (can_move_on && rnd > rnd_value / 8)
4369 MovDir[x][y] = old_move_dir;
4370 else if (can_turn_left && can_turn_right)
4371 MovDir[x][y] = (rnd < rnd_value / 2 ? left_dir : right_dir);
4372 else if (can_turn_left && rnd > rnd_value / 8)
4373 MovDir[x][y] = left_dir;
4374 else if (can_turn_right && rnd > rnd_value / 8)
4375 MovDir[x][y] = right_dir;
4377 MovDir[x][y] = back_dir;
4379 xx = x + move_xy[MovDir[x][y]].x;
4380 yy = y + move_xy[MovDir[x][y]].y;
4383 if (FrameCounter < 1 && x == 0 && y == 29)
4384 printf(":3: %d/%d: %d (%d/%d: %d) [%d]\n", x, y, MovDir[x][y],
4385 xx, yy, Feld[xx][yy],
4390 if (!IN_LEV_FIELD_AND_IS_FREE(xx, yy))
4391 MovDir[x][y] = old_move_dir;
4393 if (!IS_FREE(xx, yy))
4394 MovDir[x][y] = old_move_dir;
4398 if (FrameCounter < 1 && x == 0 && y == 29)
4399 printf(":4: %d/%d: %d [%d]\n", x, y, MovDir[x][y], FrameCounter);
4404 else if (element == EL_MOLE)
4406 boolean can_move_on =
4407 (MOLE_CAN_ENTER_FIELD(element, move_x, move_y,
4408 IS_AMOEBOID(Feld[move_x][move_y]) ||
4409 Feld[move_x][move_y] == EL_AMOEBA_SHRINKING));
4412 boolean can_turn_left =
4413 (MOLE_CAN_ENTER_FIELD(element, left_x, left_y,
4414 IS_AMOEBOID(Feld[left_x][left_y])));
4416 boolean can_turn_right =
4417 (MOLE_CAN_ENTER_FIELD(element, right_x, right_y,
4418 IS_AMOEBOID(Feld[right_x][right_y])));
4420 if (can_turn_left && can_turn_right)
4421 MovDir[x][y] = (RND(2) ? left_dir : right_dir);
4422 else if (can_turn_left)
4423 MovDir[x][y] = left_dir;
4425 MovDir[x][y] = right_dir;
4428 if (MovDir[x][y] != old_move_dir)
4431 else if (element == EL_BALLOON)
4433 MovDir[x][y] = game.balloon_dir;
4436 else if (element == EL_SPRING)
4439 if (MovDir[x][y] & MV_HORIZONTAL &&
4440 !SPRING_CAN_ENTER_FIELD(element, move_x, move_y))
4441 MovDir[x][y] = MV_NO_MOVING;
4443 if (MovDir[x][y] & MV_HORIZONTAL &&
4444 (!SPRING_CAN_ENTER_FIELD(element, move_x, move_y) ||
4445 SPRING_CAN_ENTER_FIELD(element, x, y + 1)))
4446 MovDir[x][y] = MV_NO_MOVING;
4451 else if (element == EL_ROBOT ||
4452 element == EL_SATELLITE ||
4453 element == EL_PENGUIN)
4455 int attr_x = -1, attr_y = -1;
4466 for (i = 0; i < MAX_PLAYERS; i++)
4468 struct PlayerInfo *player = &stored_player[i];
4469 int jx = player->jx, jy = player->jy;
4471 if (!player->active)
4475 ABS(jx - x) + ABS(jy - y) < ABS(attr_x - x) + ABS(attr_y - y))
4483 if (element == EL_ROBOT && ZX >= 0 && ZY >= 0)
4489 if (element == EL_PENGUIN)
4492 static int xy[4][2] =
4500 for (i = 0; i < NUM_DIRECTIONS; i++)
4502 int ex = x + xy[i][0];
4503 int ey = y + xy[i][1];
4505 if (IN_LEV_FIELD(ex, ey) && Feld[ex][ey] == EL_EXIT_OPEN)
4514 MovDir[x][y] = MV_NO_MOVING;
4516 MovDir[x][y] |= (AllPlayersGone ? MV_RIGHT : MV_LEFT);
4517 else if (attr_x > x)
4518 MovDir[x][y] |= (AllPlayersGone ? MV_LEFT : MV_RIGHT);
4520 MovDir[x][y] |= (AllPlayersGone ? MV_DOWN : MV_UP);
4521 else if (attr_y > y)
4522 MovDir[x][y] |= (AllPlayersGone ? MV_UP : MV_DOWN);
4524 if (element == EL_ROBOT)
4528 if (MovDir[x][y] & MV_HORIZONTAL && MovDir[x][y] & MV_VERTICAL)
4529 MovDir[x][y] &= (RND(2) ? MV_HORIZONTAL : MV_VERTICAL);
4530 Moving2Blocked(x, y, &newx, &newy);
4532 if (IN_LEV_FIELD(newx, newy) && IS_FREE_OR_PLAYER(newx, newy))
4533 MovDelay[x][y] = 8 + 8 * !RND(3);
4535 MovDelay[x][y] = 16;
4537 else if (element == EL_PENGUIN)
4543 if (MovDir[x][y] & MV_HORIZONTAL && MovDir[x][y] & MV_VERTICAL)
4545 boolean first_horiz = RND(2);
4546 int new_move_dir = MovDir[x][y];
4549 new_move_dir & (first_horiz ? MV_HORIZONTAL : MV_VERTICAL);
4550 Moving2Blocked(x, y, &newx, &newy);
4552 if (PENGUIN_CAN_ENTER_FIELD(EL_PENGUIN, newx, newy))
4556 new_move_dir & (!first_horiz ? MV_HORIZONTAL : MV_VERTICAL);
4557 Moving2Blocked(x, y, &newx, &newy);
4559 if (PENGUIN_CAN_ENTER_FIELD(EL_PENGUIN, newx, newy))
4562 MovDir[x][y] = old_move_dir;
4566 else /* (element == EL_SATELLITE) */
4572 if (MovDir[x][y] & MV_HORIZONTAL && MovDir[x][y] & MV_VERTICAL)
4574 boolean first_horiz = RND(2);
4575 int new_move_dir = MovDir[x][y];
4578 new_move_dir & (first_horiz ? MV_HORIZONTAL : MV_VERTICAL);
4579 Moving2Blocked(x, y, &newx, &newy);
4581 if (SATELLITE_CAN_ENTER_FIELD(newx, newy))
4585 new_move_dir & (!first_horiz ? MV_HORIZONTAL : MV_VERTICAL);
4586 Moving2Blocked(x, y, &newx, &newy);
4588 if (SATELLITE_CAN_ENTER_FIELD(newx, newy))
4591 MovDir[x][y] = old_move_dir;
4596 else if (move_pattern == MV_TURNING_LEFT ||
4597 move_pattern == MV_TURNING_RIGHT ||
4598 move_pattern == MV_TURNING_LEFT_RIGHT ||
4599 move_pattern == MV_TURNING_RIGHT_LEFT ||
4600 move_pattern == MV_TURNING_RANDOM ||
4601 move_pattern == MV_ALL_DIRECTIONS)
4603 boolean can_turn_left =
4604 CUSTOM_ELEMENT_CAN_ENTER_FIELD(element, left_x, left_y);
4605 boolean can_turn_right =
4606 CUSTOM_ELEMENT_CAN_ENTER_FIELD(element, right_x,right_y);
4608 if (move_pattern == MV_TURNING_LEFT)
4609 MovDir[x][y] = left_dir;
4610 else if (move_pattern == MV_TURNING_RIGHT)
4611 MovDir[x][y] = right_dir;
4612 else if (move_pattern == MV_TURNING_LEFT_RIGHT)
4613 MovDir[x][y] = (can_turn_left || !can_turn_right ? left_dir : right_dir);
4614 else if (move_pattern == MV_TURNING_RIGHT_LEFT)
4615 MovDir[x][y] = (can_turn_right || !can_turn_left ? right_dir : left_dir);
4616 else if (move_pattern == MV_TURNING_RANDOM)
4617 MovDir[x][y] = (can_turn_left && !can_turn_right ? left_dir :
4618 can_turn_right && !can_turn_left ? right_dir :
4619 RND(2) ? left_dir : right_dir);
4620 else if (can_turn_left && can_turn_right)
4621 MovDir[x][y] = (RND(3) ? (RND(2) ? left_dir : right_dir) : back_dir);
4622 else if (can_turn_left)
4623 MovDir[x][y] = (RND(2) ? left_dir : back_dir);
4624 else if (can_turn_right)
4625 MovDir[x][y] = (RND(2) ? right_dir : back_dir);
4627 MovDir[x][y] = back_dir;
4629 MovDelay[x][y] = GET_NEW_MOVE_DELAY(element);
4631 else if (move_pattern == MV_HORIZONTAL ||
4632 move_pattern == MV_VERTICAL)
4634 if (move_pattern & old_move_dir)
4635 MovDir[x][y] = back_dir;
4636 else if (move_pattern == MV_HORIZONTAL)
4637 MovDir[x][y] = (RND(2) ? MV_LEFT : MV_RIGHT);
4638 else if (move_pattern == MV_VERTICAL)
4639 MovDir[x][y] = (RND(2) ? MV_UP : MV_DOWN);
4641 MovDelay[x][y] = GET_NEW_MOVE_DELAY(element);
4643 else if (move_pattern & MV_ANY_DIRECTION)
4645 MovDir[x][y] = move_pattern;
4646 MovDelay[x][y] = GET_NEW_MOVE_DELAY(element);
4648 else if (move_pattern == MV_ALONG_LEFT_SIDE)
4650 if (CUSTOM_ELEMENT_CAN_ENTER_FIELD(element, left_x, left_y))
4651 MovDir[x][y] = left_dir;
4652 else if (!CUSTOM_ELEMENT_CAN_ENTER_FIELD(element, move_x, move_y))
4653 MovDir[x][y] = right_dir;
4655 if (MovDir[x][y] != old_move_dir)
4656 MovDelay[x][y] = GET_NEW_MOVE_DELAY(element);
4658 else if (move_pattern == MV_ALONG_RIGHT_SIDE)
4660 if (CUSTOM_ELEMENT_CAN_ENTER_FIELD(element, right_x, right_y))
4661 MovDir[x][y] = right_dir;
4662 else if (!CUSTOM_ELEMENT_CAN_ENTER_FIELD(element, move_x, move_y))
4663 MovDir[x][y] = left_dir;
4665 if (MovDir[x][y] != old_move_dir)
4666 MovDelay[x][y] = GET_NEW_MOVE_DELAY(element);
4668 else if (move_pattern == MV_TOWARDS_PLAYER ||
4669 move_pattern == MV_AWAY_FROM_PLAYER)
4671 int attr_x = -1, attr_y = -1;
4673 boolean move_away = (move_pattern == MV_AWAY_FROM_PLAYER);
4684 for (i = 0; i < MAX_PLAYERS; i++)
4686 struct PlayerInfo *player = &stored_player[i];
4687 int jx = player->jx, jy = player->jy;
4689 if (!player->active)
4693 ABS(jx - x) + ABS(jy - y) < ABS(attr_x - x) + ABS(attr_y - y))
4701 MovDir[x][y] = MV_NO_MOVING;
4703 MovDir[x][y] |= (move_away ? MV_RIGHT : MV_LEFT);
4704 else if (attr_x > x)
4705 MovDir[x][y] |= (move_away ? MV_LEFT : MV_RIGHT);
4707 MovDir[x][y] |= (move_away ? MV_DOWN : MV_UP);
4708 else if (attr_y > y)
4709 MovDir[x][y] |= (move_away ? MV_UP : MV_DOWN);
4711 MovDelay[x][y] = GET_NEW_MOVE_DELAY(element);
4713 if (MovDir[x][y] & MV_HORIZONTAL && MovDir[x][y] & MV_VERTICAL)
4715 boolean first_horiz = RND(2);
4716 int new_move_dir = MovDir[x][y];
4719 new_move_dir & (first_horiz ? MV_HORIZONTAL : MV_VERTICAL);
4720 Moving2Blocked(x, y, &newx, &newy);
4722 if (CUSTOM_ELEMENT_CAN_ENTER_FIELD(element, newx, newy))
4726 new_move_dir & (!first_horiz ? MV_HORIZONTAL : MV_VERTICAL);
4727 Moving2Blocked(x, y, &newx, &newy);
4729 if (CUSTOM_ELEMENT_CAN_ENTER_FIELD(element, newx, newy))
4732 MovDir[x][y] = old_move_dir;
4735 else if (move_pattern == MV_WHEN_PUSHED ||
4736 move_pattern == MV_WHEN_DROPPED)
4738 if (!CUSTOM_ELEMENT_CAN_ENTER_FIELD(element, move_x, move_y))
4739 MovDir[x][y] = MV_NO_MOVING;
4743 else if (move_pattern & MV_MAZE_RUNNER_STYLE)
4745 static int test_xy[7][2] =
4755 static int test_dir[7] =
4765 boolean hunter_mode = (move_pattern == MV_MAZE_HUNTER);
4766 int move_preference = -1000000; /* start with very low preference */
4767 int new_move_dir = MV_NO_MOVING;
4768 int start_test = RND(4);
4771 for (i = 0; i < NUM_DIRECTIONS; i++)
4773 int move_dir = test_dir[start_test + i];
4774 int move_dir_preference;
4776 xx = x + test_xy[start_test + i][0];
4777 yy = y + test_xy[start_test + i][1];
4779 if (hunter_mode && IN_LEV_FIELD(xx, yy) &&
4780 (IS_PLAYER(xx, yy) || Feld[xx][yy] == EL_PLAYER_IS_LEAVING))
4782 new_move_dir = move_dir;
4787 if (!CUSTOM_ELEMENT_CAN_ENTER_FIELD(element, xx, yy))
4790 move_dir_preference = -1 * RunnerVisit[xx][yy];
4791 if (hunter_mode && PlayerVisit[xx][yy] > 0)
4792 move_dir_preference = PlayerVisit[xx][yy];
4794 if (move_dir_preference > move_preference)
4796 /* prefer field that has not been visited for the longest time */
4797 move_preference = move_dir_preference;
4798 new_move_dir = move_dir;
4800 else if (move_dir_preference == move_preference &&
4801 move_dir == old_move_dir)
4803 /* prefer last direction when all directions are preferred equally */
4804 move_preference = move_dir_preference;
4805 new_move_dir = move_dir;
4809 MovDir[x][y] = new_move_dir;
4810 if (old_move_dir != new_move_dir)
4815 static void TurnRound(int x, int y)
4817 int direction = MovDir[x][y];
4820 GfxDir[x][y] = MovDir[x][y];
4826 GfxDir[x][y] = MovDir[x][y];
4829 if (direction != MovDir[x][y])
4834 GfxAction[x][y] = ACTION_TURNING_FROM_LEFT + MV_DIR_BIT(direction);
4837 GfxAction[x][y] = ACTION_WAITING;
4841 static boolean JustBeingPushed(int x, int y)
4845 for (i = 0; i < MAX_PLAYERS; i++)
4847 struct PlayerInfo *player = &stored_player[i];
4849 if (player->active && player->is_pushing && player->MovPos)
4851 int next_jx = player->jx + (player->jx - player->last_jx);
4852 int next_jy = player->jy + (player->jy - player->last_jy);
4854 if (x == next_jx && y == next_jy)
4862 void StartMoving(int x, int y)
4865 boolean use_spring_bug = (game.engine_version < VERSION_IDENT(2,2,0,0));
4867 boolean started_moving = FALSE; /* some elements can fall _and_ move */
4868 int element = Feld[x][y];
4874 if (MovDelay[x][y] == 0)
4875 GfxAction[x][y] = ACTION_DEFAULT;
4877 /* !!! this should be handled more generic (not only for mole) !!! */
4878 if (element != EL_MOLE && GfxAction[x][y] != ACTION_DIGGING)
4879 GfxAction[x][y] = ACTION_DEFAULT;
4882 if (CAN_FALL(element) && y < lev_fieldy - 1)
4884 if ((x > 0 && IS_PLAYER(x - 1, y)) ||
4885 (x < lev_fieldx - 1 && IS_PLAYER(x + 1, y)))
4886 if (JustBeingPushed(x, y))
4889 if (element == EL_QUICKSAND_FULL)
4891 if (IS_FREE(x, y + 1))
4893 InitMovingField(x, y, MV_DOWN);
4894 started_moving = TRUE;
4896 Feld[x][y] = EL_QUICKSAND_EMPTYING;
4897 Store[x][y] = EL_ROCK;
4899 PlayLevelSoundAction(x, y, ACTION_EMPTYING);
4901 PlayLevelSound(x, y, SND_QUICKSAND_EMPTYING);
4904 else if (Feld[x][y + 1] == EL_QUICKSAND_EMPTY)
4906 if (!MovDelay[x][y])
4907 MovDelay[x][y] = TILEY + 1;
4916 Feld[x][y] = EL_QUICKSAND_EMPTY;
4917 Feld[x][y + 1] = EL_QUICKSAND_FULL;
4918 Store[x][y + 1] = Store[x][y];
4921 PlayLevelSoundAction(x, y, ACTION_FILLING);
4923 PlayLevelSound(x, y, SND_QUICKSAND_FILLING);
4927 else if ((element == EL_ROCK || element == EL_BD_ROCK) &&
4928 Feld[x][y + 1] == EL_QUICKSAND_EMPTY)
4930 InitMovingField(x, y, MV_DOWN);
4931 started_moving = TRUE;
4933 Feld[x][y] = EL_QUICKSAND_FILLING;
4934 Store[x][y] = element;
4936 PlayLevelSoundAction(x, y, ACTION_FILLING);
4938 PlayLevelSound(x, y, SND_QUICKSAND_FILLING);
4941 else if (element == EL_MAGIC_WALL_FULL)
4943 if (IS_FREE(x, y + 1))
4945 InitMovingField(x, y, MV_DOWN);
4946 started_moving = TRUE;
4948 Feld[x][y] = EL_MAGIC_WALL_EMPTYING;
4949 Store[x][y] = EL_CHANGED(Store[x][y]);
4951 else if (Feld[x][y + 1] == EL_MAGIC_WALL_ACTIVE)
4953 if (!MovDelay[x][y])
4954 MovDelay[x][y] = TILEY/4 + 1;
4963 Feld[x][y] = EL_MAGIC_WALL_ACTIVE;
4964 Feld[x][y + 1] = EL_MAGIC_WALL_FULL;
4965 Store[x][y + 1] = EL_CHANGED(Store[x][y]);
4969 else if (element == EL_BD_MAGIC_WALL_FULL)
4971 if (IS_FREE(x, y + 1))
4973 InitMovingField(x, y, MV_DOWN);
4974 started_moving = TRUE;
4976 Feld[x][y] = EL_BD_MAGIC_WALL_EMPTYING;
4977 Store[x][y] = EL_CHANGED2(Store[x][y]);
4979 else if (Feld[x][y + 1] == EL_BD_MAGIC_WALL_ACTIVE)
4981 if (!MovDelay[x][y])
4982 MovDelay[x][y] = TILEY/4 + 1;
4991 Feld[x][y] = EL_BD_MAGIC_WALL_ACTIVE;
4992 Feld[x][y + 1] = EL_BD_MAGIC_WALL_FULL;
4993 Store[x][y + 1] = EL_CHANGED2(Store[x][y]);
4997 else if (CAN_PASS_MAGIC_WALL(element) &&
4998 (Feld[x][y + 1] == EL_MAGIC_WALL_ACTIVE ||
4999 Feld[x][y + 1] == EL_BD_MAGIC_WALL_ACTIVE))
5001 InitMovingField(x, y, MV_DOWN);
5002 started_moving = TRUE;
5005 (Feld[x][y + 1] == EL_MAGIC_WALL_ACTIVE ? EL_MAGIC_WALL_FILLING :
5006 EL_BD_MAGIC_WALL_FILLING);
5007 Store[x][y] = element;
5010 else if (CAN_SMASH(element) && Feld[x][y + 1] == EL_ACID)
5012 else if (CAN_FALL(element) && Feld[x][y + 1] == EL_ACID)
5015 SplashAcid(x, y + 1);
5017 InitMovingField(x, y, MV_DOWN);
5018 started_moving = TRUE;
5020 Store[x][y] = EL_ACID;
5022 /* !!! TEST !!! better use "_FALLING" etc. !!! */
5023 GfxAction[x][y + 1] = ACTION_ACTIVE;
5027 else if ((game.engine_version < VERSION_IDENT(2,2,0,7) &&
5028 CAN_SMASH(element) && WasJustMoving[x][y] && !Pushed[x][y + 1] &&
5029 (Feld[x][y + 1] == EL_BLOCKED)) ||
5030 (game.engine_version >= VERSION_IDENT(3,0,7,0) &&
5031 CAN_SMASH(element) && WasJustFalling[x][y] &&
5032 (Feld[x][y + 1] == EL_BLOCKED || IS_PLAYER(x, y + 1))))
5036 else if (game.engine_version < VERSION_IDENT(2,2,0,7) &&
5037 CAN_SMASH(element) && Feld[x][y + 1] == EL_BLOCKED &&
5038 WasJustMoving[x][y] && !Pushed[x][y + 1])
5040 else if (CAN_SMASH(element) && Feld[x][y + 1] == EL_BLOCKED &&
5041 WasJustMoving[x][y])
5046 /* this is needed for a special case not covered by calling "Impact()"
5047 from "ContinueMoving()": if an element moves to a tile directly below
5048 another element which was just falling on that tile (which was empty
5049 in the previous frame), the falling element above would just stop
5050 instead of smashing the element below (in previous version, the above
5051 element was just checked for "moving" instead of "falling", resulting
5052 in incorrect smashes caused by horizontal movement of the above
5053 element; also, the case of the player being the element to smash was
5054 simply not covered here... :-/ ) */
5057 WasJustMoving[x][y] = 0;
5058 WasJustFalling[x][y] = 0;
5063 else if (IS_FREE(x, y + 1) && element == EL_SPRING && level.use_spring_bug)
5065 if (MovDir[x][y] == MV_NO_MOVING)
5067 InitMovingField(x, y, MV_DOWN);
5068 started_moving = TRUE;
5071 else if (IS_FREE(x, y + 1) || Feld[x][y + 1] == EL_DIAMOND_BREAKING)
5073 if (WasJustFalling[x][y]) /* prevent animation from being restarted */
5074 MovDir[x][y] = MV_DOWN;
5076 InitMovingField(x, y, MV_DOWN);
5077 started_moving = TRUE;
5079 else if (element == EL_AMOEBA_DROP)
5081 Feld[x][y] = EL_AMOEBA_GROWING;
5082 Store[x][y] = EL_AMOEBA_WET;
5084 /* Store[x][y + 1] must be zero, because:
5085 (EL_QUICKSAND_FULL -> EL_ROCK): Store[x][y + 1] == EL_QUICKSAND_EMPTY
5088 #if OLD_GAME_BEHAVIOUR
5089 else if (IS_SLIPPERY(Feld[x][y + 1]) && !Store[x][y + 1])
5091 else if (IS_SLIPPERY(Feld[x][y + 1]) && !Store[x][y + 1] &&
5092 !IS_FALLING(x, y + 1) && !WasJustMoving[x][y + 1] &&
5093 element != EL_DX_SUPABOMB)
5096 else if (((IS_SLIPPERY(Feld[x][y + 1]) && !IS_PLAYER(x, y + 1)) ||
5097 (IS_EM_SLIPPERY_WALL(Feld[x][y + 1]) && IS_GEM(element))) &&
5098 !IS_FALLING(x, y + 1) && !WasJustMoving[x][y + 1] &&
5099 element != EL_DX_SUPABOMB && element != EL_SP_DISK_ORANGE)
5102 boolean can_fall_left = (x > 0 && IS_FREE(x - 1, y) &&
5103 (IS_FREE(x - 1, y + 1) ||
5104 Feld[x - 1][y + 1] == EL_ACID));
5105 boolean can_fall_right = (x < lev_fieldx - 1 && IS_FREE(x + 1, y) &&
5106 (IS_FREE(x + 1, y + 1) ||
5107 Feld[x + 1][y + 1] == EL_ACID));
5108 boolean can_fall_any = (can_fall_left || can_fall_right);
5109 boolean can_fall_both = (can_fall_left && can_fall_right);
5111 if (can_fall_any && IS_CUSTOM_ELEMENT(Feld[x][y + 1]))
5113 int slippery_type = element_info[Feld[x][y + 1]].slippery_type;
5115 if (slippery_type == SLIPPERY_ONLY_LEFT)
5116 can_fall_right = FALSE;
5117 else if (slippery_type == SLIPPERY_ONLY_RIGHT)
5118 can_fall_left = FALSE;
5119 else if (slippery_type == SLIPPERY_ANY_LEFT_RIGHT && can_fall_both)
5120 can_fall_right = FALSE;
5121 else if (slippery_type == SLIPPERY_ANY_RIGHT_LEFT && can_fall_both)
5122 can_fall_left = FALSE;
5124 can_fall_any = (can_fall_left || can_fall_right);
5125 can_fall_both = (can_fall_left && can_fall_right);
5130 if (can_fall_both &&
5131 (game.emulation != EMU_BOULDERDASH &&
5132 element != EL_BD_ROCK && element != EL_BD_DIAMOND))
5133 can_fall_left = !(can_fall_right = RND(2));
5135 InitMovingField(x, y, can_fall_left ? MV_LEFT : MV_RIGHT);
5136 started_moving = TRUE;
5140 else if (IS_BELT_ACTIVE(Feld[x][y + 1]) && !CAN_MOVE(element))
5142 else if (IS_BELT_ACTIVE(Feld[x][y + 1]))
5145 boolean left_is_free = (x > 0 && IS_FREE(x - 1, y));
5146 boolean right_is_free = (x < lev_fieldx - 1 && IS_FREE(x + 1, y));
5147 int belt_nr = getBeltNrFromBeltActiveElement(Feld[x][y + 1]);
5148 int belt_dir = game.belt_dir[belt_nr];
5150 if ((belt_dir == MV_LEFT && left_is_free) ||
5151 (belt_dir == MV_RIGHT && right_is_free))
5154 int nextx = (belt_dir == MV_LEFT ? x - 1 : x + 1);
5157 InitMovingField(x, y, belt_dir);
5158 started_moving = TRUE;
5161 Pushed[x][y] = TRUE;
5162 Pushed[nextx][y] = TRUE;
5165 GfxAction[x][y] = ACTION_DEFAULT;
5169 MovDir[x][y] = 0; /* if element was moving, stop it */
5174 /* not "else if" because of elements that can fall and move (EL_SPRING) */
5175 if (CAN_MOVE(element) && !started_moving)
5177 int move_pattern = element_info[element].move_pattern;
5180 Moving2Blocked(x, y, &newx, &newy);
5183 if (IS_PUSHABLE(element) && JustBeingPushed(x, y))
5186 if ((element == EL_SATELLITE ||
5187 element == EL_BALLOON ||
5188 element == EL_SPRING)
5189 && JustBeingPushed(x, y))
5194 if (game.engine_version >= VERSION_IDENT(3,1,0,0) &&
5195 WasJustMoving[x][y] && IN_LEV_FIELD(newx, newy) &&
5196 (Feld[newx][newy] == EL_BLOCKED || IS_PLAYER(newx, newy)))
5199 printf("::: element %d '%s' WasJustMoving %d [%d, %d, %d, %d]\n",
5200 element, element_info[element].token_name,
5201 WasJustMoving[x][y],
5202 HAS_ANY_CHANGE_EVENT(element, CE_HITTING_SOMETHING),
5203 HAS_ANY_CHANGE_EVENT(element, CE_HIT_BY_SOMETHING),
5204 HAS_ANY_CHANGE_EVENT(element, CE_OTHER_IS_HITTING),
5205 HAS_ANY_CHANGE_EVENT(element, CE_OTHER_GETS_HIT));
5209 WasJustMoving[x][y] = 0;
5212 TestIfElementHitsCustomElement(x, y, MovDir[x][y]);
5215 if (Feld[x][y] != element) /* element has changed */
5217 element = Feld[x][y];
5218 move_pattern = element_info[element].move_pattern;
5220 if (!CAN_MOVE(element))
5224 if (Feld[x][y] != element) /* element has changed */
5232 if (element == EL_SPRING && MovDir[x][y] == MV_DOWN)
5233 Feld[x][y + 1] = EL_EMPTY; /* was set to EL_BLOCKED above */
5235 if (element == EL_SPRING && MovDir[x][y] != MV_NO_MOVING)
5237 Moving2Blocked(x, y, &newx, &newy);
5238 if (Feld[newx][newy] == EL_BLOCKED)
5239 Feld[newx][newy] = EL_EMPTY; /* was set to EL_BLOCKED above */
5245 if (FrameCounter < 1 && x == 0 && y == 29)
5246 printf(":1: %d/%d: %d [%d]\n", x, y, MovDir[x][y], FrameCounter);
5249 if (!MovDelay[x][y]) /* start new movement phase */
5251 /* all objects that can change their move direction after each step
5252 (YAMYAM, DARK_YAMYAM and PACMAN go straight until they hit a wall */
5254 if (element != EL_YAMYAM &&
5255 element != EL_DARK_YAMYAM &&
5256 element != EL_PACMAN &&
5257 !(move_pattern & MV_ANY_DIRECTION) &&
5258 move_pattern != MV_TURNING_LEFT &&
5259 move_pattern != MV_TURNING_RIGHT &&
5260 move_pattern != MV_TURNING_LEFT_RIGHT &&
5261 move_pattern != MV_TURNING_RIGHT_LEFT &&
5262 move_pattern != MV_TURNING_RANDOM)
5267 if (FrameCounter < 1 && x == 0 && y == 29)
5268 printf(":9: %d: %d [%d]\n", y, MovDir[x][y], FrameCounter);
5271 if (MovDelay[x][y] && (element == EL_BUG ||
5272 element == EL_SPACESHIP ||
5273 element == EL_SP_SNIKSNAK ||
5274 element == EL_SP_ELECTRON ||
5275 element == EL_MOLE))
5276 DrawLevelField(x, y);
5280 if (MovDelay[x][y]) /* wait some time before next movement */
5285 if (element == EL_YAMYAM)
5288 el_act_dir2img(EL_YAMYAM, ACTION_WAITING, MV_LEFT));
5289 DrawLevelElementAnimation(x, y, element);
5293 if (MovDelay[x][y]) /* element still has to wait some time */
5296 /* !!! PLACE THIS SOMEWHERE AFTER "TurnRound()" !!! */
5297 ResetGfxAnimation(x, y);
5301 if (GfxAction[x][y] != ACTION_WAITING)
5302 printf("::: %d: %d != ACTION_WAITING\n", element, GfxAction[x][y]);
5304 GfxAction[x][y] = ACTION_WAITING;
5308 if (element == EL_ROBOT ||
5310 element == EL_PACMAN ||
5312 element == EL_YAMYAM ||
5313 element == EL_DARK_YAMYAM)
5316 DrawLevelElementAnimation(x, y, element);
5318 DrawLevelElementAnimationIfNeeded(x, y, element);
5320 PlayLevelSoundAction(x, y, ACTION_WAITING);
5322 else if (element == EL_SP_ELECTRON)
5323 DrawLevelElementAnimationIfNeeded(x, y, element);
5324 else if (element == EL_DRAGON)
5327 int dir = MovDir[x][y];
5328 int dx = (dir == MV_LEFT ? -1 : dir == MV_RIGHT ? +1 : 0);
5329 int dy = (dir == MV_UP ? -1 : dir == MV_DOWN ? +1 : 0);
5330 int graphic = (dir == MV_LEFT ? IMG_FLAMES_1_LEFT :
5331 dir == MV_RIGHT ? IMG_FLAMES_1_RIGHT :
5332 dir == MV_UP ? IMG_FLAMES_1_UP :
5333 dir == MV_DOWN ? IMG_FLAMES_1_DOWN : IMG_EMPTY);
5334 int frame = getGraphicAnimationFrame(graphic, GfxFrame[x][y]);
5337 printf("::: %d, %d\n", GfxAction[x][y], GfxFrame[x][y]);
5340 GfxAction[x][y] = ACTION_ATTACKING;
5342 if (IS_PLAYER(x, y))
5343 DrawPlayerField(x, y);
5345 DrawLevelField(x, y);
5347 PlayLevelSoundActionIfLoop(x, y, ACTION_ATTACKING);
5349 for (i = 1; i <= 3; i++)
5351 int xx = x + i * dx;
5352 int yy = y + i * dy;
5353 int sx = SCREENX(xx);
5354 int sy = SCREENY(yy);
5355 int flame_graphic = graphic + (i - 1);
5357 if (!IN_LEV_FIELD(xx, yy) || IS_DRAGONFIRE_PROOF(Feld[xx][yy]))
5362 int flamed = MovingOrBlocked2Element(xx, yy);
5366 if (IS_CLASSIC_ENEMY(flamed) || CAN_EXPLODE_BY_DRAGONFIRE(flamed))
5368 else if (IS_MOVING(xx, yy) || IS_BLOCKED(xx, yy))
5369 RemoveMovingField(xx, yy);
5371 RemoveField(xx, yy);
5373 if (IS_CLASSIC_ENEMY(flamed) || CAN_EXPLODE_BY_DRAGONFIRE(flamed))
5376 RemoveMovingField(xx, yy);
5380 if (ChangeDelay[xx][yy])
5381 printf("::: !!! [%d]\n", (IS_MOVING(xx, yy) ||
5382 Feld[xx][yy] == EL_BLOCKED));
5386 ChangeDelay[xx][yy] = 0;
5388 Feld[xx][yy] = EL_FLAMES;
5389 if (IN_SCR_FIELD(sx, sy))
5391 DrawLevelFieldCrumbledSand(xx, yy);
5392 DrawGraphic(sx, sy, flame_graphic, frame);
5397 if (Feld[xx][yy] == EL_FLAMES)
5398 Feld[xx][yy] = EL_EMPTY;
5399 DrawLevelField(xx, yy);
5404 if (MovDelay[x][y]) /* element still has to wait some time */
5406 PlayLevelSoundAction(x, y, ACTION_WAITING);
5412 /* special case of "moving" animation of waiting elements (FIX THIS !!!);
5413 for all other elements GfxAction will be set by InitMovingField() */
5414 if (element == EL_BD_BUTTERFLY || element == EL_BD_FIREFLY)
5415 GfxAction[x][y] = ACTION_MOVING;
5419 /* now make next step */
5421 Moving2Blocked(x, y, &newx, &newy); /* get next screen position */
5423 if (DONT_COLLIDE_WITH(element) &&
5424 IN_LEV_FIELD(newx, newy) && IS_PLAYER(newx, newy) &&
5425 !PLAYER_ENEMY_PROTECTED(newx, newy))
5428 TestIfBadThingRunsIntoHero(x, y, MovDir[x][y]);
5432 /* player killed by element which is deadly when colliding with */
5434 KillHero(PLAYERINFO(newx, newy));
5441 else if (CAN_MOVE_INTO_ACID(element) &&
5442 IN_LEV_FIELD(newx, newy) && Feld[newx][newy] == EL_ACID &&
5443 (MovDir[x][y] == MV_DOWN ||
5444 game.engine_version >= VERSION_IDENT(3,1,0,0)))
5446 else if (CAN_MOVE_INTO_ACID(element) && MovDir[x][y] == MV_DOWN &&
5447 IN_LEV_FIELD(newx, newy) && Feld[newx][newy] == EL_ACID)
5451 else if ((element == EL_PENGUIN ||
5452 element == EL_ROBOT ||
5453 element == EL_SATELLITE ||
5454 element == EL_BALLOON ||
5455 IS_CUSTOM_ELEMENT(element)) &&
5456 IN_LEV_FIELD(newx, newy) &&
5457 MovDir[x][y] == MV_DOWN && Feld[newx][newy] == EL_ACID)
5460 SplashAcid(newx, newy);
5461 Store[x][y] = EL_ACID;
5463 else if (element == EL_PENGUIN && IN_LEV_FIELD(newx, newy))
5465 if (Feld[newx][newy] == EL_EXIT_OPEN)
5469 DrawLevelField(x, y);
5471 Feld[x][y] = EL_EMPTY;
5472 DrawLevelField(x, y);
5475 PlayLevelSound(newx, newy, SND_PENGUIN_PASSING);
5476 if (IN_SCR_FIELD(SCREENX(newx), SCREENY(newy)))
5477 DrawGraphicThruMask(SCREENX(newx),SCREENY(newy), el2img(element), 0);
5479 local_player->friends_still_needed--;
5480 if (!local_player->friends_still_needed &&
5481 !local_player->GameOver && AllPlayersGone)
5482 local_player->LevelSolved = local_player->GameOver = TRUE;
5486 else if (IS_FOOD_PENGUIN(Feld[newx][newy]))
5488 if (DigField(local_player, x, y, newx, newy, 0,0, DF_DIG) == MF_MOVING)
5489 DrawLevelField(newx, newy);
5491 GfxDir[x][y] = MovDir[x][y] = MV_NO_MOVING;
5493 else if (!IS_FREE(newx, newy))
5495 GfxAction[x][y] = ACTION_WAITING;
5497 if (IS_PLAYER(x, y))
5498 DrawPlayerField(x, y);
5500 DrawLevelField(x, y);
5505 else if (element == EL_PIG && IN_LEV_FIELD(newx, newy))
5507 if (IS_FOOD_PIG(Feld[newx][newy]))
5509 if (IS_MOVING(newx, newy))
5510 RemoveMovingField(newx, newy);
5513 Feld[newx][newy] = EL_EMPTY;
5514 DrawLevelField(newx, newy);
5517 PlayLevelSound(x, y, SND_PIG_DIGGING);
5519 else if (!IS_FREE(newx, newy))
5521 if (IS_PLAYER(x, y))
5522 DrawPlayerField(x, y);
5524 DrawLevelField(x, y);
5533 else if (move_pattern & MV_MAZE_RUNNER_STYLE && IN_LEV_FIELD(newx, newy))
5536 else if (IS_CUSTOM_ELEMENT(element) &&
5537 CUSTOM_ELEMENT_CAN_ENTER_FIELD(element, newx, newy)
5541 !IS_FREE(newx, newy)
5546 int new_element = Feld[newx][newy];
5549 printf("::: '%s' digs '%s' [%d]\n",
5550 element_info[element].token_name,
5551 element_info[Feld[newx][newy]].token_name,
5552 StorePlayer[newx][newy]);
5555 if (!IS_FREE(newx, newy))
5557 int action = (IS_DIGGABLE(new_element) ? ACTION_DIGGING :
5558 IS_COLLECTIBLE(new_element) ? ACTION_COLLECTING :
5561 /* no element can dig solid indestructible elements */
5562 if (IS_INDESTRUCTIBLE(new_element) &&
5563 !IS_DIGGABLE(new_element) &&
5564 !IS_COLLECTIBLE(new_element))
5567 if (AmoebaNr[newx][newy] &&
5568 (new_element == EL_AMOEBA_FULL ||
5569 new_element == EL_BD_AMOEBA ||
5570 new_element == EL_AMOEBA_GROWING))
5572 AmoebaCnt[AmoebaNr[newx][newy]]--;
5573 AmoebaCnt2[AmoebaNr[newx][newy]]--;
5576 if (IS_MOVING(newx, newy))
5577 RemoveMovingField(newx, newy);
5580 RemoveField(newx, newy);
5581 DrawLevelField(newx, newy);
5584 PlayLevelSoundAction(x, y, action);
5589 Store[newx][newy] = EL_EMPTY;
5590 if (IS_EQUAL_OR_IN_GROUP(new_element, MOVE_ENTER_EL(element)))
5591 Store[newx][newy] = element_info[element].move_leave_element;
5593 Store[newx][newy] = EL_EMPTY;
5594 if (IS_EQUAL_OR_IN_GROUP(new_element, MOVE_ENTER_EL(element)) ||
5595 element_info[element].move_leave_type == LEAVE_TYPE_UNLIMITED)
5596 Store[newx][newy] = element_info[element].move_leave_element;
5599 if (IS_EQUAL_OR_IN_GROUP(new_element, MOVE_ENTER_EL(element)))
5600 element_info[element].can_leave_element = TRUE;
5603 if (move_pattern & MV_MAZE_RUNNER_STYLE)
5605 RunnerVisit[x][y] = FrameCounter;
5606 PlayerVisit[x][y] /= 8; /* expire player visit path */
5612 else if (element == EL_DRAGON && IN_LEV_FIELD(newx, newy))
5614 if (!IS_FREE(newx, newy))
5616 if (IS_PLAYER(x, y))
5617 DrawPlayerField(x, y);
5619 DrawLevelField(x, y);
5625 boolean wanna_flame = !RND(10);
5626 int dx = newx - x, dy = newy - y;
5627 int newx1 = newx + 1 * dx, newy1 = newy + 1 * dy;
5628 int newx2 = newx + 2 * dx, newy2 = newy + 2 * dy;
5629 int element1 = (IN_LEV_FIELD(newx1, newy1) ?
5630 MovingOrBlocked2Element(newx1, newy1) : EL_STEELWALL);
5631 int element2 = (IN_LEV_FIELD(newx2, newy2) ?
5632 MovingOrBlocked2Element(newx2, newy2) : EL_STEELWALL);
5635 IS_CLASSIC_ENEMY(element1) ||
5636 IS_CLASSIC_ENEMY(element2)) &&
5637 element1 != EL_DRAGON && element2 != EL_DRAGON &&
5638 element1 != EL_FLAMES && element2 != EL_FLAMES)
5641 ResetGfxAnimation(x, y);
5642 GfxAction[x][y] = ACTION_ATTACKING;
5645 if (IS_PLAYER(x, y))
5646 DrawPlayerField(x, y);
5648 DrawLevelField(x, y);
5650 PlayLevelSound(x, y, SND_DRAGON_ATTACKING);
5652 MovDelay[x][y] = 50;
5656 RemoveField(newx, newy);
5658 Feld[newx][newy] = EL_FLAMES;
5659 if (IN_LEV_FIELD(newx1, newy1) && Feld[newx1][newy1] == EL_EMPTY)
5662 RemoveField(newx1, newy1);
5664 Feld[newx1][newy1] = EL_FLAMES;
5666 if (IN_LEV_FIELD(newx2, newy2) && Feld[newx2][newy2] == EL_EMPTY)
5669 RemoveField(newx2, newy2);
5671 Feld[newx2][newy2] = EL_FLAMES;
5678 else if (element == EL_YAMYAM && IN_LEV_FIELD(newx, newy) &&
5679 Feld[newx][newy] == EL_DIAMOND)
5681 if (IS_MOVING(newx, newy))
5682 RemoveMovingField(newx, newy);
5685 Feld[newx][newy] = EL_EMPTY;
5686 DrawLevelField(newx, newy);
5689 PlayLevelSound(x, y, SND_YAMYAM_DIGGING);
5691 else if (element == EL_DARK_YAMYAM && IN_LEV_FIELD(newx, newy) &&
5692 IS_FOOD_DARK_YAMYAM(Feld[newx][newy]))
5694 if (AmoebaNr[newx][newy])
5696 AmoebaCnt2[AmoebaNr[newx][newy]]--;
5697 if (Feld[newx][newy] == EL_AMOEBA_FULL ||
5698 Feld[newx][newy] == EL_BD_AMOEBA)
5699 AmoebaCnt[AmoebaNr[newx][newy]]--;
5704 if (IS_MOVING(newx, newy) || IS_BLOCKED(newx, newy))
5706 if (IS_MOVING(newx, newy))
5709 RemoveMovingField(newx, newy);
5713 Feld[newx][newy] = EL_EMPTY;
5714 DrawLevelField(newx, newy);
5717 PlayLevelSound(x, y, SND_DARK_YAMYAM_DIGGING);
5719 else if ((element == EL_PACMAN || element == EL_MOLE)
5720 && IN_LEV_FIELD(newx, newy) && IS_AMOEBOID(Feld[newx][newy]))
5722 if (AmoebaNr[newx][newy])
5724 AmoebaCnt2[AmoebaNr[newx][newy]]--;
5725 if (Feld[newx][newy] == EL_AMOEBA_FULL ||
5726 Feld[newx][newy] == EL_BD_AMOEBA)
5727 AmoebaCnt[AmoebaNr[newx][newy]]--;
5730 if (element == EL_MOLE)
5732 Feld[newx][newy] = EL_AMOEBA_SHRINKING;
5733 PlayLevelSound(x, y, SND_MOLE_DIGGING);
5735 ResetGfxAnimation(x, y);
5736 GfxAction[x][y] = ACTION_DIGGING;
5737 DrawLevelField(x, y);
5739 MovDelay[newx][newy] = 0; /* start amoeba shrinking delay */
5741 return; /* wait for shrinking amoeba */
5743 else /* element == EL_PACMAN */
5745 Feld[newx][newy] = EL_EMPTY;
5746 DrawLevelField(newx, newy);
5747 PlayLevelSound(x, y, SND_PACMAN_DIGGING);
5750 else if (element == EL_MOLE && IN_LEV_FIELD(newx, newy) &&
5751 (Feld[newx][newy] == EL_AMOEBA_SHRINKING ||
5752 (Feld[newx][newy] == EL_EMPTY && Stop[newx][newy])))
5754 /* wait for shrinking amoeba to completely disappear */
5757 else if (!IN_LEV_FIELD(newx, newy) || !IS_FREE(newx, newy))
5759 /* object was running against a wall */
5764 if (GFX_ELEMENT(element) != EL_SAND) /* !!! FIX THIS (crumble) !!! */
5765 DrawLevelElementAnimation(x, y, element);
5767 if (element == EL_BUG ||
5768 element == EL_SPACESHIP ||
5769 element == EL_SP_SNIKSNAK)
5770 DrawLevelField(x, y);
5771 else if (element == EL_MOLE)
5772 DrawLevelField(x, y);
5773 else if (element == EL_BD_BUTTERFLY ||
5774 element == EL_BD_FIREFLY)
5775 DrawLevelElementAnimationIfNeeded(x, y, element);
5776 else if (element == EL_SATELLITE)
5777 DrawLevelElementAnimationIfNeeded(x, y, element);
5778 else if (element == EL_SP_ELECTRON)
5779 DrawLevelElementAnimationIfNeeded(x, y, element);
5782 if (DONT_TOUCH(element))
5783 TestIfBadThingTouchesHero(x, y);
5786 PlayLevelSoundAction(x, y, ACTION_WAITING);
5792 InitMovingField(x, y, MovDir[x][y]);
5794 PlayLevelSoundAction(x, y, ACTION_MOVING);
5798 ContinueMoving(x, y);
5801 void ContinueMoving(int x, int y)
5803 int element = Feld[x][y];
5804 int stored = Store[x][y];
5805 struct ElementInfo *ei = &element_info[element];
5806 int direction = MovDir[x][y];
5807 int dx = (direction == MV_LEFT ? -1 : direction == MV_RIGHT ? +1 : 0);
5808 int dy = (direction == MV_UP ? -1 : direction == MV_DOWN ? +1 : 0);
5809 int newx = x + dx, newy = y + dy;
5811 int nextx = newx + dx, nexty = newy + dy;
5814 boolean pushed_by_player = (Pushed[x][y] && IS_PLAYER(x, y));
5815 boolean pushed_by_conveyor = (Pushed[x][y] && !IS_PLAYER(x, y));
5817 boolean pushed_by_player = Pushed[x][y];
5820 MovPos[x][y] += getElementMoveStepsize(x, y);
5823 if (pushed_by_player && IS_PLAYER(x, y))
5825 /* special case: moving object pushed by player */
5826 MovPos[x][y] = SIGN(MovPos[x][y]) * (TILEX - ABS(PLAYERINFO(x,y)->MovPos));
5829 if (pushed_by_player) /* special case: moving object pushed by player */
5830 MovPos[x][y] = SIGN(MovPos[x][y]) * (TILEX - ABS(PLAYERINFO(x,y)->MovPos));
5833 if (ABS(MovPos[x][y]) < TILEX)
5835 DrawLevelField(x, y);
5837 return; /* element is still moving */
5840 /* element reached destination field */
5842 Feld[x][y] = EL_EMPTY;
5843 Feld[newx][newy] = element;
5844 MovPos[x][y] = 0; /* force "not moving" for "crumbled sand" */
5846 if (element == EL_MOLE)
5848 Feld[x][y] = EL_SAND;
5850 DrawLevelFieldCrumbledSandNeighbours(x, y);
5852 else if (element == EL_QUICKSAND_FILLING)
5854 element = Feld[newx][newy] = get_next_element(element);
5855 Store[newx][newy] = Store[x][y];
5857 else if (element == EL_QUICKSAND_EMPTYING)
5859 Feld[x][y] = get_next_element(element);
5860 element = Feld[newx][newy] = Store[x][y];
5862 else if (element == EL_MAGIC_WALL_FILLING)
5864 element = Feld[newx][newy] = get_next_element(element);
5865 if (!game.magic_wall_active)
5866 element = Feld[newx][newy] = EL_MAGIC_WALL_DEAD;
5867 Store[newx][newy] = Store[x][y];
5869 else if (element == EL_MAGIC_WALL_EMPTYING)
5871 Feld[x][y] = get_next_element(element);
5872 if (!game.magic_wall_active)
5873 Feld[x][y] = EL_MAGIC_WALL_DEAD;
5874 element = Feld[newx][newy] = Store[x][y];
5876 else if (element == EL_BD_MAGIC_WALL_FILLING)
5878 element = Feld[newx][newy] = get_next_element(element);
5879 if (!game.magic_wall_active)
5880 element = Feld[newx][newy] = EL_BD_MAGIC_WALL_DEAD;
5881 Store[newx][newy] = Store[x][y];
5883 else if (element == EL_BD_MAGIC_WALL_EMPTYING)
5885 Feld[x][y] = get_next_element(element);
5886 if (!game.magic_wall_active)
5887 Feld[x][y] = EL_BD_MAGIC_WALL_DEAD;
5888 element = Feld[newx][newy] = Store[x][y];
5890 else if (element == EL_AMOEBA_DROPPING)
5892 Feld[x][y] = get_next_element(element);
5893 element = Feld[newx][newy] = Store[x][y];
5895 else if (element == EL_SOKOBAN_OBJECT)
5898 Feld[x][y] = Back[x][y];
5900 if (Back[newx][newy])
5901 Feld[newx][newy] = EL_SOKOBAN_FIELD_FULL;
5903 Back[x][y] = Back[newx][newy] = 0;
5905 else if (Store[x][y] == EL_ACID)
5907 element = Feld[newx][newy] = EL_ACID;
5910 else if (IS_CUSTOM_ELEMENT(element) && !IS_PLAYER(x, y) &&
5911 ei->move_leave_element != EL_EMPTY &&
5912 (ei->move_leave_type == LEAVE_TYPE_UNLIMITED ||
5913 Store[x][y] != EL_EMPTY))
5915 /* some elements can leave other elements behind after moving */
5917 Feld[x][y] = ei->move_leave_element;
5918 InitField(x, y, FALSE);
5920 if (GFX_CRUMBLED(Feld[x][y]))
5921 DrawLevelFieldCrumbledSandNeighbours(x, y);
5925 Store[x][y] = EL_EMPTY;
5926 MovPos[x][y] = MovDir[x][y] = MovDelay[x][y] = 0;
5927 MovDelay[newx][newy] = 0;
5929 if (CAN_CHANGE(element))
5931 /* copy element change control values to new field */
5932 ChangeDelay[newx][newy] = ChangeDelay[x][y];
5933 ChangePage[newx][newy] = ChangePage[x][y];
5934 Changed[newx][newy] = Changed[x][y];
5935 ChangeEvent[newx][newy] = ChangeEvent[x][y];
5938 ChangeDelay[x][y] = 0;
5939 ChangePage[x][y] = -1;
5940 Changed[x][y] = CE_BITMASK_DEFAULT;
5941 ChangeEvent[x][y] = CE_BITMASK_DEFAULT;
5943 /* copy animation control values to new field */
5944 GfxFrame[newx][newy] = GfxFrame[x][y];
5945 GfxRandom[newx][newy] = GfxRandom[x][y]; /* keep same random value */
5946 GfxAction[newx][newy] = GfxAction[x][y]; /* keep action one frame */
5947 GfxDir[newx][newy] = GfxDir[x][y]; /* keep element direction */
5949 Pushed[x][y] = Pushed[newx][newy] = FALSE;
5951 ResetGfxAnimation(x, y); /* reset animation values for old field */
5954 if (IS_CUSTOM_ELEMENT(element) && !IS_PLAYER(x, y) &&
5955 ei->move_leave_element != EL_EMPTY &&
5956 (ei->move_leave_type == LEAVE_TYPE_UNLIMITED ||
5957 stored != EL_EMPTY))
5959 /* some elements can leave other elements behind after moving */
5961 Feld[x][y] = ei->move_leave_element;
5962 InitField(x, y, FALSE);
5964 if (GFX_CRUMBLED(Feld[x][y]))
5965 DrawLevelFieldCrumbledSandNeighbours(x, y);
5970 /* some elements can leave other elements behind after moving */
5971 if (IS_CUSTOM_ELEMENT(element) && !IS_PLAYER(x, y) &&
5972 ei->move_leave_element != EL_EMPTY &&
5973 (ei->move_leave_type == LEAVE_TYPE_UNLIMITED ||
5974 ei->can_leave_element_last))
5976 Feld[x][y] = ei->move_leave_element;
5977 InitField(x, y, FALSE);
5979 if (GFX_CRUMBLED(Feld[x][y]))
5980 DrawLevelFieldCrumbledSandNeighbours(x, y);
5983 ei->can_leave_element_last = ei->can_leave_element;
5984 ei->can_leave_element = FALSE;
5988 /* 2.1.1 (does not work correctly for spring) */
5989 if (!CAN_MOVE(element))
5990 MovDir[newx][newy] = 0;
5994 /* (does not work for falling objects that slide horizontally) */
5995 if (CAN_FALL(element) && MovDir[newx][newy] == MV_DOWN)
5996 MovDir[newx][newy] = 0;
5999 if (!CAN_MOVE(element) ||
6000 (element == EL_SPRING && MovDir[newx][newy] == MV_DOWN))
6001 MovDir[newx][newy] = 0;
6005 if (!CAN_MOVE(element) ||
6006 (CAN_FALL(element) && direction == MV_DOWN))
6007 GfxDir[x][y] = MovDir[newx][newy] = 0;
6009 if (!CAN_MOVE(element) ||
6010 (CAN_FALL(element) && direction == MV_DOWN &&
6011 (element == EL_SPRING ||
6012 element_info[element].move_pattern == MV_WHEN_PUSHED ||
6013 element_info[element].move_pattern == MV_WHEN_DROPPED)))
6014 GfxDir[x][y] = MovDir[newx][newy] = 0;
6020 DrawLevelField(x, y);
6021 DrawLevelField(newx, newy);
6023 Stop[newx][newy] = TRUE; /* ignore this element until the next frame */
6025 /* prevent pushed element from moving on in pushed direction */
6026 if (pushed_by_player && CAN_MOVE(element) &&
6027 element_info[element].move_pattern & MV_ANY_DIRECTION &&
6028 !(element_info[element].move_pattern & direction))
6029 TurnRound(newx, newy);
6032 /* prevent elements on conveyor belt from moving on in last direction */
6033 if (pushed_by_conveyor && CAN_FALL(element) &&
6034 direction & MV_HORIZONTAL)
6035 MovDir[newx][newy] = 0;
6038 if (!pushed_by_player)
6040 WasJustMoving[newx][newy] = 3;
6042 if (CAN_FALL(element) && direction == MV_DOWN)
6043 WasJustFalling[newx][newy] = 3;
6046 if (DONT_TOUCH(element)) /* object may be nasty to player or others */
6048 TestIfBadThingTouchesHero(newx, newy);
6049 TestIfBadThingTouchesFriend(newx, newy);
6051 if (!IS_CUSTOM_ELEMENT(element))
6052 TestIfBadThingTouchesOtherBadThing(newx, newy);
6054 else if (element == EL_PENGUIN)
6055 TestIfFriendTouchesBadThing(newx, newy);
6057 if (CAN_FALL(element) && direction == MV_DOWN &&
6058 (newy == lev_fieldy - 1 || !IS_FREE(x, newy + 1)))
6062 TestIfElementTouchesCustomElement(x, y); /* empty or new element */
6066 if (ChangePage[newx][newy] != -1) /* delayed change */
6067 ChangeElement(newx, newy, ChangePage[newx][newy]);
6072 TestIfElementHitsCustomElement(newx, newy, direction);
6076 if (!IN_LEV_FIELD(nextx, nexty) || !IS_FREE(nextx, nexty))
6078 int hitting_element = Feld[newx][newy];
6080 /* !!! fix side (direction) orientation here and elsewhere !!! */
6081 CheckElementChangeSide(newx, newy, hitting_element, CE_HITTING_SOMETHING,
6085 if (IN_LEV_FIELD(nextx, nexty))
6087 int opposite_direction = MV_DIR_OPPOSITE(direction);
6088 int hitting_side = direction;
6089 int touched_side = opposite_direction;
6090 int touched_element = MovingOrBlocked2Element(nextx, nexty);
6091 boolean object_hit = (!IS_MOVING(nextx, nexty) ||
6092 MovDir[nextx][nexty] != direction ||
6093 ABS(MovPos[nextx][nexty]) <= TILEY / 2);
6099 CheckElementChangeSide(nextx, nexty, touched_element,
6100 CE_HIT_BY_SOMETHING, opposite_direction);
6102 if (IS_CUSTOM_ELEMENT(hitting_element) &&
6103 HAS_ANY_CHANGE_EVENT(hitting_element, CE_OTHER_IS_HITTING))
6105 for (i = 0; i < element_info[hitting_element].num_change_pages; i++)
6107 struct ElementChangeInfo *change =
6108 &element_info[hitting_element].change_page[i];
6110 if (change->can_change &&
6111 change->events & CH_EVENT_BIT(CE_OTHER_IS_HITTING) &&
6112 change->trigger_side & touched_side &&
6113 change->trigger_element == touched_element)
6115 CheckElementChangePage(newx, newy, hitting_element,
6116 touched_element, CE_OTHER_IS_HITTING, i);
6122 if (IS_CUSTOM_ELEMENT(touched_element) &&
6123 HAS_ANY_CHANGE_EVENT(touched_element, CE_OTHER_GETS_HIT))
6125 for (i = 0; i < element_info[touched_element].num_change_pages; i++)
6127 struct ElementChangeInfo *change =
6128 &element_info[touched_element].change_page[i];
6130 if (change->can_change &&
6131 change->events & CH_EVENT_BIT(CE_OTHER_GETS_HIT) &&
6132 change->trigger_side & hitting_side &&
6133 change->trigger_element == hitting_element)
6135 CheckElementChangePage(nextx, nexty, touched_element,
6136 hitting_element, CE_OTHER_GETS_HIT, i);
6147 TestIfPlayerTouchesCustomElement(newx, newy);
6148 TestIfElementTouchesCustomElement(newx, newy);
6151 int AmoebeNachbarNr(int ax, int ay)
6154 int element = Feld[ax][ay];
6156 static int xy[4][2] =
6164 for (i = 0; i < NUM_DIRECTIONS; i++)
6166 int x = ax + xy[i][0];
6167 int y = ay + xy[i][1];
6169 if (!IN_LEV_FIELD(x, y))
6172 if (Feld[x][y] == element && AmoebaNr[x][y] > 0)
6173 group_nr = AmoebaNr[x][y];
6179 void AmoebenVereinigen(int ax, int ay)
6181 int i, x, y, xx, yy;
6182 int new_group_nr = AmoebaNr[ax][ay];
6183 static int xy[4][2] =
6191 if (new_group_nr == 0)
6194 for (i = 0; i < NUM_DIRECTIONS; i++)
6199 if (!IN_LEV_FIELD(x, y))
6202 if ((Feld[x][y] == EL_AMOEBA_FULL ||
6203 Feld[x][y] == EL_BD_AMOEBA ||
6204 Feld[x][y] == EL_AMOEBA_DEAD) &&
6205 AmoebaNr[x][y] != new_group_nr)
6207 int old_group_nr = AmoebaNr[x][y];
6209 if (old_group_nr == 0)
6212 AmoebaCnt[new_group_nr] += AmoebaCnt[old_group_nr];
6213 AmoebaCnt[old_group_nr] = 0;
6214 AmoebaCnt2[new_group_nr] += AmoebaCnt2[old_group_nr];
6215 AmoebaCnt2[old_group_nr] = 0;
6217 for (yy = 0; yy < lev_fieldy; yy++)
6219 for (xx = 0; xx < lev_fieldx; xx++)
6221 if (AmoebaNr[xx][yy] == old_group_nr)
6222 AmoebaNr[xx][yy] = new_group_nr;
6229 void AmoebeUmwandeln(int ax, int ay)
6233 if (Feld[ax][ay] == EL_AMOEBA_DEAD)
6235 int group_nr = AmoebaNr[ax][ay];
6240 printf("AmoebeUmwandeln(): ax = %d, ay = %d\n", ax, ay);
6241 printf("AmoebeUmwandeln(): This should never happen!\n");
6246 for (y = 0; y < lev_fieldy; y++)
6248 for (x = 0; x < lev_fieldx; x++)
6250 if (Feld[x][y] == EL_AMOEBA_DEAD && AmoebaNr[x][y] == group_nr)
6253 Feld[x][y] = EL_AMOEBA_TO_DIAMOND;
6257 PlayLevelSound(ax, ay, (IS_GEM(level.amoeba_content) ?
6258 SND_AMOEBA_TURNING_TO_GEM :
6259 SND_AMOEBA_TURNING_TO_ROCK));
6264 static int xy[4][2] =
6272 for (i = 0; i < NUM_DIRECTIONS; i++)
6277 if (!IN_LEV_FIELD(x, y))
6280 if (Feld[x][y] == EL_AMOEBA_TO_DIAMOND)
6282 PlayLevelSound(x, y, (IS_GEM(level.amoeba_content) ?
6283 SND_AMOEBA_TURNING_TO_GEM :
6284 SND_AMOEBA_TURNING_TO_ROCK));
6291 void AmoebeUmwandelnBD(int ax, int ay, int new_element)
6294 int group_nr = AmoebaNr[ax][ay];
6295 boolean done = FALSE;
6300 printf("AmoebeUmwandelnBD(): ax = %d, ay = %d\n", ax, ay);
6301 printf("AmoebeUmwandelnBD(): This should never happen!\n");
6306 for (y = 0; y < lev_fieldy; y++)
6308 for (x = 0; x < lev_fieldx; x++)
6310 if (AmoebaNr[x][y] == group_nr &&
6311 (Feld[x][y] == EL_AMOEBA_DEAD ||
6312 Feld[x][y] == EL_BD_AMOEBA ||
6313 Feld[x][y] == EL_AMOEBA_GROWING))
6316 Feld[x][y] = new_element;
6317 InitField(x, y, FALSE);
6318 DrawLevelField(x, y);
6325 PlayLevelSound(ax, ay, (new_element == EL_BD_ROCK ?
6326 SND_BD_AMOEBA_TURNING_TO_ROCK :
6327 SND_BD_AMOEBA_TURNING_TO_GEM));
6330 void AmoebeWaechst(int x, int y)
6332 static unsigned long sound_delay = 0;
6333 static unsigned long sound_delay_value = 0;
6335 if (!MovDelay[x][y]) /* start new growing cycle */
6339 if (DelayReached(&sound_delay, sound_delay_value))
6342 PlayLevelSoundElementAction(x, y, Store[x][y], ACTION_GROWING);
6344 if (Store[x][y] == EL_BD_AMOEBA)
6345 PlayLevelSound(x, y, SND_BD_AMOEBA_GROWING);
6347 PlayLevelSound(x, y, SND_AMOEBA_GROWING);
6349 sound_delay_value = 30;
6353 if (MovDelay[x][y]) /* wait some time before growing bigger */
6356 if (MovDelay[x][y]/2 && IN_SCR_FIELD(SCREENX(x), SCREENY(y)))
6358 int frame = getGraphicAnimationFrame(IMG_AMOEBA_GROWING,
6359 6 - MovDelay[x][y]);
6361 DrawGraphic(SCREENX(x), SCREENY(y), IMG_AMOEBA_GROWING, frame);
6364 if (!MovDelay[x][y])
6366 Feld[x][y] = Store[x][y];
6368 DrawLevelField(x, y);
6373 void AmoebaDisappearing(int x, int y)
6375 static unsigned long sound_delay = 0;
6376 static unsigned long sound_delay_value = 0;
6378 if (!MovDelay[x][y]) /* start new shrinking cycle */
6382 if (DelayReached(&sound_delay, sound_delay_value))
6383 sound_delay_value = 30;
6386 if (MovDelay[x][y]) /* wait some time before shrinking */
6389 if (MovDelay[x][y]/2 && IN_SCR_FIELD(SCREENX(x), SCREENY(y)))
6391 int frame = getGraphicAnimationFrame(IMG_AMOEBA_SHRINKING,
6392 6 - MovDelay[x][y]);
6394 DrawGraphic(SCREENX(x), SCREENY(y), IMG_AMOEBA_SHRINKING, frame);
6397 if (!MovDelay[x][y])
6399 Feld[x][y] = EL_EMPTY;
6400 DrawLevelField(x, y);
6402 /* don't let mole enter this field in this cycle;
6403 (give priority to objects falling to this field from above) */
6409 void AmoebeAbleger(int ax, int ay)
6412 int element = Feld[ax][ay];
6413 int graphic = el2img(element);
6414 int newax = ax, neway = ay;
6415 static int xy[4][2] =
6423 if (!level.amoeba_speed)
6425 Feld[ax][ay] = EL_AMOEBA_DEAD;
6426 DrawLevelField(ax, ay);
6430 if (IS_ANIMATED(graphic))
6431 DrawLevelGraphicAnimationIfNeeded(ax, ay, graphic);
6433 if (!MovDelay[ax][ay]) /* start making new amoeba field */
6434 MovDelay[ax][ay] = RND(FRAMES_PER_SECOND * 25 / (1 + level.amoeba_speed));
6436 if (MovDelay[ax][ay]) /* wait some time before making new amoeba */
6439 if (MovDelay[ax][ay])
6443 if (element == EL_AMOEBA_WET) /* object is an acid / amoeba drop */
6446 int x = ax + xy[start][0];
6447 int y = ay + xy[start][1];
6449 if (!IN_LEV_FIELD(x, y))
6452 /* !!! extend EL_SAND to anything diggable (but maybe not SP_BASE) !!! */
6453 if (IS_FREE(x, y) ||
6454 Feld[x][y] == EL_SAND || Feld[x][y] == EL_QUICKSAND_EMPTY)
6460 if (newax == ax && neway == ay)
6463 else /* normal or "filled" (BD style) amoeba */
6466 boolean waiting_for_player = FALSE;
6468 for (i = 0; i < NUM_DIRECTIONS; i++)
6470 int j = (start + i) % 4;
6471 int x = ax + xy[j][0];
6472 int y = ay + xy[j][1];
6474 if (!IN_LEV_FIELD(x, y))
6477 /* !!! extend EL_SAND to anything diggable (but maybe not SP_BASE) !!! */
6478 if (IS_FREE(x, y) ||
6479 Feld[x][y] == EL_SAND || Feld[x][y] == EL_QUICKSAND_EMPTY)
6485 else if (IS_PLAYER(x, y))
6486 waiting_for_player = TRUE;
6489 if (newax == ax && neway == ay) /* amoeba cannot grow */
6491 if (i == 4 && (!waiting_for_player || game.emulation == EMU_BOULDERDASH))
6493 Feld[ax][ay] = EL_AMOEBA_DEAD;
6494 DrawLevelField(ax, ay);
6495 AmoebaCnt[AmoebaNr[ax][ay]]--;
6497 if (AmoebaCnt[AmoebaNr[ax][ay]] <= 0) /* amoeba is completely dead */
6499 if (element == EL_AMOEBA_FULL)
6500 AmoebeUmwandeln(ax, ay);
6501 else if (element == EL_BD_AMOEBA)
6502 AmoebeUmwandelnBD(ax, ay, level.amoeba_content);
6507 else if (element == EL_AMOEBA_FULL || element == EL_BD_AMOEBA)
6509 /* amoeba gets larger by growing in some direction */
6511 int new_group_nr = AmoebaNr[ax][ay];
6514 if (new_group_nr == 0)
6516 printf("AmoebeAbleger(): newax = %d, neway = %d\n", newax, neway);
6517 printf("AmoebeAbleger(): This should never happen!\n");
6522 AmoebaNr[newax][neway] = new_group_nr;
6523 AmoebaCnt[new_group_nr]++;
6524 AmoebaCnt2[new_group_nr]++;
6526 /* if amoeba touches other amoeba(s) after growing, unify them */
6527 AmoebenVereinigen(newax, neway);
6529 if (element == EL_BD_AMOEBA && AmoebaCnt2[new_group_nr] >= 200)
6531 AmoebeUmwandelnBD(newax, neway, EL_BD_ROCK);
6537 if (element != EL_AMOEBA_WET || neway < ay || !IS_FREE(newax, neway) ||
6538 (neway == lev_fieldy - 1 && newax != ax))
6540 Feld[newax][neway] = EL_AMOEBA_GROWING; /* creation of new amoeba */
6541 Store[newax][neway] = element;
6543 else if (neway == ay)
6545 Feld[newax][neway] = EL_AMOEBA_DROP; /* drop left/right of amoeba */
6547 PlayLevelSoundAction(newax, neway, ACTION_GROWING);
6549 PlayLevelSound(newax, neway, SND_AMOEBA_GROWING);
6554 InitMovingField(ax, ay, MV_DOWN); /* drop dripping from amoeba */
6555 Feld[ax][ay] = EL_AMOEBA_DROPPING;
6556 Store[ax][ay] = EL_AMOEBA_DROP;
6557 ContinueMoving(ax, ay);
6561 DrawLevelField(newax, neway);
6564 void Life(int ax, int ay)
6567 static int life[4] = { 2, 3, 3, 3 }; /* parameters for "game of life" */
6569 int element = Feld[ax][ay];
6570 int graphic = el2img(element);
6571 boolean changed = FALSE;
6573 if (IS_ANIMATED(graphic))
6574 DrawLevelGraphicAnimationIfNeeded(ax, ay, graphic);
6579 if (!MovDelay[ax][ay]) /* start new "game of life" cycle */
6580 MovDelay[ax][ay] = life_time;
6582 if (MovDelay[ax][ay]) /* wait some time before next cycle */
6585 if (MovDelay[ax][ay])
6589 for (y1 = -1; y1 < 2; y1++) for (x1 = -1; x1 < 2; x1++)
6591 int xx = ax+x1, yy = ay+y1;
6594 if (!IN_LEV_FIELD(xx, yy))
6597 for (y2 = -1; y2 < 2; y2++) for (x2 = -1; x2 < 2; x2++)
6599 int x = xx+x2, y = yy+y2;
6601 if (!IN_LEV_FIELD(x, y) || (x == xx && y == yy))
6604 if (((Feld[x][y] == element ||
6605 (element == EL_GAME_OF_LIFE && IS_PLAYER(x, y))) &&
6607 (IS_FREE(x, y) && Stop[x][y]))
6611 if (xx == ax && yy == ay) /* field in the middle */
6613 if (nachbarn < life[0] || nachbarn > life[1])
6615 Feld[xx][yy] = EL_EMPTY;
6617 DrawLevelField(xx, yy);
6618 Stop[xx][yy] = TRUE;
6622 /* !!! extend EL_SAND to anything diggable (but maybe not SP_BASE) !!! */
6623 else if (IS_FREE(xx, yy) || Feld[xx][yy] == EL_SAND)
6624 { /* free border field */
6625 if (nachbarn >= life[2] && nachbarn <= life[3])
6627 Feld[xx][yy] = element;
6628 MovDelay[xx][yy] = (element == EL_GAME_OF_LIFE ? 0 : life_time-1);
6630 DrawLevelField(xx, yy);
6631 Stop[xx][yy] = TRUE;
6638 PlayLevelSound(ax, ay, element == EL_BIOMAZE ? SND_BIOMAZE_GROWING :
6639 SND_GAME_OF_LIFE_GROWING);
6642 static void InitRobotWheel(int x, int y)
6644 ChangeDelay[x][y] = level.time_wheel * FRAMES_PER_SECOND;
6647 static void RunRobotWheel(int x, int y)
6649 PlayLevelSound(x, y, SND_ROBOT_WHEEL_ACTIVE);
6652 static void StopRobotWheel(int x, int y)
6654 if (ZX == x && ZY == y)
6658 static void InitTimegateWheel(int x, int y)
6660 ChangeDelay[x][y] = level.time_wheel * FRAMES_PER_SECOND;
6663 static void RunTimegateWheel(int x, int y)
6665 PlayLevelSound(x, y, SND_TIMEGATE_SWITCH_ACTIVE);
6668 void CheckExit(int x, int y)
6670 if (local_player->gems_still_needed > 0 ||
6671 local_player->sokobanfields_still_needed > 0 ||
6672 local_player->lights_still_needed > 0)
6674 int element = Feld[x][y];
6675 int graphic = el2img(element);
6677 if (IS_ANIMATED(graphic))
6678 DrawLevelGraphicAnimationIfNeeded(x, y, graphic);
6683 if (AllPlayersGone) /* do not re-open exit door closed after last player */
6686 Feld[x][y] = EL_EXIT_OPENING;
6688 PlayLevelSoundNearest(x, y, SND_CLASS_EXIT_OPENING);
6691 void CheckExitSP(int x, int y)
6693 if (local_player->gems_still_needed > 0)
6695 int element = Feld[x][y];
6696 int graphic = el2img(element);
6698 if (IS_ANIMATED(graphic))
6699 DrawLevelGraphicAnimationIfNeeded(x, y, graphic);
6704 if (AllPlayersGone) /* do not re-open exit door closed after last player */
6707 Feld[x][y] = EL_SP_EXIT_OPENING;
6709 PlayLevelSoundNearest(x, y, SND_CLASS_SP_EXIT_OPENING);
6712 static void CloseAllOpenTimegates()
6716 for (y = 0; y < lev_fieldy; y++)
6718 for (x = 0; x < lev_fieldx; x++)
6720 int element = Feld[x][y];
6722 if (element == EL_TIMEGATE_OPEN || element == EL_TIMEGATE_OPENING)
6724 Feld[x][y] = EL_TIMEGATE_CLOSING;
6726 PlayLevelSoundAction(x, y, ACTION_CLOSING);
6728 PlayLevelSound(x, y, SND_TIMEGATE_CLOSING);
6735 void EdelsteinFunkeln(int x, int y)
6737 if (!IN_SCR_FIELD(SCREENX(x), SCREENY(y)) || IS_MOVING(x, y))
6740 if (Feld[x][y] == EL_BD_DIAMOND)
6743 if (MovDelay[x][y] == 0) /* next animation frame */
6744 MovDelay[x][y] = 11 * !SimpleRND(500);
6746 if (MovDelay[x][y] != 0) /* wait some time before next frame */
6750 if (setup.direct_draw && MovDelay[x][y])
6751 SetDrawtoField(DRAW_BUFFERED);
6753 DrawLevelElementAnimation(x, y, Feld[x][y]);
6755 if (MovDelay[x][y] != 0)
6757 int frame = getGraphicAnimationFrame(IMG_TWINKLE_WHITE,
6758 10 - MovDelay[x][y]);
6760 DrawGraphicThruMask(SCREENX(x), SCREENY(y), IMG_TWINKLE_WHITE, frame);
6762 if (setup.direct_draw)
6766 dest_x = FX + SCREENX(x) * TILEX;
6767 dest_y = FY + SCREENY(y) * TILEY;
6769 BlitBitmap(drawto_field, window,
6770 dest_x, dest_y, TILEX, TILEY, dest_x, dest_y);
6771 SetDrawtoField(DRAW_DIRECT);
6777 void MauerWaechst(int x, int y)
6781 if (!MovDelay[x][y]) /* next animation frame */
6782 MovDelay[x][y] = 3 * delay;
6784 if (MovDelay[x][y]) /* wait some time before next frame */
6788 if (IN_SCR_FIELD(SCREENX(x), SCREENY(y)))
6790 int graphic = el_dir2img(Feld[x][y], GfxDir[x][y]);
6791 int frame = getGraphicAnimationFrame(graphic, 17 - MovDelay[x][y]);
6793 DrawGraphic(SCREENX(x), SCREENY(y), graphic, frame);
6796 if (!MovDelay[x][y])
6798 if (MovDir[x][y] == MV_LEFT)
6800 if (IN_LEV_FIELD(x - 1, y) && IS_WALL(Feld[x - 1][y]))
6801 DrawLevelField(x - 1, y);
6803 else if (MovDir[x][y] == MV_RIGHT)
6805 if (IN_LEV_FIELD(x + 1, y) && IS_WALL(Feld[x + 1][y]))
6806 DrawLevelField(x + 1, y);
6808 else if (MovDir[x][y] == MV_UP)
6810 if (IN_LEV_FIELD(x, y - 1) && IS_WALL(Feld[x][y - 1]))
6811 DrawLevelField(x, y - 1);
6815 if (IN_LEV_FIELD(x, y + 1) && IS_WALL(Feld[x][y + 1]))
6816 DrawLevelField(x, y + 1);
6819 Feld[x][y] = Store[x][y];
6821 GfxDir[x][y] = MovDir[x][y] = MV_NO_MOVING;
6822 DrawLevelField(x, y);
6827 void MauerAbleger(int ax, int ay)
6829 int element = Feld[ax][ay];
6830 int graphic = el2img(element);
6831 boolean oben_frei = FALSE, unten_frei = FALSE;
6832 boolean links_frei = FALSE, rechts_frei = FALSE;
6833 boolean oben_massiv = FALSE, unten_massiv = FALSE;
6834 boolean links_massiv = FALSE, rechts_massiv = FALSE;
6835 boolean new_wall = FALSE;
6837 if (IS_ANIMATED(graphic))
6838 DrawLevelGraphicAnimationIfNeeded(ax, ay, graphic);
6840 if (!MovDelay[ax][ay]) /* start building new wall */
6841 MovDelay[ax][ay] = 6;
6843 if (MovDelay[ax][ay]) /* wait some time before building new wall */
6846 if (MovDelay[ax][ay])
6850 if (IN_LEV_FIELD(ax, ay-1) && IS_FREE(ax, ay-1))
6852 if (IN_LEV_FIELD(ax, ay+1) && IS_FREE(ax, ay+1))
6854 if (IN_LEV_FIELD(ax-1, ay) && IS_FREE(ax-1, ay))
6856 if (IN_LEV_FIELD(ax+1, ay) && IS_FREE(ax+1, ay))
6859 if (element == EL_EXPANDABLE_WALL_VERTICAL ||
6860 element == EL_EXPANDABLE_WALL_ANY)
6864 Feld[ax][ay-1] = EL_EXPANDABLE_WALL_GROWING;
6865 Store[ax][ay-1] = element;
6866 GfxDir[ax][ay-1] = MovDir[ax][ay-1] = MV_UP;
6867 if (IN_SCR_FIELD(SCREENX(ax), SCREENY(ay-1)))
6868 DrawGraphic(SCREENX(ax), SCREENY(ay - 1),
6869 IMG_EXPANDABLE_WALL_GROWING_UP, 0);
6874 Feld[ax][ay+1] = EL_EXPANDABLE_WALL_GROWING;
6875 Store[ax][ay+1] = element;
6876 GfxDir[ax][ay+1] = MovDir[ax][ay+1] = MV_DOWN;
6877 if (IN_SCR_FIELD(SCREENX(ax), SCREENY(ay+1)))
6878 DrawGraphic(SCREENX(ax), SCREENY(ay + 1),
6879 IMG_EXPANDABLE_WALL_GROWING_DOWN, 0);
6884 if (element == EL_EXPANDABLE_WALL_HORIZONTAL ||
6885 element == EL_EXPANDABLE_WALL_ANY ||
6886 element == EL_EXPANDABLE_WALL)
6890 Feld[ax-1][ay] = EL_EXPANDABLE_WALL_GROWING;
6891 Store[ax-1][ay] = element;
6892 GfxDir[ax-1][ay] = MovDir[ax-1][ay] = MV_LEFT;
6893 if (IN_SCR_FIELD(SCREENX(ax-1), SCREENY(ay)))
6894 DrawGraphic(SCREENX(ax - 1), SCREENY(ay),
6895 IMG_EXPANDABLE_WALL_GROWING_LEFT, 0);
6901 Feld[ax+1][ay] = EL_EXPANDABLE_WALL_GROWING;
6902 Store[ax+1][ay] = element;
6903 GfxDir[ax+1][ay] = MovDir[ax+1][ay] = MV_RIGHT;
6904 if (IN_SCR_FIELD(SCREENX(ax+1), SCREENY(ay)))
6905 DrawGraphic(SCREENX(ax + 1), SCREENY(ay),
6906 IMG_EXPANDABLE_WALL_GROWING_RIGHT, 0);
6911 if (element == EL_EXPANDABLE_WALL && (links_frei || rechts_frei))
6912 DrawLevelField(ax, ay);
6914 if (!IN_LEV_FIELD(ax, ay-1) || IS_WALL(Feld[ax][ay-1]))
6916 if (!IN_LEV_FIELD(ax, ay+1) || IS_WALL(Feld[ax][ay+1]))
6917 unten_massiv = TRUE;
6918 if (!IN_LEV_FIELD(ax-1, ay) || IS_WALL(Feld[ax-1][ay]))
6919 links_massiv = TRUE;
6920 if (!IN_LEV_FIELD(ax+1, ay) || IS_WALL(Feld[ax+1][ay]))
6921 rechts_massiv = TRUE;
6923 if (((oben_massiv && unten_massiv) ||
6924 element == EL_EXPANDABLE_WALL_HORIZONTAL ||
6925 element == EL_EXPANDABLE_WALL) &&
6926 ((links_massiv && rechts_massiv) ||
6927 element == EL_EXPANDABLE_WALL_VERTICAL))
6928 Feld[ax][ay] = EL_WALL;
6932 PlayLevelSoundAction(ax, ay, ACTION_GROWING);
6934 PlayLevelSound(ax, ay, SND_EXPANDABLE_WALL_GROWING);
6938 void CheckForDragon(int x, int y)
6941 boolean dragon_found = FALSE;
6942 static int xy[4][2] =
6950 for (i = 0; i < NUM_DIRECTIONS; i++)
6952 for (j = 0; j < 4; j++)
6954 int xx = x + j * xy[i][0], yy = y + j * xy[i][1];
6956 if (IN_LEV_FIELD(xx, yy) &&
6957 (Feld[xx][yy] == EL_FLAMES || Feld[xx][yy] == EL_DRAGON))
6959 if (Feld[xx][yy] == EL_DRAGON)
6960 dragon_found = TRUE;
6969 for (i = 0; i < NUM_DIRECTIONS; i++)
6971 for (j = 0; j < 3; j++)
6973 int xx = x + j * xy[i][0], yy = y + j * xy[i][1];
6975 if (IN_LEV_FIELD(xx, yy) && Feld[xx][yy] == EL_FLAMES)
6977 Feld[xx][yy] = EL_EMPTY;
6978 DrawLevelField(xx, yy);
6987 static void InitBuggyBase(int x, int y)
6989 int element = Feld[x][y];
6990 int activating_delay = FRAMES_PER_SECOND / 4;
6993 (element == EL_SP_BUGGY_BASE ?
6994 2 * FRAMES_PER_SECOND + RND(5 * FRAMES_PER_SECOND) - activating_delay :
6995 element == EL_SP_BUGGY_BASE_ACTIVATING ?
6997 element == EL_SP_BUGGY_BASE_ACTIVE ?
6998 1 * FRAMES_PER_SECOND + RND(1 * FRAMES_PER_SECOND) : 1);
7001 static void WarnBuggyBase(int x, int y)
7004 static int xy[4][2] =
7012 for (i = 0; i < NUM_DIRECTIONS; i++)
7014 int xx = x + xy[i][0], yy = y + xy[i][1];
7016 if (IS_PLAYER(xx, yy))
7018 PlayLevelSound(x, y, SND_SP_BUGGY_BASE_ACTIVE);
7025 static void InitTrap(int x, int y)
7027 ChangeDelay[x][y] = 2 * FRAMES_PER_SECOND + RND(5 * FRAMES_PER_SECOND);
7030 static void ActivateTrap(int x, int y)
7032 PlayLevelSound(x, y, SND_TRAP_ACTIVATING);
7035 static void ChangeActiveTrap(int x, int y)
7037 int graphic = IMG_TRAP_ACTIVE;
7039 /* if new animation frame was drawn, correct crumbled sand border */
7040 if (IS_NEW_FRAME(GfxFrame[x][y], graphic))
7041 DrawLevelFieldCrumbledSand(x, y);
7044 static void ChangeElementNowExt(int x, int y, int target_element)
7046 int previous_move_direction = MovDir[x][y];
7048 /* check if element under player changes from accessible to unaccessible
7049 (needed for special case of dropping element which then changes) */
7050 if (IS_PLAYER(x, y) && !PLAYER_EXPLOSION_PROTECTED(x, y) &&
7051 IS_ACCESSIBLE(Feld[x][y]) && !IS_ACCESSIBLE(target_element))
7058 Feld[x][y] = target_element;
7060 Changed[x][y] |= ChangeEvent[x][y]; /* ignore same changes in this frame */
7062 ResetGfxAnimation(x, y);
7063 ResetRandomAnimationValue(x, y);
7065 if (element_info[Feld[x][y]].move_direction_initial == MV_START_PREVIOUS)
7066 MovDir[x][y] = previous_move_direction;
7069 InitField_WithBug1(x, y, FALSE);
7071 InitField(x, y, FALSE);
7072 if (CAN_MOVE(Feld[x][y]))
7076 DrawLevelField(x, y);
7078 if (GFX_CRUMBLED(Feld[x][y]))
7079 DrawLevelFieldCrumbledSandNeighbours(x, y);
7081 TestIfBadThingTouchesHero(x, y);
7082 TestIfPlayerTouchesCustomElement(x, y);
7083 TestIfElementTouchesCustomElement(x, y);
7085 if (ELEM_IS_PLAYER(target_element))
7086 RelocatePlayer(x, y, target_element);
7089 static boolean ChangeElementNow(int x, int y, int element, int page)
7091 struct ElementChangeInfo *change = &element_info[element].change_page[page];
7094 /* always use default change event to prevent running into a loop */
7095 if (ChangeEvent[x][y] == CE_BITMASK_DEFAULT)
7096 ChangeEvent[x][y] = CH_EVENT_BIT(CE_DELAY);
7098 if (ChangeEvent[x][y] == CH_EVENT_BIT(CE_DELAY))
7100 /* reset actual trigger element and player */
7101 change->actual_trigger_element = EL_EMPTY;
7102 change->actual_trigger_player = EL_PLAYER_1;
7105 /* do not change already changed elements with same change event */
7107 if (Changed[x][y] & ChangeEvent[x][y])
7114 Changed[x][y] |= ChangeEvent[x][y]; /* ignore same changes in this frame */
7116 CheckTriggeredElementChangePage(x,y, Feld[x][y], CE_OTHER_IS_CHANGING, page);
7118 if (change->explode)
7125 if (change->use_target_content)
7127 boolean complete_replace = TRUE;
7128 boolean can_replace[3][3];
7131 for (yy = 0; yy < 3; yy++) for (xx = 0; xx < 3 ; xx++)
7134 boolean is_diggable;
7135 boolean is_destructible;
7136 int ex = x + xx - 1;
7137 int ey = y + yy - 1;
7138 int content_element = change->target_content[xx][yy];
7141 can_replace[xx][yy] = TRUE;
7143 if (ex == x && ey == y) /* do not check changing element itself */
7146 if (content_element == EL_EMPTY_SPACE)
7148 can_replace[xx][yy] = FALSE; /* do not replace border with space */
7153 if (!IN_LEV_FIELD(ex, ey))
7155 can_replace[xx][yy] = FALSE;
7156 complete_replace = FALSE;
7163 if (IS_MOVING(ex, ey) || IS_BLOCKED(ex, ey))
7164 e = MovingOrBlocked2Element(ex, ey);
7167 is_empty = (IS_FREE(ex, ey) || (IS_PLAYER(ex, ey) &&
7168 IS_WALKABLE(content_element)));
7169 is_diggable = (is_empty || IS_DIGGABLE(e));
7170 is_destructible = (is_empty || !IS_INDESTRUCTIBLE(e));
7172 can_replace[xx][yy] =
7173 ((change->replace_when == CP_WHEN_EMPTY && is_empty) ||
7174 (change->replace_when == CP_WHEN_DIGGABLE && is_diggable) ||
7175 (change->replace_when == CP_WHEN_DESTRUCTIBLE && is_destructible));
7177 if (!can_replace[xx][yy])
7178 complete_replace = FALSE;
7180 empty_for_element = (IS_FREE(ex, ey) || (IS_FREE_OR_PLAYER(ex, ey) &&
7181 IS_WALKABLE(content_element)));
7183 half_destructible = (empty_for_element || IS_DIGGABLE(e));
7185 half_destructible = (IS_FREE(ex, ey) || IS_DIGGABLE(e));
7188 if ((change->replace_when <= CP_WHEN_EMPTY && !empty_for_element) ||
7189 (change->replace_when <= CP_WHEN_DIGGABLE && !half_destructible) ||
7190 (change->replace_when <= CP_WHEN_DESTRUCTIBLE && IS_INDESTRUCTIBLE(e)))
7192 can_replace[xx][yy] = FALSE;
7193 complete_replace = FALSE;
7198 if (!change->only_if_complete || complete_replace)
7200 boolean something_has_changed = FALSE;
7202 if (change->only_if_complete && change->use_random_replace &&
7203 RND(100) < change->random_percentage)
7206 for (yy = 0; yy < 3; yy++) for (xx = 0; xx < 3 ; xx++)
7208 int ex = x + xx - 1;
7209 int ey = y + yy - 1;
7210 int content_element;
7212 if (can_replace[xx][yy] && (!change->use_random_replace ||
7213 RND(100) < change->random_percentage))
7215 if (IS_MOVING(ex, ey) || IS_BLOCKED(ex, ey))
7216 RemoveMovingField(ex, ey);
7218 ChangeEvent[ex][ey] = ChangeEvent[x][y];
7220 content_element = change->target_content[xx][yy];
7221 target_element = GET_TARGET_ELEMENT(content_element, change);
7223 ChangeElementNowExt(ex, ey, target_element);
7225 something_has_changed = TRUE;
7227 /* for symmetry reasons, freeze newly created border elements */
7228 if (ex != x || ey != y)
7229 Stop[ex][ey] = TRUE; /* no more moving in this frame */
7233 if (something_has_changed)
7234 PlayLevelSoundElementAction(x, y, element, ACTION_CHANGING);
7239 target_element = GET_TARGET_ELEMENT(change->target_element, change);
7241 ChangeElementNowExt(x, y, target_element);
7243 PlayLevelSoundElementAction(x, y, element, ACTION_CHANGING);
7249 static void ChangeElement(int x, int y, int page)
7251 int element = MovingOrBlocked2Element(x, y);
7252 struct ElementInfo *ei = &element_info[element];
7253 struct ElementChangeInfo *change = &ei->change_page[page];
7256 if (!CAN_CHANGE(element) && !CAN_CHANGE(Back[x][y]))
7259 printf("ChangeElement(): %d,%d: element = %d ('%s')\n",
7260 x, y, element, element_info[element].token_name);
7261 printf("ChangeElement(): This should never happen!\n");
7266 /* this can happen with classic bombs on walkable, changing elements */
7267 if (!CAN_CHANGE(element))
7270 if (!CAN_CHANGE(Back[x][y])) /* prevent permanent repetition */
7271 ChangeDelay[x][y] = 0;
7277 if (ChangeDelay[x][y] == 0) /* initialize element change */
7279 ChangeDelay[x][y] = ( change->delay_fixed * change->delay_frames +
7280 RND(change->delay_random * change->delay_frames)) + 1;
7282 ResetGfxAnimation(x, y);
7283 ResetRandomAnimationValue(x, y);
7285 if (change->pre_change_function)
7286 change->pre_change_function(x, y);
7289 ChangeDelay[x][y]--;
7291 if (ChangeDelay[x][y] != 0) /* continue element change */
7293 int graphic = el_act_dir2img(element, GfxAction[x][y], GfxDir[x][y]);
7295 if (IS_ANIMATED(graphic))
7296 DrawLevelGraphicAnimationIfNeeded(x, y, graphic);
7298 if (change->change_function)
7299 change->change_function(x, y);
7301 else /* finish element change */
7303 if (ChangePage[x][y] != -1) /* remember page from delayed change */
7305 page = ChangePage[x][y];
7306 ChangePage[x][y] = -1;
7308 change = &ei->change_page[page];
7312 if (IS_MOVING(x, y) && !change->explode)
7314 if (IS_MOVING(x, y)) /* never change a running system ;-) */
7317 ChangeDelay[x][y] = 1; /* try change after next move step */
7318 ChangePage[x][y] = page; /* remember page to use for change */
7323 if (ChangeElementNow(x, y, element, page))
7325 if (change->post_change_function)
7326 change->post_change_function(x, y);
7331 static boolean CheckTriggeredElementChangeExt(int lx, int ly,
7332 int trigger_element,
7339 int trigger_page_bits = (trigger_page < 0 ? CH_PAGE_ANY : 1 << trigger_page);
7341 if (!(trigger_events[trigger_element] & CH_EVENT_BIT(trigger_event)))
7344 for (i = 0; i < NUM_CUSTOM_ELEMENTS; i++)
7346 int element = EL_CUSTOM_START + i;
7348 boolean change_element = FALSE;
7351 if (!CAN_CHANGE(element) || !HAS_ANY_CHANGE_EVENT(element, trigger_event))
7354 for (j = 0; j < element_info[element].num_change_pages; j++)
7356 struct ElementChangeInfo *change = &element_info[element].change_page[j];
7358 if (change->can_change &&
7359 change->events & CH_EVENT_BIT(trigger_event) &&
7360 change->trigger_side & trigger_side &&
7361 change->trigger_player & trigger_player &&
7362 change->trigger_page & trigger_page_bits &&
7363 IS_EQUAL_OR_IN_GROUP(trigger_element, change->trigger_element))
7366 if (!(change->events & CH_EVENT_BIT(trigger_event)))
7367 printf("::: !!! %d triggers %d: using wrong page %d [event %d]\n",
7368 trigger_element-EL_CUSTOM_START+1, i+1, j, trigger_event);
7371 change_element = TRUE;
7374 change->actual_trigger_element = trigger_element;
7375 change->actual_trigger_player = EL_PLAYER_1 + log_2(trigger_player);
7381 if (!change_element)
7384 for (y = 0; y < lev_fieldy; y++) for (x = 0; x < lev_fieldx; x++)
7387 if (x == lx && y == ly) /* do not change trigger element itself */
7391 if (Feld[x][y] == element)
7393 ChangeDelay[x][y] = 1;
7394 ChangeEvent[x][y] = CH_EVENT_BIT(trigger_event);
7395 ChangeElement(x, y, page);
7403 static boolean CheckElementChangeExt(int x, int y,
7405 int trigger_element,
7411 if (!CAN_CHANGE(element) || !HAS_ANY_CHANGE_EVENT(element, trigger_event))
7414 if (Feld[x][y] == EL_BLOCKED)
7416 Blocked2Moving(x, y, &x, &y);
7417 element = Feld[x][y];
7421 if (Feld[x][y] != element) /* check if element has already changed */
7424 printf("::: %d ('%s') != %d ('%s') [%d]\n",
7425 Feld[x][y], element_info[Feld[x][y]].token_name,
7426 element, element_info[element].token_name,
7435 if (trigger_page < 0)
7437 boolean change_element = FALSE;
7440 for (i = 0; i < element_info[element].num_change_pages; i++)
7442 struct ElementChangeInfo *change = &element_info[element].change_page[i];
7444 if (change->can_change &&
7445 change->events & CH_EVENT_BIT(trigger_event) &&
7446 change->trigger_side & trigger_side &&
7447 change->trigger_player & trigger_player)
7449 change_element = TRUE;
7452 change->actual_trigger_element = trigger_element;
7453 change->actual_trigger_player = EL_PLAYER_1 + log_2(trigger_player);
7459 if (!change_element)
7464 struct ElementInfo *ei = &element_info[element];
7465 struct ElementChangeInfo *change = &ei->change_page[trigger_page];
7467 change->actual_trigger_element = trigger_element;
7468 change->actual_trigger_player = EL_PLAYER_1; /* unused */
7473 /* !!! this check misses pages with same event, but different side !!! */
7475 if (trigger_page < 0)
7476 trigger_page = element_info[element].event_page_nr[trigger_event];
7478 if (!(element_info[element].change_page[trigger_page].trigger_side & trigger_side))
7482 ChangeDelay[x][y] = 1;
7483 ChangeEvent[x][y] = CH_EVENT_BIT(trigger_event);
7484 ChangeElement(x, y, trigger_page);
7489 static void PlayPlayerSound(struct PlayerInfo *player)
7491 int jx = player->jx, jy = player->jy;
7492 int element = player->element_nr;
7493 int last_action = player->last_action_waiting;
7494 int action = player->action_waiting;
7496 if (player->is_waiting)
7498 if (action != last_action)
7499 PlayLevelSoundElementAction(jx, jy, element, action);
7501 PlayLevelSoundElementActionIfLoop(jx, jy, element, action);
7505 if (action != last_action)
7506 StopSound(element_info[element].sound[last_action]);
7508 if (last_action == ACTION_SLEEPING)
7509 PlayLevelSoundElementAction(jx, jy, element, ACTION_AWAKENING);
7513 static void PlayAllPlayersSound()
7517 for (i = 0; i < MAX_PLAYERS; i++)
7518 if (stored_player[i].active)
7519 PlayPlayerSound(&stored_player[i]);
7522 static void SetPlayerWaiting(struct PlayerInfo *player, boolean is_waiting)
7524 boolean last_waiting = player->is_waiting;
7525 int move_dir = player->MovDir;
7527 player->last_action_waiting = player->action_waiting;
7531 if (!last_waiting) /* not waiting -> waiting */
7533 player->is_waiting = TRUE;
7535 player->frame_counter_bored =
7537 game.player_boring_delay_fixed +
7538 SimpleRND(game.player_boring_delay_random);
7539 player->frame_counter_sleeping =
7541 game.player_sleeping_delay_fixed +
7542 SimpleRND(game.player_sleeping_delay_random);
7544 InitPlayerGfxAnimation(player, ACTION_WAITING, player->MovDir);
7547 if (game.player_sleeping_delay_fixed +
7548 game.player_sleeping_delay_random > 0 &&
7549 player->anim_delay_counter == 0 &&
7550 player->post_delay_counter == 0 &&
7551 FrameCounter >= player->frame_counter_sleeping)
7552 player->is_sleeping = TRUE;
7553 else if (game.player_boring_delay_fixed +
7554 game.player_boring_delay_random > 0 &&
7555 FrameCounter >= player->frame_counter_bored)
7556 player->is_bored = TRUE;
7558 player->action_waiting = (player->is_sleeping ? ACTION_SLEEPING :
7559 player->is_bored ? ACTION_BORING :
7562 if (player->is_sleeping)
7564 if (player->num_special_action_sleeping > 0)
7566 if (player->anim_delay_counter == 0 && player->post_delay_counter == 0)
7568 int last_special_action = player->special_action_sleeping;
7569 int num_special_action = player->num_special_action_sleeping;
7570 int special_action =
7571 (last_special_action == ACTION_DEFAULT ? ACTION_SLEEPING_1 :
7572 last_special_action == ACTION_SLEEPING ? ACTION_SLEEPING :
7573 last_special_action < ACTION_SLEEPING_1 + num_special_action - 1 ?
7574 last_special_action + 1 : ACTION_SLEEPING);
7575 int special_graphic =
7576 el_act_dir2img(player->element_nr, special_action, move_dir);
7578 player->anim_delay_counter =
7579 graphic_info[special_graphic].anim_delay_fixed +
7580 SimpleRND(graphic_info[special_graphic].anim_delay_random);
7581 player->post_delay_counter =
7582 graphic_info[special_graphic].post_delay_fixed +
7583 SimpleRND(graphic_info[special_graphic].post_delay_random);
7585 player->special_action_sleeping = special_action;
7588 if (player->anim_delay_counter > 0)
7590 player->action_waiting = player->special_action_sleeping;
7591 player->anim_delay_counter--;
7593 else if (player->post_delay_counter > 0)
7595 player->post_delay_counter--;
7599 else if (player->is_bored)
7601 if (player->num_special_action_bored > 0)
7603 if (player->anim_delay_counter == 0 && player->post_delay_counter == 0)
7605 int special_action =
7606 ACTION_BORING_1 + SimpleRND(player->num_special_action_bored);
7607 int special_graphic =
7608 el_act_dir2img(player->element_nr, special_action, move_dir);
7610 player->anim_delay_counter =
7611 graphic_info[special_graphic].anim_delay_fixed +
7612 SimpleRND(graphic_info[special_graphic].anim_delay_random);
7613 player->post_delay_counter =
7614 graphic_info[special_graphic].post_delay_fixed +
7615 SimpleRND(graphic_info[special_graphic].post_delay_random);
7617 player->special_action_bored = special_action;
7620 if (player->anim_delay_counter > 0)
7622 player->action_waiting = player->special_action_bored;
7623 player->anim_delay_counter--;
7625 else if (player->post_delay_counter > 0)
7627 player->post_delay_counter--;
7632 else if (last_waiting) /* waiting -> not waiting */
7634 player->is_waiting = FALSE;
7635 player->is_bored = FALSE;
7636 player->is_sleeping = FALSE;
7638 player->frame_counter_bored = -1;
7639 player->frame_counter_sleeping = -1;
7641 player->anim_delay_counter = 0;
7642 player->post_delay_counter = 0;
7644 player->action_waiting = ACTION_DEFAULT;
7646 player->special_action_bored = ACTION_DEFAULT;
7647 player->special_action_sleeping = ACTION_DEFAULT;
7652 static byte PlayerActions(struct PlayerInfo *player, byte player_action)
7655 static byte stored_player_action[MAX_PLAYERS];
7656 static int num_stored_actions = 0;
7658 boolean moved = FALSE, snapped = FALSE, dropped = FALSE;
7659 int left = player_action & JOY_LEFT;
7660 int right = player_action & JOY_RIGHT;
7661 int up = player_action & JOY_UP;
7662 int down = player_action & JOY_DOWN;
7663 int button1 = player_action & JOY_BUTTON_1;
7664 int button2 = player_action & JOY_BUTTON_2;
7665 int dx = (left ? -1 : right ? 1 : 0);
7666 int dy = (up ? -1 : down ? 1 : 0);
7669 stored_player_action[player->index_nr] = 0;
7670 num_stored_actions++;
7674 printf("::: player %d [%d]\n", player->index_nr, FrameCounter);
7677 if (!player->active || tape.pausing)
7681 printf("::: [%d %d %d %d] [%d %d]\n",
7682 left, right, up, down, button1, button2);
7688 printf("::: player %d acts [%d]\n", player->index_nr, FrameCounter);
7693 if (player->MovPos == 0)
7694 CheckGravityMovement(player);
7697 snapped = SnapField(player, dx, dy);
7701 dropped = DropElement(player);
7703 moved = MovePlayer(player, dx, dy);
7706 if (tape.single_step && tape.recording && !tape.pausing)
7708 if (button1 || (dropped && !moved))
7710 TapeTogglePause(TAPE_TOGGLE_AUTOMATIC);
7711 SnapField(player, 0, 0); /* stop snapping */
7715 SetPlayerWaiting(player, FALSE);
7718 return player_action;
7720 stored_player_action[player->index_nr] = player_action;
7726 printf("::: player %d waits [%d]\n", player->index_nr, FrameCounter);
7729 /* no actions for this player (no input at player's configured device) */
7731 DigField(player, 0, 0, 0, 0, 0, 0, DF_NO_PUSH);
7732 SnapField(player, 0, 0);
7733 CheckGravityMovementWhenNotMoving(player);
7735 if (player->MovPos == 0)
7736 SetPlayerWaiting(player, TRUE);
7738 if (player->MovPos == 0) /* needed for tape.playing */
7739 player->is_moving = FALSE;
7741 player->is_dropping = FALSE;
7747 if (tape.recording && num_stored_actions >= MAX_PLAYERS)
7749 printf("::: player %d recorded [%d]\n", player->index_nr, FrameCounter);
7751 TapeRecordAction(stored_player_action);
7752 num_stored_actions = 0;
7759 static void PlayerActions(struct PlayerInfo *player, byte player_action)
7761 static byte stored_player_action[MAX_PLAYERS];
7762 static int num_stored_actions = 0;
7763 boolean moved = FALSE, snapped = FALSE, dropped = FALSE;
7764 int left = player_action & JOY_LEFT;
7765 int right = player_action & JOY_RIGHT;
7766 int up = player_action & JOY_UP;
7767 int down = player_action & JOY_DOWN;
7768 int button1 = player_action & JOY_BUTTON_1;
7769 int button2 = player_action & JOY_BUTTON_2;
7770 int dx = (left ? -1 : right ? 1 : 0);
7771 int dy = (up ? -1 : down ? 1 : 0);
7773 stored_player_action[player->index_nr] = 0;
7774 num_stored_actions++;
7776 printf("::: player %d [%d]\n", player->index_nr, FrameCounter);
7778 if (!player->active || tape.pausing)
7783 printf("::: player %d acts [%d]\n", player->index_nr, FrameCounter);
7786 snapped = SnapField(player, dx, dy);
7790 dropped = DropElement(player);
7792 moved = MovePlayer(player, dx, dy);
7795 if (tape.single_step && tape.recording && !tape.pausing)
7797 if (button1 || (dropped && !moved))
7799 TapeTogglePause(TAPE_TOGGLE_AUTOMATIC);
7800 SnapField(player, 0, 0); /* stop snapping */
7804 stored_player_action[player->index_nr] = player_action;
7808 printf("::: player %d waits [%d]\n", player->index_nr, FrameCounter);
7810 /* no actions for this player (no input at player's configured device) */
7812 DigField(player, 0, 0, 0, 0, 0, 0, DF_NO_PUSH);
7813 SnapField(player, 0, 0);
7814 CheckGravityMovementWhenNotMoving(player);
7816 if (player->MovPos == 0)
7817 InitPlayerGfxAnimation(player, ACTION_DEFAULT, player->MovDir);
7819 if (player->MovPos == 0) /* needed for tape.playing */
7820 player->is_moving = FALSE;
7823 if (tape.recording && num_stored_actions >= MAX_PLAYERS)
7825 printf("::: player %d recorded [%d]\n", player->index_nr, FrameCounter);
7827 TapeRecordAction(stored_player_action);
7828 num_stored_actions = 0;
7835 static unsigned long action_delay = 0;
7836 unsigned long action_delay_value;
7837 int magic_wall_x = 0, magic_wall_y = 0;
7838 int i, x, y, element, graphic;
7839 byte *recorded_player_action;
7840 byte summarized_player_action = 0;
7842 byte tape_action[MAX_PLAYERS];
7845 if (game_status != GAME_MODE_PLAYING)
7848 action_delay_value =
7849 (tape.playing && tape.fast_forward ? FfwdFrameDelay : GameFrameDelay);
7851 if (tape.playing && tape.warp_forward && !tape.pausing)
7852 action_delay_value = 0;
7854 /* ---------- main game synchronization point ---------- */
7856 WaitUntilDelayReached(&action_delay, action_delay_value);
7858 if (network_playing && !network_player_action_received)
7862 printf("DEBUG: try to get network player actions in time\n");
7866 #if defined(PLATFORM_UNIX)
7867 /* last chance to get network player actions without main loop delay */
7871 if (game_status != GAME_MODE_PLAYING)
7874 if (!network_player_action_received)
7878 printf("DEBUG: failed to get network player actions in time\n");
7889 printf("::: getting new tape action [%d]\n", FrameCounter);
7892 recorded_player_action = (tape.playing ? TapePlayAction() : NULL);
7895 if (recorded_player_action == NULL && tape.pausing)
7900 printf("::: %d\n", stored_player[0].action);
7904 if (recorded_player_action != NULL)
7905 for (i = 0; i < MAX_PLAYERS; i++)
7906 stored_player[i].action = recorded_player_action[i];
7909 for (i = 0; i < MAX_PLAYERS; i++)
7911 summarized_player_action |= stored_player[i].action;
7913 if (!network_playing)
7914 stored_player[i].effective_action = stored_player[i].action;
7917 #if defined(PLATFORM_UNIX)
7918 if (network_playing)
7919 SendToServer_MovePlayer(summarized_player_action);
7922 if (!options.network && !setup.team_mode)
7923 local_player->effective_action = summarized_player_action;
7926 if (recorded_player_action != NULL)
7927 for (i = 0; i < MAX_PLAYERS; i++)
7928 stored_player[i].effective_action = recorded_player_action[i];
7932 for (i = 0; i < MAX_PLAYERS; i++)
7934 tape_action[i] = stored_player[i].effective_action;
7936 if (tape.recording && tape_action[i] && !tape.player_participates[i])
7937 tape.player_participates[i] = TRUE; /* player just appeared from CE */
7940 /* only save actions from input devices, but not programmed actions */
7942 TapeRecordAction(tape_action);
7945 for (i = 0; i < MAX_PLAYERS; i++)
7947 int actual_player_action = stored_player[i].effective_action;
7950 /* !!! THIS BREAKS THE FOLLOWING TAPES: !!!
7951 - rnd_equinox_tetrachloride 048
7952 - rnd_equinox_tetrachloride_ii 096
7953 - rnd_emanuel_schmieg 002
7954 - doctor_sloan_ww 001, 020
7956 if (stored_player[i].MovPos == 0)
7957 CheckGravityMovement(&stored_player[i]);
7961 /* overwrite programmed action with tape action */
7962 if (stored_player[i].programmed_action)
7963 actual_player_action = stored_player[i].programmed_action;
7967 if (stored_player[i].programmed_action)
7968 printf("::: %d\n", stored_player[i].programmed_action);
7971 if (recorded_player_action)
7974 if (stored_player[i].programmed_action &&
7975 stored_player[i].programmed_action != recorded_player_action[i])
7976 printf("::: %d: %d <-> %d\n", i,
7977 stored_player[i].programmed_action, recorded_player_action[i]);
7981 actual_player_action = recorded_player_action[i];
7986 /* overwrite tape action with programmed action */
7987 if (stored_player[i].programmed_action)
7988 actual_player_action = stored_player[i].programmed_action;
7993 printf("::: action: %d: %x [%d]\n",
7994 stored_player[i].MovPos, actual_player_action, FrameCounter);
7998 PlayerActions(&stored_player[i], actual_player_action);
8000 tape_action[i] = PlayerActions(&stored_player[i], actual_player_action);
8002 if (tape.recording && tape_action[i] && !tape.player_participates[i])
8003 tape.player_participates[i] = TRUE; /* player just appeared from CE */
8006 ScrollPlayer(&stored_player[i], SCROLL_GO_ON);
8011 TapeRecordAction(tape_action);
8014 network_player_action_received = FALSE;
8016 ScrollScreen(NULL, SCROLL_GO_ON);
8022 for (i = 0; i < MAX_PLAYERS; i++)
8023 stored_player[i].Frame++;
8027 /* for downwards compatibility, the following code emulates a fixed bug that
8028 occured when pushing elements (causing elements that just made their last
8029 pushing step to already (if possible) make their first falling step in the
8030 same game frame, which is bad); this code is also needed to use the famous
8031 "spring push bug" which is used in older levels and might be wanted to be
8032 used also in newer levels, but in this case the buggy pushing code is only
8033 affecting the "spring" element and no other elements */
8036 if (game.engine_version < VERSION_IDENT(2,2,0,7) || level.use_spring_bug)
8038 if (game.engine_version < VERSION_IDENT(2,2,0,7))
8041 for (i = 0; i < MAX_PLAYERS; i++)
8043 struct PlayerInfo *player = &stored_player[i];
8048 if (player->active && player->is_pushing && player->is_moving &&
8050 (game.engine_version < VERSION_IDENT(2,2,0,7) ||
8051 Feld[x][y] == EL_SPRING))
8053 if (player->active && player->is_pushing && player->is_moving &&
8057 ContinueMoving(x, y);
8059 /* continue moving after pushing (this is actually a bug) */
8060 if (!IS_MOVING(x, y))
8069 for (y = 0; y < lev_fieldy; y++) for (x = 0; x < lev_fieldx; x++)
8071 Changed[x][y] = CE_BITMASK_DEFAULT;
8072 ChangeEvent[x][y] = CE_BITMASK_DEFAULT;
8075 if (ChangePage[x][y] != -1 && ChangeDelay[x][y] != 1)
8077 printf("GameActions(): x = %d, y = %d: ChangePage != -1\n", x, y);
8078 printf("GameActions(): This should never happen!\n");
8080 ChangePage[x][y] = -1;
8085 if (WasJustMoving[x][y] > 0)
8086 WasJustMoving[x][y]--;
8087 if (WasJustFalling[x][y] > 0)
8088 WasJustFalling[x][y]--;
8093 /* reset finished pushing action (not done in ContinueMoving() to allow
8094 continous pushing animation for elements with zero push delay) */
8095 if (GfxAction[x][y] == ACTION_PUSHING && !IS_MOVING(x, y))
8097 ResetGfxAnimation(x, y);
8098 DrawLevelField(x, y);
8103 if (IS_BLOCKED(x, y))
8107 Blocked2Moving(x, y, &oldx, &oldy);
8108 if (!IS_MOVING(oldx, oldy))
8110 printf("GameActions(): (BLOCKED => MOVING) context corrupted!\n");
8111 printf("GameActions(): BLOCKED: x = %d, y = %d\n", x, y);
8112 printf("GameActions(): !MOVING: oldx = %d, oldy = %d\n", oldx, oldy);
8113 printf("GameActions(): This should never happen!\n");
8119 for (y = 0; y < lev_fieldy; y++) for (x = 0; x < lev_fieldx; x++)
8121 element = Feld[x][y];
8123 graphic = el_act_dir2img(element, GfxAction[x][y], GfxDir[x][y]);
8125 graphic = el2img(element);
8131 printf("::: %d,%d: %d [%d]\n", x, y, element, FrameCounter);
8133 element = graphic = 0;
8137 if (graphic_info[graphic].anim_global_sync)
8138 GfxFrame[x][y] = FrameCounter;
8140 if (ANIM_MODE(graphic) == ANIM_RANDOM &&
8141 IS_NEXT_FRAME(GfxFrame[x][y], graphic))
8142 ResetRandomAnimationValue(x, y);
8144 SetRandomAnimationValue(x, y);
8147 PlayLevelSoundActionIfLoop(x, y, GfxAction[x][y]);
8150 if (IS_INACTIVE(element))
8152 if (IS_ANIMATED(graphic))
8153 DrawLevelGraphicAnimationIfNeeded(x, y, graphic);
8159 /* this may take place after moving, so 'element' may have changed */
8161 if (IS_CHANGING(x, y))
8163 if (IS_CHANGING(x, y) &&
8164 (game.engine_version < VERSION_IDENT(3,0,7,1) || !Stop[x][y]))
8168 ChangeElement(x, y, ChangePage[x][y] != -1 ? ChangePage[x][y] :
8169 element_info[element].event_page_nr[CE_DELAY]);
8171 ChangeElement(x, y, element_info[element].event_page_nr[CE_DELAY]);
8174 element = Feld[x][y];
8175 graphic = el_act_dir2img(element, GfxAction[x][y], GfxDir[x][y]);
8179 if (!IS_MOVING(x, y) && (CAN_FALL(element) || CAN_MOVE(element)))
8184 element = Feld[x][y];
8185 graphic = el_act_dir2img(element, GfxAction[x][y], GfxDir[x][y]);
8187 if (element == EL_MOLE)
8188 printf("::: %d, %d, %d [%d]\n",
8189 IS_ANIMATED(graphic), IS_MOVING(x, y), Stop[x][y],
8193 if (element == EL_YAMYAM)
8194 printf("::: %d, %d, %d\n",
8195 IS_ANIMATED(graphic), IS_MOVING(x, y), Stop[x][y]);
8199 if (IS_ANIMATED(graphic) &&
8203 DrawLevelGraphicAnimationIfNeeded(x, y, graphic);
8206 if (element == EL_BUG)
8207 printf("::: %d, %d\n", graphic, GfxFrame[x][y]);
8211 if (element == EL_MOLE)
8212 printf("::: %d, %d\n", graphic, GfxFrame[x][y]);
8216 if (IS_GEM(element) || element == EL_SP_INFOTRON)
8217 EdelsteinFunkeln(x, y);
8219 else if ((element == EL_ACID ||
8220 element == EL_EXIT_OPEN ||
8221 element == EL_SP_EXIT_OPEN ||
8222 element == EL_SP_TERMINAL ||
8223 element == EL_SP_TERMINAL_ACTIVE ||
8224 element == EL_EXTRA_TIME ||
8225 element == EL_SHIELD_NORMAL ||
8226 element == EL_SHIELD_DEADLY) &&
8227 IS_ANIMATED(graphic))
8228 DrawLevelGraphicAnimationIfNeeded(x, y, graphic);
8229 else if (IS_MOVING(x, y))
8230 ContinueMoving(x, y);
8231 else if (IS_ACTIVE_BOMB(element))
8232 CheckDynamite(x, y);
8234 else if (element == EL_EXPLOSION && !game.explosions_delayed)
8235 Explode(x, y, ExplodePhase[x][y], EX_TYPE_NORMAL);
8237 else if (element == EL_AMOEBA_GROWING)
8238 AmoebeWaechst(x, y);
8239 else if (element == EL_AMOEBA_SHRINKING)
8240 AmoebaDisappearing(x, y);
8242 #if !USE_NEW_AMOEBA_CODE
8243 else if (IS_AMOEBALIVE(element))
8244 AmoebeAbleger(x, y);
8247 else if (element == EL_GAME_OF_LIFE || element == EL_BIOMAZE)
8249 else if (element == EL_EXIT_CLOSED)
8251 else if (element == EL_SP_EXIT_CLOSED)
8253 else if (element == EL_EXPANDABLE_WALL_GROWING)
8255 else if (element == EL_EXPANDABLE_WALL ||
8256 element == EL_EXPANDABLE_WALL_HORIZONTAL ||
8257 element == EL_EXPANDABLE_WALL_VERTICAL ||
8258 element == EL_EXPANDABLE_WALL_ANY)
8260 else if (element == EL_FLAMES)
8261 CheckForDragon(x, y);
8263 else if (IS_AUTO_CHANGING(element))
8264 ChangeElement(x, y);
8266 else if (element == EL_EXPLOSION)
8267 ; /* drawing of correct explosion animation is handled separately */
8268 else if (IS_ANIMATED(graphic) && !IS_CHANGING(x, y))
8269 DrawLevelGraphicAnimationIfNeeded(x, y, graphic);
8272 /* this may take place after moving, so 'element' may have changed */
8273 if (IS_AUTO_CHANGING(Feld[x][y]))
8274 ChangeElement(x, y);
8277 if (IS_BELT_ACTIVE(element))
8278 PlayLevelSoundAction(x, y, ACTION_ACTIVE);
8280 if (game.magic_wall_active)
8282 int jx = local_player->jx, jy = local_player->jy;
8284 /* play the element sound at the position nearest to the player */
8285 if ((element == EL_MAGIC_WALL_FULL ||
8286 element == EL_MAGIC_WALL_ACTIVE ||
8287 element == EL_MAGIC_WALL_EMPTYING ||
8288 element == EL_BD_MAGIC_WALL_FULL ||
8289 element == EL_BD_MAGIC_WALL_ACTIVE ||
8290 element == EL_BD_MAGIC_WALL_EMPTYING) &&
8291 ABS(x-jx) + ABS(y-jy) < ABS(magic_wall_x-jx) + ABS(magic_wall_y-jy))
8299 #if USE_NEW_AMOEBA_CODE
8300 /* new experimental amoeba growth stuff */
8302 if (!(FrameCounter % 8))
8305 static unsigned long random = 1684108901;
8307 for (i = 0; i < level.amoeba_speed * 28 / 8; i++)
8310 x = (random >> 10) % lev_fieldx;
8311 y = (random >> 20) % lev_fieldy;
8313 x = RND(lev_fieldx);
8314 y = RND(lev_fieldy);
8316 element = Feld[x][y];
8318 /* !!! extend EL_SAND to anything diggable (but maybe not SP_BASE) !!! */
8319 if (!IS_PLAYER(x,y) &&
8320 (element == EL_EMPTY ||
8321 element == EL_SAND ||
8322 element == EL_QUICKSAND_EMPTY ||
8323 element == EL_ACID_SPLASH_LEFT ||
8324 element == EL_ACID_SPLASH_RIGHT))
8326 if ((IN_LEV_FIELD(x, y-1) && Feld[x][y-1] == EL_AMOEBA_WET) ||
8327 (IN_LEV_FIELD(x-1, y) && Feld[x-1][y] == EL_AMOEBA_WET) ||
8328 (IN_LEV_FIELD(x+1, y) && Feld[x+1][y] == EL_AMOEBA_WET) ||
8329 (IN_LEV_FIELD(x, y+1) && Feld[x][y+1] == EL_AMOEBA_WET))
8330 Feld[x][y] = EL_AMOEBA_DROP;
8333 random = random * 129 + 1;
8339 if (game.explosions_delayed)
8342 game.explosions_delayed = FALSE;
8344 for (y = 0; y < lev_fieldy; y++) for (x = 0; x < lev_fieldx; x++)
8346 element = Feld[x][y];
8348 if (ExplodeField[x][y])
8349 Explode(x, y, EX_PHASE_START, ExplodeField[x][y]);
8350 else if (element == EL_EXPLOSION)
8351 Explode(x, y, ExplodePhase[x][y], EX_TYPE_NORMAL);
8353 ExplodeField[x][y] = EX_TYPE_NONE;
8356 game.explosions_delayed = TRUE;
8359 if (game.magic_wall_active)
8361 if (!(game.magic_wall_time_left % 4))
8363 int element = Feld[magic_wall_x][magic_wall_y];
8365 if (element == EL_BD_MAGIC_WALL_FULL ||
8366 element == EL_BD_MAGIC_WALL_ACTIVE ||
8367 element == EL_BD_MAGIC_WALL_EMPTYING)
8368 PlayLevelSound(magic_wall_x, magic_wall_y, SND_BD_MAGIC_WALL_ACTIVE);
8370 PlayLevelSound(magic_wall_x, magic_wall_y, SND_MAGIC_WALL_ACTIVE);
8373 if (game.magic_wall_time_left > 0)
8375 game.magic_wall_time_left--;
8376 if (!game.magic_wall_time_left)
8378 for (y = 0; y < lev_fieldy; y++) for (x = 0; x < lev_fieldx; x++)
8380 element = Feld[x][y];
8382 if (element == EL_MAGIC_WALL_ACTIVE ||
8383 element == EL_MAGIC_WALL_FULL)
8385 Feld[x][y] = EL_MAGIC_WALL_DEAD;
8386 DrawLevelField(x, y);
8388 else if (element == EL_BD_MAGIC_WALL_ACTIVE ||
8389 element == EL_BD_MAGIC_WALL_FULL)
8391 Feld[x][y] = EL_BD_MAGIC_WALL_DEAD;
8392 DrawLevelField(x, y);
8396 game.magic_wall_active = FALSE;
8401 if (game.light_time_left > 0)
8403 game.light_time_left--;
8405 if (game.light_time_left == 0)
8406 RedrawAllLightSwitchesAndInvisibleElements();
8409 if (game.timegate_time_left > 0)
8411 game.timegate_time_left--;
8413 if (game.timegate_time_left == 0)
8414 CloseAllOpenTimegates();
8417 for (i = 0; i < MAX_PLAYERS; i++)
8419 struct PlayerInfo *player = &stored_player[i];
8421 if (SHIELD_ON(player))
8423 if (player->shield_deadly_time_left)
8424 PlayLevelSound(player->jx, player->jy, SND_SHIELD_DEADLY_ACTIVE);
8425 else if (player->shield_normal_time_left)
8426 PlayLevelSound(player->jx, player->jy, SND_SHIELD_NORMAL_ACTIVE);
8430 if (TimeFrames >= FRAMES_PER_SECOND)
8435 if (!level.use_step_counter)
8439 for (i = 0; i < MAX_PLAYERS; i++)
8441 struct PlayerInfo *player = &stored_player[i];
8443 if (SHIELD_ON(player))
8445 player->shield_normal_time_left--;
8447 if (player->shield_deadly_time_left > 0)
8448 player->shield_deadly_time_left--;
8456 if (TimeLeft <= 10 && setup.time_limit)
8457 PlaySoundStereo(SND_GAME_RUNNING_OUT_OF_TIME, SOUND_MIDDLE);
8459 DrawGameValue_Time(TimeLeft);
8461 if (!TimeLeft && setup.time_limit)
8462 for (i = 0; i < MAX_PLAYERS; i++)
8463 KillHero(&stored_player[i]);
8465 else if (level.time == 0 && !AllPlayersGone) /* level w/o time limit */
8466 DrawGameValue_Time(TimePlayed);
8469 if (tape.recording || tape.playing)
8470 DrawVideoDisplay(VIDEO_STATE_TIME_ON, TapeTime);
8474 PlayAllPlayersSound();
8476 if (options.debug) /* calculate frames per second */
8478 static unsigned long fps_counter = 0;
8479 static int fps_frames = 0;
8480 unsigned long fps_delay_ms = Counter() - fps_counter;
8484 if (fps_delay_ms >= 500) /* calculate fps every 0.5 seconds */
8486 global.frames_per_second = 1000 * (float)fps_frames / fps_delay_ms;
8489 fps_counter = Counter();
8492 redraw_mask |= REDRAW_FPS;
8496 if (stored_player[0].jx != stored_player[0].last_jx ||
8497 stored_player[0].jy != stored_player[0].last_jy)
8498 printf("::: %d, %d, %d, %d, %d\n",
8499 stored_player[0].MovDir,
8500 stored_player[0].MovPos,
8501 stored_player[0].GfxPos,
8502 stored_player[0].Frame,
8503 stored_player[0].StepFrame);
8510 for (i = 0; i < MAX_PLAYERS; i++)
8513 MOVE_DELAY_NORMAL_SPEED / stored_player[i].move_delay_value;
8515 stored_player[i].Frame += move_frames;
8517 if (stored_player[i].MovPos != 0)
8518 stored_player[i].StepFrame += move_frames;
8520 if (stored_player[i].drop_delay > 0)
8521 stored_player[i].drop_delay--;
8526 if (local_player->show_envelope != 0 && local_player->MovPos == 0)
8528 ShowEnvelope(local_player->show_envelope - EL_ENVELOPE_1);
8530 local_player->show_envelope = 0;
8535 static boolean AllPlayersInSight(struct PlayerInfo *player, int x, int y)
8537 int min_x = x, min_y = y, max_x = x, max_y = y;
8540 for (i = 0; i < MAX_PLAYERS; i++)
8542 int jx = stored_player[i].jx, jy = stored_player[i].jy;
8544 if (!stored_player[i].active || &stored_player[i] == player)
8547 min_x = MIN(min_x, jx);
8548 min_y = MIN(min_y, jy);
8549 max_x = MAX(max_x, jx);
8550 max_y = MAX(max_y, jy);
8553 return (max_x - min_x < SCR_FIELDX && max_y - min_y < SCR_FIELDY);
8556 static boolean AllPlayersInVisibleScreen()
8560 for (i = 0; i < MAX_PLAYERS; i++)
8562 int jx = stored_player[i].jx, jy = stored_player[i].jy;
8564 if (!stored_player[i].active)
8567 if (!IN_VIS_FIELD(SCREENX(jx), SCREENY(jy)))
8574 void ScrollLevel(int dx, int dy)
8576 int softscroll_offset = (setup.soft_scrolling ? TILEX : 0);
8579 BlitBitmap(drawto_field, drawto_field,
8580 FX + TILEX * (dx == -1) - softscroll_offset,
8581 FY + TILEY * (dy == -1) - softscroll_offset,
8582 SXSIZE - TILEX * (dx!=0) + 2 * softscroll_offset,
8583 SYSIZE - TILEY * (dy!=0) + 2 * softscroll_offset,
8584 FX + TILEX * (dx == 1) - softscroll_offset,
8585 FY + TILEY * (dy == 1) - softscroll_offset);
8589 x = (dx == 1 ? BX1 : BX2);
8590 for (y = BY1; y <= BY2; y++)
8591 DrawScreenField(x, y);
8596 y = (dy == 1 ? BY1 : BY2);
8597 for (x = BX1; x <= BX2; x++)
8598 DrawScreenField(x, y);
8601 redraw_mask |= REDRAW_FIELD;
8605 static boolean canEnterSupaplexPort(int x, int y, int dx, int dy)
8607 int nextx = x + dx, nexty = y + dy;
8608 int element = Feld[x][y];
8611 element != EL_SP_PORT_LEFT &&
8612 element != EL_SP_GRAVITY_PORT_LEFT &&
8613 element != EL_SP_PORT_HORIZONTAL &&
8614 element != EL_SP_PORT_ANY) ||
8616 element != EL_SP_PORT_RIGHT &&
8617 element != EL_SP_GRAVITY_PORT_RIGHT &&
8618 element != EL_SP_PORT_HORIZONTAL &&
8619 element != EL_SP_PORT_ANY) ||
8621 element != EL_SP_PORT_UP &&
8622 element != EL_SP_GRAVITY_PORT_UP &&
8623 element != EL_SP_PORT_VERTICAL &&
8624 element != EL_SP_PORT_ANY) ||
8626 element != EL_SP_PORT_DOWN &&
8627 element != EL_SP_GRAVITY_PORT_DOWN &&
8628 element != EL_SP_PORT_VERTICAL &&
8629 element != EL_SP_PORT_ANY) ||
8630 !IN_LEV_FIELD(nextx, nexty) ||
8631 !IS_FREE(nextx, nexty))
8638 static boolean canFallDown(struct PlayerInfo *player)
8640 int jx = player->jx, jy = player->jy;
8642 return (IN_LEV_FIELD(jx, jy + 1) &&
8643 (IS_FREE(jx, jy + 1) ||
8644 (Feld[jx][jy + 1] == EL_ACID && player->can_fall_into_acid)) &&
8645 IS_WALKABLE_FROM(Feld[jx][jy], MV_DOWN) &&
8646 !IS_WALKABLE_INSIDE(Feld[jx][jy]));
8649 static boolean canPassField(int x, int y, int move_dir)
8651 int opposite_dir = MV_DIR_OPPOSITE(move_dir);
8652 int dx = (move_dir & MV_LEFT ? -1 : move_dir & MV_RIGHT ? +1 : 0);
8653 int dy = (move_dir & MV_UP ? -1 : move_dir & MV_DOWN ? +1 : 0);
8656 int element = Feld[x][y];
8658 return (IS_PASSABLE_FROM(element, opposite_dir) &&
8659 !CAN_MOVE(element) &&
8660 IN_LEV_FIELD(nextx, nexty) && !IS_PLAYER(nextx, nexty) &&
8661 IS_WALKABLE_FROM(Feld[nextx][nexty], move_dir) &&
8662 (level.can_pass_to_walkable || IS_FREE(nextx, nexty)));
8665 static boolean canMoveToValidFieldWithGravity(int x, int y, int move_dir)
8667 int opposite_dir = MV_DIR_OPPOSITE(move_dir);
8668 int dx = (move_dir & MV_LEFT ? -1 : move_dir & MV_RIGHT ? +1 : 0);
8669 int dy = (move_dir & MV_UP ? -1 : move_dir & MV_DOWN ? +1 : 0);
8673 int nextx = newx + dx;
8674 int nexty = newy + dy;
8678 return (IN_LEV_FIELD(newx, newy) && !IS_FREE_OR_PLAYER(newx, newy) &&
8679 (IS_DIGGABLE(Feld[newx][newy]) ||
8680 IS_WALKABLE_FROM(Feld[newx][newy], opposite_dir) ||
8681 canPassField(newx, newy, move_dir)));
8683 return (IN_LEV_FIELD(newx, newy) && !IS_FREE_OR_PLAYER(newx, newy) &&
8684 (IS_DIGGABLE(Feld[newx][newy]) ||
8685 IS_WALKABLE_FROM(Feld[newx][newy], opposite_dir) ||
8686 (IS_PASSABLE_FROM(Feld[newx][newy], opposite_dir) &&
8687 !CAN_MOVE(Feld[newx][newy]) &&
8688 IN_LEV_FIELD(nextx, nexty) && !IS_PLAYER(nextx, nexty) &&
8689 IS_WALKABLE_FROM(Feld[nextx][nexty], move_dir) &&
8690 (level.can_pass_to_walkable || IS_FREE(nextx, nexty)))));
8694 static void CheckGravityMovement(struct PlayerInfo *player)
8696 if (game.gravity && !player->programmed_action)
8699 int move_dir_horizontal = player->effective_action & MV_HORIZONTAL;
8700 int move_dir_vertical = player->effective_action & MV_VERTICAL;
8702 int move_dir_horizontal = player->action & MV_HORIZONTAL;
8703 int move_dir_vertical = player->action & MV_VERTICAL;
8706 boolean player_is_snapping = player->effective_action & JOY_BUTTON_1;
8708 boolean player_is_snapping = player->action & JOY_BUTTON_1;
8711 int jx = player->jx, jy = player->jy;
8713 boolean player_is_moving_to_valid_field =
8714 (!player_is_snapping &&
8715 (canMoveToValidFieldWithGravity(jx, jy, move_dir_horizontal) ||
8716 canMoveToValidFieldWithGravity(jx, jy, move_dir_vertical)));
8720 (player->last_move_dir & MV_HORIZONTAL ?
8721 (move_dir_vertical ? move_dir_vertical : move_dir_horizontal) :
8722 (move_dir_horizontal ? move_dir_horizontal : move_dir_vertical));
8726 int opposite_dir = MV_DIR_OPPOSITE(move_dir);
8727 int dx = (move_dir & MV_LEFT ? -1 : move_dir & MV_RIGHT ? +1 : 0);
8728 int dy = (move_dir & MV_UP ? -1 : move_dir & MV_DOWN ? +1 : 0);
8729 int new_jx = jx + dx, new_jy = jy + dy;
8730 int nextx = new_jx + dx, nexty = new_jy + dy;
8736 boolean player_can_fall_down = canFallDown(player);
8738 boolean player_can_fall_down =
8739 (IN_LEV_FIELD(jx, jy + 1) &&
8740 (IS_FREE(jx, jy + 1) ||
8741 (Feld[jx][jy + 1] == EL_ACID && player->can_fall_into_acid)));
8745 boolean player_can_fall_down =
8746 (IN_LEV_FIELD(jx, jy + 1) &&
8747 (IS_FREE(jx, jy + 1)));
8750 boolean player_is_moving_to_valid_field =
8753 !player_is_snapping &&
8757 IN_LEV_FIELD(new_jx, new_jy) &&
8758 (IS_DIGGABLE(Feld[new_jx][new_jy]) ||
8759 (IS_SP_PORT(Feld[new_jx][new_jy]) &&
8760 element_info[Feld[new_jx][new_jy]].access_direction & opposite_dir &&
8761 IN_LEV_FIELD(nextx, nexty) &&
8762 element_info[Feld[nextx][nexty]].access_direction & move_dir))
8764 IN_LEV_FIELD(new_jx, new_jy) &&
8765 (Feld[new_jx][new_jy] == EL_SP_BASE ||
8766 Feld[new_jx][new_jy] == EL_SAND ||
8767 (IS_SP_PORT(Feld[new_jx][new_jy]) &&
8768 canEnterSupaplexPort(new_jx, new_jy, dx, dy)))
8769 /* !!! extend EL_SAND to anything diggable !!! */
8775 boolean player_is_standing_on_valid_field =
8776 (IS_WALKABLE_INSIDE(Feld[jx][jy]) ||
8777 (IS_WALKABLE(Feld[jx][jy]) && !ACCESS_FROM(Feld[jx][jy], MV_DOWN)));
8781 printf("::: checking gravity NOW [%d, %d, %d] [%d] [%d / %d] ...\n",
8782 player_can_fall_down,
8783 player_is_standing_on_valid_field,
8784 player_is_moving_to_valid_field,
8785 (player_is_moving_to_valid_field ? Feld[new_jx][new_jy] : -1),
8786 player->effective_action,
8787 player->can_fall_into_acid);
8790 if (player_can_fall_down &&
8792 !player_is_standing_on_valid_field &&
8794 !player_is_moving_to_valid_field)
8797 printf("::: setting programmed_action to MV_DOWN [%d,%d - %d] ...\n",
8798 jx, jy, FrameCounter);
8801 player->programmed_action = MV_DOWN;
8806 static void CheckGravityMovementWhenNotMoving(struct PlayerInfo *player)
8809 return CheckGravityMovement(player);
8812 if (game.gravity && !player->programmed_action)
8814 int jx = player->jx, jy = player->jy;
8815 boolean field_under_player_is_free =
8816 (IN_LEV_FIELD(jx, jy + 1) && IS_FREE(jx, jy + 1));
8817 boolean player_is_standing_on_valid_field =
8818 (IS_WALKABLE_INSIDE(Feld[jx][jy]) ||
8819 (IS_WALKABLE(Feld[jx][jy]) &&
8820 !(element_info[Feld[jx][jy]].access_direction & MV_DOWN)));
8822 if (field_under_player_is_free && !player_is_standing_on_valid_field)
8823 player->programmed_action = MV_DOWN;
8829 -----------------------------------------------------------------------------
8830 dx, dy: direction (non-diagonal) to try to move the player to
8831 real_dx, real_dy: direction as read from input device (can be diagonal)
8834 boolean MovePlayerOneStep(struct PlayerInfo *player,
8835 int dx, int dy, int real_dx, int real_dy)
8838 static int trigger_sides[4][2] =
8840 /* enter side leave side */
8841 { CH_SIDE_RIGHT, CH_SIDE_LEFT }, /* moving left */
8842 { CH_SIDE_LEFT, CH_SIDE_RIGHT }, /* moving right */
8843 { CH_SIDE_BOTTOM, CH_SIDE_TOP }, /* moving up */
8844 { CH_SIDE_TOP, CH_SIDE_BOTTOM } /* moving down */
8846 int move_direction = (dx == -1 ? MV_LEFT :
8847 dx == +1 ? MV_RIGHT :
8849 dy == +1 ? MV_DOWN : MV_NO_MOVING);
8850 int enter_side = trigger_sides[MV_DIR_BIT(move_direction)][0];
8851 int leave_side = trigger_sides[MV_DIR_BIT(move_direction)][1];
8853 int jx = player->jx, jy = player->jy;
8854 int new_jx = jx + dx, new_jy = jy + dy;
8858 if (!player->active || (!dx && !dy))
8859 return MF_NO_ACTION;
8861 player->MovDir = (dx < 0 ? MV_LEFT :
8864 dy > 0 ? MV_DOWN : MV_NO_MOVING);
8866 if (!IN_LEV_FIELD(new_jx, new_jy))
8867 return MF_NO_ACTION;
8869 if (!options.network && !AllPlayersInSight(player, new_jx, new_jy))
8870 return MF_NO_ACTION;
8873 element = MovingOrBlocked2Element(new_jx, new_jy);
8875 element = MovingOrBlocked2ElementIfNotLeaving(new_jx, new_jy);
8878 if (DONT_RUN_INTO(element))
8880 if (element == EL_ACID && dx == 0 && dy == 1)
8882 SplashAcid(new_jx, new_jy);
8883 Feld[jx][jy] = EL_PLAYER_1;
8884 InitMovingField(jx, jy, MV_DOWN);
8885 Store[jx][jy] = EL_ACID;
8886 ContinueMoving(jx, jy);
8890 TestIfHeroRunsIntoBadThing(jx, jy, player->MovDir);
8895 can_move = DigField(player, jx, jy, new_jx, new_jy, real_dx,real_dy, DF_DIG);
8896 if (can_move != MF_MOVING)
8899 /* check if DigField() has caused relocation of the player */
8900 if (player->jx != jx || player->jy != jy)
8901 return MF_NO_ACTION;
8903 StorePlayer[jx][jy] = 0;
8904 player->last_jx = jx;
8905 player->last_jy = jy;
8906 player->jx = new_jx;
8907 player->jy = new_jy;
8908 StorePlayer[new_jx][new_jy] = player->element_nr;
8911 (dx > 0 || dy > 0 ? -1 : 1) * (TILEX - TILEX / player->move_delay_value);
8913 player->step_counter++;
8916 player->drop_delay = 0;
8919 PlayerVisit[jx][jy] = FrameCounter;
8921 ScrollPlayer(player, SCROLL_INIT);
8924 if (IS_CUSTOM_ELEMENT(Feld[jx][jy]))
8926 CheckTriggeredElementChangeSide(jx, jy, Feld[jx][jy], CE_OTHER_GETS_LEFT,
8928 CheckElementChangeSide(jx, jy, Feld[jx][jy], CE_LEFT_BY_PLAYER,leave_side);
8931 if (IS_CUSTOM_ELEMENT(Feld[new_jx][new_jy]))
8933 CheckTriggeredElementChangeSide(new_jx, new_jy, Feld[new_jx][new_jy],
8934 CE_OTHER_GETS_ENTERED, enter_side);
8935 CheckElementChangeSide(new_jx, new_jy, Feld[new_jx][new_jy],
8936 CE_ENTERED_BY_PLAYER, enter_side);
8943 boolean MovePlayer(struct PlayerInfo *player, int dx, int dy)
8945 int jx = player->jx, jy = player->jy;
8946 int old_jx = jx, old_jy = jy;
8947 int moved = MF_NO_ACTION;
8950 if (!player->active)
8955 if (player->MovPos == 0)
8957 player->is_moving = FALSE;
8958 player->is_digging = FALSE;
8959 player->is_collecting = FALSE;
8960 player->is_snapping = FALSE;
8961 player->is_pushing = FALSE;
8967 if (!player->active || (!dx && !dy))
8972 if (!FrameReached(&player->move_delay, player->move_delay_value) &&
8978 if (!FrameReached(&player->move_delay, player->move_delay_value))
8981 if (!FrameReached(&player->move_delay, player->move_delay_value) &&
8982 !(tape.playing && tape.file_version < FILE_VERSION_2_0))
8988 /* store if player is automatically moved to next field */
8989 player->is_auto_moving = (player->programmed_action != MV_NO_MOVING);
8991 /* remove the last programmed player action */
8992 player->programmed_action = 0;
8996 /* should only happen if pre-1.2 tape recordings are played */
8997 /* this is only for backward compatibility */
8999 int original_move_delay_value = player->move_delay_value;
9002 printf("THIS SHOULD ONLY HAPPEN WITH PRE-1.2 LEVEL TAPES. [%ld]\n",
9006 /* scroll remaining steps with finest movement resolution */
9007 player->move_delay_value = MOVE_DELAY_NORMAL_SPEED;
9009 while (player->MovPos)
9011 ScrollPlayer(player, SCROLL_GO_ON);
9012 ScrollScreen(NULL, SCROLL_GO_ON);
9018 player->move_delay_value = original_move_delay_value;
9021 if (player->last_move_dir & MV_HORIZONTAL)
9023 if (!(moved |= MovePlayerOneStep(player, 0, dy, dx, dy)))
9024 moved |= MovePlayerOneStep(player, dx, 0, dx, dy);
9028 if (!(moved |= MovePlayerOneStep(player, dx, 0, dx, dy)))
9029 moved |= MovePlayerOneStep(player, 0, dy, dx, dy);
9035 if (moved & MF_MOVING && !ScreenMovPos &&
9036 (player == local_player || !options.network))
9038 int old_scroll_x = scroll_x, old_scroll_y = scroll_y;
9039 int offset = (setup.scroll_delay ? 3 : 0);
9041 if (!IN_VIS_FIELD(SCREENX(jx), SCREENY(jy)))
9043 /* actual player has left the screen -- scroll in that direction */
9044 if (jx != old_jx) /* player has moved horizontally */
9045 scroll_x += (jx - old_jx);
9046 else /* player has moved vertically */
9047 scroll_y += (jy - old_jy);
9051 if (jx != old_jx) /* player has moved horizontally */
9053 if ((player->MovDir == MV_LEFT && scroll_x > jx - MIDPOSX + offset) ||
9054 (player->MovDir == MV_RIGHT && scroll_x < jx - MIDPOSX - offset))
9055 scroll_x = jx-MIDPOSX + (scroll_x < jx-MIDPOSX ? -offset : +offset);
9057 /* don't scroll over playfield boundaries */
9058 if (scroll_x < SBX_Left || scroll_x > SBX_Right)
9059 scroll_x = (scroll_x < SBX_Left ? SBX_Left : SBX_Right);
9061 /* don't scroll more than one field at a time */
9062 scroll_x = old_scroll_x + SIGN(scroll_x - old_scroll_x);
9064 /* don't scroll against the player's moving direction */
9065 if ((player->MovDir == MV_LEFT && scroll_x > old_scroll_x) ||
9066 (player->MovDir == MV_RIGHT && scroll_x < old_scroll_x))
9067 scroll_x = old_scroll_x;
9069 else /* player has moved vertically */
9071 if ((player->MovDir == MV_UP && scroll_y > jy - MIDPOSY + offset) ||
9072 (player->MovDir == MV_DOWN && scroll_y < jy - MIDPOSY - offset))
9073 scroll_y = jy-MIDPOSY + (scroll_y < jy-MIDPOSY ? -offset : +offset);
9075 /* don't scroll over playfield boundaries */
9076 if (scroll_y < SBY_Upper || scroll_y > SBY_Lower)
9077 scroll_y = (scroll_y < SBY_Upper ? SBY_Upper : SBY_Lower);
9079 /* don't scroll more than one field at a time */
9080 scroll_y = old_scroll_y + SIGN(scroll_y - old_scroll_y);
9082 /* don't scroll against the player's moving direction */
9083 if ((player->MovDir == MV_UP && scroll_y > old_scroll_y) ||
9084 (player->MovDir == MV_DOWN && scroll_y < old_scroll_y))
9085 scroll_y = old_scroll_y;
9089 if (scroll_x != old_scroll_x || scroll_y != old_scroll_y)
9091 if (!options.network && !AllPlayersInVisibleScreen())
9093 scroll_x = old_scroll_x;
9094 scroll_y = old_scroll_y;
9098 ScrollScreen(player, SCROLL_INIT);
9099 ScrollLevel(old_scroll_x - scroll_x, old_scroll_y - scroll_y);
9106 InitPlayerGfxAnimation(player, ACTION_DEFAULT);
9108 if (!(moved & MF_MOVING) && !player->is_pushing)
9113 player->StepFrame = 0;
9115 if (moved & MF_MOVING)
9117 if (old_jx != jx && old_jy == jy)
9118 player->MovDir = (old_jx < jx ? MV_RIGHT : MV_LEFT);
9119 else if (old_jx == jx && old_jy != jy)
9120 player->MovDir = (old_jy < jy ? MV_DOWN : MV_UP);
9122 DrawLevelField(jx, jy); /* for "crumbled sand" */
9124 player->last_move_dir = player->MovDir;
9125 player->is_moving = TRUE;
9127 player->is_snapping = FALSE;
9131 player->is_switching = FALSE;
9134 player->is_dropping = FALSE;
9138 /* !!! ENABLE THIS FOR OLD VERSIONS !!! */
9140 static int trigger_sides[4][2] =
9142 /* enter side leave side */
9143 { CH_SIDE_RIGHT, CH_SIDE_LEFT }, /* moving left */
9144 { CH_SIDE_LEFT, CH_SIDE_RIGHT }, /* moving right */
9145 { CH_SIDE_BOTTOM, CH_SIDE_TOP }, /* moving up */
9146 { CH_SIDE_TOP, CH_SIDE_BOTTOM } /* moving down */
9148 int move_direction = player->MovDir;
9149 int enter_side = trigger_sides[MV_DIR_BIT(move_direction)][0];
9150 int leave_side = trigger_sides[MV_DIR_BIT(move_direction)][1];
9153 CheckTriggeredElementChangePlayer(old_jx, old_jy, Feld[old_jx][old_jy],
9155 player->index_bit, leave_side);
9157 if (IS_CUSTOM_ELEMENT(Feld[old_jx][old_jy]))
9158 CheckElementChangePlayer(old_jx, old_jy, Feld[old_jx][old_jy],
9160 player->index_bit, leave_side);
9162 CheckTriggeredElementChangePlayer(jx, jy, Feld[jx][jy],
9163 CE_OTHER_GETS_ENTERED,
9164 player->index_bit, enter_side);
9166 if (IS_CUSTOM_ELEMENT(Feld[jx][jy]))
9167 CheckElementChangePlayer(jx, jy, Feld[jx][jy], CE_ENTERED_BY_PLAYER,
9168 player->index_bit, enter_side);
9178 CheckGravityMovementWhenNotMoving(player);
9181 player->last_move_dir = MV_NO_MOVING;
9183 player->is_moving = FALSE;
9186 if (game.engine_version < VERSION_IDENT(3,0,7,0))
9188 TestIfHeroTouchesBadThing(jx, jy);
9189 TestIfPlayerTouchesCustomElement(jx, jy);
9192 if (!player->active)
9198 void ScrollPlayer(struct PlayerInfo *player, int mode)
9200 int jx = player->jx, jy = player->jy;
9201 int last_jx = player->last_jx, last_jy = player->last_jy;
9202 int move_stepsize = TILEX / player->move_delay_value;
9204 if (!player->active || !player->MovPos)
9207 if (mode == SCROLL_INIT)
9209 player->actual_frame_counter = FrameCounter;
9210 player->GfxPos = move_stepsize * (player->MovPos / move_stepsize);
9212 if (Feld[last_jx][last_jy] == EL_EMPTY)
9213 Feld[last_jx][last_jy] = EL_PLAYER_IS_LEAVING;
9221 else if (!FrameReached(&player->actual_frame_counter, 1))
9224 player->MovPos += (player->MovPos > 0 ? -1 : 1) * move_stepsize;
9225 player->GfxPos = move_stepsize * (player->MovPos / move_stepsize);
9227 if (!player->block_last_field &&
9228 Feld[last_jx][last_jy] == EL_PLAYER_IS_LEAVING)
9229 Feld[last_jx][last_jy] = EL_EMPTY;
9231 /* before DrawPlayer() to draw correct player graphic for this case */
9232 if (player->MovPos == 0)
9233 CheckGravityMovement(player);
9236 DrawPlayer(player); /* needed here only to cleanup last field */
9239 if (player->MovPos == 0) /* player reached destination field */
9242 if (player->move_delay_reset_counter > 0)
9244 player->move_delay_reset_counter--;
9246 if (player->move_delay_reset_counter == 0)
9248 /* continue with normal speed after quickly moving through gate */
9249 HALVE_PLAYER_SPEED(player);
9251 /* be able to make the next move without delay */
9252 player->move_delay = 0;
9256 if (IS_PASSABLE(Feld[last_jx][last_jy]))
9258 /* continue with normal speed after quickly moving through gate */
9259 HALVE_PLAYER_SPEED(player);
9261 /* be able to make the next move without delay */
9262 player->move_delay = 0;
9266 if (player->block_last_field &&
9267 Feld[last_jx][last_jy] == EL_PLAYER_IS_LEAVING)
9268 Feld[last_jx][last_jy] = EL_EMPTY;
9270 player->last_jx = jx;
9271 player->last_jy = jy;
9273 if (Feld[jx][jy] == EL_EXIT_OPEN ||
9274 Feld[jx][jy] == EL_SP_EXIT_OPEN ||
9275 Feld[jx][jy] == EL_SP_EXIT_OPENING) /* <-- special case */
9277 DrawPlayer(player); /* needed here only to cleanup last field */
9280 if (local_player->friends_still_needed == 0 ||
9281 IS_SP_ELEMENT(Feld[jx][jy]))
9282 player->LevelSolved = player->GameOver = TRUE;
9286 /* !!! ENABLE THIS FOR NEW VERSIONS !!! */
9287 /* this breaks one level: "machine", level 000 */
9289 static int trigger_sides[4][2] =
9291 /* enter side leave side */
9292 { CH_SIDE_RIGHT, CH_SIDE_LEFT }, /* moving left */
9293 { CH_SIDE_LEFT, CH_SIDE_RIGHT }, /* moving right */
9294 { CH_SIDE_BOTTOM, CH_SIDE_TOP }, /* moving up */
9295 { CH_SIDE_TOP, CH_SIDE_BOTTOM } /* moving down */
9297 int move_direction = player->MovDir;
9298 int enter_side = trigger_sides[MV_DIR_BIT(move_direction)][0];
9299 int leave_side = trigger_sides[MV_DIR_BIT(move_direction)][1];
9300 int old_jx = last_jx;
9301 int old_jy = last_jy;
9304 CheckTriggeredElementChangePlayer(old_jx, old_jy, Feld[old_jx][old_jy],
9306 player->index_bit, leave_side);
9308 if (IS_CUSTOM_ELEMENT(Feld[old_jx][old_jy]))
9309 CheckElementChangePlayer(old_jx, old_jy, Feld[old_jx][old_jy],
9311 player->index_bit, leave_side);
9313 CheckTriggeredElementChangePlayer(jx, jy, Feld[jx][jy],
9314 CE_OTHER_GETS_ENTERED,
9315 player->index_bit, enter_side);
9317 if (IS_CUSTOM_ELEMENT(Feld[jx][jy]))
9318 CheckElementChangePlayer(jx, jy, Feld[jx][jy], CE_ENTERED_BY_PLAYER,
9319 player->index_bit, enter_side);
9325 if (game.engine_version >= VERSION_IDENT(3,0,7,0))
9327 TestIfHeroTouchesBadThing(jx, jy);
9328 TestIfPlayerTouchesCustomElement(jx, jy);
9330 TestIfElementTouchesCustomElement(jx, jy); /* for empty space */
9333 if (!player->active)
9337 if (level.use_step_counter)
9343 for (i = 0; i < MAX_PLAYERS; i++)
9345 struct PlayerInfo *player = &stored_player[i];
9347 if (SHIELD_ON(player))
9349 player->shield_normal_time_left--;
9351 if (player->shield_deadly_time_left > 0)
9352 player->shield_deadly_time_left--;
9360 if (TimeLeft <= 10 && setup.time_limit)
9361 PlaySoundStereo(SND_GAME_RUNNING_OUT_OF_TIME, SOUND_MIDDLE);
9363 DrawGameValue_Time(TimeLeft);
9365 if (!TimeLeft && setup.time_limit)
9366 for (i = 0; i < MAX_PLAYERS; i++)
9367 KillHero(&stored_player[i]);
9369 else if (level.time == 0 && !AllPlayersGone) /* level w/o time limit */
9370 DrawGameValue_Time(TimePlayed);
9373 if (tape.single_step && tape.recording && !tape.pausing &&
9374 !player->programmed_action)
9375 TapeTogglePause(TAPE_TOGGLE_AUTOMATIC);
9379 void ScrollScreen(struct PlayerInfo *player, int mode)
9381 static unsigned long screen_frame_counter = 0;
9383 if (mode == SCROLL_INIT)
9385 /* set scrolling step size according to actual player's moving speed */
9386 ScrollStepSize = TILEX / player->move_delay_value;
9388 screen_frame_counter = FrameCounter;
9389 ScreenMovDir = player->MovDir;
9390 ScreenMovPos = player->MovPos;
9391 ScreenGfxPos = ScrollStepSize * (ScreenMovPos / ScrollStepSize);
9394 else if (!FrameReached(&screen_frame_counter, 1))
9399 ScreenMovPos += (ScreenMovPos > 0 ? -1 : 1) * ScrollStepSize;
9400 ScreenGfxPos = ScrollStepSize * (ScreenMovPos / ScrollStepSize);
9401 redraw_mask |= REDRAW_FIELD;
9404 ScreenMovDir = MV_NO_MOVING;
9407 void TestIfPlayerTouchesCustomElement(int x, int y)
9409 static int xy[4][2] =
9416 static int trigger_sides[4][2] =
9418 /* center side border side */
9419 { CH_SIDE_TOP, CH_SIDE_BOTTOM }, /* check top */
9420 { CH_SIDE_LEFT, CH_SIDE_RIGHT }, /* check left */
9421 { CH_SIDE_RIGHT, CH_SIDE_LEFT }, /* check right */
9422 { CH_SIDE_BOTTOM, CH_SIDE_TOP } /* check bottom */
9424 static int touch_dir[4] =
9431 int center_element = Feld[x][y]; /* should always be non-moving! */
9434 for (i = 0; i < NUM_DIRECTIONS; i++)
9436 int xx = x + xy[i][0];
9437 int yy = y + xy[i][1];
9438 int center_side = trigger_sides[i][0];
9439 int border_side = trigger_sides[i][1];
9442 if (!IN_LEV_FIELD(xx, yy))
9445 if (IS_PLAYER(x, y))
9447 struct PlayerInfo *player = PLAYERINFO(x, y);
9449 if (game.engine_version < VERSION_IDENT(3,0,7,0))
9450 border_element = Feld[xx][yy]; /* may be moving! */
9451 else if (!IS_MOVING(xx, yy) && !IS_BLOCKED(xx, yy))
9452 border_element = Feld[xx][yy];
9453 else if (MovDir[xx][yy] & touch_dir[i]) /* elements are touching */
9454 border_element = MovingOrBlocked2Element(xx, yy);
9456 continue; /* center and border element do not touch */
9458 CheckTriggeredElementChangePlayer(xx, yy, border_element,
9459 CE_OTHER_GETS_TOUCHED,
9460 player->index_bit, border_side);
9461 CheckElementChangePlayer(xx, yy, border_element, CE_TOUCHED_BY_PLAYER,
9462 player->index_bit, border_side);
9464 else if (IS_PLAYER(xx, yy))
9466 struct PlayerInfo *player = PLAYERINFO(xx, yy);
9468 if (game.engine_version >= VERSION_IDENT(3,0,7,0))
9470 if (player->MovPos != 0 && !(player->MovDir & touch_dir[i]))
9471 continue; /* center and border element do not touch */
9474 CheckTriggeredElementChangePlayer(x, y, center_element,
9475 CE_OTHER_GETS_TOUCHED,
9476 player->index_bit, center_side);
9477 CheckElementChangePlayer(x, y, center_element, CE_TOUCHED_BY_PLAYER,
9478 player->index_bit, center_side);
9485 void TestIfElementTouchesCustomElement(int x, int y)
9487 static int xy[4][2] =
9494 static int trigger_sides[4][2] =
9496 /* center side border side */
9497 { CH_SIDE_TOP, CH_SIDE_BOTTOM }, /* check top */
9498 { CH_SIDE_LEFT, CH_SIDE_RIGHT }, /* check left */
9499 { CH_SIDE_RIGHT, CH_SIDE_LEFT }, /* check right */
9500 { CH_SIDE_BOTTOM, CH_SIDE_TOP } /* check bottom */
9502 static int touch_dir[4] =
9509 boolean change_center_element = FALSE;
9510 int center_element_change_page = 0;
9511 int center_element = Feld[x][y]; /* should always be non-moving! */
9512 int border_trigger_element;
9515 for (i = 0; i < NUM_DIRECTIONS; i++)
9517 int xx = x + xy[i][0];
9518 int yy = y + xy[i][1];
9519 int center_side = trigger_sides[i][0];
9520 int border_side = trigger_sides[i][1];
9523 if (!IN_LEV_FIELD(xx, yy))
9526 if (game.engine_version < VERSION_IDENT(3,0,7,0))
9527 border_element = Feld[xx][yy]; /* may be moving! */
9528 else if (!IS_MOVING(xx, yy) && !IS_BLOCKED(xx, yy))
9529 border_element = Feld[xx][yy];
9530 else if (MovDir[xx][yy] & touch_dir[i]) /* elements are touching */
9531 border_element = MovingOrBlocked2Element(xx, yy);
9533 continue; /* center and border element do not touch */
9535 /* check for change of center element (but change it only once) */
9536 if (IS_CUSTOM_ELEMENT(center_element) &&
9537 HAS_ANY_CHANGE_EVENT(center_element, CE_OTHER_IS_TOUCHING) &&
9538 !change_center_element)
9540 for (j = 0; j < element_info[center_element].num_change_pages; j++)
9542 struct ElementChangeInfo *change =
9543 &element_info[center_element].change_page[j];
9545 if (change->can_change &&
9546 change->events & CH_EVENT_BIT(CE_OTHER_IS_TOUCHING) &&
9547 change->trigger_side & border_side &&
9549 IS_EQUAL_OR_IN_GROUP(border_element, change->trigger_element)
9551 change->trigger_element == border_element
9555 change_center_element = TRUE;
9556 center_element_change_page = j;
9557 border_trigger_element = border_element;
9564 /* check for change of border element */
9565 if (IS_CUSTOM_ELEMENT(border_element) &&
9566 HAS_ANY_CHANGE_EVENT(border_element, CE_OTHER_IS_TOUCHING))
9568 for (j = 0; j < element_info[border_element].num_change_pages; j++)
9570 struct ElementChangeInfo *change =
9571 &element_info[border_element].change_page[j];
9573 if (change->can_change &&
9574 change->events & CH_EVENT_BIT(CE_OTHER_IS_TOUCHING) &&
9575 change->trigger_side & center_side &&
9577 IS_EQUAL_OR_IN_GROUP(center_element, change->trigger_element)
9579 change->trigger_element == center_element
9584 printf("::: border_element %d, %d\n", x, y);
9587 CheckElementChangePage(xx, yy, border_element, center_element,
9588 CE_OTHER_IS_TOUCHING, j);
9595 if (change_center_element)
9598 printf("::: center_element %d, %d\n", x, y);
9601 CheckElementChangePage(x, y, center_element, border_trigger_element,
9602 CE_OTHER_IS_TOUCHING, center_element_change_page);
9606 void TestIfElementHitsCustomElement(int x, int y, int direction)
9608 int dx = (direction == MV_LEFT ? -1 : direction == MV_RIGHT ? +1 : 0);
9609 int dy = (direction == MV_UP ? -1 : direction == MV_DOWN ? +1 : 0);
9610 int hitx = x + dx, hity = y + dy;
9611 int hitting_element = Feld[x][y];
9612 int touched_element;
9614 boolean object_hit = (IN_LEV_FIELD(hitx, hity) &&
9615 !IS_FREE(hitx, hity) &&
9616 (!IS_MOVING(hitx, hity) ||
9617 MovDir[hitx][hity] != direction ||
9618 ABS(MovPos[hitx][hity]) <= TILEY / 2));
9621 if (IN_LEV_FIELD(hitx, hity) && IS_FREE(hitx, hity))
9625 if (IN_LEV_FIELD(hitx, hity) && !object_hit)
9629 touched_element = (IN_LEV_FIELD(hitx, hity) ?
9630 MovingOrBlocked2Element(hitx, hity) : EL_STEELWALL);
9632 CheckElementChangeSide(x, y, hitting_element, touched_element,
9633 CE_HITTING_SOMETHING, direction);
9635 if (IN_LEV_FIELD(hitx, hity))
9637 int opposite_direction = MV_DIR_OPPOSITE(direction);
9638 int hitting_side = direction;
9639 int touched_side = opposite_direction;
9641 int touched_element = MovingOrBlocked2Element(hitx, hity);
9644 boolean object_hit = (!IS_MOVING(hitx, hity) ||
9645 MovDir[hitx][hity] != direction ||
9646 ABS(MovPos[hitx][hity]) <= TILEY / 2);
9655 CheckElementChangeSide(hitx, hity, touched_element, hitting_element,
9656 CE_HIT_BY_SOMETHING, opposite_direction);
9658 if (IS_CUSTOM_ELEMENT(hitting_element) &&
9659 HAS_ANY_CHANGE_EVENT(hitting_element, CE_OTHER_IS_HITTING))
9661 for (i = 0; i < element_info[hitting_element].num_change_pages; i++)
9663 struct ElementChangeInfo *change =
9664 &element_info[hitting_element].change_page[i];
9666 if (change->can_change &&
9667 change->events & CH_EVENT_BIT(CE_OTHER_IS_HITTING) &&
9668 change->trigger_side & touched_side &&
9671 IS_EQUAL_OR_IN_GROUP(touched_element, change->trigger_element)
9673 change->trigger_element == touched_element
9677 CheckElementChangePage(x, y, hitting_element, touched_element,
9678 CE_OTHER_IS_HITTING, i);
9684 if (IS_CUSTOM_ELEMENT(touched_element) &&
9685 HAS_ANY_CHANGE_EVENT(touched_element, CE_OTHER_GETS_HIT))
9687 for (i = 0; i < element_info[touched_element].num_change_pages; i++)
9689 struct ElementChangeInfo *change =
9690 &element_info[touched_element].change_page[i];
9692 if (change->can_change &&
9693 change->events & CH_EVENT_BIT(CE_OTHER_GETS_HIT) &&
9694 change->trigger_side & hitting_side &&
9696 IS_EQUAL_OR_IN_GROUP(hitting_element, change->trigger_element)
9698 change->trigger_element == hitting_element
9702 CheckElementChangePage(hitx, hity, touched_element,
9703 hitting_element, CE_OTHER_GETS_HIT, i);
9713 void TestIfElementSmashesCustomElement(int x, int y, int direction)
9715 int dx = (direction == MV_LEFT ? -1 : direction == MV_RIGHT ? +1 : 0);
9716 int dy = (direction == MV_UP ? -1 : direction == MV_DOWN ? +1 : 0);
9717 int hitx = x + dx, hity = y + dy;
9718 int hitting_element = Feld[x][y];
9719 int touched_element;
9721 boolean object_hit = (IN_LEV_FIELD(hitx, hity) &&
9722 !IS_FREE(hitx, hity) &&
9723 (!IS_MOVING(hitx, hity) ||
9724 MovDir[hitx][hity] != direction ||
9725 ABS(MovPos[hitx][hity]) <= TILEY / 2));
9728 if (IN_LEV_FIELD(hitx, hity) && IS_FREE(hitx, hity))
9732 if (IN_LEV_FIELD(hitx, hity) && !object_hit)
9736 touched_element = (IN_LEV_FIELD(hitx, hity) ?
9737 MovingOrBlocked2Element(hitx, hity) : EL_STEELWALL);
9739 CheckElementChangeSide(x, y, hitting_element, touched_element,
9740 EP_CAN_SMASH_EVERYTHING, direction);
9742 if (IN_LEV_FIELD(hitx, hity))
9744 int opposite_direction = MV_DIR_OPPOSITE(direction);
9745 int hitting_side = direction;
9746 int touched_side = opposite_direction;
9748 int touched_element = MovingOrBlocked2Element(hitx, hity);
9751 boolean object_hit = (!IS_MOVING(hitx, hity) ||
9752 MovDir[hitx][hity] != direction ||
9753 ABS(MovPos[hitx][hity]) <= TILEY / 2);
9762 CheckElementChangeSide(hitx, hity, touched_element, hitting_element,
9763 CE_SMASHED_BY_SOMETHING, opposite_direction);
9765 if (IS_CUSTOM_ELEMENT(hitting_element) &&
9766 HAS_ANY_CHANGE_EVENT(hitting_element, CE_OTHER_IS_SMASHING))
9768 for (i = 0; i < element_info[hitting_element].num_change_pages; i++)
9770 struct ElementChangeInfo *change =
9771 &element_info[hitting_element].change_page[i];
9773 if (change->can_change &&
9774 change->events & CH_EVENT_BIT(CE_OTHER_IS_SMASHING) &&
9775 change->trigger_side & touched_side &&
9778 IS_EQUAL_OR_IN_GROUP(touched_element, change->trigger_element)
9780 change->trigger_element == touched_element
9784 CheckElementChangePage(x, y, hitting_element, touched_element,
9785 CE_OTHER_IS_SMASHING, i);
9791 if (IS_CUSTOM_ELEMENT(touched_element) &&
9792 HAS_ANY_CHANGE_EVENT(touched_element, CE_OTHER_GETS_SMASHED))
9794 for (i = 0; i < element_info[touched_element].num_change_pages; i++)
9796 struct ElementChangeInfo *change =
9797 &element_info[touched_element].change_page[i];
9799 if (change->can_change &&
9800 change->events & CH_EVENT_BIT(CE_OTHER_GETS_SMASHED) &&
9801 change->trigger_side & hitting_side &&
9803 IS_EQUAL_OR_IN_GROUP(hitting_element, change->trigger_element)
9805 change->trigger_element == hitting_element
9809 CheckElementChangePage(hitx, hity, touched_element,
9810 hitting_element, CE_OTHER_GETS_SMASHED, i);
9820 void TestIfGoodThingHitsBadThing(int good_x, int good_y, int good_move_dir)
9822 int i, kill_x = -1, kill_y = -1;
9823 static int test_xy[4][2] =
9830 static int test_dir[4] =
9838 for (i = 0; i < NUM_DIRECTIONS; i++)
9840 int test_x, test_y, test_move_dir, test_element;
9842 test_x = good_x + test_xy[i][0];
9843 test_y = good_y + test_xy[i][1];
9844 if (!IN_LEV_FIELD(test_x, test_y))
9848 (IS_MOVING(test_x, test_y) ? MovDir[test_x][test_y] : MV_NO_MOVING);
9851 test_element = Feld[test_x][test_y];
9853 test_element = MovingOrBlocked2ElementIfNotLeaving(test_x, test_y);
9856 /* 1st case: good thing is moving towards DONT_RUN_INTO style bad thing;
9857 2nd case: DONT_TOUCH style bad thing does not move away from good thing
9859 if ((DONT_RUN_INTO(test_element) && good_move_dir == test_dir[i]) ||
9860 (DONT_TOUCH(test_element) && test_move_dir != test_dir[i]))
9868 if (kill_x != -1 || kill_y != -1)
9870 if (IS_PLAYER(good_x, good_y))
9872 struct PlayerInfo *player = PLAYERINFO(good_x, good_y);
9874 if (player->shield_deadly_time_left > 0)
9875 Bang(kill_x, kill_y);
9876 else if (!PLAYER_ENEMY_PROTECTED(good_x, good_y))
9880 Bang(good_x, good_y);
9884 void TestIfBadThingHitsGoodThing(int bad_x, int bad_y, int bad_move_dir)
9886 int i, kill_x = -1, kill_y = -1;
9887 int bad_element = Feld[bad_x][bad_y];
9888 static int test_xy[4][2] =
9895 static int touch_dir[4] =
9902 static int test_dir[4] =
9910 if (bad_element == EL_EXPLOSION) /* skip just exploding bad things */
9913 for (i = 0; i < NUM_DIRECTIONS; i++)
9915 int test_x, test_y, test_move_dir, test_element;
9917 test_x = bad_x + test_xy[i][0];
9918 test_y = bad_y + test_xy[i][1];
9919 if (!IN_LEV_FIELD(test_x, test_y))
9923 (IS_MOVING(test_x, test_y) ? MovDir[test_x][test_y] : MV_NO_MOVING);
9925 test_element = Feld[test_x][test_y];
9927 /* 1st case: good thing is moving towards DONT_RUN_INTO style bad thing;
9928 2nd case: DONT_TOUCH style bad thing does not move away from good thing
9930 if ((DONT_RUN_INTO(bad_element) && bad_move_dir == test_dir[i]) ||
9931 (DONT_TOUCH(bad_element) && test_move_dir != test_dir[i]))
9933 /* good thing is player or penguin that does not move away */
9934 if (IS_PLAYER(test_x, test_y))
9936 struct PlayerInfo *player = PLAYERINFO(test_x, test_y);
9938 if (bad_element == EL_ROBOT && player->is_moving)
9939 continue; /* robot does not kill player if he is moving */
9941 if (game.engine_version >= VERSION_IDENT(3,0,7,0))
9943 if (player->MovPos != 0 && !(player->MovDir & touch_dir[i]))
9944 continue; /* center and border element do not touch */
9951 else if (test_element == EL_PENGUIN)
9960 if (kill_x != -1 || kill_y != -1)
9962 if (IS_PLAYER(kill_x, kill_y))
9964 struct PlayerInfo *player = PLAYERINFO(kill_x, kill_y);
9966 if (player->shield_deadly_time_left > 0)
9968 else if (!PLAYER_ENEMY_PROTECTED(kill_x, kill_y))
9972 Bang(kill_x, kill_y);
9976 void TestIfHeroTouchesBadThing(int x, int y)
9978 TestIfGoodThingHitsBadThing(x, y, MV_NO_MOVING);
9981 void TestIfHeroRunsIntoBadThing(int x, int y, int move_dir)
9983 TestIfGoodThingHitsBadThing(x, y, move_dir);
9986 void TestIfBadThingTouchesHero(int x, int y)
9988 TestIfBadThingHitsGoodThing(x, y, MV_NO_MOVING);
9991 void TestIfBadThingRunsIntoHero(int x, int y, int move_dir)
9993 TestIfBadThingHitsGoodThing(x, y, move_dir);
9996 void TestIfFriendTouchesBadThing(int x, int y)
9998 TestIfGoodThingHitsBadThing(x, y, MV_NO_MOVING);
10001 void TestIfBadThingTouchesFriend(int x, int y)
10003 TestIfBadThingHitsGoodThing(x, y, MV_NO_MOVING);
10006 void TestIfBadThingTouchesOtherBadThing(int bad_x, int bad_y)
10008 int i, kill_x = bad_x, kill_y = bad_y;
10009 static int xy[4][2] =
10017 for (i = 0; i < NUM_DIRECTIONS; i++)
10021 x = bad_x + xy[i][0];
10022 y = bad_y + xy[i][1];
10023 if (!IN_LEV_FIELD(x, y))
10026 element = Feld[x][y];
10027 if (IS_AMOEBOID(element) || element == EL_GAME_OF_LIFE ||
10028 element == EL_AMOEBA_GROWING || element == EL_AMOEBA_DROP)
10036 if (kill_x != bad_x || kill_y != bad_y)
10037 Bang(bad_x, bad_y);
10040 void KillHero(struct PlayerInfo *player)
10042 int jx = player->jx, jy = player->jy;
10044 if (!player->active)
10047 /* remove accessible field at the player's position */
10048 Feld[jx][jy] = EL_EMPTY;
10050 /* deactivate shield (else Bang()/Explode() would not work right) */
10051 player->shield_normal_time_left = 0;
10052 player->shield_deadly_time_left = 0;
10058 static void KillHeroUnlessEnemyProtected(int x, int y)
10060 if (!PLAYER_ENEMY_PROTECTED(x, y))
10061 KillHero(PLAYERINFO(x, y));
10064 static void KillHeroUnlessExplosionProtected(int x, int y)
10066 if (!PLAYER_EXPLOSION_PROTECTED(x, y))
10067 KillHero(PLAYERINFO(x, y));
10070 void BuryHero(struct PlayerInfo *player)
10072 int jx = player->jx, jy = player->jy;
10074 if (!player->active)
10078 PlayLevelSoundElementAction(jx, jy, player->element_nr, ACTION_DYING);
10080 PlayLevelSound(jx, jy, SND_CLASS_PLAYER_DYING);
10082 PlayLevelSound(jx, jy, SND_GAME_LOSING);
10084 player->GameOver = TRUE;
10085 RemoveHero(player);
10088 void RemoveHero(struct PlayerInfo *player)
10090 int jx = player->jx, jy = player->jy;
10091 int i, found = FALSE;
10093 player->present = FALSE;
10094 player->active = FALSE;
10096 if (!ExplodeField[jx][jy])
10097 StorePlayer[jx][jy] = 0;
10099 for (i = 0; i < MAX_PLAYERS; i++)
10100 if (stored_player[i].active)
10104 AllPlayersGone = TRUE;
10111 =============================================================================
10112 checkDiagonalPushing()
10113 -----------------------------------------------------------------------------
10114 check if diagonal input device direction results in pushing of object
10115 (by checking if the alternative direction is walkable, diggable, ...)
10116 =============================================================================
10119 static boolean checkDiagonalPushing(struct PlayerInfo *player,
10120 int x, int y, int real_dx, int real_dy)
10122 int jx, jy, dx, dy, xx, yy;
10124 if (real_dx == 0 || real_dy == 0) /* no diagonal direction => push */
10127 /* diagonal direction: check alternative direction */
10132 xx = jx + (dx == 0 ? real_dx : 0);
10133 yy = jy + (dy == 0 ? real_dy : 0);
10135 return (!IN_LEV_FIELD(xx, yy) || IS_SOLID_FOR_PUSHING(Feld[xx][yy]));
10139 =============================================================================
10141 -----------------------------------------------------------------------------
10142 x, y: field next to player (non-diagonal) to try to dig to
10143 real_dx, real_dy: direction as read from input device (can be diagonal)
10144 =============================================================================
10147 int DigField(struct PlayerInfo *player,
10148 int oldx, int oldy, int x, int y,
10149 int real_dx, int real_dy, int mode)
10151 static int trigger_sides[4] =
10153 CH_SIDE_RIGHT, /* moving left */
10154 CH_SIDE_LEFT, /* moving right */
10155 CH_SIDE_BOTTOM, /* moving up */
10156 CH_SIDE_TOP, /* moving down */
10159 boolean use_spring_bug = (game.engine_version < VERSION_IDENT(2,2,0,0));
10161 int jx = oldx, jy = oldy;
10162 int dx = x - jx, dy = y - jy;
10163 int nextx = x + dx, nexty = y + dy;
10164 int move_direction = (dx == -1 ? MV_LEFT :
10165 dx == +1 ? MV_RIGHT :
10167 dy == +1 ? MV_DOWN : MV_NO_MOVING);
10168 int opposite_direction = MV_DIR_OPPOSITE(move_direction);
10169 int dig_side = trigger_sides[MV_DIR_BIT(move_direction)];
10170 int old_element = Feld[jx][jy];
10173 if (player->MovPos == 0)
10175 player->is_digging = FALSE;
10176 player->is_collecting = FALSE;
10179 if (player->MovPos == 0) /* last pushing move finished */
10180 player->is_pushing = FALSE;
10182 if (mode == DF_NO_PUSH) /* player just stopped pushing */
10184 player->is_switching = FALSE;
10185 player->push_delay = 0;
10187 return MF_NO_ACTION;
10190 if (IS_MOVING(x, y) || IS_PLAYER(x, y))
10191 return MF_NO_ACTION;
10196 if (IS_TUBE(Feld[jx][jy]) || IS_TUBE(Back[jx][jy]))
10198 if (IS_TUBE(Feld[jx][jy]) ||
10199 (IS_TUBE(Back[jx][jy]) && game.engine_version >= VERSION_IDENT(2,2,0,0)))
10203 int tube_element = (IS_TUBE(Feld[jx][jy]) ? Feld[jx][jy] : Back[jx][jy]);
10204 int tube_leave_directions[][2] =
10206 { EL_TUBE_ANY, MV_LEFT | MV_RIGHT | MV_UP | MV_DOWN },
10207 { EL_TUBE_VERTICAL, MV_UP | MV_DOWN },
10208 { EL_TUBE_HORIZONTAL, MV_LEFT | MV_RIGHT },
10209 { EL_TUBE_VERTICAL_LEFT, MV_LEFT | MV_UP | MV_DOWN },
10210 { EL_TUBE_VERTICAL_RIGHT, MV_RIGHT | MV_UP | MV_DOWN },
10211 { EL_TUBE_HORIZONTAL_UP, MV_LEFT | MV_RIGHT | MV_UP },
10212 { EL_TUBE_HORIZONTAL_DOWN, MV_LEFT | MV_RIGHT | MV_DOWN },
10213 { EL_TUBE_LEFT_UP, MV_LEFT | MV_UP },
10214 { EL_TUBE_LEFT_DOWN, MV_LEFT | MV_DOWN },
10215 { EL_TUBE_RIGHT_UP, MV_RIGHT | MV_UP },
10216 { EL_TUBE_RIGHT_DOWN, MV_RIGHT | MV_DOWN },
10217 { -1, MV_LEFT | MV_RIGHT | MV_UP | MV_DOWN }
10220 while (tube_leave_directions[i][0] != tube_element)
10223 if (tube_leave_directions[i][0] == -1) /* should not happen */
10227 if (!(tube_leave_directions[i][1] & move_direction))
10228 return MF_NO_ACTION; /* tube has no opening in this direction */
10233 if (IS_TUBE(Back[jx][jy]) && game.engine_version >= VERSION_IDENT(2,2,0,0))
10234 old_element = Back[jx][jy];
10238 if (IS_WALKABLE(old_element) && !ACCESS_FROM(old_element, move_direction))
10239 return MF_NO_ACTION; /* field has no opening in this direction */
10241 if (IS_PASSABLE(old_element) && !ACCESS_FROM(old_element,opposite_direction))
10242 return MF_NO_ACTION; /* field has no opening in this direction */
10244 element = Feld[x][y];
10246 if (mode == DF_SNAP && !IS_SNAPPABLE(element) &&
10247 game.engine_version >= VERSION_IDENT(2,2,0,0))
10248 return MF_NO_ACTION;
10253 case EL_SP_PORT_LEFT:
10254 case EL_SP_PORT_RIGHT:
10255 case EL_SP_PORT_UP:
10256 case EL_SP_PORT_DOWN:
10257 case EL_SP_PORT_HORIZONTAL:
10258 case EL_SP_PORT_VERTICAL:
10259 case EL_SP_PORT_ANY:
10260 case EL_SP_GRAVITY_PORT_LEFT:
10261 case EL_SP_GRAVITY_PORT_RIGHT:
10262 case EL_SP_GRAVITY_PORT_UP:
10263 case EL_SP_GRAVITY_PORT_DOWN:
10265 if (!canEnterSupaplexPort(x, y, dx, dy))
10266 return MF_NO_ACTION;
10269 element != EL_SP_PORT_LEFT &&
10270 element != EL_SP_GRAVITY_PORT_LEFT &&
10271 element != EL_SP_PORT_HORIZONTAL &&
10272 element != EL_SP_PORT_ANY) ||
10274 element != EL_SP_PORT_RIGHT &&
10275 element != EL_SP_GRAVITY_PORT_RIGHT &&
10276 element != EL_SP_PORT_HORIZONTAL &&
10277 element != EL_SP_PORT_ANY) ||
10279 element != EL_SP_PORT_UP &&
10280 element != EL_SP_GRAVITY_PORT_UP &&
10281 element != EL_SP_PORT_VERTICAL &&
10282 element != EL_SP_PORT_ANY) ||
10284 element != EL_SP_PORT_DOWN &&
10285 element != EL_SP_GRAVITY_PORT_DOWN &&
10286 element != EL_SP_PORT_VERTICAL &&
10287 element != EL_SP_PORT_ANY) ||
10288 !IN_LEV_FIELD(nextx, nexty) ||
10289 !IS_FREE(nextx, nexty))
10290 return MF_NO_ACTION;
10293 if (element == EL_SP_GRAVITY_PORT_LEFT ||
10294 element == EL_SP_GRAVITY_PORT_RIGHT ||
10295 element == EL_SP_GRAVITY_PORT_UP ||
10296 element == EL_SP_GRAVITY_PORT_DOWN)
10297 game.gravity = !game.gravity;
10299 /* automatically move to the next field with double speed */
10300 player->programmed_action = move_direction;
10302 if (player->move_delay_reset_counter == 0)
10304 player->move_delay_reset_counter = 2; /* two double speed steps */
10306 DOUBLE_PLAYER_SPEED(player);
10309 player->move_delay_reset_counter = 2;
10311 DOUBLE_PLAYER_SPEED(player);
10315 printf("::: passing port %d,%d [%d]\n", x, y, FrameCounter);
10318 PlayLevelSound(x, y, SND_CLASS_SP_PORT_PASSING);
10324 case EL_TUBE_VERTICAL:
10325 case EL_TUBE_HORIZONTAL:
10326 case EL_TUBE_VERTICAL_LEFT:
10327 case EL_TUBE_VERTICAL_RIGHT:
10328 case EL_TUBE_HORIZONTAL_UP:
10329 case EL_TUBE_HORIZONTAL_DOWN:
10330 case EL_TUBE_LEFT_UP:
10331 case EL_TUBE_LEFT_DOWN:
10332 case EL_TUBE_RIGHT_UP:
10333 case EL_TUBE_RIGHT_DOWN:
10336 int tube_enter_directions[][2] =
10338 { EL_TUBE_ANY, MV_LEFT | MV_RIGHT | MV_UP | MV_DOWN },
10339 { EL_TUBE_VERTICAL, MV_UP | MV_DOWN },
10340 { EL_TUBE_HORIZONTAL, MV_LEFT | MV_RIGHT },
10341 { EL_TUBE_VERTICAL_LEFT, MV_RIGHT | MV_UP | MV_DOWN },
10342 { EL_TUBE_VERTICAL_RIGHT, MV_LEFT | MV_UP | MV_DOWN },
10343 { EL_TUBE_HORIZONTAL_UP, MV_LEFT | MV_RIGHT | MV_DOWN },
10344 { EL_TUBE_HORIZONTAL_DOWN, MV_LEFT | MV_RIGHT | MV_UP },
10345 { EL_TUBE_LEFT_UP, MV_RIGHT | MV_DOWN },
10346 { EL_TUBE_LEFT_DOWN, MV_RIGHT | MV_UP },
10347 { EL_TUBE_RIGHT_UP, MV_LEFT | MV_DOWN },
10348 { EL_TUBE_RIGHT_DOWN, MV_LEFT | MV_UP },
10349 { -1, MV_NO_MOVING }
10352 while (tube_enter_directions[i][0] != element)
10355 if (tube_enter_directions[i][0] == -1) /* should not happen */
10359 if (!(tube_enter_directions[i][1] & move_direction))
10360 return MF_NO_ACTION; /* tube has no opening in this direction */
10362 PlayLevelSound(x, y, SND_CLASS_TUBE_WALKING);
10369 if (IS_WALKABLE(element))
10371 int sound_action = ACTION_WALKING;
10373 if (!ACCESS_FROM(element, opposite_direction))
10374 return MF_NO_ACTION; /* field not accessible from this direction */
10377 if (element == EL_EMPTY_SPACE &&
10378 game.gravity && !player->is_auto_moving &&
10379 canFallDown(player) && move_direction != MV_DOWN)
10380 return MF_NO_ACTION; /* player cannot walk here due to gravity */
10383 if (element >= EL_GATE_1 && element <= EL_GATE_4)
10385 if (!player->key[element - EL_GATE_1])
10386 return MF_NO_ACTION;
10388 else if (element >= EL_GATE_1_GRAY && element <= EL_GATE_4_GRAY)
10390 if (!player->key[element - EL_GATE_1_GRAY])
10391 return MF_NO_ACTION;
10393 else if (element == EL_EXIT_OPEN ||
10394 element == EL_SP_EXIT_OPEN ||
10395 element == EL_SP_EXIT_OPENING)
10397 sound_action = ACTION_PASSING; /* player is passing exit */
10399 else if (element == EL_EMPTY)
10401 sound_action = ACTION_MOVING; /* nothing to walk on */
10404 /* play sound from background or player, whatever is available */
10405 if (element_info[element].sound[sound_action] != SND_UNDEFINED)
10406 PlayLevelSoundElementAction(x, y, element, sound_action);
10408 PlayLevelSoundElementAction(x, y, player->element_nr, sound_action);
10412 else if (IS_PASSABLE(element))
10415 if (!canPassField(x, y, move_direction))
10416 return MF_NO_ACTION;
10420 if (!IN_LEV_FIELD(nextx, nexty) || IS_PLAYER(nextx, nexty) ||
10421 !IS_WALKABLE_FROM(Feld[nextx][nexty], move_direction) ||
10422 (!level.can_pass_to_walkable && !IS_FREE(nextx, nexty)))
10423 return MF_NO_ACTION;
10425 if (!IN_LEV_FIELD(nextx, nexty) || !IS_FREE(nextx, nexty))
10426 return MF_NO_ACTION;
10430 if (!ACCESS_FROM(element, opposite_direction))
10431 return MF_NO_ACTION; /* field not accessible from this direction */
10433 if (IS_CUSTOM_ELEMENT(element) &&
10434 !ACCESS_FROM(element, opposite_direction))
10435 return MF_NO_ACTION; /* field not accessible from this direction */
10439 if (CAN_MOVE(element)) /* only fixed elements can be passed! */
10440 return MF_NO_ACTION;
10445 if (IS_EM_GATE(element))
10447 if (!player->key[element - EL_EM_GATE_1])
10448 return MF_NO_ACTION;
10450 else if (IS_EM_GATE_GRAY(element))
10452 if (!player->key[element - EL_EM_GATE_1_GRAY])
10453 return MF_NO_ACTION;
10455 else if (IS_SP_PORT(element))
10457 if (element == EL_SP_GRAVITY_PORT_LEFT ||
10458 element == EL_SP_GRAVITY_PORT_RIGHT ||
10459 element == EL_SP_GRAVITY_PORT_UP ||
10460 element == EL_SP_GRAVITY_PORT_DOWN)
10461 game.gravity = !game.gravity;
10464 /* automatically move to the next field with double speed */
10465 player->programmed_action = move_direction;
10467 if (player->move_delay_reset_counter == 0)
10469 player->move_delay_reset_counter = 2; /* two double speed steps */
10471 DOUBLE_PLAYER_SPEED(player);
10474 player->move_delay_reset_counter = 2;
10476 DOUBLE_PLAYER_SPEED(player);
10479 PlayLevelSoundAction(x, y, ACTION_PASSING);
10483 else if (IS_DIGGABLE(element))
10487 if (mode != DF_SNAP)
10490 GfxElement[x][y] = GFX_ELEMENT(element);
10493 (GFX_CRUMBLED(element) ? EL_SAND : GFX_ELEMENT(element));
10495 player->is_digging = TRUE;
10498 PlayLevelSoundElementAction(x, y, element, ACTION_DIGGING);
10500 CheckTriggeredElementChangePlayer(x, y, element, CE_OTHER_GETS_DIGGED,
10501 player->index_bit, dig_side);
10504 if (mode == DF_SNAP)
10505 TestIfElementTouchesCustomElement(x, y); /* for empty space */
10510 else if (IS_COLLECTIBLE(element))
10514 if (mode != DF_SNAP)
10516 GfxElement[x][y] = element;
10517 player->is_collecting = TRUE;
10520 if (element == EL_SPEED_PILL)
10521 player->move_delay_value = MOVE_DELAY_HIGH_SPEED;
10522 else if (element == EL_EXTRA_TIME && level.time > 0)
10525 DrawGameValue_Time(TimeLeft);
10527 else if (element == EL_SHIELD_NORMAL || element == EL_SHIELD_DEADLY)
10529 player->shield_normal_time_left += 10;
10530 if (element == EL_SHIELD_DEADLY)
10531 player->shield_deadly_time_left += 10;
10533 else if (element == EL_DYNAMITE || element == EL_SP_DISK_RED)
10535 if (player->inventory_size < MAX_INVENTORY_SIZE)
10536 player->inventory_element[player->inventory_size++] = element;
10538 DrawGameValue_Dynamite(local_player->inventory_size);
10540 else if (element == EL_DYNABOMB_INCREASE_NUMBER)
10542 player->dynabomb_count++;
10543 player->dynabombs_left++;
10545 else if (element == EL_DYNABOMB_INCREASE_SIZE)
10547 player->dynabomb_size++;
10549 else if (element == EL_DYNABOMB_INCREASE_POWER)
10551 player->dynabomb_xl = TRUE;
10553 else if ((element >= EL_KEY_1 && element <= EL_KEY_4) ||
10554 (element >= EL_EM_KEY_1 && element <= EL_EM_KEY_4))
10556 int key_nr = (element >= EL_KEY_1 && element <= EL_KEY_4 ?
10557 element - EL_KEY_1 : element - EL_EM_KEY_1);
10559 player->key[key_nr] = TRUE;
10561 DrawGameValue_Keys(player);
10563 redraw_mask |= REDRAW_DOOR_1;
10565 else if (IS_ENVELOPE(element))
10568 player->show_envelope = element;
10570 ShowEnvelope(element - EL_ENVELOPE_1);
10573 else if (IS_DROPPABLE(element)) /* can be collected and dropped */
10577 if (element_info[element].collect_count == 0)
10578 player->inventory_infinite_element = element;
10580 for (i = 0; i < element_info[element].collect_count; i++)
10581 if (player->inventory_size < MAX_INVENTORY_SIZE)
10582 player->inventory_element[player->inventory_size++] = element;
10584 DrawGameValue_Dynamite(local_player->inventory_size);
10586 else if (element_info[element].collect_count > 0)
10588 local_player->gems_still_needed -=
10589 element_info[element].collect_count;
10590 if (local_player->gems_still_needed < 0)
10591 local_player->gems_still_needed = 0;
10593 DrawGameValue_Emeralds(local_player->gems_still_needed);
10596 RaiseScoreElement(element);
10597 PlayLevelSoundElementAction(x, y, element, ACTION_COLLECTING);
10599 CheckTriggeredElementChangePlayer(x, y, element,
10600 CE_OTHER_GETS_COLLECTED,
10601 player->index_bit, dig_side);
10604 if (mode == DF_SNAP)
10605 TestIfElementTouchesCustomElement(x, y); /* for empty space */
10610 else if (IS_PUSHABLE(element))
10612 if (mode == DF_SNAP && element != EL_BD_ROCK)
10613 return MF_NO_ACTION;
10615 if (CAN_FALL(element) && dy)
10616 return MF_NO_ACTION;
10618 if (CAN_FALL(element) && IN_LEV_FIELD(x, y + 1) && IS_FREE(x, y + 1) &&
10619 !(element == EL_SPRING && level.use_spring_bug))
10620 return MF_NO_ACTION;
10623 if (CAN_MOVE(element) && GET_MAX_MOVE_DELAY(element) == 0 &&
10624 ((move_direction & MV_VERTICAL &&
10625 ((element_info[element].move_pattern & MV_LEFT &&
10626 IN_LEV_FIELD(x - 1, y) && IS_FREE(x - 1, y)) ||
10627 (element_info[element].move_pattern & MV_RIGHT &&
10628 IN_LEV_FIELD(x + 1, y) && IS_FREE(x + 1, y)))) ||
10629 (move_direction & MV_HORIZONTAL &&
10630 ((element_info[element].move_pattern & MV_UP &&
10631 IN_LEV_FIELD(x, y - 1) && IS_FREE(x, y - 1)) ||
10632 (element_info[element].move_pattern & MV_DOWN &&
10633 IN_LEV_FIELD(x, y + 1) && IS_FREE(x, y + 1))))))
10634 return MF_NO_ACTION;
10638 /* do not push elements already moving away faster than player */
10639 if (CAN_MOVE(element) && MovDir[x][y] == move_direction &&
10640 ABS(getElementMoveStepsize(x, y)) > MOVE_STEPSIZE_NORMAL)
10641 return MF_NO_ACTION;
10643 if (element == EL_SPRING && MovDir[x][y] != MV_NO_MOVING)
10644 return MF_NO_ACTION;
10648 if (game.engine_version >= VERSION_IDENT(3,0,7,1))
10650 if (player->push_delay_value == -1)
10651 player->push_delay_value = GET_NEW_PUSH_DELAY(element);
10653 else if (game.engine_version >= VERSION_IDENT(2,2,0,7))
10655 if (!player->is_pushing)
10656 player->push_delay_value = GET_NEW_PUSH_DELAY(element);
10660 if (game.engine_version >= VERSION_IDENT(2,2,0,7) &&
10661 (game.engine_version < VERSION_IDENT(3,0,7,1) ||
10662 !player_is_pushing))
10663 player->push_delay_value = GET_NEW_PUSH_DELAY(element);
10666 if (!player->is_pushing &&
10667 game.engine_version >= VERSION_IDENT(2,2,0,7))
10668 player->push_delay_value = GET_NEW_PUSH_DELAY(element);
10672 printf("::: push delay: %ld [%d, %d] [%d]\n",
10673 player->push_delay_value, FrameCounter, game.engine_version,
10674 player->is_pushing);
10677 player->is_pushing = TRUE;
10679 if (!(IN_LEV_FIELD(nextx, nexty) &&
10680 (IS_FREE(nextx, nexty) ||
10681 (Feld[nextx][nexty] == EL_SOKOBAN_FIELD_EMPTY &&
10682 IS_SB_ELEMENT(element)))))
10683 return MF_NO_ACTION;
10685 if (!checkDiagonalPushing(player, x, y, real_dx, real_dy))
10686 return MF_NO_ACTION;
10688 if (player->push_delay == 0) /* new pushing; restart delay */
10689 player->push_delay = FrameCounter;
10691 if (!FrameReached(&player->push_delay, player->push_delay_value) &&
10692 !(tape.playing && tape.file_version < FILE_VERSION_2_0) &&
10693 element != EL_SPRING && element != EL_BALLOON)
10695 /* make sure that there is no move delay before next try to push */
10696 if (game.engine_version >= VERSION_IDENT(3,0,7,1))
10697 player->move_delay = INITIAL_MOVE_DELAY_OFF;
10699 return MF_NO_ACTION;
10703 printf("::: NOW PUSHING... [%d]\n", FrameCounter);
10706 if (IS_SB_ELEMENT(element))
10708 if (element == EL_SOKOBAN_FIELD_FULL)
10710 Back[x][y] = EL_SOKOBAN_FIELD_EMPTY;
10711 local_player->sokobanfields_still_needed++;
10714 if (Feld[nextx][nexty] == EL_SOKOBAN_FIELD_EMPTY)
10716 Back[nextx][nexty] = EL_SOKOBAN_FIELD_EMPTY;
10717 local_player->sokobanfields_still_needed--;
10720 Feld[x][y] = EL_SOKOBAN_OBJECT;
10722 if (Back[x][y] == Back[nextx][nexty])
10723 PlayLevelSoundAction(x, y, ACTION_PUSHING);
10724 else if (Back[x][y] != 0)
10725 PlayLevelSoundElementAction(x, y, EL_SOKOBAN_FIELD_FULL,
10728 PlayLevelSoundElementAction(nextx, nexty, EL_SOKOBAN_FIELD_EMPTY,
10731 if (local_player->sokobanfields_still_needed == 0 &&
10732 game.emulation == EMU_SOKOBAN)
10734 player->LevelSolved = player->GameOver = TRUE;
10735 PlayLevelSound(x, y, SND_GAME_SOKOBAN_SOLVING);
10739 PlayLevelSoundElementAction(x, y, element, ACTION_PUSHING);
10741 InitMovingField(x, y, move_direction);
10742 GfxAction[x][y] = ACTION_PUSHING;
10744 if (mode == DF_SNAP)
10745 ContinueMoving(x, y);
10747 MovPos[x][y] = (dx != 0 ? dx : dy);
10749 Pushed[x][y] = TRUE;
10750 Pushed[nextx][nexty] = TRUE;
10752 if (game.engine_version < VERSION_IDENT(2,2,0,7))
10753 player->push_delay_value = GET_NEW_PUSH_DELAY(element);
10755 player->push_delay_value = -1; /* get new value later */
10757 CheckTriggeredElementChangePlayer(x, y, element, CE_OTHER_GETS_PUSHED,
10758 player->index_bit, dig_side);
10759 CheckElementChangePlayer(x, y, element, CE_PUSHED_BY_PLAYER,
10760 player->index_bit, dig_side);
10764 else if (IS_SWITCHABLE(element))
10766 if (PLAYER_SWITCHING(player, x, y))
10769 player->is_switching = TRUE;
10770 player->switch_x = x;
10771 player->switch_y = y;
10773 PlayLevelSoundElementAction(x, y, element, ACTION_ACTIVATING);
10775 if (element == EL_ROBOT_WHEEL)
10777 Feld[x][y] = EL_ROBOT_WHEEL_ACTIVE;
10781 DrawLevelField(x, y);
10783 else if (element == EL_SP_TERMINAL)
10787 for (yy = 0; yy < lev_fieldy; yy++) for (xx=0; xx < lev_fieldx; xx++)
10789 if (Feld[xx][yy] == EL_SP_DISK_YELLOW)
10791 else if (Feld[xx][yy] == EL_SP_TERMINAL)
10792 Feld[xx][yy] = EL_SP_TERMINAL_ACTIVE;
10795 else if (IS_BELT_SWITCH(element))
10797 ToggleBeltSwitch(x, y);
10799 else if (element == EL_SWITCHGATE_SWITCH_UP ||
10800 element == EL_SWITCHGATE_SWITCH_DOWN)
10802 ToggleSwitchgateSwitch(x, y);
10804 else if (element == EL_LIGHT_SWITCH ||
10805 element == EL_LIGHT_SWITCH_ACTIVE)
10807 ToggleLightSwitch(x, y);
10810 PlayLevelSound(x, y, element == EL_LIGHT_SWITCH ?
10811 SND_LIGHT_SWITCH_ACTIVATING :
10812 SND_LIGHT_SWITCH_DEACTIVATING);
10815 else if (element == EL_TIMEGATE_SWITCH)
10817 ActivateTimegateSwitch(x, y);
10819 else if (element == EL_BALLOON_SWITCH_LEFT ||
10820 element == EL_BALLOON_SWITCH_RIGHT ||
10821 element == EL_BALLOON_SWITCH_UP ||
10822 element == EL_BALLOON_SWITCH_DOWN ||
10823 element == EL_BALLOON_SWITCH_ANY)
10825 if (element == EL_BALLOON_SWITCH_ANY)
10826 game.balloon_dir = move_direction;
10828 game.balloon_dir = (element == EL_BALLOON_SWITCH_LEFT ? MV_LEFT :
10829 element == EL_BALLOON_SWITCH_RIGHT ? MV_RIGHT :
10830 element == EL_BALLOON_SWITCH_UP ? MV_UP :
10831 element == EL_BALLOON_SWITCH_DOWN ? MV_DOWN :
10834 else if (element == EL_LAMP)
10836 Feld[x][y] = EL_LAMP_ACTIVE;
10837 local_player->lights_still_needed--;
10839 DrawLevelField(x, y);
10841 else if (element == EL_TIME_ORB_FULL)
10843 Feld[x][y] = EL_TIME_ORB_EMPTY;
10845 DrawGameValue_Time(TimeLeft);
10847 DrawLevelField(x, y);
10850 PlaySoundStereo(SND_TIME_ORB_FULL_COLLECTING, SOUND_MIDDLE);
10858 if (!PLAYER_SWITCHING(player, x, y))
10860 player->is_switching = TRUE;
10861 player->switch_x = x;
10862 player->switch_y = y;
10864 CheckTriggeredElementChangePlayer(x, y, element,
10865 CE_OTHER_IS_SWITCHING,
10866 player->index_bit, dig_side);
10867 CheckElementChangePlayer(x, y, element, CE_SWITCHED,
10868 player->index_bit, dig_side);
10871 CheckTriggeredElementChangePlayer(x, y, element, CE_OTHER_GETS_PRESSED,
10872 player->index_bit, dig_side);
10873 CheckElementChangePlayer(x, y, element, CE_PRESSED_BY_PLAYER,
10874 player->index_bit, dig_side);
10877 return MF_NO_ACTION;
10880 player->push_delay = 0;
10882 if (Feld[x][y] != element) /* really digged/collected something */
10883 player->is_collecting = !player->is_digging;
10888 boolean SnapField(struct PlayerInfo *player, int dx, int dy)
10890 int jx = player->jx, jy = player->jy;
10891 int x = jx + dx, y = jy + dy;
10892 int snap_direction = (dx == -1 ? MV_LEFT :
10893 dx == +1 ? MV_RIGHT :
10895 dy == +1 ? MV_DOWN : MV_NO_MOVING);
10898 if (player->MovPos)
10901 if (player->MovPos && game.engine_version >= VERSION_IDENT(2,2,0,0))
10905 if (!player->active || !IN_LEV_FIELD(x, y))
10913 if (player->MovPos == 0)
10914 player->is_pushing = FALSE;
10916 player->is_snapping = FALSE;
10918 if (player->MovPos == 0)
10920 player->is_moving = FALSE;
10921 player->is_digging = FALSE;
10922 player->is_collecting = FALSE;
10928 if (player->is_snapping)
10931 player->MovDir = snap_direction;
10934 if (player->MovPos == 0)
10937 player->is_moving = FALSE;
10938 player->is_digging = FALSE;
10939 player->is_collecting = FALSE;
10942 player->is_dropping = FALSE;
10944 if (DigField(player, jx, jy, x, y, 0, 0, DF_SNAP) == MF_NO_ACTION)
10947 player->is_snapping = TRUE;
10950 if (player->MovPos == 0)
10953 player->is_moving = FALSE;
10954 player->is_digging = FALSE;
10955 player->is_collecting = FALSE;
10958 DrawLevelField(x, y);
10964 boolean DropElement(struct PlayerInfo *player)
10966 static int trigger_sides[4] =
10968 CH_SIDE_LEFT, /* dropping left */
10969 CH_SIDE_RIGHT, /* dropping right */
10970 CH_SIDE_TOP, /* dropping up */
10971 CH_SIDE_BOTTOM, /* dropping down */
10973 int jx = player->jx, jy = player->jy;
10974 int drop_direction = player->MovDir;
10975 int drop_side = trigger_sides[MV_DIR_BIT(drop_direction)];
10976 int old_element = Feld[jx][jy];
10977 int drop_element = (player->inventory_size > 0 ?
10978 player->inventory_element[player->inventory_size - 1] :
10979 player->inventory_infinite_element != EL_UNDEFINED ?
10980 player->inventory_infinite_element :
10981 player->dynabombs_left > 0 ?
10982 EL_DYNABOMB_PLAYER_1_ACTIVE + player->index_nr :
10984 int new_element = drop_element; /* default: element does not change */
10986 /* check if player is active, not moving and ready to drop */
10987 if (!player->active || player->MovPos || player->drop_delay > 0)
10990 /* check if player has anything that can be dropped */
10992 if (new_element == EL_UNDEFINED)
10995 if (player->inventory_size == 0 &&
10996 player->inventory_infinite_element == EL_UNDEFINED &&
10997 player->dynabombs_left == 0)
11001 /* check if anything can be dropped at the current position */
11002 if (IS_ACTIVE_BOMB(old_element) || old_element == EL_EXPLOSION)
11005 /* collected custom elements can only be dropped on empty fields */
11007 if (IS_CUSTOM_ELEMENT(new_element) && old_element != EL_EMPTY)
11010 if (player->inventory_size > 0 &&
11011 IS_CUSTOM_ELEMENT(player->inventory_element[player->inventory_size - 1])
11012 && old_element != EL_EMPTY)
11016 if (old_element != EL_EMPTY)
11017 Back[jx][jy] = old_element; /* store old element on this field */
11019 ResetGfxAnimation(jx, jy);
11020 ResetRandomAnimationValue(jx, jy);
11022 if (player->inventory_size > 0 ||
11023 player->inventory_infinite_element != EL_UNDEFINED)
11025 if (player->inventory_size > 0)
11027 player->inventory_size--;
11030 new_element = player->inventory_element[player->inventory_size];
11033 DrawGameValue_Dynamite(local_player->inventory_size);
11035 if (new_element == EL_DYNAMITE)
11036 new_element = EL_DYNAMITE_ACTIVE;
11037 else if (new_element == EL_SP_DISK_RED)
11038 new_element = EL_SP_DISK_RED_ACTIVE;
11041 Feld[jx][jy] = new_element;
11043 if (IN_SCR_FIELD(SCREENX(jx), SCREENY(jy)))
11044 DrawGraphicThruMask(SCREENX(jx), SCREENY(jy), el2img(Feld[jx][jy]), 0);
11046 PlayLevelSoundAction(jx, jy, ACTION_DROPPING);
11049 /* needed if previous element just changed to "empty" in the last frame */
11050 Changed[jx][jy] = 0; /* allow another change */
11053 CheckTriggeredElementChangePlayer(jx, jy, new_element,
11054 CE_OTHER_GETS_DROPPED,
11055 player->index_bit, drop_side);
11056 CheckElementChangePlayer(jx, jy, new_element, CE_DROPPED_BY_PLAYER,
11057 player->index_bit, drop_side);
11059 TestIfElementTouchesCustomElement(jx, jy);
11061 else /* player is dropping a dyna bomb */
11063 player->dynabombs_left--;
11066 new_element = EL_DYNABOMB_PLAYER_1_ACTIVE + player->index_nr;
11069 Feld[jx][jy] = new_element;
11071 if (IN_SCR_FIELD(SCREENX(jx), SCREENY(jy)))
11072 DrawGraphicThruMask(SCREENX(jx), SCREENY(jy), el2img(Feld[jx][jy]), 0);
11074 PlayLevelSoundAction(jx, jy, ACTION_DROPPING);
11081 if (Feld[jx][jy] == new_element) /* uninitialized unless CE change */
11084 InitField_WithBug1(jx, jy, FALSE);
11086 InitField(jx, jy, FALSE);
11087 if (CAN_MOVE(Feld[jx][jy]))
11088 InitMovDir(jx, jy);
11092 new_element = Feld[jx][jy]; /* element might have changed */
11094 if (IS_CUSTOM_ELEMENT(new_element) && CAN_MOVE(new_element) &&
11095 element_info[new_element].move_pattern == MV_WHEN_DROPPED)
11098 int move_stepsize = element_info[new_element].move_stepsize;
11100 int direction, dx, dy, nextx, nexty;
11102 if (element_info[new_element].move_direction_initial == MV_START_AUTOMATIC)
11103 MovDir[jx][jy] = player->MovDir;
11105 direction = MovDir[jx][jy];
11106 dx = (direction == MV_LEFT ? -1 : direction == MV_RIGHT ? +1 : 0);
11107 dy = (direction == MV_UP ? -1 : direction == MV_DOWN ? +1 : 0);
11111 if (IN_LEV_FIELD(nextx, nexty) && IS_FREE(nextx, nexty))
11114 WasJustMoving[jx][jy] = 3;
11116 InitMovingField(jx, jy, direction);
11117 ContinueMoving(jx, jy);
11122 Changed[jx][jy] = 0; /* allow another change */
11125 TestIfElementHitsCustomElement(jx, jy, direction);
11127 CheckElementChangeSide(jx, jy, new_element, touched_element,
11128 CE_HITTING_SOMETHING, direction);
11133 player->drop_delay = 2 * TILEX / move_stepsize + 1;
11138 player->drop_delay = 8 + 8 + 8;
11142 player->drop_delay = GET_NEW_DROP_DELAY(drop_element);
11147 player->is_dropping = TRUE;
11153 /* ------------------------------------------------------------------------- */
11154 /* game sound playing functions */
11155 /* ------------------------------------------------------------------------- */
11157 static int *loop_sound_frame = NULL;
11158 static int *loop_sound_volume = NULL;
11160 void InitPlayLevelSound()
11162 int num_sounds = getSoundListSize();
11164 checked_free(loop_sound_frame);
11165 checked_free(loop_sound_volume);
11167 loop_sound_frame = checked_calloc(num_sounds * sizeof(int));
11168 loop_sound_volume = checked_calloc(num_sounds * sizeof(int));
11171 static void PlayLevelSound(int x, int y, int nr)
11173 int sx = SCREENX(x), sy = SCREENY(y);
11174 int volume, stereo_position;
11175 int max_distance = 8;
11176 int type = (IS_LOOP_SOUND(nr) ? SND_CTRL_PLAY_LOOP : SND_CTRL_PLAY_SOUND);
11178 if ((!setup.sound_simple && !IS_LOOP_SOUND(nr)) ||
11179 (!setup.sound_loops && IS_LOOP_SOUND(nr)))
11182 if (!IN_LEV_FIELD(x, y) ||
11183 sx < -max_distance || sx >= SCR_FIELDX + max_distance ||
11184 sy < -max_distance || sy >= SCR_FIELDY + max_distance)
11187 volume = SOUND_MAX_VOLUME;
11189 if (!IN_SCR_FIELD(sx, sy))
11191 int dx = ABS(sx - SCR_FIELDX / 2) - SCR_FIELDX / 2;
11192 int dy = ABS(sy - SCR_FIELDY / 2) - SCR_FIELDY / 2;
11194 volume -= volume * (dx > dy ? dx : dy) / max_distance;
11197 stereo_position = (SOUND_MAX_LEFT +
11198 (sx + max_distance) * SOUND_MAX_LEFT2RIGHT /
11199 (SCR_FIELDX + 2 * max_distance));
11201 if (IS_LOOP_SOUND(nr))
11203 /* This assures that quieter loop sounds do not overwrite louder ones,
11204 while restarting sound volume comparison with each new game frame. */
11206 if (loop_sound_volume[nr] > volume && loop_sound_frame[nr] == FrameCounter)
11209 loop_sound_volume[nr] = volume;
11210 loop_sound_frame[nr] = FrameCounter;
11213 PlaySoundExt(nr, volume, stereo_position, type);
11216 static void PlayLevelSoundNearest(int x, int y, int sound_action)
11218 PlayLevelSound(x < LEVELX(BX1) ? LEVELX(BX1) :
11219 x > LEVELX(BX2) ? LEVELX(BX2) : x,
11220 y < LEVELY(BY1) ? LEVELY(BY1) :
11221 y > LEVELY(BY2) ? LEVELY(BY2) : y,
11225 static void PlayLevelSoundAction(int x, int y, int action)
11227 PlayLevelSoundElementAction(x, y, Feld[x][y], action);
11230 static void PlayLevelSoundElementAction(int x, int y, int element, int action)
11232 int sound_effect = element_info[element].sound[action];
11234 if (sound_effect != SND_UNDEFINED)
11235 PlayLevelSound(x, y, sound_effect);
11238 static void PlayLevelSoundElementActionIfLoop(int x, int y, int element,
11241 int sound_effect = element_info[element].sound[action];
11243 if (sound_effect != SND_UNDEFINED && IS_LOOP_SOUND(sound_effect))
11244 PlayLevelSound(x, y, sound_effect);
11247 static void PlayLevelSoundActionIfLoop(int x, int y, int action)
11249 int sound_effect = element_info[Feld[x][y]].sound[action];
11251 if (sound_effect != SND_UNDEFINED && IS_LOOP_SOUND(sound_effect))
11252 PlayLevelSound(x, y, sound_effect);
11255 static void StopLevelSoundActionIfLoop(int x, int y, int action)
11257 int sound_effect = element_info[Feld[x][y]].sound[action];
11259 if (sound_effect != SND_UNDEFINED && IS_LOOP_SOUND(sound_effect))
11260 StopSound(sound_effect);
11263 static void PlayLevelMusic()
11265 if (levelset.music[level_nr] != MUS_UNDEFINED)
11266 PlayMusic(levelset.music[level_nr]); /* from config file */
11268 PlayMusic(MAP_NOCONF_MUSIC(level_nr)); /* from music dir */
11271 void RaiseScore(int value)
11273 local_player->score += value;
11275 DrawGameValue_Score(local_player->score);
11278 void RaiseScoreElement(int element)
11283 case EL_BD_DIAMOND:
11284 case EL_EMERALD_YELLOW:
11285 case EL_EMERALD_RED:
11286 case EL_EMERALD_PURPLE:
11287 case EL_SP_INFOTRON:
11288 RaiseScore(level.score[SC_EMERALD]);
11291 RaiseScore(level.score[SC_DIAMOND]);
11294 RaiseScore(level.score[SC_CRYSTAL]);
11297 RaiseScore(level.score[SC_PEARL]);
11300 case EL_BD_BUTTERFLY:
11301 case EL_SP_ELECTRON:
11302 RaiseScore(level.score[SC_BUG]);
11305 case EL_BD_FIREFLY:
11306 case EL_SP_SNIKSNAK:
11307 RaiseScore(level.score[SC_SPACESHIP]);
11310 case EL_DARK_YAMYAM:
11311 RaiseScore(level.score[SC_YAMYAM]);
11314 RaiseScore(level.score[SC_ROBOT]);
11317 RaiseScore(level.score[SC_PACMAN]);
11320 RaiseScore(level.score[SC_NUT]);
11323 case EL_SP_DISK_RED:
11324 case EL_DYNABOMB_INCREASE_NUMBER:
11325 case EL_DYNABOMB_INCREASE_SIZE:
11326 case EL_DYNABOMB_INCREASE_POWER:
11327 RaiseScore(level.score[SC_DYNAMITE]);
11329 case EL_SHIELD_NORMAL:
11330 case EL_SHIELD_DEADLY:
11331 RaiseScore(level.score[SC_SHIELD]);
11333 case EL_EXTRA_TIME:
11334 RaiseScore(level.score[SC_TIME_BONUS]);
11340 RaiseScore(level.score[SC_KEY]);
11343 RaiseScore(element_info[element].collect_score);
11348 void RequestQuitGame(boolean ask_if_really_quit)
11350 if (AllPlayersGone ||
11351 !ask_if_really_quit ||
11352 level_editor_test_game ||
11353 Request("Do you really want to quit the game ?",
11354 REQ_ASK | REQ_STAY_CLOSED))
11356 #if defined(PLATFORM_UNIX)
11357 if (options.network)
11358 SendToServer_StopPlaying();
11362 game_status = GAME_MODE_MAIN;
11370 if (tape.playing && tape.deactivate_display)
11371 TapeDeactivateDisplayOff(TRUE);
11374 OpenDoor(DOOR_OPEN_1 | DOOR_COPY_BACK);
11377 if (tape.playing && tape.deactivate_display)
11378 TapeDeactivateDisplayOn();
11385 /* ---------- new game button stuff ---------------------------------------- */
11387 /* graphic position values for game buttons */
11388 #define GAME_BUTTON_XSIZE 30
11389 #define GAME_BUTTON_YSIZE 30
11390 #define GAME_BUTTON_XPOS 5
11391 #define GAME_BUTTON_YPOS 215
11392 #define SOUND_BUTTON_XPOS 5
11393 #define SOUND_BUTTON_YPOS (GAME_BUTTON_YPOS + GAME_BUTTON_YSIZE)
11395 #define GAME_BUTTON_STOP_XPOS (GAME_BUTTON_XPOS + 0 * GAME_BUTTON_XSIZE)
11396 #define GAME_BUTTON_PAUSE_XPOS (GAME_BUTTON_XPOS + 1 * GAME_BUTTON_XSIZE)
11397 #define GAME_BUTTON_PLAY_XPOS (GAME_BUTTON_XPOS + 2 * GAME_BUTTON_XSIZE)
11398 #define SOUND_BUTTON_MUSIC_XPOS (SOUND_BUTTON_XPOS + 0 * GAME_BUTTON_XSIZE)
11399 #define SOUND_BUTTON_LOOPS_XPOS (SOUND_BUTTON_XPOS + 1 * GAME_BUTTON_XSIZE)
11400 #define SOUND_BUTTON_SIMPLE_XPOS (SOUND_BUTTON_XPOS + 2 * GAME_BUTTON_XSIZE)
11407 } gamebutton_info[NUM_GAME_BUTTONS] =
11410 GAME_BUTTON_STOP_XPOS, GAME_BUTTON_YPOS,
11415 GAME_BUTTON_PAUSE_XPOS, GAME_BUTTON_YPOS,
11416 GAME_CTRL_ID_PAUSE,
11420 GAME_BUTTON_PLAY_XPOS, GAME_BUTTON_YPOS,
11425 SOUND_BUTTON_MUSIC_XPOS, SOUND_BUTTON_YPOS,
11426 SOUND_CTRL_ID_MUSIC,
11427 "background music on/off"
11430 SOUND_BUTTON_LOOPS_XPOS, SOUND_BUTTON_YPOS,
11431 SOUND_CTRL_ID_LOOPS,
11432 "sound loops on/off"
11435 SOUND_BUTTON_SIMPLE_XPOS, SOUND_BUTTON_YPOS,
11436 SOUND_CTRL_ID_SIMPLE,
11437 "normal sounds on/off"
11441 void CreateGameButtons()
11445 for (i = 0; i < NUM_GAME_BUTTONS; i++)
11447 Bitmap *gd_bitmap = graphic_info[IMG_GLOBAL_DOOR].bitmap;
11448 struct GadgetInfo *gi;
11451 unsigned long event_mask;
11452 int gd_xoffset, gd_yoffset;
11453 int gd_x1, gd_x2, gd_y1, gd_y2;
11456 gd_xoffset = gamebutton_info[i].x;
11457 gd_yoffset = gamebutton_info[i].y;
11458 gd_x1 = DOOR_GFX_PAGEX4 + gd_xoffset;
11459 gd_x2 = DOOR_GFX_PAGEX3 + gd_xoffset;
11461 if (id == GAME_CTRL_ID_STOP ||
11462 id == GAME_CTRL_ID_PAUSE ||
11463 id == GAME_CTRL_ID_PLAY)
11465 button_type = GD_TYPE_NORMAL_BUTTON;
11467 event_mask = GD_EVENT_RELEASED;
11468 gd_y1 = DOOR_GFX_PAGEY1 + gd_yoffset - GAME_BUTTON_YSIZE;
11469 gd_y2 = DOOR_GFX_PAGEY1 + gd_yoffset - GAME_BUTTON_YSIZE;
11473 button_type = GD_TYPE_CHECK_BUTTON;
11475 ((id == SOUND_CTRL_ID_MUSIC && setup.sound_music) ||
11476 (id == SOUND_CTRL_ID_LOOPS && setup.sound_loops) ||
11477 (id == SOUND_CTRL_ID_SIMPLE && setup.sound_simple) ? TRUE : FALSE);
11478 event_mask = GD_EVENT_PRESSED;
11479 gd_y1 = DOOR_GFX_PAGEY1 + gd_yoffset;
11480 gd_y2 = DOOR_GFX_PAGEY1 + gd_yoffset - GAME_BUTTON_YSIZE;
11483 gi = CreateGadget(GDI_CUSTOM_ID, id,
11484 GDI_INFO_TEXT, gamebutton_info[i].infotext,
11485 GDI_X, DX + gd_xoffset,
11486 GDI_Y, DY + gd_yoffset,
11487 GDI_WIDTH, GAME_BUTTON_XSIZE,
11488 GDI_HEIGHT, GAME_BUTTON_YSIZE,
11489 GDI_TYPE, button_type,
11490 GDI_STATE, GD_BUTTON_UNPRESSED,
11491 GDI_CHECKED, checked,
11492 GDI_DESIGN_UNPRESSED, gd_bitmap, gd_x1, gd_y1,
11493 GDI_DESIGN_PRESSED, gd_bitmap, gd_x2, gd_y1,
11494 GDI_ALT_DESIGN_UNPRESSED, gd_bitmap, gd_x1, gd_y2,
11495 GDI_ALT_DESIGN_PRESSED, gd_bitmap, gd_x2, gd_y2,
11496 GDI_EVENT_MASK, event_mask,
11497 GDI_CALLBACK_ACTION, HandleGameButtons,
11501 Error(ERR_EXIT, "cannot create gadget");
11503 game_gadget[id] = gi;
11507 void FreeGameButtons()
11511 for (i = 0; i < NUM_GAME_BUTTONS; i++)
11512 FreeGadget(game_gadget[i]);
11515 static void MapGameButtons()
11519 for (i = 0; i < NUM_GAME_BUTTONS; i++)
11520 MapGadget(game_gadget[i]);
11523 void UnmapGameButtons()
11527 for (i = 0; i < NUM_GAME_BUTTONS; i++)
11528 UnmapGadget(game_gadget[i]);
11531 static void HandleGameButtons(struct GadgetInfo *gi)
11533 int id = gi->custom_id;
11535 if (game_status != GAME_MODE_PLAYING)
11540 case GAME_CTRL_ID_STOP:
11541 RequestQuitGame(TRUE);
11544 case GAME_CTRL_ID_PAUSE:
11545 if (options.network)
11547 #if defined(PLATFORM_UNIX)
11549 SendToServer_ContinuePlaying();
11551 SendToServer_PausePlaying();
11555 TapeTogglePause(TAPE_TOGGLE_MANUAL);
11558 case GAME_CTRL_ID_PLAY:
11561 #if defined(PLATFORM_UNIX)
11562 if (options.network)
11563 SendToServer_ContinuePlaying();
11567 tape.pausing = FALSE;
11568 DrawVideoDisplay(VIDEO_STATE_PAUSE_OFF,0);
11573 case SOUND_CTRL_ID_MUSIC:
11574 if (setup.sound_music)
11576 setup.sound_music = FALSE;
11579 else if (audio.music_available)
11581 setup.sound = setup.sound_music = TRUE;
11583 SetAudioMode(setup.sound);
11589 case SOUND_CTRL_ID_LOOPS:
11590 if (setup.sound_loops)
11591 setup.sound_loops = FALSE;
11592 else if (audio.loops_available)
11594 setup.sound = setup.sound_loops = TRUE;
11595 SetAudioMode(setup.sound);
11599 case SOUND_CTRL_ID_SIMPLE:
11600 if (setup.sound_simple)
11601 setup.sound_simple = FALSE;
11602 else if (audio.sound_available)
11604 setup.sound = setup.sound_simple = TRUE;
11605 SetAudioMode(setup.sound);