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 /* EXPERIMENTAL STUFF */
25 #define USE_NEW_AMOEBA_CODE FALSE
27 /* EXPERIMENTAL STUFF */
28 #define USE_NEW_STUFF ( 1)
30 #define USE_NEW_SP_SLIPPERY (USE_NEW_STUFF * 1)
31 #define USE_NEW_CUSTOM_VALUE (USE_NEW_STUFF * 1)
32 #define USE_NEW_PLAYER_ANIM (USE_NEW_STUFF * 1)
33 #define USE_NEW_ALL_SLIPPERY (USE_NEW_STUFF * 1)
34 #define USE_NEW_PLAYER_SPEED (USE_NEW_STUFF * 1)
35 #define USE_NEW_DELAYED_ACTION (USE_NEW_STUFF * 1)
36 #define USE_NEW_SNAP_DELAY (USE_NEW_STUFF * 1)
37 #define USE_ONLY_ONE_CHANGE_PER_FRAME (USE_NEW_STUFF * 1)
38 #define USE_ONE_MORE_CHANGE_PER_FRAME (USE_NEW_STUFF * 1)
39 #define USE_FIXED_DONT_RUN_INTO (USE_NEW_STUFF * 1)
40 #define USE_NEW_SPRING_BUMPER (USE_NEW_STUFF * 1)
41 #define USE_STOP_CHANGED_ELEMENTS (USE_NEW_STUFF * 1)
42 #define USE_ELEMENT_TOUCHING_BUGFIX (USE_NEW_STUFF * 1)
43 #define USE_NEW_CONTINUOUS_SNAPPING (USE_NEW_STUFF * 1)
45 #define USE_QUICKSAND_IMPACT_BUGFIX (USE_NEW_STUFF * 0)
52 /* for MovePlayer() */
53 #define MP_NO_ACTION 0
56 #define MP_DONT_RUN_INTO (MP_MOVING | MP_ACTION)
58 /* for ScrollPlayer() */
60 #define SCROLL_GO_ON 1
62 /* for Bang()/Explode() */
63 #define EX_PHASE_START 0
64 #define EX_TYPE_NONE 0
65 #define EX_TYPE_NORMAL (1 << 0)
66 #define EX_TYPE_CENTER (1 << 1)
67 #define EX_TYPE_BORDER (1 << 2)
68 #define EX_TYPE_CROSS (1 << 3)
69 #define EX_TYPE_DYNA (1 << 4)
70 #define EX_TYPE_SINGLE_TILE (EX_TYPE_CENTER | EX_TYPE_BORDER)
72 /* special positions in the game control window (relative to control window) */
75 #define XX_EMERALDS 29
76 #define YY_EMERALDS 54
77 #define XX_DYNAMITE 29
78 #define YY_DYNAMITE 89
87 /* special positions in the game control window (relative to main window) */
88 #define DX_LEVEL (DX + XX_LEVEL)
89 #define DY_LEVEL (DY + YY_LEVEL)
90 #define DX_EMERALDS (DX + XX_EMERALDS)
91 #define DY_EMERALDS (DY + YY_EMERALDS)
92 #define DX_DYNAMITE (DX + XX_DYNAMITE)
93 #define DY_DYNAMITE (DY + YY_DYNAMITE)
94 #define DX_KEYS (DX + XX_KEYS)
95 #define DY_KEYS (DY + YY_KEYS)
96 #define DX_SCORE (DX + XX_SCORE)
97 #define DY_SCORE (DY + YY_SCORE)
98 #define DX_TIME1 (DX + XX_TIME1)
99 #define DX_TIME2 (DX + XX_TIME2)
100 #define DY_TIME (DY + YY_TIME)
102 /* values for delayed check of falling and moving elements and for collision */
103 #define CHECK_DELAY_MOVING 3
104 #define CHECK_DELAY_FALLING 3
105 #define CHECK_DELAY_COLLISION 2
107 /* values for initial player move delay (initial delay counter value) */
108 #define INITIAL_MOVE_DELAY_OFF -1
109 #define INITIAL_MOVE_DELAY_ON 0
111 /* values for player movement speed (which is in fact a delay value) */
112 #define MOVE_DELAY_MIN_SPEED 32
113 #define MOVE_DELAY_NORMAL_SPEED 8
114 #define MOVE_DELAY_HIGH_SPEED 4
115 #define MOVE_DELAY_MAX_SPEED 1
118 #define DOUBLE_MOVE_DELAY(x) (x = (x <= MOVE_DELAY_HIGH_SPEED ? x * 2 : x))
119 #define HALVE_MOVE_DELAY(x) (x = (x >= MOVE_DELAY_HIGH_SPEED ? x / 2 : x))
121 #define DOUBLE_MOVE_DELAY(x) (x = (x < MOVE_DELAY_MIN_SPEED ? x * 2 : x))
122 #define HALVE_MOVE_DELAY(x) (x = (x > MOVE_DELAY_MAX_SPEED ? x / 2 : x))
124 #define DOUBLE_PLAYER_SPEED(p) (HALVE_MOVE_DELAY((p)->move_delay_value))
125 #define HALVE_PLAYER_SPEED(p) (DOUBLE_MOVE_DELAY((p)->move_delay_value))
127 /* values for other actions */
128 #define MOVE_STEPSIZE_NORMAL (TILEX / MOVE_DELAY_NORMAL_SPEED)
129 #define MOVE_STEPSIZE_MIN (1)
130 #define MOVE_STEPSIZE_MAX (TILEX)
132 #define GET_DX_FROM_DIR(d) ((d) == MV_LEFT ? -1 : (d) == MV_RIGHT ? 1 : 0)
133 #define GET_DY_FROM_DIR(d) ((d) == MV_UP ? -1 : (d) == MV_DOWN ? 1 : 0)
135 #define INIT_GFX_RANDOM() (SimpleRND(1000000))
137 #define GET_NEW_PUSH_DELAY(e) ( (element_info[e].push_delay_fixed) + \
138 RND(element_info[e].push_delay_random))
139 #define GET_NEW_DROP_DELAY(e) ( (element_info[e].drop_delay_fixed) + \
140 RND(element_info[e].drop_delay_random))
141 #define GET_NEW_MOVE_DELAY(e) ( (element_info[e].move_delay_fixed) + \
142 RND(element_info[e].move_delay_random))
143 #define GET_MAX_MOVE_DELAY(e) ( (element_info[e].move_delay_fixed) + \
144 (element_info[e].move_delay_random))
145 #define GET_NEW_CE_VALUE(e) ( (element_info[e].ce_value_fixed_initial) +\
146 RND(element_info[e].ce_value_random_initial))
147 #define GET_CE_SCORE(e) ( (element_info[e].collect_score))
148 #define GET_CHANGE_DELAY(c) ( ((c)->delay_fixed * (c)->delay_frames) + \
149 RND((c)->delay_random * (c)->delay_frames))
150 #define GET_CE_DELAY_VALUE(c) ( ((c)->delay_fixed) + \
151 RND((c)->delay_random))
155 #define GET_VALID_RUNTIME_ELEMENT(e) \
156 ((e) >= NUM_RUNTIME_ELEMENTS ? EL_UNKNOWN : (e))
158 #define GET_VALID_FILE_ELEMENT(e) \
159 ((e) >= NUM_FILE_ELEMENTS ? EL_UNKNOWN : (e))
162 #define GET_TARGET_ELEMENT(e, ch, cv, cs) \
163 ((e) == EL_TRIGGER_PLAYER ? (ch)->actual_trigger_player : \
164 (e) == EL_TRIGGER_ELEMENT ? (ch)->actual_trigger_element : \
165 (e) == EL_TRIGGER_CE_VALUE ? (ch)->actual_trigger_ce_value : \
166 (e) == EL_TRIGGER_CE_SCORE ? (ch)->actual_trigger_ce_score : \
167 (e) == EL_CURRENT_CE_VALUE ? (cv) : \
168 (e) == EL_CURRENT_CE_SCORE ? (cs) : (e))
170 #define CAN_GROW_INTO(e) \
171 ((e) == EL_SAND || (IS_DIGGABLE(e) && level.grow_into_diggable))
173 #define ELEMENT_CAN_ENTER_FIELD_BASE_X(x, y, condition) \
174 (IN_LEV_FIELD(x, y) && (IS_FREE(x, y) || \
177 #define ELEMENT_CAN_ENTER_FIELD_BASE_2(e, x, y, condition) \
178 (IN_LEV_FIELD(x, y) && (IS_FREE(x, y) || \
179 (CAN_MOVE_INTO_ACID(e) && \
180 Feld[x][y] == EL_ACID) || \
183 #define ELEMENT_CAN_ENTER_FIELD_BASE_3(e, x, y, condition) \
184 (IN_LEV_FIELD(x, y) && (IS_FREE_OR_PLAYER(x, y) || \
185 (CAN_MOVE_INTO_ACID(e) && \
186 Feld[x][y] == EL_ACID) || \
189 #define ELEMENT_CAN_ENTER_FIELD_BASE_4(e, x, y, condition) \
190 (IN_LEV_FIELD(x, y) && (IS_FREE(x, y) || \
192 (CAN_MOVE_INTO_ACID(e) && \
193 Feld[x][y] == EL_ACID) || \
194 (DONT_COLLIDE_WITH(e) && \
196 !PLAYER_ENEMY_PROTECTED(x, y))))
198 #define ELEMENT_CAN_ENTER_FIELD(e, x, y) \
199 ELEMENT_CAN_ENTER_FIELD_BASE_4(e, x, y, 0)
201 #define SATELLITE_CAN_ENTER_FIELD(x, y) \
202 ELEMENT_CAN_ENTER_FIELD_BASE_2(EL_SATELLITE, x, y, 0)
204 #define ANDROID_CAN_ENTER_FIELD(e, x, y) \
205 ELEMENT_CAN_ENTER_FIELD_BASE_2(e, x, y, Feld[x][y] == EL_EMC_PLANT)
207 #define ANDROID_CAN_CLONE_FIELD(x, y) \
208 (IN_LEV_FIELD(x, y) && (CAN_BE_CLONED_BY_ANDROID(Feld[x][y]) || \
209 CAN_BE_CLONED_BY_ANDROID(EL_TRIGGER_ELEMENT)))
211 #define ENEMY_CAN_ENTER_FIELD(e, x, y) \
212 ELEMENT_CAN_ENTER_FIELD_BASE_2(e, x, y, 0)
214 #define YAMYAM_CAN_ENTER_FIELD(e, x, y) \
215 ELEMENT_CAN_ENTER_FIELD_BASE_3(e, x, y, Feld[x][y] == EL_DIAMOND)
217 #define DARK_YAMYAM_CAN_ENTER_FIELD(e, x, y) \
218 ELEMENT_CAN_ENTER_FIELD_BASE_3(e, x,y, IS_FOOD_DARK_YAMYAM(Feld[x][y]))
220 #define PACMAN_CAN_ENTER_FIELD(e, x, y) \
221 ELEMENT_CAN_ENTER_FIELD_BASE_3(e, x, y, IS_AMOEBOID(Feld[x][y]))
223 #define PIG_CAN_ENTER_FIELD(e, x, y) \
224 ELEMENT_CAN_ENTER_FIELD_BASE_2(e, x, y, IS_FOOD_PIG(Feld[x][y]))
226 #define PENGUIN_CAN_ENTER_FIELD(e, x, y) \
227 ELEMENT_CAN_ENTER_FIELD_BASE_2(e, x, y, (Feld[x][y] == EL_EXIT_OPEN ||\
228 IS_FOOD_PENGUIN(Feld[x][y])))
229 #define DRAGON_CAN_ENTER_FIELD(e, x, y) \
230 ELEMENT_CAN_ENTER_FIELD_BASE_2(e, x, y, 0)
232 #define MOLE_CAN_ENTER_FIELD(e, x, y, condition) \
233 ELEMENT_CAN_ENTER_FIELD_BASE_2(e, x, y, (condition))
235 #define SPRING_CAN_ENTER_FIELD(e, x, y) \
236 ELEMENT_CAN_ENTER_FIELD_BASE_2(e, x, y, 0)
238 #define SPRING_CAN_BUMP_FROM_FIELD(x, y) \
239 (IN_LEV_FIELD(x, y) && (Feld[x][y] == EL_EMC_SPRING_BUMPER || \
240 Feld[x][y] == EL_EMC_SPRING_BUMPER_ACTIVE))
243 #define GROUP_NR(e) ((e) - EL_GROUP_START)
244 #define IS_IN_GROUP(e, nr) (element_info[e].in_group[nr] == TRUE)
245 #define IS_IN_GROUP_EL(e, ge) (IS_IN_GROUP(e, (ge) - EL_GROUP_START))
247 #define IS_EQUAL_OR_IN_GROUP(e, ge) \
248 (IS_GROUP_ELEMENT(ge) ? IS_IN_GROUP(e, GROUP_NR(ge)) : (e) == (ge))
251 #define MOVE_ENTER_EL(e) (element_info[e].move_enter_element)
253 #define CE_ENTER_FIELD_COND(e, x, y) \
254 (!IS_PLAYER(x, y) && \
255 IS_EQUAL_OR_IN_GROUP(Feld[x][y], MOVE_ENTER_EL(e)))
257 #define CUSTOM_ELEMENT_CAN_ENTER_FIELD(e, x, y) \
258 ELEMENT_CAN_ENTER_FIELD_BASE_4(e, x, y, CE_ENTER_FIELD_COND(e, x, y))
260 #define IN_LEV_FIELD_AND_IS_FREE(x, y) (IN_LEV_FIELD(x, y) && IS_FREE(x, y))
261 #define IN_LEV_FIELD_AND_NOT_FREE(x, y) (IN_LEV_FIELD(x, y) && !IS_FREE(x, y))
263 #define ACCESS_FROM(e, d) (element_info[e].access_direction &(d))
264 #define IS_WALKABLE_FROM(e, d) (IS_WALKABLE(e) && ACCESS_FROM(e, d))
265 #define IS_PASSABLE_FROM(e, d) (IS_PASSABLE(e) && ACCESS_FROM(e, d))
266 #define IS_ACCESSIBLE_FROM(e, d) (IS_ACCESSIBLE(e) && ACCESS_FROM(e, d))
268 /* game button identifiers */
269 #define GAME_CTRL_ID_STOP 0
270 #define GAME_CTRL_ID_PAUSE 1
271 #define GAME_CTRL_ID_PLAY 2
272 #define SOUND_CTRL_ID_MUSIC 3
273 #define SOUND_CTRL_ID_LOOPS 4
274 #define SOUND_CTRL_ID_SIMPLE 5
276 #define NUM_GAME_BUTTONS 6
279 /* forward declaration for internal use */
281 static void CreateField(int, int, int);
283 static void SetPlayerWaiting(struct PlayerInfo *, boolean);
284 static void AdvanceFrameAndPlayerCounters(int);
286 static boolean MovePlayerOneStep(struct PlayerInfo *, int, int, int, int);
287 static boolean MovePlayer(struct PlayerInfo *, int, int);
288 static void ScrollPlayer(struct PlayerInfo *, int);
289 static void ScrollScreen(struct PlayerInfo *, int);
291 int DigField(struct PlayerInfo *, int, int, int, int, int, int, int);
293 static void InitBeltMovement(void);
294 static void CloseAllOpenTimegates(void);
295 static void CheckGravityMovement(struct PlayerInfo *);
296 static void CheckGravityMovementWhenNotMoving(struct PlayerInfo *);
297 static void KillPlayerUnlessEnemyProtected(int, int);
298 static void KillPlayerUnlessExplosionProtected(int, int);
300 static void TestIfPlayerTouchesCustomElement(int, int);
301 static void TestIfElementTouchesCustomElement(int, int);
302 static void TestIfElementHitsCustomElement(int, int, int);
304 static void TestIfElementSmashesCustomElement(int, int, int);
307 static void HandleElementChange(int, int, int);
308 static void ExecuteCustomElementAction(int, int, int, int);
309 static boolean ChangeElement(int, int, int, int);
311 static boolean CheckTriggeredElementChangeExt(int, int, int, int, int,int,int);
312 #define CheckTriggeredElementChange(x, y, e, ev) \
313 CheckTriggeredElementChangeExt(x,y,e,ev, CH_PLAYER_ANY,CH_SIDE_ANY, -1)
314 #define CheckTriggeredElementChangeByPlayer(x, y, e, ev, p, s) \
315 CheckTriggeredElementChangeExt(x, y, e, ev, p, s, -1)
316 #define CheckTriggeredElementChangeBySide(x, y, e, ev, s) \
317 CheckTriggeredElementChangeExt(x, y, e, ev, CH_PLAYER_ANY, s, -1)
318 #define CheckTriggeredElementChangeByPage(x, y, e, ev, p) \
319 CheckTriggeredElementChangeExt(x,y,e,ev, CH_PLAYER_ANY, CH_SIDE_ANY, p)
321 static boolean CheckElementChangeExt(int, int, int, int, int, int, int);
322 #define CheckElementChange(x, y, e, te, ev) \
323 CheckElementChangeExt(x, y, e, te, ev, CH_PLAYER_ANY, CH_SIDE_ANY)
324 #define CheckElementChangeByPlayer(x, y, e, ev, p, s) \
325 CheckElementChangeExt(x, y, e, EL_EMPTY, ev, p, s)
326 #define CheckElementChangeBySide(x, y, e, te, ev, s) \
327 CheckElementChangeExt(x, y, e, te, ev, CH_PLAYER_ANY, s)
329 static void PlayLevelSound(int, int, int);
330 static void PlayLevelSoundNearest(int, int, int);
331 static void PlayLevelSoundAction(int, int, int);
332 static void PlayLevelSoundElementAction(int, int, int, int);
333 static void PlayLevelSoundElementActionIfLoop(int, int, int, int);
334 static void PlayLevelSoundActionIfLoop(int, int, int);
335 static void StopLevelSoundActionIfLoop(int, int, int);
336 static void PlayLevelMusic();
338 static void MapGameButtons();
339 static void HandleGameButtons(struct GadgetInfo *);
341 int AmoebeNachbarNr(int, int);
342 void AmoebeUmwandeln(int, int);
343 void ContinueMoving(int, int);
345 void InitMovDir(int, int);
346 void InitAmoebaNr(int, int);
347 int NewHiScore(void);
349 void TestIfGoodThingHitsBadThing(int, int, int);
350 void TestIfBadThingHitsGoodThing(int, int, int);
351 void TestIfPlayerTouchesBadThing(int, int);
352 void TestIfPlayerRunsIntoBadThing(int, int, int);
353 void TestIfBadThingTouchesPlayer(int, int);
354 void TestIfBadThingRunsIntoPlayer(int, int, int);
355 void TestIfFriendTouchesBadThing(int, int);
356 void TestIfBadThingTouchesFriend(int, int);
357 void TestIfBadThingTouchesOtherBadThing(int, int);
359 void KillPlayer(struct PlayerInfo *);
360 void BuryPlayer(struct PlayerInfo *);
361 void RemovePlayer(struct PlayerInfo *);
363 boolean SnapField(struct PlayerInfo *, int, int);
364 boolean DropElement(struct PlayerInfo *);
367 static struct GadgetInfo *game_gadget[NUM_GAME_BUTTONS];
370 /* ------------------------------------------------------------------------- */
371 /* definition of elements that automatically change to other elements after */
372 /* a specified time, eventually calling a function when changing */
373 /* ------------------------------------------------------------------------- */
375 /* forward declaration for changer functions */
376 static void InitBuggyBase(int, int);
377 static void WarnBuggyBase(int, int);
379 static void InitTrap(int, int);
380 static void ActivateTrap(int, int);
381 static void ChangeActiveTrap(int, int);
383 static void InitRobotWheel(int, int);
384 static void RunRobotWheel(int, int);
385 static void StopRobotWheel(int, int);
387 static void InitTimegateWheel(int, int);
388 static void RunTimegateWheel(int, int);
390 static void InitMagicBallDelay(int, int);
391 static void ActivateMagicBall(int, int);
393 static void InitDiagonalMovingElement(int, int);
395 struct ChangingElementInfo
400 void (*pre_change_function)(int x, int y);
401 void (*change_function)(int x, int y);
402 void (*post_change_function)(int x, int y);
405 static struct ChangingElementInfo change_delay_list[] =
456 EL_SWITCHGATE_OPENING,
464 EL_SWITCHGATE_CLOSING,
465 EL_SWITCHGATE_CLOSED,
497 EL_ACID_SPLASH_RIGHT,
506 EL_SP_BUGGY_BASE_ACTIVATING,
513 EL_SP_BUGGY_BASE_ACTIVATING,
514 EL_SP_BUGGY_BASE_ACTIVE,
521 EL_SP_BUGGY_BASE_ACTIVE,
545 EL_ROBOT_WHEEL_ACTIVE,
553 EL_TIMEGATE_SWITCH_ACTIVE,
561 EL_EMC_MAGIC_BALL_ACTIVE,
562 EL_EMC_MAGIC_BALL_ACTIVE,
569 EL_EMC_SPRING_BUMPER_ACTIVE,
570 EL_EMC_SPRING_BUMPER,
577 EL_DIAGONAL_SHRINKING,
590 InitDiagonalMovingElement
606 int push_delay_fixed, push_delay_random;
611 { EL_BALLOON, 0, 0 },
613 { EL_SOKOBAN_OBJECT, 2, 0 },
614 { EL_SOKOBAN_FIELD_FULL, 2, 0 },
615 { EL_SATELLITE, 2, 0 },
616 { EL_SP_DISK_YELLOW, 2, 0 },
618 { EL_UNDEFINED, 0, 0 },
626 move_stepsize_list[] =
628 { EL_AMOEBA_DROP, 2 },
629 { EL_AMOEBA_DROPPING, 2 },
630 { EL_QUICKSAND_FILLING, 1 },
631 { EL_QUICKSAND_EMPTYING, 1 },
632 { EL_MAGIC_WALL_FILLING, 2 },
633 { EL_BD_MAGIC_WALL_FILLING, 2 },
634 { EL_MAGIC_WALL_EMPTYING, 2 },
635 { EL_BD_MAGIC_WALL_EMPTYING, 2 },
645 collect_count_list[] =
648 { EL_BD_DIAMOND, 1 },
649 { EL_EMERALD_YELLOW, 1 },
650 { EL_EMERALD_RED, 1 },
651 { EL_EMERALD_PURPLE, 1 },
653 { EL_SP_INFOTRON, 1 },
665 access_direction_list[] =
667 { EL_TUBE_ANY, MV_LEFT | MV_RIGHT | MV_UP | MV_DOWN },
668 { EL_TUBE_VERTICAL, MV_UP | MV_DOWN },
669 { EL_TUBE_HORIZONTAL, MV_LEFT | MV_RIGHT },
670 { EL_TUBE_VERTICAL_LEFT, MV_LEFT | MV_UP | MV_DOWN },
671 { EL_TUBE_VERTICAL_RIGHT, MV_RIGHT | MV_UP | MV_DOWN },
672 { EL_TUBE_HORIZONTAL_UP, MV_LEFT | MV_RIGHT | MV_UP },
673 { EL_TUBE_HORIZONTAL_DOWN, MV_LEFT | MV_RIGHT | MV_DOWN },
674 { EL_TUBE_LEFT_UP, MV_LEFT | MV_UP },
675 { EL_TUBE_LEFT_DOWN, MV_LEFT | MV_DOWN },
676 { EL_TUBE_RIGHT_UP, MV_RIGHT | MV_UP },
677 { EL_TUBE_RIGHT_DOWN, MV_RIGHT | MV_DOWN },
679 { EL_SP_PORT_LEFT, MV_RIGHT },
680 { EL_SP_PORT_RIGHT, MV_LEFT },
681 { EL_SP_PORT_UP, MV_DOWN },
682 { EL_SP_PORT_DOWN, MV_UP },
683 { EL_SP_PORT_HORIZONTAL, MV_LEFT | MV_RIGHT },
684 { EL_SP_PORT_VERTICAL, MV_UP | MV_DOWN },
685 { EL_SP_PORT_ANY, MV_LEFT | MV_RIGHT | MV_UP | MV_DOWN },
686 { EL_SP_GRAVITY_PORT_LEFT, MV_RIGHT },
687 { EL_SP_GRAVITY_PORT_RIGHT, MV_LEFT },
688 { EL_SP_GRAVITY_PORT_UP, MV_DOWN },
689 { EL_SP_GRAVITY_PORT_DOWN, MV_UP },
690 { EL_SP_GRAVITY_ON_PORT_LEFT, MV_RIGHT },
691 { EL_SP_GRAVITY_ON_PORT_RIGHT, MV_LEFT },
692 { EL_SP_GRAVITY_ON_PORT_UP, MV_DOWN },
693 { EL_SP_GRAVITY_ON_PORT_DOWN, MV_UP },
694 { EL_SP_GRAVITY_OFF_PORT_LEFT, MV_RIGHT },
695 { EL_SP_GRAVITY_OFF_PORT_RIGHT, MV_LEFT },
696 { EL_SP_GRAVITY_OFF_PORT_UP, MV_DOWN },
697 { EL_SP_GRAVITY_OFF_PORT_DOWN, MV_UP },
699 { EL_UNDEFINED, MV_NONE }
702 static boolean trigger_events[MAX_NUM_ELEMENTS][NUM_CHANGE_EVENTS];
704 #define IS_AUTO_CHANGING(e) (element_info[e].has_change_event[CE_DELAY])
705 #define IS_JUST_CHANGING(x, y) (ChangeDelay[x][y] != 0)
706 #define IS_CHANGING(x, y) (IS_AUTO_CHANGING(Feld[x][y]) || \
707 IS_JUST_CHANGING(x, y))
709 #define CE_PAGE(e, ce) (element_info[e].event_page[ce])
711 /* static variables for playfield scan mode (scanning forward or backward) */
712 static int playfield_scan_start_x = 0;
713 static int playfield_scan_start_y = 0;
714 static int playfield_scan_delta_x = 1;
715 static int playfield_scan_delta_y = 1;
717 #define SCAN_PLAYFIELD(x, y) for ((y) = playfield_scan_start_y; \
718 (y) >= 0 && (y) <= lev_fieldy - 1; \
719 (y) += playfield_scan_delta_y) \
720 for ((x) = playfield_scan_start_x; \
721 (x) >= 0 && (x) <= lev_fieldx - 1; \
722 (x) += playfield_scan_delta_x) \
725 void DEBUG_SetMaximumDynamite()
729 for (i = 0; i < MAX_INVENTORY_SIZE; i++)
730 if (local_player->inventory_size < MAX_INVENTORY_SIZE)
731 local_player->inventory_element[local_player->inventory_size++] =
736 static void InitPlayfieldScanModeVars()
738 if (game.use_reverse_scan_direction)
740 playfield_scan_start_x = lev_fieldx - 1;
741 playfield_scan_start_y = lev_fieldy - 1;
743 playfield_scan_delta_x = -1;
744 playfield_scan_delta_y = -1;
748 playfield_scan_start_x = 0;
749 playfield_scan_start_y = 0;
751 playfield_scan_delta_x = 1;
752 playfield_scan_delta_y = 1;
756 static void InitPlayfieldScanMode(int mode)
758 game.use_reverse_scan_direction =
759 (mode == CA_ARG_SCAN_MODE_REVERSE ? TRUE : FALSE);
761 InitPlayfieldScanModeVars();
764 static int get_move_delay_from_stepsize(int move_stepsize)
767 MIN(MAX(MOVE_STEPSIZE_MIN, move_stepsize), MOVE_STEPSIZE_MAX);
769 /* make sure that stepsize value is always a power of 2 */
770 move_stepsize = (1 << log_2(move_stepsize));
772 return TILEX / move_stepsize;
775 static void SetPlayerMoveSpeed(struct PlayerInfo *player, int move_stepsize,
778 int move_delay = get_move_delay_from_stepsize(move_stepsize);
779 boolean cannot_move = (move_stepsize == STEPSIZE_NOT_MOVING ? TRUE : FALSE);
781 /* do no immediately change move delay -- the player might just be moving */
782 player->move_delay_value_next = move_delay;
784 /* information if player can move must be set separately */
785 player->cannot_move = cannot_move;
789 player->move_delay = game.initial_move_delay;
790 player->move_delay_value = game.initial_move_delay_value;
792 player->move_delay_value_next = -1;
794 player->move_delay_reset_counter = 0;
798 void GetPlayerConfig()
800 if (!audio.sound_available)
801 setup.sound_simple = FALSE;
803 if (!audio.loops_available)
804 setup.sound_loops = FALSE;
806 if (!audio.music_available)
807 setup.sound_music = FALSE;
809 if (!video.fullscreen_available)
810 setup.fullscreen = FALSE;
812 setup.sound = (setup.sound_simple || setup.sound_loops || setup.sound_music);
814 SetAudioMode(setup.sound);
818 static int getBeltNrFromBeltElement(int element)
820 return (element < EL_CONVEYOR_BELT_2_LEFT ? 0 :
821 element < EL_CONVEYOR_BELT_3_LEFT ? 1 :
822 element < EL_CONVEYOR_BELT_4_LEFT ? 2 : 3);
825 static int getBeltNrFromBeltActiveElement(int element)
827 return (element < EL_CONVEYOR_BELT_2_LEFT_ACTIVE ? 0 :
828 element < EL_CONVEYOR_BELT_3_LEFT_ACTIVE ? 1 :
829 element < EL_CONVEYOR_BELT_4_LEFT_ACTIVE ? 2 : 3);
832 static int getBeltNrFromBeltSwitchElement(int element)
834 return (element < EL_CONVEYOR_BELT_2_SWITCH_LEFT ? 0 :
835 element < EL_CONVEYOR_BELT_3_SWITCH_LEFT ? 1 :
836 element < EL_CONVEYOR_BELT_4_SWITCH_LEFT ? 2 : 3);
839 static int getBeltDirNrFromBeltSwitchElement(int element)
841 static int belt_base_element[4] =
843 EL_CONVEYOR_BELT_1_SWITCH_LEFT,
844 EL_CONVEYOR_BELT_2_SWITCH_LEFT,
845 EL_CONVEYOR_BELT_3_SWITCH_LEFT,
846 EL_CONVEYOR_BELT_4_SWITCH_LEFT
849 int belt_nr = getBeltNrFromBeltSwitchElement(element);
850 int belt_dir_nr = element - belt_base_element[belt_nr];
852 return (belt_dir_nr % 3);
855 static int getBeltDirFromBeltSwitchElement(int element)
857 static int belt_move_dir[3] =
864 int belt_dir_nr = getBeltDirNrFromBeltSwitchElement(element);
866 return belt_move_dir[belt_dir_nr];
869 static int get_element_from_group_element(int element)
871 if (IS_GROUP_ELEMENT(element))
873 struct ElementGroupInfo *group = element_info[element].group;
874 int last_anim_random_frame = gfx.anim_random_frame;
877 if (group->choice_mode == ANIM_RANDOM)
878 gfx.anim_random_frame = RND(group->num_elements_resolved);
880 element_pos = getAnimationFrame(group->num_elements_resolved, 1,
881 group->choice_mode, 0,
884 if (group->choice_mode == ANIM_RANDOM)
885 gfx.anim_random_frame = last_anim_random_frame;
889 element = group->element_resolved[element_pos];
895 static void InitPlayerField(int x, int y, int element, boolean init_game)
897 if (element == EL_SP_MURPHY)
901 if (stored_player[0].present)
903 Feld[x][y] = EL_SP_MURPHY_CLONE;
909 stored_player[0].use_murphy = TRUE;
911 if (!level.use_artwork_element[0])
912 stored_player[0].artwork_element = EL_SP_MURPHY;
915 Feld[x][y] = EL_PLAYER_1;
921 struct PlayerInfo *player = &stored_player[Feld[x][y] - EL_PLAYER_1];
922 int jx = player->jx, jy = player->jy;
924 player->present = TRUE;
926 player->block_last_field = (element == EL_SP_MURPHY ?
927 level.sp_block_last_field :
928 level.block_last_field);
930 /* ---------- initialize player's last field block delay --------------- */
932 /* always start with reliable default value (no adjustment needed) */
933 player->block_delay_adjustment = 0;
935 /* special case 1: in Supaplex, Murphy blocks last field one more frame */
936 if (player->block_last_field && element == EL_SP_MURPHY)
937 player->block_delay_adjustment = 1;
939 /* special case 2: in game engines before 3.1.1, blocking was different */
940 if (game.use_block_last_field_bug)
941 player->block_delay_adjustment = (player->block_last_field ? -1 : 1);
943 if (!options.network || player->connected)
945 player->active = TRUE;
947 /* remove potentially duplicate players */
948 if (StorePlayer[jx][jy] == Feld[x][y])
949 StorePlayer[jx][jy] = 0;
951 StorePlayer[x][y] = Feld[x][y];
955 printf("Player %d activated.\n", player->element_nr);
956 printf("[Local player is %d and currently %s.]\n",
957 local_player->element_nr,
958 local_player->active ? "active" : "not active");
962 Feld[x][y] = EL_EMPTY;
964 player->jx = player->last_jx = x;
965 player->jy = player->last_jy = y;
969 static void InitField(int x, int y, boolean init_game)
971 int element = Feld[x][y];
980 InitPlayerField(x, y, element, init_game);
983 case EL_SOKOBAN_FIELD_PLAYER:
984 element = Feld[x][y] = EL_PLAYER_1;
985 InitField(x, y, init_game);
987 element = Feld[x][y] = EL_SOKOBAN_FIELD_EMPTY;
988 InitField(x, y, init_game);
991 case EL_SOKOBAN_FIELD_EMPTY:
992 local_player->sokobanfields_still_needed++;
996 if (x < lev_fieldx-1 && Feld[x+1][y] == EL_ACID)
997 Feld[x][y] = EL_ACID_POOL_TOPLEFT;
998 else if (x > 0 && Feld[x-1][y] == EL_ACID)
999 Feld[x][y] = EL_ACID_POOL_TOPRIGHT;
1000 else if (y > 0 && Feld[x][y-1] == EL_ACID_POOL_TOPLEFT)
1001 Feld[x][y] = EL_ACID_POOL_BOTTOMLEFT;
1002 else if (y > 0 && Feld[x][y-1] == EL_ACID)
1003 Feld[x][y] = EL_ACID_POOL_BOTTOM;
1004 else if (y > 0 && Feld[x][y-1] == EL_ACID_POOL_TOPRIGHT)
1005 Feld[x][y] = EL_ACID_POOL_BOTTOMRIGHT;
1014 case EL_SPACESHIP_RIGHT:
1015 case EL_SPACESHIP_UP:
1016 case EL_SPACESHIP_LEFT:
1017 case EL_SPACESHIP_DOWN:
1018 case EL_BD_BUTTERFLY:
1019 case EL_BD_BUTTERFLY_RIGHT:
1020 case EL_BD_BUTTERFLY_UP:
1021 case EL_BD_BUTTERFLY_LEFT:
1022 case EL_BD_BUTTERFLY_DOWN:
1024 case EL_BD_FIREFLY_RIGHT:
1025 case EL_BD_FIREFLY_UP:
1026 case EL_BD_FIREFLY_LEFT:
1027 case EL_BD_FIREFLY_DOWN:
1028 case EL_PACMAN_RIGHT:
1030 case EL_PACMAN_LEFT:
1031 case EL_PACMAN_DOWN:
1033 case EL_YAMYAM_LEFT:
1034 case EL_YAMYAM_RIGHT:
1036 case EL_YAMYAM_DOWN:
1037 case EL_DARK_YAMYAM:
1040 case EL_SP_SNIKSNAK:
1041 case EL_SP_ELECTRON:
1050 case EL_AMOEBA_FULL:
1055 case EL_AMOEBA_DROP:
1056 if (y == lev_fieldy - 1)
1058 Feld[x][y] = EL_AMOEBA_GROWING;
1059 Store[x][y] = EL_AMOEBA_WET;
1063 case EL_DYNAMITE_ACTIVE:
1064 case EL_SP_DISK_RED_ACTIVE:
1065 case EL_DYNABOMB_PLAYER_1_ACTIVE:
1066 case EL_DYNABOMB_PLAYER_2_ACTIVE:
1067 case EL_DYNABOMB_PLAYER_3_ACTIVE:
1068 case EL_DYNABOMB_PLAYER_4_ACTIVE:
1069 MovDelay[x][y] = 96;
1072 case EL_EM_DYNAMITE_ACTIVE:
1073 MovDelay[x][y] = 32;
1077 local_player->lights_still_needed++;
1081 local_player->friends_still_needed++;
1086 GfxDir[x][y] = MovDir[x][y] = 1 << RND(4);
1089 case EL_CONVEYOR_BELT_1_SWITCH_LEFT:
1090 case EL_CONVEYOR_BELT_1_SWITCH_MIDDLE:
1091 case EL_CONVEYOR_BELT_1_SWITCH_RIGHT:
1092 case EL_CONVEYOR_BELT_2_SWITCH_LEFT:
1093 case EL_CONVEYOR_BELT_2_SWITCH_MIDDLE:
1094 case EL_CONVEYOR_BELT_2_SWITCH_RIGHT:
1095 case EL_CONVEYOR_BELT_3_SWITCH_LEFT:
1096 case EL_CONVEYOR_BELT_3_SWITCH_MIDDLE:
1097 case EL_CONVEYOR_BELT_3_SWITCH_RIGHT:
1098 case EL_CONVEYOR_BELT_4_SWITCH_LEFT:
1099 case EL_CONVEYOR_BELT_4_SWITCH_MIDDLE:
1100 case EL_CONVEYOR_BELT_4_SWITCH_RIGHT:
1103 int belt_nr = getBeltNrFromBeltSwitchElement(Feld[x][y]);
1104 int belt_dir = getBeltDirFromBeltSwitchElement(Feld[x][y]);
1105 int belt_dir_nr = getBeltDirNrFromBeltSwitchElement(Feld[x][y]);
1107 if (game.belt_dir_nr[belt_nr] == 3) /* initial value */
1109 game.belt_dir[belt_nr] = belt_dir;
1110 game.belt_dir_nr[belt_nr] = belt_dir_nr;
1112 else /* more than one switch -- set it like the first switch */
1114 Feld[x][y] = Feld[x][y] - belt_dir_nr + game.belt_dir_nr[belt_nr];
1119 case EL_SWITCHGATE_SWITCH_DOWN: /* always start with same switch pos */
1121 Feld[x][y] = EL_SWITCHGATE_SWITCH_UP;
1124 case EL_LIGHT_SWITCH_ACTIVE:
1126 game.light_time_left = level.time_light * FRAMES_PER_SECOND;
1129 case EL_EMC_MAGIC_BALL:
1130 if (game.ball_state)
1131 Feld[x][y] = EL_EMC_MAGIC_BALL_ACTIVE;
1134 case EL_EMC_MAGIC_BALL_SWITCH:
1135 if (game.ball_state)
1136 Feld[x][y] = EL_EMC_MAGIC_BALL_SWITCH_ACTIVE;
1141 if (IS_CUSTOM_ELEMENT(element))
1143 if (CAN_MOVE(element))
1146 #if USE_NEW_CUSTOM_VALUE
1147 if (!element_info[element].use_last_ce_value || init_game)
1148 CustomValue[x][y] = GET_NEW_CE_VALUE(Feld[x][y]);
1152 if (IS_CUSTOM_ELEMENT(element) && CAN_MOVE(element))
1155 else if (IS_GROUP_ELEMENT(element))
1158 Feld[x][y] = get_element_from_group_element(element);
1160 InitField(x, y, init_game);
1162 struct ElementGroupInfo *group = element_info[element].group;
1163 int last_anim_random_frame = gfx.anim_random_frame;
1166 if (group->choice_mode == ANIM_RANDOM)
1167 gfx.anim_random_frame = RND(group->num_elements_resolved);
1169 element_pos = getAnimationFrame(group->num_elements_resolved, 1,
1170 group->choice_mode, 0,
1173 if (group->choice_mode == ANIM_RANDOM)
1174 gfx.anim_random_frame = last_anim_random_frame;
1176 group->choice_pos++;
1178 Feld[x][y] = group->element_resolved[element_pos];
1180 InitField(x, y, init_game);
1188 CheckTriggeredElementChange(x, y, element, CE_CREATION_OF_X);
1193 #if USE_NEW_CUSTOM_VALUE
1196 CustomValue[x][y] = GET_NEW_CE_VALUE(Feld[x][y]);
1198 CustomValue[x][y] = element_info[Feld[x][y]].custom_value_initial;
1206 static inline void InitField_WithBug1(int x, int y, boolean init_game)
1208 InitField(x, y, init_game);
1210 /* not needed to call InitMovDir() -- already done by InitField()! */
1211 if (game.engine_version < VERSION_IDENT(3,1,0,0) &&
1212 CAN_MOVE(Feld[x][y]))
1216 static inline void InitField_WithBug2(int x, int y, boolean init_game)
1218 int old_element = Feld[x][y];
1220 InitField(x, y, init_game);
1222 /* not needed to call InitMovDir() -- already done by InitField()! */
1223 if (game.engine_version < VERSION_IDENT(3,1,0,0) &&
1224 CAN_MOVE(old_element) &&
1225 (old_element < EL_MOLE_LEFT || old_element > EL_MOLE_DOWN))
1228 /* this case is in fact a combination of not less than three bugs:
1229 first, it calls InitMovDir() for elements that can move, although this is
1230 already done by InitField(); then, it checks the element that was at this
1231 field _before_ the call to InitField() (which can change it); lastly, it
1232 was not called for "mole with direction" elements, which were treated as
1233 "cannot move" due to (fixed) wrong element initialization in "src/init.c"
1237 inline void DrawGameValue_Emeralds(int value)
1239 int xpos = (3 * 14 - 3 * getFontWidth(FONT_TEXT_2)) / 2;
1241 DrawText(DX_EMERALDS + xpos, DY_EMERALDS, int2str(value, 3), FONT_TEXT_2);
1244 inline void DrawGameValue_Dynamite(int value)
1246 int xpos = (3 * 14 - 3 * getFontWidth(FONT_TEXT_2)) / 2;
1248 DrawText(DX_DYNAMITE + xpos, DY_DYNAMITE, int2str(value, 3), FONT_TEXT_2);
1251 inline void DrawGameValue_Keys(int key[MAX_NUM_KEYS])
1253 int base_key_graphic = EL_KEY_1;
1256 if (level.game_engine_type == GAME_ENGINE_TYPE_EM)
1257 base_key_graphic = EL_EM_KEY_1;
1259 /* currently only 4 of 8 possible keys are displayed */
1260 for (i = 0; i < STD_NUM_KEYS; i++)
1263 DrawMiniGraphicExt(drawto, DX_KEYS + i * MINI_TILEX, DY_KEYS,
1264 el2edimg(base_key_graphic + i));
1266 BlitBitmap(graphic_info[IMG_GLOBAL_DOOR].bitmap, drawto,
1267 DOOR_GFX_PAGEX5 + XX_KEYS + i * MINI_TILEX, YY_KEYS,
1268 MINI_TILEX, MINI_TILEY, DX_KEYS + i * MINI_TILEX, DY_KEYS);
1272 inline void DrawGameValue_Score(int value)
1274 int xpos = (5 * 14 - 5 * getFontWidth(FONT_TEXT_2)) / 2;
1276 DrawText(DX_SCORE + xpos, DY_SCORE, int2str(value, 5), FONT_TEXT_2);
1279 inline void DrawGameValue_Time(int value)
1281 int xpos3 = (3 * 14 - 3 * getFontWidth(FONT_TEXT_2)) / 2;
1282 int xpos4 = (4 * 10 - 4 * getFontWidth(FONT_LEVEL_NUMBER)) / 2;
1284 /* clear background if value just changed its size */
1285 if (value == 999 || value == 1000)
1286 ClearRectangle(drawto, DX_TIME1, DY_TIME, 14 * 3, 14);
1289 DrawText(DX_TIME1 + xpos3, DY_TIME, int2str(value, 3), FONT_TEXT_2);
1291 DrawText(DX_TIME2 + xpos4, DY_TIME, int2str(value, 4), FONT_LEVEL_NUMBER);
1294 inline void DrawGameValue_Level(int value)
1297 DrawText(DX_LEVEL, DY_LEVEL, int2str(value, 2), FONT_TEXT_2);
1300 /* misuse area for displaying emeralds to draw bigger level number */
1301 DrawTextExt(drawto, DX_EMERALDS, DY_EMERALDS,
1302 int2str(value, 3), FONT_LEVEL_NUMBER, BLIT_OPAQUE);
1304 /* now copy it to the area for displaying level number */
1305 BlitBitmap(drawto, drawto,
1306 DX_EMERALDS, DY_EMERALDS + 1,
1307 getFontWidth(FONT_LEVEL_NUMBER) * 3,
1308 getFontHeight(FONT_LEVEL_NUMBER) - 1,
1309 DX_LEVEL - 1, DY_LEVEL + 1);
1311 /* restore the area for displaying emeralds */
1312 DrawGameValue_Emeralds(local_player->gems_still_needed);
1314 /* yes, this is all really ugly :-) */
1318 void DrawAllGameValues(int emeralds, int dynamite, int score, int time,
1321 int key[MAX_NUM_KEYS];
1324 for (i = 0; i < MAX_NUM_KEYS; i++)
1325 key[i] = key_bits & (1 << i);
1327 DrawGameValue_Level(level_nr);
1329 DrawGameValue_Emeralds(emeralds);
1330 DrawGameValue_Dynamite(dynamite);
1331 DrawGameValue_Score(score);
1332 DrawGameValue_Time(time);
1334 DrawGameValue_Keys(key);
1337 void DrawGameDoorValues()
1339 int dynamite_state = 0;
1343 if (level.game_engine_type == GAME_ENGINE_TYPE_EM)
1345 DrawGameDoorValues_EM();
1351 DrawGameValue_Level(level_nr);
1353 DrawGameValue_Emeralds(local_player->gems_still_needed);
1354 DrawGameValue_Dynamite(local_player->inventory_size);
1355 DrawGameValue_Score(local_player->score);
1356 DrawGameValue_Time(TimeLeft);
1360 if (game.centered_player_nr == -1)
1362 for (i = 0; i < MAX_PLAYERS; i++)
1364 for (j = 0; j < MAX_NUM_KEYS; j++)
1365 if (stored_player[i].key[j])
1366 key_bits |= (1 << j);
1368 dynamite_state += stored_player[i].inventory_size;
1372 DrawGameValue_Keys(stored_player[i].key);
1377 int player_nr = game.centered_player_nr;
1379 for (i = 0; i < MAX_NUM_KEYS; i++)
1380 if (stored_player[player_nr].key[i])
1381 key_bits |= (1 << i);
1383 dynamite_state = stored_player[player_nr].inventory_size;
1386 DrawAllGameValues(local_player->gems_still_needed, dynamite_state,
1387 local_player->score, TimeLeft, key_bits);
1392 static void resolve_group_element(int group_element, int recursion_depth)
1394 static int group_nr;
1395 static struct ElementGroupInfo *group;
1396 struct ElementGroupInfo *actual_group = element_info[group_element].group;
1399 if (recursion_depth > NUM_GROUP_ELEMENTS) /* recursion too deep */
1401 Error(ERR_WARN, "recursion too deep when resolving group element %d",
1402 group_element - EL_GROUP_START + 1);
1404 /* replace element which caused too deep recursion by question mark */
1405 group->element_resolved[group->num_elements_resolved++] = EL_UNKNOWN;
1410 if (recursion_depth == 0) /* initialization */
1412 group = element_info[group_element].group;
1413 group_nr = group_element - EL_GROUP_START;
1415 group->num_elements_resolved = 0;
1416 group->choice_pos = 0;
1419 for (i = 0; i < actual_group->num_elements; i++)
1421 int element = actual_group->element[i];
1423 if (group->num_elements_resolved == NUM_FILE_ELEMENTS)
1426 if (IS_GROUP_ELEMENT(element))
1427 resolve_group_element(element, recursion_depth + 1);
1430 group->element_resolved[group->num_elements_resolved++] = element;
1431 element_info[element].in_group[group_nr] = TRUE;
1438 =============================================================================
1440 -----------------------------------------------------------------------------
1441 initialize game engine due to level / tape version number
1442 =============================================================================
1445 static void InitGameEngine()
1447 int i, j, k, l, x, y;
1449 /* set game engine from tape file when re-playing, else from level file */
1450 game.engine_version = (tape.playing ? tape.engine_version :
1451 level.game_version);
1453 /* ---------------------------------------------------------------------- */
1454 /* set flags for bugs and changes according to active game engine version */
1455 /* ---------------------------------------------------------------------- */
1458 Summary of bugfix/change:
1459 Fixed handling for custom elements that change when pushed by the player.
1461 Fixed/changed in version:
1465 Before 3.1.0, custom elements that "change when pushing" changed directly
1466 after the player started pushing them (until then handled in "DigField()").
1467 Since 3.1.0, these custom elements are not changed until the "pushing"
1468 move of the element is finished (now handled in "ContinueMoving()").
1470 Affected levels/tapes:
1471 The first condition is generally needed for all levels/tapes before version
1472 3.1.0, which might use the old behaviour before it was changed; known tapes
1473 that are affected are some tapes from the level set "Walpurgis Gardens" by
1475 The second condition is an exception from the above case and is needed for
1476 the special case of tapes recorded with game (not engine!) version 3.1.0 or
1477 above (including some development versions of 3.1.0), but before it was
1478 known that this change would break tapes like the above and was fixed in
1479 3.1.1, so that the changed behaviour was active although the engine version
1480 while recording maybe was before 3.1.0. There is at least one tape that is
1481 affected by this exception, which is the tape for the one-level set "Bug
1482 Machine" by Juergen Bonhagen.
1485 game.use_change_when_pushing_bug =
1486 (game.engine_version < VERSION_IDENT(3,1,0,0) &&
1488 tape.game_version >= VERSION_IDENT(3,1,0,0) &&
1489 tape.game_version < VERSION_IDENT(3,1,1,0)));
1492 Summary of bugfix/change:
1493 Fixed handling for blocking the field the player leaves when moving.
1495 Fixed/changed in version:
1499 Before 3.1.1, when "block last field when moving" was enabled, the field
1500 the player is leaving when moving was blocked for the time of the move,
1501 and was directly unblocked afterwards. This resulted in the last field
1502 being blocked for exactly one less than the number of frames of one player
1503 move. Additionally, even when blocking was disabled, the last field was
1504 blocked for exactly one frame.
1505 Since 3.1.1, due to changes in player movement handling, the last field
1506 is not blocked at all when blocking is disabled. When blocking is enabled,
1507 the last field is blocked for exactly the number of frames of one player
1508 move. Additionally, if the player is Murphy, the hero of Supaplex, the
1509 last field is blocked for exactly one more than the number of frames of
1512 Affected levels/tapes:
1513 (!!! yet to be determined -- probably many !!!)
1516 game.use_block_last_field_bug =
1517 (game.engine_version < VERSION_IDENT(3,1,1,0));
1520 Summary of bugfix/change:
1521 Changed behaviour of CE changes with multiple changes per single frame.
1523 Fixed/changed in version:
1527 Before 3.2.0-6, only one single CE change was allowed in each engine frame.
1528 This resulted in race conditions where CEs seem to behave strange in some
1529 situations (where triggered CE changes were just skipped because there was
1530 already a CE change on that tile in the playfield in that engine frame).
1531 Since 3.2.0-6, this was changed to allow up to MAX_NUM_CHANGES_PER_FRAME.
1532 (The number of changes per frame must be limited in any case, because else
1533 it is easily possible to define CE changes that would result in an infinite
1534 loop, causing the whole game to freeze. The MAX_NUM_CHANGES_PER_FRAME value
1535 should be set large enough so that it would only be reached in cases where
1536 the corresponding CE change conditions run into a loop. Therefore, it seems
1537 to be reasonable to set MAX_NUM_CHANGES_PER_FRAME to the same value as the
1538 maximal number of change pages for custom elements.)
1540 Affected levels/tapes:
1544 #if USE_ONLY_ONE_CHANGE_PER_FRAME
1545 game.max_num_changes_per_frame = 1;
1547 game.max_num_changes_per_frame =
1548 (game.engine_version < VERSION_IDENT(3,2,0,6) ? 1 : 32);
1551 /* ---------------------------------------------------------------------- */
1553 /* default scan direction: scan playfield from top/left to bottom/right */
1554 InitPlayfieldScanMode(CA_ARG_SCAN_MODE_NORMAL);
1556 /* dynamically adjust element properties according to game engine version */
1557 InitElementPropertiesEngine(game.engine_version);
1560 printf("level %d: level version == %06d\n", level_nr, level.game_version);
1561 printf(" tape version == %06d [%s] [file: %06d]\n",
1562 tape.engine_version, (tape.playing ? "PLAYING" : "RECORDING"),
1564 printf(" => game.engine_version == %06d\n", game.engine_version);
1568 /* ---------- recursively resolve group elements ------------------------- */
1570 for (i = 0; i < MAX_NUM_ELEMENTS; i++)
1571 for (j = 0; j < NUM_GROUP_ELEMENTS; j++)
1572 element_info[i].in_group[j] = FALSE;
1574 for (i = 0; i < NUM_GROUP_ELEMENTS; i++)
1575 resolve_group_element(EL_GROUP_START + i, 0);
1578 /* ---------- initialize player's initial move delay --------------------- */
1581 /* dynamically adjust player properties according to level information */
1582 game.initial_move_delay_value =
1583 get_move_delay_from_stepsize(level.initial_player_stepsize);
1585 /* dynamically adjust player properties according to level information */
1586 game.initial_move_delay_value =
1587 (level.double_speed ? MOVE_DELAY_HIGH_SPEED : MOVE_DELAY_NORMAL_SPEED);
1590 /* dynamically adjust player properties according to game engine version */
1591 game.initial_move_delay = (game.engine_version <= VERSION_IDENT(2,0,1,0) ?
1592 game.initial_move_delay_value : 0);
1594 /* ---------- initialize player's initial push delay --------------------- */
1596 /* dynamically adjust player properties according to game engine version */
1597 game.initial_push_delay_value =
1598 (game.engine_version < VERSION_IDENT(3,0,7,1) ? 5 : -1);
1600 /* ---------- initialize changing elements ------------------------------- */
1602 /* initialize changing elements information */
1603 for (i = 0; i < MAX_NUM_ELEMENTS; i++)
1605 struct ElementInfo *ei = &element_info[i];
1607 /* this pointer might have been changed in the level editor */
1608 ei->change = &ei->change_page[0];
1610 if (!IS_CUSTOM_ELEMENT(i))
1612 ei->change->target_element = EL_EMPTY_SPACE;
1613 ei->change->delay_fixed = 0;
1614 ei->change->delay_random = 0;
1615 ei->change->delay_frames = 1;
1618 for (j = 0; j < NUM_CHANGE_EVENTS; j++)
1620 ei->has_change_event[j] = FALSE;
1622 ei->event_page_nr[j] = 0;
1623 ei->event_page[j] = &ei->change_page[0];
1627 /* add changing elements from pre-defined list */
1628 for (i = 0; change_delay_list[i].element != EL_UNDEFINED; i++)
1630 struct ChangingElementInfo *ch_delay = &change_delay_list[i];
1631 struct ElementInfo *ei = &element_info[ch_delay->element];
1633 ei->change->target_element = ch_delay->target_element;
1634 ei->change->delay_fixed = ch_delay->change_delay;
1636 ei->change->pre_change_function = ch_delay->pre_change_function;
1637 ei->change->change_function = ch_delay->change_function;
1638 ei->change->post_change_function = ch_delay->post_change_function;
1640 ei->change->can_change = TRUE;
1641 ei->change->can_change_or_has_action = TRUE;
1643 ei->has_change_event[CE_DELAY] = TRUE;
1645 SET_PROPERTY(ch_delay->element, EP_CAN_CHANGE, TRUE);
1646 SET_PROPERTY(ch_delay->element, EP_CAN_CHANGE_OR_HAS_ACTION, TRUE);
1649 /* ---------- initialize internal run-time variables ------------- */
1651 for (i = 0; i < NUM_CUSTOM_ELEMENTS; i++)
1653 struct ElementInfo *ei = &element_info[EL_CUSTOM_START + i];
1655 for (j = 0; j < ei->num_change_pages; j++)
1657 ei->change_page[j].can_change_or_has_action =
1658 (ei->change_page[j].can_change |
1659 ei->change_page[j].has_action);
1663 /* add change events from custom element configuration */
1664 for (i = 0; i < NUM_CUSTOM_ELEMENTS; i++)
1666 struct ElementInfo *ei = &element_info[EL_CUSTOM_START + i];
1668 for (j = 0; j < ei->num_change_pages; j++)
1670 if (!ei->change_page[j].can_change_or_has_action)
1673 for (k = 0; k < NUM_CHANGE_EVENTS; k++)
1675 /* only add event page for the first page found with this event */
1676 if (ei->change_page[j].has_event[k] && !(ei->has_change_event[k]))
1678 ei->has_change_event[k] = TRUE;
1680 ei->event_page_nr[k] = j;
1681 ei->event_page[k] = &ei->change_page[j];
1687 /* ---------- initialize run-time trigger player and element ------------- */
1689 for (i = 0; i < NUM_CUSTOM_ELEMENTS; i++)
1691 struct ElementInfo *ei = &element_info[EL_CUSTOM_START + i];
1693 for (j = 0; j < ei->num_change_pages; j++)
1695 ei->change_page[j].actual_trigger_element = EL_EMPTY;
1696 ei->change_page[j].actual_trigger_player = EL_PLAYER_1;
1697 ei->change_page[j].actual_trigger_side = CH_SIDE_NONE;
1698 ei->change_page[j].actual_trigger_ce_value = 0;
1699 ei->change_page[j].actual_trigger_ce_score = 0;
1703 /* ---------- initialize trigger events ---------------------------------- */
1705 /* initialize trigger events information */
1706 for (i = 0; i < MAX_NUM_ELEMENTS; i++)
1707 for (j = 0; j < NUM_CHANGE_EVENTS; j++)
1708 trigger_events[i][j] = FALSE;
1710 /* add trigger events from element change event properties */
1711 for (i = 0; i < MAX_NUM_ELEMENTS; i++)
1713 struct ElementInfo *ei = &element_info[i];
1715 for (j = 0; j < ei->num_change_pages; j++)
1717 if (!ei->change_page[j].can_change_or_has_action)
1720 if (ei->change_page[j].has_event[CE_BY_OTHER_ACTION])
1722 int trigger_element = ei->change_page[j].trigger_element;
1724 for (k = 0; k < NUM_CHANGE_EVENTS; k++)
1726 if (ei->change_page[j].has_event[k])
1728 if (IS_GROUP_ELEMENT(trigger_element))
1730 struct ElementGroupInfo *group =
1731 element_info[trigger_element].group;
1733 for (l = 0; l < group->num_elements_resolved; l++)
1734 trigger_events[group->element_resolved[l]][k] = TRUE;
1737 trigger_events[trigger_element][k] = TRUE;
1744 /* ---------- initialize push delay -------------------------------------- */
1746 /* initialize push delay values to default */
1747 for (i = 0; i < MAX_NUM_ELEMENTS; i++)
1749 if (!IS_CUSTOM_ELEMENT(i))
1751 element_info[i].push_delay_fixed = game.default_push_delay_fixed;
1752 element_info[i].push_delay_random = game.default_push_delay_random;
1756 /* set push delay value for certain elements from pre-defined list */
1757 for (i = 0; push_delay_list[i].element != EL_UNDEFINED; i++)
1759 int e = push_delay_list[i].element;
1761 element_info[e].push_delay_fixed = push_delay_list[i].push_delay_fixed;
1762 element_info[e].push_delay_random = push_delay_list[i].push_delay_random;
1765 /* set push delay value for Supaplex elements for newer engine versions */
1766 if (game.engine_version >= VERSION_IDENT(3,1,0,0))
1768 for (i = 0; i < MAX_NUM_ELEMENTS; i++)
1770 if (IS_SP_ELEMENT(i))
1772 /* set SP push delay to just enough to push under a falling zonk */
1773 int delay = (game.engine_version >= VERSION_IDENT(3,1,1,0) ? 8 : 6);
1775 element_info[i].push_delay_fixed = delay;
1776 element_info[i].push_delay_random = 0;
1781 /* ---------- initialize move stepsize ----------------------------------- */
1783 /* initialize move stepsize values to default */
1784 for (i = 0; i < MAX_NUM_ELEMENTS; i++)
1785 if (!IS_CUSTOM_ELEMENT(i))
1786 element_info[i].move_stepsize = MOVE_STEPSIZE_NORMAL;
1788 /* set move stepsize value for certain elements from pre-defined list */
1789 for (i = 0; move_stepsize_list[i].element != EL_UNDEFINED; i++)
1791 int e = move_stepsize_list[i].element;
1793 element_info[e].move_stepsize = move_stepsize_list[i].move_stepsize;
1796 /* ---------- initialize collect score ----------------------------------- */
1798 /* initialize collect score values for custom elements from initial value */
1799 for (i = 0; i < MAX_NUM_ELEMENTS; i++)
1800 if (IS_CUSTOM_ELEMENT(i))
1801 element_info[i].collect_score = element_info[i].collect_score_initial;
1803 /* ---------- initialize collect count ----------------------------------- */
1805 /* initialize collect count values for non-custom elements */
1806 for (i = 0; i < MAX_NUM_ELEMENTS; i++)
1807 if (!IS_CUSTOM_ELEMENT(i))
1808 element_info[i].collect_count_initial = 0;
1810 /* add collect count values for all elements from pre-defined list */
1811 for (i = 0; collect_count_list[i].element != EL_UNDEFINED; i++)
1812 element_info[collect_count_list[i].element].collect_count_initial =
1813 collect_count_list[i].count;
1815 /* ---------- initialize access direction -------------------------------- */
1817 /* initialize access direction values to default (access from every side) */
1818 for (i = 0; i < MAX_NUM_ELEMENTS; i++)
1819 if (!IS_CUSTOM_ELEMENT(i))
1820 element_info[i].access_direction = MV_ALL_DIRECTIONS;
1822 /* set access direction value for certain elements from pre-defined list */
1823 for (i = 0; access_direction_list[i].element != EL_UNDEFINED; i++)
1824 element_info[access_direction_list[i].element].access_direction =
1825 access_direction_list[i].direction;
1827 /* ---------- initialize explosion content ------------------------------- */
1828 for (i = 0; i < MAX_NUM_ELEMENTS; i++)
1830 if (IS_CUSTOM_ELEMENT(i))
1833 for (y = 0; y < 3; y++) for (x = 0; x < 3; x++)
1835 /* (content for EL_YAMYAM set at run-time with game.yamyam_content_nr) */
1837 element_info[i].content.e[x][y] =
1838 (i == EL_PLAYER_1 ? EL_EMERALD_YELLOW :
1839 i == EL_PLAYER_2 ? EL_EMERALD_RED :
1840 i == EL_PLAYER_3 ? EL_EMERALD :
1841 i == EL_PLAYER_4 ? EL_EMERALD_PURPLE :
1842 i == EL_MOLE ? EL_EMERALD_RED :
1843 i == EL_PENGUIN ? EL_EMERALD_PURPLE :
1844 i == EL_BUG ? (x == 1 && y == 1 ? EL_DIAMOND : EL_EMERALD) :
1845 i == EL_BD_BUTTERFLY ? EL_BD_DIAMOND :
1846 i == EL_SP_ELECTRON ? EL_SP_INFOTRON :
1847 i == EL_AMOEBA_TO_DIAMOND ? level.amoeba_content :
1848 i == EL_WALL_EMERALD ? EL_EMERALD :
1849 i == EL_WALL_DIAMOND ? EL_DIAMOND :
1850 i == EL_WALL_BD_DIAMOND ? EL_BD_DIAMOND :
1851 i == EL_WALL_EMERALD_YELLOW ? EL_EMERALD_YELLOW :
1852 i == EL_WALL_EMERALD_RED ? EL_EMERALD_RED :
1853 i == EL_WALL_EMERALD_PURPLE ? EL_EMERALD_PURPLE :
1854 i == EL_WALL_PEARL ? EL_PEARL :
1855 i == EL_WALL_CRYSTAL ? EL_CRYSTAL :
1861 int get_num_special_action(int element, int action_first, int action_last)
1863 int num_special_action = 0;
1866 for (i = action_first; i <= action_last; i++)
1868 boolean found = FALSE;
1870 for (j = 0; j < NUM_DIRECTIONS; j++)
1871 if (el_act_dir2img(element, i, j) !=
1872 el_act_dir2img(element, ACTION_DEFAULT, j))
1876 num_special_action++;
1882 printf("::: %d->%d: %d\n", action_first, action_last, num_special_action);
1885 return num_special_action;
1889 =============================================================================
1891 -----------------------------------------------------------------------------
1892 initialize and start new game
1893 =============================================================================
1898 boolean emulate_bd = TRUE; /* unless non-BOULDERDASH elements found */
1899 boolean emulate_sb = TRUE; /* unless non-SOKOBAN elements found */
1900 boolean emulate_sp = TRUE; /* unless non-SUPAPLEX elements found */
1905 /* don't play tapes over network */
1906 network_playing = (options.network && !tape.playing);
1908 for (i = 0; i < MAX_PLAYERS; i++)
1910 struct PlayerInfo *player = &stored_player[i];
1912 player->index_nr = i;
1913 player->index_bit = (1 << i);
1914 player->element_nr = EL_PLAYER_1 + i;
1916 player->present = FALSE;
1917 player->active = FALSE;
1920 player->effective_action = 0;
1921 player->programmed_action = 0;
1924 player->gems_still_needed = level.gems_needed;
1925 player->sokobanfields_still_needed = 0;
1926 player->lights_still_needed = 0;
1927 player->friends_still_needed = 0;
1929 for (j = 0; j < MAX_NUM_KEYS; j++)
1930 player->key[j] = FALSE;
1932 player->dynabomb_count = 0;
1933 player->dynabomb_size = 1;
1934 player->dynabombs_left = 0;
1935 player->dynabomb_xl = FALSE;
1937 player->MovDir = MV_NONE;
1940 player->GfxDir = MV_NONE;
1941 player->GfxAction = ACTION_DEFAULT;
1943 player->StepFrame = 0;
1945 player->use_murphy = FALSE;
1946 player->artwork_element =
1947 (level.use_artwork_element[i] ? level.artwork_element[i] :
1948 player->element_nr);
1950 player->block_last_field = FALSE; /* initialized in InitPlayerField() */
1951 player->block_delay_adjustment = 0; /* initialized in InitPlayerField() */
1953 player->can_fall_into_acid = CAN_MOVE_INTO_ACID(player->element_nr);
1955 player->actual_frame_counter = 0;
1957 player->step_counter = 0;
1959 player->last_move_dir = MV_NONE;
1961 player->is_waiting = FALSE;
1962 player->is_moving = FALSE;
1963 player->is_auto_moving = FALSE;
1964 player->is_digging = FALSE;
1965 player->is_snapping = FALSE;
1966 player->is_collecting = FALSE;
1967 player->is_pushing = FALSE;
1968 player->is_switching = FALSE;
1969 player->is_dropping = FALSE;
1970 player->is_dropping_pressed = FALSE;
1972 player->is_bored = FALSE;
1973 player->is_sleeping = FALSE;
1975 player->frame_counter_bored = -1;
1976 player->frame_counter_sleeping = -1;
1978 player->anim_delay_counter = 0;
1979 player->post_delay_counter = 0;
1981 player->dir_waiting = MV_NONE;
1982 player->action_waiting = ACTION_DEFAULT;
1983 player->last_action_waiting = ACTION_DEFAULT;
1984 player->special_action_bored = ACTION_DEFAULT;
1985 player->special_action_sleeping = ACTION_DEFAULT;
1988 /* cannot be set here -- could be modified in Init[Player]Field() below */
1990 /* set number of special actions for bored and sleeping animation */
1991 player->num_special_action_bored =
1992 get_num_special_action(player->artwork_element,
1993 ACTION_BORING_1, ACTION_BORING_LAST);
1994 player->num_special_action_sleeping =
1995 get_num_special_action(player->artwork_element,
1996 ACTION_SLEEPING_1, ACTION_SLEEPING_LAST);
1999 player->switch_x = -1;
2000 player->switch_y = -1;
2002 player->drop_x = -1;
2003 player->drop_y = -1;
2005 player->show_envelope = 0;
2008 SetPlayerMoveSpeed(player, level.initial_player_stepsize, TRUE);
2010 player->move_delay = game.initial_move_delay;
2011 player->move_delay_value = game.initial_move_delay_value;
2013 player->move_delay_value_next = -1;
2015 player->move_delay_reset_counter = 0;
2017 player->cannot_move = FALSE;
2020 player->push_delay = -1; /* initialized when pushing starts */
2021 player->push_delay_value = game.initial_push_delay_value;
2023 player->drop_delay = 0;
2024 player->drop_pressed_delay = 0;
2026 player->last_jx = player->last_jy = 0;
2027 player->jx = player->jy = 0;
2029 player->shield_normal_time_left = 0;
2030 player->shield_deadly_time_left = 0;
2032 player->inventory_infinite_element = EL_UNDEFINED;
2033 player->inventory_size = 0;
2035 DigField(player, 0, 0, 0, 0, 0, 0, DF_NO_PUSH);
2036 SnapField(player, 0, 0);
2038 player->LevelSolved = FALSE;
2039 player->GameOver = FALSE;
2042 network_player_action_received = FALSE;
2044 #if defined(NETWORK_AVALIABLE)
2045 /* initial null action */
2046 if (network_playing)
2047 SendToServer_MovePlayer(MV_NONE);
2056 TimeLeft = level.time;
2059 ScreenMovDir = MV_NONE;
2063 ScrollStepSize = 0; /* will be correctly initialized by ScrollScreen() */
2065 AllPlayersGone = FALSE;
2067 game.yamyam_content_nr = 0;
2068 game.magic_wall_active = FALSE;
2069 game.magic_wall_time_left = 0;
2070 game.light_time_left = 0;
2071 game.timegate_time_left = 0;
2072 game.switchgate_pos = 0;
2073 game.wind_direction = level.wind_direction_initial;
2074 game.gravity = level.initial_gravity;
2075 game.explosions_delayed = TRUE;
2077 game.lenses_time_left = 0;
2078 game.magnify_time_left = 0;
2080 game.ball_state = level.ball_state_initial;
2081 game.ball_content_nr = 0;
2083 game.envelope_active = FALSE;
2085 /* set focus to local player for network games, else to all players */
2086 game.centered_player_nr = (network_playing ? local_player->index_nr : -1);
2087 game.centered_player_nr_next = game.centered_player_nr;
2088 game.set_centered_player = FALSE;
2090 if (network_playing && tape.recording)
2092 /* store client dependent player focus when recording network games */
2093 tape.centered_player_nr_next = game.centered_player_nr_next;
2094 tape.set_centered_player = TRUE;
2098 printf("::: focus set to player %d [%d]\n",
2099 game.centered_player_nr, local_player->index_nr);
2102 for (i = 0; i < NUM_BELTS; i++)
2104 game.belt_dir[i] = MV_NONE;
2105 game.belt_dir_nr[i] = 3; /* not moving, next moving left */
2108 for (i = 0; i < MAX_NUM_AMOEBA; i++)
2109 AmoebaCnt[i] = AmoebaCnt2[i] = 0;
2112 SCAN_PLAYFIELD(x, y)
2114 for (x = 0; x < lev_fieldx; x++) for (y = 0; y < lev_fieldy; y++)
2117 Feld[x][y] = level.field[x][y];
2118 MovPos[x][y] = MovDir[x][y] = MovDelay[x][y] = 0;
2119 ChangeDelay[x][y] = 0;
2120 ChangePage[x][y] = -1;
2121 #if USE_NEW_CUSTOM_VALUE
2122 CustomValue[x][y] = 0; /* initialized in InitField() */
2124 Store[x][y] = Store2[x][y] = StorePlayer[x][y] = Back[x][y] = 0;
2126 WasJustMoving[x][y] = 0;
2127 WasJustFalling[x][y] = 0;
2128 CheckCollision[x][y] = 0;
2130 Pushed[x][y] = FALSE;
2132 ChangeCount[x][y] = 0;
2133 ChangeEvent[x][y] = -1;
2135 ExplodePhase[x][y] = 0;
2136 ExplodeDelay[x][y] = 0;
2137 ExplodeField[x][y] = EX_TYPE_NONE;
2139 RunnerVisit[x][y] = 0;
2140 PlayerVisit[x][y] = 0;
2143 GfxRandom[x][y] = INIT_GFX_RANDOM();
2144 GfxElement[x][y] = EL_UNDEFINED;
2145 GfxAction[x][y] = ACTION_DEFAULT;
2146 GfxDir[x][y] = MV_NONE;
2150 SCAN_PLAYFIELD(x, y)
2152 for (y = 0; y < lev_fieldy; y++) for (x = 0; x < lev_fieldx; x++)
2155 if (emulate_bd && !IS_BD_ELEMENT(Feld[x][y]))
2157 if (emulate_sb && !IS_SB_ELEMENT(Feld[x][y]))
2159 if (emulate_sp && !IS_SP_ELEMENT(Feld[x][y]))
2162 InitField(x, y, TRUE);
2167 for (i = 0; i < MAX_PLAYERS; i++)
2169 struct PlayerInfo *player = &stored_player[i];
2172 /* set number of special actions for bored and sleeping animation */
2173 player->num_special_action_bored =
2174 get_num_special_action(player->artwork_element,
2175 ACTION_BORING_1, ACTION_BORING_LAST);
2176 player->num_special_action_sleeping =
2177 get_num_special_action(player->artwork_element,
2178 ACTION_SLEEPING_1, ACTION_SLEEPING_LAST);
2183 game.emulation = (emulate_bd ? EMU_BOULDERDASH :
2184 emulate_sb ? EMU_SOKOBAN :
2185 emulate_sp ? EMU_SUPAPLEX : EMU_NONE);
2187 #if USE_NEW_ALL_SLIPPERY
2188 /* initialize type of slippery elements */
2189 for (i = 0; i < MAX_NUM_ELEMENTS; i++)
2191 if (!IS_CUSTOM_ELEMENT(i))
2193 /* default: elements slip down either to the left or right randomly */
2194 element_info[i].slippery_type = SLIPPERY_ANY_RANDOM;
2196 /* SP style elements prefer to slip down on the left side */
2197 if (game.engine_version >= VERSION_IDENT(3,1,1,0) && IS_SP_ELEMENT(i))
2198 element_info[i].slippery_type = SLIPPERY_ANY_LEFT_RIGHT;
2200 /* BD style elements prefer to slip down on the left side */
2201 if (game.emulation == EMU_BOULDERDASH)
2202 element_info[i].slippery_type = SLIPPERY_ANY_LEFT_RIGHT;
2207 /* initialize explosion and ignition delay */
2208 for (i = 0; i < MAX_NUM_ELEMENTS; i++)
2210 if (!IS_CUSTOM_ELEMENT(i))
2213 int delay = (((IS_SP_ELEMENT(i) && i != EL_EMPTY_SPACE) &&
2214 game.engine_version >= VERSION_IDENT(3,1,0,0)) ||
2215 game.emulation == EMU_SUPAPLEX ? 3 : 2);
2216 int last_phase = (num_phase + 1) * delay;
2217 int half_phase = (num_phase / 2) * delay;
2219 element_info[i].explosion_delay = last_phase - 1;
2220 element_info[i].ignition_delay = half_phase;
2222 if (i == EL_BLACK_ORB)
2223 element_info[i].ignition_delay = 1;
2227 if (element_info[i].explosion_delay < 1) /* !!! check again !!! */
2228 element_info[i].explosion_delay = 1;
2230 if (element_info[i].ignition_delay < 1) /* !!! check again !!! */
2231 element_info[i].ignition_delay = 1;
2235 /* correct non-moving belts to start moving left */
2236 for (i = 0; i < NUM_BELTS; i++)
2237 if (game.belt_dir[i] == MV_NONE)
2238 game.belt_dir_nr[i] = 3; /* not moving, next moving left */
2240 /* check if any connected player was not found in playfield */
2241 for (i = 0; i < MAX_PLAYERS; i++)
2243 struct PlayerInfo *player = &stored_player[i];
2245 if (player->connected && !player->present)
2247 for (j = 0; j < MAX_PLAYERS; j++)
2249 struct PlayerInfo *some_player = &stored_player[j];
2250 int jx = some_player->jx, jy = some_player->jy;
2252 /* assign first free player found that is present in the playfield */
2253 if (some_player->present && !some_player->connected)
2255 player->present = TRUE;
2256 player->active = TRUE;
2258 some_player->present = FALSE;
2259 some_player->active = FALSE;
2262 player->element_nr = some_player->element_nr;
2265 player->artwork_element = some_player->artwork_element;
2267 player->block_last_field = some_player->block_last_field;
2268 player->block_delay_adjustment = some_player->block_delay_adjustment;
2270 StorePlayer[jx][jy] = player->element_nr;
2271 player->jx = player->last_jx = jx;
2272 player->jy = player->last_jy = jy;
2282 /* when playing a tape, eliminate all players who do not participate */
2284 for (i = 0; i < MAX_PLAYERS; i++)
2286 if (stored_player[i].active && !tape.player_participates[i])
2288 struct PlayerInfo *player = &stored_player[i];
2289 int jx = player->jx, jy = player->jy;
2291 player->active = FALSE;
2292 StorePlayer[jx][jy] = 0;
2293 Feld[jx][jy] = EL_EMPTY;
2297 else if (!options.network && !setup.team_mode) /* && !tape.playing */
2299 /* when in single player mode, eliminate all but the first active player */
2301 for (i = 0; i < MAX_PLAYERS; i++)
2303 if (stored_player[i].active)
2305 for (j = i + 1; j < MAX_PLAYERS; j++)
2307 if (stored_player[j].active)
2309 struct PlayerInfo *player = &stored_player[j];
2310 int jx = player->jx, jy = player->jy;
2312 player->active = FALSE;
2313 player->present = FALSE;
2315 StorePlayer[jx][jy] = 0;
2316 Feld[jx][jy] = EL_EMPTY;
2323 /* when recording the game, store which players take part in the game */
2326 for (i = 0; i < MAX_PLAYERS; i++)
2327 if (stored_player[i].active)
2328 tape.player_participates[i] = TRUE;
2333 for (i = 0; i < MAX_PLAYERS; i++)
2335 struct PlayerInfo *player = &stored_player[i];
2337 printf("Player %d: present == %d, connected == %d, active == %d.\n",
2342 if (local_player == player)
2343 printf("Player %d is local player.\n", i+1);
2347 if (BorderElement == EL_EMPTY)
2350 SBX_Right = lev_fieldx - SCR_FIELDX;
2352 SBY_Lower = lev_fieldy - SCR_FIELDY;
2357 SBX_Right = lev_fieldx - SCR_FIELDX + 1;
2359 SBY_Lower = lev_fieldy - SCR_FIELDY + 1;
2362 if (lev_fieldx + (SBX_Left == -1 ? 2 : 0) <= SCR_FIELDX)
2363 SBX_Left = SBX_Right = -1 * (SCR_FIELDX - lev_fieldx) / 2;
2365 if (lev_fieldy + (SBY_Upper == -1 ? 2 : 0) <= SCR_FIELDY)
2366 SBY_Upper = SBY_Lower = -1 * (SCR_FIELDY - lev_fieldy) / 2;
2368 /* if local player not found, look for custom element that might create
2369 the player (make some assumptions about the right custom element) */
2370 if (!local_player->present)
2372 int start_x = 0, start_y = 0;
2373 int found_rating = 0;
2374 int found_element = EL_UNDEFINED;
2375 int player_nr = local_player->index_nr;
2378 SCAN_PLAYFIELD(x, y)
2380 for (y = 0; y < lev_fieldy; y++) for (x = 0; x < lev_fieldx; x++)
2383 int element = Feld[x][y];
2388 if (level.use_start_element[player_nr] &&
2389 level.start_element[player_nr] == element &&
2396 found_element = element;
2399 if (!IS_CUSTOM_ELEMENT(element))
2402 if (CAN_CHANGE(element))
2404 for (i = 0; i < element_info[element].num_change_pages; i++)
2406 /* check for player created from custom element as single target */
2407 content = element_info[element].change_page[i].target_element;
2408 is_player = ELEM_IS_PLAYER(content);
2410 if (is_player && (found_rating < 3 || element < found_element))
2416 found_element = element;
2421 for (yy = 0; yy < 3; yy++) for (xx = 0; xx < 3; xx++)
2423 /* check for player created from custom element as explosion content */
2424 content = element_info[element].content.e[xx][yy];
2425 is_player = ELEM_IS_PLAYER(content);
2427 if (is_player && (found_rating < 2 || element < found_element))
2429 start_x = x + xx - 1;
2430 start_y = y + yy - 1;
2433 found_element = element;
2436 if (!CAN_CHANGE(element))
2439 for (i = 0; i < element_info[element].num_change_pages; i++)
2441 /* check for player created from custom element as extended target */
2443 element_info[element].change_page[i].target_content.e[xx][yy];
2445 is_player = ELEM_IS_PLAYER(content);
2447 if (is_player && (found_rating < 1 || element < found_element))
2449 start_x = x + xx - 1;
2450 start_y = y + yy - 1;
2453 found_element = element;
2459 scroll_x = (start_x < SBX_Left + MIDPOSX ? SBX_Left :
2460 start_x > SBX_Right + MIDPOSX ? SBX_Right :
2463 scroll_y = (start_y < SBY_Upper + MIDPOSY ? SBY_Upper :
2464 start_y > SBY_Lower + MIDPOSY ? SBY_Lower :
2469 scroll_x = (local_player->jx < SBX_Left + MIDPOSX ? SBX_Left :
2470 local_player->jx > SBX_Right + MIDPOSX ? SBX_Right :
2471 local_player->jx - MIDPOSX);
2473 scroll_y = (local_player->jy < SBY_Upper + MIDPOSY ? SBY_Upper :
2474 local_player->jy > SBY_Lower + MIDPOSY ? SBY_Lower :
2475 local_player->jy - MIDPOSY);
2478 if (!game.restart_level)
2479 CloseDoor(DOOR_CLOSE_1);
2481 /* !!! FIX THIS (START) !!! */
2482 if (level.game_engine_type == GAME_ENGINE_TYPE_EM)
2484 InitGameEngine_EM();
2491 /* after drawing the level, correct some elements */
2492 if (game.timegate_time_left == 0)
2493 CloseAllOpenTimegates();
2495 if (setup.soft_scrolling)
2496 BlitBitmap(fieldbuffer, backbuffer, FX, FY, SXSIZE, SYSIZE, SX, SY);
2498 redraw_mask |= REDRAW_FROM_BACKBUFFER;
2501 /* !!! FIX THIS (END) !!! */
2503 if (!game.restart_level)
2505 /* copy default game door content to main double buffer */
2506 BlitBitmap(graphic_info[IMG_GLOBAL_DOOR].bitmap, drawto,
2507 DOOR_GFX_PAGEX5, DOOR_GFX_PAGEY1, DXSIZE, DYSIZE, DX, DY);
2510 DrawGameDoorValues();
2512 if (!game.restart_level)
2516 game_gadget[SOUND_CTRL_ID_MUSIC]->checked = setup.sound_music;
2517 game_gadget[SOUND_CTRL_ID_LOOPS]->checked = setup.sound_loops;
2518 game_gadget[SOUND_CTRL_ID_SIMPLE]->checked = setup.sound_simple;
2522 /* copy actual game door content to door double buffer for OpenDoor() */
2523 BlitBitmap(drawto, bitmap_db_door,
2524 DX, DY, DXSIZE, DYSIZE, DOOR_GFX_PAGEX1, DOOR_GFX_PAGEY1);
2526 OpenDoor(DOOR_OPEN_ALL);
2528 PlaySoundStereo(SND_GAME_STARTING, SOUND_MIDDLE);
2530 if (setup.sound_music)
2533 KeyboardAutoRepeatOffUnlessAutoplay();
2537 for (i = 0; i < MAX_PLAYERS; i++)
2538 printf("Player %d %sactive.\n",
2539 i + 1, (stored_player[i].active ? "" : "not "));
2543 game.restart_level = FALSE;
2546 void UpdateEngineValues(int actual_scroll_x, int actual_scroll_y)
2548 /* this is used for non-R'n'D game engines to update certain engine values */
2550 /* needed to determine if sounds are played within the visible screen area */
2551 scroll_x = actual_scroll_x;
2552 scroll_y = actual_scroll_y;
2555 void InitMovDir(int x, int y)
2557 int i, element = Feld[x][y];
2558 static int xy[4][2] =
2565 static int direction[3][4] =
2567 { MV_RIGHT, MV_UP, MV_LEFT, MV_DOWN },
2568 { MV_LEFT, MV_DOWN, MV_RIGHT, MV_UP },
2569 { MV_LEFT, MV_RIGHT, MV_UP, MV_DOWN }
2578 Feld[x][y] = EL_BUG;
2579 MovDir[x][y] = direction[0][element - EL_BUG_RIGHT];
2582 case EL_SPACESHIP_RIGHT:
2583 case EL_SPACESHIP_UP:
2584 case EL_SPACESHIP_LEFT:
2585 case EL_SPACESHIP_DOWN:
2586 Feld[x][y] = EL_SPACESHIP;
2587 MovDir[x][y] = direction[0][element - EL_SPACESHIP_RIGHT];
2590 case EL_BD_BUTTERFLY_RIGHT:
2591 case EL_BD_BUTTERFLY_UP:
2592 case EL_BD_BUTTERFLY_LEFT:
2593 case EL_BD_BUTTERFLY_DOWN:
2594 Feld[x][y] = EL_BD_BUTTERFLY;
2595 MovDir[x][y] = direction[0][element - EL_BD_BUTTERFLY_RIGHT];
2598 case EL_BD_FIREFLY_RIGHT:
2599 case EL_BD_FIREFLY_UP:
2600 case EL_BD_FIREFLY_LEFT:
2601 case EL_BD_FIREFLY_DOWN:
2602 Feld[x][y] = EL_BD_FIREFLY;
2603 MovDir[x][y] = direction[0][element - EL_BD_FIREFLY_RIGHT];
2606 case EL_PACMAN_RIGHT:
2608 case EL_PACMAN_LEFT:
2609 case EL_PACMAN_DOWN:
2610 Feld[x][y] = EL_PACMAN;
2611 MovDir[x][y] = direction[0][element - EL_PACMAN_RIGHT];
2614 case EL_YAMYAM_LEFT:
2615 case EL_YAMYAM_RIGHT:
2617 case EL_YAMYAM_DOWN:
2618 Feld[x][y] = EL_YAMYAM;
2619 MovDir[x][y] = direction[2][element - EL_YAMYAM_LEFT];
2622 case EL_SP_SNIKSNAK:
2623 MovDir[x][y] = MV_UP;
2626 case EL_SP_ELECTRON:
2627 MovDir[x][y] = MV_LEFT;
2634 Feld[x][y] = EL_MOLE;
2635 MovDir[x][y] = direction[2][element - EL_MOLE_LEFT];
2639 if (IS_CUSTOM_ELEMENT(element))
2641 struct ElementInfo *ei = &element_info[element];
2642 int move_direction_initial = ei->move_direction_initial;
2643 int move_pattern = ei->move_pattern;
2645 if (move_direction_initial == MV_START_PREVIOUS)
2647 if (MovDir[x][y] != MV_NONE)
2650 move_direction_initial = MV_START_AUTOMATIC;
2653 if (move_direction_initial == MV_START_RANDOM)
2654 MovDir[x][y] = 1 << RND(4);
2655 else if (move_direction_initial & MV_ANY_DIRECTION)
2656 MovDir[x][y] = move_direction_initial;
2657 else if (move_pattern == MV_ALL_DIRECTIONS ||
2658 move_pattern == MV_TURNING_LEFT ||
2659 move_pattern == MV_TURNING_RIGHT ||
2660 move_pattern == MV_TURNING_LEFT_RIGHT ||
2661 move_pattern == MV_TURNING_RIGHT_LEFT ||
2662 move_pattern == MV_TURNING_RANDOM)
2663 MovDir[x][y] = 1 << RND(4);
2664 else if (move_pattern == MV_HORIZONTAL)
2665 MovDir[x][y] = (RND(2) ? MV_LEFT : MV_RIGHT);
2666 else if (move_pattern == MV_VERTICAL)
2667 MovDir[x][y] = (RND(2) ? MV_UP : MV_DOWN);
2668 else if (move_pattern & MV_ANY_DIRECTION)
2669 MovDir[x][y] = element_info[element].move_pattern;
2670 else if (move_pattern == MV_ALONG_LEFT_SIDE ||
2671 move_pattern == MV_ALONG_RIGHT_SIDE)
2673 /* use random direction as default start direction */
2674 if (game.engine_version >= VERSION_IDENT(3,1,0,0))
2675 MovDir[x][y] = 1 << RND(4);
2677 for (i = 0; i < NUM_DIRECTIONS; i++)
2679 int x1 = x + xy[i][0];
2680 int y1 = y + xy[i][1];
2682 if (!IN_LEV_FIELD(x1, y1) || !IS_FREE(x1, y1))
2684 if (move_pattern == MV_ALONG_RIGHT_SIDE)
2685 MovDir[x][y] = direction[0][i];
2687 MovDir[x][y] = direction[1][i];
2696 MovDir[x][y] = 1 << RND(4);
2698 if (element != EL_BUG &&
2699 element != EL_SPACESHIP &&
2700 element != EL_BD_BUTTERFLY &&
2701 element != EL_BD_FIREFLY)
2704 for (i = 0; i < NUM_DIRECTIONS; i++)
2706 int x1 = x + xy[i][0];
2707 int y1 = y + xy[i][1];
2709 if (!IN_LEV_FIELD(x1, y1) || !IS_FREE(x1, y1))
2711 if (element == EL_BUG || element == EL_BD_BUTTERFLY)
2713 MovDir[x][y] = direction[0][i];
2716 else if (element == EL_SPACESHIP || element == EL_BD_FIREFLY ||
2717 element == EL_SP_SNIKSNAK || element == EL_SP_ELECTRON)
2719 MovDir[x][y] = direction[1][i];
2728 GfxDir[x][y] = MovDir[x][y];
2731 void InitAmoebaNr(int x, int y)
2734 int group_nr = AmoebeNachbarNr(x, y);
2738 for (i = 1; i < MAX_NUM_AMOEBA; i++)
2740 if (AmoebaCnt[i] == 0)
2748 AmoebaNr[x][y] = group_nr;
2749 AmoebaCnt[group_nr]++;
2750 AmoebaCnt2[group_nr]++;
2756 boolean raise_level = FALSE;
2758 if (local_player->MovPos)
2761 if (tape.auto_play) /* tape might already be stopped here */
2762 tape.auto_play_level_solved = TRUE;
2764 local_player->LevelSolved = FALSE;
2766 PlaySoundStereo(SND_GAME_WINNING, SOUND_MIDDLE);
2770 if (!tape.playing && setup.sound_loops)
2771 PlaySoundExt(SND_GAME_LEVELTIME_BONUS, SOUND_MAX_VOLUME, SOUND_MIDDLE,
2772 SND_CTRL_PLAY_LOOP);
2774 while (TimeLeft > 0)
2776 if (!tape.playing && !setup.sound_loops)
2777 PlaySoundStereo(SND_GAME_LEVELTIME_BONUS, SOUND_MIDDLE);
2779 if (TimeLeft > 100 && TimeLeft % 10 == 0)
2782 RaiseScore(level.score[SC_TIME_BONUS] * 10);
2787 RaiseScore(level.score[SC_TIME_BONUS]);
2790 DrawGameValue_Time(TimeLeft);
2798 if (!tape.playing && setup.sound_loops)
2799 StopSound(SND_GAME_LEVELTIME_BONUS);
2801 else if (level.time == 0) /* level without time limit */
2803 if (!tape.playing && setup.sound_loops)
2804 PlaySoundExt(SND_GAME_LEVELTIME_BONUS, SOUND_MAX_VOLUME, SOUND_MIDDLE,
2805 SND_CTRL_PLAY_LOOP);
2807 while (TimePlayed < 999)
2809 if (!tape.playing && !setup.sound_loops)
2810 PlaySoundStereo(SND_GAME_LEVELTIME_BONUS, SOUND_MIDDLE);
2812 if (TimePlayed < 900 && TimePlayed % 10 == 0)
2815 RaiseScore(level.score[SC_TIME_BONUS] * 10);
2820 RaiseScore(level.score[SC_TIME_BONUS]);
2823 DrawGameValue_Time(TimePlayed);
2831 if (!tape.playing && setup.sound_loops)
2832 StopSound(SND_GAME_LEVELTIME_BONUS);
2835 /* close exit door after last player */
2836 if (AllPlayersGone && ExitX >= 0 && ExitY >= 0 &&
2837 (Feld[ExitX][ExitY] == EL_EXIT_OPEN ||
2838 Feld[ExitX][ExitY] == EL_SP_EXIT_OPEN))
2840 int element = Feld[ExitX][ExitY];
2842 Feld[ExitX][ExitY] = (element == EL_EXIT_OPEN ? EL_EXIT_CLOSING :
2843 EL_SP_EXIT_CLOSING);
2845 PlayLevelSoundElementAction(ExitX, ExitY, element, ACTION_CLOSING);
2848 /* player disappears */
2849 if (ExitX >= 0 && ExitY >= 0)
2850 DrawLevelField(ExitX, ExitY);
2856 printf("::: TAPE PLAYING -> DO NOT SAVE SCORE\n");
2858 printf("::: NO TAPE PLAYING -> SAVING SCORE\n");
2864 CloseDoor(DOOR_CLOSE_1);
2869 SaveTape(tape.level_nr); /* Ask to save tape */
2872 if (level_nr == leveldir_current->handicap_level)
2874 leveldir_current->handicap_level++;
2875 SaveLevelSetup_SeriesInfo();
2878 if (level_editor_test_game)
2879 local_player->score = -1; /* no highscore when playing from editor */
2880 else if (level_nr < leveldir_current->last_level)
2881 raise_level = TRUE; /* advance to next level */
2883 if ((hi_pos = NewHiScore()) >= 0)
2885 game_status = GAME_MODE_SCORES;
2886 DrawHallOfFame(hi_pos);
2895 game_status = GAME_MODE_MAIN;
2912 LoadScore(level_nr);
2914 if (strcmp(setup.player_name, EMPTY_PLAYER_NAME) == 0 ||
2915 local_player->score < highscore[MAX_SCORE_ENTRIES - 1].Score)
2918 for (k = 0; k < MAX_SCORE_ENTRIES; k++)
2920 if (local_player->score > highscore[k].Score)
2922 /* player has made it to the hall of fame */
2924 if (k < MAX_SCORE_ENTRIES - 1)
2926 int m = MAX_SCORE_ENTRIES - 1;
2929 for (l = k; l < MAX_SCORE_ENTRIES; l++)
2930 if (!strcmp(setup.player_name, highscore[l].Name))
2932 if (m == k) /* player's new highscore overwrites his old one */
2936 for (l = m; l > k; l--)
2938 strcpy(highscore[l].Name, highscore[l - 1].Name);
2939 highscore[l].Score = highscore[l - 1].Score;
2946 strncpy(highscore[k].Name, setup.player_name, MAX_PLAYER_NAME_LEN);
2947 highscore[k].Name[MAX_PLAYER_NAME_LEN] = '\0';
2948 highscore[k].Score = local_player->score;
2954 else if (!strncmp(setup.player_name, highscore[k].Name,
2955 MAX_PLAYER_NAME_LEN))
2956 break; /* player already there with a higher score */
2962 SaveScore(level_nr);
2967 inline static int getElementMoveStepsize(int x, int y)
2969 int element = Feld[x][y];
2970 int direction = MovDir[x][y];
2971 int dx = (direction == MV_LEFT ? -1 : direction == MV_RIGHT ? +1 : 0);
2972 int dy = (direction == MV_UP ? -1 : direction == MV_DOWN ? +1 : 0);
2973 int horiz_move = (dx != 0);
2974 int sign = (horiz_move ? dx : dy);
2975 int step = sign * element_info[element].move_stepsize;
2977 /* special values for move stepsize for spring and things on conveyor belt */
2981 if (element == EL_SPRING)
2982 step = sign * MOVE_STEPSIZE_NORMAL * 2;
2983 else if (CAN_FALL(element) && !CAN_MOVE(element) &&
2984 y < lev_fieldy - 1 && IS_BELT_ACTIVE(Feld[x][y + 1]))
2985 step = sign * MOVE_STEPSIZE_NORMAL / 2;
2987 if (CAN_FALL(element) &&
2988 y < lev_fieldy - 1 && IS_BELT_ACTIVE(Feld[x][y + 1]))
2989 step = sign * MOVE_STEPSIZE_NORMAL / 2;
2990 else if (element == EL_SPRING)
2991 step = sign * MOVE_STEPSIZE_NORMAL * 2;
2998 void InitPlayerGfxAnimation(struct PlayerInfo *player, int action, int dir)
3000 if (player->GfxAction != action || player->GfxDir != dir)
3003 printf("Player frame reset! (%d => %d, %d => %d)\n",
3004 player->GfxAction, action, player->GfxDir, dir);
3007 player->GfxAction = action;
3008 player->GfxDir = dir;
3010 player->StepFrame = 0;
3014 static void ResetRandomAnimationValue(int x, int y)
3016 GfxRandom[x][y] = INIT_GFX_RANDOM();
3019 static void ResetGfxAnimation(int x, int y)
3022 int element, graphic;
3026 GfxAction[x][y] = ACTION_DEFAULT;
3027 GfxDir[x][y] = MovDir[x][y];
3030 element = Feld[x][y];
3031 graphic = el_act_dir2img(element, GfxAction[x][y], GfxDir[x][y]);
3033 if (graphic_info[graphic].anim_global_sync)
3034 GfxFrame[x][y] = FrameCounter;
3035 else if (ANIM_MODE(graphic) == ANIM_CE_VALUE)
3036 GfxFrame[x][y] = CustomValue[x][y];
3037 else if (ANIM_MODE(graphic) == ANIM_CE_SCORE)
3038 GfxFrame[x][y] = element_info[element].collect_score;
3042 void InitMovingField(int x, int y, int direction)
3044 int element = Feld[x][y];
3048 int dx = (direction == MV_LEFT ? -1 : direction == MV_RIGHT ? +1 : 0);
3049 int dy = (direction == MV_UP ? -1 : direction == MV_DOWN ? +1 : 0);
3053 if (!WasJustMoving[x][y] || direction != MovDir[x][y])
3054 ResetGfxAnimation(x, y);
3056 MovDir[x][y] = direction;
3057 GfxDir[x][y] = direction;
3058 GfxAction[x][y] = (direction == MV_DOWN && CAN_FALL(element) ?
3059 ACTION_FALLING : ACTION_MOVING);
3062 graphic = el_act_dir2img(element, GfxAction[x][y], GfxDir[x][y]);
3064 if (graphic_info[graphic].anim_global_sync)
3065 GfxFrame[x][y] = FrameCounter;
3066 else if (ANIM_MODE(graphic) == ANIM_CE_VALUE)
3067 GfxFrame[x][y] = CustomValue[x][y];
3068 else if (ANIM_MODE(graphic) == ANIM_CE_SCORE)
3069 GfxFrame[x][y] = element_info[element].collect_score;
3072 /* this is needed for CEs with property "can move" / "not moving" */
3074 if (getElementMoveStepsize(x, y) != 0) /* moving or being moved */
3076 if (Feld[newx][newy] == EL_EMPTY)
3077 Feld[newx][newy] = EL_BLOCKED;
3079 MovDir[newx][newy] = MovDir[x][y];
3081 #if USE_NEW_CUSTOM_VALUE
3082 CustomValue[newx][newy] = CustomValue[x][y];
3085 GfxFrame[newx][newy] = GfxFrame[x][y];
3086 GfxRandom[newx][newy] = GfxRandom[x][y];
3087 GfxAction[newx][newy] = GfxAction[x][y];
3088 GfxDir[newx][newy] = GfxDir[x][y];
3092 void Moving2Blocked(int x, int y, int *goes_to_x, int *goes_to_y)
3094 int direction = MovDir[x][y];
3096 int newx = x + (direction & MV_LEFT ? -1 : direction & MV_RIGHT ? +1 : 0);
3097 int newy = y + (direction & MV_UP ? -1 : direction & MV_DOWN ? +1 : 0);
3099 int newx = x + (direction == MV_LEFT ? -1 : direction == MV_RIGHT ? +1 : 0);
3100 int newy = y + (direction == MV_UP ? -1 : direction == MV_DOWN ? +1 : 0);
3107 void Blocked2Moving(int x, int y, int *comes_from_x, int *comes_from_y)
3109 int oldx = x, oldy = y;
3110 int direction = MovDir[x][y];
3112 if (direction == MV_LEFT)
3114 else if (direction == MV_RIGHT)
3116 else if (direction == MV_UP)
3118 else if (direction == MV_DOWN)
3121 *comes_from_x = oldx;
3122 *comes_from_y = oldy;
3125 int MovingOrBlocked2Element(int x, int y)
3127 int element = Feld[x][y];
3129 if (element == EL_BLOCKED)
3133 Blocked2Moving(x, y, &oldx, &oldy);
3134 return Feld[oldx][oldy];
3140 static int MovingOrBlocked2ElementIfNotLeaving(int x, int y)
3142 /* like MovingOrBlocked2Element(), but if element is moving
3143 and (x,y) is the field the moving element is just leaving,
3144 return EL_BLOCKED instead of the element value */
3145 int element = Feld[x][y];
3147 if (IS_MOVING(x, y))
3149 if (element == EL_BLOCKED)
3153 Blocked2Moving(x, y, &oldx, &oldy);
3154 return Feld[oldx][oldy];
3163 static void RemoveField(int x, int y)
3165 Feld[x][y] = EL_EMPTY;
3171 #if USE_NEW_CUSTOM_VALUE
3172 CustomValue[x][y] = 0;
3176 ChangeDelay[x][y] = 0;
3177 ChangePage[x][y] = -1;
3178 Pushed[x][y] = FALSE;
3181 ExplodeField[x][y] = EX_TYPE_NONE;
3184 GfxElement[x][y] = EL_UNDEFINED;
3185 GfxAction[x][y] = ACTION_DEFAULT;
3186 GfxDir[x][y] = MV_NONE;
3189 void RemoveMovingField(int x, int y)
3191 int oldx = x, oldy = y, newx = x, newy = y;
3192 int element = Feld[x][y];
3193 int next_element = EL_UNDEFINED;
3195 if (element != EL_BLOCKED && !IS_MOVING(x, y))
3198 if (IS_MOVING(x, y))
3200 Moving2Blocked(x, y, &newx, &newy);
3202 if (Feld[newx][newy] != EL_BLOCKED)
3204 /* element is moving, but target field is not free (blocked), but
3205 already occupied by something different (example: acid pool);
3206 in this case, only remove the moving field, but not the target */
3208 RemoveField(oldx, oldy);
3210 Store[oldx][oldy] = Store2[oldx][oldy] = 0;
3212 DrawLevelField(oldx, oldy);
3217 else if (element == EL_BLOCKED)
3219 Blocked2Moving(x, y, &oldx, &oldy);
3220 if (!IS_MOVING(oldx, oldy))
3224 if (element == EL_BLOCKED &&
3225 (Feld[oldx][oldy] == EL_QUICKSAND_EMPTYING ||
3226 Feld[oldx][oldy] == EL_MAGIC_WALL_EMPTYING ||
3227 Feld[oldx][oldy] == EL_BD_MAGIC_WALL_EMPTYING ||
3228 Feld[oldx][oldy] == EL_AMOEBA_DROPPING))
3229 next_element = get_next_element(Feld[oldx][oldy]);
3231 RemoveField(oldx, oldy);
3232 RemoveField(newx, newy);
3234 Store[oldx][oldy] = Store2[oldx][oldy] = 0;
3236 if (next_element != EL_UNDEFINED)
3237 Feld[oldx][oldy] = next_element;
3239 DrawLevelField(oldx, oldy);
3240 DrawLevelField(newx, newy);
3243 void DrawDynamite(int x, int y)
3245 int sx = SCREENX(x), sy = SCREENY(y);
3246 int graphic = el2img(Feld[x][y]);
3249 if (!IN_SCR_FIELD(sx, sy) || IS_PLAYER(x, y))
3252 if (IS_WALKABLE_INSIDE(Back[x][y]))
3256 DrawGraphic(sx, sy, el2img(Back[x][y]), 0);
3257 else if (Store[x][y])
3258 DrawGraphic(sx, sy, el2img(Store[x][y]), 0);
3260 frame = getGraphicAnimationFrame(graphic, GfxFrame[x][y]);
3262 if (Back[x][y] || Store[x][y])
3263 DrawGraphicThruMask(sx, sy, graphic, frame);
3265 DrawGraphic(sx, sy, graphic, frame);
3268 void CheckDynamite(int x, int y)
3270 if (MovDelay[x][y] != 0) /* dynamite is still waiting to explode */
3274 if (MovDelay[x][y] != 0)
3277 PlayLevelSoundActionIfLoop(x, y, ACTION_ACTIVE);
3283 StopLevelSoundActionIfLoop(x, y, ACTION_ACTIVE);
3290 static void setMinimalPlayerBoundaries(int *sx1, int *sy1, int *sx2, int *sy2)
3292 boolean num_checked_players = 0;
3295 for (i = 0; i < MAX_PLAYERS; i++)
3297 if (stored_player[i].active)
3299 int sx = stored_player[i].jx;
3300 int sy = stored_player[i].jy;
3302 if (num_checked_players == 0)
3309 *sx1 = MIN(*sx1, sx);
3310 *sy1 = MIN(*sy1, sy);
3311 *sx2 = MAX(*sx2, sx);
3312 *sy2 = MAX(*sy2, sy);
3315 num_checked_players++;
3320 static boolean checkIfAllPlayersFitToScreen_RND()
3322 int sx1 = 0, sy1 = 0, sx2 = 0, sy2 = 0;
3324 setMinimalPlayerBoundaries(&sx1, &sy1, &sx2, &sy2);
3326 return (sx2 - sx1 < SCR_FIELDX &&
3327 sy2 - sy1 < SCR_FIELDY);
3330 static void setScreenCenteredToAllPlayers(int *sx, int *sy)
3332 int sx1 = scroll_x, sy1 = scroll_y, sx2 = scroll_x, sy2 = scroll_y;
3334 setMinimalPlayerBoundaries(&sx1, &sy1, &sx2, &sy2);
3336 *sx = (sx1 + sx2) / 2;
3337 *sy = (sy1 + sy2) / 2;
3341 static void setMaxCenterDistanceForAllPlayers(int *max_dx, int *max_dy,
3342 int center_x, int center_y)
3344 int sx1 = center_x, sy1 = center_y, sx2 = center_x, sy2 = center_y;
3346 setMinimalPlayerBoundaries(&sx1, &sy1, &sx2, &sy2);
3348 *max_dx = MAX(ABS(sx1 - center_x), ABS(sx2 - center_x));
3349 *max_dy = MAX(ABS(sy1 - center_y), ABS(sy2 - center_y));
3352 static boolean checkIfAllPlayersAreVisible(int center_x, int center_y)
3356 setMaxCenterDistanceForAllPlayers(&max_dx, &max_dy, center_x, center_y);
3358 return (max_dx <= SCR_FIELDX / 2 &&
3359 max_dy <= SCR_FIELDY / 2);
3367 void DrawRelocateScreen(int x, int y, int move_dir, boolean center_screen,
3368 boolean quick_relocation)
3370 boolean ffwd_delay = (tape.playing && tape.fast_forward);
3371 boolean no_delay = (tape.warp_forward);
3372 int frame_delay_value = (ffwd_delay ? FfwdFrameDelay : GameFrameDelay);
3373 int wait_delay_value = (no_delay ? 0 : frame_delay_value);
3375 if (quick_relocation)
3377 int offset = (setup.scroll_delay ? 3 : 0);
3384 if (!IN_VIS_FIELD(SCREENX(x), SCREENY(y)) || center_screen)
3386 scroll_x = (x < SBX_Left + MIDPOSX ? SBX_Left :
3387 x > SBX_Right + MIDPOSX ? SBX_Right :
3390 scroll_y = (y < SBY_Upper + MIDPOSY ? SBY_Upper :
3391 y > SBY_Lower + MIDPOSY ? SBY_Lower :
3396 if ((move_dir == MV_LEFT && scroll_x > x - MIDPOSX + offset) ||
3397 (move_dir == MV_RIGHT && scroll_x < x - MIDPOSX - offset))
3398 scroll_x = x - MIDPOSX + (scroll_x < x - MIDPOSX ? -offset : +offset);
3400 if ((move_dir == MV_UP && scroll_y > y - MIDPOSY + offset) ||
3401 (move_dir == MV_DOWN && scroll_y < y - MIDPOSY - offset))
3402 scroll_y = y - MIDPOSY + (scroll_y < y - MIDPOSY ? -offset : +offset);
3404 /* don't scroll over playfield boundaries */
3405 if (scroll_x < SBX_Left || scroll_x > SBX_Right)
3406 scroll_x = (scroll_x < SBX_Left ? SBX_Left : SBX_Right);
3408 /* don't scroll over playfield boundaries */
3409 if (scroll_y < SBY_Upper || scroll_y > SBY_Lower)
3410 scroll_y = (scroll_y < SBY_Upper ? SBY_Upper : SBY_Lower);
3413 RedrawPlayfield(TRUE, 0,0,0,0);
3417 int scroll_xx = (x < SBX_Left + MIDPOSX ? SBX_Left :
3418 x > SBX_Right + MIDPOSX ? SBX_Right :
3421 int scroll_yy = (y < SBY_Upper + MIDPOSY ? SBY_Upper :
3422 y > SBY_Lower + MIDPOSY ? SBY_Lower :
3425 ScrollScreen(NULL, SCROLL_GO_ON); /* scroll last frame to full tile */
3427 while (scroll_x != scroll_xx || scroll_y != scroll_yy)
3430 int fx = FX, fy = FY;
3432 dx = (scroll_xx < scroll_x ? +1 : scroll_xx > scroll_x ? -1 : 0);
3433 dy = (scroll_yy < scroll_y ? +1 : scroll_yy > scroll_y ? -1 : 0);
3435 if (dx == 0 && dy == 0) /* no scrolling needed at all */
3441 fx += dx * TILEX / 2;
3442 fy += dy * TILEY / 2;
3444 ScrollLevel(dx, dy);
3447 /* scroll in two steps of half tile size to make things smoother */
3448 BlitBitmap(drawto_field, window, fx, fy, SXSIZE, SYSIZE, SX, SY);
3450 Delay(wait_delay_value);
3452 /* scroll second step to align at full tile size */
3454 Delay(wait_delay_value);
3459 Delay(wait_delay_value);
3465 void DrawRelocatePlayer(struct PlayerInfo *player, boolean quick_relocation)
3467 boolean ffwd_delay = (tape.playing && tape.fast_forward);
3468 boolean no_delay = (tape.warp_forward);
3469 int frame_delay_value = (ffwd_delay ? FfwdFrameDelay : GameFrameDelay);
3470 int wait_delay_value = (no_delay ? 0 : frame_delay_value);
3471 int jx = player->jx;
3472 int jy = player->jy;
3474 if (quick_relocation)
3476 int offset = (setup.scroll_delay ? 3 : 0);
3478 if (!IN_VIS_FIELD(SCREENX(jx), SCREENY(jy)))
3480 scroll_x = (player->jx < SBX_Left + MIDPOSX ? SBX_Left :
3481 player->jx > SBX_Right + MIDPOSX ? SBX_Right :
3482 player->jx - MIDPOSX);
3484 scroll_y = (player->jy < SBY_Upper + MIDPOSY ? SBY_Upper :
3485 player->jy > SBY_Lower + MIDPOSY ? SBY_Lower :
3486 player->jy - MIDPOSY);
3490 if ((player->MovDir == MV_LEFT && scroll_x > jx - MIDPOSX + offset) ||
3491 (player->MovDir == MV_RIGHT && scroll_x < jx - MIDPOSX - offset))
3492 scroll_x = jx - MIDPOSX + (scroll_x < jx-MIDPOSX ? -offset : +offset);
3494 if ((player->MovDir == MV_UP && scroll_y > jy - MIDPOSY + offset) ||
3495 (player->MovDir == MV_DOWN && scroll_y < jy - MIDPOSY - offset))
3496 scroll_y = jy - MIDPOSY + (scroll_y < jy-MIDPOSY ? -offset : +offset);
3498 /* don't scroll over playfield boundaries */
3499 if (scroll_x < SBX_Left || scroll_x > SBX_Right)
3500 scroll_x = (scroll_x < SBX_Left ? SBX_Left : SBX_Right);
3502 /* don't scroll over playfield boundaries */
3503 if (scroll_y < SBY_Upper || scroll_y > SBY_Lower)
3504 scroll_y = (scroll_y < SBY_Upper ? SBY_Upper : SBY_Lower);
3507 RedrawPlayfield(TRUE, 0,0,0,0);
3511 int scroll_xx = (player->jx < SBX_Left + MIDPOSX ? SBX_Left :
3512 player->jx > SBX_Right + MIDPOSX ? SBX_Right :
3513 player->jx - MIDPOSX);
3515 int scroll_yy = (player->jy < SBY_Upper + MIDPOSY ? SBY_Upper :
3516 player->jy > SBY_Lower + MIDPOSY ? SBY_Lower :
3517 player->jy - MIDPOSY);
3519 ScrollScreen(NULL, SCROLL_GO_ON); /* scroll last frame to full tile */
3521 while (scroll_x != scroll_xx || scroll_y != scroll_yy)
3524 int fx = FX, fy = FY;
3526 dx = (scroll_xx < scroll_x ? +1 : scroll_xx > scroll_x ? -1 : 0);
3527 dy = (scroll_yy < scroll_y ? +1 : scroll_yy > scroll_y ? -1 : 0);
3529 if (dx == 0 && dy == 0) /* no scrolling needed at all */
3535 fx += dx * TILEX / 2;
3536 fy += dy * TILEY / 2;
3538 ScrollLevel(dx, dy);
3541 /* scroll in two steps of half tile size to make things smoother */
3542 BlitBitmap(drawto_field, window, fx, fy, SXSIZE, SYSIZE, SX, SY);
3544 Delay(wait_delay_value);
3546 /* scroll second step to align at full tile size */
3548 Delay(wait_delay_value);
3553 Delay(wait_delay_value);
3559 void RelocatePlayer(int jx, int jy, int el_player_raw)
3561 int el_player = GET_PLAYER_ELEMENT(el_player_raw);
3562 int player_nr = GET_PLAYER_NR(el_player);
3563 struct PlayerInfo *player = &stored_player[player_nr];
3564 boolean ffwd_delay = (tape.playing && tape.fast_forward);
3565 boolean no_delay = (tape.warp_forward);
3566 int frame_delay_value = (ffwd_delay ? FfwdFrameDelay : GameFrameDelay);
3567 int wait_delay_value = (no_delay ? 0 : frame_delay_value);
3568 int old_jx = player->jx;
3569 int old_jy = player->jy;
3570 int old_element = Feld[old_jx][old_jy];
3571 int element = Feld[jx][jy];
3572 boolean player_relocated = (old_jx != jx || old_jy != jy);
3574 int move_dir_horiz = (jx < old_jx ? MV_LEFT : jx > old_jx ? MV_RIGHT : 0);
3575 int move_dir_vert = (jy < old_jy ? MV_UP : jy > old_jy ? MV_DOWN : 0);
3576 int enter_side_horiz = MV_DIR_OPPOSITE(move_dir_horiz);
3577 int enter_side_vert = MV_DIR_OPPOSITE(move_dir_vert);
3578 int leave_side_horiz = move_dir_horiz;
3579 int leave_side_vert = move_dir_vert;
3580 int enter_side = enter_side_horiz | enter_side_vert;
3581 int leave_side = leave_side_horiz | leave_side_vert;
3583 if (player->GameOver) /* do not reanimate dead player */
3586 if (!player_relocated) /* no need to relocate the player */
3589 if (IS_PLAYER(jx, jy)) /* player already placed at new position */
3591 RemoveField(jx, jy); /* temporarily remove newly placed player */
3592 DrawLevelField(jx, jy);
3595 if (player->present)
3597 while (player->MovPos)
3599 ScrollPlayer(player, SCROLL_GO_ON);
3600 ScrollScreen(NULL, SCROLL_GO_ON);
3602 AdvanceFrameAndPlayerCounters(player->index_nr);
3607 Delay(wait_delay_value);
3610 DrawPlayer(player); /* needed here only to cleanup last field */
3611 DrawLevelField(player->jx, player->jy); /* remove player graphic */
3613 player->is_moving = FALSE;
3616 if (IS_CUSTOM_ELEMENT(old_element))
3617 CheckElementChangeByPlayer(old_jx, old_jy, old_element,
3619 player->index_bit, leave_side);
3621 CheckTriggeredElementChangeByPlayer(old_jx, old_jy, old_element,
3623 player->index_bit, leave_side);
3625 Feld[jx][jy] = el_player;
3626 InitPlayerField(jx, jy, el_player, TRUE);
3628 if (!ELEM_IS_PLAYER(element)) /* player may be set on walkable element */
3630 Feld[jx][jy] = element;
3631 InitField(jx, jy, FALSE);
3635 /* only visually relocate centered player */
3637 DrawRelocateScreen(player->jx, player->jy, player->MovDir, FALSE,
3638 level.instant_relocation);
3640 if (player->index_nr == game.centered_player_nr)
3641 DrawRelocatePlayer(player, level.instant_relocation);
3644 if (player == local_player) /* only visually relocate local player */
3645 DrawRelocatePlayer(player, level.instant_relocation);
3648 TestIfPlayerTouchesBadThing(jx, jy);
3649 TestIfPlayerTouchesCustomElement(jx, jy);
3651 if (IS_CUSTOM_ELEMENT(element))
3652 CheckElementChangeByPlayer(jx, jy, element, CE_ENTERED_BY_PLAYER,
3653 player->index_bit, enter_side);
3655 CheckTriggeredElementChangeByPlayer(jx, jy, element, CE_PLAYER_ENTERS_X,
3656 player->index_bit, enter_side);
3659 void Explode(int ex, int ey, int phase, int mode)
3665 /* !!! eliminate this variable !!! */
3666 int delay = (game.emulation == EMU_SUPAPLEX ? 3 : 2);
3668 if (game.explosions_delayed)
3670 ExplodeField[ex][ey] = mode;
3674 if (phase == EX_PHASE_START) /* initialize 'Store[][]' field */
3676 int center_element = Feld[ex][ey];
3677 int artwork_element, explosion_element; /* set these values later */
3680 /* --- This is only really needed (and now handled) in "Impact()". --- */
3681 /* do not explode moving elements that left the explode field in time */
3682 if (game.engine_version >= VERSION_IDENT(2,2,0,7) &&
3683 center_element == EL_EMPTY &&
3684 (mode == EX_TYPE_NORMAL || mode == EX_TYPE_CENTER))
3689 /* !!! at this place, the center element may be EL_BLOCKED !!! */
3690 if (mode == EX_TYPE_NORMAL ||
3691 mode == EX_TYPE_CENTER ||
3692 mode == EX_TYPE_CROSS)
3693 PlayLevelSoundElementAction(ex, ey, artwork_element, ACTION_EXPLODING);
3696 /* remove things displayed in background while burning dynamite */
3697 if (Back[ex][ey] != EL_EMPTY && !IS_INDESTRUCTIBLE(Back[ex][ey]))
3700 if (IS_MOVING(ex, ey) || IS_BLOCKED(ex, ey))
3702 /* put moving element to center field (and let it explode there) */
3703 center_element = MovingOrBlocked2Element(ex, ey);
3704 RemoveMovingField(ex, ey);
3705 Feld[ex][ey] = center_element;
3708 /* now "center_element" is finally determined -- set related values now */
3709 artwork_element = center_element; /* for custom player artwork */
3710 explosion_element = center_element; /* for custom player artwork */
3712 if (IS_PLAYER(ex, ey))
3714 int player_nr = GET_PLAYER_NR(StorePlayer[ex][ey]);
3716 artwork_element = stored_player[player_nr].artwork_element;
3718 if (level.use_explosion_element[player_nr])
3720 explosion_element = level.explosion_element[player_nr];
3721 artwork_element = explosion_element;
3726 if (mode == EX_TYPE_NORMAL ||
3727 mode == EX_TYPE_CENTER ||
3728 mode == EX_TYPE_CROSS)
3729 PlayLevelSoundElementAction(ex, ey, artwork_element, ACTION_EXPLODING);
3733 last_phase = element_info[explosion_element].explosion_delay + 1;
3735 last_phase = element_info[center_element].explosion_delay + 1;
3738 for (y = ey - 1; y <= ey + 1; y++) for (x = ex - 1; x <= ex + 1; x++)
3740 int xx = x - ex + 1;
3741 int yy = y - ey + 1;
3744 if (!IN_LEV_FIELD(x, y) ||
3745 (mode & EX_TYPE_SINGLE_TILE && (x != ex || y != ey)) ||
3746 (mode == EX_TYPE_CROSS && (x != ex && y != ey)))
3749 element = Feld[x][y];
3751 if (IS_MOVING(x, y) || IS_BLOCKED(x, y))
3753 element = MovingOrBlocked2Element(x, y);
3755 if (!IS_EXPLOSION_PROOF(element))
3756 RemoveMovingField(x, y);
3759 /* indestructible elements can only explode in center (but not flames) */
3760 if ((IS_EXPLOSION_PROOF(element) && (x != ex || y != ey ||
3761 mode == EX_TYPE_BORDER)) ||
3762 element == EL_FLAMES)
3765 /* no idea why this was changed from 3.0.8 to 3.1.0 -- this causes buggy
3766 behaviour, for example when touching a yamyam that explodes to rocks
3767 with active deadly shield, a rock is created under the player !!! */
3768 /* (case 1 (surely buggy): >= 3.1.0, case 2 (maybe buggy): <= 3.0.8) */
3770 if (IS_PLAYER(x, y) && SHIELD_ON(PLAYERINFO(x, y)) &&
3771 (game.engine_version < VERSION_IDENT(3,1,0,0) ||
3772 (x == ex && y == ey && mode != EX_TYPE_BORDER)))
3774 if (IS_PLAYER(x, y) && SHIELD_ON(PLAYERINFO(x, y)))
3777 if (IS_ACTIVE_BOMB(element))
3779 /* re-activate things under the bomb like gate or penguin */
3780 Feld[x][y] = (Back[x][y] ? Back[x][y] : EL_EMPTY);
3787 /* save walkable background elements while explosion on same tile */
3788 if (IS_WALKABLE(element) && IS_INDESTRUCTIBLE(element) &&
3789 (x != ex || y != ey || mode == EX_TYPE_BORDER))
3790 Back[x][y] = element;
3792 /* ignite explodable elements reached by other explosion */
3793 if (element == EL_EXPLOSION)
3794 element = Store2[x][y];
3796 if (AmoebaNr[x][y] &&
3797 (element == EL_AMOEBA_FULL ||
3798 element == EL_BD_AMOEBA ||
3799 element == EL_AMOEBA_GROWING))
3801 AmoebaCnt[AmoebaNr[x][y]]--;
3802 AmoebaCnt2[AmoebaNr[x][y]]--;
3807 if (IS_PLAYER(ex, ey) && !PLAYER_EXPLOSION_PROTECTED(ex, ey))
3810 int player_nr = StorePlayer[ex][ey] - EL_PLAYER_1;
3812 Store[x][y] = EL_PLAYER_IS_EXPLODING_1 + player_nr;
3814 switch(StorePlayer[ex][ey])
3817 Store[x][y] = EL_PLAYER_IS_EXPLODING_2;
3820 Store[x][y] = EL_PLAYER_IS_EXPLODING_3;
3823 Store[x][y] = EL_PLAYER_IS_EXPLODING_4;
3827 Store[x][y] = EL_PLAYER_IS_EXPLODING_1;
3832 if (PLAYERINFO(ex, ey)->use_murphy)
3833 Store[x][y] = EL_EMPTY;
3836 /* !!! check this case -- currently needed for rnd_rado_negundo_v,
3837 !!! levels 015 018 019 020 021 022 023 026 027 028 !!! */
3838 else if (ELEM_IS_PLAYER(center_element))
3839 Store[x][y] = EL_EMPTY;
3840 else if (center_element == EL_YAMYAM)
3841 Store[x][y] = level.yamyam_content[game.yamyam_content_nr].e[xx][yy];
3842 else if (element_info[center_element].content.e[xx][yy] != EL_EMPTY)
3843 Store[x][y] = element_info[center_element].content.e[xx][yy];
3845 /* needed because EL_BD_BUTTERFLY is not defined as "CAN_EXPLODE"
3846 (killing EL_BD_BUTTERFLY with dynamite would result in BD diamond
3847 otherwise) -- FIX THIS !!! */
3848 else if (!CAN_EXPLODE(element) && element != EL_BD_BUTTERFLY)
3849 Store[x][y] = element_info[element].content.e[1][1];
3851 else if (!CAN_EXPLODE(element))
3852 Store[x][y] = element_info[element].content.e[1][1];
3855 Store[x][y] = EL_EMPTY;
3857 else if (center_element == EL_MOLE)
3858 Store[x][y] = EL_EMERALD_RED;
3859 else if (center_element == EL_PENGUIN)
3860 Store[x][y] = EL_EMERALD_PURPLE;
3861 else if (center_element == EL_BUG)
3862 Store[x][y] = ((x == ex && y == ey) ? EL_DIAMOND : EL_EMERALD);
3863 else if (center_element == EL_BD_BUTTERFLY)
3864 Store[x][y] = EL_BD_DIAMOND;
3865 else if (center_element == EL_SP_ELECTRON)
3866 Store[x][y] = EL_SP_INFOTRON;
3867 else if (center_element == EL_AMOEBA_TO_DIAMOND)
3868 Store[x][y] = level.amoeba_content;
3869 else if (center_element == EL_YAMYAM)
3870 Store[x][y] = level.yamyam_content[game.yamyam_content_nr].e[xx][yy];
3871 else if (IS_CUSTOM_ELEMENT(center_element) &&
3872 element_info[center_element].content.e[xx][yy] != EL_EMPTY)
3873 Store[x][y] = element_info[center_element].content.e[xx][yy];
3874 else if (element == EL_WALL_EMERALD)
3875 Store[x][y] = EL_EMERALD;
3876 else if (element == EL_WALL_DIAMOND)
3877 Store[x][y] = EL_DIAMOND;
3878 else if (element == EL_WALL_BD_DIAMOND)
3879 Store[x][y] = EL_BD_DIAMOND;
3880 else if (element == EL_WALL_EMERALD_YELLOW)
3881 Store[x][y] = EL_EMERALD_YELLOW;
3882 else if (element == EL_WALL_EMERALD_RED)
3883 Store[x][y] = EL_EMERALD_RED;
3884 else if (element == EL_WALL_EMERALD_PURPLE)
3885 Store[x][y] = EL_EMERALD_PURPLE;
3886 else if (element == EL_WALL_PEARL)
3887 Store[x][y] = EL_PEARL;
3888 else if (element == EL_WALL_CRYSTAL)
3889 Store[x][y] = EL_CRYSTAL;
3890 else if (IS_CUSTOM_ELEMENT(element) && !CAN_EXPLODE(element))
3891 Store[x][y] = element_info[element].content.e[1][1];
3893 Store[x][y] = EL_EMPTY;
3896 if (x != ex || y != ey || mode == EX_TYPE_BORDER ||
3897 center_element == EL_AMOEBA_TO_DIAMOND)
3898 Store2[x][y] = element;
3900 Feld[x][y] = EL_EXPLOSION;
3901 GfxElement[x][y] = artwork_element;
3904 printf(":: setting gfx(%d,%d) to %d ['%s']\n",
3905 x, y, artwork_element, EL_NAME(artwork_element));
3908 ExplodePhase[x][y] = 1;
3909 ExplodeDelay[x][y] = last_phase;
3914 if (center_element == EL_YAMYAM)
3915 game.yamyam_content_nr =
3916 (game.yamyam_content_nr + 1) % level.num_yamyam_contents;
3928 GfxFrame[x][y] = 0; /* restart explosion animation */
3930 last_phase = ExplodeDelay[x][y];
3932 ExplodePhase[x][y] = (phase < last_phase ? phase + 1 : 0);
3936 /* activate this even in non-DEBUG version until cause for crash in
3937 getGraphicAnimationFrame() (see below) is found and eliminated */
3943 /* this can happen if the player leaves an explosion just in time */
3944 if (GfxElement[x][y] == EL_UNDEFINED)
3945 GfxElement[x][y] = EL_EMPTY;
3947 if (GfxElement[x][y] == EL_UNDEFINED)
3950 printf("Explode(): x = %d, y = %d: GfxElement == EL_UNDEFINED\n", x, y);
3951 printf("Explode(): This should never happen!\n");
3954 GfxElement[x][y] = EL_EMPTY;
3960 border_element = Store2[x][y];
3961 if (IS_PLAYER(x, y) && !PLAYER_EXPLOSION_PROTECTED(x, y))
3962 border_element = StorePlayer[x][y];
3964 if (phase == element_info[border_element].ignition_delay ||
3965 phase == last_phase)
3967 boolean border_explosion = FALSE;
3969 if (IS_PLAYER(x, y) && PLAYERINFO(x, y)->present &&
3970 !PLAYER_EXPLOSION_PROTECTED(x, y))
3972 KillPlayerUnlessExplosionProtected(x, y);
3973 border_explosion = TRUE;
3975 else if (CAN_EXPLODE_BY_EXPLOSION(border_element))
3977 Feld[x][y] = Store2[x][y];
3980 border_explosion = TRUE;
3982 else if (border_element == EL_AMOEBA_TO_DIAMOND)
3984 AmoebeUmwandeln(x, y);
3986 border_explosion = TRUE;
3989 /* if an element just explodes due to another explosion (chain-reaction),
3990 do not immediately end the new explosion when it was the last frame of
3991 the explosion (as it would be done in the following "if"-statement!) */
3992 if (border_explosion && phase == last_phase)
3996 if (phase == last_phase)
4000 element = Feld[x][y] = Store[x][y];
4001 Store[x][y] = Store2[x][y] = 0;
4002 GfxElement[x][y] = EL_UNDEFINED;
4004 /* player can escape from explosions and might therefore be still alive */
4005 if (element >= EL_PLAYER_IS_EXPLODING_1 &&
4006 element <= EL_PLAYER_IS_EXPLODING_4)
4008 int player_nr = element - EL_PLAYER_IS_EXPLODING_1;
4009 int explosion_element = EL_PLAYER_1 + player_nr;
4010 int xx = MIN(MAX(0, x - stored_player[player_nr].jx + 1), 2);
4011 int yy = MIN(MAX(0, y - stored_player[player_nr].jy + 1), 2);
4013 if (level.use_explosion_element[player_nr])
4014 explosion_element = level.explosion_element[player_nr];
4016 Feld[x][y] = (stored_player[player_nr].active ? EL_EMPTY :
4017 element_info[explosion_element].content.e[xx][yy]);
4020 /* restore probably existing indestructible background element */
4021 if (Back[x][y] && IS_INDESTRUCTIBLE(Back[x][y]))
4022 element = Feld[x][y] = Back[x][y];
4025 MovDir[x][y] = MovPos[x][y] = MovDelay[x][y] = 0;
4026 GfxDir[x][y] = MV_NONE;
4027 ChangeDelay[x][y] = 0;
4028 ChangePage[x][y] = -1;
4030 #if USE_NEW_CUSTOM_VALUE
4031 CustomValue[x][y] = 0;
4034 InitField_WithBug2(x, y, FALSE);
4036 DrawLevelField(x, y);
4038 TestIfElementTouchesCustomElement(x, y);
4040 if (GFX_CRUMBLED(element))
4041 DrawLevelFieldCrumbledSandNeighbours(x, y);
4043 if (IS_PLAYER(x, y) && !PLAYERINFO(x, y)->present)
4044 StorePlayer[x][y] = 0;
4046 if (ELEM_IS_PLAYER(element))
4047 RelocatePlayer(x, y, element);
4049 else if (IN_SCR_FIELD(SCREENX(x), SCREENY(y)))
4051 int graphic = el_act2img(GfxElement[x][y], ACTION_EXPLODING);
4052 int frame = getGraphicAnimationFrame(graphic, GfxFrame[x][y]);
4055 DrawLevelFieldCrumbledSand(x, y);
4057 if (IS_WALKABLE_OVER(Back[x][y]) && Back[x][y] != EL_EMPTY)
4059 DrawLevelElement(x, y, Back[x][y]);
4060 DrawGraphicThruMask(SCREENX(x), SCREENY(y), graphic, frame);
4062 else if (IS_WALKABLE_UNDER(Back[x][y]))
4064 DrawGraphic(SCREENX(x), SCREENY(y), graphic, frame);
4065 DrawLevelElementThruMask(x, y, Back[x][y]);
4067 else if (!IS_WALKABLE_INSIDE(Back[x][y]))
4068 DrawGraphic(SCREENX(x), SCREENY(y), graphic, frame);
4072 void DynaExplode(int ex, int ey)
4075 int dynabomb_element = Feld[ex][ey];
4076 int dynabomb_size = 1;
4077 boolean dynabomb_xl = FALSE;
4078 struct PlayerInfo *player;
4079 static int xy[4][2] =
4087 if (IS_ACTIVE_BOMB(dynabomb_element))
4089 player = &stored_player[dynabomb_element - EL_DYNABOMB_PLAYER_1_ACTIVE];
4090 dynabomb_size = player->dynabomb_size;
4091 dynabomb_xl = player->dynabomb_xl;
4092 player->dynabombs_left++;
4095 Explode(ex, ey, EX_PHASE_START, EX_TYPE_CENTER);
4097 for (i = 0; i < NUM_DIRECTIONS; i++)
4099 for (j = 1; j <= dynabomb_size; j++)
4101 int x = ex + j * xy[i][0];
4102 int y = ey + j * xy[i][1];
4105 if (!IN_LEV_FIELD(x, y) || IS_INDESTRUCTIBLE(Feld[x][y]))
4108 element = Feld[x][y];
4110 /* do not restart explosions of fields with active bombs */
4111 if (element == EL_EXPLOSION && IS_ACTIVE_BOMB(Store2[x][y]))
4114 Explode(x, y, EX_PHASE_START, EX_TYPE_BORDER);
4116 if (element != EL_EMPTY && element != EL_EXPLOSION &&
4117 !IS_DIGGABLE(element) && !dynabomb_xl)
4123 void Bang(int x, int y)
4125 int element = MovingOrBlocked2Element(x, y);
4126 int explosion_type = EX_TYPE_NORMAL;
4128 if (IS_PLAYER(x, y) && !PLAYER_EXPLOSION_PROTECTED(x, y))
4130 struct PlayerInfo *player = PLAYERINFO(x, y);
4132 element = Feld[x][y] = (player->use_murphy ? EL_SP_MURPHY :
4133 player->element_nr);
4135 if (level.use_explosion_element[player->index_nr])
4137 int explosion_element = level.explosion_element[player->index_nr];
4139 if (element_info[explosion_element].explosion_type == EXPLODES_CROSS)
4140 explosion_type = EX_TYPE_CROSS;
4141 else if (element_info[explosion_element].explosion_type == EXPLODES_1X1)
4142 explosion_type = EX_TYPE_CENTER;
4150 case EL_BD_BUTTERFLY:
4153 case EL_DARK_YAMYAM:
4157 RaiseScoreElement(element);
4160 case EL_DYNABOMB_PLAYER_1_ACTIVE:
4161 case EL_DYNABOMB_PLAYER_2_ACTIVE:
4162 case EL_DYNABOMB_PLAYER_3_ACTIVE:
4163 case EL_DYNABOMB_PLAYER_4_ACTIVE:
4164 case EL_DYNABOMB_INCREASE_NUMBER:
4165 case EL_DYNABOMB_INCREASE_SIZE:
4166 case EL_DYNABOMB_INCREASE_POWER:
4167 explosion_type = EX_TYPE_DYNA;
4172 case EL_LAMP_ACTIVE:
4173 case EL_AMOEBA_TO_DIAMOND:
4174 if (!IS_PLAYER(x, y)) /* penguin and player may be at same field */
4175 explosion_type = EX_TYPE_CENTER;
4179 if (element_info[element].explosion_type == EXPLODES_CROSS)
4180 explosion_type = EX_TYPE_CROSS;
4181 else if (element_info[element].explosion_type == EXPLODES_1X1)
4182 explosion_type = EX_TYPE_CENTER;
4186 if (explosion_type == EX_TYPE_DYNA)
4189 Explode(x, y, EX_PHASE_START, explosion_type);
4191 CheckTriggeredElementChange(x, y, element, CE_EXPLOSION_OF_X);
4194 void SplashAcid(int x, int y)
4196 if (IN_LEV_FIELD(x - 1, y - 1) && IS_FREE(x - 1, y - 1) &&
4197 (!IN_LEV_FIELD(x - 1, y - 2) ||
4198 !CAN_FALL(MovingOrBlocked2Element(x - 1, y - 2))))
4199 Feld[x - 1][y - 1] = EL_ACID_SPLASH_LEFT;
4201 if (IN_LEV_FIELD(x + 1, y - 1) && IS_FREE(x + 1, y - 1) &&
4202 (!IN_LEV_FIELD(x + 1, y - 2) ||
4203 !CAN_FALL(MovingOrBlocked2Element(x + 1, y - 2))))
4204 Feld[x + 1][y - 1] = EL_ACID_SPLASH_RIGHT;
4206 PlayLevelSound(x, y, SND_ACID_SPLASHING);
4209 static void InitBeltMovement()
4211 static int belt_base_element[4] =
4213 EL_CONVEYOR_BELT_1_LEFT,
4214 EL_CONVEYOR_BELT_2_LEFT,
4215 EL_CONVEYOR_BELT_3_LEFT,
4216 EL_CONVEYOR_BELT_4_LEFT
4218 static int belt_base_active_element[4] =
4220 EL_CONVEYOR_BELT_1_LEFT_ACTIVE,
4221 EL_CONVEYOR_BELT_2_LEFT_ACTIVE,
4222 EL_CONVEYOR_BELT_3_LEFT_ACTIVE,
4223 EL_CONVEYOR_BELT_4_LEFT_ACTIVE
4228 /* set frame order for belt animation graphic according to belt direction */
4229 for (i = 0; i < NUM_BELTS; i++)
4233 for (j = 0; j < NUM_BELT_PARTS; j++)
4235 int element = belt_base_active_element[belt_nr] + j;
4236 int graphic = el2img(element);
4238 if (game.belt_dir[i] == MV_LEFT)
4239 graphic_info[graphic].anim_mode &= ~ANIM_REVERSE;
4241 graphic_info[graphic].anim_mode |= ANIM_REVERSE;
4246 SCAN_PLAYFIELD(x, y)
4248 for (y = 0; y < lev_fieldy; y++) for (x = 0; x < lev_fieldx; x++)
4251 int element = Feld[x][y];
4253 for (i = 0; i < NUM_BELTS; i++)
4255 if (IS_BELT(element) && game.belt_dir[i] != MV_NONE)
4257 int e_belt_nr = getBeltNrFromBeltElement(element);
4260 if (e_belt_nr == belt_nr)
4262 int belt_part = Feld[x][y] - belt_base_element[belt_nr];
4264 Feld[x][y] = belt_base_active_element[belt_nr] + belt_part;
4271 static void ToggleBeltSwitch(int x, int y)
4273 static int belt_base_element[4] =
4275 EL_CONVEYOR_BELT_1_LEFT,
4276 EL_CONVEYOR_BELT_2_LEFT,
4277 EL_CONVEYOR_BELT_3_LEFT,
4278 EL_CONVEYOR_BELT_4_LEFT
4280 static int belt_base_active_element[4] =
4282 EL_CONVEYOR_BELT_1_LEFT_ACTIVE,
4283 EL_CONVEYOR_BELT_2_LEFT_ACTIVE,
4284 EL_CONVEYOR_BELT_3_LEFT_ACTIVE,
4285 EL_CONVEYOR_BELT_4_LEFT_ACTIVE
4287 static int belt_base_switch_element[4] =
4289 EL_CONVEYOR_BELT_1_SWITCH_LEFT,
4290 EL_CONVEYOR_BELT_2_SWITCH_LEFT,
4291 EL_CONVEYOR_BELT_3_SWITCH_LEFT,
4292 EL_CONVEYOR_BELT_4_SWITCH_LEFT
4294 static int belt_move_dir[4] =
4302 int element = Feld[x][y];
4303 int belt_nr = getBeltNrFromBeltSwitchElement(element);
4304 int belt_dir_nr = (game.belt_dir_nr[belt_nr] + 1) % 4;
4305 int belt_dir = belt_move_dir[belt_dir_nr];
4308 if (!IS_BELT_SWITCH(element))
4311 game.belt_dir_nr[belt_nr] = belt_dir_nr;
4312 game.belt_dir[belt_nr] = belt_dir;
4314 if (belt_dir_nr == 3)
4317 /* set frame order for belt animation graphic according to belt direction */
4318 for (i = 0; i < NUM_BELT_PARTS; i++)
4320 int element = belt_base_active_element[belt_nr] + i;
4321 int graphic = el2img(element);
4323 if (belt_dir == MV_LEFT)
4324 graphic_info[graphic].anim_mode &= ~ANIM_REVERSE;
4326 graphic_info[graphic].anim_mode |= ANIM_REVERSE;
4330 SCAN_PLAYFIELD(xx, yy)
4332 for (yy = 0; yy < lev_fieldy; yy++) for (xx = 0; xx < lev_fieldx; xx++)
4335 int element = Feld[xx][yy];
4337 if (IS_BELT_SWITCH(element))
4339 int e_belt_nr = getBeltNrFromBeltSwitchElement(element);
4341 if (e_belt_nr == belt_nr)
4343 Feld[xx][yy] = belt_base_switch_element[belt_nr] + belt_dir_nr;
4344 DrawLevelField(xx, yy);
4347 else if (IS_BELT(element) && belt_dir != MV_NONE)
4349 int e_belt_nr = getBeltNrFromBeltElement(element);
4351 if (e_belt_nr == belt_nr)
4353 int belt_part = Feld[xx][yy] - belt_base_element[belt_nr];
4355 Feld[xx][yy] = belt_base_active_element[belt_nr] + belt_part;
4356 DrawLevelField(xx, yy);
4359 else if (IS_BELT_ACTIVE(element) && belt_dir == MV_NONE)
4361 int e_belt_nr = getBeltNrFromBeltActiveElement(element);
4363 if (e_belt_nr == belt_nr)
4365 int belt_part = Feld[xx][yy] - belt_base_active_element[belt_nr];
4367 Feld[xx][yy] = belt_base_element[belt_nr] + belt_part;
4368 DrawLevelField(xx, yy);
4374 static void ToggleSwitchgateSwitch(int x, int y)
4378 game.switchgate_pos = !game.switchgate_pos;
4381 SCAN_PLAYFIELD(xx, yy)
4383 for (yy = 0; yy < lev_fieldy; yy++) for (xx = 0; xx < lev_fieldx; xx++)
4386 int element = Feld[xx][yy];
4388 if (element == EL_SWITCHGATE_SWITCH_UP ||
4389 element == EL_SWITCHGATE_SWITCH_DOWN)
4391 Feld[xx][yy] = EL_SWITCHGATE_SWITCH_UP + game.switchgate_pos;
4392 DrawLevelField(xx, yy);
4394 else if (element == EL_SWITCHGATE_OPEN ||
4395 element == EL_SWITCHGATE_OPENING)
4397 Feld[xx][yy] = EL_SWITCHGATE_CLOSING;
4399 PlayLevelSoundAction(xx, yy, ACTION_CLOSING);
4401 else if (element == EL_SWITCHGATE_CLOSED ||
4402 element == EL_SWITCHGATE_CLOSING)
4404 Feld[xx][yy] = EL_SWITCHGATE_OPENING;
4406 PlayLevelSoundAction(xx, yy, ACTION_OPENING);
4411 static int getInvisibleActiveFromInvisibleElement(int element)
4413 return (element == EL_INVISIBLE_STEELWALL ? EL_INVISIBLE_STEELWALL_ACTIVE :
4414 element == EL_INVISIBLE_WALL ? EL_INVISIBLE_WALL_ACTIVE :
4415 element == EL_INVISIBLE_SAND ? EL_INVISIBLE_SAND_ACTIVE :
4419 static int getInvisibleFromInvisibleActiveElement(int element)
4421 return (element == EL_INVISIBLE_STEELWALL_ACTIVE ? EL_INVISIBLE_STEELWALL :
4422 element == EL_INVISIBLE_WALL_ACTIVE ? EL_INVISIBLE_WALL :
4423 element == EL_INVISIBLE_SAND_ACTIVE ? EL_INVISIBLE_SAND :
4427 static void RedrawAllLightSwitchesAndInvisibleElements()
4432 SCAN_PLAYFIELD(x, y)
4434 for (y = 0; y < lev_fieldy; y++) for (x = 0; x < lev_fieldx; x++)
4437 int element = Feld[x][y];
4439 if (element == EL_LIGHT_SWITCH &&
4440 game.light_time_left > 0)
4442 Feld[x][y] = EL_LIGHT_SWITCH_ACTIVE;
4443 DrawLevelField(x, y);
4445 else if (element == EL_LIGHT_SWITCH_ACTIVE &&
4446 game.light_time_left == 0)
4448 Feld[x][y] = EL_LIGHT_SWITCH;
4449 DrawLevelField(x, y);
4451 else if (element == EL_EMC_DRIPPER &&
4452 game.light_time_left > 0)
4454 Feld[x][y] = EL_EMC_DRIPPER_ACTIVE;
4455 DrawLevelField(x, y);
4457 else if (element == EL_EMC_DRIPPER_ACTIVE &&
4458 game.light_time_left == 0)
4460 Feld[x][y] = EL_EMC_DRIPPER;
4461 DrawLevelField(x, y);
4463 else if (element == EL_INVISIBLE_STEELWALL ||
4464 element == EL_INVISIBLE_WALL ||
4465 element == EL_INVISIBLE_SAND)
4467 if (game.light_time_left > 0)
4468 Feld[x][y] = getInvisibleActiveFromInvisibleElement(element);
4470 DrawLevelField(x, y);
4472 /* uncrumble neighbour fields, if needed */
4473 if (element == EL_INVISIBLE_SAND)
4474 DrawLevelFieldCrumbledSandNeighbours(x, y);
4476 else if (element == EL_INVISIBLE_STEELWALL_ACTIVE ||
4477 element == EL_INVISIBLE_WALL_ACTIVE ||
4478 element == EL_INVISIBLE_SAND_ACTIVE)
4480 if (game.light_time_left == 0)
4481 Feld[x][y] = getInvisibleFromInvisibleActiveElement(element);
4483 DrawLevelField(x, y);
4485 /* re-crumble neighbour fields, if needed */
4486 if (element == EL_INVISIBLE_SAND)
4487 DrawLevelFieldCrumbledSandNeighbours(x, y);
4492 static void RedrawAllInvisibleElementsForLenses()
4497 SCAN_PLAYFIELD(x, y)
4499 for (y = 0; y < lev_fieldy; y++) for (x = 0; x < lev_fieldx; x++)
4502 int element = Feld[x][y];
4504 if (element == EL_EMC_DRIPPER &&
4505 game.lenses_time_left > 0)
4507 Feld[x][y] = EL_EMC_DRIPPER_ACTIVE;
4508 DrawLevelField(x, y);
4510 else if (element == EL_EMC_DRIPPER_ACTIVE &&
4511 game.lenses_time_left == 0)
4513 Feld[x][y] = EL_EMC_DRIPPER;
4514 DrawLevelField(x, y);
4516 else if (element == EL_INVISIBLE_STEELWALL ||
4517 element == EL_INVISIBLE_WALL ||
4518 element == EL_INVISIBLE_SAND)
4520 if (game.lenses_time_left > 0)
4521 Feld[x][y] = getInvisibleActiveFromInvisibleElement(element);
4523 DrawLevelField(x, y);
4525 /* uncrumble neighbour fields, if needed */
4526 if (element == EL_INVISIBLE_SAND)
4527 DrawLevelFieldCrumbledSandNeighbours(x, y);
4529 else if (element == EL_INVISIBLE_STEELWALL_ACTIVE ||
4530 element == EL_INVISIBLE_WALL_ACTIVE ||
4531 element == EL_INVISIBLE_SAND_ACTIVE)
4533 if (game.lenses_time_left == 0)
4534 Feld[x][y] = getInvisibleFromInvisibleActiveElement(element);
4536 DrawLevelField(x, y);
4538 /* re-crumble neighbour fields, if needed */
4539 if (element == EL_INVISIBLE_SAND)
4540 DrawLevelFieldCrumbledSandNeighbours(x, y);
4545 static void RedrawAllInvisibleElementsForMagnifier()
4550 SCAN_PLAYFIELD(x, y)
4552 for (y = 0; y < lev_fieldy; y++) for (x = 0; x < lev_fieldx; x++)
4555 int element = Feld[x][y];
4557 if (element == EL_EMC_FAKE_GRASS &&
4558 game.magnify_time_left > 0)
4560 Feld[x][y] = EL_EMC_FAKE_GRASS_ACTIVE;
4561 DrawLevelField(x, y);
4563 else if (element == EL_EMC_FAKE_GRASS_ACTIVE &&
4564 game.magnify_time_left == 0)
4566 Feld[x][y] = EL_EMC_FAKE_GRASS;
4567 DrawLevelField(x, y);
4569 else if (IS_GATE_GRAY(element) &&
4570 game.magnify_time_left > 0)
4572 Feld[x][y] = (IS_RND_GATE_GRAY(element) ?
4573 element - EL_GATE_1_GRAY + EL_GATE_1_GRAY_ACTIVE :
4574 IS_EM_GATE_GRAY(element) ?
4575 element - EL_EM_GATE_1_GRAY + EL_EM_GATE_1_GRAY_ACTIVE :
4576 IS_EMC_GATE_GRAY(element) ?
4577 element - EL_EMC_GATE_5_GRAY + EL_EMC_GATE_5_GRAY_ACTIVE :
4579 DrawLevelField(x, y);
4581 else if (IS_GATE_GRAY_ACTIVE(element) &&
4582 game.magnify_time_left == 0)
4584 Feld[x][y] = (IS_RND_GATE_GRAY_ACTIVE(element) ?
4585 element - EL_GATE_1_GRAY_ACTIVE + EL_GATE_1_GRAY :
4586 IS_EM_GATE_GRAY_ACTIVE(element) ?
4587 element - EL_EM_GATE_1_GRAY_ACTIVE + EL_EM_GATE_1_GRAY :
4588 IS_EMC_GATE_GRAY_ACTIVE(element) ?
4589 element - EL_EMC_GATE_5_GRAY_ACTIVE + EL_EMC_GATE_5_GRAY :
4591 DrawLevelField(x, y);
4596 static void ToggleLightSwitch(int x, int y)
4598 int element = Feld[x][y];
4600 game.light_time_left =
4601 (element == EL_LIGHT_SWITCH ?
4602 level.time_light * FRAMES_PER_SECOND : 0);
4604 RedrawAllLightSwitchesAndInvisibleElements();
4607 static void ActivateTimegateSwitch(int x, int y)
4611 game.timegate_time_left = level.time_timegate * FRAMES_PER_SECOND;
4614 SCAN_PLAYFIELD(xx, yy)
4616 for (yy = 0; yy < lev_fieldy; yy++) for (xx = 0; xx < lev_fieldx; xx++)
4619 int element = Feld[xx][yy];
4621 if (element == EL_TIMEGATE_CLOSED ||
4622 element == EL_TIMEGATE_CLOSING)
4624 Feld[xx][yy] = EL_TIMEGATE_OPENING;
4625 PlayLevelSound(xx, yy, SND_TIMEGATE_OPENING);
4629 else if (element == EL_TIMEGATE_SWITCH_ACTIVE)
4631 Feld[xx][yy] = EL_TIMEGATE_SWITCH;
4632 DrawLevelField(xx, yy);
4638 Feld[x][y] = EL_TIMEGATE_SWITCH_ACTIVE;
4641 void Impact(int x, int y)
4643 boolean last_line = (y == lev_fieldy - 1);
4644 boolean object_hit = FALSE;
4645 boolean impact = (last_line || object_hit);
4646 int element = Feld[x][y];
4647 int smashed = EL_STEELWALL;
4649 if (!last_line) /* check if element below was hit */
4651 if (Feld[x][y + 1] == EL_PLAYER_IS_LEAVING)
4654 object_hit = (!IS_FREE(x, y + 1) && (!IS_MOVING(x, y + 1) ||
4655 MovDir[x][y + 1] != MV_DOWN ||
4656 MovPos[x][y + 1] <= TILEY / 2));
4658 /* do not smash moving elements that left the smashed field in time */
4659 if (game.engine_version >= VERSION_IDENT(2,2,0,7) && IS_MOVING(x, y + 1) &&
4660 ABS(MovPos[x][y + 1] + getElementMoveStepsize(x, y + 1)) >= TILEX)
4663 #if USE_QUICKSAND_IMPACT_BUGFIX
4664 if (Feld[x][y + 1] == EL_QUICKSAND_EMPTYING && object_hit == FALSE)
4666 RemoveMovingField(x, y + 1);
4667 Feld[x][y + 1] = EL_QUICKSAND_EMPTY;
4668 Feld[x][y + 2] = EL_ROCK;
4669 DrawLevelField(x, y + 2);
4676 smashed = MovingOrBlocked2Element(x, y + 1);
4678 impact = (last_line || object_hit);
4681 if (!last_line && smashed == EL_ACID) /* element falls into acid */
4683 SplashAcid(x, y + 1);
4687 /* !!! not sufficient for all cases -- see EL_PEARL below !!! */
4688 /* only reset graphic animation if graphic really changes after impact */
4690 el_act_dir2img(element, GfxAction[x][y], MV_DOWN) != el2img(element))
4692 ResetGfxAnimation(x, y);
4693 DrawLevelField(x, y);
4696 if (impact && CAN_EXPLODE_IMPACT(element))
4701 else if (impact && element == EL_PEARL)
4703 ResetGfxAnimation(x, y);
4705 Feld[x][y] = EL_PEARL_BREAKING;
4706 PlayLevelSound(x, y, SND_PEARL_BREAKING);
4709 else if (impact && CheckElementChange(x, y, element, smashed, CE_IMPACT))
4711 PlayLevelSoundElementAction(x, y, element, ACTION_IMPACT);
4716 if (impact && element == EL_AMOEBA_DROP)
4718 if (object_hit && IS_PLAYER(x, y + 1))
4719 KillPlayerUnlessEnemyProtected(x, y + 1);
4720 else if (object_hit && smashed == EL_PENGUIN)
4724 Feld[x][y] = EL_AMOEBA_GROWING;
4725 Store[x][y] = EL_AMOEBA_WET;
4727 ResetRandomAnimationValue(x, y);
4732 if (object_hit) /* check which object was hit */
4734 if (CAN_PASS_MAGIC_WALL(element) &&
4735 (smashed == EL_MAGIC_WALL ||
4736 smashed == EL_BD_MAGIC_WALL))
4739 int activated_magic_wall =
4740 (smashed == EL_MAGIC_WALL ? EL_MAGIC_WALL_ACTIVE :
4741 EL_BD_MAGIC_WALL_ACTIVE);
4743 /* activate magic wall / mill */
4745 SCAN_PLAYFIELD(xx, yy)
4747 for (yy = 0; yy < lev_fieldy; yy++) for (xx = 0; xx < lev_fieldx; xx++)
4749 if (Feld[xx][yy] == smashed)
4750 Feld[xx][yy] = activated_magic_wall;
4752 game.magic_wall_time_left = level.time_magic_wall * FRAMES_PER_SECOND;
4753 game.magic_wall_active = TRUE;
4755 PlayLevelSound(x, y, (smashed == EL_MAGIC_WALL ?
4756 SND_MAGIC_WALL_ACTIVATING :
4757 SND_BD_MAGIC_WALL_ACTIVATING));
4760 if (IS_PLAYER(x, y + 1))
4762 if (CAN_SMASH_PLAYER(element))
4764 KillPlayerUnlessEnemyProtected(x, y + 1);
4768 else if (smashed == EL_PENGUIN)
4770 if (CAN_SMASH_PLAYER(element))
4776 else if (element == EL_BD_DIAMOND)
4778 if (IS_CLASSIC_ENEMY(smashed) && IS_BD_ELEMENT(smashed))
4784 else if (((element == EL_SP_INFOTRON ||
4785 element == EL_SP_ZONK) &&
4786 (smashed == EL_SP_SNIKSNAK ||
4787 smashed == EL_SP_ELECTRON ||
4788 smashed == EL_SP_DISK_ORANGE)) ||
4789 (element == EL_SP_INFOTRON &&
4790 smashed == EL_SP_DISK_YELLOW))
4795 else if (CAN_SMASH_EVERYTHING(element))
4797 if (IS_CLASSIC_ENEMY(smashed) ||
4798 CAN_EXPLODE_SMASHED(smashed))
4803 else if (!IS_MOVING(x, y + 1) && !IS_BLOCKED(x, y + 1))
4805 if (smashed == EL_LAMP ||
4806 smashed == EL_LAMP_ACTIVE)
4811 else if (smashed == EL_NUT)
4813 Feld[x][y + 1] = EL_NUT_BREAKING;
4814 PlayLevelSound(x, y, SND_NUT_BREAKING);
4815 RaiseScoreElement(EL_NUT);
4818 else if (smashed == EL_PEARL)
4820 ResetGfxAnimation(x, y);
4822 Feld[x][y + 1] = EL_PEARL_BREAKING;
4823 PlayLevelSound(x, y, SND_PEARL_BREAKING);
4826 else if (smashed == EL_DIAMOND)
4828 Feld[x][y + 1] = EL_DIAMOND_BREAKING;
4829 PlayLevelSound(x, y, SND_DIAMOND_BREAKING);
4832 else if (IS_BELT_SWITCH(smashed))
4834 ToggleBeltSwitch(x, y + 1);
4836 else if (smashed == EL_SWITCHGATE_SWITCH_UP ||
4837 smashed == EL_SWITCHGATE_SWITCH_DOWN)
4839 ToggleSwitchgateSwitch(x, y + 1);
4841 else if (smashed == EL_LIGHT_SWITCH ||
4842 smashed == EL_LIGHT_SWITCH_ACTIVE)
4844 ToggleLightSwitch(x, y + 1);
4849 TestIfElementSmashesCustomElement(x, y, MV_DOWN);
4852 CheckElementChange(x, y + 1, smashed, element, CE_SMASHED);
4854 CheckElementChangeBySide(x, y + 1, smashed, element,
4855 CE_SWITCHED, CH_SIDE_TOP);
4856 CheckTriggeredElementChangeBySide(x, y + 1, smashed, CE_SWITCH_OF_X,
4862 CheckElementChange(x, y + 1, smashed, element, CE_SMASHED);
4867 /* play sound of magic wall / mill */
4869 (Feld[x][y + 1] == EL_MAGIC_WALL_ACTIVE ||
4870 Feld[x][y + 1] == EL_BD_MAGIC_WALL_ACTIVE))
4872 if (Feld[x][y + 1] == EL_MAGIC_WALL_ACTIVE)
4873 PlayLevelSound(x, y, SND_MAGIC_WALL_FILLING);
4874 else if (Feld[x][y + 1] == EL_BD_MAGIC_WALL_ACTIVE)
4875 PlayLevelSound(x, y, SND_BD_MAGIC_WALL_FILLING);
4880 /* play sound of object that hits the ground */
4881 if (last_line || object_hit)
4882 PlayLevelSoundElementAction(x, y, element, ACTION_IMPACT);
4885 inline static void TurnRoundExt(int x, int y)
4897 { 0, 0 }, { 0, 0 }, { 0, 0 },
4902 int left, right, back;
4906 { MV_DOWN, MV_UP, MV_RIGHT },
4907 { MV_UP, MV_DOWN, MV_LEFT },
4909 { MV_LEFT, MV_RIGHT, MV_DOWN },
4913 { MV_RIGHT, MV_LEFT, MV_UP }
4916 int element = Feld[x][y];
4917 int move_pattern = element_info[element].move_pattern;
4919 int old_move_dir = MovDir[x][y];
4920 int left_dir = turn[old_move_dir].left;
4921 int right_dir = turn[old_move_dir].right;
4922 int back_dir = turn[old_move_dir].back;
4924 int left_dx = move_xy[left_dir].dx, left_dy = move_xy[left_dir].dy;
4925 int right_dx = move_xy[right_dir].dx, right_dy = move_xy[right_dir].dy;
4926 int move_dx = move_xy[old_move_dir].dx, move_dy = move_xy[old_move_dir].dy;
4927 int back_dx = move_xy[back_dir].dx, back_dy = move_xy[back_dir].dy;
4929 int left_x = x + left_dx, left_y = y + left_dy;
4930 int right_x = x + right_dx, right_y = y + right_dy;
4931 int move_x = x + move_dx, move_y = y + move_dy;
4935 if (element == EL_BUG || element == EL_BD_BUTTERFLY)
4937 TestIfBadThingTouchesOtherBadThing(x, y);
4939 if (ENEMY_CAN_ENTER_FIELD(element, right_x, right_y))
4940 MovDir[x][y] = right_dir;
4941 else if (!ENEMY_CAN_ENTER_FIELD(element, move_x, move_y))
4942 MovDir[x][y] = left_dir;
4944 if (element == EL_BUG && MovDir[x][y] != old_move_dir)
4946 else if (element == EL_BD_BUTTERFLY) /* && MovDir[x][y] == left_dir) */
4949 else if (element == EL_SPACESHIP || element == EL_BD_FIREFLY)
4951 TestIfBadThingTouchesOtherBadThing(x, y);
4953 if (ENEMY_CAN_ENTER_FIELD(element, left_x, left_y))
4954 MovDir[x][y] = left_dir;
4955 else if (!ENEMY_CAN_ENTER_FIELD(element, move_x, move_y))
4956 MovDir[x][y] = right_dir;
4958 if (element == EL_SPACESHIP && MovDir[x][y] != old_move_dir)
4960 else if (element == EL_BD_FIREFLY) /* && MovDir[x][y] == right_dir) */
4963 else if (element == EL_SP_SNIKSNAK || element == EL_SP_ELECTRON)
4965 TestIfBadThingTouchesOtherBadThing(x, y);
4967 if (ELEMENT_CAN_ENTER_FIELD_BASE_4(element, left_x, left_y, 0))
4968 MovDir[x][y] = left_dir;
4969 else if (!ELEMENT_CAN_ENTER_FIELD_BASE_4(element, move_x, move_y, 0))
4970 MovDir[x][y] = right_dir;
4972 if (MovDir[x][y] != old_move_dir)
4975 else if (element == EL_YAMYAM)
4977 boolean can_turn_left = YAMYAM_CAN_ENTER_FIELD(element, left_x, left_y);
4978 boolean can_turn_right = YAMYAM_CAN_ENTER_FIELD(element, right_x, right_y);
4980 if (can_turn_left && can_turn_right)
4981 MovDir[x][y] = (RND(3) ? (RND(2) ? left_dir : right_dir) : back_dir);
4982 else if (can_turn_left)
4983 MovDir[x][y] = (RND(2) ? left_dir : back_dir);
4984 else if (can_turn_right)
4985 MovDir[x][y] = (RND(2) ? right_dir : back_dir);
4987 MovDir[x][y] = back_dir;
4989 MovDelay[x][y] = 16 + 16 * RND(3);
4991 else if (element == EL_DARK_YAMYAM)
4993 boolean can_turn_left = DARK_YAMYAM_CAN_ENTER_FIELD(element,
4995 boolean can_turn_right = DARK_YAMYAM_CAN_ENTER_FIELD(element,
4998 if (can_turn_left && can_turn_right)
4999 MovDir[x][y] = (RND(3) ? (RND(2) ? left_dir : right_dir) : back_dir);
5000 else if (can_turn_left)
5001 MovDir[x][y] = (RND(2) ? left_dir : back_dir);
5002 else if (can_turn_right)
5003 MovDir[x][y] = (RND(2) ? right_dir : back_dir);
5005 MovDir[x][y] = back_dir;
5007 MovDelay[x][y] = 16 + 16 * RND(3);
5009 else if (element == EL_PACMAN)
5011 boolean can_turn_left = PACMAN_CAN_ENTER_FIELD(element, left_x, left_y);
5012 boolean can_turn_right = PACMAN_CAN_ENTER_FIELD(element, right_x, right_y);
5014 if (can_turn_left && can_turn_right)
5015 MovDir[x][y] = (RND(3) ? (RND(2) ? left_dir : right_dir) : back_dir);
5016 else if (can_turn_left)
5017 MovDir[x][y] = (RND(2) ? left_dir : back_dir);
5018 else if (can_turn_right)
5019 MovDir[x][y] = (RND(2) ? right_dir : back_dir);
5021 MovDir[x][y] = back_dir;
5023 MovDelay[x][y] = 6 + RND(40);
5025 else if (element == EL_PIG)
5027 boolean can_turn_left = PIG_CAN_ENTER_FIELD(element, left_x, left_y);
5028 boolean can_turn_right = PIG_CAN_ENTER_FIELD(element, right_x, right_y);
5029 boolean can_move_on = PIG_CAN_ENTER_FIELD(element, move_x, move_y);
5030 boolean should_turn_left, should_turn_right, should_move_on;
5032 int rnd = RND(rnd_value);
5034 should_turn_left = (can_turn_left &&
5036 IN_LEV_FIELD_AND_NOT_FREE(x + back_dx + left_dx,
5037 y + back_dy + left_dy)));
5038 should_turn_right = (can_turn_right &&
5040 IN_LEV_FIELD_AND_NOT_FREE(x + back_dx + right_dx,
5041 y + back_dy + right_dy)));
5042 should_move_on = (can_move_on &&
5045 IN_LEV_FIELD_AND_NOT_FREE(x + move_dx + left_dx,
5046 y + move_dy + left_dy) ||
5047 IN_LEV_FIELD_AND_NOT_FREE(x + move_dx + right_dx,
5048 y + move_dy + right_dy)));
5050 if (should_turn_left || should_turn_right || should_move_on)
5052 if (should_turn_left && should_turn_right && should_move_on)
5053 MovDir[x][y] = (rnd < rnd_value / 3 ? left_dir :
5054 rnd < 2 * rnd_value / 3 ? right_dir :
5056 else if (should_turn_left && should_turn_right)
5057 MovDir[x][y] = (rnd < rnd_value / 2 ? left_dir : right_dir);
5058 else if (should_turn_left && should_move_on)
5059 MovDir[x][y] = (rnd < rnd_value / 2 ? left_dir : old_move_dir);
5060 else if (should_turn_right && should_move_on)
5061 MovDir[x][y] = (rnd < rnd_value / 2 ? right_dir : old_move_dir);
5062 else if (should_turn_left)
5063 MovDir[x][y] = left_dir;
5064 else if (should_turn_right)
5065 MovDir[x][y] = right_dir;
5066 else if (should_move_on)
5067 MovDir[x][y] = old_move_dir;
5069 else if (can_move_on && rnd > rnd_value / 8)
5070 MovDir[x][y] = old_move_dir;
5071 else if (can_turn_left && can_turn_right)
5072 MovDir[x][y] = (rnd < rnd_value / 2 ? left_dir : right_dir);
5073 else if (can_turn_left && rnd > rnd_value / 8)
5074 MovDir[x][y] = left_dir;
5075 else if (can_turn_right && rnd > rnd_value/8)
5076 MovDir[x][y] = right_dir;
5078 MovDir[x][y] = back_dir;
5080 xx = x + move_xy[MovDir[x][y]].dx;
5081 yy = y + move_xy[MovDir[x][y]].dy;
5083 if (!IN_LEV_FIELD(xx, yy) ||
5084 (!IS_FREE(xx, yy) && !IS_FOOD_PIG(Feld[xx][yy])))
5085 MovDir[x][y] = old_move_dir;
5089 else if (element == EL_DRAGON)
5091 boolean can_turn_left = DRAGON_CAN_ENTER_FIELD(element, left_x, left_y);
5092 boolean can_turn_right = DRAGON_CAN_ENTER_FIELD(element, right_x, right_y);
5093 boolean can_move_on = DRAGON_CAN_ENTER_FIELD(element, move_x, move_y);
5095 int rnd = RND(rnd_value);
5097 if (can_move_on && rnd > rnd_value / 8)
5098 MovDir[x][y] = old_move_dir;
5099 else if (can_turn_left && can_turn_right)
5100 MovDir[x][y] = (rnd < rnd_value / 2 ? left_dir : right_dir);
5101 else if (can_turn_left && rnd > rnd_value / 8)
5102 MovDir[x][y] = left_dir;
5103 else if (can_turn_right && rnd > rnd_value / 8)
5104 MovDir[x][y] = right_dir;
5106 MovDir[x][y] = back_dir;
5108 xx = x + move_xy[MovDir[x][y]].dx;
5109 yy = y + move_xy[MovDir[x][y]].dy;
5111 if (!IN_LEV_FIELD_AND_IS_FREE(xx, yy))
5112 MovDir[x][y] = old_move_dir;
5116 else if (element == EL_MOLE)
5118 boolean can_move_on =
5119 (MOLE_CAN_ENTER_FIELD(element, move_x, move_y,
5120 IS_AMOEBOID(Feld[move_x][move_y]) ||
5121 Feld[move_x][move_y] == EL_AMOEBA_SHRINKING));
5124 boolean can_turn_left =
5125 (MOLE_CAN_ENTER_FIELD(element, left_x, left_y,
5126 IS_AMOEBOID(Feld[left_x][left_y])));
5128 boolean can_turn_right =
5129 (MOLE_CAN_ENTER_FIELD(element, right_x, right_y,
5130 IS_AMOEBOID(Feld[right_x][right_y])));
5132 if (can_turn_left && can_turn_right)
5133 MovDir[x][y] = (RND(2) ? left_dir : right_dir);
5134 else if (can_turn_left)
5135 MovDir[x][y] = left_dir;
5137 MovDir[x][y] = right_dir;
5140 if (MovDir[x][y] != old_move_dir)
5143 else if (element == EL_BALLOON)
5145 MovDir[x][y] = game.wind_direction;
5148 else if (element == EL_SPRING)
5150 #if USE_NEW_SPRING_BUMPER
5151 if (MovDir[x][y] & MV_HORIZONTAL)
5153 if (SPRING_CAN_BUMP_FROM_FIELD(move_x, move_y) &&
5154 !SPRING_CAN_ENTER_FIELD(element, x, y + 1))
5156 Feld[move_x][move_y] = EL_EMC_SPRING_BUMPER_ACTIVE;
5157 ResetGfxAnimation(move_x, move_y);
5158 DrawLevelField(move_x, move_y);
5160 MovDir[x][y] = back_dir;
5162 else if (!SPRING_CAN_ENTER_FIELD(element, move_x, move_y) ||
5163 SPRING_CAN_ENTER_FIELD(element, x, y + 1))
5164 MovDir[x][y] = MV_NONE;
5167 if (MovDir[x][y] & MV_HORIZONTAL &&
5168 (!SPRING_CAN_ENTER_FIELD(element, move_x, move_y) ||
5169 SPRING_CAN_ENTER_FIELD(element, x, y + 1)))
5170 MovDir[x][y] = MV_NONE;
5175 else if (element == EL_ROBOT ||
5176 element == EL_SATELLITE ||
5177 element == EL_PENGUIN ||
5178 element == EL_EMC_ANDROID)
5180 int attr_x = -1, attr_y = -1;
5191 for (i = 0; i < MAX_PLAYERS; i++)
5193 struct PlayerInfo *player = &stored_player[i];
5194 int jx = player->jx, jy = player->jy;
5196 if (!player->active)
5200 ABS(jx - x) + ABS(jy - y) < ABS(attr_x - x) + ABS(attr_y - y))
5208 if (element == EL_ROBOT && ZX >= 0 && ZY >= 0 &&
5209 (Feld[ZX][ZY] == EL_ROBOT_WHEEL_ACTIVE ||
5210 game.engine_version < VERSION_IDENT(3,1,0,0)))
5216 if (element == EL_PENGUIN)
5219 static int xy[4][2] =
5227 for (i = 0; i < NUM_DIRECTIONS; i++)
5229 int ex = x + xy[i][0];
5230 int ey = y + xy[i][1];
5232 if (IN_LEV_FIELD(ex, ey) && Feld[ex][ey] == EL_EXIT_OPEN)
5241 MovDir[x][y] = MV_NONE;
5243 MovDir[x][y] |= (AllPlayersGone ? MV_RIGHT : MV_LEFT);
5244 else if (attr_x > x)
5245 MovDir[x][y] |= (AllPlayersGone ? MV_LEFT : MV_RIGHT);
5247 MovDir[x][y] |= (AllPlayersGone ? MV_DOWN : MV_UP);
5248 else if (attr_y > y)
5249 MovDir[x][y] |= (AllPlayersGone ? MV_UP : MV_DOWN);
5251 if (element == EL_ROBOT)
5255 if (MovDir[x][y] & MV_HORIZONTAL && MovDir[x][y] & MV_VERTICAL)
5256 MovDir[x][y] &= (RND(2) ? MV_HORIZONTAL : MV_VERTICAL);
5257 Moving2Blocked(x, y, &newx, &newy);
5259 if (IN_LEV_FIELD(newx, newy) && IS_FREE_OR_PLAYER(newx, newy))
5260 MovDelay[x][y] = 8 + 8 * !RND(3);
5262 MovDelay[x][y] = 16;
5264 else if (element == EL_PENGUIN)
5270 if (MovDir[x][y] & MV_HORIZONTAL && MovDir[x][y] & MV_VERTICAL)
5272 boolean first_horiz = RND(2);
5273 int new_move_dir = MovDir[x][y];
5276 new_move_dir & (first_horiz ? MV_HORIZONTAL : MV_VERTICAL);
5277 Moving2Blocked(x, y, &newx, &newy);
5279 if (PENGUIN_CAN_ENTER_FIELD(element, newx, newy))
5283 new_move_dir & (!first_horiz ? MV_HORIZONTAL : MV_VERTICAL);
5284 Moving2Blocked(x, y, &newx, &newy);
5286 if (PENGUIN_CAN_ENTER_FIELD(element, newx, newy))
5289 MovDir[x][y] = old_move_dir;
5293 else if (element == EL_SATELLITE)
5299 if (MovDir[x][y] & MV_HORIZONTAL && MovDir[x][y] & MV_VERTICAL)
5301 boolean first_horiz = RND(2);
5302 int new_move_dir = MovDir[x][y];
5305 new_move_dir & (first_horiz ? MV_HORIZONTAL : MV_VERTICAL);
5306 Moving2Blocked(x, y, &newx, &newy);
5308 if (SATELLITE_CAN_ENTER_FIELD(newx, newy))
5312 new_move_dir & (!first_horiz ? MV_HORIZONTAL : MV_VERTICAL);
5313 Moving2Blocked(x, y, &newx, &newy);
5315 if (SATELLITE_CAN_ENTER_FIELD(newx, newy))
5318 MovDir[x][y] = old_move_dir;
5322 else if (element == EL_EMC_ANDROID)
5324 static int check_pos[16] =
5326 -1, /* 0 => (invalid) */
5327 7, /* 1 => MV_LEFT */
5328 3, /* 2 => MV_RIGHT */
5329 -1, /* 3 => (invalid) */
5331 0, /* 5 => MV_LEFT | MV_UP */
5332 2, /* 6 => MV_RIGHT | MV_UP */
5333 -1, /* 7 => (invalid) */
5334 5, /* 8 => MV_DOWN */
5335 6, /* 9 => MV_LEFT | MV_DOWN */
5336 4, /* 10 => MV_RIGHT | MV_DOWN */
5337 -1, /* 11 => (invalid) */
5338 -1, /* 12 => (invalid) */
5339 -1, /* 13 => (invalid) */
5340 -1, /* 14 => (invalid) */
5341 -1, /* 15 => (invalid) */
5349 { -1, -1, MV_LEFT | MV_UP },
5351 { +1, -1, MV_RIGHT | MV_UP },
5352 { +1, 0, MV_RIGHT },
5353 { +1, +1, MV_RIGHT | MV_DOWN },
5355 { -1, +1, MV_LEFT | MV_DOWN },
5358 int start_pos, check_order;
5359 boolean can_clone = FALSE;
5362 /* check if there is any free field around current position */
5363 for (i = 0; i < 8; i++)
5365 int newx = x + check_xy[i].dx;
5366 int newy = y + check_xy[i].dy;
5368 if (IN_LEV_FIELD_AND_IS_FREE(newx, newy))
5376 if (can_clone) /* randomly find an element to clone */
5380 start_pos = check_pos[RND(8)];
5381 check_order = (RND(2) ? -1 : +1);
5383 for (i = 0; i < 8; i++)
5385 int pos_raw = start_pos + i * check_order;
5386 int pos = (pos_raw + 8) % 8;
5387 int newx = x + check_xy[pos].dx;
5388 int newy = y + check_xy[pos].dy;
5390 if (ANDROID_CAN_CLONE_FIELD(newx, newy))
5392 element_info[element].move_leave_type = LEAVE_TYPE_LIMITED;
5393 element_info[element].move_leave_element = EL_TRIGGER_ELEMENT;
5395 Store[x][y] = Feld[newx][newy];
5404 if (can_clone) /* randomly find a direction to move */
5408 start_pos = check_pos[RND(8)];
5409 check_order = (RND(2) ? -1 : +1);
5411 for (i = 0; i < 8; i++)
5413 int pos_raw = start_pos + i * check_order;
5414 int pos = (pos_raw + 8) % 8;
5415 int newx = x + check_xy[pos].dx;
5416 int newy = y + check_xy[pos].dy;
5417 int new_move_dir = check_xy[pos].dir;
5419 if (IN_LEV_FIELD_AND_IS_FREE(newx, newy))
5421 MovDir[x][y] = new_move_dir;
5422 MovDelay[x][y] = level.android_clone_time * 8 + 1;
5431 if (can_clone) /* cloning and moving successful */
5434 /* cannot clone -- try to move towards player */
5436 start_pos = check_pos[MovDir[x][y] & 0x0f];
5437 check_order = (RND(2) ? -1 : +1);
5439 for (i = 0; i < 3; i++)
5441 /* first check start_pos, then previous/next or (next/previous) pos */
5442 int pos_raw = start_pos + (i < 2 ? i : -1) * check_order;
5443 int pos = (pos_raw + 8) % 8;
5444 int newx = x + check_xy[pos].dx;
5445 int newy = y + check_xy[pos].dy;
5446 int new_move_dir = check_xy[pos].dir;
5448 if (IS_PLAYER(newx, newy))
5451 if (ANDROID_CAN_ENTER_FIELD(element, newx, newy))
5453 MovDir[x][y] = new_move_dir;
5454 MovDelay[x][y] = level.android_move_time * 8 + 1;
5461 else if (move_pattern == MV_TURNING_LEFT ||
5462 move_pattern == MV_TURNING_RIGHT ||
5463 move_pattern == MV_TURNING_LEFT_RIGHT ||
5464 move_pattern == MV_TURNING_RIGHT_LEFT ||
5465 move_pattern == MV_TURNING_RANDOM ||
5466 move_pattern == MV_ALL_DIRECTIONS)
5468 boolean can_turn_left =
5469 CUSTOM_ELEMENT_CAN_ENTER_FIELD(element, left_x, left_y);
5470 boolean can_turn_right =
5471 CUSTOM_ELEMENT_CAN_ENTER_FIELD(element, right_x,right_y);
5473 if (element_info[element].move_stepsize == 0) /* "not moving" */
5476 if (move_pattern == MV_TURNING_LEFT)
5477 MovDir[x][y] = left_dir;
5478 else if (move_pattern == MV_TURNING_RIGHT)
5479 MovDir[x][y] = right_dir;
5480 else if (move_pattern == MV_TURNING_LEFT_RIGHT)
5481 MovDir[x][y] = (can_turn_left || !can_turn_right ? left_dir : right_dir);
5482 else if (move_pattern == MV_TURNING_RIGHT_LEFT)
5483 MovDir[x][y] = (can_turn_right || !can_turn_left ? right_dir : left_dir);
5484 else if (move_pattern == MV_TURNING_RANDOM)
5485 MovDir[x][y] = (can_turn_left && !can_turn_right ? left_dir :
5486 can_turn_right && !can_turn_left ? right_dir :
5487 RND(2) ? left_dir : right_dir);
5488 else if (can_turn_left && can_turn_right)
5489 MovDir[x][y] = (RND(3) ? (RND(2) ? left_dir : right_dir) : back_dir);
5490 else if (can_turn_left)
5491 MovDir[x][y] = (RND(2) ? left_dir : back_dir);
5492 else if (can_turn_right)
5493 MovDir[x][y] = (RND(2) ? right_dir : back_dir);
5495 MovDir[x][y] = back_dir;
5497 MovDelay[x][y] = GET_NEW_MOVE_DELAY(element);
5499 else if (move_pattern == MV_HORIZONTAL ||
5500 move_pattern == MV_VERTICAL)
5502 if (move_pattern & old_move_dir)
5503 MovDir[x][y] = back_dir;
5504 else if (move_pattern == MV_HORIZONTAL)
5505 MovDir[x][y] = (RND(2) ? MV_LEFT : MV_RIGHT);
5506 else if (move_pattern == MV_VERTICAL)
5507 MovDir[x][y] = (RND(2) ? MV_UP : MV_DOWN);
5509 MovDelay[x][y] = GET_NEW_MOVE_DELAY(element);
5511 else if (move_pattern & MV_ANY_DIRECTION)
5513 MovDir[x][y] = move_pattern;
5514 MovDelay[x][y] = GET_NEW_MOVE_DELAY(element);
5516 else if (move_pattern & MV_WIND_DIRECTION)
5518 MovDir[x][y] = game.wind_direction;
5519 MovDelay[x][y] = GET_NEW_MOVE_DELAY(element);
5521 else if (move_pattern == MV_ALONG_LEFT_SIDE)
5523 if (CUSTOM_ELEMENT_CAN_ENTER_FIELD(element, left_x, left_y))
5524 MovDir[x][y] = left_dir;
5525 else if (!CUSTOM_ELEMENT_CAN_ENTER_FIELD(element, move_x, move_y))
5526 MovDir[x][y] = right_dir;
5528 if (MovDir[x][y] != old_move_dir)
5529 MovDelay[x][y] = GET_NEW_MOVE_DELAY(element);
5531 else if (move_pattern == MV_ALONG_RIGHT_SIDE)
5533 if (CUSTOM_ELEMENT_CAN_ENTER_FIELD(element, right_x, right_y))
5534 MovDir[x][y] = right_dir;
5535 else if (!CUSTOM_ELEMENT_CAN_ENTER_FIELD(element, move_x, move_y))
5536 MovDir[x][y] = left_dir;
5538 if (MovDir[x][y] != old_move_dir)
5539 MovDelay[x][y] = GET_NEW_MOVE_DELAY(element);
5541 else if (move_pattern == MV_TOWARDS_PLAYER ||
5542 move_pattern == MV_AWAY_FROM_PLAYER)
5544 int attr_x = -1, attr_y = -1;
5546 boolean move_away = (move_pattern == MV_AWAY_FROM_PLAYER);
5557 for (i = 0; i < MAX_PLAYERS; i++)
5559 struct PlayerInfo *player = &stored_player[i];
5560 int jx = player->jx, jy = player->jy;
5562 if (!player->active)
5566 ABS(jx - x) + ABS(jy - y) < ABS(attr_x - x) + ABS(attr_y - y))
5574 MovDir[x][y] = MV_NONE;
5576 MovDir[x][y] |= (move_away ? MV_RIGHT : MV_LEFT);
5577 else if (attr_x > x)
5578 MovDir[x][y] |= (move_away ? MV_LEFT : MV_RIGHT);
5580 MovDir[x][y] |= (move_away ? MV_DOWN : MV_UP);
5581 else if (attr_y > y)
5582 MovDir[x][y] |= (move_away ? MV_UP : MV_DOWN);
5584 MovDelay[x][y] = GET_NEW_MOVE_DELAY(element);
5586 if (MovDir[x][y] & MV_HORIZONTAL && MovDir[x][y] & MV_VERTICAL)
5588 boolean first_horiz = RND(2);
5589 int new_move_dir = MovDir[x][y];
5591 if (element_info[element].move_stepsize == 0) /* "not moving" */
5593 first_horiz = (ABS(attr_x - x) >= ABS(attr_y - y));
5594 MovDir[x][y] &= (first_horiz ? MV_HORIZONTAL : MV_VERTICAL);
5600 new_move_dir & (first_horiz ? MV_HORIZONTAL : MV_VERTICAL);
5601 Moving2Blocked(x, y, &newx, &newy);
5603 if (CUSTOM_ELEMENT_CAN_ENTER_FIELD(element, newx, newy))
5607 new_move_dir & (!first_horiz ? MV_HORIZONTAL : MV_VERTICAL);
5608 Moving2Blocked(x, y, &newx, &newy);
5610 if (CUSTOM_ELEMENT_CAN_ENTER_FIELD(element, newx, newy))
5613 MovDir[x][y] = old_move_dir;
5616 else if (move_pattern == MV_WHEN_PUSHED ||
5617 move_pattern == MV_WHEN_DROPPED)
5619 if (!CUSTOM_ELEMENT_CAN_ENTER_FIELD(element, move_x, move_y))
5620 MovDir[x][y] = MV_NONE;
5624 else if (move_pattern & MV_MAZE_RUNNER_STYLE)
5626 static int test_xy[7][2] =
5636 static int test_dir[7] =
5646 boolean hunter_mode = (move_pattern == MV_MAZE_HUNTER);
5647 int move_preference = -1000000; /* start with very low preference */
5648 int new_move_dir = MV_NONE;
5649 int start_test = RND(4);
5652 for (i = 0; i < NUM_DIRECTIONS; i++)
5654 int move_dir = test_dir[start_test + i];
5655 int move_dir_preference;
5657 xx = x + test_xy[start_test + i][0];
5658 yy = y + test_xy[start_test + i][1];
5660 if (hunter_mode && IN_LEV_FIELD(xx, yy) &&
5661 (IS_PLAYER(xx, yy) || Feld[xx][yy] == EL_PLAYER_IS_LEAVING))
5663 new_move_dir = move_dir;
5668 if (!CUSTOM_ELEMENT_CAN_ENTER_FIELD(element, xx, yy))
5671 move_dir_preference = -1 * RunnerVisit[xx][yy];
5672 if (hunter_mode && PlayerVisit[xx][yy] > 0)
5673 move_dir_preference = PlayerVisit[xx][yy];
5675 if (move_dir_preference > move_preference)
5677 /* prefer field that has not been visited for the longest time */
5678 move_preference = move_dir_preference;
5679 new_move_dir = move_dir;
5681 else if (move_dir_preference == move_preference &&
5682 move_dir == old_move_dir)
5684 /* prefer last direction when all directions are preferred equally */
5685 move_preference = move_dir_preference;
5686 new_move_dir = move_dir;
5690 MovDir[x][y] = new_move_dir;
5691 if (old_move_dir != new_move_dir)
5692 MovDelay[x][y] = GET_NEW_MOVE_DELAY(element);
5696 static void TurnRound(int x, int y)
5698 int direction = MovDir[x][y];
5700 int element, graphic;
5705 GfxDir[x][y] = MovDir[x][y];
5707 if (direction != MovDir[x][y])
5711 GfxAction[x][y] = ACTION_TURNING_FROM_LEFT + MV_DIR_TO_BIT(direction);
5714 element = Feld[x][y];
5715 graphic = el_act_dir2img(element, GfxAction[x][y], GfxDir[x][y]);
5717 if (graphic_info[graphic].anim_global_sync)
5718 GfxFrame[x][y] = FrameCounter;
5719 else if (ANIM_MODE(graphic) == ANIM_CE_VALUE)
5720 GfxFrame[x][y] = CustomValue[x][y];
5721 else if (ANIM_MODE(graphic) == ANIM_CE_SCORE)
5722 GfxFrame[x][y] = element_info[element].collect_score;
5726 static boolean JustBeingPushed(int x, int y)
5730 for (i = 0; i < MAX_PLAYERS; i++)
5732 struct PlayerInfo *player = &stored_player[i];
5734 if (player->active && player->is_pushing && player->MovPos)
5736 int next_jx = player->jx + (player->jx - player->last_jx);
5737 int next_jy = player->jy + (player->jy - player->last_jy);
5739 if (x == next_jx && y == next_jy)
5747 void StartMoving(int x, int y)
5749 boolean started_moving = FALSE; /* some elements can fall _and_ move */
5750 int element = Feld[x][y];
5755 if (MovDelay[x][y] == 0)
5756 GfxAction[x][y] = ACTION_DEFAULT;
5758 if (CAN_FALL(element) && y < lev_fieldy - 1)
5760 if ((x > 0 && IS_PLAYER(x - 1, y)) ||
5761 (x < lev_fieldx - 1 && IS_PLAYER(x + 1, y)))
5762 if (JustBeingPushed(x, y))
5765 if (element == EL_QUICKSAND_FULL)
5767 if (IS_FREE(x, y + 1))
5769 InitMovingField(x, y, MV_DOWN);
5770 started_moving = TRUE;
5772 Feld[x][y] = EL_QUICKSAND_EMPTYING;
5773 Store[x][y] = EL_ROCK;
5775 PlayLevelSoundAction(x, y, ACTION_EMPTYING);
5777 else if (Feld[x][y + 1] == EL_QUICKSAND_EMPTY)
5779 if (!MovDelay[x][y])
5780 MovDelay[x][y] = TILEY + 1;
5789 Feld[x][y] = EL_QUICKSAND_EMPTY;
5790 Feld[x][y + 1] = EL_QUICKSAND_FULL;
5791 Store[x][y + 1] = Store[x][y];
5794 PlayLevelSoundAction(x, y, ACTION_FILLING);
5797 else if ((element == EL_ROCK || element == EL_BD_ROCK) &&
5798 Feld[x][y + 1] == EL_QUICKSAND_EMPTY)
5800 InitMovingField(x, y, MV_DOWN);
5801 started_moving = TRUE;
5803 Feld[x][y] = EL_QUICKSAND_FILLING;
5804 Store[x][y] = element;
5806 PlayLevelSoundAction(x, y, ACTION_FILLING);
5808 else if (element == EL_MAGIC_WALL_FULL)
5810 if (IS_FREE(x, y + 1))
5812 InitMovingField(x, y, MV_DOWN);
5813 started_moving = TRUE;
5815 Feld[x][y] = EL_MAGIC_WALL_EMPTYING;
5816 Store[x][y] = EL_CHANGED(Store[x][y]);
5818 else if (Feld[x][y + 1] == EL_MAGIC_WALL_ACTIVE)
5820 if (!MovDelay[x][y])
5821 MovDelay[x][y] = TILEY/4 + 1;
5830 Feld[x][y] = EL_MAGIC_WALL_ACTIVE;
5831 Feld[x][y + 1] = EL_MAGIC_WALL_FULL;
5832 Store[x][y + 1] = EL_CHANGED(Store[x][y]);
5836 else if (element == EL_BD_MAGIC_WALL_FULL)
5838 if (IS_FREE(x, y + 1))
5840 InitMovingField(x, y, MV_DOWN);
5841 started_moving = TRUE;
5843 Feld[x][y] = EL_BD_MAGIC_WALL_EMPTYING;
5844 Store[x][y] = EL_CHANGED2(Store[x][y]);
5846 else if (Feld[x][y + 1] == EL_BD_MAGIC_WALL_ACTIVE)
5848 if (!MovDelay[x][y])
5849 MovDelay[x][y] = TILEY/4 + 1;
5858 Feld[x][y] = EL_BD_MAGIC_WALL_ACTIVE;
5859 Feld[x][y + 1] = EL_BD_MAGIC_WALL_FULL;
5860 Store[x][y + 1] = EL_CHANGED2(Store[x][y]);
5864 else if (CAN_PASS_MAGIC_WALL(element) &&
5865 (Feld[x][y + 1] == EL_MAGIC_WALL_ACTIVE ||
5866 Feld[x][y + 1] == EL_BD_MAGIC_WALL_ACTIVE))
5868 InitMovingField(x, y, MV_DOWN);
5869 started_moving = TRUE;
5872 (Feld[x][y + 1] == EL_MAGIC_WALL_ACTIVE ? EL_MAGIC_WALL_FILLING :
5873 EL_BD_MAGIC_WALL_FILLING);
5874 Store[x][y] = element;
5876 else if (CAN_FALL(element) && Feld[x][y + 1] == EL_ACID)
5878 SplashAcid(x, y + 1);
5880 InitMovingField(x, y, MV_DOWN);
5881 started_moving = TRUE;
5883 Store[x][y] = EL_ACID;
5885 else if ((game.engine_version >= VERSION_IDENT(3,1,0,0) &&
5886 CheckCollision[x][y] && !IS_FREE(x, y + 1)) ||
5888 (game.engine_version >= VERSION_IDENT(3,0,7,0) &&
5889 CAN_FALL(element) && WasJustFalling[x][y] &&
5890 (Feld[x][y + 1] == EL_BLOCKED || IS_PLAYER(x, y + 1))) ||
5892 (game.engine_version < VERSION_IDENT(2,2,0,7) &&
5893 CAN_FALL(element) && WasJustMoving[x][y] && !Pushed[x][y + 1] &&
5894 (Feld[x][y + 1] == EL_BLOCKED)))
5896 /* this is needed for a special case not covered by calling "Impact()"
5897 from "ContinueMoving()": if an element moves to a tile directly below
5898 another element which was just falling on that tile (which was empty
5899 in the previous frame), the falling element above would just stop
5900 instead of smashing the element below (in previous version, the above
5901 element was just checked for "moving" instead of "falling", resulting
5902 in incorrect smashes caused by horizontal movement of the above
5903 element; also, the case of the player being the element to smash was
5904 simply not covered here... :-/ ) */
5906 CheckCollision[x][y] = 0;
5910 else if (IS_FREE(x, y + 1) && element == EL_SPRING && level.use_spring_bug)
5912 if (MovDir[x][y] == MV_NONE)
5914 InitMovingField(x, y, MV_DOWN);
5915 started_moving = TRUE;
5918 else if (IS_FREE(x, y + 1) || Feld[x][y + 1] == EL_DIAMOND_BREAKING)
5920 if (WasJustFalling[x][y]) /* prevent animation from being restarted */
5921 MovDir[x][y] = MV_DOWN;
5923 InitMovingField(x, y, MV_DOWN);
5924 started_moving = TRUE;
5926 else if (element == EL_AMOEBA_DROP)
5928 Feld[x][y] = EL_AMOEBA_GROWING;
5929 Store[x][y] = EL_AMOEBA_WET;
5931 else if (((IS_SLIPPERY(Feld[x][y + 1]) && !IS_PLAYER(x, y + 1)) ||
5932 (IS_EM_SLIPPERY_WALL(Feld[x][y + 1]) && IS_GEM(element))) &&
5933 !IS_FALLING(x, y + 1) && !WasJustMoving[x][y + 1] &&
5934 element != EL_DX_SUPABOMB && element != EL_SP_DISK_ORANGE)
5936 boolean can_fall_left = (x > 0 && IS_FREE(x - 1, y) &&
5937 (IS_FREE(x - 1, y + 1) ||
5938 Feld[x - 1][y + 1] == EL_ACID));
5939 boolean can_fall_right = (x < lev_fieldx - 1 && IS_FREE(x + 1, y) &&
5940 (IS_FREE(x + 1, y + 1) ||
5941 Feld[x + 1][y + 1] == EL_ACID));
5942 boolean can_fall_any = (can_fall_left || can_fall_right);
5943 boolean can_fall_both = (can_fall_left && can_fall_right);
5944 int slippery_type = element_info[Feld[x][y + 1]].slippery_type;
5946 #if USE_NEW_ALL_SLIPPERY
5947 if (can_fall_any && slippery_type != SLIPPERY_ANY_RANDOM)
5949 if (slippery_type == SLIPPERY_ANY_LEFT_RIGHT && can_fall_both)
5950 can_fall_right = FALSE;
5951 else if (slippery_type == SLIPPERY_ANY_RIGHT_LEFT && can_fall_both)
5952 can_fall_left = FALSE;
5953 else if (slippery_type == SLIPPERY_ONLY_LEFT)
5954 can_fall_right = FALSE;
5955 else if (slippery_type == SLIPPERY_ONLY_RIGHT)
5956 can_fall_left = FALSE;
5958 can_fall_any = (can_fall_left || can_fall_right);
5959 can_fall_both = FALSE;
5962 if (can_fall_any && IS_CUSTOM_ELEMENT(Feld[x][y + 1]))
5964 if (slippery_type == SLIPPERY_ONLY_LEFT)
5965 can_fall_right = FALSE;
5966 else if (slippery_type == SLIPPERY_ONLY_RIGHT)
5967 can_fall_left = FALSE;
5968 else if (slippery_type == SLIPPERY_ANY_LEFT_RIGHT && can_fall_both)
5969 can_fall_right = FALSE;
5970 else if (slippery_type == SLIPPERY_ANY_RIGHT_LEFT && can_fall_both)
5971 can_fall_left = FALSE;
5973 can_fall_any = (can_fall_left || can_fall_right);
5974 can_fall_both = (can_fall_left && can_fall_right);
5978 #if USE_NEW_ALL_SLIPPERY
5980 #if USE_NEW_SP_SLIPPERY
5981 /* !!! better use the same properties as for custom elements here !!! */
5982 else if (game.engine_version >= VERSION_IDENT(3,1,1,0) &&
5983 can_fall_both && IS_SP_ELEMENT(Feld[x][y + 1]))
5985 can_fall_right = FALSE; /* slip down on left side */
5986 can_fall_both = FALSE;
5991 #if USE_NEW_ALL_SLIPPERY
5994 if (element == EL_BD_ROCK || element == EL_BD_DIAMOND)
5995 can_fall_right = FALSE; /* slip down on left side */
5997 can_fall_left = !(can_fall_right = RND(2));
5999 can_fall_both = FALSE;
6004 if (game.emulation == EMU_BOULDERDASH ||
6005 element == EL_BD_ROCK || element == EL_BD_DIAMOND)
6006 can_fall_right = FALSE; /* slip down on left side */
6008 can_fall_left = !(can_fall_right = RND(2));
6010 can_fall_both = FALSE;
6016 /* if not determined otherwise, prefer left side for slipping down */
6017 InitMovingField(x, y, can_fall_left ? MV_LEFT : MV_RIGHT);
6018 started_moving = TRUE;
6022 else if (IS_BELT_ACTIVE(Feld[x][y + 1]) && !CAN_MOVE(element))
6024 else if (IS_BELT_ACTIVE(Feld[x][y + 1]))
6027 boolean left_is_free = (x > 0 && IS_FREE(x - 1, y));
6028 boolean right_is_free = (x < lev_fieldx - 1 && IS_FREE(x + 1, y));
6029 int belt_nr = getBeltNrFromBeltActiveElement(Feld[x][y + 1]);
6030 int belt_dir = game.belt_dir[belt_nr];
6032 if ((belt_dir == MV_LEFT && left_is_free) ||
6033 (belt_dir == MV_RIGHT && right_is_free))
6035 int nextx = (belt_dir == MV_LEFT ? x - 1 : x + 1);
6037 InitMovingField(x, y, belt_dir);
6038 started_moving = TRUE;
6040 Pushed[x][y] = TRUE;
6041 Pushed[nextx][y] = TRUE;
6043 GfxAction[x][y] = ACTION_DEFAULT;
6047 MovDir[x][y] = 0; /* if element was moving, stop it */
6052 /* not "else if" because of elements that can fall and move (EL_SPRING) */
6054 if (CAN_MOVE(element) && !started_moving && MovDir[x][y] != MV_NONE)
6056 if (CAN_MOVE(element) && !started_moving)
6059 int move_pattern = element_info[element].move_pattern;
6064 if (MovDir[x][y] == MV_NONE)
6066 printf("StartMoving(): %d,%d: element %d ['%s'] not moving\n",
6067 x, y, element, element_info[element].token_name);
6068 printf("StartMoving(): This should never happen!\n");
6073 Moving2Blocked(x, y, &newx, &newy);
6075 if (IS_PUSHABLE(element) && JustBeingPushed(x, y))
6078 if (game.engine_version >= VERSION_IDENT(3,1,0,0) &&
6079 CheckCollision[x][y] && !IN_LEV_FIELD_AND_IS_FREE(newx, newy))
6081 WasJustMoving[x][y] = 0;
6082 CheckCollision[x][y] = 0;
6084 TestIfElementHitsCustomElement(x, y, MovDir[x][y]);
6086 if (Feld[x][y] != element) /* element has changed */
6090 if (!MovDelay[x][y]) /* start new movement phase */
6092 /* all objects that can change their move direction after each step
6093 (YAMYAM, DARK_YAMYAM and PACMAN go straight until they hit a wall */
6095 if (element != EL_YAMYAM &&
6096 element != EL_DARK_YAMYAM &&
6097 element != EL_PACMAN &&
6098 !(move_pattern & MV_ANY_DIRECTION) &&
6099 move_pattern != MV_TURNING_LEFT &&
6100 move_pattern != MV_TURNING_RIGHT &&
6101 move_pattern != MV_TURNING_LEFT_RIGHT &&
6102 move_pattern != MV_TURNING_RIGHT_LEFT &&
6103 move_pattern != MV_TURNING_RANDOM)
6107 if (MovDelay[x][y] && (element == EL_BUG ||
6108 element == EL_SPACESHIP ||
6109 element == EL_SP_SNIKSNAK ||
6110 element == EL_SP_ELECTRON ||
6111 element == EL_MOLE))
6112 DrawLevelField(x, y);
6116 if (MovDelay[x][y]) /* wait some time before next movement */
6120 if (element == EL_ROBOT ||
6121 element == EL_YAMYAM ||
6122 element == EL_DARK_YAMYAM)
6124 DrawLevelElementAnimationIfNeeded(x, y, element);
6125 PlayLevelSoundAction(x, y, ACTION_WAITING);
6127 else if (element == EL_SP_ELECTRON)
6128 DrawLevelElementAnimationIfNeeded(x, y, element);
6129 else if (element == EL_DRAGON)
6132 int dir = MovDir[x][y];
6133 int dx = (dir == MV_LEFT ? -1 : dir == MV_RIGHT ? +1 : 0);
6134 int dy = (dir == MV_UP ? -1 : dir == MV_DOWN ? +1 : 0);
6135 int graphic = (dir == MV_LEFT ? IMG_FLAMES_1_LEFT :
6136 dir == MV_RIGHT ? IMG_FLAMES_1_RIGHT :
6137 dir == MV_UP ? IMG_FLAMES_1_UP :
6138 dir == MV_DOWN ? IMG_FLAMES_1_DOWN : IMG_EMPTY);
6139 int frame = getGraphicAnimationFrame(graphic, GfxFrame[x][y]);
6141 GfxAction[x][y] = ACTION_ATTACKING;
6143 if (IS_PLAYER(x, y))
6144 DrawPlayerField(x, y);
6146 DrawLevelField(x, y);
6148 PlayLevelSoundActionIfLoop(x, y, ACTION_ATTACKING);
6150 for (i = 1; i <= 3; i++)
6152 int xx = x + i * dx;
6153 int yy = y + i * dy;
6154 int sx = SCREENX(xx);
6155 int sy = SCREENY(yy);
6156 int flame_graphic = graphic + (i - 1);
6158 if (!IN_LEV_FIELD(xx, yy) || IS_DRAGONFIRE_PROOF(Feld[xx][yy]))
6163 int flamed = MovingOrBlocked2Element(xx, yy);
6167 if (IS_CLASSIC_ENEMY(flamed) || CAN_EXPLODE_BY_DRAGONFIRE(flamed))
6169 else if (IS_MOVING(xx, yy) || IS_BLOCKED(xx, yy))
6170 RemoveMovingField(xx, yy);
6172 RemoveField(xx, yy);
6174 if (IS_CLASSIC_ENEMY(flamed) || CAN_EXPLODE_BY_DRAGONFIRE(flamed))
6177 RemoveMovingField(xx, yy);
6180 ChangeDelay[xx][yy] = 0;
6182 Feld[xx][yy] = EL_FLAMES;
6184 if (IN_SCR_FIELD(sx, sy))
6186 DrawLevelFieldCrumbledSand(xx, yy);
6187 DrawGraphic(sx, sy, flame_graphic, frame);
6192 if (Feld[xx][yy] == EL_FLAMES)
6193 Feld[xx][yy] = EL_EMPTY;
6194 DrawLevelField(xx, yy);
6199 if (MovDelay[x][y]) /* element still has to wait some time */
6201 PlayLevelSoundAction(x, y, ACTION_WAITING);
6207 /* now make next step */
6209 Moving2Blocked(x, y, &newx, &newy); /* get next screen position */
6211 if (DONT_COLLIDE_WITH(element) &&
6212 IN_LEV_FIELD(newx, newy) && IS_PLAYER(newx, newy) &&
6213 !PLAYER_ENEMY_PROTECTED(newx, newy))
6215 TestIfBadThingRunsIntoPlayer(x, y, MovDir[x][y]);
6220 else if (CAN_MOVE_INTO_ACID(element) &&
6221 IN_LEV_FIELD(newx, newy) && Feld[newx][newy] == EL_ACID &&
6222 !IS_MV_DIAGONAL(MovDir[x][y]) &&
6223 (MovDir[x][y] == MV_DOWN ||
6224 game.engine_version >= VERSION_IDENT(3,1,0,0)))
6226 SplashAcid(newx, newy);
6227 Store[x][y] = EL_ACID;
6229 else if (element == EL_PENGUIN && IN_LEV_FIELD(newx, newy))
6231 if (Feld[newx][newy] == EL_EXIT_OPEN)
6234 DrawLevelField(x, y);
6236 PlayLevelSound(newx, newy, SND_PENGUIN_PASSING);
6237 if (IN_SCR_FIELD(SCREENX(newx), SCREENY(newy)))
6238 DrawGraphicThruMask(SCREENX(newx),SCREENY(newy), el2img(element), 0);
6240 local_player->friends_still_needed--;
6241 if (!local_player->friends_still_needed &&
6242 !local_player->GameOver && AllPlayersGone)
6243 local_player->LevelSolved = local_player->GameOver = TRUE;
6247 else if (IS_FOOD_PENGUIN(Feld[newx][newy]))
6249 if (DigField(local_player, x, y, newx, newy, 0,0, DF_DIG) == MP_MOVING)
6250 DrawLevelField(newx, newy);
6252 GfxDir[x][y] = MovDir[x][y] = MV_NONE;
6254 else if (!IS_FREE(newx, newy))
6256 GfxAction[x][y] = ACTION_WAITING;
6258 if (IS_PLAYER(x, y))
6259 DrawPlayerField(x, y);
6261 DrawLevelField(x, y);
6266 else if (element == EL_PIG && IN_LEV_FIELD(newx, newy))
6268 if (IS_FOOD_PIG(Feld[newx][newy]))
6270 if (IS_MOVING(newx, newy))
6271 RemoveMovingField(newx, newy);
6274 Feld[newx][newy] = EL_EMPTY;
6275 DrawLevelField(newx, newy);
6278 PlayLevelSound(x, y, SND_PIG_DIGGING);
6280 else if (!IS_FREE(newx, newy))
6282 if (IS_PLAYER(x, y))
6283 DrawPlayerField(x, y);
6285 DrawLevelField(x, y);
6290 else if (element == EL_EMC_ANDROID && IN_LEV_FIELD(newx, newy))
6292 if (Store[x][y] != EL_EMPTY)
6294 boolean can_clone = FALSE;
6297 /* check if element to clone is still there */
6298 for (yy = y - 1; yy <= y + 1; yy++) for (xx = x - 1; xx <= x + 1; xx++)
6300 if (IN_LEV_FIELD(xx, yy) && Feld[xx][yy] == Store[x][y])
6308 /* cannot clone or target field not free anymore -- do not clone */
6309 if (!can_clone || !ANDROID_CAN_ENTER_FIELD(element, newx, newy))
6310 Store[x][y] = EL_EMPTY;
6313 if (ANDROID_CAN_ENTER_FIELD(element, newx, newy))
6315 if (IS_MV_DIAGONAL(MovDir[x][y]))
6317 int diagonal_move_dir = MovDir[x][y];
6318 int stored = Store[x][y];
6319 int change_delay = 8;
6322 /* android is moving diagonally */
6324 CreateField(x, y, EL_DIAGONAL_SHRINKING);
6326 Store[x][y] = (stored == EL_ACID ? EL_EMPTY : stored);
6327 GfxElement[x][y] = EL_EMC_ANDROID;
6328 GfxAction[x][y] = ACTION_SHRINKING;
6329 GfxDir[x][y] = diagonal_move_dir;
6330 ChangeDelay[x][y] = change_delay;
6332 graphic = el_act_dir2img(GfxElement[x][y], GfxAction[x][y],
6335 DrawLevelGraphicAnimation(x, y, graphic);
6336 PlayLevelSoundAction(x, y, ACTION_SHRINKING);
6338 if (Feld[newx][newy] == EL_ACID)
6340 SplashAcid(newx, newy);
6345 CreateField(newx, newy, EL_DIAGONAL_GROWING);
6347 Store[newx][newy] = EL_EMC_ANDROID;
6348 GfxElement[newx][newy] = EL_EMC_ANDROID;
6349 GfxAction[newx][newy] = ACTION_GROWING;
6350 GfxDir[newx][newy] = diagonal_move_dir;
6351 ChangeDelay[newx][newy] = change_delay;
6353 graphic = el_act_dir2img(GfxElement[newx][newy],
6354 GfxAction[newx][newy], GfxDir[newx][newy]);
6356 DrawLevelGraphicAnimation(newx, newy, graphic);
6357 PlayLevelSoundAction(newx, newy, ACTION_GROWING);
6363 Feld[newx][newy] = EL_EMPTY;
6364 DrawLevelField(newx, newy);
6366 PlayLevelSoundAction(x, y, ACTION_DIGGING);
6369 else if (!IS_FREE(newx, newy))
6372 if (IS_PLAYER(x, y))
6373 DrawPlayerField(x, y);
6375 DrawLevelField(x, y);
6381 else if (IS_CUSTOM_ELEMENT(element) &&
6382 CUSTOM_ELEMENT_CAN_ENTER_FIELD(element, newx, newy))
6384 int new_element = Feld[newx][newy];
6386 if (!IS_FREE(newx, newy))
6388 int action = (IS_DIGGABLE(new_element) ? ACTION_DIGGING :
6389 IS_COLLECTIBLE(new_element) ? ACTION_COLLECTING :
6392 /* no element can dig solid indestructible elements */
6393 if (IS_INDESTRUCTIBLE(new_element) &&
6394 !IS_DIGGABLE(new_element) &&
6395 !IS_COLLECTIBLE(new_element))
6398 if (AmoebaNr[newx][newy] &&
6399 (new_element == EL_AMOEBA_FULL ||
6400 new_element == EL_BD_AMOEBA ||
6401 new_element == EL_AMOEBA_GROWING))
6403 AmoebaCnt[AmoebaNr[newx][newy]]--;
6404 AmoebaCnt2[AmoebaNr[newx][newy]]--;
6407 if (IS_MOVING(newx, newy))
6408 RemoveMovingField(newx, newy);
6411 RemoveField(newx, newy);
6412 DrawLevelField(newx, newy);
6415 /* if digged element was about to explode, prevent the explosion */
6416 ExplodeField[newx][newy] = EX_TYPE_NONE;
6418 PlayLevelSoundAction(x, y, action);
6421 Store[newx][newy] = EL_EMPTY;
6423 /* this makes it possible to leave the removed element again */
6424 if (IS_EQUAL_OR_IN_GROUP(new_element, MOVE_ENTER_EL(element)))
6425 Store[newx][newy] = new_element;
6427 if (IS_EQUAL_OR_IN_GROUP(new_element, MOVE_ENTER_EL(element)))
6429 int move_leave_element = element_info[element].move_leave_element;
6431 /* this makes it possible to leave the removed element again */
6432 Store[newx][newy] = (move_leave_element == EL_TRIGGER_ELEMENT ?
6433 new_element : move_leave_element);
6437 if (move_pattern & MV_MAZE_RUNNER_STYLE)
6439 RunnerVisit[x][y] = FrameCounter;
6440 PlayerVisit[x][y] /= 8; /* expire player visit path */
6443 else if (element == EL_DRAGON && IN_LEV_FIELD(newx, newy))
6445 if (!IS_FREE(newx, newy))
6447 if (IS_PLAYER(x, y))
6448 DrawPlayerField(x, y);
6450 DrawLevelField(x, y);
6456 boolean wanna_flame = !RND(10);
6457 int dx = newx - x, dy = newy - y;
6458 int newx1 = newx + 1 * dx, newy1 = newy + 1 * dy;
6459 int newx2 = newx + 2 * dx, newy2 = newy + 2 * dy;
6460 int element1 = (IN_LEV_FIELD(newx1, newy1) ?
6461 MovingOrBlocked2Element(newx1, newy1) : EL_STEELWALL);
6462 int element2 = (IN_LEV_FIELD(newx2, newy2) ?
6463 MovingOrBlocked2Element(newx2, newy2) : EL_STEELWALL);
6466 IS_CLASSIC_ENEMY(element1) ||
6467 IS_CLASSIC_ENEMY(element2)) &&
6468 element1 != EL_DRAGON && element2 != EL_DRAGON &&
6469 element1 != EL_FLAMES && element2 != EL_FLAMES)
6471 ResetGfxAnimation(x, y);
6472 GfxAction[x][y] = ACTION_ATTACKING;
6474 if (IS_PLAYER(x, y))
6475 DrawPlayerField(x, y);
6477 DrawLevelField(x, y);
6479 PlayLevelSound(x, y, SND_DRAGON_ATTACKING);
6481 MovDelay[x][y] = 50;
6485 RemoveField(newx, newy);
6487 Feld[newx][newy] = EL_FLAMES;
6488 if (IN_LEV_FIELD(newx1, newy1) && Feld[newx1][newy1] == EL_EMPTY)
6491 RemoveField(newx1, newy1);
6493 Feld[newx1][newy1] = EL_FLAMES;
6495 if (IN_LEV_FIELD(newx2, newy2) && Feld[newx2][newy2] == EL_EMPTY)
6498 RemoveField(newx2, newy2);
6500 Feld[newx2][newy2] = EL_FLAMES;
6507 else if (element == EL_YAMYAM && IN_LEV_FIELD(newx, newy) &&
6508 Feld[newx][newy] == EL_DIAMOND)
6510 if (IS_MOVING(newx, newy))
6511 RemoveMovingField(newx, newy);
6514 Feld[newx][newy] = EL_EMPTY;
6515 DrawLevelField(newx, newy);
6518 PlayLevelSound(x, y, SND_YAMYAM_DIGGING);
6520 else if (element == EL_DARK_YAMYAM && IN_LEV_FIELD(newx, newy) &&
6521 IS_FOOD_DARK_YAMYAM(Feld[newx][newy]))
6523 if (AmoebaNr[newx][newy])
6525 AmoebaCnt2[AmoebaNr[newx][newy]]--;
6526 if (Feld[newx][newy] == EL_AMOEBA_FULL ||
6527 Feld[newx][newy] == EL_BD_AMOEBA)
6528 AmoebaCnt[AmoebaNr[newx][newy]]--;
6533 if (IS_MOVING(newx, newy) || IS_BLOCKED(newx, newy))
6535 RemoveMovingField(newx, newy);
6538 if (IS_MOVING(newx, newy))
6540 RemoveMovingField(newx, newy);
6545 Feld[newx][newy] = EL_EMPTY;
6546 DrawLevelField(newx, newy);
6549 PlayLevelSound(x, y, SND_DARK_YAMYAM_DIGGING);
6551 else if ((element == EL_PACMAN || element == EL_MOLE)
6552 && IN_LEV_FIELD(newx, newy) && IS_AMOEBOID(Feld[newx][newy]))
6554 if (AmoebaNr[newx][newy])
6556 AmoebaCnt2[AmoebaNr[newx][newy]]--;
6557 if (Feld[newx][newy] == EL_AMOEBA_FULL ||
6558 Feld[newx][newy] == EL_BD_AMOEBA)
6559 AmoebaCnt[AmoebaNr[newx][newy]]--;
6562 if (element == EL_MOLE)
6564 Feld[newx][newy] = EL_AMOEBA_SHRINKING;
6565 PlayLevelSound(x, y, SND_MOLE_DIGGING);
6567 ResetGfxAnimation(x, y);
6568 GfxAction[x][y] = ACTION_DIGGING;
6569 DrawLevelField(x, y);
6571 MovDelay[newx][newy] = 0; /* start amoeba shrinking delay */
6573 return; /* wait for shrinking amoeba */
6575 else /* element == EL_PACMAN */
6577 Feld[newx][newy] = EL_EMPTY;
6578 DrawLevelField(newx, newy);
6579 PlayLevelSound(x, y, SND_PACMAN_DIGGING);
6582 else if (element == EL_MOLE && IN_LEV_FIELD(newx, newy) &&
6583 (Feld[newx][newy] == EL_AMOEBA_SHRINKING ||
6584 (Feld[newx][newy] == EL_EMPTY && Stop[newx][newy])))
6586 /* wait for shrinking amoeba to completely disappear */
6589 else if (!IN_LEV_FIELD(newx, newy) || !IS_FREE(newx, newy))
6591 /* object was running against a wall */
6596 /* !!! NEW "CE_BLOCKED" STUFF !!! -- DOES NOT WORK YET... !!! */
6597 if (move_pattern & MV_ANY_DIRECTION &&
6598 move_pattern == MovDir[x][y])
6600 int blocking_element =
6601 (IN_LEV_FIELD(newx, newy) ? Feld[newx][newy] : BorderElement);
6603 CheckElementChangeBySide(x, y, element, blocking_element, CE_BLOCKED,
6606 element = Feld[x][y]; /* element might have changed */
6610 if (GFX_ELEMENT(element) != EL_SAND) /* !!! FIX THIS (crumble) !!! */
6611 DrawLevelElementAnimation(x, y, element);
6613 if (DONT_TOUCH(element))
6614 TestIfBadThingTouchesPlayer(x, y);
6619 InitMovingField(x, y, MovDir[x][y]);
6621 PlayLevelSoundAction(x, y, ACTION_MOVING);
6625 ContinueMoving(x, y);
6628 void ContinueMoving(int x, int y)
6630 int element = Feld[x][y];
6631 struct ElementInfo *ei = &element_info[element];
6632 int direction = MovDir[x][y];
6633 int dx = (direction == MV_LEFT ? -1 : direction == MV_RIGHT ? +1 : 0);
6634 int dy = (direction == MV_UP ? -1 : direction == MV_DOWN ? +1 : 0);
6635 int newx = x + dx, newy = y + dy;
6636 int stored = Store[x][y];
6637 int stored_new = Store[newx][newy];
6638 boolean pushed_by_player = (Pushed[x][y] && IS_PLAYER(x, y));
6639 boolean pushed_by_conveyor = (Pushed[x][y] && !IS_PLAYER(x, y));
6640 boolean last_line = (newy == lev_fieldy - 1);
6642 MovPos[x][y] += getElementMoveStepsize(x, y);
6644 if (pushed_by_player) /* special case: moving object pushed by player */
6645 MovPos[x][y] = SIGN(MovPos[x][y]) * (TILEX - ABS(PLAYERINFO(x,y)->MovPos));
6647 if (ABS(MovPos[x][y]) < TILEX)
6649 DrawLevelField(x, y);
6651 return; /* element is still moving */
6654 /* element reached destination field */
6656 Feld[x][y] = EL_EMPTY;
6657 Feld[newx][newy] = element;
6658 MovPos[x][y] = 0; /* force "not moving" for "crumbled sand" */
6660 if (Store[x][y] == EL_ACID) /* element is moving into acid pool */
6662 element = Feld[newx][newy] = EL_ACID;
6664 else if (element == EL_MOLE)
6666 Feld[x][y] = EL_SAND;
6668 DrawLevelFieldCrumbledSandNeighbours(x, y);
6670 else if (element == EL_QUICKSAND_FILLING)
6672 element = Feld[newx][newy] = get_next_element(element);
6673 Store[newx][newy] = Store[x][y];
6675 else if (element == EL_QUICKSAND_EMPTYING)
6677 Feld[x][y] = get_next_element(element);
6678 element = Feld[newx][newy] = Store[x][y];
6680 else if (element == EL_MAGIC_WALL_FILLING)
6682 element = Feld[newx][newy] = get_next_element(element);
6683 if (!game.magic_wall_active)
6684 element = Feld[newx][newy] = EL_MAGIC_WALL_DEAD;
6685 Store[newx][newy] = Store[x][y];
6687 else if (element == EL_MAGIC_WALL_EMPTYING)
6689 Feld[x][y] = get_next_element(element);
6690 if (!game.magic_wall_active)
6691 Feld[x][y] = EL_MAGIC_WALL_DEAD;
6692 element = Feld[newx][newy] = Store[x][y];
6694 #if USE_NEW_CUSTOM_VALUE
6695 InitField(newx, newy, FALSE);
6698 else if (element == EL_BD_MAGIC_WALL_FILLING)
6700 element = Feld[newx][newy] = get_next_element(element);
6701 if (!game.magic_wall_active)
6702 element = Feld[newx][newy] = EL_BD_MAGIC_WALL_DEAD;
6703 Store[newx][newy] = Store[x][y];
6705 else if (element == EL_BD_MAGIC_WALL_EMPTYING)
6707 Feld[x][y] = get_next_element(element);
6708 if (!game.magic_wall_active)
6709 Feld[x][y] = EL_BD_MAGIC_WALL_DEAD;
6710 element = Feld[newx][newy] = Store[x][y];
6712 #if USE_NEW_CUSTOM_VALUE
6713 InitField(newx, newy, FALSE);
6716 else if (element == EL_AMOEBA_DROPPING)
6718 Feld[x][y] = get_next_element(element);
6719 element = Feld[newx][newy] = Store[x][y];
6721 else if (element == EL_SOKOBAN_OBJECT)
6724 Feld[x][y] = Back[x][y];
6726 if (Back[newx][newy])
6727 Feld[newx][newy] = EL_SOKOBAN_FIELD_FULL;
6729 Back[x][y] = Back[newx][newy] = 0;
6732 Store[x][y] = EL_EMPTY;
6737 MovDelay[newx][newy] = 0;
6740 if (CAN_CHANGE_OR_HAS_ACTION(element))
6742 if (CAN_CHANGE(element))
6745 /* copy element change control values to new field */
6746 ChangeDelay[newx][newy] = ChangeDelay[x][y];
6747 ChangePage[newx][newy] = ChangePage[x][y];
6748 ChangeCount[newx][newy] = ChangeCount[x][y];
6749 ChangeEvent[newx][newy] = ChangeEvent[x][y];
6752 #if USE_NEW_CUSTOM_VALUE
6753 CustomValue[newx][newy] = CustomValue[x][y];
6759 #if USE_NEW_CUSTOM_VALUE
6760 CustomValue[newx][newy] = CustomValue[x][y];
6764 ChangeDelay[x][y] = 0;
6765 ChangePage[x][y] = -1;
6766 ChangeCount[x][y] = 0;
6767 ChangeEvent[x][y] = -1;
6769 #if USE_NEW_CUSTOM_VALUE
6770 CustomValue[x][y] = 0;
6773 /* copy animation control values to new field */
6774 GfxFrame[newx][newy] = GfxFrame[x][y];
6775 GfxRandom[newx][newy] = GfxRandom[x][y]; /* keep same random value */
6776 GfxAction[newx][newy] = GfxAction[x][y]; /* keep action one frame */
6777 GfxDir[newx][newy] = GfxDir[x][y]; /* keep element direction */
6779 Pushed[x][y] = Pushed[newx][newy] = FALSE;
6781 /* some elements can leave other elements behind after moving */
6783 if (ei->move_leave_element != EL_EMPTY &&
6784 (ei->move_leave_type == LEAVE_TYPE_UNLIMITED || stored != EL_EMPTY) &&
6785 (!IS_PLAYER(x, y) || IS_WALKABLE(ei->move_leave_element)))
6787 if (IS_CUSTOM_ELEMENT(element) && ei->move_leave_element != EL_EMPTY &&
6788 (ei->move_leave_type == LEAVE_TYPE_UNLIMITED || stored != EL_EMPTY) &&
6789 (!IS_PLAYER(x, y) || IS_WALKABLE(ei->move_leave_element)))
6792 int move_leave_element = ei->move_leave_element;
6796 /* this makes it possible to leave the removed element again */
6797 if (ei->move_leave_element == EL_TRIGGER_ELEMENT)
6798 move_leave_element = (stored == EL_ACID ? EL_EMPTY : stored);
6800 /* this makes it possible to leave the removed element again */
6801 if (ei->move_leave_element == EL_TRIGGER_ELEMENT)
6802 move_leave_element = stored;
6805 /* this makes it possible to leave the removed element again */
6806 if (ei->move_leave_type == LEAVE_TYPE_LIMITED &&
6807 ei->move_leave_element == EL_TRIGGER_ELEMENT)
6808 move_leave_element = stored;
6811 Feld[x][y] = move_leave_element;
6813 if (element_info[Feld[x][y]].move_direction_initial == MV_START_PREVIOUS)
6814 MovDir[x][y] = direction;
6816 InitField(x, y, FALSE);
6818 if (GFX_CRUMBLED(Feld[x][y]))
6819 DrawLevelFieldCrumbledSandNeighbours(x, y);
6821 if (ELEM_IS_PLAYER(move_leave_element))
6822 RelocatePlayer(x, y, move_leave_element);
6825 /* do this after checking for left-behind element */
6826 ResetGfxAnimation(x, y); /* reset animation values for old field */
6828 if (!CAN_MOVE(element) ||
6829 (CAN_FALL(element) && direction == MV_DOWN &&
6830 (element == EL_SPRING ||
6831 element_info[element].move_pattern == MV_WHEN_PUSHED ||
6832 element_info[element].move_pattern == MV_WHEN_DROPPED)))
6833 GfxDir[x][y] = MovDir[newx][newy] = 0;
6835 DrawLevelField(x, y);
6836 DrawLevelField(newx, newy);
6838 Stop[newx][newy] = TRUE; /* ignore this element until the next frame */
6840 /* prevent pushed element from moving on in pushed direction */
6841 if (pushed_by_player && CAN_MOVE(element) &&
6842 element_info[element].move_pattern & MV_ANY_DIRECTION &&
6843 !(element_info[element].move_pattern & direction))
6844 TurnRound(newx, newy);
6846 /* prevent elements on conveyor belt from moving on in last direction */
6847 if (pushed_by_conveyor && CAN_FALL(element) &&
6848 direction & MV_HORIZONTAL)
6849 MovDir[newx][newy] = 0;
6851 if (!pushed_by_player)
6853 int nextx = newx + dx, nexty = newy + dy;
6854 boolean check_collision_again = IN_LEV_FIELD_AND_IS_FREE(nextx, nexty);
6856 WasJustMoving[newx][newy] = CHECK_DELAY_MOVING;
6858 if (CAN_FALL(element) && direction == MV_DOWN)
6859 WasJustFalling[newx][newy] = CHECK_DELAY_FALLING;
6861 if ((!CAN_FALL(element) || direction == MV_DOWN) && check_collision_again)
6862 CheckCollision[newx][newy] = CHECK_DELAY_COLLISION;
6865 if (DONT_TOUCH(element)) /* object may be nasty to player or others */
6867 TestIfBadThingTouchesPlayer(newx, newy);
6868 TestIfBadThingTouchesFriend(newx, newy);
6870 if (!IS_CUSTOM_ELEMENT(element))
6871 TestIfBadThingTouchesOtherBadThing(newx, newy);
6873 else if (element == EL_PENGUIN)
6874 TestIfFriendTouchesBadThing(newx, newy);
6876 /* give the player one last chance (one more frame) to move away */
6877 if (CAN_FALL(element) && direction == MV_DOWN &&
6878 (last_line || (!IS_FREE(x, newy + 1) &&
6879 (!IS_PLAYER(x, newy + 1) ||
6880 game.engine_version < VERSION_IDENT(3,1,1,0)))))
6883 if (pushed_by_player && !game.use_change_when_pushing_bug)
6885 int push_side = MV_DIR_OPPOSITE(direction);
6886 struct PlayerInfo *player = PLAYERINFO(x, y);
6888 CheckElementChangeByPlayer(newx, newy, element, CE_PUSHED_BY_PLAYER,
6889 player->index_bit, push_side);
6890 CheckTriggeredElementChangeByPlayer(newx,newy, element, CE_PLAYER_PUSHES_X,
6891 player->index_bit, push_side);
6894 if (element == EL_EMC_ANDROID && pushed_by_player) /* make another move */
6895 MovDelay[newx][newy] = 1;
6897 CheckTriggeredElementChangeBySide(x, y, element, CE_MOVE_OF_X, direction);
6899 TestIfElementTouchesCustomElement(x, y); /* empty or new element */
6902 if (ChangePage[newx][newy] != -1) /* delayed change */
6904 int page = ChangePage[newx][newy];
6905 struct ElementChangeInfo *change = &ei->change_page[page];
6907 ChangePage[newx][newy] = -1;
6909 if (change->can_change)
6911 if (ChangeElement(newx, newy, element, page))
6913 if (change->post_change_function)
6914 change->post_change_function(newx, newy);
6918 if (change->has_action)
6919 ExecuteCustomElementAction(newx, newy, element, page);
6923 TestIfElementHitsCustomElement(newx, newy, direction);
6924 TestIfPlayerTouchesCustomElement(newx, newy);
6925 TestIfElementTouchesCustomElement(newx, newy);
6928 if (IS_CUSTOM_ELEMENT(element) && ei->move_enter_element != EL_EMPTY &&
6929 IS_EQUAL_OR_IN_GROUP(stored_new, ei->move_enter_element))
6930 CheckElementChangeBySide(newx, newy, element, stored_new, CE_DIGGING_X,
6931 MV_DIR_OPPOSITE(direction));
6935 int AmoebeNachbarNr(int ax, int ay)
6938 int element = Feld[ax][ay];
6940 static int xy[4][2] =
6948 for (i = 0; i < NUM_DIRECTIONS; i++)
6950 int x = ax + xy[i][0];
6951 int y = ay + xy[i][1];
6953 if (!IN_LEV_FIELD(x, y))
6956 if (Feld[x][y] == element && AmoebaNr[x][y] > 0)
6957 group_nr = AmoebaNr[x][y];
6963 void AmoebenVereinigen(int ax, int ay)
6965 int i, x, y, xx, yy;
6966 int new_group_nr = AmoebaNr[ax][ay];
6967 static int xy[4][2] =
6975 if (new_group_nr == 0)
6978 for (i = 0; i < NUM_DIRECTIONS; i++)
6983 if (!IN_LEV_FIELD(x, y))
6986 if ((Feld[x][y] == EL_AMOEBA_FULL ||
6987 Feld[x][y] == EL_BD_AMOEBA ||
6988 Feld[x][y] == EL_AMOEBA_DEAD) &&
6989 AmoebaNr[x][y] != new_group_nr)
6991 int old_group_nr = AmoebaNr[x][y];
6993 if (old_group_nr == 0)
6996 AmoebaCnt[new_group_nr] += AmoebaCnt[old_group_nr];
6997 AmoebaCnt[old_group_nr] = 0;
6998 AmoebaCnt2[new_group_nr] += AmoebaCnt2[old_group_nr];
6999 AmoebaCnt2[old_group_nr] = 0;
7002 SCAN_PLAYFIELD(xx, yy)
7004 for (yy = 0; yy < lev_fieldy; yy++) for (xx = 0; xx < lev_fieldx; xx++)
7007 if (AmoebaNr[xx][yy] == old_group_nr)
7008 AmoebaNr[xx][yy] = new_group_nr;
7014 void AmoebeUmwandeln(int ax, int ay)
7018 if (Feld[ax][ay] == EL_AMOEBA_DEAD)
7020 int group_nr = AmoebaNr[ax][ay];
7025 printf("AmoebeUmwandeln(): ax = %d, ay = %d\n", ax, ay);
7026 printf("AmoebeUmwandeln(): This should never happen!\n");
7032 SCAN_PLAYFIELD(x, y)
7034 for (y = 0; y < lev_fieldy; y++) for (x = 0; x < lev_fieldx; x++)
7037 if (Feld[x][y] == EL_AMOEBA_DEAD && AmoebaNr[x][y] == group_nr)
7040 Feld[x][y] = EL_AMOEBA_TO_DIAMOND;
7044 PlayLevelSound(ax, ay, (IS_GEM(level.amoeba_content) ?
7045 SND_AMOEBA_TURNING_TO_GEM :
7046 SND_AMOEBA_TURNING_TO_ROCK));
7051 static int xy[4][2] =
7059 for (i = 0; i < NUM_DIRECTIONS; i++)
7064 if (!IN_LEV_FIELD(x, y))
7067 if (Feld[x][y] == EL_AMOEBA_TO_DIAMOND)
7069 PlayLevelSound(x, y, (IS_GEM(level.amoeba_content) ?
7070 SND_AMOEBA_TURNING_TO_GEM :
7071 SND_AMOEBA_TURNING_TO_ROCK));
7078 void AmoebeUmwandelnBD(int ax, int ay, int new_element)
7081 int group_nr = AmoebaNr[ax][ay];
7082 boolean done = FALSE;
7087 printf("AmoebeUmwandelnBD(): ax = %d, ay = %d\n", ax, ay);
7088 printf("AmoebeUmwandelnBD(): This should never happen!\n");
7094 SCAN_PLAYFIELD(x, y)
7096 for (y = 0; y < lev_fieldy; y++) for (x = 0; x < lev_fieldx; x++)
7099 if (AmoebaNr[x][y] == group_nr &&
7100 (Feld[x][y] == EL_AMOEBA_DEAD ||
7101 Feld[x][y] == EL_BD_AMOEBA ||
7102 Feld[x][y] == EL_AMOEBA_GROWING))
7105 Feld[x][y] = new_element;
7106 InitField(x, y, FALSE);
7107 DrawLevelField(x, y);
7113 PlayLevelSound(ax, ay, (new_element == EL_BD_ROCK ?
7114 SND_BD_AMOEBA_TURNING_TO_ROCK :
7115 SND_BD_AMOEBA_TURNING_TO_GEM));
7118 void AmoebeWaechst(int x, int y)
7120 static unsigned long sound_delay = 0;
7121 static unsigned long sound_delay_value = 0;
7123 if (!MovDelay[x][y]) /* start new growing cycle */
7127 if (DelayReached(&sound_delay, sound_delay_value))
7129 PlayLevelSoundElementAction(x, y, Store[x][y], ACTION_GROWING);
7130 sound_delay_value = 30;
7134 if (MovDelay[x][y]) /* wait some time before growing bigger */
7137 if (MovDelay[x][y]/2 && IN_SCR_FIELD(SCREENX(x), SCREENY(y)))
7139 int frame = getGraphicAnimationFrame(IMG_AMOEBA_GROWING,
7140 6 - MovDelay[x][y]);
7142 DrawGraphic(SCREENX(x), SCREENY(y), IMG_AMOEBA_GROWING, frame);
7145 if (!MovDelay[x][y])
7147 Feld[x][y] = Store[x][y];
7149 DrawLevelField(x, y);
7154 void AmoebaDisappearing(int x, int y)
7156 static unsigned long sound_delay = 0;
7157 static unsigned long sound_delay_value = 0;
7159 if (!MovDelay[x][y]) /* start new shrinking cycle */
7163 if (DelayReached(&sound_delay, sound_delay_value))
7164 sound_delay_value = 30;
7167 if (MovDelay[x][y]) /* wait some time before shrinking */
7170 if (MovDelay[x][y]/2 && IN_SCR_FIELD(SCREENX(x), SCREENY(y)))
7172 int frame = getGraphicAnimationFrame(IMG_AMOEBA_SHRINKING,
7173 6 - MovDelay[x][y]);
7175 DrawGraphic(SCREENX(x), SCREENY(y), IMG_AMOEBA_SHRINKING, frame);
7178 if (!MovDelay[x][y])
7180 Feld[x][y] = EL_EMPTY;
7181 DrawLevelField(x, y);
7183 /* don't let mole enter this field in this cycle;
7184 (give priority to objects falling to this field from above) */
7190 void AmoebeAbleger(int ax, int ay)
7193 int element = Feld[ax][ay];
7194 int graphic = el2img(element);
7195 int newax = ax, neway = ay;
7196 boolean can_drop = (element == EL_AMOEBA_WET || element == EL_EMC_DRIPPER);
7197 static int xy[4][2] =
7205 if (!level.amoeba_speed && element != EL_EMC_DRIPPER)
7207 Feld[ax][ay] = EL_AMOEBA_DEAD;
7208 DrawLevelField(ax, ay);
7212 if (IS_ANIMATED(graphic))
7213 DrawLevelGraphicAnimationIfNeeded(ax, ay, graphic);
7215 if (!MovDelay[ax][ay]) /* start making new amoeba field */
7216 MovDelay[ax][ay] = RND(FRAMES_PER_SECOND * 25 / (1 + level.amoeba_speed));
7218 if (MovDelay[ax][ay]) /* wait some time before making new amoeba */
7221 if (MovDelay[ax][ay])
7225 if (can_drop) /* EL_AMOEBA_WET or EL_EMC_DRIPPER */
7228 int x = ax + xy[start][0];
7229 int y = ay + xy[start][1];
7231 if (!IN_LEV_FIELD(x, y))
7234 if (IS_FREE(x, y) ||
7235 CAN_GROW_INTO(Feld[x][y]) ||
7236 Feld[x][y] == EL_QUICKSAND_EMPTY)
7242 if (newax == ax && neway == ay)
7245 else /* normal or "filled" (BD style) amoeba */
7248 boolean waiting_for_player = FALSE;
7250 for (i = 0; i < NUM_DIRECTIONS; i++)
7252 int j = (start + i) % 4;
7253 int x = ax + xy[j][0];
7254 int y = ay + xy[j][1];
7256 if (!IN_LEV_FIELD(x, y))
7259 if (IS_FREE(x, y) ||
7260 CAN_GROW_INTO(Feld[x][y]) ||
7261 Feld[x][y] == EL_QUICKSAND_EMPTY)
7267 else if (IS_PLAYER(x, y))
7268 waiting_for_player = TRUE;
7271 if (newax == ax && neway == ay) /* amoeba cannot grow */
7273 if (i == 4 && (!waiting_for_player || element == EL_BD_AMOEBA))
7275 Feld[ax][ay] = EL_AMOEBA_DEAD;
7276 DrawLevelField(ax, ay);
7277 AmoebaCnt[AmoebaNr[ax][ay]]--;
7279 if (AmoebaCnt[AmoebaNr[ax][ay]] <= 0) /* amoeba is completely dead */
7281 if (element == EL_AMOEBA_FULL)
7282 AmoebeUmwandeln(ax, ay);
7283 else if (element == EL_BD_AMOEBA)
7284 AmoebeUmwandelnBD(ax, ay, level.amoeba_content);
7289 else if (element == EL_AMOEBA_FULL || element == EL_BD_AMOEBA)
7291 /* amoeba gets larger by growing in some direction */
7293 int new_group_nr = AmoebaNr[ax][ay];
7296 if (new_group_nr == 0)
7298 printf("AmoebeAbleger(): newax = %d, neway = %d\n", newax, neway);
7299 printf("AmoebeAbleger(): This should never happen!\n");
7304 AmoebaNr[newax][neway] = new_group_nr;
7305 AmoebaCnt[new_group_nr]++;
7306 AmoebaCnt2[new_group_nr]++;
7308 /* if amoeba touches other amoeba(s) after growing, unify them */
7309 AmoebenVereinigen(newax, neway);
7311 if (element == EL_BD_AMOEBA && AmoebaCnt2[new_group_nr] >= 200)
7313 AmoebeUmwandelnBD(newax, neway, EL_BD_ROCK);
7319 if (!can_drop || neway < ay || !IS_FREE(newax, neway) ||
7320 (neway == lev_fieldy - 1 && newax != ax))
7322 Feld[newax][neway] = EL_AMOEBA_GROWING; /* creation of new amoeba */
7323 Store[newax][neway] = element;
7325 else if (neway == ay || element == EL_EMC_DRIPPER)
7327 Feld[newax][neway] = EL_AMOEBA_DROP; /* drop left/right of amoeba */
7329 PlayLevelSoundAction(newax, neway, ACTION_GROWING);
7333 InitMovingField(ax, ay, MV_DOWN); /* drop dripping from amoeba */
7334 Feld[ax][ay] = EL_AMOEBA_DROPPING;
7335 Store[ax][ay] = EL_AMOEBA_DROP;
7336 ContinueMoving(ax, ay);
7340 DrawLevelField(newax, neway);
7343 void Life(int ax, int ay)
7347 static int life[4] = { 2, 3, 3, 3 }; /* parameters for "game of life" */
7350 int element = Feld[ax][ay];
7351 int graphic = el2img(element);
7352 int *life_parameter = (element == EL_GAME_OF_LIFE ? level.game_of_life :
7354 boolean changed = FALSE;
7356 if (IS_ANIMATED(graphic))
7357 DrawLevelGraphicAnimationIfNeeded(ax, ay, graphic);
7362 if (!MovDelay[ax][ay]) /* start new "game of life" cycle */
7363 MovDelay[ax][ay] = life_time;
7365 if (MovDelay[ax][ay]) /* wait some time before next cycle */
7368 if (MovDelay[ax][ay])
7372 for (y1 = -1; y1 < 2; y1++) for (x1 = -1; x1 < 2; x1++)
7374 int xx = ax+x1, yy = ay+y1;
7377 if (!IN_LEV_FIELD(xx, yy))
7380 for (y2 = -1; y2 < 2; y2++) for (x2 = -1; x2 < 2; x2++)
7382 int x = xx+x2, y = yy+y2;
7384 if (!IN_LEV_FIELD(x, y) || (x == xx && y == yy))
7387 if (((Feld[x][y] == element ||
7388 (element == EL_GAME_OF_LIFE && IS_PLAYER(x, y))) &&
7390 (IS_FREE(x, y) && Stop[x][y]))
7394 if (xx == ax && yy == ay) /* field in the middle */
7396 if (nachbarn < life_parameter[0] ||
7397 nachbarn > life_parameter[1])
7399 Feld[xx][yy] = EL_EMPTY;
7401 DrawLevelField(xx, yy);
7402 Stop[xx][yy] = TRUE;
7406 else if (IS_FREE(xx, yy) || CAN_GROW_INTO(Feld[xx][yy]))
7407 { /* free border field */
7408 if (nachbarn >= life_parameter[2] &&
7409 nachbarn <= life_parameter[3])
7411 Feld[xx][yy] = element;
7412 MovDelay[xx][yy] = (element == EL_GAME_OF_LIFE ? 0 : life_time-1);
7414 DrawLevelField(xx, yy);
7415 Stop[xx][yy] = TRUE;
7422 PlayLevelSound(ax, ay, element == EL_BIOMAZE ? SND_BIOMAZE_GROWING :
7423 SND_GAME_OF_LIFE_GROWING);
7426 static void InitRobotWheel(int x, int y)
7428 ChangeDelay[x][y] = level.time_wheel * FRAMES_PER_SECOND;
7431 static void RunRobotWheel(int x, int y)
7433 PlayLevelSound(x, y, SND_ROBOT_WHEEL_ACTIVE);
7436 static void StopRobotWheel(int x, int y)
7438 if (ZX == x && ZY == y)
7442 static void InitTimegateWheel(int x, int y)
7444 ChangeDelay[x][y] = level.time_timegate * FRAMES_PER_SECOND;
7447 static void RunTimegateWheel(int x, int y)
7449 PlayLevelSound(x, y, SND_TIMEGATE_SWITCH_ACTIVE);
7452 static void InitMagicBallDelay(int x, int y)
7455 ChangeDelay[x][y] = (level.ball_time + 1) * 8 + 1;
7457 ChangeDelay[x][y] = level.ball_time * FRAMES_PER_SECOND + 1;
7461 static void ActivateMagicBall(int bx, int by)
7465 if (level.ball_random)
7467 int pos_border = RND(8); /* select one of the eight border elements */
7468 int pos_content = (pos_border > 3 ? pos_border + 1 : pos_border);
7469 int xx = pos_content % 3;
7470 int yy = pos_content / 3;
7475 if (IN_LEV_FIELD(x, y) && Feld[x][y] == EL_EMPTY)
7476 CreateField(x, y, level.ball_content[game.ball_content_nr].e[xx][yy]);
7480 for (y = by - 1; y <= by + 1; y++) for (x = bx - 1; x <= bx + 1; x++)
7482 int xx = x - bx + 1;
7483 int yy = y - by + 1;
7485 if (IN_LEV_FIELD(x, y) && Feld[x][y] == EL_EMPTY)
7486 CreateField(x, y, level.ball_content[game.ball_content_nr].e[xx][yy]);
7490 game.ball_content_nr = (game.ball_content_nr + 1) % level.num_ball_contents;
7493 static void InitDiagonalMovingElement(int x, int y)
7496 MovDelay[x][y] = level.android_move_time;
7500 void CheckExit(int x, int y)
7502 if (local_player->gems_still_needed > 0 ||
7503 local_player->sokobanfields_still_needed > 0 ||
7504 local_player->lights_still_needed > 0)
7506 int element = Feld[x][y];
7507 int graphic = el2img(element);
7509 if (IS_ANIMATED(graphic))
7510 DrawLevelGraphicAnimationIfNeeded(x, y, graphic);
7515 if (AllPlayersGone) /* do not re-open exit door closed after last player */
7518 Feld[x][y] = EL_EXIT_OPENING;
7520 PlayLevelSoundNearest(x, y, SND_CLASS_EXIT_OPENING);
7523 void CheckExitSP(int x, int y)
7525 if (local_player->gems_still_needed > 0)
7527 int element = Feld[x][y];
7528 int graphic = el2img(element);
7530 if (IS_ANIMATED(graphic))
7531 DrawLevelGraphicAnimationIfNeeded(x, y, graphic);
7536 if (AllPlayersGone) /* do not re-open exit door closed after last player */
7539 Feld[x][y] = EL_SP_EXIT_OPENING;
7541 PlayLevelSoundNearest(x, y, SND_CLASS_SP_EXIT_OPENING);
7544 static void CloseAllOpenTimegates()
7549 SCAN_PLAYFIELD(x, y)
7551 for (y = 0; y < lev_fieldy; y++) for (x = 0; x < lev_fieldx; x++)
7554 int element = Feld[x][y];
7556 if (element == EL_TIMEGATE_OPEN || element == EL_TIMEGATE_OPENING)
7558 Feld[x][y] = EL_TIMEGATE_CLOSING;
7560 PlayLevelSoundAction(x, y, ACTION_CLOSING);
7565 void EdelsteinFunkeln(int x, int y)
7567 if (!IN_SCR_FIELD(SCREENX(x), SCREENY(y)) || IS_MOVING(x, y))
7570 if (Feld[x][y] == EL_BD_DIAMOND)
7573 if (MovDelay[x][y] == 0) /* next animation frame */
7574 MovDelay[x][y] = 11 * !SimpleRND(500);
7576 if (MovDelay[x][y] != 0) /* wait some time before next frame */
7580 if (setup.direct_draw && MovDelay[x][y])
7581 SetDrawtoField(DRAW_BUFFERED);
7583 DrawLevelElementAnimation(x, y, Feld[x][y]);
7585 if (MovDelay[x][y] != 0)
7587 int frame = getGraphicAnimationFrame(IMG_TWINKLE_WHITE,
7588 10 - MovDelay[x][y]);
7590 DrawGraphicThruMask(SCREENX(x), SCREENY(y), IMG_TWINKLE_WHITE, frame);
7592 if (setup.direct_draw)
7596 dest_x = FX + SCREENX(x) * TILEX;
7597 dest_y = FY + SCREENY(y) * TILEY;
7599 BlitBitmap(drawto_field, window,
7600 dest_x, dest_y, TILEX, TILEY, dest_x, dest_y);
7601 SetDrawtoField(DRAW_DIRECT);
7607 void MauerWaechst(int x, int y)
7611 if (!MovDelay[x][y]) /* next animation frame */
7612 MovDelay[x][y] = 3 * delay;
7614 if (MovDelay[x][y]) /* wait some time before next frame */
7618 if (IN_SCR_FIELD(SCREENX(x), SCREENY(y)))
7620 int graphic = el_dir2img(Feld[x][y], GfxDir[x][y]);
7621 int frame = getGraphicAnimationFrame(graphic, 17 - MovDelay[x][y]);
7623 DrawGraphic(SCREENX(x), SCREENY(y), graphic, frame);
7626 if (!MovDelay[x][y])
7628 if (MovDir[x][y] == MV_LEFT)
7630 if (IN_LEV_FIELD(x - 1, y) && IS_WALL(Feld[x - 1][y]))
7631 DrawLevelField(x - 1, y);
7633 else if (MovDir[x][y] == MV_RIGHT)
7635 if (IN_LEV_FIELD(x + 1, y) && IS_WALL(Feld[x + 1][y]))
7636 DrawLevelField(x + 1, y);
7638 else if (MovDir[x][y] == MV_UP)
7640 if (IN_LEV_FIELD(x, y - 1) && IS_WALL(Feld[x][y - 1]))
7641 DrawLevelField(x, y - 1);
7645 if (IN_LEV_FIELD(x, y + 1) && IS_WALL(Feld[x][y + 1]))
7646 DrawLevelField(x, y + 1);
7649 Feld[x][y] = Store[x][y];
7651 GfxDir[x][y] = MovDir[x][y] = MV_NONE;
7652 DrawLevelField(x, y);
7657 void MauerAbleger(int ax, int ay)
7659 int element = Feld[ax][ay];
7660 int graphic = el2img(element);
7661 boolean oben_frei = FALSE, unten_frei = FALSE;
7662 boolean links_frei = FALSE, rechts_frei = FALSE;
7663 boolean oben_massiv = FALSE, unten_massiv = FALSE;
7664 boolean links_massiv = FALSE, rechts_massiv = FALSE;
7665 boolean new_wall = FALSE;
7667 if (IS_ANIMATED(graphic))
7668 DrawLevelGraphicAnimationIfNeeded(ax, ay, graphic);
7670 if (!MovDelay[ax][ay]) /* start building new wall */
7671 MovDelay[ax][ay] = 6;
7673 if (MovDelay[ax][ay]) /* wait some time before building new wall */
7676 if (MovDelay[ax][ay])
7680 if (IN_LEV_FIELD(ax, ay-1) && IS_FREE(ax, ay-1))
7682 if (IN_LEV_FIELD(ax, ay+1) && IS_FREE(ax, ay+1))
7684 if (IN_LEV_FIELD(ax-1, ay) && IS_FREE(ax-1, ay))
7686 if (IN_LEV_FIELD(ax+1, ay) && IS_FREE(ax+1, ay))
7689 if (element == EL_EXPANDABLE_WALL_VERTICAL ||
7690 element == EL_EXPANDABLE_WALL_ANY)
7694 Feld[ax][ay-1] = EL_EXPANDABLE_WALL_GROWING;
7695 Store[ax][ay-1] = element;
7696 GfxDir[ax][ay-1] = MovDir[ax][ay-1] = MV_UP;
7697 if (IN_SCR_FIELD(SCREENX(ax), SCREENY(ay-1)))
7698 DrawGraphic(SCREENX(ax), SCREENY(ay - 1),
7699 IMG_EXPANDABLE_WALL_GROWING_UP, 0);
7704 Feld[ax][ay+1] = EL_EXPANDABLE_WALL_GROWING;
7705 Store[ax][ay+1] = element;
7706 GfxDir[ax][ay+1] = MovDir[ax][ay+1] = MV_DOWN;
7707 if (IN_SCR_FIELD(SCREENX(ax), SCREENY(ay+1)))
7708 DrawGraphic(SCREENX(ax), SCREENY(ay + 1),
7709 IMG_EXPANDABLE_WALL_GROWING_DOWN, 0);
7714 if (element == EL_EXPANDABLE_WALL_HORIZONTAL ||
7715 element == EL_EXPANDABLE_WALL_ANY ||
7716 element == EL_EXPANDABLE_WALL)
7720 Feld[ax-1][ay] = EL_EXPANDABLE_WALL_GROWING;
7721 Store[ax-1][ay] = element;
7722 GfxDir[ax-1][ay] = MovDir[ax-1][ay] = MV_LEFT;
7723 if (IN_SCR_FIELD(SCREENX(ax-1), SCREENY(ay)))
7724 DrawGraphic(SCREENX(ax - 1), SCREENY(ay),
7725 IMG_EXPANDABLE_WALL_GROWING_LEFT, 0);
7731 Feld[ax+1][ay] = EL_EXPANDABLE_WALL_GROWING;
7732 Store[ax+1][ay] = element;
7733 GfxDir[ax+1][ay] = MovDir[ax+1][ay] = MV_RIGHT;
7734 if (IN_SCR_FIELD(SCREENX(ax+1), SCREENY(ay)))
7735 DrawGraphic(SCREENX(ax + 1), SCREENY(ay),
7736 IMG_EXPANDABLE_WALL_GROWING_RIGHT, 0);
7741 if (element == EL_EXPANDABLE_WALL && (links_frei || rechts_frei))
7742 DrawLevelField(ax, ay);
7744 if (!IN_LEV_FIELD(ax, ay-1) || IS_WALL(Feld[ax][ay-1]))
7746 if (!IN_LEV_FIELD(ax, ay+1) || IS_WALL(Feld[ax][ay+1]))
7747 unten_massiv = TRUE;
7748 if (!IN_LEV_FIELD(ax-1, ay) || IS_WALL(Feld[ax-1][ay]))
7749 links_massiv = TRUE;
7750 if (!IN_LEV_FIELD(ax+1, ay) || IS_WALL(Feld[ax+1][ay]))
7751 rechts_massiv = TRUE;
7753 if (((oben_massiv && unten_massiv) ||
7754 element == EL_EXPANDABLE_WALL_HORIZONTAL ||
7755 element == EL_EXPANDABLE_WALL) &&
7756 ((links_massiv && rechts_massiv) ||
7757 element == EL_EXPANDABLE_WALL_VERTICAL))
7758 Feld[ax][ay] = EL_WALL;
7761 PlayLevelSoundAction(ax, ay, ACTION_GROWING);
7764 void CheckForDragon(int x, int y)
7767 boolean dragon_found = FALSE;
7768 static int xy[4][2] =
7776 for (i = 0; i < NUM_DIRECTIONS; i++)
7778 for (j = 0; j < 4; j++)
7780 int xx = x + j * xy[i][0], yy = y + j * xy[i][1];
7782 if (IN_LEV_FIELD(xx, yy) &&
7783 (Feld[xx][yy] == EL_FLAMES || Feld[xx][yy] == EL_DRAGON))
7785 if (Feld[xx][yy] == EL_DRAGON)
7786 dragon_found = TRUE;
7795 for (i = 0; i < NUM_DIRECTIONS; i++)
7797 for (j = 0; j < 3; j++)
7799 int xx = x + j * xy[i][0], yy = y + j * xy[i][1];
7801 if (IN_LEV_FIELD(xx, yy) && Feld[xx][yy] == EL_FLAMES)
7803 Feld[xx][yy] = EL_EMPTY;
7804 DrawLevelField(xx, yy);
7813 static void InitBuggyBase(int x, int y)
7815 int element = Feld[x][y];
7816 int activating_delay = FRAMES_PER_SECOND / 4;
7819 (element == EL_SP_BUGGY_BASE ?
7820 2 * FRAMES_PER_SECOND + RND(5 * FRAMES_PER_SECOND) - activating_delay :
7821 element == EL_SP_BUGGY_BASE_ACTIVATING ?
7823 element == EL_SP_BUGGY_BASE_ACTIVE ?
7824 1 * FRAMES_PER_SECOND + RND(1 * FRAMES_PER_SECOND) : 1);
7827 static void WarnBuggyBase(int x, int y)
7830 static int xy[4][2] =
7838 for (i = 0; i < NUM_DIRECTIONS; i++)
7840 int xx = x + xy[i][0];
7841 int yy = y + xy[i][1];
7843 if (IN_LEV_FIELD(xx, yy) && IS_PLAYER(xx, yy))
7845 PlayLevelSound(x, y, SND_SP_BUGGY_BASE_ACTIVE);
7852 static void InitTrap(int x, int y)
7854 ChangeDelay[x][y] = 2 * FRAMES_PER_SECOND + RND(5 * FRAMES_PER_SECOND);
7857 static void ActivateTrap(int x, int y)
7859 PlayLevelSound(x, y, SND_TRAP_ACTIVATING);
7862 static void ChangeActiveTrap(int x, int y)
7864 int graphic = IMG_TRAP_ACTIVE;
7866 /* if new animation frame was drawn, correct crumbled sand border */
7867 if (IS_NEW_FRAME(GfxFrame[x][y], graphic))
7868 DrawLevelFieldCrumbledSand(x, y);
7871 static int getSpecialActionElement(int element, int number, int base_element)
7873 return (element != EL_EMPTY ? element :
7874 number != -1 ? base_element + number - 1 :
7878 static int getModifiedActionNumber(int value_old, int operator, int operand,
7879 int value_min, int value_max)
7881 int value_new = (operator == CA_MODE_SET ? operand :
7882 operator == CA_MODE_ADD ? value_old + operand :
7883 operator == CA_MODE_SUBTRACT ? value_old - operand :
7884 operator == CA_MODE_MULTIPLY ? value_old * operand :
7885 operator == CA_MODE_DIVIDE ? value_old / MAX(1, operand) :
7886 operator == CA_MODE_MODULO ? value_old % MAX(1, operand) :
7889 return (value_new < value_min ? value_min :
7890 value_new > value_max ? value_max :
7894 static void ExecuteCustomElementAction(int x, int y, int element, int page)
7896 struct ElementInfo *ei = &element_info[element];
7897 struct ElementChangeInfo *change = &ei->change_page[page];
7898 int target_element = change->target_element;
7899 int action_type = change->action_type;
7900 int action_mode = change->action_mode;
7901 int action_arg = change->action_arg;
7904 if (!change->has_action)
7907 /* ---------- determine action paramater values -------------------------- */
7909 int level_time_value =
7910 (level.time > 0 ? TimeLeft :
7913 int action_arg_element =
7914 (action_arg == CA_ARG_PLAYER_TRIGGER ? change->actual_trigger_player :
7915 action_arg == CA_ARG_ELEMENT_TRIGGER ? change->actual_trigger_element :
7916 action_arg == CA_ARG_ELEMENT_TARGET ? change->target_element :
7919 int action_arg_direction =
7920 (action_arg >= CA_ARG_DIRECTION_LEFT &&
7921 action_arg <= CA_ARG_DIRECTION_DOWN ? action_arg - CA_ARG_DIRECTION :
7922 action_arg == CA_ARG_DIRECTION_TRIGGER ?
7923 change->actual_trigger_side :
7924 action_arg == CA_ARG_DIRECTION_TRIGGER_BACK ?
7925 MV_DIR_OPPOSITE(change->actual_trigger_side) :
7928 int action_arg_number_min =
7929 (action_type == CA_SET_PLAYER_SPEED ? STEPSIZE_NOT_MOVING :
7932 int action_arg_number_max =
7933 (action_type == CA_SET_PLAYER_SPEED ? STEPSIZE_EVEN_FASTER :
7934 action_type == CA_SET_LEVEL_GEMS ? 999 :
7935 action_type == CA_SET_LEVEL_TIME ? 9999 :
7936 action_type == CA_SET_LEVEL_SCORE ? 99999 :
7937 action_type == CA_SET_CE_VALUE ? 9999 :
7938 action_type == CA_SET_CE_SCORE ? 9999 :
7941 int action_arg_number_reset =
7942 (action_type == CA_SET_PLAYER_SPEED ? level.initial_player_stepsize :
7943 action_type == CA_SET_LEVEL_GEMS ? level.gems_needed :
7944 action_type == CA_SET_LEVEL_TIME ? level.time :
7945 action_type == CA_SET_LEVEL_SCORE ? 0 :
7947 action_type == CA_SET_CE_VALUE ? GET_NEW_CE_VALUE(element) :
7949 action_type == CA_SET_CE_VALUE ? ei->custom_value_initial :
7951 action_type == CA_SET_CE_SCORE ? 0 :
7954 int action_arg_number =
7955 (action_arg <= CA_ARG_MAX ? action_arg :
7956 action_arg >= CA_ARG_SPEED_NOT_MOVING &&
7957 action_arg <= CA_ARG_SPEED_EVEN_FASTER ? (action_arg - CA_ARG_SPEED) :
7958 action_arg == CA_ARG_SPEED_RESET ? action_arg_number_reset :
7959 action_arg == CA_ARG_NUMBER_MIN ? action_arg_number_min :
7960 action_arg == CA_ARG_NUMBER_MAX ? action_arg_number_max :
7961 action_arg == CA_ARG_NUMBER_RESET ? action_arg_number_reset :
7962 #if USE_NEW_CUSTOM_VALUE
7963 action_arg == CA_ARG_NUMBER_CE_VALUE ? CustomValue[x][y] :
7965 action_arg == CA_ARG_NUMBER_CE_VALUE ? ei->custom_value_initial :
7967 action_arg == CA_ARG_NUMBER_CE_SCORE ? ei->collect_score :
7968 action_arg == CA_ARG_NUMBER_CE_DELAY ? GET_CE_DELAY_VALUE(change) :
7969 action_arg == CA_ARG_NUMBER_LEVEL_TIME ? level_time_value :
7970 action_arg == CA_ARG_NUMBER_LEVEL_GEMS ? local_player->gems_still_needed :
7971 action_arg == CA_ARG_NUMBER_LEVEL_SCORE ? local_player->score :
7972 action_arg == CA_ARG_ELEMENT_CV_TARGET ? GET_NEW_CE_VALUE(target_element):
7973 action_arg == CA_ARG_ELEMENT_CV_TRIGGER ? change->actual_trigger_ce_value:
7974 action_arg == CA_ARG_ELEMENT_CS_TARGET ? GET_CE_SCORE(target_element) :
7975 action_arg == CA_ARG_ELEMENT_CS_TRIGGER ? change->actual_trigger_ce_score:
7976 action_arg == CA_ARG_ELEMENT_NR_TARGET ? change->target_element :
7977 action_arg == CA_ARG_ELEMENT_NR_TRIGGER ? change->actual_trigger_element :
7980 int action_arg_number_old =
7981 (action_type == CA_SET_LEVEL_GEMS ? local_player->gems_still_needed :
7982 action_type == CA_SET_LEVEL_TIME ? TimeLeft :
7983 action_type == CA_SET_LEVEL_SCORE ? local_player->score :
7984 action_type == CA_SET_CE_VALUE ? CustomValue[x][y] :
7985 action_type == CA_SET_CE_SCORE ? ei->collect_score :
7988 int action_arg_number_new =
7989 getModifiedActionNumber(action_arg_number_old,
7990 action_mode, action_arg_number,
7991 action_arg_number_min, action_arg_number_max);
7993 int trigger_player_bits =
7994 (change->actual_trigger_player >= EL_PLAYER_1 &&
7995 change->actual_trigger_player <= EL_PLAYER_4 ?
7996 (1 << (change->actual_trigger_player - EL_PLAYER_1)) :
7999 int action_arg_player_bits =
8000 (action_arg >= CA_ARG_PLAYER_1 &&
8001 action_arg <= CA_ARG_PLAYER_4 ? action_arg - CA_ARG_PLAYER :
8002 action_arg == CA_ARG_PLAYER_TRIGGER ? trigger_player_bits :
8005 /* ---------- execute action -------------------------------------------- */
8014 /* ---------- level actions ------------------------------------------- */
8016 case CA_RESTART_LEVEL:
8018 game.restart_level = TRUE;
8023 case CA_SHOW_ENVELOPE:
8025 int element = getSpecialActionElement(action_arg_element,
8026 action_arg_number, EL_ENVELOPE_1);
8028 if (IS_ENVELOPE(element))
8029 local_player->show_envelope = element;
8034 case CA_SET_LEVEL_TIME:
8036 if (level.time > 0) /* only modify limited time value */
8038 TimeLeft = action_arg_number_new;
8040 DrawGameValue_Time(TimeLeft);
8042 if (!TimeLeft && setup.time_limit)
8043 for (i = 0; i < MAX_PLAYERS; i++)
8044 KillPlayer(&stored_player[i]);
8050 case CA_SET_LEVEL_SCORE:
8052 local_player->score = action_arg_number_new;
8054 DrawGameValue_Score(local_player->score);
8059 case CA_SET_LEVEL_GEMS:
8061 local_player->gems_still_needed = action_arg_number_new;
8063 DrawGameValue_Emeralds(local_player->gems_still_needed);
8068 case CA_SET_LEVEL_GRAVITY:
8070 game.gravity = (action_arg == CA_ARG_GRAVITY_OFF ? FALSE :
8071 action_arg == CA_ARG_GRAVITY_ON ? TRUE :
8072 action_arg == CA_ARG_GRAVITY_TOGGLE ? !game.gravity :
8077 case CA_SET_LEVEL_WIND:
8079 game.wind_direction = action_arg_direction;
8084 /* ---------- player actions ------------------------------------------ */
8086 case CA_MOVE_PLAYER:
8088 /* automatically move to the next field in specified direction */
8089 for (i = 0; i < MAX_PLAYERS; i++)
8090 if (trigger_player_bits & (1 << i))
8091 stored_player[i].programmed_action = action_arg_direction;
8096 case CA_EXIT_PLAYER:
8098 for (i = 0; i < MAX_PLAYERS; i++)
8099 if (action_arg_player_bits & (1 << i))
8100 stored_player[i].LevelSolved = stored_player[i].GameOver = TRUE;
8105 case CA_KILL_PLAYER:
8107 for (i = 0; i < MAX_PLAYERS; i++)
8108 if (action_arg_player_bits & (1 << i))
8109 KillPlayer(&stored_player[i]);
8114 case CA_SET_PLAYER_KEYS:
8116 int key_state = (action_mode == CA_MODE_ADD ? TRUE : FALSE);
8117 int element = getSpecialActionElement(action_arg_element,
8118 action_arg_number, EL_KEY_1);
8120 if (IS_KEY(element))
8122 for (i = 0; i < MAX_PLAYERS; i++)
8124 if (trigger_player_bits & (1 << i))
8126 stored_player[i].key[KEY_NR(element)] = key_state;
8129 DrawGameDoorValues();
8131 DrawGameValue_Keys(stored_player[i].key);
8134 redraw_mask |= REDRAW_DOOR_1;
8142 case CA_SET_PLAYER_SPEED:
8144 for (i = 0; i < MAX_PLAYERS; i++)
8146 if (trigger_player_bits & (1 << i))
8148 int move_stepsize = TILEX / stored_player[i].move_delay_value;
8150 if (action_arg == CA_ARG_SPEED_FASTER &&
8151 stored_player[i].cannot_move)
8153 action_arg_number = STEPSIZE_VERY_SLOW;
8155 else if (action_arg == CA_ARG_SPEED_SLOWER ||
8156 action_arg == CA_ARG_SPEED_FASTER)
8158 action_arg_number = 2;
8159 action_mode = (action_arg == CA_ARG_SPEED_SLOWER ? CA_MODE_DIVIDE :
8164 getModifiedActionNumber(move_stepsize,
8167 action_arg_number_min,
8168 action_arg_number_max);
8171 SetPlayerMoveSpeed(&stored_player[i], move_stepsize, FALSE);
8173 /* make sure that value is power of 2 */
8174 move_stepsize = (1 << log_2(move_stepsize));
8176 /* do no immediately change -- the player might just be moving */
8177 stored_player[i].move_delay_value_next = TILEX / move_stepsize;
8179 stored_player[i].cannot_move =
8180 (action_arg == CA_ARG_SPEED_NOT_MOVING ? TRUE : FALSE);
8188 case CA_SET_PLAYER_SHIELD:
8190 for (i = 0; i < MAX_PLAYERS; i++)
8192 if (trigger_player_bits & (1 << i))
8194 if (action_arg == CA_ARG_SHIELD_OFF)
8196 stored_player[i].shield_normal_time_left = 0;
8197 stored_player[i].shield_deadly_time_left = 0;
8199 else if (action_arg == CA_ARG_SHIELD_NORMAL)
8201 stored_player[i].shield_normal_time_left = 999999;
8203 else if (action_arg == CA_ARG_SHIELD_DEADLY)
8205 stored_player[i].shield_normal_time_left = 999999;
8206 stored_player[i].shield_deadly_time_left = 999999;
8214 case CA_SET_PLAYER_ARTWORK:
8216 for (i = 0; i < MAX_PLAYERS; i++)
8218 if (trigger_player_bits & (1 << i))
8220 int artwork_element = action_arg_element;
8222 if (action_arg == CA_ARG_ELEMENT_RESET)
8224 (level.use_artwork_element[i] ? level.artwork_element[i] :
8225 stored_player[i].element_nr);
8227 stored_player[i].artwork_element = artwork_element;
8229 SetPlayerWaiting(&stored_player[i], FALSE);
8231 /* set number of special actions for bored and sleeping animation */
8232 stored_player[i].num_special_action_bored =
8233 get_num_special_action(artwork_element,
8234 ACTION_BORING_1, ACTION_BORING_LAST);
8235 stored_player[i].num_special_action_sleeping =
8236 get_num_special_action(artwork_element,
8237 ACTION_SLEEPING_1, ACTION_SLEEPING_LAST);
8244 /* ---------- CE actions ---------------------------------------------- */
8246 case CA_SET_CE_VALUE:
8248 #if USE_NEW_CUSTOM_VALUE
8249 int last_custom_value = CustomValue[x][y];
8251 CustomValue[x][y] = action_arg_number_new;
8254 printf("::: Count == %d\n", CustomValue[x][y]);
8257 if (CustomValue[x][y] == 0 && last_custom_value > 0)
8260 printf("::: CE_VALUE_GETS_ZERO\n");
8263 CheckElementChange(x, y, element, EL_UNDEFINED, CE_VALUE_GETS_ZERO);
8264 CheckTriggeredElementChange(x, y, element, CE_VALUE_GETS_ZERO_OF_X);
8267 printf("::: RESULT: %d, %d\n", Feld[x][y], ChangePage[x][y]);
8275 case CA_SET_CE_SCORE:
8277 ei->collect_score = action_arg_number_new;
8282 /* ---------- engine actions ------------------------------------------ */
8284 case CA_SET_ENGINE_SCAN_MODE:
8286 InitPlayfieldScanMode(action_arg);
8296 static void CreateFieldExt(int x, int y, int element, boolean is_change)
8298 int old_element = Feld[x][y];
8299 int new_element = get_element_from_group_element(element);
8300 int previous_move_direction = MovDir[x][y];
8301 #if USE_NEW_CUSTOM_VALUE
8302 int last_ce_value = CustomValue[x][y];
8304 boolean add_player = (ELEM_IS_PLAYER(new_element) &&
8305 IS_WALKABLE(old_element));
8308 /* check if element under player changes from accessible to unaccessible
8309 (needed for special case of dropping element which then changes) */
8310 if (IS_PLAYER(x, y) && !PLAYER_EXPLOSION_PROTECTED(x, y) &&
8311 IS_ACCESSIBLE(old_element) && !IS_ACCESSIBLE(new_element))
8321 if (IS_MOVING(x, y) || IS_BLOCKED(x, y))
8322 RemoveMovingField(x, y);
8326 Feld[x][y] = new_element;
8328 ResetGfxAnimation(x, y);
8329 ResetRandomAnimationValue(x, y);
8331 if (element_info[new_element].move_direction_initial == MV_START_PREVIOUS)
8332 MovDir[x][y] = previous_move_direction;
8334 #if USE_NEW_CUSTOM_VALUE
8335 if (element_info[new_element].use_last_ce_value)
8336 CustomValue[x][y] = last_ce_value;
8339 InitField_WithBug1(x, y, FALSE);
8341 new_element = Feld[x][y]; /* element may have changed */
8343 DrawLevelField(x, y);
8345 if (GFX_CRUMBLED(new_element))
8346 DrawLevelFieldCrumbledSandNeighbours(x, y);
8350 /* check if element under player changes from accessible to unaccessible
8351 (needed for special case of dropping element which then changes) */
8352 if (IS_PLAYER(x, y) && !PLAYER_EXPLOSION_PROTECTED(x, y) &&
8353 IS_ACCESSIBLE(old_element) && !IS_ACCESSIBLE(new_element))
8361 /* "ChangeCount" not set yet to allow "entered by player" change one time */
8362 if (ELEM_IS_PLAYER(new_element))
8363 RelocatePlayer(x, y, new_element);
8366 ChangeCount[x][y]++; /* count number of changes in the same frame */
8368 TestIfBadThingTouchesPlayer(x, y);
8369 TestIfPlayerTouchesCustomElement(x, y);
8370 TestIfElementTouchesCustomElement(x, y);
8373 static void CreateField(int x, int y, int element)
8375 CreateFieldExt(x, y, element, FALSE);
8378 static void CreateElementFromChange(int x, int y, int element)
8380 element = GET_VALID_RUNTIME_ELEMENT(element);
8382 #if USE_STOP_CHANGED_ELEMENTS
8383 if (game.engine_version >= VERSION_IDENT(3,2,0,7))
8385 int old_element = Feld[x][y];
8387 /* prevent changed element from moving in same engine frame
8388 unless both old and new element can either fall or move */
8389 if ((!CAN_FALL(old_element) || !CAN_FALL(element)) &&
8390 (!CAN_MOVE(old_element) || !CAN_MOVE(element)))
8395 CreateFieldExt(x, y, element, TRUE);
8398 static boolean ChangeElement(int x, int y, int element, int page)
8400 struct ElementInfo *ei = &element_info[element];
8401 struct ElementChangeInfo *change = &ei->change_page[page];
8402 int ce_value = CustomValue[x][y];
8403 int ce_score = ei->collect_score;
8405 int old_element = Feld[x][y];
8407 /* always use default change event to prevent running into a loop */
8408 if (ChangeEvent[x][y] == -1)
8409 ChangeEvent[x][y] = CE_DELAY;
8411 if (ChangeEvent[x][y] == CE_DELAY)
8413 /* reset actual trigger element, trigger player and action element */
8414 change->actual_trigger_element = EL_EMPTY;
8415 change->actual_trigger_player = EL_PLAYER_1;
8416 change->actual_trigger_side = CH_SIDE_NONE;
8417 change->actual_trigger_ce_value = 0;
8418 change->actual_trigger_ce_score = 0;
8421 /* do not change elements more than a specified maximum number of changes */
8422 if (ChangeCount[x][y] >= game.max_num_changes_per_frame)
8425 ChangeCount[x][y]++; /* count number of changes in the same frame */
8427 if (change->explode)
8434 if (change->use_target_content)
8436 boolean complete_replace = TRUE;
8437 boolean can_replace[3][3];
8440 for (yy = 0; yy < 3; yy++) for (xx = 0; xx < 3 ; xx++)
8443 boolean is_walkable;
8444 boolean is_diggable;
8445 boolean is_collectible;
8446 boolean is_removable;
8447 boolean is_destructible;
8448 int ex = x + xx - 1;
8449 int ey = y + yy - 1;
8450 int content_element = change->target_content.e[xx][yy];
8453 can_replace[xx][yy] = TRUE;
8455 if (ex == x && ey == y) /* do not check changing element itself */
8458 if (content_element == EL_EMPTY_SPACE)
8460 can_replace[xx][yy] = FALSE; /* do not replace border with space */
8465 if (!IN_LEV_FIELD(ex, ey))
8467 can_replace[xx][yy] = FALSE;
8468 complete_replace = FALSE;
8475 if (IS_MOVING(ex, ey) || IS_BLOCKED(ex, ey))
8476 e = MovingOrBlocked2Element(ex, ey);
8478 is_empty = (IS_FREE(ex, ey) ||
8479 (IS_FREE_OR_PLAYER(ex, ey) && IS_WALKABLE(content_element)));
8481 is_walkable = (is_empty || IS_WALKABLE(e));
8482 is_diggable = (is_empty || IS_DIGGABLE(e));
8483 is_collectible = (is_empty || IS_COLLECTIBLE(e));
8484 is_destructible = (is_empty || !IS_INDESTRUCTIBLE(e));
8485 is_removable = (is_diggable || is_collectible);
8487 can_replace[xx][yy] =
8488 (((change->replace_when == CP_WHEN_EMPTY && is_empty) ||
8489 (change->replace_when == CP_WHEN_WALKABLE && is_walkable) ||
8490 (change->replace_when == CP_WHEN_DIGGABLE && is_diggable) ||
8491 (change->replace_when == CP_WHEN_COLLECTIBLE && is_collectible) ||
8492 (change->replace_when == CP_WHEN_REMOVABLE && is_removable) ||
8493 (change->replace_when == CP_WHEN_DESTRUCTIBLE && is_destructible)) &&
8494 !(IS_PLAYER(ex, ey) && ELEM_IS_PLAYER(content_element)));
8496 if (!can_replace[xx][yy])
8497 complete_replace = FALSE;
8500 if (!change->only_if_complete || complete_replace)
8502 boolean something_has_changed = FALSE;
8504 if (change->only_if_complete && change->use_random_replace &&
8505 RND(100) < change->random_percentage)
8508 for (yy = 0; yy < 3; yy++) for (xx = 0; xx < 3 ; xx++)
8510 int ex = x + xx - 1;
8511 int ey = y + yy - 1;
8512 int content_element;
8514 if (can_replace[xx][yy] && (!change->use_random_replace ||
8515 RND(100) < change->random_percentage))
8517 if (IS_MOVING(ex, ey) || IS_BLOCKED(ex, ey))
8518 RemoveMovingField(ex, ey);
8520 ChangeEvent[ex][ey] = ChangeEvent[x][y];
8522 content_element = change->target_content.e[xx][yy];
8523 target_element = GET_TARGET_ELEMENT(content_element, change,
8524 ce_value, ce_score);
8526 CreateElementFromChange(ex, ey, target_element);
8528 something_has_changed = TRUE;
8530 /* for symmetry reasons, freeze newly created border elements */
8531 if (ex != x || ey != y)
8532 Stop[ex][ey] = TRUE; /* no more moving in this frame */
8536 if (something_has_changed)
8538 PlayLevelSoundElementAction(x, y, element, ACTION_CHANGING);
8539 PlayLevelSoundElementAction(x, y, element, ACTION_PAGE_1 + page);
8545 target_element = GET_TARGET_ELEMENT(change->target_element, change,
8546 ce_value, ce_score);
8548 if (element == EL_DIAGONAL_GROWING ||
8549 element == EL_DIAGONAL_SHRINKING)
8551 target_element = Store[x][y];
8553 Store[x][y] = EL_EMPTY;
8556 CreateElementFromChange(x, y, target_element);
8558 PlayLevelSoundElementAction(x, y, element, ACTION_CHANGING);
8559 PlayLevelSoundElementAction(x, y, element, ACTION_PAGE_1 + page);
8562 /* this uses direct change before indirect change */
8563 CheckTriggeredElementChangeByPage(x, y, old_element, CE_CHANGE_OF_X, page);
8568 #if USE_NEW_DELAYED_ACTION
8570 static void HandleElementChange(int x, int y, int page)
8572 int element = MovingOrBlocked2Element(x, y);
8573 struct ElementInfo *ei = &element_info[element];
8574 struct ElementChangeInfo *change = &ei->change_page[page];
8577 if (!CAN_CHANGE_OR_HAS_ACTION(element) &&
8578 !CAN_CHANGE_OR_HAS_ACTION(Back[x][y]))
8581 printf("HandleElementChange(): %d,%d: element = %d ('%s')\n",
8582 x, y, element, element_info[element].token_name);
8583 printf("HandleElementChange(): This should never happen!\n");
8588 /* this can happen with classic bombs on walkable, changing elements */
8589 if (!CAN_CHANGE_OR_HAS_ACTION(element))
8592 if (!CAN_CHANGE(Back[x][y])) /* prevent permanent repetition */
8593 ChangeDelay[x][y] = 0;
8599 if (ChangeDelay[x][y] == 0) /* initialize element change */
8601 ChangeDelay[x][y] = GET_CHANGE_DELAY(change) + 1;
8603 if (change->can_change)
8605 ResetGfxAnimation(x, y);
8606 ResetRandomAnimationValue(x, y);
8608 if (change->pre_change_function)
8609 change->pre_change_function(x, y);
8613 ChangeDelay[x][y]--;
8615 if (ChangeDelay[x][y] != 0) /* continue element change */
8617 if (change->can_change)
8619 int graphic = el_act_dir2img(element, GfxAction[x][y], GfxDir[x][y]);
8621 if (IS_ANIMATED(graphic))
8622 DrawLevelGraphicAnimationIfNeeded(x, y, graphic);
8624 if (change->change_function)
8625 change->change_function(x, y);
8628 else /* finish element change */
8630 if (ChangePage[x][y] != -1) /* remember page from delayed change */
8632 page = ChangePage[x][y];
8633 ChangePage[x][y] = -1;
8635 change = &ei->change_page[page];
8638 if (IS_MOVING(x, y)) /* never change a running system ;-) */
8640 ChangeDelay[x][y] = 1; /* try change after next move step */
8641 ChangePage[x][y] = page; /* remember page to use for change */
8646 if (change->can_change)
8648 if (ChangeElement(x, y, element, page))
8650 if (change->post_change_function)
8651 change->post_change_function(x, y);
8655 if (change->has_action)
8656 ExecuteCustomElementAction(x, y, element, page);
8662 static void HandleElementChange(int x, int y, int page)
8664 int element = MovingOrBlocked2Element(x, y);
8665 struct ElementInfo *ei = &element_info[element];
8666 struct ElementChangeInfo *change = &ei->change_page[page];
8669 if (!CAN_CHANGE(element) && !CAN_CHANGE(Back[x][y]))
8672 printf("HandleElementChange(): %d,%d: element = %d ('%s')\n",
8673 x, y, element, element_info[element].token_name);
8674 printf("HandleElementChange(): This should never happen!\n");
8679 /* this can happen with classic bombs on walkable, changing elements */
8680 if (!CAN_CHANGE(element))
8683 if (!CAN_CHANGE(Back[x][y])) /* prevent permanent repetition */
8684 ChangeDelay[x][y] = 0;
8690 if (ChangeDelay[x][y] == 0) /* initialize element change */
8692 ChangeDelay[x][y] = GET_CHANGE_DELAY(change) + 1;
8694 ResetGfxAnimation(x, y);
8695 ResetRandomAnimationValue(x, y);
8697 if (change->pre_change_function)
8698 change->pre_change_function(x, y);
8701 ChangeDelay[x][y]--;
8703 if (ChangeDelay[x][y] != 0) /* continue element change */
8705 int graphic = el_act_dir2img(element, GfxAction[x][y], GfxDir[x][y]);
8707 if (IS_ANIMATED(graphic))
8708 DrawLevelGraphicAnimationIfNeeded(x, y, graphic);
8710 if (change->change_function)
8711 change->change_function(x, y);
8713 else /* finish element change */
8715 if (ChangePage[x][y] != -1) /* remember page from delayed change */
8717 page = ChangePage[x][y];
8718 ChangePage[x][y] = -1;
8720 change = &ei->change_page[page];
8723 if (IS_MOVING(x, y)) /* never change a running system ;-) */
8725 ChangeDelay[x][y] = 1; /* try change after next move step */
8726 ChangePage[x][y] = page; /* remember page to use for change */
8731 if (ChangeElement(x, y, element, page))
8733 if (change->post_change_function)
8734 change->post_change_function(x, y);
8741 static boolean CheckTriggeredElementChangeExt(int trigger_x, int trigger_y,
8742 int trigger_element,
8748 boolean change_done_any = FALSE;
8749 int trigger_page_bits = (trigger_page < 0 ? CH_PAGE_ANY : 1 << trigger_page);
8752 if (!(trigger_events[trigger_element][trigger_event]))
8755 for (i = 0; i < NUM_CUSTOM_ELEMENTS; i++)
8757 int element = EL_CUSTOM_START + i;
8758 boolean change_done = FALSE;
8761 if (!CAN_CHANGE_OR_HAS_ACTION(element) ||
8762 !HAS_ANY_CHANGE_EVENT(element, trigger_event))
8765 for (p = 0; p < element_info[element].num_change_pages; p++)
8767 struct ElementChangeInfo *change = &element_info[element].change_page[p];
8769 if (change->can_change_or_has_action &&
8770 change->has_event[trigger_event] &&
8771 change->trigger_side & trigger_side &&
8772 change->trigger_player & trigger_player &&
8773 change->trigger_page & trigger_page_bits &&
8774 IS_EQUAL_OR_IN_GROUP(trigger_element, change->trigger_element))
8776 change->actual_trigger_element = trigger_element;
8777 change->actual_trigger_player = EL_PLAYER_1 + log_2(trigger_player);
8778 change->actual_trigger_side = trigger_side;
8779 change->actual_trigger_ce_value = CustomValue[trigger_x][trigger_y];
8780 change->actual_trigger_ce_score = GET_CE_SCORE(trigger_element);
8782 if ((change->can_change && !change_done) || change->has_action)
8787 SCAN_PLAYFIELD(x, y)
8789 for (y = 0; y < lev_fieldy; y++) for (x = 0; x < lev_fieldx; x++)
8792 if (Feld[x][y] == element)
8794 if (change->can_change && !change_done)
8796 ChangeDelay[x][y] = 1;
8797 ChangeEvent[x][y] = trigger_event;
8799 HandleElementChange(x, y, p);
8801 #if USE_NEW_DELAYED_ACTION
8802 else if (change->has_action)
8804 ExecuteCustomElementAction(x, y, element, p);
8805 PlayLevelSoundElementAction(x, y, element, ACTION_PAGE_1 + p);
8808 if (change->has_action)
8810 ExecuteCustomElementAction(x, y, element, p);
8811 PlayLevelSoundElementAction(x, y, element, ACTION_PAGE_1 + p);
8817 if (change->can_change)
8820 change_done_any = TRUE;
8827 return change_done_any;
8830 static boolean CheckElementChangeExt(int x, int y,
8832 int trigger_element,
8837 boolean change_done = FALSE;
8840 if (!CAN_CHANGE_OR_HAS_ACTION(element) ||
8841 !HAS_ANY_CHANGE_EVENT(element, trigger_event))
8844 if (Feld[x][y] == EL_BLOCKED)
8846 Blocked2Moving(x, y, &x, &y);
8847 element = Feld[x][y];
8851 /* check if element has already changed */
8852 if (Feld[x][y] != element)
8855 /* check if element has already changed or is about to change after moving */
8856 if ((game.engine_version < VERSION_IDENT(3,2,0,7) &&
8857 Feld[x][y] != element) ||
8859 (game.engine_version >= VERSION_IDENT(3,2,0,7) &&
8860 (ChangeCount[x][y] >= game.max_num_changes_per_frame ||
8861 ChangePage[x][y] != -1)))
8865 for (p = 0; p < element_info[element].num_change_pages; p++)
8867 struct ElementChangeInfo *change = &element_info[element].change_page[p];
8869 boolean check_trigger_element =
8870 (trigger_event == CE_TOUCHING_X ||
8871 trigger_event == CE_HITTING_X ||
8872 trigger_event == CE_HIT_BY_X);
8874 if (change->can_change_or_has_action &&
8875 change->has_event[trigger_event] &&
8876 change->trigger_side & trigger_side &&
8877 change->trigger_player & trigger_player &&
8878 (!check_trigger_element ||
8879 IS_EQUAL_OR_IN_GROUP(trigger_element, change->trigger_element)))
8881 change->actual_trigger_element = trigger_element;
8882 change->actual_trigger_player = EL_PLAYER_1 + log_2(trigger_player);
8883 change->actual_trigger_side = trigger_side;
8884 change->actual_trigger_ce_value = CustomValue[x][y];
8885 change->actual_trigger_ce_score = GET_CE_SCORE(trigger_element);
8887 /* special case: trigger element not at (x,y) position for some events */
8888 if (check_trigger_element)
8900 { 0, 0 }, { 0, 0 }, { 0, 0 },
8904 int xx = x + move_xy[MV_DIR_OPPOSITE(trigger_side)].dx;
8905 int yy = y + move_xy[MV_DIR_OPPOSITE(trigger_side)].dy;
8907 change->actual_trigger_ce_value = CustomValue[xx][yy];
8908 change->actual_trigger_ce_score = GET_CE_SCORE(trigger_element);
8911 if (change->can_change && !change_done)
8913 ChangeDelay[x][y] = 1;
8914 ChangeEvent[x][y] = trigger_event;
8916 HandleElementChange(x, y, p);
8920 #if USE_NEW_DELAYED_ACTION
8921 else if (change->has_action)
8923 ExecuteCustomElementAction(x, y, element, p);
8924 PlayLevelSoundElementAction(x, y, element, ACTION_PAGE_1 + p);
8927 if (change->has_action)
8929 ExecuteCustomElementAction(x, y, element, p);
8930 PlayLevelSoundElementAction(x, y, element, ACTION_PAGE_1 + p);
8939 static void PlayPlayerSound(struct PlayerInfo *player)
8941 int jx = player->jx, jy = player->jy;
8942 int sound_element = player->artwork_element;
8943 int last_action = player->last_action_waiting;
8944 int action = player->action_waiting;
8946 if (player->is_waiting)
8948 if (action != last_action)
8949 PlayLevelSoundElementAction(jx, jy, sound_element, action);
8951 PlayLevelSoundElementActionIfLoop(jx, jy, sound_element, action);
8955 if (action != last_action)
8956 StopSound(element_info[sound_element].sound[last_action]);
8958 if (last_action == ACTION_SLEEPING)
8959 PlayLevelSoundElementAction(jx, jy, sound_element, ACTION_AWAKENING);
8963 static void PlayAllPlayersSound()
8967 for (i = 0; i < MAX_PLAYERS; i++)
8968 if (stored_player[i].active)
8969 PlayPlayerSound(&stored_player[i]);
8972 static void SetPlayerWaiting(struct PlayerInfo *player, boolean is_waiting)
8974 boolean last_waiting = player->is_waiting;
8975 int move_dir = player->MovDir;
8977 player->dir_waiting = move_dir;
8978 player->last_action_waiting = player->action_waiting;
8982 if (!last_waiting) /* not waiting -> waiting */
8984 player->is_waiting = TRUE;
8986 player->frame_counter_bored =
8988 game.player_boring_delay_fixed +
8989 SimpleRND(game.player_boring_delay_random);
8990 player->frame_counter_sleeping =
8992 game.player_sleeping_delay_fixed +
8993 SimpleRND(game.player_sleeping_delay_random);
8996 InitPlayerGfxAnimation(player, ACTION_WAITING, move_dir);
8998 InitPlayerGfxAnimation(player, ACTION_WAITING, player->MovDir);
9002 if (game.player_sleeping_delay_fixed +
9003 game.player_sleeping_delay_random > 0 &&
9004 player->anim_delay_counter == 0 &&
9005 player->post_delay_counter == 0 &&
9006 FrameCounter >= player->frame_counter_sleeping)
9007 player->is_sleeping = TRUE;
9008 else if (game.player_boring_delay_fixed +
9009 game.player_boring_delay_random > 0 &&
9010 FrameCounter >= player->frame_counter_bored)
9011 player->is_bored = TRUE;
9013 player->action_waiting = (player->is_sleeping ? ACTION_SLEEPING :
9014 player->is_bored ? ACTION_BORING :
9018 if (player->is_sleeping && player->use_murphy)
9020 /* special case for sleeping Murphy when leaning against non-free tile */
9022 if (!IN_LEV_FIELD(player->jx - 1, player->jy) ||
9023 (Feld[player->jx - 1][player->jy] != EL_EMPTY &&
9024 !IS_MOVING(player->jx - 1, player->jy)))
9026 else if (!IN_LEV_FIELD(player->jx + 1, player->jy) ||
9027 (Feld[player->jx + 1][player->jy] != EL_EMPTY &&
9028 !IS_MOVING(player->jx + 1, player->jy)))
9029 move_dir = MV_RIGHT;
9031 player->is_sleeping = FALSE;
9033 player->dir_waiting = move_dir;
9037 if (player->is_sleeping)
9039 if (player->num_special_action_sleeping > 0)
9041 if (player->anim_delay_counter == 0 && player->post_delay_counter == 0)
9043 int last_special_action = player->special_action_sleeping;
9044 int num_special_action = player->num_special_action_sleeping;
9045 int special_action =
9046 (last_special_action == ACTION_DEFAULT ? ACTION_SLEEPING_1 :
9047 last_special_action == ACTION_SLEEPING ? ACTION_SLEEPING :
9048 last_special_action < ACTION_SLEEPING_1 + num_special_action - 1 ?
9049 last_special_action + 1 : ACTION_SLEEPING);
9050 int special_graphic =
9051 el_act_dir2img(player->artwork_element, special_action, move_dir);
9053 player->anim_delay_counter =
9054 graphic_info[special_graphic].anim_delay_fixed +
9055 SimpleRND(graphic_info[special_graphic].anim_delay_random);
9056 player->post_delay_counter =
9057 graphic_info[special_graphic].post_delay_fixed +
9058 SimpleRND(graphic_info[special_graphic].post_delay_random);
9060 player->special_action_sleeping = special_action;
9063 if (player->anim_delay_counter > 0)
9065 player->action_waiting = player->special_action_sleeping;
9066 player->anim_delay_counter--;
9068 else if (player->post_delay_counter > 0)
9070 player->post_delay_counter--;
9074 else if (player->is_bored)
9076 if (player->num_special_action_bored > 0)
9078 if (player->anim_delay_counter == 0 && player->post_delay_counter == 0)
9080 int special_action =
9081 ACTION_BORING_1 + SimpleRND(player->num_special_action_bored);
9082 int special_graphic =
9083 el_act_dir2img(player->artwork_element, special_action, move_dir);
9085 player->anim_delay_counter =
9086 graphic_info[special_graphic].anim_delay_fixed +
9087 SimpleRND(graphic_info[special_graphic].anim_delay_random);
9088 player->post_delay_counter =
9089 graphic_info[special_graphic].post_delay_fixed +
9090 SimpleRND(graphic_info[special_graphic].post_delay_random);
9092 player->special_action_bored = special_action;
9095 if (player->anim_delay_counter > 0)
9097 player->action_waiting = player->special_action_bored;
9098 player->anim_delay_counter--;
9100 else if (player->post_delay_counter > 0)
9102 player->post_delay_counter--;
9107 else if (last_waiting) /* waiting -> not waiting */
9109 player->is_waiting = FALSE;
9110 player->is_bored = FALSE;
9111 player->is_sleeping = FALSE;
9113 player->frame_counter_bored = -1;
9114 player->frame_counter_sleeping = -1;
9116 player->anim_delay_counter = 0;
9117 player->post_delay_counter = 0;
9119 player->dir_waiting = player->MovDir;
9120 player->action_waiting = ACTION_DEFAULT;
9122 player->special_action_bored = ACTION_DEFAULT;
9123 player->special_action_sleeping = ACTION_DEFAULT;
9127 static byte PlayerActions(struct PlayerInfo *player, byte player_action)
9129 boolean moved = FALSE, snapped = FALSE, dropped = FALSE;
9130 int left = player_action & JOY_LEFT;
9131 int right = player_action & JOY_RIGHT;
9132 int up = player_action & JOY_UP;
9133 int down = player_action & JOY_DOWN;
9134 int button1 = player_action & JOY_BUTTON_1;
9135 int button2 = player_action & JOY_BUTTON_2;
9136 int dx = (left ? -1 : right ? 1 : 0);
9137 int dy = (up ? -1 : down ? 1 : 0);
9139 if (!player->active || tape.pausing)
9145 snapped = SnapField(player, dx, dy);
9149 dropped = DropElement(player);
9151 moved = MovePlayer(player, dx, dy);
9154 if (tape.single_step && tape.recording && !tape.pausing)
9156 if (button1 || (dropped && !moved))
9158 TapeTogglePause(TAPE_TOGGLE_AUTOMATIC);
9159 SnapField(player, 0, 0); /* stop snapping */
9163 SetPlayerWaiting(player, FALSE);
9165 return player_action;
9169 /* no actions for this player (no input at player's configured device) */
9171 DigField(player, 0, 0, 0, 0, 0, 0, DF_NO_PUSH);
9172 SnapField(player, 0, 0);
9173 CheckGravityMovementWhenNotMoving(player);
9175 if (player->MovPos == 0)
9176 SetPlayerWaiting(player, TRUE);
9178 if (player->MovPos == 0) /* needed for tape.playing */
9179 player->is_moving = FALSE;
9181 player->is_dropping = FALSE;
9182 player->is_dropping_pressed = FALSE;
9183 player->drop_pressed_delay = 0;
9189 static void CheckLevelTime()
9193 if (level.game_engine_type == GAME_ENGINE_TYPE_EM)
9195 if (level.native_em_level->lev->home == 0) /* all players at home */
9197 local_player->LevelSolved = TRUE;
9198 AllPlayersGone = TRUE;
9200 level.native_em_level->lev->home = -1;
9203 if (level.native_em_level->ply[0]->alive == 0 &&
9204 level.native_em_level->ply[1]->alive == 0 &&
9205 level.native_em_level->ply[2]->alive == 0 &&
9206 level.native_em_level->ply[3]->alive == 0) /* all dead */
9207 AllPlayersGone = TRUE;
9210 if (TimeFrames >= FRAMES_PER_SECOND)
9215 for (i = 0; i < MAX_PLAYERS; i++)
9217 struct PlayerInfo *player = &stored_player[i];
9219 if (SHIELD_ON(player))
9221 player->shield_normal_time_left--;
9223 if (player->shield_deadly_time_left > 0)
9224 player->shield_deadly_time_left--;
9228 if (!level.use_step_counter)
9236 if (TimeLeft <= 10 && setup.time_limit)
9237 PlaySoundStereo(SND_GAME_RUNNING_OUT_OF_TIME, SOUND_MIDDLE);
9239 DrawGameValue_Time(TimeLeft);
9241 if (!TimeLeft && setup.time_limit)
9243 if (level.game_engine_type == GAME_ENGINE_TYPE_EM)
9244 level.native_em_level->lev->killed_out_of_time = TRUE;
9246 for (i = 0; i < MAX_PLAYERS; i++)
9247 KillPlayer(&stored_player[i]);
9250 else if (level.time == 0 && !AllPlayersGone) /* level w/o time limit */
9251 DrawGameValue_Time(TimePlayed);
9253 level.native_em_level->lev->time =
9254 (level.time == 0 ? TimePlayed : TimeLeft);
9257 if (tape.recording || tape.playing)
9258 DrawVideoDisplay(VIDEO_STATE_TIME_ON, TapeTime);
9262 void AdvanceFrameAndPlayerCounters(int player_nr)
9267 Error(ERR_NETWORK_CLIENT, "advancing frame counter from %d to %d",
9268 FrameCounter, FrameCounter + 1);
9271 /* advance frame counters (global frame counter and time frame counter) */
9275 /* advance player counters (counters for move delay, move animation etc.) */
9276 for (i = 0; i < MAX_PLAYERS; i++)
9278 boolean advance_player_counters = (player_nr == -1 || player_nr == i);
9279 int move_delay_value = stored_player[i].move_delay_value;
9280 int move_frames = MOVE_DELAY_NORMAL_SPEED / move_delay_value;
9282 if (!advance_player_counters) /* not all players may be affected */
9285 #if USE_NEW_PLAYER_ANIM
9286 if (move_frames == 0) /* less than one move per game frame */
9288 int stepsize = TILEX / move_delay_value;
9289 int delay = move_delay_value / MOVE_DELAY_NORMAL_SPEED;
9290 int count = (stored_player[i].is_moving ?
9291 ABS(stored_player[i].MovPos) / stepsize : FrameCounter);
9293 if (count % delay == 0)
9298 stored_player[i].Frame += move_frames;
9300 if (stored_player[i].MovPos != 0)
9301 stored_player[i].StepFrame += move_frames;
9303 if (stored_player[i].move_delay > 0)
9304 stored_player[i].move_delay--;
9306 /* due to bugs in previous versions, counter must count up, not down */
9307 if (stored_player[i].push_delay != -1)
9308 stored_player[i].push_delay++;
9310 if (stored_player[i].drop_delay > 0)
9311 stored_player[i].drop_delay--;
9313 if (stored_player[i].is_dropping_pressed)
9314 stored_player[i].drop_pressed_delay++;
9318 void StartGameActions(boolean init_network_game, boolean record_tape,
9321 unsigned long new_random_seed = InitRND(random_seed);
9324 TapeStartRecording(new_random_seed);
9326 #if defined(NETWORK_AVALIABLE)
9327 if (init_network_game)
9329 SendToServer_StartPlaying();
9337 game_status = GAME_MODE_PLAYING;
9344 static unsigned long game_frame_delay = 0;
9345 unsigned long game_frame_delay_value;
9346 byte *recorded_player_action;
9347 byte summarized_player_action = 0;
9348 byte tape_action[MAX_PLAYERS];
9351 if (game.restart_level)
9352 StartGameActions(options.network, setup.autorecord, NEW_RANDOMIZE);
9354 if (level.game_engine_type == GAME_ENGINE_TYPE_EM)
9356 if (level.native_em_level->lev->home == 0) /* all players at home */
9358 local_player->LevelSolved = TRUE;
9359 AllPlayersGone = TRUE;
9361 level.native_em_level->lev->home = -1;
9364 if (level.native_em_level->ply[0]->alive == 0 &&
9365 level.native_em_level->ply[1]->alive == 0 &&
9366 level.native_em_level->ply[2]->alive == 0 &&
9367 level.native_em_level->ply[3]->alive == 0) /* all dead */
9368 AllPlayersGone = TRUE;
9371 if (local_player->LevelSolved)
9374 if (AllPlayersGone && !TAPE_IS_STOPPED(tape))
9377 if (game_status != GAME_MODE_PLAYING) /* status might have changed */
9380 game_frame_delay_value =
9381 (tape.playing && tape.fast_forward ? FfwdFrameDelay : GameFrameDelay);
9383 if (tape.playing && tape.warp_forward && !tape.pausing)
9384 game_frame_delay_value = 0;
9386 /* ---------- main game synchronization point ---------- */
9388 WaitUntilDelayReached(&game_frame_delay, game_frame_delay_value);
9390 if (network_playing && !network_player_action_received)
9392 /* try to get network player actions in time */
9394 #if defined(NETWORK_AVALIABLE)
9395 /* last chance to get network player actions without main loop delay */
9399 /* game was quit by network peer */
9400 if (game_status != GAME_MODE_PLAYING)
9403 if (!network_player_action_received)
9404 return; /* failed to get network player actions in time */
9406 /* do not yet reset "network_player_action_received" (for tape.pausing) */
9412 /* at this point we know that we really continue executing the game */
9415 network_player_action_received = FALSE;
9418 recorded_player_action = (tape.playing ? TapePlayAction() : NULL);
9420 if (tape.set_centered_player)
9422 game.centered_player_nr_next = tape.centered_player_nr_next;
9423 game.set_centered_player = TRUE;
9426 for (i = 0; i < MAX_PLAYERS; i++)
9428 summarized_player_action |= stored_player[i].action;
9430 if (!network_playing)
9431 stored_player[i].effective_action = stored_player[i].action;
9434 #if defined(NETWORK_AVALIABLE)
9435 if (network_playing)
9436 SendToServer_MovePlayer(summarized_player_action);
9439 if (!options.network && !setup.team_mode)
9440 local_player->effective_action = summarized_player_action;
9442 if (setup.team_mode && setup.input_on_focus && game.centered_player_nr != -1)
9444 for (i = 0; i < MAX_PLAYERS; i++)
9445 stored_player[i].effective_action =
9446 (i == game.centered_player_nr ? summarized_player_action : 0);
9449 if (recorded_player_action != NULL)
9450 for (i = 0; i < MAX_PLAYERS; i++)
9451 stored_player[i].effective_action = recorded_player_action[i];
9453 for (i = 0; i < MAX_PLAYERS; i++)
9455 tape_action[i] = stored_player[i].effective_action;
9457 /* (this can only happen in the R'n'D game engine) */
9458 if (tape.recording && tape_action[i] && !tape.player_participates[i])
9459 tape.player_participates[i] = TRUE; /* player just appeared from CE */
9462 /* only record actions from input devices, but not programmed actions */
9464 TapeRecordAction(tape_action);
9466 if (level.game_engine_type == GAME_ENGINE_TYPE_EM)
9468 GameActions_EM_Main();
9476 void GameActions_EM_Main()
9478 byte effective_action[MAX_PLAYERS];
9479 boolean warp_mode = (tape.playing && tape.warp_forward && !tape.pausing);
9482 for (i = 0; i < MAX_PLAYERS; i++)
9483 effective_action[i] = stored_player[i].effective_action;
9485 GameActions_EM(effective_action, warp_mode);
9489 AdvanceFrameAndPlayerCounters(-1); /* advance counters for all players */
9492 void GameActions_RND()
9494 int magic_wall_x = 0, magic_wall_y = 0;
9495 int i, x, y, element, graphic;
9497 InitPlayfieldScanModeVars();
9499 #if USE_ONE_MORE_CHANGE_PER_FRAME
9500 if (game.engine_version >= VERSION_IDENT(3,2,0,7))
9502 SCAN_PLAYFIELD(x, y)
9504 ChangeCount[x][y] = 0;
9505 ChangeEvent[x][y] = -1;
9511 if (game.set_centered_player)
9513 boolean all_players_fit_to_screen = checkIfAllPlayersFitToScreen_RND();
9515 /* switching to "all players" only possible if all players fit to screen */
9516 if (game.centered_player_nr_next == -1 && !all_players_fit_to_screen)
9518 game.centered_player_nr_next = game.centered_player_nr;
9519 game.set_centered_player = FALSE;
9522 /* do not switch focus to non-existing (or non-active) player */
9523 if (game.centered_player_nr_next >= 0 &&
9524 !stored_player[game.centered_player_nr_next].active)
9526 game.centered_player_nr_next = game.centered_player_nr;
9527 game.set_centered_player = FALSE;
9531 if (game.set_centered_player &&
9532 ScreenMovPos == 0) /* screen currently aligned at tile position */
9536 if (game.centered_player_nr_next == -1)
9538 setScreenCenteredToAllPlayers(&sx, &sy);
9542 sx = stored_player[game.centered_player_nr_next].jx;
9543 sy = stored_player[game.centered_player_nr_next].jy;
9546 game.centered_player_nr = game.centered_player_nr_next;
9547 game.set_centered_player = FALSE;
9549 DrawRelocateScreen(sx, sy, MV_NONE, TRUE, setup.quick_switch);
9550 DrawGameDoorValues();
9554 for (i = 0; i < MAX_PLAYERS; i++)
9556 int actual_player_action = stored_player[i].effective_action;
9559 /* !!! THIS BREAKS THE FOLLOWING TAPES: !!!
9560 - rnd_equinox_tetrachloride 048
9561 - rnd_equinox_tetrachloride_ii 096
9562 - rnd_emanuel_schmieg 002
9563 - doctor_sloan_ww 001, 020
9565 if (stored_player[i].MovPos == 0)
9566 CheckGravityMovement(&stored_player[i]);
9569 /* overwrite programmed action with tape action */
9570 if (stored_player[i].programmed_action)
9571 actual_player_action = stored_player[i].programmed_action;
9574 PlayerActions(&stored_player[i], actual_player_action);
9576 tape_action[i] = PlayerActions(&stored_player[i], actual_player_action);
9578 if (tape.recording && tape_action[i] && !tape.player_participates[i])
9579 tape.player_participates[i] = TRUE; /* player just appeared from CE */
9582 ScrollPlayer(&stored_player[i], SCROLL_GO_ON);
9586 network_player_action_received = FALSE;
9589 ScrollScreen(NULL, SCROLL_GO_ON);
9591 /* for backwards compatibility, the following code emulates a fixed bug that
9592 occured when pushing elements (causing elements that just made their last
9593 pushing step to already (if possible) make their first falling step in the
9594 same game frame, which is bad); this code is also needed to use the famous
9595 "spring push bug" which is used in older levels and might be wanted to be
9596 used also in newer levels, but in this case the buggy pushing code is only
9597 affecting the "spring" element and no other elements */
9599 if (game.engine_version < VERSION_IDENT(2,2,0,7) || level.use_spring_bug)
9601 for (i = 0; i < MAX_PLAYERS; i++)
9603 struct PlayerInfo *player = &stored_player[i];
9607 if (player->active && player->is_pushing && player->is_moving &&
9609 (game.engine_version < VERSION_IDENT(2,2,0,7) ||
9610 Feld[x][y] == EL_SPRING))
9612 ContinueMoving(x, y);
9614 /* continue moving after pushing (this is actually a bug) */
9615 if (!IS_MOVING(x, y))
9624 SCAN_PLAYFIELD(x, y)
9626 for (y = 0; y < lev_fieldy; y++) for (x = 0; x < lev_fieldx; x++)
9629 ChangeCount[x][y] = 0;
9630 ChangeEvent[x][y] = -1;
9632 /* this must be handled before main playfield loop */
9633 if (Feld[x][y] == EL_PLAYER_IS_LEAVING)
9636 if (MovDelay[x][y] <= 0)
9640 #if USE_NEW_SNAP_DELAY
9641 if (Feld[x][y] == EL_ELEMENT_SNAPPING)
9644 if (MovDelay[x][y] <= 0)
9647 DrawLevelField(x, y);
9649 TestIfElementTouchesCustomElement(x, y); /* for empty space */
9655 if (ChangePage[x][y] != -1 && ChangeDelay[x][y] != 1)
9657 printf("GameActions(): x = %d, y = %d: ChangePage != -1\n", x, y);
9658 printf("GameActions(): This should never happen!\n");
9660 ChangePage[x][y] = -1;
9665 if (WasJustMoving[x][y] > 0)
9666 WasJustMoving[x][y]--;
9667 if (WasJustFalling[x][y] > 0)
9668 WasJustFalling[x][y]--;
9669 if (CheckCollision[x][y] > 0)
9670 CheckCollision[x][y]--;
9674 /* reset finished pushing action (not done in ContinueMoving() to allow
9675 continuous pushing animation for elements with zero push delay) */
9676 if (GfxAction[x][y] == ACTION_PUSHING && !IS_MOVING(x, y))
9678 ResetGfxAnimation(x, y);
9679 DrawLevelField(x, y);
9683 if (IS_BLOCKED(x, y))
9687 Blocked2Moving(x, y, &oldx, &oldy);
9688 if (!IS_MOVING(oldx, oldy))
9690 printf("GameActions(): (BLOCKED => MOVING) context corrupted!\n");
9691 printf("GameActions(): BLOCKED: x = %d, y = %d\n", x, y);
9692 printf("GameActions(): !MOVING: oldx = %d, oldy = %d\n", oldx, oldy);
9693 printf("GameActions(): This should never happen!\n");
9700 SCAN_PLAYFIELD(x, y)
9702 for (y = 0; y < lev_fieldy; y++) for (x = 0; x < lev_fieldx; x++)
9705 element = Feld[x][y];
9706 graphic = el_act_dir2img(element, GfxAction[x][y], GfxDir[x][y]);
9709 printf("::: %d,%d\n", x, y);
9711 if (element == EL_ROCK)
9712 printf("::: Yo man! Rocks can fall!\n");
9715 if (graphic_info[graphic].anim_global_sync)
9716 GfxFrame[x][y] = FrameCounter;
9717 else if (ANIM_MODE(graphic) == ANIM_CE_VALUE)
9719 int old_gfx_frame = GfxFrame[x][y];
9721 GfxFrame[x][y] = CustomValue[x][y];
9724 if (GfxFrame[x][y] != old_gfx_frame)
9726 DrawLevelGraphicAnimation(x, y, graphic);
9728 else if (ANIM_MODE(graphic) == ANIM_CE_SCORE)
9730 int old_gfx_frame = GfxFrame[x][y];
9732 GfxFrame[x][y] = element_info[element].collect_score;
9735 if (GfxFrame[x][y] != old_gfx_frame)
9737 DrawLevelGraphicAnimation(x, y, graphic);
9740 if (ANIM_MODE(graphic) == ANIM_RANDOM &&
9741 IS_NEXT_FRAME(GfxFrame[x][y], graphic))
9742 ResetRandomAnimationValue(x, y);
9744 SetRandomAnimationValue(x, y);
9746 PlayLevelSoundActionIfLoop(x, y, GfxAction[x][y]);
9748 if (IS_INACTIVE(element))
9750 if (IS_ANIMATED(graphic))
9751 DrawLevelGraphicAnimationIfNeeded(x, y, graphic);
9756 /* this may take place after moving, so 'element' may have changed */
9757 if (IS_CHANGING(x, y) &&
9758 (game.engine_version < VERSION_IDENT(3,0,7,1) || !Stop[x][y]))
9760 int page = element_info[element].event_page_nr[CE_DELAY];
9762 HandleElementChange(x, y, ChangePage[x][y] != -1 ? ChangePage[x][y] : page);
9766 printf("::: ChangeDelay == %d\n", ChangeDelay[x][y]);
9770 if (element == EL_CUSTOM_255)
9771 printf("::: ChangeDelay == %d\n", ChangeDelay[x][y]);
9775 HandleElementChange(x, y, page);
9777 if (CAN_CHANGE(element))
9778 HandleElementChange(x, y, page);
9780 if (HAS_ACTION(element))
9781 ExecuteCustomElementAction(x, y, element, page);
9786 element = Feld[x][y];
9787 graphic = el_act_dir2img(element, GfxAction[x][y], GfxDir[x][y]);
9790 if (!IS_MOVING(x, y) && (CAN_FALL(element) || CAN_MOVE(element)))
9794 element = Feld[x][y];
9795 graphic = el_act_dir2img(element, GfxAction[x][y], GfxDir[x][y]);
9797 if (IS_ANIMATED(graphic) &&
9800 DrawLevelGraphicAnimationIfNeeded(x, y, graphic);
9802 if (IS_GEM(element) || element == EL_SP_INFOTRON)
9803 EdelsteinFunkeln(x, y);
9805 else if ((element == EL_ACID ||
9806 element == EL_EXIT_OPEN ||
9807 element == EL_SP_EXIT_OPEN ||
9808 element == EL_SP_TERMINAL ||
9809 element == EL_SP_TERMINAL_ACTIVE ||
9810 element == EL_EXTRA_TIME ||
9811 element == EL_SHIELD_NORMAL ||
9812 element == EL_SHIELD_DEADLY) &&
9813 IS_ANIMATED(graphic))
9814 DrawLevelGraphicAnimationIfNeeded(x, y, graphic);
9815 else if (IS_MOVING(x, y))
9816 ContinueMoving(x, y);
9817 else if (IS_ACTIVE_BOMB(element))
9818 CheckDynamite(x, y);
9819 else if (element == EL_AMOEBA_GROWING)
9820 AmoebeWaechst(x, y);
9821 else if (element == EL_AMOEBA_SHRINKING)
9822 AmoebaDisappearing(x, y);
9824 #if !USE_NEW_AMOEBA_CODE
9825 else if (IS_AMOEBALIVE(element))
9826 AmoebeAbleger(x, y);
9829 else if (element == EL_GAME_OF_LIFE || element == EL_BIOMAZE)
9831 else if (element == EL_EXIT_CLOSED)
9833 else if (element == EL_SP_EXIT_CLOSED)
9835 else if (element == EL_EXPANDABLE_WALL_GROWING)
9837 else if (element == EL_EXPANDABLE_WALL ||
9838 element == EL_EXPANDABLE_WALL_HORIZONTAL ||
9839 element == EL_EXPANDABLE_WALL_VERTICAL ||
9840 element == EL_EXPANDABLE_WALL_ANY)
9842 else if (element == EL_FLAMES)
9843 CheckForDragon(x, y);
9844 else if (element == EL_EXPLOSION)
9845 ; /* drawing of correct explosion animation is handled separately */
9846 else if (element == EL_ELEMENT_SNAPPING ||
9847 element == EL_DIAGONAL_SHRINKING ||
9848 element == EL_DIAGONAL_GROWING)
9851 graphic = el_act_dir2img(GfxElement[x][y], GfxAction[x][y],GfxDir[x][y]);
9853 DrawLevelGraphicAnimationIfNeeded(x, y, graphic);
9856 else if (IS_ANIMATED(graphic) && !IS_CHANGING(x, y))
9857 DrawLevelGraphicAnimationIfNeeded(x, y, graphic);
9860 if (element == EL_CUSTOM_255 ||
9861 element == EL_CUSTOM_256)
9862 DrawLevelGraphicAnimation(x, y, graphic);
9865 if (IS_BELT_ACTIVE(element))
9866 PlayLevelSoundAction(x, y, ACTION_ACTIVE);
9868 if (game.magic_wall_active)
9870 int jx = local_player->jx, jy = local_player->jy;
9872 /* play the element sound at the position nearest to the player */
9873 if ((element == EL_MAGIC_WALL_FULL ||
9874 element == EL_MAGIC_WALL_ACTIVE ||
9875 element == EL_MAGIC_WALL_EMPTYING ||
9876 element == EL_BD_MAGIC_WALL_FULL ||
9877 element == EL_BD_MAGIC_WALL_ACTIVE ||
9878 element == EL_BD_MAGIC_WALL_EMPTYING) &&
9879 ABS(x-jx) + ABS(y-jy) < ABS(magic_wall_x-jx) + ABS(magic_wall_y-jy))
9887 #if USE_NEW_AMOEBA_CODE
9888 /* new experimental amoeba growth stuff */
9889 if (!(FrameCounter % 8))
9891 static unsigned long random = 1684108901;
9893 for (i = 0; i < level.amoeba_speed * 28 / 8; i++)
9895 x = RND(lev_fieldx);
9896 y = RND(lev_fieldy);
9897 element = Feld[x][y];
9899 if (!IS_PLAYER(x,y) &&
9900 (element == EL_EMPTY ||
9901 CAN_GROW_INTO(element) ||
9902 element == EL_QUICKSAND_EMPTY ||
9903 element == EL_ACID_SPLASH_LEFT ||
9904 element == EL_ACID_SPLASH_RIGHT))
9906 if ((IN_LEV_FIELD(x, y-1) && Feld[x][y-1] == EL_AMOEBA_WET) ||
9907 (IN_LEV_FIELD(x-1, y) && Feld[x-1][y] == EL_AMOEBA_WET) ||
9908 (IN_LEV_FIELD(x+1, y) && Feld[x+1][y] == EL_AMOEBA_WET) ||
9909 (IN_LEV_FIELD(x, y+1) && Feld[x][y+1] == EL_AMOEBA_WET))
9910 Feld[x][y] = EL_AMOEBA_DROP;
9913 random = random * 129 + 1;
9919 if (game.explosions_delayed)
9922 game.explosions_delayed = FALSE;
9925 SCAN_PLAYFIELD(x, y)
9927 for (y = 0; y < lev_fieldy; y++) for (x = 0; x < lev_fieldx; x++)
9930 element = Feld[x][y];
9932 if (ExplodeField[x][y])
9933 Explode(x, y, EX_PHASE_START, ExplodeField[x][y]);
9934 else if (element == EL_EXPLOSION)
9935 Explode(x, y, ExplodePhase[x][y], EX_TYPE_NORMAL);
9937 ExplodeField[x][y] = EX_TYPE_NONE;
9940 game.explosions_delayed = TRUE;
9943 if (game.magic_wall_active)
9945 if (!(game.magic_wall_time_left % 4))
9947 int element = Feld[magic_wall_x][magic_wall_y];
9949 if (element == EL_BD_MAGIC_WALL_FULL ||
9950 element == EL_BD_MAGIC_WALL_ACTIVE ||
9951 element == EL_BD_MAGIC_WALL_EMPTYING)
9952 PlayLevelSound(magic_wall_x, magic_wall_y, SND_BD_MAGIC_WALL_ACTIVE);
9954 PlayLevelSound(magic_wall_x, magic_wall_y, SND_MAGIC_WALL_ACTIVE);
9957 if (game.magic_wall_time_left > 0)
9959 game.magic_wall_time_left--;
9960 if (!game.magic_wall_time_left)
9963 SCAN_PLAYFIELD(x, y)
9965 for (y = 0; y < lev_fieldy; y++) for (x = 0; x < lev_fieldx; x++)
9968 element = Feld[x][y];
9970 if (element == EL_MAGIC_WALL_ACTIVE ||
9971 element == EL_MAGIC_WALL_FULL)
9973 Feld[x][y] = EL_MAGIC_WALL_DEAD;
9974 DrawLevelField(x, y);
9976 else if (element == EL_BD_MAGIC_WALL_ACTIVE ||
9977 element == EL_BD_MAGIC_WALL_FULL)
9979 Feld[x][y] = EL_BD_MAGIC_WALL_DEAD;
9980 DrawLevelField(x, y);
9984 game.magic_wall_active = FALSE;
9989 if (game.light_time_left > 0)
9991 game.light_time_left--;
9993 if (game.light_time_left == 0)
9994 RedrawAllLightSwitchesAndInvisibleElements();
9997 if (game.timegate_time_left > 0)
9999 game.timegate_time_left--;
10001 if (game.timegate_time_left == 0)
10002 CloseAllOpenTimegates();
10005 if (game.lenses_time_left > 0)
10007 game.lenses_time_left--;
10009 if (game.lenses_time_left == 0)
10010 RedrawAllInvisibleElementsForLenses();
10013 if (game.magnify_time_left > 0)
10015 game.magnify_time_left--;
10017 if (game.magnify_time_left == 0)
10018 RedrawAllInvisibleElementsForMagnifier();
10021 for (i = 0; i < MAX_PLAYERS; i++)
10023 struct PlayerInfo *player = &stored_player[i];
10025 if (SHIELD_ON(player))
10027 if (player->shield_deadly_time_left)
10028 PlayLevelSound(player->jx, player->jy, SND_SHIELD_DEADLY_ACTIVE);
10029 else if (player->shield_normal_time_left)
10030 PlayLevelSound(player->jx, player->jy, SND_SHIELD_NORMAL_ACTIVE);
10037 PlayAllPlayersSound();
10039 if (options.debug) /* calculate frames per second */
10041 static unsigned long fps_counter = 0;
10042 static int fps_frames = 0;
10043 unsigned long fps_delay_ms = Counter() - fps_counter;
10047 if (fps_delay_ms >= 500) /* calculate fps every 0.5 seconds */
10049 global.frames_per_second = 1000 * (float)fps_frames / fps_delay_ms;
10052 fps_counter = Counter();
10055 redraw_mask |= REDRAW_FPS;
10058 AdvanceFrameAndPlayerCounters(-1); /* advance counters for all players */
10060 if (local_player->show_envelope != 0 && local_player->MovPos == 0)
10062 ShowEnvelope(local_player->show_envelope - EL_ENVELOPE_1);
10064 local_player->show_envelope = 0;
10067 /* use random number generator in every frame to make it less predictable */
10068 if (game.engine_version >= VERSION_IDENT(3,1,1,0))
10072 static boolean AllPlayersInSight(struct PlayerInfo *player, int x, int y)
10074 int min_x = x, min_y = y, max_x = x, max_y = y;
10077 for (i = 0; i < MAX_PLAYERS; i++)
10079 int jx = stored_player[i].jx, jy = stored_player[i].jy;
10081 if (!stored_player[i].active || &stored_player[i] == player)
10084 min_x = MIN(min_x, jx);
10085 min_y = MIN(min_y, jy);
10086 max_x = MAX(max_x, jx);
10087 max_y = MAX(max_y, jy);
10090 return (max_x - min_x < SCR_FIELDX && max_y - min_y < SCR_FIELDY);
10093 static boolean AllPlayersInVisibleScreen()
10097 for (i = 0; i < MAX_PLAYERS; i++)
10099 int jx = stored_player[i].jx, jy = stored_player[i].jy;
10101 if (!stored_player[i].active)
10104 if (!IN_VIS_FIELD(SCREENX(jx), SCREENY(jy)))
10111 void ScrollLevel(int dx, int dy)
10113 int softscroll_offset = (setup.soft_scrolling ? TILEX : 0);
10116 BlitBitmap(drawto_field, drawto_field,
10117 FX + TILEX * (dx == -1) - softscroll_offset,
10118 FY + TILEY * (dy == -1) - softscroll_offset,
10119 SXSIZE - TILEX * (dx!=0) + 2 * softscroll_offset,
10120 SYSIZE - TILEY * (dy!=0) + 2 * softscroll_offset,
10121 FX + TILEX * (dx == 1) - softscroll_offset,
10122 FY + TILEY * (dy == 1) - softscroll_offset);
10126 x = (dx == 1 ? BX1 : BX2);
10127 for (y = BY1; y <= BY2; y++)
10128 DrawScreenField(x, y);
10133 y = (dy == 1 ? BY1 : BY2);
10134 for (x = BX1; x <= BX2; x++)
10135 DrawScreenField(x, y);
10138 redraw_mask |= REDRAW_FIELD;
10141 static boolean canFallDown(struct PlayerInfo *player)
10143 int jx = player->jx, jy = player->jy;
10145 return (IN_LEV_FIELD(jx, jy + 1) &&
10146 (IS_FREE(jx, jy + 1) ||
10147 (Feld[jx][jy + 1] == EL_ACID && player->can_fall_into_acid)) &&
10148 IS_WALKABLE_FROM(Feld[jx][jy], MV_DOWN) &&
10149 !IS_WALKABLE_INSIDE(Feld[jx][jy]));
10152 static boolean canPassField(int x, int y, int move_dir)
10154 int opposite_dir = MV_DIR_OPPOSITE(move_dir);
10155 int dx = (move_dir & MV_LEFT ? -1 : move_dir & MV_RIGHT ? +1 : 0);
10156 int dy = (move_dir & MV_UP ? -1 : move_dir & MV_DOWN ? +1 : 0);
10157 int nextx = x + dx;
10158 int nexty = y + dy;
10159 int element = Feld[x][y];
10161 return (IS_PASSABLE_FROM(element, opposite_dir) &&
10162 !CAN_MOVE(element) &&
10163 IN_LEV_FIELD(nextx, nexty) && !IS_PLAYER(nextx, nexty) &&
10164 IS_WALKABLE_FROM(Feld[nextx][nexty], move_dir) &&
10165 (level.can_pass_to_walkable || IS_FREE(nextx, nexty)));
10168 static boolean canMoveToValidFieldWithGravity(int x, int y, int move_dir)
10170 int opposite_dir = MV_DIR_OPPOSITE(move_dir);
10171 int dx = (move_dir & MV_LEFT ? -1 : move_dir & MV_RIGHT ? +1 : 0);
10172 int dy = (move_dir & MV_UP ? -1 : move_dir & MV_DOWN ? +1 : 0);
10176 return (IN_LEV_FIELD(newx, newy) && !IS_FREE_OR_PLAYER(newx, newy) &&
10177 IS_GRAVITY_REACHABLE(Feld[newx][newy]) &&
10178 (IS_DIGGABLE(Feld[newx][newy]) ||
10179 IS_WALKABLE_FROM(Feld[newx][newy], opposite_dir) ||
10180 canPassField(newx, newy, move_dir)));
10183 static void CheckGravityMovement(struct PlayerInfo *player)
10185 if (game.gravity && !player->programmed_action)
10187 int move_dir_horizontal = player->effective_action & MV_HORIZONTAL;
10188 int move_dir_vertical = player->effective_action & MV_VERTICAL;
10189 boolean player_is_snapping = player->effective_action & JOY_BUTTON_1;
10190 int jx = player->jx, jy = player->jy;
10191 boolean player_is_moving_to_valid_field =
10192 (!player_is_snapping &&
10193 (canMoveToValidFieldWithGravity(jx, jy, move_dir_horizontal) ||
10194 canMoveToValidFieldWithGravity(jx, jy, move_dir_vertical)));
10195 boolean player_can_fall_down = canFallDown(player);
10197 if (player_can_fall_down &&
10198 !player_is_moving_to_valid_field)
10199 player->programmed_action = MV_DOWN;
10203 static void CheckGravityMovementWhenNotMoving(struct PlayerInfo *player)
10205 return CheckGravityMovement(player);
10207 if (game.gravity && !player->programmed_action)
10209 int jx = player->jx, jy = player->jy;
10210 boolean field_under_player_is_free =
10211 (IN_LEV_FIELD(jx, jy + 1) && IS_FREE(jx, jy + 1));
10212 boolean player_is_standing_on_valid_field =
10213 (IS_WALKABLE_INSIDE(Feld[jx][jy]) ||
10214 (IS_WALKABLE(Feld[jx][jy]) &&
10215 !(element_info[Feld[jx][jy]].access_direction & MV_DOWN)));
10217 if (field_under_player_is_free && !player_is_standing_on_valid_field)
10218 player->programmed_action = MV_DOWN;
10223 MovePlayerOneStep()
10224 -----------------------------------------------------------------------------
10225 dx, dy: direction (non-diagonal) to try to move the player to
10226 real_dx, real_dy: direction as read from input device (can be diagonal)
10229 boolean MovePlayerOneStep(struct PlayerInfo *player,
10230 int dx, int dy, int real_dx, int real_dy)
10232 int jx = player->jx, jy = player->jy;
10233 int new_jx = jx + dx, new_jy = jy + dy;
10234 #if !USE_FIXED_DONT_RUN_INTO
10238 boolean player_can_move = !player->cannot_move;
10240 if (!player->active || (!dx && !dy))
10241 return MP_NO_ACTION;
10243 player->MovDir = (dx < 0 ? MV_LEFT :
10244 dx > 0 ? MV_RIGHT :
10246 dy > 0 ? MV_DOWN : MV_NONE);
10248 if (!IN_LEV_FIELD(new_jx, new_jy))
10249 return MP_NO_ACTION;
10251 if (!player_can_move)
10254 if (player->MovPos == 0)
10256 player->is_moving = FALSE;
10257 player->is_digging = FALSE;
10258 player->is_collecting = FALSE;
10259 player->is_snapping = FALSE;
10260 player->is_pushing = FALSE;
10263 DigField(player, 0, 0, 0, 0, 0, 0, DF_NO_PUSH);
10264 SnapField(player, 0, 0);
10268 return MP_NO_ACTION;
10273 if (!options.network && game.centered_player_nr == -1 &&
10274 !AllPlayersInSight(player, new_jx, new_jy))
10275 return MP_NO_ACTION;
10277 if (!options.network && !AllPlayersInSight(player, new_jx, new_jy))
10278 return MP_NO_ACTION;
10281 #if !USE_FIXED_DONT_RUN_INTO
10282 element = MovingOrBlocked2ElementIfNotLeaving(new_jx, new_jy);
10284 /* (moved to DigField()) */
10285 if (player_can_move && DONT_RUN_INTO(element))
10287 if (element == EL_ACID && dx == 0 && dy == 1)
10289 SplashAcid(new_jx, new_jy);
10290 Feld[jx][jy] = EL_PLAYER_1;
10291 InitMovingField(jx, jy, MV_DOWN);
10292 Store[jx][jy] = EL_ACID;
10293 ContinueMoving(jx, jy);
10294 BuryPlayer(player);
10297 TestIfPlayerRunsIntoBadThing(jx, jy, player->MovDir);
10303 can_move = DigField(player, jx, jy, new_jx, new_jy, real_dx,real_dy, DF_DIG);
10305 #if USE_FIXED_DONT_RUN_INTO
10306 if (can_move == MP_DONT_RUN_INTO)
10310 if (can_move != MP_MOVING)
10313 #if USE_FIXED_DONT_RUN_INTO
10316 /* check if DigField() has caused relocation of the player */
10317 if (player->jx != jx || player->jy != jy)
10318 return MP_NO_ACTION; /* <-- !!! CHECK THIS [-> MP_ACTION ?] !!! */
10320 StorePlayer[jx][jy] = 0;
10321 player->last_jx = jx;
10322 player->last_jy = jy;
10323 player->jx = new_jx;
10324 player->jy = new_jy;
10325 StorePlayer[new_jx][new_jy] = player->element_nr;
10327 if (player->move_delay_value_next != -1)
10329 player->move_delay_value = player->move_delay_value_next;
10330 player->move_delay_value_next = -1;
10334 (dx > 0 || dy > 0 ? -1 : 1) * (TILEX - TILEX / player->move_delay_value);
10336 player->step_counter++;
10338 PlayerVisit[jx][jy] = FrameCounter;
10340 ScrollPlayer(player, SCROLL_INIT);
10345 boolean MovePlayer(struct PlayerInfo *player, int dx, int dy)
10347 int jx = player->jx, jy = player->jy;
10348 int old_jx = jx, old_jy = jy;
10349 int moved = MP_NO_ACTION;
10351 if (!player->active)
10356 if (player->MovPos == 0)
10358 player->is_moving = FALSE;
10359 player->is_digging = FALSE;
10360 player->is_collecting = FALSE;
10361 player->is_snapping = FALSE;
10362 player->is_pushing = FALSE;
10368 if (player->move_delay > 0)
10371 player->move_delay = -1; /* set to "uninitialized" value */
10373 /* store if player is automatically moved to next field */
10374 player->is_auto_moving = (player->programmed_action != MV_NONE);
10376 /* remove the last programmed player action */
10377 player->programmed_action = 0;
10379 if (player->MovPos)
10381 /* should only happen if pre-1.2 tape recordings are played */
10382 /* this is only for backward compatibility */
10384 int original_move_delay_value = player->move_delay_value;
10387 printf("THIS SHOULD ONLY HAPPEN WITH PRE-1.2 LEVEL TAPES. [%ld]\n",
10391 /* scroll remaining steps with finest movement resolution */
10392 player->move_delay_value = MOVE_DELAY_NORMAL_SPEED;
10394 while (player->MovPos)
10396 ScrollPlayer(player, SCROLL_GO_ON);
10397 ScrollScreen(NULL, SCROLL_GO_ON);
10399 AdvanceFrameAndPlayerCounters(player->index_nr);
10405 player->move_delay_value = original_move_delay_value;
10408 if (player->last_move_dir & MV_HORIZONTAL)
10410 if (!(moved |= MovePlayerOneStep(player, 0, dy, dx, dy)))
10411 moved |= MovePlayerOneStep(player, dx, 0, dx, dy);
10415 if (!(moved |= MovePlayerOneStep(player, dx, 0, dx, dy)))
10416 moved |= MovePlayerOneStep(player, 0, dy, dx, dy);
10423 if (moved & MP_MOVING && !ScreenMovPos &&
10424 (player->index_nr == game.centered_player_nr ||
10425 game.centered_player_nr == -1))
10427 if (moved & MP_MOVING && !ScreenMovPos &&
10428 (player == local_player || !options.network))
10431 int old_scroll_x = scroll_x, old_scroll_y = scroll_y;
10432 int offset = (setup.scroll_delay ? 3 : 0);
10434 if (!IN_VIS_FIELD(SCREENX(jx), SCREENY(jy)))
10436 /* actual player has left the screen -- scroll in that direction */
10437 if (jx != old_jx) /* player has moved horizontally */
10438 scroll_x += (jx - old_jx);
10439 else /* player has moved vertically */
10440 scroll_y += (jy - old_jy);
10444 if (jx != old_jx) /* player has moved horizontally */
10446 if ((player->MovDir == MV_LEFT && scroll_x > jx - MIDPOSX + offset) ||
10447 (player->MovDir == MV_RIGHT && scroll_x < jx - MIDPOSX - offset))
10448 scroll_x = jx-MIDPOSX + (scroll_x < jx-MIDPOSX ? -offset : +offset);
10450 /* don't scroll over playfield boundaries */
10451 if (scroll_x < SBX_Left || scroll_x > SBX_Right)
10452 scroll_x = (scroll_x < SBX_Left ? SBX_Left : SBX_Right);
10454 /* don't scroll more than one field at a time */
10455 scroll_x = old_scroll_x + SIGN(scroll_x - old_scroll_x);
10457 /* don't scroll against the player's moving direction */
10458 if ((player->MovDir == MV_LEFT && scroll_x > old_scroll_x) ||
10459 (player->MovDir == MV_RIGHT && scroll_x < old_scroll_x))
10460 scroll_x = old_scroll_x;
10462 else /* player has moved vertically */
10464 if ((player->MovDir == MV_UP && scroll_y > jy - MIDPOSY + offset) ||
10465 (player->MovDir == MV_DOWN && scroll_y < jy - MIDPOSY - offset))
10466 scroll_y = jy-MIDPOSY + (scroll_y < jy-MIDPOSY ? -offset : +offset);
10468 /* don't scroll over playfield boundaries */
10469 if (scroll_y < SBY_Upper || scroll_y > SBY_Lower)
10470 scroll_y = (scroll_y < SBY_Upper ? SBY_Upper : SBY_Lower);
10472 /* don't scroll more than one field at a time */
10473 scroll_y = old_scroll_y + SIGN(scroll_y - old_scroll_y);
10475 /* don't scroll against the player's moving direction */
10476 if ((player->MovDir == MV_UP && scroll_y > old_scroll_y) ||
10477 (player->MovDir == MV_DOWN && scroll_y < old_scroll_y))
10478 scroll_y = old_scroll_y;
10482 if (scroll_x != old_scroll_x || scroll_y != old_scroll_y)
10485 if (!options.network && game.centered_player_nr == -1 &&
10486 !AllPlayersInVisibleScreen())
10488 scroll_x = old_scroll_x;
10489 scroll_y = old_scroll_y;
10493 if (!options.network && !AllPlayersInVisibleScreen())
10495 scroll_x = old_scroll_x;
10496 scroll_y = old_scroll_y;
10501 ScrollScreen(player, SCROLL_INIT);
10502 ScrollLevel(old_scroll_x - scroll_x, old_scroll_y - scroll_y);
10507 player->StepFrame = 0;
10509 if (moved & MP_MOVING)
10511 if (old_jx != jx && old_jy == jy)
10512 player->MovDir = (old_jx < jx ? MV_RIGHT : MV_LEFT);
10513 else if (old_jx == jx && old_jy != jy)
10514 player->MovDir = (old_jy < jy ? MV_DOWN : MV_UP);
10516 DrawLevelField(jx, jy); /* for "crumbled sand" */
10518 player->last_move_dir = player->MovDir;
10519 player->is_moving = TRUE;
10520 player->is_snapping = FALSE;
10521 player->is_switching = FALSE;
10522 player->is_dropping = FALSE;
10523 player->is_dropping_pressed = FALSE;
10524 player->drop_pressed_delay = 0;
10528 CheckGravityMovementWhenNotMoving(player);
10530 player->is_moving = FALSE;
10532 /* at this point, the player is allowed to move, but cannot move right now
10533 (e.g. because of something blocking the way) -- ensure that the player
10534 is also allowed to move in the next frame (in old versions before 3.1.1,
10535 the player was forced to wait again for eight frames before next try) */
10537 if (game.engine_version >= VERSION_IDENT(3,1,1,0))
10538 player->move_delay = 0; /* allow direct movement in the next frame */
10541 if (player->move_delay == -1) /* not yet initialized by DigField() */
10542 player->move_delay = player->move_delay_value;
10544 if (game.engine_version < VERSION_IDENT(3,0,7,0))
10546 TestIfPlayerTouchesBadThing(jx, jy);
10547 TestIfPlayerTouchesCustomElement(jx, jy);
10550 if (!player->active)
10551 RemovePlayer(player);
10556 void ScrollPlayer(struct PlayerInfo *player, int mode)
10558 int jx = player->jx, jy = player->jy;
10559 int last_jx = player->last_jx, last_jy = player->last_jy;
10560 int move_stepsize = TILEX / player->move_delay_value;
10562 #if USE_NEW_PLAYER_SPEED
10563 if (!player->active)
10566 if (player->MovPos == 0 && mode == SCROLL_GO_ON) /* player not moving */
10569 if (!player->active || player->MovPos == 0)
10573 if (mode == SCROLL_INIT)
10575 player->actual_frame_counter = FrameCounter;
10576 player->GfxPos = move_stepsize * (player->MovPos / move_stepsize);
10578 if ((player->block_last_field || player->block_delay_adjustment > 0) &&
10579 Feld[last_jx][last_jy] == EL_EMPTY)
10581 int last_field_block_delay = 0; /* start with no blocking at all */
10582 int block_delay_adjustment = player->block_delay_adjustment;
10584 /* if player blocks last field, add delay for exactly one move */
10585 if (player->block_last_field)
10587 last_field_block_delay += player->move_delay_value;
10589 /* when blocking enabled, prevent moving up despite gravity */
10590 if (game.gravity && player->MovDir == MV_UP)
10591 block_delay_adjustment = -1;
10594 /* add block delay adjustment (also possible when not blocking) */
10595 last_field_block_delay += block_delay_adjustment;
10597 Feld[last_jx][last_jy] = EL_PLAYER_IS_LEAVING;
10598 MovDelay[last_jx][last_jy] = last_field_block_delay + 1;
10601 #if USE_NEW_PLAYER_SPEED
10602 if (player->MovPos != 0) /* player has not yet reached destination */
10608 else if (!FrameReached(&player->actual_frame_counter, 1))
10612 printf("::: player->MovPos: %d -> %d\n",
10614 player->MovPos + (player->MovPos > 0 ? -1 : 1) * move_stepsize);
10617 #if USE_NEW_PLAYER_SPEED
10618 if (player->MovPos != 0)
10620 player->MovPos += (player->MovPos > 0 ? -1 : 1) * move_stepsize;
10621 player->GfxPos = move_stepsize * (player->MovPos / move_stepsize);
10623 /* before DrawPlayer() to draw correct player graphic for this case */
10624 if (player->MovPos == 0)
10625 CheckGravityMovement(player);
10628 player->MovPos += (player->MovPos > 0 ? -1 : 1) * move_stepsize;
10629 player->GfxPos = move_stepsize * (player->MovPos / move_stepsize);
10631 /* before DrawPlayer() to draw correct player graphic for this case */
10632 if (player->MovPos == 0)
10633 CheckGravityMovement(player);
10636 if (player->MovPos == 0) /* player reached destination field */
10639 printf("::: player reached destination field\n");
10642 if (player->move_delay_reset_counter > 0)
10644 player->move_delay_reset_counter--;
10646 if (player->move_delay_reset_counter == 0)
10648 /* continue with normal speed after quickly moving through gate */
10649 HALVE_PLAYER_SPEED(player);
10651 /* be able to make the next move without delay */
10652 player->move_delay = 0;
10656 player->last_jx = jx;
10657 player->last_jy = jy;
10659 if (Feld[jx][jy] == EL_EXIT_OPEN ||
10660 Feld[jx][jy] == EL_SP_EXIT_OPEN ||
10661 Feld[jx][jy] == EL_SP_EXIT_OPENING) /* <-- special case */
10663 DrawPlayer(player); /* needed here only to cleanup last field */
10664 RemovePlayer(player);
10666 if (local_player->friends_still_needed == 0 ||
10667 IS_SP_ELEMENT(Feld[jx][jy]))
10668 player->LevelSolved = player->GameOver = TRUE;
10671 /* this breaks one level: "machine", level 000 */
10673 int move_direction = player->MovDir;
10674 int enter_side = MV_DIR_OPPOSITE(move_direction);
10675 int leave_side = move_direction;
10676 int old_jx = last_jx;
10677 int old_jy = last_jy;
10678 int old_element = Feld[old_jx][old_jy];
10679 int new_element = Feld[jx][jy];
10681 if (IS_CUSTOM_ELEMENT(old_element))
10682 CheckElementChangeByPlayer(old_jx, old_jy, old_element,
10684 player->index_bit, leave_side);
10686 CheckTriggeredElementChangeByPlayer(old_jx, old_jy, old_element,
10687 CE_PLAYER_LEAVES_X,
10688 player->index_bit, leave_side);
10690 if (IS_CUSTOM_ELEMENT(new_element))
10691 CheckElementChangeByPlayer(jx, jy, new_element, CE_ENTERED_BY_PLAYER,
10692 player->index_bit, enter_side);
10694 CheckTriggeredElementChangeByPlayer(jx, jy, new_element,
10695 CE_PLAYER_ENTERS_X,
10696 player->index_bit, enter_side);
10698 CheckTriggeredElementChangeBySide(jx, jy, player->element_nr,
10699 CE_MOVE_OF_X, move_direction);
10702 if (game.engine_version >= VERSION_IDENT(3,0,7,0))
10704 TestIfPlayerTouchesBadThing(jx, jy);
10705 TestIfPlayerTouchesCustomElement(jx, jy);
10707 /* needed because pushed element has not yet reached its destination,
10708 so it would trigger a change event at its previous field location */
10709 if (!player->is_pushing)
10710 TestIfElementTouchesCustomElement(jx, jy); /* for empty space */
10712 if (!player->active)
10713 RemovePlayer(player);
10716 if (level.use_step_counter)
10726 if (TimeLeft <= 10 && setup.time_limit)
10727 PlaySoundStereo(SND_GAME_RUNNING_OUT_OF_TIME, SOUND_MIDDLE);
10729 DrawGameValue_Time(TimeLeft);
10731 if (!TimeLeft && setup.time_limit)
10732 for (i = 0; i < MAX_PLAYERS; i++)
10733 KillPlayer(&stored_player[i]);
10735 else if (level.time == 0 && !AllPlayersGone) /* level w/o time limit */
10736 DrawGameValue_Time(TimePlayed);
10739 if (tape.single_step && tape.recording && !tape.pausing &&
10740 !player->programmed_action)
10741 TapeTogglePause(TAPE_TOGGLE_AUTOMATIC);
10745 void ScrollScreen(struct PlayerInfo *player, int mode)
10747 static unsigned long screen_frame_counter = 0;
10749 if (mode == SCROLL_INIT)
10751 /* set scrolling step size according to actual player's moving speed */
10752 ScrollStepSize = TILEX / player->move_delay_value;
10754 screen_frame_counter = FrameCounter;
10755 ScreenMovDir = player->MovDir;
10756 ScreenMovPos = player->MovPos;
10757 ScreenGfxPos = ScrollStepSize * (ScreenMovPos / ScrollStepSize);
10760 else if (!FrameReached(&screen_frame_counter, 1))
10765 ScreenMovPos += (ScreenMovPos > 0 ? -1 : 1) * ScrollStepSize;
10766 ScreenGfxPos = ScrollStepSize * (ScreenMovPos / ScrollStepSize);
10767 redraw_mask |= REDRAW_FIELD;
10770 ScreenMovDir = MV_NONE;
10773 void TestIfPlayerTouchesCustomElement(int x, int y)
10775 static int xy[4][2] =
10782 static int trigger_sides[4][2] =
10784 /* center side border side */
10785 { CH_SIDE_TOP, CH_SIDE_BOTTOM }, /* check top */
10786 { CH_SIDE_LEFT, CH_SIDE_RIGHT }, /* check left */
10787 { CH_SIDE_RIGHT, CH_SIDE_LEFT }, /* check right */
10788 { CH_SIDE_BOTTOM, CH_SIDE_TOP } /* check bottom */
10790 static int touch_dir[4] =
10792 MV_LEFT | MV_RIGHT,
10797 int center_element = Feld[x][y]; /* should always be non-moving! */
10800 for (i = 0; i < NUM_DIRECTIONS; i++)
10802 int xx = x + xy[i][0];
10803 int yy = y + xy[i][1];
10804 int center_side = trigger_sides[i][0];
10805 int border_side = trigger_sides[i][1];
10806 int border_element;
10808 if (!IN_LEV_FIELD(xx, yy))
10811 if (IS_PLAYER(x, y))
10813 struct PlayerInfo *player = PLAYERINFO(x, y);
10815 if (game.engine_version < VERSION_IDENT(3,0,7,0))
10816 border_element = Feld[xx][yy]; /* may be moving! */
10817 else if (!IS_MOVING(xx, yy) && !IS_BLOCKED(xx, yy))
10818 border_element = Feld[xx][yy];
10819 else if (MovDir[xx][yy] & touch_dir[i]) /* elements are touching */
10820 border_element = MovingOrBlocked2Element(xx, yy);
10822 continue; /* center and border element do not touch */
10824 CheckElementChangeByPlayer(xx, yy, border_element, CE_TOUCHED_BY_PLAYER,
10825 player->index_bit, border_side);
10826 CheckTriggeredElementChangeByPlayer(xx, yy, border_element,
10827 CE_PLAYER_TOUCHES_X,
10828 player->index_bit, border_side);
10830 else if (IS_PLAYER(xx, yy))
10832 struct PlayerInfo *player = PLAYERINFO(xx, yy);
10834 if (game.engine_version >= VERSION_IDENT(3,0,7,0))
10836 if (player->MovPos != 0 && !(player->MovDir & touch_dir[i]))
10837 continue; /* center and border element do not touch */
10840 CheckElementChangeByPlayer(x, y, center_element, CE_TOUCHED_BY_PLAYER,
10841 player->index_bit, center_side);
10842 CheckTriggeredElementChangeByPlayer(x, y, center_element,
10843 CE_PLAYER_TOUCHES_X,
10844 player->index_bit, center_side);
10850 #if USE_ELEMENT_TOUCHING_BUGFIX
10852 void TestIfElementTouchesCustomElement(int x, int y)
10854 static int xy[4][2] =
10861 static int trigger_sides[4][2] =
10863 /* center side border side */
10864 { CH_SIDE_TOP, CH_SIDE_BOTTOM }, /* check top */
10865 { CH_SIDE_LEFT, CH_SIDE_RIGHT }, /* check left */
10866 { CH_SIDE_RIGHT, CH_SIDE_LEFT }, /* check right */
10867 { CH_SIDE_BOTTOM, CH_SIDE_TOP } /* check bottom */
10869 static int touch_dir[4] =
10871 MV_LEFT | MV_RIGHT,
10876 boolean change_center_element = FALSE;
10877 int center_element = Feld[x][y]; /* should always be non-moving! */
10878 int border_element_old[NUM_DIRECTIONS];
10881 for (i = 0; i < NUM_DIRECTIONS; i++)
10883 int xx = x + xy[i][0];
10884 int yy = y + xy[i][1];
10885 int border_element;
10887 border_element_old[i] = -1;
10889 if (!IN_LEV_FIELD(xx, yy))
10892 if (game.engine_version < VERSION_IDENT(3,0,7,0))
10893 border_element = Feld[xx][yy]; /* may be moving! */
10894 else if (!IS_MOVING(xx, yy) && !IS_BLOCKED(xx, yy))
10895 border_element = Feld[xx][yy];
10896 else if (MovDir[xx][yy] & touch_dir[i]) /* elements are touching */
10897 border_element = MovingOrBlocked2Element(xx, yy);
10899 continue; /* center and border element do not touch */
10901 border_element_old[i] = border_element;
10904 for (i = 0; i < NUM_DIRECTIONS; i++)
10906 int xx = x + xy[i][0];
10907 int yy = y + xy[i][1];
10908 int center_side = trigger_sides[i][0];
10909 int border_element = border_element_old[i];
10911 if (border_element == -1)
10914 /* check for change of border element */
10915 CheckElementChangeBySide(xx, yy, border_element, center_element,
10916 CE_TOUCHING_X, center_side);
10919 for (i = 0; i < NUM_DIRECTIONS; i++)
10921 int border_side = trigger_sides[i][1];
10922 int border_element = border_element_old[i];
10924 if (border_element == -1)
10927 /* check for change of center element (but change it only once) */
10928 if (!change_center_element)
10929 change_center_element =
10930 CheckElementChangeBySide(x, y, center_element, border_element,
10931 CE_TOUCHING_X, border_side);
10937 void TestIfElementTouchesCustomElement_OLD(int x, int y)
10939 static int xy[4][2] =
10946 static int trigger_sides[4][2] =
10948 /* center side border side */
10949 { CH_SIDE_TOP, CH_SIDE_BOTTOM }, /* check top */
10950 { CH_SIDE_LEFT, CH_SIDE_RIGHT }, /* check left */
10951 { CH_SIDE_RIGHT, CH_SIDE_LEFT }, /* check right */
10952 { CH_SIDE_BOTTOM, CH_SIDE_TOP } /* check bottom */
10954 static int touch_dir[4] =
10956 MV_LEFT | MV_RIGHT,
10961 boolean change_center_element = FALSE;
10962 int center_element = Feld[x][y]; /* should always be non-moving! */
10965 for (i = 0; i < NUM_DIRECTIONS; i++)
10967 int xx = x + xy[i][0];
10968 int yy = y + xy[i][1];
10969 int center_side = trigger_sides[i][0];
10970 int border_side = trigger_sides[i][1];
10971 int border_element;
10973 if (!IN_LEV_FIELD(xx, yy))
10976 if (game.engine_version < VERSION_IDENT(3,0,7,0))
10977 border_element = Feld[xx][yy]; /* may be moving! */
10978 else if (!IS_MOVING(xx, yy) && !IS_BLOCKED(xx, yy))
10979 border_element = Feld[xx][yy];
10980 else if (MovDir[xx][yy] & touch_dir[i]) /* elements are touching */
10981 border_element = MovingOrBlocked2Element(xx, yy);
10983 continue; /* center and border element do not touch */
10985 /* check for change of center element (but change it only once) */
10986 if (!change_center_element)
10987 change_center_element =
10988 CheckElementChangeBySide(x, y, center_element, border_element,
10989 CE_TOUCHING_X, border_side);
10991 /* check for change of border element */
10992 CheckElementChangeBySide(xx, yy, border_element, center_element,
10993 CE_TOUCHING_X, center_side);
10999 void TestIfElementHitsCustomElement(int x, int y, int direction)
11001 int dx = (direction == MV_LEFT ? -1 : direction == MV_RIGHT ? +1 : 0);
11002 int dy = (direction == MV_UP ? -1 : direction == MV_DOWN ? +1 : 0);
11003 int hitx = x + dx, hity = y + dy;
11004 int hitting_element = Feld[x][y];
11005 int touched_element;
11007 if (IN_LEV_FIELD(hitx, hity) && IS_FREE(hitx, hity))
11010 touched_element = (IN_LEV_FIELD(hitx, hity) ?
11011 MovingOrBlocked2Element(hitx, hity) : EL_STEELWALL);
11013 if (IN_LEV_FIELD(hitx, hity))
11015 int opposite_direction = MV_DIR_OPPOSITE(direction);
11016 int hitting_side = direction;
11017 int touched_side = opposite_direction;
11018 boolean object_hit = (!IS_MOVING(hitx, hity) ||
11019 MovDir[hitx][hity] != direction ||
11020 ABS(MovPos[hitx][hity]) <= TILEY / 2);
11026 CheckElementChangeBySide(x, y, hitting_element, touched_element,
11027 CE_HITTING_X, touched_side);
11029 CheckElementChangeBySide(hitx, hity, touched_element,
11030 hitting_element, CE_HIT_BY_X, hitting_side);
11032 CheckElementChangeBySide(hitx, hity, touched_element, hitting_element,
11033 CE_HIT_BY_SOMETHING, opposite_direction);
11037 /* "hitting something" is also true when hitting the playfield border */
11038 CheckElementChangeBySide(x, y, hitting_element, touched_element,
11039 CE_HITTING_SOMETHING, direction);
11043 void TestIfElementSmashesCustomElement(int x, int y, int direction)
11045 int dx = (direction == MV_LEFT ? -1 : direction == MV_RIGHT ? +1 : 0);
11046 int dy = (direction == MV_UP ? -1 : direction == MV_DOWN ? +1 : 0);
11047 int hitx = x + dx, hity = y + dy;
11048 int hitting_element = Feld[x][y];
11049 int touched_element;
11051 boolean object_hit = (IN_LEV_FIELD(hitx, hity) &&
11052 !IS_FREE(hitx, hity) &&
11053 (!IS_MOVING(hitx, hity) ||
11054 MovDir[hitx][hity] != direction ||
11055 ABS(MovPos[hitx][hity]) <= TILEY / 2));
11058 if (IN_LEV_FIELD(hitx, hity) && IS_FREE(hitx, hity))
11062 if (IN_LEV_FIELD(hitx, hity) && !object_hit)
11066 touched_element = (IN_LEV_FIELD(hitx, hity) ?
11067 MovingOrBlocked2Element(hitx, hity) : EL_STEELWALL);
11069 CheckElementChangeBySide(x, y, hitting_element, touched_element,
11070 EP_CAN_SMASH_EVERYTHING, direction);
11072 if (IN_LEV_FIELD(hitx, hity))
11074 int opposite_direction = MV_DIR_OPPOSITE(direction);
11075 int hitting_side = direction;
11076 int touched_side = opposite_direction;
11078 int touched_element = MovingOrBlocked2Element(hitx, hity);
11081 boolean object_hit = (!IS_MOVING(hitx, hity) ||
11082 MovDir[hitx][hity] != direction ||
11083 ABS(MovPos[hitx][hity]) <= TILEY / 2);
11092 CheckElementChangeBySide(hitx, hity, touched_element, hitting_element,
11093 CE_SMASHED_BY_SOMETHING, opposite_direction);
11095 CheckElementChangeBySide(x, y, hitting_element, touched_element,
11096 CE_OTHER_IS_SMASHING, touched_side);
11098 CheckElementChangeBySide(hitx, hity, touched_element, hitting_element,
11099 CE_OTHER_GETS_SMASHED, hitting_side);
11105 void TestIfGoodThingHitsBadThing(int good_x, int good_y, int good_move_dir)
11107 int i, kill_x = -1, kill_y = -1;
11109 int bad_element = -1;
11110 static int test_xy[4][2] =
11117 static int test_dir[4] =
11125 for (i = 0; i < NUM_DIRECTIONS; i++)
11127 int test_x, test_y, test_move_dir, test_element;
11129 test_x = good_x + test_xy[i][0];
11130 test_y = good_y + test_xy[i][1];
11132 if (!IN_LEV_FIELD(test_x, test_y))
11136 (IS_MOVING(test_x, test_y) ? MovDir[test_x][test_y] : MV_NONE);
11138 test_element = MovingOrBlocked2ElementIfNotLeaving(test_x, test_y);
11140 /* 1st case: good thing is moving towards DONT_RUN_INTO style bad thing;
11141 2nd case: DONT_TOUCH style bad thing does not move away from good thing
11143 if ((DONT_RUN_INTO(test_element) && good_move_dir == test_dir[i]) ||
11144 (DONT_TOUCH(test_element) && test_move_dir != test_dir[i]))
11148 bad_element = test_element;
11154 if (kill_x != -1 || kill_y != -1)
11156 if (IS_PLAYER(good_x, good_y))
11158 struct PlayerInfo *player = PLAYERINFO(good_x, good_y);
11160 if (player->shield_deadly_time_left > 0 &&
11161 !IS_INDESTRUCTIBLE(bad_element))
11162 Bang(kill_x, kill_y);
11163 else if (!PLAYER_ENEMY_PROTECTED(good_x, good_y))
11164 KillPlayer(player);
11167 Bang(good_x, good_y);
11171 void TestIfBadThingHitsGoodThing(int bad_x, int bad_y, int bad_move_dir)
11173 int i, kill_x = -1, kill_y = -1;
11174 int bad_element = Feld[bad_x][bad_y];
11175 static int test_xy[4][2] =
11182 static int touch_dir[4] =
11184 MV_LEFT | MV_RIGHT,
11189 static int test_dir[4] =
11197 if (bad_element == EL_EXPLOSION) /* skip just exploding bad things */
11200 for (i = 0; i < NUM_DIRECTIONS; i++)
11202 int test_x, test_y, test_move_dir, test_element;
11204 test_x = bad_x + test_xy[i][0];
11205 test_y = bad_y + test_xy[i][1];
11206 if (!IN_LEV_FIELD(test_x, test_y))
11210 (IS_MOVING(test_x, test_y) ? MovDir[test_x][test_y] : MV_NONE);
11212 test_element = Feld[test_x][test_y];
11214 /* 1st case: good thing is moving towards DONT_RUN_INTO style bad thing;
11215 2nd case: DONT_TOUCH style bad thing does not move away from good thing
11217 if ((DONT_RUN_INTO(bad_element) && bad_move_dir == test_dir[i]) ||
11218 (DONT_TOUCH(bad_element) && test_move_dir != test_dir[i]))
11220 /* good thing is player or penguin that does not move away */
11221 if (IS_PLAYER(test_x, test_y))
11223 struct PlayerInfo *player = PLAYERINFO(test_x, test_y);
11225 if (bad_element == EL_ROBOT && player->is_moving)
11226 continue; /* robot does not kill player if he is moving */
11228 if (game.engine_version >= VERSION_IDENT(3,0,7,0))
11230 if (player->MovPos != 0 && !(player->MovDir & touch_dir[i]))
11231 continue; /* center and border element do not touch */
11238 else if (test_element == EL_PENGUIN)
11247 if (kill_x != -1 || kill_y != -1)
11249 if (IS_PLAYER(kill_x, kill_y))
11251 struct PlayerInfo *player = PLAYERINFO(kill_x, kill_y);
11253 if (player->shield_deadly_time_left > 0 &&
11254 !IS_INDESTRUCTIBLE(bad_element))
11255 Bang(bad_x, bad_y);
11256 else if (!PLAYER_ENEMY_PROTECTED(kill_x, kill_y))
11257 KillPlayer(player);
11260 Bang(kill_x, kill_y);
11264 void TestIfPlayerTouchesBadThing(int x, int y)
11266 TestIfGoodThingHitsBadThing(x, y, MV_NONE);
11269 void TestIfPlayerRunsIntoBadThing(int x, int y, int move_dir)
11271 TestIfGoodThingHitsBadThing(x, y, move_dir);
11274 void TestIfBadThingTouchesPlayer(int x, int y)
11276 TestIfBadThingHitsGoodThing(x, y, MV_NONE);
11279 void TestIfBadThingRunsIntoPlayer(int x, int y, int move_dir)
11281 TestIfBadThingHitsGoodThing(x, y, move_dir);
11284 void TestIfFriendTouchesBadThing(int x, int y)
11286 TestIfGoodThingHitsBadThing(x, y, MV_NONE);
11289 void TestIfBadThingTouchesFriend(int x, int y)
11291 TestIfBadThingHitsGoodThing(x, y, MV_NONE);
11294 void TestIfBadThingTouchesOtherBadThing(int bad_x, int bad_y)
11296 int i, kill_x = bad_x, kill_y = bad_y;
11297 static int xy[4][2] =
11305 for (i = 0; i < NUM_DIRECTIONS; i++)
11309 x = bad_x + xy[i][0];
11310 y = bad_y + xy[i][1];
11311 if (!IN_LEV_FIELD(x, y))
11314 element = Feld[x][y];
11315 if (IS_AMOEBOID(element) || element == EL_GAME_OF_LIFE ||
11316 element == EL_AMOEBA_GROWING || element == EL_AMOEBA_DROP)
11324 if (kill_x != bad_x || kill_y != bad_y)
11325 Bang(bad_x, bad_y);
11328 void KillPlayer(struct PlayerInfo *player)
11330 int jx = player->jx, jy = player->jy;
11332 if (!player->active)
11335 /* remove accessible field at the player's position */
11336 Feld[jx][jy] = EL_EMPTY;
11338 /* deactivate shield (else Bang()/Explode() would not work right) */
11339 player->shield_normal_time_left = 0;
11340 player->shield_deadly_time_left = 0;
11343 BuryPlayer(player);
11346 static void KillPlayerUnlessEnemyProtected(int x, int y)
11348 if (!PLAYER_ENEMY_PROTECTED(x, y))
11349 KillPlayer(PLAYERINFO(x, y));
11352 static void KillPlayerUnlessExplosionProtected(int x, int y)
11354 if (!PLAYER_EXPLOSION_PROTECTED(x, y))
11355 KillPlayer(PLAYERINFO(x, y));
11358 void BuryPlayer(struct PlayerInfo *player)
11360 int jx = player->jx, jy = player->jy;
11362 if (!player->active)
11365 PlayLevelSoundElementAction(jx, jy, player->artwork_element, ACTION_DYING);
11366 PlayLevelSound(jx, jy, SND_GAME_LOSING);
11368 player->GameOver = TRUE;
11369 RemovePlayer(player);
11372 void RemovePlayer(struct PlayerInfo *player)
11374 int jx = player->jx, jy = player->jy;
11375 int i, found = FALSE;
11377 player->present = FALSE;
11378 player->active = FALSE;
11380 if (!ExplodeField[jx][jy])
11381 StorePlayer[jx][jy] = 0;
11383 if (player->is_moving)
11384 DrawLevelField(player->last_jx, player->last_jy);
11386 for (i = 0; i < MAX_PLAYERS; i++)
11387 if (stored_player[i].active)
11391 AllPlayersGone = TRUE;
11397 #if USE_NEW_SNAP_DELAY
11398 static void setFieldForSnapping(int x, int y, int element, int direction)
11400 struct ElementInfo *ei = &element_info[element];
11401 int direction_bit = MV_DIR_TO_BIT(direction);
11402 int graphic_snapping = ei->direction_graphic[ACTION_SNAPPING][direction_bit];
11403 int action = (graphic_snapping != IMG_EMPTY_SPACE ? ACTION_SNAPPING :
11404 IS_DIGGABLE(element) ? ACTION_DIGGING : ACTION_COLLECTING);
11406 Feld[x][y] = EL_ELEMENT_SNAPPING;
11407 MovDelay[x][y] = MOVE_DELAY_NORMAL_SPEED + 1 - 1;
11409 ResetGfxAnimation(x, y);
11411 GfxElement[x][y] = element;
11412 GfxAction[x][y] = action;
11413 GfxDir[x][y] = direction;
11414 GfxFrame[x][y] = -1;
11419 =============================================================================
11420 checkDiagonalPushing()
11421 -----------------------------------------------------------------------------
11422 check if diagonal input device direction results in pushing of object
11423 (by checking if the alternative direction is walkable, diggable, ...)
11424 =============================================================================
11427 static boolean checkDiagonalPushing(struct PlayerInfo *player,
11428 int x, int y, int real_dx, int real_dy)
11430 int jx, jy, dx, dy, xx, yy;
11432 if (real_dx == 0 || real_dy == 0) /* no diagonal direction => push */
11435 /* diagonal direction: check alternative direction */
11440 xx = jx + (dx == 0 ? real_dx : 0);
11441 yy = jy + (dy == 0 ? real_dy : 0);
11443 return (!IN_LEV_FIELD(xx, yy) || IS_SOLID_FOR_PUSHING(Feld[xx][yy]));
11447 =============================================================================
11449 -----------------------------------------------------------------------------
11450 x, y: field next to player (non-diagonal) to try to dig to
11451 real_dx, real_dy: direction as read from input device (can be diagonal)
11452 =============================================================================
11455 int DigField(struct PlayerInfo *player,
11456 int oldx, int oldy, int x, int y,
11457 int real_dx, int real_dy, int mode)
11459 boolean is_player = (IS_PLAYER(oldx, oldy) || mode != DF_DIG);
11460 boolean player_was_pushing = player->is_pushing;
11461 boolean player_can_move = (!player->cannot_move && mode != DF_SNAP);
11462 boolean player_can_move_or_snap = (!player->cannot_move || mode == DF_SNAP);
11463 int jx = oldx, jy = oldy;
11464 int dx = x - jx, dy = y - jy;
11465 int nextx = x + dx, nexty = y + dy;
11466 int move_direction = (dx == -1 ? MV_LEFT :
11467 dx == +1 ? MV_RIGHT :
11469 dy == +1 ? MV_DOWN : MV_NONE);
11470 int opposite_direction = MV_DIR_OPPOSITE(move_direction);
11471 int dig_side = MV_DIR_OPPOSITE(move_direction);
11472 int old_element = Feld[jx][jy];
11473 #if USE_FIXED_DONT_RUN_INTO
11474 int element = MovingOrBlocked2ElementIfNotLeaving(x, y);
11480 if (is_player) /* function can also be called by EL_PENGUIN */
11482 if (player->MovPos == 0)
11484 player->is_digging = FALSE;
11485 player->is_collecting = FALSE;
11488 if (player->MovPos == 0) /* last pushing move finished */
11489 player->is_pushing = FALSE;
11491 if (mode == DF_NO_PUSH) /* player just stopped pushing */
11493 player->is_switching = FALSE;
11494 player->push_delay = -1;
11496 return MP_NO_ACTION;
11500 #if !USE_FIXED_DONT_RUN_INTO
11501 if (IS_MOVING(x, y) || IS_PLAYER(x, y))
11502 return MP_NO_ACTION;
11505 if (IS_TUBE(Back[jx][jy]) && game.engine_version >= VERSION_IDENT(2,2,0,0))
11506 old_element = Back[jx][jy];
11508 /* in case of element dropped at player position, check background */
11509 else if (Back[jx][jy] != EL_EMPTY &&
11510 game.engine_version >= VERSION_IDENT(2,2,0,0))
11511 old_element = Back[jx][jy];
11514 #if USE_FIXED_DONT_RUN_INTO
11515 if (player_can_move && DONT_RUN_INTO(element))
11517 if (element == EL_ACID && dx == 0 && dy == 1)
11520 Feld[jx][jy] = EL_PLAYER_1;
11521 InitMovingField(jx, jy, MV_DOWN);
11522 Store[jx][jy] = EL_ACID;
11523 ContinueMoving(jx, jy);
11524 BuryPlayer(player);
11527 TestIfPlayerRunsIntoBadThing(jx, jy, player->MovDir);
11529 return MP_DONT_RUN_INTO;
11535 #if USE_FIXED_DONT_RUN_INTO
11536 if (player_can_move && DONT_RUN_INTO(element))
11538 TestIfPlayerRunsIntoBadThing(jx, jy, player->MovDir);
11540 return MP_DONT_RUN_INTO;
11545 if (IS_WALKABLE(old_element) && !ACCESS_FROM(old_element, move_direction))
11546 return MP_NO_ACTION; /* field has no opening in this direction */
11548 if (IS_PASSABLE(old_element) && !ACCESS_FROM(old_element,opposite_direction))
11549 return MP_NO_ACTION; /* field has no opening in this direction */
11552 #if USE_FIXED_DONT_RUN_INTO
11553 if (player_can_move && element == EL_ACID && move_direction == MV_DOWN)
11556 Feld[jx][jy] = EL_PLAYER_1;
11557 InitMovingField(jx, jy, MV_DOWN);
11558 Store[jx][jy] = EL_ACID;
11559 ContinueMoving(jx, jy);
11560 BuryPlayer(player);
11562 return MP_DONT_RUN_INTO;
11568 #if USE_FIXED_DONT_RUN_INTO
11569 if (player_can_move && DONT_RUN_INTO(element))
11571 if (element == EL_ACID && dx == 0 && dy == 1)
11574 Feld[jx][jy] = EL_PLAYER_1;
11575 InitMovingField(jx, jy, MV_DOWN);
11576 Store[jx][jy] = EL_ACID;
11577 ContinueMoving(jx, jy);
11578 BuryPlayer(player);
11581 TestIfPlayerRunsIntoBadThing(jx, jy, player->MovDir);
11583 return MP_DONT_RUN_INTO;
11588 #if USE_FIXED_DONT_RUN_INTO
11589 if (IS_MOVING(x, y) || IS_PLAYER(x, y))
11590 return MP_NO_ACTION;
11593 #if !USE_FIXED_DONT_RUN_INTO
11594 element = Feld[x][y];
11597 collect_count = element_info[element].collect_count_initial;
11599 if (!is_player && !IS_COLLECTIBLE(element)) /* penguin cannot collect it */
11600 return MP_NO_ACTION;
11602 if (game.engine_version < VERSION_IDENT(2,2,0,0))
11603 player_can_move = player_can_move_or_snap;
11605 if (mode == DF_SNAP && !IS_SNAPPABLE(element) &&
11606 game.engine_version >= VERSION_IDENT(2,2,0,0))
11608 CheckElementChangeByPlayer(x, y, element, CE_SNAPPED_BY_PLAYER,
11609 player->index_bit, dig_side);
11610 CheckTriggeredElementChangeByPlayer(x, y, element, CE_PLAYER_SNAPS_X,
11611 player->index_bit, dig_side);
11613 if (Feld[x][y] != element) /* field changed by snapping */
11616 return MP_NO_ACTION;
11619 if (game.gravity && is_player && !player->is_auto_moving &&
11620 canFallDown(player) && move_direction != MV_DOWN &&
11621 !canMoveToValidFieldWithGravity(jx, jy, move_direction))
11622 return MP_NO_ACTION; /* player cannot walk here due to gravity */
11624 if (player_can_move &&
11625 IS_WALKABLE(element) && ACCESS_FROM(element, opposite_direction))
11627 int sound_element = SND_ELEMENT(element);
11628 int sound_action = ACTION_WALKING;
11630 if (IS_RND_GATE(element))
11632 if (!player->key[RND_GATE_NR(element)])
11633 return MP_NO_ACTION;
11635 else if (IS_RND_GATE_GRAY(element))
11637 if (!player->key[RND_GATE_GRAY_NR(element)])
11638 return MP_NO_ACTION;
11640 else if (IS_RND_GATE_GRAY_ACTIVE(element))
11642 if (!player->key[RND_GATE_GRAY_ACTIVE_NR(element)])
11643 return MP_NO_ACTION;
11645 else if (element == EL_EXIT_OPEN ||
11646 element == EL_SP_EXIT_OPEN ||
11647 element == EL_SP_EXIT_OPENING)
11649 sound_action = ACTION_PASSING; /* player is passing exit */
11651 else if (element == EL_EMPTY)
11653 sound_action = ACTION_MOVING; /* nothing to walk on */
11656 /* play sound from background or player, whatever is available */
11657 if (element_info[sound_element].sound[sound_action] != SND_UNDEFINED)
11658 PlayLevelSoundElementAction(x, y, sound_element, sound_action);
11660 PlayLevelSoundElementAction(x, y, player->artwork_element, sound_action);
11662 else if (player_can_move &&
11663 IS_PASSABLE(element) && canPassField(x, y, move_direction))
11665 if (!ACCESS_FROM(element, opposite_direction))
11666 return MP_NO_ACTION; /* field not accessible from this direction */
11668 if (CAN_MOVE(element)) /* only fixed elements can be passed! */
11669 return MP_NO_ACTION;
11671 if (IS_EM_GATE(element))
11673 if (!player->key[EM_GATE_NR(element)])
11674 return MP_NO_ACTION;
11676 else if (IS_EM_GATE_GRAY(element))
11678 if (!player->key[EM_GATE_GRAY_NR(element)])
11679 return MP_NO_ACTION;
11681 else if (IS_EM_GATE_GRAY_ACTIVE(element))
11683 if (!player->key[EM_GATE_GRAY_ACTIVE_NR(element)])
11684 return MP_NO_ACTION;
11686 else if (IS_SP_PORT(element))
11688 if (element == EL_SP_GRAVITY_PORT_LEFT ||
11689 element == EL_SP_GRAVITY_PORT_RIGHT ||
11690 element == EL_SP_GRAVITY_PORT_UP ||
11691 element == EL_SP_GRAVITY_PORT_DOWN)
11692 game.gravity = !game.gravity;
11693 else if (element == EL_SP_GRAVITY_ON_PORT_LEFT ||
11694 element == EL_SP_GRAVITY_ON_PORT_RIGHT ||
11695 element == EL_SP_GRAVITY_ON_PORT_UP ||
11696 element == EL_SP_GRAVITY_ON_PORT_DOWN)
11697 game.gravity = TRUE;
11698 else if (element == EL_SP_GRAVITY_OFF_PORT_LEFT ||
11699 element == EL_SP_GRAVITY_OFF_PORT_RIGHT ||
11700 element == EL_SP_GRAVITY_OFF_PORT_UP ||
11701 element == EL_SP_GRAVITY_OFF_PORT_DOWN)
11702 game.gravity = FALSE;
11705 /* automatically move to the next field with double speed */
11706 player->programmed_action = move_direction;
11708 if (player->move_delay_reset_counter == 0)
11710 player->move_delay_reset_counter = 2; /* two double speed steps */
11712 DOUBLE_PLAYER_SPEED(player);
11715 PlayLevelSoundAction(x, y, ACTION_PASSING);
11717 else if (player_can_move_or_snap && IS_DIGGABLE(element))
11721 if (mode != DF_SNAP)
11723 GfxElement[x][y] = GFX_ELEMENT(element);
11724 player->is_digging = TRUE;
11727 PlayLevelSoundElementAction(x, y, element, ACTION_DIGGING);
11729 CheckTriggeredElementChangeByPlayer(x, y, element, CE_PLAYER_DIGS_X,
11730 player->index_bit, dig_side);
11732 if (mode == DF_SNAP)
11734 #if USE_NEW_SNAP_DELAY
11735 if (level.block_snap_field)
11736 setFieldForSnapping(x, y, element, move_direction);
11738 TestIfElementTouchesCustomElement(x, y); /* for empty space */
11740 TestIfElementTouchesCustomElement(x, y); /* for empty space */
11743 CheckTriggeredElementChangeByPlayer(x, y, element, CE_PLAYER_SNAPS_X,
11744 player->index_bit, dig_side);
11747 else if (player_can_move_or_snap && IS_COLLECTIBLE(element))
11751 if (is_player && mode != DF_SNAP)
11753 GfxElement[x][y] = element;
11754 player->is_collecting = TRUE;
11757 if (element == EL_SPEED_PILL)
11759 player->move_delay_value = MOVE_DELAY_HIGH_SPEED;
11761 else if (element == EL_EXTRA_TIME && level.time > 0)
11763 TimeLeft += level.extra_time;
11764 DrawGameValue_Time(TimeLeft);
11766 else if (element == EL_SHIELD_NORMAL || element == EL_SHIELD_DEADLY)
11768 player->shield_normal_time_left += level.shield_normal_time;
11769 if (element == EL_SHIELD_DEADLY)
11770 player->shield_deadly_time_left += level.shield_deadly_time;
11772 else if (element == EL_DYNAMITE ||
11773 element == EL_EM_DYNAMITE ||
11774 element == EL_SP_DISK_RED)
11776 if (player->inventory_size < MAX_INVENTORY_SIZE)
11777 player->inventory_element[player->inventory_size++] = element;
11780 DrawGameDoorValues();
11782 DrawGameValue_Dynamite(local_player->inventory_size);
11785 else if (element == EL_DYNABOMB_INCREASE_NUMBER)
11787 player->dynabomb_count++;
11788 player->dynabombs_left++;
11790 else if (element == EL_DYNABOMB_INCREASE_SIZE)
11792 player->dynabomb_size++;
11794 else if (element == EL_DYNABOMB_INCREASE_POWER)
11796 player->dynabomb_xl = TRUE;
11798 else if (IS_KEY(element))
11800 player->key[KEY_NR(element)] = TRUE;
11803 DrawGameDoorValues();
11805 DrawGameValue_Keys(player->key);
11808 redraw_mask |= REDRAW_DOOR_1;
11810 else if (IS_ENVELOPE(element))
11812 player->show_envelope = element;
11814 else if (element == EL_EMC_LENSES)
11816 game.lenses_time_left = level.lenses_time * FRAMES_PER_SECOND;
11818 RedrawAllInvisibleElementsForLenses();
11820 else if (element == EL_EMC_MAGNIFIER)
11822 game.magnify_time_left = level.magnify_time * FRAMES_PER_SECOND;
11824 RedrawAllInvisibleElementsForMagnifier();
11826 else if (IS_DROPPABLE(element) ||
11827 IS_THROWABLE(element)) /* can be collected and dropped */
11831 if (collect_count == 0)
11832 player->inventory_infinite_element = element;
11834 for (i = 0; i < collect_count; i++)
11835 if (player->inventory_size < MAX_INVENTORY_SIZE)
11836 player->inventory_element[player->inventory_size++] = element;
11839 DrawGameDoorValues();
11841 DrawGameValue_Dynamite(local_player->inventory_size);
11844 else if (collect_count > 0)
11846 local_player->gems_still_needed -= collect_count;
11847 if (local_player->gems_still_needed < 0)
11848 local_player->gems_still_needed = 0;
11850 DrawGameValue_Emeralds(local_player->gems_still_needed);
11853 RaiseScoreElement(element);
11854 PlayLevelSoundElementAction(x, y, element, ACTION_COLLECTING);
11857 CheckTriggeredElementChangeByPlayer(x, y, element, CE_PLAYER_COLLECTS_X,
11858 player->index_bit, dig_side);
11860 if (mode == DF_SNAP)
11862 #if USE_NEW_SNAP_DELAY
11863 if (level.block_snap_field)
11864 setFieldForSnapping(x, y, element, move_direction);
11866 TestIfElementTouchesCustomElement(x, y); /* for empty space */
11868 TestIfElementTouchesCustomElement(x, y); /* for empty space */
11871 CheckTriggeredElementChangeByPlayer(x, y, element, CE_PLAYER_SNAPS_X,
11872 player->index_bit, dig_side);
11875 else if (player_can_move_or_snap && IS_PUSHABLE(element))
11877 if (mode == DF_SNAP && element != EL_BD_ROCK)
11878 return MP_NO_ACTION;
11880 if (CAN_FALL(element) && dy)
11881 return MP_NO_ACTION;
11883 if (CAN_FALL(element) && IN_LEV_FIELD(x, y + 1) && IS_FREE(x, y + 1) &&
11884 !(element == EL_SPRING && level.use_spring_bug))
11885 return MP_NO_ACTION;
11887 if (CAN_MOVE(element) && GET_MAX_MOVE_DELAY(element) == 0 &&
11888 ((move_direction & MV_VERTICAL &&
11889 ((element_info[element].move_pattern & MV_LEFT &&
11890 IN_LEV_FIELD(x - 1, y) && IS_FREE(x - 1, y)) ||
11891 (element_info[element].move_pattern & MV_RIGHT &&
11892 IN_LEV_FIELD(x + 1, y) && IS_FREE(x + 1, y)))) ||
11893 (move_direction & MV_HORIZONTAL &&
11894 ((element_info[element].move_pattern & MV_UP &&
11895 IN_LEV_FIELD(x, y - 1) && IS_FREE(x, y - 1)) ||
11896 (element_info[element].move_pattern & MV_DOWN &&
11897 IN_LEV_FIELD(x, y + 1) && IS_FREE(x, y + 1))))))
11898 return MP_NO_ACTION;
11900 /* do not push elements already moving away faster than player */
11901 if (CAN_MOVE(element) && MovDir[x][y] == move_direction &&
11902 ABS(getElementMoveStepsize(x, y)) > MOVE_STEPSIZE_NORMAL)
11903 return MP_NO_ACTION;
11905 if (game.engine_version >= VERSION_IDENT(3,1,0,0))
11907 if (player->push_delay_value == -1 || !player_was_pushing)
11908 player->push_delay_value = GET_NEW_PUSH_DELAY(element);
11910 else if (game.engine_version >= VERSION_IDENT(3,0,7,1))
11912 if (player->push_delay_value == -1)
11913 player->push_delay_value = GET_NEW_PUSH_DELAY(element);
11915 else if (game.engine_version >= VERSION_IDENT(2,2,0,7))
11917 if (!player->is_pushing)
11918 player->push_delay_value = GET_NEW_PUSH_DELAY(element);
11921 player->is_pushing = TRUE;
11923 if (!(IN_LEV_FIELD(nextx, nexty) &&
11924 (IS_FREE(nextx, nexty) ||
11925 (Feld[nextx][nexty] == EL_SOKOBAN_FIELD_EMPTY &&
11926 IS_SB_ELEMENT(element)))))
11927 return MP_NO_ACTION;
11929 if (!checkDiagonalPushing(player, x, y, real_dx, real_dy))
11930 return MP_NO_ACTION;
11932 if (player->push_delay == -1) /* new pushing; restart delay */
11933 player->push_delay = 0;
11935 if (player->push_delay < player->push_delay_value &&
11936 !(tape.playing && tape.file_version < FILE_VERSION_2_0) &&
11937 element != EL_SPRING && element != EL_BALLOON)
11939 /* make sure that there is no move delay before next try to push */
11940 if (game.engine_version >= VERSION_IDENT(3,0,7,1))
11941 player->move_delay = 0;
11943 return MP_NO_ACTION;
11946 if (IS_SB_ELEMENT(element))
11948 if (element == EL_SOKOBAN_FIELD_FULL)
11950 Back[x][y] = EL_SOKOBAN_FIELD_EMPTY;
11951 local_player->sokobanfields_still_needed++;
11954 if (Feld[nextx][nexty] == EL_SOKOBAN_FIELD_EMPTY)
11956 Back[nextx][nexty] = EL_SOKOBAN_FIELD_EMPTY;
11957 local_player->sokobanfields_still_needed--;
11960 Feld[x][y] = EL_SOKOBAN_OBJECT;
11962 if (Back[x][y] == Back[nextx][nexty])
11963 PlayLevelSoundAction(x, y, ACTION_PUSHING);
11964 else if (Back[x][y] != 0)
11965 PlayLevelSoundElementAction(x, y, EL_SOKOBAN_FIELD_FULL,
11968 PlayLevelSoundElementAction(nextx, nexty, EL_SOKOBAN_FIELD_EMPTY,
11971 if (local_player->sokobanfields_still_needed == 0 &&
11972 game.emulation == EMU_SOKOBAN)
11974 player->LevelSolved = player->GameOver = TRUE;
11975 PlayLevelSound(x, y, SND_GAME_SOKOBAN_SOLVING);
11979 PlayLevelSoundElementAction(x, y, element, ACTION_PUSHING);
11981 InitMovingField(x, y, move_direction);
11982 GfxAction[x][y] = ACTION_PUSHING;
11984 if (mode == DF_SNAP)
11985 ContinueMoving(x, y);
11987 MovPos[x][y] = (dx != 0 ? dx : dy);
11989 Pushed[x][y] = TRUE;
11990 Pushed[nextx][nexty] = TRUE;
11992 if (game.engine_version < VERSION_IDENT(2,2,0,7))
11993 player->push_delay_value = GET_NEW_PUSH_DELAY(element);
11995 player->push_delay_value = -1; /* get new value later */
11997 /* check for element change _after_ element has been pushed */
11998 if (game.use_change_when_pushing_bug)
12000 CheckElementChangeByPlayer(x, y, element, CE_PUSHED_BY_PLAYER,
12001 player->index_bit, dig_side);
12002 CheckTriggeredElementChangeByPlayer(x, y, element, CE_PLAYER_PUSHES_X,
12003 player->index_bit, dig_side);
12006 else if (IS_SWITCHABLE(element))
12008 if (PLAYER_SWITCHING(player, x, y))
12010 CheckTriggeredElementChangeByPlayer(x, y, element, CE_PLAYER_PRESSES_X,
12011 player->index_bit, dig_side);
12016 player->is_switching = TRUE;
12017 player->switch_x = x;
12018 player->switch_y = y;
12020 PlayLevelSoundElementAction(x, y, element, ACTION_ACTIVATING);
12022 if (element == EL_ROBOT_WHEEL)
12024 Feld[x][y] = EL_ROBOT_WHEEL_ACTIVE;
12028 DrawLevelField(x, y);
12030 else if (element == EL_SP_TERMINAL)
12035 SCAN_PLAYFIELD(xx, yy)
12037 for (yy = 0; yy < lev_fieldy; yy++) for (xx = 0; xx < lev_fieldx; xx++)
12040 if (Feld[xx][yy] == EL_SP_DISK_YELLOW)
12042 else if (Feld[xx][yy] == EL_SP_TERMINAL)
12043 Feld[xx][yy] = EL_SP_TERMINAL_ACTIVE;
12046 else if (IS_BELT_SWITCH(element))
12048 ToggleBeltSwitch(x, y);
12050 else if (element == EL_SWITCHGATE_SWITCH_UP ||
12051 element == EL_SWITCHGATE_SWITCH_DOWN)
12053 ToggleSwitchgateSwitch(x, y);
12055 else if (element == EL_LIGHT_SWITCH ||
12056 element == EL_LIGHT_SWITCH_ACTIVE)
12058 ToggleLightSwitch(x, y);
12060 else if (element == EL_TIMEGATE_SWITCH)
12062 ActivateTimegateSwitch(x, y);
12064 else if (element == EL_BALLOON_SWITCH_LEFT ||
12065 element == EL_BALLOON_SWITCH_RIGHT ||
12066 element == EL_BALLOON_SWITCH_UP ||
12067 element == EL_BALLOON_SWITCH_DOWN ||
12068 element == EL_BALLOON_SWITCH_NONE ||
12069 element == EL_BALLOON_SWITCH_ANY)
12071 game.wind_direction = (element == EL_BALLOON_SWITCH_LEFT ? MV_LEFT :
12072 element == EL_BALLOON_SWITCH_RIGHT ? MV_RIGHT :
12073 element == EL_BALLOON_SWITCH_UP ? MV_UP :
12074 element == EL_BALLOON_SWITCH_DOWN ? MV_DOWN :
12075 element == EL_BALLOON_SWITCH_NONE ? MV_NONE :
12078 else if (element == EL_LAMP)
12080 Feld[x][y] = EL_LAMP_ACTIVE;
12081 local_player->lights_still_needed--;
12083 ResetGfxAnimation(x, y);
12084 DrawLevelField(x, y);
12086 else if (element == EL_TIME_ORB_FULL)
12088 Feld[x][y] = EL_TIME_ORB_EMPTY;
12090 if (level.time > 0 || level.use_time_orb_bug)
12092 TimeLeft += level.time_orb_time;
12093 DrawGameValue_Time(TimeLeft);
12096 ResetGfxAnimation(x, y);
12097 DrawLevelField(x, y);
12099 else if (element == EL_EMC_MAGIC_BALL_SWITCH ||
12100 element == EL_EMC_MAGIC_BALL_SWITCH_ACTIVE)
12104 game.ball_state = !game.ball_state;
12107 SCAN_PLAYFIELD(xx, yy)
12109 for (yy = 0; yy < lev_fieldy; yy++) for (xx = 0; xx < lev_fieldx; xx++)
12112 int e = Feld[xx][yy];
12114 if (game.ball_state)
12116 if (e == EL_EMC_MAGIC_BALL)
12117 CreateField(xx, yy, EL_EMC_MAGIC_BALL_ACTIVE);
12118 else if (e == EL_EMC_MAGIC_BALL_SWITCH)
12119 CreateField(xx, yy, EL_EMC_MAGIC_BALL_SWITCH_ACTIVE);
12123 if (e == EL_EMC_MAGIC_BALL_ACTIVE)
12124 CreateField(xx, yy, EL_EMC_MAGIC_BALL);
12125 else if (e == EL_EMC_MAGIC_BALL_SWITCH_ACTIVE)
12126 CreateField(xx, yy, EL_EMC_MAGIC_BALL_SWITCH);
12131 CheckTriggeredElementChangeByPlayer(x, y, element, CE_SWITCH_OF_X,
12132 player->index_bit, dig_side);
12134 CheckTriggeredElementChangeByPlayer(x, y, element, CE_PLAYER_SWITCHES_X,
12135 player->index_bit, dig_side);
12137 CheckTriggeredElementChangeByPlayer(x, y, element, CE_PLAYER_PRESSES_X,
12138 player->index_bit, dig_side);
12144 if (!PLAYER_SWITCHING(player, x, y))
12146 player->is_switching = TRUE;
12147 player->switch_x = x;
12148 player->switch_y = y;
12150 CheckElementChangeByPlayer(x, y, element, CE_SWITCHED,
12151 player->index_bit, dig_side);
12152 CheckTriggeredElementChangeByPlayer(x, y, element, CE_SWITCH_OF_X,
12153 player->index_bit, dig_side);
12155 CheckElementChangeByPlayer(x, y, element, CE_SWITCHED_BY_PLAYER,
12156 player->index_bit, dig_side);
12157 CheckTriggeredElementChangeByPlayer(x, y, element, CE_PLAYER_SWITCHES_X,
12158 player->index_bit, dig_side);
12161 CheckElementChangeByPlayer(x, y, element, CE_PRESSED_BY_PLAYER,
12162 player->index_bit, dig_side);
12163 CheckTriggeredElementChangeByPlayer(x, y, element, CE_PLAYER_PRESSES_X,
12164 player->index_bit, dig_side);
12166 return MP_NO_ACTION;
12169 player->push_delay = -1;
12171 if (is_player) /* function can also be called by EL_PENGUIN */
12173 if (Feld[x][y] != element) /* really digged/collected something */
12174 player->is_collecting = !player->is_digging;
12180 boolean SnapField(struct PlayerInfo *player, int dx, int dy)
12182 int jx = player->jx, jy = player->jy;
12183 int x = jx + dx, y = jy + dy;
12184 int snap_direction = (dx == -1 ? MV_LEFT :
12185 dx == +1 ? MV_RIGHT :
12187 dy == +1 ? MV_DOWN : MV_NONE);
12188 boolean can_continue_snapping = (level.continuous_snapping &&
12189 WasJustFalling[x][y] < CHECK_DELAY_FALLING);
12191 if (player->MovPos != 0 && game.engine_version >= VERSION_IDENT(2,2,0,0))
12194 if (!player->active || !IN_LEV_FIELD(x, y))
12202 if (player->MovPos == 0)
12203 player->is_pushing = FALSE;
12205 player->is_snapping = FALSE;
12207 if (player->MovPos == 0)
12209 player->is_moving = FALSE;
12210 player->is_digging = FALSE;
12211 player->is_collecting = FALSE;
12217 #if USE_NEW_CONTINUOUS_SNAPPING
12218 /* prevent snapping with already pressed snap key when not allowed */
12219 if (player->is_snapping && !can_continue_snapping)
12222 if (player->is_snapping)
12226 player->MovDir = snap_direction;
12228 if (player->MovPos == 0)
12230 player->is_moving = FALSE;
12231 player->is_digging = FALSE;
12232 player->is_collecting = FALSE;
12235 player->is_dropping = FALSE;
12236 player->is_dropping_pressed = FALSE;
12237 player->drop_pressed_delay = 0;
12239 if (DigField(player, jx, jy, x, y, 0, 0, DF_SNAP) == MP_NO_ACTION)
12242 player->is_snapping = TRUE;
12244 if (player->MovPos == 0)
12246 player->is_moving = FALSE;
12247 player->is_digging = FALSE;
12248 player->is_collecting = FALSE;
12251 if (player->MovPos != 0) /* prevent graphic bugs in versions < 2.2.0 */
12252 DrawLevelField(player->last_jx, player->last_jy);
12254 DrawLevelField(x, y);
12259 boolean DropElement(struct PlayerInfo *player)
12261 int old_element, new_element;
12262 int dropx = player->jx, dropy = player->jy;
12263 int drop_direction = player->MovDir;
12264 int drop_side = drop_direction;
12265 int drop_element = (player->inventory_size > 0 ?
12266 player->inventory_element[player->inventory_size - 1] :
12267 player->inventory_infinite_element != EL_UNDEFINED ?
12268 player->inventory_infinite_element :
12269 player->dynabombs_left > 0 ?
12270 EL_DYNABOMB_PLAYER_1_ACTIVE + player->index_nr :
12273 player->is_dropping_pressed = TRUE;
12275 /* do not drop an element on top of another element; when holding drop key
12276 pressed without moving, dropped element must move away before the next
12277 element can be dropped (this is especially important if the next element
12278 is dynamite, which can be placed on background for historical reasons) */
12279 if (PLAYER_DROPPING(player, dropx, dropy) && Feld[dropx][dropy] != EL_EMPTY)
12282 if (IS_THROWABLE(drop_element))
12284 dropx += GET_DX_FROM_DIR(drop_direction);
12285 dropy += GET_DY_FROM_DIR(drop_direction);
12287 if (!IN_LEV_FIELD(dropx, dropy))
12291 old_element = Feld[dropx][dropy]; /* old element at dropping position */
12292 new_element = drop_element; /* default: no change when dropping */
12294 /* check if player is active, not moving and ready to drop */
12295 if (!player->active || player->MovPos || player->drop_delay > 0)
12298 /* check if player has anything that can be dropped */
12299 if (new_element == EL_UNDEFINED)
12302 /* check if drop key was pressed long enough for EM style dynamite */
12303 if (new_element == EL_EM_DYNAMITE && player->drop_pressed_delay < 40)
12306 /* check if anything can be dropped at the current position */
12307 if (IS_ACTIVE_BOMB(old_element) || old_element == EL_EXPLOSION)
12310 /* collected custom elements can only be dropped on empty fields */
12311 if (IS_CUSTOM_ELEMENT(new_element) && old_element != EL_EMPTY)
12314 if (old_element != EL_EMPTY)
12315 Back[dropx][dropy] = old_element; /* store old element on this field */
12317 ResetGfxAnimation(dropx, dropy);
12318 ResetRandomAnimationValue(dropx, dropy);
12320 if (player->inventory_size > 0 ||
12321 player->inventory_infinite_element != EL_UNDEFINED)
12323 if (player->inventory_size > 0)
12325 player->inventory_size--;
12328 DrawGameDoorValues();
12330 DrawGameValue_Dynamite(local_player->inventory_size);
12333 if (new_element == EL_DYNAMITE)
12334 new_element = EL_DYNAMITE_ACTIVE;
12335 else if (new_element == EL_EM_DYNAMITE)
12336 new_element = EL_EM_DYNAMITE_ACTIVE;
12337 else if (new_element == EL_SP_DISK_RED)
12338 new_element = EL_SP_DISK_RED_ACTIVE;
12341 Feld[dropx][dropy] = new_element;
12343 if (IN_SCR_FIELD(SCREENX(dropx), SCREENY(dropy)))
12344 DrawGraphicThruMask(SCREENX(dropx), SCREENY(dropy),
12345 el2img(Feld[dropx][dropy]), 0);
12347 PlayLevelSoundAction(dropx, dropy, ACTION_DROPPING);
12349 /* needed if previous element just changed to "empty" in the last frame */
12350 ChangeCount[dropx][dropy] = 0; /* allow at least one more change */
12352 CheckElementChangeByPlayer(dropx, dropy, new_element, CE_DROPPED_BY_PLAYER,
12353 player->index_bit, drop_side);
12354 CheckTriggeredElementChangeByPlayer(dropx, dropy, new_element,
12356 player->index_bit, drop_side);
12358 TestIfElementTouchesCustomElement(dropx, dropy);
12360 else /* player is dropping a dyna bomb */
12362 player->dynabombs_left--;
12364 Feld[dropx][dropy] = new_element;
12366 if (IN_SCR_FIELD(SCREENX(dropx), SCREENY(dropy)))
12367 DrawGraphicThruMask(SCREENX(dropx), SCREENY(dropy),
12368 el2img(Feld[dropx][dropy]), 0);
12370 PlayLevelSoundAction(dropx, dropy, ACTION_DROPPING);
12373 if (Feld[dropx][dropy] == new_element) /* uninitialized unless CE change */
12374 InitField_WithBug1(dropx, dropy, FALSE);
12376 new_element = Feld[dropx][dropy]; /* element might have changed */
12378 if (IS_CUSTOM_ELEMENT(new_element) && CAN_MOVE(new_element) &&
12379 element_info[new_element].move_pattern == MV_WHEN_DROPPED)
12381 int move_direction, nextx, nexty;
12383 if (element_info[new_element].move_direction_initial == MV_START_AUTOMATIC)
12384 MovDir[dropx][dropy] = drop_direction;
12386 move_direction = MovDir[dropx][dropy];
12387 nextx = dropx + GET_DX_FROM_DIR(move_direction);
12388 nexty = dropy + GET_DY_FROM_DIR(move_direction);
12390 ChangeCount[dropx][dropy] = 0; /* allow at least one more change */
12391 CheckCollision[dropx][dropy] = CHECK_DELAY_COLLISION;
12394 player->drop_delay = GET_NEW_DROP_DELAY(drop_element);
12395 player->is_dropping = TRUE;
12397 player->drop_pressed_delay = 0;
12398 player->is_dropping_pressed = FALSE;
12400 player->drop_x = dropx;
12401 player->drop_y = dropy;
12406 /* ------------------------------------------------------------------------- */
12407 /* game sound playing functions */
12408 /* ------------------------------------------------------------------------- */
12410 static int *loop_sound_frame = NULL;
12411 static int *loop_sound_volume = NULL;
12413 void InitPlayLevelSound()
12415 int num_sounds = getSoundListSize();
12417 checked_free(loop_sound_frame);
12418 checked_free(loop_sound_volume);
12420 loop_sound_frame = checked_calloc(num_sounds * sizeof(int));
12421 loop_sound_volume = checked_calloc(num_sounds * sizeof(int));
12424 static void PlayLevelSound(int x, int y, int nr)
12426 int sx = SCREENX(x), sy = SCREENY(y);
12427 int volume, stereo_position;
12428 int max_distance = 8;
12429 int type = (IS_LOOP_SOUND(nr) ? SND_CTRL_PLAY_LOOP : SND_CTRL_PLAY_SOUND);
12431 if ((!setup.sound_simple && !IS_LOOP_SOUND(nr)) ||
12432 (!setup.sound_loops && IS_LOOP_SOUND(nr)))
12435 if (!IN_LEV_FIELD(x, y) ||
12436 sx < -max_distance || sx >= SCR_FIELDX + max_distance ||
12437 sy < -max_distance || sy >= SCR_FIELDY + max_distance)
12440 volume = SOUND_MAX_VOLUME;
12442 if (!IN_SCR_FIELD(sx, sy))
12444 int dx = ABS(sx - SCR_FIELDX / 2) - SCR_FIELDX / 2;
12445 int dy = ABS(sy - SCR_FIELDY / 2) - SCR_FIELDY / 2;
12447 volume -= volume * (dx > dy ? dx : dy) / max_distance;
12450 stereo_position = (SOUND_MAX_LEFT +
12451 (sx + max_distance) * SOUND_MAX_LEFT2RIGHT /
12452 (SCR_FIELDX + 2 * max_distance));
12454 if (IS_LOOP_SOUND(nr))
12456 /* This assures that quieter loop sounds do not overwrite louder ones,
12457 while restarting sound volume comparison with each new game frame. */
12459 if (loop_sound_volume[nr] > volume && loop_sound_frame[nr] == FrameCounter)
12462 loop_sound_volume[nr] = volume;
12463 loop_sound_frame[nr] = FrameCounter;
12466 PlaySoundExt(nr, volume, stereo_position, type);
12469 static void PlayLevelSoundNearest(int x, int y, int sound_action)
12471 PlayLevelSound(x < LEVELX(BX1) ? LEVELX(BX1) :
12472 x > LEVELX(BX2) ? LEVELX(BX2) : x,
12473 y < LEVELY(BY1) ? LEVELY(BY1) :
12474 y > LEVELY(BY2) ? LEVELY(BY2) : y,
12478 static void PlayLevelSoundAction(int x, int y, int action)
12480 PlayLevelSoundElementAction(x, y, Feld[x][y], action);
12483 static void PlayLevelSoundElementAction(int x, int y, int element, int action)
12485 int sound_effect = element_info[SND_ELEMENT(element)].sound[action];
12487 if (sound_effect != SND_UNDEFINED)
12488 PlayLevelSound(x, y, sound_effect);
12491 static void PlayLevelSoundElementActionIfLoop(int x, int y, int element,
12494 int sound_effect = element_info[SND_ELEMENT(element)].sound[action];
12496 if (sound_effect != SND_UNDEFINED && IS_LOOP_SOUND(sound_effect))
12497 PlayLevelSound(x, y, sound_effect);
12500 static void PlayLevelSoundActionIfLoop(int x, int y, int action)
12502 int sound_effect = element_info[SND_ELEMENT(Feld[x][y])].sound[action];
12504 if (sound_effect != SND_UNDEFINED && IS_LOOP_SOUND(sound_effect))
12505 PlayLevelSound(x, y, sound_effect);
12508 static void StopLevelSoundActionIfLoop(int x, int y, int action)
12510 int sound_effect = element_info[SND_ELEMENT(Feld[x][y])].sound[action];
12512 if (sound_effect != SND_UNDEFINED && IS_LOOP_SOUND(sound_effect))
12513 StopSound(sound_effect);
12516 static void PlayLevelMusic()
12518 if (levelset.music[level_nr] != MUS_UNDEFINED)
12519 PlayMusic(levelset.music[level_nr]); /* from config file */
12521 PlayMusic(MAP_NOCONF_MUSIC(level_nr)); /* from music dir */
12524 void PlayLevelSound_EM(int x, int y, int element_em, int sample)
12526 int element = (element_em > -1 ? map_element_EM_to_RND(element_em) : 0);
12531 PlayLevelSoundElementAction(x, y, element, ACTION_WALKING);
12535 PlayLevelSoundElementAction(x, y, element, ACTION_PUSHING);
12539 PlayLevelSoundElementAction(x, y, element, ACTION_IMPACT);
12543 PlayLevelSoundElementAction(x, y, element, ACTION_IMPACT);
12547 PlayLevelSoundElementAction(x, y, element, ACTION_BREAKING);
12551 PlayLevelSoundElementAction(x, y, element, ACTION_MOVING);
12555 PlayLevelSoundElementAction(x, y, element, ACTION_MOVING);
12558 case SAMPLE_android_clone:
12559 PlayLevelSoundElementAction(x, y, element, ACTION_DROPPING);
12562 case SAMPLE_android_move:
12563 PlayLevelSoundElementAction(x, y, element, ACTION_MOVING);
12566 case SAMPLE_spring:
12567 PlayLevelSoundElementAction(x, y, element, ACTION_IMPACT);
12571 PlayLevelSoundElementAction(x, y, element, ACTION_EATING);
12575 PlayLevelSoundElementAction(x, y, element, ACTION_WAITING);
12578 case SAMPLE_eater_eat:
12579 PlayLevelSoundElementAction(x, y, element, ACTION_DIGGING);
12583 PlayLevelSoundElementAction(x, y, element, ACTION_MOVING);
12586 case SAMPLE_collect:
12587 PlayLevelSoundElementAction(x, y, element, ACTION_COLLECTING);
12590 case SAMPLE_diamond:
12591 PlayLevelSoundElementAction(x, y, element, ACTION_IMPACT);
12594 case SAMPLE_squash:
12595 /* !!! CHECK THIS !!! */
12597 PlayLevelSoundElementAction(x, y, element, ACTION_BREAKING);
12599 PlayLevelSoundElementAction(x, y, element, ACTION_SMASHED_BY_ROCK);
12603 case SAMPLE_wonderfall:
12604 PlayLevelSoundElementAction(x, y, element, ACTION_FILLING);
12608 PlayLevelSoundElementAction(x, y, element, ACTION_IMPACT);
12612 PlayLevelSoundElementAction(x, y, element, ACTION_PUSHING);
12616 PlayLevelSoundElementAction(x, y, element, ACTION_DIGGING);
12620 PlayLevelSoundElementAction(x, y, element, ACTION_SPLASHING);
12624 PlayLevelSoundElementAction(x, y, element, ACTION_DROPPING);
12628 PlayLevelSoundElementAction(x, y, element, ACTION_GROWING);
12631 case SAMPLE_wonder:
12632 PlayLevelSoundElementAction(x, y, element, ACTION_ACTIVE);
12636 PlayLevelSoundElementAction(x, y, element, ACTION_PASSING);
12639 case SAMPLE_exit_open:
12640 PlayLevelSoundElementAction(x, y, element, ACTION_OPENING);
12643 case SAMPLE_exit_leave:
12644 PlayLevelSoundElementAction(x, y, element, ACTION_PASSING);
12647 case SAMPLE_dynamite:
12648 PlayLevelSoundElementAction(x, y, element, ACTION_DROPPING);
12652 PlayLevelSoundElementAction(x, y, element, ACTION_ACTIVE);
12656 PlayLevelSoundElementAction(x, y, element, ACTION_ACTIVATING);
12660 PlayLevelSoundElementAction(x, y, element, ACTION_ACTIVE);
12664 PlayLevelSoundElementAction(x, y, element, ACTION_EXPLODING);
12668 PlayLevelSoundElementAction(x, y, element, ACTION_DYING);
12672 PlaySoundStereo(SND_GAME_RUNNING_OUT_OF_TIME, SOUND_MIDDLE);
12676 PlayLevelSoundElementAction(x, y, element, ACTION_DEFAULT);
12681 void RaiseScore(int value)
12683 local_player->score += value;
12685 DrawGameValue_Score(local_player->score);
12688 void RaiseScoreElement(int element)
12693 case EL_BD_DIAMOND:
12694 case EL_EMERALD_YELLOW:
12695 case EL_EMERALD_RED:
12696 case EL_EMERALD_PURPLE:
12697 case EL_SP_INFOTRON:
12698 RaiseScore(level.score[SC_EMERALD]);
12701 RaiseScore(level.score[SC_DIAMOND]);
12704 RaiseScore(level.score[SC_CRYSTAL]);
12707 RaiseScore(level.score[SC_PEARL]);
12710 case EL_BD_BUTTERFLY:
12711 case EL_SP_ELECTRON:
12712 RaiseScore(level.score[SC_BUG]);
12715 case EL_BD_FIREFLY:
12716 case EL_SP_SNIKSNAK:
12717 RaiseScore(level.score[SC_SPACESHIP]);
12720 case EL_DARK_YAMYAM:
12721 RaiseScore(level.score[SC_YAMYAM]);
12724 RaiseScore(level.score[SC_ROBOT]);
12727 RaiseScore(level.score[SC_PACMAN]);
12730 RaiseScore(level.score[SC_NUT]);
12733 case EL_EM_DYNAMITE:
12734 case EL_SP_DISK_RED:
12735 case EL_DYNABOMB_INCREASE_NUMBER:
12736 case EL_DYNABOMB_INCREASE_SIZE:
12737 case EL_DYNABOMB_INCREASE_POWER:
12738 RaiseScore(level.score[SC_DYNAMITE]);
12740 case EL_SHIELD_NORMAL:
12741 case EL_SHIELD_DEADLY:
12742 RaiseScore(level.score[SC_SHIELD]);
12744 case EL_EXTRA_TIME:
12745 RaiseScore(level.extra_time_score);
12759 RaiseScore(level.score[SC_KEY]);
12762 RaiseScore(element_info[element].collect_score);
12767 void RequestQuitGame(boolean ask_if_really_quit)
12769 if (AllPlayersGone ||
12770 !ask_if_really_quit ||
12771 level_editor_test_game ||
12772 Request("Do you really want to quit the game ?",
12773 REQ_ASK | REQ_STAY_CLOSED))
12775 #if defined(NETWORK_AVALIABLE)
12776 if (options.network)
12777 SendToServer_StopPlaying(NETWORK_STOP_BY_PLAYER);
12781 game_status = GAME_MODE_MAIN;
12787 if (tape.playing && tape.deactivate_display)
12788 TapeDeactivateDisplayOff(TRUE);
12790 OpenDoor(DOOR_OPEN_1 | DOOR_COPY_BACK);
12792 if (tape.playing && tape.deactivate_display)
12793 TapeDeactivateDisplayOn();
12798 /* ---------- new game button stuff ---------------------------------------- */
12800 /* graphic position values for game buttons */
12801 #define GAME_BUTTON_XSIZE 30
12802 #define GAME_BUTTON_YSIZE 30
12803 #define GAME_BUTTON_XPOS 5
12804 #define GAME_BUTTON_YPOS 215
12805 #define SOUND_BUTTON_XPOS 5
12806 #define SOUND_BUTTON_YPOS (GAME_BUTTON_YPOS + GAME_BUTTON_YSIZE)
12808 #define GAME_BUTTON_STOP_XPOS (GAME_BUTTON_XPOS + 0 * GAME_BUTTON_XSIZE)
12809 #define GAME_BUTTON_PAUSE_XPOS (GAME_BUTTON_XPOS + 1 * GAME_BUTTON_XSIZE)
12810 #define GAME_BUTTON_PLAY_XPOS (GAME_BUTTON_XPOS + 2 * GAME_BUTTON_XSIZE)
12811 #define SOUND_BUTTON_MUSIC_XPOS (SOUND_BUTTON_XPOS + 0 * GAME_BUTTON_XSIZE)
12812 #define SOUND_BUTTON_LOOPS_XPOS (SOUND_BUTTON_XPOS + 1 * GAME_BUTTON_XSIZE)
12813 #define SOUND_BUTTON_SIMPLE_XPOS (SOUND_BUTTON_XPOS + 2 * GAME_BUTTON_XSIZE)
12820 } gamebutton_info[NUM_GAME_BUTTONS] =
12823 GAME_BUTTON_STOP_XPOS, GAME_BUTTON_YPOS,
12828 GAME_BUTTON_PAUSE_XPOS, GAME_BUTTON_YPOS,
12829 GAME_CTRL_ID_PAUSE,
12833 GAME_BUTTON_PLAY_XPOS, GAME_BUTTON_YPOS,
12838 SOUND_BUTTON_MUSIC_XPOS, SOUND_BUTTON_YPOS,
12839 SOUND_CTRL_ID_MUSIC,
12840 "background music on/off"
12843 SOUND_BUTTON_LOOPS_XPOS, SOUND_BUTTON_YPOS,
12844 SOUND_CTRL_ID_LOOPS,
12845 "sound loops on/off"
12848 SOUND_BUTTON_SIMPLE_XPOS, SOUND_BUTTON_YPOS,
12849 SOUND_CTRL_ID_SIMPLE,
12850 "normal sounds on/off"
12854 void CreateGameButtons()
12858 for (i = 0; i < NUM_GAME_BUTTONS; i++)
12860 Bitmap *gd_bitmap = graphic_info[IMG_GLOBAL_DOOR].bitmap;
12861 struct GadgetInfo *gi;
12864 unsigned long event_mask;
12865 int gd_xoffset, gd_yoffset;
12866 int gd_x1, gd_x2, gd_y1, gd_y2;
12869 gd_xoffset = gamebutton_info[i].x;
12870 gd_yoffset = gamebutton_info[i].y;
12871 gd_x1 = DOOR_GFX_PAGEX4 + gd_xoffset;
12872 gd_x2 = DOOR_GFX_PAGEX3 + gd_xoffset;
12874 if (id == GAME_CTRL_ID_STOP ||
12875 id == GAME_CTRL_ID_PAUSE ||
12876 id == GAME_CTRL_ID_PLAY)
12878 button_type = GD_TYPE_NORMAL_BUTTON;
12880 event_mask = GD_EVENT_RELEASED;
12881 gd_y1 = DOOR_GFX_PAGEY1 + gd_yoffset - GAME_BUTTON_YSIZE;
12882 gd_y2 = DOOR_GFX_PAGEY1 + gd_yoffset - GAME_BUTTON_YSIZE;
12886 button_type = GD_TYPE_CHECK_BUTTON;
12888 ((id == SOUND_CTRL_ID_MUSIC && setup.sound_music) ||
12889 (id == SOUND_CTRL_ID_LOOPS && setup.sound_loops) ||
12890 (id == SOUND_CTRL_ID_SIMPLE && setup.sound_simple) ? TRUE : FALSE);
12891 event_mask = GD_EVENT_PRESSED;
12892 gd_y1 = DOOR_GFX_PAGEY1 + gd_yoffset;
12893 gd_y2 = DOOR_GFX_PAGEY1 + gd_yoffset - GAME_BUTTON_YSIZE;
12896 gi = CreateGadget(GDI_CUSTOM_ID, id,
12897 GDI_INFO_TEXT, gamebutton_info[i].infotext,
12898 GDI_X, DX + gd_xoffset,
12899 GDI_Y, DY + gd_yoffset,
12900 GDI_WIDTH, GAME_BUTTON_XSIZE,
12901 GDI_HEIGHT, GAME_BUTTON_YSIZE,
12902 GDI_TYPE, button_type,
12903 GDI_STATE, GD_BUTTON_UNPRESSED,
12904 GDI_CHECKED, checked,
12905 GDI_DESIGN_UNPRESSED, gd_bitmap, gd_x1, gd_y1,
12906 GDI_DESIGN_PRESSED, gd_bitmap, gd_x2, gd_y1,
12907 GDI_ALT_DESIGN_UNPRESSED, gd_bitmap, gd_x1, gd_y2,
12908 GDI_ALT_DESIGN_PRESSED, gd_bitmap, gd_x2, gd_y2,
12909 GDI_EVENT_MASK, event_mask,
12910 GDI_CALLBACK_ACTION, HandleGameButtons,
12914 Error(ERR_EXIT, "cannot create gadget");
12916 game_gadget[id] = gi;
12920 void FreeGameButtons()
12924 for (i = 0; i < NUM_GAME_BUTTONS; i++)
12925 FreeGadget(game_gadget[i]);
12928 static void MapGameButtons()
12932 for (i = 0; i < NUM_GAME_BUTTONS; i++)
12933 MapGadget(game_gadget[i]);
12936 void UnmapGameButtons()
12940 for (i = 0; i < NUM_GAME_BUTTONS; i++)
12941 UnmapGadget(game_gadget[i]);
12944 static void HandleGameButtons(struct GadgetInfo *gi)
12946 int id = gi->custom_id;
12948 if (game_status != GAME_MODE_PLAYING)
12953 case GAME_CTRL_ID_STOP:
12957 RequestQuitGame(TRUE);
12960 case GAME_CTRL_ID_PAUSE:
12961 if (options.network)
12963 #if defined(NETWORK_AVALIABLE)
12965 SendToServer_ContinuePlaying();
12967 SendToServer_PausePlaying();
12971 TapeTogglePause(TAPE_TOGGLE_MANUAL);
12974 case GAME_CTRL_ID_PLAY:
12977 #if defined(NETWORK_AVALIABLE)
12978 if (options.network)
12979 SendToServer_ContinuePlaying();
12983 tape.pausing = FALSE;
12984 DrawVideoDisplay(VIDEO_STATE_PAUSE_OFF, 0);
12989 case SOUND_CTRL_ID_MUSIC:
12990 if (setup.sound_music)
12992 setup.sound_music = FALSE;
12995 else if (audio.music_available)
12997 setup.sound = setup.sound_music = TRUE;
12999 SetAudioMode(setup.sound);
13005 case SOUND_CTRL_ID_LOOPS:
13006 if (setup.sound_loops)
13007 setup.sound_loops = FALSE;
13008 else if (audio.loops_available)
13010 setup.sound = setup.sound_loops = TRUE;
13011 SetAudioMode(setup.sound);
13015 case SOUND_CTRL_ID_SIMPLE:
13016 if (setup.sound_simple)
13017 setup.sound_simple = FALSE;
13018 else if (audio.sound_available)
13020 setup.sound = setup.sound_simple = TRUE;
13021 SetAudioMode(setup.sound);