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;
836 if (!level.use_artwork_element[0])
837 stored_player[0].artwork_element = EL_SP_MURPHY;
840 Feld[x][y] = EL_PLAYER_1;
846 struct PlayerInfo *player = &stored_player[Feld[x][y] - EL_PLAYER_1];
847 int jx = player->jx, jy = player->jy;
849 player->present = TRUE;
851 player->block_last_field = (element == EL_SP_MURPHY ?
852 level.sp_block_last_field :
853 level.block_last_field);
855 /* ---------- initialize player's last field block delay --------------- */
857 /* always start with reliable default value (no adjustment needed) */
858 player->block_delay_adjustment = 0;
860 /* special case 1: in Supaplex, Murphy blocks last field one more frame */
861 if (player->block_last_field && element == EL_SP_MURPHY)
862 player->block_delay_adjustment = 1;
864 /* special case 2: in game engines before 3.1.1, blocking was different */
865 if (game.use_block_last_field_bug)
866 player->block_delay_adjustment = (player->block_last_field ? -1 : 1);
868 if (!options.network || player->connected)
870 player->active = TRUE;
872 /* remove potentially duplicate players */
873 if (StorePlayer[jx][jy] == Feld[x][y])
874 StorePlayer[jx][jy] = 0;
876 StorePlayer[x][y] = Feld[x][y];
880 printf("Player %d activated.\n", player->element_nr);
881 printf("[Local player is %d and currently %s.]\n",
882 local_player->element_nr,
883 local_player->active ? "active" : "not active");
887 Feld[x][y] = EL_EMPTY;
889 player->jx = player->last_jx = x;
890 player->jy = player->last_jy = y;
894 static void InitField(int x, int y, boolean init_game)
896 int element = Feld[x][y];
905 InitPlayerField(x, y, element, init_game);
908 case EL_SOKOBAN_FIELD_PLAYER:
909 element = Feld[x][y] = EL_PLAYER_1;
910 InitField(x, y, init_game);
912 element = Feld[x][y] = EL_SOKOBAN_FIELD_EMPTY;
913 InitField(x, y, init_game);
916 case EL_SOKOBAN_FIELD_EMPTY:
917 local_player->sokobanfields_still_needed++;
921 if (x < lev_fieldx-1 && Feld[x+1][y] == EL_ACID)
922 Feld[x][y] = EL_ACID_POOL_TOPLEFT;
923 else if (x > 0 && Feld[x-1][y] == EL_ACID)
924 Feld[x][y] = EL_ACID_POOL_TOPRIGHT;
925 else if (y > 0 && Feld[x][y-1] == EL_ACID_POOL_TOPLEFT)
926 Feld[x][y] = EL_ACID_POOL_BOTTOMLEFT;
927 else if (y > 0 && Feld[x][y-1] == EL_ACID)
928 Feld[x][y] = EL_ACID_POOL_BOTTOM;
929 else if (y > 0 && Feld[x][y-1] == EL_ACID_POOL_TOPRIGHT)
930 Feld[x][y] = EL_ACID_POOL_BOTTOMRIGHT;
938 case EL_SPACESHIP_RIGHT:
939 case EL_SPACESHIP_UP:
940 case EL_SPACESHIP_LEFT:
941 case EL_SPACESHIP_DOWN:
943 case EL_BD_BUTTERFLY_RIGHT:
944 case EL_BD_BUTTERFLY_UP:
945 case EL_BD_BUTTERFLY_LEFT:
946 case EL_BD_BUTTERFLY_DOWN:
947 case EL_BD_BUTTERFLY:
948 case EL_BD_FIREFLY_RIGHT:
949 case EL_BD_FIREFLY_UP:
950 case EL_BD_FIREFLY_LEFT:
951 case EL_BD_FIREFLY_DOWN:
953 case EL_PACMAN_RIGHT:
977 if (y == lev_fieldy - 1)
979 Feld[x][y] = EL_AMOEBA_GROWING;
980 Store[x][y] = EL_AMOEBA_WET;
984 case EL_DYNAMITE_ACTIVE:
985 case EL_SP_DISK_RED_ACTIVE:
986 case EL_DYNABOMB_PLAYER_1_ACTIVE:
987 case EL_DYNABOMB_PLAYER_2_ACTIVE:
988 case EL_DYNABOMB_PLAYER_3_ACTIVE:
989 case EL_DYNABOMB_PLAYER_4_ACTIVE:
993 case EL_EM_DYNAMITE_ACTIVE:
998 local_player->lights_still_needed++;
1002 local_player->friends_still_needed++;
1007 GfxDir[x][y] = MovDir[x][y] = 1 << RND(4);
1010 case EL_CONVEYOR_BELT_1_SWITCH_LEFT:
1011 case EL_CONVEYOR_BELT_1_SWITCH_MIDDLE:
1012 case EL_CONVEYOR_BELT_1_SWITCH_RIGHT:
1013 case EL_CONVEYOR_BELT_2_SWITCH_LEFT:
1014 case EL_CONVEYOR_BELT_2_SWITCH_MIDDLE:
1015 case EL_CONVEYOR_BELT_2_SWITCH_RIGHT:
1016 case EL_CONVEYOR_BELT_3_SWITCH_LEFT:
1017 case EL_CONVEYOR_BELT_3_SWITCH_MIDDLE:
1018 case EL_CONVEYOR_BELT_3_SWITCH_RIGHT:
1019 case EL_CONVEYOR_BELT_4_SWITCH_LEFT:
1020 case EL_CONVEYOR_BELT_4_SWITCH_MIDDLE:
1021 case EL_CONVEYOR_BELT_4_SWITCH_RIGHT:
1024 int belt_nr = getBeltNrFromBeltSwitchElement(Feld[x][y]);
1025 int belt_dir = getBeltDirFromBeltSwitchElement(Feld[x][y]);
1026 int belt_dir_nr = getBeltDirNrFromBeltSwitchElement(Feld[x][y]);
1028 if (game.belt_dir_nr[belt_nr] == 3) /* initial value */
1030 game.belt_dir[belt_nr] = belt_dir;
1031 game.belt_dir_nr[belt_nr] = belt_dir_nr;
1033 else /* more than one switch -- set it like the first switch */
1035 Feld[x][y] = Feld[x][y] - belt_dir_nr + game.belt_dir_nr[belt_nr];
1040 case EL_SWITCHGATE_SWITCH_DOWN: /* always start with same switch pos */
1042 Feld[x][y] = EL_SWITCHGATE_SWITCH_UP;
1045 case EL_LIGHT_SWITCH_ACTIVE:
1047 game.light_time_left = level.time_light * FRAMES_PER_SECOND;
1050 case EL_EMC_MAGIC_BALL:
1051 if (game.ball_state)
1052 Feld[x][y] = EL_EMC_MAGIC_BALL_ACTIVE;
1055 case EL_EMC_MAGIC_BALL_SWITCH:
1056 if (game.ball_state)
1057 Feld[x][y] = EL_EMC_MAGIC_BALL_SWITCH_ACTIVE;
1062 if (IS_CUSTOM_ELEMENT(element))
1064 if (CAN_MOVE(element))
1067 #if USE_NEW_CUSTOM_VALUE
1068 if (!element_info[element].use_last_ce_value || init_game)
1069 CustomValue[x][y] = GET_NEW_CUSTOM_VALUE(Feld[x][y]);
1073 if (IS_CUSTOM_ELEMENT(element) && CAN_MOVE(element))
1076 else if (IS_GROUP_ELEMENT(element))
1078 struct ElementGroupInfo *group = element_info[element].group;
1079 int last_anim_random_frame = gfx.anim_random_frame;
1082 if (group->choice_mode == ANIM_RANDOM)
1083 gfx.anim_random_frame = RND(group->num_elements_resolved);
1085 element_pos = getAnimationFrame(group->num_elements_resolved, 1,
1086 group->choice_mode, 0,
1089 if (group->choice_mode == ANIM_RANDOM)
1090 gfx.anim_random_frame = last_anim_random_frame;
1092 group->choice_pos++;
1094 Feld[x][y] = group->element_resolved[element_pos];
1096 InitField(x, y, init_game);
1103 CheckTriggeredElementChange(x, y, element, CE_CREATION_OF_X);
1108 #if USE_NEW_CUSTOM_VALUE
1111 CustomValue[x][y] = GET_NEW_CUSTOM_VALUE(Feld[x][y]);
1113 CustomValue[x][y] = element_info[Feld[x][y]].custom_value_initial;
1121 static inline void InitField_WithBug1(int x, int y, boolean init_game)
1123 InitField(x, y, init_game);
1125 /* not needed to call InitMovDir() -- already done by InitField()! */
1126 if (game.engine_version < VERSION_IDENT(3,1,0,0) &&
1127 CAN_MOVE(Feld[x][y]))
1131 static inline void InitField_WithBug2(int x, int y, boolean init_game)
1133 int old_element = Feld[x][y];
1135 InitField(x, y, init_game);
1137 /* not needed to call InitMovDir() -- already done by InitField()! */
1138 if (game.engine_version < VERSION_IDENT(3,1,0,0) &&
1139 CAN_MOVE(old_element) &&
1140 (old_element < EL_MOLE_LEFT || old_element > EL_MOLE_DOWN))
1143 /* this case is in fact a combination of not less than three bugs:
1144 first, it calls InitMovDir() for elements that can move, although this is
1145 already done by InitField(); then, it checks the element that was at this
1146 field _before_ the call to InitField() (which can change it); lastly, it
1147 was not called for "mole with direction" elements, which were treated as
1148 "cannot move" due to (fixed) wrong element initialization in "src/init.c"
1152 inline void DrawGameValue_Emeralds(int value)
1154 DrawText(DX_EMERALDS, DY_EMERALDS, int2str(value, 3), FONT_TEXT_2);
1157 inline void DrawGameValue_Dynamite(int value)
1159 DrawText(DX_DYNAMITE, DY_DYNAMITE, int2str(value, 3), FONT_TEXT_2);
1162 inline void DrawGameValue_Keys(int key[MAX_NUM_KEYS])
1166 /* currently only 4 of 8 possible keys are displayed */
1167 for (i = 0; i < STD_NUM_KEYS; i++)
1170 DrawMiniGraphicExt(drawto, DX_KEYS + i * MINI_TILEX, DY_KEYS,
1171 el2edimg(EL_KEY_1 + i));
1173 BlitBitmap(graphic_info[IMG_GLOBAL_DOOR].bitmap, drawto,
1174 DOOR_GFX_PAGEX5 + XX_KEYS + i * MINI_TILEX, YY_KEYS,
1175 MINI_TILEX, MINI_TILEY, DX_KEYS + i * MINI_TILEX, DY_KEYS);
1179 inline void DrawGameValue_Score(int value)
1181 DrawText(DX_SCORE, DY_SCORE, int2str(value, 5), FONT_TEXT_2);
1184 inline void DrawGameValue_Time(int value)
1187 DrawText(DX_TIME1, DY_TIME, int2str(value, 3), FONT_TEXT_2);
1189 DrawText(DX_TIME2, DY_TIME, int2str(value, 4), FONT_LEVEL_NUMBER);
1192 inline void DrawGameValue_Level(int value)
1195 DrawText(DX_LEVEL, DY_LEVEL, int2str(value, 2), FONT_TEXT_2);
1198 /* misuse area for displaying emeralds to draw bigger level number */
1199 DrawTextExt(drawto, DX_EMERALDS, DY_EMERALDS,
1200 int2str(value, 3), FONT_LEVEL_NUMBER, BLIT_OPAQUE);
1202 /* now copy it to the area for displaying level number */
1203 BlitBitmap(drawto, drawto,
1204 DX_EMERALDS, DY_EMERALDS + 1,
1205 getFontWidth(FONT_LEVEL_NUMBER) * 3,
1206 getFontHeight(FONT_LEVEL_NUMBER) - 1,
1207 DX_LEVEL - 1, DY_LEVEL + 1);
1209 /* restore the area for displaying emeralds */
1210 DrawGameValue_Emeralds(local_player->gems_still_needed);
1212 /* yes, this is all really ugly :-) */
1216 void DrawAllGameValues(int emeralds, int dynamite, int score, int time,
1219 int key[MAX_NUM_KEYS];
1222 for (i = 0; i < MAX_NUM_KEYS; i++)
1223 key[i] = key_bits & (1 << i);
1225 DrawGameValue_Level(level_nr);
1227 DrawGameValue_Emeralds(emeralds);
1228 DrawGameValue_Dynamite(dynamite);
1229 DrawGameValue_Score(score);
1230 DrawGameValue_Time(time);
1232 DrawGameValue_Keys(key);
1235 void DrawGameDoorValues()
1239 if (level.game_engine_type == GAME_ENGINE_TYPE_EM)
1241 DrawGameDoorValues_EM();
1246 DrawGameValue_Level(level_nr);
1248 DrawGameValue_Emeralds(local_player->gems_still_needed);
1249 DrawGameValue_Dynamite(local_player->inventory_size);
1250 DrawGameValue_Score(local_player->score);
1251 DrawGameValue_Time(TimeLeft);
1253 for (i = 0; i < MAX_PLAYERS; i++)
1254 DrawGameValue_Keys(stored_player[i].key);
1258 static void resolve_group_element(int group_element, int recursion_depth)
1260 static int group_nr;
1261 static struct ElementGroupInfo *group;
1262 struct ElementGroupInfo *actual_group = element_info[group_element].group;
1265 if (recursion_depth > NUM_GROUP_ELEMENTS) /* recursion too deep */
1267 Error(ERR_WARN, "recursion too deep when resolving group element %d",
1268 group_element - EL_GROUP_START + 1);
1270 /* replace element which caused too deep recursion by question mark */
1271 group->element_resolved[group->num_elements_resolved++] = EL_UNKNOWN;
1276 if (recursion_depth == 0) /* initialization */
1278 group = element_info[group_element].group;
1279 group_nr = group_element - EL_GROUP_START;
1281 group->num_elements_resolved = 0;
1282 group->choice_pos = 0;
1285 for (i = 0; i < actual_group->num_elements; i++)
1287 int element = actual_group->element[i];
1289 if (group->num_elements_resolved == NUM_FILE_ELEMENTS)
1292 if (IS_GROUP_ELEMENT(element))
1293 resolve_group_element(element, recursion_depth + 1);
1296 group->element_resolved[group->num_elements_resolved++] = element;
1297 element_info[element].in_group[group_nr] = TRUE;
1304 =============================================================================
1306 -----------------------------------------------------------------------------
1307 initialize game engine due to level / tape version number
1308 =============================================================================
1311 static void InitGameEngine()
1313 int i, j, k, l, x, y;
1315 /* set game engine from tape file when re-playing, else from level file */
1316 game.engine_version = (tape.playing ? tape.engine_version :
1317 level.game_version);
1319 /* ---------------------------------------------------------------------- */
1320 /* set flags for bugs and changes according to active game engine version */
1321 /* ---------------------------------------------------------------------- */
1324 Summary of bugfix/change:
1325 Fixed handling for custom elements that change when pushed by the player.
1327 Fixed/changed in version:
1331 Before 3.1.0, custom elements that "change when pushing" changed directly
1332 after the player started pushing them (until then handled in "DigField()").
1333 Since 3.1.0, these custom elements are not changed until the "pushing"
1334 move of the element is finished (now handled in "ContinueMoving()").
1336 Affected levels/tapes:
1337 The first condition is generally needed for all levels/tapes before version
1338 3.1.0, which might use the old behaviour before it was changed; known tapes
1339 that are affected are some tapes from the level set "Walpurgis Gardens" by
1341 The second condition is an exception from the above case and is needed for
1342 the special case of tapes recorded with game (not engine!) version 3.1.0 or
1343 above (including some development versions of 3.1.0), but before it was
1344 known that this change would break tapes like the above and was fixed in
1345 3.1.1, so that the changed behaviour was active although the engine version
1346 while recording maybe was before 3.1.0. There is at least one tape that is
1347 affected by this exception, which is the tape for the one-level set "Bug
1348 Machine" by Juergen Bonhagen.
1351 game.use_change_when_pushing_bug =
1352 (game.engine_version < VERSION_IDENT(3,1,0,0) &&
1354 tape.game_version >= VERSION_IDENT(3,1,0,0) &&
1355 tape.game_version < VERSION_IDENT(3,1,1,0)));
1358 Summary of bugfix/change:
1359 Fixed handling for blocking the field the player leaves when moving.
1361 Fixed/changed in version:
1365 Before 3.1.1, when "block last field when moving" was enabled, the field
1366 the player is leaving when moving was blocked for the time of the move,
1367 and was directly unblocked afterwards. This resulted in the last field
1368 being blocked for exactly one less than the number of frames of one player
1369 move. Additionally, even when blocking was disabled, the last field was
1370 blocked for exactly one frame.
1371 Since 3.1.1, due to changes in player movement handling, the last field
1372 is not blocked at all when blocking is disabled. When blocking is enabled,
1373 the last field is blocked for exactly the number of frames of one player
1374 move. Additionally, if the player is Murphy, the hero of Supaplex, the
1375 last field is blocked for exactly one more than the number of frames of
1378 Affected levels/tapes:
1379 (!!! yet to be determined -- probably many !!!)
1382 game.use_block_last_field_bug =
1383 (game.engine_version < VERSION_IDENT(3,1,1,0));
1386 Summary of bugfix/change:
1387 Changed behaviour of CE changes with multiple changes per single frame.
1389 Fixed/changed in version:
1393 Before 3.2.0-6, only one single CE change was allowed in each engine frame.
1394 This resulted in race conditions where CEs seem to behave strange in some
1395 situations (where triggered CE changes were just skipped because there was
1396 already a CE change on that tile in the playfield in that engine frame).
1397 Since 3.2.0-6, this was changed to allow up to MAX_NUM_CHANGES_PER_FRAME.
1398 (The number of changes per frame must be limited in any case, because else
1399 it is easily possible to define CE changes that would result in an infinite
1400 loop, causing the whole game to freeze. The MAX_NUM_CHANGES_PER_FRAME value
1401 should be set large enough so that it would only be reached in cases where
1402 the corresponding CE change conditions run into a loop. Therefore, it seems
1403 to be reasonable to set MAX_NUM_CHANGES_PER_FRAME to the same value as the
1404 maximal number of change pages for custom elements.)
1406 Affected levels/tapes:
1410 #if USE_ONLY_ONE_CHANGE_PER_FRAME
1411 game.max_num_changes_per_frame = 1;
1413 game.max_num_changes_per_frame =
1414 (game.engine_version < VERSION_IDENT(3,2,0,6) ? 1 : 32);
1417 /* ---------------------------------------------------------------------- */
1419 /* default scan direction: scan playfield from top/left to bottom/right */
1420 InitPlayfieldScanMode(CA_ARG_SCAN_MODE_NORMAL);
1422 /* dynamically adjust element properties according to game engine version */
1423 InitElementPropertiesEngine(game.engine_version);
1426 printf("level %d: level version == %06d\n", level_nr, level.game_version);
1427 printf(" tape version == %06d [%s] [file: %06d]\n",
1428 tape.engine_version, (tape.playing ? "PLAYING" : "RECORDING"),
1430 printf(" => game.engine_version == %06d\n", game.engine_version);
1434 /* ---------- recursively resolve group elements ------------------------- */
1436 for (i = 0; i < MAX_NUM_ELEMENTS; i++)
1437 for (j = 0; j < NUM_GROUP_ELEMENTS; j++)
1438 element_info[i].in_group[j] = FALSE;
1440 for (i = 0; i < NUM_GROUP_ELEMENTS; i++)
1441 resolve_group_element(EL_GROUP_START + i, 0);
1444 /* ---------- initialize player's initial move delay --------------------- */
1447 /* dynamically adjust player properties according to level information */
1448 game.initial_move_delay_value =
1449 get_move_delay_from_stepsize(level.initial_player_stepsize);
1451 /* dynamically adjust player properties according to level information */
1452 game.initial_move_delay_value =
1453 (level.double_speed ? MOVE_DELAY_HIGH_SPEED : MOVE_DELAY_NORMAL_SPEED);
1456 /* dynamically adjust player properties according to game engine version */
1457 game.initial_move_delay = (game.engine_version <= VERSION_IDENT(2,0,1,0) ?
1458 game.initial_move_delay_value : 0);
1460 /* ---------- initialize player's initial push delay --------------------- */
1462 /* dynamically adjust player properties according to game engine version */
1463 game.initial_push_delay_value =
1464 (game.engine_version < VERSION_IDENT(3,0,7,1) ? 5 : -1);
1466 /* ---------- initialize changing elements ------------------------------- */
1468 /* initialize changing elements information */
1469 for (i = 0; i < MAX_NUM_ELEMENTS; i++)
1471 struct ElementInfo *ei = &element_info[i];
1473 /* this pointer might have been changed in the level editor */
1474 ei->change = &ei->change_page[0];
1476 if (!IS_CUSTOM_ELEMENT(i))
1478 ei->change->target_element = EL_EMPTY_SPACE;
1479 ei->change->delay_fixed = 0;
1480 ei->change->delay_random = 0;
1481 ei->change->delay_frames = 1;
1484 for (j = 0; j < NUM_CHANGE_EVENTS; j++)
1486 ei->has_change_event[j] = FALSE;
1488 ei->event_page_nr[j] = 0;
1489 ei->event_page[j] = &ei->change_page[0];
1493 /* add changing elements from pre-defined list */
1494 for (i = 0; change_delay_list[i].element != EL_UNDEFINED; i++)
1496 struct ChangingElementInfo *ch_delay = &change_delay_list[i];
1497 struct ElementInfo *ei = &element_info[ch_delay->element];
1499 ei->change->target_element = ch_delay->target_element;
1500 ei->change->delay_fixed = ch_delay->change_delay;
1502 ei->change->pre_change_function = ch_delay->pre_change_function;
1503 ei->change->change_function = ch_delay->change_function;
1504 ei->change->post_change_function = ch_delay->post_change_function;
1506 ei->change->can_change = TRUE;
1507 ei->change->can_change_or_has_action = TRUE;
1509 ei->has_change_event[CE_DELAY] = TRUE;
1511 SET_PROPERTY(ch_delay->element, EP_CAN_CHANGE, TRUE);
1512 SET_PROPERTY(ch_delay->element, EP_CAN_CHANGE_OR_HAS_ACTION, TRUE);
1515 /* ---------- initialize internal run-time variables ------------- */
1517 for (i = 0; i < NUM_CUSTOM_ELEMENTS; i++)
1519 struct ElementInfo *ei = &element_info[EL_CUSTOM_START + i];
1521 for (j = 0; j < ei->num_change_pages; j++)
1523 ei->change_page[j].can_change_or_has_action =
1524 (ei->change_page[j].can_change |
1525 ei->change_page[j].has_action);
1529 /* add change events from custom element configuration */
1530 for (i = 0; i < NUM_CUSTOM_ELEMENTS; i++)
1532 struct ElementInfo *ei = &element_info[EL_CUSTOM_START + i];
1534 for (j = 0; j < ei->num_change_pages; j++)
1536 if (!ei->change_page[j].can_change_or_has_action)
1539 for (k = 0; k < NUM_CHANGE_EVENTS; k++)
1541 /* only add event page for the first page found with this event */
1542 if (ei->change_page[j].has_event[k] && !(ei->has_change_event[k]))
1544 ei->has_change_event[k] = TRUE;
1546 ei->event_page_nr[k] = j;
1547 ei->event_page[k] = &ei->change_page[j];
1553 /* ---------- initialize run-time trigger player and element ------------- */
1555 for (i = 0; i < NUM_CUSTOM_ELEMENTS; i++)
1557 struct ElementInfo *ei = &element_info[EL_CUSTOM_START + i];
1559 for (j = 0; j < ei->num_change_pages; j++)
1561 ei->change_page[j].actual_trigger_element = EL_EMPTY;
1562 ei->change_page[j].actual_trigger_player = EL_PLAYER_1;
1563 ei->change_page[j].actual_trigger_side = CH_SIDE_NONE;
1564 ei->change_page[j].actual_trigger_ce_value = 0;
1568 /* ---------- initialize trigger events ---------------------------------- */
1570 /* initialize trigger events information */
1571 for (i = 0; i < MAX_NUM_ELEMENTS; i++)
1572 for (j = 0; j < NUM_CHANGE_EVENTS; j++)
1573 trigger_events[i][j] = FALSE;
1575 /* add trigger events from element change event properties */
1576 for (i = 0; i < MAX_NUM_ELEMENTS; i++)
1578 struct ElementInfo *ei = &element_info[i];
1580 for (j = 0; j < ei->num_change_pages; j++)
1582 if (!ei->change_page[j].can_change_or_has_action)
1585 if (ei->change_page[j].has_event[CE_BY_OTHER_ACTION])
1587 int trigger_element = ei->change_page[j].trigger_element;
1589 for (k = 0; k < NUM_CHANGE_EVENTS; k++)
1591 if (ei->change_page[j].has_event[k])
1593 if (IS_GROUP_ELEMENT(trigger_element))
1595 struct ElementGroupInfo *group =
1596 element_info[trigger_element].group;
1598 for (l = 0; l < group->num_elements_resolved; l++)
1599 trigger_events[group->element_resolved[l]][k] = TRUE;
1602 trigger_events[trigger_element][k] = TRUE;
1609 /* ---------- initialize push delay -------------------------------------- */
1611 /* initialize push delay values to default */
1612 for (i = 0; i < MAX_NUM_ELEMENTS; i++)
1614 if (!IS_CUSTOM_ELEMENT(i))
1616 element_info[i].push_delay_fixed = game.default_push_delay_fixed;
1617 element_info[i].push_delay_random = game.default_push_delay_random;
1621 /* set push delay value for certain elements from pre-defined list */
1622 for (i = 0; push_delay_list[i].element != EL_UNDEFINED; i++)
1624 int e = push_delay_list[i].element;
1626 element_info[e].push_delay_fixed = push_delay_list[i].push_delay_fixed;
1627 element_info[e].push_delay_random = push_delay_list[i].push_delay_random;
1630 /* set push delay value for Supaplex elements for newer engine versions */
1631 if (game.engine_version >= VERSION_IDENT(3,1,0,0))
1633 for (i = 0; i < MAX_NUM_ELEMENTS; i++)
1635 if (IS_SP_ELEMENT(i))
1637 /* set SP push delay to just enough to push under a falling zonk */
1638 int delay = (game.engine_version >= VERSION_IDENT(3,1,1,0) ? 8 : 6);
1640 element_info[i].push_delay_fixed = delay;
1641 element_info[i].push_delay_random = 0;
1646 /* ---------- initialize move stepsize ----------------------------------- */
1648 /* initialize move stepsize values to default */
1649 for (i = 0; i < MAX_NUM_ELEMENTS; i++)
1650 if (!IS_CUSTOM_ELEMENT(i))
1651 element_info[i].move_stepsize = MOVE_STEPSIZE_NORMAL;
1653 /* set move stepsize value for certain elements from pre-defined list */
1654 for (i = 0; move_stepsize_list[i].element != EL_UNDEFINED; i++)
1656 int e = move_stepsize_list[i].element;
1658 element_info[e].move_stepsize = move_stepsize_list[i].move_stepsize;
1661 /* ---------- initialize collect score ----------------------------------- */
1663 /* initialize collect score values for custom elements from initial value */
1664 for (i = 0; i < MAX_NUM_ELEMENTS; i++)
1665 if (IS_CUSTOM_ELEMENT(i))
1666 element_info[i].collect_score = element_info[i].collect_score_initial;
1668 /* ---------- initialize collect count ----------------------------------- */
1670 /* initialize collect count values for non-custom elements */
1671 for (i = 0; i < MAX_NUM_ELEMENTS; i++)
1672 if (!IS_CUSTOM_ELEMENT(i))
1673 element_info[i].collect_count_initial = 0;
1675 /* add collect count values for all elements from pre-defined list */
1676 for (i = 0; collect_count_list[i].element != EL_UNDEFINED; i++)
1677 element_info[collect_count_list[i].element].collect_count_initial =
1678 collect_count_list[i].count;
1680 /* ---------- initialize access direction -------------------------------- */
1682 /* initialize access direction values to default (access from every side) */
1683 for (i = 0; i < MAX_NUM_ELEMENTS; i++)
1684 if (!IS_CUSTOM_ELEMENT(i))
1685 element_info[i].access_direction = MV_ALL_DIRECTIONS;
1687 /* set access direction value for certain elements from pre-defined list */
1688 for (i = 0; access_direction_list[i].element != EL_UNDEFINED; i++)
1689 element_info[access_direction_list[i].element].access_direction =
1690 access_direction_list[i].direction;
1692 /* ---------- initialize explosion content ------------------------------- */
1693 for (i = 0; i < MAX_NUM_ELEMENTS; i++)
1695 if (IS_CUSTOM_ELEMENT(i))
1698 for (y = 0; y < 3; y++) for (x = 0; x < 3; x++)
1700 /* (content for EL_YAMYAM set at run-time with game.yamyam_content_nr) */
1702 element_info[i].content.e[x][y] =
1703 (i == EL_PLAYER_1 ? EL_EMERALD_YELLOW :
1704 i == EL_PLAYER_2 ? EL_EMERALD_RED :
1705 i == EL_PLAYER_3 ? EL_EMERALD :
1706 i == EL_PLAYER_4 ? EL_EMERALD_PURPLE :
1707 i == EL_MOLE ? EL_EMERALD_RED :
1708 i == EL_PENGUIN ? EL_EMERALD_PURPLE :
1709 i == EL_BUG ? (x == 1 && y == 1 ? EL_DIAMOND : EL_EMERALD) :
1710 i == EL_BD_BUTTERFLY ? EL_BD_DIAMOND :
1711 i == EL_SP_ELECTRON ? EL_SP_INFOTRON :
1712 i == EL_AMOEBA_TO_DIAMOND ? level.amoeba_content :
1713 i == EL_WALL_EMERALD ? EL_EMERALD :
1714 i == EL_WALL_DIAMOND ? EL_DIAMOND :
1715 i == EL_WALL_BD_DIAMOND ? EL_BD_DIAMOND :
1716 i == EL_WALL_EMERALD_YELLOW ? EL_EMERALD_YELLOW :
1717 i == EL_WALL_EMERALD_RED ? EL_EMERALD_RED :
1718 i == EL_WALL_EMERALD_PURPLE ? EL_EMERALD_PURPLE :
1719 i == EL_WALL_PEARL ? EL_PEARL :
1720 i == EL_WALL_CRYSTAL ? EL_CRYSTAL :
1726 int get_num_special_action(int element, int action_first, int action_last)
1728 int num_special_action = 0;
1731 for (i = action_first; i <= action_last; i++)
1733 boolean found = FALSE;
1735 for (j = 0; j < NUM_DIRECTIONS; j++)
1736 if (el_act_dir2img(element, i, j) !=
1737 el_act_dir2img(element, ACTION_DEFAULT, j))
1741 num_special_action++;
1746 return num_special_action;
1750 =============================================================================
1752 -----------------------------------------------------------------------------
1753 initialize and start new game
1754 =============================================================================
1759 boolean emulate_bd = TRUE; /* unless non-BOULDERDASH elements found */
1760 boolean emulate_sb = TRUE; /* unless non-SOKOBAN elements found */
1761 boolean emulate_sp = TRUE; /* unless non-SUPAPLEX elements found */
1766 /* don't play tapes over network */
1767 network_playing = (options.network && !tape.playing);
1769 for (i = 0; i < MAX_PLAYERS; i++)
1771 struct PlayerInfo *player = &stored_player[i];
1773 player->index_nr = i;
1774 player->index_bit = (1 << i);
1775 player->element_nr = EL_PLAYER_1 + i;
1777 player->present = FALSE;
1778 player->active = FALSE;
1781 player->effective_action = 0;
1782 player->programmed_action = 0;
1785 player->gems_still_needed = level.gems_needed;
1786 player->sokobanfields_still_needed = 0;
1787 player->lights_still_needed = 0;
1788 player->friends_still_needed = 0;
1790 for (j = 0; j < MAX_NUM_KEYS; j++)
1791 player->key[j] = FALSE;
1793 player->dynabomb_count = 0;
1794 player->dynabomb_size = 1;
1795 player->dynabombs_left = 0;
1796 player->dynabomb_xl = FALSE;
1798 player->MovDir = MV_NONE;
1801 player->GfxDir = MV_NONE;
1802 player->GfxAction = ACTION_DEFAULT;
1804 player->StepFrame = 0;
1806 player->use_murphy = FALSE;
1807 player->artwork_element =
1808 (level.use_artwork_element[i] ? level.artwork_element[i] :
1809 player->element_nr);
1811 player->block_last_field = FALSE; /* initialized in InitPlayerField() */
1812 player->block_delay_adjustment = 0; /* initialized in InitPlayerField() */
1814 player->can_fall_into_acid = CAN_MOVE_INTO_ACID(player->element_nr);
1816 player->actual_frame_counter = 0;
1818 player->step_counter = 0;
1820 player->last_move_dir = MV_NONE;
1822 player->is_waiting = FALSE;
1823 player->is_moving = FALSE;
1824 player->is_auto_moving = FALSE;
1825 player->is_digging = FALSE;
1826 player->is_snapping = FALSE;
1827 player->is_collecting = FALSE;
1828 player->is_pushing = FALSE;
1829 player->is_switching = FALSE;
1830 player->is_dropping = FALSE;
1832 player->is_bored = FALSE;
1833 player->is_sleeping = FALSE;
1835 player->frame_counter_bored = -1;
1836 player->frame_counter_sleeping = -1;
1838 player->anim_delay_counter = 0;
1839 player->post_delay_counter = 0;
1841 player->action_waiting = ACTION_DEFAULT;
1842 player->last_action_waiting = ACTION_DEFAULT;
1843 player->special_action_bored = ACTION_DEFAULT;
1844 player->special_action_sleeping = ACTION_DEFAULT;
1846 /* set number of special actions for bored and sleeping animation */
1847 player->num_special_action_bored =
1848 get_num_special_action(player->artwork_element,
1849 ACTION_BORING_1, ACTION_BORING_LAST);
1850 player->num_special_action_sleeping =
1851 get_num_special_action(player->artwork_element,
1852 ACTION_SLEEPING_1, ACTION_SLEEPING_LAST);
1854 player->switch_x = -1;
1855 player->switch_y = -1;
1857 player->drop_x = -1;
1858 player->drop_y = -1;
1860 player->show_envelope = 0;
1863 SetPlayerMoveSpeed(player, level.initial_player_stepsize, TRUE);
1865 player->move_delay = game.initial_move_delay;
1866 player->move_delay_value = game.initial_move_delay_value;
1868 player->move_delay_value_next = -1;
1870 player->move_delay_reset_counter = 0;
1872 player->cannot_move = FALSE;
1875 player->push_delay = -1; /* initialized when pushing starts */
1876 player->push_delay_value = game.initial_push_delay_value;
1878 player->drop_delay = 0;
1880 player->last_jx = player->last_jy = 0;
1881 player->jx = player->jy = 0;
1883 player->shield_normal_time_left = 0;
1884 player->shield_deadly_time_left = 0;
1886 player->inventory_infinite_element = EL_UNDEFINED;
1887 player->inventory_size = 0;
1889 DigField(player, 0, 0, 0, 0, 0, 0, DF_NO_PUSH);
1890 SnapField(player, 0, 0);
1892 player->LevelSolved = FALSE;
1893 player->GameOver = FALSE;
1896 network_player_action_received = FALSE;
1898 #if defined(NETWORK_AVALIABLE)
1899 /* initial null action */
1900 if (network_playing)
1901 SendToServer_MovePlayer(MV_NONE);
1910 TimeLeft = level.time;
1913 ScreenMovDir = MV_NONE;
1917 ScrollStepSize = 0; /* will be correctly initialized by ScrollScreen() */
1919 AllPlayersGone = FALSE;
1921 game.yamyam_content_nr = 0;
1922 game.magic_wall_active = FALSE;
1923 game.magic_wall_time_left = 0;
1924 game.light_time_left = 0;
1925 game.timegate_time_left = 0;
1926 game.switchgate_pos = 0;
1927 game.wind_direction = level.wind_direction_initial;
1928 game.gravity = level.initial_gravity;
1929 game.explosions_delayed = TRUE;
1931 game.lenses_time_left = 0;
1932 game.magnify_time_left = 0;
1934 game.ball_state = level.ball_state_initial;
1935 game.ball_content_nr = 0;
1937 game.envelope_active = FALSE;
1939 game.centered_player_nr = game.centered_player_nr_next = -1; /* focus all */
1941 for (i = 0; i < NUM_BELTS; i++)
1943 game.belt_dir[i] = MV_NONE;
1944 game.belt_dir_nr[i] = 3; /* not moving, next moving left */
1947 for (i = 0; i < MAX_NUM_AMOEBA; i++)
1948 AmoebaCnt[i] = AmoebaCnt2[i] = 0;
1951 SCAN_PLAYFIELD(x, y)
1953 for (x = 0; x < lev_fieldx; x++) for (y = 0; y < lev_fieldy; y++)
1956 Feld[x][y] = level.field[x][y];
1957 MovPos[x][y] = MovDir[x][y] = MovDelay[x][y] = 0;
1958 ChangeDelay[x][y] = 0;
1959 ChangePage[x][y] = -1;
1960 #if USE_NEW_CUSTOM_VALUE
1961 CustomValue[x][y] = 0; /* initialized in InitField() */
1963 Store[x][y] = Store2[x][y] = StorePlayer[x][y] = Back[x][y] = 0;
1965 WasJustMoving[x][y] = 0;
1966 WasJustFalling[x][y] = 0;
1967 CheckCollision[x][y] = 0;
1969 Pushed[x][y] = FALSE;
1971 ChangeCount[x][y] = 0;
1972 ChangeEvent[x][y] = -1;
1974 ExplodePhase[x][y] = 0;
1975 ExplodeDelay[x][y] = 0;
1976 ExplodeField[x][y] = EX_TYPE_NONE;
1978 RunnerVisit[x][y] = 0;
1979 PlayerVisit[x][y] = 0;
1982 GfxRandom[x][y] = INIT_GFX_RANDOM();
1983 GfxElement[x][y] = EL_UNDEFINED;
1984 GfxAction[x][y] = ACTION_DEFAULT;
1985 GfxDir[x][y] = MV_NONE;
1989 SCAN_PLAYFIELD(x, y)
1991 for (y = 0; y < lev_fieldy; y++) for (x = 0; x < lev_fieldx; x++)
1994 if (emulate_bd && !IS_BD_ELEMENT(Feld[x][y]))
1996 if (emulate_sb && !IS_SB_ELEMENT(Feld[x][y]))
1998 if (emulate_sp && !IS_SP_ELEMENT(Feld[x][y]))
2001 InitField(x, y, TRUE);
2006 game.emulation = (emulate_bd ? EMU_BOULDERDASH :
2007 emulate_sb ? EMU_SOKOBAN :
2008 emulate_sp ? EMU_SUPAPLEX : EMU_NONE);
2010 #if USE_NEW_ALL_SLIPPERY
2011 /* initialize type of slippery elements */
2012 for (i = 0; i < MAX_NUM_ELEMENTS; i++)
2014 if (!IS_CUSTOM_ELEMENT(i))
2016 /* default: elements slip down either to the left or right randomly */
2017 element_info[i].slippery_type = SLIPPERY_ANY_RANDOM;
2019 /* SP style elements prefer to slip down on the left side */
2020 if (game.engine_version >= VERSION_IDENT(3,1,1,0) && IS_SP_ELEMENT(i))
2021 element_info[i].slippery_type = SLIPPERY_ANY_LEFT_RIGHT;
2023 /* BD style elements prefer to slip down on the left side */
2024 if (game.emulation == EMU_BOULDERDASH)
2025 element_info[i].slippery_type = SLIPPERY_ANY_LEFT_RIGHT;
2030 /* initialize explosion and ignition delay */
2031 for (i = 0; i < MAX_NUM_ELEMENTS; i++)
2033 if (!IS_CUSTOM_ELEMENT(i))
2036 int delay = (((IS_SP_ELEMENT(i) && i != EL_EMPTY_SPACE) &&
2037 game.engine_version >= VERSION_IDENT(3,1,0,0)) ||
2038 game.emulation == EMU_SUPAPLEX ? 3 : 2);
2039 int last_phase = (num_phase + 1) * delay;
2040 int half_phase = (num_phase / 2) * delay;
2042 element_info[i].explosion_delay = last_phase - 1;
2043 element_info[i].ignition_delay = half_phase;
2045 if (i == EL_BLACK_ORB)
2046 element_info[i].ignition_delay = 1;
2050 if (element_info[i].explosion_delay < 1) /* !!! check again !!! */
2051 element_info[i].explosion_delay = 1;
2053 if (element_info[i].ignition_delay < 1) /* !!! check again !!! */
2054 element_info[i].ignition_delay = 1;
2058 /* correct non-moving belts to start moving left */
2059 for (i = 0; i < NUM_BELTS; i++)
2060 if (game.belt_dir[i] == MV_NONE)
2061 game.belt_dir_nr[i] = 3; /* not moving, next moving left */
2063 /* check if any connected player was not found in playfield */
2064 for (i = 0; i < MAX_PLAYERS; i++)
2066 struct PlayerInfo *player = &stored_player[i];
2068 if (player->connected && !player->present)
2070 for (j = 0; j < MAX_PLAYERS; j++)
2072 struct PlayerInfo *some_player = &stored_player[j];
2073 int jx = some_player->jx, jy = some_player->jy;
2075 /* assign first free player found that is present in the playfield */
2076 if (some_player->present && !some_player->connected)
2078 player->present = TRUE;
2079 player->active = TRUE;
2081 some_player->present = FALSE;
2082 some_player->active = FALSE;
2085 player->element_nr = some_player->element_nr;
2088 player->artwork_element = some_player->artwork_element;
2090 player->block_last_field = some_player->block_last_field;
2091 player->block_delay_adjustment = some_player->block_delay_adjustment;
2093 StorePlayer[jx][jy] = player->element_nr;
2094 player->jx = player->last_jx = jx;
2095 player->jy = player->last_jy = jy;
2105 /* when playing a tape, eliminate all players who do not participate */
2107 for (i = 0; i < MAX_PLAYERS; i++)
2109 if (stored_player[i].active && !tape.player_participates[i])
2111 struct PlayerInfo *player = &stored_player[i];
2112 int jx = player->jx, jy = player->jy;
2114 player->active = FALSE;
2115 StorePlayer[jx][jy] = 0;
2116 Feld[jx][jy] = EL_EMPTY;
2120 else if (!options.network && !setup.team_mode) /* && !tape.playing */
2122 /* when in single player mode, eliminate all but the first active player */
2124 for (i = 0; i < MAX_PLAYERS; i++)
2126 if (stored_player[i].active)
2128 for (j = i + 1; j < MAX_PLAYERS; j++)
2130 if (stored_player[j].active)
2132 struct PlayerInfo *player = &stored_player[j];
2133 int jx = player->jx, jy = player->jy;
2135 player->active = FALSE;
2136 player->present = FALSE;
2138 StorePlayer[jx][jy] = 0;
2139 Feld[jx][jy] = EL_EMPTY;
2146 /* when recording the game, store which players take part in the game */
2149 for (i = 0; i < MAX_PLAYERS; i++)
2150 if (stored_player[i].active)
2151 tape.player_participates[i] = TRUE;
2156 for (i = 0; i < MAX_PLAYERS; i++)
2158 struct PlayerInfo *player = &stored_player[i];
2160 printf("Player %d: present == %d, connected == %d, active == %d.\n",
2165 if (local_player == player)
2166 printf("Player %d is local player.\n", i+1);
2170 if (BorderElement == EL_EMPTY)
2173 SBX_Right = lev_fieldx - SCR_FIELDX;
2175 SBY_Lower = lev_fieldy - SCR_FIELDY;
2180 SBX_Right = lev_fieldx - SCR_FIELDX + 1;
2182 SBY_Lower = lev_fieldy - SCR_FIELDY + 1;
2185 if (lev_fieldx + (SBX_Left == -1 ? 2 : 0) <= SCR_FIELDX)
2186 SBX_Left = SBX_Right = -1 * (SCR_FIELDX - lev_fieldx) / 2;
2188 if (lev_fieldy + (SBY_Upper == -1 ? 2 : 0) <= SCR_FIELDY)
2189 SBY_Upper = SBY_Lower = -1 * (SCR_FIELDY - lev_fieldy) / 2;
2191 /* if local player not found, look for custom element that might create
2192 the player (make some assumptions about the right custom element) */
2193 if (!local_player->present)
2195 int start_x = 0, start_y = 0;
2196 int found_rating = 0;
2197 int found_element = EL_UNDEFINED;
2198 int player_nr = local_player->index_nr;
2201 SCAN_PLAYFIELD(x, y)
2203 for (y = 0; y < lev_fieldy; y++) for (x = 0; x < lev_fieldx; x++)
2206 int element = Feld[x][y];
2211 if (level.use_start_element[player_nr] &&
2212 level.start_element[player_nr] == element &&
2219 found_element = element;
2222 if (!IS_CUSTOM_ELEMENT(element))
2225 if (CAN_CHANGE(element))
2227 for (i = 0; i < element_info[element].num_change_pages; i++)
2229 /* check for player created from custom element as single target */
2230 content = element_info[element].change_page[i].target_element;
2231 is_player = ELEM_IS_PLAYER(content);
2233 if (is_player && (found_rating < 3 || element < found_element))
2239 found_element = element;
2244 for (yy = 0; yy < 3; yy++) for (xx = 0; xx < 3; xx++)
2246 /* check for player created from custom element as explosion content */
2247 content = element_info[element].content.e[xx][yy];
2248 is_player = ELEM_IS_PLAYER(content);
2250 if (is_player && (found_rating < 2 || element < found_element))
2252 start_x = x + xx - 1;
2253 start_y = y + yy - 1;
2256 found_element = element;
2259 if (!CAN_CHANGE(element))
2262 for (i = 0; i < element_info[element].num_change_pages; i++)
2264 /* check for player created from custom element as extended target */
2266 element_info[element].change_page[i].target_content.e[xx][yy];
2268 is_player = ELEM_IS_PLAYER(content);
2270 if (is_player && (found_rating < 1 || element < found_element))
2272 start_x = x + xx - 1;
2273 start_y = y + yy - 1;
2276 found_element = element;
2282 scroll_x = (start_x < SBX_Left + MIDPOSX ? SBX_Left :
2283 start_x > SBX_Right + MIDPOSX ? SBX_Right :
2286 scroll_y = (start_y < SBY_Upper + MIDPOSY ? SBY_Upper :
2287 start_y > SBY_Lower + MIDPOSY ? SBY_Lower :
2292 scroll_x = (local_player->jx < SBX_Left + MIDPOSX ? SBX_Left :
2293 local_player->jx > SBX_Right + MIDPOSX ? SBX_Right :
2294 local_player->jx - MIDPOSX);
2296 scroll_y = (local_player->jy < SBY_Upper + MIDPOSY ? SBY_Upper :
2297 local_player->jy > SBY_Lower + MIDPOSY ? SBY_Lower :
2298 local_player->jy - MIDPOSY);
2301 if (!game.restart_level)
2302 CloseDoor(DOOR_CLOSE_1);
2304 /* !!! FIX THIS (START) !!! */
2305 if (level.game_engine_type == GAME_ENGINE_TYPE_EM)
2307 InitGameEngine_EM();
2314 /* after drawing the level, correct some elements */
2315 if (game.timegate_time_left == 0)
2316 CloseAllOpenTimegates();
2318 if (setup.soft_scrolling)
2319 BlitBitmap(fieldbuffer, backbuffer, FX, FY, SXSIZE, SYSIZE, SX, SY);
2321 redraw_mask |= REDRAW_FROM_BACKBUFFER;
2324 /* !!! FIX THIS (END) !!! */
2326 if (!game.restart_level)
2328 /* copy default game door content to main double buffer */
2329 BlitBitmap(graphic_info[IMG_GLOBAL_DOOR].bitmap, drawto,
2330 DOOR_GFX_PAGEX5, DOOR_GFX_PAGEY1, DXSIZE, DYSIZE, DX, DY);
2333 DrawGameDoorValues();
2335 if (!game.restart_level)
2339 game_gadget[SOUND_CTRL_ID_MUSIC]->checked = setup.sound_music;
2340 game_gadget[SOUND_CTRL_ID_LOOPS]->checked = setup.sound_loops;
2341 game_gadget[SOUND_CTRL_ID_SIMPLE]->checked = setup.sound_simple;
2345 /* copy actual game door content to door double buffer for OpenDoor() */
2346 BlitBitmap(drawto, bitmap_db_door,
2347 DX, DY, DXSIZE, DYSIZE, DOOR_GFX_PAGEX1, DOOR_GFX_PAGEY1);
2349 OpenDoor(DOOR_OPEN_ALL);
2351 PlaySoundStereo(SND_GAME_STARTING, SOUND_MIDDLE);
2353 if (setup.sound_music)
2356 KeyboardAutoRepeatOffUnlessAutoplay();
2360 for (i = 0; i < MAX_PLAYERS; i++)
2361 printf("Player %d %sactive.\n",
2362 i + 1, (stored_player[i].active ? "" : "not "));
2366 game.restart_level = FALSE;
2369 void UpdateEngineValues(int actual_scroll_x, int actual_scroll_y)
2371 /* this is used for non-R'n'D game engines to update certain engine values */
2373 /* needed to determine if sounds are played within the visible screen area */
2374 scroll_x = actual_scroll_x;
2375 scroll_y = actual_scroll_y;
2378 void InitMovDir(int x, int y)
2380 int i, element = Feld[x][y];
2381 static int xy[4][2] =
2388 static int direction[3][4] =
2390 { MV_RIGHT, MV_UP, MV_LEFT, MV_DOWN },
2391 { MV_LEFT, MV_DOWN, MV_RIGHT, MV_UP },
2392 { MV_LEFT, MV_RIGHT, MV_UP, MV_DOWN }
2401 Feld[x][y] = EL_BUG;
2402 MovDir[x][y] = direction[0][element - EL_BUG_RIGHT];
2405 case EL_SPACESHIP_RIGHT:
2406 case EL_SPACESHIP_UP:
2407 case EL_SPACESHIP_LEFT:
2408 case EL_SPACESHIP_DOWN:
2409 Feld[x][y] = EL_SPACESHIP;
2410 MovDir[x][y] = direction[0][element - EL_SPACESHIP_RIGHT];
2413 case EL_BD_BUTTERFLY_RIGHT:
2414 case EL_BD_BUTTERFLY_UP:
2415 case EL_BD_BUTTERFLY_LEFT:
2416 case EL_BD_BUTTERFLY_DOWN:
2417 Feld[x][y] = EL_BD_BUTTERFLY;
2418 MovDir[x][y] = direction[0][element - EL_BD_BUTTERFLY_RIGHT];
2421 case EL_BD_FIREFLY_RIGHT:
2422 case EL_BD_FIREFLY_UP:
2423 case EL_BD_FIREFLY_LEFT:
2424 case EL_BD_FIREFLY_DOWN:
2425 Feld[x][y] = EL_BD_FIREFLY;
2426 MovDir[x][y] = direction[0][element - EL_BD_FIREFLY_RIGHT];
2429 case EL_PACMAN_RIGHT:
2431 case EL_PACMAN_LEFT:
2432 case EL_PACMAN_DOWN:
2433 Feld[x][y] = EL_PACMAN;
2434 MovDir[x][y] = direction[0][element - EL_PACMAN_RIGHT];
2437 case EL_SP_SNIKSNAK:
2438 MovDir[x][y] = MV_UP;
2441 case EL_SP_ELECTRON:
2442 MovDir[x][y] = MV_LEFT;
2449 Feld[x][y] = EL_MOLE;
2450 MovDir[x][y] = direction[2][element - EL_MOLE_LEFT];
2454 if (IS_CUSTOM_ELEMENT(element))
2456 struct ElementInfo *ei = &element_info[element];
2457 int move_direction_initial = ei->move_direction_initial;
2458 int move_pattern = ei->move_pattern;
2460 if (move_direction_initial == MV_START_PREVIOUS)
2462 if (MovDir[x][y] != MV_NONE)
2465 move_direction_initial = MV_START_AUTOMATIC;
2468 if (move_direction_initial == MV_START_RANDOM)
2469 MovDir[x][y] = 1 << RND(4);
2470 else if (move_direction_initial & MV_ANY_DIRECTION)
2471 MovDir[x][y] = move_direction_initial;
2472 else if (move_pattern == MV_ALL_DIRECTIONS ||
2473 move_pattern == MV_TURNING_LEFT ||
2474 move_pattern == MV_TURNING_RIGHT ||
2475 move_pattern == MV_TURNING_LEFT_RIGHT ||
2476 move_pattern == MV_TURNING_RIGHT_LEFT ||
2477 move_pattern == MV_TURNING_RANDOM)
2478 MovDir[x][y] = 1 << RND(4);
2479 else if (move_pattern == MV_HORIZONTAL)
2480 MovDir[x][y] = (RND(2) ? MV_LEFT : MV_RIGHT);
2481 else if (move_pattern == MV_VERTICAL)
2482 MovDir[x][y] = (RND(2) ? MV_UP : MV_DOWN);
2483 else if (move_pattern & MV_ANY_DIRECTION)
2484 MovDir[x][y] = element_info[element].move_pattern;
2485 else if (move_pattern == MV_ALONG_LEFT_SIDE ||
2486 move_pattern == MV_ALONG_RIGHT_SIDE)
2488 /* use random direction as default start direction */
2489 if (game.engine_version >= VERSION_IDENT(3,1,0,0))
2490 MovDir[x][y] = 1 << RND(4);
2492 for (i = 0; i < NUM_DIRECTIONS; i++)
2494 int x1 = x + xy[i][0];
2495 int y1 = y + xy[i][1];
2497 if (!IN_LEV_FIELD(x1, y1) || !IS_FREE(x1, y1))
2499 if (move_pattern == MV_ALONG_RIGHT_SIDE)
2500 MovDir[x][y] = direction[0][i];
2502 MovDir[x][y] = direction[1][i];
2511 MovDir[x][y] = 1 << RND(4);
2513 if (element != EL_BUG &&
2514 element != EL_SPACESHIP &&
2515 element != EL_BD_BUTTERFLY &&
2516 element != EL_BD_FIREFLY)
2519 for (i = 0; i < NUM_DIRECTIONS; i++)
2521 int x1 = x + xy[i][0];
2522 int y1 = y + xy[i][1];
2524 if (!IN_LEV_FIELD(x1, y1) || !IS_FREE(x1, y1))
2526 if (element == EL_BUG || element == EL_BD_BUTTERFLY)
2528 MovDir[x][y] = direction[0][i];
2531 else if (element == EL_SPACESHIP || element == EL_BD_FIREFLY ||
2532 element == EL_SP_SNIKSNAK || element == EL_SP_ELECTRON)
2534 MovDir[x][y] = direction[1][i];
2543 GfxDir[x][y] = MovDir[x][y];
2546 void InitAmoebaNr(int x, int y)
2549 int group_nr = AmoebeNachbarNr(x, y);
2553 for (i = 1; i < MAX_NUM_AMOEBA; i++)
2555 if (AmoebaCnt[i] == 0)
2563 AmoebaNr[x][y] = group_nr;
2564 AmoebaCnt[group_nr]++;
2565 AmoebaCnt2[group_nr]++;
2571 boolean raise_level = FALSE;
2573 if (local_player->MovPos)
2576 if (tape.auto_play) /* tape might already be stopped here */
2577 tape.auto_play_level_solved = TRUE;
2579 local_player->LevelSolved = FALSE;
2581 PlaySoundStereo(SND_GAME_WINNING, SOUND_MIDDLE);
2585 if (!tape.playing && setup.sound_loops)
2586 PlaySoundExt(SND_GAME_LEVELTIME_BONUS, SOUND_MAX_VOLUME, SOUND_MIDDLE,
2587 SND_CTRL_PLAY_LOOP);
2589 while (TimeLeft > 0)
2591 if (!tape.playing && !setup.sound_loops)
2592 PlaySoundStereo(SND_GAME_LEVELTIME_BONUS, SOUND_MIDDLE);
2594 if (TimeLeft > 100 && TimeLeft % 10 == 0)
2597 RaiseScore(level.score[SC_TIME_BONUS] * 10);
2602 RaiseScore(level.score[SC_TIME_BONUS]);
2605 DrawGameValue_Time(TimeLeft);
2613 if (!tape.playing && setup.sound_loops)
2614 StopSound(SND_GAME_LEVELTIME_BONUS);
2616 else if (level.time == 0) /* level without time limit */
2618 if (!tape.playing && setup.sound_loops)
2619 PlaySoundExt(SND_GAME_LEVELTIME_BONUS, SOUND_MAX_VOLUME, SOUND_MIDDLE,
2620 SND_CTRL_PLAY_LOOP);
2622 while (TimePlayed < 999)
2624 if (!tape.playing && !setup.sound_loops)
2625 PlaySoundStereo(SND_GAME_LEVELTIME_BONUS, SOUND_MIDDLE);
2627 if (TimePlayed < 900 && TimePlayed % 10 == 0)
2630 RaiseScore(level.score[SC_TIME_BONUS] * 10);
2635 RaiseScore(level.score[SC_TIME_BONUS]);
2638 DrawGameValue_Time(TimePlayed);
2646 if (!tape.playing && setup.sound_loops)
2647 StopSound(SND_GAME_LEVELTIME_BONUS);
2650 /* close exit door after last player */
2651 if (AllPlayersGone && ExitX >= 0 && ExitY >= 0 &&
2652 (Feld[ExitX][ExitY] == EL_EXIT_OPEN ||
2653 Feld[ExitX][ExitY] == EL_SP_EXIT_OPEN))
2655 int element = Feld[ExitX][ExitY];
2657 Feld[ExitX][ExitY] = (element == EL_EXIT_OPEN ? EL_EXIT_CLOSING :
2658 EL_SP_EXIT_CLOSING);
2660 PlayLevelSoundElementAction(ExitX, ExitY, element, ACTION_CLOSING);
2663 /* player disappears */
2664 if (ExitX >= 0 && ExitY >= 0)
2665 DrawLevelField(ExitX, ExitY);
2671 printf("::: TAPE PLAYING -> DO NOT SAVE SCORE\n");
2673 printf("::: NO TAPE PLAYING -> SAVING SCORE\n");
2679 CloseDoor(DOOR_CLOSE_1);
2684 SaveTape(tape.level_nr); /* Ask to save tape */
2687 if (level_nr == leveldir_current->handicap_level)
2689 leveldir_current->handicap_level++;
2690 SaveLevelSetup_SeriesInfo();
2693 if (level_editor_test_game)
2694 local_player->score = -1; /* no highscore when playing from editor */
2695 else if (level_nr < leveldir_current->last_level)
2696 raise_level = TRUE; /* advance to next level */
2698 if ((hi_pos = NewHiScore()) >= 0)
2700 game_status = GAME_MODE_SCORES;
2701 DrawHallOfFame(hi_pos);
2710 game_status = GAME_MODE_MAIN;
2727 LoadScore(level_nr);
2729 if (strcmp(setup.player_name, EMPTY_PLAYER_NAME) == 0 ||
2730 local_player->score < highscore[MAX_SCORE_ENTRIES - 1].Score)
2733 for (k = 0; k < MAX_SCORE_ENTRIES; k++)
2735 if (local_player->score > highscore[k].Score)
2737 /* player has made it to the hall of fame */
2739 if (k < MAX_SCORE_ENTRIES - 1)
2741 int m = MAX_SCORE_ENTRIES - 1;
2744 for (l = k; l < MAX_SCORE_ENTRIES; l++)
2745 if (!strcmp(setup.player_name, highscore[l].Name))
2747 if (m == k) /* player's new highscore overwrites his old one */
2751 for (l = m; l > k; l--)
2753 strcpy(highscore[l].Name, highscore[l - 1].Name);
2754 highscore[l].Score = highscore[l - 1].Score;
2761 strncpy(highscore[k].Name, setup.player_name, MAX_PLAYER_NAME_LEN);
2762 highscore[k].Name[MAX_PLAYER_NAME_LEN] = '\0';
2763 highscore[k].Score = local_player->score;
2769 else if (!strncmp(setup.player_name, highscore[k].Name,
2770 MAX_PLAYER_NAME_LEN))
2771 break; /* player already there with a higher score */
2777 SaveScore(level_nr);
2782 inline static int getElementMoveStepsize(int x, int y)
2784 int element = Feld[x][y];
2785 int direction = MovDir[x][y];
2786 int dx = (direction == MV_LEFT ? -1 : direction == MV_RIGHT ? +1 : 0);
2787 int dy = (direction == MV_UP ? -1 : direction == MV_DOWN ? +1 : 0);
2788 int horiz_move = (dx != 0);
2789 int sign = (horiz_move ? dx : dy);
2790 int step = sign * element_info[element].move_stepsize;
2792 /* special values for move stepsize for spring and things on conveyor belt */
2796 if (element == EL_SPRING)
2797 step = sign * MOVE_STEPSIZE_NORMAL * 2;
2798 else if (CAN_FALL(element) && !CAN_MOVE(element) &&
2799 y < lev_fieldy - 1 && IS_BELT_ACTIVE(Feld[x][y + 1]))
2800 step = sign * MOVE_STEPSIZE_NORMAL / 2;
2802 if (CAN_FALL(element) &&
2803 y < lev_fieldy - 1 && IS_BELT_ACTIVE(Feld[x][y + 1]))
2804 step = sign * MOVE_STEPSIZE_NORMAL / 2;
2805 else if (element == EL_SPRING)
2806 step = sign * MOVE_STEPSIZE_NORMAL * 2;
2813 void InitPlayerGfxAnimation(struct PlayerInfo *player, int action, int dir)
2815 if (player->GfxAction != action || player->GfxDir != dir)
2818 printf("Player frame reset! (%d => %d, %d => %d)\n",
2819 player->GfxAction, action, player->GfxDir, dir);
2822 player->GfxAction = action;
2823 player->GfxDir = dir;
2825 player->StepFrame = 0;
2829 static void ResetRandomAnimationValue(int x, int y)
2831 GfxRandom[x][y] = INIT_GFX_RANDOM();
2834 static void ResetGfxAnimation(int x, int y)
2837 int element, graphic;
2841 GfxAction[x][y] = ACTION_DEFAULT;
2842 GfxDir[x][y] = MovDir[x][y];
2845 element = Feld[x][y];
2846 graphic = el_act_dir2img(element, GfxAction[x][y], GfxDir[x][y]);
2848 if (graphic_info[graphic].anim_global_sync)
2849 GfxFrame[x][y] = FrameCounter;
2850 else if (ANIM_MODE(graphic) == ANIM_CE_VALUE)
2851 GfxFrame[x][y] = CustomValue[x][y];
2852 else if (ANIM_MODE(graphic) == ANIM_CE_SCORE)
2853 GfxFrame[x][y] = element_info[element].collect_score;
2857 void InitMovingField(int x, int y, int direction)
2859 int element = Feld[x][y];
2863 int dx = (direction == MV_LEFT ? -1 : direction == MV_RIGHT ? +1 : 0);
2864 int dy = (direction == MV_UP ? -1 : direction == MV_DOWN ? +1 : 0);
2868 if (!WasJustMoving[x][y] || direction != MovDir[x][y])
2869 ResetGfxAnimation(x, y);
2871 MovDir[x][y] = direction;
2872 GfxDir[x][y] = direction;
2873 GfxAction[x][y] = (direction == MV_DOWN && CAN_FALL(element) ?
2874 ACTION_FALLING : ACTION_MOVING);
2877 graphic = el_act_dir2img(element, GfxAction[x][y], GfxDir[x][y]);
2879 if (graphic_info[graphic].anim_global_sync)
2880 GfxFrame[x][y] = FrameCounter;
2881 else if (ANIM_MODE(graphic) == ANIM_CE_VALUE)
2882 GfxFrame[x][y] = CustomValue[x][y];
2883 else if (ANIM_MODE(graphic) == ANIM_CE_SCORE)
2884 GfxFrame[x][y] = element_info[element].collect_score;
2887 /* this is needed for CEs with property "can move" / "not moving" */
2889 if (getElementMoveStepsize(x, y) != 0) /* moving or being moved */
2891 if (Feld[newx][newy] == EL_EMPTY)
2892 Feld[newx][newy] = EL_BLOCKED;
2894 MovDir[newx][newy] = MovDir[x][y];
2896 #if USE_NEW_CUSTOM_VALUE
2897 CustomValue[newx][newy] = CustomValue[x][y];
2900 GfxFrame[newx][newy] = GfxFrame[x][y];
2901 GfxRandom[newx][newy] = GfxRandom[x][y];
2902 GfxAction[newx][newy] = GfxAction[x][y];
2903 GfxDir[newx][newy] = GfxDir[x][y];
2907 void Moving2Blocked(int x, int y, int *goes_to_x, int *goes_to_y)
2909 int direction = MovDir[x][y];
2911 int newx = x + (direction & MV_LEFT ? -1 : direction & MV_RIGHT ? +1 : 0);
2912 int newy = y + (direction & MV_UP ? -1 : direction & MV_DOWN ? +1 : 0);
2914 int newx = x + (direction == MV_LEFT ? -1 : direction == MV_RIGHT ? +1 : 0);
2915 int newy = y + (direction == MV_UP ? -1 : direction == MV_DOWN ? +1 : 0);
2922 void Blocked2Moving(int x, int y, int *comes_from_x, int *comes_from_y)
2924 int oldx = x, oldy = y;
2925 int direction = MovDir[x][y];
2927 if (direction == MV_LEFT)
2929 else if (direction == MV_RIGHT)
2931 else if (direction == MV_UP)
2933 else if (direction == MV_DOWN)
2936 *comes_from_x = oldx;
2937 *comes_from_y = oldy;
2940 int MovingOrBlocked2Element(int x, int y)
2942 int element = Feld[x][y];
2944 if (element == EL_BLOCKED)
2948 Blocked2Moving(x, y, &oldx, &oldy);
2949 return Feld[oldx][oldy];
2955 static int MovingOrBlocked2ElementIfNotLeaving(int x, int y)
2957 /* like MovingOrBlocked2Element(), but if element is moving
2958 and (x,y) is the field the moving element is just leaving,
2959 return EL_BLOCKED instead of the element value */
2960 int element = Feld[x][y];
2962 if (IS_MOVING(x, y))
2964 if (element == EL_BLOCKED)
2968 Blocked2Moving(x, y, &oldx, &oldy);
2969 return Feld[oldx][oldy];
2978 static void RemoveField(int x, int y)
2980 Feld[x][y] = EL_EMPTY;
2986 #if USE_NEW_CUSTOM_VALUE
2987 CustomValue[x][y] = 0;
2991 ChangeDelay[x][y] = 0;
2992 ChangePage[x][y] = -1;
2993 Pushed[x][y] = FALSE;
2996 ExplodeField[x][y] = EX_TYPE_NONE;
2999 GfxElement[x][y] = EL_UNDEFINED;
3000 GfxAction[x][y] = ACTION_DEFAULT;
3001 GfxDir[x][y] = MV_NONE;
3004 void RemoveMovingField(int x, int y)
3006 int oldx = x, oldy = y, newx = x, newy = y;
3007 int element = Feld[x][y];
3008 int next_element = EL_UNDEFINED;
3010 if (element != EL_BLOCKED && !IS_MOVING(x, y))
3013 if (IS_MOVING(x, y))
3015 Moving2Blocked(x, y, &newx, &newy);
3017 if (Feld[newx][newy] != EL_BLOCKED)
3019 /* element is moving, but target field is not free (blocked), but
3020 already occupied by something different (example: acid pool);
3021 in this case, only remove the moving field, but not the target */
3023 RemoveField(oldx, oldy);
3025 Store[oldx][oldy] = Store2[oldx][oldy] = 0;
3027 DrawLevelField(oldx, oldy);
3032 else if (element == EL_BLOCKED)
3034 Blocked2Moving(x, y, &oldx, &oldy);
3035 if (!IS_MOVING(oldx, oldy))
3039 if (element == EL_BLOCKED &&
3040 (Feld[oldx][oldy] == EL_QUICKSAND_EMPTYING ||
3041 Feld[oldx][oldy] == EL_MAGIC_WALL_EMPTYING ||
3042 Feld[oldx][oldy] == EL_BD_MAGIC_WALL_EMPTYING ||
3043 Feld[oldx][oldy] == EL_AMOEBA_DROPPING))
3044 next_element = get_next_element(Feld[oldx][oldy]);
3046 RemoveField(oldx, oldy);
3047 RemoveField(newx, newy);
3049 Store[oldx][oldy] = Store2[oldx][oldy] = 0;
3051 if (next_element != EL_UNDEFINED)
3052 Feld[oldx][oldy] = next_element;
3054 DrawLevelField(oldx, oldy);
3055 DrawLevelField(newx, newy);
3058 void DrawDynamite(int x, int y)
3060 int sx = SCREENX(x), sy = SCREENY(y);
3061 int graphic = el2img(Feld[x][y]);
3064 if (!IN_SCR_FIELD(sx, sy) || IS_PLAYER(x, y))
3067 if (IS_WALKABLE_INSIDE(Back[x][y]))
3071 DrawGraphic(sx, sy, el2img(Back[x][y]), 0);
3072 else if (Store[x][y])
3073 DrawGraphic(sx, sy, el2img(Store[x][y]), 0);
3075 frame = getGraphicAnimationFrame(graphic, GfxFrame[x][y]);
3077 if (Back[x][y] || Store[x][y])
3078 DrawGraphicThruMask(sx, sy, graphic, frame);
3080 DrawGraphic(sx, sy, graphic, frame);
3083 void CheckDynamite(int x, int y)
3085 if (MovDelay[x][y] != 0) /* dynamite is still waiting to explode */
3089 if (MovDelay[x][y] != 0)
3092 PlayLevelSoundActionIfLoop(x, y, ACTION_ACTIVE);
3098 StopLevelSoundActionIfLoop(x, y, ACTION_ACTIVE);
3103 void DrawRelocatePlayer(struct PlayerInfo *player, boolean quick_relocation)
3105 boolean ffwd_delay = (tape.playing && tape.fast_forward);
3106 boolean no_delay = (tape.warp_forward);
3107 int frame_delay_value = (ffwd_delay ? FfwdFrameDelay : GameFrameDelay);
3108 int wait_delay_value = (no_delay ? 0 : frame_delay_value);
3109 int jx = player->jx;
3110 int jy = player->jy;
3112 if (quick_relocation)
3114 int offset = (setup.scroll_delay ? 3 : 0);
3116 if (!IN_VIS_FIELD(SCREENX(jx), SCREENY(jy)))
3118 scroll_x = (player->jx < SBX_Left + MIDPOSX ? SBX_Left :
3119 player->jx > SBX_Right + MIDPOSX ? SBX_Right :
3120 player->jx - MIDPOSX);
3122 scroll_y = (player->jy < SBY_Upper + MIDPOSY ? SBY_Upper :
3123 player->jy > SBY_Lower + MIDPOSY ? SBY_Lower :
3124 player->jy - MIDPOSY);
3128 if ((player->MovDir == MV_LEFT && scroll_x > jx - MIDPOSX + offset) ||
3129 (player->MovDir == MV_RIGHT && scroll_x < jx - MIDPOSX - offset))
3130 scroll_x = jx - MIDPOSX + (scroll_x < jx-MIDPOSX ? -offset : +offset);
3132 if ((player->MovDir == MV_UP && scroll_y > jy - MIDPOSY + offset) ||
3133 (player->MovDir == MV_DOWN && scroll_y < jy - MIDPOSY - offset))
3134 scroll_y = jy - MIDPOSY + (scroll_y < jy-MIDPOSY ? -offset : +offset);
3136 /* don't scroll over playfield boundaries */
3137 if (scroll_x < SBX_Left || scroll_x > SBX_Right)
3138 scroll_x = (scroll_x < SBX_Left ? SBX_Left : SBX_Right);
3140 /* don't scroll over playfield boundaries */
3141 if (scroll_y < SBY_Upper || scroll_y > SBY_Lower)
3142 scroll_y = (scroll_y < SBY_Upper ? SBY_Upper : SBY_Lower);
3145 RedrawPlayfield(TRUE, 0,0,0,0);
3149 int scroll_xx = (player->jx < SBX_Left + MIDPOSX ? SBX_Left :
3150 player->jx > SBX_Right + MIDPOSX ? SBX_Right :
3151 player->jx - MIDPOSX);
3153 int scroll_yy = (player->jy < SBY_Upper + MIDPOSY ? SBY_Upper :
3154 player->jy > SBY_Lower + MIDPOSY ? SBY_Lower :
3155 player->jy - MIDPOSY);
3157 ScrollScreen(NULL, SCROLL_GO_ON); /* scroll last frame to full tile */
3159 while (scroll_x != scroll_xx || scroll_y != scroll_yy)
3162 int fx = FX, fy = FY;
3164 dx = (scroll_xx < scroll_x ? +1 : scroll_xx > scroll_x ? -1 : 0);
3165 dy = (scroll_yy < scroll_y ? +1 : scroll_yy > scroll_y ? -1 : 0);
3167 if (dx == 0 && dy == 0) /* no scrolling needed at all */
3173 fx += dx * TILEX / 2;
3174 fy += dy * TILEY / 2;
3176 ScrollLevel(dx, dy);
3179 /* scroll in two steps of half tile size to make things smoother */
3180 BlitBitmap(drawto_field, window, fx, fy, SXSIZE, SYSIZE, SX, SY);
3182 Delay(wait_delay_value);
3184 /* scroll second step to align at full tile size */
3186 Delay(wait_delay_value);
3191 Delay(wait_delay_value);
3195 void RelocatePlayer(int jx, int jy, int el_player_raw)
3197 int el_player = GET_PLAYER_ELEMENT(el_player_raw);
3198 int player_nr = GET_PLAYER_NR(el_player);
3199 struct PlayerInfo *player = &stored_player[player_nr];
3200 boolean ffwd_delay = (tape.playing && tape.fast_forward);
3201 boolean no_delay = (tape.warp_forward);
3202 int frame_delay_value = (ffwd_delay ? FfwdFrameDelay : GameFrameDelay);
3203 int wait_delay_value = (no_delay ? 0 : frame_delay_value);
3204 int old_jx = player->jx;
3205 int old_jy = player->jy;
3206 int old_element = Feld[old_jx][old_jy];
3207 int element = Feld[jx][jy];
3208 boolean player_relocated = (old_jx != jx || old_jy != jy);
3210 int move_dir_horiz = (jx < old_jx ? MV_LEFT : jx > old_jx ? MV_RIGHT : 0);
3211 int move_dir_vert = (jy < old_jy ? MV_UP : jy > old_jy ? MV_DOWN : 0);
3212 int enter_side_horiz = MV_DIR_OPPOSITE(move_dir_horiz);
3213 int enter_side_vert = MV_DIR_OPPOSITE(move_dir_vert);
3214 int leave_side_horiz = move_dir_horiz;
3215 int leave_side_vert = move_dir_vert;
3216 int enter_side = enter_side_horiz | enter_side_vert;
3217 int leave_side = leave_side_horiz | leave_side_vert;
3219 if (player->GameOver) /* do not reanimate dead player */
3222 if (!player_relocated) /* no need to relocate the player */
3225 if (IS_PLAYER(jx, jy)) /* player already placed at new position */
3227 RemoveField(jx, jy); /* temporarily remove newly placed player */
3228 DrawLevelField(jx, jy);
3231 if (player->present)
3233 while (player->MovPos)
3235 ScrollPlayer(player, SCROLL_GO_ON);
3236 ScrollScreen(NULL, SCROLL_GO_ON);
3238 AdvanceFrameAndPlayerCounters(player->index_nr);
3243 Delay(wait_delay_value);
3246 DrawPlayer(player); /* needed here only to cleanup last field */
3247 DrawLevelField(player->jx, player->jy); /* remove player graphic */
3249 player->is_moving = FALSE;
3252 if (IS_CUSTOM_ELEMENT(old_element))
3253 CheckElementChangeByPlayer(old_jx, old_jy, old_element,
3255 player->index_bit, leave_side);
3257 CheckTriggeredElementChangeByPlayer(old_jx, old_jy, old_element,
3259 player->index_bit, leave_side);
3261 Feld[jx][jy] = el_player;
3262 InitPlayerField(jx, jy, el_player, TRUE);
3264 if (!ELEM_IS_PLAYER(element)) /* player may be set on walkable element */
3266 Feld[jx][jy] = element;
3267 InitField(jx, jy, FALSE);
3271 /* only visually relocate centered player */
3272 if (player->index_nr == game.centered_player_nr)
3273 DrawRelocatePlayer(player, level.instant_relocation);
3275 if (player == local_player) /* only visually relocate local player */
3276 DrawRelocatePlayer(player, level.instant_relocation);
3279 TestIfPlayerTouchesBadThing(jx, jy);
3280 TestIfPlayerTouchesCustomElement(jx, jy);
3282 if (IS_CUSTOM_ELEMENT(element))
3283 CheckElementChangeByPlayer(jx, jy, element, CE_ENTERED_BY_PLAYER,
3284 player->index_bit, enter_side);
3286 CheckTriggeredElementChangeByPlayer(jx, jy, element, CE_PLAYER_ENTERS_X,
3287 player->index_bit, enter_side);
3290 void Explode(int ex, int ey, int phase, int mode)
3296 /* !!! eliminate this variable !!! */
3297 int delay = (game.emulation == EMU_SUPAPLEX ? 3 : 2);
3299 if (game.explosions_delayed)
3301 ExplodeField[ex][ey] = mode;
3305 if (phase == EX_PHASE_START) /* initialize 'Store[][]' field */
3307 int center_element = Feld[ex][ey];
3308 int artwork_element, explosion_element; /* set these values later */
3311 /* --- This is only really needed (and now handled) in "Impact()". --- */
3312 /* do not explode moving elements that left the explode field in time */
3313 if (game.engine_version >= VERSION_IDENT(2,2,0,7) &&
3314 center_element == EL_EMPTY &&
3315 (mode == EX_TYPE_NORMAL || mode == EX_TYPE_CENTER))
3320 /* !!! at this place, the center element may be EL_BLOCKED !!! */
3321 if (mode == EX_TYPE_NORMAL ||
3322 mode == EX_TYPE_CENTER ||
3323 mode == EX_TYPE_CROSS)
3324 PlayLevelSoundElementAction(ex, ey, artwork_element, ACTION_EXPLODING);
3327 /* remove things displayed in background while burning dynamite */
3328 if (Back[ex][ey] != EL_EMPTY && !IS_INDESTRUCTIBLE(Back[ex][ey]))
3331 if (IS_MOVING(ex, ey) || IS_BLOCKED(ex, ey))
3333 /* put moving element to center field (and let it explode there) */
3334 center_element = MovingOrBlocked2Element(ex, ey);
3335 RemoveMovingField(ex, ey);
3336 Feld[ex][ey] = center_element;
3339 /* now "center_element" is finally determined -- set related values now */
3340 artwork_element = center_element; /* for custom player artwork */
3341 explosion_element = center_element; /* for custom player artwork */
3343 if (IS_PLAYER(ex, ey))
3345 int player_nr = GET_PLAYER_NR(StorePlayer[ex][ey]);
3347 artwork_element = stored_player[player_nr].artwork_element;
3349 if (level.use_explosion_element[player_nr])
3351 explosion_element = level.explosion_element[player_nr];
3352 artwork_element = explosion_element;
3357 if (mode == EX_TYPE_NORMAL ||
3358 mode == EX_TYPE_CENTER ||
3359 mode == EX_TYPE_CROSS)
3360 PlayLevelSoundElementAction(ex, ey, artwork_element, ACTION_EXPLODING);
3364 last_phase = element_info[explosion_element].explosion_delay + 1;
3366 last_phase = element_info[center_element].explosion_delay + 1;
3369 for (y = ey - 1; y <= ey + 1; y++) for (x = ex - 1; x <= ex + 1; x++)
3371 int xx = x - ex + 1;
3372 int yy = y - ey + 1;
3375 if (!IN_LEV_FIELD(x, y) ||
3376 (mode & EX_TYPE_SINGLE_TILE && (x != ex || y != ey)) ||
3377 (mode == EX_TYPE_CROSS && (x != ex && y != ey)))
3380 element = Feld[x][y];
3382 if (IS_MOVING(x, y) || IS_BLOCKED(x, y))
3384 element = MovingOrBlocked2Element(x, y);
3386 if (!IS_EXPLOSION_PROOF(element))
3387 RemoveMovingField(x, y);
3390 /* indestructible elements can only explode in center (but not flames) */
3391 if ((IS_EXPLOSION_PROOF(element) && (x != ex || y != ey ||
3392 mode == EX_TYPE_BORDER)) ||
3393 element == EL_FLAMES)
3396 /* no idea why this was changed from 3.0.8 to 3.1.0 -- this causes buggy
3397 behaviour, for example when touching a yamyam that explodes to rocks
3398 with active deadly shield, a rock is created under the player !!! */
3399 /* (case 1 (surely buggy): >= 3.1.0, case 2 (maybe buggy): <= 3.0.8) */
3401 if (IS_PLAYER(x, y) && SHIELD_ON(PLAYERINFO(x, y)) &&
3402 (game.engine_version < VERSION_IDENT(3,1,0,0) ||
3403 (x == ex && y == ey && mode != EX_TYPE_BORDER)))
3405 if (IS_PLAYER(x, y) && SHIELD_ON(PLAYERINFO(x, y)))
3408 if (IS_ACTIVE_BOMB(element))
3410 /* re-activate things under the bomb like gate or penguin */
3411 Feld[x][y] = (Back[x][y] ? Back[x][y] : EL_EMPTY);
3418 /* save walkable background elements while explosion on same tile */
3419 if (IS_WALKABLE(element) && IS_INDESTRUCTIBLE(element) &&
3420 (x != ex || y != ey || mode == EX_TYPE_BORDER))
3421 Back[x][y] = element;
3423 /* ignite explodable elements reached by other explosion */
3424 if (element == EL_EXPLOSION)
3425 element = Store2[x][y];
3427 if (AmoebaNr[x][y] &&
3428 (element == EL_AMOEBA_FULL ||
3429 element == EL_BD_AMOEBA ||
3430 element == EL_AMOEBA_GROWING))
3432 AmoebaCnt[AmoebaNr[x][y]]--;
3433 AmoebaCnt2[AmoebaNr[x][y]]--;
3438 if (IS_PLAYER(ex, ey) && !PLAYER_EXPLOSION_PROTECTED(ex, ey))
3441 int player_nr = StorePlayer[ex][ey] - EL_PLAYER_1;
3443 Store[x][y] = EL_PLAYER_IS_EXPLODING_1 + player_nr;
3445 switch(StorePlayer[ex][ey])
3448 Store[x][y] = EL_PLAYER_IS_EXPLODING_2;
3451 Store[x][y] = EL_PLAYER_IS_EXPLODING_3;
3454 Store[x][y] = EL_PLAYER_IS_EXPLODING_4;
3458 Store[x][y] = EL_PLAYER_IS_EXPLODING_1;
3463 if (PLAYERINFO(ex, ey)->use_murphy)
3464 Store[x][y] = EL_EMPTY;
3467 /* !!! check this case -- currently needed for rnd_rado_negundo_v,
3468 !!! levels 015 018 019 020 021 022 023 026 027 028 !!! */
3469 else if (ELEM_IS_PLAYER(center_element))
3470 Store[x][y] = EL_EMPTY;
3471 else if (center_element == EL_YAMYAM)
3472 Store[x][y] = level.yamyam_content[game.yamyam_content_nr].e[xx][yy];
3473 else if (element_info[center_element].content.e[xx][yy] != EL_EMPTY)
3474 Store[x][y] = element_info[center_element].content.e[xx][yy];
3476 /* needed because EL_BD_BUTTERFLY is not defined as "CAN_EXPLODE"
3477 (killing EL_BD_BUTTERFLY with dynamite would result in BD diamond
3478 otherwise) -- FIX THIS !!! */
3479 else if (!CAN_EXPLODE(element) && element != EL_BD_BUTTERFLY)
3480 Store[x][y] = element_info[element].content.e[1][1];
3482 else if (!CAN_EXPLODE(element))
3483 Store[x][y] = element_info[element].content.e[1][1];
3486 Store[x][y] = EL_EMPTY;
3488 else if (center_element == EL_MOLE)
3489 Store[x][y] = EL_EMERALD_RED;
3490 else if (center_element == EL_PENGUIN)
3491 Store[x][y] = EL_EMERALD_PURPLE;
3492 else if (center_element == EL_BUG)
3493 Store[x][y] = ((x == ex && y == ey) ? EL_DIAMOND : EL_EMERALD);
3494 else if (center_element == EL_BD_BUTTERFLY)
3495 Store[x][y] = EL_BD_DIAMOND;
3496 else if (center_element == EL_SP_ELECTRON)
3497 Store[x][y] = EL_SP_INFOTRON;
3498 else if (center_element == EL_AMOEBA_TO_DIAMOND)
3499 Store[x][y] = level.amoeba_content;
3500 else if (center_element == EL_YAMYAM)
3501 Store[x][y] = level.yamyam_content[game.yamyam_content_nr].e[xx][yy];
3502 else if (IS_CUSTOM_ELEMENT(center_element) &&
3503 element_info[center_element].content.e[xx][yy] != EL_EMPTY)
3504 Store[x][y] = element_info[center_element].content.e[xx][yy];
3505 else if (element == EL_WALL_EMERALD)
3506 Store[x][y] = EL_EMERALD;
3507 else if (element == EL_WALL_DIAMOND)
3508 Store[x][y] = EL_DIAMOND;
3509 else if (element == EL_WALL_BD_DIAMOND)
3510 Store[x][y] = EL_BD_DIAMOND;
3511 else if (element == EL_WALL_EMERALD_YELLOW)
3512 Store[x][y] = EL_EMERALD_YELLOW;
3513 else if (element == EL_WALL_EMERALD_RED)
3514 Store[x][y] = EL_EMERALD_RED;
3515 else if (element == EL_WALL_EMERALD_PURPLE)
3516 Store[x][y] = EL_EMERALD_PURPLE;
3517 else if (element == EL_WALL_PEARL)
3518 Store[x][y] = EL_PEARL;
3519 else if (element == EL_WALL_CRYSTAL)
3520 Store[x][y] = EL_CRYSTAL;
3521 else if (IS_CUSTOM_ELEMENT(element) && !CAN_EXPLODE(element))
3522 Store[x][y] = element_info[element].content.e[1][1];
3524 Store[x][y] = EL_EMPTY;
3527 if (x != ex || y != ey || mode == EX_TYPE_BORDER ||
3528 center_element == EL_AMOEBA_TO_DIAMOND)
3529 Store2[x][y] = element;
3531 Feld[x][y] = EL_EXPLOSION;
3532 GfxElement[x][y] = artwork_element;
3535 printf(":: setting gfx(%d,%d) to %d ['%s']\n",
3536 x, y, artwork_element, EL_NAME(artwork_element));
3539 ExplodePhase[x][y] = 1;
3540 ExplodeDelay[x][y] = last_phase;
3545 if (center_element == EL_YAMYAM)
3546 game.yamyam_content_nr =
3547 (game.yamyam_content_nr + 1) % level.num_yamyam_contents;
3559 GfxFrame[x][y] = 0; /* restart explosion animation */
3561 last_phase = ExplodeDelay[x][y];
3563 ExplodePhase[x][y] = (phase < last_phase ? phase + 1 : 0);
3567 /* activate this even in non-DEBUG version until cause for crash in
3568 getGraphicAnimationFrame() (see below) is found and eliminated */
3574 /* this can happen if the player leaves an explosion just in time */
3575 if (GfxElement[x][y] == EL_UNDEFINED)
3576 GfxElement[x][y] = EL_EMPTY;
3578 if (GfxElement[x][y] == EL_UNDEFINED)
3581 printf("Explode(): x = %d, y = %d: GfxElement == EL_UNDEFINED\n", x, y);
3582 printf("Explode(): This should never happen!\n");
3585 GfxElement[x][y] = EL_EMPTY;
3591 border_element = Store2[x][y];
3592 if (IS_PLAYER(x, y) && !PLAYER_EXPLOSION_PROTECTED(x, y))
3593 border_element = StorePlayer[x][y];
3595 if (phase == element_info[border_element].ignition_delay ||
3596 phase == last_phase)
3598 boolean border_explosion = FALSE;
3600 if (IS_PLAYER(x, y) && PLAYERINFO(x, y)->present &&
3601 !PLAYER_EXPLOSION_PROTECTED(x, y))
3603 KillPlayerUnlessExplosionProtected(x, y);
3604 border_explosion = TRUE;
3606 else if (CAN_EXPLODE_BY_EXPLOSION(border_element))
3608 Feld[x][y] = Store2[x][y];
3611 border_explosion = TRUE;
3613 else if (border_element == EL_AMOEBA_TO_DIAMOND)
3615 AmoebeUmwandeln(x, y);
3617 border_explosion = TRUE;
3620 /* if an element just explodes due to another explosion (chain-reaction),
3621 do not immediately end the new explosion when it was the last frame of
3622 the explosion (as it would be done in the following "if"-statement!) */
3623 if (border_explosion && phase == last_phase)
3627 if (phase == last_phase)
3631 element = Feld[x][y] = Store[x][y];
3632 Store[x][y] = Store2[x][y] = 0;
3633 GfxElement[x][y] = EL_UNDEFINED;
3635 /* player can escape from explosions and might therefore be still alive */
3636 if (element >= EL_PLAYER_IS_EXPLODING_1 &&
3637 element <= EL_PLAYER_IS_EXPLODING_4)
3639 int player_nr = element - EL_PLAYER_IS_EXPLODING_1;
3640 int explosion_element = EL_PLAYER_1 + player_nr;
3641 int xx = MIN(MAX(0, x - stored_player[player_nr].jx + 1), 2);
3642 int yy = MIN(MAX(0, y - stored_player[player_nr].jy + 1), 2);
3644 if (level.use_explosion_element[player_nr])
3645 explosion_element = level.explosion_element[player_nr];
3647 Feld[x][y] = (stored_player[player_nr].active ? EL_EMPTY :
3648 element_info[explosion_element].content.e[xx][yy]);
3651 /* restore probably existing indestructible background element */
3652 if (Back[x][y] && IS_INDESTRUCTIBLE(Back[x][y]))
3653 element = Feld[x][y] = Back[x][y];
3656 MovDir[x][y] = MovPos[x][y] = MovDelay[x][y] = 0;
3657 GfxDir[x][y] = MV_NONE;
3658 ChangeDelay[x][y] = 0;
3659 ChangePage[x][y] = -1;
3661 #if USE_NEW_CUSTOM_VALUE
3662 CustomValue[x][y] = 0;
3665 InitField_WithBug2(x, y, FALSE);
3667 DrawLevelField(x, y);
3669 TestIfElementTouchesCustomElement(x, y);
3671 if (GFX_CRUMBLED(element))
3672 DrawLevelFieldCrumbledSandNeighbours(x, y);
3674 if (IS_PLAYER(x, y) && !PLAYERINFO(x, y)->present)
3675 StorePlayer[x][y] = 0;
3677 if (ELEM_IS_PLAYER(element))
3678 RelocatePlayer(x, y, element);
3680 else if (IN_SCR_FIELD(SCREENX(x), SCREENY(y)))
3682 int graphic = el_act2img(GfxElement[x][y], ACTION_EXPLODING);
3683 int frame = getGraphicAnimationFrame(graphic, GfxFrame[x][y]);
3686 DrawLevelFieldCrumbledSand(x, y);
3688 if (IS_WALKABLE_OVER(Back[x][y]) && Back[x][y] != EL_EMPTY)
3690 DrawLevelElement(x, y, Back[x][y]);
3691 DrawGraphicThruMask(SCREENX(x), SCREENY(y), graphic, frame);
3693 else if (IS_WALKABLE_UNDER(Back[x][y]))
3695 DrawGraphic(SCREENX(x), SCREENY(y), graphic, frame);
3696 DrawLevelElementThruMask(x, y, Back[x][y]);
3698 else if (!IS_WALKABLE_INSIDE(Back[x][y]))
3699 DrawGraphic(SCREENX(x), SCREENY(y), graphic, frame);
3703 void DynaExplode(int ex, int ey)
3706 int dynabomb_element = Feld[ex][ey];
3707 int dynabomb_size = 1;
3708 boolean dynabomb_xl = FALSE;
3709 struct PlayerInfo *player;
3710 static int xy[4][2] =
3718 if (IS_ACTIVE_BOMB(dynabomb_element))
3720 player = &stored_player[dynabomb_element - EL_DYNABOMB_PLAYER_1_ACTIVE];
3721 dynabomb_size = player->dynabomb_size;
3722 dynabomb_xl = player->dynabomb_xl;
3723 player->dynabombs_left++;
3726 Explode(ex, ey, EX_PHASE_START, EX_TYPE_CENTER);
3728 for (i = 0; i < NUM_DIRECTIONS; i++)
3730 for (j = 1; j <= dynabomb_size; j++)
3732 int x = ex + j * xy[i][0];
3733 int y = ey + j * xy[i][1];
3736 if (!IN_LEV_FIELD(x, y) || IS_INDESTRUCTIBLE(Feld[x][y]))
3739 element = Feld[x][y];
3741 /* do not restart explosions of fields with active bombs */
3742 if (element == EL_EXPLOSION && IS_ACTIVE_BOMB(Store2[x][y]))
3745 Explode(x, y, EX_PHASE_START, EX_TYPE_BORDER);
3747 if (element != EL_EMPTY && element != EL_EXPLOSION &&
3748 !IS_DIGGABLE(element) && !dynabomb_xl)
3754 void Bang(int x, int y)
3756 int element = MovingOrBlocked2Element(x, y);
3757 int explosion_type = EX_TYPE_NORMAL;
3759 if (IS_PLAYER(x, y) && !PLAYER_EXPLOSION_PROTECTED(x, y))
3761 struct PlayerInfo *player = PLAYERINFO(x, y);
3763 element = Feld[x][y] = (player->use_murphy ? EL_SP_MURPHY :
3764 player->element_nr);
3766 if (level.use_explosion_element[player->index_nr])
3768 int explosion_element = level.explosion_element[player->index_nr];
3770 if (element_info[explosion_element].explosion_type == EXPLODES_CROSS)
3771 explosion_type = EX_TYPE_CROSS;
3772 else if (element_info[explosion_element].explosion_type == EXPLODES_1X1)
3773 explosion_type = EX_TYPE_CENTER;
3781 case EL_BD_BUTTERFLY:
3784 case EL_DARK_YAMYAM:
3788 RaiseScoreElement(element);
3791 case EL_DYNABOMB_PLAYER_1_ACTIVE:
3792 case EL_DYNABOMB_PLAYER_2_ACTIVE:
3793 case EL_DYNABOMB_PLAYER_3_ACTIVE:
3794 case EL_DYNABOMB_PLAYER_4_ACTIVE:
3795 case EL_DYNABOMB_INCREASE_NUMBER:
3796 case EL_DYNABOMB_INCREASE_SIZE:
3797 case EL_DYNABOMB_INCREASE_POWER:
3798 explosion_type = EX_TYPE_DYNA;
3803 case EL_LAMP_ACTIVE:
3804 case EL_AMOEBA_TO_DIAMOND:
3805 if (!IS_PLAYER(x, y)) /* penguin and player may be at same field */
3806 explosion_type = EX_TYPE_CENTER;
3810 if (element_info[element].explosion_type == EXPLODES_CROSS)
3811 explosion_type = EX_TYPE_CROSS;
3812 else if (element_info[element].explosion_type == EXPLODES_1X1)
3813 explosion_type = EX_TYPE_CENTER;
3817 if (explosion_type == EX_TYPE_DYNA)
3820 Explode(x, y, EX_PHASE_START, explosion_type);
3822 CheckTriggeredElementChange(x, y, element, CE_EXPLOSION_OF_X);
3825 void SplashAcid(int x, int y)
3827 if (IN_LEV_FIELD(x - 1, y - 1) && IS_FREE(x - 1, y - 1) &&
3828 (!IN_LEV_FIELD(x - 1, y - 2) ||
3829 !CAN_FALL(MovingOrBlocked2Element(x - 1, y - 2))))
3830 Feld[x - 1][y - 1] = EL_ACID_SPLASH_LEFT;
3832 if (IN_LEV_FIELD(x + 1, y - 1) && IS_FREE(x + 1, y - 1) &&
3833 (!IN_LEV_FIELD(x + 1, y - 2) ||
3834 !CAN_FALL(MovingOrBlocked2Element(x + 1, y - 2))))
3835 Feld[x + 1][y - 1] = EL_ACID_SPLASH_RIGHT;
3837 PlayLevelSound(x, y, SND_ACID_SPLASHING);
3840 static void InitBeltMovement()
3842 static int belt_base_element[4] =
3844 EL_CONVEYOR_BELT_1_LEFT,
3845 EL_CONVEYOR_BELT_2_LEFT,
3846 EL_CONVEYOR_BELT_3_LEFT,
3847 EL_CONVEYOR_BELT_4_LEFT
3849 static int belt_base_active_element[4] =
3851 EL_CONVEYOR_BELT_1_LEFT_ACTIVE,
3852 EL_CONVEYOR_BELT_2_LEFT_ACTIVE,
3853 EL_CONVEYOR_BELT_3_LEFT_ACTIVE,
3854 EL_CONVEYOR_BELT_4_LEFT_ACTIVE
3859 /* set frame order for belt animation graphic according to belt direction */
3860 for (i = 0; i < NUM_BELTS; i++)
3864 for (j = 0; j < NUM_BELT_PARTS; j++)
3866 int element = belt_base_active_element[belt_nr] + j;
3867 int graphic = el2img(element);
3869 if (game.belt_dir[i] == MV_LEFT)
3870 graphic_info[graphic].anim_mode &= ~ANIM_REVERSE;
3872 graphic_info[graphic].anim_mode |= ANIM_REVERSE;
3877 SCAN_PLAYFIELD(x, y)
3879 for (y = 0; y < lev_fieldy; y++) for (x = 0; x < lev_fieldx; x++)
3882 int element = Feld[x][y];
3884 for (i = 0; i < NUM_BELTS; i++)
3886 if (IS_BELT(element) && game.belt_dir[i] != MV_NONE)
3888 int e_belt_nr = getBeltNrFromBeltElement(element);
3891 if (e_belt_nr == belt_nr)
3893 int belt_part = Feld[x][y] - belt_base_element[belt_nr];
3895 Feld[x][y] = belt_base_active_element[belt_nr] + belt_part;
3902 static void ToggleBeltSwitch(int x, int y)
3904 static int belt_base_element[4] =
3906 EL_CONVEYOR_BELT_1_LEFT,
3907 EL_CONVEYOR_BELT_2_LEFT,
3908 EL_CONVEYOR_BELT_3_LEFT,
3909 EL_CONVEYOR_BELT_4_LEFT
3911 static int belt_base_active_element[4] =
3913 EL_CONVEYOR_BELT_1_LEFT_ACTIVE,
3914 EL_CONVEYOR_BELT_2_LEFT_ACTIVE,
3915 EL_CONVEYOR_BELT_3_LEFT_ACTIVE,
3916 EL_CONVEYOR_BELT_4_LEFT_ACTIVE
3918 static int belt_base_switch_element[4] =
3920 EL_CONVEYOR_BELT_1_SWITCH_LEFT,
3921 EL_CONVEYOR_BELT_2_SWITCH_LEFT,
3922 EL_CONVEYOR_BELT_3_SWITCH_LEFT,
3923 EL_CONVEYOR_BELT_4_SWITCH_LEFT
3925 static int belt_move_dir[4] =
3933 int element = Feld[x][y];
3934 int belt_nr = getBeltNrFromBeltSwitchElement(element);
3935 int belt_dir_nr = (game.belt_dir_nr[belt_nr] + 1) % 4;
3936 int belt_dir = belt_move_dir[belt_dir_nr];
3939 if (!IS_BELT_SWITCH(element))
3942 game.belt_dir_nr[belt_nr] = belt_dir_nr;
3943 game.belt_dir[belt_nr] = belt_dir;
3945 if (belt_dir_nr == 3)
3948 /* set frame order for belt animation graphic according to belt direction */
3949 for (i = 0; i < NUM_BELT_PARTS; i++)
3951 int element = belt_base_active_element[belt_nr] + i;
3952 int graphic = el2img(element);
3954 if (belt_dir == MV_LEFT)
3955 graphic_info[graphic].anim_mode &= ~ANIM_REVERSE;
3957 graphic_info[graphic].anim_mode |= ANIM_REVERSE;
3961 SCAN_PLAYFIELD(xx, yy)
3963 for (yy = 0; yy < lev_fieldy; yy++) for (xx = 0; xx < lev_fieldx; xx++)
3966 int element = Feld[xx][yy];
3968 if (IS_BELT_SWITCH(element))
3970 int e_belt_nr = getBeltNrFromBeltSwitchElement(element);
3972 if (e_belt_nr == belt_nr)
3974 Feld[xx][yy] = belt_base_switch_element[belt_nr] + belt_dir_nr;
3975 DrawLevelField(xx, yy);
3978 else if (IS_BELT(element) && belt_dir != MV_NONE)
3980 int e_belt_nr = getBeltNrFromBeltElement(element);
3982 if (e_belt_nr == belt_nr)
3984 int belt_part = Feld[xx][yy] - belt_base_element[belt_nr];
3986 Feld[xx][yy] = belt_base_active_element[belt_nr] + belt_part;
3987 DrawLevelField(xx, yy);
3990 else if (IS_BELT_ACTIVE(element) && belt_dir == MV_NONE)
3992 int e_belt_nr = getBeltNrFromBeltActiveElement(element);
3994 if (e_belt_nr == belt_nr)
3996 int belt_part = Feld[xx][yy] - belt_base_active_element[belt_nr];
3998 Feld[xx][yy] = belt_base_element[belt_nr] + belt_part;
3999 DrawLevelField(xx, yy);
4005 static void ToggleSwitchgateSwitch(int x, int y)
4009 game.switchgate_pos = !game.switchgate_pos;
4012 SCAN_PLAYFIELD(xx, yy)
4014 for (yy = 0; yy < lev_fieldy; yy++) for (xx = 0; xx < lev_fieldx; xx++)
4017 int element = Feld[xx][yy];
4019 if (element == EL_SWITCHGATE_SWITCH_UP ||
4020 element == EL_SWITCHGATE_SWITCH_DOWN)
4022 Feld[xx][yy] = EL_SWITCHGATE_SWITCH_UP + game.switchgate_pos;
4023 DrawLevelField(xx, yy);
4025 else if (element == EL_SWITCHGATE_OPEN ||
4026 element == EL_SWITCHGATE_OPENING)
4028 Feld[xx][yy] = EL_SWITCHGATE_CLOSING;
4030 PlayLevelSoundAction(xx, yy, ACTION_CLOSING);
4032 else if (element == EL_SWITCHGATE_CLOSED ||
4033 element == EL_SWITCHGATE_CLOSING)
4035 Feld[xx][yy] = EL_SWITCHGATE_OPENING;
4037 PlayLevelSoundAction(xx, yy, ACTION_OPENING);
4042 static int getInvisibleActiveFromInvisibleElement(int element)
4044 return (element == EL_INVISIBLE_STEELWALL ? EL_INVISIBLE_STEELWALL_ACTIVE :
4045 element == EL_INVISIBLE_WALL ? EL_INVISIBLE_WALL_ACTIVE :
4046 element == EL_INVISIBLE_SAND ? EL_INVISIBLE_SAND_ACTIVE :
4050 static int getInvisibleFromInvisibleActiveElement(int element)
4052 return (element == EL_INVISIBLE_STEELWALL_ACTIVE ? EL_INVISIBLE_STEELWALL :
4053 element == EL_INVISIBLE_WALL_ACTIVE ? EL_INVISIBLE_WALL :
4054 element == EL_INVISIBLE_SAND_ACTIVE ? EL_INVISIBLE_SAND :
4058 static void RedrawAllLightSwitchesAndInvisibleElements()
4063 SCAN_PLAYFIELD(x, y)
4065 for (y = 0; y < lev_fieldy; y++) for (x = 0; x < lev_fieldx; x++)
4068 int element = Feld[x][y];
4070 if (element == EL_LIGHT_SWITCH &&
4071 game.light_time_left > 0)
4073 Feld[x][y] = EL_LIGHT_SWITCH_ACTIVE;
4074 DrawLevelField(x, y);
4076 else if (element == EL_LIGHT_SWITCH_ACTIVE &&
4077 game.light_time_left == 0)
4079 Feld[x][y] = EL_LIGHT_SWITCH;
4080 DrawLevelField(x, y);
4082 else if (element == EL_EMC_DRIPPER &&
4083 game.light_time_left > 0)
4085 Feld[x][y] = EL_EMC_DRIPPER_ACTIVE;
4086 DrawLevelField(x, y);
4088 else if (element == EL_EMC_DRIPPER_ACTIVE &&
4089 game.light_time_left == 0)
4091 Feld[x][y] = EL_EMC_DRIPPER;
4092 DrawLevelField(x, y);
4094 else if (element == EL_INVISIBLE_STEELWALL ||
4095 element == EL_INVISIBLE_WALL ||
4096 element == EL_INVISIBLE_SAND)
4098 if (game.light_time_left > 0)
4099 Feld[x][y] = getInvisibleActiveFromInvisibleElement(element);
4101 DrawLevelField(x, y);
4103 /* uncrumble neighbour fields, if needed */
4104 if (element == EL_INVISIBLE_SAND)
4105 DrawLevelFieldCrumbledSandNeighbours(x, y);
4107 else if (element == EL_INVISIBLE_STEELWALL_ACTIVE ||
4108 element == EL_INVISIBLE_WALL_ACTIVE ||
4109 element == EL_INVISIBLE_SAND_ACTIVE)
4111 if (game.light_time_left == 0)
4112 Feld[x][y] = getInvisibleFromInvisibleActiveElement(element);
4114 DrawLevelField(x, y);
4116 /* re-crumble neighbour fields, if needed */
4117 if (element == EL_INVISIBLE_SAND)
4118 DrawLevelFieldCrumbledSandNeighbours(x, y);
4123 static void RedrawAllInvisibleElementsForLenses()
4128 SCAN_PLAYFIELD(x, y)
4130 for (y = 0; y < lev_fieldy; y++) for (x = 0; x < lev_fieldx; x++)
4133 int element = Feld[x][y];
4135 if (element == EL_EMC_DRIPPER &&
4136 game.lenses_time_left > 0)
4138 Feld[x][y] = EL_EMC_DRIPPER_ACTIVE;
4139 DrawLevelField(x, y);
4141 else if (element == EL_EMC_DRIPPER_ACTIVE &&
4142 game.lenses_time_left == 0)
4144 Feld[x][y] = EL_EMC_DRIPPER;
4145 DrawLevelField(x, y);
4147 else if (element == EL_INVISIBLE_STEELWALL ||
4148 element == EL_INVISIBLE_WALL ||
4149 element == EL_INVISIBLE_SAND)
4151 if (game.lenses_time_left > 0)
4152 Feld[x][y] = getInvisibleActiveFromInvisibleElement(element);
4154 DrawLevelField(x, y);
4156 /* uncrumble neighbour fields, if needed */
4157 if (element == EL_INVISIBLE_SAND)
4158 DrawLevelFieldCrumbledSandNeighbours(x, y);
4160 else if (element == EL_INVISIBLE_STEELWALL_ACTIVE ||
4161 element == EL_INVISIBLE_WALL_ACTIVE ||
4162 element == EL_INVISIBLE_SAND_ACTIVE)
4164 if (game.lenses_time_left == 0)
4165 Feld[x][y] = getInvisibleFromInvisibleActiveElement(element);
4167 DrawLevelField(x, y);
4169 /* re-crumble neighbour fields, if needed */
4170 if (element == EL_INVISIBLE_SAND)
4171 DrawLevelFieldCrumbledSandNeighbours(x, y);
4176 static void RedrawAllInvisibleElementsForMagnifier()
4181 SCAN_PLAYFIELD(x, y)
4183 for (y = 0; y < lev_fieldy; y++) for (x = 0; x < lev_fieldx; x++)
4186 int element = Feld[x][y];
4188 if (element == EL_EMC_FAKE_GRASS &&
4189 game.magnify_time_left > 0)
4191 Feld[x][y] = EL_EMC_FAKE_GRASS_ACTIVE;
4192 DrawLevelField(x, y);
4194 else if (element == EL_EMC_FAKE_GRASS_ACTIVE &&
4195 game.magnify_time_left == 0)
4197 Feld[x][y] = EL_EMC_FAKE_GRASS;
4198 DrawLevelField(x, y);
4200 else if (IS_GATE_GRAY(element) &&
4201 game.magnify_time_left > 0)
4203 Feld[x][y] = (IS_RND_GATE_GRAY(element) ?
4204 element - EL_GATE_1_GRAY + EL_GATE_1_GRAY_ACTIVE :
4205 IS_EM_GATE_GRAY(element) ?
4206 element - EL_EM_GATE_1_GRAY + EL_EM_GATE_1_GRAY_ACTIVE :
4207 IS_EMC_GATE_GRAY(element) ?
4208 element - EL_EMC_GATE_5_GRAY + EL_EMC_GATE_5_GRAY_ACTIVE :
4210 DrawLevelField(x, y);
4212 else if (IS_GATE_GRAY_ACTIVE(element) &&
4213 game.magnify_time_left == 0)
4215 Feld[x][y] = (IS_RND_GATE_GRAY_ACTIVE(element) ?
4216 element - EL_GATE_1_GRAY_ACTIVE + EL_GATE_1_GRAY :
4217 IS_EM_GATE_GRAY_ACTIVE(element) ?
4218 element - EL_EM_GATE_1_GRAY_ACTIVE + EL_EM_GATE_1_GRAY :
4219 IS_EMC_GATE_GRAY_ACTIVE(element) ?
4220 element - EL_EMC_GATE_5_GRAY_ACTIVE + EL_EMC_GATE_5_GRAY :
4222 DrawLevelField(x, y);
4227 static void ToggleLightSwitch(int x, int y)
4229 int element = Feld[x][y];
4231 game.light_time_left =
4232 (element == EL_LIGHT_SWITCH ?
4233 level.time_light * FRAMES_PER_SECOND : 0);
4235 RedrawAllLightSwitchesAndInvisibleElements();
4238 static void ActivateTimegateSwitch(int x, int y)
4242 game.timegate_time_left = level.time_timegate * FRAMES_PER_SECOND;
4245 SCAN_PLAYFIELD(xx, yy)
4247 for (yy = 0; yy < lev_fieldy; yy++) for (xx = 0; xx < lev_fieldx; xx++)
4250 int element = Feld[xx][yy];
4252 if (element == EL_TIMEGATE_CLOSED ||
4253 element == EL_TIMEGATE_CLOSING)
4255 Feld[xx][yy] = EL_TIMEGATE_OPENING;
4256 PlayLevelSound(xx, yy, SND_TIMEGATE_OPENING);
4260 else if (element == EL_TIMEGATE_SWITCH_ACTIVE)
4262 Feld[xx][yy] = EL_TIMEGATE_SWITCH;
4263 DrawLevelField(xx, yy);
4269 Feld[x][y] = EL_TIMEGATE_SWITCH_ACTIVE;
4272 void Impact(int x, int y)
4274 boolean last_line = (y == lev_fieldy - 1);
4275 boolean object_hit = FALSE;
4276 boolean impact = (last_line || object_hit);
4277 int element = Feld[x][y];
4278 int smashed = EL_STEELWALL;
4280 if (!last_line) /* check if element below was hit */
4282 if (Feld[x][y + 1] == EL_PLAYER_IS_LEAVING)
4285 object_hit = (!IS_FREE(x, y + 1) && (!IS_MOVING(x, y + 1) ||
4286 MovDir[x][y + 1] != MV_DOWN ||
4287 MovPos[x][y + 1] <= TILEY / 2));
4289 /* do not smash moving elements that left the smashed field in time */
4290 if (game.engine_version >= VERSION_IDENT(2,2,0,7) && IS_MOVING(x, y + 1) &&
4291 ABS(MovPos[x][y + 1] + getElementMoveStepsize(x, y + 1)) >= TILEX)
4294 #if USE_QUICKSAND_IMPACT_BUGFIX
4295 if (Feld[x][y + 1] == EL_QUICKSAND_EMPTYING && object_hit == FALSE)
4297 RemoveMovingField(x, y + 1);
4298 Feld[x][y + 1] = EL_QUICKSAND_EMPTY;
4299 Feld[x][y + 2] = EL_ROCK;
4300 DrawLevelField(x, y + 2);
4307 smashed = MovingOrBlocked2Element(x, y + 1);
4309 impact = (last_line || object_hit);
4312 if (!last_line && smashed == EL_ACID) /* element falls into acid */
4314 SplashAcid(x, y + 1);
4318 /* !!! not sufficient for all cases -- see EL_PEARL below !!! */
4319 /* only reset graphic animation if graphic really changes after impact */
4321 el_act_dir2img(element, GfxAction[x][y], MV_DOWN) != el2img(element))
4323 ResetGfxAnimation(x, y);
4324 DrawLevelField(x, y);
4327 if (impact && CAN_EXPLODE_IMPACT(element))
4332 else if (impact && element == EL_PEARL)
4334 ResetGfxAnimation(x, y);
4336 Feld[x][y] = EL_PEARL_BREAKING;
4337 PlayLevelSound(x, y, SND_PEARL_BREAKING);
4340 else if (impact && CheckElementChange(x, y, element, smashed, CE_IMPACT))
4342 PlayLevelSoundElementAction(x, y, element, ACTION_IMPACT);
4347 if (impact && element == EL_AMOEBA_DROP)
4349 if (object_hit && IS_PLAYER(x, y + 1))
4350 KillPlayerUnlessEnemyProtected(x, y + 1);
4351 else if (object_hit && smashed == EL_PENGUIN)
4355 Feld[x][y] = EL_AMOEBA_GROWING;
4356 Store[x][y] = EL_AMOEBA_WET;
4358 ResetRandomAnimationValue(x, y);
4363 if (object_hit) /* check which object was hit */
4365 if (CAN_PASS_MAGIC_WALL(element) &&
4366 (smashed == EL_MAGIC_WALL ||
4367 smashed == EL_BD_MAGIC_WALL))
4370 int activated_magic_wall =
4371 (smashed == EL_MAGIC_WALL ? EL_MAGIC_WALL_ACTIVE :
4372 EL_BD_MAGIC_WALL_ACTIVE);
4374 /* activate magic wall / mill */
4376 SCAN_PLAYFIELD(xx, yy)
4378 for (yy = 0; yy < lev_fieldy; yy++) for (xx = 0; xx < lev_fieldx; xx++)
4380 if (Feld[xx][yy] == smashed)
4381 Feld[xx][yy] = activated_magic_wall;
4383 game.magic_wall_time_left = level.time_magic_wall * FRAMES_PER_SECOND;
4384 game.magic_wall_active = TRUE;
4386 PlayLevelSound(x, y, (smashed == EL_MAGIC_WALL ?
4387 SND_MAGIC_WALL_ACTIVATING :
4388 SND_BD_MAGIC_WALL_ACTIVATING));
4391 if (IS_PLAYER(x, y + 1))
4393 if (CAN_SMASH_PLAYER(element))
4395 KillPlayerUnlessEnemyProtected(x, y + 1);
4399 else if (smashed == EL_PENGUIN)
4401 if (CAN_SMASH_PLAYER(element))
4407 else if (element == EL_BD_DIAMOND)
4409 if (IS_CLASSIC_ENEMY(smashed) && IS_BD_ELEMENT(smashed))
4415 else if (((element == EL_SP_INFOTRON ||
4416 element == EL_SP_ZONK) &&
4417 (smashed == EL_SP_SNIKSNAK ||
4418 smashed == EL_SP_ELECTRON ||
4419 smashed == EL_SP_DISK_ORANGE)) ||
4420 (element == EL_SP_INFOTRON &&
4421 smashed == EL_SP_DISK_YELLOW))
4426 else if (CAN_SMASH_EVERYTHING(element))
4428 if (IS_CLASSIC_ENEMY(smashed) ||
4429 CAN_EXPLODE_SMASHED(smashed))
4434 else if (!IS_MOVING(x, y + 1) && !IS_BLOCKED(x, y + 1))
4436 if (smashed == EL_LAMP ||
4437 smashed == EL_LAMP_ACTIVE)
4442 else if (smashed == EL_NUT)
4444 Feld[x][y + 1] = EL_NUT_BREAKING;
4445 PlayLevelSound(x, y, SND_NUT_BREAKING);
4446 RaiseScoreElement(EL_NUT);
4449 else if (smashed == EL_PEARL)
4451 ResetGfxAnimation(x, y);
4453 Feld[x][y + 1] = EL_PEARL_BREAKING;
4454 PlayLevelSound(x, y, SND_PEARL_BREAKING);
4457 else if (smashed == EL_DIAMOND)
4459 Feld[x][y + 1] = EL_DIAMOND_BREAKING;
4460 PlayLevelSound(x, y, SND_DIAMOND_BREAKING);
4463 else if (IS_BELT_SWITCH(smashed))
4465 ToggleBeltSwitch(x, y + 1);
4467 else if (smashed == EL_SWITCHGATE_SWITCH_UP ||
4468 smashed == EL_SWITCHGATE_SWITCH_DOWN)
4470 ToggleSwitchgateSwitch(x, y + 1);
4472 else if (smashed == EL_LIGHT_SWITCH ||
4473 smashed == EL_LIGHT_SWITCH_ACTIVE)
4475 ToggleLightSwitch(x, y + 1);
4480 TestIfElementSmashesCustomElement(x, y, MV_DOWN);
4483 CheckElementChange(x, y + 1, smashed, element, CE_SMASHED);
4485 CheckElementChangeBySide(x, y + 1, smashed, element,
4486 CE_SWITCHED, CH_SIDE_TOP);
4487 CheckTriggeredElementChangeBySide(x, y + 1, smashed, CE_SWITCH_OF_X,
4493 CheckElementChange(x, y + 1, smashed, element, CE_SMASHED);
4498 /* play sound of magic wall / mill */
4500 (Feld[x][y + 1] == EL_MAGIC_WALL_ACTIVE ||
4501 Feld[x][y + 1] == EL_BD_MAGIC_WALL_ACTIVE))
4503 if (Feld[x][y + 1] == EL_MAGIC_WALL_ACTIVE)
4504 PlayLevelSound(x, y, SND_MAGIC_WALL_FILLING);
4505 else if (Feld[x][y + 1] == EL_BD_MAGIC_WALL_ACTIVE)
4506 PlayLevelSound(x, y, SND_BD_MAGIC_WALL_FILLING);
4511 /* play sound of object that hits the ground */
4512 if (last_line || object_hit)
4513 PlayLevelSoundElementAction(x, y, element, ACTION_IMPACT);
4516 inline static void TurnRoundExt(int x, int y)
4528 { 0, 0 }, { 0, 0 }, { 0, 0 },
4533 int left, right, back;
4537 { MV_DOWN, MV_UP, MV_RIGHT },
4538 { MV_UP, MV_DOWN, MV_LEFT },
4540 { MV_LEFT, MV_RIGHT, MV_DOWN },
4544 { MV_RIGHT, MV_LEFT, MV_UP }
4547 int element = Feld[x][y];
4548 int move_pattern = element_info[element].move_pattern;
4550 int old_move_dir = MovDir[x][y];
4551 int left_dir = turn[old_move_dir].left;
4552 int right_dir = turn[old_move_dir].right;
4553 int back_dir = turn[old_move_dir].back;
4555 int left_dx = move_xy[left_dir].dx, left_dy = move_xy[left_dir].dy;
4556 int right_dx = move_xy[right_dir].dx, right_dy = move_xy[right_dir].dy;
4557 int move_dx = move_xy[old_move_dir].dx, move_dy = move_xy[old_move_dir].dy;
4558 int back_dx = move_xy[back_dir].dx, back_dy = move_xy[back_dir].dy;
4560 int left_x = x + left_dx, left_y = y + left_dy;
4561 int right_x = x + right_dx, right_y = y + right_dy;
4562 int move_x = x + move_dx, move_y = y + move_dy;
4566 if (element == EL_BUG || element == EL_BD_BUTTERFLY)
4568 TestIfBadThingTouchesOtherBadThing(x, y);
4570 if (ENEMY_CAN_ENTER_FIELD(element, right_x, right_y))
4571 MovDir[x][y] = right_dir;
4572 else if (!ENEMY_CAN_ENTER_FIELD(element, move_x, move_y))
4573 MovDir[x][y] = left_dir;
4575 if (element == EL_BUG && MovDir[x][y] != old_move_dir)
4577 else if (element == EL_BD_BUTTERFLY) /* && MovDir[x][y] == left_dir) */
4580 else if (element == EL_SPACESHIP || element == EL_BD_FIREFLY)
4582 TestIfBadThingTouchesOtherBadThing(x, y);
4584 if (ENEMY_CAN_ENTER_FIELD(element, left_x, left_y))
4585 MovDir[x][y] = left_dir;
4586 else if (!ENEMY_CAN_ENTER_FIELD(element, move_x, move_y))
4587 MovDir[x][y] = right_dir;
4589 if (element == EL_SPACESHIP && MovDir[x][y] != old_move_dir)
4591 else if (element == EL_BD_FIREFLY) /* && MovDir[x][y] == right_dir) */
4594 else if (element == EL_SP_SNIKSNAK || element == EL_SP_ELECTRON)
4596 TestIfBadThingTouchesOtherBadThing(x, y);
4598 if (ELEMENT_CAN_ENTER_FIELD_BASE_4(element, left_x, left_y, 0))
4599 MovDir[x][y] = left_dir;
4600 else if (!ELEMENT_CAN_ENTER_FIELD_BASE_4(element, move_x, move_y, 0))
4601 MovDir[x][y] = right_dir;
4603 if (MovDir[x][y] != old_move_dir)
4606 else if (element == EL_YAMYAM)
4608 boolean can_turn_left = YAMYAM_CAN_ENTER_FIELD(element, left_x, left_y);
4609 boolean can_turn_right = YAMYAM_CAN_ENTER_FIELD(element, right_x, right_y);
4611 if (can_turn_left && can_turn_right)
4612 MovDir[x][y] = (RND(3) ? (RND(2) ? left_dir : right_dir) : back_dir);
4613 else if (can_turn_left)
4614 MovDir[x][y] = (RND(2) ? left_dir : back_dir);
4615 else if (can_turn_right)
4616 MovDir[x][y] = (RND(2) ? right_dir : back_dir);
4618 MovDir[x][y] = back_dir;
4620 MovDelay[x][y] = 16 + 16 * RND(3);
4622 else if (element == EL_DARK_YAMYAM)
4624 boolean can_turn_left = DARK_YAMYAM_CAN_ENTER_FIELD(element,
4626 boolean can_turn_right = DARK_YAMYAM_CAN_ENTER_FIELD(element,
4629 if (can_turn_left && can_turn_right)
4630 MovDir[x][y] = (RND(3) ? (RND(2) ? left_dir : right_dir) : back_dir);
4631 else if (can_turn_left)
4632 MovDir[x][y] = (RND(2) ? left_dir : back_dir);
4633 else if (can_turn_right)
4634 MovDir[x][y] = (RND(2) ? right_dir : back_dir);
4636 MovDir[x][y] = back_dir;
4638 MovDelay[x][y] = 16 + 16 * RND(3);
4640 else if (element == EL_PACMAN)
4642 boolean can_turn_left = PACMAN_CAN_ENTER_FIELD(element, left_x, left_y);
4643 boolean can_turn_right = PACMAN_CAN_ENTER_FIELD(element, right_x, right_y);
4645 if (can_turn_left && can_turn_right)
4646 MovDir[x][y] = (RND(3) ? (RND(2) ? left_dir : right_dir) : back_dir);
4647 else if (can_turn_left)
4648 MovDir[x][y] = (RND(2) ? left_dir : back_dir);
4649 else if (can_turn_right)
4650 MovDir[x][y] = (RND(2) ? right_dir : back_dir);
4652 MovDir[x][y] = back_dir;
4654 MovDelay[x][y] = 6 + RND(40);
4656 else if (element == EL_PIG)
4658 boolean can_turn_left = PIG_CAN_ENTER_FIELD(element, left_x, left_y);
4659 boolean can_turn_right = PIG_CAN_ENTER_FIELD(element, right_x, right_y);
4660 boolean can_move_on = PIG_CAN_ENTER_FIELD(element, move_x, move_y);
4661 boolean should_turn_left, should_turn_right, should_move_on;
4663 int rnd = RND(rnd_value);
4665 should_turn_left = (can_turn_left &&
4667 IN_LEV_FIELD_AND_NOT_FREE(x + back_dx + left_dx,
4668 y + back_dy + left_dy)));
4669 should_turn_right = (can_turn_right &&
4671 IN_LEV_FIELD_AND_NOT_FREE(x + back_dx + right_dx,
4672 y + back_dy + right_dy)));
4673 should_move_on = (can_move_on &&
4676 IN_LEV_FIELD_AND_NOT_FREE(x + move_dx + left_dx,
4677 y + move_dy + left_dy) ||
4678 IN_LEV_FIELD_AND_NOT_FREE(x + move_dx + right_dx,
4679 y + move_dy + right_dy)));
4681 if (should_turn_left || should_turn_right || should_move_on)
4683 if (should_turn_left && should_turn_right && should_move_on)
4684 MovDir[x][y] = (rnd < rnd_value / 3 ? left_dir :
4685 rnd < 2 * rnd_value / 3 ? right_dir :
4687 else if (should_turn_left && should_turn_right)
4688 MovDir[x][y] = (rnd < rnd_value / 2 ? left_dir : right_dir);
4689 else if (should_turn_left && should_move_on)
4690 MovDir[x][y] = (rnd < rnd_value / 2 ? left_dir : old_move_dir);
4691 else if (should_turn_right && should_move_on)
4692 MovDir[x][y] = (rnd < rnd_value / 2 ? right_dir : old_move_dir);
4693 else if (should_turn_left)
4694 MovDir[x][y] = left_dir;
4695 else if (should_turn_right)
4696 MovDir[x][y] = right_dir;
4697 else if (should_move_on)
4698 MovDir[x][y] = old_move_dir;
4700 else if (can_move_on && rnd > rnd_value / 8)
4701 MovDir[x][y] = old_move_dir;
4702 else if (can_turn_left && can_turn_right)
4703 MovDir[x][y] = (rnd < rnd_value / 2 ? left_dir : right_dir);
4704 else if (can_turn_left && rnd > rnd_value / 8)
4705 MovDir[x][y] = left_dir;
4706 else if (can_turn_right && rnd > rnd_value/8)
4707 MovDir[x][y] = right_dir;
4709 MovDir[x][y] = back_dir;
4711 xx = x + move_xy[MovDir[x][y]].dx;
4712 yy = y + move_xy[MovDir[x][y]].dy;
4714 if (!IN_LEV_FIELD(xx, yy) ||
4715 (!IS_FREE(xx, yy) && !IS_FOOD_PIG(Feld[xx][yy])))
4716 MovDir[x][y] = old_move_dir;
4720 else if (element == EL_DRAGON)
4722 boolean can_turn_left = DRAGON_CAN_ENTER_FIELD(element, left_x, left_y);
4723 boolean can_turn_right = DRAGON_CAN_ENTER_FIELD(element, right_x, right_y);
4724 boolean can_move_on = DRAGON_CAN_ENTER_FIELD(element, move_x, move_y);
4726 int rnd = RND(rnd_value);
4728 if (can_move_on && rnd > rnd_value / 8)
4729 MovDir[x][y] = old_move_dir;
4730 else if (can_turn_left && can_turn_right)
4731 MovDir[x][y] = (rnd < rnd_value / 2 ? left_dir : right_dir);
4732 else if (can_turn_left && rnd > rnd_value / 8)
4733 MovDir[x][y] = left_dir;
4734 else if (can_turn_right && rnd > rnd_value / 8)
4735 MovDir[x][y] = right_dir;
4737 MovDir[x][y] = back_dir;
4739 xx = x + move_xy[MovDir[x][y]].dx;
4740 yy = y + move_xy[MovDir[x][y]].dy;
4742 if (!IN_LEV_FIELD_AND_IS_FREE(xx, yy))
4743 MovDir[x][y] = old_move_dir;
4747 else if (element == EL_MOLE)
4749 boolean can_move_on =
4750 (MOLE_CAN_ENTER_FIELD(element, move_x, move_y,
4751 IS_AMOEBOID(Feld[move_x][move_y]) ||
4752 Feld[move_x][move_y] == EL_AMOEBA_SHRINKING));
4755 boolean can_turn_left =
4756 (MOLE_CAN_ENTER_FIELD(element, left_x, left_y,
4757 IS_AMOEBOID(Feld[left_x][left_y])));
4759 boolean can_turn_right =
4760 (MOLE_CAN_ENTER_FIELD(element, right_x, right_y,
4761 IS_AMOEBOID(Feld[right_x][right_y])));
4763 if (can_turn_left && can_turn_right)
4764 MovDir[x][y] = (RND(2) ? left_dir : right_dir);
4765 else if (can_turn_left)
4766 MovDir[x][y] = left_dir;
4768 MovDir[x][y] = right_dir;
4771 if (MovDir[x][y] != old_move_dir)
4774 else if (element == EL_BALLOON)
4776 MovDir[x][y] = game.wind_direction;
4779 else if (element == EL_SPRING)
4781 #if USE_NEW_SPRING_BUMPER
4782 if (MovDir[x][y] & MV_HORIZONTAL)
4784 if (SPRING_CAN_BUMP_FROM_FIELD(move_x, move_y) &&
4785 !SPRING_CAN_ENTER_FIELD(element, x, y + 1))
4787 Feld[move_x][move_y] = EL_EMC_SPRING_BUMPER_ACTIVE;
4788 ResetGfxAnimation(move_x, move_y);
4789 DrawLevelField(move_x, move_y);
4791 MovDir[x][y] = back_dir;
4793 else if (!SPRING_CAN_ENTER_FIELD(element, move_x, move_y) ||
4794 SPRING_CAN_ENTER_FIELD(element, x, y + 1))
4795 MovDir[x][y] = MV_NONE;
4798 if (MovDir[x][y] & MV_HORIZONTAL &&
4799 (!SPRING_CAN_ENTER_FIELD(element, move_x, move_y) ||
4800 SPRING_CAN_ENTER_FIELD(element, x, y + 1)))
4801 MovDir[x][y] = MV_NONE;
4806 else if (element == EL_ROBOT ||
4807 element == EL_SATELLITE ||
4808 element == EL_PENGUIN ||
4809 element == EL_EMC_ANDROID)
4811 int attr_x = -1, attr_y = -1;
4822 for (i = 0; i < MAX_PLAYERS; i++)
4824 struct PlayerInfo *player = &stored_player[i];
4825 int jx = player->jx, jy = player->jy;
4827 if (!player->active)
4831 ABS(jx - x) + ABS(jy - y) < ABS(attr_x - x) + ABS(attr_y - y))
4839 if (element == EL_ROBOT && ZX >= 0 && ZY >= 0 &&
4840 (Feld[ZX][ZY] == EL_ROBOT_WHEEL_ACTIVE ||
4841 game.engine_version < VERSION_IDENT(3,1,0,0)))
4847 if (element == EL_PENGUIN)
4850 static int xy[4][2] =
4858 for (i = 0; i < NUM_DIRECTIONS; i++)
4860 int ex = x + xy[i][0];
4861 int ey = y + xy[i][1];
4863 if (IN_LEV_FIELD(ex, ey) && Feld[ex][ey] == EL_EXIT_OPEN)
4872 MovDir[x][y] = MV_NONE;
4874 MovDir[x][y] |= (AllPlayersGone ? MV_RIGHT : MV_LEFT);
4875 else if (attr_x > x)
4876 MovDir[x][y] |= (AllPlayersGone ? MV_LEFT : MV_RIGHT);
4878 MovDir[x][y] |= (AllPlayersGone ? MV_DOWN : MV_UP);
4879 else if (attr_y > y)
4880 MovDir[x][y] |= (AllPlayersGone ? MV_UP : MV_DOWN);
4882 if (element == EL_ROBOT)
4886 if (MovDir[x][y] & MV_HORIZONTAL && MovDir[x][y] & MV_VERTICAL)
4887 MovDir[x][y] &= (RND(2) ? MV_HORIZONTAL : MV_VERTICAL);
4888 Moving2Blocked(x, y, &newx, &newy);
4890 if (IN_LEV_FIELD(newx, newy) && IS_FREE_OR_PLAYER(newx, newy))
4891 MovDelay[x][y] = 8 + 8 * !RND(3);
4893 MovDelay[x][y] = 16;
4895 else if (element == EL_PENGUIN)
4901 if (MovDir[x][y] & MV_HORIZONTAL && MovDir[x][y] & MV_VERTICAL)
4903 boolean first_horiz = RND(2);
4904 int new_move_dir = MovDir[x][y];
4907 new_move_dir & (first_horiz ? MV_HORIZONTAL : MV_VERTICAL);
4908 Moving2Blocked(x, y, &newx, &newy);
4910 if (PENGUIN_CAN_ENTER_FIELD(element, newx, newy))
4914 new_move_dir & (!first_horiz ? MV_HORIZONTAL : MV_VERTICAL);
4915 Moving2Blocked(x, y, &newx, &newy);
4917 if (PENGUIN_CAN_ENTER_FIELD(element, newx, newy))
4920 MovDir[x][y] = old_move_dir;
4924 else if (element == EL_SATELLITE)
4930 if (MovDir[x][y] & MV_HORIZONTAL && MovDir[x][y] & MV_VERTICAL)
4932 boolean first_horiz = RND(2);
4933 int new_move_dir = MovDir[x][y];
4936 new_move_dir & (first_horiz ? MV_HORIZONTAL : MV_VERTICAL);
4937 Moving2Blocked(x, y, &newx, &newy);
4939 if (SATELLITE_CAN_ENTER_FIELD(newx, newy))
4943 new_move_dir & (!first_horiz ? MV_HORIZONTAL : MV_VERTICAL);
4944 Moving2Blocked(x, y, &newx, &newy);
4946 if (SATELLITE_CAN_ENTER_FIELD(newx, newy))
4949 MovDir[x][y] = old_move_dir;
4953 else if (element == EL_EMC_ANDROID)
4955 static int check_pos[16] =
4957 -1, /* 0 => (invalid) */
4958 7, /* 1 => MV_LEFT */
4959 3, /* 2 => MV_RIGHT */
4960 -1, /* 3 => (invalid) */
4962 0, /* 5 => MV_LEFT | MV_UP */
4963 2, /* 6 => MV_RIGHT | MV_UP */
4964 -1, /* 7 => (invalid) */
4965 5, /* 8 => MV_DOWN */
4966 6, /* 9 => MV_LEFT | MV_DOWN */
4967 4, /* 10 => MV_RIGHT | MV_DOWN */
4968 -1, /* 11 => (invalid) */
4969 -1, /* 12 => (invalid) */
4970 -1, /* 13 => (invalid) */
4971 -1, /* 14 => (invalid) */
4972 -1, /* 15 => (invalid) */
4980 { -1, -1, MV_LEFT | MV_UP },
4982 { +1, -1, MV_RIGHT | MV_UP },
4983 { +1, 0, MV_RIGHT },
4984 { +1, +1, MV_RIGHT | MV_DOWN },
4986 { -1, +1, MV_LEFT | MV_DOWN },
4989 int start_pos, check_order;
4990 boolean can_clone = FALSE;
4993 /* check if there is any free field around current position */
4994 for (i = 0; i < 8; i++)
4996 int newx = x + check_xy[i].dx;
4997 int newy = y + check_xy[i].dy;
4999 if (IN_LEV_FIELD_AND_IS_FREE(newx, newy))
5007 if (can_clone) /* randomly find an element to clone */
5011 start_pos = check_pos[RND(8)];
5012 check_order = (RND(2) ? -1 : +1);
5014 for (i = 0; i < 8; i++)
5016 int pos_raw = start_pos + i * check_order;
5017 int pos = (pos_raw + 8) % 8;
5018 int newx = x + check_xy[pos].dx;
5019 int newy = y + check_xy[pos].dy;
5021 if (ANDROID_CAN_CLONE_FIELD(newx, newy))
5023 element_info[element].move_leave_type = LEAVE_TYPE_LIMITED;
5024 element_info[element].move_leave_element = EL_TRIGGER_ELEMENT;
5026 Store[x][y] = Feld[newx][newy];
5035 if (can_clone) /* randomly find a direction to move */
5039 start_pos = check_pos[RND(8)];
5040 check_order = (RND(2) ? -1 : +1);
5042 for (i = 0; i < 8; i++)
5044 int pos_raw = start_pos + i * check_order;
5045 int pos = (pos_raw + 8) % 8;
5046 int newx = x + check_xy[pos].dx;
5047 int newy = y + check_xy[pos].dy;
5048 int new_move_dir = check_xy[pos].dir;
5050 if (IN_LEV_FIELD_AND_IS_FREE(newx, newy))
5052 MovDir[x][y] = new_move_dir;
5053 MovDelay[x][y] = level.android_clone_time * 8 + 1;
5062 if (can_clone) /* cloning and moving successful */
5065 /* cannot clone -- try to move towards player */
5067 start_pos = check_pos[MovDir[x][y] & 0x0f];
5068 check_order = (RND(2) ? -1 : +1);
5070 for (i = 0; i < 3; i++)
5072 /* first check start_pos, then previous/next or (next/previous) pos */
5073 int pos_raw = start_pos + (i < 2 ? i : -1) * check_order;
5074 int pos = (pos_raw + 8) % 8;
5075 int newx = x + check_xy[pos].dx;
5076 int newy = y + check_xy[pos].dy;
5077 int new_move_dir = check_xy[pos].dir;
5079 if (IS_PLAYER(newx, newy))
5082 if (ANDROID_CAN_ENTER_FIELD(element, newx, newy))
5084 MovDir[x][y] = new_move_dir;
5085 MovDelay[x][y] = level.android_move_time * 8 + 1;
5092 else if (move_pattern == MV_TURNING_LEFT ||
5093 move_pattern == MV_TURNING_RIGHT ||
5094 move_pattern == MV_TURNING_LEFT_RIGHT ||
5095 move_pattern == MV_TURNING_RIGHT_LEFT ||
5096 move_pattern == MV_TURNING_RANDOM ||
5097 move_pattern == MV_ALL_DIRECTIONS)
5099 boolean can_turn_left =
5100 CUSTOM_ELEMENT_CAN_ENTER_FIELD(element, left_x, left_y);
5101 boolean can_turn_right =
5102 CUSTOM_ELEMENT_CAN_ENTER_FIELD(element, right_x,right_y);
5104 if (element_info[element].move_stepsize == 0) /* "not moving" */
5107 if (move_pattern == MV_TURNING_LEFT)
5108 MovDir[x][y] = left_dir;
5109 else if (move_pattern == MV_TURNING_RIGHT)
5110 MovDir[x][y] = right_dir;
5111 else if (move_pattern == MV_TURNING_LEFT_RIGHT)
5112 MovDir[x][y] = (can_turn_left || !can_turn_right ? left_dir : right_dir);
5113 else if (move_pattern == MV_TURNING_RIGHT_LEFT)
5114 MovDir[x][y] = (can_turn_right || !can_turn_left ? right_dir : left_dir);
5115 else if (move_pattern == MV_TURNING_RANDOM)
5116 MovDir[x][y] = (can_turn_left && !can_turn_right ? left_dir :
5117 can_turn_right && !can_turn_left ? right_dir :
5118 RND(2) ? left_dir : right_dir);
5119 else if (can_turn_left && can_turn_right)
5120 MovDir[x][y] = (RND(3) ? (RND(2) ? left_dir : right_dir) : back_dir);
5121 else if (can_turn_left)
5122 MovDir[x][y] = (RND(2) ? left_dir : back_dir);
5123 else if (can_turn_right)
5124 MovDir[x][y] = (RND(2) ? right_dir : back_dir);
5126 MovDir[x][y] = back_dir;
5128 MovDelay[x][y] = GET_NEW_MOVE_DELAY(element);
5130 else if (move_pattern == MV_HORIZONTAL ||
5131 move_pattern == MV_VERTICAL)
5133 if (move_pattern & old_move_dir)
5134 MovDir[x][y] = back_dir;
5135 else if (move_pattern == MV_HORIZONTAL)
5136 MovDir[x][y] = (RND(2) ? MV_LEFT : MV_RIGHT);
5137 else if (move_pattern == MV_VERTICAL)
5138 MovDir[x][y] = (RND(2) ? MV_UP : MV_DOWN);
5140 MovDelay[x][y] = GET_NEW_MOVE_DELAY(element);
5142 else if (move_pattern & MV_ANY_DIRECTION)
5144 MovDir[x][y] = move_pattern;
5145 MovDelay[x][y] = GET_NEW_MOVE_DELAY(element);
5147 else if (move_pattern & MV_WIND_DIRECTION)
5149 MovDir[x][y] = game.wind_direction;
5150 MovDelay[x][y] = GET_NEW_MOVE_DELAY(element);
5152 else if (move_pattern == MV_ALONG_LEFT_SIDE)
5154 if (CUSTOM_ELEMENT_CAN_ENTER_FIELD(element, left_x, left_y))
5155 MovDir[x][y] = left_dir;
5156 else if (!CUSTOM_ELEMENT_CAN_ENTER_FIELD(element, move_x, move_y))
5157 MovDir[x][y] = right_dir;
5159 if (MovDir[x][y] != old_move_dir)
5160 MovDelay[x][y] = GET_NEW_MOVE_DELAY(element);
5162 else if (move_pattern == MV_ALONG_RIGHT_SIDE)
5164 if (CUSTOM_ELEMENT_CAN_ENTER_FIELD(element, right_x, right_y))
5165 MovDir[x][y] = right_dir;
5166 else if (!CUSTOM_ELEMENT_CAN_ENTER_FIELD(element, move_x, move_y))
5167 MovDir[x][y] = left_dir;
5169 if (MovDir[x][y] != old_move_dir)
5170 MovDelay[x][y] = GET_NEW_MOVE_DELAY(element);
5172 else if (move_pattern == MV_TOWARDS_PLAYER ||
5173 move_pattern == MV_AWAY_FROM_PLAYER)
5175 int attr_x = -1, attr_y = -1;
5177 boolean move_away = (move_pattern == MV_AWAY_FROM_PLAYER);
5188 for (i = 0; i < MAX_PLAYERS; i++)
5190 struct PlayerInfo *player = &stored_player[i];
5191 int jx = player->jx, jy = player->jy;
5193 if (!player->active)
5197 ABS(jx - x) + ABS(jy - y) < ABS(attr_x - x) + ABS(attr_y - y))
5205 MovDir[x][y] = MV_NONE;
5207 MovDir[x][y] |= (move_away ? MV_RIGHT : MV_LEFT);
5208 else if (attr_x > x)
5209 MovDir[x][y] |= (move_away ? MV_LEFT : MV_RIGHT);
5211 MovDir[x][y] |= (move_away ? MV_DOWN : MV_UP);
5212 else if (attr_y > y)
5213 MovDir[x][y] |= (move_away ? MV_UP : MV_DOWN);
5215 MovDelay[x][y] = GET_NEW_MOVE_DELAY(element);
5217 if (MovDir[x][y] & MV_HORIZONTAL && MovDir[x][y] & MV_VERTICAL)
5219 boolean first_horiz = RND(2);
5220 int new_move_dir = MovDir[x][y];
5222 if (element_info[element].move_stepsize == 0) /* "not moving" */
5224 first_horiz = (ABS(attr_x - x) >= ABS(attr_y - y));
5225 MovDir[x][y] &= (first_horiz ? MV_HORIZONTAL : MV_VERTICAL);
5231 new_move_dir & (first_horiz ? MV_HORIZONTAL : MV_VERTICAL);
5232 Moving2Blocked(x, y, &newx, &newy);
5234 if (CUSTOM_ELEMENT_CAN_ENTER_FIELD(element, newx, newy))
5238 new_move_dir & (!first_horiz ? MV_HORIZONTAL : MV_VERTICAL);
5239 Moving2Blocked(x, y, &newx, &newy);
5241 if (CUSTOM_ELEMENT_CAN_ENTER_FIELD(element, newx, newy))
5244 MovDir[x][y] = old_move_dir;
5247 else if (move_pattern == MV_WHEN_PUSHED ||
5248 move_pattern == MV_WHEN_DROPPED)
5250 if (!CUSTOM_ELEMENT_CAN_ENTER_FIELD(element, move_x, move_y))
5251 MovDir[x][y] = MV_NONE;
5255 else if (move_pattern & MV_MAZE_RUNNER_STYLE)
5257 static int test_xy[7][2] =
5267 static int test_dir[7] =
5277 boolean hunter_mode = (move_pattern == MV_MAZE_HUNTER);
5278 int move_preference = -1000000; /* start with very low preference */
5279 int new_move_dir = MV_NONE;
5280 int start_test = RND(4);
5283 for (i = 0; i < NUM_DIRECTIONS; i++)
5285 int move_dir = test_dir[start_test + i];
5286 int move_dir_preference;
5288 xx = x + test_xy[start_test + i][0];
5289 yy = y + test_xy[start_test + i][1];
5291 if (hunter_mode && IN_LEV_FIELD(xx, yy) &&
5292 (IS_PLAYER(xx, yy) || Feld[xx][yy] == EL_PLAYER_IS_LEAVING))
5294 new_move_dir = move_dir;
5299 if (!CUSTOM_ELEMENT_CAN_ENTER_FIELD(element, xx, yy))
5302 move_dir_preference = -1 * RunnerVisit[xx][yy];
5303 if (hunter_mode && PlayerVisit[xx][yy] > 0)
5304 move_dir_preference = PlayerVisit[xx][yy];
5306 if (move_dir_preference > move_preference)
5308 /* prefer field that has not been visited for the longest time */
5309 move_preference = move_dir_preference;
5310 new_move_dir = move_dir;
5312 else if (move_dir_preference == move_preference &&
5313 move_dir == old_move_dir)
5315 /* prefer last direction when all directions are preferred equally */
5316 move_preference = move_dir_preference;
5317 new_move_dir = move_dir;
5321 MovDir[x][y] = new_move_dir;
5322 if (old_move_dir != new_move_dir)
5323 MovDelay[x][y] = GET_NEW_MOVE_DELAY(element);
5327 static void TurnRound(int x, int y)
5329 int direction = MovDir[x][y];
5331 int element, graphic;
5336 GfxDir[x][y] = MovDir[x][y];
5338 if (direction != MovDir[x][y])
5342 GfxAction[x][y] = ACTION_TURNING_FROM_LEFT + MV_DIR_TO_BIT(direction);
5345 element = Feld[x][y];
5346 graphic = el_act_dir2img(element, GfxAction[x][y], GfxDir[x][y]);
5348 if (graphic_info[graphic].anim_global_sync)
5349 GfxFrame[x][y] = FrameCounter;
5350 else if (ANIM_MODE(graphic) == ANIM_CE_VALUE)
5351 GfxFrame[x][y] = CustomValue[x][y];
5352 else if (ANIM_MODE(graphic) == ANIM_CE_SCORE)
5353 GfxFrame[x][y] = element_info[element].collect_score;
5357 static boolean JustBeingPushed(int x, int y)
5361 for (i = 0; i < MAX_PLAYERS; i++)
5363 struct PlayerInfo *player = &stored_player[i];
5365 if (player->active && player->is_pushing && player->MovPos)
5367 int next_jx = player->jx + (player->jx - player->last_jx);
5368 int next_jy = player->jy + (player->jy - player->last_jy);
5370 if (x == next_jx && y == next_jy)
5378 void StartMoving(int x, int y)
5380 boolean started_moving = FALSE; /* some elements can fall _and_ move */
5381 int element = Feld[x][y];
5386 if (MovDelay[x][y] == 0)
5387 GfxAction[x][y] = ACTION_DEFAULT;
5389 if (CAN_FALL(element) && y < lev_fieldy - 1)
5391 if ((x > 0 && IS_PLAYER(x - 1, y)) ||
5392 (x < lev_fieldx - 1 && IS_PLAYER(x + 1, y)))
5393 if (JustBeingPushed(x, y))
5396 if (element == EL_QUICKSAND_FULL)
5398 if (IS_FREE(x, y + 1))
5400 InitMovingField(x, y, MV_DOWN);
5401 started_moving = TRUE;
5403 Feld[x][y] = EL_QUICKSAND_EMPTYING;
5404 Store[x][y] = EL_ROCK;
5406 PlayLevelSoundAction(x, y, ACTION_EMPTYING);
5408 else if (Feld[x][y + 1] == EL_QUICKSAND_EMPTY)
5410 if (!MovDelay[x][y])
5411 MovDelay[x][y] = TILEY + 1;
5420 Feld[x][y] = EL_QUICKSAND_EMPTY;
5421 Feld[x][y + 1] = EL_QUICKSAND_FULL;
5422 Store[x][y + 1] = Store[x][y];
5425 PlayLevelSoundAction(x, y, ACTION_FILLING);
5428 else if ((element == EL_ROCK || element == EL_BD_ROCK) &&
5429 Feld[x][y + 1] == EL_QUICKSAND_EMPTY)
5431 InitMovingField(x, y, MV_DOWN);
5432 started_moving = TRUE;
5434 Feld[x][y] = EL_QUICKSAND_FILLING;
5435 Store[x][y] = element;
5437 PlayLevelSoundAction(x, y, ACTION_FILLING);
5439 else if (element == EL_MAGIC_WALL_FULL)
5441 if (IS_FREE(x, y + 1))
5443 InitMovingField(x, y, MV_DOWN);
5444 started_moving = TRUE;
5446 Feld[x][y] = EL_MAGIC_WALL_EMPTYING;
5447 Store[x][y] = EL_CHANGED(Store[x][y]);
5449 else if (Feld[x][y + 1] == EL_MAGIC_WALL_ACTIVE)
5451 if (!MovDelay[x][y])
5452 MovDelay[x][y] = TILEY/4 + 1;
5461 Feld[x][y] = EL_MAGIC_WALL_ACTIVE;
5462 Feld[x][y + 1] = EL_MAGIC_WALL_FULL;
5463 Store[x][y + 1] = EL_CHANGED(Store[x][y]);
5467 else if (element == EL_BD_MAGIC_WALL_FULL)
5469 if (IS_FREE(x, y + 1))
5471 InitMovingField(x, y, MV_DOWN);
5472 started_moving = TRUE;
5474 Feld[x][y] = EL_BD_MAGIC_WALL_EMPTYING;
5475 Store[x][y] = EL_CHANGED2(Store[x][y]);
5477 else if (Feld[x][y + 1] == EL_BD_MAGIC_WALL_ACTIVE)
5479 if (!MovDelay[x][y])
5480 MovDelay[x][y] = TILEY/4 + 1;
5489 Feld[x][y] = EL_BD_MAGIC_WALL_ACTIVE;
5490 Feld[x][y + 1] = EL_BD_MAGIC_WALL_FULL;
5491 Store[x][y + 1] = EL_CHANGED2(Store[x][y]);
5495 else if (CAN_PASS_MAGIC_WALL(element) &&
5496 (Feld[x][y + 1] == EL_MAGIC_WALL_ACTIVE ||
5497 Feld[x][y + 1] == EL_BD_MAGIC_WALL_ACTIVE))
5499 InitMovingField(x, y, MV_DOWN);
5500 started_moving = TRUE;
5503 (Feld[x][y + 1] == EL_MAGIC_WALL_ACTIVE ? EL_MAGIC_WALL_FILLING :
5504 EL_BD_MAGIC_WALL_FILLING);
5505 Store[x][y] = element;
5507 else if (CAN_FALL(element) && Feld[x][y + 1] == EL_ACID)
5509 SplashAcid(x, y + 1);
5511 InitMovingField(x, y, MV_DOWN);
5512 started_moving = TRUE;
5514 Store[x][y] = EL_ACID;
5516 else if ((game.engine_version >= VERSION_IDENT(3,1,0,0) &&
5517 CheckCollision[x][y] && !IS_FREE(x, y + 1)) ||
5519 (game.engine_version >= VERSION_IDENT(3,0,7,0) &&
5520 CAN_FALL(element) && WasJustFalling[x][y] &&
5521 (Feld[x][y + 1] == EL_BLOCKED || IS_PLAYER(x, y + 1))) ||
5523 (game.engine_version < VERSION_IDENT(2,2,0,7) &&
5524 CAN_FALL(element) && WasJustMoving[x][y] && !Pushed[x][y + 1] &&
5525 (Feld[x][y + 1] == EL_BLOCKED)))
5527 /* this is needed for a special case not covered by calling "Impact()"
5528 from "ContinueMoving()": if an element moves to a tile directly below
5529 another element which was just falling on that tile (which was empty
5530 in the previous frame), the falling element above would just stop
5531 instead of smashing the element below (in previous version, the above
5532 element was just checked for "moving" instead of "falling", resulting
5533 in incorrect smashes caused by horizontal movement of the above
5534 element; also, the case of the player being the element to smash was
5535 simply not covered here... :-/ ) */
5537 CheckCollision[x][y] = 0;
5541 else if (IS_FREE(x, y + 1) && element == EL_SPRING && level.use_spring_bug)
5543 if (MovDir[x][y] == MV_NONE)
5545 InitMovingField(x, y, MV_DOWN);
5546 started_moving = TRUE;
5549 else if (IS_FREE(x, y + 1) || Feld[x][y + 1] == EL_DIAMOND_BREAKING)
5551 if (WasJustFalling[x][y]) /* prevent animation from being restarted */
5552 MovDir[x][y] = MV_DOWN;
5554 InitMovingField(x, y, MV_DOWN);
5555 started_moving = TRUE;
5557 else if (element == EL_AMOEBA_DROP)
5559 Feld[x][y] = EL_AMOEBA_GROWING;
5560 Store[x][y] = EL_AMOEBA_WET;
5562 else if (((IS_SLIPPERY(Feld[x][y + 1]) && !IS_PLAYER(x, y + 1)) ||
5563 (IS_EM_SLIPPERY_WALL(Feld[x][y + 1]) && IS_GEM(element))) &&
5564 !IS_FALLING(x, y + 1) && !WasJustMoving[x][y + 1] &&
5565 element != EL_DX_SUPABOMB && element != EL_SP_DISK_ORANGE)
5567 boolean can_fall_left = (x > 0 && IS_FREE(x - 1, y) &&
5568 (IS_FREE(x - 1, y + 1) ||
5569 Feld[x - 1][y + 1] == EL_ACID));
5570 boolean can_fall_right = (x < lev_fieldx - 1 && IS_FREE(x + 1, y) &&
5571 (IS_FREE(x + 1, y + 1) ||
5572 Feld[x + 1][y + 1] == EL_ACID));
5573 boolean can_fall_any = (can_fall_left || can_fall_right);
5574 boolean can_fall_both = (can_fall_left && can_fall_right);
5575 int slippery_type = element_info[Feld[x][y + 1]].slippery_type;
5577 #if USE_NEW_ALL_SLIPPERY
5578 if (can_fall_any && slippery_type != SLIPPERY_ANY_RANDOM)
5580 if (slippery_type == SLIPPERY_ANY_LEFT_RIGHT && can_fall_both)
5581 can_fall_right = FALSE;
5582 else if (slippery_type == SLIPPERY_ANY_RIGHT_LEFT && can_fall_both)
5583 can_fall_left = FALSE;
5584 else if (slippery_type == SLIPPERY_ONLY_LEFT)
5585 can_fall_right = FALSE;
5586 else if (slippery_type == SLIPPERY_ONLY_RIGHT)
5587 can_fall_left = FALSE;
5589 can_fall_any = (can_fall_left || can_fall_right);
5590 can_fall_both = FALSE;
5593 if (can_fall_any && IS_CUSTOM_ELEMENT(Feld[x][y + 1]))
5595 if (slippery_type == SLIPPERY_ONLY_LEFT)
5596 can_fall_right = FALSE;
5597 else if (slippery_type == SLIPPERY_ONLY_RIGHT)
5598 can_fall_left = FALSE;
5599 else if (slippery_type == SLIPPERY_ANY_LEFT_RIGHT && can_fall_both)
5600 can_fall_right = FALSE;
5601 else if (slippery_type == SLIPPERY_ANY_RIGHT_LEFT && can_fall_both)
5602 can_fall_left = FALSE;
5604 can_fall_any = (can_fall_left || can_fall_right);
5605 can_fall_both = (can_fall_left && can_fall_right);
5609 #if USE_NEW_ALL_SLIPPERY
5611 #if USE_NEW_SP_SLIPPERY
5612 /* !!! better use the same properties as for custom elements here !!! */
5613 else if (game.engine_version >= VERSION_IDENT(3,1,1,0) &&
5614 can_fall_both && IS_SP_ELEMENT(Feld[x][y + 1]))
5616 can_fall_right = FALSE; /* slip down on left side */
5617 can_fall_both = FALSE;
5622 #if USE_NEW_ALL_SLIPPERY
5625 if (element == EL_BD_ROCK || element == EL_BD_DIAMOND)
5626 can_fall_right = FALSE; /* slip down on left side */
5628 can_fall_left = !(can_fall_right = RND(2));
5630 can_fall_both = FALSE;
5635 if (game.emulation == EMU_BOULDERDASH ||
5636 element == EL_BD_ROCK || element == EL_BD_DIAMOND)
5637 can_fall_right = FALSE; /* slip down on left side */
5639 can_fall_left = !(can_fall_right = RND(2));
5641 can_fall_both = FALSE;
5647 /* if not determined otherwise, prefer left side for slipping down */
5648 InitMovingField(x, y, can_fall_left ? MV_LEFT : MV_RIGHT);
5649 started_moving = TRUE;
5653 else if (IS_BELT_ACTIVE(Feld[x][y + 1]) && !CAN_MOVE(element))
5655 else if (IS_BELT_ACTIVE(Feld[x][y + 1]))
5658 boolean left_is_free = (x > 0 && IS_FREE(x - 1, y));
5659 boolean right_is_free = (x < lev_fieldx - 1 && IS_FREE(x + 1, y));
5660 int belt_nr = getBeltNrFromBeltActiveElement(Feld[x][y + 1]);
5661 int belt_dir = game.belt_dir[belt_nr];
5663 if ((belt_dir == MV_LEFT && left_is_free) ||
5664 (belt_dir == MV_RIGHT && right_is_free))
5666 int nextx = (belt_dir == MV_LEFT ? x - 1 : x + 1);
5668 InitMovingField(x, y, belt_dir);
5669 started_moving = TRUE;
5671 Pushed[x][y] = TRUE;
5672 Pushed[nextx][y] = TRUE;
5674 GfxAction[x][y] = ACTION_DEFAULT;
5678 MovDir[x][y] = 0; /* if element was moving, stop it */
5683 /* not "else if" because of elements that can fall and move (EL_SPRING) */
5685 if (CAN_MOVE(element) && !started_moving && MovDir[x][y] != MV_NONE)
5687 if (CAN_MOVE(element) && !started_moving)
5690 int move_pattern = element_info[element].move_pattern;
5695 if (MovDir[x][y] == MV_NONE)
5697 printf("StartMoving(): %d,%d: element %d ['%s'] not moving\n",
5698 x, y, element, element_info[element].token_name);
5699 printf("StartMoving(): This should never happen!\n");
5704 Moving2Blocked(x, y, &newx, &newy);
5706 if (IS_PUSHABLE(element) && JustBeingPushed(x, y))
5709 if (game.engine_version >= VERSION_IDENT(3,1,0,0) &&
5710 CheckCollision[x][y] && !IN_LEV_FIELD_AND_IS_FREE(newx, newy))
5712 WasJustMoving[x][y] = 0;
5713 CheckCollision[x][y] = 0;
5715 TestIfElementHitsCustomElement(x, y, MovDir[x][y]);
5717 if (Feld[x][y] != element) /* element has changed */
5721 if (!MovDelay[x][y]) /* start new movement phase */
5723 /* all objects that can change their move direction after each step
5724 (YAMYAM, DARK_YAMYAM and PACMAN go straight until they hit a wall */
5726 if (element != EL_YAMYAM &&
5727 element != EL_DARK_YAMYAM &&
5728 element != EL_PACMAN &&
5729 !(move_pattern & MV_ANY_DIRECTION) &&
5730 move_pattern != MV_TURNING_LEFT &&
5731 move_pattern != MV_TURNING_RIGHT &&
5732 move_pattern != MV_TURNING_LEFT_RIGHT &&
5733 move_pattern != MV_TURNING_RIGHT_LEFT &&
5734 move_pattern != MV_TURNING_RANDOM)
5738 if (MovDelay[x][y] && (element == EL_BUG ||
5739 element == EL_SPACESHIP ||
5740 element == EL_SP_SNIKSNAK ||
5741 element == EL_SP_ELECTRON ||
5742 element == EL_MOLE))
5743 DrawLevelField(x, y);
5747 if (MovDelay[x][y]) /* wait some time before next movement */
5751 if (element == EL_ROBOT ||
5752 element == EL_YAMYAM ||
5753 element == EL_DARK_YAMYAM)
5755 DrawLevelElementAnimationIfNeeded(x, y, element);
5756 PlayLevelSoundAction(x, y, ACTION_WAITING);
5758 else if (element == EL_SP_ELECTRON)
5759 DrawLevelElementAnimationIfNeeded(x, y, element);
5760 else if (element == EL_DRAGON)
5763 int dir = MovDir[x][y];
5764 int dx = (dir == MV_LEFT ? -1 : dir == MV_RIGHT ? +1 : 0);
5765 int dy = (dir == MV_UP ? -1 : dir == MV_DOWN ? +1 : 0);
5766 int graphic = (dir == MV_LEFT ? IMG_FLAMES_1_LEFT :
5767 dir == MV_RIGHT ? IMG_FLAMES_1_RIGHT :
5768 dir == MV_UP ? IMG_FLAMES_1_UP :
5769 dir == MV_DOWN ? IMG_FLAMES_1_DOWN : IMG_EMPTY);
5770 int frame = getGraphicAnimationFrame(graphic, GfxFrame[x][y]);
5772 GfxAction[x][y] = ACTION_ATTACKING;
5774 if (IS_PLAYER(x, y))
5775 DrawPlayerField(x, y);
5777 DrawLevelField(x, y);
5779 PlayLevelSoundActionIfLoop(x, y, ACTION_ATTACKING);
5781 for (i = 1; i <= 3; i++)
5783 int xx = x + i * dx;
5784 int yy = y + i * dy;
5785 int sx = SCREENX(xx);
5786 int sy = SCREENY(yy);
5787 int flame_graphic = graphic + (i - 1);
5789 if (!IN_LEV_FIELD(xx, yy) || IS_DRAGONFIRE_PROOF(Feld[xx][yy]))
5794 int flamed = MovingOrBlocked2Element(xx, yy);
5798 if (IS_CLASSIC_ENEMY(flamed) || CAN_EXPLODE_BY_DRAGONFIRE(flamed))
5800 else if (IS_MOVING(xx, yy) || IS_BLOCKED(xx, yy))
5801 RemoveMovingField(xx, yy);
5803 RemoveField(xx, yy);
5805 if (IS_CLASSIC_ENEMY(flamed) || CAN_EXPLODE_BY_DRAGONFIRE(flamed))
5808 RemoveMovingField(xx, yy);
5811 ChangeDelay[xx][yy] = 0;
5813 Feld[xx][yy] = EL_FLAMES;
5815 if (IN_SCR_FIELD(sx, sy))
5817 DrawLevelFieldCrumbledSand(xx, yy);
5818 DrawGraphic(sx, sy, flame_graphic, frame);
5823 if (Feld[xx][yy] == EL_FLAMES)
5824 Feld[xx][yy] = EL_EMPTY;
5825 DrawLevelField(xx, yy);
5830 if (MovDelay[x][y]) /* element still has to wait some time */
5832 PlayLevelSoundAction(x, y, ACTION_WAITING);
5838 /* now make next step */
5840 Moving2Blocked(x, y, &newx, &newy); /* get next screen position */
5842 if (DONT_COLLIDE_WITH(element) &&
5843 IN_LEV_FIELD(newx, newy) && IS_PLAYER(newx, newy) &&
5844 !PLAYER_ENEMY_PROTECTED(newx, newy))
5846 TestIfBadThingRunsIntoPlayer(x, y, MovDir[x][y]);
5851 else if (CAN_MOVE_INTO_ACID(element) &&
5852 IN_LEV_FIELD(newx, newy) && Feld[newx][newy] == EL_ACID &&
5853 !IS_MV_DIAGONAL(MovDir[x][y]) &&
5854 (MovDir[x][y] == MV_DOWN ||
5855 game.engine_version >= VERSION_IDENT(3,1,0,0)))
5857 SplashAcid(newx, newy);
5858 Store[x][y] = EL_ACID;
5860 else if (element == EL_PENGUIN && IN_LEV_FIELD(newx, newy))
5862 if (Feld[newx][newy] == EL_EXIT_OPEN)
5865 DrawLevelField(x, y);
5867 PlayLevelSound(newx, newy, SND_PENGUIN_PASSING);
5868 if (IN_SCR_FIELD(SCREENX(newx), SCREENY(newy)))
5869 DrawGraphicThruMask(SCREENX(newx),SCREENY(newy), el2img(element), 0);
5871 local_player->friends_still_needed--;
5872 if (!local_player->friends_still_needed &&
5873 !local_player->GameOver && AllPlayersGone)
5874 local_player->LevelSolved = local_player->GameOver = TRUE;
5878 else if (IS_FOOD_PENGUIN(Feld[newx][newy]))
5880 if (DigField(local_player, x, y, newx, newy, 0,0, DF_DIG) == MP_MOVING)
5881 DrawLevelField(newx, newy);
5883 GfxDir[x][y] = MovDir[x][y] = MV_NONE;
5885 else if (!IS_FREE(newx, newy))
5887 GfxAction[x][y] = ACTION_WAITING;
5889 if (IS_PLAYER(x, y))
5890 DrawPlayerField(x, y);
5892 DrawLevelField(x, y);
5897 else if (element == EL_PIG && IN_LEV_FIELD(newx, newy))
5899 if (IS_FOOD_PIG(Feld[newx][newy]))
5901 if (IS_MOVING(newx, newy))
5902 RemoveMovingField(newx, newy);
5905 Feld[newx][newy] = EL_EMPTY;
5906 DrawLevelField(newx, newy);
5909 PlayLevelSound(x, y, SND_PIG_DIGGING);
5911 else if (!IS_FREE(newx, newy))
5913 if (IS_PLAYER(x, y))
5914 DrawPlayerField(x, y);
5916 DrawLevelField(x, y);
5921 else if (element == EL_EMC_ANDROID && IN_LEV_FIELD(newx, newy))
5923 if (Store[x][y] != EL_EMPTY)
5925 boolean can_clone = FALSE;
5928 /* check if element to clone is still there */
5929 for (yy = y - 1; yy <= y + 1; yy++) for (xx = x - 1; xx <= x + 1; xx++)
5931 if (IN_LEV_FIELD(xx, yy) && Feld[xx][yy] == Store[x][y])
5939 /* cannot clone or target field not free anymore -- do not clone */
5940 if (!can_clone || !ANDROID_CAN_ENTER_FIELD(element, newx, newy))
5941 Store[x][y] = EL_EMPTY;
5944 if (ANDROID_CAN_ENTER_FIELD(element, newx, newy))
5946 if (IS_MV_DIAGONAL(MovDir[x][y]))
5948 int diagonal_move_dir = MovDir[x][y];
5949 int stored = Store[x][y];
5950 int change_delay = 8;
5953 /* android is moving diagonally */
5955 CreateField(x, y, EL_DIAGONAL_SHRINKING);
5957 Store[x][y] = (stored == EL_ACID ? EL_EMPTY : stored);
5958 GfxElement[x][y] = EL_EMC_ANDROID;
5959 GfxAction[x][y] = ACTION_SHRINKING;
5960 GfxDir[x][y] = diagonal_move_dir;
5961 ChangeDelay[x][y] = change_delay;
5963 graphic = el_act_dir2img(GfxElement[x][y], GfxAction[x][y],
5966 DrawLevelGraphicAnimation(x, y, graphic);
5967 PlayLevelSoundAction(x, y, ACTION_SHRINKING);
5969 if (Feld[newx][newy] == EL_ACID)
5971 SplashAcid(newx, newy);
5976 CreateField(newx, newy, EL_DIAGONAL_GROWING);
5978 Store[newx][newy] = EL_EMC_ANDROID;
5979 GfxElement[newx][newy] = EL_EMC_ANDROID;
5980 GfxAction[newx][newy] = ACTION_GROWING;
5981 GfxDir[newx][newy] = diagonal_move_dir;
5982 ChangeDelay[newx][newy] = change_delay;
5984 graphic = el_act_dir2img(GfxElement[newx][newy],
5985 GfxAction[newx][newy], GfxDir[newx][newy]);
5987 DrawLevelGraphicAnimation(newx, newy, graphic);
5988 PlayLevelSoundAction(newx, newy, ACTION_GROWING);
5994 Feld[newx][newy] = EL_EMPTY;
5995 DrawLevelField(newx, newy);
5997 PlayLevelSoundAction(x, y, ACTION_DIGGING);
6000 else if (!IS_FREE(newx, newy))
6003 if (IS_PLAYER(x, y))
6004 DrawPlayerField(x, y);
6006 DrawLevelField(x, y);
6012 else if (IS_CUSTOM_ELEMENT(element) &&
6013 CUSTOM_ELEMENT_CAN_ENTER_FIELD(element, newx, newy))
6015 int new_element = Feld[newx][newy];
6017 if (!IS_FREE(newx, newy))
6019 int action = (IS_DIGGABLE(new_element) ? ACTION_DIGGING :
6020 IS_COLLECTIBLE(new_element) ? ACTION_COLLECTING :
6023 /* no element can dig solid indestructible elements */
6024 if (IS_INDESTRUCTIBLE(new_element) &&
6025 !IS_DIGGABLE(new_element) &&
6026 !IS_COLLECTIBLE(new_element))
6029 if (AmoebaNr[newx][newy] &&
6030 (new_element == EL_AMOEBA_FULL ||
6031 new_element == EL_BD_AMOEBA ||
6032 new_element == EL_AMOEBA_GROWING))
6034 AmoebaCnt[AmoebaNr[newx][newy]]--;
6035 AmoebaCnt2[AmoebaNr[newx][newy]]--;
6038 if (IS_MOVING(newx, newy))
6039 RemoveMovingField(newx, newy);
6042 RemoveField(newx, newy);
6043 DrawLevelField(newx, newy);
6046 /* if digged element was about to explode, prevent the explosion */
6047 ExplodeField[newx][newy] = EX_TYPE_NONE;
6049 PlayLevelSoundAction(x, y, action);
6052 Store[newx][newy] = EL_EMPTY;
6054 /* this makes it possible to leave the removed element again */
6055 if (IS_EQUAL_OR_IN_GROUP(new_element, MOVE_ENTER_EL(element)))
6056 Store[newx][newy] = new_element;
6058 if (IS_EQUAL_OR_IN_GROUP(new_element, MOVE_ENTER_EL(element)))
6060 int move_leave_element = element_info[element].move_leave_element;
6062 /* this makes it possible to leave the removed element again */
6063 Store[newx][newy] = (move_leave_element == EL_TRIGGER_ELEMENT ?
6064 new_element : move_leave_element);
6068 if (move_pattern & MV_MAZE_RUNNER_STYLE)
6070 RunnerVisit[x][y] = FrameCounter;
6071 PlayerVisit[x][y] /= 8; /* expire player visit path */
6074 else if (element == EL_DRAGON && IN_LEV_FIELD(newx, newy))
6076 if (!IS_FREE(newx, newy))
6078 if (IS_PLAYER(x, y))
6079 DrawPlayerField(x, y);
6081 DrawLevelField(x, y);
6087 boolean wanna_flame = !RND(10);
6088 int dx = newx - x, dy = newy - y;
6089 int newx1 = newx + 1 * dx, newy1 = newy + 1 * dy;
6090 int newx2 = newx + 2 * dx, newy2 = newy + 2 * dy;
6091 int element1 = (IN_LEV_FIELD(newx1, newy1) ?
6092 MovingOrBlocked2Element(newx1, newy1) : EL_STEELWALL);
6093 int element2 = (IN_LEV_FIELD(newx2, newy2) ?
6094 MovingOrBlocked2Element(newx2, newy2) : EL_STEELWALL);
6097 IS_CLASSIC_ENEMY(element1) ||
6098 IS_CLASSIC_ENEMY(element2)) &&
6099 element1 != EL_DRAGON && element2 != EL_DRAGON &&
6100 element1 != EL_FLAMES && element2 != EL_FLAMES)
6102 ResetGfxAnimation(x, y);
6103 GfxAction[x][y] = ACTION_ATTACKING;
6105 if (IS_PLAYER(x, y))
6106 DrawPlayerField(x, y);
6108 DrawLevelField(x, y);
6110 PlayLevelSound(x, y, SND_DRAGON_ATTACKING);
6112 MovDelay[x][y] = 50;
6116 RemoveField(newx, newy);
6118 Feld[newx][newy] = EL_FLAMES;
6119 if (IN_LEV_FIELD(newx1, newy1) && Feld[newx1][newy1] == EL_EMPTY)
6122 RemoveField(newx1, newy1);
6124 Feld[newx1][newy1] = EL_FLAMES;
6126 if (IN_LEV_FIELD(newx2, newy2) && Feld[newx2][newy2] == EL_EMPTY)
6129 RemoveField(newx2, newy2);
6131 Feld[newx2][newy2] = EL_FLAMES;
6138 else if (element == EL_YAMYAM && IN_LEV_FIELD(newx, newy) &&
6139 Feld[newx][newy] == EL_DIAMOND)
6141 if (IS_MOVING(newx, newy))
6142 RemoveMovingField(newx, newy);
6145 Feld[newx][newy] = EL_EMPTY;
6146 DrawLevelField(newx, newy);
6149 PlayLevelSound(x, y, SND_YAMYAM_DIGGING);
6151 else if (element == EL_DARK_YAMYAM && IN_LEV_FIELD(newx, newy) &&
6152 IS_FOOD_DARK_YAMYAM(Feld[newx][newy]))
6154 if (AmoebaNr[newx][newy])
6156 AmoebaCnt2[AmoebaNr[newx][newy]]--;
6157 if (Feld[newx][newy] == EL_AMOEBA_FULL ||
6158 Feld[newx][newy] == EL_BD_AMOEBA)
6159 AmoebaCnt[AmoebaNr[newx][newy]]--;
6164 if (IS_MOVING(newx, newy) || IS_BLOCKED(newx, newy))
6166 RemoveMovingField(newx, newy);
6169 if (IS_MOVING(newx, newy))
6171 RemoveMovingField(newx, newy);
6176 Feld[newx][newy] = EL_EMPTY;
6177 DrawLevelField(newx, newy);
6180 PlayLevelSound(x, y, SND_DARK_YAMYAM_DIGGING);
6182 else if ((element == EL_PACMAN || element == EL_MOLE)
6183 && IN_LEV_FIELD(newx, newy) && IS_AMOEBOID(Feld[newx][newy]))
6185 if (AmoebaNr[newx][newy])
6187 AmoebaCnt2[AmoebaNr[newx][newy]]--;
6188 if (Feld[newx][newy] == EL_AMOEBA_FULL ||
6189 Feld[newx][newy] == EL_BD_AMOEBA)
6190 AmoebaCnt[AmoebaNr[newx][newy]]--;
6193 if (element == EL_MOLE)
6195 Feld[newx][newy] = EL_AMOEBA_SHRINKING;
6196 PlayLevelSound(x, y, SND_MOLE_DIGGING);
6198 ResetGfxAnimation(x, y);
6199 GfxAction[x][y] = ACTION_DIGGING;
6200 DrawLevelField(x, y);
6202 MovDelay[newx][newy] = 0; /* start amoeba shrinking delay */
6204 return; /* wait for shrinking amoeba */
6206 else /* element == EL_PACMAN */
6208 Feld[newx][newy] = EL_EMPTY;
6209 DrawLevelField(newx, newy);
6210 PlayLevelSound(x, y, SND_PACMAN_DIGGING);
6213 else if (element == EL_MOLE && IN_LEV_FIELD(newx, newy) &&
6214 (Feld[newx][newy] == EL_AMOEBA_SHRINKING ||
6215 (Feld[newx][newy] == EL_EMPTY && Stop[newx][newy])))
6217 /* wait for shrinking amoeba to completely disappear */
6220 else if (!IN_LEV_FIELD(newx, newy) || !IS_FREE(newx, newy))
6222 /* object was running against a wall */
6227 /* !!! NEW "CE_BLOCKED" STUFF !!! -- DOES NOT WORK YET... !!! */
6228 if (move_pattern & MV_ANY_DIRECTION &&
6229 move_pattern == MovDir[x][y])
6231 int blocking_element =
6232 (IN_LEV_FIELD(newx, newy) ? Feld[newx][newy] : BorderElement);
6234 CheckElementChangeBySide(x, y, element, blocking_element, CE_BLOCKED,
6237 element = Feld[x][y]; /* element might have changed */
6241 if (GFX_ELEMENT(element) != EL_SAND) /* !!! FIX THIS (crumble) !!! */
6242 DrawLevelElementAnimation(x, y, element);
6244 if (DONT_TOUCH(element))
6245 TestIfBadThingTouchesPlayer(x, y);
6250 InitMovingField(x, y, MovDir[x][y]);
6252 PlayLevelSoundAction(x, y, ACTION_MOVING);
6256 ContinueMoving(x, y);
6259 void ContinueMoving(int x, int y)
6261 int element = Feld[x][y];
6262 struct ElementInfo *ei = &element_info[element];
6263 int direction = MovDir[x][y];
6264 int dx = (direction == MV_LEFT ? -1 : direction == MV_RIGHT ? +1 : 0);
6265 int dy = (direction == MV_UP ? -1 : direction == MV_DOWN ? +1 : 0);
6266 int newx = x + dx, newy = y + dy;
6267 int stored = Store[x][y];
6268 int stored_new = Store[newx][newy];
6269 boolean pushed_by_player = (Pushed[x][y] && IS_PLAYER(x, y));
6270 boolean pushed_by_conveyor = (Pushed[x][y] && !IS_PLAYER(x, y));
6271 boolean last_line = (newy == lev_fieldy - 1);
6273 MovPos[x][y] += getElementMoveStepsize(x, y);
6275 if (pushed_by_player) /* special case: moving object pushed by player */
6276 MovPos[x][y] = SIGN(MovPos[x][y]) * (TILEX - ABS(PLAYERINFO(x,y)->MovPos));
6278 if (ABS(MovPos[x][y]) < TILEX)
6280 DrawLevelField(x, y);
6282 return; /* element is still moving */
6285 /* element reached destination field */
6287 Feld[x][y] = EL_EMPTY;
6288 Feld[newx][newy] = element;
6289 MovPos[x][y] = 0; /* force "not moving" for "crumbled sand" */
6291 if (Store[x][y] == EL_ACID) /* element is moving into acid pool */
6293 element = Feld[newx][newy] = EL_ACID;
6295 else if (element == EL_MOLE)
6297 Feld[x][y] = EL_SAND;
6299 DrawLevelFieldCrumbledSandNeighbours(x, y);
6301 else if (element == EL_QUICKSAND_FILLING)
6303 element = Feld[newx][newy] = get_next_element(element);
6304 Store[newx][newy] = Store[x][y];
6306 else if (element == EL_QUICKSAND_EMPTYING)
6308 Feld[x][y] = get_next_element(element);
6309 element = Feld[newx][newy] = Store[x][y];
6311 else if (element == EL_MAGIC_WALL_FILLING)
6313 element = Feld[newx][newy] = get_next_element(element);
6314 if (!game.magic_wall_active)
6315 element = Feld[newx][newy] = EL_MAGIC_WALL_DEAD;
6316 Store[newx][newy] = Store[x][y];
6318 else if (element == EL_MAGIC_WALL_EMPTYING)
6320 Feld[x][y] = get_next_element(element);
6321 if (!game.magic_wall_active)
6322 Feld[x][y] = EL_MAGIC_WALL_DEAD;
6323 element = Feld[newx][newy] = Store[x][y];
6325 #if USE_NEW_CUSTOM_VALUE
6326 InitField(newx, newy, FALSE);
6329 else if (element == EL_BD_MAGIC_WALL_FILLING)
6331 element = Feld[newx][newy] = get_next_element(element);
6332 if (!game.magic_wall_active)
6333 element = Feld[newx][newy] = EL_BD_MAGIC_WALL_DEAD;
6334 Store[newx][newy] = Store[x][y];
6336 else if (element == EL_BD_MAGIC_WALL_EMPTYING)
6338 Feld[x][y] = get_next_element(element);
6339 if (!game.magic_wall_active)
6340 Feld[x][y] = EL_BD_MAGIC_WALL_DEAD;
6341 element = Feld[newx][newy] = Store[x][y];
6343 #if USE_NEW_CUSTOM_VALUE
6344 InitField(newx, newy, FALSE);
6347 else if (element == EL_AMOEBA_DROPPING)
6349 Feld[x][y] = get_next_element(element);
6350 element = Feld[newx][newy] = Store[x][y];
6352 else if (element == EL_SOKOBAN_OBJECT)
6355 Feld[x][y] = Back[x][y];
6357 if (Back[newx][newy])
6358 Feld[newx][newy] = EL_SOKOBAN_FIELD_FULL;
6360 Back[x][y] = Back[newx][newy] = 0;
6363 Store[x][y] = EL_EMPTY;
6368 MovDelay[newx][newy] = 0;
6371 if (CAN_CHANGE_OR_HAS_ACTION(element))
6373 if (CAN_CHANGE(element))
6376 /* copy element change control values to new field */
6377 ChangeDelay[newx][newy] = ChangeDelay[x][y];
6378 ChangePage[newx][newy] = ChangePage[x][y];
6379 ChangeCount[newx][newy] = ChangeCount[x][y];
6380 ChangeEvent[newx][newy] = ChangeEvent[x][y];
6383 #if USE_NEW_CUSTOM_VALUE
6384 CustomValue[newx][newy] = CustomValue[x][y];
6390 #if USE_NEW_CUSTOM_VALUE
6391 CustomValue[newx][newy] = CustomValue[x][y];
6395 ChangeDelay[x][y] = 0;
6396 ChangePage[x][y] = -1;
6397 ChangeCount[x][y] = 0;
6398 ChangeEvent[x][y] = -1;
6400 #if USE_NEW_CUSTOM_VALUE
6401 CustomValue[x][y] = 0;
6404 /* copy animation control values to new field */
6405 GfxFrame[newx][newy] = GfxFrame[x][y];
6406 GfxRandom[newx][newy] = GfxRandom[x][y]; /* keep same random value */
6407 GfxAction[newx][newy] = GfxAction[x][y]; /* keep action one frame */
6408 GfxDir[newx][newy] = GfxDir[x][y]; /* keep element direction */
6410 Pushed[x][y] = Pushed[newx][newy] = FALSE;
6412 /* some elements can leave other elements behind after moving */
6414 if (ei->move_leave_element != EL_EMPTY &&
6415 (ei->move_leave_type == LEAVE_TYPE_UNLIMITED || stored != EL_EMPTY) &&
6416 (!IS_PLAYER(x, y) || IS_WALKABLE(ei->move_leave_element)))
6418 if (IS_CUSTOM_ELEMENT(element) && ei->move_leave_element != EL_EMPTY &&
6419 (ei->move_leave_type == LEAVE_TYPE_UNLIMITED || stored != EL_EMPTY) &&
6420 (!IS_PLAYER(x, y) || IS_WALKABLE(ei->move_leave_element)))
6423 int move_leave_element = ei->move_leave_element;
6427 /* this makes it possible to leave the removed element again */
6428 if (ei->move_leave_element == EL_TRIGGER_ELEMENT)
6429 move_leave_element = (stored == EL_ACID ? EL_EMPTY : stored);
6431 /* this makes it possible to leave the removed element again */
6432 if (ei->move_leave_element == EL_TRIGGER_ELEMENT)
6433 move_leave_element = stored;
6436 /* this makes it possible to leave the removed element again */
6437 if (ei->move_leave_type == LEAVE_TYPE_LIMITED &&
6438 ei->move_leave_element == EL_TRIGGER_ELEMENT)
6439 move_leave_element = stored;
6442 Feld[x][y] = move_leave_element;
6444 if (element_info[Feld[x][y]].move_direction_initial == MV_START_PREVIOUS)
6445 MovDir[x][y] = direction;
6447 InitField(x, y, FALSE);
6449 if (GFX_CRUMBLED(Feld[x][y]))
6450 DrawLevelFieldCrumbledSandNeighbours(x, y);
6452 if (ELEM_IS_PLAYER(move_leave_element))
6453 RelocatePlayer(x, y, move_leave_element);
6456 /* do this after checking for left-behind element */
6457 ResetGfxAnimation(x, y); /* reset animation values for old field */
6459 if (!CAN_MOVE(element) ||
6460 (CAN_FALL(element) && direction == MV_DOWN &&
6461 (element == EL_SPRING ||
6462 element_info[element].move_pattern == MV_WHEN_PUSHED ||
6463 element_info[element].move_pattern == MV_WHEN_DROPPED)))
6464 GfxDir[x][y] = MovDir[newx][newy] = 0;
6466 DrawLevelField(x, y);
6467 DrawLevelField(newx, newy);
6469 Stop[newx][newy] = TRUE; /* ignore this element until the next frame */
6471 /* prevent pushed element from moving on in pushed direction */
6472 if (pushed_by_player && CAN_MOVE(element) &&
6473 element_info[element].move_pattern & MV_ANY_DIRECTION &&
6474 !(element_info[element].move_pattern & direction))
6475 TurnRound(newx, newy);
6477 /* prevent elements on conveyor belt from moving on in last direction */
6478 if (pushed_by_conveyor && CAN_FALL(element) &&
6479 direction & MV_HORIZONTAL)
6480 MovDir[newx][newy] = 0;
6482 if (!pushed_by_player)
6484 int nextx = newx + dx, nexty = newy + dy;
6485 boolean check_collision_again = IN_LEV_FIELD_AND_IS_FREE(nextx, nexty);
6487 WasJustMoving[newx][newy] = 3;
6489 if (CAN_FALL(element) && direction == MV_DOWN)
6490 WasJustFalling[newx][newy] = 3;
6492 if ((!CAN_FALL(element) || direction == MV_DOWN) && check_collision_again)
6493 CheckCollision[newx][newy] = 2;
6496 if (DONT_TOUCH(element)) /* object may be nasty to player or others */
6498 TestIfBadThingTouchesPlayer(newx, newy);
6499 TestIfBadThingTouchesFriend(newx, newy);
6501 if (!IS_CUSTOM_ELEMENT(element))
6502 TestIfBadThingTouchesOtherBadThing(newx, newy);
6504 else if (element == EL_PENGUIN)
6505 TestIfFriendTouchesBadThing(newx, newy);
6507 /* give the player one last chance (one more frame) to move away */
6508 if (CAN_FALL(element) && direction == MV_DOWN &&
6509 (last_line || (!IS_FREE(x, newy + 1) &&
6510 (!IS_PLAYER(x, newy + 1) ||
6511 game.engine_version < VERSION_IDENT(3,1,1,0)))))
6514 if (pushed_by_player && !game.use_change_when_pushing_bug)
6516 int push_side = MV_DIR_OPPOSITE(direction);
6517 struct PlayerInfo *player = PLAYERINFO(x, y);
6519 CheckElementChangeByPlayer(newx, newy, element, CE_PUSHED_BY_PLAYER,
6520 player->index_bit, push_side);
6521 CheckTriggeredElementChangeByPlayer(newx,newy, element, CE_PLAYER_PUSHES_X,
6522 player->index_bit, push_side);
6525 if (element == EL_EMC_ANDROID && pushed_by_player) /* make another move */
6526 MovDelay[newx][newy] = 1;
6528 CheckTriggeredElementChangeBySide(x, y, element, CE_MOVE_OF_X, direction);
6530 TestIfElementTouchesCustomElement(x, y); /* empty or new element */
6533 if (ChangePage[newx][newy] != -1) /* delayed change */
6535 int page = ChangePage[newx][newy];
6536 struct ElementChangeInfo *change = &ei->change_page[page];
6538 ChangePage[newx][newy] = -1;
6540 if (change->can_change)
6542 if (ChangeElement(newx, newy, element, page))
6544 if (change->post_change_function)
6545 change->post_change_function(newx, newy);
6549 if (change->has_action)
6550 ExecuteCustomElementAction(newx, newy, element, page);
6554 TestIfElementHitsCustomElement(newx, newy, direction);
6555 TestIfPlayerTouchesCustomElement(newx, newy);
6556 TestIfElementTouchesCustomElement(newx, newy);
6559 if (IS_CUSTOM_ELEMENT(element) && ei->move_enter_element != EL_EMPTY &&
6560 IS_EQUAL_OR_IN_GROUP(stored_new, ei->move_enter_element))
6561 CheckElementChangeBySide(newx, newy, element, stored_new, CE_DIGGING_X,
6562 MV_DIR_OPPOSITE(direction));
6566 int AmoebeNachbarNr(int ax, int ay)
6569 int element = Feld[ax][ay];
6571 static int xy[4][2] =
6579 for (i = 0; i < NUM_DIRECTIONS; i++)
6581 int x = ax + xy[i][0];
6582 int y = ay + xy[i][1];
6584 if (!IN_LEV_FIELD(x, y))
6587 if (Feld[x][y] == element && AmoebaNr[x][y] > 0)
6588 group_nr = AmoebaNr[x][y];
6594 void AmoebenVereinigen(int ax, int ay)
6596 int i, x, y, xx, yy;
6597 int new_group_nr = AmoebaNr[ax][ay];
6598 static int xy[4][2] =
6606 if (new_group_nr == 0)
6609 for (i = 0; i < NUM_DIRECTIONS; i++)
6614 if (!IN_LEV_FIELD(x, y))
6617 if ((Feld[x][y] == EL_AMOEBA_FULL ||
6618 Feld[x][y] == EL_BD_AMOEBA ||
6619 Feld[x][y] == EL_AMOEBA_DEAD) &&
6620 AmoebaNr[x][y] != new_group_nr)
6622 int old_group_nr = AmoebaNr[x][y];
6624 if (old_group_nr == 0)
6627 AmoebaCnt[new_group_nr] += AmoebaCnt[old_group_nr];
6628 AmoebaCnt[old_group_nr] = 0;
6629 AmoebaCnt2[new_group_nr] += AmoebaCnt2[old_group_nr];
6630 AmoebaCnt2[old_group_nr] = 0;
6633 SCAN_PLAYFIELD(xx, yy)
6635 for (yy = 0; yy < lev_fieldy; yy++) for (xx = 0; xx < lev_fieldx; xx++)
6638 if (AmoebaNr[xx][yy] == old_group_nr)
6639 AmoebaNr[xx][yy] = new_group_nr;
6645 void AmoebeUmwandeln(int ax, int ay)
6649 if (Feld[ax][ay] == EL_AMOEBA_DEAD)
6651 int group_nr = AmoebaNr[ax][ay];
6656 printf("AmoebeUmwandeln(): ax = %d, ay = %d\n", ax, ay);
6657 printf("AmoebeUmwandeln(): This should never happen!\n");
6663 SCAN_PLAYFIELD(x, y)
6665 for (y = 0; y < lev_fieldy; y++) for (x = 0; x < lev_fieldx; x++)
6668 if (Feld[x][y] == EL_AMOEBA_DEAD && AmoebaNr[x][y] == group_nr)
6671 Feld[x][y] = EL_AMOEBA_TO_DIAMOND;
6675 PlayLevelSound(ax, ay, (IS_GEM(level.amoeba_content) ?
6676 SND_AMOEBA_TURNING_TO_GEM :
6677 SND_AMOEBA_TURNING_TO_ROCK));
6682 static int xy[4][2] =
6690 for (i = 0; i < NUM_DIRECTIONS; i++)
6695 if (!IN_LEV_FIELD(x, y))
6698 if (Feld[x][y] == EL_AMOEBA_TO_DIAMOND)
6700 PlayLevelSound(x, y, (IS_GEM(level.amoeba_content) ?
6701 SND_AMOEBA_TURNING_TO_GEM :
6702 SND_AMOEBA_TURNING_TO_ROCK));
6709 void AmoebeUmwandelnBD(int ax, int ay, int new_element)
6712 int group_nr = AmoebaNr[ax][ay];
6713 boolean done = FALSE;
6718 printf("AmoebeUmwandelnBD(): ax = %d, ay = %d\n", ax, ay);
6719 printf("AmoebeUmwandelnBD(): This should never happen!\n");
6725 SCAN_PLAYFIELD(x, y)
6727 for (y = 0; y < lev_fieldy; y++) for (x = 0; x < lev_fieldx; x++)
6730 if (AmoebaNr[x][y] == group_nr &&
6731 (Feld[x][y] == EL_AMOEBA_DEAD ||
6732 Feld[x][y] == EL_BD_AMOEBA ||
6733 Feld[x][y] == EL_AMOEBA_GROWING))
6736 Feld[x][y] = new_element;
6737 InitField(x, y, FALSE);
6738 DrawLevelField(x, y);
6744 PlayLevelSound(ax, ay, (new_element == EL_BD_ROCK ?
6745 SND_BD_AMOEBA_TURNING_TO_ROCK :
6746 SND_BD_AMOEBA_TURNING_TO_GEM));
6749 void AmoebeWaechst(int x, int y)
6751 static unsigned long sound_delay = 0;
6752 static unsigned long sound_delay_value = 0;
6754 if (!MovDelay[x][y]) /* start new growing cycle */
6758 if (DelayReached(&sound_delay, sound_delay_value))
6760 PlayLevelSoundElementAction(x, y, Store[x][y], ACTION_GROWING);
6761 sound_delay_value = 30;
6765 if (MovDelay[x][y]) /* wait some time before growing bigger */
6768 if (MovDelay[x][y]/2 && IN_SCR_FIELD(SCREENX(x), SCREENY(y)))
6770 int frame = getGraphicAnimationFrame(IMG_AMOEBA_GROWING,
6771 6 - MovDelay[x][y]);
6773 DrawGraphic(SCREENX(x), SCREENY(y), IMG_AMOEBA_GROWING, frame);
6776 if (!MovDelay[x][y])
6778 Feld[x][y] = Store[x][y];
6780 DrawLevelField(x, y);
6785 void AmoebaDisappearing(int x, int y)
6787 static unsigned long sound_delay = 0;
6788 static unsigned long sound_delay_value = 0;
6790 if (!MovDelay[x][y]) /* start new shrinking cycle */
6794 if (DelayReached(&sound_delay, sound_delay_value))
6795 sound_delay_value = 30;
6798 if (MovDelay[x][y]) /* wait some time before shrinking */
6801 if (MovDelay[x][y]/2 && IN_SCR_FIELD(SCREENX(x), SCREENY(y)))
6803 int frame = getGraphicAnimationFrame(IMG_AMOEBA_SHRINKING,
6804 6 - MovDelay[x][y]);
6806 DrawGraphic(SCREENX(x), SCREENY(y), IMG_AMOEBA_SHRINKING, frame);
6809 if (!MovDelay[x][y])
6811 Feld[x][y] = EL_EMPTY;
6812 DrawLevelField(x, y);
6814 /* don't let mole enter this field in this cycle;
6815 (give priority to objects falling to this field from above) */
6821 void AmoebeAbleger(int ax, int ay)
6824 int element = Feld[ax][ay];
6825 int graphic = el2img(element);
6826 int newax = ax, neway = ay;
6827 boolean can_drop = (element == EL_AMOEBA_WET || element == EL_EMC_DRIPPER);
6828 static int xy[4][2] =
6836 if (!level.amoeba_speed && element != EL_EMC_DRIPPER)
6838 Feld[ax][ay] = EL_AMOEBA_DEAD;
6839 DrawLevelField(ax, ay);
6843 if (IS_ANIMATED(graphic))
6844 DrawLevelGraphicAnimationIfNeeded(ax, ay, graphic);
6846 if (!MovDelay[ax][ay]) /* start making new amoeba field */
6847 MovDelay[ax][ay] = RND(FRAMES_PER_SECOND * 25 / (1 + level.amoeba_speed));
6849 if (MovDelay[ax][ay]) /* wait some time before making new amoeba */
6852 if (MovDelay[ax][ay])
6856 if (can_drop) /* EL_AMOEBA_WET or EL_EMC_DRIPPER */
6859 int x = ax + xy[start][0];
6860 int y = ay + xy[start][1];
6862 if (!IN_LEV_FIELD(x, y))
6865 if (IS_FREE(x, y) ||
6866 CAN_GROW_INTO(Feld[x][y]) ||
6867 Feld[x][y] == EL_QUICKSAND_EMPTY)
6873 if (newax == ax && neway == ay)
6876 else /* normal or "filled" (BD style) amoeba */
6879 boolean waiting_for_player = FALSE;
6881 for (i = 0; i < NUM_DIRECTIONS; i++)
6883 int j = (start + i) % 4;
6884 int x = ax + xy[j][0];
6885 int y = ay + xy[j][1];
6887 if (!IN_LEV_FIELD(x, y))
6890 if (IS_FREE(x, y) ||
6891 CAN_GROW_INTO(Feld[x][y]) ||
6892 Feld[x][y] == EL_QUICKSAND_EMPTY)
6898 else if (IS_PLAYER(x, y))
6899 waiting_for_player = TRUE;
6902 if (newax == ax && neway == ay) /* amoeba cannot grow */
6904 if (i == 4 && (!waiting_for_player || element == EL_BD_AMOEBA))
6906 Feld[ax][ay] = EL_AMOEBA_DEAD;
6907 DrawLevelField(ax, ay);
6908 AmoebaCnt[AmoebaNr[ax][ay]]--;
6910 if (AmoebaCnt[AmoebaNr[ax][ay]] <= 0) /* amoeba is completely dead */
6912 if (element == EL_AMOEBA_FULL)
6913 AmoebeUmwandeln(ax, ay);
6914 else if (element == EL_BD_AMOEBA)
6915 AmoebeUmwandelnBD(ax, ay, level.amoeba_content);
6920 else if (element == EL_AMOEBA_FULL || element == EL_BD_AMOEBA)
6922 /* amoeba gets larger by growing in some direction */
6924 int new_group_nr = AmoebaNr[ax][ay];
6927 if (new_group_nr == 0)
6929 printf("AmoebeAbleger(): newax = %d, neway = %d\n", newax, neway);
6930 printf("AmoebeAbleger(): This should never happen!\n");
6935 AmoebaNr[newax][neway] = new_group_nr;
6936 AmoebaCnt[new_group_nr]++;
6937 AmoebaCnt2[new_group_nr]++;
6939 /* if amoeba touches other amoeba(s) after growing, unify them */
6940 AmoebenVereinigen(newax, neway);
6942 if (element == EL_BD_AMOEBA && AmoebaCnt2[new_group_nr] >= 200)
6944 AmoebeUmwandelnBD(newax, neway, EL_BD_ROCK);
6950 if (!can_drop || neway < ay || !IS_FREE(newax, neway) ||
6951 (neway == lev_fieldy - 1 && newax != ax))
6953 Feld[newax][neway] = EL_AMOEBA_GROWING; /* creation of new amoeba */
6954 Store[newax][neway] = element;
6956 else if (neway == ay || element == EL_EMC_DRIPPER)
6958 Feld[newax][neway] = EL_AMOEBA_DROP; /* drop left/right of amoeba */
6960 PlayLevelSoundAction(newax, neway, ACTION_GROWING);
6964 InitMovingField(ax, ay, MV_DOWN); /* drop dripping from amoeba */
6965 Feld[ax][ay] = EL_AMOEBA_DROPPING;
6966 Store[ax][ay] = EL_AMOEBA_DROP;
6967 ContinueMoving(ax, ay);
6971 DrawLevelField(newax, neway);
6974 void Life(int ax, int ay)
6978 static int life[4] = { 2, 3, 3, 3 }; /* parameters for "game of life" */
6981 int element = Feld[ax][ay];
6982 int graphic = el2img(element);
6983 int *life_parameter = (element == EL_GAME_OF_LIFE ? level.game_of_life :
6985 boolean changed = FALSE;
6987 if (IS_ANIMATED(graphic))
6988 DrawLevelGraphicAnimationIfNeeded(ax, ay, graphic);
6993 if (!MovDelay[ax][ay]) /* start new "game of life" cycle */
6994 MovDelay[ax][ay] = life_time;
6996 if (MovDelay[ax][ay]) /* wait some time before next cycle */
6999 if (MovDelay[ax][ay])
7003 for (y1 = -1; y1 < 2; y1++) for (x1 = -1; x1 < 2; x1++)
7005 int xx = ax+x1, yy = ay+y1;
7008 if (!IN_LEV_FIELD(xx, yy))
7011 for (y2 = -1; y2 < 2; y2++) for (x2 = -1; x2 < 2; x2++)
7013 int x = xx+x2, y = yy+y2;
7015 if (!IN_LEV_FIELD(x, y) || (x == xx && y == yy))
7018 if (((Feld[x][y] == element ||
7019 (element == EL_GAME_OF_LIFE && IS_PLAYER(x, y))) &&
7021 (IS_FREE(x, y) && Stop[x][y]))
7025 if (xx == ax && yy == ay) /* field in the middle */
7027 if (nachbarn < life_parameter[0] ||
7028 nachbarn > life_parameter[1])
7030 Feld[xx][yy] = EL_EMPTY;
7032 DrawLevelField(xx, yy);
7033 Stop[xx][yy] = TRUE;
7037 else if (IS_FREE(xx, yy) || CAN_GROW_INTO(Feld[xx][yy]))
7038 { /* free border field */
7039 if (nachbarn >= life_parameter[2] &&
7040 nachbarn <= life_parameter[3])
7042 Feld[xx][yy] = element;
7043 MovDelay[xx][yy] = (element == EL_GAME_OF_LIFE ? 0 : life_time-1);
7045 DrawLevelField(xx, yy);
7046 Stop[xx][yy] = TRUE;
7053 PlayLevelSound(ax, ay, element == EL_BIOMAZE ? SND_BIOMAZE_GROWING :
7054 SND_GAME_OF_LIFE_GROWING);
7057 static void InitRobotWheel(int x, int y)
7059 ChangeDelay[x][y] = level.time_wheel * FRAMES_PER_SECOND;
7062 static void RunRobotWheel(int x, int y)
7064 PlayLevelSound(x, y, SND_ROBOT_WHEEL_ACTIVE);
7067 static void StopRobotWheel(int x, int y)
7069 if (ZX == x && ZY == y)
7073 static void InitTimegateWheel(int x, int y)
7075 ChangeDelay[x][y] = level.time_timegate * FRAMES_PER_SECOND;
7078 static void RunTimegateWheel(int x, int y)
7080 PlayLevelSound(x, y, SND_TIMEGATE_SWITCH_ACTIVE);
7083 static void InitMagicBallDelay(int x, int y)
7086 ChangeDelay[x][y] = (level.ball_time + 1) * 8 + 1;
7088 ChangeDelay[x][y] = level.ball_time * FRAMES_PER_SECOND + 1;
7092 static void ActivateMagicBall(int bx, int by)
7096 if (level.ball_random)
7098 int pos_border = RND(8); /* select one of the eight border elements */
7099 int pos_content = (pos_border > 3 ? pos_border + 1 : pos_border);
7100 int xx = pos_content % 3;
7101 int yy = pos_content / 3;
7106 if (IN_LEV_FIELD(x, y) && Feld[x][y] == EL_EMPTY)
7107 CreateField(x, y, level.ball_content[game.ball_content_nr].e[xx][yy]);
7111 for (y = by - 1; y <= by + 1; y++) for (x = bx - 1; x <= bx + 1; x++)
7113 int xx = x - bx + 1;
7114 int yy = y - by + 1;
7116 if (IN_LEV_FIELD(x, y) && Feld[x][y] == EL_EMPTY)
7117 CreateField(x, y, level.ball_content[game.ball_content_nr].e[xx][yy]);
7121 game.ball_content_nr = (game.ball_content_nr + 1) % level.num_ball_contents;
7124 static void InitDiagonalMovingElement(int x, int y)
7127 MovDelay[x][y] = level.android_move_time;
7131 void CheckExit(int x, int y)
7133 if (local_player->gems_still_needed > 0 ||
7134 local_player->sokobanfields_still_needed > 0 ||
7135 local_player->lights_still_needed > 0)
7137 int element = Feld[x][y];
7138 int graphic = el2img(element);
7140 if (IS_ANIMATED(graphic))
7141 DrawLevelGraphicAnimationIfNeeded(x, y, graphic);
7146 if (AllPlayersGone) /* do not re-open exit door closed after last player */
7149 Feld[x][y] = EL_EXIT_OPENING;
7151 PlayLevelSoundNearest(x, y, SND_CLASS_EXIT_OPENING);
7154 void CheckExitSP(int x, int y)
7156 if (local_player->gems_still_needed > 0)
7158 int element = Feld[x][y];
7159 int graphic = el2img(element);
7161 if (IS_ANIMATED(graphic))
7162 DrawLevelGraphicAnimationIfNeeded(x, y, graphic);
7167 if (AllPlayersGone) /* do not re-open exit door closed after last player */
7170 Feld[x][y] = EL_SP_EXIT_OPENING;
7172 PlayLevelSoundNearest(x, y, SND_CLASS_SP_EXIT_OPENING);
7175 static void CloseAllOpenTimegates()
7180 SCAN_PLAYFIELD(x, y)
7182 for (y = 0; y < lev_fieldy; y++) for (x = 0; x < lev_fieldx; x++)
7185 int element = Feld[x][y];
7187 if (element == EL_TIMEGATE_OPEN || element == EL_TIMEGATE_OPENING)
7189 Feld[x][y] = EL_TIMEGATE_CLOSING;
7191 PlayLevelSoundAction(x, y, ACTION_CLOSING);
7196 void EdelsteinFunkeln(int x, int y)
7198 if (!IN_SCR_FIELD(SCREENX(x), SCREENY(y)) || IS_MOVING(x, y))
7201 if (Feld[x][y] == EL_BD_DIAMOND)
7204 if (MovDelay[x][y] == 0) /* next animation frame */
7205 MovDelay[x][y] = 11 * !SimpleRND(500);
7207 if (MovDelay[x][y] != 0) /* wait some time before next frame */
7211 if (setup.direct_draw && MovDelay[x][y])
7212 SetDrawtoField(DRAW_BUFFERED);
7214 DrawLevelElementAnimation(x, y, Feld[x][y]);
7216 if (MovDelay[x][y] != 0)
7218 int frame = getGraphicAnimationFrame(IMG_TWINKLE_WHITE,
7219 10 - MovDelay[x][y]);
7221 DrawGraphicThruMask(SCREENX(x), SCREENY(y), IMG_TWINKLE_WHITE, frame);
7223 if (setup.direct_draw)
7227 dest_x = FX + SCREENX(x) * TILEX;
7228 dest_y = FY + SCREENY(y) * TILEY;
7230 BlitBitmap(drawto_field, window,
7231 dest_x, dest_y, TILEX, TILEY, dest_x, dest_y);
7232 SetDrawtoField(DRAW_DIRECT);
7238 void MauerWaechst(int x, int y)
7242 if (!MovDelay[x][y]) /* next animation frame */
7243 MovDelay[x][y] = 3 * delay;
7245 if (MovDelay[x][y]) /* wait some time before next frame */
7249 if (IN_SCR_FIELD(SCREENX(x), SCREENY(y)))
7251 int graphic = el_dir2img(Feld[x][y], GfxDir[x][y]);
7252 int frame = getGraphicAnimationFrame(graphic, 17 - MovDelay[x][y]);
7254 DrawGraphic(SCREENX(x), SCREENY(y), graphic, frame);
7257 if (!MovDelay[x][y])
7259 if (MovDir[x][y] == MV_LEFT)
7261 if (IN_LEV_FIELD(x - 1, y) && IS_WALL(Feld[x - 1][y]))
7262 DrawLevelField(x - 1, y);
7264 else if (MovDir[x][y] == MV_RIGHT)
7266 if (IN_LEV_FIELD(x + 1, y) && IS_WALL(Feld[x + 1][y]))
7267 DrawLevelField(x + 1, y);
7269 else if (MovDir[x][y] == MV_UP)
7271 if (IN_LEV_FIELD(x, y - 1) && IS_WALL(Feld[x][y - 1]))
7272 DrawLevelField(x, y - 1);
7276 if (IN_LEV_FIELD(x, y + 1) && IS_WALL(Feld[x][y + 1]))
7277 DrawLevelField(x, y + 1);
7280 Feld[x][y] = Store[x][y];
7282 GfxDir[x][y] = MovDir[x][y] = MV_NONE;
7283 DrawLevelField(x, y);
7288 void MauerAbleger(int ax, int ay)
7290 int element = Feld[ax][ay];
7291 int graphic = el2img(element);
7292 boolean oben_frei = FALSE, unten_frei = FALSE;
7293 boolean links_frei = FALSE, rechts_frei = FALSE;
7294 boolean oben_massiv = FALSE, unten_massiv = FALSE;
7295 boolean links_massiv = FALSE, rechts_massiv = FALSE;
7296 boolean new_wall = FALSE;
7298 if (IS_ANIMATED(graphic))
7299 DrawLevelGraphicAnimationIfNeeded(ax, ay, graphic);
7301 if (!MovDelay[ax][ay]) /* start building new wall */
7302 MovDelay[ax][ay] = 6;
7304 if (MovDelay[ax][ay]) /* wait some time before building new wall */
7307 if (MovDelay[ax][ay])
7311 if (IN_LEV_FIELD(ax, ay-1) && IS_FREE(ax, ay-1))
7313 if (IN_LEV_FIELD(ax, ay+1) && IS_FREE(ax, ay+1))
7315 if (IN_LEV_FIELD(ax-1, ay) && IS_FREE(ax-1, ay))
7317 if (IN_LEV_FIELD(ax+1, ay) && IS_FREE(ax+1, ay))
7320 if (element == EL_EXPANDABLE_WALL_VERTICAL ||
7321 element == EL_EXPANDABLE_WALL_ANY)
7325 Feld[ax][ay-1] = EL_EXPANDABLE_WALL_GROWING;
7326 Store[ax][ay-1] = element;
7327 GfxDir[ax][ay-1] = MovDir[ax][ay-1] = MV_UP;
7328 if (IN_SCR_FIELD(SCREENX(ax), SCREENY(ay-1)))
7329 DrawGraphic(SCREENX(ax), SCREENY(ay - 1),
7330 IMG_EXPANDABLE_WALL_GROWING_UP, 0);
7335 Feld[ax][ay+1] = EL_EXPANDABLE_WALL_GROWING;
7336 Store[ax][ay+1] = element;
7337 GfxDir[ax][ay+1] = MovDir[ax][ay+1] = MV_DOWN;
7338 if (IN_SCR_FIELD(SCREENX(ax), SCREENY(ay+1)))
7339 DrawGraphic(SCREENX(ax), SCREENY(ay + 1),
7340 IMG_EXPANDABLE_WALL_GROWING_DOWN, 0);
7345 if (element == EL_EXPANDABLE_WALL_HORIZONTAL ||
7346 element == EL_EXPANDABLE_WALL_ANY ||
7347 element == EL_EXPANDABLE_WALL)
7351 Feld[ax-1][ay] = EL_EXPANDABLE_WALL_GROWING;
7352 Store[ax-1][ay] = element;
7353 GfxDir[ax-1][ay] = MovDir[ax-1][ay] = MV_LEFT;
7354 if (IN_SCR_FIELD(SCREENX(ax-1), SCREENY(ay)))
7355 DrawGraphic(SCREENX(ax - 1), SCREENY(ay),
7356 IMG_EXPANDABLE_WALL_GROWING_LEFT, 0);
7362 Feld[ax+1][ay] = EL_EXPANDABLE_WALL_GROWING;
7363 Store[ax+1][ay] = element;
7364 GfxDir[ax+1][ay] = MovDir[ax+1][ay] = MV_RIGHT;
7365 if (IN_SCR_FIELD(SCREENX(ax+1), SCREENY(ay)))
7366 DrawGraphic(SCREENX(ax + 1), SCREENY(ay),
7367 IMG_EXPANDABLE_WALL_GROWING_RIGHT, 0);
7372 if (element == EL_EXPANDABLE_WALL && (links_frei || rechts_frei))
7373 DrawLevelField(ax, ay);
7375 if (!IN_LEV_FIELD(ax, ay-1) || IS_WALL(Feld[ax][ay-1]))
7377 if (!IN_LEV_FIELD(ax, ay+1) || IS_WALL(Feld[ax][ay+1]))
7378 unten_massiv = TRUE;
7379 if (!IN_LEV_FIELD(ax-1, ay) || IS_WALL(Feld[ax-1][ay]))
7380 links_massiv = TRUE;
7381 if (!IN_LEV_FIELD(ax+1, ay) || IS_WALL(Feld[ax+1][ay]))
7382 rechts_massiv = TRUE;
7384 if (((oben_massiv && unten_massiv) ||
7385 element == EL_EXPANDABLE_WALL_HORIZONTAL ||
7386 element == EL_EXPANDABLE_WALL) &&
7387 ((links_massiv && rechts_massiv) ||
7388 element == EL_EXPANDABLE_WALL_VERTICAL))
7389 Feld[ax][ay] = EL_WALL;
7392 PlayLevelSoundAction(ax, ay, ACTION_GROWING);
7395 void CheckForDragon(int x, int y)
7398 boolean dragon_found = FALSE;
7399 static int xy[4][2] =
7407 for (i = 0; i < NUM_DIRECTIONS; i++)
7409 for (j = 0; j < 4; j++)
7411 int xx = x + j * xy[i][0], yy = y + j * xy[i][1];
7413 if (IN_LEV_FIELD(xx, yy) &&
7414 (Feld[xx][yy] == EL_FLAMES || Feld[xx][yy] == EL_DRAGON))
7416 if (Feld[xx][yy] == EL_DRAGON)
7417 dragon_found = TRUE;
7426 for (i = 0; i < NUM_DIRECTIONS; i++)
7428 for (j = 0; j < 3; j++)
7430 int xx = x + j * xy[i][0], yy = y + j * xy[i][1];
7432 if (IN_LEV_FIELD(xx, yy) && Feld[xx][yy] == EL_FLAMES)
7434 Feld[xx][yy] = EL_EMPTY;
7435 DrawLevelField(xx, yy);
7444 static void InitBuggyBase(int x, int y)
7446 int element = Feld[x][y];
7447 int activating_delay = FRAMES_PER_SECOND / 4;
7450 (element == EL_SP_BUGGY_BASE ?
7451 2 * FRAMES_PER_SECOND + RND(5 * FRAMES_PER_SECOND) - activating_delay :
7452 element == EL_SP_BUGGY_BASE_ACTIVATING ?
7454 element == EL_SP_BUGGY_BASE_ACTIVE ?
7455 1 * FRAMES_PER_SECOND + RND(1 * FRAMES_PER_SECOND) : 1);
7458 static void WarnBuggyBase(int x, int y)
7461 static int xy[4][2] =
7469 for (i = 0; i < NUM_DIRECTIONS; i++)
7471 int xx = x + xy[i][0];
7472 int yy = y + xy[i][1];
7474 if (IN_LEV_FIELD(xx, yy) && IS_PLAYER(xx, yy))
7476 PlayLevelSound(x, y, SND_SP_BUGGY_BASE_ACTIVE);
7483 static void InitTrap(int x, int y)
7485 ChangeDelay[x][y] = 2 * FRAMES_PER_SECOND + RND(5 * FRAMES_PER_SECOND);
7488 static void ActivateTrap(int x, int y)
7490 PlayLevelSound(x, y, SND_TRAP_ACTIVATING);
7493 static void ChangeActiveTrap(int x, int y)
7495 int graphic = IMG_TRAP_ACTIVE;
7497 /* if new animation frame was drawn, correct crumbled sand border */
7498 if (IS_NEW_FRAME(GfxFrame[x][y], graphic))
7499 DrawLevelFieldCrumbledSand(x, y);
7502 static int getSpecialActionElement(int element, int number, int base_element)
7504 return (element != EL_EMPTY ? element :
7505 number != -1 ? base_element + number - 1 :
7509 static int getModifiedActionNumber(int value_old, int operator, int operand,
7510 int value_min, int value_max)
7512 int value_new = (operator == CA_MODE_SET ? operand :
7513 operator == CA_MODE_ADD ? value_old + operand :
7514 operator == CA_MODE_SUBTRACT ? value_old - operand :
7515 operator == CA_MODE_MULTIPLY ? value_old * operand :
7516 operator == CA_MODE_DIVIDE ? value_old / MAX(1, operand) :
7517 operator == CA_MODE_MODULO ? value_old % MAX(1, operand) :
7520 return (value_new < value_min ? value_min :
7521 value_new > value_max ? value_max :
7525 static void ExecuteCustomElementAction(int x, int y, int element, int page)
7527 struct ElementInfo *ei = &element_info[element];
7528 struct ElementChangeInfo *change = &ei->change_page[page];
7529 int action_type = change->action_type;
7530 int action_mode = change->action_mode;
7531 int action_arg = change->action_arg;
7534 if (!change->has_action)
7537 /* ---------- determine action paramater values -------------------------- */
7539 int level_time_value =
7540 (level.time > 0 ? TimeLeft :
7543 int action_arg_element =
7544 (action_arg == CA_ARG_PLAYER_TRIGGER ? change->actual_trigger_player :
7545 action_arg == CA_ARG_ELEMENT_TRIGGER ? change->actual_trigger_element :
7546 action_arg == CA_ARG_ELEMENT_TARGET ? change->target_element :
7549 int action_arg_direction =
7550 (action_arg >= CA_ARG_DIRECTION_LEFT &&
7551 action_arg <= CA_ARG_DIRECTION_DOWN ? action_arg - CA_ARG_DIRECTION :
7552 action_arg == CA_ARG_DIRECTION_TRIGGER ?
7553 change->actual_trigger_side :
7554 action_arg == CA_ARG_DIRECTION_TRIGGER_BACK ?
7555 MV_DIR_OPPOSITE(change->actual_trigger_side) :
7558 int action_arg_number_min =
7559 (action_type == CA_SET_PLAYER_SPEED ? STEPSIZE_NOT_MOVING :
7562 int action_arg_number_max =
7563 (action_type == CA_SET_PLAYER_SPEED ? STEPSIZE_EVEN_FASTER :
7564 action_type == CA_SET_LEVEL_GEMS ? 999 :
7565 action_type == CA_SET_LEVEL_TIME ? 9999 :
7566 action_type == CA_SET_LEVEL_SCORE ? 99999 :
7567 action_type == CA_SET_CE_SCORE ? 9999 :
7568 action_type == CA_SET_CE_VALUE ? 9999 :
7571 int action_arg_number_reset =
7572 (action_type == CA_SET_PLAYER_SPEED ? level.initial_player_stepsize :
7573 action_type == CA_SET_LEVEL_GEMS ? level.gems_needed :
7574 action_type == CA_SET_LEVEL_TIME ? level.time :
7575 action_type == CA_SET_LEVEL_SCORE ? 0 :
7576 action_type == CA_SET_CE_SCORE ? 0 :
7578 action_type == CA_SET_CE_VALUE ? GET_NEW_CUSTOM_VALUE(element) :
7580 action_type == CA_SET_CE_VALUE ? ei->custom_value_initial :
7584 int action_arg_number =
7585 (action_arg <= CA_ARG_MAX ? action_arg :
7586 action_arg >= CA_ARG_SPEED_NOT_MOVING &&
7587 action_arg <= CA_ARG_SPEED_EVEN_FASTER ? (action_arg - CA_ARG_SPEED) :
7588 action_arg == CA_ARG_SPEED_RESET ? action_arg_number_reset :
7589 action_arg == CA_ARG_NUMBER_MIN ? action_arg_number_min :
7590 action_arg == CA_ARG_NUMBER_MAX ? action_arg_number_max :
7591 action_arg == CA_ARG_NUMBER_RESET ? action_arg_number_reset :
7592 action_arg == CA_ARG_NUMBER_CE_SCORE ? ei->collect_score :
7593 #if USE_NEW_CUSTOM_VALUE
7594 action_arg == CA_ARG_NUMBER_CE_VALUE ? CustomValue[x][y] :
7596 action_arg == CA_ARG_NUMBER_CE_VALUE ? ei->custom_value_initial :
7598 action_arg == CA_ARG_NUMBER_CE_DELAY ? GET_CE_DELAY_VALUE(change) :
7599 action_arg == CA_ARG_NUMBER_LEVEL_TIME ? level_time_value :
7600 action_arg == CA_ARG_NUMBER_LEVEL_GEMS ? local_player->gems_still_needed :
7601 action_arg == CA_ARG_NUMBER_LEVEL_SCORE ? local_player->score :
7602 action_arg == CA_ARG_ELEMENT_CV_TARGET ? GET_NEW_CUSTOM_VALUE(change->target_element) :
7603 action_arg == CA_ARG_ELEMENT_CV_TRIGGER ? change->actual_trigger_ce_value:
7604 action_arg == CA_ARG_ELEMENT_NR_TARGET ? change->target_element :
7605 action_arg == CA_ARG_ELEMENT_NR_TRIGGER ? change->actual_trigger_element :
7608 int action_arg_number_old =
7609 (action_type == CA_SET_LEVEL_GEMS ? local_player->gems_still_needed :
7610 action_type == CA_SET_LEVEL_TIME ? TimeLeft :
7611 action_type == CA_SET_LEVEL_SCORE ? local_player->score :
7612 action_type == CA_SET_CE_SCORE ? ei->collect_score :
7613 action_type == CA_SET_CE_VALUE ? CustomValue[x][y] :
7616 int action_arg_number_new =
7617 getModifiedActionNumber(action_arg_number_old,
7618 action_mode, action_arg_number,
7619 action_arg_number_min, action_arg_number_max);
7621 int trigger_player_bits =
7622 (change->actual_trigger_player >= EL_PLAYER_1 &&
7623 change->actual_trigger_player <= EL_PLAYER_4 ?
7624 (1 << (change->actual_trigger_player - EL_PLAYER_1)) :
7627 int action_arg_player_bits =
7628 (action_arg >= CA_ARG_PLAYER_1 &&
7629 action_arg <= CA_ARG_PLAYER_4 ? action_arg - CA_ARG_PLAYER :
7630 action_arg == CA_ARG_PLAYER_TRIGGER ? trigger_player_bits :
7633 /* ---------- execute action -------------------------------------------- */
7642 /* ---------- level actions ------------------------------------------- */
7644 case CA_RESTART_LEVEL:
7646 game.restart_level = TRUE;
7651 case CA_SHOW_ENVELOPE:
7653 int element = getSpecialActionElement(action_arg_element,
7654 action_arg_number, EL_ENVELOPE_1);
7656 if (IS_ENVELOPE(element))
7657 local_player->show_envelope = element;
7662 case CA_SET_LEVEL_TIME:
7664 if (level.time > 0) /* only modify limited time value */
7666 TimeLeft = action_arg_number_new;
7668 DrawGameValue_Time(TimeLeft);
7670 if (!TimeLeft && setup.time_limit)
7671 for (i = 0; i < MAX_PLAYERS; i++)
7672 KillPlayer(&stored_player[i]);
7678 case CA_SET_LEVEL_SCORE:
7680 local_player->score = action_arg_number_new;
7682 DrawGameValue_Score(local_player->score);
7687 case CA_SET_LEVEL_GEMS:
7689 local_player->gems_still_needed = action_arg_number_new;
7691 DrawGameValue_Emeralds(local_player->gems_still_needed);
7696 case CA_SET_LEVEL_GRAVITY:
7698 game.gravity = (action_arg == CA_ARG_GRAVITY_OFF ? FALSE :
7699 action_arg == CA_ARG_GRAVITY_ON ? TRUE :
7700 action_arg == CA_ARG_GRAVITY_TOGGLE ? !game.gravity :
7705 case CA_SET_LEVEL_WIND:
7707 game.wind_direction = action_arg_direction;
7712 /* ---------- player actions ------------------------------------------ */
7714 case CA_MOVE_PLAYER:
7716 /* automatically move to the next field in specified direction */
7717 for (i = 0; i < MAX_PLAYERS; i++)
7718 if (trigger_player_bits & (1 << i))
7719 stored_player[i].programmed_action = action_arg_direction;
7724 case CA_EXIT_PLAYER:
7726 for (i = 0; i < MAX_PLAYERS; i++)
7727 if (action_arg_player_bits & (1 << i))
7728 stored_player[i].LevelSolved = stored_player[i].GameOver = TRUE;
7733 case CA_KILL_PLAYER:
7735 for (i = 0; i < MAX_PLAYERS; i++)
7736 if (action_arg_player_bits & (1 << i))
7737 KillPlayer(&stored_player[i]);
7742 case CA_SET_PLAYER_KEYS:
7744 int key_state = (action_mode == CA_MODE_ADD ? TRUE : FALSE);
7745 int element = getSpecialActionElement(action_arg_element,
7746 action_arg_number, EL_KEY_1);
7748 if (IS_KEY(element))
7750 for (i = 0; i < MAX_PLAYERS; i++)
7752 if (trigger_player_bits & (1 << i))
7754 stored_player[i].key[KEY_NR(element)] = key_state;
7756 DrawGameValue_Keys(stored_player[i].key);
7758 redraw_mask |= REDRAW_DOOR_1;
7766 case CA_SET_PLAYER_SPEED:
7768 for (i = 0; i < MAX_PLAYERS; i++)
7770 if (trigger_player_bits & (1 << i))
7772 int move_stepsize = TILEX / stored_player[i].move_delay_value;
7774 if (action_arg == CA_ARG_SPEED_FASTER &&
7775 stored_player[i].cannot_move)
7777 action_arg_number = STEPSIZE_VERY_SLOW;
7779 else if (action_arg == CA_ARG_SPEED_SLOWER ||
7780 action_arg == CA_ARG_SPEED_FASTER)
7782 action_arg_number = 2;
7783 action_mode = (action_arg == CA_ARG_SPEED_SLOWER ? CA_MODE_DIVIDE :
7788 getModifiedActionNumber(move_stepsize,
7791 action_arg_number_min,
7792 action_arg_number_max);
7795 SetPlayerMoveSpeed(&stored_player[i], move_stepsize, FALSE);
7797 /* make sure that value is power of 2 */
7798 move_stepsize = (1 << log_2(move_stepsize));
7800 /* do no immediately change -- the player might just be moving */
7801 stored_player[i].move_delay_value_next = TILEX / move_stepsize;
7803 stored_player[i].cannot_move =
7804 (action_arg == CA_ARG_SPEED_NOT_MOVING ? TRUE : FALSE);
7812 case CA_SET_PLAYER_SHIELD:
7814 for (i = 0; i < MAX_PLAYERS; i++)
7816 if (trigger_player_bits & (1 << i))
7818 if (action_arg == CA_ARG_SHIELD_OFF)
7820 stored_player[i].shield_normal_time_left = 0;
7821 stored_player[i].shield_deadly_time_left = 0;
7823 else if (action_arg == CA_ARG_SHIELD_NORMAL)
7825 stored_player[i].shield_normal_time_left = 999999;
7827 else if (action_arg == CA_ARG_SHIELD_DEADLY)
7829 stored_player[i].shield_normal_time_left = 999999;
7830 stored_player[i].shield_deadly_time_left = 999999;
7838 case CA_SET_PLAYER_ARTWORK:
7840 for (i = 0; i < MAX_PLAYERS; i++)
7842 if (trigger_player_bits & (1 << i))
7844 int artwork_element = action_arg_element;
7846 if (action_arg == CA_ARG_ELEMENT_RESET)
7848 (level.use_artwork_element[i] ? level.artwork_element[i] :
7849 stored_player[i].element_nr);
7851 stored_player[i].artwork_element = artwork_element;
7853 SetPlayerWaiting(&stored_player[i], FALSE);
7855 /* set number of special actions for bored and sleeping animation */
7856 stored_player[i].num_special_action_bored =
7857 get_num_special_action(artwork_element,
7858 ACTION_BORING_1, ACTION_BORING_LAST);
7859 stored_player[i].num_special_action_sleeping =
7860 get_num_special_action(artwork_element,
7861 ACTION_SLEEPING_1, ACTION_SLEEPING_LAST);
7868 /* ---------- CE actions ---------------------------------------------- */
7870 case CA_SET_CE_SCORE:
7872 ei->collect_score = action_arg_number_new;
7877 case CA_SET_CE_VALUE:
7879 #if USE_NEW_CUSTOM_VALUE
7880 int last_custom_value = CustomValue[x][y];
7882 CustomValue[x][y] = action_arg_number_new;
7885 printf("::: Count == %d\n", CustomValue[x][y]);
7888 if (CustomValue[x][y] == 0 && last_custom_value > 0)
7891 printf("::: CE_VALUE_GETS_ZERO\n");
7894 CheckElementChange(x, y, element, EL_UNDEFINED, CE_VALUE_GETS_ZERO);
7895 CheckTriggeredElementChange(x, y, element, CE_VALUE_GETS_ZERO_OF_X);
7898 printf("::: RESULT: %d, %d\n", Feld[x][y], ChangePage[x][y]);
7906 /* ---------- engine actions ------------------------------------------ */
7908 case CA_SET_ENGINE_SCAN_MODE:
7910 InitPlayfieldScanMode(action_arg);
7920 static void CreateFieldExt(int x, int y, int element, boolean is_change)
7922 int previous_move_direction = MovDir[x][y];
7923 #if USE_NEW_CUSTOM_VALUE
7924 int last_ce_value = CustomValue[x][y];
7926 boolean add_player = (ELEM_IS_PLAYER(element) &&
7927 IS_WALKABLE(Feld[x][y]));
7929 /* check if element under player changes from accessible to unaccessible
7930 (needed for special case of dropping element which then changes) */
7931 if (IS_PLAYER(x, y) && !PLAYER_EXPLOSION_PROTECTED(x, y) &&
7932 IS_ACCESSIBLE(Feld[x][y]) && !IS_ACCESSIBLE(element))
7941 if (IS_MOVING(x, y) || IS_BLOCKED(x, y))
7942 RemoveMovingField(x, y);
7946 Feld[x][y] = element;
7948 ResetGfxAnimation(x, y);
7949 ResetRandomAnimationValue(x, y);
7951 if (element_info[Feld[x][y]].move_direction_initial == MV_START_PREVIOUS)
7952 MovDir[x][y] = previous_move_direction;
7954 #if USE_NEW_CUSTOM_VALUE
7955 if (element_info[Feld[x][y]].use_last_ce_value)
7956 CustomValue[x][y] = last_ce_value;
7959 InitField_WithBug1(x, y, FALSE);
7961 DrawLevelField(x, y);
7963 if (GFX_CRUMBLED(Feld[x][y]))
7964 DrawLevelFieldCrumbledSandNeighbours(x, y);
7967 /* "ChangeCount" not set yet to allow "entered by player" change one time */
7968 if (ELEM_IS_PLAYER(element))
7969 RelocatePlayer(x, y, element);
7972 ChangeCount[x][y]++; /* count number of changes in the same frame */
7974 TestIfBadThingTouchesPlayer(x, y);
7975 TestIfPlayerTouchesCustomElement(x, y);
7976 TestIfElementTouchesCustomElement(x, y);
7979 static void CreateField(int x, int y, int element)
7981 CreateFieldExt(x, y, element, FALSE);
7984 static void CreateElementFromChange(int x, int y, int element)
7986 element = GET_VALID_RUNTIME_ELEMENT(element);
7988 #if USE_STOP_CHANGED_ELEMENTS
7989 if (game.engine_version >= VERSION_IDENT(3,2,0,7))
7991 int old_element = Feld[x][y];
7993 /* prevent changed element from moving in same engine frame
7994 unless both old and new element can either fall or move */
7995 if ((!CAN_FALL(old_element) || !CAN_FALL(element)) &&
7996 (!CAN_MOVE(old_element) || !CAN_MOVE(element)))
8001 CreateFieldExt(x, y, element, TRUE);
8004 static boolean ChangeElement(int x, int y, int element, int page)
8006 struct ElementChangeInfo *change = &element_info[element].change_page[page];
8008 int old_element = Feld[x][y];
8010 /* always use default change event to prevent running into a loop */
8011 if (ChangeEvent[x][y] == -1)
8012 ChangeEvent[x][y] = CE_DELAY;
8014 if (ChangeEvent[x][y] == CE_DELAY)
8016 /* reset actual trigger element, trigger player and action element */
8017 change->actual_trigger_element = EL_EMPTY;
8018 change->actual_trigger_player = EL_PLAYER_1;
8019 change->actual_trigger_side = CH_SIDE_NONE;
8020 change->actual_trigger_ce_value = 0;
8023 /* do not change elements more than a specified maximum number of changes */
8024 if (ChangeCount[x][y] >= game.max_num_changes_per_frame)
8027 ChangeCount[x][y]++; /* count number of changes in the same frame */
8029 if (change->explode)
8036 if (change->use_target_content)
8038 boolean complete_replace = TRUE;
8039 boolean can_replace[3][3];
8042 for (yy = 0; yy < 3; yy++) for (xx = 0; xx < 3 ; xx++)
8045 boolean is_walkable;
8046 boolean is_diggable;
8047 boolean is_collectible;
8048 boolean is_removable;
8049 boolean is_destructible;
8050 int ex = x + xx - 1;
8051 int ey = y + yy - 1;
8052 int content_element = change->target_content.e[xx][yy];
8055 can_replace[xx][yy] = TRUE;
8057 if (ex == x && ey == y) /* do not check changing element itself */
8060 if (content_element == EL_EMPTY_SPACE)
8062 can_replace[xx][yy] = FALSE; /* do not replace border with space */
8067 if (!IN_LEV_FIELD(ex, ey))
8069 can_replace[xx][yy] = FALSE;
8070 complete_replace = FALSE;
8077 if (IS_MOVING(ex, ey) || IS_BLOCKED(ex, ey))
8078 e = MovingOrBlocked2Element(ex, ey);
8080 is_empty = (IS_FREE(ex, ey) ||
8081 (IS_FREE_OR_PLAYER(ex, ey) && IS_WALKABLE(content_element)));
8083 is_walkable = (is_empty || IS_WALKABLE(e));
8084 is_diggable = (is_empty || IS_DIGGABLE(e));
8085 is_collectible = (is_empty || IS_COLLECTIBLE(e));
8086 is_destructible = (is_empty || !IS_INDESTRUCTIBLE(e));
8087 is_removable = (is_diggable || is_collectible);
8089 can_replace[xx][yy] =
8090 (((change->replace_when == CP_WHEN_EMPTY && is_empty) ||
8091 (change->replace_when == CP_WHEN_WALKABLE && is_walkable) ||
8092 (change->replace_when == CP_WHEN_DIGGABLE && is_diggable) ||
8093 (change->replace_when == CP_WHEN_COLLECTIBLE && is_collectible) ||
8094 (change->replace_when == CP_WHEN_REMOVABLE && is_removable) ||
8095 (change->replace_when == CP_WHEN_DESTRUCTIBLE && is_destructible)) &&
8096 !(IS_PLAYER(ex, ey) && ELEM_IS_PLAYER(content_element)));
8098 if (!can_replace[xx][yy])
8099 complete_replace = FALSE;
8102 if (!change->only_if_complete || complete_replace)
8104 boolean something_has_changed = FALSE;
8106 if (change->only_if_complete && change->use_random_replace &&
8107 RND(100) < change->random_percentage)
8110 for (yy = 0; yy < 3; yy++) for (xx = 0; xx < 3 ; xx++)
8112 int ex = x + xx - 1;
8113 int ey = y + yy - 1;
8114 int content_element;
8116 if (can_replace[xx][yy] && (!change->use_random_replace ||
8117 RND(100) < change->random_percentage))
8119 if (IS_MOVING(ex, ey) || IS_BLOCKED(ex, ey))
8120 RemoveMovingField(ex, ey);
8122 ChangeEvent[ex][ey] = ChangeEvent[x][y];
8124 content_element = change->target_content.e[xx][yy];
8125 target_element = GET_TARGET_ELEMENT(content_element, change);
8127 CreateElementFromChange(ex, ey, target_element);
8129 something_has_changed = TRUE;
8131 /* for symmetry reasons, freeze newly created border elements */
8132 if (ex != x || ey != y)
8133 Stop[ex][ey] = TRUE; /* no more moving in this frame */
8137 if (something_has_changed)
8139 PlayLevelSoundElementAction(x, y, element, ACTION_CHANGING);
8140 PlayLevelSoundElementAction(x, y, element, ACTION_PAGE_1 + page);
8146 target_element = GET_TARGET_ELEMENT(change->target_element, change);
8148 if (element == EL_DIAGONAL_GROWING ||
8149 element == EL_DIAGONAL_SHRINKING)
8151 target_element = Store[x][y];
8153 Store[x][y] = EL_EMPTY;
8156 CreateElementFromChange(x, y, target_element);
8158 PlayLevelSoundElementAction(x, y, element, ACTION_CHANGING);
8159 PlayLevelSoundElementAction(x, y, element, ACTION_PAGE_1 + page);
8162 /* this uses direct change before indirect change */
8163 CheckTriggeredElementChangeByPage(x, y, old_element, CE_CHANGE_OF_X, page);
8168 #if USE_NEW_DELAYED_ACTION
8170 static void HandleElementChange(int x, int y, int page)
8172 int element = MovingOrBlocked2Element(x, y);
8173 struct ElementInfo *ei = &element_info[element];
8174 struct ElementChangeInfo *change = &ei->change_page[page];
8177 if (!CAN_CHANGE_OR_HAS_ACTION(element) &&
8178 !CAN_CHANGE_OR_HAS_ACTION(Back[x][y]))
8181 printf("HandleElementChange(): %d,%d: element = %d ('%s')\n",
8182 x, y, element, element_info[element].token_name);
8183 printf("HandleElementChange(): This should never happen!\n");
8188 /* this can happen with classic bombs on walkable, changing elements */
8189 if (!CAN_CHANGE_OR_HAS_ACTION(element))
8192 if (!CAN_CHANGE(Back[x][y])) /* prevent permanent repetition */
8193 ChangeDelay[x][y] = 0;
8199 if (ChangeDelay[x][y] == 0) /* initialize element change */
8201 ChangeDelay[x][y] = GET_CHANGE_DELAY(change) + 1;
8203 if (change->can_change)
8205 ResetGfxAnimation(x, y);
8206 ResetRandomAnimationValue(x, y);
8208 if (change->pre_change_function)
8209 change->pre_change_function(x, y);
8213 ChangeDelay[x][y]--;
8215 if (ChangeDelay[x][y] != 0) /* continue element change */
8217 if (change->can_change)
8219 int graphic = el_act_dir2img(element, GfxAction[x][y], GfxDir[x][y]);
8221 if (IS_ANIMATED(graphic))
8222 DrawLevelGraphicAnimationIfNeeded(x, y, graphic);
8224 if (change->change_function)
8225 change->change_function(x, y);
8228 else /* finish element change */
8230 if (ChangePage[x][y] != -1) /* remember page from delayed change */
8232 page = ChangePage[x][y];
8233 ChangePage[x][y] = -1;
8235 change = &ei->change_page[page];
8238 if (IS_MOVING(x, y)) /* never change a running system ;-) */
8240 ChangeDelay[x][y] = 1; /* try change after next move step */
8241 ChangePage[x][y] = page; /* remember page to use for change */
8246 if (change->can_change)
8248 if (ChangeElement(x, y, element, page))
8250 if (change->post_change_function)
8251 change->post_change_function(x, y);
8255 if (change->has_action)
8256 ExecuteCustomElementAction(x, y, element, page);
8262 static void HandleElementChange(int x, int y, int page)
8264 int element = MovingOrBlocked2Element(x, y);
8265 struct ElementInfo *ei = &element_info[element];
8266 struct ElementChangeInfo *change = &ei->change_page[page];
8269 if (!CAN_CHANGE(element) && !CAN_CHANGE(Back[x][y]))
8272 printf("HandleElementChange(): %d,%d: element = %d ('%s')\n",
8273 x, y, element, element_info[element].token_name);
8274 printf("HandleElementChange(): This should never happen!\n");
8279 /* this can happen with classic bombs on walkable, changing elements */
8280 if (!CAN_CHANGE(element))
8283 if (!CAN_CHANGE(Back[x][y])) /* prevent permanent repetition */
8284 ChangeDelay[x][y] = 0;
8290 if (ChangeDelay[x][y] == 0) /* initialize element change */
8292 ChangeDelay[x][y] = GET_CHANGE_DELAY(change) + 1;
8294 ResetGfxAnimation(x, y);
8295 ResetRandomAnimationValue(x, y);
8297 if (change->pre_change_function)
8298 change->pre_change_function(x, y);
8301 ChangeDelay[x][y]--;
8303 if (ChangeDelay[x][y] != 0) /* continue element change */
8305 int graphic = el_act_dir2img(element, GfxAction[x][y], GfxDir[x][y]);
8307 if (IS_ANIMATED(graphic))
8308 DrawLevelGraphicAnimationIfNeeded(x, y, graphic);
8310 if (change->change_function)
8311 change->change_function(x, y);
8313 else /* finish element change */
8315 if (ChangePage[x][y] != -1) /* remember page from delayed change */
8317 page = ChangePage[x][y];
8318 ChangePage[x][y] = -1;
8320 change = &ei->change_page[page];
8323 if (IS_MOVING(x, y)) /* never change a running system ;-) */
8325 ChangeDelay[x][y] = 1; /* try change after next move step */
8326 ChangePage[x][y] = page; /* remember page to use for change */
8331 if (ChangeElement(x, y, element, page))
8333 if (change->post_change_function)
8334 change->post_change_function(x, y);
8341 static boolean CheckTriggeredElementChangeExt(int trigger_x, int trigger_y,
8342 int trigger_element,
8348 boolean change_done_any = FALSE;
8349 int trigger_page_bits = (trigger_page < 0 ? CH_PAGE_ANY : 1 << trigger_page);
8352 if (!(trigger_events[trigger_element][trigger_event]))
8355 for (i = 0; i < NUM_CUSTOM_ELEMENTS; i++)
8357 int element = EL_CUSTOM_START + i;
8358 boolean change_done = FALSE;
8361 if (!CAN_CHANGE_OR_HAS_ACTION(element) ||
8362 !HAS_ANY_CHANGE_EVENT(element, trigger_event))
8365 for (p = 0; p < element_info[element].num_change_pages; p++)
8367 struct ElementChangeInfo *change = &element_info[element].change_page[p];
8369 if (change->can_change_or_has_action &&
8370 change->has_event[trigger_event] &&
8371 change->trigger_side & trigger_side &&
8372 change->trigger_player & trigger_player &&
8373 change->trigger_page & trigger_page_bits &&
8374 IS_EQUAL_OR_IN_GROUP(trigger_element, change->trigger_element))
8376 change->actual_trigger_element = trigger_element;
8377 change->actual_trigger_player = EL_PLAYER_1 + log_2(trigger_player);
8378 change->actual_trigger_side = trigger_side;
8379 change->actual_trigger_ce_value = CustomValue[trigger_x][trigger_y];
8381 if ((change->can_change && !change_done) || change->has_action)
8386 SCAN_PLAYFIELD(x, y)
8388 for (y = 0; y < lev_fieldy; y++) for (x = 0; x < lev_fieldx; x++)
8391 if (Feld[x][y] == element)
8393 if (change->can_change && !change_done)
8395 ChangeDelay[x][y] = 1;
8396 ChangeEvent[x][y] = trigger_event;
8398 HandleElementChange(x, y, p);
8400 #if USE_NEW_DELAYED_ACTION
8401 else if (change->has_action)
8403 ExecuteCustomElementAction(x, y, element, p);
8404 PlayLevelSoundElementAction(x, y, element, ACTION_PAGE_1 + p);
8407 if (change->has_action)
8409 ExecuteCustomElementAction(x, y, element, p);
8410 PlayLevelSoundElementAction(x, y, element, ACTION_PAGE_1 + p);
8416 if (change->can_change)
8419 change_done_any = TRUE;
8426 return change_done_any;
8429 static boolean CheckElementChangeExt(int x, int y,
8431 int trigger_element,
8436 boolean change_done = FALSE;
8439 if (!CAN_CHANGE_OR_HAS_ACTION(element) ||
8440 !HAS_ANY_CHANGE_EVENT(element, trigger_event))
8443 if (Feld[x][y] == EL_BLOCKED)
8445 Blocked2Moving(x, y, &x, &y);
8446 element = Feld[x][y];
8450 /* check if element has already changed */
8451 if (Feld[x][y] != element)
8454 /* check if element has already changed or is about to change after moving */
8455 if ((game.engine_version < VERSION_IDENT(3,2,0,7) &&
8456 Feld[x][y] != element) ||
8458 (game.engine_version >= VERSION_IDENT(3,2,0,7) &&
8459 (ChangeCount[x][y] >= game.max_num_changes_per_frame ||
8460 ChangePage[x][y] != -1)))
8464 for (p = 0; p < element_info[element].num_change_pages; p++)
8466 struct ElementChangeInfo *change = &element_info[element].change_page[p];
8468 boolean check_trigger_element =
8469 (trigger_event == CE_TOUCHING_X ||
8470 trigger_event == CE_HITTING_X ||
8471 trigger_event == CE_HIT_BY_X);
8473 if (change->can_change_or_has_action &&
8474 change->has_event[trigger_event] &&
8475 change->trigger_side & trigger_side &&
8476 change->trigger_player & trigger_player &&
8477 (!check_trigger_element ||
8478 IS_EQUAL_OR_IN_GROUP(trigger_element, change->trigger_element)))
8480 change->actual_trigger_element = trigger_element;
8481 change->actual_trigger_player = EL_PLAYER_1 + log_2(trigger_player);
8482 change->actual_trigger_side = trigger_side;
8483 change->actual_trigger_ce_value = CustomValue[x][y];
8485 /* special case: trigger element not at (x,y) position for some events */
8486 if (check_trigger_element)
8498 { 0, 0 }, { 0, 0 }, { 0, 0 },
8502 int xx = x + move_xy[MV_DIR_OPPOSITE(trigger_side)].dx;
8503 int yy = y + move_xy[MV_DIR_OPPOSITE(trigger_side)].dy;
8505 change->actual_trigger_ce_value = CustomValue[xx][yy];
8508 if (change->can_change && !change_done)
8510 ChangeDelay[x][y] = 1;
8511 ChangeEvent[x][y] = trigger_event;
8513 HandleElementChange(x, y, p);
8517 #if USE_NEW_DELAYED_ACTION
8518 else if (change->has_action)
8520 ExecuteCustomElementAction(x, y, element, p);
8521 PlayLevelSoundElementAction(x, y, element, ACTION_PAGE_1 + p);
8524 if (change->has_action)
8526 ExecuteCustomElementAction(x, y, element, p);
8527 PlayLevelSoundElementAction(x, y, element, ACTION_PAGE_1 + p);
8536 static void PlayPlayerSound(struct PlayerInfo *player)
8538 int jx = player->jx, jy = player->jy;
8539 int sound_element = player->artwork_element;
8540 int last_action = player->last_action_waiting;
8541 int action = player->action_waiting;
8543 if (player->is_waiting)
8545 if (action != last_action)
8546 PlayLevelSoundElementAction(jx, jy, sound_element, action);
8548 PlayLevelSoundElementActionIfLoop(jx, jy, sound_element, action);
8552 if (action != last_action)
8553 StopSound(element_info[sound_element].sound[last_action]);
8555 if (last_action == ACTION_SLEEPING)
8556 PlayLevelSoundElementAction(jx, jy, sound_element, ACTION_AWAKENING);
8560 static void PlayAllPlayersSound()
8564 for (i = 0; i < MAX_PLAYERS; i++)
8565 if (stored_player[i].active)
8566 PlayPlayerSound(&stored_player[i]);
8569 static void SetPlayerWaiting(struct PlayerInfo *player, boolean is_waiting)
8571 boolean last_waiting = player->is_waiting;
8572 int move_dir = player->MovDir;
8574 player->last_action_waiting = player->action_waiting;
8578 if (!last_waiting) /* not waiting -> waiting */
8580 player->is_waiting = TRUE;
8582 player->frame_counter_bored =
8584 game.player_boring_delay_fixed +
8585 SimpleRND(game.player_boring_delay_random);
8586 player->frame_counter_sleeping =
8588 game.player_sleeping_delay_fixed +
8589 SimpleRND(game.player_sleeping_delay_random);
8591 InitPlayerGfxAnimation(player, ACTION_WAITING, player->MovDir);
8594 if (game.player_sleeping_delay_fixed +
8595 game.player_sleeping_delay_random > 0 &&
8596 player->anim_delay_counter == 0 &&
8597 player->post_delay_counter == 0 &&
8598 FrameCounter >= player->frame_counter_sleeping)
8599 player->is_sleeping = TRUE;
8600 else if (game.player_boring_delay_fixed +
8601 game.player_boring_delay_random > 0 &&
8602 FrameCounter >= player->frame_counter_bored)
8603 player->is_bored = TRUE;
8605 player->action_waiting = (player->is_sleeping ? ACTION_SLEEPING :
8606 player->is_bored ? ACTION_BORING :
8609 if (player->is_sleeping)
8611 if (player->num_special_action_sleeping > 0)
8613 if (player->anim_delay_counter == 0 && player->post_delay_counter == 0)
8615 int last_special_action = player->special_action_sleeping;
8616 int num_special_action = player->num_special_action_sleeping;
8617 int special_action =
8618 (last_special_action == ACTION_DEFAULT ? ACTION_SLEEPING_1 :
8619 last_special_action == ACTION_SLEEPING ? ACTION_SLEEPING :
8620 last_special_action < ACTION_SLEEPING_1 + num_special_action - 1 ?
8621 last_special_action + 1 : ACTION_SLEEPING);
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_sleeping = special_action;
8635 if (player->anim_delay_counter > 0)
8637 player->action_waiting = player->special_action_sleeping;
8638 player->anim_delay_counter--;
8640 else if (player->post_delay_counter > 0)
8642 player->post_delay_counter--;
8646 else if (player->is_bored)
8648 if (player->num_special_action_bored > 0)
8650 if (player->anim_delay_counter == 0 && player->post_delay_counter == 0)
8652 int special_action =
8653 ACTION_BORING_1 + SimpleRND(player->num_special_action_bored);
8654 int special_graphic =
8655 el_act_dir2img(player->artwork_element, special_action, move_dir);
8657 player->anim_delay_counter =
8658 graphic_info[special_graphic].anim_delay_fixed +
8659 SimpleRND(graphic_info[special_graphic].anim_delay_random);
8660 player->post_delay_counter =
8661 graphic_info[special_graphic].post_delay_fixed +
8662 SimpleRND(graphic_info[special_graphic].post_delay_random);
8664 player->special_action_bored = special_action;
8667 if (player->anim_delay_counter > 0)
8669 player->action_waiting = player->special_action_bored;
8670 player->anim_delay_counter--;
8672 else if (player->post_delay_counter > 0)
8674 player->post_delay_counter--;
8679 else if (last_waiting) /* waiting -> not waiting */
8681 player->is_waiting = FALSE;
8682 player->is_bored = FALSE;
8683 player->is_sleeping = FALSE;
8685 player->frame_counter_bored = -1;
8686 player->frame_counter_sleeping = -1;
8688 player->anim_delay_counter = 0;
8689 player->post_delay_counter = 0;
8691 player->action_waiting = ACTION_DEFAULT;
8693 player->special_action_bored = ACTION_DEFAULT;
8694 player->special_action_sleeping = ACTION_DEFAULT;
8698 static byte PlayerActions(struct PlayerInfo *player, byte player_action)
8700 boolean moved = FALSE, snapped = FALSE, dropped = FALSE;
8701 int left = player_action & JOY_LEFT;
8702 int right = player_action & JOY_RIGHT;
8703 int up = player_action & JOY_UP;
8704 int down = player_action & JOY_DOWN;
8705 int button1 = player_action & JOY_BUTTON_1;
8706 int button2 = player_action & JOY_BUTTON_2;
8707 int dx = (left ? -1 : right ? 1 : 0);
8708 int dy = (up ? -1 : down ? 1 : 0);
8710 if (!player->active || tape.pausing)
8716 snapped = SnapField(player, dx, dy);
8720 dropped = DropElement(player);
8722 moved = MovePlayer(player, dx, dy);
8725 if (tape.single_step && tape.recording && !tape.pausing)
8727 if (button1 || (dropped && !moved))
8729 TapeTogglePause(TAPE_TOGGLE_AUTOMATIC);
8730 SnapField(player, 0, 0); /* stop snapping */
8734 SetPlayerWaiting(player, FALSE);
8736 return player_action;
8740 /* no actions for this player (no input at player's configured device) */
8742 DigField(player, 0, 0, 0, 0, 0, 0, DF_NO_PUSH);
8743 SnapField(player, 0, 0);
8744 CheckGravityMovementWhenNotMoving(player);
8746 if (player->MovPos == 0)
8747 SetPlayerWaiting(player, TRUE);
8749 if (player->MovPos == 0) /* needed for tape.playing */
8750 player->is_moving = FALSE;
8752 player->is_dropping = FALSE;
8758 void AdvanceFrameAndPlayerCounters(int player_nr)
8762 /* advance frame counters (global frame counter and time frame counter) */
8766 /* advance player counters (counters for move delay, move animation etc.) */
8767 for (i = 0; i < MAX_PLAYERS; i++)
8769 boolean advance_player_counters = (player_nr == -1 || player_nr == i);
8770 int move_delay_value = stored_player[i].move_delay_value;
8771 int move_frames = MOVE_DELAY_NORMAL_SPEED / move_delay_value;
8773 if (!advance_player_counters) /* not all players may be affected */
8776 #if USE_NEW_PLAYER_ANIM
8777 if (move_frames == 0) /* less than one move per game frame */
8779 int stepsize = TILEX / move_delay_value;
8780 int delay = move_delay_value / MOVE_DELAY_NORMAL_SPEED;
8781 int count = (stored_player[i].is_moving ?
8782 ABS(stored_player[i].MovPos) / stepsize : FrameCounter);
8784 if (count % delay == 0)
8789 stored_player[i].Frame += move_frames;
8791 if (stored_player[i].MovPos != 0)
8792 stored_player[i].StepFrame += move_frames;
8794 if (stored_player[i].move_delay > 0)
8795 stored_player[i].move_delay--;
8797 /* due to bugs in previous versions, counter must count up, not down */
8798 if (stored_player[i].push_delay != -1)
8799 stored_player[i].push_delay++;
8801 if (stored_player[i].drop_delay > 0)
8802 stored_player[i].drop_delay--;
8808 static unsigned long game_frame_delay = 0;
8809 unsigned long game_frame_delay_value;
8810 int magic_wall_x = 0, magic_wall_y = 0;
8811 int i, x, y, element, graphic;
8812 byte *recorded_player_action;
8813 byte summarized_player_action = 0;
8814 byte tape_action[MAX_PLAYERS];
8816 if (game_status != GAME_MODE_PLAYING)
8819 game_frame_delay_value =
8820 (tape.playing && tape.fast_forward ? FfwdFrameDelay : GameFrameDelay);
8822 if (tape.playing && tape.warp_forward && !tape.pausing)
8823 game_frame_delay_value = 0;
8825 /* ---------- main game synchronization point ---------- */
8827 WaitUntilDelayReached(&game_frame_delay, game_frame_delay_value);
8829 InitPlayfieldScanModeVars();
8831 if (ScreenMovPos == 0) /* screen currently aligned at tile position */
8833 struct PlayerInfo *player;
8834 int player_nr = game.centered_player_nr_next;
8836 if (game.centered_player_nr_next == -1)
8837 player_nr = local_player->index_nr;
8839 player = &stored_player[player_nr];
8841 if (!player->active)
8842 game.centered_player_nr_next = game.centered_player_nr;
8844 if (game.centered_player_nr != game.centered_player_nr_next)
8846 DrawRelocatePlayer(player, setup.quick_switch);
8848 game.centered_player_nr = game.centered_player_nr_next;
8852 #if USE_ONE_MORE_CHANGE_PER_FRAME
8853 if (game.engine_version >= VERSION_IDENT(3,2,0,7))
8855 SCAN_PLAYFIELD(x, y)
8857 ChangeCount[x][y] = 0;
8858 ChangeEvent[x][y] = -1;
8863 if (network_playing && !network_player_action_received)
8865 /* try to get network player actions in time */
8867 #if defined(NETWORK_AVALIABLE)
8868 /* last chance to get network player actions without main loop delay */
8872 /* game was quit by network peer */
8873 if (game_status != GAME_MODE_PLAYING)
8876 if (!network_player_action_received)
8877 return; /* failed to get network player actions in time */
8883 recorded_player_action = (tape.playing ? TapePlayAction() : NULL);
8886 /* !!! CHECK THIS (tape.pausing is always FALSE here!) !!! */
8887 if (recorded_player_action == NULL && tape.pausing)
8891 for (i = 0; i < MAX_PLAYERS; i++)
8893 summarized_player_action |= stored_player[i].action;
8895 if (!network_playing)
8896 stored_player[i].effective_action = stored_player[i].action;
8899 #if defined(NETWORK_AVALIABLE)
8900 if (network_playing)
8901 SendToServer_MovePlayer(summarized_player_action);
8904 if (!options.network && !setup.team_mode)
8905 local_player->effective_action = summarized_player_action;
8907 if (recorded_player_action != NULL)
8908 for (i = 0; i < MAX_PLAYERS; i++)
8909 stored_player[i].effective_action = recorded_player_action[i];
8911 for (i = 0; i < MAX_PLAYERS; i++)
8913 tape_action[i] = stored_player[i].effective_action;
8915 if (tape.recording && tape_action[i] && !tape.player_participates[i])
8916 tape.player_participates[i] = TRUE; /* player just appeared from CE */
8919 /* only save actions from input devices, but not programmed actions */
8921 TapeRecordAction(tape_action);
8923 for (i = 0; i < MAX_PLAYERS; i++)
8925 int actual_player_action = stored_player[i].effective_action;
8928 /* !!! THIS BREAKS THE FOLLOWING TAPES: !!!
8929 - rnd_equinox_tetrachloride 048
8930 - rnd_equinox_tetrachloride_ii 096
8931 - rnd_emanuel_schmieg 002
8932 - doctor_sloan_ww 001, 020
8934 if (stored_player[i].MovPos == 0)
8935 CheckGravityMovement(&stored_player[i]);
8938 /* overwrite programmed action with tape action */
8939 if (stored_player[i].programmed_action)
8940 actual_player_action = stored_player[i].programmed_action;
8943 PlayerActions(&stored_player[i], actual_player_action);
8945 tape_action[i] = PlayerActions(&stored_player[i], actual_player_action);
8947 if (tape.recording && tape_action[i] && !tape.player_participates[i])
8948 tape.player_participates[i] = TRUE; /* player just appeared from CE */
8951 ScrollPlayer(&stored_player[i], SCROLL_GO_ON);
8954 network_player_action_received = FALSE;
8956 ScrollScreen(NULL, SCROLL_GO_ON);
8958 /* for backwards compatibility, the following code emulates a fixed bug that
8959 occured when pushing elements (causing elements that just made their last
8960 pushing step to already (if possible) make their first falling step in the
8961 same game frame, which is bad); this code is also needed to use the famous
8962 "spring push bug" which is used in older levels and might be wanted to be
8963 used also in newer levels, but in this case the buggy pushing code is only
8964 affecting the "spring" element and no other elements */
8966 if (game.engine_version < VERSION_IDENT(2,2,0,7) || level.use_spring_bug)
8968 for (i = 0; i < MAX_PLAYERS; i++)
8970 struct PlayerInfo *player = &stored_player[i];
8974 if (player->active && player->is_pushing && player->is_moving &&
8976 (game.engine_version < VERSION_IDENT(2,2,0,7) ||
8977 Feld[x][y] == EL_SPRING))
8979 ContinueMoving(x, y);
8981 /* continue moving after pushing (this is actually a bug) */
8982 if (!IS_MOVING(x, y))
8991 SCAN_PLAYFIELD(x, y)
8993 for (y = 0; y < lev_fieldy; y++) for (x = 0; x < lev_fieldx; x++)
8996 ChangeCount[x][y] = 0;
8997 ChangeEvent[x][y] = -1;
8999 /* this must be handled before main playfield loop */
9000 if (Feld[x][y] == EL_PLAYER_IS_LEAVING)
9003 if (MovDelay[x][y] <= 0)
9007 #if USE_NEW_SNAP_DELAY
9008 if (Feld[x][y] == EL_ELEMENT_SNAPPING)
9011 if (MovDelay[x][y] <= 0)
9014 DrawLevelField(x, y);
9016 TestIfElementTouchesCustomElement(x, y); /* for empty space */
9022 if (ChangePage[x][y] != -1 && ChangeDelay[x][y] != 1)
9024 printf("GameActions(): x = %d, y = %d: ChangePage != -1\n", x, y);
9025 printf("GameActions(): This should never happen!\n");
9027 ChangePage[x][y] = -1;
9032 if (WasJustMoving[x][y] > 0)
9033 WasJustMoving[x][y]--;
9034 if (WasJustFalling[x][y] > 0)
9035 WasJustFalling[x][y]--;
9036 if (CheckCollision[x][y] > 0)
9037 CheckCollision[x][y]--;
9041 /* reset finished pushing action (not done in ContinueMoving() to allow
9042 continuous pushing animation for elements with zero push delay) */
9043 if (GfxAction[x][y] == ACTION_PUSHING && !IS_MOVING(x, y))
9045 ResetGfxAnimation(x, y);
9046 DrawLevelField(x, y);
9050 if (IS_BLOCKED(x, y))
9054 Blocked2Moving(x, y, &oldx, &oldy);
9055 if (!IS_MOVING(oldx, oldy))
9057 printf("GameActions(): (BLOCKED => MOVING) context corrupted!\n");
9058 printf("GameActions(): BLOCKED: x = %d, y = %d\n", x, y);
9059 printf("GameActions(): !MOVING: oldx = %d, oldy = %d\n", oldx, oldy);
9060 printf("GameActions(): This should never happen!\n");
9067 SCAN_PLAYFIELD(x, y)
9069 for (y = 0; y < lev_fieldy; y++) for (x = 0; x < lev_fieldx; x++)
9072 element = Feld[x][y];
9073 graphic = el_act_dir2img(element, GfxAction[x][y], GfxDir[x][y]);
9076 printf("::: %d,%d\n", x, y);
9078 if (element == EL_ROCK)
9079 printf("::: Yo man! Rocks can fall!\n");
9082 if (graphic_info[graphic].anim_global_sync)
9083 GfxFrame[x][y] = FrameCounter;
9084 else if (ANIM_MODE(graphic) == ANIM_CE_VALUE)
9086 int old_gfx_frame = GfxFrame[x][y];
9088 GfxFrame[x][y] = CustomValue[x][y];
9091 if (GfxFrame[x][y] != old_gfx_frame)
9093 DrawLevelGraphicAnimation(x, y, graphic);
9095 else if (ANIM_MODE(graphic) == ANIM_CE_SCORE)
9097 int old_gfx_frame = GfxFrame[x][y];
9099 GfxFrame[x][y] = element_info[element].collect_score;
9102 if (GfxFrame[x][y] != old_gfx_frame)
9104 DrawLevelGraphicAnimation(x, y, graphic);
9107 if (ANIM_MODE(graphic) == ANIM_RANDOM &&
9108 IS_NEXT_FRAME(GfxFrame[x][y], graphic))
9109 ResetRandomAnimationValue(x, y);
9111 SetRandomAnimationValue(x, y);
9113 PlayLevelSoundActionIfLoop(x, y, GfxAction[x][y]);
9115 if (IS_INACTIVE(element))
9117 if (IS_ANIMATED(graphic))
9118 DrawLevelGraphicAnimationIfNeeded(x, y, graphic);
9123 /* this may take place after moving, so 'element' may have changed */
9124 if (IS_CHANGING(x, y) &&
9125 (game.engine_version < VERSION_IDENT(3,0,7,1) || !Stop[x][y]))
9127 int page = element_info[element].event_page_nr[CE_DELAY];
9129 HandleElementChange(x, y, ChangePage[x][y] != -1 ? ChangePage[x][y] : page);
9133 printf("::: ChangeDelay == %d\n", ChangeDelay[x][y]);
9137 if (element == EL_CUSTOM_255)
9138 printf("::: ChangeDelay == %d\n", ChangeDelay[x][y]);
9142 HandleElementChange(x, y, page);
9144 if (CAN_CHANGE(element))
9145 HandleElementChange(x, y, page);
9147 if (HAS_ACTION(element))
9148 ExecuteCustomElementAction(x, y, element, page);
9153 element = Feld[x][y];
9154 graphic = el_act_dir2img(element, GfxAction[x][y], GfxDir[x][y]);
9157 if (!IS_MOVING(x, y) && (CAN_FALL(element) || CAN_MOVE(element)))
9161 element = Feld[x][y];
9162 graphic = el_act_dir2img(element, GfxAction[x][y], GfxDir[x][y]);
9164 if (IS_ANIMATED(graphic) &&
9167 DrawLevelGraphicAnimationIfNeeded(x, y, graphic);
9169 if (IS_GEM(element) || element == EL_SP_INFOTRON)
9170 EdelsteinFunkeln(x, y);
9172 else if ((element == EL_ACID ||
9173 element == EL_EXIT_OPEN ||
9174 element == EL_SP_EXIT_OPEN ||
9175 element == EL_SP_TERMINAL ||
9176 element == EL_SP_TERMINAL_ACTIVE ||
9177 element == EL_EXTRA_TIME ||
9178 element == EL_SHIELD_NORMAL ||
9179 element == EL_SHIELD_DEADLY) &&
9180 IS_ANIMATED(graphic))
9181 DrawLevelGraphicAnimationIfNeeded(x, y, graphic);
9182 else if (IS_MOVING(x, y))
9183 ContinueMoving(x, y);
9184 else if (IS_ACTIVE_BOMB(element))
9185 CheckDynamite(x, y);
9186 else if (element == EL_AMOEBA_GROWING)
9187 AmoebeWaechst(x, y);
9188 else if (element == EL_AMOEBA_SHRINKING)
9189 AmoebaDisappearing(x, y);
9191 #if !USE_NEW_AMOEBA_CODE
9192 else if (IS_AMOEBALIVE(element))
9193 AmoebeAbleger(x, y);
9196 else if (element == EL_GAME_OF_LIFE || element == EL_BIOMAZE)
9198 else if (element == EL_EXIT_CLOSED)
9200 else if (element == EL_SP_EXIT_CLOSED)
9202 else if (element == EL_EXPANDABLE_WALL_GROWING)
9204 else if (element == EL_EXPANDABLE_WALL ||
9205 element == EL_EXPANDABLE_WALL_HORIZONTAL ||
9206 element == EL_EXPANDABLE_WALL_VERTICAL ||
9207 element == EL_EXPANDABLE_WALL_ANY)
9209 else if (element == EL_FLAMES)
9210 CheckForDragon(x, y);
9211 else if (element == EL_EXPLOSION)
9212 ; /* drawing of correct explosion animation is handled separately */
9213 else if (element == EL_ELEMENT_SNAPPING ||
9214 element == EL_DIAGONAL_SHRINKING ||
9215 element == EL_DIAGONAL_GROWING)
9218 graphic = el_act_dir2img(GfxElement[x][y], GfxAction[x][y],GfxDir[x][y]);
9220 DrawLevelGraphicAnimationIfNeeded(x, y, graphic);
9223 else if (IS_ANIMATED(graphic) && !IS_CHANGING(x, y))
9224 DrawLevelGraphicAnimationIfNeeded(x, y, graphic);
9227 if (element == EL_CUSTOM_255 ||
9228 element == EL_CUSTOM_256)
9229 DrawLevelGraphicAnimation(x, y, graphic);
9232 if (IS_BELT_ACTIVE(element))
9233 PlayLevelSoundAction(x, y, ACTION_ACTIVE);
9235 if (game.magic_wall_active)
9237 int jx = local_player->jx, jy = local_player->jy;
9239 /* play the element sound at the position nearest to the player */
9240 if ((element == EL_MAGIC_WALL_FULL ||
9241 element == EL_MAGIC_WALL_ACTIVE ||
9242 element == EL_MAGIC_WALL_EMPTYING ||
9243 element == EL_BD_MAGIC_WALL_FULL ||
9244 element == EL_BD_MAGIC_WALL_ACTIVE ||
9245 element == EL_BD_MAGIC_WALL_EMPTYING) &&
9246 ABS(x-jx) + ABS(y-jy) < ABS(magic_wall_x-jx) + ABS(magic_wall_y-jy))
9254 #if USE_NEW_AMOEBA_CODE
9255 /* new experimental amoeba growth stuff */
9256 if (!(FrameCounter % 8))
9258 static unsigned long random = 1684108901;
9260 for (i = 0; i < level.amoeba_speed * 28 / 8; i++)
9262 x = RND(lev_fieldx);
9263 y = RND(lev_fieldy);
9264 element = Feld[x][y];
9266 if (!IS_PLAYER(x,y) &&
9267 (element == EL_EMPTY ||
9268 CAN_GROW_INTO(element) ||
9269 element == EL_QUICKSAND_EMPTY ||
9270 element == EL_ACID_SPLASH_LEFT ||
9271 element == EL_ACID_SPLASH_RIGHT))
9273 if ((IN_LEV_FIELD(x, y-1) && Feld[x][y-1] == EL_AMOEBA_WET) ||
9274 (IN_LEV_FIELD(x-1, y) && Feld[x-1][y] == EL_AMOEBA_WET) ||
9275 (IN_LEV_FIELD(x+1, y) && Feld[x+1][y] == EL_AMOEBA_WET) ||
9276 (IN_LEV_FIELD(x, y+1) && Feld[x][y+1] == EL_AMOEBA_WET))
9277 Feld[x][y] = EL_AMOEBA_DROP;
9280 random = random * 129 + 1;
9286 if (game.explosions_delayed)
9289 game.explosions_delayed = FALSE;
9292 SCAN_PLAYFIELD(x, y)
9294 for (y = 0; y < lev_fieldy; y++) for (x = 0; x < lev_fieldx; x++)
9297 element = Feld[x][y];
9299 if (ExplodeField[x][y])
9300 Explode(x, y, EX_PHASE_START, ExplodeField[x][y]);
9301 else if (element == EL_EXPLOSION)
9302 Explode(x, y, ExplodePhase[x][y], EX_TYPE_NORMAL);
9304 ExplodeField[x][y] = EX_TYPE_NONE;
9307 game.explosions_delayed = TRUE;
9310 if (game.magic_wall_active)
9312 if (!(game.magic_wall_time_left % 4))
9314 int element = Feld[magic_wall_x][magic_wall_y];
9316 if (element == EL_BD_MAGIC_WALL_FULL ||
9317 element == EL_BD_MAGIC_WALL_ACTIVE ||
9318 element == EL_BD_MAGIC_WALL_EMPTYING)
9319 PlayLevelSound(magic_wall_x, magic_wall_y, SND_BD_MAGIC_WALL_ACTIVE);
9321 PlayLevelSound(magic_wall_x, magic_wall_y, SND_MAGIC_WALL_ACTIVE);
9324 if (game.magic_wall_time_left > 0)
9326 game.magic_wall_time_left--;
9327 if (!game.magic_wall_time_left)
9330 SCAN_PLAYFIELD(x, y)
9332 for (y = 0; y < lev_fieldy; y++) for (x = 0; x < lev_fieldx; x++)
9335 element = Feld[x][y];
9337 if (element == EL_MAGIC_WALL_ACTIVE ||
9338 element == EL_MAGIC_WALL_FULL)
9340 Feld[x][y] = EL_MAGIC_WALL_DEAD;
9341 DrawLevelField(x, y);
9343 else if (element == EL_BD_MAGIC_WALL_ACTIVE ||
9344 element == EL_BD_MAGIC_WALL_FULL)
9346 Feld[x][y] = EL_BD_MAGIC_WALL_DEAD;
9347 DrawLevelField(x, y);
9351 game.magic_wall_active = FALSE;
9356 if (game.light_time_left > 0)
9358 game.light_time_left--;
9360 if (game.light_time_left == 0)
9361 RedrawAllLightSwitchesAndInvisibleElements();
9364 if (game.timegate_time_left > 0)
9366 game.timegate_time_left--;
9368 if (game.timegate_time_left == 0)
9369 CloseAllOpenTimegates();
9372 if (game.lenses_time_left > 0)
9374 game.lenses_time_left--;
9376 if (game.lenses_time_left == 0)
9377 RedrawAllInvisibleElementsForLenses();
9380 if (game.magnify_time_left > 0)
9382 game.magnify_time_left--;
9384 if (game.magnify_time_left == 0)
9385 RedrawAllInvisibleElementsForMagnifier();
9388 for (i = 0; i < MAX_PLAYERS; i++)
9390 struct PlayerInfo *player = &stored_player[i];
9392 if (SHIELD_ON(player))
9394 if (player->shield_deadly_time_left)
9395 PlayLevelSound(player->jx, player->jy, SND_SHIELD_DEADLY_ACTIVE);
9396 else if (player->shield_normal_time_left)
9397 PlayLevelSound(player->jx, player->jy, SND_SHIELD_NORMAL_ACTIVE);
9401 if (TimeFrames >= FRAMES_PER_SECOND)
9406 for (i = 0; i < MAX_PLAYERS; i++)
9408 struct PlayerInfo *player = &stored_player[i];
9410 if (SHIELD_ON(player))
9412 player->shield_normal_time_left--;
9414 if (player->shield_deadly_time_left > 0)
9415 player->shield_deadly_time_left--;
9419 if (!level.use_step_counter)
9427 if (TimeLeft <= 10 && setup.time_limit)
9428 PlaySoundStereo(SND_GAME_RUNNING_OUT_OF_TIME, SOUND_MIDDLE);
9430 DrawGameValue_Time(TimeLeft);
9432 if (!TimeLeft && setup.time_limit)
9433 for (i = 0; i < MAX_PLAYERS; i++)
9434 KillPlayer(&stored_player[i]);
9436 else if (level.time == 0 && !AllPlayersGone) /* level w/o time limit */
9437 DrawGameValue_Time(TimePlayed);
9440 if (tape.recording || tape.playing)
9441 DrawVideoDisplay(VIDEO_STATE_TIME_ON, TapeTime);
9445 PlayAllPlayersSound();
9447 if (options.debug) /* calculate frames per second */
9449 static unsigned long fps_counter = 0;
9450 static int fps_frames = 0;
9451 unsigned long fps_delay_ms = Counter() - fps_counter;
9455 if (fps_delay_ms >= 500) /* calculate fps every 0.5 seconds */
9457 global.frames_per_second = 1000 * (float)fps_frames / fps_delay_ms;
9460 fps_counter = Counter();
9463 redraw_mask |= REDRAW_FPS;
9466 AdvanceFrameAndPlayerCounters(-1); /* advance counters for all players */
9468 if (local_player->show_envelope != 0 && local_player->MovPos == 0)
9470 ShowEnvelope(local_player->show_envelope - EL_ENVELOPE_1);
9472 local_player->show_envelope = 0;
9475 /* use random number generator in every frame to make it less predictable */
9476 if (game.engine_version >= VERSION_IDENT(3,1,1,0))
9480 static boolean AllPlayersInSight(struct PlayerInfo *player, int x, int y)
9482 int min_x = x, min_y = y, max_x = x, max_y = y;
9485 for (i = 0; i < MAX_PLAYERS; i++)
9487 int jx = stored_player[i].jx, jy = stored_player[i].jy;
9489 if (!stored_player[i].active || &stored_player[i] == player)
9492 min_x = MIN(min_x, jx);
9493 min_y = MIN(min_y, jy);
9494 max_x = MAX(max_x, jx);
9495 max_y = MAX(max_y, jy);
9498 return (max_x - min_x < SCR_FIELDX && max_y - min_y < SCR_FIELDY);
9501 static boolean AllPlayersInVisibleScreen()
9505 for (i = 0; i < MAX_PLAYERS; i++)
9507 int jx = stored_player[i].jx, jy = stored_player[i].jy;
9509 if (!stored_player[i].active)
9512 if (!IN_VIS_FIELD(SCREENX(jx), SCREENY(jy)))
9519 void ScrollLevel(int dx, int dy)
9521 int softscroll_offset = (setup.soft_scrolling ? TILEX : 0);
9524 BlitBitmap(drawto_field, drawto_field,
9525 FX + TILEX * (dx == -1) - softscroll_offset,
9526 FY + TILEY * (dy == -1) - softscroll_offset,
9527 SXSIZE - TILEX * (dx!=0) + 2 * softscroll_offset,
9528 SYSIZE - TILEY * (dy!=0) + 2 * softscroll_offset,
9529 FX + TILEX * (dx == 1) - softscroll_offset,
9530 FY + TILEY * (dy == 1) - softscroll_offset);
9534 x = (dx == 1 ? BX1 : BX2);
9535 for (y = BY1; y <= BY2; y++)
9536 DrawScreenField(x, y);
9541 y = (dy == 1 ? BY1 : BY2);
9542 for (x = BX1; x <= BX2; x++)
9543 DrawScreenField(x, y);
9546 redraw_mask |= REDRAW_FIELD;
9549 static boolean canFallDown(struct PlayerInfo *player)
9551 int jx = player->jx, jy = player->jy;
9553 return (IN_LEV_FIELD(jx, jy + 1) &&
9554 (IS_FREE(jx, jy + 1) ||
9555 (Feld[jx][jy + 1] == EL_ACID && player->can_fall_into_acid)) &&
9556 IS_WALKABLE_FROM(Feld[jx][jy], MV_DOWN) &&
9557 !IS_WALKABLE_INSIDE(Feld[jx][jy]));
9560 static boolean canPassField(int x, int y, int move_dir)
9562 int opposite_dir = MV_DIR_OPPOSITE(move_dir);
9563 int dx = (move_dir & MV_LEFT ? -1 : move_dir & MV_RIGHT ? +1 : 0);
9564 int dy = (move_dir & MV_UP ? -1 : move_dir & MV_DOWN ? +1 : 0);
9567 int element = Feld[x][y];
9569 return (IS_PASSABLE_FROM(element, opposite_dir) &&
9570 !CAN_MOVE(element) &&
9571 IN_LEV_FIELD(nextx, nexty) && !IS_PLAYER(nextx, nexty) &&
9572 IS_WALKABLE_FROM(Feld[nextx][nexty], move_dir) &&
9573 (level.can_pass_to_walkable || IS_FREE(nextx, nexty)));
9576 static boolean canMoveToValidFieldWithGravity(int x, int y, int move_dir)
9578 int opposite_dir = MV_DIR_OPPOSITE(move_dir);
9579 int dx = (move_dir & MV_LEFT ? -1 : move_dir & MV_RIGHT ? +1 : 0);
9580 int dy = (move_dir & MV_UP ? -1 : move_dir & MV_DOWN ? +1 : 0);
9584 return (IN_LEV_FIELD(newx, newy) && !IS_FREE_OR_PLAYER(newx, newy) &&
9585 IS_GRAVITY_REACHABLE(Feld[newx][newy]) &&
9586 (IS_DIGGABLE(Feld[newx][newy]) ||
9587 IS_WALKABLE_FROM(Feld[newx][newy], opposite_dir) ||
9588 canPassField(newx, newy, move_dir)));
9591 static void CheckGravityMovement(struct PlayerInfo *player)
9593 if (game.gravity && !player->programmed_action)
9595 int move_dir_horizontal = player->effective_action & MV_HORIZONTAL;
9596 int move_dir_vertical = player->effective_action & MV_VERTICAL;
9597 boolean player_is_snapping = player->effective_action & JOY_BUTTON_1;
9598 int jx = player->jx, jy = player->jy;
9599 boolean player_is_moving_to_valid_field =
9600 (!player_is_snapping &&
9601 (canMoveToValidFieldWithGravity(jx, jy, move_dir_horizontal) ||
9602 canMoveToValidFieldWithGravity(jx, jy, move_dir_vertical)));
9603 boolean player_can_fall_down = canFallDown(player);
9605 if (player_can_fall_down &&
9606 !player_is_moving_to_valid_field)
9607 player->programmed_action = MV_DOWN;
9611 static void CheckGravityMovementWhenNotMoving(struct PlayerInfo *player)
9613 return CheckGravityMovement(player);
9615 if (game.gravity && !player->programmed_action)
9617 int jx = player->jx, jy = player->jy;
9618 boolean field_under_player_is_free =
9619 (IN_LEV_FIELD(jx, jy + 1) && IS_FREE(jx, jy + 1));
9620 boolean player_is_standing_on_valid_field =
9621 (IS_WALKABLE_INSIDE(Feld[jx][jy]) ||
9622 (IS_WALKABLE(Feld[jx][jy]) &&
9623 !(element_info[Feld[jx][jy]].access_direction & MV_DOWN)));
9625 if (field_under_player_is_free && !player_is_standing_on_valid_field)
9626 player->programmed_action = MV_DOWN;
9632 -----------------------------------------------------------------------------
9633 dx, dy: direction (non-diagonal) to try to move the player to
9634 real_dx, real_dy: direction as read from input device (can be diagonal)
9637 boolean MovePlayerOneStep(struct PlayerInfo *player,
9638 int dx, int dy, int real_dx, int real_dy)
9640 int jx = player->jx, jy = player->jy;
9641 int new_jx = jx + dx, new_jy = jy + dy;
9642 #if !USE_FIXED_DONT_RUN_INTO
9646 boolean player_can_move = !player->cannot_move;
9648 if (!player->active || (!dx && !dy))
9649 return MP_NO_ACTION;
9651 player->MovDir = (dx < 0 ? MV_LEFT :
9654 dy > 0 ? MV_DOWN : MV_NONE);
9656 if (!IN_LEV_FIELD(new_jx, new_jy))
9657 return MP_NO_ACTION;
9659 if (!player_can_move)
9662 if (player->MovPos == 0)
9664 player->is_moving = FALSE;
9665 player->is_digging = FALSE;
9666 player->is_collecting = FALSE;
9667 player->is_snapping = FALSE;
9668 player->is_pushing = FALSE;
9671 DigField(player, 0, 0, 0, 0, 0, 0, DF_NO_PUSH);
9672 SnapField(player, 0, 0);
9676 return MP_NO_ACTION;
9681 if (!options.network && game.centered_player_nr == -1 &&
9682 !AllPlayersInSight(player, new_jx, new_jy))
9683 return MP_NO_ACTION;
9685 if (!options.network && !AllPlayersInSight(player, new_jx, new_jy))
9686 return MP_NO_ACTION;
9689 #if !USE_FIXED_DONT_RUN_INTO
9690 element = MovingOrBlocked2ElementIfNotLeaving(new_jx, new_jy);
9692 /* (moved to DigField()) */
9693 if (player_can_move && DONT_RUN_INTO(element))
9695 if (element == EL_ACID && dx == 0 && dy == 1)
9697 SplashAcid(new_jx, new_jy);
9698 Feld[jx][jy] = EL_PLAYER_1;
9699 InitMovingField(jx, jy, MV_DOWN);
9700 Store[jx][jy] = EL_ACID;
9701 ContinueMoving(jx, jy);
9705 TestIfPlayerRunsIntoBadThing(jx, jy, player->MovDir);
9711 can_move = DigField(player, jx, jy, new_jx, new_jy, real_dx,real_dy, DF_DIG);
9713 #if USE_FIXED_DONT_RUN_INTO
9714 if (can_move == MP_DONT_RUN_INTO)
9718 if (can_move != MP_MOVING)
9721 #if USE_FIXED_DONT_RUN_INTO
9724 /* check if DigField() has caused relocation of the player */
9725 if (player->jx != jx || player->jy != jy)
9726 return MP_NO_ACTION; /* <-- !!! CHECK THIS [-> MP_ACTION ?] !!! */
9728 StorePlayer[jx][jy] = 0;
9729 player->last_jx = jx;
9730 player->last_jy = jy;
9731 player->jx = new_jx;
9732 player->jy = new_jy;
9733 StorePlayer[new_jx][new_jy] = player->element_nr;
9735 if (player->move_delay_value_next != -1)
9737 player->move_delay_value = player->move_delay_value_next;
9738 player->move_delay_value_next = -1;
9742 (dx > 0 || dy > 0 ? -1 : 1) * (TILEX - TILEX / player->move_delay_value);
9744 player->step_counter++;
9746 PlayerVisit[jx][jy] = FrameCounter;
9748 ScrollPlayer(player, SCROLL_INIT);
9753 boolean MovePlayer(struct PlayerInfo *player, int dx, int dy)
9755 int jx = player->jx, jy = player->jy;
9756 int old_jx = jx, old_jy = jy;
9757 int moved = MP_NO_ACTION;
9759 if (!player->active)
9764 if (player->MovPos == 0)
9766 player->is_moving = FALSE;
9767 player->is_digging = FALSE;
9768 player->is_collecting = FALSE;
9769 player->is_snapping = FALSE;
9770 player->is_pushing = FALSE;
9776 if (player->move_delay > 0)
9779 player->move_delay = -1; /* set to "uninitialized" value */
9781 /* store if player is automatically moved to next field */
9782 player->is_auto_moving = (player->programmed_action != MV_NONE);
9784 /* remove the last programmed player action */
9785 player->programmed_action = 0;
9789 /* should only happen if pre-1.2 tape recordings are played */
9790 /* this is only for backward compatibility */
9792 int original_move_delay_value = player->move_delay_value;
9795 printf("THIS SHOULD ONLY HAPPEN WITH PRE-1.2 LEVEL TAPES. [%ld]\n",
9799 /* scroll remaining steps with finest movement resolution */
9800 player->move_delay_value = MOVE_DELAY_NORMAL_SPEED;
9802 while (player->MovPos)
9804 ScrollPlayer(player, SCROLL_GO_ON);
9805 ScrollScreen(NULL, SCROLL_GO_ON);
9807 AdvanceFrameAndPlayerCounters(player->index_nr);
9813 player->move_delay_value = original_move_delay_value;
9816 if (player->last_move_dir & MV_HORIZONTAL)
9818 if (!(moved |= MovePlayerOneStep(player, 0, dy, dx, dy)))
9819 moved |= MovePlayerOneStep(player, dx, 0, dx, dy);
9823 if (!(moved |= MovePlayerOneStep(player, dx, 0, dx, dy)))
9824 moved |= MovePlayerOneStep(player, 0, dy, dx, dy);
9831 if (moved & MP_MOVING && !ScreenMovPos &&
9832 (player->index_nr == game.centered_player_nr ||
9833 game.centered_player_nr == -1))
9835 if (moved & MP_MOVING && !ScreenMovPos &&
9836 (player == local_player || !options.network))
9839 int old_scroll_x = scroll_x, old_scroll_y = scroll_y;
9840 int offset = (setup.scroll_delay ? 3 : 0);
9842 if (!IN_VIS_FIELD(SCREENX(jx), SCREENY(jy)))
9844 /* actual player has left the screen -- scroll in that direction */
9845 if (jx != old_jx) /* player has moved horizontally */
9846 scroll_x += (jx - old_jx);
9847 else /* player has moved vertically */
9848 scroll_y += (jy - old_jy);
9852 if (jx != old_jx) /* player has moved horizontally */
9854 if ((player->MovDir == MV_LEFT && scroll_x > jx - MIDPOSX + offset) ||
9855 (player->MovDir == MV_RIGHT && scroll_x < jx - MIDPOSX - offset))
9856 scroll_x = jx-MIDPOSX + (scroll_x < jx-MIDPOSX ? -offset : +offset);
9858 /* don't scroll over playfield boundaries */
9859 if (scroll_x < SBX_Left || scroll_x > SBX_Right)
9860 scroll_x = (scroll_x < SBX_Left ? SBX_Left : SBX_Right);
9862 /* don't scroll more than one field at a time */
9863 scroll_x = old_scroll_x + SIGN(scroll_x - old_scroll_x);
9865 /* don't scroll against the player's moving direction */
9866 if ((player->MovDir == MV_LEFT && scroll_x > old_scroll_x) ||
9867 (player->MovDir == MV_RIGHT && scroll_x < old_scroll_x))
9868 scroll_x = old_scroll_x;
9870 else /* player has moved vertically */
9872 if ((player->MovDir == MV_UP && scroll_y > jy - MIDPOSY + offset) ||
9873 (player->MovDir == MV_DOWN && scroll_y < jy - MIDPOSY - offset))
9874 scroll_y = jy-MIDPOSY + (scroll_y < jy-MIDPOSY ? -offset : +offset);
9876 /* don't scroll over playfield boundaries */
9877 if (scroll_y < SBY_Upper || scroll_y > SBY_Lower)
9878 scroll_y = (scroll_y < SBY_Upper ? SBY_Upper : SBY_Lower);
9880 /* don't scroll more than one field at a time */
9881 scroll_y = old_scroll_y + SIGN(scroll_y - old_scroll_y);
9883 /* don't scroll against the player's moving direction */
9884 if ((player->MovDir == MV_UP && scroll_y > old_scroll_y) ||
9885 (player->MovDir == MV_DOWN && scroll_y < old_scroll_y))
9886 scroll_y = old_scroll_y;
9890 if (scroll_x != old_scroll_x || scroll_y != old_scroll_y)
9893 if (!options.network && game.centered_player_nr == -1 &&
9894 !AllPlayersInVisibleScreen())
9896 scroll_x = old_scroll_x;
9897 scroll_y = old_scroll_y;
9901 if (!options.network && !AllPlayersInVisibleScreen())
9903 scroll_x = old_scroll_x;
9904 scroll_y = old_scroll_y;
9909 ScrollScreen(player, SCROLL_INIT);
9910 ScrollLevel(old_scroll_x - scroll_x, old_scroll_y - scroll_y);
9915 player->StepFrame = 0;
9917 if (moved & MP_MOVING)
9919 if (old_jx != jx && old_jy == jy)
9920 player->MovDir = (old_jx < jx ? MV_RIGHT : MV_LEFT);
9921 else if (old_jx == jx && old_jy != jy)
9922 player->MovDir = (old_jy < jy ? MV_DOWN : MV_UP);
9924 DrawLevelField(jx, jy); /* for "crumbled sand" */
9926 player->last_move_dir = player->MovDir;
9927 player->is_moving = TRUE;
9928 player->is_snapping = FALSE;
9929 player->is_switching = FALSE;
9930 player->is_dropping = FALSE;
9934 CheckGravityMovementWhenNotMoving(player);
9936 player->is_moving = FALSE;
9938 /* at this point, the player is allowed to move, but cannot move right now
9939 (e.g. because of something blocking the way) -- ensure that the player
9940 is also allowed to move in the next frame (in old versions before 3.1.1,
9941 the player was forced to wait again for eight frames before next try) */
9943 if (game.engine_version >= VERSION_IDENT(3,1,1,0))
9944 player->move_delay = 0; /* allow direct movement in the next frame */
9947 if (player->move_delay == -1) /* not yet initialized by DigField() */
9948 player->move_delay = player->move_delay_value;
9950 if (game.engine_version < VERSION_IDENT(3,0,7,0))
9952 TestIfPlayerTouchesBadThing(jx, jy);
9953 TestIfPlayerTouchesCustomElement(jx, jy);
9956 if (!player->active)
9957 RemovePlayer(player);
9962 void ScrollPlayer(struct PlayerInfo *player, int mode)
9964 int jx = player->jx, jy = player->jy;
9965 int last_jx = player->last_jx, last_jy = player->last_jy;
9966 int move_stepsize = TILEX / player->move_delay_value;
9968 #if USE_NEW_PLAYER_SPEED
9969 if (!player->active)
9972 if (player->MovPos == 0 && mode == SCROLL_GO_ON) /* player not moving */
9975 if (!player->active || player->MovPos == 0)
9979 if (mode == SCROLL_INIT)
9981 player->actual_frame_counter = FrameCounter;
9982 player->GfxPos = move_stepsize * (player->MovPos / move_stepsize);
9984 if ((player->block_last_field || player->block_delay_adjustment > 0) &&
9985 Feld[last_jx][last_jy] == EL_EMPTY)
9987 int last_field_block_delay = 0; /* start with no blocking at all */
9988 int block_delay_adjustment = player->block_delay_adjustment;
9990 /* if player blocks last field, add delay for exactly one move */
9991 if (player->block_last_field)
9993 last_field_block_delay += player->move_delay_value;
9995 /* when blocking enabled, prevent moving up despite gravity */
9996 if (game.gravity && player->MovDir == MV_UP)
9997 block_delay_adjustment = -1;
10000 /* add block delay adjustment (also possible when not blocking) */
10001 last_field_block_delay += block_delay_adjustment;
10003 Feld[last_jx][last_jy] = EL_PLAYER_IS_LEAVING;
10004 MovDelay[last_jx][last_jy] = last_field_block_delay + 1;
10007 #if USE_NEW_PLAYER_SPEED
10008 if (player->MovPos != 0) /* player has not yet reached destination */
10014 else if (!FrameReached(&player->actual_frame_counter, 1))
10018 printf("::: player->MovPos: %d -> %d\n",
10020 player->MovPos + (player->MovPos > 0 ? -1 : 1) * move_stepsize);
10023 #if USE_NEW_PLAYER_SPEED
10024 if (player->MovPos != 0)
10026 player->MovPos += (player->MovPos > 0 ? -1 : 1) * move_stepsize;
10027 player->GfxPos = move_stepsize * (player->MovPos / move_stepsize);
10029 /* before DrawPlayer() to draw correct player graphic for this case */
10030 if (player->MovPos == 0)
10031 CheckGravityMovement(player);
10034 player->MovPos += (player->MovPos > 0 ? -1 : 1) * move_stepsize;
10035 player->GfxPos = move_stepsize * (player->MovPos / move_stepsize);
10037 /* before DrawPlayer() to draw correct player graphic for this case */
10038 if (player->MovPos == 0)
10039 CheckGravityMovement(player);
10042 if (player->MovPos == 0) /* player reached destination field */
10045 printf("::: player reached destination field\n");
10048 if (player->move_delay_reset_counter > 0)
10050 player->move_delay_reset_counter--;
10052 if (player->move_delay_reset_counter == 0)
10054 /* continue with normal speed after quickly moving through gate */
10055 HALVE_PLAYER_SPEED(player);
10057 /* be able to make the next move without delay */
10058 player->move_delay = 0;
10062 player->last_jx = jx;
10063 player->last_jy = jy;
10065 if (Feld[jx][jy] == EL_EXIT_OPEN ||
10066 Feld[jx][jy] == EL_SP_EXIT_OPEN ||
10067 Feld[jx][jy] == EL_SP_EXIT_OPENING) /* <-- special case */
10069 DrawPlayer(player); /* needed here only to cleanup last field */
10070 RemovePlayer(player);
10072 if (local_player->friends_still_needed == 0 ||
10073 IS_SP_ELEMENT(Feld[jx][jy]))
10074 player->LevelSolved = player->GameOver = TRUE;
10077 /* this breaks one level: "machine", level 000 */
10079 int move_direction = player->MovDir;
10080 int enter_side = MV_DIR_OPPOSITE(move_direction);
10081 int leave_side = move_direction;
10082 int old_jx = last_jx;
10083 int old_jy = last_jy;
10084 int old_element = Feld[old_jx][old_jy];
10085 int new_element = Feld[jx][jy];
10087 if (IS_CUSTOM_ELEMENT(old_element))
10088 CheckElementChangeByPlayer(old_jx, old_jy, old_element,
10090 player->index_bit, leave_side);
10092 CheckTriggeredElementChangeByPlayer(old_jx, old_jy, old_element,
10093 CE_PLAYER_LEAVES_X,
10094 player->index_bit, leave_side);
10096 if (IS_CUSTOM_ELEMENT(new_element))
10097 CheckElementChangeByPlayer(jx, jy, new_element, CE_ENTERED_BY_PLAYER,
10098 player->index_bit, enter_side);
10100 CheckTriggeredElementChangeByPlayer(jx, jy, new_element,
10101 CE_PLAYER_ENTERS_X,
10102 player->index_bit, enter_side);
10104 CheckTriggeredElementChangeBySide(jx, jy, player->element_nr,
10105 CE_MOVE_OF_X, move_direction);
10108 if (game.engine_version >= VERSION_IDENT(3,0,7,0))
10110 TestIfPlayerTouchesBadThing(jx, jy);
10111 TestIfPlayerTouchesCustomElement(jx, jy);
10113 /* needed because pushed element has not yet reached its destination,
10114 so it would trigger a change event at its previous field location */
10115 if (!player->is_pushing)
10116 TestIfElementTouchesCustomElement(jx, jy); /* for empty space */
10118 if (!player->active)
10119 RemovePlayer(player);
10122 if (level.use_step_counter)
10132 if (TimeLeft <= 10 && setup.time_limit)
10133 PlaySoundStereo(SND_GAME_RUNNING_OUT_OF_TIME, SOUND_MIDDLE);
10135 DrawGameValue_Time(TimeLeft);
10137 if (!TimeLeft && setup.time_limit)
10138 for (i = 0; i < MAX_PLAYERS; i++)
10139 KillPlayer(&stored_player[i]);
10141 else if (level.time == 0 && !AllPlayersGone) /* level w/o time limit */
10142 DrawGameValue_Time(TimePlayed);
10145 if (tape.single_step && tape.recording && !tape.pausing &&
10146 !player->programmed_action)
10147 TapeTogglePause(TAPE_TOGGLE_AUTOMATIC);
10151 void ScrollScreen(struct PlayerInfo *player, int mode)
10153 static unsigned long screen_frame_counter = 0;
10155 if (mode == SCROLL_INIT)
10157 /* set scrolling step size according to actual player's moving speed */
10158 ScrollStepSize = TILEX / player->move_delay_value;
10160 screen_frame_counter = FrameCounter;
10161 ScreenMovDir = player->MovDir;
10162 ScreenMovPos = player->MovPos;
10163 ScreenGfxPos = ScrollStepSize * (ScreenMovPos / ScrollStepSize);
10166 else if (!FrameReached(&screen_frame_counter, 1))
10171 ScreenMovPos += (ScreenMovPos > 0 ? -1 : 1) * ScrollStepSize;
10172 ScreenGfxPos = ScrollStepSize * (ScreenMovPos / ScrollStepSize);
10173 redraw_mask |= REDRAW_FIELD;
10176 ScreenMovDir = MV_NONE;
10179 void TestIfPlayerTouchesCustomElement(int x, int y)
10181 static int xy[4][2] =
10188 static int trigger_sides[4][2] =
10190 /* center side border side */
10191 { CH_SIDE_TOP, CH_SIDE_BOTTOM }, /* check top */
10192 { CH_SIDE_LEFT, CH_SIDE_RIGHT }, /* check left */
10193 { CH_SIDE_RIGHT, CH_SIDE_LEFT }, /* check right */
10194 { CH_SIDE_BOTTOM, CH_SIDE_TOP } /* check bottom */
10196 static int touch_dir[4] =
10198 MV_LEFT | MV_RIGHT,
10203 int center_element = Feld[x][y]; /* should always be non-moving! */
10206 for (i = 0; i < NUM_DIRECTIONS; i++)
10208 int xx = x + xy[i][0];
10209 int yy = y + xy[i][1];
10210 int center_side = trigger_sides[i][0];
10211 int border_side = trigger_sides[i][1];
10212 int border_element;
10214 if (!IN_LEV_FIELD(xx, yy))
10217 if (IS_PLAYER(x, y))
10219 struct PlayerInfo *player = PLAYERINFO(x, y);
10221 if (game.engine_version < VERSION_IDENT(3,0,7,0))
10222 border_element = Feld[xx][yy]; /* may be moving! */
10223 else if (!IS_MOVING(xx, yy) && !IS_BLOCKED(xx, yy))
10224 border_element = Feld[xx][yy];
10225 else if (MovDir[xx][yy] & touch_dir[i]) /* elements are touching */
10226 border_element = MovingOrBlocked2Element(xx, yy);
10228 continue; /* center and border element do not touch */
10230 CheckElementChangeByPlayer(xx, yy, border_element, CE_TOUCHED_BY_PLAYER,
10231 player->index_bit, border_side);
10232 CheckTriggeredElementChangeByPlayer(xx, yy, border_element,
10233 CE_PLAYER_TOUCHES_X,
10234 player->index_bit, border_side);
10236 else if (IS_PLAYER(xx, yy))
10238 struct PlayerInfo *player = PLAYERINFO(xx, yy);
10240 if (game.engine_version >= VERSION_IDENT(3,0,7,0))
10242 if (player->MovPos != 0 && !(player->MovDir & touch_dir[i]))
10243 continue; /* center and border element do not touch */
10246 CheckElementChangeByPlayer(x, y, center_element, CE_TOUCHED_BY_PLAYER,
10247 player->index_bit, center_side);
10248 CheckTriggeredElementChangeByPlayer(x, y, center_element,
10249 CE_PLAYER_TOUCHES_X,
10250 player->index_bit, center_side);
10256 #if USE_ELEMENT_TOUCHING_BUGFIX
10258 void TestIfElementTouchesCustomElement(int x, int y)
10260 static int xy[4][2] =
10267 static int trigger_sides[4][2] =
10269 /* center side border side */
10270 { CH_SIDE_TOP, CH_SIDE_BOTTOM }, /* check top */
10271 { CH_SIDE_LEFT, CH_SIDE_RIGHT }, /* check left */
10272 { CH_SIDE_RIGHT, CH_SIDE_LEFT }, /* check right */
10273 { CH_SIDE_BOTTOM, CH_SIDE_TOP } /* check bottom */
10275 static int touch_dir[4] =
10277 MV_LEFT | MV_RIGHT,
10282 boolean change_center_element = FALSE;
10283 int center_element = Feld[x][y]; /* should always be non-moving! */
10284 int border_element_old[NUM_DIRECTIONS];
10287 for (i = 0; i < NUM_DIRECTIONS; i++)
10289 int xx = x + xy[i][0];
10290 int yy = y + xy[i][1];
10291 int border_element;
10293 border_element_old[i] = -1;
10295 if (!IN_LEV_FIELD(xx, yy))
10298 if (game.engine_version < VERSION_IDENT(3,0,7,0))
10299 border_element = Feld[xx][yy]; /* may be moving! */
10300 else if (!IS_MOVING(xx, yy) && !IS_BLOCKED(xx, yy))
10301 border_element = Feld[xx][yy];
10302 else if (MovDir[xx][yy] & touch_dir[i]) /* elements are touching */
10303 border_element = MovingOrBlocked2Element(xx, yy);
10305 continue; /* center and border element do not touch */
10307 border_element_old[i] = border_element;
10310 for (i = 0; i < NUM_DIRECTIONS; i++)
10312 int xx = x + xy[i][0];
10313 int yy = y + xy[i][1];
10314 int center_side = trigger_sides[i][0];
10315 int border_element = border_element_old[i];
10317 if (border_element == -1)
10320 /* check for change of border element */
10321 CheckElementChangeBySide(xx, yy, border_element, center_element,
10322 CE_TOUCHING_X, center_side);
10325 for (i = 0; i < NUM_DIRECTIONS; i++)
10327 int border_side = trigger_sides[i][1];
10328 int border_element = border_element_old[i];
10330 if (border_element == -1)
10333 /* check for change of center element (but change it only once) */
10334 if (!change_center_element)
10335 change_center_element =
10336 CheckElementChangeBySide(x, y, center_element, border_element,
10337 CE_TOUCHING_X, border_side);
10343 void TestIfElementTouchesCustomElement_OLD(int x, int y)
10345 static int xy[4][2] =
10352 static int trigger_sides[4][2] =
10354 /* center side border side */
10355 { CH_SIDE_TOP, CH_SIDE_BOTTOM }, /* check top */
10356 { CH_SIDE_LEFT, CH_SIDE_RIGHT }, /* check left */
10357 { CH_SIDE_RIGHT, CH_SIDE_LEFT }, /* check right */
10358 { CH_SIDE_BOTTOM, CH_SIDE_TOP } /* check bottom */
10360 static int touch_dir[4] =
10362 MV_LEFT | MV_RIGHT,
10367 boolean change_center_element = FALSE;
10368 int center_element = Feld[x][y]; /* should always be non-moving! */
10371 for (i = 0; i < NUM_DIRECTIONS; i++)
10373 int xx = x + xy[i][0];
10374 int yy = y + xy[i][1];
10375 int center_side = trigger_sides[i][0];
10376 int border_side = trigger_sides[i][1];
10377 int border_element;
10379 if (!IN_LEV_FIELD(xx, yy))
10382 if (game.engine_version < VERSION_IDENT(3,0,7,0))
10383 border_element = Feld[xx][yy]; /* may be moving! */
10384 else if (!IS_MOVING(xx, yy) && !IS_BLOCKED(xx, yy))
10385 border_element = Feld[xx][yy];
10386 else if (MovDir[xx][yy] & touch_dir[i]) /* elements are touching */
10387 border_element = MovingOrBlocked2Element(xx, yy);
10389 continue; /* center and border element do not touch */
10391 /* check for change of center element (but change it only once) */
10392 if (!change_center_element)
10393 change_center_element =
10394 CheckElementChangeBySide(x, y, center_element, border_element,
10395 CE_TOUCHING_X, border_side);
10397 /* check for change of border element */
10398 CheckElementChangeBySide(xx, yy, border_element, center_element,
10399 CE_TOUCHING_X, center_side);
10405 void TestIfElementHitsCustomElement(int x, int y, int direction)
10407 int dx = (direction == MV_LEFT ? -1 : direction == MV_RIGHT ? +1 : 0);
10408 int dy = (direction == MV_UP ? -1 : direction == MV_DOWN ? +1 : 0);
10409 int hitx = x + dx, hity = y + dy;
10410 int hitting_element = Feld[x][y];
10411 int touched_element;
10413 if (IN_LEV_FIELD(hitx, hity) && IS_FREE(hitx, hity))
10416 touched_element = (IN_LEV_FIELD(hitx, hity) ?
10417 MovingOrBlocked2Element(hitx, hity) : EL_STEELWALL);
10419 if (IN_LEV_FIELD(hitx, hity))
10421 int opposite_direction = MV_DIR_OPPOSITE(direction);
10422 int hitting_side = direction;
10423 int touched_side = opposite_direction;
10424 boolean object_hit = (!IS_MOVING(hitx, hity) ||
10425 MovDir[hitx][hity] != direction ||
10426 ABS(MovPos[hitx][hity]) <= TILEY / 2);
10432 CheckElementChangeBySide(x, y, hitting_element, touched_element,
10433 CE_HITTING_X, touched_side);
10435 CheckElementChangeBySide(hitx, hity, touched_element,
10436 hitting_element, CE_HIT_BY_X, hitting_side);
10438 CheckElementChangeBySide(hitx, hity, touched_element, hitting_element,
10439 CE_HIT_BY_SOMETHING, opposite_direction);
10443 /* "hitting something" is also true when hitting the playfield border */
10444 CheckElementChangeBySide(x, y, hitting_element, touched_element,
10445 CE_HITTING_SOMETHING, direction);
10449 void TestIfElementSmashesCustomElement(int x, int y, int direction)
10451 int dx = (direction == MV_LEFT ? -1 : direction == MV_RIGHT ? +1 : 0);
10452 int dy = (direction == MV_UP ? -1 : direction == MV_DOWN ? +1 : 0);
10453 int hitx = x + dx, hity = y + dy;
10454 int hitting_element = Feld[x][y];
10455 int touched_element;
10457 boolean object_hit = (IN_LEV_FIELD(hitx, hity) &&
10458 !IS_FREE(hitx, hity) &&
10459 (!IS_MOVING(hitx, hity) ||
10460 MovDir[hitx][hity] != direction ||
10461 ABS(MovPos[hitx][hity]) <= TILEY / 2));
10464 if (IN_LEV_FIELD(hitx, hity) && IS_FREE(hitx, hity))
10468 if (IN_LEV_FIELD(hitx, hity) && !object_hit)
10472 touched_element = (IN_LEV_FIELD(hitx, hity) ?
10473 MovingOrBlocked2Element(hitx, hity) : EL_STEELWALL);
10475 CheckElementChangeBySide(x, y, hitting_element, touched_element,
10476 EP_CAN_SMASH_EVERYTHING, direction);
10478 if (IN_LEV_FIELD(hitx, hity))
10480 int opposite_direction = MV_DIR_OPPOSITE(direction);
10481 int hitting_side = direction;
10482 int touched_side = opposite_direction;
10484 int touched_element = MovingOrBlocked2Element(hitx, hity);
10487 boolean object_hit = (!IS_MOVING(hitx, hity) ||
10488 MovDir[hitx][hity] != direction ||
10489 ABS(MovPos[hitx][hity]) <= TILEY / 2);
10498 CheckElementChangeBySide(hitx, hity, touched_element, hitting_element,
10499 CE_SMASHED_BY_SOMETHING, opposite_direction);
10501 CheckElementChangeBySide(x, y, hitting_element, touched_element,
10502 CE_OTHER_IS_SMASHING, touched_side);
10504 CheckElementChangeBySide(hitx, hity, touched_element, hitting_element,
10505 CE_OTHER_GETS_SMASHED, hitting_side);
10511 void TestIfGoodThingHitsBadThing(int good_x, int good_y, int good_move_dir)
10513 int i, kill_x = -1, kill_y = -1;
10515 int bad_element = -1;
10516 static int test_xy[4][2] =
10523 static int test_dir[4] =
10531 for (i = 0; i < NUM_DIRECTIONS; i++)
10533 int test_x, test_y, test_move_dir, test_element;
10535 test_x = good_x + test_xy[i][0];
10536 test_y = good_y + test_xy[i][1];
10538 if (!IN_LEV_FIELD(test_x, test_y))
10542 (IS_MOVING(test_x, test_y) ? MovDir[test_x][test_y] : MV_NONE);
10544 test_element = MovingOrBlocked2ElementIfNotLeaving(test_x, test_y);
10546 /* 1st case: good thing is moving towards DONT_RUN_INTO style bad thing;
10547 2nd case: DONT_TOUCH style bad thing does not move away from good thing
10549 if ((DONT_RUN_INTO(test_element) && good_move_dir == test_dir[i]) ||
10550 (DONT_TOUCH(test_element) && test_move_dir != test_dir[i]))
10554 bad_element = test_element;
10560 if (kill_x != -1 || kill_y != -1)
10562 if (IS_PLAYER(good_x, good_y))
10564 struct PlayerInfo *player = PLAYERINFO(good_x, good_y);
10566 if (player->shield_deadly_time_left > 0 &&
10567 !IS_INDESTRUCTIBLE(bad_element))
10568 Bang(kill_x, kill_y);
10569 else if (!PLAYER_ENEMY_PROTECTED(good_x, good_y))
10570 KillPlayer(player);
10573 Bang(good_x, good_y);
10577 void TestIfBadThingHitsGoodThing(int bad_x, int bad_y, int bad_move_dir)
10579 int i, kill_x = -1, kill_y = -1;
10580 int bad_element = Feld[bad_x][bad_y];
10581 static int test_xy[4][2] =
10588 static int touch_dir[4] =
10590 MV_LEFT | MV_RIGHT,
10595 static int test_dir[4] =
10603 if (bad_element == EL_EXPLOSION) /* skip just exploding bad things */
10606 for (i = 0; i < NUM_DIRECTIONS; i++)
10608 int test_x, test_y, test_move_dir, test_element;
10610 test_x = bad_x + test_xy[i][0];
10611 test_y = bad_y + test_xy[i][1];
10612 if (!IN_LEV_FIELD(test_x, test_y))
10616 (IS_MOVING(test_x, test_y) ? MovDir[test_x][test_y] : MV_NONE);
10618 test_element = Feld[test_x][test_y];
10620 /* 1st case: good thing is moving towards DONT_RUN_INTO style bad thing;
10621 2nd case: DONT_TOUCH style bad thing does not move away from good thing
10623 if ((DONT_RUN_INTO(bad_element) && bad_move_dir == test_dir[i]) ||
10624 (DONT_TOUCH(bad_element) && test_move_dir != test_dir[i]))
10626 /* good thing is player or penguin that does not move away */
10627 if (IS_PLAYER(test_x, test_y))
10629 struct PlayerInfo *player = PLAYERINFO(test_x, test_y);
10631 if (bad_element == EL_ROBOT && player->is_moving)
10632 continue; /* robot does not kill player if he is moving */
10634 if (game.engine_version >= VERSION_IDENT(3,0,7,0))
10636 if (player->MovPos != 0 && !(player->MovDir & touch_dir[i]))
10637 continue; /* center and border element do not touch */
10644 else if (test_element == EL_PENGUIN)
10653 if (kill_x != -1 || kill_y != -1)
10655 if (IS_PLAYER(kill_x, kill_y))
10657 struct PlayerInfo *player = PLAYERINFO(kill_x, kill_y);
10659 if (player->shield_deadly_time_left > 0 &&
10660 !IS_INDESTRUCTIBLE(bad_element))
10661 Bang(bad_x, bad_y);
10662 else if (!PLAYER_ENEMY_PROTECTED(kill_x, kill_y))
10663 KillPlayer(player);
10666 Bang(kill_x, kill_y);
10670 void TestIfPlayerTouchesBadThing(int x, int y)
10672 TestIfGoodThingHitsBadThing(x, y, MV_NONE);
10675 void TestIfPlayerRunsIntoBadThing(int x, int y, int move_dir)
10677 TestIfGoodThingHitsBadThing(x, y, move_dir);
10680 void TestIfBadThingTouchesPlayer(int x, int y)
10682 TestIfBadThingHitsGoodThing(x, y, MV_NONE);
10685 void TestIfBadThingRunsIntoPlayer(int x, int y, int move_dir)
10687 TestIfBadThingHitsGoodThing(x, y, move_dir);
10690 void TestIfFriendTouchesBadThing(int x, int y)
10692 TestIfGoodThingHitsBadThing(x, y, MV_NONE);
10695 void TestIfBadThingTouchesFriend(int x, int y)
10697 TestIfBadThingHitsGoodThing(x, y, MV_NONE);
10700 void TestIfBadThingTouchesOtherBadThing(int bad_x, int bad_y)
10702 int i, kill_x = bad_x, kill_y = bad_y;
10703 static int xy[4][2] =
10711 for (i = 0; i < NUM_DIRECTIONS; i++)
10715 x = bad_x + xy[i][0];
10716 y = bad_y + xy[i][1];
10717 if (!IN_LEV_FIELD(x, y))
10720 element = Feld[x][y];
10721 if (IS_AMOEBOID(element) || element == EL_GAME_OF_LIFE ||
10722 element == EL_AMOEBA_GROWING || element == EL_AMOEBA_DROP)
10730 if (kill_x != bad_x || kill_y != bad_y)
10731 Bang(bad_x, bad_y);
10734 void KillPlayer(struct PlayerInfo *player)
10736 int jx = player->jx, jy = player->jy;
10738 if (!player->active)
10741 /* remove accessible field at the player's position */
10742 Feld[jx][jy] = EL_EMPTY;
10744 /* deactivate shield (else Bang()/Explode() would not work right) */
10745 player->shield_normal_time_left = 0;
10746 player->shield_deadly_time_left = 0;
10749 BuryPlayer(player);
10752 static void KillPlayerUnlessEnemyProtected(int x, int y)
10754 if (!PLAYER_ENEMY_PROTECTED(x, y))
10755 KillPlayer(PLAYERINFO(x, y));
10758 static void KillPlayerUnlessExplosionProtected(int x, int y)
10760 if (!PLAYER_EXPLOSION_PROTECTED(x, y))
10761 KillPlayer(PLAYERINFO(x, y));
10764 void BuryPlayer(struct PlayerInfo *player)
10766 int jx = player->jx, jy = player->jy;
10768 if (!player->active)
10771 PlayLevelSoundElementAction(jx, jy, player->artwork_element, ACTION_DYING);
10772 PlayLevelSound(jx, jy, SND_GAME_LOSING);
10774 player->GameOver = TRUE;
10775 RemovePlayer(player);
10778 void RemovePlayer(struct PlayerInfo *player)
10780 int jx = player->jx, jy = player->jy;
10781 int i, found = FALSE;
10783 player->present = FALSE;
10784 player->active = FALSE;
10786 if (!ExplodeField[jx][jy])
10787 StorePlayer[jx][jy] = 0;
10789 if (player->is_moving)
10790 DrawLevelField(player->last_jx, player->last_jy);
10792 for (i = 0; i < MAX_PLAYERS; i++)
10793 if (stored_player[i].active)
10797 AllPlayersGone = TRUE;
10803 #if USE_NEW_SNAP_DELAY
10804 static void setFieldForSnapping(int x, int y, int element, int direction)
10806 struct ElementInfo *ei = &element_info[element];
10807 int direction_bit = MV_DIR_TO_BIT(direction);
10808 int graphic_snapping = ei->direction_graphic[ACTION_SNAPPING][direction_bit];
10809 int action = (graphic_snapping != IMG_EMPTY_SPACE ? ACTION_SNAPPING :
10810 IS_DIGGABLE(element) ? ACTION_DIGGING : ACTION_COLLECTING);
10812 Feld[x][y] = EL_ELEMENT_SNAPPING;
10813 MovDelay[x][y] = MOVE_DELAY_NORMAL_SPEED + 1 - 1;
10815 ResetGfxAnimation(x, y);
10817 GfxElement[x][y] = element;
10818 GfxAction[x][y] = action;
10819 GfxDir[x][y] = direction;
10820 GfxFrame[x][y] = -1;
10825 =============================================================================
10826 checkDiagonalPushing()
10827 -----------------------------------------------------------------------------
10828 check if diagonal input device direction results in pushing of object
10829 (by checking if the alternative direction is walkable, diggable, ...)
10830 =============================================================================
10833 static boolean checkDiagonalPushing(struct PlayerInfo *player,
10834 int x, int y, int real_dx, int real_dy)
10836 int jx, jy, dx, dy, xx, yy;
10838 if (real_dx == 0 || real_dy == 0) /* no diagonal direction => push */
10841 /* diagonal direction: check alternative direction */
10846 xx = jx + (dx == 0 ? real_dx : 0);
10847 yy = jy + (dy == 0 ? real_dy : 0);
10849 return (!IN_LEV_FIELD(xx, yy) || IS_SOLID_FOR_PUSHING(Feld[xx][yy]));
10853 =============================================================================
10855 -----------------------------------------------------------------------------
10856 x, y: field next to player (non-diagonal) to try to dig to
10857 real_dx, real_dy: direction as read from input device (can be diagonal)
10858 =============================================================================
10861 int DigField(struct PlayerInfo *player,
10862 int oldx, int oldy, int x, int y,
10863 int real_dx, int real_dy, int mode)
10865 boolean is_player = (IS_PLAYER(oldx, oldy) || mode != DF_DIG);
10866 boolean player_was_pushing = player->is_pushing;
10867 boolean player_can_move = (!player->cannot_move && mode != DF_SNAP);
10868 boolean player_can_move_or_snap = (!player->cannot_move || mode == DF_SNAP);
10869 int jx = oldx, jy = oldy;
10870 int dx = x - jx, dy = y - jy;
10871 int nextx = x + dx, nexty = y + dy;
10872 int move_direction = (dx == -1 ? MV_LEFT :
10873 dx == +1 ? MV_RIGHT :
10875 dy == +1 ? MV_DOWN : MV_NONE);
10876 int opposite_direction = MV_DIR_OPPOSITE(move_direction);
10877 int dig_side = MV_DIR_OPPOSITE(move_direction);
10878 int old_element = Feld[jx][jy];
10879 #if USE_FIXED_DONT_RUN_INTO
10880 int element = MovingOrBlocked2ElementIfNotLeaving(x, y);
10886 if (is_player) /* function can also be called by EL_PENGUIN */
10888 if (player->MovPos == 0)
10890 player->is_digging = FALSE;
10891 player->is_collecting = FALSE;
10894 if (player->MovPos == 0) /* last pushing move finished */
10895 player->is_pushing = FALSE;
10897 if (mode == DF_NO_PUSH) /* player just stopped pushing */
10899 player->is_switching = FALSE;
10900 player->push_delay = -1;
10902 return MP_NO_ACTION;
10906 #if !USE_FIXED_DONT_RUN_INTO
10907 if (IS_MOVING(x, y) || IS_PLAYER(x, y))
10908 return MP_NO_ACTION;
10911 if (IS_TUBE(Back[jx][jy]) && game.engine_version >= VERSION_IDENT(2,2,0,0))
10912 old_element = Back[jx][jy];
10914 /* in case of element dropped at player position, check background */
10915 else if (Back[jx][jy] != EL_EMPTY &&
10916 game.engine_version >= VERSION_IDENT(2,2,0,0))
10917 old_element = Back[jx][jy];
10920 #if USE_FIXED_DONT_RUN_INTO
10921 if (player_can_move && DONT_RUN_INTO(element))
10923 if (element == EL_ACID && dx == 0 && dy == 1)
10926 Feld[jx][jy] = EL_PLAYER_1;
10927 InitMovingField(jx, jy, MV_DOWN);
10928 Store[jx][jy] = EL_ACID;
10929 ContinueMoving(jx, jy);
10930 BuryPlayer(player);
10933 TestIfPlayerRunsIntoBadThing(jx, jy, player->MovDir);
10935 return MP_DONT_RUN_INTO;
10941 #if USE_FIXED_DONT_RUN_INTO
10942 if (player_can_move && DONT_RUN_INTO(element))
10944 TestIfPlayerRunsIntoBadThing(jx, jy, player->MovDir);
10946 return MP_DONT_RUN_INTO;
10951 if (IS_WALKABLE(old_element) && !ACCESS_FROM(old_element, move_direction))
10952 return MP_NO_ACTION; /* field has no opening in this direction */
10954 if (IS_PASSABLE(old_element) && !ACCESS_FROM(old_element,opposite_direction))
10955 return MP_NO_ACTION; /* field has no opening in this direction */
10958 #if USE_FIXED_DONT_RUN_INTO
10959 if (player_can_move && element == EL_ACID && move_direction == MV_DOWN)
10962 Feld[jx][jy] = EL_PLAYER_1;
10963 InitMovingField(jx, jy, MV_DOWN);
10964 Store[jx][jy] = EL_ACID;
10965 ContinueMoving(jx, jy);
10966 BuryPlayer(player);
10968 return MP_DONT_RUN_INTO;
10974 #if USE_FIXED_DONT_RUN_INTO
10975 if (player_can_move && DONT_RUN_INTO(element))
10977 if (element == EL_ACID && dx == 0 && dy == 1)
10980 Feld[jx][jy] = EL_PLAYER_1;
10981 InitMovingField(jx, jy, MV_DOWN);
10982 Store[jx][jy] = EL_ACID;
10983 ContinueMoving(jx, jy);
10984 BuryPlayer(player);
10987 TestIfPlayerRunsIntoBadThing(jx, jy, player->MovDir);
10989 return MP_DONT_RUN_INTO;
10994 #if USE_FIXED_DONT_RUN_INTO
10995 if (IS_MOVING(x, y) || IS_PLAYER(x, y))
10996 return MP_NO_ACTION;
10999 #if !USE_FIXED_DONT_RUN_INTO
11000 element = Feld[x][y];
11003 collect_count = element_info[element].collect_count_initial;
11005 if (!is_player && !IS_COLLECTIBLE(element)) /* penguin cannot collect it */
11006 return MP_NO_ACTION;
11008 if (game.engine_version < VERSION_IDENT(2,2,0,0))
11009 player_can_move = player_can_move_or_snap;
11011 if (mode == DF_SNAP && !IS_SNAPPABLE(element) &&
11012 game.engine_version >= VERSION_IDENT(2,2,0,0))
11014 CheckElementChangeByPlayer(x, y, element, CE_SNAPPED_BY_PLAYER,
11015 player->index_bit, dig_side);
11016 CheckTriggeredElementChangeByPlayer(x, y, element, CE_PLAYER_SNAPS_X,
11017 player->index_bit, dig_side);
11019 if (Feld[x][y] != element) /* field changed by snapping */
11022 return MP_NO_ACTION;
11025 if (game.gravity && is_player && !player->is_auto_moving &&
11026 canFallDown(player) && move_direction != MV_DOWN &&
11027 !canMoveToValidFieldWithGravity(jx, jy, move_direction))
11028 return MP_NO_ACTION; /* player cannot walk here due to gravity */
11030 if (player_can_move &&
11031 IS_WALKABLE(element) && ACCESS_FROM(element, opposite_direction))
11033 int sound_element = SND_ELEMENT(element);
11034 int sound_action = ACTION_WALKING;
11036 if (IS_RND_GATE(element))
11038 if (!player->key[RND_GATE_NR(element)])
11039 return MP_NO_ACTION;
11041 else if (IS_RND_GATE_GRAY(element))
11043 if (!player->key[RND_GATE_GRAY_NR(element)])
11044 return MP_NO_ACTION;
11046 else if (IS_RND_GATE_GRAY_ACTIVE(element))
11048 if (!player->key[RND_GATE_GRAY_ACTIVE_NR(element)])
11049 return MP_NO_ACTION;
11051 else if (element == EL_EXIT_OPEN ||
11052 element == EL_SP_EXIT_OPEN ||
11053 element == EL_SP_EXIT_OPENING)
11055 sound_action = ACTION_PASSING; /* player is passing exit */
11057 else if (element == EL_EMPTY)
11059 sound_action = ACTION_MOVING; /* nothing to walk on */
11062 /* play sound from background or player, whatever is available */
11063 if (element_info[sound_element].sound[sound_action] != SND_UNDEFINED)
11064 PlayLevelSoundElementAction(x, y, sound_element, sound_action);
11066 PlayLevelSoundElementAction(x, y, player->artwork_element, sound_action);
11068 else if (player_can_move &&
11069 IS_PASSABLE(element) && canPassField(x, y, move_direction))
11071 if (!ACCESS_FROM(element, opposite_direction))
11072 return MP_NO_ACTION; /* field not accessible from this direction */
11074 if (CAN_MOVE(element)) /* only fixed elements can be passed! */
11075 return MP_NO_ACTION;
11077 if (IS_EM_GATE(element))
11079 if (!player->key[EM_GATE_NR(element)])
11080 return MP_NO_ACTION;
11082 else if (IS_EM_GATE_GRAY(element))
11084 if (!player->key[EM_GATE_GRAY_NR(element)])
11085 return MP_NO_ACTION;
11087 else if (IS_EM_GATE_GRAY_ACTIVE(element))
11089 if (!player->key[EM_GATE_GRAY_ACTIVE_NR(element)])
11090 return MP_NO_ACTION;
11092 else if (IS_SP_PORT(element))
11094 if (element == EL_SP_GRAVITY_PORT_LEFT ||
11095 element == EL_SP_GRAVITY_PORT_RIGHT ||
11096 element == EL_SP_GRAVITY_PORT_UP ||
11097 element == EL_SP_GRAVITY_PORT_DOWN)
11098 game.gravity = !game.gravity;
11099 else if (element == EL_SP_GRAVITY_ON_PORT_LEFT ||
11100 element == EL_SP_GRAVITY_ON_PORT_RIGHT ||
11101 element == EL_SP_GRAVITY_ON_PORT_UP ||
11102 element == EL_SP_GRAVITY_ON_PORT_DOWN)
11103 game.gravity = TRUE;
11104 else if (element == EL_SP_GRAVITY_OFF_PORT_LEFT ||
11105 element == EL_SP_GRAVITY_OFF_PORT_RIGHT ||
11106 element == EL_SP_GRAVITY_OFF_PORT_UP ||
11107 element == EL_SP_GRAVITY_OFF_PORT_DOWN)
11108 game.gravity = FALSE;
11111 /* automatically move to the next field with double speed */
11112 player->programmed_action = move_direction;
11114 if (player->move_delay_reset_counter == 0)
11116 player->move_delay_reset_counter = 2; /* two double speed steps */
11118 DOUBLE_PLAYER_SPEED(player);
11121 PlayLevelSoundAction(x, y, ACTION_PASSING);
11123 else if (player_can_move_or_snap && IS_DIGGABLE(element))
11127 if (mode != DF_SNAP)
11129 GfxElement[x][y] = GFX_ELEMENT(element);
11130 player->is_digging = TRUE;
11133 PlayLevelSoundElementAction(x, y, element, ACTION_DIGGING);
11135 CheckTriggeredElementChangeByPlayer(x, y, element, CE_PLAYER_DIGS_X,
11136 player->index_bit, dig_side);
11138 if (mode == DF_SNAP)
11140 #if USE_NEW_SNAP_DELAY
11141 if (level.block_snap_field)
11142 setFieldForSnapping(x, y, element, move_direction);
11144 TestIfElementTouchesCustomElement(x, y); /* for empty space */
11146 TestIfElementTouchesCustomElement(x, y); /* for empty space */
11149 CheckTriggeredElementChangeByPlayer(x, y, element, CE_PLAYER_SNAPS_X,
11150 player->index_bit, dig_side);
11153 else if (player_can_move_or_snap && IS_COLLECTIBLE(element))
11157 if (is_player && mode != DF_SNAP)
11159 GfxElement[x][y] = element;
11160 player->is_collecting = TRUE;
11163 if (element == EL_SPEED_PILL)
11165 player->move_delay_value = MOVE_DELAY_HIGH_SPEED;
11167 else if (element == EL_EXTRA_TIME && level.time > 0)
11169 TimeLeft += level.extra_time;
11170 DrawGameValue_Time(TimeLeft);
11172 else if (element == EL_SHIELD_NORMAL || element == EL_SHIELD_DEADLY)
11174 player->shield_normal_time_left += level.shield_normal_time;
11175 if (element == EL_SHIELD_DEADLY)
11176 player->shield_deadly_time_left += level.shield_deadly_time;
11178 else if (element == EL_DYNAMITE ||
11179 element == EL_EM_DYNAMITE ||
11180 element == EL_SP_DISK_RED)
11182 if (player->inventory_size < MAX_INVENTORY_SIZE)
11183 player->inventory_element[player->inventory_size++] = element;
11185 DrawGameValue_Dynamite(local_player->inventory_size);
11187 else if (element == EL_DYNABOMB_INCREASE_NUMBER)
11189 player->dynabomb_count++;
11190 player->dynabombs_left++;
11192 else if (element == EL_DYNABOMB_INCREASE_SIZE)
11194 player->dynabomb_size++;
11196 else if (element == EL_DYNABOMB_INCREASE_POWER)
11198 player->dynabomb_xl = TRUE;
11200 else if (IS_KEY(element))
11202 player->key[KEY_NR(element)] = TRUE;
11204 DrawGameValue_Keys(player->key);
11206 redraw_mask |= REDRAW_DOOR_1;
11208 else if (IS_ENVELOPE(element))
11210 player->show_envelope = element;
11212 else if (element == EL_EMC_LENSES)
11214 game.lenses_time_left = level.lenses_time * FRAMES_PER_SECOND;
11216 RedrawAllInvisibleElementsForLenses();
11218 else if (element == EL_EMC_MAGNIFIER)
11220 game.magnify_time_left = level.magnify_time * FRAMES_PER_SECOND;
11222 RedrawAllInvisibleElementsForMagnifier();
11224 else if (IS_DROPPABLE(element) ||
11225 IS_THROWABLE(element)) /* can be collected and dropped */
11229 if (collect_count == 0)
11230 player->inventory_infinite_element = element;
11232 for (i = 0; i < collect_count; i++)
11233 if (player->inventory_size < MAX_INVENTORY_SIZE)
11234 player->inventory_element[player->inventory_size++] = element;
11236 DrawGameValue_Dynamite(local_player->inventory_size);
11238 else if (collect_count > 0)
11240 local_player->gems_still_needed -= collect_count;
11241 if (local_player->gems_still_needed < 0)
11242 local_player->gems_still_needed = 0;
11244 DrawGameValue_Emeralds(local_player->gems_still_needed);
11247 RaiseScoreElement(element);
11248 PlayLevelSoundElementAction(x, y, element, ACTION_COLLECTING);
11251 CheckTriggeredElementChangeByPlayer(x, y, element, CE_PLAYER_COLLECTS_X,
11252 player->index_bit, dig_side);
11254 if (mode == DF_SNAP)
11256 #if USE_NEW_SNAP_DELAY
11257 if (level.block_snap_field)
11258 setFieldForSnapping(x, y, element, move_direction);
11260 TestIfElementTouchesCustomElement(x, y); /* for empty space */
11262 TestIfElementTouchesCustomElement(x, y); /* for empty space */
11265 CheckTriggeredElementChangeByPlayer(x, y, element, CE_PLAYER_SNAPS_X,
11266 player->index_bit, dig_side);
11269 else if (player_can_move_or_snap && IS_PUSHABLE(element))
11271 if (mode == DF_SNAP && element != EL_BD_ROCK)
11272 return MP_NO_ACTION;
11274 if (CAN_FALL(element) && dy)
11275 return MP_NO_ACTION;
11277 if (CAN_FALL(element) && IN_LEV_FIELD(x, y + 1) && IS_FREE(x, y + 1) &&
11278 !(element == EL_SPRING && level.use_spring_bug))
11279 return MP_NO_ACTION;
11281 if (CAN_MOVE(element) && GET_MAX_MOVE_DELAY(element) == 0 &&
11282 ((move_direction & MV_VERTICAL &&
11283 ((element_info[element].move_pattern & MV_LEFT &&
11284 IN_LEV_FIELD(x - 1, y) && IS_FREE(x - 1, y)) ||
11285 (element_info[element].move_pattern & MV_RIGHT &&
11286 IN_LEV_FIELD(x + 1, y) && IS_FREE(x + 1, y)))) ||
11287 (move_direction & MV_HORIZONTAL &&
11288 ((element_info[element].move_pattern & MV_UP &&
11289 IN_LEV_FIELD(x, y - 1) && IS_FREE(x, y - 1)) ||
11290 (element_info[element].move_pattern & MV_DOWN &&
11291 IN_LEV_FIELD(x, y + 1) && IS_FREE(x, y + 1))))))
11292 return MP_NO_ACTION;
11294 /* do not push elements already moving away faster than player */
11295 if (CAN_MOVE(element) && MovDir[x][y] == move_direction &&
11296 ABS(getElementMoveStepsize(x, y)) > MOVE_STEPSIZE_NORMAL)
11297 return MP_NO_ACTION;
11299 if (game.engine_version >= VERSION_IDENT(3,1,0,0))
11301 if (player->push_delay_value == -1 || !player_was_pushing)
11302 player->push_delay_value = GET_NEW_PUSH_DELAY(element);
11304 else if (game.engine_version >= VERSION_IDENT(3,0,7,1))
11306 if (player->push_delay_value == -1)
11307 player->push_delay_value = GET_NEW_PUSH_DELAY(element);
11309 else if (game.engine_version >= VERSION_IDENT(2,2,0,7))
11311 if (!player->is_pushing)
11312 player->push_delay_value = GET_NEW_PUSH_DELAY(element);
11315 player->is_pushing = TRUE;
11317 if (!(IN_LEV_FIELD(nextx, nexty) &&
11318 (IS_FREE(nextx, nexty) ||
11319 (Feld[nextx][nexty] == EL_SOKOBAN_FIELD_EMPTY &&
11320 IS_SB_ELEMENT(element)))))
11321 return MP_NO_ACTION;
11323 if (!checkDiagonalPushing(player, x, y, real_dx, real_dy))
11324 return MP_NO_ACTION;
11326 if (player->push_delay == -1) /* new pushing; restart delay */
11327 player->push_delay = 0;
11329 if (player->push_delay < player->push_delay_value &&
11330 !(tape.playing && tape.file_version < FILE_VERSION_2_0) &&
11331 element != EL_SPRING && element != EL_BALLOON)
11333 /* make sure that there is no move delay before next try to push */
11334 if (game.engine_version >= VERSION_IDENT(3,0,7,1))
11335 player->move_delay = 0;
11337 return MP_NO_ACTION;
11340 if (IS_SB_ELEMENT(element))
11342 if (element == EL_SOKOBAN_FIELD_FULL)
11344 Back[x][y] = EL_SOKOBAN_FIELD_EMPTY;
11345 local_player->sokobanfields_still_needed++;
11348 if (Feld[nextx][nexty] == EL_SOKOBAN_FIELD_EMPTY)
11350 Back[nextx][nexty] = EL_SOKOBAN_FIELD_EMPTY;
11351 local_player->sokobanfields_still_needed--;
11354 Feld[x][y] = EL_SOKOBAN_OBJECT;
11356 if (Back[x][y] == Back[nextx][nexty])
11357 PlayLevelSoundAction(x, y, ACTION_PUSHING);
11358 else if (Back[x][y] != 0)
11359 PlayLevelSoundElementAction(x, y, EL_SOKOBAN_FIELD_FULL,
11362 PlayLevelSoundElementAction(nextx, nexty, EL_SOKOBAN_FIELD_EMPTY,
11365 if (local_player->sokobanfields_still_needed == 0 &&
11366 game.emulation == EMU_SOKOBAN)
11368 player->LevelSolved = player->GameOver = TRUE;
11369 PlayLevelSound(x, y, SND_GAME_SOKOBAN_SOLVING);
11373 PlayLevelSoundElementAction(x, y, element, ACTION_PUSHING);
11375 InitMovingField(x, y, move_direction);
11376 GfxAction[x][y] = ACTION_PUSHING;
11378 if (mode == DF_SNAP)
11379 ContinueMoving(x, y);
11381 MovPos[x][y] = (dx != 0 ? dx : dy);
11383 Pushed[x][y] = TRUE;
11384 Pushed[nextx][nexty] = TRUE;
11386 if (game.engine_version < VERSION_IDENT(2,2,0,7))
11387 player->push_delay_value = GET_NEW_PUSH_DELAY(element);
11389 player->push_delay_value = -1; /* get new value later */
11391 /* check for element change _after_ element has been pushed */
11392 if (game.use_change_when_pushing_bug)
11394 CheckElementChangeByPlayer(x, y, element, CE_PUSHED_BY_PLAYER,
11395 player->index_bit, dig_side);
11396 CheckTriggeredElementChangeByPlayer(x, y, element, CE_PLAYER_PUSHES_X,
11397 player->index_bit, dig_side);
11400 else if (IS_SWITCHABLE(element))
11402 if (PLAYER_SWITCHING(player, x, y))
11404 CheckTriggeredElementChangeByPlayer(x, y, element, CE_PLAYER_PRESSES_X,
11405 player->index_bit, dig_side);
11410 player->is_switching = TRUE;
11411 player->switch_x = x;
11412 player->switch_y = y;
11414 PlayLevelSoundElementAction(x, y, element, ACTION_ACTIVATING);
11416 if (element == EL_ROBOT_WHEEL)
11418 Feld[x][y] = EL_ROBOT_WHEEL_ACTIVE;
11422 DrawLevelField(x, y);
11424 else if (element == EL_SP_TERMINAL)
11429 SCAN_PLAYFIELD(xx, yy)
11431 for (yy = 0; yy < lev_fieldy; yy++) for (xx = 0; xx < lev_fieldx; xx++)
11434 if (Feld[xx][yy] == EL_SP_DISK_YELLOW)
11436 else if (Feld[xx][yy] == EL_SP_TERMINAL)
11437 Feld[xx][yy] = EL_SP_TERMINAL_ACTIVE;
11440 else if (IS_BELT_SWITCH(element))
11442 ToggleBeltSwitch(x, y);
11444 else if (element == EL_SWITCHGATE_SWITCH_UP ||
11445 element == EL_SWITCHGATE_SWITCH_DOWN)
11447 ToggleSwitchgateSwitch(x, y);
11449 else if (element == EL_LIGHT_SWITCH ||
11450 element == EL_LIGHT_SWITCH_ACTIVE)
11452 ToggleLightSwitch(x, y);
11454 else if (element == EL_TIMEGATE_SWITCH)
11456 ActivateTimegateSwitch(x, y);
11458 else if (element == EL_BALLOON_SWITCH_LEFT ||
11459 element == EL_BALLOON_SWITCH_RIGHT ||
11460 element == EL_BALLOON_SWITCH_UP ||
11461 element == EL_BALLOON_SWITCH_DOWN ||
11462 element == EL_BALLOON_SWITCH_NONE ||
11463 element == EL_BALLOON_SWITCH_ANY)
11465 game.wind_direction = (element == EL_BALLOON_SWITCH_LEFT ? MV_LEFT :
11466 element == EL_BALLOON_SWITCH_RIGHT ? MV_RIGHT :
11467 element == EL_BALLOON_SWITCH_UP ? MV_UP :
11468 element == EL_BALLOON_SWITCH_DOWN ? MV_DOWN :
11469 element == EL_BALLOON_SWITCH_NONE ? MV_NONE :
11472 else if (element == EL_LAMP)
11474 Feld[x][y] = EL_LAMP_ACTIVE;
11475 local_player->lights_still_needed--;
11477 ResetGfxAnimation(x, y);
11478 DrawLevelField(x, y);
11480 else if (element == EL_TIME_ORB_FULL)
11482 Feld[x][y] = EL_TIME_ORB_EMPTY;
11484 if (level.time > 0 || level.use_time_orb_bug)
11486 TimeLeft += level.time_orb_time;
11487 DrawGameValue_Time(TimeLeft);
11490 ResetGfxAnimation(x, y);
11491 DrawLevelField(x, y);
11493 else if (element == EL_EMC_MAGIC_BALL_SWITCH ||
11494 element == EL_EMC_MAGIC_BALL_SWITCH_ACTIVE)
11498 game.ball_state = !game.ball_state;
11501 SCAN_PLAYFIELD(xx, yy)
11503 for (yy = 0; yy < lev_fieldy; yy++) for (xx = 0; xx < lev_fieldx; xx++)
11506 int e = Feld[xx][yy];
11508 if (game.ball_state)
11510 if (e == EL_EMC_MAGIC_BALL)
11511 CreateField(xx, yy, EL_EMC_MAGIC_BALL_ACTIVE);
11512 else if (e == EL_EMC_MAGIC_BALL_SWITCH)
11513 CreateField(xx, yy, EL_EMC_MAGIC_BALL_SWITCH_ACTIVE);
11517 if (e == EL_EMC_MAGIC_BALL_ACTIVE)
11518 CreateField(xx, yy, EL_EMC_MAGIC_BALL);
11519 else if (e == EL_EMC_MAGIC_BALL_SWITCH_ACTIVE)
11520 CreateField(xx, yy, EL_EMC_MAGIC_BALL_SWITCH);
11525 CheckTriggeredElementChangeByPlayer(x, y, element, CE_SWITCH_OF_X,
11526 player->index_bit, dig_side);
11528 CheckTriggeredElementChangeByPlayer(x, y, element, CE_PLAYER_SWITCHES_X,
11529 player->index_bit, dig_side);
11531 CheckTriggeredElementChangeByPlayer(x, y, element, CE_PLAYER_PRESSES_X,
11532 player->index_bit, dig_side);
11538 if (!PLAYER_SWITCHING(player, x, y))
11540 player->is_switching = TRUE;
11541 player->switch_x = x;
11542 player->switch_y = y;
11544 CheckElementChangeByPlayer(x, y, element, CE_SWITCHED,
11545 player->index_bit, dig_side);
11546 CheckTriggeredElementChangeByPlayer(x, y, element, CE_SWITCH_OF_X,
11547 player->index_bit, dig_side);
11549 CheckElementChangeByPlayer(x, y, element, CE_SWITCHED_BY_PLAYER,
11550 player->index_bit, dig_side);
11551 CheckTriggeredElementChangeByPlayer(x, y, element, CE_PLAYER_SWITCHES_X,
11552 player->index_bit, dig_side);
11555 CheckElementChangeByPlayer(x, y, element, CE_PRESSED_BY_PLAYER,
11556 player->index_bit, dig_side);
11557 CheckTriggeredElementChangeByPlayer(x, y, element, CE_PLAYER_PRESSES_X,
11558 player->index_bit, dig_side);
11560 return MP_NO_ACTION;
11563 player->push_delay = -1;
11565 if (is_player) /* function can also be called by EL_PENGUIN */
11567 if (Feld[x][y] != element) /* really digged/collected something */
11568 player->is_collecting = !player->is_digging;
11574 boolean SnapField(struct PlayerInfo *player, int dx, int dy)
11576 int jx = player->jx, jy = player->jy;
11577 int x = jx + dx, y = jy + dy;
11578 int snap_direction = (dx == -1 ? MV_LEFT :
11579 dx == +1 ? MV_RIGHT :
11581 dy == +1 ? MV_DOWN : MV_NONE);
11583 if (player->MovPos != 0 && game.engine_version >= VERSION_IDENT(2,2,0,0))
11586 if (!player->active || !IN_LEV_FIELD(x, y))
11594 if (player->MovPos == 0)
11595 player->is_pushing = FALSE;
11597 player->is_snapping = FALSE;
11599 if (player->MovPos == 0)
11601 player->is_moving = FALSE;
11602 player->is_digging = FALSE;
11603 player->is_collecting = FALSE;
11609 if (player->is_snapping)
11612 player->MovDir = snap_direction;
11614 if (player->MovPos == 0)
11616 player->is_moving = FALSE;
11617 player->is_digging = FALSE;
11618 player->is_collecting = FALSE;
11621 player->is_dropping = FALSE;
11623 if (DigField(player, jx, jy, x, y, 0, 0, DF_SNAP) == MP_NO_ACTION)
11626 player->is_snapping = TRUE;
11628 if (player->MovPos == 0)
11630 player->is_moving = FALSE;
11631 player->is_digging = FALSE;
11632 player->is_collecting = FALSE;
11635 if (player->MovPos != 0) /* prevent graphic bugs in versions < 2.2.0 */
11636 DrawLevelField(player->last_jx, player->last_jy);
11638 DrawLevelField(x, y);
11643 boolean DropElement(struct PlayerInfo *player)
11645 int old_element, new_element;
11646 int dropx = player->jx, dropy = player->jy;
11647 int drop_direction = player->MovDir;
11648 int drop_side = drop_direction;
11649 int drop_element = (player->inventory_size > 0 ?
11650 player->inventory_element[player->inventory_size - 1] :
11651 player->inventory_infinite_element != EL_UNDEFINED ?
11652 player->inventory_infinite_element :
11653 player->dynabombs_left > 0 ?
11654 EL_DYNABOMB_PLAYER_1_ACTIVE + player->index_nr :
11657 /* do not drop an element on top of another element; when holding drop key
11658 pressed without moving, dropped element must move away before the next
11659 element can be dropped (this is especially important if the next element
11660 is dynamite, which can be placed on background for historical reasons) */
11661 if (PLAYER_DROPPING(player, dropx, dropy) && Feld[dropx][dropy] != EL_EMPTY)
11664 if (IS_THROWABLE(drop_element))
11666 dropx += GET_DX_FROM_DIR(drop_direction);
11667 dropy += GET_DY_FROM_DIR(drop_direction);
11669 if (!IN_LEV_FIELD(dropx, dropy))
11673 old_element = Feld[dropx][dropy]; /* old element at dropping position */
11674 new_element = drop_element; /* default: no change when dropping */
11676 /* check if player is active, not moving and ready to drop */
11677 if (!player->active || player->MovPos || player->drop_delay > 0)
11680 /* check if player has anything that can be dropped */
11681 if (new_element == EL_UNDEFINED)
11684 /* check if anything can be dropped at the current position */
11685 if (IS_ACTIVE_BOMB(old_element) || old_element == EL_EXPLOSION)
11688 /* collected custom elements can only be dropped on empty fields */
11689 if (IS_CUSTOM_ELEMENT(new_element) && old_element != EL_EMPTY)
11692 if (old_element != EL_EMPTY)
11693 Back[dropx][dropy] = old_element; /* store old element on this field */
11695 ResetGfxAnimation(dropx, dropy);
11696 ResetRandomAnimationValue(dropx, dropy);
11698 if (player->inventory_size > 0 ||
11699 player->inventory_infinite_element != EL_UNDEFINED)
11701 if (player->inventory_size > 0)
11703 player->inventory_size--;
11705 DrawGameValue_Dynamite(local_player->inventory_size);
11707 if (new_element == EL_DYNAMITE)
11708 new_element = EL_DYNAMITE_ACTIVE;
11709 else if (new_element == EL_EM_DYNAMITE)
11710 new_element = EL_EM_DYNAMITE_ACTIVE;
11711 else if (new_element == EL_SP_DISK_RED)
11712 new_element = EL_SP_DISK_RED_ACTIVE;
11715 Feld[dropx][dropy] = new_element;
11717 if (IN_SCR_FIELD(SCREENX(dropx), SCREENY(dropy)))
11718 DrawGraphicThruMask(SCREENX(dropx), SCREENY(dropy),
11719 el2img(Feld[dropx][dropy]), 0);
11721 PlayLevelSoundAction(dropx, dropy, ACTION_DROPPING);
11723 /* needed if previous element just changed to "empty" in the last frame */
11724 ChangeCount[dropx][dropy] = 0; /* allow at least one more change */
11726 CheckElementChangeByPlayer(dropx, dropy, new_element, CE_DROPPED_BY_PLAYER,
11727 player->index_bit, drop_side);
11728 CheckTriggeredElementChangeByPlayer(dropx, dropy, new_element,
11730 player->index_bit, drop_side);
11732 TestIfElementTouchesCustomElement(dropx, dropy);
11734 else /* player is dropping a dyna bomb */
11736 player->dynabombs_left--;
11738 Feld[dropx][dropy] = new_element;
11740 if (IN_SCR_FIELD(SCREENX(dropx), SCREENY(dropy)))
11741 DrawGraphicThruMask(SCREENX(dropx), SCREENY(dropy),
11742 el2img(Feld[dropx][dropy]), 0);
11744 PlayLevelSoundAction(dropx, dropy, ACTION_DROPPING);
11747 if (Feld[dropx][dropy] == new_element) /* uninitialized unless CE change */
11748 InitField_WithBug1(dropx, dropy, FALSE);
11750 new_element = Feld[dropx][dropy]; /* element might have changed */
11752 if (IS_CUSTOM_ELEMENT(new_element) && CAN_MOVE(new_element) &&
11753 element_info[new_element].move_pattern == MV_WHEN_DROPPED)
11755 int move_direction, nextx, nexty;
11757 if (element_info[new_element].move_direction_initial == MV_START_AUTOMATIC)
11758 MovDir[dropx][dropy] = drop_direction;
11760 move_direction = MovDir[dropx][dropy];
11761 nextx = dropx + GET_DX_FROM_DIR(move_direction);
11762 nexty = dropy + GET_DY_FROM_DIR(move_direction);
11764 ChangeCount[dropx][dropy] = 0; /* allow at least one more change */
11765 CheckCollision[dropx][dropy] = 2;
11768 player->drop_delay = GET_NEW_DROP_DELAY(drop_element);
11769 player->is_dropping = TRUE;
11771 player->drop_x = dropx;
11772 player->drop_y = dropy;
11777 /* ------------------------------------------------------------------------- */
11778 /* game sound playing functions */
11779 /* ------------------------------------------------------------------------- */
11781 static int *loop_sound_frame = NULL;
11782 static int *loop_sound_volume = NULL;
11784 void InitPlayLevelSound()
11786 int num_sounds = getSoundListSize();
11788 checked_free(loop_sound_frame);
11789 checked_free(loop_sound_volume);
11791 loop_sound_frame = checked_calloc(num_sounds * sizeof(int));
11792 loop_sound_volume = checked_calloc(num_sounds * sizeof(int));
11795 static void PlayLevelSound(int x, int y, int nr)
11797 int sx = SCREENX(x), sy = SCREENY(y);
11798 int volume, stereo_position;
11799 int max_distance = 8;
11800 int type = (IS_LOOP_SOUND(nr) ? SND_CTRL_PLAY_LOOP : SND_CTRL_PLAY_SOUND);
11802 if ((!setup.sound_simple && !IS_LOOP_SOUND(nr)) ||
11803 (!setup.sound_loops && IS_LOOP_SOUND(nr)))
11806 if (!IN_LEV_FIELD(x, y) ||
11807 sx < -max_distance || sx >= SCR_FIELDX + max_distance ||
11808 sy < -max_distance || sy >= SCR_FIELDY + max_distance)
11811 volume = SOUND_MAX_VOLUME;
11813 if (!IN_SCR_FIELD(sx, sy))
11815 int dx = ABS(sx - SCR_FIELDX / 2) - SCR_FIELDX / 2;
11816 int dy = ABS(sy - SCR_FIELDY / 2) - SCR_FIELDY / 2;
11818 volume -= volume * (dx > dy ? dx : dy) / max_distance;
11821 stereo_position = (SOUND_MAX_LEFT +
11822 (sx + max_distance) * SOUND_MAX_LEFT2RIGHT /
11823 (SCR_FIELDX + 2 * max_distance));
11825 if (IS_LOOP_SOUND(nr))
11827 /* This assures that quieter loop sounds do not overwrite louder ones,
11828 while restarting sound volume comparison with each new game frame. */
11830 if (loop_sound_volume[nr] > volume && loop_sound_frame[nr] == FrameCounter)
11833 loop_sound_volume[nr] = volume;
11834 loop_sound_frame[nr] = FrameCounter;
11837 PlaySoundExt(nr, volume, stereo_position, type);
11840 static void PlayLevelSoundNearest(int x, int y, int sound_action)
11842 PlayLevelSound(x < LEVELX(BX1) ? LEVELX(BX1) :
11843 x > LEVELX(BX2) ? LEVELX(BX2) : x,
11844 y < LEVELY(BY1) ? LEVELY(BY1) :
11845 y > LEVELY(BY2) ? LEVELY(BY2) : y,
11849 static void PlayLevelSoundAction(int x, int y, int action)
11851 PlayLevelSoundElementAction(x, y, Feld[x][y], action);
11854 static void PlayLevelSoundElementAction(int x, int y, int element, int action)
11856 int sound_effect = element_info[SND_ELEMENT(element)].sound[action];
11858 if (sound_effect != SND_UNDEFINED)
11859 PlayLevelSound(x, y, sound_effect);
11862 static void PlayLevelSoundElementActionIfLoop(int x, int y, int element,
11865 int sound_effect = element_info[SND_ELEMENT(element)].sound[action];
11867 if (sound_effect != SND_UNDEFINED && IS_LOOP_SOUND(sound_effect))
11868 PlayLevelSound(x, y, sound_effect);
11871 static void PlayLevelSoundActionIfLoop(int x, int y, int action)
11873 int sound_effect = element_info[SND_ELEMENT(Feld[x][y])].sound[action];
11875 if (sound_effect != SND_UNDEFINED && IS_LOOP_SOUND(sound_effect))
11876 PlayLevelSound(x, y, sound_effect);
11879 static void StopLevelSoundActionIfLoop(int x, int y, int action)
11881 int sound_effect = element_info[SND_ELEMENT(Feld[x][y])].sound[action];
11883 if (sound_effect != SND_UNDEFINED && IS_LOOP_SOUND(sound_effect))
11884 StopSound(sound_effect);
11887 static void PlayLevelMusic()
11889 if (levelset.music[level_nr] != MUS_UNDEFINED)
11890 PlayMusic(levelset.music[level_nr]); /* from config file */
11892 PlayMusic(MAP_NOCONF_MUSIC(level_nr)); /* from music dir */
11895 void PlayLevelSound_EM(int x, int y, int element_em, int sample)
11897 int element = (element_em > -1 ? map_element_EM_to_RND(element_em) : 0);
11902 PlayLevelSoundElementAction(x, y, element, ACTION_WALKING);
11906 PlayLevelSoundElementAction(x, y, element, ACTION_PUSHING);
11910 PlayLevelSoundElementAction(x, y, element, ACTION_IMPACT);
11914 PlayLevelSoundElementAction(x, y, element, ACTION_IMPACT);
11918 PlayLevelSoundElementAction(x, y, element, ACTION_BREAKING);
11922 PlayLevelSoundElementAction(x, y, element, ACTION_MOVING);
11926 PlayLevelSoundElementAction(x, y, element, ACTION_MOVING);
11929 case SAMPLE_android_clone:
11930 PlayLevelSoundElementAction(x, y, element, ACTION_DROPPING);
11933 case SAMPLE_android_move:
11934 PlayLevelSoundElementAction(x, y, element, ACTION_MOVING);
11937 case SAMPLE_spring:
11938 PlayLevelSoundElementAction(x, y, element, ACTION_IMPACT);
11942 PlayLevelSoundElementAction(x, y, element, ACTION_EATING);
11946 PlayLevelSoundElementAction(x, y, element, ACTION_WAITING);
11949 case SAMPLE_eater_eat:
11950 PlayLevelSoundElementAction(x, y, element, ACTION_DIGGING);
11954 PlayLevelSoundElementAction(x, y, element, ACTION_MOVING);
11957 case SAMPLE_collect:
11958 PlayLevelSoundElementAction(x, y, element, ACTION_COLLECTING);
11961 case SAMPLE_diamond:
11962 PlayLevelSoundElementAction(x, y, element, ACTION_IMPACT);
11965 case SAMPLE_squash:
11966 /* !!! CHECK THIS !!! */
11968 PlayLevelSoundElementAction(x, y, element, ACTION_BREAKING);
11970 PlayLevelSoundElementAction(x, y, element, ACTION_SMASHED_BY_ROCK);
11974 case SAMPLE_wonderfall:
11975 PlayLevelSoundElementAction(x, y, element, ACTION_FILLING);
11979 PlayLevelSoundElementAction(x, y, element, ACTION_IMPACT);
11983 PlayLevelSoundElementAction(x, y, element, ACTION_PUSHING);
11987 PlayLevelSoundElementAction(x, y, element, ACTION_DIGGING);
11991 PlayLevelSoundElementAction(x, y, element, ACTION_SPLASHING);
11995 PlayLevelSoundElementAction(x, y, element, ACTION_DROPPING);
11999 PlayLevelSoundElementAction(x, y, element, ACTION_GROWING);
12002 case SAMPLE_wonder:
12003 PlayLevelSoundElementAction(x, y, element, ACTION_ACTIVE);
12007 PlayLevelSoundElementAction(x, y, element, ACTION_PASSING);
12010 case SAMPLE_exit_open:
12011 PlayLevelSoundElementAction(x, y, element, ACTION_OPENING);
12014 case SAMPLE_exit_leave:
12015 PlayLevelSoundElementAction(x, y, element, ACTION_PASSING);
12018 case SAMPLE_dynamite:
12019 PlayLevelSoundElementAction(x, y, element, ACTION_DROPPING);
12023 PlayLevelSoundElementAction(x, y, element, ACTION_ACTIVE);
12027 PlayLevelSoundElementAction(x, y, element, ACTION_ACTIVATING);
12031 PlayLevelSoundElementAction(x, y, element, ACTION_ACTIVE);
12035 PlayLevelSoundElementAction(x, y, element, ACTION_EXPLODING);
12039 PlayLevelSoundElementAction(x, y, element, ACTION_DYING);
12043 PlaySoundStereo(SND_GAME_RUNNING_OUT_OF_TIME, SOUND_MIDDLE);
12047 PlayLevelSoundElementAction(x, y, element, ACTION_DEFAULT);
12052 void RaiseScore(int value)
12054 local_player->score += value;
12056 DrawGameValue_Score(local_player->score);
12059 void RaiseScoreElement(int element)
12064 case EL_BD_DIAMOND:
12065 case EL_EMERALD_YELLOW:
12066 case EL_EMERALD_RED:
12067 case EL_EMERALD_PURPLE:
12068 case EL_SP_INFOTRON:
12069 RaiseScore(level.score[SC_EMERALD]);
12072 RaiseScore(level.score[SC_DIAMOND]);
12075 RaiseScore(level.score[SC_CRYSTAL]);
12078 RaiseScore(level.score[SC_PEARL]);
12081 case EL_BD_BUTTERFLY:
12082 case EL_SP_ELECTRON:
12083 RaiseScore(level.score[SC_BUG]);
12086 case EL_BD_FIREFLY:
12087 case EL_SP_SNIKSNAK:
12088 RaiseScore(level.score[SC_SPACESHIP]);
12091 case EL_DARK_YAMYAM:
12092 RaiseScore(level.score[SC_YAMYAM]);
12095 RaiseScore(level.score[SC_ROBOT]);
12098 RaiseScore(level.score[SC_PACMAN]);
12101 RaiseScore(level.score[SC_NUT]);
12104 case EL_EM_DYNAMITE:
12105 case EL_SP_DISK_RED:
12106 case EL_DYNABOMB_INCREASE_NUMBER:
12107 case EL_DYNABOMB_INCREASE_SIZE:
12108 case EL_DYNABOMB_INCREASE_POWER:
12109 RaiseScore(level.score[SC_DYNAMITE]);
12111 case EL_SHIELD_NORMAL:
12112 case EL_SHIELD_DEADLY:
12113 RaiseScore(level.score[SC_SHIELD]);
12115 case EL_EXTRA_TIME:
12116 RaiseScore(level.extra_time_score);
12130 RaiseScore(level.score[SC_KEY]);
12133 RaiseScore(element_info[element].collect_score);
12138 void RequestQuitGame(boolean ask_if_really_quit)
12140 if (AllPlayersGone ||
12141 !ask_if_really_quit ||
12142 level_editor_test_game ||
12143 Request("Do you really want to quit the game ?",
12144 REQ_ASK | REQ_STAY_CLOSED))
12146 #if defined(NETWORK_AVALIABLE)
12147 if (options.network)
12148 SendToServer_StopPlaying();
12152 game_status = GAME_MODE_MAIN;
12158 if (tape.playing && tape.deactivate_display)
12159 TapeDeactivateDisplayOff(TRUE);
12161 OpenDoor(DOOR_OPEN_1 | DOOR_COPY_BACK);
12163 if (tape.playing && tape.deactivate_display)
12164 TapeDeactivateDisplayOn();
12169 /* ---------- new game button stuff ---------------------------------------- */
12171 /* graphic position values for game buttons */
12172 #define GAME_BUTTON_XSIZE 30
12173 #define GAME_BUTTON_YSIZE 30
12174 #define GAME_BUTTON_XPOS 5
12175 #define GAME_BUTTON_YPOS 215
12176 #define SOUND_BUTTON_XPOS 5
12177 #define SOUND_BUTTON_YPOS (GAME_BUTTON_YPOS + GAME_BUTTON_YSIZE)
12179 #define GAME_BUTTON_STOP_XPOS (GAME_BUTTON_XPOS + 0 * GAME_BUTTON_XSIZE)
12180 #define GAME_BUTTON_PAUSE_XPOS (GAME_BUTTON_XPOS + 1 * GAME_BUTTON_XSIZE)
12181 #define GAME_BUTTON_PLAY_XPOS (GAME_BUTTON_XPOS + 2 * GAME_BUTTON_XSIZE)
12182 #define SOUND_BUTTON_MUSIC_XPOS (SOUND_BUTTON_XPOS + 0 * GAME_BUTTON_XSIZE)
12183 #define SOUND_BUTTON_LOOPS_XPOS (SOUND_BUTTON_XPOS + 1 * GAME_BUTTON_XSIZE)
12184 #define SOUND_BUTTON_SIMPLE_XPOS (SOUND_BUTTON_XPOS + 2 * GAME_BUTTON_XSIZE)
12191 } gamebutton_info[NUM_GAME_BUTTONS] =
12194 GAME_BUTTON_STOP_XPOS, GAME_BUTTON_YPOS,
12199 GAME_BUTTON_PAUSE_XPOS, GAME_BUTTON_YPOS,
12200 GAME_CTRL_ID_PAUSE,
12204 GAME_BUTTON_PLAY_XPOS, GAME_BUTTON_YPOS,
12209 SOUND_BUTTON_MUSIC_XPOS, SOUND_BUTTON_YPOS,
12210 SOUND_CTRL_ID_MUSIC,
12211 "background music on/off"
12214 SOUND_BUTTON_LOOPS_XPOS, SOUND_BUTTON_YPOS,
12215 SOUND_CTRL_ID_LOOPS,
12216 "sound loops on/off"
12219 SOUND_BUTTON_SIMPLE_XPOS, SOUND_BUTTON_YPOS,
12220 SOUND_CTRL_ID_SIMPLE,
12221 "normal sounds on/off"
12225 void CreateGameButtons()
12229 for (i = 0; i < NUM_GAME_BUTTONS; i++)
12231 Bitmap *gd_bitmap = graphic_info[IMG_GLOBAL_DOOR].bitmap;
12232 struct GadgetInfo *gi;
12235 unsigned long event_mask;
12236 int gd_xoffset, gd_yoffset;
12237 int gd_x1, gd_x2, gd_y1, gd_y2;
12240 gd_xoffset = gamebutton_info[i].x;
12241 gd_yoffset = gamebutton_info[i].y;
12242 gd_x1 = DOOR_GFX_PAGEX4 + gd_xoffset;
12243 gd_x2 = DOOR_GFX_PAGEX3 + gd_xoffset;
12245 if (id == GAME_CTRL_ID_STOP ||
12246 id == GAME_CTRL_ID_PAUSE ||
12247 id == GAME_CTRL_ID_PLAY)
12249 button_type = GD_TYPE_NORMAL_BUTTON;
12251 event_mask = GD_EVENT_RELEASED;
12252 gd_y1 = DOOR_GFX_PAGEY1 + gd_yoffset - GAME_BUTTON_YSIZE;
12253 gd_y2 = DOOR_GFX_PAGEY1 + gd_yoffset - GAME_BUTTON_YSIZE;
12257 button_type = GD_TYPE_CHECK_BUTTON;
12259 ((id == SOUND_CTRL_ID_MUSIC && setup.sound_music) ||
12260 (id == SOUND_CTRL_ID_LOOPS && setup.sound_loops) ||
12261 (id == SOUND_CTRL_ID_SIMPLE && setup.sound_simple) ? TRUE : FALSE);
12262 event_mask = GD_EVENT_PRESSED;
12263 gd_y1 = DOOR_GFX_PAGEY1 + gd_yoffset;
12264 gd_y2 = DOOR_GFX_PAGEY1 + gd_yoffset - GAME_BUTTON_YSIZE;
12267 gi = CreateGadget(GDI_CUSTOM_ID, id,
12268 GDI_INFO_TEXT, gamebutton_info[i].infotext,
12269 GDI_X, DX + gd_xoffset,
12270 GDI_Y, DY + gd_yoffset,
12271 GDI_WIDTH, GAME_BUTTON_XSIZE,
12272 GDI_HEIGHT, GAME_BUTTON_YSIZE,
12273 GDI_TYPE, button_type,
12274 GDI_STATE, GD_BUTTON_UNPRESSED,
12275 GDI_CHECKED, checked,
12276 GDI_DESIGN_UNPRESSED, gd_bitmap, gd_x1, gd_y1,
12277 GDI_DESIGN_PRESSED, gd_bitmap, gd_x2, gd_y1,
12278 GDI_ALT_DESIGN_UNPRESSED, gd_bitmap, gd_x1, gd_y2,
12279 GDI_ALT_DESIGN_PRESSED, gd_bitmap, gd_x2, gd_y2,
12280 GDI_EVENT_MASK, event_mask,
12281 GDI_CALLBACK_ACTION, HandleGameButtons,
12285 Error(ERR_EXIT, "cannot create gadget");
12287 game_gadget[id] = gi;
12291 void FreeGameButtons()
12295 for (i = 0; i < NUM_GAME_BUTTONS; i++)
12296 FreeGadget(game_gadget[i]);
12299 static void MapGameButtons()
12303 for (i = 0; i < NUM_GAME_BUTTONS; i++)
12304 MapGadget(game_gadget[i]);
12307 void UnmapGameButtons()
12311 for (i = 0; i < NUM_GAME_BUTTONS; i++)
12312 UnmapGadget(game_gadget[i]);
12315 static void HandleGameButtons(struct GadgetInfo *gi)
12317 int id = gi->custom_id;
12319 if (game_status != GAME_MODE_PLAYING)
12324 case GAME_CTRL_ID_STOP:
12325 RequestQuitGame(TRUE);
12328 case GAME_CTRL_ID_PAUSE:
12329 if (options.network)
12331 #if defined(NETWORK_AVALIABLE)
12333 SendToServer_ContinuePlaying();
12335 SendToServer_PausePlaying();
12339 TapeTogglePause(TAPE_TOGGLE_MANUAL);
12342 case GAME_CTRL_ID_PLAY:
12345 #if defined(NETWORK_AVALIABLE)
12346 if (options.network)
12347 SendToServer_ContinuePlaying();
12351 tape.pausing = FALSE;
12352 DrawVideoDisplay(VIDEO_STATE_PAUSE_OFF,0);
12357 case SOUND_CTRL_ID_MUSIC:
12358 if (setup.sound_music)
12360 setup.sound_music = FALSE;
12363 else if (audio.music_available)
12365 setup.sound = setup.sound_music = TRUE;
12367 SetAudioMode(setup.sound);
12373 case SOUND_CTRL_ID_LOOPS:
12374 if (setup.sound_loops)
12375 setup.sound_loops = FALSE;
12376 else if (audio.loops_available)
12378 setup.sound = setup.sound_loops = TRUE;
12379 SetAudioMode(setup.sound);
12383 case SOUND_CTRL_ID_SIMPLE:
12384 if (setup.sound_simple)
12385 setup.sound_simple = FALSE;
12386 else if (audio.sound_available)
12388 setup.sound = setup.sound_simple = TRUE;
12389 SetAudioMode(setup.sound);