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)
62 /* for MovePlayer() */
63 #define MP_NO_ACTION 0
66 #define MP_DONT_RUN_INTO (MP_MOVING | MP_ACTION)
68 /* for ScrollPlayer() */
70 #define SCROLL_GO_ON 1
72 /* for Bang()/Explode() */
73 #define EX_PHASE_START 0
74 #define EX_TYPE_NONE 0
75 #define EX_TYPE_NORMAL (1 << 0)
76 #define EX_TYPE_CENTER (1 << 1)
77 #define EX_TYPE_BORDER (1 << 2)
78 #define EX_TYPE_CROSS (1 << 3)
79 #define EX_TYPE_DYNA (1 << 4)
80 #define EX_TYPE_SINGLE_TILE (EX_TYPE_CENTER | EX_TYPE_BORDER)
82 #define PANEL_DEACTIVATED(p) ((p).x < 0 || (p).y < 0)
84 /* special positions in the game control window (relative to control window) */
85 #define XX_LEVEL1 (game.panel.level.x)
86 #define XX_LEVEL2 (game.panel.level.x - 1)
87 #define YY_LEVEL (game.panel.level.y)
88 #define XX_EMERALDS (game.panel.gems.x)
89 #define YY_EMERALDS (game.panel.gems.y)
90 #define XX_DYNAMITE (game.panel.inventory.x)
91 #define YY_DYNAMITE (game.panel.inventory.y)
92 #define XX_KEYS (game.panel.keys.x)
93 #define YY_KEYS (game.panel.keys.y)
94 #define XX_SCORE (game.panel.score.x)
95 #define YY_SCORE (game.panel.score.y)
96 #define XX_TIME1 (game.panel.time.x)
97 #define XX_TIME2 (game.panel.time.x + 1)
98 #define YY_TIME (game.panel.time.y)
100 /* special positions in the game control window (relative to main window) */
101 #define DX_LEVEL1 (DX + XX_LEVEL1)
102 #define DX_LEVEL2 (DX + XX_LEVEL2)
103 #define DY_LEVEL (DY + YY_LEVEL)
104 #define DX_EMERALDS (DX + XX_EMERALDS)
105 #define DY_EMERALDS (DY + YY_EMERALDS)
106 #define DX_DYNAMITE (DX + XX_DYNAMITE)
107 #define DY_DYNAMITE (DY + YY_DYNAMITE)
108 #define DX_KEYS (DX + XX_KEYS)
109 #define DY_KEYS (DY + YY_KEYS)
110 #define DX_SCORE (DX + XX_SCORE)
111 #define DY_SCORE (DY + YY_SCORE)
112 #define DX_TIME1 (DX + XX_TIME1)
113 #define DX_TIME2 (DX + XX_TIME2)
114 #define DY_TIME (DY + YY_TIME)
116 /* values for delayed check of falling and moving elements and for collision */
117 #define CHECK_DELAY_MOVING 3
118 #define CHECK_DELAY_FALLING 3
119 #define CHECK_DELAY_COLLISION 2
121 /* values for initial player move delay (initial delay counter value) */
122 #define INITIAL_MOVE_DELAY_OFF -1
123 #define INITIAL_MOVE_DELAY_ON 0
125 /* values for player movement speed (which is in fact a delay value) */
126 #define MOVE_DELAY_MIN_SPEED 32
127 #define MOVE_DELAY_NORMAL_SPEED 8
128 #define MOVE_DELAY_HIGH_SPEED 4
129 #define MOVE_DELAY_MAX_SPEED 1
131 #define DOUBLE_MOVE_DELAY(x) (x = (x < MOVE_DELAY_MIN_SPEED ? x * 2 : x))
132 #define HALVE_MOVE_DELAY(x) (x = (x > MOVE_DELAY_MAX_SPEED ? x / 2 : x))
134 #define DOUBLE_PLAYER_SPEED(p) (HALVE_MOVE_DELAY( (p)->move_delay_value))
135 #define HALVE_PLAYER_SPEED(p) (DOUBLE_MOVE_DELAY((p)->move_delay_value))
137 /* values for other actions */
138 #define MOVE_STEPSIZE_NORMAL (TILEX / MOVE_DELAY_NORMAL_SPEED)
139 #define MOVE_STEPSIZE_MIN (1)
140 #define MOVE_STEPSIZE_MAX (TILEX)
142 #define GET_DX_FROM_DIR(d) ((d) == MV_LEFT ? -1 : (d) == MV_RIGHT ? 1 : 0)
143 #define GET_DY_FROM_DIR(d) ((d) == MV_UP ? -1 : (d) == MV_DOWN ? 1 : 0)
145 #define INIT_GFX_RANDOM() (SimpleRND(1000000))
147 #define GET_NEW_PUSH_DELAY(e) ( (element_info[e].push_delay_fixed) + \
148 RND(element_info[e].push_delay_random))
149 #define GET_NEW_DROP_DELAY(e) ( (element_info[e].drop_delay_fixed) + \
150 RND(element_info[e].drop_delay_random))
151 #define GET_NEW_MOVE_DELAY(e) ( (element_info[e].move_delay_fixed) + \
152 RND(element_info[e].move_delay_random))
153 #define GET_MAX_MOVE_DELAY(e) ( (element_info[e].move_delay_fixed) + \
154 (element_info[e].move_delay_random))
155 #define GET_NEW_CE_VALUE(e) ( (element_info[e].ce_value_fixed_initial) +\
156 RND(element_info[e].ce_value_random_initial))
157 #define GET_CE_SCORE(e) ( (element_info[e].collect_score))
158 #define GET_CHANGE_DELAY(c) ( ((c)->delay_fixed * (c)->delay_frames) + \
159 RND((c)->delay_random * (c)->delay_frames))
160 #define GET_CE_DELAY_VALUE(c) ( ((c)->delay_fixed) + \
161 RND((c)->delay_random))
164 #define GET_VALID_RUNTIME_ELEMENT(e) \
165 ((e) >= NUM_RUNTIME_ELEMENTS ? EL_UNKNOWN : (e))
167 #define RESOLVED_REFERENCE_ELEMENT(be, e) \
168 ((be) + (e) - EL_SELF < EL_CUSTOM_START ? EL_CUSTOM_START : \
169 (be) + (e) - EL_SELF > EL_CUSTOM_END ? EL_CUSTOM_END : \
170 (be) + (e) - EL_SELF)
172 #define GET_TARGET_ELEMENT(be, e, ch, cv, cs) \
173 ((e) == EL_TRIGGER_PLAYER ? (ch)->actual_trigger_player : \
174 (e) == EL_TRIGGER_ELEMENT ? (ch)->actual_trigger_element : \
175 (e) == EL_TRIGGER_CE_VALUE ? (ch)->actual_trigger_ce_value : \
176 (e) == EL_TRIGGER_CE_SCORE ? (ch)->actual_trigger_ce_score : \
177 (e) == EL_CURRENT_CE_VALUE ? (cv) : \
178 (e) == EL_CURRENT_CE_SCORE ? (cs) : \
179 (e) >= EL_LAST_CE_8 && (e) <= EL_NEXT_CE_8 ? \
180 RESOLVED_REFERENCE_ELEMENT(be, e) : \
183 #define CAN_GROW_INTO(e) \
184 ((e) == EL_SAND || (IS_DIGGABLE(e) && level.grow_into_diggable))
186 #define ELEMENT_CAN_ENTER_FIELD_BASE_X(x, y, condition) \
187 (IN_LEV_FIELD(x, y) && (IS_FREE(x, y) || \
190 #define ELEMENT_CAN_ENTER_FIELD_BASE_2(e, x, y, condition) \
191 (IN_LEV_FIELD(x, y) && (IS_FREE(x, y) || \
192 (CAN_MOVE_INTO_ACID(e) && \
193 Feld[x][y] == EL_ACID) || \
196 #define ELEMENT_CAN_ENTER_FIELD_BASE_3(e, x, y, condition) \
197 (IN_LEV_FIELD(x, y) && (IS_FREE_OR_PLAYER(x, y) || \
198 (CAN_MOVE_INTO_ACID(e) && \
199 Feld[x][y] == EL_ACID) || \
202 #define ELEMENT_CAN_ENTER_FIELD_BASE_4(e, x, y, condition) \
203 (IN_LEV_FIELD(x, y) && (IS_FREE(x, y) || \
205 (CAN_MOVE_INTO_ACID(e) && \
206 Feld[x][y] == EL_ACID) || \
207 (DONT_COLLIDE_WITH(e) && \
209 !PLAYER_ENEMY_PROTECTED(x, y))))
211 #define ELEMENT_CAN_ENTER_FIELD(e, x, y) \
212 ELEMENT_CAN_ENTER_FIELD_BASE_4(e, x, y, 0)
214 #define SATELLITE_CAN_ENTER_FIELD(x, y) \
215 ELEMENT_CAN_ENTER_FIELD_BASE_2(EL_SATELLITE, x, y, 0)
217 #define ANDROID_CAN_ENTER_FIELD(e, x, y) \
218 ELEMENT_CAN_ENTER_FIELD_BASE_2(e, x, y, Feld[x][y] == EL_EMC_PLANT)
220 #define ANDROID_CAN_CLONE_FIELD(x, y) \
221 (IN_LEV_FIELD(x, y) && (CAN_BE_CLONED_BY_ANDROID(Feld[x][y]) || \
222 CAN_BE_CLONED_BY_ANDROID(EL_TRIGGER_ELEMENT)))
224 #define ENEMY_CAN_ENTER_FIELD(e, x, y) \
225 ELEMENT_CAN_ENTER_FIELD_BASE_2(e, x, y, 0)
227 #define YAMYAM_CAN_ENTER_FIELD(e, x, y) \
228 ELEMENT_CAN_ENTER_FIELD_BASE_3(e, x, y, Feld[x][y] == EL_DIAMOND)
230 #define DARK_YAMYAM_CAN_ENTER_FIELD(e, x, y) \
231 ELEMENT_CAN_ENTER_FIELD_BASE_3(e, x,y, IS_FOOD_DARK_YAMYAM(Feld[x][y]))
233 #define PACMAN_CAN_ENTER_FIELD(e, x, y) \
234 ELEMENT_CAN_ENTER_FIELD_BASE_3(e, x, y, IS_AMOEBOID(Feld[x][y]))
236 #define PIG_CAN_ENTER_FIELD(e, x, y) \
237 ELEMENT_CAN_ENTER_FIELD_BASE_2(e, x, y, IS_FOOD_PIG(Feld[x][y]))
239 #define PENGUIN_CAN_ENTER_FIELD(e, x, y) \
240 ELEMENT_CAN_ENTER_FIELD_BASE_2(e, x, y, (Feld[x][y] == EL_EXIT_OPEN ||\
241 IS_FOOD_PENGUIN(Feld[x][y])))
242 #define DRAGON_CAN_ENTER_FIELD(e, x, y) \
243 ELEMENT_CAN_ENTER_FIELD_BASE_2(e, x, y, 0)
245 #define MOLE_CAN_ENTER_FIELD(e, x, y, condition) \
246 ELEMENT_CAN_ENTER_FIELD_BASE_2(e, x, y, (condition))
248 #define SPRING_CAN_ENTER_FIELD(e, x, y) \
249 ELEMENT_CAN_ENTER_FIELD_BASE_2(e, x, y, 0)
251 #define SPRING_CAN_BUMP_FROM_FIELD(x, y) \
252 (IN_LEV_FIELD(x, y) && (Feld[x][y] == EL_EMC_SPRING_BUMPER || \
253 Feld[x][y] == EL_EMC_SPRING_BUMPER_ACTIVE))
255 #define MOVE_ENTER_EL(e) (element_info[e].move_enter_element)
257 #define CE_ENTER_FIELD_COND(e, x, y) \
258 (!IS_PLAYER(x, y) && \
259 IS_EQUAL_OR_IN_GROUP(Feld[x][y], MOVE_ENTER_EL(e)))
261 #define CUSTOM_ELEMENT_CAN_ENTER_FIELD(e, x, y) \
262 ELEMENT_CAN_ENTER_FIELD_BASE_4(e, x, y, CE_ENTER_FIELD_COND(e, x, y))
264 #define IN_LEV_FIELD_AND_IS_FREE(x, y) (IN_LEV_FIELD(x, y) && IS_FREE(x, y))
265 #define IN_LEV_FIELD_AND_NOT_FREE(x, y) (IN_LEV_FIELD(x, y) && !IS_FREE(x, y))
267 #define ACCESS_FROM(e, d) (element_info[e].access_direction &(d))
268 #define IS_WALKABLE_FROM(e, d) (IS_WALKABLE(e) && ACCESS_FROM(e, d))
269 #define IS_PASSABLE_FROM(e, d) (IS_PASSABLE(e) && ACCESS_FROM(e, d))
270 #define IS_ACCESSIBLE_FROM(e, d) (IS_ACCESSIBLE(e) && ACCESS_FROM(e, d))
272 /* game button identifiers */
273 #define GAME_CTRL_ID_STOP 0
274 #define GAME_CTRL_ID_PAUSE 1
275 #define GAME_CTRL_ID_PLAY 2
276 #define SOUND_CTRL_ID_MUSIC 3
277 #define SOUND_CTRL_ID_LOOPS 4
278 #define SOUND_CTRL_ID_SIMPLE 5
280 #define NUM_GAME_BUTTONS 6
283 /* forward declaration for internal use */
285 static void CreateField(int, int, int);
287 static void SetPlayerWaiting(struct PlayerInfo *, boolean);
288 static void AdvanceFrameAndPlayerCounters(int);
290 static boolean MovePlayerOneStep(struct PlayerInfo *, int, int, int, int);
291 static boolean MovePlayer(struct PlayerInfo *, int, int);
292 static void ScrollPlayer(struct PlayerInfo *, int);
293 static void ScrollScreen(struct PlayerInfo *, int);
295 int DigField(struct PlayerInfo *, int, int, int, int, int, int, int);
297 static void InitBeltMovement(void);
298 static void CloseAllOpenTimegates(void);
299 static void CheckGravityMovement(struct PlayerInfo *);
300 static void CheckGravityMovementWhenNotMoving(struct PlayerInfo *);
301 static void KillPlayerUnlessEnemyProtected(int, int);
302 static void KillPlayerUnlessExplosionProtected(int, int);
304 static void TestIfPlayerTouchesCustomElement(int, int);
305 static void TestIfElementTouchesCustomElement(int, int);
306 static void TestIfElementHitsCustomElement(int, int, int);
308 static void TestIfElementSmashesCustomElement(int, int, int);
311 static void HandleElementChange(int, int, int);
312 static void ExecuteCustomElementAction(int, int, int, int);
313 static boolean ChangeElement(int, int, int, int);
315 static boolean CheckTriggeredElementChangeExt(int, int, int, int, int,int,int);
316 #define CheckTriggeredElementChange(x, y, e, ev) \
317 CheckTriggeredElementChangeExt(x,y,e,ev, CH_PLAYER_ANY,CH_SIDE_ANY, -1)
318 #define CheckTriggeredElementChangeByPlayer(x, y, e, ev, p, s) \
319 CheckTriggeredElementChangeExt(x, y, e, ev, p, s, -1)
320 #define CheckTriggeredElementChangeBySide(x, y, e, ev, s) \
321 CheckTriggeredElementChangeExt(x, y, e, ev, CH_PLAYER_ANY, s, -1)
322 #define CheckTriggeredElementChangeByPage(x, y, e, ev, p) \
323 CheckTriggeredElementChangeExt(x,y,e,ev, CH_PLAYER_ANY, CH_SIDE_ANY, p)
325 static boolean CheckElementChangeExt(int, int, int, int, int, int, int);
326 #define CheckElementChange(x, y, e, te, ev) \
327 CheckElementChangeExt(x, y, e, te, ev, CH_PLAYER_ANY, CH_SIDE_ANY)
328 #define CheckElementChangeByPlayer(x, y, e, ev, p, s) \
329 CheckElementChangeExt(x, y, e, EL_EMPTY, ev, p, s)
330 #define CheckElementChangeBySide(x, y, e, te, ev, s) \
331 CheckElementChangeExt(x, y, e, te, ev, CH_PLAYER_ANY, s)
333 static void PlayLevelSound(int, int, int);
334 static void PlayLevelSoundNearest(int, int, int);
335 static void PlayLevelSoundAction(int, int, int);
336 static void PlayLevelSoundElementAction(int, int, int, int);
337 static void PlayLevelSoundElementActionIfLoop(int, int, int, int);
338 static void PlayLevelSoundActionIfLoop(int, int, int);
339 static void StopLevelSoundActionIfLoop(int, int, int);
340 static void PlayLevelMusic();
342 static void MapGameButtons();
343 static void HandleGameButtons(struct GadgetInfo *);
345 int AmoebeNachbarNr(int, int);
346 void AmoebeUmwandeln(int, int);
347 void ContinueMoving(int, int);
349 void InitMovDir(int, int);
350 void InitAmoebaNr(int, int);
351 int NewHiScore(void);
353 void TestIfGoodThingHitsBadThing(int, int, int);
354 void TestIfBadThingHitsGoodThing(int, int, int);
355 void TestIfPlayerTouchesBadThing(int, int);
356 void TestIfPlayerRunsIntoBadThing(int, int, int);
357 void TestIfBadThingTouchesPlayer(int, int);
358 void TestIfBadThingRunsIntoPlayer(int, int, int);
359 void TestIfFriendTouchesBadThing(int, int);
360 void TestIfBadThingTouchesFriend(int, int);
361 void TestIfBadThingTouchesOtherBadThing(int, int);
363 void KillPlayer(struct PlayerInfo *);
364 void BuryPlayer(struct PlayerInfo *);
365 void RemovePlayer(struct PlayerInfo *);
367 boolean SnapField(struct PlayerInfo *, int, int);
368 boolean DropElement(struct PlayerInfo *);
370 static int getInvisibleActiveFromInvisibleElement(int);
371 static int getInvisibleFromInvisibleActiveElement(int);
373 static struct GadgetInfo *game_gadget[NUM_GAME_BUTTONS];
376 /* ------------------------------------------------------------------------- */
377 /* definition of elements that automatically change to other elements after */
378 /* a specified time, eventually calling a function when changing */
379 /* ------------------------------------------------------------------------- */
381 /* forward declaration for changer functions */
382 static void InitBuggyBase(int, int);
383 static void WarnBuggyBase(int, int);
385 static void InitTrap(int, int);
386 static void ActivateTrap(int, int);
387 static void ChangeActiveTrap(int, int);
389 static void InitRobotWheel(int, int);
390 static void RunRobotWheel(int, int);
391 static void StopRobotWheel(int, int);
393 static void InitTimegateWheel(int, int);
394 static void RunTimegateWheel(int, int);
396 static void InitMagicBallDelay(int, int);
397 static void ActivateMagicBall(int, int);
399 struct ChangingElementInfo
404 void (*pre_change_function)(int x, int y);
405 void (*change_function)(int x, int y);
406 void (*post_change_function)(int x, int y);
409 static struct ChangingElementInfo change_delay_list[] =
460 EL_SWITCHGATE_OPENING,
468 EL_SWITCHGATE_CLOSING,
469 EL_SWITCHGATE_CLOSED,
501 EL_ACID_SPLASH_RIGHT,
510 EL_SP_BUGGY_BASE_ACTIVATING,
517 EL_SP_BUGGY_BASE_ACTIVATING,
518 EL_SP_BUGGY_BASE_ACTIVE,
525 EL_SP_BUGGY_BASE_ACTIVE,
549 EL_ROBOT_WHEEL_ACTIVE,
557 EL_TIMEGATE_SWITCH_ACTIVE,
565 EL_EMC_MAGIC_BALL_ACTIVE,
566 EL_EMC_MAGIC_BALL_ACTIVE,
573 EL_EMC_SPRING_BUMPER_ACTIVE,
574 EL_EMC_SPRING_BUMPER,
581 EL_DIAGONAL_SHRINKING,
610 int push_delay_fixed, push_delay_random;
615 { EL_BALLOON, 0, 0 },
617 { EL_SOKOBAN_OBJECT, 2, 0 },
618 { EL_SOKOBAN_FIELD_FULL, 2, 0 },
619 { EL_SATELLITE, 2, 0 },
620 { EL_SP_DISK_YELLOW, 2, 0 },
622 { EL_UNDEFINED, 0, 0 },
630 move_stepsize_list[] =
632 { EL_AMOEBA_DROP, 2 },
633 { EL_AMOEBA_DROPPING, 2 },
634 { EL_QUICKSAND_FILLING, 1 },
635 { EL_QUICKSAND_EMPTYING, 1 },
636 { EL_MAGIC_WALL_FILLING, 2 },
637 { EL_BD_MAGIC_WALL_FILLING, 2 },
638 { EL_MAGIC_WALL_EMPTYING, 2 },
639 { EL_BD_MAGIC_WALL_EMPTYING, 2 },
649 collect_count_list[] =
652 { EL_BD_DIAMOND, 1 },
653 { EL_EMERALD_YELLOW, 1 },
654 { EL_EMERALD_RED, 1 },
655 { EL_EMERALD_PURPLE, 1 },
657 { EL_SP_INFOTRON, 1 },
669 access_direction_list[] =
671 { EL_TUBE_ANY, MV_LEFT | MV_RIGHT | MV_UP | MV_DOWN },
672 { EL_TUBE_VERTICAL, MV_UP | MV_DOWN },
673 { EL_TUBE_HORIZONTAL, MV_LEFT | MV_RIGHT },
674 { EL_TUBE_VERTICAL_LEFT, MV_LEFT | MV_UP | MV_DOWN },
675 { EL_TUBE_VERTICAL_RIGHT, MV_RIGHT | MV_UP | MV_DOWN },
676 { EL_TUBE_HORIZONTAL_UP, MV_LEFT | MV_RIGHT | MV_UP },
677 { EL_TUBE_HORIZONTAL_DOWN, MV_LEFT | MV_RIGHT | MV_DOWN },
678 { EL_TUBE_LEFT_UP, MV_LEFT | MV_UP },
679 { EL_TUBE_LEFT_DOWN, MV_LEFT | MV_DOWN },
680 { EL_TUBE_RIGHT_UP, MV_RIGHT | MV_UP },
681 { EL_TUBE_RIGHT_DOWN, MV_RIGHT | MV_DOWN },
683 { EL_SP_PORT_LEFT, MV_RIGHT },
684 { EL_SP_PORT_RIGHT, MV_LEFT },
685 { EL_SP_PORT_UP, MV_DOWN },
686 { EL_SP_PORT_DOWN, MV_UP },
687 { EL_SP_PORT_HORIZONTAL, MV_LEFT | MV_RIGHT },
688 { EL_SP_PORT_VERTICAL, MV_UP | MV_DOWN },
689 { EL_SP_PORT_ANY, MV_LEFT | MV_RIGHT | MV_UP | MV_DOWN },
690 { EL_SP_GRAVITY_PORT_LEFT, MV_RIGHT },
691 { EL_SP_GRAVITY_PORT_RIGHT, MV_LEFT },
692 { EL_SP_GRAVITY_PORT_UP, MV_DOWN },
693 { EL_SP_GRAVITY_PORT_DOWN, MV_UP },
694 { EL_SP_GRAVITY_ON_PORT_LEFT, MV_RIGHT },
695 { EL_SP_GRAVITY_ON_PORT_RIGHT, MV_LEFT },
696 { EL_SP_GRAVITY_ON_PORT_UP, MV_DOWN },
697 { EL_SP_GRAVITY_ON_PORT_DOWN, MV_UP },
698 { EL_SP_GRAVITY_OFF_PORT_LEFT, MV_RIGHT },
699 { EL_SP_GRAVITY_OFF_PORT_RIGHT, MV_LEFT },
700 { EL_SP_GRAVITY_OFF_PORT_UP, MV_DOWN },
701 { EL_SP_GRAVITY_OFF_PORT_DOWN, MV_UP },
703 { EL_UNDEFINED, MV_NONE }
706 static boolean trigger_events[MAX_NUM_ELEMENTS][NUM_CHANGE_EVENTS];
708 #define IS_AUTO_CHANGING(e) (element_info[e].has_change_event[CE_DELAY])
709 #define IS_JUST_CHANGING(x, y) (ChangeDelay[x][y] != 0)
710 #define IS_CHANGING(x, y) (IS_AUTO_CHANGING(Feld[x][y]) || \
711 IS_JUST_CHANGING(x, y))
713 #define CE_PAGE(e, ce) (element_info[e].event_page[ce])
715 /* static variables for playfield scan mode (scanning forward or backward) */
716 static int playfield_scan_start_x = 0;
717 static int playfield_scan_start_y = 0;
718 static int playfield_scan_delta_x = 1;
719 static int playfield_scan_delta_y = 1;
721 #define SCAN_PLAYFIELD(x, y) for ((y) = playfield_scan_start_y; \
722 (y) >= 0 && (y) <= lev_fieldy - 1; \
723 (y) += playfield_scan_delta_y) \
724 for ((x) = playfield_scan_start_x; \
725 (x) >= 0 && (x) <= lev_fieldx - 1; \
726 (x) += playfield_scan_delta_x) \
729 void DEBUG_SetMaximumDynamite()
733 for (i = 0; i < MAX_INVENTORY_SIZE; i++)
734 if (local_player->inventory_size < MAX_INVENTORY_SIZE)
735 local_player->inventory_element[local_player->inventory_size++] =
740 static void InitPlayfieldScanModeVars()
742 if (game.use_reverse_scan_direction)
744 playfield_scan_start_x = lev_fieldx - 1;
745 playfield_scan_start_y = lev_fieldy - 1;
747 playfield_scan_delta_x = -1;
748 playfield_scan_delta_y = -1;
752 playfield_scan_start_x = 0;
753 playfield_scan_start_y = 0;
755 playfield_scan_delta_x = 1;
756 playfield_scan_delta_y = 1;
760 static void InitPlayfieldScanMode(int mode)
762 game.use_reverse_scan_direction =
763 (mode == CA_ARG_SCAN_MODE_REVERSE ? TRUE : FALSE);
765 InitPlayfieldScanModeVars();
768 static int get_move_delay_from_stepsize(int move_stepsize)
771 MIN(MAX(MOVE_STEPSIZE_MIN, move_stepsize), MOVE_STEPSIZE_MAX);
773 /* make sure that stepsize value is always a power of 2 */
774 move_stepsize = (1 << log_2(move_stepsize));
776 return TILEX / move_stepsize;
779 static void SetPlayerMoveSpeed(struct PlayerInfo *player, int move_stepsize,
782 int player_nr = player->index_nr;
783 int move_delay = get_move_delay_from_stepsize(move_stepsize);
784 boolean cannot_move = (move_stepsize == STEPSIZE_NOT_MOVING ? TRUE : FALSE);
786 /* do no immediately change move delay -- the player might just be moving */
787 player->move_delay_value_next = move_delay;
789 /* information if player can move must be set separately */
790 player->cannot_move = cannot_move;
794 player->move_delay = game.initial_move_delay[player_nr];
795 player->move_delay_value = game.initial_move_delay_value[player_nr];
797 player->move_delay_value_next = -1;
799 player->move_delay_reset_counter = 0;
803 void GetPlayerConfig()
805 if (!audio.sound_available)
806 setup.sound_simple = FALSE;
808 if (!audio.loops_available)
809 setup.sound_loops = FALSE;
811 if (!audio.music_available)
812 setup.sound_music = FALSE;
814 if (!video.fullscreen_available)
815 setup.fullscreen = FALSE;
817 setup.sound = (setup.sound_simple || setup.sound_loops || setup.sound_music);
819 SetAudioMode(setup.sound);
823 static int getBeltNrFromBeltElement(int element)
825 return (element < EL_CONVEYOR_BELT_2_LEFT ? 0 :
826 element < EL_CONVEYOR_BELT_3_LEFT ? 1 :
827 element < EL_CONVEYOR_BELT_4_LEFT ? 2 : 3);
830 static int getBeltNrFromBeltActiveElement(int element)
832 return (element < EL_CONVEYOR_BELT_2_LEFT_ACTIVE ? 0 :
833 element < EL_CONVEYOR_BELT_3_LEFT_ACTIVE ? 1 :
834 element < EL_CONVEYOR_BELT_4_LEFT_ACTIVE ? 2 : 3);
837 static int getBeltNrFromBeltSwitchElement(int element)
839 return (element < EL_CONVEYOR_BELT_2_SWITCH_LEFT ? 0 :
840 element < EL_CONVEYOR_BELT_3_SWITCH_LEFT ? 1 :
841 element < EL_CONVEYOR_BELT_4_SWITCH_LEFT ? 2 : 3);
844 static int getBeltDirNrFromBeltSwitchElement(int element)
846 static int belt_base_element[4] =
848 EL_CONVEYOR_BELT_1_SWITCH_LEFT,
849 EL_CONVEYOR_BELT_2_SWITCH_LEFT,
850 EL_CONVEYOR_BELT_3_SWITCH_LEFT,
851 EL_CONVEYOR_BELT_4_SWITCH_LEFT
854 int belt_nr = getBeltNrFromBeltSwitchElement(element);
855 int belt_dir_nr = element - belt_base_element[belt_nr];
857 return (belt_dir_nr % 3);
860 static int getBeltDirFromBeltSwitchElement(int element)
862 static int belt_move_dir[3] =
869 int belt_dir_nr = getBeltDirNrFromBeltSwitchElement(element);
871 return belt_move_dir[belt_dir_nr];
874 static int get_element_from_group_element(int element)
876 if (IS_GROUP_ELEMENT(element))
878 struct ElementGroupInfo *group = element_info[element].group;
879 int last_anim_random_frame = gfx.anim_random_frame;
882 if (group->choice_mode == ANIM_RANDOM)
883 gfx.anim_random_frame = RND(group->num_elements_resolved);
885 element_pos = getAnimationFrame(group->num_elements_resolved, 1,
886 group->choice_mode, 0,
889 if (group->choice_mode == ANIM_RANDOM)
890 gfx.anim_random_frame = last_anim_random_frame;
894 element = group->element_resolved[element_pos];
900 static void InitPlayerField(int x, int y, int element, boolean init_game)
902 if (element == EL_SP_MURPHY)
906 if (stored_player[0].present)
908 Feld[x][y] = EL_SP_MURPHY_CLONE;
914 stored_player[0].use_murphy = TRUE;
916 if (!level.use_artwork_element[0])
917 stored_player[0].artwork_element = EL_SP_MURPHY;
920 Feld[x][y] = EL_PLAYER_1;
926 struct PlayerInfo *player = &stored_player[Feld[x][y] - EL_PLAYER_1];
927 int jx = player->jx, jy = player->jy;
929 player->present = TRUE;
931 player->block_last_field = (element == EL_SP_MURPHY ?
932 level.sp_block_last_field :
933 level.block_last_field);
935 /* ---------- initialize player's last field block delay --------------- */
937 /* always start with reliable default value (no adjustment needed) */
938 player->block_delay_adjustment = 0;
940 /* special case 1: in Supaplex, Murphy blocks last field one more frame */
941 if (player->block_last_field && element == EL_SP_MURPHY)
942 player->block_delay_adjustment = 1;
944 /* special case 2: in game engines before 3.1.1, blocking was different */
945 if (game.use_block_last_field_bug)
946 player->block_delay_adjustment = (player->block_last_field ? -1 : 1);
948 if (!options.network || player->connected)
950 player->active = TRUE;
952 /* remove potentially duplicate players */
953 if (StorePlayer[jx][jy] == Feld[x][y])
954 StorePlayer[jx][jy] = 0;
956 StorePlayer[x][y] = Feld[x][y];
960 printf("Player %d activated.\n", player->element_nr);
961 printf("[Local player is %d and currently %s.]\n",
962 local_player->element_nr,
963 local_player->active ? "active" : "not active");
967 Feld[x][y] = EL_EMPTY;
969 player->jx = player->last_jx = x;
970 player->jy = player->last_jy = y;
974 static void InitField(int x, int y, boolean init_game)
976 int element = Feld[x][y];
985 InitPlayerField(x, y, element, init_game);
988 case EL_SOKOBAN_FIELD_PLAYER:
989 element = Feld[x][y] = EL_PLAYER_1;
990 InitField(x, y, init_game);
992 element = Feld[x][y] = EL_SOKOBAN_FIELD_EMPTY;
993 InitField(x, y, init_game);
996 case EL_SOKOBAN_FIELD_EMPTY:
997 local_player->sokobanfields_still_needed++;
1001 if (x < lev_fieldx-1 && Feld[x+1][y] == EL_ACID)
1002 Feld[x][y] = EL_ACID_POOL_TOPLEFT;
1003 else if (x > 0 && Feld[x-1][y] == EL_ACID)
1004 Feld[x][y] = EL_ACID_POOL_TOPRIGHT;
1005 else if (y > 0 && Feld[x][y-1] == EL_ACID_POOL_TOPLEFT)
1006 Feld[x][y] = EL_ACID_POOL_BOTTOMLEFT;
1007 else if (y > 0 && Feld[x][y-1] == EL_ACID)
1008 Feld[x][y] = EL_ACID_POOL_BOTTOM;
1009 else if (y > 0 && Feld[x][y-1] == EL_ACID_POOL_TOPRIGHT)
1010 Feld[x][y] = EL_ACID_POOL_BOTTOMRIGHT;
1019 case EL_SPACESHIP_RIGHT:
1020 case EL_SPACESHIP_UP:
1021 case EL_SPACESHIP_LEFT:
1022 case EL_SPACESHIP_DOWN:
1023 case EL_BD_BUTTERFLY:
1024 case EL_BD_BUTTERFLY_RIGHT:
1025 case EL_BD_BUTTERFLY_UP:
1026 case EL_BD_BUTTERFLY_LEFT:
1027 case EL_BD_BUTTERFLY_DOWN:
1029 case EL_BD_FIREFLY_RIGHT:
1030 case EL_BD_FIREFLY_UP:
1031 case EL_BD_FIREFLY_LEFT:
1032 case EL_BD_FIREFLY_DOWN:
1033 case EL_PACMAN_RIGHT:
1035 case EL_PACMAN_LEFT:
1036 case EL_PACMAN_DOWN:
1038 case EL_YAMYAM_LEFT:
1039 case EL_YAMYAM_RIGHT:
1041 case EL_YAMYAM_DOWN:
1042 case EL_DARK_YAMYAM:
1045 case EL_SP_SNIKSNAK:
1046 case EL_SP_ELECTRON:
1055 case EL_AMOEBA_FULL:
1060 case EL_AMOEBA_DROP:
1061 if (y == lev_fieldy - 1)
1063 Feld[x][y] = EL_AMOEBA_GROWING;
1064 Store[x][y] = EL_AMOEBA_WET;
1068 case EL_DYNAMITE_ACTIVE:
1069 case EL_SP_DISK_RED_ACTIVE:
1070 case EL_DYNABOMB_PLAYER_1_ACTIVE:
1071 case EL_DYNABOMB_PLAYER_2_ACTIVE:
1072 case EL_DYNABOMB_PLAYER_3_ACTIVE:
1073 case EL_DYNABOMB_PLAYER_4_ACTIVE:
1074 MovDelay[x][y] = 96;
1077 case EL_EM_DYNAMITE_ACTIVE:
1078 MovDelay[x][y] = 32;
1082 local_player->lights_still_needed++;
1086 local_player->friends_still_needed++;
1091 GfxDir[x][y] = MovDir[x][y] = 1 << RND(4);
1094 case EL_CONVEYOR_BELT_1_SWITCH_LEFT:
1095 case EL_CONVEYOR_BELT_1_SWITCH_MIDDLE:
1096 case EL_CONVEYOR_BELT_1_SWITCH_RIGHT:
1097 case EL_CONVEYOR_BELT_2_SWITCH_LEFT:
1098 case EL_CONVEYOR_BELT_2_SWITCH_MIDDLE:
1099 case EL_CONVEYOR_BELT_2_SWITCH_RIGHT:
1100 case EL_CONVEYOR_BELT_3_SWITCH_LEFT:
1101 case EL_CONVEYOR_BELT_3_SWITCH_MIDDLE:
1102 case EL_CONVEYOR_BELT_3_SWITCH_RIGHT:
1103 case EL_CONVEYOR_BELT_4_SWITCH_LEFT:
1104 case EL_CONVEYOR_BELT_4_SWITCH_MIDDLE:
1105 case EL_CONVEYOR_BELT_4_SWITCH_RIGHT:
1108 int belt_nr = getBeltNrFromBeltSwitchElement(Feld[x][y]);
1109 int belt_dir = getBeltDirFromBeltSwitchElement(Feld[x][y]);
1110 int belt_dir_nr = getBeltDirNrFromBeltSwitchElement(Feld[x][y]);
1112 if (game.belt_dir_nr[belt_nr] == 3) /* initial value */
1114 game.belt_dir[belt_nr] = belt_dir;
1115 game.belt_dir_nr[belt_nr] = belt_dir_nr;
1117 else /* more than one switch -- set it like the first switch */
1119 Feld[x][y] = Feld[x][y] - belt_dir_nr + game.belt_dir_nr[belt_nr];
1124 #if !USE_BOTH_SWITCHGATE_SWITCHES
1125 case EL_SWITCHGATE_SWITCH_DOWN: /* always start with same switch pos */
1127 Feld[x][y] = EL_SWITCHGATE_SWITCH_UP;
1131 case EL_LIGHT_SWITCH_ACTIVE:
1133 game.light_time_left = level.time_light * FRAMES_PER_SECOND;
1136 case EL_INVISIBLE_STEELWALL:
1137 case EL_INVISIBLE_WALL:
1138 case EL_INVISIBLE_SAND:
1139 if (game.light_time_left > 0 ||
1140 game.lenses_time_left > 0)
1141 Feld[x][y] = getInvisibleActiveFromInvisibleElement(element);
1144 case EL_EMC_MAGIC_BALL:
1145 if (game.ball_state)
1146 Feld[x][y] = EL_EMC_MAGIC_BALL_ACTIVE;
1149 case EL_EMC_MAGIC_BALL_SWITCH:
1150 if (game.ball_state)
1151 Feld[x][y] = EL_EMC_MAGIC_BALL_SWITCH_ACTIVE;
1155 if (IS_CUSTOM_ELEMENT(element))
1157 if (CAN_MOVE(element))
1160 #if USE_NEW_CUSTOM_VALUE
1161 if (!element_info[element].use_last_ce_value || init_game)
1162 CustomValue[x][y] = GET_NEW_CE_VALUE(Feld[x][y]);
1165 else if (IS_GROUP_ELEMENT(element))
1167 Feld[x][y] = get_element_from_group_element(element);
1169 InitField(x, y, init_game);
1176 CheckTriggeredElementChange(x, y, element, CE_CREATION_OF_X);
1179 static inline void InitField_WithBug1(int x, int y, boolean init_game)
1181 InitField(x, y, init_game);
1183 /* not needed to call InitMovDir() -- already done by InitField()! */
1184 if (game.engine_version < VERSION_IDENT(3,1,0,0) &&
1185 CAN_MOVE(Feld[x][y]))
1189 static inline void InitField_WithBug2(int x, int y, boolean init_game)
1191 int old_element = Feld[x][y];
1193 InitField(x, y, init_game);
1195 /* not needed to call InitMovDir() -- already done by InitField()! */
1196 if (game.engine_version < VERSION_IDENT(3,1,0,0) &&
1197 CAN_MOVE(old_element) &&
1198 (old_element < EL_MOLE_LEFT || old_element > EL_MOLE_DOWN))
1201 /* this case is in fact a combination of not less than three bugs:
1202 first, it calls InitMovDir() for elements that can move, although this is
1203 already done by InitField(); then, it checks the element that was at this
1204 field _before_ the call to InitField() (which can change it); lastly, it
1205 was not called for "mole with direction" elements, which were treated as
1206 "cannot move" due to (fixed) wrong element initialization in "src/init.c"
1210 inline void DrawGameValue_Emeralds(int value)
1212 int xpos = (3 * 14 - 3 * getFontWidth(FONT_TEXT_2)) / 2;
1214 if (PANEL_DEACTIVATED(game.panel.gems))
1217 DrawText(DX_EMERALDS + xpos, DY_EMERALDS, int2str(value, 3), FONT_TEXT_2);
1220 inline void DrawGameValue_Dynamite(int value)
1222 int xpos = (3 * 14 - 3 * getFontWidth(FONT_TEXT_2)) / 2;
1224 if (PANEL_DEACTIVATED(game.panel.inventory))
1227 DrawText(DX_DYNAMITE + xpos, DY_DYNAMITE, int2str(value, 3), FONT_TEXT_2);
1230 inline void DrawGameValue_Keys(int key[MAX_NUM_KEYS])
1232 int base_key_graphic = EL_KEY_1;
1235 if (PANEL_DEACTIVATED(game.panel.keys))
1238 if (level.game_engine_type == GAME_ENGINE_TYPE_EM)
1239 base_key_graphic = EL_EM_KEY_1;
1241 /* currently only 4 of 8 possible keys are displayed */
1242 for (i = 0; i < STD_NUM_KEYS; i++)
1244 int x = XX_KEYS + i * MINI_TILEX;
1248 DrawMiniGraphicExt(drawto, DX + x,DY + y, el2edimg(base_key_graphic + i));
1250 BlitBitmap(graphic_info[IMG_GLOBAL_DOOR].bitmap, drawto,
1251 DOOR_GFX_PAGEX5 + x, y, MINI_TILEX, MINI_TILEY, DX + x,DY + y);
1255 inline void DrawGameValue_Score(int value)
1257 int xpos = (5 * 14 - 5 * getFontWidth(FONT_TEXT_2)) / 2;
1259 if (PANEL_DEACTIVATED(game.panel.score))
1262 DrawText(DX_SCORE + xpos, DY_SCORE, int2str(value, 5), FONT_TEXT_2);
1265 inline void DrawGameValue_Time(int value)
1267 int xpos3 = (3 * 14 - 3 * getFontWidth(FONT_TEXT_2)) / 2;
1268 int xpos4 = (4 * 10 - 4 * getFontWidth(FONT_LEVEL_NUMBER)) / 2;
1270 if (PANEL_DEACTIVATED(game.panel.time))
1273 /* clear background if value just changed its size */
1274 if (value == 999 || value == 1000)
1275 ClearRectangleOnBackground(drawto, DX_TIME1, DY_TIME, 14 * 3, 14);
1278 DrawText(DX_TIME1 + xpos3, DY_TIME, int2str(value, 3), FONT_TEXT_2);
1280 DrawText(DX_TIME2 + xpos4, DY_TIME, int2str(value, 4), FONT_LEVEL_NUMBER);
1283 inline void DrawGameValue_Level(int value)
1285 if (PANEL_DEACTIVATED(game.panel.level))
1289 DrawText(DX_LEVEL1, DY_LEVEL, int2str(value, 2), FONT_TEXT_2);
1291 DrawText(DX_LEVEL2, DY_LEVEL, int2str(value, 3), FONT_LEVEL_NUMBER);
1294 void DrawAllGameValues(int emeralds, int dynamite, int score, int time,
1297 int key[MAX_NUM_KEYS];
1300 /* prevent EM engine from updating time/score values parallel to GameWon() */
1301 if (level.game_engine_type == GAME_ENGINE_TYPE_EM &&
1302 local_player->LevelSolved)
1305 for (i = 0; i < MAX_NUM_KEYS; i++)
1306 key[i] = key_bits & (1 << i);
1308 DrawGameValue_Level(level_nr);
1310 DrawGameValue_Emeralds(emeralds);
1311 DrawGameValue_Dynamite(dynamite);
1312 DrawGameValue_Score(score);
1313 DrawGameValue_Time(time);
1315 DrawGameValue_Keys(key);
1318 void DrawGameDoorValues()
1320 int time_value = (level.time == 0 ? TimePlayed : TimeLeft);
1321 int dynamite_value = 0;
1322 int score_value = (local_player->LevelSolved ? local_player->score_final :
1323 local_player->score);
1324 int gems_value = local_player->gems_still_needed;
1328 if (level.game_engine_type == GAME_ENGINE_TYPE_EM)
1330 DrawGameDoorValues_EM();
1335 if (game.centered_player_nr == -1)
1337 for (i = 0; i < MAX_PLAYERS; i++)
1339 for (j = 0; j < MAX_NUM_KEYS; j++)
1340 if (stored_player[i].key[j])
1341 key_bits |= (1 << j);
1343 dynamite_value += stored_player[i].inventory_size;
1348 int player_nr = game.centered_player_nr;
1350 for (i = 0; i < MAX_NUM_KEYS; i++)
1351 if (stored_player[player_nr].key[i])
1352 key_bits |= (1 << i);
1354 dynamite_value = stored_player[player_nr].inventory_size;
1357 DrawAllGameValues(gems_value, dynamite_value, score_value, time_value,
1363 =============================================================================
1365 -----------------------------------------------------------------------------
1366 initialize game engine due to level / tape version number
1367 =============================================================================
1370 static void InitGameEngine()
1372 int i, j, k, l, x, y;
1374 /* set game engine from tape file when re-playing, else from level file */
1375 game.engine_version = (tape.playing ? tape.engine_version :
1376 level.game_version);
1378 /* ---------------------------------------------------------------------- */
1379 /* set flags for bugs and changes according to active game engine version */
1380 /* ---------------------------------------------------------------------- */
1383 Summary of bugfix/change:
1384 Fixed handling for custom elements that change when pushed by the player.
1386 Fixed/changed in version:
1390 Before 3.1.0, custom elements that "change when pushing" changed directly
1391 after the player started pushing them (until then handled in "DigField()").
1392 Since 3.1.0, these custom elements are not changed until the "pushing"
1393 move of the element is finished (now handled in "ContinueMoving()").
1395 Affected levels/tapes:
1396 The first condition is generally needed for all levels/tapes before version
1397 3.1.0, which might use the old behaviour before it was changed; known tapes
1398 that are affected are some tapes from the level set "Walpurgis Gardens" by
1400 The second condition is an exception from the above case and is needed for
1401 the special case of tapes recorded with game (not engine!) version 3.1.0 or
1402 above (including some development versions of 3.1.0), but before it was
1403 known that this change would break tapes like the above and was fixed in
1404 3.1.1, so that the changed behaviour was active although the engine version
1405 while recording maybe was before 3.1.0. There is at least one tape that is
1406 affected by this exception, which is the tape for the one-level set "Bug
1407 Machine" by Juergen Bonhagen.
1410 game.use_change_when_pushing_bug =
1411 (game.engine_version < VERSION_IDENT(3,1,0,0) &&
1413 tape.game_version >= VERSION_IDENT(3,1,0,0) &&
1414 tape.game_version < VERSION_IDENT(3,1,1,0)));
1417 Summary of bugfix/change:
1418 Fixed handling for blocking the field the player leaves when moving.
1420 Fixed/changed in version:
1424 Before 3.1.1, when "block last field when moving" was enabled, the field
1425 the player is leaving when moving was blocked for the time of the move,
1426 and was directly unblocked afterwards. This resulted in the last field
1427 being blocked for exactly one less than the number of frames of one player
1428 move. Additionally, even when blocking was disabled, the last field was
1429 blocked for exactly one frame.
1430 Since 3.1.1, due to changes in player movement handling, the last field
1431 is not blocked at all when blocking is disabled. When blocking is enabled,
1432 the last field is blocked for exactly the number of frames of one player
1433 move. Additionally, if the player is Murphy, the hero of Supaplex, the
1434 last field is blocked for exactly one more than the number of frames of
1437 Affected levels/tapes:
1438 (!!! yet to be determined -- probably many !!!)
1441 game.use_block_last_field_bug =
1442 (game.engine_version < VERSION_IDENT(3,1,1,0));
1445 Summary of bugfix/change:
1446 Changed behaviour of CE changes with multiple changes per single frame.
1448 Fixed/changed in version:
1452 Before 3.2.0-6, only one single CE change was allowed in each engine frame.
1453 This resulted in race conditions where CEs seem to behave strange in some
1454 situations (where triggered CE changes were just skipped because there was
1455 already a CE change on that tile in the playfield in that engine frame).
1456 Since 3.2.0-6, this was changed to allow up to MAX_NUM_CHANGES_PER_FRAME.
1457 (The number of changes per frame must be limited in any case, because else
1458 it is easily possible to define CE changes that would result in an infinite
1459 loop, causing the whole game to freeze. The MAX_NUM_CHANGES_PER_FRAME value
1460 should be set large enough so that it would only be reached in cases where
1461 the corresponding CE change conditions run into a loop. Therefore, it seems
1462 to be reasonable to set MAX_NUM_CHANGES_PER_FRAME to the same value as the
1463 maximal number of change pages for custom elements.)
1465 Affected levels/tapes:
1469 #if USE_ONLY_ONE_CHANGE_PER_FRAME
1470 game.max_num_changes_per_frame = 1;
1472 game.max_num_changes_per_frame =
1473 (game.engine_version < VERSION_IDENT(3,2,0,6) ? 1 : 32);
1476 /* ---------------------------------------------------------------------- */
1478 /* default scan direction: scan playfield from top/left to bottom/right */
1479 InitPlayfieldScanMode(CA_ARG_SCAN_MODE_NORMAL);
1481 /* dynamically adjust element properties according to game engine version */
1482 InitElementPropertiesEngine(game.engine_version);
1485 printf("level %d: level version == %06d\n", level_nr, level.game_version);
1486 printf(" tape version == %06d [%s] [file: %06d]\n",
1487 tape.engine_version, (tape.playing ? "PLAYING" : "RECORDING"),
1489 printf(" => game.engine_version == %06d\n", game.engine_version);
1492 /* ---------- initialize player's initial move delay --------------------- */
1494 /* dynamically adjust player properties according to level information */
1495 for (i = 0; i < MAX_PLAYERS; i++)
1496 game.initial_move_delay_value[i] =
1497 get_move_delay_from_stepsize(level.initial_player_stepsize[i]);
1499 /* dynamically adjust player properties according to game engine version */
1500 for (i = 0; i < MAX_PLAYERS; i++)
1501 game.initial_move_delay[i] =
1502 (game.engine_version <= VERSION_IDENT(2,0,1,0) ?
1503 game.initial_move_delay_value[i] : 0);
1505 /* ---------- initialize player's initial push delay --------------------- */
1507 /* dynamically adjust player properties according to game engine version */
1508 game.initial_push_delay_value =
1509 (game.engine_version < VERSION_IDENT(3,0,7,1) ? 5 : -1);
1511 /* ---------- initialize changing elements ------------------------------- */
1513 /* initialize changing elements information */
1514 for (i = 0; i < MAX_NUM_ELEMENTS; i++)
1516 struct ElementInfo *ei = &element_info[i];
1518 /* this pointer might have been changed in the level editor */
1519 ei->change = &ei->change_page[0];
1521 if (!IS_CUSTOM_ELEMENT(i))
1523 ei->change->target_element = EL_EMPTY_SPACE;
1524 ei->change->delay_fixed = 0;
1525 ei->change->delay_random = 0;
1526 ei->change->delay_frames = 1;
1529 for (j = 0; j < NUM_CHANGE_EVENTS; j++)
1531 ei->has_change_event[j] = FALSE;
1533 ei->event_page_nr[j] = 0;
1534 ei->event_page[j] = &ei->change_page[0];
1538 /* add changing elements from pre-defined list */
1539 for (i = 0; change_delay_list[i].element != EL_UNDEFINED; i++)
1541 struct ChangingElementInfo *ch_delay = &change_delay_list[i];
1542 struct ElementInfo *ei = &element_info[ch_delay->element];
1544 ei->change->target_element = ch_delay->target_element;
1545 ei->change->delay_fixed = ch_delay->change_delay;
1547 ei->change->pre_change_function = ch_delay->pre_change_function;
1548 ei->change->change_function = ch_delay->change_function;
1549 ei->change->post_change_function = ch_delay->post_change_function;
1551 ei->change->can_change = TRUE;
1552 ei->change->can_change_or_has_action = TRUE;
1554 ei->has_change_event[CE_DELAY] = TRUE;
1556 SET_PROPERTY(ch_delay->element, EP_CAN_CHANGE, TRUE);
1557 SET_PROPERTY(ch_delay->element, EP_CAN_CHANGE_OR_HAS_ACTION, TRUE);
1560 /* ---------- initialize internal run-time variables ------------- */
1562 for (i = 0; i < NUM_CUSTOM_ELEMENTS; i++)
1564 struct ElementInfo *ei = &element_info[EL_CUSTOM_START + i];
1566 for (j = 0; j < ei->num_change_pages; j++)
1568 ei->change_page[j].can_change_or_has_action =
1569 (ei->change_page[j].can_change |
1570 ei->change_page[j].has_action);
1574 /* add change events from custom element configuration */
1575 for (i = 0; i < NUM_CUSTOM_ELEMENTS; i++)
1577 struct ElementInfo *ei = &element_info[EL_CUSTOM_START + i];
1579 for (j = 0; j < ei->num_change_pages; j++)
1581 if (!ei->change_page[j].can_change_or_has_action)
1584 for (k = 0; k < NUM_CHANGE_EVENTS; k++)
1586 /* only add event page for the first page found with this event */
1587 if (ei->change_page[j].has_event[k] && !(ei->has_change_event[k]))
1589 ei->has_change_event[k] = TRUE;
1591 ei->event_page_nr[k] = j;
1592 ei->event_page[k] = &ei->change_page[j];
1598 /* ---------- initialize run-time trigger player and element ------------- */
1600 for (i = 0; i < NUM_CUSTOM_ELEMENTS; i++)
1602 struct ElementInfo *ei = &element_info[EL_CUSTOM_START + i];
1604 for (j = 0; j < ei->num_change_pages; j++)
1606 ei->change_page[j].actual_trigger_element = EL_EMPTY;
1607 ei->change_page[j].actual_trigger_player = EL_PLAYER_1;
1608 ei->change_page[j].actual_trigger_side = CH_SIDE_NONE;
1609 ei->change_page[j].actual_trigger_ce_value = 0;
1610 ei->change_page[j].actual_trigger_ce_score = 0;
1614 /* ---------- initialize trigger events ---------------------------------- */
1616 /* initialize trigger events information */
1617 for (i = 0; i < MAX_NUM_ELEMENTS; i++)
1618 for (j = 0; j < NUM_CHANGE_EVENTS; j++)
1619 trigger_events[i][j] = FALSE;
1621 /* add trigger events from element change event properties */
1622 for (i = 0; i < MAX_NUM_ELEMENTS; i++)
1624 struct ElementInfo *ei = &element_info[i];
1626 for (j = 0; j < ei->num_change_pages; j++)
1628 if (!ei->change_page[j].can_change_or_has_action)
1631 if (ei->change_page[j].has_event[CE_BY_OTHER_ACTION])
1633 int trigger_element = ei->change_page[j].trigger_element;
1635 for (k = 0; k < NUM_CHANGE_EVENTS; k++)
1637 if (ei->change_page[j].has_event[k])
1639 if (IS_GROUP_ELEMENT(trigger_element))
1641 struct ElementGroupInfo *group =
1642 element_info[trigger_element].group;
1644 for (l = 0; l < group->num_elements_resolved; l++)
1645 trigger_events[group->element_resolved[l]][k] = TRUE;
1647 else if (trigger_element == EL_ANY_ELEMENT)
1648 for (l = 0; l < MAX_NUM_ELEMENTS; l++)
1649 trigger_events[l][k] = TRUE;
1651 trigger_events[trigger_element][k] = TRUE;
1658 /* ---------- initialize push delay -------------------------------------- */
1660 /* initialize push delay values to default */
1661 for (i = 0; i < MAX_NUM_ELEMENTS; i++)
1663 if (!IS_CUSTOM_ELEMENT(i))
1665 /* set default push delay values (corrected since version 3.0.7-1) */
1666 if (game.engine_version < VERSION_IDENT(3,0,7,1))
1668 element_info[i].push_delay_fixed = 2;
1669 element_info[i].push_delay_random = 8;
1673 element_info[i].push_delay_fixed = 8;
1674 element_info[i].push_delay_random = 8;
1679 /* set push delay value for certain elements from pre-defined list */
1680 for (i = 0; push_delay_list[i].element != EL_UNDEFINED; i++)
1682 int e = push_delay_list[i].element;
1684 element_info[e].push_delay_fixed = push_delay_list[i].push_delay_fixed;
1685 element_info[e].push_delay_random = push_delay_list[i].push_delay_random;
1688 /* set push delay value for Supaplex elements for newer engine versions */
1689 if (game.engine_version >= VERSION_IDENT(3,1,0,0))
1691 for (i = 0; i < MAX_NUM_ELEMENTS; i++)
1693 if (IS_SP_ELEMENT(i))
1695 /* set SP push delay to just enough to push under a falling zonk */
1696 int delay = (game.engine_version >= VERSION_IDENT(3,1,1,0) ? 8 : 6);
1698 element_info[i].push_delay_fixed = delay;
1699 element_info[i].push_delay_random = 0;
1704 /* ---------- initialize move stepsize ----------------------------------- */
1706 /* initialize move stepsize values to default */
1707 for (i = 0; i < MAX_NUM_ELEMENTS; i++)
1708 if (!IS_CUSTOM_ELEMENT(i))
1709 element_info[i].move_stepsize = MOVE_STEPSIZE_NORMAL;
1711 /* set move stepsize value for certain elements from pre-defined list */
1712 for (i = 0; move_stepsize_list[i].element != EL_UNDEFINED; i++)
1714 int e = move_stepsize_list[i].element;
1716 element_info[e].move_stepsize = move_stepsize_list[i].move_stepsize;
1719 /* ---------- initialize collect score ----------------------------------- */
1721 /* initialize collect score values for custom elements from initial value */
1722 for (i = 0; i < MAX_NUM_ELEMENTS; i++)
1723 if (IS_CUSTOM_ELEMENT(i))
1724 element_info[i].collect_score = element_info[i].collect_score_initial;
1726 /* ---------- initialize collect count ----------------------------------- */
1728 /* initialize collect count values for non-custom elements */
1729 for (i = 0; i < MAX_NUM_ELEMENTS; i++)
1730 if (!IS_CUSTOM_ELEMENT(i))
1731 element_info[i].collect_count_initial = 0;
1733 /* add collect count values for all elements from pre-defined list */
1734 for (i = 0; collect_count_list[i].element != EL_UNDEFINED; i++)
1735 element_info[collect_count_list[i].element].collect_count_initial =
1736 collect_count_list[i].count;
1738 /* ---------- initialize access direction -------------------------------- */
1740 /* initialize access direction values to default (access from every side) */
1741 for (i = 0; i < MAX_NUM_ELEMENTS; i++)
1742 if (!IS_CUSTOM_ELEMENT(i))
1743 element_info[i].access_direction = MV_ALL_DIRECTIONS;
1745 /* set access direction value for certain elements from pre-defined list */
1746 for (i = 0; access_direction_list[i].element != EL_UNDEFINED; i++)
1747 element_info[access_direction_list[i].element].access_direction =
1748 access_direction_list[i].direction;
1750 /* ---------- initialize explosion content ------------------------------- */
1751 for (i = 0; i < MAX_NUM_ELEMENTS; i++)
1753 if (IS_CUSTOM_ELEMENT(i))
1756 for (y = 0; y < 3; y++) for (x = 0; x < 3; x++)
1758 /* (content for EL_YAMYAM set at run-time with game.yamyam_content_nr) */
1760 element_info[i].content.e[x][y] =
1761 (i == EL_PLAYER_1 ? EL_EMERALD_YELLOW :
1762 i == EL_PLAYER_2 ? EL_EMERALD_RED :
1763 i == EL_PLAYER_3 ? EL_EMERALD :
1764 i == EL_PLAYER_4 ? EL_EMERALD_PURPLE :
1765 i == EL_MOLE ? EL_EMERALD_RED :
1766 i == EL_PENGUIN ? EL_EMERALD_PURPLE :
1767 i == EL_BUG ? (x == 1 && y == 1 ? EL_DIAMOND : EL_EMERALD) :
1768 i == EL_BD_BUTTERFLY ? EL_BD_DIAMOND :
1769 i == EL_SP_ELECTRON ? EL_SP_INFOTRON :
1770 i == EL_AMOEBA_TO_DIAMOND ? level.amoeba_content :
1771 i == EL_WALL_EMERALD ? EL_EMERALD :
1772 i == EL_WALL_DIAMOND ? EL_DIAMOND :
1773 i == EL_WALL_BD_DIAMOND ? EL_BD_DIAMOND :
1774 i == EL_WALL_EMERALD_YELLOW ? EL_EMERALD_YELLOW :
1775 i == EL_WALL_EMERALD_RED ? EL_EMERALD_RED :
1776 i == EL_WALL_EMERALD_PURPLE ? EL_EMERALD_PURPLE :
1777 i == EL_WALL_PEARL ? EL_PEARL :
1778 i == EL_WALL_CRYSTAL ? EL_CRYSTAL :
1784 int get_num_special_action(int element, int action_first, int action_last)
1786 int num_special_action = 0;
1789 for (i = action_first; i <= action_last; i++)
1791 boolean found = FALSE;
1793 for (j = 0; j < NUM_DIRECTIONS; j++)
1794 if (el_act_dir2img(element, i, j) !=
1795 el_act_dir2img(element, ACTION_DEFAULT, j))
1799 num_special_action++;
1804 return num_special_action;
1809 =============================================================================
1811 -----------------------------------------------------------------------------
1812 initialize and start new game
1813 =============================================================================
1818 boolean emulate_bd = TRUE; /* unless non-BOULDERDASH elements found */
1819 boolean emulate_sb = TRUE; /* unless non-SOKOBAN elements found */
1820 boolean emulate_sp = TRUE; /* unless non-SUPAPLEX elements found */
1821 boolean do_fading = (game_status == GAME_MODE_MAIN);
1824 game_status = GAME_MODE_PLAYING;
1828 /* don't play tapes over network */
1829 network_playing = (options.network && !tape.playing);
1831 for (i = 0; i < MAX_PLAYERS; i++)
1833 struct PlayerInfo *player = &stored_player[i];
1835 player->index_nr = i;
1836 player->index_bit = (1 << i);
1837 player->element_nr = EL_PLAYER_1 + i;
1839 player->present = FALSE;
1840 player->active = FALSE;
1843 player->effective_action = 0;
1844 player->programmed_action = 0;
1847 player->score_final = 0;
1849 player->gems_still_needed = level.gems_needed;
1850 player->sokobanfields_still_needed = 0;
1851 player->lights_still_needed = 0;
1852 player->friends_still_needed = 0;
1854 for (j = 0; j < MAX_NUM_KEYS; j++)
1855 player->key[j] = FALSE;
1857 player->dynabomb_count = 0;
1858 player->dynabomb_size = 1;
1859 player->dynabombs_left = 0;
1860 player->dynabomb_xl = FALSE;
1862 player->MovDir = MV_NONE;
1865 player->GfxDir = MV_NONE;
1866 player->GfxAction = ACTION_DEFAULT;
1868 player->StepFrame = 0;
1870 player->use_murphy = FALSE;
1871 player->artwork_element =
1872 (level.use_artwork_element[i] ? level.artwork_element[i] :
1873 player->element_nr);
1875 player->block_last_field = FALSE; /* initialized in InitPlayerField() */
1876 player->block_delay_adjustment = 0; /* initialized in InitPlayerField() */
1878 player->gravity = level.initial_player_gravity[i];
1880 player->can_fall_into_acid = CAN_MOVE_INTO_ACID(player->element_nr);
1882 player->actual_frame_counter = 0;
1884 player->step_counter = 0;
1886 player->last_move_dir = MV_NONE;
1888 player->is_active = FALSE;
1890 player->is_waiting = FALSE;
1891 player->is_moving = FALSE;
1892 player->is_auto_moving = FALSE;
1893 player->is_digging = FALSE;
1894 player->is_snapping = FALSE;
1895 player->is_collecting = FALSE;
1896 player->is_pushing = FALSE;
1897 player->is_switching = FALSE;
1898 player->is_dropping = FALSE;
1899 player->is_dropping_pressed = FALSE;
1901 player->is_bored = FALSE;
1902 player->is_sleeping = FALSE;
1904 player->frame_counter_bored = -1;
1905 player->frame_counter_sleeping = -1;
1907 player->anim_delay_counter = 0;
1908 player->post_delay_counter = 0;
1910 player->dir_waiting = MV_NONE;
1911 player->action_waiting = ACTION_DEFAULT;
1912 player->last_action_waiting = ACTION_DEFAULT;
1913 player->special_action_bored = ACTION_DEFAULT;
1914 player->special_action_sleeping = ACTION_DEFAULT;
1916 player->switch_x = -1;
1917 player->switch_y = -1;
1919 player->drop_x = -1;
1920 player->drop_y = -1;
1922 player->show_envelope = 0;
1924 SetPlayerMoveSpeed(player, level.initial_player_stepsize[i], TRUE);
1926 player->push_delay = -1; /* initialized when pushing starts */
1927 player->push_delay_value = game.initial_push_delay_value;
1929 player->drop_delay = 0;
1930 player->drop_pressed_delay = 0;
1932 player->last_jx = player->last_jy = 0;
1933 player->jx = player->jy = 0;
1935 player->shield_normal_time_left = 0;
1936 player->shield_deadly_time_left = 0;
1938 player->inventory_infinite_element = EL_UNDEFINED;
1939 player->inventory_size = 0;
1941 DigField(player, 0, 0, 0, 0, 0, 0, DF_NO_PUSH);
1942 SnapField(player, 0, 0);
1944 player->LevelSolved = FALSE;
1945 player->GameOver = FALSE;
1947 player->LevelSolved_GameEnd = FALSE;
1948 player->LevelSolved_SaveTape = FALSE;
1949 player->LevelSolved_SaveScore = FALSE;
1952 network_player_action_received = FALSE;
1954 #if defined(NETWORK_AVALIABLE)
1955 /* initial null action */
1956 if (network_playing)
1957 SendToServer_MovePlayer(MV_NONE);
1966 TimeLeft = level.time;
1969 ScreenMovDir = MV_NONE;
1973 ScrollStepSize = 0; /* will be correctly initialized by ScrollScreen() */
1975 AllPlayersGone = FALSE;
1977 game.yamyam_content_nr = 0;
1978 game.magic_wall_active = FALSE;
1979 game.magic_wall_time_left = 0;
1980 game.light_time_left = 0;
1981 game.timegate_time_left = 0;
1982 game.switchgate_pos = 0;
1983 game.wind_direction = level.wind_direction_initial;
1985 #if !USE_PLAYER_GRAVITY
1986 game.gravity = FALSE;
1987 game.explosions_delayed = TRUE;
1990 game.lenses_time_left = 0;
1991 game.magnify_time_left = 0;
1993 game.ball_state = level.ball_state_initial;
1994 game.ball_content_nr = 0;
1996 game.envelope_active = FALSE;
1998 /* set focus to local player for network games, else to all players */
1999 game.centered_player_nr = (network_playing ? local_player->index_nr : -1);
2000 game.centered_player_nr_next = game.centered_player_nr;
2001 game.set_centered_player = FALSE;
2003 if (network_playing && tape.recording)
2005 /* store client dependent player focus when recording network games */
2006 tape.centered_player_nr_next = game.centered_player_nr_next;
2007 tape.set_centered_player = TRUE;
2010 for (i = 0; i < NUM_BELTS; i++)
2012 game.belt_dir[i] = MV_NONE;
2013 game.belt_dir_nr[i] = 3; /* not moving, next moving left */
2016 for (i = 0; i < MAX_NUM_AMOEBA; i++)
2017 AmoebaCnt[i] = AmoebaCnt2[i] = 0;
2019 SCAN_PLAYFIELD(x, y)
2021 Feld[x][y] = level.field[x][y];
2022 MovPos[x][y] = MovDir[x][y] = MovDelay[x][y] = 0;
2023 ChangeDelay[x][y] = 0;
2024 ChangePage[x][y] = -1;
2025 #if USE_NEW_CUSTOM_VALUE
2026 CustomValue[x][y] = 0; /* initialized in InitField() */
2028 Store[x][y] = Store2[x][y] = StorePlayer[x][y] = Back[x][y] = 0;
2030 WasJustMoving[x][y] = 0;
2031 WasJustFalling[x][y] = 0;
2032 CheckCollision[x][y] = 0;
2034 Pushed[x][y] = FALSE;
2036 ChangeCount[x][y] = 0;
2037 ChangeEvent[x][y] = -1;
2039 ExplodePhase[x][y] = 0;
2040 ExplodeDelay[x][y] = 0;
2041 ExplodeField[x][y] = EX_TYPE_NONE;
2043 RunnerVisit[x][y] = 0;
2044 PlayerVisit[x][y] = 0;
2047 GfxRandom[x][y] = INIT_GFX_RANDOM();
2048 GfxElement[x][y] = EL_UNDEFINED;
2049 GfxAction[x][y] = ACTION_DEFAULT;
2050 GfxDir[x][y] = MV_NONE;
2053 SCAN_PLAYFIELD(x, y)
2055 if (emulate_bd && !IS_BD_ELEMENT(Feld[x][y]))
2057 if (emulate_sb && !IS_SB_ELEMENT(Feld[x][y]))
2059 if (emulate_sp && !IS_SP_ELEMENT(Feld[x][y]))
2062 InitField(x, y, TRUE);
2067 for (i = 0; i < MAX_PLAYERS; i++)
2069 struct PlayerInfo *player = &stored_player[i];
2071 /* set number of special actions for bored and sleeping animation */
2072 player->num_special_action_bored =
2073 get_num_special_action(player->artwork_element,
2074 ACTION_BORING_1, ACTION_BORING_LAST);
2075 player->num_special_action_sleeping =
2076 get_num_special_action(player->artwork_element,
2077 ACTION_SLEEPING_1, ACTION_SLEEPING_LAST);
2080 game.emulation = (emulate_bd ? EMU_BOULDERDASH :
2081 emulate_sb ? EMU_SOKOBAN :
2082 emulate_sp ? EMU_SUPAPLEX : EMU_NONE);
2084 #if USE_NEW_ALL_SLIPPERY
2085 /* initialize type of slippery elements */
2086 for (i = 0; i < MAX_NUM_ELEMENTS; i++)
2088 if (!IS_CUSTOM_ELEMENT(i))
2090 /* default: elements slip down either to the left or right randomly */
2091 element_info[i].slippery_type = SLIPPERY_ANY_RANDOM;
2093 /* SP style elements prefer to slip down on the left side */
2094 if (game.engine_version >= VERSION_IDENT(3,1,1,0) && IS_SP_ELEMENT(i))
2095 element_info[i].slippery_type = SLIPPERY_ANY_LEFT_RIGHT;
2097 /* BD style elements prefer to slip down on the left side */
2098 if (game.emulation == EMU_BOULDERDASH)
2099 element_info[i].slippery_type = SLIPPERY_ANY_LEFT_RIGHT;
2104 /* initialize explosion and ignition delay */
2105 for (i = 0; i < MAX_NUM_ELEMENTS; i++)
2107 if (!IS_CUSTOM_ELEMENT(i))
2110 int delay = (((IS_SP_ELEMENT(i) && i != EL_EMPTY_SPACE) &&
2111 game.engine_version >= VERSION_IDENT(3,1,0,0)) ||
2112 game.emulation == EMU_SUPAPLEX ? 3 : 2);
2113 int last_phase = (num_phase + 1) * delay;
2114 int half_phase = (num_phase / 2) * delay;
2116 element_info[i].explosion_delay = last_phase - 1;
2117 element_info[i].ignition_delay = half_phase;
2119 if (i == EL_BLACK_ORB)
2120 element_info[i].ignition_delay = 1;
2124 if (element_info[i].explosion_delay < 1) /* !!! check again !!! */
2125 element_info[i].explosion_delay = 1;
2127 if (element_info[i].ignition_delay < 1) /* !!! check again !!! */
2128 element_info[i].ignition_delay = 1;
2132 /* correct non-moving belts to start moving left */
2133 for (i = 0; i < NUM_BELTS; i++)
2134 if (game.belt_dir[i] == MV_NONE)
2135 game.belt_dir_nr[i] = 3; /* not moving, next moving left */
2137 /* check if any connected player was not found in playfield */
2138 for (i = 0; i < MAX_PLAYERS; i++)
2140 struct PlayerInfo *player = &stored_player[i];
2142 if (player->connected && !player->present)
2144 for (j = 0; j < MAX_PLAYERS; j++)
2146 struct PlayerInfo *some_player = &stored_player[j];
2147 int jx = some_player->jx, jy = some_player->jy;
2149 /* assign first free player found that is present in the playfield */
2150 if (some_player->present && !some_player->connected)
2152 player->present = TRUE;
2153 player->active = TRUE;
2155 some_player->present = FALSE;
2156 some_player->active = FALSE;
2158 player->artwork_element = some_player->artwork_element;
2160 player->block_last_field = some_player->block_last_field;
2161 player->block_delay_adjustment = some_player->block_delay_adjustment;
2163 StorePlayer[jx][jy] = player->element_nr;
2164 player->jx = player->last_jx = jx;
2165 player->jy = player->last_jy = jy;
2175 /* when playing a tape, eliminate all players who do not participate */
2177 for (i = 0; i < MAX_PLAYERS; i++)
2179 if (stored_player[i].active && !tape.player_participates[i])
2181 struct PlayerInfo *player = &stored_player[i];
2182 int jx = player->jx, jy = player->jy;
2184 player->active = FALSE;
2185 StorePlayer[jx][jy] = 0;
2186 Feld[jx][jy] = EL_EMPTY;
2190 else if (!options.network && !setup.team_mode) /* && !tape.playing */
2192 /* when in single player mode, eliminate all but the first active player */
2194 for (i = 0; i < MAX_PLAYERS; i++)
2196 if (stored_player[i].active)
2198 for (j = i + 1; j < MAX_PLAYERS; j++)
2200 if (stored_player[j].active)
2202 struct PlayerInfo *player = &stored_player[j];
2203 int jx = player->jx, jy = player->jy;
2205 player->active = FALSE;
2206 player->present = FALSE;
2208 StorePlayer[jx][jy] = 0;
2209 Feld[jx][jy] = EL_EMPTY;
2216 /* when recording the game, store which players take part in the game */
2219 for (i = 0; i < MAX_PLAYERS; i++)
2220 if (stored_player[i].active)
2221 tape.player_participates[i] = TRUE;
2226 for (i = 0; i < MAX_PLAYERS; i++)
2228 struct PlayerInfo *player = &stored_player[i];
2230 printf("Player %d: present == %d, connected == %d, active == %d.\n",
2235 if (local_player == player)
2236 printf("Player %d is local player.\n", i+1);
2240 if (BorderElement == EL_EMPTY)
2243 SBX_Right = lev_fieldx - SCR_FIELDX;
2245 SBY_Lower = lev_fieldy - SCR_FIELDY;
2250 SBX_Right = lev_fieldx - SCR_FIELDX + 1;
2252 SBY_Lower = lev_fieldy - SCR_FIELDY + 1;
2255 if (lev_fieldx + (SBX_Left == -1 ? 2 : 0) <= SCR_FIELDX)
2256 SBX_Left = SBX_Right = -1 * (SCR_FIELDX - lev_fieldx) / 2;
2258 if (lev_fieldy + (SBY_Upper == -1 ? 2 : 0) <= SCR_FIELDY)
2259 SBY_Upper = SBY_Lower = -1 * (SCR_FIELDY - lev_fieldy) / 2;
2261 /* if local player not found, look for custom element that might create
2262 the player (make some assumptions about the right custom element) */
2263 if (!local_player->present)
2265 int start_x = 0, start_y = 0;
2266 int found_rating = 0;
2267 int found_element = EL_UNDEFINED;
2268 int player_nr = local_player->index_nr;
2270 SCAN_PLAYFIELD(x, y)
2272 int element = Feld[x][y];
2277 if (level.use_start_element[player_nr] &&
2278 level.start_element[player_nr] == element &&
2285 found_element = element;
2288 if (!IS_CUSTOM_ELEMENT(element))
2291 if (CAN_CHANGE(element))
2293 for (i = 0; i < element_info[element].num_change_pages; i++)
2295 /* check for player created from custom element as single target */
2296 content = element_info[element].change_page[i].target_element;
2297 is_player = ELEM_IS_PLAYER(content);
2299 if (is_player && (found_rating < 3 || element < found_element))
2305 found_element = element;
2310 for (yy = 0; yy < 3; yy++) for (xx = 0; xx < 3; xx++)
2312 /* check for player created from custom element as explosion content */
2313 content = element_info[element].content.e[xx][yy];
2314 is_player = ELEM_IS_PLAYER(content);
2316 if (is_player && (found_rating < 2 || element < found_element))
2318 start_x = x + xx - 1;
2319 start_y = y + yy - 1;
2322 found_element = element;
2325 if (!CAN_CHANGE(element))
2328 for (i = 0; i < element_info[element].num_change_pages; i++)
2330 /* check for player created from custom element as extended target */
2332 element_info[element].change_page[i].target_content.e[xx][yy];
2334 is_player = ELEM_IS_PLAYER(content);
2336 if (is_player && (found_rating < 1 || element < found_element))
2338 start_x = x + xx - 1;
2339 start_y = y + yy - 1;
2342 found_element = element;
2348 scroll_x = (start_x < SBX_Left + MIDPOSX ? SBX_Left :
2349 start_x > SBX_Right + MIDPOSX ? SBX_Right :
2352 scroll_y = (start_y < SBY_Upper + MIDPOSY ? SBY_Upper :
2353 start_y > SBY_Lower + MIDPOSY ? SBY_Lower :
2358 scroll_x = (local_player->jx < SBX_Left + MIDPOSX ? SBX_Left :
2359 local_player->jx > SBX_Right + MIDPOSX ? SBX_Right :
2360 local_player->jx - MIDPOSX);
2362 scroll_y = (local_player->jy < SBY_Upper + MIDPOSY ? SBY_Upper :
2363 local_player->jy > SBY_Lower + MIDPOSY ? SBY_Lower :
2364 local_player->jy - MIDPOSY);
2369 if (!game.restart_level)
2370 CloseDoor(DOOR_CLOSE_1);
2373 FadeOut(REDRAW_FIELD);
2375 /* !!! FIX THIS (START) !!! */
2376 if (level.game_engine_type == GAME_ENGINE_TYPE_EM)
2378 InitGameEngine_EM();
2380 /* blit playfield from scroll buffer to normal back buffer for fading in */
2381 BlitScreenToBitmap_EM(backbuffer);
2388 /* after drawing the level, correct some elements */
2389 if (game.timegate_time_left == 0)
2390 CloseAllOpenTimegates();
2392 /* blit playfield from scroll buffer to normal back buffer for fading in */
2393 if (setup.soft_scrolling)
2394 BlitBitmap(fieldbuffer, backbuffer, FX, FY, SXSIZE, SYSIZE, SX, SY);
2396 redraw_mask |= REDRAW_FROM_BACKBUFFER;
2398 /* !!! FIX THIS (END) !!! */
2401 FadeIn(REDRAW_FIELD);
2405 if (!game.restart_level)
2407 /* copy default game door content to main double buffer */
2408 BlitBitmap(graphic_info[IMG_GLOBAL_DOOR].bitmap, drawto,
2409 DOOR_GFX_PAGEX5, DOOR_GFX_PAGEY1, DXSIZE, DYSIZE, DX, DY);
2412 SetPanelBackground();
2413 SetDrawBackgroundMask(REDRAW_DOOR_1);
2415 DrawGameDoorValues();
2417 if (!game.restart_level)
2421 game_gadget[SOUND_CTRL_ID_MUSIC]->checked = setup.sound_music;
2422 game_gadget[SOUND_CTRL_ID_LOOPS]->checked = setup.sound_loops;
2423 game_gadget[SOUND_CTRL_ID_SIMPLE]->checked = setup.sound_simple;
2427 /* copy actual game door content to door double buffer for OpenDoor() */
2428 BlitBitmap(drawto, bitmap_db_door,
2429 DX, DY, DXSIZE, DYSIZE, DOOR_GFX_PAGEX1, DOOR_GFX_PAGEY1);
2431 OpenDoor(DOOR_OPEN_ALL);
2433 PlaySound(SND_GAME_STARTING);
2435 if (setup.sound_music)
2438 KeyboardAutoRepeatOffUnlessAutoplay();
2442 for (i = 0; i < MAX_PLAYERS; i++)
2443 printf("Player %d %sactive.\n",
2444 i + 1, (stored_player[i].active ? "" : "not "));
2448 game.restart_level = FALSE;
2451 void UpdateEngineValues(int actual_scroll_x, int actual_scroll_y)
2453 /* this is used for non-R'n'D game engines to update certain engine values */
2455 /* needed to determine if sounds are played within the visible screen area */
2456 scroll_x = actual_scroll_x;
2457 scroll_y = actual_scroll_y;
2460 void InitMovDir(int x, int y)
2462 int i, element = Feld[x][y];
2463 static int xy[4][2] =
2470 static int direction[3][4] =
2472 { MV_RIGHT, MV_UP, MV_LEFT, MV_DOWN },
2473 { MV_LEFT, MV_DOWN, MV_RIGHT, MV_UP },
2474 { MV_LEFT, MV_RIGHT, MV_UP, MV_DOWN }
2483 Feld[x][y] = EL_BUG;
2484 MovDir[x][y] = direction[0][element - EL_BUG_RIGHT];
2487 case EL_SPACESHIP_RIGHT:
2488 case EL_SPACESHIP_UP:
2489 case EL_SPACESHIP_LEFT:
2490 case EL_SPACESHIP_DOWN:
2491 Feld[x][y] = EL_SPACESHIP;
2492 MovDir[x][y] = direction[0][element - EL_SPACESHIP_RIGHT];
2495 case EL_BD_BUTTERFLY_RIGHT:
2496 case EL_BD_BUTTERFLY_UP:
2497 case EL_BD_BUTTERFLY_LEFT:
2498 case EL_BD_BUTTERFLY_DOWN:
2499 Feld[x][y] = EL_BD_BUTTERFLY;
2500 MovDir[x][y] = direction[0][element - EL_BD_BUTTERFLY_RIGHT];
2503 case EL_BD_FIREFLY_RIGHT:
2504 case EL_BD_FIREFLY_UP:
2505 case EL_BD_FIREFLY_LEFT:
2506 case EL_BD_FIREFLY_DOWN:
2507 Feld[x][y] = EL_BD_FIREFLY;
2508 MovDir[x][y] = direction[0][element - EL_BD_FIREFLY_RIGHT];
2511 case EL_PACMAN_RIGHT:
2513 case EL_PACMAN_LEFT:
2514 case EL_PACMAN_DOWN:
2515 Feld[x][y] = EL_PACMAN;
2516 MovDir[x][y] = direction[0][element - EL_PACMAN_RIGHT];
2519 case EL_YAMYAM_LEFT:
2520 case EL_YAMYAM_RIGHT:
2522 case EL_YAMYAM_DOWN:
2523 Feld[x][y] = EL_YAMYAM;
2524 MovDir[x][y] = direction[2][element - EL_YAMYAM_LEFT];
2527 case EL_SP_SNIKSNAK:
2528 MovDir[x][y] = MV_UP;
2531 case EL_SP_ELECTRON:
2532 MovDir[x][y] = MV_LEFT;
2539 Feld[x][y] = EL_MOLE;
2540 MovDir[x][y] = direction[2][element - EL_MOLE_LEFT];
2544 if (IS_CUSTOM_ELEMENT(element))
2546 struct ElementInfo *ei = &element_info[element];
2547 int move_direction_initial = ei->move_direction_initial;
2548 int move_pattern = ei->move_pattern;
2550 if (move_direction_initial == MV_START_PREVIOUS)
2552 if (MovDir[x][y] != MV_NONE)
2555 move_direction_initial = MV_START_AUTOMATIC;
2558 if (move_direction_initial == MV_START_RANDOM)
2559 MovDir[x][y] = 1 << RND(4);
2560 else if (move_direction_initial & MV_ANY_DIRECTION)
2561 MovDir[x][y] = move_direction_initial;
2562 else if (move_pattern == MV_ALL_DIRECTIONS ||
2563 move_pattern == MV_TURNING_LEFT ||
2564 move_pattern == MV_TURNING_RIGHT ||
2565 move_pattern == MV_TURNING_LEFT_RIGHT ||
2566 move_pattern == MV_TURNING_RIGHT_LEFT ||
2567 move_pattern == MV_TURNING_RANDOM)
2568 MovDir[x][y] = 1 << RND(4);
2569 else if (move_pattern == MV_HORIZONTAL)
2570 MovDir[x][y] = (RND(2) ? MV_LEFT : MV_RIGHT);
2571 else if (move_pattern == MV_VERTICAL)
2572 MovDir[x][y] = (RND(2) ? MV_UP : MV_DOWN);
2573 else if (move_pattern & MV_ANY_DIRECTION)
2574 MovDir[x][y] = element_info[element].move_pattern;
2575 else if (move_pattern == MV_ALONG_LEFT_SIDE ||
2576 move_pattern == MV_ALONG_RIGHT_SIDE)
2578 /* use random direction as default start direction */
2579 if (game.engine_version >= VERSION_IDENT(3,1,0,0))
2580 MovDir[x][y] = 1 << RND(4);
2582 for (i = 0; i < NUM_DIRECTIONS; i++)
2584 int x1 = x + xy[i][0];
2585 int y1 = y + xy[i][1];
2587 if (!IN_LEV_FIELD(x1, y1) || !IS_FREE(x1, y1))
2589 if (move_pattern == MV_ALONG_RIGHT_SIDE)
2590 MovDir[x][y] = direction[0][i];
2592 MovDir[x][y] = direction[1][i];
2601 MovDir[x][y] = 1 << RND(4);
2603 if (element != EL_BUG &&
2604 element != EL_SPACESHIP &&
2605 element != EL_BD_BUTTERFLY &&
2606 element != EL_BD_FIREFLY)
2609 for (i = 0; i < NUM_DIRECTIONS; i++)
2611 int x1 = x + xy[i][0];
2612 int y1 = y + xy[i][1];
2614 if (!IN_LEV_FIELD(x1, y1) || !IS_FREE(x1, y1))
2616 if (element == EL_BUG || element == EL_BD_BUTTERFLY)
2618 MovDir[x][y] = direction[0][i];
2621 else if (element == EL_SPACESHIP || element == EL_BD_FIREFLY ||
2622 element == EL_SP_SNIKSNAK || element == EL_SP_ELECTRON)
2624 MovDir[x][y] = direction[1][i];
2633 GfxDir[x][y] = MovDir[x][y];
2636 void InitAmoebaNr(int x, int y)
2639 int group_nr = AmoebeNachbarNr(x, y);
2643 for (i = 1; i < MAX_NUM_AMOEBA; i++)
2645 if (AmoebaCnt[i] == 0)
2653 AmoebaNr[x][y] = group_nr;
2654 AmoebaCnt[group_nr]++;
2655 AmoebaCnt2[group_nr]++;
2658 static void PlayerWins(struct PlayerInfo *player)
2660 player->LevelSolved = TRUE;
2661 player->GameOver = TRUE;
2663 player->score_final = (level.game_engine_type == GAME_ENGINE_TYPE_EM ?
2664 level.native_em_level->lev->score : player->score);
2669 static int time, time_final;
2670 static int score, score_final;
2671 static int game_over_delay = 0;
2672 int game_over_delay_value = 50;
2674 /* do not start end game actions before the player stops moving (to exit) */
2675 if (local_player->MovPos)
2678 if (!local_player->LevelSolved_GameEnd)
2680 local_player->LevelSolved_GameEnd = TRUE;
2681 local_player->LevelSolved_SaveTape = tape.recording;
2682 local_player->LevelSolved_SaveScore = !tape.playing;
2684 if (tape.auto_play) /* tape might already be stopped here */
2685 tape.auto_play_level_solved = TRUE;
2687 game_over_delay = game_over_delay_value;
2689 time = time_final = (level.time == 0 ? TimePlayed : TimeLeft);
2690 score = score_final = local_player->score_final;
2695 score_final += TimeLeft * level.score[SC_TIME_BONUS];
2697 else if (level.time == 0 && TimePlayed < 999)
2700 score_final += (999 - TimePlayed) * level.score[SC_TIME_BONUS];
2703 local_player->score_final = score_final;
2705 if (level_editor_test_game)
2708 score = score_final;
2710 DrawGameValue_Time(time);
2711 DrawGameValue_Score(score);
2714 if (ExitX >= 0 && ExitY >= 0) /* local player has left the level */
2716 /* close exit door after last player */
2717 if (AllPlayersGone &&
2718 (Feld[ExitX][ExitY] == EL_EXIT_OPEN ||
2719 Feld[ExitX][ExitY] == EL_SP_EXIT_OPEN))
2721 int element = Feld[ExitX][ExitY];
2723 Feld[ExitX][ExitY] = (element == EL_EXIT_OPEN ? EL_EXIT_CLOSING :
2724 EL_SP_EXIT_CLOSING);
2726 PlayLevelSoundElementAction(ExitX, ExitY, element, ACTION_CLOSING);
2729 /* player disappears */
2730 DrawLevelField(ExitX, ExitY);
2733 PlaySound(SND_GAME_WINNING);
2736 if (game_over_delay > 0)
2743 if (time != time_final)
2745 int time_to_go = ABS(time_final - time);
2746 int time_count_dir = (time < time_final ? +1 : -1);
2747 int time_count_steps = (time_to_go > 100 && time_to_go % 10 == 0 ? 10 : 1);
2749 time += time_count_steps * time_count_dir;
2750 score += time_count_steps * level.score[SC_TIME_BONUS];
2752 DrawGameValue_Time(time);
2753 DrawGameValue_Score(score);
2755 if (time == time_final)
2756 StopSound(SND_GAME_LEVELTIME_BONUS);
2757 else if (setup.sound_loops)
2758 PlaySoundLoop(SND_GAME_LEVELTIME_BONUS);
2760 PlaySound(SND_GAME_LEVELTIME_BONUS);
2767 boolean raise_level = FALSE;
2769 CloseDoor(DOOR_CLOSE_1);
2771 if (local_player->LevelSolved_SaveTape)
2775 SaveTape(tape.level_nr); /* ask to save tape */
2778 if (level_editor_test_game)
2780 game_status = GAME_MODE_MAIN;
2787 if (!local_player->LevelSolved_SaveScore)
2789 FadeOut(REDRAW_FIELD);
2791 game_status = GAME_MODE_MAIN;
2793 DrawAndFadeInMainMenu(REDRAW_FIELD);
2798 if (level_nr == leveldir_current->handicap_level)
2800 leveldir_current->handicap_level++;
2801 SaveLevelSetup_SeriesInfo();
2804 if (level_nr < leveldir_current->last_level)
2805 raise_level = TRUE; /* advance to next level */
2807 if ((hi_pos = NewHiScore()) >= 0)
2809 game_status = GAME_MODE_SCORES;
2811 DrawHallOfFame(hi_pos);
2821 FadeOut(REDRAW_FIELD);
2823 game_status = GAME_MODE_MAIN;
2831 DrawAndFadeInMainMenu(REDRAW_FIELD);
2840 LoadScore(level_nr);
2842 if (strEqual(setup.player_name, EMPTY_PLAYER_NAME) ||
2843 local_player->score_final < highscore[MAX_SCORE_ENTRIES - 1].Score)
2846 for (k = 0; k < MAX_SCORE_ENTRIES; k++)
2848 if (local_player->score_final > highscore[k].Score)
2850 /* player has made it to the hall of fame */
2852 if (k < MAX_SCORE_ENTRIES - 1)
2854 int m = MAX_SCORE_ENTRIES - 1;
2857 for (l = k; l < MAX_SCORE_ENTRIES; l++)
2858 if (strEqual(setup.player_name, highscore[l].Name))
2860 if (m == k) /* player's new highscore overwrites his old one */
2864 for (l = m; l > k; l--)
2866 strcpy(highscore[l].Name, highscore[l - 1].Name);
2867 highscore[l].Score = highscore[l - 1].Score;
2874 strncpy(highscore[k].Name, setup.player_name, MAX_PLAYER_NAME_LEN);
2875 highscore[k].Name[MAX_PLAYER_NAME_LEN] = '\0';
2876 highscore[k].Score = local_player->score_final;
2882 else if (!strncmp(setup.player_name, highscore[k].Name,
2883 MAX_PLAYER_NAME_LEN))
2884 break; /* player already there with a higher score */
2890 SaveScore(level_nr);
2895 inline static int getElementMoveStepsize(int x, int y)
2897 int element = Feld[x][y];
2898 int direction = MovDir[x][y];
2899 int dx = (direction == MV_LEFT ? -1 : direction == MV_RIGHT ? +1 : 0);
2900 int dy = (direction == MV_UP ? -1 : direction == MV_DOWN ? +1 : 0);
2901 int horiz_move = (dx != 0);
2902 int sign = (horiz_move ? dx : dy);
2903 int step = sign * element_info[element].move_stepsize;
2905 /* special values for move stepsize for spring and things on conveyor belt */
2908 if (CAN_FALL(element) &&
2909 y < lev_fieldy - 1 && IS_BELT_ACTIVE(Feld[x][y + 1]))
2910 step = sign * MOVE_STEPSIZE_NORMAL / 2;
2911 else if (element == EL_SPRING)
2912 step = sign * MOVE_STEPSIZE_NORMAL * 2;
2918 void InitPlayerGfxAnimation(struct PlayerInfo *player, int action, int dir)
2920 if (player->GfxAction != action || player->GfxDir != dir)
2923 printf("Player frame reset! (%d => %d, %d => %d)\n",
2924 player->GfxAction, action, player->GfxDir, dir);
2927 player->GfxAction = action;
2928 player->GfxDir = dir;
2930 player->StepFrame = 0;
2934 #if USE_GFX_RESET_GFX_ANIMATION
2935 static void ResetGfxFrame(int x, int y, boolean redraw)
2937 int element = Feld[x][y];
2938 int graphic = el_act_dir2img(element, GfxAction[x][y], GfxDir[x][y]);
2939 int last_gfx_frame = GfxFrame[x][y];
2941 if (graphic_info[graphic].anim_global_sync)
2942 GfxFrame[x][y] = FrameCounter;
2943 else if (ANIM_MODE(graphic) == ANIM_CE_VALUE)
2944 GfxFrame[x][y] = CustomValue[x][y];
2945 else if (ANIM_MODE(graphic) == ANIM_CE_SCORE)
2946 GfxFrame[x][y] = element_info[element].collect_score;
2947 else if (ANIM_MODE(graphic) == ANIM_CE_DELAY)
2948 GfxFrame[x][y] = ChangeDelay[x][y];
2950 if (redraw && GfxFrame[x][y] != last_gfx_frame)
2951 DrawLevelGraphicAnimation(x, y, graphic);
2955 static void ResetGfxAnimation(int x, int y)
2957 GfxAction[x][y] = ACTION_DEFAULT;
2958 GfxDir[x][y] = MovDir[x][y];
2961 #if USE_GFX_RESET_GFX_ANIMATION
2962 ResetGfxFrame(x, y, FALSE);
2966 static void ResetRandomAnimationValue(int x, int y)
2968 GfxRandom[x][y] = INIT_GFX_RANDOM();
2971 void InitMovingField(int x, int y, int direction)
2973 int element = Feld[x][y];
2974 int dx = (direction == MV_LEFT ? -1 : direction == MV_RIGHT ? +1 : 0);
2975 int dy = (direction == MV_UP ? -1 : direction == MV_DOWN ? +1 : 0);
2979 if (!WasJustMoving[x][y] || direction != MovDir[x][y])
2980 ResetGfxAnimation(x, y);
2982 MovDir[x][y] = direction;
2983 GfxDir[x][y] = direction;
2984 GfxAction[x][y] = (direction == MV_DOWN && CAN_FALL(element) ?
2985 ACTION_FALLING : ACTION_MOVING);
2987 /* this is needed for CEs with property "can move" / "not moving" */
2989 if (getElementMoveStepsize(x, y) != 0) /* moving or being moved */
2991 if (Feld[newx][newy] == EL_EMPTY)
2992 Feld[newx][newy] = EL_BLOCKED;
2994 MovDir[newx][newy] = MovDir[x][y];
2996 #if USE_NEW_CUSTOM_VALUE
2997 CustomValue[newx][newy] = CustomValue[x][y];
3000 GfxFrame[newx][newy] = GfxFrame[x][y];
3001 GfxRandom[newx][newy] = GfxRandom[x][y];
3002 GfxAction[newx][newy] = GfxAction[x][y];
3003 GfxDir[newx][newy] = GfxDir[x][y];
3007 void Moving2Blocked(int x, int y, int *goes_to_x, int *goes_to_y)
3009 int direction = MovDir[x][y];
3010 int newx = x + (direction & MV_LEFT ? -1 : direction & MV_RIGHT ? +1 : 0);
3011 int newy = y + (direction & MV_UP ? -1 : direction & MV_DOWN ? +1 : 0);
3017 void Blocked2Moving(int x, int y, int *comes_from_x, int *comes_from_y)
3019 int oldx = x, oldy = y;
3020 int direction = MovDir[x][y];
3022 if (direction == MV_LEFT)
3024 else if (direction == MV_RIGHT)
3026 else if (direction == MV_UP)
3028 else if (direction == MV_DOWN)
3031 *comes_from_x = oldx;
3032 *comes_from_y = oldy;
3035 int MovingOrBlocked2Element(int x, int y)
3037 int element = Feld[x][y];
3039 if (element == EL_BLOCKED)
3043 Blocked2Moving(x, y, &oldx, &oldy);
3044 return Feld[oldx][oldy];
3050 static int MovingOrBlocked2ElementIfNotLeaving(int x, int y)
3052 /* like MovingOrBlocked2Element(), but if element is moving
3053 and (x,y) is the field the moving element is just leaving,
3054 return EL_BLOCKED instead of the element value */
3055 int element = Feld[x][y];
3057 if (IS_MOVING(x, y))
3059 if (element == EL_BLOCKED)
3063 Blocked2Moving(x, y, &oldx, &oldy);
3064 return Feld[oldx][oldy];
3073 static void RemoveField(int x, int y)
3075 Feld[x][y] = EL_EMPTY;
3081 #if USE_NEW_CUSTOM_VALUE
3082 CustomValue[x][y] = 0;
3086 ChangeDelay[x][y] = 0;
3087 ChangePage[x][y] = -1;
3088 Pushed[x][y] = FALSE;
3091 ExplodeField[x][y] = EX_TYPE_NONE;
3094 GfxElement[x][y] = EL_UNDEFINED;
3095 GfxAction[x][y] = ACTION_DEFAULT;
3096 GfxDir[x][y] = MV_NONE;
3099 void RemoveMovingField(int x, int y)
3101 int oldx = x, oldy = y, newx = x, newy = y;
3102 int element = Feld[x][y];
3103 int next_element = EL_UNDEFINED;
3105 if (element != EL_BLOCKED && !IS_MOVING(x, y))
3108 if (IS_MOVING(x, y))
3110 Moving2Blocked(x, y, &newx, &newy);
3112 if (Feld[newx][newy] != EL_BLOCKED)
3114 /* element is moving, but target field is not free (blocked), but
3115 already occupied by something different (example: acid pool);
3116 in this case, only remove the moving field, but not the target */
3118 RemoveField(oldx, oldy);
3120 Store[oldx][oldy] = Store2[oldx][oldy] = 0;
3122 DrawLevelField(oldx, oldy);
3127 else if (element == EL_BLOCKED)
3129 Blocked2Moving(x, y, &oldx, &oldy);
3130 if (!IS_MOVING(oldx, oldy))
3134 if (element == EL_BLOCKED &&
3135 (Feld[oldx][oldy] == EL_QUICKSAND_EMPTYING ||
3136 Feld[oldx][oldy] == EL_MAGIC_WALL_EMPTYING ||
3137 Feld[oldx][oldy] == EL_BD_MAGIC_WALL_EMPTYING ||
3138 Feld[oldx][oldy] == EL_AMOEBA_DROPPING))
3139 next_element = get_next_element(Feld[oldx][oldy]);
3141 RemoveField(oldx, oldy);
3142 RemoveField(newx, newy);
3144 Store[oldx][oldy] = Store2[oldx][oldy] = 0;
3146 if (next_element != EL_UNDEFINED)
3147 Feld[oldx][oldy] = next_element;
3149 DrawLevelField(oldx, oldy);
3150 DrawLevelField(newx, newy);
3153 void DrawDynamite(int x, int y)
3155 int sx = SCREENX(x), sy = SCREENY(y);
3156 int graphic = el2img(Feld[x][y]);
3159 if (!IN_SCR_FIELD(sx, sy) || IS_PLAYER(x, y))
3162 if (IS_WALKABLE_INSIDE(Back[x][y]))
3166 DrawGraphic(sx, sy, el2img(Back[x][y]), 0);
3167 else if (Store[x][y])
3168 DrawGraphic(sx, sy, el2img(Store[x][y]), 0);
3170 frame = getGraphicAnimationFrame(graphic, GfxFrame[x][y]);
3172 if (Back[x][y] || Store[x][y])
3173 DrawGraphicThruMask(sx, sy, graphic, frame);
3175 DrawGraphic(sx, sy, graphic, frame);
3178 void CheckDynamite(int x, int y)
3180 if (MovDelay[x][y] != 0) /* dynamite is still waiting to explode */
3184 if (MovDelay[x][y] != 0)
3187 PlayLevelSoundActionIfLoop(x, y, ACTION_ACTIVE);
3193 StopLevelSoundActionIfLoop(x, y, ACTION_ACTIVE);
3198 static void setMinimalPlayerBoundaries(int *sx1, int *sy1, int *sx2, int *sy2)
3200 boolean num_checked_players = 0;
3203 for (i = 0; i < MAX_PLAYERS; i++)
3205 if (stored_player[i].active)
3207 int sx = stored_player[i].jx;
3208 int sy = stored_player[i].jy;
3210 if (num_checked_players == 0)
3217 *sx1 = MIN(*sx1, sx);
3218 *sy1 = MIN(*sy1, sy);
3219 *sx2 = MAX(*sx2, sx);
3220 *sy2 = MAX(*sy2, sy);
3223 num_checked_players++;
3228 static boolean checkIfAllPlayersFitToScreen_RND()
3230 int sx1 = 0, sy1 = 0, sx2 = 0, sy2 = 0;
3232 setMinimalPlayerBoundaries(&sx1, &sy1, &sx2, &sy2);
3234 return (sx2 - sx1 < SCR_FIELDX &&
3235 sy2 - sy1 < SCR_FIELDY);
3238 static void setScreenCenteredToAllPlayers(int *sx, int *sy)
3240 int sx1 = scroll_x, sy1 = scroll_y, sx2 = scroll_x, sy2 = scroll_y;
3242 setMinimalPlayerBoundaries(&sx1, &sy1, &sx2, &sy2);
3244 *sx = (sx1 + sx2) / 2;
3245 *sy = (sy1 + sy2) / 2;
3248 void DrawRelocateScreen(int x, int y, int move_dir, boolean center_screen,
3249 boolean quick_relocation)
3251 boolean ffwd_delay = (tape.playing && tape.fast_forward);
3252 boolean no_delay = (tape.warp_forward);
3253 int frame_delay_value = (ffwd_delay ? FfwdFrameDelay : GameFrameDelay);
3254 int wait_delay_value = (no_delay ? 0 : frame_delay_value);
3256 if (quick_relocation)
3258 int offset = (setup.scroll_delay ? 3 : 0);
3260 if (!IN_VIS_FIELD(SCREENX(x), SCREENY(y)) || center_screen)
3262 scroll_x = (x < SBX_Left + MIDPOSX ? SBX_Left :
3263 x > SBX_Right + MIDPOSX ? SBX_Right :
3266 scroll_y = (y < SBY_Upper + MIDPOSY ? SBY_Upper :
3267 y > SBY_Lower + MIDPOSY ? SBY_Lower :
3272 if ((move_dir == MV_LEFT && scroll_x > x - MIDPOSX + offset) ||
3273 (move_dir == MV_RIGHT && scroll_x < x - MIDPOSX - offset))
3274 scroll_x = x - MIDPOSX + (scroll_x < x - MIDPOSX ? -offset : +offset);
3276 if ((move_dir == MV_UP && scroll_y > y - MIDPOSY + offset) ||
3277 (move_dir == MV_DOWN && scroll_y < y - MIDPOSY - offset))
3278 scroll_y = y - MIDPOSY + (scroll_y < y - MIDPOSY ? -offset : +offset);
3280 /* don't scroll over playfield boundaries */
3281 if (scroll_x < SBX_Left || scroll_x > SBX_Right)
3282 scroll_x = (scroll_x < SBX_Left ? SBX_Left : SBX_Right);
3284 /* don't scroll over playfield boundaries */
3285 if (scroll_y < SBY_Upper || scroll_y > SBY_Lower)
3286 scroll_y = (scroll_y < SBY_Upper ? SBY_Upper : SBY_Lower);
3289 RedrawPlayfield(TRUE, 0,0,0,0);
3293 int scroll_xx = (x < SBX_Left + MIDPOSX ? SBX_Left :
3294 x > SBX_Right + MIDPOSX ? SBX_Right :
3297 int scroll_yy = (y < SBY_Upper + MIDPOSY ? SBY_Upper :
3298 y > SBY_Lower + MIDPOSY ? SBY_Lower :
3301 ScrollScreen(NULL, SCROLL_GO_ON); /* scroll last frame to full tile */
3303 while (scroll_x != scroll_xx || scroll_y != scroll_yy)
3306 int fx = FX, fy = FY;
3308 dx = (scroll_xx < scroll_x ? +1 : scroll_xx > scroll_x ? -1 : 0);
3309 dy = (scroll_yy < scroll_y ? +1 : scroll_yy > scroll_y ? -1 : 0);
3311 if (dx == 0 && dy == 0) /* no scrolling needed at all */
3317 fx += dx * TILEX / 2;
3318 fy += dy * TILEY / 2;
3320 ScrollLevel(dx, dy);
3323 /* scroll in two steps of half tile size to make things smoother */
3324 BlitBitmap(drawto_field, window, fx, fy, SXSIZE, SYSIZE, SX, SY);
3326 Delay(wait_delay_value);
3328 /* scroll second step to align at full tile size */
3330 Delay(wait_delay_value);
3335 Delay(wait_delay_value);
3339 void RelocatePlayer(int jx, int jy, int el_player_raw)
3341 int el_player = GET_PLAYER_ELEMENT(el_player_raw);
3342 int player_nr = GET_PLAYER_NR(el_player);
3343 struct PlayerInfo *player = &stored_player[player_nr];
3344 boolean ffwd_delay = (tape.playing && tape.fast_forward);
3345 boolean no_delay = (tape.warp_forward);
3346 int frame_delay_value = (ffwd_delay ? FfwdFrameDelay : GameFrameDelay);
3347 int wait_delay_value = (no_delay ? 0 : frame_delay_value);
3348 int old_jx = player->jx;
3349 int old_jy = player->jy;
3350 int old_element = Feld[old_jx][old_jy];
3351 int element = Feld[jx][jy];
3352 boolean player_relocated = (old_jx != jx || old_jy != jy);
3354 int move_dir_horiz = (jx < old_jx ? MV_LEFT : jx > old_jx ? MV_RIGHT : 0);
3355 int move_dir_vert = (jy < old_jy ? MV_UP : jy > old_jy ? MV_DOWN : 0);
3356 int enter_side_horiz = MV_DIR_OPPOSITE(move_dir_horiz);
3357 int enter_side_vert = MV_DIR_OPPOSITE(move_dir_vert);
3358 int leave_side_horiz = move_dir_horiz;
3359 int leave_side_vert = move_dir_vert;
3360 int enter_side = enter_side_horiz | enter_side_vert;
3361 int leave_side = leave_side_horiz | leave_side_vert;
3363 if (player->GameOver) /* do not reanimate dead player */
3366 if (!player_relocated) /* no need to relocate the player */
3369 if (IS_PLAYER(jx, jy)) /* player already placed at new position */
3371 RemoveField(jx, jy); /* temporarily remove newly placed player */
3372 DrawLevelField(jx, jy);
3375 if (player->present)
3377 while (player->MovPos)
3379 ScrollPlayer(player, SCROLL_GO_ON);
3380 ScrollScreen(NULL, SCROLL_GO_ON);
3382 AdvanceFrameAndPlayerCounters(player->index_nr);
3387 Delay(wait_delay_value);
3390 DrawPlayer(player); /* needed here only to cleanup last field */
3391 DrawLevelField(player->jx, player->jy); /* remove player graphic */
3393 player->is_moving = FALSE;
3396 if (IS_CUSTOM_ELEMENT(old_element))
3397 CheckElementChangeByPlayer(old_jx, old_jy, old_element,
3399 player->index_bit, leave_side);
3401 CheckTriggeredElementChangeByPlayer(old_jx, old_jy, old_element,
3403 player->index_bit, leave_side);
3405 Feld[jx][jy] = el_player;
3406 InitPlayerField(jx, jy, el_player, TRUE);
3408 if (!ELEM_IS_PLAYER(element)) /* player may be set on walkable element */
3410 Feld[jx][jy] = element;
3411 InitField(jx, jy, FALSE);
3414 /* only visually relocate centered player */
3415 DrawRelocateScreen(player->jx, player->jy, player->MovDir, FALSE,
3416 level.instant_relocation);
3418 TestIfPlayerTouchesBadThing(jx, jy);
3419 TestIfPlayerTouchesCustomElement(jx, jy);
3421 if (IS_CUSTOM_ELEMENT(element))
3422 CheckElementChangeByPlayer(jx, jy, element, CE_ENTERED_BY_PLAYER,
3423 player->index_bit, enter_side);
3425 CheckTriggeredElementChangeByPlayer(jx, jy, element, CE_PLAYER_ENTERS_X,
3426 player->index_bit, enter_side);
3429 void Explode(int ex, int ey, int phase, int mode)
3435 /* !!! eliminate this variable !!! */
3436 int delay = (game.emulation == EMU_SUPAPLEX ? 3 : 2);
3438 if (game.explosions_delayed)
3440 ExplodeField[ex][ey] = mode;
3444 if (phase == EX_PHASE_START) /* initialize 'Store[][]' field */
3446 int center_element = Feld[ex][ey];
3447 int artwork_element, explosion_element; /* set these values later */
3450 /* --- This is only really needed (and now handled) in "Impact()". --- */
3451 /* do not explode moving elements that left the explode field in time */
3452 if (game.engine_version >= VERSION_IDENT(2,2,0,7) &&
3453 center_element == EL_EMPTY &&
3454 (mode == EX_TYPE_NORMAL || mode == EX_TYPE_CENTER))
3459 /* !!! at this place, the center element may be EL_BLOCKED !!! */
3460 if (mode == EX_TYPE_NORMAL ||
3461 mode == EX_TYPE_CENTER ||
3462 mode == EX_TYPE_CROSS)
3463 PlayLevelSoundElementAction(ex, ey, artwork_element, ACTION_EXPLODING);
3466 /* remove things displayed in background while burning dynamite */
3467 if (Back[ex][ey] != EL_EMPTY && !IS_INDESTRUCTIBLE(Back[ex][ey]))
3470 if (IS_MOVING(ex, ey) || IS_BLOCKED(ex, ey))
3472 /* put moving element to center field (and let it explode there) */
3473 center_element = MovingOrBlocked2Element(ex, ey);
3474 RemoveMovingField(ex, ey);
3475 Feld[ex][ey] = center_element;
3478 /* now "center_element" is finally determined -- set related values now */
3479 artwork_element = center_element; /* for custom player artwork */
3480 explosion_element = center_element; /* for custom player artwork */
3482 if (IS_PLAYER(ex, ey))
3484 int player_nr = GET_PLAYER_NR(StorePlayer[ex][ey]);
3486 artwork_element = stored_player[player_nr].artwork_element;
3488 if (level.use_explosion_element[player_nr])
3490 explosion_element = level.explosion_element[player_nr];
3491 artwork_element = explosion_element;
3496 if (mode == EX_TYPE_NORMAL ||
3497 mode == EX_TYPE_CENTER ||
3498 mode == EX_TYPE_CROSS)
3499 PlayLevelSoundElementAction(ex, ey, artwork_element, ACTION_EXPLODING);
3502 last_phase = element_info[explosion_element].explosion_delay + 1;
3504 for (y = ey - 1; y <= ey + 1; y++) for (x = ex - 1; x <= ex + 1; x++)
3506 int xx = x - ex + 1;
3507 int yy = y - ey + 1;
3510 if (!IN_LEV_FIELD(x, y) ||
3511 (mode & EX_TYPE_SINGLE_TILE && (x != ex || y != ey)) ||
3512 (mode == EX_TYPE_CROSS && (x != ex && y != ey)))
3515 element = Feld[x][y];
3517 if (IS_MOVING(x, y) || IS_BLOCKED(x, y))
3519 element = MovingOrBlocked2Element(x, y);
3521 if (!IS_EXPLOSION_PROOF(element))
3522 RemoveMovingField(x, y);
3525 /* indestructible elements can only explode in center (but not flames) */
3526 if ((IS_EXPLOSION_PROOF(element) && (x != ex || y != ey ||
3527 mode == EX_TYPE_BORDER)) ||
3528 element == EL_FLAMES)
3531 /* no idea why this was changed from 3.0.8 to 3.1.0 -- this causes buggy
3532 behaviour, for example when touching a yamyam that explodes to rocks
3533 with active deadly shield, a rock is created under the player !!! */
3534 /* (case 1 (surely buggy): >= 3.1.0, case 2 (maybe buggy): <= 3.0.8) */
3536 if (IS_PLAYER(x, y) && SHIELD_ON(PLAYERINFO(x, y)) &&
3537 (game.engine_version < VERSION_IDENT(3,1,0,0) ||
3538 (x == ex && y == ey && mode != EX_TYPE_BORDER)))
3540 if (IS_PLAYER(x, y) && SHIELD_ON(PLAYERINFO(x, y)))
3543 if (IS_ACTIVE_BOMB(element))
3545 /* re-activate things under the bomb like gate or penguin */
3546 Feld[x][y] = (Back[x][y] ? Back[x][y] : EL_EMPTY);
3553 /* save walkable background elements while explosion on same tile */
3554 if (IS_WALKABLE(element) && IS_INDESTRUCTIBLE(element) &&
3555 (x != ex || y != ey || mode == EX_TYPE_BORDER))
3556 Back[x][y] = element;
3558 /* ignite explodable elements reached by other explosion */
3559 if (element == EL_EXPLOSION)
3560 element = Store2[x][y];
3562 if (AmoebaNr[x][y] &&
3563 (element == EL_AMOEBA_FULL ||
3564 element == EL_BD_AMOEBA ||
3565 element == EL_AMOEBA_GROWING))
3567 AmoebaCnt[AmoebaNr[x][y]]--;
3568 AmoebaCnt2[AmoebaNr[x][y]]--;
3573 if (IS_PLAYER(ex, ey) && !PLAYER_EXPLOSION_PROTECTED(ex, ey))
3575 int player_nr = StorePlayer[ex][ey] - EL_PLAYER_1;
3577 Store[x][y] = EL_PLAYER_IS_EXPLODING_1 + player_nr;
3579 if (PLAYERINFO(ex, ey)->use_murphy)
3580 Store[x][y] = EL_EMPTY;
3583 /* !!! check this case -- currently needed for rnd_rado_negundo_v,
3584 !!! levels 015 018 019 020 021 022 023 026 027 028 !!! */
3585 else if (ELEM_IS_PLAYER(center_element))
3586 Store[x][y] = EL_EMPTY;
3587 else if (center_element == EL_YAMYAM)
3588 Store[x][y] = level.yamyam_content[game.yamyam_content_nr].e[xx][yy];
3589 else if (element_info[center_element].content.e[xx][yy] != EL_EMPTY)
3590 Store[x][y] = element_info[center_element].content.e[xx][yy];
3592 /* needed because EL_BD_BUTTERFLY is not defined as "CAN_EXPLODE"
3593 (killing EL_BD_BUTTERFLY with dynamite would result in BD diamond
3594 otherwise) -- FIX THIS !!! */
3595 else if (!CAN_EXPLODE(element) && element != EL_BD_BUTTERFLY)
3596 Store[x][y] = element_info[element].content.e[1][1];
3598 else if (!CAN_EXPLODE(element))
3599 Store[x][y] = element_info[element].content.e[1][1];
3602 Store[x][y] = EL_EMPTY;
3604 if (x != ex || y != ey || mode == EX_TYPE_BORDER ||
3605 center_element == EL_AMOEBA_TO_DIAMOND)
3606 Store2[x][y] = element;
3608 Feld[x][y] = EL_EXPLOSION;
3609 GfxElement[x][y] = artwork_element;
3611 ExplodePhase[x][y] = 1;
3612 ExplodeDelay[x][y] = last_phase;
3617 if (center_element == EL_YAMYAM)
3618 game.yamyam_content_nr =
3619 (game.yamyam_content_nr + 1) % level.num_yamyam_contents;
3631 GfxFrame[x][y] = 0; /* restart explosion animation */
3633 last_phase = ExplodeDelay[x][y];
3635 ExplodePhase[x][y] = (phase < last_phase ? phase + 1 : 0);
3639 /* activate this even in non-DEBUG version until cause for crash in
3640 getGraphicAnimationFrame() (see below) is found and eliminated */
3646 /* this can happen if the player leaves an explosion just in time */
3647 if (GfxElement[x][y] == EL_UNDEFINED)
3648 GfxElement[x][y] = EL_EMPTY;
3650 if (GfxElement[x][y] == EL_UNDEFINED)
3653 printf("Explode(): x = %d, y = %d: GfxElement == EL_UNDEFINED\n", x, y);
3654 printf("Explode(): This should never happen!\n");
3657 GfxElement[x][y] = EL_EMPTY;
3663 border_element = Store2[x][y];
3664 if (IS_PLAYER(x, y) && !PLAYER_EXPLOSION_PROTECTED(x, y))
3665 border_element = StorePlayer[x][y];
3667 if (phase == element_info[border_element].ignition_delay ||
3668 phase == last_phase)
3670 boolean border_explosion = FALSE;
3672 if (IS_PLAYER(x, y) && PLAYERINFO(x, y)->present &&
3673 !PLAYER_EXPLOSION_PROTECTED(x, y))
3675 KillPlayerUnlessExplosionProtected(x, y);
3676 border_explosion = TRUE;
3678 else if (CAN_EXPLODE_BY_EXPLOSION(border_element))
3680 Feld[x][y] = Store2[x][y];
3683 border_explosion = TRUE;
3685 else if (border_element == EL_AMOEBA_TO_DIAMOND)
3687 AmoebeUmwandeln(x, y);
3689 border_explosion = TRUE;
3692 /* if an element just explodes due to another explosion (chain-reaction),
3693 do not immediately end the new explosion when it was the last frame of
3694 the explosion (as it would be done in the following "if"-statement!) */
3695 if (border_explosion && phase == last_phase)
3699 if (phase == last_phase)
3703 element = Feld[x][y] = Store[x][y];
3704 Store[x][y] = Store2[x][y] = 0;
3705 GfxElement[x][y] = EL_UNDEFINED;
3707 /* player can escape from explosions and might therefore be still alive */
3708 if (element >= EL_PLAYER_IS_EXPLODING_1 &&
3709 element <= EL_PLAYER_IS_EXPLODING_4)
3711 int player_nr = element - EL_PLAYER_IS_EXPLODING_1;
3712 int explosion_element = EL_PLAYER_1 + player_nr;
3713 int xx = MIN(MAX(0, x - stored_player[player_nr].jx + 1), 2);
3714 int yy = MIN(MAX(0, y - stored_player[player_nr].jy + 1), 2);
3716 if (level.use_explosion_element[player_nr])
3717 explosion_element = level.explosion_element[player_nr];
3719 Feld[x][y] = (stored_player[player_nr].active ? EL_EMPTY :
3720 element_info[explosion_element].content.e[xx][yy]);
3723 /* restore probably existing indestructible background element */
3724 if (Back[x][y] && IS_INDESTRUCTIBLE(Back[x][y]))
3725 element = Feld[x][y] = Back[x][y];
3728 MovDir[x][y] = MovPos[x][y] = MovDelay[x][y] = 0;
3729 GfxDir[x][y] = MV_NONE;
3730 ChangeDelay[x][y] = 0;
3731 ChangePage[x][y] = -1;
3733 #if USE_NEW_CUSTOM_VALUE
3734 CustomValue[x][y] = 0;
3737 InitField_WithBug2(x, y, FALSE);
3739 DrawLevelField(x, y);
3741 TestIfElementTouchesCustomElement(x, y);
3743 if (GFX_CRUMBLED(element))
3744 DrawLevelFieldCrumbledSandNeighbours(x, y);
3746 if (IS_PLAYER(x, y) && !PLAYERINFO(x, y)->present)
3747 StorePlayer[x][y] = 0;
3749 if (ELEM_IS_PLAYER(element))
3750 RelocatePlayer(x, y, element);
3752 else if (IN_SCR_FIELD(SCREENX(x), SCREENY(y)))
3754 int graphic = el_act2img(GfxElement[x][y], ACTION_EXPLODING);
3755 int frame = getGraphicAnimationFrame(graphic, GfxFrame[x][y]);
3758 DrawLevelFieldCrumbledSand(x, y);
3760 if (IS_WALKABLE_OVER(Back[x][y]) && Back[x][y] != EL_EMPTY)
3762 DrawLevelElement(x, y, Back[x][y]);
3763 DrawGraphicThruMask(SCREENX(x), SCREENY(y), graphic, frame);
3765 else if (IS_WALKABLE_UNDER(Back[x][y]))
3767 DrawGraphic(SCREENX(x), SCREENY(y), graphic, frame);
3768 DrawLevelElementThruMask(x, y, Back[x][y]);
3770 else if (!IS_WALKABLE_INSIDE(Back[x][y]))
3771 DrawGraphic(SCREENX(x), SCREENY(y), graphic, frame);
3775 void DynaExplode(int ex, int ey)
3778 int dynabomb_element = Feld[ex][ey];
3779 int dynabomb_size = 1;
3780 boolean dynabomb_xl = FALSE;
3781 struct PlayerInfo *player;
3782 static int xy[4][2] =
3790 if (IS_ACTIVE_BOMB(dynabomb_element))
3792 player = &stored_player[dynabomb_element - EL_DYNABOMB_PLAYER_1_ACTIVE];
3793 dynabomb_size = player->dynabomb_size;
3794 dynabomb_xl = player->dynabomb_xl;
3795 player->dynabombs_left++;
3798 Explode(ex, ey, EX_PHASE_START, EX_TYPE_CENTER);
3800 for (i = 0; i < NUM_DIRECTIONS; i++)
3802 for (j = 1; j <= dynabomb_size; j++)
3804 int x = ex + j * xy[i][0];
3805 int y = ey + j * xy[i][1];
3808 if (!IN_LEV_FIELD(x, y) || IS_INDESTRUCTIBLE(Feld[x][y]))
3811 element = Feld[x][y];
3813 /* do not restart explosions of fields with active bombs */
3814 if (element == EL_EXPLOSION && IS_ACTIVE_BOMB(Store2[x][y]))
3817 Explode(x, y, EX_PHASE_START, EX_TYPE_BORDER);
3819 if (element != EL_EMPTY && element != EL_EXPLOSION &&
3820 !IS_DIGGABLE(element) && !dynabomb_xl)
3826 void Bang(int x, int y)
3828 int element = MovingOrBlocked2Element(x, y);
3829 int explosion_type = EX_TYPE_NORMAL;
3831 if (IS_PLAYER(x, y) && !PLAYER_EXPLOSION_PROTECTED(x, y))
3833 struct PlayerInfo *player = PLAYERINFO(x, y);
3835 element = Feld[x][y] = (player->use_murphy ? EL_SP_MURPHY :
3836 player->element_nr);
3838 if (level.use_explosion_element[player->index_nr])
3840 int explosion_element = level.explosion_element[player->index_nr];
3842 if (element_info[explosion_element].explosion_type == EXPLODES_CROSS)
3843 explosion_type = EX_TYPE_CROSS;
3844 else if (element_info[explosion_element].explosion_type == EXPLODES_1X1)
3845 explosion_type = EX_TYPE_CENTER;
3853 case EL_BD_BUTTERFLY:
3856 case EL_DARK_YAMYAM:
3860 RaiseScoreElement(element);
3863 case EL_DYNABOMB_PLAYER_1_ACTIVE:
3864 case EL_DYNABOMB_PLAYER_2_ACTIVE:
3865 case EL_DYNABOMB_PLAYER_3_ACTIVE:
3866 case EL_DYNABOMB_PLAYER_4_ACTIVE:
3867 case EL_DYNABOMB_INCREASE_NUMBER:
3868 case EL_DYNABOMB_INCREASE_SIZE:
3869 case EL_DYNABOMB_INCREASE_POWER:
3870 explosion_type = EX_TYPE_DYNA;
3875 case EL_LAMP_ACTIVE:
3876 case EL_AMOEBA_TO_DIAMOND:
3877 if (!IS_PLAYER(x, y)) /* penguin and player may be at same field */
3878 explosion_type = EX_TYPE_CENTER;
3882 if (element_info[element].explosion_type == EXPLODES_CROSS)
3883 explosion_type = EX_TYPE_CROSS;
3884 else if (element_info[element].explosion_type == EXPLODES_1X1)
3885 explosion_type = EX_TYPE_CENTER;
3889 if (explosion_type == EX_TYPE_DYNA)
3892 Explode(x, y, EX_PHASE_START, explosion_type);
3894 CheckTriggeredElementChange(x, y, element, CE_EXPLOSION_OF_X);
3897 void SplashAcid(int x, int y)
3899 if (IN_LEV_FIELD(x - 1, y - 1) && IS_FREE(x - 1, y - 1) &&
3900 (!IN_LEV_FIELD(x - 1, y - 2) ||
3901 !CAN_FALL(MovingOrBlocked2Element(x - 1, y - 2))))
3902 Feld[x - 1][y - 1] = EL_ACID_SPLASH_LEFT;
3904 if (IN_LEV_FIELD(x + 1, y - 1) && IS_FREE(x + 1, y - 1) &&
3905 (!IN_LEV_FIELD(x + 1, y - 2) ||
3906 !CAN_FALL(MovingOrBlocked2Element(x + 1, y - 2))))
3907 Feld[x + 1][y - 1] = EL_ACID_SPLASH_RIGHT;
3909 PlayLevelSound(x, y, SND_ACID_SPLASHING);
3912 static void InitBeltMovement()
3914 static int belt_base_element[4] =
3916 EL_CONVEYOR_BELT_1_LEFT,
3917 EL_CONVEYOR_BELT_2_LEFT,
3918 EL_CONVEYOR_BELT_3_LEFT,
3919 EL_CONVEYOR_BELT_4_LEFT
3921 static int belt_base_active_element[4] =
3923 EL_CONVEYOR_BELT_1_LEFT_ACTIVE,
3924 EL_CONVEYOR_BELT_2_LEFT_ACTIVE,
3925 EL_CONVEYOR_BELT_3_LEFT_ACTIVE,
3926 EL_CONVEYOR_BELT_4_LEFT_ACTIVE
3931 /* set frame order for belt animation graphic according to belt direction */
3932 for (i = 0; i < NUM_BELTS; i++)
3936 for (j = 0; j < NUM_BELT_PARTS; j++)
3938 int element = belt_base_active_element[belt_nr] + j;
3939 int graphic = el2img(element);
3941 if (game.belt_dir[i] == MV_LEFT)
3942 graphic_info[graphic].anim_mode &= ~ANIM_REVERSE;
3944 graphic_info[graphic].anim_mode |= ANIM_REVERSE;
3948 SCAN_PLAYFIELD(x, y)
3950 int element = Feld[x][y];
3952 for (i = 0; i < NUM_BELTS; i++)
3954 if (IS_BELT(element) && game.belt_dir[i] != MV_NONE)
3956 int e_belt_nr = getBeltNrFromBeltElement(element);
3959 if (e_belt_nr == belt_nr)
3961 int belt_part = Feld[x][y] - belt_base_element[belt_nr];
3963 Feld[x][y] = belt_base_active_element[belt_nr] + belt_part;
3970 static void ToggleBeltSwitch(int x, int y)
3972 static int belt_base_element[4] =
3974 EL_CONVEYOR_BELT_1_LEFT,
3975 EL_CONVEYOR_BELT_2_LEFT,
3976 EL_CONVEYOR_BELT_3_LEFT,
3977 EL_CONVEYOR_BELT_4_LEFT
3979 static int belt_base_active_element[4] =
3981 EL_CONVEYOR_BELT_1_LEFT_ACTIVE,
3982 EL_CONVEYOR_BELT_2_LEFT_ACTIVE,
3983 EL_CONVEYOR_BELT_3_LEFT_ACTIVE,
3984 EL_CONVEYOR_BELT_4_LEFT_ACTIVE
3986 static int belt_base_switch_element[4] =
3988 EL_CONVEYOR_BELT_1_SWITCH_LEFT,
3989 EL_CONVEYOR_BELT_2_SWITCH_LEFT,
3990 EL_CONVEYOR_BELT_3_SWITCH_LEFT,
3991 EL_CONVEYOR_BELT_4_SWITCH_LEFT
3993 static int belt_move_dir[4] =
4001 int element = Feld[x][y];
4002 int belt_nr = getBeltNrFromBeltSwitchElement(element);
4003 int belt_dir_nr = (game.belt_dir_nr[belt_nr] + 1) % 4;
4004 int belt_dir = belt_move_dir[belt_dir_nr];
4007 if (!IS_BELT_SWITCH(element))
4010 game.belt_dir_nr[belt_nr] = belt_dir_nr;
4011 game.belt_dir[belt_nr] = belt_dir;
4013 if (belt_dir_nr == 3)
4016 /* set frame order for belt animation graphic according to belt direction */
4017 for (i = 0; i < NUM_BELT_PARTS; i++)
4019 int element = belt_base_active_element[belt_nr] + i;
4020 int graphic = el2img(element);
4022 if (belt_dir == MV_LEFT)
4023 graphic_info[graphic].anim_mode &= ~ANIM_REVERSE;
4025 graphic_info[graphic].anim_mode |= ANIM_REVERSE;
4028 SCAN_PLAYFIELD(xx, yy)
4030 int element = Feld[xx][yy];
4032 if (IS_BELT_SWITCH(element))
4034 int e_belt_nr = getBeltNrFromBeltSwitchElement(element);
4036 if (e_belt_nr == belt_nr)
4038 Feld[xx][yy] = belt_base_switch_element[belt_nr] + belt_dir_nr;
4039 DrawLevelField(xx, yy);
4042 else if (IS_BELT(element) && belt_dir != MV_NONE)
4044 int e_belt_nr = getBeltNrFromBeltElement(element);
4046 if (e_belt_nr == belt_nr)
4048 int belt_part = Feld[xx][yy] - belt_base_element[belt_nr];
4050 Feld[xx][yy] = belt_base_active_element[belt_nr] + belt_part;
4051 DrawLevelField(xx, yy);
4054 else if (IS_BELT_ACTIVE(element) && belt_dir == MV_NONE)
4056 int e_belt_nr = getBeltNrFromBeltActiveElement(element);
4058 if (e_belt_nr == belt_nr)
4060 int belt_part = Feld[xx][yy] - belt_base_active_element[belt_nr];
4062 Feld[xx][yy] = belt_base_element[belt_nr] + belt_part;
4063 DrawLevelField(xx, yy);
4069 static void ToggleSwitchgateSwitch(int x, int y)
4073 game.switchgate_pos = !game.switchgate_pos;
4075 SCAN_PLAYFIELD(xx, yy)
4077 int element = Feld[xx][yy];
4079 #if !USE_BOTH_SWITCHGATE_SWITCHES
4080 if (element == EL_SWITCHGATE_SWITCH_UP ||
4081 element == EL_SWITCHGATE_SWITCH_DOWN)
4083 Feld[xx][yy] = EL_SWITCHGATE_SWITCH_UP + game.switchgate_pos;
4084 DrawLevelField(xx, yy);
4087 if (element == EL_SWITCHGATE_SWITCH_UP)
4089 Feld[xx][yy] = EL_SWITCHGATE_SWITCH_DOWN;
4090 DrawLevelField(xx, yy);
4092 else if (element == EL_SWITCHGATE_SWITCH_DOWN)
4094 Feld[xx][yy] = EL_SWITCHGATE_SWITCH_UP;
4095 DrawLevelField(xx, yy);
4098 else if (element == EL_SWITCHGATE_OPEN ||
4099 element == EL_SWITCHGATE_OPENING)
4101 Feld[xx][yy] = EL_SWITCHGATE_CLOSING;
4103 PlayLevelSoundAction(xx, yy, ACTION_CLOSING);
4105 else if (element == EL_SWITCHGATE_CLOSED ||
4106 element == EL_SWITCHGATE_CLOSING)
4108 Feld[xx][yy] = EL_SWITCHGATE_OPENING;
4110 PlayLevelSoundAction(xx, yy, ACTION_OPENING);
4115 static int getInvisibleActiveFromInvisibleElement(int element)
4117 return (element == EL_INVISIBLE_STEELWALL ? EL_INVISIBLE_STEELWALL_ACTIVE :
4118 element == EL_INVISIBLE_WALL ? EL_INVISIBLE_WALL_ACTIVE :
4119 element == EL_INVISIBLE_SAND ? EL_INVISIBLE_SAND_ACTIVE :
4123 static int getInvisibleFromInvisibleActiveElement(int element)
4125 return (element == EL_INVISIBLE_STEELWALL_ACTIVE ? EL_INVISIBLE_STEELWALL :
4126 element == EL_INVISIBLE_WALL_ACTIVE ? EL_INVISIBLE_WALL :
4127 element == EL_INVISIBLE_SAND_ACTIVE ? EL_INVISIBLE_SAND :
4131 static void RedrawAllLightSwitchesAndInvisibleElements()
4135 SCAN_PLAYFIELD(x, y)
4137 int element = Feld[x][y];
4139 if (element == EL_LIGHT_SWITCH &&
4140 game.light_time_left > 0)
4142 Feld[x][y] = EL_LIGHT_SWITCH_ACTIVE;
4143 DrawLevelField(x, y);
4145 else if (element == EL_LIGHT_SWITCH_ACTIVE &&
4146 game.light_time_left == 0)
4148 Feld[x][y] = EL_LIGHT_SWITCH;
4149 DrawLevelField(x, y);
4151 else if (element == EL_EMC_DRIPPER &&
4152 game.light_time_left > 0)
4154 Feld[x][y] = EL_EMC_DRIPPER_ACTIVE;
4155 DrawLevelField(x, y);
4157 else if (element == EL_EMC_DRIPPER_ACTIVE &&
4158 game.light_time_left == 0)
4160 Feld[x][y] = EL_EMC_DRIPPER;
4161 DrawLevelField(x, y);
4163 else if (element == EL_INVISIBLE_STEELWALL ||
4164 element == EL_INVISIBLE_WALL ||
4165 element == EL_INVISIBLE_SAND)
4167 if (game.light_time_left > 0)
4168 Feld[x][y] = getInvisibleActiveFromInvisibleElement(element);
4170 DrawLevelField(x, y);
4172 /* uncrumble neighbour fields, if needed */
4173 if (element == EL_INVISIBLE_SAND)
4174 DrawLevelFieldCrumbledSandNeighbours(x, y);
4176 else if (element == EL_INVISIBLE_STEELWALL_ACTIVE ||
4177 element == EL_INVISIBLE_WALL_ACTIVE ||
4178 element == EL_INVISIBLE_SAND_ACTIVE)
4180 if (game.light_time_left == 0)
4181 Feld[x][y] = getInvisibleFromInvisibleActiveElement(element);
4183 DrawLevelField(x, y);
4185 /* re-crumble neighbour fields, if needed */
4186 if (element == EL_INVISIBLE_SAND)
4187 DrawLevelFieldCrumbledSandNeighbours(x, y);
4192 static void RedrawAllInvisibleElementsForLenses()
4196 SCAN_PLAYFIELD(x, y)
4198 int element = Feld[x][y];
4200 if (element == EL_EMC_DRIPPER &&
4201 game.lenses_time_left > 0)
4203 Feld[x][y] = EL_EMC_DRIPPER_ACTIVE;
4204 DrawLevelField(x, y);
4206 else if (element == EL_EMC_DRIPPER_ACTIVE &&
4207 game.lenses_time_left == 0)
4209 Feld[x][y] = EL_EMC_DRIPPER;
4210 DrawLevelField(x, y);
4212 else if (element == EL_INVISIBLE_STEELWALL ||
4213 element == EL_INVISIBLE_WALL ||
4214 element == EL_INVISIBLE_SAND)
4216 if (game.lenses_time_left > 0)
4217 Feld[x][y] = getInvisibleActiveFromInvisibleElement(element);
4219 DrawLevelField(x, y);
4221 /* uncrumble neighbour fields, if needed */
4222 if (element == EL_INVISIBLE_SAND)
4223 DrawLevelFieldCrumbledSandNeighbours(x, y);
4225 else if (element == EL_INVISIBLE_STEELWALL_ACTIVE ||
4226 element == EL_INVISIBLE_WALL_ACTIVE ||
4227 element == EL_INVISIBLE_SAND_ACTIVE)
4229 if (game.lenses_time_left == 0)
4230 Feld[x][y] = getInvisibleFromInvisibleActiveElement(element);
4232 DrawLevelField(x, y);
4234 /* re-crumble neighbour fields, if needed */
4235 if (element == EL_INVISIBLE_SAND)
4236 DrawLevelFieldCrumbledSandNeighbours(x, y);
4241 static void RedrawAllInvisibleElementsForMagnifier()
4245 SCAN_PLAYFIELD(x, y)
4247 int element = Feld[x][y];
4249 if (element == EL_EMC_FAKE_GRASS &&
4250 game.magnify_time_left > 0)
4252 Feld[x][y] = EL_EMC_FAKE_GRASS_ACTIVE;
4253 DrawLevelField(x, y);
4255 else if (element == EL_EMC_FAKE_GRASS_ACTIVE &&
4256 game.magnify_time_left == 0)
4258 Feld[x][y] = EL_EMC_FAKE_GRASS;
4259 DrawLevelField(x, y);
4261 else if (IS_GATE_GRAY(element) &&
4262 game.magnify_time_left > 0)
4264 Feld[x][y] = (IS_RND_GATE_GRAY(element) ?
4265 element - EL_GATE_1_GRAY + EL_GATE_1_GRAY_ACTIVE :
4266 IS_EM_GATE_GRAY(element) ?
4267 element - EL_EM_GATE_1_GRAY + EL_EM_GATE_1_GRAY_ACTIVE :
4268 IS_EMC_GATE_GRAY(element) ?
4269 element - EL_EMC_GATE_5_GRAY + EL_EMC_GATE_5_GRAY_ACTIVE :
4271 DrawLevelField(x, y);
4273 else if (IS_GATE_GRAY_ACTIVE(element) &&
4274 game.magnify_time_left == 0)
4276 Feld[x][y] = (IS_RND_GATE_GRAY_ACTIVE(element) ?
4277 element - EL_GATE_1_GRAY_ACTIVE + EL_GATE_1_GRAY :
4278 IS_EM_GATE_GRAY_ACTIVE(element) ?
4279 element - EL_EM_GATE_1_GRAY_ACTIVE + EL_EM_GATE_1_GRAY :
4280 IS_EMC_GATE_GRAY_ACTIVE(element) ?
4281 element - EL_EMC_GATE_5_GRAY_ACTIVE + EL_EMC_GATE_5_GRAY :
4283 DrawLevelField(x, y);
4288 static void ToggleLightSwitch(int x, int y)
4290 int element = Feld[x][y];
4292 game.light_time_left =
4293 (element == EL_LIGHT_SWITCH ?
4294 level.time_light * FRAMES_PER_SECOND : 0);
4296 RedrawAllLightSwitchesAndInvisibleElements();
4299 static void ActivateTimegateSwitch(int x, int y)
4303 game.timegate_time_left = level.time_timegate * FRAMES_PER_SECOND;
4305 SCAN_PLAYFIELD(xx, yy)
4307 int element = Feld[xx][yy];
4309 if (element == EL_TIMEGATE_CLOSED ||
4310 element == EL_TIMEGATE_CLOSING)
4312 Feld[xx][yy] = EL_TIMEGATE_OPENING;
4313 PlayLevelSound(xx, yy, SND_TIMEGATE_OPENING);
4317 else if (element == EL_TIMEGATE_SWITCH_ACTIVE)
4319 Feld[xx][yy] = EL_TIMEGATE_SWITCH;
4320 DrawLevelField(xx, yy);
4326 Feld[x][y] = EL_TIMEGATE_SWITCH_ACTIVE;
4329 void Impact(int x, int y)
4331 boolean last_line = (y == lev_fieldy - 1);
4332 boolean object_hit = FALSE;
4333 boolean impact = (last_line || object_hit);
4334 int element = Feld[x][y];
4335 int smashed = EL_STEELWALL;
4337 if (!last_line) /* check if element below was hit */
4339 if (Feld[x][y + 1] == EL_PLAYER_IS_LEAVING)
4342 object_hit = (!IS_FREE(x, y + 1) && (!IS_MOVING(x, y + 1) ||
4343 MovDir[x][y + 1] != MV_DOWN ||
4344 MovPos[x][y + 1] <= TILEY / 2));
4346 /* do not smash moving elements that left the smashed field in time */
4347 if (game.engine_version >= VERSION_IDENT(2,2,0,7) && IS_MOVING(x, y + 1) &&
4348 ABS(MovPos[x][y + 1] + getElementMoveStepsize(x, y + 1)) >= TILEX)
4351 #if USE_QUICKSAND_IMPACT_BUGFIX
4352 if (Feld[x][y + 1] == EL_QUICKSAND_EMPTYING && object_hit == FALSE)
4354 RemoveMovingField(x, y + 1);
4355 Feld[x][y + 1] = EL_QUICKSAND_EMPTY;
4356 Feld[x][y + 2] = EL_ROCK;
4357 DrawLevelField(x, y + 2);
4364 smashed = MovingOrBlocked2Element(x, y + 1);
4366 impact = (last_line || object_hit);
4369 if (!last_line && smashed == EL_ACID) /* element falls into acid */
4371 SplashAcid(x, y + 1);
4375 /* !!! not sufficient for all cases -- see EL_PEARL below !!! */
4376 /* only reset graphic animation if graphic really changes after impact */
4378 el_act_dir2img(element, GfxAction[x][y], MV_DOWN) != el2img(element))
4380 ResetGfxAnimation(x, y);
4381 DrawLevelField(x, y);
4384 if (impact && CAN_EXPLODE_IMPACT(element))
4389 else if (impact && element == EL_PEARL)
4391 ResetGfxAnimation(x, y);
4393 Feld[x][y] = EL_PEARL_BREAKING;
4394 PlayLevelSound(x, y, SND_PEARL_BREAKING);
4397 else if (impact && CheckElementChange(x, y, element, smashed, CE_IMPACT))
4399 PlayLevelSoundElementAction(x, y, element, ACTION_IMPACT);
4404 if (impact && element == EL_AMOEBA_DROP)
4406 if (object_hit && IS_PLAYER(x, y + 1))
4407 KillPlayerUnlessEnemyProtected(x, y + 1);
4408 else if (object_hit && smashed == EL_PENGUIN)
4412 Feld[x][y] = EL_AMOEBA_GROWING;
4413 Store[x][y] = EL_AMOEBA_WET;
4415 ResetRandomAnimationValue(x, y);
4420 if (object_hit) /* check which object was hit */
4422 if (CAN_PASS_MAGIC_WALL(element) &&
4423 (smashed == EL_MAGIC_WALL ||
4424 smashed == EL_BD_MAGIC_WALL))
4427 int activated_magic_wall =
4428 (smashed == EL_MAGIC_WALL ? EL_MAGIC_WALL_ACTIVE :
4429 EL_BD_MAGIC_WALL_ACTIVE);
4431 /* activate magic wall / mill */
4432 SCAN_PLAYFIELD(xx, yy)
4433 if (Feld[xx][yy] == smashed)
4434 Feld[xx][yy] = activated_magic_wall;
4436 game.magic_wall_time_left = level.time_magic_wall * FRAMES_PER_SECOND;
4437 game.magic_wall_active = TRUE;
4439 PlayLevelSound(x, y, (smashed == EL_MAGIC_WALL ?
4440 SND_MAGIC_WALL_ACTIVATING :
4441 SND_BD_MAGIC_WALL_ACTIVATING));
4444 if (IS_PLAYER(x, y + 1))
4446 if (CAN_SMASH_PLAYER(element))
4448 KillPlayerUnlessEnemyProtected(x, y + 1);
4452 else if (smashed == EL_PENGUIN)
4454 if (CAN_SMASH_PLAYER(element))
4460 else if (element == EL_BD_DIAMOND)
4462 if (IS_CLASSIC_ENEMY(smashed) && IS_BD_ELEMENT(smashed))
4468 else if (((element == EL_SP_INFOTRON ||
4469 element == EL_SP_ZONK) &&
4470 (smashed == EL_SP_SNIKSNAK ||
4471 smashed == EL_SP_ELECTRON ||
4472 smashed == EL_SP_DISK_ORANGE)) ||
4473 (element == EL_SP_INFOTRON &&
4474 smashed == EL_SP_DISK_YELLOW))
4479 else if (CAN_SMASH_EVERYTHING(element))
4481 if (IS_CLASSIC_ENEMY(smashed) ||
4482 CAN_EXPLODE_SMASHED(smashed))
4487 else if (!IS_MOVING(x, y + 1) && !IS_BLOCKED(x, y + 1))
4489 if (smashed == EL_LAMP ||
4490 smashed == EL_LAMP_ACTIVE)
4495 else if (smashed == EL_NUT)
4497 Feld[x][y + 1] = EL_NUT_BREAKING;
4498 PlayLevelSound(x, y, SND_NUT_BREAKING);
4499 RaiseScoreElement(EL_NUT);
4502 else if (smashed == EL_PEARL)
4504 ResetGfxAnimation(x, y);
4506 Feld[x][y + 1] = EL_PEARL_BREAKING;
4507 PlayLevelSound(x, y, SND_PEARL_BREAKING);
4510 else if (smashed == EL_DIAMOND)
4512 Feld[x][y + 1] = EL_DIAMOND_BREAKING;
4513 PlayLevelSound(x, y, SND_DIAMOND_BREAKING);
4516 else if (IS_BELT_SWITCH(smashed))
4518 ToggleBeltSwitch(x, y + 1);
4520 else if (smashed == EL_SWITCHGATE_SWITCH_UP ||
4521 smashed == EL_SWITCHGATE_SWITCH_DOWN)
4523 ToggleSwitchgateSwitch(x, y + 1);
4525 else if (smashed == EL_LIGHT_SWITCH ||
4526 smashed == EL_LIGHT_SWITCH_ACTIVE)
4528 ToggleLightSwitch(x, y + 1);
4533 TestIfElementSmashesCustomElement(x, y, MV_DOWN);
4536 CheckElementChange(x, y + 1, smashed, element, CE_SMASHED);
4538 CheckElementChangeBySide(x, y + 1, smashed, element,
4539 CE_SWITCHED, CH_SIDE_TOP);
4540 CheckTriggeredElementChangeBySide(x, y + 1, smashed, CE_SWITCH_OF_X,
4546 CheckElementChange(x, y + 1, smashed, element, CE_SMASHED);
4551 /* play sound of magic wall / mill */
4553 (Feld[x][y + 1] == EL_MAGIC_WALL_ACTIVE ||
4554 Feld[x][y + 1] == EL_BD_MAGIC_WALL_ACTIVE))
4556 if (Feld[x][y + 1] == EL_MAGIC_WALL_ACTIVE)
4557 PlayLevelSound(x, y, SND_MAGIC_WALL_FILLING);
4558 else if (Feld[x][y + 1] == EL_BD_MAGIC_WALL_ACTIVE)
4559 PlayLevelSound(x, y, SND_BD_MAGIC_WALL_FILLING);
4564 /* play sound of object that hits the ground */
4565 if (last_line || object_hit)
4566 PlayLevelSoundElementAction(x, y, element, ACTION_IMPACT);
4569 inline static void TurnRoundExt(int x, int y)
4581 { 0, 0 }, { 0, 0 }, { 0, 0 },
4586 int left, right, back;
4590 { MV_DOWN, MV_UP, MV_RIGHT },
4591 { MV_UP, MV_DOWN, MV_LEFT },
4593 { MV_LEFT, MV_RIGHT, MV_DOWN },
4597 { MV_RIGHT, MV_LEFT, MV_UP }
4600 int element = Feld[x][y];
4601 int move_pattern = element_info[element].move_pattern;
4603 int old_move_dir = MovDir[x][y];
4604 int left_dir = turn[old_move_dir].left;
4605 int right_dir = turn[old_move_dir].right;
4606 int back_dir = turn[old_move_dir].back;
4608 int left_dx = move_xy[left_dir].dx, left_dy = move_xy[left_dir].dy;
4609 int right_dx = move_xy[right_dir].dx, right_dy = move_xy[right_dir].dy;
4610 int move_dx = move_xy[old_move_dir].dx, move_dy = move_xy[old_move_dir].dy;
4611 int back_dx = move_xy[back_dir].dx, back_dy = move_xy[back_dir].dy;
4613 int left_x = x + left_dx, left_y = y + left_dy;
4614 int right_x = x + right_dx, right_y = y + right_dy;
4615 int move_x = x + move_dx, move_y = y + move_dy;
4619 if (element == EL_BUG || element == EL_BD_BUTTERFLY)
4621 TestIfBadThingTouchesOtherBadThing(x, y);
4623 if (ENEMY_CAN_ENTER_FIELD(element, right_x, right_y))
4624 MovDir[x][y] = right_dir;
4625 else if (!ENEMY_CAN_ENTER_FIELD(element, move_x, move_y))
4626 MovDir[x][y] = left_dir;
4628 if (element == EL_BUG && MovDir[x][y] != old_move_dir)
4630 else if (element == EL_BD_BUTTERFLY) /* && MovDir[x][y] == left_dir) */
4633 else if (element == EL_SPACESHIP || element == EL_BD_FIREFLY)
4635 TestIfBadThingTouchesOtherBadThing(x, y);
4637 if (ENEMY_CAN_ENTER_FIELD(element, left_x, left_y))
4638 MovDir[x][y] = left_dir;
4639 else if (!ENEMY_CAN_ENTER_FIELD(element, move_x, move_y))
4640 MovDir[x][y] = right_dir;
4642 if (element == EL_SPACESHIP && MovDir[x][y] != old_move_dir)
4644 else if (element == EL_BD_FIREFLY) /* && MovDir[x][y] == right_dir) */
4647 else if (element == EL_SP_SNIKSNAK || element == EL_SP_ELECTRON)
4649 TestIfBadThingTouchesOtherBadThing(x, y);
4651 if (ELEMENT_CAN_ENTER_FIELD_BASE_4(element, left_x, left_y, 0))
4652 MovDir[x][y] = left_dir;
4653 else if (!ELEMENT_CAN_ENTER_FIELD_BASE_4(element, move_x, move_y, 0))
4654 MovDir[x][y] = right_dir;
4656 if (MovDir[x][y] != old_move_dir)
4659 else if (element == EL_YAMYAM)
4661 boolean can_turn_left = YAMYAM_CAN_ENTER_FIELD(element, left_x, left_y);
4662 boolean can_turn_right = YAMYAM_CAN_ENTER_FIELD(element, right_x, right_y);
4664 if (can_turn_left && can_turn_right)
4665 MovDir[x][y] = (RND(3) ? (RND(2) ? left_dir : right_dir) : back_dir);
4666 else if (can_turn_left)
4667 MovDir[x][y] = (RND(2) ? left_dir : back_dir);
4668 else if (can_turn_right)
4669 MovDir[x][y] = (RND(2) ? right_dir : back_dir);
4671 MovDir[x][y] = back_dir;
4673 MovDelay[x][y] = 16 + 16 * RND(3);
4675 else if (element == EL_DARK_YAMYAM)
4677 boolean can_turn_left = DARK_YAMYAM_CAN_ENTER_FIELD(element,
4679 boolean can_turn_right = DARK_YAMYAM_CAN_ENTER_FIELD(element,
4682 if (can_turn_left && can_turn_right)
4683 MovDir[x][y] = (RND(3) ? (RND(2) ? left_dir : right_dir) : back_dir);
4684 else if (can_turn_left)
4685 MovDir[x][y] = (RND(2) ? left_dir : back_dir);
4686 else if (can_turn_right)
4687 MovDir[x][y] = (RND(2) ? right_dir : back_dir);
4689 MovDir[x][y] = back_dir;
4691 MovDelay[x][y] = 16 + 16 * RND(3);
4693 else if (element == EL_PACMAN)
4695 boolean can_turn_left = PACMAN_CAN_ENTER_FIELD(element, left_x, left_y);
4696 boolean can_turn_right = PACMAN_CAN_ENTER_FIELD(element, right_x, right_y);
4698 if (can_turn_left && can_turn_right)
4699 MovDir[x][y] = (RND(3) ? (RND(2) ? left_dir : right_dir) : back_dir);
4700 else if (can_turn_left)
4701 MovDir[x][y] = (RND(2) ? left_dir : back_dir);
4702 else if (can_turn_right)
4703 MovDir[x][y] = (RND(2) ? right_dir : back_dir);
4705 MovDir[x][y] = back_dir;
4707 MovDelay[x][y] = 6 + RND(40);
4709 else if (element == EL_PIG)
4711 boolean can_turn_left = PIG_CAN_ENTER_FIELD(element, left_x, left_y);
4712 boolean can_turn_right = PIG_CAN_ENTER_FIELD(element, right_x, right_y);
4713 boolean can_move_on = PIG_CAN_ENTER_FIELD(element, move_x, move_y);
4714 boolean should_turn_left, should_turn_right, should_move_on;
4716 int rnd = RND(rnd_value);
4718 should_turn_left = (can_turn_left &&
4720 IN_LEV_FIELD_AND_NOT_FREE(x + back_dx + left_dx,
4721 y + back_dy + left_dy)));
4722 should_turn_right = (can_turn_right &&
4724 IN_LEV_FIELD_AND_NOT_FREE(x + back_dx + right_dx,
4725 y + back_dy + right_dy)));
4726 should_move_on = (can_move_on &&
4729 IN_LEV_FIELD_AND_NOT_FREE(x + move_dx + left_dx,
4730 y + move_dy + left_dy) ||
4731 IN_LEV_FIELD_AND_NOT_FREE(x + move_dx + right_dx,
4732 y + move_dy + right_dy)));
4734 if (should_turn_left || should_turn_right || should_move_on)
4736 if (should_turn_left && should_turn_right && should_move_on)
4737 MovDir[x][y] = (rnd < rnd_value / 3 ? left_dir :
4738 rnd < 2 * rnd_value / 3 ? right_dir :
4740 else if (should_turn_left && should_turn_right)
4741 MovDir[x][y] = (rnd < rnd_value / 2 ? left_dir : right_dir);
4742 else if (should_turn_left && should_move_on)
4743 MovDir[x][y] = (rnd < rnd_value / 2 ? left_dir : old_move_dir);
4744 else if (should_turn_right && should_move_on)
4745 MovDir[x][y] = (rnd < rnd_value / 2 ? right_dir : old_move_dir);
4746 else if (should_turn_left)
4747 MovDir[x][y] = left_dir;
4748 else if (should_turn_right)
4749 MovDir[x][y] = right_dir;
4750 else if (should_move_on)
4751 MovDir[x][y] = old_move_dir;
4753 else if (can_move_on && rnd > rnd_value / 8)
4754 MovDir[x][y] = old_move_dir;
4755 else if (can_turn_left && can_turn_right)
4756 MovDir[x][y] = (rnd < rnd_value / 2 ? left_dir : right_dir);
4757 else if (can_turn_left && rnd > rnd_value / 8)
4758 MovDir[x][y] = left_dir;
4759 else if (can_turn_right && rnd > rnd_value/8)
4760 MovDir[x][y] = right_dir;
4762 MovDir[x][y] = back_dir;
4764 xx = x + move_xy[MovDir[x][y]].dx;
4765 yy = y + move_xy[MovDir[x][y]].dy;
4767 if (!IN_LEV_FIELD(xx, yy) ||
4768 (!IS_FREE(xx, yy) && !IS_FOOD_PIG(Feld[xx][yy])))
4769 MovDir[x][y] = old_move_dir;
4773 else if (element == EL_DRAGON)
4775 boolean can_turn_left = DRAGON_CAN_ENTER_FIELD(element, left_x, left_y);
4776 boolean can_turn_right = DRAGON_CAN_ENTER_FIELD(element, right_x, right_y);
4777 boolean can_move_on = DRAGON_CAN_ENTER_FIELD(element, move_x, move_y);
4779 int rnd = RND(rnd_value);
4781 if (can_move_on && rnd > rnd_value / 8)
4782 MovDir[x][y] = old_move_dir;
4783 else if (can_turn_left && can_turn_right)
4784 MovDir[x][y] = (rnd < rnd_value / 2 ? left_dir : right_dir);
4785 else if (can_turn_left && rnd > rnd_value / 8)
4786 MovDir[x][y] = left_dir;
4787 else if (can_turn_right && rnd > rnd_value / 8)
4788 MovDir[x][y] = right_dir;
4790 MovDir[x][y] = back_dir;
4792 xx = x + move_xy[MovDir[x][y]].dx;
4793 yy = y + move_xy[MovDir[x][y]].dy;
4795 if (!IN_LEV_FIELD_AND_IS_FREE(xx, yy))
4796 MovDir[x][y] = old_move_dir;
4800 else if (element == EL_MOLE)
4802 boolean can_move_on =
4803 (MOLE_CAN_ENTER_FIELD(element, move_x, move_y,
4804 IS_AMOEBOID(Feld[move_x][move_y]) ||
4805 Feld[move_x][move_y] == EL_AMOEBA_SHRINKING));
4808 boolean can_turn_left =
4809 (MOLE_CAN_ENTER_FIELD(element, left_x, left_y,
4810 IS_AMOEBOID(Feld[left_x][left_y])));
4812 boolean can_turn_right =
4813 (MOLE_CAN_ENTER_FIELD(element, right_x, right_y,
4814 IS_AMOEBOID(Feld[right_x][right_y])));
4816 if (can_turn_left && can_turn_right)
4817 MovDir[x][y] = (RND(2) ? left_dir : right_dir);
4818 else if (can_turn_left)
4819 MovDir[x][y] = left_dir;
4821 MovDir[x][y] = right_dir;
4824 if (MovDir[x][y] != old_move_dir)
4827 else if (element == EL_BALLOON)
4829 MovDir[x][y] = game.wind_direction;
4832 else if (element == EL_SPRING)
4834 #if USE_NEW_SPRING_BUMPER
4835 if (MovDir[x][y] & MV_HORIZONTAL)
4837 if (SPRING_CAN_BUMP_FROM_FIELD(move_x, move_y) &&
4838 !SPRING_CAN_ENTER_FIELD(element, x, y + 1))
4840 Feld[move_x][move_y] = EL_EMC_SPRING_BUMPER_ACTIVE;
4841 ResetGfxAnimation(move_x, move_y);
4842 DrawLevelField(move_x, move_y);
4844 MovDir[x][y] = back_dir;
4846 else if (!SPRING_CAN_ENTER_FIELD(element, move_x, move_y) ||
4847 SPRING_CAN_ENTER_FIELD(element, x, y + 1))
4848 MovDir[x][y] = MV_NONE;
4851 if (MovDir[x][y] & MV_HORIZONTAL &&
4852 (!SPRING_CAN_ENTER_FIELD(element, move_x, move_y) ||
4853 SPRING_CAN_ENTER_FIELD(element, x, y + 1)))
4854 MovDir[x][y] = MV_NONE;
4859 else if (element == EL_ROBOT ||
4860 element == EL_SATELLITE ||
4861 element == EL_PENGUIN ||
4862 element == EL_EMC_ANDROID)
4864 int attr_x = -1, attr_y = -1;
4875 for (i = 0; i < MAX_PLAYERS; i++)
4877 struct PlayerInfo *player = &stored_player[i];
4878 int jx = player->jx, jy = player->jy;
4880 if (!player->active)
4884 ABS(jx - x) + ABS(jy - y) < ABS(attr_x - x) + ABS(attr_y - y))
4892 if (element == EL_ROBOT && ZX >= 0 && ZY >= 0 &&
4893 (Feld[ZX][ZY] == EL_ROBOT_WHEEL_ACTIVE ||
4894 game.engine_version < VERSION_IDENT(3,1,0,0)))
4900 if (element == EL_PENGUIN)
4903 static int xy[4][2] =
4911 for (i = 0; i < NUM_DIRECTIONS; i++)
4913 int ex = x + xy[i][0];
4914 int ey = y + xy[i][1];
4916 if (IN_LEV_FIELD(ex, ey) && Feld[ex][ey] == EL_EXIT_OPEN)
4925 MovDir[x][y] = MV_NONE;
4927 MovDir[x][y] |= (AllPlayersGone ? MV_RIGHT : MV_LEFT);
4928 else if (attr_x > x)
4929 MovDir[x][y] |= (AllPlayersGone ? MV_LEFT : MV_RIGHT);
4931 MovDir[x][y] |= (AllPlayersGone ? MV_DOWN : MV_UP);
4932 else if (attr_y > y)
4933 MovDir[x][y] |= (AllPlayersGone ? MV_UP : MV_DOWN);
4935 if (element == EL_ROBOT)
4939 if (MovDir[x][y] & MV_HORIZONTAL && MovDir[x][y] & MV_VERTICAL)
4940 MovDir[x][y] &= (RND(2) ? MV_HORIZONTAL : MV_VERTICAL);
4941 Moving2Blocked(x, y, &newx, &newy);
4943 if (IN_LEV_FIELD(newx, newy) && IS_FREE_OR_PLAYER(newx, newy))
4944 MovDelay[x][y] = 8 + 8 * !RND(3);
4946 MovDelay[x][y] = 16;
4948 else if (element == EL_PENGUIN)
4954 if (MovDir[x][y] & MV_HORIZONTAL && MovDir[x][y] & MV_VERTICAL)
4956 boolean first_horiz = RND(2);
4957 int new_move_dir = MovDir[x][y];
4960 new_move_dir & (first_horiz ? MV_HORIZONTAL : MV_VERTICAL);
4961 Moving2Blocked(x, y, &newx, &newy);
4963 if (PENGUIN_CAN_ENTER_FIELD(element, newx, newy))
4967 new_move_dir & (!first_horiz ? MV_HORIZONTAL : MV_VERTICAL);
4968 Moving2Blocked(x, y, &newx, &newy);
4970 if (PENGUIN_CAN_ENTER_FIELD(element, newx, newy))
4973 MovDir[x][y] = old_move_dir;
4977 else if (element == EL_SATELLITE)
4983 if (MovDir[x][y] & MV_HORIZONTAL && MovDir[x][y] & MV_VERTICAL)
4985 boolean first_horiz = RND(2);
4986 int new_move_dir = MovDir[x][y];
4989 new_move_dir & (first_horiz ? MV_HORIZONTAL : MV_VERTICAL);
4990 Moving2Blocked(x, y, &newx, &newy);
4992 if (SATELLITE_CAN_ENTER_FIELD(newx, newy))
4996 new_move_dir & (!first_horiz ? MV_HORIZONTAL : MV_VERTICAL);
4997 Moving2Blocked(x, y, &newx, &newy);
4999 if (SATELLITE_CAN_ENTER_FIELD(newx, newy))
5002 MovDir[x][y] = old_move_dir;
5006 else if (element == EL_EMC_ANDROID)
5008 static int check_pos[16] =
5010 -1, /* 0 => (invalid) */
5011 7, /* 1 => MV_LEFT */
5012 3, /* 2 => MV_RIGHT */
5013 -1, /* 3 => (invalid) */
5015 0, /* 5 => MV_LEFT | MV_UP */
5016 2, /* 6 => MV_RIGHT | MV_UP */
5017 -1, /* 7 => (invalid) */
5018 5, /* 8 => MV_DOWN */
5019 6, /* 9 => MV_LEFT | MV_DOWN */
5020 4, /* 10 => MV_RIGHT | MV_DOWN */
5021 -1, /* 11 => (invalid) */
5022 -1, /* 12 => (invalid) */
5023 -1, /* 13 => (invalid) */
5024 -1, /* 14 => (invalid) */
5025 -1, /* 15 => (invalid) */
5033 { -1, -1, MV_LEFT | MV_UP },
5035 { +1, -1, MV_RIGHT | MV_UP },
5036 { +1, 0, MV_RIGHT },
5037 { +1, +1, MV_RIGHT | MV_DOWN },
5039 { -1, +1, MV_LEFT | MV_DOWN },
5042 int start_pos, check_order;
5043 boolean can_clone = FALSE;
5046 /* check if there is any free field around current position */
5047 for (i = 0; i < 8; i++)
5049 int newx = x + check_xy[i].dx;
5050 int newy = y + check_xy[i].dy;
5052 if (IN_LEV_FIELD_AND_IS_FREE(newx, newy))
5060 if (can_clone) /* randomly find an element to clone */
5064 start_pos = check_pos[RND(8)];
5065 check_order = (RND(2) ? -1 : +1);
5067 for (i = 0; i < 8; i++)
5069 int pos_raw = start_pos + i * check_order;
5070 int pos = (pos_raw + 8) % 8;
5071 int newx = x + check_xy[pos].dx;
5072 int newy = y + check_xy[pos].dy;
5074 if (ANDROID_CAN_CLONE_FIELD(newx, newy))
5076 element_info[element].move_leave_type = LEAVE_TYPE_LIMITED;
5077 element_info[element].move_leave_element = EL_TRIGGER_ELEMENT;
5079 Store[x][y] = Feld[newx][newy];
5088 if (can_clone) /* randomly find a direction to move */
5092 start_pos = check_pos[RND(8)];
5093 check_order = (RND(2) ? -1 : +1);
5095 for (i = 0; i < 8; i++)
5097 int pos_raw = start_pos + i * check_order;
5098 int pos = (pos_raw + 8) % 8;
5099 int newx = x + check_xy[pos].dx;
5100 int newy = y + check_xy[pos].dy;
5101 int new_move_dir = check_xy[pos].dir;
5103 if (IN_LEV_FIELD_AND_IS_FREE(newx, newy))
5105 MovDir[x][y] = new_move_dir;
5106 MovDelay[x][y] = level.android_clone_time * 8 + 1;
5115 if (can_clone) /* cloning and moving successful */
5118 /* cannot clone -- try to move towards player */
5120 start_pos = check_pos[MovDir[x][y] & 0x0f];
5121 check_order = (RND(2) ? -1 : +1);
5123 for (i = 0; i < 3; i++)
5125 /* first check start_pos, then previous/next or (next/previous) pos */
5126 int pos_raw = start_pos + (i < 2 ? i : -1) * check_order;
5127 int pos = (pos_raw + 8) % 8;
5128 int newx = x + check_xy[pos].dx;
5129 int newy = y + check_xy[pos].dy;
5130 int new_move_dir = check_xy[pos].dir;
5132 if (IS_PLAYER(newx, newy))
5135 if (ANDROID_CAN_ENTER_FIELD(element, newx, newy))
5137 MovDir[x][y] = new_move_dir;
5138 MovDelay[x][y] = level.android_move_time * 8 + 1;
5145 else if (move_pattern == MV_TURNING_LEFT ||
5146 move_pattern == MV_TURNING_RIGHT ||
5147 move_pattern == MV_TURNING_LEFT_RIGHT ||
5148 move_pattern == MV_TURNING_RIGHT_LEFT ||
5149 move_pattern == MV_TURNING_RANDOM ||
5150 move_pattern == MV_ALL_DIRECTIONS)
5152 boolean can_turn_left =
5153 CUSTOM_ELEMENT_CAN_ENTER_FIELD(element, left_x, left_y);
5154 boolean can_turn_right =
5155 CUSTOM_ELEMENT_CAN_ENTER_FIELD(element, right_x,right_y);
5157 if (element_info[element].move_stepsize == 0) /* "not moving" */
5160 if (move_pattern == MV_TURNING_LEFT)
5161 MovDir[x][y] = left_dir;
5162 else if (move_pattern == MV_TURNING_RIGHT)
5163 MovDir[x][y] = right_dir;
5164 else if (move_pattern == MV_TURNING_LEFT_RIGHT)
5165 MovDir[x][y] = (can_turn_left || !can_turn_right ? left_dir : right_dir);
5166 else if (move_pattern == MV_TURNING_RIGHT_LEFT)
5167 MovDir[x][y] = (can_turn_right || !can_turn_left ? right_dir : left_dir);
5168 else if (move_pattern == MV_TURNING_RANDOM)
5169 MovDir[x][y] = (can_turn_left && !can_turn_right ? left_dir :
5170 can_turn_right && !can_turn_left ? right_dir :
5171 RND(2) ? left_dir : right_dir);
5172 else if (can_turn_left && can_turn_right)
5173 MovDir[x][y] = (RND(3) ? (RND(2) ? left_dir : right_dir) : back_dir);
5174 else if (can_turn_left)
5175 MovDir[x][y] = (RND(2) ? left_dir : back_dir);
5176 else if (can_turn_right)
5177 MovDir[x][y] = (RND(2) ? right_dir : back_dir);
5179 MovDir[x][y] = back_dir;
5181 MovDelay[x][y] = GET_NEW_MOVE_DELAY(element);
5183 else if (move_pattern == MV_HORIZONTAL ||
5184 move_pattern == MV_VERTICAL)
5186 if (move_pattern & old_move_dir)
5187 MovDir[x][y] = back_dir;
5188 else if (move_pattern == MV_HORIZONTAL)
5189 MovDir[x][y] = (RND(2) ? MV_LEFT : MV_RIGHT);
5190 else if (move_pattern == MV_VERTICAL)
5191 MovDir[x][y] = (RND(2) ? MV_UP : MV_DOWN);
5193 MovDelay[x][y] = GET_NEW_MOVE_DELAY(element);
5195 else if (move_pattern & MV_ANY_DIRECTION)
5197 MovDir[x][y] = move_pattern;
5198 MovDelay[x][y] = GET_NEW_MOVE_DELAY(element);
5200 else if (move_pattern & MV_WIND_DIRECTION)
5202 MovDir[x][y] = game.wind_direction;
5203 MovDelay[x][y] = GET_NEW_MOVE_DELAY(element);
5205 else if (move_pattern == MV_ALONG_LEFT_SIDE)
5207 if (CUSTOM_ELEMENT_CAN_ENTER_FIELD(element, left_x, left_y))
5208 MovDir[x][y] = left_dir;
5209 else if (!CUSTOM_ELEMENT_CAN_ENTER_FIELD(element, move_x, move_y))
5210 MovDir[x][y] = right_dir;
5212 if (MovDir[x][y] != old_move_dir)
5213 MovDelay[x][y] = GET_NEW_MOVE_DELAY(element);
5215 else if (move_pattern == MV_ALONG_RIGHT_SIDE)
5217 if (CUSTOM_ELEMENT_CAN_ENTER_FIELD(element, right_x, right_y))
5218 MovDir[x][y] = right_dir;
5219 else if (!CUSTOM_ELEMENT_CAN_ENTER_FIELD(element, move_x, move_y))
5220 MovDir[x][y] = left_dir;
5222 if (MovDir[x][y] != old_move_dir)
5223 MovDelay[x][y] = GET_NEW_MOVE_DELAY(element);
5225 else if (move_pattern == MV_TOWARDS_PLAYER ||
5226 move_pattern == MV_AWAY_FROM_PLAYER)
5228 int attr_x = -1, attr_y = -1;
5230 boolean move_away = (move_pattern == MV_AWAY_FROM_PLAYER);
5241 for (i = 0; i < MAX_PLAYERS; i++)
5243 struct PlayerInfo *player = &stored_player[i];
5244 int jx = player->jx, jy = player->jy;
5246 if (!player->active)
5250 ABS(jx - x) + ABS(jy - y) < ABS(attr_x - x) + ABS(attr_y - y))
5258 MovDir[x][y] = MV_NONE;
5260 MovDir[x][y] |= (move_away ? MV_RIGHT : MV_LEFT);
5261 else if (attr_x > x)
5262 MovDir[x][y] |= (move_away ? MV_LEFT : MV_RIGHT);
5264 MovDir[x][y] |= (move_away ? MV_DOWN : MV_UP);
5265 else if (attr_y > y)
5266 MovDir[x][y] |= (move_away ? MV_UP : MV_DOWN);
5268 MovDelay[x][y] = GET_NEW_MOVE_DELAY(element);
5270 if (MovDir[x][y] & MV_HORIZONTAL && MovDir[x][y] & MV_VERTICAL)
5272 boolean first_horiz = RND(2);
5273 int new_move_dir = MovDir[x][y];
5275 if (element_info[element].move_stepsize == 0) /* "not moving" */
5277 first_horiz = (ABS(attr_x - x) >= ABS(attr_y - y));
5278 MovDir[x][y] &= (first_horiz ? MV_HORIZONTAL : MV_VERTICAL);
5284 new_move_dir & (first_horiz ? MV_HORIZONTAL : MV_VERTICAL);
5285 Moving2Blocked(x, y, &newx, &newy);
5287 if (CUSTOM_ELEMENT_CAN_ENTER_FIELD(element, newx, newy))
5291 new_move_dir & (!first_horiz ? MV_HORIZONTAL : MV_VERTICAL);
5292 Moving2Blocked(x, y, &newx, &newy);
5294 if (CUSTOM_ELEMENT_CAN_ENTER_FIELD(element, newx, newy))
5297 MovDir[x][y] = old_move_dir;
5300 else if (move_pattern == MV_WHEN_PUSHED ||
5301 move_pattern == MV_WHEN_DROPPED)
5303 if (!CUSTOM_ELEMENT_CAN_ENTER_FIELD(element, move_x, move_y))
5304 MovDir[x][y] = MV_NONE;
5308 else if (move_pattern & MV_MAZE_RUNNER_STYLE)
5310 static int test_xy[7][2] =
5320 static int test_dir[7] =
5330 boolean hunter_mode = (move_pattern == MV_MAZE_HUNTER);
5331 int move_preference = -1000000; /* start with very low preference */
5332 int new_move_dir = MV_NONE;
5333 int start_test = RND(4);
5336 for (i = 0; i < NUM_DIRECTIONS; i++)
5338 int move_dir = test_dir[start_test + i];
5339 int move_dir_preference;
5341 xx = x + test_xy[start_test + i][0];
5342 yy = y + test_xy[start_test + i][1];
5344 if (hunter_mode && IN_LEV_FIELD(xx, yy) &&
5345 (IS_PLAYER(xx, yy) || Feld[xx][yy] == EL_PLAYER_IS_LEAVING))
5347 new_move_dir = move_dir;
5352 if (!CUSTOM_ELEMENT_CAN_ENTER_FIELD(element, xx, yy))
5355 move_dir_preference = -1 * RunnerVisit[xx][yy];
5356 if (hunter_mode && PlayerVisit[xx][yy] > 0)
5357 move_dir_preference = PlayerVisit[xx][yy];
5359 if (move_dir_preference > move_preference)
5361 /* prefer field that has not been visited for the longest time */
5362 move_preference = move_dir_preference;
5363 new_move_dir = move_dir;
5365 else if (move_dir_preference == move_preference &&
5366 move_dir == old_move_dir)
5368 /* prefer last direction when all directions are preferred equally */
5369 move_preference = move_dir_preference;
5370 new_move_dir = move_dir;
5374 MovDir[x][y] = new_move_dir;
5375 if (old_move_dir != new_move_dir)
5376 MovDelay[x][y] = GET_NEW_MOVE_DELAY(element);
5380 static void TurnRound(int x, int y)
5382 int direction = MovDir[x][y];
5386 GfxDir[x][y] = MovDir[x][y];
5388 if (direction != MovDir[x][y])
5392 GfxAction[x][y] = ACTION_TURNING_FROM_LEFT + MV_DIR_TO_BIT(direction);
5394 ResetGfxFrame(x, y, FALSE);
5397 static boolean JustBeingPushed(int x, int y)
5401 for (i = 0; i < MAX_PLAYERS; i++)
5403 struct PlayerInfo *player = &stored_player[i];
5405 if (player->active && player->is_pushing && player->MovPos)
5407 int next_jx = player->jx + (player->jx - player->last_jx);
5408 int next_jy = player->jy + (player->jy - player->last_jy);
5410 if (x == next_jx && y == next_jy)
5418 void StartMoving(int x, int y)
5420 boolean started_moving = FALSE; /* some elements can fall _and_ move */
5421 int element = Feld[x][y];
5426 if (MovDelay[x][y] == 0)
5427 GfxAction[x][y] = ACTION_DEFAULT;
5429 if (CAN_FALL(element) && y < lev_fieldy - 1)
5431 if ((x > 0 && IS_PLAYER(x - 1, y)) ||
5432 (x < lev_fieldx - 1 && IS_PLAYER(x + 1, y)))
5433 if (JustBeingPushed(x, y))
5436 if (element == EL_QUICKSAND_FULL)
5438 if (IS_FREE(x, y + 1))
5440 InitMovingField(x, y, MV_DOWN);
5441 started_moving = TRUE;
5443 Feld[x][y] = EL_QUICKSAND_EMPTYING;
5444 #if USE_QUICKSAND_BD_ROCK_BUGFIX
5445 if (Store[x][y] != EL_ROCK && Store[x][y] != EL_BD_ROCK)
5446 Store[x][y] = EL_ROCK;
5448 Store[x][y] = EL_ROCK;
5451 PlayLevelSoundAction(x, y, ACTION_EMPTYING);
5453 else if (Feld[x][y + 1] == EL_QUICKSAND_EMPTY)
5455 if (!MovDelay[x][y])
5456 MovDelay[x][y] = TILEY + 1;
5465 Feld[x][y] = EL_QUICKSAND_EMPTY;
5466 Feld[x][y + 1] = EL_QUICKSAND_FULL;
5467 Store[x][y + 1] = Store[x][y];
5470 PlayLevelSoundAction(x, y, ACTION_FILLING);
5473 else if ((element == EL_ROCK || element == EL_BD_ROCK) &&
5474 Feld[x][y + 1] == EL_QUICKSAND_EMPTY)
5476 InitMovingField(x, y, MV_DOWN);
5477 started_moving = TRUE;
5479 Feld[x][y] = EL_QUICKSAND_FILLING;
5480 Store[x][y] = element;
5482 PlayLevelSoundAction(x, y, ACTION_FILLING);
5484 else if (element == EL_MAGIC_WALL_FULL)
5486 if (IS_FREE(x, y + 1))
5488 InitMovingField(x, y, MV_DOWN);
5489 started_moving = TRUE;
5491 Feld[x][y] = EL_MAGIC_WALL_EMPTYING;
5492 Store[x][y] = EL_CHANGED(Store[x][y]);
5494 else if (Feld[x][y + 1] == EL_MAGIC_WALL_ACTIVE)
5496 if (!MovDelay[x][y])
5497 MovDelay[x][y] = TILEY/4 + 1;
5506 Feld[x][y] = EL_MAGIC_WALL_ACTIVE;
5507 Feld[x][y + 1] = EL_MAGIC_WALL_FULL;
5508 Store[x][y + 1] = EL_CHANGED(Store[x][y]);
5512 else if (element == EL_BD_MAGIC_WALL_FULL)
5514 if (IS_FREE(x, y + 1))
5516 InitMovingField(x, y, MV_DOWN);
5517 started_moving = TRUE;
5519 Feld[x][y] = EL_BD_MAGIC_WALL_EMPTYING;
5520 Store[x][y] = EL_CHANGED2(Store[x][y]);
5522 else if (Feld[x][y + 1] == EL_BD_MAGIC_WALL_ACTIVE)
5524 if (!MovDelay[x][y])
5525 MovDelay[x][y] = TILEY/4 + 1;
5534 Feld[x][y] = EL_BD_MAGIC_WALL_ACTIVE;
5535 Feld[x][y + 1] = EL_BD_MAGIC_WALL_FULL;
5536 Store[x][y + 1] = EL_CHANGED2(Store[x][y]);
5540 else if (CAN_PASS_MAGIC_WALL(element) &&
5541 (Feld[x][y + 1] == EL_MAGIC_WALL_ACTIVE ||
5542 Feld[x][y + 1] == EL_BD_MAGIC_WALL_ACTIVE))
5544 InitMovingField(x, y, MV_DOWN);
5545 started_moving = TRUE;
5548 (Feld[x][y + 1] == EL_MAGIC_WALL_ACTIVE ? EL_MAGIC_WALL_FILLING :
5549 EL_BD_MAGIC_WALL_FILLING);
5550 Store[x][y] = element;
5552 else if (CAN_FALL(element) && Feld[x][y + 1] == EL_ACID)
5554 SplashAcid(x, y + 1);
5556 InitMovingField(x, y, MV_DOWN);
5557 started_moving = TRUE;
5559 Store[x][y] = EL_ACID;
5561 else if ((game.engine_version >= VERSION_IDENT(3,1,0,0) &&
5562 CheckCollision[x][y] && !IS_FREE(x, y + 1)) ||
5564 (game.engine_version >= VERSION_IDENT(3,0,7,0) &&
5565 CAN_FALL(element) && WasJustFalling[x][y] &&
5566 (Feld[x][y + 1] == EL_BLOCKED || IS_PLAYER(x, y + 1))) ||
5568 (game.engine_version < VERSION_IDENT(2,2,0,7) &&
5569 CAN_FALL(element) && WasJustMoving[x][y] && !Pushed[x][y + 1] &&
5570 (Feld[x][y + 1] == EL_BLOCKED)))
5572 /* this is needed for a special case not covered by calling "Impact()"
5573 from "ContinueMoving()": if an element moves to a tile directly below
5574 another element which was just falling on that tile (which was empty
5575 in the previous frame), the falling element above would just stop
5576 instead of smashing the element below (in previous version, the above
5577 element was just checked for "moving" instead of "falling", resulting
5578 in incorrect smashes caused by horizontal movement of the above
5579 element; also, the case of the player being the element to smash was
5580 simply not covered here... :-/ ) */
5582 CheckCollision[x][y] = 0;
5586 else if (IS_FREE(x, y + 1) && element == EL_SPRING && level.use_spring_bug)
5588 if (MovDir[x][y] == MV_NONE)
5590 InitMovingField(x, y, MV_DOWN);
5591 started_moving = TRUE;
5594 else if (IS_FREE(x, y + 1) || Feld[x][y + 1] == EL_DIAMOND_BREAKING)
5596 if (WasJustFalling[x][y]) /* prevent animation from being restarted */
5597 MovDir[x][y] = MV_DOWN;
5599 InitMovingField(x, y, MV_DOWN);
5600 started_moving = TRUE;
5602 else if (element == EL_AMOEBA_DROP)
5604 Feld[x][y] = EL_AMOEBA_GROWING;
5605 Store[x][y] = EL_AMOEBA_WET;
5607 else if (((IS_SLIPPERY(Feld[x][y + 1]) && !IS_PLAYER(x, y + 1)) ||
5608 (IS_EM_SLIPPERY_WALL(Feld[x][y + 1]) && IS_GEM(element))) &&
5609 !IS_FALLING(x, y + 1) && !WasJustMoving[x][y + 1] &&
5610 element != EL_DX_SUPABOMB && element != EL_SP_DISK_ORANGE)
5612 boolean can_fall_left = (x > 0 && IS_FREE(x - 1, y) &&
5613 (IS_FREE(x - 1, y + 1) ||
5614 Feld[x - 1][y + 1] == EL_ACID));
5615 boolean can_fall_right = (x < lev_fieldx - 1 && IS_FREE(x + 1, y) &&
5616 (IS_FREE(x + 1, y + 1) ||
5617 Feld[x + 1][y + 1] == EL_ACID));
5618 boolean can_fall_any = (can_fall_left || can_fall_right);
5619 boolean can_fall_both = (can_fall_left && can_fall_right);
5620 int slippery_type = element_info[Feld[x][y + 1]].slippery_type;
5622 #if USE_NEW_ALL_SLIPPERY
5623 if (can_fall_any && slippery_type != SLIPPERY_ANY_RANDOM)
5625 if (slippery_type == SLIPPERY_ANY_LEFT_RIGHT && can_fall_both)
5626 can_fall_right = FALSE;
5627 else if (slippery_type == SLIPPERY_ANY_RIGHT_LEFT && can_fall_both)
5628 can_fall_left = FALSE;
5629 else if (slippery_type == SLIPPERY_ONLY_LEFT)
5630 can_fall_right = FALSE;
5631 else if (slippery_type == SLIPPERY_ONLY_RIGHT)
5632 can_fall_left = FALSE;
5634 can_fall_any = (can_fall_left || can_fall_right);
5635 can_fall_both = FALSE;
5638 if (can_fall_any && IS_CUSTOM_ELEMENT(Feld[x][y + 1]))
5640 if (slippery_type == SLIPPERY_ONLY_LEFT)
5641 can_fall_right = FALSE;
5642 else if (slippery_type == SLIPPERY_ONLY_RIGHT)
5643 can_fall_left = FALSE;
5644 else if (slippery_type == SLIPPERY_ANY_LEFT_RIGHT && can_fall_both)
5645 can_fall_right = FALSE;
5646 else if (slippery_type == SLIPPERY_ANY_RIGHT_LEFT && can_fall_both)
5647 can_fall_left = FALSE;
5649 can_fall_any = (can_fall_left || can_fall_right);
5650 can_fall_both = (can_fall_left && can_fall_right);
5654 #if USE_NEW_ALL_SLIPPERY
5656 #if USE_NEW_SP_SLIPPERY
5657 /* !!! better use the same properties as for custom elements here !!! */
5658 else if (game.engine_version >= VERSION_IDENT(3,1,1,0) &&
5659 can_fall_both && IS_SP_ELEMENT(Feld[x][y + 1]))
5661 can_fall_right = FALSE; /* slip down on left side */
5662 can_fall_both = FALSE;
5667 #if USE_NEW_ALL_SLIPPERY
5670 if (element == EL_BD_ROCK || element == EL_BD_DIAMOND)
5671 can_fall_right = FALSE; /* slip down on left side */
5673 can_fall_left = !(can_fall_right = RND(2));
5675 can_fall_both = FALSE;
5680 if (game.emulation == EMU_BOULDERDASH ||
5681 element == EL_BD_ROCK || element == EL_BD_DIAMOND)
5682 can_fall_right = FALSE; /* slip down on left side */
5684 can_fall_left = !(can_fall_right = RND(2));
5686 can_fall_both = FALSE;
5692 /* if not determined otherwise, prefer left side for slipping down */
5693 InitMovingField(x, y, can_fall_left ? MV_LEFT : MV_RIGHT);
5694 started_moving = TRUE;
5698 else if (IS_BELT_ACTIVE(Feld[x][y + 1]) && !CAN_MOVE(element))
5700 else if (IS_BELT_ACTIVE(Feld[x][y + 1]))
5703 boolean left_is_free = (x > 0 && IS_FREE(x - 1, y));
5704 boolean right_is_free = (x < lev_fieldx - 1 && IS_FREE(x + 1, y));
5705 int belt_nr = getBeltNrFromBeltActiveElement(Feld[x][y + 1]);
5706 int belt_dir = game.belt_dir[belt_nr];
5708 if ((belt_dir == MV_LEFT && left_is_free) ||
5709 (belt_dir == MV_RIGHT && right_is_free))
5711 int nextx = (belt_dir == MV_LEFT ? x - 1 : x + 1);
5713 InitMovingField(x, y, belt_dir);
5714 started_moving = TRUE;
5716 Pushed[x][y] = TRUE;
5717 Pushed[nextx][y] = TRUE;
5719 GfxAction[x][y] = ACTION_DEFAULT;
5723 MovDir[x][y] = 0; /* if element was moving, stop it */
5728 /* not "else if" because of elements that can fall and move (EL_SPRING) */
5730 if (CAN_MOVE(element) && !started_moving && MovDir[x][y] != MV_NONE)
5732 if (CAN_MOVE(element) && !started_moving)
5735 int move_pattern = element_info[element].move_pattern;
5740 if (MovDir[x][y] == MV_NONE)
5742 printf("StartMoving(): %d,%d: element %d ['%s'] not moving\n",
5743 x, y, element, element_info[element].token_name);
5744 printf("StartMoving(): This should never happen!\n");
5749 Moving2Blocked(x, y, &newx, &newy);
5751 if (IS_PUSHABLE(element) && JustBeingPushed(x, y))
5754 if (game.engine_version >= VERSION_IDENT(3,1,0,0) &&
5755 CheckCollision[x][y] && !IN_LEV_FIELD_AND_IS_FREE(newx, newy))
5757 WasJustMoving[x][y] = 0;
5758 CheckCollision[x][y] = 0;
5760 TestIfElementHitsCustomElement(x, y, MovDir[x][y]);
5762 if (Feld[x][y] != element) /* element has changed */
5766 if (!MovDelay[x][y]) /* start new movement phase */
5768 /* all objects that can change their move direction after each step
5769 (YAMYAM, DARK_YAMYAM and PACMAN go straight until they hit a wall */
5771 if (element != EL_YAMYAM &&
5772 element != EL_DARK_YAMYAM &&
5773 element != EL_PACMAN &&
5774 !(move_pattern & MV_ANY_DIRECTION) &&
5775 move_pattern != MV_TURNING_LEFT &&
5776 move_pattern != MV_TURNING_RIGHT &&
5777 move_pattern != MV_TURNING_LEFT_RIGHT &&
5778 move_pattern != MV_TURNING_RIGHT_LEFT &&
5779 move_pattern != MV_TURNING_RANDOM)
5783 if (MovDelay[x][y] && (element == EL_BUG ||
5784 element == EL_SPACESHIP ||
5785 element == EL_SP_SNIKSNAK ||
5786 element == EL_SP_ELECTRON ||
5787 element == EL_MOLE))
5788 DrawLevelField(x, y);
5792 if (MovDelay[x][y]) /* wait some time before next movement */
5796 if (element == EL_ROBOT ||
5797 element == EL_YAMYAM ||
5798 element == EL_DARK_YAMYAM)
5800 DrawLevelElementAnimationIfNeeded(x, y, element);
5801 PlayLevelSoundAction(x, y, ACTION_WAITING);
5803 else if (element == EL_SP_ELECTRON)
5804 DrawLevelElementAnimationIfNeeded(x, y, element);
5805 else if (element == EL_DRAGON)
5808 int dir = MovDir[x][y];
5809 int dx = (dir == MV_LEFT ? -1 : dir == MV_RIGHT ? +1 : 0);
5810 int dy = (dir == MV_UP ? -1 : dir == MV_DOWN ? +1 : 0);
5811 int graphic = (dir == MV_LEFT ? IMG_FLAMES_1_LEFT :
5812 dir == MV_RIGHT ? IMG_FLAMES_1_RIGHT :
5813 dir == MV_UP ? IMG_FLAMES_1_UP :
5814 dir == MV_DOWN ? IMG_FLAMES_1_DOWN : IMG_EMPTY);
5815 int frame = getGraphicAnimationFrame(graphic, GfxFrame[x][y]);
5817 GfxAction[x][y] = ACTION_ATTACKING;
5819 if (IS_PLAYER(x, y))
5820 DrawPlayerField(x, y);
5822 DrawLevelField(x, y);
5824 PlayLevelSoundActionIfLoop(x, y, ACTION_ATTACKING);
5826 for (i = 1; i <= 3; i++)
5828 int xx = x + i * dx;
5829 int yy = y + i * dy;
5830 int sx = SCREENX(xx);
5831 int sy = SCREENY(yy);
5832 int flame_graphic = graphic + (i - 1);
5834 if (!IN_LEV_FIELD(xx, yy) || IS_DRAGONFIRE_PROOF(Feld[xx][yy]))
5839 int flamed = MovingOrBlocked2Element(xx, yy);
5843 if (IS_CLASSIC_ENEMY(flamed) || CAN_EXPLODE_BY_DRAGONFIRE(flamed))
5845 else if (IS_MOVING(xx, yy) || IS_BLOCKED(xx, yy))
5846 RemoveMovingField(xx, yy);
5848 RemoveField(xx, yy);
5850 if (IS_CLASSIC_ENEMY(flamed) || CAN_EXPLODE_BY_DRAGONFIRE(flamed))
5853 RemoveMovingField(xx, yy);
5856 ChangeDelay[xx][yy] = 0;
5858 Feld[xx][yy] = EL_FLAMES;
5860 if (IN_SCR_FIELD(sx, sy))
5862 DrawLevelFieldCrumbledSand(xx, yy);
5863 DrawGraphic(sx, sy, flame_graphic, frame);
5868 if (Feld[xx][yy] == EL_FLAMES)
5869 Feld[xx][yy] = EL_EMPTY;
5870 DrawLevelField(xx, yy);
5875 if (MovDelay[x][y]) /* element still has to wait some time */
5877 PlayLevelSoundAction(x, y, ACTION_WAITING);
5883 /* now make next step */
5885 Moving2Blocked(x, y, &newx, &newy); /* get next screen position */
5887 if (DONT_COLLIDE_WITH(element) &&
5888 IN_LEV_FIELD(newx, newy) && IS_PLAYER(newx, newy) &&
5889 !PLAYER_ENEMY_PROTECTED(newx, newy))
5891 TestIfBadThingRunsIntoPlayer(x, y, MovDir[x][y]);
5896 else if (CAN_MOVE_INTO_ACID(element) &&
5897 IN_LEV_FIELD(newx, newy) && Feld[newx][newy] == EL_ACID &&
5898 !IS_MV_DIAGONAL(MovDir[x][y]) &&
5899 (MovDir[x][y] == MV_DOWN ||
5900 game.engine_version >= VERSION_IDENT(3,1,0,0)))
5902 SplashAcid(newx, newy);
5903 Store[x][y] = EL_ACID;
5905 else if (element == EL_PENGUIN && IN_LEV_FIELD(newx, newy))
5907 if (Feld[newx][newy] == EL_EXIT_OPEN)
5910 DrawLevelField(x, y);
5912 PlayLevelSound(newx, newy, SND_PENGUIN_PASSING);
5913 if (IN_SCR_FIELD(SCREENX(newx), SCREENY(newy)))
5914 DrawGraphicThruMask(SCREENX(newx),SCREENY(newy), el2img(element), 0);
5916 local_player->friends_still_needed--;
5917 if (!local_player->friends_still_needed &&
5918 !local_player->GameOver && AllPlayersGone)
5919 PlayerWins(local_player);
5923 else if (IS_FOOD_PENGUIN(Feld[newx][newy]))
5925 if (DigField(local_player, x, y, newx, newy, 0,0, DF_DIG) == MP_MOVING)
5926 DrawLevelField(newx, newy);
5928 GfxDir[x][y] = MovDir[x][y] = MV_NONE;
5930 else if (!IS_FREE(newx, newy))
5932 GfxAction[x][y] = ACTION_WAITING;
5934 if (IS_PLAYER(x, y))
5935 DrawPlayerField(x, y);
5937 DrawLevelField(x, y);
5942 else if (element == EL_PIG && IN_LEV_FIELD(newx, newy))
5944 if (IS_FOOD_PIG(Feld[newx][newy]))
5946 if (IS_MOVING(newx, newy))
5947 RemoveMovingField(newx, newy);
5950 Feld[newx][newy] = EL_EMPTY;
5951 DrawLevelField(newx, newy);
5954 PlayLevelSound(x, y, SND_PIG_DIGGING);
5956 else if (!IS_FREE(newx, newy))
5958 if (IS_PLAYER(x, y))
5959 DrawPlayerField(x, y);
5961 DrawLevelField(x, y);
5966 else if (element == EL_EMC_ANDROID && IN_LEV_FIELD(newx, newy))
5968 if (Store[x][y] != EL_EMPTY)
5970 boolean can_clone = FALSE;
5973 /* check if element to clone is still there */
5974 for (yy = y - 1; yy <= y + 1; yy++) for (xx = x - 1; xx <= x + 1; xx++)
5976 if (IN_LEV_FIELD(xx, yy) && Feld[xx][yy] == Store[x][y])
5984 /* cannot clone or target field not free anymore -- do not clone */
5985 if (!can_clone || !ANDROID_CAN_ENTER_FIELD(element, newx, newy))
5986 Store[x][y] = EL_EMPTY;
5989 if (ANDROID_CAN_ENTER_FIELD(element, newx, newy))
5991 if (IS_MV_DIAGONAL(MovDir[x][y]))
5993 int diagonal_move_dir = MovDir[x][y];
5994 int stored = Store[x][y];
5995 int change_delay = 8;
5998 /* android is moving diagonally */
6000 CreateField(x, y, EL_DIAGONAL_SHRINKING);
6002 Store[x][y] = (stored == EL_ACID ? EL_EMPTY : stored);
6003 GfxElement[x][y] = EL_EMC_ANDROID;
6004 GfxAction[x][y] = ACTION_SHRINKING;
6005 GfxDir[x][y] = diagonal_move_dir;
6006 ChangeDelay[x][y] = change_delay;
6008 graphic = el_act_dir2img(GfxElement[x][y], GfxAction[x][y],
6011 DrawLevelGraphicAnimation(x, y, graphic);
6012 PlayLevelSoundAction(x, y, ACTION_SHRINKING);
6014 if (Feld[newx][newy] == EL_ACID)
6016 SplashAcid(newx, newy);
6021 CreateField(newx, newy, EL_DIAGONAL_GROWING);
6023 Store[newx][newy] = EL_EMC_ANDROID;
6024 GfxElement[newx][newy] = EL_EMC_ANDROID;
6025 GfxAction[newx][newy] = ACTION_GROWING;
6026 GfxDir[newx][newy] = diagonal_move_dir;
6027 ChangeDelay[newx][newy] = change_delay;
6029 graphic = el_act_dir2img(GfxElement[newx][newy],
6030 GfxAction[newx][newy], GfxDir[newx][newy]);
6032 DrawLevelGraphicAnimation(newx, newy, graphic);
6033 PlayLevelSoundAction(newx, newy, ACTION_GROWING);
6039 Feld[newx][newy] = EL_EMPTY;
6040 DrawLevelField(newx, newy);
6042 PlayLevelSoundAction(x, y, ACTION_DIGGING);
6045 else if (!IS_FREE(newx, newy))
6048 if (IS_PLAYER(x, y))
6049 DrawPlayerField(x, y);
6051 DrawLevelField(x, y);
6057 else if (IS_CUSTOM_ELEMENT(element) &&
6058 CUSTOM_ELEMENT_CAN_ENTER_FIELD(element, newx, newy))
6060 int new_element = Feld[newx][newy];
6062 if (!IS_FREE(newx, newy))
6064 int action = (IS_DIGGABLE(new_element) ? ACTION_DIGGING :
6065 IS_COLLECTIBLE(new_element) ? ACTION_COLLECTING :
6068 /* no element can dig solid indestructible elements */
6069 if (IS_INDESTRUCTIBLE(new_element) &&
6070 !IS_DIGGABLE(new_element) &&
6071 !IS_COLLECTIBLE(new_element))
6074 if (AmoebaNr[newx][newy] &&
6075 (new_element == EL_AMOEBA_FULL ||
6076 new_element == EL_BD_AMOEBA ||
6077 new_element == EL_AMOEBA_GROWING))
6079 AmoebaCnt[AmoebaNr[newx][newy]]--;
6080 AmoebaCnt2[AmoebaNr[newx][newy]]--;
6083 if (IS_MOVING(newx, newy))
6084 RemoveMovingField(newx, newy);
6087 RemoveField(newx, newy);
6088 DrawLevelField(newx, newy);
6091 /* if digged element was about to explode, prevent the explosion */
6092 ExplodeField[newx][newy] = EX_TYPE_NONE;
6094 PlayLevelSoundAction(x, y, action);
6097 Store[newx][newy] = EL_EMPTY;
6099 /* this makes it possible to leave the removed element again */
6100 if (IS_EQUAL_OR_IN_GROUP(new_element, MOVE_ENTER_EL(element)))
6101 Store[newx][newy] = new_element;
6103 if (IS_EQUAL_OR_IN_GROUP(new_element, MOVE_ENTER_EL(element)))
6105 int move_leave_element = element_info[element].move_leave_element;
6107 /* this makes it possible to leave the removed element again */
6108 Store[newx][newy] = (move_leave_element == EL_TRIGGER_ELEMENT ?
6109 new_element : move_leave_element);
6113 if (move_pattern & MV_MAZE_RUNNER_STYLE)
6115 RunnerVisit[x][y] = FrameCounter;
6116 PlayerVisit[x][y] /= 8; /* expire player visit path */
6119 else if (element == EL_DRAGON && IN_LEV_FIELD(newx, newy))
6121 if (!IS_FREE(newx, newy))
6123 if (IS_PLAYER(x, y))
6124 DrawPlayerField(x, y);
6126 DrawLevelField(x, y);
6132 boolean wanna_flame = !RND(10);
6133 int dx = newx - x, dy = newy - y;
6134 int newx1 = newx + 1 * dx, newy1 = newy + 1 * dy;
6135 int newx2 = newx + 2 * dx, newy2 = newy + 2 * dy;
6136 int element1 = (IN_LEV_FIELD(newx1, newy1) ?
6137 MovingOrBlocked2Element(newx1, newy1) : EL_STEELWALL);
6138 int element2 = (IN_LEV_FIELD(newx2, newy2) ?
6139 MovingOrBlocked2Element(newx2, newy2) : EL_STEELWALL);
6142 IS_CLASSIC_ENEMY(element1) ||
6143 IS_CLASSIC_ENEMY(element2)) &&
6144 element1 != EL_DRAGON && element2 != EL_DRAGON &&
6145 element1 != EL_FLAMES && element2 != EL_FLAMES)
6147 ResetGfxAnimation(x, y);
6148 GfxAction[x][y] = ACTION_ATTACKING;
6150 if (IS_PLAYER(x, y))
6151 DrawPlayerField(x, y);
6153 DrawLevelField(x, y);
6155 PlayLevelSound(x, y, SND_DRAGON_ATTACKING);
6157 MovDelay[x][y] = 50;
6161 RemoveField(newx, newy);
6163 Feld[newx][newy] = EL_FLAMES;
6164 if (IN_LEV_FIELD(newx1, newy1) && Feld[newx1][newy1] == EL_EMPTY)
6167 RemoveField(newx1, newy1);
6169 Feld[newx1][newy1] = EL_FLAMES;
6171 if (IN_LEV_FIELD(newx2, newy2) && Feld[newx2][newy2] == EL_EMPTY)
6174 RemoveField(newx2, newy2);
6176 Feld[newx2][newy2] = EL_FLAMES;
6183 else if (element == EL_YAMYAM && IN_LEV_FIELD(newx, newy) &&
6184 Feld[newx][newy] == EL_DIAMOND)
6186 if (IS_MOVING(newx, newy))
6187 RemoveMovingField(newx, newy);
6190 Feld[newx][newy] = EL_EMPTY;
6191 DrawLevelField(newx, newy);
6194 PlayLevelSound(x, y, SND_YAMYAM_DIGGING);
6196 else if (element == EL_DARK_YAMYAM && IN_LEV_FIELD(newx, newy) &&
6197 IS_FOOD_DARK_YAMYAM(Feld[newx][newy]))
6199 if (AmoebaNr[newx][newy])
6201 AmoebaCnt2[AmoebaNr[newx][newy]]--;
6202 if (Feld[newx][newy] == EL_AMOEBA_FULL ||
6203 Feld[newx][newy] == EL_BD_AMOEBA)
6204 AmoebaCnt[AmoebaNr[newx][newy]]--;
6209 if (IS_MOVING(newx, newy) || IS_BLOCKED(newx, newy))
6211 RemoveMovingField(newx, newy);
6214 if (IS_MOVING(newx, newy))
6216 RemoveMovingField(newx, newy);
6221 Feld[newx][newy] = EL_EMPTY;
6222 DrawLevelField(newx, newy);
6225 PlayLevelSound(x, y, SND_DARK_YAMYAM_DIGGING);
6227 else if ((element == EL_PACMAN || element == EL_MOLE)
6228 && IN_LEV_FIELD(newx, newy) && IS_AMOEBOID(Feld[newx][newy]))
6230 if (AmoebaNr[newx][newy])
6232 AmoebaCnt2[AmoebaNr[newx][newy]]--;
6233 if (Feld[newx][newy] == EL_AMOEBA_FULL ||
6234 Feld[newx][newy] == EL_BD_AMOEBA)
6235 AmoebaCnt[AmoebaNr[newx][newy]]--;
6238 if (element == EL_MOLE)
6240 Feld[newx][newy] = EL_AMOEBA_SHRINKING;
6241 PlayLevelSound(x, y, SND_MOLE_DIGGING);
6243 ResetGfxAnimation(x, y);
6244 GfxAction[x][y] = ACTION_DIGGING;
6245 DrawLevelField(x, y);
6247 MovDelay[newx][newy] = 0; /* start amoeba shrinking delay */
6249 return; /* wait for shrinking amoeba */
6251 else /* element == EL_PACMAN */
6253 Feld[newx][newy] = EL_EMPTY;
6254 DrawLevelField(newx, newy);
6255 PlayLevelSound(x, y, SND_PACMAN_DIGGING);
6258 else if (element == EL_MOLE && IN_LEV_FIELD(newx, newy) &&
6259 (Feld[newx][newy] == EL_AMOEBA_SHRINKING ||
6260 (Feld[newx][newy] == EL_EMPTY && Stop[newx][newy])))
6262 /* wait for shrinking amoeba to completely disappear */
6265 else if (!IN_LEV_FIELD(newx, newy) || !IS_FREE(newx, newy))
6267 /* object was running against a wall */
6272 /* !!! NEW "CE_BLOCKED" STUFF !!! -- DOES NOT WORK YET... !!! */
6273 if (move_pattern & MV_ANY_DIRECTION &&
6274 move_pattern == MovDir[x][y])
6276 int blocking_element =
6277 (IN_LEV_FIELD(newx, newy) ? Feld[newx][newy] : BorderElement);
6279 CheckElementChangeBySide(x, y, element, blocking_element, CE_BLOCKED,
6282 element = Feld[x][y]; /* element might have changed */
6286 if (GFX_ELEMENT(element) != EL_SAND) /* !!! FIX THIS (crumble) !!! */
6287 DrawLevelElementAnimation(x, y, element);
6289 if (DONT_TOUCH(element))
6290 TestIfBadThingTouchesPlayer(x, y);
6295 InitMovingField(x, y, MovDir[x][y]);
6297 PlayLevelSoundAction(x, y, ACTION_MOVING);
6301 ContinueMoving(x, y);
6304 void ContinueMoving(int x, int y)
6306 int element = Feld[x][y];
6307 struct ElementInfo *ei = &element_info[element];
6308 int direction = MovDir[x][y];
6309 int dx = (direction == MV_LEFT ? -1 : direction == MV_RIGHT ? +1 : 0);
6310 int dy = (direction == MV_UP ? -1 : direction == MV_DOWN ? +1 : 0);
6311 int newx = x + dx, newy = y + dy;
6312 int stored = Store[x][y];
6313 int stored_new = Store[newx][newy];
6314 boolean pushed_by_player = (Pushed[x][y] && IS_PLAYER(x, y));
6315 boolean pushed_by_conveyor = (Pushed[x][y] && !IS_PLAYER(x, y));
6316 boolean last_line = (newy == lev_fieldy - 1);
6318 MovPos[x][y] += getElementMoveStepsize(x, y);
6320 if (pushed_by_player) /* special case: moving object pushed by player */
6321 MovPos[x][y] = SIGN(MovPos[x][y]) * (TILEX - ABS(PLAYERINFO(x,y)->MovPos));
6323 if (ABS(MovPos[x][y]) < TILEX)
6325 DrawLevelField(x, y);
6327 return; /* element is still moving */
6330 /* element reached destination field */
6332 Feld[x][y] = EL_EMPTY;
6333 Feld[newx][newy] = element;
6334 MovPos[x][y] = 0; /* force "not moving" for "crumbled sand" */
6336 if (Store[x][y] == EL_ACID) /* element is moving into acid pool */
6338 element = Feld[newx][newy] = EL_ACID;
6340 else if (element == EL_MOLE)
6342 Feld[x][y] = EL_SAND;
6344 DrawLevelFieldCrumbledSandNeighbours(x, y);
6346 else if (element == EL_QUICKSAND_FILLING)
6348 element = Feld[newx][newy] = get_next_element(element);
6349 Store[newx][newy] = Store[x][y];
6351 else if (element == EL_QUICKSAND_EMPTYING)
6353 Feld[x][y] = get_next_element(element);
6354 element = Feld[newx][newy] = Store[x][y];
6356 else if (element == EL_MAGIC_WALL_FILLING)
6358 element = Feld[newx][newy] = get_next_element(element);
6359 if (!game.magic_wall_active)
6360 element = Feld[newx][newy] = EL_MAGIC_WALL_DEAD;
6361 Store[newx][newy] = Store[x][y];
6363 else if (element == EL_MAGIC_WALL_EMPTYING)
6365 Feld[x][y] = get_next_element(element);
6366 if (!game.magic_wall_active)
6367 Feld[x][y] = EL_MAGIC_WALL_DEAD;
6368 element = Feld[newx][newy] = Store[x][y];
6370 #if USE_NEW_CUSTOM_VALUE
6371 InitField(newx, newy, FALSE);
6374 else if (element == EL_BD_MAGIC_WALL_FILLING)
6376 element = Feld[newx][newy] = get_next_element(element);
6377 if (!game.magic_wall_active)
6378 element = Feld[newx][newy] = EL_BD_MAGIC_WALL_DEAD;
6379 Store[newx][newy] = Store[x][y];
6381 else if (element == EL_BD_MAGIC_WALL_EMPTYING)
6383 Feld[x][y] = get_next_element(element);
6384 if (!game.magic_wall_active)
6385 Feld[x][y] = EL_BD_MAGIC_WALL_DEAD;
6386 element = Feld[newx][newy] = Store[x][y];
6388 #if USE_NEW_CUSTOM_VALUE
6389 InitField(newx, newy, FALSE);
6392 else if (element == EL_AMOEBA_DROPPING)
6394 Feld[x][y] = get_next_element(element);
6395 element = Feld[newx][newy] = Store[x][y];
6397 else if (element == EL_SOKOBAN_OBJECT)
6400 Feld[x][y] = Back[x][y];
6402 if (Back[newx][newy])
6403 Feld[newx][newy] = EL_SOKOBAN_FIELD_FULL;
6405 Back[x][y] = Back[newx][newy] = 0;
6408 Store[x][y] = EL_EMPTY;
6413 MovDelay[newx][newy] = 0;
6415 if (CAN_CHANGE_OR_HAS_ACTION(element))
6417 /* copy element change control values to new field */
6418 ChangeDelay[newx][newy] = ChangeDelay[x][y];
6419 ChangePage[newx][newy] = ChangePage[x][y];
6420 ChangeCount[newx][newy] = ChangeCount[x][y];
6421 ChangeEvent[newx][newy] = ChangeEvent[x][y];
6424 #if USE_NEW_CUSTOM_VALUE
6425 CustomValue[newx][newy] = CustomValue[x][y];
6428 ChangeDelay[x][y] = 0;
6429 ChangePage[x][y] = -1;
6430 ChangeCount[x][y] = 0;
6431 ChangeEvent[x][y] = -1;
6433 #if USE_NEW_CUSTOM_VALUE
6434 CustomValue[x][y] = 0;
6437 /* copy animation control values to new field */
6438 GfxFrame[newx][newy] = GfxFrame[x][y];
6439 GfxRandom[newx][newy] = GfxRandom[x][y]; /* keep same random value */
6440 GfxAction[newx][newy] = GfxAction[x][y]; /* keep action one frame */
6441 GfxDir[newx][newy] = GfxDir[x][y]; /* keep element direction */
6443 Pushed[x][y] = Pushed[newx][newy] = FALSE;
6445 /* some elements can leave other elements behind after moving */
6447 if (ei->move_leave_element != EL_EMPTY &&
6448 (ei->move_leave_type == LEAVE_TYPE_UNLIMITED || stored != EL_EMPTY) &&
6449 (!IS_PLAYER(x, y) || IS_WALKABLE(ei->move_leave_element)))
6451 if (IS_CUSTOM_ELEMENT(element) && ei->move_leave_element != EL_EMPTY &&
6452 (ei->move_leave_type == LEAVE_TYPE_UNLIMITED || stored != EL_EMPTY) &&
6453 (!IS_PLAYER(x, y) || IS_WALKABLE(ei->move_leave_element)))
6456 int move_leave_element = ei->move_leave_element;
6460 /* this makes it possible to leave the removed element again */
6461 if (ei->move_leave_element == EL_TRIGGER_ELEMENT)
6462 move_leave_element = (stored == EL_ACID ? EL_EMPTY : stored);
6464 /* this makes it possible to leave the removed element again */
6465 if (ei->move_leave_element == EL_TRIGGER_ELEMENT)
6466 move_leave_element = stored;
6469 /* this makes it possible to leave the removed element again */
6470 if (ei->move_leave_type == LEAVE_TYPE_LIMITED &&
6471 ei->move_leave_element == EL_TRIGGER_ELEMENT)
6472 move_leave_element = stored;
6475 Feld[x][y] = move_leave_element;
6477 if (element_info[Feld[x][y]].move_direction_initial == MV_START_PREVIOUS)
6478 MovDir[x][y] = direction;
6480 InitField(x, y, FALSE);
6482 if (GFX_CRUMBLED(Feld[x][y]))
6483 DrawLevelFieldCrumbledSandNeighbours(x, y);
6485 if (ELEM_IS_PLAYER(move_leave_element))
6486 RelocatePlayer(x, y, move_leave_element);
6489 /* do this after checking for left-behind element */
6490 ResetGfxAnimation(x, y); /* reset animation values for old field */
6492 if (!CAN_MOVE(element) ||
6493 (CAN_FALL(element) && direction == MV_DOWN &&
6494 (element == EL_SPRING ||
6495 element_info[element].move_pattern == MV_WHEN_PUSHED ||
6496 element_info[element].move_pattern == MV_WHEN_DROPPED)))
6497 GfxDir[x][y] = MovDir[newx][newy] = 0;
6499 DrawLevelField(x, y);
6500 DrawLevelField(newx, newy);
6502 Stop[newx][newy] = TRUE; /* ignore this element until the next frame */
6504 /* prevent pushed element from moving on in pushed direction */
6505 if (pushed_by_player && CAN_MOVE(element) &&
6506 element_info[element].move_pattern & MV_ANY_DIRECTION &&
6507 !(element_info[element].move_pattern & direction))
6508 TurnRound(newx, newy);
6510 /* prevent elements on conveyor belt from moving on in last direction */
6511 if (pushed_by_conveyor && CAN_FALL(element) &&
6512 direction & MV_HORIZONTAL)
6513 MovDir[newx][newy] = 0;
6515 if (!pushed_by_player)
6517 int nextx = newx + dx, nexty = newy + dy;
6518 boolean check_collision_again = IN_LEV_FIELD_AND_IS_FREE(nextx, nexty);
6520 WasJustMoving[newx][newy] = CHECK_DELAY_MOVING;
6522 if (CAN_FALL(element) && direction == MV_DOWN)
6523 WasJustFalling[newx][newy] = CHECK_DELAY_FALLING;
6525 if ((!CAN_FALL(element) || direction == MV_DOWN) && check_collision_again)
6526 CheckCollision[newx][newy] = CHECK_DELAY_COLLISION;
6529 if (DONT_TOUCH(element)) /* object may be nasty to player or others */
6531 TestIfBadThingTouchesPlayer(newx, newy);
6532 TestIfBadThingTouchesFriend(newx, newy);
6534 if (!IS_CUSTOM_ELEMENT(element))
6535 TestIfBadThingTouchesOtherBadThing(newx, newy);
6537 else if (element == EL_PENGUIN)
6538 TestIfFriendTouchesBadThing(newx, newy);
6540 /* give the player one last chance (one more frame) to move away */
6541 if (CAN_FALL(element) && direction == MV_DOWN &&
6542 (last_line || (!IS_FREE(x, newy + 1) &&
6543 (!IS_PLAYER(x, newy + 1) ||
6544 game.engine_version < VERSION_IDENT(3,1,1,0)))))
6547 if (pushed_by_player && !game.use_change_when_pushing_bug)
6549 int push_side = MV_DIR_OPPOSITE(direction);
6550 struct PlayerInfo *player = PLAYERINFO(x, y);
6552 CheckElementChangeByPlayer(newx, newy, element, CE_PUSHED_BY_PLAYER,
6553 player->index_bit, push_side);
6554 CheckTriggeredElementChangeByPlayer(newx,newy, element, CE_PLAYER_PUSHES_X,
6555 player->index_bit, push_side);
6558 if (element == EL_EMC_ANDROID && pushed_by_player) /* make another move */
6559 MovDelay[newx][newy] = 1;
6561 CheckTriggeredElementChangeBySide(x, y, element, CE_MOVE_OF_X, direction);
6563 TestIfElementTouchesCustomElement(x, y); /* empty or new element */
6566 if (ChangePage[newx][newy] != -1) /* delayed change */
6568 int page = ChangePage[newx][newy];
6569 struct ElementChangeInfo *change = &ei->change_page[page];
6571 ChangePage[newx][newy] = -1;
6573 if (change->can_change)
6575 if (ChangeElement(newx, newy, element, page))
6577 if (change->post_change_function)
6578 change->post_change_function(newx, newy);
6582 if (change->has_action)
6583 ExecuteCustomElementAction(newx, newy, element, page);
6587 TestIfElementHitsCustomElement(newx, newy, direction);
6588 TestIfPlayerTouchesCustomElement(newx, newy);
6589 TestIfElementTouchesCustomElement(newx, newy);
6591 if (IS_CUSTOM_ELEMENT(element) && ei->move_enter_element != EL_EMPTY &&
6592 IS_EQUAL_OR_IN_GROUP(stored_new, ei->move_enter_element))
6593 CheckElementChangeBySide(newx, newy, element, stored_new, CE_DIGGING_X,
6594 MV_DIR_OPPOSITE(direction));
6597 int AmoebeNachbarNr(int ax, int ay)
6600 int element = Feld[ax][ay];
6602 static int xy[4][2] =
6610 for (i = 0; i < NUM_DIRECTIONS; i++)
6612 int x = ax + xy[i][0];
6613 int y = ay + xy[i][1];
6615 if (!IN_LEV_FIELD(x, y))
6618 if (Feld[x][y] == element && AmoebaNr[x][y] > 0)
6619 group_nr = AmoebaNr[x][y];
6625 void AmoebenVereinigen(int ax, int ay)
6627 int i, x, y, xx, yy;
6628 int new_group_nr = AmoebaNr[ax][ay];
6629 static int xy[4][2] =
6637 if (new_group_nr == 0)
6640 for (i = 0; i < NUM_DIRECTIONS; i++)
6645 if (!IN_LEV_FIELD(x, y))
6648 if ((Feld[x][y] == EL_AMOEBA_FULL ||
6649 Feld[x][y] == EL_BD_AMOEBA ||
6650 Feld[x][y] == EL_AMOEBA_DEAD) &&
6651 AmoebaNr[x][y] != new_group_nr)
6653 int old_group_nr = AmoebaNr[x][y];
6655 if (old_group_nr == 0)
6658 AmoebaCnt[new_group_nr] += AmoebaCnt[old_group_nr];
6659 AmoebaCnt[old_group_nr] = 0;
6660 AmoebaCnt2[new_group_nr] += AmoebaCnt2[old_group_nr];
6661 AmoebaCnt2[old_group_nr] = 0;
6663 SCAN_PLAYFIELD(xx, yy)
6665 if (AmoebaNr[xx][yy] == old_group_nr)
6666 AmoebaNr[xx][yy] = new_group_nr;
6672 void AmoebeUmwandeln(int ax, int ay)
6676 if (Feld[ax][ay] == EL_AMOEBA_DEAD)
6678 int group_nr = AmoebaNr[ax][ay];
6683 printf("AmoebeUmwandeln(): ax = %d, ay = %d\n", ax, ay);
6684 printf("AmoebeUmwandeln(): This should never happen!\n");
6689 SCAN_PLAYFIELD(x, y)
6691 if (Feld[x][y] == EL_AMOEBA_DEAD && AmoebaNr[x][y] == group_nr)
6694 Feld[x][y] = EL_AMOEBA_TO_DIAMOND;
6698 PlayLevelSound(ax, ay, (IS_GEM(level.amoeba_content) ?
6699 SND_AMOEBA_TURNING_TO_GEM :
6700 SND_AMOEBA_TURNING_TO_ROCK));
6705 static int xy[4][2] =
6713 for (i = 0; i < NUM_DIRECTIONS; i++)
6718 if (!IN_LEV_FIELD(x, y))
6721 if (Feld[x][y] == EL_AMOEBA_TO_DIAMOND)
6723 PlayLevelSound(x, y, (IS_GEM(level.amoeba_content) ?
6724 SND_AMOEBA_TURNING_TO_GEM :
6725 SND_AMOEBA_TURNING_TO_ROCK));
6732 void AmoebeUmwandelnBD(int ax, int ay, int new_element)
6735 int group_nr = AmoebaNr[ax][ay];
6736 boolean done = FALSE;
6741 printf("AmoebeUmwandelnBD(): ax = %d, ay = %d\n", ax, ay);
6742 printf("AmoebeUmwandelnBD(): This should never happen!\n");
6747 SCAN_PLAYFIELD(x, y)
6749 if (AmoebaNr[x][y] == group_nr &&
6750 (Feld[x][y] == EL_AMOEBA_DEAD ||
6751 Feld[x][y] == EL_BD_AMOEBA ||
6752 Feld[x][y] == EL_AMOEBA_GROWING))
6755 Feld[x][y] = new_element;
6756 InitField(x, y, FALSE);
6757 DrawLevelField(x, y);
6763 PlayLevelSound(ax, ay, (new_element == EL_BD_ROCK ?
6764 SND_BD_AMOEBA_TURNING_TO_ROCK :
6765 SND_BD_AMOEBA_TURNING_TO_GEM));
6768 void AmoebeWaechst(int x, int y)
6770 static unsigned long sound_delay = 0;
6771 static unsigned long sound_delay_value = 0;
6773 if (!MovDelay[x][y]) /* start new growing cycle */
6777 if (DelayReached(&sound_delay, sound_delay_value))
6779 PlayLevelSoundElementAction(x, y, Store[x][y], ACTION_GROWING);
6780 sound_delay_value = 30;
6784 if (MovDelay[x][y]) /* wait some time before growing bigger */
6787 if (MovDelay[x][y]/2 && IN_SCR_FIELD(SCREENX(x), SCREENY(y)))
6789 int frame = getGraphicAnimationFrame(IMG_AMOEBA_GROWING,
6790 6 - MovDelay[x][y]);
6792 DrawGraphic(SCREENX(x), SCREENY(y), IMG_AMOEBA_GROWING, frame);
6795 if (!MovDelay[x][y])
6797 Feld[x][y] = Store[x][y];
6799 DrawLevelField(x, y);
6804 void AmoebaDisappearing(int x, int y)
6806 static unsigned long sound_delay = 0;
6807 static unsigned long sound_delay_value = 0;
6809 if (!MovDelay[x][y]) /* start new shrinking cycle */
6813 if (DelayReached(&sound_delay, sound_delay_value))
6814 sound_delay_value = 30;
6817 if (MovDelay[x][y]) /* wait some time before shrinking */
6820 if (MovDelay[x][y]/2 && IN_SCR_FIELD(SCREENX(x), SCREENY(y)))
6822 int frame = getGraphicAnimationFrame(IMG_AMOEBA_SHRINKING,
6823 6 - MovDelay[x][y]);
6825 DrawGraphic(SCREENX(x), SCREENY(y), IMG_AMOEBA_SHRINKING, frame);
6828 if (!MovDelay[x][y])
6830 Feld[x][y] = EL_EMPTY;
6831 DrawLevelField(x, y);
6833 /* don't let mole enter this field in this cycle;
6834 (give priority to objects falling to this field from above) */
6840 void AmoebeAbleger(int ax, int ay)
6843 int element = Feld[ax][ay];
6844 int graphic = el2img(element);
6845 int newax = ax, neway = ay;
6846 boolean can_drop = (element == EL_AMOEBA_WET || element == EL_EMC_DRIPPER);
6847 static int xy[4][2] =
6855 if (!level.amoeba_speed && element != EL_EMC_DRIPPER)
6857 Feld[ax][ay] = EL_AMOEBA_DEAD;
6858 DrawLevelField(ax, ay);
6862 if (IS_ANIMATED(graphic))
6863 DrawLevelGraphicAnimationIfNeeded(ax, ay, graphic);
6865 if (!MovDelay[ax][ay]) /* start making new amoeba field */
6866 MovDelay[ax][ay] = RND(FRAMES_PER_SECOND * 25 / (1 + level.amoeba_speed));
6868 if (MovDelay[ax][ay]) /* wait some time before making new amoeba */
6871 if (MovDelay[ax][ay])
6875 if (can_drop) /* EL_AMOEBA_WET or EL_EMC_DRIPPER */
6878 int x = ax + xy[start][0];
6879 int y = ay + xy[start][1];
6881 if (!IN_LEV_FIELD(x, y))
6884 if (IS_FREE(x, y) ||
6885 CAN_GROW_INTO(Feld[x][y]) ||
6886 Feld[x][y] == EL_QUICKSAND_EMPTY)
6892 if (newax == ax && neway == ay)
6895 else /* normal or "filled" (BD style) amoeba */
6898 boolean waiting_for_player = FALSE;
6900 for (i = 0; i < NUM_DIRECTIONS; i++)
6902 int j = (start + i) % 4;
6903 int x = ax + xy[j][0];
6904 int y = ay + xy[j][1];
6906 if (!IN_LEV_FIELD(x, y))
6909 if (IS_FREE(x, y) ||
6910 CAN_GROW_INTO(Feld[x][y]) ||
6911 Feld[x][y] == EL_QUICKSAND_EMPTY)
6917 else if (IS_PLAYER(x, y))
6918 waiting_for_player = TRUE;
6921 if (newax == ax && neway == ay) /* amoeba cannot grow */
6923 if (i == 4 && (!waiting_for_player || element == EL_BD_AMOEBA))
6925 Feld[ax][ay] = EL_AMOEBA_DEAD;
6926 DrawLevelField(ax, ay);
6927 AmoebaCnt[AmoebaNr[ax][ay]]--;
6929 if (AmoebaCnt[AmoebaNr[ax][ay]] <= 0) /* amoeba is completely dead */
6931 if (element == EL_AMOEBA_FULL)
6932 AmoebeUmwandeln(ax, ay);
6933 else if (element == EL_BD_AMOEBA)
6934 AmoebeUmwandelnBD(ax, ay, level.amoeba_content);
6939 else if (element == EL_AMOEBA_FULL || element == EL_BD_AMOEBA)
6941 /* amoeba gets larger by growing in some direction */
6943 int new_group_nr = AmoebaNr[ax][ay];
6946 if (new_group_nr == 0)
6948 printf("AmoebeAbleger(): newax = %d, neway = %d\n", newax, neway);
6949 printf("AmoebeAbleger(): This should never happen!\n");
6954 AmoebaNr[newax][neway] = new_group_nr;
6955 AmoebaCnt[new_group_nr]++;
6956 AmoebaCnt2[new_group_nr]++;
6958 /* if amoeba touches other amoeba(s) after growing, unify them */
6959 AmoebenVereinigen(newax, neway);
6961 if (element == EL_BD_AMOEBA && AmoebaCnt2[new_group_nr] >= 200)
6963 AmoebeUmwandelnBD(newax, neway, EL_BD_ROCK);
6969 if (!can_drop || neway < ay || !IS_FREE(newax, neway) ||
6970 (neway == lev_fieldy - 1 && newax != ax))
6972 Feld[newax][neway] = EL_AMOEBA_GROWING; /* creation of new amoeba */
6973 Store[newax][neway] = element;
6975 else if (neway == ay || element == EL_EMC_DRIPPER)
6977 Feld[newax][neway] = EL_AMOEBA_DROP; /* drop left/right of amoeba */
6979 PlayLevelSoundAction(newax, neway, ACTION_GROWING);
6983 InitMovingField(ax, ay, MV_DOWN); /* drop dripping from amoeba */
6984 Feld[ax][ay] = EL_AMOEBA_DROPPING;
6985 Store[ax][ay] = EL_AMOEBA_DROP;
6986 ContinueMoving(ax, ay);
6990 DrawLevelField(newax, neway);
6993 void Life(int ax, int ay)
6997 int element = Feld[ax][ay];
6998 int graphic = el2img(element);
6999 int *life_parameter = (element == EL_GAME_OF_LIFE ? level.game_of_life :
7001 boolean changed = FALSE;
7003 if (IS_ANIMATED(graphic))
7004 DrawLevelGraphicAnimationIfNeeded(ax, ay, graphic);
7009 if (!MovDelay[ax][ay]) /* start new "game of life" cycle */
7010 MovDelay[ax][ay] = life_time;
7012 if (MovDelay[ax][ay]) /* wait some time before next cycle */
7015 if (MovDelay[ax][ay])
7019 for (y1 = -1; y1 < 2; y1++) for (x1 = -1; x1 < 2; x1++)
7021 int xx = ax+x1, yy = ay+y1;
7024 if (!IN_LEV_FIELD(xx, yy))
7027 for (y2 = -1; y2 < 2; y2++) for (x2 = -1; x2 < 2; x2++)
7029 int x = xx+x2, y = yy+y2;
7031 if (!IN_LEV_FIELD(x, y) || (x == xx && y == yy))
7034 if (((Feld[x][y] == element ||
7035 (element == EL_GAME_OF_LIFE && IS_PLAYER(x, y))) &&
7037 (IS_FREE(x, y) && Stop[x][y]))
7041 if (xx == ax && yy == ay) /* field in the middle */
7043 if (nachbarn < life_parameter[0] ||
7044 nachbarn > life_parameter[1])
7046 Feld[xx][yy] = EL_EMPTY;
7048 DrawLevelField(xx, yy);
7049 Stop[xx][yy] = TRUE;
7053 else if (IS_FREE(xx, yy) || CAN_GROW_INTO(Feld[xx][yy]))
7054 { /* free border field */
7055 if (nachbarn >= life_parameter[2] &&
7056 nachbarn <= life_parameter[3])
7058 Feld[xx][yy] = element;
7059 MovDelay[xx][yy] = (element == EL_GAME_OF_LIFE ? 0 : life_time-1);
7061 DrawLevelField(xx, yy);
7062 Stop[xx][yy] = TRUE;
7069 PlayLevelSound(ax, ay, element == EL_BIOMAZE ? SND_BIOMAZE_GROWING :
7070 SND_GAME_OF_LIFE_GROWING);
7073 static void InitRobotWheel(int x, int y)
7075 ChangeDelay[x][y] = level.time_wheel * FRAMES_PER_SECOND;
7078 static void RunRobotWheel(int x, int y)
7080 PlayLevelSound(x, y, SND_ROBOT_WHEEL_ACTIVE);
7083 static void StopRobotWheel(int x, int y)
7085 if (ZX == x && ZY == y)
7089 static void InitTimegateWheel(int x, int y)
7091 ChangeDelay[x][y] = level.time_timegate * FRAMES_PER_SECOND;
7094 static void RunTimegateWheel(int x, int y)
7096 PlayLevelSound(x, y, SND_TIMEGATE_SWITCH_ACTIVE);
7099 static void InitMagicBallDelay(int x, int y)
7102 ChangeDelay[x][y] = (level.ball_time + 1) * 8 + 1;
7104 ChangeDelay[x][y] = level.ball_time * FRAMES_PER_SECOND + 1;
7108 static void ActivateMagicBall(int bx, int by)
7112 if (level.ball_random)
7114 int pos_border = RND(8); /* select one of the eight border elements */
7115 int pos_content = (pos_border > 3 ? pos_border + 1 : pos_border);
7116 int xx = pos_content % 3;
7117 int yy = pos_content / 3;
7122 if (IN_LEV_FIELD(x, y) && Feld[x][y] == EL_EMPTY)
7123 CreateField(x, y, level.ball_content[game.ball_content_nr].e[xx][yy]);
7127 for (y = by - 1; y <= by + 1; y++) for (x = bx - 1; x <= bx + 1; x++)
7129 int xx = x - bx + 1;
7130 int yy = y - by + 1;
7132 if (IN_LEV_FIELD(x, y) && Feld[x][y] == EL_EMPTY)
7133 CreateField(x, y, level.ball_content[game.ball_content_nr].e[xx][yy]);
7137 game.ball_content_nr = (game.ball_content_nr + 1) % level.num_ball_contents;
7140 void CheckExit(int x, int y)
7142 if (local_player->gems_still_needed > 0 ||
7143 local_player->sokobanfields_still_needed > 0 ||
7144 local_player->lights_still_needed > 0)
7146 int element = Feld[x][y];
7147 int graphic = el2img(element);
7149 if (IS_ANIMATED(graphic))
7150 DrawLevelGraphicAnimationIfNeeded(x, y, graphic);
7155 if (AllPlayersGone) /* do not re-open exit door closed after last player */
7158 Feld[x][y] = EL_EXIT_OPENING;
7160 PlayLevelSoundNearest(x, y, SND_CLASS_EXIT_OPENING);
7163 void CheckExitSP(int x, int y)
7165 if (local_player->gems_still_needed > 0)
7167 int element = Feld[x][y];
7168 int graphic = el2img(element);
7170 if (IS_ANIMATED(graphic))
7171 DrawLevelGraphicAnimationIfNeeded(x, y, graphic);
7176 if (AllPlayersGone) /* do not re-open exit door closed after last player */
7179 Feld[x][y] = EL_SP_EXIT_OPENING;
7181 PlayLevelSoundNearest(x, y, SND_CLASS_SP_EXIT_OPENING);
7184 static void CloseAllOpenTimegates()
7188 SCAN_PLAYFIELD(x, y)
7190 int element = Feld[x][y];
7192 if (element == EL_TIMEGATE_OPEN || element == EL_TIMEGATE_OPENING)
7194 Feld[x][y] = EL_TIMEGATE_CLOSING;
7196 PlayLevelSoundAction(x, y, ACTION_CLOSING);
7201 void EdelsteinFunkeln(int x, int y)
7203 if (!IN_SCR_FIELD(SCREENX(x), SCREENY(y)) || IS_MOVING(x, y))
7206 if (Feld[x][y] == EL_BD_DIAMOND)
7209 if (MovDelay[x][y] == 0) /* next animation frame */
7210 MovDelay[x][y] = 11 * !SimpleRND(500);
7212 if (MovDelay[x][y] != 0) /* wait some time before next frame */
7216 if (setup.direct_draw && MovDelay[x][y])
7217 SetDrawtoField(DRAW_BUFFERED);
7219 DrawLevelElementAnimation(x, y, Feld[x][y]);
7221 if (MovDelay[x][y] != 0)
7223 int frame = getGraphicAnimationFrame(IMG_TWINKLE_WHITE,
7224 10 - MovDelay[x][y]);
7226 DrawGraphicThruMask(SCREENX(x), SCREENY(y), IMG_TWINKLE_WHITE, frame);
7228 if (setup.direct_draw)
7232 dest_x = FX + SCREENX(x) * TILEX;
7233 dest_y = FY + SCREENY(y) * TILEY;
7235 BlitBitmap(drawto_field, window,
7236 dest_x, dest_y, TILEX, TILEY, dest_x, dest_y);
7237 SetDrawtoField(DRAW_DIRECT);
7243 void MauerWaechst(int x, int y)
7247 if (!MovDelay[x][y]) /* next animation frame */
7248 MovDelay[x][y] = 3 * delay;
7250 if (MovDelay[x][y]) /* wait some time before next frame */
7254 if (IN_SCR_FIELD(SCREENX(x), SCREENY(y)))
7256 int graphic = el_dir2img(Feld[x][y], GfxDir[x][y]);
7257 int frame = getGraphicAnimationFrame(graphic, 17 - MovDelay[x][y]);
7259 DrawGraphic(SCREENX(x), SCREENY(y), graphic, frame);
7262 if (!MovDelay[x][y])
7264 if (MovDir[x][y] == MV_LEFT)
7266 if (IN_LEV_FIELD(x - 1, y) && IS_WALL(Feld[x - 1][y]))
7267 DrawLevelField(x - 1, y);
7269 else if (MovDir[x][y] == MV_RIGHT)
7271 if (IN_LEV_FIELD(x + 1, y) && IS_WALL(Feld[x + 1][y]))
7272 DrawLevelField(x + 1, y);
7274 else if (MovDir[x][y] == MV_UP)
7276 if (IN_LEV_FIELD(x, y - 1) && IS_WALL(Feld[x][y - 1]))
7277 DrawLevelField(x, y - 1);
7281 if (IN_LEV_FIELD(x, y + 1) && IS_WALL(Feld[x][y + 1]))
7282 DrawLevelField(x, y + 1);
7285 Feld[x][y] = Store[x][y];
7287 GfxDir[x][y] = MovDir[x][y] = MV_NONE;
7288 DrawLevelField(x, y);
7293 void MauerAbleger(int ax, int ay)
7295 int element = Feld[ax][ay];
7296 int graphic = el2img(element);
7297 boolean oben_frei = FALSE, unten_frei = FALSE;
7298 boolean links_frei = FALSE, rechts_frei = FALSE;
7299 boolean oben_massiv = FALSE, unten_massiv = FALSE;
7300 boolean links_massiv = FALSE, rechts_massiv = FALSE;
7301 boolean new_wall = FALSE;
7303 if (IS_ANIMATED(graphic))
7304 DrawLevelGraphicAnimationIfNeeded(ax, ay, graphic);
7306 if (!MovDelay[ax][ay]) /* start building new wall */
7307 MovDelay[ax][ay] = 6;
7309 if (MovDelay[ax][ay]) /* wait some time before building new wall */
7312 if (MovDelay[ax][ay])
7316 if (IN_LEV_FIELD(ax, ay-1) && IS_FREE(ax, ay-1))
7318 if (IN_LEV_FIELD(ax, ay+1) && IS_FREE(ax, ay+1))
7320 if (IN_LEV_FIELD(ax-1, ay) && IS_FREE(ax-1, ay))
7322 if (IN_LEV_FIELD(ax+1, ay) && IS_FREE(ax+1, ay))
7325 if (element == EL_EXPANDABLE_WALL_VERTICAL ||
7326 element == EL_EXPANDABLE_WALL_ANY)
7330 Feld[ax][ay-1] = EL_EXPANDABLE_WALL_GROWING;
7331 Store[ax][ay-1] = element;
7332 GfxDir[ax][ay-1] = MovDir[ax][ay-1] = MV_UP;
7333 if (IN_SCR_FIELD(SCREENX(ax), SCREENY(ay-1)))
7334 DrawGraphic(SCREENX(ax), SCREENY(ay - 1),
7335 IMG_EXPANDABLE_WALL_GROWING_UP, 0);
7340 Feld[ax][ay+1] = EL_EXPANDABLE_WALL_GROWING;
7341 Store[ax][ay+1] = element;
7342 GfxDir[ax][ay+1] = MovDir[ax][ay+1] = MV_DOWN;
7343 if (IN_SCR_FIELD(SCREENX(ax), SCREENY(ay+1)))
7344 DrawGraphic(SCREENX(ax), SCREENY(ay + 1),
7345 IMG_EXPANDABLE_WALL_GROWING_DOWN, 0);
7350 if (element == EL_EXPANDABLE_WALL_HORIZONTAL ||
7351 element == EL_EXPANDABLE_WALL_ANY ||
7352 element == EL_EXPANDABLE_WALL ||
7353 element == EL_BD_EXPANDABLE_WALL)
7357 Feld[ax-1][ay] = EL_EXPANDABLE_WALL_GROWING;
7358 Store[ax-1][ay] = element;
7359 GfxDir[ax-1][ay] = MovDir[ax-1][ay] = MV_LEFT;
7360 if (IN_SCR_FIELD(SCREENX(ax-1), SCREENY(ay)))
7361 DrawGraphic(SCREENX(ax - 1), SCREENY(ay),
7362 IMG_EXPANDABLE_WALL_GROWING_LEFT, 0);
7368 Feld[ax+1][ay] = EL_EXPANDABLE_WALL_GROWING;
7369 Store[ax+1][ay] = element;
7370 GfxDir[ax+1][ay] = MovDir[ax+1][ay] = MV_RIGHT;
7371 if (IN_SCR_FIELD(SCREENX(ax+1), SCREENY(ay)))
7372 DrawGraphic(SCREENX(ax + 1), SCREENY(ay),
7373 IMG_EXPANDABLE_WALL_GROWING_RIGHT, 0);
7378 if (element == EL_EXPANDABLE_WALL && (links_frei || rechts_frei))
7379 DrawLevelField(ax, ay);
7381 if (!IN_LEV_FIELD(ax, ay-1) || IS_WALL(Feld[ax][ay-1]))
7383 if (!IN_LEV_FIELD(ax, ay+1) || IS_WALL(Feld[ax][ay+1]))
7384 unten_massiv = TRUE;
7385 if (!IN_LEV_FIELD(ax-1, ay) || IS_WALL(Feld[ax-1][ay]))
7386 links_massiv = TRUE;
7387 if (!IN_LEV_FIELD(ax+1, ay) || IS_WALL(Feld[ax+1][ay]))
7388 rechts_massiv = TRUE;
7390 if (((oben_massiv && unten_massiv) ||
7391 element == EL_EXPANDABLE_WALL_HORIZONTAL ||
7392 element == EL_EXPANDABLE_WALL) &&
7393 ((links_massiv && rechts_massiv) ||
7394 element == EL_EXPANDABLE_WALL_VERTICAL))
7395 Feld[ax][ay] = EL_WALL;
7398 PlayLevelSoundAction(ax, ay, ACTION_GROWING);
7401 void CheckForDragon(int x, int y)
7404 boolean dragon_found = FALSE;
7405 static int xy[4][2] =
7413 for (i = 0; i < NUM_DIRECTIONS; i++)
7415 for (j = 0; j < 4; j++)
7417 int xx = x + j * xy[i][0], yy = y + j * xy[i][1];
7419 if (IN_LEV_FIELD(xx, yy) &&
7420 (Feld[xx][yy] == EL_FLAMES || Feld[xx][yy] == EL_DRAGON))
7422 if (Feld[xx][yy] == EL_DRAGON)
7423 dragon_found = TRUE;
7432 for (i = 0; i < NUM_DIRECTIONS; i++)
7434 for (j = 0; j < 3; j++)
7436 int xx = x + j * xy[i][0], yy = y + j * xy[i][1];
7438 if (IN_LEV_FIELD(xx, yy) && Feld[xx][yy] == EL_FLAMES)
7440 Feld[xx][yy] = EL_EMPTY;
7441 DrawLevelField(xx, yy);
7450 static void InitBuggyBase(int x, int y)
7452 int element = Feld[x][y];
7453 int activating_delay = FRAMES_PER_SECOND / 4;
7456 (element == EL_SP_BUGGY_BASE ?
7457 2 * FRAMES_PER_SECOND + RND(5 * FRAMES_PER_SECOND) - activating_delay :
7458 element == EL_SP_BUGGY_BASE_ACTIVATING ?
7460 element == EL_SP_BUGGY_BASE_ACTIVE ?
7461 1 * FRAMES_PER_SECOND + RND(1 * FRAMES_PER_SECOND) : 1);
7464 static void WarnBuggyBase(int x, int y)
7467 static int xy[4][2] =
7475 for (i = 0; i < NUM_DIRECTIONS; i++)
7477 int xx = x + xy[i][0];
7478 int yy = y + xy[i][1];
7480 if (IN_LEV_FIELD(xx, yy) && IS_PLAYER(xx, yy))
7482 PlayLevelSound(x, y, SND_SP_BUGGY_BASE_ACTIVE);
7489 static void InitTrap(int x, int y)
7491 ChangeDelay[x][y] = 2 * FRAMES_PER_SECOND + RND(5 * FRAMES_PER_SECOND);
7494 static void ActivateTrap(int x, int y)
7496 PlayLevelSound(x, y, SND_TRAP_ACTIVATING);
7499 static void ChangeActiveTrap(int x, int y)
7501 int graphic = IMG_TRAP_ACTIVE;
7503 /* if new animation frame was drawn, correct crumbled sand border */
7504 if (IS_NEW_FRAME(GfxFrame[x][y], graphic))
7505 DrawLevelFieldCrumbledSand(x, y);
7508 static int getSpecialActionElement(int element, int number, int base_element)
7510 return (element != EL_EMPTY ? element :
7511 number != -1 ? base_element + number - 1 :
7515 static int getModifiedActionNumber(int value_old, int operator, int operand,
7516 int value_min, int value_max)
7518 int value_new = (operator == CA_MODE_SET ? operand :
7519 operator == CA_MODE_ADD ? value_old + operand :
7520 operator == CA_MODE_SUBTRACT ? value_old - operand :
7521 operator == CA_MODE_MULTIPLY ? value_old * operand :
7522 operator == CA_MODE_DIVIDE ? value_old / MAX(1, operand) :
7523 operator == CA_MODE_MODULO ? value_old % MAX(1, operand) :
7526 return (value_new < value_min ? value_min :
7527 value_new > value_max ? value_max :
7531 static void ExecuteCustomElementAction(int x, int y, int element, int page)
7533 struct ElementInfo *ei = &element_info[element];
7534 struct ElementChangeInfo *change = &ei->change_page[page];
7535 int target_element = change->target_element;
7536 int action_type = change->action_type;
7537 int action_mode = change->action_mode;
7538 int action_arg = change->action_arg;
7541 if (!change->has_action)
7544 /* ---------- determine action paramater values -------------------------- */
7546 int level_time_value =
7547 (level.time > 0 ? TimeLeft :
7550 int action_arg_element =
7551 (action_arg == CA_ARG_PLAYER_TRIGGER ? change->actual_trigger_player :
7552 action_arg == CA_ARG_ELEMENT_TRIGGER ? change->actual_trigger_element :
7553 action_arg == CA_ARG_ELEMENT_TARGET ? change->target_element :
7556 int action_arg_direction =
7557 (action_arg >= CA_ARG_DIRECTION_LEFT &&
7558 action_arg <= CA_ARG_DIRECTION_DOWN ? action_arg - CA_ARG_DIRECTION :
7559 action_arg == CA_ARG_DIRECTION_TRIGGER ?
7560 change->actual_trigger_side :
7561 action_arg == CA_ARG_DIRECTION_TRIGGER_BACK ?
7562 MV_DIR_OPPOSITE(change->actual_trigger_side) :
7565 int action_arg_number_min =
7566 (action_type == CA_SET_PLAYER_SPEED ? STEPSIZE_NOT_MOVING :
7569 int action_arg_number_max =
7570 (action_type == CA_SET_PLAYER_SPEED ? STEPSIZE_EVEN_FASTER :
7571 action_type == CA_SET_LEVEL_GEMS ? 999 :
7572 action_type == CA_SET_LEVEL_TIME ? 9999 :
7573 action_type == CA_SET_LEVEL_SCORE ? 99999 :
7574 action_type == CA_SET_CE_VALUE ? 9999 :
7575 action_type == CA_SET_CE_SCORE ? 9999 :
7578 int action_arg_number_reset =
7579 (action_type == CA_SET_PLAYER_SPEED ? level.initial_player_stepsize[0] :
7580 action_type == CA_SET_LEVEL_GEMS ? level.gems_needed :
7581 action_type == CA_SET_LEVEL_TIME ? level.time :
7582 action_type == CA_SET_LEVEL_SCORE ? 0 :
7583 #if USE_NEW_CUSTOM_VALUE
7584 action_type == CA_SET_CE_VALUE ? GET_NEW_CE_VALUE(element) :
7586 action_type == CA_SET_CE_VALUE ? ei->custom_value_initial :
7588 action_type == CA_SET_CE_SCORE ? 0 :
7591 int action_arg_number =
7592 (action_arg <= CA_ARG_MAX ? action_arg :
7593 action_arg >= CA_ARG_SPEED_NOT_MOVING &&
7594 action_arg <= CA_ARG_SPEED_EVEN_FASTER ? (action_arg - CA_ARG_SPEED) :
7595 action_arg == CA_ARG_SPEED_RESET ? action_arg_number_reset :
7596 action_arg == CA_ARG_NUMBER_MIN ? action_arg_number_min :
7597 action_arg == CA_ARG_NUMBER_MAX ? action_arg_number_max :
7598 action_arg == CA_ARG_NUMBER_RESET ? action_arg_number_reset :
7599 #if USE_NEW_CUSTOM_VALUE
7600 action_arg == CA_ARG_NUMBER_CE_VALUE ? CustomValue[x][y] :
7602 action_arg == CA_ARG_NUMBER_CE_VALUE ? ei->custom_value_initial :
7604 action_arg == CA_ARG_NUMBER_CE_SCORE ? ei->collect_score :
7605 action_arg == CA_ARG_NUMBER_CE_DELAY ? GET_CE_DELAY_VALUE(change) :
7606 action_arg == CA_ARG_NUMBER_LEVEL_TIME ? level_time_value :
7607 action_arg == CA_ARG_NUMBER_LEVEL_GEMS ? local_player->gems_still_needed :
7608 action_arg == CA_ARG_NUMBER_LEVEL_SCORE ? local_player->score :
7609 action_arg == CA_ARG_ELEMENT_CV_TARGET ? GET_NEW_CE_VALUE(target_element):
7610 action_arg == CA_ARG_ELEMENT_CV_TRIGGER ? change->actual_trigger_ce_value:
7611 action_arg == CA_ARG_ELEMENT_CS_TARGET ? GET_CE_SCORE(target_element) :
7612 action_arg == CA_ARG_ELEMENT_CS_TRIGGER ? change->actual_trigger_ce_score:
7613 action_arg == CA_ARG_ELEMENT_NR_TARGET ? change->target_element :
7614 action_arg == CA_ARG_ELEMENT_NR_TRIGGER ? change->actual_trigger_element :
7617 int action_arg_number_old =
7618 (action_type == CA_SET_LEVEL_GEMS ? local_player->gems_still_needed :
7619 action_type == CA_SET_LEVEL_TIME ? TimeLeft :
7620 action_type == CA_SET_LEVEL_SCORE ? local_player->score :
7621 action_type == CA_SET_CE_VALUE ? CustomValue[x][y] :
7622 action_type == CA_SET_CE_SCORE ? ei->collect_score :
7625 int action_arg_number_new =
7626 getModifiedActionNumber(action_arg_number_old,
7627 action_mode, action_arg_number,
7628 action_arg_number_min, action_arg_number_max);
7630 int trigger_player_bits =
7631 (change->actual_trigger_player >= EL_PLAYER_1 &&
7632 change->actual_trigger_player <= EL_PLAYER_4 ?
7633 (1 << (change->actual_trigger_player - EL_PLAYER_1)) :
7636 int action_arg_player_bits =
7637 (action_arg >= CA_ARG_PLAYER_1 &&
7638 action_arg <= CA_ARG_PLAYER_4 ? action_arg - CA_ARG_PLAYER :
7639 action_arg == CA_ARG_PLAYER_TRIGGER ? trigger_player_bits :
7642 /* ---------- execute action -------------------------------------------- */
7651 /* ---------- level actions ------------------------------------------- */
7653 case CA_RESTART_LEVEL:
7655 game.restart_level = TRUE;
7660 case CA_SHOW_ENVELOPE:
7662 int element = getSpecialActionElement(action_arg_element,
7663 action_arg_number, EL_ENVELOPE_1);
7665 if (IS_ENVELOPE(element))
7666 local_player->show_envelope = element;
7671 case CA_SET_LEVEL_TIME:
7673 if (level.time > 0) /* only modify limited time value */
7675 TimeLeft = action_arg_number_new;
7677 DrawGameValue_Time(TimeLeft);
7679 if (!TimeLeft && setup.time_limit)
7680 for (i = 0; i < MAX_PLAYERS; i++)
7681 KillPlayer(&stored_player[i]);
7687 case CA_SET_LEVEL_SCORE:
7689 local_player->score = action_arg_number_new;
7691 DrawGameValue_Score(local_player->score);
7696 case CA_SET_LEVEL_GEMS:
7698 local_player->gems_still_needed = action_arg_number_new;
7700 DrawGameValue_Emeralds(local_player->gems_still_needed);
7705 #if !USE_PLAYER_GRAVITY
7706 case CA_SET_LEVEL_GRAVITY:
7708 game.gravity = (action_arg == CA_ARG_GRAVITY_OFF ? FALSE :
7709 action_arg == CA_ARG_GRAVITY_ON ? TRUE :
7710 action_arg == CA_ARG_GRAVITY_TOGGLE ? !game.gravity :
7716 case CA_SET_LEVEL_WIND:
7718 game.wind_direction = action_arg_direction;
7723 /* ---------- player actions ------------------------------------------ */
7725 case CA_MOVE_PLAYER:
7727 /* automatically move to the next field in specified direction */
7728 for (i = 0; i < MAX_PLAYERS; i++)
7729 if (trigger_player_bits & (1 << i))
7730 stored_player[i].programmed_action = action_arg_direction;
7735 case CA_EXIT_PLAYER:
7737 for (i = 0; i < MAX_PLAYERS; i++)
7738 if (action_arg_player_bits & (1 << i))
7739 PlayerWins(&stored_player[i]);
7744 case CA_KILL_PLAYER:
7746 for (i = 0; i < MAX_PLAYERS; i++)
7747 if (action_arg_player_bits & (1 << i))
7748 KillPlayer(&stored_player[i]);
7753 case CA_SET_PLAYER_KEYS:
7755 int key_state = (action_mode == CA_MODE_ADD ? TRUE : FALSE);
7756 int element = getSpecialActionElement(action_arg_element,
7757 action_arg_number, EL_KEY_1);
7759 if (IS_KEY(element))
7761 for (i = 0; i < MAX_PLAYERS; i++)
7763 if (trigger_player_bits & (1 << i))
7765 stored_player[i].key[KEY_NR(element)] = key_state;
7767 DrawGameDoorValues();
7775 case CA_SET_PLAYER_SPEED:
7777 for (i = 0; i < MAX_PLAYERS; i++)
7779 if (trigger_player_bits & (1 << i))
7781 int move_stepsize = TILEX / stored_player[i].move_delay_value;
7783 if (action_arg == CA_ARG_SPEED_FASTER &&
7784 stored_player[i].cannot_move)
7786 action_arg_number = STEPSIZE_VERY_SLOW;
7788 else if (action_arg == CA_ARG_SPEED_SLOWER ||
7789 action_arg == CA_ARG_SPEED_FASTER)
7791 action_arg_number = 2;
7792 action_mode = (action_arg == CA_ARG_SPEED_SLOWER ? CA_MODE_DIVIDE :
7795 else if (action_arg == CA_ARG_NUMBER_RESET)
7797 action_arg_number = level.initial_player_stepsize[i];
7801 getModifiedActionNumber(move_stepsize,
7804 action_arg_number_min,
7805 action_arg_number_max);
7807 SetPlayerMoveSpeed(&stored_player[i], move_stepsize, FALSE);
7814 case CA_SET_PLAYER_SHIELD:
7816 for (i = 0; i < MAX_PLAYERS; i++)
7818 if (trigger_player_bits & (1 << i))
7820 if (action_arg == CA_ARG_SHIELD_OFF)
7822 stored_player[i].shield_normal_time_left = 0;
7823 stored_player[i].shield_deadly_time_left = 0;
7825 else if (action_arg == CA_ARG_SHIELD_NORMAL)
7827 stored_player[i].shield_normal_time_left = 999999;
7829 else if (action_arg == CA_ARG_SHIELD_DEADLY)
7831 stored_player[i].shield_normal_time_left = 999999;
7832 stored_player[i].shield_deadly_time_left = 999999;
7840 #if USE_PLAYER_GRAVITY
7841 case CA_SET_PLAYER_GRAVITY:
7843 for (i = 0; i < MAX_PLAYERS; i++)
7845 if (trigger_player_bits & (1 << i))
7847 stored_player[i].gravity =
7848 (action_arg == CA_ARG_GRAVITY_OFF ? FALSE :
7849 action_arg == CA_ARG_GRAVITY_ON ? TRUE :
7850 action_arg == CA_ARG_GRAVITY_TOGGLE ? !stored_player[i].gravity :
7851 stored_player[i].gravity);
7859 case CA_SET_PLAYER_ARTWORK:
7861 for (i = 0; i < MAX_PLAYERS; i++)
7863 if (trigger_player_bits & (1 << i))
7865 int artwork_element = action_arg_element;
7867 if (action_arg == CA_ARG_ELEMENT_RESET)
7869 (level.use_artwork_element[i] ? level.artwork_element[i] :
7870 stored_player[i].element_nr);
7872 stored_player[i].artwork_element = artwork_element;
7874 SetPlayerWaiting(&stored_player[i], FALSE);
7876 /* set number of special actions for bored and sleeping animation */
7877 stored_player[i].num_special_action_bored =
7878 get_num_special_action(artwork_element,
7879 ACTION_BORING_1, ACTION_BORING_LAST);
7880 stored_player[i].num_special_action_sleeping =
7881 get_num_special_action(artwork_element,
7882 ACTION_SLEEPING_1, ACTION_SLEEPING_LAST);
7889 /* ---------- CE actions ---------------------------------------------- */
7891 case CA_SET_CE_VALUE:
7893 #if USE_NEW_CUSTOM_VALUE
7894 int last_ce_value = CustomValue[x][y];
7896 CustomValue[x][y] = action_arg_number_new;
7898 if (CustomValue[x][y] != last_ce_value)
7900 CheckElementChange(x, y, element, EL_UNDEFINED, CE_VALUE_CHANGES);
7901 CheckTriggeredElementChange(x, y, element, CE_VALUE_CHANGES_OF_X);
7903 if (CustomValue[x][y] == 0)
7905 CheckElementChange(x, y, element, EL_UNDEFINED, CE_VALUE_GETS_ZERO);
7906 CheckTriggeredElementChange(x, y, element, CE_VALUE_GETS_ZERO_OF_X);
7914 case CA_SET_CE_SCORE:
7916 #if USE_NEW_CUSTOM_VALUE
7917 int last_ce_score = ei->collect_score;
7919 ei->collect_score = action_arg_number_new;
7921 if (ei->collect_score != last_ce_score)
7923 CheckElementChange(x, y, element, EL_UNDEFINED, CE_SCORE_CHANGES);
7924 CheckTriggeredElementChange(x, y, element, CE_SCORE_CHANGES_OF_X);
7926 if (ei->collect_score == 0)
7930 CheckElementChange(x, y, element, EL_UNDEFINED, CE_SCORE_GETS_ZERO);
7931 CheckTriggeredElementChange(x, y, element, CE_SCORE_GETS_ZERO_OF_X);
7934 This is a very special case that seems to be a mixture between
7935 CheckElementChange() and CheckTriggeredElementChange(): while
7936 the first one only affects single elements that are triggered
7937 directly, the second one affects multiple elements in the playfield
7938 that are triggered indirectly by another element. This is a third
7939 case: Changing the CE score always affects multiple identical CEs,
7940 so every affected CE must be checked, not only the single CE for
7941 which the CE score was changed in the first place (as every instance
7942 of that CE shares the same CE score, and therefore also can change)!
7944 SCAN_PLAYFIELD(xx, yy)
7946 if (Feld[xx][yy] == element)
7947 CheckElementChange(xx, yy, element, EL_UNDEFINED,
7948 CE_SCORE_GETS_ZERO);
7957 /* ---------- engine actions ------------------------------------------ */
7959 case CA_SET_ENGINE_SCAN_MODE:
7961 InitPlayfieldScanMode(action_arg);
7971 static void CreateFieldExt(int x, int y, int element, boolean is_change)
7973 int old_element = Feld[x][y];
7974 int new_element = get_element_from_group_element(element);
7975 int previous_move_direction = MovDir[x][y];
7976 #if USE_NEW_CUSTOM_VALUE
7977 int last_ce_value = CustomValue[x][y];
7979 boolean new_element_is_player = ELEM_IS_PLAYER(new_element);
7980 boolean add_player_onto_element = (new_element_is_player &&
7981 #if USE_CODE_THAT_BREAKS_SNAKE_BITE
7982 /* this breaks SnakeBite when a snake is
7983 halfway through a door that closes */
7984 /* NOW FIXED AT LEVEL INIT IN files.c */
7985 new_element != EL_SOKOBAN_FIELD_PLAYER &&
7987 IS_WALKABLE(old_element));
7990 /* check if element under the player changes from accessible to unaccessible
7991 (needed for special case of dropping element which then changes) */
7992 if (IS_PLAYER(x, y) && !PLAYER_EXPLOSION_PROTECTED(x, y) &&
7993 IS_ACCESSIBLE(old_element) && !IS_ACCESSIBLE(new_element))
8001 if (!add_player_onto_element)
8003 if (IS_MOVING(x, y) || IS_BLOCKED(x, y))
8004 RemoveMovingField(x, y);
8008 Feld[x][y] = new_element;
8010 #if !USE_GFX_RESET_GFX_ANIMATION
8011 ResetGfxAnimation(x, y);
8012 ResetRandomAnimationValue(x, y);
8015 if (element_info[new_element].move_direction_initial == MV_START_PREVIOUS)
8016 MovDir[x][y] = previous_move_direction;
8018 #if USE_NEW_CUSTOM_VALUE
8019 if (element_info[new_element].use_last_ce_value)
8020 CustomValue[x][y] = last_ce_value;
8023 InitField_WithBug1(x, y, FALSE);
8025 new_element = Feld[x][y]; /* element may have changed */
8027 #if USE_GFX_RESET_GFX_ANIMATION
8028 ResetGfxAnimation(x, y);
8029 ResetRandomAnimationValue(x, y);
8032 DrawLevelField(x, y);
8034 if (GFX_CRUMBLED(new_element))
8035 DrawLevelFieldCrumbledSandNeighbours(x, y);
8039 /* check if element under the player changes from accessible to unaccessible
8040 (needed for special case of dropping element which then changes) */
8041 /* (must be checked after creating new element for walkable group elements) */
8042 if (IS_PLAYER(x, y) && !PLAYER_EXPLOSION_PROTECTED(x, y) &&
8043 IS_ACCESSIBLE(old_element) && !IS_ACCESSIBLE(new_element))
8051 /* "ChangeCount" not set yet to allow "entered by player" change one time */
8052 if (new_element_is_player)
8053 RelocatePlayer(x, y, new_element);
8056 ChangeCount[x][y]++; /* count number of changes in the same frame */
8058 TestIfBadThingTouchesPlayer(x, y);
8059 TestIfPlayerTouchesCustomElement(x, y);
8060 TestIfElementTouchesCustomElement(x, y);
8063 static void CreateField(int x, int y, int element)
8065 CreateFieldExt(x, y, element, FALSE);
8068 static void CreateElementFromChange(int x, int y, int element)
8070 element = GET_VALID_RUNTIME_ELEMENT(element);
8072 #if USE_STOP_CHANGED_ELEMENTS
8073 if (game.engine_version >= VERSION_IDENT(3,2,0,7))
8075 int old_element = Feld[x][y];
8077 /* prevent changed element from moving in same engine frame
8078 unless both old and new element can either fall or move */
8079 if ((!CAN_FALL(old_element) || !CAN_FALL(element)) &&
8080 (!CAN_MOVE(old_element) || !CAN_MOVE(element)))
8085 CreateFieldExt(x, y, element, TRUE);
8088 static boolean ChangeElement(int x, int y, int element, int page)
8090 struct ElementInfo *ei = &element_info[element];
8091 struct ElementChangeInfo *change = &ei->change_page[page];
8092 int ce_value = CustomValue[x][y];
8093 int ce_score = ei->collect_score;
8095 int old_element = Feld[x][y];
8097 /* always use default change event to prevent running into a loop */
8098 if (ChangeEvent[x][y] == -1)
8099 ChangeEvent[x][y] = CE_DELAY;
8101 if (ChangeEvent[x][y] == CE_DELAY)
8103 /* reset actual trigger element, trigger player and action element */
8104 change->actual_trigger_element = EL_EMPTY;
8105 change->actual_trigger_player = EL_PLAYER_1;
8106 change->actual_trigger_side = CH_SIDE_NONE;
8107 change->actual_trigger_ce_value = 0;
8108 change->actual_trigger_ce_score = 0;
8111 /* do not change elements more than a specified maximum number of changes */
8112 if (ChangeCount[x][y] >= game.max_num_changes_per_frame)
8115 ChangeCount[x][y]++; /* count number of changes in the same frame */
8117 if (change->explode)
8124 if (change->use_target_content)
8126 boolean complete_replace = TRUE;
8127 boolean can_replace[3][3];
8130 for (yy = 0; yy < 3; yy++) for (xx = 0; xx < 3 ; xx++)
8133 boolean is_walkable;
8134 boolean is_diggable;
8135 boolean is_collectible;
8136 boolean is_removable;
8137 boolean is_destructible;
8138 int ex = x + xx - 1;
8139 int ey = y + yy - 1;
8140 int content_element = change->target_content.e[xx][yy];
8143 can_replace[xx][yy] = TRUE;
8145 if (ex == x && ey == y) /* do not check changing element itself */
8148 if (content_element == EL_EMPTY_SPACE)
8150 can_replace[xx][yy] = FALSE; /* do not replace border with space */
8155 if (!IN_LEV_FIELD(ex, ey))
8157 can_replace[xx][yy] = FALSE;
8158 complete_replace = FALSE;
8165 if (IS_MOVING(ex, ey) || IS_BLOCKED(ex, ey))
8166 e = MovingOrBlocked2Element(ex, ey);
8168 is_empty = (IS_FREE(ex, ey) ||
8169 (IS_FREE_OR_PLAYER(ex, ey) && IS_WALKABLE(content_element)));
8171 is_walkable = (is_empty || IS_WALKABLE(e));
8172 is_diggable = (is_empty || IS_DIGGABLE(e));
8173 is_collectible = (is_empty || IS_COLLECTIBLE(e));
8174 is_destructible = (is_empty || !IS_INDESTRUCTIBLE(e));
8175 is_removable = (is_diggable || is_collectible);
8177 can_replace[xx][yy] =
8178 (((change->replace_when == CP_WHEN_EMPTY && is_empty) ||
8179 (change->replace_when == CP_WHEN_WALKABLE && is_walkable) ||
8180 (change->replace_when == CP_WHEN_DIGGABLE && is_diggable) ||
8181 (change->replace_when == CP_WHEN_COLLECTIBLE && is_collectible) ||
8182 (change->replace_when == CP_WHEN_REMOVABLE && is_removable) ||
8183 (change->replace_when == CP_WHEN_DESTRUCTIBLE && is_destructible)) &&
8184 !(IS_PLAYER(ex, ey) && ELEM_IS_PLAYER(content_element)));
8186 if (!can_replace[xx][yy])
8187 complete_replace = FALSE;
8190 if (!change->only_if_complete || complete_replace)
8192 boolean something_has_changed = FALSE;
8194 if (change->only_if_complete && change->use_random_replace &&
8195 RND(100) < change->random_percentage)
8198 for (yy = 0; yy < 3; yy++) for (xx = 0; xx < 3 ; xx++)
8200 int ex = x + xx - 1;
8201 int ey = y + yy - 1;
8202 int content_element;
8204 if (can_replace[xx][yy] && (!change->use_random_replace ||
8205 RND(100) < change->random_percentage))
8207 if (IS_MOVING(ex, ey) || IS_BLOCKED(ex, ey))
8208 RemoveMovingField(ex, ey);
8210 ChangeEvent[ex][ey] = ChangeEvent[x][y];
8212 content_element = change->target_content.e[xx][yy];
8213 target_element = GET_TARGET_ELEMENT(element, content_element, change,
8214 ce_value, ce_score);
8216 CreateElementFromChange(ex, ey, target_element);
8218 something_has_changed = TRUE;
8220 /* for symmetry reasons, freeze newly created border elements */
8221 if (ex != x || ey != y)
8222 Stop[ex][ey] = TRUE; /* no more moving in this frame */
8226 if (something_has_changed)
8228 PlayLevelSoundElementAction(x, y, element, ACTION_CHANGING);
8229 PlayLevelSoundElementAction(x, y, element, ACTION_PAGE_1 + page);
8235 target_element = GET_TARGET_ELEMENT(element, change->target_element, change,
8236 ce_value, ce_score);
8238 if (element == EL_DIAGONAL_GROWING ||
8239 element == EL_DIAGONAL_SHRINKING)
8241 target_element = Store[x][y];
8243 Store[x][y] = EL_EMPTY;
8246 CreateElementFromChange(x, y, target_element);
8248 PlayLevelSoundElementAction(x, y, element, ACTION_CHANGING);
8249 PlayLevelSoundElementAction(x, y, element, ACTION_PAGE_1 + page);
8252 /* this uses direct change before indirect change */
8253 CheckTriggeredElementChangeByPage(x, y, old_element, CE_CHANGE_OF_X, page);
8258 #if USE_NEW_DELAYED_ACTION
8260 static void HandleElementChange(int x, int y, int page)
8262 int element = MovingOrBlocked2Element(x, y);
8263 struct ElementInfo *ei = &element_info[element];
8264 struct ElementChangeInfo *change = &ei->change_page[page];
8267 if (!CAN_CHANGE_OR_HAS_ACTION(element) &&
8268 !CAN_CHANGE_OR_HAS_ACTION(Back[x][y]))
8271 printf("HandleElementChange(): %d,%d: element = %d ('%s')\n",
8272 x, y, element, element_info[element].token_name);
8273 printf("HandleElementChange(): This should never happen!\n");
8278 /* this can happen with classic bombs on walkable, changing elements */
8279 if (!CAN_CHANGE_OR_HAS_ACTION(element))
8282 if (!CAN_CHANGE(Back[x][y])) /* prevent permanent repetition */
8283 ChangeDelay[x][y] = 0;
8289 if (ChangeDelay[x][y] == 0) /* initialize element change */
8291 ChangeDelay[x][y] = GET_CHANGE_DELAY(change) + 1;
8293 if (change->can_change)
8295 ResetGfxAnimation(x, y);
8296 ResetRandomAnimationValue(x, y);
8298 if (change->pre_change_function)
8299 change->pre_change_function(x, y);
8303 ChangeDelay[x][y]--;
8305 if (ChangeDelay[x][y] != 0) /* continue element change */
8307 if (change->can_change)
8309 int graphic = el_act_dir2img(element, GfxAction[x][y], GfxDir[x][y]);
8311 if (IS_ANIMATED(graphic))
8312 DrawLevelGraphicAnimationIfNeeded(x, y, graphic);
8314 if (change->change_function)
8315 change->change_function(x, y);
8318 else /* finish element change */
8320 if (ChangePage[x][y] != -1) /* remember page from delayed change */
8322 page = ChangePage[x][y];
8323 ChangePage[x][y] = -1;
8325 change = &ei->change_page[page];
8328 if (IS_MOVING(x, y)) /* never change a running system ;-) */
8330 ChangeDelay[x][y] = 1; /* try change after next move step */
8331 ChangePage[x][y] = page; /* remember page to use for change */
8336 if (change->can_change)
8338 if (ChangeElement(x, y, element, page))
8340 if (change->post_change_function)
8341 change->post_change_function(x, y);
8345 if (change->has_action)
8346 ExecuteCustomElementAction(x, y, element, page);
8352 static void HandleElementChange(int x, int y, int page)
8354 int element = MovingOrBlocked2Element(x, y);
8355 struct ElementInfo *ei = &element_info[element];
8356 struct ElementChangeInfo *change = &ei->change_page[page];
8359 if (!CAN_CHANGE(element) && !CAN_CHANGE(Back[x][y]))
8362 printf("HandleElementChange(): %d,%d: element = %d ('%s')\n",
8363 x, y, element, element_info[element].token_name);
8364 printf("HandleElementChange(): This should never happen!\n");
8369 /* this can happen with classic bombs on walkable, changing elements */
8370 if (!CAN_CHANGE(element))
8373 if (!CAN_CHANGE(Back[x][y])) /* prevent permanent repetition */
8374 ChangeDelay[x][y] = 0;
8380 if (ChangeDelay[x][y] == 0) /* initialize element change */
8382 ChangeDelay[x][y] = GET_CHANGE_DELAY(change) + 1;
8384 ResetGfxAnimation(x, y);
8385 ResetRandomAnimationValue(x, y);
8387 if (change->pre_change_function)
8388 change->pre_change_function(x, y);
8391 ChangeDelay[x][y]--;
8393 if (ChangeDelay[x][y] != 0) /* continue element change */
8395 int graphic = el_act_dir2img(element, GfxAction[x][y], GfxDir[x][y]);
8397 if (IS_ANIMATED(graphic))
8398 DrawLevelGraphicAnimationIfNeeded(x, y, graphic);
8400 if (change->change_function)
8401 change->change_function(x, y);
8403 else /* finish element change */
8405 if (ChangePage[x][y] != -1) /* remember page from delayed change */
8407 page = ChangePage[x][y];
8408 ChangePage[x][y] = -1;
8410 change = &ei->change_page[page];
8413 if (IS_MOVING(x, y)) /* never change a running system ;-) */
8415 ChangeDelay[x][y] = 1; /* try change after next move step */
8416 ChangePage[x][y] = page; /* remember page to use for change */
8421 if (ChangeElement(x, y, element, page))
8423 if (change->post_change_function)
8424 change->post_change_function(x, y);
8431 static boolean CheckTriggeredElementChangeExt(int trigger_x, int trigger_y,
8432 int trigger_element,
8438 boolean change_done_any = FALSE;
8439 int trigger_page_bits = (trigger_page < 0 ? CH_PAGE_ANY : 1 << trigger_page);
8442 if (!(trigger_events[trigger_element][trigger_event]))
8445 for (i = 0; i < NUM_CUSTOM_ELEMENTS; i++)
8447 int element = EL_CUSTOM_START + i;
8448 boolean change_done = FALSE;
8451 if (!CAN_CHANGE_OR_HAS_ACTION(element) ||
8452 !HAS_ANY_CHANGE_EVENT(element, trigger_event))
8455 for (p = 0; p < element_info[element].num_change_pages; p++)
8457 struct ElementChangeInfo *change = &element_info[element].change_page[p];
8459 if (change->can_change_or_has_action &&
8460 change->has_event[trigger_event] &&
8461 change->trigger_side & trigger_side &&
8462 change->trigger_player & trigger_player &&
8463 change->trigger_page & trigger_page_bits &&
8464 IS_EQUAL_OR_IN_GROUP(trigger_element, change->trigger_element))
8466 change->actual_trigger_element = trigger_element;
8467 change->actual_trigger_player = EL_PLAYER_1 + log_2(trigger_player);
8468 change->actual_trigger_side = trigger_side;
8469 change->actual_trigger_ce_value = CustomValue[trigger_x][trigger_y];
8470 change->actual_trigger_ce_score = GET_CE_SCORE(trigger_element);
8472 if ((change->can_change && !change_done) || change->has_action)
8476 SCAN_PLAYFIELD(x, y)
8478 if (Feld[x][y] == element)
8480 if (change->can_change && !change_done)
8482 ChangeDelay[x][y] = 1;
8483 ChangeEvent[x][y] = trigger_event;
8485 HandleElementChange(x, y, p);
8487 #if USE_NEW_DELAYED_ACTION
8488 else if (change->has_action)
8490 ExecuteCustomElementAction(x, y, element, p);
8491 PlayLevelSoundElementAction(x, y, element, ACTION_PAGE_1 + p);
8494 if (change->has_action)
8496 ExecuteCustomElementAction(x, y, element, p);
8497 PlayLevelSoundElementAction(x, y, element, ACTION_PAGE_1 + p);
8503 if (change->can_change)
8506 change_done_any = TRUE;
8513 return change_done_any;
8516 static boolean CheckElementChangeExt(int x, int y,
8518 int trigger_element,
8523 boolean change_done = FALSE;
8526 if (!CAN_CHANGE_OR_HAS_ACTION(element) ||
8527 !HAS_ANY_CHANGE_EVENT(element, trigger_event))
8530 if (Feld[x][y] == EL_BLOCKED)
8532 Blocked2Moving(x, y, &x, &y);
8533 element = Feld[x][y];
8537 /* check if element has already changed */
8538 if (Feld[x][y] != element)
8541 /* check if element has already changed or is about to change after moving */
8542 if ((game.engine_version < VERSION_IDENT(3,2,0,7) &&
8543 Feld[x][y] != element) ||
8545 (game.engine_version >= VERSION_IDENT(3,2,0,7) &&
8546 (ChangeCount[x][y] >= game.max_num_changes_per_frame ||
8547 ChangePage[x][y] != -1)))
8551 for (p = 0; p < element_info[element].num_change_pages; p++)
8553 struct ElementChangeInfo *change = &element_info[element].change_page[p];
8555 boolean check_trigger_element =
8556 (trigger_event == CE_TOUCHING_X ||
8557 trigger_event == CE_HITTING_X ||
8558 trigger_event == CE_HIT_BY_X);
8560 if (change->can_change_or_has_action &&
8561 change->has_event[trigger_event] &&
8562 change->trigger_side & trigger_side &&
8563 change->trigger_player & trigger_player &&
8564 (!check_trigger_element ||
8565 IS_EQUAL_OR_IN_GROUP(trigger_element, change->trigger_element)))
8567 change->actual_trigger_element = trigger_element;
8568 change->actual_trigger_player = EL_PLAYER_1 + log_2(trigger_player);
8569 change->actual_trigger_side = trigger_side;
8570 change->actual_trigger_ce_value = CustomValue[x][y];
8571 change->actual_trigger_ce_score = GET_CE_SCORE(trigger_element);
8573 /* special case: trigger element not at (x,y) position for some events */
8574 if (check_trigger_element)
8586 { 0, 0 }, { 0, 0 }, { 0, 0 },
8590 int xx = x + move_xy[MV_DIR_OPPOSITE(trigger_side)].dx;
8591 int yy = y + move_xy[MV_DIR_OPPOSITE(trigger_side)].dy;
8593 change->actual_trigger_ce_value = CustomValue[xx][yy];
8594 change->actual_trigger_ce_score = GET_CE_SCORE(trigger_element);
8597 if (change->can_change && !change_done)
8599 ChangeDelay[x][y] = 1;
8600 ChangeEvent[x][y] = trigger_event;
8602 HandleElementChange(x, y, p);
8606 #if USE_NEW_DELAYED_ACTION
8607 else if (change->has_action)
8609 ExecuteCustomElementAction(x, y, element, p);
8610 PlayLevelSoundElementAction(x, y, element, ACTION_PAGE_1 + p);
8613 if (change->has_action)
8615 ExecuteCustomElementAction(x, y, element, p);
8616 PlayLevelSoundElementAction(x, y, element, ACTION_PAGE_1 + p);
8625 static void PlayPlayerSound(struct PlayerInfo *player)
8627 int jx = player->jx, jy = player->jy;
8628 int sound_element = player->artwork_element;
8629 int last_action = player->last_action_waiting;
8630 int action = player->action_waiting;
8632 if (player->is_waiting)
8634 if (action != last_action)
8635 PlayLevelSoundElementAction(jx, jy, sound_element, action);
8637 PlayLevelSoundElementActionIfLoop(jx, jy, sound_element, action);
8641 if (action != last_action)
8642 StopSound(element_info[sound_element].sound[last_action]);
8644 if (last_action == ACTION_SLEEPING)
8645 PlayLevelSoundElementAction(jx, jy, sound_element, ACTION_AWAKENING);
8649 static void PlayAllPlayersSound()
8653 for (i = 0; i < MAX_PLAYERS; i++)
8654 if (stored_player[i].active)
8655 PlayPlayerSound(&stored_player[i]);
8658 static void SetPlayerWaiting(struct PlayerInfo *player, boolean is_waiting)
8660 boolean last_waiting = player->is_waiting;
8661 int move_dir = player->MovDir;
8663 player->dir_waiting = move_dir;
8664 player->last_action_waiting = player->action_waiting;
8668 if (!last_waiting) /* not waiting -> waiting */
8670 player->is_waiting = TRUE;
8672 player->frame_counter_bored =
8674 game.player_boring_delay_fixed +
8675 SimpleRND(game.player_boring_delay_random);
8676 player->frame_counter_sleeping =
8678 game.player_sleeping_delay_fixed +
8679 SimpleRND(game.player_sleeping_delay_random);
8681 InitPlayerGfxAnimation(player, ACTION_WAITING, move_dir);
8684 if (game.player_sleeping_delay_fixed +
8685 game.player_sleeping_delay_random > 0 &&
8686 player->anim_delay_counter == 0 &&
8687 player->post_delay_counter == 0 &&
8688 FrameCounter >= player->frame_counter_sleeping)
8689 player->is_sleeping = TRUE;
8690 else if (game.player_boring_delay_fixed +
8691 game.player_boring_delay_random > 0 &&
8692 FrameCounter >= player->frame_counter_bored)
8693 player->is_bored = TRUE;
8695 player->action_waiting = (player->is_sleeping ? ACTION_SLEEPING :
8696 player->is_bored ? ACTION_BORING :
8699 if (player->is_sleeping && player->use_murphy)
8701 /* special case for sleeping Murphy when leaning against non-free tile */
8703 if (!IN_LEV_FIELD(player->jx - 1, player->jy) ||
8704 (Feld[player->jx - 1][player->jy] != EL_EMPTY &&
8705 !IS_MOVING(player->jx - 1, player->jy)))
8707 else if (!IN_LEV_FIELD(player->jx + 1, player->jy) ||
8708 (Feld[player->jx + 1][player->jy] != EL_EMPTY &&
8709 !IS_MOVING(player->jx + 1, player->jy)))
8710 move_dir = MV_RIGHT;
8712 player->is_sleeping = FALSE;
8714 player->dir_waiting = move_dir;
8717 if (player->is_sleeping)
8719 if (player->num_special_action_sleeping > 0)
8721 if (player->anim_delay_counter == 0 && player->post_delay_counter == 0)
8723 int last_special_action = player->special_action_sleeping;
8724 int num_special_action = player->num_special_action_sleeping;
8725 int special_action =
8726 (last_special_action == ACTION_DEFAULT ? ACTION_SLEEPING_1 :
8727 last_special_action == ACTION_SLEEPING ? ACTION_SLEEPING :
8728 last_special_action < ACTION_SLEEPING_1 + num_special_action - 1 ?
8729 last_special_action + 1 : ACTION_SLEEPING);
8730 int special_graphic =
8731 el_act_dir2img(player->artwork_element, special_action, move_dir);
8733 player->anim_delay_counter =
8734 graphic_info[special_graphic].anim_delay_fixed +
8735 SimpleRND(graphic_info[special_graphic].anim_delay_random);
8736 player->post_delay_counter =
8737 graphic_info[special_graphic].post_delay_fixed +
8738 SimpleRND(graphic_info[special_graphic].post_delay_random);
8740 player->special_action_sleeping = special_action;
8743 if (player->anim_delay_counter > 0)
8745 player->action_waiting = player->special_action_sleeping;
8746 player->anim_delay_counter--;
8748 else if (player->post_delay_counter > 0)
8750 player->post_delay_counter--;
8754 else if (player->is_bored)
8756 if (player->num_special_action_bored > 0)
8758 if (player->anim_delay_counter == 0 && player->post_delay_counter == 0)
8760 int special_action =
8761 ACTION_BORING_1 + SimpleRND(player->num_special_action_bored);
8762 int special_graphic =
8763 el_act_dir2img(player->artwork_element, special_action, move_dir);
8765 player->anim_delay_counter =
8766 graphic_info[special_graphic].anim_delay_fixed +
8767 SimpleRND(graphic_info[special_graphic].anim_delay_random);
8768 player->post_delay_counter =
8769 graphic_info[special_graphic].post_delay_fixed +
8770 SimpleRND(graphic_info[special_graphic].post_delay_random);
8772 player->special_action_bored = special_action;
8775 if (player->anim_delay_counter > 0)
8777 player->action_waiting = player->special_action_bored;
8778 player->anim_delay_counter--;
8780 else if (player->post_delay_counter > 0)
8782 player->post_delay_counter--;
8787 else if (last_waiting) /* waiting -> not waiting */
8789 player->is_waiting = FALSE;
8790 player->is_bored = FALSE;
8791 player->is_sleeping = FALSE;
8793 player->frame_counter_bored = -1;
8794 player->frame_counter_sleeping = -1;
8796 player->anim_delay_counter = 0;
8797 player->post_delay_counter = 0;
8799 player->dir_waiting = player->MovDir;
8800 player->action_waiting = ACTION_DEFAULT;
8802 player->special_action_bored = ACTION_DEFAULT;
8803 player->special_action_sleeping = ACTION_DEFAULT;
8807 static byte PlayerActions(struct PlayerInfo *player, byte player_action)
8809 boolean moved = FALSE, snapped = FALSE, dropped = FALSE;
8810 int left = player_action & JOY_LEFT;
8811 int right = player_action & JOY_RIGHT;
8812 int up = player_action & JOY_UP;
8813 int down = player_action & JOY_DOWN;
8814 int button1 = player_action & JOY_BUTTON_1;
8815 int button2 = player_action & JOY_BUTTON_2;
8816 int dx = (left ? -1 : right ? 1 : 0);
8817 int dy = (up ? -1 : down ? 1 : 0);
8819 if (!player->active || tape.pausing)
8825 snapped = SnapField(player, dx, dy);
8829 dropped = DropElement(player);
8831 moved = MovePlayer(player, dx, dy);
8834 if (tape.single_step && tape.recording && !tape.pausing)
8836 if (button1 || (dropped && !moved))
8838 TapeTogglePause(TAPE_TOGGLE_AUTOMATIC);
8839 SnapField(player, 0, 0); /* stop snapping */
8843 SetPlayerWaiting(player, FALSE);
8845 return player_action;
8849 /* no actions for this player (no input at player's configured device) */
8851 DigField(player, 0, 0, 0, 0, 0, 0, DF_NO_PUSH);
8852 SnapField(player, 0, 0);
8853 CheckGravityMovementWhenNotMoving(player);
8855 if (player->MovPos == 0)
8856 SetPlayerWaiting(player, TRUE);
8858 if (player->MovPos == 0) /* needed for tape.playing */
8859 player->is_moving = FALSE;
8861 player->is_dropping = FALSE;
8862 player->is_dropping_pressed = FALSE;
8863 player->drop_pressed_delay = 0;
8869 static void CheckLevelTime()
8873 if (level.game_engine_type == GAME_ENGINE_TYPE_EM)
8875 if (level.native_em_level->lev->home == 0) /* all players at home */
8877 PlayerWins(local_player);
8879 AllPlayersGone = TRUE;
8881 level.native_em_level->lev->home = -1;
8884 if (level.native_em_level->ply[0]->alive == 0 &&
8885 level.native_em_level->ply[1]->alive == 0 &&
8886 level.native_em_level->ply[2]->alive == 0 &&
8887 level.native_em_level->ply[3]->alive == 0) /* all dead */
8888 AllPlayersGone = TRUE;
8891 if (TimeFrames >= FRAMES_PER_SECOND)
8896 for (i = 0; i < MAX_PLAYERS; i++)
8898 struct PlayerInfo *player = &stored_player[i];
8900 if (SHIELD_ON(player))
8902 player->shield_normal_time_left--;
8904 if (player->shield_deadly_time_left > 0)
8905 player->shield_deadly_time_left--;
8909 if (!local_player->LevelSolved && !level.use_step_counter)
8917 if (TimeLeft <= 10 && setup.time_limit)
8918 PlaySound(SND_GAME_RUNNING_OUT_OF_TIME);
8920 DrawGameValue_Time(TimeLeft);
8922 if (!TimeLeft && setup.time_limit)
8924 if (level.game_engine_type == GAME_ENGINE_TYPE_EM)
8925 level.native_em_level->lev->killed_out_of_time = TRUE;
8927 for (i = 0; i < MAX_PLAYERS; i++)
8928 KillPlayer(&stored_player[i]);
8931 else if (level.time == 0 && !AllPlayersGone) /* level w/o time limit */
8932 DrawGameValue_Time(TimePlayed);
8934 level.native_em_level->lev->time =
8935 (level.time == 0 ? TimePlayed : TimeLeft);
8938 if (tape.recording || tape.playing)
8939 DrawVideoDisplay(VIDEO_STATE_TIME_ON, TapeTime);
8943 void AdvanceFrameAndPlayerCounters(int player_nr)
8947 /* advance frame counters (global frame counter and time frame counter) */
8951 /* advance player counters (counters for move delay, move animation etc.) */
8952 for (i = 0; i < MAX_PLAYERS; i++)
8954 boolean advance_player_counters = (player_nr == -1 || player_nr == i);
8955 int move_delay_value = stored_player[i].move_delay_value;
8956 int move_frames = MOVE_DELAY_NORMAL_SPEED / move_delay_value;
8958 if (!advance_player_counters) /* not all players may be affected */
8961 #if USE_NEW_PLAYER_ANIM
8962 if (move_frames == 0) /* less than one move per game frame */
8964 int stepsize = TILEX / move_delay_value;
8965 int delay = move_delay_value / MOVE_DELAY_NORMAL_SPEED;
8966 int count = (stored_player[i].is_moving ?
8967 ABS(stored_player[i].MovPos) / stepsize : FrameCounter);
8969 if (count % delay == 0)
8974 stored_player[i].Frame += move_frames;
8976 if (stored_player[i].MovPos != 0)
8977 stored_player[i].StepFrame += move_frames;
8979 if (stored_player[i].move_delay > 0)
8980 stored_player[i].move_delay--;
8982 /* due to bugs in previous versions, counter must count up, not down */
8983 if (stored_player[i].push_delay != -1)
8984 stored_player[i].push_delay++;
8986 if (stored_player[i].drop_delay > 0)
8987 stored_player[i].drop_delay--;
8989 if (stored_player[i].is_dropping_pressed)
8990 stored_player[i].drop_pressed_delay++;
8994 void StartGameActions(boolean init_network_game, boolean record_tape,
8997 unsigned long new_random_seed = InitRND(random_seed);
9000 TapeStartRecording(new_random_seed);
9002 #if defined(NETWORK_AVALIABLE)
9003 if (init_network_game)
9005 SendToServer_StartPlaying();
9016 static unsigned long game_frame_delay = 0;
9017 unsigned long game_frame_delay_value;
9018 byte *recorded_player_action;
9019 byte summarized_player_action = 0;
9020 byte tape_action[MAX_PLAYERS];
9023 if (game.restart_level)
9024 StartGameActions(options.network, setup.autorecord, NEW_RANDOMIZE);
9026 if (level.game_engine_type == GAME_ENGINE_TYPE_EM)
9028 if (level.native_em_level->lev->home == 0) /* all players at home */
9030 PlayerWins(local_player);
9032 AllPlayersGone = TRUE;
9034 level.native_em_level->lev->home = -1;
9037 if (level.native_em_level->ply[0]->alive == 0 &&
9038 level.native_em_level->ply[1]->alive == 0 &&
9039 level.native_em_level->ply[2]->alive == 0 &&
9040 level.native_em_level->ply[3]->alive == 0) /* all dead */
9041 AllPlayersGone = TRUE;
9044 if (local_player->LevelSolved)
9047 if (AllPlayersGone && !TAPE_IS_STOPPED(tape))
9050 if (game_status != GAME_MODE_PLAYING) /* status might have changed */
9053 game_frame_delay_value =
9054 (tape.playing && tape.fast_forward ? FfwdFrameDelay : GameFrameDelay);
9056 if (tape.playing && tape.warp_forward && !tape.pausing)
9057 game_frame_delay_value = 0;
9059 /* ---------- main game synchronization point ---------- */
9061 WaitUntilDelayReached(&game_frame_delay, game_frame_delay_value);
9063 if (network_playing && !network_player_action_received)
9065 /* try to get network player actions in time */
9067 #if defined(NETWORK_AVALIABLE)
9068 /* last chance to get network player actions without main loop delay */
9072 /* game was quit by network peer */
9073 if (game_status != GAME_MODE_PLAYING)
9076 if (!network_player_action_received)
9077 return; /* failed to get network player actions in time */
9079 /* do not yet reset "network_player_action_received" (for tape.pausing) */
9085 /* at this point we know that we really continue executing the game */
9087 network_player_action_received = FALSE;
9089 /* when playing tape, read previously recorded player input from tape data */
9090 recorded_player_action = (tape.playing ? TapePlayAction() : NULL);
9093 /* TapePlayAction() may return NULL when toggling to "pause before death" */
9098 if (tape.set_centered_player)
9100 game.centered_player_nr_next = tape.centered_player_nr_next;
9101 game.set_centered_player = TRUE;
9104 for (i = 0; i < MAX_PLAYERS; i++)
9106 summarized_player_action |= stored_player[i].action;
9108 if (!network_playing)
9109 stored_player[i].effective_action = stored_player[i].action;
9112 #if defined(NETWORK_AVALIABLE)
9113 if (network_playing)
9114 SendToServer_MovePlayer(summarized_player_action);
9117 if (!options.network && !setup.team_mode)
9118 local_player->effective_action = summarized_player_action;
9120 if (setup.team_mode && setup.input_on_focus && game.centered_player_nr != -1)
9122 for (i = 0; i < MAX_PLAYERS; i++)
9123 stored_player[i].effective_action =
9124 (i == game.centered_player_nr ? summarized_player_action : 0);
9127 if (recorded_player_action != NULL)
9128 for (i = 0; i < MAX_PLAYERS; i++)
9129 stored_player[i].effective_action = recorded_player_action[i];
9131 for (i = 0; i < MAX_PLAYERS; i++)
9133 tape_action[i] = stored_player[i].effective_action;
9135 /* (this can only happen in the R'n'D game engine) */
9136 if (tape.recording && tape_action[i] && !tape.player_participates[i])
9137 tape.player_participates[i] = TRUE; /* player just appeared from CE */
9140 /* only record actions from input devices, but not programmed actions */
9142 TapeRecordAction(tape_action);
9144 if (level.game_engine_type == GAME_ENGINE_TYPE_EM)
9146 GameActions_EM_Main();
9154 void GameActions_EM_Main()
9156 byte effective_action[MAX_PLAYERS];
9157 boolean warp_mode = (tape.playing && tape.warp_forward && !tape.pausing);
9160 for (i = 0; i < MAX_PLAYERS; i++)
9161 effective_action[i] = stored_player[i].effective_action;
9163 GameActions_EM(effective_action, warp_mode);
9167 AdvanceFrameAndPlayerCounters(-1); /* advance counters for all players */
9170 void GameActions_RND()
9172 int magic_wall_x = 0, magic_wall_y = 0;
9173 int i, x, y, element, graphic;
9175 InitPlayfieldScanModeVars();
9177 #if USE_ONE_MORE_CHANGE_PER_FRAME
9178 if (game.engine_version >= VERSION_IDENT(3,2,0,7))
9180 SCAN_PLAYFIELD(x, y)
9182 ChangeCount[x][y] = 0;
9183 ChangeEvent[x][y] = -1;
9188 if (game.set_centered_player)
9190 boolean all_players_fit_to_screen = checkIfAllPlayersFitToScreen_RND();
9192 /* switching to "all players" only possible if all players fit to screen */
9193 if (game.centered_player_nr_next == -1 && !all_players_fit_to_screen)
9195 game.centered_player_nr_next = game.centered_player_nr;
9196 game.set_centered_player = FALSE;
9199 /* do not switch focus to non-existing (or non-active) player */
9200 if (game.centered_player_nr_next >= 0 &&
9201 !stored_player[game.centered_player_nr_next].active)
9203 game.centered_player_nr_next = game.centered_player_nr;
9204 game.set_centered_player = FALSE;
9208 if (game.set_centered_player &&
9209 ScreenMovPos == 0) /* screen currently aligned at tile position */
9213 if (game.centered_player_nr_next == -1)
9215 setScreenCenteredToAllPlayers(&sx, &sy);
9219 sx = stored_player[game.centered_player_nr_next].jx;
9220 sy = stored_player[game.centered_player_nr_next].jy;
9223 game.centered_player_nr = game.centered_player_nr_next;
9224 game.set_centered_player = FALSE;
9226 DrawRelocateScreen(sx, sy, MV_NONE, TRUE, setup.quick_switch);
9227 DrawGameDoorValues();
9230 for (i = 0; i < MAX_PLAYERS; i++)
9232 int actual_player_action = stored_player[i].effective_action;
9235 /* !!! THIS BREAKS THE FOLLOWING TAPES: !!!
9236 - rnd_equinox_tetrachloride 048
9237 - rnd_equinox_tetrachloride_ii 096
9238 - rnd_emanuel_schmieg 002
9239 - doctor_sloan_ww 001, 020
9241 if (stored_player[i].MovPos == 0)
9242 CheckGravityMovement(&stored_player[i]);
9245 /* overwrite programmed action with tape action */
9246 if (stored_player[i].programmed_action)
9247 actual_player_action = stored_player[i].programmed_action;
9249 PlayerActions(&stored_player[i], actual_player_action);
9251 ScrollPlayer(&stored_player[i], SCROLL_GO_ON);
9254 ScrollScreen(NULL, SCROLL_GO_ON);
9256 /* for backwards compatibility, the following code emulates a fixed bug that
9257 occured when pushing elements (causing elements that just made their last
9258 pushing step to already (if possible) make their first falling step in the
9259 same game frame, which is bad); this code is also needed to use the famous
9260 "spring push bug" which is used in older levels and might be wanted to be
9261 used also in newer levels, but in this case the buggy pushing code is only
9262 affecting the "spring" element and no other elements */
9264 if (game.engine_version < VERSION_IDENT(2,2,0,7) || level.use_spring_bug)
9266 for (i = 0; i < MAX_PLAYERS; i++)
9268 struct PlayerInfo *player = &stored_player[i];
9272 if (player->active && player->is_pushing && player->is_moving &&
9274 (game.engine_version < VERSION_IDENT(2,2,0,7) ||
9275 Feld[x][y] == EL_SPRING))
9277 ContinueMoving(x, y);
9279 /* continue moving after pushing (this is actually a bug) */
9280 if (!IS_MOVING(x, y))
9288 SCAN_PLAYFIELD(x, y)
9290 ChangeCount[x][y] = 0;
9291 ChangeEvent[x][y] = -1;
9293 /* this must be handled before main playfield loop */
9294 if (Feld[x][y] == EL_PLAYER_IS_LEAVING)
9297 if (MovDelay[x][y] <= 0)
9301 #if USE_NEW_SNAP_DELAY
9302 if (Feld[x][y] == EL_ELEMENT_SNAPPING)
9305 if (MovDelay[x][y] <= 0)
9308 DrawLevelField(x, y);
9310 TestIfElementTouchesCustomElement(x, y); /* for empty space */
9316 if (ChangePage[x][y] != -1 && ChangeDelay[x][y] != 1)
9318 printf("GameActions(): x = %d, y = %d: ChangePage != -1\n", x, y);
9319 printf("GameActions(): This should never happen!\n");
9321 ChangePage[x][y] = -1;
9326 if (WasJustMoving[x][y] > 0)
9327 WasJustMoving[x][y]--;
9328 if (WasJustFalling[x][y] > 0)
9329 WasJustFalling[x][y]--;
9330 if (CheckCollision[x][y] > 0)
9331 CheckCollision[x][y]--;
9335 /* reset finished pushing action (not done in ContinueMoving() to allow
9336 continuous pushing animation for elements with zero push delay) */
9337 if (GfxAction[x][y] == ACTION_PUSHING && !IS_MOVING(x, y))
9339 ResetGfxAnimation(x, y);
9340 DrawLevelField(x, y);
9344 if (IS_BLOCKED(x, y))
9348 Blocked2Moving(x, y, &oldx, &oldy);
9349 if (!IS_MOVING(oldx, oldy))
9351 printf("GameActions(): (BLOCKED => MOVING) context corrupted!\n");
9352 printf("GameActions(): BLOCKED: x = %d, y = %d\n", x, y);
9353 printf("GameActions(): !MOVING: oldx = %d, oldy = %d\n", oldx, oldy);
9354 printf("GameActions(): This should never happen!\n");
9360 SCAN_PLAYFIELD(x, y)
9362 element = Feld[x][y];
9363 graphic = el_act_dir2img(element, GfxAction[x][y], GfxDir[x][y]);
9365 ResetGfxFrame(x, y, TRUE);
9367 if (ANIM_MODE(graphic) == ANIM_RANDOM &&
9368 IS_NEXT_FRAME(GfxFrame[x][y], graphic))
9369 ResetRandomAnimationValue(x, y);
9371 SetRandomAnimationValue(x, y);
9373 PlayLevelSoundActionIfLoop(x, y, GfxAction[x][y]);
9375 if (IS_INACTIVE(element))
9377 if (IS_ANIMATED(graphic))
9378 DrawLevelGraphicAnimationIfNeeded(x, y, graphic);
9383 /* this may take place after moving, so 'element' may have changed */
9384 if (IS_CHANGING(x, y) &&
9385 (game.engine_version < VERSION_IDENT(3,0,7,1) || !Stop[x][y]))
9387 int page = element_info[element].event_page_nr[CE_DELAY];
9390 HandleElementChange(x, y, page);
9392 if (CAN_CHANGE(element))
9393 HandleElementChange(x, y, page);
9395 if (HAS_ACTION(element))
9396 ExecuteCustomElementAction(x, y, element, page);
9399 element = Feld[x][y];
9400 graphic = el_act_dir2img(element, GfxAction[x][y], GfxDir[x][y]);
9403 if (!IS_MOVING(x, y) && (CAN_FALL(element) || CAN_MOVE(element)))
9407 element = Feld[x][y];
9408 graphic = el_act_dir2img(element, GfxAction[x][y], GfxDir[x][y]);
9410 if (IS_ANIMATED(graphic) &&
9413 DrawLevelGraphicAnimationIfNeeded(x, y, graphic);
9415 if (IS_GEM(element) || element == EL_SP_INFOTRON)
9416 EdelsteinFunkeln(x, y);
9418 else if ((element == EL_ACID ||
9419 element == EL_EXIT_OPEN ||
9420 element == EL_SP_EXIT_OPEN ||
9421 element == EL_SP_TERMINAL ||
9422 element == EL_SP_TERMINAL_ACTIVE ||
9423 element == EL_EXTRA_TIME ||
9424 element == EL_SHIELD_NORMAL ||
9425 element == EL_SHIELD_DEADLY) &&
9426 IS_ANIMATED(graphic))
9427 DrawLevelGraphicAnimationIfNeeded(x, y, graphic);
9428 else if (IS_MOVING(x, y))
9429 ContinueMoving(x, y);
9430 else if (IS_ACTIVE_BOMB(element))
9431 CheckDynamite(x, y);
9432 else if (element == EL_AMOEBA_GROWING)
9433 AmoebeWaechst(x, y);
9434 else if (element == EL_AMOEBA_SHRINKING)
9435 AmoebaDisappearing(x, y);
9437 #if !USE_NEW_AMOEBA_CODE
9438 else if (IS_AMOEBALIVE(element))
9439 AmoebeAbleger(x, y);
9442 else if (element == EL_GAME_OF_LIFE || element == EL_BIOMAZE)
9444 else if (element == EL_EXIT_CLOSED)
9446 else if (element == EL_SP_EXIT_CLOSED)
9448 else if (element == EL_EXPANDABLE_WALL_GROWING)
9450 else if (element == EL_EXPANDABLE_WALL ||
9451 element == EL_EXPANDABLE_WALL_HORIZONTAL ||
9452 element == EL_EXPANDABLE_WALL_VERTICAL ||
9453 element == EL_EXPANDABLE_WALL_ANY ||
9454 element == EL_BD_EXPANDABLE_WALL)
9456 else if (element == EL_FLAMES)
9457 CheckForDragon(x, y);
9458 else if (element == EL_EXPLOSION)
9459 ; /* drawing of correct explosion animation is handled separately */
9460 else if (element == EL_ELEMENT_SNAPPING ||
9461 element == EL_DIAGONAL_SHRINKING ||
9462 element == EL_DIAGONAL_GROWING)
9464 graphic = el_act_dir2img(GfxElement[x][y], GfxAction[x][y],GfxDir[x][y]);
9466 DrawLevelGraphicAnimationIfNeeded(x, y, graphic);
9468 else if (IS_ANIMATED(graphic) && !IS_CHANGING(x, y))
9469 DrawLevelGraphicAnimationIfNeeded(x, y, graphic);
9471 if (IS_BELT_ACTIVE(element))
9472 PlayLevelSoundAction(x, y, ACTION_ACTIVE);
9474 if (game.magic_wall_active)
9476 int jx = local_player->jx, jy = local_player->jy;
9478 /* play the element sound at the position nearest to the player */
9479 if ((element == EL_MAGIC_WALL_FULL ||
9480 element == EL_MAGIC_WALL_ACTIVE ||
9481 element == EL_MAGIC_WALL_EMPTYING ||
9482 element == EL_BD_MAGIC_WALL_FULL ||
9483 element == EL_BD_MAGIC_WALL_ACTIVE ||
9484 element == EL_BD_MAGIC_WALL_EMPTYING) &&
9485 ABS(x-jx) + ABS(y-jy) < ABS(magic_wall_x-jx) + ABS(magic_wall_y-jy))
9493 #if USE_NEW_AMOEBA_CODE
9494 /* new experimental amoeba growth stuff */
9495 if (!(FrameCounter % 8))
9497 static unsigned long random = 1684108901;
9499 for (i = 0; i < level.amoeba_speed * 28 / 8; i++)
9501 x = RND(lev_fieldx);
9502 y = RND(lev_fieldy);
9503 element = Feld[x][y];
9505 if (!IS_PLAYER(x,y) &&
9506 (element == EL_EMPTY ||
9507 CAN_GROW_INTO(element) ||
9508 element == EL_QUICKSAND_EMPTY ||
9509 element == EL_ACID_SPLASH_LEFT ||
9510 element == EL_ACID_SPLASH_RIGHT))
9512 if ((IN_LEV_FIELD(x, y-1) && Feld[x][y-1] == EL_AMOEBA_WET) ||
9513 (IN_LEV_FIELD(x-1, y) && Feld[x-1][y] == EL_AMOEBA_WET) ||
9514 (IN_LEV_FIELD(x+1, y) && Feld[x+1][y] == EL_AMOEBA_WET) ||
9515 (IN_LEV_FIELD(x, y+1) && Feld[x][y+1] == EL_AMOEBA_WET))
9516 Feld[x][y] = EL_AMOEBA_DROP;
9519 random = random * 129 + 1;
9525 if (game.explosions_delayed)
9528 game.explosions_delayed = FALSE;
9530 SCAN_PLAYFIELD(x, y)
9532 element = Feld[x][y];
9534 if (ExplodeField[x][y])
9535 Explode(x, y, EX_PHASE_START, ExplodeField[x][y]);
9536 else if (element == EL_EXPLOSION)
9537 Explode(x, y, ExplodePhase[x][y], EX_TYPE_NORMAL);
9539 ExplodeField[x][y] = EX_TYPE_NONE;
9542 game.explosions_delayed = TRUE;
9545 if (game.magic_wall_active)
9547 if (!(game.magic_wall_time_left % 4))
9549 int element = Feld[magic_wall_x][magic_wall_y];
9551 if (element == EL_BD_MAGIC_WALL_FULL ||
9552 element == EL_BD_MAGIC_WALL_ACTIVE ||
9553 element == EL_BD_MAGIC_WALL_EMPTYING)
9554 PlayLevelSound(magic_wall_x, magic_wall_y, SND_BD_MAGIC_WALL_ACTIVE);
9556 PlayLevelSound(magic_wall_x, magic_wall_y, SND_MAGIC_WALL_ACTIVE);
9559 if (game.magic_wall_time_left > 0)
9561 game.magic_wall_time_left--;
9562 if (!game.magic_wall_time_left)
9564 SCAN_PLAYFIELD(x, y)
9566 element = Feld[x][y];
9568 if (element == EL_MAGIC_WALL_ACTIVE ||
9569 element == EL_MAGIC_WALL_FULL)
9571 Feld[x][y] = EL_MAGIC_WALL_DEAD;
9572 DrawLevelField(x, y);
9574 else if (element == EL_BD_MAGIC_WALL_ACTIVE ||
9575 element == EL_BD_MAGIC_WALL_FULL)
9577 Feld[x][y] = EL_BD_MAGIC_WALL_DEAD;
9578 DrawLevelField(x, y);
9582 game.magic_wall_active = FALSE;
9587 if (game.light_time_left > 0)
9589 game.light_time_left--;
9591 if (game.light_time_left == 0)
9592 RedrawAllLightSwitchesAndInvisibleElements();
9595 if (game.timegate_time_left > 0)
9597 game.timegate_time_left--;
9599 if (game.timegate_time_left == 0)
9600 CloseAllOpenTimegates();
9603 if (game.lenses_time_left > 0)
9605 game.lenses_time_left--;
9607 if (game.lenses_time_left == 0)
9608 RedrawAllInvisibleElementsForLenses();
9611 if (game.magnify_time_left > 0)
9613 game.magnify_time_left--;
9615 if (game.magnify_time_left == 0)
9616 RedrawAllInvisibleElementsForMagnifier();
9619 for (i = 0; i < MAX_PLAYERS; i++)
9621 struct PlayerInfo *player = &stored_player[i];
9623 if (SHIELD_ON(player))
9625 if (player->shield_deadly_time_left)
9626 PlayLevelSound(player->jx, player->jy, SND_SHIELD_DEADLY_ACTIVE);
9627 else if (player->shield_normal_time_left)
9628 PlayLevelSound(player->jx, player->jy, SND_SHIELD_NORMAL_ACTIVE);
9635 PlayAllPlayersSound();
9637 if (options.debug) /* calculate frames per second */
9639 static unsigned long fps_counter = 0;
9640 static int fps_frames = 0;
9641 unsigned long fps_delay_ms = Counter() - fps_counter;
9645 if (fps_delay_ms >= 500) /* calculate fps every 0.5 seconds */
9647 global.frames_per_second = 1000 * (float)fps_frames / fps_delay_ms;
9650 fps_counter = Counter();
9653 redraw_mask |= REDRAW_FPS;
9656 AdvanceFrameAndPlayerCounters(-1); /* advance counters for all players */
9658 if (local_player->show_envelope != 0 && local_player->MovPos == 0)
9660 ShowEnvelope(local_player->show_envelope - EL_ENVELOPE_1);
9662 local_player->show_envelope = 0;
9665 /* use random number generator in every frame to make it less predictable */
9666 if (game.engine_version >= VERSION_IDENT(3,1,1,0))
9670 static boolean AllPlayersInSight(struct PlayerInfo *player, int x, int y)
9672 int min_x = x, min_y = y, max_x = x, max_y = y;
9675 for (i = 0; i < MAX_PLAYERS; i++)
9677 int jx = stored_player[i].jx, jy = stored_player[i].jy;
9679 if (!stored_player[i].active || &stored_player[i] == player)
9682 min_x = MIN(min_x, jx);
9683 min_y = MIN(min_y, jy);
9684 max_x = MAX(max_x, jx);
9685 max_y = MAX(max_y, jy);
9688 return (max_x - min_x < SCR_FIELDX && max_y - min_y < SCR_FIELDY);
9691 static boolean AllPlayersInVisibleScreen()
9695 for (i = 0; i < MAX_PLAYERS; i++)
9697 int jx = stored_player[i].jx, jy = stored_player[i].jy;
9699 if (!stored_player[i].active)
9702 if (!IN_VIS_FIELD(SCREENX(jx), SCREENY(jy)))
9709 void ScrollLevel(int dx, int dy)
9711 int softscroll_offset = (setup.soft_scrolling ? TILEX : 0);
9714 BlitBitmap(drawto_field, drawto_field,
9715 FX + TILEX * (dx == -1) - softscroll_offset,
9716 FY + TILEY * (dy == -1) - softscroll_offset,
9717 SXSIZE - TILEX * (dx!=0) + 2 * softscroll_offset,
9718 SYSIZE - TILEY * (dy!=0) + 2 * softscroll_offset,
9719 FX + TILEX * (dx == 1) - softscroll_offset,
9720 FY + TILEY * (dy == 1) - softscroll_offset);
9724 x = (dx == 1 ? BX1 : BX2);
9725 for (y = BY1; y <= BY2; y++)
9726 DrawScreenField(x, y);
9731 y = (dy == 1 ? BY1 : BY2);
9732 for (x = BX1; x <= BX2; x++)
9733 DrawScreenField(x, y);
9736 redraw_mask |= REDRAW_FIELD;
9739 static boolean canFallDown(struct PlayerInfo *player)
9741 int jx = player->jx, jy = player->jy;
9743 return (IN_LEV_FIELD(jx, jy + 1) &&
9744 (IS_FREE(jx, jy + 1) ||
9745 (Feld[jx][jy + 1] == EL_ACID && player->can_fall_into_acid)) &&
9746 IS_WALKABLE_FROM(Feld[jx][jy], MV_DOWN) &&
9747 !IS_WALKABLE_INSIDE(Feld[jx][jy]));
9750 static boolean canPassField(int x, int y, int move_dir)
9752 int opposite_dir = MV_DIR_OPPOSITE(move_dir);
9753 int dx = (move_dir & MV_LEFT ? -1 : move_dir & MV_RIGHT ? +1 : 0);
9754 int dy = (move_dir & MV_UP ? -1 : move_dir & MV_DOWN ? +1 : 0);
9757 int element = Feld[x][y];
9759 return (IS_PASSABLE_FROM(element, opposite_dir) &&
9760 !CAN_MOVE(element) &&
9761 IN_LEV_FIELD(nextx, nexty) && !IS_PLAYER(nextx, nexty) &&
9762 IS_WALKABLE_FROM(Feld[nextx][nexty], move_dir) &&
9763 (level.can_pass_to_walkable || IS_FREE(nextx, nexty)));
9766 static boolean canMoveToValidFieldWithGravity(int x, int y, int move_dir)
9768 int opposite_dir = MV_DIR_OPPOSITE(move_dir);
9769 int dx = (move_dir & MV_LEFT ? -1 : move_dir & MV_RIGHT ? +1 : 0);
9770 int dy = (move_dir & MV_UP ? -1 : move_dir & MV_DOWN ? +1 : 0);
9774 return (IN_LEV_FIELD(newx, newy) && !IS_FREE_OR_PLAYER(newx, newy) &&
9775 IS_GRAVITY_REACHABLE(Feld[newx][newy]) &&
9776 (IS_DIGGABLE(Feld[newx][newy]) ||
9777 IS_WALKABLE_FROM(Feld[newx][newy], opposite_dir) ||
9778 canPassField(newx, newy, move_dir)));
9781 static void CheckGravityMovement(struct PlayerInfo *player)
9783 #if USE_PLAYER_GRAVITY
9784 if (player->gravity && !player->programmed_action)
9786 if (game.gravity && !player->programmed_action)
9789 int move_dir_horizontal = player->effective_action & MV_HORIZONTAL;
9790 int move_dir_vertical = player->effective_action & MV_VERTICAL;
9791 boolean player_is_snapping = (player->effective_action & JOY_BUTTON_1);
9792 int jx = player->jx, jy = player->jy;
9793 boolean player_is_moving_to_valid_field =
9794 (!player_is_snapping &&
9795 (canMoveToValidFieldWithGravity(jx, jy, move_dir_horizontal) ||
9796 canMoveToValidFieldWithGravity(jx, jy, move_dir_vertical)));
9797 boolean player_can_fall_down = canFallDown(player);
9799 if (player_can_fall_down &&
9800 !player_is_moving_to_valid_field)
9801 player->programmed_action = MV_DOWN;
9805 static void CheckGravityMovementWhenNotMoving(struct PlayerInfo *player)
9807 return CheckGravityMovement(player);
9809 #if USE_PLAYER_GRAVITY
9810 if (player->gravity && !player->programmed_action)
9812 if (game.gravity && !player->programmed_action)
9815 int jx = player->jx, jy = player->jy;
9816 boolean field_under_player_is_free =
9817 (IN_LEV_FIELD(jx, jy + 1) && IS_FREE(jx, jy + 1));
9818 boolean player_is_standing_on_valid_field =
9819 (IS_WALKABLE_INSIDE(Feld[jx][jy]) ||
9820 (IS_WALKABLE(Feld[jx][jy]) &&
9821 !(element_info[Feld[jx][jy]].access_direction & MV_DOWN)));
9823 if (field_under_player_is_free && !player_is_standing_on_valid_field)
9824 player->programmed_action = MV_DOWN;
9830 -----------------------------------------------------------------------------
9831 dx, dy: direction (non-diagonal) to try to move the player to
9832 real_dx, real_dy: direction as read from input device (can be diagonal)
9835 boolean MovePlayerOneStep(struct PlayerInfo *player,
9836 int dx, int dy, int real_dx, int real_dy)
9838 int jx = player->jx, jy = player->jy;
9839 int new_jx = jx + dx, new_jy = jy + dy;
9840 #if !USE_FIXED_DONT_RUN_INTO
9844 boolean player_can_move = !player->cannot_move;
9846 if (!player->active || (!dx && !dy))
9847 return MP_NO_ACTION;
9849 player->MovDir = (dx < 0 ? MV_LEFT :
9852 dy > 0 ? MV_DOWN : MV_NONE);
9854 if (!IN_LEV_FIELD(new_jx, new_jy))
9855 return MP_NO_ACTION;
9857 if (!player_can_move)
9859 if (player->MovPos == 0)
9861 player->is_moving = FALSE;
9862 player->is_digging = FALSE;
9863 player->is_collecting = FALSE;
9864 player->is_snapping = FALSE;
9865 player->is_pushing = FALSE;
9870 if (!options.network && game.centered_player_nr == -1 &&
9871 !AllPlayersInSight(player, new_jx, new_jy))
9872 return MP_NO_ACTION;
9874 if (!options.network && !AllPlayersInSight(player, new_jx, new_jy))
9875 return MP_NO_ACTION;
9878 #if !USE_FIXED_DONT_RUN_INTO
9879 element = MovingOrBlocked2ElementIfNotLeaving(new_jx, new_jy);
9881 /* (moved to DigField()) */
9882 if (player_can_move && DONT_RUN_INTO(element))
9884 if (element == EL_ACID && dx == 0 && dy == 1)
9886 SplashAcid(new_jx, new_jy);
9887 Feld[jx][jy] = EL_PLAYER_1;
9888 InitMovingField(jx, jy, MV_DOWN);
9889 Store[jx][jy] = EL_ACID;
9890 ContinueMoving(jx, jy);
9894 TestIfPlayerRunsIntoBadThing(jx, jy, player->MovDir);
9900 can_move = DigField(player, jx, jy, new_jx, new_jy, real_dx,real_dy, DF_DIG);
9901 if (can_move != MP_MOVING)
9904 /* check if DigField() has caused relocation of the player */
9905 if (player->jx != jx || player->jy != jy)
9906 return MP_NO_ACTION; /* <-- !!! CHECK THIS [-> MP_ACTION ?] !!! */
9908 StorePlayer[jx][jy] = 0;
9909 player->last_jx = jx;
9910 player->last_jy = jy;
9911 player->jx = new_jx;
9912 player->jy = new_jy;
9913 StorePlayer[new_jx][new_jy] = player->element_nr;
9915 if (player->move_delay_value_next != -1)
9917 player->move_delay_value = player->move_delay_value_next;
9918 player->move_delay_value_next = -1;
9922 (dx > 0 || dy > 0 ? -1 : 1) * (TILEX - TILEX / player->move_delay_value);
9924 player->step_counter++;
9926 PlayerVisit[jx][jy] = FrameCounter;
9928 #if USE_UFAST_PLAYER_EXIT_BUGFIX
9929 player->is_moving = TRUE;
9933 /* should better be called in MovePlayer(), but this breaks some tapes */
9934 ScrollPlayer(player, SCROLL_INIT);
9940 boolean MovePlayer(struct PlayerInfo *player, int dx, int dy)
9942 int jx = player->jx, jy = player->jy;
9943 int old_jx = jx, old_jy = jy;
9944 int moved = MP_NO_ACTION;
9946 if (!player->active)
9951 if (player->MovPos == 0)
9953 player->is_moving = FALSE;
9954 player->is_digging = FALSE;
9955 player->is_collecting = FALSE;
9956 player->is_snapping = FALSE;
9957 player->is_pushing = FALSE;
9963 if (player->move_delay > 0)
9966 player->move_delay = -1; /* set to "uninitialized" value */
9968 /* store if player is automatically moved to next field */
9969 player->is_auto_moving = (player->programmed_action != MV_NONE);
9971 /* remove the last programmed player action */
9972 player->programmed_action = 0;
9976 /* should only happen if pre-1.2 tape recordings are played */
9977 /* this is only for backward compatibility */
9979 int original_move_delay_value = player->move_delay_value;
9982 printf("THIS SHOULD ONLY HAPPEN WITH PRE-1.2 LEVEL TAPES. [%ld]\n",
9986 /* scroll remaining steps with finest movement resolution */
9987 player->move_delay_value = MOVE_DELAY_NORMAL_SPEED;
9989 while (player->MovPos)
9991 ScrollPlayer(player, SCROLL_GO_ON);
9992 ScrollScreen(NULL, SCROLL_GO_ON);
9994 AdvanceFrameAndPlayerCounters(player->index_nr);
10000 player->move_delay_value = original_move_delay_value;
10003 player->is_active = FALSE;
10005 if (player->last_move_dir & MV_HORIZONTAL)
10007 if (!(moved |= MovePlayerOneStep(player, 0, dy, dx, dy)))
10008 moved |= MovePlayerOneStep(player, dx, 0, dx, dy);
10012 if (!(moved |= MovePlayerOneStep(player, dx, 0, dx, dy)))
10013 moved |= MovePlayerOneStep(player, 0, dy, dx, dy);
10016 #if USE_FIXED_BORDER_RUNNING_GFX
10017 if (!moved && !player->is_active)
10019 player->is_moving = FALSE;
10020 player->is_digging = FALSE;
10021 player->is_collecting = FALSE;
10022 player->is_snapping = FALSE;
10023 player->is_pushing = FALSE;
10031 if (moved & MP_MOVING && !ScreenMovPos &&
10032 (player->index_nr == game.centered_player_nr ||
10033 game.centered_player_nr == -1))
10035 if (moved & MP_MOVING && !ScreenMovPos &&
10036 (player == local_player || !options.network))
10039 int old_scroll_x = scroll_x, old_scroll_y = scroll_y;
10040 int offset = (setup.scroll_delay ? 3 : 0);
10042 if (!IN_VIS_FIELD(SCREENX(jx), SCREENY(jy)))
10044 /* actual player has left the screen -- scroll in that direction */
10045 if (jx != old_jx) /* player has moved horizontally */
10046 scroll_x += (jx - old_jx);
10047 else /* player has moved vertically */
10048 scroll_y += (jy - old_jy);
10052 if (jx != old_jx) /* player has moved horizontally */
10054 if ((player->MovDir == MV_LEFT && scroll_x > jx - MIDPOSX + offset) ||
10055 (player->MovDir == MV_RIGHT && scroll_x < jx - MIDPOSX - offset))
10056 scroll_x = jx-MIDPOSX + (scroll_x < jx-MIDPOSX ? -offset : +offset);
10058 /* don't scroll over playfield boundaries */
10059 if (scroll_x < SBX_Left || scroll_x > SBX_Right)
10060 scroll_x = (scroll_x < SBX_Left ? SBX_Left : SBX_Right);
10062 /* don't scroll more than one field at a time */
10063 scroll_x = old_scroll_x + SIGN(scroll_x - old_scroll_x);
10065 /* don't scroll against the player's moving direction */
10066 if ((player->MovDir == MV_LEFT && scroll_x > old_scroll_x) ||
10067 (player->MovDir == MV_RIGHT && scroll_x < old_scroll_x))
10068 scroll_x = old_scroll_x;
10070 else /* player has moved vertically */
10072 if ((player->MovDir == MV_UP && scroll_y > jy - MIDPOSY + offset) ||
10073 (player->MovDir == MV_DOWN && scroll_y < jy - MIDPOSY - offset))
10074 scroll_y = jy-MIDPOSY + (scroll_y < jy-MIDPOSY ? -offset : +offset);
10076 /* don't scroll over playfield boundaries */
10077 if (scroll_y < SBY_Upper || scroll_y > SBY_Lower)
10078 scroll_y = (scroll_y < SBY_Upper ? SBY_Upper : SBY_Lower);
10080 /* don't scroll more than one field at a time */
10081 scroll_y = old_scroll_y + SIGN(scroll_y - old_scroll_y);
10083 /* don't scroll against the player's moving direction */
10084 if ((player->MovDir == MV_UP && scroll_y > old_scroll_y) ||
10085 (player->MovDir == MV_DOWN && scroll_y < old_scroll_y))
10086 scroll_y = old_scroll_y;
10090 if (scroll_x != old_scroll_x || scroll_y != old_scroll_y)
10093 if (!options.network && game.centered_player_nr == -1 &&
10094 !AllPlayersInVisibleScreen())
10096 scroll_x = old_scroll_x;
10097 scroll_y = old_scroll_y;
10101 if (!options.network && !AllPlayersInVisibleScreen())
10103 scroll_x = old_scroll_x;
10104 scroll_y = old_scroll_y;
10109 ScrollScreen(player, SCROLL_INIT);
10110 ScrollLevel(old_scroll_x - scroll_x, old_scroll_y - scroll_y);
10115 player->StepFrame = 0;
10117 if (moved & MP_MOVING)
10119 if (old_jx != jx && old_jy == jy)
10120 player->MovDir = (old_jx < jx ? MV_RIGHT : MV_LEFT);
10121 else if (old_jx == jx && old_jy != jy)
10122 player->MovDir = (old_jy < jy ? MV_DOWN : MV_UP);
10124 DrawLevelField(jx, jy); /* for "crumbled sand" */
10126 player->last_move_dir = player->MovDir;
10127 player->is_moving = TRUE;
10128 player->is_snapping = FALSE;
10129 player->is_switching = FALSE;
10130 player->is_dropping = FALSE;
10131 player->is_dropping_pressed = FALSE;
10132 player->drop_pressed_delay = 0;
10135 /* should better be called here than above, but this breaks some tapes */
10136 ScrollPlayer(player, SCROLL_INIT);
10141 CheckGravityMovementWhenNotMoving(player);
10143 player->is_moving = FALSE;
10145 /* at this point, the player is allowed to move, but cannot move right now
10146 (e.g. because of something blocking the way) -- ensure that the player
10147 is also allowed to move in the next frame (in old versions before 3.1.1,
10148 the player was forced to wait again for eight frames before next try) */
10150 if (game.engine_version >= VERSION_IDENT(3,1,1,0))
10151 player->move_delay = 0; /* allow direct movement in the next frame */
10154 if (player->move_delay == -1) /* not yet initialized by DigField() */
10155 player->move_delay = player->move_delay_value;
10157 if (game.engine_version < VERSION_IDENT(3,0,7,0))
10159 TestIfPlayerTouchesBadThing(jx, jy);
10160 TestIfPlayerTouchesCustomElement(jx, jy);
10163 if (!player->active)
10164 RemovePlayer(player);
10169 void ScrollPlayer(struct PlayerInfo *player, int mode)
10171 int jx = player->jx, jy = player->jy;
10172 int last_jx = player->last_jx, last_jy = player->last_jy;
10173 int move_stepsize = TILEX / player->move_delay_value;
10175 #if USE_NEW_PLAYER_SPEED
10176 if (!player->active)
10179 if (player->MovPos == 0 && mode == SCROLL_GO_ON) /* player not moving */
10182 if (!player->active || player->MovPos == 0)
10186 if (mode == SCROLL_INIT)
10188 player->actual_frame_counter = FrameCounter;
10189 player->GfxPos = move_stepsize * (player->MovPos / move_stepsize);
10191 if ((player->block_last_field || player->block_delay_adjustment > 0) &&
10192 Feld[last_jx][last_jy] == EL_EMPTY)
10194 int last_field_block_delay = 0; /* start with no blocking at all */
10195 int block_delay_adjustment = player->block_delay_adjustment;
10197 /* if player blocks last field, add delay for exactly one move */
10198 if (player->block_last_field)
10200 last_field_block_delay += player->move_delay_value;
10202 /* when blocking enabled, prevent moving up despite gravity */
10203 #if USE_PLAYER_GRAVITY
10204 if (player->gravity && player->MovDir == MV_UP)
10205 block_delay_adjustment = -1;
10207 if (game.gravity && player->MovDir == MV_UP)
10208 block_delay_adjustment = -1;
10212 /* add block delay adjustment (also possible when not blocking) */
10213 last_field_block_delay += block_delay_adjustment;
10215 Feld[last_jx][last_jy] = EL_PLAYER_IS_LEAVING;
10216 MovDelay[last_jx][last_jy] = last_field_block_delay + 1;
10219 #if USE_NEW_PLAYER_SPEED
10220 if (player->MovPos != 0) /* player has not yet reached destination */
10226 else if (!FrameReached(&player->actual_frame_counter, 1))
10229 #if USE_NEW_PLAYER_SPEED
10230 if (player->MovPos != 0)
10232 player->MovPos += (player->MovPos > 0 ? -1 : 1) * move_stepsize;
10233 player->GfxPos = move_stepsize * (player->MovPos / move_stepsize);
10235 /* before DrawPlayer() to draw correct player graphic for this case */
10236 if (player->MovPos == 0)
10237 CheckGravityMovement(player);
10240 player->MovPos += (player->MovPos > 0 ? -1 : 1) * move_stepsize;
10241 player->GfxPos = move_stepsize * (player->MovPos / move_stepsize);
10243 /* before DrawPlayer() to draw correct player graphic for this case */
10244 if (player->MovPos == 0)
10245 CheckGravityMovement(player);
10248 if (player->MovPos == 0) /* player reached destination field */
10250 if (player->move_delay_reset_counter > 0)
10252 player->move_delay_reset_counter--;
10254 if (player->move_delay_reset_counter == 0)
10256 /* continue with normal speed after quickly moving through gate */
10257 HALVE_PLAYER_SPEED(player);
10259 /* be able to make the next move without delay */
10260 player->move_delay = 0;
10264 player->last_jx = jx;
10265 player->last_jy = jy;
10267 if (Feld[jx][jy] == EL_EXIT_OPEN ||
10268 Feld[jx][jy] == EL_SP_EXIT_OPEN ||
10269 Feld[jx][jy] == EL_SP_EXIT_OPENING) /* <-- special case */
10271 DrawPlayer(player); /* needed here only to cleanup last field */
10272 RemovePlayer(player);
10274 if (local_player->friends_still_needed == 0 ||
10275 IS_SP_ELEMENT(Feld[jx][jy]))
10276 PlayerWins(player);
10279 /* this breaks one level: "machine", level 000 */
10281 int move_direction = player->MovDir;
10282 int enter_side = MV_DIR_OPPOSITE(move_direction);
10283 int leave_side = move_direction;
10284 int old_jx = last_jx;
10285 int old_jy = last_jy;
10286 int old_element = Feld[old_jx][old_jy];
10287 int new_element = Feld[jx][jy];
10289 if (IS_CUSTOM_ELEMENT(old_element))
10290 CheckElementChangeByPlayer(old_jx, old_jy, old_element,
10292 player->index_bit, leave_side);
10294 CheckTriggeredElementChangeByPlayer(old_jx, old_jy, old_element,
10295 CE_PLAYER_LEAVES_X,
10296 player->index_bit, leave_side);
10298 if (IS_CUSTOM_ELEMENT(new_element))
10299 CheckElementChangeByPlayer(jx, jy, new_element, CE_ENTERED_BY_PLAYER,
10300 player->index_bit, enter_side);
10302 CheckTriggeredElementChangeByPlayer(jx, jy, new_element,
10303 CE_PLAYER_ENTERS_X,
10304 player->index_bit, enter_side);
10306 CheckTriggeredElementChangeBySide(jx, jy, player->element_nr,
10307 CE_MOVE_OF_X, move_direction);
10310 if (game.engine_version >= VERSION_IDENT(3,0,7,0))
10312 TestIfPlayerTouchesBadThing(jx, jy);
10313 TestIfPlayerTouchesCustomElement(jx, jy);
10315 /* needed because pushed element has not yet reached its destination,
10316 so it would trigger a change event at its previous field location */
10317 if (!player->is_pushing)
10318 TestIfElementTouchesCustomElement(jx, jy); /* for empty space */
10320 if (!player->active)
10321 RemovePlayer(player);
10324 if (!local_player->LevelSolved && level.use_step_counter)
10334 if (TimeLeft <= 10 && setup.time_limit)
10335 PlaySound(SND_GAME_RUNNING_OUT_OF_TIME);
10337 DrawGameValue_Time(TimeLeft);
10339 if (!TimeLeft && setup.time_limit)
10340 for (i = 0; i < MAX_PLAYERS; i++)
10341 KillPlayer(&stored_player[i]);
10343 else if (level.time == 0 && !AllPlayersGone) /* level w/o time limit */
10344 DrawGameValue_Time(TimePlayed);
10347 if (tape.single_step && tape.recording && !tape.pausing &&
10348 !player->programmed_action)
10349 TapeTogglePause(TAPE_TOGGLE_AUTOMATIC);
10353 void ScrollScreen(struct PlayerInfo *player, int mode)
10355 static unsigned long screen_frame_counter = 0;
10357 if (mode == SCROLL_INIT)
10359 /* set scrolling step size according to actual player's moving speed */
10360 ScrollStepSize = TILEX / player->move_delay_value;
10362 screen_frame_counter = FrameCounter;
10363 ScreenMovDir = player->MovDir;
10364 ScreenMovPos = player->MovPos;
10365 ScreenGfxPos = ScrollStepSize * (ScreenMovPos / ScrollStepSize);
10368 else if (!FrameReached(&screen_frame_counter, 1))
10373 ScreenMovPos += (ScreenMovPos > 0 ? -1 : 1) * ScrollStepSize;
10374 ScreenGfxPos = ScrollStepSize * (ScreenMovPos / ScrollStepSize);
10375 redraw_mask |= REDRAW_FIELD;
10378 ScreenMovDir = MV_NONE;
10381 void TestIfPlayerTouchesCustomElement(int x, int y)
10383 static int xy[4][2] =
10390 static int trigger_sides[4][2] =
10392 /* center side border side */
10393 { CH_SIDE_TOP, CH_SIDE_BOTTOM }, /* check top */
10394 { CH_SIDE_LEFT, CH_SIDE_RIGHT }, /* check left */
10395 { CH_SIDE_RIGHT, CH_SIDE_LEFT }, /* check right */
10396 { CH_SIDE_BOTTOM, CH_SIDE_TOP } /* check bottom */
10398 static int touch_dir[4] =
10400 MV_LEFT | MV_RIGHT,
10405 int center_element = Feld[x][y]; /* should always be non-moving! */
10408 for (i = 0; i < NUM_DIRECTIONS; i++)
10410 int xx = x + xy[i][0];
10411 int yy = y + xy[i][1];
10412 int center_side = trigger_sides[i][0];
10413 int border_side = trigger_sides[i][1];
10414 int border_element;
10416 if (!IN_LEV_FIELD(xx, yy))
10419 if (IS_PLAYER(x, y))
10421 struct PlayerInfo *player = PLAYERINFO(x, y);
10423 if (game.engine_version < VERSION_IDENT(3,0,7,0))
10424 border_element = Feld[xx][yy]; /* may be moving! */
10425 else if (!IS_MOVING(xx, yy) && !IS_BLOCKED(xx, yy))
10426 border_element = Feld[xx][yy];
10427 else if (MovDir[xx][yy] & touch_dir[i]) /* elements are touching */
10428 border_element = MovingOrBlocked2Element(xx, yy);
10430 continue; /* center and border element do not touch */
10432 CheckElementChangeByPlayer(xx, yy, border_element, CE_TOUCHED_BY_PLAYER,
10433 player->index_bit, border_side);
10434 CheckTriggeredElementChangeByPlayer(xx, yy, border_element,
10435 CE_PLAYER_TOUCHES_X,
10436 player->index_bit, border_side);
10438 else if (IS_PLAYER(xx, yy))
10440 struct PlayerInfo *player = PLAYERINFO(xx, yy);
10442 if (game.engine_version >= VERSION_IDENT(3,0,7,0))
10444 if (player->MovPos != 0 && !(player->MovDir & touch_dir[i]))
10445 continue; /* center and border element do not touch */
10448 CheckElementChangeByPlayer(x, y, center_element, CE_TOUCHED_BY_PLAYER,
10449 player->index_bit, center_side);
10450 CheckTriggeredElementChangeByPlayer(x, y, center_element,
10451 CE_PLAYER_TOUCHES_X,
10452 player->index_bit, center_side);
10458 #if USE_ELEMENT_TOUCHING_BUGFIX
10460 void TestIfElementTouchesCustomElement(int x, int y)
10462 static int xy[4][2] =
10469 static int trigger_sides[4][2] =
10471 /* center side border side */
10472 { CH_SIDE_TOP, CH_SIDE_BOTTOM }, /* check top */
10473 { CH_SIDE_LEFT, CH_SIDE_RIGHT }, /* check left */
10474 { CH_SIDE_RIGHT, CH_SIDE_LEFT }, /* check right */
10475 { CH_SIDE_BOTTOM, CH_SIDE_TOP } /* check bottom */
10477 static int touch_dir[4] =
10479 MV_LEFT | MV_RIGHT,
10484 boolean change_center_element = FALSE;
10485 int center_element = Feld[x][y]; /* should always be non-moving! */
10486 int border_element_old[NUM_DIRECTIONS];
10489 for (i = 0; i < NUM_DIRECTIONS; i++)
10491 int xx = x + xy[i][0];
10492 int yy = y + xy[i][1];
10493 int border_element;
10495 border_element_old[i] = -1;
10497 if (!IN_LEV_FIELD(xx, yy))
10500 if (game.engine_version < VERSION_IDENT(3,0,7,0))
10501 border_element = Feld[xx][yy]; /* may be moving! */
10502 else if (!IS_MOVING(xx, yy) && !IS_BLOCKED(xx, yy))
10503 border_element = Feld[xx][yy];
10504 else if (MovDir[xx][yy] & touch_dir[i]) /* elements are touching */
10505 border_element = MovingOrBlocked2Element(xx, yy);
10507 continue; /* center and border element do not touch */
10509 border_element_old[i] = border_element;
10512 for (i = 0; i < NUM_DIRECTIONS; i++)
10514 int xx = x + xy[i][0];
10515 int yy = y + xy[i][1];
10516 int center_side = trigger_sides[i][0];
10517 int border_element = border_element_old[i];
10519 if (border_element == -1)
10522 /* check for change of border element */
10523 CheckElementChangeBySide(xx, yy, border_element, center_element,
10524 CE_TOUCHING_X, center_side);
10527 for (i = 0; i < NUM_DIRECTIONS; i++)
10529 int border_side = trigger_sides[i][1];
10530 int border_element = border_element_old[i];
10532 if (border_element == -1)
10535 /* check for change of center element (but change it only once) */
10536 if (!change_center_element)
10537 change_center_element =
10538 CheckElementChangeBySide(x, y, center_element, border_element,
10539 CE_TOUCHING_X, border_side);
10545 void TestIfElementTouchesCustomElement_OLD(int x, int y)
10547 static int xy[4][2] =
10554 static int trigger_sides[4][2] =
10556 /* center side border side */
10557 { CH_SIDE_TOP, CH_SIDE_BOTTOM }, /* check top */
10558 { CH_SIDE_LEFT, CH_SIDE_RIGHT }, /* check left */
10559 { CH_SIDE_RIGHT, CH_SIDE_LEFT }, /* check right */
10560 { CH_SIDE_BOTTOM, CH_SIDE_TOP } /* check bottom */
10562 static int touch_dir[4] =
10564 MV_LEFT | MV_RIGHT,
10569 boolean change_center_element = FALSE;
10570 int center_element = Feld[x][y]; /* should always be non-moving! */
10573 for (i = 0; i < NUM_DIRECTIONS; i++)
10575 int xx = x + xy[i][0];
10576 int yy = y + xy[i][1];
10577 int center_side = trigger_sides[i][0];
10578 int border_side = trigger_sides[i][1];
10579 int border_element;
10581 if (!IN_LEV_FIELD(xx, yy))
10584 if (game.engine_version < VERSION_IDENT(3,0,7,0))
10585 border_element = Feld[xx][yy]; /* may be moving! */
10586 else if (!IS_MOVING(xx, yy) && !IS_BLOCKED(xx, yy))
10587 border_element = Feld[xx][yy];
10588 else if (MovDir[xx][yy] & touch_dir[i]) /* elements are touching */
10589 border_element = MovingOrBlocked2Element(xx, yy);
10591 continue; /* center and border element do not touch */
10593 /* check for change of center element (but change it only once) */
10594 if (!change_center_element)
10595 change_center_element =
10596 CheckElementChangeBySide(x, y, center_element, border_element,
10597 CE_TOUCHING_X, border_side);
10599 /* check for change of border element */
10600 CheckElementChangeBySide(xx, yy, border_element, center_element,
10601 CE_TOUCHING_X, center_side);
10607 void TestIfElementHitsCustomElement(int x, int y, int direction)
10609 int dx = (direction == MV_LEFT ? -1 : direction == MV_RIGHT ? +1 : 0);
10610 int dy = (direction == MV_UP ? -1 : direction == MV_DOWN ? +1 : 0);
10611 int hitx = x + dx, hity = y + dy;
10612 int hitting_element = Feld[x][y];
10613 int touched_element;
10615 if (IN_LEV_FIELD(hitx, hity) && IS_FREE(hitx, hity))
10618 touched_element = (IN_LEV_FIELD(hitx, hity) ?
10619 MovingOrBlocked2Element(hitx, hity) : EL_STEELWALL);
10621 if (IN_LEV_FIELD(hitx, hity))
10623 int opposite_direction = MV_DIR_OPPOSITE(direction);
10624 int hitting_side = direction;
10625 int touched_side = opposite_direction;
10626 boolean object_hit = (!IS_MOVING(hitx, hity) ||
10627 MovDir[hitx][hity] != direction ||
10628 ABS(MovPos[hitx][hity]) <= TILEY / 2);
10634 CheckElementChangeBySide(x, y, hitting_element, touched_element,
10635 CE_HITTING_X, touched_side);
10637 CheckElementChangeBySide(hitx, hity, touched_element,
10638 hitting_element, CE_HIT_BY_X, hitting_side);
10640 CheckElementChangeBySide(hitx, hity, touched_element, hitting_element,
10641 CE_HIT_BY_SOMETHING, opposite_direction);
10645 /* "hitting something" is also true when hitting the playfield border */
10646 CheckElementChangeBySide(x, y, hitting_element, touched_element,
10647 CE_HITTING_SOMETHING, direction);
10651 void TestIfElementSmashesCustomElement(int x, int y, int direction)
10653 int dx = (direction == MV_LEFT ? -1 : direction == MV_RIGHT ? +1 : 0);
10654 int dy = (direction == MV_UP ? -1 : direction == MV_DOWN ? +1 : 0);
10655 int hitx = x + dx, hity = y + dy;
10656 int hitting_element = Feld[x][y];
10657 int touched_element;
10659 boolean object_hit = (IN_LEV_FIELD(hitx, hity) &&
10660 !IS_FREE(hitx, hity) &&
10661 (!IS_MOVING(hitx, hity) ||
10662 MovDir[hitx][hity] != direction ||
10663 ABS(MovPos[hitx][hity]) <= TILEY / 2));
10666 if (IN_LEV_FIELD(hitx, hity) && IS_FREE(hitx, hity))
10670 if (IN_LEV_FIELD(hitx, hity) && !object_hit)
10674 touched_element = (IN_LEV_FIELD(hitx, hity) ?
10675 MovingOrBlocked2Element(hitx, hity) : EL_STEELWALL);
10677 CheckElementChangeBySide(x, y, hitting_element, touched_element,
10678 EP_CAN_SMASH_EVERYTHING, direction);
10680 if (IN_LEV_FIELD(hitx, hity))
10682 int opposite_direction = MV_DIR_OPPOSITE(direction);
10683 int hitting_side = direction;
10684 int touched_side = opposite_direction;
10686 int touched_element = MovingOrBlocked2Element(hitx, hity);
10689 boolean object_hit = (!IS_MOVING(hitx, hity) ||
10690 MovDir[hitx][hity] != direction ||
10691 ABS(MovPos[hitx][hity]) <= TILEY / 2);
10700 CheckElementChangeBySide(hitx, hity, touched_element, hitting_element,
10701 CE_SMASHED_BY_SOMETHING, opposite_direction);
10703 CheckElementChangeBySide(x, y, hitting_element, touched_element,
10704 CE_OTHER_IS_SMASHING, touched_side);
10706 CheckElementChangeBySide(hitx, hity, touched_element, hitting_element,
10707 CE_OTHER_GETS_SMASHED, hitting_side);
10713 void TestIfGoodThingHitsBadThing(int good_x, int good_y, int good_move_dir)
10715 int i, kill_x = -1, kill_y = -1;
10717 int bad_element = -1;
10718 static int test_xy[4][2] =
10725 static int test_dir[4] =
10733 for (i = 0; i < NUM_DIRECTIONS; i++)
10735 int test_x, test_y, test_move_dir, test_element;
10737 test_x = good_x + test_xy[i][0];
10738 test_y = good_y + test_xy[i][1];
10740 if (!IN_LEV_FIELD(test_x, test_y))
10744 (IS_MOVING(test_x, test_y) ? MovDir[test_x][test_y] : MV_NONE);
10746 test_element = MovingOrBlocked2ElementIfNotLeaving(test_x, test_y);
10748 /* 1st case: good thing is moving towards DONT_RUN_INTO style bad thing;
10749 2nd case: DONT_TOUCH style bad thing does not move away from good thing
10751 if ((DONT_RUN_INTO(test_element) && good_move_dir == test_dir[i]) ||
10752 (DONT_TOUCH(test_element) && test_move_dir != test_dir[i]))
10756 bad_element = test_element;
10762 if (kill_x != -1 || kill_y != -1)
10764 if (IS_PLAYER(good_x, good_y))
10766 struct PlayerInfo *player = PLAYERINFO(good_x, good_y);
10768 if (player->shield_deadly_time_left > 0 &&
10769 !IS_INDESTRUCTIBLE(bad_element))
10770 Bang(kill_x, kill_y);
10771 else if (!PLAYER_ENEMY_PROTECTED(good_x, good_y))
10772 KillPlayer(player);
10775 Bang(good_x, good_y);
10779 void TestIfBadThingHitsGoodThing(int bad_x, int bad_y, int bad_move_dir)
10781 int i, kill_x = -1, kill_y = -1;
10782 int bad_element = Feld[bad_x][bad_y];
10783 static int test_xy[4][2] =
10790 static int touch_dir[4] =
10792 MV_LEFT | MV_RIGHT,
10797 static int test_dir[4] =
10805 if (bad_element == EL_EXPLOSION) /* skip just exploding bad things */
10808 for (i = 0; i < NUM_DIRECTIONS; i++)
10810 int test_x, test_y, test_move_dir, test_element;
10812 test_x = bad_x + test_xy[i][0];
10813 test_y = bad_y + test_xy[i][1];
10814 if (!IN_LEV_FIELD(test_x, test_y))
10818 (IS_MOVING(test_x, test_y) ? MovDir[test_x][test_y] : MV_NONE);
10820 test_element = Feld[test_x][test_y];
10822 /* 1st case: good thing is moving towards DONT_RUN_INTO style bad thing;
10823 2nd case: DONT_TOUCH style bad thing does not move away from good thing
10825 if ((DONT_RUN_INTO(bad_element) && bad_move_dir == test_dir[i]) ||
10826 (DONT_TOUCH(bad_element) && test_move_dir != test_dir[i]))
10828 /* good thing is player or penguin that does not move away */
10829 if (IS_PLAYER(test_x, test_y))
10831 struct PlayerInfo *player = PLAYERINFO(test_x, test_y);
10833 if (bad_element == EL_ROBOT && player->is_moving)
10834 continue; /* robot does not kill player if he is moving */
10836 if (game.engine_version >= VERSION_IDENT(3,0,7,0))
10838 if (player->MovPos != 0 && !(player->MovDir & touch_dir[i]))
10839 continue; /* center and border element do not touch */
10846 else if (test_element == EL_PENGUIN)
10855 if (kill_x != -1 || kill_y != -1)
10857 if (IS_PLAYER(kill_x, kill_y))
10859 struct PlayerInfo *player = PLAYERINFO(kill_x, kill_y);
10861 if (player->shield_deadly_time_left > 0 &&
10862 !IS_INDESTRUCTIBLE(bad_element))
10863 Bang(bad_x, bad_y);
10864 else if (!PLAYER_ENEMY_PROTECTED(kill_x, kill_y))
10865 KillPlayer(player);
10868 Bang(kill_x, kill_y);
10872 void TestIfPlayerTouchesBadThing(int x, int y)
10874 TestIfGoodThingHitsBadThing(x, y, MV_NONE);
10877 void TestIfPlayerRunsIntoBadThing(int x, int y, int move_dir)
10879 TestIfGoodThingHitsBadThing(x, y, move_dir);
10882 void TestIfBadThingTouchesPlayer(int x, int y)
10884 TestIfBadThingHitsGoodThing(x, y, MV_NONE);
10887 void TestIfBadThingRunsIntoPlayer(int x, int y, int move_dir)
10889 TestIfBadThingHitsGoodThing(x, y, move_dir);
10892 void TestIfFriendTouchesBadThing(int x, int y)
10894 TestIfGoodThingHitsBadThing(x, y, MV_NONE);
10897 void TestIfBadThingTouchesFriend(int x, int y)
10899 TestIfBadThingHitsGoodThing(x, y, MV_NONE);
10902 void TestIfBadThingTouchesOtherBadThing(int bad_x, int bad_y)
10904 int i, kill_x = bad_x, kill_y = bad_y;
10905 static int xy[4][2] =
10913 for (i = 0; i < NUM_DIRECTIONS; i++)
10917 x = bad_x + xy[i][0];
10918 y = bad_y + xy[i][1];
10919 if (!IN_LEV_FIELD(x, y))
10922 element = Feld[x][y];
10923 if (IS_AMOEBOID(element) || element == EL_GAME_OF_LIFE ||
10924 element == EL_AMOEBA_GROWING || element == EL_AMOEBA_DROP)
10932 if (kill_x != bad_x || kill_y != bad_y)
10933 Bang(bad_x, bad_y);
10936 void KillPlayer(struct PlayerInfo *player)
10938 int jx = player->jx, jy = player->jy;
10940 if (!player->active)
10943 /* remove accessible field at the player's position */
10944 Feld[jx][jy] = EL_EMPTY;
10946 /* deactivate shield (else Bang()/Explode() would not work right) */
10947 player->shield_normal_time_left = 0;
10948 player->shield_deadly_time_left = 0;
10951 BuryPlayer(player);
10954 static void KillPlayerUnlessEnemyProtected(int x, int y)
10956 if (!PLAYER_ENEMY_PROTECTED(x, y))
10957 KillPlayer(PLAYERINFO(x, y));
10960 static void KillPlayerUnlessExplosionProtected(int x, int y)
10962 if (!PLAYER_EXPLOSION_PROTECTED(x, y))
10963 KillPlayer(PLAYERINFO(x, y));
10966 void BuryPlayer(struct PlayerInfo *player)
10968 int jx = player->jx, jy = player->jy;
10970 if (!player->active)
10973 PlayLevelSoundElementAction(jx, jy, player->artwork_element, ACTION_DYING);
10974 PlayLevelSound(jx, jy, SND_GAME_LOSING);
10976 player->GameOver = TRUE;
10977 RemovePlayer(player);
10980 void RemovePlayer(struct PlayerInfo *player)
10982 int jx = player->jx, jy = player->jy;
10983 int i, found = FALSE;
10985 player->present = FALSE;
10986 player->active = FALSE;
10988 if (!ExplodeField[jx][jy])
10989 StorePlayer[jx][jy] = 0;
10991 if (player->is_moving)
10992 DrawLevelField(player->last_jx, player->last_jy);
10994 for (i = 0; i < MAX_PLAYERS; i++)
10995 if (stored_player[i].active)
10999 AllPlayersGone = TRUE;
11005 #if USE_NEW_SNAP_DELAY
11006 static void setFieldForSnapping(int x, int y, int element, int direction)
11008 struct ElementInfo *ei = &element_info[element];
11009 int direction_bit = MV_DIR_TO_BIT(direction);
11010 int graphic_snapping = ei->direction_graphic[ACTION_SNAPPING][direction_bit];
11011 int action = (graphic_snapping != IMG_EMPTY_SPACE ? ACTION_SNAPPING :
11012 IS_DIGGABLE(element) ? ACTION_DIGGING : ACTION_COLLECTING);
11014 Feld[x][y] = EL_ELEMENT_SNAPPING;
11015 MovDelay[x][y] = MOVE_DELAY_NORMAL_SPEED + 1 - 1;
11017 ResetGfxAnimation(x, y);
11019 GfxElement[x][y] = element;
11020 GfxAction[x][y] = action;
11021 GfxDir[x][y] = direction;
11022 GfxFrame[x][y] = -1;
11027 =============================================================================
11028 checkDiagonalPushing()
11029 -----------------------------------------------------------------------------
11030 check if diagonal input device direction results in pushing of object
11031 (by checking if the alternative direction is walkable, diggable, ...)
11032 =============================================================================
11035 static boolean checkDiagonalPushing(struct PlayerInfo *player,
11036 int x, int y, int real_dx, int real_dy)
11038 int jx, jy, dx, dy, xx, yy;
11040 if (real_dx == 0 || real_dy == 0) /* no diagonal direction => push */
11043 /* diagonal direction: check alternative direction */
11048 xx = jx + (dx == 0 ? real_dx : 0);
11049 yy = jy + (dy == 0 ? real_dy : 0);
11051 return (!IN_LEV_FIELD(xx, yy) || IS_SOLID_FOR_PUSHING(Feld[xx][yy]));
11055 =============================================================================
11057 -----------------------------------------------------------------------------
11058 x, y: field next to player (non-diagonal) to try to dig to
11059 real_dx, real_dy: direction as read from input device (can be diagonal)
11060 =============================================================================
11063 int DigField(struct PlayerInfo *player,
11064 int oldx, int oldy, int x, int y,
11065 int real_dx, int real_dy, int mode)
11067 boolean is_player = (IS_PLAYER(oldx, oldy) || mode != DF_DIG);
11068 boolean player_was_pushing = player->is_pushing;
11069 boolean player_can_move = (!player->cannot_move && mode != DF_SNAP);
11070 boolean player_can_move_or_snap = (!player->cannot_move || mode == DF_SNAP);
11071 int jx = oldx, jy = oldy;
11072 int dx = x - jx, dy = y - jy;
11073 int nextx = x + dx, nexty = y + dy;
11074 int move_direction = (dx == -1 ? MV_LEFT :
11075 dx == +1 ? MV_RIGHT :
11077 dy == +1 ? MV_DOWN : MV_NONE);
11078 int opposite_direction = MV_DIR_OPPOSITE(move_direction);
11079 int dig_side = MV_DIR_OPPOSITE(move_direction);
11080 int old_element = Feld[jx][jy];
11081 #if USE_FIXED_DONT_RUN_INTO
11082 int element = MovingOrBlocked2ElementIfNotLeaving(x, y);
11088 if (is_player) /* function can also be called by EL_PENGUIN */
11090 if (player->MovPos == 0)
11092 player->is_digging = FALSE;
11093 player->is_collecting = FALSE;
11096 if (player->MovPos == 0) /* last pushing move finished */
11097 player->is_pushing = FALSE;
11099 if (mode == DF_NO_PUSH) /* player just stopped pushing */
11101 player->is_switching = FALSE;
11102 player->push_delay = -1;
11104 return MP_NO_ACTION;
11108 #if !USE_FIXED_DONT_RUN_INTO
11109 if (IS_MOVING(x, y) || IS_PLAYER(x, y))
11110 return MP_NO_ACTION;
11113 if (IS_TUBE(Back[jx][jy]) && game.engine_version >= VERSION_IDENT(2,2,0,0))
11114 old_element = Back[jx][jy];
11116 /* in case of element dropped at player position, check background */
11117 else if (Back[jx][jy] != EL_EMPTY &&
11118 game.engine_version >= VERSION_IDENT(2,2,0,0))
11119 old_element = Back[jx][jy];
11121 if (IS_WALKABLE(old_element) && !ACCESS_FROM(old_element, move_direction))
11122 return MP_NO_ACTION; /* field has no opening in this direction */
11124 if (IS_PASSABLE(old_element) && !ACCESS_FROM(old_element,opposite_direction))
11125 return MP_NO_ACTION; /* field has no opening in this direction */
11127 #if USE_FIXED_DONT_RUN_INTO
11128 if (player_can_move && element == EL_ACID && move_direction == MV_DOWN)
11132 Feld[jx][jy] = player->artwork_element;
11133 InitMovingField(jx, jy, MV_DOWN);
11134 Store[jx][jy] = EL_ACID;
11135 ContinueMoving(jx, jy);
11136 BuryPlayer(player);
11138 return MP_DONT_RUN_INTO;
11142 #if USE_FIXED_DONT_RUN_INTO
11143 if (player_can_move && DONT_RUN_INTO(element))
11145 TestIfPlayerRunsIntoBadThing(jx, jy, player->MovDir);
11147 return MP_DONT_RUN_INTO;
11151 #if USE_FIXED_DONT_RUN_INTO
11152 if (IS_MOVING(x, y) || IS_PLAYER(x, y))
11153 return MP_NO_ACTION;
11156 #if !USE_FIXED_DONT_RUN_INTO
11157 element = Feld[x][y];
11160 collect_count = element_info[element].collect_count_initial;
11162 if (!is_player && !IS_COLLECTIBLE(element)) /* penguin cannot collect it */
11163 return MP_NO_ACTION;
11165 if (game.engine_version < VERSION_IDENT(2,2,0,0))
11166 player_can_move = player_can_move_or_snap;
11168 if (mode == DF_SNAP && !IS_SNAPPABLE(element) &&
11169 game.engine_version >= VERSION_IDENT(2,2,0,0))
11171 CheckElementChangeByPlayer(x, y, element, CE_SNAPPED_BY_PLAYER,
11172 player->index_bit, dig_side);
11173 CheckTriggeredElementChangeByPlayer(x, y, element, CE_PLAYER_SNAPS_X,
11174 player->index_bit, dig_side);
11176 if (Feld[x][y] != element) /* field changed by snapping */
11179 return MP_NO_ACTION;
11182 #if USE_PLAYER_GRAVITY
11183 if (player->gravity && is_player && !player->is_auto_moving &&
11184 canFallDown(player) && move_direction != MV_DOWN &&
11185 !canMoveToValidFieldWithGravity(jx, jy, move_direction))
11186 return MP_NO_ACTION; /* player cannot walk here due to gravity */
11188 if (game.gravity && is_player && !player->is_auto_moving &&
11189 canFallDown(player) && move_direction != MV_DOWN &&
11190 !canMoveToValidFieldWithGravity(jx, jy, move_direction))
11191 return MP_NO_ACTION; /* player cannot walk here due to gravity */
11194 if (player_can_move &&
11195 IS_WALKABLE(element) && ACCESS_FROM(element, opposite_direction))
11197 int sound_element = SND_ELEMENT(element);
11198 int sound_action = ACTION_WALKING;
11200 if (IS_RND_GATE(element))
11202 if (!player->key[RND_GATE_NR(element)])
11203 return MP_NO_ACTION;
11205 else if (IS_RND_GATE_GRAY(element))
11207 if (!player->key[RND_GATE_GRAY_NR(element)])
11208 return MP_NO_ACTION;
11210 else if (IS_RND_GATE_GRAY_ACTIVE(element))
11212 if (!player->key[RND_GATE_GRAY_ACTIVE_NR(element)])
11213 return MP_NO_ACTION;
11215 else if (element == EL_EXIT_OPEN ||
11216 element == EL_SP_EXIT_OPEN ||
11217 element == EL_SP_EXIT_OPENING)
11219 sound_action = ACTION_PASSING; /* player is passing exit */
11221 else if (element == EL_EMPTY)
11223 sound_action = ACTION_MOVING; /* nothing to walk on */
11226 /* play sound from background or player, whatever is available */
11227 if (element_info[sound_element].sound[sound_action] != SND_UNDEFINED)
11228 PlayLevelSoundElementAction(x, y, sound_element, sound_action);
11230 PlayLevelSoundElementAction(x, y, player->artwork_element, sound_action);
11232 else if (player_can_move &&
11233 IS_PASSABLE(element) && canPassField(x, y, move_direction))
11235 if (!ACCESS_FROM(element, opposite_direction))
11236 return MP_NO_ACTION; /* field not accessible from this direction */
11238 if (CAN_MOVE(element)) /* only fixed elements can be passed! */
11239 return MP_NO_ACTION;
11241 if (IS_EM_GATE(element))
11243 if (!player->key[EM_GATE_NR(element)])
11244 return MP_NO_ACTION;
11246 else if (IS_EM_GATE_GRAY(element))
11248 if (!player->key[EM_GATE_GRAY_NR(element)])
11249 return MP_NO_ACTION;
11251 else if (IS_EM_GATE_GRAY_ACTIVE(element))
11253 if (!player->key[EM_GATE_GRAY_ACTIVE_NR(element)])
11254 return MP_NO_ACTION;
11256 else if (IS_EMC_GATE(element))
11258 if (!player->key[EMC_GATE_NR(element)])
11259 return MP_NO_ACTION;
11261 else if (IS_EMC_GATE_GRAY(element))
11263 if (!player->key[EMC_GATE_GRAY_NR(element)])
11264 return MP_NO_ACTION;
11266 else if (IS_EMC_GATE_GRAY_ACTIVE(element))
11268 if (!player->key[EMC_GATE_GRAY_ACTIVE_NR(element)])
11269 return MP_NO_ACTION;
11271 else if (IS_SP_PORT(element))
11273 if (element == EL_SP_GRAVITY_PORT_LEFT ||
11274 element == EL_SP_GRAVITY_PORT_RIGHT ||
11275 element == EL_SP_GRAVITY_PORT_UP ||
11276 element == EL_SP_GRAVITY_PORT_DOWN)
11277 #if USE_PLAYER_GRAVITY
11278 player->gravity = !player->gravity;
11280 game.gravity = !game.gravity;
11282 else if (element == EL_SP_GRAVITY_ON_PORT_LEFT ||
11283 element == EL_SP_GRAVITY_ON_PORT_RIGHT ||
11284 element == EL_SP_GRAVITY_ON_PORT_UP ||
11285 element == EL_SP_GRAVITY_ON_PORT_DOWN)
11286 #if USE_PLAYER_GRAVITY
11287 player->gravity = TRUE;
11289 game.gravity = TRUE;
11291 else if (element == EL_SP_GRAVITY_OFF_PORT_LEFT ||
11292 element == EL_SP_GRAVITY_OFF_PORT_RIGHT ||
11293 element == EL_SP_GRAVITY_OFF_PORT_UP ||
11294 element == EL_SP_GRAVITY_OFF_PORT_DOWN)
11295 #if USE_PLAYER_GRAVITY
11296 player->gravity = FALSE;
11298 game.gravity = FALSE;
11302 /* automatically move to the next field with double speed */
11303 player->programmed_action = move_direction;
11305 if (player->move_delay_reset_counter == 0)
11307 player->move_delay_reset_counter = 2; /* two double speed steps */
11309 DOUBLE_PLAYER_SPEED(player);
11312 PlayLevelSoundAction(x, y, ACTION_PASSING);
11314 else if (player_can_move_or_snap && IS_DIGGABLE(element))
11318 if (mode != DF_SNAP)
11320 GfxElement[x][y] = GFX_ELEMENT(element);
11321 player->is_digging = TRUE;
11324 PlayLevelSoundElementAction(x, y, element, ACTION_DIGGING);
11326 CheckTriggeredElementChangeByPlayer(x, y, element, CE_PLAYER_DIGS_X,
11327 player->index_bit, dig_side);
11329 if (mode == DF_SNAP)
11331 #if USE_NEW_SNAP_DELAY
11332 if (level.block_snap_field)
11333 setFieldForSnapping(x, y, element, move_direction);
11335 TestIfElementTouchesCustomElement(x, y); /* for empty space */
11337 TestIfElementTouchesCustomElement(x, y); /* for empty space */
11340 CheckTriggeredElementChangeByPlayer(x, y, element, CE_PLAYER_SNAPS_X,
11341 player->index_bit, dig_side);
11344 else if (player_can_move_or_snap && IS_COLLECTIBLE(element))
11348 if (is_player && mode != DF_SNAP)
11350 GfxElement[x][y] = element;
11351 player->is_collecting = TRUE;
11354 if (element == EL_SPEED_PILL)
11356 player->move_delay_value = MOVE_DELAY_HIGH_SPEED;
11358 else if (element == EL_EXTRA_TIME && level.time > 0)
11360 TimeLeft += level.extra_time;
11361 DrawGameValue_Time(TimeLeft);
11363 else if (element == EL_SHIELD_NORMAL || element == EL_SHIELD_DEADLY)
11365 player->shield_normal_time_left += level.shield_normal_time;
11366 if (element == EL_SHIELD_DEADLY)
11367 player->shield_deadly_time_left += level.shield_deadly_time;
11369 else if (element == EL_DYNAMITE ||
11370 element == EL_EM_DYNAMITE ||
11371 element == EL_SP_DISK_RED)
11373 if (player->inventory_size < MAX_INVENTORY_SIZE)
11374 player->inventory_element[player->inventory_size++] = element;
11376 DrawGameDoorValues();
11378 else if (element == EL_DYNABOMB_INCREASE_NUMBER)
11380 player->dynabomb_count++;
11381 player->dynabombs_left++;
11383 else if (element == EL_DYNABOMB_INCREASE_SIZE)
11385 player->dynabomb_size++;
11387 else if (element == EL_DYNABOMB_INCREASE_POWER)
11389 player->dynabomb_xl = TRUE;
11391 else if (IS_KEY(element))
11393 player->key[KEY_NR(element)] = TRUE;
11395 DrawGameDoorValues();
11397 else if (IS_ENVELOPE(element))
11399 player->show_envelope = element;
11401 else if (element == EL_EMC_LENSES)
11403 game.lenses_time_left = level.lenses_time * FRAMES_PER_SECOND;
11405 RedrawAllInvisibleElementsForLenses();
11407 else if (element == EL_EMC_MAGNIFIER)
11409 game.magnify_time_left = level.magnify_time * FRAMES_PER_SECOND;
11411 RedrawAllInvisibleElementsForMagnifier();
11413 else if (IS_DROPPABLE(element) ||
11414 IS_THROWABLE(element)) /* can be collected and dropped */
11418 if (collect_count == 0)
11419 player->inventory_infinite_element = element;
11421 for (i = 0; i < collect_count; i++)
11422 if (player->inventory_size < MAX_INVENTORY_SIZE)
11423 player->inventory_element[player->inventory_size++] = element;
11425 DrawGameDoorValues();
11427 else if (collect_count > 0)
11429 local_player->gems_still_needed -= collect_count;
11430 if (local_player->gems_still_needed < 0)
11431 local_player->gems_still_needed = 0;
11433 DrawGameValue_Emeralds(local_player->gems_still_needed);
11436 RaiseScoreElement(element);
11437 PlayLevelSoundElementAction(x, y, element, ACTION_COLLECTING);
11440 CheckTriggeredElementChangeByPlayer(x, y, element, CE_PLAYER_COLLECTS_X,
11441 player->index_bit, dig_side);
11443 if (mode == DF_SNAP)
11445 #if USE_NEW_SNAP_DELAY
11446 if (level.block_snap_field)
11447 setFieldForSnapping(x, y, element, move_direction);
11449 TestIfElementTouchesCustomElement(x, y); /* for empty space */
11451 TestIfElementTouchesCustomElement(x, y); /* for empty space */
11454 CheckTriggeredElementChangeByPlayer(x, y, element, CE_PLAYER_SNAPS_X,
11455 player->index_bit, dig_side);
11458 else if (player_can_move_or_snap && IS_PUSHABLE(element))
11460 if (mode == DF_SNAP && element != EL_BD_ROCK)
11461 return MP_NO_ACTION;
11463 if (CAN_FALL(element) && dy)
11464 return MP_NO_ACTION;
11466 if (CAN_FALL(element) && IN_LEV_FIELD(x, y + 1) && IS_FREE(x, y + 1) &&
11467 !(element == EL_SPRING && level.use_spring_bug))
11468 return MP_NO_ACTION;
11470 if (CAN_MOVE(element) && GET_MAX_MOVE_DELAY(element) == 0 &&
11471 ((move_direction & MV_VERTICAL &&
11472 ((element_info[element].move_pattern & MV_LEFT &&
11473 IN_LEV_FIELD(x - 1, y) && IS_FREE(x - 1, y)) ||
11474 (element_info[element].move_pattern & MV_RIGHT &&
11475 IN_LEV_FIELD(x + 1, y) && IS_FREE(x + 1, y)))) ||
11476 (move_direction & MV_HORIZONTAL &&
11477 ((element_info[element].move_pattern & MV_UP &&
11478 IN_LEV_FIELD(x, y - 1) && IS_FREE(x, y - 1)) ||
11479 (element_info[element].move_pattern & MV_DOWN &&
11480 IN_LEV_FIELD(x, y + 1) && IS_FREE(x, y + 1))))))
11481 return MP_NO_ACTION;
11483 /* do not push elements already moving away faster than player */
11484 if (CAN_MOVE(element) && MovDir[x][y] == move_direction &&
11485 ABS(getElementMoveStepsize(x, y)) > MOVE_STEPSIZE_NORMAL)
11486 return MP_NO_ACTION;
11488 if (game.engine_version >= VERSION_IDENT(3,1,0,0))
11490 if (player->push_delay_value == -1 || !player_was_pushing)
11491 player->push_delay_value = GET_NEW_PUSH_DELAY(element);
11493 else if (game.engine_version >= VERSION_IDENT(3,0,7,1))
11495 if (player->push_delay_value == -1)
11496 player->push_delay_value = GET_NEW_PUSH_DELAY(element);
11498 else if (game.engine_version >= VERSION_IDENT(2,2,0,7))
11500 if (!player->is_pushing)
11501 player->push_delay_value = GET_NEW_PUSH_DELAY(element);
11504 player->is_pushing = TRUE;
11505 player->is_active = TRUE;
11507 if (!(IN_LEV_FIELD(nextx, nexty) &&
11508 (IS_FREE(nextx, nexty) ||
11509 (Feld[nextx][nexty] == EL_SOKOBAN_FIELD_EMPTY &&
11510 IS_SB_ELEMENT(element)))))
11511 return MP_NO_ACTION;
11513 if (!checkDiagonalPushing(player, x, y, real_dx, real_dy))
11514 return MP_NO_ACTION;
11516 if (player->push_delay == -1) /* new pushing; restart delay */
11517 player->push_delay = 0;
11519 if (player->push_delay < player->push_delay_value &&
11520 !(tape.playing && tape.file_version < FILE_VERSION_2_0) &&
11521 element != EL_SPRING && element != EL_BALLOON)
11523 /* make sure that there is no move delay before next try to push */
11524 if (game.engine_version >= VERSION_IDENT(3,0,7,1))
11525 player->move_delay = 0;
11527 return MP_NO_ACTION;
11530 if (IS_SB_ELEMENT(element))
11532 if (element == EL_SOKOBAN_FIELD_FULL)
11534 Back[x][y] = EL_SOKOBAN_FIELD_EMPTY;
11535 local_player->sokobanfields_still_needed++;
11538 if (Feld[nextx][nexty] == EL_SOKOBAN_FIELD_EMPTY)
11540 Back[nextx][nexty] = EL_SOKOBAN_FIELD_EMPTY;
11541 local_player->sokobanfields_still_needed--;
11544 Feld[x][y] = EL_SOKOBAN_OBJECT;
11546 if (Back[x][y] == Back[nextx][nexty])
11547 PlayLevelSoundAction(x, y, ACTION_PUSHING);
11548 else if (Back[x][y] != 0)
11549 PlayLevelSoundElementAction(x, y, EL_SOKOBAN_FIELD_FULL,
11552 PlayLevelSoundElementAction(nextx, nexty, EL_SOKOBAN_FIELD_EMPTY,
11555 if (local_player->sokobanfields_still_needed == 0 &&
11556 game.emulation == EMU_SOKOBAN)
11558 PlayerWins(player);
11560 PlayLevelSound(x, y, SND_GAME_SOKOBAN_SOLVING);
11564 PlayLevelSoundElementAction(x, y, element, ACTION_PUSHING);
11566 InitMovingField(x, y, move_direction);
11567 GfxAction[x][y] = ACTION_PUSHING;
11569 if (mode == DF_SNAP)
11570 ContinueMoving(x, y);
11572 MovPos[x][y] = (dx != 0 ? dx : dy);
11574 Pushed[x][y] = TRUE;
11575 Pushed[nextx][nexty] = TRUE;
11577 if (game.engine_version < VERSION_IDENT(2,2,0,7))
11578 player->push_delay_value = GET_NEW_PUSH_DELAY(element);
11580 player->push_delay_value = -1; /* get new value later */
11582 /* check for element change _after_ element has been pushed */
11583 if (game.use_change_when_pushing_bug)
11585 CheckElementChangeByPlayer(x, y, element, CE_PUSHED_BY_PLAYER,
11586 player->index_bit, dig_side);
11587 CheckTriggeredElementChangeByPlayer(x, y, element, CE_PLAYER_PUSHES_X,
11588 player->index_bit, dig_side);
11591 else if (IS_SWITCHABLE(element))
11593 if (PLAYER_SWITCHING(player, x, y))
11595 CheckTriggeredElementChangeByPlayer(x, y, element, CE_PLAYER_PRESSES_X,
11596 player->index_bit, dig_side);
11601 player->is_switching = TRUE;
11602 player->switch_x = x;
11603 player->switch_y = y;
11605 PlayLevelSoundElementAction(x, y, element, ACTION_ACTIVATING);
11607 if (element == EL_ROBOT_WHEEL)
11609 Feld[x][y] = EL_ROBOT_WHEEL_ACTIVE;
11613 DrawLevelField(x, y);
11615 else if (element == EL_SP_TERMINAL)
11619 SCAN_PLAYFIELD(xx, yy)
11621 if (Feld[xx][yy] == EL_SP_DISK_YELLOW)
11623 else if (Feld[xx][yy] == EL_SP_TERMINAL)
11624 Feld[xx][yy] = EL_SP_TERMINAL_ACTIVE;
11627 else if (IS_BELT_SWITCH(element))
11629 ToggleBeltSwitch(x, y);
11631 else if (element == EL_SWITCHGATE_SWITCH_UP ||
11632 element == EL_SWITCHGATE_SWITCH_DOWN)
11634 ToggleSwitchgateSwitch(x, y);
11636 else if (element == EL_LIGHT_SWITCH ||
11637 element == EL_LIGHT_SWITCH_ACTIVE)
11639 ToggleLightSwitch(x, y);
11641 else if (element == EL_TIMEGATE_SWITCH)
11643 ActivateTimegateSwitch(x, y);
11645 else if (element == EL_BALLOON_SWITCH_LEFT ||
11646 element == EL_BALLOON_SWITCH_RIGHT ||
11647 element == EL_BALLOON_SWITCH_UP ||
11648 element == EL_BALLOON_SWITCH_DOWN ||
11649 element == EL_BALLOON_SWITCH_NONE ||
11650 element == EL_BALLOON_SWITCH_ANY)
11652 game.wind_direction = (element == EL_BALLOON_SWITCH_LEFT ? MV_LEFT :
11653 element == EL_BALLOON_SWITCH_RIGHT ? MV_RIGHT :
11654 element == EL_BALLOON_SWITCH_UP ? MV_UP :
11655 element == EL_BALLOON_SWITCH_DOWN ? MV_DOWN :
11656 element == EL_BALLOON_SWITCH_NONE ? MV_NONE :
11659 else if (element == EL_LAMP)
11661 Feld[x][y] = EL_LAMP_ACTIVE;
11662 local_player->lights_still_needed--;
11664 ResetGfxAnimation(x, y);
11665 DrawLevelField(x, y);
11667 else if (element == EL_TIME_ORB_FULL)
11669 Feld[x][y] = EL_TIME_ORB_EMPTY;
11671 if (level.time > 0 || level.use_time_orb_bug)
11673 TimeLeft += level.time_orb_time;
11674 DrawGameValue_Time(TimeLeft);
11677 ResetGfxAnimation(x, y);
11678 DrawLevelField(x, y);
11680 else if (element == EL_EMC_MAGIC_BALL_SWITCH ||
11681 element == EL_EMC_MAGIC_BALL_SWITCH_ACTIVE)
11685 game.ball_state = !game.ball_state;
11687 SCAN_PLAYFIELD(xx, yy)
11689 int e = Feld[xx][yy];
11691 if (game.ball_state)
11693 if (e == EL_EMC_MAGIC_BALL)
11694 CreateField(xx, yy, EL_EMC_MAGIC_BALL_ACTIVE);
11695 else if (e == EL_EMC_MAGIC_BALL_SWITCH)
11696 CreateField(xx, yy, EL_EMC_MAGIC_BALL_SWITCH_ACTIVE);
11700 if (e == EL_EMC_MAGIC_BALL_ACTIVE)
11701 CreateField(xx, yy, EL_EMC_MAGIC_BALL);
11702 else if (e == EL_EMC_MAGIC_BALL_SWITCH_ACTIVE)
11703 CreateField(xx, yy, EL_EMC_MAGIC_BALL_SWITCH);
11708 CheckTriggeredElementChangeByPlayer(x, y, element, CE_SWITCH_OF_X,
11709 player->index_bit, dig_side);
11711 CheckTriggeredElementChangeByPlayer(x, y, element, CE_PLAYER_SWITCHES_X,
11712 player->index_bit, dig_side);
11714 CheckTriggeredElementChangeByPlayer(x, y, element, CE_PLAYER_PRESSES_X,
11715 player->index_bit, dig_side);
11721 if (!PLAYER_SWITCHING(player, x, y))
11723 player->is_switching = TRUE;
11724 player->switch_x = x;
11725 player->switch_y = y;
11727 CheckElementChangeByPlayer(x, y, element, CE_SWITCHED,
11728 player->index_bit, dig_side);
11729 CheckTriggeredElementChangeByPlayer(x, y, element, CE_SWITCH_OF_X,
11730 player->index_bit, dig_side);
11732 CheckElementChangeByPlayer(x, y, element, CE_SWITCHED_BY_PLAYER,
11733 player->index_bit, dig_side);
11734 CheckTriggeredElementChangeByPlayer(x, y, element, CE_PLAYER_SWITCHES_X,
11735 player->index_bit, dig_side);
11738 CheckElementChangeByPlayer(x, y, element, CE_PRESSED_BY_PLAYER,
11739 player->index_bit, dig_side);
11740 CheckTriggeredElementChangeByPlayer(x, y, element, CE_PLAYER_PRESSES_X,
11741 player->index_bit, dig_side);
11743 return MP_NO_ACTION;
11746 player->push_delay = -1;
11748 if (is_player) /* function can also be called by EL_PENGUIN */
11750 if (Feld[x][y] != element) /* really digged/collected something */
11752 player->is_collecting = !player->is_digging;
11753 player->is_active = TRUE;
11760 boolean SnapField(struct PlayerInfo *player, int dx, int dy)
11762 int jx = player->jx, jy = player->jy;
11763 int x = jx + dx, y = jy + dy;
11764 int snap_direction = (dx == -1 ? MV_LEFT :
11765 dx == +1 ? MV_RIGHT :
11767 dy == +1 ? MV_DOWN : MV_NONE);
11768 boolean can_continue_snapping = (level.continuous_snapping &&
11769 WasJustFalling[x][y] < CHECK_DELAY_FALLING);
11771 if (player->MovPos != 0 && game.engine_version >= VERSION_IDENT(2,2,0,0))
11774 if (!player->active || !IN_LEV_FIELD(x, y))
11782 if (player->MovPos == 0)
11783 player->is_pushing = FALSE;
11785 player->is_snapping = FALSE;
11787 if (player->MovPos == 0)
11789 player->is_moving = FALSE;
11790 player->is_digging = FALSE;
11791 player->is_collecting = FALSE;
11797 #if USE_NEW_CONTINUOUS_SNAPPING
11798 /* prevent snapping with already pressed snap key when not allowed */
11799 if (player->is_snapping && !can_continue_snapping)
11802 if (player->is_snapping)
11806 player->MovDir = snap_direction;
11808 if (player->MovPos == 0)
11810 player->is_moving = FALSE;
11811 player->is_digging = FALSE;
11812 player->is_collecting = FALSE;
11815 player->is_dropping = FALSE;
11816 player->is_dropping_pressed = FALSE;
11817 player->drop_pressed_delay = 0;
11819 if (DigField(player, jx, jy, x, y, 0, 0, DF_SNAP) == MP_NO_ACTION)
11822 player->is_snapping = TRUE;
11823 player->is_active = TRUE;
11825 if (player->MovPos == 0)
11827 player->is_moving = FALSE;
11828 player->is_digging = FALSE;
11829 player->is_collecting = FALSE;
11832 if (player->MovPos != 0) /* prevent graphic bugs in versions < 2.2.0 */
11833 DrawLevelField(player->last_jx, player->last_jy);
11835 DrawLevelField(x, y);
11840 boolean DropElement(struct PlayerInfo *player)
11842 int old_element, new_element;
11843 int dropx = player->jx, dropy = player->jy;
11844 int drop_direction = player->MovDir;
11845 int drop_side = drop_direction;
11846 int drop_element = (player->inventory_size > 0 ?
11847 player->inventory_element[player->inventory_size - 1] :
11848 player->inventory_infinite_element != EL_UNDEFINED ?
11849 player->inventory_infinite_element :
11850 player->dynabombs_left > 0 ?
11851 EL_DYNABOMB_PLAYER_1_ACTIVE + player->index_nr :
11854 player->is_dropping_pressed = TRUE;
11856 /* do not drop an element on top of another element; when holding drop key
11857 pressed without moving, dropped element must move away before the next
11858 element can be dropped (this is especially important if the next element
11859 is dynamite, which can be placed on background for historical reasons) */
11860 if (PLAYER_DROPPING(player, dropx, dropy) && Feld[dropx][dropy] != EL_EMPTY)
11863 if (IS_THROWABLE(drop_element))
11865 dropx += GET_DX_FROM_DIR(drop_direction);
11866 dropy += GET_DY_FROM_DIR(drop_direction);
11868 if (!IN_LEV_FIELD(dropx, dropy))
11872 old_element = Feld[dropx][dropy]; /* old element at dropping position */
11873 new_element = drop_element; /* default: no change when dropping */
11875 /* check if player is active, not moving and ready to drop */
11876 if (!player->active || player->MovPos || player->drop_delay > 0)
11879 /* check if player has anything that can be dropped */
11880 if (new_element == EL_UNDEFINED)
11883 /* check if drop key was pressed long enough for EM style dynamite */
11884 if (new_element == EL_EM_DYNAMITE && player->drop_pressed_delay < 40)
11887 /* check if anything can be dropped at the current position */
11888 if (IS_ACTIVE_BOMB(old_element) || old_element == EL_EXPLOSION)
11891 /* collected custom elements can only be dropped on empty fields */
11892 if (IS_CUSTOM_ELEMENT(new_element) && old_element != EL_EMPTY)
11895 if (old_element != EL_EMPTY)
11896 Back[dropx][dropy] = old_element; /* store old element on this field */
11898 ResetGfxAnimation(dropx, dropy);
11899 ResetRandomAnimationValue(dropx, dropy);
11901 if (player->inventory_size > 0 ||
11902 player->inventory_infinite_element != EL_UNDEFINED)
11904 if (player->inventory_size > 0)
11906 player->inventory_size--;
11908 DrawGameDoorValues();
11910 if (new_element == EL_DYNAMITE)
11911 new_element = EL_DYNAMITE_ACTIVE;
11912 else if (new_element == EL_EM_DYNAMITE)
11913 new_element = EL_EM_DYNAMITE_ACTIVE;
11914 else if (new_element == EL_SP_DISK_RED)
11915 new_element = EL_SP_DISK_RED_ACTIVE;
11918 Feld[dropx][dropy] = new_element;
11920 if (IN_SCR_FIELD(SCREENX(dropx), SCREENY(dropy)))
11921 DrawGraphicThruMask(SCREENX(dropx), SCREENY(dropy),
11922 el2img(Feld[dropx][dropy]), 0);
11924 PlayLevelSoundAction(dropx, dropy, ACTION_DROPPING);
11926 /* needed if previous element just changed to "empty" in the last frame */
11927 ChangeCount[dropx][dropy] = 0; /* allow at least one more change */
11929 CheckElementChangeByPlayer(dropx, dropy, new_element, CE_DROPPED_BY_PLAYER,
11930 player->index_bit, drop_side);
11931 CheckTriggeredElementChangeByPlayer(dropx, dropy, new_element,
11933 player->index_bit, drop_side);
11935 TestIfElementTouchesCustomElement(dropx, dropy);
11937 else /* player is dropping a dyna bomb */
11939 player->dynabombs_left--;
11941 Feld[dropx][dropy] = new_element;
11943 if (IN_SCR_FIELD(SCREENX(dropx), SCREENY(dropy)))
11944 DrawGraphicThruMask(SCREENX(dropx), SCREENY(dropy),
11945 el2img(Feld[dropx][dropy]), 0);
11947 PlayLevelSoundAction(dropx, dropy, ACTION_DROPPING);
11950 if (Feld[dropx][dropy] == new_element) /* uninitialized unless CE change */
11951 InitField_WithBug1(dropx, dropy, FALSE);
11953 new_element = Feld[dropx][dropy]; /* element might have changed */
11955 if (IS_CUSTOM_ELEMENT(new_element) && CAN_MOVE(new_element) &&
11956 element_info[new_element].move_pattern == MV_WHEN_DROPPED)
11958 int move_direction, nextx, nexty;
11960 if (element_info[new_element].move_direction_initial == MV_START_AUTOMATIC)
11961 MovDir[dropx][dropy] = drop_direction;
11963 move_direction = MovDir[dropx][dropy];
11964 nextx = dropx + GET_DX_FROM_DIR(move_direction);
11965 nexty = dropy + GET_DY_FROM_DIR(move_direction);
11967 ChangeCount[dropx][dropy] = 0; /* allow at least one more change */
11968 CheckCollision[dropx][dropy] = CHECK_DELAY_COLLISION;
11971 player->drop_delay = GET_NEW_DROP_DELAY(drop_element);
11972 player->is_dropping = TRUE;
11974 player->drop_pressed_delay = 0;
11975 player->is_dropping_pressed = FALSE;
11977 player->drop_x = dropx;
11978 player->drop_y = dropy;
11983 /* ------------------------------------------------------------------------- */
11984 /* game sound playing functions */
11985 /* ------------------------------------------------------------------------- */
11987 static int *loop_sound_frame = NULL;
11988 static int *loop_sound_volume = NULL;
11990 void InitPlayLevelSound()
11992 int num_sounds = getSoundListSize();
11994 checked_free(loop_sound_frame);
11995 checked_free(loop_sound_volume);
11997 loop_sound_frame = checked_calloc(num_sounds * sizeof(int));
11998 loop_sound_volume = checked_calloc(num_sounds * sizeof(int));
12001 static void PlayLevelSound(int x, int y, int nr)
12003 int sx = SCREENX(x), sy = SCREENY(y);
12004 int volume, stereo_position;
12005 int max_distance = 8;
12006 int type = (IS_LOOP_SOUND(nr) ? SND_CTRL_PLAY_LOOP : SND_CTRL_PLAY_SOUND);
12008 if ((!setup.sound_simple && !IS_LOOP_SOUND(nr)) ||
12009 (!setup.sound_loops && IS_LOOP_SOUND(nr)))
12012 if (!IN_LEV_FIELD(x, y) ||
12013 sx < -max_distance || sx >= SCR_FIELDX + max_distance ||
12014 sy < -max_distance || sy >= SCR_FIELDY + max_distance)
12017 volume = SOUND_MAX_VOLUME;
12019 if (!IN_SCR_FIELD(sx, sy))
12021 int dx = ABS(sx - SCR_FIELDX / 2) - SCR_FIELDX / 2;
12022 int dy = ABS(sy - SCR_FIELDY / 2) - SCR_FIELDY / 2;
12024 volume -= volume * (dx > dy ? dx : dy) / max_distance;
12027 stereo_position = (SOUND_MAX_LEFT +
12028 (sx + max_distance) * SOUND_MAX_LEFT2RIGHT /
12029 (SCR_FIELDX + 2 * max_distance));
12031 if (IS_LOOP_SOUND(nr))
12033 /* This assures that quieter loop sounds do not overwrite louder ones,
12034 while restarting sound volume comparison with each new game frame. */
12036 if (loop_sound_volume[nr] > volume && loop_sound_frame[nr] == FrameCounter)
12039 loop_sound_volume[nr] = volume;
12040 loop_sound_frame[nr] = FrameCounter;
12043 PlaySoundExt(nr, volume, stereo_position, type);
12046 static void PlayLevelSoundNearest(int x, int y, int sound_action)
12048 PlayLevelSound(x < LEVELX(BX1) ? LEVELX(BX1) :
12049 x > LEVELX(BX2) ? LEVELX(BX2) : x,
12050 y < LEVELY(BY1) ? LEVELY(BY1) :
12051 y > LEVELY(BY2) ? LEVELY(BY2) : y,
12055 static void PlayLevelSoundAction(int x, int y, int action)
12057 PlayLevelSoundElementAction(x, y, Feld[x][y], action);
12060 static void PlayLevelSoundElementAction(int x, int y, int element, int action)
12062 int sound_effect = element_info[SND_ELEMENT(element)].sound[action];
12064 if (sound_effect != SND_UNDEFINED)
12065 PlayLevelSound(x, y, sound_effect);
12068 static void PlayLevelSoundElementActionIfLoop(int x, int y, int element,
12071 int sound_effect = element_info[SND_ELEMENT(element)].sound[action];
12073 if (sound_effect != SND_UNDEFINED && IS_LOOP_SOUND(sound_effect))
12074 PlayLevelSound(x, y, sound_effect);
12077 static void PlayLevelSoundActionIfLoop(int x, int y, int action)
12079 int sound_effect = element_info[SND_ELEMENT(Feld[x][y])].sound[action];
12081 if (sound_effect != SND_UNDEFINED && IS_LOOP_SOUND(sound_effect))
12082 PlayLevelSound(x, y, sound_effect);
12085 static void StopLevelSoundActionIfLoop(int x, int y, int action)
12087 int sound_effect = element_info[SND_ELEMENT(Feld[x][y])].sound[action];
12089 if (sound_effect != SND_UNDEFINED && IS_LOOP_SOUND(sound_effect))
12090 StopSound(sound_effect);
12093 static void PlayLevelMusic()
12095 if (levelset.music[level_nr] != MUS_UNDEFINED)
12096 PlayMusic(levelset.music[level_nr]); /* from config file */
12098 PlayMusic(MAP_NOCONF_MUSIC(level_nr)); /* from music dir */
12101 void PlayLevelSound_EM(int xx, int yy, int element_em, int sample)
12103 int element = (element_em > -1 ? map_element_EM_to_RND(element_em) : 0);
12104 int offset = (BorderElement == EL_STEELWALL ? 1 : 0);
12105 int x = xx - 1 - offset;
12106 int y = yy - 1 - offset;
12111 PlayLevelSoundElementAction(x, y, element, ACTION_WALKING);
12115 PlayLevelSoundElementAction(x, y, element, ACTION_PUSHING);
12119 PlayLevelSoundElementAction(x, y, element, ACTION_IMPACT);
12123 PlayLevelSoundElementAction(x, y, element, ACTION_IMPACT);
12127 PlayLevelSoundElementAction(x, y, element, ACTION_BREAKING);
12131 PlayLevelSoundElementAction(x, y, element, ACTION_MOVING);
12135 PlayLevelSoundElementAction(x, y, element, ACTION_MOVING);
12138 case SAMPLE_android_clone:
12139 PlayLevelSoundElementAction(x, y, element, ACTION_DROPPING);
12142 case SAMPLE_android_move:
12143 PlayLevelSoundElementAction(x, y, element, ACTION_MOVING);
12146 case SAMPLE_spring:
12147 PlayLevelSoundElementAction(x, y, element, ACTION_IMPACT);
12151 PlayLevelSoundElementAction(x, y, element, ACTION_EATING);
12155 PlayLevelSoundElementAction(x, y, element, ACTION_WAITING);
12158 case SAMPLE_eater_eat:
12159 PlayLevelSoundElementAction(x, y, element, ACTION_DIGGING);
12163 PlayLevelSoundElementAction(x, y, element, ACTION_MOVING);
12166 case SAMPLE_collect:
12167 PlayLevelSoundElementAction(x, y, element, ACTION_COLLECTING);
12170 case SAMPLE_diamond:
12171 PlayLevelSoundElementAction(x, y, element, ACTION_IMPACT);
12174 case SAMPLE_squash:
12175 /* !!! CHECK THIS !!! */
12177 PlayLevelSoundElementAction(x, y, element, ACTION_BREAKING);
12179 PlayLevelSoundElementAction(x, y, element, ACTION_SMASHED_BY_ROCK);
12183 case SAMPLE_wonderfall:
12184 PlayLevelSoundElementAction(x, y, element, ACTION_FILLING);
12188 PlayLevelSoundElementAction(x, y, element, ACTION_IMPACT);
12192 PlayLevelSoundElementAction(x, y, element, ACTION_PUSHING);
12196 PlayLevelSoundElementAction(x, y, element, ACTION_DIGGING);
12200 PlayLevelSoundElementAction(x, y, element, ACTION_SPLASHING);
12204 PlayLevelSoundElementAction(x, y, element, ACTION_DROPPING);
12208 PlayLevelSoundElementAction(x, y, element, ACTION_GROWING);
12211 case SAMPLE_wonder:
12212 PlayLevelSoundElementAction(x, y, element, ACTION_ACTIVE);
12216 PlayLevelSoundElementAction(x, y, element, ACTION_PASSING);
12219 case SAMPLE_exit_open:
12220 PlayLevelSoundElementAction(x, y, element, ACTION_OPENING);
12223 case SAMPLE_exit_leave:
12224 PlayLevelSoundElementAction(x, y, element, ACTION_PASSING);
12227 case SAMPLE_dynamite:
12228 PlayLevelSoundElementAction(x, y, element, ACTION_DROPPING);
12232 PlayLevelSoundElementAction(x, y, element, ACTION_ACTIVE);
12236 PlayLevelSoundElementAction(x, y, element, ACTION_ACTIVATING);
12240 PlayLevelSoundElementAction(x, y, element, ACTION_ACTIVE);
12244 PlayLevelSoundElementAction(x, y, element, ACTION_EXPLODING);
12248 PlayLevelSoundElementAction(x, y, element, ACTION_DYING);
12252 PlaySound(SND_GAME_RUNNING_OUT_OF_TIME);
12256 PlayLevelSoundElementAction(x, y, element, ACTION_DEFAULT);
12262 void ChangeTime(int value)
12264 int *time = (level.time == 0 ? &TimePlayed : &TimeLeft);
12268 /* EMC game engine uses value from time counter of RND game engine */
12269 level.native_em_level->lev->time = *time;
12271 DrawGameValue_Time(*time);
12274 void RaiseScore(int value)
12276 /* EMC game engine and RND game engine have separate score counters */
12277 int *score = (level.game_engine_type == GAME_ENGINE_TYPE_EM ?
12278 &level.native_em_level->lev->score : &local_player->score);
12282 DrawGameValue_Score(*score);
12286 void RaiseScore(int value)
12288 local_player->score += value;
12290 DrawGameValue_Score(local_player->score);
12293 void RaiseScoreElement(int element)
12298 case EL_BD_DIAMOND:
12299 case EL_EMERALD_YELLOW:
12300 case EL_EMERALD_RED:
12301 case EL_EMERALD_PURPLE:
12302 case EL_SP_INFOTRON:
12303 RaiseScore(level.score[SC_EMERALD]);
12306 RaiseScore(level.score[SC_DIAMOND]);
12309 RaiseScore(level.score[SC_CRYSTAL]);
12312 RaiseScore(level.score[SC_PEARL]);
12315 case EL_BD_BUTTERFLY:
12316 case EL_SP_ELECTRON:
12317 RaiseScore(level.score[SC_BUG]);
12320 case EL_BD_FIREFLY:
12321 case EL_SP_SNIKSNAK:
12322 RaiseScore(level.score[SC_SPACESHIP]);
12325 case EL_DARK_YAMYAM:
12326 RaiseScore(level.score[SC_YAMYAM]);
12329 RaiseScore(level.score[SC_ROBOT]);
12332 RaiseScore(level.score[SC_PACMAN]);
12335 RaiseScore(level.score[SC_NUT]);
12338 case EL_EM_DYNAMITE:
12339 case EL_SP_DISK_RED:
12340 case EL_DYNABOMB_INCREASE_NUMBER:
12341 case EL_DYNABOMB_INCREASE_SIZE:
12342 case EL_DYNABOMB_INCREASE_POWER:
12343 RaiseScore(level.score[SC_DYNAMITE]);
12345 case EL_SHIELD_NORMAL:
12346 case EL_SHIELD_DEADLY:
12347 RaiseScore(level.score[SC_SHIELD]);
12349 case EL_EXTRA_TIME:
12350 RaiseScore(level.extra_time_score);
12364 RaiseScore(level.score[SC_KEY]);
12367 RaiseScore(element_info[element].collect_score);
12372 void RequestQuitGame(boolean ask_if_really_quit)
12374 if (AllPlayersGone ||
12375 !ask_if_really_quit ||
12376 level_editor_test_game ||
12377 Request("Do you really want to quit the game ?",
12378 REQ_ASK | REQ_STAY_CLOSED))
12380 #if defined(NETWORK_AVALIABLE)
12381 if (options.network)
12382 SendToServer_StopPlaying(NETWORK_STOP_BY_PLAYER);
12386 if (!ask_if_really_quit || level_editor_test_game)
12388 game_status = GAME_MODE_MAIN;
12394 FadeOut(REDRAW_FIELD);
12396 game_status = GAME_MODE_MAIN;
12398 DrawAndFadeInMainMenu(REDRAW_FIELD);
12404 if (tape.playing && tape.deactivate_display)
12405 TapeDeactivateDisplayOff(TRUE);
12407 OpenDoor(DOOR_OPEN_1 | DOOR_COPY_BACK);
12409 if (tape.playing && tape.deactivate_display)
12410 TapeDeactivateDisplayOn();
12415 /* ---------- new game button stuff ---------------------------------------- */
12417 /* graphic position values for game buttons */
12418 #define GAME_BUTTON_XSIZE 30
12419 #define GAME_BUTTON_YSIZE 30
12420 #define GAME_BUTTON_XPOS 5
12421 #define GAME_BUTTON_YPOS 215
12422 #define SOUND_BUTTON_XPOS 5
12423 #define SOUND_BUTTON_YPOS (GAME_BUTTON_YPOS + GAME_BUTTON_YSIZE)
12425 #define GAME_BUTTON_STOP_XPOS (GAME_BUTTON_XPOS + 0 * GAME_BUTTON_XSIZE)
12426 #define GAME_BUTTON_PAUSE_XPOS (GAME_BUTTON_XPOS + 1 * GAME_BUTTON_XSIZE)
12427 #define GAME_BUTTON_PLAY_XPOS (GAME_BUTTON_XPOS + 2 * GAME_BUTTON_XSIZE)
12428 #define SOUND_BUTTON_MUSIC_XPOS (SOUND_BUTTON_XPOS + 0 * GAME_BUTTON_XSIZE)
12429 #define SOUND_BUTTON_LOOPS_XPOS (SOUND_BUTTON_XPOS + 1 * GAME_BUTTON_XSIZE)
12430 #define SOUND_BUTTON_SIMPLE_XPOS (SOUND_BUTTON_XPOS + 2 * GAME_BUTTON_XSIZE)
12437 } gamebutton_info[NUM_GAME_BUTTONS] =
12440 GAME_BUTTON_STOP_XPOS, GAME_BUTTON_YPOS,
12445 GAME_BUTTON_PAUSE_XPOS, GAME_BUTTON_YPOS,
12446 GAME_CTRL_ID_PAUSE,
12450 GAME_BUTTON_PLAY_XPOS, GAME_BUTTON_YPOS,
12455 SOUND_BUTTON_MUSIC_XPOS, SOUND_BUTTON_YPOS,
12456 SOUND_CTRL_ID_MUSIC,
12457 "background music on/off"
12460 SOUND_BUTTON_LOOPS_XPOS, SOUND_BUTTON_YPOS,
12461 SOUND_CTRL_ID_LOOPS,
12462 "sound loops on/off"
12465 SOUND_BUTTON_SIMPLE_XPOS, SOUND_BUTTON_YPOS,
12466 SOUND_CTRL_ID_SIMPLE,
12467 "normal sounds on/off"
12471 void CreateGameButtons()
12475 for (i = 0; i < NUM_GAME_BUTTONS; i++)
12477 Bitmap *gd_bitmap = graphic_info[IMG_GLOBAL_DOOR].bitmap;
12478 struct GadgetInfo *gi;
12481 unsigned long event_mask;
12482 int gd_xoffset, gd_yoffset;
12483 int gd_x1, gd_x2, gd_y1, gd_y2;
12486 gd_xoffset = gamebutton_info[i].x;
12487 gd_yoffset = gamebutton_info[i].y;
12488 gd_x1 = DOOR_GFX_PAGEX4 + gd_xoffset;
12489 gd_x2 = DOOR_GFX_PAGEX3 + gd_xoffset;
12491 if (id == GAME_CTRL_ID_STOP ||
12492 id == GAME_CTRL_ID_PAUSE ||
12493 id == GAME_CTRL_ID_PLAY)
12495 button_type = GD_TYPE_NORMAL_BUTTON;
12497 event_mask = GD_EVENT_RELEASED;
12498 gd_y1 = DOOR_GFX_PAGEY1 + gd_yoffset - GAME_BUTTON_YSIZE;
12499 gd_y2 = DOOR_GFX_PAGEY1 + gd_yoffset - GAME_BUTTON_YSIZE;
12503 button_type = GD_TYPE_CHECK_BUTTON;
12505 ((id == SOUND_CTRL_ID_MUSIC && setup.sound_music) ||
12506 (id == SOUND_CTRL_ID_LOOPS && setup.sound_loops) ||
12507 (id == SOUND_CTRL_ID_SIMPLE && setup.sound_simple) ? TRUE : FALSE);
12508 event_mask = GD_EVENT_PRESSED;
12509 gd_y1 = DOOR_GFX_PAGEY1 + gd_yoffset;
12510 gd_y2 = DOOR_GFX_PAGEY1 + gd_yoffset - GAME_BUTTON_YSIZE;
12513 gi = CreateGadget(GDI_CUSTOM_ID, id,
12514 GDI_INFO_TEXT, gamebutton_info[i].infotext,
12515 GDI_X, DX + gd_xoffset,
12516 GDI_Y, DY + gd_yoffset,
12517 GDI_WIDTH, GAME_BUTTON_XSIZE,
12518 GDI_HEIGHT, GAME_BUTTON_YSIZE,
12519 GDI_TYPE, button_type,
12520 GDI_STATE, GD_BUTTON_UNPRESSED,
12521 GDI_CHECKED, checked,
12522 GDI_DESIGN_UNPRESSED, gd_bitmap, gd_x1, gd_y1,
12523 GDI_DESIGN_PRESSED, gd_bitmap, gd_x2, gd_y1,
12524 GDI_ALT_DESIGN_UNPRESSED, gd_bitmap, gd_x1, gd_y2,
12525 GDI_ALT_DESIGN_PRESSED, gd_bitmap, gd_x2, gd_y2,
12526 GDI_EVENT_MASK, event_mask,
12527 GDI_CALLBACK_ACTION, HandleGameButtons,
12531 Error(ERR_EXIT, "cannot create gadget");
12533 game_gadget[id] = gi;
12537 void FreeGameButtons()
12541 for (i = 0; i < NUM_GAME_BUTTONS; i++)
12542 FreeGadget(game_gadget[i]);
12545 static void MapGameButtons()
12549 for (i = 0; i < NUM_GAME_BUTTONS; i++)
12550 MapGadget(game_gadget[i]);
12553 void UnmapGameButtons()
12557 for (i = 0; i < NUM_GAME_BUTTONS; i++)
12558 UnmapGadget(game_gadget[i]);
12561 static void HandleGameButtons(struct GadgetInfo *gi)
12563 int id = gi->custom_id;
12565 if (game_status != GAME_MODE_PLAYING)
12570 case GAME_CTRL_ID_STOP:
12574 RequestQuitGame(TRUE);
12577 case GAME_CTRL_ID_PAUSE:
12578 if (options.network)
12580 #if defined(NETWORK_AVALIABLE)
12582 SendToServer_ContinuePlaying();
12584 SendToServer_PausePlaying();
12588 TapeTogglePause(TAPE_TOGGLE_MANUAL);
12591 case GAME_CTRL_ID_PLAY:
12594 #if defined(NETWORK_AVALIABLE)
12595 if (options.network)
12596 SendToServer_ContinuePlaying();
12600 tape.pausing = FALSE;
12601 DrawVideoDisplay(VIDEO_STATE_PAUSE_OFF, 0);
12606 case SOUND_CTRL_ID_MUSIC:
12607 if (setup.sound_music)
12609 setup.sound_music = FALSE;
12612 else if (audio.music_available)
12614 setup.sound = setup.sound_music = TRUE;
12616 SetAudioMode(setup.sound);
12622 case SOUND_CTRL_ID_LOOPS:
12623 if (setup.sound_loops)
12624 setup.sound_loops = FALSE;
12625 else if (audio.loops_available)
12627 setup.sound = setup.sound_loops = TRUE;
12628 SetAudioMode(setup.sound);
12632 case SOUND_CTRL_ID_SIMPLE:
12633 if (setup.sound_simple)
12634 setup.sound_simple = FALSE;
12635 else if (audio.sound_available)
12637 setup.sound = setup.sound_simple = TRUE;
12638 SetAudioMode(setup.sound);