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 = -999, scroll_yy = -999;
3151 ScrollScreen(NULL, SCROLL_GO_ON); /* scroll last frame to full tile */
3153 while (scroll_xx != scroll_x || scroll_yy != scroll_y)
3156 int fx = FX, fy = FY;
3158 scroll_xx = (player->jx < SBX_Left + MIDPOSX ? SBX_Left :
3159 player->jx > SBX_Right + MIDPOSX ? SBX_Right :
3160 player->jx - MIDPOSX);
3162 scroll_yy = (player->jy < SBY_Upper + MIDPOSY ? SBY_Upper :
3163 player->jy > SBY_Lower + MIDPOSY ? SBY_Lower :
3164 player->jy - MIDPOSY);
3166 dx = (scroll_xx < scroll_x ? +1 : scroll_xx > scroll_x ? -1 : 0);
3167 dy = (scroll_yy < scroll_y ? +1 : scroll_yy > scroll_y ? -1 : 0);
3169 if (dx == 0 && dy == 0) /* no scrolling needed at all */
3175 fx += dx * TILEX / 2;
3176 fy += dy * TILEY / 2;
3178 ScrollLevel(dx, dy);
3181 /* scroll in two steps of half tile size to make things smoother */
3182 BlitBitmap(drawto_field, window, fx, fy, SXSIZE, SYSIZE, SX, SY);
3184 Delay(wait_delay_value);
3186 /* scroll second step to align at full tile size */
3188 Delay(wait_delay_value);
3193 Delay(wait_delay_value);
3197 void RelocatePlayer(int jx, int jy, int el_player_raw)
3199 int el_player = GET_PLAYER_ELEMENT(el_player_raw);
3200 int player_nr = GET_PLAYER_NR(el_player);
3201 struct PlayerInfo *player = &stored_player[player_nr];
3202 boolean ffwd_delay = (tape.playing && tape.fast_forward);
3203 boolean no_delay = (tape.warp_forward);
3204 int frame_delay_value = (ffwd_delay ? FfwdFrameDelay : GameFrameDelay);
3205 int wait_delay_value = (no_delay ? 0 : frame_delay_value);
3206 int old_jx = player->jx;
3207 int old_jy = player->jy;
3208 int old_element = Feld[old_jx][old_jy];
3209 int element = Feld[jx][jy];
3210 boolean player_relocated = (old_jx != jx || old_jy != jy);
3212 int move_dir_horiz = (jx < old_jx ? MV_LEFT : jx > old_jx ? MV_RIGHT : 0);
3213 int move_dir_vert = (jy < old_jy ? MV_UP : jy > old_jy ? MV_DOWN : 0);
3214 int enter_side_horiz = MV_DIR_OPPOSITE(move_dir_horiz);
3215 int enter_side_vert = MV_DIR_OPPOSITE(move_dir_vert);
3216 int leave_side_horiz = move_dir_horiz;
3217 int leave_side_vert = move_dir_vert;
3218 int enter_side = enter_side_horiz | enter_side_vert;
3219 int leave_side = leave_side_horiz | leave_side_vert;
3221 if (player->GameOver) /* do not reanimate dead player */
3224 if (!player_relocated) /* no need to relocate the player */
3227 if (IS_PLAYER(jx, jy)) /* player already placed at new position */
3229 RemoveField(jx, jy); /* temporarily remove newly placed player */
3230 DrawLevelField(jx, jy);
3233 if (player->present)
3235 while (player->MovPos)
3237 ScrollPlayer(player, SCROLL_GO_ON);
3238 ScrollScreen(NULL, SCROLL_GO_ON);
3240 AdvanceFrameAndPlayerCounters(player->index_nr);
3245 Delay(wait_delay_value);
3248 DrawPlayer(player); /* needed here only to cleanup last field */
3249 DrawLevelField(player->jx, player->jy); /* remove player graphic */
3251 player->is_moving = FALSE;
3254 if (IS_CUSTOM_ELEMENT(old_element))
3255 CheckElementChangeByPlayer(old_jx, old_jy, old_element,
3257 player->index_bit, leave_side);
3259 CheckTriggeredElementChangeByPlayer(old_jx, old_jy, old_element,
3261 player->index_bit, leave_side);
3263 Feld[jx][jy] = el_player;
3264 InitPlayerField(jx, jy, el_player, TRUE);
3266 if (!ELEM_IS_PLAYER(element)) /* player may be set on walkable element */
3268 Feld[jx][jy] = element;
3269 InitField(jx, jy, FALSE);
3273 /* only visually relocate centered player */
3274 if (player->index_nr == game.centered_player_nr)
3275 DrawRelocatePlayer(player, level.instant_relocation);
3277 if (player == local_player) /* only visually relocate local player */
3278 DrawRelocatePlayer(player, level.instant_relocation);
3281 TestIfPlayerTouchesBadThing(jx, jy);
3282 TestIfPlayerTouchesCustomElement(jx, jy);
3284 if (IS_CUSTOM_ELEMENT(element))
3285 CheckElementChangeByPlayer(jx, jy, element, CE_ENTERED_BY_PLAYER,
3286 player->index_bit, enter_side);
3288 CheckTriggeredElementChangeByPlayer(jx, jy, element, CE_PLAYER_ENTERS_X,
3289 player->index_bit, enter_side);
3292 void Explode(int ex, int ey, int phase, int mode)
3298 /* !!! eliminate this variable !!! */
3299 int delay = (game.emulation == EMU_SUPAPLEX ? 3 : 2);
3301 if (game.explosions_delayed)
3303 ExplodeField[ex][ey] = mode;
3307 if (phase == EX_PHASE_START) /* initialize 'Store[][]' field */
3309 int center_element = Feld[ex][ey];
3310 int artwork_element, explosion_element; /* set these values later */
3313 /* --- This is only really needed (and now handled) in "Impact()". --- */
3314 /* do not explode moving elements that left the explode field in time */
3315 if (game.engine_version >= VERSION_IDENT(2,2,0,7) &&
3316 center_element == EL_EMPTY &&
3317 (mode == EX_TYPE_NORMAL || mode == EX_TYPE_CENTER))
3322 /* !!! at this place, the center element may be EL_BLOCKED !!! */
3323 if (mode == EX_TYPE_NORMAL ||
3324 mode == EX_TYPE_CENTER ||
3325 mode == EX_TYPE_CROSS)
3326 PlayLevelSoundElementAction(ex, ey, artwork_element, ACTION_EXPLODING);
3329 /* remove things displayed in background while burning dynamite */
3330 if (Back[ex][ey] != EL_EMPTY && !IS_INDESTRUCTIBLE(Back[ex][ey]))
3333 if (IS_MOVING(ex, ey) || IS_BLOCKED(ex, ey))
3335 /* put moving element to center field (and let it explode there) */
3336 center_element = MovingOrBlocked2Element(ex, ey);
3337 RemoveMovingField(ex, ey);
3338 Feld[ex][ey] = center_element;
3341 /* now "center_element" is finally determined -- set related values now */
3342 artwork_element = center_element; /* for custom player artwork */
3343 explosion_element = center_element; /* for custom player artwork */
3345 if (IS_PLAYER(ex, ey))
3347 int player_nr = GET_PLAYER_NR(StorePlayer[ex][ey]);
3349 artwork_element = stored_player[player_nr].artwork_element;
3351 if (level.use_explosion_element[player_nr])
3353 explosion_element = level.explosion_element[player_nr];
3354 artwork_element = explosion_element;
3359 if (mode == EX_TYPE_NORMAL ||
3360 mode == EX_TYPE_CENTER ||
3361 mode == EX_TYPE_CROSS)
3362 PlayLevelSoundElementAction(ex, ey, artwork_element, ACTION_EXPLODING);
3366 last_phase = element_info[explosion_element].explosion_delay + 1;
3368 last_phase = element_info[center_element].explosion_delay + 1;
3371 for (y = ey - 1; y <= ey + 1; y++) for (x = ex - 1; x <= ex + 1; x++)
3373 int xx = x - ex + 1;
3374 int yy = y - ey + 1;
3377 if (!IN_LEV_FIELD(x, y) ||
3378 (mode & EX_TYPE_SINGLE_TILE && (x != ex || y != ey)) ||
3379 (mode == EX_TYPE_CROSS && (x != ex && y != ey)))
3382 element = Feld[x][y];
3384 if (IS_MOVING(x, y) || IS_BLOCKED(x, y))
3386 element = MovingOrBlocked2Element(x, y);
3388 if (!IS_EXPLOSION_PROOF(element))
3389 RemoveMovingField(x, y);
3392 /* indestructible elements can only explode in center (but not flames) */
3393 if ((IS_EXPLOSION_PROOF(element) && (x != ex || y != ey ||
3394 mode == EX_TYPE_BORDER)) ||
3395 element == EL_FLAMES)
3398 /* no idea why this was changed from 3.0.8 to 3.1.0 -- this causes buggy
3399 behaviour, for example when touching a yamyam that explodes to rocks
3400 with active deadly shield, a rock is created under the player !!! */
3401 /* (case 1 (surely buggy): >= 3.1.0, case 2 (maybe buggy): <= 3.0.8) */
3403 if (IS_PLAYER(x, y) && SHIELD_ON(PLAYERINFO(x, y)) &&
3404 (game.engine_version < VERSION_IDENT(3,1,0,0) ||
3405 (x == ex && y == ey && mode != EX_TYPE_BORDER)))
3407 if (IS_PLAYER(x, y) && SHIELD_ON(PLAYERINFO(x, y)))
3410 if (IS_ACTIVE_BOMB(element))
3412 /* re-activate things under the bomb like gate or penguin */
3413 Feld[x][y] = (Back[x][y] ? Back[x][y] : EL_EMPTY);
3420 /* save walkable background elements while explosion on same tile */
3421 if (IS_WALKABLE(element) && IS_INDESTRUCTIBLE(element) &&
3422 (x != ex || y != ey || mode == EX_TYPE_BORDER))
3423 Back[x][y] = element;
3425 /* ignite explodable elements reached by other explosion */
3426 if (element == EL_EXPLOSION)
3427 element = Store2[x][y];
3429 if (AmoebaNr[x][y] &&
3430 (element == EL_AMOEBA_FULL ||
3431 element == EL_BD_AMOEBA ||
3432 element == EL_AMOEBA_GROWING))
3434 AmoebaCnt[AmoebaNr[x][y]]--;
3435 AmoebaCnt2[AmoebaNr[x][y]]--;
3440 if (IS_PLAYER(ex, ey) && !PLAYER_EXPLOSION_PROTECTED(ex, ey))
3443 int player_nr = StorePlayer[ex][ey] - EL_PLAYER_1;
3445 Store[x][y] = EL_PLAYER_IS_EXPLODING_1 + player_nr;
3447 switch(StorePlayer[ex][ey])
3450 Store[x][y] = EL_PLAYER_IS_EXPLODING_2;
3453 Store[x][y] = EL_PLAYER_IS_EXPLODING_3;
3456 Store[x][y] = EL_PLAYER_IS_EXPLODING_4;
3460 Store[x][y] = EL_PLAYER_IS_EXPLODING_1;
3465 if (PLAYERINFO(ex, ey)->use_murphy)
3466 Store[x][y] = EL_EMPTY;
3469 /* !!! check this case -- currently needed for rnd_rado_negundo_v,
3470 !!! levels 015 018 019 020 021 022 023 026 027 028 !!! */
3471 else if (ELEM_IS_PLAYER(center_element))
3472 Store[x][y] = EL_EMPTY;
3473 else if (center_element == EL_YAMYAM)
3474 Store[x][y] = level.yamyam_content[game.yamyam_content_nr].e[xx][yy];
3475 else if (element_info[center_element].content.e[xx][yy] != EL_EMPTY)
3476 Store[x][y] = element_info[center_element].content.e[xx][yy];
3478 /* needed because EL_BD_BUTTERFLY is not defined as "CAN_EXPLODE"
3479 (killing EL_BD_BUTTERFLY with dynamite would result in BD diamond
3480 otherwise) -- FIX THIS !!! */
3481 else if (!CAN_EXPLODE(element) && element != EL_BD_BUTTERFLY)
3482 Store[x][y] = element_info[element].content.e[1][1];
3484 else if (!CAN_EXPLODE(element))
3485 Store[x][y] = element_info[element].content.e[1][1];
3488 Store[x][y] = EL_EMPTY;
3490 else if (center_element == EL_MOLE)
3491 Store[x][y] = EL_EMERALD_RED;
3492 else if (center_element == EL_PENGUIN)
3493 Store[x][y] = EL_EMERALD_PURPLE;
3494 else if (center_element == EL_BUG)
3495 Store[x][y] = ((x == ex && y == ey) ? EL_DIAMOND : EL_EMERALD);
3496 else if (center_element == EL_BD_BUTTERFLY)
3497 Store[x][y] = EL_BD_DIAMOND;
3498 else if (center_element == EL_SP_ELECTRON)
3499 Store[x][y] = EL_SP_INFOTRON;
3500 else if (center_element == EL_AMOEBA_TO_DIAMOND)
3501 Store[x][y] = level.amoeba_content;
3502 else if (center_element == EL_YAMYAM)
3503 Store[x][y] = level.yamyam_content[game.yamyam_content_nr].e[xx][yy];
3504 else if (IS_CUSTOM_ELEMENT(center_element) &&
3505 element_info[center_element].content.e[xx][yy] != EL_EMPTY)
3506 Store[x][y] = element_info[center_element].content.e[xx][yy];
3507 else if (element == EL_WALL_EMERALD)
3508 Store[x][y] = EL_EMERALD;
3509 else if (element == EL_WALL_DIAMOND)
3510 Store[x][y] = EL_DIAMOND;
3511 else if (element == EL_WALL_BD_DIAMOND)
3512 Store[x][y] = EL_BD_DIAMOND;
3513 else if (element == EL_WALL_EMERALD_YELLOW)
3514 Store[x][y] = EL_EMERALD_YELLOW;
3515 else if (element == EL_WALL_EMERALD_RED)
3516 Store[x][y] = EL_EMERALD_RED;
3517 else if (element == EL_WALL_EMERALD_PURPLE)
3518 Store[x][y] = EL_EMERALD_PURPLE;
3519 else if (element == EL_WALL_PEARL)
3520 Store[x][y] = EL_PEARL;
3521 else if (element == EL_WALL_CRYSTAL)
3522 Store[x][y] = EL_CRYSTAL;
3523 else if (IS_CUSTOM_ELEMENT(element) && !CAN_EXPLODE(element))
3524 Store[x][y] = element_info[element].content.e[1][1];
3526 Store[x][y] = EL_EMPTY;
3529 if (x != ex || y != ey || mode == EX_TYPE_BORDER ||
3530 center_element == EL_AMOEBA_TO_DIAMOND)
3531 Store2[x][y] = element;
3533 Feld[x][y] = EL_EXPLOSION;
3534 GfxElement[x][y] = artwork_element;
3537 printf(":: setting gfx(%d,%d) to %d ['%s']\n",
3538 x, y, artwork_element, EL_NAME(artwork_element));
3541 ExplodePhase[x][y] = 1;
3542 ExplodeDelay[x][y] = last_phase;
3547 if (center_element == EL_YAMYAM)
3548 game.yamyam_content_nr =
3549 (game.yamyam_content_nr + 1) % level.num_yamyam_contents;
3561 GfxFrame[x][y] = 0; /* restart explosion animation */
3563 last_phase = ExplodeDelay[x][y];
3565 ExplodePhase[x][y] = (phase < last_phase ? phase + 1 : 0);
3569 /* activate this even in non-DEBUG version until cause for crash in
3570 getGraphicAnimationFrame() (see below) is found and eliminated */
3576 /* this can happen if the player leaves an explosion just in time */
3577 if (GfxElement[x][y] == EL_UNDEFINED)
3578 GfxElement[x][y] = EL_EMPTY;
3580 if (GfxElement[x][y] == EL_UNDEFINED)
3583 printf("Explode(): x = %d, y = %d: GfxElement == EL_UNDEFINED\n", x, y);
3584 printf("Explode(): This should never happen!\n");
3587 GfxElement[x][y] = EL_EMPTY;
3593 border_element = Store2[x][y];
3594 if (IS_PLAYER(x, y) && !PLAYER_EXPLOSION_PROTECTED(x, y))
3595 border_element = StorePlayer[x][y];
3597 if (phase == element_info[border_element].ignition_delay ||
3598 phase == last_phase)
3600 boolean border_explosion = FALSE;
3602 if (IS_PLAYER(x, y) && PLAYERINFO(x, y)->present &&
3603 !PLAYER_EXPLOSION_PROTECTED(x, y))
3605 KillPlayerUnlessExplosionProtected(x, y);
3606 border_explosion = TRUE;
3608 else if (CAN_EXPLODE_BY_EXPLOSION(border_element))
3610 Feld[x][y] = Store2[x][y];
3613 border_explosion = TRUE;
3615 else if (border_element == EL_AMOEBA_TO_DIAMOND)
3617 AmoebeUmwandeln(x, y);
3619 border_explosion = TRUE;
3622 /* if an element just explodes due to another explosion (chain-reaction),
3623 do not immediately end the new explosion when it was the last frame of
3624 the explosion (as it would be done in the following "if"-statement!) */
3625 if (border_explosion && phase == last_phase)
3629 if (phase == last_phase)
3633 element = Feld[x][y] = Store[x][y];
3634 Store[x][y] = Store2[x][y] = 0;
3635 GfxElement[x][y] = EL_UNDEFINED;
3637 /* player can escape from explosions and might therefore be still alive */
3638 if (element >= EL_PLAYER_IS_EXPLODING_1 &&
3639 element <= EL_PLAYER_IS_EXPLODING_4)
3641 int player_nr = element - EL_PLAYER_IS_EXPLODING_1;
3642 int explosion_element = EL_PLAYER_1 + player_nr;
3643 int xx = MIN(MAX(0, x - stored_player[player_nr].jx + 1), 2);
3644 int yy = MIN(MAX(0, y - stored_player[player_nr].jy + 1), 2);
3646 if (level.use_explosion_element[player_nr])
3647 explosion_element = level.explosion_element[player_nr];
3649 Feld[x][y] = (stored_player[player_nr].active ? EL_EMPTY :
3650 element_info[explosion_element].content.e[xx][yy]);
3653 /* restore probably existing indestructible background element */
3654 if (Back[x][y] && IS_INDESTRUCTIBLE(Back[x][y]))
3655 element = Feld[x][y] = Back[x][y];
3658 MovDir[x][y] = MovPos[x][y] = MovDelay[x][y] = 0;
3659 GfxDir[x][y] = MV_NONE;
3660 ChangeDelay[x][y] = 0;
3661 ChangePage[x][y] = -1;
3663 #if USE_NEW_CUSTOM_VALUE
3664 CustomValue[x][y] = 0;
3667 InitField_WithBug2(x, y, FALSE);
3669 DrawLevelField(x, y);
3671 TestIfElementTouchesCustomElement(x, y);
3673 if (GFX_CRUMBLED(element))
3674 DrawLevelFieldCrumbledSandNeighbours(x, y);
3676 if (IS_PLAYER(x, y) && !PLAYERINFO(x, y)->present)
3677 StorePlayer[x][y] = 0;
3679 if (ELEM_IS_PLAYER(element))
3680 RelocatePlayer(x, y, element);
3682 else if (IN_SCR_FIELD(SCREENX(x), SCREENY(y)))
3684 int graphic = el_act2img(GfxElement[x][y], ACTION_EXPLODING);
3685 int frame = getGraphicAnimationFrame(graphic, GfxFrame[x][y]);
3688 DrawLevelFieldCrumbledSand(x, y);
3690 if (IS_WALKABLE_OVER(Back[x][y]) && Back[x][y] != EL_EMPTY)
3692 DrawLevelElement(x, y, Back[x][y]);
3693 DrawGraphicThruMask(SCREENX(x), SCREENY(y), graphic, frame);
3695 else if (IS_WALKABLE_UNDER(Back[x][y]))
3697 DrawGraphic(SCREENX(x), SCREENY(y), graphic, frame);
3698 DrawLevelElementThruMask(x, y, Back[x][y]);
3700 else if (!IS_WALKABLE_INSIDE(Back[x][y]))
3701 DrawGraphic(SCREENX(x), SCREENY(y), graphic, frame);
3705 void DynaExplode(int ex, int ey)
3708 int dynabomb_element = Feld[ex][ey];
3709 int dynabomb_size = 1;
3710 boolean dynabomb_xl = FALSE;
3711 struct PlayerInfo *player;
3712 static int xy[4][2] =
3720 if (IS_ACTIVE_BOMB(dynabomb_element))
3722 player = &stored_player[dynabomb_element - EL_DYNABOMB_PLAYER_1_ACTIVE];
3723 dynabomb_size = player->dynabomb_size;
3724 dynabomb_xl = player->dynabomb_xl;
3725 player->dynabombs_left++;
3728 Explode(ex, ey, EX_PHASE_START, EX_TYPE_CENTER);
3730 for (i = 0; i < NUM_DIRECTIONS; i++)
3732 for (j = 1; j <= dynabomb_size; j++)
3734 int x = ex + j * xy[i][0];
3735 int y = ey + j * xy[i][1];
3738 if (!IN_LEV_FIELD(x, y) || IS_INDESTRUCTIBLE(Feld[x][y]))
3741 element = Feld[x][y];
3743 /* do not restart explosions of fields with active bombs */
3744 if (element == EL_EXPLOSION && IS_ACTIVE_BOMB(Store2[x][y]))
3747 Explode(x, y, EX_PHASE_START, EX_TYPE_BORDER);
3749 if (element != EL_EMPTY && element != EL_EXPLOSION &&
3750 !IS_DIGGABLE(element) && !dynabomb_xl)
3756 void Bang(int x, int y)
3758 int element = MovingOrBlocked2Element(x, y);
3759 int explosion_type = EX_TYPE_NORMAL;
3761 if (IS_PLAYER(x, y) && !PLAYER_EXPLOSION_PROTECTED(x, y))
3763 struct PlayerInfo *player = PLAYERINFO(x, y);
3765 element = Feld[x][y] = (player->use_murphy ? EL_SP_MURPHY :
3766 player->element_nr);
3768 if (level.use_explosion_element[player->index_nr])
3770 int explosion_element = level.explosion_element[player->index_nr];
3772 if (element_info[explosion_element].explosion_type == EXPLODES_CROSS)
3773 explosion_type = EX_TYPE_CROSS;
3774 else if (element_info[explosion_element].explosion_type == EXPLODES_1X1)
3775 explosion_type = EX_TYPE_CENTER;
3783 case EL_BD_BUTTERFLY:
3786 case EL_DARK_YAMYAM:
3790 RaiseScoreElement(element);
3793 case EL_DYNABOMB_PLAYER_1_ACTIVE:
3794 case EL_DYNABOMB_PLAYER_2_ACTIVE:
3795 case EL_DYNABOMB_PLAYER_3_ACTIVE:
3796 case EL_DYNABOMB_PLAYER_4_ACTIVE:
3797 case EL_DYNABOMB_INCREASE_NUMBER:
3798 case EL_DYNABOMB_INCREASE_SIZE:
3799 case EL_DYNABOMB_INCREASE_POWER:
3800 explosion_type = EX_TYPE_DYNA;
3805 case EL_LAMP_ACTIVE:
3806 case EL_AMOEBA_TO_DIAMOND:
3807 if (!IS_PLAYER(x, y)) /* penguin and player may be at same field */
3808 explosion_type = EX_TYPE_CENTER;
3812 if (element_info[element].explosion_type == EXPLODES_CROSS)
3813 explosion_type = EX_TYPE_CROSS;
3814 else if (element_info[element].explosion_type == EXPLODES_1X1)
3815 explosion_type = EX_TYPE_CENTER;
3819 if (explosion_type == EX_TYPE_DYNA)
3822 Explode(x, y, EX_PHASE_START, explosion_type);
3824 CheckTriggeredElementChange(x, y, element, CE_EXPLOSION_OF_X);
3827 void SplashAcid(int x, int y)
3829 if (IN_LEV_FIELD(x - 1, y - 1) && IS_FREE(x - 1, y - 1) &&
3830 (!IN_LEV_FIELD(x - 1, y - 2) ||
3831 !CAN_FALL(MovingOrBlocked2Element(x - 1, y - 2))))
3832 Feld[x - 1][y - 1] = EL_ACID_SPLASH_LEFT;
3834 if (IN_LEV_FIELD(x + 1, y - 1) && IS_FREE(x + 1, y - 1) &&
3835 (!IN_LEV_FIELD(x + 1, y - 2) ||
3836 !CAN_FALL(MovingOrBlocked2Element(x + 1, y - 2))))
3837 Feld[x + 1][y - 1] = EL_ACID_SPLASH_RIGHT;
3839 PlayLevelSound(x, y, SND_ACID_SPLASHING);
3842 static void InitBeltMovement()
3844 static int belt_base_element[4] =
3846 EL_CONVEYOR_BELT_1_LEFT,
3847 EL_CONVEYOR_BELT_2_LEFT,
3848 EL_CONVEYOR_BELT_3_LEFT,
3849 EL_CONVEYOR_BELT_4_LEFT
3851 static int belt_base_active_element[4] =
3853 EL_CONVEYOR_BELT_1_LEFT_ACTIVE,
3854 EL_CONVEYOR_BELT_2_LEFT_ACTIVE,
3855 EL_CONVEYOR_BELT_3_LEFT_ACTIVE,
3856 EL_CONVEYOR_BELT_4_LEFT_ACTIVE
3861 /* set frame order for belt animation graphic according to belt direction */
3862 for (i = 0; i < NUM_BELTS; i++)
3866 for (j = 0; j < NUM_BELT_PARTS; j++)
3868 int element = belt_base_active_element[belt_nr] + j;
3869 int graphic = el2img(element);
3871 if (game.belt_dir[i] == MV_LEFT)
3872 graphic_info[graphic].anim_mode &= ~ANIM_REVERSE;
3874 graphic_info[graphic].anim_mode |= ANIM_REVERSE;
3879 SCAN_PLAYFIELD(x, y)
3881 for (y = 0; y < lev_fieldy; y++) for (x = 0; x < lev_fieldx; x++)
3884 int element = Feld[x][y];
3886 for (i = 0; i < NUM_BELTS; i++)
3888 if (IS_BELT(element) && game.belt_dir[i] != MV_NONE)
3890 int e_belt_nr = getBeltNrFromBeltElement(element);
3893 if (e_belt_nr == belt_nr)
3895 int belt_part = Feld[x][y] - belt_base_element[belt_nr];
3897 Feld[x][y] = belt_base_active_element[belt_nr] + belt_part;
3904 static void ToggleBeltSwitch(int x, int y)
3906 static int belt_base_element[4] =
3908 EL_CONVEYOR_BELT_1_LEFT,
3909 EL_CONVEYOR_BELT_2_LEFT,
3910 EL_CONVEYOR_BELT_3_LEFT,
3911 EL_CONVEYOR_BELT_4_LEFT
3913 static int belt_base_active_element[4] =
3915 EL_CONVEYOR_BELT_1_LEFT_ACTIVE,
3916 EL_CONVEYOR_BELT_2_LEFT_ACTIVE,
3917 EL_CONVEYOR_BELT_3_LEFT_ACTIVE,
3918 EL_CONVEYOR_BELT_4_LEFT_ACTIVE
3920 static int belt_base_switch_element[4] =
3922 EL_CONVEYOR_BELT_1_SWITCH_LEFT,
3923 EL_CONVEYOR_BELT_2_SWITCH_LEFT,
3924 EL_CONVEYOR_BELT_3_SWITCH_LEFT,
3925 EL_CONVEYOR_BELT_4_SWITCH_LEFT
3927 static int belt_move_dir[4] =
3935 int element = Feld[x][y];
3936 int belt_nr = getBeltNrFromBeltSwitchElement(element);
3937 int belt_dir_nr = (game.belt_dir_nr[belt_nr] + 1) % 4;
3938 int belt_dir = belt_move_dir[belt_dir_nr];
3941 if (!IS_BELT_SWITCH(element))
3944 game.belt_dir_nr[belt_nr] = belt_dir_nr;
3945 game.belt_dir[belt_nr] = belt_dir;
3947 if (belt_dir_nr == 3)
3950 /* set frame order for belt animation graphic according to belt direction */
3951 for (i = 0; i < NUM_BELT_PARTS; i++)
3953 int element = belt_base_active_element[belt_nr] + i;
3954 int graphic = el2img(element);
3956 if (belt_dir == MV_LEFT)
3957 graphic_info[graphic].anim_mode &= ~ANIM_REVERSE;
3959 graphic_info[graphic].anim_mode |= ANIM_REVERSE;
3963 SCAN_PLAYFIELD(xx, yy)
3965 for (yy = 0; yy < lev_fieldy; yy++) for (xx = 0; xx < lev_fieldx; xx++)
3968 int element = Feld[xx][yy];
3970 if (IS_BELT_SWITCH(element))
3972 int e_belt_nr = getBeltNrFromBeltSwitchElement(element);
3974 if (e_belt_nr == belt_nr)
3976 Feld[xx][yy] = belt_base_switch_element[belt_nr] + belt_dir_nr;
3977 DrawLevelField(xx, yy);
3980 else if (IS_BELT(element) && belt_dir != MV_NONE)
3982 int e_belt_nr = getBeltNrFromBeltElement(element);
3984 if (e_belt_nr == belt_nr)
3986 int belt_part = Feld[xx][yy] - belt_base_element[belt_nr];
3988 Feld[xx][yy] = belt_base_active_element[belt_nr] + belt_part;
3989 DrawLevelField(xx, yy);
3992 else if (IS_BELT_ACTIVE(element) && belt_dir == MV_NONE)
3994 int e_belt_nr = getBeltNrFromBeltActiveElement(element);
3996 if (e_belt_nr == belt_nr)
3998 int belt_part = Feld[xx][yy] - belt_base_active_element[belt_nr];
4000 Feld[xx][yy] = belt_base_element[belt_nr] + belt_part;
4001 DrawLevelField(xx, yy);
4007 static void ToggleSwitchgateSwitch(int x, int y)
4011 game.switchgate_pos = !game.switchgate_pos;
4014 SCAN_PLAYFIELD(xx, yy)
4016 for (yy = 0; yy < lev_fieldy; yy++) for (xx = 0; xx < lev_fieldx; xx++)
4019 int element = Feld[xx][yy];
4021 if (element == EL_SWITCHGATE_SWITCH_UP ||
4022 element == EL_SWITCHGATE_SWITCH_DOWN)
4024 Feld[xx][yy] = EL_SWITCHGATE_SWITCH_UP + game.switchgate_pos;
4025 DrawLevelField(xx, yy);
4027 else if (element == EL_SWITCHGATE_OPEN ||
4028 element == EL_SWITCHGATE_OPENING)
4030 Feld[xx][yy] = EL_SWITCHGATE_CLOSING;
4032 PlayLevelSoundAction(xx, yy, ACTION_CLOSING);
4034 else if (element == EL_SWITCHGATE_CLOSED ||
4035 element == EL_SWITCHGATE_CLOSING)
4037 Feld[xx][yy] = EL_SWITCHGATE_OPENING;
4039 PlayLevelSoundAction(xx, yy, ACTION_OPENING);
4044 static int getInvisibleActiveFromInvisibleElement(int element)
4046 return (element == EL_INVISIBLE_STEELWALL ? EL_INVISIBLE_STEELWALL_ACTIVE :
4047 element == EL_INVISIBLE_WALL ? EL_INVISIBLE_WALL_ACTIVE :
4048 element == EL_INVISIBLE_SAND ? EL_INVISIBLE_SAND_ACTIVE :
4052 static int getInvisibleFromInvisibleActiveElement(int element)
4054 return (element == EL_INVISIBLE_STEELWALL_ACTIVE ? EL_INVISIBLE_STEELWALL :
4055 element == EL_INVISIBLE_WALL_ACTIVE ? EL_INVISIBLE_WALL :
4056 element == EL_INVISIBLE_SAND_ACTIVE ? EL_INVISIBLE_SAND :
4060 static void RedrawAllLightSwitchesAndInvisibleElements()
4065 SCAN_PLAYFIELD(x, y)
4067 for (y = 0; y < lev_fieldy; y++) for (x = 0; x < lev_fieldx; x++)
4070 int element = Feld[x][y];
4072 if (element == EL_LIGHT_SWITCH &&
4073 game.light_time_left > 0)
4075 Feld[x][y] = EL_LIGHT_SWITCH_ACTIVE;
4076 DrawLevelField(x, y);
4078 else if (element == EL_LIGHT_SWITCH_ACTIVE &&
4079 game.light_time_left == 0)
4081 Feld[x][y] = EL_LIGHT_SWITCH;
4082 DrawLevelField(x, y);
4084 else if (element == EL_EMC_DRIPPER &&
4085 game.light_time_left > 0)
4087 Feld[x][y] = EL_EMC_DRIPPER_ACTIVE;
4088 DrawLevelField(x, y);
4090 else if (element == EL_EMC_DRIPPER_ACTIVE &&
4091 game.light_time_left == 0)
4093 Feld[x][y] = EL_EMC_DRIPPER;
4094 DrawLevelField(x, y);
4096 else if (element == EL_INVISIBLE_STEELWALL ||
4097 element == EL_INVISIBLE_WALL ||
4098 element == EL_INVISIBLE_SAND)
4100 if (game.light_time_left > 0)
4101 Feld[x][y] = getInvisibleActiveFromInvisibleElement(element);
4103 DrawLevelField(x, y);
4105 /* uncrumble neighbour fields, if needed */
4106 if (element == EL_INVISIBLE_SAND)
4107 DrawLevelFieldCrumbledSandNeighbours(x, y);
4109 else if (element == EL_INVISIBLE_STEELWALL_ACTIVE ||
4110 element == EL_INVISIBLE_WALL_ACTIVE ||
4111 element == EL_INVISIBLE_SAND_ACTIVE)
4113 if (game.light_time_left == 0)
4114 Feld[x][y] = getInvisibleFromInvisibleActiveElement(element);
4116 DrawLevelField(x, y);
4118 /* re-crumble neighbour fields, if needed */
4119 if (element == EL_INVISIBLE_SAND)
4120 DrawLevelFieldCrumbledSandNeighbours(x, y);
4125 static void RedrawAllInvisibleElementsForLenses()
4130 SCAN_PLAYFIELD(x, y)
4132 for (y = 0; y < lev_fieldy; y++) for (x = 0; x < lev_fieldx; x++)
4135 int element = Feld[x][y];
4137 if (element == EL_EMC_DRIPPER &&
4138 game.lenses_time_left > 0)
4140 Feld[x][y] = EL_EMC_DRIPPER_ACTIVE;
4141 DrawLevelField(x, y);
4143 else if (element == EL_EMC_DRIPPER_ACTIVE &&
4144 game.lenses_time_left == 0)
4146 Feld[x][y] = EL_EMC_DRIPPER;
4147 DrawLevelField(x, y);
4149 else if (element == EL_INVISIBLE_STEELWALL ||
4150 element == EL_INVISIBLE_WALL ||
4151 element == EL_INVISIBLE_SAND)
4153 if (game.lenses_time_left > 0)
4154 Feld[x][y] = getInvisibleActiveFromInvisibleElement(element);
4156 DrawLevelField(x, y);
4158 /* uncrumble neighbour fields, if needed */
4159 if (element == EL_INVISIBLE_SAND)
4160 DrawLevelFieldCrumbledSandNeighbours(x, y);
4162 else if (element == EL_INVISIBLE_STEELWALL_ACTIVE ||
4163 element == EL_INVISIBLE_WALL_ACTIVE ||
4164 element == EL_INVISIBLE_SAND_ACTIVE)
4166 if (game.lenses_time_left == 0)
4167 Feld[x][y] = getInvisibleFromInvisibleActiveElement(element);
4169 DrawLevelField(x, y);
4171 /* re-crumble neighbour fields, if needed */
4172 if (element == EL_INVISIBLE_SAND)
4173 DrawLevelFieldCrumbledSandNeighbours(x, y);
4178 static void RedrawAllInvisibleElementsForMagnifier()
4183 SCAN_PLAYFIELD(x, y)
4185 for (y = 0; y < lev_fieldy; y++) for (x = 0; x < lev_fieldx; x++)
4188 int element = Feld[x][y];
4190 if (element == EL_EMC_FAKE_GRASS &&
4191 game.magnify_time_left > 0)
4193 Feld[x][y] = EL_EMC_FAKE_GRASS_ACTIVE;
4194 DrawLevelField(x, y);
4196 else if (element == EL_EMC_FAKE_GRASS_ACTIVE &&
4197 game.magnify_time_left == 0)
4199 Feld[x][y] = EL_EMC_FAKE_GRASS;
4200 DrawLevelField(x, y);
4202 else if (IS_GATE_GRAY(element) &&
4203 game.magnify_time_left > 0)
4205 Feld[x][y] = (IS_RND_GATE_GRAY(element) ?
4206 element - EL_GATE_1_GRAY + EL_GATE_1_GRAY_ACTIVE :
4207 IS_EM_GATE_GRAY(element) ?
4208 element - EL_EM_GATE_1_GRAY + EL_EM_GATE_1_GRAY_ACTIVE :
4209 IS_EMC_GATE_GRAY(element) ?
4210 element - EL_EMC_GATE_5_GRAY + EL_EMC_GATE_5_GRAY_ACTIVE :
4212 DrawLevelField(x, y);
4214 else if (IS_GATE_GRAY_ACTIVE(element) &&
4215 game.magnify_time_left == 0)
4217 Feld[x][y] = (IS_RND_GATE_GRAY_ACTIVE(element) ?
4218 element - EL_GATE_1_GRAY_ACTIVE + EL_GATE_1_GRAY :
4219 IS_EM_GATE_GRAY_ACTIVE(element) ?
4220 element - EL_EM_GATE_1_GRAY_ACTIVE + EL_EM_GATE_1_GRAY :
4221 IS_EMC_GATE_GRAY_ACTIVE(element) ?
4222 element - EL_EMC_GATE_5_GRAY_ACTIVE + EL_EMC_GATE_5_GRAY :
4224 DrawLevelField(x, y);
4229 static void ToggleLightSwitch(int x, int y)
4231 int element = Feld[x][y];
4233 game.light_time_left =
4234 (element == EL_LIGHT_SWITCH ?
4235 level.time_light * FRAMES_PER_SECOND : 0);
4237 RedrawAllLightSwitchesAndInvisibleElements();
4240 static void ActivateTimegateSwitch(int x, int y)
4244 game.timegate_time_left = level.time_timegate * FRAMES_PER_SECOND;
4247 SCAN_PLAYFIELD(xx, yy)
4249 for (yy = 0; yy < lev_fieldy; yy++) for (xx = 0; xx < lev_fieldx; xx++)
4252 int element = Feld[xx][yy];
4254 if (element == EL_TIMEGATE_CLOSED ||
4255 element == EL_TIMEGATE_CLOSING)
4257 Feld[xx][yy] = EL_TIMEGATE_OPENING;
4258 PlayLevelSound(xx, yy, SND_TIMEGATE_OPENING);
4262 else if (element == EL_TIMEGATE_SWITCH_ACTIVE)
4264 Feld[xx][yy] = EL_TIMEGATE_SWITCH;
4265 DrawLevelField(xx, yy);
4271 Feld[x][y] = EL_TIMEGATE_SWITCH_ACTIVE;
4274 void Impact(int x, int y)
4276 boolean last_line = (y == lev_fieldy - 1);
4277 boolean object_hit = FALSE;
4278 boolean impact = (last_line || object_hit);
4279 int element = Feld[x][y];
4280 int smashed = EL_STEELWALL;
4282 if (!last_line) /* check if element below was hit */
4284 if (Feld[x][y + 1] == EL_PLAYER_IS_LEAVING)
4287 object_hit = (!IS_FREE(x, y + 1) && (!IS_MOVING(x, y + 1) ||
4288 MovDir[x][y + 1] != MV_DOWN ||
4289 MovPos[x][y + 1] <= TILEY / 2));
4291 /* do not smash moving elements that left the smashed field in time */
4292 if (game.engine_version >= VERSION_IDENT(2,2,0,7) && IS_MOVING(x, y + 1) &&
4293 ABS(MovPos[x][y + 1] + getElementMoveStepsize(x, y + 1)) >= TILEX)
4296 #if USE_QUICKSAND_IMPACT_BUGFIX
4297 if (Feld[x][y + 1] == EL_QUICKSAND_EMPTYING && object_hit == FALSE)
4299 RemoveMovingField(x, y + 1);
4300 Feld[x][y + 1] = EL_QUICKSAND_EMPTY;
4301 Feld[x][y + 2] = EL_ROCK;
4302 DrawLevelField(x, y + 2);
4309 smashed = MovingOrBlocked2Element(x, y + 1);
4311 impact = (last_line || object_hit);
4314 if (!last_line && smashed == EL_ACID) /* element falls into acid */
4316 SplashAcid(x, y + 1);
4320 /* !!! not sufficient for all cases -- see EL_PEARL below !!! */
4321 /* only reset graphic animation if graphic really changes after impact */
4323 el_act_dir2img(element, GfxAction[x][y], MV_DOWN) != el2img(element))
4325 ResetGfxAnimation(x, y);
4326 DrawLevelField(x, y);
4329 if (impact && CAN_EXPLODE_IMPACT(element))
4334 else if (impact && element == EL_PEARL)
4336 ResetGfxAnimation(x, y);
4338 Feld[x][y] = EL_PEARL_BREAKING;
4339 PlayLevelSound(x, y, SND_PEARL_BREAKING);
4342 else if (impact && CheckElementChange(x, y, element, smashed, CE_IMPACT))
4344 PlayLevelSoundElementAction(x, y, element, ACTION_IMPACT);
4349 if (impact && element == EL_AMOEBA_DROP)
4351 if (object_hit && IS_PLAYER(x, y + 1))
4352 KillPlayerUnlessEnemyProtected(x, y + 1);
4353 else if (object_hit && smashed == EL_PENGUIN)
4357 Feld[x][y] = EL_AMOEBA_GROWING;
4358 Store[x][y] = EL_AMOEBA_WET;
4360 ResetRandomAnimationValue(x, y);
4365 if (object_hit) /* check which object was hit */
4367 if (CAN_PASS_MAGIC_WALL(element) &&
4368 (smashed == EL_MAGIC_WALL ||
4369 smashed == EL_BD_MAGIC_WALL))
4372 int activated_magic_wall =
4373 (smashed == EL_MAGIC_WALL ? EL_MAGIC_WALL_ACTIVE :
4374 EL_BD_MAGIC_WALL_ACTIVE);
4376 /* activate magic wall / mill */
4378 SCAN_PLAYFIELD(xx, yy)
4380 for (yy = 0; yy < lev_fieldy; yy++) for (xx = 0; xx < lev_fieldx; xx++)
4382 if (Feld[xx][yy] == smashed)
4383 Feld[xx][yy] = activated_magic_wall;
4385 game.magic_wall_time_left = level.time_magic_wall * FRAMES_PER_SECOND;
4386 game.magic_wall_active = TRUE;
4388 PlayLevelSound(x, y, (smashed == EL_MAGIC_WALL ?
4389 SND_MAGIC_WALL_ACTIVATING :
4390 SND_BD_MAGIC_WALL_ACTIVATING));
4393 if (IS_PLAYER(x, y + 1))
4395 if (CAN_SMASH_PLAYER(element))
4397 KillPlayerUnlessEnemyProtected(x, y + 1);
4401 else if (smashed == EL_PENGUIN)
4403 if (CAN_SMASH_PLAYER(element))
4409 else if (element == EL_BD_DIAMOND)
4411 if (IS_CLASSIC_ENEMY(smashed) && IS_BD_ELEMENT(smashed))
4417 else if (((element == EL_SP_INFOTRON ||
4418 element == EL_SP_ZONK) &&
4419 (smashed == EL_SP_SNIKSNAK ||
4420 smashed == EL_SP_ELECTRON ||
4421 smashed == EL_SP_DISK_ORANGE)) ||
4422 (element == EL_SP_INFOTRON &&
4423 smashed == EL_SP_DISK_YELLOW))
4428 else if (CAN_SMASH_EVERYTHING(element))
4430 if (IS_CLASSIC_ENEMY(smashed) ||
4431 CAN_EXPLODE_SMASHED(smashed))
4436 else if (!IS_MOVING(x, y + 1) && !IS_BLOCKED(x, y + 1))
4438 if (smashed == EL_LAMP ||
4439 smashed == EL_LAMP_ACTIVE)
4444 else if (smashed == EL_NUT)
4446 Feld[x][y + 1] = EL_NUT_BREAKING;
4447 PlayLevelSound(x, y, SND_NUT_BREAKING);
4448 RaiseScoreElement(EL_NUT);
4451 else if (smashed == EL_PEARL)
4453 ResetGfxAnimation(x, y);
4455 Feld[x][y + 1] = EL_PEARL_BREAKING;
4456 PlayLevelSound(x, y, SND_PEARL_BREAKING);
4459 else if (smashed == EL_DIAMOND)
4461 Feld[x][y + 1] = EL_DIAMOND_BREAKING;
4462 PlayLevelSound(x, y, SND_DIAMOND_BREAKING);
4465 else if (IS_BELT_SWITCH(smashed))
4467 ToggleBeltSwitch(x, y + 1);
4469 else if (smashed == EL_SWITCHGATE_SWITCH_UP ||
4470 smashed == EL_SWITCHGATE_SWITCH_DOWN)
4472 ToggleSwitchgateSwitch(x, y + 1);
4474 else if (smashed == EL_LIGHT_SWITCH ||
4475 smashed == EL_LIGHT_SWITCH_ACTIVE)
4477 ToggleLightSwitch(x, y + 1);
4482 TestIfElementSmashesCustomElement(x, y, MV_DOWN);
4485 CheckElementChange(x, y + 1, smashed, element, CE_SMASHED);
4487 CheckElementChangeBySide(x, y + 1, smashed, element,
4488 CE_SWITCHED, CH_SIDE_TOP);
4489 CheckTriggeredElementChangeBySide(x, y + 1, smashed, CE_SWITCH_OF_X,
4495 CheckElementChange(x, y + 1, smashed, element, CE_SMASHED);
4500 /* play sound of magic wall / mill */
4502 (Feld[x][y + 1] == EL_MAGIC_WALL_ACTIVE ||
4503 Feld[x][y + 1] == EL_BD_MAGIC_WALL_ACTIVE))
4505 if (Feld[x][y + 1] == EL_MAGIC_WALL_ACTIVE)
4506 PlayLevelSound(x, y, SND_MAGIC_WALL_FILLING);
4507 else if (Feld[x][y + 1] == EL_BD_MAGIC_WALL_ACTIVE)
4508 PlayLevelSound(x, y, SND_BD_MAGIC_WALL_FILLING);
4513 /* play sound of object that hits the ground */
4514 if (last_line || object_hit)
4515 PlayLevelSoundElementAction(x, y, element, ACTION_IMPACT);
4518 inline static void TurnRoundExt(int x, int y)
4530 { 0, 0 }, { 0, 0 }, { 0, 0 },
4535 int left, right, back;
4539 { MV_DOWN, MV_UP, MV_RIGHT },
4540 { MV_UP, MV_DOWN, MV_LEFT },
4542 { MV_LEFT, MV_RIGHT, MV_DOWN },
4546 { MV_RIGHT, MV_LEFT, MV_UP }
4549 int element = Feld[x][y];
4550 int move_pattern = element_info[element].move_pattern;
4552 int old_move_dir = MovDir[x][y];
4553 int left_dir = turn[old_move_dir].left;
4554 int right_dir = turn[old_move_dir].right;
4555 int back_dir = turn[old_move_dir].back;
4557 int left_dx = move_xy[left_dir].dx, left_dy = move_xy[left_dir].dy;
4558 int right_dx = move_xy[right_dir].dx, right_dy = move_xy[right_dir].dy;
4559 int move_dx = move_xy[old_move_dir].dx, move_dy = move_xy[old_move_dir].dy;
4560 int back_dx = move_xy[back_dir].dx, back_dy = move_xy[back_dir].dy;
4562 int left_x = x + left_dx, left_y = y + left_dy;
4563 int right_x = x + right_dx, right_y = y + right_dy;
4564 int move_x = x + move_dx, move_y = y + move_dy;
4568 if (element == EL_BUG || element == EL_BD_BUTTERFLY)
4570 TestIfBadThingTouchesOtherBadThing(x, y);
4572 if (ENEMY_CAN_ENTER_FIELD(element, right_x, right_y))
4573 MovDir[x][y] = right_dir;
4574 else if (!ENEMY_CAN_ENTER_FIELD(element, move_x, move_y))
4575 MovDir[x][y] = left_dir;
4577 if (element == EL_BUG && MovDir[x][y] != old_move_dir)
4579 else if (element == EL_BD_BUTTERFLY) /* && MovDir[x][y] == left_dir) */
4582 else if (element == EL_SPACESHIP || element == EL_BD_FIREFLY)
4584 TestIfBadThingTouchesOtherBadThing(x, y);
4586 if (ENEMY_CAN_ENTER_FIELD(element, left_x, left_y))
4587 MovDir[x][y] = left_dir;
4588 else if (!ENEMY_CAN_ENTER_FIELD(element, move_x, move_y))
4589 MovDir[x][y] = right_dir;
4591 if (element == EL_SPACESHIP && MovDir[x][y] != old_move_dir)
4593 else if (element == EL_BD_FIREFLY) /* && MovDir[x][y] == right_dir) */
4596 else if (element == EL_SP_SNIKSNAK || element == EL_SP_ELECTRON)
4598 TestIfBadThingTouchesOtherBadThing(x, y);
4600 if (ELEMENT_CAN_ENTER_FIELD_BASE_4(element, left_x, left_y, 0))
4601 MovDir[x][y] = left_dir;
4602 else if (!ELEMENT_CAN_ENTER_FIELD_BASE_4(element, move_x, move_y, 0))
4603 MovDir[x][y] = right_dir;
4605 if (MovDir[x][y] != old_move_dir)
4608 else if (element == EL_YAMYAM)
4610 boolean can_turn_left = YAMYAM_CAN_ENTER_FIELD(element, left_x, left_y);
4611 boolean can_turn_right = YAMYAM_CAN_ENTER_FIELD(element, right_x, right_y);
4613 if (can_turn_left && can_turn_right)
4614 MovDir[x][y] = (RND(3) ? (RND(2) ? left_dir : right_dir) : back_dir);
4615 else if (can_turn_left)
4616 MovDir[x][y] = (RND(2) ? left_dir : back_dir);
4617 else if (can_turn_right)
4618 MovDir[x][y] = (RND(2) ? right_dir : back_dir);
4620 MovDir[x][y] = back_dir;
4622 MovDelay[x][y] = 16 + 16 * RND(3);
4624 else if (element == EL_DARK_YAMYAM)
4626 boolean can_turn_left = DARK_YAMYAM_CAN_ENTER_FIELD(element,
4628 boolean can_turn_right = DARK_YAMYAM_CAN_ENTER_FIELD(element,
4631 if (can_turn_left && can_turn_right)
4632 MovDir[x][y] = (RND(3) ? (RND(2) ? left_dir : right_dir) : back_dir);
4633 else if (can_turn_left)
4634 MovDir[x][y] = (RND(2) ? left_dir : back_dir);
4635 else if (can_turn_right)
4636 MovDir[x][y] = (RND(2) ? right_dir : back_dir);
4638 MovDir[x][y] = back_dir;
4640 MovDelay[x][y] = 16 + 16 * RND(3);
4642 else if (element == EL_PACMAN)
4644 boolean can_turn_left = PACMAN_CAN_ENTER_FIELD(element, left_x, left_y);
4645 boolean can_turn_right = PACMAN_CAN_ENTER_FIELD(element, right_x, right_y);
4647 if (can_turn_left && can_turn_right)
4648 MovDir[x][y] = (RND(3) ? (RND(2) ? left_dir : right_dir) : back_dir);
4649 else if (can_turn_left)
4650 MovDir[x][y] = (RND(2) ? left_dir : back_dir);
4651 else if (can_turn_right)
4652 MovDir[x][y] = (RND(2) ? right_dir : back_dir);
4654 MovDir[x][y] = back_dir;
4656 MovDelay[x][y] = 6 + RND(40);
4658 else if (element == EL_PIG)
4660 boolean can_turn_left = PIG_CAN_ENTER_FIELD(element, left_x, left_y);
4661 boolean can_turn_right = PIG_CAN_ENTER_FIELD(element, right_x, right_y);
4662 boolean can_move_on = PIG_CAN_ENTER_FIELD(element, move_x, move_y);
4663 boolean should_turn_left, should_turn_right, should_move_on;
4665 int rnd = RND(rnd_value);
4667 should_turn_left = (can_turn_left &&
4669 IN_LEV_FIELD_AND_NOT_FREE(x + back_dx + left_dx,
4670 y + back_dy + left_dy)));
4671 should_turn_right = (can_turn_right &&
4673 IN_LEV_FIELD_AND_NOT_FREE(x + back_dx + right_dx,
4674 y + back_dy + right_dy)));
4675 should_move_on = (can_move_on &&
4678 IN_LEV_FIELD_AND_NOT_FREE(x + move_dx + left_dx,
4679 y + move_dy + left_dy) ||
4680 IN_LEV_FIELD_AND_NOT_FREE(x + move_dx + right_dx,
4681 y + move_dy + right_dy)));
4683 if (should_turn_left || should_turn_right || should_move_on)
4685 if (should_turn_left && should_turn_right && should_move_on)
4686 MovDir[x][y] = (rnd < rnd_value / 3 ? left_dir :
4687 rnd < 2 * rnd_value / 3 ? right_dir :
4689 else if (should_turn_left && should_turn_right)
4690 MovDir[x][y] = (rnd < rnd_value / 2 ? left_dir : right_dir);
4691 else if (should_turn_left && should_move_on)
4692 MovDir[x][y] = (rnd < rnd_value / 2 ? left_dir : old_move_dir);
4693 else if (should_turn_right && should_move_on)
4694 MovDir[x][y] = (rnd < rnd_value / 2 ? right_dir : old_move_dir);
4695 else if (should_turn_left)
4696 MovDir[x][y] = left_dir;
4697 else if (should_turn_right)
4698 MovDir[x][y] = right_dir;
4699 else if (should_move_on)
4700 MovDir[x][y] = old_move_dir;
4702 else if (can_move_on && rnd > rnd_value / 8)
4703 MovDir[x][y] = old_move_dir;
4704 else if (can_turn_left && can_turn_right)
4705 MovDir[x][y] = (rnd < rnd_value / 2 ? left_dir : right_dir);
4706 else if (can_turn_left && rnd > rnd_value / 8)
4707 MovDir[x][y] = left_dir;
4708 else if (can_turn_right && rnd > rnd_value/8)
4709 MovDir[x][y] = right_dir;
4711 MovDir[x][y] = back_dir;
4713 xx = x + move_xy[MovDir[x][y]].dx;
4714 yy = y + move_xy[MovDir[x][y]].dy;
4716 if (!IN_LEV_FIELD(xx, yy) ||
4717 (!IS_FREE(xx, yy) && !IS_FOOD_PIG(Feld[xx][yy])))
4718 MovDir[x][y] = old_move_dir;
4722 else if (element == EL_DRAGON)
4724 boolean can_turn_left = DRAGON_CAN_ENTER_FIELD(element, left_x, left_y);
4725 boolean can_turn_right = DRAGON_CAN_ENTER_FIELD(element, right_x, right_y);
4726 boolean can_move_on = DRAGON_CAN_ENTER_FIELD(element, move_x, move_y);
4728 int rnd = RND(rnd_value);
4730 if (can_move_on && rnd > rnd_value / 8)
4731 MovDir[x][y] = old_move_dir;
4732 else if (can_turn_left && can_turn_right)
4733 MovDir[x][y] = (rnd < rnd_value / 2 ? left_dir : right_dir);
4734 else if (can_turn_left && rnd > rnd_value / 8)
4735 MovDir[x][y] = left_dir;
4736 else if (can_turn_right && rnd > rnd_value / 8)
4737 MovDir[x][y] = right_dir;
4739 MovDir[x][y] = back_dir;
4741 xx = x + move_xy[MovDir[x][y]].dx;
4742 yy = y + move_xy[MovDir[x][y]].dy;
4744 if (!IN_LEV_FIELD_AND_IS_FREE(xx, yy))
4745 MovDir[x][y] = old_move_dir;
4749 else if (element == EL_MOLE)
4751 boolean can_move_on =
4752 (MOLE_CAN_ENTER_FIELD(element, move_x, move_y,
4753 IS_AMOEBOID(Feld[move_x][move_y]) ||
4754 Feld[move_x][move_y] == EL_AMOEBA_SHRINKING));
4757 boolean can_turn_left =
4758 (MOLE_CAN_ENTER_FIELD(element, left_x, left_y,
4759 IS_AMOEBOID(Feld[left_x][left_y])));
4761 boolean can_turn_right =
4762 (MOLE_CAN_ENTER_FIELD(element, right_x, right_y,
4763 IS_AMOEBOID(Feld[right_x][right_y])));
4765 if (can_turn_left && can_turn_right)
4766 MovDir[x][y] = (RND(2) ? left_dir : right_dir);
4767 else if (can_turn_left)
4768 MovDir[x][y] = left_dir;
4770 MovDir[x][y] = right_dir;
4773 if (MovDir[x][y] != old_move_dir)
4776 else if (element == EL_BALLOON)
4778 MovDir[x][y] = game.wind_direction;
4781 else if (element == EL_SPRING)
4783 #if USE_NEW_SPRING_BUMPER
4784 if (MovDir[x][y] & MV_HORIZONTAL)
4786 if (SPRING_CAN_BUMP_FROM_FIELD(move_x, move_y) &&
4787 !SPRING_CAN_ENTER_FIELD(element, x, y + 1))
4789 Feld[move_x][move_y] = EL_EMC_SPRING_BUMPER_ACTIVE;
4790 ResetGfxAnimation(move_x, move_y);
4791 DrawLevelField(move_x, move_y);
4793 MovDir[x][y] = back_dir;
4795 else if (!SPRING_CAN_ENTER_FIELD(element, move_x, move_y) ||
4796 SPRING_CAN_ENTER_FIELD(element, x, y + 1))
4797 MovDir[x][y] = MV_NONE;
4800 if (MovDir[x][y] & MV_HORIZONTAL &&
4801 (!SPRING_CAN_ENTER_FIELD(element, move_x, move_y) ||
4802 SPRING_CAN_ENTER_FIELD(element, x, y + 1)))
4803 MovDir[x][y] = MV_NONE;
4808 else if (element == EL_ROBOT ||
4809 element == EL_SATELLITE ||
4810 element == EL_PENGUIN ||
4811 element == EL_EMC_ANDROID)
4813 int attr_x = -1, attr_y = -1;
4824 for (i = 0; i < MAX_PLAYERS; i++)
4826 struct PlayerInfo *player = &stored_player[i];
4827 int jx = player->jx, jy = player->jy;
4829 if (!player->active)
4833 ABS(jx - x) + ABS(jy - y) < ABS(attr_x - x) + ABS(attr_y - y))
4841 if (element == EL_ROBOT && ZX >= 0 && ZY >= 0 &&
4842 (Feld[ZX][ZY] == EL_ROBOT_WHEEL_ACTIVE ||
4843 game.engine_version < VERSION_IDENT(3,1,0,0)))
4849 if (element == EL_PENGUIN)
4852 static int xy[4][2] =
4860 for (i = 0; i < NUM_DIRECTIONS; i++)
4862 int ex = x + xy[i][0];
4863 int ey = y + xy[i][1];
4865 if (IN_LEV_FIELD(ex, ey) && Feld[ex][ey] == EL_EXIT_OPEN)
4874 MovDir[x][y] = MV_NONE;
4876 MovDir[x][y] |= (AllPlayersGone ? MV_RIGHT : MV_LEFT);
4877 else if (attr_x > x)
4878 MovDir[x][y] |= (AllPlayersGone ? MV_LEFT : MV_RIGHT);
4880 MovDir[x][y] |= (AllPlayersGone ? MV_DOWN : MV_UP);
4881 else if (attr_y > y)
4882 MovDir[x][y] |= (AllPlayersGone ? MV_UP : MV_DOWN);
4884 if (element == EL_ROBOT)
4888 if (MovDir[x][y] & MV_HORIZONTAL && MovDir[x][y] & MV_VERTICAL)
4889 MovDir[x][y] &= (RND(2) ? MV_HORIZONTAL : MV_VERTICAL);
4890 Moving2Blocked(x, y, &newx, &newy);
4892 if (IN_LEV_FIELD(newx, newy) && IS_FREE_OR_PLAYER(newx, newy))
4893 MovDelay[x][y] = 8 + 8 * !RND(3);
4895 MovDelay[x][y] = 16;
4897 else if (element == EL_PENGUIN)
4903 if (MovDir[x][y] & MV_HORIZONTAL && MovDir[x][y] & MV_VERTICAL)
4905 boolean first_horiz = RND(2);
4906 int new_move_dir = MovDir[x][y];
4909 new_move_dir & (first_horiz ? MV_HORIZONTAL : MV_VERTICAL);
4910 Moving2Blocked(x, y, &newx, &newy);
4912 if (PENGUIN_CAN_ENTER_FIELD(element, newx, newy))
4916 new_move_dir & (!first_horiz ? MV_HORIZONTAL : MV_VERTICAL);
4917 Moving2Blocked(x, y, &newx, &newy);
4919 if (PENGUIN_CAN_ENTER_FIELD(element, newx, newy))
4922 MovDir[x][y] = old_move_dir;
4926 else if (element == EL_SATELLITE)
4932 if (MovDir[x][y] & MV_HORIZONTAL && MovDir[x][y] & MV_VERTICAL)
4934 boolean first_horiz = RND(2);
4935 int new_move_dir = MovDir[x][y];
4938 new_move_dir & (first_horiz ? MV_HORIZONTAL : MV_VERTICAL);
4939 Moving2Blocked(x, y, &newx, &newy);
4941 if (SATELLITE_CAN_ENTER_FIELD(newx, newy))
4945 new_move_dir & (!first_horiz ? MV_HORIZONTAL : MV_VERTICAL);
4946 Moving2Blocked(x, y, &newx, &newy);
4948 if (SATELLITE_CAN_ENTER_FIELD(newx, newy))
4951 MovDir[x][y] = old_move_dir;
4955 else if (element == EL_EMC_ANDROID)
4957 static int check_pos[16] =
4959 -1, /* 0 => (invalid) */
4960 7, /* 1 => MV_LEFT */
4961 3, /* 2 => MV_RIGHT */
4962 -1, /* 3 => (invalid) */
4964 0, /* 5 => MV_LEFT | MV_UP */
4965 2, /* 6 => MV_RIGHT | MV_UP */
4966 -1, /* 7 => (invalid) */
4967 5, /* 8 => MV_DOWN */
4968 6, /* 9 => MV_LEFT | MV_DOWN */
4969 4, /* 10 => MV_RIGHT | MV_DOWN */
4970 -1, /* 11 => (invalid) */
4971 -1, /* 12 => (invalid) */
4972 -1, /* 13 => (invalid) */
4973 -1, /* 14 => (invalid) */
4974 -1, /* 15 => (invalid) */
4982 { -1, -1, MV_LEFT | MV_UP },
4984 { +1, -1, MV_RIGHT | MV_UP },
4985 { +1, 0, MV_RIGHT },
4986 { +1, +1, MV_RIGHT | MV_DOWN },
4988 { -1, +1, MV_LEFT | MV_DOWN },
4991 int start_pos, check_order;
4992 boolean can_clone = FALSE;
4995 /* check if there is any free field around current position */
4996 for (i = 0; i < 8; i++)
4998 int newx = x + check_xy[i].dx;
4999 int newy = y + check_xy[i].dy;
5001 if (IN_LEV_FIELD_AND_IS_FREE(newx, newy))
5009 if (can_clone) /* randomly find an element to clone */
5013 start_pos = check_pos[RND(8)];
5014 check_order = (RND(2) ? -1 : +1);
5016 for (i = 0; i < 8; i++)
5018 int pos_raw = start_pos + i * check_order;
5019 int pos = (pos_raw + 8) % 8;
5020 int newx = x + check_xy[pos].dx;
5021 int newy = y + check_xy[pos].dy;
5023 if (ANDROID_CAN_CLONE_FIELD(newx, newy))
5025 element_info[element].move_leave_type = LEAVE_TYPE_LIMITED;
5026 element_info[element].move_leave_element = EL_TRIGGER_ELEMENT;
5028 Store[x][y] = Feld[newx][newy];
5037 if (can_clone) /* randomly find a direction to move */
5041 start_pos = check_pos[RND(8)];
5042 check_order = (RND(2) ? -1 : +1);
5044 for (i = 0; i < 8; i++)
5046 int pos_raw = start_pos + i * check_order;
5047 int pos = (pos_raw + 8) % 8;
5048 int newx = x + check_xy[pos].dx;
5049 int newy = y + check_xy[pos].dy;
5050 int new_move_dir = check_xy[pos].dir;
5052 if (IN_LEV_FIELD_AND_IS_FREE(newx, newy))
5054 MovDir[x][y] = new_move_dir;
5055 MovDelay[x][y] = level.android_clone_time * 8 + 1;
5064 if (can_clone) /* cloning and moving successful */
5067 /* cannot clone -- try to move towards player */
5069 start_pos = check_pos[MovDir[x][y] & 0x0f];
5070 check_order = (RND(2) ? -1 : +1);
5072 for (i = 0; i < 3; i++)
5074 /* first check start_pos, then previous/next or (next/previous) pos */
5075 int pos_raw = start_pos + (i < 2 ? i : -1) * check_order;
5076 int pos = (pos_raw + 8) % 8;
5077 int newx = x + check_xy[pos].dx;
5078 int newy = y + check_xy[pos].dy;
5079 int new_move_dir = check_xy[pos].dir;
5081 if (IS_PLAYER(newx, newy))
5084 if (ANDROID_CAN_ENTER_FIELD(element, newx, newy))
5086 MovDir[x][y] = new_move_dir;
5087 MovDelay[x][y] = level.android_move_time * 8 + 1;
5094 else if (move_pattern == MV_TURNING_LEFT ||
5095 move_pattern == MV_TURNING_RIGHT ||
5096 move_pattern == MV_TURNING_LEFT_RIGHT ||
5097 move_pattern == MV_TURNING_RIGHT_LEFT ||
5098 move_pattern == MV_TURNING_RANDOM ||
5099 move_pattern == MV_ALL_DIRECTIONS)
5101 boolean can_turn_left =
5102 CUSTOM_ELEMENT_CAN_ENTER_FIELD(element, left_x, left_y);
5103 boolean can_turn_right =
5104 CUSTOM_ELEMENT_CAN_ENTER_FIELD(element, right_x,right_y);
5106 if (element_info[element].move_stepsize == 0) /* "not moving" */
5109 if (move_pattern == MV_TURNING_LEFT)
5110 MovDir[x][y] = left_dir;
5111 else if (move_pattern == MV_TURNING_RIGHT)
5112 MovDir[x][y] = right_dir;
5113 else if (move_pattern == MV_TURNING_LEFT_RIGHT)
5114 MovDir[x][y] = (can_turn_left || !can_turn_right ? left_dir : right_dir);
5115 else if (move_pattern == MV_TURNING_RIGHT_LEFT)
5116 MovDir[x][y] = (can_turn_right || !can_turn_left ? right_dir : left_dir);
5117 else if (move_pattern == MV_TURNING_RANDOM)
5118 MovDir[x][y] = (can_turn_left && !can_turn_right ? left_dir :
5119 can_turn_right && !can_turn_left ? right_dir :
5120 RND(2) ? left_dir : right_dir);
5121 else if (can_turn_left && can_turn_right)
5122 MovDir[x][y] = (RND(3) ? (RND(2) ? left_dir : right_dir) : back_dir);
5123 else if (can_turn_left)
5124 MovDir[x][y] = (RND(2) ? left_dir : back_dir);
5125 else if (can_turn_right)
5126 MovDir[x][y] = (RND(2) ? right_dir : back_dir);
5128 MovDir[x][y] = back_dir;
5130 MovDelay[x][y] = GET_NEW_MOVE_DELAY(element);
5132 else if (move_pattern == MV_HORIZONTAL ||
5133 move_pattern == MV_VERTICAL)
5135 if (move_pattern & old_move_dir)
5136 MovDir[x][y] = back_dir;
5137 else if (move_pattern == MV_HORIZONTAL)
5138 MovDir[x][y] = (RND(2) ? MV_LEFT : MV_RIGHT);
5139 else if (move_pattern == MV_VERTICAL)
5140 MovDir[x][y] = (RND(2) ? MV_UP : MV_DOWN);
5142 MovDelay[x][y] = GET_NEW_MOVE_DELAY(element);
5144 else if (move_pattern & MV_ANY_DIRECTION)
5146 MovDir[x][y] = move_pattern;
5147 MovDelay[x][y] = GET_NEW_MOVE_DELAY(element);
5149 else if (move_pattern & MV_WIND_DIRECTION)
5151 MovDir[x][y] = game.wind_direction;
5152 MovDelay[x][y] = GET_NEW_MOVE_DELAY(element);
5154 else if (move_pattern == MV_ALONG_LEFT_SIDE)
5156 if (CUSTOM_ELEMENT_CAN_ENTER_FIELD(element, left_x, left_y))
5157 MovDir[x][y] = left_dir;
5158 else if (!CUSTOM_ELEMENT_CAN_ENTER_FIELD(element, move_x, move_y))
5159 MovDir[x][y] = right_dir;
5161 if (MovDir[x][y] != old_move_dir)
5162 MovDelay[x][y] = GET_NEW_MOVE_DELAY(element);
5164 else if (move_pattern == MV_ALONG_RIGHT_SIDE)
5166 if (CUSTOM_ELEMENT_CAN_ENTER_FIELD(element, right_x, right_y))
5167 MovDir[x][y] = right_dir;
5168 else if (!CUSTOM_ELEMENT_CAN_ENTER_FIELD(element, move_x, move_y))
5169 MovDir[x][y] = left_dir;
5171 if (MovDir[x][y] != old_move_dir)
5172 MovDelay[x][y] = GET_NEW_MOVE_DELAY(element);
5174 else if (move_pattern == MV_TOWARDS_PLAYER ||
5175 move_pattern == MV_AWAY_FROM_PLAYER)
5177 int attr_x = -1, attr_y = -1;
5179 boolean move_away = (move_pattern == MV_AWAY_FROM_PLAYER);
5190 for (i = 0; i < MAX_PLAYERS; i++)
5192 struct PlayerInfo *player = &stored_player[i];
5193 int jx = player->jx, jy = player->jy;
5195 if (!player->active)
5199 ABS(jx - x) + ABS(jy - y) < ABS(attr_x - x) + ABS(attr_y - y))
5207 MovDir[x][y] = MV_NONE;
5209 MovDir[x][y] |= (move_away ? MV_RIGHT : MV_LEFT);
5210 else if (attr_x > x)
5211 MovDir[x][y] |= (move_away ? MV_LEFT : MV_RIGHT);
5213 MovDir[x][y] |= (move_away ? MV_DOWN : MV_UP);
5214 else if (attr_y > y)
5215 MovDir[x][y] |= (move_away ? MV_UP : MV_DOWN);
5217 MovDelay[x][y] = GET_NEW_MOVE_DELAY(element);
5219 if (MovDir[x][y] & MV_HORIZONTAL && MovDir[x][y] & MV_VERTICAL)
5221 boolean first_horiz = RND(2);
5222 int new_move_dir = MovDir[x][y];
5224 if (element_info[element].move_stepsize == 0) /* "not moving" */
5226 first_horiz = (ABS(attr_x - x) >= ABS(attr_y - y));
5227 MovDir[x][y] &= (first_horiz ? MV_HORIZONTAL : MV_VERTICAL);
5233 new_move_dir & (first_horiz ? MV_HORIZONTAL : MV_VERTICAL);
5234 Moving2Blocked(x, y, &newx, &newy);
5236 if (CUSTOM_ELEMENT_CAN_ENTER_FIELD(element, newx, newy))
5240 new_move_dir & (!first_horiz ? MV_HORIZONTAL : MV_VERTICAL);
5241 Moving2Blocked(x, y, &newx, &newy);
5243 if (CUSTOM_ELEMENT_CAN_ENTER_FIELD(element, newx, newy))
5246 MovDir[x][y] = old_move_dir;
5249 else if (move_pattern == MV_WHEN_PUSHED ||
5250 move_pattern == MV_WHEN_DROPPED)
5252 if (!CUSTOM_ELEMENT_CAN_ENTER_FIELD(element, move_x, move_y))
5253 MovDir[x][y] = MV_NONE;
5257 else if (move_pattern & MV_MAZE_RUNNER_STYLE)
5259 static int test_xy[7][2] =
5269 static int test_dir[7] =
5279 boolean hunter_mode = (move_pattern == MV_MAZE_HUNTER);
5280 int move_preference = -1000000; /* start with very low preference */
5281 int new_move_dir = MV_NONE;
5282 int start_test = RND(4);
5285 for (i = 0; i < NUM_DIRECTIONS; i++)
5287 int move_dir = test_dir[start_test + i];
5288 int move_dir_preference;
5290 xx = x + test_xy[start_test + i][0];
5291 yy = y + test_xy[start_test + i][1];
5293 if (hunter_mode && IN_LEV_FIELD(xx, yy) &&
5294 (IS_PLAYER(xx, yy) || Feld[xx][yy] == EL_PLAYER_IS_LEAVING))
5296 new_move_dir = move_dir;
5301 if (!CUSTOM_ELEMENT_CAN_ENTER_FIELD(element, xx, yy))
5304 move_dir_preference = -1 * RunnerVisit[xx][yy];
5305 if (hunter_mode && PlayerVisit[xx][yy] > 0)
5306 move_dir_preference = PlayerVisit[xx][yy];
5308 if (move_dir_preference > move_preference)
5310 /* prefer field that has not been visited for the longest time */
5311 move_preference = move_dir_preference;
5312 new_move_dir = move_dir;
5314 else if (move_dir_preference == move_preference &&
5315 move_dir == old_move_dir)
5317 /* prefer last direction when all directions are preferred equally */
5318 move_preference = move_dir_preference;
5319 new_move_dir = move_dir;
5323 MovDir[x][y] = new_move_dir;
5324 if (old_move_dir != new_move_dir)
5325 MovDelay[x][y] = GET_NEW_MOVE_DELAY(element);
5329 static void TurnRound(int x, int y)
5331 int direction = MovDir[x][y];
5333 int element, graphic;
5338 GfxDir[x][y] = MovDir[x][y];
5340 if (direction != MovDir[x][y])
5344 GfxAction[x][y] = ACTION_TURNING_FROM_LEFT + MV_DIR_TO_BIT(direction);
5347 element = Feld[x][y];
5348 graphic = el_act_dir2img(element, GfxAction[x][y], GfxDir[x][y]);
5350 if (graphic_info[graphic].anim_global_sync)
5351 GfxFrame[x][y] = FrameCounter;
5352 else if (ANIM_MODE(graphic) == ANIM_CE_VALUE)
5353 GfxFrame[x][y] = CustomValue[x][y];
5354 else if (ANIM_MODE(graphic) == ANIM_CE_SCORE)
5355 GfxFrame[x][y] = element_info[element].collect_score;
5359 static boolean JustBeingPushed(int x, int y)
5363 for (i = 0; i < MAX_PLAYERS; i++)
5365 struct PlayerInfo *player = &stored_player[i];
5367 if (player->active && player->is_pushing && player->MovPos)
5369 int next_jx = player->jx + (player->jx - player->last_jx);
5370 int next_jy = player->jy + (player->jy - player->last_jy);
5372 if (x == next_jx && y == next_jy)
5380 void StartMoving(int x, int y)
5382 boolean started_moving = FALSE; /* some elements can fall _and_ move */
5383 int element = Feld[x][y];
5388 if (MovDelay[x][y] == 0)
5389 GfxAction[x][y] = ACTION_DEFAULT;
5391 if (CAN_FALL(element) && y < lev_fieldy - 1)
5393 if ((x > 0 && IS_PLAYER(x - 1, y)) ||
5394 (x < lev_fieldx - 1 && IS_PLAYER(x + 1, y)))
5395 if (JustBeingPushed(x, y))
5398 if (element == EL_QUICKSAND_FULL)
5400 if (IS_FREE(x, y + 1))
5402 InitMovingField(x, y, MV_DOWN);
5403 started_moving = TRUE;
5405 Feld[x][y] = EL_QUICKSAND_EMPTYING;
5406 Store[x][y] = EL_ROCK;
5408 PlayLevelSoundAction(x, y, ACTION_EMPTYING);
5410 else if (Feld[x][y + 1] == EL_QUICKSAND_EMPTY)
5412 if (!MovDelay[x][y])
5413 MovDelay[x][y] = TILEY + 1;
5422 Feld[x][y] = EL_QUICKSAND_EMPTY;
5423 Feld[x][y + 1] = EL_QUICKSAND_FULL;
5424 Store[x][y + 1] = Store[x][y];
5427 PlayLevelSoundAction(x, y, ACTION_FILLING);
5430 else if ((element == EL_ROCK || element == EL_BD_ROCK) &&
5431 Feld[x][y + 1] == EL_QUICKSAND_EMPTY)
5433 InitMovingField(x, y, MV_DOWN);
5434 started_moving = TRUE;
5436 Feld[x][y] = EL_QUICKSAND_FILLING;
5437 Store[x][y] = element;
5439 PlayLevelSoundAction(x, y, ACTION_FILLING);
5441 else if (element == EL_MAGIC_WALL_FULL)
5443 if (IS_FREE(x, y + 1))
5445 InitMovingField(x, y, MV_DOWN);
5446 started_moving = TRUE;
5448 Feld[x][y] = EL_MAGIC_WALL_EMPTYING;
5449 Store[x][y] = EL_CHANGED(Store[x][y]);
5451 else if (Feld[x][y + 1] == EL_MAGIC_WALL_ACTIVE)
5453 if (!MovDelay[x][y])
5454 MovDelay[x][y] = TILEY/4 + 1;
5463 Feld[x][y] = EL_MAGIC_WALL_ACTIVE;
5464 Feld[x][y + 1] = EL_MAGIC_WALL_FULL;
5465 Store[x][y + 1] = EL_CHANGED(Store[x][y]);
5469 else if (element == EL_BD_MAGIC_WALL_FULL)
5471 if (IS_FREE(x, y + 1))
5473 InitMovingField(x, y, MV_DOWN);
5474 started_moving = TRUE;
5476 Feld[x][y] = EL_BD_MAGIC_WALL_EMPTYING;
5477 Store[x][y] = EL_CHANGED2(Store[x][y]);
5479 else if (Feld[x][y + 1] == EL_BD_MAGIC_WALL_ACTIVE)
5481 if (!MovDelay[x][y])
5482 MovDelay[x][y] = TILEY/4 + 1;
5491 Feld[x][y] = EL_BD_MAGIC_WALL_ACTIVE;
5492 Feld[x][y + 1] = EL_BD_MAGIC_WALL_FULL;
5493 Store[x][y + 1] = EL_CHANGED2(Store[x][y]);
5497 else if (CAN_PASS_MAGIC_WALL(element) &&
5498 (Feld[x][y + 1] == EL_MAGIC_WALL_ACTIVE ||
5499 Feld[x][y + 1] == EL_BD_MAGIC_WALL_ACTIVE))
5501 InitMovingField(x, y, MV_DOWN);
5502 started_moving = TRUE;
5505 (Feld[x][y + 1] == EL_MAGIC_WALL_ACTIVE ? EL_MAGIC_WALL_FILLING :
5506 EL_BD_MAGIC_WALL_FILLING);
5507 Store[x][y] = element;
5509 else if (CAN_FALL(element) && Feld[x][y + 1] == EL_ACID)
5511 SplashAcid(x, y + 1);
5513 InitMovingField(x, y, MV_DOWN);
5514 started_moving = TRUE;
5516 Store[x][y] = EL_ACID;
5518 else if ((game.engine_version >= VERSION_IDENT(3,1,0,0) &&
5519 CheckCollision[x][y] && !IS_FREE(x, y + 1)) ||
5521 (game.engine_version >= VERSION_IDENT(3,0,7,0) &&
5522 CAN_FALL(element) && WasJustFalling[x][y] &&
5523 (Feld[x][y + 1] == EL_BLOCKED || IS_PLAYER(x, y + 1))) ||
5525 (game.engine_version < VERSION_IDENT(2,2,0,7) &&
5526 CAN_FALL(element) && WasJustMoving[x][y] && !Pushed[x][y + 1] &&
5527 (Feld[x][y + 1] == EL_BLOCKED)))
5529 /* this is needed for a special case not covered by calling "Impact()"
5530 from "ContinueMoving()": if an element moves to a tile directly below
5531 another element which was just falling on that tile (which was empty
5532 in the previous frame), the falling element above would just stop
5533 instead of smashing the element below (in previous version, the above
5534 element was just checked for "moving" instead of "falling", resulting
5535 in incorrect smashes caused by horizontal movement of the above
5536 element; also, the case of the player being the element to smash was
5537 simply not covered here... :-/ ) */
5539 CheckCollision[x][y] = 0;
5543 else if (IS_FREE(x, y + 1) && element == EL_SPRING && level.use_spring_bug)
5545 if (MovDir[x][y] == MV_NONE)
5547 InitMovingField(x, y, MV_DOWN);
5548 started_moving = TRUE;
5551 else if (IS_FREE(x, y + 1) || Feld[x][y + 1] == EL_DIAMOND_BREAKING)
5553 if (WasJustFalling[x][y]) /* prevent animation from being restarted */
5554 MovDir[x][y] = MV_DOWN;
5556 InitMovingField(x, y, MV_DOWN);
5557 started_moving = TRUE;
5559 else if (element == EL_AMOEBA_DROP)
5561 Feld[x][y] = EL_AMOEBA_GROWING;
5562 Store[x][y] = EL_AMOEBA_WET;
5564 else if (((IS_SLIPPERY(Feld[x][y + 1]) && !IS_PLAYER(x, y + 1)) ||
5565 (IS_EM_SLIPPERY_WALL(Feld[x][y + 1]) && IS_GEM(element))) &&
5566 !IS_FALLING(x, y + 1) && !WasJustMoving[x][y + 1] &&
5567 element != EL_DX_SUPABOMB && element != EL_SP_DISK_ORANGE)
5569 boolean can_fall_left = (x > 0 && IS_FREE(x - 1, y) &&
5570 (IS_FREE(x - 1, y + 1) ||
5571 Feld[x - 1][y + 1] == EL_ACID));
5572 boolean can_fall_right = (x < lev_fieldx - 1 && IS_FREE(x + 1, y) &&
5573 (IS_FREE(x + 1, y + 1) ||
5574 Feld[x + 1][y + 1] == EL_ACID));
5575 boolean can_fall_any = (can_fall_left || can_fall_right);
5576 boolean can_fall_both = (can_fall_left && can_fall_right);
5577 int slippery_type = element_info[Feld[x][y + 1]].slippery_type;
5579 #if USE_NEW_ALL_SLIPPERY
5580 if (can_fall_any && slippery_type != SLIPPERY_ANY_RANDOM)
5582 if (slippery_type == SLIPPERY_ANY_LEFT_RIGHT && can_fall_both)
5583 can_fall_right = FALSE;
5584 else if (slippery_type == SLIPPERY_ANY_RIGHT_LEFT && can_fall_both)
5585 can_fall_left = FALSE;
5586 else if (slippery_type == SLIPPERY_ONLY_LEFT)
5587 can_fall_right = FALSE;
5588 else if (slippery_type == SLIPPERY_ONLY_RIGHT)
5589 can_fall_left = FALSE;
5591 can_fall_any = (can_fall_left || can_fall_right);
5592 can_fall_both = FALSE;
5595 if (can_fall_any && IS_CUSTOM_ELEMENT(Feld[x][y + 1]))
5597 if (slippery_type == SLIPPERY_ONLY_LEFT)
5598 can_fall_right = FALSE;
5599 else if (slippery_type == SLIPPERY_ONLY_RIGHT)
5600 can_fall_left = FALSE;
5601 else if (slippery_type == SLIPPERY_ANY_LEFT_RIGHT && can_fall_both)
5602 can_fall_right = FALSE;
5603 else if (slippery_type == SLIPPERY_ANY_RIGHT_LEFT && can_fall_both)
5604 can_fall_left = FALSE;
5606 can_fall_any = (can_fall_left || can_fall_right);
5607 can_fall_both = (can_fall_left && can_fall_right);
5611 #if USE_NEW_ALL_SLIPPERY
5613 #if USE_NEW_SP_SLIPPERY
5614 /* !!! better use the same properties as for custom elements here !!! */
5615 else if (game.engine_version >= VERSION_IDENT(3,1,1,0) &&
5616 can_fall_both && IS_SP_ELEMENT(Feld[x][y + 1]))
5618 can_fall_right = FALSE; /* slip down on left side */
5619 can_fall_both = FALSE;
5624 #if USE_NEW_ALL_SLIPPERY
5627 if (element == EL_BD_ROCK || element == EL_BD_DIAMOND)
5628 can_fall_right = FALSE; /* slip down on left side */
5630 can_fall_left = !(can_fall_right = RND(2));
5632 can_fall_both = FALSE;
5637 if (game.emulation == EMU_BOULDERDASH ||
5638 element == EL_BD_ROCK || element == EL_BD_DIAMOND)
5639 can_fall_right = FALSE; /* slip down on left side */
5641 can_fall_left = !(can_fall_right = RND(2));
5643 can_fall_both = FALSE;
5649 /* if not determined otherwise, prefer left side for slipping down */
5650 InitMovingField(x, y, can_fall_left ? MV_LEFT : MV_RIGHT);
5651 started_moving = TRUE;
5655 else if (IS_BELT_ACTIVE(Feld[x][y + 1]) && !CAN_MOVE(element))
5657 else if (IS_BELT_ACTIVE(Feld[x][y + 1]))
5660 boolean left_is_free = (x > 0 && IS_FREE(x - 1, y));
5661 boolean right_is_free = (x < lev_fieldx - 1 && IS_FREE(x + 1, y));
5662 int belt_nr = getBeltNrFromBeltActiveElement(Feld[x][y + 1]);
5663 int belt_dir = game.belt_dir[belt_nr];
5665 if ((belt_dir == MV_LEFT && left_is_free) ||
5666 (belt_dir == MV_RIGHT && right_is_free))
5668 int nextx = (belt_dir == MV_LEFT ? x - 1 : x + 1);
5670 InitMovingField(x, y, belt_dir);
5671 started_moving = TRUE;
5673 Pushed[x][y] = TRUE;
5674 Pushed[nextx][y] = TRUE;
5676 GfxAction[x][y] = ACTION_DEFAULT;
5680 MovDir[x][y] = 0; /* if element was moving, stop it */
5685 /* not "else if" because of elements that can fall and move (EL_SPRING) */
5687 if (CAN_MOVE(element) && !started_moving && MovDir[x][y] != MV_NONE)
5689 if (CAN_MOVE(element) && !started_moving)
5692 int move_pattern = element_info[element].move_pattern;
5697 if (MovDir[x][y] == MV_NONE)
5699 printf("StartMoving(): %d,%d: element %d ['%s'] not moving\n",
5700 x, y, element, element_info[element].token_name);
5701 printf("StartMoving(): This should never happen!\n");
5706 Moving2Blocked(x, y, &newx, &newy);
5708 if (IS_PUSHABLE(element) && JustBeingPushed(x, y))
5711 if (game.engine_version >= VERSION_IDENT(3,1,0,0) &&
5712 CheckCollision[x][y] && !IN_LEV_FIELD_AND_IS_FREE(newx, newy))
5714 WasJustMoving[x][y] = 0;
5715 CheckCollision[x][y] = 0;
5717 TestIfElementHitsCustomElement(x, y, MovDir[x][y]);
5719 if (Feld[x][y] != element) /* element has changed */
5723 if (!MovDelay[x][y]) /* start new movement phase */
5725 /* all objects that can change their move direction after each step
5726 (YAMYAM, DARK_YAMYAM and PACMAN go straight until they hit a wall */
5728 if (element != EL_YAMYAM &&
5729 element != EL_DARK_YAMYAM &&
5730 element != EL_PACMAN &&
5731 !(move_pattern & MV_ANY_DIRECTION) &&
5732 move_pattern != MV_TURNING_LEFT &&
5733 move_pattern != MV_TURNING_RIGHT &&
5734 move_pattern != MV_TURNING_LEFT_RIGHT &&
5735 move_pattern != MV_TURNING_RIGHT_LEFT &&
5736 move_pattern != MV_TURNING_RANDOM)
5740 if (MovDelay[x][y] && (element == EL_BUG ||
5741 element == EL_SPACESHIP ||
5742 element == EL_SP_SNIKSNAK ||
5743 element == EL_SP_ELECTRON ||
5744 element == EL_MOLE))
5745 DrawLevelField(x, y);
5749 if (MovDelay[x][y]) /* wait some time before next movement */
5753 if (element == EL_ROBOT ||
5754 element == EL_YAMYAM ||
5755 element == EL_DARK_YAMYAM)
5757 DrawLevelElementAnimationIfNeeded(x, y, element);
5758 PlayLevelSoundAction(x, y, ACTION_WAITING);
5760 else if (element == EL_SP_ELECTRON)
5761 DrawLevelElementAnimationIfNeeded(x, y, element);
5762 else if (element == EL_DRAGON)
5765 int dir = MovDir[x][y];
5766 int dx = (dir == MV_LEFT ? -1 : dir == MV_RIGHT ? +1 : 0);
5767 int dy = (dir == MV_UP ? -1 : dir == MV_DOWN ? +1 : 0);
5768 int graphic = (dir == MV_LEFT ? IMG_FLAMES_1_LEFT :
5769 dir == MV_RIGHT ? IMG_FLAMES_1_RIGHT :
5770 dir == MV_UP ? IMG_FLAMES_1_UP :
5771 dir == MV_DOWN ? IMG_FLAMES_1_DOWN : IMG_EMPTY);
5772 int frame = getGraphicAnimationFrame(graphic, GfxFrame[x][y]);
5774 GfxAction[x][y] = ACTION_ATTACKING;
5776 if (IS_PLAYER(x, y))
5777 DrawPlayerField(x, y);
5779 DrawLevelField(x, y);
5781 PlayLevelSoundActionIfLoop(x, y, ACTION_ATTACKING);
5783 for (i = 1; i <= 3; i++)
5785 int xx = x + i * dx;
5786 int yy = y + i * dy;
5787 int sx = SCREENX(xx);
5788 int sy = SCREENY(yy);
5789 int flame_graphic = graphic + (i - 1);
5791 if (!IN_LEV_FIELD(xx, yy) || IS_DRAGONFIRE_PROOF(Feld[xx][yy]))
5796 int flamed = MovingOrBlocked2Element(xx, yy);
5800 if (IS_CLASSIC_ENEMY(flamed) || CAN_EXPLODE_BY_DRAGONFIRE(flamed))
5802 else if (IS_MOVING(xx, yy) || IS_BLOCKED(xx, yy))
5803 RemoveMovingField(xx, yy);
5805 RemoveField(xx, yy);
5807 if (IS_CLASSIC_ENEMY(flamed) || CAN_EXPLODE_BY_DRAGONFIRE(flamed))
5810 RemoveMovingField(xx, yy);
5813 ChangeDelay[xx][yy] = 0;
5815 Feld[xx][yy] = EL_FLAMES;
5817 if (IN_SCR_FIELD(sx, sy))
5819 DrawLevelFieldCrumbledSand(xx, yy);
5820 DrawGraphic(sx, sy, flame_graphic, frame);
5825 if (Feld[xx][yy] == EL_FLAMES)
5826 Feld[xx][yy] = EL_EMPTY;
5827 DrawLevelField(xx, yy);
5832 if (MovDelay[x][y]) /* element still has to wait some time */
5834 PlayLevelSoundAction(x, y, ACTION_WAITING);
5840 /* now make next step */
5842 Moving2Blocked(x, y, &newx, &newy); /* get next screen position */
5844 if (DONT_COLLIDE_WITH(element) &&
5845 IN_LEV_FIELD(newx, newy) && IS_PLAYER(newx, newy) &&
5846 !PLAYER_ENEMY_PROTECTED(newx, newy))
5848 TestIfBadThingRunsIntoPlayer(x, y, MovDir[x][y]);
5853 else if (CAN_MOVE_INTO_ACID(element) &&
5854 IN_LEV_FIELD(newx, newy) && Feld[newx][newy] == EL_ACID &&
5855 !IS_MV_DIAGONAL(MovDir[x][y]) &&
5856 (MovDir[x][y] == MV_DOWN ||
5857 game.engine_version >= VERSION_IDENT(3,1,0,0)))
5859 SplashAcid(newx, newy);
5860 Store[x][y] = EL_ACID;
5862 else if (element == EL_PENGUIN && IN_LEV_FIELD(newx, newy))
5864 if (Feld[newx][newy] == EL_EXIT_OPEN)
5867 DrawLevelField(x, y);
5869 PlayLevelSound(newx, newy, SND_PENGUIN_PASSING);
5870 if (IN_SCR_FIELD(SCREENX(newx), SCREENY(newy)))
5871 DrawGraphicThruMask(SCREENX(newx),SCREENY(newy), el2img(element), 0);
5873 local_player->friends_still_needed--;
5874 if (!local_player->friends_still_needed &&
5875 !local_player->GameOver && AllPlayersGone)
5876 local_player->LevelSolved = local_player->GameOver = TRUE;
5880 else if (IS_FOOD_PENGUIN(Feld[newx][newy]))
5882 if (DigField(local_player, x, y, newx, newy, 0,0, DF_DIG) == MP_MOVING)
5883 DrawLevelField(newx, newy);
5885 GfxDir[x][y] = MovDir[x][y] = MV_NONE;
5887 else if (!IS_FREE(newx, newy))
5889 GfxAction[x][y] = ACTION_WAITING;
5891 if (IS_PLAYER(x, y))
5892 DrawPlayerField(x, y);
5894 DrawLevelField(x, y);
5899 else if (element == EL_PIG && IN_LEV_FIELD(newx, newy))
5901 if (IS_FOOD_PIG(Feld[newx][newy]))
5903 if (IS_MOVING(newx, newy))
5904 RemoveMovingField(newx, newy);
5907 Feld[newx][newy] = EL_EMPTY;
5908 DrawLevelField(newx, newy);
5911 PlayLevelSound(x, y, SND_PIG_DIGGING);
5913 else if (!IS_FREE(newx, newy))
5915 if (IS_PLAYER(x, y))
5916 DrawPlayerField(x, y);
5918 DrawLevelField(x, y);
5923 else if (element == EL_EMC_ANDROID && IN_LEV_FIELD(newx, newy))
5925 if (Store[x][y] != EL_EMPTY)
5927 boolean can_clone = FALSE;
5930 /* check if element to clone is still there */
5931 for (yy = y - 1; yy <= y + 1; yy++) for (xx = x - 1; xx <= x + 1; xx++)
5933 if (IN_LEV_FIELD(xx, yy) && Feld[xx][yy] == Store[x][y])
5941 /* cannot clone or target field not free anymore -- do not clone */
5942 if (!can_clone || !ANDROID_CAN_ENTER_FIELD(element, newx, newy))
5943 Store[x][y] = EL_EMPTY;
5946 if (ANDROID_CAN_ENTER_FIELD(element, newx, newy))
5948 if (IS_MV_DIAGONAL(MovDir[x][y]))
5950 int diagonal_move_dir = MovDir[x][y];
5951 int stored = Store[x][y];
5952 int change_delay = 8;
5955 /* android is moving diagonally */
5957 CreateField(x, y, EL_DIAGONAL_SHRINKING);
5959 Store[x][y] = (stored == EL_ACID ? EL_EMPTY : stored);
5960 GfxElement[x][y] = EL_EMC_ANDROID;
5961 GfxAction[x][y] = ACTION_SHRINKING;
5962 GfxDir[x][y] = diagonal_move_dir;
5963 ChangeDelay[x][y] = change_delay;
5965 graphic = el_act_dir2img(GfxElement[x][y], GfxAction[x][y],
5968 DrawLevelGraphicAnimation(x, y, graphic);
5969 PlayLevelSoundAction(x, y, ACTION_SHRINKING);
5971 if (Feld[newx][newy] == EL_ACID)
5973 SplashAcid(newx, newy);
5978 CreateField(newx, newy, EL_DIAGONAL_GROWING);
5980 Store[newx][newy] = EL_EMC_ANDROID;
5981 GfxElement[newx][newy] = EL_EMC_ANDROID;
5982 GfxAction[newx][newy] = ACTION_GROWING;
5983 GfxDir[newx][newy] = diagonal_move_dir;
5984 ChangeDelay[newx][newy] = change_delay;
5986 graphic = el_act_dir2img(GfxElement[newx][newy],
5987 GfxAction[newx][newy], GfxDir[newx][newy]);
5989 DrawLevelGraphicAnimation(newx, newy, graphic);
5990 PlayLevelSoundAction(newx, newy, ACTION_GROWING);
5996 Feld[newx][newy] = EL_EMPTY;
5997 DrawLevelField(newx, newy);
5999 PlayLevelSoundAction(x, y, ACTION_DIGGING);
6002 else if (!IS_FREE(newx, newy))
6005 if (IS_PLAYER(x, y))
6006 DrawPlayerField(x, y);
6008 DrawLevelField(x, y);
6014 else if (IS_CUSTOM_ELEMENT(element) &&
6015 CUSTOM_ELEMENT_CAN_ENTER_FIELD(element, newx, newy))
6017 int new_element = Feld[newx][newy];
6019 if (!IS_FREE(newx, newy))
6021 int action = (IS_DIGGABLE(new_element) ? ACTION_DIGGING :
6022 IS_COLLECTIBLE(new_element) ? ACTION_COLLECTING :
6025 /* no element can dig solid indestructible elements */
6026 if (IS_INDESTRUCTIBLE(new_element) &&
6027 !IS_DIGGABLE(new_element) &&
6028 !IS_COLLECTIBLE(new_element))
6031 if (AmoebaNr[newx][newy] &&
6032 (new_element == EL_AMOEBA_FULL ||
6033 new_element == EL_BD_AMOEBA ||
6034 new_element == EL_AMOEBA_GROWING))
6036 AmoebaCnt[AmoebaNr[newx][newy]]--;
6037 AmoebaCnt2[AmoebaNr[newx][newy]]--;
6040 if (IS_MOVING(newx, newy))
6041 RemoveMovingField(newx, newy);
6044 RemoveField(newx, newy);
6045 DrawLevelField(newx, newy);
6048 /* if digged element was about to explode, prevent the explosion */
6049 ExplodeField[newx][newy] = EX_TYPE_NONE;
6051 PlayLevelSoundAction(x, y, action);
6054 Store[newx][newy] = EL_EMPTY;
6056 /* this makes it possible to leave the removed element again */
6057 if (IS_EQUAL_OR_IN_GROUP(new_element, MOVE_ENTER_EL(element)))
6058 Store[newx][newy] = new_element;
6060 if (IS_EQUAL_OR_IN_GROUP(new_element, MOVE_ENTER_EL(element)))
6062 int move_leave_element = element_info[element].move_leave_element;
6064 /* this makes it possible to leave the removed element again */
6065 Store[newx][newy] = (move_leave_element == EL_TRIGGER_ELEMENT ?
6066 new_element : move_leave_element);
6070 if (move_pattern & MV_MAZE_RUNNER_STYLE)
6072 RunnerVisit[x][y] = FrameCounter;
6073 PlayerVisit[x][y] /= 8; /* expire player visit path */
6076 else if (element == EL_DRAGON && IN_LEV_FIELD(newx, newy))
6078 if (!IS_FREE(newx, newy))
6080 if (IS_PLAYER(x, y))
6081 DrawPlayerField(x, y);
6083 DrawLevelField(x, y);
6089 boolean wanna_flame = !RND(10);
6090 int dx = newx - x, dy = newy - y;
6091 int newx1 = newx + 1 * dx, newy1 = newy + 1 * dy;
6092 int newx2 = newx + 2 * dx, newy2 = newy + 2 * dy;
6093 int element1 = (IN_LEV_FIELD(newx1, newy1) ?
6094 MovingOrBlocked2Element(newx1, newy1) : EL_STEELWALL);
6095 int element2 = (IN_LEV_FIELD(newx2, newy2) ?
6096 MovingOrBlocked2Element(newx2, newy2) : EL_STEELWALL);
6099 IS_CLASSIC_ENEMY(element1) ||
6100 IS_CLASSIC_ENEMY(element2)) &&
6101 element1 != EL_DRAGON && element2 != EL_DRAGON &&
6102 element1 != EL_FLAMES && element2 != EL_FLAMES)
6104 ResetGfxAnimation(x, y);
6105 GfxAction[x][y] = ACTION_ATTACKING;
6107 if (IS_PLAYER(x, y))
6108 DrawPlayerField(x, y);
6110 DrawLevelField(x, y);
6112 PlayLevelSound(x, y, SND_DRAGON_ATTACKING);
6114 MovDelay[x][y] = 50;
6118 RemoveField(newx, newy);
6120 Feld[newx][newy] = EL_FLAMES;
6121 if (IN_LEV_FIELD(newx1, newy1) && Feld[newx1][newy1] == EL_EMPTY)
6124 RemoveField(newx1, newy1);
6126 Feld[newx1][newy1] = EL_FLAMES;
6128 if (IN_LEV_FIELD(newx2, newy2) && Feld[newx2][newy2] == EL_EMPTY)
6131 RemoveField(newx2, newy2);
6133 Feld[newx2][newy2] = EL_FLAMES;
6140 else if (element == EL_YAMYAM && IN_LEV_FIELD(newx, newy) &&
6141 Feld[newx][newy] == EL_DIAMOND)
6143 if (IS_MOVING(newx, newy))
6144 RemoveMovingField(newx, newy);
6147 Feld[newx][newy] = EL_EMPTY;
6148 DrawLevelField(newx, newy);
6151 PlayLevelSound(x, y, SND_YAMYAM_DIGGING);
6153 else if (element == EL_DARK_YAMYAM && IN_LEV_FIELD(newx, newy) &&
6154 IS_FOOD_DARK_YAMYAM(Feld[newx][newy]))
6156 if (AmoebaNr[newx][newy])
6158 AmoebaCnt2[AmoebaNr[newx][newy]]--;
6159 if (Feld[newx][newy] == EL_AMOEBA_FULL ||
6160 Feld[newx][newy] == EL_BD_AMOEBA)
6161 AmoebaCnt[AmoebaNr[newx][newy]]--;
6166 if (IS_MOVING(newx, newy) || IS_BLOCKED(newx, newy))
6168 RemoveMovingField(newx, newy);
6171 if (IS_MOVING(newx, newy))
6173 RemoveMovingField(newx, newy);
6178 Feld[newx][newy] = EL_EMPTY;
6179 DrawLevelField(newx, newy);
6182 PlayLevelSound(x, y, SND_DARK_YAMYAM_DIGGING);
6184 else if ((element == EL_PACMAN || element == EL_MOLE)
6185 && IN_LEV_FIELD(newx, newy) && IS_AMOEBOID(Feld[newx][newy]))
6187 if (AmoebaNr[newx][newy])
6189 AmoebaCnt2[AmoebaNr[newx][newy]]--;
6190 if (Feld[newx][newy] == EL_AMOEBA_FULL ||
6191 Feld[newx][newy] == EL_BD_AMOEBA)
6192 AmoebaCnt[AmoebaNr[newx][newy]]--;
6195 if (element == EL_MOLE)
6197 Feld[newx][newy] = EL_AMOEBA_SHRINKING;
6198 PlayLevelSound(x, y, SND_MOLE_DIGGING);
6200 ResetGfxAnimation(x, y);
6201 GfxAction[x][y] = ACTION_DIGGING;
6202 DrawLevelField(x, y);
6204 MovDelay[newx][newy] = 0; /* start amoeba shrinking delay */
6206 return; /* wait for shrinking amoeba */
6208 else /* element == EL_PACMAN */
6210 Feld[newx][newy] = EL_EMPTY;
6211 DrawLevelField(newx, newy);
6212 PlayLevelSound(x, y, SND_PACMAN_DIGGING);
6215 else if (element == EL_MOLE && IN_LEV_FIELD(newx, newy) &&
6216 (Feld[newx][newy] == EL_AMOEBA_SHRINKING ||
6217 (Feld[newx][newy] == EL_EMPTY && Stop[newx][newy])))
6219 /* wait for shrinking amoeba to completely disappear */
6222 else if (!IN_LEV_FIELD(newx, newy) || !IS_FREE(newx, newy))
6224 /* object was running against a wall */
6229 /* !!! NEW "CE_BLOCKED" STUFF !!! -- DOES NOT WORK YET... !!! */
6230 if (move_pattern & MV_ANY_DIRECTION &&
6231 move_pattern == MovDir[x][y])
6233 int blocking_element =
6234 (IN_LEV_FIELD(newx, newy) ? Feld[newx][newy] : BorderElement);
6236 CheckElementChangeBySide(x, y, element, blocking_element, CE_BLOCKED,
6239 element = Feld[x][y]; /* element might have changed */
6243 if (GFX_ELEMENT(element) != EL_SAND) /* !!! FIX THIS (crumble) !!! */
6244 DrawLevelElementAnimation(x, y, element);
6246 if (DONT_TOUCH(element))
6247 TestIfBadThingTouchesPlayer(x, y);
6252 InitMovingField(x, y, MovDir[x][y]);
6254 PlayLevelSoundAction(x, y, ACTION_MOVING);
6258 ContinueMoving(x, y);
6261 void ContinueMoving(int x, int y)
6263 int element = Feld[x][y];
6264 struct ElementInfo *ei = &element_info[element];
6265 int direction = MovDir[x][y];
6266 int dx = (direction == MV_LEFT ? -1 : direction == MV_RIGHT ? +1 : 0);
6267 int dy = (direction == MV_UP ? -1 : direction == MV_DOWN ? +1 : 0);
6268 int newx = x + dx, newy = y + dy;
6269 int stored = Store[x][y];
6270 int stored_new = Store[newx][newy];
6271 boolean pushed_by_player = (Pushed[x][y] && IS_PLAYER(x, y));
6272 boolean pushed_by_conveyor = (Pushed[x][y] && !IS_PLAYER(x, y));
6273 boolean last_line = (newy == lev_fieldy - 1);
6275 MovPos[x][y] += getElementMoveStepsize(x, y);
6277 if (pushed_by_player) /* special case: moving object pushed by player */
6278 MovPos[x][y] = SIGN(MovPos[x][y]) * (TILEX - ABS(PLAYERINFO(x,y)->MovPos));
6280 if (ABS(MovPos[x][y]) < TILEX)
6282 DrawLevelField(x, y);
6284 return; /* element is still moving */
6287 /* element reached destination field */
6289 Feld[x][y] = EL_EMPTY;
6290 Feld[newx][newy] = element;
6291 MovPos[x][y] = 0; /* force "not moving" for "crumbled sand" */
6293 if (Store[x][y] == EL_ACID) /* element is moving into acid pool */
6295 element = Feld[newx][newy] = EL_ACID;
6297 else if (element == EL_MOLE)
6299 Feld[x][y] = EL_SAND;
6301 DrawLevelFieldCrumbledSandNeighbours(x, y);
6303 else if (element == EL_QUICKSAND_FILLING)
6305 element = Feld[newx][newy] = get_next_element(element);
6306 Store[newx][newy] = Store[x][y];
6308 else if (element == EL_QUICKSAND_EMPTYING)
6310 Feld[x][y] = get_next_element(element);
6311 element = Feld[newx][newy] = Store[x][y];
6313 else if (element == EL_MAGIC_WALL_FILLING)
6315 element = Feld[newx][newy] = get_next_element(element);
6316 if (!game.magic_wall_active)
6317 element = Feld[newx][newy] = EL_MAGIC_WALL_DEAD;
6318 Store[newx][newy] = Store[x][y];
6320 else if (element == EL_MAGIC_WALL_EMPTYING)
6322 Feld[x][y] = get_next_element(element);
6323 if (!game.magic_wall_active)
6324 Feld[x][y] = EL_MAGIC_WALL_DEAD;
6325 element = Feld[newx][newy] = Store[x][y];
6327 #if USE_NEW_CUSTOM_VALUE
6328 InitField(newx, newy, FALSE);
6331 else if (element == EL_BD_MAGIC_WALL_FILLING)
6333 element = Feld[newx][newy] = get_next_element(element);
6334 if (!game.magic_wall_active)
6335 element = Feld[newx][newy] = EL_BD_MAGIC_WALL_DEAD;
6336 Store[newx][newy] = Store[x][y];
6338 else if (element == EL_BD_MAGIC_WALL_EMPTYING)
6340 Feld[x][y] = get_next_element(element);
6341 if (!game.magic_wall_active)
6342 Feld[x][y] = EL_BD_MAGIC_WALL_DEAD;
6343 element = Feld[newx][newy] = Store[x][y];
6345 #if USE_NEW_CUSTOM_VALUE
6346 InitField(newx, newy, FALSE);
6349 else if (element == EL_AMOEBA_DROPPING)
6351 Feld[x][y] = get_next_element(element);
6352 element = Feld[newx][newy] = Store[x][y];
6354 else if (element == EL_SOKOBAN_OBJECT)
6357 Feld[x][y] = Back[x][y];
6359 if (Back[newx][newy])
6360 Feld[newx][newy] = EL_SOKOBAN_FIELD_FULL;
6362 Back[x][y] = Back[newx][newy] = 0;
6365 Store[x][y] = EL_EMPTY;
6370 MovDelay[newx][newy] = 0;
6373 if (CAN_CHANGE_OR_HAS_ACTION(element))
6375 if (CAN_CHANGE(element))
6378 /* copy element change control values to new field */
6379 ChangeDelay[newx][newy] = ChangeDelay[x][y];
6380 ChangePage[newx][newy] = ChangePage[x][y];
6381 ChangeCount[newx][newy] = ChangeCount[x][y];
6382 ChangeEvent[newx][newy] = ChangeEvent[x][y];
6385 #if USE_NEW_CUSTOM_VALUE
6386 CustomValue[newx][newy] = CustomValue[x][y];
6392 #if USE_NEW_CUSTOM_VALUE
6393 CustomValue[newx][newy] = CustomValue[x][y];
6397 ChangeDelay[x][y] = 0;
6398 ChangePage[x][y] = -1;
6399 ChangeCount[x][y] = 0;
6400 ChangeEvent[x][y] = -1;
6402 #if USE_NEW_CUSTOM_VALUE
6403 CustomValue[x][y] = 0;
6406 /* copy animation control values to new field */
6407 GfxFrame[newx][newy] = GfxFrame[x][y];
6408 GfxRandom[newx][newy] = GfxRandom[x][y]; /* keep same random value */
6409 GfxAction[newx][newy] = GfxAction[x][y]; /* keep action one frame */
6410 GfxDir[newx][newy] = GfxDir[x][y]; /* keep element direction */
6412 Pushed[x][y] = Pushed[newx][newy] = FALSE;
6414 /* some elements can leave other elements behind after moving */
6416 if (ei->move_leave_element != EL_EMPTY &&
6417 (ei->move_leave_type == LEAVE_TYPE_UNLIMITED || stored != EL_EMPTY) &&
6418 (!IS_PLAYER(x, y) || IS_WALKABLE(ei->move_leave_element)))
6420 if (IS_CUSTOM_ELEMENT(element) && ei->move_leave_element != EL_EMPTY &&
6421 (ei->move_leave_type == LEAVE_TYPE_UNLIMITED || stored != EL_EMPTY) &&
6422 (!IS_PLAYER(x, y) || IS_WALKABLE(ei->move_leave_element)))
6425 int move_leave_element = ei->move_leave_element;
6429 /* this makes it possible to leave the removed element again */
6430 if (ei->move_leave_element == EL_TRIGGER_ELEMENT)
6431 move_leave_element = (stored == EL_ACID ? EL_EMPTY : stored);
6433 /* this makes it possible to leave the removed element again */
6434 if (ei->move_leave_element == EL_TRIGGER_ELEMENT)
6435 move_leave_element = stored;
6438 /* this makes it possible to leave the removed element again */
6439 if (ei->move_leave_type == LEAVE_TYPE_LIMITED &&
6440 ei->move_leave_element == EL_TRIGGER_ELEMENT)
6441 move_leave_element = stored;
6444 Feld[x][y] = move_leave_element;
6446 if (element_info[Feld[x][y]].move_direction_initial == MV_START_PREVIOUS)
6447 MovDir[x][y] = direction;
6449 InitField(x, y, FALSE);
6451 if (GFX_CRUMBLED(Feld[x][y]))
6452 DrawLevelFieldCrumbledSandNeighbours(x, y);
6454 if (ELEM_IS_PLAYER(move_leave_element))
6455 RelocatePlayer(x, y, move_leave_element);
6458 /* do this after checking for left-behind element */
6459 ResetGfxAnimation(x, y); /* reset animation values for old field */
6461 if (!CAN_MOVE(element) ||
6462 (CAN_FALL(element) && direction == MV_DOWN &&
6463 (element == EL_SPRING ||
6464 element_info[element].move_pattern == MV_WHEN_PUSHED ||
6465 element_info[element].move_pattern == MV_WHEN_DROPPED)))
6466 GfxDir[x][y] = MovDir[newx][newy] = 0;
6468 DrawLevelField(x, y);
6469 DrawLevelField(newx, newy);
6471 Stop[newx][newy] = TRUE; /* ignore this element until the next frame */
6473 /* prevent pushed element from moving on in pushed direction */
6474 if (pushed_by_player && CAN_MOVE(element) &&
6475 element_info[element].move_pattern & MV_ANY_DIRECTION &&
6476 !(element_info[element].move_pattern & direction))
6477 TurnRound(newx, newy);
6479 /* prevent elements on conveyor belt from moving on in last direction */
6480 if (pushed_by_conveyor && CAN_FALL(element) &&
6481 direction & MV_HORIZONTAL)
6482 MovDir[newx][newy] = 0;
6484 if (!pushed_by_player)
6486 int nextx = newx + dx, nexty = newy + dy;
6487 boolean check_collision_again = IN_LEV_FIELD_AND_IS_FREE(nextx, nexty);
6489 WasJustMoving[newx][newy] = 3;
6491 if (CAN_FALL(element) && direction == MV_DOWN)
6492 WasJustFalling[newx][newy] = 3;
6494 if ((!CAN_FALL(element) || direction == MV_DOWN) && check_collision_again)
6495 CheckCollision[newx][newy] = 2;
6498 if (DONT_TOUCH(element)) /* object may be nasty to player or others */
6500 TestIfBadThingTouchesPlayer(newx, newy);
6501 TestIfBadThingTouchesFriend(newx, newy);
6503 if (!IS_CUSTOM_ELEMENT(element))
6504 TestIfBadThingTouchesOtherBadThing(newx, newy);
6506 else if (element == EL_PENGUIN)
6507 TestIfFriendTouchesBadThing(newx, newy);
6509 /* give the player one last chance (one more frame) to move away */
6510 if (CAN_FALL(element) && direction == MV_DOWN &&
6511 (last_line || (!IS_FREE(x, newy + 1) &&
6512 (!IS_PLAYER(x, newy + 1) ||
6513 game.engine_version < VERSION_IDENT(3,1,1,0)))))
6516 if (pushed_by_player && !game.use_change_when_pushing_bug)
6518 int push_side = MV_DIR_OPPOSITE(direction);
6519 struct PlayerInfo *player = PLAYERINFO(x, y);
6521 CheckElementChangeByPlayer(newx, newy, element, CE_PUSHED_BY_PLAYER,
6522 player->index_bit, push_side);
6523 CheckTriggeredElementChangeByPlayer(newx,newy, element, CE_PLAYER_PUSHES_X,
6524 player->index_bit, push_side);
6527 if (element == EL_EMC_ANDROID && pushed_by_player) /* make another move */
6528 MovDelay[newx][newy] = 1;
6530 CheckTriggeredElementChangeBySide(x, y, element, CE_MOVE_OF_X, direction);
6532 TestIfElementTouchesCustomElement(x, y); /* empty or new element */
6535 if (ChangePage[newx][newy] != -1) /* delayed change */
6537 int page = ChangePage[newx][newy];
6538 struct ElementChangeInfo *change = &ei->change_page[page];
6540 ChangePage[newx][newy] = -1;
6542 if (change->can_change)
6544 if (ChangeElement(newx, newy, element, page))
6546 if (change->post_change_function)
6547 change->post_change_function(newx, newy);
6551 if (change->has_action)
6552 ExecuteCustomElementAction(newx, newy, element, page);
6556 TestIfElementHitsCustomElement(newx, newy, direction);
6557 TestIfPlayerTouchesCustomElement(newx, newy);
6558 TestIfElementTouchesCustomElement(newx, newy);
6561 if (IS_CUSTOM_ELEMENT(element) && ei->move_enter_element != EL_EMPTY &&
6562 IS_EQUAL_OR_IN_GROUP(stored_new, ei->move_enter_element))
6563 CheckElementChangeBySide(newx, newy, element, stored_new, CE_DIGGING_X,
6564 MV_DIR_OPPOSITE(direction));
6568 int AmoebeNachbarNr(int ax, int ay)
6571 int element = Feld[ax][ay];
6573 static int xy[4][2] =
6581 for (i = 0; i < NUM_DIRECTIONS; i++)
6583 int x = ax + xy[i][0];
6584 int y = ay + xy[i][1];
6586 if (!IN_LEV_FIELD(x, y))
6589 if (Feld[x][y] == element && AmoebaNr[x][y] > 0)
6590 group_nr = AmoebaNr[x][y];
6596 void AmoebenVereinigen(int ax, int ay)
6598 int i, x, y, xx, yy;
6599 int new_group_nr = AmoebaNr[ax][ay];
6600 static int xy[4][2] =
6608 if (new_group_nr == 0)
6611 for (i = 0; i < NUM_DIRECTIONS; i++)
6616 if (!IN_LEV_FIELD(x, y))
6619 if ((Feld[x][y] == EL_AMOEBA_FULL ||
6620 Feld[x][y] == EL_BD_AMOEBA ||
6621 Feld[x][y] == EL_AMOEBA_DEAD) &&
6622 AmoebaNr[x][y] != new_group_nr)
6624 int old_group_nr = AmoebaNr[x][y];
6626 if (old_group_nr == 0)
6629 AmoebaCnt[new_group_nr] += AmoebaCnt[old_group_nr];
6630 AmoebaCnt[old_group_nr] = 0;
6631 AmoebaCnt2[new_group_nr] += AmoebaCnt2[old_group_nr];
6632 AmoebaCnt2[old_group_nr] = 0;
6635 SCAN_PLAYFIELD(xx, yy)
6637 for (yy = 0; yy < lev_fieldy; yy++) for (xx = 0; xx < lev_fieldx; xx++)
6640 if (AmoebaNr[xx][yy] == old_group_nr)
6641 AmoebaNr[xx][yy] = new_group_nr;
6647 void AmoebeUmwandeln(int ax, int ay)
6651 if (Feld[ax][ay] == EL_AMOEBA_DEAD)
6653 int group_nr = AmoebaNr[ax][ay];
6658 printf("AmoebeUmwandeln(): ax = %d, ay = %d\n", ax, ay);
6659 printf("AmoebeUmwandeln(): This should never happen!\n");
6665 SCAN_PLAYFIELD(x, y)
6667 for (y = 0; y < lev_fieldy; y++) for (x = 0; x < lev_fieldx; x++)
6670 if (Feld[x][y] == EL_AMOEBA_DEAD && AmoebaNr[x][y] == group_nr)
6673 Feld[x][y] = EL_AMOEBA_TO_DIAMOND;
6677 PlayLevelSound(ax, ay, (IS_GEM(level.amoeba_content) ?
6678 SND_AMOEBA_TURNING_TO_GEM :
6679 SND_AMOEBA_TURNING_TO_ROCK));
6684 static int xy[4][2] =
6692 for (i = 0; i < NUM_DIRECTIONS; i++)
6697 if (!IN_LEV_FIELD(x, y))
6700 if (Feld[x][y] == EL_AMOEBA_TO_DIAMOND)
6702 PlayLevelSound(x, y, (IS_GEM(level.amoeba_content) ?
6703 SND_AMOEBA_TURNING_TO_GEM :
6704 SND_AMOEBA_TURNING_TO_ROCK));
6711 void AmoebeUmwandelnBD(int ax, int ay, int new_element)
6714 int group_nr = AmoebaNr[ax][ay];
6715 boolean done = FALSE;
6720 printf("AmoebeUmwandelnBD(): ax = %d, ay = %d\n", ax, ay);
6721 printf("AmoebeUmwandelnBD(): This should never happen!\n");
6727 SCAN_PLAYFIELD(x, y)
6729 for (y = 0; y < lev_fieldy; y++) for (x = 0; x < lev_fieldx; x++)
6732 if (AmoebaNr[x][y] == group_nr &&
6733 (Feld[x][y] == EL_AMOEBA_DEAD ||
6734 Feld[x][y] == EL_BD_AMOEBA ||
6735 Feld[x][y] == EL_AMOEBA_GROWING))
6738 Feld[x][y] = new_element;
6739 InitField(x, y, FALSE);
6740 DrawLevelField(x, y);
6746 PlayLevelSound(ax, ay, (new_element == EL_BD_ROCK ?
6747 SND_BD_AMOEBA_TURNING_TO_ROCK :
6748 SND_BD_AMOEBA_TURNING_TO_GEM));
6751 void AmoebeWaechst(int x, int y)
6753 static unsigned long sound_delay = 0;
6754 static unsigned long sound_delay_value = 0;
6756 if (!MovDelay[x][y]) /* start new growing cycle */
6760 if (DelayReached(&sound_delay, sound_delay_value))
6762 PlayLevelSoundElementAction(x, y, Store[x][y], ACTION_GROWING);
6763 sound_delay_value = 30;
6767 if (MovDelay[x][y]) /* wait some time before growing bigger */
6770 if (MovDelay[x][y]/2 && IN_SCR_FIELD(SCREENX(x), SCREENY(y)))
6772 int frame = getGraphicAnimationFrame(IMG_AMOEBA_GROWING,
6773 6 - MovDelay[x][y]);
6775 DrawGraphic(SCREENX(x), SCREENY(y), IMG_AMOEBA_GROWING, frame);
6778 if (!MovDelay[x][y])
6780 Feld[x][y] = Store[x][y];
6782 DrawLevelField(x, y);
6787 void AmoebaDisappearing(int x, int y)
6789 static unsigned long sound_delay = 0;
6790 static unsigned long sound_delay_value = 0;
6792 if (!MovDelay[x][y]) /* start new shrinking cycle */
6796 if (DelayReached(&sound_delay, sound_delay_value))
6797 sound_delay_value = 30;
6800 if (MovDelay[x][y]) /* wait some time before shrinking */
6803 if (MovDelay[x][y]/2 && IN_SCR_FIELD(SCREENX(x), SCREENY(y)))
6805 int frame = getGraphicAnimationFrame(IMG_AMOEBA_SHRINKING,
6806 6 - MovDelay[x][y]);
6808 DrawGraphic(SCREENX(x), SCREENY(y), IMG_AMOEBA_SHRINKING, frame);
6811 if (!MovDelay[x][y])
6813 Feld[x][y] = EL_EMPTY;
6814 DrawLevelField(x, y);
6816 /* don't let mole enter this field in this cycle;
6817 (give priority to objects falling to this field from above) */
6823 void AmoebeAbleger(int ax, int ay)
6826 int element = Feld[ax][ay];
6827 int graphic = el2img(element);
6828 int newax = ax, neway = ay;
6829 boolean can_drop = (element == EL_AMOEBA_WET || element == EL_EMC_DRIPPER);
6830 static int xy[4][2] =
6838 if (!level.amoeba_speed && element != EL_EMC_DRIPPER)
6840 Feld[ax][ay] = EL_AMOEBA_DEAD;
6841 DrawLevelField(ax, ay);
6845 if (IS_ANIMATED(graphic))
6846 DrawLevelGraphicAnimationIfNeeded(ax, ay, graphic);
6848 if (!MovDelay[ax][ay]) /* start making new amoeba field */
6849 MovDelay[ax][ay] = RND(FRAMES_PER_SECOND * 25 / (1 + level.amoeba_speed));
6851 if (MovDelay[ax][ay]) /* wait some time before making new amoeba */
6854 if (MovDelay[ax][ay])
6858 if (can_drop) /* EL_AMOEBA_WET or EL_EMC_DRIPPER */
6861 int x = ax + xy[start][0];
6862 int y = ay + xy[start][1];
6864 if (!IN_LEV_FIELD(x, y))
6867 if (IS_FREE(x, y) ||
6868 CAN_GROW_INTO(Feld[x][y]) ||
6869 Feld[x][y] == EL_QUICKSAND_EMPTY)
6875 if (newax == ax && neway == ay)
6878 else /* normal or "filled" (BD style) amoeba */
6881 boolean waiting_for_player = FALSE;
6883 for (i = 0; i < NUM_DIRECTIONS; i++)
6885 int j = (start + i) % 4;
6886 int x = ax + xy[j][0];
6887 int y = ay + xy[j][1];
6889 if (!IN_LEV_FIELD(x, y))
6892 if (IS_FREE(x, y) ||
6893 CAN_GROW_INTO(Feld[x][y]) ||
6894 Feld[x][y] == EL_QUICKSAND_EMPTY)
6900 else if (IS_PLAYER(x, y))
6901 waiting_for_player = TRUE;
6904 if (newax == ax && neway == ay) /* amoeba cannot grow */
6906 if (i == 4 && (!waiting_for_player || element == EL_BD_AMOEBA))
6908 Feld[ax][ay] = EL_AMOEBA_DEAD;
6909 DrawLevelField(ax, ay);
6910 AmoebaCnt[AmoebaNr[ax][ay]]--;
6912 if (AmoebaCnt[AmoebaNr[ax][ay]] <= 0) /* amoeba is completely dead */
6914 if (element == EL_AMOEBA_FULL)
6915 AmoebeUmwandeln(ax, ay);
6916 else if (element == EL_BD_AMOEBA)
6917 AmoebeUmwandelnBD(ax, ay, level.amoeba_content);
6922 else if (element == EL_AMOEBA_FULL || element == EL_BD_AMOEBA)
6924 /* amoeba gets larger by growing in some direction */
6926 int new_group_nr = AmoebaNr[ax][ay];
6929 if (new_group_nr == 0)
6931 printf("AmoebeAbleger(): newax = %d, neway = %d\n", newax, neway);
6932 printf("AmoebeAbleger(): This should never happen!\n");
6937 AmoebaNr[newax][neway] = new_group_nr;
6938 AmoebaCnt[new_group_nr]++;
6939 AmoebaCnt2[new_group_nr]++;
6941 /* if amoeba touches other amoeba(s) after growing, unify them */
6942 AmoebenVereinigen(newax, neway);
6944 if (element == EL_BD_AMOEBA && AmoebaCnt2[new_group_nr] >= 200)
6946 AmoebeUmwandelnBD(newax, neway, EL_BD_ROCK);
6952 if (!can_drop || neway < ay || !IS_FREE(newax, neway) ||
6953 (neway == lev_fieldy - 1 && newax != ax))
6955 Feld[newax][neway] = EL_AMOEBA_GROWING; /* creation of new amoeba */
6956 Store[newax][neway] = element;
6958 else if (neway == ay || element == EL_EMC_DRIPPER)
6960 Feld[newax][neway] = EL_AMOEBA_DROP; /* drop left/right of amoeba */
6962 PlayLevelSoundAction(newax, neway, ACTION_GROWING);
6966 InitMovingField(ax, ay, MV_DOWN); /* drop dripping from amoeba */
6967 Feld[ax][ay] = EL_AMOEBA_DROPPING;
6968 Store[ax][ay] = EL_AMOEBA_DROP;
6969 ContinueMoving(ax, ay);
6973 DrawLevelField(newax, neway);
6976 void Life(int ax, int ay)
6980 static int life[4] = { 2, 3, 3, 3 }; /* parameters for "game of life" */
6983 int element = Feld[ax][ay];
6984 int graphic = el2img(element);
6985 int *life_parameter = (element == EL_GAME_OF_LIFE ? level.game_of_life :
6987 boolean changed = FALSE;
6989 if (IS_ANIMATED(graphic))
6990 DrawLevelGraphicAnimationIfNeeded(ax, ay, graphic);
6995 if (!MovDelay[ax][ay]) /* start new "game of life" cycle */
6996 MovDelay[ax][ay] = life_time;
6998 if (MovDelay[ax][ay]) /* wait some time before next cycle */
7001 if (MovDelay[ax][ay])
7005 for (y1 = -1; y1 < 2; y1++) for (x1 = -1; x1 < 2; x1++)
7007 int xx = ax+x1, yy = ay+y1;
7010 if (!IN_LEV_FIELD(xx, yy))
7013 for (y2 = -1; y2 < 2; y2++) for (x2 = -1; x2 < 2; x2++)
7015 int x = xx+x2, y = yy+y2;
7017 if (!IN_LEV_FIELD(x, y) || (x == xx && y == yy))
7020 if (((Feld[x][y] == element ||
7021 (element == EL_GAME_OF_LIFE && IS_PLAYER(x, y))) &&
7023 (IS_FREE(x, y) && Stop[x][y]))
7027 if (xx == ax && yy == ay) /* field in the middle */
7029 if (nachbarn < life_parameter[0] ||
7030 nachbarn > life_parameter[1])
7032 Feld[xx][yy] = EL_EMPTY;
7034 DrawLevelField(xx, yy);
7035 Stop[xx][yy] = TRUE;
7039 else if (IS_FREE(xx, yy) || CAN_GROW_INTO(Feld[xx][yy]))
7040 { /* free border field */
7041 if (nachbarn >= life_parameter[2] &&
7042 nachbarn <= life_parameter[3])
7044 Feld[xx][yy] = element;
7045 MovDelay[xx][yy] = (element == EL_GAME_OF_LIFE ? 0 : life_time-1);
7047 DrawLevelField(xx, yy);
7048 Stop[xx][yy] = TRUE;
7055 PlayLevelSound(ax, ay, element == EL_BIOMAZE ? SND_BIOMAZE_GROWING :
7056 SND_GAME_OF_LIFE_GROWING);
7059 static void InitRobotWheel(int x, int y)
7061 ChangeDelay[x][y] = level.time_wheel * FRAMES_PER_SECOND;
7064 static void RunRobotWheel(int x, int y)
7066 PlayLevelSound(x, y, SND_ROBOT_WHEEL_ACTIVE);
7069 static void StopRobotWheel(int x, int y)
7071 if (ZX == x && ZY == y)
7075 static void InitTimegateWheel(int x, int y)
7077 ChangeDelay[x][y] = level.time_timegate * FRAMES_PER_SECOND;
7080 static void RunTimegateWheel(int x, int y)
7082 PlayLevelSound(x, y, SND_TIMEGATE_SWITCH_ACTIVE);
7085 static void InitMagicBallDelay(int x, int y)
7088 ChangeDelay[x][y] = (level.ball_time + 1) * 8 + 1;
7090 ChangeDelay[x][y] = level.ball_time * FRAMES_PER_SECOND + 1;
7094 static void ActivateMagicBall(int bx, int by)
7098 if (level.ball_random)
7100 int pos_border = RND(8); /* select one of the eight border elements */
7101 int pos_content = (pos_border > 3 ? pos_border + 1 : pos_border);
7102 int xx = pos_content % 3;
7103 int yy = pos_content / 3;
7108 if (IN_LEV_FIELD(x, y) && Feld[x][y] == EL_EMPTY)
7109 CreateField(x, y, level.ball_content[game.ball_content_nr].e[xx][yy]);
7113 for (y = by - 1; y <= by + 1; y++) for (x = bx - 1; x <= bx + 1; x++)
7115 int xx = x - bx + 1;
7116 int yy = y - by + 1;
7118 if (IN_LEV_FIELD(x, y) && Feld[x][y] == EL_EMPTY)
7119 CreateField(x, y, level.ball_content[game.ball_content_nr].e[xx][yy]);
7123 game.ball_content_nr = (game.ball_content_nr + 1) % level.num_ball_contents;
7126 static void InitDiagonalMovingElement(int x, int y)
7129 MovDelay[x][y] = level.android_move_time;
7133 void CheckExit(int x, int y)
7135 if (local_player->gems_still_needed > 0 ||
7136 local_player->sokobanfields_still_needed > 0 ||
7137 local_player->lights_still_needed > 0)
7139 int element = Feld[x][y];
7140 int graphic = el2img(element);
7142 if (IS_ANIMATED(graphic))
7143 DrawLevelGraphicAnimationIfNeeded(x, y, graphic);
7148 if (AllPlayersGone) /* do not re-open exit door closed after last player */
7151 Feld[x][y] = EL_EXIT_OPENING;
7153 PlayLevelSoundNearest(x, y, SND_CLASS_EXIT_OPENING);
7156 void CheckExitSP(int x, int y)
7158 if (local_player->gems_still_needed > 0)
7160 int element = Feld[x][y];
7161 int graphic = el2img(element);
7163 if (IS_ANIMATED(graphic))
7164 DrawLevelGraphicAnimationIfNeeded(x, y, graphic);
7169 if (AllPlayersGone) /* do not re-open exit door closed after last player */
7172 Feld[x][y] = EL_SP_EXIT_OPENING;
7174 PlayLevelSoundNearest(x, y, SND_CLASS_SP_EXIT_OPENING);
7177 static void CloseAllOpenTimegates()
7182 SCAN_PLAYFIELD(x, y)
7184 for (y = 0; y < lev_fieldy; y++) for (x = 0; x < lev_fieldx; x++)
7187 int element = Feld[x][y];
7189 if (element == EL_TIMEGATE_OPEN || element == EL_TIMEGATE_OPENING)
7191 Feld[x][y] = EL_TIMEGATE_CLOSING;
7193 PlayLevelSoundAction(x, y, ACTION_CLOSING);
7198 void EdelsteinFunkeln(int x, int y)
7200 if (!IN_SCR_FIELD(SCREENX(x), SCREENY(y)) || IS_MOVING(x, y))
7203 if (Feld[x][y] == EL_BD_DIAMOND)
7206 if (MovDelay[x][y] == 0) /* next animation frame */
7207 MovDelay[x][y] = 11 * !SimpleRND(500);
7209 if (MovDelay[x][y] != 0) /* wait some time before next frame */
7213 if (setup.direct_draw && MovDelay[x][y])
7214 SetDrawtoField(DRAW_BUFFERED);
7216 DrawLevelElementAnimation(x, y, Feld[x][y]);
7218 if (MovDelay[x][y] != 0)
7220 int frame = getGraphicAnimationFrame(IMG_TWINKLE_WHITE,
7221 10 - MovDelay[x][y]);
7223 DrawGraphicThruMask(SCREENX(x), SCREENY(y), IMG_TWINKLE_WHITE, frame);
7225 if (setup.direct_draw)
7229 dest_x = FX + SCREENX(x) * TILEX;
7230 dest_y = FY + SCREENY(y) * TILEY;
7232 BlitBitmap(drawto_field, window,
7233 dest_x, dest_y, TILEX, TILEY, dest_x, dest_y);
7234 SetDrawtoField(DRAW_DIRECT);
7240 void MauerWaechst(int x, int y)
7244 if (!MovDelay[x][y]) /* next animation frame */
7245 MovDelay[x][y] = 3 * delay;
7247 if (MovDelay[x][y]) /* wait some time before next frame */
7251 if (IN_SCR_FIELD(SCREENX(x), SCREENY(y)))
7253 int graphic = el_dir2img(Feld[x][y], GfxDir[x][y]);
7254 int frame = getGraphicAnimationFrame(graphic, 17 - MovDelay[x][y]);
7256 DrawGraphic(SCREENX(x), SCREENY(y), graphic, frame);
7259 if (!MovDelay[x][y])
7261 if (MovDir[x][y] == MV_LEFT)
7263 if (IN_LEV_FIELD(x - 1, y) && IS_WALL(Feld[x - 1][y]))
7264 DrawLevelField(x - 1, y);
7266 else if (MovDir[x][y] == MV_RIGHT)
7268 if (IN_LEV_FIELD(x + 1, y) && IS_WALL(Feld[x + 1][y]))
7269 DrawLevelField(x + 1, y);
7271 else if (MovDir[x][y] == MV_UP)
7273 if (IN_LEV_FIELD(x, y - 1) && IS_WALL(Feld[x][y - 1]))
7274 DrawLevelField(x, y - 1);
7278 if (IN_LEV_FIELD(x, y + 1) && IS_WALL(Feld[x][y + 1]))
7279 DrawLevelField(x, y + 1);
7282 Feld[x][y] = Store[x][y];
7284 GfxDir[x][y] = MovDir[x][y] = MV_NONE;
7285 DrawLevelField(x, y);
7290 void MauerAbleger(int ax, int ay)
7292 int element = Feld[ax][ay];
7293 int graphic = el2img(element);
7294 boolean oben_frei = FALSE, unten_frei = FALSE;
7295 boolean links_frei = FALSE, rechts_frei = FALSE;
7296 boolean oben_massiv = FALSE, unten_massiv = FALSE;
7297 boolean links_massiv = FALSE, rechts_massiv = FALSE;
7298 boolean new_wall = FALSE;
7300 if (IS_ANIMATED(graphic))
7301 DrawLevelGraphicAnimationIfNeeded(ax, ay, graphic);
7303 if (!MovDelay[ax][ay]) /* start building new wall */
7304 MovDelay[ax][ay] = 6;
7306 if (MovDelay[ax][ay]) /* wait some time before building new wall */
7309 if (MovDelay[ax][ay])
7313 if (IN_LEV_FIELD(ax, ay-1) && IS_FREE(ax, ay-1))
7315 if (IN_LEV_FIELD(ax, ay+1) && IS_FREE(ax, ay+1))
7317 if (IN_LEV_FIELD(ax-1, ay) && IS_FREE(ax-1, ay))
7319 if (IN_LEV_FIELD(ax+1, ay) && IS_FREE(ax+1, ay))
7322 if (element == EL_EXPANDABLE_WALL_VERTICAL ||
7323 element == EL_EXPANDABLE_WALL_ANY)
7327 Feld[ax][ay-1] = EL_EXPANDABLE_WALL_GROWING;
7328 Store[ax][ay-1] = element;
7329 GfxDir[ax][ay-1] = MovDir[ax][ay-1] = MV_UP;
7330 if (IN_SCR_FIELD(SCREENX(ax), SCREENY(ay-1)))
7331 DrawGraphic(SCREENX(ax), SCREENY(ay - 1),
7332 IMG_EXPANDABLE_WALL_GROWING_UP, 0);
7337 Feld[ax][ay+1] = EL_EXPANDABLE_WALL_GROWING;
7338 Store[ax][ay+1] = element;
7339 GfxDir[ax][ay+1] = MovDir[ax][ay+1] = MV_DOWN;
7340 if (IN_SCR_FIELD(SCREENX(ax), SCREENY(ay+1)))
7341 DrawGraphic(SCREENX(ax), SCREENY(ay + 1),
7342 IMG_EXPANDABLE_WALL_GROWING_DOWN, 0);
7347 if (element == EL_EXPANDABLE_WALL_HORIZONTAL ||
7348 element == EL_EXPANDABLE_WALL_ANY ||
7349 element == EL_EXPANDABLE_WALL)
7353 Feld[ax-1][ay] = EL_EXPANDABLE_WALL_GROWING;
7354 Store[ax-1][ay] = element;
7355 GfxDir[ax-1][ay] = MovDir[ax-1][ay] = MV_LEFT;
7356 if (IN_SCR_FIELD(SCREENX(ax-1), SCREENY(ay)))
7357 DrawGraphic(SCREENX(ax - 1), SCREENY(ay),
7358 IMG_EXPANDABLE_WALL_GROWING_LEFT, 0);
7364 Feld[ax+1][ay] = EL_EXPANDABLE_WALL_GROWING;
7365 Store[ax+1][ay] = element;
7366 GfxDir[ax+1][ay] = MovDir[ax+1][ay] = MV_RIGHT;
7367 if (IN_SCR_FIELD(SCREENX(ax+1), SCREENY(ay)))
7368 DrawGraphic(SCREENX(ax + 1), SCREENY(ay),
7369 IMG_EXPANDABLE_WALL_GROWING_RIGHT, 0);
7374 if (element == EL_EXPANDABLE_WALL && (links_frei || rechts_frei))
7375 DrawLevelField(ax, ay);
7377 if (!IN_LEV_FIELD(ax, ay-1) || IS_WALL(Feld[ax][ay-1]))
7379 if (!IN_LEV_FIELD(ax, ay+1) || IS_WALL(Feld[ax][ay+1]))
7380 unten_massiv = TRUE;
7381 if (!IN_LEV_FIELD(ax-1, ay) || IS_WALL(Feld[ax-1][ay]))
7382 links_massiv = TRUE;
7383 if (!IN_LEV_FIELD(ax+1, ay) || IS_WALL(Feld[ax+1][ay]))
7384 rechts_massiv = TRUE;
7386 if (((oben_massiv && unten_massiv) ||
7387 element == EL_EXPANDABLE_WALL_HORIZONTAL ||
7388 element == EL_EXPANDABLE_WALL) &&
7389 ((links_massiv && rechts_massiv) ||
7390 element == EL_EXPANDABLE_WALL_VERTICAL))
7391 Feld[ax][ay] = EL_WALL;
7394 PlayLevelSoundAction(ax, ay, ACTION_GROWING);
7397 void CheckForDragon(int x, int y)
7400 boolean dragon_found = FALSE;
7401 static int xy[4][2] =
7409 for (i = 0; i < NUM_DIRECTIONS; i++)
7411 for (j = 0; j < 4; j++)
7413 int xx = x + j * xy[i][0], yy = y + j * xy[i][1];
7415 if (IN_LEV_FIELD(xx, yy) &&
7416 (Feld[xx][yy] == EL_FLAMES || Feld[xx][yy] == EL_DRAGON))
7418 if (Feld[xx][yy] == EL_DRAGON)
7419 dragon_found = TRUE;
7428 for (i = 0; i < NUM_DIRECTIONS; i++)
7430 for (j = 0; j < 3; j++)
7432 int xx = x + j * xy[i][0], yy = y + j * xy[i][1];
7434 if (IN_LEV_FIELD(xx, yy) && Feld[xx][yy] == EL_FLAMES)
7436 Feld[xx][yy] = EL_EMPTY;
7437 DrawLevelField(xx, yy);
7446 static void InitBuggyBase(int x, int y)
7448 int element = Feld[x][y];
7449 int activating_delay = FRAMES_PER_SECOND / 4;
7452 (element == EL_SP_BUGGY_BASE ?
7453 2 * FRAMES_PER_SECOND + RND(5 * FRAMES_PER_SECOND) - activating_delay :
7454 element == EL_SP_BUGGY_BASE_ACTIVATING ?
7456 element == EL_SP_BUGGY_BASE_ACTIVE ?
7457 1 * FRAMES_PER_SECOND + RND(1 * FRAMES_PER_SECOND) : 1);
7460 static void WarnBuggyBase(int x, int y)
7463 static int xy[4][2] =
7471 for (i = 0; i < NUM_DIRECTIONS; i++)
7473 int xx = x + xy[i][0];
7474 int yy = y + xy[i][1];
7476 if (IN_LEV_FIELD(xx, yy) && IS_PLAYER(xx, yy))
7478 PlayLevelSound(x, y, SND_SP_BUGGY_BASE_ACTIVE);
7485 static void InitTrap(int x, int y)
7487 ChangeDelay[x][y] = 2 * FRAMES_PER_SECOND + RND(5 * FRAMES_PER_SECOND);
7490 static void ActivateTrap(int x, int y)
7492 PlayLevelSound(x, y, SND_TRAP_ACTIVATING);
7495 static void ChangeActiveTrap(int x, int y)
7497 int graphic = IMG_TRAP_ACTIVE;
7499 /* if new animation frame was drawn, correct crumbled sand border */
7500 if (IS_NEW_FRAME(GfxFrame[x][y], graphic))
7501 DrawLevelFieldCrumbledSand(x, y);
7504 static int getSpecialActionElement(int element, int number, int base_element)
7506 return (element != EL_EMPTY ? element :
7507 number != -1 ? base_element + number - 1 :
7511 static int getModifiedActionNumber(int value_old, int operator, int operand,
7512 int value_min, int value_max)
7514 int value_new = (operator == CA_MODE_SET ? operand :
7515 operator == CA_MODE_ADD ? value_old + operand :
7516 operator == CA_MODE_SUBTRACT ? value_old - operand :
7517 operator == CA_MODE_MULTIPLY ? value_old * operand :
7518 operator == CA_MODE_DIVIDE ? value_old / MAX(1, operand) :
7519 operator == CA_MODE_MODULO ? value_old % MAX(1, operand) :
7522 return (value_new < value_min ? value_min :
7523 value_new > value_max ? value_max :
7527 static void ExecuteCustomElementAction(int x, int y, int element, int page)
7529 struct ElementInfo *ei = &element_info[element];
7530 struct ElementChangeInfo *change = &ei->change_page[page];
7531 int action_type = change->action_type;
7532 int action_mode = change->action_mode;
7533 int action_arg = change->action_arg;
7536 if (!change->has_action)
7539 /* ---------- determine action paramater values -------------------------- */
7541 int level_time_value =
7542 (level.time > 0 ? TimeLeft :
7545 int action_arg_element =
7546 (action_arg == CA_ARG_PLAYER_TRIGGER ? change->actual_trigger_player :
7547 action_arg == CA_ARG_ELEMENT_TRIGGER ? change->actual_trigger_element :
7548 action_arg == CA_ARG_ELEMENT_TARGET ? change->target_element :
7551 int action_arg_direction =
7552 (action_arg >= CA_ARG_DIRECTION_LEFT &&
7553 action_arg <= CA_ARG_DIRECTION_DOWN ? action_arg - CA_ARG_DIRECTION :
7554 action_arg == CA_ARG_DIRECTION_TRIGGER ?
7555 change->actual_trigger_side :
7556 action_arg == CA_ARG_DIRECTION_TRIGGER_BACK ?
7557 MV_DIR_OPPOSITE(change->actual_trigger_side) :
7560 int action_arg_number_min =
7561 (action_type == CA_SET_PLAYER_SPEED ? STEPSIZE_NOT_MOVING :
7564 int action_arg_number_max =
7565 (action_type == CA_SET_PLAYER_SPEED ? STEPSIZE_EVEN_FASTER :
7566 action_type == CA_SET_LEVEL_GEMS ? 999 :
7567 action_type == CA_SET_LEVEL_TIME ? 9999 :
7568 action_type == CA_SET_LEVEL_SCORE ? 99999 :
7569 action_type == CA_SET_CE_SCORE ? 9999 :
7570 action_type == CA_SET_CE_VALUE ? 9999 :
7573 int action_arg_number_reset =
7574 (action_type == CA_SET_PLAYER_SPEED ? level.initial_player_stepsize :
7575 action_type == CA_SET_LEVEL_GEMS ? level.gems_needed :
7576 action_type == CA_SET_LEVEL_TIME ? level.time :
7577 action_type == CA_SET_LEVEL_SCORE ? 0 :
7578 action_type == CA_SET_CE_SCORE ? 0 :
7580 action_type == CA_SET_CE_VALUE ? GET_NEW_CUSTOM_VALUE(element) :
7582 action_type == CA_SET_CE_VALUE ? ei->custom_value_initial :
7586 int action_arg_number =
7587 (action_arg <= CA_ARG_MAX ? action_arg :
7588 action_arg >= CA_ARG_SPEED_NOT_MOVING &&
7589 action_arg <= CA_ARG_SPEED_EVEN_FASTER ? (action_arg - CA_ARG_SPEED) :
7590 action_arg == CA_ARG_SPEED_RESET ? action_arg_number_reset :
7591 action_arg == CA_ARG_NUMBER_MIN ? action_arg_number_min :
7592 action_arg == CA_ARG_NUMBER_MAX ? action_arg_number_max :
7593 action_arg == CA_ARG_NUMBER_RESET ? action_arg_number_reset :
7594 action_arg == CA_ARG_NUMBER_CE_SCORE ? ei->collect_score :
7595 #if USE_NEW_CUSTOM_VALUE
7596 action_arg == CA_ARG_NUMBER_CE_VALUE ? CustomValue[x][y] :
7598 action_arg == CA_ARG_NUMBER_CE_VALUE ? ei->custom_value_initial :
7600 action_arg == CA_ARG_NUMBER_CE_DELAY ? GET_CE_DELAY_VALUE(change) :
7601 action_arg == CA_ARG_NUMBER_LEVEL_TIME ? level_time_value :
7602 action_arg == CA_ARG_NUMBER_LEVEL_GEMS ? local_player->gems_still_needed :
7603 action_arg == CA_ARG_NUMBER_LEVEL_SCORE ? local_player->score :
7604 action_arg == CA_ARG_ELEMENT_CV_TARGET ? GET_NEW_CUSTOM_VALUE(change->target_element) :
7605 action_arg == CA_ARG_ELEMENT_CV_TRIGGER ? change->actual_trigger_ce_value:
7606 action_arg == CA_ARG_ELEMENT_NR_TARGET ? change->target_element :
7607 action_arg == CA_ARG_ELEMENT_NR_TRIGGER ? change->actual_trigger_element :
7610 int action_arg_number_old =
7611 (action_type == CA_SET_LEVEL_GEMS ? local_player->gems_still_needed :
7612 action_type == CA_SET_LEVEL_TIME ? TimeLeft :
7613 action_type == CA_SET_LEVEL_SCORE ? local_player->score :
7614 action_type == CA_SET_CE_SCORE ? ei->collect_score :
7615 action_type == CA_SET_CE_VALUE ? CustomValue[x][y] :
7618 int action_arg_number_new =
7619 getModifiedActionNumber(action_arg_number_old,
7620 action_mode, action_arg_number,
7621 action_arg_number_min, action_arg_number_max);
7623 int trigger_player_bits =
7624 (change->actual_trigger_player >= EL_PLAYER_1 &&
7625 change->actual_trigger_player <= EL_PLAYER_4 ?
7626 (1 << (change->actual_trigger_player - EL_PLAYER_1)) :
7629 int action_arg_player_bits =
7630 (action_arg >= CA_ARG_PLAYER_1 &&
7631 action_arg <= CA_ARG_PLAYER_4 ? action_arg - CA_ARG_PLAYER :
7632 action_arg == CA_ARG_PLAYER_TRIGGER ? trigger_player_bits :
7635 /* ---------- execute action -------------------------------------------- */
7644 /* ---------- level actions ------------------------------------------- */
7646 case CA_RESTART_LEVEL:
7648 game.restart_level = TRUE;
7653 case CA_SHOW_ENVELOPE:
7655 int element = getSpecialActionElement(action_arg_element,
7656 action_arg_number, EL_ENVELOPE_1);
7658 if (IS_ENVELOPE(element))
7659 local_player->show_envelope = element;
7664 case CA_SET_LEVEL_TIME:
7666 if (level.time > 0) /* only modify limited time value */
7668 TimeLeft = action_arg_number_new;
7670 DrawGameValue_Time(TimeLeft);
7672 if (!TimeLeft && setup.time_limit)
7673 for (i = 0; i < MAX_PLAYERS; i++)
7674 KillPlayer(&stored_player[i]);
7680 case CA_SET_LEVEL_SCORE:
7682 local_player->score = action_arg_number_new;
7684 DrawGameValue_Score(local_player->score);
7689 case CA_SET_LEVEL_GEMS:
7691 local_player->gems_still_needed = action_arg_number_new;
7693 DrawGameValue_Emeralds(local_player->gems_still_needed);
7698 case CA_SET_LEVEL_GRAVITY:
7700 game.gravity = (action_arg == CA_ARG_GRAVITY_OFF ? FALSE :
7701 action_arg == CA_ARG_GRAVITY_ON ? TRUE :
7702 action_arg == CA_ARG_GRAVITY_TOGGLE ? !game.gravity :
7707 case CA_SET_LEVEL_WIND:
7709 game.wind_direction = action_arg_direction;
7714 /* ---------- player actions ------------------------------------------ */
7716 case CA_MOVE_PLAYER:
7718 /* automatically move to the next field in specified direction */
7719 for (i = 0; i < MAX_PLAYERS; i++)
7720 if (trigger_player_bits & (1 << i))
7721 stored_player[i].programmed_action = action_arg_direction;
7726 case CA_EXIT_PLAYER:
7728 for (i = 0; i < MAX_PLAYERS; i++)
7729 if (action_arg_player_bits & (1 << i))
7730 stored_player[i].LevelSolved = stored_player[i].GameOver = TRUE;
7735 case CA_KILL_PLAYER:
7737 for (i = 0; i < MAX_PLAYERS; i++)
7738 if (action_arg_player_bits & (1 << i))
7739 KillPlayer(&stored_player[i]);
7744 case CA_SET_PLAYER_KEYS:
7746 int key_state = (action_mode == CA_MODE_ADD ? TRUE : FALSE);
7747 int element = getSpecialActionElement(action_arg_element,
7748 action_arg_number, EL_KEY_1);
7750 if (IS_KEY(element))
7752 for (i = 0; i < MAX_PLAYERS; i++)
7754 if (trigger_player_bits & (1 << i))
7756 stored_player[i].key[KEY_NR(element)] = key_state;
7758 DrawGameValue_Keys(stored_player[i].key);
7760 redraw_mask |= REDRAW_DOOR_1;
7768 case CA_SET_PLAYER_SPEED:
7770 for (i = 0; i < MAX_PLAYERS; i++)
7772 if (trigger_player_bits & (1 << i))
7774 int move_stepsize = TILEX / stored_player[i].move_delay_value;
7776 if (action_arg == CA_ARG_SPEED_FASTER &&
7777 stored_player[i].cannot_move)
7779 action_arg_number = STEPSIZE_VERY_SLOW;
7781 else if (action_arg == CA_ARG_SPEED_SLOWER ||
7782 action_arg == CA_ARG_SPEED_FASTER)
7784 action_arg_number = 2;
7785 action_mode = (action_arg == CA_ARG_SPEED_SLOWER ? CA_MODE_DIVIDE :
7790 getModifiedActionNumber(move_stepsize,
7793 action_arg_number_min,
7794 action_arg_number_max);
7797 SetPlayerMoveSpeed(&stored_player[i], move_stepsize, FALSE);
7799 /* make sure that value is power of 2 */
7800 move_stepsize = (1 << log_2(move_stepsize));
7802 /* do no immediately change -- the player might just be moving */
7803 stored_player[i].move_delay_value_next = TILEX / move_stepsize;
7805 stored_player[i].cannot_move =
7806 (action_arg == CA_ARG_SPEED_NOT_MOVING ? TRUE : FALSE);
7814 case CA_SET_PLAYER_SHIELD:
7816 for (i = 0; i < MAX_PLAYERS; i++)
7818 if (trigger_player_bits & (1 << i))
7820 if (action_arg == CA_ARG_SHIELD_OFF)
7822 stored_player[i].shield_normal_time_left = 0;
7823 stored_player[i].shield_deadly_time_left = 0;
7825 else if (action_arg == CA_ARG_SHIELD_NORMAL)
7827 stored_player[i].shield_normal_time_left = 999999;
7829 else if (action_arg == CA_ARG_SHIELD_DEADLY)
7831 stored_player[i].shield_normal_time_left = 999999;
7832 stored_player[i].shield_deadly_time_left = 999999;
7840 case CA_SET_PLAYER_ARTWORK:
7842 for (i = 0; i < MAX_PLAYERS; i++)
7844 if (trigger_player_bits & (1 << i))
7846 int artwork_element = action_arg_element;
7848 if (action_arg == CA_ARG_ELEMENT_RESET)
7850 (level.use_artwork_element[i] ? level.artwork_element[i] :
7851 stored_player[i].element_nr);
7853 stored_player[i].artwork_element = artwork_element;
7855 SetPlayerWaiting(&stored_player[i], FALSE);
7857 /* set number of special actions for bored and sleeping animation */
7858 stored_player[i].num_special_action_bored =
7859 get_num_special_action(artwork_element,
7860 ACTION_BORING_1, ACTION_BORING_LAST);
7861 stored_player[i].num_special_action_sleeping =
7862 get_num_special_action(artwork_element,
7863 ACTION_SLEEPING_1, ACTION_SLEEPING_LAST);
7870 /* ---------- CE actions ---------------------------------------------- */
7872 case CA_SET_CE_SCORE:
7874 ei->collect_score = action_arg_number_new;
7879 case CA_SET_CE_VALUE:
7881 #if USE_NEW_CUSTOM_VALUE
7882 int last_custom_value = CustomValue[x][y];
7884 CustomValue[x][y] = action_arg_number_new;
7887 printf("::: Count == %d\n", CustomValue[x][y]);
7890 if (CustomValue[x][y] == 0 && last_custom_value > 0)
7893 printf("::: CE_VALUE_GETS_ZERO\n");
7896 CheckElementChange(x, y, element, EL_UNDEFINED, CE_VALUE_GETS_ZERO);
7897 CheckTriggeredElementChange(x, y, element, CE_VALUE_GETS_ZERO_OF_X);
7900 printf("::: RESULT: %d, %d\n", Feld[x][y], ChangePage[x][y]);
7908 /* ---------- engine actions ------------------------------------------ */
7910 case CA_SET_ENGINE_SCAN_MODE:
7912 InitPlayfieldScanMode(action_arg);
7922 static void CreateFieldExt(int x, int y, int element, boolean is_change)
7924 int previous_move_direction = MovDir[x][y];
7925 #if USE_NEW_CUSTOM_VALUE
7926 int last_ce_value = CustomValue[x][y];
7928 boolean add_player = (ELEM_IS_PLAYER(element) &&
7929 IS_WALKABLE(Feld[x][y]));
7931 /* check if element under player changes from accessible to unaccessible
7932 (needed for special case of dropping element which then changes) */
7933 if (IS_PLAYER(x, y) && !PLAYER_EXPLOSION_PROTECTED(x, y) &&
7934 IS_ACCESSIBLE(Feld[x][y]) && !IS_ACCESSIBLE(element))
7943 if (IS_MOVING(x, y) || IS_BLOCKED(x, y))
7944 RemoveMovingField(x, y);
7948 Feld[x][y] = element;
7950 ResetGfxAnimation(x, y);
7951 ResetRandomAnimationValue(x, y);
7953 if (element_info[Feld[x][y]].move_direction_initial == MV_START_PREVIOUS)
7954 MovDir[x][y] = previous_move_direction;
7956 #if USE_NEW_CUSTOM_VALUE
7957 if (element_info[Feld[x][y]].use_last_ce_value)
7958 CustomValue[x][y] = last_ce_value;
7961 InitField_WithBug1(x, y, FALSE);
7963 DrawLevelField(x, y);
7965 if (GFX_CRUMBLED(Feld[x][y]))
7966 DrawLevelFieldCrumbledSandNeighbours(x, y);
7969 /* "ChangeCount" not set yet to allow "entered by player" change one time */
7970 if (ELEM_IS_PLAYER(element))
7971 RelocatePlayer(x, y, element);
7974 ChangeCount[x][y]++; /* count number of changes in the same frame */
7976 TestIfBadThingTouchesPlayer(x, y);
7977 TestIfPlayerTouchesCustomElement(x, y);
7978 TestIfElementTouchesCustomElement(x, y);
7981 static void CreateField(int x, int y, int element)
7983 CreateFieldExt(x, y, element, FALSE);
7986 static void CreateElementFromChange(int x, int y, int element)
7988 element = GET_VALID_RUNTIME_ELEMENT(element);
7990 #if USE_STOP_CHANGED_ELEMENTS
7991 if (game.engine_version >= VERSION_IDENT(3,2,0,7))
7993 int old_element = Feld[x][y];
7995 /* prevent changed element from moving in same engine frame
7996 unless both old and new element can either fall or move */
7997 if ((!CAN_FALL(old_element) || !CAN_FALL(element)) &&
7998 (!CAN_MOVE(old_element) || !CAN_MOVE(element)))
8003 CreateFieldExt(x, y, element, TRUE);
8006 static boolean ChangeElement(int x, int y, int element, int page)
8008 struct ElementChangeInfo *change = &element_info[element].change_page[page];
8010 int old_element = Feld[x][y];
8012 /* always use default change event to prevent running into a loop */
8013 if (ChangeEvent[x][y] == -1)
8014 ChangeEvent[x][y] = CE_DELAY;
8016 if (ChangeEvent[x][y] == CE_DELAY)
8018 /* reset actual trigger element, trigger player and action element */
8019 change->actual_trigger_element = EL_EMPTY;
8020 change->actual_trigger_player = EL_PLAYER_1;
8021 change->actual_trigger_side = CH_SIDE_NONE;
8022 change->actual_trigger_ce_value = 0;
8025 /* do not change elements more than a specified maximum number of changes */
8026 if (ChangeCount[x][y] >= game.max_num_changes_per_frame)
8029 ChangeCount[x][y]++; /* count number of changes in the same frame */
8031 if (change->explode)
8038 if (change->use_target_content)
8040 boolean complete_replace = TRUE;
8041 boolean can_replace[3][3];
8044 for (yy = 0; yy < 3; yy++) for (xx = 0; xx < 3 ; xx++)
8047 boolean is_walkable;
8048 boolean is_diggable;
8049 boolean is_collectible;
8050 boolean is_removable;
8051 boolean is_destructible;
8052 int ex = x + xx - 1;
8053 int ey = y + yy - 1;
8054 int content_element = change->target_content.e[xx][yy];
8057 can_replace[xx][yy] = TRUE;
8059 if (ex == x && ey == y) /* do not check changing element itself */
8062 if (content_element == EL_EMPTY_SPACE)
8064 can_replace[xx][yy] = FALSE; /* do not replace border with space */
8069 if (!IN_LEV_FIELD(ex, ey))
8071 can_replace[xx][yy] = FALSE;
8072 complete_replace = FALSE;
8079 if (IS_MOVING(ex, ey) || IS_BLOCKED(ex, ey))
8080 e = MovingOrBlocked2Element(ex, ey);
8082 is_empty = (IS_FREE(ex, ey) ||
8083 (IS_FREE_OR_PLAYER(ex, ey) && IS_WALKABLE(content_element)));
8085 is_walkable = (is_empty || IS_WALKABLE(e));
8086 is_diggable = (is_empty || IS_DIGGABLE(e));
8087 is_collectible = (is_empty || IS_COLLECTIBLE(e));
8088 is_destructible = (is_empty || !IS_INDESTRUCTIBLE(e));
8089 is_removable = (is_diggable || is_collectible);
8091 can_replace[xx][yy] =
8092 (((change->replace_when == CP_WHEN_EMPTY && is_empty) ||
8093 (change->replace_when == CP_WHEN_WALKABLE && is_walkable) ||
8094 (change->replace_when == CP_WHEN_DIGGABLE && is_diggable) ||
8095 (change->replace_when == CP_WHEN_COLLECTIBLE && is_collectible) ||
8096 (change->replace_when == CP_WHEN_REMOVABLE && is_removable) ||
8097 (change->replace_when == CP_WHEN_DESTRUCTIBLE && is_destructible)) &&
8098 !(IS_PLAYER(ex, ey) && ELEM_IS_PLAYER(content_element)));
8100 if (!can_replace[xx][yy])
8101 complete_replace = FALSE;
8104 if (!change->only_if_complete || complete_replace)
8106 boolean something_has_changed = FALSE;
8108 if (change->only_if_complete && change->use_random_replace &&
8109 RND(100) < change->random_percentage)
8112 for (yy = 0; yy < 3; yy++) for (xx = 0; xx < 3 ; xx++)
8114 int ex = x + xx - 1;
8115 int ey = y + yy - 1;
8116 int content_element;
8118 if (can_replace[xx][yy] && (!change->use_random_replace ||
8119 RND(100) < change->random_percentage))
8121 if (IS_MOVING(ex, ey) || IS_BLOCKED(ex, ey))
8122 RemoveMovingField(ex, ey);
8124 ChangeEvent[ex][ey] = ChangeEvent[x][y];
8126 content_element = change->target_content.e[xx][yy];
8127 target_element = GET_TARGET_ELEMENT(content_element, change);
8129 CreateElementFromChange(ex, ey, target_element);
8131 something_has_changed = TRUE;
8133 /* for symmetry reasons, freeze newly created border elements */
8134 if (ex != x || ey != y)
8135 Stop[ex][ey] = TRUE; /* no more moving in this frame */
8139 if (something_has_changed)
8141 PlayLevelSoundElementAction(x, y, element, ACTION_CHANGING);
8142 PlayLevelSoundElementAction(x, y, element, ACTION_PAGE_1 + page);
8148 target_element = GET_TARGET_ELEMENT(change->target_element, change);
8150 if (element == EL_DIAGONAL_GROWING ||
8151 element == EL_DIAGONAL_SHRINKING)
8153 target_element = Store[x][y];
8155 Store[x][y] = EL_EMPTY;
8158 CreateElementFromChange(x, y, target_element);
8160 PlayLevelSoundElementAction(x, y, element, ACTION_CHANGING);
8161 PlayLevelSoundElementAction(x, y, element, ACTION_PAGE_1 + page);
8164 /* this uses direct change before indirect change */
8165 CheckTriggeredElementChangeByPage(x, y, old_element, CE_CHANGE_OF_X, page);
8170 #if USE_NEW_DELAYED_ACTION
8172 static void HandleElementChange(int x, int y, int page)
8174 int element = MovingOrBlocked2Element(x, y);
8175 struct ElementInfo *ei = &element_info[element];
8176 struct ElementChangeInfo *change = &ei->change_page[page];
8179 if (!CAN_CHANGE_OR_HAS_ACTION(element) &&
8180 !CAN_CHANGE_OR_HAS_ACTION(Back[x][y]))
8183 printf("HandleElementChange(): %d,%d: element = %d ('%s')\n",
8184 x, y, element, element_info[element].token_name);
8185 printf("HandleElementChange(): This should never happen!\n");
8190 /* this can happen with classic bombs on walkable, changing elements */
8191 if (!CAN_CHANGE_OR_HAS_ACTION(element))
8194 if (!CAN_CHANGE(Back[x][y])) /* prevent permanent repetition */
8195 ChangeDelay[x][y] = 0;
8201 if (ChangeDelay[x][y] == 0) /* initialize element change */
8203 ChangeDelay[x][y] = GET_CHANGE_DELAY(change) + 1;
8205 if (change->can_change)
8207 ResetGfxAnimation(x, y);
8208 ResetRandomAnimationValue(x, y);
8210 if (change->pre_change_function)
8211 change->pre_change_function(x, y);
8215 ChangeDelay[x][y]--;
8217 if (ChangeDelay[x][y] != 0) /* continue element change */
8219 if (change->can_change)
8221 int graphic = el_act_dir2img(element, GfxAction[x][y], GfxDir[x][y]);
8223 if (IS_ANIMATED(graphic))
8224 DrawLevelGraphicAnimationIfNeeded(x, y, graphic);
8226 if (change->change_function)
8227 change->change_function(x, y);
8230 else /* finish element change */
8232 if (ChangePage[x][y] != -1) /* remember page from delayed change */
8234 page = ChangePage[x][y];
8235 ChangePage[x][y] = -1;
8237 change = &ei->change_page[page];
8240 if (IS_MOVING(x, y)) /* never change a running system ;-) */
8242 ChangeDelay[x][y] = 1; /* try change after next move step */
8243 ChangePage[x][y] = page; /* remember page to use for change */
8248 if (change->can_change)
8250 if (ChangeElement(x, y, element, page))
8252 if (change->post_change_function)
8253 change->post_change_function(x, y);
8257 if (change->has_action)
8258 ExecuteCustomElementAction(x, y, element, page);
8264 static void HandleElementChange(int x, int y, int page)
8266 int element = MovingOrBlocked2Element(x, y);
8267 struct ElementInfo *ei = &element_info[element];
8268 struct ElementChangeInfo *change = &ei->change_page[page];
8271 if (!CAN_CHANGE(element) && !CAN_CHANGE(Back[x][y]))
8274 printf("HandleElementChange(): %d,%d: element = %d ('%s')\n",
8275 x, y, element, element_info[element].token_name);
8276 printf("HandleElementChange(): This should never happen!\n");
8281 /* this can happen with classic bombs on walkable, changing elements */
8282 if (!CAN_CHANGE(element))
8285 if (!CAN_CHANGE(Back[x][y])) /* prevent permanent repetition */
8286 ChangeDelay[x][y] = 0;
8292 if (ChangeDelay[x][y] == 0) /* initialize element change */
8294 ChangeDelay[x][y] = GET_CHANGE_DELAY(change) + 1;
8296 ResetGfxAnimation(x, y);
8297 ResetRandomAnimationValue(x, y);
8299 if (change->pre_change_function)
8300 change->pre_change_function(x, y);
8303 ChangeDelay[x][y]--;
8305 if (ChangeDelay[x][y] != 0) /* continue element change */
8307 int graphic = el_act_dir2img(element, GfxAction[x][y], GfxDir[x][y]);
8309 if (IS_ANIMATED(graphic))
8310 DrawLevelGraphicAnimationIfNeeded(x, y, graphic);
8312 if (change->change_function)
8313 change->change_function(x, y);
8315 else /* finish element change */
8317 if (ChangePage[x][y] != -1) /* remember page from delayed change */
8319 page = ChangePage[x][y];
8320 ChangePage[x][y] = -1;
8322 change = &ei->change_page[page];
8325 if (IS_MOVING(x, y)) /* never change a running system ;-) */
8327 ChangeDelay[x][y] = 1; /* try change after next move step */
8328 ChangePage[x][y] = page; /* remember page to use for change */
8333 if (ChangeElement(x, y, element, page))
8335 if (change->post_change_function)
8336 change->post_change_function(x, y);
8343 static boolean CheckTriggeredElementChangeExt(int trigger_x, int trigger_y,
8344 int trigger_element,
8350 boolean change_done_any = FALSE;
8351 int trigger_page_bits = (trigger_page < 0 ? CH_PAGE_ANY : 1 << trigger_page);
8354 if (!(trigger_events[trigger_element][trigger_event]))
8357 for (i = 0; i < NUM_CUSTOM_ELEMENTS; i++)
8359 int element = EL_CUSTOM_START + i;
8360 boolean change_done = FALSE;
8363 if (!CAN_CHANGE_OR_HAS_ACTION(element) ||
8364 !HAS_ANY_CHANGE_EVENT(element, trigger_event))
8367 for (p = 0; p < element_info[element].num_change_pages; p++)
8369 struct ElementChangeInfo *change = &element_info[element].change_page[p];
8371 if (change->can_change_or_has_action &&
8372 change->has_event[trigger_event] &&
8373 change->trigger_side & trigger_side &&
8374 change->trigger_player & trigger_player &&
8375 change->trigger_page & trigger_page_bits &&
8376 IS_EQUAL_OR_IN_GROUP(trigger_element, change->trigger_element))
8378 change->actual_trigger_element = trigger_element;
8379 change->actual_trigger_player = EL_PLAYER_1 + log_2(trigger_player);
8380 change->actual_trigger_side = trigger_side;
8381 change->actual_trigger_ce_value = CustomValue[trigger_x][trigger_y];
8383 if ((change->can_change && !change_done) || change->has_action)
8388 SCAN_PLAYFIELD(x, y)
8390 for (y = 0; y < lev_fieldy; y++) for (x = 0; x < lev_fieldx; x++)
8393 if (Feld[x][y] == element)
8395 if (change->can_change && !change_done)
8397 ChangeDelay[x][y] = 1;
8398 ChangeEvent[x][y] = trigger_event;
8400 HandleElementChange(x, y, p);
8402 #if USE_NEW_DELAYED_ACTION
8403 else if (change->has_action)
8405 ExecuteCustomElementAction(x, y, element, p);
8406 PlayLevelSoundElementAction(x, y, element, ACTION_PAGE_1 + p);
8409 if (change->has_action)
8411 ExecuteCustomElementAction(x, y, element, p);
8412 PlayLevelSoundElementAction(x, y, element, ACTION_PAGE_1 + p);
8418 if (change->can_change)
8421 change_done_any = TRUE;
8428 return change_done_any;
8431 static boolean CheckElementChangeExt(int x, int y,
8433 int trigger_element,
8438 boolean change_done = FALSE;
8441 if (!CAN_CHANGE_OR_HAS_ACTION(element) ||
8442 !HAS_ANY_CHANGE_EVENT(element, trigger_event))
8445 if (Feld[x][y] == EL_BLOCKED)
8447 Blocked2Moving(x, y, &x, &y);
8448 element = Feld[x][y];
8452 /* check if element has already changed */
8453 if (Feld[x][y] != element)
8456 /* check if element has already changed or is about to change after moving */
8457 if ((game.engine_version < VERSION_IDENT(3,2,0,7) &&
8458 Feld[x][y] != element) ||
8460 (game.engine_version >= VERSION_IDENT(3,2,0,7) &&
8461 (ChangeCount[x][y] >= game.max_num_changes_per_frame ||
8462 ChangePage[x][y] != -1)))
8466 for (p = 0; p < element_info[element].num_change_pages; p++)
8468 struct ElementChangeInfo *change = &element_info[element].change_page[p];
8470 boolean check_trigger_element =
8471 (trigger_event == CE_TOUCHING_X ||
8472 trigger_event == CE_HITTING_X ||
8473 trigger_event == CE_HIT_BY_X);
8475 if (change->can_change_or_has_action &&
8476 change->has_event[trigger_event] &&
8477 change->trigger_side & trigger_side &&
8478 change->trigger_player & trigger_player &&
8479 (!check_trigger_element ||
8480 IS_EQUAL_OR_IN_GROUP(trigger_element, change->trigger_element)))
8482 change->actual_trigger_element = trigger_element;
8483 change->actual_trigger_player = EL_PLAYER_1 + log_2(trigger_player);
8484 change->actual_trigger_side = trigger_side;
8485 change->actual_trigger_ce_value = CustomValue[x][y];
8487 /* special case: trigger element not at (x,y) position for some events */
8488 if (check_trigger_element)
8500 { 0, 0 }, { 0, 0 }, { 0, 0 },
8504 int xx = x + move_xy[MV_DIR_OPPOSITE(trigger_side)].dx;
8505 int yy = y + move_xy[MV_DIR_OPPOSITE(trigger_side)].dy;
8507 change->actual_trigger_ce_value = CustomValue[xx][yy];
8510 if (change->can_change && !change_done)
8512 ChangeDelay[x][y] = 1;
8513 ChangeEvent[x][y] = trigger_event;
8515 HandleElementChange(x, y, p);
8519 #if USE_NEW_DELAYED_ACTION
8520 else if (change->has_action)
8522 ExecuteCustomElementAction(x, y, element, p);
8523 PlayLevelSoundElementAction(x, y, element, ACTION_PAGE_1 + p);
8526 if (change->has_action)
8528 ExecuteCustomElementAction(x, y, element, p);
8529 PlayLevelSoundElementAction(x, y, element, ACTION_PAGE_1 + p);
8538 static void PlayPlayerSound(struct PlayerInfo *player)
8540 int jx = player->jx, jy = player->jy;
8541 int sound_element = player->artwork_element;
8542 int last_action = player->last_action_waiting;
8543 int action = player->action_waiting;
8545 if (player->is_waiting)
8547 if (action != last_action)
8548 PlayLevelSoundElementAction(jx, jy, sound_element, action);
8550 PlayLevelSoundElementActionIfLoop(jx, jy, sound_element, action);
8554 if (action != last_action)
8555 StopSound(element_info[sound_element].sound[last_action]);
8557 if (last_action == ACTION_SLEEPING)
8558 PlayLevelSoundElementAction(jx, jy, sound_element, ACTION_AWAKENING);
8562 static void PlayAllPlayersSound()
8566 for (i = 0; i < MAX_PLAYERS; i++)
8567 if (stored_player[i].active)
8568 PlayPlayerSound(&stored_player[i]);
8571 static void SetPlayerWaiting(struct PlayerInfo *player, boolean is_waiting)
8573 boolean last_waiting = player->is_waiting;
8574 int move_dir = player->MovDir;
8576 player->last_action_waiting = player->action_waiting;
8580 if (!last_waiting) /* not waiting -> waiting */
8582 player->is_waiting = TRUE;
8584 player->frame_counter_bored =
8586 game.player_boring_delay_fixed +
8587 SimpleRND(game.player_boring_delay_random);
8588 player->frame_counter_sleeping =
8590 game.player_sleeping_delay_fixed +
8591 SimpleRND(game.player_sleeping_delay_random);
8593 InitPlayerGfxAnimation(player, ACTION_WAITING, player->MovDir);
8596 if (game.player_sleeping_delay_fixed +
8597 game.player_sleeping_delay_random > 0 &&
8598 player->anim_delay_counter == 0 &&
8599 player->post_delay_counter == 0 &&
8600 FrameCounter >= player->frame_counter_sleeping)
8601 player->is_sleeping = TRUE;
8602 else if (game.player_boring_delay_fixed +
8603 game.player_boring_delay_random > 0 &&
8604 FrameCounter >= player->frame_counter_bored)
8605 player->is_bored = TRUE;
8607 player->action_waiting = (player->is_sleeping ? ACTION_SLEEPING :
8608 player->is_bored ? ACTION_BORING :
8611 if (player->is_sleeping)
8613 if (player->num_special_action_sleeping > 0)
8615 if (player->anim_delay_counter == 0 && player->post_delay_counter == 0)
8617 int last_special_action = player->special_action_sleeping;
8618 int num_special_action = player->num_special_action_sleeping;
8619 int special_action =
8620 (last_special_action == ACTION_DEFAULT ? ACTION_SLEEPING_1 :
8621 last_special_action == ACTION_SLEEPING ? ACTION_SLEEPING :
8622 last_special_action < ACTION_SLEEPING_1 + num_special_action - 1 ?
8623 last_special_action + 1 : ACTION_SLEEPING);
8624 int special_graphic =
8625 el_act_dir2img(player->artwork_element, special_action, move_dir);
8627 player->anim_delay_counter =
8628 graphic_info[special_graphic].anim_delay_fixed +
8629 SimpleRND(graphic_info[special_graphic].anim_delay_random);
8630 player->post_delay_counter =
8631 graphic_info[special_graphic].post_delay_fixed +
8632 SimpleRND(graphic_info[special_graphic].post_delay_random);
8634 player->special_action_sleeping = special_action;
8637 if (player->anim_delay_counter > 0)
8639 player->action_waiting = player->special_action_sleeping;
8640 player->anim_delay_counter--;
8642 else if (player->post_delay_counter > 0)
8644 player->post_delay_counter--;
8648 else if (player->is_bored)
8650 if (player->num_special_action_bored > 0)
8652 if (player->anim_delay_counter == 0 && player->post_delay_counter == 0)
8654 int special_action =
8655 ACTION_BORING_1 + SimpleRND(player->num_special_action_bored);
8656 int special_graphic =
8657 el_act_dir2img(player->artwork_element, special_action, move_dir);
8659 player->anim_delay_counter =
8660 graphic_info[special_graphic].anim_delay_fixed +
8661 SimpleRND(graphic_info[special_graphic].anim_delay_random);
8662 player->post_delay_counter =
8663 graphic_info[special_graphic].post_delay_fixed +
8664 SimpleRND(graphic_info[special_graphic].post_delay_random);
8666 player->special_action_bored = special_action;
8669 if (player->anim_delay_counter > 0)
8671 player->action_waiting = player->special_action_bored;
8672 player->anim_delay_counter--;
8674 else if (player->post_delay_counter > 0)
8676 player->post_delay_counter--;
8681 else if (last_waiting) /* waiting -> not waiting */
8683 player->is_waiting = FALSE;
8684 player->is_bored = FALSE;
8685 player->is_sleeping = FALSE;
8687 player->frame_counter_bored = -1;
8688 player->frame_counter_sleeping = -1;
8690 player->anim_delay_counter = 0;
8691 player->post_delay_counter = 0;
8693 player->action_waiting = ACTION_DEFAULT;
8695 player->special_action_bored = ACTION_DEFAULT;
8696 player->special_action_sleeping = ACTION_DEFAULT;
8700 static byte PlayerActions(struct PlayerInfo *player, byte player_action)
8702 boolean moved = FALSE, snapped = FALSE, dropped = FALSE;
8703 int left = player_action & JOY_LEFT;
8704 int right = player_action & JOY_RIGHT;
8705 int up = player_action & JOY_UP;
8706 int down = player_action & JOY_DOWN;
8707 int button1 = player_action & JOY_BUTTON_1;
8708 int button2 = player_action & JOY_BUTTON_2;
8709 int dx = (left ? -1 : right ? 1 : 0);
8710 int dy = (up ? -1 : down ? 1 : 0);
8712 if (!player->active || tape.pausing)
8718 snapped = SnapField(player, dx, dy);
8722 dropped = DropElement(player);
8724 moved = MovePlayer(player, dx, dy);
8727 if (tape.single_step && tape.recording && !tape.pausing)
8729 if (button1 || (dropped && !moved))
8731 TapeTogglePause(TAPE_TOGGLE_AUTOMATIC);
8732 SnapField(player, 0, 0); /* stop snapping */
8736 SetPlayerWaiting(player, FALSE);
8738 return player_action;
8742 /* no actions for this player (no input at player's configured device) */
8744 DigField(player, 0, 0, 0, 0, 0, 0, DF_NO_PUSH);
8745 SnapField(player, 0, 0);
8746 CheckGravityMovementWhenNotMoving(player);
8748 if (player->MovPos == 0)
8749 SetPlayerWaiting(player, TRUE);
8751 if (player->MovPos == 0) /* needed for tape.playing */
8752 player->is_moving = FALSE;
8754 player->is_dropping = FALSE;
8760 void AdvanceFrameAndPlayerCounters(int player_nr)
8764 /* advance frame counters (global frame counter and time frame counter) */
8768 /* advance player counters (counters for move delay, move animation etc.) */
8769 for (i = 0; i < MAX_PLAYERS; i++)
8771 boolean advance_player_counters = (player_nr == -1 || player_nr == i);
8772 int move_delay_value = stored_player[i].move_delay_value;
8773 int move_frames = MOVE_DELAY_NORMAL_SPEED / move_delay_value;
8775 if (!advance_player_counters) /* not all players may be affected */
8778 #if USE_NEW_PLAYER_ANIM
8779 if (move_frames == 0) /* less than one move per game frame */
8781 int stepsize = TILEX / move_delay_value;
8782 int delay = move_delay_value / MOVE_DELAY_NORMAL_SPEED;
8783 int count = (stored_player[i].is_moving ?
8784 ABS(stored_player[i].MovPos) / stepsize : FrameCounter);
8786 if (count % delay == 0)
8791 stored_player[i].Frame += move_frames;
8793 if (stored_player[i].MovPos != 0)
8794 stored_player[i].StepFrame += move_frames;
8796 if (stored_player[i].move_delay > 0)
8797 stored_player[i].move_delay--;
8799 /* due to bugs in previous versions, counter must count up, not down */
8800 if (stored_player[i].push_delay != -1)
8801 stored_player[i].push_delay++;
8803 if (stored_player[i].drop_delay > 0)
8804 stored_player[i].drop_delay--;
8810 static unsigned long game_frame_delay = 0;
8811 unsigned long game_frame_delay_value;
8812 int magic_wall_x = 0, magic_wall_y = 0;
8813 int i, x, y, element, graphic;
8814 byte *recorded_player_action;
8815 byte summarized_player_action = 0;
8816 byte tape_action[MAX_PLAYERS];
8818 if (game_status != GAME_MODE_PLAYING)
8821 game_frame_delay_value =
8822 (tape.playing && tape.fast_forward ? FfwdFrameDelay : GameFrameDelay);
8824 if (tape.playing && tape.warp_forward && !tape.pausing)
8825 game_frame_delay_value = 0;
8827 /* ---------- main game synchronization point ---------- */
8829 WaitUntilDelayReached(&game_frame_delay, game_frame_delay_value);
8831 InitPlayfieldScanModeVars();
8833 if (ScreenMovPos == 0) /* screen currently aligned at tile position */
8835 struct PlayerInfo *player;
8836 int player_nr = game.centered_player_nr_next;
8838 if (game.centered_player_nr_next == -1)
8839 player_nr = local_player->index_nr;
8841 player = &stored_player[player_nr];
8843 if (!player->active)
8844 game.centered_player_nr_next = game.centered_player_nr;
8846 if (game.centered_player_nr != game.centered_player_nr_next)
8848 DrawRelocatePlayer(player, setup.quick_switch);
8850 game.centered_player_nr = game.centered_player_nr_next;
8854 #if USE_ONE_MORE_CHANGE_PER_FRAME
8855 if (game.engine_version >= VERSION_IDENT(3,2,0,7))
8857 SCAN_PLAYFIELD(x, y)
8859 ChangeCount[x][y] = 0;
8860 ChangeEvent[x][y] = -1;
8865 if (network_playing && !network_player_action_received)
8867 /* try to get network player actions in time */
8869 #if defined(NETWORK_AVALIABLE)
8870 /* last chance to get network player actions without main loop delay */
8874 /* game was quit by network peer */
8875 if (game_status != GAME_MODE_PLAYING)
8878 if (!network_player_action_received)
8879 return; /* failed to get network player actions in time */
8885 recorded_player_action = (tape.playing ? TapePlayAction() : NULL);
8888 /* !!! CHECK THIS (tape.pausing is always FALSE here!) !!! */
8889 if (recorded_player_action == NULL && tape.pausing)
8893 for (i = 0; i < MAX_PLAYERS; i++)
8895 summarized_player_action |= stored_player[i].action;
8897 if (!network_playing)
8898 stored_player[i].effective_action = stored_player[i].action;
8901 #if defined(NETWORK_AVALIABLE)
8902 if (network_playing)
8903 SendToServer_MovePlayer(summarized_player_action);
8906 if (!options.network && !setup.team_mode)
8907 local_player->effective_action = summarized_player_action;
8909 if (recorded_player_action != NULL)
8910 for (i = 0; i < MAX_PLAYERS; i++)
8911 stored_player[i].effective_action = recorded_player_action[i];
8913 for (i = 0; i < MAX_PLAYERS; i++)
8915 tape_action[i] = stored_player[i].effective_action;
8917 if (tape.recording && tape_action[i] && !tape.player_participates[i])
8918 tape.player_participates[i] = TRUE; /* player just appeared from CE */
8921 /* only save actions from input devices, but not programmed actions */
8923 TapeRecordAction(tape_action);
8925 for (i = 0; i < MAX_PLAYERS; i++)
8927 int actual_player_action = stored_player[i].effective_action;
8930 /* !!! THIS BREAKS THE FOLLOWING TAPES: !!!
8931 - rnd_equinox_tetrachloride 048
8932 - rnd_equinox_tetrachloride_ii 096
8933 - rnd_emanuel_schmieg 002
8934 - doctor_sloan_ww 001, 020
8936 if (stored_player[i].MovPos == 0)
8937 CheckGravityMovement(&stored_player[i]);
8940 /* overwrite programmed action with tape action */
8941 if (stored_player[i].programmed_action)
8942 actual_player_action = stored_player[i].programmed_action;
8945 PlayerActions(&stored_player[i], actual_player_action);
8947 tape_action[i] = PlayerActions(&stored_player[i], actual_player_action);
8949 if (tape.recording && tape_action[i] && !tape.player_participates[i])
8950 tape.player_participates[i] = TRUE; /* player just appeared from CE */
8953 ScrollPlayer(&stored_player[i], SCROLL_GO_ON);
8956 network_player_action_received = FALSE;
8958 ScrollScreen(NULL, SCROLL_GO_ON);
8960 /* for backwards compatibility, the following code emulates a fixed bug that
8961 occured when pushing elements (causing elements that just made their last
8962 pushing step to already (if possible) make their first falling step in the
8963 same game frame, which is bad); this code is also needed to use the famous
8964 "spring push bug" which is used in older levels and might be wanted to be
8965 used also in newer levels, but in this case the buggy pushing code is only
8966 affecting the "spring" element and no other elements */
8968 if (game.engine_version < VERSION_IDENT(2,2,0,7) || level.use_spring_bug)
8970 for (i = 0; i < MAX_PLAYERS; i++)
8972 struct PlayerInfo *player = &stored_player[i];
8976 if (player->active && player->is_pushing && player->is_moving &&
8978 (game.engine_version < VERSION_IDENT(2,2,0,7) ||
8979 Feld[x][y] == EL_SPRING))
8981 ContinueMoving(x, y);
8983 /* continue moving after pushing (this is actually a bug) */
8984 if (!IS_MOVING(x, y))
8993 SCAN_PLAYFIELD(x, y)
8995 for (y = 0; y < lev_fieldy; y++) for (x = 0; x < lev_fieldx; x++)
8998 ChangeCount[x][y] = 0;
8999 ChangeEvent[x][y] = -1;
9001 /* this must be handled before main playfield loop */
9002 if (Feld[x][y] == EL_PLAYER_IS_LEAVING)
9005 if (MovDelay[x][y] <= 0)
9009 #if USE_NEW_SNAP_DELAY
9010 if (Feld[x][y] == EL_ELEMENT_SNAPPING)
9013 if (MovDelay[x][y] <= 0)
9016 DrawLevelField(x, y);
9018 TestIfElementTouchesCustomElement(x, y); /* for empty space */
9024 if (ChangePage[x][y] != -1 && ChangeDelay[x][y] != 1)
9026 printf("GameActions(): x = %d, y = %d: ChangePage != -1\n", x, y);
9027 printf("GameActions(): This should never happen!\n");
9029 ChangePage[x][y] = -1;
9034 if (WasJustMoving[x][y] > 0)
9035 WasJustMoving[x][y]--;
9036 if (WasJustFalling[x][y] > 0)
9037 WasJustFalling[x][y]--;
9038 if (CheckCollision[x][y] > 0)
9039 CheckCollision[x][y]--;
9043 /* reset finished pushing action (not done in ContinueMoving() to allow
9044 continuous pushing animation for elements with zero push delay) */
9045 if (GfxAction[x][y] == ACTION_PUSHING && !IS_MOVING(x, y))
9047 ResetGfxAnimation(x, y);
9048 DrawLevelField(x, y);
9052 if (IS_BLOCKED(x, y))
9056 Blocked2Moving(x, y, &oldx, &oldy);
9057 if (!IS_MOVING(oldx, oldy))
9059 printf("GameActions(): (BLOCKED => MOVING) context corrupted!\n");
9060 printf("GameActions(): BLOCKED: x = %d, y = %d\n", x, y);
9061 printf("GameActions(): !MOVING: oldx = %d, oldy = %d\n", oldx, oldy);
9062 printf("GameActions(): This should never happen!\n");
9069 SCAN_PLAYFIELD(x, y)
9071 for (y = 0; y < lev_fieldy; y++) for (x = 0; x < lev_fieldx; x++)
9074 element = Feld[x][y];
9075 graphic = el_act_dir2img(element, GfxAction[x][y], GfxDir[x][y]);
9078 printf("::: %d,%d\n", x, y);
9080 if (element == EL_ROCK)
9081 printf("::: Yo man! Rocks can fall!\n");
9084 if (graphic_info[graphic].anim_global_sync)
9085 GfxFrame[x][y] = FrameCounter;
9086 else if (ANIM_MODE(graphic) == ANIM_CE_VALUE)
9088 int old_gfx_frame = GfxFrame[x][y];
9090 GfxFrame[x][y] = CustomValue[x][y];
9093 if (GfxFrame[x][y] != old_gfx_frame)
9095 DrawLevelGraphicAnimation(x, y, graphic);
9097 else if (ANIM_MODE(graphic) == ANIM_CE_SCORE)
9099 int old_gfx_frame = GfxFrame[x][y];
9101 GfxFrame[x][y] = element_info[element].collect_score;
9104 if (GfxFrame[x][y] != old_gfx_frame)
9106 DrawLevelGraphicAnimation(x, y, graphic);
9109 if (ANIM_MODE(graphic) == ANIM_RANDOM &&
9110 IS_NEXT_FRAME(GfxFrame[x][y], graphic))
9111 ResetRandomAnimationValue(x, y);
9113 SetRandomAnimationValue(x, y);
9115 PlayLevelSoundActionIfLoop(x, y, GfxAction[x][y]);
9117 if (IS_INACTIVE(element))
9119 if (IS_ANIMATED(graphic))
9120 DrawLevelGraphicAnimationIfNeeded(x, y, graphic);
9125 /* this may take place after moving, so 'element' may have changed */
9126 if (IS_CHANGING(x, y) &&
9127 (game.engine_version < VERSION_IDENT(3,0,7,1) || !Stop[x][y]))
9129 int page = element_info[element].event_page_nr[CE_DELAY];
9131 HandleElementChange(x, y, ChangePage[x][y] != -1 ? ChangePage[x][y] : page);
9135 printf("::: ChangeDelay == %d\n", ChangeDelay[x][y]);
9139 if (element == EL_CUSTOM_255)
9140 printf("::: ChangeDelay == %d\n", ChangeDelay[x][y]);
9144 HandleElementChange(x, y, page);
9146 if (CAN_CHANGE(element))
9147 HandleElementChange(x, y, page);
9149 if (HAS_ACTION(element))
9150 ExecuteCustomElementAction(x, y, element, page);
9155 element = Feld[x][y];
9156 graphic = el_act_dir2img(element, GfxAction[x][y], GfxDir[x][y]);
9159 if (!IS_MOVING(x, y) && (CAN_FALL(element) || CAN_MOVE(element)))
9163 element = Feld[x][y];
9164 graphic = el_act_dir2img(element, GfxAction[x][y], GfxDir[x][y]);
9166 if (IS_ANIMATED(graphic) &&
9169 DrawLevelGraphicAnimationIfNeeded(x, y, graphic);
9171 if (IS_GEM(element) || element == EL_SP_INFOTRON)
9172 EdelsteinFunkeln(x, y);
9174 else if ((element == EL_ACID ||
9175 element == EL_EXIT_OPEN ||
9176 element == EL_SP_EXIT_OPEN ||
9177 element == EL_SP_TERMINAL ||
9178 element == EL_SP_TERMINAL_ACTIVE ||
9179 element == EL_EXTRA_TIME ||
9180 element == EL_SHIELD_NORMAL ||
9181 element == EL_SHIELD_DEADLY) &&
9182 IS_ANIMATED(graphic))
9183 DrawLevelGraphicAnimationIfNeeded(x, y, graphic);
9184 else if (IS_MOVING(x, y))
9185 ContinueMoving(x, y);
9186 else if (IS_ACTIVE_BOMB(element))
9187 CheckDynamite(x, y);
9188 else if (element == EL_AMOEBA_GROWING)
9189 AmoebeWaechst(x, y);
9190 else if (element == EL_AMOEBA_SHRINKING)
9191 AmoebaDisappearing(x, y);
9193 #if !USE_NEW_AMOEBA_CODE
9194 else if (IS_AMOEBALIVE(element))
9195 AmoebeAbleger(x, y);
9198 else if (element == EL_GAME_OF_LIFE || element == EL_BIOMAZE)
9200 else if (element == EL_EXIT_CLOSED)
9202 else if (element == EL_SP_EXIT_CLOSED)
9204 else if (element == EL_EXPANDABLE_WALL_GROWING)
9206 else if (element == EL_EXPANDABLE_WALL ||
9207 element == EL_EXPANDABLE_WALL_HORIZONTAL ||
9208 element == EL_EXPANDABLE_WALL_VERTICAL ||
9209 element == EL_EXPANDABLE_WALL_ANY)
9211 else if (element == EL_FLAMES)
9212 CheckForDragon(x, y);
9213 else if (element == EL_EXPLOSION)
9214 ; /* drawing of correct explosion animation is handled separately */
9215 else if (element == EL_ELEMENT_SNAPPING ||
9216 element == EL_DIAGONAL_SHRINKING ||
9217 element == EL_DIAGONAL_GROWING)
9220 graphic = el_act_dir2img(GfxElement[x][y], GfxAction[x][y],GfxDir[x][y]);
9222 DrawLevelGraphicAnimationIfNeeded(x, y, graphic);
9225 else if (IS_ANIMATED(graphic) && !IS_CHANGING(x, y))
9226 DrawLevelGraphicAnimationIfNeeded(x, y, graphic);
9229 if (element == EL_CUSTOM_255 ||
9230 element == EL_CUSTOM_256)
9231 DrawLevelGraphicAnimation(x, y, graphic);
9234 if (IS_BELT_ACTIVE(element))
9235 PlayLevelSoundAction(x, y, ACTION_ACTIVE);
9237 if (game.magic_wall_active)
9239 int jx = local_player->jx, jy = local_player->jy;
9241 /* play the element sound at the position nearest to the player */
9242 if ((element == EL_MAGIC_WALL_FULL ||
9243 element == EL_MAGIC_WALL_ACTIVE ||
9244 element == EL_MAGIC_WALL_EMPTYING ||
9245 element == EL_BD_MAGIC_WALL_FULL ||
9246 element == EL_BD_MAGIC_WALL_ACTIVE ||
9247 element == EL_BD_MAGIC_WALL_EMPTYING) &&
9248 ABS(x-jx) + ABS(y-jy) < ABS(magic_wall_x-jx) + ABS(magic_wall_y-jy))
9256 #if USE_NEW_AMOEBA_CODE
9257 /* new experimental amoeba growth stuff */
9258 if (!(FrameCounter % 8))
9260 static unsigned long random = 1684108901;
9262 for (i = 0; i < level.amoeba_speed * 28 / 8; i++)
9264 x = RND(lev_fieldx);
9265 y = RND(lev_fieldy);
9266 element = Feld[x][y];
9268 if (!IS_PLAYER(x,y) &&
9269 (element == EL_EMPTY ||
9270 CAN_GROW_INTO(element) ||
9271 element == EL_QUICKSAND_EMPTY ||
9272 element == EL_ACID_SPLASH_LEFT ||
9273 element == EL_ACID_SPLASH_RIGHT))
9275 if ((IN_LEV_FIELD(x, y-1) && Feld[x][y-1] == EL_AMOEBA_WET) ||
9276 (IN_LEV_FIELD(x-1, y) && Feld[x-1][y] == EL_AMOEBA_WET) ||
9277 (IN_LEV_FIELD(x+1, y) && Feld[x+1][y] == EL_AMOEBA_WET) ||
9278 (IN_LEV_FIELD(x, y+1) && Feld[x][y+1] == EL_AMOEBA_WET))
9279 Feld[x][y] = EL_AMOEBA_DROP;
9282 random = random * 129 + 1;
9288 if (game.explosions_delayed)
9291 game.explosions_delayed = FALSE;
9294 SCAN_PLAYFIELD(x, y)
9296 for (y = 0; y < lev_fieldy; y++) for (x = 0; x < lev_fieldx; x++)
9299 element = Feld[x][y];
9301 if (ExplodeField[x][y])
9302 Explode(x, y, EX_PHASE_START, ExplodeField[x][y]);
9303 else if (element == EL_EXPLOSION)
9304 Explode(x, y, ExplodePhase[x][y], EX_TYPE_NORMAL);
9306 ExplodeField[x][y] = EX_TYPE_NONE;
9309 game.explosions_delayed = TRUE;
9312 if (game.magic_wall_active)
9314 if (!(game.magic_wall_time_left % 4))
9316 int element = Feld[magic_wall_x][magic_wall_y];
9318 if (element == EL_BD_MAGIC_WALL_FULL ||
9319 element == EL_BD_MAGIC_WALL_ACTIVE ||
9320 element == EL_BD_MAGIC_WALL_EMPTYING)
9321 PlayLevelSound(magic_wall_x, magic_wall_y, SND_BD_MAGIC_WALL_ACTIVE);
9323 PlayLevelSound(magic_wall_x, magic_wall_y, SND_MAGIC_WALL_ACTIVE);
9326 if (game.magic_wall_time_left > 0)
9328 game.magic_wall_time_left--;
9329 if (!game.magic_wall_time_left)
9332 SCAN_PLAYFIELD(x, y)
9334 for (y = 0; y < lev_fieldy; y++) for (x = 0; x < lev_fieldx; x++)
9337 element = Feld[x][y];
9339 if (element == EL_MAGIC_WALL_ACTIVE ||
9340 element == EL_MAGIC_WALL_FULL)
9342 Feld[x][y] = EL_MAGIC_WALL_DEAD;
9343 DrawLevelField(x, y);
9345 else if (element == EL_BD_MAGIC_WALL_ACTIVE ||
9346 element == EL_BD_MAGIC_WALL_FULL)
9348 Feld[x][y] = EL_BD_MAGIC_WALL_DEAD;
9349 DrawLevelField(x, y);
9353 game.magic_wall_active = FALSE;
9358 if (game.light_time_left > 0)
9360 game.light_time_left--;
9362 if (game.light_time_left == 0)
9363 RedrawAllLightSwitchesAndInvisibleElements();
9366 if (game.timegate_time_left > 0)
9368 game.timegate_time_left--;
9370 if (game.timegate_time_left == 0)
9371 CloseAllOpenTimegates();
9374 if (game.lenses_time_left > 0)
9376 game.lenses_time_left--;
9378 if (game.lenses_time_left == 0)
9379 RedrawAllInvisibleElementsForLenses();
9382 if (game.magnify_time_left > 0)
9384 game.magnify_time_left--;
9386 if (game.magnify_time_left == 0)
9387 RedrawAllInvisibleElementsForMagnifier();
9390 for (i = 0; i < MAX_PLAYERS; i++)
9392 struct PlayerInfo *player = &stored_player[i];
9394 if (SHIELD_ON(player))
9396 if (player->shield_deadly_time_left)
9397 PlayLevelSound(player->jx, player->jy, SND_SHIELD_DEADLY_ACTIVE);
9398 else if (player->shield_normal_time_left)
9399 PlayLevelSound(player->jx, player->jy, SND_SHIELD_NORMAL_ACTIVE);
9403 if (TimeFrames >= FRAMES_PER_SECOND)
9408 for (i = 0; i < MAX_PLAYERS; i++)
9410 struct PlayerInfo *player = &stored_player[i];
9412 if (SHIELD_ON(player))
9414 player->shield_normal_time_left--;
9416 if (player->shield_deadly_time_left > 0)
9417 player->shield_deadly_time_left--;
9421 if (!level.use_step_counter)
9429 if (TimeLeft <= 10 && setup.time_limit)
9430 PlaySoundStereo(SND_GAME_RUNNING_OUT_OF_TIME, SOUND_MIDDLE);
9432 DrawGameValue_Time(TimeLeft);
9434 if (!TimeLeft && setup.time_limit)
9435 for (i = 0; i < MAX_PLAYERS; i++)
9436 KillPlayer(&stored_player[i]);
9438 else if (level.time == 0 && !AllPlayersGone) /* level w/o time limit */
9439 DrawGameValue_Time(TimePlayed);
9442 if (tape.recording || tape.playing)
9443 DrawVideoDisplay(VIDEO_STATE_TIME_ON, TapeTime);
9447 PlayAllPlayersSound();
9449 if (options.debug) /* calculate frames per second */
9451 static unsigned long fps_counter = 0;
9452 static int fps_frames = 0;
9453 unsigned long fps_delay_ms = Counter() - fps_counter;
9457 if (fps_delay_ms >= 500) /* calculate fps every 0.5 seconds */
9459 global.frames_per_second = 1000 * (float)fps_frames / fps_delay_ms;
9462 fps_counter = Counter();
9465 redraw_mask |= REDRAW_FPS;
9468 AdvanceFrameAndPlayerCounters(-1); /* advance counters for all players */
9470 if (local_player->show_envelope != 0 && local_player->MovPos == 0)
9472 ShowEnvelope(local_player->show_envelope - EL_ENVELOPE_1);
9474 local_player->show_envelope = 0;
9477 /* use random number generator in every frame to make it less predictable */
9478 if (game.engine_version >= VERSION_IDENT(3,1,1,0))
9482 static boolean AllPlayersInSight(struct PlayerInfo *player, int x, int y)
9484 int min_x = x, min_y = y, max_x = x, max_y = y;
9487 for (i = 0; i < MAX_PLAYERS; i++)
9489 int jx = stored_player[i].jx, jy = stored_player[i].jy;
9491 if (!stored_player[i].active || &stored_player[i] == player)
9494 min_x = MIN(min_x, jx);
9495 min_y = MIN(min_y, jy);
9496 max_x = MAX(max_x, jx);
9497 max_y = MAX(max_y, jy);
9500 return (max_x - min_x < SCR_FIELDX && max_y - min_y < SCR_FIELDY);
9503 static boolean AllPlayersInVisibleScreen()
9507 for (i = 0; i < MAX_PLAYERS; i++)
9509 int jx = stored_player[i].jx, jy = stored_player[i].jy;
9511 if (!stored_player[i].active)
9514 if (!IN_VIS_FIELD(SCREENX(jx), SCREENY(jy)))
9521 void ScrollLevel(int dx, int dy)
9523 int softscroll_offset = (setup.soft_scrolling ? TILEX : 0);
9526 BlitBitmap(drawto_field, drawto_field,
9527 FX + TILEX * (dx == -1) - softscroll_offset,
9528 FY + TILEY * (dy == -1) - softscroll_offset,
9529 SXSIZE - TILEX * (dx!=0) + 2 * softscroll_offset,
9530 SYSIZE - TILEY * (dy!=0) + 2 * softscroll_offset,
9531 FX + TILEX * (dx == 1) - softscroll_offset,
9532 FY + TILEY * (dy == 1) - softscroll_offset);
9536 x = (dx == 1 ? BX1 : BX2);
9537 for (y = BY1; y <= BY2; y++)
9538 DrawScreenField(x, y);
9543 y = (dy == 1 ? BY1 : BY2);
9544 for (x = BX1; x <= BX2; x++)
9545 DrawScreenField(x, y);
9548 redraw_mask |= REDRAW_FIELD;
9551 static boolean canFallDown(struct PlayerInfo *player)
9553 int jx = player->jx, jy = player->jy;
9555 return (IN_LEV_FIELD(jx, jy + 1) &&
9556 (IS_FREE(jx, jy + 1) ||
9557 (Feld[jx][jy + 1] == EL_ACID && player->can_fall_into_acid)) &&
9558 IS_WALKABLE_FROM(Feld[jx][jy], MV_DOWN) &&
9559 !IS_WALKABLE_INSIDE(Feld[jx][jy]));
9562 static boolean canPassField(int x, int y, int move_dir)
9564 int opposite_dir = MV_DIR_OPPOSITE(move_dir);
9565 int dx = (move_dir & MV_LEFT ? -1 : move_dir & MV_RIGHT ? +1 : 0);
9566 int dy = (move_dir & MV_UP ? -1 : move_dir & MV_DOWN ? +1 : 0);
9569 int element = Feld[x][y];
9571 return (IS_PASSABLE_FROM(element, opposite_dir) &&
9572 !CAN_MOVE(element) &&
9573 IN_LEV_FIELD(nextx, nexty) && !IS_PLAYER(nextx, nexty) &&
9574 IS_WALKABLE_FROM(Feld[nextx][nexty], move_dir) &&
9575 (level.can_pass_to_walkable || IS_FREE(nextx, nexty)));
9578 static boolean canMoveToValidFieldWithGravity(int x, int y, int move_dir)
9580 int opposite_dir = MV_DIR_OPPOSITE(move_dir);
9581 int dx = (move_dir & MV_LEFT ? -1 : move_dir & MV_RIGHT ? +1 : 0);
9582 int dy = (move_dir & MV_UP ? -1 : move_dir & MV_DOWN ? +1 : 0);
9586 return (IN_LEV_FIELD(newx, newy) && !IS_FREE_OR_PLAYER(newx, newy) &&
9587 IS_GRAVITY_REACHABLE(Feld[newx][newy]) &&
9588 (IS_DIGGABLE(Feld[newx][newy]) ||
9589 IS_WALKABLE_FROM(Feld[newx][newy], opposite_dir) ||
9590 canPassField(newx, newy, move_dir)));
9593 static void CheckGravityMovement(struct PlayerInfo *player)
9595 if (game.gravity && !player->programmed_action)
9597 int move_dir_horizontal = player->effective_action & MV_HORIZONTAL;
9598 int move_dir_vertical = player->effective_action & MV_VERTICAL;
9599 boolean player_is_snapping = player->effective_action & JOY_BUTTON_1;
9600 int jx = player->jx, jy = player->jy;
9601 boolean player_is_moving_to_valid_field =
9602 (!player_is_snapping &&
9603 (canMoveToValidFieldWithGravity(jx, jy, move_dir_horizontal) ||
9604 canMoveToValidFieldWithGravity(jx, jy, move_dir_vertical)));
9605 boolean player_can_fall_down = canFallDown(player);
9607 if (player_can_fall_down &&
9608 !player_is_moving_to_valid_field)
9609 player->programmed_action = MV_DOWN;
9613 static void CheckGravityMovementWhenNotMoving(struct PlayerInfo *player)
9615 return CheckGravityMovement(player);
9617 if (game.gravity && !player->programmed_action)
9619 int jx = player->jx, jy = player->jy;
9620 boolean field_under_player_is_free =
9621 (IN_LEV_FIELD(jx, jy + 1) && IS_FREE(jx, jy + 1));
9622 boolean player_is_standing_on_valid_field =
9623 (IS_WALKABLE_INSIDE(Feld[jx][jy]) ||
9624 (IS_WALKABLE(Feld[jx][jy]) &&
9625 !(element_info[Feld[jx][jy]].access_direction & MV_DOWN)));
9627 if (field_under_player_is_free && !player_is_standing_on_valid_field)
9628 player->programmed_action = MV_DOWN;
9634 -----------------------------------------------------------------------------
9635 dx, dy: direction (non-diagonal) to try to move the player to
9636 real_dx, real_dy: direction as read from input device (can be diagonal)
9639 boolean MovePlayerOneStep(struct PlayerInfo *player,
9640 int dx, int dy, int real_dx, int real_dy)
9642 int jx = player->jx, jy = player->jy;
9643 int new_jx = jx + dx, new_jy = jy + dy;
9644 #if !USE_FIXED_DONT_RUN_INTO
9648 boolean player_can_move = !player->cannot_move;
9650 if (!player->active || (!dx && !dy))
9651 return MP_NO_ACTION;
9653 player->MovDir = (dx < 0 ? MV_LEFT :
9656 dy > 0 ? MV_DOWN : MV_NONE);
9658 if (!IN_LEV_FIELD(new_jx, new_jy))
9659 return MP_NO_ACTION;
9661 if (!player_can_move)
9664 if (player->MovPos == 0)
9666 player->is_moving = FALSE;
9667 player->is_digging = FALSE;
9668 player->is_collecting = FALSE;
9669 player->is_snapping = FALSE;
9670 player->is_pushing = FALSE;
9673 DigField(player, 0, 0, 0, 0, 0, 0, DF_NO_PUSH);
9674 SnapField(player, 0, 0);
9678 return MP_NO_ACTION;
9683 if (!options.network && game.centered_player_nr == -1 &&
9684 !AllPlayersInSight(player, new_jx, new_jy))
9685 return MP_NO_ACTION;
9687 if (!options.network && !AllPlayersInSight(player, new_jx, new_jy))
9688 return MP_NO_ACTION;
9691 #if !USE_FIXED_DONT_RUN_INTO
9692 element = MovingOrBlocked2ElementIfNotLeaving(new_jx, new_jy);
9694 /* (moved to DigField()) */
9695 if (player_can_move && DONT_RUN_INTO(element))
9697 if (element == EL_ACID && dx == 0 && dy == 1)
9699 SplashAcid(new_jx, new_jy);
9700 Feld[jx][jy] = EL_PLAYER_1;
9701 InitMovingField(jx, jy, MV_DOWN);
9702 Store[jx][jy] = EL_ACID;
9703 ContinueMoving(jx, jy);
9707 TestIfPlayerRunsIntoBadThing(jx, jy, player->MovDir);
9713 can_move = DigField(player, jx, jy, new_jx, new_jy, real_dx,real_dy, DF_DIG);
9715 #if USE_FIXED_DONT_RUN_INTO
9716 if (can_move == MP_DONT_RUN_INTO)
9720 if (can_move != MP_MOVING)
9723 #if USE_FIXED_DONT_RUN_INTO
9726 /* check if DigField() has caused relocation of the player */
9727 if (player->jx != jx || player->jy != jy)
9728 return MP_NO_ACTION; /* <-- !!! CHECK THIS [-> MP_ACTION ?] !!! */
9730 StorePlayer[jx][jy] = 0;
9731 player->last_jx = jx;
9732 player->last_jy = jy;
9733 player->jx = new_jx;
9734 player->jy = new_jy;
9735 StorePlayer[new_jx][new_jy] = player->element_nr;
9737 if (player->move_delay_value_next != -1)
9739 player->move_delay_value = player->move_delay_value_next;
9740 player->move_delay_value_next = -1;
9744 (dx > 0 || dy > 0 ? -1 : 1) * (TILEX - TILEX / player->move_delay_value);
9746 player->step_counter++;
9748 PlayerVisit[jx][jy] = FrameCounter;
9750 ScrollPlayer(player, SCROLL_INIT);
9755 boolean MovePlayer(struct PlayerInfo *player, int dx, int dy)
9757 int jx = player->jx, jy = player->jy;
9758 int old_jx = jx, old_jy = jy;
9759 int moved = MP_NO_ACTION;
9761 if (!player->active)
9766 if (player->MovPos == 0)
9768 player->is_moving = FALSE;
9769 player->is_digging = FALSE;
9770 player->is_collecting = FALSE;
9771 player->is_snapping = FALSE;
9772 player->is_pushing = FALSE;
9778 if (player->move_delay > 0)
9781 player->move_delay = -1; /* set to "uninitialized" value */
9783 /* store if player is automatically moved to next field */
9784 player->is_auto_moving = (player->programmed_action != MV_NONE);
9786 /* remove the last programmed player action */
9787 player->programmed_action = 0;
9791 /* should only happen if pre-1.2 tape recordings are played */
9792 /* this is only for backward compatibility */
9794 int original_move_delay_value = player->move_delay_value;
9797 printf("THIS SHOULD ONLY HAPPEN WITH PRE-1.2 LEVEL TAPES. [%ld]\n",
9801 /* scroll remaining steps with finest movement resolution */
9802 player->move_delay_value = MOVE_DELAY_NORMAL_SPEED;
9804 while (player->MovPos)
9806 ScrollPlayer(player, SCROLL_GO_ON);
9807 ScrollScreen(NULL, SCROLL_GO_ON);
9809 AdvanceFrameAndPlayerCounters(player->index_nr);
9815 player->move_delay_value = original_move_delay_value;
9818 if (player->last_move_dir & MV_HORIZONTAL)
9820 if (!(moved |= MovePlayerOneStep(player, 0, dy, dx, dy)))
9821 moved |= MovePlayerOneStep(player, dx, 0, dx, dy);
9825 if (!(moved |= MovePlayerOneStep(player, dx, 0, dx, dy)))
9826 moved |= MovePlayerOneStep(player, 0, dy, dx, dy);
9833 if (moved & MP_MOVING && !ScreenMovPos &&
9834 (player->index_nr == game.centered_player_nr ||
9835 game.centered_player_nr == -1))
9837 if (moved & MP_MOVING && !ScreenMovPos &&
9838 (player == local_player || !options.network))
9841 int old_scroll_x = scroll_x, old_scroll_y = scroll_y;
9842 int offset = (setup.scroll_delay ? 3 : 0);
9844 if (!IN_VIS_FIELD(SCREENX(jx), SCREENY(jy)))
9846 /* actual player has left the screen -- scroll in that direction */
9847 if (jx != old_jx) /* player has moved horizontally */
9848 scroll_x += (jx - old_jx);
9849 else /* player has moved vertically */
9850 scroll_y += (jy - old_jy);
9854 if (jx != old_jx) /* player has moved horizontally */
9856 if ((player->MovDir == MV_LEFT && scroll_x > jx - MIDPOSX + offset) ||
9857 (player->MovDir == MV_RIGHT && scroll_x < jx - MIDPOSX - offset))
9858 scroll_x = jx-MIDPOSX + (scroll_x < jx-MIDPOSX ? -offset : +offset);
9860 /* don't scroll over playfield boundaries */
9861 if (scroll_x < SBX_Left || scroll_x > SBX_Right)
9862 scroll_x = (scroll_x < SBX_Left ? SBX_Left : SBX_Right);
9864 /* don't scroll more than one field at a time */
9865 scroll_x = old_scroll_x + SIGN(scroll_x - old_scroll_x);
9867 /* don't scroll against the player's moving direction */
9868 if ((player->MovDir == MV_LEFT && scroll_x > old_scroll_x) ||
9869 (player->MovDir == MV_RIGHT && scroll_x < old_scroll_x))
9870 scroll_x = old_scroll_x;
9872 else /* player has moved vertically */
9874 if ((player->MovDir == MV_UP && scroll_y > jy - MIDPOSY + offset) ||
9875 (player->MovDir == MV_DOWN && scroll_y < jy - MIDPOSY - offset))
9876 scroll_y = jy-MIDPOSY + (scroll_y < jy-MIDPOSY ? -offset : +offset);
9878 /* don't scroll over playfield boundaries */
9879 if (scroll_y < SBY_Upper || scroll_y > SBY_Lower)
9880 scroll_y = (scroll_y < SBY_Upper ? SBY_Upper : SBY_Lower);
9882 /* don't scroll more than one field at a time */
9883 scroll_y = old_scroll_y + SIGN(scroll_y - old_scroll_y);
9885 /* don't scroll against the player's moving direction */
9886 if ((player->MovDir == MV_UP && scroll_y > old_scroll_y) ||
9887 (player->MovDir == MV_DOWN && scroll_y < old_scroll_y))
9888 scroll_y = old_scroll_y;
9892 if (scroll_x != old_scroll_x || scroll_y != old_scroll_y)
9895 if (!options.network && game.centered_player_nr == -1 &&
9896 !AllPlayersInVisibleScreen())
9898 scroll_x = old_scroll_x;
9899 scroll_y = old_scroll_y;
9903 if (!options.network && !AllPlayersInVisibleScreen())
9905 scroll_x = old_scroll_x;
9906 scroll_y = old_scroll_y;
9911 ScrollScreen(player, SCROLL_INIT);
9912 ScrollLevel(old_scroll_x - scroll_x, old_scroll_y - scroll_y);
9917 player->StepFrame = 0;
9919 if (moved & MP_MOVING)
9921 if (old_jx != jx && old_jy == jy)
9922 player->MovDir = (old_jx < jx ? MV_RIGHT : MV_LEFT);
9923 else if (old_jx == jx && old_jy != jy)
9924 player->MovDir = (old_jy < jy ? MV_DOWN : MV_UP);
9926 DrawLevelField(jx, jy); /* for "crumbled sand" */
9928 player->last_move_dir = player->MovDir;
9929 player->is_moving = TRUE;
9930 player->is_snapping = FALSE;
9931 player->is_switching = FALSE;
9932 player->is_dropping = FALSE;
9936 CheckGravityMovementWhenNotMoving(player);
9938 player->is_moving = FALSE;
9940 /* at this point, the player is allowed to move, but cannot move right now
9941 (e.g. because of something blocking the way) -- ensure that the player
9942 is also allowed to move in the next frame (in old versions before 3.1.1,
9943 the player was forced to wait again for eight frames before next try) */
9945 if (game.engine_version >= VERSION_IDENT(3,1,1,0))
9946 player->move_delay = 0; /* allow direct movement in the next frame */
9949 if (player->move_delay == -1) /* not yet initialized by DigField() */
9950 player->move_delay = player->move_delay_value;
9952 if (game.engine_version < VERSION_IDENT(3,0,7,0))
9954 TestIfPlayerTouchesBadThing(jx, jy);
9955 TestIfPlayerTouchesCustomElement(jx, jy);
9958 if (!player->active)
9959 RemovePlayer(player);
9964 void ScrollPlayer(struct PlayerInfo *player, int mode)
9966 int jx = player->jx, jy = player->jy;
9967 int last_jx = player->last_jx, last_jy = player->last_jy;
9968 int move_stepsize = TILEX / player->move_delay_value;
9970 #if USE_NEW_PLAYER_SPEED
9971 if (!player->active)
9974 if (player->MovPos == 0 && mode == SCROLL_GO_ON) /* player not moving */
9977 if (!player->active || player->MovPos == 0)
9981 if (mode == SCROLL_INIT)
9983 player->actual_frame_counter = FrameCounter;
9984 player->GfxPos = move_stepsize * (player->MovPos / move_stepsize);
9986 if ((player->block_last_field || player->block_delay_adjustment > 0) &&
9987 Feld[last_jx][last_jy] == EL_EMPTY)
9989 int last_field_block_delay = 0; /* start with no blocking at all */
9990 int block_delay_adjustment = player->block_delay_adjustment;
9992 /* if player blocks last field, add delay for exactly one move */
9993 if (player->block_last_field)
9995 last_field_block_delay += player->move_delay_value;
9997 /* when blocking enabled, prevent moving up despite gravity */
9998 if (game.gravity && player->MovDir == MV_UP)
9999 block_delay_adjustment = -1;
10002 /* add block delay adjustment (also possible when not blocking) */
10003 last_field_block_delay += block_delay_adjustment;
10005 Feld[last_jx][last_jy] = EL_PLAYER_IS_LEAVING;
10006 MovDelay[last_jx][last_jy] = last_field_block_delay + 1;
10009 #if USE_NEW_PLAYER_SPEED
10010 if (player->MovPos != 0) /* player has not yet reached destination */
10016 else if (!FrameReached(&player->actual_frame_counter, 1))
10020 printf("::: player->MovPos: %d -> %d\n",
10022 player->MovPos + (player->MovPos > 0 ? -1 : 1) * move_stepsize);
10025 #if USE_NEW_PLAYER_SPEED
10026 if (player->MovPos != 0)
10028 player->MovPos += (player->MovPos > 0 ? -1 : 1) * move_stepsize;
10029 player->GfxPos = move_stepsize * (player->MovPos / move_stepsize);
10031 /* before DrawPlayer() to draw correct player graphic for this case */
10032 if (player->MovPos == 0)
10033 CheckGravityMovement(player);
10036 player->MovPos += (player->MovPos > 0 ? -1 : 1) * move_stepsize;
10037 player->GfxPos = move_stepsize * (player->MovPos / move_stepsize);
10039 /* before DrawPlayer() to draw correct player graphic for this case */
10040 if (player->MovPos == 0)
10041 CheckGravityMovement(player);
10044 if (player->MovPos == 0) /* player reached destination field */
10047 printf("::: player reached destination field\n");
10050 if (player->move_delay_reset_counter > 0)
10052 player->move_delay_reset_counter--;
10054 if (player->move_delay_reset_counter == 0)
10056 /* continue with normal speed after quickly moving through gate */
10057 HALVE_PLAYER_SPEED(player);
10059 /* be able to make the next move without delay */
10060 player->move_delay = 0;
10064 player->last_jx = jx;
10065 player->last_jy = jy;
10067 if (Feld[jx][jy] == EL_EXIT_OPEN ||
10068 Feld[jx][jy] == EL_SP_EXIT_OPEN ||
10069 Feld[jx][jy] == EL_SP_EXIT_OPENING) /* <-- special case */
10071 DrawPlayer(player); /* needed here only to cleanup last field */
10072 RemovePlayer(player);
10074 if (local_player->friends_still_needed == 0 ||
10075 IS_SP_ELEMENT(Feld[jx][jy]))
10076 player->LevelSolved = player->GameOver = TRUE;
10079 /* this breaks one level: "machine", level 000 */
10081 int move_direction = player->MovDir;
10082 int enter_side = MV_DIR_OPPOSITE(move_direction);
10083 int leave_side = move_direction;
10084 int old_jx = last_jx;
10085 int old_jy = last_jy;
10086 int old_element = Feld[old_jx][old_jy];
10087 int new_element = Feld[jx][jy];
10089 if (IS_CUSTOM_ELEMENT(old_element))
10090 CheckElementChangeByPlayer(old_jx, old_jy, old_element,
10092 player->index_bit, leave_side);
10094 CheckTriggeredElementChangeByPlayer(old_jx, old_jy, old_element,
10095 CE_PLAYER_LEAVES_X,
10096 player->index_bit, leave_side);
10098 if (IS_CUSTOM_ELEMENT(new_element))
10099 CheckElementChangeByPlayer(jx, jy, new_element, CE_ENTERED_BY_PLAYER,
10100 player->index_bit, enter_side);
10102 CheckTriggeredElementChangeByPlayer(jx, jy, new_element,
10103 CE_PLAYER_ENTERS_X,
10104 player->index_bit, enter_side);
10106 CheckTriggeredElementChangeBySide(jx, jy, player->element_nr,
10107 CE_MOVE_OF_X, move_direction);
10110 if (game.engine_version >= VERSION_IDENT(3,0,7,0))
10112 TestIfPlayerTouchesBadThing(jx, jy);
10113 TestIfPlayerTouchesCustomElement(jx, jy);
10115 /* needed because pushed element has not yet reached its destination,
10116 so it would trigger a change event at its previous field location */
10117 if (!player->is_pushing)
10118 TestIfElementTouchesCustomElement(jx, jy); /* for empty space */
10120 if (!player->active)
10121 RemovePlayer(player);
10124 if (level.use_step_counter)
10134 if (TimeLeft <= 10 && setup.time_limit)
10135 PlaySoundStereo(SND_GAME_RUNNING_OUT_OF_TIME, SOUND_MIDDLE);
10137 DrawGameValue_Time(TimeLeft);
10139 if (!TimeLeft && setup.time_limit)
10140 for (i = 0; i < MAX_PLAYERS; i++)
10141 KillPlayer(&stored_player[i]);
10143 else if (level.time == 0 && !AllPlayersGone) /* level w/o time limit */
10144 DrawGameValue_Time(TimePlayed);
10147 if (tape.single_step && tape.recording && !tape.pausing &&
10148 !player->programmed_action)
10149 TapeTogglePause(TAPE_TOGGLE_AUTOMATIC);
10153 void ScrollScreen(struct PlayerInfo *player, int mode)
10155 static unsigned long screen_frame_counter = 0;
10157 if (mode == SCROLL_INIT)
10159 /* set scrolling step size according to actual player's moving speed */
10160 ScrollStepSize = TILEX / player->move_delay_value;
10162 screen_frame_counter = FrameCounter;
10163 ScreenMovDir = player->MovDir;
10164 ScreenMovPos = player->MovPos;
10165 ScreenGfxPos = ScrollStepSize * (ScreenMovPos / ScrollStepSize);
10168 else if (!FrameReached(&screen_frame_counter, 1))
10173 ScreenMovPos += (ScreenMovPos > 0 ? -1 : 1) * ScrollStepSize;
10174 ScreenGfxPos = ScrollStepSize * (ScreenMovPos / ScrollStepSize);
10175 redraw_mask |= REDRAW_FIELD;
10178 ScreenMovDir = MV_NONE;
10181 void TestIfPlayerTouchesCustomElement(int x, int y)
10183 static int xy[4][2] =
10190 static int trigger_sides[4][2] =
10192 /* center side border side */
10193 { CH_SIDE_TOP, CH_SIDE_BOTTOM }, /* check top */
10194 { CH_SIDE_LEFT, CH_SIDE_RIGHT }, /* check left */
10195 { CH_SIDE_RIGHT, CH_SIDE_LEFT }, /* check right */
10196 { CH_SIDE_BOTTOM, CH_SIDE_TOP } /* check bottom */
10198 static int touch_dir[4] =
10200 MV_LEFT | MV_RIGHT,
10205 int center_element = Feld[x][y]; /* should always be non-moving! */
10208 for (i = 0; i < NUM_DIRECTIONS; i++)
10210 int xx = x + xy[i][0];
10211 int yy = y + xy[i][1];
10212 int center_side = trigger_sides[i][0];
10213 int border_side = trigger_sides[i][1];
10214 int border_element;
10216 if (!IN_LEV_FIELD(xx, yy))
10219 if (IS_PLAYER(x, y))
10221 struct PlayerInfo *player = PLAYERINFO(x, y);
10223 if (game.engine_version < VERSION_IDENT(3,0,7,0))
10224 border_element = Feld[xx][yy]; /* may be moving! */
10225 else if (!IS_MOVING(xx, yy) && !IS_BLOCKED(xx, yy))
10226 border_element = Feld[xx][yy];
10227 else if (MovDir[xx][yy] & touch_dir[i]) /* elements are touching */
10228 border_element = MovingOrBlocked2Element(xx, yy);
10230 continue; /* center and border element do not touch */
10232 CheckElementChangeByPlayer(xx, yy, border_element, CE_TOUCHED_BY_PLAYER,
10233 player->index_bit, border_side);
10234 CheckTriggeredElementChangeByPlayer(xx, yy, border_element,
10235 CE_PLAYER_TOUCHES_X,
10236 player->index_bit, border_side);
10238 else if (IS_PLAYER(xx, yy))
10240 struct PlayerInfo *player = PLAYERINFO(xx, yy);
10242 if (game.engine_version >= VERSION_IDENT(3,0,7,0))
10244 if (player->MovPos != 0 && !(player->MovDir & touch_dir[i]))
10245 continue; /* center and border element do not touch */
10248 CheckElementChangeByPlayer(x, y, center_element, CE_TOUCHED_BY_PLAYER,
10249 player->index_bit, center_side);
10250 CheckTriggeredElementChangeByPlayer(x, y, center_element,
10251 CE_PLAYER_TOUCHES_X,
10252 player->index_bit, center_side);
10258 #if USE_ELEMENT_TOUCHING_BUGFIX
10260 void TestIfElementTouchesCustomElement(int x, int y)
10262 static int xy[4][2] =
10269 static int trigger_sides[4][2] =
10271 /* center side border side */
10272 { CH_SIDE_TOP, CH_SIDE_BOTTOM }, /* check top */
10273 { CH_SIDE_LEFT, CH_SIDE_RIGHT }, /* check left */
10274 { CH_SIDE_RIGHT, CH_SIDE_LEFT }, /* check right */
10275 { CH_SIDE_BOTTOM, CH_SIDE_TOP } /* check bottom */
10277 static int touch_dir[4] =
10279 MV_LEFT | MV_RIGHT,
10284 boolean change_center_element = FALSE;
10285 int center_element = Feld[x][y]; /* should always be non-moving! */
10286 int border_element_old[NUM_DIRECTIONS];
10289 for (i = 0; i < NUM_DIRECTIONS; i++)
10291 int xx = x + xy[i][0];
10292 int yy = y + xy[i][1];
10293 int border_element;
10295 border_element_old[i] = -1;
10297 if (!IN_LEV_FIELD(xx, yy))
10300 if (game.engine_version < VERSION_IDENT(3,0,7,0))
10301 border_element = Feld[xx][yy]; /* may be moving! */
10302 else if (!IS_MOVING(xx, yy) && !IS_BLOCKED(xx, yy))
10303 border_element = Feld[xx][yy];
10304 else if (MovDir[xx][yy] & touch_dir[i]) /* elements are touching */
10305 border_element = MovingOrBlocked2Element(xx, yy);
10307 continue; /* center and border element do not touch */
10309 border_element_old[i] = border_element;
10312 for (i = 0; i < NUM_DIRECTIONS; i++)
10314 int xx = x + xy[i][0];
10315 int yy = y + xy[i][1];
10316 int center_side = trigger_sides[i][0];
10317 int border_element = border_element_old[i];
10319 if (border_element == -1)
10322 /* check for change of border element */
10323 CheckElementChangeBySide(xx, yy, border_element, center_element,
10324 CE_TOUCHING_X, center_side);
10327 for (i = 0; i < NUM_DIRECTIONS; i++)
10329 int border_side = trigger_sides[i][1];
10330 int border_element = border_element_old[i];
10332 if (border_element == -1)
10335 /* check for change of center element (but change it only once) */
10336 if (!change_center_element)
10337 change_center_element =
10338 CheckElementChangeBySide(x, y, center_element, border_element,
10339 CE_TOUCHING_X, border_side);
10345 void TestIfElementTouchesCustomElement_OLD(int x, int y)
10347 static int xy[4][2] =
10354 static int trigger_sides[4][2] =
10356 /* center side border side */
10357 { CH_SIDE_TOP, CH_SIDE_BOTTOM }, /* check top */
10358 { CH_SIDE_LEFT, CH_SIDE_RIGHT }, /* check left */
10359 { CH_SIDE_RIGHT, CH_SIDE_LEFT }, /* check right */
10360 { CH_SIDE_BOTTOM, CH_SIDE_TOP } /* check bottom */
10362 static int touch_dir[4] =
10364 MV_LEFT | MV_RIGHT,
10369 boolean change_center_element = FALSE;
10370 int center_element = Feld[x][y]; /* should always be non-moving! */
10373 for (i = 0; i < NUM_DIRECTIONS; i++)
10375 int xx = x + xy[i][0];
10376 int yy = y + xy[i][1];
10377 int center_side = trigger_sides[i][0];
10378 int border_side = trigger_sides[i][1];
10379 int border_element;
10381 if (!IN_LEV_FIELD(xx, yy))
10384 if (game.engine_version < VERSION_IDENT(3,0,7,0))
10385 border_element = Feld[xx][yy]; /* may be moving! */
10386 else if (!IS_MOVING(xx, yy) && !IS_BLOCKED(xx, yy))
10387 border_element = Feld[xx][yy];
10388 else if (MovDir[xx][yy] & touch_dir[i]) /* elements are touching */
10389 border_element = MovingOrBlocked2Element(xx, yy);
10391 continue; /* center and border element do not touch */
10393 /* check for change of center element (but change it only once) */
10394 if (!change_center_element)
10395 change_center_element =
10396 CheckElementChangeBySide(x, y, center_element, border_element,
10397 CE_TOUCHING_X, border_side);
10399 /* check for change of border element */
10400 CheckElementChangeBySide(xx, yy, border_element, center_element,
10401 CE_TOUCHING_X, center_side);
10407 void TestIfElementHitsCustomElement(int x, int y, int direction)
10409 int dx = (direction == MV_LEFT ? -1 : direction == MV_RIGHT ? +1 : 0);
10410 int dy = (direction == MV_UP ? -1 : direction == MV_DOWN ? +1 : 0);
10411 int hitx = x + dx, hity = y + dy;
10412 int hitting_element = Feld[x][y];
10413 int touched_element;
10415 if (IN_LEV_FIELD(hitx, hity) && IS_FREE(hitx, hity))
10418 touched_element = (IN_LEV_FIELD(hitx, hity) ?
10419 MovingOrBlocked2Element(hitx, hity) : EL_STEELWALL);
10421 if (IN_LEV_FIELD(hitx, hity))
10423 int opposite_direction = MV_DIR_OPPOSITE(direction);
10424 int hitting_side = direction;
10425 int touched_side = opposite_direction;
10426 boolean object_hit = (!IS_MOVING(hitx, hity) ||
10427 MovDir[hitx][hity] != direction ||
10428 ABS(MovPos[hitx][hity]) <= TILEY / 2);
10434 CheckElementChangeBySide(x, y, hitting_element, touched_element,
10435 CE_HITTING_X, touched_side);
10437 CheckElementChangeBySide(hitx, hity, touched_element,
10438 hitting_element, CE_HIT_BY_X, hitting_side);
10440 CheckElementChangeBySide(hitx, hity, touched_element, hitting_element,
10441 CE_HIT_BY_SOMETHING, opposite_direction);
10445 /* "hitting something" is also true when hitting the playfield border */
10446 CheckElementChangeBySide(x, y, hitting_element, touched_element,
10447 CE_HITTING_SOMETHING, direction);
10451 void TestIfElementSmashesCustomElement(int x, int y, int direction)
10453 int dx = (direction == MV_LEFT ? -1 : direction == MV_RIGHT ? +1 : 0);
10454 int dy = (direction == MV_UP ? -1 : direction == MV_DOWN ? +1 : 0);
10455 int hitx = x + dx, hity = y + dy;
10456 int hitting_element = Feld[x][y];
10457 int touched_element;
10459 boolean object_hit = (IN_LEV_FIELD(hitx, hity) &&
10460 !IS_FREE(hitx, hity) &&
10461 (!IS_MOVING(hitx, hity) ||
10462 MovDir[hitx][hity] != direction ||
10463 ABS(MovPos[hitx][hity]) <= TILEY / 2));
10466 if (IN_LEV_FIELD(hitx, hity) && IS_FREE(hitx, hity))
10470 if (IN_LEV_FIELD(hitx, hity) && !object_hit)
10474 touched_element = (IN_LEV_FIELD(hitx, hity) ?
10475 MovingOrBlocked2Element(hitx, hity) : EL_STEELWALL);
10477 CheckElementChangeBySide(x, y, hitting_element, touched_element,
10478 EP_CAN_SMASH_EVERYTHING, direction);
10480 if (IN_LEV_FIELD(hitx, hity))
10482 int opposite_direction = MV_DIR_OPPOSITE(direction);
10483 int hitting_side = direction;
10484 int touched_side = opposite_direction;
10486 int touched_element = MovingOrBlocked2Element(hitx, hity);
10489 boolean object_hit = (!IS_MOVING(hitx, hity) ||
10490 MovDir[hitx][hity] != direction ||
10491 ABS(MovPos[hitx][hity]) <= TILEY / 2);
10500 CheckElementChangeBySide(hitx, hity, touched_element, hitting_element,
10501 CE_SMASHED_BY_SOMETHING, opposite_direction);
10503 CheckElementChangeBySide(x, y, hitting_element, touched_element,
10504 CE_OTHER_IS_SMASHING, touched_side);
10506 CheckElementChangeBySide(hitx, hity, touched_element, hitting_element,
10507 CE_OTHER_GETS_SMASHED, hitting_side);
10513 void TestIfGoodThingHitsBadThing(int good_x, int good_y, int good_move_dir)
10515 int i, kill_x = -1, kill_y = -1;
10517 int bad_element = -1;
10518 static int test_xy[4][2] =
10525 static int test_dir[4] =
10533 for (i = 0; i < NUM_DIRECTIONS; i++)
10535 int test_x, test_y, test_move_dir, test_element;
10537 test_x = good_x + test_xy[i][0];
10538 test_y = good_y + test_xy[i][1];
10540 if (!IN_LEV_FIELD(test_x, test_y))
10544 (IS_MOVING(test_x, test_y) ? MovDir[test_x][test_y] : MV_NONE);
10546 test_element = MovingOrBlocked2ElementIfNotLeaving(test_x, test_y);
10548 /* 1st case: good thing is moving towards DONT_RUN_INTO style bad thing;
10549 2nd case: DONT_TOUCH style bad thing does not move away from good thing
10551 if ((DONT_RUN_INTO(test_element) && good_move_dir == test_dir[i]) ||
10552 (DONT_TOUCH(test_element) && test_move_dir != test_dir[i]))
10556 bad_element = test_element;
10562 if (kill_x != -1 || kill_y != -1)
10564 if (IS_PLAYER(good_x, good_y))
10566 struct PlayerInfo *player = PLAYERINFO(good_x, good_y);
10568 if (player->shield_deadly_time_left > 0 &&
10569 !IS_INDESTRUCTIBLE(bad_element))
10570 Bang(kill_x, kill_y);
10571 else if (!PLAYER_ENEMY_PROTECTED(good_x, good_y))
10572 KillPlayer(player);
10575 Bang(good_x, good_y);
10579 void TestIfBadThingHitsGoodThing(int bad_x, int bad_y, int bad_move_dir)
10581 int i, kill_x = -1, kill_y = -1;
10582 int bad_element = Feld[bad_x][bad_y];
10583 static int test_xy[4][2] =
10590 static int touch_dir[4] =
10592 MV_LEFT | MV_RIGHT,
10597 static int test_dir[4] =
10605 if (bad_element == EL_EXPLOSION) /* skip just exploding bad things */
10608 for (i = 0; i < NUM_DIRECTIONS; i++)
10610 int test_x, test_y, test_move_dir, test_element;
10612 test_x = bad_x + test_xy[i][0];
10613 test_y = bad_y + test_xy[i][1];
10614 if (!IN_LEV_FIELD(test_x, test_y))
10618 (IS_MOVING(test_x, test_y) ? MovDir[test_x][test_y] : MV_NONE);
10620 test_element = Feld[test_x][test_y];
10622 /* 1st case: good thing is moving towards DONT_RUN_INTO style bad thing;
10623 2nd case: DONT_TOUCH style bad thing does not move away from good thing
10625 if ((DONT_RUN_INTO(bad_element) && bad_move_dir == test_dir[i]) ||
10626 (DONT_TOUCH(bad_element) && test_move_dir != test_dir[i]))
10628 /* good thing is player or penguin that does not move away */
10629 if (IS_PLAYER(test_x, test_y))
10631 struct PlayerInfo *player = PLAYERINFO(test_x, test_y);
10633 if (bad_element == EL_ROBOT && player->is_moving)
10634 continue; /* robot does not kill player if he is moving */
10636 if (game.engine_version >= VERSION_IDENT(3,0,7,0))
10638 if (player->MovPos != 0 && !(player->MovDir & touch_dir[i]))
10639 continue; /* center and border element do not touch */
10646 else if (test_element == EL_PENGUIN)
10655 if (kill_x != -1 || kill_y != -1)
10657 if (IS_PLAYER(kill_x, kill_y))
10659 struct PlayerInfo *player = PLAYERINFO(kill_x, kill_y);
10661 if (player->shield_deadly_time_left > 0 &&
10662 !IS_INDESTRUCTIBLE(bad_element))
10663 Bang(bad_x, bad_y);
10664 else if (!PLAYER_ENEMY_PROTECTED(kill_x, kill_y))
10665 KillPlayer(player);
10668 Bang(kill_x, kill_y);
10672 void TestIfPlayerTouchesBadThing(int x, int y)
10674 TestIfGoodThingHitsBadThing(x, y, MV_NONE);
10677 void TestIfPlayerRunsIntoBadThing(int x, int y, int move_dir)
10679 TestIfGoodThingHitsBadThing(x, y, move_dir);
10682 void TestIfBadThingTouchesPlayer(int x, int y)
10684 TestIfBadThingHitsGoodThing(x, y, MV_NONE);
10687 void TestIfBadThingRunsIntoPlayer(int x, int y, int move_dir)
10689 TestIfBadThingHitsGoodThing(x, y, move_dir);
10692 void TestIfFriendTouchesBadThing(int x, int y)
10694 TestIfGoodThingHitsBadThing(x, y, MV_NONE);
10697 void TestIfBadThingTouchesFriend(int x, int y)
10699 TestIfBadThingHitsGoodThing(x, y, MV_NONE);
10702 void TestIfBadThingTouchesOtherBadThing(int bad_x, int bad_y)
10704 int i, kill_x = bad_x, kill_y = bad_y;
10705 static int xy[4][2] =
10713 for (i = 0; i < NUM_DIRECTIONS; i++)
10717 x = bad_x + xy[i][0];
10718 y = bad_y + xy[i][1];
10719 if (!IN_LEV_FIELD(x, y))
10722 element = Feld[x][y];
10723 if (IS_AMOEBOID(element) || element == EL_GAME_OF_LIFE ||
10724 element == EL_AMOEBA_GROWING || element == EL_AMOEBA_DROP)
10732 if (kill_x != bad_x || kill_y != bad_y)
10733 Bang(bad_x, bad_y);
10736 void KillPlayer(struct PlayerInfo *player)
10738 int jx = player->jx, jy = player->jy;
10740 if (!player->active)
10743 /* remove accessible field at the player's position */
10744 Feld[jx][jy] = EL_EMPTY;
10746 /* deactivate shield (else Bang()/Explode() would not work right) */
10747 player->shield_normal_time_left = 0;
10748 player->shield_deadly_time_left = 0;
10751 BuryPlayer(player);
10754 static void KillPlayerUnlessEnemyProtected(int x, int y)
10756 if (!PLAYER_ENEMY_PROTECTED(x, y))
10757 KillPlayer(PLAYERINFO(x, y));
10760 static void KillPlayerUnlessExplosionProtected(int x, int y)
10762 if (!PLAYER_EXPLOSION_PROTECTED(x, y))
10763 KillPlayer(PLAYERINFO(x, y));
10766 void BuryPlayer(struct PlayerInfo *player)
10768 int jx = player->jx, jy = player->jy;
10770 if (!player->active)
10773 PlayLevelSoundElementAction(jx, jy, player->artwork_element, ACTION_DYING);
10774 PlayLevelSound(jx, jy, SND_GAME_LOSING);
10776 player->GameOver = TRUE;
10777 RemovePlayer(player);
10780 void RemovePlayer(struct PlayerInfo *player)
10782 int jx = player->jx, jy = player->jy;
10783 int i, found = FALSE;
10785 player->present = FALSE;
10786 player->active = FALSE;
10788 if (!ExplodeField[jx][jy])
10789 StorePlayer[jx][jy] = 0;
10791 if (player->is_moving)
10792 DrawLevelField(player->last_jx, player->last_jy);
10794 for (i = 0; i < MAX_PLAYERS; i++)
10795 if (stored_player[i].active)
10799 AllPlayersGone = TRUE;
10805 #if USE_NEW_SNAP_DELAY
10806 static void setFieldForSnapping(int x, int y, int element, int direction)
10808 struct ElementInfo *ei = &element_info[element];
10809 int direction_bit = MV_DIR_TO_BIT(direction);
10810 int graphic_snapping = ei->direction_graphic[ACTION_SNAPPING][direction_bit];
10811 int action = (graphic_snapping != IMG_EMPTY_SPACE ? ACTION_SNAPPING :
10812 IS_DIGGABLE(element) ? ACTION_DIGGING : ACTION_COLLECTING);
10814 Feld[x][y] = EL_ELEMENT_SNAPPING;
10815 MovDelay[x][y] = MOVE_DELAY_NORMAL_SPEED + 1 - 1;
10817 ResetGfxAnimation(x, y);
10819 GfxElement[x][y] = element;
10820 GfxAction[x][y] = action;
10821 GfxDir[x][y] = direction;
10822 GfxFrame[x][y] = -1;
10827 =============================================================================
10828 checkDiagonalPushing()
10829 -----------------------------------------------------------------------------
10830 check if diagonal input device direction results in pushing of object
10831 (by checking if the alternative direction is walkable, diggable, ...)
10832 =============================================================================
10835 static boolean checkDiagonalPushing(struct PlayerInfo *player,
10836 int x, int y, int real_dx, int real_dy)
10838 int jx, jy, dx, dy, xx, yy;
10840 if (real_dx == 0 || real_dy == 0) /* no diagonal direction => push */
10843 /* diagonal direction: check alternative direction */
10848 xx = jx + (dx == 0 ? real_dx : 0);
10849 yy = jy + (dy == 0 ? real_dy : 0);
10851 return (!IN_LEV_FIELD(xx, yy) || IS_SOLID_FOR_PUSHING(Feld[xx][yy]));
10855 =============================================================================
10857 -----------------------------------------------------------------------------
10858 x, y: field next to player (non-diagonal) to try to dig to
10859 real_dx, real_dy: direction as read from input device (can be diagonal)
10860 =============================================================================
10863 int DigField(struct PlayerInfo *player,
10864 int oldx, int oldy, int x, int y,
10865 int real_dx, int real_dy, int mode)
10867 boolean is_player = (IS_PLAYER(oldx, oldy) || mode != DF_DIG);
10868 boolean player_was_pushing = player->is_pushing;
10869 boolean player_can_move = (!player->cannot_move && mode != DF_SNAP);
10870 boolean player_can_move_or_snap = (!player->cannot_move || mode == DF_SNAP);
10871 int jx = oldx, jy = oldy;
10872 int dx = x - jx, dy = y - jy;
10873 int nextx = x + dx, nexty = y + dy;
10874 int move_direction = (dx == -1 ? MV_LEFT :
10875 dx == +1 ? MV_RIGHT :
10877 dy == +1 ? MV_DOWN : MV_NONE);
10878 int opposite_direction = MV_DIR_OPPOSITE(move_direction);
10879 int dig_side = MV_DIR_OPPOSITE(move_direction);
10880 int old_element = Feld[jx][jy];
10881 #if USE_FIXED_DONT_RUN_INTO
10882 int element = MovingOrBlocked2ElementIfNotLeaving(x, y);
10888 if (is_player) /* function can also be called by EL_PENGUIN */
10890 if (player->MovPos == 0)
10892 player->is_digging = FALSE;
10893 player->is_collecting = FALSE;
10896 if (player->MovPos == 0) /* last pushing move finished */
10897 player->is_pushing = FALSE;
10899 if (mode == DF_NO_PUSH) /* player just stopped pushing */
10901 player->is_switching = FALSE;
10902 player->push_delay = -1;
10904 return MP_NO_ACTION;
10908 #if !USE_FIXED_DONT_RUN_INTO
10909 if (IS_MOVING(x, y) || IS_PLAYER(x, y))
10910 return MP_NO_ACTION;
10913 if (IS_TUBE(Back[jx][jy]) && game.engine_version >= VERSION_IDENT(2,2,0,0))
10914 old_element = Back[jx][jy];
10916 /* in case of element dropped at player position, check background */
10917 else if (Back[jx][jy] != EL_EMPTY &&
10918 game.engine_version >= VERSION_IDENT(2,2,0,0))
10919 old_element = Back[jx][jy];
10922 #if USE_FIXED_DONT_RUN_INTO
10923 if (player_can_move && DONT_RUN_INTO(element))
10925 if (element == EL_ACID && dx == 0 && dy == 1)
10928 Feld[jx][jy] = EL_PLAYER_1;
10929 InitMovingField(jx, jy, MV_DOWN);
10930 Store[jx][jy] = EL_ACID;
10931 ContinueMoving(jx, jy);
10932 BuryPlayer(player);
10935 TestIfPlayerRunsIntoBadThing(jx, jy, player->MovDir);
10937 return MP_DONT_RUN_INTO;
10943 #if USE_FIXED_DONT_RUN_INTO
10944 if (player_can_move && DONT_RUN_INTO(element))
10946 TestIfPlayerRunsIntoBadThing(jx, jy, player->MovDir);
10948 return MP_DONT_RUN_INTO;
10953 if (IS_WALKABLE(old_element) && !ACCESS_FROM(old_element, move_direction))
10954 return MP_NO_ACTION; /* field has no opening in this direction */
10956 if (IS_PASSABLE(old_element) && !ACCESS_FROM(old_element,opposite_direction))
10957 return MP_NO_ACTION; /* field has no opening in this direction */
10960 #if USE_FIXED_DONT_RUN_INTO
10961 if (player_can_move && element == EL_ACID && move_direction == MV_DOWN)
10964 Feld[jx][jy] = EL_PLAYER_1;
10965 InitMovingField(jx, jy, MV_DOWN);
10966 Store[jx][jy] = EL_ACID;
10967 ContinueMoving(jx, jy);
10968 BuryPlayer(player);
10970 return MP_DONT_RUN_INTO;
10976 #if USE_FIXED_DONT_RUN_INTO
10977 if (player_can_move && DONT_RUN_INTO(element))
10979 if (element == EL_ACID && dx == 0 && dy == 1)
10982 Feld[jx][jy] = EL_PLAYER_1;
10983 InitMovingField(jx, jy, MV_DOWN);
10984 Store[jx][jy] = EL_ACID;
10985 ContinueMoving(jx, jy);
10986 BuryPlayer(player);
10989 TestIfPlayerRunsIntoBadThing(jx, jy, player->MovDir);
10991 return MP_DONT_RUN_INTO;
10996 #if USE_FIXED_DONT_RUN_INTO
10997 if (IS_MOVING(x, y) || IS_PLAYER(x, y))
10998 return MP_NO_ACTION;
11001 #if !USE_FIXED_DONT_RUN_INTO
11002 element = Feld[x][y];
11005 collect_count = element_info[element].collect_count_initial;
11007 if (!is_player && !IS_COLLECTIBLE(element)) /* penguin cannot collect it */
11008 return MP_NO_ACTION;
11010 if (game.engine_version < VERSION_IDENT(2,2,0,0))
11011 player_can_move = player_can_move_or_snap;
11013 if (mode == DF_SNAP && !IS_SNAPPABLE(element) &&
11014 game.engine_version >= VERSION_IDENT(2,2,0,0))
11016 CheckElementChangeByPlayer(x, y, element, CE_SNAPPED_BY_PLAYER,
11017 player->index_bit, dig_side);
11018 CheckTriggeredElementChangeByPlayer(x, y, element, CE_PLAYER_SNAPS_X,
11019 player->index_bit, dig_side);
11021 if (Feld[x][y] != element) /* field changed by snapping */
11024 return MP_NO_ACTION;
11027 if (game.gravity && is_player && !player->is_auto_moving &&
11028 canFallDown(player) && move_direction != MV_DOWN &&
11029 !canMoveToValidFieldWithGravity(jx, jy, move_direction))
11030 return MP_NO_ACTION; /* player cannot walk here due to gravity */
11032 if (player_can_move &&
11033 IS_WALKABLE(element) && ACCESS_FROM(element, opposite_direction))
11035 int sound_element = SND_ELEMENT(element);
11036 int sound_action = ACTION_WALKING;
11038 if (IS_RND_GATE(element))
11040 if (!player->key[RND_GATE_NR(element)])
11041 return MP_NO_ACTION;
11043 else if (IS_RND_GATE_GRAY(element))
11045 if (!player->key[RND_GATE_GRAY_NR(element)])
11046 return MP_NO_ACTION;
11048 else if (IS_RND_GATE_GRAY_ACTIVE(element))
11050 if (!player->key[RND_GATE_GRAY_ACTIVE_NR(element)])
11051 return MP_NO_ACTION;
11053 else if (element == EL_EXIT_OPEN ||
11054 element == EL_SP_EXIT_OPEN ||
11055 element == EL_SP_EXIT_OPENING)
11057 sound_action = ACTION_PASSING; /* player is passing exit */
11059 else if (element == EL_EMPTY)
11061 sound_action = ACTION_MOVING; /* nothing to walk on */
11064 /* play sound from background or player, whatever is available */
11065 if (element_info[sound_element].sound[sound_action] != SND_UNDEFINED)
11066 PlayLevelSoundElementAction(x, y, sound_element, sound_action);
11068 PlayLevelSoundElementAction(x, y, player->artwork_element, sound_action);
11070 else if (player_can_move &&
11071 IS_PASSABLE(element) && canPassField(x, y, move_direction))
11073 if (!ACCESS_FROM(element, opposite_direction))
11074 return MP_NO_ACTION; /* field not accessible from this direction */
11076 if (CAN_MOVE(element)) /* only fixed elements can be passed! */
11077 return MP_NO_ACTION;
11079 if (IS_EM_GATE(element))
11081 if (!player->key[EM_GATE_NR(element)])
11082 return MP_NO_ACTION;
11084 else if (IS_EM_GATE_GRAY(element))
11086 if (!player->key[EM_GATE_GRAY_NR(element)])
11087 return MP_NO_ACTION;
11089 else if (IS_EM_GATE_GRAY_ACTIVE(element))
11091 if (!player->key[EM_GATE_GRAY_ACTIVE_NR(element)])
11092 return MP_NO_ACTION;
11094 else if (IS_SP_PORT(element))
11096 if (element == EL_SP_GRAVITY_PORT_LEFT ||
11097 element == EL_SP_GRAVITY_PORT_RIGHT ||
11098 element == EL_SP_GRAVITY_PORT_UP ||
11099 element == EL_SP_GRAVITY_PORT_DOWN)
11100 game.gravity = !game.gravity;
11101 else if (element == EL_SP_GRAVITY_ON_PORT_LEFT ||
11102 element == EL_SP_GRAVITY_ON_PORT_RIGHT ||
11103 element == EL_SP_GRAVITY_ON_PORT_UP ||
11104 element == EL_SP_GRAVITY_ON_PORT_DOWN)
11105 game.gravity = TRUE;
11106 else if (element == EL_SP_GRAVITY_OFF_PORT_LEFT ||
11107 element == EL_SP_GRAVITY_OFF_PORT_RIGHT ||
11108 element == EL_SP_GRAVITY_OFF_PORT_UP ||
11109 element == EL_SP_GRAVITY_OFF_PORT_DOWN)
11110 game.gravity = FALSE;
11113 /* automatically move to the next field with double speed */
11114 player->programmed_action = move_direction;
11116 if (player->move_delay_reset_counter == 0)
11118 player->move_delay_reset_counter = 2; /* two double speed steps */
11120 DOUBLE_PLAYER_SPEED(player);
11123 PlayLevelSoundAction(x, y, ACTION_PASSING);
11125 else if (player_can_move_or_snap && IS_DIGGABLE(element))
11129 if (mode != DF_SNAP)
11131 GfxElement[x][y] = GFX_ELEMENT(element);
11132 player->is_digging = TRUE;
11135 PlayLevelSoundElementAction(x, y, element, ACTION_DIGGING);
11137 CheckTriggeredElementChangeByPlayer(x, y, element, CE_PLAYER_DIGS_X,
11138 player->index_bit, dig_side);
11140 if (mode == DF_SNAP)
11142 #if USE_NEW_SNAP_DELAY
11143 if (level.block_snap_field)
11144 setFieldForSnapping(x, y, element, move_direction);
11146 TestIfElementTouchesCustomElement(x, y); /* for empty space */
11148 TestIfElementTouchesCustomElement(x, y); /* for empty space */
11151 CheckTriggeredElementChangeByPlayer(x, y, element, CE_PLAYER_SNAPS_X,
11152 player->index_bit, dig_side);
11155 else if (player_can_move_or_snap && IS_COLLECTIBLE(element))
11159 if (is_player && mode != DF_SNAP)
11161 GfxElement[x][y] = element;
11162 player->is_collecting = TRUE;
11165 if (element == EL_SPEED_PILL)
11167 player->move_delay_value = MOVE_DELAY_HIGH_SPEED;
11169 else if (element == EL_EXTRA_TIME && level.time > 0)
11171 TimeLeft += level.extra_time;
11172 DrawGameValue_Time(TimeLeft);
11174 else if (element == EL_SHIELD_NORMAL || element == EL_SHIELD_DEADLY)
11176 player->shield_normal_time_left += level.shield_normal_time;
11177 if (element == EL_SHIELD_DEADLY)
11178 player->shield_deadly_time_left += level.shield_deadly_time;
11180 else if (element == EL_DYNAMITE ||
11181 element == EL_EM_DYNAMITE ||
11182 element == EL_SP_DISK_RED)
11184 if (player->inventory_size < MAX_INVENTORY_SIZE)
11185 player->inventory_element[player->inventory_size++] = element;
11187 DrawGameValue_Dynamite(local_player->inventory_size);
11189 else if (element == EL_DYNABOMB_INCREASE_NUMBER)
11191 player->dynabomb_count++;
11192 player->dynabombs_left++;
11194 else if (element == EL_DYNABOMB_INCREASE_SIZE)
11196 player->dynabomb_size++;
11198 else if (element == EL_DYNABOMB_INCREASE_POWER)
11200 player->dynabomb_xl = TRUE;
11202 else if (IS_KEY(element))
11204 player->key[KEY_NR(element)] = TRUE;
11206 DrawGameValue_Keys(player->key);
11208 redraw_mask |= REDRAW_DOOR_1;
11210 else if (IS_ENVELOPE(element))
11212 player->show_envelope = element;
11214 else if (element == EL_EMC_LENSES)
11216 game.lenses_time_left = level.lenses_time * FRAMES_PER_SECOND;
11218 RedrawAllInvisibleElementsForLenses();
11220 else if (element == EL_EMC_MAGNIFIER)
11222 game.magnify_time_left = level.magnify_time * FRAMES_PER_SECOND;
11224 RedrawAllInvisibleElementsForMagnifier();
11226 else if (IS_DROPPABLE(element) ||
11227 IS_THROWABLE(element)) /* can be collected and dropped */
11231 if (collect_count == 0)
11232 player->inventory_infinite_element = element;
11234 for (i = 0; i < collect_count; i++)
11235 if (player->inventory_size < MAX_INVENTORY_SIZE)
11236 player->inventory_element[player->inventory_size++] = element;
11238 DrawGameValue_Dynamite(local_player->inventory_size);
11240 else if (collect_count > 0)
11242 local_player->gems_still_needed -= collect_count;
11243 if (local_player->gems_still_needed < 0)
11244 local_player->gems_still_needed = 0;
11246 DrawGameValue_Emeralds(local_player->gems_still_needed);
11249 RaiseScoreElement(element);
11250 PlayLevelSoundElementAction(x, y, element, ACTION_COLLECTING);
11253 CheckTriggeredElementChangeByPlayer(x, y, element, CE_PLAYER_COLLECTS_X,
11254 player->index_bit, dig_side);
11256 if (mode == DF_SNAP)
11258 #if USE_NEW_SNAP_DELAY
11259 if (level.block_snap_field)
11260 setFieldForSnapping(x, y, element, move_direction);
11262 TestIfElementTouchesCustomElement(x, y); /* for empty space */
11264 TestIfElementTouchesCustomElement(x, y); /* for empty space */
11267 CheckTriggeredElementChangeByPlayer(x, y, element, CE_PLAYER_SNAPS_X,
11268 player->index_bit, dig_side);
11271 else if (player_can_move_or_snap && IS_PUSHABLE(element))
11273 if (mode == DF_SNAP && element != EL_BD_ROCK)
11274 return MP_NO_ACTION;
11276 if (CAN_FALL(element) && dy)
11277 return MP_NO_ACTION;
11279 if (CAN_FALL(element) && IN_LEV_FIELD(x, y + 1) && IS_FREE(x, y + 1) &&
11280 !(element == EL_SPRING && level.use_spring_bug))
11281 return MP_NO_ACTION;
11283 if (CAN_MOVE(element) && GET_MAX_MOVE_DELAY(element) == 0 &&
11284 ((move_direction & MV_VERTICAL &&
11285 ((element_info[element].move_pattern & MV_LEFT &&
11286 IN_LEV_FIELD(x - 1, y) && IS_FREE(x - 1, y)) ||
11287 (element_info[element].move_pattern & MV_RIGHT &&
11288 IN_LEV_FIELD(x + 1, y) && IS_FREE(x + 1, y)))) ||
11289 (move_direction & MV_HORIZONTAL &&
11290 ((element_info[element].move_pattern & MV_UP &&
11291 IN_LEV_FIELD(x, y - 1) && IS_FREE(x, y - 1)) ||
11292 (element_info[element].move_pattern & MV_DOWN &&
11293 IN_LEV_FIELD(x, y + 1) && IS_FREE(x, y + 1))))))
11294 return MP_NO_ACTION;
11296 /* do not push elements already moving away faster than player */
11297 if (CAN_MOVE(element) && MovDir[x][y] == move_direction &&
11298 ABS(getElementMoveStepsize(x, y)) > MOVE_STEPSIZE_NORMAL)
11299 return MP_NO_ACTION;
11301 if (game.engine_version >= VERSION_IDENT(3,1,0,0))
11303 if (player->push_delay_value == -1 || !player_was_pushing)
11304 player->push_delay_value = GET_NEW_PUSH_DELAY(element);
11306 else if (game.engine_version >= VERSION_IDENT(3,0,7,1))
11308 if (player->push_delay_value == -1)
11309 player->push_delay_value = GET_NEW_PUSH_DELAY(element);
11311 else if (game.engine_version >= VERSION_IDENT(2,2,0,7))
11313 if (!player->is_pushing)
11314 player->push_delay_value = GET_NEW_PUSH_DELAY(element);
11317 player->is_pushing = TRUE;
11319 if (!(IN_LEV_FIELD(nextx, nexty) &&
11320 (IS_FREE(nextx, nexty) ||
11321 (Feld[nextx][nexty] == EL_SOKOBAN_FIELD_EMPTY &&
11322 IS_SB_ELEMENT(element)))))
11323 return MP_NO_ACTION;
11325 if (!checkDiagonalPushing(player, x, y, real_dx, real_dy))
11326 return MP_NO_ACTION;
11328 if (player->push_delay == -1) /* new pushing; restart delay */
11329 player->push_delay = 0;
11331 if (player->push_delay < player->push_delay_value &&
11332 !(tape.playing && tape.file_version < FILE_VERSION_2_0) &&
11333 element != EL_SPRING && element != EL_BALLOON)
11335 /* make sure that there is no move delay before next try to push */
11336 if (game.engine_version >= VERSION_IDENT(3,0,7,1))
11337 player->move_delay = 0;
11339 return MP_NO_ACTION;
11342 if (IS_SB_ELEMENT(element))
11344 if (element == EL_SOKOBAN_FIELD_FULL)
11346 Back[x][y] = EL_SOKOBAN_FIELD_EMPTY;
11347 local_player->sokobanfields_still_needed++;
11350 if (Feld[nextx][nexty] == EL_SOKOBAN_FIELD_EMPTY)
11352 Back[nextx][nexty] = EL_SOKOBAN_FIELD_EMPTY;
11353 local_player->sokobanfields_still_needed--;
11356 Feld[x][y] = EL_SOKOBAN_OBJECT;
11358 if (Back[x][y] == Back[nextx][nexty])
11359 PlayLevelSoundAction(x, y, ACTION_PUSHING);
11360 else if (Back[x][y] != 0)
11361 PlayLevelSoundElementAction(x, y, EL_SOKOBAN_FIELD_FULL,
11364 PlayLevelSoundElementAction(nextx, nexty, EL_SOKOBAN_FIELD_EMPTY,
11367 if (local_player->sokobanfields_still_needed == 0 &&
11368 game.emulation == EMU_SOKOBAN)
11370 player->LevelSolved = player->GameOver = TRUE;
11371 PlayLevelSound(x, y, SND_GAME_SOKOBAN_SOLVING);
11375 PlayLevelSoundElementAction(x, y, element, ACTION_PUSHING);
11377 InitMovingField(x, y, move_direction);
11378 GfxAction[x][y] = ACTION_PUSHING;
11380 if (mode == DF_SNAP)
11381 ContinueMoving(x, y);
11383 MovPos[x][y] = (dx != 0 ? dx : dy);
11385 Pushed[x][y] = TRUE;
11386 Pushed[nextx][nexty] = TRUE;
11388 if (game.engine_version < VERSION_IDENT(2,2,0,7))
11389 player->push_delay_value = GET_NEW_PUSH_DELAY(element);
11391 player->push_delay_value = -1; /* get new value later */
11393 /* check for element change _after_ element has been pushed */
11394 if (game.use_change_when_pushing_bug)
11396 CheckElementChangeByPlayer(x, y, element, CE_PUSHED_BY_PLAYER,
11397 player->index_bit, dig_side);
11398 CheckTriggeredElementChangeByPlayer(x, y, element, CE_PLAYER_PUSHES_X,
11399 player->index_bit, dig_side);
11402 else if (IS_SWITCHABLE(element))
11404 if (PLAYER_SWITCHING(player, x, y))
11406 CheckTriggeredElementChangeByPlayer(x, y, element, CE_PLAYER_PRESSES_X,
11407 player->index_bit, dig_side);
11412 player->is_switching = TRUE;
11413 player->switch_x = x;
11414 player->switch_y = y;
11416 PlayLevelSoundElementAction(x, y, element, ACTION_ACTIVATING);
11418 if (element == EL_ROBOT_WHEEL)
11420 Feld[x][y] = EL_ROBOT_WHEEL_ACTIVE;
11424 DrawLevelField(x, y);
11426 else if (element == EL_SP_TERMINAL)
11431 SCAN_PLAYFIELD(xx, yy)
11433 for (yy = 0; yy < lev_fieldy; yy++) for (xx = 0; xx < lev_fieldx; xx++)
11436 if (Feld[xx][yy] == EL_SP_DISK_YELLOW)
11438 else if (Feld[xx][yy] == EL_SP_TERMINAL)
11439 Feld[xx][yy] = EL_SP_TERMINAL_ACTIVE;
11442 else if (IS_BELT_SWITCH(element))
11444 ToggleBeltSwitch(x, y);
11446 else if (element == EL_SWITCHGATE_SWITCH_UP ||
11447 element == EL_SWITCHGATE_SWITCH_DOWN)
11449 ToggleSwitchgateSwitch(x, y);
11451 else if (element == EL_LIGHT_SWITCH ||
11452 element == EL_LIGHT_SWITCH_ACTIVE)
11454 ToggleLightSwitch(x, y);
11456 else if (element == EL_TIMEGATE_SWITCH)
11458 ActivateTimegateSwitch(x, y);
11460 else if (element == EL_BALLOON_SWITCH_LEFT ||
11461 element == EL_BALLOON_SWITCH_RIGHT ||
11462 element == EL_BALLOON_SWITCH_UP ||
11463 element == EL_BALLOON_SWITCH_DOWN ||
11464 element == EL_BALLOON_SWITCH_NONE ||
11465 element == EL_BALLOON_SWITCH_ANY)
11467 game.wind_direction = (element == EL_BALLOON_SWITCH_LEFT ? MV_LEFT :
11468 element == EL_BALLOON_SWITCH_RIGHT ? MV_RIGHT :
11469 element == EL_BALLOON_SWITCH_UP ? MV_UP :
11470 element == EL_BALLOON_SWITCH_DOWN ? MV_DOWN :
11471 element == EL_BALLOON_SWITCH_NONE ? MV_NONE :
11474 else if (element == EL_LAMP)
11476 Feld[x][y] = EL_LAMP_ACTIVE;
11477 local_player->lights_still_needed--;
11479 ResetGfxAnimation(x, y);
11480 DrawLevelField(x, y);
11482 else if (element == EL_TIME_ORB_FULL)
11484 Feld[x][y] = EL_TIME_ORB_EMPTY;
11486 if (level.time > 0 || level.use_time_orb_bug)
11488 TimeLeft += level.time_orb_time;
11489 DrawGameValue_Time(TimeLeft);
11492 ResetGfxAnimation(x, y);
11493 DrawLevelField(x, y);
11495 else if (element == EL_EMC_MAGIC_BALL_SWITCH ||
11496 element == EL_EMC_MAGIC_BALL_SWITCH_ACTIVE)
11500 game.ball_state = !game.ball_state;
11503 SCAN_PLAYFIELD(xx, yy)
11505 for (yy = 0; yy < lev_fieldy; yy++) for (xx = 0; xx < lev_fieldx; xx++)
11508 int e = Feld[xx][yy];
11510 if (game.ball_state)
11512 if (e == EL_EMC_MAGIC_BALL)
11513 CreateField(xx, yy, EL_EMC_MAGIC_BALL_ACTIVE);
11514 else if (e == EL_EMC_MAGIC_BALL_SWITCH)
11515 CreateField(xx, yy, EL_EMC_MAGIC_BALL_SWITCH_ACTIVE);
11519 if (e == EL_EMC_MAGIC_BALL_ACTIVE)
11520 CreateField(xx, yy, EL_EMC_MAGIC_BALL);
11521 else if (e == EL_EMC_MAGIC_BALL_SWITCH_ACTIVE)
11522 CreateField(xx, yy, EL_EMC_MAGIC_BALL_SWITCH);
11527 CheckTriggeredElementChangeByPlayer(x, y, element, CE_SWITCH_OF_X,
11528 player->index_bit, dig_side);
11530 CheckTriggeredElementChangeByPlayer(x, y, element, CE_PLAYER_SWITCHES_X,
11531 player->index_bit, dig_side);
11533 CheckTriggeredElementChangeByPlayer(x, y, element, CE_PLAYER_PRESSES_X,
11534 player->index_bit, dig_side);
11540 if (!PLAYER_SWITCHING(player, x, y))
11542 player->is_switching = TRUE;
11543 player->switch_x = x;
11544 player->switch_y = y;
11546 CheckElementChangeByPlayer(x, y, element, CE_SWITCHED,
11547 player->index_bit, dig_side);
11548 CheckTriggeredElementChangeByPlayer(x, y, element, CE_SWITCH_OF_X,
11549 player->index_bit, dig_side);
11551 CheckElementChangeByPlayer(x, y, element, CE_SWITCHED_BY_PLAYER,
11552 player->index_bit, dig_side);
11553 CheckTriggeredElementChangeByPlayer(x, y, element, CE_PLAYER_SWITCHES_X,
11554 player->index_bit, dig_side);
11557 CheckElementChangeByPlayer(x, y, element, CE_PRESSED_BY_PLAYER,
11558 player->index_bit, dig_side);
11559 CheckTriggeredElementChangeByPlayer(x, y, element, CE_PLAYER_PRESSES_X,
11560 player->index_bit, dig_side);
11562 return MP_NO_ACTION;
11565 player->push_delay = -1;
11567 if (is_player) /* function can also be called by EL_PENGUIN */
11569 if (Feld[x][y] != element) /* really digged/collected something */
11570 player->is_collecting = !player->is_digging;
11576 boolean SnapField(struct PlayerInfo *player, int dx, int dy)
11578 int jx = player->jx, jy = player->jy;
11579 int x = jx + dx, y = jy + dy;
11580 int snap_direction = (dx == -1 ? MV_LEFT :
11581 dx == +1 ? MV_RIGHT :
11583 dy == +1 ? MV_DOWN : MV_NONE);
11585 if (player->MovPos != 0 && game.engine_version >= VERSION_IDENT(2,2,0,0))
11588 if (!player->active || !IN_LEV_FIELD(x, y))
11596 if (player->MovPos == 0)
11597 player->is_pushing = FALSE;
11599 player->is_snapping = FALSE;
11601 if (player->MovPos == 0)
11603 player->is_moving = FALSE;
11604 player->is_digging = FALSE;
11605 player->is_collecting = FALSE;
11611 if (player->is_snapping)
11614 player->MovDir = snap_direction;
11616 if (player->MovPos == 0)
11618 player->is_moving = FALSE;
11619 player->is_digging = FALSE;
11620 player->is_collecting = FALSE;
11623 player->is_dropping = FALSE;
11625 if (DigField(player, jx, jy, x, y, 0, 0, DF_SNAP) == MP_NO_ACTION)
11628 player->is_snapping = TRUE;
11630 if (player->MovPos == 0)
11632 player->is_moving = FALSE;
11633 player->is_digging = FALSE;
11634 player->is_collecting = FALSE;
11637 if (player->MovPos != 0) /* prevent graphic bugs in versions < 2.2.0 */
11638 DrawLevelField(player->last_jx, player->last_jy);
11640 DrawLevelField(x, y);
11645 boolean DropElement(struct PlayerInfo *player)
11647 int old_element, new_element;
11648 int dropx = player->jx, dropy = player->jy;
11649 int drop_direction = player->MovDir;
11650 int drop_side = drop_direction;
11651 int drop_element = (player->inventory_size > 0 ?
11652 player->inventory_element[player->inventory_size - 1] :
11653 player->inventory_infinite_element != EL_UNDEFINED ?
11654 player->inventory_infinite_element :
11655 player->dynabombs_left > 0 ?
11656 EL_DYNABOMB_PLAYER_1_ACTIVE + player->index_nr :
11659 /* do not drop an element on top of another element; when holding drop key
11660 pressed without moving, dropped element must move away before the next
11661 element can be dropped (this is especially important if the next element
11662 is dynamite, which can be placed on background for historical reasons) */
11663 if (PLAYER_DROPPING(player, dropx, dropy) && Feld[dropx][dropy] != EL_EMPTY)
11666 if (IS_THROWABLE(drop_element))
11668 dropx += GET_DX_FROM_DIR(drop_direction);
11669 dropy += GET_DY_FROM_DIR(drop_direction);
11671 if (!IN_LEV_FIELD(dropx, dropy))
11675 old_element = Feld[dropx][dropy]; /* old element at dropping position */
11676 new_element = drop_element; /* default: no change when dropping */
11678 /* check if player is active, not moving and ready to drop */
11679 if (!player->active || player->MovPos || player->drop_delay > 0)
11682 /* check if player has anything that can be dropped */
11683 if (new_element == EL_UNDEFINED)
11686 /* check if anything can be dropped at the current position */
11687 if (IS_ACTIVE_BOMB(old_element) || old_element == EL_EXPLOSION)
11690 /* collected custom elements can only be dropped on empty fields */
11691 if (IS_CUSTOM_ELEMENT(new_element) && old_element != EL_EMPTY)
11694 if (old_element != EL_EMPTY)
11695 Back[dropx][dropy] = old_element; /* store old element on this field */
11697 ResetGfxAnimation(dropx, dropy);
11698 ResetRandomAnimationValue(dropx, dropy);
11700 if (player->inventory_size > 0 ||
11701 player->inventory_infinite_element != EL_UNDEFINED)
11703 if (player->inventory_size > 0)
11705 player->inventory_size--;
11707 DrawGameValue_Dynamite(local_player->inventory_size);
11709 if (new_element == EL_DYNAMITE)
11710 new_element = EL_DYNAMITE_ACTIVE;
11711 else if (new_element == EL_EM_DYNAMITE)
11712 new_element = EL_EM_DYNAMITE_ACTIVE;
11713 else if (new_element == EL_SP_DISK_RED)
11714 new_element = EL_SP_DISK_RED_ACTIVE;
11717 Feld[dropx][dropy] = new_element;
11719 if (IN_SCR_FIELD(SCREENX(dropx), SCREENY(dropy)))
11720 DrawGraphicThruMask(SCREENX(dropx), SCREENY(dropy),
11721 el2img(Feld[dropx][dropy]), 0);
11723 PlayLevelSoundAction(dropx, dropy, ACTION_DROPPING);
11725 /* needed if previous element just changed to "empty" in the last frame */
11726 ChangeCount[dropx][dropy] = 0; /* allow at least one more change */
11728 CheckElementChangeByPlayer(dropx, dropy, new_element, CE_DROPPED_BY_PLAYER,
11729 player->index_bit, drop_side);
11730 CheckTriggeredElementChangeByPlayer(dropx, dropy, new_element,
11732 player->index_bit, drop_side);
11734 TestIfElementTouchesCustomElement(dropx, dropy);
11736 else /* player is dropping a dyna bomb */
11738 player->dynabombs_left--;
11740 Feld[dropx][dropy] = new_element;
11742 if (IN_SCR_FIELD(SCREENX(dropx), SCREENY(dropy)))
11743 DrawGraphicThruMask(SCREENX(dropx), SCREENY(dropy),
11744 el2img(Feld[dropx][dropy]), 0);
11746 PlayLevelSoundAction(dropx, dropy, ACTION_DROPPING);
11749 if (Feld[dropx][dropy] == new_element) /* uninitialized unless CE change */
11750 InitField_WithBug1(dropx, dropy, FALSE);
11752 new_element = Feld[dropx][dropy]; /* element might have changed */
11754 if (IS_CUSTOM_ELEMENT(new_element) && CAN_MOVE(new_element) &&
11755 element_info[new_element].move_pattern == MV_WHEN_DROPPED)
11757 int move_direction, nextx, nexty;
11759 if (element_info[new_element].move_direction_initial == MV_START_AUTOMATIC)
11760 MovDir[dropx][dropy] = drop_direction;
11762 move_direction = MovDir[dropx][dropy];
11763 nextx = dropx + GET_DX_FROM_DIR(move_direction);
11764 nexty = dropy + GET_DY_FROM_DIR(move_direction);
11766 ChangeCount[dropx][dropy] = 0; /* allow at least one more change */
11767 CheckCollision[dropx][dropy] = 2;
11770 player->drop_delay = GET_NEW_DROP_DELAY(drop_element);
11771 player->is_dropping = TRUE;
11773 player->drop_x = dropx;
11774 player->drop_y = dropy;
11779 /* ------------------------------------------------------------------------- */
11780 /* game sound playing functions */
11781 /* ------------------------------------------------------------------------- */
11783 static int *loop_sound_frame = NULL;
11784 static int *loop_sound_volume = NULL;
11786 void InitPlayLevelSound()
11788 int num_sounds = getSoundListSize();
11790 checked_free(loop_sound_frame);
11791 checked_free(loop_sound_volume);
11793 loop_sound_frame = checked_calloc(num_sounds * sizeof(int));
11794 loop_sound_volume = checked_calloc(num_sounds * sizeof(int));
11797 static void PlayLevelSound(int x, int y, int nr)
11799 int sx = SCREENX(x), sy = SCREENY(y);
11800 int volume, stereo_position;
11801 int max_distance = 8;
11802 int type = (IS_LOOP_SOUND(nr) ? SND_CTRL_PLAY_LOOP : SND_CTRL_PLAY_SOUND);
11804 if ((!setup.sound_simple && !IS_LOOP_SOUND(nr)) ||
11805 (!setup.sound_loops && IS_LOOP_SOUND(nr)))
11808 if (!IN_LEV_FIELD(x, y) ||
11809 sx < -max_distance || sx >= SCR_FIELDX + max_distance ||
11810 sy < -max_distance || sy >= SCR_FIELDY + max_distance)
11813 volume = SOUND_MAX_VOLUME;
11815 if (!IN_SCR_FIELD(sx, sy))
11817 int dx = ABS(sx - SCR_FIELDX / 2) - SCR_FIELDX / 2;
11818 int dy = ABS(sy - SCR_FIELDY / 2) - SCR_FIELDY / 2;
11820 volume -= volume * (dx > dy ? dx : dy) / max_distance;
11823 stereo_position = (SOUND_MAX_LEFT +
11824 (sx + max_distance) * SOUND_MAX_LEFT2RIGHT /
11825 (SCR_FIELDX + 2 * max_distance));
11827 if (IS_LOOP_SOUND(nr))
11829 /* This assures that quieter loop sounds do not overwrite louder ones,
11830 while restarting sound volume comparison with each new game frame. */
11832 if (loop_sound_volume[nr] > volume && loop_sound_frame[nr] == FrameCounter)
11835 loop_sound_volume[nr] = volume;
11836 loop_sound_frame[nr] = FrameCounter;
11839 PlaySoundExt(nr, volume, stereo_position, type);
11842 static void PlayLevelSoundNearest(int x, int y, int sound_action)
11844 PlayLevelSound(x < LEVELX(BX1) ? LEVELX(BX1) :
11845 x > LEVELX(BX2) ? LEVELX(BX2) : x,
11846 y < LEVELY(BY1) ? LEVELY(BY1) :
11847 y > LEVELY(BY2) ? LEVELY(BY2) : y,
11851 static void PlayLevelSoundAction(int x, int y, int action)
11853 PlayLevelSoundElementAction(x, y, Feld[x][y], action);
11856 static void PlayLevelSoundElementAction(int x, int y, int element, int action)
11858 int sound_effect = element_info[SND_ELEMENT(element)].sound[action];
11860 if (sound_effect != SND_UNDEFINED)
11861 PlayLevelSound(x, y, sound_effect);
11864 static void PlayLevelSoundElementActionIfLoop(int x, int y, int element,
11867 int sound_effect = element_info[SND_ELEMENT(element)].sound[action];
11869 if (sound_effect != SND_UNDEFINED && IS_LOOP_SOUND(sound_effect))
11870 PlayLevelSound(x, y, sound_effect);
11873 static void PlayLevelSoundActionIfLoop(int x, int y, int action)
11875 int sound_effect = element_info[SND_ELEMENT(Feld[x][y])].sound[action];
11877 if (sound_effect != SND_UNDEFINED && IS_LOOP_SOUND(sound_effect))
11878 PlayLevelSound(x, y, sound_effect);
11881 static void StopLevelSoundActionIfLoop(int x, int y, int action)
11883 int sound_effect = element_info[SND_ELEMENT(Feld[x][y])].sound[action];
11885 if (sound_effect != SND_UNDEFINED && IS_LOOP_SOUND(sound_effect))
11886 StopSound(sound_effect);
11889 static void PlayLevelMusic()
11891 if (levelset.music[level_nr] != MUS_UNDEFINED)
11892 PlayMusic(levelset.music[level_nr]); /* from config file */
11894 PlayMusic(MAP_NOCONF_MUSIC(level_nr)); /* from music dir */
11897 void PlayLevelSound_EM(int x, int y, int element_em, int sample)
11899 int element = (element_em > -1 ? map_element_EM_to_RND(element_em) : 0);
11904 PlayLevelSoundElementAction(x, y, element, ACTION_WALKING);
11908 PlayLevelSoundElementAction(x, y, element, ACTION_PUSHING);
11912 PlayLevelSoundElementAction(x, y, element, ACTION_IMPACT);
11916 PlayLevelSoundElementAction(x, y, element, ACTION_IMPACT);
11920 PlayLevelSoundElementAction(x, y, element, ACTION_BREAKING);
11924 PlayLevelSoundElementAction(x, y, element, ACTION_MOVING);
11928 PlayLevelSoundElementAction(x, y, element, ACTION_MOVING);
11931 case SAMPLE_android_clone:
11932 PlayLevelSoundElementAction(x, y, element, ACTION_DROPPING);
11935 case SAMPLE_android_move:
11936 PlayLevelSoundElementAction(x, y, element, ACTION_MOVING);
11939 case SAMPLE_spring:
11940 PlayLevelSoundElementAction(x, y, element, ACTION_IMPACT);
11944 PlayLevelSoundElementAction(x, y, element, ACTION_EATING);
11948 PlayLevelSoundElementAction(x, y, element, ACTION_WAITING);
11951 case SAMPLE_eater_eat:
11952 PlayLevelSoundElementAction(x, y, element, ACTION_DIGGING);
11956 PlayLevelSoundElementAction(x, y, element, ACTION_MOVING);
11959 case SAMPLE_collect:
11960 PlayLevelSoundElementAction(x, y, element, ACTION_COLLECTING);
11963 case SAMPLE_diamond:
11964 PlayLevelSoundElementAction(x, y, element, ACTION_IMPACT);
11967 case SAMPLE_squash:
11968 /* !!! CHECK THIS !!! */
11970 PlayLevelSoundElementAction(x, y, element, ACTION_BREAKING);
11972 PlayLevelSoundElementAction(x, y, element, ACTION_SMASHED_BY_ROCK);
11976 case SAMPLE_wonderfall:
11977 PlayLevelSoundElementAction(x, y, element, ACTION_FILLING);
11981 PlayLevelSoundElementAction(x, y, element, ACTION_IMPACT);
11985 PlayLevelSoundElementAction(x, y, element, ACTION_PUSHING);
11989 PlayLevelSoundElementAction(x, y, element, ACTION_DIGGING);
11993 PlayLevelSoundElementAction(x, y, element, ACTION_SPLASHING);
11997 PlayLevelSoundElementAction(x, y, element, ACTION_DROPPING);
12001 PlayLevelSoundElementAction(x, y, element, ACTION_GROWING);
12004 case SAMPLE_wonder:
12005 PlayLevelSoundElementAction(x, y, element, ACTION_ACTIVE);
12009 PlayLevelSoundElementAction(x, y, element, ACTION_PASSING);
12012 case SAMPLE_exit_open:
12013 PlayLevelSoundElementAction(x, y, element, ACTION_OPENING);
12016 case SAMPLE_exit_leave:
12017 PlayLevelSoundElementAction(x, y, element, ACTION_PASSING);
12020 case SAMPLE_dynamite:
12021 PlayLevelSoundElementAction(x, y, element, ACTION_DROPPING);
12025 PlayLevelSoundElementAction(x, y, element, ACTION_ACTIVE);
12029 PlayLevelSoundElementAction(x, y, element, ACTION_ACTIVATING);
12033 PlayLevelSoundElementAction(x, y, element, ACTION_ACTIVE);
12037 PlayLevelSoundElementAction(x, y, element, ACTION_EXPLODING);
12041 PlayLevelSoundElementAction(x, y, element, ACTION_DYING);
12045 PlaySoundStereo(SND_GAME_RUNNING_OUT_OF_TIME, SOUND_MIDDLE);
12049 PlayLevelSoundElementAction(x, y, element, ACTION_DEFAULT);
12054 void RaiseScore(int value)
12056 local_player->score += value;
12058 DrawGameValue_Score(local_player->score);
12061 void RaiseScoreElement(int element)
12066 case EL_BD_DIAMOND:
12067 case EL_EMERALD_YELLOW:
12068 case EL_EMERALD_RED:
12069 case EL_EMERALD_PURPLE:
12070 case EL_SP_INFOTRON:
12071 RaiseScore(level.score[SC_EMERALD]);
12074 RaiseScore(level.score[SC_DIAMOND]);
12077 RaiseScore(level.score[SC_CRYSTAL]);
12080 RaiseScore(level.score[SC_PEARL]);
12083 case EL_BD_BUTTERFLY:
12084 case EL_SP_ELECTRON:
12085 RaiseScore(level.score[SC_BUG]);
12088 case EL_BD_FIREFLY:
12089 case EL_SP_SNIKSNAK:
12090 RaiseScore(level.score[SC_SPACESHIP]);
12093 case EL_DARK_YAMYAM:
12094 RaiseScore(level.score[SC_YAMYAM]);
12097 RaiseScore(level.score[SC_ROBOT]);
12100 RaiseScore(level.score[SC_PACMAN]);
12103 RaiseScore(level.score[SC_NUT]);
12106 case EL_EM_DYNAMITE:
12107 case EL_SP_DISK_RED:
12108 case EL_DYNABOMB_INCREASE_NUMBER:
12109 case EL_DYNABOMB_INCREASE_SIZE:
12110 case EL_DYNABOMB_INCREASE_POWER:
12111 RaiseScore(level.score[SC_DYNAMITE]);
12113 case EL_SHIELD_NORMAL:
12114 case EL_SHIELD_DEADLY:
12115 RaiseScore(level.score[SC_SHIELD]);
12117 case EL_EXTRA_TIME:
12118 RaiseScore(level.extra_time_score);
12132 RaiseScore(level.score[SC_KEY]);
12135 RaiseScore(element_info[element].collect_score);
12140 void RequestQuitGame(boolean ask_if_really_quit)
12142 if (AllPlayersGone ||
12143 !ask_if_really_quit ||
12144 level_editor_test_game ||
12145 Request("Do you really want to quit the game ?",
12146 REQ_ASK | REQ_STAY_CLOSED))
12148 #if defined(NETWORK_AVALIABLE)
12149 if (options.network)
12150 SendToServer_StopPlaying();
12154 game_status = GAME_MODE_MAIN;
12160 if (tape.playing && tape.deactivate_display)
12161 TapeDeactivateDisplayOff(TRUE);
12163 OpenDoor(DOOR_OPEN_1 | DOOR_COPY_BACK);
12165 if (tape.playing && tape.deactivate_display)
12166 TapeDeactivateDisplayOn();
12171 /* ---------- new game button stuff ---------------------------------------- */
12173 /* graphic position values for game buttons */
12174 #define GAME_BUTTON_XSIZE 30
12175 #define GAME_BUTTON_YSIZE 30
12176 #define GAME_BUTTON_XPOS 5
12177 #define GAME_BUTTON_YPOS 215
12178 #define SOUND_BUTTON_XPOS 5
12179 #define SOUND_BUTTON_YPOS (GAME_BUTTON_YPOS + GAME_BUTTON_YSIZE)
12181 #define GAME_BUTTON_STOP_XPOS (GAME_BUTTON_XPOS + 0 * GAME_BUTTON_XSIZE)
12182 #define GAME_BUTTON_PAUSE_XPOS (GAME_BUTTON_XPOS + 1 * GAME_BUTTON_XSIZE)
12183 #define GAME_BUTTON_PLAY_XPOS (GAME_BUTTON_XPOS + 2 * GAME_BUTTON_XSIZE)
12184 #define SOUND_BUTTON_MUSIC_XPOS (SOUND_BUTTON_XPOS + 0 * GAME_BUTTON_XSIZE)
12185 #define SOUND_BUTTON_LOOPS_XPOS (SOUND_BUTTON_XPOS + 1 * GAME_BUTTON_XSIZE)
12186 #define SOUND_BUTTON_SIMPLE_XPOS (SOUND_BUTTON_XPOS + 2 * GAME_BUTTON_XSIZE)
12193 } gamebutton_info[NUM_GAME_BUTTONS] =
12196 GAME_BUTTON_STOP_XPOS, GAME_BUTTON_YPOS,
12201 GAME_BUTTON_PAUSE_XPOS, GAME_BUTTON_YPOS,
12202 GAME_CTRL_ID_PAUSE,
12206 GAME_BUTTON_PLAY_XPOS, GAME_BUTTON_YPOS,
12211 SOUND_BUTTON_MUSIC_XPOS, SOUND_BUTTON_YPOS,
12212 SOUND_CTRL_ID_MUSIC,
12213 "background music on/off"
12216 SOUND_BUTTON_LOOPS_XPOS, SOUND_BUTTON_YPOS,
12217 SOUND_CTRL_ID_LOOPS,
12218 "sound loops on/off"
12221 SOUND_BUTTON_SIMPLE_XPOS, SOUND_BUTTON_YPOS,
12222 SOUND_CTRL_ID_SIMPLE,
12223 "normal sounds on/off"
12227 void CreateGameButtons()
12231 for (i = 0; i < NUM_GAME_BUTTONS; i++)
12233 Bitmap *gd_bitmap = graphic_info[IMG_GLOBAL_DOOR].bitmap;
12234 struct GadgetInfo *gi;
12237 unsigned long event_mask;
12238 int gd_xoffset, gd_yoffset;
12239 int gd_x1, gd_x2, gd_y1, gd_y2;
12242 gd_xoffset = gamebutton_info[i].x;
12243 gd_yoffset = gamebutton_info[i].y;
12244 gd_x1 = DOOR_GFX_PAGEX4 + gd_xoffset;
12245 gd_x2 = DOOR_GFX_PAGEX3 + gd_xoffset;
12247 if (id == GAME_CTRL_ID_STOP ||
12248 id == GAME_CTRL_ID_PAUSE ||
12249 id == GAME_CTRL_ID_PLAY)
12251 button_type = GD_TYPE_NORMAL_BUTTON;
12253 event_mask = GD_EVENT_RELEASED;
12254 gd_y1 = DOOR_GFX_PAGEY1 + gd_yoffset - GAME_BUTTON_YSIZE;
12255 gd_y2 = DOOR_GFX_PAGEY1 + gd_yoffset - GAME_BUTTON_YSIZE;
12259 button_type = GD_TYPE_CHECK_BUTTON;
12261 ((id == SOUND_CTRL_ID_MUSIC && setup.sound_music) ||
12262 (id == SOUND_CTRL_ID_LOOPS && setup.sound_loops) ||
12263 (id == SOUND_CTRL_ID_SIMPLE && setup.sound_simple) ? TRUE : FALSE);
12264 event_mask = GD_EVENT_PRESSED;
12265 gd_y1 = DOOR_GFX_PAGEY1 + gd_yoffset;
12266 gd_y2 = DOOR_GFX_PAGEY1 + gd_yoffset - GAME_BUTTON_YSIZE;
12269 gi = CreateGadget(GDI_CUSTOM_ID, id,
12270 GDI_INFO_TEXT, gamebutton_info[i].infotext,
12271 GDI_X, DX + gd_xoffset,
12272 GDI_Y, DY + gd_yoffset,
12273 GDI_WIDTH, GAME_BUTTON_XSIZE,
12274 GDI_HEIGHT, GAME_BUTTON_YSIZE,
12275 GDI_TYPE, button_type,
12276 GDI_STATE, GD_BUTTON_UNPRESSED,
12277 GDI_CHECKED, checked,
12278 GDI_DESIGN_UNPRESSED, gd_bitmap, gd_x1, gd_y1,
12279 GDI_DESIGN_PRESSED, gd_bitmap, gd_x2, gd_y1,
12280 GDI_ALT_DESIGN_UNPRESSED, gd_bitmap, gd_x1, gd_y2,
12281 GDI_ALT_DESIGN_PRESSED, gd_bitmap, gd_x2, gd_y2,
12282 GDI_EVENT_MASK, event_mask,
12283 GDI_CALLBACK_ACTION, HandleGameButtons,
12287 Error(ERR_EXIT, "cannot create gadget");
12289 game_gadget[id] = gi;
12293 void FreeGameButtons()
12297 for (i = 0; i < NUM_GAME_BUTTONS; i++)
12298 FreeGadget(game_gadget[i]);
12301 static void MapGameButtons()
12305 for (i = 0; i < NUM_GAME_BUTTONS; i++)
12306 MapGadget(game_gadget[i]);
12309 void UnmapGameButtons()
12313 for (i = 0; i < NUM_GAME_BUTTONS; i++)
12314 UnmapGadget(game_gadget[i]);
12317 static void HandleGameButtons(struct GadgetInfo *gi)
12319 int id = gi->custom_id;
12321 if (game_status != GAME_MODE_PLAYING)
12326 case GAME_CTRL_ID_STOP:
12327 RequestQuitGame(TRUE);
12330 case GAME_CTRL_ID_PAUSE:
12331 if (options.network)
12333 #if defined(NETWORK_AVALIABLE)
12335 SendToServer_ContinuePlaying();
12337 SendToServer_PausePlaying();
12341 TapeTogglePause(TAPE_TOGGLE_MANUAL);
12344 case GAME_CTRL_ID_PLAY:
12347 #if defined(NETWORK_AVALIABLE)
12348 if (options.network)
12349 SendToServer_ContinuePlaying();
12353 tape.pausing = FALSE;
12354 DrawVideoDisplay(VIDEO_STATE_PAUSE_OFF,0);
12359 case SOUND_CTRL_ID_MUSIC:
12360 if (setup.sound_music)
12362 setup.sound_music = FALSE;
12365 else if (audio.music_available)
12367 setup.sound = setup.sound_music = TRUE;
12369 SetAudioMode(setup.sound);
12375 case SOUND_CTRL_ID_LOOPS:
12376 if (setup.sound_loops)
12377 setup.sound_loops = FALSE;
12378 else if (audio.loops_available)
12380 setup.sound = setup.sound_loops = TRUE;
12381 SetAudioMode(setup.sound);
12385 case SOUND_CTRL_ID_SIMPLE:
12386 if (setup.sound_simple)
12387 setup.sound_simple = FALSE;
12388 else if (audio.sound_available)
12390 setup.sound = setup.sound_simple = TRUE;
12391 SetAudioMode(setup.sound);