1 /***********************************************************
2 * Rocks'n'Diamonds -- McDuffin Strikes Back! *
3 *----------------------------------------------------------*
4 * (c) 1995-2006 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)
44 #define USE_GFX_RESET_GFX_ANIMATION (USE_NEW_STUFF * 1)
45 #define USE_BOTH_SWITCHGATE_SWITCHES (USE_NEW_STUFF * 1)
46 #define USE_PLAYER_GRAVITY (USE_NEW_STUFF * 1)
47 #define USE_FIXED_BORDER_RUNNING_GFX (USE_NEW_STUFF * 1)
48 #define USE_QUICKSAND_BD_ROCK_BUGFIX (USE_NEW_STUFF * 0)
50 #define USE_QUICKSAND_IMPACT_BUGFIX (USE_NEW_STUFF * 0)
52 #define USE_CODE_THAT_BREAKS_SNAKE_BITE (USE_NEW_STUFF * 1)
54 #define USE_UFAST_PLAYER_EXIT_BUGFIX (USE_NEW_STUFF * 1)
56 #define USE_GFX_RESET_ONLY_WHEN_MOVING (USE_NEW_STUFF * 1)
57 #define USE_GFX_RESET_PLAYER_ARTWORK (USE_NEW_STUFF * 1)
59 #define USE_FIX_KILLED_BY_NON_WALKABLE (USE_NEW_STUFF * 1)
60 #define USE_FIX_IMPACT_COLLISION (USE_NEW_STUFF * 1)
68 /* for MovePlayer() */
69 #define MP_NO_ACTION 0
72 #define MP_DONT_RUN_INTO (MP_MOVING | MP_ACTION)
74 /* for ScrollPlayer() */
76 #define SCROLL_GO_ON 1
78 /* for Bang()/Explode() */
79 #define EX_PHASE_START 0
80 #define EX_TYPE_NONE 0
81 #define EX_TYPE_NORMAL (1 << 0)
82 #define EX_TYPE_CENTER (1 << 1)
83 #define EX_TYPE_BORDER (1 << 2)
84 #define EX_TYPE_CROSS (1 << 3)
85 #define EX_TYPE_DYNA (1 << 4)
86 #define EX_TYPE_SINGLE_TILE (EX_TYPE_CENTER | EX_TYPE_BORDER)
89 #define PANEL_DEACTIVATED(p) ((p)->x < 0 || (p)->y < 0)
90 #define PANEL_XPOS(p) (DX + ALIGNED_MENU_XPOS(p))
91 #define PANEL_YPOS(p) (DY + ALIGNED_MENU_YPOS(p))
93 #define PANEL_DEACTIVATED(p) ((p).x < 0 || (p).y < 0)
94 #define PANEL_XPOS(p) (ALIGNED_XPOS((p).x, (p).width, (p).align))
95 #define PANEL_YPOS(p) ((p).y)
98 /* special positions in the game control window (relative to control window) */
99 #define XX_LEVEL1 (PANEL_XPOS(game.panel.level))
100 #define XX_LEVEL2 (PANEL_XPOS(game.panel.level) - 1)
101 #define XX_LEVEL (PANEL_XPOS(game.panel.level))
102 #define YY_LEVEL (PANEL_YPOS(game.panel.level))
103 #define XX_EMERALDS (PANEL_XPOS(game.panel.gems))
104 #define YY_EMERALDS (PANEL_YPOS(game.panel.gems))
105 #define XX_DYNAMITE (PANEL_XPOS(game.panel.inventory))
106 #define YY_DYNAMITE (PANEL_YPOS(game.panel.inventory))
107 #define XX_KEYS (PANEL_XPOS(game.panel.keys))
108 #define YY_KEYS (PANEL_YPOS(game.panel.keys))
109 #define XX_SCORE (PANEL_XPOS(game.panel.score))
110 #define YY_SCORE (PANEL_YPOS(game.panel.score))
111 #define XX_TIME1 (PANEL_XPOS(game.panel.time))
112 #define XX_TIME2 (PANEL_XPOS(game.panel.time) + 1)
113 #define XX_TIME (PANEL_XPOS(game.panel.time))
114 #define YY_TIME (PANEL_YPOS(game.panel.time))
116 /* special positions in the game control window (relative to main window) */
117 #define DX_LEVEL1 (DX + XX_LEVEL1)
118 #define DX_LEVEL2 (DX + XX_LEVEL2)
119 #define DX_LEVEL (DX + XX_LEVEL)
120 #define DY_LEVEL (DY + YY_LEVEL)
121 #define DX_EMERALDS (DX + XX_EMERALDS)
122 #define DY_EMERALDS (DY + YY_EMERALDS)
123 #define DX_DYNAMITE (DX + XX_DYNAMITE)
124 #define DY_DYNAMITE (DY + YY_DYNAMITE)
125 #define DX_KEYS (DX + XX_KEYS)
126 #define DY_KEYS (DY + YY_KEYS)
127 #define DX_SCORE (DX + XX_SCORE)
128 #define DY_SCORE (DY + YY_SCORE)
129 #define DX_TIME1 (DX + XX_TIME1)
130 #define DX_TIME2 (DX + XX_TIME2)
131 #define DX_TIME (DX + XX_TIME)
132 #define DY_TIME (DY + YY_TIME)
134 /* values for delayed check of falling and moving elements and for collision */
135 #define CHECK_DELAY_MOVING 3
136 #define CHECK_DELAY_FALLING CHECK_DELAY_MOVING
137 #define CHECK_DELAY_COLLISION 2
138 #define CHECK_DELAY_IMPACT CHECK_DELAY_COLLISION
140 /* values for initial player move delay (initial delay counter value) */
141 #define INITIAL_MOVE_DELAY_OFF -1
142 #define INITIAL_MOVE_DELAY_ON 0
144 /* values for player movement speed (which is in fact a delay value) */
145 #define MOVE_DELAY_MIN_SPEED 32
146 #define MOVE_DELAY_NORMAL_SPEED 8
147 #define MOVE_DELAY_HIGH_SPEED 4
148 #define MOVE_DELAY_MAX_SPEED 1
150 #define DOUBLE_MOVE_DELAY(x) (x = (x < MOVE_DELAY_MIN_SPEED ? x * 2 : x))
151 #define HALVE_MOVE_DELAY(x) (x = (x > MOVE_DELAY_MAX_SPEED ? x / 2 : x))
153 #define DOUBLE_PLAYER_SPEED(p) (HALVE_MOVE_DELAY( (p)->move_delay_value))
154 #define HALVE_PLAYER_SPEED(p) (DOUBLE_MOVE_DELAY((p)->move_delay_value))
156 /* values for other actions */
157 #define MOVE_STEPSIZE_NORMAL (TILEX / MOVE_DELAY_NORMAL_SPEED)
158 #define MOVE_STEPSIZE_MIN (1)
159 #define MOVE_STEPSIZE_MAX (TILEX)
161 #define GET_DX_FROM_DIR(d) ((d) == MV_LEFT ? -1 : (d) == MV_RIGHT ? 1 : 0)
162 #define GET_DY_FROM_DIR(d) ((d) == MV_UP ? -1 : (d) == MV_DOWN ? 1 : 0)
164 #define INIT_GFX_RANDOM() (GetSimpleRandom(1000000))
166 #define GET_NEW_PUSH_DELAY(e) ( (element_info[e].push_delay_fixed) + \
167 RND(element_info[e].push_delay_random))
168 #define GET_NEW_DROP_DELAY(e) ( (element_info[e].drop_delay_fixed) + \
169 RND(element_info[e].drop_delay_random))
170 #define GET_NEW_MOVE_DELAY(e) ( (element_info[e].move_delay_fixed) + \
171 RND(element_info[e].move_delay_random))
172 #define GET_MAX_MOVE_DELAY(e) ( (element_info[e].move_delay_fixed) + \
173 (element_info[e].move_delay_random))
174 #define GET_NEW_CE_VALUE(e) ( (element_info[e].ce_value_fixed_initial) +\
175 RND(element_info[e].ce_value_random_initial))
176 #define GET_CE_SCORE(e) ( (element_info[e].collect_score))
177 #define GET_CHANGE_DELAY(c) ( ((c)->delay_fixed * (c)->delay_frames) + \
178 RND((c)->delay_random * (c)->delay_frames))
179 #define GET_CE_DELAY_VALUE(c) ( ((c)->delay_fixed) + \
180 RND((c)->delay_random))
183 #define GET_VALID_RUNTIME_ELEMENT(e) \
184 ((e) >= NUM_RUNTIME_ELEMENTS ? EL_UNKNOWN : (e))
186 #define RESOLVED_REFERENCE_ELEMENT(be, e) \
187 ((be) + (e) - EL_SELF < EL_CUSTOM_START ? EL_CUSTOM_START : \
188 (be) + (e) - EL_SELF > EL_CUSTOM_END ? EL_CUSTOM_END : \
189 (be) + (e) - EL_SELF)
191 #define GET_TARGET_ELEMENT(be, e, ch, cv, cs) \
192 ((e) == EL_TRIGGER_PLAYER ? (ch)->actual_trigger_player : \
193 (e) == EL_TRIGGER_ELEMENT ? (ch)->actual_trigger_element : \
194 (e) == EL_TRIGGER_CE_VALUE ? (ch)->actual_trigger_ce_value : \
195 (e) == EL_TRIGGER_CE_SCORE ? (ch)->actual_trigger_ce_score : \
196 (e) == EL_CURRENT_CE_VALUE ? (cv) : \
197 (e) == EL_CURRENT_CE_SCORE ? (cs) : \
198 (e) >= EL_PREV_CE_8 && (e) <= EL_NEXT_CE_8 ? \
199 RESOLVED_REFERENCE_ELEMENT(be, e) : \
202 #define CAN_GROW_INTO(e) \
203 ((e) == EL_SAND || (IS_DIGGABLE(e) && level.grow_into_diggable))
205 #define ELEMENT_CAN_ENTER_FIELD_BASE_X(x, y, condition) \
206 (IN_LEV_FIELD(x, y) && (IS_FREE(x, y) || \
209 #define ELEMENT_CAN_ENTER_FIELD_BASE_2(e, x, y, condition) \
210 (IN_LEV_FIELD(x, y) && (IS_FREE(x, y) || \
211 (CAN_MOVE_INTO_ACID(e) && \
212 Feld[x][y] == EL_ACID) || \
215 #define ELEMENT_CAN_ENTER_FIELD_BASE_3(e, x, y, condition) \
216 (IN_LEV_FIELD(x, y) && (IS_FREE_OR_PLAYER(x, y) || \
217 (CAN_MOVE_INTO_ACID(e) && \
218 Feld[x][y] == EL_ACID) || \
221 #define ELEMENT_CAN_ENTER_FIELD_BASE_4(e, x, y, condition) \
222 (IN_LEV_FIELD(x, y) && (IS_FREE(x, y) || \
224 (CAN_MOVE_INTO_ACID(e) && \
225 Feld[x][y] == EL_ACID) || \
226 (DONT_COLLIDE_WITH(e) && \
228 !PLAYER_ENEMY_PROTECTED(x, y))))
230 #define ELEMENT_CAN_ENTER_FIELD(e, x, y) \
231 ELEMENT_CAN_ENTER_FIELD_BASE_4(e, x, y, 0)
233 #define SATELLITE_CAN_ENTER_FIELD(x, y) \
234 ELEMENT_CAN_ENTER_FIELD_BASE_2(EL_SATELLITE, x, y, 0)
236 #define ANDROID_CAN_ENTER_FIELD(e, x, y) \
237 ELEMENT_CAN_ENTER_FIELD_BASE_2(e, x, y, Feld[x][y] == EL_EMC_PLANT)
239 #define ANDROID_CAN_CLONE_FIELD(x, y) \
240 (IN_LEV_FIELD(x, y) && (CAN_BE_CLONED_BY_ANDROID(Feld[x][y]) || \
241 CAN_BE_CLONED_BY_ANDROID(EL_TRIGGER_ELEMENT)))
243 #define ENEMY_CAN_ENTER_FIELD(e, x, y) \
244 ELEMENT_CAN_ENTER_FIELD_BASE_2(e, x, y, 0)
246 #define YAMYAM_CAN_ENTER_FIELD(e, x, y) \
247 ELEMENT_CAN_ENTER_FIELD_BASE_3(e, x, y, Feld[x][y] == EL_DIAMOND)
249 #define DARK_YAMYAM_CAN_ENTER_FIELD(e, x, y) \
250 ELEMENT_CAN_ENTER_FIELD_BASE_3(e, x,y, IS_FOOD_DARK_YAMYAM(Feld[x][y]))
252 #define PACMAN_CAN_ENTER_FIELD(e, x, y) \
253 ELEMENT_CAN_ENTER_FIELD_BASE_3(e, x, y, IS_AMOEBOID(Feld[x][y]))
255 #define PIG_CAN_ENTER_FIELD(e, x, y) \
256 ELEMENT_CAN_ENTER_FIELD_BASE_2(e, x, y, IS_FOOD_PIG(Feld[x][y]))
258 #define PENGUIN_CAN_ENTER_FIELD(e, x, y) \
259 ELEMENT_CAN_ENTER_FIELD_BASE_2(e, x, y, (Feld[x][y] == EL_EXIT_OPEN || \
260 Feld[x][y] == EL_EM_EXIT_OPEN || \
261 Feld[x][y] == EL_STEEL_EXIT_OPEN || \
262 Feld[x][y] == EL_EM_STEEL_EXIT_OPEN || \
263 IS_FOOD_PENGUIN(Feld[x][y])))
264 #define DRAGON_CAN_ENTER_FIELD(e, x, y) \
265 ELEMENT_CAN_ENTER_FIELD_BASE_2(e, x, y, 0)
267 #define MOLE_CAN_ENTER_FIELD(e, x, y, condition) \
268 ELEMENT_CAN_ENTER_FIELD_BASE_2(e, x, y, (condition))
270 #define SPRING_CAN_ENTER_FIELD(e, x, y) \
271 ELEMENT_CAN_ENTER_FIELD_BASE_2(e, x, y, 0)
273 #define SPRING_CAN_BUMP_FROM_FIELD(x, y) \
274 (IN_LEV_FIELD(x, y) && (Feld[x][y] == EL_EMC_SPRING_BUMPER || \
275 Feld[x][y] == EL_EMC_SPRING_BUMPER_ACTIVE))
277 #define MOVE_ENTER_EL(e) (element_info[e].move_enter_element)
279 #define CE_ENTER_FIELD_COND(e, x, y) \
280 (!IS_PLAYER(x, y) && \
281 IS_EQUAL_OR_IN_GROUP(Feld[x][y], MOVE_ENTER_EL(e)))
283 #define CUSTOM_ELEMENT_CAN_ENTER_FIELD(e, x, y) \
284 ELEMENT_CAN_ENTER_FIELD_BASE_4(e, x, y, CE_ENTER_FIELD_COND(e, x, y))
286 #define IN_LEV_FIELD_AND_IS_FREE(x, y) (IN_LEV_FIELD(x, y) && IS_FREE(x, y))
287 #define IN_LEV_FIELD_AND_NOT_FREE(x, y) (IN_LEV_FIELD(x, y) && !IS_FREE(x, y))
289 #define ACCESS_FROM(e, d) (element_info[e].access_direction &(d))
290 #define IS_WALKABLE_FROM(e, d) (IS_WALKABLE(e) && ACCESS_FROM(e, d))
291 #define IS_PASSABLE_FROM(e, d) (IS_PASSABLE(e) && ACCESS_FROM(e, d))
292 #define IS_ACCESSIBLE_FROM(e, d) (IS_ACCESSIBLE(e) && ACCESS_FROM(e, d))
294 /* game button identifiers */
295 #define GAME_CTRL_ID_STOP 0
296 #define GAME_CTRL_ID_PAUSE 1
297 #define GAME_CTRL_ID_PLAY 2
298 #define SOUND_CTRL_ID_MUSIC 3
299 #define SOUND_CTRL_ID_LOOPS 4
300 #define SOUND_CTRL_ID_SIMPLE 5
302 #define NUM_GAME_BUTTONS 6
305 /* forward declaration for internal use */
307 static void CreateField(int, int, int);
309 static void SetPlayerWaiting(struct PlayerInfo *, boolean);
310 static void AdvanceFrameAndPlayerCounters(int);
312 static boolean MovePlayerOneStep(struct PlayerInfo *, int, int, int, int);
313 static boolean MovePlayer(struct PlayerInfo *, int, int);
314 static void ScrollPlayer(struct PlayerInfo *, int);
315 static void ScrollScreen(struct PlayerInfo *, int);
317 int DigField(struct PlayerInfo *, int, int, int, int, int, int, int);
319 static void InitBeltMovement(void);
320 static void CloseAllOpenTimegates(void);
321 static void CheckGravityMovement(struct PlayerInfo *);
322 static void CheckGravityMovementWhenNotMoving(struct PlayerInfo *);
323 static void KillPlayerUnlessEnemyProtected(int, int);
324 static void KillPlayerUnlessExplosionProtected(int, int);
326 static void TestIfPlayerTouchesCustomElement(int, int);
327 static void TestIfElementTouchesCustomElement(int, int);
328 static void TestIfElementHitsCustomElement(int, int, int);
330 static void TestIfElementSmashesCustomElement(int, int, int);
333 static void HandleElementChange(int, int, int);
334 static void ExecuteCustomElementAction(int, int, int, int);
335 static boolean ChangeElement(int, int, int, int);
337 static boolean CheckTriggeredElementChangeExt(int, int, int, int, int,int,int);
338 #define CheckTriggeredElementChange(x, y, e, ev) \
339 CheckTriggeredElementChangeExt(x,y,e,ev, CH_PLAYER_ANY,CH_SIDE_ANY, -1)
340 #define CheckTriggeredElementChangeByPlayer(x, y, e, ev, p, s) \
341 CheckTriggeredElementChangeExt(x, y, e, ev, p, s, -1)
342 #define CheckTriggeredElementChangeBySide(x, y, e, ev, s) \
343 CheckTriggeredElementChangeExt(x, y, e, ev, CH_PLAYER_ANY, s, -1)
344 #define CheckTriggeredElementChangeByPage(x, y, e, ev, p) \
345 CheckTriggeredElementChangeExt(x,y,e,ev, CH_PLAYER_ANY, CH_SIDE_ANY, p)
347 static boolean CheckElementChangeExt(int, int, int, int, int, int, int);
348 #define CheckElementChange(x, y, e, te, ev) \
349 CheckElementChangeExt(x, y, e, te, ev, CH_PLAYER_ANY, CH_SIDE_ANY)
350 #define CheckElementChangeByPlayer(x, y, e, ev, p, s) \
351 CheckElementChangeExt(x, y, e, EL_EMPTY, ev, p, s)
352 #define CheckElementChangeBySide(x, y, e, te, ev, s) \
353 CheckElementChangeExt(x, y, e, te, ev, CH_PLAYER_ANY, s)
355 static void PlayLevelSound(int, int, int);
356 static void PlayLevelSoundNearest(int, int, int);
357 static void PlayLevelSoundAction(int, int, int);
358 static void PlayLevelSoundElementAction(int, int, int, int);
359 static void PlayLevelSoundElementActionIfLoop(int, int, int, int);
360 static void PlayLevelSoundActionIfLoop(int, int, int);
361 static void StopLevelSoundActionIfLoop(int, int, int);
362 static void PlayLevelMusic();
364 static void MapGameButtons();
365 static void HandleGameButtons(struct GadgetInfo *);
367 int AmoebeNachbarNr(int, int);
368 void AmoebeUmwandeln(int, int);
369 void ContinueMoving(int, int);
371 void InitMovDir(int, int);
372 void InitAmoebaNr(int, int);
373 int NewHiScore(void);
375 void TestIfGoodThingHitsBadThing(int, int, int);
376 void TestIfBadThingHitsGoodThing(int, int, int);
377 void TestIfPlayerTouchesBadThing(int, int);
378 void TestIfPlayerRunsIntoBadThing(int, int, int);
379 void TestIfBadThingTouchesPlayer(int, int);
380 void TestIfBadThingRunsIntoPlayer(int, int, int);
381 void TestIfFriendTouchesBadThing(int, int);
382 void TestIfBadThingTouchesFriend(int, int);
383 void TestIfBadThingTouchesOtherBadThing(int, int);
385 void KillPlayer(struct PlayerInfo *);
386 void BuryPlayer(struct PlayerInfo *);
387 void RemovePlayer(struct PlayerInfo *);
389 boolean SnapField(struct PlayerInfo *, int, int);
390 boolean DropElement(struct PlayerInfo *);
392 static int getInvisibleActiveFromInvisibleElement(int);
393 static int getInvisibleFromInvisibleActiveElement(int);
395 static struct GadgetInfo *game_gadget[NUM_GAME_BUTTONS];
397 /* for detection of endless loops, caused by custom element programming */
398 /* (using maximal playfield width x 10 is just a rough approximation) */
399 #define MAX_ELEMENT_CHANGE_RECURSION_DEPTH (MAX_PLAYFIELD_WIDTH * 10)
401 #define RECURSION_LOOP_DETECTION_START(e, rc) \
403 if (recursion_loop_detected) \
406 if (recursion_loop_depth > MAX_ELEMENT_CHANGE_RECURSION_DEPTH) \
408 recursion_loop_detected = TRUE; \
409 recursion_loop_element = (e); \
412 recursion_loop_depth++; \
415 #define RECURSION_LOOP_DETECTION_END() \
417 recursion_loop_depth--; \
420 static int recursion_loop_depth;
421 static boolean recursion_loop_detected;
422 static boolean recursion_loop_element;
425 /* ------------------------------------------------------------------------- */
426 /* definition of elements that automatically change to other elements after */
427 /* a specified time, eventually calling a function when changing */
428 /* ------------------------------------------------------------------------- */
430 /* forward declaration for changer functions */
431 static void InitBuggyBase(int, int);
432 static void WarnBuggyBase(int, int);
434 static void InitTrap(int, int);
435 static void ActivateTrap(int, int);
436 static void ChangeActiveTrap(int, int);
438 static void InitRobotWheel(int, int);
439 static void RunRobotWheel(int, int);
440 static void StopRobotWheel(int, int);
442 static void InitTimegateWheel(int, int);
443 static void RunTimegateWheel(int, int);
445 static void InitMagicBallDelay(int, int);
446 static void ActivateMagicBall(int, int);
448 struct ChangingElementInfo
453 void (*pre_change_function)(int x, int y);
454 void (*change_function)(int x, int y);
455 void (*post_change_function)(int x, int y);
458 static struct ChangingElementInfo change_delay_list[] =
493 EL_STEEL_EXIT_OPENING,
501 EL_STEEL_EXIT_CLOSING,
502 EL_STEEL_EXIT_CLOSED,
529 EL_EM_STEEL_EXIT_OPENING,
530 EL_EM_STEEL_EXIT_OPEN,
537 EL_EM_STEEL_EXIT_CLOSING,
541 EL_EM_STEEL_EXIT_CLOSED,
565 EL_SWITCHGATE_OPENING,
573 EL_SWITCHGATE_CLOSING,
574 EL_SWITCHGATE_CLOSED,
606 EL_ACID_SPLASH_RIGHT,
615 EL_SP_BUGGY_BASE_ACTIVATING,
622 EL_SP_BUGGY_BASE_ACTIVATING,
623 EL_SP_BUGGY_BASE_ACTIVE,
630 EL_SP_BUGGY_BASE_ACTIVE,
654 EL_ROBOT_WHEEL_ACTIVE,
662 EL_TIMEGATE_SWITCH_ACTIVE,
670 EL_DC_TIMEGATE_SWITCH_ACTIVE,
671 EL_DC_TIMEGATE_SWITCH,
678 EL_EMC_MAGIC_BALL_ACTIVE,
679 EL_EMC_MAGIC_BALL_ACTIVE,
686 EL_EMC_SPRING_BUMPER_ACTIVE,
687 EL_EMC_SPRING_BUMPER,
694 EL_DIAGONAL_SHRINKING,
723 int push_delay_fixed, push_delay_random;
728 { EL_BALLOON, 0, 0 },
730 { EL_SOKOBAN_OBJECT, 2, 0 },
731 { EL_SOKOBAN_FIELD_FULL, 2, 0 },
732 { EL_SATELLITE, 2, 0 },
733 { EL_SP_DISK_YELLOW, 2, 0 },
735 { EL_UNDEFINED, 0, 0 },
743 move_stepsize_list[] =
745 { EL_AMOEBA_DROP, 2 },
746 { EL_AMOEBA_DROPPING, 2 },
747 { EL_QUICKSAND_FILLING, 1 },
748 { EL_QUICKSAND_EMPTYING, 1 },
749 { EL_QUICKSAND_FAST_FILLING, 2 },
750 { EL_QUICKSAND_FAST_EMPTYING, 2 },
751 { EL_MAGIC_WALL_FILLING, 2 },
752 { EL_MAGIC_WALL_EMPTYING, 2 },
753 { EL_BD_MAGIC_WALL_FILLING, 2 },
754 { EL_BD_MAGIC_WALL_EMPTYING, 2 },
755 { EL_DC_MAGIC_WALL_FILLING, 2 },
756 { EL_DC_MAGIC_WALL_EMPTYING, 2 },
766 collect_count_list[] =
769 { EL_BD_DIAMOND, 1 },
770 { EL_EMERALD_YELLOW, 1 },
771 { EL_EMERALD_RED, 1 },
772 { EL_EMERALD_PURPLE, 1 },
774 { EL_SP_INFOTRON, 1 },
786 access_direction_list[] =
788 { EL_TUBE_ANY, MV_LEFT | MV_RIGHT | MV_UP | MV_DOWN },
789 { EL_TUBE_VERTICAL, MV_UP | MV_DOWN },
790 { EL_TUBE_HORIZONTAL, MV_LEFT | MV_RIGHT },
791 { EL_TUBE_VERTICAL_LEFT, MV_LEFT | MV_UP | MV_DOWN },
792 { EL_TUBE_VERTICAL_RIGHT, MV_RIGHT | MV_UP | MV_DOWN },
793 { EL_TUBE_HORIZONTAL_UP, MV_LEFT | MV_RIGHT | MV_UP },
794 { EL_TUBE_HORIZONTAL_DOWN, MV_LEFT | MV_RIGHT | MV_DOWN },
795 { EL_TUBE_LEFT_UP, MV_LEFT | MV_UP },
796 { EL_TUBE_LEFT_DOWN, MV_LEFT | MV_DOWN },
797 { EL_TUBE_RIGHT_UP, MV_RIGHT | MV_UP },
798 { EL_TUBE_RIGHT_DOWN, MV_RIGHT | MV_DOWN },
800 { EL_SP_PORT_LEFT, MV_RIGHT },
801 { EL_SP_PORT_RIGHT, MV_LEFT },
802 { EL_SP_PORT_UP, MV_DOWN },
803 { EL_SP_PORT_DOWN, MV_UP },
804 { EL_SP_PORT_HORIZONTAL, MV_LEFT | MV_RIGHT },
805 { EL_SP_PORT_VERTICAL, MV_UP | MV_DOWN },
806 { EL_SP_PORT_ANY, MV_LEFT | MV_RIGHT | MV_UP | MV_DOWN },
807 { EL_SP_GRAVITY_PORT_LEFT, MV_RIGHT },
808 { EL_SP_GRAVITY_PORT_RIGHT, MV_LEFT },
809 { EL_SP_GRAVITY_PORT_UP, MV_DOWN },
810 { EL_SP_GRAVITY_PORT_DOWN, MV_UP },
811 { EL_SP_GRAVITY_ON_PORT_LEFT, MV_RIGHT },
812 { EL_SP_GRAVITY_ON_PORT_RIGHT, MV_LEFT },
813 { EL_SP_GRAVITY_ON_PORT_UP, MV_DOWN },
814 { EL_SP_GRAVITY_ON_PORT_DOWN, MV_UP },
815 { EL_SP_GRAVITY_OFF_PORT_LEFT, MV_RIGHT },
816 { EL_SP_GRAVITY_OFF_PORT_RIGHT, MV_LEFT },
817 { EL_SP_GRAVITY_OFF_PORT_UP, MV_DOWN },
818 { EL_SP_GRAVITY_OFF_PORT_DOWN, MV_UP },
820 { EL_UNDEFINED, MV_NONE }
823 static boolean trigger_events[MAX_NUM_ELEMENTS][NUM_CHANGE_EVENTS];
825 #define IS_AUTO_CHANGING(e) (element_info[e].has_change_event[CE_DELAY])
826 #define IS_JUST_CHANGING(x, y) (ChangeDelay[x][y] != 0)
827 #define IS_CHANGING(x, y) (IS_AUTO_CHANGING(Feld[x][y]) || \
828 IS_JUST_CHANGING(x, y))
830 #define CE_PAGE(e, ce) (element_info[e].event_page[ce])
832 /* static variables for playfield scan mode (scanning forward or backward) */
833 static int playfield_scan_start_x = 0;
834 static int playfield_scan_start_y = 0;
835 static int playfield_scan_delta_x = 1;
836 static int playfield_scan_delta_y = 1;
838 #define SCAN_PLAYFIELD(x, y) for ((y) = playfield_scan_start_y; \
839 (y) >= 0 && (y) <= lev_fieldy - 1; \
840 (y) += playfield_scan_delta_y) \
841 for ((x) = playfield_scan_start_x; \
842 (x) >= 0 && (x) <= lev_fieldx - 1; \
843 (x) += playfield_scan_delta_x) \
846 void DEBUG_SetMaximumDynamite()
850 for (i = 0; i < MAX_INVENTORY_SIZE; i++)
851 if (local_player->inventory_size < MAX_INVENTORY_SIZE)
852 local_player->inventory_element[local_player->inventory_size++] =
857 static void InitPlayfieldScanModeVars()
859 if (game.use_reverse_scan_direction)
861 playfield_scan_start_x = lev_fieldx - 1;
862 playfield_scan_start_y = lev_fieldy - 1;
864 playfield_scan_delta_x = -1;
865 playfield_scan_delta_y = -1;
869 playfield_scan_start_x = 0;
870 playfield_scan_start_y = 0;
872 playfield_scan_delta_x = 1;
873 playfield_scan_delta_y = 1;
877 static void InitPlayfieldScanMode(int mode)
879 game.use_reverse_scan_direction =
880 (mode == CA_ARG_SCAN_MODE_REVERSE ? TRUE : FALSE);
882 InitPlayfieldScanModeVars();
885 static int get_move_delay_from_stepsize(int move_stepsize)
888 MIN(MAX(MOVE_STEPSIZE_MIN, move_stepsize), MOVE_STEPSIZE_MAX);
890 /* make sure that stepsize value is always a power of 2 */
891 move_stepsize = (1 << log_2(move_stepsize));
893 return TILEX / move_stepsize;
896 static void SetPlayerMoveSpeed(struct PlayerInfo *player, int move_stepsize,
899 int player_nr = player->index_nr;
900 int move_delay = get_move_delay_from_stepsize(move_stepsize);
901 boolean cannot_move = (move_stepsize == STEPSIZE_NOT_MOVING ? TRUE : FALSE);
903 /* do no immediately change move delay -- the player might just be moving */
904 player->move_delay_value_next = move_delay;
906 /* information if player can move must be set separately */
907 player->cannot_move = cannot_move;
911 player->move_delay = game.initial_move_delay[player_nr];
912 player->move_delay_value = game.initial_move_delay_value[player_nr];
914 player->move_delay_value_next = -1;
916 player->move_delay_reset_counter = 0;
920 void GetPlayerConfig()
922 if (!audio.sound_available)
923 setup.sound_simple = FALSE;
925 if (!audio.loops_available)
926 setup.sound_loops = FALSE;
928 if (!audio.music_available)
929 setup.sound_music = FALSE;
931 if (!video.fullscreen_available)
932 setup.fullscreen = FALSE;
934 setup.sound = (setup.sound_simple || setup.sound_loops || setup.sound_music);
936 SetAudioMode(setup.sound);
940 static int getBeltNrFromBeltElement(int element)
942 return (element < EL_CONVEYOR_BELT_2_LEFT ? 0 :
943 element < EL_CONVEYOR_BELT_3_LEFT ? 1 :
944 element < EL_CONVEYOR_BELT_4_LEFT ? 2 : 3);
947 static int getBeltNrFromBeltActiveElement(int element)
949 return (element < EL_CONVEYOR_BELT_2_LEFT_ACTIVE ? 0 :
950 element < EL_CONVEYOR_BELT_3_LEFT_ACTIVE ? 1 :
951 element < EL_CONVEYOR_BELT_4_LEFT_ACTIVE ? 2 : 3);
954 static int getBeltNrFromBeltSwitchElement(int element)
956 return (element < EL_CONVEYOR_BELT_2_SWITCH_LEFT ? 0 :
957 element < EL_CONVEYOR_BELT_3_SWITCH_LEFT ? 1 :
958 element < EL_CONVEYOR_BELT_4_SWITCH_LEFT ? 2 : 3);
961 static int getBeltDirNrFromBeltSwitchElement(int element)
963 static int belt_base_element[4] =
965 EL_CONVEYOR_BELT_1_SWITCH_LEFT,
966 EL_CONVEYOR_BELT_2_SWITCH_LEFT,
967 EL_CONVEYOR_BELT_3_SWITCH_LEFT,
968 EL_CONVEYOR_BELT_4_SWITCH_LEFT
971 int belt_nr = getBeltNrFromBeltSwitchElement(element);
972 int belt_dir_nr = element - belt_base_element[belt_nr];
974 return (belt_dir_nr % 3);
977 static int getBeltDirFromBeltSwitchElement(int element)
979 static int belt_move_dir[3] =
986 int belt_dir_nr = getBeltDirNrFromBeltSwitchElement(element);
988 return belt_move_dir[belt_dir_nr];
991 static int get_element_from_group_element(int element)
993 if (IS_GROUP_ELEMENT(element))
995 struct ElementGroupInfo *group = element_info[element].group;
996 int last_anim_random_frame = gfx.anim_random_frame;
999 if (group->choice_mode == ANIM_RANDOM)
1000 gfx.anim_random_frame = RND(group->num_elements_resolved);
1002 element_pos = getAnimationFrame(group->num_elements_resolved, 1,
1003 group->choice_mode, 0,
1006 if (group->choice_mode == ANIM_RANDOM)
1007 gfx.anim_random_frame = last_anim_random_frame;
1009 group->choice_pos++;
1011 element = group->element_resolved[element_pos];
1017 static void InitPlayerField(int x, int y, int element, boolean init_game)
1019 if (element == EL_SP_MURPHY)
1023 if (stored_player[0].present)
1025 Feld[x][y] = EL_SP_MURPHY_CLONE;
1031 stored_player[0].use_murphy = TRUE;
1033 if (!level.use_artwork_element[0])
1034 stored_player[0].artwork_element = EL_SP_MURPHY;
1037 Feld[x][y] = EL_PLAYER_1;
1043 struct PlayerInfo *player = &stored_player[Feld[x][y] - EL_PLAYER_1];
1044 int jx = player->jx, jy = player->jy;
1046 player->present = TRUE;
1048 player->block_last_field = (element == EL_SP_MURPHY ?
1049 level.sp_block_last_field :
1050 level.block_last_field);
1052 /* ---------- initialize player's last field block delay --------------- */
1054 /* always start with reliable default value (no adjustment needed) */
1055 player->block_delay_adjustment = 0;
1057 /* special case 1: in Supaplex, Murphy blocks last field one more frame */
1058 if (player->block_last_field && element == EL_SP_MURPHY)
1059 player->block_delay_adjustment = 1;
1061 /* special case 2: in game engines before 3.1.1, blocking was different */
1062 if (game.use_block_last_field_bug)
1063 player->block_delay_adjustment = (player->block_last_field ? -1 : 1);
1065 if (!options.network || player->connected)
1067 player->active = TRUE;
1069 /* remove potentially duplicate players */
1070 if (StorePlayer[jx][jy] == Feld[x][y])
1071 StorePlayer[jx][jy] = 0;
1073 StorePlayer[x][y] = Feld[x][y];
1077 printf("Player %d activated.\n", player->element_nr);
1078 printf("[Local player is %d and currently %s.]\n",
1079 local_player->element_nr,
1080 local_player->active ? "active" : "not active");
1084 Feld[x][y] = EL_EMPTY;
1086 player->jx = player->last_jx = x;
1087 player->jy = player->last_jy = y;
1091 static void InitField(int x, int y, boolean init_game)
1093 int element = Feld[x][y];
1102 InitPlayerField(x, y, element, init_game);
1105 case EL_SOKOBAN_FIELD_PLAYER:
1106 element = Feld[x][y] = EL_PLAYER_1;
1107 InitField(x, y, init_game);
1109 element = Feld[x][y] = EL_SOKOBAN_FIELD_EMPTY;
1110 InitField(x, y, init_game);
1113 case EL_SOKOBAN_FIELD_EMPTY:
1114 local_player->sokobanfields_still_needed++;
1118 if (x < lev_fieldx-1 && Feld[x+1][y] == EL_ACID)
1119 Feld[x][y] = EL_ACID_POOL_TOPLEFT;
1120 else if (x > 0 && Feld[x-1][y] == EL_ACID)
1121 Feld[x][y] = EL_ACID_POOL_TOPRIGHT;
1122 else if (y > 0 && Feld[x][y-1] == EL_ACID_POOL_TOPLEFT)
1123 Feld[x][y] = EL_ACID_POOL_BOTTOMLEFT;
1124 else if (y > 0 && Feld[x][y-1] == EL_ACID)
1125 Feld[x][y] = EL_ACID_POOL_BOTTOM;
1126 else if (y > 0 && Feld[x][y-1] == EL_ACID_POOL_TOPRIGHT)
1127 Feld[x][y] = EL_ACID_POOL_BOTTOMRIGHT;
1136 case EL_SPACESHIP_RIGHT:
1137 case EL_SPACESHIP_UP:
1138 case EL_SPACESHIP_LEFT:
1139 case EL_SPACESHIP_DOWN:
1140 case EL_BD_BUTTERFLY:
1141 case EL_BD_BUTTERFLY_RIGHT:
1142 case EL_BD_BUTTERFLY_UP:
1143 case EL_BD_BUTTERFLY_LEFT:
1144 case EL_BD_BUTTERFLY_DOWN:
1146 case EL_BD_FIREFLY_RIGHT:
1147 case EL_BD_FIREFLY_UP:
1148 case EL_BD_FIREFLY_LEFT:
1149 case EL_BD_FIREFLY_DOWN:
1150 case EL_PACMAN_RIGHT:
1152 case EL_PACMAN_LEFT:
1153 case EL_PACMAN_DOWN:
1155 case EL_YAMYAM_LEFT:
1156 case EL_YAMYAM_RIGHT:
1158 case EL_YAMYAM_DOWN:
1159 case EL_DARK_YAMYAM:
1162 case EL_SP_SNIKSNAK:
1163 case EL_SP_ELECTRON:
1172 case EL_AMOEBA_FULL:
1177 case EL_AMOEBA_DROP:
1178 if (y == lev_fieldy - 1)
1180 Feld[x][y] = EL_AMOEBA_GROWING;
1181 Store[x][y] = EL_AMOEBA_WET;
1185 case EL_DYNAMITE_ACTIVE:
1186 case EL_SP_DISK_RED_ACTIVE:
1187 case EL_DYNABOMB_PLAYER_1_ACTIVE:
1188 case EL_DYNABOMB_PLAYER_2_ACTIVE:
1189 case EL_DYNABOMB_PLAYER_3_ACTIVE:
1190 case EL_DYNABOMB_PLAYER_4_ACTIVE:
1191 MovDelay[x][y] = 96;
1194 case EL_EM_DYNAMITE_ACTIVE:
1195 MovDelay[x][y] = 32;
1199 local_player->lights_still_needed++;
1203 local_player->friends_still_needed++;
1208 GfxDir[x][y] = MovDir[x][y] = 1 << RND(4);
1211 case EL_CONVEYOR_BELT_1_SWITCH_LEFT:
1212 case EL_CONVEYOR_BELT_1_SWITCH_MIDDLE:
1213 case EL_CONVEYOR_BELT_1_SWITCH_RIGHT:
1214 case EL_CONVEYOR_BELT_2_SWITCH_LEFT:
1215 case EL_CONVEYOR_BELT_2_SWITCH_MIDDLE:
1216 case EL_CONVEYOR_BELT_2_SWITCH_RIGHT:
1217 case EL_CONVEYOR_BELT_3_SWITCH_LEFT:
1218 case EL_CONVEYOR_BELT_3_SWITCH_MIDDLE:
1219 case EL_CONVEYOR_BELT_3_SWITCH_RIGHT:
1220 case EL_CONVEYOR_BELT_4_SWITCH_LEFT:
1221 case EL_CONVEYOR_BELT_4_SWITCH_MIDDLE:
1222 case EL_CONVEYOR_BELT_4_SWITCH_RIGHT:
1225 int belt_nr = getBeltNrFromBeltSwitchElement(Feld[x][y]);
1226 int belt_dir = getBeltDirFromBeltSwitchElement(Feld[x][y]);
1227 int belt_dir_nr = getBeltDirNrFromBeltSwitchElement(Feld[x][y]);
1229 if (game.belt_dir_nr[belt_nr] == 3) /* initial value */
1231 game.belt_dir[belt_nr] = belt_dir;
1232 game.belt_dir_nr[belt_nr] = belt_dir_nr;
1234 else /* more than one switch -- set it like the first switch */
1236 Feld[x][y] = Feld[x][y] - belt_dir_nr + game.belt_dir_nr[belt_nr];
1241 #if !USE_BOTH_SWITCHGATE_SWITCHES
1242 case EL_SWITCHGATE_SWITCH_DOWN: /* always start with same switch pos */
1244 Feld[x][y] = EL_SWITCHGATE_SWITCH_UP;
1247 case EL_DC_SWITCHGATE_SWITCH_DOWN: /* always start with same switch pos */
1249 Feld[x][y] = EL_DC_SWITCHGATE_SWITCH_UP;
1253 case EL_LIGHT_SWITCH_ACTIVE:
1255 game.light_time_left = level.time_light * FRAMES_PER_SECOND;
1258 case EL_INVISIBLE_STEELWALL:
1259 case EL_INVISIBLE_WALL:
1260 case EL_INVISIBLE_SAND:
1261 if (game.light_time_left > 0 ||
1262 game.lenses_time_left > 0)
1263 Feld[x][y] = getInvisibleActiveFromInvisibleElement(element);
1266 case EL_EMC_MAGIC_BALL:
1267 if (game.ball_state)
1268 Feld[x][y] = EL_EMC_MAGIC_BALL_ACTIVE;
1271 case EL_EMC_MAGIC_BALL_SWITCH:
1272 if (game.ball_state)
1273 Feld[x][y] = EL_EMC_MAGIC_BALL_SWITCH_ACTIVE;
1277 if (IS_CUSTOM_ELEMENT(element))
1279 if (CAN_MOVE(element))
1282 #if USE_NEW_CUSTOM_VALUE
1283 if (!element_info[element].use_last_ce_value || init_game)
1284 CustomValue[x][y] = GET_NEW_CE_VALUE(Feld[x][y]);
1287 else if (IS_GROUP_ELEMENT(element))
1289 Feld[x][y] = get_element_from_group_element(element);
1291 InitField(x, y, init_game);
1298 CheckTriggeredElementChange(x, y, element, CE_CREATION_OF_X);
1301 static inline void InitField_WithBug1(int x, int y, boolean init_game)
1303 InitField(x, y, init_game);
1305 /* not needed to call InitMovDir() -- already done by InitField()! */
1306 if (game.engine_version < VERSION_IDENT(3,1,0,0) &&
1307 CAN_MOVE(Feld[x][y]))
1311 static inline void InitField_WithBug2(int x, int y, boolean init_game)
1313 int old_element = Feld[x][y];
1315 InitField(x, y, init_game);
1317 /* not needed to call InitMovDir() -- already done by InitField()! */
1318 if (game.engine_version < VERSION_IDENT(3,1,0,0) &&
1319 CAN_MOVE(old_element) &&
1320 (old_element < EL_MOLE_LEFT || old_element > EL_MOLE_DOWN))
1323 /* this case is in fact a combination of not less than three bugs:
1324 first, it calls InitMovDir() for elements that can move, although this is
1325 already done by InitField(); then, it checks the element that was at this
1326 field _before_ the call to InitField() (which can change it); lastly, it
1327 was not called for "mole with direction" elements, which were treated as
1328 "cannot move" due to (fixed) wrong element initialization in "src/init.c"
1334 void DrawGameValue_Emeralds(int value)
1336 struct TextPosInfo *pos = &game.panel.gems;
1337 int font_nr = FONT_TEXT_2;
1338 int font_width = getFontWidth(font_nr);
1339 int digits = pos->chars;
1341 if (PANEL_DEACTIVATED(pos))
1344 pos->width = digits * font_width;
1346 DrawText(PANEL_XPOS(pos), PANEL_YPOS(pos), int2str(value, digits), font_nr);
1349 void DrawGameValue_Dynamite(int value)
1351 struct TextPosInfo *pos = &game.panel.inventory;
1352 int font_nr = FONT_TEXT_2;
1353 int font_width = getFontWidth(font_nr);
1354 int digits = pos->chars;
1356 if (PANEL_DEACTIVATED(pos))
1359 pos->width = digits * font_width;
1361 DrawText(PANEL_XPOS(pos), PANEL_YPOS(pos), int2str(value, digits), font_nr);
1364 void DrawGameValue_Score(int value)
1366 struct TextPosInfo *pos = &game.panel.score;
1367 int font_nr = FONT_TEXT_2;
1368 int font_width = getFontWidth(font_nr);
1369 int digits = pos->chars;
1371 if (PANEL_DEACTIVATED(pos))
1374 pos->width = digits * font_width;
1376 DrawText(PANEL_XPOS(pos), PANEL_YPOS(pos), int2str(value, digits), font_nr);
1379 void DrawGameValue_Time(int value)
1381 struct TextPosInfo *pos = &game.panel.time;
1382 static int last_value = -1;
1385 int digits = pos->chars;
1386 int font1_nr = FONT_TEXT_2;
1387 int font2_nr = FONT_TEXT_1;
1388 int font_nr = font1_nr;
1389 boolean use_dynamic_digits = (digits == -1 ? TRUE : FALSE);
1391 if (PANEL_DEACTIVATED(pos))
1394 if (use_dynamic_digits) /* use dynamic number of digits */
1396 digits = (value < 1000 ? digits1 : digits2);
1397 font_nr = (value < 1000 ? font1_nr : font2_nr);
1400 /* clear background if value just changed its size (dynamic digits only) */
1401 if (use_dynamic_digits && (last_value < 1000) != (value < 1000))
1403 int width1 = digits1 * getFontWidth(font1_nr);
1404 int width2 = digits2 * getFontWidth(font2_nr);
1405 int max_width = MAX(width1, width2);
1406 int max_height = MAX(getFontHeight(font1_nr), getFontHeight(font2_nr));
1408 pos->width = max_width;
1410 ClearRectangleOnBackground(drawto, PANEL_XPOS(pos), PANEL_YPOS(pos),
1411 max_width, max_height);
1414 pos->width = digits * getFontWidth(font_nr);
1416 DrawText(PANEL_XPOS(pos), PANEL_YPOS(pos), int2str(value, digits), font_nr);
1421 void DrawGameValue_Level(int value)
1423 struct TextPosInfo *pos = &game.panel.level;
1426 int digits = pos->chars;
1427 int font1_nr = FONT_TEXT_2;
1428 int font2_nr = FONT_TEXT_1;
1429 int font_nr = font1_nr;
1430 boolean use_dynamic_digits = (digits == -1 ? TRUE : FALSE);
1432 if (PANEL_DEACTIVATED(pos))
1435 if (use_dynamic_digits) /* use dynamic number of digits */
1437 digits = (level_nr < 100 ? digits1 : digits2);
1438 font_nr = (level_nr < 100 ? font1_nr : font2_nr);
1441 pos->width = digits * getFontWidth(font_nr);
1443 DrawText(PANEL_XPOS(pos), PANEL_YPOS(pos), int2str(value, digits), font_nr);
1446 void DrawGameValue_Keys(int key[MAX_NUM_KEYS])
1448 struct TextPosInfo *pos = &game.panel.keys;
1449 int base_key_graphic = EL_KEY_1;
1452 if (PANEL_DEACTIVATED(pos))
1455 if (level.game_engine_type == GAME_ENGINE_TYPE_EM)
1456 base_key_graphic = EL_EM_KEY_1;
1458 pos->width = 4 * MINI_TILEX;
1460 /* currently only 4 of 8 possible keys are displayed */
1461 for (i = 0; i < STD_NUM_KEYS; i++)
1463 int src_x = DOOR_GFX_PAGEX5 + 18;
1464 int src_y = DOOR_GFX_PAGEY1 + 123;
1465 int dst_x = PANEL_XPOS(pos) + i * MINI_TILEX;
1466 int dst_y = PANEL_YPOS(pos);
1469 DrawMiniGraphicExt(drawto, dst_x, dst_y, el2edimg(base_key_graphic + i));
1471 BlitBitmap(graphic_info[IMG_GLOBAL_DOOR].bitmap, drawto, src_x, src_y,
1472 MINI_TILEX, MINI_TILEY, dst_x, dst_y);
1478 void DrawGameValue_Emeralds(int value)
1480 int font_nr = FONT_TEXT_2;
1481 int xpos = (3 * 14 - 3 * getFontWidth(font_nr)) / 2;
1483 if (PANEL_DEACTIVATED(game.panel.gems))
1486 DrawText(DX_EMERALDS + xpos, DY_EMERALDS, int2str(value, 3), font_nr);
1489 void DrawGameValue_Dynamite(int value)
1491 int font_nr = FONT_TEXT_2;
1492 int xpos = (3 * 14 - 3 * getFontWidth(font_nr)) / 2;
1494 if (PANEL_DEACTIVATED(game.panel.inventory))
1497 DrawText(DX_DYNAMITE + xpos, DY_DYNAMITE, int2str(value, 3), font_nr);
1500 void DrawGameValue_Score(int value)
1502 int font_nr = FONT_TEXT_2;
1503 int xpos = (5 * 14 - 5 * getFontWidth(font_nr)) / 2;
1505 if (PANEL_DEACTIVATED(game.panel.score))
1508 DrawText(DX_SCORE + xpos, DY_SCORE, int2str(value, 5), font_nr);
1511 void DrawGameValue_Time(int value)
1513 int font1_nr = FONT_TEXT_2;
1515 int font2_nr = FONT_TEXT_1;
1517 int font2_nr = FONT_LEVEL_NUMBER;
1519 int xpos3 = (3 * 14 - 3 * getFontWidth(font1_nr)) / 2;
1520 int xpos4 = (4 * 10 - 4 * getFontWidth(font2_nr)) / 2;
1522 if (PANEL_DEACTIVATED(game.panel.time))
1525 /* clear background if value just changed its size */
1526 if (value == 999 || value == 1000)
1527 ClearRectangleOnBackground(drawto, DX_TIME1, DY_TIME, 14 * 3, 14);
1530 DrawText(DX_TIME1 + xpos3, DY_TIME, int2str(value, 3), font1_nr);
1532 DrawText(DX_TIME2 + xpos4, DY_TIME, int2str(value, 4), font2_nr);
1535 void DrawGameValue_Level(int value)
1537 int font1_nr = FONT_TEXT_2;
1539 int font2_nr = FONT_TEXT_1;
1541 int font2_nr = FONT_LEVEL_NUMBER;
1544 if (PANEL_DEACTIVATED(game.panel.level))
1548 DrawText(DX_LEVEL1, DY_LEVEL, int2str(value, 2), font1_nr);
1550 DrawText(DX_LEVEL2, DY_LEVEL, int2str(value, 3), font2_nr);
1553 void DrawGameValue_Keys(int key[MAX_NUM_KEYS])
1555 int base_key_graphic = EL_KEY_1;
1558 if (PANEL_DEACTIVATED(game.panel.keys))
1561 if (level.game_engine_type == GAME_ENGINE_TYPE_EM)
1562 base_key_graphic = EL_EM_KEY_1;
1564 /* currently only 4 of 8 possible keys are displayed */
1565 for (i = 0; i < STD_NUM_KEYS; i++)
1567 int x = XX_KEYS + i * MINI_TILEX;
1571 DrawMiniGraphicExt(drawto, DX + x,DY + y, el2edimg(base_key_graphic + i));
1573 BlitBitmap(graphic_info[IMG_GLOBAL_DOOR].bitmap, drawto,
1574 DOOR_GFX_PAGEX5 + x, y, MINI_TILEX, MINI_TILEY, DX + x,DY + y);
1580 void DrawAllGameValues(int emeralds, int dynamite, int score, int time,
1583 int key[MAX_NUM_KEYS];
1586 /* prevent EM engine from updating time/score values parallel to GameWon() */
1587 if (level.game_engine_type == GAME_ENGINE_TYPE_EM &&
1588 local_player->LevelSolved)
1591 for (i = 0; i < MAX_NUM_KEYS; i++)
1592 key[i] = key_bits & (1 << i);
1594 DrawGameValue_Level(level_nr);
1596 DrawGameValue_Emeralds(emeralds);
1597 DrawGameValue_Dynamite(dynamite);
1598 DrawGameValue_Score(score);
1599 DrawGameValue_Time(time);
1601 DrawGameValue_Keys(key);
1604 void DrawGameDoorValues()
1606 int time_value = (level.time == 0 ? TimePlayed : TimeLeft);
1607 int dynamite_value = 0;
1608 int score_value = (local_player->LevelSolved ? local_player->score_final :
1609 local_player->score);
1610 int gems_value = local_player->gems_still_needed;
1614 if (level.game_engine_type == GAME_ENGINE_TYPE_EM)
1616 DrawGameDoorValues_EM();
1621 if (game.centered_player_nr == -1)
1623 for (i = 0; i < MAX_PLAYERS; i++)
1625 for (j = 0; j < MAX_NUM_KEYS; j++)
1626 if (stored_player[i].key[j])
1627 key_bits |= (1 << j);
1629 dynamite_value += stored_player[i].inventory_size;
1634 int player_nr = game.centered_player_nr;
1636 for (i = 0; i < MAX_NUM_KEYS; i++)
1637 if (stored_player[player_nr].key[i])
1638 key_bits |= (1 << i);
1640 dynamite_value = stored_player[player_nr].inventory_size;
1643 DrawAllGameValues(gems_value, dynamite_value, score_value, time_value,
1649 =============================================================================
1651 -----------------------------------------------------------------------------
1652 initialize game engine due to level / tape version number
1653 =============================================================================
1656 static void InitGameEngine()
1658 int i, j, k, l, x, y;
1660 /* set game engine from tape file when re-playing, else from level file */
1661 game.engine_version = (tape.playing ? tape.engine_version :
1662 level.game_version);
1664 /* ---------------------------------------------------------------------- */
1665 /* set flags for bugs and changes according to active game engine version */
1666 /* ---------------------------------------------------------------------- */
1669 Summary of bugfix/change:
1670 Fixed handling for custom elements that change when pushed by the player.
1672 Fixed/changed in version:
1676 Before 3.1.0, custom elements that "change when pushing" changed directly
1677 after the player started pushing them (until then handled in "DigField()").
1678 Since 3.1.0, these custom elements are not changed until the "pushing"
1679 move of the element is finished (now handled in "ContinueMoving()").
1681 Affected levels/tapes:
1682 The first condition is generally needed for all levels/tapes before version
1683 3.1.0, which might use the old behaviour before it was changed; known tapes
1684 that are affected are some tapes from the level set "Walpurgis Gardens" by
1686 The second condition is an exception from the above case and is needed for
1687 the special case of tapes recorded with game (not engine!) version 3.1.0 or
1688 above (including some development versions of 3.1.0), but before it was
1689 known that this change would break tapes like the above and was fixed in
1690 3.1.1, so that the changed behaviour was active although the engine version
1691 while recording maybe was before 3.1.0. There is at least one tape that is
1692 affected by this exception, which is the tape for the one-level set "Bug
1693 Machine" by Juergen Bonhagen.
1696 game.use_change_when_pushing_bug =
1697 (game.engine_version < VERSION_IDENT(3,1,0,0) &&
1699 tape.game_version >= VERSION_IDENT(3,1,0,0) &&
1700 tape.game_version < VERSION_IDENT(3,1,1,0)));
1703 Summary of bugfix/change:
1704 Fixed handling for blocking the field the player leaves when moving.
1706 Fixed/changed in version:
1710 Before 3.1.1, when "block last field when moving" was enabled, the field
1711 the player is leaving when moving was blocked for the time of the move,
1712 and was directly unblocked afterwards. This resulted in the last field
1713 being blocked for exactly one less than the number of frames of one player
1714 move. Additionally, even when blocking was disabled, the last field was
1715 blocked for exactly one frame.
1716 Since 3.1.1, due to changes in player movement handling, the last field
1717 is not blocked at all when blocking is disabled. When blocking is enabled,
1718 the last field is blocked for exactly the number of frames of one player
1719 move. Additionally, if the player is Murphy, the hero of Supaplex, the
1720 last field is blocked for exactly one more than the number of frames of
1723 Affected levels/tapes:
1724 (!!! yet to be determined -- probably many !!!)
1727 game.use_block_last_field_bug =
1728 (game.engine_version < VERSION_IDENT(3,1,1,0));
1731 Summary of bugfix/change:
1732 Changed behaviour of CE changes with multiple changes per single frame.
1734 Fixed/changed in version:
1738 Before 3.2.0-6, only one single CE change was allowed in each engine frame.
1739 This resulted in race conditions where CEs seem to behave strange in some
1740 situations (where triggered CE changes were just skipped because there was
1741 already a CE change on that tile in the playfield in that engine frame).
1742 Since 3.2.0-6, this was changed to allow up to MAX_NUM_CHANGES_PER_FRAME.
1743 (The number of changes per frame must be limited in any case, because else
1744 it is easily possible to define CE changes that would result in an infinite
1745 loop, causing the whole game to freeze. The MAX_NUM_CHANGES_PER_FRAME value
1746 should be set large enough so that it would only be reached in cases where
1747 the corresponding CE change conditions run into a loop. Therefore, it seems
1748 to be reasonable to set MAX_NUM_CHANGES_PER_FRAME to the same value as the
1749 maximal number of change pages for custom elements.)
1751 Affected levels/tapes:
1755 #if USE_ONLY_ONE_CHANGE_PER_FRAME
1756 game.max_num_changes_per_frame = 1;
1758 game.max_num_changes_per_frame =
1759 (game.engine_version < VERSION_IDENT(3,2,0,6) ? 1 : 32);
1762 /* ---------------------------------------------------------------------- */
1764 /* default scan direction: scan playfield from top/left to bottom/right */
1765 InitPlayfieldScanMode(CA_ARG_SCAN_MODE_NORMAL);
1767 /* dynamically adjust element properties according to game engine version */
1768 InitElementPropertiesEngine(game.engine_version);
1771 printf("level %d: level version == %06d\n", level_nr, level.game_version);
1772 printf(" tape version == %06d [%s] [file: %06d]\n",
1773 tape.engine_version, (tape.playing ? "PLAYING" : "RECORDING"),
1775 printf(" => game.engine_version == %06d\n", game.engine_version);
1778 /* ---------- initialize player's initial move delay --------------------- */
1780 /* dynamically adjust player properties according to level information */
1781 for (i = 0; i < MAX_PLAYERS; i++)
1782 game.initial_move_delay_value[i] =
1783 get_move_delay_from_stepsize(level.initial_player_stepsize[i]);
1785 /* dynamically adjust player properties according to game engine version */
1786 for (i = 0; i < MAX_PLAYERS; i++)
1787 game.initial_move_delay[i] =
1788 (game.engine_version <= VERSION_IDENT(2,0,1,0) ?
1789 game.initial_move_delay_value[i] : 0);
1791 /* ---------- initialize player's initial push delay --------------------- */
1793 /* dynamically adjust player properties according to game engine version */
1794 game.initial_push_delay_value =
1795 (game.engine_version < VERSION_IDENT(3,0,7,1) ? 5 : -1);
1797 /* ---------- initialize changing elements ------------------------------- */
1799 /* initialize changing elements information */
1800 for (i = 0; i < MAX_NUM_ELEMENTS; i++)
1802 struct ElementInfo *ei = &element_info[i];
1804 /* this pointer might have been changed in the level editor */
1805 ei->change = &ei->change_page[0];
1807 if (!IS_CUSTOM_ELEMENT(i))
1809 ei->change->target_element = EL_EMPTY_SPACE;
1810 ei->change->delay_fixed = 0;
1811 ei->change->delay_random = 0;
1812 ei->change->delay_frames = 1;
1815 for (j = 0; j < NUM_CHANGE_EVENTS; j++)
1817 ei->has_change_event[j] = FALSE;
1819 ei->event_page_nr[j] = 0;
1820 ei->event_page[j] = &ei->change_page[0];
1824 /* add changing elements from pre-defined list */
1825 for (i = 0; change_delay_list[i].element != EL_UNDEFINED; i++)
1827 struct ChangingElementInfo *ch_delay = &change_delay_list[i];
1828 struct ElementInfo *ei = &element_info[ch_delay->element];
1830 ei->change->target_element = ch_delay->target_element;
1831 ei->change->delay_fixed = ch_delay->change_delay;
1833 ei->change->pre_change_function = ch_delay->pre_change_function;
1834 ei->change->change_function = ch_delay->change_function;
1835 ei->change->post_change_function = ch_delay->post_change_function;
1837 ei->change->can_change = TRUE;
1838 ei->change->can_change_or_has_action = TRUE;
1840 ei->has_change_event[CE_DELAY] = TRUE;
1842 SET_PROPERTY(ch_delay->element, EP_CAN_CHANGE, TRUE);
1843 SET_PROPERTY(ch_delay->element, EP_CAN_CHANGE_OR_HAS_ACTION, TRUE);
1846 /* ---------- initialize internal run-time variables ------------- */
1848 for (i = 0; i < NUM_CUSTOM_ELEMENTS; i++)
1850 struct ElementInfo *ei = &element_info[EL_CUSTOM_START + i];
1852 for (j = 0; j < ei->num_change_pages; j++)
1854 ei->change_page[j].can_change_or_has_action =
1855 (ei->change_page[j].can_change |
1856 ei->change_page[j].has_action);
1860 /* add change events from custom element configuration */
1861 for (i = 0; i < NUM_CUSTOM_ELEMENTS; i++)
1863 struct ElementInfo *ei = &element_info[EL_CUSTOM_START + i];
1865 for (j = 0; j < ei->num_change_pages; j++)
1867 if (!ei->change_page[j].can_change_or_has_action)
1870 for (k = 0; k < NUM_CHANGE_EVENTS; k++)
1872 /* only add event page for the first page found with this event */
1873 if (ei->change_page[j].has_event[k] && !(ei->has_change_event[k]))
1875 ei->has_change_event[k] = TRUE;
1877 ei->event_page_nr[k] = j;
1878 ei->event_page[k] = &ei->change_page[j];
1884 /* ---------- initialize run-time trigger player and element ------------- */
1886 for (i = 0; i < NUM_CUSTOM_ELEMENTS; i++)
1888 struct ElementInfo *ei = &element_info[EL_CUSTOM_START + i];
1890 for (j = 0; j < ei->num_change_pages; j++)
1892 ei->change_page[j].actual_trigger_element = EL_EMPTY;
1893 ei->change_page[j].actual_trigger_player = EL_PLAYER_1;
1894 ei->change_page[j].actual_trigger_side = CH_SIDE_NONE;
1895 ei->change_page[j].actual_trigger_ce_value = 0;
1896 ei->change_page[j].actual_trigger_ce_score = 0;
1900 /* ---------- initialize trigger events ---------------------------------- */
1902 /* initialize trigger events information */
1903 for (i = 0; i < MAX_NUM_ELEMENTS; i++)
1904 for (j = 0; j < NUM_CHANGE_EVENTS; j++)
1905 trigger_events[i][j] = FALSE;
1907 /* add trigger events from element change event properties */
1908 for (i = 0; i < MAX_NUM_ELEMENTS; i++)
1910 struct ElementInfo *ei = &element_info[i];
1912 for (j = 0; j < ei->num_change_pages; j++)
1914 if (!ei->change_page[j].can_change_or_has_action)
1917 if (ei->change_page[j].has_event[CE_BY_OTHER_ACTION])
1919 int trigger_element = ei->change_page[j].trigger_element;
1921 for (k = 0; k < NUM_CHANGE_EVENTS; k++)
1923 if (ei->change_page[j].has_event[k])
1925 if (IS_GROUP_ELEMENT(trigger_element))
1927 struct ElementGroupInfo *group =
1928 element_info[trigger_element].group;
1930 for (l = 0; l < group->num_elements_resolved; l++)
1931 trigger_events[group->element_resolved[l]][k] = TRUE;
1933 else if (trigger_element == EL_ANY_ELEMENT)
1934 for (l = 0; l < MAX_NUM_ELEMENTS; l++)
1935 trigger_events[l][k] = TRUE;
1937 trigger_events[trigger_element][k] = TRUE;
1944 /* ---------- initialize push delay -------------------------------------- */
1946 /* initialize push delay values to default */
1947 for (i = 0; i < MAX_NUM_ELEMENTS; i++)
1949 if (!IS_CUSTOM_ELEMENT(i))
1951 /* set default push delay values (corrected since version 3.0.7-1) */
1952 if (game.engine_version < VERSION_IDENT(3,0,7,1))
1954 element_info[i].push_delay_fixed = 2;
1955 element_info[i].push_delay_random = 8;
1959 element_info[i].push_delay_fixed = 8;
1960 element_info[i].push_delay_random = 8;
1965 /* set push delay value for certain elements from pre-defined list */
1966 for (i = 0; push_delay_list[i].element != EL_UNDEFINED; i++)
1968 int e = push_delay_list[i].element;
1970 element_info[e].push_delay_fixed = push_delay_list[i].push_delay_fixed;
1971 element_info[e].push_delay_random = push_delay_list[i].push_delay_random;
1974 /* set push delay value for Supaplex elements for newer engine versions */
1975 if (game.engine_version >= VERSION_IDENT(3,1,0,0))
1977 for (i = 0; i < MAX_NUM_ELEMENTS; i++)
1979 if (IS_SP_ELEMENT(i))
1981 /* set SP push delay to just enough to push under a falling zonk */
1982 int delay = (game.engine_version >= VERSION_IDENT(3,1,1,0) ? 8 : 6);
1984 element_info[i].push_delay_fixed = delay;
1985 element_info[i].push_delay_random = 0;
1990 /* ---------- initialize move stepsize ----------------------------------- */
1992 /* initialize move stepsize values to default */
1993 for (i = 0; i < MAX_NUM_ELEMENTS; i++)
1994 if (!IS_CUSTOM_ELEMENT(i))
1995 element_info[i].move_stepsize = MOVE_STEPSIZE_NORMAL;
1997 /* set move stepsize value for certain elements from pre-defined list */
1998 for (i = 0; move_stepsize_list[i].element != EL_UNDEFINED; i++)
2000 int e = move_stepsize_list[i].element;
2002 element_info[e].move_stepsize = move_stepsize_list[i].move_stepsize;
2005 /* ---------- initialize collect score ----------------------------------- */
2007 /* initialize collect score values for custom elements from initial value */
2008 for (i = 0; i < MAX_NUM_ELEMENTS; i++)
2009 if (IS_CUSTOM_ELEMENT(i))
2010 element_info[i].collect_score = element_info[i].collect_score_initial;
2012 /* ---------- initialize collect count ----------------------------------- */
2014 /* initialize collect count values for non-custom elements */
2015 for (i = 0; i < MAX_NUM_ELEMENTS; i++)
2016 if (!IS_CUSTOM_ELEMENT(i))
2017 element_info[i].collect_count_initial = 0;
2019 /* add collect count values for all elements from pre-defined list */
2020 for (i = 0; collect_count_list[i].element != EL_UNDEFINED; i++)
2021 element_info[collect_count_list[i].element].collect_count_initial =
2022 collect_count_list[i].count;
2024 /* ---------- initialize access direction -------------------------------- */
2026 /* initialize access direction values to default (access from every side) */
2027 for (i = 0; i < MAX_NUM_ELEMENTS; i++)
2028 if (!IS_CUSTOM_ELEMENT(i))
2029 element_info[i].access_direction = MV_ALL_DIRECTIONS;
2031 /* set access direction value for certain elements from pre-defined list */
2032 for (i = 0; access_direction_list[i].element != EL_UNDEFINED; i++)
2033 element_info[access_direction_list[i].element].access_direction =
2034 access_direction_list[i].direction;
2036 /* ---------- initialize explosion content ------------------------------- */
2037 for (i = 0; i < MAX_NUM_ELEMENTS; i++)
2039 if (IS_CUSTOM_ELEMENT(i))
2042 for (y = 0; y < 3; y++) for (x = 0; x < 3; x++)
2044 /* (content for EL_YAMYAM set at run-time with game.yamyam_content_nr) */
2046 element_info[i].content.e[x][y] =
2047 (i == EL_PLAYER_1 ? EL_EMERALD_YELLOW :
2048 i == EL_PLAYER_2 ? EL_EMERALD_RED :
2049 i == EL_PLAYER_3 ? EL_EMERALD :
2050 i == EL_PLAYER_4 ? EL_EMERALD_PURPLE :
2051 i == EL_MOLE ? EL_EMERALD_RED :
2052 i == EL_PENGUIN ? EL_EMERALD_PURPLE :
2053 i == EL_BUG ? (x == 1 && y == 1 ? EL_DIAMOND : EL_EMERALD) :
2054 i == EL_BD_BUTTERFLY ? EL_BD_DIAMOND :
2055 i == EL_SP_ELECTRON ? EL_SP_INFOTRON :
2056 i == EL_AMOEBA_TO_DIAMOND ? level.amoeba_content :
2057 i == EL_WALL_EMERALD ? EL_EMERALD :
2058 i == EL_WALL_DIAMOND ? EL_DIAMOND :
2059 i == EL_WALL_BD_DIAMOND ? EL_BD_DIAMOND :
2060 i == EL_WALL_EMERALD_YELLOW ? EL_EMERALD_YELLOW :
2061 i == EL_WALL_EMERALD_RED ? EL_EMERALD_RED :
2062 i == EL_WALL_EMERALD_PURPLE ? EL_EMERALD_PURPLE :
2063 i == EL_WALL_PEARL ? EL_PEARL :
2064 i == EL_WALL_CRYSTAL ? EL_CRYSTAL :
2069 /* ---------- initialize recursion detection ------------------------------ */
2070 recursion_loop_depth = 0;
2071 recursion_loop_detected = FALSE;
2072 recursion_loop_element = EL_UNDEFINED;
2075 int get_num_special_action(int element, int action_first, int action_last)
2077 int num_special_action = 0;
2080 for (i = action_first; i <= action_last; i++)
2082 boolean found = FALSE;
2084 for (j = 0; j < NUM_DIRECTIONS; j++)
2085 if (el_act_dir2img(element, i, j) !=
2086 el_act_dir2img(element, ACTION_DEFAULT, j))
2090 num_special_action++;
2095 return num_special_action;
2100 =============================================================================
2102 -----------------------------------------------------------------------------
2103 initialize and start new game
2104 =============================================================================
2109 boolean emulate_bd = TRUE; /* unless non-BOULDERDASH elements found */
2110 boolean emulate_sb = TRUE; /* unless non-SOKOBAN elements found */
2111 boolean emulate_sp = TRUE; /* unless non-SUPAPLEX elements found */
2112 boolean do_fading = (game_status == GAME_MODE_MAIN);
2115 game_status = GAME_MODE_PLAYING;
2119 /* don't play tapes over network */
2120 network_playing = (options.network && !tape.playing);
2122 for (i = 0; i < MAX_PLAYERS; i++)
2124 struct PlayerInfo *player = &stored_player[i];
2126 player->index_nr = i;
2127 player->index_bit = (1 << i);
2128 player->element_nr = EL_PLAYER_1 + i;
2130 player->present = FALSE;
2131 player->active = FALSE;
2132 player->killed = FALSE;
2135 player->effective_action = 0;
2136 player->programmed_action = 0;
2139 player->score_final = 0;
2141 player->gems_still_needed = level.gems_needed;
2142 player->sokobanfields_still_needed = 0;
2143 player->lights_still_needed = 0;
2144 player->friends_still_needed = 0;
2146 for (j = 0; j < MAX_NUM_KEYS; j++)
2147 player->key[j] = FALSE;
2149 player->num_white_keys = 0;
2151 player->dynabomb_count = 0;
2152 player->dynabomb_size = 1;
2153 player->dynabombs_left = 0;
2154 player->dynabomb_xl = FALSE;
2156 player->MovDir = MV_NONE;
2159 player->GfxDir = MV_NONE;
2160 player->GfxAction = ACTION_DEFAULT;
2162 player->StepFrame = 0;
2164 player->use_murphy = FALSE;
2165 player->artwork_element =
2166 (level.use_artwork_element[i] ? level.artwork_element[i] :
2167 player->element_nr);
2169 player->block_last_field = FALSE; /* initialized in InitPlayerField() */
2170 player->block_delay_adjustment = 0; /* initialized in InitPlayerField() */
2172 player->gravity = level.initial_player_gravity[i];
2174 player->can_fall_into_acid = CAN_MOVE_INTO_ACID(player->element_nr);
2176 player->actual_frame_counter = 0;
2178 player->step_counter = 0;
2180 player->last_move_dir = MV_NONE;
2182 player->is_active = FALSE;
2184 player->is_waiting = FALSE;
2185 player->is_moving = FALSE;
2186 player->is_auto_moving = FALSE;
2187 player->is_digging = FALSE;
2188 player->is_snapping = FALSE;
2189 player->is_collecting = FALSE;
2190 player->is_pushing = FALSE;
2191 player->is_switching = FALSE;
2192 player->is_dropping = FALSE;
2193 player->is_dropping_pressed = FALSE;
2195 player->is_bored = FALSE;
2196 player->is_sleeping = FALSE;
2198 player->frame_counter_bored = -1;
2199 player->frame_counter_sleeping = -1;
2201 player->anim_delay_counter = 0;
2202 player->post_delay_counter = 0;
2204 player->dir_waiting = MV_NONE;
2205 player->action_waiting = ACTION_DEFAULT;
2206 player->last_action_waiting = ACTION_DEFAULT;
2207 player->special_action_bored = ACTION_DEFAULT;
2208 player->special_action_sleeping = ACTION_DEFAULT;
2210 player->switch_x = -1;
2211 player->switch_y = -1;
2213 player->drop_x = -1;
2214 player->drop_y = -1;
2216 player->show_envelope = 0;
2218 SetPlayerMoveSpeed(player, level.initial_player_stepsize[i], TRUE);
2220 player->push_delay = -1; /* initialized when pushing starts */
2221 player->push_delay_value = game.initial_push_delay_value;
2223 player->drop_delay = 0;
2224 player->drop_pressed_delay = 0;
2226 player->last_jx = -1;
2227 player->last_jy = -1;
2231 player->shield_normal_time_left = 0;
2232 player->shield_deadly_time_left = 0;
2234 player->inventory_infinite_element = EL_UNDEFINED;
2235 player->inventory_size = 0;
2237 DigField(player, 0, 0, 0, 0, 0, 0, DF_NO_PUSH);
2238 SnapField(player, 0, 0);
2240 player->LevelSolved = FALSE;
2241 player->GameOver = FALSE;
2243 player->LevelSolved_GameEnd = FALSE;
2244 player->LevelSolved_SaveTape = FALSE;
2245 player->LevelSolved_SaveScore = FALSE;
2248 network_player_action_received = FALSE;
2250 #if defined(NETWORK_AVALIABLE)
2251 /* initial null action */
2252 if (network_playing)
2253 SendToServer_MovePlayer(MV_NONE);
2262 TimeLeft = level.time;
2265 ScreenMovDir = MV_NONE;
2269 ScrollStepSize = 0; /* will be correctly initialized by ScrollScreen() */
2271 AllPlayersGone = FALSE;
2273 game.yamyam_content_nr = 0;
2274 game.magic_wall_active = FALSE;
2275 game.magic_wall_time_left = 0;
2276 game.light_time_left = 0;
2277 game.timegate_time_left = 0;
2278 game.switchgate_pos = 0;
2279 game.wind_direction = level.wind_direction_initial;
2281 #if !USE_PLAYER_GRAVITY
2282 game.gravity = FALSE;
2283 game.explosions_delayed = TRUE;
2286 game.lenses_time_left = 0;
2287 game.magnify_time_left = 0;
2289 game.ball_state = level.ball_state_initial;
2290 game.ball_content_nr = 0;
2292 game.envelope_active = FALSE;
2294 /* set focus to local player for network games, else to all players */
2295 game.centered_player_nr = (network_playing ? local_player->index_nr : -1);
2296 game.centered_player_nr_next = game.centered_player_nr;
2297 game.set_centered_player = FALSE;
2299 if (network_playing && tape.recording)
2301 /* store client dependent player focus when recording network games */
2302 tape.centered_player_nr_next = game.centered_player_nr_next;
2303 tape.set_centered_player = TRUE;
2306 for (i = 0; i < NUM_BELTS; i++)
2308 game.belt_dir[i] = MV_NONE;
2309 game.belt_dir_nr[i] = 3; /* not moving, next moving left */
2312 for (i = 0; i < MAX_NUM_AMOEBA; i++)
2313 AmoebaCnt[i] = AmoebaCnt2[i] = 0;
2315 SCAN_PLAYFIELD(x, y)
2317 Feld[x][y] = level.field[x][y];
2318 MovPos[x][y] = MovDir[x][y] = MovDelay[x][y] = 0;
2319 ChangeDelay[x][y] = 0;
2320 ChangePage[x][y] = -1;
2321 #if USE_NEW_CUSTOM_VALUE
2322 CustomValue[x][y] = 0; /* initialized in InitField() */
2324 Store[x][y] = Store2[x][y] = StorePlayer[x][y] = Back[x][y] = 0;
2326 WasJustMoving[x][y] = 0;
2327 WasJustFalling[x][y] = 0;
2328 CheckCollision[x][y] = 0;
2329 CheckImpact[x][y] = 0;
2331 Pushed[x][y] = FALSE;
2333 ChangeCount[x][y] = 0;
2334 ChangeEvent[x][y] = -1;
2336 ExplodePhase[x][y] = 0;
2337 ExplodeDelay[x][y] = 0;
2338 ExplodeField[x][y] = EX_TYPE_NONE;
2340 RunnerVisit[x][y] = 0;
2341 PlayerVisit[x][y] = 0;
2344 GfxRandom[x][y] = INIT_GFX_RANDOM();
2345 GfxElement[x][y] = EL_UNDEFINED;
2346 GfxAction[x][y] = ACTION_DEFAULT;
2347 GfxDir[x][y] = MV_NONE;
2350 SCAN_PLAYFIELD(x, y)
2352 if (emulate_bd && !IS_BD_ELEMENT(Feld[x][y]))
2354 if (emulate_sb && !IS_SB_ELEMENT(Feld[x][y]))
2356 if (emulate_sp && !IS_SP_ELEMENT(Feld[x][y]))
2359 InitField(x, y, TRUE);
2364 for (i = 0; i < MAX_PLAYERS; i++)
2366 struct PlayerInfo *player = &stored_player[i];
2368 /* set number of special actions for bored and sleeping animation */
2369 player->num_special_action_bored =
2370 get_num_special_action(player->artwork_element,
2371 ACTION_BORING_1, ACTION_BORING_LAST);
2372 player->num_special_action_sleeping =
2373 get_num_special_action(player->artwork_element,
2374 ACTION_SLEEPING_1, ACTION_SLEEPING_LAST);
2377 game.emulation = (emulate_bd ? EMU_BOULDERDASH :
2378 emulate_sb ? EMU_SOKOBAN :
2379 emulate_sp ? EMU_SUPAPLEX : EMU_NONE);
2381 #if USE_NEW_ALL_SLIPPERY
2382 /* initialize type of slippery elements */
2383 for (i = 0; i < MAX_NUM_ELEMENTS; i++)
2385 if (!IS_CUSTOM_ELEMENT(i))
2387 /* default: elements slip down either to the left or right randomly */
2388 element_info[i].slippery_type = SLIPPERY_ANY_RANDOM;
2390 /* SP style elements prefer to slip down on the left side */
2391 if (game.engine_version >= VERSION_IDENT(3,1,1,0) && IS_SP_ELEMENT(i))
2392 element_info[i].slippery_type = SLIPPERY_ANY_LEFT_RIGHT;
2394 /* BD style elements prefer to slip down on the left side */
2395 if (game.emulation == EMU_BOULDERDASH)
2396 element_info[i].slippery_type = SLIPPERY_ANY_LEFT_RIGHT;
2401 /* initialize explosion and ignition delay */
2402 for (i = 0; i < MAX_NUM_ELEMENTS; i++)
2404 if (!IS_CUSTOM_ELEMENT(i))
2407 int delay = (((IS_SP_ELEMENT(i) && i != EL_EMPTY_SPACE) &&
2408 game.engine_version >= VERSION_IDENT(3,1,0,0)) ||
2409 game.emulation == EMU_SUPAPLEX ? 3 : 2);
2410 int last_phase = (num_phase + 1) * delay;
2411 int half_phase = (num_phase / 2) * delay;
2413 element_info[i].explosion_delay = last_phase - 1;
2414 element_info[i].ignition_delay = half_phase;
2416 if (i == EL_BLACK_ORB)
2417 element_info[i].ignition_delay = 1;
2421 if (element_info[i].explosion_delay < 1) /* !!! check again !!! */
2422 element_info[i].explosion_delay = 1;
2424 if (element_info[i].ignition_delay < 1) /* !!! check again !!! */
2425 element_info[i].ignition_delay = 1;
2429 /* correct non-moving belts to start moving left */
2430 for (i = 0; i < NUM_BELTS; i++)
2431 if (game.belt_dir[i] == MV_NONE)
2432 game.belt_dir_nr[i] = 3; /* not moving, next moving left */
2434 /* check if any connected player was not found in playfield */
2435 for (i = 0; i < MAX_PLAYERS; i++)
2437 struct PlayerInfo *player = &stored_player[i];
2439 if (player->connected && !player->present)
2441 for (j = 0; j < MAX_PLAYERS; j++)
2443 struct PlayerInfo *some_player = &stored_player[j];
2444 int jx = some_player->jx, jy = some_player->jy;
2446 /* assign first free player found that is present in the playfield */
2447 if (some_player->present && !some_player->connected)
2449 player->present = TRUE;
2450 player->active = TRUE;
2452 some_player->present = FALSE;
2453 some_player->active = FALSE;
2455 player->artwork_element = some_player->artwork_element;
2457 player->block_last_field = some_player->block_last_field;
2458 player->block_delay_adjustment = some_player->block_delay_adjustment;
2460 StorePlayer[jx][jy] = player->element_nr;
2461 player->jx = player->last_jx = jx;
2462 player->jy = player->last_jy = jy;
2472 /* when playing a tape, eliminate all players who do not participate */
2474 for (i = 0; i < MAX_PLAYERS; i++)
2476 if (stored_player[i].active && !tape.player_participates[i])
2478 struct PlayerInfo *player = &stored_player[i];
2479 int jx = player->jx, jy = player->jy;
2481 player->active = FALSE;
2482 StorePlayer[jx][jy] = 0;
2483 Feld[jx][jy] = EL_EMPTY;
2487 else if (!options.network && !setup.team_mode) /* && !tape.playing */
2489 /* when in single player mode, eliminate all but the first active player */
2491 for (i = 0; i < MAX_PLAYERS; i++)
2493 if (stored_player[i].active)
2495 for (j = i + 1; j < MAX_PLAYERS; j++)
2497 if (stored_player[j].active)
2499 struct PlayerInfo *player = &stored_player[j];
2500 int jx = player->jx, jy = player->jy;
2502 player->active = FALSE;
2503 player->present = FALSE;
2505 StorePlayer[jx][jy] = 0;
2506 Feld[jx][jy] = EL_EMPTY;
2513 /* when recording the game, store which players take part in the game */
2516 for (i = 0; i < MAX_PLAYERS; i++)
2517 if (stored_player[i].active)
2518 tape.player_participates[i] = TRUE;
2523 for (i = 0; i < MAX_PLAYERS; i++)
2525 struct PlayerInfo *player = &stored_player[i];
2527 printf("Player %d: present == %d, connected == %d, active == %d.\n",
2532 if (local_player == player)
2533 printf("Player %d is local player.\n", i+1);
2537 if (BorderElement == EL_EMPTY)
2540 SBX_Right = lev_fieldx - SCR_FIELDX;
2542 SBY_Lower = lev_fieldy - SCR_FIELDY;
2547 SBX_Right = lev_fieldx - SCR_FIELDX + 1;
2549 SBY_Lower = lev_fieldy - SCR_FIELDY + 1;
2552 if (lev_fieldx + (SBX_Left == -1 ? 2 : 0) <= SCR_FIELDX)
2553 SBX_Left = SBX_Right = -1 * (SCR_FIELDX - lev_fieldx) / 2;
2555 if (lev_fieldy + (SBY_Upper == -1 ? 2 : 0) <= SCR_FIELDY)
2556 SBY_Upper = SBY_Lower = -1 * (SCR_FIELDY - lev_fieldy) / 2;
2558 /* if local player not found, look for custom element that might create
2559 the player (make some assumptions about the right custom element) */
2560 if (!local_player->present)
2562 int start_x = 0, start_y = 0;
2563 int found_rating = 0;
2564 int found_element = EL_UNDEFINED;
2565 int player_nr = local_player->index_nr;
2567 SCAN_PLAYFIELD(x, y)
2569 int element = Feld[x][y];
2574 if (level.use_start_element[player_nr] &&
2575 level.start_element[player_nr] == element &&
2582 found_element = element;
2585 if (!IS_CUSTOM_ELEMENT(element))
2588 if (CAN_CHANGE(element))
2590 for (i = 0; i < element_info[element].num_change_pages; i++)
2592 /* check for player created from custom element as single target */
2593 content = element_info[element].change_page[i].target_element;
2594 is_player = ELEM_IS_PLAYER(content);
2596 if (is_player && (found_rating < 3 || element < found_element))
2602 found_element = element;
2607 for (yy = 0; yy < 3; yy++) for (xx = 0; xx < 3; xx++)
2609 /* check for player created from custom element as explosion content */
2610 content = element_info[element].content.e[xx][yy];
2611 is_player = ELEM_IS_PLAYER(content);
2613 if (is_player && (found_rating < 2 || element < found_element))
2615 start_x = x + xx - 1;
2616 start_y = y + yy - 1;
2619 found_element = element;
2622 if (!CAN_CHANGE(element))
2625 for (i = 0; i < element_info[element].num_change_pages; i++)
2627 /* check for player created from custom element as extended target */
2629 element_info[element].change_page[i].target_content.e[xx][yy];
2631 is_player = ELEM_IS_PLAYER(content);
2633 if (is_player && (found_rating < 1 || element < found_element))
2635 start_x = x + xx - 1;
2636 start_y = y + yy - 1;
2639 found_element = element;
2645 scroll_x = (start_x < SBX_Left + MIDPOSX ? SBX_Left :
2646 start_x > SBX_Right + MIDPOSX ? SBX_Right :
2649 scroll_y = (start_y < SBY_Upper + MIDPOSY ? SBY_Upper :
2650 start_y > SBY_Lower + MIDPOSY ? SBY_Lower :
2655 scroll_x = (local_player->jx < SBX_Left + MIDPOSX ? SBX_Left :
2656 local_player->jx > SBX_Right + MIDPOSX ? SBX_Right :
2657 local_player->jx - MIDPOSX);
2659 scroll_y = (local_player->jy < SBY_Upper + MIDPOSY ? SBY_Upper :
2660 local_player->jy > SBY_Lower + MIDPOSY ? SBY_Lower :
2661 local_player->jy - MIDPOSY);
2666 if (!game.restart_level)
2667 CloseDoor(DOOR_CLOSE_1);
2670 FadeOut(REDRAW_FIELD);
2672 /* !!! FIX THIS (START) !!! */
2673 if (level.game_engine_type == GAME_ENGINE_TYPE_EM)
2675 InitGameEngine_EM();
2677 /* blit playfield from scroll buffer to normal back buffer for fading in */
2678 BlitScreenToBitmap_EM(backbuffer);
2685 /* after drawing the level, correct some elements */
2686 if (game.timegate_time_left == 0)
2687 CloseAllOpenTimegates();
2689 /* blit playfield from scroll buffer to normal back buffer for fading in */
2690 if (setup.soft_scrolling)
2691 BlitBitmap(fieldbuffer, backbuffer, FX, FY, SXSIZE, SYSIZE, SX, SY);
2693 redraw_mask |= REDRAW_FROM_BACKBUFFER;
2695 /* !!! FIX THIS (END) !!! */
2698 FadeIn(REDRAW_FIELD);
2702 if (!game.restart_level)
2704 /* copy default game door content to main double buffer */
2705 BlitBitmap(graphic_info[IMG_GLOBAL_DOOR].bitmap, drawto,
2706 DOOR_GFX_PAGEX5, DOOR_GFX_PAGEY1, DXSIZE, DYSIZE, DX, DY);
2709 SetPanelBackground();
2710 SetDrawBackgroundMask(REDRAW_DOOR_1);
2712 DrawGameDoorValues();
2714 if (!game.restart_level)
2718 game_gadget[SOUND_CTRL_ID_MUSIC]->checked = setup.sound_music;
2719 game_gadget[SOUND_CTRL_ID_LOOPS]->checked = setup.sound_loops;
2720 game_gadget[SOUND_CTRL_ID_SIMPLE]->checked = setup.sound_simple;
2724 /* copy actual game door content to door double buffer for OpenDoor() */
2725 BlitBitmap(drawto, bitmap_db_door,
2726 DX, DY, DXSIZE, DYSIZE, DOOR_GFX_PAGEX1, DOOR_GFX_PAGEY1);
2728 OpenDoor(DOOR_OPEN_ALL);
2730 PlaySound(SND_GAME_STARTING);
2732 if (setup.sound_music)
2735 KeyboardAutoRepeatOffUnlessAutoplay();
2739 for (i = 0; i < MAX_PLAYERS; i++)
2740 printf("Player %d %sactive.\n",
2741 i + 1, (stored_player[i].active ? "" : "not "));
2752 game.restart_level = FALSE;
2755 void UpdateEngineValues(int actual_scroll_x, int actual_scroll_y)
2757 /* this is used for non-R'n'D game engines to update certain engine values */
2759 /* needed to determine if sounds are played within the visible screen area */
2760 scroll_x = actual_scroll_x;
2761 scroll_y = actual_scroll_y;
2764 void InitMovDir(int x, int y)
2766 int i, element = Feld[x][y];
2767 static int xy[4][2] =
2774 static int direction[3][4] =
2776 { MV_RIGHT, MV_UP, MV_LEFT, MV_DOWN },
2777 { MV_LEFT, MV_DOWN, MV_RIGHT, MV_UP },
2778 { MV_LEFT, MV_RIGHT, MV_UP, MV_DOWN }
2787 Feld[x][y] = EL_BUG;
2788 MovDir[x][y] = direction[0][element - EL_BUG_RIGHT];
2791 case EL_SPACESHIP_RIGHT:
2792 case EL_SPACESHIP_UP:
2793 case EL_SPACESHIP_LEFT:
2794 case EL_SPACESHIP_DOWN:
2795 Feld[x][y] = EL_SPACESHIP;
2796 MovDir[x][y] = direction[0][element - EL_SPACESHIP_RIGHT];
2799 case EL_BD_BUTTERFLY_RIGHT:
2800 case EL_BD_BUTTERFLY_UP:
2801 case EL_BD_BUTTERFLY_LEFT:
2802 case EL_BD_BUTTERFLY_DOWN:
2803 Feld[x][y] = EL_BD_BUTTERFLY;
2804 MovDir[x][y] = direction[0][element - EL_BD_BUTTERFLY_RIGHT];
2807 case EL_BD_FIREFLY_RIGHT:
2808 case EL_BD_FIREFLY_UP:
2809 case EL_BD_FIREFLY_LEFT:
2810 case EL_BD_FIREFLY_DOWN:
2811 Feld[x][y] = EL_BD_FIREFLY;
2812 MovDir[x][y] = direction[0][element - EL_BD_FIREFLY_RIGHT];
2815 case EL_PACMAN_RIGHT:
2817 case EL_PACMAN_LEFT:
2818 case EL_PACMAN_DOWN:
2819 Feld[x][y] = EL_PACMAN;
2820 MovDir[x][y] = direction[0][element - EL_PACMAN_RIGHT];
2823 case EL_YAMYAM_LEFT:
2824 case EL_YAMYAM_RIGHT:
2826 case EL_YAMYAM_DOWN:
2827 Feld[x][y] = EL_YAMYAM;
2828 MovDir[x][y] = direction[2][element - EL_YAMYAM_LEFT];
2831 case EL_SP_SNIKSNAK:
2832 MovDir[x][y] = MV_UP;
2835 case EL_SP_ELECTRON:
2836 MovDir[x][y] = MV_LEFT;
2843 Feld[x][y] = EL_MOLE;
2844 MovDir[x][y] = direction[2][element - EL_MOLE_LEFT];
2848 if (IS_CUSTOM_ELEMENT(element))
2850 struct ElementInfo *ei = &element_info[element];
2851 int move_direction_initial = ei->move_direction_initial;
2852 int move_pattern = ei->move_pattern;
2854 if (move_direction_initial == MV_START_PREVIOUS)
2856 if (MovDir[x][y] != MV_NONE)
2859 move_direction_initial = MV_START_AUTOMATIC;
2862 if (move_direction_initial == MV_START_RANDOM)
2863 MovDir[x][y] = 1 << RND(4);
2864 else if (move_direction_initial & MV_ANY_DIRECTION)
2865 MovDir[x][y] = move_direction_initial;
2866 else if (move_pattern == MV_ALL_DIRECTIONS ||
2867 move_pattern == MV_TURNING_LEFT ||
2868 move_pattern == MV_TURNING_RIGHT ||
2869 move_pattern == MV_TURNING_LEFT_RIGHT ||
2870 move_pattern == MV_TURNING_RIGHT_LEFT ||
2871 move_pattern == MV_TURNING_RANDOM)
2872 MovDir[x][y] = 1 << RND(4);
2873 else if (move_pattern == MV_HORIZONTAL)
2874 MovDir[x][y] = (RND(2) ? MV_LEFT : MV_RIGHT);
2875 else if (move_pattern == MV_VERTICAL)
2876 MovDir[x][y] = (RND(2) ? MV_UP : MV_DOWN);
2877 else if (move_pattern & MV_ANY_DIRECTION)
2878 MovDir[x][y] = element_info[element].move_pattern;
2879 else if (move_pattern == MV_ALONG_LEFT_SIDE ||
2880 move_pattern == MV_ALONG_RIGHT_SIDE)
2882 /* use random direction as default start direction */
2883 if (game.engine_version >= VERSION_IDENT(3,1,0,0))
2884 MovDir[x][y] = 1 << RND(4);
2886 for (i = 0; i < NUM_DIRECTIONS; i++)
2888 int x1 = x + xy[i][0];
2889 int y1 = y + xy[i][1];
2891 if (!IN_LEV_FIELD(x1, y1) || !IS_FREE(x1, y1))
2893 if (move_pattern == MV_ALONG_RIGHT_SIDE)
2894 MovDir[x][y] = direction[0][i];
2896 MovDir[x][y] = direction[1][i];
2905 MovDir[x][y] = 1 << RND(4);
2907 if (element != EL_BUG &&
2908 element != EL_SPACESHIP &&
2909 element != EL_BD_BUTTERFLY &&
2910 element != EL_BD_FIREFLY)
2913 for (i = 0; i < NUM_DIRECTIONS; i++)
2915 int x1 = x + xy[i][0];
2916 int y1 = y + xy[i][1];
2918 if (!IN_LEV_FIELD(x1, y1) || !IS_FREE(x1, y1))
2920 if (element == EL_BUG || element == EL_BD_BUTTERFLY)
2922 MovDir[x][y] = direction[0][i];
2925 else if (element == EL_SPACESHIP || element == EL_BD_FIREFLY ||
2926 element == EL_SP_SNIKSNAK || element == EL_SP_ELECTRON)
2928 MovDir[x][y] = direction[1][i];
2937 GfxDir[x][y] = MovDir[x][y];
2940 void InitAmoebaNr(int x, int y)
2943 int group_nr = AmoebeNachbarNr(x, y);
2947 for (i = 1; i < MAX_NUM_AMOEBA; i++)
2949 if (AmoebaCnt[i] == 0)
2957 AmoebaNr[x][y] = group_nr;
2958 AmoebaCnt[group_nr]++;
2959 AmoebaCnt2[group_nr]++;
2962 static void PlayerWins(struct PlayerInfo *player)
2964 player->LevelSolved = TRUE;
2965 player->GameOver = TRUE;
2967 player->score_final = (level.game_engine_type == GAME_ENGINE_TYPE_EM ?
2968 level.native_em_level->lev->score : player->score);
2973 static int time, time_final;
2974 static int score, score_final;
2975 static int game_over_delay = 0;
2976 int game_over_delay_value = 50;
2978 if (!local_player->LevelSolved_GameEnd)
2982 /* do not start end game actions before the player stops moving (to exit) */
2983 if (local_player->MovPos)
2986 local_player->LevelSolved_GameEnd = TRUE;
2987 local_player->LevelSolved_SaveTape = tape.recording;
2988 local_player->LevelSolved_SaveScore = !tape.playing;
2990 if (tape.auto_play) /* tape might already be stopped here */
2991 tape.auto_play_level_solved = TRUE;
2997 game_over_delay = game_over_delay_value;
2999 time = time_final = (level.time == 0 ? TimePlayed : TimeLeft);
3000 score = score_final = local_player->score_final;
3005 score_final += TimeLeft * level.score[SC_TIME_BONUS];
3007 else if (level.time == 0 && TimePlayed < 999)
3010 score_final += (999 - TimePlayed) * level.score[SC_TIME_BONUS];
3013 local_player->score_final = score_final;
3015 if (level_editor_test_game)
3018 score = score_final;
3020 DrawGameValue_Time(time);
3021 DrawGameValue_Score(score);
3024 if (level.game_engine_type == GAME_ENGINE_TYPE_RND)
3026 if (ExitX >= 0 && ExitY >= 0) /* local player has left the level */
3028 /* close exit door after last player */
3029 if ((AllPlayersGone &&
3030 (Feld[ExitX][ExitY] == EL_EXIT_OPEN ||
3031 Feld[ExitX][ExitY] == EL_SP_EXIT_OPEN ||
3032 Feld[ExitX][ExitY] == EL_STEEL_EXIT_OPEN)) ||
3033 Feld[ExitX][ExitY] == EL_EM_EXIT_OPEN ||
3034 Feld[ExitX][ExitY] == EL_EM_STEEL_EXIT_OPEN)
3036 int element = Feld[ExitX][ExitY];
3039 if (element == EL_EM_EXIT_OPEN ||
3040 element == EL_EM_STEEL_EXIT_OPEN)
3047 Feld[ExitX][ExitY] =
3048 (element == EL_EXIT_OPEN ? EL_EXIT_CLOSING :
3049 element == EL_EM_EXIT_OPEN ? EL_EM_EXIT_CLOSING :
3050 element == EL_SP_EXIT_OPEN ? EL_SP_EXIT_CLOSING:
3051 element == EL_STEEL_EXIT_OPEN ? EL_STEEL_EXIT_CLOSING:
3052 EL_EM_STEEL_EXIT_CLOSING);
3054 PlayLevelSoundElementAction(ExitX, ExitY, element, ACTION_CLOSING);
3058 /* player disappears */
3059 DrawLevelField(ExitX, ExitY);
3062 for (i = 0; i < MAX_PLAYERS; i++)
3064 struct PlayerInfo *player = &stored_player[i];
3066 if (player->present)
3068 RemovePlayer(player);
3070 /* player disappears */
3071 DrawLevelField(player->jx, player->jy);
3076 PlaySound(SND_GAME_WINNING);
3079 if (game_over_delay > 0)
3086 if (time != time_final)
3088 int time_to_go = ABS(time_final - time);
3089 int time_count_dir = (time < time_final ? +1 : -1);
3090 int time_count_steps = (time_to_go > 100 && time_to_go % 10 == 0 ? 10 : 1);
3092 time += time_count_steps * time_count_dir;
3093 score += time_count_steps * level.score[SC_TIME_BONUS];
3095 DrawGameValue_Time(time);
3096 DrawGameValue_Score(score);
3098 if (time == time_final)
3099 StopSound(SND_GAME_LEVELTIME_BONUS);
3100 else if (setup.sound_loops)
3101 PlaySoundLoop(SND_GAME_LEVELTIME_BONUS);
3103 PlaySound(SND_GAME_LEVELTIME_BONUS);
3110 boolean raise_level = FALSE;
3112 CloseDoor(DOOR_CLOSE_1);
3114 if (local_player->LevelSolved_SaveTape)
3121 SaveTapeChecked(tape.level_nr); /* ask to save tape */
3123 SaveTape(tape.level_nr); /* ask to save tape */
3127 if (level_editor_test_game)
3129 game_status = GAME_MODE_MAIN;
3136 if (!local_player->LevelSolved_SaveScore)
3138 FadeOut(REDRAW_FIELD);
3140 game_status = GAME_MODE_MAIN;
3142 DrawAndFadeInMainMenu(REDRAW_FIELD);
3147 if (level_nr == leveldir_current->handicap_level)
3149 leveldir_current->handicap_level++;
3150 SaveLevelSetup_SeriesInfo();
3153 if (level_nr < leveldir_current->last_level)
3154 raise_level = TRUE; /* advance to next level */
3156 if ((hi_pos = NewHiScore()) >= 0)
3158 game_status = GAME_MODE_SCORES;
3160 DrawHallOfFame(hi_pos);
3170 FadeOut(REDRAW_FIELD);
3172 game_status = GAME_MODE_MAIN;
3180 DrawAndFadeInMainMenu(REDRAW_FIELD);
3189 LoadScore(level_nr);
3191 if (strEqual(setup.player_name, EMPTY_PLAYER_NAME) ||
3192 local_player->score_final < highscore[MAX_SCORE_ENTRIES - 1].Score)
3195 for (k = 0; k < MAX_SCORE_ENTRIES; k++)
3197 if (local_player->score_final > highscore[k].Score)
3199 /* player has made it to the hall of fame */
3201 if (k < MAX_SCORE_ENTRIES - 1)
3203 int m = MAX_SCORE_ENTRIES - 1;
3206 for (l = k; l < MAX_SCORE_ENTRIES; l++)
3207 if (strEqual(setup.player_name, highscore[l].Name))
3209 if (m == k) /* player's new highscore overwrites his old one */
3213 for (l = m; l > k; l--)
3215 strcpy(highscore[l].Name, highscore[l - 1].Name);
3216 highscore[l].Score = highscore[l - 1].Score;
3223 strncpy(highscore[k].Name, setup.player_name, MAX_PLAYER_NAME_LEN);
3224 highscore[k].Name[MAX_PLAYER_NAME_LEN] = '\0';
3225 highscore[k].Score = local_player->score_final;
3231 else if (!strncmp(setup.player_name, highscore[k].Name,
3232 MAX_PLAYER_NAME_LEN))
3233 break; /* player already there with a higher score */
3239 SaveScore(level_nr);
3244 inline static int getElementMoveStepsizeExt(int x, int y, int direction)
3246 int element = Feld[x][y];
3247 int dx = (direction == MV_LEFT ? -1 : direction == MV_RIGHT ? +1 : 0);
3248 int dy = (direction == MV_UP ? -1 : direction == MV_DOWN ? +1 : 0);
3249 int horiz_move = (dx != 0);
3250 int sign = (horiz_move ? dx : dy);
3251 int step = sign * element_info[element].move_stepsize;
3253 /* special values for move stepsize for spring and things on conveyor belt */
3256 if (CAN_FALL(element) &&
3257 y < lev_fieldy - 1 && IS_BELT_ACTIVE(Feld[x][y + 1]))
3258 step = sign * MOVE_STEPSIZE_NORMAL / 2;
3259 else if (element == EL_SPRING)
3260 step = sign * MOVE_STEPSIZE_NORMAL * 2;
3266 inline static int getElementMoveStepsize(int x, int y)
3268 return getElementMoveStepsizeExt(x, y, MovDir[x][y]);
3271 void InitPlayerGfxAnimation(struct PlayerInfo *player, int action, int dir)
3273 if (player->GfxAction != action || player->GfxDir != dir)
3276 printf("Player frame reset! (%d => %d, %d => %d)\n",
3277 player->GfxAction, action, player->GfxDir, dir);
3280 player->GfxAction = action;
3281 player->GfxDir = dir;
3283 player->StepFrame = 0;
3287 #if USE_GFX_RESET_GFX_ANIMATION
3288 static void ResetGfxFrame(int x, int y, boolean redraw)
3290 int element = Feld[x][y];
3291 int graphic = el_act_dir2img(element, GfxAction[x][y], GfxDir[x][y]);
3292 int last_gfx_frame = GfxFrame[x][y];
3294 if (graphic_info[graphic].anim_global_sync)
3295 GfxFrame[x][y] = FrameCounter;
3296 else if (ANIM_MODE(graphic) == ANIM_CE_VALUE)
3297 GfxFrame[x][y] = CustomValue[x][y];
3298 else if (ANIM_MODE(graphic) == ANIM_CE_SCORE)
3299 GfxFrame[x][y] = element_info[element].collect_score;
3300 else if (ANIM_MODE(graphic) == ANIM_CE_DELAY)
3301 GfxFrame[x][y] = ChangeDelay[x][y];
3303 if (redraw && GfxFrame[x][y] != last_gfx_frame)
3304 DrawLevelGraphicAnimation(x, y, graphic);
3308 static void ResetGfxAnimation(int x, int y)
3310 GfxAction[x][y] = ACTION_DEFAULT;
3311 GfxDir[x][y] = MovDir[x][y];
3314 #if USE_GFX_RESET_GFX_ANIMATION
3315 ResetGfxFrame(x, y, FALSE);
3319 static void ResetRandomAnimationValue(int x, int y)
3321 GfxRandom[x][y] = INIT_GFX_RANDOM();
3324 void InitMovingField(int x, int y, int direction)
3326 int element = Feld[x][y];
3327 int dx = (direction == MV_LEFT ? -1 : direction == MV_RIGHT ? +1 : 0);
3328 int dy = (direction == MV_UP ? -1 : direction == MV_DOWN ? +1 : 0);
3331 boolean is_moving_before, is_moving_after;
3333 boolean continues_moving = (WasJustMoving[x][y] && direction == MovDir[x][y]);
3336 /* check if element was/is moving or being moved before/after mode change */
3338 is_moving_before = WasJustMoving[x][y];
3340 is_moving_before = (getElementMoveStepsizeExt(x, y, MovDir[x][y]) != 0);
3342 is_moving_after = (getElementMoveStepsizeExt(x, y, direction) != 0);
3344 /* reset animation only for moving elements which change direction of moving
3345 or which just started or stopped moving
3346 (else CEs with property "can move" / "not moving" are reset each frame) */
3347 #if USE_GFX_RESET_ONLY_WHEN_MOVING
3349 if (is_moving_before != is_moving_after ||
3350 direction != MovDir[x][y])
3351 ResetGfxAnimation(x, y);
3353 if ((is_moving_before || is_moving_after) && !continues_moving)
3354 ResetGfxAnimation(x, y);
3357 if (!continues_moving)
3358 ResetGfxAnimation(x, y);
3361 MovDir[x][y] = direction;
3362 GfxDir[x][y] = direction;
3364 #if USE_GFX_RESET_ONLY_WHEN_MOVING
3365 GfxAction[x][y] = (!is_moving_after ? ACTION_WAITING :
3366 direction == MV_DOWN && CAN_FALL(element) ?
3367 ACTION_FALLING : ACTION_MOVING);
3369 GfxAction[x][y] = (direction == MV_DOWN && CAN_FALL(element) ?
3370 ACTION_FALLING : ACTION_MOVING);
3373 /* this is needed for CEs with property "can move" / "not moving" */
3375 if (is_moving_after)
3377 if (Feld[newx][newy] == EL_EMPTY)
3378 Feld[newx][newy] = EL_BLOCKED;
3380 MovDir[newx][newy] = MovDir[x][y];
3382 #if USE_NEW_CUSTOM_VALUE
3383 CustomValue[newx][newy] = CustomValue[x][y];
3386 GfxFrame[newx][newy] = GfxFrame[x][y];
3387 GfxRandom[newx][newy] = GfxRandom[x][y];
3388 GfxAction[newx][newy] = GfxAction[x][y];
3389 GfxDir[newx][newy] = GfxDir[x][y];
3393 void Moving2Blocked(int x, int y, int *goes_to_x, int *goes_to_y)
3395 int direction = MovDir[x][y];
3396 int newx = x + (direction & MV_LEFT ? -1 : direction & MV_RIGHT ? +1 : 0);
3397 int newy = y + (direction & MV_UP ? -1 : direction & MV_DOWN ? +1 : 0);
3403 void Blocked2Moving(int x, int y, int *comes_from_x, int *comes_from_y)
3405 int oldx = x, oldy = y;
3406 int direction = MovDir[x][y];
3408 if (direction == MV_LEFT)
3410 else if (direction == MV_RIGHT)
3412 else if (direction == MV_UP)
3414 else if (direction == MV_DOWN)
3417 *comes_from_x = oldx;
3418 *comes_from_y = oldy;
3421 int MovingOrBlocked2Element(int x, int y)
3423 int element = Feld[x][y];
3425 if (element == EL_BLOCKED)
3429 Blocked2Moving(x, y, &oldx, &oldy);
3430 return Feld[oldx][oldy];
3436 static int MovingOrBlocked2ElementIfNotLeaving(int x, int y)
3438 /* like MovingOrBlocked2Element(), but if element is moving
3439 and (x,y) is the field the moving element is just leaving,
3440 return EL_BLOCKED instead of the element value */
3441 int element = Feld[x][y];
3443 if (IS_MOVING(x, y))
3445 if (element == EL_BLOCKED)
3449 Blocked2Moving(x, y, &oldx, &oldy);
3450 return Feld[oldx][oldy];
3459 static void RemoveField(int x, int y)
3461 Feld[x][y] = EL_EMPTY;
3467 #if USE_NEW_CUSTOM_VALUE
3468 CustomValue[x][y] = 0;
3472 ChangeDelay[x][y] = 0;
3473 ChangePage[x][y] = -1;
3474 Pushed[x][y] = FALSE;
3477 ExplodeField[x][y] = EX_TYPE_NONE;
3480 GfxElement[x][y] = EL_UNDEFINED;
3481 GfxAction[x][y] = ACTION_DEFAULT;
3482 GfxDir[x][y] = MV_NONE;
3485 void RemoveMovingField(int x, int y)
3487 int oldx = x, oldy = y, newx = x, newy = y;
3488 int element = Feld[x][y];
3489 int next_element = EL_UNDEFINED;
3491 if (element != EL_BLOCKED && !IS_MOVING(x, y))
3494 if (IS_MOVING(x, y))
3496 Moving2Blocked(x, y, &newx, &newy);
3498 if (Feld[newx][newy] != EL_BLOCKED)
3500 /* element is moving, but target field is not free (blocked), but
3501 already occupied by something different (example: acid pool);
3502 in this case, only remove the moving field, but not the target */
3504 RemoveField(oldx, oldy);
3506 Store[oldx][oldy] = Store2[oldx][oldy] = 0;
3508 DrawLevelField(oldx, oldy);
3513 else if (element == EL_BLOCKED)
3515 Blocked2Moving(x, y, &oldx, &oldy);
3516 if (!IS_MOVING(oldx, oldy))
3520 if (element == EL_BLOCKED &&
3521 (Feld[oldx][oldy] == EL_QUICKSAND_EMPTYING ||
3522 Feld[oldx][oldy] == EL_QUICKSAND_FAST_EMPTYING ||
3523 Feld[oldx][oldy] == EL_MAGIC_WALL_EMPTYING ||
3524 Feld[oldx][oldy] == EL_BD_MAGIC_WALL_EMPTYING ||
3525 Feld[oldx][oldy] == EL_DC_MAGIC_WALL_EMPTYING ||
3526 Feld[oldx][oldy] == EL_AMOEBA_DROPPING))
3527 next_element = get_next_element(Feld[oldx][oldy]);
3529 RemoveField(oldx, oldy);
3530 RemoveField(newx, newy);
3532 Store[oldx][oldy] = Store2[oldx][oldy] = 0;
3534 if (next_element != EL_UNDEFINED)
3535 Feld[oldx][oldy] = next_element;
3537 DrawLevelField(oldx, oldy);
3538 DrawLevelField(newx, newy);
3541 void DrawDynamite(int x, int y)
3543 int sx = SCREENX(x), sy = SCREENY(y);
3544 int graphic = el2img(Feld[x][y]);
3547 if (!IN_SCR_FIELD(sx, sy) || IS_PLAYER(x, y))
3550 if (IS_WALKABLE_INSIDE(Back[x][y]))
3554 DrawGraphic(sx, sy, el2img(Back[x][y]), 0);
3555 else if (Store[x][y])
3556 DrawGraphic(sx, sy, el2img(Store[x][y]), 0);
3558 frame = getGraphicAnimationFrame(graphic, GfxFrame[x][y]);
3560 if (Back[x][y] || Store[x][y])
3561 DrawGraphicThruMask(sx, sy, graphic, frame);
3563 DrawGraphic(sx, sy, graphic, frame);
3566 void CheckDynamite(int x, int y)
3568 if (MovDelay[x][y] != 0) /* dynamite is still waiting to explode */
3572 if (MovDelay[x][y] != 0)
3575 PlayLevelSoundActionIfLoop(x, y, ACTION_ACTIVE);
3581 StopLevelSoundActionIfLoop(x, y, ACTION_ACTIVE);
3586 static void setMinimalPlayerBoundaries(int *sx1, int *sy1, int *sx2, int *sy2)
3588 boolean num_checked_players = 0;
3591 for (i = 0; i < MAX_PLAYERS; i++)
3593 if (stored_player[i].active)
3595 int sx = stored_player[i].jx;
3596 int sy = stored_player[i].jy;
3598 if (num_checked_players == 0)
3605 *sx1 = MIN(*sx1, sx);
3606 *sy1 = MIN(*sy1, sy);
3607 *sx2 = MAX(*sx2, sx);
3608 *sy2 = MAX(*sy2, sy);
3611 num_checked_players++;
3616 static boolean checkIfAllPlayersFitToScreen_RND()
3618 int sx1 = 0, sy1 = 0, sx2 = 0, sy2 = 0;
3620 setMinimalPlayerBoundaries(&sx1, &sy1, &sx2, &sy2);
3622 return (sx2 - sx1 < SCR_FIELDX &&
3623 sy2 - sy1 < SCR_FIELDY);
3626 static void setScreenCenteredToAllPlayers(int *sx, int *sy)
3628 int sx1 = scroll_x, sy1 = scroll_y, sx2 = scroll_x, sy2 = scroll_y;
3630 setMinimalPlayerBoundaries(&sx1, &sy1, &sx2, &sy2);
3632 *sx = (sx1 + sx2) / 2;
3633 *sy = (sy1 + sy2) / 2;
3636 void DrawRelocateScreen(int old_x, int old_y, int x, int y, int move_dir,
3637 boolean center_screen, boolean quick_relocation)
3639 boolean ffwd_delay = (tape.playing && tape.fast_forward);
3640 boolean no_delay = (tape.warp_forward);
3641 int frame_delay_value = (ffwd_delay ? FfwdFrameDelay : GameFrameDelay);
3642 int wait_delay_value = (no_delay ? 0 : frame_delay_value);
3644 if (quick_relocation)
3646 int offset = (setup.scroll_delay ? 3 : 0);
3648 if (!IN_VIS_FIELD(SCREENX(x), SCREENY(y)) || center_screen)
3652 scroll_x = (x < SBX_Left + MIDPOSX ? SBX_Left :
3653 x > SBX_Right + MIDPOSX ? SBX_Right :
3656 scroll_y = (y < SBY_Upper + MIDPOSY ? SBY_Upper :
3657 y > SBY_Lower + MIDPOSY ? SBY_Lower :
3662 /* quick relocation (without scrolling), but do not center screen */
3664 int center_scroll_x = (old_x < SBX_Left + MIDPOSX ? SBX_Left :
3665 old_x > SBX_Right + MIDPOSX ? SBX_Right :
3668 int center_scroll_y = (old_y < SBY_Upper + MIDPOSY ? SBY_Upper :
3669 old_y > SBY_Lower + MIDPOSY ? SBY_Lower :
3672 int offset_x = x + (scroll_x - center_scroll_x);
3673 int offset_y = y + (scroll_y - center_scroll_y);
3675 scroll_x = (offset_x < SBX_Left + MIDPOSX ? SBX_Left :
3676 offset_x > SBX_Right + MIDPOSX ? SBX_Right :
3677 offset_x - MIDPOSX);
3679 scroll_y = (offset_y < SBY_Upper + MIDPOSY ? SBY_Upper :
3680 offset_y > SBY_Lower + MIDPOSY ? SBY_Lower :
3681 offset_y - MIDPOSY);
3686 if ((move_dir == MV_LEFT && scroll_x > x - MIDPOSX + offset) ||
3687 (move_dir == MV_RIGHT && scroll_x < x - MIDPOSX - offset))
3688 scroll_x = x - MIDPOSX + (scroll_x < x - MIDPOSX ? -offset : +offset);
3690 if ((move_dir == MV_UP && scroll_y > y - MIDPOSY + offset) ||
3691 (move_dir == MV_DOWN && scroll_y < y - MIDPOSY - offset))
3692 scroll_y = y - MIDPOSY + (scroll_y < y - MIDPOSY ? -offset : +offset);
3694 /* don't scroll over playfield boundaries */
3695 if (scroll_x < SBX_Left || scroll_x > SBX_Right)
3696 scroll_x = (scroll_x < SBX_Left ? SBX_Left : SBX_Right);
3698 /* don't scroll over playfield boundaries */
3699 if (scroll_y < SBY_Upper || scroll_y > SBY_Lower)
3700 scroll_y = (scroll_y < SBY_Upper ? SBY_Upper : SBY_Lower);
3703 RedrawPlayfield(TRUE, 0,0,0,0);
3707 int scroll_xx = (x < SBX_Left + MIDPOSX ? SBX_Left :
3708 x > SBX_Right + MIDPOSX ? SBX_Right :
3711 int scroll_yy = (y < SBY_Upper + MIDPOSY ? SBY_Upper :
3712 y > SBY_Lower + MIDPOSY ? SBY_Lower :
3715 ScrollScreen(NULL, SCROLL_GO_ON); /* scroll last frame to full tile */
3717 while (scroll_x != scroll_xx || scroll_y != scroll_yy)
3720 int fx = FX, fy = FY;
3722 dx = (scroll_xx < scroll_x ? +1 : scroll_xx > scroll_x ? -1 : 0);
3723 dy = (scroll_yy < scroll_y ? +1 : scroll_yy > scroll_y ? -1 : 0);
3725 if (dx == 0 && dy == 0) /* no scrolling needed at all */
3731 fx += dx * TILEX / 2;
3732 fy += dy * TILEY / 2;
3734 ScrollLevel(dx, dy);
3737 /* scroll in two steps of half tile size to make things smoother */
3738 BlitBitmap(drawto_field, window, fx, fy, SXSIZE, SYSIZE, SX, SY);
3740 Delay(wait_delay_value);
3742 /* scroll second step to align at full tile size */
3744 Delay(wait_delay_value);
3749 Delay(wait_delay_value);
3753 void RelocatePlayer(int jx, int jy, int el_player_raw)
3755 int el_player = GET_PLAYER_ELEMENT(el_player_raw);
3756 int player_nr = GET_PLAYER_NR(el_player);
3757 struct PlayerInfo *player = &stored_player[player_nr];
3758 boolean ffwd_delay = (tape.playing && tape.fast_forward);
3759 boolean no_delay = (tape.warp_forward);
3760 int frame_delay_value = (ffwd_delay ? FfwdFrameDelay : GameFrameDelay);
3761 int wait_delay_value = (no_delay ? 0 : frame_delay_value);
3762 int old_jx = player->jx;
3763 int old_jy = player->jy;
3764 int old_element = Feld[old_jx][old_jy];
3765 int element = Feld[jx][jy];
3766 boolean player_relocated = (old_jx != jx || old_jy != jy);
3768 int move_dir_horiz = (jx < old_jx ? MV_LEFT : jx > old_jx ? MV_RIGHT : 0);
3769 int move_dir_vert = (jy < old_jy ? MV_UP : jy > old_jy ? MV_DOWN : 0);
3770 int enter_side_horiz = MV_DIR_OPPOSITE(move_dir_horiz);
3771 int enter_side_vert = MV_DIR_OPPOSITE(move_dir_vert);
3772 int leave_side_horiz = move_dir_horiz;
3773 int leave_side_vert = move_dir_vert;
3774 int enter_side = enter_side_horiz | enter_side_vert;
3775 int leave_side = leave_side_horiz | leave_side_vert;
3777 if (player->GameOver) /* do not reanimate dead player */
3780 if (!player_relocated) /* no need to relocate the player */
3783 if (IS_PLAYER(jx, jy)) /* player already placed at new position */
3785 RemoveField(jx, jy); /* temporarily remove newly placed player */
3786 DrawLevelField(jx, jy);
3789 if (player->present)
3791 while (player->MovPos)
3793 ScrollPlayer(player, SCROLL_GO_ON);
3794 ScrollScreen(NULL, SCROLL_GO_ON);
3796 AdvanceFrameAndPlayerCounters(player->index_nr);
3801 Delay(wait_delay_value);
3804 DrawPlayer(player); /* needed here only to cleanup last field */
3805 DrawLevelField(player->jx, player->jy); /* remove player graphic */
3807 player->is_moving = FALSE;
3810 if (IS_CUSTOM_ELEMENT(old_element))
3811 CheckElementChangeByPlayer(old_jx, old_jy, old_element,
3813 player->index_bit, leave_side);
3815 CheckTriggeredElementChangeByPlayer(old_jx, old_jy, old_element,
3817 player->index_bit, leave_side);
3819 Feld[jx][jy] = el_player;
3820 InitPlayerField(jx, jy, el_player, TRUE);
3822 if (!ELEM_IS_PLAYER(element)) /* player may be set on walkable element */
3824 Feld[jx][jy] = element;
3825 InitField(jx, jy, FALSE);
3828 /* only visually relocate centered player */
3829 DrawRelocateScreen(old_jx, old_jy, player->jx, player->jy, player->MovDir,
3830 FALSE, level.instant_relocation);
3832 TestIfPlayerTouchesBadThing(jx, jy);
3833 TestIfPlayerTouchesCustomElement(jx, jy);
3835 if (IS_CUSTOM_ELEMENT(element))
3836 CheckElementChangeByPlayer(jx, jy, element, CE_ENTERED_BY_PLAYER,
3837 player->index_bit, enter_side);
3839 CheckTriggeredElementChangeByPlayer(jx, jy, element, CE_PLAYER_ENTERS_X,
3840 player->index_bit, enter_side);
3843 void Explode(int ex, int ey, int phase, int mode)
3849 /* !!! eliminate this variable !!! */
3850 int delay = (game.emulation == EMU_SUPAPLEX ? 3 : 2);
3852 if (game.explosions_delayed)
3854 ExplodeField[ex][ey] = mode;
3858 if (phase == EX_PHASE_START) /* initialize 'Store[][]' field */
3860 int center_element = Feld[ex][ey];
3861 int artwork_element, explosion_element; /* set these values later */
3864 /* --- This is only really needed (and now handled) in "Impact()". --- */
3865 /* do not explode moving elements that left the explode field in time */
3866 if (game.engine_version >= VERSION_IDENT(2,2,0,7) &&
3867 center_element == EL_EMPTY &&
3868 (mode == EX_TYPE_NORMAL || mode == EX_TYPE_CENTER))
3873 /* !!! at this place, the center element may be EL_BLOCKED !!! */
3874 if (mode == EX_TYPE_NORMAL ||
3875 mode == EX_TYPE_CENTER ||
3876 mode == EX_TYPE_CROSS)
3877 PlayLevelSoundElementAction(ex, ey, artwork_element, ACTION_EXPLODING);
3880 /* remove things displayed in background while burning dynamite */
3881 if (Back[ex][ey] != EL_EMPTY && !IS_INDESTRUCTIBLE(Back[ex][ey]))
3884 if (IS_MOVING(ex, ey) || IS_BLOCKED(ex, ey))
3886 /* put moving element to center field (and let it explode there) */
3887 center_element = MovingOrBlocked2Element(ex, ey);
3888 RemoveMovingField(ex, ey);
3889 Feld[ex][ey] = center_element;
3892 /* now "center_element" is finally determined -- set related values now */
3893 artwork_element = center_element; /* for custom player artwork */
3894 explosion_element = center_element; /* for custom player artwork */
3896 if (IS_PLAYER(ex, ey))
3898 int player_nr = GET_PLAYER_NR(StorePlayer[ex][ey]);
3900 artwork_element = stored_player[player_nr].artwork_element;
3902 if (level.use_explosion_element[player_nr])
3904 explosion_element = level.explosion_element[player_nr];
3905 artwork_element = explosion_element;
3910 if (mode == EX_TYPE_NORMAL ||
3911 mode == EX_TYPE_CENTER ||
3912 mode == EX_TYPE_CROSS)
3913 PlayLevelSoundElementAction(ex, ey, artwork_element, ACTION_EXPLODING);
3916 last_phase = element_info[explosion_element].explosion_delay + 1;
3918 for (y = ey - 1; y <= ey + 1; y++) for (x = ex - 1; x <= ex + 1; x++)
3920 int xx = x - ex + 1;
3921 int yy = y - ey + 1;
3924 if (!IN_LEV_FIELD(x, y) ||
3925 (mode & EX_TYPE_SINGLE_TILE && (x != ex || y != ey)) ||
3926 (mode == EX_TYPE_CROSS && (x != ex && y != ey)))
3929 element = Feld[x][y];
3931 if (IS_MOVING(x, y) || IS_BLOCKED(x, y))
3933 element = MovingOrBlocked2Element(x, y);
3935 if (!IS_EXPLOSION_PROOF(element))
3936 RemoveMovingField(x, y);
3939 /* indestructible elements can only explode in center (but not flames) */
3940 if ((IS_EXPLOSION_PROOF(element) && (x != ex || y != ey ||
3941 mode == EX_TYPE_BORDER)) ||
3942 element == EL_FLAMES)
3945 /* no idea why this was changed from 3.0.8 to 3.1.0 -- this causes buggy
3946 behaviour, for example when touching a yamyam that explodes to rocks
3947 with active deadly shield, a rock is created under the player !!! */
3948 /* (case 1 (surely buggy): >= 3.1.0, case 2 (maybe buggy): <= 3.0.8) */
3950 if (IS_PLAYER(x, y) && SHIELD_ON(PLAYERINFO(x, y)) &&
3951 (game.engine_version < VERSION_IDENT(3,1,0,0) ||
3952 (x == ex && y == ey && mode != EX_TYPE_BORDER)))
3954 if (IS_PLAYER(x, y) && SHIELD_ON(PLAYERINFO(x, y)))
3957 if (IS_ACTIVE_BOMB(element))
3959 /* re-activate things under the bomb like gate or penguin */
3960 Feld[x][y] = (Back[x][y] ? Back[x][y] : EL_EMPTY);
3967 /* save walkable background elements while explosion on same tile */
3968 if (IS_WALKABLE(element) && IS_INDESTRUCTIBLE(element) &&
3969 (x != ex || y != ey || mode == EX_TYPE_BORDER))
3970 Back[x][y] = element;
3972 /* ignite explodable elements reached by other explosion */
3973 if (element == EL_EXPLOSION)
3974 element = Store2[x][y];
3976 if (AmoebaNr[x][y] &&
3977 (element == EL_AMOEBA_FULL ||
3978 element == EL_BD_AMOEBA ||
3979 element == EL_AMOEBA_GROWING))
3981 AmoebaCnt[AmoebaNr[x][y]]--;
3982 AmoebaCnt2[AmoebaNr[x][y]]--;
3987 if (IS_PLAYER(ex, ey) && !PLAYER_EXPLOSION_PROTECTED(ex, ey))
3989 int player_nr = StorePlayer[ex][ey] - EL_PLAYER_1;
3991 Store[x][y] = EL_PLAYER_IS_EXPLODING_1 + player_nr;
3993 if (PLAYERINFO(ex, ey)->use_murphy)
3994 Store[x][y] = EL_EMPTY;
3997 /* !!! check this case -- currently needed for rnd_rado_negundo_v,
3998 !!! levels 015 018 019 020 021 022 023 026 027 028 !!! */
3999 else if (ELEM_IS_PLAYER(center_element))
4000 Store[x][y] = EL_EMPTY;
4001 else if (center_element == EL_YAMYAM)
4002 Store[x][y] = level.yamyam_content[game.yamyam_content_nr].e[xx][yy];
4003 else if (element_info[center_element].content.e[xx][yy] != EL_EMPTY)
4004 Store[x][y] = element_info[center_element].content.e[xx][yy];
4006 /* needed because EL_BD_BUTTERFLY is not defined as "CAN_EXPLODE"
4007 (killing EL_BD_BUTTERFLY with dynamite would result in BD diamond
4008 otherwise) -- FIX THIS !!! */
4009 else if (!CAN_EXPLODE(element) && element != EL_BD_BUTTERFLY)
4010 Store[x][y] = element_info[element].content.e[1][1];
4012 else if (!CAN_EXPLODE(element))
4013 Store[x][y] = element_info[element].content.e[1][1];
4016 Store[x][y] = EL_EMPTY;
4018 if (x != ex || y != ey || mode == EX_TYPE_BORDER ||
4019 center_element == EL_AMOEBA_TO_DIAMOND)
4020 Store2[x][y] = element;
4022 Feld[x][y] = EL_EXPLOSION;
4023 GfxElement[x][y] = artwork_element;
4025 ExplodePhase[x][y] = 1;
4026 ExplodeDelay[x][y] = last_phase;
4031 if (center_element == EL_YAMYAM)
4032 game.yamyam_content_nr =
4033 (game.yamyam_content_nr + 1) % level.num_yamyam_contents;
4045 GfxFrame[x][y] = 0; /* restart explosion animation */
4047 last_phase = ExplodeDelay[x][y];
4049 ExplodePhase[x][y] = (phase < last_phase ? phase + 1 : 0);
4053 /* activate this even in non-DEBUG version until cause for crash in
4054 getGraphicAnimationFrame() (see below) is found and eliminated */
4060 /* this can happen if the player leaves an explosion just in time */
4061 if (GfxElement[x][y] == EL_UNDEFINED)
4062 GfxElement[x][y] = EL_EMPTY;
4064 if (GfxElement[x][y] == EL_UNDEFINED)
4067 printf("Explode(): x = %d, y = %d: GfxElement == EL_UNDEFINED\n", x, y);
4068 printf("Explode(): This should never happen!\n");
4071 GfxElement[x][y] = EL_EMPTY;
4077 border_element = Store2[x][y];
4078 if (IS_PLAYER(x, y) && !PLAYER_EXPLOSION_PROTECTED(x, y))
4079 border_element = StorePlayer[x][y];
4081 if (phase == element_info[border_element].ignition_delay ||
4082 phase == last_phase)
4084 boolean border_explosion = FALSE;
4086 if (IS_PLAYER(x, y) && PLAYERINFO(x, y)->present &&
4087 !PLAYER_EXPLOSION_PROTECTED(x, y))
4089 KillPlayerUnlessExplosionProtected(x, y);
4090 border_explosion = TRUE;
4092 else if (CAN_EXPLODE_BY_EXPLOSION(border_element))
4094 Feld[x][y] = Store2[x][y];
4097 border_explosion = TRUE;
4099 else if (border_element == EL_AMOEBA_TO_DIAMOND)
4101 AmoebeUmwandeln(x, y);
4103 border_explosion = TRUE;
4106 /* if an element just explodes due to another explosion (chain-reaction),
4107 do not immediately end the new explosion when it was the last frame of
4108 the explosion (as it would be done in the following "if"-statement!) */
4109 if (border_explosion && phase == last_phase)
4113 if (phase == last_phase)
4117 element = Feld[x][y] = Store[x][y];
4118 Store[x][y] = Store2[x][y] = 0;
4119 GfxElement[x][y] = EL_UNDEFINED;
4121 /* player can escape from explosions and might therefore be still alive */
4122 if (element >= EL_PLAYER_IS_EXPLODING_1 &&
4123 element <= EL_PLAYER_IS_EXPLODING_4)
4125 int player_nr = element - EL_PLAYER_IS_EXPLODING_1;
4126 int explosion_element = EL_PLAYER_1 + player_nr;
4127 int xx = MIN(MAX(0, x - stored_player[player_nr].jx + 1), 2);
4128 int yy = MIN(MAX(0, y - stored_player[player_nr].jy + 1), 2);
4130 if (level.use_explosion_element[player_nr])
4131 explosion_element = level.explosion_element[player_nr];
4133 Feld[x][y] = (stored_player[player_nr].active ? EL_EMPTY :
4134 element_info[explosion_element].content.e[xx][yy]);
4137 /* restore probably existing indestructible background element */
4138 if (Back[x][y] && IS_INDESTRUCTIBLE(Back[x][y]))
4139 element = Feld[x][y] = Back[x][y];
4142 MovDir[x][y] = MovPos[x][y] = MovDelay[x][y] = 0;
4143 GfxDir[x][y] = MV_NONE;
4144 ChangeDelay[x][y] = 0;
4145 ChangePage[x][y] = -1;
4147 #if USE_NEW_CUSTOM_VALUE
4148 CustomValue[x][y] = 0;
4151 InitField_WithBug2(x, y, FALSE);
4153 DrawLevelField(x, y);
4155 TestIfElementTouchesCustomElement(x, y);
4157 if (GFX_CRUMBLED(element))
4158 DrawLevelFieldCrumbledSandNeighbours(x, y);
4160 if (IS_PLAYER(x, y) && !PLAYERINFO(x, y)->present)
4161 StorePlayer[x][y] = 0;
4163 if (ELEM_IS_PLAYER(element))
4164 RelocatePlayer(x, y, element);
4166 else if (IN_SCR_FIELD(SCREENX(x), SCREENY(y)))
4168 int graphic = el_act2img(GfxElement[x][y], ACTION_EXPLODING);
4169 int frame = getGraphicAnimationFrame(graphic, GfxFrame[x][y]);
4172 DrawLevelFieldCrumbledSand(x, y);
4174 if (IS_WALKABLE_OVER(Back[x][y]) && Back[x][y] != EL_EMPTY)
4176 DrawLevelElement(x, y, Back[x][y]);
4177 DrawGraphicThruMask(SCREENX(x), SCREENY(y), graphic, frame);
4179 else if (IS_WALKABLE_UNDER(Back[x][y]))
4181 DrawGraphic(SCREENX(x), SCREENY(y), graphic, frame);
4182 DrawLevelElementThruMask(x, y, Back[x][y]);
4184 else if (!IS_WALKABLE_INSIDE(Back[x][y]))
4185 DrawGraphic(SCREENX(x), SCREENY(y), graphic, frame);
4189 void DynaExplode(int ex, int ey)
4192 int dynabomb_element = Feld[ex][ey];
4193 int dynabomb_size = 1;
4194 boolean dynabomb_xl = FALSE;
4195 struct PlayerInfo *player;
4196 static int xy[4][2] =
4204 if (IS_ACTIVE_BOMB(dynabomb_element))
4206 player = &stored_player[dynabomb_element - EL_DYNABOMB_PLAYER_1_ACTIVE];
4207 dynabomb_size = player->dynabomb_size;
4208 dynabomb_xl = player->dynabomb_xl;
4209 player->dynabombs_left++;
4212 Explode(ex, ey, EX_PHASE_START, EX_TYPE_CENTER);
4214 for (i = 0; i < NUM_DIRECTIONS; i++)
4216 for (j = 1; j <= dynabomb_size; j++)
4218 int x = ex + j * xy[i][0];
4219 int y = ey + j * xy[i][1];
4222 if (!IN_LEV_FIELD(x, y) || IS_INDESTRUCTIBLE(Feld[x][y]))
4225 element = Feld[x][y];
4227 /* do not restart explosions of fields with active bombs */
4228 if (element == EL_EXPLOSION && IS_ACTIVE_BOMB(Store2[x][y]))
4231 Explode(x, y, EX_PHASE_START, EX_TYPE_BORDER);
4233 if (element != EL_EMPTY && element != EL_EXPLOSION &&
4234 !IS_DIGGABLE(element) && !dynabomb_xl)
4240 void Bang(int x, int y)
4242 int element = MovingOrBlocked2Element(x, y);
4243 int explosion_type = EX_TYPE_NORMAL;
4245 if (IS_PLAYER(x, y) && !PLAYER_EXPLOSION_PROTECTED(x, y))
4247 struct PlayerInfo *player = PLAYERINFO(x, y);
4249 element = Feld[x][y] = (player->use_murphy ? EL_SP_MURPHY :
4250 player->element_nr);
4252 if (level.use_explosion_element[player->index_nr])
4254 int explosion_element = level.explosion_element[player->index_nr];
4256 if (element_info[explosion_element].explosion_type == EXPLODES_CROSS)
4257 explosion_type = EX_TYPE_CROSS;
4258 else if (element_info[explosion_element].explosion_type == EXPLODES_1X1)
4259 explosion_type = EX_TYPE_CENTER;
4267 case EL_BD_BUTTERFLY:
4270 case EL_DARK_YAMYAM:
4274 RaiseScoreElement(element);
4277 case EL_DYNABOMB_PLAYER_1_ACTIVE:
4278 case EL_DYNABOMB_PLAYER_2_ACTIVE:
4279 case EL_DYNABOMB_PLAYER_3_ACTIVE:
4280 case EL_DYNABOMB_PLAYER_4_ACTIVE:
4281 case EL_DYNABOMB_INCREASE_NUMBER:
4282 case EL_DYNABOMB_INCREASE_SIZE:
4283 case EL_DYNABOMB_INCREASE_POWER:
4284 explosion_type = EX_TYPE_DYNA;
4287 case EL_DC_LANDMINE:
4289 case EL_EM_EXIT_OPEN:
4290 case EL_EM_STEEL_EXIT_OPEN:
4292 explosion_type = EX_TYPE_CENTER;
4297 case EL_LAMP_ACTIVE:
4298 case EL_AMOEBA_TO_DIAMOND:
4299 if (!IS_PLAYER(x, y)) /* penguin and player may be at same field */
4300 explosion_type = EX_TYPE_CENTER;
4304 if (element_info[element].explosion_type == EXPLODES_CROSS)
4305 explosion_type = EX_TYPE_CROSS;
4306 else if (element_info[element].explosion_type == EXPLODES_1X1)
4307 explosion_type = EX_TYPE_CENTER;
4311 if (explosion_type == EX_TYPE_DYNA)
4314 Explode(x, y, EX_PHASE_START, explosion_type);
4316 CheckTriggeredElementChange(x, y, element, CE_EXPLOSION_OF_X);
4319 void SplashAcid(int x, int y)
4321 if (IN_LEV_FIELD(x - 1, y - 1) && IS_FREE(x - 1, y - 1) &&
4322 (!IN_LEV_FIELD(x - 1, y - 2) ||
4323 !CAN_FALL(MovingOrBlocked2Element(x - 1, y - 2))))
4324 Feld[x - 1][y - 1] = EL_ACID_SPLASH_LEFT;
4326 if (IN_LEV_FIELD(x + 1, y - 1) && IS_FREE(x + 1, y - 1) &&
4327 (!IN_LEV_FIELD(x + 1, y - 2) ||
4328 !CAN_FALL(MovingOrBlocked2Element(x + 1, y - 2))))
4329 Feld[x + 1][y - 1] = EL_ACID_SPLASH_RIGHT;
4331 PlayLevelSound(x, y, SND_ACID_SPLASHING);
4334 static void InitBeltMovement()
4336 static int belt_base_element[4] =
4338 EL_CONVEYOR_BELT_1_LEFT,
4339 EL_CONVEYOR_BELT_2_LEFT,
4340 EL_CONVEYOR_BELT_3_LEFT,
4341 EL_CONVEYOR_BELT_4_LEFT
4343 static int belt_base_active_element[4] =
4345 EL_CONVEYOR_BELT_1_LEFT_ACTIVE,
4346 EL_CONVEYOR_BELT_2_LEFT_ACTIVE,
4347 EL_CONVEYOR_BELT_3_LEFT_ACTIVE,
4348 EL_CONVEYOR_BELT_4_LEFT_ACTIVE
4353 /* set frame order for belt animation graphic according to belt direction */
4354 for (i = 0; i < NUM_BELTS; i++)
4358 for (j = 0; j < NUM_BELT_PARTS; j++)
4360 int element = belt_base_active_element[belt_nr] + j;
4361 int graphic = el2img(element);
4363 if (game.belt_dir[i] == MV_LEFT)
4364 graphic_info[graphic].anim_mode &= ~ANIM_REVERSE;
4366 graphic_info[graphic].anim_mode |= ANIM_REVERSE;
4370 SCAN_PLAYFIELD(x, y)
4372 int element = Feld[x][y];
4374 for (i = 0; i < NUM_BELTS; i++)
4376 if (IS_BELT(element) && game.belt_dir[i] != MV_NONE)
4378 int e_belt_nr = getBeltNrFromBeltElement(element);
4381 if (e_belt_nr == belt_nr)
4383 int belt_part = Feld[x][y] - belt_base_element[belt_nr];
4385 Feld[x][y] = belt_base_active_element[belt_nr] + belt_part;
4392 static void ToggleBeltSwitch(int x, int y)
4394 static int belt_base_element[4] =
4396 EL_CONVEYOR_BELT_1_LEFT,
4397 EL_CONVEYOR_BELT_2_LEFT,
4398 EL_CONVEYOR_BELT_3_LEFT,
4399 EL_CONVEYOR_BELT_4_LEFT
4401 static int belt_base_active_element[4] =
4403 EL_CONVEYOR_BELT_1_LEFT_ACTIVE,
4404 EL_CONVEYOR_BELT_2_LEFT_ACTIVE,
4405 EL_CONVEYOR_BELT_3_LEFT_ACTIVE,
4406 EL_CONVEYOR_BELT_4_LEFT_ACTIVE
4408 static int belt_base_switch_element[4] =
4410 EL_CONVEYOR_BELT_1_SWITCH_LEFT,
4411 EL_CONVEYOR_BELT_2_SWITCH_LEFT,
4412 EL_CONVEYOR_BELT_3_SWITCH_LEFT,
4413 EL_CONVEYOR_BELT_4_SWITCH_LEFT
4415 static int belt_move_dir[4] =
4423 int element = Feld[x][y];
4424 int belt_nr = getBeltNrFromBeltSwitchElement(element);
4425 int belt_dir_nr = (game.belt_dir_nr[belt_nr] + 1) % 4;
4426 int belt_dir = belt_move_dir[belt_dir_nr];
4429 if (!IS_BELT_SWITCH(element))
4432 game.belt_dir_nr[belt_nr] = belt_dir_nr;
4433 game.belt_dir[belt_nr] = belt_dir;
4435 if (belt_dir_nr == 3)
4438 /* set frame order for belt animation graphic according to belt direction */
4439 for (i = 0; i < NUM_BELT_PARTS; i++)
4441 int element = belt_base_active_element[belt_nr] + i;
4442 int graphic = el2img(element);
4444 if (belt_dir == MV_LEFT)
4445 graphic_info[graphic].anim_mode &= ~ANIM_REVERSE;
4447 graphic_info[graphic].anim_mode |= ANIM_REVERSE;
4450 SCAN_PLAYFIELD(xx, yy)
4452 int element = Feld[xx][yy];
4454 if (IS_BELT_SWITCH(element))
4456 int e_belt_nr = getBeltNrFromBeltSwitchElement(element);
4458 if (e_belt_nr == belt_nr)
4460 Feld[xx][yy] = belt_base_switch_element[belt_nr] + belt_dir_nr;
4461 DrawLevelField(xx, yy);
4464 else if (IS_BELT(element) && belt_dir != MV_NONE)
4466 int e_belt_nr = getBeltNrFromBeltElement(element);
4468 if (e_belt_nr == belt_nr)
4470 int belt_part = Feld[xx][yy] - belt_base_element[belt_nr];
4472 Feld[xx][yy] = belt_base_active_element[belt_nr] + belt_part;
4473 DrawLevelField(xx, yy);
4476 else if (IS_BELT_ACTIVE(element) && belt_dir == MV_NONE)
4478 int e_belt_nr = getBeltNrFromBeltActiveElement(element);
4480 if (e_belt_nr == belt_nr)
4482 int belt_part = Feld[xx][yy] - belt_base_active_element[belt_nr];
4484 Feld[xx][yy] = belt_base_element[belt_nr] + belt_part;
4485 DrawLevelField(xx, yy);
4491 static void ToggleSwitchgateSwitch(int x, int y)
4495 game.switchgate_pos = !game.switchgate_pos;
4497 SCAN_PLAYFIELD(xx, yy)
4499 int element = Feld[xx][yy];
4501 #if !USE_BOTH_SWITCHGATE_SWITCHES
4502 if (element == EL_SWITCHGATE_SWITCH_UP ||
4503 element == EL_SWITCHGATE_SWITCH_DOWN)
4505 Feld[xx][yy] = EL_SWITCHGATE_SWITCH_UP + game.switchgate_pos;
4506 DrawLevelField(xx, yy);
4508 else if (element == EL_DC_SWITCHGATE_SWITCH_UP ||
4509 element == EL_DC_SWITCHGATE_SWITCH_DOWN)
4511 Feld[xx][yy] = EL_DC_SWITCHGATE_SWITCH_UP + game.switchgate_pos;
4512 DrawLevelField(xx, yy);
4515 if (element == EL_SWITCHGATE_SWITCH_UP)
4517 Feld[xx][yy] = EL_SWITCHGATE_SWITCH_DOWN;
4518 DrawLevelField(xx, yy);
4520 else if (element == EL_SWITCHGATE_SWITCH_DOWN)
4522 Feld[xx][yy] = EL_SWITCHGATE_SWITCH_UP;
4523 DrawLevelField(xx, yy);
4525 else if (element == EL_DC_SWITCHGATE_SWITCH_UP)
4527 Feld[xx][yy] = EL_DC_SWITCHGATE_SWITCH_DOWN;
4528 DrawLevelField(xx, yy);
4530 else if (element == EL_DC_SWITCHGATE_SWITCH_DOWN)
4532 Feld[xx][yy] = EL_DC_SWITCHGATE_SWITCH_UP;
4533 DrawLevelField(xx, yy);
4536 else if (element == EL_SWITCHGATE_OPEN ||
4537 element == EL_SWITCHGATE_OPENING)
4539 Feld[xx][yy] = EL_SWITCHGATE_CLOSING;
4541 PlayLevelSoundAction(xx, yy, ACTION_CLOSING);
4543 else if (element == EL_SWITCHGATE_CLOSED ||
4544 element == EL_SWITCHGATE_CLOSING)
4546 Feld[xx][yy] = EL_SWITCHGATE_OPENING;
4548 PlayLevelSoundAction(xx, yy, ACTION_OPENING);
4553 static int getInvisibleActiveFromInvisibleElement(int element)
4555 return (element == EL_INVISIBLE_STEELWALL ? EL_INVISIBLE_STEELWALL_ACTIVE :
4556 element == EL_INVISIBLE_WALL ? EL_INVISIBLE_WALL_ACTIVE :
4557 element == EL_INVISIBLE_SAND ? EL_INVISIBLE_SAND_ACTIVE :
4561 static int getInvisibleFromInvisibleActiveElement(int element)
4563 return (element == EL_INVISIBLE_STEELWALL_ACTIVE ? EL_INVISIBLE_STEELWALL :
4564 element == EL_INVISIBLE_WALL_ACTIVE ? EL_INVISIBLE_WALL :
4565 element == EL_INVISIBLE_SAND_ACTIVE ? EL_INVISIBLE_SAND :
4569 static void RedrawAllLightSwitchesAndInvisibleElements()
4573 SCAN_PLAYFIELD(x, y)
4575 int element = Feld[x][y];
4577 if (element == EL_LIGHT_SWITCH &&
4578 game.light_time_left > 0)
4580 Feld[x][y] = EL_LIGHT_SWITCH_ACTIVE;
4581 DrawLevelField(x, y);
4583 else if (element == EL_LIGHT_SWITCH_ACTIVE &&
4584 game.light_time_left == 0)
4586 Feld[x][y] = EL_LIGHT_SWITCH;
4587 DrawLevelField(x, y);
4589 else if (element == EL_EMC_DRIPPER &&
4590 game.light_time_left > 0)
4592 Feld[x][y] = EL_EMC_DRIPPER_ACTIVE;
4593 DrawLevelField(x, y);
4595 else if (element == EL_EMC_DRIPPER_ACTIVE &&
4596 game.light_time_left == 0)
4598 Feld[x][y] = EL_EMC_DRIPPER;
4599 DrawLevelField(x, y);
4601 else if (element == EL_INVISIBLE_STEELWALL ||
4602 element == EL_INVISIBLE_WALL ||
4603 element == EL_INVISIBLE_SAND)
4605 if (game.light_time_left > 0)
4606 Feld[x][y] = getInvisibleActiveFromInvisibleElement(element);
4608 DrawLevelField(x, y);
4610 /* uncrumble neighbour fields, if needed */
4611 if (element == EL_INVISIBLE_SAND)
4612 DrawLevelFieldCrumbledSandNeighbours(x, y);
4614 else if (element == EL_INVISIBLE_STEELWALL_ACTIVE ||
4615 element == EL_INVISIBLE_WALL_ACTIVE ||
4616 element == EL_INVISIBLE_SAND_ACTIVE)
4618 if (game.light_time_left == 0)
4619 Feld[x][y] = getInvisibleFromInvisibleActiveElement(element);
4621 DrawLevelField(x, y);
4623 /* re-crumble neighbour fields, if needed */
4624 if (element == EL_INVISIBLE_SAND)
4625 DrawLevelFieldCrumbledSandNeighbours(x, y);
4630 static void RedrawAllInvisibleElementsForLenses()
4634 SCAN_PLAYFIELD(x, y)
4636 int element = Feld[x][y];
4638 if (element == EL_EMC_DRIPPER &&
4639 game.lenses_time_left > 0)
4641 Feld[x][y] = EL_EMC_DRIPPER_ACTIVE;
4642 DrawLevelField(x, y);
4644 else if (element == EL_EMC_DRIPPER_ACTIVE &&
4645 game.lenses_time_left == 0)
4647 Feld[x][y] = EL_EMC_DRIPPER;
4648 DrawLevelField(x, y);
4650 else if (element == EL_INVISIBLE_STEELWALL ||
4651 element == EL_INVISIBLE_WALL ||
4652 element == EL_INVISIBLE_SAND)
4654 if (game.lenses_time_left > 0)
4655 Feld[x][y] = getInvisibleActiveFromInvisibleElement(element);
4657 DrawLevelField(x, y);
4659 /* uncrumble neighbour fields, if needed */
4660 if (element == EL_INVISIBLE_SAND)
4661 DrawLevelFieldCrumbledSandNeighbours(x, y);
4663 else if (element == EL_INVISIBLE_STEELWALL_ACTIVE ||
4664 element == EL_INVISIBLE_WALL_ACTIVE ||
4665 element == EL_INVISIBLE_SAND_ACTIVE)
4667 if (game.lenses_time_left == 0)
4668 Feld[x][y] = getInvisibleFromInvisibleActiveElement(element);
4670 DrawLevelField(x, y);
4672 /* re-crumble neighbour fields, if needed */
4673 if (element == EL_INVISIBLE_SAND)
4674 DrawLevelFieldCrumbledSandNeighbours(x, y);
4679 static void RedrawAllInvisibleElementsForMagnifier()
4683 SCAN_PLAYFIELD(x, y)
4685 int element = Feld[x][y];
4687 if (element == EL_EMC_FAKE_GRASS &&
4688 game.magnify_time_left > 0)
4690 Feld[x][y] = EL_EMC_FAKE_GRASS_ACTIVE;
4691 DrawLevelField(x, y);
4693 else if (element == EL_EMC_FAKE_GRASS_ACTIVE &&
4694 game.magnify_time_left == 0)
4696 Feld[x][y] = EL_EMC_FAKE_GRASS;
4697 DrawLevelField(x, y);
4699 else if (IS_GATE_GRAY(element) &&
4700 game.magnify_time_left > 0)
4702 Feld[x][y] = (IS_RND_GATE_GRAY(element) ?
4703 element - EL_GATE_1_GRAY + EL_GATE_1_GRAY_ACTIVE :
4704 IS_EM_GATE_GRAY(element) ?
4705 element - EL_EM_GATE_1_GRAY + EL_EM_GATE_1_GRAY_ACTIVE :
4706 IS_EMC_GATE_GRAY(element) ?
4707 element - EL_EMC_GATE_5_GRAY + EL_EMC_GATE_5_GRAY_ACTIVE :
4709 DrawLevelField(x, y);
4711 else if (IS_GATE_GRAY_ACTIVE(element) &&
4712 game.magnify_time_left == 0)
4714 Feld[x][y] = (IS_RND_GATE_GRAY_ACTIVE(element) ?
4715 element - EL_GATE_1_GRAY_ACTIVE + EL_GATE_1_GRAY :
4716 IS_EM_GATE_GRAY_ACTIVE(element) ?
4717 element - EL_EM_GATE_1_GRAY_ACTIVE + EL_EM_GATE_1_GRAY :
4718 IS_EMC_GATE_GRAY_ACTIVE(element) ?
4719 element - EL_EMC_GATE_5_GRAY_ACTIVE + EL_EMC_GATE_5_GRAY :
4721 DrawLevelField(x, y);
4726 static void ToggleLightSwitch(int x, int y)
4728 int element = Feld[x][y];
4730 game.light_time_left =
4731 (element == EL_LIGHT_SWITCH ?
4732 level.time_light * FRAMES_PER_SECOND : 0);
4734 RedrawAllLightSwitchesAndInvisibleElements();
4737 static void ActivateTimegateSwitch(int x, int y)
4741 game.timegate_time_left = level.time_timegate * FRAMES_PER_SECOND;
4743 SCAN_PLAYFIELD(xx, yy)
4745 int element = Feld[xx][yy];
4747 if (element == EL_TIMEGATE_CLOSED ||
4748 element == EL_TIMEGATE_CLOSING)
4750 Feld[xx][yy] = EL_TIMEGATE_OPENING;
4751 PlayLevelSound(xx, yy, SND_CLASS_TIMEGATE_OPENING);
4755 else if (element == EL_TIMEGATE_SWITCH_ACTIVE)
4757 Feld[xx][yy] = EL_TIMEGATE_SWITCH;
4758 DrawLevelField(xx, yy);
4765 Feld[x][y] = (Feld[x][y] == EL_TIMEGATE_SWITCH ? EL_TIMEGATE_SWITCH_ACTIVE :
4766 EL_DC_TIMEGATE_SWITCH_ACTIVE);
4768 Feld[x][y] = EL_TIMEGATE_SWITCH_ACTIVE;
4772 void Impact(int x, int y)
4774 boolean last_line = (y == lev_fieldy - 1);
4775 boolean object_hit = FALSE;
4776 boolean impact = (last_line || object_hit);
4777 int element = Feld[x][y];
4778 int smashed = EL_STEELWALL;
4780 if (!last_line) /* check if element below was hit */
4782 if (Feld[x][y + 1] == EL_PLAYER_IS_LEAVING)
4785 object_hit = (!IS_FREE(x, y + 1) && (!IS_MOVING(x, y + 1) ||
4786 MovDir[x][y + 1] != MV_DOWN ||
4787 MovPos[x][y + 1] <= TILEY / 2));
4789 /* do not smash moving elements that left the smashed field in time */
4790 if (game.engine_version >= VERSION_IDENT(2,2,0,7) && IS_MOVING(x, y + 1) &&
4791 ABS(MovPos[x][y + 1] + getElementMoveStepsize(x, y + 1)) >= TILEX)
4794 #if USE_QUICKSAND_IMPACT_BUGFIX
4795 if (Feld[x][y + 1] == EL_QUICKSAND_EMPTYING && object_hit == FALSE)
4797 RemoveMovingField(x, y + 1);
4798 Feld[x][y + 1] = EL_QUICKSAND_EMPTY;
4799 Feld[x][y + 2] = EL_ROCK;
4800 DrawLevelField(x, y + 2);
4805 if (Feld[x][y + 1] == EL_QUICKSAND_FAST_EMPTYING && object_hit == FALSE)
4807 RemoveMovingField(x, y + 1);
4808 Feld[x][y + 1] = EL_QUICKSAND_FAST_EMPTY;
4809 Feld[x][y + 2] = EL_ROCK;
4810 DrawLevelField(x, y + 2);
4817 smashed = MovingOrBlocked2Element(x, y + 1);
4819 impact = (last_line || object_hit);
4822 if (!last_line && smashed == EL_ACID) /* element falls into acid */
4824 SplashAcid(x, y + 1);
4828 /* !!! not sufficient for all cases -- see EL_PEARL below !!! */
4829 /* only reset graphic animation if graphic really changes after impact */
4831 el_act_dir2img(element, GfxAction[x][y], MV_DOWN) != el2img(element))
4833 ResetGfxAnimation(x, y);
4834 DrawLevelField(x, y);
4837 if (impact && CAN_EXPLODE_IMPACT(element))
4842 else if (impact && element == EL_PEARL &&
4843 smashed != EL_DC_MAGIC_WALL && smashed != EL_DC_MAGIC_WALL_ACTIVE)
4845 ResetGfxAnimation(x, y);
4847 Feld[x][y] = EL_PEARL_BREAKING;
4848 PlayLevelSound(x, y, SND_PEARL_BREAKING);
4851 else if (impact && CheckElementChange(x, y, element, smashed, CE_IMPACT))
4853 PlayLevelSoundElementAction(x, y, element, ACTION_IMPACT);
4858 if (impact && element == EL_AMOEBA_DROP)
4860 if (object_hit && IS_PLAYER(x, y + 1))
4861 KillPlayerUnlessEnemyProtected(x, y + 1);
4862 else if (object_hit && smashed == EL_PENGUIN)
4866 Feld[x][y] = EL_AMOEBA_GROWING;
4867 Store[x][y] = EL_AMOEBA_WET;
4869 ResetRandomAnimationValue(x, y);
4874 if (object_hit) /* check which object was hit */
4876 if ((CAN_PASS_MAGIC_WALL(element) &&
4877 (smashed == EL_MAGIC_WALL ||
4878 smashed == EL_BD_MAGIC_WALL)) ||
4879 (CAN_PASS_DC_MAGIC_WALL(element) &&
4880 smashed == EL_DC_MAGIC_WALL))
4883 int activated_magic_wall =
4884 (smashed == EL_MAGIC_WALL ? EL_MAGIC_WALL_ACTIVE :
4885 smashed == EL_BD_MAGIC_WALL ? EL_BD_MAGIC_WALL_ACTIVE :
4886 EL_DC_MAGIC_WALL_ACTIVE);
4888 /* activate magic wall / mill */
4889 SCAN_PLAYFIELD(xx, yy)
4891 if (Feld[xx][yy] == smashed)
4892 Feld[xx][yy] = activated_magic_wall;
4895 game.magic_wall_time_left = level.time_magic_wall * FRAMES_PER_SECOND;
4896 game.magic_wall_active = TRUE;
4898 PlayLevelSound(x, y, (smashed == EL_MAGIC_WALL ?
4899 SND_MAGIC_WALL_ACTIVATING :
4900 smashed == EL_BD_MAGIC_WALL ?
4901 SND_BD_MAGIC_WALL_ACTIVATING :
4902 SND_DC_MAGIC_WALL_ACTIVATING));
4905 if (IS_PLAYER(x, y + 1))
4907 if (CAN_SMASH_PLAYER(element))
4909 KillPlayerUnlessEnemyProtected(x, y + 1);
4913 else if (smashed == EL_PENGUIN)
4915 if (CAN_SMASH_PLAYER(element))
4921 else if (element == EL_BD_DIAMOND)
4923 if (IS_CLASSIC_ENEMY(smashed) && IS_BD_ELEMENT(smashed))
4929 else if (((element == EL_SP_INFOTRON ||
4930 element == EL_SP_ZONK) &&
4931 (smashed == EL_SP_SNIKSNAK ||
4932 smashed == EL_SP_ELECTRON ||
4933 smashed == EL_SP_DISK_ORANGE)) ||
4934 (element == EL_SP_INFOTRON &&
4935 smashed == EL_SP_DISK_YELLOW))
4940 else if (CAN_SMASH_EVERYTHING(element))
4942 if (IS_CLASSIC_ENEMY(smashed) ||
4943 CAN_EXPLODE_SMASHED(smashed))
4948 else if (!IS_MOVING(x, y + 1) && !IS_BLOCKED(x, y + 1))
4950 if (smashed == EL_LAMP ||
4951 smashed == EL_LAMP_ACTIVE)
4956 else if (smashed == EL_NUT)
4958 Feld[x][y + 1] = EL_NUT_BREAKING;
4959 PlayLevelSound(x, y, SND_NUT_BREAKING);
4960 RaiseScoreElement(EL_NUT);
4963 else if (smashed == EL_PEARL)
4965 ResetGfxAnimation(x, y);
4967 Feld[x][y + 1] = EL_PEARL_BREAKING;
4968 PlayLevelSound(x, y, SND_PEARL_BREAKING);
4971 else if (smashed == EL_DIAMOND)
4973 Feld[x][y + 1] = EL_DIAMOND_BREAKING;
4974 PlayLevelSound(x, y, SND_DIAMOND_BREAKING);
4977 else if (IS_BELT_SWITCH(smashed))
4979 ToggleBeltSwitch(x, y + 1);
4981 else if (smashed == EL_SWITCHGATE_SWITCH_UP ||
4982 smashed == EL_SWITCHGATE_SWITCH_DOWN ||
4983 smashed == EL_DC_SWITCHGATE_SWITCH_UP ||
4984 smashed == EL_DC_SWITCHGATE_SWITCH_DOWN)
4986 ToggleSwitchgateSwitch(x, y + 1);
4988 else if (smashed == EL_LIGHT_SWITCH ||
4989 smashed == EL_LIGHT_SWITCH_ACTIVE)
4991 ToggleLightSwitch(x, y + 1);
4996 TestIfElementSmashesCustomElement(x, y, MV_DOWN);
4999 CheckElementChange(x, y + 1, smashed, element, CE_SMASHED);
5001 CheckElementChangeBySide(x, y + 1, smashed, element,
5002 CE_SWITCHED, CH_SIDE_TOP);
5003 CheckTriggeredElementChangeBySide(x, y + 1, smashed, CE_SWITCH_OF_X,
5009 CheckElementChange(x, y + 1, smashed, element, CE_SMASHED);
5014 /* play sound of magic wall / mill */
5016 (Feld[x][y + 1] == EL_MAGIC_WALL_ACTIVE ||
5017 Feld[x][y + 1] == EL_BD_MAGIC_WALL_ACTIVE ||
5018 Feld[x][y + 1] == EL_DC_MAGIC_WALL_ACTIVE))
5020 if (Feld[x][y + 1] == EL_MAGIC_WALL_ACTIVE)
5021 PlayLevelSound(x, y, SND_MAGIC_WALL_FILLING);
5022 else if (Feld[x][y + 1] == EL_BD_MAGIC_WALL_ACTIVE)
5023 PlayLevelSound(x, y, SND_BD_MAGIC_WALL_FILLING);
5024 else if (Feld[x][y + 1] == EL_DC_MAGIC_WALL_ACTIVE)
5025 PlayLevelSound(x, y, SND_DC_MAGIC_WALL_FILLING);
5030 /* play sound of object that hits the ground */
5031 if (last_line || object_hit)
5032 PlayLevelSoundElementAction(x, y, element, ACTION_IMPACT);
5035 inline static void TurnRoundExt(int x, int y)
5047 { 0, 0 }, { 0, 0 }, { 0, 0 },
5052 int left, right, back;
5056 { MV_DOWN, MV_UP, MV_RIGHT },
5057 { MV_UP, MV_DOWN, MV_LEFT },
5059 { MV_LEFT, MV_RIGHT, MV_DOWN },
5063 { MV_RIGHT, MV_LEFT, MV_UP }
5066 int element = Feld[x][y];
5067 int move_pattern = element_info[element].move_pattern;
5069 int old_move_dir = MovDir[x][y];
5070 int left_dir = turn[old_move_dir].left;
5071 int right_dir = turn[old_move_dir].right;
5072 int back_dir = turn[old_move_dir].back;
5074 int left_dx = move_xy[left_dir].dx, left_dy = move_xy[left_dir].dy;
5075 int right_dx = move_xy[right_dir].dx, right_dy = move_xy[right_dir].dy;
5076 int move_dx = move_xy[old_move_dir].dx, move_dy = move_xy[old_move_dir].dy;
5077 int back_dx = move_xy[back_dir].dx, back_dy = move_xy[back_dir].dy;
5079 int left_x = x + left_dx, left_y = y + left_dy;
5080 int right_x = x + right_dx, right_y = y + right_dy;
5081 int move_x = x + move_dx, move_y = y + move_dy;
5085 if (element == EL_BUG || element == EL_BD_BUTTERFLY)
5087 TestIfBadThingTouchesOtherBadThing(x, y);
5089 if (ENEMY_CAN_ENTER_FIELD(element, right_x, right_y))
5090 MovDir[x][y] = right_dir;
5091 else if (!ENEMY_CAN_ENTER_FIELD(element, move_x, move_y))
5092 MovDir[x][y] = left_dir;
5094 if (element == EL_BUG && MovDir[x][y] != old_move_dir)
5096 else if (element == EL_BD_BUTTERFLY) /* && MovDir[x][y] == left_dir) */
5099 else if (element == EL_SPACESHIP || element == EL_BD_FIREFLY)
5101 TestIfBadThingTouchesOtherBadThing(x, y);
5103 if (ENEMY_CAN_ENTER_FIELD(element, left_x, left_y))
5104 MovDir[x][y] = left_dir;
5105 else if (!ENEMY_CAN_ENTER_FIELD(element, move_x, move_y))
5106 MovDir[x][y] = right_dir;
5108 if (element == EL_SPACESHIP && MovDir[x][y] != old_move_dir)
5110 else if (element == EL_BD_FIREFLY) /* && MovDir[x][y] == right_dir) */
5113 else if (element == EL_SP_SNIKSNAK || element == EL_SP_ELECTRON)
5115 TestIfBadThingTouchesOtherBadThing(x, y);
5117 if (ELEMENT_CAN_ENTER_FIELD_BASE_4(element, left_x, left_y, 0))
5118 MovDir[x][y] = left_dir;
5119 else if (!ELEMENT_CAN_ENTER_FIELD_BASE_4(element, move_x, move_y, 0))
5120 MovDir[x][y] = right_dir;
5122 if (MovDir[x][y] != old_move_dir)
5125 else if (element == EL_YAMYAM)
5127 boolean can_turn_left = YAMYAM_CAN_ENTER_FIELD(element, left_x, left_y);
5128 boolean can_turn_right = YAMYAM_CAN_ENTER_FIELD(element, right_x, right_y);
5130 if (can_turn_left && can_turn_right)
5131 MovDir[x][y] = (RND(3) ? (RND(2) ? left_dir : right_dir) : back_dir);
5132 else if (can_turn_left)
5133 MovDir[x][y] = (RND(2) ? left_dir : back_dir);
5134 else if (can_turn_right)
5135 MovDir[x][y] = (RND(2) ? right_dir : back_dir);
5137 MovDir[x][y] = back_dir;
5139 MovDelay[x][y] = 16 + 16 * RND(3);
5141 else if (element == EL_DARK_YAMYAM)
5143 boolean can_turn_left = DARK_YAMYAM_CAN_ENTER_FIELD(element,
5145 boolean can_turn_right = DARK_YAMYAM_CAN_ENTER_FIELD(element,
5148 if (can_turn_left && can_turn_right)
5149 MovDir[x][y] = (RND(3) ? (RND(2) ? left_dir : right_dir) : back_dir);
5150 else if (can_turn_left)
5151 MovDir[x][y] = (RND(2) ? left_dir : back_dir);
5152 else if (can_turn_right)
5153 MovDir[x][y] = (RND(2) ? right_dir : back_dir);
5155 MovDir[x][y] = back_dir;
5157 MovDelay[x][y] = 16 + 16 * RND(3);
5159 else if (element == EL_PACMAN)
5161 boolean can_turn_left = PACMAN_CAN_ENTER_FIELD(element, left_x, left_y);
5162 boolean can_turn_right = PACMAN_CAN_ENTER_FIELD(element, right_x, right_y);
5164 if (can_turn_left && can_turn_right)
5165 MovDir[x][y] = (RND(3) ? (RND(2) ? left_dir : right_dir) : back_dir);
5166 else if (can_turn_left)
5167 MovDir[x][y] = (RND(2) ? left_dir : back_dir);
5168 else if (can_turn_right)
5169 MovDir[x][y] = (RND(2) ? right_dir : back_dir);
5171 MovDir[x][y] = back_dir;
5173 MovDelay[x][y] = 6 + RND(40);
5175 else if (element == EL_PIG)
5177 boolean can_turn_left = PIG_CAN_ENTER_FIELD(element, left_x, left_y);
5178 boolean can_turn_right = PIG_CAN_ENTER_FIELD(element, right_x, right_y);
5179 boolean can_move_on = PIG_CAN_ENTER_FIELD(element, move_x, move_y);
5180 boolean should_turn_left, should_turn_right, should_move_on;
5182 int rnd = RND(rnd_value);
5184 should_turn_left = (can_turn_left &&
5186 IN_LEV_FIELD_AND_NOT_FREE(x + back_dx + left_dx,
5187 y + back_dy + left_dy)));
5188 should_turn_right = (can_turn_right &&
5190 IN_LEV_FIELD_AND_NOT_FREE(x + back_dx + right_dx,
5191 y + back_dy + right_dy)));
5192 should_move_on = (can_move_on &&
5195 IN_LEV_FIELD_AND_NOT_FREE(x + move_dx + left_dx,
5196 y + move_dy + left_dy) ||
5197 IN_LEV_FIELD_AND_NOT_FREE(x + move_dx + right_dx,
5198 y + move_dy + right_dy)));
5200 if (should_turn_left || should_turn_right || should_move_on)
5202 if (should_turn_left && should_turn_right && should_move_on)
5203 MovDir[x][y] = (rnd < rnd_value / 3 ? left_dir :
5204 rnd < 2 * rnd_value / 3 ? right_dir :
5206 else if (should_turn_left && should_turn_right)
5207 MovDir[x][y] = (rnd < rnd_value / 2 ? left_dir : right_dir);
5208 else if (should_turn_left && should_move_on)
5209 MovDir[x][y] = (rnd < rnd_value / 2 ? left_dir : old_move_dir);
5210 else if (should_turn_right && should_move_on)
5211 MovDir[x][y] = (rnd < rnd_value / 2 ? right_dir : old_move_dir);
5212 else if (should_turn_left)
5213 MovDir[x][y] = left_dir;
5214 else if (should_turn_right)
5215 MovDir[x][y] = right_dir;
5216 else if (should_move_on)
5217 MovDir[x][y] = old_move_dir;
5219 else if (can_move_on && rnd > rnd_value / 8)
5220 MovDir[x][y] = old_move_dir;
5221 else if (can_turn_left && can_turn_right)
5222 MovDir[x][y] = (rnd < rnd_value / 2 ? left_dir : right_dir);
5223 else if (can_turn_left && rnd > rnd_value / 8)
5224 MovDir[x][y] = left_dir;
5225 else if (can_turn_right && rnd > rnd_value/8)
5226 MovDir[x][y] = right_dir;
5228 MovDir[x][y] = back_dir;
5230 xx = x + move_xy[MovDir[x][y]].dx;
5231 yy = y + move_xy[MovDir[x][y]].dy;
5233 if (!IN_LEV_FIELD(xx, yy) ||
5234 (!IS_FREE(xx, yy) && !IS_FOOD_PIG(Feld[xx][yy])))
5235 MovDir[x][y] = old_move_dir;
5239 else if (element == EL_DRAGON)
5241 boolean can_turn_left = DRAGON_CAN_ENTER_FIELD(element, left_x, left_y);
5242 boolean can_turn_right = DRAGON_CAN_ENTER_FIELD(element, right_x, right_y);
5243 boolean can_move_on = DRAGON_CAN_ENTER_FIELD(element, move_x, move_y);
5245 int rnd = RND(rnd_value);
5247 if (can_move_on && rnd > rnd_value / 8)
5248 MovDir[x][y] = old_move_dir;
5249 else if (can_turn_left && can_turn_right)
5250 MovDir[x][y] = (rnd < rnd_value / 2 ? left_dir : right_dir);
5251 else if (can_turn_left && rnd > rnd_value / 8)
5252 MovDir[x][y] = left_dir;
5253 else if (can_turn_right && rnd > rnd_value / 8)
5254 MovDir[x][y] = right_dir;
5256 MovDir[x][y] = back_dir;
5258 xx = x + move_xy[MovDir[x][y]].dx;
5259 yy = y + move_xy[MovDir[x][y]].dy;
5261 if (!IN_LEV_FIELD_AND_IS_FREE(xx, yy))
5262 MovDir[x][y] = old_move_dir;
5266 else if (element == EL_MOLE)
5268 boolean can_move_on =
5269 (MOLE_CAN_ENTER_FIELD(element, move_x, move_y,
5270 IS_AMOEBOID(Feld[move_x][move_y]) ||
5271 Feld[move_x][move_y] == EL_AMOEBA_SHRINKING));
5274 boolean can_turn_left =
5275 (MOLE_CAN_ENTER_FIELD(element, left_x, left_y,
5276 IS_AMOEBOID(Feld[left_x][left_y])));
5278 boolean can_turn_right =
5279 (MOLE_CAN_ENTER_FIELD(element, right_x, right_y,
5280 IS_AMOEBOID(Feld[right_x][right_y])));
5282 if (can_turn_left && can_turn_right)
5283 MovDir[x][y] = (RND(2) ? left_dir : right_dir);
5284 else if (can_turn_left)
5285 MovDir[x][y] = left_dir;
5287 MovDir[x][y] = right_dir;
5290 if (MovDir[x][y] != old_move_dir)
5293 else if (element == EL_BALLOON)
5295 MovDir[x][y] = game.wind_direction;
5298 else if (element == EL_SPRING)
5300 #if USE_NEW_SPRING_BUMPER
5301 if (MovDir[x][y] & MV_HORIZONTAL)
5303 if (SPRING_CAN_BUMP_FROM_FIELD(move_x, move_y) &&
5304 !SPRING_CAN_ENTER_FIELD(element, x, y + 1))
5306 Feld[move_x][move_y] = EL_EMC_SPRING_BUMPER_ACTIVE;
5307 ResetGfxAnimation(move_x, move_y);
5308 DrawLevelField(move_x, move_y);
5310 MovDir[x][y] = back_dir;
5312 else if (!SPRING_CAN_ENTER_FIELD(element, move_x, move_y) ||
5313 SPRING_CAN_ENTER_FIELD(element, x, y + 1))
5314 MovDir[x][y] = MV_NONE;
5317 if (MovDir[x][y] & MV_HORIZONTAL &&
5318 (!SPRING_CAN_ENTER_FIELD(element, move_x, move_y) ||
5319 SPRING_CAN_ENTER_FIELD(element, x, y + 1)))
5320 MovDir[x][y] = MV_NONE;
5325 else if (element == EL_ROBOT ||
5326 element == EL_SATELLITE ||
5327 element == EL_PENGUIN ||
5328 element == EL_EMC_ANDROID)
5330 int attr_x = -1, attr_y = -1;
5341 for (i = 0; i < MAX_PLAYERS; i++)
5343 struct PlayerInfo *player = &stored_player[i];
5344 int jx = player->jx, jy = player->jy;
5346 if (!player->active)
5350 ABS(jx - x) + ABS(jy - y) < ABS(attr_x - x) + ABS(attr_y - y))
5358 if (element == EL_ROBOT && ZX >= 0 && ZY >= 0 &&
5359 (Feld[ZX][ZY] == EL_ROBOT_WHEEL_ACTIVE ||
5360 game.engine_version < VERSION_IDENT(3,1,0,0)))
5366 if (element == EL_PENGUIN)
5369 static int xy[4][2] =
5377 for (i = 0; i < NUM_DIRECTIONS; i++)
5379 int ex = x + xy[i][0];
5380 int ey = y + xy[i][1];
5382 if (IN_LEV_FIELD(ex, ey) && (Feld[ex][ey] == EL_EXIT_OPEN ||
5383 Feld[ex][ey] == EL_EM_EXIT_OPEN ||
5384 Feld[ex][ey] == EL_STEEL_EXIT_OPEN ||
5385 Feld[ex][ey] == EL_EM_STEEL_EXIT_OPEN))
5394 MovDir[x][y] = MV_NONE;
5396 MovDir[x][y] |= (AllPlayersGone ? MV_RIGHT : MV_LEFT);
5397 else if (attr_x > x)
5398 MovDir[x][y] |= (AllPlayersGone ? MV_LEFT : MV_RIGHT);
5400 MovDir[x][y] |= (AllPlayersGone ? MV_DOWN : MV_UP);
5401 else if (attr_y > y)
5402 MovDir[x][y] |= (AllPlayersGone ? MV_UP : MV_DOWN);
5404 if (element == EL_ROBOT)
5408 if (MovDir[x][y] & MV_HORIZONTAL && MovDir[x][y] & MV_VERTICAL)
5409 MovDir[x][y] &= (RND(2) ? MV_HORIZONTAL : MV_VERTICAL);
5410 Moving2Blocked(x, y, &newx, &newy);
5412 if (IN_LEV_FIELD(newx, newy) && IS_FREE_OR_PLAYER(newx, newy))
5413 MovDelay[x][y] = 8 + 8 * !RND(3);
5415 MovDelay[x][y] = 16;
5417 else if (element == EL_PENGUIN)
5423 if (MovDir[x][y] & MV_HORIZONTAL && MovDir[x][y] & MV_VERTICAL)
5425 boolean first_horiz = RND(2);
5426 int new_move_dir = MovDir[x][y];
5429 new_move_dir & (first_horiz ? MV_HORIZONTAL : MV_VERTICAL);
5430 Moving2Blocked(x, y, &newx, &newy);
5432 if (PENGUIN_CAN_ENTER_FIELD(element, newx, newy))
5436 new_move_dir & (!first_horiz ? MV_HORIZONTAL : MV_VERTICAL);
5437 Moving2Blocked(x, y, &newx, &newy);
5439 if (PENGUIN_CAN_ENTER_FIELD(element, newx, newy))
5442 MovDir[x][y] = old_move_dir;
5446 else if (element == EL_SATELLITE)
5452 if (MovDir[x][y] & MV_HORIZONTAL && MovDir[x][y] & MV_VERTICAL)
5454 boolean first_horiz = RND(2);
5455 int new_move_dir = MovDir[x][y];
5458 new_move_dir & (first_horiz ? MV_HORIZONTAL : MV_VERTICAL);
5459 Moving2Blocked(x, y, &newx, &newy);
5461 if (SATELLITE_CAN_ENTER_FIELD(newx, newy))
5465 new_move_dir & (!first_horiz ? MV_HORIZONTAL : MV_VERTICAL);
5466 Moving2Blocked(x, y, &newx, &newy);
5468 if (SATELLITE_CAN_ENTER_FIELD(newx, newy))
5471 MovDir[x][y] = old_move_dir;
5475 else if (element == EL_EMC_ANDROID)
5477 static int check_pos[16] =
5479 -1, /* 0 => (invalid) */
5480 7, /* 1 => MV_LEFT */
5481 3, /* 2 => MV_RIGHT */
5482 -1, /* 3 => (invalid) */
5484 0, /* 5 => MV_LEFT | MV_UP */
5485 2, /* 6 => MV_RIGHT | MV_UP */
5486 -1, /* 7 => (invalid) */
5487 5, /* 8 => MV_DOWN */
5488 6, /* 9 => MV_LEFT | MV_DOWN */
5489 4, /* 10 => MV_RIGHT | MV_DOWN */
5490 -1, /* 11 => (invalid) */
5491 -1, /* 12 => (invalid) */
5492 -1, /* 13 => (invalid) */
5493 -1, /* 14 => (invalid) */
5494 -1, /* 15 => (invalid) */
5502 { -1, -1, MV_LEFT | MV_UP },
5504 { +1, -1, MV_RIGHT | MV_UP },
5505 { +1, 0, MV_RIGHT },
5506 { +1, +1, MV_RIGHT | MV_DOWN },
5508 { -1, +1, MV_LEFT | MV_DOWN },
5511 int start_pos, check_order;
5512 boolean can_clone = FALSE;
5515 /* check if there is any free field around current position */
5516 for (i = 0; i < 8; i++)
5518 int newx = x + check_xy[i].dx;
5519 int newy = y + check_xy[i].dy;
5521 if (IN_LEV_FIELD_AND_IS_FREE(newx, newy))
5529 if (can_clone) /* randomly find an element to clone */
5533 start_pos = check_pos[RND(8)];
5534 check_order = (RND(2) ? -1 : +1);
5536 for (i = 0; i < 8; i++)
5538 int pos_raw = start_pos + i * check_order;
5539 int pos = (pos_raw + 8) % 8;
5540 int newx = x + check_xy[pos].dx;
5541 int newy = y + check_xy[pos].dy;
5543 if (ANDROID_CAN_CLONE_FIELD(newx, newy))
5545 element_info[element].move_leave_type = LEAVE_TYPE_LIMITED;
5546 element_info[element].move_leave_element = EL_TRIGGER_ELEMENT;
5548 Store[x][y] = Feld[newx][newy];
5557 if (can_clone) /* randomly find a direction to move */
5561 start_pos = check_pos[RND(8)];
5562 check_order = (RND(2) ? -1 : +1);
5564 for (i = 0; i < 8; i++)
5566 int pos_raw = start_pos + i * check_order;
5567 int pos = (pos_raw + 8) % 8;
5568 int newx = x + check_xy[pos].dx;
5569 int newy = y + check_xy[pos].dy;
5570 int new_move_dir = check_xy[pos].dir;
5572 if (IN_LEV_FIELD_AND_IS_FREE(newx, newy))
5574 MovDir[x][y] = new_move_dir;
5575 MovDelay[x][y] = level.android_clone_time * 8 + 1;
5584 if (can_clone) /* cloning and moving successful */
5587 /* cannot clone -- try to move towards player */
5589 start_pos = check_pos[MovDir[x][y] & 0x0f];
5590 check_order = (RND(2) ? -1 : +1);
5592 for (i = 0; i < 3; i++)
5594 /* first check start_pos, then previous/next or (next/previous) pos */
5595 int pos_raw = start_pos + (i < 2 ? i : -1) * check_order;
5596 int pos = (pos_raw + 8) % 8;
5597 int newx = x + check_xy[pos].dx;
5598 int newy = y + check_xy[pos].dy;
5599 int new_move_dir = check_xy[pos].dir;
5601 if (IS_PLAYER(newx, newy))
5604 if (ANDROID_CAN_ENTER_FIELD(element, newx, newy))
5606 MovDir[x][y] = new_move_dir;
5607 MovDelay[x][y] = level.android_move_time * 8 + 1;
5614 else if (move_pattern == MV_TURNING_LEFT ||
5615 move_pattern == MV_TURNING_RIGHT ||
5616 move_pattern == MV_TURNING_LEFT_RIGHT ||
5617 move_pattern == MV_TURNING_RIGHT_LEFT ||
5618 move_pattern == MV_TURNING_RANDOM ||
5619 move_pattern == MV_ALL_DIRECTIONS)
5621 boolean can_turn_left =
5622 CUSTOM_ELEMENT_CAN_ENTER_FIELD(element, left_x, left_y);
5623 boolean can_turn_right =
5624 CUSTOM_ELEMENT_CAN_ENTER_FIELD(element, right_x,right_y);
5626 if (element_info[element].move_stepsize == 0) /* "not moving" */
5629 if (move_pattern == MV_TURNING_LEFT)
5630 MovDir[x][y] = left_dir;
5631 else if (move_pattern == MV_TURNING_RIGHT)
5632 MovDir[x][y] = right_dir;
5633 else if (move_pattern == MV_TURNING_LEFT_RIGHT)
5634 MovDir[x][y] = (can_turn_left || !can_turn_right ? left_dir : right_dir);
5635 else if (move_pattern == MV_TURNING_RIGHT_LEFT)
5636 MovDir[x][y] = (can_turn_right || !can_turn_left ? right_dir : left_dir);
5637 else if (move_pattern == MV_TURNING_RANDOM)
5638 MovDir[x][y] = (can_turn_left && !can_turn_right ? left_dir :
5639 can_turn_right && !can_turn_left ? right_dir :
5640 RND(2) ? left_dir : right_dir);
5641 else if (can_turn_left && can_turn_right)
5642 MovDir[x][y] = (RND(3) ? (RND(2) ? left_dir : right_dir) : back_dir);
5643 else if (can_turn_left)
5644 MovDir[x][y] = (RND(2) ? left_dir : back_dir);
5645 else if (can_turn_right)
5646 MovDir[x][y] = (RND(2) ? right_dir : back_dir);
5648 MovDir[x][y] = back_dir;
5650 MovDelay[x][y] = GET_NEW_MOVE_DELAY(element);
5652 else if (move_pattern == MV_HORIZONTAL ||
5653 move_pattern == MV_VERTICAL)
5655 if (move_pattern & old_move_dir)
5656 MovDir[x][y] = back_dir;
5657 else if (move_pattern == MV_HORIZONTAL)
5658 MovDir[x][y] = (RND(2) ? MV_LEFT : MV_RIGHT);
5659 else if (move_pattern == MV_VERTICAL)
5660 MovDir[x][y] = (RND(2) ? MV_UP : MV_DOWN);
5662 MovDelay[x][y] = GET_NEW_MOVE_DELAY(element);
5664 else if (move_pattern & MV_ANY_DIRECTION)
5666 MovDir[x][y] = move_pattern;
5667 MovDelay[x][y] = GET_NEW_MOVE_DELAY(element);
5669 else if (move_pattern & MV_WIND_DIRECTION)
5671 MovDir[x][y] = game.wind_direction;
5672 MovDelay[x][y] = GET_NEW_MOVE_DELAY(element);
5674 else if (move_pattern == MV_ALONG_LEFT_SIDE)
5676 if (CUSTOM_ELEMENT_CAN_ENTER_FIELD(element, left_x, left_y))
5677 MovDir[x][y] = left_dir;
5678 else if (!CUSTOM_ELEMENT_CAN_ENTER_FIELD(element, move_x, move_y))
5679 MovDir[x][y] = right_dir;
5681 if (MovDir[x][y] != old_move_dir)
5682 MovDelay[x][y] = GET_NEW_MOVE_DELAY(element);
5684 else if (move_pattern == MV_ALONG_RIGHT_SIDE)
5686 if (CUSTOM_ELEMENT_CAN_ENTER_FIELD(element, right_x, right_y))
5687 MovDir[x][y] = right_dir;
5688 else if (!CUSTOM_ELEMENT_CAN_ENTER_FIELD(element, move_x, move_y))
5689 MovDir[x][y] = left_dir;
5691 if (MovDir[x][y] != old_move_dir)
5692 MovDelay[x][y] = GET_NEW_MOVE_DELAY(element);
5694 else if (move_pattern == MV_TOWARDS_PLAYER ||
5695 move_pattern == MV_AWAY_FROM_PLAYER)
5697 int attr_x = -1, attr_y = -1;
5699 boolean move_away = (move_pattern == MV_AWAY_FROM_PLAYER);
5710 for (i = 0; i < MAX_PLAYERS; i++)
5712 struct PlayerInfo *player = &stored_player[i];
5713 int jx = player->jx, jy = player->jy;
5715 if (!player->active)
5719 ABS(jx - x) + ABS(jy - y) < ABS(attr_x - x) + ABS(attr_y - y))
5727 MovDir[x][y] = MV_NONE;
5729 MovDir[x][y] |= (move_away ? MV_RIGHT : MV_LEFT);
5730 else if (attr_x > x)
5731 MovDir[x][y] |= (move_away ? MV_LEFT : MV_RIGHT);
5733 MovDir[x][y] |= (move_away ? MV_DOWN : MV_UP);
5734 else if (attr_y > y)
5735 MovDir[x][y] |= (move_away ? MV_UP : MV_DOWN);
5737 MovDelay[x][y] = GET_NEW_MOVE_DELAY(element);
5739 if (MovDir[x][y] & MV_HORIZONTAL && MovDir[x][y] & MV_VERTICAL)
5741 boolean first_horiz = RND(2);
5742 int new_move_dir = MovDir[x][y];
5744 if (element_info[element].move_stepsize == 0) /* "not moving" */
5746 first_horiz = (ABS(attr_x - x) >= ABS(attr_y - y));
5747 MovDir[x][y] &= (first_horiz ? MV_HORIZONTAL : MV_VERTICAL);
5753 new_move_dir & (first_horiz ? MV_HORIZONTAL : MV_VERTICAL);
5754 Moving2Blocked(x, y, &newx, &newy);
5756 if (CUSTOM_ELEMENT_CAN_ENTER_FIELD(element, newx, newy))
5760 new_move_dir & (!first_horiz ? MV_HORIZONTAL : MV_VERTICAL);
5761 Moving2Blocked(x, y, &newx, &newy);
5763 if (CUSTOM_ELEMENT_CAN_ENTER_FIELD(element, newx, newy))
5766 MovDir[x][y] = old_move_dir;
5769 else if (move_pattern == MV_WHEN_PUSHED ||
5770 move_pattern == MV_WHEN_DROPPED)
5772 if (!CUSTOM_ELEMENT_CAN_ENTER_FIELD(element, move_x, move_y))
5773 MovDir[x][y] = MV_NONE;
5777 else if (move_pattern & MV_MAZE_RUNNER_STYLE)
5779 static int test_xy[7][2] =
5789 static int test_dir[7] =
5799 boolean hunter_mode = (move_pattern == MV_MAZE_HUNTER);
5800 int move_preference = -1000000; /* start with very low preference */
5801 int new_move_dir = MV_NONE;
5802 int start_test = RND(4);
5805 for (i = 0; i < NUM_DIRECTIONS; i++)
5807 int move_dir = test_dir[start_test + i];
5808 int move_dir_preference;
5810 xx = x + test_xy[start_test + i][0];
5811 yy = y + test_xy[start_test + i][1];
5813 if (hunter_mode && IN_LEV_FIELD(xx, yy) &&
5814 (IS_PLAYER(xx, yy) || Feld[xx][yy] == EL_PLAYER_IS_LEAVING))
5816 new_move_dir = move_dir;
5821 if (!CUSTOM_ELEMENT_CAN_ENTER_FIELD(element, xx, yy))
5824 move_dir_preference = -1 * RunnerVisit[xx][yy];
5825 if (hunter_mode && PlayerVisit[xx][yy] > 0)
5826 move_dir_preference = PlayerVisit[xx][yy];
5828 if (move_dir_preference > move_preference)
5830 /* prefer field that has not been visited for the longest time */
5831 move_preference = move_dir_preference;
5832 new_move_dir = move_dir;
5834 else if (move_dir_preference == move_preference &&
5835 move_dir == old_move_dir)
5837 /* prefer last direction when all directions are preferred equally */
5838 move_preference = move_dir_preference;
5839 new_move_dir = move_dir;
5843 MovDir[x][y] = new_move_dir;
5844 if (old_move_dir != new_move_dir)
5845 MovDelay[x][y] = GET_NEW_MOVE_DELAY(element);
5849 static void TurnRound(int x, int y)
5851 int direction = MovDir[x][y];
5855 GfxDir[x][y] = MovDir[x][y];
5857 if (direction != MovDir[x][y])
5861 GfxAction[x][y] = ACTION_TURNING_FROM_LEFT + MV_DIR_TO_BIT(direction);
5863 ResetGfxFrame(x, y, FALSE);
5866 static boolean JustBeingPushed(int x, int y)
5870 for (i = 0; i < MAX_PLAYERS; i++)
5872 struct PlayerInfo *player = &stored_player[i];
5874 if (player->active && player->is_pushing && player->MovPos)
5876 int next_jx = player->jx + (player->jx - player->last_jx);
5877 int next_jy = player->jy + (player->jy - player->last_jy);
5879 if (x == next_jx && y == next_jy)
5887 void StartMoving(int x, int y)
5889 boolean started_moving = FALSE; /* some elements can fall _and_ move */
5890 int element = Feld[x][y];
5895 if (MovDelay[x][y] == 0)
5896 GfxAction[x][y] = ACTION_DEFAULT;
5898 if (CAN_FALL(element) && y < lev_fieldy - 1)
5900 if ((x > 0 && IS_PLAYER(x - 1, y)) ||
5901 (x < lev_fieldx - 1 && IS_PLAYER(x + 1, y)))
5902 if (JustBeingPushed(x, y))
5905 if (element == EL_QUICKSAND_FULL)
5907 if (IS_FREE(x, y + 1))
5909 InitMovingField(x, y, MV_DOWN);
5910 started_moving = TRUE;
5912 Feld[x][y] = EL_QUICKSAND_EMPTYING;
5913 #if USE_QUICKSAND_BD_ROCK_BUGFIX
5914 if (Store[x][y] != EL_ROCK && Store[x][y] != EL_BD_ROCK)
5915 Store[x][y] = EL_ROCK;
5917 Store[x][y] = EL_ROCK;
5920 PlayLevelSoundAction(x, y, ACTION_EMPTYING);
5922 else if (Feld[x][y + 1] == EL_QUICKSAND_EMPTY)
5924 if (!MovDelay[x][y])
5925 MovDelay[x][y] = TILEY + 1;
5934 Feld[x][y] = EL_QUICKSAND_EMPTY;
5935 Feld[x][y + 1] = EL_QUICKSAND_FULL;
5936 Store[x][y + 1] = Store[x][y];
5939 PlayLevelSoundAction(x, y, ACTION_FILLING);
5942 else if (element == EL_QUICKSAND_FAST_FULL)
5944 if (IS_FREE(x, y + 1))
5946 InitMovingField(x, y, MV_DOWN);
5947 started_moving = TRUE;
5949 Feld[x][y] = EL_QUICKSAND_FAST_EMPTYING;
5950 #if USE_QUICKSAND_BD_ROCK_BUGFIX
5951 if (Store[x][y] != EL_ROCK && Store[x][y] != EL_BD_ROCK)
5952 Store[x][y] = EL_ROCK;
5954 Store[x][y] = EL_ROCK;
5957 PlayLevelSoundAction(x, y, ACTION_EMPTYING);
5959 else if (Feld[x][y + 1] == EL_QUICKSAND_FAST_EMPTY)
5961 if (!MovDelay[x][y])
5962 MovDelay[x][y] = TILEY + 1;
5971 Feld[x][y] = EL_QUICKSAND_FAST_EMPTY;
5972 Feld[x][y + 1] = EL_QUICKSAND_FAST_FULL;
5973 Store[x][y + 1] = Store[x][y];
5976 PlayLevelSoundAction(x, y, ACTION_FILLING);
5979 else if ((element == EL_ROCK || element == EL_BD_ROCK) &&
5980 Feld[x][y + 1] == EL_QUICKSAND_EMPTY)
5982 InitMovingField(x, y, MV_DOWN);
5983 started_moving = TRUE;
5985 Feld[x][y] = EL_QUICKSAND_FILLING;
5986 Store[x][y] = element;
5988 PlayLevelSoundAction(x, y, ACTION_FILLING);
5990 else if ((element == EL_ROCK || element == EL_BD_ROCK) &&
5991 Feld[x][y + 1] == EL_QUICKSAND_FAST_EMPTY)
5993 InitMovingField(x, y, MV_DOWN);
5994 started_moving = TRUE;
5996 Feld[x][y] = EL_QUICKSAND_FAST_FILLING;
5997 Store[x][y] = element;
5999 PlayLevelSoundAction(x, y, ACTION_FILLING);
6001 else if (element == EL_MAGIC_WALL_FULL)
6003 if (IS_FREE(x, y + 1))
6005 InitMovingField(x, y, MV_DOWN);
6006 started_moving = TRUE;
6008 Feld[x][y] = EL_MAGIC_WALL_EMPTYING;
6009 Store[x][y] = EL_CHANGED(Store[x][y]);
6011 else if (Feld[x][y + 1] == EL_MAGIC_WALL_ACTIVE)
6013 if (!MovDelay[x][y])
6014 MovDelay[x][y] = TILEY/4 + 1;
6023 Feld[x][y] = EL_MAGIC_WALL_ACTIVE;
6024 Feld[x][y + 1] = EL_MAGIC_WALL_FULL;
6025 Store[x][y + 1] = EL_CHANGED(Store[x][y]);
6029 else if (element == EL_BD_MAGIC_WALL_FULL)
6031 if (IS_FREE(x, y + 1))
6033 InitMovingField(x, y, MV_DOWN);
6034 started_moving = TRUE;
6036 Feld[x][y] = EL_BD_MAGIC_WALL_EMPTYING;
6037 Store[x][y] = EL_CHANGED_BD(Store[x][y]);
6039 else if (Feld[x][y + 1] == EL_BD_MAGIC_WALL_ACTIVE)
6041 if (!MovDelay[x][y])
6042 MovDelay[x][y] = TILEY/4 + 1;
6051 Feld[x][y] = EL_BD_MAGIC_WALL_ACTIVE;
6052 Feld[x][y + 1] = EL_BD_MAGIC_WALL_FULL;
6053 Store[x][y + 1] = EL_CHANGED_BD(Store[x][y]);
6057 else if (element == EL_DC_MAGIC_WALL_FULL)
6059 if (IS_FREE(x, y + 1))
6061 InitMovingField(x, y, MV_DOWN);
6062 started_moving = TRUE;
6064 Feld[x][y] = EL_DC_MAGIC_WALL_EMPTYING;
6065 Store[x][y] = EL_CHANGED_DC(Store[x][y]);
6067 else if (Feld[x][y + 1] == EL_DC_MAGIC_WALL_ACTIVE)
6069 if (!MovDelay[x][y])
6070 MovDelay[x][y] = TILEY/4 + 1;
6079 Feld[x][y] = EL_DC_MAGIC_WALL_ACTIVE;
6080 Feld[x][y + 1] = EL_DC_MAGIC_WALL_FULL;
6081 Store[x][y + 1] = EL_CHANGED_DC(Store[x][y]);
6085 else if ((CAN_PASS_MAGIC_WALL(element) &&
6086 (Feld[x][y + 1] == EL_MAGIC_WALL_ACTIVE ||
6087 Feld[x][y + 1] == EL_BD_MAGIC_WALL_ACTIVE)) ||
6088 (CAN_PASS_DC_MAGIC_WALL(element) &&
6089 (Feld[x][y + 1] == EL_DC_MAGIC_WALL_ACTIVE)))
6092 InitMovingField(x, y, MV_DOWN);
6093 started_moving = TRUE;
6096 (Feld[x][y + 1] == EL_MAGIC_WALL_ACTIVE ? EL_MAGIC_WALL_FILLING :
6097 Feld[x][y + 1] == EL_BD_MAGIC_WALL_ACTIVE ? EL_BD_MAGIC_WALL_FILLING :
6098 EL_DC_MAGIC_WALL_FILLING);
6099 Store[x][y] = element;
6101 else if (CAN_FALL(element) && Feld[x][y + 1] == EL_ACID)
6103 SplashAcid(x, y + 1);
6105 InitMovingField(x, y, MV_DOWN);
6106 started_moving = TRUE;
6108 Store[x][y] = EL_ACID;
6111 #if USE_FIX_IMPACT_COLLISION
6112 (game.engine_version >= VERSION_IDENT(3,1,0,0) &&
6113 CheckImpact[x][y] && !IS_FREE(x, y + 1)) ||
6115 (game.engine_version >= VERSION_IDENT(3,1,0,0) &&
6116 CheckCollision[x][y] && !IS_FREE(x, y + 1)) ||
6118 (game.engine_version >= VERSION_IDENT(3,0,7,0) &&
6119 CAN_FALL(element) && WasJustFalling[x][y] &&
6120 (Feld[x][y + 1] == EL_BLOCKED || IS_PLAYER(x, y + 1))) ||
6122 (game.engine_version < VERSION_IDENT(2,2,0,7) &&
6123 CAN_FALL(element) && WasJustMoving[x][y] && !Pushed[x][y + 1] &&
6124 (Feld[x][y + 1] == EL_BLOCKED)))
6126 /* this is needed for a special case not covered by calling "Impact()"
6127 from "ContinueMoving()": if an element moves to a tile directly below
6128 another element which was just falling on that tile (which was empty
6129 in the previous frame), the falling element above would just stop
6130 instead of smashing the element below (in previous version, the above
6131 element was just checked for "moving" instead of "falling", resulting
6132 in incorrect smashes caused by horizontal movement of the above
6133 element; also, the case of the player being the element to smash was
6134 simply not covered here... :-/ ) */
6136 CheckCollision[x][y] = 0;
6137 CheckImpact[x][y] = 0;
6141 else if (IS_FREE(x, y + 1) && element == EL_SPRING && level.use_spring_bug)
6143 if (MovDir[x][y] == MV_NONE)
6145 InitMovingField(x, y, MV_DOWN);
6146 started_moving = TRUE;
6149 else if (IS_FREE(x, y + 1) || Feld[x][y + 1] == EL_DIAMOND_BREAKING)
6151 if (WasJustFalling[x][y]) /* prevent animation from being restarted */
6152 MovDir[x][y] = MV_DOWN;
6154 InitMovingField(x, y, MV_DOWN);
6155 started_moving = TRUE;
6157 else if (element == EL_AMOEBA_DROP)
6159 Feld[x][y] = EL_AMOEBA_GROWING;
6160 Store[x][y] = EL_AMOEBA_WET;
6162 else if (((IS_SLIPPERY(Feld[x][y + 1]) && !IS_PLAYER(x, y + 1)) ||
6163 (IS_EM_SLIPPERY_WALL(Feld[x][y + 1]) && IS_GEM(element))) &&
6164 !IS_FALLING(x, y + 1) && !WasJustMoving[x][y + 1] &&
6165 element != EL_DX_SUPABOMB && element != EL_SP_DISK_ORANGE)
6167 boolean can_fall_left = (x > 0 && IS_FREE(x - 1, y) &&
6168 (IS_FREE(x - 1, y + 1) ||
6169 Feld[x - 1][y + 1] == EL_ACID));
6170 boolean can_fall_right = (x < lev_fieldx - 1 && IS_FREE(x + 1, y) &&
6171 (IS_FREE(x + 1, y + 1) ||
6172 Feld[x + 1][y + 1] == EL_ACID));
6173 boolean can_fall_any = (can_fall_left || can_fall_right);
6174 boolean can_fall_both = (can_fall_left && can_fall_right);
6175 int slippery_type = element_info[Feld[x][y + 1]].slippery_type;
6177 #if USE_NEW_ALL_SLIPPERY
6178 if (can_fall_any && slippery_type != SLIPPERY_ANY_RANDOM)
6180 if (slippery_type == SLIPPERY_ANY_LEFT_RIGHT && can_fall_both)
6181 can_fall_right = FALSE;
6182 else if (slippery_type == SLIPPERY_ANY_RIGHT_LEFT && can_fall_both)
6183 can_fall_left = FALSE;
6184 else if (slippery_type == SLIPPERY_ONLY_LEFT)
6185 can_fall_right = FALSE;
6186 else if (slippery_type == SLIPPERY_ONLY_RIGHT)
6187 can_fall_left = FALSE;
6189 can_fall_any = (can_fall_left || can_fall_right);
6190 can_fall_both = FALSE;
6193 if (can_fall_any && IS_CUSTOM_ELEMENT(Feld[x][y + 1]))
6195 if (slippery_type == SLIPPERY_ONLY_LEFT)
6196 can_fall_right = FALSE;
6197 else if (slippery_type == SLIPPERY_ONLY_RIGHT)
6198 can_fall_left = FALSE;
6199 else if (slippery_type == SLIPPERY_ANY_LEFT_RIGHT && can_fall_both)
6200 can_fall_right = FALSE;
6201 else if (slippery_type == SLIPPERY_ANY_RIGHT_LEFT && can_fall_both)
6202 can_fall_left = FALSE;
6204 can_fall_any = (can_fall_left || can_fall_right);
6205 can_fall_both = (can_fall_left && can_fall_right);
6209 #if USE_NEW_ALL_SLIPPERY
6211 #if USE_NEW_SP_SLIPPERY
6212 /* !!! better use the same properties as for custom elements here !!! */
6213 else if (game.engine_version >= VERSION_IDENT(3,1,1,0) &&
6214 can_fall_both && IS_SP_ELEMENT(Feld[x][y + 1]))
6216 can_fall_right = FALSE; /* slip down on left side */
6217 can_fall_both = FALSE;
6222 #if USE_NEW_ALL_SLIPPERY
6225 if (element == EL_BD_ROCK || element == EL_BD_DIAMOND)
6226 can_fall_right = FALSE; /* slip down on left side */
6228 can_fall_left = !(can_fall_right = RND(2));
6230 can_fall_both = FALSE;
6235 if (game.emulation == EMU_BOULDERDASH ||
6236 element == EL_BD_ROCK || element == EL_BD_DIAMOND)
6237 can_fall_right = FALSE; /* slip down on left side */
6239 can_fall_left = !(can_fall_right = RND(2));
6241 can_fall_both = FALSE;
6247 /* if not determined otherwise, prefer left side for slipping down */
6248 InitMovingField(x, y, can_fall_left ? MV_LEFT : MV_RIGHT);
6249 started_moving = TRUE;
6253 else if (IS_BELT_ACTIVE(Feld[x][y + 1]) && !CAN_MOVE(element))
6255 else if (IS_BELT_ACTIVE(Feld[x][y + 1]))
6258 boolean left_is_free = (x > 0 && IS_FREE(x - 1, y));
6259 boolean right_is_free = (x < lev_fieldx - 1 && IS_FREE(x + 1, y));
6260 int belt_nr = getBeltNrFromBeltActiveElement(Feld[x][y + 1]);
6261 int belt_dir = game.belt_dir[belt_nr];
6263 if ((belt_dir == MV_LEFT && left_is_free) ||
6264 (belt_dir == MV_RIGHT && right_is_free))
6266 int nextx = (belt_dir == MV_LEFT ? x - 1 : x + 1);
6268 InitMovingField(x, y, belt_dir);
6269 started_moving = TRUE;
6271 Pushed[x][y] = TRUE;
6272 Pushed[nextx][y] = TRUE;
6274 GfxAction[x][y] = ACTION_DEFAULT;
6278 MovDir[x][y] = 0; /* if element was moving, stop it */
6283 /* not "else if" because of elements that can fall and move (EL_SPRING) */
6285 if (CAN_MOVE(element) && !started_moving && MovDir[x][y] != MV_NONE)
6287 if (CAN_MOVE(element) && !started_moving)
6290 int move_pattern = element_info[element].move_pattern;
6295 if (MovDir[x][y] == MV_NONE)
6297 printf("StartMoving(): %d,%d: element %d ['%s'] not moving\n",
6298 x, y, element, element_info[element].token_name);
6299 printf("StartMoving(): This should never happen!\n");
6304 Moving2Blocked(x, y, &newx, &newy);
6306 if (IS_PUSHABLE(element) && JustBeingPushed(x, y))
6309 if (game.engine_version >= VERSION_IDENT(3,1,0,0) &&
6310 CheckCollision[x][y] && !IN_LEV_FIELD_AND_IS_FREE(newx, newy))
6312 WasJustMoving[x][y] = 0;
6313 CheckCollision[x][y] = 0;
6315 TestIfElementHitsCustomElement(x, y, MovDir[x][y]);
6317 if (Feld[x][y] != element) /* element has changed */
6321 if (!MovDelay[x][y]) /* start new movement phase */
6323 /* all objects that can change their move direction after each step
6324 (YAMYAM, DARK_YAMYAM and PACMAN go straight until they hit a wall */
6326 if (element != EL_YAMYAM &&
6327 element != EL_DARK_YAMYAM &&
6328 element != EL_PACMAN &&
6329 !(move_pattern & MV_ANY_DIRECTION) &&
6330 move_pattern != MV_TURNING_LEFT &&
6331 move_pattern != MV_TURNING_RIGHT &&
6332 move_pattern != MV_TURNING_LEFT_RIGHT &&
6333 move_pattern != MV_TURNING_RIGHT_LEFT &&
6334 move_pattern != MV_TURNING_RANDOM)
6338 if (MovDelay[x][y] && (element == EL_BUG ||
6339 element == EL_SPACESHIP ||
6340 element == EL_SP_SNIKSNAK ||
6341 element == EL_SP_ELECTRON ||
6342 element == EL_MOLE))
6343 DrawLevelField(x, y);
6347 if (MovDelay[x][y]) /* wait some time before next movement */
6351 if (element == EL_ROBOT ||
6352 element == EL_YAMYAM ||
6353 element == EL_DARK_YAMYAM)
6355 DrawLevelElementAnimationIfNeeded(x, y, element);
6356 PlayLevelSoundAction(x, y, ACTION_WAITING);
6358 else if (element == EL_SP_ELECTRON)
6359 DrawLevelElementAnimationIfNeeded(x, y, element);
6360 else if (element == EL_DRAGON)
6363 int dir = MovDir[x][y];
6364 int dx = (dir == MV_LEFT ? -1 : dir == MV_RIGHT ? +1 : 0);
6365 int dy = (dir == MV_UP ? -1 : dir == MV_DOWN ? +1 : 0);
6366 int graphic = (dir == MV_LEFT ? IMG_FLAMES_1_LEFT :
6367 dir == MV_RIGHT ? IMG_FLAMES_1_RIGHT :
6368 dir == MV_UP ? IMG_FLAMES_1_UP :
6369 dir == MV_DOWN ? IMG_FLAMES_1_DOWN : IMG_EMPTY);
6370 int frame = getGraphicAnimationFrame(graphic, GfxFrame[x][y]);
6372 GfxAction[x][y] = ACTION_ATTACKING;
6374 if (IS_PLAYER(x, y))
6375 DrawPlayerField(x, y);
6377 DrawLevelField(x, y);
6379 PlayLevelSoundActionIfLoop(x, y, ACTION_ATTACKING);
6381 for (i = 1; i <= 3; i++)
6383 int xx = x + i * dx;
6384 int yy = y + i * dy;
6385 int sx = SCREENX(xx);
6386 int sy = SCREENY(yy);
6387 int flame_graphic = graphic + (i - 1);
6389 if (!IN_LEV_FIELD(xx, yy) || IS_DRAGONFIRE_PROOF(Feld[xx][yy]))
6394 int flamed = MovingOrBlocked2Element(xx, yy);
6398 if (IS_CLASSIC_ENEMY(flamed) || CAN_EXPLODE_BY_DRAGONFIRE(flamed))
6400 else if (IS_MOVING(xx, yy) || IS_BLOCKED(xx, yy))
6401 RemoveMovingField(xx, yy);
6403 RemoveField(xx, yy);
6405 if (IS_CLASSIC_ENEMY(flamed) || CAN_EXPLODE_BY_DRAGONFIRE(flamed))
6408 RemoveMovingField(xx, yy);
6411 ChangeDelay[xx][yy] = 0;
6413 Feld[xx][yy] = EL_FLAMES;
6415 if (IN_SCR_FIELD(sx, sy))
6417 DrawLevelFieldCrumbledSand(xx, yy);
6418 DrawGraphic(sx, sy, flame_graphic, frame);
6423 if (Feld[xx][yy] == EL_FLAMES)
6424 Feld[xx][yy] = EL_EMPTY;
6425 DrawLevelField(xx, yy);
6430 if (MovDelay[x][y]) /* element still has to wait some time */
6432 PlayLevelSoundAction(x, y, ACTION_WAITING);
6438 /* now make next step */
6440 Moving2Blocked(x, y, &newx, &newy); /* get next screen position */
6442 if (DONT_COLLIDE_WITH(element) &&
6443 IN_LEV_FIELD(newx, newy) && IS_PLAYER(newx, newy) &&
6444 !PLAYER_ENEMY_PROTECTED(newx, newy))
6446 TestIfBadThingRunsIntoPlayer(x, y, MovDir[x][y]);
6451 else if (CAN_MOVE_INTO_ACID(element) &&
6452 IN_LEV_FIELD(newx, newy) && Feld[newx][newy] == EL_ACID &&
6453 !IS_MV_DIAGONAL(MovDir[x][y]) &&
6454 (MovDir[x][y] == MV_DOWN ||
6455 game.engine_version >= VERSION_IDENT(3,1,0,0)))
6457 SplashAcid(newx, newy);
6458 Store[x][y] = EL_ACID;
6460 else if (element == EL_PENGUIN && IN_LEV_FIELD(newx, newy))
6462 if (Feld[newx][newy] == EL_EXIT_OPEN ||
6463 Feld[newx][newy] == EL_EM_EXIT_OPEN ||
6464 Feld[newx][newy] == EL_STEEL_EXIT_OPEN ||
6465 Feld[newx][newy] == EL_EM_STEEL_EXIT_OPEN)
6468 DrawLevelField(x, y);
6470 PlayLevelSound(newx, newy, SND_PENGUIN_PASSING);
6471 if (IN_SCR_FIELD(SCREENX(newx), SCREENY(newy)))
6472 DrawGraphicThruMask(SCREENX(newx),SCREENY(newy), el2img(element), 0);
6474 local_player->friends_still_needed--;
6475 if (!local_player->friends_still_needed &&
6476 !local_player->GameOver && AllPlayersGone)
6477 PlayerWins(local_player);
6481 else if (IS_FOOD_PENGUIN(Feld[newx][newy]))
6483 if (DigField(local_player, x, y, newx, newy, 0,0, DF_DIG) == MP_MOVING)
6484 DrawLevelField(newx, newy);
6486 GfxDir[x][y] = MovDir[x][y] = MV_NONE;
6488 else if (!IS_FREE(newx, newy))
6490 GfxAction[x][y] = ACTION_WAITING;
6492 if (IS_PLAYER(x, y))
6493 DrawPlayerField(x, y);
6495 DrawLevelField(x, y);
6500 else if (element == EL_PIG && IN_LEV_FIELD(newx, newy))
6502 if (IS_FOOD_PIG(Feld[newx][newy]))
6504 if (IS_MOVING(newx, newy))
6505 RemoveMovingField(newx, newy);
6508 Feld[newx][newy] = EL_EMPTY;
6509 DrawLevelField(newx, newy);
6512 PlayLevelSound(x, y, SND_PIG_DIGGING);
6514 else if (!IS_FREE(newx, newy))
6516 if (IS_PLAYER(x, y))
6517 DrawPlayerField(x, y);
6519 DrawLevelField(x, y);
6524 else if (element == EL_EMC_ANDROID && IN_LEV_FIELD(newx, newy))
6526 if (Store[x][y] != EL_EMPTY)
6528 boolean can_clone = FALSE;
6531 /* check if element to clone is still there */
6532 for (yy = y - 1; yy <= y + 1; yy++) for (xx = x - 1; xx <= x + 1; xx++)
6534 if (IN_LEV_FIELD(xx, yy) && Feld[xx][yy] == Store[x][y])
6542 /* cannot clone or target field not free anymore -- do not clone */
6543 if (!can_clone || !ANDROID_CAN_ENTER_FIELD(element, newx, newy))
6544 Store[x][y] = EL_EMPTY;
6547 if (ANDROID_CAN_ENTER_FIELD(element, newx, newy))
6549 if (IS_MV_DIAGONAL(MovDir[x][y]))
6551 int diagonal_move_dir = MovDir[x][y];
6552 int stored = Store[x][y];
6553 int change_delay = 8;
6556 /* android is moving diagonally */
6558 CreateField(x, y, EL_DIAGONAL_SHRINKING);
6560 Store[x][y] = (stored == EL_ACID ? EL_EMPTY : stored);
6561 GfxElement[x][y] = EL_EMC_ANDROID;
6562 GfxAction[x][y] = ACTION_SHRINKING;
6563 GfxDir[x][y] = diagonal_move_dir;
6564 ChangeDelay[x][y] = change_delay;
6566 graphic = el_act_dir2img(GfxElement[x][y], GfxAction[x][y],
6569 DrawLevelGraphicAnimation(x, y, graphic);
6570 PlayLevelSoundAction(x, y, ACTION_SHRINKING);
6572 if (Feld[newx][newy] == EL_ACID)
6574 SplashAcid(newx, newy);
6579 CreateField(newx, newy, EL_DIAGONAL_GROWING);
6581 Store[newx][newy] = EL_EMC_ANDROID;
6582 GfxElement[newx][newy] = EL_EMC_ANDROID;
6583 GfxAction[newx][newy] = ACTION_GROWING;
6584 GfxDir[newx][newy] = diagonal_move_dir;
6585 ChangeDelay[newx][newy] = change_delay;
6587 graphic = el_act_dir2img(GfxElement[newx][newy],
6588 GfxAction[newx][newy], GfxDir[newx][newy]);
6590 DrawLevelGraphicAnimation(newx, newy, graphic);
6591 PlayLevelSoundAction(newx, newy, ACTION_GROWING);
6597 Feld[newx][newy] = EL_EMPTY;
6598 DrawLevelField(newx, newy);
6600 PlayLevelSoundAction(x, y, ACTION_DIGGING);
6603 else if (!IS_FREE(newx, newy))
6606 if (IS_PLAYER(x, y))
6607 DrawPlayerField(x, y);
6609 DrawLevelField(x, y);
6615 else if (IS_CUSTOM_ELEMENT(element) &&
6616 CUSTOM_ELEMENT_CAN_ENTER_FIELD(element, newx, newy))
6618 int new_element = Feld[newx][newy];
6620 if (!IS_FREE(newx, newy))
6622 int action = (IS_DIGGABLE(new_element) ? ACTION_DIGGING :
6623 IS_COLLECTIBLE(new_element) ? ACTION_COLLECTING :
6626 /* no element can dig solid indestructible elements */
6627 if (IS_INDESTRUCTIBLE(new_element) &&
6628 !IS_DIGGABLE(new_element) &&
6629 !IS_COLLECTIBLE(new_element))
6632 if (AmoebaNr[newx][newy] &&
6633 (new_element == EL_AMOEBA_FULL ||
6634 new_element == EL_BD_AMOEBA ||
6635 new_element == EL_AMOEBA_GROWING))
6637 AmoebaCnt[AmoebaNr[newx][newy]]--;
6638 AmoebaCnt2[AmoebaNr[newx][newy]]--;
6641 if (IS_MOVING(newx, newy))
6642 RemoveMovingField(newx, newy);
6645 RemoveField(newx, newy);
6646 DrawLevelField(newx, newy);
6649 /* if digged element was about to explode, prevent the explosion */
6650 ExplodeField[newx][newy] = EX_TYPE_NONE;
6652 PlayLevelSoundAction(x, y, action);
6655 Store[newx][newy] = EL_EMPTY;
6657 /* this makes it possible to leave the removed element again */
6658 if (IS_EQUAL_OR_IN_GROUP(new_element, MOVE_ENTER_EL(element)))
6659 Store[newx][newy] = new_element;
6661 if (IS_EQUAL_OR_IN_GROUP(new_element, MOVE_ENTER_EL(element)))
6663 int move_leave_element = element_info[element].move_leave_element;
6665 /* this makes it possible to leave the removed element again */
6666 Store[newx][newy] = (move_leave_element == EL_TRIGGER_ELEMENT ?
6667 new_element : move_leave_element);
6671 if (move_pattern & MV_MAZE_RUNNER_STYLE)
6673 RunnerVisit[x][y] = FrameCounter;
6674 PlayerVisit[x][y] /= 8; /* expire player visit path */
6677 else if (element == EL_DRAGON && IN_LEV_FIELD(newx, newy))
6679 if (!IS_FREE(newx, newy))
6681 if (IS_PLAYER(x, y))
6682 DrawPlayerField(x, y);
6684 DrawLevelField(x, y);
6690 boolean wanna_flame = !RND(10);
6691 int dx = newx - x, dy = newy - y;
6692 int newx1 = newx + 1 * dx, newy1 = newy + 1 * dy;
6693 int newx2 = newx + 2 * dx, newy2 = newy + 2 * dy;
6694 int element1 = (IN_LEV_FIELD(newx1, newy1) ?
6695 MovingOrBlocked2Element(newx1, newy1) : EL_STEELWALL);
6696 int element2 = (IN_LEV_FIELD(newx2, newy2) ?
6697 MovingOrBlocked2Element(newx2, newy2) : EL_STEELWALL);
6700 IS_CLASSIC_ENEMY(element1) ||
6701 IS_CLASSIC_ENEMY(element2)) &&
6702 element1 != EL_DRAGON && element2 != EL_DRAGON &&
6703 element1 != EL_FLAMES && element2 != EL_FLAMES)
6705 ResetGfxAnimation(x, y);
6706 GfxAction[x][y] = ACTION_ATTACKING;
6708 if (IS_PLAYER(x, y))
6709 DrawPlayerField(x, y);
6711 DrawLevelField(x, y);
6713 PlayLevelSound(x, y, SND_DRAGON_ATTACKING);
6715 MovDelay[x][y] = 50;
6719 RemoveField(newx, newy);
6721 Feld[newx][newy] = EL_FLAMES;
6722 if (IN_LEV_FIELD(newx1, newy1) && Feld[newx1][newy1] == EL_EMPTY)
6725 RemoveField(newx1, newy1);
6727 Feld[newx1][newy1] = EL_FLAMES;
6729 if (IN_LEV_FIELD(newx2, newy2) && Feld[newx2][newy2] == EL_EMPTY)
6732 RemoveField(newx2, newy2);
6734 Feld[newx2][newy2] = EL_FLAMES;
6741 else if (element == EL_YAMYAM && IN_LEV_FIELD(newx, newy) &&
6742 Feld[newx][newy] == EL_DIAMOND)
6744 if (IS_MOVING(newx, newy))
6745 RemoveMovingField(newx, newy);
6748 Feld[newx][newy] = EL_EMPTY;
6749 DrawLevelField(newx, newy);
6752 PlayLevelSound(x, y, SND_YAMYAM_DIGGING);
6754 else if (element == EL_DARK_YAMYAM && IN_LEV_FIELD(newx, newy) &&
6755 IS_FOOD_DARK_YAMYAM(Feld[newx][newy]))
6757 if (AmoebaNr[newx][newy])
6759 AmoebaCnt2[AmoebaNr[newx][newy]]--;
6760 if (Feld[newx][newy] == EL_AMOEBA_FULL ||
6761 Feld[newx][newy] == EL_BD_AMOEBA)
6762 AmoebaCnt[AmoebaNr[newx][newy]]--;
6767 if (IS_MOVING(newx, newy) || IS_BLOCKED(newx, newy))
6769 RemoveMovingField(newx, newy);
6772 if (IS_MOVING(newx, newy))
6774 RemoveMovingField(newx, newy);
6779 Feld[newx][newy] = EL_EMPTY;
6780 DrawLevelField(newx, newy);
6783 PlayLevelSound(x, y, SND_DARK_YAMYAM_DIGGING);
6785 else if ((element == EL_PACMAN || element == EL_MOLE)
6786 && IN_LEV_FIELD(newx, newy) && IS_AMOEBOID(Feld[newx][newy]))
6788 if (AmoebaNr[newx][newy])
6790 AmoebaCnt2[AmoebaNr[newx][newy]]--;
6791 if (Feld[newx][newy] == EL_AMOEBA_FULL ||
6792 Feld[newx][newy] == EL_BD_AMOEBA)
6793 AmoebaCnt[AmoebaNr[newx][newy]]--;
6796 if (element == EL_MOLE)
6798 Feld[newx][newy] = EL_AMOEBA_SHRINKING;
6799 PlayLevelSound(x, y, SND_MOLE_DIGGING);
6801 ResetGfxAnimation(x, y);
6802 GfxAction[x][y] = ACTION_DIGGING;
6803 DrawLevelField(x, y);
6805 MovDelay[newx][newy] = 0; /* start amoeba shrinking delay */
6807 return; /* wait for shrinking amoeba */
6809 else /* element == EL_PACMAN */
6811 Feld[newx][newy] = EL_EMPTY;
6812 DrawLevelField(newx, newy);
6813 PlayLevelSound(x, y, SND_PACMAN_DIGGING);
6816 else if (element == EL_MOLE && IN_LEV_FIELD(newx, newy) &&
6817 (Feld[newx][newy] == EL_AMOEBA_SHRINKING ||
6818 (Feld[newx][newy] == EL_EMPTY && Stop[newx][newy])))
6820 /* wait for shrinking amoeba to completely disappear */
6823 else if (!IN_LEV_FIELD(newx, newy) || !IS_FREE(newx, newy))
6825 /* object was running against a wall */
6830 /* !!! NEW "CE_BLOCKED" STUFF !!! -- DOES NOT WORK YET... !!! */
6831 if (move_pattern & MV_ANY_DIRECTION &&
6832 move_pattern == MovDir[x][y])
6834 int blocking_element =
6835 (IN_LEV_FIELD(newx, newy) ? Feld[newx][newy] : BorderElement);
6837 CheckElementChangeBySide(x, y, element, blocking_element, CE_BLOCKED,
6840 element = Feld[x][y]; /* element might have changed */
6844 if (GFX_ELEMENT(element) != EL_SAND) /* !!! FIX THIS (crumble) !!! */
6845 DrawLevelElementAnimation(x, y, element);
6847 if (DONT_TOUCH(element))
6848 TestIfBadThingTouchesPlayer(x, y);
6853 InitMovingField(x, y, MovDir[x][y]);
6855 PlayLevelSoundAction(x, y, ACTION_MOVING);
6859 ContinueMoving(x, y);
6862 void ContinueMoving(int x, int y)
6864 int element = Feld[x][y];
6865 struct ElementInfo *ei = &element_info[element];
6866 int direction = MovDir[x][y];
6867 int dx = (direction == MV_LEFT ? -1 : direction == MV_RIGHT ? +1 : 0);
6868 int dy = (direction == MV_UP ? -1 : direction == MV_DOWN ? +1 : 0);
6869 int newx = x + dx, newy = y + dy;
6870 int stored = Store[x][y];
6871 int stored_new = Store[newx][newy];
6872 boolean pushed_by_player = (Pushed[x][y] && IS_PLAYER(x, y));
6873 boolean pushed_by_conveyor = (Pushed[x][y] && !IS_PLAYER(x, y));
6874 boolean last_line = (newy == lev_fieldy - 1);
6876 MovPos[x][y] += getElementMoveStepsize(x, y);
6878 if (pushed_by_player) /* special case: moving object pushed by player */
6879 MovPos[x][y] = SIGN(MovPos[x][y]) * (TILEX - ABS(PLAYERINFO(x,y)->MovPos));
6881 if (ABS(MovPos[x][y]) < TILEX)
6883 DrawLevelField(x, y);
6885 return; /* element is still moving */
6888 /* element reached destination field */
6890 Feld[x][y] = EL_EMPTY;
6891 Feld[newx][newy] = element;
6892 MovPos[x][y] = 0; /* force "not moving" for "crumbled sand" */
6894 if (Store[x][y] == EL_ACID) /* element is moving into acid pool */
6896 element = Feld[newx][newy] = EL_ACID;
6898 else if (element == EL_MOLE)
6900 Feld[x][y] = EL_SAND;
6902 DrawLevelFieldCrumbledSandNeighbours(x, y);
6904 else if (element == EL_QUICKSAND_FILLING)
6906 element = Feld[newx][newy] = get_next_element(element);
6907 Store[newx][newy] = Store[x][y];
6909 else if (element == EL_QUICKSAND_EMPTYING)
6911 Feld[x][y] = get_next_element(element);
6912 element = Feld[newx][newy] = Store[x][y];
6914 else if (element == EL_QUICKSAND_FAST_FILLING)
6916 element = Feld[newx][newy] = get_next_element(element);
6917 Store[newx][newy] = Store[x][y];
6919 else if (element == EL_QUICKSAND_FAST_EMPTYING)
6921 Feld[x][y] = get_next_element(element);
6922 element = Feld[newx][newy] = Store[x][y];
6924 else if (element == EL_MAGIC_WALL_FILLING)
6926 element = Feld[newx][newy] = get_next_element(element);
6927 if (!game.magic_wall_active)
6928 element = Feld[newx][newy] = EL_MAGIC_WALL_DEAD;
6929 Store[newx][newy] = Store[x][y];
6931 else if (element == EL_MAGIC_WALL_EMPTYING)
6933 Feld[x][y] = get_next_element(element);
6934 if (!game.magic_wall_active)
6935 Feld[x][y] = EL_MAGIC_WALL_DEAD;
6936 element = Feld[newx][newy] = Store[x][y];
6938 #if USE_NEW_CUSTOM_VALUE
6939 InitField(newx, newy, FALSE);
6942 else if (element == EL_BD_MAGIC_WALL_FILLING)
6944 element = Feld[newx][newy] = get_next_element(element);
6945 if (!game.magic_wall_active)
6946 element = Feld[newx][newy] = EL_BD_MAGIC_WALL_DEAD;
6947 Store[newx][newy] = Store[x][y];
6949 else if (element == EL_BD_MAGIC_WALL_EMPTYING)
6951 Feld[x][y] = get_next_element(element);
6952 if (!game.magic_wall_active)
6953 Feld[x][y] = EL_BD_MAGIC_WALL_DEAD;
6954 element = Feld[newx][newy] = Store[x][y];
6956 #if USE_NEW_CUSTOM_VALUE
6957 InitField(newx, newy, FALSE);
6960 else if (element == EL_DC_MAGIC_WALL_FILLING)
6962 element = Feld[newx][newy] = get_next_element(element);
6963 if (!game.magic_wall_active)
6964 element = Feld[newx][newy] = EL_DC_MAGIC_WALL_DEAD;
6965 Store[newx][newy] = Store[x][y];
6967 else if (element == EL_DC_MAGIC_WALL_EMPTYING)
6969 Feld[x][y] = get_next_element(element);
6970 if (!game.magic_wall_active)
6971 Feld[x][y] = EL_DC_MAGIC_WALL_DEAD;
6972 element = Feld[newx][newy] = Store[x][y];
6974 #if USE_NEW_CUSTOM_VALUE
6975 InitField(newx, newy, FALSE);
6978 else if (element == EL_AMOEBA_DROPPING)
6980 Feld[x][y] = get_next_element(element);
6981 element = Feld[newx][newy] = Store[x][y];
6983 else if (element == EL_SOKOBAN_OBJECT)
6986 Feld[x][y] = Back[x][y];
6988 if (Back[newx][newy])
6989 Feld[newx][newy] = EL_SOKOBAN_FIELD_FULL;
6991 Back[x][y] = Back[newx][newy] = 0;
6994 Store[x][y] = EL_EMPTY;
6999 MovDelay[newx][newy] = 0;
7001 if (CAN_CHANGE_OR_HAS_ACTION(element))
7003 /* copy element change control values to new field */
7004 ChangeDelay[newx][newy] = ChangeDelay[x][y];
7005 ChangePage[newx][newy] = ChangePage[x][y];
7006 ChangeCount[newx][newy] = ChangeCount[x][y];
7007 ChangeEvent[newx][newy] = ChangeEvent[x][y];
7010 #if USE_NEW_CUSTOM_VALUE
7011 CustomValue[newx][newy] = CustomValue[x][y];
7014 ChangeDelay[x][y] = 0;
7015 ChangePage[x][y] = -1;
7016 ChangeCount[x][y] = 0;
7017 ChangeEvent[x][y] = -1;
7019 #if USE_NEW_CUSTOM_VALUE
7020 CustomValue[x][y] = 0;
7023 /* copy animation control values to new field */
7024 GfxFrame[newx][newy] = GfxFrame[x][y];
7025 GfxRandom[newx][newy] = GfxRandom[x][y]; /* keep same random value */
7026 GfxAction[newx][newy] = GfxAction[x][y]; /* keep action one frame */
7027 GfxDir[newx][newy] = GfxDir[x][y]; /* keep element direction */
7029 Pushed[x][y] = Pushed[newx][newy] = FALSE;
7031 /* some elements can leave other elements behind after moving */
7033 if (ei->move_leave_element != EL_EMPTY &&
7034 (ei->move_leave_type == LEAVE_TYPE_UNLIMITED || stored != EL_EMPTY) &&
7035 (!IS_PLAYER(x, y) || IS_WALKABLE(ei->move_leave_element)))
7037 if (IS_CUSTOM_ELEMENT(element) && ei->move_leave_element != EL_EMPTY &&
7038 (ei->move_leave_type == LEAVE_TYPE_UNLIMITED || stored != EL_EMPTY) &&
7039 (!IS_PLAYER(x, y) || IS_WALKABLE(ei->move_leave_element)))
7042 int move_leave_element = ei->move_leave_element;
7046 /* this makes it possible to leave the removed element again */
7047 if (ei->move_leave_element == EL_TRIGGER_ELEMENT)
7048 move_leave_element = (stored == EL_ACID ? EL_EMPTY : stored);
7050 /* this makes it possible to leave the removed element again */
7051 if (ei->move_leave_element == EL_TRIGGER_ELEMENT)
7052 move_leave_element = stored;
7055 /* this makes it possible to leave the removed element again */
7056 if (ei->move_leave_type == LEAVE_TYPE_LIMITED &&
7057 ei->move_leave_element == EL_TRIGGER_ELEMENT)
7058 move_leave_element = stored;
7061 Feld[x][y] = move_leave_element;
7063 if (element_info[Feld[x][y]].move_direction_initial == MV_START_PREVIOUS)
7064 MovDir[x][y] = direction;
7066 InitField(x, y, FALSE);
7068 if (GFX_CRUMBLED(Feld[x][y]))
7069 DrawLevelFieldCrumbledSandNeighbours(x, y);
7071 if (ELEM_IS_PLAYER(move_leave_element))
7072 RelocatePlayer(x, y, move_leave_element);
7075 /* do this after checking for left-behind element */
7076 ResetGfxAnimation(x, y); /* reset animation values for old field */
7078 if (!CAN_MOVE(element) ||
7079 (CAN_FALL(element) && direction == MV_DOWN &&
7080 (element == EL_SPRING ||
7081 element_info[element].move_pattern == MV_WHEN_PUSHED ||
7082 element_info[element].move_pattern == MV_WHEN_DROPPED)))
7083 GfxDir[x][y] = MovDir[newx][newy] = 0;
7085 DrawLevelField(x, y);
7086 DrawLevelField(newx, newy);
7088 Stop[newx][newy] = TRUE; /* ignore this element until the next frame */
7090 /* prevent pushed element from moving on in pushed direction */
7091 if (pushed_by_player && CAN_MOVE(element) &&
7092 element_info[element].move_pattern & MV_ANY_DIRECTION &&
7093 !(element_info[element].move_pattern & direction))
7094 TurnRound(newx, newy);
7096 /* prevent elements on conveyor belt from moving on in last direction */
7097 if (pushed_by_conveyor && CAN_FALL(element) &&
7098 direction & MV_HORIZONTAL)
7099 MovDir[newx][newy] = 0;
7101 if (!pushed_by_player)
7103 int nextx = newx + dx, nexty = newy + dy;
7104 boolean check_collision_again = IN_LEV_FIELD_AND_IS_FREE(nextx, nexty);
7106 WasJustMoving[newx][newy] = CHECK_DELAY_MOVING;
7108 if (CAN_FALL(element) && direction == MV_DOWN)
7109 WasJustFalling[newx][newy] = CHECK_DELAY_FALLING;
7111 if ((!CAN_FALL(element) || direction == MV_DOWN) && check_collision_again)
7112 CheckCollision[newx][newy] = CHECK_DELAY_COLLISION;
7114 #if USE_FIX_IMPACT_COLLISION
7115 if (CAN_FALL(element) && direction == MV_DOWN && check_collision_again)
7116 CheckImpact[newx][newy] = CHECK_DELAY_IMPACT;
7120 if (DONT_TOUCH(element)) /* object may be nasty to player or others */
7122 TestIfBadThingTouchesPlayer(newx, newy);
7123 TestIfBadThingTouchesFriend(newx, newy);
7125 if (!IS_CUSTOM_ELEMENT(element))
7126 TestIfBadThingTouchesOtherBadThing(newx, newy);
7128 else if (element == EL_PENGUIN)
7129 TestIfFriendTouchesBadThing(newx, newy);
7131 /* give the player one last chance (one more frame) to move away */
7132 if (CAN_FALL(element) && direction == MV_DOWN &&
7133 (last_line || (!IS_FREE(x, newy + 1) &&
7134 (!IS_PLAYER(x, newy + 1) ||
7135 game.engine_version < VERSION_IDENT(3,1,1,0)))))
7138 if (pushed_by_player && !game.use_change_when_pushing_bug)
7140 int push_side = MV_DIR_OPPOSITE(direction);
7141 struct PlayerInfo *player = PLAYERINFO(x, y);
7143 CheckElementChangeByPlayer(newx, newy, element, CE_PUSHED_BY_PLAYER,
7144 player->index_bit, push_side);
7145 CheckTriggeredElementChangeByPlayer(newx,newy, element, CE_PLAYER_PUSHES_X,
7146 player->index_bit, push_side);
7149 if (element == EL_EMC_ANDROID && pushed_by_player) /* make another move */
7150 MovDelay[newx][newy] = 1;
7152 CheckTriggeredElementChangeBySide(x, y, element, CE_MOVE_OF_X, direction);
7154 TestIfElementTouchesCustomElement(x, y); /* empty or new element */
7157 if (ChangePage[newx][newy] != -1) /* delayed change */
7159 int page = ChangePage[newx][newy];
7160 struct ElementChangeInfo *change = &ei->change_page[page];
7162 ChangePage[newx][newy] = -1;
7164 if (change->can_change)
7166 if (ChangeElement(newx, newy, element, page))
7168 if (change->post_change_function)
7169 change->post_change_function(newx, newy);
7173 if (change->has_action)
7174 ExecuteCustomElementAction(newx, newy, element, page);
7178 TestIfElementHitsCustomElement(newx, newy, direction);
7179 TestIfPlayerTouchesCustomElement(newx, newy);
7180 TestIfElementTouchesCustomElement(newx, newy);
7182 if (IS_CUSTOM_ELEMENT(element) && ei->move_enter_element != EL_EMPTY &&
7183 IS_EQUAL_OR_IN_GROUP(stored_new, ei->move_enter_element))
7184 CheckElementChangeBySide(newx, newy, element, stored_new, CE_DIGGING_X,
7185 MV_DIR_OPPOSITE(direction));
7188 int AmoebeNachbarNr(int ax, int ay)
7191 int element = Feld[ax][ay];
7193 static int xy[4][2] =
7201 for (i = 0; i < NUM_DIRECTIONS; i++)
7203 int x = ax + xy[i][0];
7204 int y = ay + xy[i][1];
7206 if (!IN_LEV_FIELD(x, y))
7209 if (Feld[x][y] == element && AmoebaNr[x][y] > 0)
7210 group_nr = AmoebaNr[x][y];
7216 void AmoebenVereinigen(int ax, int ay)
7218 int i, x, y, xx, yy;
7219 int new_group_nr = AmoebaNr[ax][ay];
7220 static int xy[4][2] =
7228 if (new_group_nr == 0)
7231 for (i = 0; i < NUM_DIRECTIONS; i++)
7236 if (!IN_LEV_FIELD(x, y))
7239 if ((Feld[x][y] == EL_AMOEBA_FULL ||
7240 Feld[x][y] == EL_BD_AMOEBA ||
7241 Feld[x][y] == EL_AMOEBA_DEAD) &&
7242 AmoebaNr[x][y] != new_group_nr)
7244 int old_group_nr = AmoebaNr[x][y];
7246 if (old_group_nr == 0)
7249 AmoebaCnt[new_group_nr] += AmoebaCnt[old_group_nr];
7250 AmoebaCnt[old_group_nr] = 0;
7251 AmoebaCnt2[new_group_nr] += AmoebaCnt2[old_group_nr];
7252 AmoebaCnt2[old_group_nr] = 0;
7254 SCAN_PLAYFIELD(xx, yy)
7256 if (AmoebaNr[xx][yy] == old_group_nr)
7257 AmoebaNr[xx][yy] = new_group_nr;
7263 void AmoebeUmwandeln(int ax, int ay)
7267 if (Feld[ax][ay] == EL_AMOEBA_DEAD)
7269 int group_nr = AmoebaNr[ax][ay];
7274 printf("AmoebeUmwandeln(): ax = %d, ay = %d\n", ax, ay);
7275 printf("AmoebeUmwandeln(): This should never happen!\n");
7280 SCAN_PLAYFIELD(x, y)
7282 if (Feld[x][y] == EL_AMOEBA_DEAD && AmoebaNr[x][y] == group_nr)
7285 Feld[x][y] = EL_AMOEBA_TO_DIAMOND;
7289 PlayLevelSound(ax, ay, (IS_GEM(level.amoeba_content) ?
7290 SND_AMOEBA_TURNING_TO_GEM :
7291 SND_AMOEBA_TURNING_TO_ROCK));
7296 static int xy[4][2] =
7304 for (i = 0; i < NUM_DIRECTIONS; i++)
7309 if (!IN_LEV_FIELD(x, y))
7312 if (Feld[x][y] == EL_AMOEBA_TO_DIAMOND)
7314 PlayLevelSound(x, y, (IS_GEM(level.amoeba_content) ?
7315 SND_AMOEBA_TURNING_TO_GEM :
7316 SND_AMOEBA_TURNING_TO_ROCK));
7323 void AmoebeUmwandelnBD(int ax, int ay, int new_element)
7326 int group_nr = AmoebaNr[ax][ay];
7327 boolean done = FALSE;
7332 printf("AmoebeUmwandelnBD(): ax = %d, ay = %d\n", ax, ay);
7333 printf("AmoebeUmwandelnBD(): This should never happen!\n");
7338 SCAN_PLAYFIELD(x, y)
7340 if (AmoebaNr[x][y] == group_nr &&
7341 (Feld[x][y] == EL_AMOEBA_DEAD ||
7342 Feld[x][y] == EL_BD_AMOEBA ||
7343 Feld[x][y] == EL_AMOEBA_GROWING))
7346 Feld[x][y] = new_element;
7347 InitField(x, y, FALSE);
7348 DrawLevelField(x, y);
7354 PlayLevelSound(ax, ay, (new_element == EL_BD_ROCK ?
7355 SND_BD_AMOEBA_TURNING_TO_ROCK :
7356 SND_BD_AMOEBA_TURNING_TO_GEM));
7359 void AmoebeWaechst(int x, int y)
7361 static unsigned long sound_delay = 0;
7362 static unsigned long sound_delay_value = 0;
7364 if (!MovDelay[x][y]) /* start new growing cycle */
7368 if (DelayReached(&sound_delay, sound_delay_value))
7370 PlayLevelSoundElementAction(x, y, Store[x][y], ACTION_GROWING);
7371 sound_delay_value = 30;
7375 if (MovDelay[x][y]) /* wait some time before growing bigger */
7378 if (MovDelay[x][y]/2 && IN_SCR_FIELD(SCREENX(x), SCREENY(y)))
7380 int frame = getGraphicAnimationFrame(IMG_AMOEBA_GROWING,
7381 6 - MovDelay[x][y]);
7383 DrawGraphic(SCREENX(x), SCREENY(y), IMG_AMOEBA_GROWING, frame);
7386 if (!MovDelay[x][y])
7388 Feld[x][y] = Store[x][y];
7390 DrawLevelField(x, y);
7395 void AmoebaDisappearing(int x, int y)
7397 static unsigned long sound_delay = 0;
7398 static unsigned long sound_delay_value = 0;
7400 if (!MovDelay[x][y]) /* start new shrinking cycle */
7404 if (DelayReached(&sound_delay, sound_delay_value))
7405 sound_delay_value = 30;
7408 if (MovDelay[x][y]) /* wait some time before shrinking */
7411 if (MovDelay[x][y]/2 && IN_SCR_FIELD(SCREENX(x), SCREENY(y)))
7413 int frame = getGraphicAnimationFrame(IMG_AMOEBA_SHRINKING,
7414 6 - MovDelay[x][y]);
7416 DrawGraphic(SCREENX(x), SCREENY(y), IMG_AMOEBA_SHRINKING, frame);
7419 if (!MovDelay[x][y])
7421 Feld[x][y] = EL_EMPTY;
7422 DrawLevelField(x, y);
7424 /* don't let mole enter this field in this cycle;
7425 (give priority to objects falling to this field from above) */
7431 void AmoebeAbleger(int ax, int ay)
7434 int element = Feld[ax][ay];
7435 int graphic = el2img(element);
7436 int newax = ax, neway = ay;
7437 boolean can_drop = (element == EL_AMOEBA_WET || element == EL_EMC_DRIPPER);
7438 static int xy[4][2] =
7446 if (!level.amoeba_speed && element != EL_EMC_DRIPPER)
7448 Feld[ax][ay] = EL_AMOEBA_DEAD;
7449 DrawLevelField(ax, ay);
7453 if (IS_ANIMATED(graphic))
7454 DrawLevelGraphicAnimationIfNeeded(ax, ay, graphic);
7456 if (!MovDelay[ax][ay]) /* start making new amoeba field */
7457 MovDelay[ax][ay] = RND(FRAMES_PER_SECOND * 25 / (1 + level.amoeba_speed));
7459 if (MovDelay[ax][ay]) /* wait some time before making new amoeba */
7462 if (MovDelay[ax][ay])
7466 if (can_drop) /* EL_AMOEBA_WET or EL_EMC_DRIPPER */
7469 int x = ax + xy[start][0];
7470 int y = ay + xy[start][1];
7472 if (!IN_LEV_FIELD(x, y))
7475 if (IS_FREE(x, y) ||
7476 CAN_GROW_INTO(Feld[x][y]) ||
7477 Feld[x][y] == EL_QUICKSAND_EMPTY ||
7478 Feld[x][y] == EL_QUICKSAND_FAST_EMPTY)
7484 if (newax == ax && neway == ay)
7487 else /* normal or "filled" (BD style) amoeba */
7490 boolean waiting_for_player = FALSE;
7492 for (i = 0; i < NUM_DIRECTIONS; i++)
7494 int j = (start + i) % 4;
7495 int x = ax + xy[j][0];
7496 int y = ay + xy[j][1];
7498 if (!IN_LEV_FIELD(x, y))
7501 if (IS_FREE(x, y) ||
7502 CAN_GROW_INTO(Feld[x][y]) ||
7503 Feld[x][y] == EL_QUICKSAND_EMPTY ||
7504 Feld[x][y] == EL_QUICKSAND_FAST_EMPTY)
7510 else if (IS_PLAYER(x, y))
7511 waiting_for_player = TRUE;
7514 if (newax == ax && neway == ay) /* amoeba cannot grow */
7516 if (i == 4 && (!waiting_for_player || element == EL_BD_AMOEBA))
7518 Feld[ax][ay] = EL_AMOEBA_DEAD;
7519 DrawLevelField(ax, ay);
7520 AmoebaCnt[AmoebaNr[ax][ay]]--;
7522 if (AmoebaCnt[AmoebaNr[ax][ay]] <= 0) /* amoeba is completely dead */
7524 if (element == EL_AMOEBA_FULL)
7525 AmoebeUmwandeln(ax, ay);
7526 else if (element == EL_BD_AMOEBA)
7527 AmoebeUmwandelnBD(ax, ay, level.amoeba_content);
7532 else if (element == EL_AMOEBA_FULL || element == EL_BD_AMOEBA)
7534 /* amoeba gets larger by growing in some direction */
7536 int new_group_nr = AmoebaNr[ax][ay];
7539 if (new_group_nr == 0)
7541 printf("AmoebeAbleger(): newax = %d, neway = %d\n", newax, neway);
7542 printf("AmoebeAbleger(): This should never happen!\n");
7547 AmoebaNr[newax][neway] = new_group_nr;
7548 AmoebaCnt[new_group_nr]++;
7549 AmoebaCnt2[new_group_nr]++;
7551 /* if amoeba touches other amoeba(s) after growing, unify them */
7552 AmoebenVereinigen(newax, neway);
7554 if (element == EL_BD_AMOEBA && AmoebaCnt2[new_group_nr] >= 200)
7556 AmoebeUmwandelnBD(newax, neway, EL_BD_ROCK);
7562 if (!can_drop || neway < ay || !IS_FREE(newax, neway) ||
7563 (neway == lev_fieldy - 1 && newax != ax))
7565 Feld[newax][neway] = EL_AMOEBA_GROWING; /* creation of new amoeba */
7566 Store[newax][neway] = element;
7568 else if (neway == ay || element == EL_EMC_DRIPPER)
7570 Feld[newax][neway] = EL_AMOEBA_DROP; /* drop left/right of amoeba */
7572 PlayLevelSoundAction(newax, neway, ACTION_GROWING);
7576 InitMovingField(ax, ay, MV_DOWN); /* drop dripping from amoeba */
7577 Feld[ax][ay] = EL_AMOEBA_DROPPING;
7578 Store[ax][ay] = EL_AMOEBA_DROP;
7579 ContinueMoving(ax, ay);
7583 DrawLevelField(newax, neway);
7586 void Life(int ax, int ay)
7590 int element = Feld[ax][ay];
7591 int graphic = el2img(element);
7592 int *life_parameter = (element == EL_GAME_OF_LIFE ? level.game_of_life :
7594 boolean changed = FALSE;
7596 if (IS_ANIMATED(graphic))
7597 DrawLevelGraphicAnimationIfNeeded(ax, ay, graphic);
7602 if (!MovDelay[ax][ay]) /* start new "game of life" cycle */
7603 MovDelay[ax][ay] = life_time;
7605 if (MovDelay[ax][ay]) /* wait some time before next cycle */
7608 if (MovDelay[ax][ay])
7612 for (y1 = -1; y1 < 2; y1++) for (x1 = -1; x1 < 2; x1++)
7614 int xx = ax+x1, yy = ay+y1;
7617 if (!IN_LEV_FIELD(xx, yy))
7620 for (y2 = -1; y2 < 2; y2++) for (x2 = -1; x2 < 2; x2++)
7622 int x = xx+x2, y = yy+y2;
7624 if (!IN_LEV_FIELD(x, y) || (x == xx && y == yy))
7627 if (((Feld[x][y] == element ||
7628 (element == EL_GAME_OF_LIFE && IS_PLAYER(x, y))) &&
7630 (IS_FREE(x, y) && Stop[x][y]))
7634 if (xx == ax && yy == ay) /* field in the middle */
7636 if (nachbarn < life_parameter[0] ||
7637 nachbarn > life_parameter[1])
7639 Feld[xx][yy] = EL_EMPTY;
7641 DrawLevelField(xx, yy);
7642 Stop[xx][yy] = TRUE;
7646 else if (IS_FREE(xx, yy) || CAN_GROW_INTO(Feld[xx][yy]))
7647 { /* free border field */
7648 if (nachbarn >= life_parameter[2] &&
7649 nachbarn <= life_parameter[3])
7651 Feld[xx][yy] = element;
7652 MovDelay[xx][yy] = (element == EL_GAME_OF_LIFE ? 0 : life_time-1);
7654 DrawLevelField(xx, yy);
7655 Stop[xx][yy] = TRUE;
7662 PlayLevelSound(ax, ay, element == EL_BIOMAZE ? SND_BIOMAZE_GROWING :
7663 SND_GAME_OF_LIFE_GROWING);
7666 static void InitRobotWheel(int x, int y)
7668 ChangeDelay[x][y] = level.time_wheel * FRAMES_PER_SECOND;
7671 static void RunRobotWheel(int x, int y)
7673 PlayLevelSound(x, y, SND_ROBOT_WHEEL_ACTIVE);
7676 static void StopRobotWheel(int x, int y)
7678 if (ZX == x && ZY == y)
7682 static void InitTimegateWheel(int x, int y)
7684 ChangeDelay[x][y] = level.time_timegate * FRAMES_PER_SECOND;
7687 static void RunTimegateWheel(int x, int y)
7689 PlayLevelSound(x, y, SND_CLASS_TIMEGATE_SWITCH_ACTIVE);
7692 static void InitMagicBallDelay(int x, int y)
7695 ChangeDelay[x][y] = (level.ball_time + 1) * 8 + 1;
7697 ChangeDelay[x][y] = level.ball_time * FRAMES_PER_SECOND + 1;
7701 static void ActivateMagicBall(int bx, int by)
7705 if (level.ball_random)
7707 int pos_border = RND(8); /* select one of the eight border elements */
7708 int pos_content = (pos_border > 3 ? pos_border + 1 : pos_border);
7709 int xx = pos_content % 3;
7710 int yy = pos_content / 3;
7715 if (IN_LEV_FIELD(x, y) && Feld[x][y] == EL_EMPTY)
7716 CreateField(x, y, level.ball_content[game.ball_content_nr].e[xx][yy]);
7720 for (y = by - 1; y <= by + 1; y++) for (x = bx - 1; x <= bx + 1; x++)
7722 int xx = x - bx + 1;
7723 int yy = y - by + 1;
7725 if (IN_LEV_FIELD(x, y) && Feld[x][y] == EL_EMPTY)
7726 CreateField(x, y, level.ball_content[game.ball_content_nr].e[xx][yy]);
7730 game.ball_content_nr = (game.ball_content_nr + 1) % level.num_ball_contents;
7733 void CheckExit(int x, int y)
7735 if (local_player->gems_still_needed > 0 ||
7736 local_player->sokobanfields_still_needed > 0 ||
7737 local_player->lights_still_needed > 0)
7739 int element = Feld[x][y];
7740 int graphic = el2img(element);
7742 if (IS_ANIMATED(graphic))
7743 DrawLevelGraphicAnimationIfNeeded(x, y, graphic);
7748 if (AllPlayersGone) /* do not re-open exit door closed after last player */
7751 Feld[x][y] = EL_EXIT_OPENING;
7753 PlayLevelSoundNearest(x, y, SND_CLASS_EXIT_OPENING);
7756 void CheckExitEM(int x, int y)
7758 if (local_player->gems_still_needed > 0 ||
7759 local_player->sokobanfields_still_needed > 0 ||
7760 local_player->lights_still_needed > 0)
7762 int element = Feld[x][y];
7763 int graphic = el2img(element);
7765 if (IS_ANIMATED(graphic))
7766 DrawLevelGraphicAnimationIfNeeded(x, y, graphic);
7771 if (AllPlayersGone) /* do not re-open exit door closed after last player */
7774 Feld[x][y] = EL_EM_EXIT_OPENING;
7776 PlayLevelSoundNearest(x, y, SND_CLASS_EM_EXIT_OPENING);
7779 void CheckExitSteel(int x, int y)
7781 if (local_player->gems_still_needed > 0 ||
7782 local_player->sokobanfields_still_needed > 0 ||
7783 local_player->lights_still_needed > 0)
7785 int element = Feld[x][y];
7786 int graphic = el2img(element);
7788 if (IS_ANIMATED(graphic))
7789 DrawLevelGraphicAnimationIfNeeded(x, y, graphic);
7794 if (AllPlayersGone) /* do not re-open exit door closed after last player */
7797 Feld[x][y] = EL_STEEL_EXIT_OPENING;
7799 PlayLevelSoundNearest(x, y, SND_CLASS_STEEL_EXIT_OPENING);
7802 void CheckExitSteelEM(int x, int y)
7804 if (local_player->gems_still_needed > 0 ||
7805 local_player->sokobanfields_still_needed > 0 ||
7806 local_player->lights_still_needed > 0)
7808 int element = Feld[x][y];
7809 int graphic = el2img(element);
7811 if (IS_ANIMATED(graphic))
7812 DrawLevelGraphicAnimationIfNeeded(x, y, graphic);
7817 if (AllPlayersGone) /* do not re-open exit door closed after last player */
7820 Feld[x][y] = EL_EM_STEEL_EXIT_OPENING;
7822 PlayLevelSoundNearest(x, y, SND_CLASS_EM_STEEL_EXIT_OPENING);
7825 void CheckExitSP(int x, int y)
7827 if (local_player->gems_still_needed > 0)
7829 int element = Feld[x][y];
7830 int graphic = el2img(element);
7832 if (IS_ANIMATED(graphic))
7833 DrawLevelGraphicAnimationIfNeeded(x, y, graphic);
7838 if (AllPlayersGone) /* do not re-open exit door closed after last player */
7841 Feld[x][y] = EL_SP_EXIT_OPENING;
7843 PlayLevelSoundNearest(x, y, SND_CLASS_SP_EXIT_OPENING);
7846 static void CloseAllOpenTimegates()
7850 SCAN_PLAYFIELD(x, y)
7852 int element = Feld[x][y];
7854 if (element == EL_TIMEGATE_OPEN || element == EL_TIMEGATE_OPENING)
7856 Feld[x][y] = EL_TIMEGATE_CLOSING;
7858 PlayLevelSoundAction(x, y, ACTION_CLOSING);
7863 void DrawTwinkleOnField(int x, int y)
7865 if (!IN_SCR_FIELD(SCREENX(x), SCREENY(y)) || IS_MOVING(x, y))
7868 if (Feld[x][y] == EL_BD_DIAMOND)
7871 if (MovDelay[x][y] == 0) /* next animation frame */
7872 MovDelay[x][y] = 11 * !GetSimpleRandom(500);
7874 if (MovDelay[x][y] != 0) /* wait some time before next frame */
7878 if (setup.direct_draw && MovDelay[x][y])
7879 SetDrawtoField(DRAW_BUFFERED);
7881 DrawLevelElementAnimation(x, y, Feld[x][y]);
7883 if (MovDelay[x][y] != 0)
7885 int frame = getGraphicAnimationFrame(IMG_TWINKLE_WHITE,
7886 10 - MovDelay[x][y]);
7888 DrawGraphicThruMask(SCREENX(x), SCREENY(y), IMG_TWINKLE_WHITE, frame);
7890 if (setup.direct_draw)
7894 dest_x = FX + SCREENX(x) * TILEX;
7895 dest_y = FY + SCREENY(y) * TILEY;
7897 BlitBitmap(drawto_field, window,
7898 dest_x, dest_y, TILEX, TILEY, dest_x, dest_y);
7899 SetDrawtoField(DRAW_DIRECT);
7905 void MauerWaechst(int x, int y)
7909 if (!MovDelay[x][y]) /* next animation frame */
7910 MovDelay[x][y] = 3 * delay;
7912 if (MovDelay[x][y]) /* wait some time before next frame */
7916 if (IN_SCR_FIELD(SCREENX(x), SCREENY(y)))
7918 int graphic = el_dir2img(Feld[x][y], GfxDir[x][y]);
7919 int frame = getGraphicAnimationFrame(graphic, 17 - MovDelay[x][y]);
7921 DrawGraphic(SCREENX(x), SCREENY(y), graphic, frame);
7924 if (!MovDelay[x][y])
7926 if (MovDir[x][y] == MV_LEFT)
7928 if (IN_LEV_FIELD(x - 1, y) && IS_WALL(Feld[x - 1][y]))
7929 DrawLevelField(x - 1, y);
7931 else if (MovDir[x][y] == MV_RIGHT)
7933 if (IN_LEV_FIELD(x + 1, y) && IS_WALL(Feld[x + 1][y]))
7934 DrawLevelField(x + 1, y);
7936 else if (MovDir[x][y] == MV_UP)
7938 if (IN_LEV_FIELD(x, y - 1) && IS_WALL(Feld[x][y - 1]))
7939 DrawLevelField(x, y - 1);
7943 if (IN_LEV_FIELD(x, y + 1) && IS_WALL(Feld[x][y + 1]))
7944 DrawLevelField(x, y + 1);
7947 Feld[x][y] = Store[x][y];
7949 GfxDir[x][y] = MovDir[x][y] = MV_NONE;
7950 DrawLevelField(x, y);
7955 void MauerAbleger(int ax, int ay)
7957 int element = Feld[ax][ay];
7958 int graphic = el2img(element);
7959 boolean oben_frei = FALSE, unten_frei = FALSE;
7960 boolean links_frei = FALSE, rechts_frei = FALSE;
7961 boolean oben_massiv = FALSE, unten_massiv = FALSE;
7962 boolean links_massiv = FALSE, rechts_massiv = FALSE;
7963 boolean new_wall = FALSE;
7965 if (IS_ANIMATED(graphic))
7966 DrawLevelGraphicAnimationIfNeeded(ax, ay, graphic);
7968 if (!MovDelay[ax][ay]) /* start building new wall */
7969 MovDelay[ax][ay] = 6;
7971 if (MovDelay[ax][ay]) /* wait some time before building new wall */
7974 if (MovDelay[ax][ay])
7978 if (IN_LEV_FIELD(ax, ay-1) && IS_FREE(ax, ay-1))
7980 if (IN_LEV_FIELD(ax, ay+1) && IS_FREE(ax, ay+1))
7982 if (IN_LEV_FIELD(ax-1, ay) && IS_FREE(ax-1, ay))
7984 if (IN_LEV_FIELD(ax+1, ay) && IS_FREE(ax+1, ay))
7987 if (element == EL_EXPANDABLE_WALL_VERTICAL ||
7988 element == EL_EXPANDABLE_WALL_ANY)
7992 Feld[ax][ay-1] = EL_EXPANDABLE_WALL_GROWING;
7993 Store[ax][ay-1] = element;
7994 GfxDir[ax][ay-1] = MovDir[ax][ay-1] = MV_UP;
7995 if (IN_SCR_FIELD(SCREENX(ax), SCREENY(ay-1)))
7996 DrawGraphic(SCREENX(ax), SCREENY(ay - 1),
7997 IMG_EXPANDABLE_WALL_GROWING_UP, 0);
8002 Feld[ax][ay+1] = EL_EXPANDABLE_WALL_GROWING;
8003 Store[ax][ay+1] = element;
8004 GfxDir[ax][ay+1] = MovDir[ax][ay+1] = MV_DOWN;
8005 if (IN_SCR_FIELD(SCREENX(ax), SCREENY(ay+1)))
8006 DrawGraphic(SCREENX(ax), SCREENY(ay + 1),
8007 IMG_EXPANDABLE_WALL_GROWING_DOWN, 0);
8012 if (element == EL_EXPANDABLE_WALL_HORIZONTAL ||
8013 element == EL_EXPANDABLE_WALL_ANY ||
8014 element == EL_EXPANDABLE_WALL ||
8015 element == EL_BD_EXPANDABLE_WALL)
8019 Feld[ax-1][ay] = EL_EXPANDABLE_WALL_GROWING;
8020 Store[ax-1][ay] = element;
8021 GfxDir[ax-1][ay] = MovDir[ax-1][ay] = MV_LEFT;
8022 if (IN_SCR_FIELD(SCREENX(ax-1), SCREENY(ay)))
8023 DrawGraphic(SCREENX(ax - 1), SCREENY(ay),
8024 IMG_EXPANDABLE_WALL_GROWING_LEFT, 0);
8030 Feld[ax+1][ay] = EL_EXPANDABLE_WALL_GROWING;
8031 Store[ax+1][ay] = element;
8032 GfxDir[ax+1][ay] = MovDir[ax+1][ay] = MV_RIGHT;
8033 if (IN_SCR_FIELD(SCREENX(ax+1), SCREENY(ay)))
8034 DrawGraphic(SCREENX(ax + 1), SCREENY(ay),
8035 IMG_EXPANDABLE_WALL_GROWING_RIGHT, 0);
8040 if (element == EL_EXPANDABLE_WALL && (links_frei || rechts_frei))
8041 DrawLevelField(ax, ay);
8043 if (!IN_LEV_FIELD(ax, ay-1) || IS_WALL(Feld[ax][ay-1]))
8045 if (!IN_LEV_FIELD(ax, ay+1) || IS_WALL(Feld[ax][ay+1]))
8046 unten_massiv = TRUE;
8047 if (!IN_LEV_FIELD(ax-1, ay) || IS_WALL(Feld[ax-1][ay]))
8048 links_massiv = TRUE;
8049 if (!IN_LEV_FIELD(ax+1, ay) || IS_WALL(Feld[ax+1][ay]))
8050 rechts_massiv = TRUE;
8052 if (((oben_massiv && unten_massiv) ||
8053 element == EL_EXPANDABLE_WALL_HORIZONTAL ||
8054 element == EL_EXPANDABLE_WALL) &&
8055 ((links_massiv && rechts_massiv) ||
8056 element == EL_EXPANDABLE_WALL_VERTICAL))
8057 Feld[ax][ay] = EL_WALL;
8060 PlayLevelSoundAction(ax, ay, ACTION_GROWING);
8063 void MauerAblegerStahl(int ax, int ay)
8065 int element = Feld[ax][ay];
8066 int graphic = el2img(element);
8067 boolean oben_frei = FALSE, unten_frei = FALSE;
8068 boolean links_frei = FALSE, rechts_frei = FALSE;
8069 boolean oben_massiv = FALSE, unten_massiv = FALSE;
8070 boolean links_massiv = FALSE, rechts_massiv = FALSE;
8071 boolean new_wall = FALSE;
8073 if (IS_ANIMATED(graphic))
8074 DrawLevelGraphicAnimationIfNeeded(ax, ay, graphic);
8076 if (!MovDelay[ax][ay]) /* start building new wall */
8077 MovDelay[ax][ay] = 6;
8079 if (MovDelay[ax][ay]) /* wait some time before building new wall */
8082 if (MovDelay[ax][ay])
8086 if (IN_LEV_FIELD(ax, ay-1) && IS_FREE(ax, ay-1))
8088 if (IN_LEV_FIELD(ax, ay+1) && IS_FREE(ax, ay+1))
8090 if (IN_LEV_FIELD(ax-1, ay) && IS_FREE(ax-1, ay))
8092 if (IN_LEV_FIELD(ax+1, ay) && IS_FREE(ax+1, ay))
8095 if (element == EL_EXPANDABLE_STEELWALL_VERTICAL ||
8096 element == EL_EXPANDABLE_STEELWALL_ANY)
8100 Feld[ax][ay-1] = EL_EXPANDABLE_STEELWALL_GROWING;
8101 Store[ax][ay-1] = element;
8102 GfxDir[ax][ay-1] = MovDir[ax][ay-1] = MV_UP;
8103 if (IN_SCR_FIELD(SCREENX(ax), SCREENY(ay-1)))
8104 DrawGraphic(SCREENX(ax), SCREENY(ay - 1),
8105 IMG_EXPANDABLE_STEELWALL_GROWING_UP, 0);
8110 Feld[ax][ay+1] = EL_EXPANDABLE_STEELWALL_GROWING;
8111 Store[ax][ay+1] = element;
8112 GfxDir[ax][ay+1] = MovDir[ax][ay+1] = MV_DOWN;
8113 if (IN_SCR_FIELD(SCREENX(ax), SCREENY(ay+1)))
8114 DrawGraphic(SCREENX(ax), SCREENY(ay + 1),
8115 IMG_EXPANDABLE_STEELWALL_GROWING_DOWN, 0);
8120 if (element == EL_EXPANDABLE_STEELWALL_HORIZONTAL ||
8121 element == EL_EXPANDABLE_STEELWALL_ANY)
8125 Feld[ax-1][ay] = EL_EXPANDABLE_STEELWALL_GROWING;
8126 Store[ax-1][ay] = element;
8127 GfxDir[ax-1][ay] = MovDir[ax-1][ay] = MV_LEFT;
8128 if (IN_SCR_FIELD(SCREENX(ax-1), SCREENY(ay)))
8129 DrawGraphic(SCREENX(ax - 1), SCREENY(ay),
8130 IMG_EXPANDABLE_STEELWALL_GROWING_LEFT, 0);
8136 Feld[ax+1][ay] = EL_EXPANDABLE_STEELWALL_GROWING;
8137 Store[ax+1][ay] = element;
8138 GfxDir[ax+1][ay] = MovDir[ax+1][ay] = MV_RIGHT;
8139 if (IN_SCR_FIELD(SCREENX(ax+1), SCREENY(ay)))
8140 DrawGraphic(SCREENX(ax + 1), SCREENY(ay),
8141 IMG_EXPANDABLE_STEELWALL_GROWING_RIGHT, 0);
8146 if (!IN_LEV_FIELD(ax, ay-1) || IS_WALL(Feld[ax][ay-1]))
8148 if (!IN_LEV_FIELD(ax, ay+1) || IS_WALL(Feld[ax][ay+1]))
8149 unten_massiv = TRUE;
8150 if (!IN_LEV_FIELD(ax-1, ay) || IS_WALL(Feld[ax-1][ay]))
8151 links_massiv = TRUE;
8152 if (!IN_LEV_FIELD(ax+1, ay) || IS_WALL(Feld[ax+1][ay]))
8153 rechts_massiv = TRUE;
8155 if (((oben_massiv && unten_massiv) ||
8156 element == EL_EXPANDABLE_STEELWALL_HORIZONTAL) &&
8157 ((links_massiv && rechts_massiv) ||
8158 element == EL_EXPANDABLE_STEELWALL_VERTICAL))
8159 Feld[ax][ay] = EL_WALL;
8162 PlayLevelSoundAction(ax, ay, ACTION_GROWING);
8165 void CheckForDragon(int x, int y)
8168 boolean dragon_found = FALSE;
8169 static int xy[4][2] =
8177 for (i = 0; i < NUM_DIRECTIONS; i++)
8179 for (j = 0; j < 4; j++)
8181 int xx = x + j * xy[i][0], yy = y + j * xy[i][1];
8183 if (IN_LEV_FIELD(xx, yy) &&
8184 (Feld[xx][yy] == EL_FLAMES || Feld[xx][yy] == EL_DRAGON))
8186 if (Feld[xx][yy] == EL_DRAGON)
8187 dragon_found = TRUE;
8196 for (i = 0; i < NUM_DIRECTIONS; i++)
8198 for (j = 0; j < 3; j++)
8200 int xx = x + j * xy[i][0], yy = y + j * xy[i][1];
8202 if (IN_LEV_FIELD(xx, yy) && Feld[xx][yy] == EL_FLAMES)
8204 Feld[xx][yy] = EL_EMPTY;
8205 DrawLevelField(xx, yy);
8214 static void InitBuggyBase(int x, int y)
8216 int element = Feld[x][y];
8217 int activating_delay = FRAMES_PER_SECOND / 4;
8220 (element == EL_SP_BUGGY_BASE ?
8221 2 * FRAMES_PER_SECOND + RND(5 * FRAMES_PER_SECOND) - activating_delay :
8222 element == EL_SP_BUGGY_BASE_ACTIVATING ?
8224 element == EL_SP_BUGGY_BASE_ACTIVE ?
8225 1 * FRAMES_PER_SECOND + RND(1 * FRAMES_PER_SECOND) : 1);
8228 static void WarnBuggyBase(int x, int y)
8231 static int xy[4][2] =
8239 for (i = 0; i < NUM_DIRECTIONS; i++)
8241 int xx = x + xy[i][0];
8242 int yy = y + xy[i][1];
8244 if (IN_LEV_FIELD(xx, yy) && IS_PLAYER(xx, yy))
8246 PlayLevelSound(x, y, SND_SP_BUGGY_BASE_ACTIVE);
8253 static void InitTrap(int x, int y)
8255 ChangeDelay[x][y] = 2 * FRAMES_PER_SECOND + RND(5 * FRAMES_PER_SECOND);
8258 static void ActivateTrap(int x, int y)
8260 PlayLevelSound(x, y, SND_TRAP_ACTIVATING);
8263 static void ChangeActiveTrap(int x, int y)
8265 int graphic = IMG_TRAP_ACTIVE;
8267 /* if new animation frame was drawn, correct crumbled sand border */
8268 if (IS_NEW_FRAME(GfxFrame[x][y], graphic))
8269 DrawLevelFieldCrumbledSand(x, y);
8272 static int getSpecialActionElement(int element, int number, int base_element)
8274 return (element != EL_EMPTY ? element :
8275 number != -1 ? base_element + number - 1 :
8279 static int getModifiedActionNumber(int value_old, int operator, int operand,
8280 int value_min, int value_max)
8282 int value_new = (operator == CA_MODE_SET ? operand :
8283 operator == CA_MODE_ADD ? value_old + operand :
8284 operator == CA_MODE_SUBTRACT ? value_old - operand :
8285 operator == CA_MODE_MULTIPLY ? value_old * operand :
8286 operator == CA_MODE_DIVIDE ? value_old / MAX(1, operand) :
8287 operator == CA_MODE_MODULO ? value_old % MAX(1, operand) :
8290 return (value_new < value_min ? value_min :
8291 value_new > value_max ? value_max :
8295 static void ExecuteCustomElementAction(int x, int y, int element, int page)
8297 struct ElementInfo *ei = &element_info[element];
8298 struct ElementChangeInfo *change = &ei->change_page[page];
8299 int target_element = change->target_element;
8300 int action_type = change->action_type;
8301 int action_mode = change->action_mode;
8302 int action_arg = change->action_arg;
8305 if (!change->has_action)
8308 /* ---------- determine action paramater values -------------------------- */
8310 int level_time_value =
8311 (level.time > 0 ? TimeLeft :
8314 int action_arg_element =
8315 (action_arg == CA_ARG_PLAYER_TRIGGER ? change->actual_trigger_player :
8316 action_arg == CA_ARG_ELEMENT_TRIGGER ? change->actual_trigger_element :
8317 action_arg == CA_ARG_ELEMENT_TARGET ? change->target_element :
8320 int action_arg_direction =
8321 (action_arg >= CA_ARG_DIRECTION_LEFT &&
8322 action_arg <= CA_ARG_DIRECTION_DOWN ? action_arg - CA_ARG_DIRECTION :
8323 action_arg == CA_ARG_DIRECTION_TRIGGER ?
8324 change->actual_trigger_side :
8325 action_arg == CA_ARG_DIRECTION_TRIGGER_BACK ?
8326 MV_DIR_OPPOSITE(change->actual_trigger_side) :
8329 int action_arg_number_min =
8330 (action_type == CA_SET_PLAYER_SPEED ? STEPSIZE_NOT_MOVING :
8333 int action_arg_number_max =
8334 (action_type == CA_SET_PLAYER_SPEED ? STEPSIZE_EVEN_FASTER :
8335 action_type == CA_SET_LEVEL_GEMS ? 999 :
8336 action_type == CA_SET_LEVEL_TIME ? 9999 :
8337 action_type == CA_SET_LEVEL_SCORE ? 99999 :
8338 action_type == CA_SET_CE_VALUE ? 9999 :
8339 action_type == CA_SET_CE_SCORE ? 9999 :
8342 int action_arg_number_reset =
8343 (action_type == CA_SET_PLAYER_SPEED ? level.initial_player_stepsize[0] :
8344 action_type == CA_SET_LEVEL_GEMS ? level.gems_needed :
8345 action_type == CA_SET_LEVEL_TIME ? level.time :
8346 action_type == CA_SET_LEVEL_SCORE ? 0 :
8347 #if USE_NEW_CUSTOM_VALUE
8348 action_type == CA_SET_CE_VALUE ? GET_NEW_CE_VALUE(element) :
8350 action_type == CA_SET_CE_VALUE ? ei->custom_value_initial :
8352 action_type == CA_SET_CE_SCORE ? 0 :
8355 int action_arg_number =
8356 (action_arg <= CA_ARG_MAX ? action_arg :
8357 action_arg >= CA_ARG_SPEED_NOT_MOVING &&
8358 action_arg <= CA_ARG_SPEED_EVEN_FASTER ? (action_arg - CA_ARG_SPEED) :
8359 action_arg == CA_ARG_SPEED_RESET ? action_arg_number_reset :
8360 action_arg == CA_ARG_NUMBER_MIN ? action_arg_number_min :
8361 action_arg == CA_ARG_NUMBER_MAX ? action_arg_number_max :
8362 action_arg == CA_ARG_NUMBER_RESET ? action_arg_number_reset :
8363 #if USE_NEW_CUSTOM_VALUE
8364 action_arg == CA_ARG_NUMBER_CE_VALUE ? CustomValue[x][y] :
8366 action_arg == CA_ARG_NUMBER_CE_VALUE ? ei->custom_value_initial :
8368 action_arg == CA_ARG_NUMBER_CE_SCORE ? ei->collect_score :
8369 action_arg == CA_ARG_NUMBER_CE_DELAY ? GET_CE_DELAY_VALUE(change) :
8370 action_arg == CA_ARG_NUMBER_LEVEL_TIME ? level_time_value :
8371 action_arg == CA_ARG_NUMBER_LEVEL_GEMS ? local_player->gems_still_needed :
8372 action_arg == CA_ARG_NUMBER_LEVEL_SCORE ? local_player->score :
8373 action_arg == CA_ARG_ELEMENT_CV_TARGET ? GET_NEW_CE_VALUE(target_element):
8374 action_arg == CA_ARG_ELEMENT_CV_TRIGGER ? change->actual_trigger_ce_value:
8375 action_arg == CA_ARG_ELEMENT_CS_TARGET ? GET_CE_SCORE(target_element) :
8376 action_arg == CA_ARG_ELEMENT_CS_TRIGGER ? change->actual_trigger_ce_score:
8377 action_arg == CA_ARG_ELEMENT_NR_TARGET ? change->target_element :
8378 action_arg == CA_ARG_ELEMENT_NR_TRIGGER ? change->actual_trigger_element :
8381 int action_arg_number_old =
8382 (action_type == CA_SET_LEVEL_GEMS ? local_player->gems_still_needed :
8383 action_type == CA_SET_LEVEL_TIME ? TimeLeft :
8384 action_type == CA_SET_LEVEL_SCORE ? local_player->score :
8385 action_type == CA_SET_CE_VALUE ? CustomValue[x][y] :
8386 action_type == CA_SET_CE_SCORE ? ei->collect_score :
8389 int action_arg_number_new =
8390 getModifiedActionNumber(action_arg_number_old,
8391 action_mode, action_arg_number,
8392 action_arg_number_min, action_arg_number_max);
8394 int trigger_player_bits =
8395 (change->actual_trigger_player >= EL_PLAYER_1 &&
8396 change->actual_trigger_player <= EL_PLAYER_4 ?
8397 (1 << (change->actual_trigger_player - EL_PLAYER_1)) :
8400 int action_arg_player_bits =
8401 (action_arg >= CA_ARG_PLAYER_1 &&
8402 action_arg <= CA_ARG_PLAYER_4 ? action_arg - CA_ARG_PLAYER :
8403 action_arg == CA_ARG_PLAYER_TRIGGER ? trigger_player_bits :
8406 /* ---------- execute action -------------------------------------------- */
8408 switch (action_type)
8415 /* ---------- level actions ------------------------------------------- */
8417 case CA_RESTART_LEVEL:
8419 game.restart_level = TRUE;
8424 case CA_SHOW_ENVELOPE:
8426 int element = getSpecialActionElement(action_arg_element,
8427 action_arg_number, EL_ENVELOPE_1);
8429 if (IS_ENVELOPE(element))
8430 local_player->show_envelope = element;
8435 case CA_SET_LEVEL_TIME:
8437 if (level.time > 0) /* only modify limited time value */
8439 TimeLeft = action_arg_number_new;
8441 DrawGameValue_Time(TimeLeft);
8443 if (!TimeLeft && setup.time_limit)
8444 for (i = 0; i < MAX_PLAYERS; i++)
8445 KillPlayer(&stored_player[i]);
8451 case CA_SET_LEVEL_SCORE:
8453 local_player->score = action_arg_number_new;
8455 DrawGameValue_Score(local_player->score);
8460 case CA_SET_LEVEL_GEMS:
8462 local_player->gems_still_needed = action_arg_number_new;
8464 DrawGameValue_Emeralds(local_player->gems_still_needed);
8469 #if !USE_PLAYER_GRAVITY
8470 case CA_SET_LEVEL_GRAVITY:
8472 game.gravity = (action_arg == CA_ARG_GRAVITY_OFF ? FALSE :
8473 action_arg == CA_ARG_GRAVITY_ON ? TRUE :
8474 action_arg == CA_ARG_GRAVITY_TOGGLE ? !game.gravity :
8480 case CA_SET_LEVEL_WIND:
8482 game.wind_direction = action_arg_direction;
8487 /* ---------- player actions ------------------------------------------ */
8489 case CA_MOVE_PLAYER:
8491 /* automatically move to the next field in specified direction */
8492 for (i = 0; i < MAX_PLAYERS; i++)
8493 if (trigger_player_bits & (1 << i))
8494 stored_player[i].programmed_action = action_arg_direction;
8499 case CA_EXIT_PLAYER:
8501 for (i = 0; i < MAX_PLAYERS; i++)
8502 if (action_arg_player_bits & (1 << i))
8503 PlayerWins(&stored_player[i]);
8508 case CA_KILL_PLAYER:
8510 for (i = 0; i < MAX_PLAYERS; i++)
8511 if (action_arg_player_bits & (1 << i))
8512 KillPlayer(&stored_player[i]);
8517 case CA_SET_PLAYER_KEYS:
8519 int key_state = (action_mode == CA_MODE_ADD ? TRUE : FALSE);
8520 int element = getSpecialActionElement(action_arg_element,
8521 action_arg_number, EL_KEY_1);
8523 if (IS_KEY(element))
8525 for (i = 0; i < MAX_PLAYERS; i++)
8527 if (trigger_player_bits & (1 << i))
8529 stored_player[i].key[KEY_NR(element)] = key_state;
8531 DrawGameDoorValues();
8539 case CA_SET_PLAYER_SPEED:
8541 for (i = 0; i < MAX_PLAYERS; i++)
8543 if (trigger_player_bits & (1 << i))
8545 int move_stepsize = TILEX / stored_player[i].move_delay_value;
8547 if (action_arg == CA_ARG_SPEED_FASTER &&
8548 stored_player[i].cannot_move)
8550 action_arg_number = STEPSIZE_VERY_SLOW;
8552 else if (action_arg == CA_ARG_SPEED_SLOWER ||
8553 action_arg == CA_ARG_SPEED_FASTER)
8555 action_arg_number = 2;
8556 action_mode = (action_arg == CA_ARG_SPEED_SLOWER ? CA_MODE_DIVIDE :
8559 else if (action_arg == CA_ARG_NUMBER_RESET)
8561 action_arg_number = level.initial_player_stepsize[i];
8565 getModifiedActionNumber(move_stepsize,
8568 action_arg_number_min,
8569 action_arg_number_max);
8571 SetPlayerMoveSpeed(&stored_player[i], move_stepsize, FALSE);
8578 case CA_SET_PLAYER_SHIELD:
8580 for (i = 0; i < MAX_PLAYERS; i++)
8582 if (trigger_player_bits & (1 << i))
8584 if (action_arg == CA_ARG_SHIELD_OFF)
8586 stored_player[i].shield_normal_time_left = 0;
8587 stored_player[i].shield_deadly_time_left = 0;
8589 else if (action_arg == CA_ARG_SHIELD_NORMAL)
8591 stored_player[i].shield_normal_time_left = 999999;
8593 else if (action_arg == CA_ARG_SHIELD_DEADLY)
8595 stored_player[i].shield_normal_time_left = 999999;
8596 stored_player[i].shield_deadly_time_left = 999999;
8604 #if USE_PLAYER_GRAVITY
8605 case CA_SET_PLAYER_GRAVITY:
8607 for (i = 0; i < MAX_PLAYERS; i++)
8609 if (trigger_player_bits & (1 << i))
8611 stored_player[i].gravity =
8612 (action_arg == CA_ARG_GRAVITY_OFF ? FALSE :
8613 action_arg == CA_ARG_GRAVITY_ON ? TRUE :
8614 action_arg == CA_ARG_GRAVITY_TOGGLE ? !stored_player[i].gravity :
8615 stored_player[i].gravity);
8623 case CA_SET_PLAYER_ARTWORK:
8625 for (i = 0; i < MAX_PLAYERS; i++)
8627 if (trigger_player_bits & (1 << i))
8629 int artwork_element = action_arg_element;
8631 if (action_arg == CA_ARG_ELEMENT_RESET)
8633 (level.use_artwork_element[i] ? level.artwork_element[i] :
8634 stored_player[i].element_nr);
8636 #if USE_GFX_RESET_PLAYER_ARTWORK
8637 if (stored_player[i].artwork_element != artwork_element)
8638 stored_player[i].Frame = 0;
8641 stored_player[i].artwork_element = artwork_element;
8643 SetPlayerWaiting(&stored_player[i], FALSE);
8645 /* set number of special actions for bored and sleeping animation */
8646 stored_player[i].num_special_action_bored =
8647 get_num_special_action(artwork_element,
8648 ACTION_BORING_1, ACTION_BORING_LAST);
8649 stored_player[i].num_special_action_sleeping =
8650 get_num_special_action(artwork_element,
8651 ACTION_SLEEPING_1, ACTION_SLEEPING_LAST);
8658 /* ---------- CE actions ---------------------------------------------- */
8660 case CA_SET_CE_VALUE:
8662 #if USE_NEW_CUSTOM_VALUE
8663 int last_ce_value = CustomValue[x][y];
8665 CustomValue[x][y] = action_arg_number_new;
8667 if (CustomValue[x][y] != last_ce_value)
8669 CheckElementChange(x, y, element, EL_UNDEFINED, CE_VALUE_CHANGES);
8670 CheckTriggeredElementChange(x, y, element, CE_VALUE_CHANGES_OF_X);
8672 if (CustomValue[x][y] == 0)
8674 CheckElementChange(x, y, element, EL_UNDEFINED, CE_VALUE_GETS_ZERO);
8675 CheckTriggeredElementChange(x, y, element, CE_VALUE_GETS_ZERO_OF_X);
8683 case CA_SET_CE_SCORE:
8685 #if USE_NEW_CUSTOM_VALUE
8686 int last_ce_score = ei->collect_score;
8688 ei->collect_score = action_arg_number_new;
8690 if (ei->collect_score != last_ce_score)
8692 CheckElementChange(x, y, element, EL_UNDEFINED, CE_SCORE_CHANGES);
8693 CheckTriggeredElementChange(x, y, element, CE_SCORE_CHANGES_OF_X);
8695 if (ei->collect_score == 0)
8699 CheckElementChange(x, y, element, EL_UNDEFINED, CE_SCORE_GETS_ZERO);
8700 CheckTriggeredElementChange(x, y, element, CE_SCORE_GETS_ZERO_OF_X);
8703 This is a very special case that seems to be a mixture between
8704 CheckElementChange() and CheckTriggeredElementChange(): while
8705 the first one only affects single elements that are triggered
8706 directly, the second one affects multiple elements in the playfield
8707 that are triggered indirectly by another element. This is a third
8708 case: Changing the CE score always affects multiple identical CEs,
8709 so every affected CE must be checked, not only the single CE for
8710 which the CE score was changed in the first place (as every instance
8711 of that CE shares the same CE score, and therefore also can change)!
8713 SCAN_PLAYFIELD(xx, yy)
8715 if (Feld[xx][yy] == element)
8716 CheckElementChange(xx, yy, element, EL_UNDEFINED,
8717 CE_SCORE_GETS_ZERO);
8726 /* ---------- engine actions ------------------------------------------ */
8728 case CA_SET_ENGINE_SCAN_MODE:
8730 InitPlayfieldScanMode(action_arg);
8740 static void CreateFieldExt(int x, int y, int element, boolean is_change)
8742 int old_element = Feld[x][y];
8743 int new_element = get_element_from_group_element(element);
8744 int previous_move_direction = MovDir[x][y];
8745 #if USE_NEW_CUSTOM_VALUE
8746 int last_ce_value = CustomValue[x][y];
8748 boolean player_explosion_protected = PLAYER_EXPLOSION_PROTECTED(x, y);
8749 boolean new_element_is_player = ELEM_IS_PLAYER(new_element);
8750 boolean add_player_onto_element = (new_element_is_player &&
8751 #if USE_CODE_THAT_BREAKS_SNAKE_BITE
8752 /* this breaks SnakeBite when a snake is
8753 halfway through a door that closes */
8754 /* NOW FIXED AT LEVEL INIT IN files.c */
8755 new_element != EL_SOKOBAN_FIELD_PLAYER &&
8757 IS_WALKABLE(old_element));
8760 /* check if element under the player changes from accessible to unaccessible
8761 (needed for special case of dropping element which then changes) */
8762 if (IS_PLAYER(x, y) && !PLAYER_EXPLOSION_PROTECTED(x, y) &&
8763 IS_ACCESSIBLE(old_element) && !IS_ACCESSIBLE(new_element))
8771 if (!add_player_onto_element)
8773 if (IS_MOVING(x, y) || IS_BLOCKED(x, y))
8774 RemoveMovingField(x, y);
8778 Feld[x][y] = new_element;
8780 #if !USE_GFX_RESET_GFX_ANIMATION
8781 ResetGfxAnimation(x, y);
8782 ResetRandomAnimationValue(x, y);
8785 if (element_info[new_element].move_direction_initial == MV_START_PREVIOUS)
8786 MovDir[x][y] = previous_move_direction;
8788 #if USE_NEW_CUSTOM_VALUE
8789 if (element_info[new_element].use_last_ce_value)
8790 CustomValue[x][y] = last_ce_value;
8793 InitField_WithBug1(x, y, FALSE);
8795 new_element = Feld[x][y]; /* element may have changed */
8797 #if USE_GFX_RESET_GFX_ANIMATION
8798 ResetGfxAnimation(x, y);
8799 ResetRandomAnimationValue(x, y);
8802 DrawLevelField(x, y);
8804 if (GFX_CRUMBLED(new_element))
8805 DrawLevelFieldCrumbledSandNeighbours(x, y);
8809 /* check if element under the player changes from accessible to unaccessible
8810 (needed for special case of dropping element which then changes) */
8811 /* (must be checked after creating new element for walkable group elements) */
8812 #if USE_FIX_KILLED_BY_NON_WALKABLE
8813 if (IS_PLAYER(x, y) && !player_explosion_protected &&
8814 IS_ACCESSIBLE(old_element) && !IS_ACCESSIBLE(new_element))
8821 if (IS_PLAYER(x, y) && !PLAYER_EXPLOSION_PROTECTED(x, y) &&
8822 IS_ACCESSIBLE(old_element) && !IS_ACCESSIBLE(new_element))
8831 /* "ChangeCount" not set yet to allow "entered by player" change one time */
8832 if (new_element_is_player)
8833 RelocatePlayer(x, y, new_element);
8836 ChangeCount[x][y]++; /* count number of changes in the same frame */
8838 TestIfBadThingTouchesPlayer(x, y);
8839 TestIfPlayerTouchesCustomElement(x, y);
8840 TestIfElementTouchesCustomElement(x, y);
8843 static void CreateField(int x, int y, int element)
8845 CreateFieldExt(x, y, element, FALSE);
8848 static void CreateElementFromChange(int x, int y, int element)
8850 element = GET_VALID_RUNTIME_ELEMENT(element);
8852 #if USE_STOP_CHANGED_ELEMENTS
8853 if (game.engine_version >= VERSION_IDENT(3,2,0,7))
8855 int old_element = Feld[x][y];
8857 /* prevent changed element from moving in same engine frame
8858 unless both old and new element can either fall or move */
8859 if ((!CAN_FALL(old_element) || !CAN_FALL(element)) &&
8860 (!CAN_MOVE(old_element) || !CAN_MOVE(element)))
8865 CreateFieldExt(x, y, element, TRUE);
8868 static boolean ChangeElement(int x, int y, int element, int page)
8870 struct ElementInfo *ei = &element_info[element];
8871 struct ElementChangeInfo *change = &ei->change_page[page];
8872 int ce_value = CustomValue[x][y];
8873 int ce_score = ei->collect_score;
8875 int old_element = Feld[x][y];
8877 /* always use default change event to prevent running into a loop */
8878 if (ChangeEvent[x][y] == -1)
8879 ChangeEvent[x][y] = CE_DELAY;
8881 if (ChangeEvent[x][y] == CE_DELAY)
8883 /* reset actual trigger element, trigger player and action element */
8884 change->actual_trigger_element = EL_EMPTY;
8885 change->actual_trigger_player = EL_PLAYER_1;
8886 change->actual_trigger_side = CH_SIDE_NONE;
8887 change->actual_trigger_ce_value = 0;
8888 change->actual_trigger_ce_score = 0;
8891 /* do not change elements more than a specified maximum number of changes */
8892 if (ChangeCount[x][y] >= game.max_num_changes_per_frame)
8895 ChangeCount[x][y]++; /* count number of changes in the same frame */
8897 if (change->explode)
8904 if (change->use_target_content)
8906 boolean complete_replace = TRUE;
8907 boolean can_replace[3][3];
8910 for (yy = 0; yy < 3; yy++) for (xx = 0; xx < 3 ; xx++)
8913 boolean is_walkable;
8914 boolean is_diggable;
8915 boolean is_collectible;
8916 boolean is_removable;
8917 boolean is_destructible;
8918 int ex = x + xx - 1;
8919 int ey = y + yy - 1;
8920 int content_element = change->target_content.e[xx][yy];
8923 can_replace[xx][yy] = TRUE;
8925 if (ex == x && ey == y) /* do not check changing element itself */
8928 if (content_element == EL_EMPTY_SPACE)
8930 can_replace[xx][yy] = FALSE; /* do not replace border with space */
8935 if (!IN_LEV_FIELD(ex, ey))
8937 can_replace[xx][yy] = FALSE;
8938 complete_replace = FALSE;
8945 if (IS_MOVING(ex, ey) || IS_BLOCKED(ex, ey))
8946 e = MovingOrBlocked2Element(ex, ey);
8948 is_empty = (IS_FREE(ex, ey) ||
8949 (IS_FREE_OR_PLAYER(ex, ey) && IS_WALKABLE(content_element)));
8951 is_walkable = (is_empty || IS_WALKABLE(e));
8952 is_diggable = (is_empty || IS_DIGGABLE(e));
8953 is_collectible = (is_empty || IS_COLLECTIBLE(e));
8954 is_destructible = (is_empty || !IS_INDESTRUCTIBLE(e));
8955 is_removable = (is_diggable || is_collectible);
8957 can_replace[xx][yy] =
8958 (((change->replace_when == CP_WHEN_EMPTY && is_empty) ||
8959 (change->replace_when == CP_WHEN_WALKABLE && is_walkable) ||
8960 (change->replace_when == CP_WHEN_DIGGABLE && is_diggable) ||
8961 (change->replace_when == CP_WHEN_COLLECTIBLE && is_collectible) ||
8962 (change->replace_when == CP_WHEN_REMOVABLE && is_removable) ||
8963 (change->replace_when == CP_WHEN_DESTRUCTIBLE && is_destructible)) &&
8964 !(IS_PLAYER(ex, ey) && ELEM_IS_PLAYER(content_element)));
8966 if (!can_replace[xx][yy])
8967 complete_replace = FALSE;
8970 if (!change->only_if_complete || complete_replace)
8972 boolean something_has_changed = FALSE;
8974 if (change->only_if_complete && change->use_random_replace &&
8975 RND(100) < change->random_percentage)
8978 for (yy = 0; yy < 3; yy++) for (xx = 0; xx < 3 ; xx++)
8980 int ex = x + xx - 1;
8981 int ey = y + yy - 1;
8982 int content_element;
8984 if (can_replace[xx][yy] && (!change->use_random_replace ||
8985 RND(100) < change->random_percentage))
8987 if (IS_MOVING(ex, ey) || IS_BLOCKED(ex, ey))
8988 RemoveMovingField(ex, ey);
8990 ChangeEvent[ex][ey] = ChangeEvent[x][y];
8992 content_element = change->target_content.e[xx][yy];
8993 target_element = GET_TARGET_ELEMENT(element, content_element, change,
8994 ce_value, ce_score);
8996 CreateElementFromChange(ex, ey, target_element);
8998 something_has_changed = TRUE;
9000 /* for symmetry reasons, freeze newly created border elements */
9001 if (ex != x || ey != y)
9002 Stop[ex][ey] = TRUE; /* no more moving in this frame */
9006 if (something_has_changed)
9008 PlayLevelSoundElementAction(x, y, element, ACTION_CHANGING);
9009 PlayLevelSoundElementAction(x, y, element, ACTION_PAGE_1 + page);
9015 target_element = GET_TARGET_ELEMENT(element, change->target_element, change,
9016 ce_value, ce_score);
9018 if (element == EL_DIAGONAL_GROWING ||
9019 element == EL_DIAGONAL_SHRINKING)
9021 target_element = Store[x][y];
9023 Store[x][y] = EL_EMPTY;
9026 CreateElementFromChange(x, y, target_element);
9028 PlayLevelSoundElementAction(x, y, element, ACTION_CHANGING);
9029 PlayLevelSoundElementAction(x, y, element, ACTION_PAGE_1 + page);
9032 /* this uses direct change before indirect change */
9033 CheckTriggeredElementChangeByPage(x, y, old_element, CE_CHANGE_OF_X, page);
9038 #if USE_NEW_DELAYED_ACTION
9040 static void HandleElementChange(int x, int y, int page)
9042 int element = MovingOrBlocked2Element(x, y);
9043 struct ElementInfo *ei = &element_info[element];
9044 struct ElementChangeInfo *change = &ei->change_page[page];
9047 if (!CAN_CHANGE_OR_HAS_ACTION(element) &&
9048 !CAN_CHANGE_OR_HAS_ACTION(Back[x][y]))
9051 printf("HandleElementChange(): %d,%d: element = %d ('%s')\n",
9052 x, y, element, element_info[element].token_name);
9053 printf("HandleElementChange(): This should never happen!\n");
9058 /* this can happen with classic bombs on walkable, changing elements */
9059 if (!CAN_CHANGE_OR_HAS_ACTION(element))
9062 if (!CAN_CHANGE(Back[x][y])) /* prevent permanent repetition */
9063 ChangeDelay[x][y] = 0;
9069 if (ChangeDelay[x][y] == 0) /* initialize element change */
9071 ChangeDelay[x][y] = GET_CHANGE_DELAY(change) + 1;
9073 if (change->can_change)
9075 ResetGfxAnimation(x, y);
9076 ResetRandomAnimationValue(x, y);
9078 if (change->pre_change_function)
9079 change->pre_change_function(x, y);
9083 ChangeDelay[x][y]--;
9085 if (ChangeDelay[x][y] != 0) /* continue element change */
9087 if (change->can_change)
9089 int graphic = el_act_dir2img(element, GfxAction[x][y], GfxDir[x][y]);
9091 if (IS_ANIMATED(graphic))
9092 DrawLevelGraphicAnimationIfNeeded(x, y, graphic);
9094 if (change->change_function)
9095 change->change_function(x, y);
9098 else /* finish element change */
9100 if (ChangePage[x][y] != -1) /* remember page from delayed change */
9102 page = ChangePage[x][y];
9103 ChangePage[x][y] = -1;
9105 change = &ei->change_page[page];
9108 if (IS_MOVING(x, y)) /* never change a running system ;-) */
9110 ChangeDelay[x][y] = 1; /* try change after next move step */
9111 ChangePage[x][y] = page; /* remember page to use for change */
9116 if (change->can_change)
9118 if (ChangeElement(x, y, element, page))
9120 if (change->post_change_function)
9121 change->post_change_function(x, y);
9125 if (change->has_action)
9126 ExecuteCustomElementAction(x, y, element, page);
9132 static void HandleElementChange(int x, int y, int page)
9134 int element = MovingOrBlocked2Element(x, y);
9135 struct ElementInfo *ei = &element_info[element];
9136 struct ElementChangeInfo *change = &ei->change_page[page];
9139 if (!CAN_CHANGE(element) && !CAN_CHANGE(Back[x][y]))
9142 printf("HandleElementChange(): %d,%d: element = %d ('%s')\n",
9143 x, y, element, element_info[element].token_name);
9144 printf("HandleElementChange(): This should never happen!\n");
9149 /* this can happen with classic bombs on walkable, changing elements */
9150 if (!CAN_CHANGE(element))
9153 if (!CAN_CHANGE(Back[x][y])) /* prevent permanent repetition */
9154 ChangeDelay[x][y] = 0;
9160 if (ChangeDelay[x][y] == 0) /* initialize element change */
9162 ChangeDelay[x][y] = GET_CHANGE_DELAY(change) + 1;
9164 ResetGfxAnimation(x, y);
9165 ResetRandomAnimationValue(x, y);
9167 if (change->pre_change_function)
9168 change->pre_change_function(x, y);
9171 ChangeDelay[x][y]--;
9173 if (ChangeDelay[x][y] != 0) /* continue element change */
9175 int graphic = el_act_dir2img(element, GfxAction[x][y], GfxDir[x][y]);
9177 if (IS_ANIMATED(graphic))
9178 DrawLevelGraphicAnimationIfNeeded(x, y, graphic);
9180 if (change->change_function)
9181 change->change_function(x, y);
9183 else /* finish element change */
9185 if (ChangePage[x][y] != -1) /* remember page from delayed change */
9187 page = ChangePage[x][y];
9188 ChangePage[x][y] = -1;
9190 change = &ei->change_page[page];
9193 if (IS_MOVING(x, y)) /* never change a running system ;-) */
9195 ChangeDelay[x][y] = 1; /* try change after next move step */
9196 ChangePage[x][y] = page; /* remember page to use for change */
9201 if (ChangeElement(x, y, element, page))
9203 if (change->post_change_function)
9204 change->post_change_function(x, y);
9211 static boolean CheckTriggeredElementChangeExt(int trigger_x, int trigger_y,
9212 int trigger_element,
9218 boolean change_done_any = FALSE;
9219 int trigger_page_bits = (trigger_page < 0 ? CH_PAGE_ANY : 1 << trigger_page);
9222 if (!(trigger_events[trigger_element][trigger_event]))
9226 printf("::: CheckTriggeredElementChangeExt %d ... [%d, %d, %d, '%s']\n",
9227 trigger_event, recursion_loop_depth, recursion_loop_detected,
9228 recursion_loop_element, EL_NAME(recursion_loop_element));
9231 RECURSION_LOOP_DETECTION_START(trigger_element, FALSE);
9233 for (i = 0; i < NUM_CUSTOM_ELEMENTS; i++)
9235 int element = EL_CUSTOM_START + i;
9236 boolean change_done = FALSE;
9239 if (!CAN_CHANGE_OR_HAS_ACTION(element) ||
9240 !HAS_ANY_CHANGE_EVENT(element, trigger_event))
9243 for (p = 0; p < element_info[element].num_change_pages; p++)
9245 struct ElementChangeInfo *change = &element_info[element].change_page[p];
9247 if (change->can_change_or_has_action &&
9248 change->has_event[trigger_event] &&
9249 change->trigger_side & trigger_side &&
9250 change->trigger_player & trigger_player &&
9251 change->trigger_page & trigger_page_bits &&
9252 IS_EQUAL_OR_IN_GROUP(trigger_element, change->trigger_element))
9254 change->actual_trigger_element = trigger_element;
9255 change->actual_trigger_player = EL_PLAYER_1 + log_2(trigger_player);
9256 change->actual_trigger_side = trigger_side;
9257 change->actual_trigger_ce_value = CustomValue[trigger_x][trigger_y];
9258 change->actual_trigger_ce_score = GET_CE_SCORE(trigger_element);
9260 if ((change->can_change && !change_done) || change->has_action)
9264 SCAN_PLAYFIELD(x, y)
9266 if (Feld[x][y] == element)
9268 if (change->can_change && !change_done)
9270 ChangeDelay[x][y] = 1;
9271 ChangeEvent[x][y] = trigger_event;
9273 HandleElementChange(x, y, p);
9275 #if USE_NEW_DELAYED_ACTION
9276 else if (change->has_action)
9278 ExecuteCustomElementAction(x, y, element, p);
9279 PlayLevelSoundElementAction(x, y, element, ACTION_PAGE_1 + p);
9282 if (change->has_action)
9284 ExecuteCustomElementAction(x, y, element, p);
9285 PlayLevelSoundElementAction(x, y, element, ACTION_PAGE_1 + p);
9291 if (change->can_change)
9294 change_done_any = TRUE;
9301 RECURSION_LOOP_DETECTION_END();
9303 return change_done_any;
9306 static boolean CheckElementChangeExt(int x, int y,
9308 int trigger_element,
9313 boolean change_done = FALSE;
9316 if (!CAN_CHANGE_OR_HAS_ACTION(element) ||
9317 !HAS_ANY_CHANGE_EVENT(element, trigger_event))
9320 if (Feld[x][y] == EL_BLOCKED)
9322 Blocked2Moving(x, y, &x, &y);
9323 element = Feld[x][y];
9327 /* check if element has already changed */
9328 if (Feld[x][y] != element)
9331 /* check if element has already changed or is about to change after moving */
9332 if ((game.engine_version < VERSION_IDENT(3,2,0,7) &&
9333 Feld[x][y] != element) ||
9335 (game.engine_version >= VERSION_IDENT(3,2,0,7) &&
9336 (ChangeCount[x][y] >= game.max_num_changes_per_frame ||
9337 ChangePage[x][y] != -1)))
9342 printf("::: CheckElementChangeExt %d ... [%d, %d, %d, '%s']\n",
9343 trigger_event, recursion_loop_depth, recursion_loop_detected,
9344 recursion_loop_element, EL_NAME(recursion_loop_element));
9347 RECURSION_LOOP_DETECTION_START(trigger_element, FALSE);
9349 for (p = 0; p < element_info[element].num_change_pages; p++)
9351 struct ElementChangeInfo *change = &element_info[element].change_page[p];
9353 /* check trigger element for all events where the element that is checked
9354 for changing interacts with a directly adjacent element -- this is
9355 different to element changes that affect other elements to change on the
9356 whole playfield (which is handeld by CheckTriggeredElementChangeExt()) */
9357 boolean check_trigger_element =
9358 (trigger_event == CE_TOUCHING_X ||
9359 trigger_event == CE_HITTING_X ||
9360 trigger_event == CE_HIT_BY_X ||
9362 /* this one was forgotten until 3.2.3 */
9363 trigger_event == CE_DIGGING_X);
9366 if (change->can_change_or_has_action &&
9367 change->has_event[trigger_event] &&
9368 change->trigger_side & trigger_side &&
9369 change->trigger_player & trigger_player &&
9370 (!check_trigger_element ||
9371 IS_EQUAL_OR_IN_GROUP(trigger_element, change->trigger_element)))
9373 change->actual_trigger_element = trigger_element;
9374 change->actual_trigger_player = EL_PLAYER_1 + log_2(trigger_player);
9375 change->actual_trigger_side = trigger_side;
9376 change->actual_trigger_ce_value = CustomValue[x][y];
9377 change->actual_trigger_ce_score = GET_CE_SCORE(trigger_element);
9379 /* special case: trigger element not at (x,y) position for some events */
9380 if (check_trigger_element)
9392 { 0, 0 }, { 0, 0 }, { 0, 0 },
9396 int xx = x + move_xy[MV_DIR_OPPOSITE(trigger_side)].dx;
9397 int yy = y + move_xy[MV_DIR_OPPOSITE(trigger_side)].dy;
9399 change->actual_trigger_ce_value = CustomValue[xx][yy];
9400 change->actual_trigger_ce_score = GET_CE_SCORE(trigger_element);
9403 if (change->can_change && !change_done)
9405 ChangeDelay[x][y] = 1;
9406 ChangeEvent[x][y] = trigger_event;
9408 HandleElementChange(x, y, p);
9412 #if USE_NEW_DELAYED_ACTION
9413 else if (change->has_action)
9415 ExecuteCustomElementAction(x, y, element, p);
9416 PlayLevelSoundElementAction(x, y, element, ACTION_PAGE_1 + p);
9419 if (change->has_action)
9421 ExecuteCustomElementAction(x, y, element, p);
9422 PlayLevelSoundElementAction(x, y, element, ACTION_PAGE_1 + p);
9428 RECURSION_LOOP_DETECTION_END();
9433 static void PlayPlayerSound(struct PlayerInfo *player)
9435 int jx = player->jx, jy = player->jy;
9436 int sound_element = player->artwork_element;
9437 int last_action = player->last_action_waiting;
9438 int action = player->action_waiting;
9440 if (player->is_waiting)
9442 if (action != last_action)
9443 PlayLevelSoundElementAction(jx, jy, sound_element, action);
9445 PlayLevelSoundElementActionIfLoop(jx, jy, sound_element, action);
9449 if (action != last_action)
9450 StopSound(element_info[sound_element].sound[last_action]);
9452 if (last_action == ACTION_SLEEPING)
9453 PlayLevelSoundElementAction(jx, jy, sound_element, ACTION_AWAKENING);
9457 static void PlayAllPlayersSound()
9461 for (i = 0; i < MAX_PLAYERS; i++)
9462 if (stored_player[i].active)
9463 PlayPlayerSound(&stored_player[i]);
9466 static void SetPlayerWaiting(struct PlayerInfo *player, boolean is_waiting)
9468 boolean last_waiting = player->is_waiting;
9469 int move_dir = player->MovDir;
9471 player->dir_waiting = move_dir;
9472 player->last_action_waiting = player->action_waiting;
9476 if (!last_waiting) /* not waiting -> waiting */
9478 player->is_waiting = TRUE;
9480 player->frame_counter_bored =
9482 game.player_boring_delay_fixed +
9483 GetSimpleRandom(game.player_boring_delay_random);
9484 player->frame_counter_sleeping =
9486 game.player_sleeping_delay_fixed +
9487 GetSimpleRandom(game.player_sleeping_delay_random);
9489 InitPlayerGfxAnimation(player, ACTION_WAITING, move_dir);
9492 if (game.player_sleeping_delay_fixed +
9493 game.player_sleeping_delay_random > 0 &&
9494 player->anim_delay_counter == 0 &&
9495 player->post_delay_counter == 0 &&
9496 FrameCounter >= player->frame_counter_sleeping)
9497 player->is_sleeping = TRUE;
9498 else if (game.player_boring_delay_fixed +
9499 game.player_boring_delay_random > 0 &&
9500 FrameCounter >= player->frame_counter_bored)
9501 player->is_bored = TRUE;
9503 player->action_waiting = (player->is_sleeping ? ACTION_SLEEPING :
9504 player->is_bored ? ACTION_BORING :
9507 if (player->is_sleeping && player->use_murphy)
9509 /* special case for sleeping Murphy when leaning against non-free tile */
9511 if (!IN_LEV_FIELD(player->jx - 1, player->jy) ||
9512 (Feld[player->jx - 1][player->jy] != EL_EMPTY &&
9513 !IS_MOVING(player->jx - 1, player->jy)))
9515 else if (!IN_LEV_FIELD(player->jx + 1, player->jy) ||
9516 (Feld[player->jx + 1][player->jy] != EL_EMPTY &&
9517 !IS_MOVING(player->jx + 1, player->jy)))
9518 move_dir = MV_RIGHT;
9520 player->is_sleeping = FALSE;
9522 player->dir_waiting = move_dir;
9525 if (player->is_sleeping)
9527 if (player->num_special_action_sleeping > 0)
9529 if (player->anim_delay_counter == 0 && player->post_delay_counter == 0)
9531 int last_special_action = player->special_action_sleeping;
9532 int num_special_action = player->num_special_action_sleeping;
9533 int special_action =
9534 (last_special_action == ACTION_DEFAULT ? ACTION_SLEEPING_1 :
9535 last_special_action == ACTION_SLEEPING ? ACTION_SLEEPING :
9536 last_special_action < ACTION_SLEEPING_1 + num_special_action - 1 ?
9537 last_special_action + 1 : ACTION_SLEEPING);
9538 int special_graphic =
9539 el_act_dir2img(player->artwork_element, special_action, move_dir);
9541 player->anim_delay_counter =
9542 graphic_info[special_graphic].anim_delay_fixed +
9543 GetSimpleRandom(graphic_info[special_graphic].anim_delay_random);
9544 player->post_delay_counter =
9545 graphic_info[special_graphic].post_delay_fixed +
9546 GetSimpleRandom(graphic_info[special_graphic].post_delay_random);
9548 player->special_action_sleeping = special_action;
9551 if (player->anim_delay_counter > 0)
9553 player->action_waiting = player->special_action_sleeping;
9554 player->anim_delay_counter--;
9556 else if (player->post_delay_counter > 0)
9558 player->post_delay_counter--;
9562 else if (player->is_bored)
9564 if (player->num_special_action_bored > 0)
9566 if (player->anim_delay_counter == 0 && player->post_delay_counter == 0)
9568 int special_action =
9569 ACTION_BORING_1 + GetSimpleRandom(player->num_special_action_bored);
9570 int special_graphic =
9571 el_act_dir2img(player->artwork_element, special_action, move_dir);
9573 player->anim_delay_counter =
9574 graphic_info[special_graphic].anim_delay_fixed +
9575 GetSimpleRandom(graphic_info[special_graphic].anim_delay_random);
9576 player->post_delay_counter =
9577 graphic_info[special_graphic].post_delay_fixed +
9578 GetSimpleRandom(graphic_info[special_graphic].post_delay_random);
9580 player->special_action_bored = special_action;
9583 if (player->anim_delay_counter > 0)
9585 player->action_waiting = player->special_action_bored;
9586 player->anim_delay_counter--;
9588 else if (player->post_delay_counter > 0)
9590 player->post_delay_counter--;
9595 else if (last_waiting) /* waiting -> not waiting */
9597 player->is_waiting = FALSE;
9598 player->is_bored = FALSE;
9599 player->is_sleeping = FALSE;
9601 player->frame_counter_bored = -1;
9602 player->frame_counter_sleeping = -1;
9604 player->anim_delay_counter = 0;
9605 player->post_delay_counter = 0;
9607 player->dir_waiting = player->MovDir;
9608 player->action_waiting = ACTION_DEFAULT;
9610 player->special_action_bored = ACTION_DEFAULT;
9611 player->special_action_sleeping = ACTION_DEFAULT;
9615 static byte PlayerActions(struct PlayerInfo *player, byte player_action)
9617 boolean moved = FALSE, snapped = FALSE, dropped = FALSE;
9618 int left = player_action & JOY_LEFT;
9619 int right = player_action & JOY_RIGHT;
9620 int up = player_action & JOY_UP;
9621 int down = player_action & JOY_DOWN;
9622 int button1 = player_action & JOY_BUTTON_1;
9623 int button2 = player_action & JOY_BUTTON_2;
9624 int dx = (left ? -1 : right ? 1 : 0);
9625 int dy = (up ? -1 : down ? 1 : 0);
9627 if (!player->active || tape.pausing)
9633 snapped = SnapField(player, dx, dy);
9637 dropped = DropElement(player);
9639 moved = MovePlayer(player, dx, dy);
9642 if (tape.single_step && tape.recording && !tape.pausing)
9644 if (button1 || (dropped && !moved))
9646 TapeTogglePause(TAPE_TOGGLE_AUTOMATIC);
9647 SnapField(player, 0, 0); /* stop snapping */
9651 SetPlayerWaiting(player, FALSE);
9653 return player_action;
9657 /* no actions for this player (no input at player's configured device) */
9659 DigField(player, 0, 0, 0, 0, 0, 0, DF_NO_PUSH);
9660 SnapField(player, 0, 0);
9661 CheckGravityMovementWhenNotMoving(player);
9663 if (player->MovPos == 0)
9664 SetPlayerWaiting(player, TRUE);
9666 if (player->MovPos == 0) /* needed for tape.playing */
9667 player->is_moving = FALSE;
9669 player->is_dropping = FALSE;
9670 player->is_dropping_pressed = FALSE;
9671 player->drop_pressed_delay = 0;
9677 static void CheckLevelTime()
9681 if (level.game_engine_type == GAME_ENGINE_TYPE_EM)
9683 if (level.native_em_level->lev->home == 0) /* all players at home */
9685 PlayerWins(local_player);
9687 AllPlayersGone = TRUE;
9689 level.native_em_level->lev->home = -1;
9692 if (level.native_em_level->ply[0]->alive == 0 &&
9693 level.native_em_level->ply[1]->alive == 0 &&
9694 level.native_em_level->ply[2]->alive == 0 &&
9695 level.native_em_level->ply[3]->alive == 0) /* all dead */
9696 AllPlayersGone = TRUE;
9699 if (TimeFrames >= FRAMES_PER_SECOND)
9704 for (i = 0; i < MAX_PLAYERS; i++)
9706 struct PlayerInfo *player = &stored_player[i];
9708 if (SHIELD_ON(player))
9710 player->shield_normal_time_left--;
9712 if (player->shield_deadly_time_left > 0)
9713 player->shield_deadly_time_left--;
9717 if (!local_player->LevelSolved && !level.use_step_counter)
9725 if (TimeLeft <= 10 && setup.time_limit)
9726 PlaySound(SND_GAME_RUNNING_OUT_OF_TIME);
9728 DrawGameValue_Time(TimeLeft);
9730 if (!TimeLeft && setup.time_limit)
9732 if (level.game_engine_type == GAME_ENGINE_TYPE_EM)
9733 level.native_em_level->lev->killed_out_of_time = TRUE;
9735 for (i = 0; i < MAX_PLAYERS; i++)
9736 KillPlayer(&stored_player[i]);
9739 else if (level.time == 0 && !AllPlayersGone) /* level w/o time limit */
9740 DrawGameValue_Time(TimePlayed);
9742 level.native_em_level->lev->time =
9743 (level.time == 0 ? TimePlayed : TimeLeft);
9746 if (tape.recording || tape.playing)
9747 DrawVideoDisplay(VIDEO_STATE_TIME_ON, TapeTime);
9751 void AdvanceFrameAndPlayerCounters(int player_nr)
9755 /* advance frame counters (global frame counter and time frame counter) */
9759 /* advance player counters (counters for move delay, move animation etc.) */
9760 for (i = 0; i < MAX_PLAYERS; i++)
9762 boolean advance_player_counters = (player_nr == -1 || player_nr == i);
9763 int move_delay_value = stored_player[i].move_delay_value;
9764 int move_frames = MOVE_DELAY_NORMAL_SPEED / move_delay_value;
9766 if (!advance_player_counters) /* not all players may be affected */
9769 #if USE_NEW_PLAYER_ANIM
9770 if (move_frames == 0) /* less than one move per game frame */
9772 int stepsize = TILEX / move_delay_value;
9773 int delay = move_delay_value / MOVE_DELAY_NORMAL_SPEED;
9774 int count = (stored_player[i].is_moving ?
9775 ABS(stored_player[i].MovPos) / stepsize : FrameCounter);
9777 if (count % delay == 0)
9782 stored_player[i].Frame += move_frames;
9784 if (stored_player[i].MovPos != 0)
9785 stored_player[i].StepFrame += move_frames;
9787 if (stored_player[i].move_delay > 0)
9788 stored_player[i].move_delay--;
9790 /* due to bugs in previous versions, counter must count up, not down */
9791 if (stored_player[i].push_delay != -1)
9792 stored_player[i].push_delay++;
9794 if (stored_player[i].drop_delay > 0)
9795 stored_player[i].drop_delay--;
9797 if (stored_player[i].is_dropping_pressed)
9798 stored_player[i].drop_pressed_delay++;
9802 void StartGameActions(boolean init_network_game, boolean record_tape,
9805 unsigned long new_random_seed = InitRND(random_seed);
9808 TapeStartRecording(new_random_seed);
9810 #if defined(NETWORK_AVALIABLE)
9811 if (init_network_game)
9813 SendToServer_StartPlaying();
9824 static unsigned long game_frame_delay = 0;
9825 unsigned long game_frame_delay_value;
9826 byte *recorded_player_action;
9827 byte summarized_player_action = 0;
9828 byte tape_action[MAX_PLAYERS];
9831 /* detect endless loops, caused by custom element programming */
9832 if (recursion_loop_detected && recursion_loop_depth == 0)
9834 char *message = getStringCat3("Internal Error ! Element ",
9835 EL_NAME(recursion_loop_element),
9836 " caused endless loop ! Quit the game ?");
9838 Error(ERR_WARN, "element '%s' caused endless loop in game engine",
9839 EL_NAME(recursion_loop_element));
9841 RequestQuitGameExt(FALSE, level_editor_test_game, message);
9843 recursion_loop_detected = FALSE; /* if game should be continued */
9850 if (game.restart_level)
9851 StartGameActions(options.network, setup.autorecord, NEW_RANDOMIZE);
9853 if (level.game_engine_type == GAME_ENGINE_TYPE_EM)
9855 if (level.native_em_level->lev->home == 0) /* all players at home */
9857 PlayerWins(local_player);
9859 AllPlayersGone = TRUE;
9861 level.native_em_level->lev->home = -1;
9864 if (level.native_em_level->ply[0]->alive == 0 &&
9865 level.native_em_level->ply[1]->alive == 0 &&
9866 level.native_em_level->ply[2]->alive == 0 &&
9867 level.native_em_level->ply[3]->alive == 0) /* all dead */
9868 AllPlayersGone = TRUE;
9871 if (local_player->LevelSolved)
9874 if (AllPlayersGone && !TAPE_IS_STOPPED(tape))
9877 if (game_status != GAME_MODE_PLAYING) /* status might have changed */
9880 game_frame_delay_value =
9881 (tape.playing && tape.fast_forward ? FfwdFrameDelay : GameFrameDelay);
9883 if (tape.playing && tape.warp_forward && !tape.pausing)
9884 game_frame_delay_value = 0;
9886 /* ---------- main game synchronization point ---------- */
9888 WaitUntilDelayReached(&game_frame_delay, game_frame_delay_value);
9890 if (network_playing && !network_player_action_received)
9892 /* try to get network player actions in time */
9894 #if defined(NETWORK_AVALIABLE)
9895 /* last chance to get network player actions without main loop delay */
9899 /* game was quit by network peer */
9900 if (game_status != GAME_MODE_PLAYING)
9903 if (!network_player_action_received)
9904 return; /* failed to get network player actions in time */
9906 /* do not yet reset "network_player_action_received" (for tape.pausing) */
9912 /* at this point we know that we really continue executing the game */
9914 network_player_action_received = FALSE;
9916 /* when playing tape, read previously recorded player input from tape data */
9917 recorded_player_action = (tape.playing ? TapePlayAction() : NULL);
9920 /* TapePlayAction() may return NULL when toggling to "pause before death" */
9925 if (tape.set_centered_player)
9927 game.centered_player_nr_next = tape.centered_player_nr_next;
9928 game.set_centered_player = TRUE;
9931 for (i = 0; i < MAX_PLAYERS; i++)
9933 summarized_player_action |= stored_player[i].action;
9935 if (!network_playing)
9936 stored_player[i].effective_action = stored_player[i].action;
9939 #if defined(NETWORK_AVALIABLE)
9940 if (network_playing)
9941 SendToServer_MovePlayer(summarized_player_action);
9944 if (!options.network && !setup.team_mode)
9945 local_player->effective_action = summarized_player_action;
9947 if (setup.team_mode && setup.input_on_focus && game.centered_player_nr != -1)
9949 for (i = 0; i < MAX_PLAYERS; i++)
9950 stored_player[i].effective_action =
9951 (i == game.centered_player_nr ? summarized_player_action : 0);
9954 if (recorded_player_action != NULL)
9955 for (i = 0; i < MAX_PLAYERS; i++)
9956 stored_player[i].effective_action = recorded_player_action[i];
9958 for (i = 0; i < MAX_PLAYERS; i++)
9960 tape_action[i] = stored_player[i].effective_action;
9962 /* (this can only happen in the R'n'D game engine) */
9963 if (tape.recording && tape_action[i] && !tape.player_participates[i])
9964 tape.player_participates[i] = TRUE; /* player just appeared from CE */
9967 /* only record actions from input devices, but not programmed actions */
9969 TapeRecordAction(tape_action);
9971 if (level.game_engine_type == GAME_ENGINE_TYPE_EM)
9973 GameActions_EM_Main();
9981 void GameActions_EM_Main()
9983 byte effective_action[MAX_PLAYERS];
9984 boolean warp_mode = (tape.playing && tape.warp_forward && !tape.pausing);
9987 for (i = 0; i < MAX_PLAYERS; i++)
9988 effective_action[i] = stored_player[i].effective_action;
9990 GameActions_EM(effective_action, warp_mode);
9994 AdvanceFrameAndPlayerCounters(-1); /* advance counters for all players */
9997 void GameActions_RND()
9999 int magic_wall_x = 0, magic_wall_y = 0;
10000 int i, x, y, element, graphic;
10002 InitPlayfieldScanModeVars();
10004 #if USE_ONE_MORE_CHANGE_PER_FRAME
10005 if (game.engine_version >= VERSION_IDENT(3,2,0,7))
10007 SCAN_PLAYFIELD(x, y)
10009 ChangeCount[x][y] = 0;
10010 ChangeEvent[x][y] = -1;
10015 if (game.set_centered_player)
10017 boolean all_players_fit_to_screen = checkIfAllPlayersFitToScreen_RND();
10019 /* switching to "all players" only possible if all players fit to screen */
10020 if (game.centered_player_nr_next == -1 && !all_players_fit_to_screen)
10022 game.centered_player_nr_next = game.centered_player_nr;
10023 game.set_centered_player = FALSE;
10026 /* do not switch focus to non-existing (or non-active) player */
10027 if (game.centered_player_nr_next >= 0 &&
10028 !stored_player[game.centered_player_nr_next].active)
10030 game.centered_player_nr_next = game.centered_player_nr;
10031 game.set_centered_player = FALSE;
10035 if (game.set_centered_player &&
10036 ScreenMovPos == 0) /* screen currently aligned at tile position */
10040 if (game.centered_player_nr_next == -1)
10042 setScreenCenteredToAllPlayers(&sx, &sy);
10046 sx = stored_player[game.centered_player_nr_next].jx;
10047 sy = stored_player[game.centered_player_nr_next].jy;
10050 game.centered_player_nr = game.centered_player_nr_next;
10051 game.set_centered_player = FALSE;
10053 DrawRelocateScreen(0, 0, sx, sy, MV_NONE, TRUE, setup.quick_switch);
10054 DrawGameDoorValues();
10057 for (i = 0; i < MAX_PLAYERS; i++)
10059 int actual_player_action = stored_player[i].effective_action;
10062 /* !!! THIS BREAKS THE FOLLOWING TAPES: !!!
10063 - rnd_equinox_tetrachloride 048
10064 - rnd_equinox_tetrachloride_ii 096
10065 - rnd_emanuel_schmieg 002
10066 - doctor_sloan_ww 001, 020
10068 if (stored_player[i].MovPos == 0)
10069 CheckGravityMovement(&stored_player[i]);
10072 /* overwrite programmed action with tape action */
10073 if (stored_player[i].programmed_action)
10074 actual_player_action = stored_player[i].programmed_action;
10076 PlayerActions(&stored_player[i], actual_player_action);
10078 ScrollPlayer(&stored_player[i], SCROLL_GO_ON);
10081 ScrollScreen(NULL, SCROLL_GO_ON);
10083 /* for backwards compatibility, the following code emulates a fixed bug that
10084 occured when pushing elements (causing elements that just made their last
10085 pushing step to already (if possible) make their first falling step in the
10086 same game frame, which is bad); this code is also needed to use the famous
10087 "spring push bug" which is used in older levels and might be wanted to be
10088 used also in newer levels, but in this case the buggy pushing code is only
10089 affecting the "spring" element and no other elements */
10091 if (game.engine_version < VERSION_IDENT(2,2,0,7) || level.use_spring_bug)
10093 for (i = 0; i < MAX_PLAYERS; i++)
10095 struct PlayerInfo *player = &stored_player[i];
10096 int x = player->jx;
10097 int y = player->jy;
10099 if (player->active && player->is_pushing && player->is_moving &&
10101 (game.engine_version < VERSION_IDENT(2,2,0,7) ||
10102 Feld[x][y] == EL_SPRING))
10104 ContinueMoving(x, y);
10106 /* continue moving after pushing (this is actually a bug) */
10107 if (!IS_MOVING(x, y))
10109 Stop[x][y] = FALSE;
10115 SCAN_PLAYFIELD(x, y)
10117 ChangeCount[x][y] = 0;
10118 ChangeEvent[x][y] = -1;
10120 /* this must be handled before main playfield loop */
10121 if (Feld[x][y] == EL_PLAYER_IS_LEAVING)
10124 if (MovDelay[x][y] <= 0)
10128 #if USE_NEW_SNAP_DELAY
10129 if (Feld[x][y] == EL_ELEMENT_SNAPPING)
10132 if (MovDelay[x][y] <= 0)
10135 DrawLevelField(x, y);
10137 TestIfElementTouchesCustomElement(x, y); /* for empty space */
10143 if (ChangePage[x][y] != -1 && ChangeDelay[x][y] != 1)
10145 printf("GameActions(): x = %d, y = %d: ChangePage != -1\n", x, y);
10146 printf("GameActions(): This should never happen!\n");
10148 ChangePage[x][y] = -1;
10152 Stop[x][y] = FALSE;
10153 if (WasJustMoving[x][y] > 0)
10154 WasJustMoving[x][y]--;
10155 if (WasJustFalling[x][y] > 0)
10156 WasJustFalling[x][y]--;
10157 if (CheckCollision[x][y] > 0)
10158 CheckCollision[x][y]--;
10159 if (CheckImpact[x][y] > 0)
10160 CheckImpact[x][y]--;
10164 /* reset finished pushing action (not done in ContinueMoving() to allow
10165 continuous pushing animation for elements with zero push delay) */
10166 if (GfxAction[x][y] == ACTION_PUSHING && !IS_MOVING(x, y))
10168 ResetGfxAnimation(x, y);
10169 DrawLevelField(x, y);
10173 if (IS_BLOCKED(x, y))
10177 Blocked2Moving(x, y, &oldx, &oldy);
10178 if (!IS_MOVING(oldx, oldy))
10180 printf("GameActions(): (BLOCKED => MOVING) context corrupted!\n");
10181 printf("GameActions(): BLOCKED: x = %d, y = %d\n", x, y);
10182 printf("GameActions(): !MOVING: oldx = %d, oldy = %d\n", oldx, oldy);
10183 printf("GameActions(): This should never happen!\n");
10189 SCAN_PLAYFIELD(x, y)
10191 element = Feld[x][y];
10192 graphic = el_act_dir2img(element, GfxAction[x][y], GfxDir[x][y]);
10194 ResetGfxFrame(x, y, TRUE);
10196 if (ANIM_MODE(graphic) == ANIM_RANDOM &&
10197 IS_NEXT_FRAME(GfxFrame[x][y], graphic))
10198 ResetRandomAnimationValue(x, y);
10200 SetRandomAnimationValue(x, y);
10202 PlayLevelSoundActionIfLoop(x, y, GfxAction[x][y]);
10204 if (IS_INACTIVE(element))
10206 if (IS_ANIMATED(graphic))
10207 DrawLevelGraphicAnimationIfNeeded(x, y, graphic);
10212 /* this may take place after moving, so 'element' may have changed */
10213 if (IS_CHANGING(x, y) &&
10214 (game.engine_version < VERSION_IDENT(3,0,7,1) || !Stop[x][y]))
10216 int page = element_info[element].event_page_nr[CE_DELAY];
10219 HandleElementChange(x, y, page);
10221 if (CAN_CHANGE(element))
10222 HandleElementChange(x, y, page);
10224 if (HAS_ACTION(element))
10225 ExecuteCustomElementAction(x, y, element, page);
10228 element = Feld[x][y];
10229 graphic = el_act_dir2img(element, GfxAction[x][y], GfxDir[x][y]);
10232 if (!IS_MOVING(x, y) && (CAN_FALL(element) || CAN_MOVE(element)))
10236 element = Feld[x][y];
10237 graphic = el_act_dir2img(element, GfxAction[x][y], GfxDir[x][y]);
10239 if (IS_ANIMATED(graphic) &&
10240 !IS_MOVING(x, y) &&
10242 DrawLevelGraphicAnimationIfNeeded(x, y, graphic);
10244 if (IS_GEM(element) || element == EL_SP_INFOTRON)
10245 DrawTwinkleOnField(x, y);
10247 else if ((element == EL_ACID ||
10248 element == EL_EXIT_OPEN ||
10249 element == EL_EM_EXIT_OPEN ||
10250 element == EL_SP_EXIT_OPEN ||
10251 element == EL_STEEL_EXIT_OPEN ||
10252 element == EL_EM_STEEL_EXIT_OPEN ||
10253 element == EL_SP_TERMINAL ||
10254 element == EL_SP_TERMINAL_ACTIVE ||
10255 element == EL_EXTRA_TIME ||
10256 element == EL_SHIELD_NORMAL ||
10257 element == EL_SHIELD_DEADLY) &&
10258 IS_ANIMATED(graphic))
10259 DrawLevelGraphicAnimationIfNeeded(x, y, graphic);
10260 else if (IS_MOVING(x, y))
10261 ContinueMoving(x, y);
10262 else if (IS_ACTIVE_BOMB(element))
10263 CheckDynamite(x, y);
10264 else if (element == EL_AMOEBA_GROWING)
10265 AmoebeWaechst(x, y);
10266 else if (element == EL_AMOEBA_SHRINKING)
10267 AmoebaDisappearing(x, y);
10269 #if !USE_NEW_AMOEBA_CODE
10270 else if (IS_AMOEBALIVE(element))
10271 AmoebeAbleger(x, y);
10274 else if (element == EL_GAME_OF_LIFE || element == EL_BIOMAZE)
10276 else if (element == EL_EXIT_CLOSED)
10278 else if (element == EL_EM_EXIT_CLOSED)
10280 else if (element == EL_STEEL_EXIT_CLOSED)
10281 CheckExitSteel(x, y);
10282 else if (element == EL_EM_STEEL_EXIT_CLOSED)
10283 CheckExitSteelEM(x, y);
10284 else if (element == EL_SP_EXIT_CLOSED)
10286 else if (element == EL_EXPANDABLE_WALL_GROWING ||
10287 element == EL_EXPANDABLE_STEELWALL_GROWING)
10288 MauerWaechst(x, y);
10289 else if (element == EL_EXPANDABLE_WALL ||
10290 element == EL_EXPANDABLE_WALL_HORIZONTAL ||
10291 element == EL_EXPANDABLE_WALL_VERTICAL ||
10292 element == EL_EXPANDABLE_WALL_ANY ||
10293 element == EL_BD_EXPANDABLE_WALL)
10294 MauerAbleger(x, y);
10295 else if (element == EL_EXPANDABLE_STEELWALL_HORIZONTAL ||
10296 element == EL_EXPANDABLE_STEELWALL_VERTICAL ||
10297 element == EL_EXPANDABLE_STEELWALL_ANY)
10298 MauerAblegerStahl(x, y);
10299 else if (element == EL_FLAMES)
10300 CheckForDragon(x, y);
10301 else if (element == EL_EXPLOSION)
10302 ; /* drawing of correct explosion animation is handled separately */
10303 else if (element == EL_ELEMENT_SNAPPING ||
10304 element == EL_DIAGONAL_SHRINKING ||
10305 element == EL_DIAGONAL_GROWING)
10307 graphic = el_act_dir2img(GfxElement[x][y], GfxAction[x][y],GfxDir[x][y]);
10309 DrawLevelGraphicAnimationIfNeeded(x, y, graphic);
10311 else if (IS_ANIMATED(graphic) && !IS_CHANGING(x, y))
10312 DrawLevelGraphicAnimationIfNeeded(x, y, graphic);
10314 if (IS_BELT_ACTIVE(element))
10315 PlayLevelSoundAction(x, y, ACTION_ACTIVE);
10317 if (game.magic_wall_active)
10319 int jx = local_player->jx, jy = local_player->jy;
10321 /* play the element sound at the position nearest to the player */
10322 if ((element == EL_MAGIC_WALL_FULL ||
10323 element == EL_MAGIC_WALL_ACTIVE ||
10324 element == EL_MAGIC_WALL_EMPTYING ||
10325 element == EL_BD_MAGIC_WALL_FULL ||
10326 element == EL_BD_MAGIC_WALL_ACTIVE ||
10327 element == EL_BD_MAGIC_WALL_EMPTYING ||
10328 element == EL_DC_MAGIC_WALL_FULL ||
10329 element == EL_DC_MAGIC_WALL_ACTIVE ||
10330 element == EL_DC_MAGIC_WALL_EMPTYING) &&
10331 ABS(x-jx) + ABS(y-jy) < ABS(magic_wall_x-jx) + ABS(magic_wall_y-jy))
10339 #if USE_NEW_AMOEBA_CODE
10340 /* new experimental amoeba growth stuff */
10341 if (!(FrameCounter % 8))
10343 static unsigned long random = 1684108901;
10345 for (i = 0; i < level.amoeba_speed * 28 / 8; i++)
10347 x = RND(lev_fieldx);
10348 y = RND(lev_fieldy);
10349 element = Feld[x][y];
10351 if (!IS_PLAYER(x,y) &&
10352 (element == EL_EMPTY ||
10353 CAN_GROW_INTO(element) ||
10354 element == EL_QUICKSAND_EMPTY ||
10355 element == EL_QUICKSAND_FAST_EMPTY ||
10356 element == EL_ACID_SPLASH_LEFT ||
10357 element == EL_ACID_SPLASH_RIGHT))
10359 if ((IN_LEV_FIELD(x, y-1) && Feld[x][y-1] == EL_AMOEBA_WET) ||
10360 (IN_LEV_FIELD(x-1, y) && Feld[x-1][y] == EL_AMOEBA_WET) ||
10361 (IN_LEV_FIELD(x+1, y) && Feld[x+1][y] == EL_AMOEBA_WET) ||
10362 (IN_LEV_FIELD(x, y+1) && Feld[x][y+1] == EL_AMOEBA_WET))
10363 Feld[x][y] = EL_AMOEBA_DROP;
10366 random = random * 129 + 1;
10372 if (game.explosions_delayed)
10375 game.explosions_delayed = FALSE;
10377 SCAN_PLAYFIELD(x, y)
10379 element = Feld[x][y];
10381 if (ExplodeField[x][y])
10382 Explode(x, y, EX_PHASE_START, ExplodeField[x][y]);
10383 else if (element == EL_EXPLOSION)
10384 Explode(x, y, ExplodePhase[x][y], EX_TYPE_NORMAL);
10386 ExplodeField[x][y] = EX_TYPE_NONE;
10389 game.explosions_delayed = TRUE;
10392 if (game.magic_wall_active)
10394 if (!(game.magic_wall_time_left % 4))
10396 int element = Feld[magic_wall_x][magic_wall_y];
10398 if (element == EL_BD_MAGIC_WALL_FULL ||
10399 element == EL_BD_MAGIC_WALL_ACTIVE ||
10400 element == EL_BD_MAGIC_WALL_EMPTYING)
10401 PlayLevelSound(magic_wall_x, magic_wall_y, SND_BD_MAGIC_WALL_ACTIVE);
10402 else if (element == EL_DC_MAGIC_WALL_FULL ||
10403 element == EL_DC_MAGIC_WALL_ACTIVE ||
10404 element == EL_DC_MAGIC_WALL_EMPTYING)
10405 PlayLevelSound(magic_wall_x, magic_wall_y, SND_DC_MAGIC_WALL_ACTIVE);
10407 PlayLevelSound(magic_wall_x, magic_wall_y, SND_MAGIC_WALL_ACTIVE);
10410 if (game.magic_wall_time_left > 0)
10412 game.magic_wall_time_left--;
10413 if (!game.magic_wall_time_left)
10415 SCAN_PLAYFIELD(x, y)
10417 element = Feld[x][y];
10419 if (element == EL_MAGIC_WALL_ACTIVE ||
10420 element == EL_MAGIC_WALL_FULL)
10422 Feld[x][y] = EL_MAGIC_WALL_DEAD;
10423 DrawLevelField(x, y);
10425 else if (element == EL_BD_MAGIC_WALL_ACTIVE ||
10426 element == EL_BD_MAGIC_WALL_FULL)
10428 Feld[x][y] = EL_BD_MAGIC_WALL_DEAD;
10429 DrawLevelField(x, y);
10431 else if (element == EL_DC_MAGIC_WALL_ACTIVE ||
10432 element == EL_DC_MAGIC_WALL_FULL)
10434 Feld[x][y] = EL_DC_MAGIC_WALL_DEAD;
10435 DrawLevelField(x, y);
10439 game.magic_wall_active = FALSE;
10444 if (game.light_time_left > 0)
10446 game.light_time_left--;
10448 if (game.light_time_left == 0)
10449 RedrawAllLightSwitchesAndInvisibleElements();
10452 if (game.timegate_time_left > 0)
10454 game.timegate_time_left--;
10456 if (game.timegate_time_left == 0)
10457 CloseAllOpenTimegates();
10460 if (game.lenses_time_left > 0)
10462 game.lenses_time_left--;
10464 if (game.lenses_time_left == 0)
10465 RedrawAllInvisibleElementsForLenses();
10468 if (game.magnify_time_left > 0)
10470 game.magnify_time_left--;
10472 if (game.magnify_time_left == 0)
10473 RedrawAllInvisibleElementsForMagnifier();
10476 for (i = 0; i < MAX_PLAYERS; i++)
10478 struct PlayerInfo *player = &stored_player[i];
10480 if (SHIELD_ON(player))
10482 if (player->shield_deadly_time_left)
10483 PlayLevelSound(player->jx, player->jy, SND_SHIELD_DEADLY_ACTIVE);
10484 else if (player->shield_normal_time_left)
10485 PlayLevelSound(player->jx, player->jy, SND_SHIELD_NORMAL_ACTIVE);
10492 PlayAllPlayersSound();
10494 if (options.debug) /* calculate frames per second */
10496 static unsigned long fps_counter = 0;
10497 static int fps_frames = 0;
10498 unsigned long fps_delay_ms = Counter() - fps_counter;
10502 if (fps_delay_ms >= 500) /* calculate fps every 0.5 seconds */
10504 global.frames_per_second = 1000 * (float)fps_frames / fps_delay_ms;
10507 fps_counter = Counter();
10510 redraw_mask |= REDRAW_FPS;
10513 AdvanceFrameAndPlayerCounters(-1); /* advance counters for all players */
10515 if (local_player->show_envelope != 0 && local_player->MovPos == 0)
10517 ShowEnvelope(local_player->show_envelope - EL_ENVELOPE_1);
10519 local_player->show_envelope = 0;
10522 /* use random number generator in every frame to make it less predictable */
10523 if (game.engine_version >= VERSION_IDENT(3,1,1,0))
10527 static boolean AllPlayersInSight(struct PlayerInfo *player, int x, int y)
10529 int min_x = x, min_y = y, max_x = x, max_y = y;
10532 for (i = 0; i < MAX_PLAYERS; i++)
10534 int jx = stored_player[i].jx, jy = stored_player[i].jy;
10536 if (!stored_player[i].active || &stored_player[i] == player)
10539 min_x = MIN(min_x, jx);
10540 min_y = MIN(min_y, jy);
10541 max_x = MAX(max_x, jx);
10542 max_y = MAX(max_y, jy);
10545 return (max_x - min_x < SCR_FIELDX && max_y - min_y < SCR_FIELDY);
10548 static boolean AllPlayersInVisibleScreen()
10552 for (i = 0; i < MAX_PLAYERS; i++)
10554 int jx = stored_player[i].jx, jy = stored_player[i].jy;
10556 if (!stored_player[i].active)
10559 if (!IN_VIS_FIELD(SCREENX(jx), SCREENY(jy)))
10566 void ScrollLevel(int dx, int dy)
10570 /* only horizontal XOR vertical scroll direction allowed */
10571 if ((dx == 0 && dy == 0) || (dx != 0 && dy != 0))
10575 int xsize = (BX2 - BX1 + 1);
10576 int ysize = (BY2 - BY1 + 1);
10577 int start = (dx != 0 ? (dx == -1 ? BX1 : BX2) : (dy == -1 ? BY1 : BY2));
10578 int end = (dx != 0 ? (dx == -1 ? BX2 : BX1) : (dy == -1 ? BY2 : BY1));
10579 int step = (start < end ? +1 : -1);
10581 for (i = start; i != end; i += step)
10583 BlitBitmap(drawto_field, drawto_field,
10584 FX + TILEX * (dx != 0 ? i + step : 0),
10585 FY + TILEY * (dy != 0 ? i + step : 0),
10586 TILEX * (dx != 0 ? 1 : xsize),
10587 TILEY * (dy != 0 ? 1 : ysize),
10588 FX + TILEX * (dx != 0 ? i : 0),
10589 FY + TILEY * (dy != 0 ? i : 0));
10594 int softscroll_offset = (setup.soft_scrolling ? TILEX : 0);
10596 BlitBitmap(drawto_field, drawto_field,
10597 FX + TILEX * (dx == -1) - softscroll_offset,
10598 FY + TILEY * (dy == -1) - softscroll_offset,
10599 SXSIZE - TILEX * (dx != 0) + 2 * softscroll_offset,
10600 SYSIZE - TILEY * (dy != 0) + 2 * softscroll_offset,
10601 FX + TILEX * (dx == 1) - softscroll_offset,
10602 FY + TILEY * (dy == 1) - softscroll_offset);
10607 x = (dx == 1 ? BX1 : BX2);
10608 for (y = BY1; y <= BY2; y++)
10609 DrawScreenField(x, y);
10614 y = (dy == 1 ? BY1 : BY2);
10615 for (x = BX1; x <= BX2; x++)
10616 DrawScreenField(x, y);
10619 redraw_mask |= REDRAW_FIELD;
10622 static boolean canFallDown(struct PlayerInfo *player)
10624 int jx = player->jx, jy = player->jy;
10626 return (IN_LEV_FIELD(jx, jy + 1) &&
10627 (IS_FREE(jx, jy + 1) ||
10628 (Feld[jx][jy + 1] == EL_ACID && player->can_fall_into_acid)) &&
10629 IS_WALKABLE_FROM(Feld[jx][jy], MV_DOWN) &&
10630 !IS_WALKABLE_INSIDE(Feld[jx][jy]));
10633 static boolean canPassField(int x, int y, int move_dir)
10635 int opposite_dir = MV_DIR_OPPOSITE(move_dir);
10636 int dx = (move_dir & MV_LEFT ? -1 : move_dir & MV_RIGHT ? +1 : 0);
10637 int dy = (move_dir & MV_UP ? -1 : move_dir & MV_DOWN ? +1 : 0);
10638 int nextx = x + dx;
10639 int nexty = y + dy;
10640 int element = Feld[x][y];
10642 return (IS_PASSABLE_FROM(element, opposite_dir) &&
10643 !CAN_MOVE(element) &&
10644 IN_LEV_FIELD(nextx, nexty) && !IS_PLAYER(nextx, nexty) &&
10645 IS_WALKABLE_FROM(Feld[nextx][nexty], move_dir) &&
10646 (level.can_pass_to_walkable || IS_FREE(nextx, nexty)));
10649 static boolean canMoveToValidFieldWithGravity(int x, int y, int move_dir)
10651 int opposite_dir = MV_DIR_OPPOSITE(move_dir);
10652 int dx = (move_dir & MV_LEFT ? -1 : move_dir & MV_RIGHT ? +1 : 0);
10653 int dy = (move_dir & MV_UP ? -1 : move_dir & MV_DOWN ? +1 : 0);
10657 return (IN_LEV_FIELD(newx, newy) && !IS_FREE_OR_PLAYER(newx, newy) &&
10658 IS_GRAVITY_REACHABLE(Feld[newx][newy]) &&
10659 (IS_DIGGABLE(Feld[newx][newy]) ||
10660 IS_WALKABLE_FROM(Feld[newx][newy], opposite_dir) ||
10661 canPassField(newx, newy, move_dir)));
10664 static void CheckGravityMovement(struct PlayerInfo *player)
10666 #if USE_PLAYER_GRAVITY
10667 if (player->gravity && !player->programmed_action)
10669 if (game.gravity && !player->programmed_action)
10672 int move_dir_horizontal = player->effective_action & MV_HORIZONTAL;
10673 int move_dir_vertical = player->effective_action & MV_VERTICAL;
10674 boolean player_is_snapping = (player->effective_action & JOY_BUTTON_1);
10675 int jx = player->jx, jy = player->jy;
10676 boolean player_is_moving_to_valid_field =
10677 (!player_is_snapping &&
10678 (canMoveToValidFieldWithGravity(jx, jy, move_dir_horizontal) ||
10679 canMoveToValidFieldWithGravity(jx, jy, move_dir_vertical)));
10680 boolean player_can_fall_down = canFallDown(player);
10682 if (player_can_fall_down &&
10683 !player_is_moving_to_valid_field)
10684 player->programmed_action = MV_DOWN;
10688 static void CheckGravityMovementWhenNotMoving(struct PlayerInfo *player)
10690 return CheckGravityMovement(player);
10692 #if USE_PLAYER_GRAVITY
10693 if (player->gravity && !player->programmed_action)
10695 if (game.gravity && !player->programmed_action)
10698 int jx = player->jx, jy = player->jy;
10699 boolean field_under_player_is_free =
10700 (IN_LEV_FIELD(jx, jy + 1) && IS_FREE(jx, jy + 1));
10701 boolean player_is_standing_on_valid_field =
10702 (IS_WALKABLE_INSIDE(Feld[jx][jy]) ||
10703 (IS_WALKABLE(Feld[jx][jy]) &&
10704 !(element_info[Feld[jx][jy]].access_direction & MV_DOWN)));
10706 if (field_under_player_is_free && !player_is_standing_on_valid_field)
10707 player->programmed_action = MV_DOWN;
10712 MovePlayerOneStep()
10713 -----------------------------------------------------------------------------
10714 dx, dy: direction (non-diagonal) to try to move the player to
10715 real_dx, real_dy: direction as read from input device (can be diagonal)
10718 boolean MovePlayerOneStep(struct PlayerInfo *player,
10719 int dx, int dy, int real_dx, int real_dy)
10721 int jx = player->jx, jy = player->jy;
10722 int new_jx = jx + dx, new_jy = jy + dy;
10723 #if !USE_FIXED_DONT_RUN_INTO
10727 boolean player_can_move = !player->cannot_move;
10729 if (!player->active || (!dx && !dy))
10730 return MP_NO_ACTION;
10732 player->MovDir = (dx < 0 ? MV_LEFT :
10733 dx > 0 ? MV_RIGHT :
10735 dy > 0 ? MV_DOWN : MV_NONE);
10737 if (!IN_LEV_FIELD(new_jx, new_jy))
10738 return MP_NO_ACTION;
10740 if (!player_can_move)
10742 if (player->MovPos == 0)
10744 player->is_moving = FALSE;
10745 player->is_digging = FALSE;
10746 player->is_collecting = FALSE;
10747 player->is_snapping = FALSE;
10748 player->is_pushing = FALSE;
10753 if (!options.network && game.centered_player_nr == -1 &&
10754 !AllPlayersInSight(player, new_jx, new_jy))
10755 return MP_NO_ACTION;
10757 if (!options.network && !AllPlayersInSight(player, new_jx, new_jy))
10758 return MP_NO_ACTION;
10761 #if !USE_FIXED_DONT_RUN_INTO
10762 element = MovingOrBlocked2ElementIfNotLeaving(new_jx, new_jy);
10764 /* (moved to DigField()) */
10765 if (player_can_move && DONT_RUN_INTO(element))
10767 if (element == EL_ACID && dx == 0 && dy == 1)
10769 SplashAcid(new_jx, new_jy);
10770 Feld[jx][jy] = EL_PLAYER_1;
10771 InitMovingField(jx, jy, MV_DOWN);
10772 Store[jx][jy] = EL_ACID;
10773 ContinueMoving(jx, jy);
10774 BuryPlayer(player);
10777 TestIfPlayerRunsIntoBadThing(jx, jy, player->MovDir);
10783 can_move = DigField(player, jx, jy, new_jx, new_jy, real_dx,real_dy, DF_DIG);
10784 if (can_move != MP_MOVING)
10787 /* check if DigField() has caused relocation of the player */
10788 if (player->jx != jx || player->jy != jy)
10789 return MP_NO_ACTION; /* <-- !!! CHECK THIS [-> MP_ACTION ?] !!! */
10791 StorePlayer[jx][jy] = 0;
10792 player->last_jx = jx;
10793 player->last_jy = jy;
10794 player->jx = new_jx;
10795 player->jy = new_jy;
10796 StorePlayer[new_jx][new_jy] = player->element_nr;
10798 if (player->move_delay_value_next != -1)
10800 player->move_delay_value = player->move_delay_value_next;
10801 player->move_delay_value_next = -1;
10805 (dx > 0 || dy > 0 ? -1 : 1) * (TILEX - TILEX / player->move_delay_value);
10807 player->step_counter++;
10809 PlayerVisit[jx][jy] = FrameCounter;
10811 #if USE_UFAST_PLAYER_EXIT_BUGFIX
10812 player->is_moving = TRUE;
10816 /* should better be called in MovePlayer(), but this breaks some tapes */
10817 ScrollPlayer(player, SCROLL_INIT);
10823 boolean MovePlayer(struct PlayerInfo *player, int dx, int dy)
10825 int jx = player->jx, jy = player->jy;
10826 int old_jx = jx, old_jy = jy;
10827 int moved = MP_NO_ACTION;
10829 if (!player->active)
10834 if (player->MovPos == 0)
10836 player->is_moving = FALSE;
10837 player->is_digging = FALSE;
10838 player->is_collecting = FALSE;
10839 player->is_snapping = FALSE;
10840 player->is_pushing = FALSE;
10846 if (player->move_delay > 0)
10849 player->move_delay = -1; /* set to "uninitialized" value */
10851 /* store if player is automatically moved to next field */
10852 player->is_auto_moving = (player->programmed_action != MV_NONE);
10854 /* remove the last programmed player action */
10855 player->programmed_action = 0;
10857 if (player->MovPos)
10859 /* should only happen if pre-1.2 tape recordings are played */
10860 /* this is only for backward compatibility */
10862 int original_move_delay_value = player->move_delay_value;
10865 printf("THIS SHOULD ONLY HAPPEN WITH PRE-1.2 LEVEL TAPES. [%ld]\n",
10869 /* scroll remaining steps with finest movement resolution */
10870 player->move_delay_value = MOVE_DELAY_NORMAL_SPEED;
10872 while (player->MovPos)
10874 ScrollPlayer(player, SCROLL_GO_ON);
10875 ScrollScreen(NULL, SCROLL_GO_ON);
10877 AdvanceFrameAndPlayerCounters(player->index_nr);
10883 player->move_delay_value = original_move_delay_value;
10886 player->is_active = FALSE;
10888 if (player->last_move_dir & MV_HORIZONTAL)
10890 if (!(moved |= MovePlayerOneStep(player, 0, dy, dx, dy)))
10891 moved |= MovePlayerOneStep(player, dx, 0, dx, dy);
10895 if (!(moved |= MovePlayerOneStep(player, dx, 0, dx, dy)))
10896 moved |= MovePlayerOneStep(player, 0, dy, dx, dy);
10899 #if USE_FIXED_BORDER_RUNNING_GFX
10900 if (!moved && !player->is_active)
10902 player->is_moving = FALSE;
10903 player->is_digging = FALSE;
10904 player->is_collecting = FALSE;
10905 player->is_snapping = FALSE;
10906 player->is_pushing = FALSE;
10914 if (moved & MP_MOVING && !ScreenMovPos &&
10915 (player->index_nr == game.centered_player_nr ||
10916 game.centered_player_nr == -1))
10918 if (moved & MP_MOVING && !ScreenMovPos &&
10919 (player == local_player || !options.network))
10922 int old_scroll_x = scroll_x, old_scroll_y = scroll_y;
10923 int offset = (setup.scroll_delay ? 3 : 0);
10925 if (!IN_VIS_FIELD(SCREENX(jx), SCREENY(jy)))
10927 /* actual player has left the screen -- scroll in that direction */
10928 if (jx != old_jx) /* player has moved horizontally */
10929 scroll_x += (jx - old_jx);
10930 else /* player has moved vertically */
10931 scroll_y += (jy - old_jy);
10935 if (jx != old_jx) /* player has moved horizontally */
10937 if ((player->MovDir == MV_LEFT && scroll_x > jx - MIDPOSX + offset) ||
10938 (player->MovDir == MV_RIGHT && scroll_x < jx - MIDPOSX - offset))
10939 scroll_x = jx-MIDPOSX + (scroll_x < jx-MIDPOSX ? -offset : +offset);
10941 /* don't scroll over playfield boundaries */
10942 if (scroll_x < SBX_Left || scroll_x > SBX_Right)
10943 scroll_x = (scroll_x < SBX_Left ? SBX_Left : SBX_Right);
10945 /* don't scroll more than one field at a time */
10946 scroll_x = old_scroll_x + SIGN(scroll_x - old_scroll_x);
10948 /* don't scroll against the player's moving direction */
10949 if ((player->MovDir == MV_LEFT && scroll_x > old_scroll_x) ||
10950 (player->MovDir == MV_RIGHT && scroll_x < old_scroll_x))
10951 scroll_x = old_scroll_x;
10953 else /* player has moved vertically */
10955 if ((player->MovDir == MV_UP && scroll_y > jy - MIDPOSY + offset) ||
10956 (player->MovDir == MV_DOWN && scroll_y < jy - MIDPOSY - offset))
10957 scroll_y = jy-MIDPOSY + (scroll_y < jy-MIDPOSY ? -offset : +offset);
10959 /* don't scroll over playfield boundaries */
10960 if (scroll_y < SBY_Upper || scroll_y > SBY_Lower)
10961 scroll_y = (scroll_y < SBY_Upper ? SBY_Upper : SBY_Lower);
10963 /* don't scroll more than one field at a time */
10964 scroll_y = old_scroll_y + SIGN(scroll_y - old_scroll_y);
10966 /* don't scroll against the player's moving direction */
10967 if ((player->MovDir == MV_UP && scroll_y > old_scroll_y) ||
10968 (player->MovDir == MV_DOWN && scroll_y < old_scroll_y))
10969 scroll_y = old_scroll_y;
10973 if (scroll_x != old_scroll_x || scroll_y != old_scroll_y)
10976 if (!options.network && game.centered_player_nr == -1 &&
10977 !AllPlayersInVisibleScreen())
10979 scroll_x = old_scroll_x;
10980 scroll_y = old_scroll_y;
10984 if (!options.network && !AllPlayersInVisibleScreen())
10986 scroll_x = old_scroll_x;
10987 scroll_y = old_scroll_y;
10992 ScrollScreen(player, SCROLL_INIT);
10993 ScrollLevel(old_scroll_x - scroll_x, old_scroll_y - scroll_y);
10998 player->StepFrame = 0;
11000 if (moved & MP_MOVING)
11002 if (old_jx != jx && old_jy == jy)
11003 player->MovDir = (old_jx < jx ? MV_RIGHT : MV_LEFT);
11004 else if (old_jx == jx && old_jy != jy)
11005 player->MovDir = (old_jy < jy ? MV_DOWN : MV_UP);
11007 DrawLevelField(jx, jy); /* for "crumbled sand" */
11009 player->last_move_dir = player->MovDir;
11010 player->is_moving = TRUE;
11011 player->is_snapping = FALSE;
11012 player->is_switching = FALSE;
11013 player->is_dropping = FALSE;
11014 player->is_dropping_pressed = FALSE;
11015 player->drop_pressed_delay = 0;
11018 /* should better be called here than above, but this breaks some tapes */
11019 ScrollPlayer(player, SCROLL_INIT);
11024 CheckGravityMovementWhenNotMoving(player);
11026 player->is_moving = FALSE;
11028 /* at this point, the player is allowed to move, but cannot move right now
11029 (e.g. because of something blocking the way) -- ensure that the player
11030 is also allowed to move in the next frame (in old versions before 3.1.1,
11031 the player was forced to wait again for eight frames before next try) */
11033 if (game.engine_version >= VERSION_IDENT(3,1,1,0))
11034 player->move_delay = 0; /* allow direct movement in the next frame */
11037 if (player->move_delay == -1) /* not yet initialized by DigField() */
11038 player->move_delay = player->move_delay_value;
11040 if (game.engine_version < VERSION_IDENT(3,0,7,0))
11042 TestIfPlayerTouchesBadThing(jx, jy);
11043 TestIfPlayerTouchesCustomElement(jx, jy);
11046 if (!player->active)
11047 RemovePlayer(player);
11052 void ScrollPlayer(struct PlayerInfo *player, int mode)
11054 int jx = player->jx, jy = player->jy;
11055 int last_jx = player->last_jx, last_jy = player->last_jy;
11056 int move_stepsize = TILEX / player->move_delay_value;
11058 #if USE_NEW_PLAYER_SPEED
11059 if (!player->active)
11062 if (player->MovPos == 0 && mode == SCROLL_GO_ON) /* player not moving */
11065 if (!player->active || player->MovPos == 0)
11069 if (mode == SCROLL_INIT)
11071 player->actual_frame_counter = FrameCounter;
11072 player->GfxPos = move_stepsize * (player->MovPos / move_stepsize);
11074 if ((player->block_last_field || player->block_delay_adjustment > 0) &&
11075 Feld[last_jx][last_jy] == EL_EMPTY)
11077 int last_field_block_delay = 0; /* start with no blocking at all */
11078 int block_delay_adjustment = player->block_delay_adjustment;
11080 /* if player blocks last field, add delay for exactly one move */
11081 if (player->block_last_field)
11083 last_field_block_delay += player->move_delay_value;
11085 /* when blocking enabled, prevent moving up despite gravity */
11086 #if USE_PLAYER_GRAVITY
11087 if (player->gravity && player->MovDir == MV_UP)
11088 block_delay_adjustment = -1;
11090 if (game.gravity && player->MovDir == MV_UP)
11091 block_delay_adjustment = -1;
11095 /* add block delay adjustment (also possible when not blocking) */
11096 last_field_block_delay += block_delay_adjustment;
11098 Feld[last_jx][last_jy] = EL_PLAYER_IS_LEAVING;
11099 MovDelay[last_jx][last_jy] = last_field_block_delay + 1;
11102 #if USE_NEW_PLAYER_SPEED
11103 if (player->MovPos != 0) /* player has not yet reached destination */
11109 else if (!FrameReached(&player->actual_frame_counter, 1))
11112 #if USE_NEW_PLAYER_SPEED
11113 if (player->MovPos != 0)
11115 player->MovPos += (player->MovPos > 0 ? -1 : 1) * move_stepsize;
11116 player->GfxPos = move_stepsize * (player->MovPos / move_stepsize);
11118 /* before DrawPlayer() to draw correct player graphic for this case */
11119 if (player->MovPos == 0)
11120 CheckGravityMovement(player);
11123 player->MovPos += (player->MovPos > 0 ? -1 : 1) * move_stepsize;
11124 player->GfxPos = move_stepsize * (player->MovPos / move_stepsize);
11126 /* before DrawPlayer() to draw correct player graphic for this case */
11127 if (player->MovPos == 0)
11128 CheckGravityMovement(player);
11131 if (player->MovPos == 0) /* player reached destination field */
11133 if (player->move_delay_reset_counter > 0)
11135 player->move_delay_reset_counter--;
11137 if (player->move_delay_reset_counter == 0)
11139 /* continue with normal speed after quickly moving through gate */
11140 HALVE_PLAYER_SPEED(player);
11142 /* be able to make the next move without delay */
11143 player->move_delay = 0;
11147 player->last_jx = jx;
11148 player->last_jy = jy;
11150 if (Feld[jx][jy] == EL_EXIT_OPEN ||
11151 Feld[jx][jy] == EL_EM_EXIT_OPEN ||
11152 Feld[jx][jy] == EL_STEEL_EXIT_OPEN ||
11153 Feld[jx][jy] == EL_EM_STEEL_EXIT_OPEN ||
11154 Feld[jx][jy] == EL_SP_EXIT_OPEN ||
11155 Feld[jx][jy] == EL_SP_EXIT_OPENING) /* <-- special case */
11157 DrawPlayer(player); /* needed here only to cleanup last field */
11158 RemovePlayer(player);
11160 if (local_player->friends_still_needed == 0 ||
11161 IS_SP_ELEMENT(Feld[jx][jy]))
11162 PlayerWins(player);
11165 /* this breaks one level: "machine", level 000 */
11167 int move_direction = player->MovDir;
11168 int enter_side = MV_DIR_OPPOSITE(move_direction);
11169 int leave_side = move_direction;
11170 int old_jx = last_jx;
11171 int old_jy = last_jy;
11172 int old_element = Feld[old_jx][old_jy];
11173 int new_element = Feld[jx][jy];
11175 if (IS_CUSTOM_ELEMENT(old_element))
11176 CheckElementChangeByPlayer(old_jx, old_jy, old_element,
11178 player->index_bit, leave_side);
11180 CheckTriggeredElementChangeByPlayer(old_jx, old_jy, old_element,
11181 CE_PLAYER_LEAVES_X,
11182 player->index_bit, leave_side);
11184 if (IS_CUSTOM_ELEMENT(new_element))
11185 CheckElementChangeByPlayer(jx, jy, new_element, CE_ENTERED_BY_PLAYER,
11186 player->index_bit, enter_side);
11188 CheckTriggeredElementChangeByPlayer(jx, jy, new_element,
11189 CE_PLAYER_ENTERS_X,
11190 player->index_bit, enter_side);
11192 CheckTriggeredElementChangeBySide(jx, jy, player->element_nr,
11193 CE_MOVE_OF_X, move_direction);
11196 if (game.engine_version >= VERSION_IDENT(3,0,7,0))
11198 TestIfPlayerTouchesBadThing(jx, jy);
11199 TestIfPlayerTouchesCustomElement(jx, jy);
11201 /* needed because pushed element has not yet reached its destination,
11202 so it would trigger a change event at its previous field location */
11203 if (!player->is_pushing)
11204 TestIfElementTouchesCustomElement(jx, jy); /* for empty space */
11206 if (!player->active)
11207 RemovePlayer(player);
11210 if (!local_player->LevelSolved && level.use_step_counter)
11220 if (TimeLeft <= 10 && setup.time_limit)
11221 PlaySound(SND_GAME_RUNNING_OUT_OF_TIME);
11223 DrawGameValue_Time(TimeLeft);
11225 if (!TimeLeft && setup.time_limit)
11226 for (i = 0; i < MAX_PLAYERS; i++)
11227 KillPlayer(&stored_player[i]);
11229 else if (level.time == 0 && !AllPlayersGone) /* level w/o time limit */
11230 DrawGameValue_Time(TimePlayed);
11233 if (tape.single_step && tape.recording && !tape.pausing &&
11234 !player->programmed_action)
11235 TapeTogglePause(TAPE_TOGGLE_AUTOMATIC);
11239 void ScrollScreen(struct PlayerInfo *player, int mode)
11241 static unsigned long screen_frame_counter = 0;
11243 if (mode == SCROLL_INIT)
11245 /* set scrolling step size according to actual player's moving speed */
11246 ScrollStepSize = TILEX / player->move_delay_value;
11248 screen_frame_counter = FrameCounter;
11249 ScreenMovDir = player->MovDir;
11250 ScreenMovPos = player->MovPos;
11251 ScreenGfxPos = ScrollStepSize * (ScreenMovPos / ScrollStepSize);
11254 else if (!FrameReached(&screen_frame_counter, 1))
11259 ScreenMovPos += (ScreenMovPos > 0 ? -1 : 1) * ScrollStepSize;
11260 ScreenGfxPos = ScrollStepSize * (ScreenMovPos / ScrollStepSize);
11261 redraw_mask |= REDRAW_FIELD;
11264 ScreenMovDir = MV_NONE;
11267 void TestIfPlayerTouchesCustomElement(int x, int y)
11269 static int xy[4][2] =
11276 static int trigger_sides[4][2] =
11278 /* center side border side */
11279 { CH_SIDE_TOP, CH_SIDE_BOTTOM }, /* check top */
11280 { CH_SIDE_LEFT, CH_SIDE_RIGHT }, /* check left */
11281 { CH_SIDE_RIGHT, CH_SIDE_LEFT }, /* check right */
11282 { CH_SIDE_BOTTOM, CH_SIDE_TOP } /* check bottom */
11284 static int touch_dir[4] =
11286 MV_LEFT | MV_RIGHT,
11291 int center_element = Feld[x][y]; /* should always be non-moving! */
11294 for (i = 0; i < NUM_DIRECTIONS; i++)
11296 int xx = x + xy[i][0];
11297 int yy = y + xy[i][1];
11298 int center_side = trigger_sides[i][0];
11299 int border_side = trigger_sides[i][1];
11300 int border_element;
11302 if (!IN_LEV_FIELD(xx, yy))
11305 if (IS_PLAYER(x, y))
11307 struct PlayerInfo *player = PLAYERINFO(x, y);
11309 if (game.engine_version < VERSION_IDENT(3,0,7,0))
11310 border_element = Feld[xx][yy]; /* may be moving! */
11311 else if (!IS_MOVING(xx, yy) && !IS_BLOCKED(xx, yy))
11312 border_element = Feld[xx][yy];
11313 else if (MovDir[xx][yy] & touch_dir[i]) /* elements are touching */
11314 border_element = MovingOrBlocked2Element(xx, yy);
11316 continue; /* center and border element do not touch */
11318 CheckElementChangeByPlayer(xx, yy, border_element, CE_TOUCHED_BY_PLAYER,
11319 player->index_bit, border_side);
11320 CheckTriggeredElementChangeByPlayer(xx, yy, border_element,
11321 CE_PLAYER_TOUCHES_X,
11322 player->index_bit, border_side);
11324 else if (IS_PLAYER(xx, yy))
11326 struct PlayerInfo *player = PLAYERINFO(xx, yy);
11328 if (game.engine_version >= VERSION_IDENT(3,0,7,0))
11330 if (player->MovPos != 0 && !(player->MovDir & touch_dir[i]))
11331 continue; /* center and border element do not touch */
11334 CheckElementChangeByPlayer(x, y, center_element, CE_TOUCHED_BY_PLAYER,
11335 player->index_bit, center_side);
11336 CheckTriggeredElementChangeByPlayer(x, y, center_element,
11337 CE_PLAYER_TOUCHES_X,
11338 player->index_bit, center_side);
11344 #if USE_ELEMENT_TOUCHING_BUGFIX
11346 void TestIfElementTouchesCustomElement(int x, int y)
11348 static int xy[4][2] =
11355 static int trigger_sides[4][2] =
11357 /* center side border side */
11358 { CH_SIDE_TOP, CH_SIDE_BOTTOM }, /* check top */
11359 { CH_SIDE_LEFT, CH_SIDE_RIGHT }, /* check left */
11360 { CH_SIDE_RIGHT, CH_SIDE_LEFT }, /* check right */
11361 { CH_SIDE_BOTTOM, CH_SIDE_TOP } /* check bottom */
11363 static int touch_dir[4] =
11365 MV_LEFT | MV_RIGHT,
11370 boolean change_center_element = FALSE;
11371 int center_element = Feld[x][y]; /* should always be non-moving! */
11372 int border_element_old[NUM_DIRECTIONS];
11375 for (i = 0; i < NUM_DIRECTIONS; i++)
11377 int xx = x + xy[i][0];
11378 int yy = y + xy[i][1];
11379 int border_element;
11381 border_element_old[i] = -1;
11383 if (!IN_LEV_FIELD(xx, yy))
11386 if (game.engine_version < VERSION_IDENT(3,0,7,0))
11387 border_element = Feld[xx][yy]; /* may be moving! */
11388 else if (!IS_MOVING(xx, yy) && !IS_BLOCKED(xx, yy))
11389 border_element = Feld[xx][yy];
11390 else if (MovDir[xx][yy] & touch_dir[i]) /* elements are touching */
11391 border_element = MovingOrBlocked2Element(xx, yy);
11393 continue; /* center and border element do not touch */
11395 border_element_old[i] = border_element;
11398 for (i = 0; i < NUM_DIRECTIONS; i++)
11400 int xx = x + xy[i][0];
11401 int yy = y + xy[i][1];
11402 int center_side = trigger_sides[i][0];
11403 int border_element = border_element_old[i];
11405 if (border_element == -1)
11408 /* check for change of border element */
11409 CheckElementChangeBySide(xx, yy, border_element, center_element,
11410 CE_TOUCHING_X, center_side);
11413 for (i = 0; i < NUM_DIRECTIONS; i++)
11415 int border_side = trigger_sides[i][1];
11416 int border_element = border_element_old[i];
11418 if (border_element == -1)
11421 /* check for change of center element (but change it only once) */
11422 if (!change_center_element)
11423 change_center_element =
11424 CheckElementChangeBySide(x, y, center_element, border_element,
11425 CE_TOUCHING_X, border_side);
11431 void TestIfElementTouchesCustomElement_OLD(int x, int y)
11433 static int xy[4][2] =
11440 static int trigger_sides[4][2] =
11442 /* center side border side */
11443 { CH_SIDE_TOP, CH_SIDE_BOTTOM }, /* check top */
11444 { CH_SIDE_LEFT, CH_SIDE_RIGHT }, /* check left */
11445 { CH_SIDE_RIGHT, CH_SIDE_LEFT }, /* check right */
11446 { CH_SIDE_BOTTOM, CH_SIDE_TOP } /* check bottom */
11448 static int touch_dir[4] =
11450 MV_LEFT | MV_RIGHT,
11455 boolean change_center_element = FALSE;
11456 int center_element = Feld[x][y]; /* should always be non-moving! */
11459 for (i = 0; i < NUM_DIRECTIONS; i++)
11461 int xx = x + xy[i][0];
11462 int yy = y + xy[i][1];
11463 int center_side = trigger_sides[i][0];
11464 int border_side = trigger_sides[i][1];
11465 int border_element;
11467 if (!IN_LEV_FIELD(xx, yy))
11470 if (game.engine_version < VERSION_IDENT(3,0,7,0))
11471 border_element = Feld[xx][yy]; /* may be moving! */
11472 else if (!IS_MOVING(xx, yy) && !IS_BLOCKED(xx, yy))
11473 border_element = Feld[xx][yy];
11474 else if (MovDir[xx][yy] & touch_dir[i]) /* elements are touching */
11475 border_element = MovingOrBlocked2Element(xx, yy);
11477 continue; /* center and border element do not touch */
11479 /* check for change of center element (but change it only once) */
11480 if (!change_center_element)
11481 change_center_element =
11482 CheckElementChangeBySide(x, y, center_element, border_element,
11483 CE_TOUCHING_X, border_side);
11485 /* check for change of border element */
11486 CheckElementChangeBySide(xx, yy, border_element, center_element,
11487 CE_TOUCHING_X, center_side);
11493 void TestIfElementHitsCustomElement(int x, int y, int direction)
11495 int dx = (direction == MV_LEFT ? -1 : direction == MV_RIGHT ? +1 : 0);
11496 int dy = (direction == MV_UP ? -1 : direction == MV_DOWN ? +1 : 0);
11497 int hitx = x + dx, hity = y + dy;
11498 int hitting_element = Feld[x][y];
11499 int touched_element;
11501 if (IN_LEV_FIELD(hitx, hity) && IS_FREE(hitx, hity))
11504 touched_element = (IN_LEV_FIELD(hitx, hity) ?
11505 MovingOrBlocked2Element(hitx, hity) : EL_STEELWALL);
11507 if (IN_LEV_FIELD(hitx, hity))
11509 int opposite_direction = MV_DIR_OPPOSITE(direction);
11510 int hitting_side = direction;
11511 int touched_side = opposite_direction;
11512 boolean object_hit = (!IS_MOVING(hitx, hity) ||
11513 MovDir[hitx][hity] != direction ||
11514 ABS(MovPos[hitx][hity]) <= TILEY / 2);
11520 CheckElementChangeBySide(x, y, hitting_element, touched_element,
11521 CE_HITTING_X, touched_side);
11523 CheckElementChangeBySide(hitx, hity, touched_element,
11524 hitting_element, CE_HIT_BY_X, hitting_side);
11526 CheckElementChangeBySide(hitx, hity, touched_element, hitting_element,
11527 CE_HIT_BY_SOMETHING, opposite_direction);
11531 /* "hitting something" is also true when hitting the playfield border */
11532 CheckElementChangeBySide(x, y, hitting_element, touched_element,
11533 CE_HITTING_SOMETHING, direction);
11537 void TestIfElementSmashesCustomElement(int x, int y, int direction)
11539 int dx = (direction == MV_LEFT ? -1 : direction == MV_RIGHT ? +1 : 0);
11540 int dy = (direction == MV_UP ? -1 : direction == MV_DOWN ? +1 : 0);
11541 int hitx = x + dx, hity = y + dy;
11542 int hitting_element = Feld[x][y];
11543 int touched_element;
11545 boolean object_hit = (IN_LEV_FIELD(hitx, hity) &&
11546 !IS_FREE(hitx, hity) &&
11547 (!IS_MOVING(hitx, hity) ||
11548 MovDir[hitx][hity] != direction ||
11549 ABS(MovPos[hitx][hity]) <= TILEY / 2));
11552 if (IN_LEV_FIELD(hitx, hity) && IS_FREE(hitx, hity))
11556 if (IN_LEV_FIELD(hitx, hity) && !object_hit)
11560 touched_element = (IN_LEV_FIELD(hitx, hity) ?
11561 MovingOrBlocked2Element(hitx, hity) : EL_STEELWALL);
11563 CheckElementChangeBySide(x, y, hitting_element, touched_element,
11564 EP_CAN_SMASH_EVERYTHING, direction);
11566 if (IN_LEV_FIELD(hitx, hity))
11568 int opposite_direction = MV_DIR_OPPOSITE(direction);
11569 int hitting_side = direction;
11570 int touched_side = opposite_direction;
11572 int touched_element = MovingOrBlocked2Element(hitx, hity);
11575 boolean object_hit = (!IS_MOVING(hitx, hity) ||
11576 MovDir[hitx][hity] != direction ||
11577 ABS(MovPos[hitx][hity]) <= TILEY / 2);
11586 CheckElementChangeBySide(hitx, hity, touched_element, hitting_element,
11587 CE_SMASHED_BY_SOMETHING, opposite_direction);
11589 CheckElementChangeBySide(x, y, hitting_element, touched_element,
11590 CE_OTHER_IS_SMASHING, touched_side);
11592 CheckElementChangeBySide(hitx, hity, touched_element, hitting_element,
11593 CE_OTHER_GETS_SMASHED, hitting_side);
11599 void TestIfGoodThingHitsBadThing(int good_x, int good_y, int good_move_dir)
11601 int i, kill_x = -1, kill_y = -1;
11603 int bad_element = -1;
11604 static int test_xy[4][2] =
11611 static int test_dir[4] =
11619 for (i = 0; i < NUM_DIRECTIONS; i++)
11621 int test_x, test_y, test_move_dir, test_element;
11623 test_x = good_x + test_xy[i][0];
11624 test_y = good_y + test_xy[i][1];
11626 if (!IN_LEV_FIELD(test_x, test_y))
11630 (IS_MOVING(test_x, test_y) ? MovDir[test_x][test_y] : MV_NONE);
11632 test_element = MovingOrBlocked2ElementIfNotLeaving(test_x, test_y);
11634 /* 1st case: good thing is moving towards DONT_RUN_INTO style bad thing;
11635 2nd case: DONT_TOUCH style bad thing does not move away from good thing
11637 if ((DONT_RUN_INTO(test_element) && good_move_dir == test_dir[i]) ||
11638 (DONT_TOUCH(test_element) && test_move_dir != test_dir[i]))
11642 bad_element = test_element;
11648 if (kill_x != -1 || kill_y != -1)
11650 if (IS_PLAYER(good_x, good_y))
11652 struct PlayerInfo *player = PLAYERINFO(good_x, good_y);
11654 if (player->shield_deadly_time_left > 0 &&
11655 !IS_INDESTRUCTIBLE(bad_element))
11656 Bang(kill_x, kill_y);
11657 else if (!PLAYER_ENEMY_PROTECTED(good_x, good_y))
11658 KillPlayer(player);
11661 Bang(good_x, good_y);
11665 void TestIfBadThingHitsGoodThing(int bad_x, int bad_y, int bad_move_dir)
11667 int i, kill_x = -1, kill_y = -1;
11668 int bad_element = Feld[bad_x][bad_y];
11669 static int test_xy[4][2] =
11676 static int touch_dir[4] =
11678 MV_LEFT | MV_RIGHT,
11683 static int test_dir[4] =
11691 if (bad_element == EL_EXPLOSION) /* skip just exploding bad things */
11694 for (i = 0; i < NUM_DIRECTIONS; i++)
11696 int test_x, test_y, test_move_dir, test_element;
11698 test_x = bad_x + test_xy[i][0];
11699 test_y = bad_y + test_xy[i][1];
11700 if (!IN_LEV_FIELD(test_x, test_y))
11704 (IS_MOVING(test_x, test_y) ? MovDir[test_x][test_y] : MV_NONE);
11706 test_element = Feld[test_x][test_y];
11708 /* 1st case: good thing is moving towards DONT_RUN_INTO style bad thing;
11709 2nd case: DONT_TOUCH style bad thing does not move away from good thing
11711 if ((DONT_RUN_INTO(bad_element) && bad_move_dir == test_dir[i]) ||
11712 (DONT_TOUCH(bad_element) && test_move_dir != test_dir[i]))
11714 /* good thing is player or penguin that does not move away */
11715 if (IS_PLAYER(test_x, test_y))
11717 struct PlayerInfo *player = PLAYERINFO(test_x, test_y);
11719 if (bad_element == EL_ROBOT && player->is_moving)
11720 continue; /* robot does not kill player if he is moving */
11722 if (game.engine_version >= VERSION_IDENT(3,0,7,0))
11724 if (player->MovPos != 0 && !(player->MovDir & touch_dir[i]))
11725 continue; /* center and border element do not touch */
11732 else if (test_element == EL_PENGUIN)
11741 if (kill_x != -1 || kill_y != -1)
11743 if (IS_PLAYER(kill_x, kill_y))
11745 struct PlayerInfo *player = PLAYERINFO(kill_x, kill_y);
11747 if (player->shield_deadly_time_left > 0 &&
11748 !IS_INDESTRUCTIBLE(bad_element))
11749 Bang(bad_x, bad_y);
11750 else if (!PLAYER_ENEMY_PROTECTED(kill_x, kill_y))
11751 KillPlayer(player);
11754 Bang(kill_x, kill_y);
11758 void TestIfPlayerTouchesBadThing(int x, int y)
11760 TestIfGoodThingHitsBadThing(x, y, MV_NONE);
11763 void TestIfPlayerRunsIntoBadThing(int x, int y, int move_dir)
11765 TestIfGoodThingHitsBadThing(x, y, move_dir);
11768 void TestIfBadThingTouchesPlayer(int x, int y)
11770 TestIfBadThingHitsGoodThing(x, y, MV_NONE);
11773 void TestIfBadThingRunsIntoPlayer(int x, int y, int move_dir)
11775 TestIfBadThingHitsGoodThing(x, y, move_dir);
11778 void TestIfFriendTouchesBadThing(int x, int y)
11780 TestIfGoodThingHitsBadThing(x, y, MV_NONE);
11783 void TestIfBadThingTouchesFriend(int x, int y)
11785 TestIfBadThingHitsGoodThing(x, y, MV_NONE);
11788 void TestIfBadThingTouchesOtherBadThing(int bad_x, int bad_y)
11790 int i, kill_x = bad_x, kill_y = bad_y;
11791 static int xy[4][2] =
11799 for (i = 0; i < NUM_DIRECTIONS; i++)
11803 x = bad_x + xy[i][0];
11804 y = bad_y + xy[i][1];
11805 if (!IN_LEV_FIELD(x, y))
11808 element = Feld[x][y];
11809 if (IS_AMOEBOID(element) || element == EL_GAME_OF_LIFE ||
11810 element == EL_AMOEBA_GROWING || element == EL_AMOEBA_DROP)
11818 if (kill_x != bad_x || kill_y != bad_y)
11819 Bang(bad_x, bad_y);
11822 void KillPlayer(struct PlayerInfo *player)
11824 int jx = player->jx, jy = player->jy;
11826 if (!player->active)
11829 /* the following code was introduced to prevent an infinite loop when calling
11831 -> CheckTriggeredElementChangeExt()
11832 -> ExecuteCustomElementAction()
11834 -> (infinitely repeating the above sequence of function calls)
11835 which occurs when killing the player while having a CE with the setting
11836 "kill player X when explosion of <player X>"; the solution using a new
11837 field "player->killed" was chosen for backwards compatibility, although
11838 clever use of the fields "player->active" etc. would probably also work */
11840 if (player->killed)
11844 player->killed = TRUE;
11846 /* remove accessible field at the player's position */
11847 Feld[jx][jy] = EL_EMPTY;
11849 /* deactivate shield (else Bang()/Explode() would not work right) */
11850 player->shield_normal_time_left = 0;
11851 player->shield_deadly_time_left = 0;
11854 BuryPlayer(player);
11857 static void KillPlayerUnlessEnemyProtected(int x, int y)
11859 if (!PLAYER_ENEMY_PROTECTED(x, y))
11860 KillPlayer(PLAYERINFO(x, y));
11863 static void KillPlayerUnlessExplosionProtected(int x, int y)
11865 if (!PLAYER_EXPLOSION_PROTECTED(x, y))
11866 KillPlayer(PLAYERINFO(x, y));
11869 void BuryPlayer(struct PlayerInfo *player)
11871 int jx = player->jx, jy = player->jy;
11873 if (!player->active)
11876 PlayLevelSoundElementAction(jx, jy, player->artwork_element, ACTION_DYING);
11877 PlayLevelSound(jx, jy, SND_GAME_LOSING);
11879 player->GameOver = TRUE;
11880 RemovePlayer(player);
11883 void RemovePlayer(struct PlayerInfo *player)
11885 int jx = player->jx, jy = player->jy;
11886 int i, found = FALSE;
11888 player->present = FALSE;
11889 player->active = FALSE;
11891 if (!ExplodeField[jx][jy])
11892 StorePlayer[jx][jy] = 0;
11894 if (player->is_moving)
11895 DrawLevelField(player->last_jx, player->last_jy);
11897 for (i = 0; i < MAX_PLAYERS; i++)
11898 if (stored_player[i].active)
11902 AllPlayersGone = TRUE;
11908 #if USE_NEW_SNAP_DELAY
11909 static void setFieldForSnapping(int x, int y, int element, int direction)
11911 struct ElementInfo *ei = &element_info[element];
11912 int direction_bit = MV_DIR_TO_BIT(direction);
11913 int graphic_snapping = ei->direction_graphic[ACTION_SNAPPING][direction_bit];
11914 int action = (graphic_snapping != IMG_EMPTY_SPACE ? ACTION_SNAPPING :
11915 IS_DIGGABLE(element) ? ACTION_DIGGING : ACTION_COLLECTING);
11917 Feld[x][y] = EL_ELEMENT_SNAPPING;
11918 MovDelay[x][y] = MOVE_DELAY_NORMAL_SPEED + 1 - 1;
11920 ResetGfxAnimation(x, y);
11922 GfxElement[x][y] = element;
11923 GfxAction[x][y] = action;
11924 GfxDir[x][y] = direction;
11925 GfxFrame[x][y] = -1;
11930 =============================================================================
11931 checkDiagonalPushing()
11932 -----------------------------------------------------------------------------
11933 check if diagonal input device direction results in pushing of object
11934 (by checking if the alternative direction is walkable, diggable, ...)
11935 =============================================================================
11938 static boolean checkDiagonalPushing(struct PlayerInfo *player,
11939 int x, int y, int real_dx, int real_dy)
11941 int jx, jy, dx, dy, xx, yy;
11943 if (real_dx == 0 || real_dy == 0) /* no diagonal direction => push */
11946 /* diagonal direction: check alternative direction */
11951 xx = jx + (dx == 0 ? real_dx : 0);
11952 yy = jy + (dy == 0 ? real_dy : 0);
11954 return (!IN_LEV_FIELD(xx, yy) || IS_SOLID_FOR_PUSHING(Feld[xx][yy]));
11958 =============================================================================
11960 -----------------------------------------------------------------------------
11961 x, y: field next to player (non-diagonal) to try to dig to
11962 real_dx, real_dy: direction as read from input device (can be diagonal)
11963 =============================================================================
11966 int DigField(struct PlayerInfo *player,
11967 int oldx, int oldy, int x, int y,
11968 int real_dx, int real_dy, int mode)
11970 boolean is_player = (IS_PLAYER(oldx, oldy) || mode != DF_DIG);
11971 boolean player_was_pushing = player->is_pushing;
11972 boolean player_can_move = (!player->cannot_move && mode != DF_SNAP);
11973 boolean player_can_move_or_snap = (!player->cannot_move || mode == DF_SNAP);
11974 int jx = oldx, jy = oldy;
11975 int dx = x - jx, dy = y - jy;
11976 int nextx = x + dx, nexty = y + dy;
11977 int move_direction = (dx == -1 ? MV_LEFT :
11978 dx == +1 ? MV_RIGHT :
11980 dy == +1 ? MV_DOWN : MV_NONE);
11981 int opposite_direction = MV_DIR_OPPOSITE(move_direction);
11982 int dig_side = MV_DIR_OPPOSITE(move_direction);
11983 int old_element = Feld[jx][jy];
11984 #if USE_FIXED_DONT_RUN_INTO
11985 int element = MovingOrBlocked2ElementIfNotLeaving(x, y);
11991 if (is_player) /* function can also be called by EL_PENGUIN */
11993 if (player->MovPos == 0)
11995 player->is_digging = FALSE;
11996 player->is_collecting = FALSE;
11999 if (player->MovPos == 0) /* last pushing move finished */
12000 player->is_pushing = FALSE;
12002 if (mode == DF_NO_PUSH) /* player just stopped pushing */
12004 player->is_switching = FALSE;
12005 player->push_delay = -1;
12007 return MP_NO_ACTION;
12011 #if !USE_FIXED_DONT_RUN_INTO
12012 if (IS_MOVING(x, y) || IS_PLAYER(x, y))
12013 return MP_NO_ACTION;
12016 if (IS_TUBE(Back[jx][jy]) && game.engine_version >= VERSION_IDENT(2,2,0,0))
12017 old_element = Back[jx][jy];
12019 /* in case of element dropped at player position, check background */
12020 else if (Back[jx][jy] != EL_EMPTY &&
12021 game.engine_version >= VERSION_IDENT(2,2,0,0))
12022 old_element = Back[jx][jy];
12024 if (IS_WALKABLE(old_element) && !ACCESS_FROM(old_element, move_direction))
12025 return MP_NO_ACTION; /* field has no opening in this direction */
12027 if (IS_PASSABLE(old_element) && !ACCESS_FROM(old_element,opposite_direction))
12028 return MP_NO_ACTION; /* field has no opening in this direction */
12030 #if USE_FIXED_DONT_RUN_INTO
12031 if (player_can_move && element == EL_ACID && move_direction == MV_DOWN)
12035 Feld[jx][jy] = player->artwork_element;
12036 InitMovingField(jx, jy, MV_DOWN);
12037 Store[jx][jy] = EL_ACID;
12038 ContinueMoving(jx, jy);
12039 BuryPlayer(player);
12041 return MP_DONT_RUN_INTO;
12045 #if USE_FIXED_DONT_RUN_INTO
12046 if (player_can_move && DONT_RUN_INTO(element))
12048 TestIfPlayerRunsIntoBadThing(jx, jy, player->MovDir);
12050 return MP_DONT_RUN_INTO;
12054 #if USE_FIXED_DONT_RUN_INTO
12055 if (IS_MOVING(x, y) || IS_PLAYER(x, y))
12056 return MP_NO_ACTION;
12059 #if !USE_FIXED_DONT_RUN_INTO
12060 element = Feld[x][y];
12063 collect_count = element_info[element].collect_count_initial;
12065 if (!is_player && !IS_COLLECTIBLE(element)) /* penguin cannot collect it */
12066 return MP_NO_ACTION;
12068 if (game.engine_version < VERSION_IDENT(2,2,0,0))
12069 player_can_move = player_can_move_or_snap;
12071 if (mode == DF_SNAP && !IS_SNAPPABLE(element) &&
12072 game.engine_version >= VERSION_IDENT(2,2,0,0))
12074 CheckElementChangeByPlayer(x, y, element, CE_SNAPPED_BY_PLAYER,
12075 player->index_bit, dig_side);
12076 CheckTriggeredElementChangeByPlayer(x, y, element, CE_PLAYER_SNAPS_X,
12077 player->index_bit, dig_side);
12079 if (element == EL_DC_LANDMINE)
12082 if (Feld[x][y] != element) /* field changed by snapping */
12085 return MP_NO_ACTION;
12088 #if USE_PLAYER_GRAVITY
12089 if (player->gravity && is_player && !player->is_auto_moving &&
12090 canFallDown(player) && move_direction != MV_DOWN &&
12091 !canMoveToValidFieldWithGravity(jx, jy, move_direction))
12092 return MP_NO_ACTION; /* player cannot walk here due to gravity */
12094 if (game.gravity && is_player && !player->is_auto_moving &&
12095 canFallDown(player) && move_direction != MV_DOWN &&
12096 !canMoveToValidFieldWithGravity(jx, jy, move_direction))
12097 return MP_NO_ACTION; /* player cannot walk here due to gravity */
12100 if (player_can_move &&
12101 IS_WALKABLE(element) && ACCESS_FROM(element, opposite_direction))
12103 int sound_element = SND_ELEMENT(element);
12104 int sound_action = ACTION_WALKING;
12106 if (IS_RND_GATE(element))
12108 if (!player->key[RND_GATE_NR(element)])
12109 return MP_NO_ACTION;
12111 else if (IS_RND_GATE_GRAY(element))
12113 if (!player->key[RND_GATE_GRAY_NR(element)])
12114 return MP_NO_ACTION;
12116 else if (IS_RND_GATE_GRAY_ACTIVE(element))
12118 if (!player->key[RND_GATE_GRAY_ACTIVE_NR(element)])
12119 return MP_NO_ACTION;
12121 else if (element == EL_EXIT_OPEN ||
12122 element == EL_EM_EXIT_OPEN ||
12123 element == EL_STEEL_EXIT_OPEN ||
12124 element == EL_EM_STEEL_EXIT_OPEN ||
12125 element == EL_SP_EXIT_OPEN ||
12126 element == EL_SP_EXIT_OPENING)
12128 sound_action = ACTION_PASSING; /* player is passing exit */
12130 else if (element == EL_EMPTY)
12132 sound_action = ACTION_MOVING; /* nothing to walk on */
12135 /* play sound from background or player, whatever is available */
12136 if (element_info[sound_element].sound[sound_action] != SND_UNDEFINED)
12137 PlayLevelSoundElementAction(x, y, sound_element, sound_action);
12139 PlayLevelSoundElementAction(x, y, player->artwork_element, sound_action);
12141 else if (player_can_move &&
12142 IS_PASSABLE(element) && canPassField(x, y, move_direction))
12144 if (!ACCESS_FROM(element, opposite_direction))
12145 return MP_NO_ACTION; /* field not accessible from this direction */
12147 if (CAN_MOVE(element)) /* only fixed elements can be passed! */
12148 return MP_NO_ACTION;
12150 if (IS_EM_GATE(element))
12152 if (!player->key[EM_GATE_NR(element)])
12153 return MP_NO_ACTION;
12155 else if (IS_EM_GATE_GRAY(element))
12157 if (!player->key[EM_GATE_GRAY_NR(element)])
12158 return MP_NO_ACTION;
12160 else if (IS_EM_GATE_GRAY_ACTIVE(element))
12162 if (!player->key[EM_GATE_GRAY_ACTIVE_NR(element)])
12163 return MP_NO_ACTION;
12165 else if (IS_EMC_GATE(element))
12167 if (!player->key[EMC_GATE_NR(element)])
12168 return MP_NO_ACTION;
12170 else if (IS_EMC_GATE_GRAY(element))
12172 if (!player->key[EMC_GATE_GRAY_NR(element)])
12173 return MP_NO_ACTION;
12175 else if (IS_EMC_GATE_GRAY_ACTIVE(element))
12177 if (!player->key[EMC_GATE_GRAY_ACTIVE_NR(element)])
12178 return MP_NO_ACTION;
12180 else if (element == EL_DC_GATE_WHITE ||
12181 element == EL_DC_GATE_WHITE_GRAY ||
12182 element == EL_DC_GATE_WHITE_GRAY_ACTIVE)
12184 if (player->num_white_keys == 0)
12185 return MP_NO_ACTION;
12187 player->num_white_keys--;
12189 else if (IS_SP_PORT(element))
12191 if (element == EL_SP_GRAVITY_PORT_LEFT ||
12192 element == EL_SP_GRAVITY_PORT_RIGHT ||
12193 element == EL_SP_GRAVITY_PORT_UP ||
12194 element == EL_SP_GRAVITY_PORT_DOWN)
12195 #if USE_PLAYER_GRAVITY
12196 player->gravity = !player->gravity;
12198 game.gravity = !game.gravity;
12200 else if (element == EL_SP_GRAVITY_ON_PORT_LEFT ||
12201 element == EL_SP_GRAVITY_ON_PORT_RIGHT ||
12202 element == EL_SP_GRAVITY_ON_PORT_UP ||
12203 element == EL_SP_GRAVITY_ON_PORT_DOWN)
12204 #if USE_PLAYER_GRAVITY
12205 player->gravity = TRUE;
12207 game.gravity = TRUE;
12209 else if (element == EL_SP_GRAVITY_OFF_PORT_LEFT ||
12210 element == EL_SP_GRAVITY_OFF_PORT_RIGHT ||
12211 element == EL_SP_GRAVITY_OFF_PORT_UP ||
12212 element == EL_SP_GRAVITY_OFF_PORT_DOWN)
12213 #if USE_PLAYER_GRAVITY
12214 player->gravity = FALSE;
12216 game.gravity = FALSE;
12220 /* automatically move to the next field with double speed */
12221 player->programmed_action = move_direction;
12223 if (player->move_delay_reset_counter == 0)
12225 player->move_delay_reset_counter = 2; /* two double speed steps */
12227 DOUBLE_PLAYER_SPEED(player);
12230 PlayLevelSoundAction(x, y, ACTION_PASSING);
12232 else if (player_can_move_or_snap && IS_DIGGABLE(element))
12236 if (mode != DF_SNAP)
12238 GfxElement[x][y] = GFX_ELEMENT(element);
12239 player->is_digging = TRUE;
12242 PlayLevelSoundElementAction(x, y, element, ACTION_DIGGING);
12244 CheckTriggeredElementChangeByPlayer(x, y, element, CE_PLAYER_DIGS_X,
12245 player->index_bit, dig_side);
12247 if (mode == DF_SNAP)
12249 #if USE_NEW_SNAP_DELAY
12250 if (level.block_snap_field)
12251 setFieldForSnapping(x, y, element, move_direction);
12253 TestIfElementTouchesCustomElement(x, y); /* for empty space */
12255 TestIfElementTouchesCustomElement(x, y); /* for empty space */
12258 CheckTriggeredElementChangeByPlayer(x, y, element, CE_PLAYER_SNAPS_X,
12259 player->index_bit, dig_side);
12262 else if (player_can_move_or_snap && IS_COLLECTIBLE(element))
12266 if (is_player && mode != DF_SNAP)
12268 GfxElement[x][y] = element;
12269 player->is_collecting = TRUE;
12272 if (element == EL_SPEED_PILL)
12274 player->move_delay_value = MOVE_DELAY_HIGH_SPEED;
12276 else if (element == EL_EXTRA_TIME && level.time > 0)
12278 TimeLeft += level.extra_time;
12279 DrawGameValue_Time(TimeLeft);
12281 else if (element == EL_SHIELD_NORMAL || element == EL_SHIELD_DEADLY)
12283 player->shield_normal_time_left += level.shield_normal_time;
12284 if (element == EL_SHIELD_DEADLY)
12285 player->shield_deadly_time_left += level.shield_deadly_time;
12287 else if (element == EL_DYNAMITE ||
12288 element == EL_EM_DYNAMITE ||
12289 element == EL_SP_DISK_RED)
12291 if (player->inventory_size < MAX_INVENTORY_SIZE)
12292 player->inventory_element[player->inventory_size++] = element;
12294 DrawGameDoorValues();
12296 else if (element == EL_DYNABOMB_INCREASE_NUMBER)
12298 player->dynabomb_count++;
12299 player->dynabombs_left++;
12301 else if (element == EL_DYNABOMB_INCREASE_SIZE)
12303 player->dynabomb_size++;
12305 else if (element == EL_DYNABOMB_INCREASE_POWER)
12307 player->dynabomb_xl = TRUE;
12309 else if (IS_KEY(element))
12311 player->key[KEY_NR(element)] = TRUE;
12313 DrawGameDoorValues();
12315 else if (element == EL_DC_KEY_WHITE)
12317 player->num_white_keys++;
12319 /* display white keys? */
12320 /* DrawGameDoorValues(); */
12322 else if (IS_ENVELOPE(element))
12324 player->show_envelope = element;
12326 else if (element == EL_EMC_LENSES)
12328 game.lenses_time_left = level.lenses_time * FRAMES_PER_SECOND;
12330 RedrawAllInvisibleElementsForLenses();
12332 else if (element == EL_EMC_MAGNIFIER)
12334 game.magnify_time_left = level.magnify_time * FRAMES_PER_SECOND;
12336 RedrawAllInvisibleElementsForMagnifier();
12338 else if (IS_DROPPABLE(element) ||
12339 IS_THROWABLE(element)) /* can be collected and dropped */
12343 if (collect_count == 0)
12344 player->inventory_infinite_element = element;
12346 for (i = 0; i < collect_count; i++)
12347 if (player->inventory_size < MAX_INVENTORY_SIZE)
12348 player->inventory_element[player->inventory_size++] = element;
12350 DrawGameDoorValues();
12352 else if (collect_count > 0)
12354 local_player->gems_still_needed -= collect_count;
12355 if (local_player->gems_still_needed < 0)
12356 local_player->gems_still_needed = 0;
12358 DrawGameValue_Emeralds(local_player->gems_still_needed);
12361 RaiseScoreElement(element);
12362 PlayLevelSoundElementAction(x, y, element, ACTION_COLLECTING);
12365 CheckTriggeredElementChangeByPlayer(x, y, element, CE_PLAYER_COLLECTS_X,
12366 player->index_bit, dig_side);
12368 if (mode == DF_SNAP)
12370 #if USE_NEW_SNAP_DELAY
12371 if (level.block_snap_field)
12372 setFieldForSnapping(x, y, element, move_direction);
12374 TestIfElementTouchesCustomElement(x, y); /* for empty space */
12376 TestIfElementTouchesCustomElement(x, y); /* for empty space */
12379 CheckTriggeredElementChangeByPlayer(x, y, element, CE_PLAYER_SNAPS_X,
12380 player->index_bit, dig_side);
12383 else if (player_can_move_or_snap && IS_PUSHABLE(element))
12385 if (mode == DF_SNAP && element != EL_BD_ROCK)
12386 return MP_NO_ACTION;
12388 if (CAN_FALL(element) && dy)
12389 return MP_NO_ACTION;
12391 if (CAN_FALL(element) && IN_LEV_FIELD(x, y + 1) && IS_FREE(x, y + 1) &&
12392 !(element == EL_SPRING && level.use_spring_bug))
12393 return MP_NO_ACTION;
12395 if (CAN_MOVE(element) && GET_MAX_MOVE_DELAY(element) == 0 &&
12396 ((move_direction & MV_VERTICAL &&
12397 ((element_info[element].move_pattern & MV_LEFT &&
12398 IN_LEV_FIELD(x - 1, y) && IS_FREE(x - 1, y)) ||
12399 (element_info[element].move_pattern & MV_RIGHT &&
12400 IN_LEV_FIELD(x + 1, y) && IS_FREE(x + 1, y)))) ||
12401 (move_direction & MV_HORIZONTAL &&
12402 ((element_info[element].move_pattern & MV_UP &&
12403 IN_LEV_FIELD(x, y - 1) && IS_FREE(x, y - 1)) ||
12404 (element_info[element].move_pattern & MV_DOWN &&
12405 IN_LEV_FIELD(x, y + 1) && IS_FREE(x, y + 1))))))
12406 return MP_NO_ACTION;
12408 /* do not push elements already moving away faster than player */
12409 if (CAN_MOVE(element) && MovDir[x][y] == move_direction &&
12410 ABS(getElementMoveStepsize(x, y)) > MOVE_STEPSIZE_NORMAL)
12411 return MP_NO_ACTION;
12413 if (game.engine_version >= VERSION_IDENT(3,1,0,0))
12415 if (player->push_delay_value == -1 || !player_was_pushing)
12416 player->push_delay_value = GET_NEW_PUSH_DELAY(element);
12418 else if (game.engine_version >= VERSION_IDENT(3,0,7,1))
12420 if (player->push_delay_value == -1)
12421 player->push_delay_value = GET_NEW_PUSH_DELAY(element);
12423 else if (game.engine_version >= VERSION_IDENT(2,2,0,7))
12425 if (!player->is_pushing)
12426 player->push_delay_value = GET_NEW_PUSH_DELAY(element);
12429 player->is_pushing = TRUE;
12430 player->is_active = TRUE;
12432 if (!(IN_LEV_FIELD(nextx, nexty) &&
12433 (IS_FREE(nextx, nexty) ||
12434 (Feld[nextx][nexty] == EL_SOKOBAN_FIELD_EMPTY &&
12435 IS_SB_ELEMENT(element)))))
12436 return MP_NO_ACTION;
12438 if (!checkDiagonalPushing(player, x, y, real_dx, real_dy))
12439 return MP_NO_ACTION;
12441 if (player->push_delay == -1) /* new pushing; restart delay */
12442 player->push_delay = 0;
12444 if (player->push_delay < player->push_delay_value &&
12445 !(tape.playing && tape.file_version < FILE_VERSION_2_0) &&
12446 element != EL_SPRING && element != EL_BALLOON)
12448 /* make sure that there is no move delay before next try to push */
12449 if (game.engine_version >= VERSION_IDENT(3,0,7,1))
12450 player->move_delay = 0;
12452 return MP_NO_ACTION;
12455 if (IS_SB_ELEMENT(element))
12457 if (element == EL_SOKOBAN_FIELD_FULL)
12459 Back[x][y] = EL_SOKOBAN_FIELD_EMPTY;
12460 local_player->sokobanfields_still_needed++;
12463 if (Feld[nextx][nexty] == EL_SOKOBAN_FIELD_EMPTY)
12465 Back[nextx][nexty] = EL_SOKOBAN_FIELD_EMPTY;
12466 local_player->sokobanfields_still_needed--;
12469 Feld[x][y] = EL_SOKOBAN_OBJECT;
12471 if (Back[x][y] == Back[nextx][nexty])
12472 PlayLevelSoundAction(x, y, ACTION_PUSHING);
12473 else if (Back[x][y] != 0)
12474 PlayLevelSoundElementAction(x, y, EL_SOKOBAN_FIELD_FULL,
12477 PlayLevelSoundElementAction(nextx, nexty, EL_SOKOBAN_FIELD_EMPTY,
12480 if (local_player->sokobanfields_still_needed == 0 &&
12481 game.emulation == EMU_SOKOBAN)
12483 PlayerWins(player);
12485 PlayLevelSound(x, y, SND_GAME_SOKOBAN_SOLVING);
12489 PlayLevelSoundElementAction(x, y, element, ACTION_PUSHING);
12491 InitMovingField(x, y, move_direction);
12492 GfxAction[x][y] = ACTION_PUSHING;
12494 if (mode == DF_SNAP)
12495 ContinueMoving(x, y);
12497 MovPos[x][y] = (dx != 0 ? dx : dy);
12499 Pushed[x][y] = TRUE;
12500 Pushed[nextx][nexty] = TRUE;
12502 if (game.engine_version < VERSION_IDENT(2,2,0,7))
12503 player->push_delay_value = GET_NEW_PUSH_DELAY(element);
12505 player->push_delay_value = -1; /* get new value later */
12507 /* check for element change _after_ element has been pushed */
12508 if (game.use_change_when_pushing_bug)
12510 CheckElementChangeByPlayer(x, y, element, CE_PUSHED_BY_PLAYER,
12511 player->index_bit, dig_side);
12512 CheckTriggeredElementChangeByPlayer(x, y, element, CE_PLAYER_PUSHES_X,
12513 player->index_bit, dig_side);
12516 else if (IS_SWITCHABLE(element))
12518 if (PLAYER_SWITCHING(player, x, y))
12520 CheckTriggeredElementChangeByPlayer(x, y, element, CE_PLAYER_PRESSES_X,
12521 player->index_bit, dig_side);
12526 player->is_switching = TRUE;
12527 player->switch_x = x;
12528 player->switch_y = y;
12530 PlayLevelSoundElementAction(x, y, element, ACTION_ACTIVATING);
12532 if (element == EL_ROBOT_WHEEL)
12534 Feld[x][y] = EL_ROBOT_WHEEL_ACTIVE;
12538 DrawLevelField(x, y);
12540 else if (element == EL_SP_TERMINAL)
12544 SCAN_PLAYFIELD(xx, yy)
12546 if (Feld[xx][yy] == EL_SP_DISK_YELLOW)
12548 else if (Feld[xx][yy] == EL_SP_TERMINAL)
12549 Feld[xx][yy] = EL_SP_TERMINAL_ACTIVE;
12552 else if (IS_BELT_SWITCH(element))
12554 ToggleBeltSwitch(x, y);
12556 else if (element == EL_SWITCHGATE_SWITCH_UP ||
12557 element == EL_SWITCHGATE_SWITCH_DOWN ||
12558 element == EL_DC_SWITCHGATE_SWITCH_UP ||
12559 element == EL_DC_SWITCHGATE_SWITCH_DOWN)
12561 ToggleSwitchgateSwitch(x, y);
12563 else if (element == EL_LIGHT_SWITCH ||
12564 element == EL_LIGHT_SWITCH_ACTIVE)
12566 ToggleLightSwitch(x, y);
12568 else if (element == EL_TIMEGATE_SWITCH ||
12569 element == EL_DC_TIMEGATE_SWITCH)
12571 ActivateTimegateSwitch(x, y);
12573 else if (element == EL_BALLOON_SWITCH_LEFT ||
12574 element == EL_BALLOON_SWITCH_RIGHT ||
12575 element == EL_BALLOON_SWITCH_UP ||
12576 element == EL_BALLOON_SWITCH_DOWN ||
12577 element == EL_BALLOON_SWITCH_NONE ||
12578 element == EL_BALLOON_SWITCH_ANY)
12580 game.wind_direction = (element == EL_BALLOON_SWITCH_LEFT ? MV_LEFT :
12581 element == EL_BALLOON_SWITCH_RIGHT ? MV_RIGHT :
12582 element == EL_BALLOON_SWITCH_UP ? MV_UP :
12583 element == EL_BALLOON_SWITCH_DOWN ? MV_DOWN :
12584 element == EL_BALLOON_SWITCH_NONE ? MV_NONE :
12587 else if (element == EL_LAMP)
12589 Feld[x][y] = EL_LAMP_ACTIVE;
12590 local_player->lights_still_needed--;
12592 ResetGfxAnimation(x, y);
12593 DrawLevelField(x, y);
12595 else if (element == EL_TIME_ORB_FULL)
12597 Feld[x][y] = EL_TIME_ORB_EMPTY;
12599 if (level.time > 0 || level.use_time_orb_bug)
12601 TimeLeft += level.time_orb_time;
12602 DrawGameValue_Time(TimeLeft);
12605 ResetGfxAnimation(x, y);
12606 DrawLevelField(x, y);
12608 else if (element == EL_EMC_MAGIC_BALL_SWITCH ||
12609 element == EL_EMC_MAGIC_BALL_SWITCH_ACTIVE)
12613 game.ball_state = !game.ball_state;
12615 SCAN_PLAYFIELD(xx, yy)
12617 int e = Feld[xx][yy];
12619 if (game.ball_state)
12621 if (e == EL_EMC_MAGIC_BALL)
12622 CreateField(xx, yy, EL_EMC_MAGIC_BALL_ACTIVE);
12623 else if (e == EL_EMC_MAGIC_BALL_SWITCH)
12624 CreateField(xx, yy, EL_EMC_MAGIC_BALL_SWITCH_ACTIVE);
12628 if (e == EL_EMC_MAGIC_BALL_ACTIVE)
12629 CreateField(xx, yy, EL_EMC_MAGIC_BALL);
12630 else if (e == EL_EMC_MAGIC_BALL_SWITCH_ACTIVE)
12631 CreateField(xx, yy, EL_EMC_MAGIC_BALL_SWITCH);
12636 CheckTriggeredElementChangeByPlayer(x, y, element, CE_SWITCH_OF_X,
12637 player->index_bit, dig_side);
12639 CheckTriggeredElementChangeByPlayer(x, y, element, CE_PLAYER_SWITCHES_X,
12640 player->index_bit, dig_side);
12642 CheckTriggeredElementChangeByPlayer(x, y, element, CE_PLAYER_PRESSES_X,
12643 player->index_bit, dig_side);
12649 if (!PLAYER_SWITCHING(player, x, y))
12651 player->is_switching = TRUE;
12652 player->switch_x = x;
12653 player->switch_y = y;
12655 CheckElementChangeByPlayer(x, y, element, CE_SWITCHED,
12656 player->index_bit, dig_side);
12657 CheckTriggeredElementChangeByPlayer(x, y, element, CE_SWITCH_OF_X,
12658 player->index_bit, dig_side);
12660 CheckElementChangeByPlayer(x, y, element, CE_SWITCHED_BY_PLAYER,
12661 player->index_bit, dig_side);
12662 CheckTriggeredElementChangeByPlayer(x, y, element, CE_PLAYER_SWITCHES_X,
12663 player->index_bit, dig_side);
12666 CheckElementChangeByPlayer(x, y, element, CE_PRESSED_BY_PLAYER,
12667 player->index_bit, dig_side);
12668 CheckTriggeredElementChangeByPlayer(x, y, element, CE_PLAYER_PRESSES_X,
12669 player->index_bit, dig_side);
12671 return MP_NO_ACTION;
12674 player->push_delay = -1;
12676 if (is_player) /* function can also be called by EL_PENGUIN */
12678 if (Feld[x][y] != element) /* really digged/collected something */
12680 player->is_collecting = !player->is_digging;
12681 player->is_active = TRUE;
12688 boolean SnapField(struct PlayerInfo *player, int dx, int dy)
12690 int jx = player->jx, jy = player->jy;
12691 int x = jx + dx, y = jy + dy;
12692 int snap_direction = (dx == -1 ? MV_LEFT :
12693 dx == +1 ? MV_RIGHT :
12695 dy == +1 ? MV_DOWN : MV_NONE);
12696 boolean can_continue_snapping = (level.continuous_snapping &&
12697 WasJustFalling[x][y] < CHECK_DELAY_FALLING);
12699 if (player->MovPos != 0 && game.engine_version >= VERSION_IDENT(2,2,0,0))
12702 if (!player->active || !IN_LEV_FIELD(x, y))
12710 if (player->MovPos == 0)
12711 player->is_pushing = FALSE;
12713 player->is_snapping = FALSE;
12715 if (player->MovPos == 0)
12717 player->is_moving = FALSE;
12718 player->is_digging = FALSE;
12719 player->is_collecting = FALSE;
12725 #if USE_NEW_CONTINUOUS_SNAPPING
12726 /* prevent snapping with already pressed snap key when not allowed */
12727 if (player->is_snapping && !can_continue_snapping)
12730 if (player->is_snapping)
12734 player->MovDir = snap_direction;
12736 if (player->MovPos == 0)
12738 player->is_moving = FALSE;
12739 player->is_digging = FALSE;
12740 player->is_collecting = FALSE;
12743 player->is_dropping = FALSE;
12744 player->is_dropping_pressed = FALSE;
12745 player->drop_pressed_delay = 0;
12747 if (DigField(player, jx, jy, x, y, 0, 0, DF_SNAP) == MP_NO_ACTION)
12750 player->is_snapping = TRUE;
12751 player->is_active = TRUE;
12753 if (player->MovPos == 0)
12755 player->is_moving = FALSE;
12756 player->is_digging = FALSE;
12757 player->is_collecting = FALSE;
12760 if (player->MovPos != 0) /* prevent graphic bugs in versions < 2.2.0 */
12761 DrawLevelField(player->last_jx, player->last_jy);
12763 DrawLevelField(x, y);
12768 boolean DropElement(struct PlayerInfo *player)
12770 int old_element, new_element;
12771 int dropx = player->jx, dropy = player->jy;
12772 int drop_direction = player->MovDir;
12773 int drop_side = drop_direction;
12774 int drop_element = (player->inventory_size > 0 ?
12775 player->inventory_element[player->inventory_size - 1] :
12776 player->inventory_infinite_element != EL_UNDEFINED ?
12777 player->inventory_infinite_element :
12778 player->dynabombs_left > 0 ?
12779 EL_DYNABOMB_PLAYER_1_ACTIVE + player->index_nr :
12782 player->is_dropping_pressed = TRUE;
12784 /* do not drop an element on top of another element; when holding drop key
12785 pressed without moving, dropped element must move away before the next
12786 element can be dropped (this is especially important if the next element
12787 is dynamite, which can be placed on background for historical reasons) */
12788 if (PLAYER_DROPPING(player, dropx, dropy) && Feld[dropx][dropy] != EL_EMPTY)
12791 if (IS_THROWABLE(drop_element))
12793 dropx += GET_DX_FROM_DIR(drop_direction);
12794 dropy += GET_DY_FROM_DIR(drop_direction);
12796 if (!IN_LEV_FIELD(dropx, dropy))
12800 old_element = Feld[dropx][dropy]; /* old element at dropping position */
12801 new_element = drop_element; /* default: no change when dropping */
12803 /* check if player is active, not moving and ready to drop */
12804 if (!player->active || player->MovPos || player->drop_delay > 0)
12807 /* check if player has anything that can be dropped */
12808 if (new_element == EL_UNDEFINED)
12811 /* check if drop key was pressed long enough for EM style dynamite */
12812 if (new_element == EL_EM_DYNAMITE && player->drop_pressed_delay < 40)
12815 /* check if anything can be dropped at the current position */
12816 if (IS_ACTIVE_BOMB(old_element) || old_element == EL_EXPLOSION)
12819 /* collected custom elements can only be dropped on empty fields */
12820 if (IS_CUSTOM_ELEMENT(new_element) && old_element != EL_EMPTY)
12823 if (old_element != EL_EMPTY)
12824 Back[dropx][dropy] = old_element; /* store old element on this field */
12826 ResetGfxAnimation(dropx, dropy);
12827 ResetRandomAnimationValue(dropx, dropy);
12829 if (player->inventory_size > 0 ||
12830 player->inventory_infinite_element != EL_UNDEFINED)
12832 if (player->inventory_size > 0)
12834 player->inventory_size--;
12836 DrawGameDoorValues();
12838 if (new_element == EL_DYNAMITE)
12839 new_element = EL_DYNAMITE_ACTIVE;
12840 else if (new_element == EL_EM_DYNAMITE)
12841 new_element = EL_EM_DYNAMITE_ACTIVE;
12842 else if (new_element == EL_SP_DISK_RED)
12843 new_element = EL_SP_DISK_RED_ACTIVE;
12846 Feld[dropx][dropy] = new_element;
12848 if (IN_SCR_FIELD(SCREENX(dropx), SCREENY(dropy)))
12849 DrawGraphicThruMask(SCREENX(dropx), SCREENY(dropy),
12850 el2img(Feld[dropx][dropy]), 0);
12852 PlayLevelSoundAction(dropx, dropy, ACTION_DROPPING);
12854 /* needed if previous element just changed to "empty" in the last frame */
12855 ChangeCount[dropx][dropy] = 0; /* allow at least one more change */
12857 CheckElementChangeByPlayer(dropx, dropy, new_element, CE_DROPPED_BY_PLAYER,
12858 player->index_bit, drop_side);
12859 CheckTriggeredElementChangeByPlayer(dropx, dropy, new_element,
12861 player->index_bit, drop_side);
12863 TestIfElementTouchesCustomElement(dropx, dropy);
12865 else /* player is dropping a dyna bomb */
12867 player->dynabombs_left--;
12869 Feld[dropx][dropy] = new_element;
12871 if (IN_SCR_FIELD(SCREENX(dropx), SCREENY(dropy)))
12872 DrawGraphicThruMask(SCREENX(dropx), SCREENY(dropy),
12873 el2img(Feld[dropx][dropy]), 0);
12875 PlayLevelSoundAction(dropx, dropy, ACTION_DROPPING);
12878 if (Feld[dropx][dropy] == new_element) /* uninitialized unless CE change */
12879 InitField_WithBug1(dropx, dropy, FALSE);
12881 new_element = Feld[dropx][dropy]; /* element might have changed */
12883 if (IS_CUSTOM_ELEMENT(new_element) && CAN_MOVE(new_element) &&
12884 element_info[new_element].move_pattern == MV_WHEN_DROPPED)
12886 int move_direction, nextx, nexty;
12888 if (element_info[new_element].move_direction_initial == MV_START_AUTOMATIC)
12889 MovDir[dropx][dropy] = drop_direction;
12891 move_direction = MovDir[dropx][dropy];
12892 nextx = dropx + GET_DX_FROM_DIR(move_direction);
12893 nexty = dropy + GET_DY_FROM_DIR(move_direction);
12895 ChangeCount[dropx][dropy] = 0; /* allow at least one more change */
12897 #if USE_FIX_IMPACT_COLLISION
12898 /* do not cause impact style collision by dropping elements that can fall */
12899 CheckCollision[dropx][dropy] = CHECK_DELAY_COLLISION;
12901 CheckCollision[dropx][dropy] = CHECK_DELAY_COLLISION;
12905 player->drop_delay = GET_NEW_DROP_DELAY(drop_element);
12906 player->is_dropping = TRUE;
12908 player->drop_pressed_delay = 0;
12909 player->is_dropping_pressed = FALSE;
12911 player->drop_x = dropx;
12912 player->drop_y = dropy;
12917 /* ------------------------------------------------------------------------- */
12918 /* game sound playing functions */
12919 /* ------------------------------------------------------------------------- */
12921 static int *loop_sound_frame = NULL;
12922 static int *loop_sound_volume = NULL;
12924 void InitPlayLevelSound()
12926 int num_sounds = getSoundListSize();
12928 checked_free(loop_sound_frame);
12929 checked_free(loop_sound_volume);
12931 loop_sound_frame = checked_calloc(num_sounds * sizeof(int));
12932 loop_sound_volume = checked_calloc(num_sounds * sizeof(int));
12935 static void PlayLevelSound(int x, int y, int nr)
12937 int sx = SCREENX(x), sy = SCREENY(y);
12938 int volume, stereo_position;
12939 int max_distance = 8;
12940 int type = (IS_LOOP_SOUND(nr) ? SND_CTRL_PLAY_LOOP : SND_CTRL_PLAY_SOUND);
12942 if ((!setup.sound_simple && !IS_LOOP_SOUND(nr)) ||
12943 (!setup.sound_loops && IS_LOOP_SOUND(nr)))
12946 if (!IN_LEV_FIELD(x, y) ||
12947 sx < -max_distance || sx >= SCR_FIELDX + max_distance ||
12948 sy < -max_distance || sy >= SCR_FIELDY + max_distance)
12951 volume = SOUND_MAX_VOLUME;
12953 if (!IN_SCR_FIELD(sx, sy))
12955 int dx = ABS(sx - SCR_FIELDX / 2) - SCR_FIELDX / 2;
12956 int dy = ABS(sy - SCR_FIELDY / 2) - SCR_FIELDY / 2;
12958 volume -= volume * (dx > dy ? dx : dy) / max_distance;
12961 stereo_position = (SOUND_MAX_LEFT +
12962 (sx + max_distance) * SOUND_MAX_LEFT2RIGHT /
12963 (SCR_FIELDX + 2 * max_distance));
12965 if (IS_LOOP_SOUND(nr))
12967 /* This assures that quieter loop sounds do not overwrite louder ones,
12968 while restarting sound volume comparison with each new game frame. */
12970 if (loop_sound_volume[nr] > volume && loop_sound_frame[nr] == FrameCounter)
12973 loop_sound_volume[nr] = volume;
12974 loop_sound_frame[nr] = FrameCounter;
12977 PlaySoundExt(nr, volume, stereo_position, type);
12980 static void PlayLevelSoundNearest(int x, int y, int sound_action)
12982 PlayLevelSound(x < LEVELX(BX1) ? LEVELX(BX1) :
12983 x > LEVELX(BX2) ? LEVELX(BX2) : x,
12984 y < LEVELY(BY1) ? LEVELY(BY1) :
12985 y > LEVELY(BY2) ? LEVELY(BY2) : y,
12989 static void PlayLevelSoundAction(int x, int y, int action)
12991 PlayLevelSoundElementAction(x, y, Feld[x][y], action);
12994 static void PlayLevelSoundElementAction(int x, int y, int element, int action)
12996 int sound_effect = element_info[SND_ELEMENT(element)].sound[action];
12998 if (sound_effect != SND_UNDEFINED)
12999 PlayLevelSound(x, y, sound_effect);
13002 static void PlayLevelSoundElementActionIfLoop(int x, int y, int element,
13005 int sound_effect = element_info[SND_ELEMENT(element)].sound[action];
13007 if (sound_effect != SND_UNDEFINED && IS_LOOP_SOUND(sound_effect))
13008 PlayLevelSound(x, y, sound_effect);
13011 static void PlayLevelSoundActionIfLoop(int x, int y, int action)
13013 int sound_effect = element_info[SND_ELEMENT(Feld[x][y])].sound[action];
13015 if (sound_effect != SND_UNDEFINED && IS_LOOP_SOUND(sound_effect))
13016 PlayLevelSound(x, y, sound_effect);
13019 static void StopLevelSoundActionIfLoop(int x, int y, int action)
13021 int sound_effect = element_info[SND_ELEMENT(Feld[x][y])].sound[action];
13023 if (sound_effect != SND_UNDEFINED && IS_LOOP_SOUND(sound_effect))
13024 StopSound(sound_effect);
13027 static void PlayLevelMusic()
13029 if (levelset.music[level_nr] != MUS_UNDEFINED)
13030 PlayMusic(levelset.music[level_nr]); /* from config file */
13032 PlayMusic(MAP_NOCONF_MUSIC(level_nr)); /* from music dir */
13035 void PlayLevelSound_EM(int xx, int yy, int element_em, int sample)
13037 int element = (element_em > -1 ? map_element_EM_to_RND(element_em) : 0);
13038 int offset = (BorderElement == EL_STEELWALL ? 1 : 0);
13039 int x = xx - 1 - offset;
13040 int y = yy - 1 - offset;
13045 PlayLevelSoundElementAction(x, y, element, ACTION_WALKING);
13049 PlayLevelSoundElementAction(x, y, element, ACTION_PUSHING);
13053 PlayLevelSoundElementAction(x, y, element, ACTION_IMPACT);
13057 PlayLevelSoundElementAction(x, y, element, ACTION_IMPACT);
13061 PlayLevelSoundElementAction(x, y, element, ACTION_BREAKING);
13065 PlayLevelSoundElementAction(x, y, element, ACTION_MOVING);
13069 PlayLevelSoundElementAction(x, y, element, ACTION_MOVING);
13072 case SAMPLE_android_clone:
13073 PlayLevelSoundElementAction(x, y, element, ACTION_DROPPING);
13076 case SAMPLE_android_move:
13077 PlayLevelSoundElementAction(x, y, element, ACTION_MOVING);
13080 case SAMPLE_spring:
13081 PlayLevelSoundElementAction(x, y, element, ACTION_IMPACT);
13085 PlayLevelSoundElementAction(x, y, element, ACTION_EATING);
13089 PlayLevelSoundElementAction(x, y, element, ACTION_WAITING);
13092 case SAMPLE_eater_eat:
13093 PlayLevelSoundElementAction(x, y, element, ACTION_DIGGING);
13097 PlayLevelSoundElementAction(x, y, element, ACTION_MOVING);
13100 case SAMPLE_collect:
13101 PlayLevelSoundElementAction(x, y, element, ACTION_COLLECTING);
13104 case SAMPLE_diamond:
13105 PlayLevelSoundElementAction(x, y, element, ACTION_IMPACT);
13108 case SAMPLE_squash:
13109 /* !!! CHECK THIS !!! */
13111 PlayLevelSoundElementAction(x, y, element, ACTION_BREAKING);
13113 PlayLevelSoundElementAction(x, y, element, ACTION_SMASHED_BY_ROCK);
13117 case SAMPLE_wonderfall:
13118 PlayLevelSoundElementAction(x, y, element, ACTION_FILLING);
13122 PlayLevelSoundElementAction(x, y, element, ACTION_IMPACT);
13126 PlayLevelSoundElementAction(x, y, element, ACTION_PUSHING);
13130 PlayLevelSoundElementAction(x, y, element, ACTION_DIGGING);
13134 PlayLevelSoundElementAction(x, y, element, ACTION_SPLASHING);
13138 PlayLevelSoundElementAction(x, y, element, ACTION_DROPPING);
13142 PlayLevelSoundElementAction(x, y, element, ACTION_GROWING);
13145 case SAMPLE_wonder:
13146 PlayLevelSoundElementAction(x, y, element, ACTION_ACTIVE);
13150 PlayLevelSoundElementAction(x, y, element, ACTION_PASSING);
13153 case SAMPLE_exit_open:
13154 PlayLevelSoundElementAction(x, y, element, ACTION_OPENING);
13157 case SAMPLE_exit_leave:
13158 PlayLevelSoundElementAction(x, y, element, ACTION_PASSING);
13161 case SAMPLE_dynamite:
13162 PlayLevelSoundElementAction(x, y, element, ACTION_DROPPING);
13166 PlayLevelSoundElementAction(x, y, element, ACTION_ACTIVE);
13170 PlayLevelSoundElementAction(x, y, element, ACTION_ACTIVATING);
13174 PlayLevelSoundElementAction(x, y, element, ACTION_ACTIVE);
13178 PlayLevelSoundElementAction(x, y, element, ACTION_EXPLODING);
13182 PlayLevelSoundElementAction(x, y, element, ACTION_DYING);
13186 PlaySound(SND_GAME_RUNNING_OUT_OF_TIME);
13190 PlayLevelSoundElementAction(x, y, element, ACTION_DEFAULT);
13196 void ChangeTime(int value)
13198 int *time = (level.time == 0 ? &TimePlayed : &TimeLeft);
13202 /* EMC game engine uses value from time counter of RND game engine */
13203 level.native_em_level->lev->time = *time;
13205 DrawGameValue_Time(*time);
13208 void RaiseScore(int value)
13210 /* EMC game engine and RND game engine have separate score counters */
13211 int *score = (level.game_engine_type == GAME_ENGINE_TYPE_EM ?
13212 &level.native_em_level->lev->score : &local_player->score);
13216 DrawGameValue_Score(*score);
13220 void RaiseScore(int value)
13222 local_player->score += value;
13224 DrawGameValue_Score(local_player->score);
13227 void RaiseScoreElement(int element)
13232 case EL_BD_DIAMOND:
13233 case EL_EMERALD_YELLOW:
13234 case EL_EMERALD_RED:
13235 case EL_EMERALD_PURPLE:
13236 case EL_SP_INFOTRON:
13237 RaiseScore(level.score[SC_EMERALD]);
13240 RaiseScore(level.score[SC_DIAMOND]);
13243 RaiseScore(level.score[SC_CRYSTAL]);
13246 RaiseScore(level.score[SC_PEARL]);
13249 case EL_BD_BUTTERFLY:
13250 case EL_SP_ELECTRON:
13251 RaiseScore(level.score[SC_BUG]);
13254 case EL_BD_FIREFLY:
13255 case EL_SP_SNIKSNAK:
13256 RaiseScore(level.score[SC_SPACESHIP]);
13259 case EL_DARK_YAMYAM:
13260 RaiseScore(level.score[SC_YAMYAM]);
13263 RaiseScore(level.score[SC_ROBOT]);
13266 RaiseScore(level.score[SC_PACMAN]);
13269 RaiseScore(level.score[SC_NUT]);
13272 case EL_EM_DYNAMITE:
13273 case EL_SP_DISK_RED:
13274 case EL_DYNABOMB_INCREASE_NUMBER:
13275 case EL_DYNABOMB_INCREASE_SIZE:
13276 case EL_DYNABOMB_INCREASE_POWER:
13277 RaiseScore(level.score[SC_DYNAMITE]);
13279 case EL_SHIELD_NORMAL:
13280 case EL_SHIELD_DEADLY:
13281 RaiseScore(level.score[SC_SHIELD]);
13283 case EL_EXTRA_TIME:
13284 RaiseScore(level.extra_time_score);
13298 case EL_DC_KEY_WHITE:
13299 RaiseScore(level.score[SC_KEY]);
13302 RaiseScore(element_info[element].collect_score);
13307 void RequestQuitGameExt(boolean skip_request, boolean quick_quit, char *message)
13309 if (skip_request || Request(message, REQ_ASK | REQ_STAY_CLOSED))
13311 #if defined(NETWORK_AVALIABLE)
13312 if (options.network)
13313 SendToServer_StopPlaying(NETWORK_STOP_BY_PLAYER);
13319 game_status = GAME_MODE_MAIN;
13325 FadeOut(REDRAW_FIELD);
13327 game_status = GAME_MODE_MAIN;
13329 DrawAndFadeInMainMenu(REDRAW_FIELD);
13333 else /* continue playing the game */
13335 if (tape.playing && tape.deactivate_display)
13336 TapeDeactivateDisplayOff(TRUE);
13338 OpenDoor(DOOR_OPEN_1 | DOOR_COPY_BACK);
13340 if (tape.playing && tape.deactivate_display)
13341 TapeDeactivateDisplayOn();
13345 void RequestQuitGame(boolean ask_if_really_quit)
13347 boolean quick_quit = (!ask_if_really_quit || level_editor_test_game);
13348 boolean skip_request = AllPlayersGone || quick_quit;
13350 RequestQuitGameExt(skip_request, quick_quit,
13351 "Do you really want to quit the game ?");
13355 /* ------------------------------------------------------------------------- */
13356 /* random generator functions */
13357 /* ------------------------------------------------------------------------- */
13359 unsigned int InitEngineRandom_RND(long seed)
13361 game.num_random_calls = 0;
13364 unsigned int rnd_seed = InitEngineRandom(seed);
13366 printf("::: START RND: %d\n", rnd_seed);
13371 return InitEngineRandom(seed);
13377 unsigned int RND(int max)
13381 game.num_random_calls++;
13383 return GetEngineRandom(max);
13390 /* ------------------------------------------------------------------------- */
13391 /* game engine snapshot handling functions */
13392 /* ------------------------------------------------------------------------- */
13394 #define ARGS_ADDRESS_AND_SIZEOF(x) (&(x)), (sizeof(x))
13396 struct EngineSnapshotInfo
13398 /* runtime values for custom element collect score */
13399 int collect_score[NUM_CUSTOM_ELEMENTS];
13401 /* runtime values for group element choice position */
13402 int choice_pos[NUM_GROUP_ELEMENTS];
13404 /* runtime values for belt position animations */
13405 int belt_graphic[4 * NUM_BELT_PARTS];
13406 int belt_anim_mode[4 * NUM_BELT_PARTS];
13409 struct EngineSnapshotNodeInfo
13416 static struct EngineSnapshotInfo engine_snapshot_rnd;
13417 static ListNode *engine_snapshot_list = NULL;
13418 static char *snapshot_level_identifier = NULL;
13419 static int snapshot_level_nr = -1;
13421 void FreeEngineSnapshot()
13423 while (engine_snapshot_list != NULL)
13424 deleteNodeFromList(&engine_snapshot_list, engine_snapshot_list->key,
13427 setString(&snapshot_level_identifier, NULL);
13428 snapshot_level_nr = -1;
13431 static void SaveEngineSnapshotValues_RND()
13433 static int belt_base_active_element[4] =
13435 EL_CONVEYOR_BELT_1_LEFT_ACTIVE,
13436 EL_CONVEYOR_BELT_2_LEFT_ACTIVE,
13437 EL_CONVEYOR_BELT_3_LEFT_ACTIVE,
13438 EL_CONVEYOR_BELT_4_LEFT_ACTIVE
13442 for (i = 0; i < NUM_CUSTOM_ELEMENTS; i++)
13444 int element = EL_CUSTOM_START + i;
13446 engine_snapshot_rnd.collect_score[i] = element_info[element].collect_score;
13449 for (i = 0; i < NUM_GROUP_ELEMENTS; i++)
13451 int element = EL_GROUP_START + i;
13453 engine_snapshot_rnd.choice_pos[i] = element_info[element].group->choice_pos;
13456 for (i = 0; i < 4; i++)
13458 for (j = 0; j < NUM_BELT_PARTS; j++)
13460 int element = belt_base_active_element[i] + j;
13461 int graphic = el2img(element);
13462 int anim_mode = graphic_info[graphic].anim_mode;
13464 engine_snapshot_rnd.belt_graphic[i * 4 + j] = graphic;
13465 engine_snapshot_rnd.belt_anim_mode[i * 4 + j] = anim_mode;
13470 static void LoadEngineSnapshotValues_RND()
13472 unsigned long num_random_calls = game.num_random_calls;
13475 for (i = 0; i < NUM_CUSTOM_ELEMENTS; i++)
13477 int element = EL_CUSTOM_START + i;
13479 element_info[element].collect_score = engine_snapshot_rnd.collect_score[i];
13482 for (i = 0; i < NUM_GROUP_ELEMENTS; i++)
13484 int element = EL_GROUP_START + i;
13486 element_info[element].group->choice_pos = engine_snapshot_rnd.choice_pos[i];
13489 for (i = 0; i < 4; i++)
13491 for (j = 0; j < NUM_BELT_PARTS; j++)
13493 int graphic = engine_snapshot_rnd.belt_graphic[i * 4 + j];
13494 int anim_mode = engine_snapshot_rnd.belt_anim_mode[i * 4 + j];
13496 graphic_info[graphic].anim_mode = anim_mode;
13500 if (level.game_engine_type == GAME_ENGINE_TYPE_RND)
13502 InitRND(tape.random_seed);
13503 for (i = 0; i < num_random_calls; i++)
13507 if (game.num_random_calls != num_random_calls)
13509 Error(ERR_RETURN, "number of random calls out of sync");
13510 Error(ERR_RETURN, "number of random calls should be %d", num_random_calls);
13511 Error(ERR_RETURN, "number of random calls is %d", game.num_random_calls);
13512 Error(ERR_EXIT, "this should not happen -- please debug");
13516 static void SaveEngineSnapshotBuffer(void *buffer, int size)
13518 struct EngineSnapshotNodeInfo *bi =
13519 checked_calloc(sizeof(struct EngineSnapshotNodeInfo));
13521 bi->buffer_orig = buffer;
13522 bi->buffer_copy = checked_malloc(size);
13525 memcpy(bi->buffer_copy, buffer, size);
13527 addNodeToList(&engine_snapshot_list, NULL, bi);
13530 void SaveEngineSnapshot()
13532 FreeEngineSnapshot(); /* free previous snapshot, if needed */
13534 if (level_editor_test_game) /* do not save snapshots from editor */
13537 /* copy some special values to a structure better suited for the snapshot */
13539 SaveEngineSnapshotValues_RND();
13540 SaveEngineSnapshotValues_EM();
13542 /* save values stored in special snapshot structure */
13544 SaveEngineSnapshotBuffer(ARGS_ADDRESS_AND_SIZEOF(engine_snapshot_rnd));
13545 SaveEngineSnapshotBuffer(ARGS_ADDRESS_AND_SIZEOF(engine_snapshot_em));
13547 /* save further RND engine values */
13549 SaveEngineSnapshotBuffer(ARGS_ADDRESS_AND_SIZEOF(stored_player));
13550 SaveEngineSnapshotBuffer(ARGS_ADDRESS_AND_SIZEOF(game));
13551 SaveEngineSnapshotBuffer(ARGS_ADDRESS_AND_SIZEOF(tape));
13553 SaveEngineSnapshotBuffer(ARGS_ADDRESS_AND_SIZEOF(ZX));
13554 SaveEngineSnapshotBuffer(ARGS_ADDRESS_AND_SIZEOF(ZY));
13555 SaveEngineSnapshotBuffer(ARGS_ADDRESS_AND_SIZEOF(ExitX));
13556 SaveEngineSnapshotBuffer(ARGS_ADDRESS_AND_SIZEOF(ExitY));
13558 SaveEngineSnapshotBuffer(ARGS_ADDRESS_AND_SIZEOF(FrameCounter));
13559 SaveEngineSnapshotBuffer(ARGS_ADDRESS_AND_SIZEOF(TimeFrames));
13560 SaveEngineSnapshotBuffer(ARGS_ADDRESS_AND_SIZEOF(TimePlayed));
13561 SaveEngineSnapshotBuffer(ARGS_ADDRESS_AND_SIZEOF(TimeLeft));
13562 SaveEngineSnapshotBuffer(ARGS_ADDRESS_AND_SIZEOF(TapeTime));
13564 SaveEngineSnapshotBuffer(ARGS_ADDRESS_AND_SIZEOF(ScreenMovDir));
13565 SaveEngineSnapshotBuffer(ARGS_ADDRESS_AND_SIZEOF(ScreenMovPos));
13566 SaveEngineSnapshotBuffer(ARGS_ADDRESS_AND_SIZEOF(ScreenGfxPos));
13568 SaveEngineSnapshotBuffer(ARGS_ADDRESS_AND_SIZEOF(ScrollStepSize));
13570 SaveEngineSnapshotBuffer(ARGS_ADDRESS_AND_SIZEOF(AllPlayersGone));
13572 SaveEngineSnapshotBuffer(ARGS_ADDRESS_AND_SIZEOF(AmoebaCnt));
13573 SaveEngineSnapshotBuffer(ARGS_ADDRESS_AND_SIZEOF(AmoebaCnt2));
13575 SaveEngineSnapshotBuffer(ARGS_ADDRESS_AND_SIZEOF(Feld));
13576 SaveEngineSnapshotBuffer(ARGS_ADDRESS_AND_SIZEOF(MovPos));
13577 SaveEngineSnapshotBuffer(ARGS_ADDRESS_AND_SIZEOF(MovDir));
13578 SaveEngineSnapshotBuffer(ARGS_ADDRESS_AND_SIZEOF(MovDelay));
13579 SaveEngineSnapshotBuffer(ARGS_ADDRESS_AND_SIZEOF(ChangeDelay));
13580 SaveEngineSnapshotBuffer(ARGS_ADDRESS_AND_SIZEOF(ChangePage));
13581 SaveEngineSnapshotBuffer(ARGS_ADDRESS_AND_SIZEOF(CustomValue));
13582 SaveEngineSnapshotBuffer(ARGS_ADDRESS_AND_SIZEOF(Store));
13583 SaveEngineSnapshotBuffer(ARGS_ADDRESS_AND_SIZEOF(Store2));
13584 SaveEngineSnapshotBuffer(ARGS_ADDRESS_AND_SIZEOF(StorePlayer));
13585 SaveEngineSnapshotBuffer(ARGS_ADDRESS_AND_SIZEOF(Back));
13586 SaveEngineSnapshotBuffer(ARGS_ADDRESS_AND_SIZEOF(AmoebaNr));
13587 SaveEngineSnapshotBuffer(ARGS_ADDRESS_AND_SIZEOF(WasJustMoving));
13588 SaveEngineSnapshotBuffer(ARGS_ADDRESS_AND_SIZEOF(WasJustFalling));
13589 SaveEngineSnapshotBuffer(ARGS_ADDRESS_AND_SIZEOF(CheckCollision));
13590 SaveEngineSnapshotBuffer(ARGS_ADDRESS_AND_SIZEOF(CheckImpact));
13591 SaveEngineSnapshotBuffer(ARGS_ADDRESS_AND_SIZEOF(Stop));
13592 SaveEngineSnapshotBuffer(ARGS_ADDRESS_AND_SIZEOF(Pushed));
13594 SaveEngineSnapshotBuffer(ARGS_ADDRESS_AND_SIZEOF(ChangeCount));
13595 SaveEngineSnapshotBuffer(ARGS_ADDRESS_AND_SIZEOF(ChangeEvent));
13597 SaveEngineSnapshotBuffer(ARGS_ADDRESS_AND_SIZEOF(ExplodePhase));
13598 SaveEngineSnapshotBuffer(ARGS_ADDRESS_AND_SIZEOF(ExplodeDelay));
13599 SaveEngineSnapshotBuffer(ARGS_ADDRESS_AND_SIZEOF(ExplodeField));
13601 SaveEngineSnapshotBuffer(ARGS_ADDRESS_AND_SIZEOF(RunnerVisit));
13602 SaveEngineSnapshotBuffer(ARGS_ADDRESS_AND_SIZEOF(PlayerVisit));
13604 SaveEngineSnapshotBuffer(ARGS_ADDRESS_AND_SIZEOF(GfxFrame));
13605 SaveEngineSnapshotBuffer(ARGS_ADDRESS_AND_SIZEOF(GfxRandom));
13606 SaveEngineSnapshotBuffer(ARGS_ADDRESS_AND_SIZEOF(GfxElement));
13607 SaveEngineSnapshotBuffer(ARGS_ADDRESS_AND_SIZEOF(GfxAction));
13608 SaveEngineSnapshotBuffer(ARGS_ADDRESS_AND_SIZEOF(GfxDir));
13610 SaveEngineSnapshotBuffer(ARGS_ADDRESS_AND_SIZEOF(scroll_x));
13611 SaveEngineSnapshotBuffer(ARGS_ADDRESS_AND_SIZEOF(scroll_y));
13613 /* save level identification information */
13615 setString(&snapshot_level_identifier, leveldir_current->identifier);
13616 snapshot_level_nr = level_nr;
13619 ListNode *node = engine_snapshot_list;
13622 while (node != NULL)
13624 num_bytes += ((struct EngineSnapshotNodeInfo *)node->content)->size;
13629 printf("::: size of engine snapshot: %d bytes\n", num_bytes);
13633 static void LoadEngineSnapshotBuffer(struct EngineSnapshotNodeInfo *bi)
13635 memcpy(bi->buffer_orig, bi->buffer_copy, bi->size);
13638 void LoadEngineSnapshot()
13640 ListNode *node = engine_snapshot_list;
13642 if (engine_snapshot_list == NULL)
13645 while (node != NULL)
13647 LoadEngineSnapshotBuffer((struct EngineSnapshotNodeInfo *)node->content);
13652 /* restore special values from snapshot structure */
13654 LoadEngineSnapshotValues_RND();
13655 LoadEngineSnapshotValues_EM();
13658 boolean CheckEngineSnapshot()
13660 return (strEqual(snapshot_level_identifier, leveldir_current->identifier) &&
13661 snapshot_level_nr == level_nr);
13665 /* ---------- new game button stuff ---------------------------------------- */
13667 /* graphic position values for game buttons */
13668 #define GAME_BUTTON_XSIZE 30
13669 #define GAME_BUTTON_YSIZE 30
13670 #define GAME_BUTTON_XPOS 5
13671 #define GAME_BUTTON_YPOS 215
13672 #define SOUND_BUTTON_XPOS 5
13673 #define SOUND_BUTTON_YPOS (GAME_BUTTON_YPOS + GAME_BUTTON_YSIZE)
13675 #define GAME_BUTTON_STOP_XPOS (GAME_BUTTON_XPOS + 0 * GAME_BUTTON_XSIZE)
13676 #define GAME_BUTTON_PAUSE_XPOS (GAME_BUTTON_XPOS + 1 * GAME_BUTTON_XSIZE)
13677 #define GAME_BUTTON_PLAY_XPOS (GAME_BUTTON_XPOS + 2 * GAME_BUTTON_XSIZE)
13678 #define SOUND_BUTTON_MUSIC_XPOS (SOUND_BUTTON_XPOS + 0 * GAME_BUTTON_XSIZE)
13679 #define SOUND_BUTTON_LOOPS_XPOS (SOUND_BUTTON_XPOS + 1 * GAME_BUTTON_XSIZE)
13680 #define SOUND_BUTTON_SIMPLE_XPOS (SOUND_BUTTON_XPOS + 2 * GAME_BUTTON_XSIZE)
13687 } gamebutton_info[NUM_GAME_BUTTONS] =
13690 GAME_BUTTON_STOP_XPOS, GAME_BUTTON_YPOS,
13695 GAME_BUTTON_PAUSE_XPOS, GAME_BUTTON_YPOS,
13696 GAME_CTRL_ID_PAUSE,
13700 GAME_BUTTON_PLAY_XPOS, GAME_BUTTON_YPOS,
13705 SOUND_BUTTON_MUSIC_XPOS, SOUND_BUTTON_YPOS,
13706 SOUND_CTRL_ID_MUSIC,
13707 "background music on/off"
13710 SOUND_BUTTON_LOOPS_XPOS, SOUND_BUTTON_YPOS,
13711 SOUND_CTRL_ID_LOOPS,
13712 "sound loops on/off"
13715 SOUND_BUTTON_SIMPLE_XPOS, SOUND_BUTTON_YPOS,
13716 SOUND_CTRL_ID_SIMPLE,
13717 "normal sounds on/off"
13721 void CreateGameButtons()
13725 for (i = 0; i < NUM_GAME_BUTTONS; i++)
13727 Bitmap *gd_bitmap = graphic_info[IMG_GLOBAL_DOOR].bitmap;
13728 struct GadgetInfo *gi;
13731 unsigned long event_mask;
13732 int gd_xoffset, gd_yoffset;
13733 int gd_x1, gd_x2, gd_y1, gd_y2;
13736 gd_xoffset = gamebutton_info[i].x;
13737 gd_yoffset = gamebutton_info[i].y;
13738 gd_x1 = DOOR_GFX_PAGEX4 + gd_xoffset;
13739 gd_x2 = DOOR_GFX_PAGEX3 + gd_xoffset;
13741 if (id == GAME_CTRL_ID_STOP ||
13742 id == GAME_CTRL_ID_PAUSE ||
13743 id == GAME_CTRL_ID_PLAY)
13745 button_type = GD_TYPE_NORMAL_BUTTON;
13747 event_mask = GD_EVENT_RELEASED;
13748 gd_y1 = DOOR_GFX_PAGEY1 + gd_yoffset - GAME_BUTTON_YSIZE;
13749 gd_y2 = DOOR_GFX_PAGEY1 + gd_yoffset - GAME_BUTTON_YSIZE;
13753 button_type = GD_TYPE_CHECK_BUTTON;
13755 ((id == SOUND_CTRL_ID_MUSIC && setup.sound_music) ||
13756 (id == SOUND_CTRL_ID_LOOPS && setup.sound_loops) ||
13757 (id == SOUND_CTRL_ID_SIMPLE && setup.sound_simple) ? TRUE : FALSE);
13758 event_mask = GD_EVENT_PRESSED;
13759 gd_y1 = DOOR_GFX_PAGEY1 + gd_yoffset;
13760 gd_y2 = DOOR_GFX_PAGEY1 + gd_yoffset - GAME_BUTTON_YSIZE;
13763 gi = CreateGadget(GDI_CUSTOM_ID, id,
13764 GDI_INFO_TEXT, gamebutton_info[i].infotext,
13765 GDI_X, DX + gd_xoffset,
13766 GDI_Y, DY + gd_yoffset,
13767 GDI_WIDTH, GAME_BUTTON_XSIZE,
13768 GDI_HEIGHT, GAME_BUTTON_YSIZE,
13769 GDI_TYPE, button_type,
13770 GDI_STATE, GD_BUTTON_UNPRESSED,
13771 GDI_CHECKED, checked,
13772 GDI_DESIGN_UNPRESSED, gd_bitmap, gd_x1, gd_y1,
13773 GDI_DESIGN_PRESSED, gd_bitmap, gd_x2, gd_y1,
13774 GDI_ALT_DESIGN_UNPRESSED, gd_bitmap, gd_x1, gd_y2,
13775 GDI_ALT_DESIGN_PRESSED, gd_bitmap, gd_x2, gd_y2,
13776 GDI_EVENT_MASK, event_mask,
13777 GDI_CALLBACK_ACTION, HandleGameButtons,
13781 Error(ERR_EXIT, "cannot create gadget");
13783 game_gadget[id] = gi;
13787 void FreeGameButtons()
13791 for (i = 0; i < NUM_GAME_BUTTONS; i++)
13792 FreeGadget(game_gadget[i]);
13795 static void MapGameButtons()
13799 for (i = 0; i < NUM_GAME_BUTTONS; i++)
13800 MapGadget(game_gadget[i]);
13803 void UnmapGameButtons()
13807 for (i = 0; i < NUM_GAME_BUTTONS; i++)
13808 UnmapGadget(game_gadget[i]);
13811 static void HandleGameButtons(struct GadgetInfo *gi)
13813 int id = gi->custom_id;
13815 if (game_status != GAME_MODE_PLAYING)
13820 case GAME_CTRL_ID_STOP:
13824 RequestQuitGame(TRUE);
13827 case GAME_CTRL_ID_PAUSE:
13828 if (options.network)
13830 #if defined(NETWORK_AVALIABLE)
13832 SendToServer_ContinuePlaying();
13834 SendToServer_PausePlaying();
13838 TapeTogglePause(TAPE_TOGGLE_MANUAL);
13841 case GAME_CTRL_ID_PLAY:
13844 #if defined(NETWORK_AVALIABLE)
13845 if (options.network)
13846 SendToServer_ContinuePlaying();
13850 tape.pausing = FALSE;
13851 DrawVideoDisplay(VIDEO_STATE_PAUSE_OFF, 0);
13856 case SOUND_CTRL_ID_MUSIC:
13857 if (setup.sound_music)
13859 setup.sound_music = FALSE;
13862 else if (audio.music_available)
13864 setup.sound = setup.sound_music = TRUE;
13866 SetAudioMode(setup.sound);
13872 case SOUND_CTRL_ID_LOOPS:
13873 if (setup.sound_loops)
13874 setup.sound_loops = FALSE;
13875 else if (audio.loops_available)
13877 setup.sound = setup.sound_loops = TRUE;
13878 SetAudioMode(setup.sound);
13882 case SOUND_CTRL_ID_SIMPLE:
13883 if (setup.sound_simple)
13884 setup.sound_simple = FALSE;
13885 else if (audio.sound_available)
13887 setup.sound = setup.sound_simple = TRUE;
13888 SetAudioMode(setup.sound);