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 * 0)
38 #define USE_QUICKSAND_IMPACT_BUGFIX (USE_NEW_STUFF * 0)
45 /* for MovePlayer() */
46 #define MF_NO_ACTION 0
50 /* for ScrollPlayer() */
52 #define SCROLL_GO_ON 1
54 /* for Bang()/Explode() */
55 #define EX_PHASE_START 0
56 #define EX_TYPE_NONE 0
57 #define EX_TYPE_NORMAL (1 << 0)
58 #define EX_TYPE_CENTER (1 << 1)
59 #define EX_TYPE_BORDER (1 << 2)
60 #define EX_TYPE_CROSS (1 << 3)
61 #define EX_TYPE_DYNA (1 << 4)
62 #define EX_TYPE_SINGLE_TILE (EX_TYPE_CENTER | EX_TYPE_BORDER)
64 /* special positions in the game control window (relative to control window) */
67 #define XX_EMERALDS 29
68 #define YY_EMERALDS 54
69 #define XX_DYNAMITE 29
70 #define YY_DYNAMITE 89
79 /* special positions in the game control window (relative to main window) */
80 #define DX_LEVEL (DX + XX_LEVEL)
81 #define DY_LEVEL (DY + YY_LEVEL)
82 #define DX_EMERALDS (DX + XX_EMERALDS)
83 #define DY_EMERALDS (DY + YY_EMERALDS)
84 #define DX_DYNAMITE (DX + XX_DYNAMITE)
85 #define DY_DYNAMITE (DY + YY_DYNAMITE)
86 #define DX_KEYS (DX + XX_KEYS)
87 #define DY_KEYS (DY + YY_KEYS)
88 #define DX_SCORE (DX + XX_SCORE)
89 #define DY_SCORE (DY + YY_SCORE)
90 #define DX_TIME1 (DX + XX_TIME1)
91 #define DX_TIME2 (DX + XX_TIME2)
92 #define DY_TIME (DY + YY_TIME)
94 /* values for initial player move delay (initial delay counter value) */
95 #define INITIAL_MOVE_DELAY_OFF -1
96 #define INITIAL_MOVE_DELAY_ON 0
98 /* values for player movement speed (which is in fact a delay value) */
99 #define MOVE_DELAY_MIN_SPEED 32
100 #define MOVE_DELAY_NORMAL_SPEED 8
101 #define MOVE_DELAY_HIGH_SPEED 4
102 #define MOVE_DELAY_MAX_SPEED 1
105 #define DOUBLE_MOVE_DELAY(x) (x = (x <= MOVE_DELAY_HIGH_SPEED ? x * 2 : x))
106 #define HALVE_MOVE_DELAY(x) (x = (x >= MOVE_DELAY_HIGH_SPEED ? x / 2 : x))
108 #define DOUBLE_MOVE_DELAY(x) (x = (x < MOVE_DELAY_MIN_SPEED ? x * 2 : x))
109 #define HALVE_MOVE_DELAY(x) (x = (x > MOVE_DELAY_MAX_SPEED ? x / 2 : x))
111 #define DOUBLE_PLAYER_SPEED(p) (HALVE_MOVE_DELAY((p)->move_delay_value))
112 #define HALVE_PLAYER_SPEED(p) (DOUBLE_MOVE_DELAY((p)->move_delay_value))
114 /* values for other actions */
115 #define MOVE_STEPSIZE_NORMAL (TILEX / MOVE_DELAY_NORMAL_SPEED)
116 #define MOVE_STEPSIZE_MIN (1)
117 #define MOVE_STEPSIZE_MAX (TILEX)
119 #define GET_DX_FROM_DIR(d) ((d) == MV_LEFT ? -1 : (d) == MV_RIGHT ? 1 : 0)
120 #define GET_DY_FROM_DIR(d) ((d) == MV_UP ? -1 : (d) == MV_DOWN ? 1 : 0)
122 #define INIT_GFX_RANDOM() (SimpleRND(1000000))
124 #define GET_NEW_PUSH_DELAY(e) ( (element_info[e].push_delay_fixed) + \
125 RND(element_info[e].push_delay_random))
126 #define GET_NEW_DROP_DELAY(e) ( (element_info[e].drop_delay_fixed) + \
127 RND(element_info[e].drop_delay_random))
128 #define GET_NEW_MOVE_DELAY(e) ( (element_info[e].move_delay_fixed) + \
129 RND(element_info[e].move_delay_random))
130 #define GET_MAX_MOVE_DELAY(e) ( (element_info[e].move_delay_fixed) + \
131 (element_info[e].move_delay_random))
132 #define GET_NEW_CUSTOM_VALUE(e) ( (element_info[e].ce_value_fixed_initial) +\
133 RND(element_info[e].ce_value_random_initial))
134 #define GET_CHANGE_DELAY(c) ( ((c)->delay_fixed * (c)->delay_frames) + \
135 RND((c)->delay_random * (c)->delay_frames))
136 #define GET_CE_DELAY_VALUE(c) ( ((c)->delay_fixed) + \
137 RND((c)->delay_random))
139 #define GET_TARGET_ELEMENT(e, ch) \
140 ((e) == EL_TRIGGER_ELEMENT ? (ch)->actual_trigger_element : \
141 (e) == EL_TRIGGER_PLAYER ? (ch)->actual_trigger_player : (e))
143 #define CAN_GROW_INTO(e) \
144 ((e) == EL_SAND || (IS_DIGGABLE(e) && level.grow_into_diggable))
146 #define ELEMENT_CAN_ENTER_FIELD_BASE_X(x, y, condition) \
147 (IN_LEV_FIELD(x, y) && (IS_FREE(x, y) || \
150 #define ELEMENT_CAN_ENTER_FIELD_BASE_2(e, x, y, condition) \
151 (IN_LEV_FIELD(x, y) && (IS_FREE(x, y) || \
152 (CAN_MOVE_INTO_ACID(e) && \
153 Feld[x][y] == EL_ACID) || \
156 #define ELEMENT_CAN_ENTER_FIELD_BASE_3(e, x, y, condition) \
157 (IN_LEV_FIELD(x, y) && (IS_FREE_OR_PLAYER(x, y) || \
158 (CAN_MOVE_INTO_ACID(e) && \
159 Feld[x][y] == EL_ACID) || \
162 #define ELEMENT_CAN_ENTER_FIELD_BASE_4(e, x, y, condition) \
163 (IN_LEV_FIELD(x, y) && (IS_FREE(x, y) || \
165 (CAN_MOVE_INTO_ACID(e) && \
166 Feld[x][y] == EL_ACID) || \
167 (DONT_COLLIDE_WITH(e) && \
169 !PLAYER_ENEMY_PROTECTED(x, y))))
171 #define ELEMENT_CAN_ENTER_FIELD(e, x, y) \
172 ELEMENT_CAN_ENTER_FIELD_BASE_4(e, x, y, 0)
174 #define SATELLITE_CAN_ENTER_FIELD(x, y) \
175 ELEMENT_CAN_ENTER_FIELD_BASE_2(EL_SATELLITE, x, y, 0)
177 #define ENEMY_CAN_ENTER_FIELD(e, x, y) \
178 ELEMENT_CAN_ENTER_FIELD_BASE_2(e, x, y, 0)
180 #define YAMYAM_CAN_ENTER_FIELD(e, x, y) \
181 ELEMENT_CAN_ENTER_FIELD_BASE_3(e, x, y, Feld[x][y] == EL_DIAMOND)
183 #define DARK_YAMYAM_CAN_ENTER_FIELD(e, x, y) \
184 ELEMENT_CAN_ENTER_FIELD_BASE_3(e, x,y, IS_FOOD_DARK_YAMYAM(Feld[x][y]))
186 #define PACMAN_CAN_ENTER_FIELD(e, x, y) \
187 ELEMENT_CAN_ENTER_FIELD_BASE_3(e, x, y, IS_AMOEBOID(Feld[x][y]))
189 #define PIG_CAN_ENTER_FIELD(e, x, y) \
190 ELEMENT_CAN_ENTER_FIELD_BASE_2(e, x, y, IS_FOOD_PIG(Feld[x][y]))
192 #define PENGUIN_CAN_ENTER_FIELD(e, x, y) \
193 ELEMENT_CAN_ENTER_FIELD_BASE_2(e, x, y, (Feld[x][y] == EL_EXIT_OPEN ||\
194 IS_FOOD_PENGUIN(Feld[x][y])))
195 #define DRAGON_CAN_ENTER_FIELD(e, x, y) \
196 ELEMENT_CAN_ENTER_FIELD_BASE_2(e, x, y, 0)
198 #define MOLE_CAN_ENTER_FIELD(e, x, y, condition) \
199 ELEMENT_CAN_ENTER_FIELD_BASE_2(e, x, y, (condition))
201 #define SPRING_CAN_ENTER_FIELD(e, x, y) \
202 ELEMENT_CAN_ENTER_FIELD_BASE_2(e, x, y, 0)
204 #define GROUP_NR(e) ((e) - EL_GROUP_START)
205 #define MOVE_ENTER_EL(e) (element_info[e].move_enter_element)
206 #define IS_IN_GROUP(e, nr) (element_info[e].in_group[nr] == TRUE)
207 #define IS_IN_GROUP_EL(e, ge) (IS_IN_GROUP(e, (ge) - EL_GROUP_START))
209 #define IS_EQUAL_OR_IN_GROUP(e, ge) \
210 (IS_GROUP_ELEMENT(ge) ? IS_IN_GROUP(e, GROUP_NR(ge)) : (e) == (ge))
212 #define CE_ENTER_FIELD_COND(e, x, y) \
213 (!IS_PLAYER(x, y) && \
214 IS_EQUAL_OR_IN_GROUP(Feld[x][y], MOVE_ENTER_EL(e)))
216 #define CUSTOM_ELEMENT_CAN_ENTER_FIELD(e, x, y) \
217 ELEMENT_CAN_ENTER_FIELD_BASE_4(e, x, y, CE_ENTER_FIELD_COND(e, x, y))
219 #define IN_LEV_FIELD_AND_IS_FREE(x, y) (IN_LEV_FIELD(x, y) && IS_FREE(x, y))
220 #define IN_LEV_FIELD_AND_NOT_FREE(x, y) (IN_LEV_FIELD(x, y) && !IS_FREE(x, y))
222 #define ACCESS_FROM(e, d) (element_info[e].access_direction &(d))
223 #define IS_WALKABLE_FROM(e, d) (IS_WALKABLE(e) && ACCESS_FROM(e, d))
224 #define IS_PASSABLE_FROM(e, d) (IS_PASSABLE(e) && ACCESS_FROM(e, d))
225 #define IS_ACCESSIBLE_FROM(e, d) (IS_ACCESSIBLE(e) && ACCESS_FROM(e, d))
227 /* game button identifiers */
228 #define GAME_CTRL_ID_STOP 0
229 #define GAME_CTRL_ID_PAUSE 1
230 #define GAME_CTRL_ID_PLAY 2
231 #define SOUND_CTRL_ID_MUSIC 3
232 #define SOUND_CTRL_ID_LOOPS 4
233 #define SOUND_CTRL_ID_SIMPLE 5
235 #define NUM_GAME_BUTTONS 6
238 /* forward declaration for internal use */
240 static void SetPlayerWaiting(struct PlayerInfo *, boolean);
241 static void AdvanceFrameAndPlayerCounters(int);
243 static boolean MovePlayerOneStep(struct PlayerInfo *, int, int, int, int);
244 static boolean MovePlayer(struct PlayerInfo *, int, int);
245 static void ScrollPlayer(struct PlayerInfo *, int);
246 static void ScrollScreen(struct PlayerInfo *, int);
248 int DigField(struct PlayerInfo *, int, int, int, int, int, int, int);
250 static void InitBeltMovement(void);
251 static void CloseAllOpenTimegates(void);
252 static void CheckGravityMovement(struct PlayerInfo *);
253 static void CheckGravityMovementWhenNotMoving(struct PlayerInfo *);
254 static void KillPlayerUnlessEnemyProtected(int, int);
255 static void KillPlayerUnlessExplosionProtected(int, int);
257 static void TestIfPlayerTouchesCustomElement(int, int);
258 static void TestIfElementTouchesCustomElement(int, int);
259 static void TestIfElementHitsCustomElement(int, int, int);
261 static void TestIfElementSmashesCustomElement(int, int, int);
264 static void ChangeElement(int, int, int);
266 static boolean CheckTriggeredElementChangeExt(int, int, int, int, int,int,int);
267 #define CheckTriggeredElementChange(x, y, e, ev) \
268 CheckTriggeredElementChangeExt(x,y,e,ev, CH_PLAYER_ANY,CH_SIDE_ANY, -1)
269 #define CheckTriggeredElementChangeByPlayer(x, y, e, ev, p, s) \
270 CheckTriggeredElementChangeExt(x, y, e, ev, p, s, -1)
271 #define CheckTriggeredElementChangeBySide(x, y, e, ev, s) \
272 CheckTriggeredElementChangeExt(x, y, e, ev, CH_PLAYER_ANY, s, -1)
273 #define CheckTriggeredElementChangeByPage(x, y, e, ev, p) \
274 CheckTriggeredElementChangeExt(x,y,e,ev, CH_PLAYER_ANY, CH_SIDE_ANY, p)
276 static boolean CheckElementChangeExt(int, int, int, int, int, int, int);
277 #define CheckElementChange(x, y, e, te, ev) \
278 CheckElementChangeExt(x, y, e, te, ev, CH_PLAYER_ANY, CH_SIDE_ANY)
279 #define CheckElementChangeByPlayer(x, y, e, ev, p, s) \
280 CheckElementChangeExt(x, y, e, EL_EMPTY, ev, p, s)
281 #define CheckElementChangeBySide(x, y, e, te, ev, s) \
282 CheckElementChangeExt(x, y, e, te, ev, CH_PLAYER_ANY, s)
284 static void PlayLevelSound(int, int, int);
285 static void PlayLevelSoundNearest(int, int, int);
286 static void PlayLevelSoundAction(int, int, int);
287 static void PlayLevelSoundElementAction(int, int, int, int);
288 static void PlayLevelSoundElementActionIfLoop(int, int, int, int);
289 static void PlayLevelSoundActionIfLoop(int, int, int);
290 static void StopLevelSoundActionIfLoop(int, int, int);
291 static void PlayLevelMusic();
293 static void MapGameButtons();
294 static void HandleGameButtons(struct GadgetInfo *);
296 static struct GadgetInfo *game_gadget[NUM_GAME_BUTTONS];
299 /* ------------------------------------------------------------------------- */
300 /* definition of elements that automatically change to other elements after */
301 /* a specified time, eventually calling a function when changing */
302 /* ------------------------------------------------------------------------- */
304 /* forward declaration for changer functions */
305 static void InitBuggyBase(int x, int y);
306 static void WarnBuggyBase(int x, int y);
308 static void InitTrap(int x, int y);
309 static void ActivateTrap(int x, int y);
310 static void ChangeActiveTrap(int x, int y);
312 static void InitRobotWheel(int x, int y);
313 static void RunRobotWheel(int x, int y);
314 static void StopRobotWheel(int x, int y);
316 static void InitTimegateWheel(int x, int y);
317 static void RunTimegateWheel(int x, int y);
319 struct ChangingElementInfo
324 void (*pre_change_function)(int x, int y);
325 void (*change_function)(int x, int y);
326 void (*post_change_function)(int x, int y);
329 static struct ChangingElementInfo change_delay_list[] =
380 EL_SWITCHGATE_OPENING,
388 EL_SWITCHGATE_CLOSING,
389 EL_SWITCHGATE_CLOSED,
421 EL_ACID_SPLASH_RIGHT,
430 EL_SP_BUGGY_BASE_ACTIVATING,
437 EL_SP_BUGGY_BASE_ACTIVATING,
438 EL_SP_BUGGY_BASE_ACTIVE,
445 EL_SP_BUGGY_BASE_ACTIVE,
469 EL_ROBOT_WHEEL_ACTIVE,
477 EL_TIMEGATE_SWITCH_ACTIVE,
498 int push_delay_fixed, push_delay_random;
503 { EL_BALLOON, 0, 0 },
505 { EL_SOKOBAN_OBJECT, 2, 0 },
506 { EL_SOKOBAN_FIELD_FULL, 2, 0 },
507 { EL_SATELLITE, 2, 0 },
508 { EL_SP_DISK_YELLOW, 2, 0 },
510 { EL_UNDEFINED, 0, 0 },
518 move_stepsize_list[] =
520 { EL_AMOEBA_DROP, 2 },
521 { EL_AMOEBA_DROPPING, 2 },
522 { EL_QUICKSAND_FILLING, 1 },
523 { EL_QUICKSAND_EMPTYING, 1 },
524 { EL_MAGIC_WALL_FILLING, 2 },
525 { EL_BD_MAGIC_WALL_FILLING, 2 },
526 { EL_MAGIC_WALL_EMPTYING, 2 },
527 { EL_BD_MAGIC_WALL_EMPTYING, 2 },
537 collect_count_list[] =
540 { EL_BD_DIAMOND, 1 },
541 { EL_EMERALD_YELLOW, 1 },
542 { EL_EMERALD_RED, 1 },
543 { EL_EMERALD_PURPLE, 1 },
545 { EL_SP_INFOTRON, 1 },
557 access_direction_list[] =
559 { EL_TUBE_ANY, MV_LEFT | MV_RIGHT | MV_UP | MV_DOWN },
560 { EL_TUBE_VERTICAL, MV_UP | MV_DOWN },
561 { EL_TUBE_HORIZONTAL, MV_LEFT | MV_RIGHT },
562 { EL_TUBE_VERTICAL_LEFT, MV_LEFT | MV_UP | MV_DOWN },
563 { EL_TUBE_VERTICAL_RIGHT, MV_RIGHT | MV_UP | MV_DOWN },
564 { EL_TUBE_HORIZONTAL_UP, MV_LEFT | MV_RIGHT | MV_UP },
565 { EL_TUBE_HORIZONTAL_DOWN, MV_LEFT | MV_RIGHT | MV_DOWN },
566 { EL_TUBE_LEFT_UP, MV_LEFT | MV_UP },
567 { EL_TUBE_LEFT_DOWN, MV_LEFT | MV_DOWN },
568 { EL_TUBE_RIGHT_UP, MV_RIGHT | MV_UP },
569 { EL_TUBE_RIGHT_DOWN, MV_RIGHT | MV_DOWN },
571 { EL_SP_PORT_LEFT, MV_RIGHT },
572 { EL_SP_PORT_RIGHT, MV_LEFT },
573 { EL_SP_PORT_UP, MV_DOWN },
574 { EL_SP_PORT_DOWN, MV_UP },
575 { EL_SP_PORT_HORIZONTAL, MV_LEFT | MV_RIGHT },
576 { EL_SP_PORT_VERTICAL, MV_UP | MV_DOWN },
577 { EL_SP_PORT_ANY, MV_LEFT | MV_RIGHT | MV_UP | MV_DOWN },
578 { EL_SP_GRAVITY_PORT_LEFT, MV_RIGHT },
579 { EL_SP_GRAVITY_PORT_RIGHT, MV_LEFT },
580 { EL_SP_GRAVITY_PORT_UP, MV_DOWN },
581 { EL_SP_GRAVITY_PORT_DOWN, MV_UP },
582 { EL_SP_GRAVITY_ON_PORT_LEFT, MV_RIGHT },
583 { EL_SP_GRAVITY_ON_PORT_RIGHT, MV_LEFT },
584 { EL_SP_GRAVITY_ON_PORT_UP, MV_DOWN },
585 { EL_SP_GRAVITY_ON_PORT_DOWN, MV_UP },
586 { EL_SP_GRAVITY_OFF_PORT_LEFT, MV_RIGHT },
587 { EL_SP_GRAVITY_OFF_PORT_RIGHT, MV_LEFT },
588 { EL_SP_GRAVITY_OFF_PORT_UP, MV_DOWN },
589 { EL_SP_GRAVITY_OFF_PORT_DOWN, MV_UP },
591 { EL_UNDEFINED, MV_NONE }
594 static boolean trigger_events[MAX_NUM_ELEMENTS][NUM_CHANGE_EVENTS];
596 #define IS_AUTO_CHANGING(e) (element_info[e].has_change_event[CE_DELAY])
597 #define IS_JUST_CHANGING(x, y) (ChangeDelay[x][y] != 0)
598 #define IS_CHANGING(x, y) (IS_AUTO_CHANGING(Feld[x][y]) || \
599 IS_JUST_CHANGING(x, y))
601 #define CE_PAGE(e, ce) (element_info[e].event_page[ce])
604 void GetPlayerConfig()
606 if (!audio.sound_available)
607 setup.sound_simple = FALSE;
609 if (!audio.loops_available)
610 setup.sound_loops = FALSE;
612 if (!audio.music_available)
613 setup.sound_music = FALSE;
615 if (!video.fullscreen_available)
616 setup.fullscreen = FALSE;
618 setup.sound = (setup.sound_simple || setup.sound_loops || setup.sound_music);
620 SetAudioMode(setup.sound);
624 static int getBeltNrFromBeltElement(int element)
626 return (element < EL_CONVEYOR_BELT_2_LEFT ? 0 :
627 element < EL_CONVEYOR_BELT_3_LEFT ? 1 :
628 element < EL_CONVEYOR_BELT_4_LEFT ? 2 : 3);
631 static int getBeltNrFromBeltActiveElement(int element)
633 return (element < EL_CONVEYOR_BELT_2_LEFT_ACTIVE ? 0 :
634 element < EL_CONVEYOR_BELT_3_LEFT_ACTIVE ? 1 :
635 element < EL_CONVEYOR_BELT_4_LEFT_ACTIVE ? 2 : 3);
638 static int getBeltNrFromBeltSwitchElement(int element)
640 return (element < EL_CONVEYOR_BELT_2_SWITCH_LEFT ? 0 :
641 element < EL_CONVEYOR_BELT_3_SWITCH_LEFT ? 1 :
642 element < EL_CONVEYOR_BELT_4_SWITCH_LEFT ? 2 : 3);
645 static int getBeltDirNrFromBeltSwitchElement(int element)
647 static int belt_base_element[4] =
649 EL_CONVEYOR_BELT_1_SWITCH_LEFT,
650 EL_CONVEYOR_BELT_2_SWITCH_LEFT,
651 EL_CONVEYOR_BELT_3_SWITCH_LEFT,
652 EL_CONVEYOR_BELT_4_SWITCH_LEFT
655 int belt_nr = getBeltNrFromBeltSwitchElement(element);
656 int belt_dir_nr = element - belt_base_element[belt_nr];
658 return (belt_dir_nr % 3);
661 static int getBeltDirFromBeltSwitchElement(int element)
663 static int belt_move_dir[3] =
670 int belt_dir_nr = getBeltDirNrFromBeltSwitchElement(element);
672 return belt_move_dir[belt_dir_nr];
675 static void InitPlayerField(int x, int y, int element, boolean init_game)
677 if (element == EL_SP_MURPHY)
681 if (stored_player[0].present)
683 Feld[x][y] = EL_SP_MURPHY_CLONE;
689 stored_player[0].use_murphy = TRUE;
692 Feld[x][y] = EL_PLAYER_1;
698 struct PlayerInfo *player = &stored_player[Feld[x][y] - EL_PLAYER_1];
699 int jx = player->jx, jy = player->jy;
701 player->present = TRUE;
703 player->block_last_field = (element == EL_SP_MURPHY ?
704 level.sp_block_last_field :
705 level.block_last_field);
707 /* ---------- initialize player's last field block delay --------------- */
709 /* always start with reliable default value (no adjustment needed) */
710 player->block_delay_adjustment = 0;
712 /* special case 1: in Supaplex, Murphy blocks last field one more frame */
713 if (player->block_last_field && element == EL_SP_MURPHY)
714 player->block_delay_adjustment = 1;
716 /* special case 2: in game engines before 3.1.1, blocking was different */
717 if (game.use_block_last_field_bug)
718 player->block_delay_adjustment = (player->block_last_field ? -1 : 1);
720 if (!options.network || player->connected)
722 player->active = TRUE;
724 /* remove potentially duplicate players */
725 if (StorePlayer[jx][jy] == Feld[x][y])
726 StorePlayer[jx][jy] = 0;
728 StorePlayer[x][y] = Feld[x][y];
732 printf("Player %d activated.\n", player->element_nr);
733 printf("[Local player is %d and currently %s.]\n",
734 local_player->element_nr,
735 local_player->active ? "active" : "not active");
739 Feld[x][y] = EL_EMPTY;
741 player->jx = player->last_jx = x;
742 player->jy = player->last_jy = y;
746 static void InitField(int x, int y, boolean init_game)
748 int element = Feld[x][y];
757 InitPlayerField(x, y, element, init_game);
760 case EL_SOKOBAN_FIELD_PLAYER:
761 element = Feld[x][y] = EL_PLAYER_1;
762 InitField(x, y, init_game);
764 element = Feld[x][y] = EL_SOKOBAN_FIELD_EMPTY;
765 InitField(x, y, init_game);
768 case EL_SOKOBAN_FIELD_EMPTY:
769 local_player->sokobanfields_still_needed++;
773 if (x < lev_fieldx-1 && Feld[x+1][y] == EL_ACID)
774 Feld[x][y] = EL_ACID_POOL_TOPLEFT;
775 else if (x > 0 && Feld[x-1][y] == EL_ACID)
776 Feld[x][y] = EL_ACID_POOL_TOPRIGHT;
777 else if (y > 0 && Feld[x][y-1] == EL_ACID_POOL_TOPLEFT)
778 Feld[x][y] = EL_ACID_POOL_BOTTOMLEFT;
779 else if (y > 0 && Feld[x][y-1] == EL_ACID)
780 Feld[x][y] = EL_ACID_POOL_BOTTOM;
781 else if (y > 0 && Feld[x][y-1] == EL_ACID_POOL_TOPRIGHT)
782 Feld[x][y] = EL_ACID_POOL_BOTTOMRIGHT;
790 case EL_SPACESHIP_RIGHT:
791 case EL_SPACESHIP_UP:
792 case EL_SPACESHIP_LEFT:
793 case EL_SPACESHIP_DOWN:
795 case EL_BD_BUTTERFLY_RIGHT:
796 case EL_BD_BUTTERFLY_UP:
797 case EL_BD_BUTTERFLY_LEFT:
798 case EL_BD_BUTTERFLY_DOWN:
799 case EL_BD_BUTTERFLY:
800 case EL_BD_FIREFLY_RIGHT:
801 case EL_BD_FIREFLY_UP:
802 case EL_BD_FIREFLY_LEFT:
803 case EL_BD_FIREFLY_DOWN:
805 case EL_PACMAN_RIGHT:
829 if (y == lev_fieldy - 1)
831 Feld[x][y] = EL_AMOEBA_GROWING;
832 Store[x][y] = EL_AMOEBA_WET;
836 case EL_DYNAMITE_ACTIVE:
837 case EL_SP_DISK_RED_ACTIVE:
838 case EL_DYNABOMB_PLAYER_1_ACTIVE:
839 case EL_DYNABOMB_PLAYER_2_ACTIVE:
840 case EL_DYNABOMB_PLAYER_3_ACTIVE:
841 case EL_DYNABOMB_PLAYER_4_ACTIVE:
846 local_player->lights_still_needed++;
850 local_player->friends_still_needed++;
855 GfxDir[x][y] = MovDir[x][y] = 1 << RND(4);
858 case EL_CONVEYOR_BELT_1_SWITCH_LEFT:
859 case EL_CONVEYOR_BELT_1_SWITCH_MIDDLE:
860 case EL_CONVEYOR_BELT_1_SWITCH_RIGHT:
861 case EL_CONVEYOR_BELT_2_SWITCH_LEFT:
862 case EL_CONVEYOR_BELT_2_SWITCH_MIDDLE:
863 case EL_CONVEYOR_BELT_2_SWITCH_RIGHT:
864 case EL_CONVEYOR_BELT_3_SWITCH_LEFT:
865 case EL_CONVEYOR_BELT_3_SWITCH_MIDDLE:
866 case EL_CONVEYOR_BELT_3_SWITCH_RIGHT:
867 case EL_CONVEYOR_BELT_4_SWITCH_LEFT:
868 case EL_CONVEYOR_BELT_4_SWITCH_MIDDLE:
869 case EL_CONVEYOR_BELT_4_SWITCH_RIGHT:
872 int belt_nr = getBeltNrFromBeltSwitchElement(Feld[x][y]);
873 int belt_dir = getBeltDirFromBeltSwitchElement(Feld[x][y]);
874 int belt_dir_nr = getBeltDirNrFromBeltSwitchElement(Feld[x][y]);
876 if (game.belt_dir_nr[belt_nr] == 3) /* initial value */
878 game.belt_dir[belt_nr] = belt_dir;
879 game.belt_dir_nr[belt_nr] = belt_dir_nr;
881 else /* more than one switch -- set it like the first switch */
883 Feld[x][y] = Feld[x][y] - belt_dir_nr + game.belt_dir_nr[belt_nr];
888 case EL_SWITCHGATE_SWITCH_DOWN: /* always start with same switch pos */
890 Feld[x][y] = EL_SWITCHGATE_SWITCH_UP;
893 case EL_LIGHT_SWITCH_ACTIVE:
895 game.light_time_left = level.time_light * FRAMES_PER_SECOND;
900 if (IS_CUSTOM_ELEMENT(element))
902 if (CAN_MOVE(element))
905 #if USE_NEW_CUSTOM_VALUE
906 if (!element_info[element].use_last_ce_value || init_game)
907 CustomValue[x][y] = GET_NEW_CUSTOM_VALUE(Feld[x][y]);
911 if (IS_CUSTOM_ELEMENT(element) && CAN_MOVE(element))
914 else if (IS_GROUP_ELEMENT(element))
916 struct ElementGroupInfo *group = element_info[element].group;
917 int last_anim_random_frame = gfx.anim_random_frame;
920 if (group->choice_mode == ANIM_RANDOM)
921 gfx.anim_random_frame = RND(group->num_elements_resolved);
923 element_pos = getAnimationFrame(group->num_elements_resolved, 1,
924 group->choice_mode, 0,
927 if (group->choice_mode == ANIM_RANDOM)
928 gfx.anim_random_frame = last_anim_random_frame;
932 Feld[x][y] = group->element_resolved[element_pos];
934 InitField(x, y, init_game);
941 #if USE_NEW_CUSTOM_VALUE
944 CustomValue[x][y] = GET_NEW_CUSTOM_VALUE(Feld[x][y]);
946 CustomValue[x][y] = element_info[Feld[x][y]].custom_value_initial;
954 static inline void InitField_WithBug1(int x, int y, boolean init_game)
956 InitField(x, y, init_game);
958 /* not needed to call InitMovDir() -- already done by InitField()! */
959 if (game.engine_version < VERSION_IDENT(3,1,0,0) &&
960 CAN_MOVE(Feld[x][y]))
964 static inline void InitField_WithBug2(int x, int y, boolean init_game)
966 int old_element = Feld[x][y];
968 InitField(x, y, init_game);
970 /* not needed to call InitMovDir() -- already done by InitField()! */
971 if (game.engine_version < VERSION_IDENT(3,1,0,0) &&
972 CAN_MOVE(old_element) &&
973 (old_element < EL_MOLE_LEFT || old_element > EL_MOLE_DOWN))
976 /* this case is in fact a combination of not less than three bugs:
977 first, it calls InitMovDir() for elements that can move, although this is
978 already done by InitField(); then, it checks the element that was at this
979 field _before_ the call to InitField() (which can change it); lastly, it
980 was not called for "mole with direction" elements, which were treated as
981 "cannot move" due to (fixed) wrong element initialization in "src/init.c"
985 inline void DrawGameValue_Emeralds(int value)
987 DrawText(DX_EMERALDS, DY_EMERALDS, int2str(value, 3), FONT_TEXT_2);
990 inline void DrawGameValue_Dynamite(int value)
992 DrawText(DX_DYNAMITE, DY_DYNAMITE, int2str(value, 3), FONT_TEXT_2);
995 inline void DrawGameValue_Keys(int key[MAX_NUM_KEYS])
999 /* currently only 4 of 8 possible keys are displayed */
1000 for (i = 0; i < STD_NUM_KEYS; i++)
1003 DrawMiniGraphicExt(drawto, DX_KEYS + i * MINI_TILEX, DY_KEYS,
1004 el2edimg(EL_KEY_1 + i));
1006 BlitBitmap(graphic_info[IMG_GLOBAL_DOOR].bitmap, drawto,
1007 DOOR_GFX_PAGEX5 + XX_KEYS + i * MINI_TILEX, YY_KEYS,
1008 MINI_TILEX, MINI_TILEY, DX_KEYS + i * MINI_TILEX, DY_KEYS);
1012 inline void DrawGameValue_Score(int value)
1014 DrawText(DX_SCORE, DY_SCORE, int2str(value, 5), FONT_TEXT_2);
1017 inline void DrawGameValue_Time(int value)
1020 DrawText(DX_TIME1, DY_TIME, int2str(value, 3), FONT_TEXT_2);
1022 DrawText(DX_TIME2, DY_TIME, int2str(value, 4), FONT_LEVEL_NUMBER);
1025 inline void DrawGameValue_Level(int value)
1028 DrawText(DX_LEVEL, DY_LEVEL, int2str(value, 2), FONT_TEXT_2);
1031 /* misuse area for displaying emeralds to draw bigger level number */
1032 DrawTextExt(drawto, DX_EMERALDS, DY_EMERALDS,
1033 int2str(value, 3), FONT_LEVEL_NUMBER, BLIT_OPAQUE);
1035 /* now copy it to the area for displaying level number */
1036 BlitBitmap(drawto, drawto,
1037 DX_EMERALDS, DY_EMERALDS + 1,
1038 getFontWidth(FONT_LEVEL_NUMBER) * 3,
1039 getFontHeight(FONT_LEVEL_NUMBER) - 1,
1040 DX_LEVEL - 1, DY_LEVEL + 1);
1042 /* restore the area for displaying emeralds */
1043 DrawGameValue_Emeralds(local_player->gems_still_needed);
1045 /* yes, this is all really ugly :-) */
1049 void DrawAllGameValues(int emeralds, int dynamite, int score, int time,
1052 int key[MAX_NUM_KEYS];
1055 for (i = 0; i < MAX_NUM_KEYS; i++)
1056 key[i] = key_bits & (1 << i);
1058 DrawGameValue_Level(level_nr);
1060 DrawGameValue_Emeralds(emeralds);
1061 DrawGameValue_Dynamite(dynamite);
1062 DrawGameValue_Score(score);
1063 DrawGameValue_Time(time);
1065 DrawGameValue_Keys(key);
1068 void DrawGameDoorValues()
1072 if (level.game_engine_type == GAME_ENGINE_TYPE_EM)
1074 DrawGameDoorValues_EM();
1079 DrawGameValue_Level(level_nr);
1081 DrawGameValue_Emeralds(local_player->gems_still_needed);
1082 DrawGameValue_Dynamite(local_player->inventory_size);
1083 DrawGameValue_Score(local_player->score);
1084 DrawGameValue_Time(TimeLeft);
1086 for (i = 0; i < MAX_PLAYERS; i++)
1087 DrawGameValue_Keys(stored_player[i].key);
1090 static void resolve_group_element(int group_element, int recursion_depth)
1092 static int group_nr;
1093 static struct ElementGroupInfo *group;
1094 struct ElementGroupInfo *actual_group = element_info[group_element].group;
1097 if (recursion_depth > NUM_GROUP_ELEMENTS) /* recursion too deep */
1099 Error(ERR_WARN, "recursion too deep when resolving group element %d",
1100 group_element - EL_GROUP_START + 1);
1102 /* replace element which caused too deep recursion by question mark */
1103 group->element_resolved[group->num_elements_resolved++] = EL_UNKNOWN;
1108 if (recursion_depth == 0) /* initialization */
1110 group = element_info[group_element].group;
1111 group_nr = group_element - EL_GROUP_START;
1113 group->num_elements_resolved = 0;
1114 group->choice_pos = 0;
1117 for (i = 0; i < actual_group->num_elements; i++)
1119 int element = actual_group->element[i];
1121 if (group->num_elements_resolved == NUM_FILE_ELEMENTS)
1124 if (IS_GROUP_ELEMENT(element))
1125 resolve_group_element(element, recursion_depth + 1);
1128 group->element_resolved[group->num_elements_resolved++] = element;
1129 element_info[element].in_group[group_nr] = TRUE;
1136 =============================================================================
1138 -----------------------------------------------------------------------------
1139 initialize game engine due to level / tape version number
1140 =============================================================================
1143 static void InitGameEngine()
1145 int i, j, k, l, x, y;
1147 /* set game engine from tape file when re-playing, else from level file */
1148 game.engine_version = (tape.playing ? tape.engine_version :
1149 level.game_version);
1151 /* ---------------------------------------------------------------------- */
1152 /* set flags for bugs and changes according to active game engine version */
1153 /* ---------------------------------------------------------------------- */
1156 Summary of bugfix/change:
1157 Fixed handling for custom elements that change when pushed by the player.
1159 Fixed/changed in version:
1163 Before 3.1.0, custom elements that "change when pushing" changed directly
1164 after the player started pushing them (until then handled in "DigField()").
1165 Since 3.1.0, these custom elements are not changed until the "pushing"
1166 move of the element is finished (now handled in "ContinueMoving()").
1168 Affected levels/tapes:
1169 The first condition is generally needed for all levels/tapes before version
1170 3.1.0, which might use the old behaviour before it was changed; known tapes
1171 that are affected are some tapes from the level set "Walpurgis Gardens" by
1173 The second condition is an exception from the above case and is needed for
1174 the special case of tapes recorded with game (not engine!) version 3.1.0 or
1175 above (including some development versions of 3.1.0), but before it was
1176 known that this change would break tapes like the above and was fixed in
1177 3.1.1, so that the changed behaviour was active although the engine version
1178 while recording maybe was before 3.1.0. There is at least one tape that is
1179 affected by this exception, which is the tape for the one-level set "Bug
1180 Machine" by Juergen Bonhagen.
1183 game.use_change_when_pushing_bug =
1184 (game.engine_version < VERSION_IDENT(3,1,0,0) &&
1186 tape.game_version >= VERSION_IDENT(3,1,0,0) &&
1187 tape.game_version < VERSION_IDENT(3,1,1,0)));
1190 Summary of bugfix/change:
1191 Fixed handling for blocking the field the player leaves when moving.
1193 Fixed/changed in version:
1197 Before 3.1.1, when "block last field when moving" was enabled, the field
1198 the player is leaving when moving was blocked for the time of the move,
1199 and was directly unblocked afterwards. This resulted in the last field
1200 being blocked for exactly one less than the number of frames of one player
1201 move. Additionally, even when blocking was disabled, the last field was
1202 blocked for exactly one frame.
1203 Since 3.1.1, due to changes in player movement handling, the last field
1204 is not blocked at all when blocking is disabled. When blocking is enabled,
1205 the last field is blocked for exactly the number of frames of one player
1206 move. Additionally, if the player is Murphy, the hero of Supaplex, the
1207 last field is blocked for exactly one more than the number of frames of
1210 Affected levels/tapes:
1211 (!!! yet to be determined -- probably many !!!)
1214 game.use_block_last_field_bug =
1215 (game.engine_version < VERSION_IDENT(3,1,1,0));
1218 Summary of bugfix/change:
1219 Changed behaviour of CE changes with multiple changes per single frame.
1221 Fixed/changed in version:
1225 Before 3.2.0-6, only one single CE change was allowed in each engine frame.
1226 This resulted in race conditions where CEs seem to behave strange in some
1227 situations (where triggered CE changes were just skipped because there was
1228 already a CE change on that tile in the playfield in that engine frame).
1229 Since 3.2.0-6, this was changed to allow up to MAX_NUM_CHANGES_PER_FRAME.
1230 (The number of changes per frame must be limited in any case, because else
1231 it is easily possible to define CE changes that would result in an infinite
1232 loop, causing the whole game to freeze. The MAX_NUM_CHANGES_PER_FRAME value
1233 should be set large enough so that it would only be reached in cases where
1234 the corresponding CE change conditions run into a loop. Therefore, it seems
1235 to be reasonable to set MAX_NUM_CHANGES_PER_FRAME to the same value as the
1236 maximal number of change pages for custom elements.)
1238 Affected levels/tapes:
1242 #if USE_ONLY_ONE_CHANGE_PER_FRAME
1243 game.max_num_changes_per_frame = 1;
1245 game.max_num_changes_per_frame =
1246 (game.engine_version < VERSION_IDENT(3,2,0,6) ? 1 : 32);
1249 /* ---------------------------------------------------------------------- */
1251 /* dynamically adjust element properties according to game engine version */
1252 InitElementPropertiesEngine(game.engine_version);
1255 printf("level %d: level version == %06d\n", level_nr, level.game_version);
1256 printf(" tape version == %06d [%s] [file: %06d]\n",
1257 tape.engine_version, (tape.playing ? "PLAYING" : "RECORDING"),
1259 printf(" => game.engine_version == %06d\n", game.engine_version);
1262 /* ---------- recursively resolve group elements ------------------------- */
1264 for (i = 0; i < MAX_NUM_ELEMENTS; i++)
1265 for (j = 0; j < NUM_GROUP_ELEMENTS; j++)
1266 element_info[i].in_group[j] = FALSE;
1268 for (i = 0; i < NUM_GROUP_ELEMENTS; i++)
1269 resolve_group_element(EL_GROUP_START + i, 0);
1271 /* ---------- initialize player's initial move delay --------------------- */
1273 /* dynamically adjust player properties according to level information */
1274 game.initial_move_delay_value =
1275 (level.double_speed ? MOVE_DELAY_HIGH_SPEED : MOVE_DELAY_NORMAL_SPEED);
1277 /* dynamically adjust player properties according to game engine version */
1278 game.initial_move_delay = (game.engine_version <= VERSION_IDENT(2,0,1,0) ?
1279 game.initial_move_delay_value : 0);
1281 /* ---------- initialize player's initial push delay --------------------- */
1283 /* dynamically adjust player properties according to game engine version */
1284 game.initial_push_delay_value =
1285 (game.engine_version < VERSION_IDENT(3,0,7,1) ? 5 : -1);
1287 /* ---------- initialize changing elements ------------------------------- */
1289 /* initialize changing elements information */
1290 for (i = 0; i < MAX_NUM_ELEMENTS; i++)
1292 struct ElementInfo *ei = &element_info[i];
1294 /* this pointer might have been changed in the level editor */
1295 ei->change = &ei->change_page[0];
1297 if (!IS_CUSTOM_ELEMENT(i))
1299 ei->change->target_element = EL_EMPTY_SPACE;
1300 ei->change->delay_fixed = 0;
1301 ei->change->delay_random = 0;
1302 ei->change->delay_frames = 1;
1305 for (j = 0; j < NUM_CHANGE_EVENTS; j++)
1307 ei->has_change_event[j] = FALSE;
1309 ei->event_page_nr[j] = 0;
1310 ei->event_page[j] = &ei->change_page[0];
1314 /* add changing elements from pre-defined list */
1315 for (i = 0; change_delay_list[i].element != EL_UNDEFINED; i++)
1317 struct ChangingElementInfo *ch_delay = &change_delay_list[i];
1318 struct ElementInfo *ei = &element_info[ch_delay->element];
1320 ei->change->target_element = ch_delay->target_element;
1321 ei->change->delay_fixed = ch_delay->change_delay;
1323 ei->change->pre_change_function = ch_delay->pre_change_function;
1324 ei->change->change_function = ch_delay->change_function;
1325 ei->change->post_change_function = ch_delay->post_change_function;
1327 ei->change->can_change = TRUE;
1328 ei->change->can_change_or_has_action = TRUE;
1330 ei->has_change_event[CE_DELAY] = TRUE;
1332 SET_PROPERTY(ch_delay->element, EP_CAN_CHANGE, TRUE);
1333 SET_PROPERTY(ch_delay->element, EP_CAN_CHANGE_OR_HAS_ACTION, TRUE);
1336 /* ---------- initialize internal run-time variables ------------- */
1338 for (i = 0; i < NUM_CUSTOM_ELEMENTS; i++)
1340 struct ElementInfo *ei = &element_info[EL_CUSTOM_START + i];
1342 for (j = 0; j < ei->num_change_pages; j++)
1344 ei->change_page[j].can_change_or_has_action =
1345 (ei->change_page[j].can_change |
1346 ei->change_page[j].has_action);
1350 /* add change events from custom element configuration */
1351 for (i = 0; i < NUM_CUSTOM_ELEMENTS; i++)
1353 struct ElementInfo *ei = &element_info[EL_CUSTOM_START + i];
1355 for (j = 0; j < ei->num_change_pages; j++)
1357 if (!ei->change_page[j].can_change_or_has_action)
1360 for (k = 0; k < NUM_CHANGE_EVENTS; k++)
1362 /* only add event page for the first page found with this event */
1363 if (ei->change_page[j].has_event[k] && !(ei->has_change_event[k]))
1365 ei->has_change_event[k] = TRUE;
1367 ei->event_page_nr[k] = j;
1368 ei->event_page[k] = &ei->change_page[j];
1374 /* ---------- initialize run-time trigger player and element ------------- */
1376 for (i = 0; i < NUM_CUSTOM_ELEMENTS; i++)
1378 struct ElementInfo *ei = &element_info[EL_CUSTOM_START + i];
1380 for (j = 0; j < ei->num_change_pages; j++)
1382 ei->change_page[j].actual_trigger_element = EL_EMPTY;
1383 ei->change_page[j].actual_trigger_player = EL_PLAYER_1;
1384 ei->change_page[j].actual_trigger_side = CH_SIDE_NONE;
1385 ei->change_page[j].actual_trigger_ce_value = 0;
1389 /* ---------- initialize trigger events ---------------------------------- */
1391 /* initialize trigger events information */
1392 for (i = 0; i < MAX_NUM_ELEMENTS; i++)
1393 for (j = 0; j < NUM_CHANGE_EVENTS; j++)
1394 trigger_events[i][j] = FALSE;
1396 /* add trigger events from element change event properties */
1397 for (i = 0; i < MAX_NUM_ELEMENTS; i++)
1399 struct ElementInfo *ei = &element_info[i];
1401 for (j = 0; j < ei->num_change_pages; j++)
1403 if (!ei->change_page[j].can_change_or_has_action)
1406 if (ei->change_page[j].has_event[CE_BY_OTHER_ACTION])
1408 int trigger_element = ei->change_page[j].trigger_element;
1410 for (k = 0; k < NUM_CHANGE_EVENTS; k++)
1412 if (ei->change_page[j].has_event[k])
1414 if (IS_GROUP_ELEMENT(trigger_element))
1416 struct ElementGroupInfo *group =
1417 element_info[trigger_element].group;
1419 for (l = 0; l < group->num_elements_resolved; l++)
1420 trigger_events[group->element_resolved[l]][k] = TRUE;
1423 trigger_events[trigger_element][k] = TRUE;
1430 /* ---------- initialize push delay -------------------------------------- */
1432 /* initialize push delay values to default */
1433 for (i = 0; i < MAX_NUM_ELEMENTS; i++)
1435 if (!IS_CUSTOM_ELEMENT(i))
1437 element_info[i].push_delay_fixed = game.default_push_delay_fixed;
1438 element_info[i].push_delay_random = game.default_push_delay_random;
1442 /* set push delay value for certain elements from pre-defined list */
1443 for (i = 0; push_delay_list[i].element != EL_UNDEFINED; i++)
1445 int e = push_delay_list[i].element;
1447 element_info[e].push_delay_fixed = push_delay_list[i].push_delay_fixed;
1448 element_info[e].push_delay_random = push_delay_list[i].push_delay_random;
1451 /* set push delay value for Supaplex elements for newer engine versions */
1452 if (game.engine_version >= VERSION_IDENT(3,1,0,0))
1454 for (i = 0; i < MAX_NUM_ELEMENTS; i++)
1456 if (IS_SP_ELEMENT(i))
1458 /* set SP push delay to just enough to push under a falling zonk */
1459 int delay = (game.engine_version >= VERSION_IDENT(3,1,1,0) ? 8 : 6);
1461 element_info[i].push_delay_fixed = delay;
1462 element_info[i].push_delay_random = 0;
1467 /* ---------- initialize move stepsize ----------------------------------- */
1469 /* initialize move stepsize values to default */
1470 for (i = 0; i < MAX_NUM_ELEMENTS; i++)
1471 if (!IS_CUSTOM_ELEMENT(i))
1472 element_info[i].move_stepsize = MOVE_STEPSIZE_NORMAL;
1474 /* set move stepsize value for certain elements from pre-defined list */
1475 for (i = 0; move_stepsize_list[i].element != EL_UNDEFINED; i++)
1477 int e = move_stepsize_list[i].element;
1479 element_info[e].move_stepsize = move_stepsize_list[i].move_stepsize;
1482 /* ---------- initialize collect score ----------------------------------- */
1484 /* initialize collect score values for custom elements from initial value */
1485 for (i = 0; i < MAX_NUM_ELEMENTS; i++)
1486 if (IS_CUSTOM_ELEMENT(i))
1487 element_info[i].collect_score = element_info[i].collect_score_initial;
1489 /* ---------- initialize collect count ----------------------------------- */
1491 /* initialize collect count values for non-custom elements */
1492 for (i = 0; i < MAX_NUM_ELEMENTS; i++)
1493 if (!IS_CUSTOM_ELEMENT(i))
1494 element_info[i].collect_count_initial = 0;
1496 /* add collect count values for all elements from pre-defined list */
1497 for (i = 0; collect_count_list[i].element != EL_UNDEFINED; i++)
1498 element_info[collect_count_list[i].element].collect_count_initial =
1499 collect_count_list[i].count;
1501 /* ---------- initialize access direction -------------------------------- */
1503 /* initialize access direction values to default (access from every side) */
1504 for (i = 0; i < MAX_NUM_ELEMENTS; i++)
1505 if (!IS_CUSTOM_ELEMENT(i))
1506 element_info[i].access_direction = MV_ALL_DIRECTIONS;
1508 /* set access direction value for certain elements from pre-defined list */
1509 for (i = 0; access_direction_list[i].element != EL_UNDEFINED; i++)
1510 element_info[access_direction_list[i].element].access_direction =
1511 access_direction_list[i].direction;
1513 /* ---------- initialize explosion content ------------------------------- */
1514 for (i = 0; i < MAX_NUM_ELEMENTS; i++)
1516 if (IS_CUSTOM_ELEMENT(i))
1519 for (y = 0; y < 3; y++) for (x = 0; x < 3; x++)
1521 /* (content for EL_YAMYAM set at run-time with game.yamyam_content_nr) */
1523 element_info[i].content.e[x][y] =
1524 (i == EL_PLAYER_1 ? EL_EMERALD_YELLOW :
1525 i == EL_PLAYER_2 ? EL_EMERALD_RED :
1526 i == EL_PLAYER_3 ? EL_EMERALD :
1527 i == EL_PLAYER_4 ? EL_EMERALD_PURPLE :
1528 i == EL_MOLE ? EL_EMERALD_RED :
1529 i == EL_PENGUIN ? EL_EMERALD_PURPLE :
1530 i == EL_BUG ? (x == 1 && y == 1 ? EL_DIAMOND : EL_EMERALD) :
1531 i == EL_BD_BUTTERFLY ? EL_BD_DIAMOND :
1532 i == EL_SP_ELECTRON ? EL_SP_INFOTRON :
1533 i == EL_AMOEBA_TO_DIAMOND ? level.amoeba_content :
1534 i == EL_WALL_EMERALD ? EL_EMERALD :
1535 i == EL_WALL_DIAMOND ? EL_DIAMOND :
1536 i == EL_WALL_BD_DIAMOND ? EL_BD_DIAMOND :
1537 i == EL_WALL_EMERALD_YELLOW ? EL_EMERALD_YELLOW :
1538 i == EL_WALL_EMERALD_RED ? EL_EMERALD_RED :
1539 i == EL_WALL_EMERALD_PURPLE ? EL_EMERALD_PURPLE :
1540 i == EL_WALL_PEARL ? EL_PEARL :
1541 i == EL_WALL_CRYSTAL ? EL_CRYSTAL :
1547 int get_num_special_action(int element, int action_first, int action_last)
1549 int num_special_action = 0;
1552 for (i = action_first; i <= action_last; i++)
1554 boolean found = FALSE;
1556 for (j = 0; j < NUM_DIRECTIONS; j++)
1557 if (el_act_dir2img(element, i, j) !=
1558 el_act_dir2img(element, ACTION_DEFAULT, j))
1562 num_special_action++;
1567 return num_special_action;
1571 =============================================================================
1573 -----------------------------------------------------------------------------
1574 initialize and start new game
1575 =============================================================================
1580 boolean emulate_bd = TRUE; /* unless non-BOULDERDASH elements found */
1581 boolean emulate_sb = TRUE; /* unless non-SOKOBAN elements found */
1582 boolean emulate_sp = TRUE; /* unless non-SUPAPLEX elements found */
1587 /* don't play tapes over network */
1588 network_playing = (options.network && !tape.playing);
1590 for (i = 0; i < MAX_PLAYERS; i++)
1592 struct PlayerInfo *player = &stored_player[i];
1594 player->index_nr = i;
1595 player->index_bit = (1 << i);
1596 player->element_nr = EL_PLAYER_1 + i;
1598 player->present = FALSE;
1599 player->active = FALSE;
1602 player->effective_action = 0;
1603 player->programmed_action = 0;
1606 player->gems_still_needed = level.gems_needed;
1607 player->sokobanfields_still_needed = 0;
1608 player->lights_still_needed = 0;
1609 player->friends_still_needed = 0;
1611 for (j = 0; j < MAX_NUM_KEYS; j++)
1612 player->key[j] = FALSE;
1614 player->dynabomb_count = 0;
1615 player->dynabomb_size = 1;
1616 player->dynabombs_left = 0;
1617 player->dynabomb_xl = FALSE;
1619 player->MovDir = MV_NONE;
1622 player->GfxDir = MV_NONE;
1623 player->GfxAction = ACTION_DEFAULT;
1625 player->StepFrame = 0;
1627 player->use_murphy = FALSE;
1628 player->artwork_element =
1629 (level.use_artwork_element[i] ? level.artwork_element[i] :
1630 player->element_nr);
1632 player->block_last_field = FALSE; /* initialized in InitPlayerField() */
1633 player->block_delay_adjustment = 0; /* initialized in InitPlayerField() */
1635 player->can_fall_into_acid = CAN_MOVE_INTO_ACID(player->element_nr);
1637 player->actual_frame_counter = 0;
1639 player->step_counter = 0;
1641 player->last_move_dir = MV_NONE;
1643 player->is_waiting = FALSE;
1644 player->is_moving = FALSE;
1645 player->is_auto_moving = FALSE;
1646 player->is_digging = FALSE;
1647 player->is_snapping = FALSE;
1648 player->is_collecting = FALSE;
1649 player->is_pushing = FALSE;
1650 player->is_switching = FALSE;
1651 player->is_dropping = FALSE;
1653 player->is_bored = FALSE;
1654 player->is_sleeping = FALSE;
1656 player->cannot_move = FALSE;
1658 player->frame_counter_bored = -1;
1659 player->frame_counter_sleeping = -1;
1661 player->anim_delay_counter = 0;
1662 player->post_delay_counter = 0;
1664 player->action_waiting = ACTION_DEFAULT;
1665 player->last_action_waiting = ACTION_DEFAULT;
1666 player->special_action_bored = ACTION_DEFAULT;
1667 player->special_action_sleeping = ACTION_DEFAULT;
1669 /* set number of special actions for bored and sleeping animation */
1670 player->num_special_action_bored =
1671 get_num_special_action(player->artwork_element,
1672 ACTION_BORING_1, ACTION_BORING_LAST);
1673 player->num_special_action_sleeping =
1674 get_num_special_action(player->artwork_element,
1675 ACTION_SLEEPING_1, ACTION_SLEEPING_LAST);
1677 player->switch_x = -1;
1678 player->switch_y = -1;
1680 player->drop_x = -1;
1681 player->drop_y = -1;
1683 player->show_envelope = 0;
1685 player->move_delay = game.initial_move_delay;
1686 player->move_delay_value = game.initial_move_delay_value;
1688 player->move_delay_value_next = -1;
1690 player->move_delay_reset_counter = 0;
1692 player->push_delay = -1; /* initialized when pushing starts */
1693 player->push_delay_value = game.initial_push_delay_value;
1695 player->drop_delay = 0;
1697 player->last_jx = player->last_jy = 0;
1698 player->jx = player->jy = 0;
1700 player->shield_normal_time_left = 0;
1701 player->shield_deadly_time_left = 0;
1703 player->inventory_infinite_element = EL_UNDEFINED;
1704 player->inventory_size = 0;
1706 DigField(player, 0, 0, 0, 0, 0, 0, DF_NO_PUSH);
1707 SnapField(player, 0, 0);
1709 player->LevelSolved = FALSE;
1710 player->GameOver = FALSE;
1713 network_player_action_received = FALSE;
1715 #if defined(NETWORK_AVALIABLE)
1716 /* initial null action */
1717 if (network_playing)
1718 SendToServer_MovePlayer(MV_NONE);
1727 TimeLeft = level.time;
1730 ScreenMovDir = MV_NONE;
1734 ScrollStepSize = 0; /* will be correctly initialized by ScrollScreen() */
1736 AllPlayersGone = FALSE;
1738 game.yamyam_content_nr = 0;
1739 game.magic_wall_active = FALSE;
1740 game.magic_wall_time_left = 0;
1741 game.light_time_left = 0;
1742 game.timegate_time_left = 0;
1743 game.switchgate_pos = 0;
1744 game.wind_direction = level.wind_direction_initial;
1745 game.gravity = level.initial_gravity;
1746 game.explosions_delayed = TRUE;
1748 game.lenses_time_left = 0;
1749 game.magnify_time_left = 0;
1751 game.envelope_active = FALSE;
1753 for (i = 0; i < NUM_BELTS; i++)
1755 game.belt_dir[i] = MV_NONE;
1756 game.belt_dir_nr[i] = 3; /* not moving, next moving left */
1759 for (i = 0; i < MAX_NUM_AMOEBA; i++)
1760 AmoebaCnt[i] = AmoebaCnt2[i] = 0;
1762 for (x = 0; x < lev_fieldx; x++)
1764 for (y = 0; y < lev_fieldy; y++)
1766 Feld[x][y] = level.field[x][y];
1767 MovPos[x][y] = MovDir[x][y] = MovDelay[x][y] = 0;
1768 ChangeDelay[x][y] = 0;
1769 ChangePage[x][y] = -1;
1770 #if USE_NEW_CUSTOM_VALUE
1771 CustomValue[x][y] = 0; /* initialized in InitField() */
1773 Store[x][y] = Store2[x][y] = StorePlayer[x][y] = Back[x][y] = 0;
1775 WasJustMoving[x][y] = 0;
1776 WasJustFalling[x][y] = 0;
1777 CheckCollision[x][y] = 0;
1779 Pushed[x][y] = FALSE;
1781 ChangeCount[x][y] = 0;
1782 ChangeEvent[x][y] = -1;
1784 ExplodePhase[x][y] = 0;
1785 ExplodeDelay[x][y] = 0;
1786 ExplodeField[x][y] = EX_TYPE_NONE;
1788 RunnerVisit[x][y] = 0;
1789 PlayerVisit[x][y] = 0;
1792 GfxRandom[x][y] = INIT_GFX_RANDOM();
1793 GfxElement[x][y] = EL_UNDEFINED;
1794 GfxAction[x][y] = ACTION_DEFAULT;
1795 GfxDir[x][y] = MV_NONE;
1799 for (y = 0; y < lev_fieldy; y++)
1801 for (x = 0; x < lev_fieldx; x++)
1803 if (emulate_bd && !IS_BD_ELEMENT(Feld[x][y]))
1805 if (emulate_sb && !IS_SB_ELEMENT(Feld[x][y]))
1807 if (emulate_sp && !IS_SP_ELEMENT(Feld[x][y]))
1810 InitField(x, y, TRUE);
1816 game.emulation = (emulate_bd ? EMU_BOULDERDASH :
1817 emulate_sb ? EMU_SOKOBAN :
1818 emulate_sp ? EMU_SUPAPLEX : EMU_NONE);
1820 #if USE_NEW_ALL_SLIPPERY
1821 /* initialize type of slippery elements */
1822 for (i = 0; i < MAX_NUM_ELEMENTS; i++)
1824 if (!IS_CUSTOM_ELEMENT(i))
1826 /* default: elements slip down either to the left or right randomly */
1827 element_info[i].slippery_type = SLIPPERY_ANY_RANDOM;
1829 /* SP style elements prefer to slip down on the left side */
1830 if (game.engine_version >= VERSION_IDENT(3,1,1,0) && IS_SP_ELEMENT(i))
1831 element_info[i].slippery_type = SLIPPERY_ANY_LEFT_RIGHT;
1833 /* BD style elements prefer to slip down on the left side */
1834 if (game.emulation == EMU_BOULDERDASH)
1835 element_info[i].slippery_type = SLIPPERY_ANY_LEFT_RIGHT;
1840 /* initialize explosion and ignition delay */
1841 for (i = 0; i < MAX_NUM_ELEMENTS; i++)
1843 if (!IS_CUSTOM_ELEMENT(i))
1846 int delay = (((IS_SP_ELEMENT(i) && i != EL_EMPTY_SPACE) &&
1847 game.engine_version >= VERSION_IDENT(3,1,0,0)) ||
1848 game.emulation == EMU_SUPAPLEX ? 3 : 2);
1849 int last_phase = (num_phase + 1) * delay;
1850 int half_phase = (num_phase / 2) * delay;
1852 element_info[i].explosion_delay = last_phase - 1;
1853 element_info[i].ignition_delay = half_phase;
1855 if (i == EL_BLACK_ORB)
1856 element_info[i].ignition_delay = 1;
1860 if (element_info[i].explosion_delay < 1) /* !!! check again !!! */
1861 element_info[i].explosion_delay = 1;
1863 if (element_info[i].ignition_delay < 1) /* !!! check again !!! */
1864 element_info[i].ignition_delay = 1;
1868 /* correct non-moving belts to start moving left */
1869 for (i = 0; i < NUM_BELTS; i++)
1870 if (game.belt_dir[i] == MV_NONE)
1871 game.belt_dir_nr[i] = 3; /* not moving, next moving left */
1873 /* check if any connected player was not found in playfield */
1874 for (i = 0; i < MAX_PLAYERS; i++)
1876 struct PlayerInfo *player = &stored_player[i];
1878 if (player->connected && !player->present)
1880 for (j = 0; j < MAX_PLAYERS; j++)
1882 struct PlayerInfo *some_player = &stored_player[j];
1883 int jx = some_player->jx, jy = some_player->jy;
1885 /* assign first free player found that is present in the playfield */
1886 if (some_player->present && !some_player->connected)
1888 player->present = TRUE;
1889 player->active = TRUE;
1891 some_player->present = FALSE;
1892 some_player->active = FALSE;
1895 player->element_nr = some_player->element_nr;
1898 player->artwork_element = some_player->artwork_element;
1900 player->block_last_field = some_player->block_last_field;
1901 player->block_delay_adjustment = some_player->block_delay_adjustment;
1903 StorePlayer[jx][jy] = player->element_nr;
1904 player->jx = player->last_jx = jx;
1905 player->jy = player->last_jy = jy;
1915 /* when playing a tape, eliminate all players which do not participate */
1917 for (i = 0; i < MAX_PLAYERS; i++)
1919 if (stored_player[i].active && !tape.player_participates[i])
1921 struct PlayerInfo *player = &stored_player[i];
1922 int jx = player->jx, jy = player->jy;
1924 player->active = FALSE;
1925 StorePlayer[jx][jy] = 0;
1926 Feld[jx][jy] = EL_EMPTY;
1930 else if (!options.network && !setup.team_mode) /* && !tape.playing */
1932 /* when in single player mode, eliminate all but the first active player */
1934 for (i = 0; i < MAX_PLAYERS; i++)
1936 if (stored_player[i].active)
1938 for (j = i + 1; j < MAX_PLAYERS; j++)
1940 if (stored_player[j].active)
1942 struct PlayerInfo *player = &stored_player[j];
1943 int jx = player->jx, jy = player->jy;
1945 player->active = FALSE;
1946 player->present = FALSE;
1948 StorePlayer[jx][jy] = 0;
1949 Feld[jx][jy] = EL_EMPTY;
1956 /* when recording the game, store which players take part in the game */
1959 for (i = 0; i < MAX_PLAYERS; i++)
1960 if (stored_player[i].active)
1961 tape.player_participates[i] = TRUE;
1966 for (i = 0; i < MAX_PLAYERS; i++)
1968 struct PlayerInfo *player = &stored_player[i];
1970 printf("Player %d: present == %d, connected == %d, active == %d.\n",
1975 if (local_player == player)
1976 printf("Player %d is local player.\n", i+1);
1980 if (BorderElement == EL_EMPTY)
1983 SBX_Right = lev_fieldx - SCR_FIELDX;
1985 SBY_Lower = lev_fieldy - SCR_FIELDY;
1990 SBX_Right = lev_fieldx - SCR_FIELDX + 1;
1992 SBY_Lower = lev_fieldy - SCR_FIELDY + 1;
1995 if (lev_fieldx + (SBX_Left == -1 ? 2 : 0) <= SCR_FIELDX)
1996 SBX_Left = SBX_Right = -1 * (SCR_FIELDX - lev_fieldx) / 2;
1998 if (lev_fieldy + (SBY_Upper == -1 ? 2 : 0) <= SCR_FIELDY)
1999 SBY_Upper = SBY_Lower = -1 * (SCR_FIELDY - lev_fieldy) / 2;
2001 /* if local player not found, look for custom element that might create
2002 the player (make some assumptions about the right custom element) */
2003 if (!local_player->present)
2005 int start_x = 0, start_y = 0;
2006 int found_rating = 0;
2007 int found_element = EL_UNDEFINED;
2008 int player_nr = local_player->index_nr;
2010 for (y = 0; y < lev_fieldy; y++) for (x = 0; x < lev_fieldx; x++)
2012 int element = Feld[x][y];
2017 if (level.use_start_element[player_nr] &&
2018 level.start_element[player_nr] == element &&
2025 found_element = element;
2028 if (!IS_CUSTOM_ELEMENT(element))
2031 if (CAN_CHANGE(element))
2033 for (i = 0; i < element_info[element].num_change_pages; i++)
2035 /* check for player created from custom element as single target */
2036 content = element_info[element].change_page[i].target_element;
2037 is_player = ELEM_IS_PLAYER(content);
2039 if (is_player && (found_rating < 3 || element < found_element))
2045 found_element = element;
2050 for (yy = 0; yy < 3; yy++) for (xx = 0; xx < 3; xx++)
2052 /* check for player created from custom element as explosion content */
2053 content = element_info[element].content.e[xx][yy];
2054 is_player = ELEM_IS_PLAYER(content);
2056 if (is_player && (found_rating < 2 || element < found_element))
2058 start_x = x + xx - 1;
2059 start_y = y + yy - 1;
2062 found_element = element;
2065 if (!CAN_CHANGE(element))
2068 for (i = 0; i < element_info[element].num_change_pages; i++)
2070 /* check for player created from custom element as extended target */
2072 element_info[element].change_page[i].target_content.e[xx][yy];
2074 is_player = ELEM_IS_PLAYER(content);
2076 if (is_player && (found_rating < 1 || element < found_element))
2078 start_x = x + xx - 1;
2079 start_y = y + yy - 1;
2082 found_element = element;
2088 scroll_x = (start_x < SBX_Left + MIDPOSX ? SBX_Left :
2089 start_x > SBX_Right + MIDPOSX ? SBX_Right :
2092 scroll_y = (start_y < SBY_Upper + MIDPOSY ? SBY_Upper :
2093 start_y > SBY_Lower + MIDPOSY ? SBY_Lower :
2098 scroll_x = (local_player->jx < SBX_Left + MIDPOSX ? SBX_Left :
2099 local_player->jx > SBX_Right + MIDPOSX ? SBX_Right :
2100 local_player->jx - MIDPOSX);
2102 scroll_y = (local_player->jy < SBY_Upper + MIDPOSY ? SBY_Upper :
2103 local_player->jy > SBY_Lower + MIDPOSY ? SBY_Lower :
2104 local_player->jy - MIDPOSY);
2107 if (!game.restart_level)
2108 CloseDoor(DOOR_CLOSE_1);
2110 /* !!! FIX THIS (START) !!! */
2111 if (level.game_engine_type == GAME_ENGINE_TYPE_EM)
2113 InitGameEngine_EM();
2120 /* after drawing the level, correct some elements */
2121 if (game.timegate_time_left == 0)
2122 CloseAllOpenTimegates();
2124 if (setup.soft_scrolling)
2125 BlitBitmap(fieldbuffer, backbuffer, FX, FY, SXSIZE, SYSIZE, SX, SY);
2127 redraw_mask |= REDRAW_FROM_BACKBUFFER;
2130 /* !!! FIX THIS (END) !!! */
2132 if (!game.restart_level)
2134 /* copy default game door content to main double buffer */
2135 BlitBitmap(graphic_info[IMG_GLOBAL_DOOR].bitmap, drawto,
2136 DOOR_GFX_PAGEX5, DOOR_GFX_PAGEY1, DXSIZE, DYSIZE, DX, DY);
2139 DrawGameDoorValues();
2141 if (!game.restart_level)
2145 game_gadget[SOUND_CTRL_ID_MUSIC]->checked = setup.sound_music;
2146 game_gadget[SOUND_CTRL_ID_LOOPS]->checked = setup.sound_loops;
2147 game_gadget[SOUND_CTRL_ID_SIMPLE]->checked = setup.sound_simple;
2151 /* copy actual game door content to door double buffer for OpenDoor() */
2152 BlitBitmap(drawto, bitmap_db_door,
2153 DX, DY, DXSIZE, DYSIZE, DOOR_GFX_PAGEX1, DOOR_GFX_PAGEY1);
2155 OpenDoor(DOOR_OPEN_ALL);
2157 PlaySoundStereo(SND_GAME_STARTING, SOUND_MIDDLE);
2159 if (setup.sound_music)
2162 KeyboardAutoRepeatOffUnlessAutoplay();
2166 for (i = 0; i < MAX_PLAYERS; i++)
2167 printf("Player %d %sactive.\n",
2168 i + 1, (stored_player[i].active ? "" : "not "));
2172 game.restart_level = FALSE;
2175 void UpdateEngineValues(int actual_scroll_x, int actual_scroll_y)
2177 /* this is used for non-R'n'D game engines to update certain engine values */
2179 /* needed to determine if sounds are played within the visible screen area */
2180 scroll_x = actual_scroll_x;
2181 scroll_y = actual_scroll_y;
2184 void InitMovDir(int x, int y)
2186 int i, element = Feld[x][y];
2187 static int xy[4][2] =
2194 static int direction[3][4] =
2196 { MV_RIGHT, MV_UP, MV_LEFT, MV_DOWN },
2197 { MV_LEFT, MV_DOWN, MV_RIGHT, MV_UP },
2198 { MV_LEFT, MV_RIGHT, MV_UP, MV_DOWN }
2207 Feld[x][y] = EL_BUG;
2208 MovDir[x][y] = direction[0][element - EL_BUG_RIGHT];
2211 case EL_SPACESHIP_RIGHT:
2212 case EL_SPACESHIP_UP:
2213 case EL_SPACESHIP_LEFT:
2214 case EL_SPACESHIP_DOWN:
2215 Feld[x][y] = EL_SPACESHIP;
2216 MovDir[x][y] = direction[0][element - EL_SPACESHIP_RIGHT];
2219 case EL_BD_BUTTERFLY_RIGHT:
2220 case EL_BD_BUTTERFLY_UP:
2221 case EL_BD_BUTTERFLY_LEFT:
2222 case EL_BD_BUTTERFLY_DOWN:
2223 Feld[x][y] = EL_BD_BUTTERFLY;
2224 MovDir[x][y] = direction[0][element - EL_BD_BUTTERFLY_RIGHT];
2227 case EL_BD_FIREFLY_RIGHT:
2228 case EL_BD_FIREFLY_UP:
2229 case EL_BD_FIREFLY_LEFT:
2230 case EL_BD_FIREFLY_DOWN:
2231 Feld[x][y] = EL_BD_FIREFLY;
2232 MovDir[x][y] = direction[0][element - EL_BD_FIREFLY_RIGHT];
2235 case EL_PACMAN_RIGHT:
2237 case EL_PACMAN_LEFT:
2238 case EL_PACMAN_DOWN:
2239 Feld[x][y] = EL_PACMAN;
2240 MovDir[x][y] = direction[0][element - EL_PACMAN_RIGHT];
2243 case EL_SP_SNIKSNAK:
2244 MovDir[x][y] = MV_UP;
2247 case EL_SP_ELECTRON:
2248 MovDir[x][y] = MV_LEFT;
2255 Feld[x][y] = EL_MOLE;
2256 MovDir[x][y] = direction[2][element - EL_MOLE_LEFT];
2260 if (IS_CUSTOM_ELEMENT(element))
2262 struct ElementInfo *ei = &element_info[element];
2263 int move_direction_initial = ei->move_direction_initial;
2264 int move_pattern = ei->move_pattern;
2266 if (move_direction_initial == MV_START_PREVIOUS)
2268 if (MovDir[x][y] != MV_NONE)
2271 move_direction_initial = MV_START_AUTOMATIC;
2274 if (move_direction_initial == MV_START_RANDOM)
2275 MovDir[x][y] = 1 << RND(4);
2276 else if (move_direction_initial & MV_ANY_DIRECTION)
2277 MovDir[x][y] = move_direction_initial;
2278 else if (move_pattern == MV_ALL_DIRECTIONS ||
2279 move_pattern == MV_TURNING_LEFT ||
2280 move_pattern == MV_TURNING_RIGHT ||
2281 move_pattern == MV_TURNING_LEFT_RIGHT ||
2282 move_pattern == MV_TURNING_RIGHT_LEFT ||
2283 move_pattern == MV_TURNING_RANDOM)
2284 MovDir[x][y] = 1 << RND(4);
2285 else if (move_pattern == MV_HORIZONTAL)
2286 MovDir[x][y] = (RND(2) ? MV_LEFT : MV_RIGHT);
2287 else if (move_pattern == MV_VERTICAL)
2288 MovDir[x][y] = (RND(2) ? MV_UP : MV_DOWN);
2289 else if (move_pattern & MV_ANY_DIRECTION)
2290 MovDir[x][y] = element_info[element].move_pattern;
2291 else if (move_pattern == MV_ALONG_LEFT_SIDE ||
2292 move_pattern == MV_ALONG_RIGHT_SIDE)
2294 /* use random direction as default start direction */
2295 if (game.engine_version >= VERSION_IDENT(3,1,0,0))
2296 MovDir[x][y] = 1 << RND(4);
2298 for (i = 0; i < NUM_DIRECTIONS; i++)
2300 int x1 = x + xy[i][0];
2301 int y1 = y + xy[i][1];
2303 if (!IN_LEV_FIELD(x1, y1) || !IS_FREE(x1, y1))
2305 if (move_pattern == MV_ALONG_RIGHT_SIDE)
2306 MovDir[x][y] = direction[0][i];
2308 MovDir[x][y] = direction[1][i];
2317 MovDir[x][y] = 1 << RND(4);
2319 if (element != EL_BUG &&
2320 element != EL_SPACESHIP &&
2321 element != EL_BD_BUTTERFLY &&
2322 element != EL_BD_FIREFLY)
2325 for (i = 0; i < NUM_DIRECTIONS; i++)
2327 int x1 = x + xy[i][0];
2328 int y1 = y + xy[i][1];
2330 if (!IN_LEV_FIELD(x1, y1) || !IS_FREE(x1, y1))
2332 if (element == EL_BUG || element == EL_BD_BUTTERFLY)
2334 MovDir[x][y] = direction[0][i];
2337 else if (element == EL_SPACESHIP || element == EL_BD_FIREFLY ||
2338 element == EL_SP_SNIKSNAK || element == EL_SP_ELECTRON)
2340 MovDir[x][y] = direction[1][i];
2349 GfxDir[x][y] = MovDir[x][y];
2352 void InitAmoebaNr(int x, int y)
2355 int group_nr = AmoebeNachbarNr(x, y);
2359 for (i = 1; i < MAX_NUM_AMOEBA; i++)
2361 if (AmoebaCnt[i] == 0)
2369 AmoebaNr[x][y] = group_nr;
2370 AmoebaCnt[group_nr]++;
2371 AmoebaCnt2[group_nr]++;
2377 boolean raise_level = FALSE;
2379 if (local_player->MovPos)
2382 if (tape.auto_play) /* tape might already be stopped here */
2383 tape.auto_play_level_solved = TRUE;
2385 local_player->LevelSolved = FALSE;
2387 PlaySoundStereo(SND_GAME_WINNING, SOUND_MIDDLE);
2391 if (!tape.playing && setup.sound_loops)
2392 PlaySoundExt(SND_GAME_LEVELTIME_BONUS, SOUND_MAX_VOLUME, SOUND_MIDDLE,
2393 SND_CTRL_PLAY_LOOP);
2395 while (TimeLeft > 0)
2397 if (!tape.playing && !setup.sound_loops)
2398 PlaySoundStereo(SND_GAME_LEVELTIME_BONUS, SOUND_MIDDLE);
2400 if (TimeLeft > 100 && TimeLeft % 10 == 0)
2403 RaiseScore(level.score[SC_TIME_BONUS] * 10);
2408 RaiseScore(level.score[SC_TIME_BONUS]);
2411 DrawGameValue_Time(TimeLeft);
2419 if (!tape.playing && setup.sound_loops)
2420 StopSound(SND_GAME_LEVELTIME_BONUS);
2422 else if (level.time == 0) /* level without time limit */
2424 if (!tape.playing && setup.sound_loops)
2425 PlaySoundExt(SND_GAME_LEVELTIME_BONUS, SOUND_MAX_VOLUME, SOUND_MIDDLE,
2426 SND_CTRL_PLAY_LOOP);
2428 while (TimePlayed < 999)
2430 if (!tape.playing && !setup.sound_loops)
2431 PlaySoundStereo(SND_GAME_LEVELTIME_BONUS, SOUND_MIDDLE);
2433 if (TimePlayed < 900 && TimePlayed % 10 == 0)
2436 RaiseScore(level.score[SC_TIME_BONUS] * 10);
2441 RaiseScore(level.score[SC_TIME_BONUS]);
2444 DrawGameValue_Time(TimePlayed);
2452 if (!tape.playing && setup.sound_loops)
2453 StopSound(SND_GAME_LEVELTIME_BONUS);
2456 /* close exit door after last player */
2457 if (AllPlayersGone && ExitX >= 0 && ExitY >= 0 &&
2458 (Feld[ExitX][ExitY] == EL_EXIT_OPEN ||
2459 Feld[ExitX][ExitY] == EL_SP_EXIT_OPEN))
2461 int element = Feld[ExitX][ExitY];
2463 Feld[ExitX][ExitY] = (element == EL_EXIT_OPEN ? EL_EXIT_CLOSING :
2464 EL_SP_EXIT_CLOSING);
2466 PlayLevelSoundElementAction(ExitX, ExitY, element, ACTION_CLOSING);
2469 /* player disappears */
2470 if (ExitX >= 0 && ExitY >= 0)
2471 DrawLevelField(ExitX, ExitY);
2478 CloseDoor(DOOR_CLOSE_1);
2483 SaveTape(tape.level_nr); /* Ask to save tape */
2486 if (level_nr == leveldir_current->handicap_level)
2488 leveldir_current->handicap_level++;
2489 SaveLevelSetup_SeriesInfo();
2492 if (level_editor_test_game)
2493 local_player->score = -1; /* no highscore when playing from editor */
2494 else if (level_nr < leveldir_current->last_level)
2495 raise_level = TRUE; /* advance to next level */
2497 if ((hi_pos = NewHiScore()) >= 0)
2499 game_status = GAME_MODE_SCORES;
2500 DrawHallOfFame(hi_pos);
2509 game_status = GAME_MODE_MAIN;
2526 LoadScore(level_nr);
2528 if (strcmp(setup.player_name, EMPTY_PLAYER_NAME) == 0 ||
2529 local_player->score < highscore[MAX_SCORE_ENTRIES - 1].Score)
2532 for (k = 0; k < MAX_SCORE_ENTRIES; k++)
2534 if (local_player->score > highscore[k].Score)
2536 /* player has made it to the hall of fame */
2538 if (k < MAX_SCORE_ENTRIES - 1)
2540 int m = MAX_SCORE_ENTRIES - 1;
2543 for (l = k; l < MAX_SCORE_ENTRIES; l++)
2544 if (!strcmp(setup.player_name, highscore[l].Name))
2546 if (m == k) /* player's new highscore overwrites his old one */
2550 for (l = m; l > k; l--)
2552 strcpy(highscore[l].Name, highscore[l - 1].Name);
2553 highscore[l].Score = highscore[l - 1].Score;
2560 strncpy(highscore[k].Name, setup.player_name, MAX_PLAYER_NAME_LEN);
2561 highscore[k].Name[MAX_PLAYER_NAME_LEN] = '\0';
2562 highscore[k].Score = local_player->score;
2568 else if (!strncmp(setup.player_name, highscore[k].Name,
2569 MAX_PLAYER_NAME_LEN))
2570 break; /* player already there with a higher score */
2576 SaveScore(level_nr);
2581 inline static int getElementMoveStepsize(int x, int y)
2583 int element = Feld[x][y];
2584 int direction = MovDir[x][y];
2585 int dx = (direction == MV_LEFT ? -1 : direction == MV_RIGHT ? +1 : 0);
2586 int dy = (direction == MV_UP ? -1 : direction == MV_DOWN ? +1 : 0);
2587 int horiz_move = (dx != 0);
2588 int sign = (horiz_move ? dx : dy);
2589 int step = sign * element_info[element].move_stepsize;
2591 /* special values for move stepsize for spring and things on conveyor belt */
2595 if (element == EL_SPRING)
2596 step = sign * MOVE_STEPSIZE_NORMAL * 2;
2597 else if (CAN_FALL(element) && !CAN_MOVE(element) &&
2598 y < lev_fieldy - 1 && IS_BELT_ACTIVE(Feld[x][y + 1]))
2599 step = sign * MOVE_STEPSIZE_NORMAL / 2;
2601 if (CAN_FALL(element) &&
2602 y < lev_fieldy - 1 && IS_BELT_ACTIVE(Feld[x][y + 1]))
2603 step = sign * MOVE_STEPSIZE_NORMAL / 2;
2604 else if (element == EL_SPRING)
2605 step = sign * MOVE_STEPSIZE_NORMAL * 2;
2612 void InitPlayerGfxAnimation(struct PlayerInfo *player, int action, int dir)
2614 if (player->GfxAction != action || player->GfxDir != dir)
2617 printf("Player frame reset! (%d => %d, %d => %d)\n",
2618 player->GfxAction, action, player->GfxDir, dir);
2621 player->GfxAction = action;
2622 player->GfxDir = dir;
2624 player->StepFrame = 0;
2628 static void ResetRandomAnimationValue(int x, int y)
2630 GfxRandom[x][y] = INIT_GFX_RANDOM();
2633 static void ResetGfxAnimation(int x, int y)
2636 GfxAction[x][y] = ACTION_DEFAULT;
2637 GfxDir[x][y] = MovDir[x][y];
2640 void InitMovingField(int x, int y, int direction)
2642 int element = Feld[x][y];
2643 int dx = (direction == MV_LEFT ? -1 : direction == MV_RIGHT ? +1 : 0);
2644 int dy = (direction == MV_UP ? -1 : direction == MV_DOWN ? +1 : 0);
2648 if (!WasJustMoving[x][y] || direction != MovDir[x][y])
2649 ResetGfxAnimation(x, y);
2651 MovDir[x][y] = direction;
2652 GfxDir[x][y] = direction;
2653 GfxAction[x][y] = (direction == MV_DOWN && CAN_FALL(element) ?
2654 ACTION_FALLING : ACTION_MOVING);
2656 /* this is needed for CEs with property "can move" / "not moving" */
2658 if (getElementMoveStepsize(x, y) != 0) /* moving or being moved */
2660 if (Feld[newx][newy] == EL_EMPTY)
2661 Feld[newx][newy] = EL_BLOCKED;
2663 MovDir[newx][newy] = MovDir[x][y];
2665 #if USE_NEW_CUSTOM_VALUE
2666 CustomValue[newx][newy] = CustomValue[x][y];
2669 GfxFrame[newx][newy] = GfxFrame[x][y];
2670 GfxRandom[newx][newy] = GfxRandom[x][y];
2671 GfxAction[newx][newy] = GfxAction[x][y];
2672 GfxDir[newx][newy] = GfxDir[x][y];
2676 void Moving2Blocked(int x, int y, int *goes_to_x, int *goes_to_y)
2678 int direction = MovDir[x][y];
2679 int newx = x + (direction == MV_LEFT ? -1 : direction == MV_RIGHT ? +1 : 0);
2680 int newy = y + (direction == MV_UP ? -1 : direction == MV_DOWN ? +1 : 0);
2686 void Blocked2Moving(int x, int y, int *comes_from_x, int *comes_from_y)
2688 int oldx = x, oldy = y;
2689 int direction = MovDir[x][y];
2691 if (direction == MV_LEFT)
2693 else if (direction == MV_RIGHT)
2695 else if (direction == MV_UP)
2697 else if (direction == MV_DOWN)
2700 *comes_from_x = oldx;
2701 *comes_from_y = oldy;
2704 int MovingOrBlocked2Element(int x, int y)
2706 int element = Feld[x][y];
2708 if (element == EL_BLOCKED)
2712 Blocked2Moving(x, y, &oldx, &oldy);
2713 return Feld[oldx][oldy];
2719 static int MovingOrBlocked2ElementIfNotLeaving(int x, int y)
2721 /* like MovingOrBlocked2Element(), but if element is moving
2722 and (x,y) is the field the moving element is just leaving,
2723 return EL_BLOCKED instead of the element value */
2724 int element = Feld[x][y];
2726 if (IS_MOVING(x, y))
2728 if (element == EL_BLOCKED)
2732 Blocked2Moving(x, y, &oldx, &oldy);
2733 return Feld[oldx][oldy];
2742 static void RemoveField(int x, int y)
2744 Feld[x][y] = EL_EMPTY;
2750 #if USE_NEW_CUSTOM_VALUE
2751 CustomValue[x][y] = 0;
2755 ChangeDelay[x][y] = 0;
2756 ChangePage[x][y] = -1;
2757 Pushed[x][y] = FALSE;
2760 ExplodeField[x][y] = EX_TYPE_NONE;
2763 GfxElement[x][y] = EL_UNDEFINED;
2764 GfxAction[x][y] = ACTION_DEFAULT;
2765 GfxDir[x][y] = MV_NONE;
2768 void RemoveMovingField(int x, int y)
2770 int oldx = x, oldy = y, newx = x, newy = y;
2771 int element = Feld[x][y];
2772 int next_element = EL_UNDEFINED;
2774 if (element != EL_BLOCKED && !IS_MOVING(x, y))
2777 if (IS_MOVING(x, y))
2779 Moving2Blocked(x, y, &newx, &newy);
2781 if (Feld[newx][newy] != EL_BLOCKED)
2783 /* element is moving, but target field is not free (blocked), but
2784 already occupied by something different (example: acid pool);
2785 in this case, only remove the moving field, but not the target */
2787 RemoveField(oldx, oldy);
2789 Store[oldx][oldy] = Store2[oldx][oldy] = 0;
2791 DrawLevelField(oldx, oldy);
2796 else if (element == EL_BLOCKED)
2798 Blocked2Moving(x, y, &oldx, &oldy);
2799 if (!IS_MOVING(oldx, oldy))
2803 if (element == EL_BLOCKED &&
2804 (Feld[oldx][oldy] == EL_QUICKSAND_EMPTYING ||
2805 Feld[oldx][oldy] == EL_MAGIC_WALL_EMPTYING ||
2806 Feld[oldx][oldy] == EL_BD_MAGIC_WALL_EMPTYING ||
2807 Feld[oldx][oldy] == EL_AMOEBA_DROPPING))
2808 next_element = get_next_element(Feld[oldx][oldy]);
2810 RemoveField(oldx, oldy);
2811 RemoveField(newx, newy);
2813 Store[oldx][oldy] = Store2[oldx][oldy] = 0;
2815 if (next_element != EL_UNDEFINED)
2816 Feld[oldx][oldy] = next_element;
2818 DrawLevelField(oldx, oldy);
2819 DrawLevelField(newx, newy);
2822 void DrawDynamite(int x, int y)
2824 int sx = SCREENX(x), sy = SCREENY(y);
2825 int graphic = el2img(Feld[x][y]);
2828 if (!IN_SCR_FIELD(sx, sy) || IS_PLAYER(x, y))
2831 if (IS_WALKABLE_INSIDE(Back[x][y]))
2835 DrawGraphic(sx, sy, el2img(Back[x][y]), 0);
2836 else if (Store[x][y])
2837 DrawGraphic(sx, sy, el2img(Store[x][y]), 0);
2839 frame = getGraphicAnimationFrame(graphic, GfxFrame[x][y]);
2841 if (Back[x][y] || Store[x][y])
2842 DrawGraphicThruMask(sx, sy, graphic, frame);
2844 DrawGraphic(sx, sy, graphic, frame);
2847 void CheckDynamite(int x, int y)
2849 if (MovDelay[x][y] != 0) /* dynamite is still waiting to explode */
2853 if (MovDelay[x][y] != 0)
2856 PlayLevelSoundActionIfLoop(x, y, ACTION_ACTIVE);
2862 StopLevelSoundActionIfLoop(x, y, ACTION_ACTIVE);
2867 void DrawRelocatePlayer(struct PlayerInfo *player)
2869 boolean ffwd_delay = (tape.playing && tape.fast_forward);
2870 boolean no_delay = (tape.warp_forward);
2871 int frame_delay_value = (ffwd_delay ? FfwdFrameDelay : GameFrameDelay);
2872 int wait_delay_value = (no_delay ? 0 : frame_delay_value);
2873 int jx = player->jx;
2874 int jy = player->jy;
2876 if (level.instant_relocation)
2878 int offset = (setup.scroll_delay ? 3 : 0);
2880 if (!IN_VIS_FIELD(SCREENX(jx), SCREENY(jy)))
2882 scroll_x = (local_player->jx < SBX_Left + MIDPOSX ? SBX_Left :
2883 local_player->jx > SBX_Right + MIDPOSX ? SBX_Right :
2884 local_player->jx - MIDPOSX);
2886 scroll_y = (local_player->jy < SBY_Upper + MIDPOSY ? SBY_Upper :
2887 local_player->jy > SBY_Lower + MIDPOSY ? SBY_Lower :
2888 local_player->jy - MIDPOSY);
2892 if ((player->MovDir == MV_LEFT && scroll_x > jx - MIDPOSX + offset) ||
2893 (player->MovDir == MV_RIGHT && scroll_x < jx - MIDPOSX - offset))
2894 scroll_x = jx - MIDPOSX + (scroll_x < jx-MIDPOSX ? -offset : +offset);
2896 if ((player->MovDir == MV_UP && scroll_y > jy - MIDPOSY + offset) ||
2897 (player->MovDir == MV_DOWN && scroll_y < jy - MIDPOSY - offset))
2898 scroll_y = jy - MIDPOSY + (scroll_y < jy-MIDPOSY ? -offset : +offset);
2900 /* don't scroll over playfield boundaries */
2901 if (scroll_x < SBX_Left || scroll_x > SBX_Right)
2902 scroll_x = (scroll_x < SBX_Left ? SBX_Left : SBX_Right);
2904 /* don't scroll over playfield boundaries */
2905 if (scroll_y < SBY_Upper || scroll_y > SBY_Lower)
2906 scroll_y = (scroll_y < SBY_Upper ? SBY_Upper : SBY_Lower);
2909 RedrawPlayfield(TRUE, 0,0,0,0);
2913 int scroll_xx = -999, scroll_yy = -999;
2915 ScrollScreen(NULL, SCROLL_GO_ON); /* scroll last frame to full tile */
2917 while (scroll_xx != scroll_x || scroll_yy != scroll_y)
2920 int fx = FX, fy = FY;
2922 scroll_xx = (local_player->jx < SBX_Left + MIDPOSX ? SBX_Left :
2923 local_player->jx > SBX_Right + MIDPOSX ? SBX_Right :
2924 local_player->jx - MIDPOSX);
2926 scroll_yy = (local_player->jy < SBY_Upper + MIDPOSY ? SBY_Upper :
2927 local_player->jy > SBY_Lower + MIDPOSY ? SBY_Lower :
2928 local_player->jy - MIDPOSY);
2930 dx = (scroll_xx < scroll_x ? +1 : scroll_xx > scroll_x ? -1 : 0);
2931 dy = (scroll_yy < scroll_y ? +1 : scroll_yy > scroll_y ? -1 : 0);
2933 if (dx == 0 && dy == 0) /* no scrolling needed at all */
2939 fx += dx * TILEX / 2;
2940 fy += dy * TILEY / 2;
2942 ScrollLevel(dx, dy);
2945 /* scroll in two steps of half tile size to make things smoother */
2946 BlitBitmap(drawto_field, window, fx, fy, SXSIZE, SYSIZE, SX, SY);
2948 Delay(wait_delay_value);
2950 /* scroll second step to align at full tile size */
2952 Delay(wait_delay_value);
2957 Delay(wait_delay_value);
2961 void RelocatePlayer(int jx, int jy, int el_player_raw)
2963 int el_player = GET_PLAYER_ELEMENT(el_player_raw);
2964 int player_nr = GET_PLAYER_NR(el_player);
2965 struct PlayerInfo *player = &stored_player[player_nr];
2966 boolean ffwd_delay = (tape.playing && tape.fast_forward);
2967 boolean no_delay = (tape.warp_forward);
2968 int frame_delay_value = (ffwd_delay ? FfwdFrameDelay : GameFrameDelay);
2969 int wait_delay_value = (no_delay ? 0 : frame_delay_value);
2970 int old_jx = player->jx;
2971 int old_jy = player->jy;
2972 int old_element = Feld[old_jx][old_jy];
2973 int element = Feld[jx][jy];
2974 boolean player_relocated = (old_jx != jx || old_jy != jy);
2976 int move_dir_horiz = (jx < old_jx ? MV_LEFT : jx > old_jx ? MV_RIGHT : 0);
2977 int move_dir_vert = (jy < old_jy ? MV_UP : jy > old_jy ? MV_DOWN : 0);
2978 int enter_side_horiz = MV_DIR_OPPOSITE(move_dir_horiz);
2979 int enter_side_vert = MV_DIR_OPPOSITE(move_dir_vert);
2980 int leave_side_horiz = move_dir_horiz;
2981 int leave_side_vert = move_dir_vert;
2982 int enter_side = enter_side_horiz | enter_side_vert;
2983 int leave_side = leave_side_horiz | leave_side_vert;
2985 if (player->GameOver) /* do not reanimate dead player */
2988 if (!player_relocated) /* no need to relocate the player */
2991 if (IS_PLAYER(jx, jy)) /* player already placed at new position */
2993 RemoveField(jx, jy); /* temporarily remove newly placed player */
2994 DrawLevelField(jx, jy);
2997 if (player->present)
2999 while (player->MovPos)
3001 ScrollPlayer(player, SCROLL_GO_ON);
3002 ScrollScreen(NULL, SCROLL_GO_ON);
3004 AdvanceFrameAndPlayerCounters(player->index_nr);
3009 Delay(wait_delay_value);
3012 DrawPlayer(player); /* needed here only to cleanup last field */
3013 DrawLevelField(player->jx, player->jy); /* remove player graphic */
3015 player->is_moving = FALSE;
3018 if (IS_CUSTOM_ELEMENT(old_element))
3019 CheckElementChangeByPlayer(old_jx, old_jy, old_element,
3021 player->index_bit, leave_side);
3023 CheckTriggeredElementChangeByPlayer(old_jx, old_jy, old_element,
3025 player->index_bit, leave_side);
3027 Feld[jx][jy] = el_player;
3028 InitPlayerField(jx, jy, el_player, TRUE);
3030 if (!ELEM_IS_PLAYER(element)) /* player may be set on walkable element */
3032 Feld[jx][jy] = element;
3033 InitField(jx, jy, FALSE);
3036 if (player == local_player) /* only visually relocate local player */
3037 DrawRelocatePlayer(player);
3039 TestIfPlayerTouchesBadThing(jx, jy);
3040 TestIfPlayerTouchesCustomElement(jx, jy);
3042 if (IS_CUSTOM_ELEMENT(element))
3043 CheckElementChangeByPlayer(jx, jy, element, CE_ENTERED_BY_PLAYER,
3044 player->index_bit, enter_side);
3046 CheckTriggeredElementChangeByPlayer(jx, jy, element, CE_PLAYER_ENTERS_X,
3047 player->index_bit, enter_side);
3050 void Explode(int ex, int ey, int phase, int mode)
3056 /* !!! eliminate this variable !!! */
3057 int delay = (game.emulation == EMU_SUPAPLEX ? 3 : 2);
3059 if (game.explosions_delayed)
3061 ExplodeField[ex][ey] = mode;
3065 if (phase == EX_PHASE_START) /* initialize 'Store[][]' field */
3067 int center_element = Feld[ex][ey];
3068 int artwork_element = center_element; /* for custom player artwork */
3069 int explosion_element = center_element; /* for custom player artwork */
3071 if (IS_PLAYER(ex, ey))
3073 int player_nr = GET_PLAYER_NR(StorePlayer[ex][ey]);
3075 artwork_element = stored_player[player_nr].artwork_element;
3077 if (level.use_explosion_element[player_nr])
3079 explosion_element = level.explosion_element[player_nr];
3080 artwork_element = explosion_element;
3085 /* --- This is only really needed (and now handled) in "Impact()". --- */
3086 /* do not explode moving elements that left the explode field in time */
3087 if (game.engine_version >= VERSION_IDENT(2,2,0,7) &&
3088 center_element == EL_EMPTY &&
3089 (mode == EX_TYPE_NORMAL || mode == EX_TYPE_CENTER))
3093 if (mode == EX_TYPE_NORMAL ||
3094 mode == EX_TYPE_CENTER ||
3095 mode == EX_TYPE_CROSS)
3096 PlayLevelSoundElementAction(ex, ey, artwork_element, ACTION_EXPLODING);
3098 /* remove things displayed in background while burning dynamite */
3099 if (Back[ex][ey] != EL_EMPTY && !IS_INDESTRUCTIBLE(Back[ex][ey]))
3102 if (IS_MOVING(ex, ey) || IS_BLOCKED(ex, ey))
3104 /* put moving element to center field (and let it explode there) */
3105 center_element = MovingOrBlocked2Element(ex, ey);
3106 RemoveMovingField(ex, ey);
3107 Feld[ex][ey] = center_element;
3110 last_phase = element_info[explosion_element].explosion_delay + 1;
3112 for (y = ey - 1; y <= ey + 1; y++) for (x = ex - 1; x <= ex + 1; x++)
3114 int xx = x - ex + 1;
3115 int yy = y - ey + 1;
3118 if (!IN_LEV_FIELD(x, y) ||
3119 (mode & EX_TYPE_SINGLE_TILE && (x != ex || y != ey)) ||
3120 (mode == EX_TYPE_CROSS && (x != ex && y != ey)))
3123 element = Feld[x][y];
3125 if (IS_MOVING(x, y) || IS_BLOCKED(x, y))
3127 element = MovingOrBlocked2Element(x, y);
3129 if (!IS_EXPLOSION_PROOF(element))
3130 RemoveMovingField(x, y);
3133 /* indestructible elements can only explode in center (but not flames) */
3134 if ((IS_EXPLOSION_PROOF(element) && (x != ex || y != ey ||
3135 mode == EX_TYPE_BORDER)) ||
3136 element == EL_FLAMES)
3139 /* no idea why this was changed from 3.0.8 to 3.1.0 -- this causes buggy
3140 behaviour, for example when touching a yamyam that explodes to rocks
3141 with active deadly shield, a rock is created under the player !!! */
3142 /* (case 1 (surely buggy): >= 3.1.0, case 2 (maybe buggy): <= 3.0.8) */
3144 if (IS_PLAYER(x, y) && SHIELD_ON(PLAYERINFO(x, y)) &&
3145 (game.engine_version < VERSION_IDENT(3,1,0,0) ||
3146 (x == ex && y == ey && mode != EX_TYPE_BORDER)))
3148 if (IS_PLAYER(x, y) && SHIELD_ON(PLAYERINFO(x, y)))
3151 if (IS_ACTIVE_BOMB(element))
3153 /* re-activate things under the bomb like gate or penguin */
3154 Feld[x][y] = (Back[x][y] ? Back[x][y] : EL_EMPTY);
3161 /* save walkable background elements while explosion on same tile */
3162 if (IS_WALKABLE(element) && IS_INDESTRUCTIBLE(element) &&
3163 (x != ex || y != ey || mode == EX_TYPE_BORDER))
3164 Back[x][y] = element;
3166 /* ignite explodable elements reached by other explosion */
3167 if (element == EL_EXPLOSION)
3168 element = Store2[x][y];
3170 if (AmoebaNr[x][y] &&
3171 (element == EL_AMOEBA_FULL ||
3172 element == EL_BD_AMOEBA ||
3173 element == EL_AMOEBA_GROWING))
3175 AmoebaCnt[AmoebaNr[x][y]]--;
3176 AmoebaCnt2[AmoebaNr[x][y]]--;
3181 if (IS_PLAYER(ex, ey) && !PLAYER_EXPLOSION_PROTECTED(ex, ey))
3183 int player_nr = StorePlayer[ex][ey] - EL_PLAYER_1;
3185 Store[x][y] = EL_PLAYER_IS_EXPLODING_1 + player_nr;
3188 switch(StorePlayer[ex][ey])
3191 Store[x][y] = EL_PLAYER_IS_EXPLODING_2;
3194 Store[x][y] = EL_PLAYER_IS_EXPLODING_3;
3197 Store[x][y] = EL_PLAYER_IS_EXPLODING_4;
3201 Store[x][y] = EL_PLAYER_IS_EXPLODING_1;
3206 if (PLAYERINFO(ex, ey)->use_murphy)
3207 Store[x][y] = EL_EMPTY;
3210 else if (center_element == EL_YAMYAM)
3211 Store[x][y] = level.yamyam_content[game.yamyam_content_nr].e[xx][yy];
3212 else if (element_info[center_element].content.e[xx][yy] != EL_EMPTY)
3213 Store[x][y] = element_info[center_element].content.e[xx][yy];
3215 /* needed because EL_BD_BUTTERFLY is not defined as "CAN_EXPLODE"
3216 (killing EL_BD_BUTTERFLY with dynamite would result in BD diamond
3217 otherwise) -- FIX THIS !!! */
3218 else if (!CAN_EXPLODE(element) && element != EL_BD_BUTTERFLY)
3219 Store[x][y] = element_info[element].content.e[1][1];
3221 else if (!CAN_EXPLODE(element))
3222 Store[x][y] = element_info[element].content.e[1][1];
3225 Store[x][y] = EL_EMPTY;
3227 else if (center_element == EL_MOLE)
3228 Store[x][y] = EL_EMERALD_RED;
3229 else if (center_element == EL_PENGUIN)
3230 Store[x][y] = EL_EMERALD_PURPLE;
3231 else if (center_element == EL_BUG)
3232 Store[x][y] = ((x == ex && y == ey) ? EL_DIAMOND : EL_EMERALD);
3233 else if (center_element == EL_BD_BUTTERFLY)
3234 Store[x][y] = EL_BD_DIAMOND;
3235 else if (center_element == EL_SP_ELECTRON)
3236 Store[x][y] = EL_SP_INFOTRON;
3237 else if (center_element == EL_AMOEBA_TO_DIAMOND)
3238 Store[x][y] = level.amoeba_content;
3239 else if (center_element == EL_YAMYAM)
3240 Store[x][y] = level.yamyam_content[game.yamyam_content_nr].e[xx][yy];
3241 else if (IS_CUSTOM_ELEMENT(center_element) &&
3242 element_info[center_element].content.e[xx][yy] != EL_EMPTY)
3243 Store[x][y] = element_info[center_element].content.e[xx][yy];
3244 else if (element == EL_WALL_EMERALD)
3245 Store[x][y] = EL_EMERALD;
3246 else if (element == EL_WALL_DIAMOND)
3247 Store[x][y] = EL_DIAMOND;
3248 else if (element == EL_WALL_BD_DIAMOND)
3249 Store[x][y] = EL_BD_DIAMOND;
3250 else if (element == EL_WALL_EMERALD_YELLOW)
3251 Store[x][y] = EL_EMERALD_YELLOW;
3252 else if (element == EL_WALL_EMERALD_RED)
3253 Store[x][y] = EL_EMERALD_RED;
3254 else if (element == EL_WALL_EMERALD_PURPLE)
3255 Store[x][y] = EL_EMERALD_PURPLE;
3256 else if (element == EL_WALL_PEARL)
3257 Store[x][y] = EL_PEARL;
3258 else if (element == EL_WALL_CRYSTAL)
3259 Store[x][y] = EL_CRYSTAL;
3260 else if (IS_CUSTOM_ELEMENT(element) && !CAN_EXPLODE(element))
3261 Store[x][y] = element_info[element].content.e[1][1];
3263 Store[x][y] = EL_EMPTY;
3266 if (x != ex || y != ey || mode == EX_TYPE_BORDER ||
3267 center_element == EL_AMOEBA_TO_DIAMOND)
3268 Store2[x][y] = element;
3270 Feld[x][y] = EL_EXPLOSION;
3271 GfxElement[x][y] = artwork_element;
3273 ExplodePhase[x][y] = 1;
3274 ExplodeDelay[x][y] = last_phase;
3279 if (center_element == EL_YAMYAM)
3280 game.yamyam_content_nr =
3281 (game.yamyam_content_nr + 1) % level.num_yamyam_contents;
3293 GfxFrame[x][y] = 0; /* restart explosion animation */
3295 last_phase = ExplodeDelay[x][y];
3297 ExplodePhase[x][y] = (phase < last_phase ? phase + 1 : 0);
3301 /* activate this even in non-DEBUG version until cause for crash in
3302 getGraphicAnimationFrame() (see below) is found and eliminated */
3307 if (GfxElement[x][y] == EL_UNDEFINED)
3310 printf("Explode(): x = %d, y = %d: GfxElement == EL_UNDEFINED\n", x, y);
3311 printf("Explode(): This should never happen!\n");
3314 GfxElement[x][y] = EL_EMPTY;
3318 border_element = Store2[x][y];
3319 if (IS_PLAYER(x, y) && !PLAYER_EXPLOSION_PROTECTED(x, y))
3320 border_element = StorePlayer[x][y];
3322 if (phase == element_info[border_element].ignition_delay ||
3323 phase == last_phase)
3325 boolean border_explosion = FALSE;
3327 if (IS_PLAYER(x, y) && PLAYERINFO(x, y)->present &&
3328 !PLAYER_EXPLOSION_PROTECTED(x, y))
3330 KillPlayerUnlessExplosionProtected(x, y);
3331 border_explosion = TRUE;
3333 else if (CAN_EXPLODE_BY_EXPLOSION(border_element))
3335 Feld[x][y] = Store2[x][y];
3338 border_explosion = TRUE;
3340 else if (border_element == EL_AMOEBA_TO_DIAMOND)
3342 AmoebeUmwandeln(x, y);
3344 border_explosion = TRUE;
3347 /* if an element just explodes due to another explosion (chain-reaction),
3348 do not immediately end the new explosion when it was the last frame of
3349 the explosion (as it would be done in the following "if"-statement!) */
3350 if (border_explosion && phase == last_phase)
3354 if (phase == last_phase)
3358 element = Feld[x][y] = Store[x][y];
3359 Store[x][y] = Store2[x][y] = 0;
3360 GfxElement[x][y] = EL_UNDEFINED;
3362 /* player can escape from explosions and might therefore be still alive */
3363 if (element >= EL_PLAYER_IS_EXPLODING_1 &&
3364 element <= EL_PLAYER_IS_EXPLODING_4)
3366 static int player_death_elements[] =
3373 int player_nr = element - EL_PLAYER_IS_EXPLODING_1;
3374 int player_death_element = player_death_elements[player_nr];
3376 if (level.use_explosion_element[player_nr])
3378 int explosion_element = level.explosion_element[player_nr];
3379 int xx = MIN(MAX(0, x - stored_player[player_nr].jx + 1), 2);
3380 int yy = MIN(MAX(0, y - stored_player[player_nr].jy + 1), 2);
3382 player_death_element =
3383 element_info[explosion_element].content.e[xx][yy];
3386 Feld[x][y] = (stored_player[player_nr].active ? EL_EMPTY :
3387 player_death_element);
3390 /* restore probably existing indestructible background element */
3391 if (Back[x][y] && IS_INDESTRUCTIBLE(Back[x][y]))
3392 element = Feld[x][y] = Back[x][y];
3395 MovDir[x][y] = MovPos[x][y] = MovDelay[x][y] = 0;
3396 GfxDir[x][y] = MV_NONE;
3397 ChangeDelay[x][y] = 0;
3398 ChangePage[x][y] = -1;
3400 #if USE_NEW_CUSTOM_VALUE
3401 CustomValue[x][y] = 0;
3404 InitField_WithBug2(x, y, FALSE);
3406 DrawLevelField(x, y);
3408 TestIfElementTouchesCustomElement(x, y);
3410 if (GFX_CRUMBLED(element))
3411 DrawLevelFieldCrumbledSandNeighbours(x, y);
3413 if (IS_PLAYER(x, y) && !PLAYERINFO(x, y)->present)
3414 StorePlayer[x][y] = 0;
3416 if (ELEM_IS_PLAYER(element))
3417 RelocatePlayer(x, y, element);
3419 else if (IN_SCR_FIELD(SCREENX(x), SCREENY(y)))
3421 int graphic = el_act2img(GfxElement[x][y], ACTION_EXPLODING);
3422 int frame = getGraphicAnimationFrame(graphic, GfxFrame[x][y]);
3425 DrawLevelFieldCrumbledSand(x, y);
3427 if (IS_WALKABLE_OVER(Back[x][y]) && Back[x][y] != EL_EMPTY)
3429 DrawLevelElement(x, y, Back[x][y]);
3430 DrawGraphicThruMask(SCREENX(x), SCREENY(y), graphic, frame);
3432 else if (IS_WALKABLE_UNDER(Back[x][y]))
3434 DrawGraphic(SCREENX(x), SCREENY(y), graphic, frame);
3435 DrawLevelElementThruMask(x, y, Back[x][y]);
3437 else if (!IS_WALKABLE_INSIDE(Back[x][y]))
3438 DrawGraphic(SCREENX(x), SCREENY(y), graphic, frame);
3442 void DynaExplode(int ex, int ey)
3445 int dynabomb_element = Feld[ex][ey];
3446 int dynabomb_size = 1;
3447 boolean dynabomb_xl = FALSE;
3448 struct PlayerInfo *player;
3449 static int xy[4][2] =
3457 if (IS_ACTIVE_BOMB(dynabomb_element))
3459 player = &stored_player[dynabomb_element - EL_DYNABOMB_PLAYER_1_ACTIVE];
3460 dynabomb_size = player->dynabomb_size;
3461 dynabomb_xl = player->dynabomb_xl;
3462 player->dynabombs_left++;
3465 Explode(ex, ey, EX_PHASE_START, EX_TYPE_CENTER);
3467 for (i = 0; i < NUM_DIRECTIONS; i++)
3469 for (j = 1; j <= dynabomb_size; j++)
3471 int x = ex + j * xy[i][0];
3472 int y = ey + j * xy[i][1];
3475 if (!IN_LEV_FIELD(x, y) || IS_INDESTRUCTIBLE(Feld[x][y]))
3478 element = Feld[x][y];
3480 /* do not restart explosions of fields with active bombs */
3481 if (element == EL_EXPLOSION && IS_ACTIVE_BOMB(Store2[x][y]))
3484 Explode(x, y, EX_PHASE_START, EX_TYPE_BORDER);
3486 if (element != EL_EMPTY && element != EL_EXPLOSION &&
3487 !IS_DIGGABLE(element) && !dynabomb_xl)
3493 void Bang(int x, int y)
3495 int element = MovingOrBlocked2Element(x, y);
3496 int explosion_type = EX_TYPE_NORMAL;
3498 if (IS_PLAYER(x, y) && !PLAYER_EXPLOSION_PROTECTED(x, y))
3500 struct PlayerInfo *player = PLAYERINFO(x, y);
3502 element = Feld[x][y] = (player->use_murphy ? EL_SP_MURPHY :
3503 player->element_nr);
3505 if (level.use_explosion_element[player->index_nr])
3507 int explosion_element = level.explosion_element[player->index_nr];
3509 if (element_info[explosion_element].explosion_type == EXPLODES_CROSS)
3510 explosion_type = EX_TYPE_CROSS;
3511 else if (element_info[explosion_element].explosion_type == EXPLODES_1X1)
3512 explosion_type = EX_TYPE_CENTER;
3520 case EL_BD_BUTTERFLY:
3523 case EL_DARK_YAMYAM:
3527 RaiseScoreElement(element);
3530 case EL_DYNABOMB_PLAYER_1_ACTIVE:
3531 case EL_DYNABOMB_PLAYER_2_ACTIVE:
3532 case EL_DYNABOMB_PLAYER_3_ACTIVE:
3533 case EL_DYNABOMB_PLAYER_4_ACTIVE:
3534 case EL_DYNABOMB_INCREASE_NUMBER:
3535 case EL_DYNABOMB_INCREASE_SIZE:
3536 case EL_DYNABOMB_INCREASE_POWER:
3537 explosion_type = EX_TYPE_DYNA;
3542 case EL_LAMP_ACTIVE:
3543 case EL_AMOEBA_TO_DIAMOND:
3544 if (!IS_PLAYER(x, y)) /* penguin and player may be at same field */
3545 explosion_type = EX_TYPE_CENTER;
3549 if (element_info[element].explosion_type == EXPLODES_CROSS)
3550 explosion_type = EX_TYPE_CROSS;
3551 else if (element_info[element].explosion_type == EXPLODES_1X1)
3552 explosion_type = EX_TYPE_CENTER;
3556 if (explosion_type == EX_TYPE_DYNA)
3559 Explode(x, y, EX_PHASE_START, explosion_type);
3561 CheckTriggeredElementChange(x, y, element, CE_EXPLOSION_OF_X);
3564 void SplashAcid(int x, int y)
3566 if (IN_LEV_FIELD(x - 1, y - 1) && IS_FREE(x - 1, y - 1) &&
3567 (!IN_LEV_FIELD(x - 1, y - 2) ||
3568 !CAN_FALL(MovingOrBlocked2Element(x - 1, y - 2))))
3569 Feld[x - 1][y - 1] = EL_ACID_SPLASH_LEFT;
3571 if (IN_LEV_FIELD(x + 1, y - 1) && IS_FREE(x + 1, y - 1) &&
3572 (!IN_LEV_FIELD(x + 1, y - 2) ||
3573 !CAN_FALL(MovingOrBlocked2Element(x + 1, y - 2))))
3574 Feld[x + 1][y - 1] = EL_ACID_SPLASH_RIGHT;
3576 PlayLevelSound(x, y, SND_ACID_SPLASHING);
3579 static void InitBeltMovement()
3581 static int belt_base_element[4] =
3583 EL_CONVEYOR_BELT_1_LEFT,
3584 EL_CONVEYOR_BELT_2_LEFT,
3585 EL_CONVEYOR_BELT_3_LEFT,
3586 EL_CONVEYOR_BELT_4_LEFT
3588 static int belt_base_active_element[4] =
3590 EL_CONVEYOR_BELT_1_LEFT_ACTIVE,
3591 EL_CONVEYOR_BELT_2_LEFT_ACTIVE,
3592 EL_CONVEYOR_BELT_3_LEFT_ACTIVE,
3593 EL_CONVEYOR_BELT_4_LEFT_ACTIVE
3598 /* set frame order for belt animation graphic according to belt direction */
3599 for (i = 0; i < NUM_BELTS; i++)
3603 for (j = 0; j < NUM_BELT_PARTS; j++)
3605 int element = belt_base_active_element[belt_nr] + j;
3606 int graphic = el2img(element);
3608 if (game.belt_dir[i] == MV_LEFT)
3609 graphic_info[graphic].anim_mode &= ~ANIM_REVERSE;
3611 graphic_info[graphic].anim_mode |= ANIM_REVERSE;
3615 for (y = 0; y < lev_fieldy; y++)
3617 for (x = 0; x < lev_fieldx; x++)
3619 int element = Feld[x][y];
3621 for (i = 0; i < NUM_BELTS; i++)
3623 if (IS_BELT(element) && game.belt_dir[i] != MV_NONE)
3625 int e_belt_nr = getBeltNrFromBeltElement(element);
3628 if (e_belt_nr == belt_nr)
3630 int belt_part = Feld[x][y] - belt_base_element[belt_nr];
3632 Feld[x][y] = belt_base_active_element[belt_nr] + belt_part;
3640 static void ToggleBeltSwitch(int x, int y)
3642 static int belt_base_element[4] =
3644 EL_CONVEYOR_BELT_1_LEFT,
3645 EL_CONVEYOR_BELT_2_LEFT,
3646 EL_CONVEYOR_BELT_3_LEFT,
3647 EL_CONVEYOR_BELT_4_LEFT
3649 static int belt_base_active_element[4] =
3651 EL_CONVEYOR_BELT_1_LEFT_ACTIVE,
3652 EL_CONVEYOR_BELT_2_LEFT_ACTIVE,
3653 EL_CONVEYOR_BELT_3_LEFT_ACTIVE,
3654 EL_CONVEYOR_BELT_4_LEFT_ACTIVE
3656 static int belt_base_switch_element[4] =
3658 EL_CONVEYOR_BELT_1_SWITCH_LEFT,
3659 EL_CONVEYOR_BELT_2_SWITCH_LEFT,
3660 EL_CONVEYOR_BELT_3_SWITCH_LEFT,
3661 EL_CONVEYOR_BELT_4_SWITCH_LEFT
3663 static int belt_move_dir[4] =
3671 int element = Feld[x][y];
3672 int belt_nr = getBeltNrFromBeltSwitchElement(element);
3673 int belt_dir_nr = (game.belt_dir_nr[belt_nr] + 1) % 4;
3674 int belt_dir = belt_move_dir[belt_dir_nr];
3677 if (!IS_BELT_SWITCH(element))
3680 game.belt_dir_nr[belt_nr] = belt_dir_nr;
3681 game.belt_dir[belt_nr] = belt_dir;
3683 if (belt_dir_nr == 3)
3686 /* set frame order for belt animation graphic according to belt direction */
3687 for (i = 0; i < NUM_BELT_PARTS; i++)
3689 int element = belt_base_active_element[belt_nr] + i;
3690 int graphic = el2img(element);
3692 if (belt_dir == MV_LEFT)
3693 graphic_info[graphic].anim_mode &= ~ANIM_REVERSE;
3695 graphic_info[graphic].anim_mode |= ANIM_REVERSE;
3698 for (yy = 0; yy < lev_fieldy; yy++)
3700 for (xx = 0; xx < lev_fieldx; xx++)
3702 int element = Feld[xx][yy];
3704 if (IS_BELT_SWITCH(element))
3706 int e_belt_nr = getBeltNrFromBeltSwitchElement(element);
3708 if (e_belt_nr == belt_nr)
3710 Feld[xx][yy] = belt_base_switch_element[belt_nr] + belt_dir_nr;
3711 DrawLevelField(xx, yy);
3714 else if (IS_BELT(element) && belt_dir != MV_NONE)
3716 int e_belt_nr = getBeltNrFromBeltElement(element);
3718 if (e_belt_nr == belt_nr)
3720 int belt_part = Feld[xx][yy] - belt_base_element[belt_nr];
3722 Feld[xx][yy] = belt_base_active_element[belt_nr] + belt_part;
3723 DrawLevelField(xx, yy);
3726 else if (IS_BELT_ACTIVE(element) && belt_dir == MV_NONE)
3728 int e_belt_nr = getBeltNrFromBeltActiveElement(element);
3730 if (e_belt_nr == belt_nr)
3732 int belt_part = Feld[xx][yy] - belt_base_active_element[belt_nr];
3734 Feld[xx][yy] = belt_base_element[belt_nr] + belt_part;
3735 DrawLevelField(xx, yy);
3742 static void ToggleSwitchgateSwitch(int x, int y)
3746 game.switchgate_pos = !game.switchgate_pos;
3748 for (yy = 0; yy < lev_fieldy; yy++)
3750 for (xx = 0; xx < lev_fieldx; xx++)
3752 int element = Feld[xx][yy];
3754 if (element == EL_SWITCHGATE_SWITCH_UP ||
3755 element == EL_SWITCHGATE_SWITCH_DOWN)
3757 Feld[xx][yy] = EL_SWITCHGATE_SWITCH_UP + game.switchgate_pos;
3758 DrawLevelField(xx, yy);
3760 else if (element == EL_SWITCHGATE_OPEN ||
3761 element == EL_SWITCHGATE_OPENING)
3763 Feld[xx][yy] = EL_SWITCHGATE_CLOSING;
3765 PlayLevelSoundAction(xx, yy, ACTION_CLOSING);
3767 else if (element == EL_SWITCHGATE_CLOSED ||
3768 element == EL_SWITCHGATE_CLOSING)
3770 Feld[xx][yy] = EL_SWITCHGATE_OPENING;
3772 PlayLevelSoundAction(xx, yy, ACTION_OPENING);
3778 static int getInvisibleActiveFromInvisibleElement(int element)
3780 return (element == EL_INVISIBLE_STEELWALL ? EL_INVISIBLE_STEELWALL_ACTIVE :
3781 element == EL_INVISIBLE_WALL ? EL_INVISIBLE_WALL_ACTIVE :
3782 element == EL_INVISIBLE_SAND ? EL_INVISIBLE_SAND_ACTIVE :
3786 static int getInvisibleFromInvisibleActiveElement(int element)
3788 return (element == EL_INVISIBLE_STEELWALL_ACTIVE ? EL_INVISIBLE_STEELWALL :
3789 element == EL_INVISIBLE_WALL_ACTIVE ? EL_INVISIBLE_WALL :
3790 element == EL_INVISIBLE_SAND_ACTIVE ? EL_INVISIBLE_SAND :
3794 static void RedrawAllLightSwitchesAndInvisibleElements()
3798 for (y = 0; y < lev_fieldy; y++) for (x = 0; x < lev_fieldx; x++)
3800 int element = Feld[x][y];
3802 if (element == EL_LIGHT_SWITCH &&
3803 game.light_time_left > 0)
3805 Feld[x][y] = EL_LIGHT_SWITCH_ACTIVE;
3806 DrawLevelField(x, y);
3808 else if (element == EL_LIGHT_SWITCH_ACTIVE &&
3809 game.light_time_left == 0)
3811 Feld[x][y] = EL_LIGHT_SWITCH;
3812 DrawLevelField(x, y);
3814 else if (element == EL_EMC_DRIPPER &&
3815 game.light_time_left > 0)
3817 Feld[x][y] = EL_EMC_DRIPPER_ACTIVE;
3818 DrawLevelField(x, y);
3820 else if (element == EL_EMC_DRIPPER_ACTIVE &&
3821 game.light_time_left == 0)
3823 Feld[x][y] = EL_EMC_DRIPPER;
3824 DrawLevelField(x, y);
3826 else if (element == EL_INVISIBLE_STEELWALL ||
3827 element == EL_INVISIBLE_WALL ||
3828 element == EL_INVISIBLE_SAND)
3830 if (game.light_time_left > 0)
3831 Feld[x][y] = getInvisibleActiveFromInvisibleElement(element);
3833 DrawLevelField(x, y);
3835 /* uncrumble neighbour fields, if needed */
3836 if (element == EL_INVISIBLE_SAND)
3837 DrawLevelFieldCrumbledSandNeighbours(x, y);
3839 else if (element == EL_INVISIBLE_STEELWALL_ACTIVE ||
3840 element == EL_INVISIBLE_WALL_ACTIVE ||
3841 element == EL_INVISIBLE_SAND_ACTIVE)
3843 if (game.light_time_left == 0)
3844 Feld[x][y] = getInvisibleFromInvisibleActiveElement(element);
3846 DrawLevelField(x, y);
3848 /* re-crumble neighbour fields, if needed */
3849 if (element == EL_INVISIBLE_SAND)
3850 DrawLevelFieldCrumbledSandNeighbours(x, y);
3855 static void RedrawAllInvisibleElementsForLenses()
3859 for (y = 0; y < lev_fieldy; y++) for (x = 0; x < lev_fieldx; x++)
3861 int element = Feld[x][y];
3863 if (element == EL_EMC_DRIPPER &&
3864 game.lenses_time_left > 0)
3866 Feld[x][y] = EL_EMC_DRIPPER_ACTIVE;
3867 DrawLevelField(x, y);
3869 else if (element == EL_EMC_DRIPPER_ACTIVE &&
3870 game.lenses_time_left == 0)
3872 Feld[x][y] = EL_EMC_DRIPPER;
3873 DrawLevelField(x, y);
3875 else if (element == EL_INVISIBLE_STEELWALL ||
3876 element == EL_INVISIBLE_WALL ||
3877 element == EL_INVISIBLE_SAND)
3879 if (game.lenses_time_left > 0)
3880 Feld[x][y] = getInvisibleActiveFromInvisibleElement(element);
3882 DrawLevelField(x, y);
3884 /* uncrumble neighbour fields, if needed */
3885 if (element == EL_INVISIBLE_SAND)
3886 DrawLevelFieldCrumbledSandNeighbours(x, y);
3888 else if (element == EL_INVISIBLE_STEELWALL_ACTIVE ||
3889 element == EL_INVISIBLE_WALL_ACTIVE ||
3890 element == EL_INVISIBLE_SAND_ACTIVE)
3892 if (game.lenses_time_left == 0)
3893 Feld[x][y] = getInvisibleFromInvisibleActiveElement(element);
3895 DrawLevelField(x, y);
3897 /* re-crumble neighbour fields, if needed */
3898 if (element == EL_INVISIBLE_SAND)
3899 DrawLevelFieldCrumbledSandNeighbours(x, y);
3904 static void RedrawAllInvisibleElementsForMagnifier()
3908 for (y = 0; y < lev_fieldy; y++) for (x = 0; x < lev_fieldx; x++)
3910 int element = Feld[x][y];
3912 if (element == EL_EMC_FAKE_GRASS &&
3913 game.magnify_time_left > 0)
3915 Feld[x][y] = EL_EMC_FAKE_GRASS_ACTIVE;
3916 DrawLevelField(x, y);
3918 else if (element == EL_EMC_FAKE_GRASS_ACTIVE &&
3919 game.magnify_time_left == 0)
3921 Feld[x][y] = EL_EMC_FAKE_GRASS;
3922 DrawLevelField(x, y);
3924 else if (IS_GATE_GRAY(element) &&
3925 game.magnify_time_left > 0)
3927 Feld[x][y] = (IS_RND_GATE_GRAY(element) ?
3928 element - EL_GATE_1_GRAY + EL_GATE_1_GRAY_ACTIVE :
3929 IS_EM_GATE_GRAY(element) ?
3930 element - EL_EM_GATE_1_GRAY + EL_EM_GATE_1_GRAY_ACTIVE :
3931 IS_EMC_GATE_GRAY(element) ?
3932 element - EL_EMC_GATE_5_GRAY + EL_EMC_GATE_5_GRAY_ACTIVE :
3934 DrawLevelField(x, y);
3936 else if (IS_GATE_GRAY_ACTIVE(element) &&
3937 game.magnify_time_left == 0)
3939 Feld[x][y] = (IS_RND_GATE_GRAY_ACTIVE(element) ?
3940 element - EL_GATE_1_GRAY_ACTIVE + EL_GATE_1_GRAY :
3941 IS_EM_GATE_GRAY_ACTIVE(element) ?
3942 element - EL_EM_GATE_1_GRAY_ACTIVE + EL_EM_GATE_1_GRAY :
3943 IS_EMC_GATE_GRAY_ACTIVE(element) ?
3944 element - EL_EMC_GATE_5_GRAY_ACTIVE + EL_EMC_GATE_5_GRAY :
3946 DrawLevelField(x, y);
3951 static void ToggleLightSwitch(int x, int y)
3953 int element = Feld[x][y];
3955 game.light_time_left =
3956 (element == EL_LIGHT_SWITCH ?
3957 level.time_light * FRAMES_PER_SECOND : 0);
3959 RedrawAllLightSwitchesAndInvisibleElements();
3962 static void ActivateTimegateSwitch(int x, int y)
3966 game.timegate_time_left = level.time_timegate * FRAMES_PER_SECOND;
3968 for (yy = 0; yy < lev_fieldy; yy++)
3970 for (xx = 0; xx < lev_fieldx; xx++)
3972 int element = Feld[xx][yy];
3974 if (element == EL_TIMEGATE_CLOSED ||
3975 element == EL_TIMEGATE_CLOSING)
3977 Feld[xx][yy] = EL_TIMEGATE_OPENING;
3978 PlayLevelSound(xx, yy, SND_TIMEGATE_OPENING);
3982 else if (element == EL_TIMEGATE_SWITCH_ACTIVE)
3984 Feld[xx][yy] = EL_TIMEGATE_SWITCH;
3985 DrawLevelField(xx, yy);
3992 Feld[x][y] = EL_TIMEGATE_SWITCH_ACTIVE;
3995 void Impact(int x, int y)
3997 boolean last_line = (y == lev_fieldy - 1);
3998 boolean object_hit = FALSE;
3999 boolean impact = (last_line || object_hit);
4000 int element = Feld[x][y];
4001 int smashed = EL_STEELWALL;
4003 if (!last_line) /* check if element below was hit */
4005 if (Feld[x][y + 1] == EL_PLAYER_IS_LEAVING)
4008 object_hit = (!IS_FREE(x, y + 1) && (!IS_MOVING(x, y + 1) ||
4009 MovDir[x][y + 1] != MV_DOWN ||
4010 MovPos[x][y + 1] <= TILEY / 2));
4012 /* do not smash moving elements that left the smashed field in time */
4013 if (game.engine_version >= VERSION_IDENT(2,2,0,7) && IS_MOVING(x, y + 1) &&
4014 ABS(MovPos[x][y + 1] + getElementMoveStepsize(x, y + 1)) >= TILEX)
4017 #if USE_QUICKSAND_IMPACT_BUGFIX
4018 if (Feld[x][y + 1] == EL_QUICKSAND_EMPTYING && object_hit == FALSE)
4020 RemoveMovingField(x, y + 1);
4021 Feld[x][y + 1] = EL_QUICKSAND_EMPTY;
4022 Feld[x][y + 2] = EL_ROCK;
4023 DrawLevelField(x, y + 2);
4030 smashed = MovingOrBlocked2Element(x, y + 1);
4032 impact = (last_line || object_hit);
4035 if (!last_line && smashed == EL_ACID) /* element falls into acid */
4037 SplashAcid(x, y + 1);
4041 /* !!! not sufficient for all cases -- see EL_PEARL below !!! */
4042 /* only reset graphic animation if graphic really changes after impact */
4044 el_act_dir2img(element, GfxAction[x][y], MV_DOWN) != el2img(element))
4046 ResetGfxAnimation(x, y);
4047 DrawLevelField(x, y);
4050 if (impact && CAN_EXPLODE_IMPACT(element))
4055 else if (impact && element == EL_PEARL)
4057 ResetGfxAnimation(x, y);
4059 Feld[x][y] = EL_PEARL_BREAKING;
4060 PlayLevelSound(x, y, SND_PEARL_BREAKING);
4063 else if (impact && CheckElementChange(x, y, element, smashed, CE_IMPACT))
4065 PlayLevelSoundElementAction(x, y, element, ACTION_IMPACT);
4070 if (impact && element == EL_AMOEBA_DROP)
4072 if (object_hit && IS_PLAYER(x, y + 1))
4073 KillPlayerUnlessEnemyProtected(x, y + 1);
4074 else if (object_hit && smashed == EL_PENGUIN)
4078 Feld[x][y] = EL_AMOEBA_GROWING;
4079 Store[x][y] = EL_AMOEBA_WET;
4081 ResetRandomAnimationValue(x, y);
4086 if (object_hit) /* check which object was hit */
4088 if (CAN_PASS_MAGIC_WALL(element) &&
4089 (smashed == EL_MAGIC_WALL ||
4090 smashed == EL_BD_MAGIC_WALL))
4093 int activated_magic_wall =
4094 (smashed == EL_MAGIC_WALL ? EL_MAGIC_WALL_ACTIVE :
4095 EL_BD_MAGIC_WALL_ACTIVE);
4097 /* activate magic wall / mill */
4098 for (yy = 0; yy < lev_fieldy; yy++)
4099 for (xx = 0; xx < lev_fieldx; xx++)
4100 if (Feld[xx][yy] == smashed)
4101 Feld[xx][yy] = activated_magic_wall;
4103 game.magic_wall_time_left = level.time_magic_wall * FRAMES_PER_SECOND;
4104 game.magic_wall_active = TRUE;
4106 PlayLevelSound(x, y, (smashed == EL_MAGIC_WALL ?
4107 SND_MAGIC_WALL_ACTIVATING :
4108 SND_BD_MAGIC_WALL_ACTIVATING));
4111 if (IS_PLAYER(x, y + 1))
4113 if (CAN_SMASH_PLAYER(element))
4115 KillPlayerUnlessEnemyProtected(x, y + 1);
4119 else if (smashed == EL_PENGUIN)
4121 if (CAN_SMASH_PLAYER(element))
4127 else if (element == EL_BD_DIAMOND)
4129 if (IS_CLASSIC_ENEMY(smashed) && IS_BD_ELEMENT(smashed))
4135 else if (((element == EL_SP_INFOTRON ||
4136 element == EL_SP_ZONK) &&
4137 (smashed == EL_SP_SNIKSNAK ||
4138 smashed == EL_SP_ELECTRON ||
4139 smashed == EL_SP_DISK_ORANGE)) ||
4140 (element == EL_SP_INFOTRON &&
4141 smashed == EL_SP_DISK_YELLOW))
4146 else if (CAN_SMASH_EVERYTHING(element))
4148 if (IS_CLASSIC_ENEMY(smashed) ||
4149 CAN_EXPLODE_SMASHED(smashed))
4154 else if (!IS_MOVING(x, y + 1) && !IS_BLOCKED(x, y + 1))
4156 if (smashed == EL_LAMP ||
4157 smashed == EL_LAMP_ACTIVE)
4162 else if (smashed == EL_NUT)
4164 Feld[x][y + 1] = EL_NUT_BREAKING;
4165 PlayLevelSound(x, y, SND_NUT_BREAKING);
4166 RaiseScoreElement(EL_NUT);
4169 else if (smashed == EL_PEARL)
4171 ResetGfxAnimation(x, y);
4173 Feld[x][y + 1] = EL_PEARL_BREAKING;
4174 PlayLevelSound(x, y, SND_PEARL_BREAKING);
4177 else if (smashed == EL_DIAMOND)
4179 Feld[x][y + 1] = EL_DIAMOND_BREAKING;
4180 PlayLevelSound(x, y, SND_DIAMOND_BREAKING);
4183 else if (IS_BELT_SWITCH(smashed))
4185 ToggleBeltSwitch(x, y + 1);
4187 else if (smashed == EL_SWITCHGATE_SWITCH_UP ||
4188 smashed == EL_SWITCHGATE_SWITCH_DOWN)
4190 ToggleSwitchgateSwitch(x, y + 1);
4192 else if (smashed == EL_LIGHT_SWITCH ||
4193 smashed == EL_LIGHT_SWITCH_ACTIVE)
4195 ToggleLightSwitch(x, y + 1);
4200 TestIfElementSmashesCustomElement(x, y, MV_DOWN);
4203 CheckElementChange(x, y + 1, smashed, element, CE_SMASHED);
4205 CheckElementChangeBySide(x, y + 1, smashed, element,
4206 CE_SWITCHED, CH_SIDE_TOP);
4207 CheckTriggeredElementChangeBySide(x, y + 1, smashed, CE_SWITCH_OF_X,
4213 CheckElementChange(x, y + 1, smashed, element, CE_SMASHED);
4218 /* play sound of magic wall / mill */
4220 (Feld[x][y + 1] == EL_MAGIC_WALL_ACTIVE ||
4221 Feld[x][y + 1] == EL_BD_MAGIC_WALL_ACTIVE))
4223 if (Feld[x][y + 1] == EL_MAGIC_WALL_ACTIVE)
4224 PlayLevelSound(x, y, SND_MAGIC_WALL_FILLING);
4225 else if (Feld[x][y + 1] == EL_BD_MAGIC_WALL_ACTIVE)
4226 PlayLevelSound(x, y, SND_BD_MAGIC_WALL_FILLING);
4231 /* play sound of object that hits the ground */
4232 if (last_line || object_hit)
4233 PlayLevelSoundElementAction(x, y, element, ACTION_IMPACT);
4236 inline static void TurnRoundExt(int x, int y)
4248 { 0, 0 }, { 0, 0 }, { 0, 0 },
4253 int left, right, back;
4257 { MV_DOWN, MV_UP, MV_RIGHT },
4258 { MV_UP, MV_DOWN, MV_LEFT },
4260 { MV_LEFT, MV_RIGHT, MV_DOWN },
4264 { MV_RIGHT, MV_LEFT, MV_UP }
4267 int element = Feld[x][y];
4268 int move_pattern = element_info[element].move_pattern;
4270 int old_move_dir = MovDir[x][y];
4271 int left_dir = turn[old_move_dir].left;
4272 int right_dir = turn[old_move_dir].right;
4273 int back_dir = turn[old_move_dir].back;
4275 int left_dx = move_xy[left_dir].dx, left_dy = move_xy[left_dir].dy;
4276 int right_dx = move_xy[right_dir].dx, right_dy = move_xy[right_dir].dy;
4277 int move_dx = move_xy[old_move_dir].dx, move_dy = move_xy[old_move_dir].dy;
4278 int back_dx = move_xy[back_dir].dx, back_dy = move_xy[back_dir].dy;
4280 int left_x = x + left_dx, left_y = y + left_dy;
4281 int right_x = x + right_dx, right_y = y + right_dy;
4282 int move_x = x + move_dx, move_y = y + move_dy;
4286 if (element == EL_BUG || element == EL_BD_BUTTERFLY)
4288 TestIfBadThingTouchesOtherBadThing(x, y);
4290 if (ENEMY_CAN_ENTER_FIELD(element, right_x, right_y))
4291 MovDir[x][y] = right_dir;
4292 else if (!ENEMY_CAN_ENTER_FIELD(element, move_x, move_y))
4293 MovDir[x][y] = left_dir;
4295 if (element == EL_BUG && MovDir[x][y] != old_move_dir)
4297 else if (element == EL_BD_BUTTERFLY) /* && MovDir[x][y] == left_dir) */
4300 else if (element == EL_SPACESHIP || element == EL_BD_FIREFLY)
4302 TestIfBadThingTouchesOtherBadThing(x, y);
4304 if (ENEMY_CAN_ENTER_FIELD(element, left_x, left_y))
4305 MovDir[x][y] = left_dir;
4306 else if (!ENEMY_CAN_ENTER_FIELD(element, move_x, move_y))
4307 MovDir[x][y] = right_dir;
4309 if (element == EL_SPACESHIP && MovDir[x][y] != old_move_dir)
4311 else if (element == EL_BD_FIREFLY) /* && MovDir[x][y] == right_dir) */
4314 else if (element == EL_SP_SNIKSNAK || element == EL_SP_ELECTRON)
4316 TestIfBadThingTouchesOtherBadThing(x, y);
4318 if (ELEMENT_CAN_ENTER_FIELD_BASE_4(element, left_x, left_y, 0))
4319 MovDir[x][y] = left_dir;
4320 else if (!ELEMENT_CAN_ENTER_FIELD_BASE_4(element, move_x, move_y, 0))
4321 MovDir[x][y] = right_dir;
4323 if (MovDir[x][y] != old_move_dir)
4326 else if (element == EL_YAMYAM)
4328 boolean can_turn_left = YAMYAM_CAN_ENTER_FIELD(element, left_x, left_y);
4329 boolean can_turn_right = YAMYAM_CAN_ENTER_FIELD(element, right_x, right_y);
4331 if (can_turn_left && can_turn_right)
4332 MovDir[x][y] = (RND(3) ? (RND(2) ? left_dir : right_dir) : back_dir);
4333 else if (can_turn_left)
4334 MovDir[x][y] = (RND(2) ? left_dir : back_dir);
4335 else if (can_turn_right)
4336 MovDir[x][y] = (RND(2) ? right_dir : back_dir);
4338 MovDir[x][y] = back_dir;
4340 MovDelay[x][y] = 16 + 16 * RND(3);
4342 else if (element == EL_DARK_YAMYAM)
4344 boolean can_turn_left = DARK_YAMYAM_CAN_ENTER_FIELD(element,
4346 boolean can_turn_right = DARK_YAMYAM_CAN_ENTER_FIELD(element,
4349 if (can_turn_left && can_turn_right)
4350 MovDir[x][y] = (RND(3) ? (RND(2) ? left_dir : right_dir) : back_dir);
4351 else if (can_turn_left)
4352 MovDir[x][y] = (RND(2) ? left_dir : back_dir);
4353 else if (can_turn_right)
4354 MovDir[x][y] = (RND(2) ? right_dir : back_dir);
4356 MovDir[x][y] = back_dir;
4358 MovDelay[x][y] = 16 + 16 * RND(3);
4360 else if (element == EL_PACMAN)
4362 boolean can_turn_left = PACMAN_CAN_ENTER_FIELD(element, left_x, left_y);
4363 boolean can_turn_right = PACMAN_CAN_ENTER_FIELD(element, right_x, right_y);
4365 if (can_turn_left && can_turn_right)
4366 MovDir[x][y] = (RND(3) ? (RND(2) ? left_dir : right_dir) : back_dir);
4367 else if (can_turn_left)
4368 MovDir[x][y] = (RND(2) ? left_dir : back_dir);
4369 else if (can_turn_right)
4370 MovDir[x][y] = (RND(2) ? right_dir : back_dir);
4372 MovDir[x][y] = back_dir;
4374 MovDelay[x][y] = 6 + RND(40);
4376 else if (element == EL_PIG)
4378 boolean can_turn_left = PIG_CAN_ENTER_FIELD(element, left_x, left_y);
4379 boolean can_turn_right = PIG_CAN_ENTER_FIELD(element, right_x, right_y);
4380 boolean can_move_on = PIG_CAN_ENTER_FIELD(element, move_x, move_y);
4381 boolean should_turn_left, should_turn_right, should_move_on;
4383 int rnd = RND(rnd_value);
4385 should_turn_left = (can_turn_left &&
4387 IN_LEV_FIELD_AND_NOT_FREE(x + back_dx + left_dx,
4388 y + back_dy + left_dy)));
4389 should_turn_right = (can_turn_right &&
4391 IN_LEV_FIELD_AND_NOT_FREE(x + back_dx + right_dx,
4392 y + back_dy + right_dy)));
4393 should_move_on = (can_move_on &&
4396 IN_LEV_FIELD_AND_NOT_FREE(x + move_dx + left_dx,
4397 y + move_dy + left_dy) ||
4398 IN_LEV_FIELD_AND_NOT_FREE(x + move_dx + right_dx,
4399 y + move_dy + right_dy)));
4401 if (should_turn_left || should_turn_right || should_move_on)
4403 if (should_turn_left && should_turn_right && should_move_on)
4404 MovDir[x][y] = (rnd < rnd_value / 3 ? left_dir :
4405 rnd < 2 * rnd_value / 3 ? right_dir :
4407 else if (should_turn_left && should_turn_right)
4408 MovDir[x][y] = (rnd < rnd_value / 2 ? left_dir : right_dir);
4409 else if (should_turn_left && should_move_on)
4410 MovDir[x][y] = (rnd < rnd_value / 2 ? left_dir : old_move_dir);
4411 else if (should_turn_right && should_move_on)
4412 MovDir[x][y] = (rnd < rnd_value / 2 ? right_dir : old_move_dir);
4413 else if (should_turn_left)
4414 MovDir[x][y] = left_dir;
4415 else if (should_turn_right)
4416 MovDir[x][y] = right_dir;
4417 else if (should_move_on)
4418 MovDir[x][y] = old_move_dir;
4420 else if (can_move_on && rnd > rnd_value / 8)
4421 MovDir[x][y] = old_move_dir;
4422 else if (can_turn_left && can_turn_right)
4423 MovDir[x][y] = (rnd < rnd_value / 2 ? left_dir : right_dir);
4424 else if (can_turn_left && rnd > rnd_value / 8)
4425 MovDir[x][y] = left_dir;
4426 else if (can_turn_right && rnd > rnd_value/8)
4427 MovDir[x][y] = right_dir;
4429 MovDir[x][y] = back_dir;
4431 xx = x + move_xy[MovDir[x][y]].dx;
4432 yy = y + move_xy[MovDir[x][y]].dy;
4434 if (!IN_LEV_FIELD(xx, yy) ||
4435 (!IS_FREE(xx, yy) && !IS_FOOD_PIG(Feld[xx][yy])))
4436 MovDir[x][y] = old_move_dir;
4440 else if (element == EL_DRAGON)
4442 boolean can_turn_left = DRAGON_CAN_ENTER_FIELD(element, left_x, left_y);
4443 boolean can_turn_right = DRAGON_CAN_ENTER_FIELD(element, right_x, right_y);
4444 boolean can_move_on = DRAGON_CAN_ENTER_FIELD(element, move_x, move_y);
4446 int rnd = RND(rnd_value);
4448 if (can_move_on && rnd > rnd_value / 8)
4449 MovDir[x][y] = old_move_dir;
4450 else if (can_turn_left && can_turn_right)
4451 MovDir[x][y] = (rnd < rnd_value / 2 ? left_dir : right_dir);
4452 else if (can_turn_left && rnd > rnd_value / 8)
4453 MovDir[x][y] = left_dir;
4454 else if (can_turn_right && rnd > rnd_value / 8)
4455 MovDir[x][y] = right_dir;
4457 MovDir[x][y] = back_dir;
4459 xx = x + move_xy[MovDir[x][y]].dx;
4460 yy = y + move_xy[MovDir[x][y]].dy;
4462 if (!IN_LEV_FIELD_AND_IS_FREE(xx, yy))
4463 MovDir[x][y] = old_move_dir;
4467 else if (element == EL_MOLE)
4469 boolean can_move_on =
4470 (MOLE_CAN_ENTER_FIELD(element, move_x, move_y,
4471 IS_AMOEBOID(Feld[move_x][move_y]) ||
4472 Feld[move_x][move_y] == EL_AMOEBA_SHRINKING));
4475 boolean can_turn_left =
4476 (MOLE_CAN_ENTER_FIELD(element, left_x, left_y,
4477 IS_AMOEBOID(Feld[left_x][left_y])));
4479 boolean can_turn_right =
4480 (MOLE_CAN_ENTER_FIELD(element, right_x, right_y,
4481 IS_AMOEBOID(Feld[right_x][right_y])));
4483 if (can_turn_left && can_turn_right)
4484 MovDir[x][y] = (RND(2) ? left_dir : right_dir);
4485 else if (can_turn_left)
4486 MovDir[x][y] = left_dir;
4488 MovDir[x][y] = right_dir;
4491 if (MovDir[x][y] != old_move_dir)
4494 else if (element == EL_BALLOON)
4496 MovDir[x][y] = game.wind_direction;
4499 else if (element == EL_SPRING)
4501 if (MovDir[x][y] & MV_HORIZONTAL &&
4502 (!SPRING_CAN_ENTER_FIELD(element, move_x, move_y) ||
4503 SPRING_CAN_ENTER_FIELD(element, x, y + 1)))
4504 MovDir[x][y] = MV_NONE;
4508 else if (element == EL_ROBOT ||
4509 element == EL_SATELLITE ||
4510 element == EL_PENGUIN)
4512 int attr_x = -1, attr_y = -1;
4523 for (i = 0; i < MAX_PLAYERS; i++)
4525 struct PlayerInfo *player = &stored_player[i];
4526 int jx = player->jx, jy = player->jy;
4528 if (!player->active)
4532 ABS(jx - x) + ABS(jy - y) < ABS(attr_x - x) + ABS(attr_y - y))
4540 if (element == EL_ROBOT && ZX >= 0 && ZY >= 0 &&
4541 (Feld[ZX][ZY] == EL_ROBOT_WHEEL_ACTIVE ||
4542 game.engine_version < VERSION_IDENT(3,1,0,0)))
4548 if (element == EL_PENGUIN)
4551 static int xy[4][2] =
4559 for (i = 0; i < NUM_DIRECTIONS; i++)
4561 int ex = x + xy[i][0];
4562 int ey = y + xy[i][1];
4564 if (IN_LEV_FIELD(ex, ey) && Feld[ex][ey] == EL_EXIT_OPEN)
4573 MovDir[x][y] = MV_NONE;
4575 MovDir[x][y] |= (AllPlayersGone ? MV_RIGHT : MV_LEFT);
4576 else if (attr_x > x)
4577 MovDir[x][y] |= (AllPlayersGone ? MV_LEFT : MV_RIGHT);
4579 MovDir[x][y] |= (AllPlayersGone ? MV_DOWN : MV_UP);
4580 else if (attr_y > y)
4581 MovDir[x][y] |= (AllPlayersGone ? MV_UP : MV_DOWN);
4583 if (element == EL_ROBOT)
4587 if (MovDir[x][y] & MV_HORIZONTAL && MovDir[x][y] & MV_VERTICAL)
4588 MovDir[x][y] &= (RND(2) ? MV_HORIZONTAL : MV_VERTICAL);
4589 Moving2Blocked(x, y, &newx, &newy);
4591 if (IN_LEV_FIELD(newx, newy) && IS_FREE_OR_PLAYER(newx, newy))
4592 MovDelay[x][y] = 8 + 8 * !RND(3);
4594 MovDelay[x][y] = 16;
4596 else if (element == EL_PENGUIN)
4602 if (MovDir[x][y] & MV_HORIZONTAL && MovDir[x][y] & MV_VERTICAL)
4604 boolean first_horiz = RND(2);
4605 int new_move_dir = MovDir[x][y];
4608 new_move_dir & (first_horiz ? MV_HORIZONTAL : MV_VERTICAL);
4609 Moving2Blocked(x, y, &newx, &newy);
4611 if (PENGUIN_CAN_ENTER_FIELD(EL_PENGUIN, newx, newy))
4615 new_move_dir & (!first_horiz ? MV_HORIZONTAL : MV_VERTICAL);
4616 Moving2Blocked(x, y, &newx, &newy);
4618 if (PENGUIN_CAN_ENTER_FIELD(EL_PENGUIN, newx, newy))
4621 MovDir[x][y] = old_move_dir;
4625 else /* (element == EL_SATELLITE) */
4631 if (MovDir[x][y] & MV_HORIZONTAL && MovDir[x][y] & MV_VERTICAL)
4633 boolean first_horiz = RND(2);
4634 int new_move_dir = MovDir[x][y];
4637 new_move_dir & (first_horiz ? MV_HORIZONTAL : MV_VERTICAL);
4638 Moving2Blocked(x, y, &newx, &newy);
4640 if (SATELLITE_CAN_ENTER_FIELD(newx, newy))
4644 new_move_dir & (!first_horiz ? MV_HORIZONTAL : MV_VERTICAL);
4645 Moving2Blocked(x, y, &newx, &newy);
4647 if (SATELLITE_CAN_ENTER_FIELD(newx, newy))
4650 MovDir[x][y] = old_move_dir;
4655 else if (move_pattern == MV_TURNING_LEFT ||
4656 move_pattern == MV_TURNING_RIGHT ||
4657 move_pattern == MV_TURNING_LEFT_RIGHT ||
4658 move_pattern == MV_TURNING_RIGHT_LEFT ||
4659 move_pattern == MV_TURNING_RANDOM ||
4660 move_pattern == MV_ALL_DIRECTIONS)
4662 boolean can_turn_left =
4663 CUSTOM_ELEMENT_CAN_ENTER_FIELD(element, left_x, left_y);
4664 boolean can_turn_right =
4665 CUSTOM_ELEMENT_CAN_ENTER_FIELD(element, right_x,right_y);
4667 if (element_info[element].move_stepsize == 0) /* "not moving" */
4670 if (move_pattern == MV_TURNING_LEFT)
4671 MovDir[x][y] = left_dir;
4672 else if (move_pattern == MV_TURNING_RIGHT)
4673 MovDir[x][y] = right_dir;
4674 else if (move_pattern == MV_TURNING_LEFT_RIGHT)
4675 MovDir[x][y] = (can_turn_left || !can_turn_right ? left_dir : right_dir);
4676 else if (move_pattern == MV_TURNING_RIGHT_LEFT)
4677 MovDir[x][y] = (can_turn_right || !can_turn_left ? right_dir : left_dir);
4678 else if (move_pattern == MV_TURNING_RANDOM)
4679 MovDir[x][y] = (can_turn_left && !can_turn_right ? left_dir :
4680 can_turn_right && !can_turn_left ? right_dir :
4681 RND(2) ? left_dir : right_dir);
4682 else if (can_turn_left && can_turn_right)
4683 MovDir[x][y] = (RND(3) ? (RND(2) ? left_dir : right_dir) : back_dir);
4684 else if (can_turn_left)
4685 MovDir[x][y] = (RND(2) ? left_dir : back_dir);
4686 else if (can_turn_right)
4687 MovDir[x][y] = (RND(2) ? right_dir : back_dir);
4689 MovDir[x][y] = back_dir;
4691 MovDelay[x][y] = GET_NEW_MOVE_DELAY(element);
4693 else if (move_pattern == MV_HORIZONTAL ||
4694 move_pattern == MV_VERTICAL)
4696 if (move_pattern & old_move_dir)
4697 MovDir[x][y] = back_dir;
4698 else if (move_pattern == MV_HORIZONTAL)
4699 MovDir[x][y] = (RND(2) ? MV_LEFT : MV_RIGHT);
4700 else if (move_pattern == MV_VERTICAL)
4701 MovDir[x][y] = (RND(2) ? MV_UP : MV_DOWN);
4703 MovDelay[x][y] = GET_NEW_MOVE_DELAY(element);
4705 else if (move_pattern & MV_ANY_DIRECTION)
4707 MovDir[x][y] = move_pattern;
4708 MovDelay[x][y] = GET_NEW_MOVE_DELAY(element);
4710 else if (move_pattern & MV_WIND_DIRECTION)
4712 MovDir[x][y] = game.wind_direction;
4713 MovDelay[x][y] = GET_NEW_MOVE_DELAY(element);
4715 else if (move_pattern == MV_ALONG_LEFT_SIDE)
4717 if (CUSTOM_ELEMENT_CAN_ENTER_FIELD(element, left_x, left_y))
4718 MovDir[x][y] = left_dir;
4719 else if (!CUSTOM_ELEMENT_CAN_ENTER_FIELD(element, move_x, move_y))
4720 MovDir[x][y] = right_dir;
4722 if (MovDir[x][y] != old_move_dir)
4723 MovDelay[x][y] = GET_NEW_MOVE_DELAY(element);
4725 else if (move_pattern == MV_ALONG_RIGHT_SIDE)
4727 if (CUSTOM_ELEMENT_CAN_ENTER_FIELD(element, right_x, right_y))
4728 MovDir[x][y] = right_dir;
4729 else if (!CUSTOM_ELEMENT_CAN_ENTER_FIELD(element, move_x, move_y))
4730 MovDir[x][y] = left_dir;
4732 if (MovDir[x][y] != old_move_dir)
4733 MovDelay[x][y] = GET_NEW_MOVE_DELAY(element);
4735 else if (move_pattern == MV_TOWARDS_PLAYER ||
4736 move_pattern == MV_AWAY_FROM_PLAYER)
4738 int attr_x = -1, attr_y = -1;
4740 boolean move_away = (move_pattern == MV_AWAY_FROM_PLAYER);
4751 for (i = 0; i < MAX_PLAYERS; i++)
4753 struct PlayerInfo *player = &stored_player[i];
4754 int jx = player->jx, jy = player->jy;
4756 if (!player->active)
4760 ABS(jx - x) + ABS(jy - y) < ABS(attr_x - x) + ABS(attr_y - y))
4768 MovDir[x][y] = MV_NONE;
4770 MovDir[x][y] |= (move_away ? MV_RIGHT : MV_LEFT);
4771 else if (attr_x > x)
4772 MovDir[x][y] |= (move_away ? MV_LEFT : MV_RIGHT);
4774 MovDir[x][y] |= (move_away ? MV_DOWN : MV_UP);
4775 else if (attr_y > y)
4776 MovDir[x][y] |= (move_away ? MV_UP : MV_DOWN);
4778 MovDelay[x][y] = GET_NEW_MOVE_DELAY(element);
4780 if (MovDir[x][y] & MV_HORIZONTAL && MovDir[x][y] & MV_VERTICAL)
4782 boolean first_horiz = RND(2);
4783 int new_move_dir = MovDir[x][y];
4785 if (element_info[element].move_stepsize == 0) /* "not moving" */
4787 first_horiz = (ABS(attr_x - x) >= ABS(attr_y - y));
4788 MovDir[x][y] &= (first_horiz ? MV_HORIZONTAL : MV_VERTICAL);
4794 new_move_dir & (first_horiz ? MV_HORIZONTAL : MV_VERTICAL);
4795 Moving2Blocked(x, y, &newx, &newy);
4797 if (CUSTOM_ELEMENT_CAN_ENTER_FIELD(element, newx, newy))
4801 new_move_dir & (!first_horiz ? MV_HORIZONTAL : MV_VERTICAL);
4802 Moving2Blocked(x, y, &newx, &newy);
4804 if (CUSTOM_ELEMENT_CAN_ENTER_FIELD(element, newx, newy))
4807 MovDir[x][y] = old_move_dir;
4810 else if (move_pattern == MV_WHEN_PUSHED ||
4811 move_pattern == MV_WHEN_DROPPED)
4813 if (!CUSTOM_ELEMENT_CAN_ENTER_FIELD(element, move_x, move_y))
4814 MovDir[x][y] = MV_NONE;
4818 else if (move_pattern & MV_MAZE_RUNNER_STYLE)
4820 static int test_xy[7][2] =
4830 static int test_dir[7] =
4840 boolean hunter_mode = (move_pattern == MV_MAZE_HUNTER);
4841 int move_preference = -1000000; /* start with very low preference */
4842 int new_move_dir = MV_NONE;
4843 int start_test = RND(4);
4846 for (i = 0; i < NUM_DIRECTIONS; i++)
4848 int move_dir = test_dir[start_test + i];
4849 int move_dir_preference;
4851 xx = x + test_xy[start_test + i][0];
4852 yy = y + test_xy[start_test + i][1];
4854 if (hunter_mode && IN_LEV_FIELD(xx, yy) &&
4855 (IS_PLAYER(xx, yy) || Feld[xx][yy] == EL_PLAYER_IS_LEAVING))
4857 new_move_dir = move_dir;
4862 if (!CUSTOM_ELEMENT_CAN_ENTER_FIELD(element, xx, yy))
4865 move_dir_preference = -1 * RunnerVisit[xx][yy];
4866 if (hunter_mode && PlayerVisit[xx][yy] > 0)
4867 move_dir_preference = PlayerVisit[xx][yy];
4869 if (move_dir_preference > move_preference)
4871 /* prefer field that has not been visited for the longest time */
4872 move_preference = move_dir_preference;
4873 new_move_dir = move_dir;
4875 else if (move_dir_preference == move_preference &&
4876 move_dir == old_move_dir)
4878 /* prefer last direction when all directions are preferred equally */
4879 move_preference = move_dir_preference;
4880 new_move_dir = move_dir;
4884 MovDir[x][y] = new_move_dir;
4885 if (old_move_dir != new_move_dir)
4886 MovDelay[x][y] = GET_NEW_MOVE_DELAY(element);
4890 static void TurnRound(int x, int y)
4892 int direction = MovDir[x][y];
4896 GfxDir[x][y] = MovDir[x][y];
4898 if (direction != MovDir[x][y])
4902 GfxAction[x][y] = ACTION_TURNING_FROM_LEFT + MV_DIR_BIT(direction);
4905 static boolean JustBeingPushed(int x, int y)
4909 for (i = 0; i < MAX_PLAYERS; i++)
4911 struct PlayerInfo *player = &stored_player[i];
4913 if (player->active && player->is_pushing && player->MovPos)
4915 int next_jx = player->jx + (player->jx - player->last_jx);
4916 int next_jy = player->jy + (player->jy - player->last_jy);
4918 if (x == next_jx && y == next_jy)
4926 void StartMoving(int x, int y)
4928 boolean started_moving = FALSE; /* some elements can fall _and_ move */
4929 int element = Feld[x][y];
4934 if (MovDelay[x][y] == 0)
4935 GfxAction[x][y] = ACTION_DEFAULT;
4937 if (CAN_FALL(element) && y < lev_fieldy - 1)
4939 if ((x > 0 && IS_PLAYER(x - 1, y)) ||
4940 (x < lev_fieldx - 1 && IS_PLAYER(x + 1, y)))
4941 if (JustBeingPushed(x, y))
4944 if (element == EL_QUICKSAND_FULL)
4946 if (IS_FREE(x, y + 1))
4948 InitMovingField(x, y, MV_DOWN);
4949 started_moving = TRUE;
4951 Feld[x][y] = EL_QUICKSAND_EMPTYING;
4952 Store[x][y] = EL_ROCK;
4954 PlayLevelSoundAction(x, y, ACTION_EMPTYING);
4956 else if (Feld[x][y + 1] == EL_QUICKSAND_EMPTY)
4958 if (!MovDelay[x][y])
4959 MovDelay[x][y] = TILEY + 1;
4968 Feld[x][y] = EL_QUICKSAND_EMPTY;
4969 Feld[x][y + 1] = EL_QUICKSAND_FULL;
4970 Store[x][y + 1] = Store[x][y];
4973 PlayLevelSoundAction(x, y, ACTION_FILLING);
4976 else if ((element == EL_ROCK || element == EL_BD_ROCK) &&
4977 Feld[x][y + 1] == EL_QUICKSAND_EMPTY)
4979 InitMovingField(x, y, MV_DOWN);
4980 started_moving = TRUE;
4982 Feld[x][y] = EL_QUICKSAND_FILLING;
4983 Store[x][y] = element;
4985 PlayLevelSoundAction(x, y, ACTION_FILLING);
4987 else if (element == EL_MAGIC_WALL_FULL)
4989 if (IS_FREE(x, y + 1))
4991 InitMovingField(x, y, MV_DOWN);
4992 started_moving = TRUE;
4994 Feld[x][y] = EL_MAGIC_WALL_EMPTYING;
4995 Store[x][y] = EL_CHANGED(Store[x][y]);
4997 else if (Feld[x][y + 1] == EL_MAGIC_WALL_ACTIVE)
4999 if (!MovDelay[x][y])
5000 MovDelay[x][y] = TILEY/4 + 1;
5009 Feld[x][y] = EL_MAGIC_WALL_ACTIVE;
5010 Feld[x][y + 1] = EL_MAGIC_WALL_FULL;
5011 Store[x][y + 1] = EL_CHANGED(Store[x][y]);
5015 else if (element == EL_BD_MAGIC_WALL_FULL)
5017 if (IS_FREE(x, y + 1))
5019 InitMovingField(x, y, MV_DOWN);
5020 started_moving = TRUE;
5022 Feld[x][y] = EL_BD_MAGIC_WALL_EMPTYING;
5023 Store[x][y] = EL_CHANGED2(Store[x][y]);
5025 else if (Feld[x][y + 1] == EL_BD_MAGIC_WALL_ACTIVE)
5027 if (!MovDelay[x][y])
5028 MovDelay[x][y] = TILEY/4 + 1;
5037 Feld[x][y] = EL_BD_MAGIC_WALL_ACTIVE;
5038 Feld[x][y + 1] = EL_BD_MAGIC_WALL_FULL;
5039 Store[x][y + 1] = EL_CHANGED2(Store[x][y]);
5043 else if (CAN_PASS_MAGIC_WALL(element) &&
5044 (Feld[x][y + 1] == EL_MAGIC_WALL_ACTIVE ||
5045 Feld[x][y + 1] == EL_BD_MAGIC_WALL_ACTIVE))
5047 InitMovingField(x, y, MV_DOWN);
5048 started_moving = TRUE;
5051 (Feld[x][y + 1] == EL_MAGIC_WALL_ACTIVE ? EL_MAGIC_WALL_FILLING :
5052 EL_BD_MAGIC_WALL_FILLING);
5053 Store[x][y] = element;
5055 else if (CAN_FALL(element) && Feld[x][y + 1] == EL_ACID)
5057 SplashAcid(x, y + 1);
5059 InitMovingField(x, y, MV_DOWN);
5060 started_moving = TRUE;
5062 Store[x][y] = EL_ACID;
5064 else if ((game.engine_version >= VERSION_IDENT(3,1,0,0) &&
5065 CheckCollision[x][y] && !IS_FREE(x, y + 1)) ||
5067 (game.engine_version >= VERSION_IDENT(3,0,7,0) &&
5068 CAN_FALL(element) && WasJustFalling[x][y] &&
5069 (Feld[x][y + 1] == EL_BLOCKED || IS_PLAYER(x, y + 1))) ||
5071 (game.engine_version < VERSION_IDENT(2,2,0,7) &&
5072 CAN_FALL(element) && WasJustMoving[x][y] && !Pushed[x][y + 1] &&
5073 (Feld[x][y + 1] == EL_BLOCKED)))
5075 /* this is needed for a special case not covered by calling "Impact()"
5076 from "ContinueMoving()": if an element moves to a tile directly below
5077 another element which was just falling on that tile (which was empty
5078 in the previous frame), the falling element above would just stop
5079 instead of smashing the element below (in previous version, the above
5080 element was just checked for "moving" instead of "falling", resulting
5081 in incorrect smashes caused by horizontal movement of the above
5082 element; also, the case of the player being the element to smash was
5083 simply not covered here... :-/ ) */
5085 CheckCollision[x][y] = 0;
5089 else if (IS_FREE(x, y + 1) && element == EL_SPRING && level.use_spring_bug)
5091 if (MovDir[x][y] == MV_NONE)
5093 InitMovingField(x, y, MV_DOWN);
5094 started_moving = TRUE;
5097 else if (IS_FREE(x, y + 1) || Feld[x][y + 1] == EL_DIAMOND_BREAKING)
5099 if (WasJustFalling[x][y]) /* prevent animation from being restarted */
5100 MovDir[x][y] = MV_DOWN;
5102 InitMovingField(x, y, MV_DOWN);
5103 started_moving = TRUE;
5105 else if (element == EL_AMOEBA_DROP)
5107 Feld[x][y] = EL_AMOEBA_GROWING;
5108 Store[x][y] = EL_AMOEBA_WET;
5110 else if (((IS_SLIPPERY(Feld[x][y + 1]) && !IS_PLAYER(x, y + 1)) ||
5111 (IS_EM_SLIPPERY_WALL(Feld[x][y + 1]) && IS_GEM(element))) &&
5112 !IS_FALLING(x, y + 1) && !WasJustMoving[x][y + 1] &&
5113 element != EL_DX_SUPABOMB && element != EL_SP_DISK_ORANGE)
5115 boolean can_fall_left = (x > 0 && IS_FREE(x - 1, y) &&
5116 (IS_FREE(x - 1, y + 1) ||
5117 Feld[x - 1][y + 1] == EL_ACID));
5118 boolean can_fall_right = (x < lev_fieldx - 1 && IS_FREE(x + 1, y) &&
5119 (IS_FREE(x + 1, y + 1) ||
5120 Feld[x + 1][y + 1] == EL_ACID));
5121 boolean can_fall_any = (can_fall_left || can_fall_right);
5122 boolean can_fall_both = (can_fall_left && can_fall_right);
5123 int slippery_type = element_info[Feld[x][y + 1]].slippery_type;
5125 #if USE_NEW_ALL_SLIPPERY
5126 if (can_fall_any && slippery_type != SLIPPERY_ANY_RANDOM)
5128 if (slippery_type == SLIPPERY_ANY_LEFT_RIGHT && can_fall_both)
5129 can_fall_right = FALSE;
5130 else if (slippery_type == SLIPPERY_ANY_RIGHT_LEFT && can_fall_both)
5131 can_fall_left = FALSE;
5132 else if (slippery_type == SLIPPERY_ONLY_LEFT)
5133 can_fall_right = FALSE;
5134 else if (slippery_type == SLIPPERY_ONLY_RIGHT)
5135 can_fall_left = FALSE;
5137 can_fall_any = (can_fall_left || can_fall_right);
5138 can_fall_both = FALSE;
5141 if (can_fall_any && IS_CUSTOM_ELEMENT(Feld[x][y + 1]))
5143 if (slippery_type == SLIPPERY_ONLY_LEFT)
5144 can_fall_right = FALSE;
5145 else if (slippery_type == SLIPPERY_ONLY_RIGHT)
5146 can_fall_left = FALSE;
5147 else if (slippery_type == SLIPPERY_ANY_LEFT_RIGHT && can_fall_both)
5148 can_fall_right = FALSE;
5149 else if (slippery_type == SLIPPERY_ANY_RIGHT_LEFT && can_fall_both)
5150 can_fall_left = FALSE;
5152 can_fall_any = (can_fall_left || can_fall_right);
5153 can_fall_both = (can_fall_left && can_fall_right);
5157 #if USE_NEW_ALL_SLIPPERY
5159 #if USE_NEW_SP_SLIPPERY
5160 /* !!! better use the same properties as for custom elements here !!! */
5161 else if (game.engine_version >= VERSION_IDENT(3,1,1,0) &&
5162 can_fall_both && IS_SP_ELEMENT(Feld[x][y + 1]))
5164 can_fall_right = FALSE; /* slip down on left side */
5165 can_fall_both = FALSE;
5170 #if USE_NEW_ALL_SLIPPERY
5173 if (element == EL_BD_ROCK || element == EL_BD_DIAMOND)
5174 can_fall_right = FALSE; /* slip down on left side */
5176 can_fall_left = !(can_fall_right = RND(2));
5178 can_fall_both = FALSE;
5183 if (game.emulation == EMU_BOULDERDASH ||
5184 element == EL_BD_ROCK || element == EL_BD_DIAMOND)
5185 can_fall_right = FALSE; /* slip down on left side */
5187 can_fall_left = !(can_fall_right = RND(2));
5189 can_fall_both = FALSE;
5195 /* if not determined otherwise, prefer left side for slipping down */
5196 InitMovingField(x, y, can_fall_left ? MV_LEFT : MV_RIGHT);
5197 started_moving = TRUE;
5201 else if (IS_BELT_ACTIVE(Feld[x][y + 1]) && !CAN_MOVE(element))
5203 else if (IS_BELT_ACTIVE(Feld[x][y + 1]))
5206 boolean left_is_free = (x > 0 && IS_FREE(x - 1, y));
5207 boolean right_is_free = (x < lev_fieldx - 1 && IS_FREE(x + 1, y));
5208 int belt_nr = getBeltNrFromBeltActiveElement(Feld[x][y + 1]);
5209 int belt_dir = game.belt_dir[belt_nr];
5211 if ((belt_dir == MV_LEFT && left_is_free) ||
5212 (belt_dir == MV_RIGHT && right_is_free))
5214 int nextx = (belt_dir == MV_LEFT ? x - 1 : x + 1);
5216 InitMovingField(x, y, belt_dir);
5217 started_moving = TRUE;
5219 Pushed[x][y] = TRUE;
5220 Pushed[nextx][y] = TRUE;
5222 GfxAction[x][y] = ACTION_DEFAULT;
5226 MovDir[x][y] = 0; /* if element was moving, stop it */
5231 /* not "else if" because of elements that can fall and move (EL_SPRING) */
5233 if (CAN_MOVE(element) && !started_moving && MovDir[x][y] != MV_NONE)
5235 if (CAN_MOVE(element) && !started_moving)
5238 int move_pattern = element_info[element].move_pattern;
5243 if (MovDir[x][y] == MV_NONE)
5245 printf("StartMoving(): %d,%d: element %d ['%s'] not moving\n",
5246 x, y, element, element_info[element].token_name);
5247 printf("StartMoving(): This should never happen!\n");
5252 Moving2Blocked(x, y, &newx, &newy);
5254 if (IS_PUSHABLE(element) && JustBeingPushed(x, y))
5257 if (game.engine_version >= VERSION_IDENT(3,1,0,0) &&
5258 CheckCollision[x][y] && !IN_LEV_FIELD_AND_IS_FREE(newx, newy))
5260 WasJustMoving[x][y] = 0;
5261 CheckCollision[x][y] = 0;
5263 TestIfElementHitsCustomElement(x, y, MovDir[x][y]);
5265 if (Feld[x][y] != element) /* element has changed */
5269 if (!MovDelay[x][y]) /* start new movement phase */
5271 /* all objects that can change their move direction after each step
5272 (YAMYAM, DARK_YAMYAM and PACMAN go straight until they hit a wall */
5274 if (element != EL_YAMYAM &&
5275 element != EL_DARK_YAMYAM &&
5276 element != EL_PACMAN &&
5277 !(move_pattern & MV_ANY_DIRECTION) &&
5278 move_pattern != MV_TURNING_LEFT &&
5279 move_pattern != MV_TURNING_RIGHT &&
5280 move_pattern != MV_TURNING_LEFT_RIGHT &&
5281 move_pattern != MV_TURNING_RIGHT_LEFT &&
5282 move_pattern != MV_TURNING_RANDOM)
5286 if (MovDelay[x][y] && (element == EL_BUG ||
5287 element == EL_SPACESHIP ||
5288 element == EL_SP_SNIKSNAK ||
5289 element == EL_SP_ELECTRON ||
5290 element == EL_MOLE))
5291 DrawLevelField(x, y);
5295 if (MovDelay[x][y]) /* wait some time before next movement */
5299 if (element == EL_ROBOT ||
5300 element == EL_YAMYAM ||
5301 element == EL_DARK_YAMYAM)
5303 DrawLevelElementAnimationIfNeeded(x, y, element);
5304 PlayLevelSoundAction(x, y, ACTION_WAITING);
5306 else if (element == EL_SP_ELECTRON)
5307 DrawLevelElementAnimationIfNeeded(x, y, element);
5308 else if (element == EL_DRAGON)
5311 int dir = MovDir[x][y];
5312 int dx = (dir == MV_LEFT ? -1 : dir == MV_RIGHT ? +1 : 0);
5313 int dy = (dir == MV_UP ? -1 : dir == MV_DOWN ? +1 : 0);
5314 int graphic = (dir == MV_LEFT ? IMG_FLAMES_1_LEFT :
5315 dir == MV_RIGHT ? IMG_FLAMES_1_RIGHT :
5316 dir == MV_UP ? IMG_FLAMES_1_UP :
5317 dir == MV_DOWN ? IMG_FLAMES_1_DOWN : IMG_EMPTY);
5318 int frame = getGraphicAnimationFrame(graphic, GfxFrame[x][y]);
5320 GfxAction[x][y] = ACTION_ATTACKING;
5322 if (IS_PLAYER(x, y))
5323 DrawPlayerField(x, y);
5325 DrawLevelField(x, y);
5327 PlayLevelSoundActionIfLoop(x, y, ACTION_ATTACKING);
5329 for (i = 1; i <= 3; i++)
5331 int xx = x + i * dx;
5332 int yy = y + i * dy;
5333 int sx = SCREENX(xx);
5334 int sy = SCREENY(yy);
5335 int flame_graphic = graphic + (i - 1);
5337 if (!IN_LEV_FIELD(xx, yy) || IS_DRAGONFIRE_PROOF(Feld[xx][yy]))
5342 int flamed = MovingOrBlocked2Element(xx, yy);
5346 if (IS_CLASSIC_ENEMY(flamed) || CAN_EXPLODE_BY_DRAGONFIRE(flamed))
5348 else if (IS_MOVING(xx, yy) || IS_BLOCKED(xx, yy))
5349 RemoveMovingField(xx, yy);
5351 RemoveField(xx, yy);
5353 if (IS_CLASSIC_ENEMY(flamed) || CAN_EXPLODE_BY_DRAGONFIRE(flamed))
5356 RemoveMovingField(xx, yy);
5359 ChangeDelay[xx][yy] = 0;
5361 Feld[xx][yy] = EL_FLAMES;
5363 if (IN_SCR_FIELD(sx, sy))
5365 DrawLevelFieldCrumbledSand(xx, yy);
5366 DrawGraphic(sx, sy, flame_graphic, frame);
5371 if (Feld[xx][yy] == EL_FLAMES)
5372 Feld[xx][yy] = EL_EMPTY;
5373 DrawLevelField(xx, yy);
5378 if (MovDelay[x][y]) /* element still has to wait some time */
5380 PlayLevelSoundAction(x, y, ACTION_WAITING);
5386 /* now make next step */
5388 Moving2Blocked(x, y, &newx, &newy); /* get next screen position */
5390 if (DONT_COLLIDE_WITH(element) &&
5391 IN_LEV_FIELD(newx, newy) && IS_PLAYER(newx, newy) &&
5392 !PLAYER_ENEMY_PROTECTED(newx, newy))
5394 TestIfBadThingRunsIntoPlayer(x, y, MovDir[x][y]);
5399 else if (CAN_MOVE_INTO_ACID(element) &&
5400 IN_LEV_FIELD(newx, newy) && Feld[newx][newy] == EL_ACID &&
5401 (MovDir[x][y] == MV_DOWN ||
5402 game.engine_version >= VERSION_IDENT(3,1,0,0)))
5404 SplashAcid(newx, newy);
5405 Store[x][y] = EL_ACID;
5407 else if (element == EL_PENGUIN && IN_LEV_FIELD(newx, newy))
5409 if (Feld[newx][newy] == EL_EXIT_OPEN)
5412 DrawLevelField(x, y);
5414 PlayLevelSound(newx, newy, SND_PENGUIN_PASSING);
5415 if (IN_SCR_FIELD(SCREENX(newx), SCREENY(newy)))
5416 DrawGraphicThruMask(SCREENX(newx),SCREENY(newy), el2img(element), 0);
5418 local_player->friends_still_needed--;
5419 if (!local_player->friends_still_needed &&
5420 !local_player->GameOver && AllPlayersGone)
5421 local_player->LevelSolved = local_player->GameOver = TRUE;
5425 else if (IS_FOOD_PENGUIN(Feld[newx][newy]))
5427 if (DigField(local_player, x, y, newx, newy, 0,0, DF_DIG) == MF_MOVING)
5428 DrawLevelField(newx, newy);
5430 GfxDir[x][y] = MovDir[x][y] = MV_NONE;
5432 else if (!IS_FREE(newx, newy))
5434 GfxAction[x][y] = ACTION_WAITING;
5436 if (IS_PLAYER(x, y))
5437 DrawPlayerField(x, y);
5439 DrawLevelField(x, y);
5444 else if (element == EL_PIG && IN_LEV_FIELD(newx, newy))
5446 if (IS_FOOD_PIG(Feld[newx][newy]))
5448 if (IS_MOVING(newx, newy))
5449 RemoveMovingField(newx, newy);
5452 Feld[newx][newy] = EL_EMPTY;
5453 DrawLevelField(newx, newy);
5456 PlayLevelSound(x, y, SND_PIG_DIGGING);
5458 else if (!IS_FREE(newx, newy))
5460 if (IS_PLAYER(x, y))
5461 DrawPlayerField(x, y);
5463 DrawLevelField(x, y);
5468 else if (IS_CUSTOM_ELEMENT(element) &&
5469 CUSTOM_ELEMENT_CAN_ENTER_FIELD(element, newx, newy))
5471 int new_element = Feld[newx][newy];
5473 if (!IS_FREE(newx, newy))
5475 int action = (IS_DIGGABLE(new_element) ? ACTION_DIGGING :
5476 IS_COLLECTIBLE(new_element) ? ACTION_COLLECTING :
5479 /* no element can dig solid indestructible elements */
5480 if (IS_INDESTRUCTIBLE(new_element) &&
5481 !IS_DIGGABLE(new_element) &&
5482 !IS_COLLECTIBLE(new_element))
5485 if (AmoebaNr[newx][newy] &&
5486 (new_element == EL_AMOEBA_FULL ||
5487 new_element == EL_BD_AMOEBA ||
5488 new_element == EL_AMOEBA_GROWING))
5490 AmoebaCnt[AmoebaNr[newx][newy]]--;
5491 AmoebaCnt2[AmoebaNr[newx][newy]]--;
5494 if (IS_MOVING(newx, newy))
5495 RemoveMovingField(newx, newy);
5498 RemoveField(newx, newy);
5499 DrawLevelField(newx, newy);
5502 /* if digged element was about to explode, prevent the explosion */
5503 ExplodeField[newx][newy] = EX_TYPE_NONE;
5505 PlayLevelSoundAction(x, y, action);
5508 Store[newx][newy] = EL_EMPTY;
5509 if (IS_EQUAL_OR_IN_GROUP(new_element, MOVE_ENTER_EL(element)))
5511 int move_leave_element = element_info[element].move_leave_element;
5513 /* this makes it possible to leave the removed element again */
5514 Store[newx][newy] = (move_leave_element == EL_TRIGGER_ELEMENT ?
5515 new_element : move_leave_element);
5518 if (move_pattern & MV_MAZE_RUNNER_STYLE)
5520 RunnerVisit[x][y] = FrameCounter;
5521 PlayerVisit[x][y] /= 8; /* expire player visit path */
5524 else if (element == EL_DRAGON && IN_LEV_FIELD(newx, newy))
5526 if (!IS_FREE(newx, newy))
5528 if (IS_PLAYER(x, y))
5529 DrawPlayerField(x, y);
5531 DrawLevelField(x, y);
5537 boolean wanna_flame = !RND(10);
5538 int dx = newx - x, dy = newy - y;
5539 int newx1 = newx + 1 * dx, newy1 = newy + 1 * dy;
5540 int newx2 = newx + 2 * dx, newy2 = newy + 2 * dy;
5541 int element1 = (IN_LEV_FIELD(newx1, newy1) ?
5542 MovingOrBlocked2Element(newx1, newy1) : EL_STEELWALL);
5543 int element2 = (IN_LEV_FIELD(newx2, newy2) ?
5544 MovingOrBlocked2Element(newx2, newy2) : EL_STEELWALL);
5547 IS_CLASSIC_ENEMY(element1) ||
5548 IS_CLASSIC_ENEMY(element2)) &&
5549 element1 != EL_DRAGON && element2 != EL_DRAGON &&
5550 element1 != EL_FLAMES && element2 != EL_FLAMES)
5552 ResetGfxAnimation(x, y);
5553 GfxAction[x][y] = ACTION_ATTACKING;
5555 if (IS_PLAYER(x, y))
5556 DrawPlayerField(x, y);
5558 DrawLevelField(x, y);
5560 PlayLevelSound(x, y, SND_DRAGON_ATTACKING);
5562 MovDelay[x][y] = 50;
5566 RemoveField(newx, newy);
5568 Feld[newx][newy] = EL_FLAMES;
5569 if (IN_LEV_FIELD(newx1, newy1) && Feld[newx1][newy1] == EL_EMPTY)
5572 RemoveField(newx1, newy1);
5574 Feld[newx1][newy1] = EL_FLAMES;
5576 if (IN_LEV_FIELD(newx2, newy2) && Feld[newx2][newy2] == EL_EMPTY)
5579 RemoveField(newx2, newy2);
5581 Feld[newx2][newy2] = EL_FLAMES;
5588 else if (element == EL_YAMYAM && IN_LEV_FIELD(newx, newy) &&
5589 Feld[newx][newy] == EL_DIAMOND)
5591 if (IS_MOVING(newx, newy))
5592 RemoveMovingField(newx, newy);
5595 Feld[newx][newy] = EL_EMPTY;
5596 DrawLevelField(newx, newy);
5599 PlayLevelSound(x, y, SND_YAMYAM_DIGGING);
5601 else if (element == EL_DARK_YAMYAM && IN_LEV_FIELD(newx, newy) &&
5602 IS_FOOD_DARK_YAMYAM(Feld[newx][newy]))
5604 if (AmoebaNr[newx][newy])
5606 AmoebaCnt2[AmoebaNr[newx][newy]]--;
5607 if (Feld[newx][newy] == EL_AMOEBA_FULL ||
5608 Feld[newx][newy] == EL_BD_AMOEBA)
5609 AmoebaCnt[AmoebaNr[newx][newy]]--;
5614 if (IS_MOVING(newx, newy) || IS_BLOCKED(newx, newy))
5616 RemoveMovingField(newx, newy);
5619 if (IS_MOVING(newx, newy))
5621 RemoveMovingField(newx, newy);
5626 Feld[newx][newy] = EL_EMPTY;
5627 DrawLevelField(newx, newy);
5630 PlayLevelSound(x, y, SND_DARK_YAMYAM_DIGGING);
5632 else if ((element == EL_PACMAN || element == EL_MOLE)
5633 && IN_LEV_FIELD(newx, newy) && IS_AMOEBOID(Feld[newx][newy]))
5635 if (AmoebaNr[newx][newy])
5637 AmoebaCnt2[AmoebaNr[newx][newy]]--;
5638 if (Feld[newx][newy] == EL_AMOEBA_FULL ||
5639 Feld[newx][newy] == EL_BD_AMOEBA)
5640 AmoebaCnt[AmoebaNr[newx][newy]]--;
5643 if (element == EL_MOLE)
5645 Feld[newx][newy] = EL_AMOEBA_SHRINKING;
5646 PlayLevelSound(x, y, SND_MOLE_DIGGING);
5648 ResetGfxAnimation(x, y);
5649 GfxAction[x][y] = ACTION_DIGGING;
5650 DrawLevelField(x, y);
5652 MovDelay[newx][newy] = 0; /* start amoeba shrinking delay */
5654 return; /* wait for shrinking amoeba */
5656 else /* element == EL_PACMAN */
5658 Feld[newx][newy] = EL_EMPTY;
5659 DrawLevelField(newx, newy);
5660 PlayLevelSound(x, y, SND_PACMAN_DIGGING);
5663 else if (element == EL_MOLE && IN_LEV_FIELD(newx, newy) &&
5664 (Feld[newx][newy] == EL_AMOEBA_SHRINKING ||
5665 (Feld[newx][newy] == EL_EMPTY && Stop[newx][newy])))
5667 /* wait for shrinking amoeba to completely disappear */
5670 else if (!IN_LEV_FIELD(newx, newy) || !IS_FREE(newx, newy))
5672 /* object was running against a wall */
5677 /* !!! NEW "CE_BLOCKED" STUFF !!! -- DOES NOT WORK YET... !!! */
5678 if (move_pattern & MV_ANY_DIRECTION &&
5679 move_pattern == MovDir[x][y])
5681 int blocking_element =
5682 (IN_LEV_FIELD(newx, newy) ? Feld[newx][newy] : BorderElement);
5684 CheckElementChangeBySide(x, y, element, blocking_element, CE_BLOCKED,
5687 element = Feld[x][y]; /* element might have changed */
5691 if (GFX_ELEMENT(element) != EL_SAND) /* !!! FIX THIS (crumble) !!! */
5692 DrawLevelElementAnimation(x, y, element);
5694 if (DONT_TOUCH(element))
5695 TestIfBadThingTouchesPlayer(x, y);
5700 InitMovingField(x, y, MovDir[x][y]);
5702 PlayLevelSoundAction(x, y, ACTION_MOVING);
5706 ContinueMoving(x, y);
5709 void ContinueMoving(int x, int y)
5711 int element = Feld[x][y];
5712 int stored = Store[x][y];
5713 struct ElementInfo *ei = &element_info[element];
5714 int direction = MovDir[x][y];
5715 int dx = (direction == MV_LEFT ? -1 : direction == MV_RIGHT ? +1 : 0);
5716 int dy = (direction == MV_UP ? -1 : direction == MV_DOWN ? +1 : 0);
5717 int newx = x + dx, newy = y + dy;
5718 boolean pushed_by_player = (Pushed[x][y] && IS_PLAYER(x, y));
5719 boolean pushed_by_conveyor = (Pushed[x][y] && !IS_PLAYER(x, y));
5720 boolean last_line = (newy == lev_fieldy - 1);
5722 MovPos[x][y] += getElementMoveStepsize(x, y);
5724 if (pushed_by_player) /* special case: moving object pushed by player */
5725 MovPos[x][y] = SIGN(MovPos[x][y]) * (TILEX - ABS(PLAYERINFO(x,y)->MovPos));
5727 if (ABS(MovPos[x][y]) < TILEX)
5729 DrawLevelField(x, y);
5731 return; /* element is still moving */
5734 /* element reached destination field */
5736 Feld[x][y] = EL_EMPTY;
5737 Feld[newx][newy] = element;
5738 MovPos[x][y] = 0; /* force "not moving" for "crumbled sand" */
5740 if (Store[x][y] == EL_ACID) /* element is moving into acid pool */
5742 element = Feld[newx][newy] = EL_ACID;
5744 else if (element == EL_MOLE)
5746 Feld[x][y] = EL_SAND;
5748 DrawLevelFieldCrumbledSandNeighbours(x, y);
5750 else if (element == EL_QUICKSAND_FILLING)
5752 element = Feld[newx][newy] = get_next_element(element);
5753 Store[newx][newy] = Store[x][y];
5755 else if (element == EL_QUICKSAND_EMPTYING)
5757 Feld[x][y] = get_next_element(element);
5758 element = Feld[newx][newy] = Store[x][y];
5760 else if (element == EL_MAGIC_WALL_FILLING)
5762 element = Feld[newx][newy] = get_next_element(element);
5763 if (!game.magic_wall_active)
5764 element = Feld[newx][newy] = EL_MAGIC_WALL_DEAD;
5765 Store[newx][newy] = Store[x][y];
5767 else if (element == EL_MAGIC_WALL_EMPTYING)
5769 Feld[x][y] = get_next_element(element);
5770 if (!game.magic_wall_active)
5771 Feld[x][y] = EL_MAGIC_WALL_DEAD;
5772 element = Feld[newx][newy] = Store[x][y];
5774 #if USE_NEW_CUSTOM_VALUE
5775 InitField(newx, newy, FALSE);
5778 else if (element == EL_BD_MAGIC_WALL_FILLING)
5780 element = Feld[newx][newy] = get_next_element(element);
5781 if (!game.magic_wall_active)
5782 element = Feld[newx][newy] = EL_BD_MAGIC_WALL_DEAD;
5783 Store[newx][newy] = Store[x][y];
5785 else if (element == EL_BD_MAGIC_WALL_EMPTYING)
5787 Feld[x][y] = get_next_element(element);
5788 if (!game.magic_wall_active)
5789 Feld[x][y] = EL_BD_MAGIC_WALL_DEAD;
5790 element = Feld[newx][newy] = Store[x][y];
5792 #if USE_NEW_CUSTOM_VALUE
5793 InitField(newx, newy, FALSE);
5796 else if (element == EL_AMOEBA_DROPPING)
5798 Feld[x][y] = get_next_element(element);
5799 element = Feld[newx][newy] = Store[x][y];
5801 else if (element == EL_SOKOBAN_OBJECT)
5804 Feld[x][y] = Back[x][y];
5806 if (Back[newx][newy])
5807 Feld[newx][newy] = EL_SOKOBAN_FIELD_FULL;
5809 Back[x][y] = Back[newx][newy] = 0;
5812 Store[x][y] = EL_EMPTY;
5817 MovDelay[newx][newy] = 0;
5820 if (CAN_CHANGE_OR_HAS_ACTION(element))
5822 if (CAN_CHANGE(element))
5825 /* copy element change control values to new field */
5826 ChangeDelay[newx][newy] = ChangeDelay[x][y];
5827 ChangePage[newx][newy] = ChangePage[x][y];
5828 ChangeCount[newx][newy] = ChangeCount[x][y];
5829 ChangeEvent[newx][newy] = ChangeEvent[x][y];
5832 #if USE_NEW_CUSTOM_VALUE
5833 CustomValue[newx][newy] = CustomValue[x][y];
5839 #if USE_NEW_CUSTOM_VALUE
5840 CustomValue[newx][newy] = CustomValue[x][y];
5844 ChangeDelay[x][y] = 0;
5845 ChangePage[x][y] = -1;
5846 ChangeCount[x][y] = 0;
5847 ChangeEvent[x][y] = -1;
5849 #if USE_NEW_CUSTOM_VALUE
5850 CustomValue[x][y] = 0;
5853 /* copy animation control values to new field */
5854 GfxFrame[newx][newy] = GfxFrame[x][y];
5855 GfxRandom[newx][newy] = GfxRandom[x][y]; /* keep same random value */
5856 GfxAction[newx][newy] = GfxAction[x][y]; /* keep action one frame */
5857 GfxDir[newx][newy] = GfxDir[x][y]; /* keep element direction */
5859 Pushed[x][y] = Pushed[newx][newy] = FALSE;
5861 /* some elements can leave other elements behind after moving */
5862 if (IS_CUSTOM_ELEMENT(element) && ei->move_leave_element != EL_EMPTY &&
5863 (ei->move_leave_type == LEAVE_TYPE_UNLIMITED || stored != EL_EMPTY) &&
5864 (!IS_PLAYER(x, y) || IS_WALKABLE(ei->move_leave_element)))
5866 int move_leave_element = ei->move_leave_element;
5868 /* this makes it possible to leave the removed element again */
5869 if (ei->move_leave_type == LEAVE_TYPE_LIMITED &&
5870 ei->move_leave_element == EL_TRIGGER_ELEMENT)
5871 move_leave_element = stored;
5873 Feld[x][y] = move_leave_element;
5875 if (element_info[Feld[x][y]].move_direction_initial == MV_START_PREVIOUS)
5876 MovDir[x][y] = direction;
5878 InitField(x, y, FALSE);
5880 if (GFX_CRUMBLED(Feld[x][y]))
5881 DrawLevelFieldCrumbledSandNeighbours(x, y);
5883 if (ELEM_IS_PLAYER(move_leave_element))
5884 RelocatePlayer(x, y, move_leave_element);
5887 /* do this after checking for left-behind element */
5888 ResetGfxAnimation(x, y); /* reset animation values for old field */
5890 if (!CAN_MOVE(element) ||
5891 (CAN_FALL(element) && direction == MV_DOWN &&
5892 (element == EL_SPRING ||
5893 element_info[element].move_pattern == MV_WHEN_PUSHED ||
5894 element_info[element].move_pattern == MV_WHEN_DROPPED)))
5895 GfxDir[x][y] = MovDir[newx][newy] = 0;
5897 DrawLevelField(x, y);
5898 DrawLevelField(newx, newy);
5900 Stop[newx][newy] = TRUE; /* ignore this element until the next frame */
5902 /* prevent pushed element from moving on in pushed direction */
5903 if (pushed_by_player && CAN_MOVE(element) &&
5904 element_info[element].move_pattern & MV_ANY_DIRECTION &&
5905 !(element_info[element].move_pattern & direction))
5906 TurnRound(newx, newy);
5908 /* prevent elements on conveyor belt from moving on in last direction */
5909 if (pushed_by_conveyor && CAN_FALL(element) &&
5910 direction & MV_HORIZONTAL)
5911 MovDir[newx][newy] = 0;
5913 if (!pushed_by_player)
5915 int nextx = newx + dx, nexty = newy + dy;
5916 boolean check_collision_again = IN_LEV_FIELD_AND_IS_FREE(nextx, nexty);
5918 WasJustMoving[newx][newy] = 3;
5920 if (CAN_FALL(element) && direction == MV_DOWN)
5921 WasJustFalling[newx][newy] = 3;
5923 if ((!CAN_FALL(element) || direction == MV_DOWN) && check_collision_again)
5924 CheckCollision[newx][newy] = 2;
5927 if (DONT_TOUCH(element)) /* object may be nasty to player or others */
5929 TestIfBadThingTouchesPlayer(newx, newy);
5930 TestIfBadThingTouchesFriend(newx, newy);
5932 if (!IS_CUSTOM_ELEMENT(element))
5933 TestIfBadThingTouchesOtherBadThing(newx, newy);
5935 else if (element == EL_PENGUIN)
5936 TestIfFriendTouchesBadThing(newx, newy);
5938 /* give the player one last chance (one more frame) to move away */
5939 if (CAN_FALL(element) && direction == MV_DOWN &&
5940 (last_line || (!IS_FREE(x, newy + 1) &&
5941 (!IS_PLAYER(x, newy + 1) ||
5942 game.engine_version < VERSION_IDENT(3,1,1,0)))))
5945 if (pushed_by_player && !game.use_change_when_pushing_bug)
5947 int push_side = MV_DIR_OPPOSITE(direction);
5948 struct PlayerInfo *player = PLAYERINFO(x, y);
5950 CheckElementChangeByPlayer(newx, newy, element, CE_PUSHED_BY_PLAYER,
5951 player->index_bit, push_side);
5952 CheckTriggeredElementChangeByPlayer(newx,newy, element, CE_PLAYER_PUSHES_X,
5953 player->index_bit, push_side);
5956 CheckTriggeredElementChangeBySide(x, y, element, CE_MOVE_OF_X, direction);
5958 TestIfElementTouchesCustomElement(x, y); /* empty or new element */
5960 TestIfElementHitsCustomElement(newx, newy, direction);
5961 TestIfPlayerTouchesCustomElement(newx, newy);
5962 TestIfElementTouchesCustomElement(newx, newy);
5965 int AmoebeNachbarNr(int ax, int ay)
5968 int element = Feld[ax][ay];
5970 static int xy[4][2] =
5978 for (i = 0; i < NUM_DIRECTIONS; i++)
5980 int x = ax + xy[i][0];
5981 int y = ay + xy[i][1];
5983 if (!IN_LEV_FIELD(x, y))
5986 if (Feld[x][y] == element && AmoebaNr[x][y] > 0)
5987 group_nr = AmoebaNr[x][y];
5993 void AmoebenVereinigen(int ax, int ay)
5995 int i, x, y, xx, yy;
5996 int new_group_nr = AmoebaNr[ax][ay];
5997 static int xy[4][2] =
6005 if (new_group_nr == 0)
6008 for (i = 0; i < NUM_DIRECTIONS; i++)
6013 if (!IN_LEV_FIELD(x, y))
6016 if ((Feld[x][y] == EL_AMOEBA_FULL ||
6017 Feld[x][y] == EL_BD_AMOEBA ||
6018 Feld[x][y] == EL_AMOEBA_DEAD) &&
6019 AmoebaNr[x][y] != new_group_nr)
6021 int old_group_nr = AmoebaNr[x][y];
6023 if (old_group_nr == 0)
6026 AmoebaCnt[new_group_nr] += AmoebaCnt[old_group_nr];
6027 AmoebaCnt[old_group_nr] = 0;
6028 AmoebaCnt2[new_group_nr] += AmoebaCnt2[old_group_nr];
6029 AmoebaCnt2[old_group_nr] = 0;
6031 for (yy = 0; yy < lev_fieldy; yy++)
6033 for (xx = 0; xx < lev_fieldx; xx++)
6035 if (AmoebaNr[xx][yy] == old_group_nr)
6036 AmoebaNr[xx][yy] = new_group_nr;
6043 void AmoebeUmwandeln(int ax, int ay)
6047 if (Feld[ax][ay] == EL_AMOEBA_DEAD)
6049 int group_nr = AmoebaNr[ax][ay];
6054 printf("AmoebeUmwandeln(): ax = %d, ay = %d\n", ax, ay);
6055 printf("AmoebeUmwandeln(): This should never happen!\n");
6060 for (y = 0; y < lev_fieldy; y++)
6062 for (x = 0; x < lev_fieldx; x++)
6064 if (Feld[x][y] == EL_AMOEBA_DEAD && AmoebaNr[x][y] == group_nr)
6067 Feld[x][y] = EL_AMOEBA_TO_DIAMOND;
6071 PlayLevelSound(ax, ay, (IS_GEM(level.amoeba_content) ?
6072 SND_AMOEBA_TURNING_TO_GEM :
6073 SND_AMOEBA_TURNING_TO_ROCK));
6078 static int xy[4][2] =
6086 for (i = 0; i < NUM_DIRECTIONS; i++)
6091 if (!IN_LEV_FIELD(x, y))
6094 if (Feld[x][y] == EL_AMOEBA_TO_DIAMOND)
6096 PlayLevelSound(x, y, (IS_GEM(level.amoeba_content) ?
6097 SND_AMOEBA_TURNING_TO_GEM :
6098 SND_AMOEBA_TURNING_TO_ROCK));
6105 void AmoebeUmwandelnBD(int ax, int ay, int new_element)
6108 int group_nr = AmoebaNr[ax][ay];
6109 boolean done = FALSE;
6114 printf("AmoebeUmwandelnBD(): ax = %d, ay = %d\n", ax, ay);
6115 printf("AmoebeUmwandelnBD(): This should never happen!\n");
6120 for (y = 0; y < lev_fieldy; y++)
6122 for (x = 0; x < lev_fieldx; x++)
6124 if (AmoebaNr[x][y] == group_nr &&
6125 (Feld[x][y] == EL_AMOEBA_DEAD ||
6126 Feld[x][y] == EL_BD_AMOEBA ||
6127 Feld[x][y] == EL_AMOEBA_GROWING))
6130 Feld[x][y] = new_element;
6131 InitField(x, y, FALSE);
6132 DrawLevelField(x, y);
6139 PlayLevelSound(ax, ay, (new_element == EL_BD_ROCK ?
6140 SND_BD_AMOEBA_TURNING_TO_ROCK :
6141 SND_BD_AMOEBA_TURNING_TO_GEM));
6144 void AmoebeWaechst(int x, int y)
6146 static unsigned long sound_delay = 0;
6147 static unsigned long sound_delay_value = 0;
6149 if (!MovDelay[x][y]) /* start new growing cycle */
6153 if (DelayReached(&sound_delay, sound_delay_value))
6155 PlayLevelSoundElementAction(x, y, Store[x][y], ACTION_GROWING);
6156 sound_delay_value = 30;
6160 if (MovDelay[x][y]) /* wait some time before growing bigger */
6163 if (MovDelay[x][y]/2 && IN_SCR_FIELD(SCREENX(x), SCREENY(y)))
6165 int frame = getGraphicAnimationFrame(IMG_AMOEBA_GROWING,
6166 6 - MovDelay[x][y]);
6168 DrawGraphic(SCREENX(x), SCREENY(y), IMG_AMOEBA_GROWING, frame);
6171 if (!MovDelay[x][y])
6173 Feld[x][y] = Store[x][y];
6175 DrawLevelField(x, y);
6180 void AmoebaDisappearing(int x, int y)
6182 static unsigned long sound_delay = 0;
6183 static unsigned long sound_delay_value = 0;
6185 if (!MovDelay[x][y]) /* start new shrinking cycle */
6189 if (DelayReached(&sound_delay, sound_delay_value))
6190 sound_delay_value = 30;
6193 if (MovDelay[x][y]) /* wait some time before shrinking */
6196 if (MovDelay[x][y]/2 && IN_SCR_FIELD(SCREENX(x), SCREENY(y)))
6198 int frame = getGraphicAnimationFrame(IMG_AMOEBA_SHRINKING,
6199 6 - MovDelay[x][y]);
6201 DrawGraphic(SCREENX(x), SCREENY(y), IMG_AMOEBA_SHRINKING, frame);
6204 if (!MovDelay[x][y])
6206 Feld[x][y] = EL_EMPTY;
6207 DrawLevelField(x, y);
6209 /* don't let mole enter this field in this cycle;
6210 (give priority to objects falling to this field from above) */
6216 void AmoebeAbleger(int ax, int ay)
6219 int element = Feld[ax][ay];
6220 int graphic = el2img(element);
6221 int newax = ax, neway = ay;
6222 static int xy[4][2] =
6230 if (!level.amoeba_speed)
6232 Feld[ax][ay] = EL_AMOEBA_DEAD;
6233 DrawLevelField(ax, ay);
6237 if (IS_ANIMATED(graphic))
6238 DrawLevelGraphicAnimationIfNeeded(ax, ay, graphic);
6240 if (!MovDelay[ax][ay]) /* start making new amoeba field */
6241 MovDelay[ax][ay] = RND(FRAMES_PER_SECOND * 25 / (1 + level.amoeba_speed));
6243 if (MovDelay[ax][ay]) /* wait some time before making new amoeba */
6246 if (MovDelay[ax][ay])
6250 if (element == EL_AMOEBA_WET) /* object is an acid / amoeba drop */
6253 int x = ax + xy[start][0];
6254 int y = ay + xy[start][1];
6256 if (!IN_LEV_FIELD(x, y))
6259 if (IS_FREE(x, y) ||
6260 CAN_GROW_INTO(Feld[x][y]) ||
6261 Feld[x][y] == EL_QUICKSAND_EMPTY)
6267 if (newax == ax && neway == ay)
6270 else /* normal or "filled" (BD style) amoeba */
6273 boolean waiting_for_player = FALSE;
6275 for (i = 0; i < NUM_DIRECTIONS; i++)
6277 int j = (start + i) % 4;
6278 int x = ax + xy[j][0];
6279 int y = ay + xy[j][1];
6281 if (!IN_LEV_FIELD(x, y))
6284 if (IS_FREE(x, y) ||
6285 CAN_GROW_INTO(Feld[x][y]) ||
6286 Feld[x][y] == EL_QUICKSAND_EMPTY)
6292 else if (IS_PLAYER(x, y))
6293 waiting_for_player = TRUE;
6296 if (newax == ax && neway == ay) /* amoeba cannot grow */
6298 if (i == 4 && (!waiting_for_player || element == EL_BD_AMOEBA))
6300 Feld[ax][ay] = EL_AMOEBA_DEAD;
6301 DrawLevelField(ax, ay);
6302 AmoebaCnt[AmoebaNr[ax][ay]]--;
6304 if (AmoebaCnt[AmoebaNr[ax][ay]] <= 0) /* amoeba is completely dead */
6306 if (element == EL_AMOEBA_FULL)
6307 AmoebeUmwandeln(ax, ay);
6308 else if (element == EL_BD_AMOEBA)
6309 AmoebeUmwandelnBD(ax, ay, level.amoeba_content);
6314 else if (element == EL_AMOEBA_FULL || element == EL_BD_AMOEBA)
6316 /* amoeba gets larger by growing in some direction */
6318 int new_group_nr = AmoebaNr[ax][ay];
6321 if (new_group_nr == 0)
6323 printf("AmoebeAbleger(): newax = %d, neway = %d\n", newax, neway);
6324 printf("AmoebeAbleger(): This should never happen!\n");
6329 AmoebaNr[newax][neway] = new_group_nr;
6330 AmoebaCnt[new_group_nr]++;
6331 AmoebaCnt2[new_group_nr]++;
6333 /* if amoeba touches other amoeba(s) after growing, unify them */
6334 AmoebenVereinigen(newax, neway);
6336 if (element == EL_BD_AMOEBA && AmoebaCnt2[new_group_nr] >= 200)
6338 AmoebeUmwandelnBD(newax, neway, EL_BD_ROCK);
6344 if (element != EL_AMOEBA_WET || neway < ay || !IS_FREE(newax, neway) ||
6345 (neway == lev_fieldy - 1 && newax != ax))
6347 Feld[newax][neway] = EL_AMOEBA_GROWING; /* creation of new amoeba */
6348 Store[newax][neway] = element;
6350 else if (neway == ay)
6352 Feld[newax][neway] = EL_AMOEBA_DROP; /* drop left/right of amoeba */
6354 PlayLevelSoundAction(newax, neway, ACTION_GROWING);
6358 InitMovingField(ax, ay, MV_DOWN); /* drop dripping from amoeba */
6359 Feld[ax][ay] = EL_AMOEBA_DROPPING;
6360 Store[ax][ay] = EL_AMOEBA_DROP;
6361 ContinueMoving(ax, ay);
6365 DrawLevelField(newax, neway);
6368 void Life(int ax, int ay)
6372 static int life[4] = { 2, 3, 3, 3 }; /* parameters for "game of life" */
6375 int element = Feld[ax][ay];
6376 int graphic = el2img(element);
6377 int *life_parameter = (element == EL_GAME_OF_LIFE ? level.game_of_life :
6379 boolean changed = FALSE;
6381 if (IS_ANIMATED(graphic))
6382 DrawLevelGraphicAnimationIfNeeded(ax, ay, graphic);
6387 if (!MovDelay[ax][ay]) /* start new "game of life" cycle */
6388 MovDelay[ax][ay] = life_time;
6390 if (MovDelay[ax][ay]) /* wait some time before next cycle */
6393 if (MovDelay[ax][ay])
6397 for (y1 = -1; y1 < 2; y1++) for (x1 = -1; x1 < 2; x1++)
6399 int xx = ax+x1, yy = ay+y1;
6402 if (!IN_LEV_FIELD(xx, yy))
6405 for (y2 = -1; y2 < 2; y2++) for (x2 = -1; x2 < 2; x2++)
6407 int x = xx+x2, y = yy+y2;
6409 if (!IN_LEV_FIELD(x, y) || (x == xx && y == yy))
6412 if (((Feld[x][y] == element ||
6413 (element == EL_GAME_OF_LIFE && IS_PLAYER(x, y))) &&
6415 (IS_FREE(x, y) && Stop[x][y]))
6419 if (xx == ax && yy == ay) /* field in the middle */
6421 if (nachbarn < life_parameter[0] ||
6422 nachbarn > life_parameter[1])
6424 Feld[xx][yy] = EL_EMPTY;
6426 DrawLevelField(xx, yy);
6427 Stop[xx][yy] = TRUE;
6431 else if (IS_FREE(xx, yy) || CAN_GROW_INTO(Feld[xx][yy]))
6432 { /* free border field */
6433 if (nachbarn >= life_parameter[2] &&
6434 nachbarn <= life_parameter[3])
6436 Feld[xx][yy] = element;
6437 MovDelay[xx][yy] = (element == EL_GAME_OF_LIFE ? 0 : life_time-1);
6439 DrawLevelField(xx, yy);
6440 Stop[xx][yy] = TRUE;
6447 PlayLevelSound(ax, ay, element == EL_BIOMAZE ? SND_BIOMAZE_GROWING :
6448 SND_GAME_OF_LIFE_GROWING);
6451 static void InitRobotWheel(int x, int y)
6453 ChangeDelay[x][y] = level.time_wheel * FRAMES_PER_SECOND;
6456 static void RunRobotWheel(int x, int y)
6458 PlayLevelSound(x, y, SND_ROBOT_WHEEL_ACTIVE);
6461 static void StopRobotWheel(int x, int y)
6463 if (ZX == x && ZY == y)
6467 static void InitTimegateWheel(int x, int y)
6469 ChangeDelay[x][y] = level.time_timegate * FRAMES_PER_SECOND;
6472 static void RunTimegateWheel(int x, int y)
6474 PlayLevelSound(x, y, SND_TIMEGATE_SWITCH_ACTIVE);
6477 void CheckExit(int x, int y)
6479 if (local_player->gems_still_needed > 0 ||
6480 local_player->sokobanfields_still_needed > 0 ||
6481 local_player->lights_still_needed > 0)
6483 int element = Feld[x][y];
6484 int graphic = el2img(element);
6486 if (IS_ANIMATED(graphic))
6487 DrawLevelGraphicAnimationIfNeeded(x, y, graphic);
6492 if (AllPlayersGone) /* do not re-open exit door closed after last player */
6495 Feld[x][y] = EL_EXIT_OPENING;
6497 PlayLevelSoundNearest(x, y, SND_CLASS_EXIT_OPENING);
6500 void CheckExitSP(int x, int y)
6502 if (local_player->gems_still_needed > 0)
6504 int element = Feld[x][y];
6505 int graphic = el2img(element);
6507 if (IS_ANIMATED(graphic))
6508 DrawLevelGraphicAnimationIfNeeded(x, y, graphic);
6513 if (AllPlayersGone) /* do not re-open exit door closed after last player */
6516 Feld[x][y] = EL_SP_EXIT_OPENING;
6518 PlayLevelSoundNearest(x, y, SND_CLASS_SP_EXIT_OPENING);
6521 static void CloseAllOpenTimegates()
6525 for (y = 0; y < lev_fieldy; y++)
6527 for (x = 0; x < lev_fieldx; x++)
6529 int element = Feld[x][y];
6531 if (element == EL_TIMEGATE_OPEN || element == EL_TIMEGATE_OPENING)
6533 Feld[x][y] = EL_TIMEGATE_CLOSING;
6535 PlayLevelSoundAction(x, y, ACTION_CLOSING);
6541 void EdelsteinFunkeln(int x, int y)
6543 if (!IN_SCR_FIELD(SCREENX(x), SCREENY(y)) || IS_MOVING(x, y))
6546 if (Feld[x][y] == EL_BD_DIAMOND)
6549 if (MovDelay[x][y] == 0) /* next animation frame */
6550 MovDelay[x][y] = 11 * !SimpleRND(500);
6552 if (MovDelay[x][y] != 0) /* wait some time before next frame */
6556 if (setup.direct_draw && MovDelay[x][y])
6557 SetDrawtoField(DRAW_BUFFERED);
6559 DrawLevelElementAnimation(x, y, Feld[x][y]);
6561 if (MovDelay[x][y] != 0)
6563 int frame = getGraphicAnimationFrame(IMG_TWINKLE_WHITE,
6564 10 - MovDelay[x][y]);
6566 DrawGraphicThruMask(SCREENX(x), SCREENY(y), IMG_TWINKLE_WHITE, frame);
6568 if (setup.direct_draw)
6572 dest_x = FX + SCREENX(x) * TILEX;
6573 dest_y = FY + SCREENY(y) * TILEY;
6575 BlitBitmap(drawto_field, window,
6576 dest_x, dest_y, TILEX, TILEY, dest_x, dest_y);
6577 SetDrawtoField(DRAW_DIRECT);
6583 void MauerWaechst(int x, int y)
6587 if (!MovDelay[x][y]) /* next animation frame */
6588 MovDelay[x][y] = 3 * delay;
6590 if (MovDelay[x][y]) /* wait some time before next frame */
6594 if (IN_SCR_FIELD(SCREENX(x), SCREENY(y)))
6596 int graphic = el_dir2img(Feld[x][y], GfxDir[x][y]);
6597 int frame = getGraphicAnimationFrame(graphic, 17 - MovDelay[x][y]);
6599 DrawGraphic(SCREENX(x), SCREENY(y), graphic, frame);
6602 if (!MovDelay[x][y])
6604 if (MovDir[x][y] == MV_LEFT)
6606 if (IN_LEV_FIELD(x - 1, y) && IS_WALL(Feld[x - 1][y]))
6607 DrawLevelField(x - 1, y);
6609 else if (MovDir[x][y] == MV_RIGHT)
6611 if (IN_LEV_FIELD(x + 1, y) && IS_WALL(Feld[x + 1][y]))
6612 DrawLevelField(x + 1, y);
6614 else if (MovDir[x][y] == MV_UP)
6616 if (IN_LEV_FIELD(x, y - 1) && IS_WALL(Feld[x][y - 1]))
6617 DrawLevelField(x, y - 1);
6621 if (IN_LEV_FIELD(x, y + 1) && IS_WALL(Feld[x][y + 1]))
6622 DrawLevelField(x, y + 1);
6625 Feld[x][y] = Store[x][y];
6627 GfxDir[x][y] = MovDir[x][y] = MV_NONE;
6628 DrawLevelField(x, y);
6633 void MauerAbleger(int ax, int ay)
6635 int element = Feld[ax][ay];
6636 int graphic = el2img(element);
6637 boolean oben_frei = FALSE, unten_frei = FALSE;
6638 boolean links_frei = FALSE, rechts_frei = FALSE;
6639 boolean oben_massiv = FALSE, unten_massiv = FALSE;
6640 boolean links_massiv = FALSE, rechts_massiv = FALSE;
6641 boolean new_wall = FALSE;
6643 if (IS_ANIMATED(graphic))
6644 DrawLevelGraphicAnimationIfNeeded(ax, ay, graphic);
6646 if (!MovDelay[ax][ay]) /* start building new wall */
6647 MovDelay[ax][ay] = 6;
6649 if (MovDelay[ax][ay]) /* wait some time before building new wall */
6652 if (MovDelay[ax][ay])
6656 if (IN_LEV_FIELD(ax, ay-1) && IS_FREE(ax, ay-1))
6658 if (IN_LEV_FIELD(ax, ay+1) && IS_FREE(ax, ay+1))
6660 if (IN_LEV_FIELD(ax-1, ay) && IS_FREE(ax-1, ay))
6662 if (IN_LEV_FIELD(ax+1, ay) && IS_FREE(ax+1, ay))
6665 if (element == EL_EXPANDABLE_WALL_VERTICAL ||
6666 element == EL_EXPANDABLE_WALL_ANY)
6670 Feld[ax][ay-1] = EL_EXPANDABLE_WALL_GROWING;
6671 Store[ax][ay-1] = element;
6672 GfxDir[ax][ay-1] = MovDir[ax][ay-1] = MV_UP;
6673 if (IN_SCR_FIELD(SCREENX(ax), SCREENY(ay-1)))
6674 DrawGraphic(SCREENX(ax), SCREENY(ay - 1),
6675 IMG_EXPANDABLE_WALL_GROWING_UP, 0);
6680 Feld[ax][ay+1] = EL_EXPANDABLE_WALL_GROWING;
6681 Store[ax][ay+1] = element;
6682 GfxDir[ax][ay+1] = MovDir[ax][ay+1] = MV_DOWN;
6683 if (IN_SCR_FIELD(SCREENX(ax), SCREENY(ay+1)))
6684 DrawGraphic(SCREENX(ax), SCREENY(ay + 1),
6685 IMG_EXPANDABLE_WALL_GROWING_DOWN, 0);
6690 if (element == EL_EXPANDABLE_WALL_HORIZONTAL ||
6691 element == EL_EXPANDABLE_WALL_ANY ||
6692 element == EL_EXPANDABLE_WALL)
6696 Feld[ax-1][ay] = EL_EXPANDABLE_WALL_GROWING;
6697 Store[ax-1][ay] = element;
6698 GfxDir[ax-1][ay] = MovDir[ax-1][ay] = MV_LEFT;
6699 if (IN_SCR_FIELD(SCREENX(ax-1), SCREENY(ay)))
6700 DrawGraphic(SCREENX(ax - 1), SCREENY(ay),
6701 IMG_EXPANDABLE_WALL_GROWING_LEFT, 0);
6707 Feld[ax+1][ay] = EL_EXPANDABLE_WALL_GROWING;
6708 Store[ax+1][ay] = element;
6709 GfxDir[ax+1][ay] = MovDir[ax+1][ay] = MV_RIGHT;
6710 if (IN_SCR_FIELD(SCREENX(ax+1), SCREENY(ay)))
6711 DrawGraphic(SCREENX(ax + 1), SCREENY(ay),
6712 IMG_EXPANDABLE_WALL_GROWING_RIGHT, 0);
6717 if (element == EL_EXPANDABLE_WALL && (links_frei || rechts_frei))
6718 DrawLevelField(ax, ay);
6720 if (!IN_LEV_FIELD(ax, ay-1) || IS_WALL(Feld[ax][ay-1]))
6722 if (!IN_LEV_FIELD(ax, ay+1) || IS_WALL(Feld[ax][ay+1]))
6723 unten_massiv = TRUE;
6724 if (!IN_LEV_FIELD(ax-1, ay) || IS_WALL(Feld[ax-1][ay]))
6725 links_massiv = TRUE;
6726 if (!IN_LEV_FIELD(ax+1, ay) || IS_WALL(Feld[ax+1][ay]))
6727 rechts_massiv = TRUE;
6729 if (((oben_massiv && unten_massiv) ||
6730 element == EL_EXPANDABLE_WALL_HORIZONTAL ||
6731 element == EL_EXPANDABLE_WALL) &&
6732 ((links_massiv && rechts_massiv) ||
6733 element == EL_EXPANDABLE_WALL_VERTICAL))
6734 Feld[ax][ay] = EL_WALL;
6737 PlayLevelSoundAction(ax, ay, ACTION_GROWING);
6740 void CheckForDragon(int x, int y)
6743 boolean dragon_found = FALSE;
6744 static int xy[4][2] =
6752 for (i = 0; i < NUM_DIRECTIONS; i++)
6754 for (j = 0; j < 4; j++)
6756 int xx = x + j * xy[i][0], yy = y + j * xy[i][1];
6758 if (IN_LEV_FIELD(xx, yy) &&
6759 (Feld[xx][yy] == EL_FLAMES || Feld[xx][yy] == EL_DRAGON))
6761 if (Feld[xx][yy] == EL_DRAGON)
6762 dragon_found = TRUE;
6771 for (i = 0; i < NUM_DIRECTIONS; i++)
6773 for (j = 0; j < 3; j++)
6775 int xx = x + j * xy[i][0], yy = y + j * xy[i][1];
6777 if (IN_LEV_FIELD(xx, yy) && Feld[xx][yy] == EL_FLAMES)
6779 Feld[xx][yy] = EL_EMPTY;
6780 DrawLevelField(xx, yy);
6789 static void InitBuggyBase(int x, int y)
6791 int element = Feld[x][y];
6792 int activating_delay = FRAMES_PER_SECOND / 4;
6795 (element == EL_SP_BUGGY_BASE ?
6796 2 * FRAMES_PER_SECOND + RND(5 * FRAMES_PER_SECOND) - activating_delay :
6797 element == EL_SP_BUGGY_BASE_ACTIVATING ?
6799 element == EL_SP_BUGGY_BASE_ACTIVE ?
6800 1 * FRAMES_PER_SECOND + RND(1 * FRAMES_PER_SECOND) : 1);
6803 static void WarnBuggyBase(int x, int y)
6806 static int xy[4][2] =
6814 for (i = 0; i < NUM_DIRECTIONS; i++)
6816 int xx = x + xy[i][0], yy = y + xy[i][1];
6818 if (IS_PLAYER(xx, yy))
6820 PlayLevelSound(x, y, SND_SP_BUGGY_BASE_ACTIVE);
6827 static void InitTrap(int x, int y)
6829 ChangeDelay[x][y] = 2 * FRAMES_PER_SECOND + RND(5 * FRAMES_PER_SECOND);
6832 static void ActivateTrap(int x, int y)
6834 PlayLevelSound(x, y, SND_TRAP_ACTIVATING);
6837 static void ChangeActiveTrap(int x, int y)
6839 int graphic = IMG_TRAP_ACTIVE;
6841 /* if new animation frame was drawn, correct crumbled sand border */
6842 if (IS_NEW_FRAME(GfxFrame[x][y], graphic))
6843 DrawLevelFieldCrumbledSand(x, y);
6846 static int getSpecialActionElement(int element, int number, int base_element)
6848 return (element != EL_EMPTY ? element :
6849 number != -1 ? base_element + number - 1 :
6853 static int getModifiedActionNumber(int value_old, int operator, int operand,
6854 int value_min, int value_max)
6856 int value_new = (operator == CA_MODE_SET ? operand :
6857 operator == CA_MODE_ADD ? value_old + operand :
6858 operator == CA_MODE_SUBTRACT ? value_old - operand :
6859 operator == CA_MODE_MULTIPLY ? value_old * operand :
6860 operator == CA_MODE_DIVIDE ? value_old / MAX(1, operand) :
6861 operator == CA_MODE_MODULO ? value_old % MAX(1, operand) :
6864 return (value_new < value_min ? value_min :
6865 value_new > value_max ? value_max :
6869 static void ExecuteCustomElementAction(int x, int y, int element, int page)
6871 struct ElementInfo *ei = &element_info[element];
6872 struct ElementChangeInfo *change = &ei->change_page[page];
6873 int action_type = change->action_type;
6874 int action_mode = change->action_mode;
6875 int action_arg = change->action_arg;
6878 if (!change->has_action)
6881 /* ---------- determine action paramater values -------------------------- */
6883 int level_time_value =
6884 (level.time > 0 ? TimeLeft :
6887 int action_arg_element =
6888 (action_arg == CA_ARG_PLAYER_TRIGGER ? change->actual_trigger_player :
6889 action_arg == CA_ARG_ELEMENT_TRIGGER ? change->actual_trigger_element :
6890 action_arg == CA_ARG_ELEMENT_TARGET ? change->target_element :
6893 int action_arg_direction =
6894 (action_arg >= CA_ARG_DIRECTION_LEFT &&
6895 action_arg <= CA_ARG_DIRECTION_DOWN ? action_arg - CA_ARG_DIRECTION :
6896 action_arg == CA_ARG_DIRECTION_TRIGGER ?
6897 change->actual_trigger_side :
6898 action_arg == CA_ARG_DIRECTION_TRIGGER_BACK ?
6899 MV_DIR_OPPOSITE(change->actual_trigger_side) :
6902 int action_arg_number_min =
6903 (action_type == CA_SET_PLAYER_SPEED ? MOVE_STEPSIZE_MIN :
6906 int action_arg_number_max =
6907 (action_type == CA_SET_PLAYER_SPEED ? MOVE_STEPSIZE_MAX :
6908 action_type == CA_SET_LEVEL_GEMS ? 999 :
6909 action_type == CA_SET_LEVEL_TIME ? 9999 :
6910 action_type == CA_SET_LEVEL_SCORE ? 99999 :
6911 action_type == CA_SET_CE_SCORE ? 9999 :
6912 action_type == CA_SET_CE_VALUE ? 9999 :
6915 int action_arg_number_reset =
6916 (action_type == CA_SET_PLAYER_SPEED ? TILEX/game.initial_move_delay_value :
6917 action_type == CA_SET_LEVEL_GEMS ? level.gems_needed :
6918 action_type == CA_SET_LEVEL_TIME ? level.time :
6919 action_type == CA_SET_LEVEL_SCORE ? 0 :
6920 action_type == CA_SET_CE_SCORE ? 0 :
6922 action_type == CA_SET_CE_VALUE ? GET_NEW_CUSTOM_VALUE(element) :
6924 action_type == CA_SET_CE_VALUE ? ei->custom_value_initial :
6928 int action_arg_number =
6929 (action_arg <= CA_ARG_MAX ? action_arg :
6930 action_arg >= CA_ARG_SPEED_NOT_MOVING &&
6931 action_arg <= CA_ARG_SPEED_EVEN_FASTER ? (action_arg - CA_ARG_SPEED) :
6932 action_arg == CA_ARG_SPEED_RESET ? action_arg_number_reset :
6933 action_arg == CA_ARG_NUMBER_MIN ? action_arg_number_min :
6934 action_arg == CA_ARG_NUMBER_MAX ? action_arg_number_max :
6935 action_arg == CA_ARG_NUMBER_RESET ? action_arg_number_reset :
6936 action_arg == CA_ARG_NUMBER_CE_SCORE ? ei->collect_score :
6937 #if USE_NEW_CUSTOM_VALUE
6938 action_arg == CA_ARG_NUMBER_CE_VALUE ? CustomValue[x][y] :
6940 action_arg == CA_ARG_NUMBER_CE_VALUE ? ei->custom_value_initial :
6942 action_arg == CA_ARG_NUMBER_CE_DELAY ? GET_CE_DELAY_VALUE(change) :
6943 action_arg == CA_ARG_NUMBER_LEVEL_TIME ? level_time_value :
6944 action_arg == CA_ARG_NUMBER_LEVEL_GEMS ? local_player->gems_still_needed :
6945 action_arg == CA_ARG_NUMBER_LEVEL_SCORE ? local_player->score :
6946 action_arg == CA_ARG_ELEMENT_TARGET ? GET_NEW_CUSTOM_VALUE(change->target_element) :
6947 action_arg == CA_ARG_ELEMENT_TRIGGER ? change->actual_trigger_ce_value :
6950 int action_arg_number_old =
6951 (action_type == CA_SET_LEVEL_GEMS ? local_player->gems_still_needed :
6952 action_type == CA_SET_LEVEL_TIME ? TimeLeft :
6953 action_type == CA_SET_LEVEL_SCORE ? local_player->score :
6954 action_type == CA_SET_CE_SCORE ? ei->collect_score :
6955 action_type == CA_SET_CE_VALUE ? CustomValue[x][y] :
6958 int action_arg_number_new =
6959 getModifiedActionNumber(action_arg_number_old,
6960 action_mode, action_arg_number,
6961 action_arg_number_min, action_arg_number_max);
6963 int trigger_player_bits =
6964 (change->actual_trigger_player >= EL_PLAYER_1 &&
6965 change->actual_trigger_player <= EL_PLAYER_4 ?
6966 (1 << (change->actual_trigger_player - EL_PLAYER_1)) :
6969 int action_arg_player_bits =
6970 (action_arg >= CA_ARG_PLAYER_1 &&
6971 action_arg <= CA_ARG_PLAYER_4 ? action_arg - CA_ARG_PLAYER :
6972 action_arg == CA_ARG_PLAYER_TRIGGER ? trigger_player_bits :
6975 /* ---------- execute action -------------------------------------------- */
6984 /* ---------- level actions ------------------------------------------- */
6986 case CA_RESTART_LEVEL:
6988 game.restart_level = TRUE;
6993 case CA_SHOW_ENVELOPE:
6995 int element = getSpecialActionElement(action_arg_element,
6996 action_arg_number, EL_ENVELOPE_1);
6998 if (IS_ENVELOPE(element))
6999 local_player->show_envelope = element;
7004 case CA_SET_LEVEL_TIME:
7006 if (level.time > 0) /* only modify limited time value */
7008 TimeLeft = action_arg_number_new;
7010 DrawGameValue_Time(TimeLeft);
7012 if (!TimeLeft && setup.time_limit)
7013 for (i = 0; i < MAX_PLAYERS; i++)
7014 KillPlayer(&stored_player[i]);
7020 case CA_SET_LEVEL_SCORE:
7022 local_player->score = action_arg_number_new;
7024 DrawGameValue_Score(local_player->score);
7029 case CA_SET_LEVEL_GEMS:
7031 local_player->gems_still_needed = action_arg_number_new;
7033 DrawGameValue_Emeralds(local_player->gems_still_needed);
7038 case CA_SET_LEVEL_GRAVITY:
7040 game.gravity = (action_arg == CA_ARG_GRAVITY_OFF ? FALSE :
7041 action_arg == CA_ARG_GRAVITY_ON ? TRUE :
7042 action_arg == CA_ARG_GRAVITY_TOGGLE ? !game.gravity :
7047 case CA_SET_LEVEL_WIND:
7049 game.wind_direction = action_arg_direction;
7054 /* ---------- player actions ------------------------------------------ */
7056 case CA_MOVE_PLAYER:
7058 /* automatically move to the next field in specified direction */
7059 for (i = 0; i < MAX_PLAYERS; i++)
7060 if (trigger_player_bits & (1 << i))
7061 stored_player[i].programmed_action = action_arg_direction;
7066 case CA_EXIT_PLAYER:
7068 for (i = 0; i < MAX_PLAYERS; i++)
7069 if (action_arg_player_bits & (1 << i))
7070 stored_player[i].LevelSolved = stored_player[i].GameOver = TRUE;
7075 case CA_KILL_PLAYER:
7077 for (i = 0; i < MAX_PLAYERS; i++)
7078 if (action_arg_player_bits & (1 << i))
7079 KillPlayer(&stored_player[i]);
7084 case CA_SET_PLAYER_KEYS:
7086 int key_state = (action_mode == CA_MODE_ADD ? TRUE : FALSE);
7087 int element = getSpecialActionElement(action_arg_element,
7088 action_arg_number, EL_KEY_1);
7090 if (IS_KEY(element))
7092 for (i = 0; i < MAX_PLAYERS; i++)
7094 if (trigger_player_bits & (1 << i))
7096 stored_player[i].key[KEY_NR(element)] = key_state;
7098 DrawGameValue_Keys(stored_player[i].key);
7100 redraw_mask |= REDRAW_DOOR_1;
7108 case CA_SET_PLAYER_SPEED:
7110 for (i = 0; i < MAX_PLAYERS; i++)
7112 if (trigger_player_bits & (1 << i))
7114 int move_stepsize = TILEX / stored_player[i].move_delay_value;
7116 if (action_arg == CA_ARG_SPEED_SLOWER ||
7117 action_arg == CA_ARG_SPEED_FASTER)
7119 action_arg_number = 2;
7120 action_mode = (action_arg == CA_ARG_SPEED_SLOWER ? CA_MODE_DIVIDE :
7125 getModifiedActionNumber(move_stepsize,
7128 action_arg_number_min,
7129 action_arg_number_max);
7131 /* make sure that value is power of 2 */
7132 move_stepsize = (1 << log_2(move_stepsize));
7134 /* do no immediately change -- the player might just be moving */
7135 stored_player[i].move_delay_value_next = TILEX / move_stepsize;
7137 stored_player[i].cannot_move =
7138 (action_arg == CA_ARG_SPEED_NOT_MOVING ? TRUE : FALSE);
7145 case CA_SET_PLAYER_SHIELD:
7147 for (i = 0; i < MAX_PLAYERS; i++)
7149 if (trigger_player_bits & (1 << i))
7151 if (action_arg == CA_ARG_SHIELD_OFF)
7153 stored_player[i].shield_normal_time_left = 0;
7154 stored_player[i].shield_deadly_time_left = 0;
7156 else if (action_arg == CA_ARG_SHIELD_NORMAL)
7158 stored_player[i].shield_normal_time_left = 999999;
7160 else if (action_arg == CA_ARG_SHIELD_DEADLY)
7162 stored_player[i].shield_normal_time_left = 999999;
7163 stored_player[i].shield_deadly_time_left = 999999;
7171 case CA_SET_PLAYER_ARTWORK:
7173 for (i = 0; i < MAX_PLAYERS; i++)
7175 if (trigger_player_bits & (1 << i))
7177 int artwork_element = action_arg_element;
7179 if (action_arg == CA_ARG_ELEMENT_RESET)
7181 (level.use_artwork_element[i] ? level.artwork_element[i] :
7182 stored_player[i].element_nr);
7184 stored_player[i].artwork_element = artwork_element;
7186 SetPlayerWaiting(&stored_player[i], FALSE);
7188 /* set number of special actions for bored and sleeping animation */
7189 stored_player[i].num_special_action_bored =
7190 get_num_special_action(artwork_element,
7191 ACTION_BORING_1, ACTION_BORING_LAST);
7192 stored_player[i].num_special_action_sleeping =
7193 get_num_special_action(artwork_element,
7194 ACTION_SLEEPING_1, ACTION_SLEEPING_LAST);
7201 /* ---------- CE actions ---------------------------------------------- */
7203 case CA_SET_CE_SCORE:
7205 ei->collect_score = action_arg_number_new;
7210 case CA_SET_CE_VALUE:
7212 #if USE_NEW_CUSTOM_VALUE
7213 int last_custom_value = CustomValue[x][y];
7215 CustomValue[x][y] = action_arg_number_new;
7218 printf("::: Count == %d\n", CustomValue[x][y]);
7221 if (CustomValue[x][y] == 0 && last_custom_value > 0)
7224 printf("::: CE_VALUE_GETS_ZERO\n");
7227 CheckElementChange(x, y, element, EL_UNDEFINED, CE_VALUE_GETS_ZERO);
7228 CheckTriggeredElementChange(x, y, element, CE_VALUE_GETS_ZERO_OF_X);
7240 static void ChangeElementNowExt(struct ElementChangeInfo *change,
7241 int x, int y, int target_element)
7243 int previous_move_direction = MovDir[x][y];
7244 #if USE_NEW_CUSTOM_VALUE
7245 int last_ce_value = CustomValue[x][y];
7247 boolean add_player = (ELEM_IS_PLAYER(target_element) &&
7248 IS_WALKABLE(Feld[x][y]));
7250 /* check if element under player changes from accessible to unaccessible
7251 (needed for special case of dropping element which then changes) */
7252 if (IS_PLAYER(x, y) && !PLAYER_EXPLOSION_PROTECTED(x, y) &&
7253 IS_ACCESSIBLE(Feld[x][y]) && !IS_ACCESSIBLE(target_element))
7261 if (IS_MOVING(x, y) || IS_BLOCKED(x, y))
7262 RemoveMovingField(x, y);
7266 Feld[x][y] = target_element;
7268 ResetGfxAnimation(x, y);
7269 ResetRandomAnimationValue(x, y);
7271 if (element_info[Feld[x][y]].move_direction_initial == MV_START_PREVIOUS)
7272 MovDir[x][y] = previous_move_direction;
7274 #if USE_NEW_CUSTOM_VALUE
7275 if (element_info[Feld[x][y]].use_last_ce_value)
7276 CustomValue[x][y] = last_ce_value;
7279 InitField_WithBug1(x, y, FALSE);
7281 DrawLevelField(x, y);
7283 if (GFX_CRUMBLED(Feld[x][y]))
7284 DrawLevelFieldCrumbledSandNeighbours(x, y);
7287 /* "ChangeCount" not set yet to allow "entered by player" change one time */
7288 if (ELEM_IS_PLAYER(target_element))
7289 RelocatePlayer(x, y, target_element);
7291 ChangeCount[x][y]++; /* count number of changes in the same frame */
7293 TestIfBadThingTouchesPlayer(x, y);
7294 TestIfPlayerTouchesCustomElement(x, y);
7295 TestIfElementTouchesCustomElement(x, y);
7298 static boolean ChangeElementNow(int x, int y, int element, int page)
7300 struct ElementChangeInfo *change = &element_info[element].change_page[page];
7302 int old_element = Feld[x][y];
7304 /* always use default change event to prevent running into a loop */
7305 if (ChangeEvent[x][y] == -1)
7306 ChangeEvent[x][y] = CE_DELAY;
7308 if (ChangeEvent[x][y] == CE_DELAY)
7310 /* reset actual trigger element, trigger player and action element */
7311 change->actual_trigger_element = EL_EMPTY;
7312 change->actual_trigger_player = EL_PLAYER_1;
7313 change->actual_trigger_side = CH_SIDE_NONE;
7314 change->actual_trigger_ce_value = 0;
7317 /* do not change elements more than a specified maximum number of changes */
7318 if (ChangeCount[x][y] >= game.max_num_changes_per_frame)
7321 ChangeCount[x][y]++; /* count number of changes in the same frame */
7323 if (change->explode)
7330 if (change->use_target_content)
7332 boolean complete_replace = TRUE;
7333 boolean can_replace[3][3];
7336 for (yy = 0; yy < 3; yy++) for (xx = 0; xx < 3 ; xx++)
7339 boolean is_walkable;
7340 boolean is_diggable;
7341 boolean is_collectible;
7342 boolean is_removable;
7343 boolean is_destructible;
7344 int ex = x + xx - 1;
7345 int ey = y + yy - 1;
7346 int content_element = change->target_content.e[xx][yy];
7349 can_replace[xx][yy] = TRUE;
7351 if (ex == x && ey == y) /* do not check changing element itself */
7354 if (content_element == EL_EMPTY_SPACE)
7356 can_replace[xx][yy] = FALSE; /* do not replace border with space */
7361 if (!IN_LEV_FIELD(ex, ey))
7363 can_replace[xx][yy] = FALSE;
7364 complete_replace = FALSE;
7371 if (IS_MOVING(ex, ey) || IS_BLOCKED(ex, ey))
7372 e = MovingOrBlocked2Element(ex, ey);
7374 is_empty = (IS_FREE(ex, ey) ||
7375 (IS_FREE_OR_PLAYER(ex, ey) && IS_WALKABLE(content_element)));
7377 is_walkable = (is_empty || IS_WALKABLE(e));
7378 is_diggable = (is_empty || IS_DIGGABLE(e));
7379 is_collectible = (is_empty || IS_COLLECTIBLE(e));
7380 is_destructible = (is_empty || !IS_INDESTRUCTIBLE(e));
7381 is_removable = (is_diggable || is_collectible);
7383 can_replace[xx][yy] =
7384 (((change->replace_when == CP_WHEN_EMPTY && is_empty) ||
7385 (change->replace_when == CP_WHEN_WALKABLE && is_walkable) ||
7386 (change->replace_when == CP_WHEN_DIGGABLE && is_diggable) ||
7387 (change->replace_when == CP_WHEN_COLLECTIBLE && is_collectible) ||
7388 (change->replace_when == CP_WHEN_REMOVABLE && is_removable) ||
7389 (change->replace_when == CP_WHEN_DESTRUCTIBLE && is_destructible)) &&
7390 !(IS_PLAYER(ex, ey) && ELEM_IS_PLAYER(content_element)));
7392 if (!can_replace[xx][yy])
7393 complete_replace = FALSE;
7396 if (!change->only_if_complete || complete_replace)
7398 boolean something_has_changed = FALSE;
7400 if (change->only_if_complete && change->use_random_replace &&
7401 RND(100) < change->random_percentage)
7404 for (yy = 0; yy < 3; yy++) for (xx = 0; xx < 3 ; xx++)
7406 int ex = x + xx - 1;
7407 int ey = y + yy - 1;
7408 int content_element;
7410 if (can_replace[xx][yy] && (!change->use_random_replace ||
7411 RND(100) < change->random_percentage))
7413 if (IS_MOVING(ex, ey) || IS_BLOCKED(ex, ey))
7414 RemoveMovingField(ex, ey);
7416 ChangeEvent[ex][ey] = ChangeEvent[x][y];
7418 content_element = change->target_content.e[xx][yy];
7419 target_element = GET_TARGET_ELEMENT(content_element, change);
7421 ChangeElementNowExt(change, ex, ey, target_element);
7423 something_has_changed = TRUE;
7425 /* for symmetry reasons, freeze newly created border elements */
7426 if (ex != x || ey != y)
7427 Stop[ex][ey] = TRUE; /* no more moving in this frame */
7431 if (something_has_changed)
7433 PlayLevelSoundElementAction(x, y, element, ACTION_CHANGING);
7434 PlayLevelSoundElementAction(x, y, element, ACTION_PAGE_1 + page);
7440 target_element = GET_TARGET_ELEMENT(change->target_element, change);
7442 ChangeElementNowExt(change, x, y, target_element);
7444 PlayLevelSoundElementAction(x, y, element, ACTION_CHANGING);
7445 PlayLevelSoundElementAction(x, y, element, ACTION_PAGE_1 + page);
7448 /* this uses direct change before indirect change */
7449 CheckTriggeredElementChangeByPage(x, y, old_element, CE_CHANGE_OF_X, page);
7454 #if USE_NEW_DELAYED_ACTION
7456 static void ChangeElement(int x, int y, int page)
7458 int element = MovingOrBlocked2Element(x, y);
7459 struct ElementInfo *ei = &element_info[element];
7460 struct ElementChangeInfo *change = &ei->change_page[page];
7463 if (!CAN_CHANGE_OR_HAS_ACTION(element) &&
7464 !CAN_CHANGE_OR_HAS_ACTION(Back[x][y]))
7467 printf("ChangeElement(): %d,%d: element = %d ('%s')\n",
7468 x, y, element, element_info[element].token_name);
7469 printf("ChangeElement(): This should never happen!\n");
7474 /* this can happen with classic bombs on walkable, changing elements */
7475 if (!CAN_CHANGE_OR_HAS_ACTION(element))
7478 if (!CAN_CHANGE(Back[x][y])) /* prevent permanent repetition */
7479 ChangeDelay[x][y] = 0;
7485 if (ChangeDelay[x][y] == 0) /* initialize element change */
7487 ChangeDelay[x][y] = GET_CHANGE_DELAY(change) + 1;
7489 if (change->can_change)
7491 ResetGfxAnimation(x, y);
7492 ResetRandomAnimationValue(x, y);
7494 if (change->pre_change_function)
7495 change->pre_change_function(x, y);
7499 ChangeDelay[x][y]--;
7501 if (ChangeDelay[x][y] != 0) /* continue element change */
7503 if (change->can_change)
7505 int graphic = el_act_dir2img(element, GfxAction[x][y], GfxDir[x][y]);
7507 if (IS_ANIMATED(graphic))
7508 DrawLevelGraphicAnimationIfNeeded(x, y, graphic);
7510 if (change->change_function)
7511 change->change_function(x, y);
7514 else /* finish element change */
7516 if (ChangePage[x][y] != -1) /* remember page from delayed change */
7518 page = ChangePage[x][y];
7519 ChangePage[x][y] = -1;
7521 change = &ei->change_page[page];
7524 if (IS_MOVING(x, y)) /* never change a running system ;-) */
7526 ChangeDelay[x][y] = 1; /* try change after next move step */
7527 ChangePage[x][y] = page; /* remember page to use for change */
7532 if (change->can_change)
7534 if (ChangeElementNow(x, y, element, page))
7536 if (change->post_change_function)
7537 change->post_change_function(x, y);
7541 if (change->has_action)
7542 ExecuteCustomElementAction(x, y, element, page);
7548 static void ChangeElement(int x, int y, int page)
7550 int element = MovingOrBlocked2Element(x, y);
7551 struct ElementInfo *ei = &element_info[element];
7552 struct ElementChangeInfo *change = &ei->change_page[page];
7555 if (!CAN_CHANGE(element) && !CAN_CHANGE(Back[x][y]))
7558 printf("ChangeElement(): %d,%d: element = %d ('%s')\n",
7559 x, y, element, element_info[element].token_name);
7560 printf("ChangeElement(): This should never happen!\n");
7565 /* this can happen with classic bombs on walkable, changing elements */
7566 if (!CAN_CHANGE(element))
7569 if (!CAN_CHANGE(Back[x][y])) /* prevent permanent repetition */
7570 ChangeDelay[x][y] = 0;
7576 if (ChangeDelay[x][y] == 0) /* initialize element change */
7578 ChangeDelay[x][y] = GET_CHANGE_DELAY(change) + 1;
7580 ResetGfxAnimation(x, y);
7581 ResetRandomAnimationValue(x, y);
7583 if (change->pre_change_function)
7584 change->pre_change_function(x, y);
7587 ChangeDelay[x][y]--;
7589 if (ChangeDelay[x][y] != 0) /* continue element change */
7591 int graphic = el_act_dir2img(element, GfxAction[x][y], GfxDir[x][y]);
7593 if (IS_ANIMATED(graphic))
7594 DrawLevelGraphicAnimationIfNeeded(x, y, graphic);
7596 if (change->change_function)
7597 change->change_function(x, y);
7599 else /* finish element change */
7601 if (ChangePage[x][y] != -1) /* remember page from delayed change */
7603 page = ChangePage[x][y];
7604 ChangePage[x][y] = -1;
7606 change = &ei->change_page[page];
7609 if (IS_MOVING(x, y)) /* never change a running system ;-) */
7611 ChangeDelay[x][y] = 1; /* try change after next move step */
7612 ChangePage[x][y] = page; /* remember page to use for change */
7617 if (ChangeElementNow(x, y, element, page))
7619 if (change->post_change_function)
7620 change->post_change_function(x, y);
7627 static boolean CheckTriggeredElementChangeExt(int x, int y,
7628 int trigger_element,
7634 boolean change_done_any = FALSE;
7635 int trigger_page_bits = (trigger_page < 0 ? CH_PAGE_ANY : 1 << trigger_page);
7638 if (!(trigger_events[trigger_element][trigger_event]))
7641 for (i = 0; i < NUM_CUSTOM_ELEMENTS; i++)
7643 int element = EL_CUSTOM_START + i;
7644 boolean change_done = FALSE;
7647 if (!CAN_CHANGE_OR_HAS_ACTION(element) ||
7648 !HAS_ANY_CHANGE_EVENT(element, trigger_event))
7651 for (p = 0; p < element_info[element].num_change_pages; p++)
7653 struct ElementChangeInfo *change = &element_info[element].change_page[p];
7655 if (change->can_change_or_has_action &&
7656 change->has_event[trigger_event] &&
7657 change->trigger_side & trigger_side &&
7658 change->trigger_player & trigger_player &&
7659 change->trigger_page & trigger_page_bits &&
7660 IS_EQUAL_OR_IN_GROUP(trigger_element, change->trigger_element))
7662 change->actual_trigger_element = trigger_element;
7663 change->actual_trigger_player = EL_PLAYER_1 + log_2(trigger_player);
7664 change->actual_trigger_side = trigger_side;
7665 change->actual_trigger_ce_value = CustomValue[x][y];
7667 if ((change->can_change && !change_done) || change->has_action)
7671 for (y = 0; y < lev_fieldy; y++) for (x = 0; x < lev_fieldx; x++)
7673 if (Feld[x][y] == element)
7675 if (change->can_change && !change_done)
7677 ChangeDelay[x][y] = 1;
7678 ChangeEvent[x][y] = trigger_event;
7679 ChangeElement(x, y, p);
7681 #if USE_NEW_DELAYED_ACTION
7682 else if (change->has_action)
7684 ExecuteCustomElementAction(x, y, element, p);
7685 PlayLevelSoundElementAction(x, y, element, ACTION_PAGE_1 + p);
7688 if (change->has_action)
7690 ExecuteCustomElementAction(x, y, element, p);
7691 PlayLevelSoundElementAction(x, y, element, ACTION_PAGE_1 + p);
7697 if (change->can_change)
7700 change_done_any = TRUE;
7707 return change_done_any;
7710 static boolean CheckElementChangeExt(int x, int y,
7712 int trigger_element,
7717 boolean change_done = FALSE;
7720 if (!CAN_CHANGE_OR_HAS_ACTION(element) ||
7721 !HAS_ANY_CHANGE_EVENT(element, trigger_event))
7724 if (Feld[x][y] == EL_BLOCKED)
7726 Blocked2Moving(x, y, &x, &y);
7727 element = Feld[x][y];
7730 if (Feld[x][y] != element) /* check if element has already changed */
7733 for (p = 0; p < element_info[element].num_change_pages; p++)
7735 struct ElementChangeInfo *change = &element_info[element].change_page[p];
7737 boolean check_trigger_element =
7738 (trigger_event == CE_TOUCHING_X ||
7739 trigger_event == CE_HITTING_X ||
7740 trigger_event == CE_HIT_BY_X);
7742 if (change->can_change_or_has_action &&
7743 change->has_event[trigger_event] &&
7744 change->trigger_side & trigger_side &&
7745 change->trigger_player & trigger_player &&
7746 (!check_trigger_element ||
7747 IS_EQUAL_OR_IN_GROUP(trigger_element, change->trigger_element)))
7749 change->actual_trigger_element = trigger_element;
7750 change->actual_trigger_player = EL_PLAYER_1 + log_2(trigger_player);
7751 change->actual_trigger_side = trigger_side;
7752 change->actual_trigger_ce_value = CustomValue[x][y];
7754 /* special case: trigger element not at (x,y) position for some events */
7755 if (check_trigger_element)
7767 { 0, 0 }, { 0, 0 }, { 0, 0 },
7771 int xx = x + move_xy[MV_DIR_OPPOSITE(trigger_side)].dx;
7772 int yy = y + move_xy[MV_DIR_OPPOSITE(trigger_side)].dy;
7774 change->actual_trigger_ce_value = CustomValue[xx][yy];
7777 if (change->can_change && !change_done)
7779 ChangeDelay[x][y] = 1;
7780 ChangeEvent[x][y] = trigger_event;
7781 ChangeElement(x, y, p);
7785 #if USE_NEW_DELAYED_ACTION
7786 else if (change->has_action)
7788 ExecuteCustomElementAction(x, y, element, p);
7789 PlayLevelSoundElementAction(x, y, element, ACTION_PAGE_1 + p);
7792 if (change->has_action)
7794 ExecuteCustomElementAction(x, y, element, p);
7795 PlayLevelSoundElementAction(x, y, element, ACTION_PAGE_1 + p);
7804 static void PlayPlayerSound(struct PlayerInfo *player)
7806 int jx = player->jx, jy = player->jy;
7807 int sound_element = player->artwork_element;
7808 int last_action = player->last_action_waiting;
7809 int action = player->action_waiting;
7811 if (player->is_waiting)
7813 if (action != last_action)
7814 PlayLevelSoundElementAction(jx, jy, sound_element, action);
7816 PlayLevelSoundElementActionIfLoop(jx, jy, sound_element, action);
7820 if (action != last_action)
7821 StopSound(element_info[sound_element].sound[last_action]);
7823 if (last_action == ACTION_SLEEPING)
7824 PlayLevelSoundElementAction(jx, jy, sound_element, ACTION_AWAKENING);
7828 static void PlayAllPlayersSound()
7832 for (i = 0; i < MAX_PLAYERS; i++)
7833 if (stored_player[i].active)
7834 PlayPlayerSound(&stored_player[i]);
7837 static void SetPlayerWaiting(struct PlayerInfo *player, boolean is_waiting)
7839 boolean last_waiting = player->is_waiting;
7840 int move_dir = player->MovDir;
7842 player->last_action_waiting = player->action_waiting;
7846 if (!last_waiting) /* not waiting -> waiting */
7848 player->is_waiting = TRUE;
7850 player->frame_counter_bored =
7852 game.player_boring_delay_fixed +
7853 SimpleRND(game.player_boring_delay_random);
7854 player->frame_counter_sleeping =
7856 game.player_sleeping_delay_fixed +
7857 SimpleRND(game.player_sleeping_delay_random);
7859 InitPlayerGfxAnimation(player, ACTION_WAITING, player->MovDir);
7862 if (game.player_sleeping_delay_fixed +
7863 game.player_sleeping_delay_random > 0 &&
7864 player->anim_delay_counter == 0 &&
7865 player->post_delay_counter == 0 &&
7866 FrameCounter >= player->frame_counter_sleeping)
7867 player->is_sleeping = TRUE;
7868 else if (game.player_boring_delay_fixed +
7869 game.player_boring_delay_random > 0 &&
7870 FrameCounter >= player->frame_counter_bored)
7871 player->is_bored = TRUE;
7873 player->action_waiting = (player->is_sleeping ? ACTION_SLEEPING :
7874 player->is_bored ? ACTION_BORING :
7877 if (player->is_sleeping)
7879 if (player->num_special_action_sleeping > 0)
7881 if (player->anim_delay_counter == 0 && player->post_delay_counter == 0)
7883 int last_special_action = player->special_action_sleeping;
7884 int num_special_action = player->num_special_action_sleeping;
7885 int special_action =
7886 (last_special_action == ACTION_DEFAULT ? ACTION_SLEEPING_1 :
7887 last_special_action == ACTION_SLEEPING ? ACTION_SLEEPING :
7888 last_special_action < ACTION_SLEEPING_1 + num_special_action - 1 ?
7889 last_special_action + 1 : ACTION_SLEEPING);
7890 int special_graphic =
7891 el_act_dir2img(player->artwork_element, special_action, move_dir);
7893 player->anim_delay_counter =
7894 graphic_info[special_graphic].anim_delay_fixed +
7895 SimpleRND(graphic_info[special_graphic].anim_delay_random);
7896 player->post_delay_counter =
7897 graphic_info[special_graphic].post_delay_fixed +
7898 SimpleRND(graphic_info[special_graphic].post_delay_random);
7900 player->special_action_sleeping = special_action;
7903 if (player->anim_delay_counter > 0)
7905 player->action_waiting = player->special_action_sleeping;
7906 player->anim_delay_counter--;
7908 else if (player->post_delay_counter > 0)
7910 player->post_delay_counter--;
7914 else if (player->is_bored)
7916 if (player->num_special_action_bored > 0)
7918 if (player->anim_delay_counter == 0 && player->post_delay_counter == 0)
7920 int special_action =
7921 ACTION_BORING_1 + SimpleRND(player->num_special_action_bored);
7922 int special_graphic =
7923 el_act_dir2img(player->artwork_element, special_action, move_dir);
7925 player->anim_delay_counter =
7926 graphic_info[special_graphic].anim_delay_fixed +
7927 SimpleRND(graphic_info[special_graphic].anim_delay_random);
7928 player->post_delay_counter =
7929 graphic_info[special_graphic].post_delay_fixed +
7930 SimpleRND(graphic_info[special_graphic].post_delay_random);
7932 player->special_action_bored = special_action;
7935 if (player->anim_delay_counter > 0)
7937 player->action_waiting = player->special_action_bored;
7938 player->anim_delay_counter--;
7940 else if (player->post_delay_counter > 0)
7942 player->post_delay_counter--;
7947 else if (last_waiting) /* waiting -> not waiting */
7949 player->is_waiting = FALSE;
7950 player->is_bored = FALSE;
7951 player->is_sleeping = FALSE;
7953 player->frame_counter_bored = -1;
7954 player->frame_counter_sleeping = -1;
7956 player->anim_delay_counter = 0;
7957 player->post_delay_counter = 0;
7959 player->action_waiting = ACTION_DEFAULT;
7961 player->special_action_bored = ACTION_DEFAULT;
7962 player->special_action_sleeping = ACTION_DEFAULT;
7966 static byte PlayerActions(struct PlayerInfo *player, byte player_action)
7968 boolean moved = FALSE, snapped = FALSE, dropped = FALSE;
7969 int left = player_action & JOY_LEFT;
7970 int right = player_action & JOY_RIGHT;
7971 int up = player_action & JOY_UP;
7972 int down = player_action & JOY_DOWN;
7973 int button1 = player_action & JOY_BUTTON_1;
7974 int button2 = player_action & JOY_BUTTON_2;
7975 int dx = (left ? -1 : right ? 1 : 0);
7976 int dy = (up ? -1 : down ? 1 : 0);
7978 if (!player->active || tape.pausing)
7984 snapped = SnapField(player, dx, dy);
7988 dropped = DropElement(player);
7990 moved = MovePlayer(player, dx, dy);
7993 if (tape.single_step && tape.recording && !tape.pausing)
7995 if (button1 || (dropped && !moved))
7997 TapeTogglePause(TAPE_TOGGLE_AUTOMATIC);
7998 SnapField(player, 0, 0); /* stop snapping */
8002 SetPlayerWaiting(player, FALSE);
8004 return player_action;
8008 /* no actions for this player (no input at player's configured device) */
8010 DigField(player, 0, 0, 0, 0, 0, 0, DF_NO_PUSH);
8011 SnapField(player, 0, 0);
8012 CheckGravityMovementWhenNotMoving(player);
8014 if (player->MovPos == 0)
8015 SetPlayerWaiting(player, TRUE);
8017 if (player->MovPos == 0) /* needed for tape.playing */
8018 player->is_moving = FALSE;
8020 player->is_dropping = FALSE;
8026 void AdvanceFrameAndPlayerCounters(int player_nr)
8030 /* advance frame counters (global frame counter and time frame counter) */
8034 /* advance player counters (counters for move delay, move animation etc.) */
8035 for (i = 0; i < MAX_PLAYERS; i++)
8037 boolean advance_player_counters = (player_nr == -1 || player_nr == i);
8038 int move_delay_value = stored_player[i].move_delay_value;
8039 int move_frames = MOVE_DELAY_NORMAL_SPEED / move_delay_value;
8041 if (!advance_player_counters) /* not all players may be affected */
8044 #if USE_NEW_PLAYER_ANIM
8045 if (move_frames == 0) /* less than one move per game frame */
8047 int stepsize = TILEX / move_delay_value;
8048 int delay = move_delay_value / MOVE_DELAY_NORMAL_SPEED;
8049 int count = (stored_player[i].is_moving ?
8050 ABS(stored_player[i].MovPos) / stepsize : FrameCounter);
8052 if (count % delay == 0)
8057 stored_player[i].Frame += move_frames;
8059 if (stored_player[i].MovPos != 0)
8060 stored_player[i].StepFrame += move_frames;
8062 if (stored_player[i].move_delay > 0)
8063 stored_player[i].move_delay--;
8065 /* due to bugs in previous versions, counter must count up, not down */
8066 if (stored_player[i].push_delay != -1)
8067 stored_player[i].push_delay++;
8069 if (stored_player[i].drop_delay > 0)
8070 stored_player[i].drop_delay--;
8076 static unsigned long game_frame_delay = 0;
8077 unsigned long game_frame_delay_value;
8078 int magic_wall_x = 0, magic_wall_y = 0;
8079 int i, x, y, element, graphic;
8080 byte *recorded_player_action;
8081 byte summarized_player_action = 0;
8082 byte tape_action[MAX_PLAYERS];
8084 if (game_status != GAME_MODE_PLAYING)
8087 game_frame_delay_value =
8088 (tape.playing && tape.fast_forward ? FfwdFrameDelay : GameFrameDelay);
8090 if (tape.playing && tape.warp_forward && !tape.pausing)
8091 game_frame_delay_value = 0;
8093 /* ---------- main game synchronization point ---------- */
8095 WaitUntilDelayReached(&game_frame_delay, game_frame_delay_value);
8097 if (network_playing && !network_player_action_received)
8099 /* try to get network player actions in time */
8101 #if defined(NETWORK_AVALIABLE)
8102 /* last chance to get network player actions without main loop delay */
8106 /* game was quit by network peer */
8107 if (game_status != GAME_MODE_PLAYING)
8110 if (!network_player_action_received)
8111 return; /* failed to get network player actions in time */
8117 recorded_player_action = (tape.playing ? TapePlayAction() : NULL);
8120 /* !!! CHECK THIS (tape.pausing is always FALSE here!) !!! */
8121 if (recorded_player_action == NULL && tape.pausing)
8125 for (i = 0; i < MAX_PLAYERS; i++)
8127 summarized_player_action |= stored_player[i].action;
8129 if (!network_playing)
8130 stored_player[i].effective_action = stored_player[i].action;
8133 #if defined(NETWORK_AVALIABLE)
8134 if (network_playing)
8135 SendToServer_MovePlayer(summarized_player_action);
8138 if (!options.network && !setup.team_mode)
8139 local_player->effective_action = summarized_player_action;
8141 if (recorded_player_action != NULL)
8142 for (i = 0; i < MAX_PLAYERS; i++)
8143 stored_player[i].effective_action = recorded_player_action[i];
8145 for (i = 0; i < MAX_PLAYERS; i++)
8147 tape_action[i] = stored_player[i].effective_action;
8149 if (tape.recording && tape_action[i] && !tape.player_participates[i])
8150 tape.player_participates[i] = TRUE; /* player just appeared from CE */
8153 /* only save actions from input devices, but not programmed actions */
8155 TapeRecordAction(tape_action);
8157 for (i = 0; i < MAX_PLAYERS; i++)
8159 int actual_player_action = stored_player[i].effective_action;
8162 /* !!! THIS BREAKS THE FOLLOWING TAPES: !!!
8163 - rnd_equinox_tetrachloride 048
8164 - rnd_equinox_tetrachloride_ii 096
8165 - rnd_emanuel_schmieg 002
8166 - doctor_sloan_ww 001, 020
8168 if (stored_player[i].MovPos == 0)
8169 CheckGravityMovement(&stored_player[i]);
8172 /* overwrite programmed action with tape action */
8173 if (stored_player[i].programmed_action)
8174 actual_player_action = stored_player[i].programmed_action;
8177 PlayerActions(&stored_player[i], actual_player_action);
8179 tape_action[i] = PlayerActions(&stored_player[i], actual_player_action);
8181 if (tape.recording && tape_action[i] && !tape.player_participates[i])
8182 tape.player_participates[i] = TRUE; /* player just appeared from CE */
8185 ScrollPlayer(&stored_player[i], SCROLL_GO_ON);
8188 network_player_action_received = FALSE;
8190 ScrollScreen(NULL, SCROLL_GO_ON);
8192 /* for backwards compatibility, the following code emulates a fixed bug that
8193 occured when pushing elements (causing elements that just made their last
8194 pushing step to already (if possible) make their first falling step in the
8195 same game frame, which is bad); this code is also needed to use the famous
8196 "spring push bug" which is used in older levels and might be wanted to be
8197 used also in newer levels, but in this case the buggy pushing code is only
8198 affecting the "spring" element and no other elements */
8200 if (game.engine_version < VERSION_IDENT(2,2,0,7) || level.use_spring_bug)
8202 for (i = 0; i < MAX_PLAYERS; i++)
8204 struct PlayerInfo *player = &stored_player[i];
8208 if (player->active && player->is_pushing && player->is_moving &&
8210 (game.engine_version < VERSION_IDENT(2,2,0,7) ||
8211 Feld[x][y] == EL_SPRING))
8213 ContinueMoving(x, y);
8215 /* continue moving after pushing (this is actually a bug) */
8216 if (!IS_MOVING(x, y))
8224 for (y = 0; y < lev_fieldy; y++) for (x = 0; x < lev_fieldx; x++)
8226 ChangeCount[x][y] = 0;
8227 ChangeEvent[x][y] = -1;
8229 /* this must be handled before main playfield loop */
8230 if (Feld[x][y] == EL_PLAYER_IS_LEAVING)
8233 if (MovDelay[x][y] <= 0)
8237 #if USE_NEW_SNAP_DELAY
8238 if (Feld[x][y] == EL_ELEMENT_SNAPPING)
8241 if (MovDelay[x][y] <= 0)
8244 DrawLevelField(x, y);
8246 TestIfElementTouchesCustomElement(x, y); /* for empty space */
8252 if (ChangePage[x][y] != -1 && ChangeDelay[x][y] != 1)
8254 printf("GameActions(): x = %d, y = %d: ChangePage != -1\n", x, y);
8255 printf("GameActions(): This should never happen!\n");
8257 ChangePage[x][y] = -1;
8262 if (WasJustMoving[x][y] > 0)
8263 WasJustMoving[x][y]--;
8264 if (WasJustFalling[x][y] > 0)
8265 WasJustFalling[x][y]--;
8266 if (CheckCollision[x][y] > 0)
8267 CheckCollision[x][y]--;
8271 /* reset finished pushing action (not done in ContinueMoving() to allow
8272 continous pushing animation for elements with zero push delay) */
8273 if (GfxAction[x][y] == ACTION_PUSHING && !IS_MOVING(x, y))
8275 ResetGfxAnimation(x, y);
8276 DrawLevelField(x, y);
8280 if (IS_BLOCKED(x, y))
8284 Blocked2Moving(x, y, &oldx, &oldy);
8285 if (!IS_MOVING(oldx, oldy))
8287 printf("GameActions(): (BLOCKED => MOVING) context corrupted!\n");
8288 printf("GameActions(): BLOCKED: x = %d, y = %d\n", x, y);
8289 printf("GameActions(): !MOVING: oldx = %d, oldy = %d\n", oldx, oldy);
8290 printf("GameActions(): This should never happen!\n");
8296 for (y = 0; y < lev_fieldy; y++) for (x = 0; x < lev_fieldx; x++)
8298 element = Feld[x][y];
8299 graphic = el_act_dir2img(element, GfxAction[x][y], GfxDir[x][y]);
8301 if (graphic_info[graphic].anim_global_sync)
8302 GfxFrame[x][y] = FrameCounter;
8303 else if (ANIM_MODE(graphic) == ANIM_CE_VALUE)
8305 int old_gfx_frame = GfxFrame[x][y];
8307 GfxFrame[x][y] = CustomValue[x][y];
8310 if (GfxFrame[x][y] != old_gfx_frame)
8312 DrawLevelGraphicAnimation(x, y, graphic);
8314 else if (ANIM_MODE(graphic) == ANIM_CE_SCORE)
8316 int old_gfx_frame = GfxFrame[x][y];
8318 GfxFrame[x][y] = element_info[element].collect_score;
8321 if (GfxFrame[x][y] != old_gfx_frame)
8323 DrawLevelGraphicAnimation(x, y, graphic);
8326 if (ANIM_MODE(graphic) == ANIM_RANDOM &&
8327 IS_NEXT_FRAME(GfxFrame[x][y], graphic))
8328 ResetRandomAnimationValue(x, y);
8330 SetRandomAnimationValue(x, y);
8332 PlayLevelSoundActionIfLoop(x, y, GfxAction[x][y]);
8334 if (IS_INACTIVE(element))
8336 if (IS_ANIMATED(graphic))
8337 DrawLevelGraphicAnimationIfNeeded(x, y, graphic);
8342 /* this may take place after moving, so 'element' may have changed */
8343 if (IS_CHANGING(x, y) &&
8344 (game.engine_version < VERSION_IDENT(3,0,7,1) || !Stop[x][y]))
8346 int page = element_info[element].event_page_nr[CE_DELAY];
8348 ChangeElement(x, y, ChangePage[x][y] != -1 ? ChangePage[x][y] : page);
8352 printf("::: ChangeDelay == %d\n", ChangeDelay[x][y]);
8356 if (element == EL_CUSTOM_255)
8357 printf("::: ChangeDelay == %d\n", ChangeDelay[x][y]);
8361 ChangeElement(x, y, page);
8363 if (CAN_CHANGE(element))
8364 ChangeElement(x, y, page);
8366 if (HAS_ACTION(element))
8367 ExecuteCustomElementAction(x, y, element, page);
8372 element = Feld[x][y];
8373 graphic = el_act_dir2img(element, GfxAction[x][y], GfxDir[x][y]);
8376 if (!IS_MOVING(x, y) && (CAN_FALL(element) || CAN_MOVE(element)))
8380 element = Feld[x][y];
8381 graphic = el_act_dir2img(element, GfxAction[x][y], GfxDir[x][y]);
8383 if (IS_ANIMATED(graphic) &&
8386 DrawLevelGraphicAnimationIfNeeded(x, y, graphic);
8388 if (IS_GEM(element) || element == EL_SP_INFOTRON)
8389 EdelsteinFunkeln(x, y);
8391 else if ((element == EL_ACID ||
8392 element == EL_EXIT_OPEN ||
8393 element == EL_SP_EXIT_OPEN ||
8394 element == EL_SP_TERMINAL ||
8395 element == EL_SP_TERMINAL_ACTIVE ||
8396 element == EL_EXTRA_TIME ||
8397 element == EL_SHIELD_NORMAL ||
8398 element == EL_SHIELD_DEADLY) &&
8399 IS_ANIMATED(graphic))
8400 DrawLevelGraphicAnimationIfNeeded(x, y, graphic);
8401 else if (IS_MOVING(x, y))
8402 ContinueMoving(x, y);
8403 else if (IS_ACTIVE_BOMB(element))
8404 CheckDynamite(x, y);
8405 else if (element == EL_AMOEBA_GROWING)
8406 AmoebeWaechst(x, y);
8407 else if (element == EL_AMOEBA_SHRINKING)
8408 AmoebaDisappearing(x, y);
8410 #if !USE_NEW_AMOEBA_CODE
8411 else if (IS_AMOEBALIVE(element))
8412 AmoebeAbleger(x, y);
8415 else if (element == EL_GAME_OF_LIFE || element == EL_BIOMAZE)
8417 else if (element == EL_EXIT_CLOSED)
8419 else if (element == EL_SP_EXIT_CLOSED)
8421 else if (element == EL_EXPANDABLE_WALL_GROWING)
8423 else if (element == EL_EXPANDABLE_WALL ||
8424 element == EL_EXPANDABLE_WALL_HORIZONTAL ||
8425 element == EL_EXPANDABLE_WALL_VERTICAL ||
8426 element == EL_EXPANDABLE_WALL_ANY)
8428 else if (element == EL_FLAMES)
8429 CheckForDragon(x, y);
8430 else if (element == EL_EXPLOSION)
8431 ; /* drawing of correct explosion animation is handled separately */
8432 else if (element == EL_ELEMENT_SNAPPING)
8435 graphic = el_act_dir2img(GfxElement[x][y], GfxAction[x][y],GfxDir[x][y]);
8437 DrawLevelGraphicAnimationIfNeeded(x, y, graphic);
8440 else if (IS_ANIMATED(graphic) && !IS_CHANGING(x, y))
8441 DrawLevelGraphicAnimationIfNeeded(x, y, graphic);
8444 if (element == EL_CUSTOM_255 ||
8445 element == EL_CUSTOM_256)
8446 DrawLevelGraphicAnimation(x, y, graphic);
8449 if (IS_BELT_ACTIVE(element))
8450 PlayLevelSoundAction(x, y, ACTION_ACTIVE);
8452 if (game.magic_wall_active)
8454 int jx = local_player->jx, jy = local_player->jy;
8456 /* play the element sound at the position nearest to the player */
8457 if ((element == EL_MAGIC_WALL_FULL ||
8458 element == EL_MAGIC_WALL_ACTIVE ||
8459 element == EL_MAGIC_WALL_EMPTYING ||
8460 element == EL_BD_MAGIC_WALL_FULL ||
8461 element == EL_BD_MAGIC_WALL_ACTIVE ||
8462 element == EL_BD_MAGIC_WALL_EMPTYING) &&
8463 ABS(x-jx) + ABS(y-jy) < ABS(magic_wall_x-jx) + ABS(magic_wall_y-jy))
8471 #if USE_NEW_AMOEBA_CODE
8472 /* new experimental amoeba growth stuff */
8473 if (!(FrameCounter % 8))
8475 static unsigned long random = 1684108901;
8477 for (i = 0; i < level.amoeba_speed * 28 / 8; i++)
8479 x = RND(lev_fieldx);
8480 y = RND(lev_fieldy);
8481 element = Feld[x][y];
8483 if (!IS_PLAYER(x,y) &&
8484 (element == EL_EMPTY ||
8485 CAN_GROW_INTO(element) ||
8486 element == EL_QUICKSAND_EMPTY ||
8487 element == EL_ACID_SPLASH_LEFT ||
8488 element == EL_ACID_SPLASH_RIGHT))
8490 if ((IN_LEV_FIELD(x, y-1) && Feld[x][y-1] == EL_AMOEBA_WET) ||
8491 (IN_LEV_FIELD(x-1, y) && Feld[x-1][y] == EL_AMOEBA_WET) ||
8492 (IN_LEV_FIELD(x+1, y) && Feld[x+1][y] == EL_AMOEBA_WET) ||
8493 (IN_LEV_FIELD(x, y+1) && Feld[x][y+1] == EL_AMOEBA_WET))
8494 Feld[x][y] = EL_AMOEBA_DROP;
8497 random = random * 129 + 1;
8503 if (game.explosions_delayed)
8506 game.explosions_delayed = FALSE;
8508 for (y = 0; y < lev_fieldy; y++) for (x = 0; x < lev_fieldx; x++)
8510 element = Feld[x][y];
8512 if (ExplodeField[x][y])
8513 Explode(x, y, EX_PHASE_START, ExplodeField[x][y]);
8514 else if (element == EL_EXPLOSION)
8515 Explode(x, y, ExplodePhase[x][y], EX_TYPE_NORMAL);
8517 ExplodeField[x][y] = EX_TYPE_NONE;
8520 game.explosions_delayed = TRUE;
8523 if (game.magic_wall_active)
8525 if (!(game.magic_wall_time_left % 4))
8527 int element = Feld[magic_wall_x][magic_wall_y];
8529 if (element == EL_BD_MAGIC_WALL_FULL ||
8530 element == EL_BD_MAGIC_WALL_ACTIVE ||
8531 element == EL_BD_MAGIC_WALL_EMPTYING)
8532 PlayLevelSound(magic_wall_x, magic_wall_y, SND_BD_MAGIC_WALL_ACTIVE);
8534 PlayLevelSound(magic_wall_x, magic_wall_y, SND_MAGIC_WALL_ACTIVE);
8537 if (game.magic_wall_time_left > 0)
8539 game.magic_wall_time_left--;
8540 if (!game.magic_wall_time_left)
8542 for (y = 0; y < lev_fieldy; y++) for (x = 0; x < lev_fieldx; x++)
8544 element = Feld[x][y];
8546 if (element == EL_MAGIC_WALL_ACTIVE ||
8547 element == EL_MAGIC_WALL_FULL)
8549 Feld[x][y] = EL_MAGIC_WALL_DEAD;
8550 DrawLevelField(x, y);
8552 else if (element == EL_BD_MAGIC_WALL_ACTIVE ||
8553 element == EL_BD_MAGIC_WALL_FULL)
8555 Feld[x][y] = EL_BD_MAGIC_WALL_DEAD;
8556 DrawLevelField(x, y);
8560 game.magic_wall_active = FALSE;
8565 if (game.light_time_left > 0)
8567 game.light_time_left--;
8569 if (game.light_time_left == 0)
8570 RedrawAllLightSwitchesAndInvisibleElements();
8573 if (game.timegate_time_left > 0)
8575 game.timegate_time_left--;
8577 if (game.timegate_time_left == 0)
8578 CloseAllOpenTimegates();
8581 if (game.lenses_time_left > 0)
8583 game.lenses_time_left--;
8585 if (game.lenses_time_left == 0)
8586 RedrawAllInvisibleElementsForLenses();
8589 if (game.magnify_time_left > 0)
8591 game.magnify_time_left--;
8593 if (game.magnify_time_left == 0)
8594 RedrawAllInvisibleElementsForMagnifier();
8597 for (i = 0; i < MAX_PLAYERS; i++)
8599 struct PlayerInfo *player = &stored_player[i];
8601 if (SHIELD_ON(player))
8603 if (player->shield_deadly_time_left)
8604 PlayLevelSound(player->jx, player->jy, SND_SHIELD_DEADLY_ACTIVE);
8605 else if (player->shield_normal_time_left)
8606 PlayLevelSound(player->jx, player->jy, SND_SHIELD_NORMAL_ACTIVE);
8610 if (TimeFrames >= FRAMES_PER_SECOND)
8615 for (i = 0; i < MAX_PLAYERS; i++)
8617 struct PlayerInfo *player = &stored_player[i];
8619 if (SHIELD_ON(player))
8621 player->shield_normal_time_left--;
8623 if (player->shield_deadly_time_left > 0)
8624 player->shield_deadly_time_left--;
8628 if (!level.use_step_counter)
8636 if (TimeLeft <= 10 && setup.time_limit)
8637 PlaySoundStereo(SND_GAME_RUNNING_OUT_OF_TIME, SOUND_MIDDLE);
8639 DrawGameValue_Time(TimeLeft);
8641 if (!TimeLeft && setup.time_limit)
8642 for (i = 0; i < MAX_PLAYERS; i++)
8643 KillPlayer(&stored_player[i]);
8645 else if (level.time == 0 && !AllPlayersGone) /* level w/o time limit */
8646 DrawGameValue_Time(TimePlayed);
8649 if (tape.recording || tape.playing)
8650 DrawVideoDisplay(VIDEO_STATE_TIME_ON, TapeTime);
8654 PlayAllPlayersSound();
8656 if (options.debug) /* calculate frames per second */
8658 static unsigned long fps_counter = 0;
8659 static int fps_frames = 0;
8660 unsigned long fps_delay_ms = Counter() - fps_counter;
8664 if (fps_delay_ms >= 500) /* calculate fps every 0.5 seconds */
8666 global.frames_per_second = 1000 * (float)fps_frames / fps_delay_ms;
8669 fps_counter = Counter();
8672 redraw_mask |= REDRAW_FPS;
8675 AdvanceFrameAndPlayerCounters(-1); /* advance counters for all players */
8677 if (local_player->show_envelope != 0 && local_player->MovPos == 0)
8679 ShowEnvelope(local_player->show_envelope - EL_ENVELOPE_1);
8681 local_player->show_envelope = 0;
8684 /* use random number generator in every frame to make it less predictable */
8685 if (game.engine_version >= VERSION_IDENT(3,1,1,0))
8689 static boolean AllPlayersInSight(struct PlayerInfo *player, int x, int y)
8691 int min_x = x, min_y = y, max_x = x, max_y = y;
8694 for (i = 0; i < MAX_PLAYERS; i++)
8696 int jx = stored_player[i].jx, jy = stored_player[i].jy;
8698 if (!stored_player[i].active || &stored_player[i] == player)
8701 min_x = MIN(min_x, jx);
8702 min_y = MIN(min_y, jy);
8703 max_x = MAX(max_x, jx);
8704 max_y = MAX(max_y, jy);
8707 return (max_x - min_x < SCR_FIELDX && max_y - min_y < SCR_FIELDY);
8710 static boolean AllPlayersInVisibleScreen()
8714 for (i = 0; i < MAX_PLAYERS; i++)
8716 int jx = stored_player[i].jx, jy = stored_player[i].jy;
8718 if (!stored_player[i].active)
8721 if (!IN_VIS_FIELD(SCREENX(jx), SCREENY(jy)))
8728 void ScrollLevel(int dx, int dy)
8730 int softscroll_offset = (setup.soft_scrolling ? TILEX : 0);
8733 BlitBitmap(drawto_field, drawto_field,
8734 FX + TILEX * (dx == -1) - softscroll_offset,
8735 FY + TILEY * (dy == -1) - softscroll_offset,
8736 SXSIZE - TILEX * (dx!=0) + 2 * softscroll_offset,
8737 SYSIZE - TILEY * (dy!=0) + 2 * softscroll_offset,
8738 FX + TILEX * (dx == 1) - softscroll_offset,
8739 FY + TILEY * (dy == 1) - softscroll_offset);
8743 x = (dx == 1 ? BX1 : BX2);
8744 for (y = BY1; y <= BY2; y++)
8745 DrawScreenField(x, y);
8750 y = (dy == 1 ? BY1 : BY2);
8751 for (x = BX1; x <= BX2; x++)
8752 DrawScreenField(x, y);
8755 redraw_mask |= REDRAW_FIELD;
8758 static boolean canFallDown(struct PlayerInfo *player)
8760 int jx = player->jx, jy = player->jy;
8762 return (IN_LEV_FIELD(jx, jy + 1) &&
8763 (IS_FREE(jx, jy + 1) ||
8764 (Feld[jx][jy + 1] == EL_ACID && player->can_fall_into_acid)) &&
8765 IS_WALKABLE_FROM(Feld[jx][jy], MV_DOWN) &&
8766 !IS_WALKABLE_INSIDE(Feld[jx][jy]));
8769 static boolean canPassField(int x, int y, int move_dir)
8771 int opposite_dir = MV_DIR_OPPOSITE(move_dir);
8772 int dx = (move_dir & MV_LEFT ? -1 : move_dir & MV_RIGHT ? +1 : 0);
8773 int dy = (move_dir & MV_UP ? -1 : move_dir & MV_DOWN ? +1 : 0);
8776 int element = Feld[x][y];
8778 return (IS_PASSABLE_FROM(element, opposite_dir) &&
8779 !CAN_MOVE(element) &&
8780 IN_LEV_FIELD(nextx, nexty) && !IS_PLAYER(nextx, nexty) &&
8781 IS_WALKABLE_FROM(Feld[nextx][nexty], move_dir) &&
8782 (level.can_pass_to_walkable || IS_FREE(nextx, nexty)));
8785 static boolean canMoveToValidFieldWithGravity(int x, int y, int move_dir)
8787 int opposite_dir = MV_DIR_OPPOSITE(move_dir);
8788 int dx = (move_dir & MV_LEFT ? -1 : move_dir & MV_RIGHT ? +1 : 0);
8789 int dy = (move_dir & MV_UP ? -1 : move_dir & MV_DOWN ? +1 : 0);
8793 return (IN_LEV_FIELD(newx, newy) && !IS_FREE_OR_PLAYER(newx, newy) &&
8794 IS_GRAVITY_REACHABLE(Feld[newx][newy]) &&
8795 (IS_DIGGABLE(Feld[newx][newy]) ||
8796 IS_WALKABLE_FROM(Feld[newx][newy], opposite_dir) ||
8797 canPassField(newx, newy, move_dir)));
8800 static void CheckGravityMovement(struct PlayerInfo *player)
8802 if (game.gravity && !player->programmed_action)
8804 int move_dir_horizontal = player->effective_action & MV_HORIZONTAL;
8805 int move_dir_vertical = player->effective_action & MV_VERTICAL;
8806 boolean player_is_snapping = player->effective_action & JOY_BUTTON_1;
8807 int jx = player->jx, jy = player->jy;
8808 boolean player_is_moving_to_valid_field =
8809 (!player_is_snapping &&
8810 (canMoveToValidFieldWithGravity(jx, jy, move_dir_horizontal) ||
8811 canMoveToValidFieldWithGravity(jx, jy, move_dir_vertical)));
8812 boolean player_can_fall_down = canFallDown(player);
8814 if (player_can_fall_down &&
8815 !player_is_moving_to_valid_field)
8816 player->programmed_action = MV_DOWN;
8820 static void CheckGravityMovementWhenNotMoving(struct PlayerInfo *player)
8822 return CheckGravityMovement(player);
8824 if (game.gravity && !player->programmed_action)
8826 int jx = player->jx, jy = player->jy;
8827 boolean field_under_player_is_free =
8828 (IN_LEV_FIELD(jx, jy + 1) && IS_FREE(jx, jy + 1));
8829 boolean player_is_standing_on_valid_field =
8830 (IS_WALKABLE_INSIDE(Feld[jx][jy]) ||
8831 (IS_WALKABLE(Feld[jx][jy]) &&
8832 !(element_info[Feld[jx][jy]].access_direction & MV_DOWN)));
8834 if (field_under_player_is_free && !player_is_standing_on_valid_field)
8835 player->programmed_action = MV_DOWN;
8841 -----------------------------------------------------------------------------
8842 dx, dy: direction (non-diagonal) to try to move the player to
8843 real_dx, real_dy: direction as read from input device (can be diagonal)
8846 boolean MovePlayerOneStep(struct PlayerInfo *player,
8847 int dx, int dy, int real_dx, int real_dy)
8849 int jx = player->jx, jy = player->jy;
8850 int new_jx = jx + dx, new_jy = jy + dy;
8854 if (!player->active || (!dx && !dy))
8855 return MF_NO_ACTION;
8857 player->MovDir = (dx < 0 ? MV_LEFT :
8860 dy > 0 ? MV_DOWN : MV_NONE);
8862 if (!IN_LEV_FIELD(new_jx, new_jy))
8863 return MF_NO_ACTION;
8865 if (player->cannot_move)
8868 if (player->MovPos == 0)
8870 player->is_moving = FALSE;
8871 player->is_digging = FALSE;
8872 player->is_collecting = FALSE;
8873 player->is_snapping = FALSE;
8874 player->is_pushing = FALSE;
8877 DigField(player, 0, 0, 0, 0, 0, 0, DF_NO_PUSH);
8878 SnapField(player, 0, 0);
8881 return MF_NO_ACTION;
8884 if (!options.network && !AllPlayersInSight(player, new_jx, new_jy))
8885 return MF_NO_ACTION;
8887 element = MovingOrBlocked2ElementIfNotLeaving(new_jx, new_jy);
8889 if (DONT_RUN_INTO(element))
8891 if (element == EL_ACID && dx == 0 && dy == 1)
8893 SplashAcid(new_jx, new_jy);
8894 Feld[jx][jy] = EL_PLAYER_1;
8895 InitMovingField(jx, jy, MV_DOWN);
8896 Store[jx][jy] = EL_ACID;
8897 ContinueMoving(jx, jy);
8901 TestIfPlayerRunsIntoBadThing(jx, jy, player->MovDir);
8906 can_move = DigField(player, jx, jy, new_jx, new_jy, real_dx,real_dy, DF_DIG);
8907 if (can_move != MF_MOVING)
8910 /* check if DigField() has caused relocation of the player */
8911 if (player->jx != jx || player->jy != jy)
8912 return MF_NO_ACTION; /* <-- !!! CHECK THIS [-> MF_ACTION ?] !!! */
8914 StorePlayer[jx][jy] = 0;
8915 player->last_jx = jx;
8916 player->last_jy = jy;
8917 player->jx = new_jx;
8918 player->jy = new_jy;
8919 StorePlayer[new_jx][new_jy] = player->element_nr;
8921 if (player->move_delay_value_next != -1)
8923 player->move_delay_value = player->move_delay_value_next;
8924 player->move_delay_value_next = -1;
8928 (dx > 0 || dy > 0 ? -1 : 1) * (TILEX - TILEX / player->move_delay_value);
8930 player->step_counter++;
8932 PlayerVisit[jx][jy] = FrameCounter;
8934 ScrollPlayer(player, SCROLL_INIT);
8939 boolean MovePlayer(struct PlayerInfo *player, int dx, int dy)
8941 int jx = player->jx, jy = player->jy;
8942 int old_jx = jx, old_jy = jy;
8943 int moved = MF_NO_ACTION;
8945 if (!player->active)
8950 if (player->MovPos == 0)
8952 player->is_moving = FALSE;
8953 player->is_digging = FALSE;
8954 player->is_collecting = FALSE;
8955 player->is_snapping = FALSE;
8956 player->is_pushing = FALSE;
8962 if (player->move_delay > 0)
8965 player->move_delay = -1; /* set to "uninitialized" value */
8967 /* store if player is automatically moved to next field */
8968 player->is_auto_moving = (player->programmed_action != MV_NONE);
8970 /* remove the last programmed player action */
8971 player->programmed_action = 0;
8975 /* should only happen if pre-1.2 tape recordings are played */
8976 /* this is only for backward compatibility */
8978 int original_move_delay_value = player->move_delay_value;
8981 printf("THIS SHOULD ONLY HAPPEN WITH PRE-1.2 LEVEL TAPES. [%ld]\n",
8985 /* scroll remaining steps with finest movement resolution */
8986 player->move_delay_value = MOVE_DELAY_NORMAL_SPEED;
8988 while (player->MovPos)
8990 ScrollPlayer(player, SCROLL_GO_ON);
8991 ScrollScreen(NULL, SCROLL_GO_ON);
8993 AdvanceFrameAndPlayerCounters(player->index_nr);
8999 player->move_delay_value = original_move_delay_value;
9002 if (player->last_move_dir & MV_HORIZONTAL)
9004 if (!(moved |= MovePlayerOneStep(player, 0, dy, dx, dy)))
9005 moved |= MovePlayerOneStep(player, dx, 0, dx, dy);
9009 if (!(moved |= MovePlayerOneStep(player, dx, 0, dx, dy)))
9010 moved |= MovePlayerOneStep(player, 0, dy, dx, dy);
9016 if (moved & MF_MOVING && !ScreenMovPos &&
9017 (player == local_player || !options.network))
9019 int old_scroll_x = scroll_x, old_scroll_y = scroll_y;
9020 int offset = (setup.scroll_delay ? 3 : 0);
9022 if (!IN_VIS_FIELD(SCREENX(jx), SCREENY(jy)))
9024 /* actual player has left the screen -- scroll in that direction */
9025 if (jx != old_jx) /* player has moved horizontally */
9026 scroll_x += (jx - old_jx);
9027 else /* player has moved vertically */
9028 scroll_y += (jy - old_jy);
9032 if (jx != old_jx) /* player has moved horizontally */
9034 if ((player->MovDir == MV_LEFT && scroll_x > jx - MIDPOSX + offset) ||
9035 (player->MovDir == MV_RIGHT && scroll_x < jx - MIDPOSX - offset))
9036 scroll_x = jx-MIDPOSX + (scroll_x < jx-MIDPOSX ? -offset : +offset);
9038 /* don't scroll over playfield boundaries */
9039 if (scroll_x < SBX_Left || scroll_x > SBX_Right)
9040 scroll_x = (scroll_x < SBX_Left ? SBX_Left : SBX_Right);
9042 /* don't scroll more than one field at a time */
9043 scroll_x = old_scroll_x + SIGN(scroll_x - old_scroll_x);
9045 /* don't scroll against the player's moving direction */
9046 if ((player->MovDir == MV_LEFT && scroll_x > old_scroll_x) ||
9047 (player->MovDir == MV_RIGHT && scroll_x < old_scroll_x))
9048 scroll_x = old_scroll_x;
9050 else /* player has moved vertically */
9052 if ((player->MovDir == MV_UP && scroll_y > jy - MIDPOSY + offset) ||
9053 (player->MovDir == MV_DOWN && scroll_y < jy - MIDPOSY - offset))
9054 scroll_y = jy-MIDPOSY + (scroll_y < jy-MIDPOSY ? -offset : +offset);
9056 /* don't scroll over playfield boundaries */
9057 if (scroll_y < SBY_Upper || scroll_y > SBY_Lower)
9058 scroll_y = (scroll_y < SBY_Upper ? SBY_Upper : SBY_Lower);
9060 /* don't scroll more than one field at a time */
9061 scroll_y = old_scroll_y + SIGN(scroll_y - old_scroll_y);
9063 /* don't scroll against the player's moving direction */
9064 if ((player->MovDir == MV_UP && scroll_y > old_scroll_y) ||
9065 (player->MovDir == MV_DOWN && scroll_y < old_scroll_y))
9066 scroll_y = old_scroll_y;
9070 if (scroll_x != old_scroll_x || scroll_y != old_scroll_y)
9072 if (!options.network && !AllPlayersInVisibleScreen())
9074 scroll_x = old_scroll_x;
9075 scroll_y = old_scroll_y;
9079 ScrollScreen(player, SCROLL_INIT);
9080 ScrollLevel(old_scroll_x - scroll_x, old_scroll_y - scroll_y);
9085 player->StepFrame = 0;
9087 if (moved & MF_MOVING)
9089 if (old_jx != jx && old_jy == jy)
9090 player->MovDir = (old_jx < jx ? MV_RIGHT : MV_LEFT);
9091 else if (old_jx == jx && old_jy != jy)
9092 player->MovDir = (old_jy < jy ? MV_DOWN : MV_UP);
9094 DrawLevelField(jx, jy); /* for "crumbled sand" */
9096 player->last_move_dir = player->MovDir;
9097 player->is_moving = TRUE;
9098 player->is_snapping = FALSE;
9099 player->is_switching = FALSE;
9100 player->is_dropping = FALSE;
9104 CheckGravityMovementWhenNotMoving(player);
9106 player->is_moving = FALSE;
9108 /* at this point, the player is allowed to move, but cannot move right now
9109 (e.g. because of something blocking the way) -- ensure that the player
9110 is also allowed to move in the next frame (in old versions before 3.1.1,
9111 the player was forced to wait again for eight frames before next try) */
9113 if (game.engine_version >= VERSION_IDENT(3,1,1,0))
9114 player->move_delay = 0; /* allow direct movement in the next frame */
9117 if (player->move_delay == -1) /* not yet initialized by DigField() */
9118 player->move_delay = player->move_delay_value;
9120 if (game.engine_version < VERSION_IDENT(3,0,7,0))
9122 TestIfPlayerTouchesBadThing(jx, jy);
9123 TestIfPlayerTouchesCustomElement(jx, jy);
9126 if (!player->active)
9127 RemovePlayer(player);
9132 void ScrollPlayer(struct PlayerInfo *player, int mode)
9134 int jx = player->jx, jy = player->jy;
9135 int last_jx = player->last_jx, last_jy = player->last_jy;
9136 int move_stepsize = TILEX / player->move_delay_value;
9138 #if USE_NEW_PLAYER_SPEED
9139 if (!player->active)
9142 if (player->MovPos == 0 && mode == SCROLL_GO_ON) /* player not moving */
9145 if (!player->active || player->MovPos == 0)
9149 if (mode == SCROLL_INIT)
9151 player->actual_frame_counter = FrameCounter;
9152 player->GfxPos = move_stepsize * (player->MovPos / move_stepsize);
9154 if ((player->block_last_field || player->block_delay_adjustment > 0) &&
9155 Feld[last_jx][last_jy] == EL_EMPTY)
9157 int last_field_block_delay = 0; /* start with no blocking at all */
9158 int block_delay_adjustment = player->block_delay_adjustment;
9160 /* if player blocks last field, add delay for exactly one move */
9161 if (player->block_last_field)
9163 last_field_block_delay += player->move_delay_value;
9165 /* when blocking enabled, prevent moving up despite gravity */
9166 if (game.gravity && player->MovDir == MV_UP)
9167 block_delay_adjustment = -1;
9170 /* add block delay adjustment (also possible when not blocking) */
9171 last_field_block_delay += block_delay_adjustment;
9173 Feld[last_jx][last_jy] = EL_PLAYER_IS_LEAVING;
9174 MovDelay[last_jx][last_jy] = last_field_block_delay + 1;
9177 #if USE_NEW_PLAYER_SPEED
9178 if (player->MovPos != 0) /* player has not yet reached destination */
9184 else if (!FrameReached(&player->actual_frame_counter, 1))
9188 printf("::: player->MovPos: %d -> %d\n",
9190 player->MovPos + (player->MovPos > 0 ? -1 : 1) * move_stepsize);
9193 #if USE_NEW_PLAYER_SPEED
9194 if (player->MovPos != 0)
9196 player->MovPos += (player->MovPos > 0 ? -1 : 1) * move_stepsize;
9197 player->GfxPos = move_stepsize * (player->MovPos / move_stepsize);
9199 /* before DrawPlayer() to draw correct player graphic for this case */
9200 if (player->MovPos == 0)
9201 CheckGravityMovement(player);
9204 player->MovPos += (player->MovPos > 0 ? -1 : 1) * move_stepsize;
9205 player->GfxPos = move_stepsize * (player->MovPos / move_stepsize);
9207 /* before DrawPlayer() to draw correct player graphic for this case */
9208 if (player->MovPos == 0)
9209 CheckGravityMovement(player);
9212 if (player->MovPos == 0) /* player reached destination field */
9215 printf("::: player reached destination field\n");
9218 if (player->move_delay_reset_counter > 0)
9220 player->move_delay_reset_counter--;
9222 if (player->move_delay_reset_counter == 0)
9224 /* continue with normal speed after quickly moving through gate */
9225 HALVE_PLAYER_SPEED(player);
9227 /* be able to make the next move without delay */
9228 player->move_delay = 0;
9232 player->last_jx = jx;
9233 player->last_jy = jy;
9235 if (Feld[jx][jy] == EL_EXIT_OPEN ||
9236 Feld[jx][jy] == EL_SP_EXIT_OPEN ||
9237 Feld[jx][jy] == EL_SP_EXIT_OPENING) /* <-- special case */
9239 DrawPlayer(player); /* needed here only to cleanup last field */
9240 RemovePlayer(player);
9242 if (local_player->friends_still_needed == 0 ||
9243 IS_SP_ELEMENT(Feld[jx][jy]))
9244 player->LevelSolved = player->GameOver = TRUE;
9247 /* this breaks one level: "machine", level 000 */
9249 int move_direction = player->MovDir;
9250 int enter_side = MV_DIR_OPPOSITE(move_direction);
9251 int leave_side = move_direction;
9252 int old_jx = last_jx;
9253 int old_jy = last_jy;
9254 int old_element = Feld[old_jx][old_jy];
9255 int new_element = Feld[jx][jy];
9257 if (IS_CUSTOM_ELEMENT(old_element))
9258 CheckElementChangeByPlayer(old_jx, old_jy, old_element,
9260 player->index_bit, leave_side);
9262 CheckTriggeredElementChangeByPlayer(old_jx, old_jy, old_element,
9264 player->index_bit, leave_side);
9266 if (IS_CUSTOM_ELEMENT(new_element))
9267 CheckElementChangeByPlayer(jx, jy, new_element, CE_ENTERED_BY_PLAYER,
9268 player->index_bit, enter_side);
9270 CheckTriggeredElementChangeByPlayer(jx, jy, new_element,
9272 player->index_bit, enter_side);
9274 CheckTriggeredElementChangeBySide(jx, jy, player->element_nr,
9275 CE_MOVE_OF_X, move_direction);
9278 if (game.engine_version >= VERSION_IDENT(3,0,7,0))
9280 TestIfPlayerTouchesBadThing(jx, jy);
9281 TestIfPlayerTouchesCustomElement(jx, jy);
9283 /* needed because pushed element has not yet reached its destination,
9284 so it would trigger a change event at its previous field location */
9285 if (!player->is_pushing)
9286 TestIfElementTouchesCustomElement(jx, jy); /* for empty space */
9288 if (!player->active)
9289 RemovePlayer(player);
9292 if (level.use_step_counter)
9302 if (TimeLeft <= 10 && setup.time_limit)
9303 PlaySoundStereo(SND_GAME_RUNNING_OUT_OF_TIME, SOUND_MIDDLE);
9305 DrawGameValue_Time(TimeLeft);
9307 if (!TimeLeft && setup.time_limit)
9308 for (i = 0; i < MAX_PLAYERS; i++)
9309 KillPlayer(&stored_player[i]);
9311 else if (level.time == 0 && !AllPlayersGone) /* level w/o time limit */
9312 DrawGameValue_Time(TimePlayed);
9315 if (tape.single_step && tape.recording && !tape.pausing &&
9316 !player->programmed_action)
9317 TapeTogglePause(TAPE_TOGGLE_AUTOMATIC);
9321 void ScrollScreen(struct PlayerInfo *player, int mode)
9323 static unsigned long screen_frame_counter = 0;
9325 if (mode == SCROLL_INIT)
9327 /* set scrolling step size according to actual player's moving speed */
9328 ScrollStepSize = TILEX / player->move_delay_value;
9330 screen_frame_counter = FrameCounter;
9331 ScreenMovDir = player->MovDir;
9332 ScreenMovPos = player->MovPos;
9333 ScreenGfxPos = ScrollStepSize * (ScreenMovPos / ScrollStepSize);
9336 else if (!FrameReached(&screen_frame_counter, 1))
9341 ScreenMovPos += (ScreenMovPos > 0 ? -1 : 1) * ScrollStepSize;
9342 ScreenGfxPos = ScrollStepSize * (ScreenMovPos / ScrollStepSize);
9343 redraw_mask |= REDRAW_FIELD;
9346 ScreenMovDir = MV_NONE;
9349 void TestIfPlayerTouchesCustomElement(int x, int y)
9351 static int xy[4][2] =
9358 static int trigger_sides[4][2] =
9360 /* center side border side */
9361 { CH_SIDE_TOP, CH_SIDE_BOTTOM }, /* check top */
9362 { CH_SIDE_LEFT, CH_SIDE_RIGHT }, /* check left */
9363 { CH_SIDE_RIGHT, CH_SIDE_LEFT }, /* check right */
9364 { CH_SIDE_BOTTOM, CH_SIDE_TOP } /* check bottom */
9366 static int touch_dir[4] =
9373 int center_element = Feld[x][y]; /* should always be non-moving! */
9376 for (i = 0; i < NUM_DIRECTIONS; i++)
9378 int xx = x + xy[i][0];
9379 int yy = y + xy[i][1];
9380 int center_side = trigger_sides[i][0];
9381 int border_side = trigger_sides[i][1];
9384 if (!IN_LEV_FIELD(xx, yy))
9387 if (IS_PLAYER(x, y))
9389 struct PlayerInfo *player = PLAYERINFO(x, y);
9391 if (game.engine_version < VERSION_IDENT(3,0,7,0))
9392 border_element = Feld[xx][yy]; /* may be moving! */
9393 else if (!IS_MOVING(xx, yy) && !IS_BLOCKED(xx, yy))
9394 border_element = Feld[xx][yy];
9395 else if (MovDir[xx][yy] & touch_dir[i]) /* elements are touching */
9396 border_element = MovingOrBlocked2Element(xx, yy);
9398 continue; /* center and border element do not touch */
9400 CheckElementChangeByPlayer(xx, yy, border_element, CE_TOUCHED_BY_PLAYER,
9401 player->index_bit, border_side);
9402 CheckTriggeredElementChangeByPlayer(xx, yy, border_element,
9403 CE_PLAYER_TOUCHES_X,
9404 player->index_bit, border_side);
9406 else if (IS_PLAYER(xx, yy))
9408 struct PlayerInfo *player = PLAYERINFO(xx, yy);
9410 if (game.engine_version >= VERSION_IDENT(3,0,7,0))
9412 if (player->MovPos != 0 && !(player->MovDir & touch_dir[i]))
9413 continue; /* center and border element do not touch */
9416 CheckElementChangeByPlayer(x, y, center_element, CE_TOUCHED_BY_PLAYER,
9417 player->index_bit, center_side);
9418 CheckTriggeredElementChangeByPlayer(x, y, center_element,
9419 CE_PLAYER_TOUCHES_X,
9420 player->index_bit, center_side);
9426 void TestIfElementTouchesCustomElement(int x, int y)
9428 static int xy[4][2] =
9435 static int trigger_sides[4][2] =
9437 /* center side border side */
9438 { CH_SIDE_TOP, CH_SIDE_BOTTOM }, /* check top */
9439 { CH_SIDE_LEFT, CH_SIDE_RIGHT }, /* check left */
9440 { CH_SIDE_RIGHT, CH_SIDE_LEFT }, /* check right */
9441 { CH_SIDE_BOTTOM, CH_SIDE_TOP } /* check bottom */
9443 static int touch_dir[4] =
9450 boolean change_center_element = FALSE;
9451 int center_element = Feld[x][y]; /* should always be non-moving! */
9454 for (i = 0; i < NUM_DIRECTIONS; i++)
9456 int xx = x + xy[i][0];
9457 int yy = y + xy[i][1];
9458 int center_side = trigger_sides[i][0];
9459 int border_side = trigger_sides[i][1];
9462 if (!IN_LEV_FIELD(xx, yy))
9465 if (game.engine_version < VERSION_IDENT(3,0,7,0))
9466 border_element = Feld[xx][yy]; /* may be moving! */
9467 else if (!IS_MOVING(xx, yy) && !IS_BLOCKED(xx, yy))
9468 border_element = Feld[xx][yy];
9469 else if (MovDir[xx][yy] & touch_dir[i]) /* elements are touching */
9470 border_element = MovingOrBlocked2Element(xx, yy);
9472 continue; /* center and border element do not touch */
9474 /* check for change of center element (but change it only once) */
9475 if (!change_center_element)
9476 change_center_element =
9477 CheckElementChangeBySide(x, y, center_element, border_element,
9478 CE_TOUCHING_X, border_side);
9480 /* check for change of border element */
9481 CheckElementChangeBySide(xx, yy, border_element, center_element,
9482 CE_TOUCHING_X, center_side);
9486 void TestIfElementHitsCustomElement(int x, int y, int direction)
9488 int dx = (direction == MV_LEFT ? -1 : direction == MV_RIGHT ? +1 : 0);
9489 int dy = (direction == MV_UP ? -1 : direction == MV_DOWN ? +1 : 0);
9490 int hitx = x + dx, hity = y + dy;
9491 int hitting_element = Feld[x][y];
9492 int touched_element;
9494 if (IN_LEV_FIELD(hitx, hity) && IS_FREE(hitx, hity))
9497 touched_element = (IN_LEV_FIELD(hitx, hity) ?
9498 MovingOrBlocked2Element(hitx, hity) : EL_STEELWALL);
9500 if (IN_LEV_FIELD(hitx, hity))
9502 int opposite_direction = MV_DIR_OPPOSITE(direction);
9503 int hitting_side = direction;
9504 int touched_side = opposite_direction;
9505 boolean object_hit = (!IS_MOVING(hitx, hity) ||
9506 MovDir[hitx][hity] != direction ||
9507 ABS(MovPos[hitx][hity]) <= TILEY / 2);
9513 CheckElementChangeBySide(x, y, hitting_element, touched_element,
9514 CE_HITTING_X, touched_side);
9516 CheckElementChangeBySide(hitx, hity, touched_element,
9517 hitting_element, CE_HIT_BY_X, hitting_side);
9519 CheckElementChangeBySide(hitx, hity, touched_element, hitting_element,
9520 CE_HIT_BY_SOMETHING, opposite_direction);
9524 /* "hitting something" is also true when hitting the playfield border */
9525 CheckElementChangeBySide(x, y, hitting_element, touched_element,
9526 CE_HITTING_SOMETHING, direction);
9530 void TestIfElementSmashesCustomElement(int x, int y, int direction)
9532 int dx = (direction == MV_LEFT ? -1 : direction == MV_RIGHT ? +1 : 0);
9533 int dy = (direction == MV_UP ? -1 : direction == MV_DOWN ? +1 : 0);
9534 int hitx = x + dx, hity = y + dy;
9535 int hitting_element = Feld[x][y];
9536 int touched_element;
9538 boolean object_hit = (IN_LEV_FIELD(hitx, hity) &&
9539 !IS_FREE(hitx, hity) &&
9540 (!IS_MOVING(hitx, hity) ||
9541 MovDir[hitx][hity] != direction ||
9542 ABS(MovPos[hitx][hity]) <= TILEY / 2));
9545 if (IN_LEV_FIELD(hitx, hity) && IS_FREE(hitx, hity))
9549 if (IN_LEV_FIELD(hitx, hity) && !object_hit)
9553 touched_element = (IN_LEV_FIELD(hitx, hity) ?
9554 MovingOrBlocked2Element(hitx, hity) : EL_STEELWALL);
9556 CheckElementChangeBySide(x, y, hitting_element, touched_element,
9557 EP_CAN_SMASH_EVERYTHING, direction);
9559 if (IN_LEV_FIELD(hitx, hity))
9561 int opposite_direction = MV_DIR_OPPOSITE(direction);
9562 int hitting_side = direction;
9563 int touched_side = opposite_direction;
9565 int touched_element = MovingOrBlocked2Element(hitx, hity);
9568 boolean object_hit = (!IS_MOVING(hitx, hity) ||
9569 MovDir[hitx][hity] != direction ||
9570 ABS(MovPos[hitx][hity]) <= TILEY / 2);
9579 CheckElementChangeBySide(hitx, hity, touched_element, hitting_element,
9580 CE_SMASHED_BY_SOMETHING, opposite_direction);
9582 CheckElementChangeBySide(x, y, hitting_element, touched_element,
9583 CE_OTHER_IS_SMASHING, touched_side);
9585 CheckElementChangeBySide(hitx, hity, touched_element, hitting_element,
9586 CE_OTHER_GETS_SMASHED, hitting_side);
9592 void TestIfGoodThingHitsBadThing(int good_x, int good_y, int good_move_dir)
9594 int i, kill_x = -1, kill_y = -1;
9595 int bad_element = -1;
9596 static int test_xy[4][2] =
9603 static int test_dir[4] =
9611 for (i = 0; i < NUM_DIRECTIONS; i++)
9613 int test_x, test_y, test_move_dir, test_element;
9615 test_x = good_x + test_xy[i][0];
9616 test_y = good_y + test_xy[i][1];
9618 if (!IN_LEV_FIELD(test_x, test_y))
9622 (IS_MOVING(test_x, test_y) ? MovDir[test_x][test_y] : MV_NONE);
9624 test_element = MovingOrBlocked2ElementIfNotLeaving(test_x, test_y);
9626 /* 1st case: good thing is moving towards DONT_RUN_INTO style bad thing;
9627 2nd case: DONT_TOUCH style bad thing does not move away from good thing
9629 if ((DONT_RUN_INTO(test_element) && good_move_dir == test_dir[i]) ||
9630 (DONT_TOUCH(test_element) && test_move_dir != test_dir[i]))
9634 bad_element = test_element;
9640 if (kill_x != -1 || kill_y != -1)
9642 if (IS_PLAYER(good_x, good_y))
9644 struct PlayerInfo *player = PLAYERINFO(good_x, good_y);
9646 if (player->shield_deadly_time_left > 0 &&
9647 !IS_INDESTRUCTIBLE(bad_element))
9648 Bang(kill_x, kill_y);
9649 else if (!PLAYER_ENEMY_PROTECTED(good_x, good_y))
9653 Bang(good_x, good_y);
9657 void TestIfBadThingHitsGoodThing(int bad_x, int bad_y, int bad_move_dir)
9659 int i, kill_x = -1, kill_y = -1;
9660 int bad_element = Feld[bad_x][bad_y];
9661 static int test_xy[4][2] =
9668 static int touch_dir[4] =
9675 static int test_dir[4] =
9683 if (bad_element == EL_EXPLOSION) /* skip just exploding bad things */
9686 for (i = 0; i < NUM_DIRECTIONS; i++)
9688 int test_x, test_y, test_move_dir, test_element;
9690 test_x = bad_x + test_xy[i][0];
9691 test_y = bad_y + test_xy[i][1];
9692 if (!IN_LEV_FIELD(test_x, test_y))
9696 (IS_MOVING(test_x, test_y) ? MovDir[test_x][test_y] : MV_NONE);
9698 test_element = Feld[test_x][test_y];
9700 /* 1st case: good thing is moving towards DONT_RUN_INTO style bad thing;
9701 2nd case: DONT_TOUCH style bad thing does not move away from good thing
9703 if ((DONT_RUN_INTO(bad_element) && bad_move_dir == test_dir[i]) ||
9704 (DONT_TOUCH(bad_element) && test_move_dir != test_dir[i]))
9706 /* good thing is player or penguin that does not move away */
9707 if (IS_PLAYER(test_x, test_y))
9709 struct PlayerInfo *player = PLAYERINFO(test_x, test_y);
9711 if (bad_element == EL_ROBOT && player->is_moving)
9712 continue; /* robot does not kill player if he is moving */
9714 if (game.engine_version >= VERSION_IDENT(3,0,7,0))
9716 if (player->MovPos != 0 && !(player->MovDir & touch_dir[i]))
9717 continue; /* center and border element do not touch */
9724 else if (test_element == EL_PENGUIN)
9733 if (kill_x != -1 || kill_y != -1)
9735 if (IS_PLAYER(kill_x, kill_y))
9737 struct PlayerInfo *player = PLAYERINFO(kill_x, kill_y);
9739 if (player->shield_deadly_time_left > 0 &&
9740 !IS_INDESTRUCTIBLE(bad_element))
9742 else if (!PLAYER_ENEMY_PROTECTED(kill_x, kill_y))
9746 Bang(kill_x, kill_y);
9750 void TestIfPlayerTouchesBadThing(int x, int y)
9752 TestIfGoodThingHitsBadThing(x, y, MV_NONE);
9755 void TestIfPlayerRunsIntoBadThing(int x, int y, int move_dir)
9757 TestIfGoodThingHitsBadThing(x, y, move_dir);
9760 void TestIfBadThingTouchesPlayer(int x, int y)
9762 TestIfBadThingHitsGoodThing(x, y, MV_NONE);
9765 void TestIfBadThingRunsIntoPlayer(int x, int y, int move_dir)
9767 TestIfBadThingHitsGoodThing(x, y, move_dir);
9770 void TestIfFriendTouchesBadThing(int x, int y)
9772 TestIfGoodThingHitsBadThing(x, y, MV_NONE);
9775 void TestIfBadThingTouchesFriend(int x, int y)
9777 TestIfBadThingHitsGoodThing(x, y, MV_NONE);
9780 void TestIfBadThingTouchesOtherBadThing(int bad_x, int bad_y)
9782 int i, kill_x = bad_x, kill_y = bad_y;
9783 static int xy[4][2] =
9791 for (i = 0; i < NUM_DIRECTIONS; i++)
9795 x = bad_x + xy[i][0];
9796 y = bad_y + xy[i][1];
9797 if (!IN_LEV_FIELD(x, y))
9800 element = Feld[x][y];
9801 if (IS_AMOEBOID(element) || element == EL_GAME_OF_LIFE ||
9802 element == EL_AMOEBA_GROWING || element == EL_AMOEBA_DROP)
9810 if (kill_x != bad_x || kill_y != bad_y)
9814 void KillPlayer(struct PlayerInfo *player)
9816 int jx = player->jx, jy = player->jy;
9818 if (!player->active)
9821 /* remove accessible field at the player's position */
9822 Feld[jx][jy] = EL_EMPTY;
9824 /* deactivate shield (else Bang()/Explode() would not work right) */
9825 player->shield_normal_time_left = 0;
9826 player->shield_deadly_time_left = 0;
9832 static void KillPlayerUnlessEnemyProtected(int x, int y)
9834 if (!PLAYER_ENEMY_PROTECTED(x, y))
9835 KillPlayer(PLAYERINFO(x, y));
9838 static void KillPlayerUnlessExplosionProtected(int x, int y)
9840 if (!PLAYER_EXPLOSION_PROTECTED(x, y))
9841 KillPlayer(PLAYERINFO(x, y));
9844 void BuryPlayer(struct PlayerInfo *player)
9846 int jx = player->jx, jy = player->jy;
9848 if (!player->active)
9851 PlayLevelSoundElementAction(jx, jy, player->artwork_element, ACTION_DYING);
9852 PlayLevelSound(jx, jy, SND_GAME_LOSING);
9854 player->GameOver = TRUE;
9855 RemovePlayer(player);
9858 void RemovePlayer(struct PlayerInfo *player)
9860 int jx = player->jx, jy = player->jy;
9861 int i, found = FALSE;
9863 player->present = FALSE;
9864 player->active = FALSE;
9866 if (!ExplodeField[jx][jy])
9867 StorePlayer[jx][jy] = 0;
9869 if (player->is_moving)
9870 DrawLevelField(player->last_jx, player->last_jy);
9872 for (i = 0; i < MAX_PLAYERS; i++)
9873 if (stored_player[i].active)
9877 AllPlayersGone = TRUE;
9883 #if USE_NEW_SNAP_DELAY
9884 static void setFieldForSnapping(int x, int y, int element, int direction)
9886 struct ElementInfo *ei = &element_info[element];
9887 int direction_bit = MV_DIR_BIT(direction);
9888 int graphic_snapping = ei->direction_graphic[ACTION_SNAPPING][direction_bit];
9889 int action = (graphic_snapping != IMG_EMPTY_SPACE ? ACTION_SNAPPING :
9890 IS_DIGGABLE(element) ? ACTION_DIGGING : ACTION_COLLECTING);
9892 Feld[x][y] = EL_ELEMENT_SNAPPING;
9893 MovDelay[x][y] = MOVE_DELAY_NORMAL_SPEED + 1 - 1;
9895 ResetGfxAnimation(x, y);
9897 GfxElement[x][y] = element;
9898 GfxAction[x][y] = action;
9899 GfxDir[x][y] = direction;
9900 GfxFrame[x][y] = -1;
9905 =============================================================================
9906 checkDiagonalPushing()
9907 -----------------------------------------------------------------------------
9908 check if diagonal input device direction results in pushing of object
9909 (by checking if the alternative direction is walkable, diggable, ...)
9910 =============================================================================
9913 static boolean checkDiagonalPushing(struct PlayerInfo *player,
9914 int x, int y, int real_dx, int real_dy)
9916 int jx, jy, dx, dy, xx, yy;
9918 if (real_dx == 0 || real_dy == 0) /* no diagonal direction => push */
9921 /* diagonal direction: check alternative direction */
9926 xx = jx + (dx == 0 ? real_dx : 0);
9927 yy = jy + (dy == 0 ? real_dy : 0);
9929 return (!IN_LEV_FIELD(xx, yy) || IS_SOLID_FOR_PUSHING(Feld[xx][yy]));
9933 =============================================================================
9935 -----------------------------------------------------------------------------
9936 x, y: field next to player (non-diagonal) to try to dig to
9937 real_dx, real_dy: direction as read from input device (can be diagonal)
9938 =============================================================================
9941 int DigField(struct PlayerInfo *player,
9942 int oldx, int oldy, int x, int y,
9943 int real_dx, int real_dy, int mode)
9945 boolean is_player = (IS_PLAYER(oldx, oldy) || mode != DF_DIG);
9946 boolean player_was_pushing = player->is_pushing;
9947 int jx = oldx, jy = oldy;
9948 int dx = x - jx, dy = y - jy;
9949 int nextx = x + dx, nexty = y + dy;
9950 int move_direction = (dx == -1 ? MV_LEFT :
9951 dx == +1 ? MV_RIGHT :
9953 dy == +1 ? MV_DOWN : MV_NONE);
9954 int opposite_direction = MV_DIR_OPPOSITE(move_direction);
9955 int dig_side = MV_DIR_OPPOSITE(move_direction);
9956 int old_element = Feld[jx][jy];
9960 if (is_player) /* function can also be called by EL_PENGUIN */
9962 if (player->MovPos == 0)
9964 player->is_digging = FALSE;
9965 player->is_collecting = FALSE;
9968 if (player->MovPos == 0) /* last pushing move finished */
9969 player->is_pushing = FALSE;
9971 if (mode == DF_NO_PUSH) /* player just stopped pushing */
9973 player->is_switching = FALSE;
9974 player->push_delay = -1;
9976 return MF_NO_ACTION;
9980 if (IS_MOVING(x, y) || IS_PLAYER(x, y))
9981 return MF_NO_ACTION;
9983 if (IS_TUBE(Back[jx][jy]) && game.engine_version >= VERSION_IDENT(2,2,0,0))
9984 old_element = Back[jx][jy];
9986 /* in case of element dropped at player position, check background */
9987 else if (Back[jx][jy] != EL_EMPTY &&
9988 game.engine_version >= VERSION_IDENT(2,2,0,0))
9989 old_element = Back[jx][jy];
9991 if (IS_WALKABLE(old_element) && !ACCESS_FROM(old_element, move_direction))
9992 return MF_NO_ACTION; /* field has no opening in this direction */
9994 if (IS_PASSABLE(old_element) && !ACCESS_FROM(old_element,opposite_direction))
9995 return MF_NO_ACTION; /* field has no opening in this direction */
9997 element = Feld[x][y];
9998 #if USE_NEW_CUSTOM_VALUE
10001 collect_count = element_info[element].collect_count_initial;
10003 collect_count = CustomValue[x][y];
10007 collect_count = element_info[element].collect_count_initial;
10011 if (element != EL_BLOCKED &&
10012 CustomValue[x][y] != element_info[element].collect_count_initial)
10013 printf("::: %d: %d != %d\n",
10016 element_info[element].collect_count_initial);
10019 if (!is_player && !IS_COLLECTIBLE(element)) /* penguin cannot collect it */
10020 return MF_NO_ACTION;
10022 if (mode == DF_SNAP && !IS_SNAPPABLE(element) &&
10023 game.engine_version >= VERSION_IDENT(2,2,0,0))
10025 CheckElementChangeByPlayer(x, y, element, CE_SNAPPED_BY_PLAYER,
10026 player->index_bit, dig_side);
10027 CheckTriggeredElementChangeByPlayer(x, y, element, CE_PLAYER_SNAPS_X,
10028 player->index_bit, dig_side);
10030 if (Feld[x][y] != element) /* field changed by snapping */
10033 return MF_NO_ACTION;
10036 if (game.gravity && is_player && !player->is_auto_moving &&
10037 canFallDown(player) && move_direction != MV_DOWN &&
10038 !canMoveToValidFieldWithGravity(jx, jy, move_direction))
10039 return MF_NO_ACTION; /* player cannot walk here due to gravity */
10041 if (IS_WALKABLE(element) && ACCESS_FROM(element, opposite_direction))
10043 int sound_element = SND_ELEMENT(element);
10044 int sound_action = ACTION_WALKING;
10046 if (IS_RND_GATE(element))
10048 if (!player->key[RND_GATE_NR(element)])
10049 return MF_NO_ACTION;
10051 else if (IS_RND_GATE_GRAY(element))
10053 if (!player->key[RND_GATE_GRAY_NR(element)])
10054 return MF_NO_ACTION;
10056 else if (IS_RND_GATE_GRAY_ACTIVE(element))
10058 if (!player->key[RND_GATE_GRAY_ACTIVE_NR(element)])
10059 return MF_NO_ACTION;
10061 else if (element == EL_EXIT_OPEN ||
10062 element == EL_SP_EXIT_OPEN ||
10063 element == EL_SP_EXIT_OPENING)
10065 sound_action = ACTION_PASSING; /* player is passing exit */
10067 else if (element == EL_EMPTY)
10069 sound_action = ACTION_MOVING; /* nothing to walk on */
10072 /* play sound from background or player, whatever is available */
10073 if (element_info[sound_element].sound[sound_action] != SND_UNDEFINED)
10074 PlayLevelSoundElementAction(x, y, sound_element, sound_action);
10076 PlayLevelSoundElementAction(x, y, player->artwork_element, sound_action);
10078 else if (IS_PASSABLE(element) && canPassField(x, y, move_direction))
10080 if (!ACCESS_FROM(element, opposite_direction))
10081 return MF_NO_ACTION; /* field not accessible from this direction */
10083 if (CAN_MOVE(element)) /* only fixed elements can be passed! */
10084 return MF_NO_ACTION;
10086 if (IS_EM_GATE(element))
10088 if (!player->key[EM_GATE_NR(element)])
10089 return MF_NO_ACTION;
10091 else if (IS_EM_GATE_GRAY(element))
10093 if (!player->key[EM_GATE_GRAY_NR(element)])
10094 return MF_NO_ACTION;
10096 else if (IS_EM_GATE_GRAY_ACTIVE(element))
10098 if (!player->key[EM_GATE_GRAY_ACTIVE_NR(element)])
10099 return MF_NO_ACTION;
10101 else if (IS_SP_PORT(element))
10103 if (element == EL_SP_GRAVITY_PORT_LEFT ||
10104 element == EL_SP_GRAVITY_PORT_RIGHT ||
10105 element == EL_SP_GRAVITY_PORT_UP ||
10106 element == EL_SP_GRAVITY_PORT_DOWN)
10107 game.gravity = !game.gravity;
10108 else if (element == EL_SP_GRAVITY_ON_PORT_LEFT ||
10109 element == EL_SP_GRAVITY_ON_PORT_RIGHT ||
10110 element == EL_SP_GRAVITY_ON_PORT_UP ||
10111 element == EL_SP_GRAVITY_ON_PORT_DOWN)
10112 game.gravity = TRUE;
10113 else if (element == EL_SP_GRAVITY_OFF_PORT_LEFT ||
10114 element == EL_SP_GRAVITY_OFF_PORT_RIGHT ||
10115 element == EL_SP_GRAVITY_OFF_PORT_UP ||
10116 element == EL_SP_GRAVITY_OFF_PORT_DOWN)
10117 game.gravity = FALSE;
10120 /* automatically move to the next field with double speed */
10121 player->programmed_action = move_direction;
10123 if (player->move_delay_reset_counter == 0)
10125 player->move_delay_reset_counter = 2; /* two double speed steps */
10127 DOUBLE_PLAYER_SPEED(player);
10130 PlayLevelSoundAction(x, y, ACTION_PASSING);
10132 else if (IS_DIGGABLE(element))
10136 if (mode != DF_SNAP)
10138 GfxElement[x][y] = GFX_ELEMENT(element);
10139 player->is_digging = TRUE;
10142 PlayLevelSoundElementAction(x, y, element, ACTION_DIGGING);
10144 CheckTriggeredElementChangeByPlayer(x, y, element, CE_PLAYER_DIGS_X,
10145 player->index_bit, dig_side);
10147 if (mode == DF_SNAP)
10149 #if USE_NEW_SNAP_DELAY
10150 if (level.block_snap_field)
10151 setFieldForSnapping(x, y, element, move_direction);
10153 TestIfElementTouchesCustomElement(x, y); /* for empty space */
10155 TestIfElementTouchesCustomElement(x, y); /* for empty space */
10158 CheckTriggeredElementChangeByPlayer(x, y, element, CE_PLAYER_SNAPS_X,
10159 player->index_bit, dig_side);
10162 else if (IS_COLLECTIBLE(element))
10166 if (is_player && mode != DF_SNAP)
10168 GfxElement[x][y] = element;
10169 player->is_collecting = TRUE;
10172 if (element == EL_SPEED_PILL)
10174 player->move_delay_value = MOVE_DELAY_HIGH_SPEED;
10176 else if (element == EL_EXTRA_TIME && level.time > 0)
10178 TimeLeft += level.extra_time;
10179 DrawGameValue_Time(TimeLeft);
10181 else if (element == EL_SHIELD_NORMAL || element == EL_SHIELD_DEADLY)
10183 player->shield_normal_time_left += level.shield_normal_time;
10184 if (element == EL_SHIELD_DEADLY)
10185 player->shield_deadly_time_left += level.shield_deadly_time;
10187 else if (element == EL_DYNAMITE || element == EL_SP_DISK_RED)
10189 if (player->inventory_size < MAX_INVENTORY_SIZE)
10190 player->inventory_element[player->inventory_size++] = element;
10192 DrawGameValue_Dynamite(local_player->inventory_size);
10194 else if (element == EL_DYNABOMB_INCREASE_NUMBER)
10196 player->dynabomb_count++;
10197 player->dynabombs_left++;
10199 else if (element == EL_DYNABOMB_INCREASE_SIZE)
10201 player->dynabomb_size++;
10203 else if (element == EL_DYNABOMB_INCREASE_POWER)
10205 player->dynabomb_xl = TRUE;
10207 else if (IS_KEY(element))
10209 player->key[KEY_NR(element)] = TRUE;
10211 DrawGameValue_Keys(player->key);
10213 redraw_mask |= REDRAW_DOOR_1;
10215 else if (IS_ENVELOPE(element))
10217 player->show_envelope = element;
10219 else if (element == EL_EMC_LENSES)
10221 game.lenses_time_left = level.lenses_time * FRAMES_PER_SECOND;
10223 RedrawAllInvisibleElementsForLenses();
10225 else if (element == EL_EMC_MAGNIFIER)
10227 game.magnify_time_left = level.magnify_time * FRAMES_PER_SECOND;
10229 RedrawAllInvisibleElementsForMagnifier();
10231 else if (IS_DROPPABLE(element) ||
10232 IS_THROWABLE(element)) /* can be collected and dropped */
10236 if (collect_count == 0)
10237 player->inventory_infinite_element = element;
10239 for (i = 0; i < collect_count; i++)
10240 if (player->inventory_size < MAX_INVENTORY_SIZE)
10241 player->inventory_element[player->inventory_size++] = element;
10243 DrawGameValue_Dynamite(local_player->inventory_size);
10245 else if (collect_count > 0)
10247 local_player->gems_still_needed -= collect_count;
10248 if (local_player->gems_still_needed < 0)
10249 local_player->gems_still_needed = 0;
10251 DrawGameValue_Emeralds(local_player->gems_still_needed);
10254 RaiseScoreElement(element);
10255 PlayLevelSoundElementAction(x, y, element, ACTION_COLLECTING);
10258 CheckTriggeredElementChangeByPlayer(x, y, element, CE_PLAYER_COLLECTS_X,
10259 player->index_bit, dig_side);
10261 if (mode == DF_SNAP)
10263 #if USE_NEW_SNAP_DELAY
10264 if (level.block_snap_field)
10265 setFieldForSnapping(x, y, element, move_direction);
10267 TestIfElementTouchesCustomElement(x, y); /* for empty space */
10269 TestIfElementTouchesCustomElement(x, y); /* for empty space */
10272 CheckTriggeredElementChangeByPlayer(x, y, element, CE_PLAYER_SNAPS_X,
10273 player->index_bit, dig_side);
10276 else if (IS_PUSHABLE(element))
10278 if (mode == DF_SNAP && element != EL_BD_ROCK)
10279 return MF_NO_ACTION;
10281 if (CAN_FALL(element) && dy)
10282 return MF_NO_ACTION;
10284 if (CAN_FALL(element) && IN_LEV_FIELD(x, y + 1) && IS_FREE(x, y + 1) &&
10285 !(element == EL_SPRING && level.use_spring_bug))
10286 return MF_NO_ACTION;
10288 if (CAN_MOVE(element) && GET_MAX_MOVE_DELAY(element) == 0 &&
10289 ((move_direction & MV_VERTICAL &&
10290 ((element_info[element].move_pattern & MV_LEFT &&
10291 IN_LEV_FIELD(x - 1, y) && IS_FREE(x - 1, y)) ||
10292 (element_info[element].move_pattern & MV_RIGHT &&
10293 IN_LEV_FIELD(x + 1, y) && IS_FREE(x + 1, y)))) ||
10294 (move_direction & MV_HORIZONTAL &&
10295 ((element_info[element].move_pattern & MV_UP &&
10296 IN_LEV_FIELD(x, y - 1) && IS_FREE(x, y - 1)) ||
10297 (element_info[element].move_pattern & MV_DOWN &&
10298 IN_LEV_FIELD(x, y + 1) && IS_FREE(x, y + 1))))))
10299 return MF_NO_ACTION;
10301 /* do not push elements already moving away faster than player */
10302 if (CAN_MOVE(element) && MovDir[x][y] == move_direction &&
10303 ABS(getElementMoveStepsize(x, y)) > MOVE_STEPSIZE_NORMAL)
10304 return MF_NO_ACTION;
10306 if (game.engine_version >= VERSION_IDENT(3,1,0,0))
10308 if (player->push_delay_value == -1 || !player_was_pushing)
10309 player->push_delay_value = GET_NEW_PUSH_DELAY(element);
10311 else if (game.engine_version >= VERSION_IDENT(3,0,7,1))
10313 if (player->push_delay_value == -1)
10314 player->push_delay_value = GET_NEW_PUSH_DELAY(element);
10316 else if (game.engine_version >= VERSION_IDENT(2,2,0,7))
10318 if (!player->is_pushing)
10319 player->push_delay_value = GET_NEW_PUSH_DELAY(element);
10322 player->is_pushing = TRUE;
10324 if (!(IN_LEV_FIELD(nextx, nexty) &&
10325 (IS_FREE(nextx, nexty) ||
10326 (Feld[nextx][nexty] == EL_SOKOBAN_FIELD_EMPTY &&
10327 IS_SB_ELEMENT(element)))))
10328 return MF_NO_ACTION;
10330 if (!checkDiagonalPushing(player, x, y, real_dx, real_dy))
10331 return MF_NO_ACTION;
10333 if (player->push_delay == -1) /* new pushing; restart delay */
10334 player->push_delay = 0;
10336 if (player->push_delay < player->push_delay_value &&
10337 !(tape.playing && tape.file_version < FILE_VERSION_2_0) &&
10338 element != EL_SPRING && element != EL_BALLOON)
10340 /* make sure that there is no move delay before next try to push */
10341 if (game.engine_version >= VERSION_IDENT(3,0,7,1))
10342 player->move_delay = 0;
10344 return MF_NO_ACTION;
10347 if (IS_SB_ELEMENT(element))
10349 if (element == EL_SOKOBAN_FIELD_FULL)
10351 Back[x][y] = EL_SOKOBAN_FIELD_EMPTY;
10352 local_player->sokobanfields_still_needed++;
10355 if (Feld[nextx][nexty] == EL_SOKOBAN_FIELD_EMPTY)
10357 Back[nextx][nexty] = EL_SOKOBAN_FIELD_EMPTY;
10358 local_player->sokobanfields_still_needed--;
10361 Feld[x][y] = EL_SOKOBAN_OBJECT;
10363 if (Back[x][y] == Back[nextx][nexty])
10364 PlayLevelSoundAction(x, y, ACTION_PUSHING);
10365 else if (Back[x][y] != 0)
10366 PlayLevelSoundElementAction(x, y, EL_SOKOBAN_FIELD_FULL,
10369 PlayLevelSoundElementAction(nextx, nexty, EL_SOKOBAN_FIELD_EMPTY,
10372 if (local_player->sokobanfields_still_needed == 0 &&
10373 game.emulation == EMU_SOKOBAN)
10375 player->LevelSolved = player->GameOver = TRUE;
10376 PlayLevelSound(x, y, SND_GAME_SOKOBAN_SOLVING);
10380 PlayLevelSoundElementAction(x, y, element, ACTION_PUSHING);
10382 InitMovingField(x, y, move_direction);
10383 GfxAction[x][y] = ACTION_PUSHING;
10385 if (mode == DF_SNAP)
10386 ContinueMoving(x, y);
10388 MovPos[x][y] = (dx != 0 ? dx : dy);
10390 Pushed[x][y] = TRUE;
10391 Pushed[nextx][nexty] = TRUE;
10393 if (game.engine_version < VERSION_IDENT(2,2,0,7))
10394 player->push_delay_value = GET_NEW_PUSH_DELAY(element);
10396 player->push_delay_value = -1; /* get new value later */
10398 /* check for element change _after_ element has been pushed */
10399 if (game.use_change_when_pushing_bug)
10401 CheckElementChangeByPlayer(x, y, element, CE_PUSHED_BY_PLAYER,
10402 player->index_bit, dig_side);
10403 CheckTriggeredElementChangeByPlayer(x, y, element, CE_PLAYER_PUSHES_X,
10404 player->index_bit, dig_side);
10407 else if (IS_SWITCHABLE(element))
10409 if (PLAYER_SWITCHING(player, x, y))
10411 CheckTriggeredElementChangeByPlayer(x, y, element, CE_PLAYER_PRESSES_X,
10412 player->index_bit, dig_side);
10417 player->is_switching = TRUE;
10418 player->switch_x = x;
10419 player->switch_y = y;
10421 PlayLevelSoundElementAction(x, y, element, ACTION_ACTIVATING);
10423 if (element == EL_ROBOT_WHEEL)
10425 Feld[x][y] = EL_ROBOT_WHEEL_ACTIVE;
10429 DrawLevelField(x, y);
10431 else if (element == EL_SP_TERMINAL)
10435 for (yy = 0; yy < lev_fieldy; yy++) for (xx=0; xx < lev_fieldx; xx++)
10437 if (Feld[xx][yy] == EL_SP_DISK_YELLOW)
10439 else if (Feld[xx][yy] == EL_SP_TERMINAL)
10440 Feld[xx][yy] = EL_SP_TERMINAL_ACTIVE;
10443 else if (IS_BELT_SWITCH(element))
10445 ToggleBeltSwitch(x, y);
10447 else if (element == EL_SWITCHGATE_SWITCH_UP ||
10448 element == EL_SWITCHGATE_SWITCH_DOWN)
10450 ToggleSwitchgateSwitch(x, y);
10452 else if (element == EL_LIGHT_SWITCH ||
10453 element == EL_LIGHT_SWITCH_ACTIVE)
10455 ToggleLightSwitch(x, y);
10457 else if (element == EL_TIMEGATE_SWITCH)
10459 ActivateTimegateSwitch(x, y);
10461 else if (element == EL_BALLOON_SWITCH_LEFT ||
10462 element == EL_BALLOON_SWITCH_RIGHT ||
10463 element == EL_BALLOON_SWITCH_UP ||
10464 element == EL_BALLOON_SWITCH_DOWN ||
10465 element == EL_BALLOON_SWITCH_NONE ||
10466 element == EL_BALLOON_SWITCH_ANY)
10468 game.wind_direction = (element == EL_BALLOON_SWITCH_LEFT ? MV_LEFT :
10469 element == EL_BALLOON_SWITCH_RIGHT ? MV_RIGHT :
10470 element == EL_BALLOON_SWITCH_UP ? MV_UP :
10471 element == EL_BALLOON_SWITCH_DOWN ? MV_DOWN :
10472 element == EL_BALLOON_SWITCH_NONE ? MV_NONE :
10475 else if (element == EL_LAMP)
10477 Feld[x][y] = EL_LAMP_ACTIVE;
10478 local_player->lights_still_needed--;
10480 ResetGfxAnimation(x, y);
10481 DrawLevelField(x, y);
10483 else if (element == EL_TIME_ORB_FULL)
10485 Feld[x][y] = EL_TIME_ORB_EMPTY;
10487 if (level.time > 0 || level.use_time_orb_bug)
10489 TimeLeft += level.time_orb_time;
10490 DrawGameValue_Time(TimeLeft);
10493 ResetGfxAnimation(x, y);
10494 DrawLevelField(x, y);
10497 CheckTriggeredElementChangeByPlayer(x, y, element, CE_SWITCH_OF_X,
10498 player->index_bit, dig_side);
10500 CheckTriggeredElementChangeByPlayer(x, y, element, CE_PLAYER_SWITCHES_X,
10501 player->index_bit, dig_side);
10503 CheckTriggeredElementChangeByPlayer(x, y, element, CE_PLAYER_PRESSES_X,
10504 player->index_bit, dig_side);
10510 if (!PLAYER_SWITCHING(player, x, y))
10512 player->is_switching = TRUE;
10513 player->switch_x = x;
10514 player->switch_y = y;
10516 CheckElementChangeByPlayer(x, y, element, CE_SWITCHED,
10517 player->index_bit, dig_side);
10518 CheckTriggeredElementChangeByPlayer(x, y, element, CE_SWITCH_OF_X,
10519 player->index_bit, dig_side);
10521 CheckElementChangeByPlayer(x, y, element, CE_SWITCHED_BY_PLAYER,
10522 player->index_bit, dig_side);
10523 CheckTriggeredElementChangeByPlayer(x, y, element, CE_PLAYER_SWITCHES_X,
10524 player->index_bit, dig_side);
10527 CheckElementChangeByPlayer(x, y, element, CE_PRESSED_BY_PLAYER,
10528 player->index_bit, dig_side);
10529 CheckTriggeredElementChangeByPlayer(x, y, element, CE_PLAYER_PRESSES_X,
10530 player->index_bit, dig_side);
10532 return MF_NO_ACTION;
10535 player->push_delay = -1;
10537 if (is_player) /* function can also be called by EL_PENGUIN */
10539 if (Feld[x][y] != element) /* really digged/collected something */
10540 player->is_collecting = !player->is_digging;
10546 boolean SnapField(struct PlayerInfo *player, int dx, int dy)
10548 int jx = player->jx, jy = player->jy;
10549 int x = jx + dx, y = jy + dy;
10550 int snap_direction = (dx == -1 ? MV_LEFT :
10551 dx == +1 ? MV_RIGHT :
10553 dy == +1 ? MV_DOWN : MV_NONE);
10555 if (player->MovPos != 0 && game.engine_version >= VERSION_IDENT(2,2,0,0))
10558 if (!player->active || !IN_LEV_FIELD(x, y))
10566 if (player->MovPos == 0)
10567 player->is_pushing = FALSE;
10569 player->is_snapping = FALSE;
10571 if (player->MovPos == 0)
10573 player->is_moving = FALSE;
10574 player->is_digging = FALSE;
10575 player->is_collecting = FALSE;
10581 if (player->is_snapping)
10584 player->MovDir = snap_direction;
10586 if (player->MovPos == 0)
10588 player->is_moving = FALSE;
10589 player->is_digging = FALSE;
10590 player->is_collecting = FALSE;
10593 player->is_dropping = FALSE;
10595 if (DigField(player, jx, jy, x, y, 0, 0, DF_SNAP) == MF_NO_ACTION)
10598 player->is_snapping = TRUE;
10600 if (player->MovPos == 0)
10602 player->is_moving = FALSE;
10603 player->is_digging = FALSE;
10604 player->is_collecting = FALSE;
10607 if (player->MovPos != 0) /* prevent graphic bugs in versions < 2.2.0 */
10608 DrawLevelField(player->last_jx, player->last_jy);
10610 DrawLevelField(x, y);
10615 boolean DropElement(struct PlayerInfo *player)
10617 int old_element, new_element;
10618 int dropx = player->jx, dropy = player->jy;
10619 int drop_direction = player->MovDir;
10620 int drop_side = drop_direction;
10621 int drop_element = (player->inventory_size > 0 ?
10622 player->inventory_element[player->inventory_size - 1] :
10623 player->inventory_infinite_element != EL_UNDEFINED ?
10624 player->inventory_infinite_element :
10625 player->dynabombs_left > 0 ?
10626 EL_DYNABOMB_PLAYER_1_ACTIVE + player->index_nr :
10629 /* do not drop an element on top of another element; when holding drop key
10630 pressed without moving, dropped element must move away before the next
10631 element can be dropped (this is especially important if the next element
10632 is dynamite, which can be placed on background for historical reasons) */
10633 if (PLAYER_DROPPING(player, dropx, dropy) && Feld[dropx][dropy] != EL_EMPTY)
10636 if (IS_THROWABLE(drop_element))
10638 dropx += GET_DX_FROM_DIR(drop_direction);
10639 dropy += GET_DY_FROM_DIR(drop_direction);
10641 if (!IN_LEV_FIELD(dropx, dropy))
10645 old_element = Feld[dropx][dropy]; /* old element at dropping position */
10646 new_element = drop_element; /* default: no change when dropping */
10648 /* check if player is active, not moving and ready to drop */
10649 if (!player->active || player->MovPos || player->drop_delay > 0)
10652 /* check if player has anything that can be dropped */
10653 if (new_element == EL_UNDEFINED)
10656 /* check if anything can be dropped at the current position */
10657 if (IS_ACTIVE_BOMB(old_element) || old_element == EL_EXPLOSION)
10660 /* collected custom elements can only be dropped on empty fields */
10661 if (IS_CUSTOM_ELEMENT(new_element) && old_element != EL_EMPTY)
10664 if (old_element != EL_EMPTY)
10665 Back[dropx][dropy] = old_element; /* store old element on this field */
10667 ResetGfxAnimation(dropx, dropy);
10668 ResetRandomAnimationValue(dropx, dropy);
10670 if (player->inventory_size > 0 ||
10671 player->inventory_infinite_element != EL_UNDEFINED)
10673 if (player->inventory_size > 0)
10675 player->inventory_size--;
10677 DrawGameValue_Dynamite(local_player->inventory_size);
10679 if (new_element == EL_DYNAMITE)
10680 new_element = EL_DYNAMITE_ACTIVE;
10681 else if (new_element == EL_SP_DISK_RED)
10682 new_element = EL_SP_DISK_RED_ACTIVE;
10685 Feld[dropx][dropy] = new_element;
10687 if (IN_SCR_FIELD(SCREENX(dropx), SCREENY(dropy)))
10688 DrawGraphicThruMask(SCREENX(dropx), SCREENY(dropy),
10689 el2img(Feld[dropx][dropy]), 0);
10691 PlayLevelSoundAction(dropx, dropy, ACTION_DROPPING);
10693 /* needed if previous element just changed to "empty" in the last frame */
10694 ChangeCount[dropx][dropy] = 0; /* allow at least one more change */
10696 CheckElementChangeByPlayer(dropx, dropy, new_element, CE_DROPPED_BY_PLAYER,
10697 player->index_bit, drop_side);
10698 CheckTriggeredElementChangeByPlayer(dropx, dropy, new_element,
10700 player->index_bit, drop_side);
10702 TestIfElementTouchesCustomElement(dropx, dropy);
10704 else /* player is dropping a dyna bomb */
10706 player->dynabombs_left--;
10708 Feld[dropx][dropy] = new_element;
10710 if (IN_SCR_FIELD(SCREENX(dropx), SCREENY(dropy)))
10711 DrawGraphicThruMask(SCREENX(dropx), SCREENY(dropy),
10712 el2img(Feld[dropx][dropy]), 0);
10714 PlayLevelSoundAction(dropx, dropy, ACTION_DROPPING);
10717 if (Feld[dropx][dropy] == new_element) /* uninitialized unless CE change */
10718 InitField_WithBug1(dropx, dropy, FALSE);
10720 new_element = Feld[dropx][dropy]; /* element might have changed */
10722 if (IS_CUSTOM_ELEMENT(new_element) && CAN_MOVE(new_element) &&
10723 element_info[new_element].move_pattern == MV_WHEN_DROPPED)
10725 int move_direction, nextx, nexty;
10727 if (element_info[new_element].move_direction_initial == MV_START_AUTOMATIC)
10728 MovDir[dropx][dropy] = drop_direction;
10730 move_direction = MovDir[dropx][dropy];
10731 nextx = dropx + GET_DX_FROM_DIR(move_direction);
10732 nexty = dropy + GET_DY_FROM_DIR(move_direction);
10734 ChangeCount[dropx][dropy] = 0; /* allow at least one more change */
10735 CheckCollision[dropx][dropy] = 2;
10738 player->drop_delay = GET_NEW_DROP_DELAY(drop_element);
10739 player->is_dropping = TRUE;
10741 player->drop_x = dropx;
10742 player->drop_y = dropy;
10747 /* ------------------------------------------------------------------------- */
10748 /* game sound playing functions */
10749 /* ------------------------------------------------------------------------- */
10751 static int *loop_sound_frame = NULL;
10752 static int *loop_sound_volume = NULL;
10754 void InitPlayLevelSound()
10756 int num_sounds = getSoundListSize();
10758 checked_free(loop_sound_frame);
10759 checked_free(loop_sound_volume);
10761 loop_sound_frame = checked_calloc(num_sounds * sizeof(int));
10762 loop_sound_volume = checked_calloc(num_sounds * sizeof(int));
10765 static void PlayLevelSound(int x, int y, int nr)
10767 int sx = SCREENX(x), sy = SCREENY(y);
10768 int volume, stereo_position;
10769 int max_distance = 8;
10770 int type = (IS_LOOP_SOUND(nr) ? SND_CTRL_PLAY_LOOP : SND_CTRL_PLAY_SOUND);
10772 if ((!setup.sound_simple && !IS_LOOP_SOUND(nr)) ||
10773 (!setup.sound_loops && IS_LOOP_SOUND(nr)))
10776 if (!IN_LEV_FIELD(x, y) ||
10777 sx < -max_distance || sx >= SCR_FIELDX + max_distance ||
10778 sy < -max_distance || sy >= SCR_FIELDY + max_distance)
10781 volume = SOUND_MAX_VOLUME;
10783 if (!IN_SCR_FIELD(sx, sy))
10785 int dx = ABS(sx - SCR_FIELDX / 2) - SCR_FIELDX / 2;
10786 int dy = ABS(sy - SCR_FIELDY / 2) - SCR_FIELDY / 2;
10788 volume -= volume * (dx > dy ? dx : dy) / max_distance;
10791 stereo_position = (SOUND_MAX_LEFT +
10792 (sx + max_distance) * SOUND_MAX_LEFT2RIGHT /
10793 (SCR_FIELDX + 2 * max_distance));
10795 if (IS_LOOP_SOUND(nr))
10797 /* This assures that quieter loop sounds do not overwrite louder ones,
10798 while restarting sound volume comparison with each new game frame. */
10800 if (loop_sound_volume[nr] > volume && loop_sound_frame[nr] == FrameCounter)
10803 loop_sound_volume[nr] = volume;
10804 loop_sound_frame[nr] = FrameCounter;
10807 PlaySoundExt(nr, volume, stereo_position, type);
10810 static void PlayLevelSoundNearest(int x, int y, int sound_action)
10812 PlayLevelSound(x < LEVELX(BX1) ? LEVELX(BX1) :
10813 x > LEVELX(BX2) ? LEVELX(BX2) : x,
10814 y < LEVELY(BY1) ? LEVELY(BY1) :
10815 y > LEVELY(BY2) ? LEVELY(BY2) : y,
10819 static void PlayLevelSoundAction(int x, int y, int action)
10821 PlayLevelSoundElementAction(x, y, Feld[x][y], action);
10824 static void PlayLevelSoundElementAction(int x, int y, int element, int action)
10826 int sound_effect = element_info[SND_ELEMENT(element)].sound[action];
10828 if (sound_effect != SND_UNDEFINED)
10829 PlayLevelSound(x, y, sound_effect);
10832 static void PlayLevelSoundElementActionIfLoop(int x, int y, int element,
10835 int sound_effect = element_info[SND_ELEMENT(element)].sound[action];
10837 if (sound_effect != SND_UNDEFINED && IS_LOOP_SOUND(sound_effect))
10838 PlayLevelSound(x, y, sound_effect);
10841 static void PlayLevelSoundActionIfLoop(int x, int y, int action)
10843 int sound_effect = element_info[SND_ELEMENT(Feld[x][y])].sound[action];
10845 if (sound_effect != SND_UNDEFINED && IS_LOOP_SOUND(sound_effect))
10846 PlayLevelSound(x, y, sound_effect);
10849 static void StopLevelSoundActionIfLoop(int x, int y, int action)
10851 int sound_effect = element_info[SND_ELEMENT(Feld[x][y])].sound[action];
10853 if (sound_effect != SND_UNDEFINED && IS_LOOP_SOUND(sound_effect))
10854 StopSound(sound_effect);
10857 static void PlayLevelMusic()
10859 if (levelset.music[level_nr] != MUS_UNDEFINED)
10860 PlayMusic(levelset.music[level_nr]); /* from config file */
10862 PlayMusic(MAP_NOCONF_MUSIC(level_nr)); /* from music dir */
10865 void PlayLevelSound_EM(int x, int y, int element_em, int sample)
10867 int element = (element_em > -1 ? map_element_EM_to_RND(element_em) : 0);
10872 PlayLevelSoundElementAction(x, y, element, ACTION_WALKING);
10876 PlayLevelSoundElementAction(x, y, element, ACTION_PUSHING);
10880 PlayLevelSoundElementAction(x, y, element, ACTION_IMPACT);
10884 PlayLevelSoundElementAction(x, y, element, ACTION_IMPACT);
10888 PlayLevelSoundElementAction(x, y, element, ACTION_BREAKING);
10892 PlayLevelSoundElementAction(x, y, element, ACTION_MOVING);
10896 PlayLevelSoundElementAction(x, y, element, ACTION_MOVING);
10899 case SAMPLE_android_clone:
10900 PlayLevelSoundElementAction(x, y, element, ACTION_DROPPING);
10903 case SAMPLE_android_move:
10904 PlayLevelSoundElementAction(x, y, element, ACTION_MOVING);
10907 case SAMPLE_spring:
10908 PlayLevelSoundElementAction(x, y, element, ACTION_IMPACT);
10912 PlayLevelSoundElementAction(x, y, element, ACTION_SLURPED_BY_SPRING);
10916 PlayLevelSoundElementAction(x, y, element, ACTION_WAITING);
10919 case SAMPLE_eater_eat:
10920 PlayLevelSoundElementAction(x, y, element, ACTION_DIGGING);
10924 PlayLevelSoundElementAction(x, y, element, ACTION_MOVING);
10927 case SAMPLE_collect:
10928 PlayLevelSoundElementAction(x, y, element, ACTION_COLLECTING);
10931 case SAMPLE_diamond:
10932 PlayLevelSoundElementAction(x, y, element, ACTION_IMPACT);
10935 case SAMPLE_squash:
10936 /* !!! CHECK THIS !!! */
10938 PlayLevelSoundElementAction(x, y, element, ACTION_BREAKING);
10940 PlayLevelSoundElementAction(x, y, element, ACTION_SMASHED_BY_ROCK);
10944 case SAMPLE_wonderfall:
10945 PlayLevelSoundElementAction(x, y, element, ACTION_FILLING);
10949 PlayLevelSoundElementAction(x, y, element, ACTION_IMPACT);
10953 PlayLevelSoundElementAction(x, y, element, ACTION_PUSHING);
10957 PlayLevelSoundElementAction(x, y, element, ACTION_DIGGING);
10961 PlayLevelSoundElementAction(x, y, element, ACTION_SPLASHING);
10965 PlayLevelSoundElementAction(x, y, element, ACTION_DROPPING);
10969 PlayLevelSoundElementAction(x, y, element, ACTION_GROWING);
10972 case SAMPLE_wonder:
10973 PlayLevelSoundElementAction(x, y, element, ACTION_ACTIVE);
10977 PlayLevelSoundElementAction(x, y, element, ACTION_PASSING);
10980 case SAMPLE_exit_open:
10981 PlayLevelSoundElementAction(x, y, element, ACTION_OPENING);
10984 case SAMPLE_exit_leave:
10985 PlayLevelSoundElementAction(x, y, element, ACTION_PASSING);
10988 case SAMPLE_dynamite:
10989 PlayLevelSoundElementAction(x, y, element, ACTION_DROPPING);
10993 PlayLevelSoundElementAction(x, y, element, ACTION_ACTIVE);
10997 PlayLevelSoundElementAction(x, y, element, ACTION_ACTIVATING);
11001 PlayLevelSoundElementAction(x, y, element, ACTION_ACTIVE);
11005 PlayLevelSoundElementAction(x, y, element, ACTION_EXPLODING);
11009 PlayLevelSoundElementAction(x, y, element, ACTION_DYING);
11013 PlaySoundStereo(SND_GAME_RUNNING_OUT_OF_TIME, SOUND_MIDDLE);
11017 PlayLevelSoundElementAction(x, y, element, ACTION_DEFAULT);
11022 void RaiseScore(int value)
11024 local_player->score += value;
11026 DrawGameValue_Score(local_player->score);
11029 void RaiseScoreElement(int element)
11034 case EL_BD_DIAMOND:
11035 case EL_EMERALD_YELLOW:
11036 case EL_EMERALD_RED:
11037 case EL_EMERALD_PURPLE:
11038 case EL_SP_INFOTRON:
11039 RaiseScore(level.score[SC_EMERALD]);
11042 RaiseScore(level.score[SC_DIAMOND]);
11045 RaiseScore(level.score[SC_CRYSTAL]);
11048 RaiseScore(level.score[SC_PEARL]);
11051 case EL_BD_BUTTERFLY:
11052 case EL_SP_ELECTRON:
11053 RaiseScore(level.score[SC_BUG]);
11056 case EL_BD_FIREFLY:
11057 case EL_SP_SNIKSNAK:
11058 RaiseScore(level.score[SC_SPACESHIP]);
11061 case EL_DARK_YAMYAM:
11062 RaiseScore(level.score[SC_YAMYAM]);
11065 RaiseScore(level.score[SC_ROBOT]);
11068 RaiseScore(level.score[SC_PACMAN]);
11071 RaiseScore(level.score[SC_NUT]);
11074 case EL_SP_DISK_RED:
11075 case EL_DYNABOMB_INCREASE_NUMBER:
11076 case EL_DYNABOMB_INCREASE_SIZE:
11077 case EL_DYNABOMB_INCREASE_POWER:
11078 RaiseScore(level.score[SC_DYNAMITE]);
11080 case EL_SHIELD_NORMAL:
11081 case EL_SHIELD_DEADLY:
11082 RaiseScore(level.score[SC_SHIELD]);
11084 case EL_EXTRA_TIME:
11085 RaiseScore(level.extra_time_score);
11099 RaiseScore(level.score[SC_KEY]);
11102 RaiseScore(element_info[element].collect_score);
11107 void RequestQuitGame(boolean ask_if_really_quit)
11109 if (AllPlayersGone ||
11110 !ask_if_really_quit ||
11111 level_editor_test_game ||
11112 Request("Do you really want to quit the game ?",
11113 REQ_ASK | REQ_STAY_CLOSED))
11115 #if defined(NETWORK_AVALIABLE)
11116 if (options.network)
11117 SendToServer_StopPlaying();
11121 game_status = GAME_MODE_MAIN;
11127 if (tape.playing && tape.deactivate_display)
11128 TapeDeactivateDisplayOff(TRUE);
11130 OpenDoor(DOOR_OPEN_1 | DOOR_COPY_BACK);
11132 if (tape.playing && tape.deactivate_display)
11133 TapeDeactivateDisplayOn();
11138 /* ---------- new game button stuff ---------------------------------------- */
11140 /* graphic position values for game buttons */
11141 #define GAME_BUTTON_XSIZE 30
11142 #define GAME_BUTTON_YSIZE 30
11143 #define GAME_BUTTON_XPOS 5
11144 #define GAME_BUTTON_YPOS 215
11145 #define SOUND_BUTTON_XPOS 5
11146 #define SOUND_BUTTON_YPOS (GAME_BUTTON_YPOS + GAME_BUTTON_YSIZE)
11148 #define GAME_BUTTON_STOP_XPOS (GAME_BUTTON_XPOS + 0 * GAME_BUTTON_XSIZE)
11149 #define GAME_BUTTON_PAUSE_XPOS (GAME_BUTTON_XPOS + 1 * GAME_BUTTON_XSIZE)
11150 #define GAME_BUTTON_PLAY_XPOS (GAME_BUTTON_XPOS + 2 * GAME_BUTTON_XSIZE)
11151 #define SOUND_BUTTON_MUSIC_XPOS (SOUND_BUTTON_XPOS + 0 * GAME_BUTTON_XSIZE)
11152 #define SOUND_BUTTON_LOOPS_XPOS (SOUND_BUTTON_XPOS + 1 * GAME_BUTTON_XSIZE)
11153 #define SOUND_BUTTON_SIMPLE_XPOS (SOUND_BUTTON_XPOS + 2 * GAME_BUTTON_XSIZE)
11160 } gamebutton_info[NUM_GAME_BUTTONS] =
11163 GAME_BUTTON_STOP_XPOS, GAME_BUTTON_YPOS,
11168 GAME_BUTTON_PAUSE_XPOS, GAME_BUTTON_YPOS,
11169 GAME_CTRL_ID_PAUSE,
11173 GAME_BUTTON_PLAY_XPOS, GAME_BUTTON_YPOS,
11178 SOUND_BUTTON_MUSIC_XPOS, SOUND_BUTTON_YPOS,
11179 SOUND_CTRL_ID_MUSIC,
11180 "background music on/off"
11183 SOUND_BUTTON_LOOPS_XPOS, SOUND_BUTTON_YPOS,
11184 SOUND_CTRL_ID_LOOPS,
11185 "sound loops on/off"
11188 SOUND_BUTTON_SIMPLE_XPOS, SOUND_BUTTON_YPOS,
11189 SOUND_CTRL_ID_SIMPLE,
11190 "normal sounds on/off"
11194 void CreateGameButtons()
11198 for (i = 0; i < NUM_GAME_BUTTONS; i++)
11200 Bitmap *gd_bitmap = graphic_info[IMG_GLOBAL_DOOR].bitmap;
11201 struct GadgetInfo *gi;
11204 unsigned long event_mask;
11205 int gd_xoffset, gd_yoffset;
11206 int gd_x1, gd_x2, gd_y1, gd_y2;
11209 gd_xoffset = gamebutton_info[i].x;
11210 gd_yoffset = gamebutton_info[i].y;
11211 gd_x1 = DOOR_GFX_PAGEX4 + gd_xoffset;
11212 gd_x2 = DOOR_GFX_PAGEX3 + gd_xoffset;
11214 if (id == GAME_CTRL_ID_STOP ||
11215 id == GAME_CTRL_ID_PAUSE ||
11216 id == GAME_CTRL_ID_PLAY)
11218 button_type = GD_TYPE_NORMAL_BUTTON;
11220 event_mask = GD_EVENT_RELEASED;
11221 gd_y1 = DOOR_GFX_PAGEY1 + gd_yoffset - GAME_BUTTON_YSIZE;
11222 gd_y2 = DOOR_GFX_PAGEY1 + gd_yoffset - GAME_BUTTON_YSIZE;
11226 button_type = GD_TYPE_CHECK_BUTTON;
11228 ((id == SOUND_CTRL_ID_MUSIC && setup.sound_music) ||
11229 (id == SOUND_CTRL_ID_LOOPS && setup.sound_loops) ||
11230 (id == SOUND_CTRL_ID_SIMPLE && setup.sound_simple) ? TRUE : FALSE);
11231 event_mask = GD_EVENT_PRESSED;
11232 gd_y1 = DOOR_GFX_PAGEY1 + gd_yoffset;
11233 gd_y2 = DOOR_GFX_PAGEY1 + gd_yoffset - GAME_BUTTON_YSIZE;
11236 gi = CreateGadget(GDI_CUSTOM_ID, id,
11237 GDI_INFO_TEXT, gamebutton_info[i].infotext,
11238 GDI_X, DX + gd_xoffset,
11239 GDI_Y, DY + gd_yoffset,
11240 GDI_WIDTH, GAME_BUTTON_XSIZE,
11241 GDI_HEIGHT, GAME_BUTTON_YSIZE,
11242 GDI_TYPE, button_type,
11243 GDI_STATE, GD_BUTTON_UNPRESSED,
11244 GDI_CHECKED, checked,
11245 GDI_DESIGN_UNPRESSED, gd_bitmap, gd_x1, gd_y1,
11246 GDI_DESIGN_PRESSED, gd_bitmap, gd_x2, gd_y1,
11247 GDI_ALT_DESIGN_UNPRESSED, gd_bitmap, gd_x1, gd_y2,
11248 GDI_ALT_DESIGN_PRESSED, gd_bitmap, gd_x2, gd_y2,
11249 GDI_EVENT_MASK, event_mask,
11250 GDI_CALLBACK_ACTION, HandleGameButtons,
11254 Error(ERR_EXIT, "cannot create gadget");
11256 game_gadget[id] = gi;
11260 void FreeGameButtons()
11264 for (i = 0; i < NUM_GAME_BUTTONS; i++)
11265 FreeGadget(game_gadget[i]);
11268 static void MapGameButtons()
11272 for (i = 0; i < NUM_GAME_BUTTONS; i++)
11273 MapGadget(game_gadget[i]);
11276 void UnmapGameButtons()
11280 for (i = 0; i < NUM_GAME_BUTTONS; i++)
11281 UnmapGadget(game_gadget[i]);
11284 static void HandleGameButtons(struct GadgetInfo *gi)
11286 int id = gi->custom_id;
11288 if (game_status != GAME_MODE_PLAYING)
11293 case GAME_CTRL_ID_STOP:
11294 RequestQuitGame(TRUE);
11297 case GAME_CTRL_ID_PAUSE:
11298 if (options.network)
11300 #if defined(NETWORK_AVALIABLE)
11302 SendToServer_ContinuePlaying();
11304 SendToServer_PausePlaying();
11308 TapeTogglePause(TAPE_TOGGLE_MANUAL);
11311 case GAME_CTRL_ID_PLAY:
11314 #if defined(NETWORK_AVALIABLE)
11315 if (options.network)
11316 SendToServer_ContinuePlaying();
11320 tape.pausing = FALSE;
11321 DrawVideoDisplay(VIDEO_STATE_PAUSE_OFF,0);
11326 case SOUND_CTRL_ID_MUSIC:
11327 if (setup.sound_music)
11329 setup.sound_music = FALSE;
11332 else if (audio.music_available)
11334 setup.sound = setup.sound_music = TRUE;
11336 SetAudioMode(setup.sound);
11342 case SOUND_CTRL_ID_LOOPS:
11343 if (setup.sound_loops)
11344 setup.sound_loops = FALSE;
11345 else if (audio.loops_available)
11347 setup.sound = setup.sound_loops = TRUE;
11348 SetAudioMode(setup.sound);
11352 case SOUND_CTRL_ID_SIMPLE:
11353 if (setup.sound_simple)
11354 setup.sound_simple = FALSE;
11355 else if (audio.sound_available)
11357 setup.sound = setup.sound_simple = TRUE;
11358 SetAudioMode(setup.sound);