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))
7453 if (IS_MOVING(x, y) || IS_BLOCKED(x, y))
7454 RemoveMovingField(x, y);
7458 Feld[x][y] = target_element;
7461 Feld[x][y] = target_element;
7464 ResetGfxAnimation(x, y);
7465 ResetRandomAnimationValue(x, y);
7467 if (element_info[Feld[x][y]].move_direction_initial == MV_START_PREVIOUS)
7468 MovDir[x][y] = previous_move_direction;
7471 InitField_WithBug1(x, y, FALSE);
7473 InitField(x, y, FALSE);
7474 if (CAN_MOVE(Feld[x][y]))
7478 DrawLevelField(x, y);
7480 if (GFX_CRUMBLED(Feld[x][y]))
7481 DrawLevelFieldCrumbledSandNeighbours(x, y);
7485 Changed[x][y] |= ChangeEvent[x][y]; /* ignore same changes in this frame */
7489 TestIfBadThingTouchesHero(x, y);
7490 TestIfPlayerTouchesCustomElement(x, y);
7491 TestIfElementTouchesCustomElement(x, y);
7494 /* "Changed[][]" not set yet to allow "entered by player" change one time */
7495 if (ELEM_IS_PLAYER(target_element))
7496 RelocatePlayer(x, y, target_element);
7499 Changed[x][y] |= ChangeEvent[x][y]; /* ignore same changes in this frame */
7503 TestIfBadThingTouchesHero(x, y);
7504 TestIfPlayerTouchesCustomElement(x, y);
7505 TestIfElementTouchesCustomElement(x, y);
7509 static boolean ChangeElementNow(int x, int y, int element, int page)
7511 struct ElementChangeInfo *change = &element_info[element].change_page[page];
7513 int old_element = Feld[x][y];
7515 /* always use default change event to prevent running into a loop */
7516 if (ChangeEvent[x][y] == CE_BITMASK_DEFAULT)
7517 ChangeEvent[x][y] = CH_EVENT_BIT(CE_DELAY);
7519 if (ChangeEvent[x][y] == CH_EVENT_BIT(CE_DELAY))
7521 /* reset actual trigger element and player */
7522 change->actual_trigger_element = EL_EMPTY;
7523 change->actual_trigger_player = EL_PLAYER_1;
7526 /* do not change already changed elements with same change event */
7528 if (Changed[x][y] & ChangeEvent[x][y])
7535 Changed[x][y] |= ChangeEvent[x][y]; /* ignore same changes in this frame */
7538 /* !!! indirect change before direct change !!! */
7539 CheckTriggeredElementChangeByPage(x,y,Feld[x][y], CE_OTHER_IS_CHANGING,page);
7542 if (change->explode)
7549 if (change->use_target_content)
7551 boolean complete_replace = TRUE;
7552 boolean can_replace[3][3];
7555 for (yy = 0; yy < 3; yy++) for (xx = 0; xx < 3 ; xx++)
7558 boolean is_walkable;
7559 boolean is_diggable;
7560 boolean is_collectible;
7561 boolean is_removable;
7562 boolean is_destructible;
7563 int ex = x + xx - 1;
7564 int ey = y + yy - 1;
7565 int content_element = change->target_content[xx][yy];
7568 can_replace[xx][yy] = TRUE;
7570 if (ex == x && ey == y) /* do not check changing element itself */
7573 if (content_element == EL_EMPTY_SPACE)
7575 can_replace[xx][yy] = FALSE; /* do not replace border with space */
7580 if (!IN_LEV_FIELD(ex, ey))
7582 can_replace[xx][yy] = FALSE;
7583 complete_replace = FALSE;
7589 if (Changed[ex][ey]) /* do not change already changed elements */
7591 can_replace[xx][yy] = FALSE;
7592 complete_replace = FALSE;
7600 if (IS_MOVING(ex, ey) || IS_BLOCKED(ex, ey))
7601 e = MovingOrBlocked2Element(ex, ey);
7606 is_empty = (IS_FREE(ex, ey) ||
7607 (IS_PLAYER(ex, ey) && IS_WALKABLE(content_element)) ||
7608 (IS_WALKABLE(e) && ELEM_IS_PLAYER(content_element) &&
7609 !IS_MOVING(ex, ey) && !IS_BLOCKED(ex, ey)));
7613 is_empty = (IS_FREE(ex, ey) ||
7614 (IS_PLAYER(ex, ey) && IS_WALKABLE(content_element)));
7616 is_empty = (IS_FREE(ex, ey) ||
7617 (IS_FREE_OR_PLAYER(ex, ey) && IS_WALKABLE(content_element)));
7621 is_walkable = (is_empty || IS_WALKABLE(e));
7622 is_diggable = (is_empty || IS_DIGGABLE(e));
7623 is_collectible = (is_empty || IS_COLLECTIBLE(e));
7624 is_destructible = (is_empty || !IS_INDESTRUCTIBLE(e));
7625 is_removable = (is_diggable || is_collectible);
7627 can_replace[xx][yy] =
7628 ((change->replace_when == CP_WHEN_EMPTY && is_empty) ||
7629 (change->replace_when == CP_WHEN_WALKABLE && is_walkable) ||
7630 (change->replace_when == CP_WHEN_DIGGABLE && is_diggable) ||
7631 (change->replace_when == CP_WHEN_COLLECTIBLE && is_collectible) ||
7632 (change->replace_when == CP_WHEN_REMOVABLE && is_removable) ||
7633 (change->replace_when == CP_WHEN_DESTRUCTIBLE && is_destructible));
7635 if (!can_replace[xx][yy])
7636 complete_replace = FALSE;
7638 empty_for_element = (IS_FREE(ex, ey) || (IS_FREE_OR_PLAYER(ex, ey) &&
7639 IS_WALKABLE(content_element)));
7641 half_destructible = (empty_for_element || IS_DIGGABLE(e));
7643 half_destructible = (IS_FREE(ex, ey) || IS_DIGGABLE(e));
7646 if ((change->replace_when <= CP_WHEN_EMPTY && !empty_for_element) ||
7647 (change->replace_when <= CP_WHEN_DIGGABLE && !half_destructible) ||
7648 (change->replace_when <= CP_WHEN_DESTRUCTIBLE && IS_INDESTRUCTIBLE(e)))
7650 can_replace[xx][yy] = FALSE;
7651 complete_replace = FALSE;
7656 if (!change->only_if_complete || complete_replace)
7658 boolean something_has_changed = FALSE;
7660 if (change->only_if_complete && change->use_random_replace &&
7661 RND(100) < change->random_percentage)
7664 for (yy = 0; yy < 3; yy++) for (xx = 0; xx < 3 ; xx++)
7666 int ex = x + xx - 1;
7667 int ey = y + yy - 1;
7668 int content_element;
7670 if (can_replace[xx][yy] && (!change->use_random_replace ||
7671 RND(100) < change->random_percentage))
7673 if (IS_MOVING(ex, ey) || IS_BLOCKED(ex, ey))
7674 RemoveMovingField(ex, ey);
7676 ChangeEvent[ex][ey] = ChangeEvent[x][y];
7678 content_element = change->target_content[xx][yy];
7679 target_element = GET_TARGET_ELEMENT(content_element, change);
7681 ChangeElementNowExt(ex, ey, target_element);
7683 something_has_changed = TRUE;
7685 /* for symmetry reasons, freeze newly created border elements */
7686 if (ex != x || ey != y)
7687 Stop[ex][ey] = TRUE; /* no more moving in this frame */
7691 if (something_has_changed)
7692 PlayLevelSoundElementAction(x, y, element, ACTION_CHANGING);
7697 target_element = GET_TARGET_ELEMENT(change->target_element, change);
7699 ChangeElementNowExt(x, y, target_element);
7701 PlayLevelSoundElementAction(x, y, element, ACTION_CHANGING);
7705 /* this uses direct change before indirect change */
7706 CheckTriggeredElementChangeByPage(x,y,old_element,CE_OTHER_IS_CHANGING,page);
7712 static void ChangeElement(int x, int y, int page)
7714 int element = MovingOrBlocked2Element(x, y);
7715 struct ElementInfo *ei = &element_info[element];
7716 struct ElementChangeInfo *change = &ei->change_page[page];
7719 if (!CAN_CHANGE(element) && !CAN_CHANGE(Back[x][y]))
7722 printf("ChangeElement(): %d,%d: element = %d ('%s')\n",
7723 x, y, element, element_info[element].token_name);
7724 printf("ChangeElement(): This should never happen!\n");
7729 /* this can happen with classic bombs on walkable, changing elements */
7730 if (!CAN_CHANGE(element))
7733 if (!CAN_CHANGE(Back[x][y])) /* prevent permanent repetition */
7734 ChangeDelay[x][y] = 0;
7740 if (ChangeDelay[x][y] == 0) /* initialize element change */
7742 ChangeDelay[x][y] = ( change->delay_fixed * change->delay_frames +
7743 RND(change->delay_random * change->delay_frames)) + 1;
7745 ResetGfxAnimation(x, y);
7746 ResetRandomAnimationValue(x, y);
7748 if (change->pre_change_function)
7749 change->pre_change_function(x, y);
7752 ChangeDelay[x][y]--;
7754 if (ChangeDelay[x][y] != 0) /* continue element change */
7756 int graphic = el_act_dir2img(element, GfxAction[x][y], GfxDir[x][y]);
7758 if (IS_ANIMATED(graphic))
7759 DrawLevelGraphicAnimationIfNeeded(x, y, graphic);
7761 if (change->change_function)
7762 change->change_function(x, y);
7764 else /* finish element change */
7766 if (ChangePage[x][y] != -1) /* remember page from delayed change */
7768 page = ChangePage[x][y];
7769 ChangePage[x][y] = -1;
7771 change = &ei->change_page[page];
7775 if (IS_MOVING(x, y) && !change->explode)
7777 if (IS_MOVING(x, y)) /* never change a running system ;-) */
7780 ChangeDelay[x][y] = 1; /* try change after next move step */
7781 ChangePage[x][y] = page; /* remember page to use for change */
7786 if (ChangeElementNow(x, y, element, page))
7788 if (change->post_change_function)
7789 change->post_change_function(x, y);
7794 static boolean CheckTriggeredElementChangeExt(int lx, int ly,
7795 int trigger_element,
7802 int trigger_page_bits = (trigger_page < 0 ? CH_PAGE_ANY : 1 << trigger_page);
7804 if (!(trigger_events[trigger_element] & CH_EVENT_BIT(trigger_event)))
7807 for (i = 0; i < NUM_CUSTOM_ELEMENTS; i++)
7809 int element = EL_CUSTOM_START + i;
7811 boolean change_element = FALSE;
7814 if (!CAN_CHANGE(element) || !HAS_ANY_CHANGE_EVENT(element, trigger_event))
7817 for (j = 0; j < element_info[element].num_change_pages; j++)
7819 struct ElementChangeInfo *change = &element_info[element].change_page[j];
7821 if (change->can_change &&
7822 change->events & CH_EVENT_BIT(trigger_event) &&
7823 change->trigger_side & trigger_side &&
7824 change->trigger_player & trigger_player &&
7825 change->trigger_page & trigger_page_bits &&
7826 IS_EQUAL_OR_IN_GROUP(trigger_element, change->trigger_element))
7829 if (!(change->events & CH_EVENT_BIT(trigger_event)))
7830 printf("::: !!! %d triggers %d: using wrong page %d [event %d]\n",
7831 trigger_element-EL_CUSTOM_START+1, i+1, j, trigger_event);
7834 change_element = TRUE;
7837 change->actual_trigger_element = trigger_element;
7838 change->actual_trigger_player = EL_PLAYER_1 + log_2(trigger_player);
7844 if (!change_element)
7847 for (y = 0; y < lev_fieldy; y++) for (x = 0; x < lev_fieldx; x++)
7850 if (x == lx && y == ly) /* do not change trigger element itself */
7854 if (Feld[x][y] == element)
7856 ChangeDelay[x][y] = 1;
7857 ChangeEvent[x][y] = CH_EVENT_BIT(trigger_event);
7858 ChangeElement(x, y, page);
7866 static boolean CheckElementChangeExt(int x, int y,
7868 int trigger_element,
7874 if (!CAN_CHANGE(element) || !HAS_ANY_CHANGE_EVENT(element, trigger_event))
7877 if (Feld[x][y] == EL_BLOCKED)
7879 Blocked2Moving(x, y, &x, &y);
7880 element = Feld[x][y];
7884 if (Feld[x][y] != element) /* check if element has already changed */
7887 printf("::: %d ('%s') != %d ('%s') [%d]\n",
7888 Feld[x][y], element_info[Feld[x][y]].token_name,
7889 element, element_info[element].token_name,
7898 if (trigger_page < 0)
7900 boolean change_element = FALSE;
7903 for (i = 0; i < element_info[element].num_change_pages; i++)
7905 struct ElementChangeInfo *change = &element_info[element].change_page[i];
7907 if (change->can_change &&
7908 change->events & CH_EVENT_BIT(trigger_event) &&
7909 change->trigger_side & trigger_side &&
7910 change->trigger_player & trigger_player)
7912 change_element = TRUE;
7915 change->actual_trigger_element = trigger_element;
7916 change->actual_trigger_player = EL_PLAYER_1 + log_2(trigger_player);
7922 if (!change_element)
7927 struct ElementInfo *ei = &element_info[element];
7928 struct ElementChangeInfo *change = &ei->change_page[trigger_page];
7930 change->actual_trigger_element = trigger_element;
7931 change->actual_trigger_player = EL_PLAYER_1; /* unused */
7936 /* !!! this check misses pages with same event, but different side !!! */
7938 if (trigger_page < 0)
7939 trigger_page = element_info[element].event_page_nr[trigger_event];
7941 if (!(element_info[element].change_page[trigger_page].trigger_side & trigger_side))
7945 ChangeDelay[x][y] = 1;
7946 ChangeEvent[x][y] = CH_EVENT_BIT(trigger_event);
7947 ChangeElement(x, y, trigger_page);
7952 static void PlayPlayerSound(struct PlayerInfo *player)
7954 int jx = player->jx, jy = player->jy;
7955 int element = player->element_nr;
7956 int last_action = player->last_action_waiting;
7957 int action = player->action_waiting;
7959 if (player->is_waiting)
7961 if (action != last_action)
7962 PlayLevelSoundElementAction(jx, jy, element, action);
7964 PlayLevelSoundElementActionIfLoop(jx, jy, element, action);
7968 if (action != last_action)
7969 StopSound(element_info[element].sound[last_action]);
7971 if (last_action == ACTION_SLEEPING)
7972 PlayLevelSoundElementAction(jx, jy, element, ACTION_AWAKENING);
7976 static void PlayAllPlayersSound()
7980 for (i = 0; i < MAX_PLAYERS; i++)
7981 if (stored_player[i].active)
7982 PlayPlayerSound(&stored_player[i]);
7985 static void SetPlayerWaiting(struct PlayerInfo *player, boolean is_waiting)
7987 boolean last_waiting = player->is_waiting;
7988 int move_dir = player->MovDir;
7990 player->last_action_waiting = player->action_waiting;
7994 if (!last_waiting) /* not waiting -> waiting */
7996 player->is_waiting = TRUE;
7998 player->frame_counter_bored =
8000 game.player_boring_delay_fixed +
8001 SimpleRND(game.player_boring_delay_random);
8002 player->frame_counter_sleeping =
8004 game.player_sleeping_delay_fixed +
8005 SimpleRND(game.player_sleeping_delay_random);
8007 InitPlayerGfxAnimation(player, ACTION_WAITING, player->MovDir);
8010 if (game.player_sleeping_delay_fixed +
8011 game.player_sleeping_delay_random > 0 &&
8012 player->anim_delay_counter == 0 &&
8013 player->post_delay_counter == 0 &&
8014 FrameCounter >= player->frame_counter_sleeping)
8015 player->is_sleeping = TRUE;
8016 else if (game.player_boring_delay_fixed +
8017 game.player_boring_delay_random > 0 &&
8018 FrameCounter >= player->frame_counter_bored)
8019 player->is_bored = TRUE;
8021 player->action_waiting = (player->is_sleeping ? ACTION_SLEEPING :
8022 player->is_bored ? ACTION_BORING :
8025 if (player->is_sleeping)
8027 if (player->num_special_action_sleeping > 0)
8029 if (player->anim_delay_counter == 0 && player->post_delay_counter == 0)
8031 int last_special_action = player->special_action_sleeping;
8032 int num_special_action = player->num_special_action_sleeping;
8033 int special_action =
8034 (last_special_action == ACTION_DEFAULT ? ACTION_SLEEPING_1 :
8035 last_special_action == ACTION_SLEEPING ? ACTION_SLEEPING :
8036 last_special_action < ACTION_SLEEPING_1 + num_special_action - 1 ?
8037 last_special_action + 1 : ACTION_SLEEPING);
8038 int special_graphic =
8039 el_act_dir2img(player->element_nr, special_action, move_dir);
8041 player->anim_delay_counter =
8042 graphic_info[special_graphic].anim_delay_fixed +
8043 SimpleRND(graphic_info[special_graphic].anim_delay_random);
8044 player->post_delay_counter =
8045 graphic_info[special_graphic].post_delay_fixed +
8046 SimpleRND(graphic_info[special_graphic].post_delay_random);
8048 player->special_action_sleeping = special_action;
8051 if (player->anim_delay_counter > 0)
8053 player->action_waiting = player->special_action_sleeping;
8054 player->anim_delay_counter--;
8056 else if (player->post_delay_counter > 0)
8058 player->post_delay_counter--;
8062 else if (player->is_bored)
8064 if (player->num_special_action_bored > 0)
8066 if (player->anim_delay_counter == 0 && player->post_delay_counter == 0)
8068 int special_action =
8069 ACTION_BORING_1 + SimpleRND(player->num_special_action_bored);
8070 int special_graphic =
8071 el_act_dir2img(player->element_nr, special_action, move_dir);
8073 player->anim_delay_counter =
8074 graphic_info[special_graphic].anim_delay_fixed +
8075 SimpleRND(graphic_info[special_graphic].anim_delay_random);
8076 player->post_delay_counter =
8077 graphic_info[special_graphic].post_delay_fixed +
8078 SimpleRND(graphic_info[special_graphic].post_delay_random);
8080 player->special_action_bored = special_action;
8083 if (player->anim_delay_counter > 0)
8085 player->action_waiting = player->special_action_bored;
8086 player->anim_delay_counter--;
8088 else if (player->post_delay_counter > 0)
8090 player->post_delay_counter--;
8095 else if (last_waiting) /* waiting -> not waiting */
8097 player->is_waiting = FALSE;
8098 player->is_bored = FALSE;
8099 player->is_sleeping = FALSE;
8101 player->frame_counter_bored = -1;
8102 player->frame_counter_sleeping = -1;
8104 player->anim_delay_counter = 0;
8105 player->post_delay_counter = 0;
8107 player->action_waiting = ACTION_DEFAULT;
8109 player->special_action_bored = ACTION_DEFAULT;
8110 player->special_action_sleeping = ACTION_DEFAULT;
8115 static byte PlayerActions(struct PlayerInfo *player, byte player_action)
8118 static byte stored_player_action[MAX_PLAYERS];
8119 static int num_stored_actions = 0;
8121 boolean moved = FALSE, snapped = FALSE, dropped = FALSE;
8122 int left = player_action & JOY_LEFT;
8123 int right = player_action & JOY_RIGHT;
8124 int up = player_action & JOY_UP;
8125 int down = player_action & JOY_DOWN;
8126 int button1 = player_action & JOY_BUTTON_1;
8127 int button2 = player_action & JOY_BUTTON_2;
8128 int dx = (left ? -1 : right ? 1 : 0);
8129 int dy = (up ? -1 : down ? 1 : 0);
8132 stored_player_action[player->index_nr] = 0;
8133 num_stored_actions++;
8137 printf("::: player %d [%d]\n", player->index_nr, FrameCounter);
8140 if (!player->active || tape.pausing)
8144 printf("::: [%d %d %d %d] [%d %d]\n",
8145 left, right, up, down, button1, button2);
8151 printf("::: player %d acts [%d]\n", player->index_nr, FrameCounter);
8156 if (player->MovPos == 0)
8157 CheckGravityMovement(player);
8160 snapped = SnapField(player, dx, dy);
8164 dropped = DropElement(player);
8166 moved = MovePlayer(player, dx, dy);
8169 if (tape.single_step && tape.recording && !tape.pausing)
8171 if (button1 || (dropped && !moved))
8173 TapeTogglePause(TAPE_TOGGLE_AUTOMATIC);
8174 SnapField(player, 0, 0); /* stop snapping */
8178 SetPlayerWaiting(player, FALSE);
8181 return player_action;
8183 stored_player_action[player->index_nr] = player_action;
8189 printf("::: player %d waits [%d]\n", player->index_nr, FrameCounter);
8192 /* no actions for this player (no input at player's configured device) */
8194 DigField(player, 0, 0, 0, 0, 0, 0, DF_NO_PUSH);
8195 SnapField(player, 0, 0);
8196 CheckGravityMovementWhenNotMoving(player);
8198 if (player->MovPos == 0)
8199 SetPlayerWaiting(player, TRUE);
8201 if (player->MovPos == 0) /* needed for tape.playing */
8202 player->is_moving = FALSE;
8204 player->is_dropping = FALSE;
8210 if (tape.recording && num_stored_actions >= MAX_PLAYERS)
8212 printf("::: player %d recorded [%d]\n", player->index_nr, FrameCounter);
8214 TapeRecordAction(stored_player_action);
8215 num_stored_actions = 0;
8222 static void PlayerActions(struct PlayerInfo *player, byte player_action)
8224 static byte stored_player_action[MAX_PLAYERS];
8225 static int num_stored_actions = 0;
8226 boolean moved = FALSE, snapped = FALSE, dropped = FALSE;
8227 int left = player_action & JOY_LEFT;
8228 int right = player_action & JOY_RIGHT;
8229 int up = player_action & JOY_UP;
8230 int down = player_action & JOY_DOWN;
8231 int button1 = player_action & JOY_BUTTON_1;
8232 int button2 = player_action & JOY_BUTTON_2;
8233 int dx = (left ? -1 : right ? 1 : 0);
8234 int dy = (up ? -1 : down ? 1 : 0);
8236 stored_player_action[player->index_nr] = 0;
8237 num_stored_actions++;
8239 printf("::: player %d [%d]\n", player->index_nr, FrameCounter);
8241 if (!player->active || tape.pausing)
8246 printf("::: player %d acts [%d]\n", player->index_nr, FrameCounter);
8249 snapped = SnapField(player, dx, dy);
8253 dropped = DropElement(player);
8255 moved = MovePlayer(player, dx, dy);
8258 if (tape.single_step && tape.recording && !tape.pausing)
8260 if (button1 || (dropped && !moved))
8262 TapeTogglePause(TAPE_TOGGLE_AUTOMATIC);
8263 SnapField(player, 0, 0); /* stop snapping */
8267 stored_player_action[player->index_nr] = player_action;
8271 printf("::: player %d waits [%d]\n", player->index_nr, FrameCounter);
8273 /* no actions for this player (no input at player's configured device) */
8275 DigField(player, 0, 0, 0, 0, 0, 0, DF_NO_PUSH);
8276 SnapField(player, 0, 0);
8277 CheckGravityMovementWhenNotMoving(player);
8279 if (player->MovPos == 0)
8280 InitPlayerGfxAnimation(player, ACTION_DEFAULT, player->MovDir);
8282 if (player->MovPos == 0) /* needed for tape.playing */
8283 player->is_moving = FALSE;
8286 if (tape.recording && num_stored_actions >= MAX_PLAYERS)
8288 printf("::: player %d recorded [%d]\n", player->index_nr, FrameCounter);
8290 TapeRecordAction(stored_player_action);
8291 num_stored_actions = 0;
8298 static unsigned long action_delay = 0;
8299 unsigned long action_delay_value;
8300 int magic_wall_x = 0, magic_wall_y = 0;
8301 int i, x, y, element, graphic;
8302 byte *recorded_player_action;
8303 byte summarized_player_action = 0;
8305 byte tape_action[MAX_PLAYERS];
8308 if (game_status != GAME_MODE_PLAYING)
8311 action_delay_value =
8312 (tape.playing && tape.fast_forward ? FfwdFrameDelay : GameFrameDelay);
8314 if (tape.playing && tape.warp_forward && !tape.pausing)
8315 action_delay_value = 0;
8317 /* ---------- main game synchronization point ---------- */
8319 WaitUntilDelayReached(&action_delay, action_delay_value);
8321 if (network_playing && !network_player_action_received)
8325 printf("DEBUG: try to get network player actions in time\n");
8329 #if defined(NETWORK_AVALIABLE)
8330 /* last chance to get network player actions without main loop delay */
8334 if (game_status != GAME_MODE_PLAYING)
8337 if (!network_player_action_received)
8341 printf("DEBUG: failed to get network player actions in time\n");
8352 printf("::: getting new tape action [%d]\n", FrameCounter);
8355 recorded_player_action = (tape.playing ? TapePlayAction() : NULL);
8358 if (recorded_player_action == NULL && tape.pausing)
8363 printf("::: %d\n", stored_player[0].action);
8367 if (recorded_player_action != NULL)
8368 for (i = 0; i < MAX_PLAYERS; i++)
8369 stored_player[i].action = recorded_player_action[i];
8372 for (i = 0; i < MAX_PLAYERS; i++)
8374 summarized_player_action |= stored_player[i].action;
8376 if (!network_playing)
8377 stored_player[i].effective_action = stored_player[i].action;
8380 #if defined(NETWORK_AVALIABLE)
8381 if (network_playing)
8382 SendToServer_MovePlayer(summarized_player_action);
8385 if (!options.network && !setup.team_mode)
8386 local_player->effective_action = summarized_player_action;
8389 if (recorded_player_action != NULL)
8390 for (i = 0; i < MAX_PLAYERS; i++)
8391 stored_player[i].effective_action = recorded_player_action[i];
8395 for (i = 0; i < MAX_PLAYERS; i++)
8397 tape_action[i] = stored_player[i].effective_action;
8399 if (tape.recording && tape_action[i] && !tape.player_participates[i])
8400 tape.player_participates[i] = TRUE; /* player just appeared from CE */
8403 /* only save actions from input devices, but not programmed actions */
8405 TapeRecordAction(tape_action);
8408 for (i = 0; i < MAX_PLAYERS; i++)
8410 int actual_player_action = stored_player[i].effective_action;
8413 /* !!! THIS BREAKS THE FOLLOWING TAPES: !!!
8414 - rnd_equinox_tetrachloride 048
8415 - rnd_equinox_tetrachloride_ii 096
8416 - rnd_emanuel_schmieg 002
8417 - doctor_sloan_ww 001, 020
8419 if (stored_player[i].MovPos == 0)
8420 CheckGravityMovement(&stored_player[i]);
8424 /* overwrite programmed action with tape action */
8425 if (stored_player[i].programmed_action)
8426 actual_player_action = stored_player[i].programmed_action;
8430 if (stored_player[i].programmed_action)
8431 printf("::: %d\n", stored_player[i].programmed_action);
8434 if (recorded_player_action)
8437 if (stored_player[i].programmed_action &&
8438 stored_player[i].programmed_action != recorded_player_action[i])
8439 printf("::: %d: %d <-> %d\n", i,
8440 stored_player[i].programmed_action, recorded_player_action[i]);
8444 actual_player_action = recorded_player_action[i];
8449 /* overwrite tape action with programmed action */
8450 if (stored_player[i].programmed_action)
8451 actual_player_action = stored_player[i].programmed_action;
8456 printf("::: action: %d: %x [%d]\n",
8457 stored_player[i].MovPos, actual_player_action, FrameCounter);
8461 PlayerActions(&stored_player[i], actual_player_action);
8463 tape_action[i] = PlayerActions(&stored_player[i], actual_player_action);
8465 if (tape.recording && tape_action[i] && !tape.player_participates[i])
8466 tape.player_participates[i] = TRUE; /* player just appeared from CE */
8469 ScrollPlayer(&stored_player[i], SCROLL_GO_ON);
8474 TapeRecordAction(tape_action);
8477 network_player_action_received = FALSE;
8479 ScrollScreen(NULL, SCROLL_GO_ON);
8485 for (i = 0; i < MAX_PLAYERS; i++)
8486 stored_player[i].Frame++;
8490 /* for downwards compatibility, the following code emulates a fixed bug that
8491 occured when pushing elements (causing elements that just made their last
8492 pushing step to already (if possible) make their first falling step in the
8493 same game frame, which is bad); this code is also needed to use the famous
8494 "spring push bug" which is used in older levels and might be wanted to be
8495 used also in newer levels, but in this case the buggy pushing code is only
8496 affecting the "spring" element and no other elements */
8499 if (game.engine_version < VERSION_IDENT(2,2,0,7) || level.use_spring_bug)
8501 if (game.engine_version < VERSION_IDENT(2,2,0,7))
8504 for (i = 0; i < MAX_PLAYERS; i++)
8506 struct PlayerInfo *player = &stored_player[i];
8511 if (player->active && player->is_pushing && player->is_moving &&
8513 (game.engine_version < VERSION_IDENT(2,2,0,7) ||
8514 Feld[x][y] == EL_SPRING))
8516 if (player->active && player->is_pushing && player->is_moving &&
8520 ContinueMoving(x, y);
8522 /* continue moving after pushing (this is actually a bug) */
8523 if (!IS_MOVING(x, y))
8532 for (y = 0; y < lev_fieldy; y++) for (x = 0; x < lev_fieldx; x++)
8534 Changed[x][y] = CE_BITMASK_DEFAULT;
8535 ChangeEvent[x][y] = CE_BITMASK_DEFAULT;
8538 if (ChangePage[x][y] != -1 && ChangeDelay[x][y] != 1)
8540 printf("GameActions(): x = %d, y = %d: ChangePage != -1\n", x, y);
8541 printf("GameActions(): This should never happen!\n");
8543 ChangePage[x][y] = -1;
8548 if (WasJustMoving[x][y] > 0)
8549 WasJustMoving[x][y]--;
8550 if (WasJustFalling[x][y] > 0)
8551 WasJustFalling[x][y]--;
8552 if (CheckCollision[x][y] > 0)
8553 CheckCollision[x][y]--;
8558 /* reset finished pushing action (not done in ContinueMoving() to allow
8559 continous pushing animation for elements with zero push delay) */
8560 if (GfxAction[x][y] == ACTION_PUSHING && !IS_MOVING(x, y))
8562 ResetGfxAnimation(x, y);
8563 DrawLevelField(x, y);
8568 if (IS_BLOCKED(x, y))
8572 Blocked2Moving(x, y, &oldx, &oldy);
8573 if (!IS_MOVING(oldx, oldy))
8575 printf("GameActions(): (BLOCKED => MOVING) context corrupted!\n");
8576 printf("GameActions(): BLOCKED: x = %d, y = %d\n", x, y);
8577 printf("GameActions(): !MOVING: oldx = %d, oldy = %d\n", oldx, oldy);
8578 printf("GameActions(): This should never happen!\n");
8584 for (y = 0; y < lev_fieldy; y++) for (x = 0; x < lev_fieldx; x++)
8586 element = Feld[x][y];
8588 graphic = el_act_dir2img(element, GfxAction[x][y], GfxDir[x][y]);
8590 graphic = el2img(element);
8596 printf("::: %d,%d: %d [%d]\n", x, y, element, FrameCounter);
8598 element = graphic = 0;
8602 if (graphic_info[graphic].anim_global_sync)
8603 GfxFrame[x][y] = FrameCounter;
8605 if (ANIM_MODE(graphic) == ANIM_RANDOM &&
8606 IS_NEXT_FRAME(GfxFrame[x][y], graphic))
8607 ResetRandomAnimationValue(x, y);
8609 SetRandomAnimationValue(x, y);
8612 PlayLevelSoundActionIfLoop(x, y, GfxAction[x][y]);
8615 if (IS_INACTIVE(element))
8617 if (IS_ANIMATED(graphic))
8618 DrawLevelGraphicAnimationIfNeeded(x, y, graphic);
8624 /* this may take place after moving, so 'element' may have changed */
8626 if (IS_CHANGING(x, y))
8628 if (IS_CHANGING(x, y) &&
8629 (game.engine_version < VERSION_IDENT(3,0,7,1) || !Stop[x][y]))
8633 ChangeElement(x, y, ChangePage[x][y] != -1 ? ChangePage[x][y] :
8634 element_info[element].event_page_nr[CE_DELAY]);
8636 ChangeElement(x, y, element_info[element].event_page_nr[CE_DELAY]);
8639 element = Feld[x][y];
8640 graphic = el_act_dir2img(element, GfxAction[x][y], GfxDir[x][y]);
8644 if (!IS_MOVING(x, y) && (CAN_FALL(element) || CAN_MOVE(element)))
8649 element = Feld[x][y];
8650 graphic = el_act_dir2img(element, GfxAction[x][y], GfxDir[x][y]);
8652 if (element == EL_MOLE)
8653 printf("::: %d, %d, %d [%d]\n",
8654 IS_ANIMATED(graphic), IS_MOVING(x, y), Stop[x][y],
8658 if (element == EL_YAMYAM)
8659 printf("::: %d, %d, %d\n",
8660 IS_ANIMATED(graphic), IS_MOVING(x, y), Stop[x][y]);
8664 if (IS_ANIMATED(graphic) &&
8668 DrawLevelGraphicAnimationIfNeeded(x, y, graphic);
8671 if (element == EL_BUG)
8672 printf("::: %d, %d\n", graphic, GfxFrame[x][y]);
8676 if (element == EL_MOLE)
8677 printf("::: %d, %d\n", graphic, GfxFrame[x][y]);
8681 if (IS_GEM(element) || element == EL_SP_INFOTRON)
8682 EdelsteinFunkeln(x, y);
8684 else if ((element == EL_ACID ||
8685 element == EL_EXIT_OPEN ||
8686 element == EL_SP_EXIT_OPEN ||
8687 element == EL_SP_TERMINAL ||
8688 element == EL_SP_TERMINAL_ACTIVE ||
8689 element == EL_EXTRA_TIME ||
8690 element == EL_SHIELD_NORMAL ||
8691 element == EL_SHIELD_DEADLY) &&
8692 IS_ANIMATED(graphic))
8693 DrawLevelGraphicAnimationIfNeeded(x, y, graphic);
8694 else if (IS_MOVING(x, y))
8695 ContinueMoving(x, y);
8696 else if (IS_ACTIVE_BOMB(element))
8697 CheckDynamite(x, y);
8699 else if (element == EL_EXPLOSION && !game.explosions_delayed)
8700 Explode(x, y, ExplodePhase[x][y], EX_TYPE_NORMAL);
8702 else if (element == EL_AMOEBA_GROWING)
8703 AmoebeWaechst(x, y);
8704 else if (element == EL_AMOEBA_SHRINKING)
8705 AmoebaDisappearing(x, y);
8707 #if !USE_NEW_AMOEBA_CODE
8708 else if (IS_AMOEBALIVE(element))
8709 AmoebeAbleger(x, y);
8712 else if (element == EL_GAME_OF_LIFE || element == EL_BIOMAZE)
8714 else if (element == EL_EXIT_CLOSED)
8716 else if (element == EL_SP_EXIT_CLOSED)
8718 else if (element == EL_EXPANDABLE_WALL_GROWING)
8720 else if (element == EL_EXPANDABLE_WALL ||
8721 element == EL_EXPANDABLE_WALL_HORIZONTAL ||
8722 element == EL_EXPANDABLE_WALL_VERTICAL ||
8723 element == EL_EXPANDABLE_WALL_ANY)
8725 else if (element == EL_FLAMES)
8726 CheckForDragon(x, y);
8728 else if (IS_AUTO_CHANGING(element))
8729 ChangeElement(x, y);
8731 else if (element == EL_EXPLOSION)
8732 ; /* drawing of correct explosion animation is handled separately */
8733 else if (IS_ANIMATED(graphic) && !IS_CHANGING(x, y))
8734 DrawLevelGraphicAnimationIfNeeded(x, y, graphic);
8737 /* this may take place after moving, so 'element' may have changed */
8738 if (IS_AUTO_CHANGING(Feld[x][y]))
8739 ChangeElement(x, y);
8742 if (IS_BELT_ACTIVE(element))
8743 PlayLevelSoundAction(x, y, ACTION_ACTIVE);
8745 if (game.magic_wall_active)
8747 int jx = local_player->jx, jy = local_player->jy;
8749 /* play the element sound at the position nearest to the player */
8750 if ((element == EL_MAGIC_WALL_FULL ||
8751 element == EL_MAGIC_WALL_ACTIVE ||
8752 element == EL_MAGIC_WALL_EMPTYING ||
8753 element == EL_BD_MAGIC_WALL_FULL ||
8754 element == EL_BD_MAGIC_WALL_ACTIVE ||
8755 element == EL_BD_MAGIC_WALL_EMPTYING) &&
8756 ABS(x-jx) + ABS(y-jy) < ABS(magic_wall_x-jx) + ABS(magic_wall_y-jy))
8764 #if USE_NEW_AMOEBA_CODE
8765 /* new experimental amoeba growth stuff */
8767 if (!(FrameCounter % 8))
8770 static unsigned long random = 1684108901;
8772 for (i = 0; i < level.amoeba_speed * 28 / 8; i++)
8775 x = (random >> 10) % lev_fieldx;
8776 y = (random >> 20) % lev_fieldy;
8778 x = RND(lev_fieldx);
8779 y = RND(lev_fieldy);
8781 element = Feld[x][y];
8784 if (!IS_PLAYER(x,y) &&
8785 (element == EL_EMPTY ||
8786 CAN_GROW_INTO(element) ||
8787 element == EL_QUICKSAND_EMPTY ||
8788 element == EL_ACID_SPLASH_LEFT ||
8789 element == EL_ACID_SPLASH_RIGHT))
8791 if ((IN_LEV_FIELD(x, y-1) && Feld[x][y-1] == EL_AMOEBA_WET) ||
8792 (IN_LEV_FIELD(x-1, y) && Feld[x-1][y] == EL_AMOEBA_WET) ||
8793 (IN_LEV_FIELD(x+1, y) && Feld[x+1][y] == EL_AMOEBA_WET) ||
8794 (IN_LEV_FIELD(x, y+1) && Feld[x][y+1] == EL_AMOEBA_WET))
8795 Feld[x][y] = EL_AMOEBA_DROP;
8798 /* !!! extend EL_SAND to anything diggable (but maybe not SP_BASE) !!! */
8799 if (!IS_PLAYER(x,y) &&
8800 (element == EL_EMPTY ||
8801 element == EL_SAND ||
8802 element == EL_QUICKSAND_EMPTY ||
8803 element == EL_ACID_SPLASH_LEFT ||
8804 element == EL_ACID_SPLASH_RIGHT))
8806 if ((IN_LEV_FIELD(x, y-1) && Feld[x][y-1] == EL_AMOEBA_WET) ||
8807 (IN_LEV_FIELD(x-1, y) && Feld[x-1][y] == EL_AMOEBA_WET) ||
8808 (IN_LEV_FIELD(x+1, y) && Feld[x+1][y] == EL_AMOEBA_WET) ||
8809 (IN_LEV_FIELD(x, y+1) && Feld[x][y+1] == EL_AMOEBA_WET))
8810 Feld[x][y] = EL_AMOEBA_DROP;
8814 random = random * 129 + 1;
8820 if (game.explosions_delayed)
8823 game.explosions_delayed = FALSE;
8825 for (y = 0; y < lev_fieldy; y++) for (x = 0; x < lev_fieldx; x++)
8827 element = Feld[x][y];
8829 if (ExplodeField[x][y])
8830 Explode(x, y, EX_PHASE_START, ExplodeField[x][y]);
8831 else if (element == EL_EXPLOSION)
8832 Explode(x, y, ExplodePhase[x][y], EX_TYPE_NORMAL);
8834 ExplodeField[x][y] = EX_TYPE_NONE;
8837 game.explosions_delayed = TRUE;
8840 if (game.magic_wall_active)
8842 if (!(game.magic_wall_time_left % 4))
8844 int element = Feld[magic_wall_x][magic_wall_y];
8846 if (element == EL_BD_MAGIC_WALL_FULL ||
8847 element == EL_BD_MAGIC_WALL_ACTIVE ||
8848 element == EL_BD_MAGIC_WALL_EMPTYING)
8849 PlayLevelSound(magic_wall_x, magic_wall_y, SND_BD_MAGIC_WALL_ACTIVE);
8851 PlayLevelSound(magic_wall_x, magic_wall_y, SND_MAGIC_WALL_ACTIVE);
8854 if (game.magic_wall_time_left > 0)
8856 game.magic_wall_time_left--;
8857 if (!game.magic_wall_time_left)
8859 for (y = 0; y < lev_fieldy; y++) for (x = 0; x < lev_fieldx; x++)
8861 element = Feld[x][y];
8863 if (element == EL_MAGIC_WALL_ACTIVE ||
8864 element == EL_MAGIC_WALL_FULL)
8866 Feld[x][y] = EL_MAGIC_WALL_DEAD;
8867 DrawLevelField(x, y);
8869 else if (element == EL_BD_MAGIC_WALL_ACTIVE ||
8870 element == EL_BD_MAGIC_WALL_FULL)
8872 Feld[x][y] = EL_BD_MAGIC_WALL_DEAD;
8873 DrawLevelField(x, y);
8877 game.magic_wall_active = FALSE;
8882 if (game.light_time_left > 0)
8884 game.light_time_left--;
8886 if (game.light_time_left == 0)
8887 RedrawAllLightSwitchesAndInvisibleElements();
8890 if (game.timegate_time_left > 0)
8892 game.timegate_time_left--;
8894 if (game.timegate_time_left == 0)
8895 CloseAllOpenTimegates();
8898 for (i = 0; i < MAX_PLAYERS; i++)
8900 struct PlayerInfo *player = &stored_player[i];
8902 if (SHIELD_ON(player))
8904 if (player->shield_deadly_time_left)
8905 PlayLevelSound(player->jx, player->jy, SND_SHIELD_DEADLY_ACTIVE);
8906 else if (player->shield_normal_time_left)
8907 PlayLevelSound(player->jx, player->jy, SND_SHIELD_NORMAL_ACTIVE);
8911 if (TimeFrames >= FRAMES_PER_SECOND)
8916 for (i = 0; i < MAX_PLAYERS; i++)
8918 struct PlayerInfo *player = &stored_player[i];
8920 if (SHIELD_ON(player))
8922 player->shield_normal_time_left--;
8924 if (player->shield_deadly_time_left > 0)
8925 player->shield_deadly_time_left--;
8929 if (!level.use_step_counter)
8937 if (TimeLeft <= 10 && setup.time_limit)
8938 PlaySoundStereo(SND_GAME_RUNNING_OUT_OF_TIME, SOUND_MIDDLE);
8940 DrawGameValue_Time(TimeLeft);
8942 if (!TimeLeft && setup.time_limit)
8943 for (i = 0; i < MAX_PLAYERS; i++)
8944 KillHero(&stored_player[i]);
8946 else if (level.time == 0 && !AllPlayersGone) /* level w/o time limit */
8947 DrawGameValue_Time(TimePlayed);
8950 if (tape.recording || tape.playing)
8951 DrawVideoDisplay(VIDEO_STATE_TIME_ON, TapeTime);
8955 PlayAllPlayersSound();
8957 if (options.debug) /* calculate frames per second */
8959 static unsigned long fps_counter = 0;
8960 static int fps_frames = 0;
8961 unsigned long fps_delay_ms = Counter() - fps_counter;
8965 if (fps_delay_ms >= 500) /* calculate fps every 0.5 seconds */
8967 global.frames_per_second = 1000 * (float)fps_frames / fps_delay_ms;
8970 fps_counter = Counter();
8973 redraw_mask |= REDRAW_FPS;
8977 if (stored_player[0].jx != stored_player[0].last_jx ||
8978 stored_player[0].jy != stored_player[0].last_jy)
8979 printf("::: %d, %d, %d, %d, %d\n",
8980 stored_player[0].MovDir,
8981 stored_player[0].MovPos,
8982 stored_player[0].GfxPos,
8983 stored_player[0].Frame,
8984 stored_player[0].StepFrame);
8991 for (i = 0; i < MAX_PLAYERS; i++)
8994 MOVE_DELAY_NORMAL_SPEED / stored_player[i].move_delay_value;
8996 stored_player[i].Frame += move_frames;
8998 if (stored_player[i].MovPos != 0)
8999 stored_player[i].StepFrame += move_frames;
9001 if (stored_player[i].drop_delay > 0)
9002 stored_player[i].drop_delay--;
9007 if (local_player->show_envelope != 0 && local_player->MovPos == 0)
9009 ShowEnvelope(local_player->show_envelope - EL_ENVELOPE_1);
9011 local_player->show_envelope = 0;
9016 static boolean AllPlayersInSight(struct PlayerInfo *player, int x, int y)
9018 int min_x = x, min_y = y, max_x = x, max_y = y;
9021 for (i = 0; i < MAX_PLAYERS; i++)
9023 int jx = stored_player[i].jx, jy = stored_player[i].jy;
9025 if (!stored_player[i].active || &stored_player[i] == player)
9028 min_x = MIN(min_x, jx);
9029 min_y = MIN(min_y, jy);
9030 max_x = MAX(max_x, jx);
9031 max_y = MAX(max_y, jy);
9034 return (max_x - min_x < SCR_FIELDX && max_y - min_y < SCR_FIELDY);
9037 static boolean AllPlayersInVisibleScreen()
9041 for (i = 0; i < MAX_PLAYERS; i++)
9043 int jx = stored_player[i].jx, jy = stored_player[i].jy;
9045 if (!stored_player[i].active)
9048 if (!IN_VIS_FIELD(SCREENX(jx), SCREENY(jy)))
9055 void ScrollLevel(int dx, int dy)
9057 int softscroll_offset = (setup.soft_scrolling ? TILEX : 0);
9060 BlitBitmap(drawto_field, drawto_field,
9061 FX + TILEX * (dx == -1) - softscroll_offset,
9062 FY + TILEY * (dy == -1) - softscroll_offset,
9063 SXSIZE - TILEX * (dx!=0) + 2 * softscroll_offset,
9064 SYSIZE - TILEY * (dy!=0) + 2 * softscroll_offset,
9065 FX + TILEX * (dx == 1) - softscroll_offset,
9066 FY + TILEY * (dy == 1) - softscroll_offset);
9070 x = (dx == 1 ? BX1 : BX2);
9071 for (y = BY1; y <= BY2; y++)
9072 DrawScreenField(x, y);
9077 y = (dy == 1 ? BY1 : BY2);
9078 for (x = BX1; x <= BX2; x++)
9079 DrawScreenField(x, y);
9082 redraw_mask |= REDRAW_FIELD;
9086 static boolean canEnterSupaplexPort(int x, int y, int dx, int dy)
9088 int nextx = x + dx, nexty = y + dy;
9089 int element = Feld[x][y];
9092 element != EL_SP_PORT_LEFT &&
9093 element != EL_SP_GRAVITY_PORT_LEFT &&
9094 element != EL_SP_PORT_HORIZONTAL &&
9095 element != EL_SP_PORT_ANY) ||
9097 element != EL_SP_PORT_RIGHT &&
9098 element != EL_SP_GRAVITY_PORT_RIGHT &&
9099 element != EL_SP_PORT_HORIZONTAL &&
9100 element != EL_SP_PORT_ANY) ||
9102 element != EL_SP_PORT_UP &&
9103 element != EL_SP_GRAVITY_PORT_UP &&
9104 element != EL_SP_PORT_VERTICAL &&
9105 element != EL_SP_PORT_ANY) ||
9107 element != EL_SP_PORT_DOWN &&
9108 element != EL_SP_GRAVITY_PORT_DOWN &&
9109 element != EL_SP_PORT_VERTICAL &&
9110 element != EL_SP_PORT_ANY) ||
9111 !IN_LEV_FIELD(nextx, nexty) ||
9112 !IS_FREE(nextx, nexty))
9119 static boolean canFallDown(struct PlayerInfo *player)
9121 int jx = player->jx, jy = player->jy;
9123 return (IN_LEV_FIELD(jx, jy + 1) &&
9124 (IS_FREE(jx, jy + 1) ||
9125 (Feld[jx][jy + 1] == EL_ACID && player->can_fall_into_acid)) &&
9126 IS_WALKABLE_FROM(Feld[jx][jy], MV_DOWN) &&
9127 !IS_WALKABLE_INSIDE(Feld[jx][jy]));
9130 static boolean canPassField(int x, int y, int move_dir)
9132 int opposite_dir = MV_DIR_OPPOSITE(move_dir);
9133 int dx = (move_dir & MV_LEFT ? -1 : move_dir & MV_RIGHT ? +1 : 0);
9134 int dy = (move_dir & MV_UP ? -1 : move_dir & MV_DOWN ? +1 : 0);
9137 int element = Feld[x][y];
9139 return (IS_PASSABLE_FROM(element, opposite_dir) &&
9140 !CAN_MOVE(element) &&
9141 IN_LEV_FIELD(nextx, nexty) && !IS_PLAYER(nextx, nexty) &&
9142 IS_WALKABLE_FROM(Feld[nextx][nexty], move_dir) &&
9143 (level.can_pass_to_walkable || IS_FREE(nextx, nexty)));
9146 static boolean canMoveToValidFieldWithGravity(int x, int y, int move_dir)
9148 int opposite_dir = MV_DIR_OPPOSITE(move_dir);
9149 int dx = (move_dir & MV_LEFT ? -1 : move_dir & MV_RIGHT ? +1 : 0);
9150 int dy = (move_dir & MV_UP ? -1 : move_dir & MV_DOWN ? +1 : 0);
9154 int nextx = newx + dx;
9155 int nexty = newy + dy;
9159 return (IN_LEV_FIELD(newx, newy) && !IS_FREE_OR_PLAYER(newx, newy) &&
9160 IS_GRAVITY_REACHABLE(Feld[newx][newy]) &&
9162 (!IS_SP_PORT(Feld[newx][newy]) || move_dir == MV_UP) &&
9164 (IS_DIGGABLE(Feld[newx][newy]) ||
9165 IS_WALKABLE_FROM(Feld[newx][newy], opposite_dir) ||
9166 canPassField(newx, newy, move_dir)));
9169 return (IN_LEV_FIELD(newx, newy) && !IS_FREE_OR_PLAYER(newx, newy) &&
9170 IS_GRAVITY_REACHABLE(Feld[newx][newy]) &&
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_DIGGABLE_WITH_GRAVITY(Feld[newx][newy]) ||
9178 IS_WALKABLE_FROM(Feld[newx][newy], opposite_dir) ||
9179 canPassField(newx, newy, move_dir)));
9181 return (IN_LEV_FIELD(newx, newy) && !IS_FREE_OR_PLAYER(newx, newy) &&
9182 (IS_DIGGABLE(Feld[newx][newy]) ||
9183 IS_WALKABLE_FROM(Feld[newx][newy], opposite_dir) ||
9184 (IS_PASSABLE_FROM(Feld[newx][newy], opposite_dir) &&
9185 !CAN_MOVE(Feld[newx][newy]) &&
9186 IN_LEV_FIELD(nextx, nexty) && !IS_PLAYER(nextx, nexty) &&
9187 IS_WALKABLE_FROM(Feld[nextx][nexty], move_dir) &&
9188 (level.can_pass_to_walkable || IS_FREE(nextx, nexty)))));
9194 static void CheckGravityMovement(struct PlayerInfo *player)
9196 if (game.gravity && !player->programmed_action)
9199 int move_dir_horizontal = player->effective_action & MV_HORIZONTAL;
9200 int move_dir_vertical = player->effective_action & MV_VERTICAL;
9202 int move_dir_horizontal = player->action & MV_HORIZONTAL;
9203 int move_dir_vertical = player->action & MV_VERTICAL;
9207 boolean player_is_snapping = player->effective_action & JOY_BUTTON_1;
9209 boolean player_is_snapping = player->action & JOY_BUTTON_1;
9212 int jx = player->jx, jy = player->jy;
9214 boolean player_is_moving_to_valid_field =
9215 (!player_is_snapping &&
9216 (canMoveToValidFieldWithGravity(jx, jy, move_dir_horizontal) ||
9217 canMoveToValidFieldWithGravity(jx, jy, move_dir_vertical)));
9221 (player->last_move_dir & MV_HORIZONTAL ?
9222 (move_dir_vertical ? move_dir_vertical : move_dir_horizontal) :
9223 (move_dir_horizontal ? move_dir_horizontal : move_dir_vertical));
9227 int opposite_dir = MV_DIR_OPPOSITE(move_dir);
9228 int dx = (move_dir & MV_LEFT ? -1 : move_dir & MV_RIGHT ? +1 : 0);
9229 int dy = (move_dir & MV_UP ? -1 : move_dir & MV_DOWN ? +1 : 0);
9230 int new_jx = jx + dx, new_jy = jy + dy;
9231 int nextx = new_jx + dx, nexty = new_jy + dy;
9237 boolean player_can_fall_down = canFallDown(player);
9239 boolean player_can_fall_down =
9240 (IN_LEV_FIELD(jx, jy + 1) &&
9241 (IS_FREE(jx, jy + 1) ||
9242 (Feld[jx][jy + 1] == EL_ACID && player->can_fall_into_acid)));
9246 boolean player_can_fall_down =
9247 (IN_LEV_FIELD(jx, jy + 1) &&
9248 (IS_FREE(jx, jy + 1)));
9252 boolean player_is_moving_to_valid_field =
9255 !player_is_snapping &&
9259 IN_LEV_FIELD(new_jx, new_jy) &&
9260 (IS_DIGGABLE(Feld[new_jx][new_jy]) ||
9261 (IS_SP_PORT(Feld[new_jx][new_jy]) &&
9262 element_info[Feld[new_jx][new_jy]].access_direction & opposite_dir &&
9263 IN_LEV_FIELD(nextx, nexty) &&
9264 element_info[Feld[nextx][nexty]].access_direction & move_dir))
9266 IN_LEV_FIELD(new_jx, new_jy) &&
9267 (Feld[new_jx][new_jy] == EL_SP_BASE ||
9268 Feld[new_jx][new_jy] == EL_SAND ||
9269 (IS_SP_PORT(Feld[new_jx][new_jy]) &&
9270 canEnterSupaplexPort(new_jx, new_jy, dx, dy)))
9271 /* !!! extend EL_SAND to anything diggable !!! */
9277 boolean player_is_standing_on_valid_field =
9278 (IS_WALKABLE_INSIDE(Feld[jx][jy]) ||
9279 (IS_WALKABLE(Feld[jx][jy]) && !ACCESS_FROM(Feld[jx][jy], MV_DOWN)));
9283 printf("::: checking gravity NOW [%d, %d, %d] [%d] [%d / %d] ...\n",
9284 player_can_fall_down,
9285 player_is_standing_on_valid_field,
9286 player_is_moving_to_valid_field,
9287 (player_is_moving_to_valid_field ? Feld[new_jx][new_jy] : -1),
9288 player->effective_action,
9289 player->can_fall_into_acid);
9292 if (player_can_fall_down &&
9294 !player_is_standing_on_valid_field &&
9296 !player_is_moving_to_valid_field)
9299 printf("::: setting programmed_action to MV_DOWN [%d,%d - %d] ...\n",
9300 jx, jy, FrameCounter);
9303 player->programmed_action = MV_DOWN;
9308 static void CheckGravityMovementWhenNotMoving(struct PlayerInfo *player)
9311 return CheckGravityMovement(player);
9314 if (game.gravity && !player->programmed_action)
9316 int jx = player->jx, jy = player->jy;
9317 boolean field_under_player_is_free =
9318 (IN_LEV_FIELD(jx, jy + 1) && IS_FREE(jx, jy + 1));
9319 boolean player_is_standing_on_valid_field =
9320 (IS_WALKABLE_INSIDE(Feld[jx][jy]) ||
9321 (IS_WALKABLE(Feld[jx][jy]) &&
9322 !(element_info[Feld[jx][jy]].access_direction & MV_DOWN)));
9324 if (field_under_player_is_free && !player_is_standing_on_valid_field)
9325 player->programmed_action = MV_DOWN;
9331 -----------------------------------------------------------------------------
9332 dx, dy: direction (non-diagonal) to try to move the player to
9333 real_dx, real_dy: direction as read from input device (can be diagonal)
9336 boolean MovePlayerOneStep(struct PlayerInfo *player,
9337 int dx, int dy, int real_dx, int real_dy)
9340 static int trigger_sides[4][2] =
9342 /* enter side leave side */
9343 { CH_SIDE_RIGHT, CH_SIDE_LEFT }, /* moving left */
9344 { CH_SIDE_LEFT, CH_SIDE_RIGHT }, /* moving right */
9345 { CH_SIDE_BOTTOM, CH_SIDE_TOP }, /* moving up */
9346 { CH_SIDE_TOP, CH_SIDE_BOTTOM } /* moving down */
9348 int move_direction = (dx == -1 ? MV_LEFT :
9349 dx == +1 ? MV_RIGHT :
9351 dy == +1 ? MV_DOWN : MV_NO_MOVING);
9352 int enter_side = trigger_sides[MV_DIR_BIT(move_direction)][0];
9353 int leave_side = trigger_sides[MV_DIR_BIT(move_direction)][1];
9355 int jx = player->jx, jy = player->jy;
9356 int new_jx = jx + dx, new_jy = jy + dy;
9360 if (!player->active || (!dx && !dy))
9361 return MF_NO_ACTION;
9363 player->MovDir = (dx < 0 ? MV_LEFT :
9366 dy > 0 ? MV_DOWN : MV_NO_MOVING);
9368 if (!IN_LEV_FIELD(new_jx, new_jy))
9369 return MF_NO_ACTION;
9371 if (!options.network && !AllPlayersInSight(player, new_jx, new_jy))
9372 return MF_NO_ACTION;
9375 element = MovingOrBlocked2Element(new_jx, new_jy);
9377 element = MovingOrBlocked2ElementIfNotLeaving(new_jx, new_jy);
9380 if (DONT_RUN_INTO(element))
9382 if (element == EL_ACID && dx == 0 && dy == 1)
9384 SplashAcid(new_jx, new_jy);
9385 Feld[jx][jy] = EL_PLAYER_1;
9386 InitMovingField(jx, jy, MV_DOWN);
9387 Store[jx][jy] = EL_ACID;
9388 ContinueMoving(jx, jy);
9392 TestIfHeroRunsIntoBadThing(jx, jy, player->MovDir);
9397 can_move = DigField(player, jx, jy, new_jx, new_jy, real_dx,real_dy, DF_DIG);
9398 if (can_move != MF_MOVING)
9401 /* check if DigField() has caused relocation of the player */
9402 if (player->jx != jx || player->jy != jy)
9403 return MF_NO_ACTION;
9405 StorePlayer[jx][jy] = 0;
9406 player->last_jx = jx;
9407 player->last_jy = jy;
9408 player->jx = new_jx;
9409 player->jy = new_jy;
9410 StorePlayer[new_jx][new_jy] = player->element_nr;
9413 (dx > 0 || dy > 0 ? -1 : 1) * (TILEX - TILEX / player->move_delay_value);
9415 player->step_counter++;
9418 player->drop_delay = 0;
9421 PlayerVisit[jx][jy] = FrameCounter;
9423 ScrollPlayer(player, SCROLL_INIT);
9426 if (IS_CUSTOM_ELEMENT(Feld[jx][jy]))
9428 CheckTriggeredElementChangeBySide(jx, jy, Feld[jx][jy], CE_OTHER_GETS_LEFT,
9430 CheckElementChangeBySide(jx,jy, Feld[jx][jy],CE_LEFT_BY_PLAYER,leave_side);
9433 if (IS_CUSTOM_ELEMENT(Feld[new_jx][new_jy]))
9435 CheckTriggeredElementChangeBySide(new_jx, new_jy, Feld[new_jx][new_jy],
9436 CE_OTHER_GETS_ENTERED, enter_side);
9437 CheckElementChangeBySide(new_jx, new_jy, Feld[new_jx][new_jy],
9438 CE_ENTERED_BY_PLAYER, enter_side);
9445 boolean MovePlayer(struct PlayerInfo *player, int dx, int dy)
9447 int jx = player->jx, jy = player->jy;
9448 int old_jx = jx, old_jy = jy;
9449 int moved = MF_NO_ACTION;
9452 if (!player->active)
9457 if (player->MovPos == 0)
9459 player->is_moving = FALSE;
9460 player->is_digging = FALSE;
9461 player->is_collecting = FALSE;
9462 player->is_snapping = FALSE;
9463 player->is_pushing = FALSE;
9469 if (!player->active || (!dx && !dy))
9474 if (!FrameReached(&player->move_delay, player->move_delay_value) &&
9480 if (!FrameReached(&player->move_delay, player->move_delay_value))
9483 if (!FrameReached(&player->move_delay, player->move_delay_value) &&
9484 !(tape.playing && tape.file_version < FILE_VERSION_2_0))
9490 /* store if player is automatically moved to next field */
9491 player->is_auto_moving = (player->programmed_action != MV_NO_MOVING);
9493 /* remove the last programmed player action */
9494 player->programmed_action = 0;
9498 /* should only happen if pre-1.2 tape recordings are played */
9499 /* this is only for backward compatibility */
9501 int original_move_delay_value = player->move_delay_value;
9504 printf("THIS SHOULD ONLY HAPPEN WITH PRE-1.2 LEVEL TAPES. [%ld]\n",
9508 /* scroll remaining steps with finest movement resolution */
9509 player->move_delay_value = MOVE_DELAY_NORMAL_SPEED;
9511 while (player->MovPos)
9513 ScrollPlayer(player, SCROLL_GO_ON);
9514 ScrollScreen(NULL, SCROLL_GO_ON);
9520 player->move_delay_value = original_move_delay_value;
9523 if (player->last_move_dir & MV_HORIZONTAL)
9525 if (!(moved |= MovePlayerOneStep(player, 0, dy, dx, dy)))
9526 moved |= MovePlayerOneStep(player, dx, 0, dx, dy);
9530 if (!(moved |= MovePlayerOneStep(player, dx, 0, dx, dy)))
9531 moved |= MovePlayerOneStep(player, 0, dy, dx, dy);
9537 if (moved & MF_MOVING && !ScreenMovPos &&
9538 (player == local_player || !options.network))
9540 int old_scroll_x = scroll_x, old_scroll_y = scroll_y;
9541 int offset = (setup.scroll_delay ? 3 : 0);
9543 if (!IN_VIS_FIELD(SCREENX(jx), SCREENY(jy)))
9545 /* actual player has left the screen -- scroll in that direction */
9546 if (jx != old_jx) /* player has moved horizontally */
9547 scroll_x += (jx - old_jx);
9548 else /* player has moved vertically */
9549 scroll_y += (jy - old_jy);
9553 if (jx != old_jx) /* player has moved horizontally */
9555 if ((player->MovDir == MV_LEFT && scroll_x > jx - MIDPOSX + offset) ||
9556 (player->MovDir == MV_RIGHT && scroll_x < jx - MIDPOSX - offset))
9557 scroll_x = jx-MIDPOSX + (scroll_x < jx-MIDPOSX ? -offset : +offset);
9559 /* don't scroll over playfield boundaries */
9560 if (scroll_x < SBX_Left || scroll_x > SBX_Right)
9561 scroll_x = (scroll_x < SBX_Left ? SBX_Left : SBX_Right);
9563 /* don't scroll more than one field at a time */
9564 scroll_x = old_scroll_x + SIGN(scroll_x - old_scroll_x);
9566 /* don't scroll against the player's moving direction */
9567 if ((player->MovDir == MV_LEFT && scroll_x > old_scroll_x) ||
9568 (player->MovDir == MV_RIGHT && scroll_x < old_scroll_x))
9569 scroll_x = old_scroll_x;
9571 else /* player has moved vertically */
9573 if ((player->MovDir == MV_UP && scroll_y > jy - MIDPOSY + offset) ||
9574 (player->MovDir == MV_DOWN && scroll_y < jy - MIDPOSY - offset))
9575 scroll_y = jy-MIDPOSY + (scroll_y < jy-MIDPOSY ? -offset : +offset);
9577 /* don't scroll over playfield boundaries */
9578 if (scroll_y < SBY_Upper || scroll_y > SBY_Lower)
9579 scroll_y = (scroll_y < SBY_Upper ? SBY_Upper : SBY_Lower);
9581 /* don't scroll more than one field at a time */
9582 scroll_y = old_scroll_y + SIGN(scroll_y - old_scroll_y);
9584 /* don't scroll against the player's moving direction */
9585 if ((player->MovDir == MV_UP && scroll_y > old_scroll_y) ||
9586 (player->MovDir == MV_DOWN && scroll_y < old_scroll_y))
9587 scroll_y = old_scroll_y;
9591 if (scroll_x != old_scroll_x || scroll_y != old_scroll_y)
9593 if (!options.network && !AllPlayersInVisibleScreen())
9595 scroll_x = old_scroll_x;
9596 scroll_y = old_scroll_y;
9600 ScrollScreen(player, SCROLL_INIT);
9601 ScrollLevel(old_scroll_x - scroll_x, old_scroll_y - scroll_y);
9608 InitPlayerGfxAnimation(player, ACTION_DEFAULT);
9610 if (!(moved & MF_MOVING) && !player->is_pushing)
9615 player->StepFrame = 0;
9617 if (moved & MF_MOVING)
9619 if (old_jx != jx && old_jy == jy)
9620 player->MovDir = (old_jx < jx ? MV_RIGHT : MV_LEFT);
9621 else if (old_jx == jx && old_jy != jy)
9622 player->MovDir = (old_jy < jy ? MV_DOWN : MV_UP);
9624 DrawLevelField(jx, jy); /* for "crumbled sand" */
9626 player->last_move_dir = player->MovDir;
9627 player->is_moving = TRUE;
9629 player->is_snapping = FALSE;
9633 player->is_switching = FALSE;
9636 player->is_dropping = FALSE;
9640 /* !!! ENABLE THIS FOR OLD VERSIONS !!! */
9643 if (game.engine_version < VERSION_IDENT(3,1,0,0))
9646 int move_direction = player->MovDir;
9648 int enter_side = MV_DIR_OPPOSITE(move_direction);
9649 int leave_side = move_direction;
9651 static int trigger_sides[4][2] =
9653 /* enter side leave side */
9654 { CH_SIDE_RIGHT, CH_SIDE_LEFT }, /* moving left */
9655 { CH_SIDE_LEFT, CH_SIDE_RIGHT }, /* moving right */
9656 { CH_SIDE_BOTTOM, CH_SIDE_TOP }, /* moving up */
9657 { CH_SIDE_TOP, CH_SIDE_BOTTOM } /* moving down */
9659 int enter_side = trigger_sides[MV_DIR_BIT(move_direction)][0];
9660 int leave_side = trigger_sides[MV_DIR_BIT(move_direction)][1];
9662 int old_element = Feld[old_jx][old_jy];
9663 int new_element = Feld[jx][jy];
9666 /* !!! TEST ONLY !!! */
9667 if (IS_CUSTOM_ELEMENT(old_element))
9668 CheckElementChangeByPlayer(old_jx, old_jy, old_element,
9670 player->index_bit, leave_side);
9672 CheckTriggeredElementChangeByPlayer(old_jx, old_jy, old_element,
9674 player->index_bit, leave_side);
9676 if (IS_CUSTOM_ELEMENT(new_element))
9677 CheckElementChangeByPlayer(jx, jy, new_element, CE_ENTERED_BY_PLAYER,
9678 player->index_bit, enter_side);
9680 CheckTriggeredElementChangeByPlayer(jx, jy, new_element,
9681 CE_OTHER_GETS_ENTERED,
9682 player->index_bit, enter_side);
9692 CheckGravityMovementWhenNotMoving(player);
9695 player->last_move_dir = MV_NO_MOVING;
9697 player->is_moving = FALSE;
9700 if (game.engine_version < VERSION_IDENT(3,0,7,0))
9702 TestIfHeroTouchesBadThing(jx, jy);
9703 TestIfPlayerTouchesCustomElement(jx, jy);
9706 if (!player->active)
9712 void ScrollPlayer(struct PlayerInfo *player, int mode)
9714 int jx = player->jx, jy = player->jy;
9715 int last_jx = player->last_jx, last_jy = player->last_jy;
9716 int move_stepsize = TILEX / player->move_delay_value;
9718 if (!player->active || !player->MovPos)
9721 if (mode == SCROLL_INIT)
9723 player->actual_frame_counter = FrameCounter;
9724 player->GfxPos = move_stepsize * (player->MovPos / move_stepsize);
9726 if (Feld[last_jx][last_jy] == EL_EMPTY)
9727 Feld[last_jx][last_jy] = EL_PLAYER_IS_LEAVING;
9735 else if (!FrameReached(&player->actual_frame_counter, 1))
9738 player->MovPos += (player->MovPos > 0 ? -1 : 1) * move_stepsize;
9739 player->GfxPos = move_stepsize * (player->MovPos / move_stepsize);
9741 if (!player->block_last_field &&
9742 Feld[last_jx][last_jy] == EL_PLAYER_IS_LEAVING)
9743 Feld[last_jx][last_jy] = EL_EMPTY;
9745 /* before DrawPlayer() to draw correct player graphic for this case */
9746 if (player->MovPos == 0)
9747 CheckGravityMovement(player);
9750 DrawPlayer(player); /* needed here only to cleanup last field */
9753 if (player->MovPos == 0) /* player reached destination field */
9756 if (player->move_delay_reset_counter > 0)
9758 player->move_delay_reset_counter--;
9760 if (player->move_delay_reset_counter == 0)
9762 /* continue with normal speed after quickly moving through gate */
9763 HALVE_PLAYER_SPEED(player);
9765 /* be able to make the next move without delay */
9766 player->move_delay = 0;
9770 if (IS_PASSABLE(Feld[last_jx][last_jy]))
9772 /* continue with normal speed after quickly moving through gate */
9773 HALVE_PLAYER_SPEED(player);
9775 /* be able to make the next move without delay */
9776 player->move_delay = 0;
9780 if (player->block_last_field &&
9781 Feld[last_jx][last_jy] == EL_PLAYER_IS_LEAVING)
9782 Feld[last_jx][last_jy] = EL_EMPTY;
9784 player->last_jx = jx;
9785 player->last_jy = jy;
9787 if (Feld[jx][jy] == EL_EXIT_OPEN ||
9788 Feld[jx][jy] == EL_SP_EXIT_OPEN ||
9789 Feld[jx][jy] == EL_SP_EXIT_OPENING) /* <-- special case */
9791 DrawPlayer(player); /* needed here only to cleanup last field */
9794 if (local_player->friends_still_needed == 0 ||
9795 IS_SP_ELEMENT(Feld[jx][jy]))
9796 player->LevelSolved = player->GameOver = TRUE;
9800 /* !!! ENABLE THIS FOR NEW VERSIONS !!! */
9801 /* this breaks one level: "machine", level 000 */
9803 if (game.engine_version >= VERSION_IDENT(3,1,0,0))
9806 int move_direction = player->MovDir;
9808 int enter_side = MV_DIR_OPPOSITE(move_direction);
9809 int leave_side = move_direction;
9811 static int trigger_sides[4][2] =
9813 /* enter side leave side */
9814 { CH_SIDE_RIGHT, CH_SIDE_LEFT }, /* moving left */
9815 { CH_SIDE_LEFT, CH_SIDE_RIGHT }, /* moving right */
9816 { CH_SIDE_BOTTOM, CH_SIDE_TOP }, /* moving up */
9817 { CH_SIDE_TOP, CH_SIDE_BOTTOM } /* moving down */
9819 int enter_side = trigger_sides[MV_DIR_BIT(move_direction)][0];
9820 int leave_side = trigger_sides[MV_DIR_BIT(move_direction)][1];
9822 int old_jx = last_jx;
9823 int old_jy = last_jy;
9824 int old_element = Feld[old_jx][old_jy];
9825 int new_element = Feld[jx][jy];
9828 /* !!! TEST ONLY !!! */
9829 if (IS_CUSTOM_ELEMENT(old_element))
9830 CheckElementChangeByPlayer(old_jx, old_jy, old_element,
9832 player->index_bit, leave_side);
9834 CheckTriggeredElementChangeByPlayer(old_jx, old_jy, old_element,
9836 player->index_bit, leave_side);
9838 if (IS_CUSTOM_ELEMENT(new_element))
9839 CheckElementChangeByPlayer(jx, jy, new_element, CE_ENTERED_BY_PLAYER,
9840 player->index_bit, enter_side);
9842 CheckTriggeredElementChangeByPlayer(jx, jy, new_element,
9843 CE_OTHER_GETS_ENTERED,
9844 player->index_bit, enter_side);
9850 if (game.engine_version >= VERSION_IDENT(3,0,7,0))
9852 TestIfHeroTouchesBadThing(jx, jy);
9853 TestIfPlayerTouchesCustomElement(jx, jy);
9856 /* needed because pushed element has not yet reached its destination,
9857 so it would trigger a change event at its previous field location */
9858 if (!player->is_pushing)
9860 TestIfElementTouchesCustomElement(jx, jy); /* for empty space */
9863 if (!player->active)
9867 if (level.use_step_counter)
9877 if (TimeLeft <= 10 && setup.time_limit)
9878 PlaySoundStereo(SND_GAME_RUNNING_OUT_OF_TIME, SOUND_MIDDLE);
9880 DrawGameValue_Time(TimeLeft);
9882 if (!TimeLeft && setup.time_limit)
9883 for (i = 0; i < MAX_PLAYERS; i++)
9884 KillHero(&stored_player[i]);
9886 else if (level.time == 0 && !AllPlayersGone) /* level w/o time limit */
9887 DrawGameValue_Time(TimePlayed);
9890 if (tape.single_step && tape.recording && !tape.pausing &&
9891 !player->programmed_action)
9892 TapeTogglePause(TAPE_TOGGLE_AUTOMATIC);
9896 void ScrollScreen(struct PlayerInfo *player, int mode)
9898 static unsigned long screen_frame_counter = 0;
9900 if (mode == SCROLL_INIT)
9902 /* set scrolling step size according to actual player's moving speed */
9903 ScrollStepSize = TILEX / player->move_delay_value;
9905 screen_frame_counter = FrameCounter;
9906 ScreenMovDir = player->MovDir;
9907 ScreenMovPos = player->MovPos;
9908 ScreenGfxPos = ScrollStepSize * (ScreenMovPos / ScrollStepSize);
9911 else if (!FrameReached(&screen_frame_counter, 1))
9916 ScreenMovPos += (ScreenMovPos > 0 ? -1 : 1) * ScrollStepSize;
9917 ScreenGfxPos = ScrollStepSize * (ScreenMovPos / ScrollStepSize);
9918 redraw_mask |= REDRAW_FIELD;
9921 ScreenMovDir = MV_NO_MOVING;
9924 void TestIfPlayerTouchesCustomElement(int x, int y)
9926 static int xy[4][2] =
9933 static int trigger_sides[4][2] =
9935 /* center side border side */
9936 { CH_SIDE_TOP, CH_SIDE_BOTTOM }, /* check top */
9937 { CH_SIDE_LEFT, CH_SIDE_RIGHT }, /* check left */
9938 { CH_SIDE_RIGHT, CH_SIDE_LEFT }, /* check right */
9939 { CH_SIDE_BOTTOM, CH_SIDE_TOP } /* check bottom */
9941 static int touch_dir[4] =
9948 int center_element = Feld[x][y]; /* should always be non-moving! */
9951 for (i = 0; i < NUM_DIRECTIONS; i++)
9953 int xx = x + xy[i][0];
9954 int yy = y + xy[i][1];
9955 int center_side = trigger_sides[i][0];
9956 int border_side = trigger_sides[i][1];
9959 if (!IN_LEV_FIELD(xx, yy))
9962 if (IS_PLAYER(x, y))
9964 struct PlayerInfo *player = PLAYERINFO(x, y);
9966 if (game.engine_version < VERSION_IDENT(3,0,7,0))
9967 border_element = Feld[xx][yy]; /* may be moving! */
9968 else if (!IS_MOVING(xx, yy) && !IS_BLOCKED(xx, yy))
9969 border_element = Feld[xx][yy];
9970 else if (MovDir[xx][yy] & touch_dir[i]) /* elements are touching */
9971 border_element = MovingOrBlocked2Element(xx, yy);
9973 continue; /* center and border element do not touch */
9976 /* !!! TEST ONLY !!! */
9977 CheckElementChangeByPlayer(xx, yy, border_element, CE_TOUCHED_BY_PLAYER,
9978 player->index_bit, border_side);
9979 CheckTriggeredElementChangeByPlayer(xx, yy, border_element,
9980 CE_OTHER_GETS_TOUCHED,
9981 player->index_bit, border_side);
9983 CheckTriggeredElementChangeByPlayer(xx, yy, border_element,
9984 CE_OTHER_GETS_TOUCHED,
9985 player->index_bit, border_side);
9986 CheckElementChangeByPlayer(xx, yy, border_element, CE_TOUCHED_BY_PLAYER,
9987 player->index_bit, border_side);
9990 else if (IS_PLAYER(xx, yy))
9992 struct PlayerInfo *player = PLAYERINFO(xx, yy);
9994 if (game.engine_version >= VERSION_IDENT(3,0,7,0))
9996 if (player->MovPos != 0 && !(player->MovDir & touch_dir[i]))
9997 continue; /* center and border element do not touch */
10001 /* !!! TEST ONLY !!! */
10002 CheckElementChangeByPlayer(x, y, center_element, CE_TOUCHED_BY_PLAYER,
10003 player->index_bit, center_side);
10004 CheckTriggeredElementChangeByPlayer(x, y, center_element,
10005 CE_OTHER_GETS_TOUCHED,
10006 player->index_bit, center_side);
10008 CheckTriggeredElementChangeByPlayer(x, y, center_element,
10009 CE_OTHER_GETS_TOUCHED,
10010 player->index_bit, center_side);
10011 CheckElementChangeByPlayer(x, y, center_element, CE_TOUCHED_BY_PLAYER,
10012 player->index_bit, center_side);
10020 void TestIfElementTouchesCustomElement(int x, int y)
10022 static int xy[4][2] =
10029 static int trigger_sides[4][2] =
10031 /* center side border side */
10032 { CH_SIDE_TOP, CH_SIDE_BOTTOM }, /* check top */
10033 { CH_SIDE_LEFT, CH_SIDE_RIGHT }, /* check left */
10034 { CH_SIDE_RIGHT, CH_SIDE_LEFT }, /* check right */
10035 { CH_SIDE_BOTTOM, CH_SIDE_TOP } /* check bottom */
10037 static int touch_dir[4] =
10039 MV_LEFT | MV_RIGHT,
10044 boolean change_center_element = FALSE;
10045 int center_element_change_page = 0;
10046 int center_element = Feld[x][y]; /* should always be non-moving! */
10047 int border_trigger_element;
10050 for (i = 0; i < NUM_DIRECTIONS; i++)
10052 int xx = x + xy[i][0];
10053 int yy = y + xy[i][1];
10054 int center_side = trigger_sides[i][0];
10055 int border_side = trigger_sides[i][1];
10056 int border_element;
10058 if (!IN_LEV_FIELD(xx, yy))
10061 if (game.engine_version < VERSION_IDENT(3,0,7,0))
10062 border_element = Feld[xx][yy]; /* may be moving! */
10063 else if (!IS_MOVING(xx, yy) && !IS_BLOCKED(xx, yy))
10064 border_element = Feld[xx][yy];
10065 else if (MovDir[xx][yy] & touch_dir[i]) /* elements are touching */
10066 border_element = MovingOrBlocked2Element(xx, yy);
10068 continue; /* center and border element do not touch */
10070 /* check for change of center element (but change it only once) */
10071 if (IS_CUSTOM_ELEMENT(center_element) &&
10072 HAS_ANY_CHANGE_EVENT(center_element, CE_OTHER_IS_TOUCHING) &&
10073 !change_center_element)
10075 for (j = 0; j < element_info[center_element].num_change_pages; j++)
10077 struct ElementChangeInfo *change =
10078 &element_info[center_element].change_page[j];
10080 if (change->can_change &&
10081 change->events & CH_EVENT_BIT(CE_OTHER_IS_TOUCHING) &&
10082 change->trigger_side & border_side &&
10084 IS_EQUAL_OR_IN_GROUP(border_element, change->trigger_element)
10086 change->trigger_element == border_element
10090 change_center_element = TRUE;
10091 center_element_change_page = j;
10092 border_trigger_element = border_element;
10099 /* check for change of border element */
10100 if (IS_CUSTOM_ELEMENT(border_element) &&
10101 HAS_ANY_CHANGE_EVENT(border_element, CE_OTHER_IS_TOUCHING))
10103 for (j = 0; j < element_info[border_element].num_change_pages; j++)
10105 struct ElementChangeInfo *change =
10106 &element_info[border_element].change_page[j];
10108 if (change->can_change &&
10109 change->events & CH_EVENT_BIT(CE_OTHER_IS_TOUCHING) &&
10110 change->trigger_side & center_side &&
10112 IS_EQUAL_OR_IN_GROUP(center_element, change->trigger_element)
10114 change->trigger_element == center_element
10119 printf("::: border_element %d, %d\n", x, y);
10122 CheckElementChangeByPage(xx, yy, border_element, center_element,
10123 CE_OTHER_IS_TOUCHING, j);
10130 if (change_center_element)
10133 printf("::: center_element %d, %d\n", x, y);
10136 CheckElementChangeByPage(x, y, center_element, border_trigger_element,
10137 CE_OTHER_IS_TOUCHING, center_element_change_page);
10141 void TestIfElementHitsCustomElement(int x, int y, int direction)
10143 int dx = (direction == MV_LEFT ? -1 : direction == MV_RIGHT ? +1 : 0);
10144 int dy = (direction == MV_UP ? -1 : direction == MV_DOWN ? +1 : 0);
10145 int hitx = x + dx, hity = y + dy;
10146 int hitting_element = Feld[x][y];
10147 int touched_element;
10149 boolean object_hit = (IN_LEV_FIELD(hitx, hity) &&
10150 !IS_FREE(hitx, hity) &&
10151 (!IS_MOVING(hitx, hity) ||
10152 MovDir[hitx][hity] != direction ||
10153 ABS(MovPos[hitx][hity]) <= TILEY / 2));
10156 if (IN_LEV_FIELD(hitx, hity) && IS_FREE(hitx, hity))
10160 if (IN_LEV_FIELD(hitx, hity) && !object_hit)
10164 touched_element = (IN_LEV_FIELD(hitx, hity) ?
10165 MovingOrBlocked2Element(hitx, hity) : EL_STEELWALL);
10167 CheckElementChangeBySide(x, y, hitting_element, touched_element,
10168 CE_HITTING_SOMETHING, direction);
10170 if (IN_LEV_FIELD(hitx, hity))
10172 int opposite_direction = MV_DIR_OPPOSITE(direction);
10173 int hitting_side = direction;
10174 int touched_side = opposite_direction;
10176 int touched_element = MovingOrBlocked2Element(hitx, hity);
10179 boolean object_hit = (!IS_MOVING(hitx, hity) ||
10180 MovDir[hitx][hity] != direction ||
10181 ABS(MovPos[hitx][hity]) <= TILEY / 2);
10190 CheckElementChangeBySide(hitx, hity, touched_element, hitting_element,
10191 CE_HIT_BY_SOMETHING, opposite_direction);
10193 if (IS_CUSTOM_ELEMENT(hitting_element) &&
10194 HAS_ANY_CHANGE_EVENT(hitting_element, CE_OTHER_IS_HITTING))
10196 for (i = 0; i < element_info[hitting_element].num_change_pages; i++)
10198 struct ElementChangeInfo *change =
10199 &element_info[hitting_element].change_page[i];
10201 if (change->can_change &&
10202 change->events & CH_EVENT_BIT(CE_OTHER_IS_HITTING) &&
10203 change->trigger_side & touched_side &&
10206 IS_EQUAL_OR_IN_GROUP(touched_element, change->trigger_element)
10208 change->trigger_element == touched_element
10212 CheckElementChangeByPage(x, y, hitting_element, touched_element,
10213 CE_OTHER_IS_HITTING, i);
10219 if (IS_CUSTOM_ELEMENT(touched_element) &&
10220 HAS_ANY_CHANGE_EVENT(touched_element, CE_OTHER_GETS_HIT))
10222 for (i = 0; i < element_info[touched_element].num_change_pages; i++)
10224 struct ElementChangeInfo *change =
10225 &element_info[touched_element].change_page[i];
10227 if (change->can_change &&
10228 change->events & CH_EVENT_BIT(CE_OTHER_GETS_HIT) &&
10229 change->trigger_side & hitting_side &&
10231 IS_EQUAL_OR_IN_GROUP(hitting_element, change->trigger_element)
10233 change->trigger_element == hitting_element
10237 CheckElementChangeByPage(hitx, hity, touched_element,
10238 hitting_element, CE_OTHER_GETS_HIT, i);
10248 void TestIfElementSmashesCustomElement(int x, int y, int direction)
10250 int dx = (direction == MV_LEFT ? -1 : direction == MV_RIGHT ? +1 : 0);
10251 int dy = (direction == MV_UP ? -1 : direction == MV_DOWN ? +1 : 0);
10252 int hitx = x + dx, hity = y + dy;
10253 int hitting_element = Feld[x][y];
10254 int touched_element;
10256 boolean object_hit = (IN_LEV_FIELD(hitx, hity) &&
10257 !IS_FREE(hitx, hity) &&
10258 (!IS_MOVING(hitx, hity) ||
10259 MovDir[hitx][hity] != direction ||
10260 ABS(MovPos[hitx][hity]) <= TILEY / 2));
10263 if (IN_LEV_FIELD(hitx, hity) && IS_FREE(hitx, hity))
10267 if (IN_LEV_FIELD(hitx, hity) && !object_hit)
10271 touched_element = (IN_LEV_FIELD(hitx, hity) ?
10272 MovingOrBlocked2Element(hitx, hity) : EL_STEELWALL);
10274 CheckElementChangeBySide(x, y, hitting_element, touched_element,
10275 EP_CAN_SMASH_EVERYTHING, direction);
10277 if (IN_LEV_FIELD(hitx, hity))
10279 int opposite_direction = MV_DIR_OPPOSITE(direction);
10280 int hitting_side = direction;
10281 int touched_side = opposite_direction;
10283 int touched_element = MovingOrBlocked2Element(hitx, hity);
10286 boolean object_hit = (!IS_MOVING(hitx, hity) ||
10287 MovDir[hitx][hity] != direction ||
10288 ABS(MovPos[hitx][hity]) <= TILEY / 2);
10297 CheckElementChangeBySide(hitx, hity, touched_element, hitting_element,
10298 CE_SMASHED_BY_SOMETHING, opposite_direction);
10300 if (IS_CUSTOM_ELEMENT(hitting_element) &&
10301 HAS_ANY_CHANGE_EVENT(hitting_element, CE_OTHER_IS_SMASHING))
10303 for (i = 0; i < element_info[hitting_element].num_change_pages; i++)
10305 struct ElementChangeInfo *change =
10306 &element_info[hitting_element].change_page[i];
10308 if (change->can_change &&
10309 change->events & CH_EVENT_BIT(CE_OTHER_IS_SMASHING) &&
10310 change->trigger_side & touched_side &&
10313 IS_EQUAL_OR_IN_GROUP(touched_element, change->trigger_element)
10315 change->trigger_element == touched_element
10319 CheckElementChangeByPage(x, y, hitting_element, touched_element,
10320 CE_OTHER_IS_SMASHING, i);
10326 if (IS_CUSTOM_ELEMENT(touched_element) &&
10327 HAS_ANY_CHANGE_EVENT(touched_element, CE_OTHER_GETS_SMASHED))
10329 for (i = 0; i < element_info[touched_element].num_change_pages; i++)
10331 struct ElementChangeInfo *change =
10332 &element_info[touched_element].change_page[i];
10334 if (change->can_change &&
10335 change->events & CH_EVENT_BIT(CE_OTHER_GETS_SMASHED) &&
10336 change->trigger_side & hitting_side &&
10338 IS_EQUAL_OR_IN_GROUP(hitting_element, change->trigger_element)
10340 change->trigger_element == hitting_element
10344 CheckElementChangeByPage(hitx, hity, touched_element,
10345 hitting_element, CE_OTHER_GETS_SMASHED,i);
10355 void TestIfGoodThingHitsBadThing(int good_x, int good_y, int good_move_dir)
10357 int i, kill_x = -1, kill_y = -1;
10358 int bad_element = -1;
10359 static int test_xy[4][2] =
10366 static int test_dir[4] =
10374 for (i = 0; i < NUM_DIRECTIONS; i++)
10376 int test_x, test_y, test_move_dir, test_element;
10378 test_x = good_x + test_xy[i][0];
10379 test_y = good_y + test_xy[i][1];
10381 if (!IN_LEV_FIELD(test_x, test_y))
10385 (IS_MOVING(test_x, test_y) ? MovDir[test_x][test_y] : MV_NO_MOVING);
10388 test_element = Feld[test_x][test_y];
10390 test_element = MovingOrBlocked2ElementIfNotLeaving(test_x, test_y);
10393 /* 1st case: good thing is moving towards DONT_RUN_INTO style bad thing;
10394 2nd case: DONT_TOUCH style bad thing does not move away from good thing
10396 if ((DONT_RUN_INTO(test_element) && good_move_dir == test_dir[i]) ||
10397 (DONT_TOUCH(test_element) && test_move_dir != test_dir[i]))
10401 bad_element = test_element;
10407 if (kill_x != -1 || kill_y != -1)
10409 if (IS_PLAYER(good_x, good_y))
10411 struct PlayerInfo *player = PLAYERINFO(good_x, good_y);
10414 if (player->shield_deadly_time_left > 0 &&
10415 !IS_INDESTRUCTIBLE(bad_element))
10416 Bang(kill_x, kill_y);
10417 else if (!PLAYER_ENEMY_PROTECTED(good_x, good_y))
10420 if (player->shield_deadly_time_left > 0)
10421 Bang(kill_x, kill_y);
10422 else if (!PLAYER_ENEMY_PROTECTED(good_x, good_y))
10427 Bang(good_x, good_y);
10431 void TestIfBadThingHitsGoodThing(int bad_x, int bad_y, int bad_move_dir)
10433 int i, kill_x = -1, kill_y = -1;
10434 int bad_element = Feld[bad_x][bad_y];
10435 static int test_xy[4][2] =
10442 static int touch_dir[4] =
10444 MV_LEFT | MV_RIGHT,
10449 static int test_dir[4] =
10457 if (bad_element == EL_EXPLOSION) /* skip just exploding bad things */
10460 for (i = 0; i < NUM_DIRECTIONS; i++)
10462 int test_x, test_y, test_move_dir, test_element;
10464 test_x = bad_x + test_xy[i][0];
10465 test_y = bad_y + test_xy[i][1];
10466 if (!IN_LEV_FIELD(test_x, test_y))
10470 (IS_MOVING(test_x, test_y) ? MovDir[test_x][test_y] : MV_NO_MOVING);
10472 test_element = Feld[test_x][test_y];
10474 /* 1st case: good thing is moving towards DONT_RUN_INTO style bad thing;
10475 2nd case: DONT_TOUCH style bad thing does not move away from good thing
10477 if ((DONT_RUN_INTO(bad_element) && bad_move_dir == test_dir[i]) ||
10478 (DONT_TOUCH(bad_element) && test_move_dir != test_dir[i]))
10480 /* good thing is player or penguin that does not move away */
10481 if (IS_PLAYER(test_x, test_y))
10483 struct PlayerInfo *player = PLAYERINFO(test_x, test_y);
10485 if (bad_element == EL_ROBOT && player->is_moving)
10486 continue; /* robot does not kill player if he is moving */
10488 if (game.engine_version >= VERSION_IDENT(3,0,7,0))
10490 if (player->MovPos != 0 && !(player->MovDir & touch_dir[i]))
10491 continue; /* center and border element do not touch */
10498 else if (test_element == EL_PENGUIN)
10507 if (kill_x != -1 || kill_y != -1)
10509 if (IS_PLAYER(kill_x, kill_y))
10511 struct PlayerInfo *player = PLAYERINFO(kill_x, kill_y);
10514 if (player->shield_deadly_time_left > 0 &&
10515 !IS_INDESTRUCTIBLE(bad_element))
10516 Bang(bad_x, bad_y);
10517 else if (!PLAYER_ENEMY_PROTECTED(kill_x, kill_y))
10520 if (player->shield_deadly_time_left > 0)
10521 Bang(bad_x, bad_y);
10522 else if (!PLAYER_ENEMY_PROTECTED(kill_x, kill_y))
10527 Bang(kill_x, kill_y);
10531 void TestIfHeroTouchesBadThing(int x, int y)
10533 TestIfGoodThingHitsBadThing(x, y, MV_NO_MOVING);
10536 void TestIfHeroRunsIntoBadThing(int x, int y, int move_dir)
10538 TestIfGoodThingHitsBadThing(x, y, move_dir);
10541 void TestIfBadThingTouchesHero(int x, int y)
10543 TestIfBadThingHitsGoodThing(x, y, MV_NO_MOVING);
10546 void TestIfBadThingRunsIntoHero(int x, int y, int move_dir)
10548 TestIfBadThingHitsGoodThing(x, y, move_dir);
10551 void TestIfFriendTouchesBadThing(int x, int y)
10553 TestIfGoodThingHitsBadThing(x, y, MV_NO_MOVING);
10556 void TestIfBadThingTouchesFriend(int x, int y)
10558 TestIfBadThingHitsGoodThing(x, y, MV_NO_MOVING);
10561 void TestIfBadThingTouchesOtherBadThing(int bad_x, int bad_y)
10563 int i, kill_x = bad_x, kill_y = bad_y;
10564 static int xy[4][2] =
10572 for (i = 0; i < NUM_DIRECTIONS; i++)
10576 x = bad_x + xy[i][0];
10577 y = bad_y + xy[i][1];
10578 if (!IN_LEV_FIELD(x, y))
10581 element = Feld[x][y];
10582 if (IS_AMOEBOID(element) || element == EL_GAME_OF_LIFE ||
10583 element == EL_AMOEBA_GROWING || element == EL_AMOEBA_DROP)
10591 if (kill_x != bad_x || kill_y != bad_y)
10592 Bang(bad_x, bad_y);
10595 void KillHero(struct PlayerInfo *player)
10597 int jx = player->jx, jy = player->jy;
10599 if (!player->active)
10602 /* remove accessible field at the player's position */
10603 Feld[jx][jy] = EL_EMPTY;
10605 /* deactivate shield (else Bang()/Explode() would not work right) */
10606 player->shield_normal_time_left = 0;
10607 player->shield_deadly_time_left = 0;
10613 static void KillHeroUnlessEnemyProtected(int x, int y)
10615 if (!PLAYER_ENEMY_PROTECTED(x, y))
10616 KillHero(PLAYERINFO(x, y));
10619 static void KillHeroUnlessExplosionProtected(int x, int y)
10621 if (!PLAYER_EXPLOSION_PROTECTED(x, y))
10622 KillHero(PLAYERINFO(x, y));
10625 void BuryHero(struct PlayerInfo *player)
10627 int jx = player->jx, jy = player->jy;
10629 if (!player->active)
10633 PlayLevelSoundElementAction(jx, jy, player->element_nr, ACTION_DYING);
10635 PlayLevelSound(jx, jy, SND_CLASS_PLAYER_DYING);
10637 PlayLevelSound(jx, jy, SND_GAME_LOSING);
10639 player->GameOver = TRUE;
10640 RemoveHero(player);
10643 void RemoveHero(struct PlayerInfo *player)
10645 int jx = player->jx, jy = player->jy;
10646 int i, found = FALSE;
10648 player->present = FALSE;
10649 player->active = FALSE;
10651 if (!ExplodeField[jx][jy])
10652 StorePlayer[jx][jy] = 0;
10654 for (i = 0; i < MAX_PLAYERS; i++)
10655 if (stored_player[i].active)
10659 AllPlayersGone = TRUE;
10666 =============================================================================
10667 checkDiagonalPushing()
10668 -----------------------------------------------------------------------------
10669 check if diagonal input device direction results in pushing of object
10670 (by checking if the alternative direction is walkable, diggable, ...)
10671 =============================================================================
10674 static boolean checkDiagonalPushing(struct PlayerInfo *player,
10675 int x, int y, int real_dx, int real_dy)
10677 int jx, jy, dx, dy, xx, yy;
10679 if (real_dx == 0 || real_dy == 0) /* no diagonal direction => push */
10682 /* diagonal direction: check alternative direction */
10687 xx = jx + (dx == 0 ? real_dx : 0);
10688 yy = jy + (dy == 0 ? real_dy : 0);
10690 return (!IN_LEV_FIELD(xx, yy) || IS_SOLID_FOR_PUSHING(Feld[xx][yy]));
10694 =============================================================================
10696 -----------------------------------------------------------------------------
10697 x, y: field next to player (non-diagonal) to try to dig to
10698 real_dx, real_dy: direction as read from input device (can be diagonal)
10699 =============================================================================
10702 int DigField(struct PlayerInfo *player,
10703 int oldx, int oldy, int x, int y,
10704 int real_dx, int real_dy, int mode)
10707 boolean use_spring_bug = (game.engine_version < VERSION_IDENT(2,2,0,0));
10709 boolean is_player = (IS_PLAYER(oldx, oldy) || mode != DF_DIG);
10710 boolean player_was_pushing = player->is_pushing;
10711 int jx = oldx, jy = oldy;
10712 int dx = x - jx, dy = y - jy;
10713 int nextx = x + dx, nexty = y + dy;
10714 int move_direction = (dx == -1 ? MV_LEFT :
10715 dx == +1 ? MV_RIGHT :
10717 dy == +1 ? MV_DOWN : MV_NO_MOVING);
10718 int opposite_direction = MV_DIR_OPPOSITE(move_direction);
10720 int dig_side = MV_DIR_OPPOSITE(move_direction);
10722 static int trigger_sides[4] =
10724 CH_SIDE_RIGHT, /* moving left */
10725 CH_SIDE_LEFT, /* moving right */
10726 CH_SIDE_BOTTOM, /* moving up */
10727 CH_SIDE_TOP, /* moving down */
10729 int dig_side = trigger_sides[MV_DIR_BIT(move_direction)];
10731 int old_element = Feld[jx][jy];
10734 if (is_player) /* function can also be called by EL_PENGUIN */
10736 if (player->MovPos == 0)
10738 player->is_digging = FALSE;
10739 player->is_collecting = FALSE;
10742 if (player->MovPos == 0) /* last pushing move finished */
10743 player->is_pushing = FALSE;
10745 if (mode == DF_NO_PUSH) /* player just stopped pushing */
10747 player->is_switching = FALSE;
10748 player->push_delay = 0;
10750 return MF_NO_ACTION;
10754 if (IS_MOVING(x, y) || IS_PLAYER(x, y))
10755 return MF_NO_ACTION;
10760 if (IS_TUBE(Feld[jx][jy]) || IS_TUBE(Back[jx][jy]))
10762 if (IS_TUBE(Feld[jx][jy]) ||
10763 (IS_TUBE(Back[jx][jy]) && game.engine_version >= VERSION_IDENT(2,2,0,0)))
10767 int tube_element = (IS_TUBE(Feld[jx][jy]) ? Feld[jx][jy] : Back[jx][jy]);
10768 int tube_leave_directions[][2] =
10770 { EL_TUBE_ANY, MV_LEFT | MV_RIGHT | MV_UP | MV_DOWN },
10771 { EL_TUBE_VERTICAL, MV_UP | MV_DOWN },
10772 { EL_TUBE_HORIZONTAL, MV_LEFT | MV_RIGHT },
10773 { EL_TUBE_VERTICAL_LEFT, MV_LEFT | MV_UP | MV_DOWN },
10774 { EL_TUBE_VERTICAL_RIGHT, MV_RIGHT | MV_UP | MV_DOWN },
10775 { EL_TUBE_HORIZONTAL_UP, MV_LEFT | MV_RIGHT | MV_UP },
10776 { EL_TUBE_HORIZONTAL_DOWN, MV_LEFT | MV_RIGHT | MV_DOWN },
10777 { EL_TUBE_LEFT_UP, MV_LEFT | MV_UP },
10778 { EL_TUBE_LEFT_DOWN, MV_LEFT | MV_DOWN },
10779 { EL_TUBE_RIGHT_UP, MV_RIGHT | MV_UP },
10780 { EL_TUBE_RIGHT_DOWN, MV_RIGHT | MV_DOWN },
10781 { -1, MV_LEFT | MV_RIGHT | MV_UP | MV_DOWN }
10784 while (tube_leave_directions[i][0] != tube_element)
10787 if (tube_leave_directions[i][0] == -1) /* should not happen */
10791 if (!(tube_leave_directions[i][1] & move_direction))
10792 return MF_NO_ACTION; /* tube has no opening in this direction */
10797 if (IS_TUBE(Back[jx][jy]) && game.engine_version >= VERSION_IDENT(2,2,0,0))
10798 old_element = Back[jx][jy];
10802 if (IS_WALKABLE(old_element) && !ACCESS_FROM(old_element, move_direction))
10803 return MF_NO_ACTION; /* field has no opening in this direction */
10805 if (IS_PASSABLE(old_element) && !ACCESS_FROM(old_element,opposite_direction))
10806 return MF_NO_ACTION; /* field has no opening in this direction */
10808 element = Feld[x][y];
10810 if (!is_player && !IS_COLLECTIBLE(element)) /* penguin cannot collect it */
10811 return MF_NO_ACTION;
10813 if (mode == DF_SNAP && !IS_SNAPPABLE(element) &&
10814 game.engine_version >= VERSION_IDENT(2,2,0,0))
10815 return MF_NO_ACTION;
10818 if (game.gravity && is_player && !player->is_auto_moving &&
10819 canFallDown(player) && move_direction != MV_DOWN &&
10820 !canMoveToValidFieldWithGravity(jx, jy, move_direction))
10821 return MF_NO_ACTION; /* player cannot walk here due to gravity */
10825 if (element == EL_EMPTY_SPACE &&
10826 game.gravity && !player->is_auto_moving &&
10827 canFallDown(player) && move_direction != MV_DOWN)
10828 return MF_NO_ACTION; /* player cannot walk here due to gravity */
10834 case EL_SP_PORT_LEFT:
10835 case EL_SP_PORT_RIGHT:
10836 case EL_SP_PORT_UP:
10837 case EL_SP_PORT_DOWN:
10838 case EL_SP_PORT_HORIZONTAL:
10839 case EL_SP_PORT_VERTICAL:
10840 case EL_SP_PORT_ANY:
10841 case EL_SP_GRAVITY_PORT_LEFT:
10842 case EL_SP_GRAVITY_PORT_RIGHT:
10843 case EL_SP_GRAVITY_PORT_UP:
10844 case EL_SP_GRAVITY_PORT_DOWN:
10846 if (!canEnterSupaplexPort(x, y, dx, dy))
10847 return MF_NO_ACTION;
10850 element != EL_SP_PORT_LEFT &&
10851 element != EL_SP_GRAVITY_PORT_LEFT &&
10852 element != EL_SP_PORT_HORIZONTAL &&
10853 element != EL_SP_PORT_ANY) ||
10855 element != EL_SP_PORT_RIGHT &&
10856 element != EL_SP_GRAVITY_PORT_RIGHT &&
10857 element != EL_SP_PORT_HORIZONTAL &&
10858 element != EL_SP_PORT_ANY) ||
10860 element != EL_SP_PORT_UP &&
10861 element != EL_SP_GRAVITY_PORT_UP &&
10862 element != EL_SP_PORT_VERTICAL &&
10863 element != EL_SP_PORT_ANY) ||
10865 element != EL_SP_PORT_DOWN &&
10866 element != EL_SP_GRAVITY_PORT_DOWN &&
10867 element != EL_SP_PORT_VERTICAL &&
10868 element != EL_SP_PORT_ANY) ||
10869 !IN_LEV_FIELD(nextx, nexty) ||
10870 !IS_FREE(nextx, nexty))
10871 return MF_NO_ACTION;
10874 if (element == EL_SP_GRAVITY_PORT_LEFT ||
10875 element == EL_SP_GRAVITY_PORT_RIGHT ||
10876 element == EL_SP_GRAVITY_PORT_UP ||
10877 element == EL_SP_GRAVITY_PORT_DOWN)
10878 game.gravity = !game.gravity;
10880 /* automatically move to the next field with double speed */
10881 player->programmed_action = move_direction;
10883 if (player->move_delay_reset_counter == 0)
10885 player->move_delay_reset_counter = 2; /* two double speed steps */
10887 DOUBLE_PLAYER_SPEED(player);
10890 player->move_delay_reset_counter = 2;
10892 DOUBLE_PLAYER_SPEED(player);
10896 printf("::: passing port %d,%d [%d]\n", x, y, FrameCounter);
10899 PlayLevelSound(x, y, SND_CLASS_SP_PORT_PASSING);
10905 case EL_TUBE_VERTICAL:
10906 case EL_TUBE_HORIZONTAL:
10907 case EL_TUBE_VERTICAL_LEFT:
10908 case EL_TUBE_VERTICAL_RIGHT:
10909 case EL_TUBE_HORIZONTAL_UP:
10910 case EL_TUBE_HORIZONTAL_DOWN:
10911 case EL_TUBE_LEFT_UP:
10912 case EL_TUBE_LEFT_DOWN:
10913 case EL_TUBE_RIGHT_UP:
10914 case EL_TUBE_RIGHT_DOWN:
10917 int tube_enter_directions[][2] =
10919 { EL_TUBE_ANY, MV_LEFT | MV_RIGHT | MV_UP | MV_DOWN },
10920 { EL_TUBE_VERTICAL, MV_UP | MV_DOWN },
10921 { EL_TUBE_HORIZONTAL, MV_LEFT | MV_RIGHT },
10922 { EL_TUBE_VERTICAL_LEFT, MV_RIGHT | MV_UP | MV_DOWN },
10923 { EL_TUBE_VERTICAL_RIGHT, MV_LEFT | MV_UP | MV_DOWN },
10924 { EL_TUBE_HORIZONTAL_UP, MV_LEFT | MV_RIGHT | MV_DOWN },
10925 { EL_TUBE_HORIZONTAL_DOWN, MV_LEFT | MV_RIGHT | MV_UP },
10926 { EL_TUBE_LEFT_UP, MV_RIGHT | MV_DOWN },
10927 { EL_TUBE_LEFT_DOWN, MV_RIGHT | MV_UP },
10928 { EL_TUBE_RIGHT_UP, MV_LEFT | MV_DOWN },
10929 { EL_TUBE_RIGHT_DOWN, MV_LEFT | MV_UP },
10930 { -1, MV_NO_MOVING }
10933 while (tube_enter_directions[i][0] != element)
10936 if (tube_enter_directions[i][0] == -1) /* should not happen */
10940 if (!(tube_enter_directions[i][1] & move_direction))
10941 return MF_NO_ACTION; /* tube has no opening in this direction */
10943 PlayLevelSound(x, y, SND_CLASS_TUBE_WALKING);
10951 if (IS_WALKABLE(element) && ACCESS_FROM(element, opposite_direction))
10953 if (IS_WALKABLE(element))
10956 int sound_element = SND_ELEMENT(element);
10957 int sound_action = ACTION_WALKING;
10960 if (!ACCESS_FROM(element, opposite_direction))
10961 return MF_NO_ACTION; /* field not accessible from this direction */
10965 if (element == EL_EMPTY_SPACE &&
10966 game.gravity && !player->is_auto_moving &&
10967 canFallDown(player) && move_direction != MV_DOWN)
10968 return MF_NO_ACTION; /* player cannot walk here due to gravity */
10971 if (IS_GATE(element))
10973 if (!player->key[element - EL_GATE_1])
10974 return MF_NO_ACTION;
10976 else if (IS_GATE_GRAY(element))
10978 if (!player->key[element - EL_GATE_1_GRAY])
10979 return MF_NO_ACTION;
10981 else if (element == EL_EXIT_OPEN ||
10982 element == EL_SP_EXIT_OPEN ||
10983 element == EL_SP_EXIT_OPENING)
10985 sound_action = ACTION_PASSING; /* player is passing exit */
10987 else if (element == EL_EMPTY)
10989 sound_action = ACTION_MOVING; /* nothing to walk on */
10992 /* play sound from background or player, whatever is available */
10993 if (element_info[sound_element].sound[sound_action] != SND_UNDEFINED)
10994 PlayLevelSoundElementAction(x, y, sound_element, sound_action);
10996 PlayLevelSoundElementAction(x, y, player->element_nr, sound_action);
11001 else if (IS_PASSABLE(element) && canPassField(x, y, move_direction))
11003 else if (IS_PASSABLE(element))
11007 if (!canPassField(x, y, move_direction))
11008 return MF_NO_ACTION;
11013 if (!IN_LEV_FIELD(nextx, nexty) || IS_PLAYER(nextx, nexty) ||
11014 !IS_WALKABLE_FROM(Feld[nextx][nexty], move_direction) ||
11015 (!level.can_pass_to_walkable && !IS_FREE(nextx, nexty)))
11016 return MF_NO_ACTION;
11018 if (!IN_LEV_FIELD(nextx, nexty) || !IS_FREE(nextx, nexty))
11019 return MF_NO_ACTION;
11024 if (!ACCESS_FROM(element, opposite_direction))
11025 return MF_NO_ACTION; /* field not accessible from this direction */
11027 if (IS_CUSTOM_ELEMENT(element) &&
11028 !ACCESS_FROM(element, opposite_direction))
11029 return MF_NO_ACTION; /* field not accessible from this direction */
11033 if (CAN_MOVE(element)) /* only fixed elements can be passed! */
11034 return MF_NO_ACTION;
11039 if (IS_EM_GATE(element))
11041 if (!player->key[element - EL_EM_GATE_1])
11042 return MF_NO_ACTION;
11044 else if (IS_EM_GATE_GRAY(element))
11046 if (!player->key[element - EL_EM_GATE_1_GRAY])
11047 return MF_NO_ACTION;
11049 else if (IS_SP_PORT(element))
11051 if (element == EL_SP_GRAVITY_PORT_LEFT ||
11052 element == EL_SP_GRAVITY_PORT_RIGHT ||
11053 element == EL_SP_GRAVITY_PORT_UP ||
11054 element == EL_SP_GRAVITY_PORT_DOWN)
11055 game.gravity = !game.gravity;
11056 else if (element == EL_SP_GRAVITY_ON_PORT_LEFT ||
11057 element == EL_SP_GRAVITY_ON_PORT_RIGHT ||
11058 element == EL_SP_GRAVITY_ON_PORT_UP ||
11059 element == EL_SP_GRAVITY_ON_PORT_DOWN)
11060 game.gravity = TRUE;
11061 else if (element == EL_SP_GRAVITY_OFF_PORT_LEFT ||
11062 element == EL_SP_GRAVITY_OFF_PORT_RIGHT ||
11063 element == EL_SP_GRAVITY_OFF_PORT_UP ||
11064 element == EL_SP_GRAVITY_OFF_PORT_DOWN)
11065 game.gravity = FALSE;
11068 /* automatically move to the next field with double speed */
11069 player->programmed_action = move_direction;
11071 if (player->move_delay_reset_counter == 0)
11073 player->move_delay_reset_counter = 2; /* two double speed steps */
11075 DOUBLE_PLAYER_SPEED(player);
11078 player->move_delay_reset_counter = 2;
11080 DOUBLE_PLAYER_SPEED(player);
11083 PlayLevelSoundAction(x, y, ACTION_PASSING);
11087 else if (IS_DIGGABLE(element))
11091 if (mode != DF_SNAP)
11094 GfxElement[x][y] = GFX_ELEMENT(element);
11097 (GFX_CRUMBLED(element) ? EL_SAND : GFX_ELEMENT(element));
11099 player->is_digging = TRUE;
11102 PlayLevelSoundElementAction(x, y, element, ACTION_DIGGING);
11104 CheckTriggeredElementChangeByPlayer(x, y, element,CE_OTHER_GETS_DIGGED,
11105 player->index_bit, dig_side);
11108 if (mode == DF_SNAP)
11109 TestIfElementTouchesCustomElement(x, y); /* for empty space */
11114 else if (IS_COLLECTIBLE(element))
11118 if (is_player && mode != DF_SNAP)
11120 GfxElement[x][y] = element;
11121 player->is_collecting = TRUE;
11124 if (element == EL_SPEED_PILL)
11125 player->move_delay_value = MOVE_DELAY_HIGH_SPEED;
11126 else if (element == EL_EXTRA_TIME && level.time > 0)
11129 DrawGameValue_Time(TimeLeft);
11131 else if (element == EL_SHIELD_NORMAL || element == EL_SHIELD_DEADLY)
11133 player->shield_normal_time_left += 10;
11134 if (element == EL_SHIELD_DEADLY)
11135 player->shield_deadly_time_left += 10;
11137 else if (element == EL_DYNAMITE || element == EL_SP_DISK_RED)
11139 if (player->inventory_size < MAX_INVENTORY_SIZE)
11140 player->inventory_element[player->inventory_size++] = element;
11142 DrawGameValue_Dynamite(local_player->inventory_size);
11144 else if (element == EL_DYNABOMB_INCREASE_NUMBER)
11146 player->dynabomb_count++;
11147 player->dynabombs_left++;
11149 else if (element == EL_DYNABOMB_INCREASE_SIZE)
11151 player->dynabomb_size++;
11153 else if (element == EL_DYNABOMB_INCREASE_POWER)
11155 player->dynabomb_xl = TRUE;
11157 else if ((element >= EL_KEY_1 && element <= EL_KEY_4) ||
11158 (element >= EL_EM_KEY_1 && element <= EL_EM_KEY_4))
11160 int key_nr = (element >= EL_KEY_1 && element <= EL_KEY_4 ?
11161 element - EL_KEY_1 : element - EL_EM_KEY_1);
11163 player->key[key_nr] = TRUE;
11165 DrawGameValue_Keys(player);
11167 redraw_mask |= REDRAW_DOOR_1;
11169 else if (IS_ENVELOPE(element))
11172 player->show_envelope = element;
11174 ShowEnvelope(element - EL_ENVELOPE_1);
11177 else if (IS_DROPPABLE(element) ||
11178 IS_THROWABLE(element)) /* can be collected and dropped */
11182 if (element_info[element].collect_count == 0)
11183 player->inventory_infinite_element = element;
11185 for (i = 0; i < element_info[element].collect_count; i++)
11186 if (player->inventory_size < MAX_INVENTORY_SIZE)
11187 player->inventory_element[player->inventory_size++] = element;
11189 DrawGameValue_Dynamite(local_player->inventory_size);
11191 else if (element_info[element].collect_count > 0)
11193 local_player->gems_still_needed -=
11194 element_info[element].collect_count;
11195 if (local_player->gems_still_needed < 0)
11196 local_player->gems_still_needed = 0;
11198 DrawGameValue_Emeralds(local_player->gems_still_needed);
11201 RaiseScoreElement(element);
11202 PlayLevelSoundElementAction(x, y, element, ACTION_COLLECTING);
11205 CheckTriggeredElementChangeByPlayer(x, y, element,
11206 CE_OTHER_GETS_COLLECTED,
11207 player->index_bit, dig_side);
11210 if (mode == DF_SNAP)
11211 TestIfElementTouchesCustomElement(x, y); /* for empty space */
11216 else if (IS_PUSHABLE(element))
11218 if (mode == DF_SNAP && element != EL_BD_ROCK)
11219 return MF_NO_ACTION;
11221 if (CAN_FALL(element) && dy)
11222 return MF_NO_ACTION;
11224 if (CAN_FALL(element) && IN_LEV_FIELD(x, y + 1) && IS_FREE(x, y + 1) &&
11225 !(element == EL_SPRING && level.use_spring_bug))
11226 return MF_NO_ACTION;
11229 if (CAN_MOVE(element) && GET_MAX_MOVE_DELAY(element) == 0 &&
11230 ((move_direction & MV_VERTICAL &&
11231 ((element_info[element].move_pattern & MV_LEFT &&
11232 IN_LEV_FIELD(x - 1, y) && IS_FREE(x - 1, y)) ||
11233 (element_info[element].move_pattern & MV_RIGHT &&
11234 IN_LEV_FIELD(x + 1, y) && IS_FREE(x + 1, y)))) ||
11235 (move_direction & MV_HORIZONTAL &&
11236 ((element_info[element].move_pattern & MV_UP &&
11237 IN_LEV_FIELD(x, y - 1) && IS_FREE(x, y - 1)) ||
11238 (element_info[element].move_pattern & MV_DOWN &&
11239 IN_LEV_FIELD(x, y + 1) && IS_FREE(x, y + 1))))))
11240 return MF_NO_ACTION;
11244 /* do not push elements already moving away faster than player */
11245 if (CAN_MOVE(element) && MovDir[x][y] == move_direction &&
11246 ABS(getElementMoveStepsize(x, y)) > MOVE_STEPSIZE_NORMAL)
11247 return MF_NO_ACTION;
11249 if (element == EL_SPRING && MovDir[x][y] != MV_NO_MOVING)
11250 return MF_NO_ACTION;
11256 if (game.engine_version >= VERSION_IDENT(3,1,0,0))
11258 if (player->push_delay_value == -1 || !player_was_pushing)
11259 player->push_delay_value = GET_NEW_PUSH_DELAY(element);
11261 else if (game.engine_version >= VERSION_IDENT(3,0,7,1))
11263 if (player->push_delay_value == -1)
11264 player->push_delay_value = GET_NEW_PUSH_DELAY(element);
11267 if (game.engine_version >= VERSION_IDENT(3,0,7,1))
11269 if (player->push_delay_value == -1 || !player_was_pushing)
11270 player->push_delay_value = GET_NEW_PUSH_DELAY(element);
11273 else if (game.engine_version >= VERSION_IDENT(2,2,0,7))
11275 if (!player->is_pushing)
11276 player->push_delay_value = GET_NEW_PUSH_DELAY(element);
11280 if (game.engine_version >= VERSION_IDENT(2,2,0,7) &&
11281 (game.engine_version < VERSION_IDENT(3,0,7,1) ||
11282 !player_is_pushing))
11283 player->push_delay_value = GET_NEW_PUSH_DELAY(element);
11286 if (!player->is_pushing &&
11287 game.engine_version >= VERSION_IDENT(2,2,0,7))
11288 player->push_delay_value = GET_NEW_PUSH_DELAY(element);
11292 printf("::: push delay: %ld -> %ld [%d, %d] [%d / %d] [%d '%s': %d]\n",
11293 player->push_delay, player->push_delay_value,
11294 FrameCounter, game.engine_version,
11295 player_was_pushing, player->is_pushing,
11296 element, element_info[element].token_name,
11297 GET_NEW_PUSH_DELAY(element));
11300 player->is_pushing = TRUE;
11302 if (!(IN_LEV_FIELD(nextx, nexty) &&
11303 (IS_FREE(nextx, nexty) ||
11304 (Feld[nextx][nexty] == EL_SOKOBAN_FIELD_EMPTY &&
11305 IS_SB_ELEMENT(element)))))
11306 return MF_NO_ACTION;
11308 if (!checkDiagonalPushing(player, x, y, real_dx, real_dy))
11309 return MF_NO_ACTION;
11311 if (player->push_delay == 0) /* new pushing; restart delay */
11312 player->push_delay = FrameCounter;
11314 if (!FrameReached(&player->push_delay, player->push_delay_value) &&
11315 !(tape.playing && tape.file_version < FILE_VERSION_2_0) &&
11316 element != EL_SPRING && element != EL_BALLOON)
11318 /* make sure that there is no move delay before next try to push */
11319 if (game.engine_version >= VERSION_IDENT(3,0,7,1))
11320 player->move_delay = INITIAL_MOVE_DELAY_OFF;
11322 return MF_NO_ACTION;
11326 printf("::: NOW PUSHING... [%d]\n", FrameCounter);
11329 if (IS_SB_ELEMENT(element))
11331 if (element == EL_SOKOBAN_FIELD_FULL)
11333 Back[x][y] = EL_SOKOBAN_FIELD_EMPTY;
11334 local_player->sokobanfields_still_needed++;
11337 if (Feld[nextx][nexty] == EL_SOKOBAN_FIELD_EMPTY)
11339 Back[nextx][nexty] = EL_SOKOBAN_FIELD_EMPTY;
11340 local_player->sokobanfields_still_needed--;
11343 Feld[x][y] = EL_SOKOBAN_OBJECT;
11345 if (Back[x][y] == Back[nextx][nexty])
11346 PlayLevelSoundAction(x, y, ACTION_PUSHING);
11347 else if (Back[x][y] != 0)
11348 PlayLevelSoundElementAction(x, y, EL_SOKOBAN_FIELD_FULL,
11351 PlayLevelSoundElementAction(nextx, nexty, EL_SOKOBAN_FIELD_EMPTY,
11354 if (local_player->sokobanfields_still_needed == 0 &&
11355 game.emulation == EMU_SOKOBAN)
11357 player->LevelSolved = player->GameOver = TRUE;
11358 PlayLevelSound(x, y, SND_GAME_SOKOBAN_SOLVING);
11362 PlayLevelSoundElementAction(x, y, element, ACTION_PUSHING);
11364 InitMovingField(x, y, move_direction);
11365 GfxAction[x][y] = ACTION_PUSHING;
11367 if (mode == DF_SNAP)
11368 ContinueMoving(x, y);
11370 MovPos[x][y] = (dx != 0 ? dx : dy);
11372 Pushed[x][y] = TRUE;
11373 Pushed[nextx][nexty] = TRUE;
11375 if (game.engine_version < VERSION_IDENT(2,2,0,7))
11376 player->push_delay_value = GET_NEW_PUSH_DELAY(element);
11378 player->push_delay_value = -1; /* get new value later */
11381 /* check for element change _after_ element has been pushed! */
11385 /* !!! TEST ONLY !!! */
11386 CheckElementChangeByPlayer(x, y, element, CE_PUSHED_BY_PLAYER,
11387 player->index_bit, dig_side);
11388 CheckTriggeredElementChangeByPlayer(x, y, element,CE_OTHER_GETS_PUSHED,
11389 player->index_bit, dig_side);
11391 CheckTriggeredElementChangeByPlayer(x, y, element,CE_OTHER_GETS_PUSHED,
11392 player->index_bit, dig_side);
11393 CheckElementChangeByPlayer(x, y, element, CE_PUSHED_BY_PLAYER,
11394 player->index_bit, dig_side);
11400 else if (IS_SWITCHABLE(element))
11402 if (PLAYER_SWITCHING(player, x, y))
11404 CheckTriggeredElementChangeByPlayer(x,y, element,
11405 CE_OTHER_GETS_PRESSED,
11406 player->index_bit, dig_side);
11411 player->is_switching = TRUE;
11412 player->switch_x = x;
11413 player->switch_y = y;
11415 PlayLevelSoundElementAction(x, y, element, ACTION_ACTIVATING);
11417 if (element == EL_ROBOT_WHEEL)
11419 Feld[x][y] = EL_ROBOT_WHEEL_ACTIVE;
11423 DrawLevelField(x, y);
11425 else if (element == EL_SP_TERMINAL)
11429 for (yy = 0; yy < lev_fieldy; yy++) for (xx=0; xx < lev_fieldx; xx++)
11431 if (Feld[xx][yy] == EL_SP_DISK_YELLOW)
11433 else if (Feld[xx][yy] == EL_SP_TERMINAL)
11434 Feld[xx][yy] = EL_SP_TERMINAL_ACTIVE;
11437 else if (IS_BELT_SWITCH(element))
11439 ToggleBeltSwitch(x, y);
11441 else if (element == EL_SWITCHGATE_SWITCH_UP ||
11442 element == EL_SWITCHGATE_SWITCH_DOWN)
11444 ToggleSwitchgateSwitch(x, y);
11446 else if (element == EL_LIGHT_SWITCH ||
11447 element == EL_LIGHT_SWITCH_ACTIVE)
11449 ToggleLightSwitch(x, y);
11452 PlayLevelSound(x, y, element == EL_LIGHT_SWITCH ?
11453 SND_LIGHT_SWITCH_ACTIVATING :
11454 SND_LIGHT_SWITCH_DEACTIVATING);
11457 else if (element == EL_TIMEGATE_SWITCH)
11459 ActivateTimegateSwitch(x, y);
11461 else if (element == EL_BALLOON_SWITCH_LEFT ||
11462 element == EL_BALLOON_SWITCH_RIGHT ||
11463 element == EL_BALLOON_SWITCH_UP ||
11464 element == EL_BALLOON_SWITCH_DOWN ||
11465 element == EL_BALLOON_SWITCH_ANY)
11467 if (element == EL_BALLOON_SWITCH_ANY)
11468 game.balloon_dir = move_direction;
11470 game.balloon_dir = (element == EL_BALLOON_SWITCH_LEFT ? MV_LEFT :
11471 element == EL_BALLOON_SWITCH_RIGHT ? MV_RIGHT :
11472 element == EL_BALLOON_SWITCH_UP ? MV_UP :
11473 element == EL_BALLOON_SWITCH_DOWN ? MV_DOWN :
11476 else if (element == EL_LAMP)
11478 Feld[x][y] = EL_LAMP_ACTIVE;
11479 local_player->lights_still_needed--;
11481 DrawLevelField(x, y);
11483 else if (element == EL_TIME_ORB_FULL)
11485 Feld[x][y] = EL_TIME_ORB_EMPTY;
11487 DrawGameValue_Time(TimeLeft);
11489 DrawLevelField(x, y);
11492 PlaySoundStereo(SND_TIME_ORB_FULL_COLLECTING, SOUND_MIDDLE);
11496 CheckTriggeredElementChangeByPlayer(x, y, element,
11497 CE_OTHER_IS_SWITCHING,
11498 player->index_bit, dig_side);
11500 CheckTriggeredElementChangeByPlayer(x,y, element,CE_OTHER_GETS_PRESSED,
11501 player->index_bit, dig_side);
11507 if (!PLAYER_SWITCHING(player, x, y))
11509 player->is_switching = TRUE;
11510 player->switch_x = x;
11511 player->switch_y = y;
11514 /* !!! TEST ONLY !!! */
11515 CheckElementChangeByPlayer(x, y, element, CE_SWITCHED,
11516 player->index_bit, dig_side);
11517 CheckTriggeredElementChangeByPlayer(x, y, element,
11518 CE_OTHER_IS_SWITCHING,
11519 player->index_bit, dig_side);
11521 CheckTriggeredElementChangeByPlayer(x, y, element,
11522 CE_OTHER_IS_SWITCHING,
11523 player->index_bit, dig_side);
11524 CheckElementChangeByPlayer(x, y, element, CE_SWITCHED,
11525 player->index_bit, dig_side);
11530 /* !!! TEST ONLY !!! (this breaks "machine", level 000) */
11531 CheckElementChangeByPlayer(x, y, element, CE_PRESSED_BY_PLAYER,
11532 player->index_bit, dig_side);
11533 CheckTriggeredElementChangeByPlayer(x,y, element,CE_OTHER_GETS_PRESSED,
11534 player->index_bit, dig_side);
11536 CheckTriggeredElementChangeByPlayer(x,y, element,CE_OTHER_GETS_PRESSED,
11537 player->index_bit, dig_side);
11538 CheckElementChangeByPlayer(x, y, element, CE_PRESSED_BY_PLAYER,
11539 player->index_bit, dig_side);
11543 return MF_NO_ACTION;
11546 player->push_delay = 0;
11548 if (Feld[x][y] != element) /* really digged/collected something */
11549 player->is_collecting = !player->is_digging;
11554 boolean SnapField(struct PlayerInfo *player, int dx, int dy)
11556 int jx = player->jx, jy = player->jy;
11557 int x = jx + dx, y = jy + dy;
11558 int snap_direction = (dx == -1 ? MV_LEFT :
11559 dx == +1 ? MV_RIGHT :
11561 dy == +1 ? MV_DOWN : MV_NO_MOVING);
11564 if (player->MovPos != 0)
11567 if (player->MovPos != 0 && game.engine_version >= VERSION_IDENT(2,2,0,0))
11571 if (!player->active || !IN_LEV_FIELD(x, y))
11579 if (player->MovPos == 0)
11580 player->is_pushing = FALSE;
11582 player->is_snapping = FALSE;
11584 if (player->MovPos == 0)
11586 player->is_moving = FALSE;
11587 player->is_digging = FALSE;
11588 player->is_collecting = FALSE;
11594 if (player->is_snapping)
11597 player->MovDir = snap_direction;
11600 if (player->MovPos == 0)
11603 player->is_moving = FALSE;
11604 player->is_digging = FALSE;
11605 player->is_collecting = FALSE;
11608 player->is_dropping = FALSE;
11610 if (DigField(player, jx, jy, x, y, 0, 0, DF_SNAP) == MF_NO_ACTION)
11613 player->is_snapping = TRUE;
11616 if (player->MovPos == 0)
11619 player->is_moving = FALSE;
11620 player->is_digging = FALSE;
11621 player->is_collecting = FALSE;
11625 if (player->MovPos != 0) /* prevent graphic bugs in versions < 2.2.0 */
11626 DrawLevelField(player->last_jx, player->last_jy);
11629 DrawLevelField(x, y);
11638 boolean DropElement(struct PlayerInfo *player)
11640 int old_element, new_element;
11641 int dropx = player->jx, dropy = player->jy;
11642 int drop_direction = player->MovDir;
11644 int drop_side = drop_direction;
11646 static int trigger_sides[4] =
11648 CH_SIDE_LEFT, /* dropping left */
11649 CH_SIDE_RIGHT, /* dropping right */
11650 CH_SIDE_TOP, /* dropping up */
11651 CH_SIDE_BOTTOM, /* dropping down */
11653 int drop_side = trigger_sides[MV_DIR_BIT(drop_direction)];
11655 int drop_element = (player->inventory_size > 0 ?
11656 player->inventory_element[player->inventory_size - 1] :
11657 player->inventory_infinite_element != EL_UNDEFINED ?
11658 player->inventory_infinite_element :
11659 player->dynabombs_left > 0 ?
11660 EL_DYNABOMB_PLAYER_1_ACTIVE + player->index_nr :
11663 if (IS_THROWABLE(drop_element))
11665 dropx += GET_DX_FROM_DIR(drop_direction);
11666 dropy += GET_DY_FROM_DIR(drop_direction);
11668 if (!IN_LEV_FIELD(dropx, dropy))
11672 old_element = Feld[dropx][dropy]; /* old element at dropping position */
11673 new_element = drop_element; /* default: no change when dropping */
11675 /* check if player is active, not moving and ready to drop */
11676 if (!player->active || player->MovPos || player->drop_delay > 0)
11679 /* check if player has anything that can be dropped */
11681 if (new_element == EL_UNDEFINED)
11684 if (player->inventory_size == 0 &&
11685 player->inventory_infinite_element == EL_UNDEFINED &&
11686 player->dynabombs_left == 0)
11690 /* check if anything can be dropped at the current position */
11691 if (IS_ACTIVE_BOMB(old_element) || old_element == EL_EXPLOSION)
11694 /* collected custom elements can only be dropped on empty fields */
11696 if (IS_CUSTOM_ELEMENT(new_element) && old_element != EL_EMPTY)
11699 if (player->inventory_size > 0 &&
11700 IS_CUSTOM_ELEMENT(player->inventory_element[player->inventory_size - 1])
11701 && old_element != EL_EMPTY)
11705 if (old_element != EL_EMPTY)
11706 Back[dropx][dropy] = old_element; /* store old element on this field */
11708 ResetGfxAnimation(dropx, dropy);
11709 ResetRandomAnimationValue(dropx, dropy);
11711 if (player->inventory_size > 0 ||
11712 player->inventory_infinite_element != EL_UNDEFINED)
11714 if (player->inventory_size > 0)
11716 player->inventory_size--;
11719 new_element = player->inventory_element[player->inventory_size];
11722 DrawGameValue_Dynamite(local_player->inventory_size);
11724 if (new_element == EL_DYNAMITE)
11725 new_element = EL_DYNAMITE_ACTIVE;
11726 else if (new_element == EL_SP_DISK_RED)
11727 new_element = EL_SP_DISK_RED_ACTIVE;
11730 Feld[dropx][dropy] = new_element;
11732 if (IN_SCR_FIELD(SCREENX(dropx), SCREENY(dropy)))
11733 DrawGraphicThruMask(SCREENX(dropx), SCREENY(dropy),
11734 el2img(Feld[dropx][dropy]), 0);
11736 PlayLevelSoundAction(dropx, dropy, ACTION_DROPPING);
11739 /* needed if previous element just changed to "empty" in the last frame */
11740 Changed[dropx][dropy] = 0; /* allow another change */
11744 /* !!! TEST ONLY !!! */
11745 CheckElementChangeByPlayer(dropx, dropy, new_element, CE_DROPPED_BY_PLAYER,
11746 player->index_bit, drop_side);
11747 CheckTriggeredElementChangeByPlayer(dropx, dropy, new_element,
11748 CE_OTHER_GETS_DROPPED,
11749 player->index_bit, drop_side);
11751 CheckTriggeredElementChangeByPlayer(dropx, dropy, new_element,
11752 CE_OTHER_GETS_DROPPED,
11753 player->index_bit, drop_side);
11754 CheckElementChangeByPlayer(dropx, dropy, new_element, CE_DROPPED_BY_PLAYER,
11755 player->index_bit, drop_side);
11758 TestIfElementTouchesCustomElement(dropx, dropy);
11760 else /* player is dropping a dyna bomb */
11762 player->dynabombs_left--;
11765 new_element = EL_DYNABOMB_PLAYER_1_ACTIVE + player->index_nr;
11768 Feld[dropx][dropy] = new_element;
11770 if (IN_SCR_FIELD(SCREENX(dropx), SCREENY(dropy)))
11771 DrawGraphicThruMask(SCREENX(dropx), SCREENY(dropy),
11772 el2img(Feld[dropx][dropy]), 0);
11774 PlayLevelSoundAction(dropx, dropy, ACTION_DROPPING);
11781 if (Feld[dropx][dropy] == new_element) /* uninitialized unless CE change */
11784 InitField_WithBug1(dropx, dropy, FALSE);
11786 InitField(dropx, dropy, FALSE);
11787 if (CAN_MOVE(Feld[dropx][dropy]))
11788 InitMovDir(dropx, dropy);
11792 new_element = Feld[dropx][dropy]; /* element might have changed */
11794 if (IS_CUSTOM_ELEMENT(new_element) && CAN_MOVE(new_element) &&
11795 element_info[new_element].move_pattern == MV_WHEN_DROPPED)
11798 int move_stepsize = element_info[new_element].move_stepsize;
11800 int move_direction, nextx, nexty;
11802 if (element_info[new_element].move_direction_initial == MV_START_AUTOMATIC)
11803 MovDir[dropx][dropy] = drop_direction;
11805 move_direction = MovDir[dropx][dropy];
11806 nextx = dropx + GET_DX_FROM_DIR(move_direction);
11807 nexty = dropy + GET_DY_FROM_DIR(move_direction);
11810 Changed[dropx][dropy] = 0; /* allow another change */
11811 CheckCollision[dropx][dropy] = 2;
11814 if (IN_LEV_FIELD_AND_IS_FREE(nextx, nexty))
11817 WasJustMoving[dropx][dropy] = 3;
11820 InitMovingField(dropx, dropy, move_direction);
11821 ContinueMoving(dropx, dropy);
11826 /* !!! commented out from 3.1.0-4 to 3.1.0-5 !!! */
11829 Changed[dropx][dropy] = 0; /* allow another change */
11832 TestIfElementHitsCustomElement(dropx, dropy, move_direction);
11834 CheckElementChangeBySide(dropx, dropy, new_element, touched_element,
11835 CE_HITTING_SOMETHING, move_direction);
11843 player->drop_delay = 2 * TILEX / move_stepsize + 1;
11848 player->drop_delay = 8 + 8 + 8;
11852 player->drop_delay = GET_NEW_DROP_DELAY(drop_element);
11857 player->is_dropping = TRUE;
11863 /* ------------------------------------------------------------------------- */
11864 /* game sound playing functions */
11865 /* ------------------------------------------------------------------------- */
11867 static int *loop_sound_frame = NULL;
11868 static int *loop_sound_volume = NULL;
11870 void InitPlayLevelSound()
11872 int num_sounds = getSoundListSize();
11874 checked_free(loop_sound_frame);
11875 checked_free(loop_sound_volume);
11877 loop_sound_frame = checked_calloc(num_sounds * sizeof(int));
11878 loop_sound_volume = checked_calloc(num_sounds * sizeof(int));
11881 static void PlayLevelSound(int x, int y, int nr)
11883 int sx = SCREENX(x), sy = SCREENY(y);
11884 int volume, stereo_position;
11885 int max_distance = 8;
11886 int type = (IS_LOOP_SOUND(nr) ? SND_CTRL_PLAY_LOOP : SND_CTRL_PLAY_SOUND);
11888 if ((!setup.sound_simple && !IS_LOOP_SOUND(nr)) ||
11889 (!setup.sound_loops && IS_LOOP_SOUND(nr)))
11892 if (!IN_LEV_FIELD(x, y) ||
11893 sx < -max_distance || sx >= SCR_FIELDX + max_distance ||
11894 sy < -max_distance || sy >= SCR_FIELDY + max_distance)
11897 volume = SOUND_MAX_VOLUME;
11899 if (!IN_SCR_FIELD(sx, sy))
11901 int dx = ABS(sx - SCR_FIELDX / 2) - SCR_FIELDX / 2;
11902 int dy = ABS(sy - SCR_FIELDY / 2) - SCR_FIELDY / 2;
11904 volume -= volume * (dx > dy ? dx : dy) / max_distance;
11907 stereo_position = (SOUND_MAX_LEFT +
11908 (sx + max_distance) * SOUND_MAX_LEFT2RIGHT /
11909 (SCR_FIELDX + 2 * max_distance));
11911 if (IS_LOOP_SOUND(nr))
11913 /* This assures that quieter loop sounds do not overwrite louder ones,
11914 while restarting sound volume comparison with each new game frame. */
11916 if (loop_sound_volume[nr] > volume && loop_sound_frame[nr] == FrameCounter)
11919 loop_sound_volume[nr] = volume;
11920 loop_sound_frame[nr] = FrameCounter;
11923 PlaySoundExt(nr, volume, stereo_position, type);
11926 static void PlayLevelSoundNearest(int x, int y, int sound_action)
11928 PlayLevelSound(x < LEVELX(BX1) ? LEVELX(BX1) :
11929 x > LEVELX(BX2) ? LEVELX(BX2) : x,
11930 y < LEVELY(BY1) ? LEVELY(BY1) :
11931 y > LEVELY(BY2) ? LEVELY(BY2) : y,
11935 static void PlayLevelSoundAction(int x, int y, int action)
11937 PlayLevelSoundElementAction(x, y, Feld[x][y], action);
11940 static void PlayLevelSoundElementAction(int x, int y, int element, int action)
11942 int sound_effect = element_info[SND_ELEMENT(element)].sound[action];
11944 if (sound_effect != SND_UNDEFINED)
11945 PlayLevelSound(x, y, sound_effect);
11948 static void PlayLevelSoundElementActionIfLoop(int x, int y, int element,
11951 int sound_effect = element_info[SND_ELEMENT(element)].sound[action];
11953 if (sound_effect != SND_UNDEFINED && IS_LOOP_SOUND(sound_effect))
11954 PlayLevelSound(x, y, sound_effect);
11957 static void PlayLevelSoundActionIfLoop(int x, int y, int action)
11959 int sound_effect = element_info[SND_ELEMENT(Feld[x][y])].sound[action];
11961 if (sound_effect != SND_UNDEFINED && IS_LOOP_SOUND(sound_effect))
11962 PlayLevelSound(x, y, sound_effect);
11965 static void StopLevelSoundActionIfLoop(int x, int y, int action)
11967 int sound_effect = element_info[SND_ELEMENT(Feld[x][y])].sound[action];
11969 if (sound_effect != SND_UNDEFINED && IS_LOOP_SOUND(sound_effect))
11970 StopSound(sound_effect);
11973 static void PlayLevelMusic()
11975 if (levelset.music[level_nr] != MUS_UNDEFINED)
11976 PlayMusic(levelset.music[level_nr]); /* from config file */
11978 PlayMusic(MAP_NOCONF_MUSIC(level_nr)); /* from music dir */
11981 void RaiseScore(int value)
11983 local_player->score += value;
11985 DrawGameValue_Score(local_player->score);
11988 void RaiseScoreElement(int element)
11993 case EL_BD_DIAMOND:
11994 case EL_EMERALD_YELLOW:
11995 case EL_EMERALD_RED:
11996 case EL_EMERALD_PURPLE:
11997 case EL_SP_INFOTRON:
11998 RaiseScore(level.score[SC_EMERALD]);
12001 RaiseScore(level.score[SC_DIAMOND]);
12004 RaiseScore(level.score[SC_CRYSTAL]);
12007 RaiseScore(level.score[SC_PEARL]);
12010 case EL_BD_BUTTERFLY:
12011 case EL_SP_ELECTRON:
12012 RaiseScore(level.score[SC_BUG]);
12015 case EL_BD_FIREFLY:
12016 case EL_SP_SNIKSNAK:
12017 RaiseScore(level.score[SC_SPACESHIP]);
12020 case EL_DARK_YAMYAM:
12021 RaiseScore(level.score[SC_YAMYAM]);
12024 RaiseScore(level.score[SC_ROBOT]);
12027 RaiseScore(level.score[SC_PACMAN]);
12030 RaiseScore(level.score[SC_NUT]);
12033 case EL_SP_DISK_RED:
12034 case EL_DYNABOMB_INCREASE_NUMBER:
12035 case EL_DYNABOMB_INCREASE_SIZE:
12036 case EL_DYNABOMB_INCREASE_POWER:
12037 RaiseScore(level.score[SC_DYNAMITE]);
12039 case EL_SHIELD_NORMAL:
12040 case EL_SHIELD_DEADLY:
12041 RaiseScore(level.score[SC_SHIELD]);
12043 case EL_EXTRA_TIME:
12044 RaiseScore(level.score[SC_TIME_BONUS]);
12050 RaiseScore(level.score[SC_KEY]);
12053 RaiseScore(element_info[element].collect_score);
12058 void RequestQuitGame(boolean ask_if_really_quit)
12060 if (AllPlayersGone ||
12061 !ask_if_really_quit ||
12062 level_editor_test_game ||
12063 Request("Do you really want to quit the game ?",
12064 REQ_ASK | REQ_STAY_CLOSED))
12066 #if defined(NETWORK_AVALIABLE)
12067 if (options.network)
12068 SendToServer_StopPlaying();
12072 game_status = GAME_MODE_MAIN;
12080 if (tape.playing && tape.deactivate_display)
12081 TapeDeactivateDisplayOff(TRUE);
12084 OpenDoor(DOOR_OPEN_1 | DOOR_COPY_BACK);
12087 if (tape.playing && tape.deactivate_display)
12088 TapeDeactivateDisplayOn();
12095 /* ---------- new game button stuff ---------------------------------------- */
12097 /* graphic position values for game buttons */
12098 #define GAME_BUTTON_XSIZE 30
12099 #define GAME_BUTTON_YSIZE 30
12100 #define GAME_BUTTON_XPOS 5
12101 #define GAME_BUTTON_YPOS 215
12102 #define SOUND_BUTTON_XPOS 5
12103 #define SOUND_BUTTON_YPOS (GAME_BUTTON_YPOS + GAME_BUTTON_YSIZE)
12105 #define GAME_BUTTON_STOP_XPOS (GAME_BUTTON_XPOS + 0 * GAME_BUTTON_XSIZE)
12106 #define GAME_BUTTON_PAUSE_XPOS (GAME_BUTTON_XPOS + 1 * GAME_BUTTON_XSIZE)
12107 #define GAME_BUTTON_PLAY_XPOS (GAME_BUTTON_XPOS + 2 * GAME_BUTTON_XSIZE)
12108 #define SOUND_BUTTON_MUSIC_XPOS (SOUND_BUTTON_XPOS + 0 * GAME_BUTTON_XSIZE)
12109 #define SOUND_BUTTON_LOOPS_XPOS (SOUND_BUTTON_XPOS + 1 * GAME_BUTTON_XSIZE)
12110 #define SOUND_BUTTON_SIMPLE_XPOS (SOUND_BUTTON_XPOS + 2 * GAME_BUTTON_XSIZE)
12117 } gamebutton_info[NUM_GAME_BUTTONS] =
12120 GAME_BUTTON_STOP_XPOS, GAME_BUTTON_YPOS,
12125 GAME_BUTTON_PAUSE_XPOS, GAME_BUTTON_YPOS,
12126 GAME_CTRL_ID_PAUSE,
12130 GAME_BUTTON_PLAY_XPOS, GAME_BUTTON_YPOS,
12135 SOUND_BUTTON_MUSIC_XPOS, SOUND_BUTTON_YPOS,
12136 SOUND_CTRL_ID_MUSIC,
12137 "background music on/off"
12140 SOUND_BUTTON_LOOPS_XPOS, SOUND_BUTTON_YPOS,
12141 SOUND_CTRL_ID_LOOPS,
12142 "sound loops on/off"
12145 SOUND_BUTTON_SIMPLE_XPOS, SOUND_BUTTON_YPOS,
12146 SOUND_CTRL_ID_SIMPLE,
12147 "normal sounds on/off"
12151 void CreateGameButtons()
12155 for (i = 0; i < NUM_GAME_BUTTONS; i++)
12157 Bitmap *gd_bitmap = graphic_info[IMG_GLOBAL_DOOR].bitmap;
12158 struct GadgetInfo *gi;
12161 unsigned long event_mask;
12162 int gd_xoffset, gd_yoffset;
12163 int gd_x1, gd_x2, gd_y1, gd_y2;
12166 gd_xoffset = gamebutton_info[i].x;
12167 gd_yoffset = gamebutton_info[i].y;
12168 gd_x1 = DOOR_GFX_PAGEX4 + gd_xoffset;
12169 gd_x2 = DOOR_GFX_PAGEX3 + gd_xoffset;
12171 if (id == GAME_CTRL_ID_STOP ||
12172 id == GAME_CTRL_ID_PAUSE ||
12173 id == GAME_CTRL_ID_PLAY)
12175 button_type = GD_TYPE_NORMAL_BUTTON;
12177 event_mask = GD_EVENT_RELEASED;
12178 gd_y1 = DOOR_GFX_PAGEY1 + gd_yoffset - GAME_BUTTON_YSIZE;
12179 gd_y2 = DOOR_GFX_PAGEY1 + gd_yoffset - GAME_BUTTON_YSIZE;
12183 button_type = GD_TYPE_CHECK_BUTTON;
12185 ((id == SOUND_CTRL_ID_MUSIC && setup.sound_music) ||
12186 (id == SOUND_CTRL_ID_LOOPS && setup.sound_loops) ||
12187 (id == SOUND_CTRL_ID_SIMPLE && setup.sound_simple) ? TRUE : FALSE);
12188 event_mask = GD_EVENT_PRESSED;
12189 gd_y1 = DOOR_GFX_PAGEY1 + gd_yoffset;
12190 gd_y2 = DOOR_GFX_PAGEY1 + gd_yoffset - GAME_BUTTON_YSIZE;
12193 gi = CreateGadget(GDI_CUSTOM_ID, id,
12194 GDI_INFO_TEXT, gamebutton_info[i].infotext,
12195 GDI_X, DX + gd_xoffset,
12196 GDI_Y, DY + gd_yoffset,
12197 GDI_WIDTH, GAME_BUTTON_XSIZE,
12198 GDI_HEIGHT, GAME_BUTTON_YSIZE,
12199 GDI_TYPE, button_type,
12200 GDI_STATE, GD_BUTTON_UNPRESSED,
12201 GDI_CHECKED, checked,
12202 GDI_DESIGN_UNPRESSED, gd_bitmap, gd_x1, gd_y1,
12203 GDI_DESIGN_PRESSED, gd_bitmap, gd_x2, gd_y1,
12204 GDI_ALT_DESIGN_UNPRESSED, gd_bitmap, gd_x1, gd_y2,
12205 GDI_ALT_DESIGN_PRESSED, gd_bitmap, gd_x2, gd_y2,
12206 GDI_EVENT_MASK, event_mask,
12207 GDI_CALLBACK_ACTION, HandleGameButtons,
12211 Error(ERR_EXIT, "cannot create gadget");
12213 game_gadget[id] = gi;
12217 void FreeGameButtons()
12221 for (i = 0; i < NUM_GAME_BUTTONS; i++)
12222 FreeGadget(game_gadget[i]);
12225 static void MapGameButtons()
12229 for (i = 0; i < NUM_GAME_BUTTONS; i++)
12230 MapGadget(game_gadget[i]);
12233 void UnmapGameButtons()
12237 for (i = 0; i < NUM_GAME_BUTTONS; i++)
12238 UnmapGadget(game_gadget[i]);
12241 static void HandleGameButtons(struct GadgetInfo *gi)
12243 int id = gi->custom_id;
12245 if (game_status != GAME_MODE_PLAYING)
12250 case GAME_CTRL_ID_STOP:
12251 RequestQuitGame(TRUE);
12254 case GAME_CTRL_ID_PAUSE:
12255 if (options.network)
12257 #if defined(NETWORK_AVALIABLE)
12259 SendToServer_ContinuePlaying();
12261 SendToServer_PausePlaying();
12265 TapeTogglePause(TAPE_TOGGLE_MANUAL);
12268 case GAME_CTRL_ID_PLAY:
12271 #if defined(NETWORK_AVALIABLE)
12272 if (options.network)
12273 SendToServer_ContinuePlaying();
12277 tape.pausing = FALSE;
12278 DrawVideoDisplay(VIDEO_STATE_PAUSE_OFF,0);
12283 case SOUND_CTRL_ID_MUSIC:
12284 if (setup.sound_music)
12286 setup.sound_music = FALSE;
12289 else if (audio.music_available)
12291 setup.sound = setup.sound_music = TRUE;
12293 SetAudioMode(setup.sound);
12299 case SOUND_CTRL_ID_LOOPS:
12300 if (setup.sound_loops)
12301 setup.sound_loops = FALSE;
12302 else if (audio.loops_available)
12304 setup.sound = setup.sound_loops = TRUE;
12305 SetAudioMode(setup.sound);
12309 case SOUND_CTRL_ID_SIMPLE:
12310 if (setup.sound_simple)
12311 setup.sound_simple = FALSE;
12312 else if (audio.sound_available)
12314 setup.sound = setup.sound_simple = TRUE;
12315 SetAudioMode(setup.sound);