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)
88 #define PANEL_DEACTIVATED(p) ((p).x < 0 || (p).y < 0)
90 /* special positions in the game control window (relative to control window) */
91 #define XX_LEVEL1 (game.panel.level.x)
92 #define XX_LEVEL2 (game.panel.level.x - 1)
93 #define YY_LEVEL (game.panel.level.y)
94 #define XX_EMERALDS (game.panel.gems.x)
95 #define YY_EMERALDS (game.panel.gems.y)
96 #define XX_DYNAMITE (game.panel.inventory.x)
97 #define YY_DYNAMITE (game.panel.inventory.y)
98 #define XX_KEYS (game.panel.keys.x)
99 #define YY_KEYS (game.panel.keys.y)
100 #define XX_SCORE (game.panel.score.x)
101 #define YY_SCORE (game.panel.score.y)
102 #define XX_TIME1 (game.panel.time.x)
103 #define XX_TIME2 (game.panel.time.x + 1)
104 #define YY_TIME (game.panel.time.y)
106 /* special positions in the game control window (relative to main window) */
107 #define DX_LEVEL1 (DX + XX_LEVEL1)
108 #define DX_LEVEL2 (DX + XX_LEVEL2)
109 #define DY_LEVEL (DY + YY_LEVEL)
110 #define DX_EMERALDS (DX + XX_EMERALDS)
111 #define DY_EMERALDS (DY + YY_EMERALDS)
112 #define DX_DYNAMITE (DX + XX_DYNAMITE)
113 #define DY_DYNAMITE (DY + YY_DYNAMITE)
114 #define DX_KEYS (DX + XX_KEYS)
115 #define DY_KEYS (DY + YY_KEYS)
116 #define DX_SCORE (DX + XX_SCORE)
117 #define DY_SCORE (DY + YY_SCORE)
118 #define DX_TIME1 (DX + XX_TIME1)
119 #define DX_TIME2 (DX + XX_TIME2)
120 #define DY_TIME (DY + YY_TIME)
122 /* values for delayed check of falling and moving elements and for collision */
123 #define CHECK_DELAY_MOVING 3
124 #define CHECK_DELAY_FALLING CHECK_DELAY_MOVING
125 #define CHECK_DELAY_COLLISION 2
126 #define CHECK_DELAY_IMPACT CHECK_DELAY_COLLISION
128 /* values for initial player move delay (initial delay counter value) */
129 #define INITIAL_MOVE_DELAY_OFF -1
130 #define INITIAL_MOVE_DELAY_ON 0
132 /* values for player movement speed (which is in fact a delay value) */
133 #define MOVE_DELAY_MIN_SPEED 32
134 #define MOVE_DELAY_NORMAL_SPEED 8
135 #define MOVE_DELAY_HIGH_SPEED 4
136 #define MOVE_DELAY_MAX_SPEED 1
138 #define DOUBLE_MOVE_DELAY(x) (x = (x < MOVE_DELAY_MIN_SPEED ? x * 2 : x))
139 #define HALVE_MOVE_DELAY(x) (x = (x > MOVE_DELAY_MAX_SPEED ? x / 2 : x))
141 #define DOUBLE_PLAYER_SPEED(p) (HALVE_MOVE_DELAY( (p)->move_delay_value))
142 #define HALVE_PLAYER_SPEED(p) (DOUBLE_MOVE_DELAY((p)->move_delay_value))
144 /* values for other actions */
145 #define MOVE_STEPSIZE_NORMAL (TILEX / MOVE_DELAY_NORMAL_SPEED)
146 #define MOVE_STEPSIZE_MIN (1)
147 #define MOVE_STEPSIZE_MAX (TILEX)
149 #define GET_DX_FROM_DIR(d) ((d) == MV_LEFT ? -1 : (d) == MV_RIGHT ? 1 : 0)
150 #define GET_DY_FROM_DIR(d) ((d) == MV_UP ? -1 : (d) == MV_DOWN ? 1 : 0)
152 #define INIT_GFX_RANDOM() (GetSimpleRandom(1000000))
154 #define GET_NEW_PUSH_DELAY(e) ( (element_info[e].push_delay_fixed) + \
155 RND(element_info[e].push_delay_random))
156 #define GET_NEW_DROP_DELAY(e) ( (element_info[e].drop_delay_fixed) + \
157 RND(element_info[e].drop_delay_random))
158 #define GET_NEW_MOVE_DELAY(e) ( (element_info[e].move_delay_fixed) + \
159 RND(element_info[e].move_delay_random))
160 #define GET_MAX_MOVE_DELAY(e) ( (element_info[e].move_delay_fixed) + \
161 (element_info[e].move_delay_random))
162 #define GET_NEW_CE_VALUE(e) ( (element_info[e].ce_value_fixed_initial) +\
163 RND(element_info[e].ce_value_random_initial))
164 #define GET_CE_SCORE(e) ( (element_info[e].collect_score))
165 #define GET_CHANGE_DELAY(c) ( ((c)->delay_fixed * (c)->delay_frames) + \
166 RND((c)->delay_random * (c)->delay_frames))
167 #define GET_CE_DELAY_VALUE(c) ( ((c)->delay_fixed) + \
168 RND((c)->delay_random))
171 #define GET_VALID_RUNTIME_ELEMENT(e) \
172 ((e) >= NUM_RUNTIME_ELEMENTS ? EL_UNKNOWN : (e))
174 #define RESOLVED_REFERENCE_ELEMENT(be, e) \
175 ((be) + (e) - EL_SELF < EL_CUSTOM_START ? EL_CUSTOM_START : \
176 (be) + (e) - EL_SELF > EL_CUSTOM_END ? EL_CUSTOM_END : \
177 (be) + (e) - EL_SELF)
179 #define GET_TARGET_ELEMENT(be, e, ch, cv, cs) \
180 ((e) == EL_TRIGGER_PLAYER ? (ch)->actual_trigger_player : \
181 (e) == EL_TRIGGER_ELEMENT ? (ch)->actual_trigger_element : \
182 (e) == EL_TRIGGER_CE_VALUE ? (ch)->actual_trigger_ce_value : \
183 (e) == EL_TRIGGER_CE_SCORE ? (ch)->actual_trigger_ce_score : \
184 (e) == EL_CURRENT_CE_VALUE ? (cv) : \
185 (e) == EL_CURRENT_CE_SCORE ? (cs) : \
186 (e) >= EL_PREV_CE_8 && (e) <= EL_NEXT_CE_8 ? \
187 RESOLVED_REFERENCE_ELEMENT(be, e) : \
190 #define CAN_GROW_INTO(e) \
191 ((e) == EL_SAND || (IS_DIGGABLE(e) && level.grow_into_diggable))
193 #define ELEMENT_CAN_ENTER_FIELD_BASE_X(x, y, condition) \
194 (IN_LEV_FIELD(x, y) && (IS_FREE(x, y) || \
197 #define ELEMENT_CAN_ENTER_FIELD_BASE_2(e, x, y, condition) \
198 (IN_LEV_FIELD(x, y) && (IS_FREE(x, y) || \
199 (CAN_MOVE_INTO_ACID(e) && \
200 Feld[x][y] == EL_ACID) || \
203 #define ELEMENT_CAN_ENTER_FIELD_BASE_3(e, x, y, condition) \
204 (IN_LEV_FIELD(x, y) && (IS_FREE_OR_PLAYER(x, y) || \
205 (CAN_MOVE_INTO_ACID(e) && \
206 Feld[x][y] == EL_ACID) || \
209 #define ELEMENT_CAN_ENTER_FIELD_BASE_4(e, x, y, condition) \
210 (IN_LEV_FIELD(x, y) && (IS_FREE(x, y) || \
212 (CAN_MOVE_INTO_ACID(e) && \
213 Feld[x][y] == EL_ACID) || \
214 (DONT_COLLIDE_WITH(e) && \
216 !PLAYER_ENEMY_PROTECTED(x, y))))
218 #define ELEMENT_CAN_ENTER_FIELD(e, x, y) \
219 ELEMENT_CAN_ENTER_FIELD_BASE_4(e, x, y, 0)
221 #define SATELLITE_CAN_ENTER_FIELD(x, y) \
222 ELEMENT_CAN_ENTER_FIELD_BASE_2(EL_SATELLITE, x, y, 0)
224 #define ANDROID_CAN_ENTER_FIELD(e, x, y) \
225 ELEMENT_CAN_ENTER_FIELD_BASE_2(e, x, y, Feld[x][y] == EL_EMC_PLANT)
227 #define ANDROID_CAN_CLONE_FIELD(x, y) \
228 (IN_LEV_FIELD(x, y) && (CAN_BE_CLONED_BY_ANDROID(Feld[x][y]) || \
229 CAN_BE_CLONED_BY_ANDROID(EL_TRIGGER_ELEMENT)))
231 #define ENEMY_CAN_ENTER_FIELD(e, x, y) \
232 ELEMENT_CAN_ENTER_FIELD_BASE_2(e, x, y, 0)
234 #define YAMYAM_CAN_ENTER_FIELD(e, x, y) \
235 ELEMENT_CAN_ENTER_FIELD_BASE_3(e, x, y, Feld[x][y] == EL_DIAMOND)
237 #define DARK_YAMYAM_CAN_ENTER_FIELD(e, x, y) \
238 ELEMENT_CAN_ENTER_FIELD_BASE_3(e, x,y, IS_FOOD_DARK_YAMYAM(Feld[x][y]))
240 #define PACMAN_CAN_ENTER_FIELD(e, x, y) \
241 ELEMENT_CAN_ENTER_FIELD_BASE_3(e, x, y, IS_AMOEBOID(Feld[x][y]))
243 #define PIG_CAN_ENTER_FIELD(e, x, y) \
244 ELEMENT_CAN_ENTER_FIELD_BASE_2(e, x, y, IS_FOOD_PIG(Feld[x][y]))
246 #define PENGUIN_CAN_ENTER_FIELD(e, x, y) \
247 ELEMENT_CAN_ENTER_FIELD_BASE_2(e, x, y, (Feld[x][y] == EL_EXIT_OPEN || \
248 Feld[x][y] == EL_STEEL_EXIT_OPEN || \
249 IS_FOOD_PENGUIN(Feld[x][y])))
250 #define DRAGON_CAN_ENTER_FIELD(e, x, y) \
251 ELEMENT_CAN_ENTER_FIELD_BASE_2(e, x, y, 0)
253 #define MOLE_CAN_ENTER_FIELD(e, x, y, condition) \
254 ELEMENT_CAN_ENTER_FIELD_BASE_2(e, x, y, (condition))
256 #define SPRING_CAN_ENTER_FIELD(e, x, y) \
257 ELEMENT_CAN_ENTER_FIELD_BASE_2(e, x, y, 0)
259 #define SPRING_CAN_BUMP_FROM_FIELD(x, y) \
260 (IN_LEV_FIELD(x, y) && (Feld[x][y] == EL_EMC_SPRING_BUMPER || \
261 Feld[x][y] == EL_EMC_SPRING_BUMPER_ACTIVE))
263 #define MOVE_ENTER_EL(e) (element_info[e].move_enter_element)
265 #define CE_ENTER_FIELD_COND(e, x, y) \
266 (!IS_PLAYER(x, y) && \
267 IS_EQUAL_OR_IN_GROUP(Feld[x][y], MOVE_ENTER_EL(e)))
269 #define CUSTOM_ELEMENT_CAN_ENTER_FIELD(e, x, y) \
270 ELEMENT_CAN_ENTER_FIELD_BASE_4(e, x, y, CE_ENTER_FIELD_COND(e, x, y))
272 #define IN_LEV_FIELD_AND_IS_FREE(x, y) (IN_LEV_FIELD(x, y) && IS_FREE(x, y))
273 #define IN_LEV_FIELD_AND_NOT_FREE(x, y) (IN_LEV_FIELD(x, y) && !IS_FREE(x, y))
275 #define ACCESS_FROM(e, d) (element_info[e].access_direction &(d))
276 #define IS_WALKABLE_FROM(e, d) (IS_WALKABLE(e) && ACCESS_FROM(e, d))
277 #define IS_PASSABLE_FROM(e, d) (IS_PASSABLE(e) && ACCESS_FROM(e, d))
278 #define IS_ACCESSIBLE_FROM(e, d) (IS_ACCESSIBLE(e) && ACCESS_FROM(e, d))
280 /* game button identifiers */
281 #define GAME_CTRL_ID_STOP 0
282 #define GAME_CTRL_ID_PAUSE 1
283 #define GAME_CTRL_ID_PLAY 2
284 #define SOUND_CTRL_ID_MUSIC 3
285 #define SOUND_CTRL_ID_LOOPS 4
286 #define SOUND_CTRL_ID_SIMPLE 5
288 #define NUM_GAME_BUTTONS 6
291 /* forward declaration for internal use */
293 static void CreateField(int, int, int);
295 static void SetPlayerWaiting(struct PlayerInfo *, boolean);
296 static void AdvanceFrameAndPlayerCounters(int);
298 static boolean MovePlayerOneStep(struct PlayerInfo *, int, int, int, int);
299 static boolean MovePlayer(struct PlayerInfo *, int, int);
300 static void ScrollPlayer(struct PlayerInfo *, int);
301 static void ScrollScreen(struct PlayerInfo *, int);
303 int DigField(struct PlayerInfo *, int, int, int, int, int, int, int);
305 static void InitBeltMovement(void);
306 static void CloseAllOpenTimegates(void);
307 static void CheckGravityMovement(struct PlayerInfo *);
308 static void CheckGravityMovementWhenNotMoving(struct PlayerInfo *);
309 static void KillPlayerUnlessEnemyProtected(int, int);
310 static void KillPlayerUnlessExplosionProtected(int, int);
312 static void TestIfPlayerTouchesCustomElement(int, int);
313 static void TestIfElementTouchesCustomElement(int, int);
314 static void TestIfElementHitsCustomElement(int, int, int);
316 static void TestIfElementSmashesCustomElement(int, int, int);
319 static void HandleElementChange(int, int, int);
320 static void ExecuteCustomElementAction(int, int, int, int);
321 static boolean ChangeElement(int, int, int, int);
323 static boolean CheckTriggeredElementChangeExt(int, int, int, int, int,int,int);
324 #define CheckTriggeredElementChange(x, y, e, ev) \
325 CheckTriggeredElementChangeExt(x,y,e,ev, CH_PLAYER_ANY,CH_SIDE_ANY, -1)
326 #define CheckTriggeredElementChangeByPlayer(x, y, e, ev, p, s) \
327 CheckTriggeredElementChangeExt(x, y, e, ev, p, s, -1)
328 #define CheckTriggeredElementChangeBySide(x, y, e, ev, s) \
329 CheckTriggeredElementChangeExt(x, y, e, ev, CH_PLAYER_ANY, s, -1)
330 #define CheckTriggeredElementChangeByPage(x, y, e, ev, p) \
331 CheckTriggeredElementChangeExt(x,y,e,ev, CH_PLAYER_ANY, CH_SIDE_ANY, p)
333 static boolean CheckElementChangeExt(int, int, int, int, int, int, int);
334 #define CheckElementChange(x, y, e, te, ev) \
335 CheckElementChangeExt(x, y, e, te, ev, CH_PLAYER_ANY, CH_SIDE_ANY)
336 #define CheckElementChangeByPlayer(x, y, e, ev, p, s) \
337 CheckElementChangeExt(x, y, e, EL_EMPTY, ev, p, s)
338 #define CheckElementChangeBySide(x, y, e, te, ev, s) \
339 CheckElementChangeExt(x, y, e, te, ev, CH_PLAYER_ANY, s)
341 static void PlayLevelSound(int, int, int);
342 static void PlayLevelSoundNearest(int, int, int);
343 static void PlayLevelSoundAction(int, int, int);
344 static void PlayLevelSoundElementAction(int, int, int, int);
345 static void PlayLevelSoundElementActionIfLoop(int, int, int, int);
346 static void PlayLevelSoundActionIfLoop(int, int, int);
347 static void StopLevelSoundActionIfLoop(int, int, int);
348 static void PlayLevelMusic();
350 static void MapGameButtons();
351 static void HandleGameButtons(struct GadgetInfo *);
353 int AmoebeNachbarNr(int, int);
354 void AmoebeUmwandeln(int, int);
355 void ContinueMoving(int, int);
357 void InitMovDir(int, int);
358 void InitAmoebaNr(int, int);
359 int NewHiScore(void);
361 void TestIfGoodThingHitsBadThing(int, int, int);
362 void TestIfBadThingHitsGoodThing(int, int, int);
363 void TestIfPlayerTouchesBadThing(int, int);
364 void TestIfPlayerRunsIntoBadThing(int, int, int);
365 void TestIfBadThingTouchesPlayer(int, int);
366 void TestIfBadThingRunsIntoPlayer(int, int, int);
367 void TestIfFriendTouchesBadThing(int, int);
368 void TestIfBadThingTouchesFriend(int, int);
369 void TestIfBadThingTouchesOtherBadThing(int, int);
371 void KillPlayer(struct PlayerInfo *);
372 void BuryPlayer(struct PlayerInfo *);
373 void RemovePlayer(struct PlayerInfo *);
375 boolean SnapField(struct PlayerInfo *, int, int);
376 boolean DropElement(struct PlayerInfo *);
378 static int getInvisibleActiveFromInvisibleElement(int);
379 static int getInvisibleFromInvisibleActiveElement(int);
381 static struct GadgetInfo *game_gadget[NUM_GAME_BUTTONS];
383 /* for detection of endless loops, caused by custom element programming */
384 /* (using "MAX_PLAYFIELD_WIDTH" here is just a rough approximation...) */
385 #define MAX_ELEMENT_CHANGE_RECURSION_DEPTH (MAX_PLAYFIELD_WIDTH)
387 #define RECURSION_LOOP_DETECTION_START(e, rc) \
389 if (recursion_loop_detected) \
392 if (recursion_loop_depth > MAX_ELEMENT_CHANGE_RECURSION_DEPTH) \
394 recursion_loop_detected = TRUE; \
395 recursion_loop_element = (e); \
398 recursion_loop_depth++; \
401 #define RECURSION_LOOP_DETECTION_END() \
403 recursion_loop_depth--; \
406 static int recursion_loop_depth;
407 static boolean recursion_loop_detected;
408 static boolean recursion_loop_element;
411 /* ------------------------------------------------------------------------- */
412 /* definition of elements that automatically change to other elements after */
413 /* a specified time, eventually calling a function when changing */
414 /* ------------------------------------------------------------------------- */
416 /* forward declaration for changer functions */
417 static void InitBuggyBase(int, int);
418 static void WarnBuggyBase(int, int);
420 static void InitTrap(int, int);
421 static void ActivateTrap(int, int);
422 static void ChangeActiveTrap(int, int);
424 static void InitRobotWheel(int, int);
425 static void RunRobotWheel(int, int);
426 static void StopRobotWheel(int, int);
428 static void InitTimegateWheel(int, int);
429 static void RunTimegateWheel(int, int);
431 static void InitMagicBallDelay(int, int);
432 static void ActivateMagicBall(int, int);
434 struct ChangingElementInfo
439 void (*pre_change_function)(int x, int y);
440 void (*change_function)(int x, int y);
441 void (*post_change_function)(int x, int y);
444 static struct ChangingElementInfo change_delay_list[] =
479 EL_STEEL_EXIT_OPENING,
487 EL_STEEL_EXIT_CLOSING,
488 EL_STEEL_EXIT_CLOSED,
511 EL_SWITCHGATE_OPENING,
519 EL_SWITCHGATE_CLOSING,
520 EL_SWITCHGATE_CLOSED,
552 EL_ACID_SPLASH_RIGHT,
561 EL_SP_BUGGY_BASE_ACTIVATING,
568 EL_SP_BUGGY_BASE_ACTIVATING,
569 EL_SP_BUGGY_BASE_ACTIVE,
576 EL_SP_BUGGY_BASE_ACTIVE,
600 EL_ROBOT_WHEEL_ACTIVE,
608 EL_TIMEGATE_SWITCH_ACTIVE,
616 EL_EMC_MAGIC_BALL_ACTIVE,
617 EL_EMC_MAGIC_BALL_ACTIVE,
624 EL_EMC_SPRING_BUMPER_ACTIVE,
625 EL_EMC_SPRING_BUMPER,
632 EL_DIAGONAL_SHRINKING,
661 int push_delay_fixed, push_delay_random;
666 { EL_BALLOON, 0, 0 },
668 { EL_SOKOBAN_OBJECT, 2, 0 },
669 { EL_SOKOBAN_FIELD_FULL, 2, 0 },
670 { EL_SATELLITE, 2, 0 },
671 { EL_SP_DISK_YELLOW, 2, 0 },
673 { EL_UNDEFINED, 0, 0 },
681 move_stepsize_list[] =
683 { EL_AMOEBA_DROP, 2 },
684 { EL_AMOEBA_DROPPING, 2 },
685 { EL_QUICKSAND_FILLING, 1 },
686 { EL_QUICKSAND_EMPTYING, 1 },
687 { EL_MAGIC_WALL_FILLING, 2 },
688 { EL_BD_MAGIC_WALL_FILLING, 2 },
689 { EL_MAGIC_WALL_EMPTYING, 2 },
690 { EL_BD_MAGIC_WALL_EMPTYING, 2 },
700 collect_count_list[] =
703 { EL_BD_DIAMOND, 1 },
704 { EL_EMERALD_YELLOW, 1 },
705 { EL_EMERALD_RED, 1 },
706 { EL_EMERALD_PURPLE, 1 },
708 { EL_SP_INFOTRON, 1 },
720 access_direction_list[] =
722 { EL_TUBE_ANY, MV_LEFT | MV_RIGHT | MV_UP | MV_DOWN },
723 { EL_TUBE_VERTICAL, MV_UP | MV_DOWN },
724 { EL_TUBE_HORIZONTAL, MV_LEFT | MV_RIGHT },
725 { EL_TUBE_VERTICAL_LEFT, MV_LEFT | MV_UP | MV_DOWN },
726 { EL_TUBE_VERTICAL_RIGHT, MV_RIGHT | MV_UP | MV_DOWN },
727 { EL_TUBE_HORIZONTAL_UP, MV_LEFT | MV_RIGHT | MV_UP },
728 { EL_TUBE_HORIZONTAL_DOWN, MV_LEFT | MV_RIGHT | MV_DOWN },
729 { EL_TUBE_LEFT_UP, MV_LEFT | MV_UP },
730 { EL_TUBE_LEFT_DOWN, MV_LEFT | MV_DOWN },
731 { EL_TUBE_RIGHT_UP, MV_RIGHT | MV_UP },
732 { EL_TUBE_RIGHT_DOWN, MV_RIGHT | MV_DOWN },
734 { EL_SP_PORT_LEFT, MV_RIGHT },
735 { EL_SP_PORT_RIGHT, MV_LEFT },
736 { EL_SP_PORT_UP, MV_DOWN },
737 { EL_SP_PORT_DOWN, MV_UP },
738 { EL_SP_PORT_HORIZONTAL, MV_LEFT | MV_RIGHT },
739 { EL_SP_PORT_VERTICAL, MV_UP | MV_DOWN },
740 { EL_SP_PORT_ANY, MV_LEFT | MV_RIGHT | MV_UP | MV_DOWN },
741 { EL_SP_GRAVITY_PORT_LEFT, MV_RIGHT },
742 { EL_SP_GRAVITY_PORT_RIGHT, MV_LEFT },
743 { EL_SP_GRAVITY_PORT_UP, MV_DOWN },
744 { EL_SP_GRAVITY_PORT_DOWN, MV_UP },
745 { EL_SP_GRAVITY_ON_PORT_LEFT, MV_RIGHT },
746 { EL_SP_GRAVITY_ON_PORT_RIGHT, MV_LEFT },
747 { EL_SP_GRAVITY_ON_PORT_UP, MV_DOWN },
748 { EL_SP_GRAVITY_ON_PORT_DOWN, MV_UP },
749 { EL_SP_GRAVITY_OFF_PORT_LEFT, MV_RIGHT },
750 { EL_SP_GRAVITY_OFF_PORT_RIGHT, MV_LEFT },
751 { EL_SP_GRAVITY_OFF_PORT_UP, MV_DOWN },
752 { EL_SP_GRAVITY_OFF_PORT_DOWN, MV_UP },
754 { EL_UNDEFINED, MV_NONE }
757 static boolean trigger_events[MAX_NUM_ELEMENTS][NUM_CHANGE_EVENTS];
759 #define IS_AUTO_CHANGING(e) (element_info[e].has_change_event[CE_DELAY])
760 #define IS_JUST_CHANGING(x, y) (ChangeDelay[x][y] != 0)
761 #define IS_CHANGING(x, y) (IS_AUTO_CHANGING(Feld[x][y]) || \
762 IS_JUST_CHANGING(x, y))
764 #define CE_PAGE(e, ce) (element_info[e].event_page[ce])
766 /* static variables for playfield scan mode (scanning forward or backward) */
767 static int playfield_scan_start_x = 0;
768 static int playfield_scan_start_y = 0;
769 static int playfield_scan_delta_x = 1;
770 static int playfield_scan_delta_y = 1;
772 #define SCAN_PLAYFIELD(x, y) for ((y) = playfield_scan_start_y; \
773 (y) >= 0 && (y) <= lev_fieldy - 1; \
774 (y) += playfield_scan_delta_y) \
775 for ((x) = playfield_scan_start_x; \
776 (x) >= 0 && (x) <= lev_fieldx - 1; \
777 (x) += playfield_scan_delta_x) \
780 void DEBUG_SetMaximumDynamite()
784 for (i = 0; i < MAX_INVENTORY_SIZE; i++)
785 if (local_player->inventory_size < MAX_INVENTORY_SIZE)
786 local_player->inventory_element[local_player->inventory_size++] =
791 static void InitPlayfieldScanModeVars()
793 if (game.use_reverse_scan_direction)
795 playfield_scan_start_x = lev_fieldx - 1;
796 playfield_scan_start_y = lev_fieldy - 1;
798 playfield_scan_delta_x = -1;
799 playfield_scan_delta_y = -1;
803 playfield_scan_start_x = 0;
804 playfield_scan_start_y = 0;
806 playfield_scan_delta_x = 1;
807 playfield_scan_delta_y = 1;
811 static void InitPlayfieldScanMode(int mode)
813 game.use_reverse_scan_direction =
814 (mode == CA_ARG_SCAN_MODE_REVERSE ? TRUE : FALSE);
816 InitPlayfieldScanModeVars();
819 static int get_move_delay_from_stepsize(int move_stepsize)
822 MIN(MAX(MOVE_STEPSIZE_MIN, move_stepsize), MOVE_STEPSIZE_MAX);
824 /* make sure that stepsize value is always a power of 2 */
825 move_stepsize = (1 << log_2(move_stepsize));
827 return TILEX / move_stepsize;
830 static void SetPlayerMoveSpeed(struct PlayerInfo *player, int move_stepsize,
833 int player_nr = player->index_nr;
834 int move_delay = get_move_delay_from_stepsize(move_stepsize);
835 boolean cannot_move = (move_stepsize == STEPSIZE_NOT_MOVING ? TRUE : FALSE);
837 /* do no immediately change move delay -- the player might just be moving */
838 player->move_delay_value_next = move_delay;
840 /* information if player can move must be set separately */
841 player->cannot_move = cannot_move;
845 player->move_delay = game.initial_move_delay[player_nr];
846 player->move_delay_value = game.initial_move_delay_value[player_nr];
848 player->move_delay_value_next = -1;
850 player->move_delay_reset_counter = 0;
854 void GetPlayerConfig()
856 if (!audio.sound_available)
857 setup.sound_simple = FALSE;
859 if (!audio.loops_available)
860 setup.sound_loops = FALSE;
862 if (!audio.music_available)
863 setup.sound_music = FALSE;
865 if (!video.fullscreen_available)
866 setup.fullscreen = FALSE;
868 setup.sound = (setup.sound_simple || setup.sound_loops || setup.sound_music);
870 SetAudioMode(setup.sound);
874 static int getBeltNrFromBeltElement(int element)
876 return (element < EL_CONVEYOR_BELT_2_LEFT ? 0 :
877 element < EL_CONVEYOR_BELT_3_LEFT ? 1 :
878 element < EL_CONVEYOR_BELT_4_LEFT ? 2 : 3);
881 static int getBeltNrFromBeltActiveElement(int element)
883 return (element < EL_CONVEYOR_BELT_2_LEFT_ACTIVE ? 0 :
884 element < EL_CONVEYOR_BELT_3_LEFT_ACTIVE ? 1 :
885 element < EL_CONVEYOR_BELT_4_LEFT_ACTIVE ? 2 : 3);
888 static int getBeltNrFromBeltSwitchElement(int element)
890 return (element < EL_CONVEYOR_BELT_2_SWITCH_LEFT ? 0 :
891 element < EL_CONVEYOR_BELT_3_SWITCH_LEFT ? 1 :
892 element < EL_CONVEYOR_BELT_4_SWITCH_LEFT ? 2 : 3);
895 static int getBeltDirNrFromBeltSwitchElement(int element)
897 static int belt_base_element[4] =
899 EL_CONVEYOR_BELT_1_SWITCH_LEFT,
900 EL_CONVEYOR_BELT_2_SWITCH_LEFT,
901 EL_CONVEYOR_BELT_3_SWITCH_LEFT,
902 EL_CONVEYOR_BELT_4_SWITCH_LEFT
905 int belt_nr = getBeltNrFromBeltSwitchElement(element);
906 int belt_dir_nr = element - belt_base_element[belt_nr];
908 return (belt_dir_nr % 3);
911 static int getBeltDirFromBeltSwitchElement(int element)
913 static int belt_move_dir[3] =
920 int belt_dir_nr = getBeltDirNrFromBeltSwitchElement(element);
922 return belt_move_dir[belt_dir_nr];
925 static int get_element_from_group_element(int element)
927 if (IS_GROUP_ELEMENT(element))
929 struct ElementGroupInfo *group = element_info[element].group;
930 int last_anim_random_frame = gfx.anim_random_frame;
933 if (group->choice_mode == ANIM_RANDOM)
934 gfx.anim_random_frame = RND(group->num_elements_resolved);
936 element_pos = getAnimationFrame(group->num_elements_resolved, 1,
937 group->choice_mode, 0,
940 if (group->choice_mode == ANIM_RANDOM)
941 gfx.anim_random_frame = last_anim_random_frame;
945 element = group->element_resolved[element_pos];
951 static void InitPlayerField(int x, int y, int element, boolean init_game)
953 if (element == EL_SP_MURPHY)
957 if (stored_player[0].present)
959 Feld[x][y] = EL_SP_MURPHY_CLONE;
965 stored_player[0].use_murphy = TRUE;
967 if (!level.use_artwork_element[0])
968 stored_player[0].artwork_element = EL_SP_MURPHY;
971 Feld[x][y] = EL_PLAYER_1;
977 struct PlayerInfo *player = &stored_player[Feld[x][y] - EL_PLAYER_1];
978 int jx = player->jx, jy = player->jy;
980 player->present = TRUE;
982 player->block_last_field = (element == EL_SP_MURPHY ?
983 level.sp_block_last_field :
984 level.block_last_field);
986 /* ---------- initialize player's last field block delay --------------- */
988 /* always start with reliable default value (no adjustment needed) */
989 player->block_delay_adjustment = 0;
991 /* special case 1: in Supaplex, Murphy blocks last field one more frame */
992 if (player->block_last_field && element == EL_SP_MURPHY)
993 player->block_delay_adjustment = 1;
995 /* special case 2: in game engines before 3.1.1, blocking was different */
996 if (game.use_block_last_field_bug)
997 player->block_delay_adjustment = (player->block_last_field ? -1 : 1);
999 if (!options.network || player->connected)
1001 player->active = TRUE;
1003 /* remove potentially duplicate players */
1004 if (StorePlayer[jx][jy] == Feld[x][y])
1005 StorePlayer[jx][jy] = 0;
1007 StorePlayer[x][y] = Feld[x][y];
1011 printf("Player %d activated.\n", player->element_nr);
1012 printf("[Local player is %d and currently %s.]\n",
1013 local_player->element_nr,
1014 local_player->active ? "active" : "not active");
1018 Feld[x][y] = EL_EMPTY;
1020 player->jx = player->last_jx = x;
1021 player->jy = player->last_jy = y;
1025 static void InitField(int x, int y, boolean init_game)
1027 int element = Feld[x][y];
1036 InitPlayerField(x, y, element, init_game);
1039 case EL_SOKOBAN_FIELD_PLAYER:
1040 element = Feld[x][y] = EL_PLAYER_1;
1041 InitField(x, y, init_game);
1043 element = Feld[x][y] = EL_SOKOBAN_FIELD_EMPTY;
1044 InitField(x, y, init_game);
1047 case EL_SOKOBAN_FIELD_EMPTY:
1048 local_player->sokobanfields_still_needed++;
1052 if (x < lev_fieldx-1 && Feld[x+1][y] == EL_ACID)
1053 Feld[x][y] = EL_ACID_POOL_TOPLEFT;
1054 else if (x > 0 && Feld[x-1][y] == EL_ACID)
1055 Feld[x][y] = EL_ACID_POOL_TOPRIGHT;
1056 else if (y > 0 && Feld[x][y-1] == EL_ACID_POOL_TOPLEFT)
1057 Feld[x][y] = EL_ACID_POOL_BOTTOMLEFT;
1058 else if (y > 0 && Feld[x][y-1] == EL_ACID)
1059 Feld[x][y] = EL_ACID_POOL_BOTTOM;
1060 else if (y > 0 && Feld[x][y-1] == EL_ACID_POOL_TOPRIGHT)
1061 Feld[x][y] = EL_ACID_POOL_BOTTOMRIGHT;
1070 case EL_SPACESHIP_RIGHT:
1071 case EL_SPACESHIP_UP:
1072 case EL_SPACESHIP_LEFT:
1073 case EL_SPACESHIP_DOWN:
1074 case EL_BD_BUTTERFLY:
1075 case EL_BD_BUTTERFLY_RIGHT:
1076 case EL_BD_BUTTERFLY_UP:
1077 case EL_BD_BUTTERFLY_LEFT:
1078 case EL_BD_BUTTERFLY_DOWN:
1080 case EL_BD_FIREFLY_RIGHT:
1081 case EL_BD_FIREFLY_UP:
1082 case EL_BD_FIREFLY_LEFT:
1083 case EL_BD_FIREFLY_DOWN:
1084 case EL_PACMAN_RIGHT:
1086 case EL_PACMAN_LEFT:
1087 case EL_PACMAN_DOWN:
1089 case EL_YAMYAM_LEFT:
1090 case EL_YAMYAM_RIGHT:
1092 case EL_YAMYAM_DOWN:
1093 case EL_DARK_YAMYAM:
1096 case EL_SP_SNIKSNAK:
1097 case EL_SP_ELECTRON:
1106 case EL_AMOEBA_FULL:
1111 case EL_AMOEBA_DROP:
1112 if (y == lev_fieldy - 1)
1114 Feld[x][y] = EL_AMOEBA_GROWING;
1115 Store[x][y] = EL_AMOEBA_WET;
1119 case EL_DYNAMITE_ACTIVE:
1120 case EL_SP_DISK_RED_ACTIVE:
1121 case EL_DYNABOMB_PLAYER_1_ACTIVE:
1122 case EL_DYNABOMB_PLAYER_2_ACTIVE:
1123 case EL_DYNABOMB_PLAYER_3_ACTIVE:
1124 case EL_DYNABOMB_PLAYER_4_ACTIVE:
1125 MovDelay[x][y] = 96;
1128 case EL_EM_DYNAMITE_ACTIVE:
1129 MovDelay[x][y] = 32;
1133 local_player->lights_still_needed++;
1137 local_player->friends_still_needed++;
1142 GfxDir[x][y] = MovDir[x][y] = 1 << RND(4);
1145 case EL_CONVEYOR_BELT_1_SWITCH_LEFT:
1146 case EL_CONVEYOR_BELT_1_SWITCH_MIDDLE:
1147 case EL_CONVEYOR_BELT_1_SWITCH_RIGHT:
1148 case EL_CONVEYOR_BELT_2_SWITCH_LEFT:
1149 case EL_CONVEYOR_BELT_2_SWITCH_MIDDLE:
1150 case EL_CONVEYOR_BELT_2_SWITCH_RIGHT:
1151 case EL_CONVEYOR_BELT_3_SWITCH_LEFT:
1152 case EL_CONVEYOR_BELT_3_SWITCH_MIDDLE:
1153 case EL_CONVEYOR_BELT_3_SWITCH_RIGHT:
1154 case EL_CONVEYOR_BELT_4_SWITCH_LEFT:
1155 case EL_CONVEYOR_BELT_4_SWITCH_MIDDLE:
1156 case EL_CONVEYOR_BELT_4_SWITCH_RIGHT:
1159 int belt_nr = getBeltNrFromBeltSwitchElement(Feld[x][y]);
1160 int belt_dir = getBeltDirFromBeltSwitchElement(Feld[x][y]);
1161 int belt_dir_nr = getBeltDirNrFromBeltSwitchElement(Feld[x][y]);
1163 if (game.belt_dir_nr[belt_nr] == 3) /* initial value */
1165 game.belt_dir[belt_nr] = belt_dir;
1166 game.belt_dir_nr[belt_nr] = belt_dir_nr;
1168 else /* more than one switch -- set it like the first switch */
1170 Feld[x][y] = Feld[x][y] - belt_dir_nr + game.belt_dir_nr[belt_nr];
1175 #if !USE_BOTH_SWITCHGATE_SWITCHES
1176 case EL_SWITCHGATE_SWITCH_DOWN: /* always start with same switch pos */
1178 Feld[x][y] = EL_SWITCHGATE_SWITCH_UP;
1182 case EL_LIGHT_SWITCH_ACTIVE:
1184 game.light_time_left = level.time_light * FRAMES_PER_SECOND;
1187 case EL_INVISIBLE_STEELWALL:
1188 case EL_INVISIBLE_WALL:
1189 case EL_INVISIBLE_SAND:
1190 if (game.light_time_left > 0 ||
1191 game.lenses_time_left > 0)
1192 Feld[x][y] = getInvisibleActiveFromInvisibleElement(element);
1195 case EL_EMC_MAGIC_BALL:
1196 if (game.ball_state)
1197 Feld[x][y] = EL_EMC_MAGIC_BALL_ACTIVE;
1200 case EL_EMC_MAGIC_BALL_SWITCH:
1201 if (game.ball_state)
1202 Feld[x][y] = EL_EMC_MAGIC_BALL_SWITCH_ACTIVE;
1206 if (IS_CUSTOM_ELEMENT(element))
1208 if (CAN_MOVE(element))
1211 #if USE_NEW_CUSTOM_VALUE
1212 if (!element_info[element].use_last_ce_value || init_game)
1213 CustomValue[x][y] = GET_NEW_CE_VALUE(Feld[x][y]);
1216 else if (IS_GROUP_ELEMENT(element))
1218 Feld[x][y] = get_element_from_group_element(element);
1220 InitField(x, y, init_game);
1227 CheckTriggeredElementChange(x, y, element, CE_CREATION_OF_X);
1230 static inline void InitField_WithBug1(int x, int y, boolean init_game)
1232 InitField(x, y, init_game);
1234 /* not needed to call InitMovDir() -- already done by InitField()! */
1235 if (game.engine_version < VERSION_IDENT(3,1,0,0) &&
1236 CAN_MOVE(Feld[x][y]))
1240 static inline void InitField_WithBug2(int x, int y, boolean init_game)
1242 int old_element = Feld[x][y];
1244 InitField(x, y, init_game);
1246 /* not needed to call InitMovDir() -- already done by InitField()! */
1247 if (game.engine_version < VERSION_IDENT(3,1,0,0) &&
1248 CAN_MOVE(old_element) &&
1249 (old_element < EL_MOLE_LEFT || old_element > EL_MOLE_DOWN))
1252 /* this case is in fact a combination of not less than three bugs:
1253 first, it calls InitMovDir() for elements that can move, although this is
1254 already done by InitField(); then, it checks the element that was at this
1255 field _before_ the call to InitField() (which can change it); lastly, it
1256 was not called for "mole with direction" elements, which were treated as
1257 "cannot move" due to (fixed) wrong element initialization in "src/init.c"
1261 inline void DrawGameValue_Emeralds(int value)
1263 int xpos = (3 * 14 - 3 * getFontWidth(FONT_TEXT_2)) / 2;
1265 if (PANEL_DEACTIVATED(game.panel.gems))
1268 DrawText(DX_EMERALDS + xpos, DY_EMERALDS, int2str(value, 3), FONT_TEXT_2);
1271 inline void DrawGameValue_Dynamite(int value)
1273 int xpos = (3 * 14 - 3 * getFontWidth(FONT_TEXT_2)) / 2;
1275 if (PANEL_DEACTIVATED(game.panel.inventory))
1278 DrawText(DX_DYNAMITE + xpos, DY_DYNAMITE, int2str(value, 3), FONT_TEXT_2);
1281 inline void DrawGameValue_Keys(int key[MAX_NUM_KEYS])
1283 int base_key_graphic = EL_KEY_1;
1286 if (PANEL_DEACTIVATED(game.panel.keys))
1289 if (level.game_engine_type == GAME_ENGINE_TYPE_EM)
1290 base_key_graphic = EL_EM_KEY_1;
1292 /* currently only 4 of 8 possible keys are displayed */
1293 for (i = 0; i < STD_NUM_KEYS; i++)
1295 int x = XX_KEYS + i * MINI_TILEX;
1299 DrawMiniGraphicExt(drawto, DX + x,DY + y, el2edimg(base_key_graphic + i));
1301 BlitBitmap(graphic_info[IMG_GLOBAL_DOOR].bitmap, drawto,
1302 DOOR_GFX_PAGEX5 + x, y, MINI_TILEX, MINI_TILEY, DX + x,DY + y);
1306 inline void DrawGameValue_Score(int value)
1308 int xpos = (5 * 14 - 5 * getFontWidth(FONT_TEXT_2)) / 2;
1310 if (PANEL_DEACTIVATED(game.panel.score))
1313 DrawText(DX_SCORE + xpos, DY_SCORE, int2str(value, 5), FONT_TEXT_2);
1316 inline void DrawGameValue_Time(int value)
1318 int xpos3 = (3 * 14 - 3 * getFontWidth(FONT_TEXT_2)) / 2;
1319 int xpos4 = (4 * 10 - 4 * getFontWidth(FONT_LEVEL_NUMBER)) / 2;
1321 if (PANEL_DEACTIVATED(game.panel.time))
1324 /* clear background if value just changed its size */
1325 if (value == 999 || value == 1000)
1326 ClearRectangleOnBackground(drawto, DX_TIME1, DY_TIME, 14 * 3, 14);
1329 DrawText(DX_TIME1 + xpos3, DY_TIME, int2str(value, 3), FONT_TEXT_2);
1331 DrawText(DX_TIME2 + xpos4, DY_TIME, int2str(value, 4), FONT_LEVEL_NUMBER);
1334 inline void DrawGameValue_Level(int value)
1336 if (PANEL_DEACTIVATED(game.panel.level))
1340 DrawText(DX_LEVEL1, DY_LEVEL, int2str(value, 2), FONT_TEXT_2);
1342 DrawText(DX_LEVEL2, DY_LEVEL, int2str(value, 3), FONT_LEVEL_NUMBER);
1345 void DrawAllGameValues(int emeralds, int dynamite, int score, int time,
1348 int key[MAX_NUM_KEYS];
1351 /* prevent EM engine from updating time/score values parallel to GameWon() */
1352 if (level.game_engine_type == GAME_ENGINE_TYPE_EM &&
1353 local_player->LevelSolved)
1356 for (i = 0; i < MAX_NUM_KEYS; i++)
1357 key[i] = key_bits & (1 << i);
1359 DrawGameValue_Level(level_nr);
1361 DrawGameValue_Emeralds(emeralds);
1362 DrawGameValue_Dynamite(dynamite);
1363 DrawGameValue_Score(score);
1364 DrawGameValue_Time(time);
1366 DrawGameValue_Keys(key);
1369 void DrawGameDoorValues()
1371 int time_value = (level.time == 0 ? TimePlayed : TimeLeft);
1372 int dynamite_value = 0;
1373 int score_value = (local_player->LevelSolved ? local_player->score_final :
1374 local_player->score);
1375 int gems_value = local_player->gems_still_needed;
1379 if (level.game_engine_type == GAME_ENGINE_TYPE_EM)
1381 DrawGameDoorValues_EM();
1386 if (game.centered_player_nr == -1)
1388 for (i = 0; i < MAX_PLAYERS; i++)
1390 for (j = 0; j < MAX_NUM_KEYS; j++)
1391 if (stored_player[i].key[j])
1392 key_bits |= (1 << j);
1394 dynamite_value += stored_player[i].inventory_size;
1399 int player_nr = game.centered_player_nr;
1401 for (i = 0; i < MAX_NUM_KEYS; i++)
1402 if (stored_player[player_nr].key[i])
1403 key_bits |= (1 << i);
1405 dynamite_value = stored_player[player_nr].inventory_size;
1408 DrawAllGameValues(gems_value, dynamite_value, score_value, time_value,
1414 =============================================================================
1416 -----------------------------------------------------------------------------
1417 initialize game engine due to level / tape version number
1418 =============================================================================
1421 static void InitGameEngine()
1423 int i, j, k, l, x, y;
1425 /* set game engine from tape file when re-playing, else from level file */
1426 game.engine_version = (tape.playing ? tape.engine_version :
1427 level.game_version);
1429 /* ---------------------------------------------------------------------- */
1430 /* set flags for bugs and changes according to active game engine version */
1431 /* ---------------------------------------------------------------------- */
1434 Summary of bugfix/change:
1435 Fixed handling for custom elements that change when pushed by the player.
1437 Fixed/changed in version:
1441 Before 3.1.0, custom elements that "change when pushing" changed directly
1442 after the player started pushing them (until then handled in "DigField()").
1443 Since 3.1.0, these custom elements are not changed until the "pushing"
1444 move of the element is finished (now handled in "ContinueMoving()").
1446 Affected levels/tapes:
1447 The first condition is generally needed for all levels/tapes before version
1448 3.1.0, which might use the old behaviour before it was changed; known tapes
1449 that are affected are some tapes from the level set "Walpurgis Gardens" by
1451 The second condition is an exception from the above case and is needed for
1452 the special case of tapes recorded with game (not engine!) version 3.1.0 or
1453 above (including some development versions of 3.1.0), but before it was
1454 known that this change would break tapes like the above and was fixed in
1455 3.1.1, so that the changed behaviour was active although the engine version
1456 while recording maybe was before 3.1.0. There is at least one tape that is
1457 affected by this exception, which is the tape for the one-level set "Bug
1458 Machine" by Juergen Bonhagen.
1461 game.use_change_when_pushing_bug =
1462 (game.engine_version < VERSION_IDENT(3,1,0,0) &&
1464 tape.game_version >= VERSION_IDENT(3,1,0,0) &&
1465 tape.game_version < VERSION_IDENT(3,1,1,0)));
1468 Summary of bugfix/change:
1469 Fixed handling for blocking the field the player leaves when moving.
1471 Fixed/changed in version:
1475 Before 3.1.1, when "block last field when moving" was enabled, the field
1476 the player is leaving when moving was blocked for the time of the move,
1477 and was directly unblocked afterwards. This resulted in the last field
1478 being blocked for exactly one less than the number of frames of one player
1479 move. Additionally, even when blocking was disabled, the last field was
1480 blocked for exactly one frame.
1481 Since 3.1.1, due to changes in player movement handling, the last field
1482 is not blocked at all when blocking is disabled. When blocking is enabled,
1483 the last field is blocked for exactly the number of frames of one player
1484 move. Additionally, if the player is Murphy, the hero of Supaplex, the
1485 last field is blocked for exactly one more than the number of frames of
1488 Affected levels/tapes:
1489 (!!! yet to be determined -- probably many !!!)
1492 game.use_block_last_field_bug =
1493 (game.engine_version < VERSION_IDENT(3,1,1,0));
1496 Summary of bugfix/change:
1497 Changed behaviour of CE changes with multiple changes per single frame.
1499 Fixed/changed in version:
1503 Before 3.2.0-6, only one single CE change was allowed in each engine frame.
1504 This resulted in race conditions where CEs seem to behave strange in some
1505 situations (where triggered CE changes were just skipped because there was
1506 already a CE change on that tile in the playfield in that engine frame).
1507 Since 3.2.0-6, this was changed to allow up to MAX_NUM_CHANGES_PER_FRAME.
1508 (The number of changes per frame must be limited in any case, because else
1509 it is easily possible to define CE changes that would result in an infinite
1510 loop, causing the whole game to freeze. The MAX_NUM_CHANGES_PER_FRAME value
1511 should be set large enough so that it would only be reached in cases where
1512 the corresponding CE change conditions run into a loop. Therefore, it seems
1513 to be reasonable to set MAX_NUM_CHANGES_PER_FRAME to the same value as the
1514 maximal number of change pages for custom elements.)
1516 Affected levels/tapes:
1520 #if USE_ONLY_ONE_CHANGE_PER_FRAME
1521 game.max_num_changes_per_frame = 1;
1523 game.max_num_changes_per_frame =
1524 (game.engine_version < VERSION_IDENT(3,2,0,6) ? 1 : 32);
1527 /* ---------------------------------------------------------------------- */
1529 /* default scan direction: scan playfield from top/left to bottom/right */
1530 InitPlayfieldScanMode(CA_ARG_SCAN_MODE_NORMAL);
1532 /* dynamically adjust element properties according to game engine version */
1533 InitElementPropertiesEngine(game.engine_version);
1536 printf("level %d: level version == %06d\n", level_nr, level.game_version);
1537 printf(" tape version == %06d [%s] [file: %06d]\n",
1538 tape.engine_version, (tape.playing ? "PLAYING" : "RECORDING"),
1540 printf(" => game.engine_version == %06d\n", game.engine_version);
1543 /* ---------- initialize player's initial move delay --------------------- */
1545 /* dynamically adjust player properties according to level information */
1546 for (i = 0; i < MAX_PLAYERS; i++)
1547 game.initial_move_delay_value[i] =
1548 get_move_delay_from_stepsize(level.initial_player_stepsize[i]);
1550 /* dynamically adjust player properties according to game engine version */
1551 for (i = 0; i < MAX_PLAYERS; i++)
1552 game.initial_move_delay[i] =
1553 (game.engine_version <= VERSION_IDENT(2,0,1,0) ?
1554 game.initial_move_delay_value[i] : 0);
1556 /* ---------- initialize player's initial push delay --------------------- */
1558 /* dynamically adjust player properties according to game engine version */
1559 game.initial_push_delay_value =
1560 (game.engine_version < VERSION_IDENT(3,0,7,1) ? 5 : -1);
1562 /* ---------- initialize changing elements ------------------------------- */
1564 /* initialize changing elements information */
1565 for (i = 0; i < MAX_NUM_ELEMENTS; i++)
1567 struct ElementInfo *ei = &element_info[i];
1569 /* this pointer might have been changed in the level editor */
1570 ei->change = &ei->change_page[0];
1572 if (!IS_CUSTOM_ELEMENT(i))
1574 ei->change->target_element = EL_EMPTY_SPACE;
1575 ei->change->delay_fixed = 0;
1576 ei->change->delay_random = 0;
1577 ei->change->delay_frames = 1;
1580 for (j = 0; j < NUM_CHANGE_EVENTS; j++)
1582 ei->has_change_event[j] = FALSE;
1584 ei->event_page_nr[j] = 0;
1585 ei->event_page[j] = &ei->change_page[0];
1589 /* add changing elements from pre-defined list */
1590 for (i = 0; change_delay_list[i].element != EL_UNDEFINED; i++)
1592 struct ChangingElementInfo *ch_delay = &change_delay_list[i];
1593 struct ElementInfo *ei = &element_info[ch_delay->element];
1595 ei->change->target_element = ch_delay->target_element;
1596 ei->change->delay_fixed = ch_delay->change_delay;
1598 ei->change->pre_change_function = ch_delay->pre_change_function;
1599 ei->change->change_function = ch_delay->change_function;
1600 ei->change->post_change_function = ch_delay->post_change_function;
1602 ei->change->can_change = TRUE;
1603 ei->change->can_change_or_has_action = TRUE;
1605 ei->has_change_event[CE_DELAY] = TRUE;
1607 SET_PROPERTY(ch_delay->element, EP_CAN_CHANGE, TRUE);
1608 SET_PROPERTY(ch_delay->element, EP_CAN_CHANGE_OR_HAS_ACTION, TRUE);
1611 /* ---------- initialize internal run-time variables ------------- */
1613 for (i = 0; i < NUM_CUSTOM_ELEMENTS; i++)
1615 struct ElementInfo *ei = &element_info[EL_CUSTOM_START + i];
1617 for (j = 0; j < ei->num_change_pages; j++)
1619 ei->change_page[j].can_change_or_has_action =
1620 (ei->change_page[j].can_change |
1621 ei->change_page[j].has_action);
1625 /* add change events from custom element configuration */
1626 for (i = 0; i < NUM_CUSTOM_ELEMENTS; i++)
1628 struct ElementInfo *ei = &element_info[EL_CUSTOM_START + i];
1630 for (j = 0; j < ei->num_change_pages; j++)
1632 if (!ei->change_page[j].can_change_or_has_action)
1635 for (k = 0; k < NUM_CHANGE_EVENTS; k++)
1637 /* only add event page for the first page found with this event */
1638 if (ei->change_page[j].has_event[k] && !(ei->has_change_event[k]))
1640 ei->has_change_event[k] = TRUE;
1642 ei->event_page_nr[k] = j;
1643 ei->event_page[k] = &ei->change_page[j];
1649 /* ---------- initialize run-time trigger player and element ------------- */
1651 for (i = 0; i < NUM_CUSTOM_ELEMENTS; i++)
1653 struct ElementInfo *ei = &element_info[EL_CUSTOM_START + i];
1655 for (j = 0; j < ei->num_change_pages; j++)
1657 ei->change_page[j].actual_trigger_element = EL_EMPTY;
1658 ei->change_page[j].actual_trigger_player = EL_PLAYER_1;
1659 ei->change_page[j].actual_trigger_side = CH_SIDE_NONE;
1660 ei->change_page[j].actual_trigger_ce_value = 0;
1661 ei->change_page[j].actual_trigger_ce_score = 0;
1665 /* ---------- initialize trigger events ---------------------------------- */
1667 /* initialize trigger events information */
1668 for (i = 0; i < MAX_NUM_ELEMENTS; i++)
1669 for (j = 0; j < NUM_CHANGE_EVENTS; j++)
1670 trigger_events[i][j] = FALSE;
1672 /* add trigger events from element change event properties */
1673 for (i = 0; i < MAX_NUM_ELEMENTS; i++)
1675 struct ElementInfo *ei = &element_info[i];
1677 for (j = 0; j < ei->num_change_pages; j++)
1679 if (!ei->change_page[j].can_change_or_has_action)
1682 if (ei->change_page[j].has_event[CE_BY_OTHER_ACTION])
1684 int trigger_element = ei->change_page[j].trigger_element;
1686 for (k = 0; k < NUM_CHANGE_EVENTS; k++)
1688 if (ei->change_page[j].has_event[k])
1690 if (IS_GROUP_ELEMENT(trigger_element))
1692 struct ElementGroupInfo *group =
1693 element_info[trigger_element].group;
1695 for (l = 0; l < group->num_elements_resolved; l++)
1696 trigger_events[group->element_resolved[l]][k] = TRUE;
1698 else if (trigger_element == EL_ANY_ELEMENT)
1699 for (l = 0; l < MAX_NUM_ELEMENTS; l++)
1700 trigger_events[l][k] = TRUE;
1702 trigger_events[trigger_element][k] = TRUE;
1709 /* ---------- initialize push delay -------------------------------------- */
1711 /* initialize push delay values to default */
1712 for (i = 0; i < MAX_NUM_ELEMENTS; i++)
1714 if (!IS_CUSTOM_ELEMENT(i))
1716 /* set default push delay values (corrected since version 3.0.7-1) */
1717 if (game.engine_version < VERSION_IDENT(3,0,7,1))
1719 element_info[i].push_delay_fixed = 2;
1720 element_info[i].push_delay_random = 8;
1724 element_info[i].push_delay_fixed = 8;
1725 element_info[i].push_delay_random = 8;
1730 /* set push delay value for certain elements from pre-defined list */
1731 for (i = 0; push_delay_list[i].element != EL_UNDEFINED; i++)
1733 int e = push_delay_list[i].element;
1735 element_info[e].push_delay_fixed = push_delay_list[i].push_delay_fixed;
1736 element_info[e].push_delay_random = push_delay_list[i].push_delay_random;
1739 /* set push delay value for Supaplex elements for newer engine versions */
1740 if (game.engine_version >= VERSION_IDENT(3,1,0,0))
1742 for (i = 0; i < MAX_NUM_ELEMENTS; i++)
1744 if (IS_SP_ELEMENT(i))
1746 /* set SP push delay to just enough to push under a falling zonk */
1747 int delay = (game.engine_version >= VERSION_IDENT(3,1,1,0) ? 8 : 6);
1749 element_info[i].push_delay_fixed = delay;
1750 element_info[i].push_delay_random = 0;
1755 /* ---------- initialize move stepsize ----------------------------------- */
1757 /* initialize move stepsize values to default */
1758 for (i = 0; i < MAX_NUM_ELEMENTS; i++)
1759 if (!IS_CUSTOM_ELEMENT(i))
1760 element_info[i].move_stepsize = MOVE_STEPSIZE_NORMAL;
1762 /* set move stepsize value for certain elements from pre-defined list */
1763 for (i = 0; move_stepsize_list[i].element != EL_UNDEFINED; i++)
1765 int e = move_stepsize_list[i].element;
1767 element_info[e].move_stepsize = move_stepsize_list[i].move_stepsize;
1770 /* ---------- initialize collect score ----------------------------------- */
1772 /* initialize collect score values for custom elements from initial value */
1773 for (i = 0; i < MAX_NUM_ELEMENTS; i++)
1774 if (IS_CUSTOM_ELEMENT(i))
1775 element_info[i].collect_score = element_info[i].collect_score_initial;
1777 /* ---------- initialize collect count ----------------------------------- */
1779 /* initialize collect count values for non-custom elements */
1780 for (i = 0; i < MAX_NUM_ELEMENTS; i++)
1781 if (!IS_CUSTOM_ELEMENT(i))
1782 element_info[i].collect_count_initial = 0;
1784 /* add collect count values for all elements from pre-defined list */
1785 for (i = 0; collect_count_list[i].element != EL_UNDEFINED; i++)
1786 element_info[collect_count_list[i].element].collect_count_initial =
1787 collect_count_list[i].count;
1789 /* ---------- initialize access direction -------------------------------- */
1791 /* initialize access direction values to default (access from every side) */
1792 for (i = 0; i < MAX_NUM_ELEMENTS; i++)
1793 if (!IS_CUSTOM_ELEMENT(i))
1794 element_info[i].access_direction = MV_ALL_DIRECTIONS;
1796 /* set access direction value for certain elements from pre-defined list */
1797 for (i = 0; access_direction_list[i].element != EL_UNDEFINED; i++)
1798 element_info[access_direction_list[i].element].access_direction =
1799 access_direction_list[i].direction;
1801 /* ---------- initialize explosion content ------------------------------- */
1802 for (i = 0; i < MAX_NUM_ELEMENTS; i++)
1804 if (IS_CUSTOM_ELEMENT(i))
1807 for (y = 0; y < 3; y++) for (x = 0; x < 3; x++)
1809 /* (content for EL_YAMYAM set at run-time with game.yamyam_content_nr) */
1811 element_info[i].content.e[x][y] =
1812 (i == EL_PLAYER_1 ? EL_EMERALD_YELLOW :
1813 i == EL_PLAYER_2 ? EL_EMERALD_RED :
1814 i == EL_PLAYER_3 ? EL_EMERALD :
1815 i == EL_PLAYER_4 ? EL_EMERALD_PURPLE :
1816 i == EL_MOLE ? EL_EMERALD_RED :
1817 i == EL_PENGUIN ? EL_EMERALD_PURPLE :
1818 i == EL_BUG ? (x == 1 && y == 1 ? EL_DIAMOND : EL_EMERALD) :
1819 i == EL_BD_BUTTERFLY ? EL_BD_DIAMOND :
1820 i == EL_SP_ELECTRON ? EL_SP_INFOTRON :
1821 i == EL_AMOEBA_TO_DIAMOND ? level.amoeba_content :
1822 i == EL_WALL_EMERALD ? EL_EMERALD :
1823 i == EL_WALL_DIAMOND ? EL_DIAMOND :
1824 i == EL_WALL_BD_DIAMOND ? EL_BD_DIAMOND :
1825 i == EL_WALL_EMERALD_YELLOW ? EL_EMERALD_YELLOW :
1826 i == EL_WALL_EMERALD_RED ? EL_EMERALD_RED :
1827 i == EL_WALL_EMERALD_PURPLE ? EL_EMERALD_PURPLE :
1828 i == EL_WALL_PEARL ? EL_PEARL :
1829 i == EL_WALL_CRYSTAL ? EL_CRYSTAL :
1834 /* ---------- initialize recursion detection ------------------------------ */
1835 recursion_loop_depth = 0;
1836 recursion_loop_detected = FALSE;
1837 recursion_loop_element = EL_UNDEFINED;
1840 int get_num_special_action(int element, int action_first, int action_last)
1842 int num_special_action = 0;
1845 for (i = action_first; i <= action_last; i++)
1847 boolean found = FALSE;
1849 for (j = 0; j < NUM_DIRECTIONS; j++)
1850 if (el_act_dir2img(element, i, j) !=
1851 el_act_dir2img(element, ACTION_DEFAULT, j))
1855 num_special_action++;
1860 return num_special_action;
1865 =============================================================================
1867 -----------------------------------------------------------------------------
1868 initialize and start new game
1869 =============================================================================
1874 boolean emulate_bd = TRUE; /* unless non-BOULDERDASH elements found */
1875 boolean emulate_sb = TRUE; /* unless non-SOKOBAN elements found */
1876 boolean emulate_sp = TRUE; /* unless non-SUPAPLEX elements found */
1877 boolean do_fading = (game_status == GAME_MODE_MAIN);
1880 game_status = GAME_MODE_PLAYING;
1884 /* don't play tapes over network */
1885 network_playing = (options.network && !tape.playing);
1887 for (i = 0; i < MAX_PLAYERS; i++)
1889 struct PlayerInfo *player = &stored_player[i];
1891 player->index_nr = i;
1892 player->index_bit = (1 << i);
1893 player->element_nr = EL_PLAYER_1 + i;
1895 player->present = FALSE;
1896 player->active = FALSE;
1897 player->killed = FALSE;
1900 player->effective_action = 0;
1901 player->programmed_action = 0;
1904 player->score_final = 0;
1906 player->gems_still_needed = level.gems_needed;
1907 player->sokobanfields_still_needed = 0;
1908 player->lights_still_needed = 0;
1909 player->friends_still_needed = 0;
1911 for (j = 0; j < MAX_NUM_KEYS; j++)
1912 player->key[j] = FALSE;
1914 player->dynabomb_count = 0;
1915 player->dynabomb_size = 1;
1916 player->dynabombs_left = 0;
1917 player->dynabomb_xl = FALSE;
1919 player->MovDir = MV_NONE;
1922 player->GfxDir = MV_NONE;
1923 player->GfxAction = ACTION_DEFAULT;
1925 player->StepFrame = 0;
1927 player->use_murphy = FALSE;
1928 player->artwork_element =
1929 (level.use_artwork_element[i] ? level.artwork_element[i] :
1930 player->element_nr);
1932 player->block_last_field = FALSE; /* initialized in InitPlayerField() */
1933 player->block_delay_adjustment = 0; /* initialized in InitPlayerField() */
1935 player->gravity = level.initial_player_gravity[i];
1937 player->can_fall_into_acid = CAN_MOVE_INTO_ACID(player->element_nr);
1939 player->actual_frame_counter = 0;
1941 player->step_counter = 0;
1943 player->last_move_dir = MV_NONE;
1945 player->is_active = FALSE;
1947 player->is_waiting = FALSE;
1948 player->is_moving = FALSE;
1949 player->is_auto_moving = FALSE;
1950 player->is_digging = FALSE;
1951 player->is_snapping = FALSE;
1952 player->is_collecting = FALSE;
1953 player->is_pushing = FALSE;
1954 player->is_switching = FALSE;
1955 player->is_dropping = FALSE;
1956 player->is_dropping_pressed = FALSE;
1958 player->is_bored = FALSE;
1959 player->is_sleeping = FALSE;
1961 player->frame_counter_bored = -1;
1962 player->frame_counter_sleeping = -1;
1964 player->anim_delay_counter = 0;
1965 player->post_delay_counter = 0;
1967 player->dir_waiting = MV_NONE;
1968 player->action_waiting = ACTION_DEFAULT;
1969 player->last_action_waiting = ACTION_DEFAULT;
1970 player->special_action_bored = ACTION_DEFAULT;
1971 player->special_action_sleeping = ACTION_DEFAULT;
1973 player->switch_x = -1;
1974 player->switch_y = -1;
1976 player->drop_x = -1;
1977 player->drop_y = -1;
1979 player->show_envelope = 0;
1981 SetPlayerMoveSpeed(player, level.initial_player_stepsize[i], TRUE);
1983 player->push_delay = -1; /* initialized when pushing starts */
1984 player->push_delay_value = game.initial_push_delay_value;
1986 player->drop_delay = 0;
1987 player->drop_pressed_delay = 0;
1989 player->last_jx = -1;
1990 player->last_jy = -1;
1994 player->shield_normal_time_left = 0;
1995 player->shield_deadly_time_left = 0;
1997 player->inventory_infinite_element = EL_UNDEFINED;
1998 player->inventory_size = 0;
2000 DigField(player, 0, 0, 0, 0, 0, 0, DF_NO_PUSH);
2001 SnapField(player, 0, 0);
2003 player->LevelSolved = FALSE;
2004 player->GameOver = FALSE;
2006 player->LevelSolved_GameEnd = FALSE;
2007 player->LevelSolved_SaveTape = FALSE;
2008 player->LevelSolved_SaveScore = FALSE;
2011 network_player_action_received = FALSE;
2013 #if defined(NETWORK_AVALIABLE)
2014 /* initial null action */
2015 if (network_playing)
2016 SendToServer_MovePlayer(MV_NONE);
2025 TimeLeft = level.time;
2028 ScreenMovDir = MV_NONE;
2032 ScrollStepSize = 0; /* will be correctly initialized by ScrollScreen() */
2034 AllPlayersGone = FALSE;
2036 game.yamyam_content_nr = 0;
2037 game.magic_wall_active = FALSE;
2038 game.magic_wall_time_left = 0;
2039 game.light_time_left = 0;
2040 game.timegate_time_left = 0;
2041 game.switchgate_pos = 0;
2042 game.wind_direction = level.wind_direction_initial;
2044 #if !USE_PLAYER_GRAVITY
2045 game.gravity = FALSE;
2046 game.explosions_delayed = TRUE;
2049 game.lenses_time_left = 0;
2050 game.magnify_time_left = 0;
2052 game.ball_state = level.ball_state_initial;
2053 game.ball_content_nr = 0;
2055 game.envelope_active = FALSE;
2057 /* set focus to local player for network games, else to all players */
2058 game.centered_player_nr = (network_playing ? local_player->index_nr : -1);
2059 game.centered_player_nr_next = game.centered_player_nr;
2060 game.set_centered_player = FALSE;
2062 if (network_playing && tape.recording)
2064 /* store client dependent player focus when recording network games */
2065 tape.centered_player_nr_next = game.centered_player_nr_next;
2066 tape.set_centered_player = TRUE;
2069 for (i = 0; i < NUM_BELTS; i++)
2071 game.belt_dir[i] = MV_NONE;
2072 game.belt_dir_nr[i] = 3; /* not moving, next moving left */
2075 for (i = 0; i < MAX_NUM_AMOEBA; i++)
2076 AmoebaCnt[i] = AmoebaCnt2[i] = 0;
2078 SCAN_PLAYFIELD(x, y)
2080 Feld[x][y] = level.field[x][y];
2081 MovPos[x][y] = MovDir[x][y] = MovDelay[x][y] = 0;
2082 ChangeDelay[x][y] = 0;
2083 ChangePage[x][y] = -1;
2084 #if USE_NEW_CUSTOM_VALUE
2085 CustomValue[x][y] = 0; /* initialized in InitField() */
2087 Store[x][y] = Store2[x][y] = StorePlayer[x][y] = Back[x][y] = 0;
2089 WasJustMoving[x][y] = 0;
2090 WasJustFalling[x][y] = 0;
2091 CheckCollision[x][y] = 0;
2092 CheckImpact[x][y] = 0;
2094 Pushed[x][y] = FALSE;
2096 ChangeCount[x][y] = 0;
2097 ChangeEvent[x][y] = -1;
2099 ExplodePhase[x][y] = 0;
2100 ExplodeDelay[x][y] = 0;
2101 ExplodeField[x][y] = EX_TYPE_NONE;
2103 RunnerVisit[x][y] = 0;
2104 PlayerVisit[x][y] = 0;
2107 GfxRandom[x][y] = INIT_GFX_RANDOM();
2108 GfxElement[x][y] = EL_UNDEFINED;
2109 GfxAction[x][y] = ACTION_DEFAULT;
2110 GfxDir[x][y] = MV_NONE;
2113 SCAN_PLAYFIELD(x, y)
2115 if (emulate_bd && !IS_BD_ELEMENT(Feld[x][y]))
2117 if (emulate_sb && !IS_SB_ELEMENT(Feld[x][y]))
2119 if (emulate_sp && !IS_SP_ELEMENT(Feld[x][y]))
2122 InitField(x, y, TRUE);
2127 for (i = 0; i < MAX_PLAYERS; i++)
2129 struct PlayerInfo *player = &stored_player[i];
2131 /* set number of special actions for bored and sleeping animation */
2132 player->num_special_action_bored =
2133 get_num_special_action(player->artwork_element,
2134 ACTION_BORING_1, ACTION_BORING_LAST);
2135 player->num_special_action_sleeping =
2136 get_num_special_action(player->artwork_element,
2137 ACTION_SLEEPING_1, ACTION_SLEEPING_LAST);
2140 game.emulation = (emulate_bd ? EMU_BOULDERDASH :
2141 emulate_sb ? EMU_SOKOBAN :
2142 emulate_sp ? EMU_SUPAPLEX : EMU_NONE);
2144 #if USE_NEW_ALL_SLIPPERY
2145 /* initialize type of slippery elements */
2146 for (i = 0; i < MAX_NUM_ELEMENTS; i++)
2148 if (!IS_CUSTOM_ELEMENT(i))
2150 /* default: elements slip down either to the left or right randomly */
2151 element_info[i].slippery_type = SLIPPERY_ANY_RANDOM;
2153 /* SP style elements prefer to slip down on the left side */
2154 if (game.engine_version >= VERSION_IDENT(3,1,1,0) && IS_SP_ELEMENT(i))
2155 element_info[i].slippery_type = SLIPPERY_ANY_LEFT_RIGHT;
2157 /* BD style elements prefer to slip down on the left side */
2158 if (game.emulation == EMU_BOULDERDASH)
2159 element_info[i].slippery_type = SLIPPERY_ANY_LEFT_RIGHT;
2164 /* initialize explosion and ignition delay */
2165 for (i = 0; i < MAX_NUM_ELEMENTS; i++)
2167 if (!IS_CUSTOM_ELEMENT(i))
2170 int delay = (((IS_SP_ELEMENT(i) && i != EL_EMPTY_SPACE) &&
2171 game.engine_version >= VERSION_IDENT(3,1,0,0)) ||
2172 game.emulation == EMU_SUPAPLEX ? 3 : 2);
2173 int last_phase = (num_phase + 1) * delay;
2174 int half_phase = (num_phase / 2) * delay;
2176 element_info[i].explosion_delay = last_phase - 1;
2177 element_info[i].ignition_delay = half_phase;
2179 if (i == EL_BLACK_ORB)
2180 element_info[i].ignition_delay = 1;
2184 if (element_info[i].explosion_delay < 1) /* !!! check again !!! */
2185 element_info[i].explosion_delay = 1;
2187 if (element_info[i].ignition_delay < 1) /* !!! check again !!! */
2188 element_info[i].ignition_delay = 1;
2192 /* correct non-moving belts to start moving left */
2193 for (i = 0; i < NUM_BELTS; i++)
2194 if (game.belt_dir[i] == MV_NONE)
2195 game.belt_dir_nr[i] = 3; /* not moving, next moving left */
2197 /* check if any connected player was not found in playfield */
2198 for (i = 0; i < MAX_PLAYERS; i++)
2200 struct PlayerInfo *player = &stored_player[i];
2202 if (player->connected && !player->present)
2204 for (j = 0; j < MAX_PLAYERS; j++)
2206 struct PlayerInfo *some_player = &stored_player[j];
2207 int jx = some_player->jx, jy = some_player->jy;
2209 /* assign first free player found that is present in the playfield */
2210 if (some_player->present && !some_player->connected)
2212 player->present = TRUE;
2213 player->active = TRUE;
2215 some_player->present = FALSE;
2216 some_player->active = FALSE;
2218 player->artwork_element = some_player->artwork_element;
2220 player->block_last_field = some_player->block_last_field;
2221 player->block_delay_adjustment = some_player->block_delay_adjustment;
2223 StorePlayer[jx][jy] = player->element_nr;
2224 player->jx = player->last_jx = jx;
2225 player->jy = player->last_jy = jy;
2235 /* when playing a tape, eliminate all players who do not participate */
2237 for (i = 0; i < MAX_PLAYERS; i++)
2239 if (stored_player[i].active && !tape.player_participates[i])
2241 struct PlayerInfo *player = &stored_player[i];
2242 int jx = player->jx, jy = player->jy;
2244 player->active = FALSE;
2245 StorePlayer[jx][jy] = 0;
2246 Feld[jx][jy] = EL_EMPTY;
2250 else if (!options.network && !setup.team_mode) /* && !tape.playing */
2252 /* when in single player mode, eliminate all but the first active player */
2254 for (i = 0; i < MAX_PLAYERS; i++)
2256 if (stored_player[i].active)
2258 for (j = i + 1; j < MAX_PLAYERS; j++)
2260 if (stored_player[j].active)
2262 struct PlayerInfo *player = &stored_player[j];
2263 int jx = player->jx, jy = player->jy;
2265 player->active = FALSE;
2266 player->present = FALSE;
2268 StorePlayer[jx][jy] = 0;
2269 Feld[jx][jy] = EL_EMPTY;
2276 /* when recording the game, store which players take part in the game */
2279 for (i = 0; i < MAX_PLAYERS; i++)
2280 if (stored_player[i].active)
2281 tape.player_participates[i] = TRUE;
2286 for (i = 0; i < MAX_PLAYERS; i++)
2288 struct PlayerInfo *player = &stored_player[i];
2290 printf("Player %d: present == %d, connected == %d, active == %d.\n",
2295 if (local_player == player)
2296 printf("Player %d is local player.\n", i+1);
2300 if (BorderElement == EL_EMPTY)
2303 SBX_Right = lev_fieldx - SCR_FIELDX;
2305 SBY_Lower = lev_fieldy - SCR_FIELDY;
2310 SBX_Right = lev_fieldx - SCR_FIELDX + 1;
2312 SBY_Lower = lev_fieldy - SCR_FIELDY + 1;
2315 if (lev_fieldx + (SBX_Left == -1 ? 2 : 0) <= SCR_FIELDX)
2316 SBX_Left = SBX_Right = -1 * (SCR_FIELDX - lev_fieldx) / 2;
2318 if (lev_fieldy + (SBY_Upper == -1 ? 2 : 0) <= SCR_FIELDY)
2319 SBY_Upper = SBY_Lower = -1 * (SCR_FIELDY - lev_fieldy) / 2;
2321 /* if local player not found, look for custom element that might create
2322 the player (make some assumptions about the right custom element) */
2323 if (!local_player->present)
2325 int start_x = 0, start_y = 0;
2326 int found_rating = 0;
2327 int found_element = EL_UNDEFINED;
2328 int player_nr = local_player->index_nr;
2330 SCAN_PLAYFIELD(x, y)
2332 int element = Feld[x][y];
2337 if (level.use_start_element[player_nr] &&
2338 level.start_element[player_nr] == element &&
2345 found_element = element;
2348 if (!IS_CUSTOM_ELEMENT(element))
2351 if (CAN_CHANGE(element))
2353 for (i = 0; i < element_info[element].num_change_pages; i++)
2355 /* check for player created from custom element as single target */
2356 content = element_info[element].change_page[i].target_element;
2357 is_player = ELEM_IS_PLAYER(content);
2359 if (is_player && (found_rating < 3 || element < found_element))
2365 found_element = element;
2370 for (yy = 0; yy < 3; yy++) for (xx = 0; xx < 3; xx++)
2372 /* check for player created from custom element as explosion content */
2373 content = element_info[element].content.e[xx][yy];
2374 is_player = ELEM_IS_PLAYER(content);
2376 if (is_player && (found_rating < 2 || element < found_element))
2378 start_x = x + xx - 1;
2379 start_y = y + yy - 1;
2382 found_element = element;
2385 if (!CAN_CHANGE(element))
2388 for (i = 0; i < element_info[element].num_change_pages; i++)
2390 /* check for player created from custom element as extended target */
2392 element_info[element].change_page[i].target_content.e[xx][yy];
2394 is_player = ELEM_IS_PLAYER(content);
2396 if (is_player && (found_rating < 1 || element < found_element))
2398 start_x = x + xx - 1;
2399 start_y = y + yy - 1;
2402 found_element = element;
2408 scroll_x = (start_x < SBX_Left + MIDPOSX ? SBX_Left :
2409 start_x > SBX_Right + MIDPOSX ? SBX_Right :
2412 scroll_y = (start_y < SBY_Upper + MIDPOSY ? SBY_Upper :
2413 start_y > SBY_Lower + MIDPOSY ? SBY_Lower :
2418 scroll_x = (local_player->jx < SBX_Left + MIDPOSX ? SBX_Left :
2419 local_player->jx > SBX_Right + MIDPOSX ? SBX_Right :
2420 local_player->jx - MIDPOSX);
2422 scroll_y = (local_player->jy < SBY_Upper + MIDPOSY ? SBY_Upper :
2423 local_player->jy > SBY_Lower + MIDPOSY ? SBY_Lower :
2424 local_player->jy - MIDPOSY);
2429 if (!game.restart_level)
2430 CloseDoor(DOOR_CLOSE_1);
2433 FadeOut(REDRAW_FIELD);
2435 /* !!! FIX THIS (START) !!! */
2436 if (level.game_engine_type == GAME_ENGINE_TYPE_EM)
2438 InitGameEngine_EM();
2440 /* blit playfield from scroll buffer to normal back buffer for fading in */
2441 BlitScreenToBitmap_EM(backbuffer);
2448 /* after drawing the level, correct some elements */
2449 if (game.timegate_time_left == 0)
2450 CloseAllOpenTimegates();
2452 /* blit playfield from scroll buffer to normal back buffer for fading in */
2453 if (setup.soft_scrolling)
2454 BlitBitmap(fieldbuffer, backbuffer, FX, FY, SXSIZE, SYSIZE, SX, SY);
2456 redraw_mask |= REDRAW_FROM_BACKBUFFER;
2458 /* !!! FIX THIS (END) !!! */
2461 FadeIn(REDRAW_FIELD);
2465 if (!game.restart_level)
2467 /* copy default game door content to main double buffer */
2468 BlitBitmap(graphic_info[IMG_GLOBAL_DOOR].bitmap, drawto,
2469 DOOR_GFX_PAGEX5, DOOR_GFX_PAGEY1, DXSIZE, DYSIZE, DX, DY);
2472 SetPanelBackground();
2473 SetDrawBackgroundMask(REDRAW_DOOR_1);
2475 DrawGameDoorValues();
2477 if (!game.restart_level)
2481 game_gadget[SOUND_CTRL_ID_MUSIC]->checked = setup.sound_music;
2482 game_gadget[SOUND_CTRL_ID_LOOPS]->checked = setup.sound_loops;
2483 game_gadget[SOUND_CTRL_ID_SIMPLE]->checked = setup.sound_simple;
2487 /* copy actual game door content to door double buffer for OpenDoor() */
2488 BlitBitmap(drawto, bitmap_db_door,
2489 DX, DY, DXSIZE, DYSIZE, DOOR_GFX_PAGEX1, DOOR_GFX_PAGEY1);
2491 OpenDoor(DOOR_OPEN_ALL);
2493 PlaySound(SND_GAME_STARTING);
2495 if (setup.sound_music)
2498 KeyboardAutoRepeatOffUnlessAutoplay();
2502 for (i = 0; i < MAX_PLAYERS; i++)
2503 printf("Player %d %sactive.\n",
2504 i + 1, (stored_player[i].active ? "" : "not "));
2515 game.restart_level = FALSE;
2518 void UpdateEngineValues(int actual_scroll_x, int actual_scroll_y)
2520 /* this is used for non-R'n'D game engines to update certain engine values */
2522 /* needed to determine if sounds are played within the visible screen area */
2523 scroll_x = actual_scroll_x;
2524 scroll_y = actual_scroll_y;
2527 void InitMovDir(int x, int y)
2529 int i, element = Feld[x][y];
2530 static int xy[4][2] =
2537 static int direction[3][4] =
2539 { MV_RIGHT, MV_UP, MV_LEFT, MV_DOWN },
2540 { MV_LEFT, MV_DOWN, MV_RIGHT, MV_UP },
2541 { MV_LEFT, MV_RIGHT, MV_UP, MV_DOWN }
2550 Feld[x][y] = EL_BUG;
2551 MovDir[x][y] = direction[0][element - EL_BUG_RIGHT];
2554 case EL_SPACESHIP_RIGHT:
2555 case EL_SPACESHIP_UP:
2556 case EL_SPACESHIP_LEFT:
2557 case EL_SPACESHIP_DOWN:
2558 Feld[x][y] = EL_SPACESHIP;
2559 MovDir[x][y] = direction[0][element - EL_SPACESHIP_RIGHT];
2562 case EL_BD_BUTTERFLY_RIGHT:
2563 case EL_BD_BUTTERFLY_UP:
2564 case EL_BD_BUTTERFLY_LEFT:
2565 case EL_BD_BUTTERFLY_DOWN:
2566 Feld[x][y] = EL_BD_BUTTERFLY;
2567 MovDir[x][y] = direction[0][element - EL_BD_BUTTERFLY_RIGHT];
2570 case EL_BD_FIREFLY_RIGHT:
2571 case EL_BD_FIREFLY_UP:
2572 case EL_BD_FIREFLY_LEFT:
2573 case EL_BD_FIREFLY_DOWN:
2574 Feld[x][y] = EL_BD_FIREFLY;
2575 MovDir[x][y] = direction[0][element - EL_BD_FIREFLY_RIGHT];
2578 case EL_PACMAN_RIGHT:
2580 case EL_PACMAN_LEFT:
2581 case EL_PACMAN_DOWN:
2582 Feld[x][y] = EL_PACMAN;
2583 MovDir[x][y] = direction[0][element - EL_PACMAN_RIGHT];
2586 case EL_YAMYAM_LEFT:
2587 case EL_YAMYAM_RIGHT:
2589 case EL_YAMYAM_DOWN:
2590 Feld[x][y] = EL_YAMYAM;
2591 MovDir[x][y] = direction[2][element - EL_YAMYAM_LEFT];
2594 case EL_SP_SNIKSNAK:
2595 MovDir[x][y] = MV_UP;
2598 case EL_SP_ELECTRON:
2599 MovDir[x][y] = MV_LEFT;
2606 Feld[x][y] = EL_MOLE;
2607 MovDir[x][y] = direction[2][element - EL_MOLE_LEFT];
2611 if (IS_CUSTOM_ELEMENT(element))
2613 struct ElementInfo *ei = &element_info[element];
2614 int move_direction_initial = ei->move_direction_initial;
2615 int move_pattern = ei->move_pattern;
2617 if (move_direction_initial == MV_START_PREVIOUS)
2619 if (MovDir[x][y] != MV_NONE)
2622 move_direction_initial = MV_START_AUTOMATIC;
2625 if (move_direction_initial == MV_START_RANDOM)
2626 MovDir[x][y] = 1 << RND(4);
2627 else if (move_direction_initial & MV_ANY_DIRECTION)
2628 MovDir[x][y] = move_direction_initial;
2629 else if (move_pattern == MV_ALL_DIRECTIONS ||
2630 move_pattern == MV_TURNING_LEFT ||
2631 move_pattern == MV_TURNING_RIGHT ||
2632 move_pattern == MV_TURNING_LEFT_RIGHT ||
2633 move_pattern == MV_TURNING_RIGHT_LEFT ||
2634 move_pattern == MV_TURNING_RANDOM)
2635 MovDir[x][y] = 1 << RND(4);
2636 else if (move_pattern == MV_HORIZONTAL)
2637 MovDir[x][y] = (RND(2) ? MV_LEFT : MV_RIGHT);
2638 else if (move_pattern == MV_VERTICAL)
2639 MovDir[x][y] = (RND(2) ? MV_UP : MV_DOWN);
2640 else if (move_pattern & MV_ANY_DIRECTION)
2641 MovDir[x][y] = element_info[element].move_pattern;
2642 else if (move_pattern == MV_ALONG_LEFT_SIDE ||
2643 move_pattern == MV_ALONG_RIGHT_SIDE)
2645 /* use random direction as default start direction */
2646 if (game.engine_version >= VERSION_IDENT(3,1,0,0))
2647 MovDir[x][y] = 1 << RND(4);
2649 for (i = 0; i < NUM_DIRECTIONS; i++)
2651 int x1 = x + xy[i][0];
2652 int y1 = y + xy[i][1];
2654 if (!IN_LEV_FIELD(x1, y1) || !IS_FREE(x1, y1))
2656 if (move_pattern == MV_ALONG_RIGHT_SIDE)
2657 MovDir[x][y] = direction[0][i];
2659 MovDir[x][y] = direction[1][i];
2668 MovDir[x][y] = 1 << RND(4);
2670 if (element != EL_BUG &&
2671 element != EL_SPACESHIP &&
2672 element != EL_BD_BUTTERFLY &&
2673 element != EL_BD_FIREFLY)
2676 for (i = 0; i < NUM_DIRECTIONS; i++)
2678 int x1 = x + xy[i][0];
2679 int y1 = y + xy[i][1];
2681 if (!IN_LEV_FIELD(x1, y1) || !IS_FREE(x1, y1))
2683 if (element == EL_BUG || element == EL_BD_BUTTERFLY)
2685 MovDir[x][y] = direction[0][i];
2688 else if (element == EL_SPACESHIP || element == EL_BD_FIREFLY ||
2689 element == EL_SP_SNIKSNAK || element == EL_SP_ELECTRON)
2691 MovDir[x][y] = direction[1][i];
2700 GfxDir[x][y] = MovDir[x][y];
2703 void InitAmoebaNr(int x, int y)
2706 int group_nr = AmoebeNachbarNr(x, y);
2710 for (i = 1; i < MAX_NUM_AMOEBA; i++)
2712 if (AmoebaCnt[i] == 0)
2720 AmoebaNr[x][y] = group_nr;
2721 AmoebaCnt[group_nr]++;
2722 AmoebaCnt2[group_nr]++;
2725 static void PlayerWins(struct PlayerInfo *player)
2727 player->LevelSolved = TRUE;
2728 player->GameOver = TRUE;
2730 player->score_final = (level.game_engine_type == GAME_ENGINE_TYPE_EM ?
2731 level.native_em_level->lev->score : player->score);
2736 static int time, time_final;
2737 static int score, score_final;
2738 static int game_over_delay = 0;
2739 int game_over_delay_value = 50;
2741 if (!local_player->LevelSolved_GameEnd)
2745 /* do not start end game actions before the player stops moving (to exit) */
2746 if (local_player->MovPos)
2749 local_player->LevelSolved_GameEnd = TRUE;
2750 local_player->LevelSolved_SaveTape = tape.recording;
2751 local_player->LevelSolved_SaveScore = !tape.playing;
2753 if (tape.auto_play) /* tape might already be stopped here */
2754 tape.auto_play_level_solved = TRUE;
2760 game_over_delay = game_over_delay_value;
2762 time = time_final = (level.time == 0 ? TimePlayed : TimeLeft);
2763 score = score_final = local_player->score_final;
2768 score_final += TimeLeft * level.score[SC_TIME_BONUS];
2770 else if (level.time == 0 && TimePlayed < 999)
2773 score_final += (999 - TimePlayed) * level.score[SC_TIME_BONUS];
2776 local_player->score_final = score_final;
2778 if (level_editor_test_game)
2781 score = score_final;
2783 DrawGameValue_Time(time);
2784 DrawGameValue_Score(score);
2787 if (level.game_engine_type == GAME_ENGINE_TYPE_RND)
2789 if (ExitX >= 0 && ExitY >= 0) /* local player has left the level */
2791 /* close exit door after last player */
2792 if (AllPlayersGone &&
2793 (Feld[ExitX][ExitY] == EL_EXIT_OPEN ||
2794 Feld[ExitX][ExitY] == EL_SP_EXIT_OPEN ||
2795 Feld[ExitX][ExitY] == EL_STEEL_EXIT_OPEN))
2797 int element = Feld[ExitX][ExitY];
2799 Feld[ExitX][ExitY] = (element == EL_EXIT_OPEN ? EL_EXIT_CLOSING :
2800 element == EL_SP_EXIT_OPEN ? EL_SP_EXIT_CLOSING:
2801 EL_STEEL_EXIT_CLOSING);
2803 PlayLevelSoundElementAction(ExitX, ExitY, element, ACTION_CLOSING);
2806 /* player disappears */
2807 DrawLevelField(ExitX, ExitY);
2810 for (i = 0; i < MAX_PLAYERS; i++)
2812 struct PlayerInfo *player = &stored_player[i];
2814 if (player->present)
2816 RemovePlayer(player);
2818 /* player disappears */
2819 DrawLevelField(player->jx, player->jy);
2824 PlaySound(SND_GAME_WINNING);
2827 if (game_over_delay > 0)
2834 if (time != time_final)
2836 int time_to_go = ABS(time_final - time);
2837 int time_count_dir = (time < time_final ? +1 : -1);
2838 int time_count_steps = (time_to_go > 100 && time_to_go % 10 == 0 ? 10 : 1);
2840 time += time_count_steps * time_count_dir;
2841 score += time_count_steps * level.score[SC_TIME_BONUS];
2843 DrawGameValue_Time(time);
2844 DrawGameValue_Score(score);
2846 if (time == time_final)
2847 StopSound(SND_GAME_LEVELTIME_BONUS);
2848 else if (setup.sound_loops)
2849 PlaySoundLoop(SND_GAME_LEVELTIME_BONUS);
2851 PlaySound(SND_GAME_LEVELTIME_BONUS);
2858 boolean raise_level = FALSE;
2860 CloseDoor(DOOR_CLOSE_1);
2862 if (local_player->LevelSolved_SaveTape)
2869 SaveTapeChecked(tape.level_nr); /* ask to save tape */
2871 SaveTape(tape.level_nr); /* ask to save tape */
2875 if (level_editor_test_game)
2877 game_status = GAME_MODE_MAIN;
2884 if (!local_player->LevelSolved_SaveScore)
2886 FadeOut(REDRAW_FIELD);
2888 game_status = GAME_MODE_MAIN;
2890 DrawAndFadeInMainMenu(REDRAW_FIELD);
2895 if (level_nr == leveldir_current->handicap_level)
2897 leveldir_current->handicap_level++;
2898 SaveLevelSetup_SeriesInfo();
2901 if (level_nr < leveldir_current->last_level)
2902 raise_level = TRUE; /* advance to next level */
2904 if ((hi_pos = NewHiScore()) >= 0)
2906 game_status = GAME_MODE_SCORES;
2908 DrawHallOfFame(hi_pos);
2918 FadeOut(REDRAW_FIELD);
2920 game_status = GAME_MODE_MAIN;
2928 DrawAndFadeInMainMenu(REDRAW_FIELD);
2937 LoadScore(level_nr);
2939 if (strEqual(setup.player_name, EMPTY_PLAYER_NAME) ||
2940 local_player->score_final < highscore[MAX_SCORE_ENTRIES - 1].Score)
2943 for (k = 0; k < MAX_SCORE_ENTRIES; k++)
2945 if (local_player->score_final > highscore[k].Score)
2947 /* player has made it to the hall of fame */
2949 if (k < MAX_SCORE_ENTRIES - 1)
2951 int m = MAX_SCORE_ENTRIES - 1;
2954 for (l = k; l < MAX_SCORE_ENTRIES; l++)
2955 if (strEqual(setup.player_name, highscore[l].Name))
2957 if (m == k) /* player's new highscore overwrites his old one */
2961 for (l = m; l > k; l--)
2963 strcpy(highscore[l].Name, highscore[l - 1].Name);
2964 highscore[l].Score = highscore[l - 1].Score;
2971 strncpy(highscore[k].Name, setup.player_name, MAX_PLAYER_NAME_LEN);
2972 highscore[k].Name[MAX_PLAYER_NAME_LEN] = '\0';
2973 highscore[k].Score = local_player->score_final;
2979 else if (!strncmp(setup.player_name, highscore[k].Name,
2980 MAX_PLAYER_NAME_LEN))
2981 break; /* player already there with a higher score */
2987 SaveScore(level_nr);
2992 inline static int getElementMoveStepsizeExt(int x, int y, int direction)
2994 int element = Feld[x][y];
2995 int dx = (direction == MV_LEFT ? -1 : direction == MV_RIGHT ? +1 : 0);
2996 int dy = (direction == MV_UP ? -1 : direction == MV_DOWN ? +1 : 0);
2997 int horiz_move = (dx != 0);
2998 int sign = (horiz_move ? dx : dy);
2999 int step = sign * element_info[element].move_stepsize;
3001 /* special values for move stepsize for spring and things on conveyor belt */
3004 if (CAN_FALL(element) &&
3005 y < lev_fieldy - 1 && IS_BELT_ACTIVE(Feld[x][y + 1]))
3006 step = sign * MOVE_STEPSIZE_NORMAL / 2;
3007 else if (element == EL_SPRING)
3008 step = sign * MOVE_STEPSIZE_NORMAL * 2;
3014 inline static int getElementMoveStepsize(int x, int y)
3016 return getElementMoveStepsizeExt(x, y, MovDir[x][y]);
3019 void InitPlayerGfxAnimation(struct PlayerInfo *player, int action, int dir)
3021 if (player->GfxAction != action || player->GfxDir != dir)
3024 printf("Player frame reset! (%d => %d, %d => %d)\n",
3025 player->GfxAction, action, player->GfxDir, dir);
3028 player->GfxAction = action;
3029 player->GfxDir = dir;
3031 player->StepFrame = 0;
3035 #if USE_GFX_RESET_GFX_ANIMATION
3036 static void ResetGfxFrame(int x, int y, boolean redraw)
3038 int element = Feld[x][y];
3039 int graphic = el_act_dir2img(element, GfxAction[x][y], GfxDir[x][y]);
3040 int last_gfx_frame = GfxFrame[x][y];
3042 if (graphic_info[graphic].anim_global_sync)
3043 GfxFrame[x][y] = FrameCounter;
3044 else if (ANIM_MODE(graphic) == ANIM_CE_VALUE)
3045 GfxFrame[x][y] = CustomValue[x][y];
3046 else if (ANIM_MODE(graphic) == ANIM_CE_SCORE)
3047 GfxFrame[x][y] = element_info[element].collect_score;
3048 else if (ANIM_MODE(graphic) == ANIM_CE_DELAY)
3049 GfxFrame[x][y] = ChangeDelay[x][y];
3051 if (redraw && GfxFrame[x][y] != last_gfx_frame)
3052 DrawLevelGraphicAnimation(x, y, graphic);
3056 static void ResetGfxAnimation(int x, int y)
3058 GfxAction[x][y] = ACTION_DEFAULT;
3059 GfxDir[x][y] = MovDir[x][y];
3062 #if USE_GFX_RESET_GFX_ANIMATION
3063 ResetGfxFrame(x, y, FALSE);
3067 static void ResetRandomAnimationValue(int x, int y)
3069 GfxRandom[x][y] = INIT_GFX_RANDOM();
3072 void InitMovingField(int x, int y, int direction)
3074 int element = Feld[x][y];
3075 int dx = (direction == MV_LEFT ? -1 : direction == MV_RIGHT ? +1 : 0);
3076 int dy = (direction == MV_UP ? -1 : direction == MV_DOWN ? +1 : 0);
3079 boolean is_moving_before, is_moving_after;
3081 boolean continues_moving = (WasJustMoving[x][y] && direction == MovDir[x][y]);
3084 /* check if element was/is moving or being moved before/after mode change */
3086 is_moving_before = WasJustMoving[x][y];
3088 is_moving_before = (getElementMoveStepsizeExt(x, y, MovDir[x][y]) != 0);
3090 is_moving_after = (getElementMoveStepsizeExt(x, y, direction) != 0);
3092 /* reset animation only for moving elements which change direction of moving
3093 or which just started or stopped moving
3094 (else CEs with property "can move" / "not moving" are reset each frame) */
3095 #if USE_GFX_RESET_ONLY_WHEN_MOVING
3097 if (is_moving_before != is_moving_after ||
3098 direction != MovDir[x][y])
3099 ResetGfxAnimation(x, y);
3101 if ((is_moving_before || is_moving_after) && !continues_moving)
3102 ResetGfxAnimation(x, y);
3105 if (!continues_moving)
3106 ResetGfxAnimation(x, y);
3109 MovDir[x][y] = direction;
3110 GfxDir[x][y] = direction;
3112 #if USE_GFX_RESET_ONLY_WHEN_MOVING
3113 GfxAction[x][y] = (!is_moving_after ? ACTION_WAITING :
3114 direction == MV_DOWN && CAN_FALL(element) ?
3115 ACTION_FALLING : ACTION_MOVING);
3117 GfxAction[x][y] = (direction == MV_DOWN && CAN_FALL(element) ?
3118 ACTION_FALLING : ACTION_MOVING);
3121 /* this is needed for CEs with property "can move" / "not moving" */
3123 if (is_moving_after)
3125 if (Feld[newx][newy] == EL_EMPTY)
3126 Feld[newx][newy] = EL_BLOCKED;
3128 MovDir[newx][newy] = MovDir[x][y];
3130 #if USE_NEW_CUSTOM_VALUE
3131 CustomValue[newx][newy] = CustomValue[x][y];
3134 GfxFrame[newx][newy] = GfxFrame[x][y];
3135 GfxRandom[newx][newy] = GfxRandom[x][y];
3136 GfxAction[newx][newy] = GfxAction[x][y];
3137 GfxDir[newx][newy] = GfxDir[x][y];
3141 void Moving2Blocked(int x, int y, int *goes_to_x, int *goes_to_y)
3143 int direction = MovDir[x][y];
3144 int newx = x + (direction & MV_LEFT ? -1 : direction & MV_RIGHT ? +1 : 0);
3145 int newy = y + (direction & MV_UP ? -1 : direction & MV_DOWN ? +1 : 0);
3151 void Blocked2Moving(int x, int y, int *comes_from_x, int *comes_from_y)
3153 int oldx = x, oldy = y;
3154 int direction = MovDir[x][y];
3156 if (direction == MV_LEFT)
3158 else if (direction == MV_RIGHT)
3160 else if (direction == MV_UP)
3162 else if (direction == MV_DOWN)
3165 *comes_from_x = oldx;
3166 *comes_from_y = oldy;
3169 int MovingOrBlocked2Element(int x, int y)
3171 int element = Feld[x][y];
3173 if (element == EL_BLOCKED)
3177 Blocked2Moving(x, y, &oldx, &oldy);
3178 return Feld[oldx][oldy];
3184 static int MovingOrBlocked2ElementIfNotLeaving(int x, int y)
3186 /* like MovingOrBlocked2Element(), but if element is moving
3187 and (x,y) is the field the moving element is just leaving,
3188 return EL_BLOCKED instead of the element value */
3189 int element = Feld[x][y];
3191 if (IS_MOVING(x, y))
3193 if (element == EL_BLOCKED)
3197 Blocked2Moving(x, y, &oldx, &oldy);
3198 return Feld[oldx][oldy];
3207 static void RemoveField(int x, int y)
3209 Feld[x][y] = EL_EMPTY;
3215 #if USE_NEW_CUSTOM_VALUE
3216 CustomValue[x][y] = 0;
3220 ChangeDelay[x][y] = 0;
3221 ChangePage[x][y] = -1;
3222 Pushed[x][y] = FALSE;
3225 ExplodeField[x][y] = EX_TYPE_NONE;
3228 GfxElement[x][y] = EL_UNDEFINED;
3229 GfxAction[x][y] = ACTION_DEFAULT;
3230 GfxDir[x][y] = MV_NONE;
3233 void RemoveMovingField(int x, int y)
3235 int oldx = x, oldy = y, newx = x, newy = y;
3236 int element = Feld[x][y];
3237 int next_element = EL_UNDEFINED;
3239 if (element != EL_BLOCKED && !IS_MOVING(x, y))
3242 if (IS_MOVING(x, y))
3244 Moving2Blocked(x, y, &newx, &newy);
3246 if (Feld[newx][newy] != EL_BLOCKED)
3248 /* element is moving, but target field is not free (blocked), but
3249 already occupied by something different (example: acid pool);
3250 in this case, only remove the moving field, but not the target */
3252 RemoveField(oldx, oldy);
3254 Store[oldx][oldy] = Store2[oldx][oldy] = 0;
3256 DrawLevelField(oldx, oldy);
3261 else if (element == EL_BLOCKED)
3263 Blocked2Moving(x, y, &oldx, &oldy);
3264 if (!IS_MOVING(oldx, oldy))
3268 if (element == EL_BLOCKED &&
3269 (Feld[oldx][oldy] == EL_QUICKSAND_EMPTYING ||
3270 Feld[oldx][oldy] == EL_MAGIC_WALL_EMPTYING ||
3271 Feld[oldx][oldy] == EL_BD_MAGIC_WALL_EMPTYING ||
3272 Feld[oldx][oldy] == EL_AMOEBA_DROPPING))
3273 next_element = get_next_element(Feld[oldx][oldy]);
3275 RemoveField(oldx, oldy);
3276 RemoveField(newx, newy);
3278 Store[oldx][oldy] = Store2[oldx][oldy] = 0;
3280 if (next_element != EL_UNDEFINED)
3281 Feld[oldx][oldy] = next_element;
3283 DrawLevelField(oldx, oldy);
3284 DrawLevelField(newx, newy);
3287 void DrawDynamite(int x, int y)
3289 int sx = SCREENX(x), sy = SCREENY(y);
3290 int graphic = el2img(Feld[x][y]);
3293 if (!IN_SCR_FIELD(sx, sy) || IS_PLAYER(x, y))
3296 if (IS_WALKABLE_INSIDE(Back[x][y]))
3300 DrawGraphic(sx, sy, el2img(Back[x][y]), 0);
3301 else if (Store[x][y])
3302 DrawGraphic(sx, sy, el2img(Store[x][y]), 0);
3304 frame = getGraphicAnimationFrame(graphic, GfxFrame[x][y]);
3306 if (Back[x][y] || Store[x][y])
3307 DrawGraphicThruMask(sx, sy, graphic, frame);
3309 DrawGraphic(sx, sy, graphic, frame);
3312 void CheckDynamite(int x, int y)
3314 if (MovDelay[x][y] != 0) /* dynamite is still waiting to explode */
3318 if (MovDelay[x][y] != 0)
3321 PlayLevelSoundActionIfLoop(x, y, ACTION_ACTIVE);
3327 StopLevelSoundActionIfLoop(x, y, ACTION_ACTIVE);
3332 static void setMinimalPlayerBoundaries(int *sx1, int *sy1, int *sx2, int *sy2)
3334 boolean num_checked_players = 0;
3337 for (i = 0; i < MAX_PLAYERS; i++)
3339 if (stored_player[i].active)
3341 int sx = stored_player[i].jx;
3342 int sy = stored_player[i].jy;
3344 if (num_checked_players == 0)
3351 *sx1 = MIN(*sx1, sx);
3352 *sy1 = MIN(*sy1, sy);
3353 *sx2 = MAX(*sx2, sx);
3354 *sy2 = MAX(*sy2, sy);
3357 num_checked_players++;
3362 static boolean checkIfAllPlayersFitToScreen_RND()
3364 int sx1 = 0, sy1 = 0, sx2 = 0, sy2 = 0;
3366 setMinimalPlayerBoundaries(&sx1, &sy1, &sx2, &sy2);
3368 return (sx2 - sx1 < SCR_FIELDX &&
3369 sy2 - sy1 < SCR_FIELDY);
3372 static void setScreenCenteredToAllPlayers(int *sx, int *sy)
3374 int sx1 = scroll_x, sy1 = scroll_y, sx2 = scroll_x, sy2 = scroll_y;
3376 setMinimalPlayerBoundaries(&sx1, &sy1, &sx2, &sy2);
3378 *sx = (sx1 + sx2) / 2;
3379 *sy = (sy1 + sy2) / 2;
3382 void DrawRelocateScreen(int old_x, int old_y, int x, int y, int move_dir,
3383 boolean center_screen, boolean quick_relocation)
3385 boolean ffwd_delay = (tape.playing && tape.fast_forward);
3386 boolean no_delay = (tape.warp_forward);
3387 int frame_delay_value = (ffwd_delay ? FfwdFrameDelay : GameFrameDelay);
3388 int wait_delay_value = (no_delay ? 0 : frame_delay_value);
3390 if (quick_relocation)
3392 int offset = (setup.scroll_delay ? 3 : 0);
3394 if (!IN_VIS_FIELD(SCREENX(x), SCREENY(y)) || center_screen)
3398 scroll_x = (x < SBX_Left + MIDPOSX ? SBX_Left :
3399 x > SBX_Right + MIDPOSX ? SBX_Right :
3402 scroll_y = (y < SBY_Upper + MIDPOSY ? SBY_Upper :
3403 y > SBY_Lower + MIDPOSY ? SBY_Lower :
3408 /* quick relocation (without scrolling), but do not center screen */
3410 int center_scroll_x = (old_x < SBX_Left + MIDPOSX ? SBX_Left :
3411 old_x > SBX_Right + MIDPOSX ? SBX_Right :
3414 int center_scroll_y = (old_y < SBY_Upper + MIDPOSY ? SBY_Upper :
3415 old_y > SBY_Lower + MIDPOSY ? SBY_Lower :
3418 int offset_x = x + (scroll_x - center_scroll_x);
3419 int offset_y = y + (scroll_y - center_scroll_y);
3421 scroll_x = (offset_x < SBX_Left + MIDPOSX ? SBX_Left :
3422 offset_x > SBX_Right + MIDPOSX ? SBX_Right :
3423 offset_x - MIDPOSX);
3425 scroll_y = (offset_y < SBY_Upper + MIDPOSY ? SBY_Upper :
3426 offset_y > SBY_Lower + MIDPOSY ? SBY_Lower :
3427 offset_y - MIDPOSY);
3432 if ((move_dir == MV_LEFT && scroll_x > x - MIDPOSX + offset) ||
3433 (move_dir == MV_RIGHT && scroll_x < x - MIDPOSX - offset))
3434 scroll_x = x - MIDPOSX + (scroll_x < x - MIDPOSX ? -offset : +offset);
3436 if ((move_dir == MV_UP && scroll_y > y - MIDPOSY + offset) ||
3437 (move_dir == MV_DOWN && scroll_y < y - MIDPOSY - offset))
3438 scroll_y = y - MIDPOSY + (scroll_y < y - MIDPOSY ? -offset : +offset);
3440 /* don't scroll over playfield boundaries */
3441 if (scroll_x < SBX_Left || scroll_x > SBX_Right)
3442 scroll_x = (scroll_x < SBX_Left ? SBX_Left : SBX_Right);
3444 /* don't scroll over playfield boundaries */
3445 if (scroll_y < SBY_Upper || scroll_y > SBY_Lower)
3446 scroll_y = (scroll_y < SBY_Upper ? SBY_Upper : SBY_Lower);
3449 RedrawPlayfield(TRUE, 0,0,0,0);
3453 int scroll_xx = (x < SBX_Left + MIDPOSX ? SBX_Left :
3454 x > SBX_Right + MIDPOSX ? SBX_Right :
3457 int scroll_yy = (y < SBY_Upper + MIDPOSY ? SBY_Upper :
3458 y > SBY_Lower + MIDPOSY ? SBY_Lower :
3461 ScrollScreen(NULL, SCROLL_GO_ON); /* scroll last frame to full tile */
3463 while (scroll_x != scroll_xx || scroll_y != scroll_yy)
3466 int fx = FX, fy = FY;
3468 dx = (scroll_xx < scroll_x ? +1 : scroll_xx > scroll_x ? -1 : 0);
3469 dy = (scroll_yy < scroll_y ? +1 : scroll_yy > scroll_y ? -1 : 0);
3471 if (dx == 0 && dy == 0) /* no scrolling needed at all */
3477 fx += dx * TILEX / 2;
3478 fy += dy * TILEY / 2;
3480 ScrollLevel(dx, dy);
3483 /* scroll in two steps of half tile size to make things smoother */
3484 BlitBitmap(drawto_field, window, fx, fy, SXSIZE, SYSIZE, SX, SY);
3486 Delay(wait_delay_value);
3488 /* scroll second step to align at full tile size */
3490 Delay(wait_delay_value);
3495 Delay(wait_delay_value);
3499 void RelocatePlayer(int jx, int jy, int el_player_raw)
3501 int el_player = GET_PLAYER_ELEMENT(el_player_raw);
3502 int player_nr = GET_PLAYER_NR(el_player);
3503 struct PlayerInfo *player = &stored_player[player_nr];
3504 boolean ffwd_delay = (tape.playing && tape.fast_forward);
3505 boolean no_delay = (tape.warp_forward);
3506 int frame_delay_value = (ffwd_delay ? FfwdFrameDelay : GameFrameDelay);
3507 int wait_delay_value = (no_delay ? 0 : frame_delay_value);
3508 int old_jx = player->jx;
3509 int old_jy = player->jy;
3510 int old_element = Feld[old_jx][old_jy];
3511 int element = Feld[jx][jy];
3512 boolean player_relocated = (old_jx != jx || old_jy != jy);
3514 int move_dir_horiz = (jx < old_jx ? MV_LEFT : jx > old_jx ? MV_RIGHT : 0);
3515 int move_dir_vert = (jy < old_jy ? MV_UP : jy > old_jy ? MV_DOWN : 0);
3516 int enter_side_horiz = MV_DIR_OPPOSITE(move_dir_horiz);
3517 int enter_side_vert = MV_DIR_OPPOSITE(move_dir_vert);
3518 int leave_side_horiz = move_dir_horiz;
3519 int leave_side_vert = move_dir_vert;
3520 int enter_side = enter_side_horiz | enter_side_vert;
3521 int leave_side = leave_side_horiz | leave_side_vert;
3523 if (player->GameOver) /* do not reanimate dead player */
3526 if (!player_relocated) /* no need to relocate the player */
3529 if (IS_PLAYER(jx, jy)) /* player already placed at new position */
3531 RemoveField(jx, jy); /* temporarily remove newly placed player */
3532 DrawLevelField(jx, jy);
3535 if (player->present)
3537 while (player->MovPos)
3539 ScrollPlayer(player, SCROLL_GO_ON);
3540 ScrollScreen(NULL, SCROLL_GO_ON);
3542 AdvanceFrameAndPlayerCounters(player->index_nr);
3547 Delay(wait_delay_value);
3550 DrawPlayer(player); /* needed here only to cleanup last field */
3551 DrawLevelField(player->jx, player->jy); /* remove player graphic */
3553 player->is_moving = FALSE;
3556 if (IS_CUSTOM_ELEMENT(old_element))
3557 CheckElementChangeByPlayer(old_jx, old_jy, old_element,
3559 player->index_bit, leave_side);
3561 CheckTriggeredElementChangeByPlayer(old_jx, old_jy, old_element,
3563 player->index_bit, leave_side);
3565 Feld[jx][jy] = el_player;
3566 InitPlayerField(jx, jy, el_player, TRUE);
3568 if (!ELEM_IS_PLAYER(element)) /* player may be set on walkable element */
3570 Feld[jx][jy] = element;
3571 InitField(jx, jy, FALSE);
3574 /* only visually relocate centered player */
3575 DrawRelocateScreen(old_jx, old_jy, player->jx, player->jy, player->MovDir,
3576 FALSE, level.instant_relocation);
3578 TestIfPlayerTouchesBadThing(jx, jy);
3579 TestIfPlayerTouchesCustomElement(jx, jy);
3581 if (IS_CUSTOM_ELEMENT(element))
3582 CheckElementChangeByPlayer(jx, jy, element, CE_ENTERED_BY_PLAYER,
3583 player->index_bit, enter_side);
3585 CheckTriggeredElementChangeByPlayer(jx, jy, element, CE_PLAYER_ENTERS_X,
3586 player->index_bit, enter_side);
3589 void Explode(int ex, int ey, int phase, int mode)
3595 /* !!! eliminate this variable !!! */
3596 int delay = (game.emulation == EMU_SUPAPLEX ? 3 : 2);
3598 if (game.explosions_delayed)
3600 ExplodeField[ex][ey] = mode;
3604 if (phase == EX_PHASE_START) /* initialize 'Store[][]' field */
3606 int center_element = Feld[ex][ey];
3607 int artwork_element, explosion_element; /* set these values later */
3610 /* --- This is only really needed (and now handled) in "Impact()". --- */
3611 /* do not explode moving elements that left the explode field in time */
3612 if (game.engine_version >= VERSION_IDENT(2,2,0,7) &&
3613 center_element == EL_EMPTY &&
3614 (mode == EX_TYPE_NORMAL || mode == EX_TYPE_CENTER))
3619 /* !!! at this place, the center element may be EL_BLOCKED !!! */
3620 if (mode == EX_TYPE_NORMAL ||
3621 mode == EX_TYPE_CENTER ||
3622 mode == EX_TYPE_CROSS)
3623 PlayLevelSoundElementAction(ex, ey, artwork_element, ACTION_EXPLODING);
3626 /* remove things displayed in background while burning dynamite */
3627 if (Back[ex][ey] != EL_EMPTY && !IS_INDESTRUCTIBLE(Back[ex][ey]))
3630 if (IS_MOVING(ex, ey) || IS_BLOCKED(ex, ey))
3632 /* put moving element to center field (and let it explode there) */
3633 center_element = MovingOrBlocked2Element(ex, ey);
3634 RemoveMovingField(ex, ey);
3635 Feld[ex][ey] = center_element;
3638 /* now "center_element" is finally determined -- set related values now */
3639 artwork_element = center_element; /* for custom player artwork */
3640 explosion_element = center_element; /* for custom player artwork */
3642 if (IS_PLAYER(ex, ey))
3644 int player_nr = GET_PLAYER_NR(StorePlayer[ex][ey]);
3646 artwork_element = stored_player[player_nr].artwork_element;
3648 if (level.use_explosion_element[player_nr])
3650 explosion_element = level.explosion_element[player_nr];
3651 artwork_element = explosion_element;
3656 if (mode == EX_TYPE_NORMAL ||
3657 mode == EX_TYPE_CENTER ||
3658 mode == EX_TYPE_CROSS)
3659 PlayLevelSoundElementAction(ex, ey, artwork_element, ACTION_EXPLODING);
3662 last_phase = element_info[explosion_element].explosion_delay + 1;
3664 for (y = ey - 1; y <= ey + 1; y++) for (x = ex - 1; x <= ex + 1; x++)
3666 int xx = x - ex + 1;
3667 int yy = y - ey + 1;
3670 if (!IN_LEV_FIELD(x, y) ||
3671 (mode & EX_TYPE_SINGLE_TILE && (x != ex || y != ey)) ||
3672 (mode == EX_TYPE_CROSS && (x != ex && y != ey)))
3675 element = Feld[x][y];
3677 if (IS_MOVING(x, y) || IS_BLOCKED(x, y))
3679 element = MovingOrBlocked2Element(x, y);
3681 if (!IS_EXPLOSION_PROOF(element))
3682 RemoveMovingField(x, y);
3685 /* indestructible elements can only explode in center (but not flames) */
3686 if ((IS_EXPLOSION_PROOF(element) && (x != ex || y != ey ||
3687 mode == EX_TYPE_BORDER)) ||
3688 element == EL_FLAMES)
3691 /* no idea why this was changed from 3.0.8 to 3.1.0 -- this causes buggy
3692 behaviour, for example when touching a yamyam that explodes to rocks
3693 with active deadly shield, a rock is created under the player !!! */
3694 /* (case 1 (surely buggy): >= 3.1.0, case 2 (maybe buggy): <= 3.0.8) */
3696 if (IS_PLAYER(x, y) && SHIELD_ON(PLAYERINFO(x, y)) &&
3697 (game.engine_version < VERSION_IDENT(3,1,0,0) ||
3698 (x == ex && y == ey && mode != EX_TYPE_BORDER)))
3700 if (IS_PLAYER(x, y) && SHIELD_ON(PLAYERINFO(x, y)))
3703 if (IS_ACTIVE_BOMB(element))
3705 /* re-activate things under the bomb like gate or penguin */
3706 Feld[x][y] = (Back[x][y] ? Back[x][y] : EL_EMPTY);
3713 /* save walkable background elements while explosion on same tile */
3714 if (IS_WALKABLE(element) && IS_INDESTRUCTIBLE(element) &&
3715 (x != ex || y != ey || mode == EX_TYPE_BORDER))
3716 Back[x][y] = element;
3718 /* ignite explodable elements reached by other explosion */
3719 if (element == EL_EXPLOSION)
3720 element = Store2[x][y];
3722 if (AmoebaNr[x][y] &&
3723 (element == EL_AMOEBA_FULL ||
3724 element == EL_BD_AMOEBA ||
3725 element == EL_AMOEBA_GROWING))
3727 AmoebaCnt[AmoebaNr[x][y]]--;
3728 AmoebaCnt2[AmoebaNr[x][y]]--;
3733 if (IS_PLAYER(ex, ey) && !PLAYER_EXPLOSION_PROTECTED(ex, ey))
3735 int player_nr = StorePlayer[ex][ey] - EL_PLAYER_1;
3737 Store[x][y] = EL_PLAYER_IS_EXPLODING_1 + player_nr;
3739 if (PLAYERINFO(ex, ey)->use_murphy)
3740 Store[x][y] = EL_EMPTY;
3743 /* !!! check this case -- currently needed for rnd_rado_negundo_v,
3744 !!! levels 015 018 019 020 021 022 023 026 027 028 !!! */
3745 else if (ELEM_IS_PLAYER(center_element))
3746 Store[x][y] = EL_EMPTY;
3747 else if (center_element == EL_YAMYAM)
3748 Store[x][y] = level.yamyam_content[game.yamyam_content_nr].e[xx][yy];
3749 else if (element_info[center_element].content.e[xx][yy] != EL_EMPTY)
3750 Store[x][y] = element_info[center_element].content.e[xx][yy];
3752 /* needed because EL_BD_BUTTERFLY is not defined as "CAN_EXPLODE"
3753 (killing EL_BD_BUTTERFLY with dynamite would result in BD diamond
3754 otherwise) -- FIX THIS !!! */
3755 else if (!CAN_EXPLODE(element) && element != EL_BD_BUTTERFLY)
3756 Store[x][y] = element_info[element].content.e[1][1];
3758 else if (!CAN_EXPLODE(element))
3759 Store[x][y] = element_info[element].content.e[1][1];
3762 Store[x][y] = EL_EMPTY;
3764 if (x != ex || y != ey || mode == EX_TYPE_BORDER ||
3765 center_element == EL_AMOEBA_TO_DIAMOND)
3766 Store2[x][y] = element;
3768 Feld[x][y] = EL_EXPLOSION;
3769 GfxElement[x][y] = artwork_element;
3771 ExplodePhase[x][y] = 1;
3772 ExplodeDelay[x][y] = last_phase;
3777 if (center_element == EL_YAMYAM)
3778 game.yamyam_content_nr =
3779 (game.yamyam_content_nr + 1) % level.num_yamyam_contents;
3791 GfxFrame[x][y] = 0; /* restart explosion animation */
3793 last_phase = ExplodeDelay[x][y];
3795 ExplodePhase[x][y] = (phase < last_phase ? phase + 1 : 0);
3799 /* activate this even in non-DEBUG version until cause for crash in
3800 getGraphicAnimationFrame() (see below) is found and eliminated */
3806 /* this can happen if the player leaves an explosion just in time */
3807 if (GfxElement[x][y] == EL_UNDEFINED)
3808 GfxElement[x][y] = EL_EMPTY;
3810 if (GfxElement[x][y] == EL_UNDEFINED)
3813 printf("Explode(): x = %d, y = %d: GfxElement == EL_UNDEFINED\n", x, y);
3814 printf("Explode(): This should never happen!\n");
3817 GfxElement[x][y] = EL_EMPTY;
3823 border_element = Store2[x][y];
3824 if (IS_PLAYER(x, y) && !PLAYER_EXPLOSION_PROTECTED(x, y))
3825 border_element = StorePlayer[x][y];
3827 if (phase == element_info[border_element].ignition_delay ||
3828 phase == last_phase)
3830 boolean border_explosion = FALSE;
3832 if (IS_PLAYER(x, y) && PLAYERINFO(x, y)->present &&
3833 !PLAYER_EXPLOSION_PROTECTED(x, y))
3835 KillPlayerUnlessExplosionProtected(x, y);
3836 border_explosion = TRUE;
3838 else if (CAN_EXPLODE_BY_EXPLOSION(border_element))
3840 Feld[x][y] = Store2[x][y];
3843 border_explosion = TRUE;
3845 else if (border_element == EL_AMOEBA_TO_DIAMOND)
3847 AmoebeUmwandeln(x, y);
3849 border_explosion = TRUE;
3852 /* if an element just explodes due to another explosion (chain-reaction),
3853 do not immediately end the new explosion when it was the last frame of
3854 the explosion (as it would be done in the following "if"-statement!) */
3855 if (border_explosion && phase == last_phase)
3859 if (phase == last_phase)
3863 element = Feld[x][y] = Store[x][y];
3864 Store[x][y] = Store2[x][y] = 0;
3865 GfxElement[x][y] = EL_UNDEFINED;
3867 /* player can escape from explosions and might therefore be still alive */
3868 if (element >= EL_PLAYER_IS_EXPLODING_1 &&
3869 element <= EL_PLAYER_IS_EXPLODING_4)
3871 int player_nr = element - EL_PLAYER_IS_EXPLODING_1;
3872 int explosion_element = EL_PLAYER_1 + player_nr;
3873 int xx = MIN(MAX(0, x - stored_player[player_nr].jx + 1), 2);
3874 int yy = MIN(MAX(0, y - stored_player[player_nr].jy + 1), 2);
3876 if (level.use_explosion_element[player_nr])
3877 explosion_element = level.explosion_element[player_nr];
3879 Feld[x][y] = (stored_player[player_nr].active ? EL_EMPTY :
3880 element_info[explosion_element].content.e[xx][yy]);
3883 /* restore probably existing indestructible background element */
3884 if (Back[x][y] && IS_INDESTRUCTIBLE(Back[x][y]))
3885 element = Feld[x][y] = Back[x][y];
3888 MovDir[x][y] = MovPos[x][y] = MovDelay[x][y] = 0;
3889 GfxDir[x][y] = MV_NONE;
3890 ChangeDelay[x][y] = 0;
3891 ChangePage[x][y] = -1;
3893 #if USE_NEW_CUSTOM_VALUE
3894 CustomValue[x][y] = 0;
3897 InitField_WithBug2(x, y, FALSE);
3899 DrawLevelField(x, y);
3901 TestIfElementTouchesCustomElement(x, y);
3903 if (GFX_CRUMBLED(element))
3904 DrawLevelFieldCrumbledSandNeighbours(x, y);
3906 if (IS_PLAYER(x, y) && !PLAYERINFO(x, y)->present)
3907 StorePlayer[x][y] = 0;
3909 if (ELEM_IS_PLAYER(element))
3910 RelocatePlayer(x, y, element);
3912 else if (IN_SCR_FIELD(SCREENX(x), SCREENY(y)))
3914 int graphic = el_act2img(GfxElement[x][y], ACTION_EXPLODING);
3915 int frame = getGraphicAnimationFrame(graphic, GfxFrame[x][y]);
3918 DrawLevelFieldCrumbledSand(x, y);
3920 if (IS_WALKABLE_OVER(Back[x][y]) && Back[x][y] != EL_EMPTY)
3922 DrawLevelElement(x, y, Back[x][y]);
3923 DrawGraphicThruMask(SCREENX(x), SCREENY(y), graphic, frame);
3925 else if (IS_WALKABLE_UNDER(Back[x][y]))
3927 DrawGraphic(SCREENX(x), SCREENY(y), graphic, frame);
3928 DrawLevelElementThruMask(x, y, Back[x][y]);
3930 else if (!IS_WALKABLE_INSIDE(Back[x][y]))
3931 DrawGraphic(SCREENX(x), SCREENY(y), graphic, frame);
3935 void DynaExplode(int ex, int ey)
3938 int dynabomb_element = Feld[ex][ey];
3939 int dynabomb_size = 1;
3940 boolean dynabomb_xl = FALSE;
3941 struct PlayerInfo *player;
3942 static int xy[4][2] =
3950 if (IS_ACTIVE_BOMB(dynabomb_element))
3952 player = &stored_player[dynabomb_element - EL_DYNABOMB_PLAYER_1_ACTIVE];
3953 dynabomb_size = player->dynabomb_size;
3954 dynabomb_xl = player->dynabomb_xl;
3955 player->dynabombs_left++;
3958 Explode(ex, ey, EX_PHASE_START, EX_TYPE_CENTER);
3960 for (i = 0; i < NUM_DIRECTIONS; i++)
3962 for (j = 1; j <= dynabomb_size; j++)
3964 int x = ex + j * xy[i][0];
3965 int y = ey + j * xy[i][1];
3968 if (!IN_LEV_FIELD(x, y) || IS_INDESTRUCTIBLE(Feld[x][y]))
3971 element = Feld[x][y];
3973 /* do not restart explosions of fields with active bombs */
3974 if (element == EL_EXPLOSION && IS_ACTIVE_BOMB(Store2[x][y]))
3977 Explode(x, y, EX_PHASE_START, EX_TYPE_BORDER);
3979 if (element != EL_EMPTY && element != EL_EXPLOSION &&
3980 !IS_DIGGABLE(element) && !dynabomb_xl)
3986 void Bang(int x, int y)
3988 int element = MovingOrBlocked2Element(x, y);
3989 int explosion_type = EX_TYPE_NORMAL;
3991 if (IS_PLAYER(x, y) && !PLAYER_EXPLOSION_PROTECTED(x, y))
3993 struct PlayerInfo *player = PLAYERINFO(x, y);
3995 element = Feld[x][y] = (player->use_murphy ? EL_SP_MURPHY :
3996 player->element_nr);
3998 if (level.use_explosion_element[player->index_nr])
4000 int explosion_element = level.explosion_element[player->index_nr];
4002 if (element_info[explosion_element].explosion_type == EXPLODES_CROSS)
4003 explosion_type = EX_TYPE_CROSS;
4004 else if (element_info[explosion_element].explosion_type == EXPLODES_1X1)
4005 explosion_type = EX_TYPE_CENTER;
4013 case EL_BD_BUTTERFLY:
4016 case EL_DARK_YAMYAM:
4020 RaiseScoreElement(element);
4023 case EL_DYNABOMB_PLAYER_1_ACTIVE:
4024 case EL_DYNABOMB_PLAYER_2_ACTIVE:
4025 case EL_DYNABOMB_PLAYER_3_ACTIVE:
4026 case EL_DYNABOMB_PLAYER_4_ACTIVE:
4027 case EL_DYNABOMB_INCREASE_NUMBER:
4028 case EL_DYNABOMB_INCREASE_SIZE:
4029 case EL_DYNABOMB_INCREASE_POWER:
4030 explosion_type = EX_TYPE_DYNA;
4035 case EL_LAMP_ACTIVE:
4036 case EL_AMOEBA_TO_DIAMOND:
4037 if (!IS_PLAYER(x, y)) /* penguin and player may be at same field */
4038 explosion_type = EX_TYPE_CENTER;
4042 if (element_info[element].explosion_type == EXPLODES_CROSS)
4043 explosion_type = EX_TYPE_CROSS;
4044 else if (element_info[element].explosion_type == EXPLODES_1X1)
4045 explosion_type = EX_TYPE_CENTER;
4049 if (explosion_type == EX_TYPE_DYNA)
4052 Explode(x, y, EX_PHASE_START, explosion_type);
4054 CheckTriggeredElementChange(x, y, element, CE_EXPLOSION_OF_X);
4057 void SplashAcid(int x, int y)
4059 if (IN_LEV_FIELD(x - 1, y - 1) && IS_FREE(x - 1, y - 1) &&
4060 (!IN_LEV_FIELD(x - 1, y - 2) ||
4061 !CAN_FALL(MovingOrBlocked2Element(x - 1, y - 2))))
4062 Feld[x - 1][y - 1] = EL_ACID_SPLASH_LEFT;
4064 if (IN_LEV_FIELD(x + 1, y - 1) && IS_FREE(x + 1, y - 1) &&
4065 (!IN_LEV_FIELD(x + 1, y - 2) ||
4066 !CAN_FALL(MovingOrBlocked2Element(x + 1, y - 2))))
4067 Feld[x + 1][y - 1] = EL_ACID_SPLASH_RIGHT;
4069 PlayLevelSound(x, y, SND_ACID_SPLASHING);
4072 static void InitBeltMovement()
4074 static int belt_base_element[4] =
4076 EL_CONVEYOR_BELT_1_LEFT,
4077 EL_CONVEYOR_BELT_2_LEFT,
4078 EL_CONVEYOR_BELT_3_LEFT,
4079 EL_CONVEYOR_BELT_4_LEFT
4081 static int belt_base_active_element[4] =
4083 EL_CONVEYOR_BELT_1_LEFT_ACTIVE,
4084 EL_CONVEYOR_BELT_2_LEFT_ACTIVE,
4085 EL_CONVEYOR_BELT_3_LEFT_ACTIVE,
4086 EL_CONVEYOR_BELT_4_LEFT_ACTIVE
4091 /* set frame order for belt animation graphic according to belt direction */
4092 for (i = 0; i < NUM_BELTS; i++)
4096 for (j = 0; j < NUM_BELT_PARTS; j++)
4098 int element = belt_base_active_element[belt_nr] + j;
4099 int graphic = el2img(element);
4101 if (game.belt_dir[i] == MV_LEFT)
4102 graphic_info[graphic].anim_mode &= ~ANIM_REVERSE;
4104 graphic_info[graphic].anim_mode |= ANIM_REVERSE;
4108 SCAN_PLAYFIELD(x, y)
4110 int element = Feld[x][y];
4112 for (i = 0; i < NUM_BELTS; i++)
4114 if (IS_BELT(element) && game.belt_dir[i] != MV_NONE)
4116 int e_belt_nr = getBeltNrFromBeltElement(element);
4119 if (e_belt_nr == belt_nr)
4121 int belt_part = Feld[x][y] - belt_base_element[belt_nr];
4123 Feld[x][y] = belt_base_active_element[belt_nr] + belt_part;
4130 static void ToggleBeltSwitch(int x, int y)
4132 static int belt_base_element[4] =
4134 EL_CONVEYOR_BELT_1_LEFT,
4135 EL_CONVEYOR_BELT_2_LEFT,
4136 EL_CONVEYOR_BELT_3_LEFT,
4137 EL_CONVEYOR_BELT_4_LEFT
4139 static int belt_base_active_element[4] =
4141 EL_CONVEYOR_BELT_1_LEFT_ACTIVE,
4142 EL_CONVEYOR_BELT_2_LEFT_ACTIVE,
4143 EL_CONVEYOR_BELT_3_LEFT_ACTIVE,
4144 EL_CONVEYOR_BELT_4_LEFT_ACTIVE
4146 static int belt_base_switch_element[4] =
4148 EL_CONVEYOR_BELT_1_SWITCH_LEFT,
4149 EL_CONVEYOR_BELT_2_SWITCH_LEFT,
4150 EL_CONVEYOR_BELT_3_SWITCH_LEFT,
4151 EL_CONVEYOR_BELT_4_SWITCH_LEFT
4153 static int belt_move_dir[4] =
4161 int element = Feld[x][y];
4162 int belt_nr = getBeltNrFromBeltSwitchElement(element);
4163 int belt_dir_nr = (game.belt_dir_nr[belt_nr] + 1) % 4;
4164 int belt_dir = belt_move_dir[belt_dir_nr];
4167 if (!IS_BELT_SWITCH(element))
4170 game.belt_dir_nr[belt_nr] = belt_dir_nr;
4171 game.belt_dir[belt_nr] = belt_dir;
4173 if (belt_dir_nr == 3)
4176 /* set frame order for belt animation graphic according to belt direction */
4177 for (i = 0; i < NUM_BELT_PARTS; i++)
4179 int element = belt_base_active_element[belt_nr] + i;
4180 int graphic = el2img(element);
4182 if (belt_dir == MV_LEFT)
4183 graphic_info[graphic].anim_mode &= ~ANIM_REVERSE;
4185 graphic_info[graphic].anim_mode |= ANIM_REVERSE;
4188 SCAN_PLAYFIELD(xx, yy)
4190 int element = Feld[xx][yy];
4192 if (IS_BELT_SWITCH(element))
4194 int e_belt_nr = getBeltNrFromBeltSwitchElement(element);
4196 if (e_belt_nr == belt_nr)
4198 Feld[xx][yy] = belt_base_switch_element[belt_nr] + belt_dir_nr;
4199 DrawLevelField(xx, yy);
4202 else if (IS_BELT(element) && belt_dir != MV_NONE)
4204 int e_belt_nr = getBeltNrFromBeltElement(element);
4206 if (e_belt_nr == belt_nr)
4208 int belt_part = Feld[xx][yy] - belt_base_element[belt_nr];
4210 Feld[xx][yy] = belt_base_active_element[belt_nr] + belt_part;
4211 DrawLevelField(xx, yy);
4214 else if (IS_BELT_ACTIVE(element) && belt_dir == MV_NONE)
4216 int e_belt_nr = getBeltNrFromBeltActiveElement(element);
4218 if (e_belt_nr == belt_nr)
4220 int belt_part = Feld[xx][yy] - belt_base_active_element[belt_nr];
4222 Feld[xx][yy] = belt_base_element[belt_nr] + belt_part;
4223 DrawLevelField(xx, yy);
4229 static void ToggleSwitchgateSwitch(int x, int y)
4233 game.switchgate_pos = !game.switchgate_pos;
4235 SCAN_PLAYFIELD(xx, yy)
4237 int element = Feld[xx][yy];
4239 #if !USE_BOTH_SWITCHGATE_SWITCHES
4240 if (element == EL_SWITCHGATE_SWITCH_UP ||
4241 element == EL_SWITCHGATE_SWITCH_DOWN)
4243 Feld[xx][yy] = EL_SWITCHGATE_SWITCH_UP + game.switchgate_pos;
4244 DrawLevelField(xx, yy);
4247 if (element == EL_SWITCHGATE_SWITCH_UP)
4249 Feld[xx][yy] = EL_SWITCHGATE_SWITCH_DOWN;
4250 DrawLevelField(xx, yy);
4252 else if (element == EL_SWITCHGATE_SWITCH_DOWN)
4254 Feld[xx][yy] = EL_SWITCHGATE_SWITCH_UP;
4255 DrawLevelField(xx, yy);
4258 else if (element == EL_SWITCHGATE_OPEN ||
4259 element == EL_SWITCHGATE_OPENING)
4261 Feld[xx][yy] = EL_SWITCHGATE_CLOSING;
4263 PlayLevelSoundAction(xx, yy, ACTION_CLOSING);
4265 else if (element == EL_SWITCHGATE_CLOSED ||
4266 element == EL_SWITCHGATE_CLOSING)
4268 Feld[xx][yy] = EL_SWITCHGATE_OPENING;
4270 PlayLevelSoundAction(xx, yy, ACTION_OPENING);
4275 static int getInvisibleActiveFromInvisibleElement(int element)
4277 return (element == EL_INVISIBLE_STEELWALL ? EL_INVISIBLE_STEELWALL_ACTIVE :
4278 element == EL_INVISIBLE_WALL ? EL_INVISIBLE_WALL_ACTIVE :
4279 element == EL_INVISIBLE_SAND ? EL_INVISIBLE_SAND_ACTIVE :
4283 static int getInvisibleFromInvisibleActiveElement(int element)
4285 return (element == EL_INVISIBLE_STEELWALL_ACTIVE ? EL_INVISIBLE_STEELWALL :
4286 element == EL_INVISIBLE_WALL_ACTIVE ? EL_INVISIBLE_WALL :
4287 element == EL_INVISIBLE_SAND_ACTIVE ? EL_INVISIBLE_SAND :
4291 static void RedrawAllLightSwitchesAndInvisibleElements()
4295 SCAN_PLAYFIELD(x, y)
4297 int element = Feld[x][y];
4299 if (element == EL_LIGHT_SWITCH &&
4300 game.light_time_left > 0)
4302 Feld[x][y] = EL_LIGHT_SWITCH_ACTIVE;
4303 DrawLevelField(x, y);
4305 else if (element == EL_LIGHT_SWITCH_ACTIVE &&
4306 game.light_time_left == 0)
4308 Feld[x][y] = EL_LIGHT_SWITCH;
4309 DrawLevelField(x, y);
4311 else if (element == EL_EMC_DRIPPER &&
4312 game.light_time_left > 0)
4314 Feld[x][y] = EL_EMC_DRIPPER_ACTIVE;
4315 DrawLevelField(x, y);
4317 else if (element == EL_EMC_DRIPPER_ACTIVE &&
4318 game.light_time_left == 0)
4320 Feld[x][y] = EL_EMC_DRIPPER;
4321 DrawLevelField(x, y);
4323 else if (element == EL_INVISIBLE_STEELWALL ||
4324 element == EL_INVISIBLE_WALL ||
4325 element == EL_INVISIBLE_SAND)
4327 if (game.light_time_left > 0)
4328 Feld[x][y] = getInvisibleActiveFromInvisibleElement(element);
4330 DrawLevelField(x, y);
4332 /* uncrumble neighbour fields, if needed */
4333 if (element == EL_INVISIBLE_SAND)
4334 DrawLevelFieldCrumbledSandNeighbours(x, y);
4336 else if (element == EL_INVISIBLE_STEELWALL_ACTIVE ||
4337 element == EL_INVISIBLE_WALL_ACTIVE ||
4338 element == EL_INVISIBLE_SAND_ACTIVE)
4340 if (game.light_time_left == 0)
4341 Feld[x][y] = getInvisibleFromInvisibleActiveElement(element);
4343 DrawLevelField(x, y);
4345 /* re-crumble neighbour fields, if needed */
4346 if (element == EL_INVISIBLE_SAND)
4347 DrawLevelFieldCrumbledSandNeighbours(x, y);
4352 static void RedrawAllInvisibleElementsForLenses()
4356 SCAN_PLAYFIELD(x, y)
4358 int element = Feld[x][y];
4360 if (element == EL_EMC_DRIPPER &&
4361 game.lenses_time_left > 0)
4363 Feld[x][y] = EL_EMC_DRIPPER_ACTIVE;
4364 DrawLevelField(x, y);
4366 else if (element == EL_EMC_DRIPPER_ACTIVE &&
4367 game.lenses_time_left == 0)
4369 Feld[x][y] = EL_EMC_DRIPPER;
4370 DrawLevelField(x, y);
4372 else if (element == EL_INVISIBLE_STEELWALL ||
4373 element == EL_INVISIBLE_WALL ||
4374 element == EL_INVISIBLE_SAND)
4376 if (game.lenses_time_left > 0)
4377 Feld[x][y] = getInvisibleActiveFromInvisibleElement(element);
4379 DrawLevelField(x, y);
4381 /* uncrumble neighbour fields, if needed */
4382 if (element == EL_INVISIBLE_SAND)
4383 DrawLevelFieldCrumbledSandNeighbours(x, y);
4385 else if (element == EL_INVISIBLE_STEELWALL_ACTIVE ||
4386 element == EL_INVISIBLE_WALL_ACTIVE ||
4387 element == EL_INVISIBLE_SAND_ACTIVE)
4389 if (game.lenses_time_left == 0)
4390 Feld[x][y] = getInvisibleFromInvisibleActiveElement(element);
4392 DrawLevelField(x, y);
4394 /* re-crumble neighbour fields, if needed */
4395 if (element == EL_INVISIBLE_SAND)
4396 DrawLevelFieldCrumbledSandNeighbours(x, y);
4401 static void RedrawAllInvisibleElementsForMagnifier()
4405 SCAN_PLAYFIELD(x, y)
4407 int element = Feld[x][y];
4409 if (element == EL_EMC_FAKE_GRASS &&
4410 game.magnify_time_left > 0)
4412 Feld[x][y] = EL_EMC_FAKE_GRASS_ACTIVE;
4413 DrawLevelField(x, y);
4415 else if (element == EL_EMC_FAKE_GRASS_ACTIVE &&
4416 game.magnify_time_left == 0)
4418 Feld[x][y] = EL_EMC_FAKE_GRASS;
4419 DrawLevelField(x, y);
4421 else if (IS_GATE_GRAY(element) &&
4422 game.magnify_time_left > 0)
4424 Feld[x][y] = (IS_RND_GATE_GRAY(element) ?
4425 element - EL_GATE_1_GRAY + EL_GATE_1_GRAY_ACTIVE :
4426 IS_EM_GATE_GRAY(element) ?
4427 element - EL_EM_GATE_1_GRAY + EL_EM_GATE_1_GRAY_ACTIVE :
4428 IS_EMC_GATE_GRAY(element) ?
4429 element - EL_EMC_GATE_5_GRAY + EL_EMC_GATE_5_GRAY_ACTIVE :
4431 DrawLevelField(x, y);
4433 else if (IS_GATE_GRAY_ACTIVE(element) &&
4434 game.magnify_time_left == 0)
4436 Feld[x][y] = (IS_RND_GATE_GRAY_ACTIVE(element) ?
4437 element - EL_GATE_1_GRAY_ACTIVE + EL_GATE_1_GRAY :
4438 IS_EM_GATE_GRAY_ACTIVE(element) ?
4439 element - EL_EM_GATE_1_GRAY_ACTIVE + EL_EM_GATE_1_GRAY :
4440 IS_EMC_GATE_GRAY_ACTIVE(element) ?
4441 element - EL_EMC_GATE_5_GRAY_ACTIVE + EL_EMC_GATE_5_GRAY :
4443 DrawLevelField(x, y);
4448 static void ToggleLightSwitch(int x, int y)
4450 int element = Feld[x][y];
4452 game.light_time_left =
4453 (element == EL_LIGHT_SWITCH ?
4454 level.time_light * FRAMES_PER_SECOND : 0);
4456 RedrawAllLightSwitchesAndInvisibleElements();
4459 static void ActivateTimegateSwitch(int x, int y)
4463 game.timegate_time_left = level.time_timegate * FRAMES_PER_SECOND;
4465 SCAN_PLAYFIELD(xx, yy)
4467 int element = Feld[xx][yy];
4469 if (element == EL_TIMEGATE_CLOSED ||
4470 element == EL_TIMEGATE_CLOSING)
4472 Feld[xx][yy] = EL_TIMEGATE_OPENING;
4473 PlayLevelSound(xx, yy, SND_TIMEGATE_OPENING);
4477 else if (element == EL_TIMEGATE_SWITCH_ACTIVE)
4479 Feld[xx][yy] = EL_TIMEGATE_SWITCH;
4480 DrawLevelField(xx, yy);
4486 Feld[x][y] = EL_TIMEGATE_SWITCH_ACTIVE;
4489 void Impact(int x, int y)
4491 boolean last_line = (y == lev_fieldy - 1);
4492 boolean object_hit = FALSE;
4493 boolean impact = (last_line || object_hit);
4494 int element = Feld[x][y];
4495 int smashed = EL_STEELWALL;
4497 if (!last_line) /* check if element below was hit */
4499 if (Feld[x][y + 1] == EL_PLAYER_IS_LEAVING)
4502 object_hit = (!IS_FREE(x, y + 1) && (!IS_MOVING(x, y + 1) ||
4503 MovDir[x][y + 1] != MV_DOWN ||
4504 MovPos[x][y + 1] <= TILEY / 2));
4506 /* do not smash moving elements that left the smashed field in time */
4507 if (game.engine_version >= VERSION_IDENT(2,2,0,7) && IS_MOVING(x, y + 1) &&
4508 ABS(MovPos[x][y + 1] + getElementMoveStepsize(x, y + 1)) >= TILEX)
4511 #if USE_QUICKSAND_IMPACT_BUGFIX
4512 if (Feld[x][y + 1] == EL_QUICKSAND_EMPTYING && object_hit == FALSE)
4514 RemoveMovingField(x, y + 1);
4515 Feld[x][y + 1] = EL_QUICKSAND_EMPTY;
4516 Feld[x][y + 2] = EL_ROCK;
4517 DrawLevelField(x, y + 2);
4524 smashed = MovingOrBlocked2Element(x, y + 1);
4526 impact = (last_line || object_hit);
4529 if (!last_line && smashed == EL_ACID) /* element falls into acid */
4531 SplashAcid(x, y + 1);
4535 /* !!! not sufficient for all cases -- see EL_PEARL below !!! */
4536 /* only reset graphic animation if graphic really changes after impact */
4538 el_act_dir2img(element, GfxAction[x][y], MV_DOWN) != el2img(element))
4540 ResetGfxAnimation(x, y);
4541 DrawLevelField(x, y);
4544 if (impact && CAN_EXPLODE_IMPACT(element))
4549 else if (impact && element == EL_PEARL)
4551 ResetGfxAnimation(x, y);
4553 Feld[x][y] = EL_PEARL_BREAKING;
4554 PlayLevelSound(x, y, SND_PEARL_BREAKING);
4557 else if (impact && CheckElementChange(x, y, element, smashed, CE_IMPACT))
4559 PlayLevelSoundElementAction(x, y, element, ACTION_IMPACT);
4564 if (impact && element == EL_AMOEBA_DROP)
4566 if (object_hit && IS_PLAYER(x, y + 1))
4567 KillPlayerUnlessEnemyProtected(x, y + 1);
4568 else if (object_hit && smashed == EL_PENGUIN)
4572 Feld[x][y] = EL_AMOEBA_GROWING;
4573 Store[x][y] = EL_AMOEBA_WET;
4575 ResetRandomAnimationValue(x, y);
4580 if (object_hit) /* check which object was hit */
4582 if (CAN_PASS_MAGIC_WALL(element) &&
4583 (smashed == EL_MAGIC_WALL ||
4584 smashed == EL_BD_MAGIC_WALL))
4587 int activated_magic_wall =
4588 (smashed == EL_MAGIC_WALL ? EL_MAGIC_WALL_ACTIVE :
4589 EL_BD_MAGIC_WALL_ACTIVE);
4591 /* activate magic wall / mill */
4592 SCAN_PLAYFIELD(xx, yy)
4593 if (Feld[xx][yy] == smashed)
4594 Feld[xx][yy] = activated_magic_wall;
4596 game.magic_wall_time_left = level.time_magic_wall * FRAMES_PER_SECOND;
4597 game.magic_wall_active = TRUE;
4599 PlayLevelSound(x, y, (smashed == EL_MAGIC_WALL ?
4600 SND_MAGIC_WALL_ACTIVATING :
4601 SND_BD_MAGIC_WALL_ACTIVATING));
4604 if (IS_PLAYER(x, y + 1))
4606 if (CAN_SMASH_PLAYER(element))
4608 KillPlayerUnlessEnemyProtected(x, y + 1);
4612 else if (smashed == EL_PENGUIN)
4614 if (CAN_SMASH_PLAYER(element))
4620 else if (element == EL_BD_DIAMOND)
4622 if (IS_CLASSIC_ENEMY(smashed) && IS_BD_ELEMENT(smashed))
4628 else if (((element == EL_SP_INFOTRON ||
4629 element == EL_SP_ZONK) &&
4630 (smashed == EL_SP_SNIKSNAK ||
4631 smashed == EL_SP_ELECTRON ||
4632 smashed == EL_SP_DISK_ORANGE)) ||
4633 (element == EL_SP_INFOTRON &&
4634 smashed == EL_SP_DISK_YELLOW))
4639 else if (CAN_SMASH_EVERYTHING(element))
4641 if (IS_CLASSIC_ENEMY(smashed) ||
4642 CAN_EXPLODE_SMASHED(smashed))
4647 else if (!IS_MOVING(x, y + 1) && !IS_BLOCKED(x, y + 1))
4649 if (smashed == EL_LAMP ||
4650 smashed == EL_LAMP_ACTIVE)
4655 else if (smashed == EL_NUT)
4657 Feld[x][y + 1] = EL_NUT_BREAKING;
4658 PlayLevelSound(x, y, SND_NUT_BREAKING);
4659 RaiseScoreElement(EL_NUT);
4662 else if (smashed == EL_PEARL)
4664 ResetGfxAnimation(x, y);
4666 Feld[x][y + 1] = EL_PEARL_BREAKING;
4667 PlayLevelSound(x, y, SND_PEARL_BREAKING);
4670 else if (smashed == EL_DIAMOND)
4672 Feld[x][y + 1] = EL_DIAMOND_BREAKING;
4673 PlayLevelSound(x, y, SND_DIAMOND_BREAKING);
4676 else if (IS_BELT_SWITCH(smashed))
4678 ToggleBeltSwitch(x, y + 1);
4680 else if (smashed == EL_SWITCHGATE_SWITCH_UP ||
4681 smashed == EL_SWITCHGATE_SWITCH_DOWN)
4683 ToggleSwitchgateSwitch(x, y + 1);
4685 else if (smashed == EL_LIGHT_SWITCH ||
4686 smashed == EL_LIGHT_SWITCH_ACTIVE)
4688 ToggleLightSwitch(x, y + 1);
4693 TestIfElementSmashesCustomElement(x, y, MV_DOWN);
4696 CheckElementChange(x, y + 1, smashed, element, CE_SMASHED);
4698 CheckElementChangeBySide(x, y + 1, smashed, element,
4699 CE_SWITCHED, CH_SIDE_TOP);
4700 CheckTriggeredElementChangeBySide(x, y + 1, smashed, CE_SWITCH_OF_X,
4706 CheckElementChange(x, y + 1, smashed, element, CE_SMASHED);
4711 /* play sound of magic wall / mill */
4713 (Feld[x][y + 1] == EL_MAGIC_WALL_ACTIVE ||
4714 Feld[x][y + 1] == EL_BD_MAGIC_WALL_ACTIVE))
4716 if (Feld[x][y + 1] == EL_MAGIC_WALL_ACTIVE)
4717 PlayLevelSound(x, y, SND_MAGIC_WALL_FILLING);
4718 else if (Feld[x][y + 1] == EL_BD_MAGIC_WALL_ACTIVE)
4719 PlayLevelSound(x, y, SND_BD_MAGIC_WALL_FILLING);
4724 /* play sound of object that hits the ground */
4725 if (last_line || object_hit)
4726 PlayLevelSoundElementAction(x, y, element, ACTION_IMPACT);
4729 inline static void TurnRoundExt(int x, int y)
4741 { 0, 0 }, { 0, 0 }, { 0, 0 },
4746 int left, right, back;
4750 { MV_DOWN, MV_UP, MV_RIGHT },
4751 { MV_UP, MV_DOWN, MV_LEFT },
4753 { MV_LEFT, MV_RIGHT, MV_DOWN },
4757 { MV_RIGHT, MV_LEFT, MV_UP }
4760 int element = Feld[x][y];
4761 int move_pattern = element_info[element].move_pattern;
4763 int old_move_dir = MovDir[x][y];
4764 int left_dir = turn[old_move_dir].left;
4765 int right_dir = turn[old_move_dir].right;
4766 int back_dir = turn[old_move_dir].back;
4768 int left_dx = move_xy[left_dir].dx, left_dy = move_xy[left_dir].dy;
4769 int right_dx = move_xy[right_dir].dx, right_dy = move_xy[right_dir].dy;
4770 int move_dx = move_xy[old_move_dir].dx, move_dy = move_xy[old_move_dir].dy;
4771 int back_dx = move_xy[back_dir].dx, back_dy = move_xy[back_dir].dy;
4773 int left_x = x + left_dx, left_y = y + left_dy;
4774 int right_x = x + right_dx, right_y = y + right_dy;
4775 int move_x = x + move_dx, move_y = y + move_dy;
4779 if (element == EL_BUG || element == EL_BD_BUTTERFLY)
4781 TestIfBadThingTouchesOtherBadThing(x, y);
4783 if (ENEMY_CAN_ENTER_FIELD(element, right_x, right_y))
4784 MovDir[x][y] = right_dir;
4785 else if (!ENEMY_CAN_ENTER_FIELD(element, move_x, move_y))
4786 MovDir[x][y] = left_dir;
4788 if (element == EL_BUG && MovDir[x][y] != old_move_dir)
4790 else if (element == EL_BD_BUTTERFLY) /* && MovDir[x][y] == left_dir) */
4793 else if (element == EL_SPACESHIP || element == EL_BD_FIREFLY)
4795 TestIfBadThingTouchesOtherBadThing(x, y);
4797 if (ENEMY_CAN_ENTER_FIELD(element, left_x, left_y))
4798 MovDir[x][y] = left_dir;
4799 else if (!ENEMY_CAN_ENTER_FIELD(element, move_x, move_y))
4800 MovDir[x][y] = right_dir;
4802 if (element == EL_SPACESHIP && MovDir[x][y] != old_move_dir)
4804 else if (element == EL_BD_FIREFLY) /* && MovDir[x][y] == right_dir) */
4807 else if (element == EL_SP_SNIKSNAK || element == EL_SP_ELECTRON)
4809 TestIfBadThingTouchesOtherBadThing(x, y);
4811 if (ELEMENT_CAN_ENTER_FIELD_BASE_4(element, left_x, left_y, 0))
4812 MovDir[x][y] = left_dir;
4813 else if (!ELEMENT_CAN_ENTER_FIELD_BASE_4(element, move_x, move_y, 0))
4814 MovDir[x][y] = right_dir;
4816 if (MovDir[x][y] != old_move_dir)
4819 else if (element == EL_YAMYAM)
4821 boolean can_turn_left = YAMYAM_CAN_ENTER_FIELD(element, left_x, left_y);
4822 boolean can_turn_right = YAMYAM_CAN_ENTER_FIELD(element, right_x, right_y);
4824 if (can_turn_left && can_turn_right)
4825 MovDir[x][y] = (RND(3) ? (RND(2) ? left_dir : right_dir) : back_dir);
4826 else if (can_turn_left)
4827 MovDir[x][y] = (RND(2) ? left_dir : back_dir);
4828 else if (can_turn_right)
4829 MovDir[x][y] = (RND(2) ? right_dir : back_dir);
4831 MovDir[x][y] = back_dir;
4833 MovDelay[x][y] = 16 + 16 * RND(3);
4835 else if (element == EL_DARK_YAMYAM)
4837 boolean can_turn_left = DARK_YAMYAM_CAN_ENTER_FIELD(element,
4839 boolean can_turn_right = DARK_YAMYAM_CAN_ENTER_FIELD(element,
4842 if (can_turn_left && can_turn_right)
4843 MovDir[x][y] = (RND(3) ? (RND(2) ? left_dir : right_dir) : back_dir);
4844 else if (can_turn_left)
4845 MovDir[x][y] = (RND(2) ? left_dir : back_dir);
4846 else if (can_turn_right)
4847 MovDir[x][y] = (RND(2) ? right_dir : back_dir);
4849 MovDir[x][y] = back_dir;
4851 MovDelay[x][y] = 16 + 16 * RND(3);
4853 else if (element == EL_PACMAN)
4855 boolean can_turn_left = PACMAN_CAN_ENTER_FIELD(element, left_x, left_y);
4856 boolean can_turn_right = PACMAN_CAN_ENTER_FIELD(element, right_x, right_y);
4858 if (can_turn_left && can_turn_right)
4859 MovDir[x][y] = (RND(3) ? (RND(2) ? left_dir : right_dir) : back_dir);
4860 else if (can_turn_left)
4861 MovDir[x][y] = (RND(2) ? left_dir : back_dir);
4862 else if (can_turn_right)
4863 MovDir[x][y] = (RND(2) ? right_dir : back_dir);
4865 MovDir[x][y] = back_dir;
4867 MovDelay[x][y] = 6 + RND(40);
4869 else if (element == EL_PIG)
4871 boolean can_turn_left = PIG_CAN_ENTER_FIELD(element, left_x, left_y);
4872 boolean can_turn_right = PIG_CAN_ENTER_FIELD(element, right_x, right_y);
4873 boolean can_move_on = PIG_CAN_ENTER_FIELD(element, move_x, move_y);
4874 boolean should_turn_left, should_turn_right, should_move_on;
4876 int rnd = RND(rnd_value);
4878 should_turn_left = (can_turn_left &&
4880 IN_LEV_FIELD_AND_NOT_FREE(x + back_dx + left_dx,
4881 y + back_dy + left_dy)));
4882 should_turn_right = (can_turn_right &&
4884 IN_LEV_FIELD_AND_NOT_FREE(x + back_dx + right_dx,
4885 y + back_dy + right_dy)));
4886 should_move_on = (can_move_on &&
4889 IN_LEV_FIELD_AND_NOT_FREE(x + move_dx + left_dx,
4890 y + move_dy + left_dy) ||
4891 IN_LEV_FIELD_AND_NOT_FREE(x + move_dx + right_dx,
4892 y + move_dy + right_dy)));
4894 if (should_turn_left || should_turn_right || should_move_on)
4896 if (should_turn_left && should_turn_right && should_move_on)
4897 MovDir[x][y] = (rnd < rnd_value / 3 ? left_dir :
4898 rnd < 2 * rnd_value / 3 ? right_dir :
4900 else if (should_turn_left && should_turn_right)
4901 MovDir[x][y] = (rnd < rnd_value / 2 ? left_dir : right_dir);
4902 else if (should_turn_left && should_move_on)
4903 MovDir[x][y] = (rnd < rnd_value / 2 ? left_dir : old_move_dir);
4904 else if (should_turn_right && should_move_on)
4905 MovDir[x][y] = (rnd < rnd_value / 2 ? right_dir : old_move_dir);
4906 else if (should_turn_left)
4907 MovDir[x][y] = left_dir;
4908 else if (should_turn_right)
4909 MovDir[x][y] = right_dir;
4910 else if (should_move_on)
4911 MovDir[x][y] = old_move_dir;
4913 else if (can_move_on && rnd > rnd_value / 8)
4914 MovDir[x][y] = old_move_dir;
4915 else if (can_turn_left && can_turn_right)
4916 MovDir[x][y] = (rnd < rnd_value / 2 ? left_dir : right_dir);
4917 else if (can_turn_left && rnd > rnd_value / 8)
4918 MovDir[x][y] = left_dir;
4919 else if (can_turn_right && rnd > rnd_value/8)
4920 MovDir[x][y] = right_dir;
4922 MovDir[x][y] = back_dir;
4924 xx = x + move_xy[MovDir[x][y]].dx;
4925 yy = y + move_xy[MovDir[x][y]].dy;
4927 if (!IN_LEV_FIELD(xx, yy) ||
4928 (!IS_FREE(xx, yy) && !IS_FOOD_PIG(Feld[xx][yy])))
4929 MovDir[x][y] = old_move_dir;
4933 else if (element == EL_DRAGON)
4935 boolean can_turn_left = DRAGON_CAN_ENTER_FIELD(element, left_x, left_y);
4936 boolean can_turn_right = DRAGON_CAN_ENTER_FIELD(element, right_x, right_y);
4937 boolean can_move_on = DRAGON_CAN_ENTER_FIELD(element, move_x, move_y);
4939 int rnd = RND(rnd_value);
4941 if (can_move_on && rnd > rnd_value / 8)
4942 MovDir[x][y] = old_move_dir;
4943 else if (can_turn_left && can_turn_right)
4944 MovDir[x][y] = (rnd < rnd_value / 2 ? left_dir : right_dir);
4945 else if (can_turn_left && rnd > rnd_value / 8)
4946 MovDir[x][y] = left_dir;
4947 else if (can_turn_right && rnd > rnd_value / 8)
4948 MovDir[x][y] = right_dir;
4950 MovDir[x][y] = back_dir;
4952 xx = x + move_xy[MovDir[x][y]].dx;
4953 yy = y + move_xy[MovDir[x][y]].dy;
4955 if (!IN_LEV_FIELD_AND_IS_FREE(xx, yy))
4956 MovDir[x][y] = old_move_dir;
4960 else if (element == EL_MOLE)
4962 boolean can_move_on =
4963 (MOLE_CAN_ENTER_FIELD(element, move_x, move_y,
4964 IS_AMOEBOID(Feld[move_x][move_y]) ||
4965 Feld[move_x][move_y] == EL_AMOEBA_SHRINKING));
4968 boolean can_turn_left =
4969 (MOLE_CAN_ENTER_FIELD(element, left_x, left_y,
4970 IS_AMOEBOID(Feld[left_x][left_y])));
4972 boolean can_turn_right =
4973 (MOLE_CAN_ENTER_FIELD(element, right_x, right_y,
4974 IS_AMOEBOID(Feld[right_x][right_y])));
4976 if (can_turn_left && can_turn_right)
4977 MovDir[x][y] = (RND(2) ? left_dir : right_dir);
4978 else if (can_turn_left)
4979 MovDir[x][y] = left_dir;
4981 MovDir[x][y] = right_dir;
4984 if (MovDir[x][y] != old_move_dir)
4987 else if (element == EL_BALLOON)
4989 MovDir[x][y] = game.wind_direction;
4992 else if (element == EL_SPRING)
4994 #if USE_NEW_SPRING_BUMPER
4995 if (MovDir[x][y] & MV_HORIZONTAL)
4997 if (SPRING_CAN_BUMP_FROM_FIELD(move_x, move_y) &&
4998 !SPRING_CAN_ENTER_FIELD(element, x, y + 1))
5000 Feld[move_x][move_y] = EL_EMC_SPRING_BUMPER_ACTIVE;
5001 ResetGfxAnimation(move_x, move_y);
5002 DrawLevelField(move_x, move_y);
5004 MovDir[x][y] = back_dir;
5006 else if (!SPRING_CAN_ENTER_FIELD(element, move_x, move_y) ||
5007 SPRING_CAN_ENTER_FIELD(element, x, y + 1))
5008 MovDir[x][y] = MV_NONE;
5011 if (MovDir[x][y] & MV_HORIZONTAL &&
5012 (!SPRING_CAN_ENTER_FIELD(element, move_x, move_y) ||
5013 SPRING_CAN_ENTER_FIELD(element, x, y + 1)))
5014 MovDir[x][y] = MV_NONE;
5019 else if (element == EL_ROBOT ||
5020 element == EL_SATELLITE ||
5021 element == EL_PENGUIN ||
5022 element == EL_EMC_ANDROID)
5024 int attr_x = -1, attr_y = -1;
5035 for (i = 0; i < MAX_PLAYERS; i++)
5037 struct PlayerInfo *player = &stored_player[i];
5038 int jx = player->jx, jy = player->jy;
5040 if (!player->active)
5044 ABS(jx - x) + ABS(jy - y) < ABS(attr_x - x) + ABS(attr_y - y))
5052 if (element == EL_ROBOT && ZX >= 0 && ZY >= 0 &&
5053 (Feld[ZX][ZY] == EL_ROBOT_WHEEL_ACTIVE ||
5054 game.engine_version < VERSION_IDENT(3,1,0,0)))
5060 if (element == EL_PENGUIN)
5063 static int xy[4][2] =
5071 for (i = 0; i < NUM_DIRECTIONS; i++)
5073 int ex = x + xy[i][0];
5074 int ey = y + xy[i][1];
5076 if (IN_LEV_FIELD(ex, ey) && (Feld[ex][ey] == EL_EXIT_OPEN ||
5077 Feld[ex][ey] == EL_STEEL_EXIT_OPEN))
5086 MovDir[x][y] = MV_NONE;
5088 MovDir[x][y] |= (AllPlayersGone ? MV_RIGHT : MV_LEFT);
5089 else if (attr_x > x)
5090 MovDir[x][y] |= (AllPlayersGone ? MV_LEFT : MV_RIGHT);
5092 MovDir[x][y] |= (AllPlayersGone ? MV_DOWN : MV_UP);
5093 else if (attr_y > y)
5094 MovDir[x][y] |= (AllPlayersGone ? MV_UP : MV_DOWN);
5096 if (element == EL_ROBOT)
5100 if (MovDir[x][y] & MV_HORIZONTAL && MovDir[x][y] & MV_VERTICAL)
5101 MovDir[x][y] &= (RND(2) ? MV_HORIZONTAL : MV_VERTICAL);
5102 Moving2Blocked(x, y, &newx, &newy);
5104 if (IN_LEV_FIELD(newx, newy) && IS_FREE_OR_PLAYER(newx, newy))
5105 MovDelay[x][y] = 8 + 8 * !RND(3);
5107 MovDelay[x][y] = 16;
5109 else if (element == EL_PENGUIN)
5115 if (MovDir[x][y] & MV_HORIZONTAL && MovDir[x][y] & MV_VERTICAL)
5117 boolean first_horiz = RND(2);
5118 int new_move_dir = MovDir[x][y];
5121 new_move_dir & (first_horiz ? MV_HORIZONTAL : MV_VERTICAL);
5122 Moving2Blocked(x, y, &newx, &newy);
5124 if (PENGUIN_CAN_ENTER_FIELD(element, newx, newy))
5128 new_move_dir & (!first_horiz ? MV_HORIZONTAL : MV_VERTICAL);
5129 Moving2Blocked(x, y, &newx, &newy);
5131 if (PENGUIN_CAN_ENTER_FIELD(element, newx, newy))
5134 MovDir[x][y] = old_move_dir;
5138 else if (element == EL_SATELLITE)
5144 if (MovDir[x][y] & MV_HORIZONTAL && MovDir[x][y] & MV_VERTICAL)
5146 boolean first_horiz = RND(2);
5147 int new_move_dir = MovDir[x][y];
5150 new_move_dir & (first_horiz ? MV_HORIZONTAL : MV_VERTICAL);
5151 Moving2Blocked(x, y, &newx, &newy);
5153 if (SATELLITE_CAN_ENTER_FIELD(newx, newy))
5157 new_move_dir & (!first_horiz ? MV_HORIZONTAL : MV_VERTICAL);
5158 Moving2Blocked(x, y, &newx, &newy);
5160 if (SATELLITE_CAN_ENTER_FIELD(newx, newy))
5163 MovDir[x][y] = old_move_dir;
5167 else if (element == EL_EMC_ANDROID)
5169 static int check_pos[16] =
5171 -1, /* 0 => (invalid) */
5172 7, /* 1 => MV_LEFT */
5173 3, /* 2 => MV_RIGHT */
5174 -1, /* 3 => (invalid) */
5176 0, /* 5 => MV_LEFT | MV_UP */
5177 2, /* 6 => MV_RIGHT | MV_UP */
5178 -1, /* 7 => (invalid) */
5179 5, /* 8 => MV_DOWN */
5180 6, /* 9 => MV_LEFT | MV_DOWN */
5181 4, /* 10 => MV_RIGHT | MV_DOWN */
5182 -1, /* 11 => (invalid) */
5183 -1, /* 12 => (invalid) */
5184 -1, /* 13 => (invalid) */
5185 -1, /* 14 => (invalid) */
5186 -1, /* 15 => (invalid) */
5194 { -1, -1, MV_LEFT | MV_UP },
5196 { +1, -1, MV_RIGHT | MV_UP },
5197 { +1, 0, MV_RIGHT },
5198 { +1, +1, MV_RIGHT | MV_DOWN },
5200 { -1, +1, MV_LEFT | MV_DOWN },
5203 int start_pos, check_order;
5204 boolean can_clone = FALSE;
5207 /* check if there is any free field around current position */
5208 for (i = 0; i < 8; i++)
5210 int newx = x + check_xy[i].dx;
5211 int newy = y + check_xy[i].dy;
5213 if (IN_LEV_FIELD_AND_IS_FREE(newx, newy))
5221 if (can_clone) /* randomly find an element to clone */
5225 start_pos = check_pos[RND(8)];
5226 check_order = (RND(2) ? -1 : +1);
5228 for (i = 0; i < 8; i++)
5230 int pos_raw = start_pos + i * check_order;
5231 int pos = (pos_raw + 8) % 8;
5232 int newx = x + check_xy[pos].dx;
5233 int newy = y + check_xy[pos].dy;
5235 if (ANDROID_CAN_CLONE_FIELD(newx, newy))
5237 element_info[element].move_leave_type = LEAVE_TYPE_LIMITED;
5238 element_info[element].move_leave_element = EL_TRIGGER_ELEMENT;
5240 Store[x][y] = Feld[newx][newy];
5249 if (can_clone) /* randomly find a direction to move */
5253 start_pos = check_pos[RND(8)];
5254 check_order = (RND(2) ? -1 : +1);
5256 for (i = 0; i < 8; i++)
5258 int pos_raw = start_pos + i * check_order;
5259 int pos = (pos_raw + 8) % 8;
5260 int newx = x + check_xy[pos].dx;
5261 int newy = y + check_xy[pos].dy;
5262 int new_move_dir = check_xy[pos].dir;
5264 if (IN_LEV_FIELD_AND_IS_FREE(newx, newy))
5266 MovDir[x][y] = new_move_dir;
5267 MovDelay[x][y] = level.android_clone_time * 8 + 1;
5276 if (can_clone) /* cloning and moving successful */
5279 /* cannot clone -- try to move towards player */
5281 start_pos = check_pos[MovDir[x][y] & 0x0f];
5282 check_order = (RND(2) ? -1 : +1);
5284 for (i = 0; i < 3; i++)
5286 /* first check start_pos, then previous/next or (next/previous) pos */
5287 int pos_raw = start_pos + (i < 2 ? i : -1) * check_order;
5288 int pos = (pos_raw + 8) % 8;
5289 int newx = x + check_xy[pos].dx;
5290 int newy = y + check_xy[pos].dy;
5291 int new_move_dir = check_xy[pos].dir;
5293 if (IS_PLAYER(newx, newy))
5296 if (ANDROID_CAN_ENTER_FIELD(element, newx, newy))
5298 MovDir[x][y] = new_move_dir;
5299 MovDelay[x][y] = level.android_move_time * 8 + 1;
5306 else if (move_pattern == MV_TURNING_LEFT ||
5307 move_pattern == MV_TURNING_RIGHT ||
5308 move_pattern == MV_TURNING_LEFT_RIGHT ||
5309 move_pattern == MV_TURNING_RIGHT_LEFT ||
5310 move_pattern == MV_TURNING_RANDOM ||
5311 move_pattern == MV_ALL_DIRECTIONS)
5313 boolean can_turn_left =
5314 CUSTOM_ELEMENT_CAN_ENTER_FIELD(element, left_x, left_y);
5315 boolean can_turn_right =
5316 CUSTOM_ELEMENT_CAN_ENTER_FIELD(element, right_x,right_y);
5318 if (element_info[element].move_stepsize == 0) /* "not moving" */
5321 if (move_pattern == MV_TURNING_LEFT)
5322 MovDir[x][y] = left_dir;
5323 else if (move_pattern == MV_TURNING_RIGHT)
5324 MovDir[x][y] = right_dir;
5325 else if (move_pattern == MV_TURNING_LEFT_RIGHT)
5326 MovDir[x][y] = (can_turn_left || !can_turn_right ? left_dir : right_dir);
5327 else if (move_pattern == MV_TURNING_RIGHT_LEFT)
5328 MovDir[x][y] = (can_turn_right || !can_turn_left ? right_dir : left_dir);
5329 else if (move_pattern == MV_TURNING_RANDOM)
5330 MovDir[x][y] = (can_turn_left && !can_turn_right ? left_dir :
5331 can_turn_right && !can_turn_left ? right_dir :
5332 RND(2) ? left_dir : right_dir);
5333 else if (can_turn_left && can_turn_right)
5334 MovDir[x][y] = (RND(3) ? (RND(2) ? left_dir : right_dir) : back_dir);
5335 else if (can_turn_left)
5336 MovDir[x][y] = (RND(2) ? left_dir : back_dir);
5337 else if (can_turn_right)
5338 MovDir[x][y] = (RND(2) ? right_dir : back_dir);
5340 MovDir[x][y] = back_dir;
5342 MovDelay[x][y] = GET_NEW_MOVE_DELAY(element);
5344 else if (move_pattern == MV_HORIZONTAL ||
5345 move_pattern == MV_VERTICAL)
5347 if (move_pattern & old_move_dir)
5348 MovDir[x][y] = back_dir;
5349 else if (move_pattern == MV_HORIZONTAL)
5350 MovDir[x][y] = (RND(2) ? MV_LEFT : MV_RIGHT);
5351 else if (move_pattern == MV_VERTICAL)
5352 MovDir[x][y] = (RND(2) ? MV_UP : MV_DOWN);
5354 MovDelay[x][y] = GET_NEW_MOVE_DELAY(element);
5356 else if (move_pattern & MV_ANY_DIRECTION)
5358 MovDir[x][y] = move_pattern;
5359 MovDelay[x][y] = GET_NEW_MOVE_DELAY(element);
5361 else if (move_pattern & MV_WIND_DIRECTION)
5363 MovDir[x][y] = game.wind_direction;
5364 MovDelay[x][y] = GET_NEW_MOVE_DELAY(element);
5366 else if (move_pattern == MV_ALONG_LEFT_SIDE)
5368 if (CUSTOM_ELEMENT_CAN_ENTER_FIELD(element, left_x, left_y))
5369 MovDir[x][y] = left_dir;
5370 else if (!CUSTOM_ELEMENT_CAN_ENTER_FIELD(element, move_x, move_y))
5371 MovDir[x][y] = right_dir;
5373 if (MovDir[x][y] != old_move_dir)
5374 MovDelay[x][y] = GET_NEW_MOVE_DELAY(element);
5376 else if (move_pattern == MV_ALONG_RIGHT_SIDE)
5378 if (CUSTOM_ELEMENT_CAN_ENTER_FIELD(element, right_x, right_y))
5379 MovDir[x][y] = right_dir;
5380 else if (!CUSTOM_ELEMENT_CAN_ENTER_FIELD(element, move_x, move_y))
5381 MovDir[x][y] = left_dir;
5383 if (MovDir[x][y] != old_move_dir)
5384 MovDelay[x][y] = GET_NEW_MOVE_DELAY(element);
5386 else if (move_pattern == MV_TOWARDS_PLAYER ||
5387 move_pattern == MV_AWAY_FROM_PLAYER)
5389 int attr_x = -1, attr_y = -1;
5391 boolean move_away = (move_pattern == MV_AWAY_FROM_PLAYER);
5402 for (i = 0; i < MAX_PLAYERS; i++)
5404 struct PlayerInfo *player = &stored_player[i];
5405 int jx = player->jx, jy = player->jy;
5407 if (!player->active)
5411 ABS(jx - x) + ABS(jy - y) < ABS(attr_x - x) + ABS(attr_y - y))
5419 MovDir[x][y] = MV_NONE;
5421 MovDir[x][y] |= (move_away ? MV_RIGHT : MV_LEFT);
5422 else if (attr_x > x)
5423 MovDir[x][y] |= (move_away ? MV_LEFT : MV_RIGHT);
5425 MovDir[x][y] |= (move_away ? MV_DOWN : MV_UP);
5426 else if (attr_y > y)
5427 MovDir[x][y] |= (move_away ? MV_UP : MV_DOWN);
5429 MovDelay[x][y] = GET_NEW_MOVE_DELAY(element);
5431 if (MovDir[x][y] & MV_HORIZONTAL && MovDir[x][y] & MV_VERTICAL)
5433 boolean first_horiz = RND(2);
5434 int new_move_dir = MovDir[x][y];
5436 if (element_info[element].move_stepsize == 0) /* "not moving" */
5438 first_horiz = (ABS(attr_x - x) >= ABS(attr_y - y));
5439 MovDir[x][y] &= (first_horiz ? MV_HORIZONTAL : MV_VERTICAL);
5445 new_move_dir & (first_horiz ? MV_HORIZONTAL : MV_VERTICAL);
5446 Moving2Blocked(x, y, &newx, &newy);
5448 if (CUSTOM_ELEMENT_CAN_ENTER_FIELD(element, newx, newy))
5452 new_move_dir & (!first_horiz ? MV_HORIZONTAL : MV_VERTICAL);
5453 Moving2Blocked(x, y, &newx, &newy);
5455 if (CUSTOM_ELEMENT_CAN_ENTER_FIELD(element, newx, newy))
5458 MovDir[x][y] = old_move_dir;
5461 else if (move_pattern == MV_WHEN_PUSHED ||
5462 move_pattern == MV_WHEN_DROPPED)
5464 if (!CUSTOM_ELEMENT_CAN_ENTER_FIELD(element, move_x, move_y))
5465 MovDir[x][y] = MV_NONE;
5469 else if (move_pattern & MV_MAZE_RUNNER_STYLE)
5471 static int test_xy[7][2] =
5481 static int test_dir[7] =
5491 boolean hunter_mode = (move_pattern == MV_MAZE_HUNTER);
5492 int move_preference = -1000000; /* start with very low preference */
5493 int new_move_dir = MV_NONE;
5494 int start_test = RND(4);
5497 for (i = 0; i < NUM_DIRECTIONS; i++)
5499 int move_dir = test_dir[start_test + i];
5500 int move_dir_preference;
5502 xx = x + test_xy[start_test + i][0];
5503 yy = y + test_xy[start_test + i][1];
5505 if (hunter_mode && IN_LEV_FIELD(xx, yy) &&
5506 (IS_PLAYER(xx, yy) || Feld[xx][yy] == EL_PLAYER_IS_LEAVING))
5508 new_move_dir = move_dir;
5513 if (!CUSTOM_ELEMENT_CAN_ENTER_FIELD(element, xx, yy))
5516 move_dir_preference = -1 * RunnerVisit[xx][yy];
5517 if (hunter_mode && PlayerVisit[xx][yy] > 0)
5518 move_dir_preference = PlayerVisit[xx][yy];
5520 if (move_dir_preference > move_preference)
5522 /* prefer field that has not been visited for the longest time */
5523 move_preference = move_dir_preference;
5524 new_move_dir = move_dir;
5526 else if (move_dir_preference == move_preference &&
5527 move_dir == old_move_dir)
5529 /* prefer last direction when all directions are preferred equally */
5530 move_preference = move_dir_preference;
5531 new_move_dir = move_dir;
5535 MovDir[x][y] = new_move_dir;
5536 if (old_move_dir != new_move_dir)
5537 MovDelay[x][y] = GET_NEW_MOVE_DELAY(element);
5541 static void TurnRound(int x, int y)
5543 int direction = MovDir[x][y];
5547 GfxDir[x][y] = MovDir[x][y];
5549 if (direction != MovDir[x][y])
5553 GfxAction[x][y] = ACTION_TURNING_FROM_LEFT + MV_DIR_TO_BIT(direction);
5555 ResetGfxFrame(x, y, FALSE);
5558 static boolean JustBeingPushed(int x, int y)
5562 for (i = 0; i < MAX_PLAYERS; i++)
5564 struct PlayerInfo *player = &stored_player[i];
5566 if (player->active && player->is_pushing && player->MovPos)
5568 int next_jx = player->jx + (player->jx - player->last_jx);
5569 int next_jy = player->jy + (player->jy - player->last_jy);
5571 if (x == next_jx && y == next_jy)
5579 void StartMoving(int x, int y)
5581 boolean started_moving = FALSE; /* some elements can fall _and_ move */
5582 int element = Feld[x][y];
5587 if (MovDelay[x][y] == 0)
5588 GfxAction[x][y] = ACTION_DEFAULT;
5590 if (CAN_FALL(element) && y < lev_fieldy - 1)
5592 if ((x > 0 && IS_PLAYER(x - 1, y)) ||
5593 (x < lev_fieldx - 1 && IS_PLAYER(x + 1, y)))
5594 if (JustBeingPushed(x, y))
5597 if (element == EL_QUICKSAND_FULL)
5599 if (IS_FREE(x, y + 1))
5601 InitMovingField(x, y, MV_DOWN);
5602 started_moving = TRUE;
5604 Feld[x][y] = EL_QUICKSAND_EMPTYING;
5605 #if USE_QUICKSAND_BD_ROCK_BUGFIX
5606 if (Store[x][y] != EL_ROCK && Store[x][y] != EL_BD_ROCK)
5607 Store[x][y] = EL_ROCK;
5609 Store[x][y] = EL_ROCK;
5612 PlayLevelSoundAction(x, y, ACTION_EMPTYING);
5614 else if (Feld[x][y + 1] == EL_QUICKSAND_EMPTY)
5616 if (!MovDelay[x][y])
5617 MovDelay[x][y] = TILEY + 1;
5626 Feld[x][y] = EL_QUICKSAND_EMPTY;
5627 Feld[x][y + 1] = EL_QUICKSAND_FULL;
5628 Store[x][y + 1] = Store[x][y];
5631 PlayLevelSoundAction(x, y, ACTION_FILLING);
5634 else if ((element == EL_ROCK || element == EL_BD_ROCK) &&
5635 Feld[x][y + 1] == EL_QUICKSAND_EMPTY)
5637 InitMovingField(x, y, MV_DOWN);
5638 started_moving = TRUE;
5640 Feld[x][y] = EL_QUICKSAND_FILLING;
5641 Store[x][y] = element;
5643 PlayLevelSoundAction(x, y, ACTION_FILLING);
5645 else if (element == EL_MAGIC_WALL_FULL)
5647 if (IS_FREE(x, y + 1))
5649 InitMovingField(x, y, MV_DOWN);
5650 started_moving = TRUE;
5652 Feld[x][y] = EL_MAGIC_WALL_EMPTYING;
5653 Store[x][y] = EL_CHANGED(Store[x][y]);
5655 else if (Feld[x][y + 1] == EL_MAGIC_WALL_ACTIVE)
5657 if (!MovDelay[x][y])
5658 MovDelay[x][y] = TILEY/4 + 1;
5667 Feld[x][y] = EL_MAGIC_WALL_ACTIVE;
5668 Feld[x][y + 1] = EL_MAGIC_WALL_FULL;
5669 Store[x][y + 1] = EL_CHANGED(Store[x][y]);
5673 else if (element == EL_BD_MAGIC_WALL_FULL)
5675 if (IS_FREE(x, y + 1))
5677 InitMovingField(x, y, MV_DOWN);
5678 started_moving = TRUE;
5680 Feld[x][y] = EL_BD_MAGIC_WALL_EMPTYING;
5681 Store[x][y] = EL_CHANGED2(Store[x][y]);
5683 else if (Feld[x][y + 1] == EL_BD_MAGIC_WALL_ACTIVE)
5685 if (!MovDelay[x][y])
5686 MovDelay[x][y] = TILEY/4 + 1;
5695 Feld[x][y] = EL_BD_MAGIC_WALL_ACTIVE;
5696 Feld[x][y + 1] = EL_BD_MAGIC_WALL_FULL;
5697 Store[x][y + 1] = EL_CHANGED2(Store[x][y]);
5701 else if (CAN_PASS_MAGIC_WALL(element) &&
5702 (Feld[x][y + 1] == EL_MAGIC_WALL_ACTIVE ||
5703 Feld[x][y + 1] == EL_BD_MAGIC_WALL_ACTIVE))
5705 InitMovingField(x, y, MV_DOWN);
5706 started_moving = TRUE;
5709 (Feld[x][y + 1] == EL_MAGIC_WALL_ACTIVE ? EL_MAGIC_WALL_FILLING :
5710 EL_BD_MAGIC_WALL_FILLING);
5711 Store[x][y] = element;
5713 else if (CAN_FALL(element) && Feld[x][y + 1] == EL_ACID)
5715 SplashAcid(x, y + 1);
5717 InitMovingField(x, y, MV_DOWN);
5718 started_moving = TRUE;
5720 Store[x][y] = EL_ACID;
5723 #if USE_FIX_IMPACT_COLLISION
5724 (game.engine_version >= VERSION_IDENT(3,1,0,0) &&
5725 CheckImpact[x][y] && !IS_FREE(x, y + 1)) ||
5727 (game.engine_version >= VERSION_IDENT(3,1,0,0) &&
5728 CheckCollision[x][y] && !IS_FREE(x, y + 1)) ||
5730 (game.engine_version >= VERSION_IDENT(3,0,7,0) &&
5731 CAN_FALL(element) && WasJustFalling[x][y] &&
5732 (Feld[x][y + 1] == EL_BLOCKED || IS_PLAYER(x, y + 1))) ||
5734 (game.engine_version < VERSION_IDENT(2,2,0,7) &&
5735 CAN_FALL(element) && WasJustMoving[x][y] && !Pushed[x][y + 1] &&
5736 (Feld[x][y + 1] == EL_BLOCKED)))
5738 /* this is needed for a special case not covered by calling "Impact()"
5739 from "ContinueMoving()": if an element moves to a tile directly below
5740 another element which was just falling on that tile (which was empty
5741 in the previous frame), the falling element above would just stop
5742 instead of smashing the element below (in previous version, the above
5743 element was just checked for "moving" instead of "falling", resulting
5744 in incorrect smashes caused by horizontal movement of the above
5745 element; also, the case of the player being the element to smash was
5746 simply not covered here... :-/ ) */
5748 CheckCollision[x][y] = 0;
5749 CheckImpact[x][y] = 0;
5753 else if (IS_FREE(x, y + 1) && element == EL_SPRING && level.use_spring_bug)
5755 if (MovDir[x][y] == MV_NONE)
5757 InitMovingField(x, y, MV_DOWN);
5758 started_moving = TRUE;
5761 else if (IS_FREE(x, y + 1) || Feld[x][y + 1] == EL_DIAMOND_BREAKING)
5763 if (WasJustFalling[x][y]) /* prevent animation from being restarted */
5764 MovDir[x][y] = MV_DOWN;
5766 InitMovingField(x, y, MV_DOWN);
5767 started_moving = TRUE;
5769 else if (element == EL_AMOEBA_DROP)
5771 Feld[x][y] = EL_AMOEBA_GROWING;
5772 Store[x][y] = EL_AMOEBA_WET;
5774 else if (((IS_SLIPPERY(Feld[x][y + 1]) && !IS_PLAYER(x, y + 1)) ||
5775 (IS_EM_SLIPPERY_WALL(Feld[x][y + 1]) && IS_GEM(element))) &&
5776 !IS_FALLING(x, y + 1) && !WasJustMoving[x][y + 1] &&
5777 element != EL_DX_SUPABOMB && element != EL_SP_DISK_ORANGE)
5779 boolean can_fall_left = (x > 0 && IS_FREE(x - 1, y) &&
5780 (IS_FREE(x - 1, y + 1) ||
5781 Feld[x - 1][y + 1] == EL_ACID));
5782 boolean can_fall_right = (x < lev_fieldx - 1 && IS_FREE(x + 1, y) &&
5783 (IS_FREE(x + 1, y + 1) ||
5784 Feld[x + 1][y + 1] == EL_ACID));
5785 boolean can_fall_any = (can_fall_left || can_fall_right);
5786 boolean can_fall_both = (can_fall_left && can_fall_right);
5787 int slippery_type = element_info[Feld[x][y + 1]].slippery_type;
5789 #if USE_NEW_ALL_SLIPPERY
5790 if (can_fall_any && slippery_type != SLIPPERY_ANY_RANDOM)
5792 if (slippery_type == SLIPPERY_ANY_LEFT_RIGHT && can_fall_both)
5793 can_fall_right = FALSE;
5794 else if (slippery_type == SLIPPERY_ANY_RIGHT_LEFT && can_fall_both)
5795 can_fall_left = FALSE;
5796 else if (slippery_type == SLIPPERY_ONLY_LEFT)
5797 can_fall_right = FALSE;
5798 else if (slippery_type == SLIPPERY_ONLY_RIGHT)
5799 can_fall_left = FALSE;
5801 can_fall_any = (can_fall_left || can_fall_right);
5802 can_fall_both = FALSE;
5805 if (can_fall_any && IS_CUSTOM_ELEMENT(Feld[x][y + 1]))
5807 if (slippery_type == SLIPPERY_ONLY_LEFT)
5808 can_fall_right = FALSE;
5809 else if (slippery_type == SLIPPERY_ONLY_RIGHT)
5810 can_fall_left = FALSE;
5811 else if (slippery_type == SLIPPERY_ANY_LEFT_RIGHT && can_fall_both)
5812 can_fall_right = FALSE;
5813 else if (slippery_type == SLIPPERY_ANY_RIGHT_LEFT && can_fall_both)
5814 can_fall_left = FALSE;
5816 can_fall_any = (can_fall_left || can_fall_right);
5817 can_fall_both = (can_fall_left && can_fall_right);
5821 #if USE_NEW_ALL_SLIPPERY
5823 #if USE_NEW_SP_SLIPPERY
5824 /* !!! better use the same properties as for custom elements here !!! */
5825 else if (game.engine_version >= VERSION_IDENT(3,1,1,0) &&
5826 can_fall_both && IS_SP_ELEMENT(Feld[x][y + 1]))
5828 can_fall_right = FALSE; /* slip down on left side */
5829 can_fall_both = FALSE;
5834 #if USE_NEW_ALL_SLIPPERY
5837 if (element == EL_BD_ROCK || element == EL_BD_DIAMOND)
5838 can_fall_right = FALSE; /* slip down on left side */
5840 can_fall_left = !(can_fall_right = RND(2));
5842 can_fall_both = FALSE;
5847 if (game.emulation == EMU_BOULDERDASH ||
5848 element == EL_BD_ROCK || element == EL_BD_DIAMOND)
5849 can_fall_right = FALSE; /* slip down on left side */
5851 can_fall_left = !(can_fall_right = RND(2));
5853 can_fall_both = FALSE;
5859 /* if not determined otherwise, prefer left side for slipping down */
5860 InitMovingField(x, y, can_fall_left ? MV_LEFT : MV_RIGHT);
5861 started_moving = TRUE;
5865 else if (IS_BELT_ACTIVE(Feld[x][y + 1]) && !CAN_MOVE(element))
5867 else if (IS_BELT_ACTIVE(Feld[x][y + 1]))
5870 boolean left_is_free = (x > 0 && IS_FREE(x - 1, y));
5871 boolean right_is_free = (x < lev_fieldx - 1 && IS_FREE(x + 1, y));
5872 int belt_nr = getBeltNrFromBeltActiveElement(Feld[x][y + 1]);
5873 int belt_dir = game.belt_dir[belt_nr];
5875 if ((belt_dir == MV_LEFT && left_is_free) ||
5876 (belt_dir == MV_RIGHT && right_is_free))
5878 int nextx = (belt_dir == MV_LEFT ? x - 1 : x + 1);
5880 InitMovingField(x, y, belt_dir);
5881 started_moving = TRUE;
5883 Pushed[x][y] = TRUE;
5884 Pushed[nextx][y] = TRUE;
5886 GfxAction[x][y] = ACTION_DEFAULT;
5890 MovDir[x][y] = 0; /* if element was moving, stop it */
5895 /* not "else if" because of elements that can fall and move (EL_SPRING) */
5897 if (CAN_MOVE(element) && !started_moving && MovDir[x][y] != MV_NONE)
5899 if (CAN_MOVE(element) && !started_moving)
5902 int move_pattern = element_info[element].move_pattern;
5907 if (MovDir[x][y] == MV_NONE)
5909 printf("StartMoving(): %d,%d: element %d ['%s'] not moving\n",
5910 x, y, element, element_info[element].token_name);
5911 printf("StartMoving(): This should never happen!\n");
5916 Moving2Blocked(x, y, &newx, &newy);
5918 if (IS_PUSHABLE(element) && JustBeingPushed(x, y))
5921 if (game.engine_version >= VERSION_IDENT(3,1,0,0) &&
5922 CheckCollision[x][y] && !IN_LEV_FIELD_AND_IS_FREE(newx, newy))
5924 WasJustMoving[x][y] = 0;
5925 CheckCollision[x][y] = 0;
5927 TestIfElementHitsCustomElement(x, y, MovDir[x][y]);
5929 if (Feld[x][y] != element) /* element has changed */
5933 if (!MovDelay[x][y]) /* start new movement phase */
5935 /* all objects that can change their move direction after each step
5936 (YAMYAM, DARK_YAMYAM and PACMAN go straight until they hit a wall */
5938 if (element != EL_YAMYAM &&
5939 element != EL_DARK_YAMYAM &&
5940 element != EL_PACMAN &&
5941 !(move_pattern & MV_ANY_DIRECTION) &&
5942 move_pattern != MV_TURNING_LEFT &&
5943 move_pattern != MV_TURNING_RIGHT &&
5944 move_pattern != MV_TURNING_LEFT_RIGHT &&
5945 move_pattern != MV_TURNING_RIGHT_LEFT &&
5946 move_pattern != MV_TURNING_RANDOM)
5950 if (MovDelay[x][y] && (element == EL_BUG ||
5951 element == EL_SPACESHIP ||
5952 element == EL_SP_SNIKSNAK ||
5953 element == EL_SP_ELECTRON ||
5954 element == EL_MOLE))
5955 DrawLevelField(x, y);
5959 if (MovDelay[x][y]) /* wait some time before next movement */
5963 if (element == EL_ROBOT ||
5964 element == EL_YAMYAM ||
5965 element == EL_DARK_YAMYAM)
5967 DrawLevelElementAnimationIfNeeded(x, y, element);
5968 PlayLevelSoundAction(x, y, ACTION_WAITING);
5970 else if (element == EL_SP_ELECTRON)
5971 DrawLevelElementAnimationIfNeeded(x, y, element);
5972 else if (element == EL_DRAGON)
5975 int dir = MovDir[x][y];
5976 int dx = (dir == MV_LEFT ? -1 : dir == MV_RIGHT ? +1 : 0);
5977 int dy = (dir == MV_UP ? -1 : dir == MV_DOWN ? +1 : 0);
5978 int graphic = (dir == MV_LEFT ? IMG_FLAMES_1_LEFT :
5979 dir == MV_RIGHT ? IMG_FLAMES_1_RIGHT :
5980 dir == MV_UP ? IMG_FLAMES_1_UP :
5981 dir == MV_DOWN ? IMG_FLAMES_1_DOWN : IMG_EMPTY);
5982 int frame = getGraphicAnimationFrame(graphic, GfxFrame[x][y]);
5984 GfxAction[x][y] = ACTION_ATTACKING;
5986 if (IS_PLAYER(x, y))
5987 DrawPlayerField(x, y);
5989 DrawLevelField(x, y);
5991 PlayLevelSoundActionIfLoop(x, y, ACTION_ATTACKING);
5993 for (i = 1; i <= 3; i++)
5995 int xx = x + i * dx;
5996 int yy = y + i * dy;
5997 int sx = SCREENX(xx);
5998 int sy = SCREENY(yy);
5999 int flame_graphic = graphic + (i - 1);
6001 if (!IN_LEV_FIELD(xx, yy) || IS_DRAGONFIRE_PROOF(Feld[xx][yy]))
6006 int flamed = MovingOrBlocked2Element(xx, yy);
6010 if (IS_CLASSIC_ENEMY(flamed) || CAN_EXPLODE_BY_DRAGONFIRE(flamed))
6012 else if (IS_MOVING(xx, yy) || IS_BLOCKED(xx, yy))
6013 RemoveMovingField(xx, yy);
6015 RemoveField(xx, yy);
6017 if (IS_CLASSIC_ENEMY(flamed) || CAN_EXPLODE_BY_DRAGONFIRE(flamed))
6020 RemoveMovingField(xx, yy);
6023 ChangeDelay[xx][yy] = 0;
6025 Feld[xx][yy] = EL_FLAMES;
6027 if (IN_SCR_FIELD(sx, sy))
6029 DrawLevelFieldCrumbledSand(xx, yy);
6030 DrawGraphic(sx, sy, flame_graphic, frame);
6035 if (Feld[xx][yy] == EL_FLAMES)
6036 Feld[xx][yy] = EL_EMPTY;
6037 DrawLevelField(xx, yy);
6042 if (MovDelay[x][y]) /* element still has to wait some time */
6044 PlayLevelSoundAction(x, y, ACTION_WAITING);
6050 /* now make next step */
6052 Moving2Blocked(x, y, &newx, &newy); /* get next screen position */
6054 if (DONT_COLLIDE_WITH(element) &&
6055 IN_LEV_FIELD(newx, newy) && IS_PLAYER(newx, newy) &&
6056 !PLAYER_ENEMY_PROTECTED(newx, newy))
6058 TestIfBadThingRunsIntoPlayer(x, y, MovDir[x][y]);
6063 else if (CAN_MOVE_INTO_ACID(element) &&
6064 IN_LEV_FIELD(newx, newy) && Feld[newx][newy] == EL_ACID &&
6065 !IS_MV_DIAGONAL(MovDir[x][y]) &&
6066 (MovDir[x][y] == MV_DOWN ||
6067 game.engine_version >= VERSION_IDENT(3,1,0,0)))
6069 SplashAcid(newx, newy);
6070 Store[x][y] = EL_ACID;
6072 else if (element == EL_PENGUIN && IN_LEV_FIELD(newx, newy))
6074 if (Feld[newx][newy] == EL_EXIT_OPEN ||
6075 Feld[newx][newy] == EL_STEEL_EXIT_OPEN)
6078 DrawLevelField(x, y);
6080 PlayLevelSound(newx, newy, SND_PENGUIN_PASSING);
6081 if (IN_SCR_FIELD(SCREENX(newx), SCREENY(newy)))
6082 DrawGraphicThruMask(SCREENX(newx),SCREENY(newy), el2img(element), 0);
6084 local_player->friends_still_needed--;
6085 if (!local_player->friends_still_needed &&
6086 !local_player->GameOver && AllPlayersGone)
6087 PlayerWins(local_player);
6091 else if (IS_FOOD_PENGUIN(Feld[newx][newy]))
6093 if (DigField(local_player, x, y, newx, newy, 0,0, DF_DIG) == MP_MOVING)
6094 DrawLevelField(newx, newy);
6096 GfxDir[x][y] = MovDir[x][y] = MV_NONE;
6098 else if (!IS_FREE(newx, newy))
6100 GfxAction[x][y] = ACTION_WAITING;
6102 if (IS_PLAYER(x, y))
6103 DrawPlayerField(x, y);
6105 DrawLevelField(x, y);
6110 else if (element == EL_PIG && IN_LEV_FIELD(newx, newy))
6112 if (IS_FOOD_PIG(Feld[newx][newy]))
6114 if (IS_MOVING(newx, newy))
6115 RemoveMovingField(newx, newy);
6118 Feld[newx][newy] = EL_EMPTY;
6119 DrawLevelField(newx, newy);
6122 PlayLevelSound(x, y, SND_PIG_DIGGING);
6124 else if (!IS_FREE(newx, newy))
6126 if (IS_PLAYER(x, y))
6127 DrawPlayerField(x, y);
6129 DrawLevelField(x, y);
6134 else if (element == EL_EMC_ANDROID && IN_LEV_FIELD(newx, newy))
6136 if (Store[x][y] != EL_EMPTY)
6138 boolean can_clone = FALSE;
6141 /* check if element to clone is still there */
6142 for (yy = y - 1; yy <= y + 1; yy++) for (xx = x - 1; xx <= x + 1; xx++)
6144 if (IN_LEV_FIELD(xx, yy) && Feld[xx][yy] == Store[x][y])
6152 /* cannot clone or target field not free anymore -- do not clone */
6153 if (!can_clone || !ANDROID_CAN_ENTER_FIELD(element, newx, newy))
6154 Store[x][y] = EL_EMPTY;
6157 if (ANDROID_CAN_ENTER_FIELD(element, newx, newy))
6159 if (IS_MV_DIAGONAL(MovDir[x][y]))
6161 int diagonal_move_dir = MovDir[x][y];
6162 int stored = Store[x][y];
6163 int change_delay = 8;
6166 /* android is moving diagonally */
6168 CreateField(x, y, EL_DIAGONAL_SHRINKING);
6170 Store[x][y] = (stored == EL_ACID ? EL_EMPTY : stored);
6171 GfxElement[x][y] = EL_EMC_ANDROID;
6172 GfxAction[x][y] = ACTION_SHRINKING;
6173 GfxDir[x][y] = diagonal_move_dir;
6174 ChangeDelay[x][y] = change_delay;
6176 graphic = el_act_dir2img(GfxElement[x][y], GfxAction[x][y],
6179 DrawLevelGraphicAnimation(x, y, graphic);
6180 PlayLevelSoundAction(x, y, ACTION_SHRINKING);
6182 if (Feld[newx][newy] == EL_ACID)
6184 SplashAcid(newx, newy);
6189 CreateField(newx, newy, EL_DIAGONAL_GROWING);
6191 Store[newx][newy] = EL_EMC_ANDROID;
6192 GfxElement[newx][newy] = EL_EMC_ANDROID;
6193 GfxAction[newx][newy] = ACTION_GROWING;
6194 GfxDir[newx][newy] = diagonal_move_dir;
6195 ChangeDelay[newx][newy] = change_delay;
6197 graphic = el_act_dir2img(GfxElement[newx][newy],
6198 GfxAction[newx][newy], GfxDir[newx][newy]);
6200 DrawLevelGraphicAnimation(newx, newy, graphic);
6201 PlayLevelSoundAction(newx, newy, ACTION_GROWING);
6207 Feld[newx][newy] = EL_EMPTY;
6208 DrawLevelField(newx, newy);
6210 PlayLevelSoundAction(x, y, ACTION_DIGGING);
6213 else if (!IS_FREE(newx, newy))
6216 if (IS_PLAYER(x, y))
6217 DrawPlayerField(x, y);
6219 DrawLevelField(x, y);
6225 else if (IS_CUSTOM_ELEMENT(element) &&
6226 CUSTOM_ELEMENT_CAN_ENTER_FIELD(element, newx, newy))
6228 int new_element = Feld[newx][newy];
6230 if (!IS_FREE(newx, newy))
6232 int action = (IS_DIGGABLE(new_element) ? ACTION_DIGGING :
6233 IS_COLLECTIBLE(new_element) ? ACTION_COLLECTING :
6236 /* no element can dig solid indestructible elements */
6237 if (IS_INDESTRUCTIBLE(new_element) &&
6238 !IS_DIGGABLE(new_element) &&
6239 !IS_COLLECTIBLE(new_element))
6242 if (AmoebaNr[newx][newy] &&
6243 (new_element == EL_AMOEBA_FULL ||
6244 new_element == EL_BD_AMOEBA ||
6245 new_element == EL_AMOEBA_GROWING))
6247 AmoebaCnt[AmoebaNr[newx][newy]]--;
6248 AmoebaCnt2[AmoebaNr[newx][newy]]--;
6251 if (IS_MOVING(newx, newy))
6252 RemoveMovingField(newx, newy);
6255 RemoveField(newx, newy);
6256 DrawLevelField(newx, newy);
6259 /* if digged element was about to explode, prevent the explosion */
6260 ExplodeField[newx][newy] = EX_TYPE_NONE;
6262 PlayLevelSoundAction(x, y, action);
6265 Store[newx][newy] = EL_EMPTY;
6267 /* this makes it possible to leave the removed element again */
6268 if (IS_EQUAL_OR_IN_GROUP(new_element, MOVE_ENTER_EL(element)))
6269 Store[newx][newy] = new_element;
6271 if (IS_EQUAL_OR_IN_GROUP(new_element, MOVE_ENTER_EL(element)))
6273 int move_leave_element = element_info[element].move_leave_element;
6275 /* this makes it possible to leave the removed element again */
6276 Store[newx][newy] = (move_leave_element == EL_TRIGGER_ELEMENT ?
6277 new_element : move_leave_element);
6281 if (move_pattern & MV_MAZE_RUNNER_STYLE)
6283 RunnerVisit[x][y] = FrameCounter;
6284 PlayerVisit[x][y] /= 8; /* expire player visit path */
6287 else if (element == EL_DRAGON && IN_LEV_FIELD(newx, newy))
6289 if (!IS_FREE(newx, newy))
6291 if (IS_PLAYER(x, y))
6292 DrawPlayerField(x, y);
6294 DrawLevelField(x, y);
6300 boolean wanna_flame = !RND(10);
6301 int dx = newx - x, dy = newy - y;
6302 int newx1 = newx + 1 * dx, newy1 = newy + 1 * dy;
6303 int newx2 = newx + 2 * dx, newy2 = newy + 2 * dy;
6304 int element1 = (IN_LEV_FIELD(newx1, newy1) ?
6305 MovingOrBlocked2Element(newx1, newy1) : EL_STEELWALL);
6306 int element2 = (IN_LEV_FIELD(newx2, newy2) ?
6307 MovingOrBlocked2Element(newx2, newy2) : EL_STEELWALL);
6310 IS_CLASSIC_ENEMY(element1) ||
6311 IS_CLASSIC_ENEMY(element2)) &&
6312 element1 != EL_DRAGON && element2 != EL_DRAGON &&
6313 element1 != EL_FLAMES && element2 != EL_FLAMES)
6315 ResetGfxAnimation(x, y);
6316 GfxAction[x][y] = ACTION_ATTACKING;
6318 if (IS_PLAYER(x, y))
6319 DrawPlayerField(x, y);
6321 DrawLevelField(x, y);
6323 PlayLevelSound(x, y, SND_DRAGON_ATTACKING);
6325 MovDelay[x][y] = 50;
6329 RemoveField(newx, newy);
6331 Feld[newx][newy] = EL_FLAMES;
6332 if (IN_LEV_FIELD(newx1, newy1) && Feld[newx1][newy1] == EL_EMPTY)
6335 RemoveField(newx1, newy1);
6337 Feld[newx1][newy1] = EL_FLAMES;
6339 if (IN_LEV_FIELD(newx2, newy2) && Feld[newx2][newy2] == EL_EMPTY)
6342 RemoveField(newx2, newy2);
6344 Feld[newx2][newy2] = EL_FLAMES;
6351 else if (element == EL_YAMYAM && IN_LEV_FIELD(newx, newy) &&
6352 Feld[newx][newy] == EL_DIAMOND)
6354 if (IS_MOVING(newx, newy))
6355 RemoveMovingField(newx, newy);
6358 Feld[newx][newy] = EL_EMPTY;
6359 DrawLevelField(newx, newy);
6362 PlayLevelSound(x, y, SND_YAMYAM_DIGGING);
6364 else if (element == EL_DARK_YAMYAM && IN_LEV_FIELD(newx, newy) &&
6365 IS_FOOD_DARK_YAMYAM(Feld[newx][newy]))
6367 if (AmoebaNr[newx][newy])
6369 AmoebaCnt2[AmoebaNr[newx][newy]]--;
6370 if (Feld[newx][newy] == EL_AMOEBA_FULL ||
6371 Feld[newx][newy] == EL_BD_AMOEBA)
6372 AmoebaCnt[AmoebaNr[newx][newy]]--;
6377 if (IS_MOVING(newx, newy) || IS_BLOCKED(newx, newy))
6379 RemoveMovingField(newx, newy);
6382 if (IS_MOVING(newx, newy))
6384 RemoveMovingField(newx, newy);
6389 Feld[newx][newy] = EL_EMPTY;
6390 DrawLevelField(newx, newy);
6393 PlayLevelSound(x, y, SND_DARK_YAMYAM_DIGGING);
6395 else if ((element == EL_PACMAN || element == EL_MOLE)
6396 && IN_LEV_FIELD(newx, newy) && IS_AMOEBOID(Feld[newx][newy]))
6398 if (AmoebaNr[newx][newy])
6400 AmoebaCnt2[AmoebaNr[newx][newy]]--;
6401 if (Feld[newx][newy] == EL_AMOEBA_FULL ||
6402 Feld[newx][newy] == EL_BD_AMOEBA)
6403 AmoebaCnt[AmoebaNr[newx][newy]]--;
6406 if (element == EL_MOLE)
6408 Feld[newx][newy] = EL_AMOEBA_SHRINKING;
6409 PlayLevelSound(x, y, SND_MOLE_DIGGING);
6411 ResetGfxAnimation(x, y);
6412 GfxAction[x][y] = ACTION_DIGGING;
6413 DrawLevelField(x, y);
6415 MovDelay[newx][newy] = 0; /* start amoeba shrinking delay */
6417 return; /* wait for shrinking amoeba */
6419 else /* element == EL_PACMAN */
6421 Feld[newx][newy] = EL_EMPTY;
6422 DrawLevelField(newx, newy);
6423 PlayLevelSound(x, y, SND_PACMAN_DIGGING);
6426 else if (element == EL_MOLE && IN_LEV_FIELD(newx, newy) &&
6427 (Feld[newx][newy] == EL_AMOEBA_SHRINKING ||
6428 (Feld[newx][newy] == EL_EMPTY && Stop[newx][newy])))
6430 /* wait for shrinking amoeba to completely disappear */
6433 else if (!IN_LEV_FIELD(newx, newy) || !IS_FREE(newx, newy))
6435 /* object was running against a wall */
6440 /* !!! NEW "CE_BLOCKED" STUFF !!! -- DOES NOT WORK YET... !!! */
6441 if (move_pattern & MV_ANY_DIRECTION &&
6442 move_pattern == MovDir[x][y])
6444 int blocking_element =
6445 (IN_LEV_FIELD(newx, newy) ? Feld[newx][newy] : BorderElement);
6447 CheckElementChangeBySide(x, y, element, blocking_element, CE_BLOCKED,
6450 element = Feld[x][y]; /* element might have changed */
6454 if (GFX_ELEMENT(element) != EL_SAND) /* !!! FIX THIS (crumble) !!! */
6455 DrawLevelElementAnimation(x, y, element);
6457 if (DONT_TOUCH(element))
6458 TestIfBadThingTouchesPlayer(x, y);
6463 InitMovingField(x, y, MovDir[x][y]);
6465 PlayLevelSoundAction(x, y, ACTION_MOVING);
6469 ContinueMoving(x, y);
6472 void ContinueMoving(int x, int y)
6474 int element = Feld[x][y];
6475 struct ElementInfo *ei = &element_info[element];
6476 int direction = MovDir[x][y];
6477 int dx = (direction == MV_LEFT ? -1 : direction == MV_RIGHT ? +1 : 0);
6478 int dy = (direction == MV_UP ? -1 : direction == MV_DOWN ? +1 : 0);
6479 int newx = x + dx, newy = y + dy;
6480 int stored = Store[x][y];
6481 int stored_new = Store[newx][newy];
6482 boolean pushed_by_player = (Pushed[x][y] && IS_PLAYER(x, y));
6483 boolean pushed_by_conveyor = (Pushed[x][y] && !IS_PLAYER(x, y));
6484 boolean last_line = (newy == lev_fieldy - 1);
6486 MovPos[x][y] += getElementMoveStepsize(x, y);
6488 if (pushed_by_player) /* special case: moving object pushed by player */
6489 MovPos[x][y] = SIGN(MovPos[x][y]) * (TILEX - ABS(PLAYERINFO(x,y)->MovPos));
6491 if (ABS(MovPos[x][y]) < TILEX)
6493 DrawLevelField(x, y);
6495 return; /* element is still moving */
6498 /* element reached destination field */
6500 Feld[x][y] = EL_EMPTY;
6501 Feld[newx][newy] = element;
6502 MovPos[x][y] = 0; /* force "not moving" for "crumbled sand" */
6504 if (Store[x][y] == EL_ACID) /* element is moving into acid pool */
6506 element = Feld[newx][newy] = EL_ACID;
6508 else if (element == EL_MOLE)
6510 Feld[x][y] = EL_SAND;
6512 DrawLevelFieldCrumbledSandNeighbours(x, y);
6514 else if (element == EL_QUICKSAND_FILLING)
6516 element = Feld[newx][newy] = get_next_element(element);
6517 Store[newx][newy] = Store[x][y];
6519 else if (element == EL_QUICKSAND_EMPTYING)
6521 Feld[x][y] = get_next_element(element);
6522 element = Feld[newx][newy] = Store[x][y];
6524 else if (element == EL_MAGIC_WALL_FILLING)
6526 element = Feld[newx][newy] = get_next_element(element);
6527 if (!game.magic_wall_active)
6528 element = Feld[newx][newy] = EL_MAGIC_WALL_DEAD;
6529 Store[newx][newy] = Store[x][y];
6531 else if (element == EL_MAGIC_WALL_EMPTYING)
6533 Feld[x][y] = get_next_element(element);
6534 if (!game.magic_wall_active)
6535 Feld[x][y] = EL_MAGIC_WALL_DEAD;
6536 element = Feld[newx][newy] = Store[x][y];
6538 #if USE_NEW_CUSTOM_VALUE
6539 InitField(newx, newy, FALSE);
6542 else if (element == EL_BD_MAGIC_WALL_FILLING)
6544 element = Feld[newx][newy] = get_next_element(element);
6545 if (!game.magic_wall_active)
6546 element = Feld[newx][newy] = EL_BD_MAGIC_WALL_DEAD;
6547 Store[newx][newy] = Store[x][y];
6549 else if (element == EL_BD_MAGIC_WALL_EMPTYING)
6551 Feld[x][y] = get_next_element(element);
6552 if (!game.magic_wall_active)
6553 Feld[x][y] = EL_BD_MAGIC_WALL_DEAD;
6554 element = Feld[newx][newy] = Store[x][y];
6556 #if USE_NEW_CUSTOM_VALUE
6557 InitField(newx, newy, FALSE);
6560 else if (element == EL_AMOEBA_DROPPING)
6562 Feld[x][y] = get_next_element(element);
6563 element = Feld[newx][newy] = Store[x][y];
6565 else if (element == EL_SOKOBAN_OBJECT)
6568 Feld[x][y] = Back[x][y];
6570 if (Back[newx][newy])
6571 Feld[newx][newy] = EL_SOKOBAN_FIELD_FULL;
6573 Back[x][y] = Back[newx][newy] = 0;
6576 Store[x][y] = EL_EMPTY;
6581 MovDelay[newx][newy] = 0;
6583 if (CAN_CHANGE_OR_HAS_ACTION(element))
6585 /* copy element change control values to new field */
6586 ChangeDelay[newx][newy] = ChangeDelay[x][y];
6587 ChangePage[newx][newy] = ChangePage[x][y];
6588 ChangeCount[newx][newy] = ChangeCount[x][y];
6589 ChangeEvent[newx][newy] = ChangeEvent[x][y];
6592 #if USE_NEW_CUSTOM_VALUE
6593 CustomValue[newx][newy] = CustomValue[x][y];
6596 ChangeDelay[x][y] = 0;
6597 ChangePage[x][y] = -1;
6598 ChangeCount[x][y] = 0;
6599 ChangeEvent[x][y] = -1;
6601 #if USE_NEW_CUSTOM_VALUE
6602 CustomValue[x][y] = 0;
6605 /* copy animation control values to new field */
6606 GfxFrame[newx][newy] = GfxFrame[x][y];
6607 GfxRandom[newx][newy] = GfxRandom[x][y]; /* keep same random value */
6608 GfxAction[newx][newy] = GfxAction[x][y]; /* keep action one frame */
6609 GfxDir[newx][newy] = GfxDir[x][y]; /* keep element direction */
6611 Pushed[x][y] = Pushed[newx][newy] = FALSE;
6613 /* some elements can leave other elements behind after moving */
6615 if (ei->move_leave_element != EL_EMPTY &&
6616 (ei->move_leave_type == LEAVE_TYPE_UNLIMITED || stored != EL_EMPTY) &&
6617 (!IS_PLAYER(x, y) || IS_WALKABLE(ei->move_leave_element)))
6619 if (IS_CUSTOM_ELEMENT(element) && ei->move_leave_element != EL_EMPTY &&
6620 (ei->move_leave_type == LEAVE_TYPE_UNLIMITED || stored != EL_EMPTY) &&
6621 (!IS_PLAYER(x, y) || IS_WALKABLE(ei->move_leave_element)))
6624 int move_leave_element = ei->move_leave_element;
6628 /* this makes it possible to leave the removed element again */
6629 if (ei->move_leave_element == EL_TRIGGER_ELEMENT)
6630 move_leave_element = (stored == EL_ACID ? EL_EMPTY : stored);
6632 /* this makes it possible to leave the removed element again */
6633 if (ei->move_leave_element == EL_TRIGGER_ELEMENT)
6634 move_leave_element = stored;
6637 /* this makes it possible to leave the removed element again */
6638 if (ei->move_leave_type == LEAVE_TYPE_LIMITED &&
6639 ei->move_leave_element == EL_TRIGGER_ELEMENT)
6640 move_leave_element = stored;
6643 Feld[x][y] = move_leave_element;
6645 if (element_info[Feld[x][y]].move_direction_initial == MV_START_PREVIOUS)
6646 MovDir[x][y] = direction;
6648 InitField(x, y, FALSE);
6650 if (GFX_CRUMBLED(Feld[x][y]))
6651 DrawLevelFieldCrumbledSandNeighbours(x, y);
6653 if (ELEM_IS_PLAYER(move_leave_element))
6654 RelocatePlayer(x, y, move_leave_element);
6657 /* do this after checking for left-behind element */
6658 ResetGfxAnimation(x, y); /* reset animation values for old field */
6660 if (!CAN_MOVE(element) ||
6661 (CAN_FALL(element) && direction == MV_DOWN &&
6662 (element == EL_SPRING ||
6663 element_info[element].move_pattern == MV_WHEN_PUSHED ||
6664 element_info[element].move_pattern == MV_WHEN_DROPPED)))
6665 GfxDir[x][y] = MovDir[newx][newy] = 0;
6667 DrawLevelField(x, y);
6668 DrawLevelField(newx, newy);
6670 Stop[newx][newy] = TRUE; /* ignore this element until the next frame */
6672 /* prevent pushed element from moving on in pushed direction */
6673 if (pushed_by_player && CAN_MOVE(element) &&
6674 element_info[element].move_pattern & MV_ANY_DIRECTION &&
6675 !(element_info[element].move_pattern & direction))
6676 TurnRound(newx, newy);
6678 /* prevent elements on conveyor belt from moving on in last direction */
6679 if (pushed_by_conveyor && CAN_FALL(element) &&
6680 direction & MV_HORIZONTAL)
6681 MovDir[newx][newy] = 0;
6683 if (!pushed_by_player)
6685 int nextx = newx + dx, nexty = newy + dy;
6686 boolean check_collision_again = IN_LEV_FIELD_AND_IS_FREE(nextx, nexty);
6688 WasJustMoving[newx][newy] = CHECK_DELAY_MOVING;
6690 if (CAN_FALL(element) && direction == MV_DOWN)
6691 WasJustFalling[newx][newy] = CHECK_DELAY_FALLING;
6693 if ((!CAN_FALL(element) || direction == MV_DOWN) && check_collision_again)
6694 CheckCollision[newx][newy] = CHECK_DELAY_COLLISION;
6696 #if USE_FIX_IMPACT_COLLISION
6697 if (CAN_FALL(element) && direction == MV_DOWN && check_collision_again)
6698 CheckImpact[newx][newy] = CHECK_DELAY_IMPACT;
6702 if (DONT_TOUCH(element)) /* object may be nasty to player or others */
6704 TestIfBadThingTouchesPlayer(newx, newy);
6705 TestIfBadThingTouchesFriend(newx, newy);
6707 if (!IS_CUSTOM_ELEMENT(element))
6708 TestIfBadThingTouchesOtherBadThing(newx, newy);
6710 else if (element == EL_PENGUIN)
6711 TestIfFriendTouchesBadThing(newx, newy);
6713 /* give the player one last chance (one more frame) to move away */
6714 if (CAN_FALL(element) && direction == MV_DOWN &&
6715 (last_line || (!IS_FREE(x, newy + 1) &&
6716 (!IS_PLAYER(x, newy + 1) ||
6717 game.engine_version < VERSION_IDENT(3,1,1,0)))))
6720 if (pushed_by_player && !game.use_change_when_pushing_bug)
6722 int push_side = MV_DIR_OPPOSITE(direction);
6723 struct PlayerInfo *player = PLAYERINFO(x, y);
6725 CheckElementChangeByPlayer(newx, newy, element, CE_PUSHED_BY_PLAYER,
6726 player->index_bit, push_side);
6727 CheckTriggeredElementChangeByPlayer(newx,newy, element, CE_PLAYER_PUSHES_X,
6728 player->index_bit, push_side);
6731 if (element == EL_EMC_ANDROID && pushed_by_player) /* make another move */
6732 MovDelay[newx][newy] = 1;
6734 CheckTriggeredElementChangeBySide(x, y, element, CE_MOVE_OF_X, direction);
6736 TestIfElementTouchesCustomElement(x, y); /* empty or new element */
6739 if (ChangePage[newx][newy] != -1) /* delayed change */
6741 int page = ChangePage[newx][newy];
6742 struct ElementChangeInfo *change = &ei->change_page[page];
6744 ChangePage[newx][newy] = -1;
6746 if (change->can_change)
6748 if (ChangeElement(newx, newy, element, page))
6750 if (change->post_change_function)
6751 change->post_change_function(newx, newy);
6755 if (change->has_action)
6756 ExecuteCustomElementAction(newx, newy, element, page);
6760 TestIfElementHitsCustomElement(newx, newy, direction);
6761 TestIfPlayerTouchesCustomElement(newx, newy);
6762 TestIfElementTouchesCustomElement(newx, newy);
6764 if (IS_CUSTOM_ELEMENT(element) && ei->move_enter_element != EL_EMPTY &&
6765 IS_EQUAL_OR_IN_GROUP(stored_new, ei->move_enter_element))
6766 CheckElementChangeBySide(newx, newy, element, stored_new, CE_DIGGING_X,
6767 MV_DIR_OPPOSITE(direction));
6770 int AmoebeNachbarNr(int ax, int ay)
6773 int element = Feld[ax][ay];
6775 static int xy[4][2] =
6783 for (i = 0; i < NUM_DIRECTIONS; i++)
6785 int x = ax + xy[i][0];
6786 int y = ay + xy[i][1];
6788 if (!IN_LEV_FIELD(x, y))
6791 if (Feld[x][y] == element && AmoebaNr[x][y] > 0)
6792 group_nr = AmoebaNr[x][y];
6798 void AmoebenVereinigen(int ax, int ay)
6800 int i, x, y, xx, yy;
6801 int new_group_nr = AmoebaNr[ax][ay];
6802 static int xy[4][2] =
6810 if (new_group_nr == 0)
6813 for (i = 0; i < NUM_DIRECTIONS; i++)
6818 if (!IN_LEV_FIELD(x, y))
6821 if ((Feld[x][y] == EL_AMOEBA_FULL ||
6822 Feld[x][y] == EL_BD_AMOEBA ||
6823 Feld[x][y] == EL_AMOEBA_DEAD) &&
6824 AmoebaNr[x][y] != new_group_nr)
6826 int old_group_nr = AmoebaNr[x][y];
6828 if (old_group_nr == 0)
6831 AmoebaCnt[new_group_nr] += AmoebaCnt[old_group_nr];
6832 AmoebaCnt[old_group_nr] = 0;
6833 AmoebaCnt2[new_group_nr] += AmoebaCnt2[old_group_nr];
6834 AmoebaCnt2[old_group_nr] = 0;
6836 SCAN_PLAYFIELD(xx, yy)
6838 if (AmoebaNr[xx][yy] == old_group_nr)
6839 AmoebaNr[xx][yy] = new_group_nr;
6845 void AmoebeUmwandeln(int ax, int ay)
6849 if (Feld[ax][ay] == EL_AMOEBA_DEAD)
6851 int group_nr = AmoebaNr[ax][ay];
6856 printf("AmoebeUmwandeln(): ax = %d, ay = %d\n", ax, ay);
6857 printf("AmoebeUmwandeln(): This should never happen!\n");
6862 SCAN_PLAYFIELD(x, y)
6864 if (Feld[x][y] == EL_AMOEBA_DEAD && AmoebaNr[x][y] == group_nr)
6867 Feld[x][y] = EL_AMOEBA_TO_DIAMOND;
6871 PlayLevelSound(ax, ay, (IS_GEM(level.amoeba_content) ?
6872 SND_AMOEBA_TURNING_TO_GEM :
6873 SND_AMOEBA_TURNING_TO_ROCK));
6878 static int xy[4][2] =
6886 for (i = 0; i < NUM_DIRECTIONS; i++)
6891 if (!IN_LEV_FIELD(x, y))
6894 if (Feld[x][y] == EL_AMOEBA_TO_DIAMOND)
6896 PlayLevelSound(x, y, (IS_GEM(level.amoeba_content) ?
6897 SND_AMOEBA_TURNING_TO_GEM :
6898 SND_AMOEBA_TURNING_TO_ROCK));
6905 void AmoebeUmwandelnBD(int ax, int ay, int new_element)
6908 int group_nr = AmoebaNr[ax][ay];
6909 boolean done = FALSE;
6914 printf("AmoebeUmwandelnBD(): ax = %d, ay = %d\n", ax, ay);
6915 printf("AmoebeUmwandelnBD(): This should never happen!\n");
6920 SCAN_PLAYFIELD(x, y)
6922 if (AmoebaNr[x][y] == group_nr &&
6923 (Feld[x][y] == EL_AMOEBA_DEAD ||
6924 Feld[x][y] == EL_BD_AMOEBA ||
6925 Feld[x][y] == EL_AMOEBA_GROWING))
6928 Feld[x][y] = new_element;
6929 InitField(x, y, FALSE);
6930 DrawLevelField(x, y);
6936 PlayLevelSound(ax, ay, (new_element == EL_BD_ROCK ?
6937 SND_BD_AMOEBA_TURNING_TO_ROCK :
6938 SND_BD_AMOEBA_TURNING_TO_GEM));
6941 void AmoebeWaechst(int x, int y)
6943 static unsigned long sound_delay = 0;
6944 static unsigned long sound_delay_value = 0;
6946 if (!MovDelay[x][y]) /* start new growing cycle */
6950 if (DelayReached(&sound_delay, sound_delay_value))
6952 PlayLevelSoundElementAction(x, y, Store[x][y], ACTION_GROWING);
6953 sound_delay_value = 30;
6957 if (MovDelay[x][y]) /* wait some time before growing bigger */
6960 if (MovDelay[x][y]/2 && IN_SCR_FIELD(SCREENX(x), SCREENY(y)))
6962 int frame = getGraphicAnimationFrame(IMG_AMOEBA_GROWING,
6963 6 - MovDelay[x][y]);
6965 DrawGraphic(SCREENX(x), SCREENY(y), IMG_AMOEBA_GROWING, frame);
6968 if (!MovDelay[x][y])
6970 Feld[x][y] = Store[x][y];
6972 DrawLevelField(x, y);
6977 void AmoebaDisappearing(int x, int y)
6979 static unsigned long sound_delay = 0;
6980 static unsigned long sound_delay_value = 0;
6982 if (!MovDelay[x][y]) /* start new shrinking cycle */
6986 if (DelayReached(&sound_delay, sound_delay_value))
6987 sound_delay_value = 30;
6990 if (MovDelay[x][y]) /* wait some time before shrinking */
6993 if (MovDelay[x][y]/2 && IN_SCR_FIELD(SCREENX(x), SCREENY(y)))
6995 int frame = getGraphicAnimationFrame(IMG_AMOEBA_SHRINKING,
6996 6 - MovDelay[x][y]);
6998 DrawGraphic(SCREENX(x), SCREENY(y), IMG_AMOEBA_SHRINKING, frame);
7001 if (!MovDelay[x][y])
7003 Feld[x][y] = EL_EMPTY;
7004 DrawLevelField(x, y);
7006 /* don't let mole enter this field in this cycle;
7007 (give priority to objects falling to this field from above) */
7013 void AmoebeAbleger(int ax, int ay)
7016 int element = Feld[ax][ay];
7017 int graphic = el2img(element);
7018 int newax = ax, neway = ay;
7019 boolean can_drop = (element == EL_AMOEBA_WET || element == EL_EMC_DRIPPER);
7020 static int xy[4][2] =
7028 if (!level.amoeba_speed && element != EL_EMC_DRIPPER)
7030 Feld[ax][ay] = EL_AMOEBA_DEAD;
7031 DrawLevelField(ax, ay);
7035 if (IS_ANIMATED(graphic))
7036 DrawLevelGraphicAnimationIfNeeded(ax, ay, graphic);
7038 if (!MovDelay[ax][ay]) /* start making new amoeba field */
7039 MovDelay[ax][ay] = RND(FRAMES_PER_SECOND * 25 / (1 + level.amoeba_speed));
7041 if (MovDelay[ax][ay]) /* wait some time before making new amoeba */
7044 if (MovDelay[ax][ay])
7048 if (can_drop) /* EL_AMOEBA_WET or EL_EMC_DRIPPER */
7051 int x = ax + xy[start][0];
7052 int y = ay + xy[start][1];
7054 if (!IN_LEV_FIELD(x, y))
7057 if (IS_FREE(x, y) ||
7058 CAN_GROW_INTO(Feld[x][y]) ||
7059 Feld[x][y] == EL_QUICKSAND_EMPTY)
7065 if (newax == ax && neway == ay)
7068 else /* normal or "filled" (BD style) amoeba */
7071 boolean waiting_for_player = FALSE;
7073 for (i = 0; i < NUM_DIRECTIONS; i++)
7075 int j = (start + i) % 4;
7076 int x = ax + xy[j][0];
7077 int y = ay + xy[j][1];
7079 if (!IN_LEV_FIELD(x, y))
7082 if (IS_FREE(x, y) ||
7083 CAN_GROW_INTO(Feld[x][y]) ||
7084 Feld[x][y] == EL_QUICKSAND_EMPTY)
7090 else if (IS_PLAYER(x, y))
7091 waiting_for_player = TRUE;
7094 if (newax == ax && neway == ay) /* amoeba cannot grow */
7096 if (i == 4 && (!waiting_for_player || element == EL_BD_AMOEBA))
7098 Feld[ax][ay] = EL_AMOEBA_DEAD;
7099 DrawLevelField(ax, ay);
7100 AmoebaCnt[AmoebaNr[ax][ay]]--;
7102 if (AmoebaCnt[AmoebaNr[ax][ay]] <= 0) /* amoeba is completely dead */
7104 if (element == EL_AMOEBA_FULL)
7105 AmoebeUmwandeln(ax, ay);
7106 else if (element == EL_BD_AMOEBA)
7107 AmoebeUmwandelnBD(ax, ay, level.amoeba_content);
7112 else if (element == EL_AMOEBA_FULL || element == EL_BD_AMOEBA)
7114 /* amoeba gets larger by growing in some direction */
7116 int new_group_nr = AmoebaNr[ax][ay];
7119 if (new_group_nr == 0)
7121 printf("AmoebeAbleger(): newax = %d, neway = %d\n", newax, neway);
7122 printf("AmoebeAbleger(): This should never happen!\n");
7127 AmoebaNr[newax][neway] = new_group_nr;
7128 AmoebaCnt[new_group_nr]++;
7129 AmoebaCnt2[new_group_nr]++;
7131 /* if amoeba touches other amoeba(s) after growing, unify them */
7132 AmoebenVereinigen(newax, neway);
7134 if (element == EL_BD_AMOEBA && AmoebaCnt2[new_group_nr] >= 200)
7136 AmoebeUmwandelnBD(newax, neway, EL_BD_ROCK);
7142 if (!can_drop || neway < ay || !IS_FREE(newax, neway) ||
7143 (neway == lev_fieldy - 1 && newax != ax))
7145 Feld[newax][neway] = EL_AMOEBA_GROWING; /* creation of new amoeba */
7146 Store[newax][neway] = element;
7148 else if (neway == ay || element == EL_EMC_DRIPPER)
7150 Feld[newax][neway] = EL_AMOEBA_DROP; /* drop left/right of amoeba */
7152 PlayLevelSoundAction(newax, neway, ACTION_GROWING);
7156 InitMovingField(ax, ay, MV_DOWN); /* drop dripping from amoeba */
7157 Feld[ax][ay] = EL_AMOEBA_DROPPING;
7158 Store[ax][ay] = EL_AMOEBA_DROP;
7159 ContinueMoving(ax, ay);
7163 DrawLevelField(newax, neway);
7166 void Life(int ax, int ay)
7170 int element = Feld[ax][ay];
7171 int graphic = el2img(element);
7172 int *life_parameter = (element == EL_GAME_OF_LIFE ? level.game_of_life :
7174 boolean changed = FALSE;
7176 if (IS_ANIMATED(graphic))
7177 DrawLevelGraphicAnimationIfNeeded(ax, ay, graphic);
7182 if (!MovDelay[ax][ay]) /* start new "game of life" cycle */
7183 MovDelay[ax][ay] = life_time;
7185 if (MovDelay[ax][ay]) /* wait some time before next cycle */
7188 if (MovDelay[ax][ay])
7192 for (y1 = -1; y1 < 2; y1++) for (x1 = -1; x1 < 2; x1++)
7194 int xx = ax+x1, yy = ay+y1;
7197 if (!IN_LEV_FIELD(xx, yy))
7200 for (y2 = -1; y2 < 2; y2++) for (x2 = -1; x2 < 2; x2++)
7202 int x = xx+x2, y = yy+y2;
7204 if (!IN_LEV_FIELD(x, y) || (x == xx && y == yy))
7207 if (((Feld[x][y] == element ||
7208 (element == EL_GAME_OF_LIFE && IS_PLAYER(x, y))) &&
7210 (IS_FREE(x, y) && Stop[x][y]))
7214 if (xx == ax && yy == ay) /* field in the middle */
7216 if (nachbarn < life_parameter[0] ||
7217 nachbarn > life_parameter[1])
7219 Feld[xx][yy] = EL_EMPTY;
7221 DrawLevelField(xx, yy);
7222 Stop[xx][yy] = TRUE;
7226 else if (IS_FREE(xx, yy) || CAN_GROW_INTO(Feld[xx][yy]))
7227 { /* free border field */
7228 if (nachbarn >= life_parameter[2] &&
7229 nachbarn <= life_parameter[3])
7231 Feld[xx][yy] = element;
7232 MovDelay[xx][yy] = (element == EL_GAME_OF_LIFE ? 0 : life_time-1);
7234 DrawLevelField(xx, yy);
7235 Stop[xx][yy] = TRUE;
7242 PlayLevelSound(ax, ay, element == EL_BIOMAZE ? SND_BIOMAZE_GROWING :
7243 SND_GAME_OF_LIFE_GROWING);
7246 static void InitRobotWheel(int x, int y)
7248 ChangeDelay[x][y] = level.time_wheel * FRAMES_PER_SECOND;
7251 static void RunRobotWheel(int x, int y)
7253 PlayLevelSound(x, y, SND_ROBOT_WHEEL_ACTIVE);
7256 static void StopRobotWheel(int x, int y)
7258 if (ZX == x && ZY == y)
7262 static void InitTimegateWheel(int x, int y)
7264 ChangeDelay[x][y] = level.time_timegate * FRAMES_PER_SECOND;
7267 static void RunTimegateWheel(int x, int y)
7269 PlayLevelSound(x, y, SND_TIMEGATE_SWITCH_ACTIVE);
7272 static void InitMagicBallDelay(int x, int y)
7275 ChangeDelay[x][y] = (level.ball_time + 1) * 8 + 1;
7277 ChangeDelay[x][y] = level.ball_time * FRAMES_PER_SECOND + 1;
7281 static void ActivateMagicBall(int bx, int by)
7285 if (level.ball_random)
7287 int pos_border = RND(8); /* select one of the eight border elements */
7288 int pos_content = (pos_border > 3 ? pos_border + 1 : pos_border);
7289 int xx = pos_content % 3;
7290 int yy = pos_content / 3;
7295 if (IN_LEV_FIELD(x, y) && Feld[x][y] == EL_EMPTY)
7296 CreateField(x, y, level.ball_content[game.ball_content_nr].e[xx][yy]);
7300 for (y = by - 1; y <= by + 1; y++) for (x = bx - 1; x <= bx + 1; x++)
7302 int xx = x - bx + 1;
7303 int yy = y - by + 1;
7305 if (IN_LEV_FIELD(x, y) && Feld[x][y] == EL_EMPTY)
7306 CreateField(x, y, level.ball_content[game.ball_content_nr].e[xx][yy]);
7310 game.ball_content_nr = (game.ball_content_nr + 1) % level.num_ball_contents;
7313 void CheckExit(int x, int y)
7315 if (local_player->gems_still_needed > 0 ||
7316 local_player->sokobanfields_still_needed > 0 ||
7317 local_player->lights_still_needed > 0)
7319 int element = Feld[x][y];
7320 int graphic = el2img(element);
7322 if (IS_ANIMATED(graphic))
7323 DrawLevelGraphicAnimationIfNeeded(x, y, graphic);
7328 if (AllPlayersGone) /* do not re-open exit door closed after last player */
7331 Feld[x][y] = EL_EXIT_OPENING;
7333 PlayLevelSoundNearest(x, y, SND_CLASS_EXIT_OPENING);
7336 void CheckExitSteel(int x, int y)
7338 if (local_player->gems_still_needed > 0 ||
7339 local_player->sokobanfields_still_needed > 0 ||
7340 local_player->lights_still_needed > 0)
7342 int element = Feld[x][y];
7343 int graphic = el2img(element);
7345 if (IS_ANIMATED(graphic))
7346 DrawLevelGraphicAnimationIfNeeded(x, y, graphic);
7351 if (AllPlayersGone) /* do not re-open exit door closed after last player */
7354 Feld[x][y] = EL_STEEL_EXIT_OPENING;
7356 PlayLevelSoundNearest(x, y, SND_CLASS_STEEL_EXIT_OPENING);
7359 void CheckExitSP(int x, int y)
7361 if (local_player->gems_still_needed > 0)
7363 int element = Feld[x][y];
7364 int graphic = el2img(element);
7366 if (IS_ANIMATED(graphic))
7367 DrawLevelGraphicAnimationIfNeeded(x, y, graphic);
7372 if (AllPlayersGone) /* do not re-open exit door closed after last player */
7375 Feld[x][y] = EL_SP_EXIT_OPENING;
7377 PlayLevelSoundNearest(x, y, SND_CLASS_SP_EXIT_OPENING);
7380 static void CloseAllOpenTimegates()
7384 SCAN_PLAYFIELD(x, y)
7386 int element = Feld[x][y];
7388 if (element == EL_TIMEGATE_OPEN || element == EL_TIMEGATE_OPENING)
7390 Feld[x][y] = EL_TIMEGATE_CLOSING;
7392 PlayLevelSoundAction(x, y, ACTION_CLOSING);
7397 void DrawTwinkleOnField(int x, int y)
7399 if (!IN_SCR_FIELD(SCREENX(x), SCREENY(y)) || IS_MOVING(x, y))
7402 if (Feld[x][y] == EL_BD_DIAMOND)
7405 if (MovDelay[x][y] == 0) /* next animation frame */
7406 MovDelay[x][y] = 11 * !GetSimpleRandom(500);
7408 if (MovDelay[x][y] != 0) /* wait some time before next frame */
7412 if (setup.direct_draw && MovDelay[x][y])
7413 SetDrawtoField(DRAW_BUFFERED);
7415 DrawLevelElementAnimation(x, y, Feld[x][y]);
7417 if (MovDelay[x][y] != 0)
7419 int frame = getGraphicAnimationFrame(IMG_TWINKLE_WHITE,
7420 10 - MovDelay[x][y]);
7422 DrawGraphicThruMask(SCREENX(x), SCREENY(y), IMG_TWINKLE_WHITE, frame);
7424 if (setup.direct_draw)
7428 dest_x = FX + SCREENX(x) * TILEX;
7429 dest_y = FY + SCREENY(y) * TILEY;
7431 BlitBitmap(drawto_field, window,
7432 dest_x, dest_y, TILEX, TILEY, dest_x, dest_y);
7433 SetDrawtoField(DRAW_DIRECT);
7439 void MauerWaechst(int x, int y)
7443 if (!MovDelay[x][y]) /* next animation frame */
7444 MovDelay[x][y] = 3 * delay;
7446 if (MovDelay[x][y]) /* wait some time before next frame */
7450 if (IN_SCR_FIELD(SCREENX(x), SCREENY(y)))
7452 int graphic = el_dir2img(Feld[x][y], GfxDir[x][y]);
7453 int frame = getGraphicAnimationFrame(graphic, 17 - MovDelay[x][y]);
7455 DrawGraphic(SCREENX(x), SCREENY(y), graphic, frame);
7458 if (!MovDelay[x][y])
7460 if (MovDir[x][y] == MV_LEFT)
7462 if (IN_LEV_FIELD(x - 1, y) && IS_WALL(Feld[x - 1][y]))
7463 DrawLevelField(x - 1, y);
7465 else if (MovDir[x][y] == MV_RIGHT)
7467 if (IN_LEV_FIELD(x + 1, y) && IS_WALL(Feld[x + 1][y]))
7468 DrawLevelField(x + 1, y);
7470 else if (MovDir[x][y] == MV_UP)
7472 if (IN_LEV_FIELD(x, y - 1) && IS_WALL(Feld[x][y - 1]))
7473 DrawLevelField(x, y - 1);
7477 if (IN_LEV_FIELD(x, y + 1) && IS_WALL(Feld[x][y + 1]))
7478 DrawLevelField(x, y + 1);
7481 Feld[x][y] = Store[x][y];
7483 GfxDir[x][y] = MovDir[x][y] = MV_NONE;
7484 DrawLevelField(x, y);
7489 void MauerAbleger(int ax, int ay)
7491 int element = Feld[ax][ay];
7492 int graphic = el2img(element);
7493 boolean oben_frei = FALSE, unten_frei = FALSE;
7494 boolean links_frei = FALSE, rechts_frei = FALSE;
7495 boolean oben_massiv = FALSE, unten_massiv = FALSE;
7496 boolean links_massiv = FALSE, rechts_massiv = FALSE;
7497 boolean new_wall = FALSE;
7499 if (IS_ANIMATED(graphic))
7500 DrawLevelGraphicAnimationIfNeeded(ax, ay, graphic);
7502 if (!MovDelay[ax][ay]) /* start building new wall */
7503 MovDelay[ax][ay] = 6;
7505 if (MovDelay[ax][ay]) /* wait some time before building new wall */
7508 if (MovDelay[ax][ay])
7512 if (IN_LEV_FIELD(ax, ay-1) && IS_FREE(ax, ay-1))
7514 if (IN_LEV_FIELD(ax, ay+1) && IS_FREE(ax, ay+1))
7516 if (IN_LEV_FIELD(ax-1, ay) && IS_FREE(ax-1, ay))
7518 if (IN_LEV_FIELD(ax+1, ay) && IS_FREE(ax+1, ay))
7521 if (element == EL_EXPANDABLE_WALL_VERTICAL ||
7522 element == EL_EXPANDABLE_WALL_ANY)
7526 Feld[ax][ay-1] = EL_EXPANDABLE_WALL_GROWING;
7527 Store[ax][ay-1] = element;
7528 GfxDir[ax][ay-1] = MovDir[ax][ay-1] = MV_UP;
7529 if (IN_SCR_FIELD(SCREENX(ax), SCREENY(ay-1)))
7530 DrawGraphic(SCREENX(ax), SCREENY(ay - 1),
7531 IMG_EXPANDABLE_WALL_GROWING_UP, 0);
7536 Feld[ax][ay+1] = EL_EXPANDABLE_WALL_GROWING;
7537 Store[ax][ay+1] = element;
7538 GfxDir[ax][ay+1] = MovDir[ax][ay+1] = MV_DOWN;
7539 if (IN_SCR_FIELD(SCREENX(ax), SCREENY(ay+1)))
7540 DrawGraphic(SCREENX(ax), SCREENY(ay + 1),
7541 IMG_EXPANDABLE_WALL_GROWING_DOWN, 0);
7546 if (element == EL_EXPANDABLE_WALL_HORIZONTAL ||
7547 element == EL_EXPANDABLE_WALL_ANY ||
7548 element == EL_EXPANDABLE_WALL ||
7549 element == EL_BD_EXPANDABLE_WALL)
7553 Feld[ax-1][ay] = EL_EXPANDABLE_WALL_GROWING;
7554 Store[ax-1][ay] = element;
7555 GfxDir[ax-1][ay] = MovDir[ax-1][ay] = MV_LEFT;
7556 if (IN_SCR_FIELD(SCREENX(ax-1), SCREENY(ay)))
7557 DrawGraphic(SCREENX(ax - 1), SCREENY(ay),
7558 IMG_EXPANDABLE_WALL_GROWING_LEFT, 0);
7564 Feld[ax+1][ay] = EL_EXPANDABLE_WALL_GROWING;
7565 Store[ax+1][ay] = element;
7566 GfxDir[ax+1][ay] = MovDir[ax+1][ay] = MV_RIGHT;
7567 if (IN_SCR_FIELD(SCREENX(ax+1), SCREENY(ay)))
7568 DrawGraphic(SCREENX(ax + 1), SCREENY(ay),
7569 IMG_EXPANDABLE_WALL_GROWING_RIGHT, 0);
7574 if (element == EL_EXPANDABLE_WALL && (links_frei || rechts_frei))
7575 DrawLevelField(ax, ay);
7577 if (!IN_LEV_FIELD(ax, ay-1) || IS_WALL(Feld[ax][ay-1]))
7579 if (!IN_LEV_FIELD(ax, ay+1) || IS_WALL(Feld[ax][ay+1]))
7580 unten_massiv = TRUE;
7581 if (!IN_LEV_FIELD(ax-1, ay) || IS_WALL(Feld[ax-1][ay]))
7582 links_massiv = TRUE;
7583 if (!IN_LEV_FIELD(ax+1, ay) || IS_WALL(Feld[ax+1][ay]))
7584 rechts_massiv = TRUE;
7586 if (((oben_massiv && unten_massiv) ||
7587 element == EL_EXPANDABLE_WALL_HORIZONTAL ||
7588 element == EL_EXPANDABLE_WALL) &&
7589 ((links_massiv && rechts_massiv) ||
7590 element == EL_EXPANDABLE_WALL_VERTICAL))
7591 Feld[ax][ay] = EL_WALL;
7594 PlayLevelSoundAction(ax, ay, ACTION_GROWING);
7597 void CheckForDragon(int x, int y)
7600 boolean dragon_found = FALSE;
7601 static int xy[4][2] =
7609 for (i = 0; i < NUM_DIRECTIONS; i++)
7611 for (j = 0; j < 4; j++)
7613 int xx = x + j * xy[i][0], yy = y + j * xy[i][1];
7615 if (IN_LEV_FIELD(xx, yy) &&
7616 (Feld[xx][yy] == EL_FLAMES || Feld[xx][yy] == EL_DRAGON))
7618 if (Feld[xx][yy] == EL_DRAGON)
7619 dragon_found = TRUE;
7628 for (i = 0; i < NUM_DIRECTIONS; i++)
7630 for (j = 0; j < 3; j++)
7632 int xx = x + j * xy[i][0], yy = y + j * xy[i][1];
7634 if (IN_LEV_FIELD(xx, yy) && Feld[xx][yy] == EL_FLAMES)
7636 Feld[xx][yy] = EL_EMPTY;
7637 DrawLevelField(xx, yy);
7646 static void InitBuggyBase(int x, int y)
7648 int element = Feld[x][y];
7649 int activating_delay = FRAMES_PER_SECOND / 4;
7652 (element == EL_SP_BUGGY_BASE ?
7653 2 * FRAMES_PER_SECOND + RND(5 * FRAMES_PER_SECOND) - activating_delay :
7654 element == EL_SP_BUGGY_BASE_ACTIVATING ?
7656 element == EL_SP_BUGGY_BASE_ACTIVE ?
7657 1 * FRAMES_PER_SECOND + RND(1 * FRAMES_PER_SECOND) : 1);
7660 static void WarnBuggyBase(int x, int y)
7663 static int xy[4][2] =
7671 for (i = 0; i < NUM_DIRECTIONS; i++)
7673 int xx = x + xy[i][0];
7674 int yy = y + xy[i][1];
7676 if (IN_LEV_FIELD(xx, yy) && IS_PLAYER(xx, yy))
7678 PlayLevelSound(x, y, SND_SP_BUGGY_BASE_ACTIVE);
7685 static void InitTrap(int x, int y)
7687 ChangeDelay[x][y] = 2 * FRAMES_PER_SECOND + RND(5 * FRAMES_PER_SECOND);
7690 static void ActivateTrap(int x, int y)
7692 PlayLevelSound(x, y, SND_TRAP_ACTIVATING);
7695 static void ChangeActiveTrap(int x, int y)
7697 int graphic = IMG_TRAP_ACTIVE;
7699 /* if new animation frame was drawn, correct crumbled sand border */
7700 if (IS_NEW_FRAME(GfxFrame[x][y], graphic))
7701 DrawLevelFieldCrumbledSand(x, y);
7704 static int getSpecialActionElement(int element, int number, int base_element)
7706 return (element != EL_EMPTY ? element :
7707 number != -1 ? base_element + number - 1 :
7711 static int getModifiedActionNumber(int value_old, int operator, int operand,
7712 int value_min, int value_max)
7714 int value_new = (operator == CA_MODE_SET ? operand :
7715 operator == CA_MODE_ADD ? value_old + operand :
7716 operator == CA_MODE_SUBTRACT ? value_old - operand :
7717 operator == CA_MODE_MULTIPLY ? value_old * operand :
7718 operator == CA_MODE_DIVIDE ? value_old / MAX(1, operand) :
7719 operator == CA_MODE_MODULO ? value_old % MAX(1, operand) :
7722 return (value_new < value_min ? value_min :
7723 value_new > value_max ? value_max :
7727 static void ExecuteCustomElementAction(int x, int y, int element, int page)
7729 struct ElementInfo *ei = &element_info[element];
7730 struct ElementChangeInfo *change = &ei->change_page[page];
7731 int target_element = change->target_element;
7732 int action_type = change->action_type;
7733 int action_mode = change->action_mode;
7734 int action_arg = change->action_arg;
7737 if (!change->has_action)
7740 /* ---------- determine action paramater values -------------------------- */
7742 int level_time_value =
7743 (level.time > 0 ? TimeLeft :
7746 int action_arg_element =
7747 (action_arg == CA_ARG_PLAYER_TRIGGER ? change->actual_trigger_player :
7748 action_arg == CA_ARG_ELEMENT_TRIGGER ? change->actual_trigger_element :
7749 action_arg == CA_ARG_ELEMENT_TARGET ? change->target_element :
7752 int action_arg_direction =
7753 (action_arg >= CA_ARG_DIRECTION_LEFT &&
7754 action_arg <= CA_ARG_DIRECTION_DOWN ? action_arg - CA_ARG_DIRECTION :
7755 action_arg == CA_ARG_DIRECTION_TRIGGER ?
7756 change->actual_trigger_side :
7757 action_arg == CA_ARG_DIRECTION_TRIGGER_BACK ?
7758 MV_DIR_OPPOSITE(change->actual_trigger_side) :
7761 int action_arg_number_min =
7762 (action_type == CA_SET_PLAYER_SPEED ? STEPSIZE_NOT_MOVING :
7765 int action_arg_number_max =
7766 (action_type == CA_SET_PLAYER_SPEED ? STEPSIZE_EVEN_FASTER :
7767 action_type == CA_SET_LEVEL_GEMS ? 999 :
7768 action_type == CA_SET_LEVEL_TIME ? 9999 :
7769 action_type == CA_SET_LEVEL_SCORE ? 99999 :
7770 action_type == CA_SET_CE_VALUE ? 9999 :
7771 action_type == CA_SET_CE_SCORE ? 9999 :
7774 int action_arg_number_reset =
7775 (action_type == CA_SET_PLAYER_SPEED ? level.initial_player_stepsize[0] :
7776 action_type == CA_SET_LEVEL_GEMS ? level.gems_needed :
7777 action_type == CA_SET_LEVEL_TIME ? level.time :
7778 action_type == CA_SET_LEVEL_SCORE ? 0 :
7779 #if USE_NEW_CUSTOM_VALUE
7780 action_type == CA_SET_CE_VALUE ? GET_NEW_CE_VALUE(element) :
7782 action_type == CA_SET_CE_VALUE ? ei->custom_value_initial :
7784 action_type == CA_SET_CE_SCORE ? 0 :
7787 int action_arg_number =
7788 (action_arg <= CA_ARG_MAX ? action_arg :
7789 action_arg >= CA_ARG_SPEED_NOT_MOVING &&
7790 action_arg <= CA_ARG_SPEED_EVEN_FASTER ? (action_arg - CA_ARG_SPEED) :
7791 action_arg == CA_ARG_SPEED_RESET ? action_arg_number_reset :
7792 action_arg == CA_ARG_NUMBER_MIN ? action_arg_number_min :
7793 action_arg == CA_ARG_NUMBER_MAX ? action_arg_number_max :
7794 action_arg == CA_ARG_NUMBER_RESET ? action_arg_number_reset :
7795 #if USE_NEW_CUSTOM_VALUE
7796 action_arg == CA_ARG_NUMBER_CE_VALUE ? CustomValue[x][y] :
7798 action_arg == CA_ARG_NUMBER_CE_VALUE ? ei->custom_value_initial :
7800 action_arg == CA_ARG_NUMBER_CE_SCORE ? ei->collect_score :
7801 action_arg == CA_ARG_NUMBER_CE_DELAY ? GET_CE_DELAY_VALUE(change) :
7802 action_arg == CA_ARG_NUMBER_LEVEL_TIME ? level_time_value :
7803 action_arg == CA_ARG_NUMBER_LEVEL_GEMS ? local_player->gems_still_needed :
7804 action_arg == CA_ARG_NUMBER_LEVEL_SCORE ? local_player->score :
7805 action_arg == CA_ARG_ELEMENT_CV_TARGET ? GET_NEW_CE_VALUE(target_element):
7806 action_arg == CA_ARG_ELEMENT_CV_TRIGGER ? change->actual_trigger_ce_value:
7807 action_arg == CA_ARG_ELEMENT_CS_TARGET ? GET_CE_SCORE(target_element) :
7808 action_arg == CA_ARG_ELEMENT_CS_TRIGGER ? change->actual_trigger_ce_score:
7809 action_arg == CA_ARG_ELEMENT_NR_TARGET ? change->target_element :
7810 action_arg == CA_ARG_ELEMENT_NR_TRIGGER ? change->actual_trigger_element :
7813 int action_arg_number_old =
7814 (action_type == CA_SET_LEVEL_GEMS ? local_player->gems_still_needed :
7815 action_type == CA_SET_LEVEL_TIME ? TimeLeft :
7816 action_type == CA_SET_LEVEL_SCORE ? local_player->score :
7817 action_type == CA_SET_CE_VALUE ? CustomValue[x][y] :
7818 action_type == CA_SET_CE_SCORE ? ei->collect_score :
7821 int action_arg_number_new =
7822 getModifiedActionNumber(action_arg_number_old,
7823 action_mode, action_arg_number,
7824 action_arg_number_min, action_arg_number_max);
7826 int trigger_player_bits =
7827 (change->actual_trigger_player >= EL_PLAYER_1 &&
7828 change->actual_trigger_player <= EL_PLAYER_4 ?
7829 (1 << (change->actual_trigger_player - EL_PLAYER_1)) :
7832 int action_arg_player_bits =
7833 (action_arg >= CA_ARG_PLAYER_1 &&
7834 action_arg <= CA_ARG_PLAYER_4 ? action_arg - CA_ARG_PLAYER :
7835 action_arg == CA_ARG_PLAYER_TRIGGER ? trigger_player_bits :
7838 /* ---------- execute action -------------------------------------------- */
7840 switch (action_type)
7847 /* ---------- level actions ------------------------------------------- */
7849 case CA_RESTART_LEVEL:
7851 game.restart_level = TRUE;
7856 case CA_SHOW_ENVELOPE:
7858 int element = getSpecialActionElement(action_arg_element,
7859 action_arg_number, EL_ENVELOPE_1);
7861 if (IS_ENVELOPE(element))
7862 local_player->show_envelope = element;
7867 case CA_SET_LEVEL_TIME:
7869 if (level.time > 0) /* only modify limited time value */
7871 TimeLeft = action_arg_number_new;
7873 DrawGameValue_Time(TimeLeft);
7875 if (!TimeLeft && setup.time_limit)
7876 for (i = 0; i < MAX_PLAYERS; i++)
7877 KillPlayer(&stored_player[i]);
7883 case CA_SET_LEVEL_SCORE:
7885 local_player->score = action_arg_number_new;
7887 DrawGameValue_Score(local_player->score);
7892 case CA_SET_LEVEL_GEMS:
7894 local_player->gems_still_needed = action_arg_number_new;
7896 DrawGameValue_Emeralds(local_player->gems_still_needed);
7901 #if !USE_PLAYER_GRAVITY
7902 case CA_SET_LEVEL_GRAVITY:
7904 game.gravity = (action_arg == CA_ARG_GRAVITY_OFF ? FALSE :
7905 action_arg == CA_ARG_GRAVITY_ON ? TRUE :
7906 action_arg == CA_ARG_GRAVITY_TOGGLE ? !game.gravity :
7912 case CA_SET_LEVEL_WIND:
7914 game.wind_direction = action_arg_direction;
7919 /* ---------- player actions ------------------------------------------ */
7921 case CA_MOVE_PLAYER:
7923 /* automatically move to the next field in specified direction */
7924 for (i = 0; i < MAX_PLAYERS; i++)
7925 if (trigger_player_bits & (1 << i))
7926 stored_player[i].programmed_action = action_arg_direction;
7931 case CA_EXIT_PLAYER:
7933 for (i = 0; i < MAX_PLAYERS; i++)
7934 if (action_arg_player_bits & (1 << i))
7935 PlayerWins(&stored_player[i]);
7940 case CA_KILL_PLAYER:
7942 for (i = 0; i < MAX_PLAYERS; i++)
7943 if (action_arg_player_bits & (1 << i))
7944 KillPlayer(&stored_player[i]);
7949 case CA_SET_PLAYER_KEYS:
7951 int key_state = (action_mode == CA_MODE_ADD ? TRUE : FALSE);
7952 int element = getSpecialActionElement(action_arg_element,
7953 action_arg_number, EL_KEY_1);
7955 if (IS_KEY(element))
7957 for (i = 0; i < MAX_PLAYERS; i++)
7959 if (trigger_player_bits & (1 << i))
7961 stored_player[i].key[KEY_NR(element)] = key_state;
7963 DrawGameDoorValues();
7971 case CA_SET_PLAYER_SPEED:
7973 for (i = 0; i < MAX_PLAYERS; i++)
7975 if (trigger_player_bits & (1 << i))
7977 int move_stepsize = TILEX / stored_player[i].move_delay_value;
7979 if (action_arg == CA_ARG_SPEED_FASTER &&
7980 stored_player[i].cannot_move)
7982 action_arg_number = STEPSIZE_VERY_SLOW;
7984 else if (action_arg == CA_ARG_SPEED_SLOWER ||
7985 action_arg == CA_ARG_SPEED_FASTER)
7987 action_arg_number = 2;
7988 action_mode = (action_arg == CA_ARG_SPEED_SLOWER ? CA_MODE_DIVIDE :
7991 else if (action_arg == CA_ARG_NUMBER_RESET)
7993 action_arg_number = level.initial_player_stepsize[i];
7997 getModifiedActionNumber(move_stepsize,
8000 action_arg_number_min,
8001 action_arg_number_max);
8003 SetPlayerMoveSpeed(&stored_player[i], move_stepsize, FALSE);
8010 case CA_SET_PLAYER_SHIELD:
8012 for (i = 0; i < MAX_PLAYERS; i++)
8014 if (trigger_player_bits & (1 << i))
8016 if (action_arg == CA_ARG_SHIELD_OFF)
8018 stored_player[i].shield_normal_time_left = 0;
8019 stored_player[i].shield_deadly_time_left = 0;
8021 else if (action_arg == CA_ARG_SHIELD_NORMAL)
8023 stored_player[i].shield_normal_time_left = 999999;
8025 else if (action_arg == CA_ARG_SHIELD_DEADLY)
8027 stored_player[i].shield_normal_time_left = 999999;
8028 stored_player[i].shield_deadly_time_left = 999999;
8036 #if USE_PLAYER_GRAVITY
8037 case CA_SET_PLAYER_GRAVITY:
8039 for (i = 0; i < MAX_PLAYERS; i++)
8041 if (trigger_player_bits & (1 << i))
8043 stored_player[i].gravity =
8044 (action_arg == CA_ARG_GRAVITY_OFF ? FALSE :
8045 action_arg == CA_ARG_GRAVITY_ON ? TRUE :
8046 action_arg == CA_ARG_GRAVITY_TOGGLE ? !stored_player[i].gravity :
8047 stored_player[i].gravity);
8055 case CA_SET_PLAYER_ARTWORK:
8057 for (i = 0; i < MAX_PLAYERS; i++)
8059 if (trigger_player_bits & (1 << i))
8061 int artwork_element = action_arg_element;
8063 if (action_arg == CA_ARG_ELEMENT_RESET)
8065 (level.use_artwork_element[i] ? level.artwork_element[i] :
8066 stored_player[i].element_nr);
8068 #if USE_GFX_RESET_PLAYER_ARTWORK
8069 if (stored_player[i].artwork_element != artwork_element)
8070 stored_player[i].Frame = 0;
8073 stored_player[i].artwork_element = artwork_element;
8075 SetPlayerWaiting(&stored_player[i], FALSE);
8077 /* set number of special actions for bored and sleeping animation */
8078 stored_player[i].num_special_action_bored =
8079 get_num_special_action(artwork_element,
8080 ACTION_BORING_1, ACTION_BORING_LAST);
8081 stored_player[i].num_special_action_sleeping =
8082 get_num_special_action(artwork_element,
8083 ACTION_SLEEPING_1, ACTION_SLEEPING_LAST);
8090 /* ---------- CE actions ---------------------------------------------- */
8092 case CA_SET_CE_VALUE:
8094 #if USE_NEW_CUSTOM_VALUE
8095 int last_ce_value = CustomValue[x][y];
8097 CustomValue[x][y] = action_arg_number_new;
8099 if (CustomValue[x][y] != last_ce_value)
8101 CheckElementChange(x, y, element, EL_UNDEFINED, CE_VALUE_CHANGES);
8102 CheckTriggeredElementChange(x, y, element, CE_VALUE_CHANGES_OF_X);
8104 if (CustomValue[x][y] == 0)
8106 CheckElementChange(x, y, element, EL_UNDEFINED, CE_VALUE_GETS_ZERO);
8107 CheckTriggeredElementChange(x, y, element, CE_VALUE_GETS_ZERO_OF_X);
8115 case CA_SET_CE_SCORE:
8117 #if USE_NEW_CUSTOM_VALUE
8118 int last_ce_score = ei->collect_score;
8120 ei->collect_score = action_arg_number_new;
8122 if (ei->collect_score != last_ce_score)
8124 CheckElementChange(x, y, element, EL_UNDEFINED, CE_SCORE_CHANGES);
8125 CheckTriggeredElementChange(x, y, element, CE_SCORE_CHANGES_OF_X);
8127 if (ei->collect_score == 0)
8131 CheckElementChange(x, y, element, EL_UNDEFINED, CE_SCORE_GETS_ZERO);
8132 CheckTriggeredElementChange(x, y, element, CE_SCORE_GETS_ZERO_OF_X);
8135 This is a very special case that seems to be a mixture between
8136 CheckElementChange() and CheckTriggeredElementChange(): while
8137 the first one only affects single elements that are triggered
8138 directly, the second one affects multiple elements in the playfield
8139 that are triggered indirectly by another element. This is a third
8140 case: Changing the CE score always affects multiple identical CEs,
8141 so every affected CE must be checked, not only the single CE for
8142 which the CE score was changed in the first place (as every instance
8143 of that CE shares the same CE score, and therefore also can change)!
8145 SCAN_PLAYFIELD(xx, yy)
8147 if (Feld[xx][yy] == element)
8148 CheckElementChange(xx, yy, element, EL_UNDEFINED,
8149 CE_SCORE_GETS_ZERO);
8158 /* ---------- engine actions ------------------------------------------ */
8160 case CA_SET_ENGINE_SCAN_MODE:
8162 InitPlayfieldScanMode(action_arg);
8172 static void CreateFieldExt(int x, int y, int element, boolean is_change)
8174 int old_element = Feld[x][y];
8175 int new_element = get_element_from_group_element(element);
8176 int previous_move_direction = MovDir[x][y];
8177 #if USE_NEW_CUSTOM_VALUE
8178 int last_ce_value = CustomValue[x][y];
8180 boolean player_explosion_protected = PLAYER_EXPLOSION_PROTECTED(x, y);
8181 boolean new_element_is_player = ELEM_IS_PLAYER(new_element);
8182 boolean add_player_onto_element = (new_element_is_player &&
8183 #if USE_CODE_THAT_BREAKS_SNAKE_BITE
8184 /* this breaks SnakeBite when a snake is
8185 halfway through a door that closes */
8186 /* NOW FIXED AT LEVEL INIT IN files.c */
8187 new_element != EL_SOKOBAN_FIELD_PLAYER &&
8189 IS_WALKABLE(old_element));
8192 /* check if element under the player changes from accessible to unaccessible
8193 (needed for special case of dropping element which then changes) */
8194 if (IS_PLAYER(x, y) && !PLAYER_EXPLOSION_PROTECTED(x, y) &&
8195 IS_ACCESSIBLE(old_element) && !IS_ACCESSIBLE(new_element))
8203 if (!add_player_onto_element)
8205 if (IS_MOVING(x, y) || IS_BLOCKED(x, y))
8206 RemoveMovingField(x, y);
8210 Feld[x][y] = new_element;
8212 #if !USE_GFX_RESET_GFX_ANIMATION
8213 ResetGfxAnimation(x, y);
8214 ResetRandomAnimationValue(x, y);
8217 if (element_info[new_element].move_direction_initial == MV_START_PREVIOUS)
8218 MovDir[x][y] = previous_move_direction;
8220 #if USE_NEW_CUSTOM_VALUE
8221 if (element_info[new_element].use_last_ce_value)
8222 CustomValue[x][y] = last_ce_value;
8225 InitField_WithBug1(x, y, FALSE);
8227 new_element = Feld[x][y]; /* element may have changed */
8229 #if USE_GFX_RESET_GFX_ANIMATION
8230 ResetGfxAnimation(x, y);
8231 ResetRandomAnimationValue(x, y);
8234 DrawLevelField(x, y);
8236 if (GFX_CRUMBLED(new_element))
8237 DrawLevelFieldCrumbledSandNeighbours(x, y);
8241 /* check if element under the player changes from accessible to unaccessible
8242 (needed for special case of dropping element which then changes) */
8243 /* (must be checked after creating new element for walkable group elements) */
8244 #if USE_FIX_KILLED_BY_NON_WALKABLE
8245 if (IS_PLAYER(x, y) && !player_explosion_protected &&
8246 IS_ACCESSIBLE(old_element) && !IS_ACCESSIBLE(new_element))
8253 if (IS_PLAYER(x, y) && !PLAYER_EXPLOSION_PROTECTED(x, y) &&
8254 IS_ACCESSIBLE(old_element) && !IS_ACCESSIBLE(new_element))
8263 /* "ChangeCount" not set yet to allow "entered by player" change one time */
8264 if (new_element_is_player)
8265 RelocatePlayer(x, y, new_element);
8268 ChangeCount[x][y]++; /* count number of changes in the same frame */
8270 TestIfBadThingTouchesPlayer(x, y);
8271 TestIfPlayerTouchesCustomElement(x, y);
8272 TestIfElementTouchesCustomElement(x, y);
8275 static void CreateField(int x, int y, int element)
8277 CreateFieldExt(x, y, element, FALSE);
8280 static void CreateElementFromChange(int x, int y, int element)
8282 element = GET_VALID_RUNTIME_ELEMENT(element);
8284 #if USE_STOP_CHANGED_ELEMENTS
8285 if (game.engine_version >= VERSION_IDENT(3,2,0,7))
8287 int old_element = Feld[x][y];
8289 /* prevent changed element from moving in same engine frame
8290 unless both old and new element can either fall or move */
8291 if ((!CAN_FALL(old_element) || !CAN_FALL(element)) &&
8292 (!CAN_MOVE(old_element) || !CAN_MOVE(element)))
8297 CreateFieldExt(x, y, element, TRUE);
8300 static boolean ChangeElement(int x, int y, int element, int page)
8302 struct ElementInfo *ei = &element_info[element];
8303 struct ElementChangeInfo *change = &ei->change_page[page];
8304 int ce_value = CustomValue[x][y];
8305 int ce_score = ei->collect_score;
8307 int old_element = Feld[x][y];
8309 /* always use default change event to prevent running into a loop */
8310 if (ChangeEvent[x][y] == -1)
8311 ChangeEvent[x][y] = CE_DELAY;
8313 if (ChangeEvent[x][y] == CE_DELAY)
8315 /* reset actual trigger element, trigger player and action element */
8316 change->actual_trigger_element = EL_EMPTY;
8317 change->actual_trigger_player = EL_PLAYER_1;
8318 change->actual_trigger_side = CH_SIDE_NONE;
8319 change->actual_trigger_ce_value = 0;
8320 change->actual_trigger_ce_score = 0;
8323 /* do not change elements more than a specified maximum number of changes */
8324 if (ChangeCount[x][y] >= game.max_num_changes_per_frame)
8327 ChangeCount[x][y]++; /* count number of changes in the same frame */
8329 if (change->explode)
8336 if (change->use_target_content)
8338 boolean complete_replace = TRUE;
8339 boolean can_replace[3][3];
8342 for (yy = 0; yy < 3; yy++) for (xx = 0; xx < 3 ; xx++)
8345 boolean is_walkable;
8346 boolean is_diggable;
8347 boolean is_collectible;
8348 boolean is_removable;
8349 boolean is_destructible;
8350 int ex = x + xx - 1;
8351 int ey = y + yy - 1;
8352 int content_element = change->target_content.e[xx][yy];
8355 can_replace[xx][yy] = TRUE;
8357 if (ex == x && ey == y) /* do not check changing element itself */
8360 if (content_element == EL_EMPTY_SPACE)
8362 can_replace[xx][yy] = FALSE; /* do not replace border with space */
8367 if (!IN_LEV_FIELD(ex, ey))
8369 can_replace[xx][yy] = FALSE;
8370 complete_replace = FALSE;
8377 if (IS_MOVING(ex, ey) || IS_BLOCKED(ex, ey))
8378 e = MovingOrBlocked2Element(ex, ey);
8380 is_empty = (IS_FREE(ex, ey) ||
8381 (IS_FREE_OR_PLAYER(ex, ey) && IS_WALKABLE(content_element)));
8383 is_walkable = (is_empty || IS_WALKABLE(e));
8384 is_diggable = (is_empty || IS_DIGGABLE(e));
8385 is_collectible = (is_empty || IS_COLLECTIBLE(e));
8386 is_destructible = (is_empty || !IS_INDESTRUCTIBLE(e));
8387 is_removable = (is_diggable || is_collectible);
8389 can_replace[xx][yy] =
8390 (((change->replace_when == CP_WHEN_EMPTY && is_empty) ||
8391 (change->replace_when == CP_WHEN_WALKABLE && is_walkable) ||
8392 (change->replace_when == CP_WHEN_DIGGABLE && is_diggable) ||
8393 (change->replace_when == CP_WHEN_COLLECTIBLE && is_collectible) ||
8394 (change->replace_when == CP_WHEN_REMOVABLE && is_removable) ||
8395 (change->replace_when == CP_WHEN_DESTRUCTIBLE && is_destructible)) &&
8396 !(IS_PLAYER(ex, ey) && ELEM_IS_PLAYER(content_element)));
8398 if (!can_replace[xx][yy])
8399 complete_replace = FALSE;
8402 if (!change->only_if_complete || complete_replace)
8404 boolean something_has_changed = FALSE;
8406 if (change->only_if_complete && change->use_random_replace &&
8407 RND(100) < change->random_percentage)
8410 for (yy = 0; yy < 3; yy++) for (xx = 0; xx < 3 ; xx++)
8412 int ex = x + xx - 1;
8413 int ey = y + yy - 1;
8414 int content_element;
8416 if (can_replace[xx][yy] && (!change->use_random_replace ||
8417 RND(100) < change->random_percentage))
8419 if (IS_MOVING(ex, ey) || IS_BLOCKED(ex, ey))
8420 RemoveMovingField(ex, ey);
8422 ChangeEvent[ex][ey] = ChangeEvent[x][y];
8424 content_element = change->target_content.e[xx][yy];
8425 target_element = GET_TARGET_ELEMENT(element, content_element, change,
8426 ce_value, ce_score);
8428 CreateElementFromChange(ex, ey, target_element);
8430 something_has_changed = TRUE;
8432 /* for symmetry reasons, freeze newly created border elements */
8433 if (ex != x || ey != y)
8434 Stop[ex][ey] = TRUE; /* no more moving in this frame */
8438 if (something_has_changed)
8440 PlayLevelSoundElementAction(x, y, element, ACTION_CHANGING);
8441 PlayLevelSoundElementAction(x, y, element, ACTION_PAGE_1 + page);
8447 target_element = GET_TARGET_ELEMENT(element, change->target_element, change,
8448 ce_value, ce_score);
8450 if (element == EL_DIAGONAL_GROWING ||
8451 element == EL_DIAGONAL_SHRINKING)
8453 target_element = Store[x][y];
8455 Store[x][y] = EL_EMPTY;
8458 CreateElementFromChange(x, y, target_element);
8460 PlayLevelSoundElementAction(x, y, element, ACTION_CHANGING);
8461 PlayLevelSoundElementAction(x, y, element, ACTION_PAGE_1 + page);
8464 /* this uses direct change before indirect change */
8465 CheckTriggeredElementChangeByPage(x, y, old_element, CE_CHANGE_OF_X, page);
8470 #if USE_NEW_DELAYED_ACTION
8472 static void HandleElementChange(int x, int y, int page)
8474 int element = MovingOrBlocked2Element(x, y);
8475 struct ElementInfo *ei = &element_info[element];
8476 struct ElementChangeInfo *change = &ei->change_page[page];
8479 if (!CAN_CHANGE_OR_HAS_ACTION(element) &&
8480 !CAN_CHANGE_OR_HAS_ACTION(Back[x][y]))
8483 printf("HandleElementChange(): %d,%d: element = %d ('%s')\n",
8484 x, y, element, element_info[element].token_name);
8485 printf("HandleElementChange(): This should never happen!\n");
8490 /* this can happen with classic bombs on walkable, changing elements */
8491 if (!CAN_CHANGE_OR_HAS_ACTION(element))
8494 if (!CAN_CHANGE(Back[x][y])) /* prevent permanent repetition */
8495 ChangeDelay[x][y] = 0;
8501 if (ChangeDelay[x][y] == 0) /* initialize element change */
8503 ChangeDelay[x][y] = GET_CHANGE_DELAY(change) + 1;
8505 if (change->can_change)
8507 ResetGfxAnimation(x, y);
8508 ResetRandomAnimationValue(x, y);
8510 if (change->pre_change_function)
8511 change->pre_change_function(x, y);
8515 ChangeDelay[x][y]--;
8517 if (ChangeDelay[x][y] != 0) /* continue element change */
8519 if (change->can_change)
8521 int graphic = el_act_dir2img(element, GfxAction[x][y], GfxDir[x][y]);
8523 if (IS_ANIMATED(graphic))
8524 DrawLevelGraphicAnimationIfNeeded(x, y, graphic);
8526 if (change->change_function)
8527 change->change_function(x, y);
8530 else /* finish element change */
8532 if (ChangePage[x][y] != -1) /* remember page from delayed change */
8534 page = ChangePage[x][y];
8535 ChangePage[x][y] = -1;
8537 change = &ei->change_page[page];
8540 if (IS_MOVING(x, y)) /* never change a running system ;-) */
8542 ChangeDelay[x][y] = 1; /* try change after next move step */
8543 ChangePage[x][y] = page; /* remember page to use for change */
8548 if (change->can_change)
8550 if (ChangeElement(x, y, element, page))
8552 if (change->post_change_function)
8553 change->post_change_function(x, y);
8557 if (change->has_action)
8558 ExecuteCustomElementAction(x, y, element, page);
8564 static void HandleElementChange(int x, int y, int page)
8566 int element = MovingOrBlocked2Element(x, y);
8567 struct ElementInfo *ei = &element_info[element];
8568 struct ElementChangeInfo *change = &ei->change_page[page];
8571 if (!CAN_CHANGE(element) && !CAN_CHANGE(Back[x][y]))
8574 printf("HandleElementChange(): %d,%d: element = %d ('%s')\n",
8575 x, y, element, element_info[element].token_name);
8576 printf("HandleElementChange(): This should never happen!\n");
8581 /* this can happen with classic bombs on walkable, changing elements */
8582 if (!CAN_CHANGE(element))
8585 if (!CAN_CHANGE(Back[x][y])) /* prevent permanent repetition */
8586 ChangeDelay[x][y] = 0;
8592 if (ChangeDelay[x][y] == 0) /* initialize element change */
8594 ChangeDelay[x][y] = GET_CHANGE_DELAY(change) + 1;
8596 ResetGfxAnimation(x, y);
8597 ResetRandomAnimationValue(x, y);
8599 if (change->pre_change_function)
8600 change->pre_change_function(x, y);
8603 ChangeDelay[x][y]--;
8605 if (ChangeDelay[x][y] != 0) /* continue element change */
8607 int graphic = el_act_dir2img(element, GfxAction[x][y], GfxDir[x][y]);
8609 if (IS_ANIMATED(graphic))
8610 DrawLevelGraphicAnimationIfNeeded(x, y, graphic);
8612 if (change->change_function)
8613 change->change_function(x, y);
8615 else /* finish element change */
8617 if (ChangePage[x][y] != -1) /* remember page from delayed change */
8619 page = ChangePage[x][y];
8620 ChangePage[x][y] = -1;
8622 change = &ei->change_page[page];
8625 if (IS_MOVING(x, y)) /* never change a running system ;-) */
8627 ChangeDelay[x][y] = 1; /* try change after next move step */
8628 ChangePage[x][y] = page; /* remember page to use for change */
8633 if (ChangeElement(x, y, element, page))
8635 if (change->post_change_function)
8636 change->post_change_function(x, y);
8643 static boolean CheckTriggeredElementChangeExt(int trigger_x, int trigger_y,
8644 int trigger_element,
8650 boolean change_done_any = FALSE;
8651 int trigger_page_bits = (trigger_page < 0 ? CH_PAGE_ANY : 1 << trigger_page);
8654 if (!(trigger_events[trigger_element][trigger_event]))
8658 printf("::: CheckTriggeredElementChangeExt %d ... [%d, %d, %d, '%s']\n",
8659 trigger_event, recursion_loop_depth, recursion_loop_detected,
8660 recursion_loop_element, EL_NAME(recursion_loop_element));
8663 RECURSION_LOOP_DETECTION_START(trigger_element, FALSE);
8665 for (i = 0; i < NUM_CUSTOM_ELEMENTS; i++)
8667 int element = EL_CUSTOM_START + i;
8668 boolean change_done = FALSE;
8671 if (!CAN_CHANGE_OR_HAS_ACTION(element) ||
8672 !HAS_ANY_CHANGE_EVENT(element, trigger_event))
8675 for (p = 0; p < element_info[element].num_change_pages; p++)
8677 struct ElementChangeInfo *change = &element_info[element].change_page[p];
8679 if (change->can_change_or_has_action &&
8680 change->has_event[trigger_event] &&
8681 change->trigger_side & trigger_side &&
8682 change->trigger_player & trigger_player &&
8683 change->trigger_page & trigger_page_bits &&
8684 IS_EQUAL_OR_IN_GROUP(trigger_element, change->trigger_element))
8686 change->actual_trigger_element = trigger_element;
8687 change->actual_trigger_player = EL_PLAYER_1 + log_2(trigger_player);
8688 change->actual_trigger_side = trigger_side;
8689 change->actual_trigger_ce_value = CustomValue[trigger_x][trigger_y];
8690 change->actual_trigger_ce_score = GET_CE_SCORE(trigger_element);
8692 if ((change->can_change && !change_done) || change->has_action)
8696 SCAN_PLAYFIELD(x, y)
8698 if (Feld[x][y] == element)
8700 if (change->can_change && !change_done)
8702 ChangeDelay[x][y] = 1;
8703 ChangeEvent[x][y] = trigger_event;
8705 HandleElementChange(x, y, p);
8707 #if USE_NEW_DELAYED_ACTION
8708 else if (change->has_action)
8710 ExecuteCustomElementAction(x, y, element, p);
8711 PlayLevelSoundElementAction(x, y, element, ACTION_PAGE_1 + p);
8714 if (change->has_action)
8716 ExecuteCustomElementAction(x, y, element, p);
8717 PlayLevelSoundElementAction(x, y, element, ACTION_PAGE_1 + p);
8723 if (change->can_change)
8726 change_done_any = TRUE;
8733 RECURSION_LOOP_DETECTION_END();
8735 return change_done_any;
8738 static boolean CheckElementChangeExt(int x, int y,
8740 int trigger_element,
8745 boolean change_done = FALSE;
8748 if (!CAN_CHANGE_OR_HAS_ACTION(element) ||
8749 !HAS_ANY_CHANGE_EVENT(element, trigger_event))
8752 if (Feld[x][y] == EL_BLOCKED)
8754 Blocked2Moving(x, y, &x, &y);
8755 element = Feld[x][y];
8759 /* check if element has already changed */
8760 if (Feld[x][y] != element)
8763 /* check if element has already changed or is about to change after moving */
8764 if ((game.engine_version < VERSION_IDENT(3,2,0,7) &&
8765 Feld[x][y] != element) ||
8767 (game.engine_version >= VERSION_IDENT(3,2,0,7) &&
8768 (ChangeCount[x][y] >= game.max_num_changes_per_frame ||
8769 ChangePage[x][y] != -1)))
8774 printf("::: CheckElementChangeExt %d ... [%d, %d, %d, '%s']\n",
8775 trigger_event, recursion_loop_depth, recursion_loop_detected,
8776 recursion_loop_element, EL_NAME(recursion_loop_element));
8779 RECURSION_LOOP_DETECTION_START(trigger_element, FALSE);
8781 for (p = 0; p < element_info[element].num_change_pages; p++)
8783 struct ElementChangeInfo *change = &element_info[element].change_page[p];
8785 /* check trigger element for all events where the element that is checked
8786 for changing interacts with a directly adjacent element -- this is
8787 different to element changes that affect other elements to change on the
8788 whole playfield (which is handeld by CheckTriggeredElementChangeExt()) */
8789 boolean check_trigger_element =
8790 (trigger_event == CE_TOUCHING_X ||
8791 trigger_event == CE_HITTING_X ||
8792 trigger_event == CE_HIT_BY_X ||
8794 /* this one was forgotten until 3.2.3 */
8795 trigger_event == CE_DIGGING_X);
8798 if (change->can_change_or_has_action &&
8799 change->has_event[trigger_event] &&
8800 change->trigger_side & trigger_side &&
8801 change->trigger_player & trigger_player &&
8802 (!check_trigger_element ||
8803 IS_EQUAL_OR_IN_GROUP(trigger_element, change->trigger_element)))
8805 change->actual_trigger_element = trigger_element;
8806 change->actual_trigger_player = EL_PLAYER_1 + log_2(trigger_player);
8807 change->actual_trigger_side = trigger_side;
8808 change->actual_trigger_ce_value = CustomValue[x][y];
8809 change->actual_trigger_ce_score = GET_CE_SCORE(trigger_element);
8811 /* special case: trigger element not at (x,y) position for some events */
8812 if (check_trigger_element)
8824 { 0, 0 }, { 0, 0 }, { 0, 0 },
8828 int xx = x + move_xy[MV_DIR_OPPOSITE(trigger_side)].dx;
8829 int yy = y + move_xy[MV_DIR_OPPOSITE(trigger_side)].dy;
8831 change->actual_trigger_ce_value = CustomValue[xx][yy];
8832 change->actual_trigger_ce_score = GET_CE_SCORE(trigger_element);
8835 if (change->can_change && !change_done)
8837 ChangeDelay[x][y] = 1;
8838 ChangeEvent[x][y] = trigger_event;
8840 HandleElementChange(x, y, p);
8844 #if USE_NEW_DELAYED_ACTION
8845 else if (change->has_action)
8847 ExecuteCustomElementAction(x, y, element, p);
8848 PlayLevelSoundElementAction(x, y, element, ACTION_PAGE_1 + p);
8851 if (change->has_action)
8853 ExecuteCustomElementAction(x, y, element, p);
8854 PlayLevelSoundElementAction(x, y, element, ACTION_PAGE_1 + p);
8860 RECURSION_LOOP_DETECTION_END();
8865 static void PlayPlayerSound(struct PlayerInfo *player)
8867 int jx = player->jx, jy = player->jy;
8868 int sound_element = player->artwork_element;
8869 int last_action = player->last_action_waiting;
8870 int action = player->action_waiting;
8872 if (player->is_waiting)
8874 if (action != last_action)
8875 PlayLevelSoundElementAction(jx, jy, sound_element, action);
8877 PlayLevelSoundElementActionIfLoop(jx, jy, sound_element, action);
8881 if (action != last_action)
8882 StopSound(element_info[sound_element].sound[last_action]);
8884 if (last_action == ACTION_SLEEPING)
8885 PlayLevelSoundElementAction(jx, jy, sound_element, ACTION_AWAKENING);
8889 static void PlayAllPlayersSound()
8893 for (i = 0; i < MAX_PLAYERS; i++)
8894 if (stored_player[i].active)
8895 PlayPlayerSound(&stored_player[i]);
8898 static void SetPlayerWaiting(struct PlayerInfo *player, boolean is_waiting)
8900 boolean last_waiting = player->is_waiting;
8901 int move_dir = player->MovDir;
8903 player->dir_waiting = move_dir;
8904 player->last_action_waiting = player->action_waiting;
8908 if (!last_waiting) /* not waiting -> waiting */
8910 player->is_waiting = TRUE;
8912 player->frame_counter_bored =
8914 game.player_boring_delay_fixed +
8915 GetSimpleRandom(game.player_boring_delay_random);
8916 player->frame_counter_sleeping =
8918 game.player_sleeping_delay_fixed +
8919 GetSimpleRandom(game.player_sleeping_delay_random);
8921 InitPlayerGfxAnimation(player, ACTION_WAITING, move_dir);
8924 if (game.player_sleeping_delay_fixed +
8925 game.player_sleeping_delay_random > 0 &&
8926 player->anim_delay_counter == 0 &&
8927 player->post_delay_counter == 0 &&
8928 FrameCounter >= player->frame_counter_sleeping)
8929 player->is_sleeping = TRUE;
8930 else if (game.player_boring_delay_fixed +
8931 game.player_boring_delay_random > 0 &&
8932 FrameCounter >= player->frame_counter_bored)
8933 player->is_bored = TRUE;
8935 player->action_waiting = (player->is_sleeping ? ACTION_SLEEPING :
8936 player->is_bored ? ACTION_BORING :
8939 if (player->is_sleeping && player->use_murphy)
8941 /* special case for sleeping Murphy when leaning against non-free tile */
8943 if (!IN_LEV_FIELD(player->jx - 1, player->jy) ||
8944 (Feld[player->jx - 1][player->jy] != EL_EMPTY &&
8945 !IS_MOVING(player->jx - 1, player->jy)))
8947 else if (!IN_LEV_FIELD(player->jx + 1, player->jy) ||
8948 (Feld[player->jx + 1][player->jy] != EL_EMPTY &&
8949 !IS_MOVING(player->jx + 1, player->jy)))
8950 move_dir = MV_RIGHT;
8952 player->is_sleeping = FALSE;
8954 player->dir_waiting = move_dir;
8957 if (player->is_sleeping)
8959 if (player->num_special_action_sleeping > 0)
8961 if (player->anim_delay_counter == 0 && player->post_delay_counter == 0)
8963 int last_special_action = player->special_action_sleeping;
8964 int num_special_action = player->num_special_action_sleeping;
8965 int special_action =
8966 (last_special_action == ACTION_DEFAULT ? ACTION_SLEEPING_1 :
8967 last_special_action == ACTION_SLEEPING ? ACTION_SLEEPING :
8968 last_special_action < ACTION_SLEEPING_1 + num_special_action - 1 ?
8969 last_special_action + 1 : ACTION_SLEEPING);
8970 int special_graphic =
8971 el_act_dir2img(player->artwork_element, special_action, move_dir);
8973 player->anim_delay_counter =
8974 graphic_info[special_graphic].anim_delay_fixed +
8975 GetSimpleRandom(graphic_info[special_graphic].anim_delay_random);
8976 player->post_delay_counter =
8977 graphic_info[special_graphic].post_delay_fixed +
8978 GetSimpleRandom(graphic_info[special_graphic].post_delay_random);
8980 player->special_action_sleeping = special_action;
8983 if (player->anim_delay_counter > 0)
8985 player->action_waiting = player->special_action_sleeping;
8986 player->anim_delay_counter--;
8988 else if (player->post_delay_counter > 0)
8990 player->post_delay_counter--;
8994 else if (player->is_bored)
8996 if (player->num_special_action_bored > 0)
8998 if (player->anim_delay_counter == 0 && player->post_delay_counter == 0)
9000 int special_action =
9001 ACTION_BORING_1 + GetSimpleRandom(player->num_special_action_bored);
9002 int special_graphic =
9003 el_act_dir2img(player->artwork_element, special_action, move_dir);
9005 player->anim_delay_counter =
9006 graphic_info[special_graphic].anim_delay_fixed +
9007 GetSimpleRandom(graphic_info[special_graphic].anim_delay_random);
9008 player->post_delay_counter =
9009 graphic_info[special_graphic].post_delay_fixed +
9010 GetSimpleRandom(graphic_info[special_graphic].post_delay_random);
9012 player->special_action_bored = special_action;
9015 if (player->anim_delay_counter > 0)
9017 player->action_waiting = player->special_action_bored;
9018 player->anim_delay_counter--;
9020 else if (player->post_delay_counter > 0)
9022 player->post_delay_counter--;
9027 else if (last_waiting) /* waiting -> not waiting */
9029 player->is_waiting = FALSE;
9030 player->is_bored = FALSE;
9031 player->is_sleeping = FALSE;
9033 player->frame_counter_bored = -1;
9034 player->frame_counter_sleeping = -1;
9036 player->anim_delay_counter = 0;
9037 player->post_delay_counter = 0;
9039 player->dir_waiting = player->MovDir;
9040 player->action_waiting = ACTION_DEFAULT;
9042 player->special_action_bored = ACTION_DEFAULT;
9043 player->special_action_sleeping = ACTION_DEFAULT;
9047 static byte PlayerActions(struct PlayerInfo *player, byte player_action)
9049 boolean moved = FALSE, snapped = FALSE, dropped = FALSE;
9050 int left = player_action & JOY_LEFT;
9051 int right = player_action & JOY_RIGHT;
9052 int up = player_action & JOY_UP;
9053 int down = player_action & JOY_DOWN;
9054 int button1 = player_action & JOY_BUTTON_1;
9055 int button2 = player_action & JOY_BUTTON_2;
9056 int dx = (left ? -1 : right ? 1 : 0);
9057 int dy = (up ? -1 : down ? 1 : 0);
9059 if (!player->active || tape.pausing)
9065 snapped = SnapField(player, dx, dy);
9069 dropped = DropElement(player);
9071 moved = MovePlayer(player, dx, dy);
9074 if (tape.single_step && tape.recording && !tape.pausing)
9076 if (button1 || (dropped && !moved))
9078 TapeTogglePause(TAPE_TOGGLE_AUTOMATIC);
9079 SnapField(player, 0, 0); /* stop snapping */
9083 SetPlayerWaiting(player, FALSE);
9085 return player_action;
9089 /* no actions for this player (no input at player's configured device) */
9091 DigField(player, 0, 0, 0, 0, 0, 0, DF_NO_PUSH);
9092 SnapField(player, 0, 0);
9093 CheckGravityMovementWhenNotMoving(player);
9095 if (player->MovPos == 0)
9096 SetPlayerWaiting(player, TRUE);
9098 if (player->MovPos == 0) /* needed for tape.playing */
9099 player->is_moving = FALSE;
9101 player->is_dropping = FALSE;
9102 player->is_dropping_pressed = FALSE;
9103 player->drop_pressed_delay = 0;
9109 static void CheckLevelTime()
9113 if (level.game_engine_type == GAME_ENGINE_TYPE_EM)
9115 if (level.native_em_level->lev->home == 0) /* all players at home */
9117 PlayerWins(local_player);
9119 AllPlayersGone = TRUE;
9121 level.native_em_level->lev->home = -1;
9124 if (level.native_em_level->ply[0]->alive == 0 &&
9125 level.native_em_level->ply[1]->alive == 0 &&
9126 level.native_em_level->ply[2]->alive == 0 &&
9127 level.native_em_level->ply[3]->alive == 0) /* all dead */
9128 AllPlayersGone = TRUE;
9131 if (TimeFrames >= FRAMES_PER_SECOND)
9136 for (i = 0; i < MAX_PLAYERS; i++)
9138 struct PlayerInfo *player = &stored_player[i];
9140 if (SHIELD_ON(player))
9142 player->shield_normal_time_left--;
9144 if (player->shield_deadly_time_left > 0)
9145 player->shield_deadly_time_left--;
9149 if (!local_player->LevelSolved && !level.use_step_counter)
9157 if (TimeLeft <= 10 && setup.time_limit)
9158 PlaySound(SND_GAME_RUNNING_OUT_OF_TIME);
9160 DrawGameValue_Time(TimeLeft);
9162 if (!TimeLeft && setup.time_limit)
9164 if (level.game_engine_type == GAME_ENGINE_TYPE_EM)
9165 level.native_em_level->lev->killed_out_of_time = TRUE;
9167 for (i = 0; i < MAX_PLAYERS; i++)
9168 KillPlayer(&stored_player[i]);
9171 else if (level.time == 0 && !AllPlayersGone) /* level w/o time limit */
9172 DrawGameValue_Time(TimePlayed);
9174 level.native_em_level->lev->time =
9175 (level.time == 0 ? TimePlayed : TimeLeft);
9178 if (tape.recording || tape.playing)
9179 DrawVideoDisplay(VIDEO_STATE_TIME_ON, TapeTime);
9183 void AdvanceFrameAndPlayerCounters(int player_nr)
9187 /* advance frame counters (global frame counter and time frame counter) */
9191 /* advance player counters (counters for move delay, move animation etc.) */
9192 for (i = 0; i < MAX_PLAYERS; i++)
9194 boolean advance_player_counters = (player_nr == -1 || player_nr == i);
9195 int move_delay_value = stored_player[i].move_delay_value;
9196 int move_frames = MOVE_DELAY_NORMAL_SPEED / move_delay_value;
9198 if (!advance_player_counters) /* not all players may be affected */
9201 #if USE_NEW_PLAYER_ANIM
9202 if (move_frames == 0) /* less than one move per game frame */
9204 int stepsize = TILEX / move_delay_value;
9205 int delay = move_delay_value / MOVE_DELAY_NORMAL_SPEED;
9206 int count = (stored_player[i].is_moving ?
9207 ABS(stored_player[i].MovPos) / stepsize : FrameCounter);
9209 if (count % delay == 0)
9214 stored_player[i].Frame += move_frames;
9216 if (stored_player[i].MovPos != 0)
9217 stored_player[i].StepFrame += move_frames;
9219 if (stored_player[i].move_delay > 0)
9220 stored_player[i].move_delay--;
9222 /* due to bugs in previous versions, counter must count up, not down */
9223 if (stored_player[i].push_delay != -1)
9224 stored_player[i].push_delay++;
9226 if (stored_player[i].drop_delay > 0)
9227 stored_player[i].drop_delay--;
9229 if (stored_player[i].is_dropping_pressed)
9230 stored_player[i].drop_pressed_delay++;
9234 void StartGameActions(boolean init_network_game, boolean record_tape,
9237 unsigned long new_random_seed = InitRND(random_seed);
9240 TapeStartRecording(new_random_seed);
9242 #if defined(NETWORK_AVALIABLE)
9243 if (init_network_game)
9245 SendToServer_StartPlaying();
9256 static unsigned long game_frame_delay = 0;
9257 unsigned long game_frame_delay_value;
9258 byte *recorded_player_action;
9259 byte summarized_player_action = 0;
9260 byte tape_action[MAX_PLAYERS];
9263 /* detect endless loops, caused by custom element programming */
9264 if (recursion_loop_detected && recursion_loop_depth == 0)
9266 char *message = getStringCat3("Internal Error ! Element ",
9267 EL_NAME(recursion_loop_element),
9268 " caused endless loop ! Quit the game ?");
9270 Error(ERR_WARN, "element '%s' caused endless loop in game engine",
9271 EL_NAME(recursion_loop_element));
9273 RequestQuitGameExt(FALSE, level_editor_test_game, message);
9275 recursion_loop_detected = FALSE; /* if game should be continued */
9282 if (game.restart_level)
9283 StartGameActions(options.network, setup.autorecord, NEW_RANDOMIZE);
9285 if (level.game_engine_type == GAME_ENGINE_TYPE_EM)
9287 if (level.native_em_level->lev->home == 0) /* all players at home */
9289 PlayerWins(local_player);
9291 AllPlayersGone = TRUE;
9293 level.native_em_level->lev->home = -1;
9296 if (level.native_em_level->ply[0]->alive == 0 &&
9297 level.native_em_level->ply[1]->alive == 0 &&
9298 level.native_em_level->ply[2]->alive == 0 &&
9299 level.native_em_level->ply[3]->alive == 0) /* all dead */
9300 AllPlayersGone = TRUE;
9303 if (local_player->LevelSolved)
9306 if (AllPlayersGone && !TAPE_IS_STOPPED(tape))
9309 if (game_status != GAME_MODE_PLAYING) /* status might have changed */
9312 game_frame_delay_value =
9313 (tape.playing && tape.fast_forward ? FfwdFrameDelay : GameFrameDelay);
9315 if (tape.playing && tape.warp_forward && !tape.pausing)
9316 game_frame_delay_value = 0;
9318 /* ---------- main game synchronization point ---------- */
9320 WaitUntilDelayReached(&game_frame_delay, game_frame_delay_value);
9322 if (network_playing && !network_player_action_received)
9324 /* try to get network player actions in time */
9326 #if defined(NETWORK_AVALIABLE)
9327 /* last chance to get network player actions without main loop delay */
9331 /* game was quit by network peer */
9332 if (game_status != GAME_MODE_PLAYING)
9335 if (!network_player_action_received)
9336 return; /* failed to get network player actions in time */
9338 /* do not yet reset "network_player_action_received" (for tape.pausing) */
9344 /* at this point we know that we really continue executing the game */
9346 network_player_action_received = FALSE;
9348 /* when playing tape, read previously recorded player input from tape data */
9349 recorded_player_action = (tape.playing ? TapePlayAction() : NULL);
9352 /* TapePlayAction() may return NULL when toggling to "pause before death" */
9357 if (tape.set_centered_player)
9359 game.centered_player_nr_next = tape.centered_player_nr_next;
9360 game.set_centered_player = TRUE;
9363 for (i = 0; i < MAX_PLAYERS; i++)
9365 summarized_player_action |= stored_player[i].action;
9367 if (!network_playing)
9368 stored_player[i].effective_action = stored_player[i].action;
9371 #if defined(NETWORK_AVALIABLE)
9372 if (network_playing)
9373 SendToServer_MovePlayer(summarized_player_action);
9376 if (!options.network && !setup.team_mode)
9377 local_player->effective_action = summarized_player_action;
9379 if (setup.team_mode && setup.input_on_focus && game.centered_player_nr != -1)
9381 for (i = 0; i < MAX_PLAYERS; i++)
9382 stored_player[i].effective_action =
9383 (i == game.centered_player_nr ? summarized_player_action : 0);
9386 if (recorded_player_action != NULL)
9387 for (i = 0; i < MAX_PLAYERS; i++)
9388 stored_player[i].effective_action = recorded_player_action[i];
9390 for (i = 0; i < MAX_PLAYERS; i++)
9392 tape_action[i] = stored_player[i].effective_action;
9394 /* (this can only happen in the R'n'D game engine) */
9395 if (tape.recording && tape_action[i] && !tape.player_participates[i])
9396 tape.player_participates[i] = TRUE; /* player just appeared from CE */
9399 /* only record actions from input devices, but not programmed actions */
9401 TapeRecordAction(tape_action);
9403 if (level.game_engine_type == GAME_ENGINE_TYPE_EM)
9405 GameActions_EM_Main();
9413 void GameActions_EM_Main()
9415 byte effective_action[MAX_PLAYERS];
9416 boolean warp_mode = (tape.playing && tape.warp_forward && !tape.pausing);
9419 for (i = 0; i < MAX_PLAYERS; i++)
9420 effective_action[i] = stored_player[i].effective_action;
9422 GameActions_EM(effective_action, warp_mode);
9426 AdvanceFrameAndPlayerCounters(-1); /* advance counters for all players */
9429 void GameActions_RND()
9431 int magic_wall_x = 0, magic_wall_y = 0;
9432 int i, x, y, element, graphic;
9434 InitPlayfieldScanModeVars();
9436 #if USE_ONE_MORE_CHANGE_PER_FRAME
9437 if (game.engine_version >= VERSION_IDENT(3,2,0,7))
9439 SCAN_PLAYFIELD(x, y)
9441 ChangeCount[x][y] = 0;
9442 ChangeEvent[x][y] = -1;
9447 if (game.set_centered_player)
9449 boolean all_players_fit_to_screen = checkIfAllPlayersFitToScreen_RND();
9451 /* switching to "all players" only possible if all players fit to screen */
9452 if (game.centered_player_nr_next == -1 && !all_players_fit_to_screen)
9454 game.centered_player_nr_next = game.centered_player_nr;
9455 game.set_centered_player = FALSE;
9458 /* do not switch focus to non-existing (or non-active) player */
9459 if (game.centered_player_nr_next >= 0 &&
9460 !stored_player[game.centered_player_nr_next].active)
9462 game.centered_player_nr_next = game.centered_player_nr;
9463 game.set_centered_player = FALSE;
9467 if (game.set_centered_player &&
9468 ScreenMovPos == 0) /* screen currently aligned at tile position */
9472 if (game.centered_player_nr_next == -1)
9474 setScreenCenteredToAllPlayers(&sx, &sy);
9478 sx = stored_player[game.centered_player_nr_next].jx;
9479 sy = stored_player[game.centered_player_nr_next].jy;
9482 game.centered_player_nr = game.centered_player_nr_next;
9483 game.set_centered_player = FALSE;
9485 DrawRelocateScreen(0, 0, sx, sy, MV_NONE, TRUE, setup.quick_switch);
9486 DrawGameDoorValues();
9489 for (i = 0; i < MAX_PLAYERS; i++)
9491 int actual_player_action = stored_player[i].effective_action;
9494 /* !!! THIS BREAKS THE FOLLOWING TAPES: !!!
9495 - rnd_equinox_tetrachloride 048
9496 - rnd_equinox_tetrachloride_ii 096
9497 - rnd_emanuel_schmieg 002
9498 - doctor_sloan_ww 001, 020
9500 if (stored_player[i].MovPos == 0)
9501 CheckGravityMovement(&stored_player[i]);
9504 /* overwrite programmed action with tape action */
9505 if (stored_player[i].programmed_action)
9506 actual_player_action = stored_player[i].programmed_action;
9508 PlayerActions(&stored_player[i], actual_player_action);
9510 ScrollPlayer(&stored_player[i], SCROLL_GO_ON);
9513 ScrollScreen(NULL, SCROLL_GO_ON);
9515 /* for backwards compatibility, the following code emulates a fixed bug that
9516 occured when pushing elements (causing elements that just made their last
9517 pushing step to already (if possible) make their first falling step in the
9518 same game frame, which is bad); this code is also needed to use the famous
9519 "spring push bug" which is used in older levels and might be wanted to be
9520 used also in newer levels, but in this case the buggy pushing code is only
9521 affecting the "spring" element and no other elements */
9523 if (game.engine_version < VERSION_IDENT(2,2,0,7) || level.use_spring_bug)
9525 for (i = 0; i < MAX_PLAYERS; i++)
9527 struct PlayerInfo *player = &stored_player[i];
9531 if (player->active && player->is_pushing && player->is_moving &&
9533 (game.engine_version < VERSION_IDENT(2,2,0,7) ||
9534 Feld[x][y] == EL_SPRING))
9536 ContinueMoving(x, y);
9538 /* continue moving after pushing (this is actually a bug) */
9539 if (!IS_MOVING(x, y))
9547 SCAN_PLAYFIELD(x, y)
9549 ChangeCount[x][y] = 0;
9550 ChangeEvent[x][y] = -1;
9552 /* this must be handled before main playfield loop */
9553 if (Feld[x][y] == EL_PLAYER_IS_LEAVING)
9556 if (MovDelay[x][y] <= 0)
9560 #if USE_NEW_SNAP_DELAY
9561 if (Feld[x][y] == EL_ELEMENT_SNAPPING)
9564 if (MovDelay[x][y] <= 0)
9567 DrawLevelField(x, y);
9569 TestIfElementTouchesCustomElement(x, y); /* for empty space */
9575 if (ChangePage[x][y] != -1 && ChangeDelay[x][y] != 1)
9577 printf("GameActions(): x = %d, y = %d: ChangePage != -1\n", x, y);
9578 printf("GameActions(): This should never happen!\n");
9580 ChangePage[x][y] = -1;
9585 if (WasJustMoving[x][y] > 0)
9586 WasJustMoving[x][y]--;
9587 if (WasJustFalling[x][y] > 0)
9588 WasJustFalling[x][y]--;
9589 if (CheckCollision[x][y] > 0)
9590 CheckCollision[x][y]--;
9591 if (CheckImpact[x][y] > 0)
9592 CheckImpact[x][y]--;
9596 /* reset finished pushing action (not done in ContinueMoving() to allow
9597 continuous pushing animation for elements with zero push delay) */
9598 if (GfxAction[x][y] == ACTION_PUSHING && !IS_MOVING(x, y))
9600 ResetGfxAnimation(x, y);
9601 DrawLevelField(x, y);
9605 if (IS_BLOCKED(x, y))
9609 Blocked2Moving(x, y, &oldx, &oldy);
9610 if (!IS_MOVING(oldx, oldy))
9612 printf("GameActions(): (BLOCKED => MOVING) context corrupted!\n");
9613 printf("GameActions(): BLOCKED: x = %d, y = %d\n", x, y);
9614 printf("GameActions(): !MOVING: oldx = %d, oldy = %d\n", oldx, oldy);
9615 printf("GameActions(): This should never happen!\n");
9621 SCAN_PLAYFIELD(x, y)
9623 element = Feld[x][y];
9624 graphic = el_act_dir2img(element, GfxAction[x][y], GfxDir[x][y]);
9626 ResetGfxFrame(x, y, TRUE);
9628 if (ANIM_MODE(graphic) == ANIM_RANDOM &&
9629 IS_NEXT_FRAME(GfxFrame[x][y], graphic))
9630 ResetRandomAnimationValue(x, y);
9632 SetRandomAnimationValue(x, y);
9634 PlayLevelSoundActionIfLoop(x, y, GfxAction[x][y]);
9636 if (IS_INACTIVE(element))
9638 if (IS_ANIMATED(graphic))
9639 DrawLevelGraphicAnimationIfNeeded(x, y, graphic);
9644 /* this may take place after moving, so 'element' may have changed */
9645 if (IS_CHANGING(x, y) &&
9646 (game.engine_version < VERSION_IDENT(3,0,7,1) || !Stop[x][y]))
9648 int page = element_info[element].event_page_nr[CE_DELAY];
9651 HandleElementChange(x, y, page);
9653 if (CAN_CHANGE(element))
9654 HandleElementChange(x, y, page);
9656 if (HAS_ACTION(element))
9657 ExecuteCustomElementAction(x, y, element, page);
9660 element = Feld[x][y];
9661 graphic = el_act_dir2img(element, GfxAction[x][y], GfxDir[x][y]);
9664 if (!IS_MOVING(x, y) && (CAN_FALL(element) || CAN_MOVE(element)))
9668 element = Feld[x][y];
9669 graphic = el_act_dir2img(element, GfxAction[x][y], GfxDir[x][y]);
9671 if (IS_ANIMATED(graphic) &&
9674 DrawLevelGraphicAnimationIfNeeded(x, y, graphic);
9676 if (IS_GEM(element) || element == EL_SP_INFOTRON)
9677 DrawTwinkleOnField(x, y);
9679 else if ((element == EL_ACID ||
9680 element == EL_EXIT_OPEN ||
9681 element == EL_SP_EXIT_OPEN ||
9682 element == EL_STEEL_EXIT_OPEN ||
9683 element == EL_SP_TERMINAL ||
9684 element == EL_SP_TERMINAL_ACTIVE ||
9685 element == EL_EXTRA_TIME ||
9686 element == EL_SHIELD_NORMAL ||
9687 element == EL_SHIELD_DEADLY) &&
9688 IS_ANIMATED(graphic))
9689 DrawLevelGraphicAnimationIfNeeded(x, y, graphic);
9690 else if (IS_MOVING(x, y))
9691 ContinueMoving(x, y);
9692 else if (IS_ACTIVE_BOMB(element))
9693 CheckDynamite(x, y);
9694 else if (element == EL_AMOEBA_GROWING)
9695 AmoebeWaechst(x, y);
9696 else if (element == EL_AMOEBA_SHRINKING)
9697 AmoebaDisappearing(x, y);
9699 #if !USE_NEW_AMOEBA_CODE
9700 else if (IS_AMOEBALIVE(element))
9701 AmoebeAbleger(x, y);
9704 else if (element == EL_GAME_OF_LIFE || element == EL_BIOMAZE)
9706 else if (element == EL_EXIT_CLOSED)
9708 else if (element == EL_STEEL_EXIT_CLOSED)
9709 CheckExitSteel(x, y);
9710 else if (element == EL_SP_EXIT_CLOSED)
9712 else if (element == EL_EXPANDABLE_WALL_GROWING)
9714 else if (element == EL_EXPANDABLE_WALL ||
9715 element == EL_EXPANDABLE_WALL_HORIZONTAL ||
9716 element == EL_EXPANDABLE_WALL_VERTICAL ||
9717 element == EL_EXPANDABLE_WALL_ANY ||
9718 element == EL_BD_EXPANDABLE_WALL)
9720 else if (element == EL_FLAMES)
9721 CheckForDragon(x, y);
9722 else if (element == EL_EXPLOSION)
9723 ; /* drawing of correct explosion animation is handled separately */
9724 else if (element == EL_ELEMENT_SNAPPING ||
9725 element == EL_DIAGONAL_SHRINKING ||
9726 element == EL_DIAGONAL_GROWING)
9728 graphic = el_act_dir2img(GfxElement[x][y], GfxAction[x][y],GfxDir[x][y]);
9730 DrawLevelGraphicAnimationIfNeeded(x, y, graphic);
9732 else if (IS_ANIMATED(graphic) && !IS_CHANGING(x, y))
9733 DrawLevelGraphicAnimationIfNeeded(x, y, graphic);
9735 if (IS_BELT_ACTIVE(element))
9736 PlayLevelSoundAction(x, y, ACTION_ACTIVE);
9738 if (game.magic_wall_active)
9740 int jx = local_player->jx, jy = local_player->jy;
9742 /* play the element sound at the position nearest to the player */
9743 if ((element == EL_MAGIC_WALL_FULL ||
9744 element == EL_MAGIC_WALL_ACTIVE ||
9745 element == EL_MAGIC_WALL_EMPTYING ||
9746 element == EL_BD_MAGIC_WALL_FULL ||
9747 element == EL_BD_MAGIC_WALL_ACTIVE ||
9748 element == EL_BD_MAGIC_WALL_EMPTYING) &&
9749 ABS(x-jx) + ABS(y-jy) < ABS(magic_wall_x-jx) + ABS(magic_wall_y-jy))
9757 #if USE_NEW_AMOEBA_CODE
9758 /* new experimental amoeba growth stuff */
9759 if (!(FrameCounter % 8))
9761 static unsigned long random = 1684108901;
9763 for (i = 0; i < level.amoeba_speed * 28 / 8; i++)
9765 x = RND(lev_fieldx);
9766 y = RND(lev_fieldy);
9767 element = Feld[x][y];
9769 if (!IS_PLAYER(x,y) &&
9770 (element == EL_EMPTY ||
9771 CAN_GROW_INTO(element) ||
9772 element == EL_QUICKSAND_EMPTY ||
9773 element == EL_ACID_SPLASH_LEFT ||
9774 element == EL_ACID_SPLASH_RIGHT))
9776 if ((IN_LEV_FIELD(x, y-1) && Feld[x][y-1] == EL_AMOEBA_WET) ||
9777 (IN_LEV_FIELD(x-1, y) && Feld[x-1][y] == EL_AMOEBA_WET) ||
9778 (IN_LEV_FIELD(x+1, y) && Feld[x+1][y] == EL_AMOEBA_WET) ||
9779 (IN_LEV_FIELD(x, y+1) && Feld[x][y+1] == EL_AMOEBA_WET))
9780 Feld[x][y] = EL_AMOEBA_DROP;
9783 random = random * 129 + 1;
9789 if (game.explosions_delayed)
9792 game.explosions_delayed = FALSE;
9794 SCAN_PLAYFIELD(x, y)
9796 element = Feld[x][y];
9798 if (ExplodeField[x][y])
9799 Explode(x, y, EX_PHASE_START, ExplodeField[x][y]);
9800 else if (element == EL_EXPLOSION)
9801 Explode(x, y, ExplodePhase[x][y], EX_TYPE_NORMAL);
9803 ExplodeField[x][y] = EX_TYPE_NONE;
9806 game.explosions_delayed = TRUE;
9809 if (game.magic_wall_active)
9811 if (!(game.magic_wall_time_left % 4))
9813 int element = Feld[magic_wall_x][magic_wall_y];
9815 if (element == EL_BD_MAGIC_WALL_FULL ||
9816 element == EL_BD_MAGIC_WALL_ACTIVE ||
9817 element == EL_BD_MAGIC_WALL_EMPTYING)
9818 PlayLevelSound(magic_wall_x, magic_wall_y, SND_BD_MAGIC_WALL_ACTIVE);
9820 PlayLevelSound(magic_wall_x, magic_wall_y, SND_MAGIC_WALL_ACTIVE);
9823 if (game.magic_wall_time_left > 0)
9825 game.magic_wall_time_left--;
9826 if (!game.magic_wall_time_left)
9828 SCAN_PLAYFIELD(x, y)
9830 element = Feld[x][y];
9832 if (element == EL_MAGIC_WALL_ACTIVE ||
9833 element == EL_MAGIC_WALL_FULL)
9835 Feld[x][y] = EL_MAGIC_WALL_DEAD;
9836 DrawLevelField(x, y);
9838 else if (element == EL_BD_MAGIC_WALL_ACTIVE ||
9839 element == EL_BD_MAGIC_WALL_FULL)
9841 Feld[x][y] = EL_BD_MAGIC_WALL_DEAD;
9842 DrawLevelField(x, y);
9846 game.magic_wall_active = FALSE;
9851 if (game.light_time_left > 0)
9853 game.light_time_left--;
9855 if (game.light_time_left == 0)
9856 RedrawAllLightSwitchesAndInvisibleElements();
9859 if (game.timegate_time_left > 0)
9861 game.timegate_time_left--;
9863 if (game.timegate_time_left == 0)
9864 CloseAllOpenTimegates();
9867 if (game.lenses_time_left > 0)
9869 game.lenses_time_left--;
9871 if (game.lenses_time_left == 0)
9872 RedrawAllInvisibleElementsForLenses();
9875 if (game.magnify_time_left > 0)
9877 game.magnify_time_left--;
9879 if (game.magnify_time_left == 0)
9880 RedrawAllInvisibleElementsForMagnifier();
9883 for (i = 0; i < MAX_PLAYERS; i++)
9885 struct PlayerInfo *player = &stored_player[i];
9887 if (SHIELD_ON(player))
9889 if (player->shield_deadly_time_left)
9890 PlayLevelSound(player->jx, player->jy, SND_SHIELD_DEADLY_ACTIVE);
9891 else if (player->shield_normal_time_left)
9892 PlayLevelSound(player->jx, player->jy, SND_SHIELD_NORMAL_ACTIVE);
9899 PlayAllPlayersSound();
9901 if (options.debug) /* calculate frames per second */
9903 static unsigned long fps_counter = 0;
9904 static int fps_frames = 0;
9905 unsigned long fps_delay_ms = Counter() - fps_counter;
9909 if (fps_delay_ms >= 500) /* calculate fps every 0.5 seconds */
9911 global.frames_per_second = 1000 * (float)fps_frames / fps_delay_ms;
9914 fps_counter = Counter();
9917 redraw_mask |= REDRAW_FPS;
9920 AdvanceFrameAndPlayerCounters(-1); /* advance counters for all players */
9922 if (local_player->show_envelope != 0 && local_player->MovPos == 0)
9924 ShowEnvelope(local_player->show_envelope - EL_ENVELOPE_1);
9926 local_player->show_envelope = 0;
9929 /* use random number generator in every frame to make it less predictable */
9930 if (game.engine_version >= VERSION_IDENT(3,1,1,0))
9934 static boolean AllPlayersInSight(struct PlayerInfo *player, int x, int y)
9936 int min_x = x, min_y = y, max_x = x, max_y = y;
9939 for (i = 0; i < MAX_PLAYERS; i++)
9941 int jx = stored_player[i].jx, jy = stored_player[i].jy;
9943 if (!stored_player[i].active || &stored_player[i] == player)
9946 min_x = MIN(min_x, jx);
9947 min_y = MIN(min_y, jy);
9948 max_x = MAX(max_x, jx);
9949 max_y = MAX(max_y, jy);
9952 return (max_x - min_x < SCR_FIELDX && max_y - min_y < SCR_FIELDY);
9955 static boolean AllPlayersInVisibleScreen()
9959 for (i = 0; i < MAX_PLAYERS; i++)
9961 int jx = stored_player[i].jx, jy = stored_player[i].jy;
9963 if (!stored_player[i].active)
9966 if (!IN_VIS_FIELD(SCREENX(jx), SCREENY(jy)))
9973 void ScrollLevel(int dx, int dy)
9975 int softscroll_offset = (setup.soft_scrolling ? TILEX : 0);
9978 BlitBitmap(drawto_field, drawto_field,
9979 FX + TILEX * (dx == -1) - softscroll_offset,
9980 FY + TILEY * (dy == -1) - softscroll_offset,
9981 SXSIZE - TILEX * (dx!=0) + 2 * softscroll_offset,
9982 SYSIZE - TILEY * (dy!=0) + 2 * softscroll_offset,
9983 FX + TILEX * (dx == 1) - softscroll_offset,
9984 FY + TILEY * (dy == 1) - softscroll_offset);
9988 x = (dx == 1 ? BX1 : BX2);
9989 for (y = BY1; y <= BY2; y++)
9990 DrawScreenField(x, y);
9995 y = (dy == 1 ? BY1 : BY2);
9996 for (x = BX1; x <= BX2; x++)
9997 DrawScreenField(x, y);
10000 redraw_mask |= REDRAW_FIELD;
10003 static boolean canFallDown(struct PlayerInfo *player)
10005 int jx = player->jx, jy = player->jy;
10007 return (IN_LEV_FIELD(jx, jy + 1) &&
10008 (IS_FREE(jx, jy + 1) ||
10009 (Feld[jx][jy + 1] == EL_ACID && player->can_fall_into_acid)) &&
10010 IS_WALKABLE_FROM(Feld[jx][jy], MV_DOWN) &&
10011 !IS_WALKABLE_INSIDE(Feld[jx][jy]));
10014 static boolean canPassField(int x, int y, int move_dir)
10016 int opposite_dir = MV_DIR_OPPOSITE(move_dir);
10017 int dx = (move_dir & MV_LEFT ? -1 : move_dir & MV_RIGHT ? +1 : 0);
10018 int dy = (move_dir & MV_UP ? -1 : move_dir & MV_DOWN ? +1 : 0);
10019 int nextx = x + dx;
10020 int nexty = y + dy;
10021 int element = Feld[x][y];
10023 return (IS_PASSABLE_FROM(element, opposite_dir) &&
10024 !CAN_MOVE(element) &&
10025 IN_LEV_FIELD(nextx, nexty) && !IS_PLAYER(nextx, nexty) &&
10026 IS_WALKABLE_FROM(Feld[nextx][nexty], move_dir) &&
10027 (level.can_pass_to_walkable || IS_FREE(nextx, nexty)));
10030 static boolean canMoveToValidFieldWithGravity(int x, int y, int move_dir)
10032 int opposite_dir = MV_DIR_OPPOSITE(move_dir);
10033 int dx = (move_dir & MV_LEFT ? -1 : move_dir & MV_RIGHT ? +1 : 0);
10034 int dy = (move_dir & MV_UP ? -1 : move_dir & MV_DOWN ? +1 : 0);
10038 return (IN_LEV_FIELD(newx, newy) && !IS_FREE_OR_PLAYER(newx, newy) &&
10039 IS_GRAVITY_REACHABLE(Feld[newx][newy]) &&
10040 (IS_DIGGABLE(Feld[newx][newy]) ||
10041 IS_WALKABLE_FROM(Feld[newx][newy], opposite_dir) ||
10042 canPassField(newx, newy, move_dir)));
10045 static void CheckGravityMovement(struct PlayerInfo *player)
10047 #if USE_PLAYER_GRAVITY
10048 if (player->gravity && !player->programmed_action)
10050 if (game.gravity && !player->programmed_action)
10053 int move_dir_horizontal = player->effective_action & MV_HORIZONTAL;
10054 int move_dir_vertical = player->effective_action & MV_VERTICAL;
10055 boolean player_is_snapping = (player->effective_action & JOY_BUTTON_1);
10056 int jx = player->jx, jy = player->jy;
10057 boolean player_is_moving_to_valid_field =
10058 (!player_is_snapping &&
10059 (canMoveToValidFieldWithGravity(jx, jy, move_dir_horizontal) ||
10060 canMoveToValidFieldWithGravity(jx, jy, move_dir_vertical)));
10061 boolean player_can_fall_down = canFallDown(player);
10063 if (player_can_fall_down &&
10064 !player_is_moving_to_valid_field)
10065 player->programmed_action = MV_DOWN;
10069 static void CheckGravityMovementWhenNotMoving(struct PlayerInfo *player)
10071 return CheckGravityMovement(player);
10073 #if USE_PLAYER_GRAVITY
10074 if (player->gravity && !player->programmed_action)
10076 if (game.gravity && !player->programmed_action)
10079 int jx = player->jx, jy = player->jy;
10080 boolean field_under_player_is_free =
10081 (IN_LEV_FIELD(jx, jy + 1) && IS_FREE(jx, jy + 1));
10082 boolean player_is_standing_on_valid_field =
10083 (IS_WALKABLE_INSIDE(Feld[jx][jy]) ||
10084 (IS_WALKABLE(Feld[jx][jy]) &&
10085 !(element_info[Feld[jx][jy]].access_direction & MV_DOWN)));
10087 if (field_under_player_is_free && !player_is_standing_on_valid_field)
10088 player->programmed_action = MV_DOWN;
10093 MovePlayerOneStep()
10094 -----------------------------------------------------------------------------
10095 dx, dy: direction (non-diagonal) to try to move the player to
10096 real_dx, real_dy: direction as read from input device (can be diagonal)
10099 boolean MovePlayerOneStep(struct PlayerInfo *player,
10100 int dx, int dy, int real_dx, int real_dy)
10102 int jx = player->jx, jy = player->jy;
10103 int new_jx = jx + dx, new_jy = jy + dy;
10104 #if !USE_FIXED_DONT_RUN_INTO
10108 boolean player_can_move = !player->cannot_move;
10110 if (!player->active || (!dx && !dy))
10111 return MP_NO_ACTION;
10113 player->MovDir = (dx < 0 ? MV_LEFT :
10114 dx > 0 ? MV_RIGHT :
10116 dy > 0 ? MV_DOWN : MV_NONE);
10118 if (!IN_LEV_FIELD(new_jx, new_jy))
10119 return MP_NO_ACTION;
10121 if (!player_can_move)
10123 if (player->MovPos == 0)
10125 player->is_moving = FALSE;
10126 player->is_digging = FALSE;
10127 player->is_collecting = FALSE;
10128 player->is_snapping = FALSE;
10129 player->is_pushing = FALSE;
10134 if (!options.network && game.centered_player_nr == -1 &&
10135 !AllPlayersInSight(player, new_jx, new_jy))
10136 return MP_NO_ACTION;
10138 if (!options.network && !AllPlayersInSight(player, new_jx, new_jy))
10139 return MP_NO_ACTION;
10142 #if !USE_FIXED_DONT_RUN_INTO
10143 element = MovingOrBlocked2ElementIfNotLeaving(new_jx, new_jy);
10145 /* (moved to DigField()) */
10146 if (player_can_move && DONT_RUN_INTO(element))
10148 if (element == EL_ACID && dx == 0 && dy == 1)
10150 SplashAcid(new_jx, new_jy);
10151 Feld[jx][jy] = EL_PLAYER_1;
10152 InitMovingField(jx, jy, MV_DOWN);
10153 Store[jx][jy] = EL_ACID;
10154 ContinueMoving(jx, jy);
10155 BuryPlayer(player);
10158 TestIfPlayerRunsIntoBadThing(jx, jy, player->MovDir);
10164 can_move = DigField(player, jx, jy, new_jx, new_jy, real_dx,real_dy, DF_DIG);
10165 if (can_move != MP_MOVING)
10168 /* check if DigField() has caused relocation of the player */
10169 if (player->jx != jx || player->jy != jy)
10170 return MP_NO_ACTION; /* <-- !!! CHECK THIS [-> MP_ACTION ?] !!! */
10172 StorePlayer[jx][jy] = 0;
10173 player->last_jx = jx;
10174 player->last_jy = jy;
10175 player->jx = new_jx;
10176 player->jy = new_jy;
10177 StorePlayer[new_jx][new_jy] = player->element_nr;
10179 if (player->move_delay_value_next != -1)
10181 player->move_delay_value = player->move_delay_value_next;
10182 player->move_delay_value_next = -1;
10186 (dx > 0 || dy > 0 ? -1 : 1) * (TILEX - TILEX / player->move_delay_value);
10188 player->step_counter++;
10190 PlayerVisit[jx][jy] = FrameCounter;
10192 #if USE_UFAST_PLAYER_EXIT_BUGFIX
10193 player->is_moving = TRUE;
10197 /* should better be called in MovePlayer(), but this breaks some tapes */
10198 ScrollPlayer(player, SCROLL_INIT);
10204 boolean MovePlayer(struct PlayerInfo *player, int dx, int dy)
10206 int jx = player->jx, jy = player->jy;
10207 int old_jx = jx, old_jy = jy;
10208 int moved = MP_NO_ACTION;
10210 if (!player->active)
10215 if (player->MovPos == 0)
10217 player->is_moving = FALSE;
10218 player->is_digging = FALSE;
10219 player->is_collecting = FALSE;
10220 player->is_snapping = FALSE;
10221 player->is_pushing = FALSE;
10227 if (player->move_delay > 0)
10230 player->move_delay = -1; /* set to "uninitialized" value */
10232 /* store if player is automatically moved to next field */
10233 player->is_auto_moving = (player->programmed_action != MV_NONE);
10235 /* remove the last programmed player action */
10236 player->programmed_action = 0;
10238 if (player->MovPos)
10240 /* should only happen if pre-1.2 tape recordings are played */
10241 /* this is only for backward compatibility */
10243 int original_move_delay_value = player->move_delay_value;
10246 printf("THIS SHOULD ONLY HAPPEN WITH PRE-1.2 LEVEL TAPES. [%ld]\n",
10250 /* scroll remaining steps with finest movement resolution */
10251 player->move_delay_value = MOVE_DELAY_NORMAL_SPEED;
10253 while (player->MovPos)
10255 ScrollPlayer(player, SCROLL_GO_ON);
10256 ScrollScreen(NULL, SCROLL_GO_ON);
10258 AdvanceFrameAndPlayerCounters(player->index_nr);
10264 player->move_delay_value = original_move_delay_value;
10267 player->is_active = FALSE;
10269 if (player->last_move_dir & MV_HORIZONTAL)
10271 if (!(moved |= MovePlayerOneStep(player, 0, dy, dx, dy)))
10272 moved |= MovePlayerOneStep(player, dx, 0, dx, dy);
10276 if (!(moved |= MovePlayerOneStep(player, dx, 0, dx, dy)))
10277 moved |= MovePlayerOneStep(player, 0, dy, dx, dy);
10280 #if USE_FIXED_BORDER_RUNNING_GFX
10281 if (!moved && !player->is_active)
10283 player->is_moving = FALSE;
10284 player->is_digging = FALSE;
10285 player->is_collecting = FALSE;
10286 player->is_snapping = FALSE;
10287 player->is_pushing = FALSE;
10295 if (moved & MP_MOVING && !ScreenMovPos &&
10296 (player->index_nr == game.centered_player_nr ||
10297 game.centered_player_nr == -1))
10299 if (moved & MP_MOVING && !ScreenMovPos &&
10300 (player == local_player || !options.network))
10303 int old_scroll_x = scroll_x, old_scroll_y = scroll_y;
10304 int offset = (setup.scroll_delay ? 3 : 0);
10306 if (!IN_VIS_FIELD(SCREENX(jx), SCREENY(jy)))
10308 /* actual player has left the screen -- scroll in that direction */
10309 if (jx != old_jx) /* player has moved horizontally */
10310 scroll_x += (jx - old_jx);
10311 else /* player has moved vertically */
10312 scroll_y += (jy - old_jy);
10316 if (jx != old_jx) /* player has moved horizontally */
10318 if ((player->MovDir == MV_LEFT && scroll_x > jx - MIDPOSX + offset) ||
10319 (player->MovDir == MV_RIGHT && scroll_x < jx - MIDPOSX - offset))
10320 scroll_x = jx-MIDPOSX + (scroll_x < jx-MIDPOSX ? -offset : +offset);
10322 /* don't scroll over playfield boundaries */
10323 if (scroll_x < SBX_Left || scroll_x > SBX_Right)
10324 scroll_x = (scroll_x < SBX_Left ? SBX_Left : SBX_Right);
10326 /* don't scroll more than one field at a time */
10327 scroll_x = old_scroll_x + SIGN(scroll_x - old_scroll_x);
10329 /* don't scroll against the player's moving direction */
10330 if ((player->MovDir == MV_LEFT && scroll_x > old_scroll_x) ||
10331 (player->MovDir == MV_RIGHT && scroll_x < old_scroll_x))
10332 scroll_x = old_scroll_x;
10334 else /* player has moved vertically */
10336 if ((player->MovDir == MV_UP && scroll_y > jy - MIDPOSY + offset) ||
10337 (player->MovDir == MV_DOWN && scroll_y < jy - MIDPOSY - offset))
10338 scroll_y = jy-MIDPOSY + (scroll_y < jy-MIDPOSY ? -offset : +offset);
10340 /* don't scroll over playfield boundaries */
10341 if (scroll_y < SBY_Upper || scroll_y > SBY_Lower)
10342 scroll_y = (scroll_y < SBY_Upper ? SBY_Upper : SBY_Lower);
10344 /* don't scroll more than one field at a time */
10345 scroll_y = old_scroll_y + SIGN(scroll_y - old_scroll_y);
10347 /* don't scroll against the player's moving direction */
10348 if ((player->MovDir == MV_UP && scroll_y > old_scroll_y) ||
10349 (player->MovDir == MV_DOWN && scroll_y < old_scroll_y))
10350 scroll_y = old_scroll_y;
10354 if (scroll_x != old_scroll_x || scroll_y != old_scroll_y)
10357 if (!options.network && game.centered_player_nr == -1 &&
10358 !AllPlayersInVisibleScreen())
10360 scroll_x = old_scroll_x;
10361 scroll_y = old_scroll_y;
10365 if (!options.network && !AllPlayersInVisibleScreen())
10367 scroll_x = old_scroll_x;
10368 scroll_y = old_scroll_y;
10373 ScrollScreen(player, SCROLL_INIT);
10374 ScrollLevel(old_scroll_x - scroll_x, old_scroll_y - scroll_y);
10379 player->StepFrame = 0;
10381 if (moved & MP_MOVING)
10383 if (old_jx != jx && old_jy == jy)
10384 player->MovDir = (old_jx < jx ? MV_RIGHT : MV_LEFT);
10385 else if (old_jx == jx && old_jy != jy)
10386 player->MovDir = (old_jy < jy ? MV_DOWN : MV_UP);
10388 DrawLevelField(jx, jy); /* for "crumbled sand" */
10390 player->last_move_dir = player->MovDir;
10391 player->is_moving = TRUE;
10392 player->is_snapping = FALSE;
10393 player->is_switching = FALSE;
10394 player->is_dropping = FALSE;
10395 player->is_dropping_pressed = FALSE;
10396 player->drop_pressed_delay = 0;
10399 /* should better be called here than above, but this breaks some tapes */
10400 ScrollPlayer(player, SCROLL_INIT);
10405 CheckGravityMovementWhenNotMoving(player);
10407 player->is_moving = FALSE;
10409 /* at this point, the player is allowed to move, but cannot move right now
10410 (e.g. because of something blocking the way) -- ensure that the player
10411 is also allowed to move in the next frame (in old versions before 3.1.1,
10412 the player was forced to wait again for eight frames before next try) */
10414 if (game.engine_version >= VERSION_IDENT(3,1,1,0))
10415 player->move_delay = 0; /* allow direct movement in the next frame */
10418 if (player->move_delay == -1) /* not yet initialized by DigField() */
10419 player->move_delay = player->move_delay_value;
10421 if (game.engine_version < VERSION_IDENT(3,0,7,0))
10423 TestIfPlayerTouchesBadThing(jx, jy);
10424 TestIfPlayerTouchesCustomElement(jx, jy);
10427 if (!player->active)
10428 RemovePlayer(player);
10433 void ScrollPlayer(struct PlayerInfo *player, int mode)
10435 int jx = player->jx, jy = player->jy;
10436 int last_jx = player->last_jx, last_jy = player->last_jy;
10437 int move_stepsize = TILEX / player->move_delay_value;
10439 #if USE_NEW_PLAYER_SPEED
10440 if (!player->active)
10443 if (player->MovPos == 0 && mode == SCROLL_GO_ON) /* player not moving */
10446 if (!player->active || player->MovPos == 0)
10450 if (mode == SCROLL_INIT)
10452 player->actual_frame_counter = FrameCounter;
10453 player->GfxPos = move_stepsize * (player->MovPos / move_stepsize);
10455 if ((player->block_last_field || player->block_delay_adjustment > 0) &&
10456 Feld[last_jx][last_jy] == EL_EMPTY)
10458 int last_field_block_delay = 0; /* start with no blocking at all */
10459 int block_delay_adjustment = player->block_delay_adjustment;
10461 /* if player blocks last field, add delay for exactly one move */
10462 if (player->block_last_field)
10464 last_field_block_delay += player->move_delay_value;
10466 /* when blocking enabled, prevent moving up despite gravity */
10467 #if USE_PLAYER_GRAVITY
10468 if (player->gravity && player->MovDir == MV_UP)
10469 block_delay_adjustment = -1;
10471 if (game.gravity && player->MovDir == MV_UP)
10472 block_delay_adjustment = -1;
10476 /* add block delay adjustment (also possible when not blocking) */
10477 last_field_block_delay += block_delay_adjustment;
10479 Feld[last_jx][last_jy] = EL_PLAYER_IS_LEAVING;
10480 MovDelay[last_jx][last_jy] = last_field_block_delay + 1;
10483 #if USE_NEW_PLAYER_SPEED
10484 if (player->MovPos != 0) /* player has not yet reached destination */
10490 else if (!FrameReached(&player->actual_frame_counter, 1))
10493 #if USE_NEW_PLAYER_SPEED
10494 if (player->MovPos != 0)
10496 player->MovPos += (player->MovPos > 0 ? -1 : 1) * move_stepsize;
10497 player->GfxPos = move_stepsize * (player->MovPos / move_stepsize);
10499 /* before DrawPlayer() to draw correct player graphic for this case */
10500 if (player->MovPos == 0)
10501 CheckGravityMovement(player);
10504 player->MovPos += (player->MovPos > 0 ? -1 : 1) * move_stepsize;
10505 player->GfxPos = move_stepsize * (player->MovPos / move_stepsize);
10507 /* before DrawPlayer() to draw correct player graphic for this case */
10508 if (player->MovPos == 0)
10509 CheckGravityMovement(player);
10512 if (player->MovPos == 0) /* player reached destination field */
10514 if (player->move_delay_reset_counter > 0)
10516 player->move_delay_reset_counter--;
10518 if (player->move_delay_reset_counter == 0)
10520 /* continue with normal speed after quickly moving through gate */
10521 HALVE_PLAYER_SPEED(player);
10523 /* be able to make the next move without delay */
10524 player->move_delay = 0;
10528 player->last_jx = jx;
10529 player->last_jy = jy;
10531 if (Feld[jx][jy] == EL_EXIT_OPEN ||
10532 Feld[jx][jy] == EL_STEEL_EXIT_OPEN ||
10533 Feld[jx][jy] == EL_SP_EXIT_OPEN ||
10534 Feld[jx][jy] == EL_SP_EXIT_OPENING) /* <-- special case */
10536 DrawPlayer(player); /* needed here only to cleanup last field */
10537 RemovePlayer(player);
10539 if (local_player->friends_still_needed == 0 ||
10540 IS_SP_ELEMENT(Feld[jx][jy]))
10541 PlayerWins(player);
10544 /* this breaks one level: "machine", level 000 */
10546 int move_direction = player->MovDir;
10547 int enter_side = MV_DIR_OPPOSITE(move_direction);
10548 int leave_side = move_direction;
10549 int old_jx = last_jx;
10550 int old_jy = last_jy;
10551 int old_element = Feld[old_jx][old_jy];
10552 int new_element = Feld[jx][jy];
10554 if (IS_CUSTOM_ELEMENT(old_element))
10555 CheckElementChangeByPlayer(old_jx, old_jy, old_element,
10557 player->index_bit, leave_side);
10559 CheckTriggeredElementChangeByPlayer(old_jx, old_jy, old_element,
10560 CE_PLAYER_LEAVES_X,
10561 player->index_bit, leave_side);
10563 if (IS_CUSTOM_ELEMENT(new_element))
10564 CheckElementChangeByPlayer(jx, jy, new_element, CE_ENTERED_BY_PLAYER,
10565 player->index_bit, enter_side);
10567 CheckTriggeredElementChangeByPlayer(jx, jy, new_element,
10568 CE_PLAYER_ENTERS_X,
10569 player->index_bit, enter_side);
10571 CheckTriggeredElementChangeBySide(jx, jy, player->element_nr,
10572 CE_MOVE_OF_X, move_direction);
10575 if (game.engine_version >= VERSION_IDENT(3,0,7,0))
10577 TestIfPlayerTouchesBadThing(jx, jy);
10578 TestIfPlayerTouchesCustomElement(jx, jy);
10580 /* needed because pushed element has not yet reached its destination,
10581 so it would trigger a change event at its previous field location */
10582 if (!player->is_pushing)
10583 TestIfElementTouchesCustomElement(jx, jy); /* for empty space */
10585 if (!player->active)
10586 RemovePlayer(player);
10589 if (!local_player->LevelSolved && level.use_step_counter)
10599 if (TimeLeft <= 10 && setup.time_limit)
10600 PlaySound(SND_GAME_RUNNING_OUT_OF_TIME);
10602 DrawGameValue_Time(TimeLeft);
10604 if (!TimeLeft && setup.time_limit)
10605 for (i = 0; i < MAX_PLAYERS; i++)
10606 KillPlayer(&stored_player[i]);
10608 else if (level.time == 0 && !AllPlayersGone) /* level w/o time limit */
10609 DrawGameValue_Time(TimePlayed);
10612 if (tape.single_step && tape.recording && !tape.pausing &&
10613 !player->programmed_action)
10614 TapeTogglePause(TAPE_TOGGLE_AUTOMATIC);
10618 void ScrollScreen(struct PlayerInfo *player, int mode)
10620 static unsigned long screen_frame_counter = 0;
10622 if (mode == SCROLL_INIT)
10624 /* set scrolling step size according to actual player's moving speed */
10625 ScrollStepSize = TILEX / player->move_delay_value;
10627 screen_frame_counter = FrameCounter;
10628 ScreenMovDir = player->MovDir;
10629 ScreenMovPos = player->MovPos;
10630 ScreenGfxPos = ScrollStepSize * (ScreenMovPos / ScrollStepSize);
10633 else if (!FrameReached(&screen_frame_counter, 1))
10638 ScreenMovPos += (ScreenMovPos > 0 ? -1 : 1) * ScrollStepSize;
10639 ScreenGfxPos = ScrollStepSize * (ScreenMovPos / ScrollStepSize);
10640 redraw_mask |= REDRAW_FIELD;
10643 ScreenMovDir = MV_NONE;
10646 void TestIfPlayerTouchesCustomElement(int x, int y)
10648 static int xy[4][2] =
10655 static int trigger_sides[4][2] =
10657 /* center side border side */
10658 { CH_SIDE_TOP, CH_SIDE_BOTTOM }, /* check top */
10659 { CH_SIDE_LEFT, CH_SIDE_RIGHT }, /* check left */
10660 { CH_SIDE_RIGHT, CH_SIDE_LEFT }, /* check right */
10661 { CH_SIDE_BOTTOM, CH_SIDE_TOP } /* check bottom */
10663 static int touch_dir[4] =
10665 MV_LEFT | MV_RIGHT,
10670 int center_element = Feld[x][y]; /* should always be non-moving! */
10673 for (i = 0; i < NUM_DIRECTIONS; i++)
10675 int xx = x + xy[i][0];
10676 int yy = y + xy[i][1];
10677 int center_side = trigger_sides[i][0];
10678 int border_side = trigger_sides[i][1];
10679 int border_element;
10681 if (!IN_LEV_FIELD(xx, yy))
10684 if (IS_PLAYER(x, y))
10686 struct PlayerInfo *player = PLAYERINFO(x, y);
10688 if (game.engine_version < VERSION_IDENT(3,0,7,0))
10689 border_element = Feld[xx][yy]; /* may be moving! */
10690 else if (!IS_MOVING(xx, yy) && !IS_BLOCKED(xx, yy))
10691 border_element = Feld[xx][yy];
10692 else if (MovDir[xx][yy] & touch_dir[i]) /* elements are touching */
10693 border_element = MovingOrBlocked2Element(xx, yy);
10695 continue; /* center and border element do not touch */
10697 CheckElementChangeByPlayer(xx, yy, border_element, CE_TOUCHED_BY_PLAYER,
10698 player->index_bit, border_side);
10699 CheckTriggeredElementChangeByPlayer(xx, yy, border_element,
10700 CE_PLAYER_TOUCHES_X,
10701 player->index_bit, border_side);
10703 else if (IS_PLAYER(xx, yy))
10705 struct PlayerInfo *player = PLAYERINFO(xx, yy);
10707 if (game.engine_version >= VERSION_IDENT(3,0,7,0))
10709 if (player->MovPos != 0 && !(player->MovDir & touch_dir[i]))
10710 continue; /* center and border element do not touch */
10713 CheckElementChangeByPlayer(x, y, center_element, CE_TOUCHED_BY_PLAYER,
10714 player->index_bit, center_side);
10715 CheckTriggeredElementChangeByPlayer(x, y, center_element,
10716 CE_PLAYER_TOUCHES_X,
10717 player->index_bit, center_side);
10723 #if USE_ELEMENT_TOUCHING_BUGFIX
10725 void TestIfElementTouchesCustomElement(int x, int y)
10727 static int xy[4][2] =
10734 static int trigger_sides[4][2] =
10736 /* center side border side */
10737 { CH_SIDE_TOP, CH_SIDE_BOTTOM }, /* check top */
10738 { CH_SIDE_LEFT, CH_SIDE_RIGHT }, /* check left */
10739 { CH_SIDE_RIGHT, CH_SIDE_LEFT }, /* check right */
10740 { CH_SIDE_BOTTOM, CH_SIDE_TOP } /* check bottom */
10742 static int touch_dir[4] =
10744 MV_LEFT | MV_RIGHT,
10749 boolean change_center_element = FALSE;
10750 int center_element = Feld[x][y]; /* should always be non-moving! */
10751 int border_element_old[NUM_DIRECTIONS];
10754 for (i = 0; i < NUM_DIRECTIONS; i++)
10756 int xx = x + xy[i][0];
10757 int yy = y + xy[i][1];
10758 int border_element;
10760 border_element_old[i] = -1;
10762 if (!IN_LEV_FIELD(xx, yy))
10765 if (game.engine_version < VERSION_IDENT(3,0,7,0))
10766 border_element = Feld[xx][yy]; /* may be moving! */
10767 else if (!IS_MOVING(xx, yy) && !IS_BLOCKED(xx, yy))
10768 border_element = Feld[xx][yy];
10769 else if (MovDir[xx][yy] & touch_dir[i]) /* elements are touching */
10770 border_element = MovingOrBlocked2Element(xx, yy);
10772 continue; /* center and border element do not touch */
10774 border_element_old[i] = border_element;
10777 for (i = 0; i < NUM_DIRECTIONS; i++)
10779 int xx = x + xy[i][0];
10780 int yy = y + xy[i][1];
10781 int center_side = trigger_sides[i][0];
10782 int border_element = border_element_old[i];
10784 if (border_element == -1)
10787 /* check for change of border element */
10788 CheckElementChangeBySide(xx, yy, border_element, center_element,
10789 CE_TOUCHING_X, center_side);
10792 for (i = 0; i < NUM_DIRECTIONS; i++)
10794 int border_side = trigger_sides[i][1];
10795 int border_element = border_element_old[i];
10797 if (border_element == -1)
10800 /* check for change of center element (but change it only once) */
10801 if (!change_center_element)
10802 change_center_element =
10803 CheckElementChangeBySide(x, y, center_element, border_element,
10804 CE_TOUCHING_X, border_side);
10810 void TestIfElementTouchesCustomElement_OLD(int x, int y)
10812 static int xy[4][2] =
10819 static int trigger_sides[4][2] =
10821 /* center side border side */
10822 { CH_SIDE_TOP, CH_SIDE_BOTTOM }, /* check top */
10823 { CH_SIDE_LEFT, CH_SIDE_RIGHT }, /* check left */
10824 { CH_SIDE_RIGHT, CH_SIDE_LEFT }, /* check right */
10825 { CH_SIDE_BOTTOM, CH_SIDE_TOP } /* check bottom */
10827 static int touch_dir[4] =
10829 MV_LEFT | MV_RIGHT,
10834 boolean change_center_element = FALSE;
10835 int center_element = Feld[x][y]; /* should always be non-moving! */
10838 for (i = 0; i < NUM_DIRECTIONS; i++)
10840 int xx = x + xy[i][0];
10841 int yy = y + xy[i][1];
10842 int center_side = trigger_sides[i][0];
10843 int border_side = trigger_sides[i][1];
10844 int border_element;
10846 if (!IN_LEV_FIELD(xx, yy))
10849 if (game.engine_version < VERSION_IDENT(3,0,7,0))
10850 border_element = Feld[xx][yy]; /* may be moving! */
10851 else if (!IS_MOVING(xx, yy) && !IS_BLOCKED(xx, yy))
10852 border_element = Feld[xx][yy];
10853 else if (MovDir[xx][yy] & touch_dir[i]) /* elements are touching */
10854 border_element = MovingOrBlocked2Element(xx, yy);
10856 continue; /* center and border element do not touch */
10858 /* check for change of center element (but change it only once) */
10859 if (!change_center_element)
10860 change_center_element =
10861 CheckElementChangeBySide(x, y, center_element, border_element,
10862 CE_TOUCHING_X, border_side);
10864 /* check for change of border element */
10865 CheckElementChangeBySide(xx, yy, border_element, center_element,
10866 CE_TOUCHING_X, center_side);
10872 void TestIfElementHitsCustomElement(int x, int y, int direction)
10874 int dx = (direction == MV_LEFT ? -1 : direction == MV_RIGHT ? +1 : 0);
10875 int dy = (direction == MV_UP ? -1 : direction == MV_DOWN ? +1 : 0);
10876 int hitx = x + dx, hity = y + dy;
10877 int hitting_element = Feld[x][y];
10878 int touched_element;
10880 if (IN_LEV_FIELD(hitx, hity) && IS_FREE(hitx, hity))
10883 touched_element = (IN_LEV_FIELD(hitx, hity) ?
10884 MovingOrBlocked2Element(hitx, hity) : EL_STEELWALL);
10886 if (IN_LEV_FIELD(hitx, hity))
10888 int opposite_direction = MV_DIR_OPPOSITE(direction);
10889 int hitting_side = direction;
10890 int touched_side = opposite_direction;
10891 boolean object_hit = (!IS_MOVING(hitx, hity) ||
10892 MovDir[hitx][hity] != direction ||
10893 ABS(MovPos[hitx][hity]) <= TILEY / 2);
10899 CheckElementChangeBySide(x, y, hitting_element, touched_element,
10900 CE_HITTING_X, touched_side);
10902 CheckElementChangeBySide(hitx, hity, touched_element,
10903 hitting_element, CE_HIT_BY_X, hitting_side);
10905 CheckElementChangeBySide(hitx, hity, touched_element, hitting_element,
10906 CE_HIT_BY_SOMETHING, opposite_direction);
10910 /* "hitting something" is also true when hitting the playfield border */
10911 CheckElementChangeBySide(x, y, hitting_element, touched_element,
10912 CE_HITTING_SOMETHING, direction);
10916 void TestIfElementSmashesCustomElement(int x, int y, int direction)
10918 int dx = (direction == MV_LEFT ? -1 : direction == MV_RIGHT ? +1 : 0);
10919 int dy = (direction == MV_UP ? -1 : direction == MV_DOWN ? +1 : 0);
10920 int hitx = x + dx, hity = y + dy;
10921 int hitting_element = Feld[x][y];
10922 int touched_element;
10924 boolean object_hit = (IN_LEV_FIELD(hitx, hity) &&
10925 !IS_FREE(hitx, hity) &&
10926 (!IS_MOVING(hitx, hity) ||
10927 MovDir[hitx][hity] != direction ||
10928 ABS(MovPos[hitx][hity]) <= TILEY / 2));
10931 if (IN_LEV_FIELD(hitx, hity) && IS_FREE(hitx, hity))
10935 if (IN_LEV_FIELD(hitx, hity) && !object_hit)
10939 touched_element = (IN_LEV_FIELD(hitx, hity) ?
10940 MovingOrBlocked2Element(hitx, hity) : EL_STEELWALL);
10942 CheckElementChangeBySide(x, y, hitting_element, touched_element,
10943 EP_CAN_SMASH_EVERYTHING, direction);
10945 if (IN_LEV_FIELD(hitx, hity))
10947 int opposite_direction = MV_DIR_OPPOSITE(direction);
10948 int hitting_side = direction;
10949 int touched_side = opposite_direction;
10951 int touched_element = MovingOrBlocked2Element(hitx, hity);
10954 boolean object_hit = (!IS_MOVING(hitx, hity) ||
10955 MovDir[hitx][hity] != direction ||
10956 ABS(MovPos[hitx][hity]) <= TILEY / 2);
10965 CheckElementChangeBySide(hitx, hity, touched_element, hitting_element,
10966 CE_SMASHED_BY_SOMETHING, opposite_direction);
10968 CheckElementChangeBySide(x, y, hitting_element, touched_element,
10969 CE_OTHER_IS_SMASHING, touched_side);
10971 CheckElementChangeBySide(hitx, hity, touched_element, hitting_element,
10972 CE_OTHER_GETS_SMASHED, hitting_side);
10978 void TestIfGoodThingHitsBadThing(int good_x, int good_y, int good_move_dir)
10980 int i, kill_x = -1, kill_y = -1;
10982 int bad_element = -1;
10983 static int test_xy[4][2] =
10990 static int test_dir[4] =
10998 for (i = 0; i < NUM_DIRECTIONS; i++)
11000 int test_x, test_y, test_move_dir, test_element;
11002 test_x = good_x + test_xy[i][0];
11003 test_y = good_y + test_xy[i][1];
11005 if (!IN_LEV_FIELD(test_x, test_y))
11009 (IS_MOVING(test_x, test_y) ? MovDir[test_x][test_y] : MV_NONE);
11011 test_element = MovingOrBlocked2ElementIfNotLeaving(test_x, test_y);
11013 /* 1st case: good thing is moving towards DONT_RUN_INTO style bad thing;
11014 2nd case: DONT_TOUCH style bad thing does not move away from good thing
11016 if ((DONT_RUN_INTO(test_element) && good_move_dir == test_dir[i]) ||
11017 (DONT_TOUCH(test_element) && test_move_dir != test_dir[i]))
11021 bad_element = test_element;
11027 if (kill_x != -1 || kill_y != -1)
11029 if (IS_PLAYER(good_x, good_y))
11031 struct PlayerInfo *player = PLAYERINFO(good_x, good_y);
11033 if (player->shield_deadly_time_left > 0 &&
11034 !IS_INDESTRUCTIBLE(bad_element))
11035 Bang(kill_x, kill_y);
11036 else if (!PLAYER_ENEMY_PROTECTED(good_x, good_y))
11037 KillPlayer(player);
11040 Bang(good_x, good_y);
11044 void TestIfBadThingHitsGoodThing(int bad_x, int bad_y, int bad_move_dir)
11046 int i, kill_x = -1, kill_y = -1;
11047 int bad_element = Feld[bad_x][bad_y];
11048 static int test_xy[4][2] =
11055 static int touch_dir[4] =
11057 MV_LEFT | MV_RIGHT,
11062 static int test_dir[4] =
11070 if (bad_element == EL_EXPLOSION) /* skip just exploding bad things */
11073 for (i = 0; i < NUM_DIRECTIONS; i++)
11075 int test_x, test_y, test_move_dir, test_element;
11077 test_x = bad_x + test_xy[i][0];
11078 test_y = bad_y + test_xy[i][1];
11079 if (!IN_LEV_FIELD(test_x, test_y))
11083 (IS_MOVING(test_x, test_y) ? MovDir[test_x][test_y] : MV_NONE);
11085 test_element = Feld[test_x][test_y];
11087 /* 1st case: good thing is moving towards DONT_RUN_INTO style bad thing;
11088 2nd case: DONT_TOUCH style bad thing does not move away from good thing
11090 if ((DONT_RUN_INTO(bad_element) && bad_move_dir == test_dir[i]) ||
11091 (DONT_TOUCH(bad_element) && test_move_dir != test_dir[i]))
11093 /* good thing is player or penguin that does not move away */
11094 if (IS_PLAYER(test_x, test_y))
11096 struct PlayerInfo *player = PLAYERINFO(test_x, test_y);
11098 if (bad_element == EL_ROBOT && player->is_moving)
11099 continue; /* robot does not kill player if he is moving */
11101 if (game.engine_version >= VERSION_IDENT(3,0,7,0))
11103 if (player->MovPos != 0 && !(player->MovDir & touch_dir[i]))
11104 continue; /* center and border element do not touch */
11111 else if (test_element == EL_PENGUIN)
11120 if (kill_x != -1 || kill_y != -1)
11122 if (IS_PLAYER(kill_x, kill_y))
11124 struct PlayerInfo *player = PLAYERINFO(kill_x, kill_y);
11126 if (player->shield_deadly_time_left > 0 &&
11127 !IS_INDESTRUCTIBLE(bad_element))
11128 Bang(bad_x, bad_y);
11129 else if (!PLAYER_ENEMY_PROTECTED(kill_x, kill_y))
11130 KillPlayer(player);
11133 Bang(kill_x, kill_y);
11137 void TestIfPlayerTouchesBadThing(int x, int y)
11139 TestIfGoodThingHitsBadThing(x, y, MV_NONE);
11142 void TestIfPlayerRunsIntoBadThing(int x, int y, int move_dir)
11144 TestIfGoodThingHitsBadThing(x, y, move_dir);
11147 void TestIfBadThingTouchesPlayer(int x, int y)
11149 TestIfBadThingHitsGoodThing(x, y, MV_NONE);
11152 void TestIfBadThingRunsIntoPlayer(int x, int y, int move_dir)
11154 TestIfBadThingHitsGoodThing(x, y, move_dir);
11157 void TestIfFriendTouchesBadThing(int x, int y)
11159 TestIfGoodThingHitsBadThing(x, y, MV_NONE);
11162 void TestIfBadThingTouchesFriend(int x, int y)
11164 TestIfBadThingHitsGoodThing(x, y, MV_NONE);
11167 void TestIfBadThingTouchesOtherBadThing(int bad_x, int bad_y)
11169 int i, kill_x = bad_x, kill_y = bad_y;
11170 static int xy[4][2] =
11178 for (i = 0; i < NUM_DIRECTIONS; i++)
11182 x = bad_x + xy[i][0];
11183 y = bad_y + xy[i][1];
11184 if (!IN_LEV_FIELD(x, y))
11187 element = Feld[x][y];
11188 if (IS_AMOEBOID(element) || element == EL_GAME_OF_LIFE ||
11189 element == EL_AMOEBA_GROWING || element == EL_AMOEBA_DROP)
11197 if (kill_x != bad_x || kill_y != bad_y)
11198 Bang(bad_x, bad_y);
11201 void KillPlayer(struct PlayerInfo *player)
11203 int jx = player->jx, jy = player->jy;
11205 if (!player->active)
11208 /* the following code was introduced to prevent an infinite loop when calling
11210 -> CheckTriggeredElementChangeExt()
11211 -> ExecuteCustomElementAction()
11213 -> (infinitely repeating the above sequence of function calls)
11214 which occurs when killing the player while having a CE with the setting
11215 "kill player X when explosion of <player X>"; the solution using a new
11216 field "player->killed" was chosen for backwards compatibility, although
11217 clever use of the fields "player->active" etc. would probably also work */
11219 if (player->killed)
11223 player->killed = TRUE;
11225 /* remove accessible field at the player's position */
11226 Feld[jx][jy] = EL_EMPTY;
11228 /* deactivate shield (else Bang()/Explode() would not work right) */
11229 player->shield_normal_time_left = 0;
11230 player->shield_deadly_time_left = 0;
11233 BuryPlayer(player);
11236 static void KillPlayerUnlessEnemyProtected(int x, int y)
11238 if (!PLAYER_ENEMY_PROTECTED(x, y))
11239 KillPlayer(PLAYERINFO(x, y));
11242 static void KillPlayerUnlessExplosionProtected(int x, int y)
11244 if (!PLAYER_EXPLOSION_PROTECTED(x, y))
11245 KillPlayer(PLAYERINFO(x, y));
11248 void BuryPlayer(struct PlayerInfo *player)
11250 int jx = player->jx, jy = player->jy;
11252 if (!player->active)
11255 PlayLevelSoundElementAction(jx, jy, player->artwork_element, ACTION_DYING);
11256 PlayLevelSound(jx, jy, SND_GAME_LOSING);
11258 player->GameOver = TRUE;
11259 RemovePlayer(player);
11262 void RemovePlayer(struct PlayerInfo *player)
11264 int jx = player->jx, jy = player->jy;
11265 int i, found = FALSE;
11267 player->present = FALSE;
11268 player->active = FALSE;
11270 if (!ExplodeField[jx][jy])
11271 StorePlayer[jx][jy] = 0;
11273 if (player->is_moving)
11274 DrawLevelField(player->last_jx, player->last_jy);
11276 for (i = 0; i < MAX_PLAYERS; i++)
11277 if (stored_player[i].active)
11281 AllPlayersGone = TRUE;
11287 #if USE_NEW_SNAP_DELAY
11288 static void setFieldForSnapping(int x, int y, int element, int direction)
11290 struct ElementInfo *ei = &element_info[element];
11291 int direction_bit = MV_DIR_TO_BIT(direction);
11292 int graphic_snapping = ei->direction_graphic[ACTION_SNAPPING][direction_bit];
11293 int action = (graphic_snapping != IMG_EMPTY_SPACE ? ACTION_SNAPPING :
11294 IS_DIGGABLE(element) ? ACTION_DIGGING : ACTION_COLLECTING);
11296 Feld[x][y] = EL_ELEMENT_SNAPPING;
11297 MovDelay[x][y] = MOVE_DELAY_NORMAL_SPEED + 1 - 1;
11299 ResetGfxAnimation(x, y);
11301 GfxElement[x][y] = element;
11302 GfxAction[x][y] = action;
11303 GfxDir[x][y] = direction;
11304 GfxFrame[x][y] = -1;
11309 =============================================================================
11310 checkDiagonalPushing()
11311 -----------------------------------------------------------------------------
11312 check if diagonal input device direction results in pushing of object
11313 (by checking if the alternative direction is walkable, diggable, ...)
11314 =============================================================================
11317 static boolean checkDiagonalPushing(struct PlayerInfo *player,
11318 int x, int y, int real_dx, int real_dy)
11320 int jx, jy, dx, dy, xx, yy;
11322 if (real_dx == 0 || real_dy == 0) /* no diagonal direction => push */
11325 /* diagonal direction: check alternative direction */
11330 xx = jx + (dx == 0 ? real_dx : 0);
11331 yy = jy + (dy == 0 ? real_dy : 0);
11333 return (!IN_LEV_FIELD(xx, yy) || IS_SOLID_FOR_PUSHING(Feld[xx][yy]));
11337 =============================================================================
11339 -----------------------------------------------------------------------------
11340 x, y: field next to player (non-diagonal) to try to dig to
11341 real_dx, real_dy: direction as read from input device (can be diagonal)
11342 =============================================================================
11345 int DigField(struct PlayerInfo *player,
11346 int oldx, int oldy, int x, int y,
11347 int real_dx, int real_dy, int mode)
11349 boolean is_player = (IS_PLAYER(oldx, oldy) || mode != DF_DIG);
11350 boolean player_was_pushing = player->is_pushing;
11351 boolean player_can_move = (!player->cannot_move && mode != DF_SNAP);
11352 boolean player_can_move_or_snap = (!player->cannot_move || mode == DF_SNAP);
11353 int jx = oldx, jy = oldy;
11354 int dx = x - jx, dy = y - jy;
11355 int nextx = x + dx, nexty = y + dy;
11356 int move_direction = (dx == -1 ? MV_LEFT :
11357 dx == +1 ? MV_RIGHT :
11359 dy == +1 ? MV_DOWN : MV_NONE);
11360 int opposite_direction = MV_DIR_OPPOSITE(move_direction);
11361 int dig_side = MV_DIR_OPPOSITE(move_direction);
11362 int old_element = Feld[jx][jy];
11363 #if USE_FIXED_DONT_RUN_INTO
11364 int element = MovingOrBlocked2ElementIfNotLeaving(x, y);
11370 if (is_player) /* function can also be called by EL_PENGUIN */
11372 if (player->MovPos == 0)
11374 player->is_digging = FALSE;
11375 player->is_collecting = FALSE;
11378 if (player->MovPos == 0) /* last pushing move finished */
11379 player->is_pushing = FALSE;
11381 if (mode == DF_NO_PUSH) /* player just stopped pushing */
11383 player->is_switching = FALSE;
11384 player->push_delay = -1;
11386 return MP_NO_ACTION;
11390 #if !USE_FIXED_DONT_RUN_INTO
11391 if (IS_MOVING(x, y) || IS_PLAYER(x, y))
11392 return MP_NO_ACTION;
11395 if (IS_TUBE(Back[jx][jy]) && game.engine_version >= VERSION_IDENT(2,2,0,0))
11396 old_element = Back[jx][jy];
11398 /* in case of element dropped at player position, check background */
11399 else if (Back[jx][jy] != EL_EMPTY &&
11400 game.engine_version >= VERSION_IDENT(2,2,0,0))
11401 old_element = Back[jx][jy];
11403 if (IS_WALKABLE(old_element) && !ACCESS_FROM(old_element, move_direction))
11404 return MP_NO_ACTION; /* field has no opening in this direction */
11406 if (IS_PASSABLE(old_element) && !ACCESS_FROM(old_element,opposite_direction))
11407 return MP_NO_ACTION; /* field has no opening in this direction */
11409 #if USE_FIXED_DONT_RUN_INTO
11410 if (player_can_move && element == EL_ACID && move_direction == MV_DOWN)
11414 Feld[jx][jy] = player->artwork_element;
11415 InitMovingField(jx, jy, MV_DOWN);
11416 Store[jx][jy] = EL_ACID;
11417 ContinueMoving(jx, jy);
11418 BuryPlayer(player);
11420 return MP_DONT_RUN_INTO;
11424 #if USE_FIXED_DONT_RUN_INTO
11425 if (player_can_move && DONT_RUN_INTO(element))
11427 TestIfPlayerRunsIntoBadThing(jx, jy, player->MovDir);
11429 return MP_DONT_RUN_INTO;
11433 #if USE_FIXED_DONT_RUN_INTO
11434 if (IS_MOVING(x, y) || IS_PLAYER(x, y))
11435 return MP_NO_ACTION;
11438 #if !USE_FIXED_DONT_RUN_INTO
11439 element = Feld[x][y];
11442 collect_count = element_info[element].collect_count_initial;
11444 if (!is_player && !IS_COLLECTIBLE(element)) /* penguin cannot collect it */
11445 return MP_NO_ACTION;
11447 if (game.engine_version < VERSION_IDENT(2,2,0,0))
11448 player_can_move = player_can_move_or_snap;
11450 if (mode == DF_SNAP && !IS_SNAPPABLE(element) &&
11451 game.engine_version >= VERSION_IDENT(2,2,0,0))
11453 CheckElementChangeByPlayer(x, y, element, CE_SNAPPED_BY_PLAYER,
11454 player->index_bit, dig_side);
11455 CheckTriggeredElementChangeByPlayer(x, y, element, CE_PLAYER_SNAPS_X,
11456 player->index_bit, dig_side);
11458 if (Feld[x][y] != element) /* field changed by snapping */
11461 return MP_NO_ACTION;
11464 #if USE_PLAYER_GRAVITY
11465 if (player->gravity && is_player && !player->is_auto_moving &&
11466 canFallDown(player) && move_direction != MV_DOWN &&
11467 !canMoveToValidFieldWithGravity(jx, jy, move_direction))
11468 return MP_NO_ACTION; /* player cannot walk here due to gravity */
11470 if (game.gravity && is_player && !player->is_auto_moving &&
11471 canFallDown(player) && move_direction != MV_DOWN &&
11472 !canMoveToValidFieldWithGravity(jx, jy, move_direction))
11473 return MP_NO_ACTION; /* player cannot walk here due to gravity */
11476 if (player_can_move &&
11477 IS_WALKABLE(element) && ACCESS_FROM(element, opposite_direction))
11479 int sound_element = SND_ELEMENT(element);
11480 int sound_action = ACTION_WALKING;
11482 if (IS_RND_GATE(element))
11484 if (!player->key[RND_GATE_NR(element)])
11485 return MP_NO_ACTION;
11487 else if (IS_RND_GATE_GRAY(element))
11489 if (!player->key[RND_GATE_GRAY_NR(element)])
11490 return MP_NO_ACTION;
11492 else if (IS_RND_GATE_GRAY_ACTIVE(element))
11494 if (!player->key[RND_GATE_GRAY_ACTIVE_NR(element)])
11495 return MP_NO_ACTION;
11497 else if (element == EL_EXIT_OPEN ||
11498 element == EL_STEEL_EXIT_OPEN ||
11499 element == EL_SP_EXIT_OPEN ||
11500 element == EL_SP_EXIT_OPENING)
11502 sound_action = ACTION_PASSING; /* player is passing exit */
11504 else if (element == EL_EMPTY)
11506 sound_action = ACTION_MOVING; /* nothing to walk on */
11509 /* play sound from background or player, whatever is available */
11510 if (element_info[sound_element].sound[sound_action] != SND_UNDEFINED)
11511 PlayLevelSoundElementAction(x, y, sound_element, sound_action);
11513 PlayLevelSoundElementAction(x, y, player->artwork_element, sound_action);
11515 else if (player_can_move &&
11516 IS_PASSABLE(element) && canPassField(x, y, move_direction))
11518 if (!ACCESS_FROM(element, opposite_direction))
11519 return MP_NO_ACTION; /* field not accessible from this direction */
11521 if (CAN_MOVE(element)) /* only fixed elements can be passed! */
11522 return MP_NO_ACTION;
11524 if (IS_EM_GATE(element))
11526 if (!player->key[EM_GATE_NR(element)])
11527 return MP_NO_ACTION;
11529 else if (IS_EM_GATE_GRAY(element))
11531 if (!player->key[EM_GATE_GRAY_NR(element)])
11532 return MP_NO_ACTION;
11534 else if (IS_EM_GATE_GRAY_ACTIVE(element))
11536 if (!player->key[EM_GATE_GRAY_ACTIVE_NR(element)])
11537 return MP_NO_ACTION;
11539 else if (IS_EMC_GATE(element))
11541 if (!player->key[EMC_GATE_NR(element)])
11542 return MP_NO_ACTION;
11544 else if (IS_EMC_GATE_GRAY(element))
11546 if (!player->key[EMC_GATE_GRAY_NR(element)])
11547 return MP_NO_ACTION;
11549 else if (IS_EMC_GATE_GRAY_ACTIVE(element))
11551 if (!player->key[EMC_GATE_GRAY_ACTIVE_NR(element)])
11552 return MP_NO_ACTION;
11554 else if (IS_SP_PORT(element))
11556 if (element == EL_SP_GRAVITY_PORT_LEFT ||
11557 element == EL_SP_GRAVITY_PORT_RIGHT ||
11558 element == EL_SP_GRAVITY_PORT_UP ||
11559 element == EL_SP_GRAVITY_PORT_DOWN)
11560 #if USE_PLAYER_GRAVITY
11561 player->gravity = !player->gravity;
11563 game.gravity = !game.gravity;
11565 else if (element == EL_SP_GRAVITY_ON_PORT_LEFT ||
11566 element == EL_SP_GRAVITY_ON_PORT_RIGHT ||
11567 element == EL_SP_GRAVITY_ON_PORT_UP ||
11568 element == EL_SP_GRAVITY_ON_PORT_DOWN)
11569 #if USE_PLAYER_GRAVITY
11570 player->gravity = TRUE;
11572 game.gravity = TRUE;
11574 else if (element == EL_SP_GRAVITY_OFF_PORT_LEFT ||
11575 element == EL_SP_GRAVITY_OFF_PORT_RIGHT ||
11576 element == EL_SP_GRAVITY_OFF_PORT_UP ||
11577 element == EL_SP_GRAVITY_OFF_PORT_DOWN)
11578 #if USE_PLAYER_GRAVITY
11579 player->gravity = FALSE;
11581 game.gravity = FALSE;
11585 /* automatically move to the next field with double speed */
11586 player->programmed_action = move_direction;
11588 if (player->move_delay_reset_counter == 0)
11590 player->move_delay_reset_counter = 2; /* two double speed steps */
11592 DOUBLE_PLAYER_SPEED(player);
11595 PlayLevelSoundAction(x, y, ACTION_PASSING);
11597 else if (player_can_move_or_snap && IS_DIGGABLE(element))
11601 if (mode != DF_SNAP)
11603 GfxElement[x][y] = GFX_ELEMENT(element);
11604 player->is_digging = TRUE;
11607 PlayLevelSoundElementAction(x, y, element, ACTION_DIGGING);
11609 CheckTriggeredElementChangeByPlayer(x, y, element, CE_PLAYER_DIGS_X,
11610 player->index_bit, dig_side);
11612 if (mode == DF_SNAP)
11614 #if USE_NEW_SNAP_DELAY
11615 if (level.block_snap_field)
11616 setFieldForSnapping(x, y, element, move_direction);
11618 TestIfElementTouchesCustomElement(x, y); /* for empty space */
11620 TestIfElementTouchesCustomElement(x, y); /* for empty space */
11623 CheckTriggeredElementChangeByPlayer(x, y, element, CE_PLAYER_SNAPS_X,
11624 player->index_bit, dig_side);
11627 else if (player_can_move_or_snap && IS_COLLECTIBLE(element))
11631 if (is_player && mode != DF_SNAP)
11633 GfxElement[x][y] = element;
11634 player->is_collecting = TRUE;
11637 if (element == EL_SPEED_PILL)
11639 player->move_delay_value = MOVE_DELAY_HIGH_SPEED;
11641 else if (element == EL_EXTRA_TIME && level.time > 0)
11643 TimeLeft += level.extra_time;
11644 DrawGameValue_Time(TimeLeft);
11646 else if (element == EL_SHIELD_NORMAL || element == EL_SHIELD_DEADLY)
11648 player->shield_normal_time_left += level.shield_normal_time;
11649 if (element == EL_SHIELD_DEADLY)
11650 player->shield_deadly_time_left += level.shield_deadly_time;
11652 else if (element == EL_DYNAMITE ||
11653 element == EL_EM_DYNAMITE ||
11654 element == EL_SP_DISK_RED)
11656 if (player->inventory_size < MAX_INVENTORY_SIZE)
11657 player->inventory_element[player->inventory_size++] = element;
11659 DrawGameDoorValues();
11661 else if (element == EL_DYNABOMB_INCREASE_NUMBER)
11663 player->dynabomb_count++;
11664 player->dynabombs_left++;
11666 else if (element == EL_DYNABOMB_INCREASE_SIZE)
11668 player->dynabomb_size++;
11670 else if (element == EL_DYNABOMB_INCREASE_POWER)
11672 player->dynabomb_xl = TRUE;
11674 else if (IS_KEY(element))
11676 player->key[KEY_NR(element)] = TRUE;
11678 DrawGameDoorValues();
11680 else if (IS_ENVELOPE(element))
11682 player->show_envelope = element;
11684 else if (element == EL_EMC_LENSES)
11686 game.lenses_time_left = level.lenses_time * FRAMES_PER_SECOND;
11688 RedrawAllInvisibleElementsForLenses();
11690 else if (element == EL_EMC_MAGNIFIER)
11692 game.magnify_time_left = level.magnify_time * FRAMES_PER_SECOND;
11694 RedrawAllInvisibleElementsForMagnifier();
11696 else if (IS_DROPPABLE(element) ||
11697 IS_THROWABLE(element)) /* can be collected and dropped */
11701 if (collect_count == 0)
11702 player->inventory_infinite_element = element;
11704 for (i = 0; i < collect_count; i++)
11705 if (player->inventory_size < MAX_INVENTORY_SIZE)
11706 player->inventory_element[player->inventory_size++] = element;
11708 DrawGameDoorValues();
11710 else if (collect_count > 0)
11712 local_player->gems_still_needed -= collect_count;
11713 if (local_player->gems_still_needed < 0)
11714 local_player->gems_still_needed = 0;
11716 DrawGameValue_Emeralds(local_player->gems_still_needed);
11719 RaiseScoreElement(element);
11720 PlayLevelSoundElementAction(x, y, element, ACTION_COLLECTING);
11723 CheckTriggeredElementChangeByPlayer(x, y, element, CE_PLAYER_COLLECTS_X,
11724 player->index_bit, dig_side);
11726 if (mode == DF_SNAP)
11728 #if USE_NEW_SNAP_DELAY
11729 if (level.block_snap_field)
11730 setFieldForSnapping(x, y, element, move_direction);
11732 TestIfElementTouchesCustomElement(x, y); /* for empty space */
11734 TestIfElementTouchesCustomElement(x, y); /* for empty space */
11737 CheckTriggeredElementChangeByPlayer(x, y, element, CE_PLAYER_SNAPS_X,
11738 player->index_bit, dig_side);
11741 else if (player_can_move_or_snap && IS_PUSHABLE(element))
11743 if (mode == DF_SNAP && element != EL_BD_ROCK)
11744 return MP_NO_ACTION;
11746 if (CAN_FALL(element) && dy)
11747 return MP_NO_ACTION;
11749 if (CAN_FALL(element) && IN_LEV_FIELD(x, y + 1) && IS_FREE(x, y + 1) &&
11750 !(element == EL_SPRING && level.use_spring_bug))
11751 return MP_NO_ACTION;
11753 if (CAN_MOVE(element) && GET_MAX_MOVE_DELAY(element) == 0 &&
11754 ((move_direction & MV_VERTICAL &&
11755 ((element_info[element].move_pattern & MV_LEFT &&
11756 IN_LEV_FIELD(x - 1, y) && IS_FREE(x - 1, y)) ||
11757 (element_info[element].move_pattern & MV_RIGHT &&
11758 IN_LEV_FIELD(x + 1, y) && IS_FREE(x + 1, y)))) ||
11759 (move_direction & MV_HORIZONTAL &&
11760 ((element_info[element].move_pattern & MV_UP &&
11761 IN_LEV_FIELD(x, y - 1) && IS_FREE(x, y - 1)) ||
11762 (element_info[element].move_pattern & MV_DOWN &&
11763 IN_LEV_FIELD(x, y + 1) && IS_FREE(x, y + 1))))))
11764 return MP_NO_ACTION;
11766 /* do not push elements already moving away faster than player */
11767 if (CAN_MOVE(element) && MovDir[x][y] == move_direction &&
11768 ABS(getElementMoveStepsize(x, y)) > MOVE_STEPSIZE_NORMAL)
11769 return MP_NO_ACTION;
11771 if (game.engine_version >= VERSION_IDENT(3,1,0,0))
11773 if (player->push_delay_value == -1 || !player_was_pushing)
11774 player->push_delay_value = GET_NEW_PUSH_DELAY(element);
11776 else if (game.engine_version >= VERSION_IDENT(3,0,7,1))
11778 if (player->push_delay_value == -1)
11779 player->push_delay_value = GET_NEW_PUSH_DELAY(element);
11781 else if (game.engine_version >= VERSION_IDENT(2,2,0,7))
11783 if (!player->is_pushing)
11784 player->push_delay_value = GET_NEW_PUSH_DELAY(element);
11787 player->is_pushing = TRUE;
11788 player->is_active = TRUE;
11790 if (!(IN_LEV_FIELD(nextx, nexty) &&
11791 (IS_FREE(nextx, nexty) ||
11792 (Feld[nextx][nexty] == EL_SOKOBAN_FIELD_EMPTY &&
11793 IS_SB_ELEMENT(element)))))
11794 return MP_NO_ACTION;
11796 if (!checkDiagonalPushing(player, x, y, real_dx, real_dy))
11797 return MP_NO_ACTION;
11799 if (player->push_delay == -1) /* new pushing; restart delay */
11800 player->push_delay = 0;
11802 if (player->push_delay < player->push_delay_value &&
11803 !(tape.playing && tape.file_version < FILE_VERSION_2_0) &&
11804 element != EL_SPRING && element != EL_BALLOON)
11806 /* make sure that there is no move delay before next try to push */
11807 if (game.engine_version >= VERSION_IDENT(3,0,7,1))
11808 player->move_delay = 0;
11810 return MP_NO_ACTION;
11813 if (IS_SB_ELEMENT(element))
11815 if (element == EL_SOKOBAN_FIELD_FULL)
11817 Back[x][y] = EL_SOKOBAN_FIELD_EMPTY;
11818 local_player->sokobanfields_still_needed++;
11821 if (Feld[nextx][nexty] == EL_SOKOBAN_FIELD_EMPTY)
11823 Back[nextx][nexty] = EL_SOKOBAN_FIELD_EMPTY;
11824 local_player->sokobanfields_still_needed--;
11827 Feld[x][y] = EL_SOKOBAN_OBJECT;
11829 if (Back[x][y] == Back[nextx][nexty])
11830 PlayLevelSoundAction(x, y, ACTION_PUSHING);
11831 else if (Back[x][y] != 0)
11832 PlayLevelSoundElementAction(x, y, EL_SOKOBAN_FIELD_FULL,
11835 PlayLevelSoundElementAction(nextx, nexty, EL_SOKOBAN_FIELD_EMPTY,
11838 if (local_player->sokobanfields_still_needed == 0 &&
11839 game.emulation == EMU_SOKOBAN)
11841 PlayerWins(player);
11843 PlayLevelSound(x, y, SND_GAME_SOKOBAN_SOLVING);
11847 PlayLevelSoundElementAction(x, y, element, ACTION_PUSHING);
11849 InitMovingField(x, y, move_direction);
11850 GfxAction[x][y] = ACTION_PUSHING;
11852 if (mode == DF_SNAP)
11853 ContinueMoving(x, y);
11855 MovPos[x][y] = (dx != 0 ? dx : dy);
11857 Pushed[x][y] = TRUE;
11858 Pushed[nextx][nexty] = TRUE;
11860 if (game.engine_version < VERSION_IDENT(2,2,0,7))
11861 player->push_delay_value = GET_NEW_PUSH_DELAY(element);
11863 player->push_delay_value = -1; /* get new value later */
11865 /* check for element change _after_ element has been pushed */
11866 if (game.use_change_when_pushing_bug)
11868 CheckElementChangeByPlayer(x, y, element, CE_PUSHED_BY_PLAYER,
11869 player->index_bit, dig_side);
11870 CheckTriggeredElementChangeByPlayer(x, y, element, CE_PLAYER_PUSHES_X,
11871 player->index_bit, dig_side);
11874 else if (IS_SWITCHABLE(element))
11876 if (PLAYER_SWITCHING(player, x, y))
11878 CheckTriggeredElementChangeByPlayer(x, y, element, CE_PLAYER_PRESSES_X,
11879 player->index_bit, dig_side);
11884 player->is_switching = TRUE;
11885 player->switch_x = x;
11886 player->switch_y = y;
11888 PlayLevelSoundElementAction(x, y, element, ACTION_ACTIVATING);
11890 if (element == EL_ROBOT_WHEEL)
11892 Feld[x][y] = EL_ROBOT_WHEEL_ACTIVE;
11896 DrawLevelField(x, y);
11898 else if (element == EL_SP_TERMINAL)
11902 SCAN_PLAYFIELD(xx, yy)
11904 if (Feld[xx][yy] == EL_SP_DISK_YELLOW)
11906 else if (Feld[xx][yy] == EL_SP_TERMINAL)
11907 Feld[xx][yy] = EL_SP_TERMINAL_ACTIVE;
11910 else if (IS_BELT_SWITCH(element))
11912 ToggleBeltSwitch(x, y);
11914 else if (element == EL_SWITCHGATE_SWITCH_UP ||
11915 element == EL_SWITCHGATE_SWITCH_DOWN)
11917 ToggleSwitchgateSwitch(x, y);
11919 else if (element == EL_LIGHT_SWITCH ||
11920 element == EL_LIGHT_SWITCH_ACTIVE)
11922 ToggleLightSwitch(x, y);
11924 else if (element == EL_TIMEGATE_SWITCH)
11926 ActivateTimegateSwitch(x, y);
11928 else if (element == EL_BALLOON_SWITCH_LEFT ||
11929 element == EL_BALLOON_SWITCH_RIGHT ||
11930 element == EL_BALLOON_SWITCH_UP ||
11931 element == EL_BALLOON_SWITCH_DOWN ||
11932 element == EL_BALLOON_SWITCH_NONE ||
11933 element == EL_BALLOON_SWITCH_ANY)
11935 game.wind_direction = (element == EL_BALLOON_SWITCH_LEFT ? MV_LEFT :
11936 element == EL_BALLOON_SWITCH_RIGHT ? MV_RIGHT :
11937 element == EL_BALLOON_SWITCH_UP ? MV_UP :
11938 element == EL_BALLOON_SWITCH_DOWN ? MV_DOWN :
11939 element == EL_BALLOON_SWITCH_NONE ? MV_NONE :
11942 else if (element == EL_LAMP)
11944 Feld[x][y] = EL_LAMP_ACTIVE;
11945 local_player->lights_still_needed--;
11947 ResetGfxAnimation(x, y);
11948 DrawLevelField(x, y);
11950 else if (element == EL_TIME_ORB_FULL)
11952 Feld[x][y] = EL_TIME_ORB_EMPTY;
11954 if (level.time > 0 || level.use_time_orb_bug)
11956 TimeLeft += level.time_orb_time;
11957 DrawGameValue_Time(TimeLeft);
11960 ResetGfxAnimation(x, y);
11961 DrawLevelField(x, y);
11963 else if (element == EL_EMC_MAGIC_BALL_SWITCH ||
11964 element == EL_EMC_MAGIC_BALL_SWITCH_ACTIVE)
11968 game.ball_state = !game.ball_state;
11970 SCAN_PLAYFIELD(xx, yy)
11972 int e = Feld[xx][yy];
11974 if (game.ball_state)
11976 if (e == EL_EMC_MAGIC_BALL)
11977 CreateField(xx, yy, EL_EMC_MAGIC_BALL_ACTIVE);
11978 else if (e == EL_EMC_MAGIC_BALL_SWITCH)
11979 CreateField(xx, yy, EL_EMC_MAGIC_BALL_SWITCH_ACTIVE);
11983 if (e == EL_EMC_MAGIC_BALL_ACTIVE)
11984 CreateField(xx, yy, EL_EMC_MAGIC_BALL);
11985 else if (e == EL_EMC_MAGIC_BALL_SWITCH_ACTIVE)
11986 CreateField(xx, yy, EL_EMC_MAGIC_BALL_SWITCH);
11991 CheckTriggeredElementChangeByPlayer(x, y, element, CE_SWITCH_OF_X,
11992 player->index_bit, dig_side);
11994 CheckTriggeredElementChangeByPlayer(x, y, element, CE_PLAYER_SWITCHES_X,
11995 player->index_bit, dig_side);
11997 CheckTriggeredElementChangeByPlayer(x, y, element, CE_PLAYER_PRESSES_X,
11998 player->index_bit, dig_side);
12004 if (!PLAYER_SWITCHING(player, x, y))
12006 player->is_switching = TRUE;
12007 player->switch_x = x;
12008 player->switch_y = y;
12010 CheckElementChangeByPlayer(x, y, element, CE_SWITCHED,
12011 player->index_bit, dig_side);
12012 CheckTriggeredElementChangeByPlayer(x, y, element, CE_SWITCH_OF_X,
12013 player->index_bit, dig_side);
12015 CheckElementChangeByPlayer(x, y, element, CE_SWITCHED_BY_PLAYER,
12016 player->index_bit, dig_side);
12017 CheckTriggeredElementChangeByPlayer(x, y, element, CE_PLAYER_SWITCHES_X,
12018 player->index_bit, dig_side);
12021 CheckElementChangeByPlayer(x, y, element, CE_PRESSED_BY_PLAYER,
12022 player->index_bit, dig_side);
12023 CheckTriggeredElementChangeByPlayer(x, y, element, CE_PLAYER_PRESSES_X,
12024 player->index_bit, dig_side);
12026 return MP_NO_ACTION;
12029 player->push_delay = -1;
12031 if (is_player) /* function can also be called by EL_PENGUIN */
12033 if (Feld[x][y] != element) /* really digged/collected something */
12035 player->is_collecting = !player->is_digging;
12036 player->is_active = TRUE;
12043 boolean SnapField(struct PlayerInfo *player, int dx, int dy)
12045 int jx = player->jx, jy = player->jy;
12046 int x = jx + dx, y = jy + dy;
12047 int snap_direction = (dx == -1 ? MV_LEFT :
12048 dx == +1 ? MV_RIGHT :
12050 dy == +1 ? MV_DOWN : MV_NONE);
12051 boolean can_continue_snapping = (level.continuous_snapping &&
12052 WasJustFalling[x][y] < CHECK_DELAY_FALLING);
12054 if (player->MovPos != 0 && game.engine_version >= VERSION_IDENT(2,2,0,0))
12057 if (!player->active || !IN_LEV_FIELD(x, y))
12065 if (player->MovPos == 0)
12066 player->is_pushing = FALSE;
12068 player->is_snapping = FALSE;
12070 if (player->MovPos == 0)
12072 player->is_moving = FALSE;
12073 player->is_digging = FALSE;
12074 player->is_collecting = FALSE;
12080 #if USE_NEW_CONTINUOUS_SNAPPING
12081 /* prevent snapping with already pressed snap key when not allowed */
12082 if (player->is_snapping && !can_continue_snapping)
12085 if (player->is_snapping)
12089 player->MovDir = snap_direction;
12091 if (player->MovPos == 0)
12093 player->is_moving = FALSE;
12094 player->is_digging = FALSE;
12095 player->is_collecting = FALSE;
12098 player->is_dropping = FALSE;
12099 player->is_dropping_pressed = FALSE;
12100 player->drop_pressed_delay = 0;
12102 if (DigField(player, jx, jy, x, y, 0, 0, DF_SNAP) == MP_NO_ACTION)
12105 player->is_snapping = TRUE;
12106 player->is_active = TRUE;
12108 if (player->MovPos == 0)
12110 player->is_moving = FALSE;
12111 player->is_digging = FALSE;
12112 player->is_collecting = FALSE;
12115 if (player->MovPos != 0) /* prevent graphic bugs in versions < 2.2.0 */
12116 DrawLevelField(player->last_jx, player->last_jy);
12118 DrawLevelField(x, y);
12123 boolean DropElement(struct PlayerInfo *player)
12125 int old_element, new_element;
12126 int dropx = player->jx, dropy = player->jy;
12127 int drop_direction = player->MovDir;
12128 int drop_side = drop_direction;
12129 int drop_element = (player->inventory_size > 0 ?
12130 player->inventory_element[player->inventory_size - 1] :
12131 player->inventory_infinite_element != EL_UNDEFINED ?
12132 player->inventory_infinite_element :
12133 player->dynabombs_left > 0 ?
12134 EL_DYNABOMB_PLAYER_1_ACTIVE + player->index_nr :
12137 player->is_dropping_pressed = TRUE;
12139 /* do not drop an element on top of another element; when holding drop key
12140 pressed without moving, dropped element must move away before the next
12141 element can be dropped (this is especially important if the next element
12142 is dynamite, which can be placed on background for historical reasons) */
12143 if (PLAYER_DROPPING(player, dropx, dropy) && Feld[dropx][dropy] != EL_EMPTY)
12146 if (IS_THROWABLE(drop_element))
12148 dropx += GET_DX_FROM_DIR(drop_direction);
12149 dropy += GET_DY_FROM_DIR(drop_direction);
12151 if (!IN_LEV_FIELD(dropx, dropy))
12155 old_element = Feld[dropx][dropy]; /* old element at dropping position */
12156 new_element = drop_element; /* default: no change when dropping */
12158 /* check if player is active, not moving and ready to drop */
12159 if (!player->active || player->MovPos || player->drop_delay > 0)
12162 /* check if player has anything that can be dropped */
12163 if (new_element == EL_UNDEFINED)
12166 /* check if drop key was pressed long enough for EM style dynamite */
12167 if (new_element == EL_EM_DYNAMITE && player->drop_pressed_delay < 40)
12170 /* check if anything can be dropped at the current position */
12171 if (IS_ACTIVE_BOMB(old_element) || old_element == EL_EXPLOSION)
12174 /* collected custom elements can only be dropped on empty fields */
12175 if (IS_CUSTOM_ELEMENT(new_element) && old_element != EL_EMPTY)
12178 if (old_element != EL_EMPTY)
12179 Back[dropx][dropy] = old_element; /* store old element on this field */
12181 ResetGfxAnimation(dropx, dropy);
12182 ResetRandomAnimationValue(dropx, dropy);
12184 if (player->inventory_size > 0 ||
12185 player->inventory_infinite_element != EL_UNDEFINED)
12187 if (player->inventory_size > 0)
12189 player->inventory_size--;
12191 DrawGameDoorValues();
12193 if (new_element == EL_DYNAMITE)
12194 new_element = EL_DYNAMITE_ACTIVE;
12195 else if (new_element == EL_EM_DYNAMITE)
12196 new_element = EL_EM_DYNAMITE_ACTIVE;
12197 else if (new_element == EL_SP_DISK_RED)
12198 new_element = EL_SP_DISK_RED_ACTIVE;
12201 Feld[dropx][dropy] = new_element;
12203 if (IN_SCR_FIELD(SCREENX(dropx), SCREENY(dropy)))
12204 DrawGraphicThruMask(SCREENX(dropx), SCREENY(dropy),
12205 el2img(Feld[dropx][dropy]), 0);
12207 PlayLevelSoundAction(dropx, dropy, ACTION_DROPPING);
12209 /* needed if previous element just changed to "empty" in the last frame */
12210 ChangeCount[dropx][dropy] = 0; /* allow at least one more change */
12212 CheckElementChangeByPlayer(dropx, dropy, new_element, CE_DROPPED_BY_PLAYER,
12213 player->index_bit, drop_side);
12214 CheckTriggeredElementChangeByPlayer(dropx, dropy, new_element,
12216 player->index_bit, drop_side);
12218 TestIfElementTouchesCustomElement(dropx, dropy);
12220 else /* player is dropping a dyna bomb */
12222 player->dynabombs_left--;
12224 Feld[dropx][dropy] = new_element;
12226 if (IN_SCR_FIELD(SCREENX(dropx), SCREENY(dropy)))
12227 DrawGraphicThruMask(SCREENX(dropx), SCREENY(dropy),
12228 el2img(Feld[dropx][dropy]), 0);
12230 PlayLevelSoundAction(dropx, dropy, ACTION_DROPPING);
12233 if (Feld[dropx][dropy] == new_element) /* uninitialized unless CE change */
12234 InitField_WithBug1(dropx, dropy, FALSE);
12236 new_element = Feld[dropx][dropy]; /* element might have changed */
12238 if (IS_CUSTOM_ELEMENT(new_element) && CAN_MOVE(new_element) &&
12239 element_info[new_element].move_pattern == MV_WHEN_DROPPED)
12241 int move_direction, nextx, nexty;
12243 if (element_info[new_element].move_direction_initial == MV_START_AUTOMATIC)
12244 MovDir[dropx][dropy] = drop_direction;
12246 move_direction = MovDir[dropx][dropy];
12247 nextx = dropx + GET_DX_FROM_DIR(move_direction);
12248 nexty = dropy + GET_DY_FROM_DIR(move_direction);
12250 ChangeCount[dropx][dropy] = 0; /* allow at least one more change */
12252 #if USE_FIX_IMPACT_COLLISION
12253 /* do not cause impact style collision by dropping elements that can fall */
12254 CheckCollision[dropx][dropy] = CHECK_DELAY_COLLISION;
12256 CheckCollision[dropx][dropy] = CHECK_DELAY_COLLISION;
12260 player->drop_delay = GET_NEW_DROP_DELAY(drop_element);
12261 player->is_dropping = TRUE;
12263 player->drop_pressed_delay = 0;
12264 player->is_dropping_pressed = FALSE;
12266 player->drop_x = dropx;
12267 player->drop_y = dropy;
12272 /* ------------------------------------------------------------------------- */
12273 /* game sound playing functions */
12274 /* ------------------------------------------------------------------------- */
12276 static int *loop_sound_frame = NULL;
12277 static int *loop_sound_volume = NULL;
12279 void InitPlayLevelSound()
12281 int num_sounds = getSoundListSize();
12283 checked_free(loop_sound_frame);
12284 checked_free(loop_sound_volume);
12286 loop_sound_frame = checked_calloc(num_sounds * sizeof(int));
12287 loop_sound_volume = checked_calloc(num_sounds * sizeof(int));
12290 static void PlayLevelSound(int x, int y, int nr)
12292 int sx = SCREENX(x), sy = SCREENY(y);
12293 int volume, stereo_position;
12294 int max_distance = 8;
12295 int type = (IS_LOOP_SOUND(nr) ? SND_CTRL_PLAY_LOOP : SND_CTRL_PLAY_SOUND);
12297 if ((!setup.sound_simple && !IS_LOOP_SOUND(nr)) ||
12298 (!setup.sound_loops && IS_LOOP_SOUND(nr)))
12301 if (!IN_LEV_FIELD(x, y) ||
12302 sx < -max_distance || sx >= SCR_FIELDX + max_distance ||
12303 sy < -max_distance || sy >= SCR_FIELDY + max_distance)
12306 volume = SOUND_MAX_VOLUME;
12308 if (!IN_SCR_FIELD(sx, sy))
12310 int dx = ABS(sx - SCR_FIELDX / 2) - SCR_FIELDX / 2;
12311 int dy = ABS(sy - SCR_FIELDY / 2) - SCR_FIELDY / 2;
12313 volume -= volume * (dx > dy ? dx : dy) / max_distance;
12316 stereo_position = (SOUND_MAX_LEFT +
12317 (sx + max_distance) * SOUND_MAX_LEFT2RIGHT /
12318 (SCR_FIELDX + 2 * max_distance));
12320 if (IS_LOOP_SOUND(nr))
12322 /* This assures that quieter loop sounds do not overwrite louder ones,
12323 while restarting sound volume comparison with each new game frame. */
12325 if (loop_sound_volume[nr] > volume && loop_sound_frame[nr] == FrameCounter)
12328 loop_sound_volume[nr] = volume;
12329 loop_sound_frame[nr] = FrameCounter;
12332 PlaySoundExt(nr, volume, stereo_position, type);
12335 static void PlayLevelSoundNearest(int x, int y, int sound_action)
12337 PlayLevelSound(x < LEVELX(BX1) ? LEVELX(BX1) :
12338 x > LEVELX(BX2) ? LEVELX(BX2) : x,
12339 y < LEVELY(BY1) ? LEVELY(BY1) :
12340 y > LEVELY(BY2) ? LEVELY(BY2) : y,
12344 static void PlayLevelSoundAction(int x, int y, int action)
12346 PlayLevelSoundElementAction(x, y, Feld[x][y], action);
12349 static void PlayLevelSoundElementAction(int x, int y, int element, int action)
12351 int sound_effect = element_info[SND_ELEMENT(element)].sound[action];
12353 if (sound_effect != SND_UNDEFINED)
12354 PlayLevelSound(x, y, sound_effect);
12357 static void PlayLevelSoundElementActionIfLoop(int x, int y, int element,
12360 int sound_effect = element_info[SND_ELEMENT(element)].sound[action];
12362 if (sound_effect != SND_UNDEFINED && IS_LOOP_SOUND(sound_effect))
12363 PlayLevelSound(x, y, sound_effect);
12366 static void PlayLevelSoundActionIfLoop(int x, int y, int action)
12368 int sound_effect = element_info[SND_ELEMENT(Feld[x][y])].sound[action];
12370 if (sound_effect != SND_UNDEFINED && IS_LOOP_SOUND(sound_effect))
12371 PlayLevelSound(x, y, sound_effect);
12374 static void StopLevelSoundActionIfLoop(int x, int y, int action)
12376 int sound_effect = element_info[SND_ELEMENT(Feld[x][y])].sound[action];
12378 if (sound_effect != SND_UNDEFINED && IS_LOOP_SOUND(sound_effect))
12379 StopSound(sound_effect);
12382 static void PlayLevelMusic()
12384 if (levelset.music[level_nr] != MUS_UNDEFINED)
12385 PlayMusic(levelset.music[level_nr]); /* from config file */
12387 PlayMusic(MAP_NOCONF_MUSIC(level_nr)); /* from music dir */
12390 void PlayLevelSound_EM(int xx, int yy, int element_em, int sample)
12392 int element = (element_em > -1 ? map_element_EM_to_RND(element_em) : 0);
12393 int offset = (BorderElement == EL_STEELWALL ? 1 : 0);
12394 int x = xx - 1 - offset;
12395 int y = yy - 1 - offset;
12400 PlayLevelSoundElementAction(x, y, element, ACTION_WALKING);
12404 PlayLevelSoundElementAction(x, y, element, ACTION_PUSHING);
12408 PlayLevelSoundElementAction(x, y, element, ACTION_IMPACT);
12412 PlayLevelSoundElementAction(x, y, element, ACTION_IMPACT);
12416 PlayLevelSoundElementAction(x, y, element, ACTION_BREAKING);
12420 PlayLevelSoundElementAction(x, y, element, ACTION_MOVING);
12424 PlayLevelSoundElementAction(x, y, element, ACTION_MOVING);
12427 case SAMPLE_android_clone:
12428 PlayLevelSoundElementAction(x, y, element, ACTION_DROPPING);
12431 case SAMPLE_android_move:
12432 PlayLevelSoundElementAction(x, y, element, ACTION_MOVING);
12435 case SAMPLE_spring:
12436 PlayLevelSoundElementAction(x, y, element, ACTION_IMPACT);
12440 PlayLevelSoundElementAction(x, y, element, ACTION_EATING);
12444 PlayLevelSoundElementAction(x, y, element, ACTION_WAITING);
12447 case SAMPLE_eater_eat:
12448 PlayLevelSoundElementAction(x, y, element, ACTION_DIGGING);
12452 PlayLevelSoundElementAction(x, y, element, ACTION_MOVING);
12455 case SAMPLE_collect:
12456 PlayLevelSoundElementAction(x, y, element, ACTION_COLLECTING);
12459 case SAMPLE_diamond:
12460 PlayLevelSoundElementAction(x, y, element, ACTION_IMPACT);
12463 case SAMPLE_squash:
12464 /* !!! CHECK THIS !!! */
12466 PlayLevelSoundElementAction(x, y, element, ACTION_BREAKING);
12468 PlayLevelSoundElementAction(x, y, element, ACTION_SMASHED_BY_ROCK);
12472 case SAMPLE_wonderfall:
12473 PlayLevelSoundElementAction(x, y, element, ACTION_FILLING);
12477 PlayLevelSoundElementAction(x, y, element, ACTION_IMPACT);
12481 PlayLevelSoundElementAction(x, y, element, ACTION_PUSHING);
12485 PlayLevelSoundElementAction(x, y, element, ACTION_DIGGING);
12489 PlayLevelSoundElementAction(x, y, element, ACTION_SPLASHING);
12493 PlayLevelSoundElementAction(x, y, element, ACTION_DROPPING);
12497 PlayLevelSoundElementAction(x, y, element, ACTION_GROWING);
12500 case SAMPLE_wonder:
12501 PlayLevelSoundElementAction(x, y, element, ACTION_ACTIVE);
12505 PlayLevelSoundElementAction(x, y, element, ACTION_PASSING);
12508 case SAMPLE_exit_open:
12509 PlayLevelSoundElementAction(x, y, element, ACTION_OPENING);
12512 case SAMPLE_exit_leave:
12513 PlayLevelSoundElementAction(x, y, element, ACTION_PASSING);
12516 case SAMPLE_dynamite:
12517 PlayLevelSoundElementAction(x, y, element, ACTION_DROPPING);
12521 PlayLevelSoundElementAction(x, y, element, ACTION_ACTIVE);
12525 PlayLevelSoundElementAction(x, y, element, ACTION_ACTIVATING);
12529 PlayLevelSoundElementAction(x, y, element, ACTION_ACTIVE);
12533 PlayLevelSoundElementAction(x, y, element, ACTION_EXPLODING);
12537 PlayLevelSoundElementAction(x, y, element, ACTION_DYING);
12541 PlaySound(SND_GAME_RUNNING_OUT_OF_TIME);
12545 PlayLevelSoundElementAction(x, y, element, ACTION_DEFAULT);
12551 void ChangeTime(int value)
12553 int *time = (level.time == 0 ? &TimePlayed : &TimeLeft);
12557 /* EMC game engine uses value from time counter of RND game engine */
12558 level.native_em_level->lev->time = *time;
12560 DrawGameValue_Time(*time);
12563 void RaiseScore(int value)
12565 /* EMC game engine and RND game engine have separate score counters */
12566 int *score = (level.game_engine_type == GAME_ENGINE_TYPE_EM ?
12567 &level.native_em_level->lev->score : &local_player->score);
12571 DrawGameValue_Score(*score);
12575 void RaiseScore(int value)
12577 local_player->score += value;
12579 DrawGameValue_Score(local_player->score);
12582 void RaiseScoreElement(int element)
12587 case EL_BD_DIAMOND:
12588 case EL_EMERALD_YELLOW:
12589 case EL_EMERALD_RED:
12590 case EL_EMERALD_PURPLE:
12591 case EL_SP_INFOTRON:
12592 RaiseScore(level.score[SC_EMERALD]);
12595 RaiseScore(level.score[SC_DIAMOND]);
12598 RaiseScore(level.score[SC_CRYSTAL]);
12601 RaiseScore(level.score[SC_PEARL]);
12604 case EL_BD_BUTTERFLY:
12605 case EL_SP_ELECTRON:
12606 RaiseScore(level.score[SC_BUG]);
12609 case EL_BD_FIREFLY:
12610 case EL_SP_SNIKSNAK:
12611 RaiseScore(level.score[SC_SPACESHIP]);
12614 case EL_DARK_YAMYAM:
12615 RaiseScore(level.score[SC_YAMYAM]);
12618 RaiseScore(level.score[SC_ROBOT]);
12621 RaiseScore(level.score[SC_PACMAN]);
12624 RaiseScore(level.score[SC_NUT]);
12627 case EL_EM_DYNAMITE:
12628 case EL_SP_DISK_RED:
12629 case EL_DYNABOMB_INCREASE_NUMBER:
12630 case EL_DYNABOMB_INCREASE_SIZE:
12631 case EL_DYNABOMB_INCREASE_POWER:
12632 RaiseScore(level.score[SC_DYNAMITE]);
12634 case EL_SHIELD_NORMAL:
12635 case EL_SHIELD_DEADLY:
12636 RaiseScore(level.score[SC_SHIELD]);
12638 case EL_EXTRA_TIME:
12639 RaiseScore(level.extra_time_score);
12653 RaiseScore(level.score[SC_KEY]);
12656 RaiseScore(element_info[element].collect_score);
12661 void RequestQuitGameExt(boolean skip_request, boolean quick_quit, char *message)
12663 if (skip_request || Request(message, REQ_ASK | REQ_STAY_CLOSED))
12665 #if defined(NETWORK_AVALIABLE)
12666 if (options.network)
12667 SendToServer_StopPlaying(NETWORK_STOP_BY_PLAYER);
12673 game_status = GAME_MODE_MAIN;
12679 FadeOut(REDRAW_FIELD);
12681 game_status = GAME_MODE_MAIN;
12683 DrawAndFadeInMainMenu(REDRAW_FIELD);
12687 else /* continue playing the game */
12689 if (tape.playing && tape.deactivate_display)
12690 TapeDeactivateDisplayOff(TRUE);
12692 OpenDoor(DOOR_OPEN_1 | DOOR_COPY_BACK);
12694 if (tape.playing && tape.deactivate_display)
12695 TapeDeactivateDisplayOn();
12699 void RequestQuitGame(boolean ask_if_really_quit)
12701 boolean quick_quit = (!ask_if_really_quit || level_editor_test_game);
12702 boolean skip_request = AllPlayersGone || quick_quit;
12704 RequestQuitGameExt(skip_request, quick_quit,
12705 "Do you really want to quit the game ?");
12709 /* ------------------------------------------------------------------------- */
12710 /* random generator functions */
12711 /* ------------------------------------------------------------------------- */
12713 unsigned int InitEngineRandom_RND(long seed)
12715 game.num_random_calls = 0;
12718 unsigned int rnd_seed = InitEngineRandom(seed);
12720 printf("::: START RND: %d\n", rnd_seed);
12725 return InitEngineRandom(seed);
12731 unsigned int RND(int max)
12735 game.num_random_calls++;
12737 return GetEngineRandom(max);
12744 /* ------------------------------------------------------------------------- */
12745 /* game engine snapshot handling functions */
12746 /* ------------------------------------------------------------------------- */
12748 #define ARGS_ADDRESS_AND_SIZEOF(x) (&(x)), (sizeof(x))
12750 struct EngineSnapshotInfo
12752 /* runtime values for custom element collect score */
12753 int collect_score[NUM_CUSTOM_ELEMENTS];
12755 /* runtime values for group element choice position */
12756 int choice_pos[NUM_GROUP_ELEMENTS];
12758 /* runtime values for belt position animations */
12759 int belt_graphic[4 * NUM_BELT_PARTS];
12760 int belt_anim_mode[4 * NUM_BELT_PARTS];
12763 struct EngineSnapshotNodeInfo
12770 static struct EngineSnapshotInfo engine_snapshot_rnd;
12771 static ListNode *engine_snapshot_list = NULL;
12772 static char *snapshot_level_identifier = NULL;
12773 static int snapshot_level_nr = -1;
12775 void FreeEngineSnapshot()
12777 while (engine_snapshot_list != NULL)
12778 deleteNodeFromList(&engine_snapshot_list, engine_snapshot_list->key,
12781 setString(&snapshot_level_identifier, NULL);
12782 snapshot_level_nr = -1;
12785 static void SaveEngineSnapshotValues_RND()
12787 static int belt_base_active_element[4] =
12789 EL_CONVEYOR_BELT_1_LEFT_ACTIVE,
12790 EL_CONVEYOR_BELT_2_LEFT_ACTIVE,
12791 EL_CONVEYOR_BELT_3_LEFT_ACTIVE,
12792 EL_CONVEYOR_BELT_4_LEFT_ACTIVE
12796 for (i = 0; i < NUM_CUSTOM_ELEMENTS; i++)
12798 int element = EL_CUSTOM_START + i;
12800 engine_snapshot_rnd.collect_score[i] = element_info[element].collect_score;
12803 for (i = 0; i < NUM_GROUP_ELEMENTS; i++)
12805 int element = EL_GROUP_START + i;
12807 engine_snapshot_rnd.choice_pos[i] = element_info[element].group->choice_pos;
12810 for (i = 0; i < 4; i++)
12812 for (j = 0; j < NUM_BELT_PARTS; j++)
12814 int element = belt_base_active_element[i] + j;
12815 int graphic = el2img(element);
12816 int anim_mode = graphic_info[graphic].anim_mode;
12818 engine_snapshot_rnd.belt_graphic[i * 4 + j] = graphic;
12819 engine_snapshot_rnd.belt_anim_mode[i * 4 + j] = anim_mode;
12824 static void LoadEngineSnapshotValues_RND()
12826 unsigned long num_random_calls = game.num_random_calls;
12829 for (i = 0; i < NUM_CUSTOM_ELEMENTS; i++)
12831 int element = EL_CUSTOM_START + i;
12833 element_info[element].collect_score = engine_snapshot_rnd.collect_score[i];
12836 for (i = 0; i < NUM_GROUP_ELEMENTS; i++)
12838 int element = EL_GROUP_START + i;
12840 element_info[element].group->choice_pos = engine_snapshot_rnd.choice_pos[i];
12843 for (i = 0; i < 4; i++)
12845 for (j = 0; j < NUM_BELT_PARTS; j++)
12847 int graphic = engine_snapshot_rnd.belt_graphic[i * 4 + j];
12848 int anim_mode = engine_snapshot_rnd.belt_anim_mode[i * 4 + j];
12850 graphic_info[graphic].anim_mode = anim_mode;
12854 if (level.game_engine_type == GAME_ENGINE_TYPE_RND)
12856 InitRND(tape.random_seed);
12857 for (i = 0; i < num_random_calls; i++)
12861 if (game.num_random_calls != num_random_calls)
12863 Error(ERR_RETURN, "number of random calls out of sync");
12864 Error(ERR_RETURN, "number of random calls should be %d", num_random_calls);
12865 Error(ERR_RETURN, "number of random calls is %d", game.num_random_calls);
12866 Error(ERR_EXIT, "this should not happen -- please debug");
12870 static void SaveEngineSnapshotBuffer(void *buffer, int size)
12872 struct EngineSnapshotNodeInfo *bi =
12873 checked_calloc(sizeof(struct EngineSnapshotNodeInfo));
12875 bi->buffer_orig = buffer;
12876 bi->buffer_copy = checked_malloc(size);
12879 memcpy(bi->buffer_copy, buffer, size);
12881 addNodeToList(&engine_snapshot_list, NULL, bi);
12884 void SaveEngineSnapshot()
12886 FreeEngineSnapshot(); /* free previous snapshot, if needed */
12888 if (level_editor_test_game) /* do not save snapshots from editor */
12891 /* copy some special values to a structure better suited for the snapshot */
12893 SaveEngineSnapshotValues_RND();
12894 SaveEngineSnapshotValues_EM();
12896 /* save values stored in special snapshot structure */
12898 SaveEngineSnapshotBuffer(ARGS_ADDRESS_AND_SIZEOF(engine_snapshot_rnd));
12899 SaveEngineSnapshotBuffer(ARGS_ADDRESS_AND_SIZEOF(engine_snapshot_em));
12901 /* save further RND engine values */
12903 SaveEngineSnapshotBuffer(ARGS_ADDRESS_AND_SIZEOF(stored_player));
12904 SaveEngineSnapshotBuffer(ARGS_ADDRESS_AND_SIZEOF(game));
12905 SaveEngineSnapshotBuffer(ARGS_ADDRESS_AND_SIZEOF(tape));
12907 SaveEngineSnapshotBuffer(ARGS_ADDRESS_AND_SIZEOF(ZX));
12908 SaveEngineSnapshotBuffer(ARGS_ADDRESS_AND_SIZEOF(ZY));
12909 SaveEngineSnapshotBuffer(ARGS_ADDRESS_AND_SIZEOF(ExitX));
12910 SaveEngineSnapshotBuffer(ARGS_ADDRESS_AND_SIZEOF(ExitY));
12912 SaveEngineSnapshotBuffer(ARGS_ADDRESS_AND_SIZEOF(FrameCounter));
12913 SaveEngineSnapshotBuffer(ARGS_ADDRESS_AND_SIZEOF(TimeFrames));
12914 SaveEngineSnapshotBuffer(ARGS_ADDRESS_AND_SIZEOF(TimePlayed));
12915 SaveEngineSnapshotBuffer(ARGS_ADDRESS_AND_SIZEOF(TimeLeft));
12916 SaveEngineSnapshotBuffer(ARGS_ADDRESS_AND_SIZEOF(TapeTime));
12918 SaveEngineSnapshotBuffer(ARGS_ADDRESS_AND_SIZEOF(ScreenMovDir));
12919 SaveEngineSnapshotBuffer(ARGS_ADDRESS_AND_SIZEOF(ScreenMovPos));
12920 SaveEngineSnapshotBuffer(ARGS_ADDRESS_AND_SIZEOF(ScreenGfxPos));
12922 SaveEngineSnapshotBuffer(ARGS_ADDRESS_AND_SIZEOF(ScrollStepSize));
12924 SaveEngineSnapshotBuffer(ARGS_ADDRESS_AND_SIZEOF(AllPlayersGone));
12926 SaveEngineSnapshotBuffer(ARGS_ADDRESS_AND_SIZEOF(AmoebaCnt));
12927 SaveEngineSnapshotBuffer(ARGS_ADDRESS_AND_SIZEOF(AmoebaCnt2));
12929 SaveEngineSnapshotBuffer(ARGS_ADDRESS_AND_SIZEOF(Feld));
12930 SaveEngineSnapshotBuffer(ARGS_ADDRESS_AND_SIZEOF(MovPos));
12931 SaveEngineSnapshotBuffer(ARGS_ADDRESS_AND_SIZEOF(MovDir));
12932 SaveEngineSnapshotBuffer(ARGS_ADDRESS_AND_SIZEOF(MovDelay));
12933 SaveEngineSnapshotBuffer(ARGS_ADDRESS_AND_SIZEOF(ChangeDelay));
12934 SaveEngineSnapshotBuffer(ARGS_ADDRESS_AND_SIZEOF(ChangePage));
12935 SaveEngineSnapshotBuffer(ARGS_ADDRESS_AND_SIZEOF(CustomValue));
12936 SaveEngineSnapshotBuffer(ARGS_ADDRESS_AND_SIZEOF(Store));
12937 SaveEngineSnapshotBuffer(ARGS_ADDRESS_AND_SIZEOF(Store2));
12938 SaveEngineSnapshotBuffer(ARGS_ADDRESS_AND_SIZEOF(StorePlayer));
12939 SaveEngineSnapshotBuffer(ARGS_ADDRESS_AND_SIZEOF(Back));
12940 SaveEngineSnapshotBuffer(ARGS_ADDRESS_AND_SIZEOF(AmoebaNr));
12941 SaveEngineSnapshotBuffer(ARGS_ADDRESS_AND_SIZEOF(WasJustMoving));
12942 SaveEngineSnapshotBuffer(ARGS_ADDRESS_AND_SIZEOF(WasJustFalling));
12943 SaveEngineSnapshotBuffer(ARGS_ADDRESS_AND_SIZEOF(CheckCollision));
12944 SaveEngineSnapshotBuffer(ARGS_ADDRESS_AND_SIZEOF(CheckImpact));
12945 SaveEngineSnapshotBuffer(ARGS_ADDRESS_AND_SIZEOF(Stop));
12946 SaveEngineSnapshotBuffer(ARGS_ADDRESS_AND_SIZEOF(Pushed));
12948 SaveEngineSnapshotBuffer(ARGS_ADDRESS_AND_SIZEOF(ChangeCount));
12949 SaveEngineSnapshotBuffer(ARGS_ADDRESS_AND_SIZEOF(ChangeEvent));
12951 SaveEngineSnapshotBuffer(ARGS_ADDRESS_AND_SIZEOF(ExplodePhase));
12952 SaveEngineSnapshotBuffer(ARGS_ADDRESS_AND_SIZEOF(ExplodeDelay));
12953 SaveEngineSnapshotBuffer(ARGS_ADDRESS_AND_SIZEOF(ExplodeField));
12955 SaveEngineSnapshotBuffer(ARGS_ADDRESS_AND_SIZEOF(RunnerVisit));
12956 SaveEngineSnapshotBuffer(ARGS_ADDRESS_AND_SIZEOF(PlayerVisit));
12958 SaveEngineSnapshotBuffer(ARGS_ADDRESS_AND_SIZEOF(GfxFrame));
12959 SaveEngineSnapshotBuffer(ARGS_ADDRESS_AND_SIZEOF(GfxRandom));
12960 SaveEngineSnapshotBuffer(ARGS_ADDRESS_AND_SIZEOF(GfxElement));
12961 SaveEngineSnapshotBuffer(ARGS_ADDRESS_AND_SIZEOF(GfxAction));
12962 SaveEngineSnapshotBuffer(ARGS_ADDRESS_AND_SIZEOF(GfxDir));
12964 SaveEngineSnapshotBuffer(ARGS_ADDRESS_AND_SIZEOF(scroll_x));
12965 SaveEngineSnapshotBuffer(ARGS_ADDRESS_AND_SIZEOF(scroll_y));
12967 /* save level identification information */
12969 setString(&snapshot_level_identifier, leveldir_current->identifier);
12970 snapshot_level_nr = level_nr;
12973 ListNode *node = engine_snapshot_list;
12976 while (node != NULL)
12978 num_bytes += ((struct EngineSnapshotNodeInfo *)node->content)->size;
12983 printf("::: size of engine snapshot: %d bytes\n", num_bytes);
12987 static void LoadEngineSnapshotBuffer(struct EngineSnapshotNodeInfo *bi)
12989 memcpy(bi->buffer_orig, bi->buffer_copy, bi->size);
12992 void LoadEngineSnapshot()
12994 ListNode *node = engine_snapshot_list;
12996 if (engine_snapshot_list == NULL)
12999 while (node != NULL)
13001 LoadEngineSnapshotBuffer((struct EngineSnapshotNodeInfo *)node->content);
13006 /* restore special values from snapshot structure */
13008 LoadEngineSnapshotValues_RND();
13009 LoadEngineSnapshotValues_EM();
13012 boolean CheckEngineSnapshot()
13014 return (strEqual(snapshot_level_identifier, leveldir_current->identifier) &&
13015 snapshot_level_nr == level_nr);
13019 /* ---------- new game button stuff ---------------------------------------- */
13021 /* graphic position values for game buttons */
13022 #define GAME_BUTTON_XSIZE 30
13023 #define GAME_BUTTON_YSIZE 30
13024 #define GAME_BUTTON_XPOS 5
13025 #define GAME_BUTTON_YPOS 215
13026 #define SOUND_BUTTON_XPOS 5
13027 #define SOUND_BUTTON_YPOS (GAME_BUTTON_YPOS + GAME_BUTTON_YSIZE)
13029 #define GAME_BUTTON_STOP_XPOS (GAME_BUTTON_XPOS + 0 * GAME_BUTTON_XSIZE)
13030 #define GAME_BUTTON_PAUSE_XPOS (GAME_BUTTON_XPOS + 1 * GAME_BUTTON_XSIZE)
13031 #define GAME_BUTTON_PLAY_XPOS (GAME_BUTTON_XPOS + 2 * GAME_BUTTON_XSIZE)
13032 #define SOUND_BUTTON_MUSIC_XPOS (SOUND_BUTTON_XPOS + 0 * GAME_BUTTON_XSIZE)
13033 #define SOUND_BUTTON_LOOPS_XPOS (SOUND_BUTTON_XPOS + 1 * GAME_BUTTON_XSIZE)
13034 #define SOUND_BUTTON_SIMPLE_XPOS (SOUND_BUTTON_XPOS + 2 * GAME_BUTTON_XSIZE)
13041 } gamebutton_info[NUM_GAME_BUTTONS] =
13044 GAME_BUTTON_STOP_XPOS, GAME_BUTTON_YPOS,
13049 GAME_BUTTON_PAUSE_XPOS, GAME_BUTTON_YPOS,
13050 GAME_CTRL_ID_PAUSE,
13054 GAME_BUTTON_PLAY_XPOS, GAME_BUTTON_YPOS,
13059 SOUND_BUTTON_MUSIC_XPOS, SOUND_BUTTON_YPOS,
13060 SOUND_CTRL_ID_MUSIC,
13061 "background music on/off"
13064 SOUND_BUTTON_LOOPS_XPOS, SOUND_BUTTON_YPOS,
13065 SOUND_CTRL_ID_LOOPS,
13066 "sound loops on/off"
13069 SOUND_BUTTON_SIMPLE_XPOS, SOUND_BUTTON_YPOS,
13070 SOUND_CTRL_ID_SIMPLE,
13071 "normal sounds on/off"
13075 void CreateGameButtons()
13079 for (i = 0; i < NUM_GAME_BUTTONS; i++)
13081 Bitmap *gd_bitmap = graphic_info[IMG_GLOBAL_DOOR].bitmap;
13082 struct GadgetInfo *gi;
13085 unsigned long event_mask;
13086 int gd_xoffset, gd_yoffset;
13087 int gd_x1, gd_x2, gd_y1, gd_y2;
13090 gd_xoffset = gamebutton_info[i].x;
13091 gd_yoffset = gamebutton_info[i].y;
13092 gd_x1 = DOOR_GFX_PAGEX4 + gd_xoffset;
13093 gd_x2 = DOOR_GFX_PAGEX3 + gd_xoffset;
13095 if (id == GAME_CTRL_ID_STOP ||
13096 id == GAME_CTRL_ID_PAUSE ||
13097 id == GAME_CTRL_ID_PLAY)
13099 button_type = GD_TYPE_NORMAL_BUTTON;
13101 event_mask = GD_EVENT_RELEASED;
13102 gd_y1 = DOOR_GFX_PAGEY1 + gd_yoffset - GAME_BUTTON_YSIZE;
13103 gd_y2 = DOOR_GFX_PAGEY1 + gd_yoffset - GAME_BUTTON_YSIZE;
13107 button_type = GD_TYPE_CHECK_BUTTON;
13109 ((id == SOUND_CTRL_ID_MUSIC && setup.sound_music) ||
13110 (id == SOUND_CTRL_ID_LOOPS && setup.sound_loops) ||
13111 (id == SOUND_CTRL_ID_SIMPLE && setup.sound_simple) ? TRUE : FALSE);
13112 event_mask = GD_EVENT_PRESSED;
13113 gd_y1 = DOOR_GFX_PAGEY1 + gd_yoffset;
13114 gd_y2 = DOOR_GFX_PAGEY1 + gd_yoffset - GAME_BUTTON_YSIZE;
13117 gi = CreateGadget(GDI_CUSTOM_ID, id,
13118 GDI_INFO_TEXT, gamebutton_info[i].infotext,
13119 GDI_X, DX + gd_xoffset,
13120 GDI_Y, DY + gd_yoffset,
13121 GDI_WIDTH, GAME_BUTTON_XSIZE,
13122 GDI_HEIGHT, GAME_BUTTON_YSIZE,
13123 GDI_TYPE, button_type,
13124 GDI_STATE, GD_BUTTON_UNPRESSED,
13125 GDI_CHECKED, checked,
13126 GDI_DESIGN_UNPRESSED, gd_bitmap, gd_x1, gd_y1,
13127 GDI_DESIGN_PRESSED, gd_bitmap, gd_x2, gd_y1,
13128 GDI_ALT_DESIGN_UNPRESSED, gd_bitmap, gd_x1, gd_y2,
13129 GDI_ALT_DESIGN_PRESSED, gd_bitmap, gd_x2, gd_y2,
13130 GDI_EVENT_MASK, event_mask,
13131 GDI_CALLBACK_ACTION, HandleGameButtons,
13135 Error(ERR_EXIT, "cannot create gadget");
13137 game_gadget[id] = gi;
13141 void FreeGameButtons()
13145 for (i = 0; i < NUM_GAME_BUTTONS; i++)
13146 FreeGadget(game_gadget[i]);
13149 static void MapGameButtons()
13153 for (i = 0; i < NUM_GAME_BUTTONS; i++)
13154 MapGadget(game_gadget[i]);
13157 void UnmapGameButtons()
13161 for (i = 0; i < NUM_GAME_BUTTONS; i++)
13162 UnmapGadget(game_gadget[i]);
13165 static void HandleGameButtons(struct GadgetInfo *gi)
13167 int id = gi->custom_id;
13169 if (game_status != GAME_MODE_PLAYING)
13174 case GAME_CTRL_ID_STOP:
13178 RequestQuitGame(TRUE);
13181 case GAME_CTRL_ID_PAUSE:
13182 if (options.network)
13184 #if defined(NETWORK_AVALIABLE)
13186 SendToServer_ContinuePlaying();
13188 SendToServer_PausePlaying();
13192 TapeTogglePause(TAPE_TOGGLE_MANUAL);
13195 case GAME_CTRL_ID_PLAY:
13198 #if defined(NETWORK_AVALIABLE)
13199 if (options.network)
13200 SendToServer_ContinuePlaying();
13204 tape.pausing = FALSE;
13205 DrawVideoDisplay(VIDEO_STATE_PAUSE_OFF, 0);
13210 case SOUND_CTRL_ID_MUSIC:
13211 if (setup.sound_music)
13213 setup.sound_music = FALSE;
13216 else if (audio.music_available)
13218 setup.sound = setup.sound_music = TRUE;
13220 SetAudioMode(setup.sound);
13226 case SOUND_CTRL_ID_LOOPS:
13227 if (setup.sound_loops)
13228 setup.sound_loops = FALSE;
13229 else if (audio.loops_available)
13231 setup.sound = setup.sound_loops = TRUE;
13232 SetAudioMode(setup.sound);
13236 case SOUND_CTRL_ID_SIMPLE:
13237 if (setup.sound_simple)
13238 setup.sound_simple = FALSE;
13239 else if (audio.sound_available)
13241 setup.sound = setup.sound_simple = TRUE;
13242 SetAudioMode(setup.sound);