1 /***********************************************************
2 * Rocks'n'Diamonds -- McDuffin Strikes Back! *
3 *----------------------------------------------------------*
4 * (c) 1995-2002 Artsoft Entertainment *
6 * Detmolder Strasse 189 *
9 * e-mail: info@artsoft.org *
10 *----------------------------------------------------------*
12 ***********************************************************/
14 #include "libgame/libgame.h"
24 /* EXPERIMENTAL STUFF */
25 #define USE_NEW_AMOEBA_CODE FALSE
27 /* EXPERIMENTAL STUFF */
28 #define USE_NEW_STUFF ( 1)
30 #define USE_NEW_SP_SLIPPERY (USE_NEW_STUFF * 1)
31 #define USE_NEW_CUSTOM_VALUE (USE_NEW_STUFF * 1)
32 #define USE_NEW_PLAYER_ANIM (USE_NEW_STUFF * 1)
33 #define USE_NEW_ALL_SLIPPERY (USE_NEW_STUFF * 1)
34 #define USE_NEW_PLAYER_SPEED (USE_NEW_STUFF * 1)
35 #define USE_NEW_DELAYED_ACTION (USE_NEW_STUFF * 1)
36 #define USE_NEW_SNAP_DELAY (USE_NEW_STUFF * 1)
37 #define USE_ONLY_ONE_CHANGE_PER_FRAME (USE_NEW_STUFF * 1)
38 #define USE_ONE_MORE_CHANGE_PER_FRAME (USE_NEW_STUFF * 1)
39 #define USE_FIXED_DONT_RUN_INTO (USE_NEW_STUFF * 1)
40 #define USE_NEW_SPRING_BUMPER (USE_NEW_STUFF * 1)
41 #define USE_STOP_CHANGED_ELEMENTS (USE_NEW_STUFF * 1)
42 #define USE_ELEMENT_TOUCHING_BUGFIX (USE_NEW_STUFF * 1)
44 #define USE_QUICKSAND_IMPACT_BUGFIX (USE_NEW_STUFF * 0)
51 /* for MovePlayer() */
52 #define MP_NO_ACTION 0
55 #define MP_DONT_RUN_INTO (MP_MOVING | MP_ACTION)
57 /* for ScrollPlayer() */
59 #define SCROLL_GO_ON 1
61 /* for Bang()/Explode() */
62 #define EX_PHASE_START 0
63 #define EX_TYPE_NONE 0
64 #define EX_TYPE_NORMAL (1 << 0)
65 #define EX_TYPE_CENTER (1 << 1)
66 #define EX_TYPE_BORDER (1 << 2)
67 #define EX_TYPE_CROSS (1 << 3)
68 #define EX_TYPE_DYNA (1 << 4)
69 #define EX_TYPE_SINGLE_TILE (EX_TYPE_CENTER | EX_TYPE_BORDER)
71 /* special positions in the game control window (relative to control window) */
74 #define XX_EMERALDS 29
75 #define YY_EMERALDS 54
76 #define XX_DYNAMITE 29
77 #define YY_DYNAMITE 89
86 /* special positions in the game control window (relative to main window) */
87 #define DX_LEVEL (DX + XX_LEVEL)
88 #define DY_LEVEL (DY + YY_LEVEL)
89 #define DX_EMERALDS (DX + XX_EMERALDS)
90 #define DY_EMERALDS (DY + YY_EMERALDS)
91 #define DX_DYNAMITE (DX + XX_DYNAMITE)
92 #define DY_DYNAMITE (DY + YY_DYNAMITE)
93 #define DX_KEYS (DX + XX_KEYS)
94 #define DY_KEYS (DY + YY_KEYS)
95 #define DX_SCORE (DX + XX_SCORE)
96 #define DY_SCORE (DY + YY_SCORE)
97 #define DX_TIME1 (DX + XX_TIME1)
98 #define DX_TIME2 (DX + XX_TIME2)
99 #define DY_TIME (DY + YY_TIME)
101 /* values for initial player move delay (initial delay counter value) */
102 #define INITIAL_MOVE_DELAY_OFF -1
103 #define INITIAL_MOVE_DELAY_ON 0
105 /* values for player movement speed (which is in fact a delay value) */
106 #define MOVE_DELAY_MIN_SPEED 32
107 #define MOVE_DELAY_NORMAL_SPEED 8
108 #define MOVE_DELAY_HIGH_SPEED 4
109 #define MOVE_DELAY_MAX_SPEED 1
112 #define DOUBLE_MOVE_DELAY(x) (x = (x <= MOVE_DELAY_HIGH_SPEED ? x * 2 : x))
113 #define HALVE_MOVE_DELAY(x) (x = (x >= MOVE_DELAY_HIGH_SPEED ? x / 2 : x))
115 #define DOUBLE_MOVE_DELAY(x) (x = (x < MOVE_DELAY_MIN_SPEED ? x * 2 : x))
116 #define HALVE_MOVE_DELAY(x) (x = (x > MOVE_DELAY_MAX_SPEED ? x / 2 : x))
118 #define DOUBLE_PLAYER_SPEED(p) (HALVE_MOVE_DELAY((p)->move_delay_value))
119 #define HALVE_PLAYER_SPEED(p) (DOUBLE_MOVE_DELAY((p)->move_delay_value))
121 /* values for other actions */
122 #define MOVE_STEPSIZE_NORMAL (TILEX / MOVE_DELAY_NORMAL_SPEED)
123 #define MOVE_STEPSIZE_MIN (1)
124 #define MOVE_STEPSIZE_MAX (TILEX)
126 #define GET_DX_FROM_DIR(d) ((d) == MV_LEFT ? -1 : (d) == MV_RIGHT ? 1 : 0)
127 #define GET_DY_FROM_DIR(d) ((d) == MV_UP ? -1 : (d) == MV_DOWN ? 1 : 0)
129 #define INIT_GFX_RANDOM() (SimpleRND(1000000))
131 #define GET_NEW_PUSH_DELAY(e) ( (element_info[e].push_delay_fixed) + \
132 RND(element_info[e].push_delay_random))
133 #define GET_NEW_DROP_DELAY(e) ( (element_info[e].drop_delay_fixed) + \
134 RND(element_info[e].drop_delay_random))
135 #define GET_NEW_MOVE_DELAY(e) ( (element_info[e].move_delay_fixed) + \
136 RND(element_info[e].move_delay_random))
137 #define GET_MAX_MOVE_DELAY(e) ( (element_info[e].move_delay_fixed) + \
138 (element_info[e].move_delay_random))
139 #define GET_NEW_CUSTOM_VALUE(e) ( (element_info[e].ce_value_fixed_initial) +\
140 RND(element_info[e].ce_value_random_initial))
141 #define GET_CHANGE_DELAY(c) ( ((c)->delay_fixed * (c)->delay_frames) + \
142 RND((c)->delay_random * (c)->delay_frames))
143 #define GET_CE_DELAY_VALUE(c) ( ((c)->delay_fixed) + \
144 RND((c)->delay_random))
147 #define GET_VALID_RUNTIME_ELEMENT(e) \
148 ((e) >= NUM_RUNTIME_ELEMENTS ? EL_UNKNOWN : (e))
150 #define GET_VALID_FILE_ELEMENT(e) \
151 ((e) >= NUM_FILE_ELEMENTS ? EL_UNKNOWN : (e))
154 #define GET_TARGET_ELEMENT(e, ch) \
155 ((e) == EL_TRIGGER_PLAYER ? (ch)->actual_trigger_player : \
156 (e) == EL_TRIGGER_ELEMENT ? (ch)->actual_trigger_element : \
157 (e) == EL_TRIGGER_CE_VALUE ? (ch)->actual_trigger_ce_value : (e))
159 #define CAN_GROW_INTO(e) \
160 ((e) == EL_SAND || (IS_DIGGABLE(e) && level.grow_into_diggable))
162 #define ELEMENT_CAN_ENTER_FIELD_BASE_X(x, y, condition) \
163 (IN_LEV_FIELD(x, y) && (IS_FREE(x, y) || \
166 #define ELEMENT_CAN_ENTER_FIELD_BASE_2(e, x, y, condition) \
167 (IN_LEV_FIELD(x, y) && (IS_FREE(x, y) || \
168 (CAN_MOVE_INTO_ACID(e) && \
169 Feld[x][y] == EL_ACID) || \
172 #define ELEMENT_CAN_ENTER_FIELD_BASE_3(e, x, y, condition) \
173 (IN_LEV_FIELD(x, y) && (IS_FREE_OR_PLAYER(x, y) || \
174 (CAN_MOVE_INTO_ACID(e) && \
175 Feld[x][y] == EL_ACID) || \
178 #define ELEMENT_CAN_ENTER_FIELD_BASE_4(e, x, y, condition) \
179 (IN_LEV_FIELD(x, y) && (IS_FREE(x, y) || \
181 (CAN_MOVE_INTO_ACID(e) && \
182 Feld[x][y] == EL_ACID) || \
183 (DONT_COLLIDE_WITH(e) && \
185 !PLAYER_ENEMY_PROTECTED(x, y))))
187 #define ELEMENT_CAN_ENTER_FIELD(e, x, y) \
188 ELEMENT_CAN_ENTER_FIELD_BASE_4(e, x, y, 0)
190 #define SATELLITE_CAN_ENTER_FIELD(x, y) \
191 ELEMENT_CAN_ENTER_FIELD_BASE_2(EL_SATELLITE, x, y, 0)
193 #define ANDROID_CAN_ENTER_FIELD(e, x, y) \
194 ELEMENT_CAN_ENTER_FIELD_BASE_2(e, x, y, Feld[x][y] == EL_EMC_PLANT)
196 #define ANDROID_CAN_CLONE_FIELD(x, y) \
197 (IN_LEV_FIELD(x, y) && (CAN_BE_CLONED_BY_ANDROID(Feld[x][y]) || \
198 CAN_BE_CLONED_BY_ANDROID(EL_TRIGGER_ELEMENT)))
200 #define ENEMY_CAN_ENTER_FIELD(e, x, y) \
201 ELEMENT_CAN_ENTER_FIELD_BASE_2(e, x, y, 0)
203 #define YAMYAM_CAN_ENTER_FIELD(e, x, y) \
204 ELEMENT_CAN_ENTER_FIELD_BASE_3(e, x, y, Feld[x][y] == EL_DIAMOND)
206 #define DARK_YAMYAM_CAN_ENTER_FIELD(e, x, y) \
207 ELEMENT_CAN_ENTER_FIELD_BASE_3(e, x,y, IS_FOOD_DARK_YAMYAM(Feld[x][y]))
209 #define PACMAN_CAN_ENTER_FIELD(e, x, y) \
210 ELEMENT_CAN_ENTER_FIELD_BASE_3(e, x, y, IS_AMOEBOID(Feld[x][y]))
212 #define PIG_CAN_ENTER_FIELD(e, x, y) \
213 ELEMENT_CAN_ENTER_FIELD_BASE_2(e, x, y, IS_FOOD_PIG(Feld[x][y]))
215 #define PENGUIN_CAN_ENTER_FIELD(e, x, y) \
216 ELEMENT_CAN_ENTER_FIELD_BASE_2(e, x, y, (Feld[x][y] == EL_EXIT_OPEN ||\
217 IS_FOOD_PENGUIN(Feld[x][y])))
218 #define DRAGON_CAN_ENTER_FIELD(e, x, y) \
219 ELEMENT_CAN_ENTER_FIELD_BASE_2(e, x, y, 0)
221 #define MOLE_CAN_ENTER_FIELD(e, x, y, condition) \
222 ELEMENT_CAN_ENTER_FIELD_BASE_2(e, x, y, (condition))
224 #define SPRING_CAN_ENTER_FIELD(e, x, y) \
225 ELEMENT_CAN_ENTER_FIELD_BASE_2(e, x, y, 0)
227 #define SPRING_CAN_BUMP_FROM_FIELD(x, y) \
228 (IN_LEV_FIELD(x, y) && (Feld[x][y] == EL_EMC_SPRING_BUMPER || \
229 Feld[x][y] == EL_EMC_SPRING_BUMPER_ACTIVE))
232 #define GROUP_NR(e) ((e) - EL_GROUP_START)
233 #define IS_IN_GROUP(e, nr) (element_info[e].in_group[nr] == TRUE)
234 #define IS_IN_GROUP_EL(e, ge) (IS_IN_GROUP(e, (ge) - EL_GROUP_START))
236 #define IS_EQUAL_OR_IN_GROUP(e, ge) \
237 (IS_GROUP_ELEMENT(ge) ? IS_IN_GROUP(e, GROUP_NR(ge)) : (e) == (ge))
240 #define MOVE_ENTER_EL(e) (element_info[e].move_enter_element)
242 #define CE_ENTER_FIELD_COND(e, x, y) \
243 (!IS_PLAYER(x, y) && \
244 IS_EQUAL_OR_IN_GROUP(Feld[x][y], MOVE_ENTER_EL(e)))
246 #define CUSTOM_ELEMENT_CAN_ENTER_FIELD(e, x, y) \
247 ELEMENT_CAN_ENTER_FIELD_BASE_4(e, x, y, CE_ENTER_FIELD_COND(e, x, y))
249 #define IN_LEV_FIELD_AND_IS_FREE(x, y) (IN_LEV_FIELD(x, y) && IS_FREE(x, y))
250 #define IN_LEV_FIELD_AND_NOT_FREE(x, y) (IN_LEV_FIELD(x, y) && !IS_FREE(x, y))
252 #define ACCESS_FROM(e, d) (element_info[e].access_direction &(d))
253 #define IS_WALKABLE_FROM(e, d) (IS_WALKABLE(e) && ACCESS_FROM(e, d))
254 #define IS_PASSABLE_FROM(e, d) (IS_PASSABLE(e) && ACCESS_FROM(e, d))
255 #define IS_ACCESSIBLE_FROM(e, d) (IS_ACCESSIBLE(e) && ACCESS_FROM(e, d))
257 /* game button identifiers */
258 #define GAME_CTRL_ID_STOP 0
259 #define GAME_CTRL_ID_PAUSE 1
260 #define GAME_CTRL_ID_PLAY 2
261 #define SOUND_CTRL_ID_MUSIC 3
262 #define SOUND_CTRL_ID_LOOPS 4
263 #define SOUND_CTRL_ID_SIMPLE 5
265 #define NUM_GAME_BUTTONS 6
268 /* forward declaration for internal use */
270 static void CreateField(int, int, int);
272 static void SetPlayerWaiting(struct PlayerInfo *, boolean);
273 static void AdvanceFrameAndPlayerCounters(int);
275 static boolean MovePlayerOneStep(struct PlayerInfo *, int, int, int, int);
276 static boolean MovePlayer(struct PlayerInfo *, int, int);
277 static void ScrollPlayer(struct PlayerInfo *, int);
278 static void ScrollScreen(struct PlayerInfo *, int);
280 int DigField(struct PlayerInfo *, int, int, int, int, int, int, int);
282 static void InitBeltMovement(void);
283 static void CloseAllOpenTimegates(void);
284 static void CheckGravityMovement(struct PlayerInfo *);
285 static void CheckGravityMovementWhenNotMoving(struct PlayerInfo *);
286 static void KillPlayerUnlessEnemyProtected(int, int);
287 static void KillPlayerUnlessExplosionProtected(int, int);
289 static void TestIfPlayerTouchesCustomElement(int, int);
290 static void TestIfElementTouchesCustomElement(int, int);
291 static void TestIfElementHitsCustomElement(int, int, int);
293 static void TestIfElementSmashesCustomElement(int, int, int);
296 static void HandleElementChange(int, int, int);
297 static void ExecuteCustomElementAction(int, int, int, int);
298 static boolean ChangeElement(int, int, int, int);
300 static boolean CheckTriggeredElementChangeExt(int, int, int, int, int,int,int);
301 #define CheckTriggeredElementChange(x, y, e, ev) \
302 CheckTriggeredElementChangeExt(x,y,e,ev, CH_PLAYER_ANY,CH_SIDE_ANY, -1)
303 #define CheckTriggeredElementChangeByPlayer(x, y, e, ev, p, s) \
304 CheckTriggeredElementChangeExt(x, y, e, ev, p, s, -1)
305 #define CheckTriggeredElementChangeBySide(x, y, e, ev, s) \
306 CheckTriggeredElementChangeExt(x, y, e, ev, CH_PLAYER_ANY, s, -1)
307 #define CheckTriggeredElementChangeByPage(x, y, e, ev, p) \
308 CheckTriggeredElementChangeExt(x,y,e,ev, CH_PLAYER_ANY, CH_SIDE_ANY, p)
310 static boolean CheckElementChangeExt(int, int, int, int, int, int, int);
311 #define CheckElementChange(x, y, e, te, ev) \
312 CheckElementChangeExt(x, y, e, te, ev, CH_PLAYER_ANY, CH_SIDE_ANY)
313 #define CheckElementChangeByPlayer(x, y, e, ev, p, s) \
314 CheckElementChangeExt(x, y, e, EL_EMPTY, ev, p, s)
315 #define CheckElementChangeBySide(x, y, e, te, ev, s) \
316 CheckElementChangeExt(x, y, e, te, ev, CH_PLAYER_ANY, s)
318 static void PlayLevelSound(int, int, int);
319 static void PlayLevelSoundNearest(int, int, int);
320 static void PlayLevelSoundAction(int, int, int);
321 static void PlayLevelSoundElementAction(int, int, int, int);
322 static void PlayLevelSoundElementActionIfLoop(int, int, int, int);
323 static void PlayLevelSoundActionIfLoop(int, int, int);
324 static void StopLevelSoundActionIfLoop(int, int, int);
325 static void PlayLevelMusic();
327 static void MapGameButtons();
328 static void HandleGameButtons(struct GadgetInfo *);
330 static struct GadgetInfo *game_gadget[NUM_GAME_BUTTONS];
333 /* ------------------------------------------------------------------------- */
334 /* definition of elements that automatically change to other elements after */
335 /* a specified time, eventually calling a function when changing */
336 /* ------------------------------------------------------------------------- */
338 /* forward declaration for changer functions */
339 static void InitBuggyBase(int, int);
340 static void WarnBuggyBase(int, int);
342 static void InitTrap(int, int);
343 static void ActivateTrap(int, int);
344 static void ChangeActiveTrap(int, int);
346 static void InitRobotWheel(int, int);
347 static void RunRobotWheel(int, int);
348 static void StopRobotWheel(int, int);
350 static void InitTimegateWheel(int, int);
351 static void RunTimegateWheel(int, int);
353 static void InitMagicBallDelay(int, int);
354 static void ActivateMagicBall(int, int);
356 static void InitDiagonalMovingElement(int, int);
358 struct ChangingElementInfo
363 void (*pre_change_function)(int x, int y);
364 void (*change_function)(int x, int y);
365 void (*post_change_function)(int x, int y);
368 static struct ChangingElementInfo change_delay_list[] =
419 EL_SWITCHGATE_OPENING,
427 EL_SWITCHGATE_CLOSING,
428 EL_SWITCHGATE_CLOSED,
460 EL_ACID_SPLASH_RIGHT,
469 EL_SP_BUGGY_BASE_ACTIVATING,
476 EL_SP_BUGGY_BASE_ACTIVATING,
477 EL_SP_BUGGY_BASE_ACTIVE,
484 EL_SP_BUGGY_BASE_ACTIVE,
508 EL_ROBOT_WHEEL_ACTIVE,
516 EL_TIMEGATE_SWITCH_ACTIVE,
524 EL_EMC_MAGIC_BALL_ACTIVE,
525 EL_EMC_MAGIC_BALL_ACTIVE,
532 EL_EMC_SPRING_BUMPER_ACTIVE,
533 EL_EMC_SPRING_BUMPER,
540 EL_DIAGONAL_SHRINKING,
553 InitDiagonalMovingElement
569 int push_delay_fixed, push_delay_random;
574 { EL_BALLOON, 0, 0 },
576 { EL_SOKOBAN_OBJECT, 2, 0 },
577 { EL_SOKOBAN_FIELD_FULL, 2, 0 },
578 { EL_SATELLITE, 2, 0 },
579 { EL_SP_DISK_YELLOW, 2, 0 },
581 { EL_UNDEFINED, 0, 0 },
589 move_stepsize_list[] =
591 { EL_AMOEBA_DROP, 2 },
592 { EL_AMOEBA_DROPPING, 2 },
593 { EL_QUICKSAND_FILLING, 1 },
594 { EL_QUICKSAND_EMPTYING, 1 },
595 { EL_MAGIC_WALL_FILLING, 2 },
596 { EL_BD_MAGIC_WALL_FILLING, 2 },
597 { EL_MAGIC_WALL_EMPTYING, 2 },
598 { EL_BD_MAGIC_WALL_EMPTYING, 2 },
608 collect_count_list[] =
611 { EL_BD_DIAMOND, 1 },
612 { EL_EMERALD_YELLOW, 1 },
613 { EL_EMERALD_RED, 1 },
614 { EL_EMERALD_PURPLE, 1 },
616 { EL_SP_INFOTRON, 1 },
628 access_direction_list[] =
630 { EL_TUBE_ANY, MV_LEFT | MV_RIGHT | MV_UP | MV_DOWN },
631 { EL_TUBE_VERTICAL, MV_UP | MV_DOWN },
632 { EL_TUBE_HORIZONTAL, MV_LEFT | MV_RIGHT },
633 { EL_TUBE_VERTICAL_LEFT, MV_LEFT | MV_UP | MV_DOWN },
634 { EL_TUBE_VERTICAL_RIGHT, MV_RIGHT | MV_UP | MV_DOWN },
635 { EL_TUBE_HORIZONTAL_UP, MV_LEFT | MV_RIGHT | MV_UP },
636 { EL_TUBE_HORIZONTAL_DOWN, MV_LEFT | MV_RIGHT | MV_DOWN },
637 { EL_TUBE_LEFT_UP, MV_LEFT | MV_UP },
638 { EL_TUBE_LEFT_DOWN, MV_LEFT | MV_DOWN },
639 { EL_TUBE_RIGHT_UP, MV_RIGHT | MV_UP },
640 { EL_TUBE_RIGHT_DOWN, MV_RIGHT | MV_DOWN },
642 { EL_SP_PORT_LEFT, MV_RIGHT },
643 { EL_SP_PORT_RIGHT, MV_LEFT },
644 { EL_SP_PORT_UP, MV_DOWN },
645 { EL_SP_PORT_DOWN, MV_UP },
646 { EL_SP_PORT_HORIZONTAL, MV_LEFT | MV_RIGHT },
647 { EL_SP_PORT_VERTICAL, MV_UP | MV_DOWN },
648 { EL_SP_PORT_ANY, MV_LEFT | MV_RIGHT | MV_UP | MV_DOWN },
649 { EL_SP_GRAVITY_PORT_LEFT, MV_RIGHT },
650 { EL_SP_GRAVITY_PORT_RIGHT, MV_LEFT },
651 { EL_SP_GRAVITY_PORT_UP, MV_DOWN },
652 { EL_SP_GRAVITY_PORT_DOWN, MV_UP },
653 { EL_SP_GRAVITY_ON_PORT_LEFT, MV_RIGHT },
654 { EL_SP_GRAVITY_ON_PORT_RIGHT, MV_LEFT },
655 { EL_SP_GRAVITY_ON_PORT_UP, MV_DOWN },
656 { EL_SP_GRAVITY_ON_PORT_DOWN, MV_UP },
657 { EL_SP_GRAVITY_OFF_PORT_LEFT, MV_RIGHT },
658 { EL_SP_GRAVITY_OFF_PORT_RIGHT, MV_LEFT },
659 { EL_SP_GRAVITY_OFF_PORT_UP, MV_DOWN },
660 { EL_SP_GRAVITY_OFF_PORT_DOWN, MV_UP },
662 { EL_UNDEFINED, MV_NONE }
665 static boolean trigger_events[MAX_NUM_ELEMENTS][NUM_CHANGE_EVENTS];
667 #define IS_AUTO_CHANGING(e) (element_info[e].has_change_event[CE_DELAY])
668 #define IS_JUST_CHANGING(x, y) (ChangeDelay[x][y] != 0)
669 #define IS_CHANGING(x, y) (IS_AUTO_CHANGING(Feld[x][y]) || \
670 IS_JUST_CHANGING(x, y))
672 #define CE_PAGE(e, ce) (element_info[e].event_page[ce])
674 /* static variables for playfield scan mode (scanning forward or backward) */
675 static int playfield_scan_start_x = 0;
676 static int playfield_scan_start_y = 0;
677 static int playfield_scan_delta_x = 1;
678 static int playfield_scan_delta_y = 1;
680 #define SCAN_PLAYFIELD(x, y) for ((y) = playfield_scan_start_y; \
681 (y) >= 0 && (y) <= lev_fieldy - 1; \
682 (y) += playfield_scan_delta_y) \
683 for ((x) = playfield_scan_start_x; \
684 (x) >= 0 && (x) <= lev_fieldx - 1; \
685 (x) += playfield_scan_delta_x) \
687 static void InitPlayfieldScanModeVars()
689 if (game.use_reverse_scan_direction)
691 playfield_scan_start_x = lev_fieldx - 1;
692 playfield_scan_start_y = lev_fieldy - 1;
694 playfield_scan_delta_x = -1;
695 playfield_scan_delta_y = -1;
699 playfield_scan_start_x = 0;
700 playfield_scan_start_y = 0;
702 playfield_scan_delta_x = 1;
703 playfield_scan_delta_y = 1;
707 static void InitPlayfieldScanMode(int mode)
709 game.use_reverse_scan_direction =
710 (mode == CA_ARG_SCAN_MODE_REVERSE ? TRUE : FALSE);
712 InitPlayfieldScanModeVars();
715 static int get_move_delay_from_stepsize(int move_stepsize)
718 MIN(MAX(MOVE_STEPSIZE_MIN, move_stepsize), MOVE_STEPSIZE_MAX);
720 /* make sure that stepsize value is always a power of 2 */
721 move_stepsize = (1 << log_2(move_stepsize));
723 return TILEX / move_stepsize;
726 static void SetPlayerMoveSpeed(struct PlayerInfo *player, int move_stepsize,
729 int move_delay = get_move_delay_from_stepsize(move_stepsize);
730 boolean cannot_move = (move_stepsize == STEPSIZE_NOT_MOVING ? TRUE : FALSE);
732 /* do no immediately change move delay -- the player might just be moving */
733 player->move_delay_value_next = move_delay;
735 /* information if player can move must be set separately */
736 player->cannot_move = cannot_move;
740 player->move_delay = game.initial_move_delay;
741 player->move_delay_value = game.initial_move_delay_value;
743 player->move_delay_value_next = -1;
745 player->move_delay_reset_counter = 0;
749 void GetPlayerConfig()
751 if (!audio.sound_available)
752 setup.sound_simple = FALSE;
754 if (!audio.loops_available)
755 setup.sound_loops = FALSE;
757 if (!audio.music_available)
758 setup.sound_music = FALSE;
760 if (!video.fullscreen_available)
761 setup.fullscreen = FALSE;
763 setup.sound = (setup.sound_simple || setup.sound_loops || setup.sound_music);
765 SetAudioMode(setup.sound);
769 static int getBeltNrFromBeltElement(int element)
771 return (element < EL_CONVEYOR_BELT_2_LEFT ? 0 :
772 element < EL_CONVEYOR_BELT_3_LEFT ? 1 :
773 element < EL_CONVEYOR_BELT_4_LEFT ? 2 : 3);
776 static int getBeltNrFromBeltActiveElement(int element)
778 return (element < EL_CONVEYOR_BELT_2_LEFT_ACTIVE ? 0 :
779 element < EL_CONVEYOR_BELT_3_LEFT_ACTIVE ? 1 :
780 element < EL_CONVEYOR_BELT_4_LEFT_ACTIVE ? 2 : 3);
783 static int getBeltNrFromBeltSwitchElement(int element)
785 return (element < EL_CONVEYOR_BELT_2_SWITCH_LEFT ? 0 :
786 element < EL_CONVEYOR_BELT_3_SWITCH_LEFT ? 1 :
787 element < EL_CONVEYOR_BELT_4_SWITCH_LEFT ? 2 : 3);
790 static int getBeltDirNrFromBeltSwitchElement(int element)
792 static int belt_base_element[4] =
794 EL_CONVEYOR_BELT_1_SWITCH_LEFT,
795 EL_CONVEYOR_BELT_2_SWITCH_LEFT,
796 EL_CONVEYOR_BELT_3_SWITCH_LEFT,
797 EL_CONVEYOR_BELT_4_SWITCH_LEFT
800 int belt_nr = getBeltNrFromBeltSwitchElement(element);
801 int belt_dir_nr = element - belt_base_element[belt_nr];
803 return (belt_dir_nr % 3);
806 static int getBeltDirFromBeltSwitchElement(int element)
808 static int belt_move_dir[3] =
815 int belt_dir_nr = getBeltDirNrFromBeltSwitchElement(element);
817 return belt_move_dir[belt_dir_nr];
820 static void InitPlayerField(int x, int y, int element, boolean init_game)
822 if (element == EL_SP_MURPHY)
826 if (stored_player[0].present)
828 Feld[x][y] = EL_SP_MURPHY_CLONE;
834 stored_player[0].use_murphy = TRUE;
837 Feld[x][y] = EL_PLAYER_1;
843 struct PlayerInfo *player = &stored_player[Feld[x][y] - EL_PLAYER_1];
844 int jx = player->jx, jy = player->jy;
846 player->present = TRUE;
848 player->block_last_field = (element == EL_SP_MURPHY ?
849 level.sp_block_last_field :
850 level.block_last_field);
852 /* ---------- initialize player's last field block delay --------------- */
854 /* always start with reliable default value (no adjustment needed) */
855 player->block_delay_adjustment = 0;
857 /* special case 1: in Supaplex, Murphy blocks last field one more frame */
858 if (player->block_last_field && element == EL_SP_MURPHY)
859 player->block_delay_adjustment = 1;
861 /* special case 2: in game engines before 3.1.1, blocking was different */
862 if (game.use_block_last_field_bug)
863 player->block_delay_adjustment = (player->block_last_field ? -1 : 1);
865 if (!options.network || player->connected)
867 player->active = TRUE;
869 /* remove potentially duplicate players */
870 if (StorePlayer[jx][jy] == Feld[x][y])
871 StorePlayer[jx][jy] = 0;
873 StorePlayer[x][y] = Feld[x][y];
877 printf("Player %d activated.\n", player->element_nr);
878 printf("[Local player is %d and currently %s.]\n",
879 local_player->element_nr,
880 local_player->active ? "active" : "not active");
884 Feld[x][y] = EL_EMPTY;
886 player->jx = player->last_jx = x;
887 player->jy = player->last_jy = y;
891 static void InitField(int x, int y, boolean init_game)
893 int element = Feld[x][y];
902 InitPlayerField(x, y, element, init_game);
905 case EL_SOKOBAN_FIELD_PLAYER:
906 element = Feld[x][y] = EL_PLAYER_1;
907 InitField(x, y, init_game);
909 element = Feld[x][y] = EL_SOKOBAN_FIELD_EMPTY;
910 InitField(x, y, init_game);
913 case EL_SOKOBAN_FIELD_EMPTY:
914 local_player->sokobanfields_still_needed++;
918 if (x < lev_fieldx-1 && Feld[x+1][y] == EL_ACID)
919 Feld[x][y] = EL_ACID_POOL_TOPLEFT;
920 else if (x > 0 && Feld[x-1][y] == EL_ACID)
921 Feld[x][y] = EL_ACID_POOL_TOPRIGHT;
922 else if (y > 0 && Feld[x][y-1] == EL_ACID_POOL_TOPLEFT)
923 Feld[x][y] = EL_ACID_POOL_BOTTOMLEFT;
924 else if (y > 0 && Feld[x][y-1] == EL_ACID)
925 Feld[x][y] = EL_ACID_POOL_BOTTOM;
926 else if (y > 0 && Feld[x][y-1] == EL_ACID_POOL_TOPRIGHT)
927 Feld[x][y] = EL_ACID_POOL_BOTTOMRIGHT;
935 case EL_SPACESHIP_RIGHT:
936 case EL_SPACESHIP_UP:
937 case EL_SPACESHIP_LEFT:
938 case EL_SPACESHIP_DOWN:
940 case EL_BD_BUTTERFLY_RIGHT:
941 case EL_BD_BUTTERFLY_UP:
942 case EL_BD_BUTTERFLY_LEFT:
943 case EL_BD_BUTTERFLY_DOWN:
944 case EL_BD_BUTTERFLY:
945 case EL_BD_FIREFLY_RIGHT:
946 case EL_BD_FIREFLY_UP:
947 case EL_BD_FIREFLY_LEFT:
948 case EL_BD_FIREFLY_DOWN:
950 case EL_PACMAN_RIGHT:
974 if (y == lev_fieldy - 1)
976 Feld[x][y] = EL_AMOEBA_GROWING;
977 Store[x][y] = EL_AMOEBA_WET;
981 case EL_DYNAMITE_ACTIVE:
982 case EL_SP_DISK_RED_ACTIVE:
983 case EL_DYNABOMB_PLAYER_1_ACTIVE:
984 case EL_DYNABOMB_PLAYER_2_ACTIVE:
985 case EL_DYNABOMB_PLAYER_3_ACTIVE:
986 case EL_DYNABOMB_PLAYER_4_ACTIVE:
991 local_player->lights_still_needed++;
995 local_player->friends_still_needed++;
1000 GfxDir[x][y] = MovDir[x][y] = 1 << RND(4);
1003 case EL_CONVEYOR_BELT_1_SWITCH_LEFT:
1004 case EL_CONVEYOR_BELT_1_SWITCH_MIDDLE:
1005 case EL_CONVEYOR_BELT_1_SWITCH_RIGHT:
1006 case EL_CONVEYOR_BELT_2_SWITCH_LEFT:
1007 case EL_CONVEYOR_BELT_2_SWITCH_MIDDLE:
1008 case EL_CONVEYOR_BELT_2_SWITCH_RIGHT:
1009 case EL_CONVEYOR_BELT_3_SWITCH_LEFT:
1010 case EL_CONVEYOR_BELT_3_SWITCH_MIDDLE:
1011 case EL_CONVEYOR_BELT_3_SWITCH_RIGHT:
1012 case EL_CONVEYOR_BELT_4_SWITCH_LEFT:
1013 case EL_CONVEYOR_BELT_4_SWITCH_MIDDLE:
1014 case EL_CONVEYOR_BELT_4_SWITCH_RIGHT:
1017 int belt_nr = getBeltNrFromBeltSwitchElement(Feld[x][y]);
1018 int belt_dir = getBeltDirFromBeltSwitchElement(Feld[x][y]);
1019 int belt_dir_nr = getBeltDirNrFromBeltSwitchElement(Feld[x][y]);
1021 if (game.belt_dir_nr[belt_nr] == 3) /* initial value */
1023 game.belt_dir[belt_nr] = belt_dir;
1024 game.belt_dir_nr[belt_nr] = belt_dir_nr;
1026 else /* more than one switch -- set it like the first switch */
1028 Feld[x][y] = Feld[x][y] - belt_dir_nr + game.belt_dir_nr[belt_nr];
1033 case EL_SWITCHGATE_SWITCH_DOWN: /* always start with same switch pos */
1035 Feld[x][y] = EL_SWITCHGATE_SWITCH_UP;
1038 case EL_LIGHT_SWITCH_ACTIVE:
1040 game.light_time_left = level.time_light * FRAMES_PER_SECOND;
1043 case EL_EMC_MAGIC_BALL:
1044 if (game.ball_state)
1045 Feld[x][y] = EL_EMC_MAGIC_BALL_ACTIVE;
1048 case EL_EMC_MAGIC_BALL_SWITCH:
1049 if (game.ball_state)
1050 Feld[x][y] = EL_EMC_MAGIC_BALL_SWITCH_ACTIVE;
1055 if (IS_CUSTOM_ELEMENT(element))
1057 if (CAN_MOVE(element))
1060 #if USE_NEW_CUSTOM_VALUE
1061 if (!element_info[element].use_last_ce_value || init_game)
1062 CustomValue[x][y] = GET_NEW_CUSTOM_VALUE(Feld[x][y]);
1066 if (IS_CUSTOM_ELEMENT(element) && CAN_MOVE(element))
1069 else if (IS_GROUP_ELEMENT(element))
1071 struct ElementGroupInfo *group = element_info[element].group;
1072 int last_anim_random_frame = gfx.anim_random_frame;
1075 if (group->choice_mode == ANIM_RANDOM)
1076 gfx.anim_random_frame = RND(group->num_elements_resolved);
1078 element_pos = getAnimationFrame(group->num_elements_resolved, 1,
1079 group->choice_mode, 0,
1082 if (group->choice_mode == ANIM_RANDOM)
1083 gfx.anim_random_frame = last_anim_random_frame;
1085 group->choice_pos++;
1087 Feld[x][y] = group->element_resolved[element_pos];
1089 InitField(x, y, init_game);
1096 CheckTriggeredElementChange(x, y, element, CE_CREATION_OF_X);
1101 #if USE_NEW_CUSTOM_VALUE
1104 CustomValue[x][y] = GET_NEW_CUSTOM_VALUE(Feld[x][y]);
1106 CustomValue[x][y] = element_info[Feld[x][y]].custom_value_initial;
1114 static inline void InitField_WithBug1(int x, int y, boolean init_game)
1116 InitField(x, y, init_game);
1118 /* not needed to call InitMovDir() -- already done by InitField()! */
1119 if (game.engine_version < VERSION_IDENT(3,1,0,0) &&
1120 CAN_MOVE(Feld[x][y]))
1124 static inline void InitField_WithBug2(int x, int y, boolean init_game)
1126 int old_element = Feld[x][y];
1128 InitField(x, y, init_game);
1130 /* not needed to call InitMovDir() -- already done by InitField()! */
1131 if (game.engine_version < VERSION_IDENT(3,1,0,0) &&
1132 CAN_MOVE(old_element) &&
1133 (old_element < EL_MOLE_LEFT || old_element > EL_MOLE_DOWN))
1136 /* this case is in fact a combination of not less than three bugs:
1137 first, it calls InitMovDir() for elements that can move, although this is
1138 already done by InitField(); then, it checks the element that was at this
1139 field _before_ the call to InitField() (which can change it); lastly, it
1140 was not called for "mole with direction" elements, which were treated as
1141 "cannot move" due to (fixed) wrong element initialization in "src/init.c"
1145 inline void DrawGameValue_Emeralds(int value)
1147 DrawText(DX_EMERALDS, DY_EMERALDS, int2str(value, 3), FONT_TEXT_2);
1150 inline void DrawGameValue_Dynamite(int value)
1152 DrawText(DX_DYNAMITE, DY_DYNAMITE, int2str(value, 3), FONT_TEXT_2);
1155 inline void DrawGameValue_Keys(int key[MAX_NUM_KEYS])
1159 /* currently only 4 of 8 possible keys are displayed */
1160 for (i = 0; i < STD_NUM_KEYS; i++)
1163 DrawMiniGraphicExt(drawto, DX_KEYS + i * MINI_TILEX, DY_KEYS,
1164 el2edimg(EL_KEY_1 + i));
1166 BlitBitmap(graphic_info[IMG_GLOBAL_DOOR].bitmap, drawto,
1167 DOOR_GFX_PAGEX5 + XX_KEYS + i * MINI_TILEX, YY_KEYS,
1168 MINI_TILEX, MINI_TILEY, DX_KEYS + i * MINI_TILEX, DY_KEYS);
1172 inline void DrawGameValue_Score(int value)
1174 DrawText(DX_SCORE, DY_SCORE, int2str(value, 5), FONT_TEXT_2);
1177 inline void DrawGameValue_Time(int value)
1180 DrawText(DX_TIME1, DY_TIME, int2str(value, 3), FONT_TEXT_2);
1182 DrawText(DX_TIME2, DY_TIME, int2str(value, 4), FONT_LEVEL_NUMBER);
1185 inline void DrawGameValue_Level(int value)
1188 DrawText(DX_LEVEL, DY_LEVEL, int2str(value, 2), FONT_TEXT_2);
1191 /* misuse area for displaying emeralds to draw bigger level number */
1192 DrawTextExt(drawto, DX_EMERALDS, DY_EMERALDS,
1193 int2str(value, 3), FONT_LEVEL_NUMBER, BLIT_OPAQUE);
1195 /* now copy it to the area for displaying level number */
1196 BlitBitmap(drawto, drawto,
1197 DX_EMERALDS, DY_EMERALDS + 1,
1198 getFontWidth(FONT_LEVEL_NUMBER) * 3,
1199 getFontHeight(FONT_LEVEL_NUMBER) - 1,
1200 DX_LEVEL - 1, DY_LEVEL + 1);
1202 /* restore the area for displaying emeralds */
1203 DrawGameValue_Emeralds(local_player->gems_still_needed);
1205 /* yes, this is all really ugly :-) */
1209 void DrawAllGameValues(int emeralds, int dynamite, int score, int time,
1212 int key[MAX_NUM_KEYS];
1215 for (i = 0; i < MAX_NUM_KEYS; i++)
1216 key[i] = key_bits & (1 << i);
1218 DrawGameValue_Level(level_nr);
1220 DrawGameValue_Emeralds(emeralds);
1221 DrawGameValue_Dynamite(dynamite);
1222 DrawGameValue_Score(score);
1223 DrawGameValue_Time(time);
1225 DrawGameValue_Keys(key);
1228 void DrawGameDoorValues()
1232 if (level.game_engine_type == GAME_ENGINE_TYPE_EM)
1234 DrawGameDoorValues_EM();
1239 DrawGameValue_Level(level_nr);
1241 DrawGameValue_Emeralds(local_player->gems_still_needed);
1242 DrawGameValue_Dynamite(local_player->inventory_size);
1243 DrawGameValue_Score(local_player->score);
1244 DrawGameValue_Time(TimeLeft);
1246 for (i = 0; i < MAX_PLAYERS; i++)
1247 DrawGameValue_Keys(stored_player[i].key);
1251 static void resolve_group_element(int group_element, int recursion_depth)
1253 static int group_nr;
1254 static struct ElementGroupInfo *group;
1255 struct ElementGroupInfo *actual_group = element_info[group_element].group;
1258 if (recursion_depth > NUM_GROUP_ELEMENTS) /* recursion too deep */
1260 Error(ERR_WARN, "recursion too deep when resolving group element %d",
1261 group_element - EL_GROUP_START + 1);
1263 /* replace element which caused too deep recursion by question mark */
1264 group->element_resolved[group->num_elements_resolved++] = EL_UNKNOWN;
1269 if (recursion_depth == 0) /* initialization */
1271 group = element_info[group_element].group;
1272 group_nr = group_element - EL_GROUP_START;
1274 group->num_elements_resolved = 0;
1275 group->choice_pos = 0;
1278 for (i = 0; i < actual_group->num_elements; i++)
1280 int element = actual_group->element[i];
1282 if (group->num_elements_resolved == NUM_FILE_ELEMENTS)
1285 if (IS_GROUP_ELEMENT(element))
1286 resolve_group_element(element, recursion_depth + 1);
1289 group->element_resolved[group->num_elements_resolved++] = element;
1290 element_info[element].in_group[group_nr] = TRUE;
1297 =============================================================================
1299 -----------------------------------------------------------------------------
1300 initialize game engine due to level / tape version number
1301 =============================================================================
1304 static void InitGameEngine()
1306 int i, j, k, l, x, y;
1308 /* set game engine from tape file when re-playing, else from level file */
1309 game.engine_version = (tape.playing ? tape.engine_version :
1310 level.game_version);
1312 /* ---------------------------------------------------------------------- */
1313 /* set flags for bugs and changes according to active game engine version */
1314 /* ---------------------------------------------------------------------- */
1317 Summary of bugfix/change:
1318 Fixed handling for custom elements that change when pushed by the player.
1320 Fixed/changed in version:
1324 Before 3.1.0, custom elements that "change when pushing" changed directly
1325 after the player started pushing them (until then handled in "DigField()").
1326 Since 3.1.0, these custom elements are not changed until the "pushing"
1327 move of the element is finished (now handled in "ContinueMoving()").
1329 Affected levels/tapes:
1330 The first condition is generally needed for all levels/tapes before version
1331 3.1.0, which might use the old behaviour before it was changed; known tapes
1332 that are affected are some tapes from the level set "Walpurgis Gardens" by
1334 The second condition is an exception from the above case and is needed for
1335 the special case of tapes recorded with game (not engine!) version 3.1.0 or
1336 above (including some development versions of 3.1.0), but before it was
1337 known that this change would break tapes like the above and was fixed in
1338 3.1.1, so that the changed behaviour was active although the engine version
1339 while recording maybe was before 3.1.0. There is at least one tape that is
1340 affected by this exception, which is the tape for the one-level set "Bug
1341 Machine" by Juergen Bonhagen.
1344 game.use_change_when_pushing_bug =
1345 (game.engine_version < VERSION_IDENT(3,1,0,0) &&
1347 tape.game_version >= VERSION_IDENT(3,1,0,0) &&
1348 tape.game_version < VERSION_IDENT(3,1,1,0)));
1351 Summary of bugfix/change:
1352 Fixed handling for blocking the field the player leaves when moving.
1354 Fixed/changed in version:
1358 Before 3.1.1, when "block last field when moving" was enabled, the field
1359 the player is leaving when moving was blocked for the time of the move,
1360 and was directly unblocked afterwards. This resulted in the last field
1361 being blocked for exactly one less than the number of frames of one player
1362 move. Additionally, even when blocking was disabled, the last field was
1363 blocked for exactly one frame.
1364 Since 3.1.1, due to changes in player movement handling, the last field
1365 is not blocked at all when blocking is disabled. When blocking is enabled,
1366 the last field is blocked for exactly the number of frames of one player
1367 move. Additionally, if the player is Murphy, the hero of Supaplex, the
1368 last field is blocked for exactly one more than the number of frames of
1371 Affected levels/tapes:
1372 (!!! yet to be determined -- probably many !!!)
1375 game.use_block_last_field_bug =
1376 (game.engine_version < VERSION_IDENT(3,1,1,0));
1379 Summary of bugfix/change:
1380 Changed behaviour of CE changes with multiple changes per single frame.
1382 Fixed/changed in version:
1386 Before 3.2.0-6, only one single CE change was allowed in each engine frame.
1387 This resulted in race conditions where CEs seem to behave strange in some
1388 situations (where triggered CE changes were just skipped because there was
1389 already a CE change on that tile in the playfield in that engine frame).
1390 Since 3.2.0-6, this was changed to allow up to MAX_NUM_CHANGES_PER_FRAME.
1391 (The number of changes per frame must be limited in any case, because else
1392 it is easily possible to define CE changes that would result in an infinite
1393 loop, causing the whole game to freeze. The MAX_NUM_CHANGES_PER_FRAME value
1394 should be set large enough so that it would only be reached in cases where
1395 the corresponding CE change conditions run into a loop. Therefore, it seems
1396 to be reasonable to set MAX_NUM_CHANGES_PER_FRAME to the same value as the
1397 maximal number of change pages for custom elements.)
1399 Affected levels/tapes:
1403 #if USE_ONLY_ONE_CHANGE_PER_FRAME
1404 game.max_num_changes_per_frame = 1;
1406 game.max_num_changes_per_frame =
1407 (game.engine_version < VERSION_IDENT(3,2,0,6) ? 1 : 32);
1410 /* ---------------------------------------------------------------------- */
1412 /* default scan direction: scan playfield from top/left to bottom/right */
1413 InitPlayfieldScanMode(CA_ARG_SCAN_MODE_NORMAL);
1415 /* dynamically adjust element properties according to game engine version */
1416 InitElementPropertiesEngine(game.engine_version);
1419 printf("level %d: level version == %06d\n", level_nr, level.game_version);
1420 printf(" tape version == %06d [%s] [file: %06d]\n",
1421 tape.engine_version, (tape.playing ? "PLAYING" : "RECORDING"),
1423 printf(" => game.engine_version == %06d\n", game.engine_version);
1427 /* ---------- recursively resolve group elements ------------------------- */
1429 for (i = 0; i < MAX_NUM_ELEMENTS; i++)
1430 for (j = 0; j < NUM_GROUP_ELEMENTS; j++)
1431 element_info[i].in_group[j] = FALSE;
1433 for (i = 0; i < NUM_GROUP_ELEMENTS; i++)
1434 resolve_group_element(EL_GROUP_START + i, 0);
1437 /* ---------- initialize player's initial move delay --------------------- */
1440 /* dynamically adjust player properties according to level information */
1441 game.initial_move_delay_value =
1442 get_move_delay_from_stepsize(level.initial_player_stepsize);
1444 /* dynamically adjust player properties according to level information */
1445 game.initial_move_delay_value =
1446 (level.double_speed ? MOVE_DELAY_HIGH_SPEED : MOVE_DELAY_NORMAL_SPEED);
1449 /* dynamically adjust player properties according to game engine version */
1450 game.initial_move_delay = (game.engine_version <= VERSION_IDENT(2,0,1,0) ?
1451 game.initial_move_delay_value : 0);
1453 /* ---------- initialize player's initial push delay --------------------- */
1455 /* dynamically adjust player properties according to game engine version */
1456 game.initial_push_delay_value =
1457 (game.engine_version < VERSION_IDENT(3,0,7,1) ? 5 : -1);
1459 /* ---------- initialize changing elements ------------------------------- */
1461 /* initialize changing elements information */
1462 for (i = 0; i < MAX_NUM_ELEMENTS; i++)
1464 struct ElementInfo *ei = &element_info[i];
1466 /* this pointer might have been changed in the level editor */
1467 ei->change = &ei->change_page[0];
1469 if (!IS_CUSTOM_ELEMENT(i))
1471 ei->change->target_element = EL_EMPTY_SPACE;
1472 ei->change->delay_fixed = 0;
1473 ei->change->delay_random = 0;
1474 ei->change->delay_frames = 1;
1477 for (j = 0; j < NUM_CHANGE_EVENTS; j++)
1479 ei->has_change_event[j] = FALSE;
1481 ei->event_page_nr[j] = 0;
1482 ei->event_page[j] = &ei->change_page[0];
1486 /* add changing elements from pre-defined list */
1487 for (i = 0; change_delay_list[i].element != EL_UNDEFINED; i++)
1489 struct ChangingElementInfo *ch_delay = &change_delay_list[i];
1490 struct ElementInfo *ei = &element_info[ch_delay->element];
1492 ei->change->target_element = ch_delay->target_element;
1493 ei->change->delay_fixed = ch_delay->change_delay;
1495 ei->change->pre_change_function = ch_delay->pre_change_function;
1496 ei->change->change_function = ch_delay->change_function;
1497 ei->change->post_change_function = ch_delay->post_change_function;
1499 ei->change->can_change = TRUE;
1500 ei->change->can_change_or_has_action = TRUE;
1502 ei->has_change_event[CE_DELAY] = TRUE;
1504 SET_PROPERTY(ch_delay->element, EP_CAN_CHANGE, TRUE);
1505 SET_PROPERTY(ch_delay->element, EP_CAN_CHANGE_OR_HAS_ACTION, TRUE);
1508 /* ---------- initialize internal run-time variables ------------- */
1510 for (i = 0; i < NUM_CUSTOM_ELEMENTS; i++)
1512 struct ElementInfo *ei = &element_info[EL_CUSTOM_START + i];
1514 for (j = 0; j < ei->num_change_pages; j++)
1516 ei->change_page[j].can_change_or_has_action =
1517 (ei->change_page[j].can_change |
1518 ei->change_page[j].has_action);
1522 /* add change events from custom element configuration */
1523 for (i = 0; i < NUM_CUSTOM_ELEMENTS; i++)
1525 struct ElementInfo *ei = &element_info[EL_CUSTOM_START + i];
1527 for (j = 0; j < ei->num_change_pages; j++)
1529 if (!ei->change_page[j].can_change_or_has_action)
1532 for (k = 0; k < NUM_CHANGE_EVENTS; k++)
1534 /* only add event page for the first page found with this event */
1535 if (ei->change_page[j].has_event[k] && !(ei->has_change_event[k]))
1537 ei->has_change_event[k] = TRUE;
1539 ei->event_page_nr[k] = j;
1540 ei->event_page[k] = &ei->change_page[j];
1546 /* ---------- initialize run-time trigger player and element ------------- */
1548 for (i = 0; i < NUM_CUSTOM_ELEMENTS; i++)
1550 struct ElementInfo *ei = &element_info[EL_CUSTOM_START + i];
1552 for (j = 0; j < ei->num_change_pages; j++)
1554 ei->change_page[j].actual_trigger_element = EL_EMPTY;
1555 ei->change_page[j].actual_trigger_player = EL_PLAYER_1;
1556 ei->change_page[j].actual_trigger_side = CH_SIDE_NONE;
1557 ei->change_page[j].actual_trigger_ce_value = 0;
1561 /* ---------- initialize trigger events ---------------------------------- */
1563 /* initialize trigger events information */
1564 for (i = 0; i < MAX_NUM_ELEMENTS; i++)
1565 for (j = 0; j < NUM_CHANGE_EVENTS; j++)
1566 trigger_events[i][j] = FALSE;
1568 /* add trigger events from element change event properties */
1569 for (i = 0; i < MAX_NUM_ELEMENTS; i++)
1571 struct ElementInfo *ei = &element_info[i];
1573 for (j = 0; j < ei->num_change_pages; j++)
1575 if (!ei->change_page[j].can_change_or_has_action)
1578 if (ei->change_page[j].has_event[CE_BY_OTHER_ACTION])
1580 int trigger_element = ei->change_page[j].trigger_element;
1582 for (k = 0; k < NUM_CHANGE_EVENTS; k++)
1584 if (ei->change_page[j].has_event[k])
1586 if (IS_GROUP_ELEMENT(trigger_element))
1588 struct ElementGroupInfo *group =
1589 element_info[trigger_element].group;
1591 for (l = 0; l < group->num_elements_resolved; l++)
1592 trigger_events[group->element_resolved[l]][k] = TRUE;
1595 trigger_events[trigger_element][k] = TRUE;
1602 /* ---------- initialize push delay -------------------------------------- */
1604 /* initialize push delay values to default */
1605 for (i = 0; i < MAX_NUM_ELEMENTS; i++)
1607 if (!IS_CUSTOM_ELEMENT(i))
1609 element_info[i].push_delay_fixed = game.default_push_delay_fixed;
1610 element_info[i].push_delay_random = game.default_push_delay_random;
1614 /* set push delay value for certain elements from pre-defined list */
1615 for (i = 0; push_delay_list[i].element != EL_UNDEFINED; i++)
1617 int e = push_delay_list[i].element;
1619 element_info[e].push_delay_fixed = push_delay_list[i].push_delay_fixed;
1620 element_info[e].push_delay_random = push_delay_list[i].push_delay_random;
1623 /* set push delay value for Supaplex elements for newer engine versions */
1624 if (game.engine_version >= VERSION_IDENT(3,1,0,0))
1626 for (i = 0; i < MAX_NUM_ELEMENTS; i++)
1628 if (IS_SP_ELEMENT(i))
1630 /* set SP push delay to just enough to push under a falling zonk */
1631 int delay = (game.engine_version >= VERSION_IDENT(3,1,1,0) ? 8 : 6);
1633 element_info[i].push_delay_fixed = delay;
1634 element_info[i].push_delay_random = 0;
1639 /* ---------- initialize move stepsize ----------------------------------- */
1641 /* initialize move stepsize values to default */
1642 for (i = 0; i < MAX_NUM_ELEMENTS; i++)
1643 if (!IS_CUSTOM_ELEMENT(i))
1644 element_info[i].move_stepsize = MOVE_STEPSIZE_NORMAL;
1646 /* set move stepsize value for certain elements from pre-defined list */
1647 for (i = 0; move_stepsize_list[i].element != EL_UNDEFINED; i++)
1649 int e = move_stepsize_list[i].element;
1651 element_info[e].move_stepsize = move_stepsize_list[i].move_stepsize;
1654 /* ---------- initialize collect score ----------------------------------- */
1656 /* initialize collect score values for custom elements from initial value */
1657 for (i = 0; i < MAX_NUM_ELEMENTS; i++)
1658 if (IS_CUSTOM_ELEMENT(i))
1659 element_info[i].collect_score = element_info[i].collect_score_initial;
1661 /* ---------- initialize collect count ----------------------------------- */
1663 /* initialize collect count values for non-custom elements */
1664 for (i = 0; i < MAX_NUM_ELEMENTS; i++)
1665 if (!IS_CUSTOM_ELEMENT(i))
1666 element_info[i].collect_count_initial = 0;
1668 /* add collect count values for all elements from pre-defined list */
1669 for (i = 0; collect_count_list[i].element != EL_UNDEFINED; i++)
1670 element_info[collect_count_list[i].element].collect_count_initial =
1671 collect_count_list[i].count;
1673 /* ---------- initialize access direction -------------------------------- */
1675 /* initialize access direction values to default (access from every side) */
1676 for (i = 0; i < MAX_NUM_ELEMENTS; i++)
1677 if (!IS_CUSTOM_ELEMENT(i))
1678 element_info[i].access_direction = MV_ALL_DIRECTIONS;
1680 /* set access direction value for certain elements from pre-defined list */
1681 for (i = 0; access_direction_list[i].element != EL_UNDEFINED; i++)
1682 element_info[access_direction_list[i].element].access_direction =
1683 access_direction_list[i].direction;
1685 /* ---------- initialize explosion content ------------------------------- */
1686 for (i = 0; i < MAX_NUM_ELEMENTS; i++)
1688 if (IS_CUSTOM_ELEMENT(i))
1691 for (y = 0; y < 3; y++) for (x = 0; x < 3; x++)
1693 /* (content for EL_YAMYAM set at run-time with game.yamyam_content_nr) */
1695 element_info[i].content.e[x][y] =
1696 (i == EL_PLAYER_1 ? EL_EMERALD_YELLOW :
1697 i == EL_PLAYER_2 ? EL_EMERALD_RED :
1698 i == EL_PLAYER_3 ? EL_EMERALD :
1699 i == EL_PLAYER_4 ? EL_EMERALD_PURPLE :
1700 i == EL_MOLE ? EL_EMERALD_RED :
1701 i == EL_PENGUIN ? EL_EMERALD_PURPLE :
1702 i == EL_BUG ? (x == 1 && y == 1 ? EL_DIAMOND : EL_EMERALD) :
1703 i == EL_BD_BUTTERFLY ? EL_BD_DIAMOND :
1704 i == EL_SP_ELECTRON ? EL_SP_INFOTRON :
1705 i == EL_AMOEBA_TO_DIAMOND ? level.amoeba_content :
1706 i == EL_WALL_EMERALD ? EL_EMERALD :
1707 i == EL_WALL_DIAMOND ? EL_DIAMOND :
1708 i == EL_WALL_BD_DIAMOND ? EL_BD_DIAMOND :
1709 i == EL_WALL_EMERALD_YELLOW ? EL_EMERALD_YELLOW :
1710 i == EL_WALL_EMERALD_RED ? EL_EMERALD_RED :
1711 i == EL_WALL_EMERALD_PURPLE ? EL_EMERALD_PURPLE :
1712 i == EL_WALL_PEARL ? EL_PEARL :
1713 i == EL_WALL_CRYSTAL ? EL_CRYSTAL :
1719 int get_num_special_action(int element, int action_first, int action_last)
1721 int num_special_action = 0;
1724 for (i = action_first; i <= action_last; i++)
1726 boolean found = FALSE;
1728 for (j = 0; j < NUM_DIRECTIONS; j++)
1729 if (el_act_dir2img(element, i, j) !=
1730 el_act_dir2img(element, ACTION_DEFAULT, j))
1734 num_special_action++;
1739 return num_special_action;
1743 =============================================================================
1745 -----------------------------------------------------------------------------
1746 initialize and start new game
1747 =============================================================================
1752 boolean emulate_bd = TRUE; /* unless non-BOULDERDASH elements found */
1753 boolean emulate_sb = TRUE; /* unless non-SOKOBAN elements found */
1754 boolean emulate_sp = TRUE; /* unless non-SUPAPLEX elements found */
1759 /* don't play tapes over network */
1760 network_playing = (options.network && !tape.playing);
1762 for (i = 0; i < MAX_PLAYERS; i++)
1764 struct PlayerInfo *player = &stored_player[i];
1766 player->index_nr = i;
1767 player->index_bit = (1 << i);
1768 player->element_nr = EL_PLAYER_1 + i;
1770 player->present = FALSE;
1771 player->active = FALSE;
1774 player->effective_action = 0;
1775 player->programmed_action = 0;
1778 player->gems_still_needed = level.gems_needed;
1779 player->sokobanfields_still_needed = 0;
1780 player->lights_still_needed = 0;
1781 player->friends_still_needed = 0;
1783 for (j = 0; j < MAX_NUM_KEYS; j++)
1784 player->key[j] = FALSE;
1786 player->dynabomb_count = 0;
1787 player->dynabomb_size = 1;
1788 player->dynabombs_left = 0;
1789 player->dynabomb_xl = FALSE;
1791 player->MovDir = MV_NONE;
1794 player->GfxDir = MV_NONE;
1795 player->GfxAction = ACTION_DEFAULT;
1797 player->StepFrame = 0;
1799 player->use_murphy = FALSE;
1800 player->artwork_element =
1801 (level.use_artwork_element[i] ? level.artwork_element[i] :
1802 player->element_nr);
1804 player->block_last_field = FALSE; /* initialized in InitPlayerField() */
1805 player->block_delay_adjustment = 0; /* initialized in InitPlayerField() */
1807 player->can_fall_into_acid = CAN_MOVE_INTO_ACID(player->element_nr);
1809 player->actual_frame_counter = 0;
1811 player->step_counter = 0;
1813 player->last_move_dir = MV_NONE;
1815 player->is_waiting = FALSE;
1816 player->is_moving = FALSE;
1817 player->is_auto_moving = FALSE;
1818 player->is_digging = FALSE;
1819 player->is_snapping = FALSE;
1820 player->is_collecting = FALSE;
1821 player->is_pushing = FALSE;
1822 player->is_switching = FALSE;
1823 player->is_dropping = FALSE;
1825 player->is_bored = FALSE;
1826 player->is_sleeping = FALSE;
1828 player->frame_counter_bored = -1;
1829 player->frame_counter_sleeping = -1;
1831 player->anim_delay_counter = 0;
1832 player->post_delay_counter = 0;
1834 player->action_waiting = ACTION_DEFAULT;
1835 player->last_action_waiting = ACTION_DEFAULT;
1836 player->special_action_bored = ACTION_DEFAULT;
1837 player->special_action_sleeping = ACTION_DEFAULT;
1839 /* set number of special actions for bored and sleeping animation */
1840 player->num_special_action_bored =
1841 get_num_special_action(player->artwork_element,
1842 ACTION_BORING_1, ACTION_BORING_LAST);
1843 player->num_special_action_sleeping =
1844 get_num_special_action(player->artwork_element,
1845 ACTION_SLEEPING_1, ACTION_SLEEPING_LAST);
1847 player->switch_x = -1;
1848 player->switch_y = -1;
1850 player->drop_x = -1;
1851 player->drop_y = -1;
1853 player->show_envelope = 0;
1856 SetPlayerMoveSpeed(player, level.initial_player_stepsize, TRUE);
1858 player->move_delay = game.initial_move_delay;
1859 player->move_delay_value = game.initial_move_delay_value;
1861 player->move_delay_value_next = -1;
1863 player->move_delay_reset_counter = 0;
1865 player->cannot_move = FALSE;
1868 player->push_delay = -1; /* initialized when pushing starts */
1869 player->push_delay_value = game.initial_push_delay_value;
1871 player->drop_delay = 0;
1873 player->last_jx = player->last_jy = 0;
1874 player->jx = player->jy = 0;
1876 player->shield_normal_time_left = 0;
1877 player->shield_deadly_time_left = 0;
1879 player->inventory_infinite_element = EL_UNDEFINED;
1880 player->inventory_size = 0;
1882 DigField(player, 0, 0, 0, 0, 0, 0, DF_NO_PUSH);
1883 SnapField(player, 0, 0);
1885 player->LevelSolved = FALSE;
1886 player->GameOver = FALSE;
1889 network_player_action_received = FALSE;
1891 #if defined(NETWORK_AVALIABLE)
1892 /* initial null action */
1893 if (network_playing)
1894 SendToServer_MovePlayer(MV_NONE);
1903 TimeLeft = level.time;
1906 ScreenMovDir = MV_NONE;
1910 ScrollStepSize = 0; /* will be correctly initialized by ScrollScreen() */
1912 AllPlayersGone = FALSE;
1914 game.yamyam_content_nr = 0;
1915 game.magic_wall_active = FALSE;
1916 game.magic_wall_time_left = 0;
1917 game.light_time_left = 0;
1918 game.timegate_time_left = 0;
1919 game.switchgate_pos = 0;
1920 game.wind_direction = level.wind_direction_initial;
1921 game.gravity = level.initial_gravity;
1922 game.explosions_delayed = TRUE;
1924 game.lenses_time_left = 0;
1925 game.magnify_time_left = 0;
1927 game.ball_state = level.ball_state_initial;
1928 game.ball_content_nr = 0;
1930 game.envelope_active = FALSE;
1932 for (i = 0; i < NUM_BELTS; i++)
1934 game.belt_dir[i] = MV_NONE;
1935 game.belt_dir_nr[i] = 3; /* not moving, next moving left */
1938 for (i = 0; i < MAX_NUM_AMOEBA; i++)
1939 AmoebaCnt[i] = AmoebaCnt2[i] = 0;
1942 SCAN_PLAYFIELD(x, y)
1944 for (x = 0; x < lev_fieldx; x++) for (y = 0; y < lev_fieldy; y++)
1947 Feld[x][y] = level.field[x][y];
1948 MovPos[x][y] = MovDir[x][y] = MovDelay[x][y] = 0;
1949 ChangeDelay[x][y] = 0;
1950 ChangePage[x][y] = -1;
1951 #if USE_NEW_CUSTOM_VALUE
1952 CustomValue[x][y] = 0; /* initialized in InitField() */
1954 Store[x][y] = Store2[x][y] = StorePlayer[x][y] = Back[x][y] = 0;
1956 WasJustMoving[x][y] = 0;
1957 WasJustFalling[x][y] = 0;
1958 CheckCollision[x][y] = 0;
1960 Pushed[x][y] = FALSE;
1962 ChangeCount[x][y] = 0;
1963 ChangeEvent[x][y] = -1;
1965 ExplodePhase[x][y] = 0;
1966 ExplodeDelay[x][y] = 0;
1967 ExplodeField[x][y] = EX_TYPE_NONE;
1969 RunnerVisit[x][y] = 0;
1970 PlayerVisit[x][y] = 0;
1973 GfxRandom[x][y] = INIT_GFX_RANDOM();
1974 GfxElement[x][y] = EL_UNDEFINED;
1975 GfxAction[x][y] = ACTION_DEFAULT;
1976 GfxDir[x][y] = MV_NONE;
1980 SCAN_PLAYFIELD(x, y)
1982 for (y = 0; y < lev_fieldy; y++) for (x = 0; x < lev_fieldx; x++)
1985 if (emulate_bd && !IS_BD_ELEMENT(Feld[x][y]))
1987 if (emulate_sb && !IS_SB_ELEMENT(Feld[x][y]))
1989 if (emulate_sp && !IS_SP_ELEMENT(Feld[x][y]))
1992 InitField(x, y, TRUE);
1997 game.emulation = (emulate_bd ? EMU_BOULDERDASH :
1998 emulate_sb ? EMU_SOKOBAN :
1999 emulate_sp ? EMU_SUPAPLEX : EMU_NONE);
2001 #if USE_NEW_ALL_SLIPPERY
2002 /* initialize type of slippery elements */
2003 for (i = 0; i < MAX_NUM_ELEMENTS; i++)
2005 if (!IS_CUSTOM_ELEMENT(i))
2007 /* default: elements slip down either to the left or right randomly */
2008 element_info[i].slippery_type = SLIPPERY_ANY_RANDOM;
2010 /* SP style elements prefer to slip down on the left side */
2011 if (game.engine_version >= VERSION_IDENT(3,1,1,0) && IS_SP_ELEMENT(i))
2012 element_info[i].slippery_type = SLIPPERY_ANY_LEFT_RIGHT;
2014 /* BD style elements prefer to slip down on the left side */
2015 if (game.emulation == EMU_BOULDERDASH)
2016 element_info[i].slippery_type = SLIPPERY_ANY_LEFT_RIGHT;
2021 /* initialize explosion and ignition delay */
2022 for (i = 0; i < MAX_NUM_ELEMENTS; i++)
2024 if (!IS_CUSTOM_ELEMENT(i))
2027 int delay = (((IS_SP_ELEMENT(i) && i != EL_EMPTY_SPACE) &&
2028 game.engine_version >= VERSION_IDENT(3,1,0,0)) ||
2029 game.emulation == EMU_SUPAPLEX ? 3 : 2);
2030 int last_phase = (num_phase + 1) * delay;
2031 int half_phase = (num_phase / 2) * delay;
2033 element_info[i].explosion_delay = last_phase - 1;
2034 element_info[i].ignition_delay = half_phase;
2036 if (i == EL_BLACK_ORB)
2037 element_info[i].ignition_delay = 1;
2041 if (element_info[i].explosion_delay < 1) /* !!! check again !!! */
2042 element_info[i].explosion_delay = 1;
2044 if (element_info[i].ignition_delay < 1) /* !!! check again !!! */
2045 element_info[i].ignition_delay = 1;
2049 /* correct non-moving belts to start moving left */
2050 for (i = 0; i < NUM_BELTS; i++)
2051 if (game.belt_dir[i] == MV_NONE)
2052 game.belt_dir_nr[i] = 3; /* not moving, next moving left */
2054 /* check if any connected player was not found in playfield */
2055 for (i = 0; i < MAX_PLAYERS; i++)
2057 struct PlayerInfo *player = &stored_player[i];
2059 if (player->connected && !player->present)
2061 for (j = 0; j < MAX_PLAYERS; j++)
2063 struct PlayerInfo *some_player = &stored_player[j];
2064 int jx = some_player->jx, jy = some_player->jy;
2066 /* assign first free player found that is present in the playfield */
2067 if (some_player->present && !some_player->connected)
2069 player->present = TRUE;
2070 player->active = TRUE;
2072 some_player->present = FALSE;
2073 some_player->active = FALSE;
2076 player->element_nr = some_player->element_nr;
2079 player->artwork_element = some_player->artwork_element;
2081 player->block_last_field = some_player->block_last_field;
2082 player->block_delay_adjustment = some_player->block_delay_adjustment;
2084 StorePlayer[jx][jy] = player->element_nr;
2085 player->jx = player->last_jx = jx;
2086 player->jy = player->last_jy = jy;
2096 /* when playing a tape, eliminate all players which do not participate */
2098 for (i = 0; i < MAX_PLAYERS; i++)
2100 if (stored_player[i].active && !tape.player_participates[i])
2102 struct PlayerInfo *player = &stored_player[i];
2103 int jx = player->jx, jy = player->jy;
2105 player->active = FALSE;
2106 StorePlayer[jx][jy] = 0;
2107 Feld[jx][jy] = EL_EMPTY;
2111 else if (!options.network && !setup.team_mode) /* && !tape.playing */
2113 /* when in single player mode, eliminate all but the first active player */
2115 for (i = 0; i < MAX_PLAYERS; i++)
2117 if (stored_player[i].active)
2119 for (j = i + 1; j < MAX_PLAYERS; j++)
2121 if (stored_player[j].active)
2123 struct PlayerInfo *player = &stored_player[j];
2124 int jx = player->jx, jy = player->jy;
2126 player->active = FALSE;
2127 player->present = FALSE;
2129 StorePlayer[jx][jy] = 0;
2130 Feld[jx][jy] = EL_EMPTY;
2137 /* when recording the game, store which players take part in the game */
2140 for (i = 0; i < MAX_PLAYERS; i++)
2141 if (stored_player[i].active)
2142 tape.player_participates[i] = TRUE;
2147 for (i = 0; i < MAX_PLAYERS; i++)
2149 struct PlayerInfo *player = &stored_player[i];
2151 printf("Player %d: present == %d, connected == %d, active == %d.\n",
2156 if (local_player == player)
2157 printf("Player %d is local player.\n", i+1);
2161 if (BorderElement == EL_EMPTY)
2164 SBX_Right = lev_fieldx - SCR_FIELDX;
2166 SBY_Lower = lev_fieldy - SCR_FIELDY;
2171 SBX_Right = lev_fieldx - SCR_FIELDX + 1;
2173 SBY_Lower = lev_fieldy - SCR_FIELDY + 1;
2176 if (lev_fieldx + (SBX_Left == -1 ? 2 : 0) <= SCR_FIELDX)
2177 SBX_Left = SBX_Right = -1 * (SCR_FIELDX - lev_fieldx) / 2;
2179 if (lev_fieldy + (SBY_Upper == -1 ? 2 : 0) <= SCR_FIELDY)
2180 SBY_Upper = SBY_Lower = -1 * (SCR_FIELDY - lev_fieldy) / 2;
2182 /* if local player not found, look for custom element that might create
2183 the player (make some assumptions about the right custom element) */
2184 if (!local_player->present)
2186 int start_x = 0, start_y = 0;
2187 int found_rating = 0;
2188 int found_element = EL_UNDEFINED;
2189 int player_nr = local_player->index_nr;
2192 SCAN_PLAYFIELD(x, y)
2194 for (y = 0; y < lev_fieldy; y++) for (x = 0; x < lev_fieldx; x++)
2197 int element = Feld[x][y];
2202 if (level.use_start_element[player_nr] &&
2203 level.start_element[player_nr] == element &&
2210 found_element = element;
2213 if (!IS_CUSTOM_ELEMENT(element))
2216 if (CAN_CHANGE(element))
2218 for (i = 0; i < element_info[element].num_change_pages; i++)
2220 /* check for player created from custom element as single target */
2221 content = element_info[element].change_page[i].target_element;
2222 is_player = ELEM_IS_PLAYER(content);
2224 if (is_player && (found_rating < 3 || element < found_element))
2230 found_element = element;
2235 for (yy = 0; yy < 3; yy++) for (xx = 0; xx < 3; xx++)
2237 /* check for player created from custom element as explosion content */
2238 content = element_info[element].content.e[xx][yy];
2239 is_player = ELEM_IS_PLAYER(content);
2241 if (is_player && (found_rating < 2 || element < found_element))
2243 start_x = x + xx - 1;
2244 start_y = y + yy - 1;
2247 found_element = element;
2250 if (!CAN_CHANGE(element))
2253 for (i = 0; i < element_info[element].num_change_pages; i++)
2255 /* check for player created from custom element as extended target */
2257 element_info[element].change_page[i].target_content.e[xx][yy];
2259 is_player = ELEM_IS_PLAYER(content);
2261 if (is_player && (found_rating < 1 || element < found_element))
2263 start_x = x + xx - 1;
2264 start_y = y + yy - 1;
2267 found_element = element;
2273 scroll_x = (start_x < SBX_Left + MIDPOSX ? SBX_Left :
2274 start_x > SBX_Right + MIDPOSX ? SBX_Right :
2277 scroll_y = (start_y < SBY_Upper + MIDPOSY ? SBY_Upper :
2278 start_y > SBY_Lower + MIDPOSY ? SBY_Lower :
2283 scroll_x = (local_player->jx < SBX_Left + MIDPOSX ? SBX_Left :
2284 local_player->jx > SBX_Right + MIDPOSX ? SBX_Right :
2285 local_player->jx - MIDPOSX);
2287 scroll_y = (local_player->jy < SBY_Upper + MIDPOSY ? SBY_Upper :
2288 local_player->jy > SBY_Lower + MIDPOSY ? SBY_Lower :
2289 local_player->jy - MIDPOSY);
2292 if (!game.restart_level)
2293 CloseDoor(DOOR_CLOSE_1);
2295 /* !!! FIX THIS (START) !!! */
2296 if (level.game_engine_type == GAME_ENGINE_TYPE_EM)
2298 InitGameEngine_EM();
2305 /* after drawing the level, correct some elements */
2306 if (game.timegate_time_left == 0)
2307 CloseAllOpenTimegates();
2309 if (setup.soft_scrolling)
2310 BlitBitmap(fieldbuffer, backbuffer, FX, FY, SXSIZE, SYSIZE, SX, SY);
2312 redraw_mask |= REDRAW_FROM_BACKBUFFER;
2315 /* !!! FIX THIS (END) !!! */
2317 if (!game.restart_level)
2319 /* copy default game door content to main double buffer */
2320 BlitBitmap(graphic_info[IMG_GLOBAL_DOOR].bitmap, drawto,
2321 DOOR_GFX_PAGEX5, DOOR_GFX_PAGEY1, DXSIZE, DYSIZE, DX, DY);
2324 DrawGameDoorValues();
2326 if (!game.restart_level)
2330 game_gadget[SOUND_CTRL_ID_MUSIC]->checked = setup.sound_music;
2331 game_gadget[SOUND_CTRL_ID_LOOPS]->checked = setup.sound_loops;
2332 game_gadget[SOUND_CTRL_ID_SIMPLE]->checked = setup.sound_simple;
2336 /* copy actual game door content to door double buffer for OpenDoor() */
2337 BlitBitmap(drawto, bitmap_db_door,
2338 DX, DY, DXSIZE, DYSIZE, DOOR_GFX_PAGEX1, DOOR_GFX_PAGEY1);
2340 OpenDoor(DOOR_OPEN_ALL);
2342 PlaySoundStereo(SND_GAME_STARTING, SOUND_MIDDLE);
2344 if (setup.sound_music)
2347 KeyboardAutoRepeatOffUnlessAutoplay();
2351 for (i = 0; i < MAX_PLAYERS; i++)
2352 printf("Player %d %sactive.\n",
2353 i + 1, (stored_player[i].active ? "" : "not "));
2357 game.restart_level = FALSE;
2360 void UpdateEngineValues(int actual_scroll_x, int actual_scroll_y)
2362 /* this is used for non-R'n'D game engines to update certain engine values */
2364 /* needed to determine if sounds are played within the visible screen area */
2365 scroll_x = actual_scroll_x;
2366 scroll_y = actual_scroll_y;
2369 void InitMovDir(int x, int y)
2371 int i, element = Feld[x][y];
2372 static int xy[4][2] =
2379 static int direction[3][4] =
2381 { MV_RIGHT, MV_UP, MV_LEFT, MV_DOWN },
2382 { MV_LEFT, MV_DOWN, MV_RIGHT, MV_UP },
2383 { MV_LEFT, MV_RIGHT, MV_UP, MV_DOWN }
2392 Feld[x][y] = EL_BUG;
2393 MovDir[x][y] = direction[0][element - EL_BUG_RIGHT];
2396 case EL_SPACESHIP_RIGHT:
2397 case EL_SPACESHIP_UP:
2398 case EL_SPACESHIP_LEFT:
2399 case EL_SPACESHIP_DOWN:
2400 Feld[x][y] = EL_SPACESHIP;
2401 MovDir[x][y] = direction[0][element - EL_SPACESHIP_RIGHT];
2404 case EL_BD_BUTTERFLY_RIGHT:
2405 case EL_BD_BUTTERFLY_UP:
2406 case EL_BD_BUTTERFLY_LEFT:
2407 case EL_BD_BUTTERFLY_DOWN:
2408 Feld[x][y] = EL_BD_BUTTERFLY;
2409 MovDir[x][y] = direction[0][element - EL_BD_BUTTERFLY_RIGHT];
2412 case EL_BD_FIREFLY_RIGHT:
2413 case EL_BD_FIREFLY_UP:
2414 case EL_BD_FIREFLY_LEFT:
2415 case EL_BD_FIREFLY_DOWN:
2416 Feld[x][y] = EL_BD_FIREFLY;
2417 MovDir[x][y] = direction[0][element - EL_BD_FIREFLY_RIGHT];
2420 case EL_PACMAN_RIGHT:
2422 case EL_PACMAN_LEFT:
2423 case EL_PACMAN_DOWN:
2424 Feld[x][y] = EL_PACMAN;
2425 MovDir[x][y] = direction[0][element - EL_PACMAN_RIGHT];
2428 case EL_SP_SNIKSNAK:
2429 MovDir[x][y] = MV_UP;
2432 case EL_SP_ELECTRON:
2433 MovDir[x][y] = MV_LEFT;
2440 Feld[x][y] = EL_MOLE;
2441 MovDir[x][y] = direction[2][element - EL_MOLE_LEFT];
2445 if (IS_CUSTOM_ELEMENT(element))
2447 struct ElementInfo *ei = &element_info[element];
2448 int move_direction_initial = ei->move_direction_initial;
2449 int move_pattern = ei->move_pattern;
2451 if (move_direction_initial == MV_START_PREVIOUS)
2453 if (MovDir[x][y] != MV_NONE)
2456 move_direction_initial = MV_START_AUTOMATIC;
2459 if (move_direction_initial == MV_START_RANDOM)
2460 MovDir[x][y] = 1 << RND(4);
2461 else if (move_direction_initial & MV_ANY_DIRECTION)
2462 MovDir[x][y] = move_direction_initial;
2463 else if (move_pattern == MV_ALL_DIRECTIONS ||
2464 move_pattern == MV_TURNING_LEFT ||
2465 move_pattern == MV_TURNING_RIGHT ||
2466 move_pattern == MV_TURNING_LEFT_RIGHT ||
2467 move_pattern == MV_TURNING_RIGHT_LEFT ||
2468 move_pattern == MV_TURNING_RANDOM)
2469 MovDir[x][y] = 1 << RND(4);
2470 else if (move_pattern == MV_HORIZONTAL)
2471 MovDir[x][y] = (RND(2) ? MV_LEFT : MV_RIGHT);
2472 else if (move_pattern == MV_VERTICAL)
2473 MovDir[x][y] = (RND(2) ? MV_UP : MV_DOWN);
2474 else if (move_pattern & MV_ANY_DIRECTION)
2475 MovDir[x][y] = element_info[element].move_pattern;
2476 else if (move_pattern == MV_ALONG_LEFT_SIDE ||
2477 move_pattern == MV_ALONG_RIGHT_SIDE)
2479 /* use random direction as default start direction */
2480 if (game.engine_version >= VERSION_IDENT(3,1,0,0))
2481 MovDir[x][y] = 1 << RND(4);
2483 for (i = 0; i < NUM_DIRECTIONS; i++)
2485 int x1 = x + xy[i][0];
2486 int y1 = y + xy[i][1];
2488 if (!IN_LEV_FIELD(x1, y1) || !IS_FREE(x1, y1))
2490 if (move_pattern == MV_ALONG_RIGHT_SIDE)
2491 MovDir[x][y] = direction[0][i];
2493 MovDir[x][y] = direction[1][i];
2502 MovDir[x][y] = 1 << RND(4);
2504 if (element != EL_BUG &&
2505 element != EL_SPACESHIP &&
2506 element != EL_BD_BUTTERFLY &&
2507 element != EL_BD_FIREFLY)
2510 for (i = 0; i < NUM_DIRECTIONS; i++)
2512 int x1 = x + xy[i][0];
2513 int y1 = y + xy[i][1];
2515 if (!IN_LEV_FIELD(x1, y1) || !IS_FREE(x1, y1))
2517 if (element == EL_BUG || element == EL_BD_BUTTERFLY)
2519 MovDir[x][y] = direction[0][i];
2522 else if (element == EL_SPACESHIP || element == EL_BD_FIREFLY ||
2523 element == EL_SP_SNIKSNAK || element == EL_SP_ELECTRON)
2525 MovDir[x][y] = direction[1][i];
2534 GfxDir[x][y] = MovDir[x][y];
2537 void InitAmoebaNr(int x, int y)
2540 int group_nr = AmoebeNachbarNr(x, y);
2544 for (i = 1; i < MAX_NUM_AMOEBA; i++)
2546 if (AmoebaCnt[i] == 0)
2554 AmoebaNr[x][y] = group_nr;
2555 AmoebaCnt[group_nr]++;
2556 AmoebaCnt2[group_nr]++;
2562 boolean raise_level = FALSE;
2564 if (local_player->MovPos)
2567 if (tape.auto_play) /* tape might already be stopped here */
2568 tape.auto_play_level_solved = TRUE;
2570 local_player->LevelSolved = FALSE;
2572 PlaySoundStereo(SND_GAME_WINNING, SOUND_MIDDLE);
2576 if (!tape.playing && setup.sound_loops)
2577 PlaySoundExt(SND_GAME_LEVELTIME_BONUS, SOUND_MAX_VOLUME, SOUND_MIDDLE,
2578 SND_CTRL_PLAY_LOOP);
2580 while (TimeLeft > 0)
2582 if (!tape.playing && !setup.sound_loops)
2583 PlaySoundStereo(SND_GAME_LEVELTIME_BONUS, SOUND_MIDDLE);
2585 if (TimeLeft > 100 && TimeLeft % 10 == 0)
2588 RaiseScore(level.score[SC_TIME_BONUS] * 10);
2593 RaiseScore(level.score[SC_TIME_BONUS]);
2596 DrawGameValue_Time(TimeLeft);
2604 if (!tape.playing && setup.sound_loops)
2605 StopSound(SND_GAME_LEVELTIME_BONUS);
2607 else if (level.time == 0) /* level without time limit */
2609 if (!tape.playing && setup.sound_loops)
2610 PlaySoundExt(SND_GAME_LEVELTIME_BONUS, SOUND_MAX_VOLUME, SOUND_MIDDLE,
2611 SND_CTRL_PLAY_LOOP);
2613 while (TimePlayed < 999)
2615 if (!tape.playing && !setup.sound_loops)
2616 PlaySoundStereo(SND_GAME_LEVELTIME_BONUS, SOUND_MIDDLE);
2618 if (TimePlayed < 900 && TimePlayed % 10 == 0)
2621 RaiseScore(level.score[SC_TIME_BONUS] * 10);
2626 RaiseScore(level.score[SC_TIME_BONUS]);
2629 DrawGameValue_Time(TimePlayed);
2637 if (!tape.playing && setup.sound_loops)
2638 StopSound(SND_GAME_LEVELTIME_BONUS);
2641 /* close exit door after last player */
2642 if (AllPlayersGone && ExitX >= 0 && ExitY >= 0 &&
2643 (Feld[ExitX][ExitY] == EL_EXIT_OPEN ||
2644 Feld[ExitX][ExitY] == EL_SP_EXIT_OPEN))
2646 int element = Feld[ExitX][ExitY];
2648 Feld[ExitX][ExitY] = (element == EL_EXIT_OPEN ? EL_EXIT_CLOSING :
2649 EL_SP_EXIT_CLOSING);
2651 PlayLevelSoundElementAction(ExitX, ExitY, element, ACTION_CLOSING);
2654 /* player disappears */
2655 if (ExitX >= 0 && ExitY >= 0)
2656 DrawLevelField(ExitX, ExitY);
2663 CloseDoor(DOOR_CLOSE_1);
2668 SaveTape(tape.level_nr); /* Ask to save tape */
2671 if (level_nr == leveldir_current->handicap_level)
2673 leveldir_current->handicap_level++;
2674 SaveLevelSetup_SeriesInfo();
2677 if (level_editor_test_game)
2678 local_player->score = -1; /* no highscore when playing from editor */
2679 else if (level_nr < leveldir_current->last_level)
2680 raise_level = TRUE; /* advance to next level */
2682 if ((hi_pos = NewHiScore()) >= 0)
2684 game_status = GAME_MODE_SCORES;
2685 DrawHallOfFame(hi_pos);
2694 game_status = GAME_MODE_MAIN;
2711 LoadScore(level_nr);
2713 if (strcmp(setup.player_name, EMPTY_PLAYER_NAME) == 0 ||
2714 local_player->score < highscore[MAX_SCORE_ENTRIES - 1].Score)
2717 for (k = 0; k < MAX_SCORE_ENTRIES; k++)
2719 if (local_player->score > highscore[k].Score)
2721 /* player has made it to the hall of fame */
2723 if (k < MAX_SCORE_ENTRIES - 1)
2725 int m = MAX_SCORE_ENTRIES - 1;
2728 for (l = k; l < MAX_SCORE_ENTRIES; l++)
2729 if (!strcmp(setup.player_name, highscore[l].Name))
2731 if (m == k) /* player's new highscore overwrites his old one */
2735 for (l = m; l > k; l--)
2737 strcpy(highscore[l].Name, highscore[l - 1].Name);
2738 highscore[l].Score = highscore[l - 1].Score;
2745 strncpy(highscore[k].Name, setup.player_name, MAX_PLAYER_NAME_LEN);
2746 highscore[k].Name[MAX_PLAYER_NAME_LEN] = '\0';
2747 highscore[k].Score = local_player->score;
2753 else if (!strncmp(setup.player_name, highscore[k].Name,
2754 MAX_PLAYER_NAME_LEN))
2755 break; /* player already there with a higher score */
2761 SaveScore(level_nr);
2766 inline static int getElementMoveStepsize(int x, int y)
2768 int element = Feld[x][y];
2769 int direction = MovDir[x][y];
2770 int dx = (direction == MV_LEFT ? -1 : direction == MV_RIGHT ? +1 : 0);
2771 int dy = (direction == MV_UP ? -1 : direction == MV_DOWN ? +1 : 0);
2772 int horiz_move = (dx != 0);
2773 int sign = (horiz_move ? dx : dy);
2774 int step = sign * element_info[element].move_stepsize;
2776 /* special values for move stepsize for spring and things on conveyor belt */
2780 if (element == EL_SPRING)
2781 step = sign * MOVE_STEPSIZE_NORMAL * 2;
2782 else if (CAN_FALL(element) && !CAN_MOVE(element) &&
2783 y < lev_fieldy - 1 && IS_BELT_ACTIVE(Feld[x][y + 1]))
2784 step = sign * MOVE_STEPSIZE_NORMAL / 2;
2786 if (CAN_FALL(element) &&
2787 y < lev_fieldy - 1 && IS_BELT_ACTIVE(Feld[x][y + 1]))
2788 step = sign * MOVE_STEPSIZE_NORMAL / 2;
2789 else if (element == EL_SPRING)
2790 step = sign * MOVE_STEPSIZE_NORMAL * 2;
2797 void InitPlayerGfxAnimation(struct PlayerInfo *player, int action, int dir)
2799 if (player->GfxAction != action || player->GfxDir != dir)
2802 printf("Player frame reset! (%d => %d, %d => %d)\n",
2803 player->GfxAction, action, player->GfxDir, dir);
2806 player->GfxAction = action;
2807 player->GfxDir = dir;
2809 player->StepFrame = 0;
2813 static void ResetRandomAnimationValue(int x, int y)
2815 GfxRandom[x][y] = INIT_GFX_RANDOM();
2818 static void ResetGfxAnimation(int x, int y)
2821 int element, graphic;
2825 GfxAction[x][y] = ACTION_DEFAULT;
2826 GfxDir[x][y] = MovDir[x][y];
2829 element = Feld[x][y];
2830 graphic = el_act_dir2img(element, GfxAction[x][y], GfxDir[x][y]);
2832 if (graphic_info[graphic].anim_global_sync)
2833 GfxFrame[x][y] = FrameCounter;
2834 else if (ANIM_MODE(graphic) == ANIM_CE_VALUE)
2835 GfxFrame[x][y] = CustomValue[x][y];
2836 else if (ANIM_MODE(graphic) == ANIM_CE_SCORE)
2837 GfxFrame[x][y] = element_info[element].collect_score;
2841 void InitMovingField(int x, int y, int direction)
2843 int element = Feld[x][y];
2847 int dx = (direction == MV_LEFT ? -1 : direction == MV_RIGHT ? +1 : 0);
2848 int dy = (direction == MV_UP ? -1 : direction == MV_DOWN ? +1 : 0);
2852 if (!WasJustMoving[x][y] || direction != MovDir[x][y])
2853 ResetGfxAnimation(x, y);
2855 MovDir[x][y] = direction;
2856 GfxDir[x][y] = direction;
2857 GfxAction[x][y] = (direction == MV_DOWN && CAN_FALL(element) ?
2858 ACTION_FALLING : ACTION_MOVING);
2861 graphic = el_act_dir2img(element, GfxAction[x][y], GfxDir[x][y]);
2863 if (graphic_info[graphic].anim_global_sync)
2864 GfxFrame[x][y] = FrameCounter;
2865 else if (ANIM_MODE(graphic) == ANIM_CE_VALUE)
2866 GfxFrame[x][y] = CustomValue[x][y];
2867 else if (ANIM_MODE(graphic) == ANIM_CE_SCORE)
2868 GfxFrame[x][y] = element_info[element].collect_score;
2871 /* this is needed for CEs with property "can move" / "not moving" */
2873 if (getElementMoveStepsize(x, y) != 0) /* moving or being moved */
2875 if (Feld[newx][newy] == EL_EMPTY)
2876 Feld[newx][newy] = EL_BLOCKED;
2878 MovDir[newx][newy] = MovDir[x][y];
2880 #if USE_NEW_CUSTOM_VALUE
2881 CustomValue[newx][newy] = CustomValue[x][y];
2884 GfxFrame[newx][newy] = GfxFrame[x][y];
2885 GfxRandom[newx][newy] = GfxRandom[x][y];
2886 GfxAction[newx][newy] = GfxAction[x][y];
2887 GfxDir[newx][newy] = GfxDir[x][y];
2891 void Moving2Blocked(int x, int y, int *goes_to_x, int *goes_to_y)
2893 int direction = MovDir[x][y];
2895 int newx = x + (direction & MV_LEFT ? -1 : direction & MV_RIGHT ? +1 : 0);
2896 int newy = y + (direction & MV_UP ? -1 : direction & MV_DOWN ? +1 : 0);
2898 int newx = x + (direction == MV_LEFT ? -1 : direction == MV_RIGHT ? +1 : 0);
2899 int newy = y + (direction == MV_UP ? -1 : direction == MV_DOWN ? +1 : 0);
2906 void Blocked2Moving(int x, int y, int *comes_from_x, int *comes_from_y)
2908 int oldx = x, oldy = y;
2909 int direction = MovDir[x][y];
2911 if (direction == MV_LEFT)
2913 else if (direction == MV_RIGHT)
2915 else if (direction == MV_UP)
2917 else if (direction == MV_DOWN)
2920 *comes_from_x = oldx;
2921 *comes_from_y = oldy;
2924 int MovingOrBlocked2Element(int x, int y)
2926 int element = Feld[x][y];
2928 if (element == EL_BLOCKED)
2932 Blocked2Moving(x, y, &oldx, &oldy);
2933 return Feld[oldx][oldy];
2939 static int MovingOrBlocked2ElementIfNotLeaving(int x, int y)
2941 /* like MovingOrBlocked2Element(), but if element is moving
2942 and (x,y) is the field the moving element is just leaving,
2943 return EL_BLOCKED instead of the element value */
2944 int element = Feld[x][y];
2946 if (IS_MOVING(x, y))
2948 if (element == EL_BLOCKED)
2952 Blocked2Moving(x, y, &oldx, &oldy);
2953 return Feld[oldx][oldy];
2962 static void RemoveField(int x, int y)
2964 Feld[x][y] = EL_EMPTY;
2970 #if USE_NEW_CUSTOM_VALUE
2971 CustomValue[x][y] = 0;
2975 ChangeDelay[x][y] = 0;
2976 ChangePage[x][y] = -1;
2977 Pushed[x][y] = FALSE;
2980 ExplodeField[x][y] = EX_TYPE_NONE;
2983 GfxElement[x][y] = EL_UNDEFINED;
2984 GfxAction[x][y] = ACTION_DEFAULT;
2985 GfxDir[x][y] = MV_NONE;
2988 void RemoveMovingField(int x, int y)
2990 int oldx = x, oldy = y, newx = x, newy = y;
2991 int element = Feld[x][y];
2992 int next_element = EL_UNDEFINED;
2994 if (element != EL_BLOCKED && !IS_MOVING(x, y))
2997 if (IS_MOVING(x, y))
2999 Moving2Blocked(x, y, &newx, &newy);
3001 if (Feld[newx][newy] != EL_BLOCKED)
3003 /* element is moving, but target field is not free (blocked), but
3004 already occupied by something different (example: acid pool);
3005 in this case, only remove the moving field, but not the target */
3007 RemoveField(oldx, oldy);
3009 Store[oldx][oldy] = Store2[oldx][oldy] = 0;
3011 DrawLevelField(oldx, oldy);
3016 else if (element == EL_BLOCKED)
3018 Blocked2Moving(x, y, &oldx, &oldy);
3019 if (!IS_MOVING(oldx, oldy))
3023 if (element == EL_BLOCKED &&
3024 (Feld[oldx][oldy] == EL_QUICKSAND_EMPTYING ||
3025 Feld[oldx][oldy] == EL_MAGIC_WALL_EMPTYING ||
3026 Feld[oldx][oldy] == EL_BD_MAGIC_WALL_EMPTYING ||
3027 Feld[oldx][oldy] == EL_AMOEBA_DROPPING))
3028 next_element = get_next_element(Feld[oldx][oldy]);
3030 RemoveField(oldx, oldy);
3031 RemoveField(newx, newy);
3033 Store[oldx][oldy] = Store2[oldx][oldy] = 0;
3035 if (next_element != EL_UNDEFINED)
3036 Feld[oldx][oldy] = next_element;
3038 DrawLevelField(oldx, oldy);
3039 DrawLevelField(newx, newy);
3042 void DrawDynamite(int x, int y)
3044 int sx = SCREENX(x), sy = SCREENY(y);
3045 int graphic = el2img(Feld[x][y]);
3048 if (!IN_SCR_FIELD(sx, sy) || IS_PLAYER(x, y))
3051 if (IS_WALKABLE_INSIDE(Back[x][y]))
3055 DrawGraphic(sx, sy, el2img(Back[x][y]), 0);
3056 else if (Store[x][y])
3057 DrawGraphic(sx, sy, el2img(Store[x][y]), 0);
3059 frame = getGraphicAnimationFrame(graphic, GfxFrame[x][y]);
3061 if (Back[x][y] || Store[x][y])
3062 DrawGraphicThruMask(sx, sy, graphic, frame);
3064 DrawGraphic(sx, sy, graphic, frame);
3067 void CheckDynamite(int x, int y)
3069 if (MovDelay[x][y] != 0) /* dynamite is still waiting to explode */
3073 if (MovDelay[x][y] != 0)
3076 PlayLevelSoundActionIfLoop(x, y, ACTION_ACTIVE);
3082 StopLevelSoundActionIfLoop(x, y, ACTION_ACTIVE);
3087 void DrawRelocatePlayer(struct PlayerInfo *player)
3089 boolean ffwd_delay = (tape.playing && tape.fast_forward);
3090 boolean no_delay = (tape.warp_forward);
3091 int frame_delay_value = (ffwd_delay ? FfwdFrameDelay : GameFrameDelay);
3092 int wait_delay_value = (no_delay ? 0 : frame_delay_value);
3093 int jx = player->jx;
3094 int jy = player->jy;
3096 if (level.instant_relocation)
3098 int offset = (setup.scroll_delay ? 3 : 0);
3100 if (!IN_VIS_FIELD(SCREENX(jx), SCREENY(jy)))
3102 scroll_x = (local_player->jx < SBX_Left + MIDPOSX ? SBX_Left :
3103 local_player->jx > SBX_Right + MIDPOSX ? SBX_Right :
3104 local_player->jx - MIDPOSX);
3106 scroll_y = (local_player->jy < SBY_Upper + MIDPOSY ? SBY_Upper :
3107 local_player->jy > SBY_Lower + MIDPOSY ? SBY_Lower :
3108 local_player->jy - MIDPOSY);
3112 if ((player->MovDir == MV_LEFT && scroll_x > jx - MIDPOSX + offset) ||
3113 (player->MovDir == MV_RIGHT && scroll_x < jx - MIDPOSX - offset))
3114 scroll_x = jx - MIDPOSX + (scroll_x < jx-MIDPOSX ? -offset : +offset);
3116 if ((player->MovDir == MV_UP && scroll_y > jy - MIDPOSY + offset) ||
3117 (player->MovDir == MV_DOWN && scroll_y < jy - MIDPOSY - offset))
3118 scroll_y = jy - MIDPOSY + (scroll_y < jy-MIDPOSY ? -offset : +offset);
3120 /* don't scroll over playfield boundaries */
3121 if (scroll_x < SBX_Left || scroll_x > SBX_Right)
3122 scroll_x = (scroll_x < SBX_Left ? SBX_Left : SBX_Right);
3124 /* don't scroll over playfield boundaries */
3125 if (scroll_y < SBY_Upper || scroll_y > SBY_Lower)
3126 scroll_y = (scroll_y < SBY_Upper ? SBY_Upper : SBY_Lower);
3129 RedrawPlayfield(TRUE, 0,0,0,0);
3133 int scroll_xx = -999, scroll_yy = -999;
3135 ScrollScreen(NULL, SCROLL_GO_ON); /* scroll last frame to full tile */
3137 while (scroll_xx != scroll_x || scroll_yy != scroll_y)
3140 int fx = FX, fy = FY;
3142 scroll_xx = (local_player->jx < SBX_Left + MIDPOSX ? SBX_Left :
3143 local_player->jx > SBX_Right + MIDPOSX ? SBX_Right :
3144 local_player->jx - MIDPOSX);
3146 scroll_yy = (local_player->jy < SBY_Upper + MIDPOSY ? SBY_Upper :
3147 local_player->jy > SBY_Lower + MIDPOSY ? SBY_Lower :
3148 local_player->jy - MIDPOSY);
3150 dx = (scroll_xx < scroll_x ? +1 : scroll_xx > scroll_x ? -1 : 0);
3151 dy = (scroll_yy < scroll_y ? +1 : scroll_yy > scroll_y ? -1 : 0);
3153 if (dx == 0 && dy == 0) /* no scrolling needed at all */
3159 fx += dx * TILEX / 2;
3160 fy += dy * TILEY / 2;
3162 ScrollLevel(dx, dy);
3165 /* scroll in two steps of half tile size to make things smoother */
3166 BlitBitmap(drawto_field, window, fx, fy, SXSIZE, SYSIZE, SX, SY);
3168 Delay(wait_delay_value);
3170 /* scroll second step to align at full tile size */
3172 Delay(wait_delay_value);
3177 Delay(wait_delay_value);
3181 void RelocatePlayer(int jx, int jy, int el_player_raw)
3183 int el_player = GET_PLAYER_ELEMENT(el_player_raw);
3184 int player_nr = GET_PLAYER_NR(el_player);
3185 struct PlayerInfo *player = &stored_player[player_nr];
3186 boolean ffwd_delay = (tape.playing && tape.fast_forward);
3187 boolean no_delay = (tape.warp_forward);
3188 int frame_delay_value = (ffwd_delay ? FfwdFrameDelay : GameFrameDelay);
3189 int wait_delay_value = (no_delay ? 0 : frame_delay_value);
3190 int old_jx = player->jx;
3191 int old_jy = player->jy;
3192 int old_element = Feld[old_jx][old_jy];
3193 int element = Feld[jx][jy];
3194 boolean player_relocated = (old_jx != jx || old_jy != jy);
3196 int move_dir_horiz = (jx < old_jx ? MV_LEFT : jx > old_jx ? MV_RIGHT : 0);
3197 int move_dir_vert = (jy < old_jy ? MV_UP : jy > old_jy ? MV_DOWN : 0);
3198 int enter_side_horiz = MV_DIR_OPPOSITE(move_dir_horiz);
3199 int enter_side_vert = MV_DIR_OPPOSITE(move_dir_vert);
3200 int leave_side_horiz = move_dir_horiz;
3201 int leave_side_vert = move_dir_vert;
3202 int enter_side = enter_side_horiz | enter_side_vert;
3203 int leave_side = leave_side_horiz | leave_side_vert;
3205 if (player->GameOver) /* do not reanimate dead player */
3208 if (!player_relocated) /* no need to relocate the player */
3211 if (IS_PLAYER(jx, jy)) /* player already placed at new position */
3213 RemoveField(jx, jy); /* temporarily remove newly placed player */
3214 DrawLevelField(jx, jy);
3217 if (player->present)
3219 while (player->MovPos)
3221 ScrollPlayer(player, SCROLL_GO_ON);
3222 ScrollScreen(NULL, SCROLL_GO_ON);
3224 AdvanceFrameAndPlayerCounters(player->index_nr);
3229 Delay(wait_delay_value);
3232 DrawPlayer(player); /* needed here only to cleanup last field */
3233 DrawLevelField(player->jx, player->jy); /* remove player graphic */
3235 player->is_moving = FALSE;
3238 if (IS_CUSTOM_ELEMENT(old_element))
3239 CheckElementChangeByPlayer(old_jx, old_jy, old_element,
3241 player->index_bit, leave_side);
3243 CheckTriggeredElementChangeByPlayer(old_jx, old_jy, old_element,
3245 player->index_bit, leave_side);
3247 Feld[jx][jy] = el_player;
3248 InitPlayerField(jx, jy, el_player, TRUE);
3250 if (!ELEM_IS_PLAYER(element)) /* player may be set on walkable element */
3252 Feld[jx][jy] = element;
3253 InitField(jx, jy, FALSE);
3256 if (player == local_player) /* only visually relocate local player */
3257 DrawRelocatePlayer(player);
3259 TestIfPlayerTouchesBadThing(jx, jy);
3260 TestIfPlayerTouchesCustomElement(jx, jy);
3262 if (IS_CUSTOM_ELEMENT(element))
3263 CheckElementChangeByPlayer(jx, jy, element, CE_ENTERED_BY_PLAYER,
3264 player->index_bit, enter_side);
3266 CheckTriggeredElementChangeByPlayer(jx, jy, element, CE_PLAYER_ENTERS_X,
3267 player->index_bit, enter_side);
3270 void Explode(int ex, int ey, int phase, int mode)
3276 /* !!! eliminate this variable !!! */
3277 int delay = (game.emulation == EMU_SUPAPLEX ? 3 : 2);
3279 if (game.explosions_delayed)
3281 ExplodeField[ex][ey] = mode;
3285 if (phase == EX_PHASE_START) /* initialize 'Store[][]' field */
3287 int center_element = Feld[ex][ey];
3288 int artwork_element, explosion_element; /* set these values later */
3291 /* --- This is only really needed (and now handled) in "Impact()". --- */
3292 /* do not explode moving elements that left the explode field in time */
3293 if (game.engine_version >= VERSION_IDENT(2,2,0,7) &&
3294 center_element == EL_EMPTY &&
3295 (mode == EX_TYPE_NORMAL || mode == EX_TYPE_CENTER))
3300 /* !!! at this place, the center element may be EL_BLOCKED !!! */
3301 if (mode == EX_TYPE_NORMAL ||
3302 mode == EX_TYPE_CENTER ||
3303 mode == EX_TYPE_CROSS)
3304 PlayLevelSoundElementAction(ex, ey, artwork_element, ACTION_EXPLODING);
3307 /* remove things displayed in background while burning dynamite */
3308 if (Back[ex][ey] != EL_EMPTY && !IS_INDESTRUCTIBLE(Back[ex][ey]))
3311 if (IS_MOVING(ex, ey) || IS_BLOCKED(ex, ey))
3313 /* put moving element to center field (and let it explode there) */
3314 center_element = MovingOrBlocked2Element(ex, ey);
3315 RemoveMovingField(ex, ey);
3316 Feld[ex][ey] = center_element;
3319 /* now "center_element" is finally determined -- set related values now */
3320 artwork_element = center_element; /* for custom player artwork */
3321 explosion_element = center_element; /* for custom player artwork */
3323 if (IS_PLAYER(ex, ey))
3325 int player_nr = GET_PLAYER_NR(StorePlayer[ex][ey]);
3327 artwork_element = stored_player[player_nr].artwork_element;
3329 if (level.use_explosion_element[player_nr])
3331 explosion_element = level.explosion_element[player_nr];
3332 artwork_element = explosion_element;
3337 if (mode == EX_TYPE_NORMAL ||
3338 mode == EX_TYPE_CENTER ||
3339 mode == EX_TYPE_CROSS)
3340 PlayLevelSoundElementAction(ex, ey, artwork_element, ACTION_EXPLODING);
3344 last_phase = element_info[explosion_element].explosion_delay + 1;
3346 last_phase = element_info[center_element].explosion_delay + 1;
3349 for (y = ey - 1; y <= ey + 1; y++) for (x = ex - 1; x <= ex + 1; x++)
3351 int xx = x - ex + 1;
3352 int yy = y - ey + 1;
3355 if (!IN_LEV_FIELD(x, y) ||
3356 (mode & EX_TYPE_SINGLE_TILE && (x != ex || y != ey)) ||
3357 (mode == EX_TYPE_CROSS && (x != ex && y != ey)))
3360 element = Feld[x][y];
3362 if (IS_MOVING(x, y) || IS_BLOCKED(x, y))
3364 element = MovingOrBlocked2Element(x, y);
3366 if (!IS_EXPLOSION_PROOF(element))
3367 RemoveMovingField(x, y);
3370 /* indestructible elements can only explode in center (but not flames) */
3371 if ((IS_EXPLOSION_PROOF(element) && (x != ex || y != ey ||
3372 mode == EX_TYPE_BORDER)) ||
3373 element == EL_FLAMES)
3376 /* no idea why this was changed from 3.0.8 to 3.1.0 -- this causes buggy
3377 behaviour, for example when touching a yamyam that explodes to rocks
3378 with active deadly shield, a rock is created under the player !!! */
3379 /* (case 1 (surely buggy): >= 3.1.0, case 2 (maybe buggy): <= 3.0.8) */
3381 if (IS_PLAYER(x, y) && SHIELD_ON(PLAYERINFO(x, y)) &&
3382 (game.engine_version < VERSION_IDENT(3,1,0,0) ||
3383 (x == ex && y == ey && mode != EX_TYPE_BORDER)))
3385 if (IS_PLAYER(x, y) && SHIELD_ON(PLAYERINFO(x, y)))
3388 if (IS_ACTIVE_BOMB(element))
3390 /* re-activate things under the bomb like gate or penguin */
3391 Feld[x][y] = (Back[x][y] ? Back[x][y] : EL_EMPTY);
3398 /* save walkable background elements while explosion on same tile */
3399 if (IS_WALKABLE(element) && IS_INDESTRUCTIBLE(element) &&
3400 (x != ex || y != ey || mode == EX_TYPE_BORDER))
3401 Back[x][y] = element;
3403 /* ignite explodable elements reached by other explosion */
3404 if (element == EL_EXPLOSION)
3405 element = Store2[x][y];
3407 if (AmoebaNr[x][y] &&
3408 (element == EL_AMOEBA_FULL ||
3409 element == EL_BD_AMOEBA ||
3410 element == EL_AMOEBA_GROWING))
3412 AmoebaCnt[AmoebaNr[x][y]]--;
3413 AmoebaCnt2[AmoebaNr[x][y]]--;
3418 if (IS_PLAYER(ex, ey) && !PLAYER_EXPLOSION_PROTECTED(ex, ey))
3421 int player_nr = StorePlayer[ex][ey] - EL_PLAYER_1;
3423 Store[x][y] = EL_PLAYER_IS_EXPLODING_1 + player_nr;
3425 switch(StorePlayer[ex][ey])
3428 Store[x][y] = EL_PLAYER_IS_EXPLODING_2;
3431 Store[x][y] = EL_PLAYER_IS_EXPLODING_3;
3434 Store[x][y] = EL_PLAYER_IS_EXPLODING_4;
3438 Store[x][y] = EL_PLAYER_IS_EXPLODING_1;
3443 if (PLAYERINFO(ex, ey)->use_murphy)
3444 Store[x][y] = EL_EMPTY;
3447 /* !!! check this case -- currently needed for rnd_rado_negundo_v,
3448 !!! levels 015 018 019 020 021 022 023 026 027 028 !!! */
3449 else if (ELEM_IS_PLAYER(center_element))
3450 Store[x][y] = EL_EMPTY;
3451 else if (center_element == EL_YAMYAM)
3452 Store[x][y] = level.yamyam_content[game.yamyam_content_nr].e[xx][yy];
3453 else if (element_info[center_element].content.e[xx][yy] != EL_EMPTY)
3454 Store[x][y] = element_info[center_element].content.e[xx][yy];
3456 /* needed because EL_BD_BUTTERFLY is not defined as "CAN_EXPLODE"
3457 (killing EL_BD_BUTTERFLY with dynamite would result in BD diamond
3458 otherwise) -- FIX THIS !!! */
3459 else if (!CAN_EXPLODE(element) && element != EL_BD_BUTTERFLY)
3460 Store[x][y] = element_info[element].content.e[1][1];
3462 else if (!CAN_EXPLODE(element))
3463 Store[x][y] = element_info[element].content.e[1][1];
3466 Store[x][y] = EL_EMPTY;
3468 else if (center_element == EL_MOLE)
3469 Store[x][y] = EL_EMERALD_RED;
3470 else if (center_element == EL_PENGUIN)
3471 Store[x][y] = EL_EMERALD_PURPLE;
3472 else if (center_element == EL_BUG)
3473 Store[x][y] = ((x == ex && y == ey) ? EL_DIAMOND : EL_EMERALD);
3474 else if (center_element == EL_BD_BUTTERFLY)
3475 Store[x][y] = EL_BD_DIAMOND;
3476 else if (center_element == EL_SP_ELECTRON)
3477 Store[x][y] = EL_SP_INFOTRON;
3478 else if (center_element == EL_AMOEBA_TO_DIAMOND)
3479 Store[x][y] = level.amoeba_content;
3480 else if (center_element == EL_YAMYAM)
3481 Store[x][y] = level.yamyam_content[game.yamyam_content_nr].e[xx][yy];
3482 else if (IS_CUSTOM_ELEMENT(center_element) &&
3483 element_info[center_element].content.e[xx][yy] != EL_EMPTY)
3484 Store[x][y] = element_info[center_element].content.e[xx][yy];
3485 else if (element == EL_WALL_EMERALD)
3486 Store[x][y] = EL_EMERALD;
3487 else if (element == EL_WALL_DIAMOND)
3488 Store[x][y] = EL_DIAMOND;
3489 else if (element == EL_WALL_BD_DIAMOND)
3490 Store[x][y] = EL_BD_DIAMOND;
3491 else if (element == EL_WALL_EMERALD_YELLOW)
3492 Store[x][y] = EL_EMERALD_YELLOW;
3493 else if (element == EL_WALL_EMERALD_RED)
3494 Store[x][y] = EL_EMERALD_RED;
3495 else if (element == EL_WALL_EMERALD_PURPLE)
3496 Store[x][y] = EL_EMERALD_PURPLE;
3497 else if (element == EL_WALL_PEARL)
3498 Store[x][y] = EL_PEARL;
3499 else if (element == EL_WALL_CRYSTAL)
3500 Store[x][y] = EL_CRYSTAL;
3501 else if (IS_CUSTOM_ELEMENT(element) && !CAN_EXPLODE(element))
3502 Store[x][y] = element_info[element].content.e[1][1];
3504 Store[x][y] = EL_EMPTY;
3507 if (x != ex || y != ey || mode == EX_TYPE_BORDER ||
3508 center_element == EL_AMOEBA_TO_DIAMOND)
3509 Store2[x][y] = element;
3511 Feld[x][y] = EL_EXPLOSION;
3512 GfxElement[x][y] = artwork_element;
3514 ExplodePhase[x][y] = 1;
3515 ExplodeDelay[x][y] = last_phase;
3520 if (center_element == EL_YAMYAM)
3521 game.yamyam_content_nr =
3522 (game.yamyam_content_nr + 1) % level.num_yamyam_contents;
3534 GfxFrame[x][y] = 0; /* restart explosion animation */
3536 last_phase = ExplodeDelay[x][y];
3538 ExplodePhase[x][y] = (phase < last_phase ? phase + 1 : 0);
3542 /* activate this even in non-DEBUG version until cause for crash in
3543 getGraphicAnimationFrame() (see below) is found and eliminated */
3548 if (GfxElement[x][y] == EL_UNDEFINED)
3551 printf("Explode(): x = %d, y = %d: GfxElement == EL_UNDEFINED\n", x, y);
3552 printf("Explode(): This should never happen!\n");
3555 GfxElement[x][y] = EL_EMPTY;
3559 border_element = Store2[x][y];
3560 if (IS_PLAYER(x, y) && !PLAYER_EXPLOSION_PROTECTED(x, y))
3561 border_element = StorePlayer[x][y];
3563 if (phase == element_info[border_element].ignition_delay ||
3564 phase == last_phase)
3566 boolean border_explosion = FALSE;
3568 if (IS_PLAYER(x, y) && PLAYERINFO(x, y)->present &&
3569 !PLAYER_EXPLOSION_PROTECTED(x, y))
3571 KillPlayerUnlessExplosionProtected(x, y);
3572 border_explosion = TRUE;
3574 else if (CAN_EXPLODE_BY_EXPLOSION(border_element))
3576 Feld[x][y] = Store2[x][y];
3579 border_explosion = TRUE;
3581 else if (border_element == EL_AMOEBA_TO_DIAMOND)
3583 AmoebeUmwandeln(x, y);
3585 border_explosion = TRUE;
3588 /* if an element just explodes due to another explosion (chain-reaction),
3589 do not immediately end the new explosion when it was the last frame of
3590 the explosion (as it would be done in the following "if"-statement!) */
3591 if (border_explosion && phase == last_phase)
3595 if (phase == last_phase)
3599 element = Feld[x][y] = Store[x][y];
3600 Store[x][y] = Store2[x][y] = 0;
3601 GfxElement[x][y] = EL_UNDEFINED;
3603 /* player can escape from explosions and might therefore be still alive */
3604 if (element >= EL_PLAYER_IS_EXPLODING_1 &&
3605 element <= EL_PLAYER_IS_EXPLODING_4)
3607 int player_nr = element - EL_PLAYER_IS_EXPLODING_1;
3608 int explosion_element = EL_PLAYER_1 + player_nr;
3609 int xx = MIN(MAX(0, x - stored_player[player_nr].jx + 1), 2);
3610 int yy = MIN(MAX(0, y - stored_player[player_nr].jy + 1), 2);
3612 if (level.use_explosion_element[player_nr])
3613 explosion_element = level.explosion_element[player_nr];
3615 Feld[x][y] = (stored_player[player_nr].active ? EL_EMPTY :
3616 element_info[explosion_element].content.e[xx][yy]);
3619 /* restore probably existing indestructible background element */
3620 if (Back[x][y] && IS_INDESTRUCTIBLE(Back[x][y]))
3621 element = Feld[x][y] = Back[x][y];
3624 MovDir[x][y] = MovPos[x][y] = MovDelay[x][y] = 0;
3625 GfxDir[x][y] = MV_NONE;
3626 ChangeDelay[x][y] = 0;
3627 ChangePage[x][y] = -1;
3629 #if USE_NEW_CUSTOM_VALUE
3630 CustomValue[x][y] = 0;
3633 InitField_WithBug2(x, y, FALSE);
3635 DrawLevelField(x, y);
3637 TestIfElementTouchesCustomElement(x, y);
3639 if (GFX_CRUMBLED(element))
3640 DrawLevelFieldCrumbledSandNeighbours(x, y);
3642 if (IS_PLAYER(x, y) && !PLAYERINFO(x, y)->present)
3643 StorePlayer[x][y] = 0;
3645 if (ELEM_IS_PLAYER(element))
3646 RelocatePlayer(x, y, element);
3648 else if (IN_SCR_FIELD(SCREENX(x), SCREENY(y)))
3650 int graphic = el_act2img(GfxElement[x][y], ACTION_EXPLODING);
3651 int frame = getGraphicAnimationFrame(graphic, GfxFrame[x][y]);
3654 DrawLevelFieldCrumbledSand(x, y);
3656 if (IS_WALKABLE_OVER(Back[x][y]) && Back[x][y] != EL_EMPTY)
3658 DrawLevelElement(x, y, Back[x][y]);
3659 DrawGraphicThruMask(SCREENX(x), SCREENY(y), graphic, frame);
3661 else if (IS_WALKABLE_UNDER(Back[x][y]))
3663 DrawGraphic(SCREENX(x), SCREENY(y), graphic, frame);
3664 DrawLevelElementThruMask(x, y, Back[x][y]);
3666 else if (!IS_WALKABLE_INSIDE(Back[x][y]))
3667 DrawGraphic(SCREENX(x), SCREENY(y), graphic, frame);
3671 void DynaExplode(int ex, int ey)
3674 int dynabomb_element = Feld[ex][ey];
3675 int dynabomb_size = 1;
3676 boolean dynabomb_xl = FALSE;
3677 struct PlayerInfo *player;
3678 static int xy[4][2] =
3686 if (IS_ACTIVE_BOMB(dynabomb_element))
3688 player = &stored_player[dynabomb_element - EL_DYNABOMB_PLAYER_1_ACTIVE];
3689 dynabomb_size = player->dynabomb_size;
3690 dynabomb_xl = player->dynabomb_xl;
3691 player->dynabombs_left++;
3694 Explode(ex, ey, EX_PHASE_START, EX_TYPE_CENTER);
3696 for (i = 0; i < NUM_DIRECTIONS; i++)
3698 for (j = 1; j <= dynabomb_size; j++)
3700 int x = ex + j * xy[i][0];
3701 int y = ey + j * xy[i][1];
3704 if (!IN_LEV_FIELD(x, y) || IS_INDESTRUCTIBLE(Feld[x][y]))
3707 element = Feld[x][y];
3709 /* do not restart explosions of fields with active bombs */
3710 if (element == EL_EXPLOSION && IS_ACTIVE_BOMB(Store2[x][y]))
3713 Explode(x, y, EX_PHASE_START, EX_TYPE_BORDER);
3715 if (element != EL_EMPTY && element != EL_EXPLOSION &&
3716 !IS_DIGGABLE(element) && !dynabomb_xl)
3722 void Bang(int x, int y)
3724 int element = MovingOrBlocked2Element(x, y);
3725 int explosion_type = EX_TYPE_NORMAL;
3727 if (IS_PLAYER(x, y) && !PLAYER_EXPLOSION_PROTECTED(x, y))
3729 struct PlayerInfo *player = PLAYERINFO(x, y);
3731 element = Feld[x][y] = (player->use_murphy ? EL_SP_MURPHY :
3732 player->element_nr);
3734 if (level.use_explosion_element[player->index_nr])
3736 int explosion_element = level.explosion_element[player->index_nr];
3738 if (element_info[explosion_element].explosion_type == EXPLODES_CROSS)
3739 explosion_type = EX_TYPE_CROSS;
3740 else if (element_info[explosion_element].explosion_type == EXPLODES_1X1)
3741 explosion_type = EX_TYPE_CENTER;
3749 case EL_BD_BUTTERFLY:
3752 case EL_DARK_YAMYAM:
3756 RaiseScoreElement(element);
3759 case EL_DYNABOMB_PLAYER_1_ACTIVE:
3760 case EL_DYNABOMB_PLAYER_2_ACTIVE:
3761 case EL_DYNABOMB_PLAYER_3_ACTIVE:
3762 case EL_DYNABOMB_PLAYER_4_ACTIVE:
3763 case EL_DYNABOMB_INCREASE_NUMBER:
3764 case EL_DYNABOMB_INCREASE_SIZE:
3765 case EL_DYNABOMB_INCREASE_POWER:
3766 explosion_type = EX_TYPE_DYNA;
3771 case EL_LAMP_ACTIVE:
3772 case EL_AMOEBA_TO_DIAMOND:
3773 if (!IS_PLAYER(x, y)) /* penguin and player may be at same field */
3774 explosion_type = EX_TYPE_CENTER;
3778 if (element_info[element].explosion_type == EXPLODES_CROSS)
3779 explosion_type = EX_TYPE_CROSS;
3780 else if (element_info[element].explosion_type == EXPLODES_1X1)
3781 explosion_type = EX_TYPE_CENTER;
3785 if (explosion_type == EX_TYPE_DYNA)
3788 Explode(x, y, EX_PHASE_START, explosion_type);
3790 CheckTriggeredElementChange(x, y, element, CE_EXPLOSION_OF_X);
3793 void SplashAcid(int x, int y)
3795 if (IN_LEV_FIELD(x - 1, y - 1) && IS_FREE(x - 1, y - 1) &&
3796 (!IN_LEV_FIELD(x - 1, y - 2) ||
3797 !CAN_FALL(MovingOrBlocked2Element(x - 1, y - 2))))
3798 Feld[x - 1][y - 1] = EL_ACID_SPLASH_LEFT;
3800 if (IN_LEV_FIELD(x + 1, y - 1) && IS_FREE(x + 1, y - 1) &&
3801 (!IN_LEV_FIELD(x + 1, y - 2) ||
3802 !CAN_FALL(MovingOrBlocked2Element(x + 1, y - 2))))
3803 Feld[x + 1][y - 1] = EL_ACID_SPLASH_RIGHT;
3805 PlayLevelSound(x, y, SND_ACID_SPLASHING);
3808 static void InitBeltMovement()
3810 static int belt_base_element[4] =
3812 EL_CONVEYOR_BELT_1_LEFT,
3813 EL_CONVEYOR_BELT_2_LEFT,
3814 EL_CONVEYOR_BELT_3_LEFT,
3815 EL_CONVEYOR_BELT_4_LEFT
3817 static int belt_base_active_element[4] =
3819 EL_CONVEYOR_BELT_1_LEFT_ACTIVE,
3820 EL_CONVEYOR_BELT_2_LEFT_ACTIVE,
3821 EL_CONVEYOR_BELT_3_LEFT_ACTIVE,
3822 EL_CONVEYOR_BELT_4_LEFT_ACTIVE
3827 /* set frame order for belt animation graphic according to belt direction */
3828 for (i = 0; i < NUM_BELTS; i++)
3832 for (j = 0; j < NUM_BELT_PARTS; j++)
3834 int element = belt_base_active_element[belt_nr] + j;
3835 int graphic = el2img(element);
3837 if (game.belt_dir[i] == MV_LEFT)
3838 graphic_info[graphic].anim_mode &= ~ANIM_REVERSE;
3840 graphic_info[graphic].anim_mode |= ANIM_REVERSE;
3845 SCAN_PLAYFIELD(x, y)
3847 for (y = 0; y < lev_fieldy; y++) for (x = 0; x < lev_fieldx; x++)
3850 int element = Feld[x][y];
3852 for (i = 0; i < NUM_BELTS; i++)
3854 if (IS_BELT(element) && game.belt_dir[i] != MV_NONE)
3856 int e_belt_nr = getBeltNrFromBeltElement(element);
3859 if (e_belt_nr == belt_nr)
3861 int belt_part = Feld[x][y] - belt_base_element[belt_nr];
3863 Feld[x][y] = belt_base_active_element[belt_nr] + belt_part;
3870 static void ToggleBeltSwitch(int x, int y)
3872 static int belt_base_element[4] =
3874 EL_CONVEYOR_BELT_1_LEFT,
3875 EL_CONVEYOR_BELT_2_LEFT,
3876 EL_CONVEYOR_BELT_3_LEFT,
3877 EL_CONVEYOR_BELT_4_LEFT
3879 static int belt_base_active_element[4] =
3881 EL_CONVEYOR_BELT_1_LEFT_ACTIVE,
3882 EL_CONVEYOR_BELT_2_LEFT_ACTIVE,
3883 EL_CONVEYOR_BELT_3_LEFT_ACTIVE,
3884 EL_CONVEYOR_BELT_4_LEFT_ACTIVE
3886 static int belt_base_switch_element[4] =
3888 EL_CONVEYOR_BELT_1_SWITCH_LEFT,
3889 EL_CONVEYOR_BELT_2_SWITCH_LEFT,
3890 EL_CONVEYOR_BELT_3_SWITCH_LEFT,
3891 EL_CONVEYOR_BELT_4_SWITCH_LEFT
3893 static int belt_move_dir[4] =
3901 int element = Feld[x][y];
3902 int belt_nr = getBeltNrFromBeltSwitchElement(element);
3903 int belt_dir_nr = (game.belt_dir_nr[belt_nr] + 1) % 4;
3904 int belt_dir = belt_move_dir[belt_dir_nr];
3907 if (!IS_BELT_SWITCH(element))
3910 game.belt_dir_nr[belt_nr] = belt_dir_nr;
3911 game.belt_dir[belt_nr] = belt_dir;
3913 if (belt_dir_nr == 3)
3916 /* set frame order for belt animation graphic according to belt direction */
3917 for (i = 0; i < NUM_BELT_PARTS; i++)
3919 int element = belt_base_active_element[belt_nr] + i;
3920 int graphic = el2img(element);
3922 if (belt_dir == MV_LEFT)
3923 graphic_info[graphic].anim_mode &= ~ANIM_REVERSE;
3925 graphic_info[graphic].anim_mode |= ANIM_REVERSE;
3929 SCAN_PLAYFIELD(xx, yy)
3931 for (yy = 0; yy < lev_fieldy; yy++) for (xx = 0; xx < lev_fieldx; xx++)
3934 int element = Feld[xx][yy];
3936 if (IS_BELT_SWITCH(element))
3938 int e_belt_nr = getBeltNrFromBeltSwitchElement(element);
3940 if (e_belt_nr == belt_nr)
3942 Feld[xx][yy] = belt_base_switch_element[belt_nr] + belt_dir_nr;
3943 DrawLevelField(xx, yy);
3946 else if (IS_BELT(element) && belt_dir != MV_NONE)
3948 int e_belt_nr = getBeltNrFromBeltElement(element);
3950 if (e_belt_nr == belt_nr)
3952 int belt_part = Feld[xx][yy] - belt_base_element[belt_nr];
3954 Feld[xx][yy] = belt_base_active_element[belt_nr] + belt_part;
3955 DrawLevelField(xx, yy);
3958 else if (IS_BELT_ACTIVE(element) && belt_dir == MV_NONE)
3960 int e_belt_nr = getBeltNrFromBeltActiveElement(element);
3962 if (e_belt_nr == belt_nr)
3964 int belt_part = Feld[xx][yy] - belt_base_active_element[belt_nr];
3966 Feld[xx][yy] = belt_base_element[belt_nr] + belt_part;
3967 DrawLevelField(xx, yy);
3973 static void ToggleSwitchgateSwitch(int x, int y)
3977 game.switchgate_pos = !game.switchgate_pos;
3980 SCAN_PLAYFIELD(xx, yy)
3982 for (yy = 0; yy < lev_fieldy; yy++) for (xx = 0; xx < lev_fieldx; xx++)
3985 int element = Feld[xx][yy];
3987 if (element == EL_SWITCHGATE_SWITCH_UP ||
3988 element == EL_SWITCHGATE_SWITCH_DOWN)
3990 Feld[xx][yy] = EL_SWITCHGATE_SWITCH_UP + game.switchgate_pos;
3991 DrawLevelField(xx, yy);
3993 else if (element == EL_SWITCHGATE_OPEN ||
3994 element == EL_SWITCHGATE_OPENING)
3996 Feld[xx][yy] = EL_SWITCHGATE_CLOSING;
3998 PlayLevelSoundAction(xx, yy, ACTION_CLOSING);
4000 else if (element == EL_SWITCHGATE_CLOSED ||
4001 element == EL_SWITCHGATE_CLOSING)
4003 Feld[xx][yy] = EL_SWITCHGATE_OPENING;
4005 PlayLevelSoundAction(xx, yy, ACTION_OPENING);
4010 static int getInvisibleActiveFromInvisibleElement(int element)
4012 return (element == EL_INVISIBLE_STEELWALL ? EL_INVISIBLE_STEELWALL_ACTIVE :
4013 element == EL_INVISIBLE_WALL ? EL_INVISIBLE_WALL_ACTIVE :
4014 element == EL_INVISIBLE_SAND ? EL_INVISIBLE_SAND_ACTIVE :
4018 static int getInvisibleFromInvisibleActiveElement(int element)
4020 return (element == EL_INVISIBLE_STEELWALL_ACTIVE ? EL_INVISIBLE_STEELWALL :
4021 element == EL_INVISIBLE_WALL_ACTIVE ? EL_INVISIBLE_WALL :
4022 element == EL_INVISIBLE_SAND_ACTIVE ? EL_INVISIBLE_SAND :
4026 static void RedrawAllLightSwitchesAndInvisibleElements()
4031 SCAN_PLAYFIELD(x, y)
4033 for (y = 0; y < lev_fieldy; y++) for (x = 0; x < lev_fieldx; x++)
4036 int element = Feld[x][y];
4038 if (element == EL_LIGHT_SWITCH &&
4039 game.light_time_left > 0)
4041 Feld[x][y] = EL_LIGHT_SWITCH_ACTIVE;
4042 DrawLevelField(x, y);
4044 else if (element == EL_LIGHT_SWITCH_ACTIVE &&
4045 game.light_time_left == 0)
4047 Feld[x][y] = EL_LIGHT_SWITCH;
4048 DrawLevelField(x, y);
4050 else if (element == EL_EMC_DRIPPER &&
4051 game.light_time_left > 0)
4053 Feld[x][y] = EL_EMC_DRIPPER_ACTIVE;
4054 DrawLevelField(x, y);
4056 else if (element == EL_EMC_DRIPPER_ACTIVE &&
4057 game.light_time_left == 0)
4059 Feld[x][y] = EL_EMC_DRIPPER;
4060 DrawLevelField(x, y);
4062 else if (element == EL_INVISIBLE_STEELWALL ||
4063 element == EL_INVISIBLE_WALL ||
4064 element == EL_INVISIBLE_SAND)
4066 if (game.light_time_left > 0)
4067 Feld[x][y] = getInvisibleActiveFromInvisibleElement(element);
4069 DrawLevelField(x, y);
4071 /* uncrumble neighbour fields, if needed */
4072 if (element == EL_INVISIBLE_SAND)
4073 DrawLevelFieldCrumbledSandNeighbours(x, y);
4075 else if (element == EL_INVISIBLE_STEELWALL_ACTIVE ||
4076 element == EL_INVISIBLE_WALL_ACTIVE ||
4077 element == EL_INVISIBLE_SAND_ACTIVE)
4079 if (game.light_time_left == 0)
4080 Feld[x][y] = getInvisibleFromInvisibleActiveElement(element);
4082 DrawLevelField(x, y);
4084 /* re-crumble neighbour fields, if needed */
4085 if (element == EL_INVISIBLE_SAND)
4086 DrawLevelFieldCrumbledSandNeighbours(x, y);
4091 static void RedrawAllInvisibleElementsForLenses()
4096 SCAN_PLAYFIELD(x, y)
4098 for (y = 0; y < lev_fieldy; y++) for (x = 0; x < lev_fieldx; x++)
4101 int element = Feld[x][y];
4103 if (element == EL_EMC_DRIPPER &&
4104 game.lenses_time_left > 0)
4106 Feld[x][y] = EL_EMC_DRIPPER_ACTIVE;
4107 DrawLevelField(x, y);
4109 else if (element == EL_EMC_DRIPPER_ACTIVE &&
4110 game.lenses_time_left == 0)
4112 Feld[x][y] = EL_EMC_DRIPPER;
4113 DrawLevelField(x, y);
4115 else if (element == EL_INVISIBLE_STEELWALL ||
4116 element == EL_INVISIBLE_WALL ||
4117 element == EL_INVISIBLE_SAND)
4119 if (game.lenses_time_left > 0)
4120 Feld[x][y] = getInvisibleActiveFromInvisibleElement(element);
4122 DrawLevelField(x, y);
4124 /* uncrumble neighbour fields, if needed */
4125 if (element == EL_INVISIBLE_SAND)
4126 DrawLevelFieldCrumbledSandNeighbours(x, y);
4128 else if (element == EL_INVISIBLE_STEELWALL_ACTIVE ||
4129 element == EL_INVISIBLE_WALL_ACTIVE ||
4130 element == EL_INVISIBLE_SAND_ACTIVE)
4132 if (game.lenses_time_left == 0)
4133 Feld[x][y] = getInvisibleFromInvisibleActiveElement(element);
4135 DrawLevelField(x, y);
4137 /* re-crumble neighbour fields, if needed */
4138 if (element == EL_INVISIBLE_SAND)
4139 DrawLevelFieldCrumbledSandNeighbours(x, y);
4144 static void RedrawAllInvisibleElementsForMagnifier()
4149 SCAN_PLAYFIELD(x, y)
4151 for (y = 0; y < lev_fieldy; y++) for (x = 0; x < lev_fieldx; x++)
4154 int element = Feld[x][y];
4156 if (element == EL_EMC_FAKE_GRASS &&
4157 game.magnify_time_left > 0)
4159 Feld[x][y] = EL_EMC_FAKE_GRASS_ACTIVE;
4160 DrawLevelField(x, y);
4162 else if (element == EL_EMC_FAKE_GRASS_ACTIVE &&
4163 game.magnify_time_left == 0)
4165 Feld[x][y] = EL_EMC_FAKE_GRASS;
4166 DrawLevelField(x, y);
4168 else if (IS_GATE_GRAY(element) &&
4169 game.magnify_time_left > 0)
4171 Feld[x][y] = (IS_RND_GATE_GRAY(element) ?
4172 element - EL_GATE_1_GRAY + EL_GATE_1_GRAY_ACTIVE :
4173 IS_EM_GATE_GRAY(element) ?
4174 element - EL_EM_GATE_1_GRAY + EL_EM_GATE_1_GRAY_ACTIVE :
4175 IS_EMC_GATE_GRAY(element) ?
4176 element - EL_EMC_GATE_5_GRAY + EL_EMC_GATE_5_GRAY_ACTIVE :
4178 DrawLevelField(x, y);
4180 else if (IS_GATE_GRAY_ACTIVE(element) &&
4181 game.magnify_time_left == 0)
4183 Feld[x][y] = (IS_RND_GATE_GRAY_ACTIVE(element) ?
4184 element - EL_GATE_1_GRAY_ACTIVE + EL_GATE_1_GRAY :
4185 IS_EM_GATE_GRAY_ACTIVE(element) ?
4186 element - EL_EM_GATE_1_GRAY_ACTIVE + EL_EM_GATE_1_GRAY :
4187 IS_EMC_GATE_GRAY_ACTIVE(element) ?
4188 element - EL_EMC_GATE_5_GRAY_ACTIVE + EL_EMC_GATE_5_GRAY :
4190 DrawLevelField(x, y);
4195 static void ToggleLightSwitch(int x, int y)
4197 int element = Feld[x][y];
4199 game.light_time_left =
4200 (element == EL_LIGHT_SWITCH ?
4201 level.time_light * FRAMES_PER_SECOND : 0);
4203 RedrawAllLightSwitchesAndInvisibleElements();
4206 static void ActivateTimegateSwitch(int x, int y)
4210 game.timegate_time_left = level.time_timegate * FRAMES_PER_SECOND;
4213 SCAN_PLAYFIELD(xx, yy)
4215 for (yy = 0; yy < lev_fieldy; yy++) for (xx = 0; xx < lev_fieldx; xx++)
4218 int element = Feld[xx][yy];
4220 if (element == EL_TIMEGATE_CLOSED ||
4221 element == EL_TIMEGATE_CLOSING)
4223 Feld[xx][yy] = EL_TIMEGATE_OPENING;
4224 PlayLevelSound(xx, yy, SND_TIMEGATE_OPENING);
4228 else if (element == EL_TIMEGATE_SWITCH_ACTIVE)
4230 Feld[xx][yy] = EL_TIMEGATE_SWITCH;
4231 DrawLevelField(xx, yy);
4237 Feld[x][y] = EL_TIMEGATE_SWITCH_ACTIVE;
4240 void Impact(int x, int y)
4242 boolean last_line = (y == lev_fieldy - 1);
4243 boolean object_hit = FALSE;
4244 boolean impact = (last_line || object_hit);
4245 int element = Feld[x][y];
4246 int smashed = EL_STEELWALL;
4248 if (!last_line) /* check if element below was hit */
4250 if (Feld[x][y + 1] == EL_PLAYER_IS_LEAVING)
4253 object_hit = (!IS_FREE(x, y + 1) && (!IS_MOVING(x, y + 1) ||
4254 MovDir[x][y + 1] != MV_DOWN ||
4255 MovPos[x][y + 1] <= TILEY / 2));
4257 /* do not smash moving elements that left the smashed field in time */
4258 if (game.engine_version >= VERSION_IDENT(2,2,0,7) && IS_MOVING(x, y + 1) &&
4259 ABS(MovPos[x][y + 1] + getElementMoveStepsize(x, y + 1)) >= TILEX)
4262 #if USE_QUICKSAND_IMPACT_BUGFIX
4263 if (Feld[x][y + 1] == EL_QUICKSAND_EMPTYING && object_hit == FALSE)
4265 RemoveMovingField(x, y + 1);
4266 Feld[x][y + 1] = EL_QUICKSAND_EMPTY;
4267 Feld[x][y + 2] = EL_ROCK;
4268 DrawLevelField(x, y + 2);
4275 smashed = MovingOrBlocked2Element(x, y + 1);
4277 impact = (last_line || object_hit);
4280 if (!last_line && smashed == EL_ACID) /* element falls into acid */
4282 SplashAcid(x, y + 1);
4286 /* !!! not sufficient for all cases -- see EL_PEARL below !!! */
4287 /* only reset graphic animation if graphic really changes after impact */
4289 el_act_dir2img(element, GfxAction[x][y], MV_DOWN) != el2img(element))
4291 ResetGfxAnimation(x, y);
4292 DrawLevelField(x, y);
4295 if (impact && CAN_EXPLODE_IMPACT(element))
4300 else if (impact && element == EL_PEARL)
4302 ResetGfxAnimation(x, y);
4304 Feld[x][y] = EL_PEARL_BREAKING;
4305 PlayLevelSound(x, y, SND_PEARL_BREAKING);
4308 else if (impact && CheckElementChange(x, y, element, smashed, CE_IMPACT))
4310 PlayLevelSoundElementAction(x, y, element, ACTION_IMPACT);
4315 if (impact && element == EL_AMOEBA_DROP)
4317 if (object_hit && IS_PLAYER(x, y + 1))
4318 KillPlayerUnlessEnemyProtected(x, y + 1);
4319 else if (object_hit && smashed == EL_PENGUIN)
4323 Feld[x][y] = EL_AMOEBA_GROWING;
4324 Store[x][y] = EL_AMOEBA_WET;
4326 ResetRandomAnimationValue(x, y);
4331 if (object_hit) /* check which object was hit */
4333 if (CAN_PASS_MAGIC_WALL(element) &&
4334 (smashed == EL_MAGIC_WALL ||
4335 smashed == EL_BD_MAGIC_WALL))
4338 int activated_magic_wall =
4339 (smashed == EL_MAGIC_WALL ? EL_MAGIC_WALL_ACTIVE :
4340 EL_BD_MAGIC_WALL_ACTIVE);
4342 /* activate magic wall / mill */
4344 SCAN_PLAYFIELD(xx, yy)
4346 for (yy = 0; yy < lev_fieldy; yy++) for (xx = 0; xx < lev_fieldx; xx++)
4348 if (Feld[xx][yy] == smashed)
4349 Feld[xx][yy] = activated_magic_wall;
4351 game.magic_wall_time_left = level.time_magic_wall * FRAMES_PER_SECOND;
4352 game.magic_wall_active = TRUE;
4354 PlayLevelSound(x, y, (smashed == EL_MAGIC_WALL ?
4355 SND_MAGIC_WALL_ACTIVATING :
4356 SND_BD_MAGIC_WALL_ACTIVATING));
4359 if (IS_PLAYER(x, y + 1))
4361 if (CAN_SMASH_PLAYER(element))
4363 KillPlayerUnlessEnemyProtected(x, y + 1);
4367 else if (smashed == EL_PENGUIN)
4369 if (CAN_SMASH_PLAYER(element))
4375 else if (element == EL_BD_DIAMOND)
4377 if (IS_CLASSIC_ENEMY(smashed) && IS_BD_ELEMENT(smashed))
4383 else if (((element == EL_SP_INFOTRON ||
4384 element == EL_SP_ZONK) &&
4385 (smashed == EL_SP_SNIKSNAK ||
4386 smashed == EL_SP_ELECTRON ||
4387 smashed == EL_SP_DISK_ORANGE)) ||
4388 (element == EL_SP_INFOTRON &&
4389 smashed == EL_SP_DISK_YELLOW))
4394 else if (CAN_SMASH_EVERYTHING(element))
4396 if (IS_CLASSIC_ENEMY(smashed) ||
4397 CAN_EXPLODE_SMASHED(smashed))
4402 else if (!IS_MOVING(x, y + 1) && !IS_BLOCKED(x, y + 1))
4404 if (smashed == EL_LAMP ||
4405 smashed == EL_LAMP_ACTIVE)
4410 else if (smashed == EL_NUT)
4412 Feld[x][y + 1] = EL_NUT_BREAKING;
4413 PlayLevelSound(x, y, SND_NUT_BREAKING);
4414 RaiseScoreElement(EL_NUT);
4417 else if (smashed == EL_PEARL)
4419 ResetGfxAnimation(x, y);
4421 Feld[x][y + 1] = EL_PEARL_BREAKING;
4422 PlayLevelSound(x, y, SND_PEARL_BREAKING);
4425 else if (smashed == EL_DIAMOND)
4427 Feld[x][y + 1] = EL_DIAMOND_BREAKING;
4428 PlayLevelSound(x, y, SND_DIAMOND_BREAKING);
4431 else if (IS_BELT_SWITCH(smashed))
4433 ToggleBeltSwitch(x, y + 1);
4435 else if (smashed == EL_SWITCHGATE_SWITCH_UP ||
4436 smashed == EL_SWITCHGATE_SWITCH_DOWN)
4438 ToggleSwitchgateSwitch(x, y + 1);
4440 else if (smashed == EL_LIGHT_SWITCH ||
4441 smashed == EL_LIGHT_SWITCH_ACTIVE)
4443 ToggleLightSwitch(x, y + 1);
4448 TestIfElementSmashesCustomElement(x, y, MV_DOWN);
4451 CheckElementChange(x, y + 1, smashed, element, CE_SMASHED);
4453 CheckElementChangeBySide(x, y + 1, smashed, element,
4454 CE_SWITCHED, CH_SIDE_TOP);
4455 CheckTriggeredElementChangeBySide(x, y + 1, smashed, CE_SWITCH_OF_X,
4461 CheckElementChange(x, y + 1, smashed, element, CE_SMASHED);
4466 /* play sound of magic wall / mill */
4468 (Feld[x][y + 1] == EL_MAGIC_WALL_ACTIVE ||
4469 Feld[x][y + 1] == EL_BD_MAGIC_WALL_ACTIVE))
4471 if (Feld[x][y + 1] == EL_MAGIC_WALL_ACTIVE)
4472 PlayLevelSound(x, y, SND_MAGIC_WALL_FILLING);
4473 else if (Feld[x][y + 1] == EL_BD_MAGIC_WALL_ACTIVE)
4474 PlayLevelSound(x, y, SND_BD_MAGIC_WALL_FILLING);
4479 /* play sound of object that hits the ground */
4480 if (last_line || object_hit)
4481 PlayLevelSoundElementAction(x, y, element, ACTION_IMPACT);
4484 inline static void TurnRoundExt(int x, int y)
4496 { 0, 0 }, { 0, 0 }, { 0, 0 },
4501 int left, right, back;
4505 { MV_DOWN, MV_UP, MV_RIGHT },
4506 { MV_UP, MV_DOWN, MV_LEFT },
4508 { MV_LEFT, MV_RIGHT, MV_DOWN },
4512 { MV_RIGHT, MV_LEFT, MV_UP }
4515 int element = Feld[x][y];
4516 int move_pattern = element_info[element].move_pattern;
4518 int old_move_dir = MovDir[x][y];
4519 int left_dir = turn[old_move_dir].left;
4520 int right_dir = turn[old_move_dir].right;
4521 int back_dir = turn[old_move_dir].back;
4523 int left_dx = move_xy[left_dir].dx, left_dy = move_xy[left_dir].dy;
4524 int right_dx = move_xy[right_dir].dx, right_dy = move_xy[right_dir].dy;
4525 int move_dx = move_xy[old_move_dir].dx, move_dy = move_xy[old_move_dir].dy;
4526 int back_dx = move_xy[back_dir].dx, back_dy = move_xy[back_dir].dy;
4528 int left_x = x + left_dx, left_y = y + left_dy;
4529 int right_x = x + right_dx, right_y = y + right_dy;
4530 int move_x = x + move_dx, move_y = y + move_dy;
4534 if (element == EL_BUG || element == EL_BD_BUTTERFLY)
4536 TestIfBadThingTouchesOtherBadThing(x, y);
4538 if (ENEMY_CAN_ENTER_FIELD(element, right_x, right_y))
4539 MovDir[x][y] = right_dir;
4540 else if (!ENEMY_CAN_ENTER_FIELD(element, move_x, move_y))
4541 MovDir[x][y] = left_dir;
4543 if (element == EL_BUG && MovDir[x][y] != old_move_dir)
4545 else if (element == EL_BD_BUTTERFLY) /* && MovDir[x][y] == left_dir) */
4548 else if (element == EL_SPACESHIP || element == EL_BD_FIREFLY)
4550 TestIfBadThingTouchesOtherBadThing(x, y);
4552 if (ENEMY_CAN_ENTER_FIELD(element, left_x, left_y))
4553 MovDir[x][y] = left_dir;
4554 else if (!ENEMY_CAN_ENTER_FIELD(element, move_x, move_y))
4555 MovDir[x][y] = right_dir;
4557 if (element == EL_SPACESHIP && MovDir[x][y] != old_move_dir)
4559 else if (element == EL_BD_FIREFLY) /* && MovDir[x][y] == right_dir) */
4562 else if (element == EL_SP_SNIKSNAK || element == EL_SP_ELECTRON)
4564 TestIfBadThingTouchesOtherBadThing(x, y);
4566 if (ELEMENT_CAN_ENTER_FIELD_BASE_4(element, left_x, left_y, 0))
4567 MovDir[x][y] = left_dir;
4568 else if (!ELEMENT_CAN_ENTER_FIELD_BASE_4(element, move_x, move_y, 0))
4569 MovDir[x][y] = right_dir;
4571 if (MovDir[x][y] != old_move_dir)
4574 else if (element == EL_YAMYAM)
4576 boolean can_turn_left = YAMYAM_CAN_ENTER_FIELD(element, left_x, left_y);
4577 boolean can_turn_right = YAMYAM_CAN_ENTER_FIELD(element, right_x, right_y);
4579 if (can_turn_left && can_turn_right)
4580 MovDir[x][y] = (RND(3) ? (RND(2) ? left_dir : right_dir) : back_dir);
4581 else if (can_turn_left)
4582 MovDir[x][y] = (RND(2) ? left_dir : back_dir);
4583 else if (can_turn_right)
4584 MovDir[x][y] = (RND(2) ? right_dir : back_dir);
4586 MovDir[x][y] = back_dir;
4588 MovDelay[x][y] = 16 + 16 * RND(3);
4590 else if (element == EL_DARK_YAMYAM)
4592 boolean can_turn_left = DARK_YAMYAM_CAN_ENTER_FIELD(element,
4594 boolean can_turn_right = DARK_YAMYAM_CAN_ENTER_FIELD(element,
4597 if (can_turn_left && can_turn_right)
4598 MovDir[x][y] = (RND(3) ? (RND(2) ? left_dir : right_dir) : back_dir);
4599 else if (can_turn_left)
4600 MovDir[x][y] = (RND(2) ? left_dir : back_dir);
4601 else if (can_turn_right)
4602 MovDir[x][y] = (RND(2) ? right_dir : back_dir);
4604 MovDir[x][y] = back_dir;
4606 MovDelay[x][y] = 16 + 16 * RND(3);
4608 else if (element == EL_PACMAN)
4610 boolean can_turn_left = PACMAN_CAN_ENTER_FIELD(element, left_x, left_y);
4611 boolean can_turn_right = PACMAN_CAN_ENTER_FIELD(element, right_x, right_y);
4613 if (can_turn_left && can_turn_right)
4614 MovDir[x][y] = (RND(3) ? (RND(2) ? left_dir : right_dir) : back_dir);
4615 else if (can_turn_left)
4616 MovDir[x][y] = (RND(2) ? left_dir : back_dir);
4617 else if (can_turn_right)
4618 MovDir[x][y] = (RND(2) ? right_dir : back_dir);
4620 MovDir[x][y] = back_dir;
4622 MovDelay[x][y] = 6 + RND(40);
4624 else if (element == EL_PIG)
4626 boolean can_turn_left = PIG_CAN_ENTER_FIELD(element, left_x, left_y);
4627 boolean can_turn_right = PIG_CAN_ENTER_FIELD(element, right_x, right_y);
4628 boolean can_move_on = PIG_CAN_ENTER_FIELD(element, move_x, move_y);
4629 boolean should_turn_left, should_turn_right, should_move_on;
4631 int rnd = RND(rnd_value);
4633 should_turn_left = (can_turn_left &&
4635 IN_LEV_FIELD_AND_NOT_FREE(x + back_dx + left_dx,
4636 y + back_dy + left_dy)));
4637 should_turn_right = (can_turn_right &&
4639 IN_LEV_FIELD_AND_NOT_FREE(x + back_dx + right_dx,
4640 y + back_dy + right_dy)));
4641 should_move_on = (can_move_on &&
4644 IN_LEV_FIELD_AND_NOT_FREE(x + move_dx + left_dx,
4645 y + move_dy + left_dy) ||
4646 IN_LEV_FIELD_AND_NOT_FREE(x + move_dx + right_dx,
4647 y + move_dy + right_dy)));
4649 if (should_turn_left || should_turn_right || should_move_on)
4651 if (should_turn_left && should_turn_right && should_move_on)
4652 MovDir[x][y] = (rnd < rnd_value / 3 ? left_dir :
4653 rnd < 2 * rnd_value / 3 ? right_dir :
4655 else if (should_turn_left && should_turn_right)
4656 MovDir[x][y] = (rnd < rnd_value / 2 ? left_dir : right_dir);
4657 else if (should_turn_left && should_move_on)
4658 MovDir[x][y] = (rnd < rnd_value / 2 ? left_dir : old_move_dir);
4659 else if (should_turn_right && should_move_on)
4660 MovDir[x][y] = (rnd < rnd_value / 2 ? right_dir : old_move_dir);
4661 else if (should_turn_left)
4662 MovDir[x][y] = left_dir;
4663 else if (should_turn_right)
4664 MovDir[x][y] = right_dir;
4665 else if (should_move_on)
4666 MovDir[x][y] = old_move_dir;
4668 else if (can_move_on && rnd > rnd_value / 8)
4669 MovDir[x][y] = old_move_dir;
4670 else if (can_turn_left && can_turn_right)
4671 MovDir[x][y] = (rnd < rnd_value / 2 ? left_dir : right_dir);
4672 else if (can_turn_left && rnd > rnd_value / 8)
4673 MovDir[x][y] = left_dir;
4674 else if (can_turn_right && rnd > rnd_value/8)
4675 MovDir[x][y] = right_dir;
4677 MovDir[x][y] = back_dir;
4679 xx = x + move_xy[MovDir[x][y]].dx;
4680 yy = y + move_xy[MovDir[x][y]].dy;
4682 if (!IN_LEV_FIELD(xx, yy) ||
4683 (!IS_FREE(xx, yy) && !IS_FOOD_PIG(Feld[xx][yy])))
4684 MovDir[x][y] = old_move_dir;
4688 else if (element == EL_DRAGON)
4690 boolean can_turn_left = DRAGON_CAN_ENTER_FIELD(element, left_x, left_y);
4691 boolean can_turn_right = DRAGON_CAN_ENTER_FIELD(element, right_x, right_y);
4692 boolean can_move_on = DRAGON_CAN_ENTER_FIELD(element, move_x, move_y);
4694 int rnd = RND(rnd_value);
4696 if (can_move_on && rnd > rnd_value / 8)
4697 MovDir[x][y] = old_move_dir;
4698 else if (can_turn_left && can_turn_right)
4699 MovDir[x][y] = (rnd < rnd_value / 2 ? left_dir : right_dir);
4700 else if (can_turn_left && rnd > rnd_value / 8)
4701 MovDir[x][y] = left_dir;
4702 else if (can_turn_right && rnd > rnd_value / 8)
4703 MovDir[x][y] = right_dir;
4705 MovDir[x][y] = back_dir;
4707 xx = x + move_xy[MovDir[x][y]].dx;
4708 yy = y + move_xy[MovDir[x][y]].dy;
4710 if (!IN_LEV_FIELD_AND_IS_FREE(xx, yy))
4711 MovDir[x][y] = old_move_dir;
4715 else if (element == EL_MOLE)
4717 boolean can_move_on =
4718 (MOLE_CAN_ENTER_FIELD(element, move_x, move_y,
4719 IS_AMOEBOID(Feld[move_x][move_y]) ||
4720 Feld[move_x][move_y] == EL_AMOEBA_SHRINKING));
4723 boolean can_turn_left =
4724 (MOLE_CAN_ENTER_FIELD(element, left_x, left_y,
4725 IS_AMOEBOID(Feld[left_x][left_y])));
4727 boolean can_turn_right =
4728 (MOLE_CAN_ENTER_FIELD(element, right_x, right_y,
4729 IS_AMOEBOID(Feld[right_x][right_y])));
4731 if (can_turn_left && can_turn_right)
4732 MovDir[x][y] = (RND(2) ? left_dir : right_dir);
4733 else if (can_turn_left)
4734 MovDir[x][y] = left_dir;
4736 MovDir[x][y] = right_dir;
4739 if (MovDir[x][y] != old_move_dir)
4742 else if (element == EL_BALLOON)
4744 MovDir[x][y] = game.wind_direction;
4747 else if (element == EL_SPRING)
4749 #if USE_NEW_SPRING_BUMPER
4750 if (MovDir[x][y] & MV_HORIZONTAL)
4752 if (SPRING_CAN_BUMP_FROM_FIELD(move_x, move_y) &&
4753 !SPRING_CAN_ENTER_FIELD(element, x, y + 1))
4755 Feld[move_x][move_y] = EL_EMC_SPRING_BUMPER_ACTIVE;
4756 ResetGfxAnimation(move_x, move_y);
4757 DrawLevelField(move_x, move_y);
4759 MovDir[x][y] = back_dir;
4761 else if (!SPRING_CAN_ENTER_FIELD(element, move_x, move_y) ||
4762 SPRING_CAN_ENTER_FIELD(element, x, y + 1))
4763 MovDir[x][y] = MV_NONE;
4766 if (MovDir[x][y] & MV_HORIZONTAL &&
4767 (!SPRING_CAN_ENTER_FIELD(element, move_x, move_y) ||
4768 SPRING_CAN_ENTER_FIELD(element, x, y + 1)))
4769 MovDir[x][y] = MV_NONE;
4774 else if (element == EL_ROBOT ||
4775 element == EL_SATELLITE ||
4776 element == EL_PENGUIN ||
4777 element == EL_EMC_ANDROID)
4779 int attr_x = -1, attr_y = -1;
4790 for (i = 0; i < MAX_PLAYERS; i++)
4792 struct PlayerInfo *player = &stored_player[i];
4793 int jx = player->jx, jy = player->jy;
4795 if (!player->active)
4799 ABS(jx - x) + ABS(jy - y) < ABS(attr_x - x) + ABS(attr_y - y))
4807 if (element == EL_ROBOT && ZX >= 0 && ZY >= 0 &&
4808 (Feld[ZX][ZY] == EL_ROBOT_WHEEL_ACTIVE ||
4809 game.engine_version < VERSION_IDENT(3,1,0,0)))
4815 if (element == EL_PENGUIN)
4818 static int xy[4][2] =
4826 for (i = 0; i < NUM_DIRECTIONS; i++)
4828 int ex = x + xy[i][0];
4829 int ey = y + xy[i][1];
4831 if (IN_LEV_FIELD(ex, ey) && Feld[ex][ey] == EL_EXIT_OPEN)
4840 MovDir[x][y] = MV_NONE;
4842 MovDir[x][y] |= (AllPlayersGone ? MV_RIGHT : MV_LEFT);
4843 else if (attr_x > x)
4844 MovDir[x][y] |= (AllPlayersGone ? MV_LEFT : MV_RIGHT);
4846 MovDir[x][y] |= (AllPlayersGone ? MV_DOWN : MV_UP);
4847 else if (attr_y > y)
4848 MovDir[x][y] |= (AllPlayersGone ? MV_UP : MV_DOWN);
4850 if (element == EL_ROBOT)
4854 if (MovDir[x][y] & MV_HORIZONTAL && MovDir[x][y] & MV_VERTICAL)
4855 MovDir[x][y] &= (RND(2) ? MV_HORIZONTAL : MV_VERTICAL);
4856 Moving2Blocked(x, y, &newx, &newy);
4858 if (IN_LEV_FIELD(newx, newy) && IS_FREE_OR_PLAYER(newx, newy))
4859 MovDelay[x][y] = 8 + 8 * !RND(3);
4861 MovDelay[x][y] = 16;
4863 else if (element == EL_PENGUIN)
4869 if (MovDir[x][y] & MV_HORIZONTAL && MovDir[x][y] & MV_VERTICAL)
4871 boolean first_horiz = RND(2);
4872 int new_move_dir = MovDir[x][y];
4875 new_move_dir & (first_horiz ? MV_HORIZONTAL : MV_VERTICAL);
4876 Moving2Blocked(x, y, &newx, &newy);
4878 if (PENGUIN_CAN_ENTER_FIELD(element, newx, newy))
4882 new_move_dir & (!first_horiz ? MV_HORIZONTAL : MV_VERTICAL);
4883 Moving2Blocked(x, y, &newx, &newy);
4885 if (PENGUIN_CAN_ENTER_FIELD(element, newx, newy))
4888 MovDir[x][y] = old_move_dir;
4892 else if (element == EL_SATELLITE)
4898 if (MovDir[x][y] & MV_HORIZONTAL && MovDir[x][y] & MV_VERTICAL)
4900 boolean first_horiz = RND(2);
4901 int new_move_dir = MovDir[x][y];
4904 new_move_dir & (first_horiz ? MV_HORIZONTAL : MV_VERTICAL);
4905 Moving2Blocked(x, y, &newx, &newy);
4907 if (SATELLITE_CAN_ENTER_FIELD(newx, newy))
4911 new_move_dir & (!first_horiz ? MV_HORIZONTAL : MV_VERTICAL);
4912 Moving2Blocked(x, y, &newx, &newy);
4914 if (SATELLITE_CAN_ENTER_FIELD(newx, newy))
4917 MovDir[x][y] = old_move_dir;
4921 else if (element == EL_EMC_ANDROID)
4923 static int check_pos[16] =
4925 -1, /* 0 => (invalid) */
4926 7, /* 1 => MV_LEFT */
4927 3, /* 2 => MV_RIGHT */
4928 -1, /* 3 => (invalid) */
4930 0, /* 5 => MV_LEFT | MV_UP */
4931 2, /* 6 => MV_RIGHT | MV_UP */
4932 -1, /* 7 => (invalid) */
4933 5, /* 8 => MV_DOWN */
4934 6, /* 9 => MV_LEFT | MV_DOWN */
4935 4, /* 10 => MV_RIGHT | MV_DOWN */
4936 -1, /* 11 => (invalid) */
4937 -1, /* 12 => (invalid) */
4938 -1, /* 13 => (invalid) */
4939 -1, /* 14 => (invalid) */
4940 -1, /* 15 => (invalid) */
4948 { -1, -1, MV_LEFT | MV_UP },
4950 { +1, -1, MV_RIGHT | MV_UP },
4951 { +1, 0, MV_RIGHT },
4952 { +1, +1, MV_RIGHT | MV_DOWN },
4954 { -1, +1, MV_LEFT | MV_DOWN },
4957 int start_pos, check_order;
4958 boolean can_clone = FALSE;
4961 /* check if there is any free field around current position */
4962 for (i = 0; i < 8; i++)
4964 int newx = x + check_xy[i].dx;
4965 int newy = y + check_xy[i].dy;
4967 if (IN_LEV_FIELD_AND_IS_FREE(newx, newy))
4975 if (can_clone) /* randomly find an element to clone */
4979 start_pos = check_pos[RND(8)];
4980 check_order = (RND(2) ? -1 : +1);
4982 for (i = 0; i < 8; i++)
4984 int pos_raw = start_pos + i * check_order;
4985 int pos = (pos_raw + 8) % 8;
4986 int newx = x + check_xy[pos].dx;
4987 int newy = y + check_xy[pos].dy;
4989 if (ANDROID_CAN_CLONE_FIELD(newx, newy))
4991 element_info[element].move_leave_type = LEAVE_TYPE_LIMITED;
4992 element_info[element].move_leave_element = EL_TRIGGER_ELEMENT;
4994 Store[x][y] = Feld[newx][newy];
5003 if (can_clone) /* randomly find a direction to move */
5007 start_pos = check_pos[RND(8)];
5008 check_order = (RND(2) ? -1 : +1);
5010 for (i = 0; i < 8; i++)
5012 int pos_raw = start_pos + i * check_order;
5013 int pos = (pos_raw + 8) % 8;
5014 int newx = x + check_xy[pos].dx;
5015 int newy = y + check_xy[pos].dy;
5016 int new_move_dir = check_xy[pos].dir;
5018 if (IN_LEV_FIELD_AND_IS_FREE(newx, newy))
5020 MovDir[x][y] = new_move_dir;
5021 MovDelay[x][y] = level.android_clone_time * 8 + 1;
5030 if (can_clone) /* cloning and moving successful */
5033 /* cannot clone -- try to move towards player */
5035 start_pos = check_pos[MovDir[x][y] & 0x0f];
5036 check_order = (RND(2) ? -1 : +1);
5038 for (i = 0; i < 3; i++)
5040 /* first check start_pos, then previous/next or (next/previous) pos */
5041 int pos_raw = start_pos + (i < 2 ? i : -1) * check_order;
5042 int pos = (pos_raw + 8) % 8;
5043 int newx = x + check_xy[pos].dx;
5044 int newy = y + check_xy[pos].dy;
5045 int new_move_dir = check_xy[pos].dir;
5047 if (IS_PLAYER(newx, newy))
5050 if (ANDROID_CAN_ENTER_FIELD(element, newx, newy))
5052 MovDir[x][y] = new_move_dir;
5053 MovDelay[x][y] = level.android_move_time * 8 + 1;
5060 else if (move_pattern == MV_TURNING_LEFT ||
5061 move_pattern == MV_TURNING_RIGHT ||
5062 move_pattern == MV_TURNING_LEFT_RIGHT ||
5063 move_pattern == MV_TURNING_RIGHT_LEFT ||
5064 move_pattern == MV_TURNING_RANDOM ||
5065 move_pattern == MV_ALL_DIRECTIONS)
5067 boolean can_turn_left =
5068 CUSTOM_ELEMENT_CAN_ENTER_FIELD(element, left_x, left_y);
5069 boolean can_turn_right =
5070 CUSTOM_ELEMENT_CAN_ENTER_FIELD(element, right_x,right_y);
5072 if (element_info[element].move_stepsize == 0) /* "not moving" */
5075 if (move_pattern == MV_TURNING_LEFT)
5076 MovDir[x][y] = left_dir;
5077 else if (move_pattern == MV_TURNING_RIGHT)
5078 MovDir[x][y] = right_dir;
5079 else if (move_pattern == MV_TURNING_LEFT_RIGHT)
5080 MovDir[x][y] = (can_turn_left || !can_turn_right ? left_dir : right_dir);
5081 else if (move_pattern == MV_TURNING_RIGHT_LEFT)
5082 MovDir[x][y] = (can_turn_right || !can_turn_left ? right_dir : left_dir);
5083 else if (move_pattern == MV_TURNING_RANDOM)
5084 MovDir[x][y] = (can_turn_left && !can_turn_right ? left_dir :
5085 can_turn_right && !can_turn_left ? right_dir :
5086 RND(2) ? left_dir : right_dir);
5087 else if (can_turn_left && can_turn_right)
5088 MovDir[x][y] = (RND(3) ? (RND(2) ? left_dir : right_dir) : back_dir);
5089 else if (can_turn_left)
5090 MovDir[x][y] = (RND(2) ? left_dir : back_dir);
5091 else if (can_turn_right)
5092 MovDir[x][y] = (RND(2) ? right_dir : back_dir);
5094 MovDir[x][y] = back_dir;
5096 MovDelay[x][y] = GET_NEW_MOVE_DELAY(element);
5098 else if (move_pattern == MV_HORIZONTAL ||
5099 move_pattern == MV_VERTICAL)
5101 if (move_pattern & old_move_dir)
5102 MovDir[x][y] = back_dir;
5103 else if (move_pattern == MV_HORIZONTAL)
5104 MovDir[x][y] = (RND(2) ? MV_LEFT : MV_RIGHT);
5105 else if (move_pattern == MV_VERTICAL)
5106 MovDir[x][y] = (RND(2) ? MV_UP : MV_DOWN);
5108 MovDelay[x][y] = GET_NEW_MOVE_DELAY(element);
5110 else if (move_pattern & MV_ANY_DIRECTION)
5112 MovDir[x][y] = move_pattern;
5113 MovDelay[x][y] = GET_NEW_MOVE_DELAY(element);
5115 else if (move_pattern & MV_WIND_DIRECTION)
5117 MovDir[x][y] = game.wind_direction;
5118 MovDelay[x][y] = GET_NEW_MOVE_DELAY(element);
5120 else if (move_pattern == MV_ALONG_LEFT_SIDE)
5122 if (CUSTOM_ELEMENT_CAN_ENTER_FIELD(element, left_x, left_y))
5123 MovDir[x][y] = left_dir;
5124 else if (!CUSTOM_ELEMENT_CAN_ENTER_FIELD(element, move_x, move_y))
5125 MovDir[x][y] = right_dir;
5127 if (MovDir[x][y] != old_move_dir)
5128 MovDelay[x][y] = GET_NEW_MOVE_DELAY(element);
5130 else if (move_pattern == MV_ALONG_RIGHT_SIDE)
5132 if (CUSTOM_ELEMENT_CAN_ENTER_FIELD(element, right_x, right_y))
5133 MovDir[x][y] = right_dir;
5134 else if (!CUSTOM_ELEMENT_CAN_ENTER_FIELD(element, move_x, move_y))
5135 MovDir[x][y] = left_dir;
5137 if (MovDir[x][y] != old_move_dir)
5138 MovDelay[x][y] = GET_NEW_MOVE_DELAY(element);
5140 else if (move_pattern == MV_TOWARDS_PLAYER ||
5141 move_pattern == MV_AWAY_FROM_PLAYER)
5143 int attr_x = -1, attr_y = -1;
5145 boolean move_away = (move_pattern == MV_AWAY_FROM_PLAYER);
5156 for (i = 0; i < MAX_PLAYERS; i++)
5158 struct PlayerInfo *player = &stored_player[i];
5159 int jx = player->jx, jy = player->jy;
5161 if (!player->active)
5165 ABS(jx - x) + ABS(jy - y) < ABS(attr_x - x) + ABS(attr_y - y))
5173 MovDir[x][y] = MV_NONE;
5175 MovDir[x][y] |= (move_away ? MV_RIGHT : MV_LEFT);
5176 else if (attr_x > x)
5177 MovDir[x][y] |= (move_away ? MV_LEFT : MV_RIGHT);
5179 MovDir[x][y] |= (move_away ? MV_DOWN : MV_UP);
5180 else if (attr_y > y)
5181 MovDir[x][y] |= (move_away ? MV_UP : MV_DOWN);
5183 MovDelay[x][y] = GET_NEW_MOVE_DELAY(element);
5185 if (MovDir[x][y] & MV_HORIZONTAL && MovDir[x][y] & MV_VERTICAL)
5187 boolean first_horiz = RND(2);
5188 int new_move_dir = MovDir[x][y];
5190 if (element_info[element].move_stepsize == 0) /* "not moving" */
5192 first_horiz = (ABS(attr_x - x) >= ABS(attr_y - y));
5193 MovDir[x][y] &= (first_horiz ? MV_HORIZONTAL : MV_VERTICAL);
5199 new_move_dir & (first_horiz ? MV_HORIZONTAL : MV_VERTICAL);
5200 Moving2Blocked(x, y, &newx, &newy);
5202 if (CUSTOM_ELEMENT_CAN_ENTER_FIELD(element, newx, newy))
5206 new_move_dir & (!first_horiz ? MV_HORIZONTAL : MV_VERTICAL);
5207 Moving2Blocked(x, y, &newx, &newy);
5209 if (CUSTOM_ELEMENT_CAN_ENTER_FIELD(element, newx, newy))
5212 MovDir[x][y] = old_move_dir;
5215 else if (move_pattern == MV_WHEN_PUSHED ||
5216 move_pattern == MV_WHEN_DROPPED)
5218 if (!CUSTOM_ELEMENT_CAN_ENTER_FIELD(element, move_x, move_y))
5219 MovDir[x][y] = MV_NONE;
5223 else if (move_pattern & MV_MAZE_RUNNER_STYLE)
5225 static int test_xy[7][2] =
5235 static int test_dir[7] =
5245 boolean hunter_mode = (move_pattern == MV_MAZE_HUNTER);
5246 int move_preference = -1000000; /* start with very low preference */
5247 int new_move_dir = MV_NONE;
5248 int start_test = RND(4);
5251 for (i = 0; i < NUM_DIRECTIONS; i++)
5253 int move_dir = test_dir[start_test + i];
5254 int move_dir_preference;
5256 xx = x + test_xy[start_test + i][0];
5257 yy = y + test_xy[start_test + i][1];
5259 if (hunter_mode && IN_LEV_FIELD(xx, yy) &&
5260 (IS_PLAYER(xx, yy) || Feld[xx][yy] == EL_PLAYER_IS_LEAVING))
5262 new_move_dir = move_dir;
5267 if (!CUSTOM_ELEMENT_CAN_ENTER_FIELD(element, xx, yy))
5270 move_dir_preference = -1 * RunnerVisit[xx][yy];
5271 if (hunter_mode && PlayerVisit[xx][yy] > 0)
5272 move_dir_preference = PlayerVisit[xx][yy];
5274 if (move_dir_preference > move_preference)
5276 /* prefer field that has not been visited for the longest time */
5277 move_preference = move_dir_preference;
5278 new_move_dir = move_dir;
5280 else if (move_dir_preference == move_preference &&
5281 move_dir == old_move_dir)
5283 /* prefer last direction when all directions are preferred equally */
5284 move_preference = move_dir_preference;
5285 new_move_dir = move_dir;
5289 MovDir[x][y] = new_move_dir;
5290 if (old_move_dir != new_move_dir)
5291 MovDelay[x][y] = GET_NEW_MOVE_DELAY(element);
5295 static void TurnRound(int x, int y)
5297 int direction = MovDir[x][y];
5299 int element, graphic;
5304 GfxDir[x][y] = MovDir[x][y];
5306 if (direction != MovDir[x][y])
5310 GfxAction[x][y] = ACTION_TURNING_FROM_LEFT + MV_DIR_TO_BIT(direction);
5313 element = Feld[x][y];
5314 graphic = el_act_dir2img(element, GfxAction[x][y], GfxDir[x][y]);
5316 if (graphic_info[graphic].anim_global_sync)
5317 GfxFrame[x][y] = FrameCounter;
5318 else if (ANIM_MODE(graphic) == ANIM_CE_VALUE)
5319 GfxFrame[x][y] = CustomValue[x][y];
5320 else if (ANIM_MODE(graphic) == ANIM_CE_SCORE)
5321 GfxFrame[x][y] = element_info[element].collect_score;
5325 static boolean JustBeingPushed(int x, int y)
5329 for (i = 0; i < MAX_PLAYERS; i++)
5331 struct PlayerInfo *player = &stored_player[i];
5333 if (player->active && player->is_pushing && player->MovPos)
5335 int next_jx = player->jx + (player->jx - player->last_jx);
5336 int next_jy = player->jy + (player->jy - player->last_jy);
5338 if (x == next_jx && y == next_jy)
5346 void StartMoving(int x, int y)
5348 boolean started_moving = FALSE; /* some elements can fall _and_ move */
5349 int element = Feld[x][y];
5354 if (MovDelay[x][y] == 0)
5355 GfxAction[x][y] = ACTION_DEFAULT;
5357 if (CAN_FALL(element) && y < lev_fieldy - 1)
5359 if ((x > 0 && IS_PLAYER(x - 1, y)) ||
5360 (x < lev_fieldx - 1 && IS_PLAYER(x + 1, y)))
5361 if (JustBeingPushed(x, y))
5364 if (element == EL_QUICKSAND_FULL)
5366 if (IS_FREE(x, y + 1))
5368 InitMovingField(x, y, MV_DOWN);
5369 started_moving = TRUE;
5371 Feld[x][y] = EL_QUICKSAND_EMPTYING;
5372 Store[x][y] = EL_ROCK;
5374 PlayLevelSoundAction(x, y, ACTION_EMPTYING);
5376 else if (Feld[x][y + 1] == EL_QUICKSAND_EMPTY)
5378 if (!MovDelay[x][y])
5379 MovDelay[x][y] = TILEY + 1;
5388 Feld[x][y] = EL_QUICKSAND_EMPTY;
5389 Feld[x][y + 1] = EL_QUICKSAND_FULL;
5390 Store[x][y + 1] = Store[x][y];
5393 PlayLevelSoundAction(x, y, ACTION_FILLING);
5396 else if ((element == EL_ROCK || element == EL_BD_ROCK) &&
5397 Feld[x][y + 1] == EL_QUICKSAND_EMPTY)
5399 InitMovingField(x, y, MV_DOWN);
5400 started_moving = TRUE;
5402 Feld[x][y] = EL_QUICKSAND_FILLING;
5403 Store[x][y] = element;
5405 PlayLevelSoundAction(x, y, ACTION_FILLING);
5407 else if (element == EL_MAGIC_WALL_FULL)
5409 if (IS_FREE(x, y + 1))
5411 InitMovingField(x, y, MV_DOWN);
5412 started_moving = TRUE;
5414 Feld[x][y] = EL_MAGIC_WALL_EMPTYING;
5415 Store[x][y] = EL_CHANGED(Store[x][y]);
5417 else if (Feld[x][y + 1] == EL_MAGIC_WALL_ACTIVE)
5419 if (!MovDelay[x][y])
5420 MovDelay[x][y] = TILEY/4 + 1;
5429 Feld[x][y] = EL_MAGIC_WALL_ACTIVE;
5430 Feld[x][y + 1] = EL_MAGIC_WALL_FULL;
5431 Store[x][y + 1] = EL_CHANGED(Store[x][y]);
5435 else if (element == EL_BD_MAGIC_WALL_FULL)
5437 if (IS_FREE(x, y + 1))
5439 InitMovingField(x, y, MV_DOWN);
5440 started_moving = TRUE;
5442 Feld[x][y] = EL_BD_MAGIC_WALL_EMPTYING;
5443 Store[x][y] = EL_CHANGED2(Store[x][y]);
5445 else if (Feld[x][y + 1] == EL_BD_MAGIC_WALL_ACTIVE)
5447 if (!MovDelay[x][y])
5448 MovDelay[x][y] = TILEY/4 + 1;
5457 Feld[x][y] = EL_BD_MAGIC_WALL_ACTIVE;
5458 Feld[x][y + 1] = EL_BD_MAGIC_WALL_FULL;
5459 Store[x][y + 1] = EL_CHANGED2(Store[x][y]);
5463 else if (CAN_PASS_MAGIC_WALL(element) &&
5464 (Feld[x][y + 1] == EL_MAGIC_WALL_ACTIVE ||
5465 Feld[x][y + 1] == EL_BD_MAGIC_WALL_ACTIVE))
5467 InitMovingField(x, y, MV_DOWN);
5468 started_moving = TRUE;
5471 (Feld[x][y + 1] == EL_MAGIC_WALL_ACTIVE ? EL_MAGIC_WALL_FILLING :
5472 EL_BD_MAGIC_WALL_FILLING);
5473 Store[x][y] = element;
5475 else if (CAN_FALL(element) && Feld[x][y + 1] == EL_ACID)
5477 SplashAcid(x, y + 1);
5479 InitMovingField(x, y, MV_DOWN);
5480 started_moving = TRUE;
5482 Store[x][y] = EL_ACID;
5484 else if ((game.engine_version >= VERSION_IDENT(3,1,0,0) &&
5485 CheckCollision[x][y] && !IS_FREE(x, y + 1)) ||
5487 (game.engine_version >= VERSION_IDENT(3,0,7,0) &&
5488 CAN_FALL(element) && WasJustFalling[x][y] &&
5489 (Feld[x][y + 1] == EL_BLOCKED || IS_PLAYER(x, y + 1))) ||
5491 (game.engine_version < VERSION_IDENT(2,2,0,7) &&
5492 CAN_FALL(element) && WasJustMoving[x][y] && !Pushed[x][y + 1] &&
5493 (Feld[x][y + 1] == EL_BLOCKED)))
5495 /* this is needed for a special case not covered by calling "Impact()"
5496 from "ContinueMoving()": if an element moves to a tile directly below
5497 another element which was just falling on that tile (which was empty
5498 in the previous frame), the falling element above would just stop
5499 instead of smashing the element below (in previous version, the above
5500 element was just checked for "moving" instead of "falling", resulting
5501 in incorrect smashes caused by horizontal movement of the above
5502 element; also, the case of the player being the element to smash was
5503 simply not covered here... :-/ ) */
5505 CheckCollision[x][y] = 0;
5509 else if (IS_FREE(x, y + 1) && element == EL_SPRING && level.use_spring_bug)
5511 if (MovDir[x][y] == MV_NONE)
5513 InitMovingField(x, y, MV_DOWN);
5514 started_moving = TRUE;
5517 else if (IS_FREE(x, y + 1) || Feld[x][y + 1] == EL_DIAMOND_BREAKING)
5519 if (WasJustFalling[x][y]) /* prevent animation from being restarted */
5520 MovDir[x][y] = MV_DOWN;
5522 InitMovingField(x, y, MV_DOWN);
5523 started_moving = TRUE;
5525 else if (element == EL_AMOEBA_DROP)
5527 Feld[x][y] = EL_AMOEBA_GROWING;
5528 Store[x][y] = EL_AMOEBA_WET;
5530 else if (((IS_SLIPPERY(Feld[x][y + 1]) && !IS_PLAYER(x, y + 1)) ||
5531 (IS_EM_SLIPPERY_WALL(Feld[x][y + 1]) && IS_GEM(element))) &&
5532 !IS_FALLING(x, y + 1) && !WasJustMoving[x][y + 1] &&
5533 element != EL_DX_SUPABOMB && element != EL_SP_DISK_ORANGE)
5535 boolean can_fall_left = (x > 0 && IS_FREE(x - 1, y) &&
5536 (IS_FREE(x - 1, y + 1) ||
5537 Feld[x - 1][y + 1] == EL_ACID));
5538 boolean can_fall_right = (x < lev_fieldx - 1 && IS_FREE(x + 1, y) &&
5539 (IS_FREE(x + 1, y + 1) ||
5540 Feld[x + 1][y + 1] == EL_ACID));
5541 boolean can_fall_any = (can_fall_left || can_fall_right);
5542 boolean can_fall_both = (can_fall_left && can_fall_right);
5543 int slippery_type = element_info[Feld[x][y + 1]].slippery_type;
5545 #if USE_NEW_ALL_SLIPPERY
5546 if (can_fall_any && slippery_type != SLIPPERY_ANY_RANDOM)
5548 if (slippery_type == SLIPPERY_ANY_LEFT_RIGHT && can_fall_both)
5549 can_fall_right = FALSE;
5550 else if (slippery_type == SLIPPERY_ANY_RIGHT_LEFT && can_fall_both)
5551 can_fall_left = FALSE;
5552 else if (slippery_type == SLIPPERY_ONLY_LEFT)
5553 can_fall_right = FALSE;
5554 else if (slippery_type == SLIPPERY_ONLY_RIGHT)
5555 can_fall_left = FALSE;
5557 can_fall_any = (can_fall_left || can_fall_right);
5558 can_fall_both = FALSE;
5561 if (can_fall_any && IS_CUSTOM_ELEMENT(Feld[x][y + 1]))
5563 if (slippery_type == SLIPPERY_ONLY_LEFT)
5564 can_fall_right = FALSE;
5565 else if (slippery_type == SLIPPERY_ONLY_RIGHT)
5566 can_fall_left = FALSE;
5567 else if (slippery_type == SLIPPERY_ANY_LEFT_RIGHT && can_fall_both)
5568 can_fall_right = FALSE;
5569 else if (slippery_type == SLIPPERY_ANY_RIGHT_LEFT && can_fall_both)
5570 can_fall_left = FALSE;
5572 can_fall_any = (can_fall_left || can_fall_right);
5573 can_fall_both = (can_fall_left && can_fall_right);
5577 #if USE_NEW_ALL_SLIPPERY
5579 #if USE_NEW_SP_SLIPPERY
5580 /* !!! better use the same properties as for custom elements here !!! */
5581 else if (game.engine_version >= VERSION_IDENT(3,1,1,0) &&
5582 can_fall_both && IS_SP_ELEMENT(Feld[x][y + 1]))
5584 can_fall_right = FALSE; /* slip down on left side */
5585 can_fall_both = FALSE;
5590 #if USE_NEW_ALL_SLIPPERY
5593 if (element == EL_BD_ROCK || element == EL_BD_DIAMOND)
5594 can_fall_right = FALSE; /* slip down on left side */
5596 can_fall_left = !(can_fall_right = RND(2));
5598 can_fall_both = FALSE;
5603 if (game.emulation == EMU_BOULDERDASH ||
5604 element == EL_BD_ROCK || element == EL_BD_DIAMOND)
5605 can_fall_right = FALSE; /* slip down on left side */
5607 can_fall_left = !(can_fall_right = RND(2));
5609 can_fall_both = FALSE;
5615 /* if not determined otherwise, prefer left side for slipping down */
5616 InitMovingField(x, y, can_fall_left ? MV_LEFT : MV_RIGHT);
5617 started_moving = TRUE;
5621 else if (IS_BELT_ACTIVE(Feld[x][y + 1]) && !CAN_MOVE(element))
5623 else if (IS_BELT_ACTIVE(Feld[x][y + 1]))
5626 boolean left_is_free = (x > 0 && IS_FREE(x - 1, y));
5627 boolean right_is_free = (x < lev_fieldx - 1 && IS_FREE(x + 1, y));
5628 int belt_nr = getBeltNrFromBeltActiveElement(Feld[x][y + 1]);
5629 int belt_dir = game.belt_dir[belt_nr];
5631 if ((belt_dir == MV_LEFT && left_is_free) ||
5632 (belt_dir == MV_RIGHT && right_is_free))
5634 int nextx = (belt_dir == MV_LEFT ? x - 1 : x + 1);
5636 InitMovingField(x, y, belt_dir);
5637 started_moving = TRUE;
5639 Pushed[x][y] = TRUE;
5640 Pushed[nextx][y] = TRUE;
5642 GfxAction[x][y] = ACTION_DEFAULT;
5646 MovDir[x][y] = 0; /* if element was moving, stop it */
5651 /* not "else if" because of elements that can fall and move (EL_SPRING) */
5653 if (CAN_MOVE(element) && !started_moving && MovDir[x][y] != MV_NONE)
5655 if (CAN_MOVE(element) && !started_moving)
5658 int move_pattern = element_info[element].move_pattern;
5663 if (MovDir[x][y] == MV_NONE)
5665 printf("StartMoving(): %d,%d: element %d ['%s'] not moving\n",
5666 x, y, element, element_info[element].token_name);
5667 printf("StartMoving(): This should never happen!\n");
5672 Moving2Blocked(x, y, &newx, &newy);
5674 if (IS_PUSHABLE(element) && JustBeingPushed(x, y))
5677 if (game.engine_version >= VERSION_IDENT(3,1,0,0) &&
5678 CheckCollision[x][y] && !IN_LEV_FIELD_AND_IS_FREE(newx, newy))
5680 WasJustMoving[x][y] = 0;
5681 CheckCollision[x][y] = 0;
5683 TestIfElementHitsCustomElement(x, y, MovDir[x][y]);
5685 if (Feld[x][y] != element) /* element has changed */
5689 if (!MovDelay[x][y]) /* start new movement phase */
5691 /* all objects that can change their move direction after each step
5692 (YAMYAM, DARK_YAMYAM and PACMAN go straight until they hit a wall */
5694 if (element != EL_YAMYAM &&
5695 element != EL_DARK_YAMYAM &&
5696 element != EL_PACMAN &&
5697 !(move_pattern & MV_ANY_DIRECTION) &&
5698 move_pattern != MV_TURNING_LEFT &&
5699 move_pattern != MV_TURNING_RIGHT &&
5700 move_pattern != MV_TURNING_LEFT_RIGHT &&
5701 move_pattern != MV_TURNING_RIGHT_LEFT &&
5702 move_pattern != MV_TURNING_RANDOM)
5706 if (MovDelay[x][y] && (element == EL_BUG ||
5707 element == EL_SPACESHIP ||
5708 element == EL_SP_SNIKSNAK ||
5709 element == EL_SP_ELECTRON ||
5710 element == EL_MOLE))
5711 DrawLevelField(x, y);
5715 if (MovDelay[x][y]) /* wait some time before next movement */
5719 if (element == EL_ROBOT ||
5720 element == EL_YAMYAM ||
5721 element == EL_DARK_YAMYAM)
5723 DrawLevelElementAnimationIfNeeded(x, y, element);
5724 PlayLevelSoundAction(x, y, ACTION_WAITING);
5726 else if (element == EL_SP_ELECTRON)
5727 DrawLevelElementAnimationIfNeeded(x, y, element);
5728 else if (element == EL_DRAGON)
5731 int dir = MovDir[x][y];
5732 int dx = (dir == MV_LEFT ? -1 : dir == MV_RIGHT ? +1 : 0);
5733 int dy = (dir == MV_UP ? -1 : dir == MV_DOWN ? +1 : 0);
5734 int graphic = (dir == MV_LEFT ? IMG_FLAMES_1_LEFT :
5735 dir == MV_RIGHT ? IMG_FLAMES_1_RIGHT :
5736 dir == MV_UP ? IMG_FLAMES_1_UP :
5737 dir == MV_DOWN ? IMG_FLAMES_1_DOWN : IMG_EMPTY);
5738 int frame = getGraphicAnimationFrame(graphic, GfxFrame[x][y]);
5740 GfxAction[x][y] = ACTION_ATTACKING;
5742 if (IS_PLAYER(x, y))
5743 DrawPlayerField(x, y);
5745 DrawLevelField(x, y);
5747 PlayLevelSoundActionIfLoop(x, y, ACTION_ATTACKING);
5749 for (i = 1; i <= 3; i++)
5751 int xx = x + i * dx;
5752 int yy = y + i * dy;
5753 int sx = SCREENX(xx);
5754 int sy = SCREENY(yy);
5755 int flame_graphic = graphic + (i - 1);
5757 if (!IN_LEV_FIELD(xx, yy) || IS_DRAGONFIRE_PROOF(Feld[xx][yy]))
5762 int flamed = MovingOrBlocked2Element(xx, yy);
5766 if (IS_CLASSIC_ENEMY(flamed) || CAN_EXPLODE_BY_DRAGONFIRE(flamed))
5768 else if (IS_MOVING(xx, yy) || IS_BLOCKED(xx, yy))
5769 RemoveMovingField(xx, yy);
5771 RemoveField(xx, yy);
5773 if (IS_CLASSIC_ENEMY(flamed) || CAN_EXPLODE_BY_DRAGONFIRE(flamed))
5776 RemoveMovingField(xx, yy);
5779 ChangeDelay[xx][yy] = 0;
5781 Feld[xx][yy] = EL_FLAMES;
5783 if (IN_SCR_FIELD(sx, sy))
5785 DrawLevelFieldCrumbledSand(xx, yy);
5786 DrawGraphic(sx, sy, flame_graphic, frame);
5791 if (Feld[xx][yy] == EL_FLAMES)
5792 Feld[xx][yy] = EL_EMPTY;
5793 DrawLevelField(xx, yy);
5798 if (MovDelay[x][y]) /* element still has to wait some time */
5800 PlayLevelSoundAction(x, y, ACTION_WAITING);
5806 /* now make next step */
5808 Moving2Blocked(x, y, &newx, &newy); /* get next screen position */
5810 if (DONT_COLLIDE_WITH(element) &&
5811 IN_LEV_FIELD(newx, newy) && IS_PLAYER(newx, newy) &&
5812 !PLAYER_ENEMY_PROTECTED(newx, newy))
5814 TestIfBadThingRunsIntoPlayer(x, y, MovDir[x][y]);
5819 else if (CAN_MOVE_INTO_ACID(element) &&
5820 IN_LEV_FIELD(newx, newy) && Feld[newx][newy] == EL_ACID &&
5821 !IS_MV_DIAGONAL(MovDir[x][y]) &&
5822 (MovDir[x][y] == MV_DOWN ||
5823 game.engine_version >= VERSION_IDENT(3,1,0,0)))
5825 SplashAcid(newx, newy);
5826 Store[x][y] = EL_ACID;
5828 else if (element == EL_PENGUIN && IN_LEV_FIELD(newx, newy))
5830 if (Feld[newx][newy] == EL_EXIT_OPEN)
5833 DrawLevelField(x, y);
5835 PlayLevelSound(newx, newy, SND_PENGUIN_PASSING);
5836 if (IN_SCR_FIELD(SCREENX(newx), SCREENY(newy)))
5837 DrawGraphicThruMask(SCREENX(newx),SCREENY(newy), el2img(element), 0);
5839 local_player->friends_still_needed--;
5840 if (!local_player->friends_still_needed &&
5841 !local_player->GameOver && AllPlayersGone)
5842 local_player->LevelSolved = local_player->GameOver = TRUE;
5846 else if (IS_FOOD_PENGUIN(Feld[newx][newy]))
5848 if (DigField(local_player, x, y, newx, newy, 0,0, DF_DIG) == MP_MOVING)
5849 DrawLevelField(newx, newy);
5851 GfxDir[x][y] = MovDir[x][y] = MV_NONE;
5853 else if (!IS_FREE(newx, newy))
5855 GfxAction[x][y] = ACTION_WAITING;
5857 if (IS_PLAYER(x, y))
5858 DrawPlayerField(x, y);
5860 DrawLevelField(x, y);
5865 else if (element == EL_PIG && IN_LEV_FIELD(newx, newy))
5867 if (IS_FOOD_PIG(Feld[newx][newy]))
5869 if (IS_MOVING(newx, newy))
5870 RemoveMovingField(newx, newy);
5873 Feld[newx][newy] = EL_EMPTY;
5874 DrawLevelField(newx, newy);
5877 PlayLevelSound(x, y, SND_PIG_DIGGING);
5879 else if (!IS_FREE(newx, newy))
5881 if (IS_PLAYER(x, y))
5882 DrawPlayerField(x, y);
5884 DrawLevelField(x, y);
5889 else if (element == EL_EMC_ANDROID && IN_LEV_FIELD(newx, newy))
5891 if (Store[x][y] != EL_EMPTY)
5893 boolean can_clone = FALSE;
5896 /* check if element to clone is still there */
5897 for (yy = y - 1; yy <= y + 1; yy++) for (xx = x - 1; xx <= x + 1; xx++)
5899 if (IN_LEV_FIELD(xx, yy) && Feld[xx][yy] == Store[x][y])
5907 /* cannot clone or target field not free anymore -- do not clone */
5908 if (!can_clone || !ANDROID_CAN_ENTER_FIELD(element, newx, newy))
5909 Store[x][y] = EL_EMPTY;
5912 if (ANDROID_CAN_ENTER_FIELD(element, newx, newy))
5914 if (IS_MV_DIAGONAL(MovDir[x][y]))
5916 int diagonal_move_dir = MovDir[x][y];
5917 int stored = Store[x][y];
5918 int change_delay = 8;
5921 /* android is moving diagonally */
5923 CreateField(x, y, EL_DIAGONAL_SHRINKING);
5925 Store[x][y] = (stored == EL_ACID ? EL_EMPTY : stored);
5926 GfxElement[x][y] = EL_EMC_ANDROID;
5927 GfxAction[x][y] = ACTION_SHRINKING;
5928 GfxDir[x][y] = diagonal_move_dir;
5929 ChangeDelay[x][y] = change_delay;
5931 graphic = el_act_dir2img(GfxElement[x][y], GfxAction[x][y],
5934 DrawLevelGraphicAnimation(x, y, graphic);
5935 PlayLevelSoundAction(x, y, ACTION_SHRINKING);
5937 if (Feld[newx][newy] == EL_ACID)
5939 SplashAcid(newx, newy);
5944 CreateField(newx, newy, EL_DIAGONAL_GROWING);
5946 Store[newx][newy] = EL_EMC_ANDROID;
5947 GfxElement[newx][newy] = EL_EMC_ANDROID;
5948 GfxAction[newx][newy] = ACTION_GROWING;
5949 GfxDir[newx][newy] = diagonal_move_dir;
5950 ChangeDelay[newx][newy] = change_delay;
5952 graphic = el_act_dir2img(GfxElement[newx][newy],
5953 GfxAction[newx][newy], GfxDir[newx][newy]);
5955 DrawLevelGraphicAnimation(newx, newy, graphic);
5956 PlayLevelSoundAction(newx, newy, ACTION_GROWING);
5962 Feld[newx][newy] = EL_EMPTY;
5963 DrawLevelField(newx, newy);
5965 PlayLevelSoundAction(x, y, ACTION_DIGGING);
5968 else if (!IS_FREE(newx, newy))
5971 if (IS_PLAYER(x, y))
5972 DrawPlayerField(x, y);
5974 DrawLevelField(x, y);
5980 else if (IS_CUSTOM_ELEMENT(element) &&
5981 CUSTOM_ELEMENT_CAN_ENTER_FIELD(element, newx, newy))
5983 int new_element = Feld[newx][newy];
5985 if (!IS_FREE(newx, newy))
5987 int action = (IS_DIGGABLE(new_element) ? ACTION_DIGGING :
5988 IS_COLLECTIBLE(new_element) ? ACTION_COLLECTING :
5991 /* no element can dig solid indestructible elements */
5992 if (IS_INDESTRUCTIBLE(new_element) &&
5993 !IS_DIGGABLE(new_element) &&
5994 !IS_COLLECTIBLE(new_element))
5997 if (AmoebaNr[newx][newy] &&
5998 (new_element == EL_AMOEBA_FULL ||
5999 new_element == EL_BD_AMOEBA ||
6000 new_element == EL_AMOEBA_GROWING))
6002 AmoebaCnt[AmoebaNr[newx][newy]]--;
6003 AmoebaCnt2[AmoebaNr[newx][newy]]--;
6006 if (IS_MOVING(newx, newy))
6007 RemoveMovingField(newx, newy);
6010 RemoveField(newx, newy);
6011 DrawLevelField(newx, newy);
6014 /* if digged element was about to explode, prevent the explosion */
6015 ExplodeField[newx][newy] = EX_TYPE_NONE;
6017 PlayLevelSoundAction(x, y, action);
6020 Store[newx][newy] = EL_EMPTY;
6022 /* this makes it possible to leave the removed element again */
6023 if (IS_EQUAL_OR_IN_GROUP(new_element, MOVE_ENTER_EL(element)))
6024 Store[newx][newy] = new_element;
6026 if (IS_EQUAL_OR_IN_GROUP(new_element, MOVE_ENTER_EL(element)))
6028 int move_leave_element = element_info[element].move_leave_element;
6030 /* this makes it possible to leave the removed element again */
6031 Store[newx][newy] = (move_leave_element == EL_TRIGGER_ELEMENT ?
6032 new_element : move_leave_element);
6036 if (move_pattern & MV_MAZE_RUNNER_STYLE)
6038 RunnerVisit[x][y] = FrameCounter;
6039 PlayerVisit[x][y] /= 8; /* expire player visit path */
6042 else if (element == EL_DRAGON && IN_LEV_FIELD(newx, newy))
6044 if (!IS_FREE(newx, newy))
6046 if (IS_PLAYER(x, y))
6047 DrawPlayerField(x, y);
6049 DrawLevelField(x, y);
6055 boolean wanna_flame = !RND(10);
6056 int dx = newx - x, dy = newy - y;
6057 int newx1 = newx + 1 * dx, newy1 = newy + 1 * dy;
6058 int newx2 = newx + 2 * dx, newy2 = newy + 2 * dy;
6059 int element1 = (IN_LEV_FIELD(newx1, newy1) ?
6060 MovingOrBlocked2Element(newx1, newy1) : EL_STEELWALL);
6061 int element2 = (IN_LEV_FIELD(newx2, newy2) ?
6062 MovingOrBlocked2Element(newx2, newy2) : EL_STEELWALL);
6065 IS_CLASSIC_ENEMY(element1) ||
6066 IS_CLASSIC_ENEMY(element2)) &&
6067 element1 != EL_DRAGON && element2 != EL_DRAGON &&
6068 element1 != EL_FLAMES && element2 != EL_FLAMES)
6070 ResetGfxAnimation(x, y);
6071 GfxAction[x][y] = ACTION_ATTACKING;
6073 if (IS_PLAYER(x, y))
6074 DrawPlayerField(x, y);
6076 DrawLevelField(x, y);
6078 PlayLevelSound(x, y, SND_DRAGON_ATTACKING);
6080 MovDelay[x][y] = 50;
6084 RemoveField(newx, newy);
6086 Feld[newx][newy] = EL_FLAMES;
6087 if (IN_LEV_FIELD(newx1, newy1) && Feld[newx1][newy1] == EL_EMPTY)
6090 RemoveField(newx1, newy1);
6092 Feld[newx1][newy1] = EL_FLAMES;
6094 if (IN_LEV_FIELD(newx2, newy2) && Feld[newx2][newy2] == EL_EMPTY)
6097 RemoveField(newx2, newy2);
6099 Feld[newx2][newy2] = EL_FLAMES;
6106 else if (element == EL_YAMYAM && IN_LEV_FIELD(newx, newy) &&
6107 Feld[newx][newy] == EL_DIAMOND)
6109 if (IS_MOVING(newx, newy))
6110 RemoveMovingField(newx, newy);
6113 Feld[newx][newy] = EL_EMPTY;
6114 DrawLevelField(newx, newy);
6117 PlayLevelSound(x, y, SND_YAMYAM_DIGGING);
6119 else if (element == EL_DARK_YAMYAM && IN_LEV_FIELD(newx, newy) &&
6120 IS_FOOD_DARK_YAMYAM(Feld[newx][newy]))
6122 if (AmoebaNr[newx][newy])
6124 AmoebaCnt2[AmoebaNr[newx][newy]]--;
6125 if (Feld[newx][newy] == EL_AMOEBA_FULL ||
6126 Feld[newx][newy] == EL_BD_AMOEBA)
6127 AmoebaCnt[AmoebaNr[newx][newy]]--;
6132 if (IS_MOVING(newx, newy) || IS_BLOCKED(newx, newy))
6134 RemoveMovingField(newx, newy);
6137 if (IS_MOVING(newx, newy))
6139 RemoveMovingField(newx, newy);
6144 Feld[newx][newy] = EL_EMPTY;
6145 DrawLevelField(newx, newy);
6148 PlayLevelSound(x, y, SND_DARK_YAMYAM_DIGGING);
6150 else if ((element == EL_PACMAN || element == EL_MOLE)
6151 && IN_LEV_FIELD(newx, newy) && IS_AMOEBOID(Feld[newx][newy]))
6153 if (AmoebaNr[newx][newy])
6155 AmoebaCnt2[AmoebaNr[newx][newy]]--;
6156 if (Feld[newx][newy] == EL_AMOEBA_FULL ||
6157 Feld[newx][newy] == EL_BD_AMOEBA)
6158 AmoebaCnt[AmoebaNr[newx][newy]]--;
6161 if (element == EL_MOLE)
6163 Feld[newx][newy] = EL_AMOEBA_SHRINKING;
6164 PlayLevelSound(x, y, SND_MOLE_DIGGING);
6166 ResetGfxAnimation(x, y);
6167 GfxAction[x][y] = ACTION_DIGGING;
6168 DrawLevelField(x, y);
6170 MovDelay[newx][newy] = 0; /* start amoeba shrinking delay */
6172 return; /* wait for shrinking amoeba */
6174 else /* element == EL_PACMAN */
6176 Feld[newx][newy] = EL_EMPTY;
6177 DrawLevelField(newx, newy);
6178 PlayLevelSound(x, y, SND_PACMAN_DIGGING);
6181 else if (element == EL_MOLE && IN_LEV_FIELD(newx, newy) &&
6182 (Feld[newx][newy] == EL_AMOEBA_SHRINKING ||
6183 (Feld[newx][newy] == EL_EMPTY && Stop[newx][newy])))
6185 /* wait for shrinking amoeba to completely disappear */
6188 else if (!IN_LEV_FIELD(newx, newy) || !IS_FREE(newx, newy))
6190 /* object was running against a wall */
6195 /* !!! NEW "CE_BLOCKED" STUFF !!! -- DOES NOT WORK YET... !!! */
6196 if (move_pattern & MV_ANY_DIRECTION &&
6197 move_pattern == MovDir[x][y])
6199 int blocking_element =
6200 (IN_LEV_FIELD(newx, newy) ? Feld[newx][newy] : BorderElement);
6202 CheckElementChangeBySide(x, y, element, blocking_element, CE_BLOCKED,
6205 element = Feld[x][y]; /* element might have changed */
6209 if (GFX_ELEMENT(element) != EL_SAND) /* !!! FIX THIS (crumble) !!! */
6210 DrawLevelElementAnimation(x, y, element);
6212 if (DONT_TOUCH(element))
6213 TestIfBadThingTouchesPlayer(x, y);
6218 InitMovingField(x, y, MovDir[x][y]);
6220 PlayLevelSoundAction(x, y, ACTION_MOVING);
6224 ContinueMoving(x, y);
6227 void ContinueMoving(int x, int y)
6229 int element = Feld[x][y];
6230 struct ElementInfo *ei = &element_info[element];
6231 int direction = MovDir[x][y];
6232 int dx = (direction == MV_LEFT ? -1 : direction == MV_RIGHT ? +1 : 0);
6233 int dy = (direction == MV_UP ? -1 : direction == MV_DOWN ? +1 : 0);
6234 int newx = x + dx, newy = y + dy;
6235 int stored = Store[x][y];
6236 int stored_new = Store[newx][newy];
6237 boolean pushed_by_player = (Pushed[x][y] && IS_PLAYER(x, y));
6238 boolean pushed_by_conveyor = (Pushed[x][y] && !IS_PLAYER(x, y));
6239 boolean last_line = (newy == lev_fieldy - 1);
6241 MovPos[x][y] += getElementMoveStepsize(x, y);
6243 if (pushed_by_player) /* special case: moving object pushed by player */
6244 MovPos[x][y] = SIGN(MovPos[x][y]) * (TILEX - ABS(PLAYERINFO(x,y)->MovPos));
6246 if (ABS(MovPos[x][y]) < TILEX)
6248 DrawLevelField(x, y);
6250 return; /* element is still moving */
6253 /* element reached destination field */
6255 Feld[x][y] = EL_EMPTY;
6256 Feld[newx][newy] = element;
6257 MovPos[x][y] = 0; /* force "not moving" for "crumbled sand" */
6259 if (Store[x][y] == EL_ACID) /* element is moving into acid pool */
6261 element = Feld[newx][newy] = EL_ACID;
6263 else if (element == EL_MOLE)
6265 Feld[x][y] = EL_SAND;
6267 DrawLevelFieldCrumbledSandNeighbours(x, y);
6269 else if (element == EL_QUICKSAND_FILLING)
6271 element = Feld[newx][newy] = get_next_element(element);
6272 Store[newx][newy] = Store[x][y];
6274 else if (element == EL_QUICKSAND_EMPTYING)
6276 Feld[x][y] = get_next_element(element);
6277 element = Feld[newx][newy] = Store[x][y];
6279 else if (element == EL_MAGIC_WALL_FILLING)
6281 element = Feld[newx][newy] = get_next_element(element);
6282 if (!game.magic_wall_active)
6283 element = Feld[newx][newy] = EL_MAGIC_WALL_DEAD;
6284 Store[newx][newy] = Store[x][y];
6286 else if (element == EL_MAGIC_WALL_EMPTYING)
6288 Feld[x][y] = get_next_element(element);
6289 if (!game.magic_wall_active)
6290 Feld[x][y] = EL_MAGIC_WALL_DEAD;
6291 element = Feld[newx][newy] = Store[x][y];
6293 #if USE_NEW_CUSTOM_VALUE
6294 InitField(newx, newy, FALSE);
6297 else if (element == EL_BD_MAGIC_WALL_FILLING)
6299 element = Feld[newx][newy] = get_next_element(element);
6300 if (!game.magic_wall_active)
6301 element = Feld[newx][newy] = EL_BD_MAGIC_WALL_DEAD;
6302 Store[newx][newy] = Store[x][y];
6304 else if (element == EL_BD_MAGIC_WALL_EMPTYING)
6306 Feld[x][y] = get_next_element(element);
6307 if (!game.magic_wall_active)
6308 Feld[x][y] = EL_BD_MAGIC_WALL_DEAD;
6309 element = Feld[newx][newy] = Store[x][y];
6311 #if USE_NEW_CUSTOM_VALUE
6312 InitField(newx, newy, FALSE);
6315 else if (element == EL_AMOEBA_DROPPING)
6317 Feld[x][y] = get_next_element(element);
6318 element = Feld[newx][newy] = Store[x][y];
6320 else if (element == EL_SOKOBAN_OBJECT)
6323 Feld[x][y] = Back[x][y];
6325 if (Back[newx][newy])
6326 Feld[newx][newy] = EL_SOKOBAN_FIELD_FULL;
6328 Back[x][y] = Back[newx][newy] = 0;
6331 Store[x][y] = EL_EMPTY;
6336 MovDelay[newx][newy] = 0;
6339 if (CAN_CHANGE_OR_HAS_ACTION(element))
6341 if (CAN_CHANGE(element))
6344 /* copy element change control values to new field */
6345 ChangeDelay[newx][newy] = ChangeDelay[x][y];
6346 ChangePage[newx][newy] = ChangePage[x][y];
6347 ChangeCount[newx][newy] = ChangeCount[x][y];
6348 ChangeEvent[newx][newy] = ChangeEvent[x][y];
6351 #if USE_NEW_CUSTOM_VALUE
6352 CustomValue[newx][newy] = CustomValue[x][y];
6358 #if USE_NEW_CUSTOM_VALUE
6359 CustomValue[newx][newy] = CustomValue[x][y];
6363 ChangeDelay[x][y] = 0;
6364 ChangePage[x][y] = -1;
6365 ChangeCount[x][y] = 0;
6366 ChangeEvent[x][y] = -1;
6368 #if USE_NEW_CUSTOM_VALUE
6369 CustomValue[x][y] = 0;
6372 /* copy animation control values to new field */
6373 GfxFrame[newx][newy] = GfxFrame[x][y];
6374 GfxRandom[newx][newy] = GfxRandom[x][y]; /* keep same random value */
6375 GfxAction[newx][newy] = GfxAction[x][y]; /* keep action one frame */
6376 GfxDir[newx][newy] = GfxDir[x][y]; /* keep element direction */
6378 Pushed[x][y] = Pushed[newx][newy] = FALSE;
6380 /* some elements can leave other elements behind after moving */
6382 if (ei->move_leave_element != EL_EMPTY &&
6383 (ei->move_leave_type == LEAVE_TYPE_UNLIMITED || stored != EL_EMPTY) &&
6384 (!IS_PLAYER(x, y) || IS_WALKABLE(ei->move_leave_element)))
6386 if (IS_CUSTOM_ELEMENT(element) && ei->move_leave_element != EL_EMPTY &&
6387 (ei->move_leave_type == LEAVE_TYPE_UNLIMITED || stored != EL_EMPTY) &&
6388 (!IS_PLAYER(x, y) || IS_WALKABLE(ei->move_leave_element)))
6391 int move_leave_element = ei->move_leave_element;
6395 /* this makes it possible to leave the removed element again */
6396 if (ei->move_leave_element == EL_TRIGGER_ELEMENT)
6397 move_leave_element = (stored == EL_ACID ? EL_EMPTY : stored);
6399 /* this makes it possible to leave the removed element again */
6400 if (ei->move_leave_element == EL_TRIGGER_ELEMENT)
6401 move_leave_element = stored;
6404 /* this makes it possible to leave the removed element again */
6405 if (ei->move_leave_type == LEAVE_TYPE_LIMITED &&
6406 ei->move_leave_element == EL_TRIGGER_ELEMENT)
6407 move_leave_element = stored;
6410 Feld[x][y] = move_leave_element;
6412 if (element_info[Feld[x][y]].move_direction_initial == MV_START_PREVIOUS)
6413 MovDir[x][y] = direction;
6415 InitField(x, y, FALSE);
6417 if (GFX_CRUMBLED(Feld[x][y]))
6418 DrawLevelFieldCrumbledSandNeighbours(x, y);
6420 if (ELEM_IS_PLAYER(move_leave_element))
6421 RelocatePlayer(x, y, move_leave_element);
6424 /* do this after checking for left-behind element */
6425 ResetGfxAnimation(x, y); /* reset animation values for old field */
6427 if (!CAN_MOVE(element) ||
6428 (CAN_FALL(element) && direction == MV_DOWN &&
6429 (element == EL_SPRING ||
6430 element_info[element].move_pattern == MV_WHEN_PUSHED ||
6431 element_info[element].move_pattern == MV_WHEN_DROPPED)))
6432 GfxDir[x][y] = MovDir[newx][newy] = 0;
6434 DrawLevelField(x, y);
6435 DrawLevelField(newx, newy);
6437 Stop[newx][newy] = TRUE; /* ignore this element until the next frame */
6439 /* prevent pushed element from moving on in pushed direction */
6440 if (pushed_by_player && CAN_MOVE(element) &&
6441 element_info[element].move_pattern & MV_ANY_DIRECTION &&
6442 !(element_info[element].move_pattern & direction))
6443 TurnRound(newx, newy);
6445 /* prevent elements on conveyor belt from moving on in last direction */
6446 if (pushed_by_conveyor && CAN_FALL(element) &&
6447 direction & MV_HORIZONTAL)
6448 MovDir[newx][newy] = 0;
6450 if (!pushed_by_player)
6452 int nextx = newx + dx, nexty = newy + dy;
6453 boolean check_collision_again = IN_LEV_FIELD_AND_IS_FREE(nextx, nexty);
6455 WasJustMoving[newx][newy] = 3;
6457 if (CAN_FALL(element) && direction == MV_DOWN)
6458 WasJustFalling[newx][newy] = 3;
6460 if ((!CAN_FALL(element) || direction == MV_DOWN) && check_collision_again)
6461 CheckCollision[newx][newy] = 2;
6464 if (DONT_TOUCH(element)) /* object may be nasty to player or others */
6466 TestIfBadThingTouchesPlayer(newx, newy);
6467 TestIfBadThingTouchesFriend(newx, newy);
6469 if (!IS_CUSTOM_ELEMENT(element))
6470 TestIfBadThingTouchesOtherBadThing(newx, newy);
6472 else if (element == EL_PENGUIN)
6473 TestIfFriendTouchesBadThing(newx, newy);
6475 /* give the player one last chance (one more frame) to move away */
6476 if (CAN_FALL(element) && direction == MV_DOWN &&
6477 (last_line || (!IS_FREE(x, newy + 1) &&
6478 (!IS_PLAYER(x, newy + 1) ||
6479 game.engine_version < VERSION_IDENT(3,1,1,0)))))
6482 if (pushed_by_player && !game.use_change_when_pushing_bug)
6484 int push_side = MV_DIR_OPPOSITE(direction);
6485 struct PlayerInfo *player = PLAYERINFO(x, y);
6487 CheckElementChangeByPlayer(newx, newy, element, CE_PUSHED_BY_PLAYER,
6488 player->index_bit, push_side);
6489 CheckTriggeredElementChangeByPlayer(newx,newy, element, CE_PLAYER_PUSHES_X,
6490 player->index_bit, push_side);
6493 if (element == EL_EMC_ANDROID && pushed_by_player) /* make another move */
6494 MovDelay[newx][newy] = 1;
6496 CheckTriggeredElementChangeBySide(x, y, element, CE_MOVE_OF_X, direction);
6498 TestIfElementTouchesCustomElement(x, y); /* empty or new element */
6501 if (ChangePage[newx][newy] != -1) /* delayed change */
6503 int page = ChangePage[newx][newy];
6504 struct ElementChangeInfo *change = &ei->change_page[page];
6506 ChangePage[newx][newy] = -1;
6508 if (change->can_change)
6510 if (ChangeElement(newx, newy, element, page))
6512 if (change->post_change_function)
6513 change->post_change_function(newx, newy);
6517 if (change->has_action)
6518 ExecuteCustomElementAction(newx, newy, element, page);
6522 TestIfElementHitsCustomElement(newx, newy, direction);
6523 TestIfPlayerTouchesCustomElement(newx, newy);
6524 TestIfElementTouchesCustomElement(newx, newy);
6527 if (IS_CUSTOM_ELEMENT(element) && ei->move_enter_element != EL_EMPTY &&
6528 IS_EQUAL_OR_IN_GROUP(stored_new, ei->move_enter_element))
6529 CheckElementChangeBySide(newx, newy, element, stored_new, CE_DIGGING_X,
6530 MV_DIR_OPPOSITE(direction));
6534 int AmoebeNachbarNr(int ax, int ay)
6537 int element = Feld[ax][ay];
6539 static int xy[4][2] =
6547 for (i = 0; i < NUM_DIRECTIONS; i++)
6549 int x = ax + xy[i][0];
6550 int y = ay + xy[i][1];
6552 if (!IN_LEV_FIELD(x, y))
6555 if (Feld[x][y] == element && AmoebaNr[x][y] > 0)
6556 group_nr = AmoebaNr[x][y];
6562 void AmoebenVereinigen(int ax, int ay)
6564 int i, x, y, xx, yy;
6565 int new_group_nr = AmoebaNr[ax][ay];
6566 static int xy[4][2] =
6574 if (new_group_nr == 0)
6577 for (i = 0; i < NUM_DIRECTIONS; i++)
6582 if (!IN_LEV_FIELD(x, y))
6585 if ((Feld[x][y] == EL_AMOEBA_FULL ||
6586 Feld[x][y] == EL_BD_AMOEBA ||
6587 Feld[x][y] == EL_AMOEBA_DEAD) &&
6588 AmoebaNr[x][y] != new_group_nr)
6590 int old_group_nr = AmoebaNr[x][y];
6592 if (old_group_nr == 0)
6595 AmoebaCnt[new_group_nr] += AmoebaCnt[old_group_nr];
6596 AmoebaCnt[old_group_nr] = 0;
6597 AmoebaCnt2[new_group_nr] += AmoebaCnt2[old_group_nr];
6598 AmoebaCnt2[old_group_nr] = 0;
6601 SCAN_PLAYFIELD(xx, yy)
6603 for (yy = 0; yy < lev_fieldy; yy++) for (xx = 0; xx < lev_fieldx; xx++)
6606 if (AmoebaNr[xx][yy] == old_group_nr)
6607 AmoebaNr[xx][yy] = new_group_nr;
6613 void AmoebeUmwandeln(int ax, int ay)
6617 if (Feld[ax][ay] == EL_AMOEBA_DEAD)
6619 int group_nr = AmoebaNr[ax][ay];
6624 printf("AmoebeUmwandeln(): ax = %d, ay = %d\n", ax, ay);
6625 printf("AmoebeUmwandeln(): This should never happen!\n");
6631 SCAN_PLAYFIELD(x, y)
6633 for (y = 0; y < lev_fieldy; y++) for (x = 0; x < lev_fieldx; x++)
6636 if (Feld[x][y] == EL_AMOEBA_DEAD && AmoebaNr[x][y] == group_nr)
6639 Feld[x][y] = EL_AMOEBA_TO_DIAMOND;
6643 PlayLevelSound(ax, ay, (IS_GEM(level.amoeba_content) ?
6644 SND_AMOEBA_TURNING_TO_GEM :
6645 SND_AMOEBA_TURNING_TO_ROCK));
6650 static int xy[4][2] =
6658 for (i = 0; i < NUM_DIRECTIONS; i++)
6663 if (!IN_LEV_FIELD(x, y))
6666 if (Feld[x][y] == EL_AMOEBA_TO_DIAMOND)
6668 PlayLevelSound(x, y, (IS_GEM(level.amoeba_content) ?
6669 SND_AMOEBA_TURNING_TO_GEM :
6670 SND_AMOEBA_TURNING_TO_ROCK));
6677 void AmoebeUmwandelnBD(int ax, int ay, int new_element)
6680 int group_nr = AmoebaNr[ax][ay];
6681 boolean done = FALSE;
6686 printf("AmoebeUmwandelnBD(): ax = %d, ay = %d\n", ax, ay);
6687 printf("AmoebeUmwandelnBD(): This should never happen!\n");
6693 SCAN_PLAYFIELD(x, y)
6695 for (y = 0; y < lev_fieldy; y++) for (x = 0; x < lev_fieldx; x++)
6698 if (AmoebaNr[x][y] == group_nr &&
6699 (Feld[x][y] == EL_AMOEBA_DEAD ||
6700 Feld[x][y] == EL_BD_AMOEBA ||
6701 Feld[x][y] == EL_AMOEBA_GROWING))
6704 Feld[x][y] = new_element;
6705 InitField(x, y, FALSE);
6706 DrawLevelField(x, y);
6712 PlayLevelSound(ax, ay, (new_element == EL_BD_ROCK ?
6713 SND_BD_AMOEBA_TURNING_TO_ROCK :
6714 SND_BD_AMOEBA_TURNING_TO_GEM));
6717 void AmoebeWaechst(int x, int y)
6719 static unsigned long sound_delay = 0;
6720 static unsigned long sound_delay_value = 0;
6722 if (!MovDelay[x][y]) /* start new growing cycle */
6726 if (DelayReached(&sound_delay, sound_delay_value))
6728 PlayLevelSoundElementAction(x, y, Store[x][y], ACTION_GROWING);
6729 sound_delay_value = 30;
6733 if (MovDelay[x][y]) /* wait some time before growing bigger */
6736 if (MovDelay[x][y]/2 && IN_SCR_FIELD(SCREENX(x), SCREENY(y)))
6738 int frame = getGraphicAnimationFrame(IMG_AMOEBA_GROWING,
6739 6 - MovDelay[x][y]);
6741 DrawGraphic(SCREENX(x), SCREENY(y), IMG_AMOEBA_GROWING, frame);
6744 if (!MovDelay[x][y])
6746 Feld[x][y] = Store[x][y];
6748 DrawLevelField(x, y);
6753 void AmoebaDisappearing(int x, int y)
6755 static unsigned long sound_delay = 0;
6756 static unsigned long sound_delay_value = 0;
6758 if (!MovDelay[x][y]) /* start new shrinking cycle */
6762 if (DelayReached(&sound_delay, sound_delay_value))
6763 sound_delay_value = 30;
6766 if (MovDelay[x][y]) /* wait some time before shrinking */
6769 if (MovDelay[x][y]/2 && IN_SCR_FIELD(SCREENX(x), SCREENY(y)))
6771 int frame = getGraphicAnimationFrame(IMG_AMOEBA_SHRINKING,
6772 6 - MovDelay[x][y]);
6774 DrawGraphic(SCREENX(x), SCREENY(y), IMG_AMOEBA_SHRINKING, frame);
6777 if (!MovDelay[x][y])
6779 Feld[x][y] = EL_EMPTY;
6780 DrawLevelField(x, y);
6782 /* don't let mole enter this field in this cycle;
6783 (give priority to objects falling to this field from above) */
6789 void AmoebeAbleger(int ax, int ay)
6792 int element = Feld[ax][ay];
6793 int graphic = el2img(element);
6794 int newax = ax, neway = ay;
6795 boolean can_drop = (element == EL_AMOEBA_WET || element == EL_EMC_DRIPPER);
6796 static int xy[4][2] =
6804 if (!level.amoeba_speed && element != EL_EMC_DRIPPER)
6806 Feld[ax][ay] = EL_AMOEBA_DEAD;
6807 DrawLevelField(ax, ay);
6811 if (IS_ANIMATED(graphic))
6812 DrawLevelGraphicAnimationIfNeeded(ax, ay, graphic);
6814 if (!MovDelay[ax][ay]) /* start making new amoeba field */
6815 MovDelay[ax][ay] = RND(FRAMES_PER_SECOND * 25 / (1 + level.amoeba_speed));
6817 if (MovDelay[ax][ay]) /* wait some time before making new amoeba */
6820 if (MovDelay[ax][ay])
6824 if (can_drop) /* EL_AMOEBA_WET or EL_EMC_DRIPPER */
6827 int x = ax + xy[start][0];
6828 int y = ay + xy[start][1];
6830 if (!IN_LEV_FIELD(x, y))
6833 if (IS_FREE(x, y) ||
6834 CAN_GROW_INTO(Feld[x][y]) ||
6835 Feld[x][y] == EL_QUICKSAND_EMPTY)
6841 if (newax == ax && neway == ay)
6844 else /* normal or "filled" (BD style) amoeba */
6847 boolean waiting_for_player = FALSE;
6849 for (i = 0; i < NUM_DIRECTIONS; i++)
6851 int j = (start + i) % 4;
6852 int x = ax + xy[j][0];
6853 int y = ay + xy[j][1];
6855 if (!IN_LEV_FIELD(x, y))
6858 if (IS_FREE(x, y) ||
6859 CAN_GROW_INTO(Feld[x][y]) ||
6860 Feld[x][y] == EL_QUICKSAND_EMPTY)
6866 else if (IS_PLAYER(x, y))
6867 waiting_for_player = TRUE;
6870 if (newax == ax && neway == ay) /* amoeba cannot grow */
6872 if (i == 4 && (!waiting_for_player || element == EL_BD_AMOEBA))
6874 Feld[ax][ay] = EL_AMOEBA_DEAD;
6875 DrawLevelField(ax, ay);
6876 AmoebaCnt[AmoebaNr[ax][ay]]--;
6878 if (AmoebaCnt[AmoebaNr[ax][ay]] <= 0) /* amoeba is completely dead */
6880 if (element == EL_AMOEBA_FULL)
6881 AmoebeUmwandeln(ax, ay);
6882 else if (element == EL_BD_AMOEBA)
6883 AmoebeUmwandelnBD(ax, ay, level.amoeba_content);
6888 else if (element == EL_AMOEBA_FULL || element == EL_BD_AMOEBA)
6890 /* amoeba gets larger by growing in some direction */
6892 int new_group_nr = AmoebaNr[ax][ay];
6895 if (new_group_nr == 0)
6897 printf("AmoebeAbleger(): newax = %d, neway = %d\n", newax, neway);
6898 printf("AmoebeAbleger(): This should never happen!\n");
6903 AmoebaNr[newax][neway] = new_group_nr;
6904 AmoebaCnt[new_group_nr]++;
6905 AmoebaCnt2[new_group_nr]++;
6907 /* if amoeba touches other amoeba(s) after growing, unify them */
6908 AmoebenVereinigen(newax, neway);
6910 if (element == EL_BD_AMOEBA && AmoebaCnt2[new_group_nr] >= 200)
6912 AmoebeUmwandelnBD(newax, neway, EL_BD_ROCK);
6918 if (!can_drop || neway < ay || !IS_FREE(newax, neway) ||
6919 (neway == lev_fieldy - 1 && newax != ax))
6921 Feld[newax][neway] = EL_AMOEBA_GROWING; /* creation of new amoeba */
6922 Store[newax][neway] = element;
6924 else if (neway == ay || element == EL_EMC_DRIPPER)
6926 Feld[newax][neway] = EL_AMOEBA_DROP; /* drop left/right of amoeba */
6928 PlayLevelSoundAction(newax, neway, ACTION_GROWING);
6932 InitMovingField(ax, ay, MV_DOWN); /* drop dripping from amoeba */
6933 Feld[ax][ay] = EL_AMOEBA_DROPPING;
6934 Store[ax][ay] = EL_AMOEBA_DROP;
6935 ContinueMoving(ax, ay);
6939 DrawLevelField(newax, neway);
6942 void Life(int ax, int ay)
6946 static int life[4] = { 2, 3, 3, 3 }; /* parameters for "game of life" */
6949 int element = Feld[ax][ay];
6950 int graphic = el2img(element);
6951 int *life_parameter = (element == EL_GAME_OF_LIFE ? level.game_of_life :
6953 boolean changed = FALSE;
6955 if (IS_ANIMATED(graphic))
6956 DrawLevelGraphicAnimationIfNeeded(ax, ay, graphic);
6961 if (!MovDelay[ax][ay]) /* start new "game of life" cycle */
6962 MovDelay[ax][ay] = life_time;
6964 if (MovDelay[ax][ay]) /* wait some time before next cycle */
6967 if (MovDelay[ax][ay])
6971 for (y1 = -1; y1 < 2; y1++) for (x1 = -1; x1 < 2; x1++)
6973 int xx = ax+x1, yy = ay+y1;
6976 if (!IN_LEV_FIELD(xx, yy))
6979 for (y2 = -1; y2 < 2; y2++) for (x2 = -1; x2 < 2; x2++)
6981 int x = xx+x2, y = yy+y2;
6983 if (!IN_LEV_FIELD(x, y) || (x == xx && y == yy))
6986 if (((Feld[x][y] == element ||
6987 (element == EL_GAME_OF_LIFE && IS_PLAYER(x, y))) &&
6989 (IS_FREE(x, y) && Stop[x][y]))
6993 if (xx == ax && yy == ay) /* field in the middle */
6995 if (nachbarn < life_parameter[0] ||
6996 nachbarn > life_parameter[1])
6998 Feld[xx][yy] = EL_EMPTY;
7000 DrawLevelField(xx, yy);
7001 Stop[xx][yy] = TRUE;
7005 else if (IS_FREE(xx, yy) || CAN_GROW_INTO(Feld[xx][yy]))
7006 { /* free border field */
7007 if (nachbarn >= life_parameter[2] &&
7008 nachbarn <= life_parameter[3])
7010 Feld[xx][yy] = element;
7011 MovDelay[xx][yy] = (element == EL_GAME_OF_LIFE ? 0 : life_time-1);
7013 DrawLevelField(xx, yy);
7014 Stop[xx][yy] = TRUE;
7021 PlayLevelSound(ax, ay, element == EL_BIOMAZE ? SND_BIOMAZE_GROWING :
7022 SND_GAME_OF_LIFE_GROWING);
7025 static void InitRobotWheel(int x, int y)
7027 ChangeDelay[x][y] = level.time_wheel * FRAMES_PER_SECOND;
7030 static void RunRobotWheel(int x, int y)
7032 PlayLevelSound(x, y, SND_ROBOT_WHEEL_ACTIVE);
7035 static void StopRobotWheel(int x, int y)
7037 if (ZX == x && ZY == y)
7041 static void InitTimegateWheel(int x, int y)
7043 ChangeDelay[x][y] = level.time_timegate * FRAMES_PER_SECOND;
7046 static void RunTimegateWheel(int x, int y)
7048 PlayLevelSound(x, y, SND_TIMEGATE_SWITCH_ACTIVE);
7051 static void InitMagicBallDelay(int x, int y)
7054 ChangeDelay[x][y] = (level.ball_time + 1) * 8 + 1;
7056 ChangeDelay[x][y] = level.ball_time * FRAMES_PER_SECOND + 1;
7060 static void ActivateMagicBall(int bx, int by)
7064 if (level.ball_random)
7066 int pos_border = RND(8); /* select one of the eight border elements */
7067 int pos_content = (pos_border > 3 ? pos_border + 1 : pos_border);
7068 int xx = pos_content % 3;
7069 int yy = pos_content / 3;
7074 if (IN_LEV_FIELD(x, y) && Feld[x][y] == EL_EMPTY)
7075 CreateField(x, y, level.ball_content[game.ball_content_nr].e[xx][yy]);
7079 for (y = by - 1; y <= by + 1; y++) for (x = bx - 1; x <= bx + 1; x++)
7081 int xx = x - bx + 1;
7082 int yy = y - by + 1;
7084 if (IN_LEV_FIELD(x, y) && Feld[x][y] == EL_EMPTY)
7085 CreateField(x, y, level.ball_content[game.ball_content_nr].e[xx][yy]);
7089 game.ball_content_nr = (game.ball_content_nr + 1) % level.num_ball_contents;
7092 static void InitDiagonalMovingElement(int x, int y)
7095 MovDelay[x][y] = level.android_move_time;
7099 void CheckExit(int x, int y)
7101 if (local_player->gems_still_needed > 0 ||
7102 local_player->sokobanfields_still_needed > 0 ||
7103 local_player->lights_still_needed > 0)
7105 int element = Feld[x][y];
7106 int graphic = el2img(element);
7108 if (IS_ANIMATED(graphic))
7109 DrawLevelGraphicAnimationIfNeeded(x, y, graphic);
7114 if (AllPlayersGone) /* do not re-open exit door closed after last player */
7117 Feld[x][y] = EL_EXIT_OPENING;
7119 PlayLevelSoundNearest(x, y, SND_CLASS_EXIT_OPENING);
7122 void CheckExitSP(int x, int y)
7124 if (local_player->gems_still_needed > 0)
7126 int element = Feld[x][y];
7127 int graphic = el2img(element);
7129 if (IS_ANIMATED(graphic))
7130 DrawLevelGraphicAnimationIfNeeded(x, y, graphic);
7135 if (AllPlayersGone) /* do not re-open exit door closed after last player */
7138 Feld[x][y] = EL_SP_EXIT_OPENING;
7140 PlayLevelSoundNearest(x, y, SND_CLASS_SP_EXIT_OPENING);
7143 static void CloseAllOpenTimegates()
7148 SCAN_PLAYFIELD(x, y)
7150 for (y = 0; y < lev_fieldy; y++) for (x = 0; x < lev_fieldx; x++)
7153 int element = Feld[x][y];
7155 if (element == EL_TIMEGATE_OPEN || element == EL_TIMEGATE_OPENING)
7157 Feld[x][y] = EL_TIMEGATE_CLOSING;
7159 PlayLevelSoundAction(x, y, ACTION_CLOSING);
7164 void EdelsteinFunkeln(int x, int y)
7166 if (!IN_SCR_FIELD(SCREENX(x), SCREENY(y)) || IS_MOVING(x, y))
7169 if (Feld[x][y] == EL_BD_DIAMOND)
7172 if (MovDelay[x][y] == 0) /* next animation frame */
7173 MovDelay[x][y] = 11 * !SimpleRND(500);
7175 if (MovDelay[x][y] != 0) /* wait some time before next frame */
7179 if (setup.direct_draw && MovDelay[x][y])
7180 SetDrawtoField(DRAW_BUFFERED);
7182 DrawLevelElementAnimation(x, y, Feld[x][y]);
7184 if (MovDelay[x][y] != 0)
7186 int frame = getGraphicAnimationFrame(IMG_TWINKLE_WHITE,
7187 10 - MovDelay[x][y]);
7189 DrawGraphicThruMask(SCREENX(x), SCREENY(y), IMG_TWINKLE_WHITE, frame);
7191 if (setup.direct_draw)
7195 dest_x = FX + SCREENX(x) * TILEX;
7196 dest_y = FY + SCREENY(y) * TILEY;
7198 BlitBitmap(drawto_field, window,
7199 dest_x, dest_y, TILEX, TILEY, dest_x, dest_y);
7200 SetDrawtoField(DRAW_DIRECT);
7206 void MauerWaechst(int x, int y)
7210 if (!MovDelay[x][y]) /* next animation frame */
7211 MovDelay[x][y] = 3 * delay;
7213 if (MovDelay[x][y]) /* wait some time before next frame */
7217 if (IN_SCR_FIELD(SCREENX(x), SCREENY(y)))
7219 int graphic = el_dir2img(Feld[x][y], GfxDir[x][y]);
7220 int frame = getGraphicAnimationFrame(graphic, 17 - MovDelay[x][y]);
7222 DrawGraphic(SCREENX(x), SCREENY(y), graphic, frame);
7225 if (!MovDelay[x][y])
7227 if (MovDir[x][y] == MV_LEFT)
7229 if (IN_LEV_FIELD(x - 1, y) && IS_WALL(Feld[x - 1][y]))
7230 DrawLevelField(x - 1, y);
7232 else if (MovDir[x][y] == MV_RIGHT)
7234 if (IN_LEV_FIELD(x + 1, y) && IS_WALL(Feld[x + 1][y]))
7235 DrawLevelField(x + 1, y);
7237 else if (MovDir[x][y] == MV_UP)
7239 if (IN_LEV_FIELD(x, y - 1) && IS_WALL(Feld[x][y - 1]))
7240 DrawLevelField(x, y - 1);
7244 if (IN_LEV_FIELD(x, y + 1) && IS_WALL(Feld[x][y + 1]))
7245 DrawLevelField(x, y + 1);
7248 Feld[x][y] = Store[x][y];
7250 GfxDir[x][y] = MovDir[x][y] = MV_NONE;
7251 DrawLevelField(x, y);
7256 void MauerAbleger(int ax, int ay)
7258 int element = Feld[ax][ay];
7259 int graphic = el2img(element);
7260 boolean oben_frei = FALSE, unten_frei = FALSE;
7261 boolean links_frei = FALSE, rechts_frei = FALSE;
7262 boolean oben_massiv = FALSE, unten_massiv = FALSE;
7263 boolean links_massiv = FALSE, rechts_massiv = FALSE;
7264 boolean new_wall = FALSE;
7266 if (IS_ANIMATED(graphic))
7267 DrawLevelGraphicAnimationIfNeeded(ax, ay, graphic);
7269 if (!MovDelay[ax][ay]) /* start building new wall */
7270 MovDelay[ax][ay] = 6;
7272 if (MovDelay[ax][ay]) /* wait some time before building new wall */
7275 if (MovDelay[ax][ay])
7279 if (IN_LEV_FIELD(ax, ay-1) && IS_FREE(ax, ay-1))
7281 if (IN_LEV_FIELD(ax, ay+1) && IS_FREE(ax, ay+1))
7283 if (IN_LEV_FIELD(ax-1, ay) && IS_FREE(ax-1, ay))
7285 if (IN_LEV_FIELD(ax+1, ay) && IS_FREE(ax+1, ay))
7288 if (element == EL_EXPANDABLE_WALL_VERTICAL ||
7289 element == EL_EXPANDABLE_WALL_ANY)
7293 Feld[ax][ay-1] = EL_EXPANDABLE_WALL_GROWING;
7294 Store[ax][ay-1] = element;
7295 GfxDir[ax][ay-1] = MovDir[ax][ay-1] = MV_UP;
7296 if (IN_SCR_FIELD(SCREENX(ax), SCREENY(ay-1)))
7297 DrawGraphic(SCREENX(ax), SCREENY(ay - 1),
7298 IMG_EXPANDABLE_WALL_GROWING_UP, 0);
7303 Feld[ax][ay+1] = EL_EXPANDABLE_WALL_GROWING;
7304 Store[ax][ay+1] = element;
7305 GfxDir[ax][ay+1] = MovDir[ax][ay+1] = MV_DOWN;
7306 if (IN_SCR_FIELD(SCREENX(ax), SCREENY(ay+1)))
7307 DrawGraphic(SCREENX(ax), SCREENY(ay + 1),
7308 IMG_EXPANDABLE_WALL_GROWING_DOWN, 0);
7313 if (element == EL_EXPANDABLE_WALL_HORIZONTAL ||
7314 element == EL_EXPANDABLE_WALL_ANY ||
7315 element == EL_EXPANDABLE_WALL)
7319 Feld[ax-1][ay] = EL_EXPANDABLE_WALL_GROWING;
7320 Store[ax-1][ay] = element;
7321 GfxDir[ax-1][ay] = MovDir[ax-1][ay] = MV_LEFT;
7322 if (IN_SCR_FIELD(SCREENX(ax-1), SCREENY(ay)))
7323 DrawGraphic(SCREENX(ax - 1), SCREENY(ay),
7324 IMG_EXPANDABLE_WALL_GROWING_LEFT, 0);
7330 Feld[ax+1][ay] = EL_EXPANDABLE_WALL_GROWING;
7331 Store[ax+1][ay] = element;
7332 GfxDir[ax+1][ay] = MovDir[ax+1][ay] = MV_RIGHT;
7333 if (IN_SCR_FIELD(SCREENX(ax+1), SCREENY(ay)))
7334 DrawGraphic(SCREENX(ax + 1), SCREENY(ay),
7335 IMG_EXPANDABLE_WALL_GROWING_RIGHT, 0);
7340 if (element == EL_EXPANDABLE_WALL && (links_frei || rechts_frei))
7341 DrawLevelField(ax, ay);
7343 if (!IN_LEV_FIELD(ax, ay-1) || IS_WALL(Feld[ax][ay-1]))
7345 if (!IN_LEV_FIELD(ax, ay+1) || IS_WALL(Feld[ax][ay+1]))
7346 unten_massiv = TRUE;
7347 if (!IN_LEV_FIELD(ax-1, ay) || IS_WALL(Feld[ax-1][ay]))
7348 links_massiv = TRUE;
7349 if (!IN_LEV_FIELD(ax+1, ay) || IS_WALL(Feld[ax+1][ay]))
7350 rechts_massiv = TRUE;
7352 if (((oben_massiv && unten_massiv) ||
7353 element == EL_EXPANDABLE_WALL_HORIZONTAL ||
7354 element == EL_EXPANDABLE_WALL) &&
7355 ((links_massiv && rechts_massiv) ||
7356 element == EL_EXPANDABLE_WALL_VERTICAL))
7357 Feld[ax][ay] = EL_WALL;
7360 PlayLevelSoundAction(ax, ay, ACTION_GROWING);
7363 void CheckForDragon(int x, int y)
7366 boolean dragon_found = FALSE;
7367 static int xy[4][2] =
7375 for (i = 0; i < NUM_DIRECTIONS; i++)
7377 for (j = 0; j < 4; j++)
7379 int xx = x + j * xy[i][0], yy = y + j * xy[i][1];
7381 if (IN_LEV_FIELD(xx, yy) &&
7382 (Feld[xx][yy] == EL_FLAMES || Feld[xx][yy] == EL_DRAGON))
7384 if (Feld[xx][yy] == EL_DRAGON)
7385 dragon_found = TRUE;
7394 for (i = 0; i < NUM_DIRECTIONS; i++)
7396 for (j = 0; j < 3; j++)
7398 int xx = x + j * xy[i][0], yy = y + j * xy[i][1];
7400 if (IN_LEV_FIELD(xx, yy) && Feld[xx][yy] == EL_FLAMES)
7402 Feld[xx][yy] = EL_EMPTY;
7403 DrawLevelField(xx, yy);
7412 static void InitBuggyBase(int x, int y)
7414 int element = Feld[x][y];
7415 int activating_delay = FRAMES_PER_SECOND / 4;
7418 (element == EL_SP_BUGGY_BASE ?
7419 2 * FRAMES_PER_SECOND + RND(5 * FRAMES_PER_SECOND) - activating_delay :
7420 element == EL_SP_BUGGY_BASE_ACTIVATING ?
7422 element == EL_SP_BUGGY_BASE_ACTIVE ?
7423 1 * FRAMES_PER_SECOND + RND(1 * FRAMES_PER_SECOND) : 1);
7426 static void WarnBuggyBase(int x, int y)
7429 static int xy[4][2] =
7437 for (i = 0; i < NUM_DIRECTIONS; i++)
7439 int xx = x + xy[i][0];
7440 int yy = y + xy[i][1];
7442 if (IN_LEV_FIELD(xx, yy) && IS_PLAYER(xx, yy))
7444 PlayLevelSound(x, y, SND_SP_BUGGY_BASE_ACTIVE);
7451 static void InitTrap(int x, int y)
7453 ChangeDelay[x][y] = 2 * FRAMES_PER_SECOND + RND(5 * FRAMES_PER_SECOND);
7456 static void ActivateTrap(int x, int y)
7458 PlayLevelSound(x, y, SND_TRAP_ACTIVATING);
7461 static void ChangeActiveTrap(int x, int y)
7463 int graphic = IMG_TRAP_ACTIVE;
7465 /* if new animation frame was drawn, correct crumbled sand border */
7466 if (IS_NEW_FRAME(GfxFrame[x][y], graphic))
7467 DrawLevelFieldCrumbledSand(x, y);
7470 static int getSpecialActionElement(int element, int number, int base_element)
7472 return (element != EL_EMPTY ? element :
7473 number != -1 ? base_element + number - 1 :
7477 static int getModifiedActionNumber(int value_old, int operator, int operand,
7478 int value_min, int value_max)
7480 int value_new = (operator == CA_MODE_SET ? operand :
7481 operator == CA_MODE_ADD ? value_old + operand :
7482 operator == CA_MODE_SUBTRACT ? value_old - operand :
7483 operator == CA_MODE_MULTIPLY ? value_old * operand :
7484 operator == CA_MODE_DIVIDE ? value_old / MAX(1, operand) :
7485 operator == CA_MODE_MODULO ? value_old % MAX(1, operand) :
7488 return (value_new < value_min ? value_min :
7489 value_new > value_max ? value_max :
7493 static void ExecuteCustomElementAction(int x, int y, int element, int page)
7495 struct ElementInfo *ei = &element_info[element];
7496 struct ElementChangeInfo *change = &ei->change_page[page];
7497 int action_type = change->action_type;
7498 int action_mode = change->action_mode;
7499 int action_arg = change->action_arg;
7502 if (!change->has_action)
7505 /* ---------- determine action paramater values -------------------------- */
7507 int level_time_value =
7508 (level.time > 0 ? TimeLeft :
7511 int action_arg_element =
7512 (action_arg == CA_ARG_PLAYER_TRIGGER ? change->actual_trigger_player :
7513 action_arg == CA_ARG_ELEMENT_TRIGGER ? change->actual_trigger_element :
7514 action_arg == CA_ARG_ELEMENT_TARGET ? change->target_element :
7517 int action_arg_direction =
7518 (action_arg >= CA_ARG_DIRECTION_LEFT &&
7519 action_arg <= CA_ARG_DIRECTION_DOWN ? action_arg - CA_ARG_DIRECTION :
7520 action_arg == CA_ARG_DIRECTION_TRIGGER ?
7521 change->actual_trigger_side :
7522 action_arg == CA_ARG_DIRECTION_TRIGGER_BACK ?
7523 MV_DIR_OPPOSITE(change->actual_trigger_side) :
7526 int action_arg_number_min =
7527 (action_type == CA_SET_PLAYER_SPEED ? STEPSIZE_NOT_MOVING :
7530 int action_arg_number_max =
7531 (action_type == CA_SET_PLAYER_SPEED ? STEPSIZE_EVEN_FASTER :
7532 action_type == CA_SET_LEVEL_GEMS ? 999 :
7533 action_type == CA_SET_LEVEL_TIME ? 9999 :
7534 action_type == CA_SET_LEVEL_SCORE ? 99999 :
7535 action_type == CA_SET_CE_SCORE ? 9999 :
7536 action_type == CA_SET_CE_VALUE ? 9999 :
7539 int action_arg_number_reset =
7540 (action_type == CA_SET_PLAYER_SPEED ? level.initial_player_stepsize :
7541 action_type == CA_SET_LEVEL_GEMS ? level.gems_needed :
7542 action_type == CA_SET_LEVEL_TIME ? level.time :
7543 action_type == CA_SET_LEVEL_SCORE ? 0 :
7544 action_type == CA_SET_CE_SCORE ? 0 :
7546 action_type == CA_SET_CE_VALUE ? GET_NEW_CUSTOM_VALUE(element) :
7548 action_type == CA_SET_CE_VALUE ? ei->custom_value_initial :
7552 int action_arg_number =
7553 (action_arg <= CA_ARG_MAX ? action_arg :
7554 action_arg >= CA_ARG_SPEED_NOT_MOVING &&
7555 action_arg <= CA_ARG_SPEED_EVEN_FASTER ? (action_arg - CA_ARG_SPEED) :
7556 action_arg == CA_ARG_SPEED_RESET ? action_arg_number_reset :
7557 action_arg == CA_ARG_NUMBER_MIN ? action_arg_number_min :
7558 action_arg == CA_ARG_NUMBER_MAX ? action_arg_number_max :
7559 action_arg == CA_ARG_NUMBER_RESET ? action_arg_number_reset :
7560 action_arg == CA_ARG_NUMBER_CE_SCORE ? ei->collect_score :
7561 #if USE_NEW_CUSTOM_VALUE
7562 action_arg == CA_ARG_NUMBER_CE_VALUE ? CustomValue[x][y] :
7564 action_arg == CA_ARG_NUMBER_CE_VALUE ? ei->custom_value_initial :
7566 action_arg == CA_ARG_NUMBER_CE_DELAY ? GET_CE_DELAY_VALUE(change) :
7567 action_arg == CA_ARG_NUMBER_LEVEL_TIME ? level_time_value :
7568 action_arg == CA_ARG_NUMBER_LEVEL_GEMS ? local_player->gems_still_needed :
7569 action_arg == CA_ARG_NUMBER_LEVEL_SCORE ? local_player->score :
7570 action_arg == CA_ARG_ELEMENT_CV_TARGET ? GET_NEW_CUSTOM_VALUE(change->target_element) :
7571 action_arg == CA_ARG_ELEMENT_CV_TRIGGER ? change->actual_trigger_ce_value:
7572 action_arg == CA_ARG_ELEMENT_NR_TARGET ? change->target_element :
7573 action_arg == CA_ARG_ELEMENT_NR_TRIGGER ? change->actual_trigger_element :
7576 int action_arg_number_old =
7577 (action_type == CA_SET_LEVEL_GEMS ? local_player->gems_still_needed :
7578 action_type == CA_SET_LEVEL_TIME ? TimeLeft :
7579 action_type == CA_SET_LEVEL_SCORE ? local_player->score :
7580 action_type == CA_SET_CE_SCORE ? ei->collect_score :
7581 action_type == CA_SET_CE_VALUE ? CustomValue[x][y] :
7584 int action_arg_number_new =
7585 getModifiedActionNumber(action_arg_number_old,
7586 action_mode, action_arg_number,
7587 action_arg_number_min, action_arg_number_max);
7589 int trigger_player_bits =
7590 (change->actual_trigger_player >= EL_PLAYER_1 &&
7591 change->actual_trigger_player <= EL_PLAYER_4 ?
7592 (1 << (change->actual_trigger_player - EL_PLAYER_1)) :
7595 int action_arg_player_bits =
7596 (action_arg >= CA_ARG_PLAYER_1 &&
7597 action_arg <= CA_ARG_PLAYER_4 ? action_arg - CA_ARG_PLAYER :
7598 action_arg == CA_ARG_PLAYER_TRIGGER ? trigger_player_bits :
7601 /* ---------- execute action -------------------------------------------- */
7610 /* ---------- level actions ------------------------------------------- */
7612 case CA_RESTART_LEVEL:
7614 game.restart_level = TRUE;
7619 case CA_SHOW_ENVELOPE:
7621 int element = getSpecialActionElement(action_arg_element,
7622 action_arg_number, EL_ENVELOPE_1);
7624 if (IS_ENVELOPE(element))
7625 local_player->show_envelope = element;
7630 case CA_SET_LEVEL_TIME:
7632 if (level.time > 0) /* only modify limited time value */
7634 TimeLeft = action_arg_number_new;
7636 DrawGameValue_Time(TimeLeft);
7638 if (!TimeLeft && setup.time_limit)
7639 for (i = 0; i < MAX_PLAYERS; i++)
7640 KillPlayer(&stored_player[i]);
7646 case CA_SET_LEVEL_SCORE:
7648 local_player->score = action_arg_number_new;
7650 DrawGameValue_Score(local_player->score);
7655 case CA_SET_LEVEL_GEMS:
7657 local_player->gems_still_needed = action_arg_number_new;
7659 DrawGameValue_Emeralds(local_player->gems_still_needed);
7664 case CA_SET_LEVEL_GRAVITY:
7666 game.gravity = (action_arg == CA_ARG_GRAVITY_OFF ? FALSE :
7667 action_arg == CA_ARG_GRAVITY_ON ? TRUE :
7668 action_arg == CA_ARG_GRAVITY_TOGGLE ? !game.gravity :
7673 case CA_SET_LEVEL_WIND:
7675 game.wind_direction = action_arg_direction;
7680 /* ---------- player actions ------------------------------------------ */
7682 case CA_MOVE_PLAYER:
7684 /* automatically move to the next field in specified direction */
7685 for (i = 0; i < MAX_PLAYERS; i++)
7686 if (trigger_player_bits & (1 << i))
7687 stored_player[i].programmed_action = action_arg_direction;
7692 case CA_EXIT_PLAYER:
7694 for (i = 0; i < MAX_PLAYERS; i++)
7695 if (action_arg_player_bits & (1 << i))
7696 stored_player[i].LevelSolved = stored_player[i].GameOver = TRUE;
7701 case CA_KILL_PLAYER:
7703 for (i = 0; i < MAX_PLAYERS; i++)
7704 if (action_arg_player_bits & (1 << i))
7705 KillPlayer(&stored_player[i]);
7710 case CA_SET_PLAYER_KEYS:
7712 int key_state = (action_mode == CA_MODE_ADD ? TRUE : FALSE);
7713 int element = getSpecialActionElement(action_arg_element,
7714 action_arg_number, EL_KEY_1);
7716 if (IS_KEY(element))
7718 for (i = 0; i < MAX_PLAYERS; i++)
7720 if (trigger_player_bits & (1 << i))
7722 stored_player[i].key[KEY_NR(element)] = key_state;
7724 DrawGameValue_Keys(stored_player[i].key);
7726 redraw_mask |= REDRAW_DOOR_1;
7734 case CA_SET_PLAYER_SPEED:
7736 for (i = 0; i < MAX_PLAYERS; i++)
7738 if (trigger_player_bits & (1 << i))
7740 int move_stepsize = TILEX / stored_player[i].move_delay_value;
7742 if (action_arg == CA_ARG_SPEED_FASTER &&
7743 stored_player[i].cannot_move)
7745 action_arg_number = STEPSIZE_VERY_SLOW;
7747 else if (action_arg == CA_ARG_SPEED_SLOWER ||
7748 action_arg == CA_ARG_SPEED_FASTER)
7750 action_arg_number = 2;
7751 action_mode = (action_arg == CA_ARG_SPEED_SLOWER ? CA_MODE_DIVIDE :
7756 getModifiedActionNumber(move_stepsize,
7759 action_arg_number_min,
7760 action_arg_number_max);
7763 SetPlayerMoveSpeed(&stored_player[i], move_stepsize, FALSE);
7765 /* make sure that value is power of 2 */
7766 move_stepsize = (1 << log_2(move_stepsize));
7768 /* do no immediately change -- the player might just be moving */
7769 stored_player[i].move_delay_value_next = TILEX / move_stepsize;
7771 stored_player[i].cannot_move =
7772 (action_arg == CA_ARG_SPEED_NOT_MOVING ? TRUE : FALSE);
7780 case CA_SET_PLAYER_SHIELD:
7782 for (i = 0; i < MAX_PLAYERS; i++)
7784 if (trigger_player_bits & (1 << i))
7786 if (action_arg == CA_ARG_SHIELD_OFF)
7788 stored_player[i].shield_normal_time_left = 0;
7789 stored_player[i].shield_deadly_time_left = 0;
7791 else if (action_arg == CA_ARG_SHIELD_NORMAL)
7793 stored_player[i].shield_normal_time_left = 999999;
7795 else if (action_arg == CA_ARG_SHIELD_DEADLY)
7797 stored_player[i].shield_normal_time_left = 999999;
7798 stored_player[i].shield_deadly_time_left = 999999;
7806 case CA_SET_PLAYER_ARTWORK:
7808 for (i = 0; i < MAX_PLAYERS; i++)
7810 if (trigger_player_bits & (1 << i))
7812 int artwork_element = action_arg_element;
7814 if (action_arg == CA_ARG_ELEMENT_RESET)
7816 (level.use_artwork_element[i] ? level.artwork_element[i] :
7817 stored_player[i].element_nr);
7819 stored_player[i].artwork_element = artwork_element;
7821 SetPlayerWaiting(&stored_player[i], FALSE);
7823 /* set number of special actions for bored and sleeping animation */
7824 stored_player[i].num_special_action_bored =
7825 get_num_special_action(artwork_element,
7826 ACTION_BORING_1, ACTION_BORING_LAST);
7827 stored_player[i].num_special_action_sleeping =
7828 get_num_special_action(artwork_element,
7829 ACTION_SLEEPING_1, ACTION_SLEEPING_LAST);
7836 /* ---------- CE actions ---------------------------------------------- */
7838 case CA_SET_CE_SCORE:
7840 ei->collect_score = action_arg_number_new;
7845 case CA_SET_CE_VALUE:
7847 #if USE_NEW_CUSTOM_VALUE
7848 int last_custom_value = CustomValue[x][y];
7850 CustomValue[x][y] = action_arg_number_new;
7853 printf("::: Count == %d\n", CustomValue[x][y]);
7856 if (CustomValue[x][y] == 0 && last_custom_value > 0)
7859 printf("::: CE_VALUE_GETS_ZERO\n");
7862 CheckElementChange(x, y, element, EL_UNDEFINED, CE_VALUE_GETS_ZERO);
7863 CheckTriggeredElementChange(x, y, element, CE_VALUE_GETS_ZERO_OF_X);
7866 printf("::: RESULT: %d, %d\n", Feld[x][y], ChangePage[x][y]);
7874 /* ---------- engine actions ------------------------------------------ */
7876 case CA_SET_ENGINE_SCAN_MODE:
7878 InitPlayfieldScanMode(action_arg);
7888 static void CreateFieldExt(int x, int y, int element, boolean is_change)
7890 int previous_move_direction = MovDir[x][y];
7891 #if USE_NEW_CUSTOM_VALUE
7892 int last_ce_value = CustomValue[x][y];
7894 boolean add_player = (ELEM_IS_PLAYER(element) &&
7895 IS_WALKABLE(Feld[x][y]));
7897 /* check if element under player changes from accessible to unaccessible
7898 (needed for special case of dropping element which then changes) */
7899 if (IS_PLAYER(x, y) && !PLAYER_EXPLOSION_PROTECTED(x, y) &&
7900 IS_ACCESSIBLE(Feld[x][y]) && !IS_ACCESSIBLE(element))
7909 if (IS_MOVING(x, y) || IS_BLOCKED(x, y))
7910 RemoveMovingField(x, y);
7914 Feld[x][y] = element;
7916 ResetGfxAnimation(x, y);
7917 ResetRandomAnimationValue(x, y);
7919 if (element_info[Feld[x][y]].move_direction_initial == MV_START_PREVIOUS)
7920 MovDir[x][y] = previous_move_direction;
7922 #if USE_NEW_CUSTOM_VALUE
7923 if (element_info[Feld[x][y]].use_last_ce_value)
7924 CustomValue[x][y] = last_ce_value;
7927 InitField_WithBug1(x, y, FALSE);
7929 DrawLevelField(x, y);
7931 if (GFX_CRUMBLED(Feld[x][y]))
7932 DrawLevelFieldCrumbledSandNeighbours(x, y);
7935 /* "ChangeCount" not set yet to allow "entered by player" change one time */
7936 if (ELEM_IS_PLAYER(element))
7937 RelocatePlayer(x, y, element);
7940 ChangeCount[x][y]++; /* count number of changes in the same frame */
7942 TestIfBadThingTouchesPlayer(x, y);
7943 TestIfPlayerTouchesCustomElement(x, y);
7944 TestIfElementTouchesCustomElement(x, y);
7947 static void CreateField(int x, int y, int element)
7949 CreateFieldExt(x, y, element, FALSE);
7952 static void CreateElementFromChange(int x, int y, int element)
7954 element = GET_VALID_RUNTIME_ELEMENT(element);
7956 #if USE_STOP_CHANGED_ELEMENTS
7957 if (game.engine_version >= VERSION_IDENT(3,2,0,7))
7959 int old_element = Feld[x][y];
7961 /* prevent changed element from moving in same engine frame
7962 unless both old and new element can either fall or move */
7963 if ((!CAN_FALL(old_element) || !CAN_FALL(element)) &&
7964 (!CAN_MOVE(old_element) || !CAN_MOVE(element)))
7969 CreateFieldExt(x, y, element, TRUE);
7972 static boolean ChangeElement(int x, int y, int element, int page)
7974 struct ElementChangeInfo *change = &element_info[element].change_page[page];
7976 int old_element = Feld[x][y];
7978 /* always use default change event to prevent running into a loop */
7979 if (ChangeEvent[x][y] == -1)
7980 ChangeEvent[x][y] = CE_DELAY;
7982 if (ChangeEvent[x][y] == CE_DELAY)
7984 /* reset actual trigger element, trigger player and action element */
7985 change->actual_trigger_element = EL_EMPTY;
7986 change->actual_trigger_player = EL_PLAYER_1;
7987 change->actual_trigger_side = CH_SIDE_NONE;
7988 change->actual_trigger_ce_value = 0;
7991 /* do not change elements more than a specified maximum number of changes */
7992 if (ChangeCount[x][y] >= game.max_num_changes_per_frame)
7995 ChangeCount[x][y]++; /* count number of changes in the same frame */
7997 if (change->explode)
8004 if (change->use_target_content)
8006 boolean complete_replace = TRUE;
8007 boolean can_replace[3][3];
8010 for (yy = 0; yy < 3; yy++) for (xx = 0; xx < 3 ; xx++)
8013 boolean is_walkable;
8014 boolean is_diggable;
8015 boolean is_collectible;
8016 boolean is_removable;
8017 boolean is_destructible;
8018 int ex = x + xx - 1;
8019 int ey = y + yy - 1;
8020 int content_element = change->target_content.e[xx][yy];
8023 can_replace[xx][yy] = TRUE;
8025 if (ex == x && ey == y) /* do not check changing element itself */
8028 if (content_element == EL_EMPTY_SPACE)
8030 can_replace[xx][yy] = FALSE; /* do not replace border with space */
8035 if (!IN_LEV_FIELD(ex, ey))
8037 can_replace[xx][yy] = FALSE;
8038 complete_replace = FALSE;
8045 if (IS_MOVING(ex, ey) || IS_BLOCKED(ex, ey))
8046 e = MovingOrBlocked2Element(ex, ey);
8048 is_empty = (IS_FREE(ex, ey) ||
8049 (IS_FREE_OR_PLAYER(ex, ey) && IS_WALKABLE(content_element)));
8051 is_walkable = (is_empty || IS_WALKABLE(e));
8052 is_diggable = (is_empty || IS_DIGGABLE(e));
8053 is_collectible = (is_empty || IS_COLLECTIBLE(e));
8054 is_destructible = (is_empty || !IS_INDESTRUCTIBLE(e));
8055 is_removable = (is_diggable || is_collectible);
8057 can_replace[xx][yy] =
8058 (((change->replace_when == CP_WHEN_EMPTY && is_empty) ||
8059 (change->replace_when == CP_WHEN_WALKABLE && is_walkable) ||
8060 (change->replace_when == CP_WHEN_DIGGABLE && is_diggable) ||
8061 (change->replace_when == CP_WHEN_COLLECTIBLE && is_collectible) ||
8062 (change->replace_when == CP_WHEN_REMOVABLE && is_removable) ||
8063 (change->replace_when == CP_WHEN_DESTRUCTIBLE && is_destructible)) &&
8064 !(IS_PLAYER(ex, ey) && ELEM_IS_PLAYER(content_element)));
8066 if (!can_replace[xx][yy])
8067 complete_replace = FALSE;
8070 if (!change->only_if_complete || complete_replace)
8072 boolean something_has_changed = FALSE;
8074 if (change->only_if_complete && change->use_random_replace &&
8075 RND(100) < change->random_percentage)
8078 for (yy = 0; yy < 3; yy++) for (xx = 0; xx < 3 ; xx++)
8080 int ex = x + xx - 1;
8081 int ey = y + yy - 1;
8082 int content_element;
8084 if (can_replace[xx][yy] && (!change->use_random_replace ||
8085 RND(100) < change->random_percentage))
8087 if (IS_MOVING(ex, ey) || IS_BLOCKED(ex, ey))
8088 RemoveMovingField(ex, ey);
8090 ChangeEvent[ex][ey] = ChangeEvent[x][y];
8092 content_element = change->target_content.e[xx][yy];
8093 target_element = GET_TARGET_ELEMENT(content_element, change);
8095 CreateElementFromChange(ex, ey, target_element);
8097 something_has_changed = TRUE;
8099 /* for symmetry reasons, freeze newly created border elements */
8100 if (ex != x || ey != y)
8101 Stop[ex][ey] = TRUE; /* no more moving in this frame */
8105 if (something_has_changed)
8107 PlayLevelSoundElementAction(x, y, element, ACTION_CHANGING);
8108 PlayLevelSoundElementAction(x, y, element, ACTION_PAGE_1 + page);
8114 target_element = GET_TARGET_ELEMENT(change->target_element, change);
8116 if (element == EL_DIAGONAL_GROWING ||
8117 element == EL_DIAGONAL_SHRINKING)
8119 target_element = Store[x][y];
8121 Store[x][y] = EL_EMPTY;
8124 CreateElementFromChange(x, y, target_element);
8126 PlayLevelSoundElementAction(x, y, element, ACTION_CHANGING);
8127 PlayLevelSoundElementAction(x, y, element, ACTION_PAGE_1 + page);
8130 /* this uses direct change before indirect change */
8131 CheckTriggeredElementChangeByPage(x, y, old_element, CE_CHANGE_OF_X, page);
8136 #if USE_NEW_DELAYED_ACTION
8138 static void HandleElementChange(int x, int y, int page)
8140 int element = MovingOrBlocked2Element(x, y);
8141 struct ElementInfo *ei = &element_info[element];
8142 struct ElementChangeInfo *change = &ei->change_page[page];
8145 if (!CAN_CHANGE_OR_HAS_ACTION(element) &&
8146 !CAN_CHANGE_OR_HAS_ACTION(Back[x][y]))
8149 printf("HandleElementChange(): %d,%d: element = %d ('%s')\n",
8150 x, y, element, element_info[element].token_name);
8151 printf("HandleElementChange(): This should never happen!\n");
8156 /* this can happen with classic bombs on walkable, changing elements */
8157 if (!CAN_CHANGE_OR_HAS_ACTION(element))
8160 if (!CAN_CHANGE(Back[x][y])) /* prevent permanent repetition */
8161 ChangeDelay[x][y] = 0;
8167 if (ChangeDelay[x][y] == 0) /* initialize element change */
8169 ChangeDelay[x][y] = GET_CHANGE_DELAY(change) + 1;
8171 if (change->can_change)
8173 ResetGfxAnimation(x, y);
8174 ResetRandomAnimationValue(x, y);
8176 if (change->pre_change_function)
8177 change->pre_change_function(x, y);
8181 ChangeDelay[x][y]--;
8183 if (ChangeDelay[x][y] != 0) /* continue element change */
8185 if (change->can_change)
8187 int graphic = el_act_dir2img(element, GfxAction[x][y], GfxDir[x][y]);
8189 if (IS_ANIMATED(graphic))
8190 DrawLevelGraphicAnimationIfNeeded(x, y, graphic);
8192 if (change->change_function)
8193 change->change_function(x, y);
8196 else /* finish element change */
8198 if (ChangePage[x][y] != -1) /* remember page from delayed change */
8200 page = ChangePage[x][y];
8201 ChangePage[x][y] = -1;
8203 change = &ei->change_page[page];
8206 if (IS_MOVING(x, y)) /* never change a running system ;-) */
8208 ChangeDelay[x][y] = 1; /* try change after next move step */
8209 ChangePage[x][y] = page; /* remember page to use for change */
8214 if (change->can_change)
8216 if (ChangeElement(x, y, element, page))
8218 if (change->post_change_function)
8219 change->post_change_function(x, y);
8223 if (change->has_action)
8224 ExecuteCustomElementAction(x, y, element, page);
8230 static void HandleElementChange(int x, int y, int page)
8232 int element = MovingOrBlocked2Element(x, y);
8233 struct ElementInfo *ei = &element_info[element];
8234 struct ElementChangeInfo *change = &ei->change_page[page];
8237 if (!CAN_CHANGE(element) && !CAN_CHANGE(Back[x][y]))
8240 printf("HandleElementChange(): %d,%d: element = %d ('%s')\n",
8241 x, y, element, element_info[element].token_name);
8242 printf("HandleElementChange(): This should never happen!\n");
8247 /* this can happen with classic bombs on walkable, changing elements */
8248 if (!CAN_CHANGE(element))
8251 if (!CAN_CHANGE(Back[x][y])) /* prevent permanent repetition */
8252 ChangeDelay[x][y] = 0;
8258 if (ChangeDelay[x][y] == 0) /* initialize element change */
8260 ChangeDelay[x][y] = GET_CHANGE_DELAY(change) + 1;
8262 ResetGfxAnimation(x, y);
8263 ResetRandomAnimationValue(x, y);
8265 if (change->pre_change_function)
8266 change->pre_change_function(x, y);
8269 ChangeDelay[x][y]--;
8271 if (ChangeDelay[x][y] != 0) /* continue element change */
8273 int graphic = el_act_dir2img(element, GfxAction[x][y], GfxDir[x][y]);
8275 if (IS_ANIMATED(graphic))
8276 DrawLevelGraphicAnimationIfNeeded(x, y, graphic);
8278 if (change->change_function)
8279 change->change_function(x, y);
8281 else /* finish element change */
8283 if (ChangePage[x][y] != -1) /* remember page from delayed change */
8285 page = ChangePage[x][y];
8286 ChangePage[x][y] = -1;
8288 change = &ei->change_page[page];
8291 if (IS_MOVING(x, y)) /* never change a running system ;-) */
8293 ChangeDelay[x][y] = 1; /* try change after next move step */
8294 ChangePage[x][y] = page; /* remember page to use for change */
8299 if (ChangeElement(x, y, element, page))
8301 if (change->post_change_function)
8302 change->post_change_function(x, y);
8309 static boolean CheckTriggeredElementChangeExt(int trigger_x, int trigger_y,
8310 int trigger_element,
8316 boolean change_done_any = FALSE;
8317 int trigger_page_bits = (trigger_page < 0 ? CH_PAGE_ANY : 1 << trigger_page);
8320 if (!(trigger_events[trigger_element][trigger_event]))
8323 for (i = 0; i < NUM_CUSTOM_ELEMENTS; i++)
8325 int element = EL_CUSTOM_START + i;
8326 boolean change_done = FALSE;
8329 if (!CAN_CHANGE_OR_HAS_ACTION(element) ||
8330 !HAS_ANY_CHANGE_EVENT(element, trigger_event))
8333 for (p = 0; p < element_info[element].num_change_pages; p++)
8335 struct ElementChangeInfo *change = &element_info[element].change_page[p];
8337 if (change->can_change_or_has_action &&
8338 change->has_event[trigger_event] &&
8339 change->trigger_side & trigger_side &&
8340 change->trigger_player & trigger_player &&
8341 change->trigger_page & trigger_page_bits &&
8342 IS_EQUAL_OR_IN_GROUP(trigger_element, change->trigger_element))
8344 change->actual_trigger_element = trigger_element;
8345 change->actual_trigger_player = EL_PLAYER_1 + log_2(trigger_player);
8346 change->actual_trigger_side = trigger_side;
8347 change->actual_trigger_ce_value = CustomValue[trigger_x][trigger_y];
8349 if ((change->can_change && !change_done) || change->has_action)
8354 SCAN_PLAYFIELD(x, y)
8356 for (y = 0; y < lev_fieldy; y++) for (x = 0; x < lev_fieldx; x++)
8359 if (Feld[x][y] == element)
8361 if (change->can_change && !change_done)
8363 ChangeDelay[x][y] = 1;
8364 ChangeEvent[x][y] = trigger_event;
8366 HandleElementChange(x, y, p);
8368 #if USE_NEW_DELAYED_ACTION
8369 else if (change->has_action)
8371 ExecuteCustomElementAction(x, y, element, p);
8372 PlayLevelSoundElementAction(x, y, element, ACTION_PAGE_1 + p);
8375 if (change->has_action)
8377 ExecuteCustomElementAction(x, y, element, p);
8378 PlayLevelSoundElementAction(x, y, element, ACTION_PAGE_1 + p);
8384 if (change->can_change)
8387 change_done_any = TRUE;
8394 return change_done_any;
8397 static boolean CheckElementChangeExt(int x, int y,
8399 int trigger_element,
8404 boolean change_done = FALSE;
8407 if (!CAN_CHANGE_OR_HAS_ACTION(element) ||
8408 !HAS_ANY_CHANGE_EVENT(element, trigger_event))
8411 if (Feld[x][y] == EL_BLOCKED)
8413 Blocked2Moving(x, y, &x, &y);
8414 element = Feld[x][y];
8418 /* check if element has already changed */
8419 if (Feld[x][y] != element)
8422 /* check if element has already changed or is about to change after moving */
8423 if ((game.engine_version < VERSION_IDENT(3,2,0,7) &&
8424 Feld[x][y] != element) ||
8426 (game.engine_version >= VERSION_IDENT(3,2,0,7) &&
8427 (ChangeCount[x][y] >= game.max_num_changes_per_frame ||
8428 ChangePage[x][y] != -1)))
8432 for (p = 0; p < element_info[element].num_change_pages; p++)
8434 struct ElementChangeInfo *change = &element_info[element].change_page[p];
8436 boolean check_trigger_element =
8437 (trigger_event == CE_TOUCHING_X ||
8438 trigger_event == CE_HITTING_X ||
8439 trigger_event == CE_HIT_BY_X);
8441 if (change->can_change_or_has_action &&
8442 change->has_event[trigger_event] &&
8443 change->trigger_side & trigger_side &&
8444 change->trigger_player & trigger_player &&
8445 (!check_trigger_element ||
8446 IS_EQUAL_OR_IN_GROUP(trigger_element, change->trigger_element)))
8448 change->actual_trigger_element = trigger_element;
8449 change->actual_trigger_player = EL_PLAYER_1 + log_2(trigger_player);
8450 change->actual_trigger_side = trigger_side;
8451 change->actual_trigger_ce_value = CustomValue[x][y];
8453 /* special case: trigger element not at (x,y) position for some events */
8454 if (check_trigger_element)
8466 { 0, 0 }, { 0, 0 }, { 0, 0 },
8470 int xx = x + move_xy[MV_DIR_OPPOSITE(trigger_side)].dx;
8471 int yy = y + move_xy[MV_DIR_OPPOSITE(trigger_side)].dy;
8473 change->actual_trigger_ce_value = CustomValue[xx][yy];
8476 if (change->can_change && !change_done)
8478 ChangeDelay[x][y] = 1;
8479 ChangeEvent[x][y] = trigger_event;
8481 HandleElementChange(x, y, p);
8485 #if USE_NEW_DELAYED_ACTION
8486 else if (change->has_action)
8488 ExecuteCustomElementAction(x, y, element, p);
8489 PlayLevelSoundElementAction(x, y, element, ACTION_PAGE_1 + p);
8492 if (change->has_action)
8494 ExecuteCustomElementAction(x, y, element, p);
8495 PlayLevelSoundElementAction(x, y, element, ACTION_PAGE_1 + p);
8504 static void PlayPlayerSound(struct PlayerInfo *player)
8506 int jx = player->jx, jy = player->jy;
8507 int sound_element = player->artwork_element;
8508 int last_action = player->last_action_waiting;
8509 int action = player->action_waiting;
8511 if (player->is_waiting)
8513 if (action != last_action)
8514 PlayLevelSoundElementAction(jx, jy, sound_element, action);
8516 PlayLevelSoundElementActionIfLoop(jx, jy, sound_element, action);
8520 if (action != last_action)
8521 StopSound(element_info[sound_element].sound[last_action]);
8523 if (last_action == ACTION_SLEEPING)
8524 PlayLevelSoundElementAction(jx, jy, sound_element, ACTION_AWAKENING);
8528 static void PlayAllPlayersSound()
8532 for (i = 0; i < MAX_PLAYERS; i++)
8533 if (stored_player[i].active)
8534 PlayPlayerSound(&stored_player[i]);
8537 static void SetPlayerWaiting(struct PlayerInfo *player, boolean is_waiting)
8539 boolean last_waiting = player->is_waiting;
8540 int move_dir = player->MovDir;
8542 player->last_action_waiting = player->action_waiting;
8546 if (!last_waiting) /* not waiting -> waiting */
8548 player->is_waiting = TRUE;
8550 player->frame_counter_bored =
8552 game.player_boring_delay_fixed +
8553 SimpleRND(game.player_boring_delay_random);
8554 player->frame_counter_sleeping =
8556 game.player_sleeping_delay_fixed +
8557 SimpleRND(game.player_sleeping_delay_random);
8559 InitPlayerGfxAnimation(player, ACTION_WAITING, player->MovDir);
8562 if (game.player_sleeping_delay_fixed +
8563 game.player_sleeping_delay_random > 0 &&
8564 player->anim_delay_counter == 0 &&
8565 player->post_delay_counter == 0 &&
8566 FrameCounter >= player->frame_counter_sleeping)
8567 player->is_sleeping = TRUE;
8568 else if (game.player_boring_delay_fixed +
8569 game.player_boring_delay_random > 0 &&
8570 FrameCounter >= player->frame_counter_bored)
8571 player->is_bored = TRUE;
8573 player->action_waiting = (player->is_sleeping ? ACTION_SLEEPING :
8574 player->is_bored ? ACTION_BORING :
8577 if (player->is_sleeping)
8579 if (player->num_special_action_sleeping > 0)
8581 if (player->anim_delay_counter == 0 && player->post_delay_counter == 0)
8583 int last_special_action = player->special_action_sleeping;
8584 int num_special_action = player->num_special_action_sleeping;
8585 int special_action =
8586 (last_special_action == ACTION_DEFAULT ? ACTION_SLEEPING_1 :
8587 last_special_action == ACTION_SLEEPING ? ACTION_SLEEPING :
8588 last_special_action < ACTION_SLEEPING_1 + num_special_action - 1 ?
8589 last_special_action + 1 : ACTION_SLEEPING);
8590 int special_graphic =
8591 el_act_dir2img(player->artwork_element, special_action, move_dir);
8593 player->anim_delay_counter =
8594 graphic_info[special_graphic].anim_delay_fixed +
8595 SimpleRND(graphic_info[special_graphic].anim_delay_random);
8596 player->post_delay_counter =
8597 graphic_info[special_graphic].post_delay_fixed +
8598 SimpleRND(graphic_info[special_graphic].post_delay_random);
8600 player->special_action_sleeping = special_action;
8603 if (player->anim_delay_counter > 0)
8605 player->action_waiting = player->special_action_sleeping;
8606 player->anim_delay_counter--;
8608 else if (player->post_delay_counter > 0)
8610 player->post_delay_counter--;
8614 else if (player->is_bored)
8616 if (player->num_special_action_bored > 0)
8618 if (player->anim_delay_counter == 0 && player->post_delay_counter == 0)
8620 int special_action =
8621 ACTION_BORING_1 + SimpleRND(player->num_special_action_bored);
8622 int special_graphic =
8623 el_act_dir2img(player->artwork_element, special_action, move_dir);
8625 player->anim_delay_counter =
8626 graphic_info[special_graphic].anim_delay_fixed +
8627 SimpleRND(graphic_info[special_graphic].anim_delay_random);
8628 player->post_delay_counter =
8629 graphic_info[special_graphic].post_delay_fixed +
8630 SimpleRND(graphic_info[special_graphic].post_delay_random);
8632 player->special_action_bored = special_action;
8635 if (player->anim_delay_counter > 0)
8637 player->action_waiting = player->special_action_bored;
8638 player->anim_delay_counter--;
8640 else if (player->post_delay_counter > 0)
8642 player->post_delay_counter--;
8647 else if (last_waiting) /* waiting -> not waiting */
8649 player->is_waiting = FALSE;
8650 player->is_bored = FALSE;
8651 player->is_sleeping = FALSE;
8653 player->frame_counter_bored = -1;
8654 player->frame_counter_sleeping = -1;
8656 player->anim_delay_counter = 0;
8657 player->post_delay_counter = 0;
8659 player->action_waiting = ACTION_DEFAULT;
8661 player->special_action_bored = ACTION_DEFAULT;
8662 player->special_action_sleeping = ACTION_DEFAULT;
8666 static byte PlayerActions(struct PlayerInfo *player, byte player_action)
8668 boolean moved = FALSE, snapped = FALSE, dropped = FALSE;
8669 int left = player_action & JOY_LEFT;
8670 int right = player_action & JOY_RIGHT;
8671 int up = player_action & JOY_UP;
8672 int down = player_action & JOY_DOWN;
8673 int button1 = player_action & JOY_BUTTON_1;
8674 int button2 = player_action & JOY_BUTTON_2;
8675 int dx = (left ? -1 : right ? 1 : 0);
8676 int dy = (up ? -1 : down ? 1 : 0);
8678 if (!player->active || tape.pausing)
8684 snapped = SnapField(player, dx, dy);
8688 dropped = DropElement(player);
8690 moved = MovePlayer(player, dx, dy);
8693 if (tape.single_step && tape.recording && !tape.pausing)
8695 if (button1 || (dropped && !moved))
8697 TapeTogglePause(TAPE_TOGGLE_AUTOMATIC);
8698 SnapField(player, 0, 0); /* stop snapping */
8702 SetPlayerWaiting(player, FALSE);
8704 return player_action;
8708 /* no actions for this player (no input at player's configured device) */
8710 DigField(player, 0, 0, 0, 0, 0, 0, DF_NO_PUSH);
8711 SnapField(player, 0, 0);
8712 CheckGravityMovementWhenNotMoving(player);
8714 if (player->MovPos == 0)
8715 SetPlayerWaiting(player, TRUE);
8717 if (player->MovPos == 0) /* needed for tape.playing */
8718 player->is_moving = FALSE;
8720 player->is_dropping = FALSE;
8726 void AdvanceFrameAndPlayerCounters(int player_nr)
8730 /* advance frame counters (global frame counter and time frame counter) */
8734 /* advance player counters (counters for move delay, move animation etc.) */
8735 for (i = 0; i < MAX_PLAYERS; i++)
8737 boolean advance_player_counters = (player_nr == -1 || player_nr == i);
8738 int move_delay_value = stored_player[i].move_delay_value;
8739 int move_frames = MOVE_DELAY_NORMAL_SPEED / move_delay_value;
8741 if (!advance_player_counters) /* not all players may be affected */
8744 #if USE_NEW_PLAYER_ANIM
8745 if (move_frames == 0) /* less than one move per game frame */
8747 int stepsize = TILEX / move_delay_value;
8748 int delay = move_delay_value / MOVE_DELAY_NORMAL_SPEED;
8749 int count = (stored_player[i].is_moving ?
8750 ABS(stored_player[i].MovPos) / stepsize : FrameCounter);
8752 if (count % delay == 0)
8757 stored_player[i].Frame += move_frames;
8759 if (stored_player[i].MovPos != 0)
8760 stored_player[i].StepFrame += move_frames;
8762 if (stored_player[i].move_delay > 0)
8763 stored_player[i].move_delay--;
8765 /* due to bugs in previous versions, counter must count up, not down */
8766 if (stored_player[i].push_delay != -1)
8767 stored_player[i].push_delay++;
8769 if (stored_player[i].drop_delay > 0)
8770 stored_player[i].drop_delay--;
8776 static unsigned long game_frame_delay = 0;
8777 unsigned long game_frame_delay_value;
8778 int magic_wall_x = 0, magic_wall_y = 0;
8779 int i, x, y, element, graphic;
8780 byte *recorded_player_action;
8781 byte summarized_player_action = 0;
8782 byte tape_action[MAX_PLAYERS];
8784 if (game_status != GAME_MODE_PLAYING)
8787 game_frame_delay_value =
8788 (tape.playing && tape.fast_forward ? FfwdFrameDelay : GameFrameDelay);
8790 if (tape.playing && tape.warp_forward && !tape.pausing)
8791 game_frame_delay_value = 0;
8793 /* ---------- main game synchronization point ---------- */
8795 WaitUntilDelayReached(&game_frame_delay, game_frame_delay_value);
8797 InitPlayfieldScanModeVars();
8799 #if USE_ONE_MORE_CHANGE_PER_FRAME
8800 if (game.engine_version >= VERSION_IDENT(3,2,0,7))
8802 SCAN_PLAYFIELD(x, y)
8804 ChangeCount[x][y] = 0;
8805 ChangeEvent[x][y] = -1;
8810 if (network_playing && !network_player_action_received)
8812 /* try to get network player actions in time */
8814 #if defined(NETWORK_AVALIABLE)
8815 /* last chance to get network player actions without main loop delay */
8819 /* game was quit by network peer */
8820 if (game_status != GAME_MODE_PLAYING)
8823 if (!network_player_action_received)
8824 return; /* failed to get network player actions in time */
8830 recorded_player_action = (tape.playing ? TapePlayAction() : NULL);
8833 /* !!! CHECK THIS (tape.pausing is always FALSE here!) !!! */
8834 if (recorded_player_action == NULL && tape.pausing)
8838 for (i = 0; i < MAX_PLAYERS; i++)
8840 summarized_player_action |= stored_player[i].action;
8842 if (!network_playing)
8843 stored_player[i].effective_action = stored_player[i].action;
8846 #if defined(NETWORK_AVALIABLE)
8847 if (network_playing)
8848 SendToServer_MovePlayer(summarized_player_action);
8851 if (!options.network && !setup.team_mode)
8852 local_player->effective_action = summarized_player_action;
8854 if (recorded_player_action != NULL)
8855 for (i = 0; i < MAX_PLAYERS; i++)
8856 stored_player[i].effective_action = recorded_player_action[i];
8858 for (i = 0; i < MAX_PLAYERS; i++)
8860 tape_action[i] = stored_player[i].effective_action;
8862 if (tape.recording && tape_action[i] && !tape.player_participates[i])
8863 tape.player_participates[i] = TRUE; /* player just appeared from CE */
8866 /* only save actions from input devices, but not programmed actions */
8868 TapeRecordAction(tape_action);
8870 for (i = 0; i < MAX_PLAYERS; i++)
8872 int actual_player_action = stored_player[i].effective_action;
8875 /* !!! THIS BREAKS THE FOLLOWING TAPES: !!!
8876 - rnd_equinox_tetrachloride 048
8877 - rnd_equinox_tetrachloride_ii 096
8878 - rnd_emanuel_schmieg 002
8879 - doctor_sloan_ww 001, 020
8881 if (stored_player[i].MovPos == 0)
8882 CheckGravityMovement(&stored_player[i]);
8885 /* overwrite programmed action with tape action */
8886 if (stored_player[i].programmed_action)
8887 actual_player_action = stored_player[i].programmed_action;
8890 PlayerActions(&stored_player[i], actual_player_action);
8892 tape_action[i] = PlayerActions(&stored_player[i], actual_player_action);
8894 if (tape.recording && tape_action[i] && !tape.player_participates[i])
8895 tape.player_participates[i] = TRUE; /* player just appeared from CE */
8898 ScrollPlayer(&stored_player[i], SCROLL_GO_ON);
8901 network_player_action_received = FALSE;
8903 ScrollScreen(NULL, SCROLL_GO_ON);
8905 /* for backwards compatibility, the following code emulates a fixed bug that
8906 occured when pushing elements (causing elements that just made their last
8907 pushing step to already (if possible) make their first falling step in the
8908 same game frame, which is bad); this code is also needed to use the famous
8909 "spring push bug" which is used in older levels and might be wanted to be
8910 used also in newer levels, but in this case the buggy pushing code is only
8911 affecting the "spring" element and no other elements */
8913 if (game.engine_version < VERSION_IDENT(2,2,0,7) || level.use_spring_bug)
8915 for (i = 0; i < MAX_PLAYERS; i++)
8917 struct PlayerInfo *player = &stored_player[i];
8921 if (player->active && player->is_pushing && player->is_moving &&
8923 (game.engine_version < VERSION_IDENT(2,2,0,7) ||
8924 Feld[x][y] == EL_SPRING))
8926 ContinueMoving(x, y);
8928 /* continue moving after pushing (this is actually a bug) */
8929 if (!IS_MOVING(x, y))
8938 SCAN_PLAYFIELD(x, y)
8940 for (y = 0; y < lev_fieldy; y++) for (x = 0; x < lev_fieldx; x++)
8943 ChangeCount[x][y] = 0;
8944 ChangeEvent[x][y] = -1;
8946 /* this must be handled before main playfield loop */
8947 if (Feld[x][y] == EL_PLAYER_IS_LEAVING)
8950 if (MovDelay[x][y] <= 0)
8954 #if USE_NEW_SNAP_DELAY
8955 if (Feld[x][y] == EL_ELEMENT_SNAPPING)
8958 if (MovDelay[x][y] <= 0)
8961 DrawLevelField(x, y);
8963 TestIfElementTouchesCustomElement(x, y); /* for empty space */
8969 if (ChangePage[x][y] != -1 && ChangeDelay[x][y] != 1)
8971 printf("GameActions(): x = %d, y = %d: ChangePage != -1\n", x, y);
8972 printf("GameActions(): This should never happen!\n");
8974 ChangePage[x][y] = -1;
8979 if (WasJustMoving[x][y] > 0)
8980 WasJustMoving[x][y]--;
8981 if (WasJustFalling[x][y] > 0)
8982 WasJustFalling[x][y]--;
8983 if (CheckCollision[x][y] > 0)
8984 CheckCollision[x][y]--;
8988 /* reset finished pushing action (not done in ContinueMoving() to allow
8989 continuous pushing animation for elements with zero push delay) */
8990 if (GfxAction[x][y] == ACTION_PUSHING && !IS_MOVING(x, y))
8992 ResetGfxAnimation(x, y);
8993 DrawLevelField(x, y);
8997 if (IS_BLOCKED(x, y))
9001 Blocked2Moving(x, y, &oldx, &oldy);
9002 if (!IS_MOVING(oldx, oldy))
9004 printf("GameActions(): (BLOCKED => MOVING) context corrupted!\n");
9005 printf("GameActions(): BLOCKED: x = %d, y = %d\n", x, y);
9006 printf("GameActions(): !MOVING: oldx = %d, oldy = %d\n", oldx, oldy);
9007 printf("GameActions(): This should never happen!\n");
9014 SCAN_PLAYFIELD(x, y)
9016 for (y = 0; y < lev_fieldy; y++) for (x = 0; x < lev_fieldx; x++)
9019 element = Feld[x][y];
9020 graphic = el_act_dir2img(element, GfxAction[x][y], GfxDir[x][y]);
9023 printf("::: %d,%d\n", x, y);
9025 if (element == EL_ROCK)
9026 printf("::: Yo man! Rocks can fall!\n");
9029 if (graphic_info[graphic].anim_global_sync)
9030 GfxFrame[x][y] = FrameCounter;
9031 else if (ANIM_MODE(graphic) == ANIM_CE_VALUE)
9033 int old_gfx_frame = GfxFrame[x][y];
9035 GfxFrame[x][y] = CustomValue[x][y];
9038 if (GfxFrame[x][y] != old_gfx_frame)
9040 DrawLevelGraphicAnimation(x, y, graphic);
9042 else if (ANIM_MODE(graphic) == ANIM_CE_SCORE)
9044 int old_gfx_frame = GfxFrame[x][y];
9046 GfxFrame[x][y] = element_info[element].collect_score;
9049 if (GfxFrame[x][y] != old_gfx_frame)
9051 DrawLevelGraphicAnimation(x, y, graphic);
9054 if (ANIM_MODE(graphic) == ANIM_RANDOM &&
9055 IS_NEXT_FRAME(GfxFrame[x][y], graphic))
9056 ResetRandomAnimationValue(x, y);
9058 SetRandomAnimationValue(x, y);
9060 PlayLevelSoundActionIfLoop(x, y, GfxAction[x][y]);
9062 if (IS_INACTIVE(element))
9064 if (IS_ANIMATED(graphic))
9065 DrawLevelGraphicAnimationIfNeeded(x, y, graphic);
9070 /* this may take place after moving, so 'element' may have changed */
9071 if (IS_CHANGING(x, y) &&
9072 (game.engine_version < VERSION_IDENT(3,0,7,1) || !Stop[x][y]))
9074 int page = element_info[element].event_page_nr[CE_DELAY];
9076 HandleElementChange(x, y, ChangePage[x][y] != -1 ? ChangePage[x][y] : page);
9080 printf("::: ChangeDelay == %d\n", ChangeDelay[x][y]);
9084 if (element == EL_CUSTOM_255)
9085 printf("::: ChangeDelay == %d\n", ChangeDelay[x][y]);
9089 HandleElementChange(x, y, page);
9091 if (CAN_CHANGE(element))
9092 HandleElementChange(x, y, page);
9094 if (HAS_ACTION(element))
9095 ExecuteCustomElementAction(x, y, element, page);
9100 element = Feld[x][y];
9101 graphic = el_act_dir2img(element, GfxAction[x][y], GfxDir[x][y]);
9104 if (!IS_MOVING(x, y) && (CAN_FALL(element) || CAN_MOVE(element)))
9108 element = Feld[x][y];
9109 graphic = el_act_dir2img(element, GfxAction[x][y], GfxDir[x][y]);
9111 if (IS_ANIMATED(graphic) &&
9114 DrawLevelGraphicAnimationIfNeeded(x, y, graphic);
9116 if (IS_GEM(element) || element == EL_SP_INFOTRON)
9117 EdelsteinFunkeln(x, y);
9119 else if ((element == EL_ACID ||
9120 element == EL_EXIT_OPEN ||
9121 element == EL_SP_EXIT_OPEN ||
9122 element == EL_SP_TERMINAL ||
9123 element == EL_SP_TERMINAL_ACTIVE ||
9124 element == EL_EXTRA_TIME ||
9125 element == EL_SHIELD_NORMAL ||
9126 element == EL_SHIELD_DEADLY) &&
9127 IS_ANIMATED(graphic))
9128 DrawLevelGraphicAnimationIfNeeded(x, y, graphic);
9129 else if (IS_MOVING(x, y))
9130 ContinueMoving(x, y);
9131 else if (IS_ACTIVE_BOMB(element))
9132 CheckDynamite(x, y);
9133 else if (element == EL_AMOEBA_GROWING)
9134 AmoebeWaechst(x, y);
9135 else if (element == EL_AMOEBA_SHRINKING)
9136 AmoebaDisappearing(x, y);
9138 #if !USE_NEW_AMOEBA_CODE
9139 else if (IS_AMOEBALIVE(element))
9140 AmoebeAbleger(x, y);
9143 else if (element == EL_GAME_OF_LIFE || element == EL_BIOMAZE)
9145 else if (element == EL_EXIT_CLOSED)
9147 else if (element == EL_SP_EXIT_CLOSED)
9149 else if (element == EL_EXPANDABLE_WALL_GROWING)
9151 else if (element == EL_EXPANDABLE_WALL ||
9152 element == EL_EXPANDABLE_WALL_HORIZONTAL ||
9153 element == EL_EXPANDABLE_WALL_VERTICAL ||
9154 element == EL_EXPANDABLE_WALL_ANY)
9156 else if (element == EL_FLAMES)
9157 CheckForDragon(x, y);
9158 else if (element == EL_EXPLOSION)
9159 ; /* drawing of correct explosion animation is handled separately */
9160 else if (element == EL_ELEMENT_SNAPPING ||
9161 element == EL_DIAGONAL_SHRINKING ||
9162 element == EL_DIAGONAL_GROWING)
9165 graphic = el_act_dir2img(GfxElement[x][y], GfxAction[x][y],GfxDir[x][y]);
9167 DrawLevelGraphicAnimationIfNeeded(x, y, graphic);
9170 else if (IS_ANIMATED(graphic) && !IS_CHANGING(x, y))
9171 DrawLevelGraphicAnimationIfNeeded(x, y, graphic);
9174 if (element == EL_CUSTOM_255 ||
9175 element == EL_CUSTOM_256)
9176 DrawLevelGraphicAnimation(x, y, graphic);
9179 if (IS_BELT_ACTIVE(element))
9180 PlayLevelSoundAction(x, y, ACTION_ACTIVE);
9182 if (game.magic_wall_active)
9184 int jx = local_player->jx, jy = local_player->jy;
9186 /* play the element sound at the position nearest to the player */
9187 if ((element == EL_MAGIC_WALL_FULL ||
9188 element == EL_MAGIC_WALL_ACTIVE ||
9189 element == EL_MAGIC_WALL_EMPTYING ||
9190 element == EL_BD_MAGIC_WALL_FULL ||
9191 element == EL_BD_MAGIC_WALL_ACTIVE ||
9192 element == EL_BD_MAGIC_WALL_EMPTYING) &&
9193 ABS(x-jx) + ABS(y-jy) < ABS(magic_wall_x-jx) + ABS(magic_wall_y-jy))
9201 #if USE_NEW_AMOEBA_CODE
9202 /* new experimental amoeba growth stuff */
9203 if (!(FrameCounter % 8))
9205 static unsigned long random = 1684108901;
9207 for (i = 0; i < level.amoeba_speed * 28 / 8; i++)
9209 x = RND(lev_fieldx);
9210 y = RND(lev_fieldy);
9211 element = Feld[x][y];
9213 if (!IS_PLAYER(x,y) &&
9214 (element == EL_EMPTY ||
9215 CAN_GROW_INTO(element) ||
9216 element == EL_QUICKSAND_EMPTY ||
9217 element == EL_ACID_SPLASH_LEFT ||
9218 element == EL_ACID_SPLASH_RIGHT))
9220 if ((IN_LEV_FIELD(x, y-1) && Feld[x][y-1] == EL_AMOEBA_WET) ||
9221 (IN_LEV_FIELD(x-1, y) && Feld[x-1][y] == EL_AMOEBA_WET) ||
9222 (IN_LEV_FIELD(x+1, y) && Feld[x+1][y] == EL_AMOEBA_WET) ||
9223 (IN_LEV_FIELD(x, y+1) && Feld[x][y+1] == EL_AMOEBA_WET))
9224 Feld[x][y] = EL_AMOEBA_DROP;
9227 random = random * 129 + 1;
9233 if (game.explosions_delayed)
9236 game.explosions_delayed = FALSE;
9239 SCAN_PLAYFIELD(x, y)
9241 for (y = 0; y < lev_fieldy; y++) for (x = 0; x < lev_fieldx; x++)
9244 element = Feld[x][y];
9246 if (ExplodeField[x][y])
9247 Explode(x, y, EX_PHASE_START, ExplodeField[x][y]);
9248 else if (element == EL_EXPLOSION)
9249 Explode(x, y, ExplodePhase[x][y], EX_TYPE_NORMAL);
9251 ExplodeField[x][y] = EX_TYPE_NONE;
9254 game.explosions_delayed = TRUE;
9257 if (game.magic_wall_active)
9259 if (!(game.magic_wall_time_left % 4))
9261 int element = Feld[magic_wall_x][magic_wall_y];
9263 if (element == EL_BD_MAGIC_WALL_FULL ||
9264 element == EL_BD_MAGIC_WALL_ACTIVE ||
9265 element == EL_BD_MAGIC_WALL_EMPTYING)
9266 PlayLevelSound(magic_wall_x, magic_wall_y, SND_BD_MAGIC_WALL_ACTIVE);
9268 PlayLevelSound(magic_wall_x, magic_wall_y, SND_MAGIC_WALL_ACTIVE);
9271 if (game.magic_wall_time_left > 0)
9273 game.magic_wall_time_left--;
9274 if (!game.magic_wall_time_left)
9277 SCAN_PLAYFIELD(x, y)
9279 for (y = 0; y < lev_fieldy; y++) for (x = 0; x < lev_fieldx; x++)
9282 element = Feld[x][y];
9284 if (element == EL_MAGIC_WALL_ACTIVE ||
9285 element == EL_MAGIC_WALL_FULL)
9287 Feld[x][y] = EL_MAGIC_WALL_DEAD;
9288 DrawLevelField(x, y);
9290 else if (element == EL_BD_MAGIC_WALL_ACTIVE ||
9291 element == EL_BD_MAGIC_WALL_FULL)
9293 Feld[x][y] = EL_BD_MAGIC_WALL_DEAD;
9294 DrawLevelField(x, y);
9298 game.magic_wall_active = FALSE;
9303 if (game.light_time_left > 0)
9305 game.light_time_left--;
9307 if (game.light_time_left == 0)
9308 RedrawAllLightSwitchesAndInvisibleElements();
9311 if (game.timegate_time_left > 0)
9313 game.timegate_time_left--;
9315 if (game.timegate_time_left == 0)
9316 CloseAllOpenTimegates();
9319 if (game.lenses_time_left > 0)
9321 game.lenses_time_left--;
9323 if (game.lenses_time_left == 0)
9324 RedrawAllInvisibleElementsForLenses();
9327 if (game.magnify_time_left > 0)
9329 game.magnify_time_left--;
9331 if (game.magnify_time_left == 0)
9332 RedrawAllInvisibleElementsForMagnifier();
9335 for (i = 0; i < MAX_PLAYERS; i++)
9337 struct PlayerInfo *player = &stored_player[i];
9339 if (SHIELD_ON(player))
9341 if (player->shield_deadly_time_left)
9342 PlayLevelSound(player->jx, player->jy, SND_SHIELD_DEADLY_ACTIVE);
9343 else if (player->shield_normal_time_left)
9344 PlayLevelSound(player->jx, player->jy, SND_SHIELD_NORMAL_ACTIVE);
9348 if (TimeFrames >= FRAMES_PER_SECOND)
9353 for (i = 0; i < MAX_PLAYERS; i++)
9355 struct PlayerInfo *player = &stored_player[i];
9357 if (SHIELD_ON(player))
9359 player->shield_normal_time_left--;
9361 if (player->shield_deadly_time_left > 0)
9362 player->shield_deadly_time_left--;
9366 if (!level.use_step_counter)
9374 if (TimeLeft <= 10 && setup.time_limit)
9375 PlaySoundStereo(SND_GAME_RUNNING_OUT_OF_TIME, SOUND_MIDDLE);
9377 DrawGameValue_Time(TimeLeft);
9379 if (!TimeLeft && setup.time_limit)
9380 for (i = 0; i < MAX_PLAYERS; i++)
9381 KillPlayer(&stored_player[i]);
9383 else if (level.time == 0 && !AllPlayersGone) /* level w/o time limit */
9384 DrawGameValue_Time(TimePlayed);
9387 if (tape.recording || tape.playing)
9388 DrawVideoDisplay(VIDEO_STATE_TIME_ON, TapeTime);
9392 PlayAllPlayersSound();
9394 if (options.debug) /* calculate frames per second */
9396 static unsigned long fps_counter = 0;
9397 static int fps_frames = 0;
9398 unsigned long fps_delay_ms = Counter() - fps_counter;
9402 if (fps_delay_ms >= 500) /* calculate fps every 0.5 seconds */
9404 global.frames_per_second = 1000 * (float)fps_frames / fps_delay_ms;
9407 fps_counter = Counter();
9410 redraw_mask |= REDRAW_FPS;
9413 AdvanceFrameAndPlayerCounters(-1); /* advance counters for all players */
9415 if (local_player->show_envelope != 0 && local_player->MovPos == 0)
9417 ShowEnvelope(local_player->show_envelope - EL_ENVELOPE_1);
9419 local_player->show_envelope = 0;
9422 /* use random number generator in every frame to make it less predictable */
9423 if (game.engine_version >= VERSION_IDENT(3,1,1,0))
9427 static boolean AllPlayersInSight(struct PlayerInfo *player, int x, int y)
9429 int min_x = x, min_y = y, max_x = x, max_y = y;
9432 for (i = 0; i < MAX_PLAYERS; i++)
9434 int jx = stored_player[i].jx, jy = stored_player[i].jy;
9436 if (!stored_player[i].active || &stored_player[i] == player)
9439 min_x = MIN(min_x, jx);
9440 min_y = MIN(min_y, jy);
9441 max_x = MAX(max_x, jx);
9442 max_y = MAX(max_y, jy);
9445 return (max_x - min_x < SCR_FIELDX && max_y - min_y < SCR_FIELDY);
9448 static boolean AllPlayersInVisibleScreen()
9452 for (i = 0; i < MAX_PLAYERS; i++)
9454 int jx = stored_player[i].jx, jy = stored_player[i].jy;
9456 if (!stored_player[i].active)
9459 if (!IN_VIS_FIELD(SCREENX(jx), SCREENY(jy)))
9466 void ScrollLevel(int dx, int dy)
9468 int softscroll_offset = (setup.soft_scrolling ? TILEX : 0);
9471 BlitBitmap(drawto_field, drawto_field,
9472 FX + TILEX * (dx == -1) - softscroll_offset,
9473 FY + TILEY * (dy == -1) - softscroll_offset,
9474 SXSIZE - TILEX * (dx!=0) + 2 * softscroll_offset,
9475 SYSIZE - TILEY * (dy!=0) + 2 * softscroll_offset,
9476 FX + TILEX * (dx == 1) - softscroll_offset,
9477 FY + TILEY * (dy == 1) - softscroll_offset);
9481 x = (dx == 1 ? BX1 : BX2);
9482 for (y = BY1; y <= BY2; y++)
9483 DrawScreenField(x, y);
9488 y = (dy == 1 ? BY1 : BY2);
9489 for (x = BX1; x <= BX2; x++)
9490 DrawScreenField(x, y);
9493 redraw_mask |= REDRAW_FIELD;
9496 static boolean canFallDown(struct PlayerInfo *player)
9498 int jx = player->jx, jy = player->jy;
9500 return (IN_LEV_FIELD(jx, jy + 1) &&
9501 (IS_FREE(jx, jy + 1) ||
9502 (Feld[jx][jy + 1] == EL_ACID && player->can_fall_into_acid)) &&
9503 IS_WALKABLE_FROM(Feld[jx][jy], MV_DOWN) &&
9504 !IS_WALKABLE_INSIDE(Feld[jx][jy]));
9507 static boolean canPassField(int x, int y, int move_dir)
9509 int opposite_dir = MV_DIR_OPPOSITE(move_dir);
9510 int dx = (move_dir & MV_LEFT ? -1 : move_dir & MV_RIGHT ? +1 : 0);
9511 int dy = (move_dir & MV_UP ? -1 : move_dir & MV_DOWN ? +1 : 0);
9514 int element = Feld[x][y];
9516 return (IS_PASSABLE_FROM(element, opposite_dir) &&
9517 !CAN_MOVE(element) &&
9518 IN_LEV_FIELD(nextx, nexty) && !IS_PLAYER(nextx, nexty) &&
9519 IS_WALKABLE_FROM(Feld[nextx][nexty], move_dir) &&
9520 (level.can_pass_to_walkable || IS_FREE(nextx, nexty)));
9523 static boolean canMoveToValidFieldWithGravity(int x, int y, int move_dir)
9525 int opposite_dir = MV_DIR_OPPOSITE(move_dir);
9526 int dx = (move_dir & MV_LEFT ? -1 : move_dir & MV_RIGHT ? +1 : 0);
9527 int dy = (move_dir & MV_UP ? -1 : move_dir & MV_DOWN ? +1 : 0);
9531 return (IN_LEV_FIELD(newx, newy) && !IS_FREE_OR_PLAYER(newx, newy) &&
9532 IS_GRAVITY_REACHABLE(Feld[newx][newy]) &&
9533 (IS_DIGGABLE(Feld[newx][newy]) ||
9534 IS_WALKABLE_FROM(Feld[newx][newy], opposite_dir) ||
9535 canPassField(newx, newy, move_dir)));
9538 static void CheckGravityMovement(struct PlayerInfo *player)
9540 if (game.gravity && !player->programmed_action)
9542 int move_dir_horizontal = player->effective_action & MV_HORIZONTAL;
9543 int move_dir_vertical = player->effective_action & MV_VERTICAL;
9544 boolean player_is_snapping = player->effective_action & JOY_BUTTON_1;
9545 int jx = player->jx, jy = player->jy;
9546 boolean player_is_moving_to_valid_field =
9547 (!player_is_snapping &&
9548 (canMoveToValidFieldWithGravity(jx, jy, move_dir_horizontal) ||
9549 canMoveToValidFieldWithGravity(jx, jy, move_dir_vertical)));
9550 boolean player_can_fall_down = canFallDown(player);
9552 if (player_can_fall_down &&
9553 !player_is_moving_to_valid_field)
9554 player->programmed_action = MV_DOWN;
9558 static void CheckGravityMovementWhenNotMoving(struct PlayerInfo *player)
9560 return CheckGravityMovement(player);
9562 if (game.gravity && !player->programmed_action)
9564 int jx = player->jx, jy = player->jy;
9565 boolean field_under_player_is_free =
9566 (IN_LEV_FIELD(jx, jy + 1) && IS_FREE(jx, jy + 1));
9567 boolean player_is_standing_on_valid_field =
9568 (IS_WALKABLE_INSIDE(Feld[jx][jy]) ||
9569 (IS_WALKABLE(Feld[jx][jy]) &&
9570 !(element_info[Feld[jx][jy]].access_direction & MV_DOWN)));
9572 if (field_under_player_is_free && !player_is_standing_on_valid_field)
9573 player->programmed_action = MV_DOWN;
9579 -----------------------------------------------------------------------------
9580 dx, dy: direction (non-diagonal) to try to move the player to
9581 real_dx, real_dy: direction as read from input device (can be diagonal)
9584 boolean MovePlayerOneStep(struct PlayerInfo *player,
9585 int dx, int dy, int real_dx, int real_dy)
9587 int jx = player->jx, jy = player->jy;
9588 int new_jx = jx + dx, new_jy = jy + dy;
9589 #if !USE_FIXED_DONT_RUN_INTO
9593 boolean player_can_move = !player->cannot_move;
9595 if (!player->active || (!dx && !dy))
9596 return MP_NO_ACTION;
9598 player->MovDir = (dx < 0 ? MV_LEFT :
9601 dy > 0 ? MV_DOWN : MV_NONE);
9603 if (!IN_LEV_FIELD(new_jx, new_jy))
9604 return MP_NO_ACTION;
9606 if (!player_can_move)
9609 if (player->MovPos == 0)
9611 player->is_moving = FALSE;
9612 player->is_digging = FALSE;
9613 player->is_collecting = FALSE;
9614 player->is_snapping = FALSE;
9615 player->is_pushing = FALSE;
9618 DigField(player, 0, 0, 0, 0, 0, 0, DF_NO_PUSH);
9619 SnapField(player, 0, 0);
9623 return MP_NO_ACTION;
9627 if (!options.network && !AllPlayersInSight(player, new_jx, new_jy))
9628 return MP_NO_ACTION;
9630 #if !USE_FIXED_DONT_RUN_INTO
9631 element = MovingOrBlocked2ElementIfNotLeaving(new_jx, new_jy);
9633 /* (moved to DigField()) */
9634 if (player_can_move && DONT_RUN_INTO(element))
9636 if (element == EL_ACID && dx == 0 && dy == 1)
9638 SplashAcid(new_jx, new_jy);
9639 Feld[jx][jy] = EL_PLAYER_1;
9640 InitMovingField(jx, jy, MV_DOWN);
9641 Store[jx][jy] = EL_ACID;
9642 ContinueMoving(jx, jy);
9646 TestIfPlayerRunsIntoBadThing(jx, jy, player->MovDir);
9652 can_move = DigField(player, jx, jy, new_jx, new_jy, real_dx,real_dy, DF_DIG);
9654 #if USE_FIXED_DONT_RUN_INTO
9655 if (can_move == MP_DONT_RUN_INTO)
9659 if (can_move != MP_MOVING)
9662 #if USE_FIXED_DONT_RUN_INTO
9665 /* check if DigField() has caused relocation of the player */
9666 if (player->jx != jx || player->jy != jy)
9667 return MP_NO_ACTION; /* <-- !!! CHECK THIS [-> MP_ACTION ?] !!! */
9669 StorePlayer[jx][jy] = 0;
9670 player->last_jx = jx;
9671 player->last_jy = jy;
9672 player->jx = new_jx;
9673 player->jy = new_jy;
9674 StorePlayer[new_jx][new_jy] = player->element_nr;
9676 if (player->move_delay_value_next != -1)
9678 player->move_delay_value = player->move_delay_value_next;
9679 player->move_delay_value_next = -1;
9683 (dx > 0 || dy > 0 ? -1 : 1) * (TILEX - TILEX / player->move_delay_value);
9685 player->step_counter++;
9687 PlayerVisit[jx][jy] = FrameCounter;
9689 ScrollPlayer(player, SCROLL_INIT);
9694 boolean MovePlayer(struct PlayerInfo *player, int dx, int dy)
9696 int jx = player->jx, jy = player->jy;
9697 int old_jx = jx, old_jy = jy;
9698 int moved = MP_NO_ACTION;
9700 if (!player->active)
9705 if (player->MovPos == 0)
9707 player->is_moving = FALSE;
9708 player->is_digging = FALSE;
9709 player->is_collecting = FALSE;
9710 player->is_snapping = FALSE;
9711 player->is_pushing = FALSE;
9717 if (player->move_delay > 0)
9720 player->move_delay = -1; /* set to "uninitialized" value */
9722 /* store if player is automatically moved to next field */
9723 player->is_auto_moving = (player->programmed_action != MV_NONE);
9725 /* remove the last programmed player action */
9726 player->programmed_action = 0;
9730 /* should only happen if pre-1.2 tape recordings are played */
9731 /* this is only for backward compatibility */
9733 int original_move_delay_value = player->move_delay_value;
9736 printf("THIS SHOULD ONLY HAPPEN WITH PRE-1.2 LEVEL TAPES. [%ld]\n",
9740 /* scroll remaining steps with finest movement resolution */
9741 player->move_delay_value = MOVE_DELAY_NORMAL_SPEED;
9743 while (player->MovPos)
9745 ScrollPlayer(player, SCROLL_GO_ON);
9746 ScrollScreen(NULL, SCROLL_GO_ON);
9748 AdvanceFrameAndPlayerCounters(player->index_nr);
9754 player->move_delay_value = original_move_delay_value;
9757 if (player->last_move_dir & MV_HORIZONTAL)
9759 if (!(moved |= MovePlayerOneStep(player, 0, dy, dx, dy)))
9760 moved |= MovePlayerOneStep(player, dx, 0, dx, dy);
9764 if (!(moved |= MovePlayerOneStep(player, dx, 0, dx, dy)))
9765 moved |= MovePlayerOneStep(player, 0, dy, dx, dy);
9771 if (moved & MP_MOVING && !ScreenMovPos &&
9772 (player == local_player || !options.network))
9774 int old_scroll_x = scroll_x, old_scroll_y = scroll_y;
9775 int offset = (setup.scroll_delay ? 3 : 0);
9777 if (!IN_VIS_FIELD(SCREENX(jx), SCREENY(jy)))
9779 /* actual player has left the screen -- scroll in that direction */
9780 if (jx != old_jx) /* player has moved horizontally */
9781 scroll_x += (jx - old_jx);
9782 else /* player has moved vertically */
9783 scroll_y += (jy - old_jy);
9787 if (jx != old_jx) /* player has moved horizontally */
9789 if ((player->MovDir == MV_LEFT && scroll_x > jx - MIDPOSX + offset) ||
9790 (player->MovDir == MV_RIGHT && scroll_x < jx - MIDPOSX - offset))
9791 scroll_x = jx-MIDPOSX + (scroll_x < jx-MIDPOSX ? -offset : +offset);
9793 /* don't scroll over playfield boundaries */
9794 if (scroll_x < SBX_Left || scroll_x > SBX_Right)
9795 scroll_x = (scroll_x < SBX_Left ? SBX_Left : SBX_Right);
9797 /* don't scroll more than one field at a time */
9798 scroll_x = old_scroll_x + SIGN(scroll_x - old_scroll_x);
9800 /* don't scroll against the player's moving direction */
9801 if ((player->MovDir == MV_LEFT && scroll_x > old_scroll_x) ||
9802 (player->MovDir == MV_RIGHT && scroll_x < old_scroll_x))
9803 scroll_x = old_scroll_x;
9805 else /* player has moved vertically */
9807 if ((player->MovDir == MV_UP && scroll_y > jy - MIDPOSY + offset) ||
9808 (player->MovDir == MV_DOWN && scroll_y < jy - MIDPOSY - offset))
9809 scroll_y = jy-MIDPOSY + (scroll_y < jy-MIDPOSY ? -offset : +offset);
9811 /* don't scroll over playfield boundaries */
9812 if (scroll_y < SBY_Upper || scroll_y > SBY_Lower)
9813 scroll_y = (scroll_y < SBY_Upper ? SBY_Upper : SBY_Lower);
9815 /* don't scroll more than one field at a time */
9816 scroll_y = old_scroll_y + SIGN(scroll_y - old_scroll_y);
9818 /* don't scroll against the player's moving direction */
9819 if ((player->MovDir == MV_UP && scroll_y > old_scroll_y) ||
9820 (player->MovDir == MV_DOWN && scroll_y < old_scroll_y))
9821 scroll_y = old_scroll_y;
9825 if (scroll_x != old_scroll_x || scroll_y != old_scroll_y)
9827 if (!options.network && !AllPlayersInVisibleScreen())
9829 scroll_x = old_scroll_x;
9830 scroll_y = old_scroll_y;
9834 ScrollScreen(player, SCROLL_INIT);
9835 ScrollLevel(old_scroll_x - scroll_x, old_scroll_y - scroll_y);
9840 player->StepFrame = 0;
9842 if (moved & MP_MOVING)
9844 if (old_jx != jx && old_jy == jy)
9845 player->MovDir = (old_jx < jx ? MV_RIGHT : MV_LEFT);
9846 else if (old_jx == jx && old_jy != jy)
9847 player->MovDir = (old_jy < jy ? MV_DOWN : MV_UP);
9849 DrawLevelField(jx, jy); /* for "crumbled sand" */
9851 player->last_move_dir = player->MovDir;
9852 player->is_moving = TRUE;
9853 player->is_snapping = FALSE;
9854 player->is_switching = FALSE;
9855 player->is_dropping = FALSE;
9859 CheckGravityMovementWhenNotMoving(player);
9861 player->is_moving = FALSE;
9863 /* at this point, the player is allowed to move, but cannot move right now
9864 (e.g. because of something blocking the way) -- ensure that the player
9865 is also allowed to move in the next frame (in old versions before 3.1.1,
9866 the player was forced to wait again for eight frames before next try) */
9868 if (game.engine_version >= VERSION_IDENT(3,1,1,0))
9869 player->move_delay = 0; /* allow direct movement in the next frame */
9872 if (player->move_delay == -1) /* not yet initialized by DigField() */
9873 player->move_delay = player->move_delay_value;
9875 if (game.engine_version < VERSION_IDENT(3,0,7,0))
9877 TestIfPlayerTouchesBadThing(jx, jy);
9878 TestIfPlayerTouchesCustomElement(jx, jy);
9881 if (!player->active)
9882 RemovePlayer(player);
9887 void ScrollPlayer(struct PlayerInfo *player, int mode)
9889 int jx = player->jx, jy = player->jy;
9890 int last_jx = player->last_jx, last_jy = player->last_jy;
9891 int move_stepsize = TILEX / player->move_delay_value;
9893 #if USE_NEW_PLAYER_SPEED
9894 if (!player->active)
9897 if (player->MovPos == 0 && mode == SCROLL_GO_ON) /* player not moving */
9900 if (!player->active || player->MovPos == 0)
9904 if (mode == SCROLL_INIT)
9906 player->actual_frame_counter = FrameCounter;
9907 player->GfxPos = move_stepsize * (player->MovPos / move_stepsize);
9909 if ((player->block_last_field || player->block_delay_adjustment > 0) &&
9910 Feld[last_jx][last_jy] == EL_EMPTY)
9912 int last_field_block_delay = 0; /* start with no blocking at all */
9913 int block_delay_adjustment = player->block_delay_adjustment;
9915 /* if player blocks last field, add delay for exactly one move */
9916 if (player->block_last_field)
9918 last_field_block_delay += player->move_delay_value;
9920 /* when blocking enabled, prevent moving up despite gravity */
9921 if (game.gravity && player->MovDir == MV_UP)
9922 block_delay_adjustment = -1;
9925 /* add block delay adjustment (also possible when not blocking) */
9926 last_field_block_delay += block_delay_adjustment;
9928 Feld[last_jx][last_jy] = EL_PLAYER_IS_LEAVING;
9929 MovDelay[last_jx][last_jy] = last_field_block_delay + 1;
9932 #if USE_NEW_PLAYER_SPEED
9933 if (player->MovPos != 0) /* player has not yet reached destination */
9939 else if (!FrameReached(&player->actual_frame_counter, 1))
9943 printf("::: player->MovPos: %d -> %d\n",
9945 player->MovPos + (player->MovPos > 0 ? -1 : 1) * move_stepsize);
9948 #if USE_NEW_PLAYER_SPEED
9949 if (player->MovPos != 0)
9951 player->MovPos += (player->MovPos > 0 ? -1 : 1) * move_stepsize;
9952 player->GfxPos = move_stepsize * (player->MovPos / move_stepsize);
9954 /* before DrawPlayer() to draw correct player graphic for this case */
9955 if (player->MovPos == 0)
9956 CheckGravityMovement(player);
9959 player->MovPos += (player->MovPos > 0 ? -1 : 1) * move_stepsize;
9960 player->GfxPos = move_stepsize * (player->MovPos / move_stepsize);
9962 /* before DrawPlayer() to draw correct player graphic for this case */
9963 if (player->MovPos == 0)
9964 CheckGravityMovement(player);
9967 if (player->MovPos == 0) /* player reached destination field */
9970 printf("::: player reached destination field\n");
9973 if (player->move_delay_reset_counter > 0)
9975 player->move_delay_reset_counter--;
9977 if (player->move_delay_reset_counter == 0)
9979 /* continue with normal speed after quickly moving through gate */
9980 HALVE_PLAYER_SPEED(player);
9982 /* be able to make the next move without delay */
9983 player->move_delay = 0;
9987 player->last_jx = jx;
9988 player->last_jy = jy;
9990 if (Feld[jx][jy] == EL_EXIT_OPEN ||
9991 Feld[jx][jy] == EL_SP_EXIT_OPEN ||
9992 Feld[jx][jy] == EL_SP_EXIT_OPENING) /* <-- special case */
9994 DrawPlayer(player); /* needed here only to cleanup last field */
9995 RemovePlayer(player);
9997 if (local_player->friends_still_needed == 0 ||
9998 IS_SP_ELEMENT(Feld[jx][jy]))
9999 player->LevelSolved = player->GameOver = TRUE;
10002 /* this breaks one level: "machine", level 000 */
10004 int move_direction = player->MovDir;
10005 int enter_side = MV_DIR_OPPOSITE(move_direction);
10006 int leave_side = move_direction;
10007 int old_jx = last_jx;
10008 int old_jy = last_jy;
10009 int old_element = Feld[old_jx][old_jy];
10010 int new_element = Feld[jx][jy];
10012 if (IS_CUSTOM_ELEMENT(old_element))
10013 CheckElementChangeByPlayer(old_jx, old_jy, old_element,
10015 player->index_bit, leave_side);
10017 CheckTriggeredElementChangeByPlayer(old_jx, old_jy, old_element,
10018 CE_PLAYER_LEAVES_X,
10019 player->index_bit, leave_side);
10021 if (IS_CUSTOM_ELEMENT(new_element))
10022 CheckElementChangeByPlayer(jx, jy, new_element, CE_ENTERED_BY_PLAYER,
10023 player->index_bit, enter_side);
10025 CheckTriggeredElementChangeByPlayer(jx, jy, new_element,
10026 CE_PLAYER_ENTERS_X,
10027 player->index_bit, enter_side);
10029 CheckTriggeredElementChangeBySide(jx, jy, player->element_nr,
10030 CE_MOVE_OF_X, move_direction);
10033 if (game.engine_version >= VERSION_IDENT(3,0,7,0))
10035 TestIfPlayerTouchesBadThing(jx, jy);
10036 TestIfPlayerTouchesCustomElement(jx, jy);
10038 /* needed because pushed element has not yet reached its destination,
10039 so it would trigger a change event at its previous field location */
10040 if (!player->is_pushing)
10041 TestIfElementTouchesCustomElement(jx, jy); /* for empty space */
10043 if (!player->active)
10044 RemovePlayer(player);
10047 if (level.use_step_counter)
10057 if (TimeLeft <= 10 && setup.time_limit)
10058 PlaySoundStereo(SND_GAME_RUNNING_OUT_OF_TIME, SOUND_MIDDLE);
10060 DrawGameValue_Time(TimeLeft);
10062 if (!TimeLeft && setup.time_limit)
10063 for (i = 0; i < MAX_PLAYERS; i++)
10064 KillPlayer(&stored_player[i]);
10066 else if (level.time == 0 && !AllPlayersGone) /* level w/o time limit */
10067 DrawGameValue_Time(TimePlayed);
10070 if (tape.single_step && tape.recording && !tape.pausing &&
10071 !player->programmed_action)
10072 TapeTogglePause(TAPE_TOGGLE_AUTOMATIC);
10076 void ScrollScreen(struct PlayerInfo *player, int mode)
10078 static unsigned long screen_frame_counter = 0;
10080 if (mode == SCROLL_INIT)
10082 /* set scrolling step size according to actual player's moving speed */
10083 ScrollStepSize = TILEX / player->move_delay_value;
10085 screen_frame_counter = FrameCounter;
10086 ScreenMovDir = player->MovDir;
10087 ScreenMovPos = player->MovPos;
10088 ScreenGfxPos = ScrollStepSize * (ScreenMovPos / ScrollStepSize);
10091 else if (!FrameReached(&screen_frame_counter, 1))
10096 ScreenMovPos += (ScreenMovPos > 0 ? -1 : 1) * ScrollStepSize;
10097 ScreenGfxPos = ScrollStepSize * (ScreenMovPos / ScrollStepSize);
10098 redraw_mask |= REDRAW_FIELD;
10101 ScreenMovDir = MV_NONE;
10104 void TestIfPlayerTouchesCustomElement(int x, int y)
10106 static int xy[4][2] =
10113 static int trigger_sides[4][2] =
10115 /* center side border side */
10116 { CH_SIDE_TOP, CH_SIDE_BOTTOM }, /* check top */
10117 { CH_SIDE_LEFT, CH_SIDE_RIGHT }, /* check left */
10118 { CH_SIDE_RIGHT, CH_SIDE_LEFT }, /* check right */
10119 { CH_SIDE_BOTTOM, CH_SIDE_TOP } /* check bottom */
10121 static int touch_dir[4] =
10123 MV_LEFT | MV_RIGHT,
10128 int center_element = Feld[x][y]; /* should always be non-moving! */
10131 for (i = 0; i < NUM_DIRECTIONS; i++)
10133 int xx = x + xy[i][0];
10134 int yy = y + xy[i][1];
10135 int center_side = trigger_sides[i][0];
10136 int border_side = trigger_sides[i][1];
10137 int border_element;
10139 if (!IN_LEV_FIELD(xx, yy))
10142 if (IS_PLAYER(x, y))
10144 struct PlayerInfo *player = PLAYERINFO(x, y);
10146 if (game.engine_version < VERSION_IDENT(3,0,7,0))
10147 border_element = Feld[xx][yy]; /* may be moving! */
10148 else if (!IS_MOVING(xx, yy) && !IS_BLOCKED(xx, yy))
10149 border_element = Feld[xx][yy];
10150 else if (MovDir[xx][yy] & touch_dir[i]) /* elements are touching */
10151 border_element = MovingOrBlocked2Element(xx, yy);
10153 continue; /* center and border element do not touch */
10155 CheckElementChangeByPlayer(xx, yy, border_element, CE_TOUCHED_BY_PLAYER,
10156 player->index_bit, border_side);
10157 CheckTriggeredElementChangeByPlayer(xx, yy, border_element,
10158 CE_PLAYER_TOUCHES_X,
10159 player->index_bit, border_side);
10161 else if (IS_PLAYER(xx, yy))
10163 struct PlayerInfo *player = PLAYERINFO(xx, yy);
10165 if (game.engine_version >= VERSION_IDENT(3,0,7,0))
10167 if (player->MovPos != 0 && !(player->MovDir & touch_dir[i]))
10168 continue; /* center and border element do not touch */
10171 CheckElementChangeByPlayer(x, y, center_element, CE_TOUCHED_BY_PLAYER,
10172 player->index_bit, center_side);
10173 CheckTriggeredElementChangeByPlayer(x, y, center_element,
10174 CE_PLAYER_TOUCHES_X,
10175 player->index_bit, center_side);
10181 #if USE_ELEMENT_TOUCHING_BUGFIX
10183 void TestIfElementTouchesCustomElement(int x, int y)
10185 static int xy[4][2] =
10192 static int trigger_sides[4][2] =
10194 /* center side border side */
10195 { CH_SIDE_TOP, CH_SIDE_BOTTOM }, /* check top */
10196 { CH_SIDE_LEFT, CH_SIDE_RIGHT }, /* check left */
10197 { CH_SIDE_RIGHT, CH_SIDE_LEFT }, /* check right */
10198 { CH_SIDE_BOTTOM, CH_SIDE_TOP } /* check bottom */
10200 static int touch_dir[4] =
10202 MV_LEFT | MV_RIGHT,
10207 boolean change_center_element = FALSE;
10208 int center_element = Feld[x][y]; /* should always be non-moving! */
10209 int border_element_old[NUM_DIRECTIONS];
10212 for (i = 0; i < NUM_DIRECTIONS; i++)
10214 int xx = x + xy[i][0];
10215 int yy = y + xy[i][1];
10216 int border_element;
10218 border_element_old[i] = -1;
10220 if (!IN_LEV_FIELD(xx, yy))
10223 if (game.engine_version < VERSION_IDENT(3,0,7,0))
10224 border_element = Feld[xx][yy]; /* may be moving! */
10225 else if (!IS_MOVING(xx, yy) && !IS_BLOCKED(xx, yy))
10226 border_element = Feld[xx][yy];
10227 else if (MovDir[xx][yy] & touch_dir[i]) /* elements are touching */
10228 border_element = MovingOrBlocked2Element(xx, yy);
10230 continue; /* center and border element do not touch */
10232 border_element_old[i] = border_element;
10235 for (i = 0; i < NUM_DIRECTIONS; i++)
10237 int xx = x + xy[i][0];
10238 int yy = y + xy[i][1];
10239 int center_side = trigger_sides[i][0];
10240 int border_element = border_element_old[i];
10242 if (border_element == -1)
10245 /* check for change of border element */
10246 CheckElementChangeBySide(xx, yy, border_element, center_element,
10247 CE_TOUCHING_X, center_side);
10250 for (i = 0; i < NUM_DIRECTIONS; i++)
10252 int border_side = trigger_sides[i][1];
10253 int border_element = border_element_old[i];
10255 if (border_element == -1)
10258 /* check for change of center element (but change it only once) */
10259 if (!change_center_element)
10260 change_center_element =
10261 CheckElementChangeBySide(x, y, center_element, border_element,
10262 CE_TOUCHING_X, border_side);
10268 void TestIfElementTouchesCustomElement_OLD(int x, int y)
10270 static int xy[4][2] =
10277 static int trigger_sides[4][2] =
10279 /* center side border side */
10280 { CH_SIDE_TOP, CH_SIDE_BOTTOM }, /* check top */
10281 { CH_SIDE_LEFT, CH_SIDE_RIGHT }, /* check left */
10282 { CH_SIDE_RIGHT, CH_SIDE_LEFT }, /* check right */
10283 { CH_SIDE_BOTTOM, CH_SIDE_TOP } /* check bottom */
10285 static int touch_dir[4] =
10287 MV_LEFT | MV_RIGHT,
10292 boolean change_center_element = FALSE;
10293 int center_element = Feld[x][y]; /* should always be non-moving! */
10296 for (i = 0; i < NUM_DIRECTIONS; i++)
10298 int xx = x + xy[i][0];
10299 int yy = y + xy[i][1];
10300 int center_side = trigger_sides[i][0];
10301 int border_side = trigger_sides[i][1];
10302 int border_element;
10304 if (!IN_LEV_FIELD(xx, yy))
10307 if (game.engine_version < VERSION_IDENT(3,0,7,0))
10308 border_element = Feld[xx][yy]; /* may be moving! */
10309 else if (!IS_MOVING(xx, yy) && !IS_BLOCKED(xx, yy))
10310 border_element = Feld[xx][yy];
10311 else if (MovDir[xx][yy] & touch_dir[i]) /* elements are touching */
10312 border_element = MovingOrBlocked2Element(xx, yy);
10314 continue; /* center and border element do not touch */
10316 /* check for change of center element (but change it only once) */
10317 if (!change_center_element)
10318 change_center_element =
10319 CheckElementChangeBySide(x, y, center_element, border_element,
10320 CE_TOUCHING_X, border_side);
10322 /* check for change of border element */
10323 CheckElementChangeBySide(xx, yy, border_element, center_element,
10324 CE_TOUCHING_X, center_side);
10330 void TestIfElementHitsCustomElement(int x, int y, int direction)
10332 int dx = (direction == MV_LEFT ? -1 : direction == MV_RIGHT ? +1 : 0);
10333 int dy = (direction == MV_UP ? -1 : direction == MV_DOWN ? +1 : 0);
10334 int hitx = x + dx, hity = y + dy;
10335 int hitting_element = Feld[x][y];
10336 int touched_element;
10338 if (IN_LEV_FIELD(hitx, hity) && IS_FREE(hitx, hity))
10341 touched_element = (IN_LEV_FIELD(hitx, hity) ?
10342 MovingOrBlocked2Element(hitx, hity) : EL_STEELWALL);
10344 if (IN_LEV_FIELD(hitx, hity))
10346 int opposite_direction = MV_DIR_OPPOSITE(direction);
10347 int hitting_side = direction;
10348 int touched_side = opposite_direction;
10349 boolean object_hit = (!IS_MOVING(hitx, hity) ||
10350 MovDir[hitx][hity] != direction ||
10351 ABS(MovPos[hitx][hity]) <= TILEY / 2);
10357 CheckElementChangeBySide(x, y, hitting_element, touched_element,
10358 CE_HITTING_X, touched_side);
10360 CheckElementChangeBySide(hitx, hity, touched_element,
10361 hitting_element, CE_HIT_BY_X, hitting_side);
10363 CheckElementChangeBySide(hitx, hity, touched_element, hitting_element,
10364 CE_HIT_BY_SOMETHING, opposite_direction);
10368 /* "hitting something" is also true when hitting the playfield border */
10369 CheckElementChangeBySide(x, y, hitting_element, touched_element,
10370 CE_HITTING_SOMETHING, direction);
10374 void TestIfElementSmashesCustomElement(int x, int y, int direction)
10376 int dx = (direction == MV_LEFT ? -1 : direction == MV_RIGHT ? +1 : 0);
10377 int dy = (direction == MV_UP ? -1 : direction == MV_DOWN ? +1 : 0);
10378 int hitx = x + dx, hity = y + dy;
10379 int hitting_element = Feld[x][y];
10380 int touched_element;
10382 boolean object_hit = (IN_LEV_FIELD(hitx, hity) &&
10383 !IS_FREE(hitx, hity) &&
10384 (!IS_MOVING(hitx, hity) ||
10385 MovDir[hitx][hity] != direction ||
10386 ABS(MovPos[hitx][hity]) <= TILEY / 2));
10389 if (IN_LEV_FIELD(hitx, hity) && IS_FREE(hitx, hity))
10393 if (IN_LEV_FIELD(hitx, hity) && !object_hit)
10397 touched_element = (IN_LEV_FIELD(hitx, hity) ?
10398 MovingOrBlocked2Element(hitx, hity) : EL_STEELWALL);
10400 CheckElementChangeBySide(x, y, hitting_element, touched_element,
10401 EP_CAN_SMASH_EVERYTHING, direction);
10403 if (IN_LEV_FIELD(hitx, hity))
10405 int opposite_direction = MV_DIR_OPPOSITE(direction);
10406 int hitting_side = direction;
10407 int touched_side = opposite_direction;
10409 int touched_element = MovingOrBlocked2Element(hitx, hity);
10412 boolean object_hit = (!IS_MOVING(hitx, hity) ||
10413 MovDir[hitx][hity] != direction ||
10414 ABS(MovPos[hitx][hity]) <= TILEY / 2);
10423 CheckElementChangeBySide(hitx, hity, touched_element, hitting_element,
10424 CE_SMASHED_BY_SOMETHING, opposite_direction);
10426 CheckElementChangeBySide(x, y, hitting_element, touched_element,
10427 CE_OTHER_IS_SMASHING, touched_side);
10429 CheckElementChangeBySide(hitx, hity, touched_element, hitting_element,
10430 CE_OTHER_GETS_SMASHED, hitting_side);
10436 void TestIfGoodThingHitsBadThing(int good_x, int good_y, int good_move_dir)
10438 int i, kill_x = -1, kill_y = -1;
10440 int bad_element = -1;
10441 static int test_xy[4][2] =
10448 static int test_dir[4] =
10456 for (i = 0; i < NUM_DIRECTIONS; i++)
10458 int test_x, test_y, test_move_dir, test_element;
10460 test_x = good_x + test_xy[i][0];
10461 test_y = good_y + test_xy[i][1];
10463 if (!IN_LEV_FIELD(test_x, test_y))
10467 (IS_MOVING(test_x, test_y) ? MovDir[test_x][test_y] : MV_NONE);
10469 test_element = MovingOrBlocked2ElementIfNotLeaving(test_x, test_y);
10471 /* 1st case: good thing is moving towards DONT_RUN_INTO style bad thing;
10472 2nd case: DONT_TOUCH style bad thing does not move away from good thing
10474 if ((DONT_RUN_INTO(test_element) && good_move_dir == test_dir[i]) ||
10475 (DONT_TOUCH(test_element) && test_move_dir != test_dir[i]))
10479 bad_element = test_element;
10485 if (kill_x != -1 || kill_y != -1)
10487 if (IS_PLAYER(good_x, good_y))
10489 struct PlayerInfo *player = PLAYERINFO(good_x, good_y);
10491 if (player->shield_deadly_time_left > 0 &&
10492 !IS_INDESTRUCTIBLE(bad_element))
10493 Bang(kill_x, kill_y);
10494 else if (!PLAYER_ENEMY_PROTECTED(good_x, good_y))
10495 KillPlayer(player);
10498 Bang(good_x, good_y);
10502 void TestIfBadThingHitsGoodThing(int bad_x, int bad_y, int bad_move_dir)
10504 int i, kill_x = -1, kill_y = -1;
10505 int bad_element = Feld[bad_x][bad_y];
10506 static int test_xy[4][2] =
10513 static int touch_dir[4] =
10515 MV_LEFT | MV_RIGHT,
10520 static int test_dir[4] =
10528 if (bad_element == EL_EXPLOSION) /* skip just exploding bad things */
10531 for (i = 0; i < NUM_DIRECTIONS; i++)
10533 int test_x, test_y, test_move_dir, test_element;
10535 test_x = bad_x + test_xy[i][0];
10536 test_y = bad_y + test_xy[i][1];
10537 if (!IN_LEV_FIELD(test_x, test_y))
10541 (IS_MOVING(test_x, test_y) ? MovDir[test_x][test_y] : MV_NONE);
10543 test_element = Feld[test_x][test_y];
10545 /* 1st case: good thing is moving towards DONT_RUN_INTO style bad thing;
10546 2nd case: DONT_TOUCH style bad thing does not move away from good thing
10548 if ((DONT_RUN_INTO(bad_element) && bad_move_dir == test_dir[i]) ||
10549 (DONT_TOUCH(bad_element) && test_move_dir != test_dir[i]))
10551 /* good thing is player or penguin that does not move away */
10552 if (IS_PLAYER(test_x, test_y))
10554 struct PlayerInfo *player = PLAYERINFO(test_x, test_y);
10556 if (bad_element == EL_ROBOT && player->is_moving)
10557 continue; /* robot does not kill player if he is moving */
10559 if (game.engine_version >= VERSION_IDENT(3,0,7,0))
10561 if (player->MovPos != 0 && !(player->MovDir & touch_dir[i]))
10562 continue; /* center and border element do not touch */
10569 else if (test_element == EL_PENGUIN)
10578 if (kill_x != -1 || kill_y != -1)
10580 if (IS_PLAYER(kill_x, kill_y))
10582 struct PlayerInfo *player = PLAYERINFO(kill_x, kill_y);
10584 if (player->shield_deadly_time_left > 0 &&
10585 !IS_INDESTRUCTIBLE(bad_element))
10586 Bang(bad_x, bad_y);
10587 else if (!PLAYER_ENEMY_PROTECTED(kill_x, kill_y))
10588 KillPlayer(player);
10591 Bang(kill_x, kill_y);
10595 void TestIfPlayerTouchesBadThing(int x, int y)
10597 TestIfGoodThingHitsBadThing(x, y, MV_NONE);
10600 void TestIfPlayerRunsIntoBadThing(int x, int y, int move_dir)
10602 TestIfGoodThingHitsBadThing(x, y, move_dir);
10605 void TestIfBadThingTouchesPlayer(int x, int y)
10607 TestIfBadThingHitsGoodThing(x, y, MV_NONE);
10610 void TestIfBadThingRunsIntoPlayer(int x, int y, int move_dir)
10612 TestIfBadThingHitsGoodThing(x, y, move_dir);
10615 void TestIfFriendTouchesBadThing(int x, int y)
10617 TestIfGoodThingHitsBadThing(x, y, MV_NONE);
10620 void TestIfBadThingTouchesFriend(int x, int y)
10622 TestIfBadThingHitsGoodThing(x, y, MV_NONE);
10625 void TestIfBadThingTouchesOtherBadThing(int bad_x, int bad_y)
10627 int i, kill_x = bad_x, kill_y = bad_y;
10628 static int xy[4][2] =
10636 for (i = 0; i < NUM_DIRECTIONS; i++)
10640 x = bad_x + xy[i][0];
10641 y = bad_y + xy[i][1];
10642 if (!IN_LEV_FIELD(x, y))
10645 element = Feld[x][y];
10646 if (IS_AMOEBOID(element) || element == EL_GAME_OF_LIFE ||
10647 element == EL_AMOEBA_GROWING || element == EL_AMOEBA_DROP)
10655 if (kill_x != bad_x || kill_y != bad_y)
10656 Bang(bad_x, bad_y);
10659 void KillPlayer(struct PlayerInfo *player)
10661 int jx = player->jx, jy = player->jy;
10663 if (!player->active)
10666 /* remove accessible field at the player's position */
10667 Feld[jx][jy] = EL_EMPTY;
10669 /* deactivate shield (else Bang()/Explode() would not work right) */
10670 player->shield_normal_time_left = 0;
10671 player->shield_deadly_time_left = 0;
10674 BuryPlayer(player);
10677 static void KillPlayerUnlessEnemyProtected(int x, int y)
10679 if (!PLAYER_ENEMY_PROTECTED(x, y))
10680 KillPlayer(PLAYERINFO(x, y));
10683 static void KillPlayerUnlessExplosionProtected(int x, int y)
10685 if (!PLAYER_EXPLOSION_PROTECTED(x, y))
10686 KillPlayer(PLAYERINFO(x, y));
10689 void BuryPlayer(struct PlayerInfo *player)
10691 int jx = player->jx, jy = player->jy;
10693 if (!player->active)
10696 PlayLevelSoundElementAction(jx, jy, player->artwork_element, ACTION_DYING);
10697 PlayLevelSound(jx, jy, SND_GAME_LOSING);
10699 player->GameOver = TRUE;
10700 RemovePlayer(player);
10703 void RemovePlayer(struct PlayerInfo *player)
10705 int jx = player->jx, jy = player->jy;
10706 int i, found = FALSE;
10708 player->present = FALSE;
10709 player->active = FALSE;
10711 if (!ExplodeField[jx][jy])
10712 StorePlayer[jx][jy] = 0;
10714 if (player->is_moving)
10715 DrawLevelField(player->last_jx, player->last_jy);
10717 for (i = 0; i < MAX_PLAYERS; i++)
10718 if (stored_player[i].active)
10722 AllPlayersGone = TRUE;
10728 #if USE_NEW_SNAP_DELAY
10729 static void setFieldForSnapping(int x, int y, int element, int direction)
10731 struct ElementInfo *ei = &element_info[element];
10732 int direction_bit = MV_DIR_TO_BIT(direction);
10733 int graphic_snapping = ei->direction_graphic[ACTION_SNAPPING][direction_bit];
10734 int action = (graphic_snapping != IMG_EMPTY_SPACE ? ACTION_SNAPPING :
10735 IS_DIGGABLE(element) ? ACTION_DIGGING : ACTION_COLLECTING);
10737 Feld[x][y] = EL_ELEMENT_SNAPPING;
10738 MovDelay[x][y] = MOVE_DELAY_NORMAL_SPEED + 1 - 1;
10740 ResetGfxAnimation(x, y);
10742 GfxElement[x][y] = element;
10743 GfxAction[x][y] = action;
10744 GfxDir[x][y] = direction;
10745 GfxFrame[x][y] = -1;
10750 =============================================================================
10751 checkDiagonalPushing()
10752 -----------------------------------------------------------------------------
10753 check if diagonal input device direction results in pushing of object
10754 (by checking if the alternative direction is walkable, diggable, ...)
10755 =============================================================================
10758 static boolean checkDiagonalPushing(struct PlayerInfo *player,
10759 int x, int y, int real_dx, int real_dy)
10761 int jx, jy, dx, dy, xx, yy;
10763 if (real_dx == 0 || real_dy == 0) /* no diagonal direction => push */
10766 /* diagonal direction: check alternative direction */
10771 xx = jx + (dx == 0 ? real_dx : 0);
10772 yy = jy + (dy == 0 ? real_dy : 0);
10774 return (!IN_LEV_FIELD(xx, yy) || IS_SOLID_FOR_PUSHING(Feld[xx][yy]));
10778 =============================================================================
10780 -----------------------------------------------------------------------------
10781 x, y: field next to player (non-diagonal) to try to dig to
10782 real_dx, real_dy: direction as read from input device (can be diagonal)
10783 =============================================================================
10786 int DigField(struct PlayerInfo *player,
10787 int oldx, int oldy, int x, int y,
10788 int real_dx, int real_dy, int mode)
10790 boolean is_player = (IS_PLAYER(oldx, oldy) || mode != DF_DIG);
10791 boolean player_was_pushing = player->is_pushing;
10792 boolean player_can_move = (!player->cannot_move && mode != DF_SNAP);
10793 boolean player_can_move_or_snap = (!player->cannot_move || mode == DF_SNAP);
10794 int jx = oldx, jy = oldy;
10795 int dx = x - jx, dy = y - jy;
10796 int nextx = x + dx, nexty = y + dy;
10797 int move_direction = (dx == -1 ? MV_LEFT :
10798 dx == +1 ? MV_RIGHT :
10800 dy == +1 ? MV_DOWN : MV_NONE);
10801 int opposite_direction = MV_DIR_OPPOSITE(move_direction);
10802 int dig_side = MV_DIR_OPPOSITE(move_direction);
10803 int old_element = Feld[jx][jy];
10804 #if USE_FIXED_DONT_RUN_INTO
10805 int element = MovingOrBlocked2ElementIfNotLeaving(x, y);
10811 if (is_player) /* function can also be called by EL_PENGUIN */
10813 if (player->MovPos == 0)
10815 player->is_digging = FALSE;
10816 player->is_collecting = FALSE;
10819 if (player->MovPos == 0) /* last pushing move finished */
10820 player->is_pushing = FALSE;
10822 if (mode == DF_NO_PUSH) /* player just stopped pushing */
10824 player->is_switching = FALSE;
10825 player->push_delay = -1;
10827 return MP_NO_ACTION;
10831 #if !USE_FIXED_DONT_RUN_INTO
10832 if (IS_MOVING(x, y) || IS_PLAYER(x, y))
10833 return MP_NO_ACTION;
10836 if (IS_TUBE(Back[jx][jy]) && game.engine_version >= VERSION_IDENT(2,2,0,0))
10837 old_element = Back[jx][jy];
10839 /* in case of element dropped at player position, check background */
10840 else if (Back[jx][jy] != EL_EMPTY &&
10841 game.engine_version >= VERSION_IDENT(2,2,0,0))
10842 old_element = Back[jx][jy];
10845 #if USE_FIXED_DONT_RUN_INTO
10846 if (player_can_move && DONT_RUN_INTO(element))
10848 if (element == EL_ACID && dx == 0 && dy == 1)
10851 Feld[jx][jy] = EL_PLAYER_1;
10852 InitMovingField(jx, jy, MV_DOWN);
10853 Store[jx][jy] = EL_ACID;
10854 ContinueMoving(jx, jy);
10855 BuryPlayer(player);
10858 TestIfPlayerRunsIntoBadThing(jx, jy, player->MovDir);
10860 return MP_DONT_RUN_INTO;
10866 #if USE_FIXED_DONT_RUN_INTO
10867 if (player_can_move && DONT_RUN_INTO(element))
10869 TestIfPlayerRunsIntoBadThing(jx, jy, player->MovDir);
10871 return MP_DONT_RUN_INTO;
10876 if (IS_WALKABLE(old_element) && !ACCESS_FROM(old_element, move_direction))
10877 return MP_NO_ACTION; /* field has no opening in this direction */
10879 if (IS_PASSABLE(old_element) && !ACCESS_FROM(old_element,opposite_direction))
10880 return MP_NO_ACTION; /* field has no opening in this direction */
10883 #if USE_FIXED_DONT_RUN_INTO
10884 if (player_can_move && element == EL_ACID && move_direction == MV_DOWN)
10887 Feld[jx][jy] = EL_PLAYER_1;
10888 InitMovingField(jx, jy, MV_DOWN);
10889 Store[jx][jy] = EL_ACID;
10890 ContinueMoving(jx, jy);
10891 BuryPlayer(player);
10893 return MP_DONT_RUN_INTO;
10899 #if USE_FIXED_DONT_RUN_INTO
10900 if (player_can_move && DONT_RUN_INTO(element))
10902 if (element == EL_ACID && dx == 0 && dy == 1)
10905 Feld[jx][jy] = EL_PLAYER_1;
10906 InitMovingField(jx, jy, MV_DOWN);
10907 Store[jx][jy] = EL_ACID;
10908 ContinueMoving(jx, jy);
10909 BuryPlayer(player);
10912 TestIfPlayerRunsIntoBadThing(jx, jy, player->MovDir);
10914 return MP_DONT_RUN_INTO;
10919 #if USE_FIXED_DONT_RUN_INTO
10920 if (IS_MOVING(x, y) || IS_PLAYER(x, y))
10921 return MP_NO_ACTION;
10924 #if !USE_FIXED_DONT_RUN_INTO
10925 element = Feld[x][y];
10928 collect_count = element_info[element].collect_count_initial;
10930 if (!is_player && !IS_COLLECTIBLE(element)) /* penguin cannot collect it */
10931 return MP_NO_ACTION;
10933 if (game.engine_version < VERSION_IDENT(2,2,0,0))
10934 player_can_move = player_can_move_or_snap;
10936 if (mode == DF_SNAP && !IS_SNAPPABLE(element) &&
10937 game.engine_version >= VERSION_IDENT(2,2,0,0))
10939 CheckElementChangeByPlayer(x, y, element, CE_SNAPPED_BY_PLAYER,
10940 player->index_bit, dig_side);
10941 CheckTriggeredElementChangeByPlayer(x, y, element, CE_PLAYER_SNAPS_X,
10942 player->index_bit, dig_side);
10944 if (Feld[x][y] != element) /* field changed by snapping */
10947 return MP_NO_ACTION;
10950 if (game.gravity && is_player && !player->is_auto_moving &&
10951 canFallDown(player) && move_direction != MV_DOWN &&
10952 !canMoveToValidFieldWithGravity(jx, jy, move_direction))
10953 return MP_NO_ACTION; /* player cannot walk here due to gravity */
10955 if (player_can_move &&
10956 IS_WALKABLE(element) && ACCESS_FROM(element, opposite_direction))
10958 int sound_element = SND_ELEMENT(element);
10959 int sound_action = ACTION_WALKING;
10961 if (IS_RND_GATE(element))
10963 if (!player->key[RND_GATE_NR(element)])
10964 return MP_NO_ACTION;
10966 else if (IS_RND_GATE_GRAY(element))
10968 if (!player->key[RND_GATE_GRAY_NR(element)])
10969 return MP_NO_ACTION;
10971 else if (IS_RND_GATE_GRAY_ACTIVE(element))
10973 if (!player->key[RND_GATE_GRAY_ACTIVE_NR(element)])
10974 return MP_NO_ACTION;
10976 else if (element == EL_EXIT_OPEN ||
10977 element == EL_SP_EXIT_OPEN ||
10978 element == EL_SP_EXIT_OPENING)
10980 sound_action = ACTION_PASSING; /* player is passing exit */
10982 else if (element == EL_EMPTY)
10984 sound_action = ACTION_MOVING; /* nothing to walk on */
10987 /* play sound from background or player, whatever is available */
10988 if (element_info[sound_element].sound[sound_action] != SND_UNDEFINED)
10989 PlayLevelSoundElementAction(x, y, sound_element, sound_action);
10991 PlayLevelSoundElementAction(x, y, player->artwork_element, sound_action);
10993 else if (player_can_move &&
10994 IS_PASSABLE(element) && canPassField(x, y, move_direction))
10996 if (!ACCESS_FROM(element, opposite_direction))
10997 return MP_NO_ACTION; /* field not accessible from this direction */
10999 if (CAN_MOVE(element)) /* only fixed elements can be passed! */
11000 return MP_NO_ACTION;
11002 if (IS_EM_GATE(element))
11004 if (!player->key[EM_GATE_NR(element)])
11005 return MP_NO_ACTION;
11007 else if (IS_EM_GATE_GRAY(element))
11009 if (!player->key[EM_GATE_GRAY_NR(element)])
11010 return MP_NO_ACTION;
11012 else if (IS_EM_GATE_GRAY_ACTIVE(element))
11014 if (!player->key[EM_GATE_GRAY_ACTIVE_NR(element)])
11015 return MP_NO_ACTION;
11017 else if (IS_SP_PORT(element))
11019 if (element == EL_SP_GRAVITY_PORT_LEFT ||
11020 element == EL_SP_GRAVITY_PORT_RIGHT ||
11021 element == EL_SP_GRAVITY_PORT_UP ||
11022 element == EL_SP_GRAVITY_PORT_DOWN)
11023 game.gravity = !game.gravity;
11024 else if (element == EL_SP_GRAVITY_ON_PORT_LEFT ||
11025 element == EL_SP_GRAVITY_ON_PORT_RIGHT ||
11026 element == EL_SP_GRAVITY_ON_PORT_UP ||
11027 element == EL_SP_GRAVITY_ON_PORT_DOWN)
11028 game.gravity = TRUE;
11029 else if (element == EL_SP_GRAVITY_OFF_PORT_LEFT ||
11030 element == EL_SP_GRAVITY_OFF_PORT_RIGHT ||
11031 element == EL_SP_GRAVITY_OFF_PORT_UP ||
11032 element == EL_SP_GRAVITY_OFF_PORT_DOWN)
11033 game.gravity = FALSE;
11036 /* automatically move to the next field with double speed */
11037 player->programmed_action = move_direction;
11039 if (player->move_delay_reset_counter == 0)
11041 player->move_delay_reset_counter = 2; /* two double speed steps */
11043 DOUBLE_PLAYER_SPEED(player);
11046 PlayLevelSoundAction(x, y, ACTION_PASSING);
11048 else if (player_can_move_or_snap && IS_DIGGABLE(element))
11052 if (mode != DF_SNAP)
11054 GfxElement[x][y] = GFX_ELEMENT(element);
11055 player->is_digging = TRUE;
11058 PlayLevelSoundElementAction(x, y, element, ACTION_DIGGING);
11060 CheckTriggeredElementChangeByPlayer(x, y, element, CE_PLAYER_DIGS_X,
11061 player->index_bit, dig_side);
11063 if (mode == DF_SNAP)
11065 #if USE_NEW_SNAP_DELAY
11066 if (level.block_snap_field)
11067 setFieldForSnapping(x, y, element, move_direction);
11069 TestIfElementTouchesCustomElement(x, y); /* for empty space */
11071 TestIfElementTouchesCustomElement(x, y); /* for empty space */
11074 CheckTriggeredElementChangeByPlayer(x, y, element, CE_PLAYER_SNAPS_X,
11075 player->index_bit, dig_side);
11078 else if (player_can_move_or_snap && IS_COLLECTIBLE(element))
11082 if (is_player && mode != DF_SNAP)
11084 GfxElement[x][y] = element;
11085 player->is_collecting = TRUE;
11088 if (element == EL_SPEED_PILL)
11090 player->move_delay_value = MOVE_DELAY_HIGH_SPEED;
11092 else if (element == EL_EXTRA_TIME && level.time > 0)
11094 TimeLeft += level.extra_time;
11095 DrawGameValue_Time(TimeLeft);
11097 else if (element == EL_SHIELD_NORMAL || element == EL_SHIELD_DEADLY)
11099 player->shield_normal_time_left += level.shield_normal_time;
11100 if (element == EL_SHIELD_DEADLY)
11101 player->shield_deadly_time_left += level.shield_deadly_time;
11103 else if (element == EL_DYNAMITE || element == EL_SP_DISK_RED)
11105 if (player->inventory_size < MAX_INVENTORY_SIZE)
11106 player->inventory_element[player->inventory_size++] = element;
11108 DrawGameValue_Dynamite(local_player->inventory_size);
11110 else if (element == EL_DYNABOMB_INCREASE_NUMBER)
11112 player->dynabomb_count++;
11113 player->dynabombs_left++;
11115 else if (element == EL_DYNABOMB_INCREASE_SIZE)
11117 player->dynabomb_size++;
11119 else if (element == EL_DYNABOMB_INCREASE_POWER)
11121 player->dynabomb_xl = TRUE;
11123 else if (IS_KEY(element))
11125 player->key[KEY_NR(element)] = TRUE;
11127 DrawGameValue_Keys(player->key);
11129 redraw_mask |= REDRAW_DOOR_1;
11131 else if (IS_ENVELOPE(element))
11133 player->show_envelope = element;
11135 else if (element == EL_EMC_LENSES)
11137 game.lenses_time_left = level.lenses_time * FRAMES_PER_SECOND;
11139 RedrawAllInvisibleElementsForLenses();
11141 else if (element == EL_EMC_MAGNIFIER)
11143 game.magnify_time_left = level.magnify_time * FRAMES_PER_SECOND;
11145 RedrawAllInvisibleElementsForMagnifier();
11147 else if (IS_DROPPABLE(element) ||
11148 IS_THROWABLE(element)) /* can be collected and dropped */
11152 if (collect_count == 0)
11153 player->inventory_infinite_element = element;
11155 for (i = 0; i < collect_count; i++)
11156 if (player->inventory_size < MAX_INVENTORY_SIZE)
11157 player->inventory_element[player->inventory_size++] = element;
11159 DrawGameValue_Dynamite(local_player->inventory_size);
11161 else if (collect_count > 0)
11163 local_player->gems_still_needed -= collect_count;
11164 if (local_player->gems_still_needed < 0)
11165 local_player->gems_still_needed = 0;
11167 DrawGameValue_Emeralds(local_player->gems_still_needed);
11170 RaiseScoreElement(element);
11171 PlayLevelSoundElementAction(x, y, element, ACTION_COLLECTING);
11174 CheckTriggeredElementChangeByPlayer(x, y, element, CE_PLAYER_COLLECTS_X,
11175 player->index_bit, dig_side);
11177 if (mode == DF_SNAP)
11179 #if USE_NEW_SNAP_DELAY
11180 if (level.block_snap_field)
11181 setFieldForSnapping(x, y, element, move_direction);
11183 TestIfElementTouchesCustomElement(x, y); /* for empty space */
11185 TestIfElementTouchesCustomElement(x, y); /* for empty space */
11188 CheckTriggeredElementChangeByPlayer(x, y, element, CE_PLAYER_SNAPS_X,
11189 player->index_bit, dig_side);
11192 else if (player_can_move_or_snap && IS_PUSHABLE(element))
11194 if (mode == DF_SNAP && element != EL_BD_ROCK)
11195 return MP_NO_ACTION;
11197 if (CAN_FALL(element) && dy)
11198 return MP_NO_ACTION;
11200 if (CAN_FALL(element) && IN_LEV_FIELD(x, y + 1) && IS_FREE(x, y + 1) &&
11201 !(element == EL_SPRING && level.use_spring_bug))
11202 return MP_NO_ACTION;
11204 if (CAN_MOVE(element) && GET_MAX_MOVE_DELAY(element) == 0 &&
11205 ((move_direction & MV_VERTICAL &&
11206 ((element_info[element].move_pattern & MV_LEFT &&
11207 IN_LEV_FIELD(x - 1, y) && IS_FREE(x - 1, y)) ||
11208 (element_info[element].move_pattern & MV_RIGHT &&
11209 IN_LEV_FIELD(x + 1, y) && IS_FREE(x + 1, y)))) ||
11210 (move_direction & MV_HORIZONTAL &&
11211 ((element_info[element].move_pattern & MV_UP &&
11212 IN_LEV_FIELD(x, y - 1) && IS_FREE(x, y - 1)) ||
11213 (element_info[element].move_pattern & MV_DOWN &&
11214 IN_LEV_FIELD(x, y + 1) && IS_FREE(x, y + 1))))))
11215 return MP_NO_ACTION;
11217 /* do not push elements already moving away faster than player */
11218 if (CAN_MOVE(element) && MovDir[x][y] == move_direction &&
11219 ABS(getElementMoveStepsize(x, y)) > MOVE_STEPSIZE_NORMAL)
11220 return MP_NO_ACTION;
11222 if (game.engine_version >= VERSION_IDENT(3,1,0,0))
11224 if (player->push_delay_value == -1 || !player_was_pushing)
11225 player->push_delay_value = GET_NEW_PUSH_DELAY(element);
11227 else if (game.engine_version >= VERSION_IDENT(3,0,7,1))
11229 if (player->push_delay_value == -1)
11230 player->push_delay_value = GET_NEW_PUSH_DELAY(element);
11232 else if (game.engine_version >= VERSION_IDENT(2,2,0,7))
11234 if (!player->is_pushing)
11235 player->push_delay_value = GET_NEW_PUSH_DELAY(element);
11238 player->is_pushing = TRUE;
11240 if (!(IN_LEV_FIELD(nextx, nexty) &&
11241 (IS_FREE(nextx, nexty) ||
11242 (Feld[nextx][nexty] == EL_SOKOBAN_FIELD_EMPTY &&
11243 IS_SB_ELEMENT(element)))))
11244 return MP_NO_ACTION;
11246 if (!checkDiagonalPushing(player, x, y, real_dx, real_dy))
11247 return MP_NO_ACTION;
11249 if (player->push_delay == -1) /* new pushing; restart delay */
11250 player->push_delay = 0;
11252 if (player->push_delay < player->push_delay_value &&
11253 !(tape.playing && tape.file_version < FILE_VERSION_2_0) &&
11254 element != EL_SPRING && element != EL_BALLOON)
11256 /* make sure that there is no move delay before next try to push */
11257 if (game.engine_version >= VERSION_IDENT(3,0,7,1))
11258 player->move_delay = 0;
11260 return MP_NO_ACTION;
11263 if (IS_SB_ELEMENT(element))
11265 if (element == EL_SOKOBAN_FIELD_FULL)
11267 Back[x][y] = EL_SOKOBAN_FIELD_EMPTY;
11268 local_player->sokobanfields_still_needed++;
11271 if (Feld[nextx][nexty] == EL_SOKOBAN_FIELD_EMPTY)
11273 Back[nextx][nexty] = EL_SOKOBAN_FIELD_EMPTY;
11274 local_player->sokobanfields_still_needed--;
11277 Feld[x][y] = EL_SOKOBAN_OBJECT;
11279 if (Back[x][y] == Back[nextx][nexty])
11280 PlayLevelSoundAction(x, y, ACTION_PUSHING);
11281 else if (Back[x][y] != 0)
11282 PlayLevelSoundElementAction(x, y, EL_SOKOBAN_FIELD_FULL,
11285 PlayLevelSoundElementAction(nextx, nexty, EL_SOKOBAN_FIELD_EMPTY,
11288 if (local_player->sokobanfields_still_needed == 0 &&
11289 game.emulation == EMU_SOKOBAN)
11291 player->LevelSolved = player->GameOver = TRUE;
11292 PlayLevelSound(x, y, SND_GAME_SOKOBAN_SOLVING);
11296 PlayLevelSoundElementAction(x, y, element, ACTION_PUSHING);
11298 InitMovingField(x, y, move_direction);
11299 GfxAction[x][y] = ACTION_PUSHING;
11301 if (mode == DF_SNAP)
11302 ContinueMoving(x, y);
11304 MovPos[x][y] = (dx != 0 ? dx : dy);
11306 Pushed[x][y] = TRUE;
11307 Pushed[nextx][nexty] = TRUE;
11309 if (game.engine_version < VERSION_IDENT(2,2,0,7))
11310 player->push_delay_value = GET_NEW_PUSH_DELAY(element);
11312 player->push_delay_value = -1; /* get new value later */
11314 /* check for element change _after_ element has been pushed */
11315 if (game.use_change_when_pushing_bug)
11317 CheckElementChangeByPlayer(x, y, element, CE_PUSHED_BY_PLAYER,
11318 player->index_bit, dig_side);
11319 CheckTriggeredElementChangeByPlayer(x, y, element, CE_PLAYER_PUSHES_X,
11320 player->index_bit, dig_side);
11323 else if (IS_SWITCHABLE(element))
11325 if (PLAYER_SWITCHING(player, x, y))
11327 CheckTriggeredElementChangeByPlayer(x, y, element, CE_PLAYER_PRESSES_X,
11328 player->index_bit, dig_side);
11333 player->is_switching = TRUE;
11334 player->switch_x = x;
11335 player->switch_y = y;
11337 PlayLevelSoundElementAction(x, y, element, ACTION_ACTIVATING);
11339 if (element == EL_ROBOT_WHEEL)
11341 Feld[x][y] = EL_ROBOT_WHEEL_ACTIVE;
11345 DrawLevelField(x, y);
11347 else if (element == EL_SP_TERMINAL)
11352 SCAN_PLAYFIELD(xx, yy)
11354 for (yy = 0; yy < lev_fieldy; yy++) for (xx = 0; xx < lev_fieldx; xx++)
11357 if (Feld[xx][yy] == EL_SP_DISK_YELLOW)
11359 else if (Feld[xx][yy] == EL_SP_TERMINAL)
11360 Feld[xx][yy] = EL_SP_TERMINAL_ACTIVE;
11363 else if (IS_BELT_SWITCH(element))
11365 ToggleBeltSwitch(x, y);
11367 else if (element == EL_SWITCHGATE_SWITCH_UP ||
11368 element == EL_SWITCHGATE_SWITCH_DOWN)
11370 ToggleSwitchgateSwitch(x, y);
11372 else if (element == EL_LIGHT_SWITCH ||
11373 element == EL_LIGHT_SWITCH_ACTIVE)
11375 ToggleLightSwitch(x, y);
11377 else if (element == EL_TIMEGATE_SWITCH)
11379 ActivateTimegateSwitch(x, y);
11381 else if (element == EL_BALLOON_SWITCH_LEFT ||
11382 element == EL_BALLOON_SWITCH_RIGHT ||
11383 element == EL_BALLOON_SWITCH_UP ||
11384 element == EL_BALLOON_SWITCH_DOWN ||
11385 element == EL_BALLOON_SWITCH_NONE ||
11386 element == EL_BALLOON_SWITCH_ANY)
11388 game.wind_direction = (element == EL_BALLOON_SWITCH_LEFT ? MV_LEFT :
11389 element == EL_BALLOON_SWITCH_RIGHT ? MV_RIGHT :
11390 element == EL_BALLOON_SWITCH_UP ? MV_UP :
11391 element == EL_BALLOON_SWITCH_DOWN ? MV_DOWN :
11392 element == EL_BALLOON_SWITCH_NONE ? MV_NONE :
11395 else if (element == EL_LAMP)
11397 Feld[x][y] = EL_LAMP_ACTIVE;
11398 local_player->lights_still_needed--;
11400 ResetGfxAnimation(x, y);
11401 DrawLevelField(x, y);
11403 else if (element == EL_TIME_ORB_FULL)
11405 Feld[x][y] = EL_TIME_ORB_EMPTY;
11407 if (level.time > 0 || level.use_time_orb_bug)
11409 TimeLeft += level.time_orb_time;
11410 DrawGameValue_Time(TimeLeft);
11413 ResetGfxAnimation(x, y);
11414 DrawLevelField(x, y);
11416 else if (element == EL_EMC_MAGIC_BALL_SWITCH ||
11417 element == EL_EMC_MAGIC_BALL_SWITCH_ACTIVE)
11421 game.ball_state = !game.ball_state;
11424 SCAN_PLAYFIELD(xx, yy)
11426 for (yy = 0; yy < lev_fieldy; yy++) for (xx = 0; xx < lev_fieldx; xx++)
11429 int e = Feld[xx][yy];
11431 if (game.ball_state)
11433 if (e == EL_EMC_MAGIC_BALL)
11434 CreateField(xx, yy, EL_EMC_MAGIC_BALL_ACTIVE);
11435 else if (e == EL_EMC_MAGIC_BALL_SWITCH)
11436 CreateField(xx, yy, EL_EMC_MAGIC_BALL_SWITCH_ACTIVE);
11440 if (e == EL_EMC_MAGIC_BALL_ACTIVE)
11441 CreateField(xx, yy, EL_EMC_MAGIC_BALL);
11442 else if (e == EL_EMC_MAGIC_BALL_SWITCH_ACTIVE)
11443 CreateField(xx, yy, EL_EMC_MAGIC_BALL_SWITCH);
11448 CheckTriggeredElementChangeByPlayer(x, y, element, CE_SWITCH_OF_X,
11449 player->index_bit, dig_side);
11451 CheckTriggeredElementChangeByPlayer(x, y, element, CE_PLAYER_SWITCHES_X,
11452 player->index_bit, dig_side);
11454 CheckTriggeredElementChangeByPlayer(x, y, element, CE_PLAYER_PRESSES_X,
11455 player->index_bit, dig_side);
11461 if (!PLAYER_SWITCHING(player, x, y))
11463 player->is_switching = TRUE;
11464 player->switch_x = x;
11465 player->switch_y = y;
11467 CheckElementChangeByPlayer(x, y, element, CE_SWITCHED,
11468 player->index_bit, dig_side);
11469 CheckTriggeredElementChangeByPlayer(x, y, element, CE_SWITCH_OF_X,
11470 player->index_bit, dig_side);
11472 CheckElementChangeByPlayer(x, y, element, CE_SWITCHED_BY_PLAYER,
11473 player->index_bit, dig_side);
11474 CheckTriggeredElementChangeByPlayer(x, y, element, CE_PLAYER_SWITCHES_X,
11475 player->index_bit, dig_side);
11478 CheckElementChangeByPlayer(x, y, element, CE_PRESSED_BY_PLAYER,
11479 player->index_bit, dig_side);
11480 CheckTriggeredElementChangeByPlayer(x, y, element, CE_PLAYER_PRESSES_X,
11481 player->index_bit, dig_side);
11483 return MP_NO_ACTION;
11486 player->push_delay = -1;
11488 if (is_player) /* function can also be called by EL_PENGUIN */
11490 if (Feld[x][y] != element) /* really digged/collected something */
11491 player->is_collecting = !player->is_digging;
11497 boolean SnapField(struct PlayerInfo *player, int dx, int dy)
11499 int jx = player->jx, jy = player->jy;
11500 int x = jx + dx, y = jy + dy;
11501 int snap_direction = (dx == -1 ? MV_LEFT :
11502 dx == +1 ? MV_RIGHT :
11504 dy == +1 ? MV_DOWN : MV_NONE);
11506 if (player->MovPos != 0 && game.engine_version >= VERSION_IDENT(2,2,0,0))
11509 if (!player->active || !IN_LEV_FIELD(x, y))
11517 if (player->MovPos == 0)
11518 player->is_pushing = FALSE;
11520 player->is_snapping = FALSE;
11522 if (player->MovPos == 0)
11524 player->is_moving = FALSE;
11525 player->is_digging = FALSE;
11526 player->is_collecting = FALSE;
11532 if (player->is_snapping)
11535 player->MovDir = snap_direction;
11537 if (player->MovPos == 0)
11539 player->is_moving = FALSE;
11540 player->is_digging = FALSE;
11541 player->is_collecting = FALSE;
11544 player->is_dropping = FALSE;
11546 if (DigField(player, jx, jy, x, y, 0, 0, DF_SNAP) == MP_NO_ACTION)
11549 player->is_snapping = TRUE;
11551 if (player->MovPos == 0)
11553 player->is_moving = FALSE;
11554 player->is_digging = FALSE;
11555 player->is_collecting = FALSE;
11558 if (player->MovPos != 0) /* prevent graphic bugs in versions < 2.2.0 */
11559 DrawLevelField(player->last_jx, player->last_jy);
11561 DrawLevelField(x, y);
11566 boolean DropElement(struct PlayerInfo *player)
11568 int old_element, new_element;
11569 int dropx = player->jx, dropy = player->jy;
11570 int drop_direction = player->MovDir;
11571 int drop_side = drop_direction;
11572 int drop_element = (player->inventory_size > 0 ?
11573 player->inventory_element[player->inventory_size - 1] :
11574 player->inventory_infinite_element != EL_UNDEFINED ?
11575 player->inventory_infinite_element :
11576 player->dynabombs_left > 0 ?
11577 EL_DYNABOMB_PLAYER_1_ACTIVE + player->index_nr :
11580 /* do not drop an element on top of another element; when holding drop key
11581 pressed without moving, dropped element must move away before the next
11582 element can be dropped (this is especially important if the next element
11583 is dynamite, which can be placed on background for historical reasons) */
11584 if (PLAYER_DROPPING(player, dropx, dropy) && Feld[dropx][dropy] != EL_EMPTY)
11587 if (IS_THROWABLE(drop_element))
11589 dropx += GET_DX_FROM_DIR(drop_direction);
11590 dropy += GET_DY_FROM_DIR(drop_direction);
11592 if (!IN_LEV_FIELD(dropx, dropy))
11596 old_element = Feld[dropx][dropy]; /* old element at dropping position */
11597 new_element = drop_element; /* default: no change when dropping */
11599 /* check if player is active, not moving and ready to drop */
11600 if (!player->active || player->MovPos || player->drop_delay > 0)
11603 /* check if player has anything that can be dropped */
11604 if (new_element == EL_UNDEFINED)
11607 /* check if anything can be dropped at the current position */
11608 if (IS_ACTIVE_BOMB(old_element) || old_element == EL_EXPLOSION)
11611 /* collected custom elements can only be dropped on empty fields */
11612 if (IS_CUSTOM_ELEMENT(new_element) && old_element != EL_EMPTY)
11615 if (old_element != EL_EMPTY)
11616 Back[dropx][dropy] = old_element; /* store old element on this field */
11618 ResetGfxAnimation(dropx, dropy);
11619 ResetRandomAnimationValue(dropx, dropy);
11621 if (player->inventory_size > 0 ||
11622 player->inventory_infinite_element != EL_UNDEFINED)
11624 if (player->inventory_size > 0)
11626 player->inventory_size--;
11628 DrawGameValue_Dynamite(local_player->inventory_size);
11630 if (new_element == EL_DYNAMITE)
11631 new_element = EL_DYNAMITE_ACTIVE;
11632 else if (new_element == EL_SP_DISK_RED)
11633 new_element = EL_SP_DISK_RED_ACTIVE;
11636 Feld[dropx][dropy] = new_element;
11638 if (IN_SCR_FIELD(SCREENX(dropx), SCREENY(dropy)))
11639 DrawGraphicThruMask(SCREENX(dropx), SCREENY(dropy),
11640 el2img(Feld[dropx][dropy]), 0);
11642 PlayLevelSoundAction(dropx, dropy, ACTION_DROPPING);
11644 /* needed if previous element just changed to "empty" in the last frame */
11645 ChangeCount[dropx][dropy] = 0; /* allow at least one more change */
11647 CheckElementChangeByPlayer(dropx, dropy, new_element, CE_DROPPED_BY_PLAYER,
11648 player->index_bit, drop_side);
11649 CheckTriggeredElementChangeByPlayer(dropx, dropy, new_element,
11651 player->index_bit, drop_side);
11653 TestIfElementTouchesCustomElement(dropx, dropy);
11655 else /* player is dropping a dyna bomb */
11657 player->dynabombs_left--;
11659 Feld[dropx][dropy] = new_element;
11661 if (IN_SCR_FIELD(SCREENX(dropx), SCREENY(dropy)))
11662 DrawGraphicThruMask(SCREENX(dropx), SCREENY(dropy),
11663 el2img(Feld[dropx][dropy]), 0);
11665 PlayLevelSoundAction(dropx, dropy, ACTION_DROPPING);
11668 if (Feld[dropx][dropy] == new_element) /* uninitialized unless CE change */
11669 InitField_WithBug1(dropx, dropy, FALSE);
11671 new_element = Feld[dropx][dropy]; /* element might have changed */
11673 if (IS_CUSTOM_ELEMENT(new_element) && CAN_MOVE(new_element) &&
11674 element_info[new_element].move_pattern == MV_WHEN_DROPPED)
11676 int move_direction, nextx, nexty;
11678 if (element_info[new_element].move_direction_initial == MV_START_AUTOMATIC)
11679 MovDir[dropx][dropy] = drop_direction;
11681 move_direction = MovDir[dropx][dropy];
11682 nextx = dropx + GET_DX_FROM_DIR(move_direction);
11683 nexty = dropy + GET_DY_FROM_DIR(move_direction);
11685 ChangeCount[dropx][dropy] = 0; /* allow at least one more change */
11686 CheckCollision[dropx][dropy] = 2;
11689 player->drop_delay = GET_NEW_DROP_DELAY(drop_element);
11690 player->is_dropping = TRUE;
11692 player->drop_x = dropx;
11693 player->drop_y = dropy;
11698 /* ------------------------------------------------------------------------- */
11699 /* game sound playing functions */
11700 /* ------------------------------------------------------------------------- */
11702 static int *loop_sound_frame = NULL;
11703 static int *loop_sound_volume = NULL;
11705 void InitPlayLevelSound()
11707 int num_sounds = getSoundListSize();
11709 checked_free(loop_sound_frame);
11710 checked_free(loop_sound_volume);
11712 loop_sound_frame = checked_calloc(num_sounds * sizeof(int));
11713 loop_sound_volume = checked_calloc(num_sounds * sizeof(int));
11716 static void PlayLevelSound(int x, int y, int nr)
11718 int sx = SCREENX(x), sy = SCREENY(y);
11719 int volume, stereo_position;
11720 int max_distance = 8;
11721 int type = (IS_LOOP_SOUND(nr) ? SND_CTRL_PLAY_LOOP : SND_CTRL_PLAY_SOUND);
11723 if ((!setup.sound_simple && !IS_LOOP_SOUND(nr)) ||
11724 (!setup.sound_loops && IS_LOOP_SOUND(nr)))
11727 if (!IN_LEV_FIELD(x, y) ||
11728 sx < -max_distance || sx >= SCR_FIELDX + max_distance ||
11729 sy < -max_distance || sy >= SCR_FIELDY + max_distance)
11732 volume = SOUND_MAX_VOLUME;
11734 if (!IN_SCR_FIELD(sx, sy))
11736 int dx = ABS(sx - SCR_FIELDX / 2) - SCR_FIELDX / 2;
11737 int dy = ABS(sy - SCR_FIELDY / 2) - SCR_FIELDY / 2;
11739 volume -= volume * (dx > dy ? dx : dy) / max_distance;
11742 stereo_position = (SOUND_MAX_LEFT +
11743 (sx + max_distance) * SOUND_MAX_LEFT2RIGHT /
11744 (SCR_FIELDX + 2 * max_distance));
11746 if (IS_LOOP_SOUND(nr))
11748 /* This assures that quieter loop sounds do not overwrite louder ones,
11749 while restarting sound volume comparison with each new game frame. */
11751 if (loop_sound_volume[nr] > volume && loop_sound_frame[nr] == FrameCounter)
11754 loop_sound_volume[nr] = volume;
11755 loop_sound_frame[nr] = FrameCounter;
11758 PlaySoundExt(nr, volume, stereo_position, type);
11761 static void PlayLevelSoundNearest(int x, int y, int sound_action)
11763 PlayLevelSound(x < LEVELX(BX1) ? LEVELX(BX1) :
11764 x > LEVELX(BX2) ? LEVELX(BX2) : x,
11765 y < LEVELY(BY1) ? LEVELY(BY1) :
11766 y > LEVELY(BY2) ? LEVELY(BY2) : y,
11770 static void PlayLevelSoundAction(int x, int y, int action)
11772 PlayLevelSoundElementAction(x, y, Feld[x][y], action);
11775 static void PlayLevelSoundElementAction(int x, int y, int element, int action)
11777 int sound_effect = element_info[SND_ELEMENT(element)].sound[action];
11779 if (sound_effect != SND_UNDEFINED)
11780 PlayLevelSound(x, y, sound_effect);
11783 static void PlayLevelSoundElementActionIfLoop(int x, int y, int element,
11786 int sound_effect = element_info[SND_ELEMENT(element)].sound[action];
11788 if (sound_effect != SND_UNDEFINED && IS_LOOP_SOUND(sound_effect))
11789 PlayLevelSound(x, y, sound_effect);
11792 static void PlayLevelSoundActionIfLoop(int x, int y, int action)
11794 int sound_effect = element_info[SND_ELEMENT(Feld[x][y])].sound[action];
11796 if (sound_effect != SND_UNDEFINED && IS_LOOP_SOUND(sound_effect))
11797 PlayLevelSound(x, y, sound_effect);
11800 static void StopLevelSoundActionIfLoop(int x, int y, int action)
11802 int sound_effect = element_info[SND_ELEMENT(Feld[x][y])].sound[action];
11804 if (sound_effect != SND_UNDEFINED && IS_LOOP_SOUND(sound_effect))
11805 StopSound(sound_effect);
11808 static void PlayLevelMusic()
11810 if (levelset.music[level_nr] != MUS_UNDEFINED)
11811 PlayMusic(levelset.music[level_nr]); /* from config file */
11813 PlayMusic(MAP_NOCONF_MUSIC(level_nr)); /* from music dir */
11816 void PlayLevelSound_EM(int x, int y, int element_em, int sample)
11818 int element = (element_em > -1 ? map_element_EM_to_RND(element_em) : 0);
11823 PlayLevelSoundElementAction(x, y, element, ACTION_WALKING);
11827 PlayLevelSoundElementAction(x, y, element, ACTION_PUSHING);
11831 PlayLevelSoundElementAction(x, y, element, ACTION_IMPACT);
11835 PlayLevelSoundElementAction(x, y, element, ACTION_IMPACT);
11839 PlayLevelSoundElementAction(x, y, element, ACTION_BREAKING);
11843 PlayLevelSoundElementAction(x, y, element, ACTION_MOVING);
11847 PlayLevelSoundElementAction(x, y, element, ACTION_MOVING);
11850 case SAMPLE_android_clone:
11851 PlayLevelSoundElementAction(x, y, element, ACTION_DROPPING);
11854 case SAMPLE_android_move:
11855 PlayLevelSoundElementAction(x, y, element, ACTION_MOVING);
11858 case SAMPLE_spring:
11859 PlayLevelSoundElementAction(x, y, element, ACTION_IMPACT);
11863 PlayLevelSoundElementAction(x, y, element, ACTION_SLURPING);
11867 PlayLevelSoundElementAction(x, y, element, ACTION_WAITING);
11870 case SAMPLE_eater_eat:
11871 PlayLevelSoundElementAction(x, y, element, ACTION_DIGGING);
11875 PlayLevelSoundElementAction(x, y, element, ACTION_MOVING);
11878 case SAMPLE_collect:
11879 PlayLevelSoundElementAction(x, y, element, ACTION_COLLECTING);
11882 case SAMPLE_diamond:
11883 PlayLevelSoundElementAction(x, y, element, ACTION_IMPACT);
11886 case SAMPLE_squash:
11887 /* !!! CHECK THIS !!! */
11889 PlayLevelSoundElementAction(x, y, element, ACTION_BREAKING);
11891 PlayLevelSoundElementAction(x, y, element, ACTION_SMASHED_BY_ROCK);
11895 case SAMPLE_wonderfall:
11896 PlayLevelSoundElementAction(x, y, element, ACTION_FILLING);
11900 PlayLevelSoundElementAction(x, y, element, ACTION_IMPACT);
11904 PlayLevelSoundElementAction(x, y, element, ACTION_PUSHING);
11908 PlayLevelSoundElementAction(x, y, element, ACTION_DIGGING);
11912 PlayLevelSoundElementAction(x, y, element, ACTION_SPLASHING);
11916 PlayLevelSoundElementAction(x, y, element, ACTION_DROPPING);
11920 PlayLevelSoundElementAction(x, y, element, ACTION_GROWING);
11923 case SAMPLE_wonder:
11924 PlayLevelSoundElementAction(x, y, element, ACTION_ACTIVE);
11928 PlayLevelSoundElementAction(x, y, element, ACTION_PASSING);
11931 case SAMPLE_exit_open:
11932 PlayLevelSoundElementAction(x, y, element, ACTION_OPENING);
11935 case SAMPLE_exit_leave:
11936 PlayLevelSoundElementAction(x, y, element, ACTION_PASSING);
11939 case SAMPLE_dynamite:
11940 PlayLevelSoundElementAction(x, y, element, ACTION_DROPPING);
11944 PlayLevelSoundElementAction(x, y, element, ACTION_ACTIVE);
11948 PlayLevelSoundElementAction(x, y, element, ACTION_ACTIVATING);
11952 PlayLevelSoundElementAction(x, y, element, ACTION_ACTIVE);
11956 PlayLevelSoundElementAction(x, y, element, ACTION_EXPLODING);
11960 PlayLevelSoundElementAction(x, y, element, ACTION_DYING);
11964 PlaySoundStereo(SND_GAME_RUNNING_OUT_OF_TIME, SOUND_MIDDLE);
11968 PlayLevelSoundElementAction(x, y, element, ACTION_DEFAULT);
11973 void RaiseScore(int value)
11975 local_player->score += value;
11977 DrawGameValue_Score(local_player->score);
11980 void RaiseScoreElement(int element)
11985 case EL_BD_DIAMOND:
11986 case EL_EMERALD_YELLOW:
11987 case EL_EMERALD_RED:
11988 case EL_EMERALD_PURPLE:
11989 case EL_SP_INFOTRON:
11990 RaiseScore(level.score[SC_EMERALD]);
11993 RaiseScore(level.score[SC_DIAMOND]);
11996 RaiseScore(level.score[SC_CRYSTAL]);
11999 RaiseScore(level.score[SC_PEARL]);
12002 case EL_BD_BUTTERFLY:
12003 case EL_SP_ELECTRON:
12004 RaiseScore(level.score[SC_BUG]);
12007 case EL_BD_FIREFLY:
12008 case EL_SP_SNIKSNAK:
12009 RaiseScore(level.score[SC_SPACESHIP]);
12012 case EL_DARK_YAMYAM:
12013 RaiseScore(level.score[SC_YAMYAM]);
12016 RaiseScore(level.score[SC_ROBOT]);
12019 RaiseScore(level.score[SC_PACMAN]);
12022 RaiseScore(level.score[SC_NUT]);
12025 case EL_SP_DISK_RED:
12026 case EL_DYNABOMB_INCREASE_NUMBER:
12027 case EL_DYNABOMB_INCREASE_SIZE:
12028 case EL_DYNABOMB_INCREASE_POWER:
12029 RaiseScore(level.score[SC_DYNAMITE]);
12031 case EL_SHIELD_NORMAL:
12032 case EL_SHIELD_DEADLY:
12033 RaiseScore(level.score[SC_SHIELD]);
12035 case EL_EXTRA_TIME:
12036 RaiseScore(level.extra_time_score);
12050 RaiseScore(level.score[SC_KEY]);
12053 RaiseScore(element_info[element].collect_score);
12058 void RequestQuitGame(boolean ask_if_really_quit)
12060 if (AllPlayersGone ||
12061 !ask_if_really_quit ||
12062 level_editor_test_game ||
12063 Request("Do you really want to quit the game ?",
12064 REQ_ASK | REQ_STAY_CLOSED))
12066 #if defined(NETWORK_AVALIABLE)
12067 if (options.network)
12068 SendToServer_StopPlaying();
12072 game_status = GAME_MODE_MAIN;
12078 if (tape.playing && tape.deactivate_display)
12079 TapeDeactivateDisplayOff(TRUE);
12081 OpenDoor(DOOR_OPEN_1 | DOOR_COPY_BACK);
12083 if (tape.playing && tape.deactivate_display)
12084 TapeDeactivateDisplayOn();
12089 /* ---------- new game button stuff ---------------------------------------- */
12091 /* graphic position values for game buttons */
12092 #define GAME_BUTTON_XSIZE 30
12093 #define GAME_BUTTON_YSIZE 30
12094 #define GAME_BUTTON_XPOS 5
12095 #define GAME_BUTTON_YPOS 215
12096 #define SOUND_BUTTON_XPOS 5
12097 #define SOUND_BUTTON_YPOS (GAME_BUTTON_YPOS + GAME_BUTTON_YSIZE)
12099 #define GAME_BUTTON_STOP_XPOS (GAME_BUTTON_XPOS + 0 * GAME_BUTTON_XSIZE)
12100 #define GAME_BUTTON_PAUSE_XPOS (GAME_BUTTON_XPOS + 1 * GAME_BUTTON_XSIZE)
12101 #define GAME_BUTTON_PLAY_XPOS (GAME_BUTTON_XPOS + 2 * GAME_BUTTON_XSIZE)
12102 #define SOUND_BUTTON_MUSIC_XPOS (SOUND_BUTTON_XPOS + 0 * GAME_BUTTON_XSIZE)
12103 #define SOUND_BUTTON_LOOPS_XPOS (SOUND_BUTTON_XPOS + 1 * GAME_BUTTON_XSIZE)
12104 #define SOUND_BUTTON_SIMPLE_XPOS (SOUND_BUTTON_XPOS + 2 * GAME_BUTTON_XSIZE)
12111 } gamebutton_info[NUM_GAME_BUTTONS] =
12114 GAME_BUTTON_STOP_XPOS, GAME_BUTTON_YPOS,
12119 GAME_BUTTON_PAUSE_XPOS, GAME_BUTTON_YPOS,
12120 GAME_CTRL_ID_PAUSE,
12124 GAME_BUTTON_PLAY_XPOS, GAME_BUTTON_YPOS,
12129 SOUND_BUTTON_MUSIC_XPOS, SOUND_BUTTON_YPOS,
12130 SOUND_CTRL_ID_MUSIC,
12131 "background music on/off"
12134 SOUND_BUTTON_LOOPS_XPOS, SOUND_BUTTON_YPOS,
12135 SOUND_CTRL_ID_LOOPS,
12136 "sound loops on/off"
12139 SOUND_BUTTON_SIMPLE_XPOS, SOUND_BUTTON_YPOS,
12140 SOUND_CTRL_ID_SIMPLE,
12141 "normal sounds on/off"
12145 void CreateGameButtons()
12149 for (i = 0; i < NUM_GAME_BUTTONS; i++)
12151 Bitmap *gd_bitmap = graphic_info[IMG_GLOBAL_DOOR].bitmap;
12152 struct GadgetInfo *gi;
12155 unsigned long event_mask;
12156 int gd_xoffset, gd_yoffset;
12157 int gd_x1, gd_x2, gd_y1, gd_y2;
12160 gd_xoffset = gamebutton_info[i].x;
12161 gd_yoffset = gamebutton_info[i].y;
12162 gd_x1 = DOOR_GFX_PAGEX4 + gd_xoffset;
12163 gd_x2 = DOOR_GFX_PAGEX3 + gd_xoffset;
12165 if (id == GAME_CTRL_ID_STOP ||
12166 id == GAME_CTRL_ID_PAUSE ||
12167 id == GAME_CTRL_ID_PLAY)
12169 button_type = GD_TYPE_NORMAL_BUTTON;
12171 event_mask = GD_EVENT_RELEASED;
12172 gd_y1 = DOOR_GFX_PAGEY1 + gd_yoffset - GAME_BUTTON_YSIZE;
12173 gd_y2 = DOOR_GFX_PAGEY1 + gd_yoffset - GAME_BUTTON_YSIZE;
12177 button_type = GD_TYPE_CHECK_BUTTON;
12179 ((id == SOUND_CTRL_ID_MUSIC && setup.sound_music) ||
12180 (id == SOUND_CTRL_ID_LOOPS && setup.sound_loops) ||
12181 (id == SOUND_CTRL_ID_SIMPLE && setup.sound_simple) ? TRUE : FALSE);
12182 event_mask = GD_EVENT_PRESSED;
12183 gd_y1 = DOOR_GFX_PAGEY1 + gd_yoffset;
12184 gd_y2 = DOOR_GFX_PAGEY1 + gd_yoffset - GAME_BUTTON_YSIZE;
12187 gi = CreateGadget(GDI_CUSTOM_ID, id,
12188 GDI_INFO_TEXT, gamebutton_info[i].infotext,
12189 GDI_X, DX + gd_xoffset,
12190 GDI_Y, DY + gd_yoffset,
12191 GDI_WIDTH, GAME_BUTTON_XSIZE,
12192 GDI_HEIGHT, GAME_BUTTON_YSIZE,
12193 GDI_TYPE, button_type,
12194 GDI_STATE, GD_BUTTON_UNPRESSED,
12195 GDI_CHECKED, checked,
12196 GDI_DESIGN_UNPRESSED, gd_bitmap, gd_x1, gd_y1,
12197 GDI_DESIGN_PRESSED, gd_bitmap, gd_x2, gd_y1,
12198 GDI_ALT_DESIGN_UNPRESSED, gd_bitmap, gd_x1, gd_y2,
12199 GDI_ALT_DESIGN_PRESSED, gd_bitmap, gd_x2, gd_y2,
12200 GDI_EVENT_MASK, event_mask,
12201 GDI_CALLBACK_ACTION, HandleGameButtons,
12205 Error(ERR_EXIT, "cannot create gadget");
12207 game_gadget[id] = gi;
12211 void FreeGameButtons()
12215 for (i = 0; i < NUM_GAME_BUTTONS; i++)
12216 FreeGadget(game_gadget[i]);
12219 static void MapGameButtons()
12223 for (i = 0; i < NUM_GAME_BUTTONS; i++)
12224 MapGadget(game_gadget[i]);
12227 void UnmapGameButtons()
12231 for (i = 0; i < NUM_GAME_BUTTONS; i++)
12232 UnmapGadget(game_gadget[i]);
12235 static void HandleGameButtons(struct GadgetInfo *gi)
12237 int id = gi->custom_id;
12239 if (game_status != GAME_MODE_PLAYING)
12244 case GAME_CTRL_ID_STOP:
12245 RequestQuitGame(TRUE);
12248 case GAME_CTRL_ID_PAUSE:
12249 if (options.network)
12251 #if defined(NETWORK_AVALIABLE)
12253 SendToServer_ContinuePlaying();
12255 SendToServer_PausePlaying();
12259 TapeTogglePause(TAPE_TOGGLE_MANUAL);
12262 case GAME_CTRL_ID_PLAY:
12265 #if defined(NETWORK_AVALIABLE)
12266 if (options.network)
12267 SendToServer_ContinuePlaying();
12271 tape.pausing = FALSE;
12272 DrawVideoDisplay(VIDEO_STATE_PAUSE_OFF,0);
12277 case SOUND_CTRL_ID_MUSIC:
12278 if (setup.sound_music)
12280 setup.sound_music = FALSE;
12283 else if (audio.music_available)
12285 setup.sound = setup.sound_music = TRUE;
12287 SetAudioMode(setup.sound);
12293 case SOUND_CTRL_ID_LOOPS:
12294 if (setup.sound_loops)
12295 setup.sound_loops = FALSE;
12296 else if (audio.loops_available)
12298 setup.sound = setup.sound_loops = TRUE;
12299 SetAudioMode(setup.sound);
12303 case SOUND_CTRL_ID_SIMPLE:
12304 if (setup.sound_simple)
12305 setup.sound_simple = FALSE;
12306 else if (audio.sound_available)
12308 setup.sound = setup.sound_simple = TRUE;
12309 SetAudioMode(setup.sound);