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 GET_DX_FROM_DIR(d) ((d) == MV_LEFT ? -1 : (d) == MV_RIGHT ? 1 : 0)
100 #define GET_DY_FROM_DIR(d) ((d) == MV_UP ? -1 : (d) == MV_DOWN ? 1 : 0)
102 #define INIT_GFX_RANDOM() (SimpleRND(1000000))
104 #define GET_NEW_PUSH_DELAY(e) ( (element_info[e].push_delay_fixed) + \
105 RND(element_info[e].push_delay_random))
106 #define GET_NEW_DROP_DELAY(e) ( (element_info[e].drop_delay_fixed) + \
107 RND(element_info[e].drop_delay_random))
108 #define GET_NEW_MOVE_DELAY(e) ( (element_info[e].move_delay_fixed) + \
109 RND(element_info[e].move_delay_random))
110 #define GET_MAX_MOVE_DELAY(e) ( (element_info[e].move_delay_fixed) + \
111 (element_info[e].move_delay_random))
113 #define GET_TARGET_ELEMENT(e, ch) \
114 ((e) == EL_TRIGGER_ELEMENT ? (ch)->actual_trigger_element : \
115 (e) == EL_TRIGGER_PLAYER ? (ch)->actual_trigger_player : (e))
117 #define GET_VALID_PLAYER_ELEMENT(e) \
118 ((e) >= EL_PLAYER_1 && (e) <= EL_PLAYER_4 ? (e) : EL_PLAYER_1)
120 #define CAN_GROW_INTO(e) \
121 ((e) == EL_SAND || (IS_DIGGABLE(e) && level.grow_into_diggable))
123 #define ELEMENT_CAN_ENTER_FIELD_BASE_X(x, y, condition) \
124 (IN_LEV_FIELD(x, y) && (IS_FREE(x, y) || \
127 #define ELEMENT_CAN_ENTER_FIELD_BASE_2(e, x, y, condition) \
128 (IN_LEV_FIELD(x, y) && (IS_FREE(x, y) || \
129 (CAN_MOVE_INTO_ACID(e) && \
130 Feld[x][y] == EL_ACID) || \
133 #define ELEMENT_CAN_ENTER_FIELD_BASE_3(e, x, y, condition) \
134 (IN_LEV_FIELD(x, y) && (IS_FREE_OR_PLAYER(x, y) || \
135 (CAN_MOVE_INTO_ACID(e) && \
136 Feld[x][y] == EL_ACID) || \
139 #define ELEMENT_CAN_ENTER_FIELD_BASE_4(e, x, y, condition) \
140 (IN_LEV_FIELD(x, y) && (IS_FREE(x, y) || \
142 (CAN_MOVE_INTO_ACID(e) && \
143 Feld[x][y] == EL_ACID) || \
144 (DONT_COLLIDE_WITH(e) && \
146 !PLAYER_ENEMY_PROTECTED(x, y))))
149 #define ELEMENT_CAN_ENTER_FIELD_GENERIC(e, x, y, condition) \
150 (IN_LEV_FIELD(x, y) && (IS_FREE(x, y) || \
152 (DONT_COLLIDE_WITH(e) && \
154 !PLAYER_ENEMY_PROTECTED(x, y))))
157 #define ELEMENT_CAN_ENTER_FIELD(e, x, y) \
158 ELEMENT_CAN_ENTER_FIELD_BASE_4(e, x, y, 0)
161 #define SATELLITE_CAN_ENTER_FIELD(x, y) \
162 ELEMENT_CAN_ENTER_FIELD_BASE_2(EL_SATELLITE, x, y, 0)
164 #define SATELLITE_CAN_ENTER_FIELD(x, y) \
165 ELEMENT_CAN_ENTER_FIELD_BASE_X(x, y, Feld[x][y] == EL_ACID)
169 #define ENEMY_CAN_ENTER_FIELD(e, x, y) (IN_LEV_FIELD(x, y) && IS_FREE(x, y))
172 #define ENEMY_CAN_ENTER_FIELD(e, x, y) \
173 ELEMENT_CAN_ENTER_FIELD_BASE_2(e, x, y, 0)
177 #define YAMYAM_CAN_ENTER_FIELD(e, x, y) \
178 ELEMENT_CAN_ENTER_FIELD_BASE_3(e, x, y, Feld[x][y] == EL_DIAMOND)
180 #define DARK_YAMYAM_CAN_ENTER_FIELD(e, x, y) \
181 ELEMENT_CAN_ENTER_FIELD_BASE_3(e, x,y, IS_FOOD_DARK_YAMYAM(Feld[x][y]))
183 #define PACMAN_CAN_ENTER_FIELD(e, x, y) \
184 ELEMENT_CAN_ENTER_FIELD_BASE_3(e, x, y, IS_AMOEBOID(Feld[x][y]))
186 #define PIG_CAN_ENTER_FIELD(e, x, y) \
187 ELEMENT_CAN_ENTER_FIELD_BASE_2(e, x, y, IS_FOOD_PIG(Feld[x][y]))
189 #define PENGUIN_CAN_ENTER_FIELD(e, x, y) \
190 ELEMENT_CAN_ENTER_FIELD_BASE_2(e, x, y, (Feld[x][y] == EL_EXIT_OPEN ||\
191 IS_FOOD_PENGUIN(Feld[x][y])))
192 #define DRAGON_CAN_ENTER_FIELD(e, x, y) \
193 ELEMENT_CAN_ENTER_FIELD_BASE_2(e, x, y, 0)
195 #define MOLE_CAN_ENTER_FIELD(e, x, y, condition) \
196 ELEMENT_CAN_ENTER_FIELD_BASE_2(e, x, y, (condition))
198 #define SPRING_CAN_ENTER_FIELD(e, x, y) \
199 ELEMENT_CAN_ENTER_FIELD_BASE_2(e, x, y, 0)
203 #define YAMYAM_CAN_ENTER_FIELD(e, x, y) \
204 (IN_LEV_FIELD(x, y) && (IS_FREE_OR_PLAYER(x, y) || \
205 (CAN_MOVE_INTO_ACID(e) && \
206 Feld[x][y] == EL_ACID) || \
207 Feld[x][y] == EL_DIAMOND))
209 #define DARK_YAMYAM_CAN_ENTER_FIELD(e, x, y) \
210 (IN_LEV_FIELD(x, y) && (IS_FREE_OR_PLAYER(x, y) || \
211 (CAN_MOVE_INTO_ACID(e) && \
212 Feld[x][y] == EL_ACID) || \
213 IS_FOOD_DARK_YAMYAM(Feld[x][y])))
215 #define PACMAN_CAN_ENTER_FIELD(e, x, y) \
216 (IN_LEV_FIELD(x, y) && (IS_FREE_OR_PLAYER(x, y) || \
217 (CAN_MOVE_INTO_ACID(e) && \
218 Feld[x][y] == EL_ACID) || \
219 IS_AMOEBOID(Feld[x][y])))
221 #define PIG_CAN_ENTER_FIELD(e, x, y) \
222 (IN_LEV_FIELD(x, y) && (IS_FREE(x, y) || \
223 (CAN_MOVE_INTO_ACID(e) && \
224 Feld[x][y] == EL_ACID) || \
225 IS_FOOD_PIG(Feld[x][y])))
227 #define PENGUIN_CAN_ENTER_FIELD(e, x, y) \
228 (IN_LEV_FIELD(x, y) && (IS_FREE(x, y) || \
229 (CAN_MOVE_INTO_ACID(e) && \
230 Feld[x][y] == EL_ACID) || \
231 IS_FOOD_PENGUIN(Feld[x][y]) || \
232 Feld[x][y] == EL_EXIT_OPEN))
234 #define DRAGON_CAN_ENTER_FIELD(e, x, y) \
235 (IN_LEV_FIELD(x, y) && (IS_FREE(x, y) || \
236 (CAN_MOVE_INTO_ACID(e) && \
237 Feld[x][y] == EL_ACID)))
239 #define MOLE_CAN_ENTER_FIELD(e, x, y, condition) \
240 (IN_LEV_FIELD(x, y) && (IS_FREE(x, y) || \
241 (CAN_MOVE_INTO_ACID(e) && \
242 Feld[x][y] == EL_ACID) || \
245 #define SPRING_CAN_ENTER_FIELD(e, x, y) \
246 (IN_LEV_FIELD(x, y) && (IS_FREE(x, y) || \
247 (CAN_MOVE_INTO_ACID(e) && \
248 Feld[x][y] == EL_ACID)))
252 #define GROUP_NR(e) ((e) - EL_GROUP_START)
253 #define MOVE_ENTER_EL(e) (element_info[e].move_enter_element)
254 #define IS_IN_GROUP(e, nr) (element_info[e].in_group[nr] == TRUE)
255 #define IS_IN_GROUP_EL(e, ge) (IS_IN_GROUP(e, (ge) - EL_GROUP_START))
257 #define IS_EQUAL_OR_IN_GROUP(e, ge) \
258 (IS_GROUP_ELEMENT(ge) ? IS_IN_GROUP(e, GROUP_NR(ge)) : (e) == (ge))
261 #define CE_ENTER_FIELD_COND(e, x, y) \
262 (!IS_PLAYER(x, y) && \
263 (Feld[x][y] == EL_ACID || \
264 IS_EQUAL_OR_IN_GROUP(Feld[x][y], MOVE_ENTER_EL(e))))
266 #define CE_ENTER_FIELD_COND(e, x, y) \
267 (!IS_PLAYER(x, y) && \
268 IS_EQUAL_OR_IN_GROUP(Feld[x][y], MOVE_ENTER_EL(e)))
271 #define CUSTOM_ELEMENT_CAN_ENTER_FIELD(e, x, y) \
272 ELEMENT_CAN_ENTER_FIELD_BASE_4(e, x, y, CE_ENTER_FIELD_COND(e, x, y))
274 #define IN_LEV_FIELD_AND_IS_FREE(x, y) (IN_LEV_FIELD(x, y) && IS_FREE(x, y))
275 #define IN_LEV_FIELD_AND_NOT_FREE(x, y) (IN_LEV_FIELD(x, y) && !IS_FREE(x, y))
277 #define ACCESS_FROM(e, d) (element_info[e].access_direction &(d))
278 #define IS_WALKABLE_FROM(e, d) (IS_WALKABLE(e) && ACCESS_FROM(e, d))
279 #define IS_PASSABLE_FROM(e, d) (IS_PASSABLE(e) && ACCESS_FROM(e, d))
280 #define IS_ACCESSIBLE_FROM(e, d) (IS_ACCESSIBLE(e) && ACCESS_FROM(e, d))
282 /* game button identifiers */
283 #define GAME_CTRL_ID_STOP 0
284 #define GAME_CTRL_ID_PAUSE 1
285 #define GAME_CTRL_ID_PLAY 2
286 #define SOUND_CTRL_ID_MUSIC 3
287 #define SOUND_CTRL_ID_LOOPS 4
288 #define SOUND_CTRL_ID_SIMPLE 5
290 #define NUM_GAME_BUTTONS 6
293 /* forward declaration for internal use */
295 static boolean MovePlayerOneStep(struct PlayerInfo *, int, int, int, int);
296 static boolean MovePlayer(struct PlayerInfo *, int, int);
297 static void ScrollPlayer(struct PlayerInfo *, int);
298 static void ScrollScreen(struct PlayerInfo *, int);
300 int DigField(struct PlayerInfo *, int, int, int, int, int, int, int);
302 static void InitBeltMovement(void);
303 static void CloseAllOpenTimegates(void);
304 static void CheckGravityMovement(struct PlayerInfo *);
305 static void CheckGravityMovementWhenNotMoving(struct PlayerInfo *);
306 static void KillHeroUnlessEnemyProtected(int, int);
307 static void KillHeroUnlessExplosionProtected(int, int);
309 static void TestIfPlayerTouchesCustomElement(int, int);
310 static void TestIfElementTouchesCustomElement(int, int);
311 static void TestIfElementHitsCustomElement(int, int, int);
313 static void TestIfElementSmashesCustomElement(int, int, int);
316 static void ChangeElement(int, int, int);
318 static boolean CheckTriggeredElementChangeExt(int, int, int, int, int,int,int);
319 #define CheckTriggeredElementChange(x, y, e, ev) \
320 CheckTriggeredElementChangeExt(x, y, e, ev, CH_PLAYER_ANY, \
322 #define CheckTriggeredElementChangeByPlayer(x, y, e, ev, p, s) \
323 CheckTriggeredElementChangeExt(x, y, e, ev, p, s, -1)
324 #define CheckTriggeredElementChangeBySide(x, y, e, ev, s) \
325 CheckTriggeredElementChangeExt(x, y, e, ev, CH_PLAYER_ANY, s, -1)
326 #define CheckTriggeredElementChangeByPage(x, y, e, ev, p) \
327 CheckTriggeredElementChangeExt(x, y, e, ev, CH_PLAYER_ANY, \
330 static boolean CheckElementChangeExt(int, int, int, int, int, int, int, int);
331 #define CheckElementChange(x, y, e, te, ev) \
332 CheckElementChangeExt(x, y, e, te, ev, CH_PLAYER_ANY, CH_SIDE_ANY, -1)
333 #define CheckElementChangeByPlayer(x, y, e, ev, p, s) \
334 CheckElementChangeExt(x, y, e, EL_EMPTY, ev, p, s, CH_PAGE_ANY)
335 #define CheckElementChangeBySide(x, y, e, te, ev, s) \
336 CheckElementChangeExt(x, y, e, te, ev, CH_PLAYER_ANY, s, CH_PAGE_ANY)
337 #define CheckElementChangeByPage(x, y, e, te, ev, p) \
338 CheckElementChangeExt(x, y, e, te, ev, CH_PLAYER_ANY, CH_SIDE_ANY, p)
340 static void PlayLevelSound(int, int, int);
341 static void PlayLevelSoundNearest(int, int, int);
342 static void PlayLevelSoundAction(int, int, int);
343 static void PlayLevelSoundElementAction(int, int, int, int);
344 static void PlayLevelSoundElementActionIfLoop(int, int, int, int);
345 static void PlayLevelSoundActionIfLoop(int, int, int);
346 static void StopLevelSoundActionIfLoop(int, int, int);
347 static void PlayLevelMusic();
349 static void MapGameButtons();
350 static void HandleGameButtons(struct GadgetInfo *);
352 static struct GadgetInfo *game_gadget[NUM_GAME_BUTTONS];
355 /* ------------------------------------------------------------------------- */
356 /* definition of elements that automatically change to other elements after */
357 /* a specified time, eventually calling a function when changing */
358 /* ------------------------------------------------------------------------- */
360 /* forward declaration for changer functions */
361 static void InitBuggyBase(int x, int y);
362 static void WarnBuggyBase(int x, int y);
364 static void InitTrap(int x, int y);
365 static void ActivateTrap(int x, int y);
366 static void ChangeActiveTrap(int x, int y);
368 static void InitRobotWheel(int x, int y);
369 static void RunRobotWheel(int x, int y);
370 static void StopRobotWheel(int x, int y);
372 static void InitTimegateWheel(int x, int y);
373 static void RunTimegateWheel(int x, int y);
375 struct ChangingElementInfo
380 void (*pre_change_function)(int x, int y);
381 void (*change_function)(int x, int y);
382 void (*post_change_function)(int x, int y);
385 static struct ChangingElementInfo change_delay_list[] =
436 EL_SWITCHGATE_OPENING,
444 EL_SWITCHGATE_CLOSING,
445 EL_SWITCHGATE_CLOSED,
477 EL_ACID_SPLASH_RIGHT,
486 EL_SP_BUGGY_BASE_ACTIVATING,
493 EL_SP_BUGGY_BASE_ACTIVATING,
494 EL_SP_BUGGY_BASE_ACTIVE,
501 EL_SP_BUGGY_BASE_ACTIVE,
525 EL_ROBOT_WHEEL_ACTIVE,
533 EL_TIMEGATE_SWITCH_ACTIVE,
554 int push_delay_fixed, push_delay_random;
559 { EL_BALLOON, 0, 0 },
561 { EL_SOKOBAN_OBJECT, 2, 0 },
562 { EL_SOKOBAN_FIELD_FULL, 2, 0 },
563 { EL_SATELLITE, 2, 0 },
564 { EL_SP_DISK_YELLOW, 2, 0 },
566 { EL_UNDEFINED, 0, 0 },
574 move_stepsize_list[] =
576 { EL_AMOEBA_DROP, 2 },
577 { EL_AMOEBA_DROPPING, 2 },
578 { EL_QUICKSAND_FILLING, 1 },
579 { EL_QUICKSAND_EMPTYING, 1 },
580 { EL_MAGIC_WALL_FILLING, 2 },
581 { EL_BD_MAGIC_WALL_FILLING, 2 },
582 { EL_MAGIC_WALL_EMPTYING, 2 },
583 { EL_BD_MAGIC_WALL_EMPTYING, 2 },
593 collect_count_list[] =
596 { EL_BD_DIAMOND, 1 },
597 { EL_EMERALD_YELLOW, 1 },
598 { EL_EMERALD_RED, 1 },
599 { EL_EMERALD_PURPLE, 1 },
601 { EL_SP_INFOTRON, 1 },
613 access_direction_list[] =
615 { EL_TUBE_ANY, MV_LEFT | MV_RIGHT | MV_UP | MV_DOWN },
616 { EL_TUBE_VERTICAL, MV_UP | MV_DOWN },
617 { EL_TUBE_HORIZONTAL, MV_LEFT | MV_RIGHT },
618 { EL_TUBE_VERTICAL_LEFT, MV_LEFT | MV_UP | MV_DOWN },
619 { EL_TUBE_VERTICAL_RIGHT, MV_RIGHT | MV_UP | MV_DOWN },
620 { EL_TUBE_HORIZONTAL_UP, MV_LEFT | MV_RIGHT | MV_UP },
621 { EL_TUBE_HORIZONTAL_DOWN, MV_LEFT | MV_RIGHT | MV_DOWN },
622 { EL_TUBE_LEFT_UP, MV_LEFT | MV_UP },
623 { EL_TUBE_LEFT_DOWN, MV_LEFT | MV_DOWN },
624 { EL_TUBE_RIGHT_UP, MV_RIGHT | MV_UP },
625 { EL_TUBE_RIGHT_DOWN, MV_RIGHT | MV_DOWN },
627 { EL_SP_PORT_LEFT, MV_RIGHT },
628 { EL_SP_PORT_RIGHT, MV_LEFT },
629 { EL_SP_PORT_UP, MV_DOWN },
630 { EL_SP_PORT_DOWN, MV_UP },
631 { EL_SP_PORT_HORIZONTAL, MV_LEFT | MV_RIGHT },
632 { EL_SP_PORT_VERTICAL, MV_UP | MV_DOWN },
633 { EL_SP_PORT_ANY, MV_LEFT | MV_RIGHT | MV_UP | MV_DOWN },
634 { EL_SP_GRAVITY_PORT_LEFT, MV_RIGHT },
635 { EL_SP_GRAVITY_PORT_RIGHT, MV_LEFT },
636 { EL_SP_GRAVITY_PORT_UP, MV_DOWN },
637 { EL_SP_GRAVITY_PORT_DOWN, MV_UP },
638 { EL_SP_GRAVITY_ON_PORT_LEFT, MV_RIGHT },
639 { EL_SP_GRAVITY_ON_PORT_RIGHT, MV_LEFT },
640 { EL_SP_GRAVITY_ON_PORT_UP, MV_DOWN },
641 { EL_SP_GRAVITY_ON_PORT_DOWN, MV_UP },
642 { EL_SP_GRAVITY_OFF_PORT_LEFT, MV_RIGHT },
643 { EL_SP_GRAVITY_OFF_PORT_RIGHT, MV_LEFT },
644 { EL_SP_GRAVITY_OFF_PORT_UP, MV_DOWN },
645 { EL_SP_GRAVITY_OFF_PORT_DOWN, MV_UP },
647 { EL_UNDEFINED, MV_NO_MOVING }
650 static unsigned long trigger_events[MAX_NUM_ELEMENTS];
652 #define IS_AUTO_CHANGING(e) (element_info[e].change_events & \
653 CH_EVENT_BIT(CE_DELAY))
654 #define IS_JUST_CHANGING(x, y) (ChangeDelay[x][y] != 0)
655 #define IS_CHANGING(x, y) (IS_AUTO_CHANGING(Feld[x][y]) || \
656 IS_JUST_CHANGING(x, y))
658 #define CE_PAGE(e, ce) (element_info[e].event_page[ce])
661 void GetPlayerConfig()
663 if (!audio.sound_available)
664 setup.sound_simple = FALSE;
666 if (!audio.loops_available)
667 setup.sound_loops = FALSE;
669 if (!audio.music_available)
670 setup.sound_music = FALSE;
672 if (!video.fullscreen_available)
673 setup.fullscreen = FALSE;
675 setup.sound = (setup.sound_simple || setup.sound_loops || setup.sound_music);
677 SetAudioMode(setup.sound);
681 static int getBeltNrFromBeltElement(int element)
683 return (element < EL_CONVEYOR_BELT_2_LEFT ? 0 :
684 element < EL_CONVEYOR_BELT_3_LEFT ? 1 :
685 element < EL_CONVEYOR_BELT_4_LEFT ? 2 : 3);
688 static int getBeltNrFromBeltActiveElement(int element)
690 return (element < EL_CONVEYOR_BELT_2_LEFT_ACTIVE ? 0 :
691 element < EL_CONVEYOR_BELT_3_LEFT_ACTIVE ? 1 :
692 element < EL_CONVEYOR_BELT_4_LEFT_ACTIVE ? 2 : 3);
695 static int getBeltNrFromBeltSwitchElement(int element)
697 return (element < EL_CONVEYOR_BELT_2_SWITCH_LEFT ? 0 :
698 element < EL_CONVEYOR_BELT_3_SWITCH_LEFT ? 1 :
699 element < EL_CONVEYOR_BELT_4_SWITCH_LEFT ? 2 : 3);
702 static int getBeltDirNrFromBeltSwitchElement(int element)
704 static int belt_base_element[4] =
706 EL_CONVEYOR_BELT_1_SWITCH_LEFT,
707 EL_CONVEYOR_BELT_2_SWITCH_LEFT,
708 EL_CONVEYOR_BELT_3_SWITCH_LEFT,
709 EL_CONVEYOR_BELT_4_SWITCH_LEFT
712 int belt_nr = getBeltNrFromBeltSwitchElement(element);
713 int belt_dir_nr = element - belt_base_element[belt_nr];
715 return (belt_dir_nr % 3);
718 static int getBeltDirFromBeltSwitchElement(int element)
720 static int belt_move_dir[3] =
727 int belt_dir_nr = getBeltDirNrFromBeltSwitchElement(element);
729 return belt_move_dir[belt_dir_nr];
732 static void InitPlayerField(int x, int y, int element, boolean init_game)
734 if (element == EL_SP_MURPHY)
738 if (stored_player[0].present)
740 Feld[x][y] = EL_SP_MURPHY_CLONE;
746 stored_player[0].use_murphy_graphic = TRUE;
749 Feld[x][y] = EL_PLAYER_1;
755 struct PlayerInfo *player = &stored_player[Feld[x][y] - EL_PLAYER_1];
756 int jx = player->jx, jy = player->jy;
758 player->present = TRUE;
760 player->block_last_field = (element == EL_SP_MURPHY ?
761 level.sp_block_last_field :
762 level.block_last_field);
764 if (!options.network || player->connected)
766 player->active = TRUE;
768 /* remove potentially duplicate players */
769 if (StorePlayer[jx][jy] == Feld[x][y])
770 StorePlayer[jx][jy] = 0;
772 StorePlayer[x][y] = Feld[x][y];
776 printf("Player %d activated.\n", player->element_nr);
777 printf("[Local player is %d and currently %s.]\n",
778 local_player->element_nr,
779 local_player->active ? "active" : "not active");
783 Feld[x][y] = EL_EMPTY;
785 player->jx = player->last_jx = x;
786 player->jy = player->last_jy = y;
790 static void InitField(int x, int y, boolean init_game)
792 int element = Feld[x][y];
801 InitPlayerField(x, y, element, init_game);
804 case EL_SOKOBAN_FIELD_PLAYER:
805 element = Feld[x][y] = EL_PLAYER_1;
806 InitField(x, y, init_game);
808 element = Feld[x][y] = EL_SOKOBAN_FIELD_EMPTY;
809 InitField(x, y, init_game);
812 case EL_SOKOBAN_FIELD_EMPTY:
813 local_player->sokobanfields_still_needed++;
817 if (x < lev_fieldx-1 && Feld[x+1][y] == EL_ACID)
818 Feld[x][y] = EL_ACID_POOL_TOPLEFT;
819 else if (x > 0 && Feld[x-1][y] == EL_ACID)
820 Feld[x][y] = EL_ACID_POOL_TOPRIGHT;
821 else if (y > 0 && Feld[x][y-1] == EL_ACID_POOL_TOPLEFT)
822 Feld[x][y] = EL_ACID_POOL_BOTTOMLEFT;
823 else if (y > 0 && Feld[x][y-1] == EL_ACID)
824 Feld[x][y] = EL_ACID_POOL_BOTTOM;
825 else if (y > 0 && Feld[x][y-1] == EL_ACID_POOL_TOPRIGHT)
826 Feld[x][y] = EL_ACID_POOL_BOTTOMRIGHT;
834 case EL_SPACESHIP_RIGHT:
835 case EL_SPACESHIP_UP:
836 case EL_SPACESHIP_LEFT:
837 case EL_SPACESHIP_DOWN:
839 case EL_BD_BUTTERFLY_RIGHT:
840 case EL_BD_BUTTERFLY_UP:
841 case EL_BD_BUTTERFLY_LEFT:
842 case EL_BD_BUTTERFLY_DOWN:
843 case EL_BD_BUTTERFLY:
844 case EL_BD_FIREFLY_RIGHT:
845 case EL_BD_FIREFLY_UP:
846 case EL_BD_FIREFLY_LEFT:
847 case EL_BD_FIREFLY_DOWN:
849 case EL_PACMAN_RIGHT:
873 if (y == lev_fieldy - 1)
875 Feld[x][y] = EL_AMOEBA_GROWING;
876 Store[x][y] = EL_AMOEBA_WET;
880 case EL_DYNAMITE_ACTIVE:
881 case EL_SP_DISK_RED_ACTIVE:
882 case EL_DYNABOMB_PLAYER_1_ACTIVE:
883 case EL_DYNABOMB_PLAYER_2_ACTIVE:
884 case EL_DYNABOMB_PLAYER_3_ACTIVE:
885 case EL_DYNABOMB_PLAYER_4_ACTIVE:
890 local_player->lights_still_needed++;
894 local_player->friends_still_needed++;
899 GfxDir[x][y] = MovDir[x][y] = 1 << RND(4);
904 Feld[x][y] = EL_EMPTY;
909 case EL_EM_KEY_1_FILE:
910 Feld[x][y] = EL_EM_KEY_1;
912 case EL_EM_KEY_2_FILE:
913 Feld[x][y] = EL_EM_KEY_2;
915 case EL_EM_KEY_3_FILE:
916 Feld[x][y] = EL_EM_KEY_3;
918 case EL_EM_KEY_4_FILE:
919 Feld[x][y] = EL_EM_KEY_4;
923 case EL_CONVEYOR_BELT_1_SWITCH_LEFT:
924 case EL_CONVEYOR_BELT_1_SWITCH_MIDDLE:
925 case EL_CONVEYOR_BELT_1_SWITCH_RIGHT:
926 case EL_CONVEYOR_BELT_2_SWITCH_LEFT:
927 case EL_CONVEYOR_BELT_2_SWITCH_MIDDLE:
928 case EL_CONVEYOR_BELT_2_SWITCH_RIGHT:
929 case EL_CONVEYOR_BELT_3_SWITCH_LEFT:
930 case EL_CONVEYOR_BELT_3_SWITCH_MIDDLE:
931 case EL_CONVEYOR_BELT_3_SWITCH_RIGHT:
932 case EL_CONVEYOR_BELT_4_SWITCH_LEFT:
933 case EL_CONVEYOR_BELT_4_SWITCH_MIDDLE:
934 case EL_CONVEYOR_BELT_4_SWITCH_RIGHT:
937 int belt_nr = getBeltNrFromBeltSwitchElement(Feld[x][y]);
938 int belt_dir = getBeltDirFromBeltSwitchElement(Feld[x][y]);
939 int belt_dir_nr = getBeltDirNrFromBeltSwitchElement(Feld[x][y]);
941 if (game.belt_dir_nr[belt_nr] == 3) /* initial value */
943 game.belt_dir[belt_nr] = belt_dir;
944 game.belt_dir_nr[belt_nr] = belt_dir_nr;
946 else /* more than one switch -- set it like the first switch */
948 Feld[x][y] = Feld[x][y] - belt_dir_nr + game.belt_dir_nr[belt_nr];
953 case EL_SWITCHGATE_SWITCH_DOWN: /* always start with same switch pos */
955 Feld[x][y] = EL_SWITCHGATE_SWITCH_UP;
958 case EL_LIGHT_SWITCH_ACTIVE:
960 game.light_time_left = level.time_light * FRAMES_PER_SECOND;
964 if (IS_CUSTOM_ELEMENT(element) && CAN_MOVE(element))
966 else if (IS_GROUP_ELEMENT(element))
968 struct ElementGroupInfo *group = element_info[element].group;
969 int last_anim_random_frame = gfx.anim_random_frame;
972 if (group->choice_mode == ANIM_RANDOM)
973 gfx.anim_random_frame = RND(group->num_elements_resolved);
975 element_pos = getAnimationFrame(group->num_elements_resolved, 1,
976 group->choice_mode, 0,
979 if (group->choice_mode == ANIM_RANDOM)
980 gfx.anim_random_frame = last_anim_random_frame;
984 Feld[x][y] = group->element_resolved[element_pos];
986 InitField(x, y, init_game);
992 static inline void InitField_WithBug1(int x, int y, boolean init_game)
994 InitField(x, y, init_game);
996 /* not needed to call InitMovDir() -- already done by InitField()! */
997 if (game.engine_version < VERSION_IDENT(3,1,0,0) &&
998 CAN_MOVE(Feld[x][y]))
1002 static inline void InitField_WithBug2(int x, int y, boolean init_game)
1004 int old_element = Feld[x][y];
1006 InitField(x, y, init_game);
1008 /* not needed to call InitMovDir() -- already done by InitField()! */
1009 if (game.engine_version < VERSION_IDENT(3,1,0,0) &&
1010 CAN_MOVE(old_element) &&
1011 (old_element < EL_MOLE_LEFT || old_element > EL_MOLE_DOWN))
1014 /* this case is in fact a combination of not less than three bugs:
1015 first, it calls InitMovDir() for elements that can move, although this is
1016 already done by InitField(); then, it checks the element that was at this
1017 field _before_ the call to InitField() (which can change it); lastly, it
1018 was not called for "mole with direction" elements, which were treated as
1019 "cannot move" due to (fixed) wrong element initialization in "src/init.c"
1023 inline void DrawGameValue_Emeralds(int value)
1025 DrawText(DX_EMERALDS, DY_EMERALDS, int2str(value, 3), FONT_TEXT_2);
1028 inline void DrawGameValue_Dynamite(int value)
1030 DrawText(DX_DYNAMITE, DY_DYNAMITE, int2str(value, 3), FONT_TEXT_2);
1033 inline void DrawGameValue_Keys(struct PlayerInfo *player)
1037 for (i = 0; i < MAX_KEYS; i++)
1039 DrawMiniGraphicExt(drawto, DX_KEYS + i * MINI_TILEX, DY_KEYS,
1040 el2edimg(EL_KEY_1 + i));
1043 inline void DrawGameValue_Score(int value)
1045 DrawText(DX_SCORE, DY_SCORE, int2str(value, 5), FONT_TEXT_2);
1048 inline void DrawGameValue_Time(int value)
1051 DrawText(DX_TIME1, DY_TIME, int2str(value, 3), FONT_TEXT_2);
1053 DrawText(DX_TIME2, DY_TIME, int2str(value, 4), FONT_LEVEL_NUMBER);
1056 inline void DrawGameValue_Level(int value)
1059 DrawText(DX_LEVEL, DY_LEVEL, int2str(value, 2), FONT_TEXT_2);
1062 /* misuse area for displaying emeralds to draw bigger level number */
1063 DrawTextExt(drawto, DX_EMERALDS, DY_EMERALDS,
1064 int2str(value, 3), FONT_LEVEL_NUMBER, BLIT_OPAQUE);
1066 /* now copy it to the area for displaying level number */
1067 BlitBitmap(drawto, drawto,
1068 DX_EMERALDS, DY_EMERALDS + 1,
1069 getFontWidth(FONT_LEVEL_NUMBER) * 3,
1070 getFontHeight(FONT_LEVEL_NUMBER) - 1,
1071 DX_LEVEL - 1, DY_LEVEL + 1);
1073 /* restore the area for displaying emeralds */
1074 DrawGameValue_Emeralds(local_player->gems_still_needed);
1076 /* yes, this is all really ugly :-) */
1080 void DrawGameDoorValues()
1084 DrawGameValue_Level(level_nr);
1086 for (i = 0; i < MAX_PLAYERS; i++)
1087 DrawGameValue_Keys(&stored_player[i]);
1089 DrawGameValue_Emeralds(local_player->gems_still_needed);
1090 DrawGameValue_Dynamite(local_player->inventory_size);
1091 DrawGameValue_Score(local_player->score);
1092 DrawGameValue_Time(TimeLeft);
1095 static void resolve_group_element(int group_element, int recursion_depth)
1097 static int group_nr;
1098 static struct ElementGroupInfo *group;
1099 struct ElementGroupInfo *actual_group = element_info[group_element].group;
1102 if (recursion_depth > NUM_GROUP_ELEMENTS) /* recursion too deep */
1104 Error(ERR_WARN, "recursion too deep when resolving group element %d",
1105 group_element - EL_GROUP_START + 1);
1107 /* replace element which caused too deep recursion by question mark */
1108 group->element_resolved[group->num_elements_resolved++] = EL_UNKNOWN;
1113 if (recursion_depth == 0) /* initialization */
1115 group = element_info[group_element].group;
1116 group_nr = group_element - EL_GROUP_START;
1118 group->num_elements_resolved = 0;
1119 group->choice_pos = 0;
1122 for (i = 0; i < actual_group->num_elements; i++)
1124 int element = actual_group->element[i];
1126 if (group->num_elements_resolved == NUM_FILE_ELEMENTS)
1129 if (IS_GROUP_ELEMENT(element))
1130 resolve_group_element(element, recursion_depth + 1);
1133 group->element_resolved[group->num_elements_resolved++] = element;
1134 element_info[element].in_group[group_nr] = TRUE;
1139 if (recursion_depth == 0 && group_element <= EL_GROUP_4)
1141 printf("::: group %d: %d resolved elements\n",
1142 group_element - EL_GROUP_START, group->num_elements_resolved);
1143 for (i = 0; i < group->num_elements_resolved; i++)
1144 printf("::: - %d ['%s']\n", group->element_resolved[i],
1145 element_info[group->element_resolved[i]].token_name);
1152 =============================================================================
1154 -----------------------------------------------------------------------------
1155 initialize game engine due to level / tape version number
1156 =============================================================================
1159 static void InitGameEngine()
1163 /* set game engine from tape file when re-playing, else from level file */
1164 game.engine_version = (tape.playing ? tape.engine_version :
1165 level.game_version);
1167 /* dynamically adjust element properties according to game engine version */
1168 InitElementPropertiesEngine(game.engine_version);
1171 printf("level %d: level version == %06d\n", level_nr, level.game_version);
1172 printf(" tape version == %06d [%s] [file: %06d]\n",
1173 tape.engine_version, (tape.playing ? "PLAYING" : "RECORDING"),
1175 printf(" => game.engine_version == %06d\n", game.engine_version);
1178 /* ---------- recursively resolve group elements ------------------------- */
1180 for (i = 0; i < MAX_NUM_ELEMENTS; i++)
1181 for (j = 0; j < NUM_GROUP_ELEMENTS; j++)
1182 element_info[i].in_group[j] = FALSE;
1184 for (i = 0; i < NUM_GROUP_ELEMENTS; i++)
1185 resolve_group_element(EL_GROUP_START + i, 0);
1187 /* ---------- initialize player's initial move delay --------------------- */
1189 /* dynamically adjust player properties according to game engine version */
1190 game.initial_move_delay =
1191 (game.engine_version <= VERSION_IDENT(2,0,1,0) ? INITIAL_MOVE_DELAY_ON :
1192 INITIAL_MOVE_DELAY_OFF);
1194 /* dynamically adjust player properties according to level information */
1195 game.initial_move_delay_value =
1196 (level.double_speed ? MOVE_DELAY_HIGH_SPEED : MOVE_DELAY_NORMAL_SPEED);
1198 /* ---------- initialize player's initial push delay --------------------- */
1200 /* dynamically adjust player properties according to game engine version */
1201 game.initial_push_delay_value =
1202 (game.engine_version < VERSION_IDENT(3,0,7,1) ? 5 : -1);
1204 /* ---------- initialize changing elements ------------------------------- */
1206 /* initialize changing elements information */
1207 for (i = 0; i < MAX_NUM_ELEMENTS; i++)
1209 struct ElementInfo *ei = &element_info[i];
1211 /* this pointer might have been changed in the level editor */
1212 ei->change = &ei->change_page[0];
1214 if (!IS_CUSTOM_ELEMENT(i))
1216 ei->change->target_element = EL_EMPTY_SPACE;
1217 ei->change->delay_fixed = 0;
1218 ei->change->delay_random = 0;
1219 ei->change->delay_frames = 1;
1222 ei->change_events = CE_BITMASK_DEFAULT;
1223 for (j = 0; j < NUM_CHANGE_EVENTS; j++)
1225 ei->event_page_nr[j] = 0;
1226 ei->event_page[j] = &ei->change_page[0];
1230 /* add changing elements from pre-defined list */
1231 for (i = 0; change_delay_list[i].element != EL_UNDEFINED; i++)
1233 struct ChangingElementInfo *ch_delay = &change_delay_list[i];
1234 struct ElementInfo *ei = &element_info[ch_delay->element];
1236 ei->change->target_element = ch_delay->target_element;
1237 ei->change->delay_fixed = ch_delay->change_delay;
1239 ei->change->pre_change_function = ch_delay->pre_change_function;
1240 ei->change->change_function = ch_delay->change_function;
1241 ei->change->post_change_function = ch_delay->post_change_function;
1243 ei->change_events |= CH_EVENT_BIT(CE_DELAY);
1246 SET_PROPERTY(ch_delay->element, EP_CAN_CHANGE, TRUE);
1251 /* add change events from custom element configuration */
1252 for (i = 0; i < NUM_CUSTOM_ELEMENTS; i++)
1254 struct ElementInfo *ei = &element_info[EL_CUSTOM_START + i];
1256 for (j = 0; j < ei->num_change_pages; j++)
1258 if (!ei->change_page[j].can_change)
1261 for (k = 0; k < NUM_CHANGE_EVENTS; k++)
1263 /* only add event page for the first page found with this event */
1264 if (ei->change_page[j].events & CH_EVENT_BIT(k) &&
1265 !(ei->change_events & CH_EVENT_BIT(k)))
1267 ei->change_events |= CH_EVENT_BIT(k);
1268 ei->event_page_nr[k] = j;
1269 ei->event_page[k] = &ei->change_page[j];
1277 /* add change events from custom element configuration */
1278 for (i = 0; i < NUM_CUSTOM_ELEMENTS; i++)
1280 int element = EL_CUSTOM_START + i;
1282 /* only add custom elements that change after fixed/random frame delay */
1283 if (CAN_CHANGE(element) && HAS_CHANGE_EVENT(element, CE_DELAY))
1284 element_info[element].change_events |= CH_EVENT_BIT(CE_DELAY);
1288 /* ---------- initialize run-time trigger player and element ------------- */
1290 for (i = 0; i < NUM_CUSTOM_ELEMENTS; i++)
1292 struct ElementInfo *ei = &element_info[EL_CUSTOM_START + i];
1294 for (j = 0; j < ei->num_change_pages; j++)
1296 ei->change_page[j].actual_trigger_element = EL_EMPTY;
1297 ei->change_page[j].actual_trigger_player = EL_PLAYER_1;
1301 /* ---------- initialize trigger events ---------------------------------- */
1303 /* initialize trigger events information */
1304 for (i = 0; i < MAX_NUM_ELEMENTS; i++)
1305 trigger_events[i] = EP_BITMASK_DEFAULT;
1308 /* add trigger events from element change event properties */
1309 for (i = 0; i < MAX_NUM_ELEMENTS; i++)
1311 struct ElementInfo *ei = &element_info[i];
1313 for (j = 0; j < ei->num_change_pages; j++)
1315 if (!ei->change_page[j].can_change)
1318 if (ei->change_page[j].events & CH_EVENT_BIT(CE_BY_OTHER_ACTION))
1320 int trigger_element = ei->change_page[j].trigger_element;
1322 if (IS_GROUP_ELEMENT(trigger_element))
1324 struct ElementGroupInfo *group = element_info[trigger_element].group;
1326 for (k = 0; k < group->num_elements_resolved; k++)
1327 trigger_events[group->element_resolved[k]]
1328 |= ei->change_page[j].events;
1331 trigger_events[trigger_element] |= ei->change_page[j].events;
1336 /* add trigger events from element change event properties */
1337 for (i = 0; i < MAX_NUM_ELEMENTS; i++)
1338 if (HAS_CHANGE_EVENT(i, CE_BY_OTHER_ACTION))
1339 trigger_events[element_info[i].change->trigger_element] |=
1340 element_info[i].change->events;
1343 /* ---------- initialize push delay -------------------------------------- */
1345 /* initialize push delay values to default */
1346 for (i = 0; i < MAX_NUM_ELEMENTS; i++)
1348 if (!IS_CUSTOM_ELEMENT(i))
1350 element_info[i].push_delay_fixed = game.default_push_delay_fixed;
1351 element_info[i].push_delay_random = game.default_push_delay_random;
1355 /* set push delay value for certain elements from pre-defined list */
1356 for (i = 0; push_delay_list[i].element != EL_UNDEFINED; i++)
1358 int e = push_delay_list[i].element;
1360 element_info[e].push_delay_fixed = push_delay_list[i].push_delay_fixed;
1361 element_info[e].push_delay_random = push_delay_list[i].push_delay_random;
1364 /* set push delay value for Supaplex elements for newer engine versions */
1365 if (game.engine_version >= VERSION_IDENT(3,1,0,0))
1367 for (i = 0; i < MAX_NUM_ELEMENTS; i++)
1369 if (IS_SP_ELEMENT(i))
1371 element_info[i].push_delay_fixed = 6; /* just enough to escape ... */
1372 element_info[i].push_delay_random = 0; /* ... from falling zonk */
1377 /* ---------- initialize move stepsize ----------------------------------- */
1379 /* initialize move stepsize values to default */
1380 for (i = 0; i < MAX_NUM_ELEMENTS; i++)
1381 if (!IS_CUSTOM_ELEMENT(i))
1382 element_info[i].move_stepsize = MOVE_STEPSIZE_NORMAL;
1384 /* set move stepsize value for certain elements from pre-defined list */
1385 for (i = 0; move_stepsize_list[i].element != EL_UNDEFINED; i++)
1387 int e = move_stepsize_list[i].element;
1389 element_info[e].move_stepsize = move_stepsize_list[i].move_stepsize;
1393 /* ---------- initialize move dig/leave ---------------------------------- */
1395 for (i = 0; i < MAX_NUM_ELEMENTS; i++)
1397 element_info[i].can_leave_element = FALSE;
1398 element_info[i].can_leave_element_last = FALSE;
1402 /* ---------- initialize gem count --------------------------------------- */
1404 /* initialize gem count values for each element */
1405 for (i = 0; i < MAX_NUM_ELEMENTS; i++)
1406 if (!IS_CUSTOM_ELEMENT(i))
1407 element_info[i].collect_count = 0;
1409 /* add gem count values for all elements from pre-defined list */
1410 for (i = 0; collect_count_list[i].element != EL_UNDEFINED; i++)
1411 element_info[collect_count_list[i].element].collect_count =
1412 collect_count_list[i].count;
1414 /* ---------- initialize access direction -------------------------------- */
1416 /* initialize access direction values to default (access from every side) */
1417 for (i = 0; i < MAX_NUM_ELEMENTS; i++)
1418 if (!IS_CUSTOM_ELEMENT(i))
1419 element_info[i].access_direction = MV_ALL_DIRECTIONS;
1421 /* set access direction value for certain elements from pre-defined list */
1422 for (i = 0; access_direction_list[i].element != EL_UNDEFINED; i++)
1423 element_info[access_direction_list[i].element].access_direction =
1424 access_direction_list[i].direction;
1429 =============================================================================
1431 -----------------------------------------------------------------------------
1432 initialize and start new game
1433 =============================================================================
1438 boolean emulate_bd = TRUE; /* unless non-BOULDERDASH elements found */
1439 boolean emulate_sb = TRUE; /* unless non-SOKOBAN elements found */
1440 boolean emulate_sp = TRUE; /* unless non-SUPAPLEX elements found */
1447 #if USE_NEW_AMOEBA_CODE
1448 printf("Using new amoeba code.\n");
1450 printf("Using old amoeba code.\n");
1455 /* don't play tapes over network */
1456 network_playing = (options.network && !tape.playing);
1458 for (i = 0; i < MAX_PLAYERS; i++)
1460 struct PlayerInfo *player = &stored_player[i];
1462 player->index_nr = i;
1463 player->index_bit = (1 << i);
1464 player->element_nr = EL_PLAYER_1 + i;
1466 player->present = FALSE;
1467 player->active = FALSE;
1470 player->effective_action = 0;
1471 player->programmed_action = 0;
1474 player->gems_still_needed = level.gems_needed;
1475 player->sokobanfields_still_needed = 0;
1476 player->lights_still_needed = 0;
1477 player->friends_still_needed = 0;
1479 for (j = 0; j < MAX_KEYS; j++)
1480 player->key[j] = FALSE;
1482 player->dynabomb_count = 0;
1483 player->dynabomb_size = 1;
1484 player->dynabombs_left = 0;
1485 player->dynabomb_xl = FALSE;
1487 player->MovDir = MV_NO_MOVING;
1490 player->GfxDir = MV_NO_MOVING;
1491 player->GfxAction = ACTION_DEFAULT;
1493 player->StepFrame = 0;
1495 player->use_murphy_graphic = FALSE;
1497 player->block_last_field = FALSE;
1498 player->can_fall_into_acid = CAN_MOVE_INTO_ACID(player->element_nr);
1500 player->actual_frame_counter = 0;
1502 player->step_counter = 0;
1504 player->last_move_dir = MV_NO_MOVING;
1506 player->is_waiting = FALSE;
1507 player->is_moving = FALSE;
1508 player->is_auto_moving = FALSE;
1509 player->is_digging = FALSE;
1510 player->is_snapping = FALSE;
1511 player->is_collecting = FALSE;
1512 player->is_pushing = FALSE;
1513 player->is_switching = FALSE;
1514 player->is_dropping = FALSE;
1516 player->is_bored = FALSE;
1517 player->is_sleeping = FALSE;
1519 player->frame_counter_bored = -1;
1520 player->frame_counter_sleeping = -1;
1522 player->anim_delay_counter = 0;
1523 player->post_delay_counter = 0;
1525 player->action_waiting = ACTION_DEFAULT;
1526 player->last_action_waiting = ACTION_DEFAULT;
1527 player->special_action_bored = ACTION_DEFAULT;
1528 player->special_action_sleeping = ACTION_DEFAULT;
1530 player->num_special_action_bored = 0;
1531 player->num_special_action_sleeping = 0;
1533 /* determine number of special actions for bored and sleeping animation */
1534 for (j = ACTION_BORING_1; j <= ACTION_BORING_LAST; j++)
1536 boolean found = FALSE;
1538 for (k = 0; k < NUM_DIRECTIONS; k++)
1539 if (el_act_dir2img(player->element_nr, j, k) !=
1540 el_act_dir2img(player->element_nr, ACTION_DEFAULT, k))
1544 player->num_special_action_bored++;
1548 for (j = ACTION_SLEEPING_1; j <= ACTION_SLEEPING_LAST; j++)
1550 boolean found = FALSE;
1552 for (k = 0; k < NUM_DIRECTIONS; k++)
1553 if (el_act_dir2img(player->element_nr, j, k) !=
1554 el_act_dir2img(player->element_nr, ACTION_DEFAULT, k))
1558 player->num_special_action_sleeping++;
1563 player->switch_x = -1;
1564 player->switch_y = -1;
1566 player->show_envelope = 0;
1568 player->move_delay = game.initial_move_delay;
1569 player->move_delay_value = game.initial_move_delay_value;
1571 player->move_delay_reset_counter = 0;
1573 player->push_delay = 0;
1574 player->push_delay_value = game.initial_push_delay_value;
1576 player->drop_delay = 0;
1578 player->last_jx = player->last_jy = 0;
1579 player->jx = player->jy = 0;
1581 player->shield_normal_time_left = 0;
1582 player->shield_deadly_time_left = 0;
1584 player->inventory_infinite_element = EL_UNDEFINED;
1585 player->inventory_size = 0;
1587 DigField(player, 0, 0, 0, 0, 0, 0, DF_NO_PUSH);
1588 SnapField(player, 0, 0);
1590 player->LevelSolved = FALSE;
1591 player->GameOver = FALSE;
1594 network_player_action_received = FALSE;
1596 #if defined(NETWORK_AVALIABLE)
1597 /* initial null action */
1598 if (network_playing)
1599 SendToServer_MovePlayer(MV_NO_MOVING);
1607 TimeLeft = level.time;
1610 ScreenMovDir = MV_NO_MOVING;
1614 ScrollStepSize = 0; /* will be correctly initialized by ScrollScreen() */
1616 AllPlayersGone = FALSE;
1618 game.yamyam_content_nr = 0;
1619 game.magic_wall_active = FALSE;
1620 game.magic_wall_time_left = 0;
1621 game.light_time_left = 0;
1622 game.timegate_time_left = 0;
1623 game.switchgate_pos = 0;
1624 game.balloon_dir = MV_NO_MOVING;
1625 game.gravity = level.initial_gravity;
1626 game.explosions_delayed = TRUE;
1628 game.envelope_active = FALSE;
1630 for (i = 0; i < NUM_BELTS; i++)
1632 game.belt_dir[i] = MV_NO_MOVING;
1633 game.belt_dir_nr[i] = 3; /* not moving, next moving left */
1636 for (i = 0; i < MAX_NUM_AMOEBA; i++)
1637 AmoebaCnt[i] = AmoebaCnt2[i] = 0;
1639 for (x = 0; x < lev_fieldx; x++)
1641 for (y = 0; y < lev_fieldy; y++)
1643 Feld[x][y] = level.field[x][y];
1644 MovPos[x][y] = MovDir[x][y] = MovDelay[x][y] = 0;
1645 ChangeDelay[x][y] = 0;
1646 ChangePage[x][y] = -1;
1647 Store[x][y] = Store2[x][y] = StorePlayer[x][y] = Back[x][y] = 0;
1649 WasJustMoving[x][y] = 0;
1650 WasJustFalling[x][y] = 0;
1651 CheckCollision[x][y] = 0;
1653 Pushed[x][y] = FALSE;
1655 Changed[x][y] = CE_BITMASK_DEFAULT;
1656 ChangeEvent[x][y] = CE_BITMASK_DEFAULT;
1658 ExplodePhase[x][y] = 0;
1659 ExplodeDelay[x][y] = 0;
1660 ExplodeField[x][y] = EX_TYPE_NONE;
1662 RunnerVisit[x][y] = 0;
1663 PlayerVisit[x][y] = 0;
1666 GfxRandom[x][y] = INIT_GFX_RANDOM();
1667 GfxElement[x][y] = EL_UNDEFINED;
1668 GfxAction[x][y] = ACTION_DEFAULT;
1669 GfxDir[x][y] = MV_NO_MOVING;
1673 for (y = 0; y < lev_fieldy; y++)
1675 for (x = 0; x < lev_fieldx; x++)
1677 if (emulate_bd && !IS_BD_ELEMENT(Feld[x][y]))
1679 if (emulate_sb && !IS_SB_ELEMENT(Feld[x][y]))
1681 if (emulate_sp && !IS_SP_ELEMENT(Feld[x][y]))
1684 InitField(x, y, TRUE);
1690 game.emulation = (emulate_bd ? EMU_BOULDERDASH :
1691 emulate_sb ? EMU_SOKOBAN :
1692 emulate_sp ? EMU_SUPAPLEX : EMU_NONE);
1694 /* initialize explosion and ignition delay */
1695 for (i = 0; i < MAX_NUM_ELEMENTS; i++)
1697 if (!IS_CUSTOM_ELEMENT(i))
1700 int delay = (((IS_SP_ELEMENT(i) && i != EL_EMPTY_SPACE) &&
1701 game.engine_version >= VERSION_IDENT(3,1,0,0)) ||
1702 game.emulation == EMU_SUPAPLEX ? 3 : 2);
1703 int last_phase = (num_phase + 1) * delay;
1704 int half_phase = (num_phase / 2) * delay;
1706 element_info[i].explosion_delay = last_phase - 1;
1707 element_info[i].ignition_delay = half_phase;
1710 if (i == EL_BLACK_ORB)
1711 element_info[i].ignition_delay = 0;
1713 if (i == EL_BLACK_ORB)
1714 element_info[i].ignition_delay = 1;
1719 if (element_info[i].explosion_delay < 1) /* !!! check again !!! */
1720 element_info[i].explosion_delay = 1;
1722 if (element_info[i].ignition_delay < 1) /* !!! check again !!! */
1723 element_info[i].ignition_delay = 1;
1727 /* correct non-moving belts to start moving left */
1728 for (i = 0; i < NUM_BELTS; i++)
1729 if (game.belt_dir[i] == MV_NO_MOVING)
1730 game.belt_dir_nr[i] = 3; /* not moving, next moving left */
1732 /* check if any connected player was not found in playfield */
1733 for (i = 0; i < MAX_PLAYERS; i++)
1735 struct PlayerInfo *player = &stored_player[i];
1737 if (player->connected && !player->present)
1739 for (j = 0; j < MAX_PLAYERS; j++)
1741 struct PlayerInfo *some_player = &stored_player[j];
1742 int jx = some_player->jx, jy = some_player->jy;
1744 /* assign first free player found that is present in the playfield */
1745 if (some_player->present && !some_player->connected)
1747 player->present = TRUE;
1748 player->active = TRUE;
1750 some_player->present = FALSE;
1751 some_player->active = FALSE;
1754 player->element_nr = some_player->element_nr;
1757 StorePlayer[jx][jy] = player->element_nr;
1758 player->jx = player->last_jx = jx;
1759 player->jy = player->last_jy = jy;
1769 /* when playing a tape, eliminate all players which do not participate */
1771 for (i = 0; i < MAX_PLAYERS; i++)
1773 if (stored_player[i].active && !tape.player_participates[i])
1775 struct PlayerInfo *player = &stored_player[i];
1776 int jx = player->jx, jy = player->jy;
1778 player->active = FALSE;
1779 StorePlayer[jx][jy] = 0;
1780 Feld[jx][jy] = EL_EMPTY;
1784 else if (!options.network && !setup.team_mode) /* && !tape.playing */
1786 /* when in single player mode, eliminate all but the first active player */
1788 for (i = 0; i < MAX_PLAYERS; i++)
1790 if (stored_player[i].active)
1792 for (j = i + 1; j < MAX_PLAYERS; j++)
1794 if (stored_player[j].active)
1796 struct PlayerInfo *player = &stored_player[j];
1797 int jx = player->jx, jy = player->jy;
1799 player->active = FALSE;
1800 player->present = FALSE;
1802 StorePlayer[jx][jy] = 0;
1803 Feld[jx][jy] = EL_EMPTY;
1810 /* when recording the game, store which players take part in the game */
1813 for (i = 0; i < MAX_PLAYERS; i++)
1814 if (stored_player[i].active)
1815 tape.player_participates[i] = TRUE;
1820 for (i = 0; i < MAX_PLAYERS; i++)
1822 struct PlayerInfo *player = &stored_player[i];
1824 printf("Player %d: present == %d, connected == %d, active == %d.\n",
1829 if (local_player == player)
1830 printf("Player %d is local player.\n", i+1);
1834 if (BorderElement == EL_EMPTY)
1837 SBX_Right = lev_fieldx - SCR_FIELDX;
1839 SBY_Lower = lev_fieldy - SCR_FIELDY;
1844 SBX_Right = lev_fieldx - SCR_FIELDX + 1;
1846 SBY_Lower = lev_fieldy - SCR_FIELDY + 1;
1849 if (lev_fieldx + (SBX_Left == -1 ? 2 : 0) <= SCR_FIELDX)
1850 SBX_Left = SBX_Right = -1 * (SCR_FIELDX - lev_fieldx) / 2;
1852 if (lev_fieldy + (SBY_Upper == -1 ? 2 : 0) <= SCR_FIELDY)
1853 SBY_Upper = SBY_Lower = -1 * (SCR_FIELDY - lev_fieldy) / 2;
1855 /* if local player not found, look for custom element that might create
1856 the player (make some assumptions about the right custom element) */
1857 if (!local_player->present)
1859 int start_x = 0, start_y = 0;
1860 int found_rating = 0;
1861 int found_element = EL_UNDEFINED;
1863 for (y = 0; y < lev_fieldy; y++) for (x = 0; x < lev_fieldx; x++)
1865 int element = Feld[x][y];
1870 if (!IS_CUSTOM_ELEMENT(element))
1873 if (CAN_CHANGE(element))
1875 for (i = 0; i < element_info[element].num_change_pages; i++)
1877 content = element_info[element].change_page[i].target_element;
1878 is_player = ELEM_IS_PLAYER(content);
1880 if (is_player && (found_rating < 3 || element < found_element))
1886 found_element = element;
1891 for (yy = 0; yy < 3; yy++) for (xx = 0; xx < 3; xx++)
1893 content = element_info[element].content[xx][yy];
1894 is_player = ELEM_IS_PLAYER(content);
1896 if (is_player && (found_rating < 2 || element < found_element))
1898 start_x = x + xx - 1;
1899 start_y = y + yy - 1;
1902 found_element = element;
1905 if (!CAN_CHANGE(element))
1908 for (i = 0; i < element_info[element].num_change_pages; i++)
1910 content= element_info[element].change_page[i].target_content[xx][yy];
1911 is_player = ELEM_IS_PLAYER(content);
1913 if (is_player && (found_rating < 1 || element < found_element))
1915 start_x = x + xx - 1;
1916 start_y = y + yy - 1;
1919 found_element = element;
1925 scroll_x = (start_x < SBX_Left + MIDPOSX ? SBX_Left :
1926 start_x > SBX_Right + MIDPOSX ? SBX_Right :
1929 scroll_y = (start_y < SBY_Upper + MIDPOSY ? SBY_Upper :
1930 start_y > SBY_Lower + MIDPOSY ? SBY_Lower :
1936 scroll_x = (local_player->jx < SBX_Left + MIDPOSX ? SBX_Left :
1937 local_player->jx > SBX_Right + MIDPOSX ? SBX_Right :
1938 local_player->jx - MIDPOSX);
1940 scroll_y = (local_player->jy < SBY_Upper + MIDPOSY ? SBY_Upper :
1941 local_player->jy > SBY_Lower + MIDPOSY ? SBY_Lower :
1942 local_player->jy - MIDPOSY);
1944 scroll_x = SBX_Left;
1945 scroll_y = SBY_Upper;
1946 if (local_player->jx >= SBX_Left + MIDPOSX)
1947 scroll_x = (local_player->jx <= SBX_Right + MIDPOSX ?
1948 local_player->jx - MIDPOSX :
1950 if (local_player->jy >= SBY_Upper + MIDPOSY)
1951 scroll_y = (local_player->jy <= SBY_Lower + MIDPOSY ?
1952 local_player->jy - MIDPOSY :
1957 CloseDoor(DOOR_CLOSE_1);
1962 /* after drawing the level, correct some elements */
1963 if (game.timegate_time_left == 0)
1964 CloseAllOpenTimegates();
1966 if (setup.soft_scrolling)
1967 BlitBitmap(fieldbuffer, backbuffer, FX, FY, SXSIZE, SYSIZE, SX, SY);
1969 redraw_mask |= REDRAW_FROM_BACKBUFFER;
1972 /* copy default game door content to main double buffer */
1973 BlitBitmap(graphic_info[IMG_GLOBAL_DOOR].bitmap, drawto,
1974 DOOR_GFX_PAGEX5, DOOR_GFX_PAGEY1, DXSIZE, DYSIZE, DX, DY);
1976 DrawGameDoorValues();
1980 game_gadget[SOUND_CTRL_ID_MUSIC]->checked = setup.sound_music;
1981 game_gadget[SOUND_CTRL_ID_LOOPS]->checked = setup.sound_loops;
1982 game_gadget[SOUND_CTRL_ID_SIMPLE]->checked = setup.sound_simple;
1986 /* copy actual game door content to door double buffer for OpenDoor() */
1987 BlitBitmap(drawto, bitmap_db_door,
1988 DX, DY, DXSIZE, DYSIZE, DOOR_GFX_PAGEX1, DOOR_GFX_PAGEY1);
1990 OpenDoor(DOOR_OPEN_ALL);
1992 PlaySoundStereo(SND_GAME_STARTING, SOUND_MIDDLE);
1994 if (setup.sound_music)
1997 KeyboardAutoRepeatOffUnlessAutoplay();
2001 for (i = 0; i < MAX_PLAYERS; i++)
2002 printf("Player %d %sactive.\n",
2003 i + 1, (stored_player[i].active ? "" : "not "));
2007 printf("::: starting game [%d]\n", FrameCounter);
2011 void InitMovDir(int x, int y)
2013 int i, element = Feld[x][y];
2014 static int xy[4][2] =
2021 static int direction[3][4] =
2023 { MV_RIGHT, MV_UP, MV_LEFT, MV_DOWN },
2024 { MV_LEFT, MV_DOWN, MV_RIGHT, MV_UP },
2025 { MV_LEFT, MV_RIGHT, MV_UP, MV_DOWN }
2034 Feld[x][y] = EL_BUG;
2035 MovDir[x][y] = direction[0][element - EL_BUG_RIGHT];
2038 case EL_SPACESHIP_RIGHT:
2039 case EL_SPACESHIP_UP:
2040 case EL_SPACESHIP_LEFT:
2041 case EL_SPACESHIP_DOWN:
2042 Feld[x][y] = EL_SPACESHIP;
2043 MovDir[x][y] = direction[0][element - EL_SPACESHIP_RIGHT];
2046 case EL_BD_BUTTERFLY_RIGHT:
2047 case EL_BD_BUTTERFLY_UP:
2048 case EL_BD_BUTTERFLY_LEFT:
2049 case EL_BD_BUTTERFLY_DOWN:
2050 Feld[x][y] = EL_BD_BUTTERFLY;
2051 MovDir[x][y] = direction[0][element - EL_BD_BUTTERFLY_RIGHT];
2054 case EL_BD_FIREFLY_RIGHT:
2055 case EL_BD_FIREFLY_UP:
2056 case EL_BD_FIREFLY_LEFT:
2057 case EL_BD_FIREFLY_DOWN:
2058 Feld[x][y] = EL_BD_FIREFLY;
2059 MovDir[x][y] = direction[0][element - EL_BD_FIREFLY_RIGHT];
2062 case EL_PACMAN_RIGHT:
2064 case EL_PACMAN_LEFT:
2065 case EL_PACMAN_DOWN:
2066 Feld[x][y] = EL_PACMAN;
2067 MovDir[x][y] = direction[0][element - EL_PACMAN_RIGHT];
2070 case EL_SP_SNIKSNAK:
2071 MovDir[x][y] = MV_UP;
2074 case EL_SP_ELECTRON:
2075 MovDir[x][y] = MV_LEFT;
2082 Feld[x][y] = EL_MOLE;
2083 MovDir[x][y] = direction[2][element - EL_MOLE_LEFT];
2087 if (IS_CUSTOM_ELEMENT(element))
2089 struct ElementInfo *ei = &element_info[element];
2090 int move_direction_initial = ei->move_direction_initial;
2091 int move_pattern = ei->move_pattern;
2093 if (move_direction_initial == MV_START_PREVIOUS)
2095 if (MovDir[x][y] != MV_NO_MOVING)
2098 move_direction_initial = MV_START_AUTOMATIC;
2101 if (move_direction_initial == MV_START_RANDOM)
2102 MovDir[x][y] = 1 << RND(4);
2103 else if (move_direction_initial & MV_ANY_DIRECTION)
2104 MovDir[x][y] = move_direction_initial;
2105 else if (move_pattern == MV_ALL_DIRECTIONS ||
2106 move_pattern == MV_TURNING_LEFT ||
2107 move_pattern == MV_TURNING_RIGHT ||
2108 move_pattern == MV_TURNING_LEFT_RIGHT ||
2109 move_pattern == MV_TURNING_RIGHT_LEFT ||
2110 move_pattern == MV_TURNING_RANDOM)
2111 MovDir[x][y] = 1 << RND(4);
2112 else if (move_pattern == MV_HORIZONTAL)
2113 MovDir[x][y] = (RND(2) ? MV_LEFT : MV_RIGHT);
2114 else if (move_pattern == MV_VERTICAL)
2115 MovDir[x][y] = (RND(2) ? MV_UP : MV_DOWN);
2116 else if (move_pattern & MV_ANY_DIRECTION)
2117 MovDir[x][y] = element_info[element].move_pattern;
2118 else if (move_pattern == MV_ALONG_LEFT_SIDE ||
2119 move_pattern == MV_ALONG_RIGHT_SIDE)
2122 /* use random direction as default start direction */
2123 if (game.engine_version >= VERSION_IDENT(3,1,0,0))
2124 MovDir[x][y] = 1 << RND(4);
2127 for (i = 0; i < NUM_DIRECTIONS; i++)
2129 int x1 = x + xy[i][0];
2130 int y1 = y + xy[i][1];
2132 if (!IN_LEV_FIELD(x1, y1) || !IS_FREE(x1, y1))
2134 if (move_pattern == MV_ALONG_RIGHT_SIDE)
2135 MovDir[x][y] = direction[0][i];
2137 MovDir[x][y] = direction[1][i];
2146 MovDir[x][y] = 1 << RND(4);
2148 if (element != EL_BUG &&
2149 element != EL_SPACESHIP &&
2150 element != EL_BD_BUTTERFLY &&
2151 element != EL_BD_FIREFLY)
2154 for (i = 0; i < NUM_DIRECTIONS; i++)
2156 int x1 = x + xy[i][0];
2157 int y1 = y + xy[i][1];
2159 if (!IN_LEV_FIELD(x1, y1) || !IS_FREE(x1, y1))
2161 if (element == EL_BUG || element == EL_BD_BUTTERFLY)
2163 MovDir[x][y] = direction[0][i];
2166 else if (element == EL_SPACESHIP || element == EL_BD_FIREFLY ||
2167 element == EL_SP_SNIKSNAK || element == EL_SP_ELECTRON)
2169 MovDir[x][y] = direction[1][i];
2178 GfxDir[x][y] = MovDir[x][y];
2181 void InitAmoebaNr(int x, int y)
2184 int group_nr = AmoebeNachbarNr(x, y);
2188 for (i = 1; i < MAX_NUM_AMOEBA; i++)
2190 if (AmoebaCnt[i] == 0)
2198 AmoebaNr[x][y] = group_nr;
2199 AmoebaCnt[group_nr]++;
2200 AmoebaCnt2[group_nr]++;
2206 boolean raise_level = FALSE;
2208 if (local_player->MovPos)
2212 if (tape.auto_play) /* tape might already be stopped here */
2213 tape.auto_play_level_solved = TRUE;
2215 if (tape.playing && tape.auto_play)
2216 tape.auto_play_level_solved = TRUE;
2219 local_player->LevelSolved = FALSE;
2221 PlaySoundStereo(SND_GAME_WINNING, SOUND_MIDDLE);
2225 if (!tape.playing && setup.sound_loops)
2226 PlaySoundExt(SND_GAME_LEVELTIME_BONUS, SOUND_MAX_VOLUME, SOUND_MIDDLE,
2227 SND_CTRL_PLAY_LOOP);
2229 while (TimeLeft > 0)
2231 if (!tape.playing && !setup.sound_loops)
2232 PlaySoundStereo(SND_GAME_LEVELTIME_BONUS, SOUND_MIDDLE);
2233 if (TimeLeft > 0 && !(TimeLeft % 10))
2234 RaiseScore(level.score[SC_TIME_BONUS]);
2235 if (TimeLeft > 100 && !(TimeLeft % 10))
2240 DrawGameValue_Time(TimeLeft);
2248 if (!tape.playing && setup.sound_loops)
2249 StopSound(SND_GAME_LEVELTIME_BONUS);
2251 else if (level.time == 0) /* level without time limit */
2253 if (!tape.playing && setup.sound_loops)
2254 PlaySoundExt(SND_GAME_LEVELTIME_BONUS, SOUND_MAX_VOLUME, SOUND_MIDDLE,
2255 SND_CTRL_PLAY_LOOP);
2257 while (TimePlayed < 999)
2259 if (!tape.playing && !setup.sound_loops)
2260 PlaySoundStereo(SND_GAME_LEVELTIME_BONUS, SOUND_MIDDLE);
2261 if (TimePlayed < 999 && !(TimePlayed % 10))
2262 RaiseScore(level.score[SC_TIME_BONUS]);
2263 if (TimePlayed < 900 && !(TimePlayed % 10))
2268 DrawGameValue_Time(TimePlayed);
2276 if (!tape.playing && setup.sound_loops)
2277 StopSound(SND_GAME_LEVELTIME_BONUS);
2280 /* close exit door after last player */
2281 if ((Feld[ExitX][ExitY] == EL_EXIT_OPEN ||
2282 Feld[ExitX][ExitY] == EL_SP_EXIT_OPEN) && AllPlayersGone)
2284 int element = Feld[ExitX][ExitY];
2286 Feld[ExitX][ExitY] = (element == EL_EXIT_OPEN ? EL_EXIT_CLOSING :
2287 EL_SP_EXIT_CLOSING);
2289 PlayLevelSoundElementAction(ExitX, ExitY, element, ACTION_CLOSING);
2292 /* Hero disappears */
2293 DrawLevelField(ExitX, ExitY);
2299 CloseDoor(DOOR_CLOSE_1);
2304 SaveTape(tape.level_nr); /* Ask to save tape */
2307 if (level_nr == leveldir_current->handicap_level)
2309 leveldir_current->handicap_level++;
2310 SaveLevelSetup_SeriesInfo();
2313 if (level_editor_test_game)
2314 local_player->score = -1; /* no highscore when playing from editor */
2315 else if (level_nr < leveldir_current->last_level)
2316 raise_level = TRUE; /* advance to next level */
2318 if ((hi_pos = NewHiScore()) >= 0)
2320 game_status = GAME_MODE_SCORES;
2321 DrawHallOfFame(hi_pos);
2330 game_status = GAME_MODE_MAIN;
2347 LoadScore(level_nr);
2349 if (strcmp(setup.player_name, EMPTY_PLAYER_NAME) == 0 ||
2350 local_player->score < highscore[MAX_SCORE_ENTRIES - 1].Score)
2353 for (k = 0; k < MAX_SCORE_ENTRIES; k++)
2355 if (local_player->score > highscore[k].Score)
2357 /* player has made it to the hall of fame */
2359 if (k < MAX_SCORE_ENTRIES - 1)
2361 int m = MAX_SCORE_ENTRIES - 1;
2364 for (l = k; l < MAX_SCORE_ENTRIES; l++)
2365 if (!strcmp(setup.player_name, highscore[l].Name))
2367 if (m == k) /* player's new highscore overwrites his old one */
2371 for (l = m; l > k; l--)
2373 strcpy(highscore[l].Name, highscore[l - 1].Name);
2374 highscore[l].Score = highscore[l - 1].Score;
2381 strncpy(highscore[k].Name, setup.player_name, MAX_PLAYER_NAME_LEN);
2382 highscore[k].Name[MAX_PLAYER_NAME_LEN] = '\0';
2383 highscore[k].Score = local_player->score;
2389 else if (!strncmp(setup.player_name, highscore[k].Name,
2390 MAX_PLAYER_NAME_LEN))
2391 break; /* player already there with a higher score */
2397 SaveScore(level_nr);
2402 void InitPlayerGfxAnimation(struct PlayerInfo *player, int action, int dir)
2404 if (player->GfxAction != action || player->GfxDir != dir)
2407 printf("Player frame reset! (%d => %d, %d => %d)\n",
2408 player->GfxAction, action, player->GfxDir, dir);
2411 player->GfxAction = action;
2412 player->GfxDir = dir;
2414 player->StepFrame = 0;
2418 static void ResetRandomAnimationValue(int x, int y)
2420 GfxRandom[x][y] = INIT_GFX_RANDOM();
2423 static void ResetGfxAnimation(int x, int y)
2426 GfxAction[x][y] = ACTION_DEFAULT;
2427 GfxDir[x][y] = MovDir[x][y];
2430 void InitMovingField(int x, int y, int direction)
2432 int element = Feld[x][y];
2433 int dx = (direction == MV_LEFT ? -1 : direction == MV_RIGHT ? +1 : 0);
2434 int dy = (direction == MV_UP ? -1 : direction == MV_DOWN ? +1 : 0);
2438 if (!WasJustMoving[x][y] || direction != MovDir[x][y])
2439 ResetGfxAnimation(x, y);
2441 MovDir[newx][newy] = MovDir[x][y] = direction;
2442 GfxDir[x][y] = direction;
2444 if (Feld[newx][newy] == EL_EMPTY)
2445 Feld[newx][newy] = EL_BLOCKED;
2447 if (direction == MV_DOWN && CAN_FALL(element))
2448 GfxAction[x][y] = ACTION_FALLING;
2450 GfxAction[x][y] = ACTION_MOVING;
2452 GfxFrame[newx][newy] = GfxFrame[x][y];
2453 GfxRandom[newx][newy] = GfxRandom[x][y];
2454 GfxAction[newx][newy] = GfxAction[x][y];
2455 GfxDir[newx][newy] = GfxDir[x][y];
2458 void Moving2Blocked(int x, int y, int *goes_to_x, int *goes_to_y)
2460 int direction = MovDir[x][y];
2461 int newx = x + (direction == MV_LEFT ? -1 : direction == MV_RIGHT ? +1 : 0);
2462 int newy = y + (direction == MV_UP ? -1 : direction == MV_DOWN ? +1 : 0);
2468 void Blocked2Moving(int x, int y, int *comes_from_x, int *comes_from_y)
2470 int oldx = x, oldy = y;
2471 int direction = MovDir[x][y];
2473 if (direction == MV_LEFT)
2475 else if (direction == MV_RIGHT)
2477 else if (direction == MV_UP)
2479 else if (direction == MV_DOWN)
2482 *comes_from_x = oldx;
2483 *comes_from_y = oldy;
2486 int MovingOrBlocked2Element(int x, int y)
2488 int element = Feld[x][y];
2490 if (element == EL_BLOCKED)
2494 Blocked2Moving(x, y, &oldx, &oldy);
2495 return Feld[oldx][oldy];
2501 static int MovingOrBlocked2ElementIfNotLeaving(int x, int y)
2503 /* like MovingOrBlocked2Element(), but if element is moving
2504 and (x,y) is the field the moving element is just leaving,
2505 return EL_BLOCKED instead of the element value */
2506 int element = Feld[x][y];
2508 if (IS_MOVING(x, y))
2510 if (element == EL_BLOCKED)
2514 Blocked2Moving(x, y, &oldx, &oldy);
2515 return Feld[oldx][oldy];
2524 static void RemoveField(int x, int y)
2526 Feld[x][y] = EL_EMPTY;
2533 ChangeDelay[x][y] = 0;
2534 ChangePage[x][y] = -1;
2535 Pushed[x][y] = FALSE;
2538 ExplodeField[x][y] = EX_TYPE_NONE;
2541 GfxElement[x][y] = EL_UNDEFINED;
2542 GfxAction[x][y] = ACTION_DEFAULT;
2543 GfxDir[x][y] = MV_NO_MOVING;
2546 void RemoveMovingField(int x, int y)
2548 int oldx = x, oldy = y, newx = x, newy = y;
2549 int element = Feld[x][y];
2550 int next_element = EL_UNDEFINED;
2552 if (element != EL_BLOCKED && !IS_MOVING(x, y))
2555 if (IS_MOVING(x, y))
2557 Moving2Blocked(x, y, &newx, &newy);
2559 if (Feld[newx][newy] != EL_BLOCKED)
2562 if (Feld[newx][newy] != EL_BLOCKED)
2564 /* element is moving, but target field is not free (blocked), but
2565 already occupied by something different (example: acid pool);
2566 in this case, only remove the moving field, but not the target */
2568 RemoveField(oldx, oldy);
2570 Store[oldx][oldy] = Store2[oldx][oldy] = 0;
2572 DrawLevelField(oldx, oldy);
2578 else if (element == EL_BLOCKED)
2580 Blocked2Moving(x, y, &oldx, &oldy);
2581 if (!IS_MOVING(oldx, oldy))
2585 if (element == EL_BLOCKED &&
2586 (Feld[oldx][oldy] == EL_QUICKSAND_EMPTYING ||
2587 Feld[oldx][oldy] == EL_MAGIC_WALL_EMPTYING ||
2588 Feld[oldx][oldy] == EL_BD_MAGIC_WALL_EMPTYING ||
2589 Feld[oldx][oldy] == EL_AMOEBA_DROPPING))
2590 next_element = get_next_element(Feld[oldx][oldy]);
2592 RemoveField(oldx, oldy);
2593 RemoveField(newx, newy);
2595 Store[oldx][oldy] = Store2[oldx][oldy] = 0;
2597 if (next_element != EL_UNDEFINED)
2598 Feld[oldx][oldy] = next_element;
2600 DrawLevelField(oldx, oldy);
2601 DrawLevelField(newx, newy);
2604 void DrawDynamite(int x, int y)
2606 int sx = SCREENX(x), sy = SCREENY(y);
2607 int graphic = el2img(Feld[x][y]);
2610 if (!IN_SCR_FIELD(sx, sy) || IS_PLAYER(x, y))
2613 if (IS_WALKABLE_INSIDE(Back[x][y]))
2617 DrawGraphic(sx, sy, el2img(Back[x][y]), 0);
2618 else if (Store[x][y])
2619 DrawGraphic(sx, sy, el2img(Store[x][y]), 0);
2621 frame = getGraphicAnimationFrame(graphic, GfxFrame[x][y]);
2624 if (Back[x][y] || Store[x][y])
2625 DrawGraphicThruMask(sx, sy, graphic, frame);
2627 DrawGraphic(sx, sy, graphic, frame);
2629 if (game.emulation == EMU_SUPAPLEX)
2630 DrawGraphic(sx, sy, IMG_SP_DISK_RED, frame);
2631 else if (Store[x][y])
2632 DrawGraphicThruMask(sx, sy, graphic, frame);
2634 DrawGraphic(sx, sy, graphic, frame);
2638 void CheckDynamite(int x, int y)
2640 if (MovDelay[x][y] != 0) /* dynamite is still waiting to explode */
2644 if (MovDelay[x][y] != 0)
2647 PlayLevelSoundActionIfLoop(x, y, ACTION_ACTIVE);
2654 StopLevelSoundActionIfLoop(x, y, ACTION_ACTIVE);
2656 if (Feld[x][y] == EL_DYNAMITE_ACTIVE ||
2657 Feld[x][y] == EL_SP_DISK_RED_ACTIVE)
2658 StopSound(SND_DYNAMITE_ACTIVE);
2660 StopSound(SND_DYNABOMB_ACTIVE);
2666 void DrawRelocatePlayer(struct PlayerInfo *player)
2668 boolean ffwd_delay = (tape.playing && tape.fast_forward);
2669 boolean no_delay = (tape.warp_forward);
2670 int frame_delay_value = (ffwd_delay ? FfwdFrameDelay : GameFrameDelay);
2671 int wait_delay_value = (no_delay ? 0 : frame_delay_value);
2672 int jx = player->jx;
2673 int jy = player->jy;
2675 if (level.instant_relocation)
2678 int offset = (setup.scroll_delay ? 3 : 0);
2680 if (!IN_VIS_FIELD(SCREENX(jx), SCREENY(jy)))
2682 scroll_x = (local_player->jx < SBX_Left + MIDPOSX ? SBX_Left :
2683 local_player->jx > SBX_Right + MIDPOSX ? SBX_Right :
2684 local_player->jx - MIDPOSX);
2686 scroll_y = (local_player->jy < SBY_Upper + MIDPOSY ? SBY_Upper :
2687 local_player->jy > SBY_Lower + MIDPOSY ? SBY_Lower :
2688 local_player->jy - MIDPOSY);
2692 if ((player->MovDir == MV_LEFT && scroll_x > jx - MIDPOSX + offset) ||
2693 (player->MovDir == MV_RIGHT && scroll_x < jx - MIDPOSX - offset))
2694 scroll_x = jx - MIDPOSX + (scroll_x < jx-MIDPOSX ? -offset : +offset);
2696 if ((player->MovDir == MV_UP && scroll_y > jy - MIDPOSY + offset) ||
2697 (player->MovDir == MV_DOWN && scroll_y < jy - MIDPOSY - offset))
2698 scroll_y = jy - MIDPOSY + (scroll_y < jy-MIDPOSY ? -offset : +offset);
2700 /* don't scroll over playfield boundaries */
2701 if (scroll_x < SBX_Left || scroll_x > SBX_Right)
2702 scroll_x = (scroll_x < SBX_Left ? SBX_Left : SBX_Right);
2704 /* don't scroll over playfield boundaries */
2705 if (scroll_y < SBY_Upper || scroll_y > SBY_Lower)
2706 scroll_y = (scroll_y < SBY_Upper ? SBY_Upper : SBY_Lower);
2709 scroll_x += (local_player->jx - old_jx);
2710 scroll_y += (local_player->jy - old_jy);
2712 /* don't scroll over playfield boundaries */
2713 if (scroll_x < SBX_Left || scroll_x > SBX_Right)
2714 scroll_x = (scroll_x < SBX_Left ? SBX_Left : SBX_Right);
2716 /* don't scroll over playfield boundaries */
2717 if (scroll_y < SBY_Upper || scroll_y > SBY_Lower)
2718 scroll_y = (scroll_y < SBY_Upper ? SBY_Upper : SBY_Lower);
2721 RedrawPlayfield(TRUE, 0,0,0,0);
2727 int offset = (setup.scroll_delay ? 3 : 0);
2729 int scroll_xx = -999, scroll_yy = -999;
2731 ScrollScreen(NULL, SCROLL_GO_ON); /* scroll last frame to full tile */
2733 while (scroll_xx != scroll_x || scroll_yy != scroll_y)
2736 int fx = FX, fy = FY;
2738 scroll_xx = (local_player->jx < SBX_Left + MIDPOSX ? SBX_Left :
2739 local_player->jx > SBX_Right + MIDPOSX ? SBX_Right :
2740 local_player->jx - MIDPOSX);
2742 scroll_yy = (local_player->jy < SBY_Upper + MIDPOSY ? SBY_Upper :
2743 local_player->jy > SBY_Lower + MIDPOSY ? SBY_Lower :
2744 local_player->jy - MIDPOSY);
2746 dx = (scroll_xx < scroll_x ? +1 : scroll_xx > scroll_x ? -1 : 0);
2747 dy = (scroll_yy < scroll_y ? +1 : scroll_yy > scroll_y ? -1 : 0);
2750 if (dx == 0 && dy == 0) /* no scrolling needed at all */
2753 if (scroll_xx == scroll_x && scroll_yy == scroll_y)
2760 fx += dx * TILEX / 2;
2761 fy += dy * TILEY / 2;
2763 ScrollLevel(dx, dy);
2766 /* scroll in two steps of half tile size to make things smoother */
2767 BlitBitmap(drawto_field, window, fx, fy, SXSIZE, SYSIZE, SX, SY);
2769 Delay(wait_delay_value);
2771 /* scroll second step to align at full tile size */
2773 Delay(wait_delay_value);
2776 int scroll_xx = -999, scroll_yy = -999;
2778 ScrollScreen(NULL, SCROLL_GO_ON); /* scroll last frame to full tile */
2780 while (scroll_xx != scroll_x || scroll_yy != scroll_y)
2783 int fx = FX, fy = FY;
2785 scroll_xx = (local_player->jx < SBX_Left + MIDPOSX ? SBX_Left :
2786 local_player->jx > SBX_Right + MIDPOSX ? SBX_Right :
2787 local_player->jx - MIDPOSX);
2789 scroll_yy = (local_player->jy < SBY_Upper + MIDPOSY ? SBY_Upper :
2790 local_player->jy > SBY_Lower + MIDPOSY ? SBY_Lower :
2791 local_player->jy - MIDPOSY);
2793 dx = (scroll_xx < scroll_x ? +1 : scroll_xx > scroll_x ? -1 : 0);
2794 dy = (scroll_yy < scroll_y ? +1 : scroll_yy > scroll_y ? -1 : 0);
2797 if (dx == 0 && dy == 0) /* no scrolling needed at all */
2800 if (scroll_xx == scroll_x && scroll_yy == scroll_y)
2807 fx += dx * TILEX / 2;
2808 fy += dy * TILEY / 2;
2810 ScrollLevel(dx, dy);
2813 /* scroll in two steps of half tile size to make things smoother */
2814 BlitBitmap(drawto_field, window, fx, fy, SXSIZE, SYSIZE, SX, SY);
2816 Delay(wait_delay_value);
2818 /* scroll second step to align at full tile size */
2820 Delay(wait_delay_value);
2826 Delay(wait_delay_value);
2830 void RelocatePlayer(int jx, int jy, int el_player_raw)
2833 int el_player = GET_VALID_PLAYER_ELEMENT(el_player_raw);
2835 int el_player = (el_player_raw == EL_SP_MURPHY ? EL_PLAYER_1 :el_player_raw);
2837 struct PlayerInfo *player = &stored_player[el_player - EL_PLAYER_1];
2838 boolean ffwd_delay = (tape.playing && tape.fast_forward);
2839 boolean no_delay = (tape.warp_forward);
2840 int frame_delay_value = (ffwd_delay ? FfwdFrameDelay : GameFrameDelay);
2841 int wait_delay_value = (no_delay ? 0 : frame_delay_value);
2842 int old_jx = player->jx;
2843 int old_jy = player->jy;
2844 int old_element = Feld[old_jx][old_jy];
2845 int element = Feld[jx][jy];
2846 boolean player_relocated = (old_jx != jx || old_jy != jy);
2848 int move_dir_horiz = (jx < old_jx ? MV_LEFT : jx > old_jx ? MV_RIGHT : 0);
2849 int move_dir_vert = (jy < old_jy ? MV_UP : jy > old_jy ? MV_DOWN : 0);
2851 int enter_side_horiz = MV_DIR_OPPOSITE(move_dir_horiz);
2852 int enter_side_vert = MV_DIR_OPPOSITE(move_dir_vert);
2853 int leave_side_horiz = move_dir_horiz;
2854 int leave_side_vert = move_dir_vert;
2856 static int trigger_sides[4][2] =
2858 /* enter side leave side */
2859 { CH_SIDE_RIGHT, CH_SIDE_LEFT }, /* moving left */
2860 { CH_SIDE_LEFT, CH_SIDE_RIGHT }, /* moving right */
2861 { CH_SIDE_BOTTOM, CH_SIDE_TOP }, /* moving up */
2862 { CH_SIDE_TOP, CH_SIDE_BOTTOM } /* moving down */
2864 int enter_side_horiz = trigger_sides[MV_DIR_BIT(move_dir_horiz)][0];
2865 int enter_side_vert = trigger_sides[MV_DIR_BIT(move_dir_vert)][0];
2866 int leave_side_horiz = trigger_sides[MV_DIR_BIT(move_dir_horiz)][1];
2867 int leave_side_vert = trigger_sides[MV_DIR_BIT(move_dir_vert)][1];
2869 int enter_side = enter_side_horiz | enter_side_vert;
2870 int leave_side = leave_side_horiz | leave_side_vert;
2872 if (player->GameOver) /* do not reanimate dead player */
2875 if (!player_relocated) /* no need to relocate the player */
2878 if (IS_PLAYER(jx, jy)) /* player already placed at new position */
2880 RemoveField(jx, jy); /* temporarily remove newly placed player */
2881 DrawLevelField(jx, jy);
2884 if (player->present)
2886 while (player->MovPos)
2888 ScrollPlayer(player, SCROLL_GO_ON);
2889 ScrollScreen(NULL, SCROLL_GO_ON);
2895 Delay(wait_delay_value);
2898 DrawPlayer(player); /* needed here only to cleanup last field */
2899 DrawLevelField(player->jx, player->jy); /* remove player graphic */
2901 player->is_moving = FALSE;
2905 if (IS_CUSTOM_ELEMENT(old_element))
2906 CheckElementChangeByPlayer(old_jx, old_jy, old_element,
2908 player->index_bit, leave_side);
2910 CheckTriggeredElementChangeByPlayer(old_jx, old_jy, old_element,
2912 player->index_bit, leave_side);
2915 Feld[jx][jy] = el_player;
2916 InitPlayerField(jx, jy, el_player, TRUE);
2918 if (!ELEM_IS_PLAYER(element)) /* player may be set on walkable element */
2920 Feld[jx][jy] = element;
2921 InitField(jx, jy, FALSE);
2925 if (player == local_player) /* only visually relocate local player */
2926 DrawRelocatePlayer(player);
2930 TestIfHeroTouchesBadThing(jx, jy);
2931 TestIfPlayerTouchesCustomElement(jx, jy);
2935 printf("::: %d,%d: %d\n", jx, jy-1, Changed[jx][jy-1]);
2940 /* needed to allow change of walkable custom element by entering player */
2941 if (!(Changed[jx][jy] & CH_EVENT_BIT(CE_ENTERED_BY_PLAYER)))
2942 Changed[jx][jy] = 0; /* allow another change (but prevent loop) */
2944 /* needed to allow change of walkable custom element by entering player */
2945 Changed[jx][jy] = 0; /* allow another change */
2950 printf("::: player entering %d, %d from %s ...\n", jx, jy,
2951 enter_side == MV_LEFT ? "left" :
2952 enter_side == MV_RIGHT ? "right" :
2953 enter_side == MV_UP ? "top" :
2954 enter_side == MV_DOWN ? "bottom" : "oops! no idea!");
2958 if (IS_CUSTOM_ELEMENT(element))
2959 CheckElementChangeByPlayer(jx, jy, element, CE_ENTERED_BY_PLAYER,
2960 player->index_bit, enter_side);
2962 CheckTriggeredElementChangeByPlayer(jx, jy, element,
2963 CE_OTHER_GETS_ENTERED,
2964 player->index_bit, enter_side);
2968 void Explode(int ex, int ey, int phase, int mode)
2975 /* !!! eliminate this variable !!! */
2976 int delay = (game.emulation == EMU_SUPAPLEX ? 3 : 2);
2981 int last_phase = num_phase * delay;
2982 int half_phase = (num_phase / 2) * delay;
2983 int first_phase_after_start = EX_PHASE_START + 1;
2987 if (game.explosions_delayed)
2989 ExplodeField[ex][ey] = mode;
2993 if (phase == EX_PHASE_START) /* initialize 'Store[][]' field */
2995 int center_element = Feld[ex][ey];
2998 printf("::: start explosion %d,%d [%d]\n", ex, ey, FrameCounter);
3002 /* --- This is only really needed (and now handled) in "Impact()". --- */
3003 /* do not explode moving elements that left the explode field in time */
3004 if (game.engine_version >= VERSION_IDENT(2,2,0,7) &&
3005 center_element == EL_EMPTY &&
3006 (mode == EX_TYPE_NORMAL || mode == EX_TYPE_CENTER))
3010 if (mode == EX_TYPE_NORMAL || mode == EX_TYPE_CENTER)
3011 PlayLevelSoundAction(ex, ey, ACTION_EXPLODING);
3013 /* remove things displayed in background while burning dynamite */
3014 if (Back[ex][ey] != EL_EMPTY && !IS_INDESTRUCTIBLE(Back[ex][ey]))
3017 if (IS_MOVING(ex, ey) || IS_BLOCKED(ex, ey))
3019 /* put moving element to center field (and let it explode there) */
3020 center_element = MovingOrBlocked2Element(ex, ey);
3021 RemoveMovingField(ex, ey);
3022 Feld[ex][ey] = center_element;
3028 last_phase = element_info[center_element].explosion_delay + 1;
3030 last_phase = element_info[center_element].explosion_delay;
3034 printf("::: %d -> %d\n", center_element, last_phase);
3038 for (y = ey - 1; y <= ey + 1; y++) for (x = ex - 1; x <= ex + 1; x++)
3040 int xx = x - ex + 1;
3041 int yy = y - ey + 1;
3046 if (!IN_LEV_FIELD(x, y) ||
3047 (mode & EX_TYPE_SINGLE_TILE && (x != ex || y != ey)) ||
3048 (mode == EX_TYPE_CROSS && (x != ex && y != ey)))
3051 if (!IN_LEV_FIELD(x, y) ||
3052 (mode != EX_TYPE_NORMAL && (x != ex || y != ey)))
3056 if (!IN_LEV_FIELD(x, y) ||
3057 ((mode != EX_TYPE_NORMAL ||
3058 center_element == EL_AMOEBA_TO_DIAMOND) &&
3059 (x != ex || y != ey)))
3063 element = Feld[x][y];
3065 if (IS_MOVING(x, y) || IS_BLOCKED(x, y))
3067 element = MovingOrBlocked2Element(x, y);
3069 if (!IS_EXPLOSION_PROOF(element))
3070 RemoveMovingField(x, y);
3076 if (IS_EXPLOSION_PROOF(element))
3079 /* indestructible elements can only explode in center (but not flames) */
3081 if ((IS_EXPLOSION_PROOF(element) && (x != ex || y != ey ||
3082 mode == EX_TYPE_BORDER)) ||
3083 element == EL_FLAMES)
3086 if ((IS_EXPLOSION_PROOF(element) && (x != ex || y != ey)) ||
3087 element == EL_FLAMES)
3093 if ((IS_INDESTRUCTIBLE(element) &&
3094 (game.engine_version < VERSION_IDENT(2,2,0,0) ||
3095 (!IS_WALKABLE_OVER(element) && !IS_WALKABLE_UNDER(element)))) ||
3096 element == EL_FLAMES)
3101 if (IS_PLAYER(x, y) && SHIELD_ON(PLAYERINFO(x, y)) &&
3102 (game.engine_version < VERSION_IDENT(3,1,0,0) ||
3103 (x == ex && y == ey && mode != EX_TYPE_BORDER)))
3105 if (IS_PLAYER(x, y) && SHIELD_ON(PLAYERINFO(x, y)))
3108 if (IS_ACTIVE_BOMB(element))
3110 /* re-activate things under the bomb like gate or penguin */
3112 Feld[x][y] = (Back[x][y] ? Back[x][y] : EL_EMPTY);
3115 Feld[x][y] = (Store[x][y] ? Store[x][y] : EL_EMPTY);
3120 printf("::: %d,%d: %d %s [%d, %d]\n", x, y, Feld[x][y],
3121 element_info[Feld[x][y]].token_name,
3122 Store[x][y], Store2[x][y]);
3129 /* save walkable background elements while explosion on same tile */
3131 if (IS_INDESTRUCTIBLE(element))
3132 Back[x][y] = element;
3136 if (IS_WALKABLE(element) && IS_INDESTRUCTIBLE(element) &&
3137 (x != ex || y != ey || mode == EX_TYPE_BORDER))
3138 Back[x][y] = element;
3140 if (IS_WALKABLE(element) && IS_INDESTRUCTIBLE(element) &&
3141 (x != ex || y != ey))
3142 Back[x][y] = element;
3145 if (IS_WALKABLE(element) && IS_INDESTRUCTIBLE(element))
3146 Back[x][y] = element;
3150 /* ignite explodable elements reached by other explosion */
3151 if (element == EL_EXPLOSION)
3152 element = Store2[x][y];
3155 if (AmoebaNr[x][y] &&
3156 (element == EL_AMOEBA_FULL ||
3157 element == EL_BD_AMOEBA ||
3158 element == EL_AMOEBA_GROWING))
3160 AmoebaCnt[AmoebaNr[x][y]]--;
3161 AmoebaCnt2[AmoebaNr[x][y]]--;
3167 if (IS_PLAYER(ex, ey) && !PLAYER_EXPLOSION_PROTECTED(ex, ey))
3169 switch(StorePlayer[ex][ey])
3172 Store[x][y] = EL_PLAYER_IS_EXPLODING_2;
3175 Store[x][y] = EL_PLAYER_IS_EXPLODING_3;
3178 Store[x][y] = EL_PLAYER_IS_EXPLODING_4;
3182 Store[x][y] = EL_PLAYER_IS_EXPLODING_1;
3187 if (PLAYERINFO(ex, ey)->use_murphy_graphic)
3188 Store[x][y] = EL_EMPTY;
3190 if (game.emulation == EMU_SUPAPLEX)
3191 Store[x][y] = EL_EMPTY;
3194 else if (center_element == EL_MOLE)
3195 Store[x][y] = EL_EMERALD_RED;
3196 else if (center_element == EL_PENGUIN)
3197 Store[x][y] = EL_EMERALD_PURPLE;
3198 else if (center_element == EL_BUG)
3199 Store[x][y] = ((x == ex && y == ey) ? EL_DIAMOND : EL_EMERALD);
3200 else if (center_element == EL_BD_BUTTERFLY)
3201 Store[x][y] = EL_BD_DIAMOND;
3202 else if (center_element == EL_SP_ELECTRON)
3203 Store[x][y] = EL_SP_INFOTRON;
3204 else if (center_element == EL_AMOEBA_TO_DIAMOND)
3205 Store[x][y] = level.amoeba_content;
3206 else if (center_element == EL_YAMYAM)
3207 Store[x][y] = level.yamyam_content[game.yamyam_content_nr][xx][yy];
3208 else if (IS_CUSTOM_ELEMENT(center_element) &&
3209 element_info[center_element].content[xx][yy] != EL_EMPTY)
3210 Store[x][y] = element_info[center_element].content[xx][yy];
3211 else if (element == EL_WALL_EMERALD)
3212 Store[x][y] = EL_EMERALD;
3213 else if (element == EL_WALL_DIAMOND)
3214 Store[x][y] = EL_DIAMOND;
3215 else if (element == EL_WALL_BD_DIAMOND)
3216 Store[x][y] = EL_BD_DIAMOND;
3217 else if (element == EL_WALL_EMERALD_YELLOW)
3218 Store[x][y] = EL_EMERALD_YELLOW;
3219 else if (element == EL_WALL_EMERALD_RED)
3220 Store[x][y] = EL_EMERALD_RED;
3221 else if (element == EL_WALL_EMERALD_PURPLE)
3222 Store[x][y] = EL_EMERALD_PURPLE;
3223 else if (element == EL_WALL_PEARL)
3224 Store[x][y] = EL_PEARL;
3225 else if (element == EL_WALL_CRYSTAL)
3226 Store[x][y] = EL_CRYSTAL;
3227 else if (IS_CUSTOM_ELEMENT(element) && !CAN_EXPLODE(element))
3228 Store[x][y] = element_info[element].content[1][1];
3230 Store[x][y] = EL_EMPTY;
3232 if (x != ex || y != ey || mode == EX_TYPE_BORDER ||
3233 center_element == EL_AMOEBA_TO_DIAMOND)
3234 Store2[x][y] = element;
3237 printf("::: %d,%d: %d %s\n", x, y, Store2[x][y],
3238 element_info[Store2[x][y]].token_name);
3242 if (AmoebaNr[x][y] &&
3243 (element == EL_AMOEBA_FULL ||
3244 element == EL_BD_AMOEBA ||
3245 element == EL_AMOEBA_GROWING))
3247 AmoebaCnt[AmoebaNr[x][y]]--;
3248 AmoebaCnt2[AmoebaNr[x][y]]--;
3254 MovDir[x][y] = MovPos[x][y] = 0;
3255 GfxDir[x][y] = MovDir[x][y];
3260 Feld[x][y] = EL_EXPLOSION;
3262 GfxElement[x][y] = center_element;
3264 GfxElement[x][y] = EL_UNDEFINED;
3267 ExplodePhase[x][y] = 1;
3269 ExplodeDelay[x][y] = last_phase;
3274 GfxFrame[x][y] = 0; /* animation does not start until next frame */
3276 GfxFrame[x][y] = -1; /* animation does not start until next frame */
3283 if (center_element == EL_YAMYAM)
3284 game.yamyam_content_nr =
3285 (game.yamyam_content_nr + 1) % level.num_yamyam_contents;
3288 printf("::: %d,%d: %d %s [%d]\n", ex + 1, ey, Feld[ex + 1][ey],
3289 element_info[Feld[ex + 1][ey]].token_name, Store2[ex + 1][ey]);
3303 GfxFrame[x][y] = 0; /* restart explosion animation */
3307 printf(":X: phase == %d [%d]\n", phase, GfxFrame[x][y]);
3311 last_phase = ExplodeDelay[x][y];
3314 ExplodePhase[x][y] = (phase < last_phase ? phase + 1 : 0);
3318 /* activate this even in non-DEBUG version until cause for crash in
3319 getGraphicAnimationFrame() (see below) is found and eliminated */
3323 if (GfxElement[x][y] == EL_UNDEFINED)
3326 printf("Explode(): x = %d, y = %d: GfxElement == EL_UNDEFINED\n", x, y);
3327 printf("Explode(): This should never happen!\n");
3330 GfxElement[x][y] = EL_EMPTY;
3336 border_element = Store2[x][y];
3338 if (IS_PLAYER(x, y) && !PLAYER_EXPLOSION_PROTECTED(x, y))
3339 border_element = StorePlayer[x][y];
3341 if (IS_PLAYER(x, y))
3342 border_element = StorePlayer[x][y];
3346 printf("::: %d,%d: %d %s [%d]\n", x, y, border_element,
3347 element_info[border_element].token_name, Store2[x][y]);
3351 printf("::: phase == %d\n", phase);
3354 if (phase == element_info[border_element].ignition_delay ||
3355 phase == last_phase)
3357 boolean border_explosion = FALSE;
3361 if (IS_PLAYER(x, y) && PLAYERINFO(x, y)->present &&
3362 !PLAYER_EXPLOSION_PROTECTED(x, y))
3364 if (IS_PLAYER(x, y) && PLAYERINFO(x, y)->present)
3367 if (IS_PLAYER(x, y))
3370 KillHeroUnlessExplosionProtected(x, y);
3371 border_explosion = TRUE;
3374 if (phase == last_phase)
3375 printf("::: IS_PLAYER\n");
3378 else if (CAN_EXPLODE_BY_EXPLOSION(border_element))
3381 printf("::: %d,%d: %d %s\n", x, y, border_element,
3382 element_info[border_element].token_name);
3385 Feld[x][y] = Store2[x][y];
3388 border_explosion = TRUE;
3391 if (phase == last_phase)
3392 printf("::: CAN_EXPLODE_BY_EXPLOSION\n");
3395 else if (border_element == EL_AMOEBA_TO_DIAMOND)
3397 AmoebeUmwandeln(x, y);
3399 border_explosion = TRUE;
3402 if (phase == last_phase)
3403 printf("::: EL_AMOEBA_TO_DIAMOND [%d, %d] [%d]\n",
3404 element_info[border_element].explosion_delay,
3405 element_info[border_element].ignition_delay,
3411 /* if an element just explodes due to another explosion (chain-reaction),
3412 do not immediately end the new explosion when it was the last frame of
3413 the explosion (as it would be done in the following "if"-statement!) */
3414 if (border_explosion && phase == last_phase)
3421 if (phase == first_phase_after_start)
3423 int element = Store2[x][y];
3425 if (element == EL_BLACK_ORB)
3427 Feld[x][y] = Store2[x][y];
3432 else if (phase == half_phase)
3434 int element = Store2[x][y];
3436 if (IS_PLAYER(x, y))
3437 KillHeroUnlessExplosionProtected(x, y);
3438 else if (CAN_EXPLODE_BY_EXPLOSION(element))
3440 Feld[x][y] = Store2[x][y];
3444 else if (element == EL_AMOEBA_TO_DIAMOND)
3445 AmoebeUmwandeln(x, y);
3449 if (phase == last_phase)
3454 printf("::: done: phase == %d\n", phase);
3458 printf("::: explosion %d,%d done [%d]\n", x, y, FrameCounter);
3461 element = Feld[x][y] = Store[x][y];
3462 Store[x][y] = Store2[x][y] = 0;
3463 GfxElement[x][y] = EL_UNDEFINED;
3465 /* player can escape from explosions and might therefore be still alive */
3466 if (element >= EL_PLAYER_IS_EXPLODING_1 &&
3467 element <= EL_PLAYER_IS_EXPLODING_4)
3468 Feld[x][y] = (stored_player[element - EL_PLAYER_IS_EXPLODING_1].active ?
3470 element == EL_PLAYER_IS_EXPLODING_1 ? EL_EMERALD_YELLOW :
3471 element == EL_PLAYER_IS_EXPLODING_2 ? EL_EMERALD_RED :
3472 element == EL_PLAYER_IS_EXPLODING_3 ? EL_EMERALD :
3475 /* restore probably existing indestructible background element */
3476 if (Back[x][y] && IS_INDESTRUCTIBLE(Back[x][y]))
3477 element = Feld[x][y] = Back[x][y];
3480 MovDir[x][y] = MovPos[x][y] = MovDelay[x][y] = 0;
3481 GfxDir[x][y] = MV_NO_MOVING;
3482 ChangeDelay[x][y] = 0;
3483 ChangePage[x][y] = -1;
3486 InitField_WithBug2(x, y, FALSE);
3488 InitField(x, y, FALSE);
3490 /* !!! not needed !!! */
3492 if (game.engine_version < VERSION_IDENT(3,1,0,0) &&
3493 CAN_MOVE(Feld[x][y]) && Feld[x][y] != EL_MOLE)
3496 if (CAN_MOVE(element))
3501 DrawLevelField(x, y);
3503 TestIfElementTouchesCustomElement(x, y);
3505 if (GFX_CRUMBLED(element))
3506 DrawLevelFieldCrumbledSandNeighbours(x, y);
3508 if (IS_PLAYER(x, y) && !PLAYERINFO(x, y)->present)
3509 StorePlayer[x][y] = 0;
3511 if (ELEM_IS_PLAYER(element))
3512 RelocatePlayer(x, y, element);
3515 else if (IN_SCR_FIELD(SCREENX(x), SCREENY(y)))
3517 else if (phase >= delay && IN_SCR_FIELD(SCREENX(x), SCREENY(y)))
3521 int graphic = el_act2img(GfxElement[x][y], ACTION_EXPLODING);
3523 int stored = Store[x][y];
3524 int graphic = (game.emulation != EMU_SUPAPLEX ? IMG_EXPLOSION :
3525 stored == EL_SP_INFOTRON ? IMG_SP_EXPLOSION_INFOTRON :
3529 int frame = getGraphicAnimationFrame(graphic, GfxFrame[x][y]);
3531 int frame = getGraphicAnimationFrame(graphic, phase - delay);
3535 printf("::: phase == %d [%d]\n", phase, GfxFrame[x][y]);
3539 printf("::: %d / %d [%d - %d]\n",
3540 GfxFrame[x][y], phase - delay, phase, delay);
3544 printf("::: %d ['%s'] -> %d\n", GfxElement[x][y],
3545 element_info[GfxElement[x][y]].token_name,
3550 DrawLevelFieldCrumbledSand(x, y);
3552 if (IS_WALKABLE_OVER(Back[x][y]) && Back[x][y] != EL_EMPTY)
3554 DrawLevelElement(x, y, Back[x][y]);
3555 DrawGraphicThruMask(SCREENX(x), SCREENY(y), graphic, frame);
3557 else if (IS_WALKABLE_UNDER(Back[x][y]))
3559 DrawGraphic(SCREENX(x), SCREENY(y), graphic, frame);
3560 DrawLevelElementThruMask(x, y, Back[x][y]);
3562 else if (!IS_WALKABLE_INSIDE(Back[x][y]))
3563 DrawGraphic(SCREENX(x), SCREENY(y), graphic, frame);
3567 void DynaExplode(int ex, int ey)
3570 int dynabomb_element = Feld[ex][ey];
3571 int dynabomb_size = 1;
3572 boolean dynabomb_xl = FALSE;
3573 struct PlayerInfo *player;
3574 static int xy[4][2] =
3582 if (IS_ACTIVE_BOMB(dynabomb_element))
3584 player = &stored_player[dynabomb_element - EL_DYNABOMB_PLAYER_1_ACTIVE];
3585 dynabomb_size = player->dynabomb_size;
3586 dynabomb_xl = player->dynabomb_xl;
3587 player->dynabombs_left++;
3590 Explode(ex, ey, EX_PHASE_START, EX_TYPE_CENTER);
3592 for (i = 0; i < NUM_DIRECTIONS; i++)
3594 for (j = 1; j <= dynabomb_size; j++)
3596 int x = ex + j * xy[i][0];
3597 int y = ey + j * xy[i][1];
3600 if (!IN_LEV_FIELD(x, y) || IS_INDESTRUCTIBLE(Feld[x][y]))
3603 element = Feld[x][y];
3605 /* do not restart explosions of fields with active bombs */
3606 if (element == EL_EXPLOSION && IS_ACTIVE_BOMB(Store2[x][y]))
3609 Explode(x, y, EX_PHASE_START, EX_TYPE_BORDER);
3613 if (element != EL_EMPTY && element != EL_EXPLOSION &&
3614 !IS_DIGGABLE(element) && !dynabomb_xl)
3617 if (element != EL_EMPTY && element != EL_EXPLOSION &&
3618 !CAN_GROW_INTO(element) && !dynabomb_xl)
3622 /* !!! extend EL_SAND to anything diggable (but maybe not SP_BASE) !!! */
3623 if (element != EL_EMPTY && element != EL_EXPLOSION &&
3624 element != EL_SAND && !dynabomb_xl)
3631 void Bang(int x, int y)
3634 int element = MovingOrBlocked2Element(x, y);
3636 int element = Feld[x][y];
3640 if (IS_PLAYER(x, y) && !PLAYER_EXPLOSION_PROTECTED(x, y))
3642 if (IS_PLAYER(x, y))
3645 struct PlayerInfo *player = PLAYERINFO(x, y);
3647 element = Feld[x][y] = (player->use_murphy_graphic ? EL_SP_MURPHY :
3648 player->element_nr);
3653 PlayLevelSoundAction(x, y, ACTION_EXPLODING);
3655 if (game.emulation == EMU_SUPAPLEX)
3656 PlayLevelSound(x, y, SND_SP_ELEMENT_EXPLODING);
3658 PlayLevelSound(x, y, SND_ELEMENT_EXPLODING);
3663 if (IS_PLAYER(x, y)) /* remove objects that might cause smaller explosion */
3671 case EL_BD_BUTTERFLY:
3674 case EL_DARK_YAMYAM:
3678 RaiseScoreElement(element);
3679 Explode(x, y, EX_PHASE_START, EX_TYPE_NORMAL);
3681 case EL_DYNABOMB_PLAYER_1_ACTIVE:
3682 case EL_DYNABOMB_PLAYER_2_ACTIVE:
3683 case EL_DYNABOMB_PLAYER_3_ACTIVE:
3684 case EL_DYNABOMB_PLAYER_4_ACTIVE:
3685 case EL_DYNABOMB_INCREASE_NUMBER:
3686 case EL_DYNABOMB_INCREASE_SIZE:
3687 case EL_DYNABOMB_INCREASE_POWER:
3692 case EL_LAMP_ACTIVE:
3694 case EL_AMOEBA_TO_DIAMOND:
3696 if (IS_PLAYER(x, y))
3697 Explode(x, y, EX_PHASE_START, EX_TYPE_NORMAL);
3699 Explode(x, y, EX_PHASE_START, EX_TYPE_CENTER);
3703 if (element_info[element].explosion_type == EXPLODES_CROSS)
3705 if (CAN_EXPLODE_CROSS(element))
3708 Explode(x, y, EX_PHASE_START, EX_TYPE_CROSS);
3713 else if (element_info[element].explosion_type == EXPLODES_1X1)
3715 else if (CAN_EXPLODE_1X1(element))
3717 Explode(x, y, EX_PHASE_START, EX_TYPE_CENTER);
3719 Explode(x, y, EX_PHASE_START, EX_TYPE_NORMAL);
3723 CheckTriggeredElementChange(x, y, element, CE_OTHER_IS_EXPLODING);
3726 void SplashAcid(int x, int y)
3729 if (IN_LEV_FIELD(x - 1, y - 1) && IS_FREE(x - 1, y - 1) &&
3730 (!IN_LEV_FIELD(x - 1, y - 2) ||
3731 !CAN_FALL(MovingOrBlocked2Element(x - 1, y - 2))))
3732 Feld[x - 1][y - 1] = EL_ACID_SPLASH_LEFT;
3734 if (IN_LEV_FIELD(x + 1, y - 1) && IS_FREE(x + 1, y - 1) &&
3735 (!IN_LEV_FIELD(x + 1, y - 2) ||
3736 !CAN_FALL(MovingOrBlocked2Element(x + 1, y - 2))))
3737 Feld[x + 1][y - 1] = EL_ACID_SPLASH_RIGHT;
3739 PlayLevelSound(x, y, SND_ACID_SPLASHING);
3741 /* input: position of element entering acid (obsolete) */
3743 int element = Feld[x][y];
3745 if (!IN_LEV_FIELD(x, y + 1) || Feld[x][y + 1] != EL_ACID)
3748 if (element != EL_ACID_SPLASH_LEFT &&
3749 element != EL_ACID_SPLASH_RIGHT)
3751 PlayLevelSound(x, y, SND_ACID_SPLASHING);
3753 if (IN_LEV_FIELD(x - 1, y) && IS_FREE(x - 1, y) &&
3754 (!IN_LEV_FIELD(x - 1, y - 1) ||
3755 !CAN_FALL(MovingOrBlocked2Element(x - 1, y - 1))))
3756 Feld[x - 1][y] = EL_ACID_SPLASH_LEFT;
3758 if (IN_LEV_FIELD(x + 1, y) && IS_FREE(x + 1, y) &&
3759 (!IN_LEV_FIELD(x + 1, y - 1) ||
3760 !CAN_FALL(MovingOrBlocked2Element(x + 1, y - 1))))
3761 Feld[x + 1][y] = EL_ACID_SPLASH_RIGHT;
3766 static void InitBeltMovement()
3768 static int belt_base_element[4] =
3770 EL_CONVEYOR_BELT_1_LEFT,
3771 EL_CONVEYOR_BELT_2_LEFT,
3772 EL_CONVEYOR_BELT_3_LEFT,
3773 EL_CONVEYOR_BELT_4_LEFT
3775 static int belt_base_active_element[4] =
3777 EL_CONVEYOR_BELT_1_LEFT_ACTIVE,
3778 EL_CONVEYOR_BELT_2_LEFT_ACTIVE,
3779 EL_CONVEYOR_BELT_3_LEFT_ACTIVE,
3780 EL_CONVEYOR_BELT_4_LEFT_ACTIVE
3785 /* set frame order for belt animation graphic according to belt direction */
3786 for (i = 0; i < NUM_BELTS; i++)
3790 for (j = 0; j < NUM_BELT_PARTS; j++)
3792 int element = belt_base_active_element[belt_nr] + j;
3793 int graphic = el2img(element);
3795 if (game.belt_dir[i] == MV_LEFT)
3796 graphic_info[graphic].anim_mode &= ~ANIM_REVERSE;
3798 graphic_info[graphic].anim_mode |= ANIM_REVERSE;
3802 for (y = 0; y < lev_fieldy; y++)
3804 for (x = 0; x < lev_fieldx; x++)
3806 int element = Feld[x][y];
3808 for (i = 0; i < NUM_BELTS; i++)
3810 if (IS_BELT(element) && game.belt_dir[i] != MV_NO_MOVING)
3812 int e_belt_nr = getBeltNrFromBeltElement(element);
3815 if (e_belt_nr == belt_nr)
3817 int belt_part = Feld[x][y] - belt_base_element[belt_nr];
3819 Feld[x][y] = belt_base_active_element[belt_nr] + belt_part;
3827 static void ToggleBeltSwitch(int x, int y)
3829 static int belt_base_element[4] =
3831 EL_CONVEYOR_BELT_1_LEFT,
3832 EL_CONVEYOR_BELT_2_LEFT,
3833 EL_CONVEYOR_BELT_3_LEFT,
3834 EL_CONVEYOR_BELT_4_LEFT
3836 static int belt_base_active_element[4] =
3838 EL_CONVEYOR_BELT_1_LEFT_ACTIVE,
3839 EL_CONVEYOR_BELT_2_LEFT_ACTIVE,
3840 EL_CONVEYOR_BELT_3_LEFT_ACTIVE,
3841 EL_CONVEYOR_BELT_4_LEFT_ACTIVE
3843 static int belt_base_switch_element[4] =
3845 EL_CONVEYOR_BELT_1_SWITCH_LEFT,
3846 EL_CONVEYOR_BELT_2_SWITCH_LEFT,
3847 EL_CONVEYOR_BELT_3_SWITCH_LEFT,
3848 EL_CONVEYOR_BELT_4_SWITCH_LEFT
3850 static int belt_move_dir[4] =
3858 int element = Feld[x][y];
3859 int belt_nr = getBeltNrFromBeltSwitchElement(element);
3860 int belt_dir_nr = (game.belt_dir_nr[belt_nr] + 1) % 4;
3861 int belt_dir = belt_move_dir[belt_dir_nr];
3864 if (!IS_BELT_SWITCH(element))
3867 game.belt_dir_nr[belt_nr] = belt_dir_nr;
3868 game.belt_dir[belt_nr] = belt_dir;
3870 if (belt_dir_nr == 3)
3873 /* set frame order for belt animation graphic according to belt direction */
3874 for (i = 0; i < NUM_BELT_PARTS; i++)
3876 int element = belt_base_active_element[belt_nr] + i;
3877 int graphic = el2img(element);
3879 if (belt_dir == MV_LEFT)
3880 graphic_info[graphic].anim_mode &= ~ANIM_REVERSE;
3882 graphic_info[graphic].anim_mode |= ANIM_REVERSE;
3885 for (yy = 0; yy < lev_fieldy; yy++)
3887 for (xx = 0; xx < lev_fieldx; xx++)
3889 int element = Feld[xx][yy];
3891 if (IS_BELT_SWITCH(element))
3893 int e_belt_nr = getBeltNrFromBeltSwitchElement(element);
3895 if (e_belt_nr == belt_nr)
3897 Feld[xx][yy] = belt_base_switch_element[belt_nr] + belt_dir_nr;
3898 DrawLevelField(xx, yy);
3901 else if (IS_BELT(element) && belt_dir != MV_NO_MOVING)
3903 int e_belt_nr = getBeltNrFromBeltElement(element);
3905 if (e_belt_nr == belt_nr)
3907 int belt_part = Feld[xx][yy] - belt_base_element[belt_nr];
3909 Feld[xx][yy] = belt_base_active_element[belt_nr] + belt_part;
3910 DrawLevelField(xx, yy);
3913 else if (IS_BELT_ACTIVE(element) && belt_dir == MV_NO_MOVING)
3915 int e_belt_nr = getBeltNrFromBeltActiveElement(element);
3917 if (e_belt_nr == belt_nr)
3919 int belt_part = Feld[xx][yy] - belt_base_active_element[belt_nr];
3921 Feld[xx][yy] = belt_base_element[belt_nr] + belt_part;
3922 DrawLevelField(xx, yy);
3929 static void ToggleSwitchgateSwitch(int x, int y)
3933 game.switchgate_pos = !game.switchgate_pos;
3935 for (yy = 0; yy < lev_fieldy; yy++)
3937 for (xx = 0; xx < lev_fieldx; xx++)
3939 int element = Feld[xx][yy];
3941 if (element == EL_SWITCHGATE_SWITCH_UP ||
3942 element == EL_SWITCHGATE_SWITCH_DOWN)
3944 Feld[xx][yy] = EL_SWITCHGATE_SWITCH_UP + game.switchgate_pos;
3945 DrawLevelField(xx, yy);
3947 else if (element == EL_SWITCHGATE_OPEN ||
3948 element == EL_SWITCHGATE_OPENING)
3950 Feld[xx][yy] = EL_SWITCHGATE_CLOSING;
3952 PlayLevelSoundAction(xx, yy, ACTION_CLOSING);
3954 PlayLevelSound(xx, yy, SND_SWITCHGATE_CLOSING);
3957 else if (element == EL_SWITCHGATE_CLOSED ||
3958 element == EL_SWITCHGATE_CLOSING)
3960 Feld[xx][yy] = EL_SWITCHGATE_OPENING;
3962 PlayLevelSoundAction(xx, yy, ACTION_OPENING);
3964 PlayLevelSound(xx, yy, SND_SWITCHGATE_OPENING);
3971 static int getInvisibleActiveFromInvisibleElement(int element)
3973 return (element == EL_INVISIBLE_STEELWALL ? EL_INVISIBLE_STEELWALL_ACTIVE :
3974 element == EL_INVISIBLE_WALL ? EL_INVISIBLE_WALL_ACTIVE :
3975 element == EL_INVISIBLE_SAND ? EL_INVISIBLE_SAND_ACTIVE :
3979 static int getInvisibleFromInvisibleActiveElement(int element)
3981 return (element == EL_INVISIBLE_STEELWALL_ACTIVE ? EL_INVISIBLE_STEELWALL :
3982 element == EL_INVISIBLE_WALL_ACTIVE ? EL_INVISIBLE_WALL :
3983 element == EL_INVISIBLE_SAND_ACTIVE ? EL_INVISIBLE_SAND :
3987 static void RedrawAllLightSwitchesAndInvisibleElements()
3991 for (y = 0; y < lev_fieldy; y++)
3993 for (x = 0; x < lev_fieldx; x++)
3995 int element = Feld[x][y];
3997 if (element == EL_LIGHT_SWITCH &&
3998 game.light_time_left > 0)
4000 Feld[x][y] = EL_LIGHT_SWITCH_ACTIVE;
4001 DrawLevelField(x, y);
4003 else if (element == EL_LIGHT_SWITCH_ACTIVE &&
4004 game.light_time_left == 0)
4006 Feld[x][y] = EL_LIGHT_SWITCH;
4007 DrawLevelField(x, y);
4009 else if (element == EL_INVISIBLE_STEELWALL ||
4010 element == EL_INVISIBLE_WALL ||
4011 element == EL_INVISIBLE_SAND)
4013 if (game.light_time_left > 0)
4014 Feld[x][y] = getInvisibleActiveFromInvisibleElement(element);
4016 DrawLevelField(x, y);
4018 else if (element == EL_INVISIBLE_STEELWALL_ACTIVE ||
4019 element == EL_INVISIBLE_WALL_ACTIVE ||
4020 element == EL_INVISIBLE_SAND_ACTIVE)
4022 if (game.light_time_left == 0)
4023 Feld[x][y] = getInvisibleFromInvisibleActiveElement(element);
4025 DrawLevelField(x, y);
4031 static void ToggleLightSwitch(int x, int y)
4033 int element = Feld[x][y];
4035 game.light_time_left =
4036 (element == EL_LIGHT_SWITCH ?
4037 level.time_light * FRAMES_PER_SECOND : 0);
4039 RedrawAllLightSwitchesAndInvisibleElements();
4042 static void ActivateTimegateSwitch(int x, int y)
4046 game.timegate_time_left = level.time_timegate * FRAMES_PER_SECOND;
4048 for (yy = 0; yy < lev_fieldy; yy++)
4050 for (xx = 0; xx < lev_fieldx; xx++)
4052 int element = Feld[xx][yy];
4054 if (element == EL_TIMEGATE_CLOSED ||
4055 element == EL_TIMEGATE_CLOSING)
4057 Feld[xx][yy] = EL_TIMEGATE_OPENING;
4058 PlayLevelSound(xx, yy, SND_TIMEGATE_OPENING);
4062 else if (element == EL_TIMEGATE_SWITCH_ACTIVE)
4064 Feld[xx][yy] = EL_TIMEGATE_SWITCH;
4065 DrawLevelField(xx, yy);
4072 Feld[x][y] = EL_TIMEGATE_SWITCH_ACTIVE;
4075 inline static int getElementMoveStepsize(int x, int y)
4077 int element = Feld[x][y];
4078 int direction = MovDir[x][y];
4079 int dx = (direction == MV_LEFT ? -1 : direction == MV_RIGHT ? +1 : 0);
4080 int dy = (direction == MV_UP ? -1 : direction == MV_DOWN ? +1 : 0);
4081 int horiz_move = (dx != 0);
4082 int sign = (horiz_move ? dx : dy);
4083 int step = sign * element_info[element].move_stepsize;
4085 /* special values for move stepsize for spring and things on conveyor belt */
4089 if (element == EL_SPRING)
4090 step = sign * MOVE_STEPSIZE_NORMAL * 2;
4091 else if (CAN_FALL(element) && !CAN_MOVE(element) &&
4092 y < lev_fieldy - 1 && IS_BELT_ACTIVE(Feld[x][y + 1]))
4093 step = sign * MOVE_STEPSIZE_NORMAL / 2;
4095 if (CAN_FALL(element) &&
4096 y < lev_fieldy - 1 && IS_BELT_ACTIVE(Feld[x][y + 1]))
4097 step = sign * MOVE_STEPSIZE_NORMAL / 2;
4098 else if (element == EL_SPRING)
4099 step = sign * MOVE_STEPSIZE_NORMAL * 2;
4106 void Impact(int x, int y)
4108 boolean lastline = (y == lev_fieldy-1);
4109 boolean object_hit = FALSE;
4110 boolean impact = (lastline || object_hit);
4111 int element = Feld[x][y];
4112 int smashed = EL_STEELWALL;
4114 if (!lastline) /* check if element below was hit */
4116 if (Feld[x][y + 1] == EL_PLAYER_IS_LEAVING)
4119 object_hit = (!IS_FREE(x, y + 1) && (!IS_MOVING(x, y + 1) ||
4120 MovDir[x][y + 1] != MV_DOWN ||
4121 MovPos[x][y + 1] <= TILEY / 2));
4124 object_hit = !IS_FREE(x, y + 1);
4127 /* do not smash moving elements that left the smashed field in time */
4128 if (game.engine_version >= VERSION_IDENT(2,2,0,7) && IS_MOVING(x, y + 1) &&
4129 ABS(MovPos[x][y + 1] + getElementMoveStepsize(x, y + 1)) >= TILEX)
4133 smashed = MovingOrBlocked2Element(x, y + 1);
4135 impact = (lastline || object_hit);
4138 if (!lastline && smashed == EL_ACID) /* element falls into acid */
4140 SplashAcid(x, y + 1);
4144 /* !!! not sufficient for all cases -- see EL_PEARL below !!! */
4145 /* only reset graphic animation if graphic really changes after impact */
4147 el_act_dir2img(element, GfxAction[x][y], MV_DOWN) != el2img(element))
4149 ResetGfxAnimation(x, y);
4150 DrawLevelField(x, y);
4153 if (impact && CAN_EXPLODE_IMPACT(element))
4158 else if (impact && element == EL_PEARL)
4160 ResetGfxAnimation(x, y);
4162 Feld[x][y] = EL_PEARL_BREAKING;
4163 PlayLevelSound(x, y, SND_PEARL_BREAKING);
4166 else if (impact && CheckElementChange(x, y, element, smashed, CE_IMPACT))
4168 PlayLevelSoundElementAction(x, y, element, ACTION_IMPACT);
4173 if (impact && element == EL_AMOEBA_DROP)
4175 if (object_hit && IS_PLAYER(x, y + 1))
4176 KillHeroUnlessEnemyProtected(x, y + 1);
4177 else if (object_hit && smashed == EL_PENGUIN)
4181 Feld[x][y] = EL_AMOEBA_GROWING;
4182 Store[x][y] = EL_AMOEBA_WET;
4184 ResetRandomAnimationValue(x, y);
4189 if (object_hit) /* check which object was hit */
4191 if (CAN_PASS_MAGIC_WALL(element) &&
4192 (smashed == EL_MAGIC_WALL ||
4193 smashed == EL_BD_MAGIC_WALL))
4196 int activated_magic_wall =
4197 (smashed == EL_MAGIC_WALL ? EL_MAGIC_WALL_ACTIVE :
4198 EL_BD_MAGIC_WALL_ACTIVE);
4200 /* activate magic wall / mill */
4201 for (yy = 0; yy < lev_fieldy; yy++)
4202 for (xx = 0; xx < lev_fieldx; xx++)
4203 if (Feld[xx][yy] == smashed)
4204 Feld[xx][yy] = activated_magic_wall;
4206 game.magic_wall_time_left = level.time_magic_wall * FRAMES_PER_SECOND;
4207 game.magic_wall_active = TRUE;
4209 PlayLevelSound(x, y, (smashed == EL_MAGIC_WALL ?
4210 SND_MAGIC_WALL_ACTIVATING :
4211 SND_BD_MAGIC_WALL_ACTIVATING));
4214 if (IS_PLAYER(x, y + 1))
4216 if (CAN_SMASH_PLAYER(element))
4218 KillHeroUnlessEnemyProtected(x, y + 1);
4222 else if (smashed == EL_PENGUIN)
4224 if (CAN_SMASH_PLAYER(element))
4230 else if (element == EL_BD_DIAMOND)
4232 if (IS_CLASSIC_ENEMY(smashed) && IS_BD_ELEMENT(smashed))
4238 else if (((element == EL_SP_INFOTRON ||
4239 element == EL_SP_ZONK) &&
4240 (smashed == EL_SP_SNIKSNAK ||
4241 smashed == EL_SP_ELECTRON ||
4242 smashed == EL_SP_DISK_ORANGE)) ||
4243 (element == EL_SP_INFOTRON &&
4244 smashed == EL_SP_DISK_YELLOW))
4250 else if (CAN_SMASH_ENEMIES(element) && IS_CLASSIC_ENEMY(smashed))
4256 else if (CAN_SMASH_EVERYTHING(element))
4258 if (IS_CLASSIC_ENEMY(smashed) ||
4259 CAN_EXPLODE_SMASHED(smashed))
4264 else if (!IS_MOVING(x, y + 1) && !IS_BLOCKED(x, y + 1))
4266 if (smashed == EL_LAMP ||
4267 smashed == EL_LAMP_ACTIVE)
4272 else if (smashed == EL_NUT)
4274 Feld[x][y + 1] = EL_NUT_BREAKING;
4275 PlayLevelSound(x, y, SND_NUT_BREAKING);
4276 RaiseScoreElement(EL_NUT);
4279 else if (smashed == EL_PEARL)
4281 ResetGfxAnimation(x, y);
4283 Feld[x][y + 1] = EL_PEARL_BREAKING;
4284 PlayLevelSound(x, y, SND_PEARL_BREAKING);
4287 else if (smashed == EL_DIAMOND)
4289 Feld[x][y + 1] = EL_DIAMOND_BREAKING;
4290 PlayLevelSound(x, y, SND_DIAMOND_BREAKING);
4293 else if (IS_BELT_SWITCH(smashed))
4295 ToggleBeltSwitch(x, y + 1);
4297 else if (smashed == EL_SWITCHGATE_SWITCH_UP ||
4298 smashed == EL_SWITCHGATE_SWITCH_DOWN)
4300 ToggleSwitchgateSwitch(x, y + 1);
4302 else if (smashed == EL_LIGHT_SWITCH ||
4303 smashed == EL_LIGHT_SWITCH_ACTIVE)
4305 ToggleLightSwitch(x, y + 1);
4310 TestIfElementSmashesCustomElement(x, y, MV_DOWN);
4313 CheckElementChange(x, y + 1, smashed, element, CE_SMASHED);
4316 /* !!! TEST ONLY !!! */
4317 CheckElementChangeBySide(x, y + 1, smashed, element,
4318 CE_SWITCHED, CH_SIDE_TOP);
4319 CheckTriggeredElementChangeBySide(x, y + 1, smashed,
4320 CE_OTHER_IS_SWITCHING,CH_SIDE_TOP);
4322 CheckTriggeredElementChangeBySide(x, y + 1, smashed,
4323 CE_OTHER_IS_SWITCHING,CH_SIDE_TOP);
4324 CheckElementChangeBySide(x, y + 1, smashed, element,
4325 CE_SWITCHED, CH_SIDE_TOP);
4331 CheckElementChange(x, y + 1, smashed, element, CE_SMASHED);
4336 /* play sound of magic wall / mill */
4338 (Feld[x][y + 1] == EL_MAGIC_WALL_ACTIVE ||
4339 Feld[x][y + 1] == EL_BD_MAGIC_WALL_ACTIVE))
4341 if (Feld[x][y + 1] == EL_MAGIC_WALL_ACTIVE)
4342 PlayLevelSound(x, y, SND_MAGIC_WALL_FILLING);
4343 else if (Feld[x][y + 1] == EL_BD_MAGIC_WALL_ACTIVE)
4344 PlayLevelSound(x, y, SND_BD_MAGIC_WALL_FILLING);
4349 /* play sound of object that hits the ground */
4350 if (lastline || object_hit)
4351 PlayLevelSoundElementAction(x, y, element, ACTION_IMPACT);
4354 inline static void TurnRoundExt(int x, int y)
4366 { 0, 0 }, { 0, 0 }, { 0, 0 },
4371 int left, right, back;
4375 { MV_DOWN, MV_UP, MV_RIGHT },
4376 { MV_UP, MV_DOWN, MV_LEFT },
4378 { MV_LEFT, MV_RIGHT, MV_DOWN },
4382 { MV_RIGHT, MV_LEFT, MV_UP }
4385 int element = Feld[x][y];
4386 int move_pattern = element_info[element].move_pattern;
4388 int old_move_dir = MovDir[x][y];
4389 int left_dir = turn[old_move_dir].left;
4390 int right_dir = turn[old_move_dir].right;
4391 int back_dir = turn[old_move_dir].back;
4393 int left_dx = move_xy[left_dir].x, left_dy = move_xy[left_dir].y;
4394 int right_dx = move_xy[right_dir].x, right_dy = move_xy[right_dir].y;
4395 int move_dx = move_xy[old_move_dir].x, move_dy = move_xy[old_move_dir].y;
4396 int back_dx = move_xy[back_dir].x, back_dy = move_xy[back_dir].y;
4398 int left_x = x + left_dx, left_y = y + left_dy;
4399 int right_x = x + right_dx, right_y = y + right_dy;
4400 int move_x = x + move_dx, move_y = y + move_dy;
4404 if (element == EL_BUG || element == EL_BD_BUTTERFLY)
4406 TestIfBadThingTouchesOtherBadThing(x, y);
4408 if (ENEMY_CAN_ENTER_FIELD(element, right_x, right_y))
4409 MovDir[x][y] = right_dir;
4410 else if (!ENEMY_CAN_ENTER_FIELD(element, move_x, move_y))
4411 MovDir[x][y] = left_dir;
4413 if (element == EL_BUG && MovDir[x][y] != old_move_dir)
4415 else if (element == EL_BD_BUTTERFLY) /* && MovDir[x][y] == left_dir) */
4419 else if (element == EL_SPACESHIP || element == EL_BD_FIREFLY ||
4420 element == EL_SP_SNIKSNAK || element == EL_SP_ELECTRON)
4422 TestIfBadThingTouchesOtherBadThing(x, y);
4424 if (ENEMY_CAN_ENTER_FIELD(element, left_x, left_y))
4425 MovDir[x][y] = left_dir;
4426 else if (!ENEMY_CAN_ENTER_FIELD(element, move_x, move_y))
4427 MovDir[x][y] = right_dir;
4429 if ((element == EL_SPACESHIP ||
4430 element == EL_SP_SNIKSNAK ||
4431 element == EL_SP_ELECTRON)
4432 && MovDir[x][y] != old_move_dir)
4434 else if (element == EL_BD_FIREFLY) /* && MovDir[x][y] == right_dir) */
4438 else if (element == EL_SPACESHIP || element == EL_BD_FIREFLY)
4440 TestIfBadThingTouchesOtherBadThing(x, y);
4442 if (ENEMY_CAN_ENTER_FIELD(element, left_x, left_y))
4443 MovDir[x][y] = left_dir;
4444 else if (!ENEMY_CAN_ENTER_FIELD(element, move_x, move_y))
4445 MovDir[x][y] = right_dir;
4447 if (element == EL_SPACESHIP && MovDir[x][y] != old_move_dir)
4449 else if (element == EL_BD_FIREFLY) /* && MovDir[x][y] == right_dir) */
4452 else if (element == EL_SP_SNIKSNAK || element == EL_SP_ELECTRON)
4454 TestIfBadThingTouchesOtherBadThing(x, y);
4456 if (ELEMENT_CAN_ENTER_FIELD_BASE_4(element, left_x, left_y, 0))
4457 MovDir[x][y] = left_dir;
4458 else if (!ELEMENT_CAN_ENTER_FIELD_BASE_4(element, move_x, move_y, 0))
4459 MovDir[x][y] = right_dir;
4461 if (MovDir[x][y] != old_move_dir)
4465 else if (element == EL_YAMYAM)
4467 boolean can_turn_left = YAMYAM_CAN_ENTER_FIELD(element, left_x, left_y);
4468 boolean can_turn_right = YAMYAM_CAN_ENTER_FIELD(element, right_x, right_y);
4470 if (can_turn_left && can_turn_right)
4471 MovDir[x][y] = (RND(3) ? (RND(2) ? left_dir : right_dir) : back_dir);
4472 else if (can_turn_left)
4473 MovDir[x][y] = (RND(2) ? left_dir : back_dir);
4474 else if (can_turn_right)
4475 MovDir[x][y] = (RND(2) ? right_dir : back_dir);
4477 MovDir[x][y] = back_dir;
4479 MovDelay[x][y] = 16 + 16 * RND(3);
4481 else if (element == EL_DARK_YAMYAM)
4483 boolean can_turn_left = DARK_YAMYAM_CAN_ENTER_FIELD(element,
4485 boolean can_turn_right = DARK_YAMYAM_CAN_ENTER_FIELD(element,
4488 if (can_turn_left && can_turn_right)
4489 MovDir[x][y] = (RND(3) ? (RND(2) ? left_dir : right_dir) : back_dir);
4490 else if (can_turn_left)
4491 MovDir[x][y] = (RND(2) ? left_dir : back_dir);
4492 else if (can_turn_right)
4493 MovDir[x][y] = (RND(2) ? right_dir : back_dir);
4495 MovDir[x][y] = back_dir;
4497 MovDelay[x][y] = 16 + 16 * RND(3);
4499 else if (element == EL_PACMAN)
4501 boolean can_turn_left = PACMAN_CAN_ENTER_FIELD(element, left_x, left_y);
4502 boolean can_turn_right = PACMAN_CAN_ENTER_FIELD(element, right_x, right_y);
4504 if (can_turn_left && can_turn_right)
4505 MovDir[x][y] = (RND(3) ? (RND(2) ? left_dir : right_dir) : back_dir);
4506 else if (can_turn_left)
4507 MovDir[x][y] = (RND(2) ? left_dir : back_dir);
4508 else if (can_turn_right)
4509 MovDir[x][y] = (RND(2) ? right_dir : back_dir);
4511 MovDir[x][y] = back_dir;
4513 MovDelay[x][y] = 6 + RND(40);
4515 else if (element == EL_PIG)
4517 boolean can_turn_left = PIG_CAN_ENTER_FIELD(element, left_x, left_y);
4518 boolean can_turn_right = PIG_CAN_ENTER_FIELD(element, right_x, right_y);
4519 boolean can_move_on = PIG_CAN_ENTER_FIELD(element, move_x, move_y);
4520 boolean should_turn_left, should_turn_right, should_move_on;
4522 int rnd = RND(rnd_value);
4524 should_turn_left = (can_turn_left &&
4526 IN_LEV_FIELD_AND_NOT_FREE(x + back_dx + left_dx,
4527 y + back_dy + left_dy)));
4528 should_turn_right = (can_turn_right &&
4530 IN_LEV_FIELD_AND_NOT_FREE(x + back_dx + right_dx,
4531 y + back_dy + right_dy)));
4532 should_move_on = (can_move_on &&
4535 IN_LEV_FIELD_AND_NOT_FREE(x + move_dx + left_dx,
4536 y + move_dy + left_dy) ||
4537 IN_LEV_FIELD_AND_NOT_FREE(x + move_dx + right_dx,
4538 y + move_dy + right_dy)));
4540 if (should_turn_left || should_turn_right || should_move_on)
4542 if (should_turn_left && should_turn_right && should_move_on)
4543 MovDir[x][y] = (rnd < rnd_value / 3 ? left_dir :
4544 rnd < 2 * rnd_value / 3 ? right_dir :
4546 else if (should_turn_left && should_turn_right)
4547 MovDir[x][y] = (rnd < rnd_value / 2 ? left_dir : right_dir);
4548 else if (should_turn_left && should_move_on)
4549 MovDir[x][y] = (rnd < rnd_value / 2 ? left_dir : old_move_dir);
4550 else if (should_turn_right && should_move_on)
4551 MovDir[x][y] = (rnd < rnd_value / 2 ? right_dir : old_move_dir);
4552 else if (should_turn_left)
4553 MovDir[x][y] = left_dir;
4554 else if (should_turn_right)
4555 MovDir[x][y] = right_dir;
4556 else if (should_move_on)
4557 MovDir[x][y] = old_move_dir;
4559 else if (can_move_on && rnd > rnd_value / 8)
4560 MovDir[x][y] = old_move_dir;
4561 else if (can_turn_left && can_turn_right)
4562 MovDir[x][y] = (rnd < rnd_value / 2 ? left_dir : right_dir);
4563 else if (can_turn_left && rnd > rnd_value / 8)
4564 MovDir[x][y] = left_dir;
4565 else if (can_turn_right && rnd > rnd_value/8)
4566 MovDir[x][y] = right_dir;
4568 MovDir[x][y] = back_dir;
4570 xx = x + move_xy[MovDir[x][y]].x;
4571 yy = y + move_xy[MovDir[x][y]].y;
4573 if (!IS_FREE(xx, yy) && !IS_FOOD_PIG(Feld[xx][yy]))
4574 MovDir[x][y] = old_move_dir;
4578 else if (element == EL_DRAGON)
4580 boolean can_turn_left = DRAGON_CAN_ENTER_FIELD(element, left_x, left_y);
4581 boolean can_turn_right = DRAGON_CAN_ENTER_FIELD(element, right_x, right_y);
4582 boolean can_move_on = DRAGON_CAN_ENTER_FIELD(element, move_x, move_y);
4584 int rnd = RND(rnd_value);
4587 if (FrameCounter < 1 && x == 0 && y == 29)
4588 printf(":2: %d/%d: %d [%d]\n", x, y, MovDir[x][y], FrameCounter);
4591 if (can_move_on && rnd > rnd_value / 8)
4592 MovDir[x][y] = old_move_dir;
4593 else if (can_turn_left && can_turn_right)
4594 MovDir[x][y] = (rnd < rnd_value / 2 ? left_dir : right_dir);
4595 else if (can_turn_left && rnd > rnd_value / 8)
4596 MovDir[x][y] = left_dir;
4597 else if (can_turn_right && rnd > rnd_value / 8)
4598 MovDir[x][y] = right_dir;
4600 MovDir[x][y] = back_dir;
4602 xx = x + move_xy[MovDir[x][y]].x;
4603 yy = y + move_xy[MovDir[x][y]].y;
4606 if (FrameCounter < 1 && x == 0 && y == 29)
4607 printf(":3: %d/%d: %d (%d/%d: %d) [%d]\n", x, y, MovDir[x][y],
4608 xx, yy, Feld[xx][yy],
4613 if (!IN_LEV_FIELD_AND_IS_FREE(xx, yy))
4614 MovDir[x][y] = old_move_dir;
4616 if (!IS_FREE(xx, yy))
4617 MovDir[x][y] = old_move_dir;
4621 if (FrameCounter < 1 && x == 0 && y == 29)
4622 printf(":4: %d/%d: %d [%d]\n", x, y, MovDir[x][y], FrameCounter);
4627 else if (element == EL_MOLE)
4629 boolean can_move_on =
4630 (MOLE_CAN_ENTER_FIELD(element, move_x, move_y,
4631 IS_AMOEBOID(Feld[move_x][move_y]) ||
4632 Feld[move_x][move_y] == EL_AMOEBA_SHRINKING));
4635 boolean can_turn_left =
4636 (MOLE_CAN_ENTER_FIELD(element, left_x, left_y,
4637 IS_AMOEBOID(Feld[left_x][left_y])));
4639 boolean can_turn_right =
4640 (MOLE_CAN_ENTER_FIELD(element, right_x, right_y,
4641 IS_AMOEBOID(Feld[right_x][right_y])));
4643 if (can_turn_left && can_turn_right)
4644 MovDir[x][y] = (RND(2) ? left_dir : right_dir);
4645 else if (can_turn_left)
4646 MovDir[x][y] = left_dir;
4648 MovDir[x][y] = right_dir;
4651 if (MovDir[x][y] != old_move_dir)
4654 else if (element == EL_BALLOON)
4656 MovDir[x][y] = game.balloon_dir;
4659 else if (element == EL_SPRING)
4662 if (MovDir[x][y] & MV_HORIZONTAL &&
4663 !SPRING_CAN_ENTER_FIELD(element, move_x, move_y))
4664 MovDir[x][y] = MV_NO_MOVING;
4666 if (MovDir[x][y] & MV_HORIZONTAL &&
4667 (!SPRING_CAN_ENTER_FIELD(element, move_x, move_y) ||
4668 SPRING_CAN_ENTER_FIELD(element, x, y + 1)))
4669 MovDir[x][y] = MV_NO_MOVING;
4674 else if (element == EL_ROBOT ||
4675 element == EL_SATELLITE ||
4676 element == EL_PENGUIN)
4678 int attr_x = -1, attr_y = -1;
4689 for (i = 0; i < MAX_PLAYERS; i++)
4691 struct PlayerInfo *player = &stored_player[i];
4692 int jx = player->jx, jy = player->jy;
4694 if (!player->active)
4698 ABS(jx - x) + ABS(jy - y) < ABS(attr_x - x) + ABS(attr_y - y))
4707 if (element == EL_ROBOT && ZX >= 0 && ZY >= 0 &&
4708 (Feld[ZX][ZY] == EL_ROBOT_WHEEL_ACTIVE ||
4709 game.engine_version < VERSION_IDENT(3,1,0,0)))
4711 if (element == EL_ROBOT && ZX >= 0 && ZY >= 0)
4718 if (element == EL_PENGUIN)
4721 static int xy[4][2] =
4729 for (i = 0; i < NUM_DIRECTIONS; i++)
4731 int ex = x + xy[i][0];
4732 int ey = y + xy[i][1];
4734 if (IN_LEV_FIELD(ex, ey) && Feld[ex][ey] == EL_EXIT_OPEN)
4743 MovDir[x][y] = MV_NO_MOVING;
4745 MovDir[x][y] |= (AllPlayersGone ? MV_RIGHT : MV_LEFT);
4746 else if (attr_x > x)
4747 MovDir[x][y] |= (AllPlayersGone ? MV_LEFT : MV_RIGHT);
4749 MovDir[x][y] |= (AllPlayersGone ? MV_DOWN : MV_UP);
4750 else if (attr_y > y)
4751 MovDir[x][y] |= (AllPlayersGone ? MV_UP : MV_DOWN);
4753 if (element == EL_ROBOT)
4757 if (MovDir[x][y] & MV_HORIZONTAL && MovDir[x][y] & MV_VERTICAL)
4758 MovDir[x][y] &= (RND(2) ? MV_HORIZONTAL : MV_VERTICAL);
4759 Moving2Blocked(x, y, &newx, &newy);
4761 if (IN_LEV_FIELD(newx, newy) && IS_FREE_OR_PLAYER(newx, newy))
4762 MovDelay[x][y] = 8 + 8 * !RND(3);
4764 MovDelay[x][y] = 16;
4766 else if (element == EL_PENGUIN)
4772 if (MovDir[x][y] & MV_HORIZONTAL && MovDir[x][y] & MV_VERTICAL)
4774 boolean first_horiz = RND(2);
4775 int new_move_dir = MovDir[x][y];
4778 new_move_dir & (first_horiz ? MV_HORIZONTAL : MV_VERTICAL);
4779 Moving2Blocked(x, y, &newx, &newy);
4781 if (PENGUIN_CAN_ENTER_FIELD(EL_PENGUIN, newx, newy))
4785 new_move_dir & (!first_horiz ? MV_HORIZONTAL : MV_VERTICAL);
4786 Moving2Blocked(x, y, &newx, &newy);
4788 if (PENGUIN_CAN_ENTER_FIELD(EL_PENGUIN, newx, newy))
4791 MovDir[x][y] = old_move_dir;
4795 else /* (element == EL_SATELLITE) */
4801 if (MovDir[x][y] & MV_HORIZONTAL && MovDir[x][y] & MV_VERTICAL)
4803 boolean first_horiz = RND(2);
4804 int new_move_dir = MovDir[x][y];
4807 new_move_dir & (first_horiz ? MV_HORIZONTAL : MV_VERTICAL);
4808 Moving2Blocked(x, y, &newx, &newy);
4810 if (SATELLITE_CAN_ENTER_FIELD(newx, newy))
4814 new_move_dir & (!first_horiz ? MV_HORIZONTAL : MV_VERTICAL);
4815 Moving2Blocked(x, y, &newx, &newy);
4817 if (SATELLITE_CAN_ENTER_FIELD(newx, newy))
4820 MovDir[x][y] = old_move_dir;
4825 else if (move_pattern == MV_TURNING_LEFT ||
4826 move_pattern == MV_TURNING_RIGHT ||
4827 move_pattern == MV_TURNING_LEFT_RIGHT ||
4828 move_pattern == MV_TURNING_RIGHT_LEFT ||
4829 move_pattern == MV_TURNING_RANDOM ||
4830 move_pattern == MV_ALL_DIRECTIONS)
4832 boolean can_turn_left =
4833 CUSTOM_ELEMENT_CAN_ENTER_FIELD(element, left_x, left_y);
4834 boolean can_turn_right =
4835 CUSTOM_ELEMENT_CAN_ENTER_FIELD(element, right_x,right_y);
4837 if (move_pattern == MV_TURNING_LEFT)
4838 MovDir[x][y] = left_dir;
4839 else if (move_pattern == MV_TURNING_RIGHT)
4840 MovDir[x][y] = right_dir;
4841 else if (move_pattern == MV_TURNING_LEFT_RIGHT)
4842 MovDir[x][y] = (can_turn_left || !can_turn_right ? left_dir : right_dir);
4843 else if (move_pattern == MV_TURNING_RIGHT_LEFT)
4844 MovDir[x][y] = (can_turn_right || !can_turn_left ? right_dir : left_dir);
4845 else if (move_pattern == MV_TURNING_RANDOM)
4846 MovDir[x][y] = (can_turn_left && !can_turn_right ? left_dir :
4847 can_turn_right && !can_turn_left ? right_dir :
4848 RND(2) ? left_dir : right_dir);
4849 else if (can_turn_left && can_turn_right)
4850 MovDir[x][y] = (RND(3) ? (RND(2) ? left_dir : right_dir) : back_dir);
4851 else if (can_turn_left)
4852 MovDir[x][y] = (RND(2) ? left_dir : back_dir);
4853 else if (can_turn_right)
4854 MovDir[x][y] = (RND(2) ? right_dir : back_dir);
4856 MovDir[x][y] = back_dir;
4858 MovDelay[x][y] = GET_NEW_MOVE_DELAY(element);
4860 else if (move_pattern == MV_HORIZONTAL ||
4861 move_pattern == MV_VERTICAL)
4863 if (move_pattern & old_move_dir)
4864 MovDir[x][y] = back_dir;
4865 else if (move_pattern == MV_HORIZONTAL)
4866 MovDir[x][y] = (RND(2) ? MV_LEFT : MV_RIGHT);
4867 else if (move_pattern == MV_VERTICAL)
4868 MovDir[x][y] = (RND(2) ? MV_UP : MV_DOWN);
4870 MovDelay[x][y] = GET_NEW_MOVE_DELAY(element);
4872 else if (move_pattern & MV_ANY_DIRECTION)
4874 MovDir[x][y] = move_pattern;
4875 MovDelay[x][y] = GET_NEW_MOVE_DELAY(element);
4877 else if (move_pattern == MV_ALONG_LEFT_SIDE)
4879 if (CUSTOM_ELEMENT_CAN_ENTER_FIELD(element, left_x, left_y))
4880 MovDir[x][y] = left_dir;
4881 else if (!CUSTOM_ELEMENT_CAN_ENTER_FIELD(element, move_x, move_y))
4882 MovDir[x][y] = right_dir;
4884 if (MovDir[x][y] != old_move_dir)
4885 MovDelay[x][y] = GET_NEW_MOVE_DELAY(element);
4887 else if (move_pattern == MV_ALONG_RIGHT_SIDE)
4889 if (CUSTOM_ELEMENT_CAN_ENTER_FIELD(element, right_x, right_y))
4890 MovDir[x][y] = right_dir;
4891 else if (!CUSTOM_ELEMENT_CAN_ENTER_FIELD(element, move_x, move_y))
4892 MovDir[x][y] = left_dir;
4894 if (MovDir[x][y] != old_move_dir)
4895 MovDelay[x][y] = GET_NEW_MOVE_DELAY(element);
4897 else if (move_pattern == MV_TOWARDS_PLAYER ||
4898 move_pattern == MV_AWAY_FROM_PLAYER)
4900 int attr_x = -1, attr_y = -1;
4902 boolean move_away = (move_pattern == MV_AWAY_FROM_PLAYER);
4913 for (i = 0; i < MAX_PLAYERS; i++)
4915 struct PlayerInfo *player = &stored_player[i];
4916 int jx = player->jx, jy = player->jy;
4918 if (!player->active)
4922 ABS(jx - x) + ABS(jy - y) < ABS(attr_x - x) + ABS(attr_y - y))
4930 MovDir[x][y] = MV_NO_MOVING;
4932 MovDir[x][y] |= (move_away ? MV_RIGHT : MV_LEFT);
4933 else if (attr_x > x)
4934 MovDir[x][y] |= (move_away ? MV_LEFT : MV_RIGHT);
4936 MovDir[x][y] |= (move_away ? MV_DOWN : MV_UP);
4937 else if (attr_y > y)
4938 MovDir[x][y] |= (move_away ? MV_UP : MV_DOWN);
4940 MovDelay[x][y] = GET_NEW_MOVE_DELAY(element);
4942 if (MovDir[x][y] & MV_HORIZONTAL && MovDir[x][y] & MV_VERTICAL)
4944 boolean first_horiz = RND(2);
4945 int new_move_dir = MovDir[x][y];
4948 new_move_dir & (first_horiz ? MV_HORIZONTAL : MV_VERTICAL);
4949 Moving2Blocked(x, y, &newx, &newy);
4951 if (CUSTOM_ELEMENT_CAN_ENTER_FIELD(element, newx, newy))
4955 new_move_dir & (!first_horiz ? MV_HORIZONTAL : MV_VERTICAL);
4956 Moving2Blocked(x, y, &newx, &newy);
4958 if (CUSTOM_ELEMENT_CAN_ENTER_FIELD(element, newx, newy))
4961 MovDir[x][y] = old_move_dir;
4964 else if (move_pattern == MV_WHEN_PUSHED ||
4965 move_pattern == MV_WHEN_DROPPED)
4967 if (!CUSTOM_ELEMENT_CAN_ENTER_FIELD(element, move_x, move_y))
4968 MovDir[x][y] = MV_NO_MOVING;
4972 else if (move_pattern & MV_MAZE_RUNNER_STYLE)
4974 static int test_xy[7][2] =
4984 static int test_dir[7] =
4994 boolean hunter_mode = (move_pattern == MV_MAZE_HUNTER);
4995 int move_preference = -1000000; /* start with very low preference */
4996 int new_move_dir = MV_NO_MOVING;
4997 int start_test = RND(4);
5000 for (i = 0; i < NUM_DIRECTIONS; i++)
5002 int move_dir = test_dir[start_test + i];
5003 int move_dir_preference;
5005 xx = x + test_xy[start_test + i][0];
5006 yy = y + test_xy[start_test + i][1];
5008 if (hunter_mode && IN_LEV_FIELD(xx, yy) &&
5009 (IS_PLAYER(xx, yy) || Feld[xx][yy] == EL_PLAYER_IS_LEAVING))
5011 new_move_dir = move_dir;
5016 if (!CUSTOM_ELEMENT_CAN_ENTER_FIELD(element, xx, yy))
5019 move_dir_preference = -1 * RunnerVisit[xx][yy];
5020 if (hunter_mode && PlayerVisit[xx][yy] > 0)
5021 move_dir_preference = PlayerVisit[xx][yy];
5023 if (move_dir_preference > move_preference)
5025 /* prefer field that has not been visited for the longest time */
5026 move_preference = move_dir_preference;
5027 new_move_dir = move_dir;
5029 else if (move_dir_preference == move_preference &&
5030 move_dir == old_move_dir)
5032 /* prefer last direction when all directions are preferred equally */
5033 move_preference = move_dir_preference;
5034 new_move_dir = move_dir;
5038 MovDir[x][y] = new_move_dir;
5039 if (old_move_dir != new_move_dir)
5044 static void TurnRound(int x, int y)
5046 int direction = MovDir[x][y];
5049 GfxDir[x][y] = MovDir[x][y];
5055 GfxDir[x][y] = MovDir[x][y];
5058 if (direction != MovDir[x][y])
5063 GfxAction[x][y] = ACTION_TURNING_FROM_LEFT + MV_DIR_BIT(direction);
5066 GfxAction[x][y] = ACTION_WAITING;
5070 static boolean JustBeingPushed(int x, int y)
5074 for (i = 0; i < MAX_PLAYERS; i++)
5076 struct PlayerInfo *player = &stored_player[i];
5078 if (player->active && player->is_pushing && player->MovPos)
5080 int next_jx = player->jx + (player->jx - player->last_jx);
5081 int next_jy = player->jy + (player->jy - player->last_jy);
5083 if (x == next_jx && y == next_jy)
5091 void StartMoving(int x, int y)
5094 boolean use_spring_bug = (game.engine_version < VERSION_IDENT(2,2,0,0));
5096 boolean started_moving = FALSE; /* some elements can fall _and_ move */
5097 int element = Feld[x][y];
5103 if (MovDelay[x][y] == 0)
5104 GfxAction[x][y] = ACTION_DEFAULT;
5106 /* !!! this should be handled more generic (not only for mole) !!! */
5107 if (element != EL_MOLE && GfxAction[x][y] != ACTION_DIGGING)
5108 GfxAction[x][y] = ACTION_DEFAULT;
5111 if (CAN_FALL(element) && y < lev_fieldy - 1)
5113 if ((x > 0 && IS_PLAYER(x - 1, y)) ||
5114 (x < lev_fieldx - 1 && IS_PLAYER(x + 1, y)))
5115 if (JustBeingPushed(x, y))
5118 if (element == EL_QUICKSAND_FULL)
5120 if (IS_FREE(x, y + 1))
5122 InitMovingField(x, y, MV_DOWN);
5123 started_moving = TRUE;
5125 Feld[x][y] = EL_QUICKSAND_EMPTYING;
5126 Store[x][y] = EL_ROCK;
5128 PlayLevelSoundAction(x, y, ACTION_EMPTYING);
5130 PlayLevelSound(x, y, SND_QUICKSAND_EMPTYING);
5133 else if (Feld[x][y + 1] == EL_QUICKSAND_EMPTY)
5135 if (!MovDelay[x][y])
5136 MovDelay[x][y] = TILEY + 1;
5145 Feld[x][y] = EL_QUICKSAND_EMPTY;
5146 Feld[x][y + 1] = EL_QUICKSAND_FULL;
5147 Store[x][y + 1] = Store[x][y];
5150 PlayLevelSoundAction(x, y, ACTION_FILLING);
5152 PlayLevelSound(x, y, SND_QUICKSAND_FILLING);
5156 else if ((element == EL_ROCK || element == EL_BD_ROCK) &&
5157 Feld[x][y + 1] == EL_QUICKSAND_EMPTY)
5159 InitMovingField(x, y, MV_DOWN);
5160 started_moving = TRUE;
5162 Feld[x][y] = EL_QUICKSAND_FILLING;
5163 Store[x][y] = element;
5165 PlayLevelSoundAction(x, y, ACTION_FILLING);
5167 PlayLevelSound(x, y, SND_QUICKSAND_FILLING);
5170 else if (element == EL_MAGIC_WALL_FULL)
5172 if (IS_FREE(x, y + 1))
5174 InitMovingField(x, y, MV_DOWN);
5175 started_moving = TRUE;
5177 Feld[x][y] = EL_MAGIC_WALL_EMPTYING;
5178 Store[x][y] = EL_CHANGED(Store[x][y]);
5180 else if (Feld[x][y + 1] == EL_MAGIC_WALL_ACTIVE)
5182 if (!MovDelay[x][y])
5183 MovDelay[x][y] = TILEY/4 + 1;
5192 Feld[x][y] = EL_MAGIC_WALL_ACTIVE;
5193 Feld[x][y + 1] = EL_MAGIC_WALL_FULL;
5194 Store[x][y + 1] = EL_CHANGED(Store[x][y]);
5198 else if (element == EL_BD_MAGIC_WALL_FULL)
5200 if (IS_FREE(x, y + 1))
5202 InitMovingField(x, y, MV_DOWN);
5203 started_moving = TRUE;
5205 Feld[x][y] = EL_BD_MAGIC_WALL_EMPTYING;
5206 Store[x][y] = EL_CHANGED2(Store[x][y]);
5208 else if (Feld[x][y + 1] == EL_BD_MAGIC_WALL_ACTIVE)
5210 if (!MovDelay[x][y])
5211 MovDelay[x][y] = TILEY/4 + 1;
5220 Feld[x][y] = EL_BD_MAGIC_WALL_ACTIVE;
5221 Feld[x][y + 1] = EL_BD_MAGIC_WALL_FULL;
5222 Store[x][y + 1] = EL_CHANGED2(Store[x][y]);
5226 else if (CAN_PASS_MAGIC_WALL(element) &&
5227 (Feld[x][y + 1] == EL_MAGIC_WALL_ACTIVE ||
5228 Feld[x][y + 1] == EL_BD_MAGIC_WALL_ACTIVE))
5230 InitMovingField(x, y, MV_DOWN);
5231 started_moving = TRUE;
5234 (Feld[x][y + 1] == EL_MAGIC_WALL_ACTIVE ? EL_MAGIC_WALL_FILLING :
5235 EL_BD_MAGIC_WALL_FILLING);
5236 Store[x][y] = element;
5239 else if (CAN_SMASH(element) && Feld[x][y + 1] == EL_ACID)
5241 else if (CAN_FALL(element) && Feld[x][y + 1] == EL_ACID)
5244 SplashAcid(x, y + 1);
5246 InitMovingField(x, y, MV_DOWN);
5247 started_moving = TRUE;
5249 Store[x][y] = EL_ACID;
5251 /* !!! TEST !!! better use "_FALLING" etc. !!! */
5252 GfxAction[x][y + 1] = ACTION_ACTIVE;
5256 else if ((game.engine_version >= VERSION_IDENT(3,1,0,0) &&
5257 CheckCollision[x][y] && !IS_FREE(x, y + 1)) ||
5259 (game.engine_version >= VERSION_IDENT(3,0,7,0) &&
5260 CAN_SMASH(element) && WasJustFalling[x][y] &&
5261 (Feld[x][y + 1] == EL_BLOCKED || IS_PLAYER(x, y + 1))) ||
5263 (game.engine_version < VERSION_IDENT(2,2,0,7) &&
5264 CAN_SMASH(element) && WasJustMoving[x][y] && !Pushed[x][y + 1] &&
5265 (Feld[x][y + 1] == EL_BLOCKED)))
5269 else if (game.engine_version < VERSION_IDENT(2,2,0,7) &&
5270 CAN_SMASH(element) && Feld[x][y + 1] == EL_BLOCKED &&
5271 WasJustMoving[x][y] && !Pushed[x][y + 1])
5273 else if (CAN_SMASH(element) && Feld[x][y + 1] == EL_BLOCKED &&
5274 WasJustMoving[x][y])
5279 /* this is needed for a special case not covered by calling "Impact()"
5280 from "ContinueMoving()": if an element moves to a tile directly below
5281 another element which was just falling on that tile (which was empty
5282 in the previous frame), the falling element above would just stop
5283 instead of smashing the element below (in previous version, the above
5284 element was just checked for "moving" instead of "falling", resulting
5285 in incorrect smashes caused by horizontal movement of the above
5286 element; also, the case of the player being the element to smash was
5287 simply not covered here... :-/ ) */
5290 WasJustMoving[x][y] = 0;
5291 WasJustFalling[x][y] = 0;
5294 CheckCollision[x][y] = 0;
5298 else if (IS_FREE(x, y + 1) && element == EL_SPRING && level.use_spring_bug)
5300 if (MovDir[x][y] == MV_NO_MOVING)
5302 InitMovingField(x, y, MV_DOWN);
5303 started_moving = TRUE;
5306 else if (IS_FREE(x, y + 1) || Feld[x][y + 1] == EL_DIAMOND_BREAKING)
5308 if (WasJustFalling[x][y]) /* prevent animation from being restarted */
5309 MovDir[x][y] = MV_DOWN;
5311 InitMovingField(x, y, MV_DOWN);
5312 started_moving = TRUE;
5314 else if (element == EL_AMOEBA_DROP)
5316 Feld[x][y] = EL_AMOEBA_GROWING;
5317 Store[x][y] = EL_AMOEBA_WET;
5319 /* Store[x][y + 1] must be zero, because:
5320 (EL_QUICKSAND_FULL -> EL_ROCK): Store[x][y + 1] == EL_QUICKSAND_EMPTY
5323 #if OLD_GAME_BEHAVIOUR
5324 else if (IS_SLIPPERY(Feld[x][y + 1]) && !Store[x][y + 1])
5326 else if (IS_SLIPPERY(Feld[x][y + 1]) && !Store[x][y + 1] &&
5327 !IS_FALLING(x, y + 1) && !WasJustMoving[x][y + 1] &&
5328 element != EL_DX_SUPABOMB)
5331 else if (((IS_SLIPPERY(Feld[x][y + 1]) && !IS_PLAYER(x, y + 1)) ||
5332 (IS_EM_SLIPPERY_WALL(Feld[x][y + 1]) && IS_GEM(element))) &&
5333 !IS_FALLING(x, y + 1) && !WasJustMoving[x][y + 1] &&
5334 element != EL_DX_SUPABOMB && element != EL_SP_DISK_ORANGE)
5337 boolean can_fall_left = (x > 0 && IS_FREE(x - 1, y) &&
5338 (IS_FREE(x - 1, y + 1) ||
5339 Feld[x - 1][y + 1] == EL_ACID));
5340 boolean can_fall_right = (x < lev_fieldx - 1 && IS_FREE(x + 1, y) &&
5341 (IS_FREE(x + 1, y + 1) ||
5342 Feld[x + 1][y + 1] == EL_ACID));
5343 boolean can_fall_any = (can_fall_left || can_fall_right);
5344 boolean can_fall_both = (can_fall_left && can_fall_right);
5346 if (can_fall_any && IS_CUSTOM_ELEMENT(Feld[x][y + 1]))
5348 int slippery_type = element_info[Feld[x][y + 1]].slippery_type;
5350 if (slippery_type == SLIPPERY_ONLY_LEFT)
5351 can_fall_right = FALSE;
5352 else if (slippery_type == SLIPPERY_ONLY_RIGHT)
5353 can_fall_left = FALSE;
5354 else if (slippery_type == SLIPPERY_ANY_LEFT_RIGHT && can_fall_both)
5355 can_fall_right = FALSE;
5356 else if (slippery_type == SLIPPERY_ANY_RIGHT_LEFT && can_fall_both)
5357 can_fall_left = FALSE;
5359 can_fall_any = (can_fall_left || can_fall_right);
5360 can_fall_both = (can_fall_left && can_fall_right);
5365 if (can_fall_both &&
5366 (game.emulation != EMU_BOULDERDASH &&
5367 element != EL_BD_ROCK && element != EL_BD_DIAMOND))
5368 can_fall_left = !(can_fall_right = RND(2));
5370 InitMovingField(x, y, can_fall_left ? MV_LEFT : MV_RIGHT);
5371 started_moving = TRUE;
5375 else if (IS_BELT_ACTIVE(Feld[x][y + 1]) && !CAN_MOVE(element))
5377 else if (IS_BELT_ACTIVE(Feld[x][y + 1]))
5380 boolean left_is_free = (x > 0 && IS_FREE(x - 1, y));
5381 boolean right_is_free = (x < lev_fieldx - 1 && IS_FREE(x + 1, y));
5382 int belt_nr = getBeltNrFromBeltActiveElement(Feld[x][y + 1]);
5383 int belt_dir = game.belt_dir[belt_nr];
5385 if ((belt_dir == MV_LEFT && left_is_free) ||
5386 (belt_dir == MV_RIGHT && right_is_free))
5389 int nextx = (belt_dir == MV_LEFT ? x - 1 : x + 1);
5392 InitMovingField(x, y, belt_dir);
5393 started_moving = TRUE;
5396 Pushed[x][y] = TRUE;
5397 Pushed[nextx][y] = TRUE;
5400 GfxAction[x][y] = ACTION_DEFAULT;
5404 MovDir[x][y] = 0; /* if element was moving, stop it */
5409 /* not "else if" because of elements that can fall and move (EL_SPRING) */
5411 if (CAN_MOVE(element) && !started_moving && MovDir[x][y] != MV_NO_MOVING)
5413 if (CAN_MOVE(element) && !started_moving)
5416 int move_pattern = element_info[element].move_pattern;
5421 if (MovDir[x][y] == MV_NO_MOVING)
5423 printf("StartMoving(): %d,%d: element %d ['%s'] not moving\n",
5424 x, y, element, element_info[element].token_name);
5425 printf("StartMoving(): This should never happen!\n");
5430 Moving2Blocked(x, y, &newx, &newy);
5433 if (IS_PUSHABLE(element) && JustBeingPushed(x, y))
5436 if ((element == EL_SATELLITE ||
5437 element == EL_BALLOON ||
5438 element == EL_SPRING)
5439 && JustBeingPushed(x, y))
5446 if (game.engine_version >= VERSION_IDENT(3,1,0,0) &&
5447 CheckCollision[x][y] && !IN_LEV_FIELD_AND_IS_FREE(newx, newy))
5449 if (game.engine_version >= VERSION_IDENT(3,1,0,0) &&
5450 WasJustMoving[x][y] && IN_LEV_FIELD(newx, newy) &&
5451 (Feld[newx][newy] == EL_BLOCKED || IS_PLAYER(newx, newy)))
5455 printf("::: element %d '%s' WasJustMoving %d [%d, %d, %d, %d]\n",
5456 element, element_info[element].token_name,
5457 WasJustMoving[x][y],
5458 HAS_ANY_CHANGE_EVENT(element, CE_HITTING_SOMETHING),
5459 HAS_ANY_CHANGE_EVENT(element, CE_HIT_BY_SOMETHING),
5460 HAS_ANY_CHANGE_EVENT(element, CE_OTHER_IS_HITTING),
5461 HAS_ANY_CHANGE_EVENT(element, CE_OTHER_GETS_HIT));
5465 WasJustMoving[x][y] = 0;
5468 CheckCollision[x][y] = 0;
5470 TestIfElementHitsCustomElement(x, y, MovDir[x][y]);
5473 if (Feld[x][y] != element) /* element has changed */
5475 element = Feld[x][y];
5476 move_pattern = element_info[element].move_pattern;
5478 if (!CAN_MOVE(element))
5482 if (Feld[x][y] != element) /* element has changed */
5490 if (element == EL_SPRING && MovDir[x][y] == MV_DOWN)
5491 Feld[x][y + 1] = EL_EMPTY; /* was set to EL_BLOCKED above */
5493 if (element == EL_SPRING && MovDir[x][y] != MV_NO_MOVING)
5495 Moving2Blocked(x, y, &newx, &newy);
5496 if (Feld[newx][newy] == EL_BLOCKED)
5497 Feld[newx][newy] = EL_EMPTY; /* was set to EL_BLOCKED above */
5503 if (FrameCounter < 1 && x == 0 && y == 29)
5504 printf(":1: %d/%d: %d [%d]\n", x, y, MovDir[x][y], FrameCounter);
5507 if (!MovDelay[x][y]) /* start new movement phase */
5509 /* all objects that can change their move direction after each step
5510 (YAMYAM, DARK_YAMYAM and PACMAN go straight until they hit a wall */
5512 if (element != EL_YAMYAM &&
5513 element != EL_DARK_YAMYAM &&
5514 element != EL_PACMAN &&
5515 !(move_pattern & MV_ANY_DIRECTION) &&
5516 move_pattern != MV_TURNING_LEFT &&
5517 move_pattern != MV_TURNING_RIGHT &&
5518 move_pattern != MV_TURNING_LEFT_RIGHT &&
5519 move_pattern != MV_TURNING_RIGHT_LEFT &&
5520 move_pattern != MV_TURNING_RANDOM)
5525 if (FrameCounter < 1 && x == 0 && y == 29)
5526 printf(":9: %d: %d [%d]\n", y, MovDir[x][y], FrameCounter);
5529 if (MovDelay[x][y] && (element == EL_BUG ||
5530 element == EL_SPACESHIP ||
5531 element == EL_SP_SNIKSNAK ||
5532 element == EL_SP_ELECTRON ||
5533 element == EL_MOLE))
5534 DrawLevelField(x, y);
5538 if (MovDelay[x][y]) /* wait some time before next movement */
5543 if (element == EL_YAMYAM)
5546 el_act_dir2img(EL_YAMYAM, ACTION_WAITING, MV_LEFT));
5547 DrawLevelElementAnimation(x, y, element);
5551 if (MovDelay[x][y]) /* element still has to wait some time */
5554 /* !!! PLACE THIS SOMEWHERE AFTER "TurnRound()" !!! */
5555 ResetGfxAnimation(x, y);
5559 if (GfxAction[x][y] != ACTION_WAITING)
5560 printf("::: %d: %d != ACTION_WAITING\n", element, GfxAction[x][y]);
5562 GfxAction[x][y] = ACTION_WAITING;
5566 if (element == EL_ROBOT ||
5568 element == EL_PACMAN ||
5570 element == EL_YAMYAM ||
5571 element == EL_DARK_YAMYAM)
5574 DrawLevelElementAnimation(x, y, element);
5576 DrawLevelElementAnimationIfNeeded(x, y, element);
5578 PlayLevelSoundAction(x, y, ACTION_WAITING);
5580 else if (element == EL_SP_ELECTRON)
5581 DrawLevelElementAnimationIfNeeded(x, y, element);
5582 else if (element == EL_DRAGON)
5585 int dir = MovDir[x][y];
5586 int dx = (dir == MV_LEFT ? -1 : dir == MV_RIGHT ? +1 : 0);
5587 int dy = (dir == MV_UP ? -1 : dir == MV_DOWN ? +1 : 0);
5588 int graphic = (dir == MV_LEFT ? IMG_FLAMES_1_LEFT :
5589 dir == MV_RIGHT ? IMG_FLAMES_1_RIGHT :
5590 dir == MV_UP ? IMG_FLAMES_1_UP :
5591 dir == MV_DOWN ? IMG_FLAMES_1_DOWN : IMG_EMPTY);
5592 int frame = getGraphicAnimationFrame(graphic, GfxFrame[x][y]);
5595 printf("::: %d, %d\n", GfxAction[x][y], GfxFrame[x][y]);
5598 GfxAction[x][y] = ACTION_ATTACKING;
5600 if (IS_PLAYER(x, y))
5601 DrawPlayerField(x, y);
5603 DrawLevelField(x, y);
5605 PlayLevelSoundActionIfLoop(x, y, ACTION_ATTACKING);
5607 for (i = 1; i <= 3; i++)
5609 int xx = x + i * dx;
5610 int yy = y + i * dy;
5611 int sx = SCREENX(xx);
5612 int sy = SCREENY(yy);
5613 int flame_graphic = graphic + (i - 1);
5615 if (!IN_LEV_FIELD(xx, yy) || IS_DRAGONFIRE_PROOF(Feld[xx][yy]))
5620 int flamed = MovingOrBlocked2Element(xx, yy);
5624 if (IS_CLASSIC_ENEMY(flamed) || CAN_EXPLODE_BY_DRAGONFIRE(flamed))
5626 else if (IS_MOVING(xx, yy) || IS_BLOCKED(xx, yy))
5627 RemoveMovingField(xx, yy);
5629 RemoveField(xx, yy);
5631 if (IS_CLASSIC_ENEMY(flamed) || CAN_EXPLODE_BY_DRAGONFIRE(flamed))
5634 RemoveMovingField(xx, yy);
5638 if (ChangeDelay[xx][yy])
5639 printf("::: !!! [%d]\n", (IS_MOVING(xx, yy) ||
5640 Feld[xx][yy] == EL_BLOCKED));
5644 ChangeDelay[xx][yy] = 0;
5646 Feld[xx][yy] = EL_FLAMES;
5647 if (IN_SCR_FIELD(sx, sy))
5649 DrawLevelFieldCrumbledSand(xx, yy);
5650 DrawGraphic(sx, sy, flame_graphic, frame);
5655 if (Feld[xx][yy] == EL_FLAMES)
5656 Feld[xx][yy] = EL_EMPTY;
5657 DrawLevelField(xx, yy);
5662 if (MovDelay[x][y]) /* element still has to wait some time */
5664 PlayLevelSoundAction(x, y, ACTION_WAITING);
5670 /* special case of "moving" animation of waiting elements (FIX THIS !!!);
5671 for all other elements GfxAction will be set by InitMovingField() */
5672 if (element == EL_BD_BUTTERFLY || element == EL_BD_FIREFLY)
5673 GfxAction[x][y] = ACTION_MOVING;
5677 /* now make next step */
5679 Moving2Blocked(x, y, &newx, &newy); /* get next screen position */
5681 if (DONT_COLLIDE_WITH(element) &&
5682 IN_LEV_FIELD(newx, newy) && IS_PLAYER(newx, newy) &&
5683 !PLAYER_ENEMY_PROTECTED(newx, newy))
5686 TestIfBadThingRunsIntoHero(x, y, MovDir[x][y]);
5690 /* player killed by element which is deadly when colliding with */
5692 KillHero(PLAYERINFO(newx, newy));
5699 else if (CAN_MOVE_INTO_ACID(element) &&
5700 IN_LEV_FIELD(newx, newy) && Feld[newx][newy] == EL_ACID &&
5701 (MovDir[x][y] == MV_DOWN ||
5702 game.engine_version >= VERSION_IDENT(3,1,0,0)))
5704 else if (CAN_MOVE_INTO_ACID(element) && MovDir[x][y] == MV_DOWN &&
5705 IN_LEV_FIELD(newx, newy) && Feld[newx][newy] == EL_ACID)
5709 else if ((element == EL_PENGUIN ||
5710 element == EL_ROBOT ||
5711 element == EL_SATELLITE ||
5712 element == EL_BALLOON ||
5713 IS_CUSTOM_ELEMENT(element)) &&
5714 IN_LEV_FIELD(newx, newy) &&
5715 MovDir[x][y] == MV_DOWN && Feld[newx][newy] == EL_ACID)
5718 SplashAcid(newx, newy);
5719 Store[x][y] = EL_ACID;
5721 else if (element == EL_PENGUIN && IN_LEV_FIELD(newx, newy))
5723 if (Feld[newx][newy] == EL_EXIT_OPEN)
5727 DrawLevelField(x, y);
5729 Feld[x][y] = EL_EMPTY;
5730 DrawLevelField(x, y);
5733 PlayLevelSound(newx, newy, SND_PENGUIN_PASSING);
5734 if (IN_SCR_FIELD(SCREENX(newx), SCREENY(newy)))
5735 DrawGraphicThruMask(SCREENX(newx),SCREENY(newy), el2img(element), 0);
5737 local_player->friends_still_needed--;
5738 if (!local_player->friends_still_needed &&
5739 !local_player->GameOver && AllPlayersGone)
5740 local_player->LevelSolved = local_player->GameOver = TRUE;
5744 else if (IS_FOOD_PENGUIN(Feld[newx][newy]))
5746 if (DigField(local_player, x, y, newx, newy, 0,0, DF_DIG) == MF_MOVING)
5747 DrawLevelField(newx, newy);
5749 GfxDir[x][y] = MovDir[x][y] = MV_NO_MOVING;
5751 else if (!IS_FREE(newx, newy))
5753 GfxAction[x][y] = ACTION_WAITING;
5755 if (IS_PLAYER(x, y))
5756 DrawPlayerField(x, y);
5758 DrawLevelField(x, y);
5763 else if (element == EL_PIG && IN_LEV_FIELD(newx, newy))
5765 if (IS_FOOD_PIG(Feld[newx][newy]))
5767 if (IS_MOVING(newx, newy))
5768 RemoveMovingField(newx, newy);
5771 Feld[newx][newy] = EL_EMPTY;
5772 DrawLevelField(newx, newy);
5775 PlayLevelSound(x, y, SND_PIG_DIGGING);
5777 else if (!IS_FREE(newx, newy))
5779 if (IS_PLAYER(x, y))
5780 DrawPlayerField(x, y);
5782 DrawLevelField(x, y);
5791 else if (move_pattern & MV_MAZE_RUNNER_STYLE && IN_LEV_FIELD(newx, newy))
5794 else if (IS_CUSTOM_ELEMENT(element) &&
5795 CUSTOM_ELEMENT_CAN_ENTER_FIELD(element, newx, newy)
5799 !IS_FREE(newx, newy)
5804 int new_element = Feld[newx][newy];
5807 printf("::: '%s' digs '%s' [%d]\n",
5808 element_info[element].token_name,
5809 element_info[Feld[newx][newy]].token_name,
5810 StorePlayer[newx][newy]);
5813 if (!IS_FREE(newx, newy))
5815 int action = (IS_DIGGABLE(new_element) ? ACTION_DIGGING :
5816 IS_COLLECTIBLE(new_element) ? ACTION_COLLECTING :
5819 /* no element can dig solid indestructible elements */
5820 if (IS_INDESTRUCTIBLE(new_element) &&
5821 !IS_DIGGABLE(new_element) &&
5822 !IS_COLLECTIBLE(new_element))
5825 if (AmoebaNr[newx][newy] &&
5826 (new_element == EL_AMOEBA_FULL ||
5827 new_element == EL_BD_AMOEBA ||
5828 new_element == EL_AMOEBA_GROWING))
5830 AmoebaCnt[AmoebaNr[newx][newy]]--;
5831 AmoebaCnt2[AmoebaNr[newx][newy]]--;
5834 if (IS_MOVING(newx, newy))
5835 RemoveMovingField(newx, newy);
5838 RemoveField(newx, newy);
5839 DrawLevelField(newx, newy);
5842 /* if digged element was about to explode, prevent the explosion */
5843 ExplodeField[newx][newy] = EX_TYPE_NONE;
5845 PlayLevelSoundAction(x, y, action);
5850 Store[newx][newy] = EL_EMPTY;
5851 if (IS_EQUAL_OR_IN_GROUP(new_element, MOVE_ENTER_EL(element)))
5852 Store[newx][newy] = element_info[element].move_leave_element;
5854 Store[newx][newy] = EL_EMPTY;
5855 if (IS_EQUAL_OR_IN_GROUP(new_element, MOVE_ENTER_EL(element)) ||
5856 element_info[element].move_leave_type == LEAVE_TYPE_UNLIMITED)
5857 Store[newx][newy] = element_info[element].move_leave_element;
5860 if (IS_EQUAL_OR_IN_GROUP(new_element, MOVE_ENTER_EL(element)))
5861 element_info[element].can_leave_element = TRUE;
5864 if (move_pattern & MV_MAZE_RUNNER_STYLE)
5866 RunnerVisit[x][y] = FrameCounter;
5867 PlayerVisit[x][y] /= 8; /* expire player visit path */
5873 else if (element == EL_DRAGON && IN_LEV_FIELD(newx, newy))
5875 if (!IS_FREE(newx, newy))
5877 if (IS_PLAYER(x, y))
5878 DrawPlayerField(x, y);
5880 DrawLevelField(x, y);
5886 boolean wanna_flame = !RND(10);
5887 int dx = newx - x, dy = newy - y;
5888 int newx1 = newx + 1 * dx, newy1 = newy + 1 * dy;
5889 int newx2 = newx + 2 * dx, newy2 = newy + 2 * dy;
5890 int element1 = (IN_LEV_FIELD(newx1, newy1) ?
5891 MovingOrBlocked2Element(newx1, newy1) : EL_STEELWALL);
5892 int element2 = (IN_LEV_FIELD(newx2, newy2) ?
5893 MovingOrBlocked2Element(newx2, newy2) : EL_STEELWALL);
5896 IS_CLASSIC_ENEMY(element1) ||
5897 IS_CLASSIC_ENEMY(element2)) &&
5898 element1 != EL_DRAGON && element2 != EL_DRAGON &&
5899 element1 != EL_FLAMES && element2 != EL_FLAMES)
5902 ResetGfxAnimation(x, y);
5903 GfxAction[x][y] = ACTION_ATTACKING;
5906 if (IS_PLAYER(x, y))
5907 DrawPlayerField(x, y);
5909 DrawLevelField(x, y);
5911 PlayLevelSound(x, y, SND_DRAGON_ATTACKING);
5913 MovDelay[x][y] = 50;
5917 RemoveField(newx, newy);
5919 Feld[newx][newy] = EL_FLAMES;
5920 if (IN_LEV_FIELD(newx1, newy1) && Feld[newx1][newy1] == EL_EMPTY)
5923 RemoveField(newx1, newy1);
5925 Feld[newx1][newy1] = EL_FLAMES;
5927 if (IN_LEV_FIELD(newx2, newy2) && Feld[newx2][newy2] == EL_EMPTY)
5930 RemoveField(newx2, newy2);
5932 Feld[newx2][newy2] = EL_FLAMES;
5939 else if (element == EL_YAMYAM && IN_LEV_FIELD(newx, newy) &&
5940 Feld[newx][newy] == EL_DIAMOND)
5942 if (IS_MOVING(newx, newy))
5943 RemoveMovingField(newx, newy);
5946 Feld[newx][newy] = EL_EMPTY;
5947 DrawLevelField(newx, newy);
5950 PlayLevelSound(x, y, SND_YAMYAM_DIGGING);
5952 else if (element == EL_DARK_YAMYAM && IN_LEV_FIELD(newx, newy) &&
5953 IS_FOOD_DARK_YAMYAM(Feld[newx][newy]))
5955 if (AmoebaNr[newx][newy])
5957 AmoebaCnt2[AmoebaNr[newx][newy]]--;
5958 if (Feld[newx][newy] == EL_AMOEBA_FULL ||
5959 Feld[newx][newy] == EL_BD_AMOEBA)
5960 AmoebaCnt[AmoebaNr[newx][newy]]--;
5965 if (IS_MOVING(newx, newy) || IS_BLOCKED(newx, newy))
5967 if (IS_MOVING(newx, newy))
5970 RemoveMovingField(newx, newy);
5974 Feld[newx][newy] = EL_EMPTY;
5975 DrawLevelField(newx, newy);
5978 PlayLevelSound(x, y, SND_DARK_YAMYAM_DIGGING);
5980 else if ((element == EL_PACMAN || element == EL_MOLE)
5981 && IN_LEV_FIELD(newx, newy) && IS_AMOEBOID(Feld[newx][newy]))
5983 if (AmoebaNr[newx][newy])
5985 AmoebaCnt2[AmoebaNr[newx][newy]]--;
5986 if (Feld[newx][newy] == EL_AMOEBA_FULL ||
5987 Feld[newx][newy] == EL_BD_AMOEBA)
5988 AmoebaCnt[AmoebaNr[newx][newy]]--;
5991 if (element == EL_MOLE)
5993 Feld[newx][newy] = EL_AMOEBA_SHRINKING;
5994 PlayLevelSound(x, y, SND_MOLE_DIGGING);
5996 ResetGfxAnimation(x, y);
5997 GfxAction[x][y] = ACTION_DIGGING;
5998 DrawLevelField(x, y);
6000 MovDelay[newx][newy] = 0; /* start amoeba shrinking delay */
6002 return; /* wait for shrinking amoeba */
6004 else /* element == EL_PACMAN */
6006 Feld[newx][newy] = EL_EMPTY;
6007 DrawLevelField(newx, newy);
6008 PlayLevelSound(x, y, SND_PACMAN_DIGGING);
6011 else if (element == EL_MOLE && IN_LEV_FIELD(newx, newy) &&
6012 (Feld[newx][newy] == EL_AMOEBA_SHRINKING ||
6013 (Feld[newx][newy] == EL_EMPTY && Stop[newx][newy])))
6015 /* wait for shrinking amoeba to completely disappear */
6018 else if (!IN_LEV_FIELD(newx, newy) || !IS_FREE(newx, newy))
6020 /* object was running against a wall */
6025 if (move_pattern & MV_ANY_DIRECTION &&
6026 move_pattern == MovDir[x][y])
6028 int blocking_element =
6029 (IN_LEV_FIELD(newx, newy) ? Feld[newx][newy] : BorderElement);
6032 printf("::: '%s' is blocked by '%s'! [%d,%d -> %d,%d]\n",
6033 element_info[element].token_name,
6034 element_info[blocking_element].token_name,
6038 CheckElementChangeBySide(x, y, element, blocking_element, CE_BLOCKED,
6041 element = Feld[x][y]; /* element might have changed */
6046 if (GFX_ELEMENT(element) != EL_SAND) /* !!! FIX THIS (crumble) !!! */
6047 DrawLevelElementAnimation(x, y, element);
6049 if (element == EL_BUG ||
6050 element == EL_SPACESHIP ||
6051 element == EL_SP_SNIKSNAK)
6052 DrawLevelField(x, y);
6053 else if (element == EL_MOLE)
6054 DrawLevelField(x, y);
6055 else if (element == EL_BD_BUTTERFLY ||
6056 element == EL_BD_FIREFLY)
6057 DrawLevelElementAnimationIfNeeded(x, y, element);
6058 else if (element == EL_SATELLITE)
6059 DrawLevelElementAnimationIfNeeded(x, y, element);
6060 else if (element == EL_SP_ELECTRON)
6061 DrawLevelElementAnimationIfNeeded(x, y, element);
6064 if (DONT_TOUCH(element))
6065 TestIfBadThingTouchesHero(x, y);
6068 PlayLevelSoundAction(x, y, ACTION_WAITING);
6074 InitMovingField(x, y, MovDir[x][y]);
6076 PlayLevelSoundAction(x, y, ACTION_MOVING);
6080 ContinueMoving(x, y);
6083 void ContinueMoving(int x, int y)
6085 int element = Feld[x][y];
6086 int stored = Store[x][y];
6087 struct ElementInfo *ei = &element_info[element];
6088 int direction = MovDir[x][y];
6089 int dx = (direction == MV_LEFT ? -1 : direction == MV_RIGHT ? +1 : 0);
6090 int dy = (direction == MV_UP ? -1 : direction == MV_DOWN ? +1 : 0);
6091 int newx = x + dx, newy = y + dy;
6093 int nextx = newx + dx, nexty = newy + dy;
6096 boolean pushed_by_player = (Pushed[x][y] && IS_PLAYER(x, y));
6097 boolean pushed_by_conveyor = (Pushed[x][y] && !IS_PLAYER(x, y));
6099 boolean pushed_by_player = Pushed[x][y];
6102 MovPos[x][y] += getElementMoveStepsize(x, y);
6105 if (pushed_by_player && IS_PLAYER(x, y))
6107 /* special case: moving object pushed by player */
6108 MovPos[x][y] = SIGN(MovPos[x][y]) * (TILEX - ABS(PLAYERINFO(x,y)->MovPos));
6111 if (pushed_by_player) /* special case: moving object pushed by player */
6112 MovPos[x][y] = SIGN(MovPos[x][y]) * (TILEX - ABS(PLAYERINFO(x,y)->MovPos));
6115 if (ABS(MovPos[x][y]) < TILEX)
6117 DrawLevelField(x, y);
6119 return; /* element is still moving */
6122 /* element reached destination field */
6124 Feld[x][y] = EL_EMPTY;
6125 Feld[newx][newy] = element;
6126 MovPos[x][y] = 0; /* force "not moving" for "crumbled sand" */
6129 if (Store[x][y] == EL_ACID) /* element is moving into acid pool */
6131 element = Feld[newx][newy] = EL_ACID;
6134 else if (element == EL_MOLE)
6136 Feld[x][y] = EL_SAND;
6138 DrawLevelFieldCrumbledSandNeighbours(x, y);
6140 else if (element == EL_QUICKSAND_FILLING)
6142 element = Feld[newx][newy] = get_next_element(element);
6143 Store[newx][newy] = Store[x][y];
6145 else if (element == EL_QUICKSAND_EMPTYING)
6147 Feld[x][y] = get_next_element(element);
6148 element = Feld[newx][newy] = Store[x][y];
6150 else if (element == EL_MAGIC_WALL_FILLING)
6152 element = Feld[newx][newy] = get_next_element(element);
6153 if (!game.magic_wall_active)
6154 element = Feld[newx][newy] = EL_MAGIC_WALL_DEAD;
6155 Store[newx][newy] = Store[x][y];
6157 else if (element == EL_MAGIC_WALL_EMPTYING)
6159 Feld[x][y] = get_next_element(element);
6160 if (!game.magic_wall_active)
6161 Feld[x][y] = EL_MAGIC_WALL_DEAD;
6162 element = Feld[newx][newy] = Store[x][y];
6164 else if (element == EL_BD_MAGIC_WALL_FILLING)
6166 element = Feld[newx][newy] = get_next_element(element);
6167 if (!game.magic_wall_active)
6168 element = Feld[newx][newy] = EL_BD_MAGIC_WALL_DEAD;
6169 Store[newx][newy] = Store[x][y];
6171 else if (element == EL_BD_MAGIC_WALL_EMPTYING)
6173 Feld[x][y] = get_next_element(element);
6174 if (!game.magic_wall_active)
6175 Feld[x][y] = EL_BD_MAGIC_WALL_DEAD;
6176 element = Feld[newx][newy] = Store[x][y];
6178 else if (element == EL_AMOEBA_DROPPING)
6180 Feld[x][y] = get_next_element(element);
6181 element = Feld[newx][newy] = Store[x][y];
6183 else if (element == EL_SOKOBAN_OBJECT)
6186 Feld[x][y] = Back[x][y];
6188 if (Back[newx][newy])
6189 Feld[newx][newy] = EL_SOKOBAN_FIELD_FULL;
6191 Back[x][y] = Back[newx][newy] = 0;
6194 else if (Store[x][y] == EL_ACID)
6196 element = Feld[newx][newy] = EL_ACID;
6200 else if (IS_CUSTOM_ELEMENT(element) && !IS_PLAYER(x, y) &&
6201 ei->move_leave_element != EL_EMPTY &&
6202 (ei->move_leave_type == LEAVE_TYPE_UNLIMITED ||
6203 Store[x][y] != EL_EMPTY))
6205 /* some elements can leave other elements behind after moving */
6207 Feld[x][y] = ei->move_leave_element;
6208 InitField(x, y, FALSE);
6210 if (GFX_CRUMBLED(Feld[x][y]))
6211 DrawLevelFieldCrumbledSandNeighbours(x, y);
6215 Store[x][y] = EL_EMPTY;
6216 MovPos[x][y] = MovDir[x][y] = MovDelay[x][y] = 0;
6217 MovDelay[newx][newy] = 0;
6219 if (CAN_CHANGE(element))
6221 /* copy element change control values to new field */
6222 ChangeDelay[newx][newy] = ChangeDelay[x][y];
6223 ChangePage[newx][newy] = ChangePage[x][y];
6224 Changed[newx][newy] = Changed[x][y];
6225 ChangeEvent[newx][newy] = ChangeEvent[x][y];
6228 ChangeDelay[x][y] = 0;
6229 ChangePage[x][y] = -1;
6230 Changed[x][y] = CE_BITMASK_DEFAULT;
6231 ChangeEvent[x][y] = CE_BITMASK_DEFAULT;
6233 /* copy animation control values to new field */
6234 GfxFrame[newx][newy] = GfxFrame[x][y];
6235 GfxRandom[newx][newy] = GfxRandom[x][y]; /* keep same random value */
6236 GfxAction[newx][newy] = GfxAction[x][y]; /* keep action one frame */
6237 GfxDir[newx][newy] = GfxDir[x][y]; /* keep element direction */
6239 Pushed[x][y] = Pushed[newx][newy] = FALSE;
6241 ResetGfxAnimation(x, y); /* reset animation values for old field */
6244 /* some elements can leave other elements behind after moving */
6246 if (IS_CUSTOM_ELEMENT(element) && ei->move_leave_element != EL_EMPTY &&
6247 (ei->move_leave_type == LEAVE_TYPE_UNLIMITED || stored != EL_EMPTY) &&
6248 (!IS_PLAYER(x, y) || IS_WALKABLE(ei->move_leave_element)))
6250 if (IS_CUSTOM_ELEMENT(element) && ei->move_leave_element != EL_EMPTY &&
6251 (ei->move_leave_type == LEAVE_TYPE_UNLIMITED || stored != EL_EMPTY) &&
6255 int move_leave_element = ei->move_leave_element;
6257 Feld[x][y] = move_leave_element;
6258 InitField(x, y, FALSE);
6260 if (GFX_CRUMBLED(Feld[x][y]))
6261 DrawLevelFieldCrumbledSandNeighbours(x, y);
6263 if (ELEM_IS_PLAYER(move_leave_element))
6264 RelocatePlayer(x, y, move_leave_element);
6269 /* some elements can leave other elements behind after moving */
6270 if (IS_CUSTOM_ELEMENT(element) && !IS_PLAYER(x, y) &&
6271 ei->move_leave_element != EL_EMPTY &&
6272 (ei->move_leave_type == LEAVE_TYPE_UNLIMITED ||
6273 ei->can_leave_element_last))
6275 Feld[x][y] = ei->move_leave_element;
6276 InitField(x, y, FALSE);
6278 if (GFX_CRUMBLED(Feld[x][y]))
6279 DrawLevelFieldCrumbledSandNeighbours(x, y);
6282 ei->can_leave_element_last = ei->can_leave_element;
6283 ei->can_leave_element = FALSE;
6287 /* 2.1.1 (does not work correctly for spring) */
6288 if (!CAN_MOVE(element))
6289 MovDir[newx][newy] = 0;
6293 /* (does not work for falling objects that slide horizontally) */
6294 if (CAN_FALL(element) && MovDir[newx][newy] == MV_DOWN)
6295 MovDir[newx][newy] = 0;
6298 if (!CAN_MOVE(element) ||
6299 (element == EL_SPRING && MovDir[newx][newy] == MV_DOWN))
6300 MovDir[newx][newy] = 0;
6304 if (!CAN_MOVE(element) ||
6305 (CAN_FALL(element) && direction == MV_DOWN))
6306 GfxDir[x][y] = MovDir[newx][newy] = 0;
6308 if (!CAN_MOVE(element) ||
6309 (CAN_FALL(element) && direction == MV_DOWN &&
6310 (element == EL_SPRING ||
6311 element_info[element].move_pattern == MV_WHEN_PUSHED ||
6312 element_info[element].move_pattern == MV_WHEN_DROPPED)))
6313 GfxDir[x][y] = MovDir[newx][newy] = 0;
6319 DrawLevelField(x, y);
6320 DrawLevelField(newx, newy);
6322 Stop[newx][newy] = TRUE; /* ignore this element until the next frame */
6324 /* prevent pushed element from moving on in pushed direction */
6325 if (pushed_by_player && CAN_MOVE(element) &&
6326 element_info[element].move_pattern & MV_ANY_DIRECTION &&
6327 !(element_info[element].move_pattern & direction))
6328 TurnRound(newx, newy);
6331 /* prevent elements on conveyor belt from moving on in last direction */
6332 if (pushed_by_conveyor && CAN_FALL(element) &&
6333 direction & MV_HORIZONTAL)
6336 if (CAN_MOVE(element))
6337 InitMovDir(newx, newy);
6339 MovDir[newx][newy] = 0;
6341 MovDir[newx][newy] = 0;
6346 if (!pushed_by_player)
6348 int nextx = newx + dx, nexty = newy + dy;
6349 boolean check_collision_again = IN_LEV_FIELD_AND_IS_FREE(nextx, nexty);
6351 WasJustMoving[newx][newy] = 3;
6353 if (CAN_FALL(element) && direction == MV_DOWN)
6354 WasJustFalling[newx][newy] = 3;
6356 if ((!CAN_FALL(element) || direction == MV_DOWN) && check_collision_again)
6357 CheckCollision[newx][newy] = 2;
6360 if (DONT_TOUCH(element)) /* object may be nasty to player or others */
6362 TestIfBadThingTouchesHero(newx, newy);
6363 TestIfBadThingTouchesFriend(newx, newy);
6365 if (!IS_CUSTOM_ELEMENT(element))
6366 TestIfBadThingTouchesOtherBadThing(newx, newy);
6368 else if (element == EL_PENGUIN)
6369 TestIfFriendTouchesBadThing(newx, newy);
6371 if (CAN_FALL(element) && direction == MV_DOWN &&
6372 (newy == lev_fieldy - 1 || !IS_FREE(x, newy + 1)))
6376 if (pushed_by_player)
6379 int dig_side = MV_DIR_OPPOSITE(direction);
6381 static int trigger_sides[4] =
6383 CH_SIDE_RIGHT, /* moving left */
6384 CH_SIDE_LEFT, /* moving right */
6385 CH_SIDE_BOTTOM, /* moving up */
6386 CH_SIDE_TOP, /* moving down */
6388 int dig_side = trigger_sides[MV_DIR_BIT(direction)];
6390 struct PlayerInfo *player = PLAYERINFO(x, y);
6392 CheckElementChangeByPlayer(newx, newy, element, CE_PUSHED_BY_PLAYER,
6393 player->index_bit, dig_side);
6394 CheckTriggeredElementChangeByPlayer(newx,newy,element,CE_OTHER_GETS_PUSHED,
6395 player->index_bit, dig_side);
6400 TestIfElementTouchesCustomElement(x, y); /* empty or new element */
6404 if (ChangePage[newx][newy] != -1) /* delayed change */
6405 ChangeElement(newx, newy, ChangePage[newx][newy]);
6410 TestIfElementHitsCustomElement(newx, newy, direction);
6414 if (!IN_LEV_FIELD(nextx, nexty) || !IS_FREE(nextx, nexty))
6416 int hitting_element = Feld[newx][newy];
6418 /* !!! fix side (direction) orientation here and elsewhere !!! */
6419 CheckElementChangeBySide(newx, newy, hitting_element, CE_HITTING_SOMETHING,
6423 if (IN_LEV_FIELD(nextx, nexty))
6425 int opposite_direction = MV_DIR_OPPOSITE(direction);
6426 int hitting_side = direction;
6427 int touched_side = opposite_direction;
6428 int touched_element = MovingOrBlocked2Element(nextx, nexty);
6429 boolean object_hit = (!IS_MOVING(nextx, nexty) ||
6430 MovDir[nextx][nexty] != direction ||
6431 ABS(MovPos[nextx][nexty]) <= TILEY / 2);
6437 CheckElementChangeBySide(nextx, nexty, touched_element,
6438 CE_HIT_BY_SOMETHING, opposite_direction);
6440 if (IS_CUSTOM_ELEMENT(hitting_element) &&
6441 HAS_ANY_CHANGE_EVENT(hitting_element, CE_OTHER_IS_HITTING))
6443 for (i = 0; i < element_info[hitting_element].num_change_pages; i++)
6445 struct ElementChangeInfo *change =
6446 &element_info[hitting_element].change_page[i];
6448 if (change->can_change &&
6449 change->events & CH_EVENT_BIT(CE_OTHER_IS_HITTING) &&
6450 change->trigger_side & touched_side &&
6451 change->trigger_element == touched_element)
6453 CheckElementChangeByPage(newx, newy, hitting_element,
6454 touched_element, CE_OTHER_IS_HITTING,i);
6460 if (IS_CUSTOM_ELEMENT(touched_element) &&
6461 HAS_ANY_CHANGE_EVENT(touched_element, CE_OTHER_GETS_HIT))
6463 for (i = 0; i < element_info[touched_element].num_change_pages; i++)
6465 struct ElementChangeInfo *change =
6466 &element_info[touched_element].change_page[i];
6468 if (change->can_change &&
6469 change->events & CH_EVENT_BIT(CE_OTHER_GETS_HIT) &&
6470 change->trigger_side & hitting_side &&
6471 change->trigger_element == hitting_element)
6473 CheckElementChangeByPage(nextx, nexty, touched_element,
6474 hitting_element, CE_OTHER_GETS_HIT, i);
6485 TestIfPlayerTouchesCustomElement(newx, newy);
6486 TestIfElementTouchesCustomElement(newx, newy);
6489 int AmoebeNachbarNr(int ax, int ay)
6492 int element = Feld[ax][ay];
6494 static int xy[4][2] =
6502 for (i = 0; i < NUM_DIRECTIONS; i++)
6504 int x = ax + xy[i][0];
6505 int y = ay + xy[i][1];
6507 if (!IN_LEV_FIELD(x, y))
6510 if (Feld[x][y] == element && AmoebaNr[x][y] > 0)
6511 group_nr = AmoebaNr[x][y];
6517 void AmoebenVereinigen(int ax, int ay)
6519 int i, x, y, xx, yy;
6520 int new_group_nr = AmoebaNr[ax][ay];
6521 static int xy[4][2] =
6529 if (new_group_nr == 0)
6532 for (i = 0; i < NUM_DIRECTIONS; i++)
6537 if (!IN_LEV_FIELD(x, y))
6540 if ((Feld[x][y] == EL_AMOEBA_FULL ||
6541 Feld[x][y] == EL_BD_AMOEBA ||
6542 Feld[x][y] == EL_AMOEBA_DEAD) &&
6543 AmoebaNr[x][y] != new_group_nr)
6545 int old_group_nr = AmoebaNr[x][y];
6547 if (old_group_nr == 0)
6550 AmoebaCnt[new_group_nr] += AmoebaCnt[old_group_nr];
6551 AmoebaCnt[old_group_nr] = 0;
6552 AmoebaCnt2[new_group_nr] += AmoebaCnt2[old_group_nr];
6553 AmoebaCnt2[old_group_nr] = 0;
6555 for (yy = 0; yy < lev_fieldy; yy++)
6557 for (xx = 0; xx < lev_fieldx; xx++)
6559 if (AmoebaNr[xx][yy] == old_group_nr)
6560 AmoebaNr[xx][yy] = new_group_nr;
6567 void AmoebeUmwandeln(int ax, int ay)
6571 if (Feld[ax][ay] == EL_AMOEBA_DEAD)
6573 int group_nr = AmoebaNr[ax][ay];
6578 printf("AmoebeUmwandeln(): ax = %d, ay = %d\n", ax, ay);
6579 printf("AmoebeUmwandeln(): This should never happen!\n");
6584 for (y = 0; y < lev_fieldy; y++)
6586 for (x = 0; x < lev_fieldx; x++)
6588 if (Feld[x][y] == EL_AMOEBA_DEAD && AmoebaNr[x][y] == group_nr)
6591 Feld[x][y] = EL_AMOEBA_TO_DIAMOND;
6595 PlayLevelSound(ax, ay, (IS_GEM(level.amoeba_content) ?
6596 SND_AMOEBA_TURNING_TO_GEM :
6597 SND_AMOEBA_TURNING_TO_ROCK));
6602 static int xy[4][2] =
6610 for (i = 0; i < NUM_DIRECTIONS; i++)
6615 if (!IN_LEV_FIELD(x, y))
6618 if (Feld[x][y] == EL_AMOEBA_TO_DIAMOND)
6620 PlayLevelSound(x, y, (IS_GEM(level.amoeba_content) ?
6621 SND_AMOEBA_TURNING_TO_GEM :
6622 SND_AMOEBA_TURNING_TO_ROCK));
6629 void AmoebeUmwandelnBD(int ax, int ay, int new_element)
6632 int group_nr = AmoebaNr[ax][ay];
6633 boolean done = FALSE;
6638 printf("AmoebeUmwandelnBD(): ax = %d, ay = %d\n", ax, ay);
6639 printf("AmoebeUmwandelnBD(): This should never happen!\n");
6644 for (y = 0; y < lev_fieldy; y++)
6646 for (x = 0; x < lev_fieldx; x++)
6648 if (AmoebaNr[x][y] == group_nr &&
6649 (Feld[x][y] == EL_AMOEBA_DEAD ||
6650 Feld[x][y] == EL_BD_AMOEBA ||
6651 Feld[x][y] == EL_AMOEBA_GROWING))
6654 Feld[x][y] = new_element;
6655 InitField(x, y, FALSE);
6656 DrawLevelField(x, y);
6663 PlayLevelSound(ax, ay, (new_element == EL_BD_ROCK ?
6664 SND_BD_AMOEBA_TURNING_TO_ROCK :
6665 SND_BD_AMOEBA_TURNING_TO_GEM));
6668 void AmoebeWaechst(int x, int y)
6670 static unsigned long sound_delay = 0;
6671 static unsigned long sound_delay_value = 0;
6673 if (!MovDelay[x][y]) /* start new growing cycle */
6677 if (DelayReached(&sound_delay, sound_delay_value))
6680 PlayLevelSoundElementAction(x, y, Store[x][y], ACTION_GROWING);
6682 if (Store[x][y] == EL_BD_AMOEBA)
6683 PlayLevelSound(x, y, SND_BD_AMOEBA_GROWING);
6685 PlayLevelSound(x, y, SND_AMOEBA_GROWING);
6687 sound_delay_value = 30;
6691 if (MovDelay[x][y]) /* wait some time before growing bigger */
6694 if (MovDelay[x][y]/2 && IN_SCR_FIELD(SCREENX(x), SCREENY(y)))
6696 int frame = getGraphicAnimationFrame(IMG_AMOEBA_GROWING,
6697 6 - MovDelay[x][y]);
6699 DrawGraphic(SCREENX(x), SCREENY(y), IMG_AMOEBA_GROWING, frame);
6702 if (!MovDelay[x][y])
6704 Feld[x][y] = Store[x][y];
6706 DrawLevelField(x, y);
6711 void AmoebaDisappearing(int x, int y)
6713 static unsigned long sound_delay = 0;
6714 static unsigned long sound_delay_value = 0;
6716 if (!MovDelay[x][y]) /* start new shrinking cycle */
6720 if (DelayReached(&sound_delay, sound_delay_value))
6721 sound_delay_value = 30;
6724 if (MovDelay[x][y]) /* wait some time before shrinking */
6727 if (MovDelay[x][y]/2 && IN_SCR_FIELD(SCREENX(x), SCREENY(y)))
6729 int frame = getGraphicAnimationFrame(IMG_AMOEBA_SHRINKING,
6730 6 - MovDelay[x][y]);
6732 DrawGraphic(SCREENX(x), SCREENY(y), IMG_AMOEBA_SHRINKING, frame);
6735 if (!MovDelay[x][y])
6737 Feld[x][y] = EL_EMPTY;
6738 DrawLevelField(x, y);
6740 /* don't let mole enter this field in this cycle;
6741 (give priority to objects falling to this field from above) */
6747 void AmoebeAbleger(int ax, int ay)
6750 int element = Feld[ax][ay];
6751 int graphic = el2img(element);
6752 int newax = ax, neway = ay;
6753 static int xy[4][2] =
6761 if (!level.amoeba_speed)
6763 Feld[ax][ay] = EL_AMOEBA_DEAD;
6764 DrawLevelField(ax, ay);
6768 if (IS_ANIMATED(graphic))
6769 DrawLevelGraphicAnimationIfNeeded(ax, ay, graphic);
6771 if (!MovDelay[ax][ay]) /* start making new amoeba field */
6772 MovDelay[ax][ay] = RND(FRAMES_PER_SECOND * 25 / (1 + level.amoeba_speed));
6774 if (MovDelay[ax][ay]) /* wait some time before making new amoeba */
6777 if (MovDelay[ax][ay])
6781 if (element == EL_AMOEBA_WET) /* object is an acid / amoeba drop */
6784 int x = ax + xy[start][0];
6785 int y = ay + xy[start][1];
6787 if (!IN_LEV_FIELD(x, y))
6791 if (IS_FREE(x, y) ||
6792 CAN_GROW_INTO(Feld[x][y]) ||
6793 Feld[x][y] == EL_QUICKSAND_EMPTY)
6799 /* !!! extend EL_SAND to anything diggable (but maybe not SP_BASE) !!! */
6800 if (IS_FREE(x, y) ||
6801 Feld[x][y] == EL_SAND || Feld[x][y] == EL_QUICKSAND_EMPTY)
6808 if (newax == ax && neway == ay)
6811 else /* normal or "filled" (BD style) amoeba */
6814 boolean waiting_for_player = FALSE;
6816 for (i = 0; i < NUM_DIRECTIONS; i++)
6818 int j = (start + i) % 4;
6819 int x = ax + xy[j][0];
6820 int y = ay + xy[j][1];
6822 if (!IN_LEV_FIELD(x, y))
6826 if (IS_FREE(x, y) ||
6827 CAN_GROW_INTO(Feld[x][y]) ||
6828 Feld[x][y] == EL_QUICKSAND_EMPTY)
6835 /* !!! extend EL_SAND to anything diggable (but maybe not SP_BASE) !!! */
6836 if (IS_FREE(x, y) ||
6837 Feld[x][y] == EL_SAND || Feld[x][y] == EL_QUICKSAND_EMPTY)
6844 else if (IS_PLAYER(x, y))
6845 waiting_for_player = TRUE;
6848 if (newax == ax && neway == ay) /* amoeba cannot grow */
6851 if (i == 4 && (!waiting_for_player || element == EL_BD_AMOEBA))
6853 if (i == 4 && (!waiting_for_player || game.emulation == EMU_BOULDERDASH))
6856 Feld[ax][ay] = EL_AMOEBA_DEAD;
6857 DrawLevelField(ax, ay);
6858 AmoebaCnt[AmoebaNr[ax][ay]]--;
6860 if (AmoebaCnt[AmoebaNr[ax][ay]] <= 0) /* amoeba is completely dead */
6862 if (element == EL_AMOEBA_FULL)
6863 AmoebeUmwandeln(ax, ay);
6864 else if (element == EL_BD_AMOEBA)
6865 AmoebeUmwandelnBD(ax, ay, level.amoeba_content);
6870 else if (element == EL_AMOEBA_FULL || element == EL_BD_AMOEBA)
6872 /* amoeba gets larger by growing in some direction */
6874 int new_group_nr = AmoebaNr[ax][ay];
6877 if (new_group_nr == 0)
6879 printf("AmoebeAbleger(): newax = %d, neway = %d\n", newax, neway);
6880 printf("AmoebeAbleger(): This should never happen!\n");
6885 AmoebaNr[newax][neway] = new_group_nr;
6886 AmoebaCnt[new_group_nr]++;
6887 AmoebaCnt2[new_group_nr]++;
6889 /* if amoeba touches other amoeba(s) after growing, unify them */
6890 AmoebenVereinigen(newax, neway);
6892 if (element == EL_BD_AMOEBA && AmoebaCnt2[new_group_nr] >= 200)
6894 AmoebeUmwandelnBD(newax, neway, EL_BD_ROCK);
6900 if (element != EL_AMOEBA_WET || neway < ay || !IS_FREE(newax, neway) ||
6901 (neway == lev_fieldy - 1 && newax != ax))
6903 Feld[newax][neway] = EL_AMOEBA_GROWING; /* creation of new amoeba */
6904 Store[newax][neway] = element;
6906 else if (neway == ay)
6908 Feld[newax][neway] = EL_AMOEBA_DROP; /* drop left/right of amoeba */
6910 PlayLevelSoundAction(newax, neway, ACTION_GROWING);
6912 PlayLevelSound(newax, neway, SND_AMOEBA_GROWING);
6917 InitMovingField(ax, ay, MV_DOWN); /* drop dripping from amoeba */
6918 Feld[ax][ay] = EL_AMOEBA_DROPPING;
6919 Store[ax][ay] = EL_AMOEBA_DROP;
6920 ContinueMoving(ax, ay);
6924 DrawLevelField(newax, neway);
6927 void Life(int ax, int ay)
6930 static int life[4] = { 2, 3, 3, 3 }; /* parameters for "game of life" */
6932 int element = Feld[ax][ay];
6933 int graphic = el2img(element);
6934 boolean changed = FALSE;
6936 if (IS_ANIMATED(graphic))
6937 DrawLevelGraphicAnimationIfNeeded(ax, ay, graphic);
6942 if (!MovDelay[ax][ay]) /* start new "game of life" cycle */
6943 MovDelay[ax][ay] = life_time;
6945 if (MovDelay[ax][ay]) /* wait some time before next cycle */
6948 if (MovDelay[ax][ay])
6952 for (y1 = -1; y1 < 2; y1++) for (x1 = -1; x1 < 2; x1++)
6954 int xx = ax+x1, yy = ay+y1;
6957 if (!IN_LEV_FIELD(xx, yy))
6960 for (y2 = -1; y2 < 2; y2++) for (x2 = -1; x2 < 2; x2++)
6962 int x = xx+x2, y = yy+y2;
6964 if (!IN_LEV_FIELD(x, y) || (x == xx && y == yy))
6967 if (((Feld[x][y] == element ||
6968 (element == EL_GAME_OF_LIFE && IS_PLAYER(x, y))) &&
6970 (IS_FREE(x, y) && Stop[x][y]))
6974 if (xx == ax && yy == ay) /* field in the middle */
6976 if (nachbarn < life[0] || nachbarn > life[1])
6978 Feld[xx][yy] = EL_EMPTY;
6980 DrawLevelField(xx, yy);
6981 Stop[xx][yy] = TRUE;
6986 else if (IS_FREE(xx, yy) || CAN_GROW_INTO(Feld[xx][yy]))
6987 { /* free border field */
6988 if (nachbarn >= life[2] && nachbarn <= life[3])
6990 Feld[xx][yy] = element;
6991 MovDelay[xx][yy] = (element == EL_GAME_OF_LIFE ? 0 : life_time-1);
6993 DrawLevelField(xx, yy);
6994 Stop[xx][yy] = TRUE;
6999 /* !!! extend EL_SAND to anything diggable (but maybe not SP_BASE) !!! */
7000 else if (IS_FREE(xx, yy) || Feld[xx][yy] == EL_SAND)
7001 { /* free border field */
7002 if (nachbarn >= life[2] && nachbarn <= life[3])
7004 Feld[xx][yy] = element;
7005 MovDelay[xx][yy] = (element == EL_GAME_OF_LIFE ? 0 : life_time-1);
7007 DrawLevelField(xx, yy);
7008 Stop[xx][yy] = TRUE;
7016 PlayLevelSound(ax, ay, element == EL_BIOMAZE ? SND_BIOMAZE_GROWING :
7017 SND_GAME_OF_LIFE_GROWING);
7020 static void InitRobotWheel(int x, int y)
7022 ChangeDelay[x][y] = level.time_wheel * FRAMES_PER_SECOND;
7025 static void RunRobotWheel(int x, int y)
7027 PlayLevelSound(x, y, SND_ROBOT_WHEEL_ACTIVE);
7030 static void StopRobotWheel(int x, int y)
7032 if (ZX == x && ZY == y)
7036 static void InitTimegateWheel(int x, int y)
7039 ChangeDelay[x][y] = level.time_timegate * FRAMES_PER_SECOND;
7041 /* another brainless, "type style" bug ... :-( */
7042 ChangeDelay[x][y] = level.time_wheel * FRAMES_PER_SECOND;
7046 static void RunTimegateWheel(int x, int y)
7048 PlayLevelSound(x, y, SND_TIMEGATE_SWITCH_ACTIVE);
7051 void CheckExit(int x, int y)
7053 if (local_player->gems_still_needed > 0 ||
7054 local_player->sokobanfields_still_needed > 0 ||
7055 local_player->lights_still_needed > 0)
7057 int element = Feld[x][y];
7058 int graphic = el2img(element);
7060 if (IS_ANIMATED(graphic))
7061 DrawLevelGraphicAnimationIfNeeded(x, y, graphic);
7066 if (AllPlayersGone) /* do not re-open exit door closed after last player */
7069 Feld[x][y] = EL_EXIT_OPENING;
7071 PlayLevelSoundNearest(x, y, SND_CLASS_EXIT_OPENING);
7074 void CheckExitSP(int x, int y)
7076 if (local_player->gems_still_needed > 0)
7078 int element = Feld[x][y];
7079 int graphic = el2img(element);
7081 if (IS_ANIMATED(graphic))
7082 DrawLevelGraphicAnimationIfNeeded(x, y, graphic);
7087 if (AllPlayersGone) /* do not re-open exit door closed after last player */
7090 Feld[x][y] = EL_SP_EXIT_OPENING;
7092 PlayLevelSoundNearest(x, y, SND_CLASS_SP_EXIT_OPENING);
7095 static void CloseAllOpenTimegates()
7099 for (y = 0; y < lev_fieldy; y++)
7101 for (x = 0; x < lev_fieldx; x++)
7103 int element = Feld[x][y];
7105 if (element == EL_TIMEGATE_OPEN || element == EL_TIMEGATE_OPENING)
7107 Feld[x][y] = EL_TIMEGATE_CLOSING;
7109 PlayLevelSoundAction(x, y, ACTION_CLOSING);
7111 PlayLevelSound(x, y, SND_TIMEGATE_CLOSING);
7118 void EdelsteinFunkeln(int x, int y)
7120 if (!IN_SCR_FIELD(SCREENX(x), SCREENY(y)) || IS_MOVING(x, y))
7123 if (Feld[x][y] == EL_BD_DIAMOND)
7126 if (MovDelay[x][y] == 0) /* next animation frame */
7127 MovDelay[x][y] = 11 * !SimpleRND(500);
7129 if (MovDelay[x][y] != 0) /* wait some time before next frame */
7133 if (setup.direct_draw && MovDelay[x][y])
7134 SetDrawtoField(DRAW_BUFFERED);
7136 DrawLevelElementAnimation(x, y, Feld[x][y]);
7138 if (MovDelay[x][y] != 0)
7140 int frame = getGraphicAnimationFrame(IMG_TWINKLE_WHITE,
7141 10 - MovDelay[x][y]);
7143 DrawGraphicThruMask(SCREENX(x), SCREENY(y), IMG_TWINKLE_WHITE, frame);
7145 if (setup.direct_draw)
7149 dest_x = FX + SCREENX(x) * TILEX;
7150 dest_y = FY + SCREENY(y) * TILEY;
7152 BlitBitmap(drawto_field, window,
7153 dest_x, dest_y, TILEX, TILEY, dest_x, dest_y);
7154 SetDrawtoField(DRAW_DIRECT);
7160 void MauerWaechst(int x, int y)
7164 if (!MovDelay[x][y]) /* next animation frame */
7165 MovDelay[x][y] = 3 * delay;
7167 if (MovDelay[x][y]) /* wait some time before next frame */
7171 if (IN_SCR_FIELD(SCREENX(x), SCREENY(y)))
7173 int graphic = el_dir2img(Feld[x][y], GfxDir[x][y]);
7174 int frame = getGraphicAnimationFrame(graphic, 17 - MovDelay[x][y]);
7176 DrawGraphic(SCREENX(x), SCREENY(y), graphic, frame);
7179 if (!MovDelay[x][y])
7181 if (MovDir[x][y] == MV_LEFT)
7183 if (IN_LEV_FIELD(x - 1, y) && IS_WALL(Feld[x - 1][y]))
7184 DrawLevelField(x - 1, y);
7186 else if (MovDir[x][y] == MV_RIGHT)
7188 if (IN_LEV_FIELD(x + 1, y) && IS_WALL(Feld[x + 1][y]))
7189 DrawLevelField(x + 1, y);
7191 else if (MovDir[x][y] == MV_UP)
7193 if (IN_LEV_FIELD(x, y - 1) && IS_WALL(Feld[x][y - 1]))
7194 DrawLevelField(x, y - 1);
7198 if (IN_LEV_FIELD(x, y + 1) && IS_WALL(Feld[x][y + 1]))
7199 DrawLevelField(x, y + 1);
7202 Feld[x][y] = Store[x][y];
7204 GfxDir[x][y] = MovDir[x][y] = MV_NO_MOVING;
7205 DrawLevelField(x, y);
7210 void MauerAbleger(int ax, int ay)
7212 int element = Feld[ax][ay];
7213 int graphic = el2img(element);
7214 boolean oben_frei = FALSE, unten_frei = FALSE;
7215 boolean links_frei = FALSE, rechts_frei = FALSE;
7216 boolean oben_massiv = FALSE, unten_massiv = FALSE;
7217 boolean links_massiv = FALSE, rechts_massiv = FALSE;
7218 boolean new_wall = FALSE;
7220 if (IS_ANIMATED(graphic))
7221 DrawLevelGraphicAnimationIfNeeded(ax, ay, graphic);
7223 if (!MovDelay[ax][ay]) /* start building new wall */
7224 MovDelay[ax][ay] = 6;
7226 if (MovDelay[ax][ay]) /* wait some time before building new wall */
7229 if (MovDelay[ax][ay])
7233 if (IN_LEV_FIELD(ax, ay-1) && IS_FREE(ax, ay-1))
7235 if (IN_LEV_FIELD(ax, ay+1) && IS_FREE(ax, ay+1))
7237 if (IN_LEV_FIELD(ax-1, ay) && IS_FREE(ax-1, ay))
7239 if (IN_LEV_FIELD(ax+1, ay) && IS_FREE(ax+1, ay))
7242 if (element == EL_EXPANDABLE_WALL_VERTICAL ||
7243 element == EL_EXPANDABLE_WALL_ANY)
7247 Feld[ax][ay-1] = EL_EXPANDABLE_WALL_GROWING;
7248 Store[ax][ay-1] = element;
7249 GfxDir[ax][ay-1] = MovDir[ax][ay-1] = MV_UP;
7250 if (IN_SCR_FIELD(SCREENX(ax), SCREENY(ay-1)))
7251 DrawGraphic(SCREENX(ax), SCREENY(ay - 1),
7252 IMG_EXPANDABLE_WALL_GROWING_UP, 0);
7257 Feld[ax][ay+1] = EL_EXPANDABLE_WALL_GROWING;
7258 Store[ax][ay+1] = element;
7259 GfxDir[ax][ay+1] = MovDir[ax][ay+1] = MV_DOWN;
7260 if (IN_SCR_FIELD(SCREENX(ax), SCREENY(ay+1)))
7261 DrawGraphic(SCREENX(ax), SCREENY(ay + 1),
7262 IMG_EXPANDABLE_WALL_GROWING_DOWN, 0);
7267 if (element == EL_EXPANDABLE_WALL_HORIZONTAL ||
7268 element == EL_EXPANDABLE_WALL_ANY ||
7269 element == EL_EXPANDABLE_WALL)
7273 Feld[ax-1][ay] = EL_EXPANDABLE_WALL_GROWING;
7274 Store[ax-1][ay] = element;
7275 GfxDir[ax-1][ay] = MovDir[ax-1][ay] = MV_LEFT;
7276 if (IN_SCR_FIELD(SCREENX(ax-1), SCREENY(ay)))
7277 DrawGraphic(SCREENX(ax - 1), SCREENY(ay),
7278 IMG_EXPANDABLE_WALL_GROWING_LEFT, 0);
7284 Feld[ax+1][ay] = EL_EXPANDABLE_WALL_GROWING;
7285 Store[ax+1][ay] = element;
7286 GfxDir[ax+1][ay] = MovDir[ax+1][ay] = MV_RIGHT;
7287 if (IN_SCR_FIELD(SCREENX(ax+1), SCREENY(ay)))
7288 DrawGraphic(SCREENX(ax + 1), SCREENY(ay),
7289 IMG_EXPANDABLE_WALL_GROWING_RIGHT, 0);
7294 if (element == EL_EXPANDABLE_WALL && (links_frei || rechts_frei))
7295 DrawLevelField(ax, ay);
7297 if (!IN_LEV_FIELD(ax, ay-1) || IS_WALL(Feld[ax][ay-1]))
7299 if (!IN_LEV_FIELD(ax, ay+1) || IS_WALL(Feld[ax][ay+1]))
7300 unten_massiv = TRUE;
7301 if (!IN_LEV_FIELD(ax-1, ay) || IS_WALL(Feld[ax-1][ay]))
7302 links_massiv = TRUE;
7303 if (!IN_LEV_FIELD(ax+1, ay) || IS_WALL(Feld[ax+1][ay]))
7304 rechts_massiv = TRUE;
7306 if (((oben_massiv && unten_massiv) ||
7307 element == EL_EXPANDABLE_WALL_HORIZONTAL ||
7308 element == EL_EXPANDABLE_WALL) &&
7309 ((links_massiv && rechts_massiv) ||
7310 element == EL_EXPANDABLE_WALL_VERTICAL))
7311 Feld[ax][ay] = EL_WALL;
7315 PlayLevelSoundAction(ax, ay, ACTION_GROWING);
7317 PlayLevelSound(ax, ay, SND_EXPANDABLE_WALL_GROWING);
7321 void CheckForDragon(int x, int y)
7324 boolean dragon_found = FALSE;
7325 static int xy[4][2] =
7333 for (i = 0; i < NUM_DIRECTIONS; i++)
7335 for (j = 0; j < 4; j++)
7337 int xx = x + j * xy[i][0], yy = y + j * xy[i][1];
7339 if (IN_LEV_FIELD(xx, yy) &&
7340 (Feld[xx][yy] == EL_FLAMES || Feld[xx][yy] == EL_DRAGON))
7342 if (Feld[xx][yy] == EL_DRAGON)
7343 dragon_found = TRUE;
7352 for (i = 0; i < NUM_DIRECTIONS; i++)
7354 for (j = 0; j < 3; j++)
7356 int xx = x + j * xy[i][0], yy = y + j * xy[i][1];
7358 if (IN_LEV_FIELD(xx, yy) && Feld[xx][yy] == EL_FLAMES)
7360 Feld[xx][yy] = EL_EMPTY;
7361 DrawLevelField(xx, yy);
7370 static void InitBuggyBase(int x, int y)
7372 int element = Feld[x][y];
7373 int activating_delay = FRAMES_PER_SECOND / 4;
7376 (element == EL_SP_BUGGY_BASE ?
7377 2 * FRAMES_PER_SECOND + RND(5 * FRAMES_PER_SECOND) - activating_delay :
7378 element == EL_SP_BUGGY_BASE_ACTIVATING ?
7380 element == EL_SP_BUGGY_BASE_ACTIVE ?
7381 1 * FRAMES_PER_SECOND + RND(1 * FRAMES_PER_SECOND) : 1);
7384 static void WarnBuggyBase(int x, int y)
7387 static int xy[4][2] =
7395 for (i = 0; i < NUM_DIRECTIONS; i++)
7397 int xx = x + xy[i][0], yy = y + xy[i][1];
7399 if (IS_PLAYER(xx, yy))
7401 PlayLevelSound(x, y, SND_SP_BUGGY_BASE_ACTIVE);
7408 static void InitTrap(int x, int y)
7410 ChangeDelay[x][y] = 2 * FRAMES_PER_SECOND + RND(5 * FRAMES_PER_SECOND);
7413 static void ActivateTrap(int x, int y)
7415 PlayLevelSound(x, y, SND_TRAP_ACTIVATING);
7418 static void ChangeActiveTrap(int x, int y)
7420 int graphic = IMG_TRAP_ACTIVE;
7422 /* if new animation frame was drawn, correct crumbled sand border */
7423 if (IS_NEW_FRAME(GfxFrame[x][y], graphic))
7424 DrawLevelFieldCrumbledSand(x, y);
7427 static void ChangeElementNowExt(int x, int y, int target_element)
7429 int previous_move_direction = MovDir[x][y];
7431 boolean add_player = (ELEM_IS_PLAYER(target_element) &&
7432 IS_WALKABLE(Feld[x][y]));
7434 boolean add_player = (ELEM_IS_PLAYER(target_element) &&
7435 IS_WALKABLE(Feld[x][y]) &&
7439 /* check if element under player changes from accessible to unaccessible
7440 (needed for special case of dropping element which then changes) */
7441 if (IS_PLAYER(x, y) && !PLAYER_EXPLOSION_PROTECTED(x, y) &&
7442 IS_ACCESSIBLE(Feld[x][y]) && !IS_ACCESSIBLE(target_element))
7445 printf("::: BOOOM! [%d, '%s']\n", target_element,
7446 element_info[target_element].token_name);
7458 if (IS_MOVING(x, y) || IS_BLOCKED(x, y))
7459 RemoveMovingField(x, y);
7463 Feld[x][y] = target_element;
7466 Feld[x][y] = target_element;
7469 ResetGfxAnimation(x, y);
7470 ResetRandomAnimationValue(x, y);
7472 if (element_info[Feld[x][y]].move_direction_initial == MV_START_PREVIOUS)
7473 MovDir[x][y] = previous_move_direction;
7476 InitField_WithBug1(x, y, FALSE);
7478 InitField(x, y, FALSE);
7479 if (CAN_MOVE(Feld[x][y]))
7483 DrawLevelField(x, y);
7485 if (GFX_CRUMBLED(Feld[x][y]))
7486 DrawLevelFieldCrumbledSandNeighbours(x, y);
7490 Changed[x][y] |= ChangeEvent[x][y]; /* ignore same changes in this frame */
7494 TestIfBadThingTouchesHero(x, y);
7495 TestIfPlayerTouchesCustomElement(x, y);
7496 TestIfElementTouchesCustomElement(x, y);
7499 /* "Changed[][]" not set yet to allow "entered by player" change one time */
7500 if (ELEM_IS_PLAYER(target_element))
7501 RelocatePlayer(x, y, target_element);
7504 Changed[x][y] |= ChangeEvent[x][y]; /* ignore same changes in this frame */
7508 TestIfBadThingTouchesHero(x, y);
7509 TestIfPlayerTouchesCustomElement(x, y);
7510 TestIfElementTouchesCustomElement(x, y);
7514 static boolean ChangeElementNow(int x, int y, int element, int page)
7516 struct ElementChangeInfo *change = &element_info[element].change_page[page];
7518 int old_element = Feld[x][y];
7520 /* always use default change event to prevent running into a loop */
7521 if (ChangeEvent[x][y] == CE_BITMASK_DEFAULT)
7522 ChangeEvent[x][y] = CH_EVENT_BIT(CE_DELAY);
7524 if (ChangeEvent[x][y] == CH_EVENT_BIT(CE_DELAY))
7526 /* reset actual trigger element and player */
7527 change->actual_trigger_element = EL_EMPTY;
7528 change->actual_trigger_player = EL_PLAYER_1;
7531 /* do not change already changed elements with same change event */
7533 if (Changed[x][y] & ChangeEvent[x][y])
7540 Changed[x][y] |= ChangeEvent[x][y]; /* ignore same changes in this frame */
7543 /* !!! indirect change before direct change !!! */
7544 CheckTriggeredElementChangeByPage(x,y,Feld[x][y], CE_OTHER_IS_CHANGING,page);
7547 if (change->explode)
7554 if (change->use_target_content)
7556 boolean complete_replace = TRUE;
7557 boolean can_replace[3][3];
7560 for (yy = 0; yy < 3; yy++) for (xx = 0; xx < 3 ; xx++)
7563 boolean is_walkable;
7564 boolean is_diggable;
7565 boolean is_collectible;
7566 boolean is_removable;
7567 boolean is_destructible;
7568 int ex = x + xx - 1;
7569 int ey = y + yy - 1;
7570 int content_element = change->target_content[xx][yy];
7573 can_replace[xx][yy] = TRUE;
7575 if (ex == x && ey == y) /* do not check changing element itself */
7578 if (content_element == EL_EMPTY_SPACE)
7580 can_replace[xx][yy] = FALSE; /* do not replace border with space */
7585 if (!IN_LEV_FIELD(ex, ey))
7587 can_replace[xx][yy] = FALSE;
7588 complete_replace = FALSE;
7594 if (Changed[ex][ey]) /* do not change already changed elements */
7596 can_replace[xx][yy] = FALSE;
7597 complete_replace = FALSE;
7605 if (IS_MOVING(ex, ey) || IS_BLOCKED(ex, ey))
7606 e = MovingOrBlocked2Element(ex, ey);
7611 is_empty = (IS_FREE(ex, ey) ||
7612 (IS_PLAYER(ex, ey) && IS_WALKABLE(content_element)) ||
7613 (IS_WALKABLE(e) && ELEM_IS_PLAYER(content_element) &&
7614 !IS_MOVING(ex, ey) && !IS_BLOCKED(ex, ey)));
7618 is_empty = (IS_FREE(ex, ey) ||
7619 (IS_PLAYER(ex, ey) && IS_WALKABLE(content_element)));
7621 is_empty = (IS_FREE(ex, ey) ||
7622 (IS_FREE_OR_PLAYER(ex, ey) && IS_WALKABLE(content_element)));
7627 is_walkable = (is_empty || IS_WALKABLE(e));
7628 is_diggable = (is_empty || IS_DIGGABLE(e));
7629 is_collectible = (is_empty || IS_COLLECTIBLE(e));
7630 is_destructible = (is_empty || !IS_INDESTRUCTIBLE(e));
7631 is_removable = (is_diggable || is_collectible);
7633 can_replace[xx][yy] =
7634 (((change->replace_when == CP_WHEN_EMPTY && is_empty) ||
7635 (change->replace_when == CP_WHEN_WALKABLE && is_walkable) ||
7636 (change->replace_when == CP_WHEN_DIGGABLE && is_diggable) ||
7637 (change->replace_when == CP_WHEN_COLLECTIBLE && is_collectible) ||
7638 (change->replace_when == CP_WHEN_REMOVABLE && is_removable) ||
7639 (change->replace_when == CP_WHEN_DESTRUCTIBLE && is_destructible)) &&
7640 !(IS_PLAYER(ex, ey) && ELEM_IS_PLAYER(content_element)));
7642 if (!can_replace[xx][yy])
7643 complete_replace = FALSE;
7645 empty_for_element = (IS_FREE(ex, ey) || (IS_FREE_OR_PLAYER(ex, ey) &&
7646 IS_WALKABLE(content_element)));
7648 half_destructible = (empty_for_element || IS_DIGGABLE(e));
7650 half_destructible = (IS_FREE(ex, ey) || IS_DIGGABLE(e));
7653 if ((change->replace_when <= CP_WHEN_EMPTY && !empty_for_element) ||
7654 (change->replace_when <= CP_WHEN_DIGGABLE && !half_destructible) ||
7655 (change->replace_when <= CP_WHEN_DESTRUCTIBLE && IS_INDESTRUCTIBLE(e)))
7657 can_replace[xx][yy] = FALSE;
7658 complete_replace = FALSE;
7663 if (!change->only_if_complete || complete_replace)
7665 boolean something_has_changed = FALSE;
7667 if (change->only_if_complete && change->use_random_replace &&
7668 RND(100) < change->random_percentage)
7671 for (yy = 0; yy < 3; yy++) for (xx = 0; xx < 3 ; xx++)
7673 int ex = x + xx - 1;
7674 int ey = y + yy - 1;
7675 int content_element;
7677 if (can_replace[xx][yy] && (!change->use_random_replace ||
7678 RND(100) < change->random_percentage))
7680 if (IS_MOVING(ex, ey) || IS_BLOCKED(ex, ey))
7681 RemoveMovingField(ex, ey);
7683 ChangeEvent[ex][ey] = ChangeEvent[x][y];
7685 content_element = change->target_content[xx][yy];
7686 target_element = GET_TARGET_ELEMENT(content_element, change);
7688 ChangeElementNowExt(ex, ey, target_element);
7690 something_has_changed = TRUE;
7692 /* for symmetry reasons, freeze newly created border elements */
7693 if (ex != x || ey != y)
7694 Stop[ex][ey] = TRUE; /* no more moving in this frame */
7698 if (something_has_changed)
7699 PlayLevelSoundElementAction(x, y, element, ACTION_CHANGING);
7704 target_element = GET_TARGET_ELEMENT(change->target_element, change);
7706 ChangeElementNowExt(x, y, target_element);
7708 PlayLevelSoundElementAction(x, y, element, ACTION_CHANGING);
7712 /* this uses direct change before indirect change */
7713 CheckTriggeredElementChangeByPage(x,y,old_element,CE_OTHER_IS_CHANGING,page);
7719 static void ChangeElement(int x, int y, int page)
7721 int element = MovingOrBlocked2Element(x, y);
7722 struct ElementInfo *ei = &element_info[element];
7723 struct ElementChangeInfo *change = &ei->change_page[page];
7726 if (!CAN_CHANGE(element) && !CAN_CHANGE(Back[x][y]))
7729 printf("ChangeElement(): %d,%d: element = %d ('%s')\n",
7730 x, y, element, element_info[element].token_name);
7731 printf("ChangeElement(): This should never happen!\n");
7736 /* this can happen with classic bombs on walkable, changing elements */
7737 if (!CAN_CHANGE(element))
7740 if (!CAN_CHANGE(Back[x][y])) /* prevent permanent repetition */
7741 ChangeDelay[x][y] = 0;
7747 if (ChangeDelay[x][y] == 0) /* initialize element change */
7749 ChangeDelay[x][y] = ( change->delay_fixed * change->delay_frames +
7750 RND(change->delay_random * change->delay_frames)) + 1;
7752 ResetGfxAnimation(x, y);
7753 ResetRandomAnimationValue(x, y);
7755 if (change->pre_change_function)
7756 change->pre_change_function(x, y);
7759 ChangeDelay[x][y]--;
7761 if (ChangeDelay[x][y] != 0) /* continue element change */
7763 int graphic = el_act_dir2img(element, GfxAction[x][y], GfxDir[x][y]);
7765 if (IS_ANIMATED(graphic))
7766 DrawLevelGraphicAnimationIfNeeded(x, y, graphic);
7768 if (change->change_function)
7769 change->change_function(x, y);
7771 else /* finish element change */
7773 if (ChangePage[x][y] != -1) /* remember page from delayed change */
7775 page = ChangePage[x][y];
7776 ChangePage[x][y] = -1;
7778 change = &ei->change_page[page];
7782 if (IS_MOVING(x, y) && !change->explode)
7784 if (IS_MOVING(x, y)) /* never change a running system ;-) */
7787 ChangeDelay[x][y] = 1; /* try change after next move step */
7788 ChangePage[x][y] = page; /* remember page to use for change */
7793 if (ChangeElementNow(x, y, element, page))
7795 if (change->post_change_function)
7796 change->post_change_function(x, y);
7801 static boolean CheckTriggeredElementChangeExt(int lx, int ly,
7802 int trigger_element,
7809 int trigger_page_bits = (trigger_page < 0 ? CH_PAGE_ANY : 1 << trigger_page);
7811 if (!(trigger_events[trigger_element] & CH_EVENT_BIT(trigger_event)))
7814 for (i = 0; i < NUM_CUSTOM_ELEMENTS; i++)
7816 int element = EL_CUSTOM_START + i;
7818 boolean change_element = FALSE;
7821 if (!CAN_CHANGE(element) || !HAS_ANY_CHANGE_EVENT(element, trigger_event))
7824 for (j = 0; j < element_info[element].num_change_pages; j++)
7826 struct ElementChangeInfo *change = &element_info[element].change_page[j];
7828 if (change->can_change &&
7829 change->events & CH_EVENT_BIT(trigger_event) &&
7830 change->trigger_side & trigger_side &&
7831 change->trigger_player & trigger_player &&
7832 change->trigger_page & trigger_page_bits &&
7833 IS_EQUAL_OR_IN_GROUP(trigger_element, change->trigger_element))
7836 if (!(change->events & CH_EVENT_BIT(trigger_event)))
7837 printf("::: !!! %d triggers %d: using wrong page %d [event %d]\n",
7838 trigger_element-EL_CUSTOM_START+1, i+1, j, trigger_event);
7841 change_element = TRUE;
7844 change->actual_trigger_element = trigger_element;
7845 change->actual_trigger_player = EL_PLAYER_1 + log_2(trigger_player);
7851 if (!change_element)
7854 for (y = 0; y < lev_fieldy; y++) for (x = 0; x < lev_fieldx; x++)
7857 if (x == lx && y == ly) /* do not change trigger element itself */
7861 if (Feld[x][y] == element)
7863 ChangeDelay[x][y] = 1;
7864 ChangeEvent[x][y] = CH_EVENT_BIT(trigger_event);
7865 ChangeElement(x, y, page);
7873 static boolean CheckElementChangeExt(int x, int y,
7875 int trigger_element,
7881 if (!CAN_CHANGE(element) || !HAS_ANY_CHANGE_EVENT(element, trigger_event))
7884 if (Feld[x][y] == EL_BLOCKED)
7886 Blocked2Moving(x, y, &x, &y);
7887 element = Feld[x][y];
7891 if (Feld[x][y] != element) /* check if element has already changed */
7894 printf("::: %d ('%s') != %d ('%s') [%d]\n",
7895 Feld[x][y], element_info[Feld[x][y]].token_name,
7896 element, element_info[element].token_name,
7905 if (trigger_page < 0)
7907 boolean change_element = FALSE;
7910 for (i = 0; i < element_info[element].num_change_pages; i++)
7912 struct ElementChangeInfo *change = &element_info[element].change_page[i];
7914 if (change->can_change &&
7915 change->events & CH_EVENT_BIT(trigger_event) &&
7916 change->trigger_side & trigger_side &&
7917 change->trigger_player & trigger_player)
7919 change_element = TRUE;
7922 change->actual_trigger_element = trigger_element;
7923 change->actual_trigger_player = EL_PLAYER_1 + log_2(trigger_player);
7929 if (!change_element)
7934 struct ElementInfo *ei = &element_info[element];
7935 struct ElementChangeInfo *change = &ei->change_page[trigger_page];
7937 change->actual_trigger_element = trigger_element;
7938 change->actual_trigger_player = EL_PLAYER_1; /* unused */
7943 /* !!! this check misses pages with same event, but different side !!! */
7945 if (trigger_page < 0)
7946 trigger_page = element_info[element].event_page_nr[trigger_event];
7948 if (!(element_info[element].change_page[trigger_page].trigger_side & trigger_side))
7952 ChangeDelay[x][y] = 1;
7953 ChangeEvent[x][y] = CH_EVENT_BIT(trigger_event);
7954 ChangeElement(x, y, trigger_page);
7959 static void PlayPlayerSound(struct PlayerInfo *player)
7961 int jx = player->jx, jy = player->jy;
7962 int element = player->element_nr;
7963 int last_action = player->last_action_waiting;
7964 int action = player->action_waiting;
7966 if (player->is_waiting)
7968 if (action != last_action)
7969 PlayLevelSoundElementAction(jx, jy, element, action);
7971 PlayLevelSoundElementActionIfLoop(jx, jy, element, action);
7975 if (action != last_action)
7976 StopSound(element_info[element].sound[last_action]);
7978 if (last_action == ACTION_SLEEPING)
7979 PlayLevelSoundElementAction(jx, jy, element, ACTION_AWAKENING);
7983 static void PlayAllPlayersSound()
7987 for (i = 0; i < MAX_PLAYERS; i++)
7988 if (stored_player[i].active)
7989 PlayPlayerSound(&stored_player[i]);
7992 static void SetPlayerWaiting(struct PlayerInfo *player, boolean is_waiting)
7994 boolean last_waiting = player->is_waiting;
7995 int move_dir = player->MovDir;
7997 player->last_action_waiting = player->action_waiting;
8001 if (!last_waiting) /* not waiting -> waiting */
8003 player->is_waiting = TRUE;
8005 player->frame_counter_bored =
8007 game.player_boring_delay_fixed +
8008 SimpleRND(game.player_boring_delay_random);
8009 player->frame_counter_sleeping =
8011 game.player_sleeping_delay_fixed +
8012 SimpleRND(game.player_sleeping_delay_random);
8014 InitPlayerGfxAnimation(player, ACTION_WAITING, player->MovDir);
8017 if (game.player_sleeping_delay_fixed +
8018 game.player_sleeping_delay_random > 0 &&
8019 player->anim_delay_counter == 0 &&
8020 player->post_delay_counter == 0 &&
8021 FrameCounter >= player->frame_counter_sleeping)
8022 player->is_sleeping = TRUE;
8023 else if (game.player_boring_delay_fixed +
8024 game.player_boring_delay_random > 0 &&
8025 FrameCounter >= player->frame_counter_bored)
8026 player->is_bored = TRUE;
8028 player->action_waiting = (player->is_sleeping ? ACTION_SLEEPING :
8029 player->is_bored ? ACTION_BORING :
8032 if (player->is_sleeping)
8034 if (player->num_special_action_sleeping > 0)
8036 if (player->anim_delay_counter == 0 && player->post_delay_counter == 0)
8038 int last_special_action = player->special_action_sleeping;
8039 int num_special_action = player->num_special_action_sleeping;
8040 int special_action =
8041 (last_special_action == ACTION_DEFAULT ? ACTION_SLEEPING_1 :
8042 last_special_action == ACTION_SLEEPING ? ACTION_SLEEPING :
8043 last_special_action < ACTION_SLEEPING_1 + num_special_action - 1 ?
8044 last_special_action + 1 : ACTION_SLEEPING);
8045 int special_graphic =
8046 el_act_dir2img(player->element_nr, special_action, move_dir);
8048 player->anim_delay_counter =
8049 graphic_info[special_graphic].anim_delay_fixed +
8050 SimpleRND(graphic_info[special_graphic].anim_delay_random);
8051 player->post_delay_counter =
8052 graphic_info[special_graphic].post_delay_fixed +
8053 SimpleRND(graphic_info[special_graphic].post_delay_random);
8055 player->special_action_sleeping = special_action;
8058 if (player->anim_delay_counter > 0)
8060 player->action_waiting = player->special_action_sleeping;
8061 player->anim_delay_counter--;
8063 else if (player->post_delay_counter > 0)
8065 player->post_delay_counter--;
8069 else if (player->is_bored)
8071 if (player->num_special_action_bored > 0)
8073 if (player->anim_delay_counter == 0 && player->post_delay_counter == 0)
8075 int special_action =
8076 ACTION_BORING_1 + SimpleRND(player->num_special_action_bored);
8077 int special_graphic =
8078 el_act_dir2img(player->element_nr, special_action, move_dir);
8080 player->anim_delay_counter =
8081 graphic_info[special_graphic].anim_delay_fixed +
8082 SimpleRND(graphic_info[special_graphic].anim_delay_random);
8083 player->post_delay_counter =
8084 graphic_info[special_graphic].post_delay_fixed +
8085 SimpleRND(graphic_info[special_graphic].post_delay_random);
8087 player->special_action_bored = special_action;
8090 if (player->anim_delay_counter > 0)
8092 player->action_waiting = player->special_action_bored;
8093 player->anim_delay_counter--;
8095 else if (player->post_delay_counter > 0)
8097 player->post_delay_counter--;
8102 else if (last_waiting) /* waiting -> not waiting */
8104 player->is_waiting = FALSE;
8105 player->is_bored = FALSE;
8106 player->is_sleeping = FALSE;
8108 player->frame_counter_bored = -1;
8109 player->frame_counter_sleeping = -1;
8111 player->anim_delay_counter = 0;
8112 player->post_delay_counter = 0;
8114 player->action_waiting = ACTION_DEFAULT;
8116 player->special_action_bored = ACTION_DEFAULT;
8117 player->special_action_sleeping = ACTION_DEFAULT;
8122 static byte PlayerActions(struct PlayerInfo *player, byte player_action)
8125 static byte stored_player_action[MAX_PLAYERS];
8126 static int num_stored_actions = 0;
8128 boolean moved = FALSE, snapped = FALSE, dropped = FALSE;
8129 int left = player_action & JOY_LEFT;
8130 int right = player_action & JOY_RIGHT;
8131 int up = player_action & JOY_UP;
8132 int down = player_action & JOY_DOWN;
8133 int button1 = player_action & JOY_BUTTON_1;
8134 int button2 = player_action & JOY_BUTTON_2;
8135 int dx = (left ? -1 : right ? 1 : 0);
8136 int dy = (up ? -1 : down ? 1 : 0);
8139 stored_player_action[player->index_nr] = 0;
8140 num_stored_actions++;
8144 printf("::: player %d [%d]\n", player->index_nr, FrameCounter);
8147 if (!player->active || tape.pausing)
8151 printf("::: [%d %d %d %d] [%d %d]\n",
8152 left, right, up, down, button1, button2);
8158 printf("::: player %d acts [%d]\n", player->index_nr, FrameCounter);
8163 if (player->MovPos == 0)
8164 CheckGravityMovement(player);
8167 snapped = SnapField(player, dx, dy);
8171 dropped = DropElement(player);
8173 moved = MovePlayer(player, dx, dy);
8176 if (tape.single_step && tape.recording && !tape.pausing)
8178 if (button1 || (dropped && !moved))
8180 TapeTogglePause(TAPE_TOGGLE_AUTOMATIC);
8181 SnapField(player, 0, 0); /* stop snapping */
8185 SetPlayerWaiting(player, FALSE);
8188 return player_action;
8190 stored_player_action[player->index_nr] = player_action;
8196 printf("::: player %d waits [%d]\n", player->index_nr, FrameCounter);
8199 /* no actions for this player (no input at player's configured device) */
8201 DigField(player, 0, 0, 0, 0, 0, 0, DF_NO_PUSH);
8202 SnapField(player, 0, 0);
8203 CheckGravityMovementWhenNotMoving(player);
8205 if (player->MovPos == 0)
8206 SetPlayerWaiting(player, TRUE);
8208 if (player->MovPos == 0) /* needed for tape.playing */
8209 player->is_moving = FALSE;
8211 player->is_dropping = FALSE;
8217 if (tape.recording && num_stored_actions >= MAX_PLAYERS)
8219 printf("::: player %d recorded [%d]\n", player->index_nr, FrameCounter);
8221 TapeRecordAction(stored_player_action);
8222 num_stored_actions = 0;
8229 static void PlayerActions(struct PlayerInfo *player, byte player_action)
8231 static byte stored_player_action[MAX_PLAYERS];
8232 static int num_stored_actions = 0;
8233 boolean moved = FALSE, snapped = FALSE, dropped = FALSE;
8234 int left = player_action & JOY_LEFT;
8235 int right = player_action & JOY_RIGHT;
8236 int up = player_action & JOY_UP;
8237 int down = player_action & JOY_DOWN;
8238 int button1 = player_action & JOY_BUTTON_1;
8239 int button2 = player_action & JOY_BUTTON_2;
8240 int dx = (left ? -1 : right ? 1 : 0);
8241 int dy = (up ? -1 : down ? 1 : 0);
8243 stored_player_action[player->index_nr] = 0;
8244 num_stored_actions++;
8246 printf("::: player %d [%d]\n", player->index_nr, FrameCounter);
8248 if (!player->active || tape.pausing)
8253 printf("::: player %d acts [%d]\n", player->index_nr, FrameCounter);
8256 snapped = SnapField(player, dx, dy);
8260 dropped = DropElement(player);
8262 moved = MovePlayer(player, dx, dy);
8265 if (tape.single_step && tape.recording && !tape.pausing)
8267 if (button1 || (dropped && !moved))
8269 TapeTogglePause(TAPE_TOGGLE_AUTOMATIC);
8270 SnapField(player, 0, 0); /* stop snapping */
8274 stored_player_action[player->index_nr] = player_action;
8278 printf("::: player %d waits [%d]\n", player->index_nr, FrameCounter);
8280 /* no actions for this player (no input at player's configured device) */
8282 DigField(player, 0, 0, 0, 0, 0, 0, DF_NO_PUSH);
8283 SnapField(player, 0, 0);
8284 CheckGravityMovementWhenNotMoving(player);
8286 if (player->MovPos == 0)
8287 InitPlayerGfxAnimation(player, ACTION_DEFAULT, player->MovDir);
8289 if (player->MovPos == 0) /* needed for tape.playing */
8290 player->is_moving = FALSE;
8293 if (tape.recording && num_stored_actions >= MAX_PLAYERS)
8295 printf("::: player %d recorded [%d]\n", player->index_nr, FrameCounter);
8297 TapeRecordAction(stored_player_action);
8298 num_stored_actions = 0;
8305 static unsigned long action_delay = 0;
8306 unsigned long action_delay_value;
8307 int magic_wall_x = 0, magic_wall_y = 0;
8308 int i, x, y, element, graphic;
8309 byte *recorded_player_action;
8310 byte summarized_player_action = 0;
8312 byte tape_action[MAX_PLAYERS];
8315 if (game_status != GAME_MODE_PLAYING)
8318 action_delay_value =
8319 (tape.playing && tape.fast_forward ? FfwdFrameDelay : GameFrameDelay);
8321 if (tape.playing && tape.warp_forward && !tape.pausing)
8322 action_delay_value = 0;
8324 /* ---------- main game synchronization point ---------- */
8326 WaitUntilDelayReached(&action_delay, action_delay_value);
8328 if (network_playing && !network_player_action_received)
8332 printf("DEBUG: try to get network player actions in time\n");
8336 #if defined(NETWORK_AVALIABLE)
8337 /* last chance to get network player actions without main loop delay */
8341 if (game_status != GAME_MODE_PLAYING)
8344 if (!network_player_action_received)
8348 printf("DEBUG: failed to get network player actions in time\n");
8359 printf("::: getting new tape action [%d]\n", FrameCounter);
8362 recorded_player_action = (tape.playing ? TapePlayAction() : NULL);
8365 if (recorded_player_action == NULL && tape.pausing)
8370 printf("::: %d\n", stored_player[0].action);
8374 if (recorded_player_action != NULL)
8375 for (i = 0; i < MAX_PLAYERS; i++)
8376 stored_player[i].action = recorded_player_action[i];
8379 for (i = 0; i < MAX_PLAYERS; i++)
8381 summarized_player_action |= stored_player[i].action;
8383 if (!network_playing)
8384 stored_player[i].effective_action = stored_player[i].action;
8387 #if defined(NETWORK_AVALIABLE)
8388 if (network_playing)
8389 SendToServer_MovePlayer(summarized_player_action);
8392 if (!options.network && !setup.team_mode)
8393 local_player->effective_action = summarized_player_action;
8396 if (recorded_player_action != NULL)
8397 for (i = 0; i < MAX_PLAYERS; i++)
8398 stored_player[i].effective_action = recorded_player_action[i];
8402 for (i = 0; i < MAX_PLAYERS; i++)
8404 tape_action[i] = stored_player[i].effective_action;
8406 if (tape.recording && tape_action[i] && !tape.player_participates[i])
8407 tape.player_participates[i] = TRUE; /* player just appeared from CE */
8410 /* only save actions from input devices, but not programmed actions */
8412 TapeRecordAction(tape_action);
8415 for (i = 0; i < MAX_PLAYERS; i++)
8417 int actual_player_action = stored_player[i].effective_action;
8420 /* !!! THIS BREAKS THE FOLLOWING TAPES: !!!
8421 - rnd_equinox_tetrachloride 048
8422 - rnd_equinox_tetrachloride_ii 096
8423 - rnd_emanuel_schmieg 002
8424 - doctor_sloan_ww 001, 020
8426 if (stored_player[i].MovPos == 0)
8427 CheckGravityMovement(&stored_player[i]);
8431 /* overwrite programmed action with tape action */
8432 if (stored_player[i].programmed_action)
8433 actual_player_action = stored_player[i].programmed_action;
8437 if (stored_player[i].programmed_action)
8438 printf("::: %d\n", stored_player[i].programmed_action);
8441 if (recorded_player_action)
8444 if (stored_player[i].programmed_action &&
8445 stored_player[i].programmed_action != recorded_player_action[i])
8446 printf("::: %d: %d <-> %d\n", i,
8447 stored_player[i].programmed_action, recorded_player_action[i]);
8451 actual_player_action = recorded_player_action[i];
8456 /* overwrite tape action with programmed action */
8457 if (stored_player[i].programmed_action)
8458 actual_player_action = stored_player[i].programmed_action;
8463 printf("::: action: %d: %x [%d]\n",
8464 stored_player[i].MovPos, actual_player_action, FrameCounter);
8468 PlayerActions(&stored_player[i], actual_player_action);
8470 tape_action[i] = PlayerActions(&stored_player[i], actual_player_action);
8472 if (tape.recording && tape_action[i] && !tape.player_participates[i])
8473 tape.player_participates[i] = TRUE; /* player just appeared from CE */
8476 ScrollPlayer(&stored_player[i], SCROLL_GO_ON);
8481 TapeRecordAction(tape_action);
8484 network_player_action_received = FALSE;
8486 ScrollScreen(NULL, SCROLL_GO_ON);
8492 for (i = 0; i < MAX_PLAYERS; i++)
8493 stored_player[i].Frame++;
8497 /* for downwards compatibility, the following code emulates a fixed bug that
8498 occured when pushing elements (causing elements that just made their last
8499 pushing step to already (if possible) make their first falling step in the
8500 same game frame, which is bad); this code is also needed to use the famous
8501 "spring push bug" which is used in older levels and might be wanted to be
8502 used also in newer levels, but in this case the buggy pushing code is only
8503 affecting the "spring" element and no other elements */
8506 if (game.engine_version < VERSION_IDENT(2,2,0,7) || level.use_spring_bug)
8508 if (game.engine_version < VERSION_IDENT(2,2,0,7))
8511 for (i = 0; i < MAX_PLAYERS; i++)
8513 struct PlayerInfo *player = &stored_player[i];
8518 if (player->active && player->is_pushing && player->is_moving &&
8520 (game.engine_version < VERSION_IDENT(2,2,0,7) ||
8521 Feld[x][y] == EL_SPRING))
8523 if (player->active && player->is_pushing && player->is_moving &&
8527 ContinueMoving(x, y);
8529 /* continue moving after pushing (this is actually a bug) */
8530 if (!IS_MOVING(x, y))
8539 for (y = 0; y < lev_fieldy; y++) for (x = 0; x < lev_fieldx; x++)
8541 Changed[x][y] = CE_BITMASK_DEFAULT;
8542 ChangeEvent[x][y] = CE_BITMASK_DEFAULT;
8545 if (ChangePage[x][y] != -1 && ChangeDelay[x][y] != 1)
8547 printf("GameActions(): x = %d, y = %d: ChangePage != -1\n", x, y);
8548 printf("GameActions(): This should never happen!\n");
8550 ChangePage[x][y] = -1;
8555 if (WasJustMoving[x][y] > 0)
8556 WasJustMoving[x][y]--;
8557 if (WasJustFalling[x][y] > 0)
8558 WasJustFalling[x][y]--;
8559 if (CheckCollision[x][y] > 0)
8560 CheckCollision[x][y]--;
8565 /* reset finished pushing action (not done in ContinueMoving() to allow
8566 continous pushing animation for elements with zero push delay) */
8567 if (GfxAction[x][y] == ACTION_PUSHING && !IS_MOVING(x, y))
8569 ResetGfxAnimation(x, y);
8570 DrawLevelField(x, y);
8575 if (IS_BLOCKED(x, y))
8579 Blocked2Moving(x, y, &oldx, &oldy);
8580 if (!IS_MOVING(oldx, oldy))
8582 printf("GameActions(): (BLOCKED => MOVING) context corrupted!\n");
8583 printf("GameActions(): BLOCKED: x = %d, y = %d\n", x, y);
8584 printf("GameActions(): !MOVING: oldx = %d, oldy = %d\n", oldx, oldy);
8585 printf("GameActions(): This should never happen!\n");
8591 for (y = 0; y < lev_fieldy; y++) for (x = 0; x < lev_fieldx; x++)
8593 element = Feld[x][y];
8595 graphic = el_act_dir2img(element, GfxAction[x][y], GfxDir[x][y]);
8597 graphic = el2img(element);
8603 printf("::: %d,%d: %d [%d]\n", x, y, element, FrameCounter);
8605 element = graphic = 0;
8609 if (graphic_info[graphic].anim_global_sync)
8610 GfxFrame[x][y] = FrameCounter;
8612 if (ANIM_MODE(graphic) == ANIM_RANDOM &&
8613 IS_NEXT_FRAME(GfxFrame[x][y], graphic))
8614 ResetRandomAnimationValue(x, y);
8616 SetRandomAnimationValue(x, y);
8619 PlayLevelSoundActionIfLoop(x, y, GfxAction[x][y]);
8622 if (IS_INACTIVE(element))
8624 if (IS_ANIMATED(graphic))
8625 DrawLevelGraphicAnimationIfNeeded(x, y, graphic);
8631 /* this may take place after moving, so 'element' may have changed */
8633 if (IS_CHANGING(x, y))
8635 if (IS_CHANGING(x, y) &&
8636 (game.engine_version < VERSION_IDENT(3,0,7,1) || !Stop[x][y]))
8640 ChangeElement(x, y, ChangePage[x][y] != -1 ? ChangePage[x][y] :
8641 element_info[element].event_page_nr[CE_DELAY]);
8643 ChangeElement(x, y, element_info[element].event_page_nr[CE_DELAY]);
8646 element = Feld[x][y];
8647 graphic = el_act_dir2img(element, GfxAction[x][y], GfxDir[x][y]);
8651 if (!IS_MOVING(x, y) && (CAN_FALL(element) || CAN_MOVE(element)))
8656 element = Feld[x][y];
8657 graphic = el_act_dir2img(element, GfxAction[x][y], GfxDir[x][y]);
8659 if (element == EL_MOLE)
8660 printf("::: %d, %d, %d [%d]\n",
8661 IS_ANIMATED(graphic), IS_MOVING(x, y), Stop[x][y],
8665 if (element == EL_YAMYAM)
8666 printf("::: %d, %d, %d\n",
8667 IS_ANIMATED(graphic), IS_MOVING(x, y), Stop[x][y]);
8671 if (IS_ANIMATED(graphic) &&
8675 DrawLevelGraphicAnimationIfNeeded(x, y, graphic);
8678 if (element == EL_BUG)
8679 printf("::: %d, %d\n", graphic, GfxFrame[x][y]);
8683 if (element == EL_MOLE)
8684 printf("::: %d, %d\n", graphic, GfxFrame[x][y]);
8688 if (IS_GEM(element) || element == EL_SP_INFOTRON)
8689 EdelsteinFunkeln(x, y);
8691 else if ((element == EL_ACID ||
8692 element == EL_EXIT_OPEN ||
8693 element == EL_SP_EXIT_OPEN ||
8694 element == EL_SP_TERMINAL ||
8695 element == EL_SP_TERMINAL_ACTIVE ||
8696 element == EL_EXTRA_TIME ||
8697 element == EL_SHIELD_NORMAL ||
8698 element == EL_SHIELD_DEADLY) &&
8699 IS_ANIMATED(graphic))
8700 DrawLevelGraphicAnimationIfNeeded(x, y, graphic);
8701 else if (IS_MOVING(x, y))
8702 ContinueMoving(x, y);
8703 else if (IS_ACTIVE_BOMB(element))
8704 CheckDynamite(x, y);
8706 else if (element == EL_EXPLOSION && !game.explosions_delayed)
8707 Explode(x, y, ExplodePhase[x][y], EX_TYPE_NORMAL);
8709 else if (element == EL_AMOEBA_GROWING)
8710 AmoebeWaechst(x, y);
8711 else if (element == EL_AMOEBA_SHRINKING)
8712 AmoebaDisappearing(x, y);
8714 #if !USE_NEW_AMOEBA_CODE
8715 else if (IS_AMOEBALIVE(element))
8716 AmoebeAbleger(x, y);
8719 else if (element == EL_GAME_OF_LIFE || element == EL_BIOMAZE)
8721 else if (element == EL_EXIT_CLOSED)
8723 else if (element == EL_SP_EXIT_CLOSED)
8725 else if (element == EL_EXPANDABLE_WALL_GROWING)
8727 else if (element == EL_EXPANDABLE_WALL ||
8728 element == EL_EXPANDABLE_WALL_HORIZONTAL ||
8729 element == EL_EXPANDABLE_WALL_VERTICAL ||
8730 element == EL_EXPANDABLE_WALL_ANY)
8732 else if (element == EL_FLAMES)
8733 CheckForDragon(x, y);
8735 else if (IS_AUTO_CHANGING(element))
8736 ChangeElement(x, y);
8738 else if (element == EL_EXPLOSION)
8739 ; /* drawing of correct explosion animation is handled separately */
8740 else if (IS_ANIMATED(graphic) && !IS_CHANGING(x, y))
8741 DrawLevelGraphicAnimationIfNeeded(x, y, graphic);
8744 /* this may take place after moving, so 'element' may have changed */
8745 if (IS_AUTO_CHANGING(Feld[x][y]))
8746 ChangeElement(x, y);
8749 if (IS_BELT_ACTIVE(element))
8750 PlayLevelSoundAction(x, y, ACTION_ACTIVE);
8752 if (game.magic_wall_active)
8754 int jx = local_player->jx, jy = local_player->jy;
8756 /* play the element sound at the position nearest to the player */
8757 if ((element == EL_MAGIC_WALL_FULL ||
8758 element == EL_MAGIC_WALL_ACTIVE ||
8759 element == EL_MAGIC_WALL_EMPTYING ||
8760 element == EL_BD_MAGIC_WALL_FULL ||
8761 element == EL_BD_MAGIC_WALL_ACTIVE ||
8762 element == EL_BD_MAGIC_WALL_EMPTYING) &&
8763 ABS(x-jx) + ABS(y-jy) < ABS(magic_wall_x-jx) + ABS(magic_wall_y-jy))
8771 #if USE_NEW_AMOEBA_CODE
8772 /* new experimental amoeba growth stuff */
8774 if (!(FrameCounter % 8))
8777 static unsigned long random = 1684108901;
8779 for (i = 0; i < level.amoeba_speed * 28 / 8; i++)
8782 x = (random >> 10) % lev_fieldx;
8783 y = (random >> 20) % lev_fieldy;
8785 x = RND(lev_fieldx);
8786 y = RND(lev_fieldy);
8788 element = Feld[x][y];
8791 if (!IS_PLAYER(x,y) &&
8792 (element == EL_EMPTY ||
8793 CAN_GROW_INTO(element) ||
8794 element == EL_QUICKSAND_EMPTY ||
8795 element == EL_ACID_SPLASH_LEFT ||
8796 element == EL_ACID_SPLASH_RIGHT))
8798 if ((IN_LEV_FIELD(x, y-1) && Feld[x][y-1] == EL_AMOEBA_WET) ||
8799 (IN_LEV_FIELD(x-1, y) && Feld[x-1][y] == EL_AMOEBA_WET) ||
8800 (IN_LEV_FIELD(x+1, y) && Feld[x+1][y] == EL_AMOEBA_WET) ||
8801 (IN_LEV_FIELD(x, y+1) && Feld[x][y+1] == EL_AMOEBA_WET))
8802 Feld[x][y] = EL_AMOEBA_DROP;
8805 /* !!! extend EL_SAND to anything diggable (but maybe not SP_BASE) !!! */
8806 if (!IS_PLAYER(x,y) &&
8807 (element == EL_EMPTY ||
8808 element == EL_SAND ||
8809 element == EL_QUICKSAND_EMPTY ||
8810 element == EL_ACID_SPLASH_LEFT ||
8811 element == EL_ACID_SPLASH_RIGHT))
8813 if ((IN_LEV_FIELD(x, y-1) && Feld[x][y-1] == EL_AMOEBA_WET) ||
8814 (IN_LEV_FIELD(x-1, y) && Feld[x-1][y] == EL_AMOEBA_WET) ||
8815 (IN_LEV_FIELD(x+1, y) && Feld[x+1][y] == EL_AMOEBA_WET) ||
8816 (IN_LEV_FIELD(x, y+1) && Feld[x][y+1] == EL_AMOEBA_WET))
8817 Feld[x][y] = EL_AMOEBA_DROP;
8821 random = random * 129 + 1;
8827 if (game.explosions_delayed)
8830 game.explosions_delayed = FALSE;
8832 for (y = 0; y < lev_fieldy; y++) for (x = 0; x < lev_fieldx; x++)
8834 element = Feld[x][y];
8836 if (ExplodeField[x][y])
8837 Explode(x, y, EX_PHASE_START, ExplodeField[x][y]);
8838 else if (element == EL_EXPLOSION)
8839 Explode(x, y, ExplodePhase[x][y], EX_TYPE_NORMAL);
8841 ExplodeField[x][y] = EX_TYPE_NONE;
8844 game.explosions_delayed = TRUE;
8847 if (game.magic_wall_active)
8849 if (!(game.magic_wall_time_left % 4))
8851 int element = Feld[magic_wall_x][magic_wall_y];
8853 if (element == EL_BD_MAGIC_WALL_FULL ||
8854 element == EL_BD_MAGIC_WALL_ACTIVE ||
8855 element == EL_BD_MAGIC_WALL_EMPTYING)
8856 PlayLevelSound(magic_wall_x, magic_wall_y, SND_BD_MAGIC_WALL_ACTIVE);
8858 PlayLevelSound(magic_wall_x, magic_wall_y, SND_MAGIC_WALL_ACTIVE);
8861 if (game.magic_wall_time_left > 0)
8863 game.magic_wall_time_left--;
8864 if (!game.magic_wall_time_left)
8866 for (y = 0; y < lev_fieldy; y++) for (x = 0; x < lev_fieldx; x++)
8868 element = Feld[x][y];
8870 if (element == EL_MAGIC_WALL_ACTIVE ||
8871 element == EL_MAGIC_WALL_FULL)
8873 Feld[x][y] = EL_MAGIC_WALL_DEAD;
8874 DrawLevelField(x, y);
8876 else if (element == EL_BD_MAGIC_WALL_ACTIVE ||
8877 element == EL_BD_MAGIC_WALL_FULL)
8879 Feld[x][y] = EL_BD_MAGIC_WALL_DEAD;
8880 DrawLevelField(x, y);
8884 game.magic_wall_active = FALSE;
8889 if (game.light_time_left > 0)
8891 game.light_time_left--;
8893 if (game.light_time_left == 0)
8894 RedrawAllLightSwitchesAndInvisibleElements();
8897 if (game.timegate_time_left > 0)
8899 game.timegate_time_left--;
8901 if (game.timegate_time_left == 0)
8902 CloseAllOpenTimegates();
8905 for (i = 0; i < MAX_PLAYERS; i++)
8907 struct PlayerInfo *player = &stored_player[i];
8909 if (SHIELD_ON(player))
8911 if (player->shield_deadly_time_left)
8912 PlayLevelSound(player->jx, player->jy, SND_SHIELD_DEADLY_ACTIVE);
8913 else if (player->shield_normal_time_left)
8914 PlayLevelSound(player->jx, player->jy, SND_SHIELD_NORMAL_ACTIVE);
8918 if (TimeFrames >= FRAMES_PER_SECOND)
8923 for (i = 0; i < MAX_PLAYERS; i++)
8925 struct PlayerInfo *player = &stored_player[i];
8927 if (SHIELD_ON(player))
8929 player->shield_normal_time_left--;
8931 if (player->shield_deadly_time_left > 0)
8932 player->shield_deadly_time_left--;
8936 if (!level.use_step_counter)
8944 if (TimeLeft <= 10 && setup.time_limit)
8945 PlaySoundStereo(SND_GAME_RUNNING_OUT_OF_TIME, SOUND_MIDDLE);
8947 DrawGameValue_Time(TimeLeft);
8949 if (!TimeLeft && setup.time_limit)
8950 for (i = 0; i < MAX_PLAYERS; i++)
8951 KillHero(&stored_player[i]);
8953 else if (level.time == 0 && !AllPlayersGone) /* level w/o time limit */
8954 DrawGameValue_Time(TimePlayed);
8957 if (tape.recording || tape.playing)
8958 DrawVideoDisplay(VIDEO_STATE_TIME_ON, TapeTime);
8962 PlayAllPlayersSound();
8964 if (options.debug) /* calculate frames per second */
8966 static unsigned long fps_counter = 0;
8967 static int fps_frames = 0;
8968 unsigned long fps_delay_ms = Counter() - fps_counter;
8972 if (fps_delay_ms >= 500) /* calculate fps every 0.5 seconds */
8974 global.frames_per_second = 1000 * (float)fps_frames / fps_delay_ms;
8977 fps_counter = Counter();
8980 redraw_mask |= REDRAW_FPS;
8984 if (stored_player[0].jx != stored_player[0].last_jx ||
8985 stored_player[0].jy != stored_player[0].last_jy)
8986 printf("::: %d, %d, %d, %d, %d\n",
8987 stored_player[0].MovDir,
8988 stored_player[0].MovPos,
8989 stored_player[0].GfxPos,
8990 stored_player[0].Frame,
8991 stored_player[0].StepFrame);
8998 for (i = 0; i < MAX_PLAYERS; i++)
9001 MOVE_DELAY_NORMAL_SPEED / stored_player[i].move_delay_value;
9003 stored_player[i].Frame += move_frames;
9005 if (stored_player[i].MovPos != 0)
9006 stored_player[i].StepFrame += move_frames;
9008 if (stored_player[i].drop_delay > 0)
9009 stored_player[i].drop_delay--;
9014 if (local_player->show_envelope != 0 && local_player->MovPos == 0)
9016 ShowEnvelope(local_player->show_envelope - EL_ENVELOPE_1);
9018 local_player->show_envelope = 0;
9023 static boolean AllPlayersInSight(struct PlayerInfo *player, int x, int y)
9025 int min_x = x, min_y = y, max_x = x, max_y = y;
9028 for (i = 0; i < MAX_PLAYERS; i++)
9030 int jx = stored_player[i].jx, jy = stored_player[i].jy;
9032 if (!stored_player[i].active || &stored_player[i] == player)
9035 min_x = MIN(min_x, jx);
9036 min_y = MIN(min_y, jy);
9037 max_x = MAX(max_x, jx);
9038 max_y = MAX(max_y, jy);
9041 return (max_x - min_x < SCR_FIELDX && max_y - min_y < SCR_FIELDY);
9044 static boolean AllPlayersInVisibleScreen()
9048 for (i = 0; i < MAX_PLAYERS; i++)
9050 int jx = stored_player[i].jx, jy = stored_player[i].jy;
9052 if (!stored_player[i].active)
9055 if (!IN_VIS_FIELD(SCREENX(jx), SCREENY(jy)))
9062 void ScrollLevel(int dx, int dy)
9064 int softscroll_offset = (setup.soft_scrolling ? TILEX : 0);
9067 BlitBitmap(drawto_field, drawto_field,
9068 FX + TILEX * (dx == -1) - softscroll_offset,
9069 FY + TILEY * (dy == -1) - softscroll_offset,
9070 SXSIZE - TILEX * (dx!=0) + 2 * softscroll_offset,
9071 SYSIZE - TILEY * (dy!=0) + 2 * softscroll_offset,
9072 FX + TILEX * (dx == 1) - softscroll_offset,
9073 FY + TILEY * (dy == 1) - softscroll_offset);
9077 x = (dx == 1 ? BX1 : BX2);
9078 for (y = BY1; y <= BY2; y++)
9079 DrawScreenField(x, y);
9084 y = (dy == 1 ? BY1 : BY2);
9085 for (x = BX1; x <= BX2; x++)
9086 DrawScreenField(x, y);
9089 redraw_mask |= REDRAW_FIELD;
9093 static boolean canEnterSupaplexPort(int x, int y, int dx, int dy)
9095 int nextx = x + dx, nexty = y + dy;
9096 int element = Feld[x][y];
9099 element != EL_SP_PORT_LEFT &&
9100 element != EL_SP_GRAVITY_PORT_LEFT &&
9101 element != EL_SP_PORT_HORIZONTAL &&
9102 element != EL_SP_PORT_ANY) ||
9104 element != EL_SP_PORT_RIGHT &&
9105 element != EL_SP_GRAVITY_PORT_RIGHT &&
9106 element != EL_SP_PORT_HORIZONTAL &&
9107 element != EL_SP_PORT_ANY) ||
9109 element != EL_SP_PORT_UP &&
9110 element != EL_SP_GRAVITY_PORT_UP &&
9111 element != EL_SP_PORT_VERTICAL &&
9112 element != EL_SP_PORT_ANY) ||
9114 element != EL_SP_PORT_DOWN &&
9115 element != EL_SP_GRAVITY_PORT_DOWN &&
9116 element != EL_SP_PORT_VERTICAL &&
9117 element != EL_SP_PORT_ANY) ||
9118 !IN_LEV_FIELD(nextx, nexty) ||
9119 !IS_FREE(nextx, nexty))
9126 static boolean canFallDown(struct PlayerInfo *player)
9128 int jx = player->jx, jy = player->jy;
9130 return (IN_LEV_FIELD(jx, jy + 1) &&
9131 (IS_FREE(jx, jy + 1) ||
9132 (Feld[jx][jy + 1] == EL_ACID && player->can_fall_into_acid)) &&
9133 IS_WALKABLE_FROM(Feld[jx][jy], MV_DOWN) &&
9134 !IS_WALKABLE_INSIDE(Feld[jx][jy]));
9137 static boolean canPassField(int x, int y, int move_dir)
9139 int opposite_dir = MV_DIR_OPPOSITE(move_dir);
9140 int dx = (move_dir & MV_LEFT ? -1 : move_dir & MV_RIGHT ? +1 : 0);
9141 int dy = (move_dir & MV_UP ? -1 : move_dir & MV_DOWN ? +1 : 0);
9144 int element = Feld[x][y];
9146 return (IS_PASSABLE_FROM(element, opposite_dir) &&
9147 !CAN_MOVE(element) &&
9148 IN_LEV_FIELD(nextx, nexty) && !IS_PLAYER(nextx, nexty) &&
9149 IS_WALKABLE_FROM(Feld[nextx][nexty], move_dir) &&
9150 (level.can_pass_to_walkable || IS_FREE(nextx, nexty)));
9153 static boolean canMoveToValidFieldWithGravity(int x, int y, int move_dir)
9155 int opposite_dir = MV_DIR_OPPOSITE(move_dir);
9156 int dx = (move_dir & MV_LEFT ? -1 : move_dir & MV_RIGHT ? +1 : 0);
9157 int dy = (move_dir & MV_UP ? -1 : move_dir & MV_DOWN ? +1 : 0);
9161 int nextx = newx + dx;
9162 int nexty = newy + dy;
9166 return (IN_LEV_FIELD(newx, newy) && !IS_FREE_OR_PLAYER(newx, newy) &&
9167 IS_GRAVITY_REACHABLE(Feld[newx][newy]) &&
9169 (!IS_SP_PORT(Feld[newx][newy]) || move_dir == MV_UP) &&
9171 (IS_DIGGABLE(Feld[newx][newy]) ||
9172 IS_WALKABLE_FROM(Feld[newx][newy], opposite_dir) ||
9173 canPassField(newx, newy, move_dir)));
9176 return (IN_LEV_FIELD(newx, newy) && !IS_FREE_OR_PLAYER(newx, newy) &&
9177 IS_GRAVITY_REACHABLE(Feld[newx][newy]) &&
9178 (IS_DIGGABLE(Feld[newx][newy]) ||
9179 IS_WALKABLE_FROM(Feld[newx][newy], opposite_dir) ||
9180 canPassField(newx, newy, move_dir)));
9183 return (IN_LEV_FIELD(newx, newy) && !IS_FREE_OR_PLAYER(newx, newy) &&
9184 (IS_DIGGABLE_WITH_GRAVITY(Feld[newx][newy]) ||
9185 IS_WALKABLE_FROM(Feld[newx][newy], opposite_dir) ||
9186 canPassField(newx, newy, move_dir)));
9188 return (IN_LEV_FIELD(newx, newy) && !IS_FREE_OR_PLAYER(newx, newy) &&
9189 (IS_DIGGABLE(Feld[newx][newy]) ||
9190 IS_WALKABLE_FROM(Feld[newx][newy], opposite_dir) ||
9191 (IS_PASSABLE_FROM(Feld[newx][newy], opposite_dir) &&
9192 !CAN_MOVE(Feld[newx][newy]) &&
9193 IN_LEV_FIELD(nextx, nexty) && !IS_PLAYER(nextx, nexty) &&
9194 IS_WALKABLE_FROM(Feld[nextx][nexty], move_dir) &&
9195 (level.can_pass_to_walkable || IS_FREE(nextx, nexty)))));
9201 static void CheckGravityMovement(struct PlayerInfo *player)
9203 if (game.gravity && !player->programmed_action)
9206 int move_dir_horizontal = player->effective_action & MV_HORIZONTAL;
9207 int move_dir_vertical = player->effective_action & MV_VERTICAL;
9209 int move_dir_horizontal = player->action & MV_HORIZONTAL;
9210 int move_dir_vertical = player->action & MV_VERTICAL;
9214 boolean player_is_snapping = player->effective_action & JOY_BUTTON_1;
9216 boolean player_is_snapping = player->action & JOY_BUTTON_1;
9219 int jx = player->jx, jy = player->jy;
9221 boolean player_is_moving_to_valid_field =
9222 (!player_is_snapping &&
9223 (canMoveToValidFieldWithGravity(jx, jy, move_dir_horizontal) ||
9224 canMoveToValidFieldWithGravity(jx, jy, move_dir_vertical)));
9228 (player->last_move_dir & MV_HORIZONTAL ?
9229 (move_dir_vertical ? move_dir_vertical : move_dir_horizontal) :
9230 (move_dir_horizontal ? move_dir_horizontal : move_dir_vertical));
9234 int opposite_dir = MV_DIR_OPPOSITE(move_dir);
9235 int dx = (move_dir & MV_LEFT ? -1 : move_dir & MV_RIGHT ? +1 : 0);
9236 int dy = (move_dir & MV_UP ? -1 : move_dir & MV_DOWN ? +1 : 0);
9237 int new_jx = jx + dx, new_jy = jy + dy;
9238 int nextx = new_jx + dx, nexty = new_jy + dy;
9244 boolean player_can_fall_down = canFallDown(player);
9246 boolean player_can_fall_down =
9247 (IN_LEV_FIELD(jx, jy + 1) &&
9248 (IS_FREE(jx, jy + 1) ||
9249 (Feld[jx][jy + 1] == EL_ACID && player->can_fall_into_acid)));
9253 boolean player_can_fall_down =
9254 (IN_LEV_FIELD(jx, jy + 1) &&
9255 (IS_FREE(jx, jy + 1)));
9259 boolean player_is_moving_to_valid_field =
9262 !player_is_snapping &&
9266 IN_LEV_FIELD(new_jx, new_jy) &&
9267 (IS_DIGGABLE(Feld[new_jx][new_jy]) ||
9268 (IS_SP_PORT(Feld[new_jx][new_jy]) &&
9269 element_info[Feld[new_jx][new_jy]].access_direction & opposite_dir &&
9270 IN_LEV_FIELD(nextx, nexty) &&
9271 element_info[Feld[nextx][nexty]].access_direction & move_dir))
9273 IN_LEV_FIELD(new_jx, new_jy) &&
9274 (Feld[new_jx][new_jy] == EL_SP_BASE ||
9275 Feld[new_jx][new_jy] == EL_SAND ||
9276 (IS_SP_PORT(Feld[new_jx][new_jy]) &&
9277 canEnterSupaplexPort(new_jx, new_jy, dx, dy)))
9278 /* !!! extend EL_SAND to anything diggable !!! */
9284 boolean player_is_standing_on_valid_field =
9285 (IS_WALKABLE_INSIDE(Feld[jx][jy]) ||
9286 (IS_WALKABLE(Feld[jx][jy]) && !ACCESS_FROM(Feld[jx][jy], MV_DOWN)));
9290 printf("::: checking gravity NOW [%d, %d, %d] [%d] [%d / %d] ...\n",
9291 player_can_fall_down,
9292 player_is_standing_on_valid_field,
9293 player_is_moving_to_valid_field,
9294 (player_is_moving_to_valid_field ? Feld[new_jx][new_jy] : -1),
9295 player->effective_action,
9296 player->can_fall_into_acid);
9299 if (player_can_fall_down &&
9301 !player_is_standing_on_valid_field &&
9303 !player_is_moving_to_valid_field)
9306 printf("::: setting programmed_action to MV_DOWN [%d,%d - %d] ...\n",
9307 jx, jy, FrameCounter);
9310 player->programmed_action = MV_DOWN;
9315 static void CheckGravityMovementWhenNotMoving(struct PlayerInfo *player)
9318 return CheckGravityMovement(player);
9321 if (game.gravity && !player->programmed_action)
9323 int jx = player->jx, jy = player->jy;
9324 boolean field_under_player_is_free =
9325 (IN_LEV_FIELD(jx, jy + 1) && IS_FREE(jx, jy + 1));
9326 boolean player_is_standing_on_valid_field =
9327 (IS_WALKABLE_INSIDE(Feld[jx][jy]) ||
9328 (IS_WALKABLE(Feld[jx][jy]) &&
9329 !(element_info[Feld[jx][jy]].access_direction & MV_DOWN)));
9331 if (field_under_player_is_free && !player_is_standing_on_valid_field)
9332 player->programmed_action = MV_DOWN;
9338 -----------------------------------------------------------------------------
9339 dx, dy: direction (non-diagonal) to try to move the player to
9340 real_dx, real_dy: direction as read from input device (can be diagonal)
9343 boolean MovePlayerOneStep(struct PlayerInfo *player,
9344 int dx, int dy, int real_dx, int real_dy)
9347 static int trigger_sides[4][2] =
9349 /* enter side leave side */
9350 { CH_SIDE_RIGHT, CH_SIDE_LEFT }, /* moving left */
9351 { CH_SIDE_LEFT, CH_SIDE_RIGHT }, /* moving right */
9352 { CH_SIDE_BOTTOM, CH_SIDE_TOP }, /* moving up */
9353 { CH_SIDE_TOP, CH_SIDE_BOTTOM } /* moving down */
9355 int move_direction = (dx == -1 ? MV_LEFT :
9356 dx == +1 ? MV_RIGHT :
9358 dy == +1 ? MV_DOWN : MV_NO_MOVING);
9359 int enter_side = trigger_sides[MV_DIR_BIT(move_direction)][0];
9360 int leave_side = trigger_sides[MV_DIR_BIT(move_direction)][1];
9362 int jx = player->jx, jy = player->jy;
9363 int new_jx = jx + dx, new_jy = jy + dy;
9367 if (!player->active || (!dx && !dy))
9368 return MF_NO_ACTION;
9370 player->MovDir = (dx < 0 ? MV_LEFT :
9373 dy > 0 ? MV_DOWN : MV_NO_MOVING);
9375 if (!IN_LEV_FIELD(new_jx, new_jy))
9376 return MF_NO_ACTION;
9378 if (!options.network && !AllPlayersInSight(player, new_jx, new_jy))
9379 return MF_NO_ACTION;
9382 element = MovingOrBlocked2Element(new_jx, new_jy);
9384 element = MovingOrBlocked2ElementIfNotLeaving(new_jx, new_jy);
9387 if (DONT_RUN_INTO(element))
9389 if (element == EL_ACID && dx == 0 && dy == 1)
9391 SplashAcid(new_jx, new_jy);
9392 Feld[jx][jy] = EL_PLAYER_1;
9393 InitMovingField(jx, jy, MV_DOWN);
9394 Store[jx][jy] = EL_ACID;
9395 ContinueMoving(jx, jy);
9399 TestIfHeroRunsIntoBadThing(jx, jy, player->MovDir);
9404 can_move = DigField(player, jx, jy, new_jx, new_jy, real_dx,real_dy, DF_DIG);
9405 if (can_move != MF_MOVING)
9408 /* check if DigField() has caused relocation of the player */
9409 if (player->jx != jx || player->jy != jy)
9410 return MF_NO_ACTION;
9412 StorePlayer[jx][jy] = 0;
9413 player->last_jx = jx;
9414 player->last_jy = jy;
9415 player->jx = new_jx;
9416 player->jy = new_jy;
9417 StorePlayer[new_jx][new_jy] = player->element_nr;
9420 (dx > 0 || dy > 0 ? -1 : 1) * (TILEX - TILEX / player->move_delay_value);
9422 player->step_counter++;
9425 player->drop_delay = 0;
9428 PlayerVisit[jx][jy] = FrameCounter;
9430 ScrollPlayer(player, SCROLL_INIT);
9433 if (IS_CUSTOM_ELEMENT(Feld[jx][jy]))
9435 CheckTriggeredElementChangeBySide(jx, jy, Feld[jx][jy], CE_OTHER_GETS_LEFT,
9437 CheckElementChangeBySide(jx,jy, Feld[jx][jy],CE_LEFT_BY_PLAYER,leave_side);
9440 if (IS_CUSTOM_ELEMENT(Feld[new_jx][new_jy]))
9442 CheckTriggeredElementChangeBySide(new_jx, new_jy, Feld[new_jx][new_jy],
9443 CE_OTHER_GETS_ENTERED, enter_side);
9444 CheckElementChangeBySide(new_jx, new_jy, Feld[new_jx][new_jy],
9445 CE_ENTERED_BY_PLAYER, enter_side);
9452 boolean MovePlayer(struct PlayerInfo *player, int dx, int dy)
9454 int jx = player->jx, jy = player->jy;
9455 int old_jx = jx, old_jy = jy;
9456 int moved = MF_NO_ACTION;
9459 if (!player->active)
9464 if (player->MovPos == 0)
9466 player->is_moving = FALSE;
9467 player->is_digging = FALSE;
9468 player->is_collecting = FALSE;
9469 player->is_snapping = FALSE;
9470 player->is_pushing = FALSE;
9476 if (!player->active || (!dx && !dy))
9481 if (!FrameReached(&player->move_delay, player->move_delay_value) &&
9487 if (!FrameReached(&player->move_delay, player->move_delay_value))
9490 if (!FrameReached(&player->move_delay, player->move_delay_value) &&
9491 !(tape.playing && tape.file_version < FILE_VERSION_2_0))
9497 /* store if player is automatically moved to next field */
9498 player->is_auto_moving = (player->programmed_action != MV_NO_MOVING);
9500 /* remove the last programmed player action */
9501 player->programmed_action = 0;
9505 /* should only happen if pre-1.2 tape recordings are played */
9506 /* this is only for backward compatibility */
9508 int original_move_delay_value = player->move_delay_value;
9511 printf("THIS SHOULD ONLY HAPPEN WITH PRE-1.2 LEVEL TAPES. [%ld]\n",
9515 /* scroll remaining steps with finest movement resolution */
9516 player->move_delay_value = MOVE_DELAY_NORMAL_SPEED;
9518 while (player->MovPos)
9520 ScrollPlayer(player, SCROLL_GO_ON);
9521 ScrollScreen(NULL, SCROLL_GO_ON);
9527 player->move_delay_value = original_move_delay_value;
9530 if (player->last_move_dir & MV_HORIZONTAL)
9532 if (!(moved |= MovePlayerOneStep(player, 0, dy, dx, dy)))
9533 moved |= MovePlayerOneStep(player, dx, 0, dx, dy);
9537 if (!(moved |= MovePlayerOneStep(player, dx, 0, dx, dy)))
9538 moved |= MovePlayerOneStep(player, 0, dy, dx, dy);
9544 if (moved & MF_MOVING && !ScreenMovPos &&
9545 (player == local_player || !options.network))
9547 int old_scroll_x = scroll_x, old_scroll_y = scroll_y;
9548 int offset = (setup.scroll_delay ? 3 : 0);
9550 if (!IN_VIS_FIELD(SCREENX(jx), SCREENY(jy)))
9552 /* actual player has left the screen -- scroll in that direction */
9553 if (jx != old_jx) /* player has moved horizontally */
9554 scroll_x += (jx - old_jx);
9555 else /* player has moved vertically */
9556 scroll_y += (jy - old_jy);
9560 if (jx != old_jx) /* player has moved horizontally */
9562 if ((player->MovDir == MV_LEFT && scroll_x > jx - MIDPOSX + offset) ||
9563 (player->MovDir == MV_RIGHT && scroll_x < jx - MIDPOSX - offset))
9564 scroll_x = jx-MIDPOSX + (scroll_x < jx-MIDPOSX ? -offset : +offset);
9566 /* don't scroll over playfield boundaries */
9567 if (scroll_x < SBX_Left || scroll_x > SBX_Right)
9568 scroll_x = (scroll_x < SBX_Left ? SBX_Left : SBX_Right);
9570 /* don't scroll more than one field at a time */
9571 scroll_x = old_scroll_x + SIGN(scroll_x - old_scroll_x);
9573 /* don't scroll against the player's moving direction */
9574 if ((player->MovDir == MV_LEFT && scroll_x > old_scroll_x) ||
9575 (player->MovDir == MV_RIGHT && scroll_x < old_scroll_x))
9576 scroll_x = old_scroll_x;
9578 else /* player has moved vertically */
9580 if ((player->MovDir == MV_UP && scroll_y > jy - MIDPOSY + offset) ||
9581 (player->MovDir == MV_DOWN && scroll_y < jy - MIDPOSY - offset))
9582 scroll_y = jy-MIDPOSY + (scroll_y < jy-MIDPOSY ? -offset : +offset);
9584 /* don't scroll over playfield boundaries */
9585 if (scroll_y < SBY_Upper || scroll_y > SBY_Lower)
9586 scroll_y = (scroll_y < SBY_Upper ? SBY_Upper : SBY_Lower);
9588 /* don't scroll more than one field at a time */
9589 scroll_y = old_scroll_y + SIGN(scroll_y - old_scroll_y);
9591 /* don't scroll against the player's moving direction */
9592 if ((player->MovDir == MV_UP && scroll_y > old_scroll_y) ||
9593 (player->MovDir == MV_DOWN && scroll_y < old_scroll_y))
9594 scroll_y = old_scroll_y;
9598 if (scroll_x != old_scroll_x || scroll_y != old_scroll_y)
9600 if (!options.network && !AllPlayersInVisibleScreen())
9602 scroll_x = old_scroll_x;
9603 scroll_y = old_scroll_y;
9607 ScrollScreen(player, SCROLL_INIT);
9608 ScrollLevel(old_scroll_x - scroll_x, old_scroll_y - scroll_y);
9615 InitPlayerGfxAnimation(player, ACTION_DEFAULT);
9617 if (!(moved & MF_MOVING) && !player->is_pushing)
9622 player->StepFrame = 0;
9624 if (moved & MF_MOVING)
9626 if (old_jx != jx && old_jy == jy)
9627 player->MovDir = (old_jx < jx ? MV_RIGHT : MV_LEFT);
9628 else if (old_jx == jx && old_jy != jy)
9629 player->MovDir = (old_jy < jy ? MV_DOWN : MV_UP);
9631 DrawLevelField(jx, jy); /* for "crumbled sand" */
9633 player->last_move_dir = player->MovDir;
9634 player->is_moving = TRUE;
9636 player->is_snapping = FALSE;
9640 player->is_switching = FALSE;
9643 player->is_dropping = FALSE;
9647 /* !!! ENABLE THIS FOR OLD VERSIONS !!! */
9650 if (game.engine_version < VERSION_IDENT(3,1,0,0))
9653 int move_direction = player->MovDir;
9655 int enter_side = MV_DIR_OPPOSITE(move_direction);
9656 int leave_side = move_direction;
9658 static int trigger_sides[4][2] =
9660 /* enter side leave side */
9661 { CH_SIDE_RIGHT, CH_SIDE_LEFT }, /* moving left */
9662 { CH_SIDE_LEFT, CH_SIDE_RIGHT }, /* moving right */
9663 { CH_SIDE_BOTTOM, CH_SIDE_TOP }, /* moving up */
9664 { CH_SIDE_TOP, CH_SIDE_BOTTOM } /* moving down */
9666 int enter_side = trigger_sides[MV_DIR_BIT(move_direction)][0];
9667 int leave_side = trigger_sides[MV_DIR_BIT(move_direction)][1];
9669 int old_element = Feld[old_jx][old_jy];
9670 int new_element = Feld[jx][jy];
9673 /* !!! TEST ONLY !!! */
9674 if (IS_CUSTOM_ELEMENT(old_element))
9675 CheckElementChangeByPlayer(old_jx, old_jy, old_element,
9677 player->index_bit, leave_side);
9679 CheckTriggeredElementChangeByPlayer(old_jx, old_jy, old_element,
9681 player->index_bit, leave_side);
9683 if (IS_CUSTOM_ELEMENT(new_element))
9684 CheckElementChangeByPlayer(jx, jy, new_element, CE_ENTERED_BY_PLAYER,
9685 player->index_bit, enter_side);
9687 CheckTriggeredElementChangeByPlayer(jx, jy, new_element,
9688 CE_OTHER_GETS_ENTERED,
9689 player->index_bit, enter_side);
9699 CheckGravityMovementWhenNotMoving(player);
9702 player->last_move_dir = MV_NO_MOVING;
9704 player->is_moving = FALSE;
9707 if (game.engine_version < VERSION_IDENT(3,0,7,0))
9709 TestIfHeroTouchesBadThing(jx, jy);
9710 TestIfPlayerTouchesCustomElement(jx, jy);
9713 if (!player->active)
9719 void ScrollPlayer(struct PlayerInfo *player, int mode)
9721 int jx = player->jx, jy = player->jy;
9722 int last_jx = player->last_jx, last_jy = player->last_jy;
9723 int move_stepsize = TILEX / player->move_delay_value;
9725 if (!player->active || !player->MovPos)
9728 if (mode == SCROLL_INIT)
9730 player->actual_frame_counter = FrameCounter;
9731 player->GfxPos = move_stepsize * (player->MovPos / move_stepsize);
9733 if (Feld[last_jx][last_jy] == EL_EMPTY)
9734 Feld[last_jx][last_jy] = EL_PLAYER_IS_LEAVING;
9742 else if (!FrameReached(&player->actual_frame_counter, 1))
9745 player->MovPos += (player->MovPos > 0 ? -1 : 1) * move_stepsize;
9746 player->GfxPos = move_stepsize * (player->MovPos / move_stepsize);
9748 if (!player->block_last_field &&
9749 Feld[last_jx][last_jy] == EL_PLAYER_IS_LEAVING)
9750 Feld[last_jx][last_jy] = EL_EMPTY;
9752 /* before DrawPlayer() to draw correct player graphic for this case */
9753 if (player->MovPos == 0)
9754 CheckGravityMovement(player);
9757 DrawPlayer(player); /* needed here only to cleanup last field */
9760 if (player->MovPos == 0) /* player reached destination field */
9763 if (player->move_delay_reset_counter > 0)
9765 player->move_delay_reset_counter--;
9767 if (player->move_delay_reset_counter == 0)
9769 /* continue with normal speed after quickly moving through gate */
9770 HALVE_PLAYER_SPEED(player);
9772 /* be able to make the next move without delay */
9773 player->move_delay = 0;
9777 if (IS_PASSABLE(Feld[last_jx][last_jy]))
9779 /* continue with normal speed after quickly moving through gate */
9780 HALVE_PLAYER_SPEED(player);
9782 /* be able to make the next move without delay */
9783 player->move_delay = 0;
9787 if (player->block_last_field &&
9788 Feld[last_jx][last_jy] == EL_PLAYER_IS_LEAVING)
9789 Feld[last_jx][last_jy] = EL_EMPTY;
9791 player->last_jx = jx;
9792 player->last_jy = jy;
9794 if (Feld[jx][jy] == EL_EXIT_OPEN ||
9795 Feld[jx][jy] == EL_SP_EXIT_OPEN ||
9796 Feld[jx][jy] == EL_SP_EXIT_OPENING) /* <-- special case */
9798 DrawPlayer(player); /* needed here only to cleanup last field */
9801 if (local_player->friends_still_needed == 0 ||
9802 IS_SP_ELEMENT(Feld[jx][jy]))
9803 player->LevelSolved = player->GameOver = TRUE;
9807 /* !!! ENABLE THIS FOR NEW VERSIONS !!! */
9808 /* this breaks one level: "machine", level 000 */
9810 if (game.engine_version >= VERSION_IDENT(3,1,0,0))
9813 int move_direction = player->MovDir;
9815 int enter_side = MV_DIR_OPPOSITE(move_direction);
9816 int leave_side = move_direction;
9818 static int trigger_sides[4][2] =
9820 /* enter side leave side */
9821 { CH_SIDE_RIGHT, CH_SIDE_LEFT }, /* moving left */
9822 { CH_SIDE_LEFT, CH_SIDE_RIGHT }, /* moving right */
9823 { CH_SIDE_BOTTOM, CH_SIDE_TOP }, /* moving up */
9824 { CH_SIDE_TOP, CH_SIDE_BOTTOM } /* moving down */
9826 int enter_side = trigger_sides[MV_DIR_BIT(move_direction)][0];
9827 int leave_side = trigger_sides[MV_DIR_BIT(move_direction)][1];
9829 int old_jx = last_jx;
9830 int old_jy = last_jy;
9831 int old_element = Feld[old_jx][old_jy];
9832 int new_element = Feld[jx][jy];
9835 /* !!! TEST ONLY !!! */
9836 if (IS_CUSTOM_ELEMENT(old_element))
9837 CheckElementChangeByPlayer(old_jx, old_jy, old_element,
9839 player->index_bit, leave_side);
9841 CheckTriggeredElementChangeByPlayer(old_jx, old_jy, old_element,
9843 player->index_bit, leave_side);
9845 if (IS_CUSTOM_ELEMENT(new_element))
9846 CheckElementChangeByPlayer(jx, jy, new_element, CE_ENTERED_BY_PLAYER,
9847 player->index_bit, enter_side);
9849 CheckTriggeredElementChangeByPlayer(jx, jy, new_element,
9850 CE_OTHER_GETS_ENTERED,
9851 player->index_bit, enter_side);
9857 if (game.engine_version >= VERSION_IDENT(3,0,7,0))
9859 TestIfHeroTouchesBadThing(jx, jy);
9860 TestIfPlayerTouchesCustomElement(jx, jy);
9863 /* needed because pushed element has not yet reached its destination,
9864 so it would trigger a change event at its previous field location */
9865 if (!player->is_pushing)
9867 TestIfElementTouchesCustomElement(jx, jy); /* for empty space */
9870 if (!player->active)
9874 if (level.use_step_counter)
9884 if (TimeLeft <= 10 && setup.time_limit)
9885 PlaySoundStereo(SND_GAME_RUNNING_OUT_OF_TIME, SOUND_MIDDLE);
9887 DrawGameValue_Time(TimeLeft);
9889 if (!TimeLeft && setup.time_limit)
9890 for (i = 0; i < MAX_PLAYERS; i++)
9891 KillHero(&stored_player[i]);
9893 else if (level.time == 0 && !AllPlayersGone) /* level w/o time limit */
9894 DrawGameValue_Time(TimePlayed);
9897 if (tape.single_step && tape.recording && !tape.pausing &&
9898 !player->programmed_action)
9899 TapeTogglePause(TAPE_TOGGLE_AUTOMATIC);
9903 void ScrollScreen(struct PlayerInfo *player, int mode)
9905 static unsigned long screen_frame_counter = 0;
9907 if (mode == SCROLL_INIT)
9909 /* set scrolling step size according to actual player's moving speed */
9910 ScrollStepSize = TILEX / player->move_delay_value;
9912 screen_frame_counter = FrameCounter;
9913 ScreenMovDir = player->MovDir;
9914 ScreenMovPos = player->MovPos;
9915 ScreenGfxPos = ScrollStepSize * (ScreenMovPos / ScrollStepSize);
9918 else if (!FrameReached(&screen_frame_counter, 1))
9923 ScreenMovPos += (ScreenMovPos > 0 ? -1 : 1) * ScrollStepSize;
9924 ScreenGfxPos = ScrollStepSize * (ScreenMovPos / ScrollStepSize);
9925 redraw_mask |= REDRAW_FIELD;
9928 ScreenMovDir = MV_NO_MOVING;
9931 void TestIfPlayerTouchesCustomElement(int x, int y)
9933 static int xy[4][2] =
9940 static int trigger_sides[4][2] =
9942 /* center side border side */
9943 { CH_SIDE_TOP, CH_SIDE_BOTTOM }, /* check top */
9944 { CH_SIDE_LEFT, CH_SIDE_RIGHT }, /* check left */
9945 { CH_SIDE_RIGHT, CH_SIDE_LEFT }, /* check right */
9946 { CH_SIDE_BOTTOM, CH_SIDE_TOP } /* check bottom */
9948 static int touch_dir[4] =
9955 int center_element = Feld[x][y]; /* should always be non-moving! */
9958 for (i = 0; i < NUM_DIRECTIONS; i++)
9960 int xx = x + xy[i][0];
9961 int yy = y + xy[i][1];
9962 int center_side = trigger_sides[i][0];
9963 int border_side = trigger_sides[i][1];
9966 if (!IN_LEV_FIELD(xx, yy))
9969 if (IS_PLAYER(x, y))
9971 struct PlayerInfo *player = PLAYERINFO(x, y);
9973 if (game.engine_version < VERSION_IDENT(3,0,7,0))
9974 border_element = Feld[xx][yy]; /* may be moving! */
9975 else if (!IS_MOVING(xx, yy) && !IS_BLOCKED(xx, yy))
9976 border_element = Feld[xx][yy];
9977 else if (MovDir[xx][yy] & touch_dir[i]) /* elements are touching */
9978 border_element = MovingOrBlocked2Element(xx, yy);
9980 continue; /* center and border element do not touch */
9983 /* !!! TEST ONLY !!! */
9984 CheckElementChangeByPlayer(xx, yy, border_element, CE_TOUCHED_BY_PLAYER,
9985 player->index_bit, border_side);
9986 CheckTriggeredElementChangeByPlayer(xx, yy, border_element,
9987 CE_OTHER_GETS_TOUCHED,
9988 player->index_bit, border_side);
9990 CheckTriggeredElementChangeByPlayer(xx, yy, border_element,
9991 CE_OTHER_GETS_TOUCHED,
9992 player->index_bit, border_side);
9993 CheckElementChangeByPlayer(xx, yy, border_element, CE_TOUCHED_BY_PLAYER,
9994 player->index_bit, border_side);
9997 else if (IS_PLAYER(xx, yy))
9999 struct PlayerInfo *player = PLAYERINFO(xx, yy);
10001 if (game.engine_version >= VERSION_IDENT(3,0,7,0))
10003 if (player->MovPos != 0 && !(player->MovDir & touch_dir[i]))
10004 continue; /* center and border element do not touch */
10008 /* !!! TEST ONLY !!! */
10009 CheckElementChangeByPlayer(x, y, center_element, CE_TOUCHED_BY_PLAYER,
10010 player->index_bit, center_side);
10011 CheckTriggeredElementChangeByPlayer(x, y, center_element,
10012 CE_OTHER_GETS_TOUCHED,
10013 player->index_bit, center_side);
10015 CheckTriggeredElementChangeByPlayer(x, y, center_element,
10016 CE_OTHER_GETS_TOUCHED,
10017 player->index_bit, center_side);
10018 CheckElementChangeByPlayer(x, y, center_element, CE_TOUCHED_BY_PLAYER,
10019 player->index_bit, center_side);
10027 void TestIfElementTouchesCustomElement(int x, int y)
10029 static int xy[4][2] =
10036 static int trigger_sides[4][2] =
10038 /* center side border side */
10039 { CH_SIDE_TOP, CH_SIDE_BOTTOM }, /* check top */
10040 { CH_SIDE_LEFT, CH_SIDE_RIGHT }, /* check left */
10041 { CH_SIDE_RIGHT, CH_SIDE_LEFT }, /* check right */
10042 { CH_SIDE_BOTTOM, CH_SIDE_TOP } /* check bottom */
10044 static int touch_dir[4] =
10046 MV_LEFT | MV_RIGHT,
10051 boolean change_center_element = FALSE;
10052 int center_element_change_page = 0;
10053 int center_element = Feld[x][y]; /* should always be non-moving! */
10054 int border_trigger_element = EL_UNDEFINED;
10057 for (i = 0; i < NUM_DIRECTIONS; i++)
10059 int xx = x + xy[i][0];
10060 int yy = y + xy[i][1];
10061 int center_side = trigger_sides[i][0];
10062 int border_side = trigger_sides[i][1];
10063 int border_element;
10065 if (!IN_LEV_FIELD(xx, yy))
10068 if (game.engine_version < VERSION_IDENT(3,0,7,0))
10069 border_element = Feld[xx][yy]; /* may be moving! */
10070 else if (!IS_MOVING(xx, yy) && !IS_BLOCKED(xx, yy))
10071 border_element = Feld[xx][yy];
10072 else if (MovDir[xx][yy] & touch_dir[i]) /* elements are touching */
10073 border_element = MovingOrBlocked2Element(xx, yy);
10075 continue; /* center and border element do not touch */
10077 /* check for change of center element (but change it only once) */
10078 if (IS_CUSTOM_ELEMENT(center_element) &&
10079 HAS_ANY_CHANGE_EVENT(center_element, CE_OTHER_IS_TOUCHING) &&
10080 !change_center_element)
10082 for (j = 0; j < element_info[center_element].num_change_pages; j++)
10084 struct ElementChangeInfo *change =
10085 &element_info[center_element].change_page[j];
10087 if (change->can_change &&
10088 change->events & CH_EVENT_BIT(CE_OTHER_IS_TOUCHING) &&
10089 change->trigger_side & border_side &&
10091 IS_EQUAL_OR_IN_GROUP(border_element, change->trigger_element)
10093 change->trigger_element == border_element
10097 change_center_element = TRUE;
10098 center_element_change_page = j;
10099 border_trigger_element = border_element;
10106 /* check for change of border element */
10107 if (IS_CUSTOM_ELEMENT(border_element) &&
10108 HAS_ANY_CHANGE_EVENT(border_element, CE_OTHER_IS_TOUCHING))
10110 for (j = 0; j < element_info[border_element].num_change_pages; j++)
10112 struct ElementChangeInfo *change =
10113 &element_info[border_element].change_page[j];
10115 if (change->can_change &&
10116 change->events & CH_EVENT_BIT(CE_OTHER_IS_TOUCHING) &&
10117 change->trigger_side & center_side &&
10119 IS_EQUAL_OR_IN_GROUP(center_element, change->trigger_element)
10121 change->trigger_element == center_element
10126 printf("::: border_element %d, %d\n", x, y);
10129 CheckElementChangeByPage(xx, yy, border_element, center_element,
10130 CE_OTHER_IS_TOUCHING, j);
10137 if (change_center_element)
10140 printf("::: center_element %d, %d\n", x, y);
10143 CheckElementChangeByPage(x, y, center_element, border_trigger_element,
10144 CE_OTHER_IS_TOUCHING, center_element_change_page);
10148 void TestIfElementHitsCustomElement(int x, int y, int direction)
10150 int dx = (direction == MV_LEFT ? -1 : direction == MV_RIGHT ? +1 : 0);
10151 int dy = (direction == MV_UP ? -1 : direction == MV_DOWN ? +1 : 0);
10152 int hitx = x + dx, hity = y + dy;
10153 int hitting_element = Feld[x][y];
10154 int touched_element;
10156 boolean object_hit = (IN_LEV_FIELD(hitx, hity) &&
10157 !IS_FREE(hitx, hity) &&
10158 (!IS_MOVING(hitx, hity) ||
10159 MovDir[hitx][hity] != direction ||
10160 ABS(MovPos[hitx][hity]) <= TILEY / 2));
10163 if (IN_LEV_FIELD(hitx, hity) && IS_FREE(hitx, hity))
10167 if (IN_LEV_FIELD(hitx, hity) && !object_hit)
10171 touched_element = (IN_LEV_FIELD(hitx, hity) ?
10172 MovingOrBlocked2Element(hitx, hity) : EL_STEELWALL);
10174 CheckElementChangeBySide(x, y, hitting_element, touched_element,
10175 CE_HITTING_SOMETHING, direction);
10177 if (IN_LEV_FIELD(hitx, hity))
10179 int opposite_direction = MV_DIR_OPPOSITE(direction);
10180 int hitting_side = direction;
10181 int touched_side = opposite_direction;
10183 int touched_element = MovingOrBlocked2Element(hitx, hity);
10186 boolean object_hit = (!IS_MOVING(hitx, hity) ||
10187 MovDir[hitx][hity] != direction ||
10188 ABS(MovPos[hitx][hity]) <= TILEY / 2);
10197 CheckElementChangeBySide(hitx, hity, touched_element, hitting_element,
10198 CE_HIT_BY_SOMETHING, opposite_direction);
10200 if (IS_CUSTOM_ELEMENT(hitting_element) &&
10201 HAS_ANY_CHANGE_EVENT(hitting_element, CE_OTHER_IS_HITTING))
10203 for (i = 0; i < element_info[hitting_element].num_change_pages; i++)
10205 struct ElementChangeInfo *change =
10206 &element_info[hitting_element].change_page[i];
10208 if (change->can_change &&
10209 change->events & CH_EVENT_BIT(CE_OTHER_IS_HITTING) &&
10210 change->trigger_side & touched_side &&
10213 IS_EQUAL_OR_IN_GROUP(touched_element, change->trigger_element)
10215 change->trigger_element == touched_element
10219 CheckElementChangeByPage(x, y, hitting_element, touched_element,
10220 CE_OTHER_IS_HITTING, i);
10226 if (IS_CUSTOM_ELEMENT(touched_element) &&
10227 HAS_ANY_CHANGE_EVENT(touched_element, CE_OTHER_GETS_HIT))
10229 for (i = 0; i < element_info[touched_element].num_change_pages; i++)
10231 struct ElementChangeInfo *change =
10232 &element_info[touched_element].change_page[i];
10234 if (change->can_change &&
10235 change->events & CH_EVENT_BIT(CE_OTHER_GETS_HIT) &&
10236 change->trigger_side & hitting_side &&
10238 IS_EQUAL_OR_IN_GROUP(hitting_element, change->trigger_element)
10240 change->trigger_element == hitting_element
10244 CheckElementChangeByPage(hitx, hity, touched_element,
10245 hitting_element, CE_OTHER_GETS_HIT, i);
10255 void TestIfElementSmashesCustomElement(int x, int y, int direction)
10257 int dx = (direction == MV_LEFT ? -1 : direction == MV_RIGHT ? +1 : 0);
10258 int dy = (direction == MV_UP ? -1 : direction == MV_DOWN ? +1 : 0);
10259 int hitx = x + dx, hity = y + dy;
10260 int hitting_element = Feld[x][y];
10261 int touched_element;
10263 boolean object_hit = (IN_LEV_FIELD(hitx, hity) &&
10264 !IS_FREE(hitx, hity) &&
10265 (!IS_MOVING(hitx, hity) ||
10266 MovDir[hitx][hity] != direction ||
10267 ABS(MovPos[hitx][hity]) <= TILEY / 2));
10270 if (IN_LEV_FIELD(hitx, hity) && IS_FREE(hitx, hity))
10274 if (IN_LEV_FIELD(hitx, hity) && !object_hit)
10278 touched_element = (IN_LEV_FIELD(hitx, hity) ?
10279 MovingOrBlocked2Element(hitx, hity) : EL_STEELWALL);
10281 CheckElementChangeBySide(x, y, hitting_element, touched_element,
10282 EP_CAN_SMASH_EVERYTHING, direction);
10284 if (IN_LEV_FIELD(hitx, hity))
10286 int opposite_direction = MV_DIR_OPPOSITE(direction);
10287 int hitting_side = direction;
10288 int touched_side = opposite_direction;
10290 int touched_element = MovingOrBlocked2Element(hitx, hity);
10293 boolean object_hit = (!IS_MOVING(hitx, hity) ||
10294 MovDir[hitx][hity] != direction ||
10295 ABS(MovPos[hitx][hity]) <= TILEY / 2);
10304 CheckElementChangeBySide(hitx, hity, touched_element, hitting_element,
10305 CE_SMASHED_BY_SOMETHING, opposite_direction);
10307 if (IS_CUSTOM_ELEMENT(hitting_element) &&
10308 HAS_ANY_CHANGE_EVENT(hitting_element, CE_OTHER_IS_SMASHING))
10310 for (i = 0; i < element_info[hitting_element].num_change_pages; i++)
10312 struct ElementChangeInfo *change =
10313 &element_info[hitting_element].change_page[i];
10315 if (change->can_change &&
10316 change->events & CH_EVENT_BIT(CE_OTHER_IS_SMASHING) &&
10317 change->trigger_side & touched_side &&
10320 IS_EQUAL_OR_IN_GROUP(touched_element, change->trigger_element)
10322 change->trigger_element == touched_element
10326 CheckElementChangeByPage(x, y, hitting_element, touched_element,
10327 CE_OTHER_IS_SMASHING, i);
10333 if (IS_CUSTOM_ELEMENT(touched_element) &&
10334 HAS_ANY_CHANGE_EVENT(touched_element, CE_OTHER_GETS_SMASHED))
10336 for (i = 0; i < element_info[touched_element].num_change_pages; i++)
10338 struct ElementChangeInfo *change =
10339 &element_info[touched_element].change_page[i];
10341 if (change->can_change &&
10342 change->events & CH_EVENT_BIT(CE_OTHER_GETS_SMASHED) &&
10343 change->trigger_side & hitting_side &&
10345 IS_EQUAL_OR_IN_GROUP(hitting_element, change->trigger_element)
10347 change->trigger_element == hitting_element
10351 CheckElementChangeByPage(hitx, hity, touched_element,
10352 hitting_element, CE_OTHER_GETS_SMASHED,i);
10362 void TestIfGoodThingHitsBadThing(int good_x, int good_y, int good_move_dir)
10364 int i, kill_x = -1, kill_y = -1;
10365 int bad_element = -1;
10366 static int test_xy[4][2] =
10373 static int test_dir[4] =
10381 for (i = 0; i < NUM_DIRECTIONS; i++)
10383 int test_x, test_y, test_move_dir, test_element;
10385 test_x = good_x + test_xy[i][0];
10386 test_y = good_y + test_xy[i][1];
10388 if (!IN_LEV_FIELD(test_x, test_y))
10392 (IS_MOVING(test_x, test_y) ? MovDir[test_x][test_y] : MV_NO_MOVING);
10395 test_element = Feld[test_x][test_y];
10397 test_element = MovingOrBlocked2ElementIfNotLeaving(test_x, test_y);
10400 /* 1st case: good thing is moving towards DONT_RUN_INTO style bad thing;
10401 2nd case: DONT_TOUCH style bad thing does not move away from good thing
10403 if ((DONT_RUN_INTO(test_element) && good_move_dir == test_dir[i]) ||
10404 (DONT_TOUCH(test_element) && test_move_dir != test_dir[i]))
10408 bad_element = test_element;
10414 if (kill_x != -1 || kill_y != -1)
10416 if (IS_PLAYER(good_x, good_y))
10418 struct PlayerInfo *player = PLAYERINFO(good_x, good_y);
10421 if (player->shield_deadly_time_left > 0 &&
10422 !IS_INDESTRUCTIBLE(bad_element))
10423 Bang(kill_x, kill_y);
10424 else if (!PLAYER_ENEMY_PROTECTED(good_x, good_y))
10427 if (player->shield_deadly_time_left > 0)
10428 Bang(kill_x, kill_y);
10429 else if (!PLAYER_ENEMY_PROTECTED(good_x, good_y))
10434 Bang(good_x, good_y);
10438 void TestIfBadThingHitsGoodThing(int bad_x, int bad_y, int bad_move_dir)
10440 int i, kill_x = -1, kill_y = -1;
10441 int bad_element = Feld[bad_x][bad_y];
10442 static int test_xy[4][2] =
10449 static int touch_dir[4] =
10451 MV_LEFT | MV_RIGHT,
10456 static int test_dir[4] =
10464 if (bad_element == EL_EXPLOSION) /* skip just exploding bad things */
10467 for (i = 0; i < NUM_DIRECTIONS; i++)
10469 int test_x, test_y, test_move_dir, test_element;
10471 test_x = bad_x + test_xy[i][0];
10472 test_y = bad_y + test_xy[i][1];
10473 if (!IN_LEV_FIELD(test_x, test_y))
10477 (IS_MOVING(test_x, test_y) ? MovDir[test_x][test_y] : MV_NO_MOVING);
10479 test_element = Feld[test_x][test_y];
10481 /* 1st case: good thing is moving towards DONT_RUN_INTO style bad thing;
10482 2nd case: DONT_TOUCH style bad thing does not move away from good thing
10484 if ((DONT_RUN_INTO(bad_element) && bad_move_dir == test_dir[i]) ||
10485 (DONT_TOUCH(bad_element) && test_move_dir != test_dir[i]))
10487 /* good thing is player or penguin that does not move away */
10488 if (IS_PLAYER(test_x, test_y))
10490 struct PlayerInfo *player = PLAYERINFO(test_x, test_y);
10492 if (bad_element == EL_ROBOT && player->is_moving)
10493 continue; /* robot does not kill player if he is moving */
10495 if (game.engine_version >= VERSION_IDENT(3,0,7,0))
10497 if (player->MovPos != 0 && !(player->MovDir & touch_dir[i]))
10498 continue; /* center and border element do not touch */
10505 else if (test_element == EL_PENGUIN)
10514 if (kill_x != -1 || kill_y != -1)
10516 if (IS_PLAYER(kill_x, kill_y))
10518 struct PlayerInfo *player = PLAYERINFO(kill_x, kill_y);
10521 if (player->shield_deadly_time_left > 0 &&
10522 !IS_INDESTRUCTIBLE(bad_element))
10523 Bang(bad_x, bad_y);
10524 else if (!PLAYER_ENEMY_PROTECTED(kill_x, kill_y))
10527 if (player->shield_deadly_time_left > 0)
10528 Bang(bad_x, bad_y);
10529 else if (!PLAYER_ENEMY_PROTECTED(kill_x, kill_y))
10534 Bang(kill_x, kill_y);
10538 void TestIfHeroTouchesBadThing(int x, int y)
10540 TestIfGoodThingHitsBadThing(x, y, MV_NO_MOVING);
10543 void TestIfHeroRunsIntoBadThing(int x, int y, int move_dir)
10545 TestIfGoodThingHitsBadThing(x, y, move_dir);
10548 void TestIfBadThingTouchesHero(int x, int y)
10550 TestIfBadThingHitsGoodThing(x, y, MV_NO_MOVING);
10553 void TestIfBadThingRunsIntoHero(int x, int y, int move_dir)
10555 TestIfBadThingHitsGoodThing(x, y, move_dir);
10558 void TestIfFriendTouchesBadThing(int x, int y)
10560 TestIfGoodThingHitsBadThing(x, y, MV_NO_MOVING);
10563 void TestIfBadThingTouchesFriend(int x, int y)
10565 TestIfBadThingHitsGoodThing(x, y, MV_NO_MOVING);
10568 void TestIfBadThingTouchesOtherBadThing(int bad_x, int bad_y)
10570 int i, kill_x = bad_x, kill_y = bad_y;
10571 static int xy[4][2] =
10579 for (i = 0; i < NUM_DIRECTIONS; i++)
10583 x = bad_x + xy[i][0];
10584 y = bad_y + xy[i][1];
10585 if (!IN_LEV_FIELD(x, y))
10588 element = Feld[x][y];
10589 if (IS_AMOEBOID(element) || element == EL_GAME_OF_LIFE ||
10590 element == EL_AMOEBA_GROWING || element == EL_AMOEBA_DROP)
10598 if (kill_x != bad_x || kill_y != bad_y)
10599 Bang(bad_x, bad_y);
10602 void KillHero(struct PlayerInfo *player)
10604 int jx = player->jx, jy = player->jy;
10606 if (!player->active)
10609 /* remove accessible field at the player's position */
10610 Feld[jx][jy] = EL_EMPTY;
10612 /* deactivate shield (else Bang()/Explode() would not work right) */
10613 player->shield_normal_time_left = 0;
10614 player->shield_deadly_time_left = 0;
10620 static void KillHeroUnlessEnemyProtected(int x, int y)
10622 if (!PLAYER_ENEMY_PROTECTED(x, y))
10623 KillHero(PLAYERINFO(x, y));
10626 static void KillHeroUnlessExplosionProtected(int x, int y)
10628 if (!PLAYER_EXPLOSION_PROTECTED(x, y))
10629 KillHero(PLAYERINFO(x, y));
10632 void BuryHero(struct PlayerInfo *player)
10634 int jx = player->jx, jy = player->jy;
10636 if (!player->active)
10640 PlayLevelSoundElementAction(jx, jy, player->element_nr, ACTION_DYING);
10642 PlayLevelSound(jx, jy, SND_CLASS_PLAYER_DYING);
10644 PlayLevelSound(jx, jy, SND_GAME_LOSING);
10646 player->GameOver = TRUE;
10647 RemoveHero(player);
10650 void RemoveHero(struct PlayerInfo *player)
10652 int jx = player->jx, jy = player->jy;
10653 int i, found = FALSE;
10655 player->present = FALSE;
10656 player->active = FALSE;
10658 if (!ExplodeField[jx][jy])
10659 StorePlayer[jx][jy] = 0;
10661 for (i = 0; i < MAX_PLAYERS; i++)
10662 if (stored_player[i].active)
10666 AllPlayersGone = TRUE;
10673 =============================================================================
10674 checkDiagonalPushing()
10675 -----------------------------------------------------------------------------
10676 check if diagonal input device direction results in pushing of object
10677 (by checking if the alternative direction is walkable, diggable, ...)
10678 =============================================================================
10681 static boolean checkDiagonalPushing(struct PlayerInfo *player,
10682 int x, int y, int real_dx, int real_dy)
10684 int jx, jy, dx, dy, xx, yy;
10686 if (real_dx == 0 || real_dy == 0) /* no diagonal direction => push */
10689 /* diagonal direction: check alternative direction */
10694 xx = jx + (dx == 0 ? real_dx : 0);
10695 yy = jy + (dy == 0 ? real_dy : 0);
10697 return (!IN_LEV_FIELD(xx, yy) || IS_SOLID_FOR_PUSHING(Feld[xx][yy]));
10701 =============================================================================
10703 -----------------------------------------------------------------------------
10704 x, y: field next to player (non-diagonal) to try to dig to
10705 real_dx, real_dy: direction as read from input device (can be diagonal)
10706 =============================================================================
10709 int DigField(struct PlayerInfo *player,
10710 int oldx, int oldy, int x, int y,
10711 int real_dx, int real_dy, int mode)
10714 boolean use_spring_bug = (game.engine_version < VERSION_IDENT(2,2,0,0));
10716 boolean is_player = (IS_PLAYER(oldx, oldy) || mode != DF_DIG);
10717 boolean player_was_pushing = player->is_pushing;
10718 int jx = oldx, jy = oldy;
10719 int dx = x - jx, dy = y - jy;
10720 int nextx = x + dx, nexty = y + dy;
10721 int move_direction = (dx == -1 ? MV_LEFT :
10722 dx == +1 ? MV_RIGHT :
10724 dy == +1 ? MV_DOWN : MV_NO_MOVING);
10725 int opposite_direction = MV_DIR_OPPOSITE(move_direction);
10727 int dig_side = MV_DIR_OPPOSITE(move_direction);
10729 static int trigger_sides[4] =
10731 CH_SIDE_RIGHT, /* moving left */
10732 CH_SIDE_LEFT, /* moving right */
10733 CH_SIDE_BOTTOM, /* moving up */
10734 CH_SIDE_TOP, /* moving down */
10736 int dig_side = trigger_sides[MV_DIR_BIT(move_direction)];
10738 int old_element = Feld[jx][jy];
10741 if (is_player) /* function can also be called by EL_PENGUIN */
10743 if (player->MovPos == 0)
10745 player->is_digging = FALSE;
10746 player->is_collecting = FALSE;
10749 if (player->MovPos == 0) /* last pushing move finished */
10750 player->is_pushing = FALSE;
10752 if (mode == DF_NO_PUSH) /* player just stopped pushing */
10754 player->is_switching = FALSE;
10755 player->push_delay = 0;
10757 return MF_NO_ACTION;
10761 if (IS_MOVING(x, y) || IS_PLAYER(x, y))
10762 return MF_NO_ACTION;
10767 if (IS_TUBE(Feld[jx][jy]) || IS_TUBE(Back[jx][jy]))
10769 if (IS_TUBE(Feld[jx][jy]) ||
10770 (IS_TUBE(Back[jx][jy]) && game.engine_version >= VERSION_IDENT(2,2,0,0)))
10774 int tube_element = (IS_TUBE(Feld[jx][jy]) ? Feld[jx][jy] : Back[jx][jy]);
10775 int tube_leave_directions[][2] =
10777 { EL_TUBE_ANY, MV_LEFT | MV_RIGHT | MV_UP | MV_DOWN },
10778 { EL_TUBE_VERTICAL, MV_UP | MV_DOWN },
10779 { EL_TUBE_HORIZONTAL, MV_LEFT | MV_RIGHT },
10780 { EL_TUBE_VERTICAL_LEFT, MV_LEFT | MV_UP | MV_DOWN },
10781 { EL_TUBE_VERTICAL_RIGHT, MV_RIGHT | MV_UP | MV_DOWN },
10782 { EL_TUBE_HORIZONTAL_UP, MV_LEFT | MV_RIGHT | MV_UP },
10783 { EL_TUBE_HORIZONTAL_DOWN, MV_LEFT | MV_RIGHT | MV_DOWN },
10784 { EL_TUBE_LEFT_UP, MV_LEFT | MV_UP },
10785 { EL_TUBE_LEFT_DOWN, MV_LEFT | MV_DOWN },
10786 { EL_TUBE_RIGHT_UP, MV_RIGHT | MV_UP },
10787 { EL_TUBE_RIGHT_DOWN, MV_RIGHT | MV_DOWN },
10788 { -1, MV_LEFT | MV_RIGHT | MV_UP | MV_DOWN }
10791 while (tube_leave_directions[i][0] != tube_element)
10794 if (tube_leave_directions[i][0] == -1) /* should not happen */
10798 if (!(tube_leave_directions[i][1] & move_direction))
10799 return MF_NO_ACTION; /* tube has no opening in this direction */
10804 if (IS_TUBE(Back[jx][jy]) && game.engine_version >= VERSION_IDENT(2,2,0,0))
10805 old_element = Back[jx][jy];
10809 if (IS_WALKABLE(old_element) && !ACCESS_FROM(old_element, move_direction))
10810 return MF_NO_ACTION; /* field has no opening in this direction */
10812 if (IS_PASSABLE(old_element) && !ACCESS_FROM(old_element,opposite_direction))
10813 return MF_NO_ACTION; /* field has no opening in this direction */
10815 element = Feld[x][y];
10817 if (!is_player && !IS_COLLECTIBLE(element)) /* penguin cannot collect it */
10818 return MF_NO_ACTION;
10820 if (mode == DF_SNAP && !IS_SNAPPABLE(element) &&
10821 game.engine_version >= VERSION_IDENT(2,2,0,0))
10822 return MF_NO_ACTION;
10825 if (game.gravity && is_player && !player->is_auto_moving &&
10826 canFallDown(player) && move_direction != MV_DOWN &&
10827 !canMoveToValidFieldWithGravity(jx, jy, move_direction))
10828 return MF_NO_ACTION; /* player cannot walk here due to gravity */
10832 if (element == EL_EMPTY_SPACE &&
10833 game.gravity && !player->is_auto_moving &&
10834 canFallDown(player) && move_direction != MV_DOWN)
10835 return MF_NO_ACTION; /* player cannot walk here due to gravity */
10841 case EL_SP_PORT_LEFT:
10842 case EL_SP_PORT_RIGHT:
10843 case EL_SP_PORT_UP:
10844 case EL_SP_PORT_DOWN:
10845 case EL_SP_PORT_HORIZONTAL:
10846 case EL_SP_PORT_VERTICAL:
10847 case EL_SP_PORT_ANY:
10848 case EL_SP_GRAVITY_PORT_LEFT:
10849 case EL_SP_GRAVITY_PORT_RIGHT:
10850 case EL_SP_GRAVITY_PORT_UP:
10851 case EL_SP_GRAVITY_PORT_DOWN:
10853 if (!canEnterSupaplexPort(x, y, dx, dy))
10854 return MF_NO_ACTION;
10857 element != EL_SP_PORT_LEFT &&
10858 element != EL_SP_GRAVITY_PORT_LEFT &&
10859 element != EL_SP_PORT_HORIZONTAL &&
10860 element != EL_SP_PORT_ANY) ||
10862 element != EL_SP_PORT_RIGHT &&
10863 element != EL_SP_GRAVITY_PORT_RIGHT &&
10864 element != EL_SP_PORT_HORIZONTAL &&
10865 element != EL_SP_PORT_ANY) ||
10867 element != EL_SP_PORT_UP &&
10868 element != EL_SP_GRAVITY_PORT_UP &&
10869 element != EL_SP_PORT_VERTICAL &&
10870 element != EL_SP_PORT_ANY) ||
10872 element != EL_SP_PORT_DOWN &&
10873 element != EL_SP_GRAVITY_PORT_DOWN &&
10874 element != EL_SP_PORT_VERTICAL &&
10875 element != EL_SP_PORT_ANY) ||
10876 !IN_LEV_FIELD(nextx, nexty) ||
10877 !IS_FREE(nextx, nexty))
10878 return MF_NO_ACTION;
10881 if (element == EL_SP_GRAVITY_PORT_LEFT ||
10882 element == EL_SP_GRAVITY_PORT_RIGHT ||
10883 element == EL_SP_GRAVITY_PORT_UP ||
10884 element == EL_SP_GRAVITY_PORT_DOWN)
10885 game.gravity = !game.gravity;
10887 /* automatically move to the next field with double speed */
10888 player->programmed_action = move_direction;
10890 if (player->move_delay_reset_counter == 0)
10892 player->move_delay_reset_counter = 2; /* two double speed steps */
10894 DOUBLE_PLAYER_SPEED(player);
10897 player->move_delay_reset_counter = 2;
10899 DOUBLE_PLAYER_SPEED(player);
10903 printf("::: passing port %d,%d [%d]\n", x, y, FrameCounter);
10906 PlayLevelSound(x, y, SND_CLASS_SP_PORT_PASSING);
10912 case EL_TUBE_VERTICAL:
10913 case EL_TUBE_HORIZONTAL:
10914 case EL_TUBE_VERTICAL_LEFT:
10915 case EL_TUBE_VERTICAL_RIGHT:
10916 case EL_TUBE_HORIZONTAL_UP:
10917 case EL_TUBE_HORIZONTAL_DOWN:
10918 case EL_TUBE_LEFT_UP:
10919 case EL_TUBE_LEFT_DOWN:
10920 case EL_TUBE_RIGHT_UP:
10921 case EL_TUBE_RIGHT_DOWN:
10924 int tube_enter_directions[][2] =
10926 { EL_TUBE_ANY, MV_LEFT | MV_RIGHT | MV_UP | MV_DOWN },
10927 { EL_TUBE_VERTICAL, MV_UP | MV_DOWN },
10928 { EL_TUBE_HORIZONTAL, MV_LEFT | MV_RIGHT },
10929 { EL_TUBE_VERTICAL_LEFT, MV_RIGHT | MV_UP | MV_DOWN },
10930 { EL_TUBE_VERTICAL_RIGHT, MV_LEFT | MV_UP | MV_DOWN },
10931 { EL_TUBE_HORIZONTAL_UP, MV_LEFT | MV_RIGHT | MV_DOWN },
10932 { EL_TUBE_HORIZONTAL_DOWN, MV_LEFT | MV_RIGHT | MV_UP },
10933 { EL_TUBE_LEFT_UP, MV_RIGHT | MV_DOWN },
10934 { EL_TUBE_LEFT_DOWN, MV_RIGHT | MV_UP },
10935 { EL_TUBE_RIGHT_UP, MV_LEFT | MV_DOWN },
10936 { EL_TUBE_RIGHT_DOWN, MV_LEFT | MV_UP },
10937 { -1, MV_NO_MOVING }
10940 while (tube_enter_directions[i][0] != element)
10943 if (tube_enter_directions[i][0] == -1) /* should not happen */
10947 if (!(tube_enter_directions[i][1] & move_direction))
10948 return MF_NO_ACTION; /* tube has no opening in this direction */
10950 PlayLevelSound(x, y, SND_CLASS_TUBE_WALKING);
10958 if (IS_WALKABLE(element) && ACCESS_FROM(element, opposite_direction))
10960 if (IS_WALKABLE(element))
10963 int sound_element = SND_ELEMENT(element);
10964 int sound_action = ACTION_WALKING;
10967 if (!ACCESS_FROM(element, opposite_direction))
10968 return MF_NO_ACTION; /* field not accessible from this direction */
10972 if (element == EL_EMPTY_SPACE &&
10973 game.gravity && !player->is_auto_moving &&
10974 canFallDown(player) && move_direction != MV_DOWN)
10975 return MF_NO_ACTION; /* player cannot walk here due to gravity */
10978 if (IS_GATE(element))
10980 if (!player->key[element - EL_GATE_1])
10981 return MF_NO_ACTION;
10983 else if (IS_GATE_GRAY(element))
10985 if (!player->key[element - EL_GATE_1_GRAY])
10986 return MF_NO_ACTION;
10988 else if (element == EL_EXIT_OPEN ||
10989 element == EL_SP_EXIT_OPEN ||
10990 element == EL_SP_EXIT_OPENING)
10992 sound_action = ACTION_PASSING; /* player is passing exit */
10994 else if (element == EL_EMPTY)
10996 sound_action = ACTION_MOVING; /* nothing to walk on */
10999 /* play sound from background or player, whatever is available */
11000 if (element_info[sound_element].sound[sound_action] != SND_UNDEFINED)
11001 PlayLevelSoundElementAction(x, y, sound_element, sound_action);
11003 PlayLevelSoundElementAction(x, y, player->element_nr, sound_action);
11008 else if (IS_PASSABLE(element) && canPassField(x, y, move_direction))
11010 else if (IS_PASSABLE(element))
11014 if (!canPassField(x, y, move_direction))
11015 return MF_NO_ACTION;
11020 if (!IN_LEV_FIELD(nextx, nexty) || IS_PLAYER(nextx, nexty) ||
11021 !IS_WALKABLE_FROM(Feld[nextx][nexty], move_direction) ||
11022 (!level.can_pass_to_walkable && !IS_FREE(nextx, nexty)))
11023 return MF_NO_ACTION;
11025 if (!IN_LEV_FIELD(nextx, nexty) || !IS_FREE(nextx, nexty))
11026 return MF_NO_ACTION;
11031 if (!ACCESS_FROM(element, opposite_direction))
11032 return MF_NO_ACTION; /* field not accessible from this direction */
11034 if (IS_CUSTOM_ELEMENT(element) &&
11035 !ACCESS_FROM(element, opposite_direction))
11036 return MF_NO_ACTION; /* field not accessible from this direction */
11040 if (CAN_MOVE(element)) /* only fixed elements can be passed! */
11041 return MF_NO_ACTION;
11046 if (IS_EM_GATE(element))
11048 if (!player->key[element - EL_EM_GATE_1])
11049 return MF_NO_ACTION;
11051 else if (IS_EM_GATE_GRAY(element))
11053 if (!player->key[element - EL_EM_GATE_1_GRAY])
11054 return MF_NO_ACTION;
11056 else if (IS_SP_PORT(element))
11058 if (element == EL_SP_GRAVITY_PORT_LEFT ||
11059 element == EL_SP_GRAVITY_PORT_RIGHT ||
11060 element == EL_SP_GRAVITY_PORT_UP ||
11061 element == EL_SP_GRAVITY_PORT_DOWN)
11062 game.gravity = !game.gravity;
11063 else if (element == EL_SP_GRAVITY_ON_PORT_LEFT ||
11064 element == EL_SP_GRAVITY_ON_PORT_RIGHT ||
11065 element == EL_SP_GRAVITY_ON_PORT_UP ||
11066 element == EL_SP_GRAVITY_ON_PORT_DOWN)
11067 game.gravity = TRUE;
11068 else if (element == EL_SP_GRAVITY_OFF_PORT_LEFT ||
11069 element == EL_SP_GRAVITY_OFF_PORT_RIGHT ||
11070 element == EL_SP_GRAVITY_OFF_PORT_UP ||
11071 element == EL_SP_GRAVITY_OFF_PORT_DOWN)
11072 game.gravity = FALSE;
11075 /* automatically move to the next field with double speed */
11076 player->programmed_action = move_direction;
11078 if (player->move_delay_reset_counter == 0)
11080 player->move_delay_reset_counter = 2; /* two double speed steps */
11082 DOUBLE_PLAYER_SPEED(player);
11085 player->move_delay_reset_counter = 2;
11087 DOUBLE_PLAYER_SPEED(player);
11090 PlayLevelSoundAction(x, y, ACTION_PASSING);
11094 else if (IS_DIGGABLE(element))
11098 if (mode != DF_SNAP)
11101 GfxElement[x][y] = GFX_ELEMENT(element);
11104 (GFX_CRUMBLED(element) ? EL_SAND : GFX_ELEMENT(element));
11106 player->is_digging = TRUE;
11109 PlayLevelSoundElementAction(x, y, element, ACTION_DIGGING);
11111 CheckTriggeredElementChangeByPlayer(x, y, element,CE_OTHER_GETS_DIGGED,
11112 player->index_bit, dig_side);
11115 if (mode == DF_SNAP)
11116 TestIfElementTouchesCustomElement(x, y); /* for empty space */
11121 else if (IS_COLLECTIBLE(element))
11125 if (is_player && mode != DF_SNAP)
11127 GfxElement[x][y] = element;
11128 player->is_collecting = TRUE;
11131 if (element == EL_SPEED_PILL)
11132 player->move_delay_value = MOVE_DELAY_HIGH_SPEED;
11133 else if (element == EL_EXTRA_TIME && level.time > 0)
11136 DrawGameValue_Time(TimeLeft);
11138 else if (element == EL_SHIELD_NORMAL || element == EL_SHIELD_DEADLY)
11140 player->shield_normal_time_left += 10;
11141 if (element == EL_SHIELD_DEADLY)
11142 player->shield_deadly_time_left += 10;
11144 else if (element == EL_DYNAMITE || element == EL_SP_DISK_RED)
11146 if (player->inventory_size < MAX_INVENTORY_SIZE)
11147 player->inventory_element[player->inventory_size++] = element;
11149 DrawGameValue_Dynamite(local_player->inventory_size);
11151 else if (element == EL_DYNABOMB_INCREASE_NUMBER)
11153 player->dynabomb_count++;
11154 player->dynabombs_left++;
11156 else if (element == EL_DYNABOMB_INCREASE_SIZE)
11158 player->dynabomb_size++;
11160 else if (element == EL_DYNABOMB_INCREASE_POWER)
11162 player->dynabomb_xl = TRUE;
11164 else if ((element >= EL_KEY_1 && element <= EL_KEY_4) ||
11165 (element >= EL_EM_KEY_1 && element <= EL_EM_KEY_4))
11167 int key_nr = (element >= EL_KEY_1 && element <= EL_KEY_4 ?
11168 element - EL_KEY_1 : element - EL_EM_KEY_1);
11170 player->key[key_nr] = TRUE;
11172 DrawGameValue_Keys(player);
11174 redraw_mask |= REDRAW_DOOR_1;
11176 else if (IS_ENVELOPE(element))
11179 player->show_envelope = element;
11181 ShowEnvelope(element - EL_ENVELOPE_1);
11184 else if (IS_DROPPABLE(element) ||
11185 IS_THROWABLE(element)) /* can be collected and dropped */
11189 if (element_info[element].collect_count == 0)
11190 player->inventory_infinite_element = element;
11192 for (i = 0; i < element_info[element].collect_count; i++)
11193 if (player->inventory_size < MAX_INVENTORY_SIZE)
11194 player->inventory_element[player->inventory_size++] = element;
11196 DrawGameValue_Dynamite(local_player->inventory_size);
11198 else if (element_info[element].collect_count > 0)
11200 local_player->gems_still_needed -=
11201 element_info[element].collect_count;
11202 if (local_player->gems_still_needed < 0)
11203 local_player->gems_still_needed = 0;
11205 DrawGameValue_Emeralds(local_player->gems_still_needed);
11208 RaiseScoreElement(element);
11209 PlayLevelSoundElementAction(x, y, element, ACTION_COLLECTING);
11212 CheckTriggeredElementChangeByPlayer(x, y, element,
11213 CE_OTHER_GETS_COLLECTED,
11214 player->index_bit, dig_side);
11217 if (mode == DF_SNAP)
11218 TestIfElementTouchesCustomElement(x, y); /* for empty space */
11223 else if (IS_PUSHABLE(element))
11225 if (mode == DF_SNAP && element != EL_BD_ROCK)
11226 return MF_NO_ACTION;
11228 if (CAN_FALL(element) && dy)
11229 return MF_NO_ACTION;
11231 if (CAN_FALL(element) && IN_LEV_FIELD(x, y + 1) && IS_FREE(x, y + 1) &&
11232 !(element == EL_SPRING && level.use_spring_bug))
11233 return MF_NO_ACTION;
11236 if (CAN_MOVE(element) && GET_MAX_MOVE_DELAY(element) == 0 &&
11237 ((move_direction & MV_VERTICAL &&
11238 ((element_info[element].move_pattern & MV_LEFT &&
11239 IN_LEV_FIELD(x - 1, y) && IS_FREE(x - 1, y)) ||
11240 (element_info[element].move_pattern & MV_RIGHT &&
11241 IN_LEV_FIELD(x + 1, y) && IS_FREE(x + 1, y)))) ||
11242 (move_direction & MV_HORIZONTAL &&
11243 ((element_info[element].move_pattern & MV_UP &&
11244 IN_LEV_FIELD(x, y - 1) && IS_FREE(x, y - 1)) ||
11245 (element_info[element].move_pattern & MV_DOWN &&
11246 IN_LEV_FIELD(x, y + 1) && IS_FREE(x, y + 1))))))
11247 return MF_NO_ACTION;
11251 /* do not push elements already moving away faster than player */
11252 if (CAN_MOVE(element) && MovDir[x][y] == move_direction &&
11253 ABS(getElementMoveStepsize(x, y)) > MOVE_STEPSIZE_NORMAL)
11254 return MF_NO_ACTION;
11256 if (element == EL_SPRING && MovDir[x][y] != MV_NO_MOVING)
11257 return MF_NO_ACTION;
11263 if (game.engine_version >= VERSION_IDENT(3,1,0,0))
11265 if (player->push_delay_value == -1 || !player_was_pushing)
11266 player->push_delay_value = GET_NEW_PUSH_DELAY(element);
11268 else if (game.engine_version >= VERSION_IDENT(3,0,7,1))
11270 if (player->push_delay_value == -1)
11271 player->push_delay_value = GET_NEW_PUSH_DELAY(element);
11274 if (game.engine_version >= VERSION_IDENT(3,0,7,1))
11276 if (player->push_delay_value == -1 || !player_was_pushing)
11277 player->push_delay_value = GET_NEW_PUSH_DELAY(element);
11280 else if (game.engine_version >= VERSION_IDENT(2,2,0,7))
11282 if (!player->is_pushing)
11283 player->push_delay_value = GET_NEW_PUSH_DELAY(element);
11287 if (game.engine_version >= VERSION_IDENT(2,2,0,7) &&
11288 (game.engine_version < VERSION_IDENT(3,0,7,1) ||
11289 !player_is_pushing))
11290 player->push_delay_value = GET_NEW_PUSH_DELAY(element);
11293 if (!player->is_pushing &&
11294 game.engine_version >= VERSION_IDENT(2,2,0,7))
11295 player->push_delay_value = GET_NEW_PUSH_DELAY(element);
11299 printf("::: push delay: %ld -> %ld [%d, %d] [%d / %d] [%d '%s': %d]\n",
11300 player->push_delay, player->push_delay_value,
11301 FrameCounter, game.engine_version,
11302 player_was_pushing, player->is_pushing,
11303 element, element_info[element].token_name,
11304 GET_NEW_PUSH_DELAY(element));
11307 player->is_pushing = TRUE;
11309 if (!(IN_LEV_FIELD(nextx, nexty) &&
11310 (IS_FREE(nextx, nexty) ||
11311 (Feld[nextx][nexty] == EL_SOKOBAN_FIELD_EMPTY &&
11312 IS_SB_ELEMENT(element)))))
11313 return MF_NO_ACTION;
11315 if (!checkDiagonalPushing(player, x, y, real_dx, real_dy))
11316 return MF_NO_ACTION;
11318 if (player->push_delay == 0) /* new pushing; restart delay */
11319 player->push_delay = FrameCounter;
11321 if (!FrameReached(&player->push_delay, player->push_delay_value) &&
11322 !(tape.playing && tape.file_version < FILE_VERSION_2_0) &&
11323 element != EL_SPRING && element != EL_BALLOON)
11325 /* make sure that there is no move delay before next try to push */
11326 if (game.engine_version >= VERSION_IDENT(3,0,7,1))
11327 player->move_delay = INITIAL_MOVE_DELAY_OFF;
11329 return MF_NO_ACTION;
11333 printf("::: NOW PUSHING... [%d]\n", FrameCounter);
11336 if (IS_SB_ELEMENT(element))
11338 if (element == EL_SOKOBAN_FIELD_FULL)
11340 Back[x][y] = EL_SOKOBAN_FIELD_EMPTY;
11341 local_player->sokobanfields_still_needed++;
11344 if (Feld[nextx][nexty] == EL_SOKOBAN_FIELD_EMPTY)
11346 Back[nextx][nexty] = EL_SOKOBAN_FIELD_EMPTY;
11347 local_player->sokobanfields_still_needed--;
11350 Feld[x][y] = EL_SOKOBAN_OBJECT;
11352 if (Back[x][y] == Back[nextx][nexty])
11353 PlayLevelSoundAction(x, y, ACTION_PUSHING);
11354 else if (Back[x][y] != 0)
11355 PlayLevelSoundElementAction(x, y, EL_SOKOBAN_FIELD_FULL,
11358 PlayLevelSoundElementAction(nextx, nexty, EL_SOKOBAN_FIELD_EMPTY,
11361 if (local_player->sokobanfields_still_needed == 0 &&
11362 game.emulation == EMU_SOKOBAN)
11364 player->LevelSolved = player->GameOver = TRUE;
11365 PlayLevelSound(x, y, SND_GAME_SOKOBAN_SOLVING);
11369 PlayLevelSoundElementAction(x, y, element, ACTION_PUSHING);
11371 InitMovingField(x, y, move_direction);
11372 GfxAction[x][y] = ACTION_PUSHING;
11374 if (mode == DF_SNAP)
11375 ContinueMoving(x, y);
11377 MovPos[x][y] = (dx != 0 ? dx : dy);
11379 Pushed[x][y] = TRUE;
11380 Pushed[nextx][nexty] = TRUE;
11382 if (game.engine_version < VERSION_IDENT(2,2,0,7))
11383 player->push_delay_value = GET_NEW_PUSH_DELAY(element);
11385 player->push_delay_value = -1; /* get new value later */
11388 /* check for element change _after_ element has been pushed! */
11392 /* !!! TEST ONLY !!! */
11393 CheckElementChangeByPlayer(x, y, element, CE_PUSHED_BY_PLAYER,
11394 player->index_bit, dig_side);
11395 CheckTriggeredElementChangeByPlayer(x, y, element,CE_OTHER_GETS_PUSHED,
11396 player->index_bit, dig_side);
11398 CheckTriggeredElementChangeByPlayer(x, y, element,CE_OTHER_GETS_PUSHED,
11399 player->index_bit, dig_side);
11400 CheckElementChangeByPlayer(x, y, element, CE_PUSHED_BY_PLAYER,
11401 player->index_bit, dig_side);
11407 else if (IS_SWITCHABLE(element))
11409 if (PLAYER_SWITCHING(player, x, y))
11411 CheckTriggeredElementChangeByPlayer(x,y, element,
11412 CE_OTHER_GETS_PRESSED,
11413 player->index_bit, dig_side);
11418 player->is_switching = TRUE;
11419 player->switch_x = x;
11420 player->switch_y = y;
11422 PlayLevelSoundElementAction(x, y, element, ACTION_ACTIVATING);
11424 if (element == EL_ROBOT_WHEEL)
11426 Feld[x][y] = EL_ROBOT_WHEEL_ACTIVE;
11430 DrawLevelField(x, y);
11432 else if (element == EL_SP_TERMINAL)
11436 for (yy = 0; yy < lev_fieldy; yy++) for (xx=0; xx < lev_fieldx; xx++)
11438 if (Feld[xx][yy] == EL_SP_DISK_YELLOW)
11440 else if (Feld[xx][yy] == EL_SP_TERMINAL)
11441 Feld[xx][yy] = EL_SP_TERMINAL_ACTIVE;
11444 else if (IS_BELT_SWITCH(element))
11446 ToggleBeltSwitch(x, y);
11448 else if (element == EL_SWITCHGATE_SWITCH_UP ||
11449 element == EL_SWITCHGATE_SWITCH_DOWN)
11451 ToggleSwitchgateSwitch(x, y);
11453 else if (element == EL_LIGHT_SWITCH ||
11454 element == EL_LIGHT_SWITCH_ACTIVE)
11456 ToggleLightSwitch(x, y);
11459 PlayLevelSound(x, y, element == EL_LIGHT_SWITCH ?
11460 SND_LIGHT_SWITCH_ACTIVATING :
11461 SND_LIGHT_SWITCH_DEACTIVATING);
11464 else if (element == EL_TIMEGATE_SWITCH)
11466 ActivateTimegateSwitch(x, y);
11468 else if (element == EL_BALLOON_SWITCH_LEFT ||
11469 element == EL_BALLOON_SWITCH_RIGHT ||
11470 element == EL_BALLOON_SWITCH_UP ||
11471 element == EL_BALLOON_SWITCH_DOWN ||
11472 element == EL_BALLOON_SWITCH_ANY)
11474 if (element == EL_BALLOON_SWITCH_ANY)
11475 game.balloon_dir = move_direction;
11477 game.balloon_dir = (element == EL_BALLOON_SWITCH_LEFT ? MV_LEFT :
11478 element == EL_BALLOON_SWITCH_RIGHT ? MV_RIGHT :
11479 element == EL_BALLOON_SWITCH_UP ? MV_UP :
11480 element == EL_BALLOON_SWITCH_DOWN ? MV_DOWN :
11483 else if (element == EL_LAMP)
11485 Feld[x][y] = EL_LAMP_ACTIVE;
11486 local_player->lights_still_needed--;
11488 DrawLevelField(x, y);
11490 else if (element == EL_TIME_ORB_FULL)
11492 Feld[x][y] = EL_TIME_ORB_EMPTY;
11494 DrawGameValue_Time(TimeLeft);
11496 DrawLevelField(x, y);
11499 PlaySoundStereo(SND_TIME_ORB_FULL_COLLECTING, SOUND_MIDDLE);
11503 CheckTriggeredElementChangeByPlayer(x, y, element,
11504 CE_OTHER_IS_SWITCHING,
11505 player->index_bit, dig_side);
11507 CheckTriggeredElementChangeByPlayer(x,y, element,CE_OTHER_GETS_PRESSED,
11508 player->index_bit, dig_side);
11514 if (!PLAYER_SWITCHING(player, x, y))
11516 player->is_switching = TRUE;
11517 player->switch_x = x;
11518 player->switch_y = y;
11521 /* !!! TEST ONLY !!! */
11522 CheckElementChangeByPlayer(x, y, element, CE_SWITCHED,
11523 player->index_bit, dig_side);
11524 CheckTriggeredElementChangeByPlayer(x, y, element,
11525 CE_OTHER_IS_SWITCHING,
11526 player->index_bit, dig_side);
11528 CheckTriggeredElementChangeByPlayer(x, y, element,
11529 CE_OTHER_IS_SWITCHING,
11530 player->index_bit, dig_side);
11531 CheckElementChangeByPlayer(x, y, element, CE_SWITCHED,
11532 player->index_bit, dig_side);
11537 /* !!! TEST ONLY !!! (this breaks "machine", level 000) */
11538 CheckElementChangeByPlayer(x, y, element, CE_PRESSED_BY_PLAYER,
11539 player->index_bit, dig_side);
11540 CheckTriggeredElementChangeByPlayer(x,y, element,CE_OTHER_GETS_PRESSED,
11541 player->index_bit, dig_side);
11543 CheckTriggeredElementChangeByPlayer(x,y, element,CE_OTHER_GETS_PRESSED,
11544 player->index_bit, dig_side);
11545 CheckElementChangeByPlayer(x, y, element, CE_PRESSED_BY_PLAYER,
11546 player->index_bit, dig_side);
11550 return MF_NO_ACTION;
11553 player->push_delay = 0;
11555 if (Feld[x][y] != element) /* really digged/collected something */
11556 player->is_collecting = !player->is_digging;
11561 boolean SnapField(struct PlayerInfo *player, int dx, int dy)
11563 int jx = player->jx, jy = player->jy;
11564 int x = jx + dx, y = jy + dy;
11565 int snap_direction = (dx == -1 ? MV_LEFT :
11566 dx == +1 ? MV_RIGHT :
11568 dy == +1 ? MV_DOWN : MV_NO_MOVING);
11571 if (player->MovPos != 0)
11574 if (player->MovPos != 0 && game.engine_version >= VERSION_IDENT(2,2,0,0))
11578 if (!player->active || !IN_LEV_FIELD(x, y))
11586 if (player->MovPos == 0)
11587 player->is_pushing = FALSE;
11589 player->is_snapping = FALSE;
11591 if (player->MovPos == 0)
11593 player->is_moving = FALSE;
11594 player->is_digging = FALSE;
11595 player->is_collecting = FALSE;
11601 if (player->is_snapping)
11604 player->MovDir = snap_direction;
11607 if (player->MovPos == 0)
11610 player->is_moving = FALSE;
11611 player->is_digging = FALSE;
11612 player->is_collecting = FALSE;
11615 player->is_dropping = FALSE;
11617 if (DigField(player, jx, jy, x, y, 0, 0, DF_SNAP) == MF_NO_ACTION)
11620 player->is_snapping = TRUE;
11623 if (player->MovPos == 0)
11626 player->is_moving = FALSE;
11627 player->is_digging = FALSE;
11628 player->is_collecting = FALSE;
11632 if (player->MovPos != 0) /* prevent graphic bugs in versions < 2.2.0 */
11633 DrawLevelField(player->last_jx, player->last_jy);
11636 DrawLevelField(x, y);
11645 boolean DropElement(struct PlayerInfo *player)
11647 int old_element, new_element;
11648 int dropx = player->jx, dropy = player->jy;
11649 int drop_direction = player->MovDir;
11651 int drop_side = drop_direction;
11653 static int trigger_sides[4] =
11655 CH_SIDE_LEFT, /* dropping left */
11656 CH_SIDE_RIGHT, /* dropping right */
11657 CH_SIDE_TOP, /* dropping up */
11658 CH_SIDE_BOTTOM, /* dropping down */
11660 int drop_side = trigger_sides[MV_DIR_BIT(drop_direction)];
11662 int drop_element = (player->inventory_size > 0 ?
11663 player->inventory_element[player->inventory_size - 1] :
11664 player->inventory_infinite_element != EL_UNDEFINED ?
11665 player->inventory_infinite_element :
11666 player->dynabombs_left > 0 ?
11667 EL_DYNABOMB_PLAYER_1_ACTIVE + player->index_nr :
11670 if (IS_THROWABLE(drop_element))
11672 dropx += GET_DX_FROM_DIR(drop_direction);
11673 dropy += GET_DY_FROM_DIR(drop_direction);
11675 if (!IN_LEV_FIELD(dropx, dropy))
11679 old_element = Feld[dropx][dropy]; /* old element at dropping position */
11680 new_element = drop_element; /* default: no change when dropping */
11682 /* check if player is active, not moving and ready to drop */
11683 if (!player->active || player->MovPos || player->drop_delay > 0)
11686 /* check if player has anything that can be dropped */
11688 if (new_element == EL_UNDEFINED)
11691 if (player->inventory_size == 0 &&
11692 player->inventory_infinite_element == EL_UNDEFINED &&
11693 player->dynabombs_left == 0)
11697 /* check if anything can be dropped at the current position */
11698 if (IS_ACTIVE_BOMB(old_element) || old_element == EL_EXPLOSION)
11701 /* collected custom elements can only be dropped on empty fields */
11703 if (IS_CUSTOM_ELEMENT(new_element) && old_element != EL_EMPTY)
11706 if (player->inventory_size > 0 &&
11707 IS_CUSTOM_ELEMENT(player->inventory_element[player->inventory_size - 1])
11708 && old_element != EL_EMPTY)
11712 if (old_element != EL_EMPTY)
11713 Back[dropx][dropy] = old_element; /* store old element on this field */
11715 ResetGfxAnimation(dropx, dropy);
11716 ResetRandomAnimationValue(dropx, dropy);
11718 if (player->inventory_size > 0 ||
11719 player->inventory_infinite_element != EL_UNDEFINED)
11721 if (player->inventory_size > 0)
11723 player->inventory_size--;
11726 new_element = player->inventory_element[player->inventory_size];
11729 DrawGameValue_Dynamite(local_player->inventory_size);
11731 if (new_element == EL_DYNAMITE)
11732 new_element = EL_DYNAMITE_ACTIVE;
11733 else if (new_element == EL_SP_DISK_RED)
11734 new_element = EL_SP_DISK_RED_ACTIVE;
11737 Feld[dropx][dropy] = new_element;
11739 if (IN_SCR_FIELD(SCREENX(dropx), SCREENY(dropy)))
11740 DrawGraphicThruMask(SCREENX(dropx), SCREENY(dropy),
11741 el2img(Feld[dropx][dropy]), 0);
11743 PlayLevelSoundAction(dropx, dropy, ACTION_DROPPING);
11746 /* needed if previous element just changed to "empty" in the last frame */
11747 Changed[dropx][dropy] = 0; /* allow another change */
11751 /* !!! TEST ONLY !!! */
11752 CheckElementChangeByPlayer(dropx, dropy, new_element, CE_DROPPED_BY_PLAYER,
11753 player->index_bit, drop_side);
11754 CheckTriggeredElementChangeByPlayer(dropx, dropy, new_element,
11755 CE_OTHER_GETS_DROPPED,
11756 player->index_bit, drop_side);
11758 CheckTriggeredElementChangeByPlayer(dropx, dropy, new_element,
11759 CE_OTHER_GETS_DROPPED,
11760 player->index_bit, drop_side);
11761 CheckElementChangeByPlayer(dropx, dropy, new_element, CE_DROPPED_BY_PLAYER,
11762 player->index_bit, drop_side);
11765 TestIfElementTouchesCustomElement(dropx, dropy);
11767 else /* player is dropping a dyna bomb */
11769 player->dynabombs_left--;
11772 new_element = EL_DYNABOMB_PLAYER_1_ACTIVE + player->index_nr;
11775 Feld[dropx][dropy] = new_element;
11777 if (IN_SCR_FIELD(SCREENX(dropx), SCREENY(dropy)))
11778 DrawGraphicThruMask(SCREENX(dropx), SCREENY(dropy),
11779 el2img(Feld[dropx][dropy]), 0);
11781 PlayLevelSoundAction(dropx, dropy, ACTION_DROPPING);
11788 if (Feld[dropx][dropy] == new_element) /* uninitialized unless CE change */
11791 InitField_WithBug1(dropx, dropy, FALSE);
11793 InitField(dropx, dropy, FALSE);
11794 if (CAN_MOVE(Feld[dropx][dropy]))
11795 InitMovDir(dropx, dropy);
11799 new_element = Feld[dropx][dropy]; /* element might have changed */
11801 if (IS_CUSTOM_ELEMENT(new_element) && CAN_MOVE(new_element) &&
11802 element_info[new_element].move_pattern == MV_WHEN_DROPPED)
11805 int move_stepsize = element_info[new_element].move_stepsize;
11807 int move_direction, nextx, nexty;
11809 if (element_info[new_element].move_direction_initial == MV_START_AUTOMATIC)
11810 MovDir[dropx][dropy] = drop_direction;
11812 move_direction = MovDir[dropx][dropy];
11813 nextx = dropx + GET_DX_FROM_DIR(move_direction);
11814 nexty = dropy + GET_DY_FROM_DIR(move_direction);
11817 Changed[dropx][dropy] = 0; /* allow another change */
11818 CheckCollision[dropx][dropy] = 2;
11821 if (IN_LEV_FIELD_AND_IS_FREE(nextx, nexty))
11824 WasJustMoving[dropx][dropy] = 3;
11827 InitMovingField(dropx, dropy, move_direction);
11828 ContinueMoving(dropx, dropy);
11833 /* !!! commented out from 3.1.0-4 to 3.1.0-5 !!! */
11836 Changed[dropx][dropy] = 0; /* allow another change */
11839 TestIfElementHitsCustomElement(dropx, dropy, move_direction);
11841 CheckElementChangeBySide(dropx, dropy, new_element, touched_element,
11842 CE_HITTING_SOMETHING, move_direction);
11850 player->drop_delay = 2 * TILEX / move_stepsize + 1;
11855 player->drop_delay = 8 + 8 + 8;
11859 player->drop_delay = GET_NEW_DROP_DELAY(drop_element);
11864 player->is_dropping = TRUE;
11870 /* ------------------------------------------------------------------------- */
11871 /* game sound playing functions */
11872 /* ------------------------------------------------------------------------- */
11874 static int *loop_sound_frame = NULL;
11875 static int *loop_sound_volume = NULL;
11877 void InitPlayLevelSound()
11879 int num_sounds = getSoundListSize();
11881 checked_free(loop_sound_frame);
11882 checked_free(loop_sound_volume);
11884 loop_sound_frame = checked_calloc(num_sounds * sizeof(int));
11885 loop_sound_volume = checked_calloc(num_sounds * sizeof(int));
11888 static void PlayLevelSound(int x, int y, int nr)
11890 int sx = SCREENX(x), sy = SCREENY(y);
11891 int volume, stereo_position;
11892 int max_distance = 8;
11893 int type = (IS_LOOP_SOUND(nr) ? SND_CTRL_PLAY_LOOP : SND_CTRL_PLAY_SOUND);
11895 if ((!setup.sound_simple && !IS_LOOP_SOUND(nr)) ||
11896 (!setup.sound_loops && IS_LOOP_SOUND(nr)))
11899 if (!IN_LEV_FIELD(x, y) ||
11900 sx < -max_distance || sx >= SCR_FIELDX + max_distance ||
11901 sy < -max_distance || sy >= SCR_FIELDY + max_distance)
11904 volume = SOUND_MAX_VOLUME;
11906 if (!IN_SCR_FIELD(sx, sy))
11908 int dx = ABS(sx - SCR_FIELDX / 2) - SCR_FIELDX / 2;
11909 int dy = ABS(sy - SCR_FIELDY / 2) - SCR_FIELDY / 2;
11911 volume -= volume * (dx > dy ? dx : dy) / max_distance;
11914 stereo_position = (SOUND_MAX_LEFT +
11915 (sx + max_distance) * SOUND_MAX_LEFT2RIGHT /
11916 (SCR_FIELDX + 2 * max_distance));
11918 if (IS_LOOP_SOUND(nr))
11920 /* This assures that quieter loop sounds do not overwrite louder ones,
11921 while restarting sound volume comparison with each new game frame. */
11923 if (loop_sound_volume[nr] > volume && loop_sound_frame[nr] == FrameCounter)
11926 loop_sound_volume[nr] = volume;
11927 loop_sound_frame[nr] = FrameCounter;
11930 PlaySoundExt(nr, volume, stereo_position, type);
11933 static void PlayLevelSoundNearest(int x, int y, int sound_action)
11935 PlayLevelSound(x < LEVELX(BX1) ? LEVELX(BX1) :
11936 x > LEVELX(BX2) ? LEVELX(BX2) : x,
11937 y < LEVELY(BY1) ? LEVELY(BY1) :
11938 y > LEVELY(BY2) ? LEVELY(BY2) : y,
11942 static void PlayLevelSoundAction(int x, int y, int action)
11944 PlayLevelSoundElementAction(x, y, Feld[x][y], action);
11947 static void PlayLevelSoundElementAction(int x, int y, int element, int action)
11949 int sound_effect = element_info[SND_ELEMENT(element)].sound[action];
11951 if (sound_effect != SND_UNDEFINED)
11952 PlayLevelSound(x, y, sound_effect);
11955 static void PlayLevelSoundElementActionIfLoop(int x, int y, int element,
11958 int sound_effect = element_info[SND_ELEMENT(element)].sound[action];
11960 if (sound_effect != SND_UNDEFINED && IS_LOOP_SOUND(sound_effect))
11961 PlayLevelSound(x, y, sound_effect);
11964 static void PlayLevelSoundActionIfLoop(int x, int y, int action)
11966 int sound_effect = element_info[SND_ELEMENT(Feld[x][y])].sound[action];
11968 if (sound_effect != SND_UNDEFINED && IS_LOOP_SOUND(sound_effect))
11969 PlayLevelSound(x, y, sound_effect);
11972 static void StopLevelSoundActionIfLoop(int x, int y, int action)
11974 int sound_effect = element_info[SND_ELEMENT(Feld[x][y])].sound[action];
11976 if (sound_effect != SND_UNDEFINED && IS_LOOP_SOUND(sound_effect))
11977 StopSound(sound_effect);
11980 static void PlayLevelMusic()
11982 if (levelset.music[level_nr] != MUS_UNDEFINED)
11983 PlayMusic(levelset.music[level_nr]); /* from config file */
11985 PlayMusic(MAP_NOCONF_MUSIC(level_nr)); /* from music dir */
11988 void RaiseScore(int value)
11990 local_player->score += value;
11992 DrawGameValue_Score(local_player->score);
11995 void RaiseScoreElement(int element)
12000 case EL_BD_DIAMOND:
12001 case EL_EMERALD_YELLOW:
12002 case EL_EMERALD_RED:
12003 case EL_EMERALD_PURPLE:
12004 case EL_SP_INFOTRON:
12005 RaiseScore(level.score[SC_EMERALD]);
12008 RaiseScore(level.score[SC_DIAMOND]);
12011 RaiseScore(level.score[SC_CRYSTAL]);
12014 RaiseScore(level.score[SC_PEARL]);
12017 case EL_BD_BUTTERFLY:
12018 case EL_SP_ELECTRON:
12019 RaiseScore(level.score[SC_BUG]);
12022 case EL_BD_FIREFLY:
12023 case EL_SP_SNIKSNAK:
12024 RaiseScore(level.score[SC_SPACESHIP]);
12027 case EL_DARK_YAMYAM:
12028 RaiseScore(level.score[SC_YAMYAM]);
12031 RaiseScore(level.score[SC_ROBOT]);
12034 RaiseScore(level.score[SC_PACMAN]);
12037 RaiseScore(level.score[SC_NUT]);
12040 case EL_SP_DISK_RED:
12041 case EL_DYNABOMB_INCREASE_NUMBER:
12042 case EL_DYNABOMB_INCREASE_SIZE:
12043 case EL_DYNABOMB_INCREASE_POWER:
12044 RaiseScore(level.score[SC_DYNAMITE]);
12046 case EL_SHIELD_NORMAL:
12047 case EL_SHIELD_DEADLY:
12048 RaiseScore(level.score[SC_SHIELD]);
12050 case EL_EXTRA_TIME:
12051 RaiseScore(level.score[SC_TIME_BONUS]);
12057 RaiseScore(level.score[SC_KEY]);
12060 RaiseScore(element_info[element].collect_score);
12065 void RequestQuitGame(boolean ask_if_really_quit)
12067 if (AllPlayersGone ||
12068 !ask_if_really_quit ||
12069 level_editor_test_game ||
12070 Request("Do you really want to quit the game ?",
12071 REQ_ASK | REQ_STAY_CLOSED))
12073 #if defined(NETWORK_AVALIABLE)
12074 if (options.network)
12075 SendToServer_StopPlaying();
12079 game_status = GAME_MODE_MAIN;
12087 if (tape.playing && tape.deactivate_display)
12088 TapeDeactivateDisplayOff(TRUE);
12091 OpenDoor(DOOR_OPEN_1 | DOOR_COPY_BACK);
12094 if (tape.playing && tape.deactivate_display)
12095 TapeDeactivateDisplayOn();
12102 /* ---------- new game button stuff ---------------------------------------- */
12104 /* graphic position values for game buttons */
12105 #define GAME_BUTTON_XSIZE 30
12106 #define GAME_BUTTON_YSIZE 30
12107 #define GAME_BUTTON_XPOS 5
12108 #define GAME_BUTTON_YPOS 215
12109 #define SOUND_BUTTON_XPOS 5
12110 #define SOUND_BUTTON_YPOS (GAME_BUTTON_YPOS + GAME_BUTTON_YSIZE)
12112 #define GAME_BUTTON_STOP_XPOS (GAME_BUTTON_XPOS + 0 * GAME_BUTTON_XSIZE)
12113 #define GAME_BUTTON_PAUSE_XPOS (GAME_BUTTON_XPOS + 1 * GAME_BUTTON_XSIZE)
12114 #define GAME_BUTTON_PLAY_XPOS (GAME_BUTTON_XPOS + 2 * GAME_BUTTON_XSIZE)
12115 #define SOUND_BUTTON_MUSIC_XPOS (SOUND_BUTTON_XPOS + 0 * GAME_BUTTON_XSIZE)
12116 #define SOUND_BUTTON_LOOPS_XPOS (SOUND_BUTTON_XPOS + 1 * GAME_BUTTON_XSIZE)
12117 #define SOUND_BUTTON_SIMPLE_XPOS (SOUND_BUTTON_XPOS + 2 * GAME_BUTTON_XSIZE)
12124 } gamebutton_info[NUM_GAME_BUTTONS] =
12127 GAME_BUTTON_STOP_XPOS, GAME_BUTTON_YPOS,
12132 GAME_BUTTON_PAUSE_XPOS, GAME_BUTTON_YPOS,
12133 GAME_CTRL_ID_PAUSE,
12137 GAME_BUTTON_PLAY_XPOS, GAME_BUTTON_YPOS,
12142 SOUND_BUTTON_MUSIC_XPOS, SOUND_BUTTON_YPOS,
12143 SOUND_CTRL_ID_MUSIC,
12144 "background music on/off"
12147 SOUND_BUTTON_LOOPS_XPOS, SOUND_BUTTON_YPOS,
12148 SOUND_CTRL_ID_LOOPS,
12149 "sound loops on/off"
12152 SOUND_BUTTON_SIMPLE_XPOS, SOUND_BUTTON_YPOS,
12153 SOUND_CTRL_ID_SIMPLE,
12154 "normal sounds on/off"
12158 void CreateGameButtons()
12162 for (i = 0; i < NUM_GAME_BUTTONS; i++)
12164 Bitmap *gd_bitmap = graphic_info[IMG_GLOBAL_DOOR].bitmap;
12165 struct GadgetInfo *gi;
12168 unsigned long event_mask;
12169 int gd_xoffset, gd_yoffset;
12170 int gd_x1, gd_x2, gd_y1, gd_y2;
12173 gd_xoffset = gamebutton_info[i].x;
12174 gd_yoffset = gamebutton_info[i].y;
12175 gd_x1 = DOOR_GFX_PAGEX4 + gd_xoffset;
12176 gd_x2 = DOOR_GFX_PAGEX3 + gd_xoffset;
12178 if (id == GAME_CTRL_ID_STOP ||
12179 id == GAME_CTRL_ID_PAUSE ||
12180 id == GAME_CTRL_ID_PLAY)
12182 button_type = GD_TYPE_NORMAL_BUTTON;
12184 event_mask = GD_EVENT_RELEASED;
12185 gd_y1 = DOOR_GFX_PAGEY1 + gd_yoffset - GAME_BUTTON_YSIZE;
12186 gd_y2 = DOOR_GFX_PAGEY1 + gd_yoffset - GAME_BUTTON_YSIZE;
12190 button_type = GD_TYPE_CHECK_BUTTON;
12192 ((id == SOUND_CTRL_ID_MUSIC && setup.sound_music) ||
12193 (id == SOUND_CTRL_ID_LOOPS && setup.sound_loops) ||
12194 (id == SOUND_CTRL_ID_SIMPLE && setup.sound_simple) ? TRUE : FALSE);
12195 event_mask = GD_EVENT_PRESSED;
12196 gd_y1 = DOOR_GFX_PAGEY1 + gd_yoffset;
12197 gd_y2 = DOOR_GFX_PAGEY1 + gd_yoffset - GAME_BUTTON_YSIZE;
12200 gi = CreateGadget(GDI_CUSTOM_ID, id,
12201 GDI_INFO_TEXT, gamebutton_info[i].infotext,
12202 GDI_X, DX + gd_xoffset,
12203 GDI_Y, DY + gd_yoffset,
12204 GDI_WIDTH, GAME_BUTTON_XSIZE,
12205 GDI_HEIGHT, GAME_BUTTON_YSIZE,
12206 GDI_TYPE, button_type,
12207 GDI_STATE, GD_BUTTON_UNPRESSED,
12208 GDI_CHECKED, checked,
12209 GDI_DESIGN_UNPRESSED, gd_bitmap, gd_x1, gd_y1,
12210 GDI_DESIGN_PRESSED, gd_bitmap, gd_x2, gd_y1,
12211 GDI_ALT_DESIGN_UNPRESSED, gd_bitmap, gd_x1, gd_y2,
12212 GDI_ALT_DESIGN_PRESSED, gd_bitmap, gd_x2, gd_y2,
12213 GDI_EVENT_MASK, event_mask,
12214 GDI_CALLBACK_ACTION, HandleGameButtons,
12218 Error(ERR_EXIT, "cannot create gadget");
12220 game_gadget[id] = gi;
12224 void FreeGameButtons()
12228 for (i = 0; i < NUM_GAME_BUTTONS; i++)
12229 FreeGadget(game_gadget[i]);
12232 static void MapGameButtons()
12236 for (i = 0; i < NUM_GAME_BUTTONS; i++)
12237 MapGadget(game_gadget[i]);
12240 void UnmapGameButtons()
12244 for (i = 0; i < NUM_GAME_BUTTONS; i++)
12245 UnmapGadget(game_gadget[i]);
12248 static void HandleGameButtons(struct GadgetInfo *gi)
12250 int id = gi->custom_id;
12252 if (game_status != GAME_MODE_PLAYING)
12257 case GAME_CTRL_ID_STOP:
12258 RequestQuitGame(TRUE);
12261 case GAME_CTRL_ID_PAUSE:
12262 if (options.network)
12264 #if defined(NETWORK_AVALIABLE)
12266 SendToServer_ContinuePlaying();
12268 SendToServer_PausePlaying();
12272 TapeTogglePause(TAPE_TOGGLE_MANUAL);
12275 case GAME_CTRL_ID_PLAY:
12278 #if defined(NETWORK_AVALIABLE)
12279 if (options.network)
12280 SendToServer_ContinuePlaying();
12284 tape.pausing = FALSE;
12285 DrawVideoDisplay(VIDEO_STATE_PAUSE_OFF,0);
12290 case SOUND_CTRL_ID_MUSIC:
12291 if (setup.sound_music)
12293 setup.sound_music = FALSE;
12296 else if (audio.music_available)
12298 setup.sound = setup.sound_music = TRUE;
12300 SetAudioMode(setup.sound);
12306 case SOUND_CTRL_ID_LOOPS:
12307 if (setup.sound_loops)
12308 setup.sound_loops = FALSE;
12309 else if (audio.loops_available)
12311 setup.sound = setup.sound_loops = TRUE;
12312 SetAudioMode(setup.sound);
12316 case SOUND_CTRL_ID_SIMPLE:
12317 if (setup.sound_simple)
12318 setup.sound_simple = FALSE;
12319 else if (audio.sound_available)
12321 setup.sound = setup.sound_simple = TRUE;
12322 SetAudioMode(setup.sound);