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)
44 /* for MovePlayer() */
45 #define MF_NO_ACTION 0
49 /* for ScrollPlayer() */
51 #define SCROLL_GO_ON 1
53 /* for Bang()/Explode() */
54 #define EX_PHASE_START 0
55 #define EX_TYPE_NONE 0
56 #define EX_TYPE_NORMAL (1 << 0)
57 #define EX_TYPE_CENTER (1 << 1)
58 #define EX_TYPE_BORDER (1 << 2)
59 #define EX_TYPE_CROSS (1 << 3)
60 #define EX_TYPE_DYNA (1 << 4)
61 #define EX_TYPE_SINGLE_TILE (EX_TYPE_CENTER | EX_TYPE_BORDER)
63 /* special positions in the game control window (relative to control window) */
66 #define XX_EMERALDS 29
67 #define YY_EMERALDS 54
68 #define XX_DYNAMITE 29
69 #define YY_DYNAMITE 89
78 /* special positions in the game control window (relative to main window) */
79 #define DX_LEVEL (DX + XX_LEVEL)
80 #define DY_LEVEL (DY + YY_LEVEL)
81 #define DX_EMERALDS (DX + XX_EMERALDS)
82 #define DY_EMERALDS (DY + YY_EMERALDS)
83 #define DX_DYNAMITE (DX + XX_DYNAMITE)
84 #define DY_DYNAMITE (DY + YY_DYNAMITE)
85 #define DX_KEYS (DX + XX_KEYS)
86 #define DY_KEYS (DY + YY_KEYS)
87 #define DX_SCORE (DX + XX_SCORE)
88 #define DY_SCORE (DY + YY_SCORE)
89 #define DX_TIME1 (DX + XX_TIME1)
90 #define DX_TIME2 (DX + XX_TIME2)
91 #define DY_TIME (DY + YY_TIME)
93 /* values for initial player move delay (initial delay counter value) */
94 #define INITIAL_MOVE_DELAY_OFF -1
95 #define INITIAL_MOVE_DELAY_ON 0
97 /* values for player movement speed (which is in fact a delay value) */
98 #define MOVE_DELAY_MIN_SPEED 32
99 #define MOVE_DELAY_NORMAL_SPEED 8
100 #define MOVE_DELAY_HIGH_SPEED 4
101 #define MOVE_DELAY_MAX_SPEED 1
104 #define DOUBLE_MOVE_DELAY(x) (x = (x <= MOVE_DELAY_HIGH_SPEED ? x * 2 : x))
105 #define HALVE_MOVE_DELAY(x) (x = (x >= MOVE_DELAY_HIGH_SPEED ? x / 2 : x))
107 #define DOUBLE_MOVE_DELAY(x) (x = (x < MOVE_DELAY_MIN_SPEED ? x * 2 : x))
108 #define HALVE_MOVE_DELAY(x) (x = (x > MOVE_DELAY_MAX_SPEED ? x / 2 : x))
110 #define DOUBLE_PLAYER_SPEED(p) (HALVE_MOVE_DELAY((p)->move_delay_value))
111 #define HALVE_PLAYER_SPEED(p) (DOUBLE_MOVE_DELAY((p)->move_delay_value))
113 /* values for other actions */
114 #define MOVE_STEPSIZE_NORMAL (TILEX / MOVE_DELAY_NORMAL_SPEED)
115 #define MOVE_STEPSIZE_MIN (1)
116 #define MOVE_STEPSIZE_MAX (TILEX)
118 #define GET_DX_FROM_DIR(d) ((d) == MV_LEFT ? -1 : (d) == MV_RIGHT ? 1 : 0)
119 #define GET_DY_FROM_DIR(d) ((d) == MV_UP ? -1 : (d) == MV_DOWN ? 1 : 0)
121 #define INIT_GFX_RANDOM() (SimpleRND(1000000))
123 #define GET_NEW_PUSH_DELAY(e) ( (element_info[e].push_delay_fixed) + \
124 RND(element_info[e].push_delay_random))
125 #define GET_NEW_DROP_DELAY(e) ( (element_info[e].drop_delay_fixed) + \
126 RND(element_info[e].drop_delay_random))
127 #define GET_NEW_MOVE_DELAY(e) ( (element_info[e].move_delay_fixed) + \
128 RND(element_info[e].move_delay_random))
129 #define GET_MAX_MOVE_DELAY(e) ( (element_info[e].move_delay_fixed) + \
130 (element_info[e].move_delay_random))
131 #define GET_NEW_CUSTOM_VALUE(e) ( (element_info[e].ce_value_fixed_initial) +\
132 RND(element_info[e].ce_value_random_initial))
133 #define GET_CHANGE_DELAY(c) ( ((c)->delay_fixed * (c)->delay_frames) + \
134 RND((c)->delay_random * (c)->delay_frames))
136 #define GET_TARGET_ELEMENT(e, ch) \
137 ((e) == EL_TRIGGER_ELEMENT ? (ch)->actual_trigger_element : \
138 (e) == EL_TRIGGER_PLAYER ? (ch)->actual_trigger_player : (e))
140 #define CAN_GROW_INTO(e) \
141 ((e) == EL_SAND || (IS_DIGGABLE(e) && level.grow_into_diggable))
143 #define ELEMENT_CAN_ENTER_FIELD_BASE_X(x, y, condition) \
144 (IN_LEV_FIELD(x, y) && (IS_FREE(x, y) || \
147 #define ELEMENT_CAN_ENTER_FIELD_BASE_2(e, x, y, condition) \
148 (IN_LEV_FIELD(x, y) && (IS_FREE(x, y) || \
149 (CAN_MOVE_INTO_ACID(e) && \
150 Feld[x][y] == EL_ACID) || \
153 #define ELEMENT_CAN_ENTER_FIELD_BASE_3(e, x, y, condition) \
154 (IN_LEV_FIELD(x, y) && (IS_FREE_OR_PLAYER(x, y) || \
155 (CAN_MOVE_INTO_ACID(e) && \
156 Feld[x][y] == EL_ACID) || \
159 #define ELEMENT_CAN_ENTER_FIELD_BASE_4(e, x, y, condition) \
160 (IN_LEV_FIELD(x, y) && (IS_FREE(x, y) || \
162 (CAN_MOVE_INTO_ACID(e) && \
163 Feld[x][y] == EL_ACID) || \
164 (DONT_COLLIDE_WITH(e) && \
166 !PLAYER_ENEMY_PROTECTED(x, y))))
168 #define ELEMENT_CAN_ENTER_FIELD(e, x, y) \
169 ELEMENT_CAN_ENTER_FIELD_BASE_4(e, x, y, 0)
171 #define SATELLITE_CAN_ENTER_FIELD(x, y) \
172 ELEMENT_CAN_ENTER_FIELD_BASE_2(EL_SATELLITE, x, y, 0)
174 #define ENEMY_CAN_ENTER_FIELD(e, x, y) \
175 ELEMENT_CAN_ENTER_FIELD_BASE_2(e, x, y, 0)
177 #define YAMYAM_CAN_ENTER_FIELD(e, x, y) \
178 ELEMENT_CAN_ENTER_FIELD_BASE_3(e, x, y, Feld[x][y] == EL_DIAMOND)
180 #define DARK_YAMYAM_CAN_ENTER_FIELD(e, x, y) \
181 ELEMENT_CAN_ENTER_FIELD_BASE_3(e, x,y, IS_FOOD_DARK_YAMYAM(Feld[x][y]))
183 #define PACMAN_CAN_ENTER_FIELD(e, x, y) \
184 ELEMENT_CAN_ENTER_FIELD_BASE_3(e, x, y, IS_AMOEBOID(Feld[x][y]))
186 #define PIG_CAN_ENTER_FIELD(e, x, y) \
187 ELEMENT_CAN_ENTER_FIELD_BASE_2(e, x, y, IS_FOOD_PIG(Feld[x][y]))
189 #define PENGUIN_CAN_ENTER_FIELD(e, x, y) \
190 ELEMENT_CAN_ENTER_FIELD_BASE_2(e, x, y, (Feld[x][y] == EL_EXIT_OPEN ||\
191 IS_FOOD_PENGUIN(Feld[x][y])))
192 #define DRAGON_CAN_ENTER_FIELD(e, x, y) \
193 ELEMENT_CAN_ENTER_FIELD_BASE_2(e, x, y, 0)
195 #define MOLE_CAN_ENTER_FIELD(e, x, y, condition) \
196 ELEMENT_CAN_ENTER_FIELD_BASE_2(e, x, y, (condition))
198 #define SPRING_CAN_ENTER_FIELD(e, x, y) \
199 ELEMENT_CAN_ENTER_FIELD_BASE_2(e, x, y, 0)
201 #define GROUP_NR(e) ((e) - EL_GROUP_START)
202 #define MOVE_ENTER_EL(e) (element_info[e].move_enter_element)
203 #define IS_IN_GROUP(e, nr) (element_info[e].in_group[nr] == TRUE)
204 #define IS_IN_GROUP_EL(e, ge) (IS_IN_GROUP(e, (ge) - EL_GROUP_START))
206 #define IS_EQUAL_OR_IN_GROUP(e, ge) \
207 (IS_GROUP_ELEMENT(ge) ? IS_IN_GROUP(e, GROUP_NR(ge)) : (e) == (ge))
209 #define CE_ENTER_FIELD_COND(e, x, y) \
210 (!IS_PLAYER(x, y) && \
211 IS_EQUAL_OR_IN_GROUP(Feld[x][y], MOVE_ENTER_EL(e)))
213 #define CUSTOM_ELEMENT_CAN_ENTER_FIELD(e, x, y) \
214 ELEMENT_CAN_ENTER_FIELD_BASE_4(e, x, y, CE_ENTER_FIELD_COND(e, x, y))
216 #define IN_LEV_FIELD_AND_IS_FREE(x, y) (IN_LEV_FIELD(x, y) && IS_FREE(x, y))
217 #define IN_LEV_FIELD_AND_NOT_FREE(x, y) (IN_LEV_FIELD(x, y) && !IS_FREE(x, y))
219 #define ACCESS_FROM(e, d) (element_info[e].access_direction &(d))
220 #define IS_WALKABLE_FROM(e, d) (IS_WALKABLE(e) && ACCESS_FROM(e, d))
221 #define IS_PASSABLE_FROM(e, d) (IS_PASSABLE(e) && ACCESS_FROM(e, d))
222 #define IS_ACCESSIBLE_FROM(e, d) (IS_ACCESSIBLE(e) && ACCESS_FROM(e, d))
224 /* game button identifiers */
225 #define GAME_CTRL_ID_STOP 0
226 #define GAME_CTRL_ID_PAUSE 1
227 #define GAME_CTRL_ID_PLAY 2
228 #define SOUND_CTRL_ID_MUSIC 3
229 #define SOUND_CTRL_ID_LOOPS 4
230 #define SOUND_CTRL_ID_SIMPLE 5
232 #define NUM_GAME_BUTTONS 6
235 /* forward declaration for internal use */
237 static void SetPlayerWaiting(struct PlayerInfo *, boolean);
238 static void AdvanceFrameAndPlayerCounters(int);
240 static boolean MovePlayerOneStep(struct PlayerInfo *, int, int, int, int);
241 static boolean MovePlayer(struct PlayerInfo *, int, int);
242 static void ScrollPlayer(struct PlayerInfo *, int);
243 static void ScrollScreen(struct PlayerInfo *, int);
245 int DigField(struct PlayerInfo *, int, int, int, int, int, int, int);
247 static void InitBeltMovement(void);
248 static void CloseAllOpenTimegates(void);
249 static void CheckGravityMovement(struct PlayerInfo *);
250 static void CheckGravityMovementWhenNotMoving(struct PlayerInfo *);
251 static void KillPlayerUnlessEnemyProtected(int, int);
252 static void KillPlayerUnlessExplosionProtected(int, int);
254 static void TestIfPlayerTouchesCustomElement(int, int);
255 static void TestIfElementTouchesCustomElement(int, int);
256 static void TestIfElementHitsCustomElement(int, int, int);
258 static void TestIfElementSmashesCustomElement(int, int, int);
261 static void ChangeElement(int, int, int);
263 static boolean CheckTriggeredElementChangeExt(int, int, int, int, int,int,int);
264 #define CheckTriggeredElementChange(x, y, e, ev) \
265 CheckTriggeredElementChangeExt(x,y,e,ev, CH_PLAYER_ANY,CH_SIDE_ANY, -1)
266 #define CheckTriggeredElementChangeByPlayer(x, y, e, ev, p, s) \
267 CheckTriggeredElementChangeExt(x, y, e, ev, p, s, -1)
268 #define CheckTriggeredElementChangeBySide(x, y, e, ev, s) \
269 CheckTriggeredElementChangeExt(x, y, e, ev, CH_PLAYER_ANY, s, -1)
270 #define CheckTriggeredElementChangeByPage(x, y, e, ev, p) \
271 CheckTriggeredElementChangeExt(x,y,e,ev, CH_PLAYER_ANY, CH_SIDE_ANY, p)
273 static boolean CheckElementChangeExt(int, int, int, int, int, int, int);
274 #define CheckElementChange(x, y, e, te, ev) \
275 CheckElementChangeExt(x, y, e, te, ev, CH_PLAYER_ANY, CH_SIDE_ANY)
276 #define CheckElementChangeByPlayer(x, y, e, ev, p, s) \
277 CheckElementChangeExt(x, y, e, EL_EMPTY, ev, p, s)
278 #define CheckElementChangeBySide(x, y, e, te, ev, s) \
279 CheckElementChangeExt(x, y, e, te, ev, CH_PLAYER_ANY, s)
281 static void PlayLevelSound(int, int, int);
282 static void PlayLevelSoundNearest(int, int, int);
283 static void PlayLevelSoundAction(int, int, int);
284 static void PlayLevelSoundElementAction(int, int, int, int);
285 static void PlayLevelSoundElementActionIfLoop(int, int, int, int);
286 static void PlayLevelSoundActionIfLoop(int, int, int);
287 static void StopLevelSoundActionIfLoop(int, int, int);
288 static void PlayLevelMusic();
290 static void MapGameButtons();
291 static void HandleGameButtons(struct GadgetInfo *);
293 static struct GadgetInfo *game_gadget[NUM_GAME_BUTTONS];
296 /* ------------------------------------------------------------------------- */
297 /* definition of elements that automatically change to other elements after */
298 /* a specified time, eventually calling a function when changing */
299 /* ------------------------------------------------------------------------- */
301 /* forward declaration for changer functions */
302 static void InitBuggyBase(int x, int y);
303 static void WarnBuggyBase(int x, int y);
305 static void InitTrap(int x, int y);
306 static void ActivateTrap(int x, int y);
307 static void ChangeActiveTrap(int x, int y);
309 static void InitRobotWheel(int x, int y);
310 static void RunRobotWheel(int x, int y);
311 static void StopRobotWheel(int x, int y);
313 static void InitTimegateWheel(int x, int y);
314 static void RunTimegateWheel(int x, int y);
316 struct ChangingElementInfo
321 void (*pre_change_function)(int x, int y);
322 void (*change_function)(int x, int y);
323 void (*post_change_function)(int x, int y);
326 static struct ChangingElementInfo change_delay_list[] =
377 EL_SWITCHGATE_OPENING,
385 EL_SWITCHGATE_CLOSING,
386 EL_SWITCHGATE_CLOSED,
418 EL_ACID_SPLASH_RIGHT,
427 EL_SP_BUGGY_BASE_ACTIVATING,
434 EL_SP_BUGGY_BASE_ACTIVATING,
435 EL_SP_BUGGY_BASE_ACTIVE,
442 EL_SP_BUGGY_BASE_ACTIVE,
466 EL_ROBOT_WHEEL_ACTIVE,
474 EL_TIMEGATE_SWITCH_ACTIVE,
495 int push_delay_fixed, push_delay_random;
500 { EL_BALLOON, 0, 0 },
502 { EL_SOKOBAN_OBJECT, 2, 0 },
503 { EL_SOKOBAN_FIELD_FULL, 2, 0 },
504 { EL_SATELLITE, 2, 0 },
505 { EL_SP_DISK_YELLOW, 2, 0 },
507 { EL_UNDEFINED, 0, 0 },
515 move_stepsize_list[] =
517 { EL_AMOEBA_DROP, 2 },
518 { EL_AMOEBA_DROPPING, 2 },
519 { EL_QUICKSAND_FILLING, 1 },
520 { EL_QUICKSAND_EMPTYING, 1 },
521 { EL_MAGIC_WALL_FILLING, 2 },
522 { EL_BD_MAGIC_WALL_FILLING, 2 },
523 { EL_MAGIC_WALL_EMPTYING, 2 },
524 { EL_BD_MAGIC_WALL_EMPTYING, 2 },
534 collect_count_list[] =
537 { EL_BD_DIAMOND, 1 },
538 { EL_EMERALD_YELLOW, 1 },
539 { EL_EMERALD_RED, 1 },
540 { EL_EMERALD_PURPLE, 1 },
542 { EL_SP_INFOTRON, 1 },
554 access_direction_list[] =
556 { EL_TUBE_ANY, MV_LEFT | MV_RIGHT | MV_UP | MV_DOWN },
557 { EL_TUBE_VERTICAL, MV_UP | MV_DOWN },
558 { EL_TUBE_HORIZONTAL, MV_LEFT | MV_RIGHT },
559 { EL_TUBE_VERTICAL_LEFT, MV_LEFT | MV_UP | MV_DOWN },
560 { EL_TUBE_VERTICAL_RIGHT, MV_RIGHT | MV_UP | MV_DOWN },
561 { EL_TUBE_HORIZONTAL_UP, MV_LEFT | MV_RIGHT | MV_UP },
562 { EL_TUBE_HORIZONTAL_DOWN, MV_LEFT | MV_RIGHT | MV_DOWN },
563 { EL_TUBE_LEFT_UP, MV_LEFT | MV_UP },
564 { EL_TUBE_LEFT_DOWN, MV_LEFT | MV_DOWN },
565 { EL_TUBE_RIGHT_UP, MV_RIGHT | MV_UP },
566 { EL_TUBE_RIGHT_DOWN, MV_RIGHT | MV_DOWN },
568 { EL_SP_PORT_LEFT, MV_RIGHT },
569 { EL_SP_PORT_RIGHT, MV_LEFT },
570 { EL_SP_PORT_UP, MV_DOWN },
571 { EL_SP_PORT_DOWN, MV_UP },
572 { EL_SP_PORT_HORIZONTAL, MV_LEFT | MV_RIGHT },
573 { EL_SP_PORT_VERTICAL, MV_UP | MV_DOWN },
574 { EL_SP_PORT_ANY, MV_LEFT | MV_RIGHT | MV_UP | MV_DOWN },
575 { EL_SP_GRAVITY_PORT_LEFT, MV_RIGHT },
576 { EL_SP_GRAVITY_PORT_RIGHT, MV_LEFT },
577 { EL_SP_GRAVITY_PORT_UP, MV_DOWN },
578 { EL_SP_GRAVITY_PORT_DOWN, MV_UP },
579 { EL_SP_GRAVITY_ON_PORT_LEFT, MV_RIGHT },
580 { EL_SP_GRAVITY_ON_PORT_RIGHT, MV_LEFT },
581 { EL_SP_GRAVITY_ON_PORT_UP, MV_DOWN },
582 { EL_SP_GRAVITY_ON_PORT_DOWN, MV_UP },
583 { EL_SP_GRAVITY_OFF_PORT_LEFT, MV_RIGHT },
584 { EL_SP_GRAVITY_OFF_PORT_RIGHT, MV_LEFT },
585 { EL_SP_GRAVITY_OFF_PORT_UP, MV_DOWN },
586 { EL_SP_GRAVITY_OFF_PORT_DOWN, MV_UP },
588 { EL_UNDEFINED, MV_NONE }
591 static boolean trigger_events[MAX_NUM_ELEMENTS][NUM_CHANGE_EVENTS];
593 #define IS_AUTO_CHANGING(e) (element_info[e].has_change_event[CE_DELAY])
594 #define IS_JUST_CHANGING(x, y) (ChangeDelay[x][y] != 0)
595 #define IS_CHANGING(x, y) (IS_AUTO_CHANGING(Feld[x][y]) || \
596 IS_JUST_CHANGING(x, y))
598 #define CE_PAGE(e, ce) (element_info[e].event_page[ce])
601 void GetPlayerConfig()
603 if (!audio.sound_available)
604 setup.sound_simple = FALSE;
606 if (!audio.loops_available)
607 setup.sound_loops = FALSE;
609 if (!audio.music_available)
610 setup.sound_music = FALSE;
612 if (!video.fullscreen_available)
613 setup.fullscreen = FALSE;
615 setup.sound = (setup.sound_simple || setup.sound_loops || setup.sound_music);
617 SetAudioMode(setup.sound);
621 static int getBeltNrFromBeltElement(int element)
623 return (element < EL_CONVEYOR_BELT_2_LEFT ? 0 :
624 element < EL_CONVEYOR_BELT_3_LEFT ? 1 :
625 element < EL_CONVEYOR_BELT_4_LEFT ? 2 : 3);
628 static int getBeltNrFromBeltActiveElement(int element)
630 return (element < EL_CONVEYOR_BELT_2_LEFT_ACTIVE ? 0 :
631 element < EL_CONVEYOR_BELT_3_LEFT_ACTIVE ? 1 :
632 element < EL_CONVEYOR_BELT_4_LEFT_ACTIVE ? 2 : 3);
635 static int getBeltNrFromBeltSwitchElement(int element)
637 return (element < EL_CONVEYOR_BELT_2_SWITCH_LEFT ? 0 :
638 element < EL_CONVEYOR_BELT_3_SWITCH_LEFT ? 1 :
639 element < EL_CONVEYOR_BELT_4_SWITCH_LEFT ? 2 : 3);
642 static int getBeltDirNrFromBeltSwitchElement(int element)
644 static int belt_base_element[4] =
646 EL_CONVEYOR_BELT_1_SWITCH_LEFT,
647 EL_CONVEYOR_BELT_2_SWITCH_LEFT,
648 EL_CONVEYOR_BELT_3_SWITCH_LEFT,
649 EL_CONVEYOR_BELT_4_SWITCH_LEFT
652 int belt_nr = getBeltNrFromBeltSwitchElement(element);
653 int belt_dir_nr = element - belt_base_element[belt_nr];
655 return (belt_dir_nr % 3);
658 static int getBeltDirFromBeltSwitchElement(int element)
660 static int belt_move_dir[3] =
667 int belt_dir_nr = getBeltDirNrFromBeltSwitchElement(element);
669 return belt_move_dir[belt_dir_nr];
672 static void InitPlayerField(int x, int y, int element, boolean init_game)
674 if (element == EL_SP_MURPHY)
678 if (stored_player[0].present)
680 Feld[x][y] = EL_SP_MURPHY_CLONE;
686 stored_player[0].use_murphy = TRUE;
689 Feld[x][y] = EL_PLAYER_1;
695 struct PlayerInfo *player = &stored_player[Feld[x][y] - EL_PLAYER_1];
696 int jx = player->jx, jy = player->jy;
698 player->present = TRUE;
700 player->block_last_field = (element == EL_SP_MURPHY ?
701 level.sp_block_last_field :
702 level.block_last_field);
704 /* ---------- initialize player's last field block delay --------------- */
706 /* always start with reliable default value (no adjustment needed) */
707 player->block_delay_adjustment = 0;
709 /* special case 1: in Supaplex, Murphy blocks last field one more frame */
710 if (player->block_last_field && element == EL_SP_MURPHY)
711 player->block_delay_adjustment = 1;
713 /* special case 2: in game engines before 3.1.1, blocking was different */
714 if (game.use_block_last_field_bug)
715 player->block_delay_adjustment = (player->block_last_field ? -1 : 1);
717 if (!options.network || player->connected)
719 player->active = TRUE;
721 /* remove potentially duplicate players */
722 if (StorePlayer[jx][jy] == Feld[x][y])
723 StorePlayer[jx][jy] = 0;
725 StorePlayer[x][y] = Feld[x][y];
729 printf("Player %d activated.\n", player->element_nr);
730 printf("[Local player is %d and currently %s.]\n",
731 local_player->element_nr,
732 local_player->active ? "active" : "not active");
736 Feld[x][y] = EL_EMPTY;
738 player->jx = player->last_jx = x;
739 player->jy = player->last_jy = y;
743 static void InitField(int x, int y, boolean init_game)
745 int element = Feld[x][y];
754 InitPlayerField(x, y, element, init_game);
757 case EL_SOKOBAN_FIELD_PLAYER:
758 element = Feld[x][y] = EL_PLAYER_1;
759 InitField(x, y, init_game);
761 element = Feld[x][y] = EL_SOKOBAN_FIELD_EMPTY;
762 InitField(x, y, init_game);
765 case EL_SOKOBAN_FIELD_EMPTY:
766 local_player->sokobanfields_still_needed++;
770 if (x < lev_fieldx-1 && Feld[x+1][y] == EL_ACID)
771 Feld[x][y] = EL_ACID_POOL_TOPLEFT;
772 else if (x > 0 && Feld[x-1][y] == EL_ACID)
773 Feld[x][y] = EL_ACID_POOL_TOPRIGHT;
774 else if (y > 0 && Feld[x][y-1] == EL_ACID_POOL_TOPLEFT)
775 Feld[x][y] = EL_ACID_POOL_BOTTOMLEFT;
776 else if (y > 0 && Feld[x][y-1] == EL_ACID)
777 Feld[x][y] = EL_ACID_POOL_BOTTOM;
778 else if (y > 0 && Feld[x][y-1] == EL_ACID_POOL_TOPRIGHT)
779 Feld[x][y] = EL_ACID_POOL_BOTTOMRIGHT;
787 case EL_SPACESHIP_RIGHT:
788 case EL_SPACESHIP_UP:
789 case EL_SPACESHIP_LEFT:
790 case EL_SPACESHIP_DOWN:
792 case EL_BD_BUTTERFLY_RIGHT:
793 case EL_BD_BUTTERFLY_UP:
794 case EL_BD_BUTTERFLY_LEFT:
795 case EL_BD_BUTTERFLY_DOWN:
796 case EL_BD_BUTTERFLY:
797 case EL_BD_FIREFLY_RIGHT:
798 case EL_BD_FIREFLY_UP:
799 case EL_BD_FIREFLY_LEFT:
800 case EL_BD_FIREFLY_DOWN:
802 case EL_PACMAN_RIGHT:
826 if (y == lev_fieldy - 1)
828 Feld[x][y] = EL_AMOEBA_GROWING;
829 Store[x][y] = EL_AMOEBA_WET;
833 case EL_DYNAMITE_ACTIVE:
834 case EL_SP_DISK_RED_ACTIVE:
835 case EL_DYNABOMB_PLAYER_1_ACTIVE:
836 case EL_DYNABOMB_PLAYER_2_ACTIVE:
837 case EL_DYNABOMB_PLAYER_3_ACTIVE:
838 case EL_DYNABOMB_PLAYER_4_ACTIVE:
843 local_player->lights_still_needed++;
847 local_player->friends_still_needed++;
852 GfxDir[x][y] = MovDir[x][y] = 1 << RND(4);
855 case EL_CONVEYOR_BELT_1_SWITCH_LEFT:
856 case EL_CONVEYOR_BELT_1_SWITCH_MIDDLE:
857 case EL_CONVEYOR_BELT_1_SWITCH_RIGHT:
858 case EL_CONVEYOR_BELT_2_SWITCH_LEFT:
859 case EL_CONVEYOR_BELT_2_SWITCH_MIDDLE:
860 case EL_CONVEYOR_BELT_2_SWITCH_RIGHT:
861 case EL_CONVEYOR_BELT_3_SWITCH_LEFT:
862 case EL_CONVEYOR_BELT_3_SWITCH_MIDDLE:
863 case EL_CONVEYOR_BELT_3_SWITCH_RIGHT:
864 case EL_CONVEYOR_BELT_4_SWITCH_LEFT:
865 case EL_CONVEYOR_BELT_4_SWITCH_MIDDLE:
866 case EL_CONVEYOR_BELT_4_SWITCH_RIGHT:
869 int belt_nr = getBeltNrFromBeltSwitchElement(Feld[x][y]);
870 int belt_dir = getBeltDirFromBeltSwitchElement(Feld[x][y]);
871 int belt_dir_nr = getBeltDirNrFromBeltSwitchElement(Feld[x][y]);
873 if (game.belt_dir_nr[belt_nr] == 3) /* initial value */
875 game.belt_dir[belt_nr] = belt_dir;
876 game.belt_dir_nr[belt_nr] = belt_dir_nr;
878 else /* more than one switch -- set it like the first switch */
880 Feld[x][y] = Feld[x][y] - belt_dir_nr + game.belt_dir_nr[belt_nr];
885 case EL_SWITCHGATE_SWITCH_DOWN: /* always start with same switch pos */
887 Feld[x][y] = EL_SWITCHGATE_SWITCH_UP;
890 case EL_LIGHT_SWITCH_ACTIVE:
892 game.light_time_left = level.time_light * FRAMES_PER_SECOND;
897 if (IS_CUSTOM_ELEMENT(element))
899 if (CAN_MOVE(element))
902 #if USE_NEW_CUSTOM_VALUE
903 if (!element_info[element].use_last_ce_value || init_game)
904 CustomValue[x][y] = GET_NEW_CUSTOM_VALUE(Feld[x][y]);
908 if (IS_CUSTOM_ELEMENT(element) && CAN_MOVE(element))
911 else if (IS_GROUP_ELEMENT(element))
913 struct ElementGroupInfo *group = element_info[element].group;
914 int last_anim_random_frame = gfx.anim_random_frame;
917 if (group->choice_mode == ANIM_RANDOM)
918 gfx.anim_random_frame = RND(group->num_elements_resolved);
920 element_pos = getAnimationFrame(group->num_elements_resolved, 1,
921 group->choice_mode, 0,
924 if (group->choice_mode == ANIM_RANDOM)
925 gfx.anim_random_frame = last_anim_random_frame;
929 Feld[x][y] = group->element_resolved[element_pos];
931 InitField(x, y, init_game);
938 #if USE_NEW_CUSTOM_VALUE
941 CustomValue[x][y] = GET_NEW_CUSTOM_VALUE(Feld[x][y]);
943 CustomValue[x][y] = element_info[Feld[x][y]].custom_value_initial;
951 static inline void InitField_WithBug1(int x, int y, boolean init_game)
953 InitField(x, y, init_game);
955 /* not needed to call InitMovDir() -- already done by InitField()! */
956 if (game.engine_version < VERSION_IDENT(3,1,0,0) &&
957 CAN_MOVE(Feld[x][y]))
961 static inline void InitField_WithBug2(int x, int y, boolean init_game)
963 int old_element = Feld[x][y];
965 InitField(x, y, init_game);
967 /* not needed to call InitMovDir() -- already done by InitField()! */
968 if (game.engine_version < VERSION_IDENT(3,1,0,0) &&
969 CAN_MOVE(old_element) &&
970 (old_element < EL_MOLE_LEFT || old_element > EL_MOLE_DOWN))
973 /* this case is in fact a combination of not less than three bugs:
974 first, it calls InitMovDir() for elements that can move, although this is
975 already done by InitField(); then, it checks the element that was at this
976 field _before_ the call to InitField() (which can change it); lastly, it
977 was not called for "mole with direction" elements, which were treated as
978 "cannot move" due to (fixed) wrong element initialization in "src/init.c"
982 inline void DrawGameValue_Emeralds(int value)
984 DrawText(DX_EMERALDS, DY_EMERALDS, int2str(value, 3), FONT_TEXT_2);
987 inline void DrawGameValue_Dynamite(int value)
989 DrawText(DX_DYNAMITE, DY_DYNAMITE, int2str(value, 3), FONT_TEXT_2);
992 inline void DrawGameValue_Keys(int key[MAX_NUM_KEYS])
996 /* currently only 4 of 8 possible keys are displayed */
997 for (i = 0; i < STD_NUM_KEYS; i++)
1000 DrawMiniGraphicExt(drawto, DX_KEYS + i * MINI_TILEX, DY_KEYS,
1001 el2edimg(EL_KEY_1 + i));
1003 BlitBitmap(graphic_info[IMG_GLOBAL_DOOR].bitmap, drawto,
1004 DOOR_GFX_PAGEX5 + XX_KEYS + i * MINI_TILEX, YY_KEYS,
1005 MINI_TILEX, MINI_TILEY, DX_KEYS + i * MINI_TILEX, DY_KEYS);
1009 inline void DrawGameValue_Score(int value)
1011 DrawText(DX_SCORE, DY_SCORE, int2str(value, 5), FONT_TEXT_2);
1014 inline void DrawGameValue_Time(int value)
1017 DrawText(DX_TIME1, DY_TIME, int2str(value, 3), FONT_TEXT_2);
1019 DrawText(DX_TIME2, DY_TIME, int2str(value, 4), FONT_LEVEL_NUMBER);
1022 inline void DrawGameValue_Level(int value)
1025 DrawText(DX_LEVEL, DY_LEVEL, int2str(value, 2), FONT_TEXT_2);
1028 /* misuse area for displaying emeralds to draw bigger level number */
1029 DrawTextExt(drawto, DX_EMERALDS, DY_EMERALDS,
1030 int2str(value, 3), FONT_LEVEL_NUMBER, BLIT_OPAQUE);
1032 /* now copy it to the area for displaying level number */
1033 BlitBitmap(drawto, drawto,
1034 DX_EMERALDS, DY_EMERALDS + 1,
1035 getFontWidth(FONT_LEVEL_NUMBER) * 3,
1036 getFontHeight(FONT_LEVEL_NUMBER) - 1,
1037 DX_LEVEL - 1, DY_LEVEL + 1);
1039 /* restore the area for displaying emeralds */
1040 DrawGameValue_Emeralds(local_player->gems_still_needed);
1042 /* yes, this is all really ugly :-) */
1046 void DrawAllGameValues(int emeralds, int dynamite, int score, int time,
1049 int key[MAX_NUM_KEYS];
1052 for (i = 0; i < MAX_NUM_KEYS; i++)
1053 key[i] = key_bits & (1 << i);
1055 DrawGameValue_Level(level_nr);
1057 DrawGameValue_Emeralds(emeralds);
1058 DrawGameValue_Dynamite(dynamite);
1059 DrawGameValue_Score(score);
1060 DrawGameValue_Time(time);
1062 DrawGameValue_Keys(key);
1065 void DrawGameDoorValues()
1069 if (level.game_engine_type == GAME_ENGINE_TYPE_EM)
1071 DrawGameDoorValues_EM();
1076 DrawGameValue_Level(level_nr);
1078 DrawGameValue_Emeralds(local_player->gems_still_needed);
1079 DrawGameValue_Dynamite(local_player->inventory_size);
1080 DrawGameValue_Score(local_player->score);
1081 DrawGameValue_Time(TimeLeft);
1083 for (i = 0; i < MAX_PLAYERS; i++)
1084 DrawGameValue_Keys(stored_player[i].key);
1087 static void resolve_group_element(int group_element, int recursion_depth)
1089 static int group_nr;
1090 static struct ElementGroupInfo *group;
1091 struct ElementGroupInfo *actual_group = element_info[group_element].group;
1094 if (recursion_depth > NUM_GROUP_ELEMENTS) /* recursion too deep */
1096 Error(ERR_WARN, "recursion too deep when resolving group element %d",
1097 group_element - EL_GROUP_START + 1);
1099 /* replace element which caused too deep recursion by question mark */
1100 group->element_resolved[group->num_elements_resolved++] = EL_UNKNOWN;
1105 if (recursion_depth == 0) /* initialization */
1107 group = element_info[group_element].group;
1108 group_nr = group_element - EL_GROUP_START;
1110 group->num_elements_resolved = 0;
1111 group->choice_pos = 0;
1114 for (i = 0; i < actual_group->num_elements; i++)
1116 int element = actual_group->element[i];
1118 if (group->num_elements_resolved == NUM_FILE_ELEMENTS)
1121 if (IS_GROUP_ELEMENT(element))
1122 resolve_group_element(element, recursion_depth + 1);
1125 group->element_resolved[group->num_elements_resolved++] = element;
1126 element_info[element].in_group[group_nr] = TRUE;
1133 =============================================================================
1135 -----------------------------------------------------------------------------
1136 initialize game engine due to level / tape version number
1137 =============================================================================
1140 static void InitGameEngine()
1142 int i, j, k, l, x, y;
1144 /* set game engine from tape file when re-playing, else from level file */
1145 game.engine_version = (tape.playing ? tape.engine_version :
1146 level.game_version);
1148 /* ---------------------------------------------------------------------- */
1149 /* set flags for bugs and changes according to active game engine version */
1150 /* ---------------------------------------------------------------------- */
1153 Summary of bugfix/change:
1154 Fixed handling for custom elements that change when pushed by the player.
1156 Fixed/changed in version:
1160 Before 3.1.0, custom elements that "change when pushing" changed directly
1161 after the player started pushing them (until then handled in "DigField()").
1162 Since 3.1.0, these custom elements are not changed until the "pushing"
1163 move of the element is finished (now handled in "ContinueMoving()").
1165 Affected levels/tapes:
1166 The first condition is generally needed for all levels/tapes before version
1167 3.1.0, which might use the old behaviour before it was changed; known tapes
1168 that are affected are some tapes from the level set "Walpurgis Gardens" by
1170 The second condition is an exception from the above case and is needed for
1171 the special case of tapes recorded with game (not engine!) version 3.1.0 or
1172 above (including some development versions of 3.1.0), but before it was
1173 known that this change would break tapes like the above and was fixed in
1174 3.1.1, so that the changed behaviour was active although the engine version
1175 while recording maybe was before 3.1.0. There is at least one tape that is
1176 affected by this exception, which is the tape for the one-level set "Bug
1177 Machine" by Juergen Bonhagen.
1180 game.use_change_when_pushing_bug =
1181 (game.engine_version < VERSION_IDENT(3,1,0,0) &&
1183 tape.game_version >= VERSION_IDENT(3,1,0,0) &&
1184 tape.game_version < VERSION_IDENT(3,1,1,0)));
1187 Summary of bugfix/change:
1188 Fixed handling for blocking the field the player leaves when moving.
1190 Fixed/changed in version:
1194 Before 3.1.1, when "block last field when moving" was enabled, the field
1195 the player is leaving when moving was blocked for the time of the move,
1196 and was directly unblocked afterwards. This resulted in the last field
1197 being blocked for exactly one less than the number of frames of one player
1198 move. Additionally, even when blocking was disabled, the last field was
1199 blocked for exactly one frame.
1200 Since 3.1.1, due to changes in player movement handling, the last field
1201 is not blocked at all when blocking is disabled. When blocking is enabled,
1202 the last field is blocked for exactly the number of frames of one player
1203 move. Additionally, if the player is Murphy, the hero of Supaplex, the
1204 last field is blocked for exactly one more than the number of frames of
1207 Affected levels/tapes:
1208 (!!! yet to be determined -- probably many !!!)
1211 game.use_block_last_field_bug =
1212 (game.engine_version < VERSION_IDENT(3,1,1,0));
1215 Summary of bugfix/change:
1216 Changed behaviour of CE changes with multiple changes per single frame.
1218 Fixed/changed in version:
1222 Before 3.2.0-6, only one single CE change was allowed in each engine frame.
1223 This resulted in race conditions where CEs seem to behave strange in some
1224 situations (where triggered CE changes were just skipped because there was
1225 already a CE change on that tile in the playfield in that engine frame).
1226 Since 3.2.0-6, this was changed to allow up to MAX_NUM_CHANGES_PER_FRAME.
1227 (The number of changes per frame must be limited in any case, because else
1228 it is easily possible to define CE changes that would result in an infinite
1229 loop, causing the whole game to freeze. The MAX_NUM_CHANGES_PER_FRAME value
1230 should be set large enough so that it would only be reached in cases where
1231 the corresponding CE change conditions run into a loop. Therefore, it seems
1232 to be reasonable to set MAX_NUM_CHANGES_PER_FRAME to the same value as the
1233 maximal number of change pages for custom elements.)
1235 Affected levels/tapes:
1239 #if USE_ONLY_ONE_CHANGE_PER_FRAME
1240 game.max_num_changes_per_frame = 1;
1242 game.max_num_changes_per_frame =
1243 (game.engine_version < VERSION_IDENT(3,2,0,6) ? 1 : 32);
1246 /* ---------------------------------------------------------------------- */
1248 /* dynamically adjust element properties according to game engine version */
1249 InitElementPropertiesEngine(game.engine_version);
1252 printf("level %d: level version == %06d\n", level_nr, level.game_version);
1253 printf(" tape version == %06d [%s] [file: %06d]\n",
1254 tape.engine_version, (tape.playing ? "PLAYING" : "RECORDING"),
1256 printf(" => game.engine_version == %06d\n", game.engine_version);
1259 /* ---------- recursively resolve group elements ------------------------- */
1261 for (i = 0; i < MAX_NUM_ELEMENTS; i++)
1262 for (j = 0; j < NUM_GROUP_ELEMENTS; j++)
1263 element_info[i].in_group[j] = FALSE;
1265 for (i = 0; i < NUM_GROUP_ELEMENTS; i++)
1266 resolve_group_element(EL_GROUP_START + i, 0);
1268 /* ---------- initialize player's initial move delay --------------------- */
1270 /* dynamically adjust player properties according to level information */
1271 game.initial_move_delay_value =
1272 (level.double_speed ? MOVE_DELAY_HIGH_SPEED : MOVE_DELAY_NORMAL_SPEED);
1274 /* dynamically adjust player properties according to game engine version */
1275 game.initial_move_delay = (game.engine_version <= VERSION_IDENT(2,0,1,0) ?
1276 game.initial_move_delay_value : 0);
1278 /* ---------- initialize player's initial push delay --------------------- */
1280 /* dynamically adjust player properties according to game engine version */
1281 game.initial_push_delay_value =
1282 (game.engine_version < VERSION_IDENT(3,0,7,1) ? 5 : -1);
1284 /* ---------- initialize changing elements ------------------------------- */
1286 /* initialize changing elements information */
1287 for (i = 0; i < MAX_NUM_ELEMENTS; i++)
1289 struct ElementInfo *ei = &element_info[i];
1291 /* this pointer might have been changed in the level editor */
1292 ei->change = &ei->change_page[0];
1294 if (!IS_CUSTOM_ELEMENT(i))
1296 ei->change->target_element = EL_EMPTY_SPACE;
1297 ei->change->delay_fixed = 0;
1298 ei->change->delay_random = 0;
1299 ei->change->delay_frames = 1;
1302 for (j = 0; j < NUM_CHANGE_EVENTS; j++)
1304 ei->has_change_event[j] = FALSE;
1306 ei->event_page_nr[j] = 0;
1307 ei->event_page[j] = &ei->change_page[0];
1311 /* add changing elements from pre-defined list */
1312 for (i = 0; change_delay_list[i].element != EL_UNDEFINED; i++)
1314 struct ChangingElementInfo *ch_delay = &change_delay_list[i];
1315 struct ElementInfo *ei = &element_info[ch_delay->element];
1317 ei->change->target_element = ch_delay->target_element;
1318 ei->change->delay_fixed = ch_delay->change_delay;
1320 ei->change->pre_change_function = ch_delay->pre_change_function;
1321 ei->change->change_function = ch_delay->change_function;
1322 ei->change->post_change_function = ch_delay->post_change_function;
1324 ei->change->can_change = TRUE;
1325 ei->change->can_change_or_has_action = TRUE;
1327 ei->has_change_event[CE_DELAY] = TRUE;
1329 SET_PROPERTY(ch_delay->element, EP_CAN_CHANGE, TRUE);
1330 SET_PROPERTY(ch_delay->element, EP_CAN_CHANGE_OR_HAS_ACTION, TRUE);
1333 /* ---------- initialize internal run-time variables ------------- */
1335 for (i = 0; i < NUM_CUSTOM_ELEMENTS; i++)
1337 struct ElementInfo *ei = &element_info[EL_CUSTOM_START + i];
1339 for (j = 0; j < ei->num_change_pages; j++)
1341 ei->change_page[j].can_change_or_has_action =
1342 (ei->change_page[j].can_change |
1343 ei->change_page[j].has_action);
1347 /* add change events from custom element configuration */
1348 for (i = 0; i < NUM_CUSTOM_ELEMENTS; i++)
1350 struct ElementInfo *ei = &element_info[EL_CUSTOM_START + i];
1352 for (j = 0; j < ei->num_change_pages; j++)
1354 if (!ei->change_page[j].can_change_or_has_action)
1357 for (k = 0; k < NUM_CHANGE_EVENTS; k++)
1359 /* only add event page for the first page found with this event */
1360 if (ei->change_page[j].has_event[k] && !(ei->has_change_event[k]))
1362 ei->has_change_event[k] = TRUE;
1364 ei->event_page_nr[k] = j;
1365 ei->event_page[k] = &ei->change_page[j];
1371 /* ---------- initialize run-time trigger player and element ------------- */
1373 for (i = 0; i < NUM_CUSTOM_ELEMENTS; i++)
1375 struct ElementInfo *ei = &element_info[EL_CUSTOM_START + i];
1377 for (j = 0; j < ei->num_change_pages; j++)
1379 ei->change_page[j].actual_trigger_element = EL_EMPTY;
1380 ei->change_page[j].actual_trigger_player = EL_PLAYER_1;
1381 ei->change_page[j].actual_trigger_side = CH_SIDE_NONE;
1382 ei->change_page[j].actual_trigger_ce_value = 0;
1386 /* ---------- initialize trigger events ---------------------------------- */
1388 /* initialize trigger events information */
1389 for (i = 0; i < MAX_NUM_ELEMENTS; i++)
1390 for (j = 0; j < NUM_CHANGE_EVENTS; j++)
1391 trigger_events[i][j] = FALSE;
1393 /* add trigger events from element change event properties */
1394 for (i = 0; i < MAX_NUM_ELEMENTS; i++)
1396 struct ElementInfo *ei = &element_info[i];
1398 for (j = 0; j < ei->num_change_pages; j++)
1400 if (!ei->change_page[j].can_change_or_has_action)
1403 if (ei->change_page[j].has_event[CE_BY_OTHER_ACTION])
1405 int trigger_element = ei->change_page[j].trigger_element;
1407 for (k = 0; k < NUM_CHANGE_EVENTS; k++)
1409 if (ei->change_page[j].has_event[k])
1411 if (IS_GROUP_ELEMENT(trigger_element))
1413 struct ElementGroupInfo *group =
1414 element_info[trigger_element].group;
1416 for (l = 0; l < group->num_elements_resolved; l++)
1417 trigger_events[group->element_resolved[l]][k] = TRUE;
1420 trigger_events[trigger_element][k] = TRUE;
1427 /* ---------- initialize push delay -------------------------------------- */
1429 /* initialize push delay values to default */
1430 for (i = 0; i < MAX_NUM_ELEMENTS; i++)
1432 if (!IS_CUSTOM_ELEMENT(i))
1434 element_info[i].push_delay_fixed = game.default_push_delay_fixed;
1435 element_info[i].push_delay_random = game.default_push_delay_random;
1439 /* set push delay value for certain elements from pre-defined list */
1440 for (i = 0; push_delay_list[i].element != EL_UNDEFINED; i++)
1442 int e = push_delay_list[i].element;
1444 element_info[e].push_delay_fixed = push_delay_list[i].push_delay_fixed;
1445 element_info[e].push_delay_random = push_delay_list[i].push_delay_random;
1448 /* set push delay value for Supaplex elements for newer engine versions */
1449 if (game.engine_version >= VERSION_IDENT(3,1,0,0))
1451 for (i = 0; i < MAX_NUM_ELEMENTS; i++)
1453 if (IS_SP_ELEMENT(i))
1455 /* set SP push delay to just enough to push under a falling zonk */
1456 int delay = (game.engine_version >= VERSION_IDENT(3,1,1,0) ? 8 : 6);
1458 element_info[i].push_delay_fixed = delay;
1459 element_info[i].push_delay_random = 0;
1464 /* ---------- initialize move stepsize ----------------------------------- */
1466 /* initialize move stepsize values to default */
1467 for (i = 0; i < MAX_NUM_ELEMENTS; i++)
1468 if (!IS_CUSTOM_ELEMENT(i))
1469 element_info[i].move_stepsize = MOVE_STEPSIZE_NORMAL;
1471 /* set move stepsize value for certain elements from pre-defined list */
1472 for (i = 0; move_stepsize_list[i].element != EL_UNDEFINED; i++)
1474 int e = move_stepsize_list[i].element;
1476 element_info[e].move_stepsize = move_stepsize_list[i].move_stepsize;
1479 /* ---------- initialize collect score ----------------------------------- */
1481 /* initialize collect score values for custom elements from initial value */
1482 for (i = 0; i < MAX_NUM_ELEMENTS; i++)
1483 if (IS_CUSTOM_ELEMENT(i))
1484 element_info[i].collect_score = element_info[i].collect_score_initial;
1486 /* ---------- initialize collect count ----------------------------------- */
1488 /* initialize collect count values for non-custom elements */
1489 for (i = 0; i < MAX_NUM_ELEMENTS; i++)
1490 if (!IS_CUSTOM_ELEMENT(i))
1491 element_info[i].collect_count_initial = 0;
1493 /* add collect count values for all elements from pre-defined list */
1494 for (i = 0; collect_count_list[i].element != EL_UNDEFINED; i++)
1495 element_info[collect_count_list[i].element].collect_count_initial =
1496 collect_count_list[i].count;
1498 /* ---------- initialize access direction -------------------------------- */
1500 /* initialize access direction values to default (access from every side) */
1501 for (i = 0; i < MAX_NUM_ELEMENTS; i++)
1502 if (!IS_CUSTOM_ELEMENT(i))
1503 element_info[i].access_direction = MV_ALL_DIRECTIONS;
1505 /* set access direction value for certain elements from pre-defined list */
1506 for (i = 0; access_direction_list[i].element != EL_UNDEFINED; i++)
1507 element_info[access_direction_list[i].element].access_direction =
1508 access_direction_list[i].direction;
1510 /* ---------- initialize explosion content ------------------------------- */
1511 for (i = 0; i < MAX_NUM_ELEMENTS; i++)
1513 if (IS_CUSTOM_ELEMENT(i))
1516 for (y = 0; y < 3; y++) for (x = 0; x < 3; x++)
1518 /* (content for EL_YAMYAM set at run-time with game.yamyam_content_nr) */
1520 element_info[i].content.e[x][y] =
1521 (i == EL_PLAYER_1 ? EL_EMERALD_YELLOW :
1522 i == EL_PLAYER_2 ? EL_EMERALD_RED :
1523 i == EL_PLAYER_3 ? EL_EMERALD :
1524 i == EL_PLAYER_4 ? EL_EMERALD_PURPLE :
1525 i == EL_MOLE ? EL_EMERALD_RED :
1526 i == EL_PENGUIN ? EL_EMERALD_PURPLE :
1527 i == EL_BUG ? (x == 1 && y == 1 ? EL_DIAMOND : EL_EMERALD) :
1528 i == EL_BD_BUTTERFLY ? EL_BD_DIAMOND :
1529 i == EL_SP_ELECTRON ? EL_SP_INFOTRON :
1530 i == EL_AMOEBA_TO_DIAMOND ? level.amoeba_content :
1531 i == EL_YAMYAM ? EL_UNDEFINED :
1532 i == EL_WALL_EMERALD ? EL_EMERALD :
1533 i == EL_WALL_DIAMOND ? EL_DIAMOND :
1534 i == EL_WALL_BD_DIAMOND ? EL_BD_DIAMOND :
1535 i == EL_WALL_EMERALD_YELLOW ? EL_EMERALD_YELLOW :
1536 i == EL_WALL_EMERALD_RED ? EL_EMERALD_RED :
1537 i == EL_WALL_EMERALD_PURPLE ? EL_EMERALD_PURPLE :
1538 i == EL_WALL_PEARL ? EL_PEARL :
1539 i == EL_WALL_CRYSTAL ? EL_CRYSTAL :
1545 int get_num_special_action(int element, int action_first, int action_last)
1547 int num_special_action = 0;
1550 for (i = action_first; i <= action_last; i++)
1552 boolean found = FALSE;
1554 for (j = 0; j < NUM_DIRECTIONS; j++)
1555 if (el_act_dir2img(element, i, j) !=
1556 el_act_dir2img(element, ACTION_DEFAULT, j))
1560 num_special_action++;
1565 return num_special_action;
1569 =============================================================================
1571 -----------------------------------------------------------------------------
1572 initialize and start new game
1573 =============================================================================
1578 boolean emulate_bd = TRUE; /* unless non-BOULDERDASH elements found */
1579 boolean emulate_sb = TRUE; /* unless non-SOKOBAN elements found */
1580 boolean emulate_sp = TRUE; /* unless non-SUPAPLEX elements found */
1585 /* don't play tapes over network */
1586 network_playing = (options.network && !tape.playing);
1588 for (i = 0; i < MAX_PLAYERS; i++)
1590 struct PlayerInfo *player = &stored_player[i];
1592 player->index_nr = i;
1593 player->index_bit = (1 << i);
1594 player->element_nr = EL_PLAYER_1 + i;
1596 player->present = FALSE;
1597 player->active = FALSE;
1600 player->effective_action = 0;
1601 player->programmed_action = 0;
1604 player->gems_still_needed = level.gems_needed;
1605 player->sokobanfields_still_needed = 0;
1606 player->lights_still_needed = 0;
1607 player->friends_still_needed = 0;
1609 for (j = 0; j < MAX_NUM_KEYS; j++)
1610 player->key[j] = FALSE;
1612 player->dynabomb_count = 0;
1613 player->dynabomb_size = 1;
1614 player->dynabombs_left = 0;
1615 player->dynabomb_xl = FALSE;
1617 player->MovDir = MV_NONE;
1620 player->GfxDir = MV_NONE;
1621 player->GfxAction = ACTION_DEFAULT;
1623 player->StepFrame = 0;
1625 player->use_murphy = FALSE;
1626 player->artwork_element =
1627 (level.use_artwork_element[i] ? level.artwork_element[i] :
1628 player->element_nr);
1630 player->block_last_field = FALSE; /* initialized in InitPlayerField() */
1631 player->block_delay_adjustment = 0; /* initialized in InitPlayerField() */
1633 player->can_fall_into_acid = CAN_MOVE_INTO_ACID(player->element_nr);
1635 player->actual_frame_counter = 0;
1637 player->step_counter = 0;
1639 player->last_move_dir = MV_NONE;
1641 player->is_waiting = FALSE;
1642 player->is_moving = FALSE;
1643 player->is_auto_moving = FALSE;
1644 player->is_digging = FALSE;
1645 player->is_snapping = FALSE;
1646 player->is_collecting = FALSE;
1647 player->is_pushing = FALSE;
1648 player->is_switching = FALSE;
1649 player->is_dropping = FALSE;
1651 player->is_bored = FALSE;
1652 player->is_sleeping = FALSE;
1654 player->cannot_move = FALSE;
1656 player->frame_counter_bored = -1;
1657 player->frame_counter_sleeping = -1;
1659 player->anim_delay_counter = 0;
1660 player->post_delay_counter = 0;
1662 player->action_waiting = ACTION_DEFAULT;
1663 player->last_action_waiting = ACTION_DEFAULT;
1664 player->special_action_bored = ACTION_DEFAULT;
1665 player->special_action_sleeping = ACTION_DEFAULT;
1667 /* set number of special actions for bored and sleeping animation */
1668 player->num_special_action_bored =
1669 get_num_special_action(player->artwork_element,
1670 ACTION_BORING_1, ACTION_BORING_LAST);
1671 player->num_special_action_sleeping =
1672 get_num_special_action(player->artwork_element,
1673 ACTION_SLEEPING_1, ACTION_SLEEPING_LAST);
1675 player->switch_x = -1;
1676 player->switch_y = -1;
1678 player->drop_x = -1;
1679 player->drop_y = -1;
1681 player->show_envelope = 0;
1683 player->move_delay = game.initial_move_delay;
1684 player->move_delay_value = game.initial_move_delay_value;
1686 player->move_delay_value_next = -1;
1688 player->move_delay_reset_counter = 0;
1690 player->push_delay = -1; /* initialized when pushing starts */
1691 player->push_delay_value = game.initial_push_delay_value;
1693 player->drop_delay = 0;
1695 player->last_jx = player->last_jy = 0;
1696 player->jx = player->jy = 0;
1698 player->shield_normal_time_left = 0;
1699 player->shield_deadly_time_left = 0;
1701 player->inventory_infinite_element = EL_UNDEFINED;
1702 player->inventory_size = 0;
1704 DigField(player, 0, 0, 0, 0, 0, 0, DF_NO_PUSH);
1705 SnapField(player, 0, 0);
1707 player->LevelSolved = FALSE;
1708 player->GameOver = FALSE;
1711 network_player_action_received = FALSE;
1713 #if defined(NETWORK_AVALIABLE)
1714 /* initial null action */
1715 if (network_playing)
1716 SendToServer_MovePlayer(MV_NONE);
1725 TimeLeft = level.time;
1728 ScreenMovDir = MV_NONE;
1732 ScrollStepSize = 0; /* will be correctly initialized by ScrollScreen() */
1734 AllPlayersGone = FALSE;
1736 game.yamyam_content_nr = 0;
1737 game.magic_wall_active = FALSE;
1738 game.magic_wall_time_left = 0;
1739 game.light_time_left = 0;
1740 game.timegate_time_left = 0;
1741 game.switchgate_pos = 0;
1742 game.wind_direction = level.wind_direction_initial;
1743 game.gravity = level.initial_gravity;
1744 game.explosions_delayed = TRUE;
1746 game.lenses_time_left = 0;
1747 game.magnify_time_left = 0;
1749 game.envelope_active = FALSE;
1751 for (i = 0; i < NUM_BELTS; i++)
1753 game.belt_dir[i] = MV_NONE;
1754 game.belt_dir_nr[i] = 3; /* not moving, next moving left */
1757 for (i = 0; i < MAX_NUM_AMOEBA; i++)
1758 AmoebaCnt[i] = AmoebaCnt2[i] = 0;
1760 for (x = 0; x < lev_fieldx; x++)
1762 for (y = 0; y < lev_fieldy; y++)
1764 Feld[x][y] = level.field[x][y];
1765 MovPos[x][y] = MovDir[x][y] = MovDelay[x][y] = 0;
1766 ChangeDelay[x][y] = 0;
1767 ChangePage[x][y] = -1;
1768 #if USE_NEW_CUSTOM_VALUE
1769 CustomValue[x][y] = 0; /* initialized in InitField() */
1771 Store[x][y] = Store2[x][y] = StorePlayer[x][y] = Back[x][y] = 0;
1773 WasJustMoving[x][y] = 0;
1774 WasJustFalling[x][y] = 0;
1775 CheckCollision[x][y] = 0;
1777 Pushed[x][y] = FALSE;
1780 ChangeEvent[x][y] = -1;
1782 ExplodePhase[x][y] = 0;
1783 ExplodeDelay[x][y] = 0;
1784 ExplodeField[x][y] = EX_TYPE_NONE;
1786 RunnerVisit[x][y] = 0;
1787 PlayerVisit[x][y] = 0;
1790 GfxRandom[x][y] = INIT_GFX_RANDOM();
1791 GfxElement[x][y] = EL_UNDEFINED;
1792 GfxAction[x][y] = ACTION_DEFAULT;
1793 GfxDir[x][y] = MV_NONE;
1797 for (y = 0; y < lev_fieldy; y++)
1799 for (x = 0; x < lev_fieldx; x++)
1801 if (emulate_bd && !IS_BD_ELEMENT(Feld[x][y]))
1803 if (emulate_sb && !IS_SB_ELEMENT(Feld[x][y]))
1805 if (emulate_sp && !IS_SP_ELEMENT(Feld[x][y]))
1808 InitField(x, y, TRUE);
1814 game.emulation = (emulate_bd ? EMU_BOULDERDASH :
1815 emulate_sb ? EMU_SOKOBAN :
1816 emulate_sp ? EMU_SUPAPLEX : EMU_NONE);
1818 #if USE_NEW_ALL_SLIPPERY
1819 /* initialize type of slippery elements */
1820 for (i = 0; i < MAX_NUM_ELEMENTS; i++)
1822 if (!IS_CUSTOM_ELEMENT(i))
1824 /* default: elements slip down either to the left or right randomly */
1825 element_info[i].slippery_type = SLIPPERY_ANY_RANDOM;
1827 /* SP style elements prefer to slip down on the left side */
1828 if (game.engine_version >= VERSION_IDENT(3,1,1,0) && IS_SP_ELEMENT(i))
1829 element_info[i].slippery_type = SLIPPERY_ANY_LEFT_RIGHT;
1831 /* BD style elements prefer to slip down on the left side */
1832 if (game.emulation == EMU_BOULDERDASH)
1833 element_info[i].slippery_type = SLIPPERY_ANY_LEFT_RIGHT;
1838 /* initialize explosion and ignition delay */
1839 for (i = 0; i < MAX_NUM_ELEMENTS; i++)
1841 if (!IS_CUSTOM_ELEMENT(i))
1844 int delay = (((IS_SP_ELEMENT(i) && i != EL_EMPTY_SPACE) &&
1845 game.engine_version >= VERSION_IDENT(3,1,0,0)) ||
1846 game.emulation == EMU_SUPAPLEX ? 3 : 2);
1847 int last_phase = (num_phase + 1) * delay;
1848 int half_phase = (num_phase / 2) * delay;
1850 element_info[i].explosion_delay = last_phase - 1;
1851 element_info[i].ignition_delay = half_phase;
1853 if (i == EL_BLACK_ORB)
1854 element_info[i].ignition_delay = 1;
1858 if (element_info[i].explosion_delay < 1) /* !!! check again !!! */
1859 element_info[i].explosion_delay = 1;
1861 if (element_info[i].ignition_delay < 1) /* !!! check again !!! */
1862 element_info[i].ignition_delay = 1;
1866 /* correct non-moving belts to start moving left */
1867 for (i = 0; i < NUM_BELTS; i++)
1868 if (game.belt_dir[i] == MV_NONE)
1869 game.belt_dir_nr[i] = 3; /* not moving, next moving left */
1871 /* check if any connected player was not found in playfield */
1872 for (i = 0; i < MAX_PLAYERS; i++)
1874 struct PlayerInfo *player = &stored_player[i];
1876 if (player->connected && !player->present)
1878 for (j = 0; j < MAX_PLAYERS; j++)
1880 struct PlayerInfo *some_player = &stored_player[j];
1881 int jx = some_player->jx, jy = some_player->jy;
1883 /* assign first free player found that is present in the playfield */
1884 if (some_player->present && !some_player->connected)
1886 player->present = TRUE;
1887 player->active = TRUE;
1889 some_player->present = FALSE;
1890 some_player->active = FALSE;
1893 player->element_nr = some_player->element_nr;
1896 player->artwork_element = some_player->artwork_element;
1898 player->block_last_field = some_player->block_last_field;
1899 player->block_delay_adjustment = some_player->block_delay_adjustment;
1901 StorePlayer[jx][jy] = player->element_nr;
1902 player->jx = player->last_jx = jx;
1903 player->jy = player->last_jy = jy;
1913 /* when playing a tape, eliminate all players which do not participate */
1915 for (i = 0; i < MAX_PLAYERS; i++)
1917 if (stored_player[i].active && !tape.player_participates[i])
1919 struct PlayerInfo *player = &stored_player[i];
1920 int jx = player->jx, jy = player->jy;
1922 player->active = FALSE;
1923 StorePlayer[jx][jy] = 0;
1924 Feld[jx][jy] = EL_EMPTY;
1928 else if (!options.network && !setup.team_mode) /* && !tape.playing */
1930 /* when in single player mode, eliminate all but the first active player */
1932 for (i = 0; i < MAX_PLAYERS; i++)
1934 if (stored_player[i].active)
1936 for (j = i + 1; j < MAX_PLAYERS; j++)
1938 if (stored_player[j].active)
1940 struct PlayerInfo *player = &stored_player[j];
1941 int jx = player->jx, jy = player->jy;
1943 player->active = FALSE;
1944 player->present = FALSE;
1946 StorePlayer[jx][jy] = 0;
1947 Feld[jx][jy] = EL_EMPTY;
1954 /* when recording the game, store which players take part in the game */
1957 for (i = 0; i < MAX_PLAYERS; i++)
1958 if (stored_player[i].active)
1959 tape.player_participates[i] = TRUE;
1964 for (i = 0; i < MAX_PLAYERS; i++)
1966 struct PlayerInfo *player = &stored_player[i];
1968 printf("Player %d: present == %d, connected == %d, active == %d.\n",
1973 if (local_player == player)
1974 printf("Player %d is local player.\n", i+1);
1978 if (BorderElement == EL_EMPTY)
1981 SBX_Right = lev_fieldx - SCR_FIELDX;
1983 SBY_Lower = lev_fieldy - SCR_FIELDY;
1988 SBX_Right = lev_fieldx - SCR_FIELDX + 1;
1990 SBY_Lower = lev_fieldy - SCR_FIELDY + 1;
1993 if (lev_fieldx + (SBX_Left == -1 ? 2 : 0) <= SCR_FIELDX)
1994 SBX_Left = SBX_Right = -1 * (SCR_FIELDX - lev_fieldx) / 2;
1996 if (lev_fieldy + (SBY_Upper == -1 ? 2 : 0) <= SCR_FIELDY)
1997 SBY_Upper = SBY_Lower = -1 * (SCR_FIELDY - lev_fieldy) / 2;
1999 /* if local player not found, look for custom element that might create
2000 the player (make some assumptions about the right custom element) */
2001 if (!local_player->present)
2003 int start_x = 0, start_y = 0;
2004 int found_rating = 0;
2005 int found_element = EL_UNDEFINED;
2006 int player_nr = local_player->index_nr;
2008 for (y = 0; y < lev_fieldy; y++) for (x = 0; x < lev_fieldx; x++)
2010 int element = Feld[x][y];
2015 if (level.use_start_element[player_nr] &&
2016 level.start_element[player_nr] == element &&
2023 found_element = element;
2026 if (!IS_CUSTOM_ELEMENT(element))
2029 if (CAN_CHANGE(element))
2031 for (i = 0; i < element_info[element].num_change_pages; i++)
2033 /* check for player created from custom element as single target */
2034 content = element_info[element].change_page[i].target_element;
2035 is_player = ELEM_IS_PLAYER(content);
2037 if (is_player && (found_rating < 3 || element < found_element))
2043 found_element = element;
2048 for (yy = 0; yy < 3; yy++) for (xx = 0; xx < 3; xx++)
2050 /* check for player created from custom element as explosion content */
2051 content = element_info[element].content.e[xx][yy];
2052 is_player = ELEM_IS_PLAYER(content);
2054 if (is_player && (found_rating < 2 || element < found_element))
2056 start_x = x + xx - 1;
2057 start_y = y + yy - 1;
2060 found_element = element;
2063 if (!CAN_CHANGE(element))
2066 for (i = 0; i < element_info[element].num_change_pages; i++)
2068 /* check for player created from custom element as extended target */
2070 element_info[element].change_page[i].target_content.e[xx][yy];
2072 is_player = ELEM_IS_PLAYER(content);
2074 if (is_player && (found_rating < 1 || element < found_element))
2076 start_x = x + xx - 1;
2077 start_y = y + yy - 1;
2080 found_element = element;
2086 scroll_x = (start_x < SBX_Left + MIDPOSX ? SBX_Left :
2087 start_x > SBX_Right + MIDPOSX ? SBX_Right :
2090 scroll_y = (start_y < SBY_Upper + MIDPOSY ? SBY_Upper :
2091 start_y > SBY_Lower + MIDPOSY ? SBY_Lower :
2096 scroll_x = (local_player->jx < SBX_Left + MIDPOSX ? SBX_Left :
2097 local_player->jx > SBX_Right + MIDPOSX ? SBX_Right :
2098 local_player->jx - MIDPOSX);
2100 scroll_y = (local_player->jy < SBY_Upper + MIDPOSY ? SBY_Upper :
2101 local_player->jy > SBY_Lower + MIDPOSY ? SBY_Lower :
2102 local_player->jy - MIDPOSY);
2105 if (!game.restart_level)
2106 CloseDoor(DOOR_CLOSE_1);
2108 /* !!! FIX THIS (START) !!! */
2109 if (level.game_engine_type == GAME_ENGINE_TYPE_EM)
2111 InitGameEngine_EM();
2118 /* after drawing the level, correct some elements */
2119 if (game.timegate_time_left == 0)
2120 CloseAllOpenTimegates();
2122 if (setup.soft_scrolling)
2123 BlitBitmap(fieldbuffer, backbuffer, FX, FY, SXSIZE, SYSIZE, SX, SY);
2125 redraw_mask |= REDRAW_FROM_BACKBUFFER;
2128 /* !!! FIX THIS (END) !!! */
2130 if (!game.restart_level)
2132 /* copy default game door content to main double buffer */
2133 BlitBitmap(graphic_info[IMG_GLOBAL_DOOR].bitmap, drawto,
2134 DOOR_GFX_PAGEX5, DOOR_GFX_PAGEY1, DXSIZE, DYSIZE, DX, DY);
2137 DrawGameDoorValues();
2139 if (!game.restart_level)
2143 game_gadget[SOUND_CTRL_ID_MUSIC]->checked = setup.sound_music;
2144 game_gadget[SOUND_CTRL_ID_LOOPS]->checked = setup.sound_loops;
2145 game_gadget[SOUND_CTRL_ID_SIMPLE]->checked = setup.sound_simple;
2149 /* copy actual game door content to door double buffer for OpenDoor() */
2150 BlitBitmap(drawto, bitmap_db_door,
2151 DX, DY, DXSIZE, DYSIZE, DOOR_GFX_PAGEX1, DOOR_GFX_PAGEY1);
2153 OpenDoor(DOOR_OPEN_ALL);
2155 PlaySoundStereo(SND_GAME_STARTING, SOUND_MIDDLE);
2157 if (setup.sound_music)
2160 KeyboardAutoRepeatOffUnlessAutoplay();
2164 for (i = 0; i < MAX_PLAYERS; i++)
2165 printf("Player %d %sactive.\n",
2166 i + 1, (stored_player[i].active ? "" : "not "));
2170 game.restart_level = FALSE;
2173 void UpdateEngineValues(int actual_scroll_x, int actual_scroll_y)
2175 /* this is used for non-R'n'D game engines to update certain engine values */
2177 /* needed to determine if sounds are played within the visible screen area */
2178 scroll_x = actual_scroll_x;
2179 scroll_y = actual_scroll_y;
2182 void InitMovDir(int x, int y)
2184 int i, element = Feld[x][y];
2185 static int xy[4][2] =
2192 static int direction[3][4] =
2194 { MV_RIGHT, MV_UP, MV_LEFT, MV_DOWN },
2195 { MV_LEFT, MV_DOWN, MV_RIGHT, MV_UP },
2196 { MV_LEFT, MV_RIGHT, MV_UP, MV_DOWN }
2205 Feld[x][y] = EL_BUG;
2206 MovDir[x][y] = direction[0][element - EL_BUG_RIGHT];
2209 case EL_SPACESHIP_RIGHT:
2210 case EL_SPACESHIP_UP:
2211 case EL_SPACESHIP_LEFT:
2212 case EL_SPACESHIP_DOWN:
2213 Feld[x][y] = EL_SPACESHIP;
2214 MovDir[x][y] = direction[0][element - EL_SPACESHIP_RIGHT];
2217 case EL_BD_BUTTERFLY_RIGHT:
2218 case EL_BD_BUTTERFLY_UP:
2219 case EL_BD_BUTTERFLY_LEFT:
2220 case EL_BD_BUTTERFLY_DOWN:
2221 Feld[x][y] = EL_BD_BUTTERFLY;
2222 MovDir[x][y] = direction[0][element - EL_BD_BUTTERFLY_RIGHT];
2225 case EL_BD_FIREFLY_RIGHT:
2226 case EL_BD_FIREFLY_UP:
2227 case EL_BD_FIREFLY_LEFT:
2228 case EL_BD_FIREFLY_DOWN:
2229 Feld[x][y] = EL_BD_FIREFLY;
2230 MovDir[x][y] = direction[0][element - EL_BD_FIREFLY_RIGHT];
2233 case EL_PACMAN_RIGHT:
2235 case EL_PACMAN_LEFT:
2236 case EL_PACMAN_DOWN:
2237 Feld[x][y] = EL_PACMAN;
2238 MovDir[x][y] = direction[0][element - EL_PACMAN_RIGHT];
2241 case EL_SP_SNIKSNAK:
2242 MovDir[x][y] = MV_UP;
2245 case EL_SP_ELECTRON:
2246 MovDir[x][y] = MV_LEFT;
2253 Feld[x][y] = EL_MOLE;
2254 MovDir[x][y] = direction[2][element - EL_MOLE_LEFT];
2258 if (IS_CUSTOM_ELEMENT(element))
2260 struct ElementInfo *ei = &element_info[element];
2261 int move_direction_initial = ei->move_direction_initial;
2262 int move_pattern = ei->move_pattern;
2264 if (move_direction_initial == MV_START_PREVIOUS)
2266 if (MovDir[x][y] != MV_NONE)
2269 move_direction_initial = MV_START_AUTOMATIC;
2272 if (move_direction_initial == MV_START_RANDOM)
2273 MovDir[x][y] = 1 << RND(4);
2274 else if (move_direction_initial & MV_ANY_DIRECTION)
2275 MovDir[x][y] = move_direction_initial;
2276 else if (move_pattern == MV_ALL_DIRECTIONS ||
2277 move_pattern == MV_TURNING_LEFT ||
2278 move_pattern == MV_TURNING_RIGHT ||
2279 move_pattern == MV_TURNING_LEFT_RIGHT ||
2280 move_pattern == MV_TURNING_RIGHT_LEFT ||
2281 move_pattern == MV_TURNING_RANDOM)
2282 MovDir[x][y] = 1 << RND(4);
2283 else if (move_pattern == MV_HORIZONTAL)
2284 MovDir[x][y] = (RND(2) ? MV_LEFT : MV_RIGHT);
2285 else if (move_pattern == MV_VERTICAL)
2286 MovDir[x][y] = (RND(2) ? MV_UP : MV_DOWN);
2287 else if (move_pattern & MV_ANY_DIRECTION)
2288 MovDir[x][y] = element_info[element].move_pattern;
2289 else if (move_pattern == MV_ALONG_LEFT_SIDE ||
2290 move_pattern == MV_ALONG_RIGHT_SIDE)
2292 /* use random direction as default start direction */
2293 if (game.engine_version >= VERSION_IDENT(3,1,0,0))
2294 MovDir[x][y] = 1 << RND(4);
2296 for (i = 0; i < NUM_DIRECTIONS; i++)
2298 int x1 = x + xy[i][0];
2299 int y1 = y + xy[i][1];
2301 if (!IN_LEV_FIELD(x1, y1) || !IS_FREE(x1, y1))
2303 if (move_pattern == MV_ALONG_RIGHT_SIDE)
2304 MovDir[x][y] = direction[0][i];
2306 MovDir[x][y] = direction[1][i];
2315 MovDir[x][y] = 1 << RND(4);
2317 if (element != EL_BUG &&
2318 element != EL_SPACESHIP &&
2319 element != EL_BD_BUTTERFLY &&
2320 element != EL_BD_FIREFLY)
2323 for (i = 0; i < NUM_DIRECTIONS; i++)
2325 int x1 = x + xy[i][0];
2326 int y1 = y + xy[i][1];
2328 if (!IN_LEV_FIELD(x1, y1) || !IS_FREE(x1, y1))
2330 if (element == EL_BUG || element == EL_BD_BUTTERFLY)
2332 MovDir[x][y] = direction[0][i];
2335 else if (element == EL_SPACESHIP || element == EL_BD_FIREFLY ||
2336 element == EL_SP_SNIKSNAK || element == EL_SP_ELECTRON)
2338 MovDir[x][y] = direction[1][i];
2347 GfxDir[x][y] = MovDir[x][y];
2350 void InitAmoebaNr(int x, int y)
2353 int group_nr = AmoebeNachbarNr(x, y);
2357 for (i = 1; i < MAX_NUM_AMOEBA; i++)
2359 if (AmoebaCnt[i] == 0)
2367 AmoebaNr[x][y] = group_nr;
2368 AmoebaCnt[group_nr]++;
2369 AmoebaCnt2[group_nr]++;
2375 boolean raise_level = FALSE;
2377 if (local_player->MovPos)
2380 if (tape.auto_play) /* tape might already be stopped here */
2381 tape.auto_play_level_solved = TRUE;
2383 local_player->LevelSolved = FALSE;
2385 PlaySoundStereo(SND_GAME_WINNING, SOUND_MIDDLE);
2389 if (!tape.playing && setup.sound_loops)
2390 PlaySoundExt(SND_GAME_LEVELTIME_BONUS, SOUND_MAX_VOLUME, SOUND_MIDDLE,
2391 SND_CTRL_PLAY_LOOP);
2393 while (TimeLeft > 0)
2395 if (!tape.playing && !setup.sound_loops)
2396 PlaySoundStereo(SND_GAME_LEVELTIME_BONUS, SOUND_MIDDLE);
2398 if (TimeLeft > 100 && TimeLeft % 10 == 0)
2401 RaiseScore(level.score[SC_TIME_BONUS] * 10);
2406 RaiseScore(level.score[SC_TIME_BONUS]);
2409 DrawGameValue_Time(TimeLeft);
2417 if (!tape.playing && setup.sound_loops)
2418 StopSound(SND_GAME_LEVELTIME_BONUS);
2420 else if (level.time == 0) /* level without time limit */
2422 if (!tape.playing && setup.sound_loops)
2423 PlaySoundExt(SND_GAME_LEVELTIME_BONUS, SOUND_MAX_VOLUME, SOUND_MIDDLE,
2424 SND_CTRL_PLAY_LOOP);
2426 while (TimePlayed < 999)
2428 if (!tape.playing && !setup.sound_loops)
2429 PlaySoundStereo(SND_GAME_LEVELTIME_BONUS, SOUND_MIDDLE);
2431 if (TimePlayed < 900 && TimePlayed % 10 == 0)
2434 RaiseScore(level.score[SC_TIME_BONUS] * 10);
2439 RaiseScore(level.score[SC_TIME_BONUS]);
2442 DrawGameValue_Time(TimePlayed);
2450 if (!tape.playing && setup.sound_loops)
2451 StopSound(SND_GAME_LEVELTIME_BONUS);
2454 /* close exit door after last player */
2455 if (AllPlayersGone && ExitX >= 0 && ExitY >= 0 &&
2456 (Feld[ExitX][ExitY] == EL_EXIT_OPEN ||
2457 Feld[ExitX][ExitY] == EL_SP_EXIT_OPEN))
2459 int element = Feld[ExitX][ExitY];
2461 Feld[ExitX][ExitY] = (element == EL_EXIT_OPEN ? EL_EXIT_CLOSING :
2462 EL_SP_EXIT_CLOSING);
2464 PlayLevelSoundElementAction(ExitX, ExitY, element, ACTION_CLOSING);
2467 /* player disappears */
2468 if (ExitX >= 0 && ExitY >= 0)
2469 DrawLevelField(ExitX, ExitY);
2476 CloseDoor(DOOR_CLOSE_1);
2481 SaveTape(tape.level_nr); /* Ask to save tape */
2484 if (level_nr == leveldir_current->handicap_level)
2486 leveldir_current->handicap_level++;
2487 SaveLevelSetup_SeriesInfo();
2490 if (level_editor_test_game)
2491 local_player->score = -1; /* no highscore when playing from editor */
2492 else if (level_nr < leveldir_current->last_level)
2493 raise_level = TRUE; /* advance to next level */
2495 if ((hi_pos = NewHiScore()) >= 0)
2497 game_status = GAME_MODE_SCORES;
2498 DrawHallOfFame(hi_pos);
2507 game_status = GAME_MODE_MAIN;
2524 LoadScore(level_nr);
2526 if (strcmp(setup.player_name, EMPTY_PLAYER_NAME) == 0 ||
2527 local_player->score < highscore[MAX_SCORE_ENTRIES - 1].Score)
2530 for (k = 0; k < MAX_SCORE_ENTRIES; k++)
2532 if (local_player->score > highscore[k].Score)
2534 /* player has made it to the hall of fame */
2536 if (k < MAX_SCORE_ENTRIES - 1)
2538 int m = MAX_SCORE_ENTRIES - 1;
2541 for (l = k; l < MAX_SCORE_ENTRIES; l++)
2542 if (!strcmp(setup.player_name, highscore[l].Name))
2544 if (m == k) /* player's new highscore overwrites his old one */
2548 for (l = m; l > k; l--)
2550 strcpy(highscore[l].Name, highscore[l - 1].Name);
2551 highscore[l].Score = highscore[l - 1].Score;
2558 strncpy(highscore[k].Name, setup.player_name, MAX_PLAYER_NAME_LEN);
2559 highscore[k].Name[MAX_PLAYER_NAME_LEN] = '\0';
2560 highscore[k].Score = local_player->score;
2566 else if (!strncmp(setup.player_name, highscore[k].Name,
2567 MAX_PLAYER_NAME_LEN))
2568 break; /* player already there with a higher score */
2574 SaveScore(level_nr);
2579 inline static int getElementMoveStepsize(int x, int y)
2581 int element = Feld[x][y];
2582 int direction = MovDir[x][y];
2583 int dx = (direction == MV_LEFT ? -1 : direction == MV_RIGHT ? +1 : 0);
2584 int dy = (direction == MV_UP ? -1 : direction == MV_DOWN ? +1 : 0);
2585 int horiz_move = (dx != 0);
2586 int sign = (horiz_move ? dx : dy);
2587 int step = sign * element_info[element].move_stepsize;
2589 /* special values for move stepsize for spring and things on conveyor belt */
2593 if (element == EL_SPRING)
2594 step = sign * MOVE_STEPSIZE_NORMAL * 2;
2595 else if (CAN_FALL(element) && !CAN_MOVE(element) &&
2596 y < lev_fieldy - 1 && IS_BELT_ACTIVE(Feld[x][y + 1]))
2597 step = sign * MOVE_STEPSIZE_NORMAL / 2;
2599 if (CAN_FALL(element) &&
2600 y < lev_fieldy - 1 && IS_BELT_ACTIVE(Feld[x][y + 1]))
2601 step = sign * MOVE_STEPSIZE_NORMAL / 2;
2602 else if (element == EL_SPRING)
2603 step = sign * MOVE_STEPSIZE_NORMAL * 2;
2610 void InitPlayerGfxAnimation(struct PlayerInfo *player, int action, int dir)
2612 if (player->GfxAction != action || player->GfxDir != dir)
2615 printf("Player frame reset! (%d => %d, %d => %d)\n",
2616 player->GfxAction, action, player->GfxDir, dir);
2619 player->GfxAction = action;
2620 player->GfxDir = dir;
2622 player->StepFrame = 0;
2626 static void ResetRandomAnimationValue(int x, int y)
2628 GfxRandom[x][y] = INIT_GFX_RANDOM();
2631 static void ResetGfxAnimation(int x, int y)
2634 GfxAction[x][y] = ACTION_DEFAULT;
2635 GfxDir[x][y] = MovDir[x][y];
2638 void InitMovingField(int x, int y, int direction)
2640 int element = Feld[x][y];
2641 int dx = (direction == MV_LEFT ? -1 : direction == MV_RIGHT ? +1 : 0);
2642 int dy = (direction == MV_UP ? -1 : direction == MV_DOWN ? +1 : 0);
2646 if (!WasJustMoving[x][y] || direction != MovDir[x][y])
2647 ResetGfxAnimation(x, y);
2649 MovDir[x][y] = direction;
2650 GfxDir[x][y] = direction;
2651 GfxAction[x][y] = (direction == MV_DOWN && CAN_FALL(element) ?
2652 ACTION_FALLING : ACTION_MOVING);
2654 /* this is needed for CEs with property "can move" / "not moving" */
2656 if (getElementMoveStepsize(x, y) != 0) /* moving or being moved */
2658 if (Feld[newx][newy] == EL_EMPTY)
2659 Feld[newx][newy] = EL_BLOCKED;
2661 MovDir[newx][newy] = MovDir[x][y];
2663 #if USE_NEW_CUSTOM_VALUE
2664 CustomValue[newx][newy] = CustomValue[x][y];
2667 GfxFrame[newx][newy] = GfxFrame[x][y];
2668 GfxRandom[newx][newy] = GfxRandom[x][y];
2669 GfxAction[newx][newy] = GfxAction[x][y];
2670 GfxDir[newx][newy] = GfxDir[x][y];
2674 void Moving2Blocked(int x, int y, int *goes_to_x, int *goes_to_y)
2676 int direction = MovDir[x][y];
2677 int newx = x + (direction == MV_LEFT ? -1 : direction == MV_RIGHT ? +1 : 0);
2678 int newy = y + (direction == MV_UP ? -1 : direction == MV_DOWN ? +1 : 0);
2684 void Blocked2Moving(int x, int y, int *comes_from_x, int *comes_from_y)
2686 int oldx = x, oldy = y;
2687 int direction = MovDir[x][y];
2689 if (direction == MV_LEFT)
2691 else if (direction == MV_RIGHT)
2693 else if (direction == MV_UP)
2695 else if (direction == MV_DOWN)
2698 *comes_from_x = oldx;
2699 *comes_from_y = oldy;
2702 int MovingOrBlocked2Element(int x, int y)
2704 int element = Feld[x][y];
2706 if (element == EL_BLOCKED)
2710 Blocked2Moving(x, y, &oldx, &oldy);
2711 return Feld[oldx][oldy];
2717 static int MovingOrBlocked2ElementIfNotLeaving(int x, int y)
2719 /* like MovingOrBlocked2Element(), but if element is moving
2720 and (x,y) is the field the moving element is just leaving,
2721 return EL_BLOCKED instead of the element value */
2722 int element = Feld[x][y];
2724 if (IS_MOVING(x, y))
2726 if (element == EL_BLOCKED)
2730 Blocked2Moving(x, y, &oldx, &oldy);
2731 return Feld[oldx][oldy];
2740 static void RemoveField(int x, int y)
2742 Feld[x][y] = EL_EMPTY;
2748 #if USE_NEW_CUSTOM_VALUE
2749 CustomValue[x][y] = 0;
2753 ChangeDelay[x][y] = 0;
2754 ChangePage[x][y] = -1;
2755 Pushed[x][y] = FALSE;
2758 ExplodeField[x][y] = EX_TYPE_NONE;
2761 GfxElement[x][y] = EL_UNDEFINED;
2762 GfxAction[x][y] = ACTION_DEFAULT;
2763 GfxDir[x][y] = MV_NONE;
2766 void RemoveMovingField(int x, int y)
2768 int oldx = x, oldy = y, newx = x, newy = y;
2769 int element = Feld[x][y];
2770 int next_element = EL_UNDEFINED;
2772 if (element != EL_BLOCKED && !IS_MOVING(x, y))
2775 if (IS_MOVING(x, y))
2777 Moving2Blocked(x, y, &newx, &newy);
2779 if (Feld[newx][newy] != EL_BLOCKED)
2781 /* element is moving, but target field is not free (blocked), but
2782 already occupied by something different (example: acid pool);
2783 in this case, only remove the moving field, but not the target */
2785 RemoveField(oldx, oldy);
2787 Store[oldx][oldy] = Store2[oldx][oldy] = 0;
2789 DrawLevelField(oldx, oldy);
2794 else if (element == EL_BLOCKED)
2796 Blocked2Moving(x, y, &oldx, &oldy);
2797 if (!IS_MOVING(oldx, oldy))
2801 if (element == EL_BLOCKED &&
2802 (Feld[oldx][oldy] == EL_QUICKSAND_EMPTYING ||
2803 Feld[oldx][oldy] == EL_MAGIC_WALL_EMPTYING ||
2804 Feld[oldx][oldy] == EL_BD_MAGIC_WALL_EMPTYING ||
2805 Feld[oldx][oldy] == EL_AMOEBA_DROPPING))
2806 next_element = get_next_element(Feld[oldx][oldy]);
2808 RemoveField(oldx, oldy);
2809 RemoveField(newx, newy);
2811 Store[oldx][oldy] = Store2[oldx][oldy] = 0;
2813 if (next_element != EL_UNDEFINED)
2814 Feld[oldx][oldy] = next_element;
2816 DrawLevelField(oldx, oldy);
2817 DrawLevelField(newx, newy);
2820 void DrawDynamite(int x, int y)
2822 int sx = SCREENX(x), sy = SCREENY(y);
2823 int graphic = el2img(Feld[x][y]);
2826 if (!IN_SCR_FIELD(sx, sy) || IS_PLAYER(x, y))
2829 if (IS_WALKABLE_INSIDE(Back[x][y]))
2833 DrawGraphic(sx, sy, el2img(Back[x][y]), 0);
2834 else if (Store[x][y])
2835 DrawGraphic(sx, sy, el2img(Store[x][y]), 0);
2837 frame = getGraphicAnimationFrame(graphic, GfxFrame[x][y]);
2839 if (Back[x][y] || Store[x][y])
2840 DrawGraphicThruMask(sx, sy, graphic, frame);
2842 DrawGraphic(sx, sy, graphic, frame);
2845 void CheckDynamite(int x, int y)
2847 if (MovDelay[x][y] != 0) /* dynamite is still waiting to explode */
2851 if (MovDelay[x][y] != 0)
2854 PlayLevelSoundActionIfLoop(x, y, ACTION_ACTIVE);
2860 StopLevelSoundActionIfLoop(x, y, ACTION_ACTIVE);
2865 void DrawRelocatePlayer(struct PlayerInfo *player)
2867 boolean ffwd_delay = (tape.playing && tape.fast_forward);
2868 boolean no_delay = (tape.warp_forward);
2869 int frame_delay_value = (ffwd_delay ? FfwdFrameDelay : GameFrameDelay);
2870 int wait_delay_value = (no_delay ? 0 : frame_delay_value);
2871 int jx = player->jx;
2872 int jy = player->jy;
2874 if (level.instant_relocation)
2876 int offset = (setup.scroll_delay ? 3 : 0);
2878 if (!IN_VIS_FIELD(SCREENX(jx), SCREENY(jy)))
2880 scroll_x = (local_player->jx < SBX_Left + MIDPOSX ? SBX_Left :
2881 local_player->jx > SBX_Right + MIDPOSX ? SBX_Right :
2882 local_player->jx - MIDPOSX);
2884 scroll_y = (local_player->jy < SBY_Upper + MIDPOSY ? SBY_Upper :
2885 local_player->jy > SBY_Lower + MIDPOSY ? SBY_Lower :
2886 local_player->jy - MIDPOSY);
2890 if ((player->MovDir == MV_LEFT && scroll_x > jx - MIDPOSX + offset) ||
2891 (player->MovDir == MV_RIGHT && scroll_x < jx - MIDPOSX - offset))
2892 scroll_x = jx - MIDPOSX + (scroll_x < jx-MIDPOSX ? -offset : +offset);
2894 if ((player->MovDir == MV_UP && scroll_y > jy - MIDPOSY + offset) ||
2895 (player->MovDir == MV_DOWN && scroll_y < jy - MIDPOSY - offset))
2896 scroll_y = jy - MIDPOSY + (scroll_y < jy-MIDPOSY ? -offset : +offset);
2898 /* don't scroll over playfield boundaries */
2899 if (scroll_x < SBX_Left || scroll_x > SBX_Right)
2900 scroll_x = (scroll_x < SBX_Left ? SBX_Left : SBX_Right);
2902 /* don't scroll over playfield boundaries */
2903 if (scroll_y < SBY_Upper || scroll_y > SBY_Lower)
2904 scroll_y = (scroll_y < SBY_Upper ? SBY_Upper : SBY_Lower);
2907 RedrawPlayfield(TRUE, 0,0,0,0);
2911 int scroll_xx = -999, scroll_yy = -999;
2913 ScrollScreen(NULL, SCROLL_GO_ON); /* scroll last frame to full tile */
2915 while (scroll_xx != scroll_x || scroll_yy != scroll_y)
2918 int fx = FX, fy = FY;
2920 scroll_xx = (local_player->jx < SBX_Left + MIDPOSX ? SBX_Left :
2921 local_player->jx > SBX_Right + MIDPOSX ? SBX_Right :
2922 local_player->jx - MIDPOSX);
2924 scroll_yy = (local_player->jy < SBY_Upper + MIDPOSY ? SBY_Upper :
2925 local_player->jy > SBY_Lower + MIDPOSY ? SBY_Lower :
2926 local_player->jy - MIDPOSY);
2928 dx = (scroll_xx < scroll_x ? +1 : scroll_xx > scroll_x ? -1 : 0);
2929 dy = (scroll_yy < scroll_y ? +1 : scroll_yy > scroll_y ? -1 : 0);
2931 if (dx == 0 && dy == 0) /* no scrolling needed at all */
2937 fx += dx * TILEX / 2;
2938 fy += dy * TILEY / 2;
2940 ScrollLevel(dx, dy);
2943 /* scroll in two steps of half tile size to make things smoother */
2944 BlitBitmap(drawto_field, window, fx, fy, SXSIZE, SYSIZE, SX, SY);
2946 Delay(wait_delay_value);
2948 /* scroll second step to align at full tile size */
2950 Delay(wait_delay_value);
2955 Delay(wait_delay_value);
2959 void RelocatePlayer(int jx, int jy, int el_player_raw)
2961 int el_player = GET_PLAYER_ELEMENT(el_player_raw);
2962 int player_nr = GET_PLAYER_NR(el_player);
2963 struct PlayerInfo *player = &stored_player[player_nr];
2964 boolean ffwd_delay = (tape.playing && tape.fast_forward);
2965 boolean no_delay = (tape.warp_forward);
2966 int frame_delay_value = (ffwd_delay ? FfwdFrameDelay : GameFrameDelay);
2967 int wait_delay_value = (no_delay ? 0 : frame_delay_value);
2968 int old_jx = player->jx;
2969 int old_jy = player->jy;
2970 int old_element = Feld[old_jx][old_jy];
2971 int element = Feld[jx][jy];
2972 boolean player_relocated = (old_jx != jx || old_jy != jy);
2974 int move_dir_horiz = (jx < old_jx ? MV_LEFT : jx > old_jx ? MV_RIGHT : 0);
2975 int move_dir_vert = (jy < old_jy ? MV_UP : jy > old_jy ? MV_DOWN : 0);
2976 int enter_side_horiz = MV_DIR_OPPOSITE(move_dir_horiz);
2977 int enter_side_vert = MV_DIR_OPPOSITE(move_dir_vert);
2978 int leave_side_horiz = move_dir_horiz;
2979 int leave_side_vert = move_dir_vert;
2980 int enter_side = enter_side_horiz | enter_side_vert;
2981 int leave_side = leave_side_horiz | leave_side_vert;
2983 if (player->GameOver) /* do not reanimate dead player */
2986 if (!player_relocated) /* no need to relocate the player */
2989 if (IS_PLAYER(jx, jy)) /* player already placed at new position */
2991 RemoveField(jx, jy); /* temporarily remove newly placed player */
2992 DrawLevelField(jx, jy);
2995 if (player->present)
2997 while (player->MovPos)
2999 ScrollPlayer(player, SCROLL_GO_ON);
3000 ScrollScreen(NULL, SCROLL_GO_ON);
3002 AdvanceFrameAndPlayerCounters(player->index_nr);
3007 Delay(wait_delay_value);
3010 DrawPlayer(player); /* needed here only to cleanup last field */
3011 DrawLevelField(player->jx, player->jy); /* remove player graphic */
3013 player->is_moving = FALSE;
3016 if (IS_CUSTOM_ELEMENT(old_element))
3017 CheckElementChangeByPlayer(old_jx, old_jy, old_element,
3019 player->index_bit, leave_side);
3021 CheckTriggeredElementChangeByPlayer(old_jx, old_jy, old_element,
3023 player->index_bit, leave_side);
3025 Feld[jx][jy] = el_player;
3026 InitPlayerField(jx, jy, el_player, TRUE);
3028 if (!ELEM_IS_PLAYER(element)) /* player may be set on walkable element */
3030 Feld[jx][jy] = element;
3031 InitField(jx, jy, FALSE);
3034 if (player == local_player) /* only visually relocate local player */
3035 DrawRelocatePlayer(player);
3037 TestIfPlayerTouchesBadThing(jx, jy);
3038 TestIfPlayerTouchesCustomElement(jx, jy);
3040 if (IS_CUSTOM_ELEMENT(element))
3041 CheckElementChangeByPlayer(jx, jy, element, CE_ENTERED_BY_PLAYER,
3042 player->index_bit, enter_side);
3044 CheckTriggeredElementChangeByPlayer(jx, jy, element, CE_PLAYER_ENTERS_X,
3045 player->index_bit, enter_side);
3048 void Explode(int ex, int ey, int phase, int mode)
3054 /* !!! eliminate this variable !!! */
3055 int delay = (game.emulation == EMU_SUPAPLEX ? 3 : 2);
3057 if (game.explosions_delayed)
3059 ExplodeField[ex][ey] = mode;
3063 if (phase == EX_PHASE_START) /* initialize 'Store[][]' field */
3065 int center_element = Feld[ex][ey];
3066 int artwork_element = center_element; /* for custom player artwork */
3067 int explosion_element = center_element; /* for custom player artwork */
3069 if (IS_PLAYER(ex, ey))
3071 int player_nr = GET_PLAYER_NR(StorePlayer[ex][ey]);
3073 artwork_element = stored_player[player_nr].artwork_element;
3075 if (level.use_explosion_element[player_nr])
3077 explosion_element = level.explosion_element[player_nr];
3078 artwork_element = explosion_element;
3083 /* --- This is only really needed (and now handled) in "Impact()". --- */
3084 /* do not explode moving elements that left the explode field in time */
3085 if (game.engine_version >= VERSION_IDENT(2,2,0,7) &&
3086 center_element == EL_EMPTY &&
3087 (mode == EX_TYPE_NORMAL || mode == EX_TYPE_CENTER))
3091 if (mode == EX_TYPE_NORMAL ||
3092 mode == EX_TYPE_CENTER ||
3093 mode == EX_TYPE_CROSS)
3094 PlayLevelSoundElementAction(ex, ey, artwork_element, ACTION_EXPLODING);
3096 /* remove things displayed in background while burning dynamite */
3097 if (Back[ex][ey] != EL_EMPTY && !IS_INDESTRUCTIBLE(Back[ex][ey]))
3100 if (IS_MOVING(ex, ey) || IS_BLOCKED(ex, ey))
3102 /* put moving element to center field (and let it explode there) */
3103 center_element = MovingOrBlocked2Element(ex, ey);
3104 RemoveMovingField(ex, ey);
3105 Feld[ex][ey] = center_element;
3108 last_phase = element_info[explosion_element].explosion_delay + 1;
3110 for (y = ey - 1; y <= ey + 1; y++) for (x = ex - 1; x <= ex + 1; x++)
3112 int xx = x - ex + 1;
3113 int yy = y - ey + 1;
3116 if (!IN_LEV_FIELD(x, y) ||
3117 (mode & EX_TYPE_SINGLE_TILE && (x != ex || y != ey)) ||
3118 (mode == EX_TYPE_CROSS && (x != ex && y != ey)))
3121 element = Feld[x][y];
3123 if (IS_MOVING(x, y) || IS_BLOCKED(x, y))
3125 element = MovingOrBlocked2Element(x, y);
3127 if (!IS_EXPLOSION_PROOF(element))
3128 RemoveMovingField(x, y);
3131 /* indestructible elements can only explode in center (but not flames) */
3132 if ((IS_EXPLOSION_PROOF(element) && (x != ex || y != ey ||
3133 mode == EX_TYPE_BORDER)) ||
3134 element == EL_FLAMES)
3137 /* no idea why this was changed from 3.0.8 to 3.1.0 -- this causes buggy
3138 behaviour, for example when touching a yamyam that explodes to rocks
3139 with active deadly shield, a rock is created under the player !!! */
3140 /* (case 1 (surely buggy): >= 3.1.0, case 2 (maybe buggy): <= 3.0.8) */
3142 if (IS_PLAYER(x, y) && SHIELD_ON(PLAYERINFO(x, y)) &&
3143 (game.engine_version < VERSION_IDENT(3,1,0,0) ||
3144 (x == ex && y == ey && mode != EX_TYPE_BORDER)))
3146 if (IS_PLAYER(x, y) && SHIELD_ON(PLAYERINFO(x, y)))
3149 if (IS_ACTIVE_BOMB(element))
3151 /* re-activate things under the bomb like gate or penguin */
3152 Feld[x][y] = (Back[x][y] ? Back[x][y] : EL_EMPTY);
3159 /* save walkable background elements while explosion on same tile */
3160 if (IS_WALKABLE(element) && IS_INDESTRUCTIBLE(element) &&
3161 (x != ex || y != ey || mode == EX_TYPE_BORDER))
3162 Back[x][y] = element;
3164 /* ignite explodable elements reached by other explosion */
3165 if (element == EL_EXPLOSION)
3166 element = Store2[x][y];
3168 if (AmoebaNr[x][y] &&
3169 (element == EL_AMOEBA_FULL ||
3170 element == EL_BD_AMOEBA ||
3171 element == EL_AMOEBA_GROWING))
3173 AmoebaCnt[AmoebaNr[x][y]]--;
3174 AmoebaCnt2[AmoebaNr[x][y]]--;
3179 if (IS_PLAYER(ex, ey) && !PLAYER_EXPLOSION_PROTECTED(ex, ey))
3181 int player_nr = StorePlayer[ex][ey] - EL_PLAYER_1;
3183 Store[x][y] = EL_PLAYER_IS_EXPLODING_1 + player_nr;
3186 switch(StorePlayer[ex][ey])
3189 Store[x][y] = EL_PLAYER_IS_EXPLODING_2;
3192 Store[x][y] = EL_PLAYER_IS_EXPLODING_3;
3195 Store[x][y] = EL_PLAYER_IS_EXPLODING_4;
3199 Store[x][y] = EL_PLAYER_IS_EXPLODING_1;
3204 if (PLAYERINFO(ex, ey)->use_murphy)
3205 Store[x][y] = EL_EMPTY;
3208 else if (center_element == EL_YAMYAM)
3209 Store[x][y] = level.yamyam_content[game.yamyam_content_nr].e[xx][yy];
3210 else if (element_info[center_element].content.e[xx][yy] != EL_EMPTY)
3211 Store[x][y] = element_info[center_element].content.e[xx][yy];
3212 else if (!CAN_EXPLODE(element))
3213 Store[x][y] = element_info[element].content.e[1][1];
3215 Store[x][y] = EL_EMPTY;
3217 else if (center_element == EL_MOLE)
3218 Store[x][y] = EL_EMERALD_RED;
3219 else if (center_element == EL_PENGUIN)
3220 Store[x][y] = EL_EMERALD_PURPLE;
3221 else if (center_element == EL_BUG)
3222 Store[x][y] = ((x == ex && y == ey) ? EL_DIAMOND : EL_EMERALD);
3223 else if (center_element == EL_BD_BUTTERFLY)
3224 Store[x][y] = EL_BD_DIAMOND;
3225 else if (center_element == EL_SP_ELECTRON)
3226 Store[x][y] = EL_SP_INFOTRON;
3227 else if (center_element == EL_AMOEBA_TO_DIAMOND)
3228 Store[x][y] = level.amoeba_content;
3229 else if (center_element == EL_YAMYAM)
3230 Store[x][y] = level.yamyam_content[game.yamyam_content_nr].e[xx][yy];
3231 else if (IS_CUSTOM_ELEMENT(center_element) &&
3232 element_info[center_element].content.e[xx][yy] != EL_EMPTY)
3233 Store[x][y] = element_info[center_element].content.e[xx][yy];
3234 else if (element == EL_WALL_EMERALD)
3235 Store[x][y] = EL_EMERALD;
3236 else if (element == EL_WALL_DIAMOND)
3237 Store[x][y] = EL_DIAMOND;
3238 else if (element == EL_WALL_BD_DIAMOND)
3239 Store[x][y] = EL_BD_DIAMOND;
3240 else if (element == EL_WALL_EMERALD_YELLOW)
3241 Store[x][y] = EL_EMERALD_YELLOW;
3242 else if (element == EL_WALL_EMERALD_RED)
3243 Store[x][y] = EL_EMERALD_RED;
3244 else if (element == EL_WALL_EMERALD_PURPLE)
3245 Store[x][y] = EL_EMERALD_PURPLE;
3246 else if (element == EL_WALL_PEARL)
3247 Store[x][y] = EL_PEARL;
3248 else if (element == EL_WALL_CRYSTAL)
3249 Store[x][y] = EL_CRYSTAL;
3250 else if (IS_CUSTOM_ELEMENT(element) && !CAN_EXPLODE(element))
3251 Store[x][y] = element_info[element].content.e[1][1];
3253 Store[x][y] = EL_EMPTY;
3256 if (x != ex || y != ey || mode == EX_TYPE_BORDER ||
3257 center_element == EL_AMOEBA_TO_DIAMOND)
3258 Store2[x][y] = element;
3260 Feld[x][y] = EL_EXPLOSION;
3261 GfxElement[x][y] = artwork_element;
3263 ExplodePhase[x][y] = 1;
3264 ExplodeDelay[x][y] = last_phase;
3269 if (center_element == EL_YAMYAM)
3270 game.yamyam_content_nr =
3271 (game.yamyam_content_nr + 1) % level.num_yamyam_contents;
3283 GfxFrame[x][y] = 0; /* restart explosion animation */
3285 last_phase = ExplodeDelay[x][y];
3287 ExplodePhase[x][y] = (phase < last_phase ? phase + 1 : 0);
3291 /* activate this even in non-DEBUG version until cause for crash in
3292 getGraphicAnimationFrame() (see below) is found and eliminated */
3297 if (GfxElement[x][y] == EL_UNDEFINED)
3300 printf("Explode(): x = %d, y = %d: GfxElement == EL_UNDEFINED\n", x, y);
3301 printf("Explode(): This should never happen!\n");
3304 GfxElement[x][y] = EL_EMPTY;
3308 border_element = Store2[x][y];
3309 if (IS_PLAYER(x, y) && !PLAYER_EXPLOSION_PROTECTED(x, y))
3310 border_element = StorePlayer[x][y];
3312 if (phase == element_info[border_element].ignition_delay ||
3313 phase == last_phase)
3315 boolean border_explosion = FALSE;
3317 if (IS_PLAYER(x, y) && PLAYERINFO(x, y)->present &&
3318 !PLAYER_EXPLOSION_PROTECTED(x, y))
3320 KillPlayerUnlessExplosionProtected(x, y);
3321 border_explosion = TRUE;
3323 else if (CAN_EXPLODE_BY_EXPLOSION(border_element))
3325 Feld[x][y] = Store2[x][y];
3328 border_explosion = TRUE;
3330 else if (border_element == EL_AMOEBA_TO_DIAMOND)
3332 AmoebeUmwandeln(x, y);
3334 border_explosion = TRUE;
3337 /* if an element just explodes due to another explosion (chain-reaction),
3338 do not immediately end the new explosion when it was the last frame of
3339 the explosion (as it would be done in the following "if"-statement!) */
3340 if (border_explosion && phase == last_phase)
3344 if (phase == last_phase)
3348 element = Feld[x][y] = Store[x][y];
3349 Store[x][y] = Store2[x][y] = 0;
3350 GfxElement[x][y] = EL_UNDEFINED;
3352 /* player can escape from explosions and might therefore be still alive */
3353 if (element >= EL_PLAYER_IS_EXPLODING_1 &&
3354 element <= EL_PLAYER_IS_EXPLODING_4)
3356 static int player_death_elements[] =
3363 int player_nr = element - EL_PLAYER_IS_EXPLODING_1;
3364 int player_death_element = player_death_elements[player_nr];
3366 if (level.use_explosion_element[player_nr])
3368 int explosion_element = level.explosion_element[player_nr];
3369 int xx = MIN(MAX(0, x - stored_player[player_nr].jx + 1), 2);
3370 int yy = MIN(MAX(0, y - stored_player[player_nr].jy + 1), 2);
3372 player_death_element =
3373 element_info[explosion_element].content.e[xx][yy];
3376 Feld[x][y] = (stored_player[player_nr].active ? EL_EMPTY :
3377 player_death_element);
3380 /* restore probably existing indestructible background element */
3381 if (Back[x][y] && IS_INDESTRUCTIBLE(Back[x][y]))
3382 element = Feld[x][y] = Back[x][y];
3385 MovDir[x][y] = MovPos[x][y] = MovDelay[x][y] = 0;
3386 GfxDir[x][y] = MV_NONE;
3387 ChangeDelay[x][y] = 0;
3388 ChangePage[x][y] = -1;
3390 #if USE_NEW_CUSTOM_VALUE
3391 CustomValue[x][y] = 0;
3394 InitField_WithBug2(x, y, FALSE);
3396 DrawLevelField(x, y);
3398 TestIfElementTouchesCustomElement(x, y);
3400 if (GFX_CRUMBLED(element))
3401 DrawLevelFieldCrumbledSandNeighbours(x, y);
3403 if (IS_PLAYER(x, y) && !PLAYERINFO(x, y)->present)
3404 StorePlayer[x][y] = 0;
3406 if (ELEM_IS_PLAYER(element))
3407 RelocatePlayer(x, y, element);
3409 else if (IN_SCR_FIELD(SCREENX(x), SCREENY(y)))
3411 int graphic = el_act2img(GfxElement[x][y], ACTION_EXPLODING);
3412 int frame = getGraphicAnimationFrame(graphic, GfxFrame[x][y]);
3415 DrawLevelFieldCrumbledSand(x, y);
3417 if (IS_WALKABLE_OVER(Back[x][y]) && Back[x][y] != EL_EMPTY)
3419 DrawLevelElement(x, y, Back[x][y]);
3420 DrawGraphicThruMask(SCREENX(x), SCREENY(y), graphic, frame);
3422 else if (IS_WALKABLE_UNDER(Back[x][y]))
3424 DrawGraphic(SCREENX(x), SCREENY(y), graphic, frame);
3425 DrawLevelElementThruMask(x, y, Back[x][y]);
3427 else if (!IS_WALKABLE_INSIDE(Back[x][y]))
3428 DrawGraphic(SCREENX(x), SCREENY(y), graphic, frame);
3432 void DynaExplode(int ex, int ey)
3435 int dynabomb_element = Feld[ex][ey];
3436 int dynabomb_size = 1;
3437 boolean dynabomb_xl = FALSE;
3438 struct PlayerInfo *player;
3439 static int xy[4][2] =
3447 if (IS_ACTIVE_BOMB(dynabomb_element))
3449 player = &stored_player[dynabomb_element - EL_DYNABOMB_PLAYER_1_ACTIVE];
3450 dynabomb_size = player->dynabomb_size;
3451 dynabomb_xl = player->dynabomb_xl;
3452 player->dynabombs_left++;
3455 Explode(ex, ey, EX_PHASE_START, EX_TYPE_CENTER);
3457 for (i = 0; i < NUM_DIRECTIONS; i++)
3459 for (j = 1; j <= dynabomb_size; j++)
3461 int x = ex + j * xy[i][0];
3462 int y = ey + j * xy[i][1];
3465 if (!IN_LEV_FIELD(x, y) || IS_INDESTRUCTIBLE(Feld[x][y]))
3468 element = Feld[x][y];
3470 /* do not restart explosions of fields with active bombs */
3471 if (element == EL_EXPLOSION && IS_ACTIVE_BOMB(Store2[x][y]))
3474 Explode(x, y, EX_PHASE_START, EX_TYPE_BORDER);
3476 if (element != EL_EMPTY && element != EL_EXPLOSION &&
3477 !IS_DIGGABLE(element) && !dynabomb_xl)
3483 void Bang(int x, int y)
3485 int element = MovingOrBlocked2Element(x, y);
3486 int explosion_type = EX_TYPE_NORMAL;
3488 if (IS_PLAYER(x, y) && !PLAYER_EXPLOSION_PROTECTED(x, y))
3490 struct PlayerInfo *player = PLAYERINFO(x, y);
3492 element = Feld[x][y] = (player->use_murphy ? EL_SP_MURPHY :
3493 player->element_nr);
3495 if (level.use_explosion_element[player->index_nr])
3497 int explosion_element = level.explosion_element[player->index_nr];
3499 if (element_info[explosion_element].explosion_type == EXPLODES_CROSS)
3500 explosion_type = EX_TYPE_CROSS;
3501 else if (element_info[explosion_element].explosion_type == EXPLODES_1X1)
3502 explosion_type = EX_TYPE_CENTER;
3510 case EL_BD_BUTTERFLY:
3513 case EL_DARK_YAMYAM:
3517 RaiseScoreElement(element);
3520 case EL_DYNABOMB_PLAYER_1_ACTIVE:
3521 case EL_DYNABOMB_PLAYER_2_ACTIVE:
3522 case EL_DYNABOMB_PLAYER_3_ACTIVE:
3523 case EL_DYNABOMB_PLAYER_4_ACTIVE:
3524 case EL_DYNABOMB_INCREASE_NUMBER:
3525 case EL_DYNABOMB_INCREASE_SIZE:
3526 case EL_DYNABOMB_INCREASE_POWER:
3527 explosion_type = EX_TYPE_DYNA;
3532 case EL_LAMP_ACTIVE:
3533 case EL_AMOEBA_TO_DIAMOND:
3534 if (!IS_PLAYER(x, y)) /* penguin and player may be at same field */
3535 explosion_type = EX_TYPE_CENTER;
3539 if (element_info[element].explosion_type == EXPLODES_CROSS)
3540 explosion_type = EX_TYPE_CROSS;
3541 else if (element_info[element].explosion_type == EXPLODES_1X1)
3542 explosion_type = EX_TYPE_CENTER;
3546 if (explosion_type == EX_TYPE_DYNA)
3549 Explode(x, y, EX_PHASE_START, explosion_type);
3551 CheckTriggeredElementChange(x, y, element, CE_EXPLOSION_OF_X);
3554 void SplashAcid(int x, int y)
3556 if (IN_LEV_FIELD(x - 1, y - 1) && IS_FREE(x - 1, y - 1) &&
3557 (!IN_LEV_FIELD(x - 1, y - 2) ||
3558 !CAN_FALL(MovingOrBlocked2Element(x - 1, y - 2))))
3559 Feld[x - 1][y - 1] = EL_ACID_SPLASH_LEFT;
3561 if (IN_LEV_FIELD(x + 1, y - 1) && IS_FREE(x + 1, y - 1) &&
3562 (!IN_LEV_FIELD(x + 1, y - 2) ||
3563 !CAN_FALL(MovingOrBlocked2Element(x + 1, y - 2))))
3564 Feld[x + 1][y - 1] = EL_ACID_SPLASH_RIGHT;
3566 PlayLevelSound(x, y, SND_ACID_SPLASHING);
3569 static void InitBeltMovement()
3571 static int belt_base_element[4] =
3573 EL_CONVEYOR_BELT_1_LEFT,
3574 EL_CONVEYOR_BELT_2_LEFT,
3575 EL_CONVEYOR_BELT_3_LEFT,
3576 EL_CONVEYOR_BELT_4_LEFT
3578 static int belt_base_active_element[4] =
3580 EL_CONVEYOR_BELT_1_LEFT_ACTIVE,
3581 EL_CONVEYOR_BELT_2_LEFT_ACTIVE,
3582 EL_CONVEYOR_BELT_3_LEFT_ACTIVE,
3583 EL_CONVEYOR_BELT_4_LEFT_ACTIVE
3588 /* set frame order for belt animation graphic according to belt direction */
3589 for (i = 0; i < NUM_BELTS; i++)
3593 for (j = 0; j < NUM_BELT_PARTS; j++)
3595 int element = belt_base_active_element[belt_nr] + j;
3596 int graphic = el2img(element);
3598 if (game.belt_dir[i] == MV_LEFT)
3599 graphic_info[graphic].anim_mode &= ~ANIM_REVERSE;
3601 graphic_info[graphic].anim_mode |= ANIM_REVERSE;
3605 for (y = 0; y < lev_fieldy; y++)
3607 for (x = 0; x < lev_fieldx; x++)
3609 int element = Feld[x][y];
3611 for (i = 0; i < NUM_BELTS; i++)
3613 if (IS_BELT(element) && game.belt_dir[i] != MV_NONE)
3615 int e_belt_nr = getBeltNrFromBeltElement(element);
3618 if (e_belt_nr == belt_nr)
3620 int belt_part = Feld[x][y] - belt_base_element[belt_nr];
3622 Feld[x][y] = belt_base_active_element[belt_nr] + belt_part;
3630 static void ToggleBeltSwitch(int x, int y)
3632 static int belt_base_element[4] =
3634 EL_CONVEYOR_BELT_1_LEFT,
3635 EL_CONVEYOR_BELT_2_LEFT,
3636 EL_CONVEYOR_BELT_3_LEFT,
3637 EL_CONVEYOR_BELT_4_LEFT
3639 static int belt_base_active_element[4] =
3641 EL_CONVEYOR_BELT_1_LEFT_ACTIVE,
3642 EL_CONVEYOR_BELT_2_LEFT_ACTIVE,
3643 EL_CONVEYOR_BELT_3_LEFT_ACTIVE,
3644 EL_CONVEYOR_BELT_4_LEFT_ACTIVE
3646 static int belt_base_switch_element[4] =
3648 EL_CONVEYOR_BELT_1_SWITCH_LEFT,
3649 EL_CONVEYOR_BELT_2_SWITCH_LEFT,
3650 EL_CONVEYOR_BELT_3_SWITCH_LEFT,
3651 EL_CONVEYOR_BELT_4_SWITCH_LEFT
3653 static int belt_move_dir[4] =
3661 int element = Feld[x][y];
3662 int belt_nr = getBeltNrFromBeltSwitchElement(element);
3663 int belt_dir_nr = (game.belt_dir_nr[belt_nr] + 1) % 4;
3664 int belt_dir = belt_move_dir[belt_dir_nr];
3667 if (!IS_BELT_SWITCH(element))
3670 game.belt_dir_nr[belt_nr] = belt_dir_nr;
3671 game.belt_dir[belt_nr] = belt_dir;
3673 if (belt_dir_nr == 3)
3676 /* set frame order for belt animation graphic according to belt direction */
3677 for (i = 0; i < NUM_BELT_PARTS; i++)
3679 int element = belt_base_active_element[belt_nr] + i;
3680 int graphic = el2img(element);
3682 if (belt_dir == MV_LEFT)
3683 graphic_info[graphic].anim_mode &= ~ANIM_REVERSE;
3685 graphic_info[graphic].anim_mode |= ANIM_REVERSE;
3688 for (yy = 0; yy < lev_fieldy; yy++)
3690 for (xx = 0; xx < lev_fieldx; xx++)
3692 int element = Feld[xx][yy];
3694 if (IS_BELT_SWITCH(element))
3696 int e_belt_nr = getBeltNrFromBeltSwitchElement(element);
3698 if (e_belt_nr == belt_nr)
3700 Feld[xx][yy] = belt_base_switch_element[belt_nr] + belt_dir_nr;
3701 DrawLevelField(xx, yy);
3704 else if (IS_BELT(element) && belt_dir != MV_NONE)
3706 int e_belt_nr = getBeltNrFromBeltElement(element);
3708 if (e_belt_nr == belt_nr)
3710 int belt_part = Feld[xx][yy] - belt_base_element[belt_nr];
3712 Feld[xx][yy] = belt_base_active_element[belt_nr] + belt_part;
3713 DrawLevelField(xx, yy);
3716 else if (IS_BELT_ACTIVE(element) && belt_dir == MV_NONE)
3718 int e_belt_nr = getBeltNrFromBeltActiveElement(element);
3720 if (e_belt_nr == belt_nr)
3722 int belt_part = Feld[xx][yy] - belt_base_active_element[belt_nr];
3724 Feld[xx][yy] = belt_base_element[belt_nr] + belt_part;
3725 DrawLevelField(xx, yy);
3732 static void ToggleSwitchgateSwitch(int x, int y)
3736 game.switchgate_pos = !game.switchgate_pos;
3738 for (yy = 0; yy < lev_fieldy; yy++)
3740 for (xx = 0; xx < lev_fieldx; xx++)
3742 int element = Feld[xx][yy];
3744 if (element == EL_SWITCHGATE_SWITCH_UP ||
3745 element == EL_SWITCHGATE_SWITCH_DOWN)
3747 Feld[xx][yy] = EL_SWITCHGATE_SWITCH_UP + game.switchgate_pos;
3748 DrawLevelField(xx, yy);
3750 else if (element == EL_SWITCHGATE_OPEN ||
3751 element == EL_SWITCHGATE_OPENING)
3753 Feld[xx][yy] = EL_SWITCHGATE_CLOSING;
3755 PlayLevelSoundAction(xx, yy, ACTION_CLOSING);
3757 else if (element == EL_SWITCHGATE_CLOSED ||
3758 element == EL_SWITCHGATE_CLOSING)
3760 Feld[xx][yy] = EL_SWITCHGATE_OPENING;
3762 PlayLevelSoundAction(xx, yy, ACTION_OPENING);
3768 static int getInvisibleActiveFromInvisibleElement(int element)
3770 return (element == EL_INVISIBLE_STEELWALL ? EL_INVISIBLE_STEELWALL_ACTIVE :
3771 element == EL_INVISIBLE_WALL ? EL_INVISIBLE_WALL_ACTIVE :
3772 element == EL_INVISIBLE_SAND ? EL_INVISIBLE_SAND_ACTIVE :
3776 static int getInvisibleFromInvisibleActiveElement(int element)
3778 return (element == EL_INVISIBLE_STEELWALL_ACTIVE ? EL_INVISIBLE_STEELWALL :
3779 element == EL_INVISIBLE_WALL_ACTIVE ? EL_INVISIBLE_WALL :
3780 element == EL_INVISIBLE_SAND_ACTIVE ? EL_INVISIBLE_SAND :
3784 static void RedrawAllLightSwitchesAndInvisibleElements()
3788 for (y = 0; y < lev_fieldy; y++) for (x = 0; x < lev_fieldx; x++)
3790 int element = Feld[x][y];
3792 if (element == EL_LIGHT_SWITCH &&
3793 game.light_time_left > 0)
3795 Feld[x][y] = EL_LIGHT_SWITCH_ACTIVE;
3796 DrawLevelField(x, y);
3798 else if (element == EL_LIGHT_SWITCH_ACTIVE &&
3799 game.light_time_left == 0)
3801 Feld[x][y] = EL_LIGHT_SWITCH;
3802 DrawLevelField(x, y);
3804 else if (element == EL_EMC_DRIPPER &&
3805 game.light_time_left > 0)
3807 Feld[x][y] = EL_EMC_DRIPPER_ACTIVE;
3808 DrawLevelField(x, y);
3810 else if (element == EL_EMC_DRIPPER_ACTIVE &&
3811 game.light_time_left == 0)
3813 Feld[x][y] = EL_EMC_DRIPPER;
3814 DrawLevelField(x, y);
3816 else if (element == EL_INVISIBLE_STEELWALL ||
3817 element == EL_INVISIBLE_WALL ||
3818 element == EL_INVISIBLE_SAND)
3820 if (game.light_time_left > 0)
3821 Feld[x][y] = getInvisibleActiveFromInvisibleElement(element);
3823 DrawLevelField(x, y);
3825 /* uncrumble neighbour fields, if needed */
3826 if (element == EL_INVISIBLE_SAND)
3827 DrawLevelFieldCrumbledSandNeighbours(x, y);
3829 else if (element == EL_INVISIBLE_STEELWALL_ACTIVE ||
3830 element == EL_INVISIBLE_WALL_ACTIVE ||
3831 element == EL_INVISIBLE_SAND_ACTIVE)
3833 if (game.light_time_left == 0)
3834 Feld[x][y] = getInvisibleFromInvisibleActiveElement(element);
3836 DrawLevelField(x, y);
3838 /* re-crumble neighbour fields, if needed */
3839 if (element == EL_INVISIBLE_SAND)
3840 DrawLevelFieldCrumbledSandNeighbours(x, y);
3845 static void RedrawAllInvisibleElementsForLenses()
3849 for (y = 0; y < lev_fieldy; y++) for (x = 0; x < lev_fieldx; x++)
3851 int element = Feld[x][y];
3853 if (element == EL_EMC_DRIPPER &&
3854 game.lenses_time_left > 0)
3856 Feld[x][y] = EL_EMC_DRIPPER_ACTIVE;
3857 DrawLevelField(x, y);
3859 else if (element == EL_EMC_DRIPPER_ACTIVE &&
3860 game.lenses_time_left == 0)
3862 Feld[x][y] = EL_EMC_DRIPPER;
3863 DrawLevelField(x, y);
3865 else if (element == EL_INVISIBLE_STEELWALL ||
3866 element == EL_INVISIBLE_WALL ||
3867 element == EL_INVISIBLE_SAND)
3869 if (game.lenses_time_left > 0)
3870 Feld[x][y] = getInvisibleActiveFromInvisibleElement(element);
3872 DrawLevelField(x, y);
3874 /* uncrumble neighbour fields, if needed */
3875 if (element == EL_INVISIBLE_SAND)
3876 DrawLevelFieldCrumbledSandNeighbours(x, y);
3878 else if (element == EL_INVISIBLE_STEELWALL_ACTIVE ||
3879 element == EL_INVISIBLE_WALL_ACTIVE ||
3880 element == EL_INVISIBLE_SAND_ACTIVE)
3882 if (game.lenses_time_left == 0)
3883 Feld[x][y] = getInvisibleFromInvisibleActiveElement(element);
3885 DrawLevelField(x, y);
3887 /* re-crumble neighbour fields, if needed */
3888 if (element == EL_INVISIBLE_SAND)
3889 DrawLevelFieldCrumbledSandNeighbours(x, y);
3894 static void RedrawAllInvisibleElementsForMagnifier()
3898 for (y = 0; y < lev_fieldy; y++) for (x = 0; x < lev_fieldx; x++)
3900 int element = Feld[x][y];
3902 if (element == EL_EMC_FAKE_GRASS &&
3903 game.magnify_time_left > 0)
3905 Feld[x][y] = EL_EMC_FAKE_GRASS_ACTIVE;
3906 DrawLevelField(x, y);
3908 else if (element == EL_EMC_FAKE_GRASS_ACTIVE &&
3909 game.magnify_time_left == 0)
3911 Feld[x][y] = EL_EMC_FAKE_GRASS;
3912 DrawLevelField(x, y);
3914 else if (IS_GATE_GRAY(element) &&
3915 game.magnify_time_left > 0)
3917 Feld[x][y] = (IS_RND_GATE_GRAY(element) ?
3918 element - EL_GATE_1_GRAY + EL_GATE_1_GRAY_ACTIVE :
3919 IS_EM_GATE_GRAY(element) ?
3920 element - EL_EM_GATE_1_GRAY + EL_EM_GATE_1_GRAY_ACTIVE :
3921 IS_EMC_GATE_GRAY(element) ?
3922 element - EL_EMC_GATE_5_GRAY + EL_EMC_GATE_5_GRAY_ACTIVE :
3924 DrawLevelField(x, y);
3926 else if (IS_GATE_GRAY_ACTIVE(element) &&
3927 game.magnify_time_left == 0)
3929 Feld[x][y] = (IS_RND_GATE_GRAY_ACTIVE(element) ?
3930 element - EL_GATE_1_GRAY_ACTIVE + EL_GATE_1_GRAY :
3931 IS_EM_GATE_GRAY_ACTIVE(element) ?
3932 element - EL_EM_GATE_1_GRAY_ACTIVE + EL_EM_GATE_1_GRAY :
3933 IS_EMC_GATE_GRAY_ACTIVE(element) ?
3934 element - EL_EMC_GATE_5_GRAY_ACTIVE + EL_EMC_GATE_5_GRAY :
3936 DrawLevelField(x, y);
3941 static void ToggleLightSwitch(int x, int y)
3943 int element = Feld[x][y];
3945 game.light_time_left =
3946 (element == EL_LIGHT_SWITCH ?
3947 level.time_light * FRAMES_PER_SECOND : 0);
3949 RedrawAllLightSwitchesAndInvisibleElements();
3952 static void ActivateTimegateSwitch(int x, int y)
3956 game.timegate_time_left = level.time_timegate * FRAMES_PER_SECOND;
3958 for (yy = 0; yy < lev_fieldy; yy++)
3960 for (xx = 0; xx < lev_fieldx; xx++)
3962 int element = Feld[xx][yy];
3964 if (element == EL_TIMEGATE_CLOSED ||
3965 element == EL_TIMEGATE_CLOSING)
3967 Feld[xx][yy] = EL_TIMEGATE_OPENING;
3968 PlayLevelSound(xx, yy, SND_TIMEGATE_OPENING);
3972 else if (element == EL_TIMEGATE_SWITCH_ACTIVE)
3974 Feld[xx][yy] = EL_TIMEGATE_SWITCH;
3975 DrawLevelField(xx, yy);
3982 Feld[x][y] = EL_TIMEGATE_SWITCH_ACTIVE;
3985 void Impact(int x, int y)
3987 boolean last_line = (y == lev_fieldy - 1);
3988 boolean object_hit = FALSE;
3989 boolean impact = (last_line || object_hit);
3990 int element = Feld[x][y];
3991 int smashed = EL_STEELWALL;
3993 if (!last_line) /* check if element below was hit */
3995 if (Feld[x][y + 1] == EL_PLAYER_IS_LEAVING)
3998 object_hit = (!IS_FREE(x, y + 1) && (!IS_MOVING(x, y + 1) ||
3999 MovDir[x][y + 1] != MV_DOWN ||
4000 MovPos[x][y + 1] <= TILEY / 2));
4002 /* do not smash moving elements that left the smashed field in time */
4003 if (game.engine_version >= VERSION_IDENT(2,2,0,7) && IS_MOVING(x, y + 1) &&
4004 ABS(MovPos[x][y + 1] + getElementMoveStepsize(x, y + 1)) >= TILEX)
4008 smashed = MovingOrBlocked2Element(x, y + 1);
4010 impact = (last_line || object_hit);
4013 if (!last_line && smashed == EL_ACID) /* element falls into acid */
4015 SplashAcid(x, y + 1);
4019 /* !!! not sufficient for all cases -- see EL_PEARL below !!! */
4020 /* only reset graphic animation if graphic really changes after impact */
4022 el_act_dir2img(element, GfxAction[x][y], MV_DOWN) != el2img(element))
4024 ResetGfxAnimation(x, y);
4025 DrawLevelField(x, y);
4028 if (impact && CAN_EXPLODE_IMPACT(element))
4033 else if (impact && element == EL_PEARL)
4035 ResetGfxAnimation(x, y);
4037 Feld[x][y] = EL_PEARL_BREAKING;
4038 PlayLevelSound(x, y, SND_PEARL_BREAKING);
4041 else if (impact && CheckElementChange(x, y, element, smashed, CE_IMPACT))
4043 PlayLevelSoundElementAction(x, y, element, ACTION_IMPACT);
4048 if (impact && element == EL_AMOEBA_DROP)
4050 if (object_hit && IS_PLAYER(x, y + 1))
4051 KillPlayerUnlessEnemyProtected(x, y + 1);
4052 else if (object_hit && smashed == EL_PENGUIN)
4056 Feld[x][y] = EL_AMOEBA_GROWING;
4057 Store[x][y] = EL_AMOEBA_WET;
4059 ResetRandomAnimationValue(x, y);
4064 if (object_hit) /* check which object was hit */
4066 if (CAN_PASS_MAGIC_WALL(element) &&
4067 (smashed == EL_MAGIC_WALL ||
4068 smashed == EL_BD_MAGIC_WALL))
4071 int activated_magic_wall =
4072 (smashed == EL_MAGIC_WALL ? EL_MAGIC_WALL_ACTIVE :
4073 EL_BD_MAGIC_WALL_ACTIVE);
4075 /* activate magic wall / mill */
4076 for (yy = 0; yy < lev_fieldy; yy++)
4077 for (xx = 0; xx < lev_fieldx; xx++)
4078 if (Feld[xx][yy] == smashed)
4079 Feld[xx][yy] = activated_magic_wall;
4081 game.magic_wall_time_left = level.time_magic_wall * FRAMES_PER_SECOND;
4082 game.magic_wall_active = TRUE;
4084 PlayLevelSound(x, y, (smashed == EL_MAGIC_WALL ?
4085 SND_MAGIC_WALL_ACTIVATING :
4086 SND_BD_MAGIC_WALL_ACTIVATING));
4089 if (IS_PLAYER(x, y + 1))
4091 if (CAN_SMASH_PLAYER(element))
4093 KillPlayerUnlessEnemyProtected(x, y + 1);
4097 else if (smashed == EL_PENGUIN)
4099 if (CAN_SMASH_PLAYER(element))
4105 else if (element == EL_BD_DIAMOND)
4107 if (IS_CLASSIC_ENEMY(smashed) && IS_BD_ELEMENT(smashed))
4113 else if (((element == EL_SP_INFOTRON ||
4114 element == EL_SP_ZONK) &&
4115 (smashed == EL_SP_SNIKSNAK ||
4116 smashed == EL_SP_ELECTRON ||
4117 smashed == EL_SP_DISK_ORANGE)) ||
4118 (element == EL_SP_INFOTRON &&
4119 smashed == EL_SP_DISK_YELLOW))
4124 else if (CAN_SMASH_EVERYTHING(element))
4126 if (IS_CLASSIC_ENEMY(smashed) ||
4127 CAN_EXPLODE_SMASHED(smashed))
4132 else if (!IS_MOVING(x, y + 1) && !IS_BLOCKED(x, y + 1))
4134 if (smashed == EL_LAMP ||
4135 smashed == EL_LAMP_ACTIVE)
4140 else if (smashed == EL_NUT)
4142 Feld[x][y + 1] = EL_NUT_BREAKING;
4143 PlayLevelSound(x, y, SND_NUT_BREAKING);
4144 RaiseScoreElement(EL_NUT);
4147 else if (smashed == EL_PEARL)
4149 ResetGfxAnimation(x, y);
4151 Feld[x][y + 1] = EL_PEARL_BREAKING;
4152 PlayLevelSound(x, y, SND_PEARL_BREAKING);
4155 else if (smashed == EL_DIAMOND)
4157 Feld[x][y + 1] = EL_DIAMOND_BREAKING;
4158 PlayLevelSound(x, y, SND_DIAMOND_BREAKING);
4161 else if (IS_BELT_SWITCH(smashed))
4163 ToggleBeltSwitch(x, y + 1);
4165 else if (smashed == EL_SWITCHGATE_SWITCH_UP ||
4166 smashed == EL_SWITCHGATE_SWITCH_DOWN)
4168 ToggleSwitchgateSwitch(x, y + 1);
4170 else if (smashed == EL_LIGHT_SWITCH ||
4171 smashed == EL_LIGHT_SWITCH_ACTIVE)
4173 ToggleLightSwitch(x, y + 1);
4178 TestIfElementSmashesCustomElement(x, y, MV_DOWN);
4181 CheckElementChange(x, y + 1, smashed, element, CE_SMASHED);
4183 CheckElementChangeBySide(x, y + 1, smashed, element,
4184 CE_SWITCHED, CH_SIDE_TOP);
4185 CheckTriggeredElementChangeBySide(x, y + 1, smashed, CE_SWITCH_OF_X,
4191 CheckElementChange(x, y + 1, smashed, element, CE_SMASHED);
4196 /* play sound of magic wall / mill */
4198 (Feld[x][y + 1] == EL_MAGIC_WALL_ACTIVE ||
4199 Feld[x][y + 1] == EL_BD_MAGIC_WALL_ACTIVE))
4201 if (Feld[x][y + 1] == EL_MAGIC_WALL_ACTIVE)
4202 PlayLevelSound(x, y, SND_MAGIC_WALL_FILLING);
4203 else if (Feld[x][y + 1] == EL_BD_MAGIC_WALL_ACTIVE)
4204 PlayLevelSound(x, y, SND_BD_MAGIC_WALL_FILLING);
4209 /* play sound of object that hits the ground */
4210 if (last_line || object_hit)
4211 PlayLevelSoundElementAction(x, y, element, ACTION_IMPACT);
4214 inline static void TurnRoundExt(int x, int y)
4226 { 0, 0 }, { 0, 0 }, { 0, 0 },
4231 int left, right, back;
4235 { MV_DOWN, MV_UP, MV_RIGHT },
4236 { MV_UP, MV_DOWN, MV_LEFT },
4238 { MV_LEFT, MV_RIGHT, MV_DOWN },
4242 { MV_RIGHT, MV_LEFT, MV_UP }
4245 int element = Feld[x][y];
4246 int move_pattern = element_info[element].move_pattern;
4248 int old_move_dir = MovDir[x][y];
4249 int left_dir = turn[old_move_dir].left;
4250 int right_dir = turn[old_move_dir].right;
4251 int back_dir = turn[old_move_dir].back;
4253 int left_dx = move_xy[left_dir].x, left_dy = move_xy[left_dir].y;
4254 int right_dx = move_xy[right_dir].x, right_dy = move_xy[right_dir].y;
4255 int move_dx = move_xy[old_move_dir].x, move_dy = move_xy[old_move_dir].y;
4256 int back_dx = move_xy[back_dir].x, back_dy = move_xy[back_dir].y;
4258 int left_x = x + left_dx, left_y = y + left_dy;
4259 int right_x = x + right_dx, right_y = y + right_dy;
4260 int move_x = x + move_dx, move_y = y + move_dy;
4264 if (element == EL_BUG || element == EL_BD_BUTTERFLY)
4266 TestIfBadThingTouchesOtherBadThing(x, y);
4268 if (ENEMY_CAN_ENTER_FIELD(element, right_x, right_y))
4269 MovDir[x][y] = right_dir;
4270 else if (!ENEMY_CAN_ENTER_FIELD(element, move_x, move_y))
4271 MovDir[x][y] = left_dir;
4273 if (element == EL_BUG && MovDir[x][y] != old_move_dir)
4275 else if (element == EL_BD_BUTTERFLY) /* && MovDir[x][y] == left_dir) */
4278 else if (element == EL_SPACESHIP || element == EL_BD_FIREFLY)
4280 TestIfBadThingTouchesOtherBadThing(x, y);
4282 if (ENEMY_CAN_ENTER_FIELD(element, left_x, left_y))
4283 MovDir[x][y] = left_dir;
4284 else if (!ENEMY_CAN_ENTER_FIELD(element, move_x, move_y))
4285 MovDir[x][y] = right_dir;
4287 if (element == EL_SPACESHIP && MovDir[x][y] != old_move_dir)
4289 else if (element == EL_BD_FIREFLY) /* && MovDir[x][y] == right_dir) */
4292 else if (element == EL_SP_SNIKSNAK || element == EL_SP_ELECTRON)
4294 TestIfBadThingTouchesOtherBadThing(x, y);
4296 if (ELEMENT_CAN_ENTER_FIELD_BASE_4(element, left_x, left_y, 0))
4297 MovDir[x][y] = left_dir;
4298 else if (!ELEMENT_CAN_ENTER_FIELD_BASE_4(element, move_x, move_y, 0))
4299 MovDir[x][y] = right_dir;
4301 if (MovDir[x][y] != old_move_dir)
4304 else if (element == EL_YAMYAM)
4306 boolean can_turn_left = YAMYAM_CAN_ENTER_FIELD(element, left_x, left_y);
4307 boolean can_turn_right = YAMYAM_CAN_ENTER_FIELD(element, right_x, right_y);
4309 if (can_turn_left && can_turn_right)
4310 MovDir[x][y] = (RND(3) ? (RND(2) ? left_dir : right_dir) : back_dir);
4311 else if (can_turn_left)
4312 MovDir[x][y] = (RND(2) ? left_dir : back_dir);
4313 else if (can_turn_right)
4314 MovDir[x][y] = (RND(2) ? right_dir : back_dir);
4316 MovDir[x][y] = back_dir;
4318 MovDelay[x][y] = 16 + 16 * RND(3);
4320 else if (element == EL_DARK_YAMYAM)
4322 boolean can_turn_left = DARK_YAMYAM_CAN_ENTER_FIELD(element,
4324 boolean can_turn_right = DARK_YAMYAM_CAN_ENTER_FIELD(element,
4327 if (can_turn_left && can_turn_right)
4328 MovDir[x][y] = (RND(3) ? (RND(2) ? left_dir : right_dir) : back_dir);
4329 else if (can_turn_left)
4330 MovDir[x][y] = (RND(2) ? left_dir : back_dir);
4331 else if (can_turn_right)
4332 MovDir[x][y] = (RND(2) ? right_dir : back_dir);
4334 MovDir[x][y] = back_dir;
4336 MovDelay[x][y] = 16 + 16 * RND(3);
4338 else if (element == EL_PACMAN)
4340 boolean can_turn_left = PACMAN_CAN_ENTER_FIELD(element, left_x, left_y);
4341 boolean can_turn_right = PACMAN_CAN_ENTER_FIELD(element, right_x, right_y);
4343 if (can_turn_left && can_turn_right)
4344 MovDir[x][y] = (RND(3) ? (RND(2) ? left_dir : right_dir) : back_dir);
4345 else if (can_turn_left)
4346 MovDir[x][y] = (RND(2) ? left_dir : back_dir);
4347 else if (can_turn_right)
4348 MovDir[x][y] = (RND(2) ? right_dir : back_dir);
4350 MovDir[x][y] = back_dir;
4352 MovDelay[x][y] = 6 + RND(40);
4354 else if (element == EL_PIG)
4356 boolean can_turn_left = PIG_CAN_ENTER_FIELD(element, left_x, left_y);
4357 boolean can_turn_right = PIG_CAN_ENTER_FIELD(element, right_x, right_y);
4358 boolean can_move_on = PIG_CAN_ENTER_FIELD(element, move_x, move_y);
4359 boolean should_turn_left, should_turn_right, should_move_on;
4361 int rnd = RND(rnd_value);
4363 should_turn_left = (can_turn_left &&
4365 IN_LEV_FIELD_AND_NOT_FREE(x + back_dx + left_dx,
4366 y + back_dy + left_dy)));
4367 should_turn_right = (can_turn_right &&
4369 IN_LEV_FIELD_AND_NOT_FREE(x + back_dx + right_dx,
4370 y + back_dy + right_dy)));
4371 should_move_on = (can_move_on &&
4374 IN_LEV_FIELD_AND_NOT_FREE(x + move_dx + left_dx,
4375 y + move_dy + left_dy) ||
4376 IN_LEV_FIELD_AND_NOT_FREE(x + move_dx + right_dx,
4377 y + move_dy + right_dy)));
4379 if (should_turn_left || should_turn_right || should_move_on)
4381 if (should_turn_left && should_turn_right && should_move_on)
4382 MovDir[x][y] = (rnd < rnd_value / 3 ? left_dir :
4383 rnd < 2 * rnd_value / 3 ? right_dir :
4385 else if (should_turn_left && should_turn_right)
4386 MovDir[x][y] = (rnd < rnd_value / 2 ? left_dir : right_dir);
4387 else if (should_turn_left && should_move_on)
4388 MovDir[x][y] = (rnd < rnd_value / 2 ? left_dir : old_move_dir);
4389 else if (should_turn_right && should_move_on)
4390 MovDir[x][y] = (rnd < rnd_value / 2 ? right_dir : old_move_dir);
4391 else if (should_turn_left)
4392 MovDir[x][y] = left_dir;
4393 else if (should_turn_right)
4394 MovDir[x][y] = right_dir;
4395 else if (should_move_on)
4396 MovDir[x][y] = old_move_dir;
4398 else if (can_move_on && rnd > rnd_value / 8)
4399 MovDir[x][y] = old_move_dir;
4400 else if (can_turn_left && can_turn_right)
4401 MovDir[x][y] = (rnd < rnd_value / 2 ? left_dir : right_dir);
4402 else if (can_turn_left && rnd > rnd_value / 8)
4403 MovDir[x][y] = left_dir;
4404 else if (can_turn_right && rnd > rnd_value/8)
4405 MovDir[x][y] = right_dir;
4407 MovDir[x][y] = back_dir;
4409 xx = x + move_xy[MovDir[x][y]].x;
4410 yy = y + move_xy[MovDir[x][y]].y;
4412 if (!IN_LEV_FIELD(xx, yy) ||
4413 (!IS_FREE(xx, yy) && !IS_FOOD_PIG(Feld[xx][yy])))
4414 MovDir[x][y] = old_move_dir;
4418 else if (element == EL_DRAGON)
4420 boolean can_turn_left = DRAGON_CAN_ENTER_FIELD(element, left_x, left_y);
4421 boolean can_turn_right = DRAGON_CAN_ENTER_FIELD(element, right_x, right_y);
4422 boolean can_move_on = DRAGON_CAN_ENTER_FIELD(element, move_x, move_y);
4424 int rnd = RND(rnd_value);
4426 if (can_move_on && rnd > rnd_value / 8)
4427 MovDir[x][y] = old_move_dir;
4428 else if (can_turn_left && can_turn_right)
4429 MovDir[x][y] = (rnd < rnd_value / 2 ? left_dir : right_dir);
4430 else if (can_turn_left && rnd > rnd_value / 8)
4431 MovDir[x][y] = left_dir;
4432 else if (can_turn_right && rnd > rnd_value / 8)
4433 MovDir[x][y] = right_dir;
4435 MovDir[x][y] = back_dir;
4437 xx = x + move_xy[MovDir[x][y]].x;
4438 yy = y + move_xy[MovDir[x][y]].y;
4440 if (!IN_LEV_FIELD_AND_IS_FREE(xx, yy))
4441 MovDir[x][y] = old_move_dir;
4445 else if (element == EL_MOLE)
4447 boolean can_move_on =
4448 (MOLE_CAN_ENTER_FIELD(element, move_x, move_y,
4449 IS_AMOEBOID(Feld[move_x][move_y]) ||
4450 Feld[move_x][move_y] == EL_AMOEBA_SHRINKING));
4453 boolean can_turn_left =
4454 (MOLE_CAN_ENTER_FIELD(element, left_x, left_y,
4455 IS_AMOEBOID(Feld[left_x][left_y])));
4457 boolean can_turn_right =
4458 (MOLE_CAN_ENTER_FIELD(element, right_x, right_y,
4459 IS_AMOEBOID(Feld[right_x][right_y])));
4461 if (can_turn_left && can_turn_right)
4462 MovDir[x][y] = (RND(2) ? left_dir : right_dir);
4463 else if (can_turn_left)
4464 MovDir[x][y] = left_dir;
4466 MovDir[x][y] = right_dir;
4469 if (MovDir[x][y] != old_move_dir)
4472 else if (element == EL_BALLOON)
4474 MovDir[x][y] = game.wind_direction;
4477 else if (element == EL_SPRING)
4479 if (MovDir[x][y] & MV_HORIZONTAL &&
4480 (!SPRING_CAN_ENTER_FIELD(element, move_x, move_y) ||
4481 SPRING_CAN_ENTER_FIELD(element, x, y + 1)))
4482 MovDir[x][y] = MV_NONE;
4486 else if (element == EL_ROBOT ||
4487 element == EL_SATELLITE ||
4488 element == EL_PENGUIN)
4490 int attr_x = -1, attr_y = -1;
4501 for (i = 0; i < MAX_PLAYERS; i++)
4503 struct PlayerInfo *player = &stored_player[i];
4504 int jx = player->jx, jy = player->jy;
4506 if (!player->active)
4510 ABS(jx - x) + ABS(jy - y) < ABS(attr_x - x) + ABS(attr_y - y))
4518 if (element == EL_ROBOT && ZX >= 0 && ZY >= 0 &&
4519 (Feld[ZX][ZY] == EL_ROBOT_WHEEL_ACTIVE ||
4520 game.engine_version < VERSION_IDENT(3,1,0,0)))
4526 if (element == EL_PENGUIN)
4529 static int xy[4][2] =
4537 for (i = 0; i < NUM_DIRECTIONS; i++)
4539 int ex = x + xy[i][0];
4540 int ey = y + xy[i][1];
4542 if (IN_LEV_FIELD(ex, ey) && Feld[ex][ey] == EL_EXIT_OPEN)
4551 MovDir[x][y] = MV_NONE;
4553 MovDir[x][y] |= (AllPlayersGone ? MV_RIGHT : MV_LEFT);
4554 else if (attr_x > x)
4555 MovDir[x][y] |= (AllPlayersGone ? MV_LEFT : MV_RIGHT);
4557 MovDir[x][y] |= (AllPlayersGone ? MV_DOWN : MV_UP);
4558 else if (attr_y > y)
4559 MovDir[x][y] |= (AllPlayersGone ? MV_UP : MV_DOWN);
4561 if (element == EL_ROBOT)
4565 if (MovDir[x][y] & MV_HORIZONTAL && MovDir[x][y] & MV_VERTICAL)
4566 MovDir[x][y] &= (RND(2) ? MV_HORIZONTAL : MV_VERTICAL);
4567 Moving2Blocked(x, y, &newx, &newy);
4569 if (IN_LEV_FIELD(newx, newy) && IS_FREE_OR_PLAYER(newx, newy))
4570 MovDelay[x][y] = 8 + 8 * !RND(3);
4572 MovDelay[x][y] = 16;
4574 else if (element == EL_PENGUIN)
4580 if (MovDir[x][y] & MV_HORIZONTAL && MovDir[x][y] & MV_VERTICAL)
4582 boolean first_horiz = RND(2);
4583 int new_move_dir = MovDir[x][y];
4586 new_move_dir & (first_horiz ? MV_HORIZONTAL : MV_VERTICAL);
4587 Moving2Blocked(x, y, &newx, &newy);
4589 if (PENGUIN_CAN_ENTER_FIELD(EL_PENGUIN, newx, newy))
4593 new_move_dir & (!first_horiz ? MV_HORIZONTAL : MV_VERTICAL);
4594 Moving2Blocked(x, y, &newx, &newy);
4596 if (PENGUIN_CAN_ENTER_FIELD(EL_PENGUIN, newx, newy))
4599 MovDir[x][y] = old_move_dir;
4603 else /* (element == EL_SATELLITE) */
4609 if (MovDir[x][y] & MV_HORIZONTAL && MovDir[x][y] & MV_VERTICAL)
4611 boolean first_horiz = RND(2);
4612 int new_move_dir = MovDir[x][y];
4615 new_move_dir & (first_horiz ? MV_HORIZONTAL : MV_VERTICAL);
4616 Moving2Blocked(x, y, &newx, &newy);
4618 if (SATELLITE_CAN_ENTER_FIELD(newx, newy))
4622 new_move_dir & (!first_horiz ? MV_HORIZONTAL : MV_VERTICAL);
4623 Moving2Blocked(x, y, &newx, &newy);
4625 if (SATELLITE_CAN_ENTER_FIELD(newx, newy))
4628 MovDir[x][y] = old_move_dir;
4633 else if (move_pattern == MV_TURNING_LEFT ||
4634 move_pattern == MV_TURNING_RIGHT ||
4635 move_pattern == MV_TURNING_LEFT_RIGHT ||
4636 move_pattern == MV_TURNING_RIGHT_LEFT ||
4637 move_pattern == MV_TURNING_RANDOM ||
4638 move_pattern == MV_ALL_DIRECTIONS)
4640 boolean can_turn_left =
4641 CUSTOM_ELEMENT_CAN_ENTER_FIELD(element, left_x, left_y);
4642 boolean can_turn_right =
4643 CUSTOM_ELEMENT_CAN_ENTER_FIELD(element, right_x,right_y);
4645 if (element_info[element].move_stepsize == 0) /* "not moving" */
4648 if (move_pattern == MV_TURNING_LEFT)
4649 MovDir[x][y] = left_dir;
4650 else if (move_pattern == MV_TURNING_RIGHT)
4651 MovDir[x][y] = right_dir;
4652 else if (move_pattern == MV_TURNING_LEFT_RIGHT)
4653 MovDir[x][y] = (can_turn_left || !can_turn_right ? left_dir : right_dir);
4654 else if (move_pattern == MV_TURNING_RIGHT_LEFT)
4655 MovDir[x][y] = (can_turn_right || !can_turn_left ? right_dir : left_dir);
4656 else if (move_pattern == MV_TURNING_RANDOM)
4657 MovDir[x][y] = (can_turn_left && !can_turn_right ? left_dir :
4658 can_turn_right && !can_turn_left ? right_dir :
4659 RND(2) ? left_dir : right_dir);
4660 else if (can_turn_left && can_turn_right)
4661 MovDir[x][y] = (RND(3) ? (RND(2) ? left_dir : right_dir) : back_dir);
4662 else if (can_turn_left)
4663 MovDir[x][y] = (RND(2) ? left_dir : back_dir);
4664 else if (can_turn_right)
4665 MovDir[x][y] = (RND(2) ? right_dir : back_dir);
4667 MovDir[x][y] = back_dir;
4669 MovDelay[x][y] = GET_NEW_MOVE_DELAY(element);
4671 else if (move_pattern == MV_HORIZONTAL ||
4672 move_pattern == MV_VERTICAL)
4674 if (move_pattern & old_move_dir)
4675 MovDir[x][y] = back_dir;
4676 else if (move_pattern == MV_HORIZONTAL)
4677 MovDir[x][y] = (RND(2) ? MV_LEFT : MV_RIGHT);
4678 else if (move_pattern == MV_VERTICAL)
4679 MovDir[x][y] = (RND(2) ? MV_UP : MV_DOWN);
4681 MovDelay[x][y] = GET_NEW_MOVE_DELAY(element);
4683 else if (move_pattern & MV_ANY_DIRECTION)
4685 MovDir[x][y] = move_pattern;
4686 MovDelay[x][y] = GET_NEW_MOVE_DELAY(element);
4688 else if (move_pattern & MV_WIND_DIRECTION)
4690 MovDir[x][y] = game.wind_direction;
4691 MovDelay[x][y] = GET_NEW_MOVE_DELAY(element);
4693 else if (move_pattern == MV_ALONG_LEFT_SIDE)
4695 if (CUSTOM_ELEMENT_CAN_ENTER_FIELD(element, left_x, left_y))
4696 MovDir[x][y] = left_dir;
4697 else if (!CUSTOM_ELEMENT_CAN_ENTER_FIELD(element, move_x, move_y))
4698 MovDir[x][y] = right_dir;
4700 if (MovDir[x][y] != old_move_dir)
4701 MovDelay[x][y] = GET_NEW_MOVE_DELAY(element);
4703 else if (move_pattern == MV_ALONG_RIGHT_SIDE)
4705 if (CUSTOM_ELEMENT_CAN_ENTER_FIELD(element, right_x, right_y))
4706 MovDir[x][y] = right_dir;
4707 else if (!CUSTOM_ELEMENT_CAN_ENTER_FIELD(element, move_x, move_y))
4708 MovDir[x][y] = left_dir;
4710 if (MovDir[x][y] != old_move_dir)
4711 MovDelay[x][y] = GET_NEW_MOVE_DELAY(element);
4713 else if (move_pattern == MV_TOWARDS_PLAYER ||
4714 move_pattern == MV_AWAY_FROM_PLAYER)
4716 int attr_x = -1, attr_y = -1;
4718 boolean move_away = (move_pattern == MV_AWAY_FROM_PLAYER);
4729 for (i = 0; i < MAX_PLAYERS; i++)
4731 struct PlayerInfo *player = &stored_player[i];
4732 int jx = player->jx, jy = player->jy;
4734 if (!player->active)
4738 ABS(jx - x) + ABS(jy - y) < ABS(attr_x - x) + ABS(attr_y - y))
4746 MovDir[x][y] = MV_NONE;
4748 MovDir[x][y] |= (move_away ? MV_RIGHT : MV_LEFT);
4749 else if (attr_x > x)
4750 MovDir[x][y] |= (move_away ? MV_LEFT : MV_RIGHT);
4752 MovDir[x][y] |= (move_away ? MV_DOWN : MV_UP);
4753 else if (attr_y > y)
4754 MovDir[x][y] |= (move_away ? MV_UP : MV_DOWN);
4756 MovDelay[x][y] = GET_NEW_MOVE_DELAY(element);
4758 if (MovDir[x][y] & MV_HORIZONTAL && MovDir[x][y] & MV_VERTICAL)
4760 boolean first_horiz = RND(2);
4761 int new_move_dir = MovDir[x][y];
4763 if (element_info[element].move_stepsize == 0) /* "not moving" */
4765 first_horiz = (ABS(attr_x - x) >= ABS(attr_y - y));
4766 MovDir[x][y] &= (first_horiz ? MV_HORIZONTAL : MV_VERTICAL);
4772 new_move_dir & (first_horiz ? MV_HORIZONTAL : MV_VERTICAL);
4773 Moving2Blocked(x, y, &newx, &newy);
4775 if (CUSTOM_ELEMENT_CAN_ENTER_FIELD(element, newx, newy))
4779 new_move_dir & (!first_horiz ? MV_HORIZONTAL : MV_VERTICAL);
4780 Moving2Blocked(x, y, &newx, &newy);
4782 if (CUSTOM_ELEMENT_CAN_ENTER_FIELD(element, newx, newy))
4785 MovDir[x][y] = old_move_dir;
4788 else if (move_pattern == MV_WHEN_PUSHED ||
4789 move_pattern == MV_WHEN_DROPPED)
4791 if (!CUSTOM_ELEMENT_CAN_ENTER_FIELD(element, move_x, move_y))
4792 MovDir[x][y] = MV_NONE;
4796 else if (move_pattern & MV_MAZE_RUNNER_STYLE)
4798 static int test_xy[7][2] =
4808 static int test_dir[7] =
4818 boolean hunter_mode = (move_pattern == MV_MAZE_HUNTER);
4819 int move_preference = -1000000; /* start with very low preference */
4820 int new_move_dir = MV_NONE;
4821 int start_test = RND(4);
4824 for (i = 0; i < NUM_DIRECTIONS; i++)
4826 int move_dir = test_dir[start_test + i];
4827 int move_dir_preference;
4829 xx = x + test_xy[start_test + i][0];
4830 yy = y + test_xy[start_test + i][1];
4832 if (hunter_mode && IN_LEV_FIELD(xx, yy) &&
4833 (IS_PLAYER(xx, yy) || Feld[xx][yy] == EL_PLAYER_IS_LEAVING))
4835 new_move_dir = move_dir;
4840 if (!CUSTOM_ELEMENT_CAN_ENTER_FIELD(element, xx, yy))
4843 move_dir_preference = -1 * RunnerVisit[xx][yy];
4844 if (hunter_mode && PlayerVisit[xx][yy] > 0)
4845 move_dir_preference = PlayerVisit[xx][yy];
4847 if (move_dir_preference > move_preference)
4849 /* prefer field that has not been visited for the longest time */
4850 move_preference = move_dir_preference;
4851 new_move_dir = move_dir;
4853 else if (move_dir_preference == move_preference &&
4854 move_dir == old_move_dir)
4856 /* prefer last direction when all directions are preferred equally */
4857 move_preference = move_dir_preference;
4858 new_move_dir = move_dir;
4862 MovDir[x][y] = new_move_dir;
4863 if (old_move_dir != new_move_dir)
4864 MovDelay[x][y] = GET_NEW_MOVE_DELAY(element);
4868 static void TurnRound(int x, int y)
4870 int direction = MovDir[x][y];
4874 GfxDir[x][y] = MovDir[x][y];
4876 if (direction != MovDir[x][y])
4880 GfxAction[x][y] = ACTION_TURNING_FROM_LEFT + MV_DIR_BIT(direction);
4883 static boolean JustBeingPushed(int x, int y)
4887 for (i = 0; i < MAX_PLAYERS; i++)
4889 struct PlayerInfo *player = &stored_player[i];
4891 if (player->active && player->is_pushing && player->MovPos)
4893 int next_jx = player->jx + (player->jx - player->last_jx);
4894 int next_jy = player->jy + (player->jy - player->last_jy);
4896 if (x == next_jx && y == next_jy)
4904 void StartMoving(int x, int y)
4906 boolean started_moving = FALSE; /* some elements can fall _and_ move */
4907 int element = Feld[x][y];
4912 if (MovDelay[x][y] == 0)
4913 GfxAction[x][y] = ACTION_DEFAULT;
4915 if (CAN_FALL(element) && y < lev_fieldy - 1)
4917 if ((x > 0 && IS_PLAYER(x - 1, y)) ||
4918 (x < lev_fieldx - 1 && IS_PLAYER(x + 1, y)))
4919 if (JustBeingPushed(x, y))
4922 if (element == EL_QUICKSAND_FULL)
4924 if (IS_FREE(x, y + 1))
4926 InitMovingField(x, y, MV_DOWN);
4927 started_moving = TRUE;
4929 Feld[x][y] = EL_QUICKSAND_EMPTYING;
4930 Store[x][y] = EL_ROCK;
4932 PlayLevelSoundAction(x, y, ACTION_EMPTYING);
4934 else if (Feld[x][y + 1] == EL_QUICKSAND_EMPTY)
4936 if (!MovDelay[x][y])
4937 MovDelay[x][y] = TILEY + 1;
4946 Feld[x][y] = EL_QUICKSAND_EMPTY;
4947 Feld[x][y + 1] = EL_QUICKSAND_FULL;
4948 Store[x][y + 1] = Store[x][y];
4951 PlayLevelSoundAction(x, y, ACTION_FILLING);
4954 else if ((element == EL_ROCK || element == EL_BD_ROCK) &&
4955 Feld[x][y + 1] == EL_QUICKSAND_EMPTY)
4957 InitMovingField(x, y, MV_DOWN);
4958 started_moving = TRUE;
4960 Feld[x][y] = EL_QUICKSAND_FILLING;
4961 Store[x][y] = element;
4963 PlayLevelSoundAction(x, y, ACTION_FILLING);
4965 else if (element == EL_MAGIC_WALL_FULL)
4967 if (IS_FREE(x, y + 1))
4969 InitMovingField(x, y, MV_DOWN);
4970 started_moving = TRUE;
4972 Feld[x][y] = EL_MAGIC_WALL_EMPTYING;
4973 Store[x][y] = EL_CHANGED(Store[x][y]);
4975 else if (Feld[x][y + 1] == EL_MAGIC_WALL_ACTIVE)
4977 if (!MovDelay[x][y])
4978 MovDelay[x][y] = TILEY/4 + 1;
4987 Feld[x][y] = EL_MAGIC_WALL_ACTIVE;
4988 Feld[x][y + 1] = EL_MAGIC_WALL_FULL;
4989 Store[x][y + 1] = EL_CHANGED(Store[x][y]);
4993 else if (element == EL_BD_MAGIC_WALL_FULL)
4995 if (IS_FREE(x, y + 1))
4997 InitMovingField(x, y, MV_DOWN);
4998 started_moving = TRUE;
5000 Feld[x][y] = EL_BD_MAGIC_WALL_EMPTYING;
5001 Store[x][y] = EL_CHANGED2(Store[x][y]);
5003 else if (Feld[x][y + 1] == EL_BD_MAGIC_WALL_ACTIVE)
5005 if (!MovDelay[x][y])
5006 MovDelay[x][y] = TILEY/4 + 1;
5015 Feld[x][y] = EL_BD_MAGIC_WALL_ACTIVE;
5016 Feld[x][y + 1] = EL_BD_MAGIC_WALL_FULL;
5017 Store[x][y + 1] = EL_CHANGED2(Store[x][y]);
5021 else if (CAN_PASS_MAGIC_WALL(element) &&
5022 (Feld[x][y + 1] == EL_MAGIC_WALL_ACTIVE ||
5023 Feld[x][y + 1] == EL_BD_MAGIC_WALL_ACTIVE))
5025 InitMovingField(x, y, MV_DOWN);
5026 started_moving = TRUE;
5029 (Feld[x][y + 1] == EL_MAGIC_WALL_ACTIVE ? EL_MAGIC_WALL_FILLING :
5030 EL_BD_MAGIC_WALL_FILLING);
5031 Store[x][y] = element;
5033 else if (CAN_FALL(element) && Feld[x][y + 1] == EL_ACID)
5035 SplashAcid(x, y + 1);
5037 InitMovingField(x, y, MV_DOWN);
5038 started_moving = TRUE;
5040 Store[x][y] = EL_ACID;
5042 else if ((game.engine_version >= VERSION_IDENT(3,1,0,0) &&
5043 CheckCollision[x][y] && !IS_FREE(x, y + 1)) ||
5045 (game.engine_version >= VERSION_IDENT(3,0,7,0) &&
5046 CAN_FALL(element) && WasJustFalling[x][y] &&
5047 (Feld[x][y + 1] == EL_BLOCKED || IS_PLAYER(x, y + 1))) ||
5049 (game.engine_version < VERSION_IDENT(2,2,0,7) &&
5050 CAN_FALL(element) && WasJustMoving[x][y] && !Pushed[x][y + 1] &&
5051 (Feld[x][y + 1] == EL_BLOCKED)))
5053 /* this is needed for a special case not covered by calling "Impact()"
5054 from "ContinueMoving()": if an element moves to a tile directly below
5055 another element which was just falling on that tile (which was empty
5056 in the previous frame), the falling element above would just stop
5057 instead of smashing the element below (in previous version, the above
5058 element was just checked for "moving" instead of "falling", resulting
5059 in incorrect smashes caused by horizontal movement of the above
5060 element; also, the case of the player being the element to smash was
5061 simply not covered here... :-/ ) */
5063 CheckCollision[x][y] = 0;
5067 else if (IS_FREE(x, y + 1) && element == EL_SPRING && level.use_spring_bug)
5069 if (MovDir[x][y] == MV_NONE)
5071 InitMovingField(x, y, MV_DOWN);
5072 started_moving = TRUE;
5075 else if (IS_FREE(x, y + 1) || Feld[x][y + 1] == EL_DIAMOND_BREAKING)
5077 if (WasJustFalling[x][y]) /* prevent animation from being restarted */
5078 MovDir[x][y] = MV_DOWN;
5080 InitMovingField(x, y, MV_DOWN);
5081 started_moving = TRUE;
5083 else if (element == EL_AMOEBA_DROP)
5085 Feld[x][y] = EL_AMOEBA_GROWING;
5086 Store[x][y] = EL_AMOEBA_WET;
5088 else if (((IS_SLIPPERY(Feld[x][y + 1]) && !IS_PLAYER(x, y + 1)) ||
5089 (IS_EM_SLIPPERY_WALL(Feld[x][y + 1]) && IS_GEM(element))) &&
5090 !IS_FALLING(x, y + 1) && !WasJustMoving[x][y + 1] &&
5091 element != EL_DX_SUPABOMB && element != EL_SP_DISK_ORANGE)
5093 boolean can_fall_left = (x > 0 && IS_FREE(x - 1, y) &&
5094 (IS_FREE(x - 1, y + 1) ||
5095 Feld[x - 1][y + 1] == EL_ACID));
5096 boolean can_fall_right = (x < lev_fieldx - 1 && IS_FREE(x + 1, y) &&
5097 (IS_FREE(x + 1, y + 1) ||
5098 Feld[x + 1][y + 1] == EL_ACID));
5099 boolean can_fall_any = (can_fall_left || can_fall_right);
5100 boolean can_fall_both = (can_fall_left && can_fall_right);
5101 int slippery_type = element_info[Feld[x][y + 1]].slippery_type;
5103 #if USE_NEW_ALL_SLIPPERY
5104 if (can_fall_any && slippery_type != SLIPPERY_ANY_RANDOM)
5106 if (slippery_type == SLIPPERY_ANY_LEFT_RIGHT && can_fall_both)
5107 can_fall_right = FALSE;
5108 else if (slippery_type == SLIPPERY_ANY_RIGHT_LEFT && can_fall_both)
5109 can_fall_left = FALSE;
5110 else if (slippery_type == SLIPPERY_ONLY_LEFT)
5111 can_fall_right = FALSE;
5112 else if (slippery_type == SLIPPERY_ONLY_RIGHT)
5113 can_fall_left = FALSE;
5115 can_fall_any = (can_fall_left || can_fall_right);
5116 can_fall_both = FALSE;
5119 if (can_fall_any && IS_CUSTOM_ELEMENT(Feld[x][y + 1]))
5121 if (slippery_type == SLIPPERY_ONLY_LEFT)
5122 can_fall_right = FALSE;
5123 else if (slippery_type == SLIPPERY_ONLY_RIGHT)
5124 can_fall_left = FALSE;
5125 else if (slippery_type == SLIPPERY_ANY_LEFT_RIGHT && can_fall_both)
5126 can_fall_right = FALSE;
5127 else if (slippery_type == SLIPPERY_ANY_RIGHT_LEFT && can_fall_both)
5128 can_fall_left = FALSE;
5130 can_fall_any = (can_fall_left || can_fall_right);
5131 can_fall_both = (can_fall_left && can_fall_right);
5135 #if USE_NEW_ALL_SLIPPERY
5137 #if USE_NEW_SP_SLIPPERY
5138 /* !!! better use the same properties as for custom elements here !!! */
5139 else if (game.engine_version >= VERSION_IDENT(3,1,1,0) &&
5140 can_fall_both && IS_SP_ELEMENT(Feld[x][y + 1]))
5142 can_fall_right = FALSE; /* slip down on left side */
5143 can_fall_both = FALSE;
5148 #if USE_NEW_ALL_SLIPPERY
5151 if (element == EL_BD_ROCK || element == EL_BD_DIAMOND)
5152 can_fall_right = FALSE; /* slip down on left side */
5154 can_fall_left = !(can_fall_right = RND(2));
5156 can_fall_both = FALSE;
5161 if (game.emulation == EMU_BOULDERDASH ||
5162 element == EL_BD_ROCK || element == EL_BD_DIAMOND)
5163 can_fall_right = FALSE; /* slip down on left side */
5165 can_fall_left = !(can_fall_right = RND(2));
5167 can_fall_both = FALSE;
5173 /* if not determined otherwise, prefer left side for slipping down */
5174 InitMovingField(x, y, can_fall_left ? MV_LEFT : MV_RIGHT);
5175 started_moving = TRUE;
5179 else if (IS_BELT_ACTIVE(Feld[x][y + 1]) && !CAN_MOVE(element))
5181 else if (IS_BELT_ACTIVE(Feld[x][y + 1]))
5184 boolean left_is_free = (x > 0 && IS_FREE(x - 1, y));
5185 boolean right_is_free = (x < lev_fieldx - 1 && IS_FREE(x + 1, y));
5186 int belt_nr = getBeltNrFromBeltActiveElement(Feld[x][y + 1]);
5187 int belt_dir = game.belt_dir[belt_nr];
5189 if ((belt_dir == MV_LEFT && left_is_free) ||
5190 (belt_dir == MV_RIGHT && right_is_free))
5192 int nextx = (belt_dir == MV_LEFT ? x - 1 : x + 1);
5194 InitMovingField(x, y, belt_dir);
5195 started_moving = TRUE;
5197 Pushed[x][y] = TRUE;
5198 Pushed[nextx][y] = TRUE;
5200 GfxAction[x][y] = ACTION_DEFAULT;
5204 MovDir[x][y] = 0; /* if element was moving, stop it */
5209 /* not "else if" because of elements that can fall and move (EL_SPRING) */
5211 if (CAN_MOVE(element) && !started_moving && MovDir[x][y] != MV_NONE)
5213 if (CAN_MOVE(element) && !started_moving)
5216 int move_pattern = element_info[element].move_pattern;
5221 if (MovDir[x][y] == MV_NONE)
5223 printf("StartMoving(): %d,%d: element %d ['%s'] not moving\n",
5224 x, y, element, element_info[element].token_name);
5225 printf("StartMoving(): This should never happen!\n");
5230 Moving2Blocked(x, y, &newx, &newy);
5232 if (IS_PUSHABLE(element) && JustBeingPushed(x, y))
5235 if (game.engine_version >= VERSION_IDENT(3,1,0,0) &&
5236 CheckCollision[x][y] && !IN_LEV_FIELD_AND_IS_FREE(newx, newy))
5238 WasJustMoving[x][y] = 0;
5239 CheckCollision[x][y] = 0;
5241 TestIfElementHitsCustomElement(x, y, MovDir[x][y]);
5243 if (Feld[x][y] != element) /* element has changed */
5247 if (!MovDelay[x][y]) /* start new movement phase */
5249 /* all objects that can change their move direction after each step
5250 (YAMYAM, DARK_YAMYAM and PACMAN go straight until they hit a wall */
5252 if (element != EL_YAMYAM &&
5253 element != EL_DARK_YAMYAM &&
5254 element != EL_PACMAN &&
5255 !(move_pattern & MV_ANY_DIRECTION) &&
5256 move_pattern != MV_TURNING_LEFT &&
5257 move_pattern != MV_TURNING_RIGHT &&
5258 move_pattern != MV_TURNING_LEFT_RIGHT &&
5259 move_pattern != MV_TURNING_RIGHT_LEFT &&
5260 move_pattern != MV_TURNING_RANDOM)
5264 if (MovDelay[x][y] && (element == EL_BUG ||
5265 element == EL_SPACESHIP ||
5266 element == EL_SP_SNIKSNAK ||
5267 element == EL_SP_ELECTRON ||
5268 element == EL_MOLE))
5269 DrawLevelField(x, y);
5273 if (MovDelay[x][y]) /* wait some time before next movement */
5277 if (element == EL_ROBOT ||
5278 element == EL_YAMYAM ||
5279 element == EL_DARK_YAMYAM)
5281 DrawLevelElementAnimationIfNeeded(x, y, element);
5282 PlayLevelSoundAction(x, y, ACTION_WAITING);
5284 else if (element == EL_SP_ELECTRON)
5285 DrawLevelElementAnimationIfNeeded(x, y, element);
5286 else if (element == EL_DRAGON)
5289 int dir = MovDir[x][y];
5290 int dx = (dir == MV_LEFT ? -1 : dir == MV_RIGHT ? +1 : 0);
5291 int dy = (dir == MV_UP ? -1 : dir == MV_DOWN ? +1 : 0);
5292 int graphic = (dir == MV_LEFT ? IMG_FLAMES_1_LEFT :
5293 dir == MV_RIGHT ? IMG_FLAMES_1_RIGHT :
5294 dir == MV_UP ? IMG_FLAMES_1_UP :
5295 dir == MV_DOWN ? IMG_FLAMES_1_DOWN : IMG_EMPTY);
5296 int frame = getGraphicAnimationFrame(graphic, GfxFrame[x][y]);
5298 GfxAction[x][y] = ACTION_ATTACKING;
5300 if (IS_PLAYER(x, y))
5301 DrawPlayerField(x, y);
5303 DrawLevelField(x, y);
5305 PlayLevelSoundActionIfLoop(x, y, ACTION_ATTACKING);
5307 for (i = 1; i <= 3; i++)
5309 int xx = x + i * dx;
5310 int yy = y + i * dy;
5311 int sx = SCREENX(xx);
5312 int sy = SCREENY(yy);
5313 int flame_graphic = graphic + (i - 1);
5315 if (!IN_LEV_FIELD(xx, yy) || IS_DRAGONFIRE_PROOF(Feld[xx][yy]))
5320 int flamed = MovingOrBlocked2Element(xx, yy);
5324 if (IS_CLASSIC_ENEMY(flamed) || CAN_EXPLODE_BY_DRAGONFIRE(flamed))
5326 else if (IS_MOVING(xx, yy) || IS_BLOCKED(xx, yy))
5327 RemoveMovingField(xx, yy);
5329 RemoveField(xx, yy);
5331 if (IS_CLASSIC_ENEMY(flamed) || CAN_EXPLODE_BY_DRAGONFIRE(flamed))
5334 RemoveMovingField(xx, yy);
5337 ChangeDelay[xx][yy] = 0;
5339 Feld[xx][yy] = EL_FLAMES;
5341 if (IN_SCR_FIELD(sx, sy))
5343 DrawLevelFieldCrumbledSand(xx, yy);
5344 DrawGraphic(sx, sy, flame_graphic, frame);
5349 if (Feld[xx][yy] == EL_FLAMES)
5350 Feld[xx][yy] = EL_EMPTY;
5351 DrawLevelField(xx, yy);
5356 if (MovDelay[x][y]) /* element still has to wait some time */
5358 PlayLevelSoundAction(x, y, ACTION_WAITING);
5364 /* now make next step */
5366 Moving2Blocked(x, y, &newx, &newy); /* get next screen position */
5368 if (DONT_COLLIDE_WITH(element) &&
5369 IN_LEV_FIELD(newx, newy) && IS_PLAYER(newx, newy) &&
5370 !PLAYER_ENEMY_PROTECTED(newx, newy))
5372 TestIfBadThingRunsIntoPlayer(x, y, MovDir[x][y]);
5377 else if (CAN_MOVE_INTO_ACID(element) &&
5378 IN_LEV_FIELD(newx, newy) && Feld[newx][newy] == EL_ACID &&
5379 (MovDir[x][y] == MV_DOWN ||
5380 game.engine_version >= VERSION_IDENT(3,1,0,0)))
5382 SplashAcid(newx, newy);
5383 Store[x][y] = EL_ACID;
5385 else if (element == EL_PENGUIN && IN_LEV_FIELD(newx, newy))
5387 if (Feld[newx][newy] == EL_EXIT_OPEN)
5390 DrawLevelField(x, y);
5392 PlayLevelSound(newx, newy, SND_PENGUIN_PASSING);
5393 if (IN_SCR_FIELD(SCREENX(newx), SCREENY(newy)))
5394 DrawGraphicThruMask(SCREENX(newx),SCREENY(newy), el2img(element), 0);
5396 local_player->friends_still_needed--;
5397 if (!local_player->friends_still_needed &&
5398 !local_player->GameOver && AllPlayersGone)
5399 local_player->LevelSolved = local_player->GameOver = TRUE;
5403 else if (IS_FOOD_PENGUIN(Feld[newx][newy]))
5405 if (DigField(local_player, x, y, newx, newy, 0,0, DF_DIG) == MF_MOVING)
5406 DrawLevelField(newx, newy);
5408 GfxDir[x][y] = MovDir[x][y] = MV_NONE;
5410 else if (!IS_FREE(newx, newy))
5412 GfxAction[x][y] = ACTION_WAITING;
5414 if (IS_PLAYER(x, y))
5415 DrawPlayerField(x, y);
5417 DrawLevelField(x, y);
5422 else if (element == EL_PIG && IN_LEV_FIELD(newx, newy))
5424 if (IS_FOOD_PIG(Feld[newx][newy]))
5426 if (IS_MOVING(newx, newy))
5427 RemoveMovingField(newx, newy);
5430 Feld[newx][newy] = EL_EMPTY;
5431 DrawLevelField(newx, newy);
5434 PlayLevelSound(x, y, SND_PIG_DIGGING);
5436 else if (!IS_FREE(newx, newy))
5438 if (IS_PLAYER(x, y))
5439 DrawPlayerField(x, y);
5441 DrawLevelField(x, y);
5446 else if (IS_CUSTOM_ELEMENT(element) &&
5447 CUSTOM_ELEMENT_CAN_ENTER_FIELD(element, newx, newy))
5449 int new_element = Feld[newx][newy];
5451 if (!IS_FREE(newx, newy))
5453 int action = (IS_DIGGABLE(new_element) ? ACTION_DIGGING :
5454 IS_COLLECTIBLE(new_element) ? ACTION_COLLECTING :
5457 /* no element can dig solid indestructible elements */
5458 if (IS_INDESTRUCTIBLE(new_element) &&
5459 !IS_DIGGABLE(new_element) &&
5460 !IS_COLLECTIBLE(new_element))
5463 if (AmoebaNr[newx][newy] &&
5464 (new_element == EL_AMOEBA_FULL ||
5465 new_element == EL_BD_AMOEBA ||
5466 new_element == EL_AMOEBA_GROWING))
5468 AmoebaCnt[AmoebaNr[newx][newy]]--;
5469 AmoebaCnt2[AmoebaNr[newx][newy]]--;
5472 if (IS_MOVING(newx, newy))
5473 RemoveMovingField(newx, newy);
5476 RemoveField(newx, newy);
5477 DrawLevelField(newx, newy);
5480 /* if digged element was about to explode, prevent the explosion */
5481 ExplodeField[newx][newy] = EX_TYPE_NONE;
5483 PlayLevelSoundAction(x, y, action);
5486 Store[newx][newy] = EL_EMPTY;
5487 if (IS_EQUAL_OR_IN_GROUP(new_element, MOVE_ENTER_EL(element)))
5489 int move_leave_element = element_info[element].move_leave_element;
5491 /* this makes it possible to leave the removed element again */
5492 Store[newx][newy] = (move_leave_element == EL_TRIGGER_ELEMENT ?
5493 new_element : move_leave_element);
5496 if (move_pattern & MV_MAZE_RUNNER_STYLE)
5498 RunnerVisit[x][y] = FrameCounter;
5499 PlayerVisit[x][y] /= 8; /* expire player visit path */
5502 else if (element == EL_DRAGON && IN_LEV_FIELD(newx, newy))
5504 if (!IS_FREE(newx, newy))
5506 if (IS_PLAYER(x, y))
5507 DrawPlayerField(x, y);
5509 DrawLevelField(x, y);
5515 boolean wanna_flame = !RND(10);
5516 int dx = newx - x, dy = newy - y;
5517 int newx1 = newx + 1 * dx, newy1 = newy + 1 * dy;
5518 int newx2 = newx + 2 * dx, newy2 = newy + 2 * dy;
5519 int element1 = (IN_LEV_FIELD(newx1, newy1) ?
5520 MovingOrBlocked2Element(newx1, newy1) : EL_STEELWALL);
5521 int element2 = (IN_LEV_FIELD(newx2, newy2) ?
5522 MovingOrBlocked2Element(newx2, newy2) : EL_STEELWALL);
5525 IS_CLASSIC_ENEMY(element1) ||
5526 IS_CLASSIC_ENEMY(element2)) &&
5527 element1 != EL_DRAGON && element2 != EL_DRAGON &&
5528 element1 != EL_FLAMES && element2 != EL_FLAMES)
5530 ResetGfxAnimation(x, y);
5531 GfxAction[x][y] = ACTION_ATTACKING;
5533 if (IS_PLAYER(x, y))
5534 DrawPlayerField(x, y);
5536 DrawLevelField(x, y);
5538 PlayLevelSound(x, y, SND_DRAGON_ATTACKING);
5540 MovDelay[x][y] = 50;
5544 RemoveField(newx, newy);
5546 Feld[newx][newy] = EL_FLAMES;
5547 if (IN_LEV_FIELD(newx1, newy1) && Feld[newx1][newy1] == EL_EMPTY)
5550 RemoveField(newx1, newy1);
5552 Feld[newx1][newy1] = EL_FLAMES;
5554 if (IN_LEV_FIELD(newx2, newy2) && Feld[newx2][newy2] == EL_EMPTY)
5557 RemoveField(newx2, newy2);
5559 Feld[newx2][newy2] = EL_FLAMES;
5566 else if (element == EL_YAMYAM && IN_LEV_FIELD(newx, newy) &&
5567 Feld[newx][newy] == EL_DIAMOND)
5569 if (IS_MOVING(newx, newy))
5570 RemoveMovingField(newx, newy);
5573 Feld[newx][newy] = EL_EMPTY;
5574 DrawLevelField(newx, newy);
5577 PlayLevelSound(x, y, SND_YAMYAM_DIGGING);
5579 else if (element == EL_DARK_YAMYAM && IN_LEV_FIELD(newx, newy) &&
5580 IS_FOOD_DARK_YAMYAM(Feld[newx][newy]))
5582 if (AmoebaNr[newx][newy])
5584 AmoebaCnt2[AmoebaNr[newx][newy]]--;
5585 if (Feld[newx][newy] == EL_AMOEBA_FULL ||
5586 Feld[newx][newy] == EL_BD_AMOEBA)
5587 AmoebaCnt[AmoebaNr[newx][newy]]--;
5592 if (IS_MOVING(newx, newy) || IS_BLOCKED(newx, newy))
5594 RemoveMovingField(newx, newy);
5597 if (IS_MOVING(newx, newy))
5599 RemoveMovingField(newx, newy);
5604 Feld[newx][newy] = EL_EMPTY;
5605 DrawLevelField(newx, newy);
5608 PlayLevelSound(x, y, SND_DARK_YAMYAM_DIGGING);
5610 else if ((element == EL_PACMAN || element == EL_MOLE)
5611 && IN_LEV_FIELD(newx, newy) && IS_AMOEBOID(Feld[newx][newy]))
5613 if (AmoebaNr[newx][newy])
5615 AmoebaCnt2[AmoebaNr[newx][newy]]--;
5616 if (Feld[newx][newy] == EL_AMOEBA_FULL ||
5617 Feld[newx][newy] == EL_BD_AMOEBA)
5618 AmoebaCnt[AmoebaNr[newx][newy]]--;
5621 if (element == EL_MOLE)
5623 Feld[newx][newy] = EL_AMOEBA_SHRINKING;
5624 PlayLevelSound(x, y, SND_MOLE_DIGGING);
5626 ResetGfxAnimation(x, y);
5627 GfxAction[x][y] = ACTION_DIGGING;
5628 DrawLevelField(x, y);
5630 MovDelay[newx][newy] = 0; /* start amoeba shrinking delay */
5632 return; /* wait for shrinking amoeba */
5634 else /* element == EL_PACMAN */
5636 Feld[newx][newy] = EL_EMPTY;
5637 DrawLevelField(newx, newy);
5638 PlayLevelSound(x, y, SND_PACMAN_DIGGING);
5641 else if (element == EL_MOLE && IN_LEV_FIELD(newx, newy) &&
5642 (Feld[newx][newy] == EL_AMOEBA_SHRINKING ||
5643 (Feld[newx][newy] == EL_EMPTY && Stop[newx][newy])))
5645 /* wait for shrinking amoeba to completely disappear */
5648 else if (!IN_LEV_FIELD(newx, newy) || !IS_FREE(newx, newy))
5650 /* object was running against a wall */
5655 /* !!! NEW "CE_BLOCKED" STUFF !!! -- DOES NOT WORK YET... !!! */
5656 if (move_pattern & MV_ANY_DIRECTION &&
5657 move_pattern == MovDir[x][y])
5659 int blocking_element =
5660 (IN_LEV_FIELD(newx, newy) ? Feld[newx][newy] : BorderElement);
5662 CheckElementChangeBySide(x, y, element, blocking_element, CE_BLOCKED,
5665 element = Feld[x][y]; /* element might have changed */
5669 if (GFX_ELEMENT(element) != EL_SAND) /* !!! FIX THIS (crumble) !!! */
5670 DrawLevelElementAnimation(x, y, element);
5672 if (DONT_TOUCH(element))
5673 TestIfBadThingTouchesPlayer(x, y);
5678 InitMovingField(x, y, MovDir[x][y]);
5680 PlayLevelSoundAction(x, y, ACTION_MOVING);
5684 ContinueMoving(x, y);
5687 void ContinueMoving(int x, int y)
5689 int element = Feld[x][y];
5690 int stored = Store[x][y];
5691 struct ElementInfo *ei = &element_info[element];
5692 int direction = MovDir[x][y];
5693 int dx = (direction == MV_LEFT ? -1 : direction == MV_RIGHT ? +1 : 0);
5694 int dy = (direction == MV_UP ? -1 : direction == MV_DOWN ? +1 : 0);
5695 int newx = x + dx, newy = y + dy;
5696 boolean pushed_by_player = (Pushed[x][y] && IS_PLAYER(x, y));
5697 boolean pushed_by_conveyor = (Pushed[x][y] && !IS_PLAYER(x, y));
5698 boolean last_line = (newy == lev_fieldy - 1);
5700 MovPos[x][y] += getElementMoveStepsize(x, y);
5702 if (pushed_by_player) /* special case: moving object pushed by player */
5703 MovPos[x][y] = SIGN(MovPos[x][y]) * (TILEX - ABS(PLAYERINFO(x,y)->MovPos));
5705 if (ABS(MovPos[x][y]) < TILEX)
5707 DrawLevelField(x, y);
5709 return; /* element is still moving */
5712 /* element reached destination field */
5714 Feld[x][y] = EL_EMPTY;
5715 Feld[newx][newy] = element;
5716 MovPos[x][y] = 0; /* force "not moving" for "crumbled sand" */
5718 if (Store[x][y] == EL_ACID) /* element is moving into acid pool */
5720 element = Feld[newx][newy] = EL_ACID;
5722 else if (element == EL_MOLE)
5724 Feld[x][y] = EL_SAND;
5726 DrawLevelFieldCrumbledSandNeighbours(x, y);
5728 else if (element == EL_QUICKSAND_FILLING)
5730 element = Feld[newx][newy] = get_next_element(element);
5731 Store[newx][newy] = Store[x][y];
5733 else if (element == EL_QUICKSAND_EMPTYING)
5735 Feld[x][y] = get_next_element(element);
5736 element = Feld[newx][newy] = Store[x][y];
5738 else if (element == EL_MAGIC_WALL_FILLING)
5740 element = Feld[newx][newy] = get_next_element(element);
5741 if (!game.magic_wall_active)
5742 element = Feld[newx][newy] = EL_MAGIC_WALL_DEAD;
5743 Store[newx][newy] = Store[x][y];
5745 else if (element == EL_MAGIC_WALL_EMPTYING)
5747 Feld[x][y] = get_next_element(element);
5748 if (!game.magic_wall_active)
5749 Feld[x][y] = EL_MAGIC_WALL_DEAD;
5750 element = Feld[newx][newy] = Store[x][y];
5752 #if USE_NEW_CUSTOM_VALUE
5753 InitField(newx, newy, FALSE);
5756 else if (element == EL_BD_MAGIC_WALL_FILLING)
5758 element = Feld[newx][newy] = get_next_element(element);
5759 if (!game.magic_wall_active)
5760 element = Feld[newx][newy] = EL_BD_MAGIC_WALL_DEAD;
5761 Store[newx][newy] = Store[x][y];
5763 else if (element == EL_BD_MAGIC_WALL_EMPTYING)
5765 Feld[x][y] = get_next_element(element);
5766 if (!game.magic_wall_active)
5767 Feld[x][y] = EL_BD_MAGIC_WALL_DEAD;
5768 element = Feld[newx][newy] = Store[x][y];
5770 #if USE_NEW_CUSTOM_VALUE
5771 InitField(newx, newy, FALSE);
5774 else if (element == EL_AMOEBA_DROPPING)
5776 Feld[x][y] = get_next_element(element);
5777 element = Feld[newx][newy] = Store[x][y];
5779 else if (element == EL_SOKOBAN_OBJECT)
5782 Feld[x][y] = Back[x][y];
5784 if (Back[newx][newy])
5785 Feld[newx][newy] = EL_SOKOBAN_FIELD_FULL;
5787 Back[x][y] = Back[newx][newy] = 0;
5790 Store[x][y] = EL_EMPTY;
5795 MovDelay[newx][newy] = 0;
5797 if (CAN_CHANGE(element))
5799 /* copy element change control values to new field */
5800 ChangeDelay[newx][newy] = ChangeDelay[x][y];
5801 ChangePage[newx][newy] = ChangePage[x][y];
5802 Changed[newx][newy] = Changed[x][y];
5803 ChangeEvent[newx][newy] = ChangeEvent[x][y];
5805 #if USE_NEW_CUSTOM_VALUE
5806 CustomValue[newx][newy] = CustomValue[x][y];
5810 ChangeDelay[x][y] = 0;
5811 ChangePage[x][y] = -1;
5813 ChangeEvent[x][y] = -1;
5815 #if USE_NEW_CUSTOM_VALUE
5816 CustomValue[x][y] = 0;
5819 /* copy animation control values to new field */
5820 GfxFrame[newx][newy] = GfxFrame[x][y];
5821 GfxRandom[newx][newy] = GfxRandom[x][y]; /* keep same random value */
5822 GfxAction[newx][newy] = GfxAction[x][y]; /* keep action one frame */
5823 GfxDir[newx][newy] = GfxDir[x][y]; /* keep element direction */
5825 Pushed[x][y] = Pushed[newx][newy] = FALSE;
5827 /* some elements can leave other elements behind after moving */
5828 if (IS_CUSTOM_ELEMENT(element) && ei->move_leave_element != EL_EMPTY &&
5829 (ei->move_leave_type == LEAVE_TYPE_UNLIMITED || stored != EL_EMPTY) &&
5830 (!IS_PLAYER(x, y) || IS_WALKABLE(ei->move_leave_element)))
5832 int move_leave_element = ei->move_leave_element;
5834 /* this makes it possible to leave the removed element again */
5835 if (ei->move_leave_type == LEAVE_TYPE_LIMITED &&
5836 ei->move_leave_element == EL_TRIGGER_ELEMENT)
5837 move_leave_element = stored;
5839 Feld[x][y] = move_leave_element;
5841 if (element_info[Feld[x][y]].move_direction_initial == MV_START_PREVIOUS)
5842 MovDir[x][y] = direction;
5844 InitField(x, y, FALSE);
5846 if (GFX_CRUMBLED(Feld[x][y]))
5847 DrawLevelFieldCrumbledSandNeighbours(x, y);
5849 if (ELEM_IS_PLAYER(move_leave_element))
5850 RelocatePlayer(x, y, move_leave_element);
5853 /* do this after checking for left-behind element */
5854 ResetGfxAnimation(x, y); /* reset animation values for old field */
5856 if (!CAN_MOVE(element) ||
5857 (CAN_FALL(element) && direction == MV_DOWN &&
5858 (element == EL_SPRING ||
5859 element_info[element].move_pattern == MV_WHEN_PUSHED ||
5860 element_info[element].move_pattern == MV_WHEN_DROPPED)))
5861 GfxDir[x][y] = MovDir[newx][newy] = 0;
5863 DrawLevelField(x, y);
5864 DrawLevelField(newx, newy);
5866 Stop[newx][newy] = TRUE; /* ignore this element until the next frame */
5868 /* prevent pushed element from moving on in pushed direction */
5869 if (pushed_by_player && CAN_MOVE(element) &&
5870 element_info[element].move_pattern & MV_ANY_DIRECTION &&
5871 !(element_info[element].move_pattern & direction))
5872 TurnRound(newx, newy);
5874 /* prevent elements on conveyor belt from moving on in last direction */
5875 if (pushed_by_conveyor && CAN_FALL(element) &&
5876 direction & MV_HORIZONTAL)
5877 MovDir[newx][newy] = 0;
5879 if (!pushed_by_player)
5881 int nextx = newx + dx, nexty = newy + dy;
5882 boolean check_collision_again = IN_LEV_FIELD_AND_IS_FREE(nextx, nexty);
5884 WasJustMoving[newx][newy] = 3;
5886 if (CAN_FALL(element) && direction == MV_DOWN)
5887 WasJustFalling[newx][newy] = 3;
5889 if ((!CAN_FALL(element) || direction == MV_DOWN) && check_collision_again)
5890 CheckCollision[newx][newy] = 2;
5893 if (DONT_TOUCH(element)) /* object may be nasty to player or others */
5895 TestIfBadThingTouchesPlayer(newx, newy);
5896 TestIfBadThingTouchesFriend(newx, newy);
5898 if (!IS_CUSTOM_ELEMENT(element))
5899 TestIfBadThingTouchesOtherBadThing(newx, newy);
5901 else if (element == EL_PENGUIN)
5902 TestIfFriendTouchesBadThing(newx, newy);
5904 /* give the player one last chance (one more frame) to move away */
5905 if (CAN_FALL(element) && direction == MV_DOWN &&
5906 (last_line || (!IS_FREE(x, newy + 1) &&
5907 (!IS_PLAYER(x, newy + 1) ||
5908 game.engine_version < VERSION_IDENT(3,1,1,0)))))
5911 if (pushed_by_player && !game.use_change_when_pushing_bug)
5913 int push_side = MV_DIR_OPPOSITE(direction);
5914 struct PlayerInfo *player = PLAYERINFO(x, y);
5916 CheckElementChangeByPlayer(newx, newy, element, CE_PUSHED_BY_PLAYER,
5917 player->index_bit, push_side);
5918 CheckTriggeredElementChangeByPlayer(newx,newy, element, CE_PLAYER_PUSHES_X,
5919 player->index_bit, push_side);
5922 CheckTriggeredElementChangeBySide(x, y, element, CE_MOVE_OF_X, direction);
5924 TestIfElementTouchesCustomElement(x, y); /* empty or new element */
5926 TestIfElementHitsCustomElement(newx, newy, direction);
5927 TestIfPlayerTouchesCustomElement(newx, newy);
5928 TestIfElementTouchesCustomElement(newx, newy);
5931 int AmoebeNachbarNr(int ax, int ay)
5934 int element = Feld[ax][ay];
5936 static int xy[4][2] =
5944 for (i = 0; i < NUM_DIRECTIONS; i++)
5946 int x = ax + xy[i][0];
5947 int y = ay + xy[i][1];
5949 if (!IN_LEV_FIELD(x, y))
5952 if (Feld[x][y] == element && AmoebaNr[x][y] > 0)
5953 group_nr = AmoebaNr[x][y];
5959 void AmoebenVereinigen(int ax, int ay)
5961 int i, x, y, xx, yy;
5962 int new_group_nr = AmoebaNr[ax][ay];
5963 static int xy[4][2] =
5971 if (new_group_nr == 0)
5974 for (i = 0; i < NUM_DIRECTIONS; i++)
5979 if (!IN_LEV_FIELD(x, y))
5982 if ((Feld[x][y] == EL_AMOEBA_FULL ||
5983 Feld[x][y] == EL_BD_AMOEBA ||
5984 Feld[x][y] == EL_AMOEBA_DEAD) &&
5985 AmoebaNr[x][y] != new_group_nr)
5987 int old_group_nr = AmoebaNr[x][y];
5989 if (old_group_nr == 0)
5992 AmoebaCnt[new_group_nr] += AmoebaCnt[old_group_nr];
5993 AmoebaCnt[old_group_nr] = 0;
5994 AmoebaCnt2[new_group_nr] += AmoebaCnt2[old_group_nr];
5995 AmoebaCnt2[old_group_nr] = 0;
5997 for (yy = 0; yy < lev_fieldy; yy++)
5999 for (xx = 0; xx < lev_fieldx; xx++)
6001 if (AmoebaNr[xx][yy] == old_group_nr)
6002 AmoebaNr[xx][yy] = new_group_nr;
6009 void AmoebeUmwandeln(int ax, int ay)
6013 if (Feld[ax][ay] == EL_AMOEBA_DEAD)
6015 int group_nr = AmoebaNr[ax][ay];
6020 printf("AmoebeUmwandeln(): ax = %d, ay = %d\n", ax, ay);
6021 printf("AmoebeUmwandeln(): This should never happen!\n");
6026 for (y = 0; y < lev_fieldy; y++)
6028 for (x = 0; x < lev_fieldx; x++)
6030 if (Feld[x][y] == EL_AMOEBA_DEAD && AmoebaNr[x][y] == group_nr)
6033 Feld[x][y] = EL_AMOEBA_TO_DIAMOND;
6037 PlayLevelSound(ax, ay, (IS_GEM(level.amoeba_content) ?
6038 SND_AMOEBA_TURNING_TO_GEM :
6039 SND_AMOEBA_TURNING_TO_ROCK));
6044 static int xy[4][2] =
6052 for (i = 0; i < NUM_DIRECTIONS; i++)
6057 if (!IN_LEV_FIELD(x, y))
6060 if (Feld[x][y] == EL_AMOEBA_TO_DIAMOND)
6062 PlayLevelSound(x, y, (IS_GEM(level.amoeba_content) ?
6063 SND_AMOEBA_TURNING_TO_GEM :
6064 SND_AMOEBA_TURNING_TO_ROCK));
6071 void AmoebeUmwandelnBD(int ax, int ay, int new_element)
6074 int group_nr = AmoebaNr[ax][ay];
6075 boolean done = FALSE;
6080 printf("AmoebeUmwandelnBD(): ax = %d, ay = %d\n", ax, ay);
6081 printf("AmoebeUmwandelnBD(): This should never happen!\n");
6086 for (y = 0; y < lev_fieldy; y++)
6088 for (x = 0; x < lev_fieldx; x++)
6090 if (AmoebaNr[x][y] == group_nr &&
6091 (Feld[x][y] == EL_AMOEBA_DEAD ||
6092 Feld[x][y] == EL_BD_AMOEBA ||
6093 Feld[x][y] == EL_AMOEBA_GROWING))
6096 Feld[x][y] = new_element;
6097 InitField(x, y, FALSE);
6098 DrawLevelField(x, y);
6105 PlayLevelSound(ax, ay, (new_element == EL_BD_ROCK ?
6106 SND_BD_AMOEBA_TURNING_TO_ROCK :
6107 SND_BD_AMOEBA_TURNING_TO_GEM));
6110 void AmoebeWaechst(int x, int y)
6112 static unsigned long sound_delay = 0;
6113 static unsigned long sound_delay_value = 0;
6115 if (!MovDelay[x][y]) /* start new growing cycle */
6119 if (DelayReached(&sound_delay, sound_delay_value))
6121 PlayLevelSoundElementAction(x, y, Store[x][y], ACTION_GROWING);
6122 sound_delay_value = 30;
6126 if (MovDelay[x][y]) /* wait some time before growing bigger */
6129 if (MovDelay[x][y]/2 && IN_SCR_FIELD(SCREENX(x), SCREENY(y)))
6131 int frame = getGraphicAnimationFrame(IMG_AMOEBA_GROWING,
6132 6 - MovDelay[x][y]);
6134 DrawGraphic(SCREENX(x), SCREENY(y), IMG_AMOEBA_GROWING, frame);
6137 if (!MovDelay[x][y])
6139 Feld[x][y] = Store[x][y];
6141 DrawLevelField(x, y);
6146 void AmoebaDisappearing(int x, int y)
6148 static unsigned long sound_delay = 0;
6149 static unsigned long sound_delay_value = 0;
6151 if (!MovDelay[x][y]) /* start new shrinking cycle */
6155 if (DelayReached(&sound_delay, sound_delay_value))
6156 sound_delay_value = 30;
6159 if (MovDelay[x][y]) /* wait some time before shrinking */
6162 if (MovDelay[x][y]/2 && IN_SCR_FIELD(SCREENX(x), SCREENY(y)))
6164 int frame = getGraphicAnimationFrame(IMG_AMOEBA_SHRINKING,
6165 6 - MovDelay[x][y]);
6167 DrawGraphic(SCREENX(x), SCREENY(y), IMG_AMOEBA_SHRINKING, frame);
6170 if (!MovDelay[x][y])
6172 Feld[x][y] = EL_EMPTY;
6173 DrawLevelField(x, y);
6175 /* don't let mole enter this field in this cycle;
6176 (give priority to objects falling to this field from above) */
6182 void AmoebeAbleger(int ax, int ay)
6185 int element = Feld[ax][ay];
6186 int graphic = el2img(element);
6187 int newax = ax, neway = ay;
6188 static int xy[4][2] =
6196 if (!level.amoeba_speed)
6198 Feld[ax][ay] = EL_AMOEBA_DEAD;
6199 DrawLevelField(ax, ay);
6203 if (IS_ANIMATED(graphic))
6204 DrawLevelGraphicAnimationIfNeeded(ax, ay, graphic);
6206 if (!MovDelay[ax][ay]) /* start making new amoeba field */
6207 MovDelay[ax][ay] = RND(FRAMES_PER_SECOND * 25 / (1 + level.amoeba_speed));
6209 if (MovDelay[ax][ay]) /* wait some time before making new amoeba */
6212 if (MovDelay[ax][ay])
6216 if (element == EL_AMOEBA_WET) /* object is an acid / amoeba drop */
6219 int x = ax + xy[start][0];
6220 int y = ay + xy[start][1];
6222 if (!IN_LEV_FIELD(x, y))
6225 if (IS_FREE(x, y) ||
6226 CAN_GROW_INTO(Feld[x][y]) ||
6227 Feld[x][y] == EL_QUICKSAND_EMPTY)
6233 if (newax == ax && neway == ay)
6236 else /* normal or "filled" (BD style) amoeba */
6239 boolean waiting_for_player = FALSE;
6241 for (i = 0; i < NUM_DIRECTIONS; i++)
6243 int j = (start + i) % 4;
6244 int x = ax + xy[j][0];
6245 int y = ay + xy[j][1];
6247 if (!IN_LEV_FIELD(x, y))
6250 if (IS_FREE(x, y) ||
6251 CAN_GROW_INTO(Feld[x][y]) ||
6252 Feld[x][y] == EL_QUICKSAND_EMPTY)
6258 else if (IS_PLAYER(x, y))
6259 waiting_for_player = TRUE;
6262 if (newax == ax && neway == ay) /* amoeba cannot grow */
6264 if (i == 4 && (!waiting_for_player || element == EL_BD_AMOEBA))
6266 Feld[ax][ay] = EL_AMOEBA_DEAD;
6267 DrawLevelField(ax, ay);
6268 AmoebaCnt[AmoebaNr[ax][ay]]--;
6270 if (AmoebaCnt[AmoebaNr[ax][ay]] <= 0) /* amoeba is completely dead */
6272 if (element == EL_AMOEBA_FULL)
6273 AmoebeUmwandeln(ax, ay);
6274 else if (element == EL_BD_AMOEBA)
6275 AmoebeUmwandelnBD(ax, ay, level.amoeba_content);
6280 else if (element == EL_AMOEBA_FULL || element == EL_BD_AMOEBA)
6282 /* amoeba gets larger by growing in some direction */
6284 int new_group_nr = AmoebaNr[ax][ay];
6287 if (new_group_nr == 0)
6289 printf("AmoebeAbleger(): newax = %d, neway = %d\n", newax, neway);
6290 printf("AmoebeAbleger(): This should never happen!\n");
6295 AmoebaNr[newax][neway] = new_group_nr;
6296 AmoebaCnt[new_group_nr]++;
6297 AmoebaCnt2[new_group_nr]++;
6299 /* if amoeba touches other amoeba(s) after growing, unify them */
6300 AmoebenVereinigen(newax, neway);
6302 if (element == EL_BD_AMOEBA && AmoebaCnt2[new_group_nr] >= 200)
6304 AmoebeUmwandelnBD(newax, neway, EL_BD_ROCK);
6310 if (element != EL_AMOEBA_WET || neway < ay || !IS_FREE(newax, neway) ||
6311 (neway == lev_fieldy - 1 && newax != ax))
6313 Feld[newax][neway] = EL_AMOEBA_GROWING; /* creation of new amoeba */
6314 Store[newax][neway] = element;
6316 else if (neway == ay)
6318 Feld[newax][neway] = EL_AMOEBA_DROP; /* drop left/right of amoeba */
6320 PlayLevelSoundAction(newax, neway, ACTION_GROWING);
6324 InitMovingField(ax, ay, MV_DOWN); /* drop dripping from amoeba */
6325 Feld[ax][ay] = EL_AMOEBA_DROPPING;
6326 Store[ax][ay] = EL_AMOEBA_DROP;
6327 ContinueMoving(ax, ay);
6331 DrawLevelField(newax, neway);
6334 void Life(int ax, int ay)
6338 static int life[4] = { 2, 3, 3, 3 }; /* parameters for "game of life" */
6341 int element = Feld[ax][ay];
6342 int graphic = el2img(element);
6343 int *life_parameter = (element == EL_GAME_OF_LIFE ? level.game_of_life :
6345 boolean changed = FALSE;
6347 if (IS_ANIMATED(graphic))
6348 DrawLevelGraphicAnimationIfNeeded(ax, ay, graphic);
6353 if (!MovDelay[ax][ay]) /* start new "game of life" cycle */
6354 MovDelay[ax][ay] = life_time;
6356 if (MovDelay[ax][ay]) /* wait some time before next cycle */
6359 if (MovDelay[ax][ay])
6363 for (y1 = -1; y1 < 2; y1++) for (x1 = -1; x1 < 2; x1++)
6365 int xx = ax+x1, yy = ay+y1;
6368 if (!IN_LEV_FIELD(xx, yy))
6371 for (y2 = -1; y2 < 2; y2++) for (x2 = -1; x2 < 2; x2++)
6373 int x = xx+x2, y = yy+y2;
6375 if (!IN_LEV_FIELD(x, y) || (x == xx && y == yy))
6378 if (((Feld[x][y] == element ||
6379 (element == EL_GAME_OF_LIFE && IS_PLAYER(x, y))) &&
6381 (IS_FREE(x, y) && Stop[x][y]))
6385 if (xx == ax && yy == ay) /* field in the middle */
6387 if (nachbarn < life_parameter[0] ||
6388 nachbarn > life_parameter[1])
6390 Feld[xx][yy] = EL_EMPTY;
6392 DrawLevelField(xx, yy);
6393 Stop[xx][yy] = TRUE;
6397 else if (IS_FREE(xx, yy) || CAN_GROW_INTO(Feld[xx][yy]))
6398 { /* free border field */
6399 if (nachbarn >= life_parameter[2] &&
6400 nachbarn <= life_parameter[3])
6402 Feld[xx][yy] = element;
6403 MovDelay[xx][yy] = (element == EL_GAME_OF_LIFE ? 0 : life_time-1);
6405 DrawLevelField(xx, yy);
6406 Stop[xx][yy] = TRUE;
6413 PlayLevelSound(ax, ay, element == EL_BIOMAZE ? SND_BIOMAZE_GROWING :
6414 SND_GAME_OF_LIFE_GROWING);
6417 static void InitRobotWheel(int x, int y)
6419 ChangeDelay[x][y] = level.time_wheel * FRAMES_PER_SECOND;
6422 static void RunRobotWheel(int x, int y)
6424 PlayLevelSound(x, y, SND_ROBOT_WHEEL_ACTIVE);
6427 static void StopRobotWheel(int x, int y)
6429 if (ZX == x && ZY == y)
6433 static void InitTimegateWheel(int x, int y)
6435 ChangeDelay[x][y] = level.time_timegate * FRAMES_PER_SECOND;
6438 static void RunTimegateWheel(int x, int y)
6440 PlayLevelSound(x, y, SND_TIMEGATE_SWITCH_ACTIVE);
6443 void CheckExit(int x, int y)
6445 if (local_player->gems_still_needed > 0 ||
6446 local_player->sokobanfields_still_needed > 0 ||
6447 local_player->lights_still_needed > 0)
6449 int element = Feld[x][y];
6450 int graphic = el2img(element);
6452 if (IS_ANIMATED(graphic))
6453 DrawLevelGraphicAnimationIfNeeded(x, y, graphic);
6458 if (AllPlayersGone) /* do not re-open exit door closed after last player */
6461 Feld[x][y] = EL_EXIT_OPENING;
6463 PlayLevelSoundNearest(x, y, SND_CLASS_EXIT_OPENING);
6466 void CheckExitSP(int x, int y)
6468 if (local_player->gems_still_needed > 0)
6470 int element = Feld[x][y];
6471 int graphic = el2img(element);
6473 if (IS_ANIMATED(graphic))
6474 DrawLevelGraphicAnimationIfNeeded(x, y, graphic);
6479 if (AllPlayersGone) /* do not re-open exit door closed after last player */
6482 Feld[x][y] = EL_SP_EXIT_OPENING;
6484 PlayLevelSoundNearest(x, y, SND_CLASS_SP_EXIT_OPENING);
6487 static void CloseAllOpenTimegates()
6491 for (y = 0; y < lev_fieldy; y++)
6493 for (x = 0; x < lev_fieldx; x++)
6495 int element = Feld[x][y];
6497 if (element == EL_TIMEGATE_OPEN || element == EL_TIMEGATE_OPENING)
6499 Feld[x][y] = EL_TIMEGATE_CLOSING;
6501 PlayLevelSoundAction(x, y, ACTION_CLOSING);
6507 void EdelsteinFunkeln(int x, int y)
6509 if (!IN_SCR_FIELD(SCREENX(x), SCREENY(y)) || IS_MOVING(x, y))
6512 if (Feld[x][y] == EL_BD_DIAMOND)
6515 if (MovDelay[x][y] == 0) /* next animation frame */
6516 MovDelay[x][y] = 11 * !SimpleRND(500);
6518 if (MovDelay[x][y] != 0) /* wait some time before next frame */
6522 if (setup.direct_draw && MovDelay[x][y])
6523 SetDrawtoField(DRAW_BUFFERED);
6525 DrawLevelElementAnimation(x, y, Feld[x][y]);
6527 if (MovDelay[x][y] != 0)
6529 int frame = getGraphicAnimationFrame(IMG_TWINKLE_WHITE,
6530 10 - MovDelay[x][y]);
6532 DrawGraphicThruMask(SCREENX(x), SCREENY(y), IMG_TWINKLE_WHITE, frame);
6534 if (setup.direct_draw)
6538 dest_x = FX + SCREENX(x) * TILEX;
6539 dest_y = FY + SCREENY(y) * TILEY;
6541 BlitBitmap(drawto_field, window,
6542 dest_x, dest_y, TILEX, TILEY, dest_x, dest_y);
6543 SetDrawtoField(DRAW_DIRECT);
6549 void MauerWaechst(int x, int y)
6553 if (!MovDelay[x][y]) /* next animation frame */
6554 MovDelay[x][y] = 3 * delay;
6556 if (MovDelay[x][y]) /* wait some time before next frame */
6560 if (IN_SCR_FIELD(SCREENX(x), SCREENY(y)))
6562 int graphic = el_dir2img(Feld[x][y], GfxDir[x][y]);
6563 int frame = getGraphicAnimationFrame(graphic, 17 - MovDelay[x][y]);
6565 DrawGraphic(SCREENX(x), SCREENY(y), graphic, frame);
6568 if (!MovDelay[x][y])
6570 if (MovDir[x][y] == MV_LEFT)
6572 if (IN_LEV_FIELD(x - 1, y) && IS_WALL(Feld[x - 1][y]))
6573 DrawLevelField(x - 1, y);
6575 else if (MovDir[x][y] == MV_RIGHT)
6577 if (IN_LEV_FIELD(x + 1, y) && IS_WALL(Feld[x + 1][y]))
6578 DrawLevelField(x + 1, y);
6580 else if (MovDir[x][y] == MV_UP)
6582 if (IN_LEV_FIELD(x, y - 1) && IS_WALL(Feld[x][y - 1]))
6583 DrawLevelField(x, y - 1);
6587 if (IN_LEV_FIELD(x, y + 1) && IS_WALL(Feld[x][y + 1]))
6588 DrawLevelField(x, y + 1);
6591 Feld[x][y] = Store[x][y];
6593 GfxDir[x][y] = MovDir[x][y] = MV_NONE;
6594 DrawLevelField(x, y);
6599 void MauerAbleger(int ax, int ay)
6601 int element = Feld[ax][ay];
6602 int graphic = el2img(element);
6603 boolean oben_frei = FALSE, unten_frei = FALSE;
6604 boolean links_frei = FALSE, rechts_frei = FALSE;
6605 boolean oben_massiv = FALSE, unten_massiv = FALSE;
6606 boolean links_massiv = FALSE, rechts_massiv = FALSE;
6607 boolean new_wall = FALSE;
6609 if (IS_ANIMATED(graphic))
6610 DrawLevelGraphicAnimationIfNeeded(ax, ay, graphic);
6612 if (!MovDelay[ax][ay]) /* start building new wall */
6613 MovDelay[ax][ay] = 6;
6615 if (MovDelay[ax][ay]) /* wait some time before building new wall */
6618 if (MovDelay[ax][ay])
6622 if (IN_LEV_FIELD(ax, ay-1) && IS_FREE(ax, ay-1))
6624 if (IN_LEV_FIELD(ax, ay+1) && IS_FREE(ax, ay+1))
6626 if (IN_LEV_FIELD(ax-1, ay) && IS_FREE(ax-1, ay))
6628 if (IN_LEV_FIELD(ax+1, ay) && IS_FREE(ax+1, ay))
6631 if (element == EL_EXPANDABLE_WALL_VERTICAL ||
6632 element == EL_EXPANDABLE_WALL_ANY)
6636 Feld[ax][ay-1] = EL_EXPANDABLE_WALL_GROWING;
6637 Store[ax][ay-1] = element;
6638 GfxDir[ax][ay-1] = MovDir[ax][ay-1] = MV_UP;
6639 if (IN_SCR_FIELD(SCREENX(ax), SCREENY(ay-1)))
6640 DrawGraphic(SCREENX(ax), SCREENY(ay - 1),
6641 IMG_EXPANDABLE_WALL_GROWING_UP, 0);
6646 Feld[ax][ay+1] = EL_EXPANDABLE_WALL_GROWING;
6647 Store[ax][ay+1] = element;
6648 GfxDir[ax][ay+1] = MovDir[ax][ay+1] = MV_DOWN;
6649 if (IN_SCR_FIELD(SCREENX(ax), SCREENY(ay+1)))
6650 DrawGraphic(SCREENX(ax), SCREENY(ay + 1),
6651 IMG_EXPANDABLE_WALL_GROWING_DOWN, 0);
6656 if (element == EL_EXPANDABLE_WALL_HORIZONTAL ||
6657 element == EL_EXPANDABLE_WALL_ANY ||
6658 element == EL_EXPANDABLE_WALL)
6662 Feld[ax-1][ay] = EL_EXPANDABLE_WALL_GROWING;
6663 Store[ax-1][ay] = element;
6664 GfxDir[ax-1][ay] = MovDir[ax-1][ay] = MV_LEFT;
6665 if (IN_SCR_FIELD(SCREENX(ax-1), SCREENY(ay)))
6666 DrawGraphic(SCREENX(ax - 1), SCREENY(ay),
6667 IMG_EXPANDABLE_WALL_GROWING_LEFT, 0);
6673 Feld[ax+1][ay] = EL_EXPANDABLE_WALL_GROWING;
6674 Store[ax+1][ay] = element;
6675 GfxDir[ax+1][ay] = MovDir[ax+1][ay] = MV_RIGHT;
6676 if (IN_SCR_FIELD(SCREENX(ax+1), SCREENY(ay)))
6677 DrawGraphic(SCREENX(ax + 1), SCREENY(ay),
6678 IMG_EXPANDABLE_WALL_GROWING_RIGHT, 0);
6683 if (element == EL_EXPANDABLE_WALL && (links_frei || rechts_frei))
6684 DrawLevelField(ax, ay);
6686 if (!IN_LEV_FIELD(ax, ay-1) || IS_WALL(Feld[ax][ay-1]))
6688 if (!IN_LEV_FIELD(ax, ay+1) || IS_WALL(Feld[ax][ay+1]))
6689 unten_massiv = TRUE;
6690 if (!IN_LEV_FIELD(ax-1, ay) || IS_WALL(Feld[ax-1][ay]))
6691 links_massiv = TRUE;
6692 if (!IN_LEV_FIELD(ax+1, ay) || IS_WALL(Feld[ax+1][ay]))
6693 rechts_massiv = TRUE;
6695 if (((oben_massiv && unten_massiv) ||
6696 element == EL_EXPANDABLE_WALL_HORIZONTAL ||
6697 element == EL_EXPANDABLE_WALL) &&
6698 ((links_massiv && rechts_massiv) ||
6699 element == EL_EXPANDABLE_WALL_VERTICAL))
6700 Feld[ax][ay] = EL_WALL;
6703 PlayLevelSoundAction(ax, ay, ACTION_GROWING);
6706 void CheckForDragon(int x, int y)
6709 boolean dragon_found = FALSE;
6710 static int xy[4][2] =
6718 for (i = 0; i < NUM_DIRECTIONS; i++)
6720 for (j = 0; j < 4; j++)
6722 int xx = x + j * xy[i][0], yy = y + j * xy[i][1];
6724 if (IN_LEV_FIELD(xx, yy) &&
6725 (Feld[xx][yy] == EL_FLAMES || Feld[xx][yy] == EL_DRAGON))
6727 if (Feld[xx][yy] == EL_DRAGON)
6728 dragon_found = TRUE;
6737 for (i = 0; i < NUM_DIRECTIONS; i++)
6739 for (j = 0; j < 3; j++)
6741 int xx = x + j * xy[i][0], yy = y + j * xy[i][1];
6743 if (IN_LEV_FIELD(xx, yy) && Feld[xx][yy] == EL_FLAMES)
6745 Feld[xx][yy] = EL_EMPTY;
6746 DrawLevelField(xx, yy);
6755 static void InitBuggyBase(int x, int y)
6757 int element = Feld[x][y];
6758 int activating_delay = FRAMES_PER_SECOND / 4;
6761 (element == EL_SP_BUGGY_BASE ?
6762 2 * FRAMES_PER_SECOND + RND(5 * FRAMES_PER_SECOND) - activating_delay :
6763 element == EL_SP_BUGGY_BASE_ACTIVATING ?
6765 element == EL_SP_BUGGY_BASE_ACTIVE ?
6766 1 * FRAMES_PER_SECOND + RND(1 * FRAMES_PER_SECOND) : 1);
6769 static void WarnBuggyBase(int x, int y)
6772 static int xy[4][2] =
6780 for (i = 0; i < NUM_DIRECTIONS; i++)
6782 int xx = x + xy[i][0], yy = y + xy[i][1];
6784 if (IS_PLAYER(xx, yy))
6786 PlayLevelSound(x, y, SND_SP_BUGGY_BASE_ACTIVE);
6793 static void InitTrap(int x, int y)
6795 ChangeDelay[x][y] = 2 * FRAMES_PER_SECOND + RND(5 * FRAMES_PER_SECOND);
6798 static void ActivateTrap(int x, int y)
6800 PlayLevelSound(x, y, SND_TRAP_ACTIVATING);
6803 static void ChangeActiveTrap(int x, int y)
6805 int graphic = IMG_TRAP_ACTIVE;
6807 /* if new animation frame was drawn, correct crumbled sand border */
6808 if (IS_NEW_FRAME(GfxFrame[x][y], graphic))
6809 DrawLevelFieldCrumbledSand(x, y);
6812 static int getSpecialActionElement(int element, int number, int base_element)
6814 return (element != EL_EMPTY ? element :
6815 number != -1 ? base_element + number - 1 :
6819 static int getModifiedActionNumber(int value_old, int operator, int operand,
6820 int value_min, int value_max)
6822 int value_new = (operator == CA_MODE_SET ? operand :
6823 operator == CA_MODE_ADD ? value_old + operand :
6824 operator == CA_MODE_SUBTRACT ? value_old - operand :
6825 operator == CA_MODE_MULTIPLY ? value_old * operand :
6826 operator == CA_MODE_DIVIDE ? value_old / MAX(1, operand) :
6827 operator == CA_MODE_MODULO ? value_old % MAX(1, operand) :
6830 return (value_new < value_min ? value_min :
6831 value_new > value_max ? value_max :
6835 static void ExecuteCustomElementAction(int x, int y, int element, int page)
6837 struct ElementInfo *ei = &element_info[element];
6838 struct ElementChangeInfo *change = &ei->change_page[page];
6839 int action_type = change->action_type;
6840 int action_mode = change->action_mode;
6841 int action_arg = change->action_arg;
6844 if (!change->has_action)
6847 /* ---------- determine action paramater values -------------------------- */
6849 int level_time_value =
6850 (level.time > 0 ? TimeLeft :
6853 int action_arg_element =
6854 (action_arg == CA_ARG_PLAYER_TRIGGER ? change->actual_trigger_player :
6855 action_arg == CA_ARG_ELEMENT_TRIGGER ? change->actual_trigger_element :
6856 action_arg == CA_ARG_ELEMENT_TARGET ? change->target_element :
6859 int action_arg_direction =
6860 (action_arg >= CA_ARG_DIRECTION_LEFT &&
6861 action_arg <= CA_ARG_DIRECTION_DOWN ? action_arg - CA_ARG_DIRECTION :
6862 action_arg == CA_ARG_DIRECTION_TRIGGER ?
6863 change->actual_trigger_side :
6864 action_arg == CA_ARG_DIRECTION_TRIGGER_BACK ?
6865 MV_DIR_OPPOSITE(change->actual_trigger_side) :
6868 int action_arg_number_min =
6869 (action_type == CA_SET_PLAYER_SPEED ? MOVE_STEPSIZE_MIN :
6872 int action_arg_number_max =
6873 (action_type == CA_SET_PLAYER_SPEED ? MOVE_STEPSIZE_MAX :
6874 action_type == CA_SET_LEVEL_GEMS ? 999 :
6875 action_type == CA_SET_LEVEL_TIME ? 9999 :
6876 action_type == CA_SET_LEVEL_SCORE ? 99999 :
6877 action_type == CA_SET_CE_SCORE ? 9999 :
6878 action_type == CA_SET_CE_VALUE ? 9999 :
6881 int action_arg_number_reset =
6882 (action_type == CA_SET_PLAYER_SPEED ? TILEX/game.initial_move_delay_value :
6883 action_type == CA_SET_LEVEL_GEMS ? level.gems_needed :
6884 action_type == CA_SET_LEVEL_TIME ? level.time :
6885 action_type == CA_SET_LEVEL_SCORE ? 0 :
6886 action_type == CA_SET_CE_SCORE ? 0 :
6888 action_type == CA_SET_CE_VALUE ? GET_NEW_CUSTOM_VALUE(element) :
6890 action_type == CA_SET_CE_VALUE ? ei->custom_value_initial :
6894 int action_arg_number =
6895 (action_arg <= CA_ARG_MAX ? action_arg :
6896 action_arg >= CA_ARG_SPEED_NOT_MOVING &&
6897 action_arg <= CA_ARG_SPEED_EVEN_FASTER ? (action_arg - CA_ARG_SPEED) :
6898 action_arg == CA_ARG_SPEED_RESET ? action_arg_number_reset :
6899 action_arg == CA_ARG_NUMBER_MIN ? action_arg_number_min :
6900 action_arg == CA_ARG_NUMBER_MAX ? action_arg_number_max :
6901 action_arg == CA_ARG_NUMBER_RESET ? action_arg_number_reset :
6902 action_arg == CA_ARG_NUMBER_CE_SCORE ? ei->collect_score :
6903 #if USE_NEW_CUSTOM_VALUE
6904 action_arg == CA_ARG_NUMBER_CE_VALUE ? CustomValue[x][y] :
6906 action_arg == CA_ARG_NUMBER_CE_VALUE ? ei->custom_value_initial :
6908 action_arg == CA_ARG_NUMBER_CE_DELAY ? GET_CHANGE_DELAY(change) :
6909 action_arg == CA_ARG_NUMBER_LEVEL_TIME ? level_time_value :
6910 action_arg == CA_ARG_NUMBER_LEVEL_GEMS ? local_player->gems_still_needed :
6911 action_arg == CA_ARG_NUMBER_LEVEL_SCORE ? local_player->score :
6912 action_arg == CA_ARG_ELEMENT_TARGET ? GET_NEW_CUSTOM_VALUE(change->target_element) :
6913 action_arg == CA_ARG_ELEMENT_TRIGGER ? change->actual_trigger_ce_value :
6916 int action_arg_number_old =
6917 (action_type == CA_SET_LEVEL_GEMS ? local_player->gems_still_needed :
6918 action_type == CA_SET_LEVEL_TIME ? TimeLeft :
6919 action_type == CA_SET_LEVEL_SCORE ? local_player->score :
6920 action_type == CA_SET_CE_SCORE ? ei->collect_score :
6921 action_type == CA_SET_CE_VALUE ? CustomValue[x][y] :
6924 int action_arg_number_new =
6925 getModifiedActionNumber(action_arg_number_old,
6926 action_mode, action_arg_number,
6927 action_arg_number_min, action_arg_number_max);
6929 int trigger_player_bits =
6930 (change->actual_trigger_player >= EL_PLAYER_1 &&
6931 change->actual_trigger_player <= EL_PLAYER_4 ?
6932 (1 << (change->actual_trigger_player - EL_PLAYER_1)) :
6935 int action_arg_player_bits =
6936 (action_arg >= CA_ARG_PLAYER_1 &&
6937 action_arg <= CA_ARG_PLAYER_4 ? action_arg - CA_ARG_PLAYER :
6938 action_arg == CA_ARG_PLAYER_TRIGGER ? trigger_player_bits :
6941 /* ---------- execute action -------------------------------------------- */
6950 /* ---------- level actions ------------------------------------------- */
6952 case CA_RESTART_LEVEL:
6954 game.restart_level = TRUE;
6959 case CA_SHOW_ENVELOPE:
6961 int element = getSpecialActionElement(action_arg_element,
6962 action_arg_number, EL_ENVELOPE_1);
6964 if (IS_ENVELOPE(element))
6965 local_player->show_envelope = element;
6970 case CA_SET_LEVEL_TIME:
6972 if (level.time > 0) /* only modify limited time value */
6974 TimeLeft = action_arg_number_new;
6976 DrawGameValue_Time(TimeLeft);
6978 if (!TimeLeft && setup.time_limit)
6979 for (i = 0; i < MAX_PLAYERS; i++)
6980 KillPlayer(&stored_player[i]);
6986 case CA_SET_LEVEL_SCORE:
6988 local_player->score = action_arg_number_new;
6990 DrawGameValue_Score(local_player->score);
6995 case CA_SET_LEVEL_GEMS:
6997 local_player->gems_still_needed = action_arg_number_new;
6999 DrawGameValue_Emeralds(local_player->gems_still_needed);
7004 case CA_SET_LEVEL_GRAVITY:
7006 game.gravity = (action_arg == CA_ARG_GRAVITY_OFF ? FALSE :
7007 action_arg == CA_ARG_GRAVITY_ON ? TRUE :
7008 action_arg == CA_ARG_GRAVITY_TOGGLE ? !game.gravity :
7013 case CA_SET_LEVEL_WIND:
7015 game.wind_direction = action_arg_direction;
7020 /* ---------- player actions ------------------------------------------ */
7022 case CA_MOVE_PLAYER:
7024 /* automatically move to the next field in specified direction */
7025 for (i = 0; i < MAX_PLAYERS; i++)
7026 if (trigger_player_bits & (1 << i))
7027 stored_player[i].programmed_action = action_arg_direction;
7032 case CA_EXIT_PLAYER:
7034 for (i = 0; i < MAX_PLAYERS; i++)
7035 if (action_arg_player_bits & (1 << i))
7036 stored_player[i].LevelSolved = stored_player[i].GameOver = TRUE;
7041 case CA_KILL_PLAYER:
7043 for (i = 0; i < MAX_PLAYERS; i++)
7044 if (action_arg_player_bits & (1 << i))
7045 KillPlayer(&stored_player[i]);
7050 case CA_SET_PLAYER_KEYS:
7052 int key_state = (action_mode == CA_MODE_ADD ? TRUE : FALSE);
7053 int element = getSpecialActionElement(action_arg_element,
7054 action_arg_number, EL_KEY_1);
7056 if (IS_KEY(element))
7058 for (i = 0; i < MAX_PLAYERS; i++)
7060 if (trigger_player_bits & (1 << i))
7062 stored_player[i].key[KEY_NR(element)] = key_state;
7064 DrawGameValue_Keys(stored_player[i].key);
7066 redraw_mask |= REDRAW_DOOR_1;
7074 case CA_SET_PLAYER_SPEED:
7076 for (i = 0; i < MAX_PLAYERS; i++)
7078 if (trigger_player_bits & (1 << i))
7080 int move_stepsize = TILEX / stored_player[i].move_delay_value;
7082 if (action_arg == CA_ARG_SPEED_SLOWER ||
7083 action_arg == CA_ARG_SPEED_FASTER)
7085 action_arg_number = 2;
7086 action_mode = (action_arg == CA_ARG_SPEED_SLOWER ? CA_MODE_DIVIDE :
7091 getModifiedActionNumber(move_stepsize,
7094 action_arg_number_min,
7095 action_arg_number_max);
7097 /* make sure that value is power of 2 */
7098 move_stepsize = (1 << log_2(move_stepsize));
7100 /* do no immediately change -- the player might just be moving */
7101 stored_player[i].move_delay_value_next = TILEX / move_stepsize;
7103 stored_player[i].cannot_move =
7104 (action_arg == CA_ARG_SPEED_NOT_MOVING ? TRUE : FALSE);
7111 case CA_SET_PLAYER_SHIELD:
7113 for (i = 0; i < MAX_PLAYERS; i++)
7115 if (trigger_player_bits & (1 << i))
7117 if (action_arg == CA_ARG_SHIELD_OFF)
7119 stored_player[i].shield_normal_time_left = 0;
7120 stored_player[i].shield_deadly_time_left = 0;
7122 else if (action_arg == CA_ARG_SHIELD_NORMAL)
7124 stored_player[i].shield_normal_time_left = 999999;
7126 else if (action_arg == CA_ARG_SHIELD_DEADLY)
7128 stored_player[i].shield_normal_time_left = 999999;
7129 stored_player[i].shield_deadly_time_left = 999999;
7137 case CA_SET_PLAYER_ARTWORK:
7139 for (i = 0; i < MAX_PLAYERS; i++)
7141 if (trigger_player_bits & (1 << i))
7143 int artwork_element = action_arg_element;
7145 if (action_arg == CA_ARG_ELEMENT_RESET)
7147 (level.use_artwork_element[i] ? level.artwork_element[i] :
7148 stored_player[i].element_nr);
7150 stored_player[i].artwork_element = artwork_element;
7152 SetPlayerWaiting(&stored_player[i], FALSE);
7154 /* set number of special actions for bored and sleeping animation */
7155 stored_player[i].num_special_action_bored =
7156 get_num_special_action(artwork_element,
7157 ACTION_BORING_1, ACTION_BORING_LAST);
7158 stored_player[i].num_special_action_sleeping =
7159 get_num_special_action(artwork_element,
7160 ACTION_SLEEPING_1, ACTION_SLEEPING_LAST);
7167 /* ---------- CE actions ---------------------------------------------- */
7169 case CA_SET_CE_SCORE:
7171 ei->collect_score = action_arg_number_new;
7176 case CA_SET_CE_VALUE:
7178 #if USE_NEW_CUSTOM_VALUE
7179 int last_custom_value = CustomValue[x][y];
7181 CustomValue[x][y] = action_arg_number_new;
7184 printf("::: Count == %d\n", CustomValue[x][y]);
7187 if (CustomValue[x][y] == 0 && last_custom_value > 0)
7190 printf("::: CE_VALUE_GETS_ZERO\n");
7193 CheckElementChange(x, y, element, EL_UNDEFINED, CE_VALUE_GETS_ZERO);
7194 CheckTriggeredElementChange(x, y, element, CE_VALUE_GETS_ZERO_OF_X);
7206 static void ChangeElementNowExt(struct ElementChangeInfo *change,
7207 int x, int y, int target_element)
7209 int previous_move_direction = MovDir[x][y];
7210 #if USE_NEW_CUSTOM_VALUE
7211 int last_ce_value = CustomValue[x][y];
7213 boolean add_player = (ELEM_IS_PLAYER(target_element) &&
7214 IS_WALKABLE(Feld[x][y]));
7216 /* check if element under player changes from accessible to unaccessible
7217 (needed for special case of dropping element which then changes) */
7218 if (IS_PLAYER(x, y) && !PLAYER_EXPLOSION_PROTECTED(x, y) &&
7219 IS_ACCESSIBLE(Feld[x][y]) && !IS_ACCESSIBLE(target_element))
7227 if (IS_MOVING(x, y) || IS_BLOCKED(x, y))
7228 RemoveMovingField(x, y);
7232 Feld[x][y] = target_element;
7234 ResetGfxAnimation(x, y);
7235 ResetRandomAnimationValue(x, y);
7237 if (element_info[Feld[x][y]].move_direction_initial == MV_START_PREVIOUS)
7238 MovDir[x][y] = previous_move_direction;
7240 #if USE_NEW_CUSTOM_VALUE
7241 if (element_info[Feld[x][y]].use_last_ce_value)
7242 CustomValue[x][y] = last_ce_value;
7245 InitField_WithBug1(x, y, FALSE);
7247 DrawLevelField(x, y);
7249 if (GFX_CRUMBLED(Feld[x][y]))
7250 DrawLevelFieldCrumbledSandNeighbours(x, y);
7253 /* "Changed[][]" not set yet to allow "entered by player" change one time */
7254 if (ELEM_IS_PLAYER(target_element))
7255 RelocatePlayer(x, y, target_element);
7257 Changed[x][y]++; /* count number of changes in the same frame */
7259 TestIfBadThingTouchesPlayer(x, y);
7260 TestIfPlayerTouchesCustomElement(x, y);
7261 TestIfElementTouchesCustomElement(x, y);
7264 static boolean ChangeElementNow(int x, int y, int element, int page)
7266 struct ElementChangeInfo *change = &element_info[element].change_page[page];
7268 int old_element = Feld[x][y];
7270 /* always use default change event to prevent running into a loop */
7271 if (ChangeEvent[x][y] == -1)
7272 ChangeEvent[x][y] = CE_DELAY;
7274 if (ChangeEvent[x][y] == CE_DELAY)
7276 /* reset actual trigger element, trigger player and action element */
7277 change->actual_trigger_element = EL_EMPTY;
7278 change->actual_trigger_player = EL_PLAYER_1;
7279 change->actual_trigger_side = CH_SIDE_NONE;
7280 change->actual_trigger_ce_value = 0;
7283 /* do not change elements more than a specified maximum number of changes */
7284 if (Changed[x][y] >= game.max_num_changes_per_frame)
7287 Changed[x][y]++; /* count number of changes in the same frame */
7289 if (change->explode)
7296 if (change->use_target_content)
7298 boolean complete_replace = TRUE;
7299 boolean can_replace[3][3];
7302 for (yy = 0; yy < 3; yy++) for (xx = 0; xx < 3 ; xx++)
7305 boolean is_walkable;
7306 boolean is_diggable;
7307 boolean is_collectible;
7308 boolean is_removable;
7309 boolean is_destructible;
7310 int ex = x + xx - 1;
7311 int ey = y + yy - 1;
7312 int content_element = change->target_content.e[xx][yy];
7315 can_replace[xx][yy] = TRUE;
7317 if (ex == x && ey == y) /* do not check changing element itself */
7320 if (content_element == EL_EMPTY_SPACE)
7322 can_replace[xx][yy] = FALSE; /* do not replace border with space */
7327 if (!IN_LEV_FIELD(ex, ey))
7329 can_replace[xx][yy] = FALSE;
7330 complete_replace = FALSE;
7337 if (IS_MOVING(ex, ey) || IS_BLOCKED(ex, ey))
7338 e = MovingOrBlocked2Element(ex, ey);
7340 is_empty = (IS_FREE(ex, ey) ||
7341 (IS_FREE_OR_PLAYER(ex, ey) && IS_WALKABLE(content_element)));
7343 is_walkable = (is_empty || IS_WALKABLE(e));
7344 is_diggable = (is_empty || IS_DIGGABLE(e));
7345 is_collectible = (is_empty || IS_COLLECTIBLE(e));
7346 is_destructible = (is_empty || !IS_INDESTRUCTIBLE(e));
7347 is_removable = (is_diggable || is_collectible);
7349 can_replace[xx][yy] =
7350 (((change->replace_when == CP_WHEN_EMPTY && is_empty) ||
7351 (change->replace_when == CP_WHEN_WALKABLE && is_walkable) ||
7352 (change->replace_when == CP_WHEN_DIGGABLE && is_diggable) ||
7353 (change->replace_when == CP_WHEN_COLLECTIBLE && is_collectible) ||
7354 (change->replace_when == CP_WHEN_REMOVABLE && is_removable) ||
7355 (change->replace_when == CP_WHEN_DESTRUCTIBLE && is_destructible)) &&
7356 !(IS_PLAYER(ex, ey) && ELEM_IS_PLAYER(content_element)));
7358 if (!can_replace[xx][yy])
7359 complete_replace = FALSE;
7362 if (!change->only_if_complete || complete_replace)
7364 boolean something_has_changed = FALSE;
7366 if (change->only_if_complete && change->use_random_replace &&
7367 RND(100) < change->random_percentage)
7370 for (yy = 0; yy < 3; yy++) for (xx = 0; xx < 3 ; xx++)
7372 int ex = x + xx - 1;
7373 int ey = y + yy - 1;
7374 int content_element;
7376 if (can_replace[xx][yy] && (!change->use_random_replace ||
7377 RND(100) < change->random_percentage))
7379 if (IS_MOVING(ex, ey) || IS_BLOCKED(ex, ey))
7380 RemoveMovingField(ex, ey);
7382 ChangeEvent[ex][ey] = ChangeEvent[x][y];
7384 content_element = change->target_content.e[xx][yy];
7385 target_element = GET_TARGET_ELEMENT(content_element, change);
7387 ChangeElementNowExt(change, ex, ey, target_element);
7389 something_has_changed = TRUE;
7391 /* for symmetry reasons, freeze newly created border elements */
7392 if (ex != x || ey != y)
7393 Stop[ex][ey] = TRUE; /* no more moving in this frame */
7397 if (something_has_changed)
7399 PlayLevelSoundElementAction(x, y, element, ACTION_CHANGING);
7400 PlayLevelSoundElementAction(x, y, element, ACTION_PAGE_1 + page);
7406 target_element = GET_TARGET_ELEMENT(change->target_element, change);
7408 ChangeElementNowExt(change, x, y, target_element);
7410 PlayLevelSoundElementAction(x, y, element, ACTION_CHANGING);
7411 PlayLevelSoundElementAction(x, y, element, ACTION_PAGE_1 + page);
7414 /* this uses direct change before indirect change */
7415 CheckTriggeredElementChangeByPage(x, y, old_element, CE_CHANGE_OF_X, page);
7420 #if USE_NEW_DELAYED_ACTION
7422 static void ChangeElement(int x, int y, int page)
7424 int element = MovingOrBlocked2Element(x, y);
7425 struct ElementInfo *ei = &element_info[element];
7426 struct ElementChangeInfo *change = &ei->change_page[page];
7429 if (!CAN_CHANGE_OR_HAS_ACTION(element) &&
7430 !CAN_CHANGE_OR_HAS_ACTION(Back[x][y]))
7433 printf("ChangeElement(): %d,%d: element = %d ('%s')\n",
7434 x, y, element, element_info[element].token_name);
7435 printf("ChangeElement(): This should never happen!\n");
7440 /* this can happen with classic bombs on walkable, changing elements */
7441 if (!CAN_CHANGE_OR_HAS_ACTION(element))
7444 if (!CAN_CHANGE(Back[x][y])) /* prevent permanent repetition */
7445 ChangeDelay[x][y] = 0;
7451 if (ChangeDelay[x][y] == 0) /* initialize element change */
7453 ChangeDelay[x][y] = GET_CHANGE_DELAY(change) + 1;
7455 if (change->can_change)
7457 ResetGfxAnimation(x, y);
7458 ResetRandomAnimationValue(x, y);
7460 if (change->pre_change_function)
7461 change->pre_change_function(x, y);
7465 ChangeDelay[x][y]--;
7467 if (ChangeDelay[x][y] != 0) /* continue element change */
7469 if (change->can_change)
7471 int graphic = el_act_dir2img(element, GfxAction[x][y], GfxDir[x][y]);
7473 if (IS_ANIMATED(graphic))
7474 DrawLevelGraphicAnimationIfNeeded(x, y, graphic);
7476 if (change->change_function)
7477 change->change_function(x, y);
7480 else /* finish element change */
7482 if (ChangePage[x][y] != -1) /* remember page from delayed change */
7484 page = ChangePage[x][y];
7485 ChangePage[x][y] = -1;
7487 change = &ei->change_page[page];
7490 if (IS_MOVING(x, y)) /* never change a running system ;-) */
7492 ChangeDelay[x][y] = 1; /* try change after next move step */
7493 ChangePage[x][y] = page; /* remember page to use for change */
7498 if (change->can_change)
7500 if (ChangeElementNow(x, y, element, page))
7502 if (change->post_change_function)
7503 change->post_change_function(x, y);
7507 if (change->has_action)
7508 ExecuteCustomElementAction(x, y, element, page);
7514 static void ChangeElement(int x, int y, int page)
7516 int element = MovingOrBlocked2Element(x, y);
7517 struct ElementInfo *ei = &element_info[element];
7518 struct ElementChangeInfo *change = &ei->change_page[page];
7521 if (!CAN_CHANGE(element) && !CAN_CHANGE(Back[x][y]))
7524 printf("ChangeElement(): %d,%d: element = %d ('%s')\n",
7525 x, y, element, element_info[element].token_name);
7526 printf("ChangeElement(): This should never happen!\n");
7531 /* this can happen with classic bombs on walkable, changing elements */
7532 if (!CAN_CHANGE(element))
7535 if (!CAN_CHANGE(Back[x][y])) /* prevent permanent repetition */
7536 ChangeDelay[x][y] = 0;
7542 if (ChangeDelay[x][y] == 0) /* initialize element change */
7544 ChangeDelay[x][y] = GET_CHANGE_DELAY(change) + 1;
7546 ResetGfxAnimation(x, y);
7547 ResetRandomAnimationValue(x, y);
7549 if (change->pre_change_function)
7550 change->pre_change_function(x, y);
7553 ChangeDelay[x][y]--;
7555 if (ChangeDelay[x][y] != 0) /* continue element change */
7557 int graphic = el_act_dir2img(element, GfxAction[x][y], GfxDir[x][y]);
7559 if (IS_ANIMATED(graphic))
7560 DrawLevelGraphicAnimationIfNeeded(x, y, graphic);
7562 if (change->change_function)
7563 change->change_function(x, y);
7565 else /* finish element change */
7567 if (ChangePage[x][y] != -1) /* remember page from delayed change */
7569 page = ChangePage[x][y];
7570 ChangePage[x][y] = -1;
7572 change = &ei->change_page[page];
7575 if (IS_MOVING(x, y)) /* never change a running system ;-) */
7577 ChangeDelay[x][y] = 1; /* try change after next move step */
7578 ChangePage[x][y] = page; /* remember page to use for change */
7583 if (ChangeElementNow(x, y, element, page))
7585 if (change->post_change_function)
7586 change->post_change_function(x, y);
7593 static boolean CheckTriggeredElementChangeExt(int x, int y,
7594 int trigger_element,
7600 boolean change_done_any = FALSE;
7601 int trigger_page_bits = (trigger_page < 0 ? CH_PAGE_ANY : 1 << trigger_page);
7604 if (!(trigger_events[trigger_element][trigger_event]))
7607 for (i = 0; i < NUM_CUSTOM_ELEMENTS; i++)
7609 int element = EL_CUSTOM_START + i;
7610 boolean change_done = FALSE;
7613 if (!CAN_CHANGE_OR_HAS_ACTION(element) ||
7614 !HAS_ANY_CHANGE_EVENT(element, trigger_event))
7617 for (p = 0; p < element_info[element].num_change_pages; p++)
7619 struct ElementChangeInfo *change = &element_info[element].change_page[p];
7621 if (change->can_change_or_has_action &&
7622 change->has_event[trigger_event] &&
7623 change->trigger_side & trigger_side &&
7624 change->trigger_player & trigger_player &&
7625 change->trigger_page & trigger_page_bits &&
7626 IS_EQUAL_OR_IN_GROUP(trigger_element, change->trigger_element))
7628 change->actual_trigger_element = trigger_element;
7629 change->actual_trigger_player = EL_PLAYER_1 + log_2(trigger_player);
7630 change->actual_trigger_side = trigger_side;
7631 change->actual_trigger_ce_value = CustomValue[x][y];
7633 if ((change->can_change && !change_done) || change->has_action)
7637 for (y = 0; y < lev_fieldy; y++) for (x = 0; x < lev_fieldx; x++)
7639 if (Feld[x][y] == element)
7641 if (change->can_change && !change_done)
7643 ChangeDelay[x][y] = 1;
7644 ChangeEvent[x][y] = trigger_event;
7645 ChangeElement(x, y, p);
7647 #if USE_NEW_DELAYED_ACTION
7648 else if (change->has_action)
7650 ExecuteCustomElementAction(x, y, element, p);
7651 PlayLevelSoundElementAction(x, y, element, ACTION_PAGE_1 + p);
7654 if (change->has_action)
7656 ExecuteCustomElementAction(x, y, element, p);
7657 PlayLevelSoundElementAction(x, y, element, ACTION_PAGE_1 + p);
7663 if (change->can_change)
7666 change_done_any = TRUE;
7673 return change_done_any;
7676 static boolean CheckElementChangeExt(int x, int y,
7678 int trigger_element,
7683 boolean change_done = FALSE;
7686 if (!CAN_CHANGE_OR_HAS_ACTION(element) ||
7687 !HAS_ANY_CHANGE_EVENT(element, trigger_event))
7690 if (Feld[x][y] == EL_BLOCKED)
7692 Blocked2Moving(x, y, &x, &y);
7693 element = Feld[x][y];
7696 if (Feld[x][y] != element) /* check if element has already changed */
7699 for (p = 0; p < element_info[element].num_change_pages; p++)
7701 struct ElementChangeInfo *change = &element_info[element].change_page[p];
7703 boolean check_trigger_element =
7704 (trigger_event == CE_TOUCHING_X ||
7705 trigger_event == CE_HITTING_X ||
7706 trigger_event == CE_HIT_BY_X);
7708 if (change->can_change_or_has_action &&
7709 change->has_event[trigger_event] &&
7710 change->trigger_side & trigger_side &&
7711 change->trigger_player & trigger_player &&
7712 (!check_trigger_element ||
7713 IS_EQUAL_OR_IN_GROUP(trigger_element, change->trigger_element)))
7715 change->actual_trigger_element = trigger_element;
7716 change->actual_trigger_player = EL_PLAYER_1 + log_2(trigger_player);
7717 change->actual_trigger_side = trigger_side;
7718 change->actual_trigger_ce_value = CustomValue[x][y];
7720 if (change->can_change && !change_done)
7722 ChangeDelay[x][y] = 1;
7723 ChangeEvent[x][y] = trigger_event;
7724 ChangeElement(x, y, p);
7728 #if USE_NEW_DELAYED_ACTION
7729 else if (change->has_action)
7731 ExecuteCustomElementAction(x, y, element, p);
7732 PlayLevelSoundElementAction(x, y, element, ACTION_PAGE_1 + p);
7735 if (change->has_action)
7737 ExecuteCustomElementAction(x, y, element, p);
7738 PlayLevelSoundElementAction(x, y, element, ACTION_PAGE_1 + p);
7747 static void PlayPlayerSound(struct PlayerInfo *player)
7749 int jx = player->jx, jy = player->jy;
7750 int sound_element = player->artwork_element;
7751 int last_action = player->last_action_waiting;
7752 int action = player->action_waiting;
7754 if (player->is_waiting)
7756 if (action != last_action)
7757 PlayLevelSoundElementAction(jx, jy, sound_element, action);
7759 PlayLevelSoundElementActionIfLoop(jx, jy, sound_element, action);
7763 if (action != last_action)
7764 StopSound(element_info[sound_element].sound[last_action]);
7766 if (last_action == ACTION_SLEEPING)
7767 PlayLevelSoundElementAction(jx, jy, sound_element, ACTION_AWAKENING);
7771 static void PlayAllPlayersSound()
7775 for (i = 0; i < MAX_PLAYERS; i++)
7776 if (stored_player[i].active)
7777 PlayPlayerSound(&stored_player[i]);
7780 static void SetPlayerWaiting(struct PlayerInfo *player, boolean is_waiting)
7782 boolean last_waiting = player->is_waiting;
7783 int move_dir = player->MovDir;
7785 player->last_action_waiting = player->action_waiting;
7789 if (!last_waiting) /* not waiting -> waiting */
7791 player->is_waiting = TRUE;
7793 player->frame_counter_bored =
7795 game.player_boring_delay_fixed +
7796 SimpleRND(game.player_boring_delay_random);
7797 player->frame_counter_sleeping =
7799 game.player_sleeping_delay_fixed +
7800 SimpleRND(game.player_sleeping_delay_random);
7802 InitPlayerGfxAnimation(player, ACTION_WAITING, player->MovDir);
7805 if (game.player_sleeping_delay_fixed +
7806 game.player_sleeping_delay_random > 0 &&
7807 player->anim_delay_counter == 0 &&
7808 player->post_delay_counter == 0 &&
7809 FrameCounter >= player->frame_counter_sleeping)
7810 player->is_sleeping = TRUE;
7811 else if (game.player_boring_delay_fixed +
7812 game.player_boring_delay_random > 0 &&
7813 FrameCounter >= player->frame_counter_bored)
7814 player->is_bored = TRUE;
7816 player->action_waiting = (player->is_sleeping ? ACTION_SLEEPING :
7817 player->is_bored ? ACTION_BORING :
7820 if (player->is_sleeping)
7822 if (player->num_special_action_sleeping > 0)
7824 if (player->anim_delay_counter == 0 && player->post_delay_counter == 0)
7826 int last_special_action = player->special_action_sleeping;
7827 int num_special_action = player->num_special_action_sleeping;
7828 int special_action =
7829 (last_special_action == ACTION_DEFAULT ? ACTION_SLEEPING_1 :
7830 last_special_action == ACTION_SLEEPING ? ACTION_SLEEPING :
7831 last_special_action < ACTION_SLEEPING_1 + num_special_action - 1 ?
7832 last_special_action + 1 : ACTION_SLEEPING);
7833 int special_graphic =
7834 el_act_dir2img(player->artwork_element, special_action, move_dir);
7836 player->anim_delay_counter =
7837 graphic_info[special_graphic].anim_delay_fixed +
7838 SimpleRND(graphic_info[special_graphic].anim_delay_random);
7839 player->post_delay_counter =
7840 graphic_info[special_graphic].post_delay_fixed +
7841 SimpleRND(graphic_info[special_graphic].post_delay_random);
7843 player->special_action_sleeping = special_action;
7846 if (player->anim_delay_counter > 0)
7848 player->action_waiting = player->special_action_sleeping;
7849 player->anim_delay_counter--;
7851 else if (player->post_delay_counter > 0)
7853 player->post_delay_counter--;
7857 else if (player->is_bored)
7859 if (player->num_special_action_bored > 0)
7861 if (player->anim_delay_counter == 0 && player->post_delay_counter == 0)
7863 int special_action =
7864 ACTION_BORING_1 + SimpleRND(player->num_special_action_bored);
7865 int special_graphic =
7866 el_act_dir2img(player->artwork_element, special_action, move_dir);
7868 player->anim_delay_counter =
7869 graphic_info[special_graphic].anim_delay_fixed +
7870 SimpleRND(graphic_info[special_graphic].anim_delay_random);
7871 player->post_delay_counter =
7872 graphic_info[special_graphic].post_delay_fixed +
7873 SimpleRND(graphic_info[special_graphic].post_delay_random);
7875 player->special_action_bored = special_action;
7878 if (player->anim_delay_counter > 0)
7880 player->action_waiting = player->special_action_bored;
7881 player->anim_delay_counter--;
7883 else if (player->post_delay_counter > 0)
7885 player->post_delay_counter--;
7890 else if (last_waiting) /* waiting -> not waiting */
7892 player->is_waiting = FALSE;
7893 player->is_bored = FALSE;
7894 player->is_sleeping = FALSE;
7896 player->frame_counter_bored = -1;
7897 player->frame_counter_sleeping = -1;
7899 player->anim_delay_counter = 0;
7900 player->post_delay_counter = 0;
7902 player->action_waiting = ACTION_DEFAULT;
7904 player->special_action_bored = ACTION_DEFAULT;
7905 player->special_action_sleeping = ACTION_DEFAULT;
7909 static byte PlayerActions(struct PlayerInfo *player, byte player_action)
7911 boolean moved = FALSE, snapped = FALSE, dropped = FALSE;
7912 int left = player_action & JOY_LEFT;
7913 int right = player_action & JOY_RIGHT;
7914 int up = player_action & JOY_UP;
7915 int down = player_action & JOY_DOWN;
7916 int button1 = player_action & JOY_BUTTON_1;
7917 int button2 = player_action & JOY_BUTTON_2;
7918 int dx = (left ? -1 : right ? 1 : 0);
7919 int dy = (up ? -1 : down ? 1 : 0);
7921 if (!player->active || tape.pausing)
7927 snapped = SnapField(player, dx, dy);
7931 dropped = DropElement(player);
7933 moved = MovePlayer(player, dx, dy);
7936 if (tape.single_step && tape.recording && !tape.pausing)
7938 if (button1 || (dropped && !moved))
7940 TapeTogglePause(TAPE_TOGGLE_AUTOMATIC);
7941 SnapField(player, 0, 0); /* stop snapping */
7945 SetPlayerWaiting(player, FALSE);
7947 return player_action;
7951 /* no actions for this player (no input at player's configured device) */
7953 DigField(player, 0, 0, 0, 0, 0, 0, DF_NO_PUSH);
7954 SnapField(player, 0, 0);
7955 CheckGravityMovementWhenNotMoving(player);
7957 if (player->MovPos == 0)
7958 SetPlayerWaiting(player, TRUE);
7960 if (player->MovPos == 0) /* needed for tape.playing */
7961 player->is_moving = FALSE;
7963 player->is_dropping = FALSE;
7969 void AdvanceFrameAndPlayerCounters(int player_nr)
7973 /* advance frame counters (global frame counter and time frame counter) */
7977 /* advance player counters (counters for move delay, move animation etc.) */
7978 for (i = 0; i < MAX_PLAYERS; i++)
7980 boolean advance_player_counters = (player_nr == -1 || player_nr == i);
7981 int move_delay_value = stored_player[i].move_delay_value;
7982 int move_frames = MOVE_DELAY_NORMAL_SPEED / move_delay_value;
7984 if (!advance_player_counters) /* not all players may be affected */
7987 #if USE_NEW_PLAYER_ANIM
7988 if (move_frames == 0) /* less than one move per game frame */
7990 int stepsize = TILEX / move_delay_value;
7991 int delay = move_delay_value / MOVE_DELAY_NORMAL_SPEED;
7992 int count = (stored_player[i].is_moving ?
7993 ABS(stored_player[i].MovPos) / stepsize : FrameCounter);
7995 if (count % delay == 0)
8000 stored_player[i].Frame += move_frames;
8002 if (stored_player[i].MovPos != 0)
8003 stored_player[i].StepFrame += move_frames;
8005 if (stored_player[i].move_delay > 0)
8006 stored_player[i].move_delay--;
8008 /* due to bugs in previous versions, counter must count up, not down */
8009 if (stored_player[i].push_delay != -1)
8010 stored_player[i].push_delay++;
8012 if (stored_player[i].drop_delay > 0)
8013 stored_player[i].drop_delay--;
8019 static unsigned long game_frame_delay = 0;
8020 unsigned long game_frame_delay_value;
8021 int magic_wall_x = 0, magic_wall_y = 0;
8022 int i, x, y, element, graphic;
8023 byte *recorded_player_action;
8024 byte summarized_player_action = 0;
8025 byte tape_action[MAX_PLAYERS];
8027 if (game_status != GAME_MODE_PLAYING)
8030 game_frame_delay_value =
8031 (tape.playing && tape.fast_forward ? FfwdFrameDelay : GameFrameDelay);
8033 if (tape.playing && tape.warp_forward && !tape.pausing)
8034 game_frame_delay_value = 0;
8036 /* ---------- main game synchronization point ---------- */
8038 WaitUntilDelayReached(&game_frame_delay, game_frame_delay_value);
8040 if (network_playing && !network_player_action_received)
8042 /* try to get network player actions in time */
8044 #if defined(NETWORK_AVALIABLE)
8045 /* last chance to get network player actions without main loop delay */
8049 /* game was quit by network peer */
8050 if (game_status != GAME_MODE_PLAYING)
8053 if (!network_player_action_received)
8054 return; /* failed to get network player actions in time */
8060 recorded_player_action = (tape.playing ? TapePlayAction() : NULL);
8063 /* !!! CHECK THIS (tape.pausing is always FALSE here!) !!! */
8064 if (recorded_player_action == NULL && tape.pausing)
8068 for (i = 0; i < MAX_PLAYERS; i++)
8070 summarized_player_action |= stored_player[i].action;
8072 if (!network_playing)
8073 stored_player[i].effective_action = stored_player[i].action;
8076 #if defined(NETWORK_AVALIABLE)
8077 if (network_playing)
8078 SendToServer_MovePlayer(summarized_player_action);
8081 if (!options.network && !setup.team_mode)
8082 local_player->effective_action = summarized_player_action;
8084 if (recorded_player_action != NULL)
8085 for (i = 0; i < MAX_PLAYERS; i++)
8086 stored_player[i].effective_action = recorded_player_action[i];
8088 for (i = 0; i < MAX_PLAYERS; i++)
8090 tape_action[i] = stored_player[i].effective_action;
8092 if (tape.recording && tape_action[i] && !tape.player_participates[i])
8093 tape.player_participates[i] = TRUE; /* player just appeared from CE */
8096 /* only save actions from input devices, but not programmed actions */
8098 TapeRecordAction(tape_action);
8100 for (i = 0; i < MAX_PLAYERS; i++)
8102 int actual_player_action = stored_player[i].effective_action;
8105 /* !!! THIS BREAKS THE FOLLOWING TAPES: !!!
8106 - rnd_equinox_tetrachloride 048
8107 - rnd_equinox_tetrachloride_ii 096
8108 - rnd_emanuel_schmieg 002
8109 - doctor_sloan_ww 001, 020
8111 if (stored_player[i].MovPos == 0)
8112 CheckGravityMovement(&stored_player[i]);
8115 /* overwrite programmed action with tape action */
8116 if (stored_player[i].programmed_action)
8117 actual_player_action = stored_player[i].programmed_action;
8120 PlayerActions(&stored_player[i], actual_player_action);
8122 tape_action[i] = PlayerActions(&stored_player[i], actual_player_action);
8124 if (tape.recording && tape_action[i] && !tape.player_participates[i])
8125 tape.player_participates[i] = TRUE; /* player just appeared from CE */
8128 ScrollPlayer(&stored_player[i], SCROLL_GO_ON);
8131 network_player_action_received = FALSE;
8133 ScrollScreen(NULL, SCROLL_GO_ON);
8135 /* for backwards compatibility, the following code emulates a fixed bug that
8136 occured when pushing elements (causing elements that just made their last
8137 pushing step to already (if possible) make their first falling step in the
8138 same game frame, which is bad); this code is also needed to use the famous
8139 "spring push bug" which is used in older levels and might be wanted to be
8140 used also in newer levels, but in this case the buggy pushing code is only
8141 affecting the "spring" element and no other elements */
8143 if (game.engine_version < VERSION_IDENT(2,2,0,7) || level.use_spring_bug)
8145 for (i = 0; i < MAX_PLAYERS; i++)
8147 struct PlayerInfo *player = &stored_player[i];
8151 if (player->active && player->is_pushing && player->is_moving &&
8153 (game.engine_version < VERSION_IDENT(2,2,0,7) ||
8154 Feld[x][y] == EL_SPRING))
8156 ContinueMoving(x, y);
8158 /* continue moving after pushing (this is actually a bug) */
8159 if (!IS_MOVING(x, y))
8167 for (y = 0; y < lev_fieldy; y++) for (x = 0; x < lev_fieldx; x++)
8170 ChangeEvent[x][y] = -1;
8172 /* this must be handled before main playfield loop */
8173 if (Feld[x][y] == EL_PLAYER_IS_LEAVING)
8176 if (MovDelay[x][y] <= 0)
8180 #if USE_NEW_SNAP_DELAY
8181 if (Feld[x][y] == EL_ELEMENT_SNAPPING)
8184 if (MovDelay[x][y] <= 0)
8187 DrawLevelField(x, y);
8189 TestIfElementTouchesCustomElement(x, y); /* for empty space */
8195 if (ChangePage[x][y] != -1 && ChangeDelay[x][y] != 1)
8197 printf("GameActions(): x = %d, y = %d: ChangePage != -1\n", x, y);
8198 printf("GameActions(): This should never happen!\n");
8200 ChangePage[x][y] = -1;
8205 if (WasJustMoving[x][y] > 0)
8206 WasJustMoving[x][y]--;
8207 if (WasJustFalling[x][y] > 0)
8208 WasJustFalling[x][y]--;
8209 if (CheckCollision[x][y] > 0)
8210 CheckCollision[x][y]--;
8214 /* reset finished pushing action (not done in ContinueMoving() to allow
8215 continous pushing animation for elements with zero push delay) */
8216 if (GfxAction[x][y] == ACTION_PUSHING && !IS_MOVING(x, y))
8218 ResetGfxAnimation(x, y);
8219 DrawLevelField(x, y);
8223 if (IS_BLOCKED(x, y))
8227 Blocked2Moving(x, y, &oldx, &oldy);
8228 if (!IS_MOVING(oldx, oldy))
8230 printf("GameActions(): (BLOCKED => MOVING) context corrupted!\n");
8231 printf("GameActions(): BLOCKED: x = %d, y = %d\n", x, y);
8232 printf("GameActions(): !MOVING: oldx = %d, oldy = %d\n", oldx, oldy);
8233 printf("GameActions(): This should never happen!\n");
8239 for (y = 0; y < lev_fieldy; y++) for (x = 0; x < lev_fieldx; x++)
8241 element = Feld[x][y];
8242 graphic = el_act_dir2img(element, GfxAction[x][y], GfxDir[x][y]);
8244 if (graphic_info[graphic].anim_global_sync)
8245 GfxFrame[x][y] = FrameCounter;
8247 if (ANIM_MODE(graphic) == ANIM_RANDOM &&
8248 IS_NEXT_FRAME(GfxFrame[x][y], graphic))
8249 ResetRandomAnimationValue(x, y);
8251 SetRandomAnimationValue(x, y);
8253 PlayLevelSoundActionIfLoop(x, y, GfxAction[x][y]);
8255 if (IS_INACTIVE(element))
8257 if (IS_ANIMATED(graphic))
8258 DrawLevelGraphicAnimationIfNeeded(x, y, graphic);
8263 /* this may take place after moving, so 'element' may have changed */
8264 if (IS_CHANGING(x, y) &&
8265 (game.engine_version < VERSION_IDENT(3,0,7,1) || !Stop[x][y]))
8267 int page = element_info[element].event_page_nr[CE_DELAY];
8269 ChangeElement(x, y, ChangePage[x][y] != -1 ? ChangePage[x][y] : page);
8273 printf("::: ChangeDelay == %d\n", ChangeDelay[x][y]);
8277 ChangeElement(x, y, page);
8279 if (CAN_CHANGE(element))
8280 ChangeElement(x, y, page);
8282 if (HAS_ACTION(element))
8283 ExecuteCustomElementAction(x, y, element, page);
8288 element = Feld[x][y];
8289 graphic = el_act_dir2img(element, GfxAction[x][y], GfxDir[x][y]);
8292 if (!IS_MOVING(x, y) && (CAN_FALL(element) || CAN_MOVE(element)))
8296 element = Feld[x][y];
8297 graphic = el_act_dir2img(element, GfxAction[x][y], GfxDir[x][y]);
8299 if (IS_ANIMATED(graphic) &&
8302 DrawLevelGraphicAnimationIfNeeded(x, y, graphic);
8304 if (IS_GEM(element) || element == EL_SP_INFOTRON)
8305 EdelsteinFunkeln(x, y);
8307 else if ((element == EL_ACID ||
8308 element == EL_EXIT_OPEN ||
8309 element == EL_SP_EXIT_OPEN ||
8310 element == EL_SP_TERMINAL ||
8311 element == EL_SP_TERMINAL_ACTIVE ||
8312 element == EL_EXTRA_TIME ||
8313 element == EL_SHIELD_NORMAL ||
8314 element == EL_SHIELD_DEADLY) &&
8315 IS_ANIMATED(graphic))
8316 DrawLevelGraphicAnimationIfNeeded(x, y, graphic);
8317 else if (IS_MOVING(x, y))
8318 ContinueMoving(x, y);
8319 else if (IS_ACTIVE_BOMB(element))
8320 CheckDynamite(x, y);
8321 else if (element == EL_AMOEBA_GROWING)
8322 AmoebeWaechst(x, y);
8323 else if (element == EL_AMOEBA_SHRINKING)
8324 AmoebaDisappearing(x, y);
8326 #if !USE_NEW_AMOEBA_CODE
8327 else if (IS_AMOEBALIVE(element))
8328 AmoebeAbleger(x, y);
8331 else if (element == EL_GAME_OF_LIFE || element == EL_BIOMAZE)
8333 else if (element == EL_EXIT_CLOSED)
8335 else if (element == EL_SP_EXIT_CLOSED)
8337 else if (element == EL_EXPANDABLE_WALL_GROWING)
8339 else if (element == EL_EXPANDABLE_WALL ||
8340 element == EL_EXPANDABLE_WALL_HORIZONTAL ||
8341 element == EL_EXPANDABLE_WALL_VERTICAL ||
8342 element == EL_EXPANDABLE_WALL_ANY)
8344 else if (element == EL_FLAMES)
8345 CheckForDragon(x, y);
8346 else if (element == EL_EXPLOSION)
8347 ; /* drawing of correct explosion animation is handled separately */
8348 else if (element == EL_ELEMENT_SNAPPING)
8351 graphic = el_act_dir2img(GfxElement[x][y], GfxAction[x][y],GfxDir[x][y]);
8353 DrawLevelGraphicAnimationIfNeeded(x, y, graphic);
8356 else if (IS_ANIMATED(graphic) && !IS_CHANGING(x, y))
8357 DrawLevelGraphicAnimationIfNeeded(x, y, graphic);
8359 if (IS_BELT_ACTIVE(element))
8360 PlayLevelSoundAction(x, y, ACTION_ACTIVE);
8362 if (game.magic_wall_active)
8364 int jx = local_player->jx, jy = local_player->jy;
8366 /* play the element sound at the position nearest to the player */
8367 if ((element == EL_MAGIC_WALL_FULL ||
8368 element == EL_MAGIC_WALL_ACTIVE ||
8369 element == EL_MAGIC_WALL_EMPTYING ||
8370 element == EL_BD_MAGIC_WALL_FULL ||
8371 element == EL_BD_MAGIC_WALL_ACTIVE ||
8372 element == EL_BD_MAGIC_WALL_EMPTYING) &&
8373 ABS(x-jx) + ABS(y-jy) < ABS(magic_wall_x-jx) + ABS(magic_wall_y-jy))
8381 #if USE_NEW_AMOEBA_CODE
8382 /* new experimental amoeba growth stuff */
8383 if (!(FrameCounter % 8))
8385 static unsigned long random = 1684108901;
8387 for (i = 0; i < level.amoeba_speed * 28 / 8; i++)
8389 x = RND(lev_fieldx);
8390 y = RND(lev_fieldy);
8391 element = Feld[x][y];
8393 if (!IS_PLAYER(x,y) &&
8394 (element == EL_EMPTY ||
8395 CAN_GROW_INTO(element) ||
8396 element == EL_QUICKSAND_EMPTY ||
8397 element == EL_ACID_SPLASH_LEFT ||
8398 element == EL_ACID_SPLASH_RIGHT))
8400 if ((IN_LEV_FIELD(x, y-1) && Feld[x][y-1] == EL_AMOEBA_WET) ||
8401 (IN_LEV_FIELD(x-1, y) && Feld[x-1][y] == EL_AMOEBA_WET) ||
8402 (IN_LEV_FIELD(x+1, y) && Feld[x+1][y] == EL_AMOEBA_WET) ||
8403 (IN_LEV_FIELD(x, y+1) && Feld[x][y+1] == EL_AMOEBA_WET))
8404 Feld[x][y] = EL_AMOEBA_DROP;
8407 random = random * 129 + 1;
8413 if (game.explosions_delayed)
8416 game.explosions_delayed = FALSE;
8418 for (y = 0; y < lev_fieldy; y++) for (x = 0; x < lev_fieldx; x++)
8420 element = Feld[x][y];
8422 if (ExplodeField[x][y])
8423 Explode(x, y, EX_PHASE_START, ExplodeField[x][y]);
8424 else if (element == EL_EXPLOSION)
8425 Explode(x, y, ExplodePhase[x][y], EX_TYPE_NORMAL);
8427 ExplodeField[x][y] = EX_TYPE_NONE;
8430 game.explosions_delayed = TRUE;
8433 if (game.magic_wall_active)
8435 if (!(game.magic_wall_time_left % 4))
8437 int element = Feld[magic_wall_x][magic_wall_y];
8439 if (element == EL_BD_MAGIC_WALL_FULL ||
8440 element == EL_BD_MAGIC_WALL_ACTIVE ||
8441 element == EL_BD_MAGIC_WALL_EMPTYING)
8442 PlayLevelSound(magic_wall_x, magic_wall_y, SND_BD_MAGIC_WALL_ACTIVE);
8444 PlayLevelSound(magic_wall_x, magic_wall_y, SND_MAGIC_WALL_ACTIVE);
8447 if (game.magic_wall_time_left > 0)
8449 game.magic_wall_time_left--;
8450 if (!game.magic_wall_time_left)
8452 for (y = 0; y < lev_fieldy; y++) for (x = 0; x < lev_fieldx; x++)
8454 element = Feld[x][y];
8456 if (element == EL_MAGIC_WALL_ACTIVE ||
8457 element == EL_MAGIC_WALL_FULL)
8459 Feld[x][y] = EL_MAGIC_WALL_DEAD;
8460 DrawLevelField(x, y);
8462 else if (element == EL_BD_MAGIC_WALL_ACTIVE ||
8463 element == EL_BD_MAGIC_WALL_FULL)
8465 Feld[x][y] = EL_BD_MAGIC_WALL_DEAD;
8466 DrawLevelField(x, y);
8470 game.magic_wall_active = FALSE;
8475 if (game.light_time_left > 0)
8477 game.light_time_left--;
8479 if (game.light_time_left == 0)
8480 RedrawAllLightSwitchesAndInvisibleElements();
8483 if (game.timegate_time_left > 0)
8485 game.timegate_time_left--;
8487 if (game.timegate_time_left == 0)
8488 CloseAllOpenTimegates();
8491 if (game.lenses_time_left > 0)
8493 game.lenses_time_left--;
8495 if (game.lenses_time_left == 0)
8496 RedrawAllInvisibleElementsForLenses();
8499 if (game.magnify_time_left > 0)
8501 game.magnify_time_left--;
8503 if (game.magnify_time_left == 0)
8504 RedrawAllInvisibleElementsForMagnifier();
8507 for (i = 0; i < MAX_PLAYERS; i++)
8509 struct PlayerInfo *player = &stored_player[i];
8511 if (SHIELD_ON(player))
8513 if (player->shield_deadly_time_left)
8514 PlayLevelSound(player->jx, player->jy, SND_SHIELD_DEADLY_ACTIVE);
8515 else if (player->shield_normal_time_left)
8516 PlayLevelSound(player->jx, player->jy, SND_SHIELD_NORMAL_ACTIVE);
8520 if (TimeFrames >= FRAMES_PER_SECOND)
8525 for (i = 0; i < MAX_PLAYERS; i++)
8527 struct PlayerInfo *player = &stored_player[i];
8529 if (SHIELD_ON(player))
8531 player->shield_normal_time_left--;
8533 if (player->shield_deadly_time_left > 0)
8534 player->shield_deadly_time_left--;
8538 if (!level.use_step_counter)
8546 if (TimeLeft <= 10 && setup.time_limit)
8547 PlaySoundStereo(SND_GAME_RUNNING_OUT_OF_TIME, SOUND_MIDDLE);
8549 DrawGameValue_Time(TimeLeft);
8551 if (!TimeLeft && setup.time_limit)
8552 for (i = 0; i < MAX_PLAYERS; i++)
8553 KillPlayer(&stored_player[i]);
8555 else if (level.time == 0 && !AllPlayersGone) /* level w/o time limit */
8556 DrawGameValue_Time(TimePlayed);
8559 if (tape.recording || tape.playing)
8560 DrawVideoDisplay(VIDEO_STATE_TIME_ON, TapeTime);
8564 PlayAllPlayersSound();
8566 if (options.debug) /* calculate frames per second */
8568 static unsigned long fps_counter = 0;
8569 static int fps_frames = 0;
8570 unsigned long fps_delay_ms = Counter() - fps_counter;
8574 if (fps_delay_ms >= 500) /* calculate fps every 0.5 seconds */
8576 global.frames_per_second = 1000 * (float)fps_frames / fps_delay_ms;
8579 fps_counter = Counter();
8582 redraw_mask |= REDRAW_FPS;
8585 AdvanceFrameAndPlayerCounters(-1); /* advance counters for all players */
8587 if (local_player->show_envelope != 0 && local_player->MovPos == 0)
8589 ShowEnvelope(local_player->show_envelope - EL_ENVELOPE_1);
8591 local_player->show_envelope = 0;
8594 /* use random number generator in every frame to make it less predictable */
8595 if (game.engine_version >= VERSION_IDENT(3,1,1,0))
8599 static boolean AllPlayersInSight(struct PlayerInfo *player, int x, int y)
8601 int min_x = x, min_y = y, max_x = x, max_y = y;
8604 for (i = 0; i < MAX_PLAYERS; i++)
8606 int jx = stored_player[i].jx, jy = stored_player[i].jy;
8608 if (!stored_player[i].active || &stored_player[i] == player)
8611 min_x = MIN(min_x, jx);
8612 min_y = MIN(min_y, jy);
8613 max_x = MAX(max_x, jx);
8614 max_y = MAX(max_y, jy);
8617 return (max_x - min_x < SCR_FIELDX && max_y - min_y < SCR_FIELDY);
8620 static boolean AllPlayersInVisibleScreen()
8624 for (i = 0; i < MAX_PLAYERS; i++)
8626 int jx = stored_player[i].jx, jy = stored_player[i].jy;
8628 if (!stored_player[i].active)
8631 if (!IN_VIS_FIELD(SCREENX(jx), SCREENY(jy)))
8638 void ScrollLevel(int dx, int dy)
8640 int softscroll_offset = (setup.soft_scrolling ? TILEX : 0);
8643 BlitBitmap(drawto_field, drawto_field,
8644 FX + TILEX * (dx == -1) - softscroll_offset,
8645 FY + TILEY * (dy == -1) - softscroll_offset,
8646 SXSIZE - TILEX * (dx!=0) + 2 * softscroll_offset,
8647 SYSIZE - TILEY * (dy!=0) + 2 * softscroll_offset,
8648 FX + TILEX * (dx == 1) - softscroll_offset,
8649 FY + TILEY * (dy == 1) - softscroll_offset);
8653 x = (dx == 1 ? BX1 : BX2);
8654 for (y = BY1; y <= BY2; y++)
8655 DrawScreenField(x, y);
8660 y = (dy == 1 ? BY1 : BY2);
8661 for (x = BX1; x <= BX2; x++)
8662 DrawScreenField(x, y);
8665 redraw_mask |= REDRAW_FIELD;
8668 static boolean canFallDown(struct PlayerInfo *player)
8670 int jx = player->jx, jy = player->jy;
8672 return (IN_LEV_FIELD(jx, jy + 1) &&
8673 (IS_FREE(jx, jy + 1) ||
8674 (Feld[jx][jy + 1] == EL_ACID && player->can_fall_into_acid)) &&
8675 IS_WALKABLE_FROM(Feld[jx][jy], MV_DOWN) &&
8676 !IS_WALKABLE_INSIDE(Feld[jx][jy]));
8679 static boolean canPassField(int x, int y, int move_dir)
8681 int opposite_dir = MV_DIR_OPPOSITE(move_dir);
8682 int dx = (move_dir & MV_LEFT ? -1 : move_dir & MV_RIGHT ? +1 : 0);
8683 int dy = (move_dir & MV_UP ? -1 : move_dir & MV_DOWN ? +1 : 0);
8686 int element = Feld[x][y];
8688 return (IS_PASSABLE_FROM(element, opposite_dir) &&
8689 !CAN_MOVE(element) &&
8690 IN_LEV_FIELD(nextx, nexty) && !IS_PLAYER(nextx, nexty) &&
8691 IS_WALKABLE_FROM(Feld[nextx][nexty], move_dir) &&
8692 (level.can_pass_to_walkable || IS_FREE(nextx, nexty)));
8695 static boolean canMoveToValidFieldWithGravity(int x, int y, int move_dir)
8697 int opposite_dir = MV_DIR_OPPOSITE(move_dir);
8698 int dx = (move_dir & MV_LEFT ? -1 : move_dir & MV_RIGHT ? +1 : 0);
8699 int dy = (move_dir & MV_UP ? -1 : move_dir & MV_DOWN ? +1 : 0);
8703 return (IN_LEV_FIELD(newx, newy) && !IS_FREE_OR_PLAYER(newx, newy) &&
8704 IS_GRAVITY_REACHABLE(Feld[newx][newy]) &&
8705 (IS_DIGGABLE(Feld[newx][newy]) ||
8706 IS_WALKABLE_FROM(Feld[newx][newy], opposite_dir) ||
8707 canPassField(newx, newy, move_dir)));
8710 static void CheckGravityMovement(struct PlayerInfo *player)
8712 if (game.gravity && !player->programmed_action)
8714 int move_dir_horizontal = player->effective_action & MV_HORIZONTAL;
8715 int move_dir_vertical = player->effective_action & MV_VERTICAL;
8716 boolean player_is_snapping = player->effective_action & JOY_BUTTON_1;
8717 int jx = player->jx, jy = player->jy;
8718 boolean player_is_moving_to_valid_field =
8719 (!player_is_snapping &&
8720 (canMoveToValidFieldWithGravity(jx, jy, move_dir_horizontal) ||
8721 canMoveToValidFieldWithGravity(jx, jy, move_dir_vertical)));
8722 boolean player_can_fall_down = canFallDown(player);
8724 if (player_can_fall_down &&
8725 !player_is_moving_to_valid_field)
8726 player->programmed_action = MV_DOWN;
8730 static void CheckGravityMovementWhenNotMoving(struct PlayerInfo *player)
8732 return CheckGravityMovement(player);
8734 if (game.gravity && !player->programmed_action)
8736 int jx = player->jx, jy = player->jy;
8737 boolean field_under_player_is_free =
8738 (IN_LEV_FIELD(jx, jy + 1) && IS_FREE(jx, jy + 1));
8739 boolean player_is_standing_on_valid_field =
8740 (IS_WALKABLE_INSIDE(Feld[jx][jy]) ||
8741 (IS_WALKABLE(Feld[jx][jy]) &&
8742 !(element_info[Feld[jx][jy]].access_direction & MV_DOWN)));
8744 if (field_under_player_is_free && !player_is_standing_on_valid_field)
8745 player->programmed_action = MV_DOWN;
8751 -----------------------------------------------------------------------------
8752 dx, dy: direction (non-diagonal) to try to move the player to
8753 real_dx, real_dy: direction as read from input device (can be diagonal)
8756 boolean MovePlayerOneStep(struct PlayerInfo *player,
8757 int dx, int dy, int real_dx, int real_dy)
8759 int jx = player->jx, jy = player->jy;
8760 int new_jx = jx + dx, new_jy = jy + dy;
8764 if (!player->active || (!dx && !dy))
8765 return MF_NO_ACTION;
8767 player->MovDir = (dx < 0 ? MV_LEFT :
8770 dy > 0 ? MV_DOWN : MV_NONE);
8772 if (!IN_LEV_FIELD(new_jx, new_jy))
8773 return MF_NO_ACTION;
8775 if (player->cannot_move)
8778 if (player->MovPos == 0)
8780 player->is_moving = FALSE;
8781 player->is_digging = FALSE;
8782 player->is_collecting = FALSE;
8783 player->is_snapping = FALSE;
8784 player->is_pushing = FALSE;
8787 DigField(player, 0, 0, 0, 0, 0, 0, DF_NO_PUSH);
8788 SnapField(player, 0, 0);
8791 return MF_NO_ACTION;
8794 if (!options.network && !AllPlayersInSight(player, new_jx, new_jy))
8795 return MF_NO_ACTION;
8797 element = MovingOrBlocked2ElementIfNotLeaving(new_jx, new_jy);
8799 if (DONT_RUN_INTO(element))
8801 if (element == EL_ACID && dx == 0 && dy == 1)
8803 SplashAcid(new_jx, new_jy);
8804 Feld[jx][jy] = EL_PLAYER_1;
8805 InitMovingField(jx, jy, MV_DOWN);
8806 Store[jx][jy] = EL_ACID;
8807 ContinueMoving(jx, jy);
8811 TestIfPlayerRunsIntoBadThing(jx, jy, player->MovDir);
8816 can_move = DigField(player, jx, jy, new_jx, new_jy, real_dx,real_dy, DF_DIG);
8817 if (can_move != MF_MOVING)
8820 /* check if DigField() has caused relocation of the player */
8821 if (player->jx != jx || player->jy != jy)
8822 return MF_NO_ACTION; /* <-- !!! CHECK THIS [-> MF_ACTION ?] !!! */
8824 StorePlayer[jx][jy] = 0;
8825 player->last_jx = jx;
8826 player->last_jy = jy;
8827 player->jx = new_jx;
8828 player->jy = new_jy;
8829 StorePlayer[new_jx][new_jy] = player->element_nr;
8831 if (player->move_delay_value_next != -1)
8833 player->move_delay_value = player->move_delay_value_next;
8834 player->move_delay_value_next = -1;
8838 (dx > 0 || dy > 0 ? -1 : 1) * (TILEX - TILEX / player->move_delay_value);
8840 player->step_counter++;
8842 PlayerVisit[jx][jy] = FrameCounter;
8844 ScrollPlayer(player, SCROLL_INIT);
8849 boolean MovePlayer(struct PlayerInfo *player, int dx, int dy)
8851 int jx = player->jx, jy = player->jy;
8852 int old_jx = jx, old_jy = jy;
8853 int moved = MF_NO_ACTION;
8855 if (!player->active)
8860 if (player->MovPos == 0)
8862 player->is_moving = FALSE;
8863 player->is_digging = FALSE;
8864 player->is_collecting = FALSE;
8865 player->is_snapping = FALSE;
8866 player->is_pushing = FALSE;
8872 if (player->move_delay > 0)
8875 player->move_delay = -1; /* set to "uninitialized" value */
8877 /* store if player is automatically moved to next field */
8878 player->is_auto_moving = (player->programmed_action != MV_NONE);
8880 /* remove the last programmed player action */
8881 player->programmed_action = 0;
8885 /* should only happen if pre-1.2 tape recordings are played */
8886 /* this is only for backward compatibility */
8888 int original_move_delay_value = player->move_delay_value;
8891 printf("THIS SHOULD ONLY HAPPEN WITH PRE-1.2 LEVEL TAPES. [%ld]\n",
8895 /* scroll remaining steps with finest movement resolution */
8896 player->move_delay_value = MOVE_DELAY_NORMAL_SPEED;
8898 while (player->MovPos)
8900 ScrollPlayer(player, SCROLL_GO_ON);
8901 ScrollScreen(NULL, SCROLL_GO_ON);
8903 AdvanceFrameAndPlayerCounters(player->index_nr);
8909 player->move_delay_value = original_move_delay_value;
8912 if (player->last_move_dir & MV_HORIZONTAL)
8914 if (!(moved |= MovePlayerOneStep(player, 0, dy, dx, dy)))
8915 moved |= MovePlayerOneStep(player, dx, 0, dx, dy);
8919 if (!(moved |= MovePlayerOneStep(player, dx, 0, dx, dy)))
8920 moved |= MovePlayerOneStep(player, 0, dy, dx, dy);
8926 if (moved & MF_MOVING && !ScreenMovPos &&
8927 (player == local_player || !options.network))
8929 int old_scroll_x = scroll_x, old_scroll_y = scroll_y;
8930 int offset = (setup.scroll_delay ? 3 : 0);
8932 if (!IN_VIS_FIELD(SCREENX(jx), SCREENY(jy)))
8934 /* actual player has left the screen -- scroll in that direction */
8935 if (jx != old_jx) /* player has moved horizontally */
8936 scroll_x += (jx - old_jx);
8937 else /* player has moved vertically */
8938 scroll_y += (jy - old_jy);
8942 if (jx != old_jx) /* player has moved horizontally */
8944 if ((player->MovDir == MV_LEFT && scroll_x > jx - MIDPOSX + offset) ||
8945 (player->MovDir == MV_RIGHT && scroll_x < jx - MIDPOSX - offset))
8946 scroll_x = jx-MIDPOSX + (scroll_x < jx-MIDPOSX ? -offset : +offset);
8948 /* don't scroll over playfield boundaries */
8949 if (scroll_x < SBX_Left || scroll_x > SBX_Right)
8950 scroll_x = (scroll_x < SBX_Left ? SBX_Left : SBX_Right);
8952 /* don't scroll more than one field at a time */
8953 scroll_x = old_scroll_x + SIGN(scroll_x - old_scroll_x);
8955 /* don't scroll against the player's moving direction */
8956 if ((player->MovDir == MV_LEFT && scroll_x > old_scroll_x) ||
8957 (player->MovDir == MV_RIGHT && scroll_x < old_scroll_x))
8958 scroll_x = old_scroll_x;
8960 else /* player has moved vertically */
8962 if ((player->MovDir == MV_UP && scroll_y > jy - MIDPOSY + offset) ||
8963 (player->MovDir == MV_DOWN && scroll_y < jy - MIDPOSY - offset))
8964 scroll_y = jy-MIDPOSY + (scroll_y < jy-MIDPOSY ? -offset : +offset);
8966 /* don't scroll over playfield boundaries */
8967 if (scroll_y < SBY_Upper || scroll_y > SBY_Lower)
8968 scroll_y = (scroll_y < SBY_Upper ? SBY_Upper : SBY_Lower);
8970 /* don't scroll more than one field at a time */
8971 scroll_y = old_scroll_y + SIGN(scroll_y - old_scroll_y);
8973 /* don't scroll against the player's moving direction */
8974 if ((player->MovDir == MV_UP && scroll_y > old_scroll_y) ||
8975 (player->MovDir == MV_DOWN && scroll_y < old_scroll_y))
8976 scroll_y = old_scroll_y;
8980 if (scroll_x != old_scroll_x || scroll_y != old_scroll_y)
8982 if (!options.network && !AllPlayersInVisibleScreen())
8984 scroll_x = old_scroll_x;
8985 scroll_y = old_scroll_y;
8989 ScrollScreen(player, SCROLL_INIT);
8990 ScrollLevel(old_scroll_x - scroll_x, old_scroll_y - scroll_y);
8995 player->StepFrame = 0;
8997 if (moved & MF_MOVING)
8999 if (old_jx != jx && old_jy == jy)
9000 player->MovDir = (old_jx < jx ? MV_RIGHT : MV_LEFT);
9001 else if (old_jx == jx && old_jy != jy)
9002 player->MovDir = (old_jy < jy ? MV_DOWN : MV_UP);
9004 DrawLevelField(jx, jy); /* for "crumbled sand" */
9006 player->last_move_dir = player->MovDir;
9007 player->is_moving = TRUE;
9008 player->is_snapping = FALSE;
9009 player->is_switching = FALSE;
9010 player->is_dropping = FALSE;
9014 CheckGravityMovementWhenNotMoving(player);
9016 player->is_moving = FALSE;
9018 /* at this point, the player is allowed to move, but cannot move right now
9019 (e.g. because of something blocking the way) -- ensure that the player
9020 is also allowed to move in the next frame (in old versions before 3.1.1,
9021 the player was forced to wait again for eight frames before next try) */
9023 if (game.engine_version >= VERSION_IDENT(3,1,1,0))
9024 player->move_delay = 0; /* allow direct movement in the next frame */
9027 if (player->move_delay == -1) /* not yet initialized by DigField() */
9028 player->move_delay = player->move_delay_value;
9030 if (game.engine_version < VERSION_IDENT(3,0,7,0))
9032 TestIfPlayerTouchesBadThing(jx, jy);
9033 TestIfPlayerTouchesCustomElement(jx, jy);
9036 if (!player->active)
9037 RemovePlayer(player);
9042 void ScrollPlayer(struct PlayerInfo *player, int mode)
9044 int jx = player->jx, jy = player->jy;
9045 int last_jx = player->last_jx, last_jy = player->last_jy;
9046 int move_stepsize = TILEX / player->move_delay_value;
9048 #if USE_NEW_PLAYER_SPEED
9049 if (!player->active)
9052 if (player->MovPos == 0 && mode == SCROLL_GO_ON) /* player not moving */
9055 if (!player->active || player->MovPos == 0)
9059 if (mode == SCROLL_INIT)
9061 player->actual_frame_counter = FrameCounter;
9062 player->GfxPos = move_stepsize * (player->MovPos / move_stepsize);
9064 if ((player->block_last_field || player->block_delay_adjustment > 0) &&
9065 Feld[last_jx][last_jy] == EL_EMPTY)
9067 int last_field_block_delay = 0; /* start with no blocking at all */
9068 int block_delay_adjustment = player->block_delay_adjustment;
9070 /* if player blocks last field, add delay for exactly one move */
9071 if (player->block_last_field)
9073 last_field_block_delay += player->move_delay_value;
9075 /* when blocking enabled, prevent moving up despite gravity */
9076 if (game.gravity && player->MovDir == MV_UP)
9077 block_delay_adjustment = -1;
9080 /* add block delay adjustment (also possible when not blocking) */
9081 last_field_block_delay += block_delay_adjustment;
9083 Feld[last_jx][last_jy] = EL_PLAYER_IS_LEAVING;
9084 MovDelay[last_jx][last_jy] = last_field_block_delay + 1;
9087 #if USE_NEW_PLAYER_SPEED
9088 if (player->MovPos != 0) /* player has not yet reached destination */
9094 else if (!FrameReached(&player->actual_frame_counter, 1))
9098 printf("::: player->MovPos: %d -> %d\n",
9100 player->MovPos + (player->MovPos > 0 ? -1 : 1) * move_stepsize);
9103 #if USE_NEW_PLAYER_SPEED
9104 if (player->MovPos != 0)
9106 player->MovPos += (player->MovPos > 0 ? -1 : 1) * move_stepsize;
9107 player->GfxPos = move_stepsize * (player->MovPos / move_stepsize);
9109 /* before DrawPlayer() to draw correct player graphic for this case */
9110 if (player->MovPos == 0)
9111 CheckGravityMovement(player);
9114 player->MovPos += (player->MovPos > 0 ? -1 : 1) * move_stepsize;
9115 player->GfxPos = move_stepsize * (player->MovPos / move_stepsize);
9117 /* before DrawPlayer() to draw correct player graphic for this case */
9118 if (player->MovPos == 0)
9119 CheckGravityMovement(player);
9122 if (player->MovPos == 0) /* player reached destination field */
9125 printf("::: player reached destination field\n");
9128 if (player->move_delay_reset_counter > 0)
9130 player->move_delay_reset_counter--;
9132 if (player->move_delay_reset_counter == 0)
9134 /* continue with normal speed after quickly moving through gate */
9135 HALVE_PLAYER_SPEED(player);
9137 /* be able to make the next move without delay */
9138 player->move_delay = 0;
9142 player->last_jx = jx;
9143 player->last_jy = jy;
9145 if (Feld[jx][jy] == EL_EXIT_OPEN ||
9146 Feld[jx][jy] == EL_SP_EXIT_OPEN ||
9147 Feld[jx][jy] == EL_SP_EXIT_OPENING) /* <-- special case */
9149 DrawPlayer(player); /* needed here only to cleanup last field */
9150 RemovePlayer(player);
9152 if (local_player->friends_still_needed == 0 ||
9153 IS_SP_ELEMENT(Feld[jx][jy]))
9154 player->LevelSolved = player->GameOver = TRUE;
9157 /* this breaks one level: "machine", level 000 */
9159 int move_direction = player->MovDir;
9160 int enter_side = MV_DIR_OPPOSITE(move_direction);
9161 int leave_side = move_direction;
9162 int old_jx = last_jx;
9163 int old_jy = last_jy;
9164 int old_element = Feld[old_jx][old_jy];
9165 int new_element = Feld[jx][jy];
9167 if (IS_CUSTOM_ELEMENT(old_element))
9168 CheckElementChangeByPlayer(old_jx, old_jy, old_element,
9170 player->index_bit, leave_side);
9172 CheckTriggeredElementChangeByPlayer(old_jx, old_jy, old_element,
9174 player->index_bit, leave_side);
9176 if (IS_CUSTOM_ELEMENT(new_element))
9177 CheckElementChangeByPlayer(jx, jy, new_element, CE_ENTERED_BY_PLAYER,
9178 player->index_bit, enter_side);
9180 CheckTriggeredElementChangeByPlayer(jx, jy, new_element,
9182 player->index_bit, enter_side);
9184 CheckTriggeredElementChangeBySide(jx, jy, player->element_nr,
9185 CE_MOVE_OF_X, move_direction);
9188 if (game.engine_version >= VERSION_IDENT(3,0,7,0))
9190 TestIfPlayerTouchesBadThing(jx, jy);
9191 TestIfPlayerTouchesCustomElement(jx, jy);
9193 /* needed because pushed element has not yet reached its destination,
9194 so it would trigger a change event at its previous field location */
9195 if (!player->is_pushing)
9196 TestIfElementTouchesCustomElement(jx, jy); /* for empty space */
9198 if (!player->active)
9199 RemovePlayer(player);
9202 if (level.use_step_counter)
9212 if (TimeLeft <= 10 && setup.time_limit)
9213 PlaySoundStereo(SND_GAME_RUNNING_OUT_OF_TIME, SOUND_MIDDLE);
9215 DrawGameValue_Time(TimeLeft);
9217 if (!TimeLeft && setup.time_limit)
9218 for (i = 0; i < MAX_PLAYERS; i++)
9219 KillPlayer(&stored_player[i]);
9221 else if (level.time == 0 && !AllPlayersGone) /* level w/o time limit */
9222 DrawGameValue_Time(TimePlayed);
9225 if (tape.single_step && tape.recording && !tape.pausing &&
9226 !player->programmed_action)
9227 TapeTogglePause(TAPE_TOGGLE_AUTOMATIC);
9231 void ScrollScreen(struct PlayerInfo *player, int mode)
9233 static unsigned long screen_frame_counter = 0;
9235 if (mode == SCROLL_INIT)
9237 /* set scrolling step size according to actual player's moving speed */
9238 ScrollStepSize = TILEX / player->move_delay_value;
9240 screen_frame_counter = FrameCounter;
9241 ScreenMovDir = player->MovDir;
9242 ScreenMovPos = player->MovPos;
9243 ScreenGfxPos = ScrollStepSize * (ScreenMovPos / ScrollStepSize);
9246 else if (!FrameReached(&screen_frame_counter, 1))
9251 ScreenMovPos += (ScreenMovPos > 0 ? -1 : 1) * ScrollStepSize;
9252 ScreenGfxPos = ScrollStepSize * (ScreenMovPos / ScrollStepSize);
9253 redraw_mask |= REDRAW_FIELD;
9256 ScreenMovDir = MV_NONE;
9259 void TestIfPlayerTouchesCustomElement(int x, int y)
9261 static int xy[4][2] =
9268 static int trigger_sides[4][2] =
9270 /* center side border side */
9271 { CH_SIDE_TOP, CH_SIDE_BOTTOM }, /* check top */
9272 { CH_SIDE_LEFT, CH_SIDE_RIGHT }, /* check left */
9273 { CH_SIDE_RIGHT, CH_SIDE_LEFT }, /* check right */
9274 { CH_SIDE_BOTTOM, CH_SIDE_TOP } /* check bottom */
9276 static int touch_dir[4] =
9283 int center_element = Feld[x][y]; /* should always be non-moving! */
9286 for (i = 0; i < NUM_DIRECTIONS; i++)
9288 int xx = x + xy[i][0];
9289 int yy = y + xy[i][1];
9290 int center_side = trigger_sides[i][0];
9291 int border_side = trigger_sides[i][1];
9294 if (!IN_LEV_FIELD(xx, yy))
9297 if (IS_PLAYER(x, y))
9299 struct PlayerInfo *player = PLAYERINFO(x, y);
9301 if (game.engine_version < VERSION_IDENT(3,0,7,0))
9302 border_element = Feld[xx][yy]; /* may be moving! */
9303 else if (!IS_MOVING(xx, yy) && !IS_BLOCKED(xx, yy))
9304 border_element = Feld[xx][yy];
9305 else if (MovDir[xx][yy] & touch_dir[i]) /* elements are touching */
9306 border_element = MovingOrBlocked2Element(xx, yy);
9308 continue; /* center and border element do not touch */
9310 CheckElementChangeByPlayer(xx, yy, border_element, CE_TOUCHED_BY_PLAYER,
9311 player->index_bit, border_side);
9312 CheckTriggeredElementChangeByPlayer(xx, yy, border_element,
9313 CE_PLAYER_TOUCHES_X,
9314 player->index_bit, border_side);
9316 else if (IS_PLAYER(xx, yy))
9318 struct PlayerInfo *player = PLAYERINFO(xx, yy);
9320 if (game.engine_version >= VERSION_IDENT(3,0,7,0))
9322 if (player->MovPos != 0 && !(player->MovDir & touch_dir[i]))
9323 continue; /* center and border element do not touch */
9326 CheckElementChangeByPlayer(x, y, center_element, CE_TOUCHED_BY_PLAYER,
9327 player->index_bit, center_side);
9328 CheckTriggeredElementChangeByPlayer(x, y, center_element,
9329 CE_PLAYER_TOUCHES_X,
9330 player->index_bit, center_side);
9336 void TestIfElementTouchesCustomElement(int x, int y)
9338 static int xy[4][2] =
9345 static int trigger_sides[4][2] =
9347 /* center side border side */
9348 { CH_SIDE_TOP, CH_SIDE_BOTTOM }, /* check top */
9349 { CH_SIDE_LEFT, CH_SIDE_RIGHT }, /* check left */
9350 { CH_SIDE_RIGHT, CH_SIDE_LEFT }, /* check right */
9351 { CH_SIDE_BOTTOM, CH_SIDE_TOP } /* check bottom */
9353 static int touch_dir[4] =
9360 boolean change_center_element = FALSE;
9361 int center_element = Feld[x][y]; /* should always be non-moving! */
9364 for (i = 0; i < NUM_DIRECTIONS; i++)
9366 int xx = x + xy[i][0];
9367 int yy = y + xy[i][1];
9368 int center_side = trigger_sides[i][0];
9369 int border_side = trigger_sides[i][1];
9372 if (!IN_LEV_FIELD(xx, yy))
9375 if (game.engine_version < VERSION_IDENT(3,0,7,0))
9376 border_element = Feld[xx][yy]; /* may be moving! */
9377 else if (!IS_MOVING(xx, yy) && !IS_BLOCKED(xx, yy))
9378 border_element = Feld[xx][yy];
9379 else if (MovDir[xx][yy] & touch_dir[i]) /* elements are touching */
9380 border_element = MovingOrBlocked2Element(xx, yy);
9382 continue; /* center and border element do not touch */
9384 /* check for change of center element (but change it only once) */
9385 if (!change_center_element)
9386 change_center_element =
9387 CheckElementChangeBySide(x, y, center_element, border_element,
9388 CE_TOUCHING_X, border_side);
9390 /* check for change of border element */
9391 CheckElementChangeBySide(xx, yy, border_element, center_element,
9392 CE_TOUCHING_X, center_side);
9396 void TestIfElementHitsCustomElement(int x, int y, int direction)
9398 int dx = (direction == MV_LEFT ? -1 : direction == MV_RIGHT ? +1 : 0);
9399 int dy = (direction == MV_UP ? -1 : direction == MV_DOWN ? +1 : 0);
9400 int hitx = x + dx, hity = y + dy;
9401 int hitting_element = Feld[x][y];
9402 int touched_element;
9404 if (IN_LEV_FIELD(hitx, hity) && IS_FREE(hitx, hity))
9407 touched_element = (IN_LEV_FIELD(hitx, hity) ?
9408 MovingOrBlocked2Element(hitx, hity) : EL_STEELWALL);
9410 if (IN_LEV_FIELD(hitx, hity))
9412 int opposite_direction = MV_DIR_OPPOSITE(direction);
9413 int hitting_side = direction;
9414 int touched_side = opposite_direction;
9415 boolean object_hit = (!IS_MOVING(hitx, hity) ||
9416 MovDir[hitx][hity] != direction ||
9417 ABS(MovPos[hitx][hity]) <= TILEY / 2);
9423 CheckElementChangeBySide(x, y, hitting_element, touched_element,
9424 CE_HITTING_X, touched_side);
9426 CheckElementChangeBySide(hitx, hity, touched_element,
9427 hitting_element, CE_HIT_BY_X, hitting_side);
9429 CheckElementChangeBySide(hitx, hity, touched_element, hitting_element,
9430 CE_HIT_BY_SOMETHING, opposite_direction);
9434 /* "hitting something" is also true when hitting the playfield border */
9435 CheckElementChangeBySide(x, y, hitting_element, touched_element,
9436 CE_HITTING_SOMETHING, direction);
9440 void TestIfElementSmashesCustomElement(int x, int y, int direction)
9442 int dx = (direction == MV_LEFT ? -1 : direction == MV_RIGHT ? +1 : 0);
9443 int dy = (direction == MV_UP ? -1 : direction == MV_DOWN ? +1 : 0);
9444 int hitx = x + dx, hity = y + dy;
9445 int hitting_element = Feld[x][y];
9446 int touched_element;
9448 boolean object_hit = (IN_LEV_FIELD(hitx, hity) &&
9449 !IS_FREE(hitx, hity) &&
9450 (!IS_MOVING(hitx, hity) ||
9451 MovDir[hitx][hity] != direction ||
9452 ABS(MovPos[hitx][hity]) <= TILEY / 2));
9455 if (IN_LEV_FIELD(hitx, hity) && IS_FREE(hitx, hity))
9459 if (IN_LEV_FIELD(hitx, hity) && !object_hit)
9463 touched_element = (IN_LEV_FIELD(hitx, hity) ?
9464 MovingOrBlocked2Element(hitx, hity) : EL_STEELWALL);
9466 CheckElementChangeBySide(x, y, hitting_element, touched_element,
9467 EP_CAN_SMASH_EVERYTHING, direction);
9469 if (IN_LEV_FIELD(hitx, hity))
9471 int opposite_direction = MV_DIR_OPPOSITE(direction);
9472 int hitting_side = direction;
9473 int touched_side = opposite_direction;
9475 int touched_element = MovingOrBlocked2Element(hitx, hity);
9478 boolean object_hit = (!IS_MOVING(hitx, hity) ||
9479 MovDir[hitx][hity] != direction ||
9480 ABS(MovPos[hitx][hity]) <= TILEY / 2);
9489 CheckElementChangeBySide(hitx, hity, touched_element, hitting_element,
9490 CE_SMASHED_BY_SOMETHING, opposite_direction);
9492 CheckElementChangeBySide(x, y, hitting_element, touched_element,
9493 CE_OTHER_IS_SMASHING, touched_side);
9495 CheckElementChangeBySide(hitx, hity, touched_element, hitting_element,
9496 CE_OTHER_GETS_SMASHED, hitting_side);
9502 void TestIfGoodThingHitsBadThing(int good_x, int good_y, int good_move_dir)
9504 int i, kill_x = -1, kill_y = -1;
9505 int bad_element = -1;
9506 static int test_xy[4][2] =
9513 static int test_dir[4] =
9521 for (i = 0; i < NUM_DIRECTIONS; i++)
9523 int test_x, test_y, test_move_dir, test_element;
9525 test_x = good_x + test_xy[i][0];
9526 test_y = good_y + test_xy[i][1];
9528 if (!IN_LEV_FIELD(test_x, test_y))
9532 (IS_MOVING(test_x, test_y) ? MovDir[test_x][test_y] : MV_NONE);
9534 test_element = MovingOrBlocked2ElementIfNotLeaving(test_x, test_y);
9536 /* 1st case: good thing is moving towards DONT_RUN_INTO style bad thing;
9537 2nd case: DONT_TOUCH style bad thing does not move away from good thing
9539 if ((DONT_RUN_INTO(test_element) && good_move_dir == test_dir[i]) ||
9540 (DONT_TOUCH(test_element) && test_move_dir != test_dir[i]))
9544 bad_element = test_element;
9550 if (kill_x != -1 || kill_y != -1)
9552 if (IS_PLAYER(good_x, good_y))
9554 struct PlayerInfo *player = PLAYERINFO(good_x, good_y);
9556 if (player->shield_deadly_time_left > 0 &&
9557 !IS_INDESTRUCTIBLE(bad_element))
9558 Bang(kill_x, kill_y);
9559 else if (!PLAYER_ENEMY_PROTECTED(good_x, good_y))
9563 Bang(good_x, good_y);
9567 void TestIfBadThingHitsGoodThing(int bad_x, int bad_y, int bad_move_dir)
9569 int i, kill_x = -1, kill_y = -1;
9570 int bad_element = Feld[bad_x][bad_y];
9571 static int test_xy[4][2] =
9578 static int touch_dir[4] =
9585 static int test_dir[4] =
9593 if (bad_element == EL_EXPLOSION) /* skip just exploding bad things */
9596 for (i = 0; i < NUM_DIRECTIONS; i++)
9598 int test_x, test_y, test_move_dir, test_element;
9600 test_x = bad_x + test_xy[i][0];
9601 test_y = bad_y + test_xy[i][1];
9602 if (!IN_LEV_FIELD(test_x, test_y))
9606 (IS_MOVING(test_x, test_y) ? MovDir[test_x][test_y] : MV_NONE);
9608 test_element = Feld[test_x][test_y];
9610 /* 1st case: good thing is moving towards DONT_RUN_INTO style bad thing;
9611 2nd case: DONT_TOUCH style bad thing does not move away from good thing
9613 if ((DONT_RUN_INTO(bad_element) && bad_move_dir == test_dir[i]) ||
9614 (DONT_TOUCH(bad_element) && test_move_dir != test_dir[i]))
9616 /* good thing is player or penguin that does not move away */
9617 if (IS_PLAYER(test_x, test_y))
9619 struct PlayerInfo *player = PLAYERINFO(test_x, test_y);
9621 if (bad_element == EL_ROBOT && player->is_moving)
9622 continue; /* robot does not kill player if he is moving */
9624 if (game.engine_version >= VERSION_IDENT(3,0,7,0))
9626 if (player->MovPos != 0 && !(player->MovDir & touch_dir[i]))
9627 continue; /* center and border element do not touch */
9634 else if (test_element == EL_PENGUIN)
9643 if (kill_x != -1 || kill_y != -1)
9645 if (IS_PLAYER(kill_x, kill_y))
9647 struct PlayerInfo *player = PLAYERINFO(kill_x, kill_y);
9649 if (player->shield_deadly_time_left > 0 &&
9650 !IS_INDESTRUCTIBLE(bad_element))
9652 else if (!PLAYER_ENEMY_PROTECTED(kill_x, kill_y))
9656 Bang(kill_x, kill_y);
9660 void TestIfPlayerTouchesBadThing(int x, int y)
9662 TestIfGoodThingHitsBadThing(x, y, MV_NONE);
9665 void TestIfPlayerRunsIntoBadThing(int x, int y, int move_dir)
9667 TestIfGoodThingHitsBadThing(x, y, move_dir);
9670 void TestIfBadThingTouchesPlayer(int x, int y)
9672 TestIfBadThingHitsGoodThing(x, y, MV_NONE);
9675 void TestIfBadThingRunsIntoPlayer(int x, int y, int move_dir)
9677 TestIfBadThingHitsGoodThing(x, y, move_dir);
9680 void TestIfFriendTouchesBadThing(int x, int y)
9682 TestIfGoodThingHitsBadThing(x, y, MV_NONE);
9685 void TestIfBadThingTouchesFriend(int x, int y)
9687 TestIfBadThingHitsGoodThing(x, y, MV_NONE);
9690 void TestIfBadThingTouchesOtherBadThing(int bad_x, int bad_y)
9692 int i, kill_x = bad_x, kill_y = bad_y;
9693 static int xy[4][2] =
9701 for (i = 0; i < NUM_DIRECTIONS; i++)
9705 x = bad_x + xy[i][0];
9706 y = bad_y + xy[i][1];
9707 if (!IN_LEV_FIELD(x, y))
9710 element = Feld[x][y];
9711 if (IS_AMOEBOID(element) || element == EL_GAME_OF_LIFE ||
9712 element == EL_AMOEBA_GROWING || element == EL_AMOEBA_DROP)
9720 if (kill_x != bad_x || kill_y != bad_y)
9724 void KillPlayer(struct PlayerInfo *player)
9726 int jx = player->jx, jy = player->jy;
9728 if (!player->active)
9731 /* remove accessible field at the player's position */
9732 Feld[jx][jy] = EL_EMPTY;
9734 /* deactivate shield (else Bang()/Explode() would not work right) */
9735 player->shield_normal_time_left = 0;
9736 player->shield_deadly_time_left = 0;
9742 static void KillPlayerUnlessEnemyProtected(int x, int y)
9744 if (!PLAYER_ENEMY_PROTECTED(x, y))
9745 KillPlayer(PLAYERINFO(x, y));
9748 static void KillPlayerUnlessExplosionProtected(int x, int y)
9750 if (!PLAYER_EXPLOSION_PROTECTED(x, y))
9751 KillPlayer(PLAYERINFO(x, y));
9754 void BuryPlayer(struct PlayerInfo *player)
9756 int jx = player->jx, jy = player->jy;
9758 if (!player->active)
9761 PlayLevelSoundElementAction(jx, jy, player->artwork_element, ACTION_DYING);
9762 PlayLevelSound(jx, jy, SND_GAME_LOSING);
9764 player->GameOver = TRUE;
9765 RemovePlayer(player);
9768 void RemovePlayer(struct PlayerInfo *player)
9770 int jx = player->jx, jy = player->jy;
9771 int i, found = FALSE;
9773 player->present = FALSE;
9774 player->active = FALSE;
9776 if (!ExplodeField[jx][jy])
9777 StorePlayer[jx][jy] = 0;
9779 if (player->is_moving)
9780 DrawLevelField(player->last_jx, player->last_jy);
9782 for (i = 0; i < MAX_PLAYERS; i++)
9783 if (stored_player[i].active)
9787 AllPlayersGone = TRUE;
9793 #if USE_NEW_SNAP_DELAY
9794 static void setFieldForSnapping(int x, int y, int element, int direction)
9796 struct ElementInfo *ei = &element_info[element];
9797 int direction_bit = MV_DIR_BIT(direction);
9798 int graphic_snapping = ei->direction_graphic[ACTION_SNAPPING][direction_bit];
9799 int action = (graphic_snapping != IMG_EMPTY_SPACE ? ACTION_SNAPPING :
9800 IS_DIGGABLE(element) ? ACTION_DIGGING : ACTION_COLLECTING);
9802 Feld[x][y] = EL_ELEMENT_SNAPPING;
9803 MovDelay[x][y] = MOVE_DELAY_NORMAL_SPEED + 1 - 1;
9805 ResetGfxAnimation(x, y);
9807 GfxElement[x][y] = element;
9808 GfxAction[x][y] = action;
9809 GfxDir[x][y] = direction;
9810 GfxFrame[x][y] = -1;
9815 =============================================================================
9816 checkDiagonalPushing()
9817 -----------------------------------------------------------------------------
9818 check if diagonal input device direction results in pushing of object
9819 (by checking if the alternative direction is walkable, diggable, ...)
9820 =============================================================================
9823 static boolean checkDiagonalPushing(struct PlayerInfo *player,
9824 int x, int y, int real_dx, int real_dy)
9826 int jx, jy, dx, dy, xx, yy;
9828 if (real_dx == 0 || real_dy == 0) /* no diagonal direction => push */
9831 /* diagonal direction: check alternative direction */
9836 xx = jx + (dx == 0 ? real_dx : 0);
9837 yy = jy + (dy == 0 ? real_dy : 0);
9839 return (!IN_LEV_FIELD(xx, yy) || IS_SOLID_FOR_PUSHING(Feld[xx][yy]));
9843 =============================================================================
9845 -----------------------------------------------------------------------------
9846 x, y: field next to player (non-diagonal) to try to dig to
9847 real_dx, real_dy: direction as read from input device (can be diagonal)
9848 =============================================================================
9851 int DigField(struct PlayerInfo *player,
9852 int oldx, int oldy, int x, int y,
9853 int real_dx, int real_dy, int mode)
9855 boolean is_player = (IS_PLAYER(oldx, oldy) || mode != DF_DIG);
9856 boolean player_was_pushing = player->is_pushing;
9857 int jx = oldx, jy = oldy;
9858 int dx = x - jx, dy = y - jy;
9859 int nextx = x + dx, nexty = y + dy;
9860 int move_direction = (dx == -1 ? MV_LEFT :
9861 dx == +1 ? MV_RIGHT :
9863 dy == +1 ? MV_DOWN : MV_NONE);
9864 int opposite_direction = MV_DIR_OPPOSITE(move_direction);
9865 int dig_side = MV_DIR_OPPOSITE(move_direction);
9866 int old_element = Feld[jx][jy];
9870 if (is_player) /* function can also be called by EL_PENGUIN */
9872 if (player->MovPos == 0)
9874 player->is_digging = FALSE;
9875 player->is_collecting = FALSE;
9878 if (player->MovPos == 0) /* last pushing move finished */
9879 player->is_pushing = FALSE;
9881 if (mode == DF_NO_PUSH) /* player just stopped pushing */
9883 player->is_switching = FALSE;
9884 player->push_delay = -1;
9886 return MF_NO_ACTION;
9890 if (IS_MOVING(x, y) || IS_PLAYER(x, y))
9891 return MF_NO_ACTION;
9893 if (IS_TUBE(Back[jx][jy]) && game.engine_version >= VERSION_IDENT(2,2,0,0))
9894 old_element = Back[jx][jy];
9896 /* in case of element dropped at player position, check background */
9897 else if (Back[jx][jy] != EL_EMPTY &&
9898 game.engine_version >= VERSION_IDENT(2,2,0,0))
9899 old_element = Back[jx][jy];
9901 if (IS_WALKABLE(old_element) && !ACCESS_FROM(old_element, move_direction))
9902 return MF_NO_ACTION; /* field has no opening in this direction */
9904 if (IS_PASSABLE(old_element) && !ACCESS_FROM(old_element,opposite_direction))
9905 return MF_NO_ACTION; /* field has no opening in this direction */
9907 element = Feld[x][y];
9908 #if USE_NEW_CUSTOM_VALUE
9911 collect_count = element_info[element].collect_count_initial;
9913 collect_count = CustomValue[x][y];
9917 collect_count = element_info[element].collect_count_initial;
9921 if (element != EL_BLOCKED &&
9922 CustomValue[x][y] != element_info[element].collect_count_initial)
9923 printf("::: %d: %d != %d\n",
9926 element_info[element].collect_count_initial);
9929 if (!is_player && !IS_COLLECTIBLE(element)) /* penguin cannot collect it */
9930 return MF_NO_ACTION;
9932 if (mode == DF_SNAP && !IS_SNAPPABLE(element) &&
9933 game.engine_version >= VERSION_IDENT(2,2,0,0))
9935 CheckElementChangeByPlayer(x, y, element, CE_SNAPPED_BY_PLAYER,
9936 player->index_bit, dig_side);
9937 CheckTriggeredElementChangeByPlayer(x, y, element, CE_PLAYER_SNAPS_X,
9938 player->index_bit, dig_side);
9940 if (Feld[x][y] != element) /* field changed by snapping */
9943 return MF_NO_ACTION;
9946 if (game.gravity && is_player && !player->is_auto_moving &&
9947 canFallDown(player) && move_direction != MV_DOWN &&
9948 !canMoveToValidFieldWithGravity(jx, jy, move_direction))
9949 return MF_NO_ACTION; /* player cannot walk here due to gravity */
9951 if (IS_WALKABLE(element) && ACCESS_FROM(element, opposite_direction))
9953 int sound_element = SND_ELEMENT(element);
9954 int sound_action = ACTION_WALKING;
9956 if (IS_RND_GATE(element))
9958 if (!player->key[RND_GATE_NR(element)])
9959 return MF_NO_ACTION;
9961 else if (IS_RND_GATE_GRAY(element))
9963 if (!player->key[RND_GATE_GRAY_NR(element)])
9964 return MF_NO_ACTION;
9966 else if (IS_RND_GATE_GRAY_ACTIVE(element))
9968 if (!player->key[RND_GATE_GRAY_ACTIVE_NR(element)])
9969 return MF_NO_ACTION;
9971 else if (element == EL_EXIT_OPEN ||
9972 element == EL_SP_EXIT_OPEN ||
9973 element == EL_SP_EXIT_OPENING)
9975 sound_action = ACTION_PASSING; /* player is passing exit */
9977 else if (element == EL_EMPTY)
9979 sound_action = ACTION_MOVING; /* nothing to walk on */
9982 /* play sound from background or player, whatever is available */
9983 if (element_info[sound_element].sound[sound_action] != SND_UNDEFINED)
9984 PlayLevelSoundElementAction(x, y, sound_element, sound_action);
9986 PlayLevelSoundElementAction(x, y, player->artwork_element, sound_action);
9988 else if (IS_PASSABLE(element) && canPassField(x, y, move_direction))
9990 if (!ACCESS_FROM(element, opposite_direction))
9991 return MF_NO_ACTION; /* field not accessible from this direction */
9993 if (CAN_MOVE(element)) /* only fixed elements can be passed! */
9994 return MF_NO_ACTION;
9996 if (IS_EM_GATE(element))
9998 if (!player->key[EM_GATE_NR(element)])
9999 return MF_NO_ACTION;
10001 else if (IS_EM_GATE_GRAY(element))
10003 if (!player->key[EM_GATE_GRAY_NR(element)])
10004 return MF_NO_ACTION;
10006 else if (IS_EM_GATE_GRAY_ACTIVE(element))
10008 if (!player->key[EM_GATE_GRAY_ACTIVE_NR(element)])
10009 return MF_NO_ACTION;
10011 else if (IS_SP_PORT(element))
10013 if (element == EL_SP_GRAVITY_PORT_LEFT ||
10014 element == EL_SP_GRAVITY_PORT_RIGHT ||
10015 element == EL_SP_GRAVITY_PORT_UP ||
10016 element == EL_SP_GRAVITY_PORT_DOWN)
10017 game.gravity = !game.gravity;
10018 else if (element == EL_SP_GRAVITY_ON_PORT_LEFT ||
10019 element == EL_SP_GRAVITY_ON_PORT_RIGHT ||
10020 element == EL_SP_GRAVITY_ON_PORT_UP ||
10021 element == EL_SP_GRAVITY_ON_PORT_DOWN)
10022 game.gravity = TRUE;
10023 else if (element == EL_SP_GRAVITY_OFF_PORT_LEFT ||
10024 element == EL_SP_GRAVITY_OFF_PORT_RIGHT ||
10025 element == EL_SP_GRAVITY_OFF_PORT_UP ||
10026 element == EL_SP_GRAVITY_OFF_PORT_DOWN)
10027 game.gravity = FALSE;
10030 /* automatically move to the next field with double speed */
10031 player->programmed_action = move_direction;
10033 if (player->move_delay_reset_counter == 0)
10035 player->move_delay_reset_counter = 2; /* two double speed steps */
10037 DOUBLE_PLAYER_SPEED(player);
10040 PlayLevelSoundAction(x, y, ACTION_PASSING);
10042 else if (IS_DIGGABLE(element))
10046 if (mode != DF_SNAP)
10048 GfxElement[x][y] = GFX_ELEMENT(element);
10049 player->is_digging = TRUE;
10052 PlayLevelSoundElementAction(x, y, element, ACTION_DIGGING);
10054 CheckTriggeredElementChangeByPlayer(x, y, element, CE_PLAYER_DIGS_X,
10055 player->index_bit, dig_side);
10057 if (mode == DF_SNAP)
10059 #if USE_NEW_SNAP_DELAY
10060 if (level.block_snap_field)
10061 setFieldForSnapping(x, y, element, move_direction);
10063 TestIfElementTouchesCustomElement(x, y); /* for empty space */
10065 TestIfElementTouchesCustomElement(x, y); /* for empty space */
10068 CheckTriggeredElementChangeByPlayer(x, y, element, CE_PLAYER_SNAPS_X,
10069 player->index_bit, dig_side);
10072 else if (IS_COLLECTIBLE(element))
10076 if (is_player && mode != DF_SNAP)
10078 GfxElement[x][y] = element;
10079 player->is_collecting = TRUE;
10082 if (element == EL_SPEED_PILL)
10084 player->move_delay_value = MOVE_DELAY_HIGH_SPEED;
10086 else if (element == EL_EXTRA_TIME && level.time > 0)
10088 TimeLeft += level.extra_time;
10089 DrawGameValue_Time(TimeLeft);
10091 else if (element == EL_SHIELD_NORMAL || element == EL_SHIELD_DEADLY)
10093 player->shield_normal_time_left += level.shield_normal_time;
10094 if (element == EL_SHIELD_DEADLY)
10095 player->shield_deadly_time_left += level.shield_deadly_time;
10097 else if (element == EL_DYNAMITE || element == EL_SP_DISK_RED)
10099 if (player->inventory_size < MAX_INVENTORY_SIZE)
10100 player->inventory_element[player->inventory_size++] = element;
10102 DrawGameValue_Dynamite(local_player->inventory_size);
10104 else if (element == EL_DYNABOMB_INCREASE_NUMBER)
10106 player->dynabomb_count++;
10107 player->dynabombs_left++;
10109 else if (element == EL_DYNABOMB_INCREASE_SIZE)
10111 player->dynabomb_size++;
10113 else if (element == EL_DYNABOMB_INCREASE_POWER)
10115 player->dynabomb_xl = TRUE;
10117 else if (IS_KEY(element))
10119 player->key[KEY_NR(element)] = TRUE;
10121 DrawGameValue_Keys(player->key);
10123 redraw_mask |= REDRAW_DOOR_1;
10125 else if (IS_ENVELOPE(element))
10127 player->show_envelope = element;
10129 else if (element == EL_EMC_LENSES)
10131 game.lenses_time_left = level.lenses_time * FRAMES_PER_SECOND;
10133 RedrawAllInvisibleElementsForLenses();
10135 else if (element == EL_EMC_MAGNIFIER)
10137 game.magnify_time_left = level.magnify_time * FRAMES_PER_SECOND;
10139 RedrawAllInvisibleElementsForMagnifier();
10141 else if (IS_DROPPABLE(element) ||
10142 IS_THROWABLE(element)) /* can be collected and dropped */
10146 if (collect_count == 0)
10147 player->inventory_infinite_element = element;
10149 for (i = 0; i < collect_count; i++)
10150 if (player->inventory_size < MAX_INVENTORY_SIZE)
10151 player->inventory_element[player->inventory_size++] = element;
10153 DrawGameValue_Dynamite(local_player->inventory_size);
10155 else if (collect_count > 0)
10157 local_player->gems_still_needed -= collect_count;
10158 if (local_player->gems_still_needed < 0)
10159 local_player->gems_still_needed = 0;
10161 DrawGameValue_Emeralds(local_player->gems_still_needed);
10164 RaiseScoreElement(element);
10165 PlayLevelSoundElementAction(x, y, element, ACTION_COLLECTING);
10168 CheckTriggeredElementChangeByPlayer(x, y, element, CE_PLAYER_COLLECTS_X,
10169 player->index_bit, dig_side);
10171 if (mode == DF_SNAP)
10173 #if USE_NEW_SNAP_DELAY
10174 if (level.block_snap_field)
10175 setFieldForSnapping(x, y, element, move_direction);
10177 TestIfElementTouchesCustomElement(x, y); /* for empty space */
10179 TestIfElementTouchesCustomElement(x, y); /* for empty space */
10182 CheckTriggeredElementChangeByPlayer(x, y, element, CE_PLAYER_SNAPS_X,
10183 player->index_bit, dig_side);
10186 else if (IS_PUSHABLE(element))
10188 if (mode == DF_SNAP && element != EL_BD_ROCK)
10189 return MF_NO_ACTION;
10191 if (CAN_FALL(element) && dy)
10192 return MF_NO_ACTION;
10194 if (CAN_FALL(element) && IN_LEV_FIELD(x, y + 1) && IS_FREE(x, y + 1) &&
10195 !(element == EL_SPRING && level.use_spring_bug))
10196 return MF_NO_ACTION;
10198 if (CAN_MOVE(element) && GET_MAX_MOVE_DELAY(element) == 0 &&
10199 ((move_direction & MV_VERTICAL &&
10200 ((element_info[element].move_pattern & MV_LEFT &&
10201 IN_LEV_FIELD(x - 1, y) && IS_FREE(x - 1, y)) ||
10202 (element_info[element].move_pattern & MV_RIGHT &&
10203 IN_LEV_FIELD(x + 1, y) && IS_FREE(x + 1, y)))) ||
10204 (move_direction & MV_HORIZONTAL &&
10205 ((element_info[element].move_pattern & MV_UP &&
10206 IN_LEV_FIELD(x, y - 1) && IS_FREE(x, y - 1)) ||
10207 (element_info[element].move_pattern & MV_DOWN &&
10208 IN_LEV_FIELD(x, y + 1) && IS_FREE(x, y + 1))))))
10209 return MF_NO_ACTION;
10211 /* do not push elements already moving away faster than player */
10212 if (CAN_MOVE(element) && MovDir[x][y] == move_direction &&
10213 ABS(getElementMoveStepsize(x, y)) > MOVE_STEPSIZE_NORMAL)
10214 return MF_NO_ACTION;
10216 if (game.engine_version >= VERSION_IDENT(3,1,0,0))
10218 if (player->push_delay_value == -1 || !player_was_pushing)
10219 player->push_delay_value = GET_NEW_PUSH_DELAY(element);
10221 else if (game.engine_version >= VERSION_IDENT(3,0,7,1))
10223 if (player->push_delay_value == -1)
10224 player->push_delay_value = GET_NEW_PUSH_DELAY(element);
10226 else if (game.engine_version >= VERSION_IDENT(2,2,0,7))
10228 if (!player->is_pushing)
10229 player->push_delay_value = GET_NEW_PUSH_DELAY(element);
10232 player->is_pushing = TRUE;
10234 if (!(IN_LEV_FIELD(nextx, nexty) &&
10235 (IS_FREE(nextx, nexty) ||
10236 (Feld[nextx][nexty] == EL_SOKOBAN_FIELD_EMPTY &&
10237 IS_SB_ELEMENT(element)))))
10238 return MF_NO_ACTION;
10240 if (!checkDiagonalPushing(player, x, y, real_dx, real_dy))
10241 return MF_NO_ACTION;
10243 if (player->push_delay == -1) /* new pushing; restart delay */
10244 player->push_delay = 0;
10246 if (player->push_delay < player->push_delay_value &&
10247 !(tape.playing && tape.file_version < FILE_VERSION_2_0) &&
10248 element != EL_SPRING && element != EL_BALLOON)
10250 /* make sure that there is no move delay before next try to push */
10251 if (game.engine_version >= VERSION_IDENT(3,0,7,1))
10252 player->move_delay = 0;
10254 return MF_NO_ACTION;
10257 if (IS_SB_ELEMENT(element))
10259 if (element == EL_SOKOBAN_FIELD_FULL)
10261 Back[x][y] = EL_SOKOBAN_FIELD_EMPTY;
10262 local_player->sokobanfields_still_needed++;
10265 if (Feld[nextx][nexty] == EL_SOKOBAN_FIELD_EMPTY)
10267 Back[nextx][nexty] = EL_SOKOBAN_FIELD_EMPTY;
10268 local_player->sokobanfields_still_needed--;
10271 Feld[x][y] = EL_SOKOBAN_OBJECT;
10273 if (Back[x][y] == Back[nextx][nexty])
10274 PlayLevelSoundAction(x, y, ACTION_PUSHING);
10275 else if (Back[x][y] != 0)
10276 PlayLevelSoundElementAction(x, y, EL_SOKOBAN_FIELD_FULL,
10279 PlayLevelSoundElementAction(nextx, nexty, EL_SOKOBAN_FIELD_EMPTY,
10282 if (local_player->sokobanfields_still_needed == 0 &&
10283 game.emulation == EMU_SOKOBAN)
10285 player->LevelSolved = player->GameOver = TRUE;
10286 PlayLevelSound(x, y, SND_GAME_SOKOBAN_SOLVING);
10290 PlayLevelSoundElementAction(x, y, element, ACTION_PUSHING);
10292 InitMovingField(x, y, move_direction);
10293 GfxAction[x][y] = ACTION_PUSHING;
10295 if (mode == DF_SNAP)
10296 ContinueMoving(x, y);
10298 MovPos[x][y] = (dx != 0 ? dx : dy);
10300 Pushed[x][y] = TRUE;
10301 Pushed[nextx][nexty] = TRUE;
10303 if (game.engine_version < VERSION_IDENT(2,2,0,7))
10304 player->push_delay_value = GET_NEW_PUSH_DELAY(element);
10306 player->push_delay_value = -1; /* get new value later */
10308 /* check for element change _after_ element has been pushed */
10309 if (game.use_change_when_pushing_bug)
10311 CheckElementChangeByPlayer(x, y, element, CE_PUSHED_BY_PLAYER,
10312 player->index_bit, dig_side);
10313 CheckTriggeredElementChangeByPlayer(x, y, element, CE_PLAYER_PUSHES_X,
10314 player->index_bit, dig_side);
10317 else if (IS_SWITCHABLE(element))
10319 if (PLAYER_SWITCHING(player, x, y))
10321 CheckTriggeredElementChangeByPlayer(x, y, element, CE_PLAYER_PRESSES_X,
10322 player->index_bit, dig_side);
10327 player->is_switching = TRUE;
10328 player->switch_x = x;
10329 player->switch_y = y;
10331 PlayLevelSoundElementAction(x, y, element, ACTION_ACTIVATING);
10333 if (element == EL_ROBOT_WHEEL)
10335 Feld[x][y] = EL_ROBOT_WHEEL_ACTIVE;
10339 DrawLevelField(x, y);
10341 else if (element == EL_SP_TERMINAL)
10345 for (yy = 0; yy < lev_fieldy; yy++) for (xx=0; xx < lev_fieldx; xx++)
10347 if (Feld[xx][yy] == EL_SP_DISK_YELLOW)
10349 else if (Feld[xx][yy] == EL_SP_TERMINAL)
10350 Feld[xx][yy] = EL_SP_TERMINAL_ACTIVE;
10353 else if (IS_BELT_SWITCH(element))
10355 ToggleBeltSwitch(x, y);
10357 else if (element == EL_SWITCHGATE_SWITCH_UP ||
10358 element == EL_SWITCHGATE_SWITCH_DOWN)
10360 ToggleSwitchgateSwitch(x, y);
10362 else if (element == EL_LIGHT_SWITCH ||
10363 element == EL_LIGHT_SWITCH_ACTIVE)
10365 ToggleLightSwitch(x, y);
10367 else if (element == EL_TIMEGATE_SWITCH)
10369 ActivateTimegateSwitch(x, y);
10371 else if (element == EL_BALLOON_SWITCH_LEFT ||
10372 element == EL_BALLOON_SWITCH_RIGHT ||
10373 element == EL_BALLOON_SWITCH_UP ||
10374 element == EL_BALLOON_SWITCH_DOWN ||
10375 element == EL_BALLOON_SWITCH_NONE ||
10376 element == EL_BALLOON_SWITCH_ANY)
10378 game.wind_direction = (element == EL_BALLOON_SWITCH_LEFT ? MV_LEFT :
10379 element == EL_BALLOON_SWITCH_RIGHT ? MV_RIGHT :
10380 element == EL_BALLOON_SWITCH_UP ? MV_UP :
10381 element == EL_BALLOON_SWITCH_DOWN ? MV_DOWN :
10382 element == EL_BALLOON_SWITCH_NONE ? MV_NONE :
10385 else if (element == EL_LAMP)
10387 Feld[x][y] = EL_LAMP_ACTIVE;
10388 local_player->lights_still_needed--;
10390 ResetGfxAnimation(x, y);
10391 DrawLevelField(x, y);
10393 else if (element == EL_TIME_ORB_FULL)
10395 Feld[x][y] = EL_TIME_ORB_EMPTY;
10397 if (level.time > 0 || level.use_time_orb_bug)
10399 TimeLeft += level.time_orb_time;
10400 DrawGameValue_Time(TimeLeft);
10403 ResetGfxAnimation(x, y);
10404 DrawLevelField(x, y);
10407 CheckTriggeredElementChangeByPlayer(x, y, element, CE_SWITCH_OF_X,
10408 player->index_bit, dig_side);
10410 CheckTriggeredElementChangeByPlayer(x, y, element, CE_PLAYER_SWITCHES_X,
10411 player->index_bit, dig_side);
10413 CheckTriggeredElementChangeByPlayer(x, y, element, CE_PLAYER_PRESSES_X,
10414 player->index_bit, dig_side);
10420 if (!PLAYER_SWITCHING(player, x, y))
10422 player->is_switching = TRUE;
10423 player->switch_x = x;
10424 player->switch_y = y;
10426 CheckElementChangeByPlayer(x, y, element, CE_SWITCHED,
10427 player->index_bit, dig_side);
10428 CheckTriggeredElementChangeByPlayer(x, y, element, CE_SWITCH_OF_X,
10429 player->index_bit, dig_side);
10431 CheckElementChangeByPlayer(x, y, element, CE_SWITCHED_BY_PLAYER,
10432 player->index_bit, dig_side);
10433 CheckTriggeredElementChangeByPlayer(x, y, element, CE_PLAYER_SWITCHES_X,
10434 player->index_bit, dig_side);
10437 CheckElementChangeByPlayer(x, y, element, CE_PRESSED_BY_PLAYER,
10438 player->index_bit, dig_side);
10439 CheckTriggeredElementChangeByPlayer(x, y, element, CE_PLAYER_PRESSES_X,
10440 player->index_bit, dig_side);
10442 return MF_NO_ACTION;
10445 player->push_delay = -1;
10447 if (is_player) /* function can also be called by EL_PENGUIN */
10449 if (Feld[x][y] != element) /* really digged/collected something */
10450 player->is_collecting = !player->is_digging;
10456 boolean SnapField(struct PlayerInfo *player, int dx, int dy)
10458 int jx = player->jx, jy = player->jy;
10459 int x = jx + dx, y = jy + dy;
10460 int snap_direction = (dx == -1 ? MV_LEFT :
10461 dx == +1 ? MV_RIGHT :
10463 dy == +1 ? MV_DOWN : MV_NONE);
10465 if (player->MovPos != 0 && game.engine_version >= VERSION_IDENT(2,2,0,0))
10468 if (!player->active || !IN_LEV_FIELD(x, y))
10476 if (player->MovPos == 0)
10477 player->is_pushing = FALSE;
10479 player->is_snapping = FALSE;
10481 if (player->MovPos == 0)
10483 player->is_moving = FALSE;
10484 player->is_digging = FALSE;
10485 player->is_collecting = FALSE;
10491 if (player->is_snapping)
10494 player->MovDir = snap_direction;
10496 if (player->MovPos == 0)
10498 player->is_moving = FALSE;
10499 player->is_digging = FALSE;
10500 player->is_collecting = FALSE;
10503 player->is_dropping = FALSE;
10505 if (DigField(player, jx, jy, x, y, 0, 0, DF_SNAP) == MF_NO_ACTION)
10508 player->is_snapping = TRUE;
10510 if (player->MovPos == 0)
10512 player->is_moving = FALSE;
10513 player->is_digging = FALSE;
10514 player->is_collecting = FALSE;
10517 if (player->MovPos != 0) /* prevent graphic bugs in versions < 2.2.0 */
10518 DrawLevelField(player->last_jx, player->last_jy);
10520 DrawLevelField(x, y);
10525 boolean DropElement(struct PlayerInfo *player)
10527 int old_element, new_element;
10528 int dropx = player->jx, dropy = player->jy;
10529 int drop_direction = player->MovDir;
10530 int drop_side = drop_direction;
10531 int drop_element = (player->inventory_size > 0 ?
10532 player->inventory_element[player->inventory_size - 1] :
10533 player->inventory_infinite_element != EL_UNDEFINED ?
10534 player->inventory_infinite_element :
10535 player->dynabombs_left > 0 ?
10536 EL_DYNABOMB_PLAYER_1_ACTIVE + player->index_nr :
10539 /* do not drop an element on top of another element; when holding drop key
10540 pressed without moving, dropped element must move away before the next
10541 element can be dropped (this is especially important if the next element
10542 is dynamite, which can be placed on background for historical reasons) */
10543 if (PLAYER_DROPPING(player, dropx, dropy) && Feld[dropx][dropy] != EL_EMPTY)
10546 if (IS_THROWABLE(drop_element))
10548 dropx += GET_DX_FROM_DIR(drop_direction);
10549 dropy += GET_DY_FROM_DIR(drop_direction);
10551 if (!IN_LEV_FIELD(dropx, dropy))
10555 old_element = Feld[dropx][dropy]; /* old element at dropping position */
10556 new_element = drop_element; /* default: no change when dropping */
10558 /* check if player is active, not moving and ready to drop */
10559 if (!player->active || player->MovPos || player->drop_delay > 0)
10562 /* check if player has anything that can be dropped */
10563 if (new_element == EL_UNDEFINED)
10566 /* check if anything can be dropped at the current position */
10567 if (IS_ACTIVE_BOMB(old_element) || old_element == EL_EXPLOSION)
10570 /* collected custom elements can only be dropped on empty fields */
10571 if (IS_CUSTOM_ELEMENT(new_element) && old_element != EL_EMPTY)
10574 if (old_element != EL_EMPTY)
10575 Back[dropx][dropy] = old_element; /* store old element on this field */
10577 ResetGfxAnimation(dropx, dropy);
10578 ResetRandomAnimationValue(dropx, dropy);
10580 if (player->inventory_size > 0 ||
10581 player->inventory_infinite_element != EL_UNDEFINED)
10583 if (player->inventory_size > 0)
10585 player->inventory_size--;
10587 DrawGameValue_Dynamite(local_player->inventory_size);
10589 if (new_element == EL_DYNAMITE)
10590 new_element = EL_DYNAMITE_ACTIVE;
10591 else if (new_element == EL_SP_DISK_RED)
10592 new_element = EL_SP_DISK_RED_ACTIVE;
10595 Feld[dropx][dropy] = new_element;
10597 if (IN_SCR_FIELD(SCREENX(dropx), SCREENY(dropy)))
10598 DrawGraphicThruMask(SCREENX(dropx), SCREENY(dropy),
10599 el2img(Feld[dropx][dropy]), 0);
10601 PlayLevelSoundAction(dropx, dropy, ACTION_DROPPING);
10603 /* needed if previous element just changed to "empty" in the last frame */
10604 Changed[dropx][dropy] = 0; /* allow at least one more change */
10606 CheckElementChangeByPlayer(dropx, dropy, new_element, CE_DROPPED_BY_PLAYER,
10607 player->index_bit, drop_side);
10608 CheckTriggeredElementChangeByPlayer(dropx, dropy, new_element,
10610 player->index_bit, drop_side);
10612 TestIfElementTouchesCustomElement(dropx, dropy);
10614 else /* player is dropping a dyna bomb */
10616 player->dynabombs_left--;
10618 Feld[dropx][dropy] = new_element;
10620 if (IN_SCR_FIELD(SCREENX(dropx), SCREENY(dropy)))
10621 DrawGraphicThruMask(SCREENX(dropx), SCREENY(dropy),
10622 el2img(Feld[dropx][dropy]), 0);
10624 PlayLevelSoundAction(dropx, dropy, ACTION_DROPPING);
10627 if (Feld[dropx][dropy] == new_element) /* uninitialized unless CE change */
10628 InitField_WithBug1(dropx, dropy, FALSE);
10630 new_element = Feld[dropx][dropy]; /* element might have changed */
10632 if (IS_CUSTOM_ELEMENT(new_element) && CAN_MOVE(new_element) &&
10633 element_info[new_element].move_pattern == MV_WHEN_DROPPED)
10635 int move_direction, nextx, nexty;
10637 if (element_info[new_element].move_direction_initial == MV_START_AUTOMATIC)
10638 MovDir[dropx][dropy] = drop_direction;
10640 move_direction = MovDir[dropx][dropy];
10641 nextx = dropx + GET_DX_FROM_DIR(move_direction);
10642 nexty = dropy + GET_DY_FROM_DIR(move_direction);
10644 Changed[dropx][dropy] = 0; /* allow at least one more change */
10645 CheckCollision[dropx][dropy] = 2;
10648 player->drop_delay = GET_NEW_DROP_DELAY(drop_element);
10649 player->is_dropping = TRUE;
10651 player->drop_x = dropx;
10652 player->drop_y = dropy;
10657 /* ------------------------------------------------------------------------- */
10658 /* game sound playing functions */
10659 /* ------------------------------------------------------------------------- */
10661 static int *loop_sound_frame = NULL;
10662 static int *loop_sound_volume = NULL;
10664 void InitPlayLevelSound()
10666 int num_sounds = getSoundListSize();
10668 checked_free(loop_sound_frame);
10669 checked_free(loop_sound_volume);
10671 loop_sound_frame = checked_calloc(num_sounds * sizeof(int));
10672 loop_sound_volume = checked_calloc(num_sounds * sizeof(int));
10675 static void PlayLevelSound(int x, int y, int nr)
10677 int sx = SCREENX(x), sy = SCREENY(y);
10678 int volume, stereo_position;
10679 int max_distance = 8;
10680 int type = (IS_LOOP_SOUND(nr) ? SND_CTRL_PLAY_LOOP : SND_CTRL_PLAY_SOUND);
10682 if ((!setup.sound_simple && !IS_LOOP_SOUND(nr)) ||
10683 (!setup.sound_loops && IS_LOOP_SOUND(nr)))
10686 if (!IN_LEV_FIELD(x, y) ||
10687 sx < -max_distance || sx >= SCR_FIELDX + max_distance ||
10688 sy < -max_distance || sy >= SCR_FIELDY + max_distance)
10691 volume = SOUND_MAX_VOLUME;
10693 if (!IN_SCR_FIELD(sx, sy))
10695 int dx = ABS(sx - SCR_FIELDX / 2) - SCR_FIELDX / 2;
10696 int dy = ABS(sy - SCR_FIELDY / 2) - SCR_FIELDY / 2;
10698 volume -= volume * (dx > dy ? dx : dy) / max_distance;
10701 stereo_position = (SOUND_MAX_LEFT +
10702 (sx + max_distance) * SOUND_MAX_LEFT2RIGHT /
10703 (SCR_FIELDX + 2 * max_distance));
10705 if (IS_LOOP_SOUND(nr))
10707 /* This assures that quieter loop sounds do not overwrite louder ones,
10708 while restarting sound volume comparison with each new game frame. */
10710 if (loop_sound_volume[nr] > volume && loop_sound_frame[nr] == FrameCounter)
10713 loop_sound_volume[nr] = volume;
10714 loop_sound_frame[nr] = FrameCounter;
10717 PlaySoundExt(nr, volume, stereo_position, type);
10720 static void PlayLevelSoundNearest(int x, int y, int sound_action)
10722 PlayLevelSound(x < LEVELX(BX1) ? LEVELX(BX1) :
10723 x > LEVELX(BX2) ? LEVELX(BX2) : x,
10724 y < LEVELY(BY1) ? LEVELY(BY1) :
10725 y > LEVELY(BY2) ? LEVELY(BY2) : y,
10729 static void PlayLevelSoundAction(int x, int y, int action)
10731 PlayLevelSoundElementAction(x, y, Feld[x][y], action);
10734 static void PlayLevelSoundElementAction(int x, int y, int element, int action)
10736 int sound_effect = element_info[SND_ELEMENT(element)].sound[action];
10738 if (sound_effect != SND_UNDEFINED)
10739 PlayLevelSound(x, y, sound_effect);
10742 static void PlayLevelSoundElementActionIfLoop(int x, int y, int element,
10745 int sound_effect = element_info[SND_ELEMENT(element)].sound[action];
10747 if (sound_effect != SND_UNDEFINED && IS_LOOP_SOUND(sound_effect))
10748 PlayLevelSound(x, y, sound_effect);
10751 static void PlayLevelSoundActionIfLoop(int x, int y, int action)
10753 int sound_effect = element_info[SND_ELEMENT(Feld[x][y])].sound[action];
10755 if (sound_effect != SND_UNDEFINED && IS_LOOP_SOUND(sound_effect))
10756 PlayLevelSound(x, y, sound_effect);
10759 static void StopLevelSoundActionIfLoop(int x, int y, int action)
10761 int sound_effect = element_info[SND_ELEMENT(Feld[x][y])].sound[action];
10763 if (sound_effect != SND_UNDEFINED && IS_LOOP_SOUND(sound_effect))
10764 StopSound(sound_effect);
10767 static void PlayLevelMusic()
10769 if (levelset.music[level_nr] != MUS_UNDEFINED)
10770 PlayMusic(levelset.music[level_nr]); /* from config file */
10772 PlayMusic(MAP_NOCONF_MUSIC(level_nr)); /* from music dir */
10775 void PlayLevelSound_EM(int x, int y, int element_em, int sample)
10777 int element = (element_em > -1 ? map_element_EM_to_RND(element_em) : 0);
10782 PlayLevelSoundElementAction(x, y, element, ACTION_WALKING);
10786 PlayLevelSoundElementAction(x, y, element, ACTION_PUSHING);
10790 PlayLevelSoundElementAction(x, y, element, ACTION_IMPACT);
10794 PlayLevelSoundElementAction(x, y, element, ACTION_IMPACT);
10798 PlayLevelSoundElementAction(x, y, element, ACTION_BREAKING);
10802 PlayLevelSoundElementAction(x, y, element, ACTION_MOVING);
10806 PlayLevelSoundElementAction(x, y, element, ACTION_MOVING);
10809 case SAMPLE_android_clone:
10810 PlayLevelSoundElementAction(x, y, element, ACTION_DROPPING);
10813 case SAMPLE_android_move:
10814 PlayLevelSoundElementAction(x, y, element, ACTION_MOVING);
10817 case SAMPLE_spring:
10818 PlayLevelSoundElementAction(x, y, element, ACTION_IMPACT);
10822 PlayLevelSoundElementAction(x, y, element, ACTION_SLURPED_BY_SPRING);
10826 PlayLevelSoundElementAction(x, y, element, ACTION_WAITING);
10829 case SAMPLE_eater_eat:
10830 PlayLevelSoundElementAction(x, y, element, ACTION_DIGGING);
10834 PlayLevelSoundElementAction(x, y, element, ACTION_MOVING);
10837 case SAMPLE_collect:
10838 PlayLevelSoundElementAction(x, y, element, ACTION_COLLECTING);
10841 case SAMPLE_diamond:
10842 PlayLevelSoundElementAction(x, y, element, ACTION_IMPACT);
10845 case SAMPLE_squash:
10846 /* !!! CHECK THIS !!! */
10848 PlayLevelSoundElementAction(x, y, element, ACTION_BREAKING);
10850 PlayLevelSoundElementAction(x, y, element, ACTION_SMASHED_BY_ROCK);
10854 case SAMPLE_wonderfall:
10855 PlayLevelSoundElementAction(x, y, element, ACTION_FILLING);
10859 PlayLevelSoundElementAction(x, y, element, ACTION_IMPACT);
10863 PlayLevelSoundElementAction(x, y, element, ACTION_PUSHING);
10867 PlayLevelSoundElementAction(x, y, element, ACTION_DIGGING);
10871 PlayLevelSoundElementAction(x, y, element, ACTION_SPLASHING);
10875 PlayLevelSoundElementAction(x, y, element, ACTION_DROPPING);
10879 PlayLevelSoundElementAction(x, y, element, ACTION_GROWING);
10882 case SAMPLE_wonder:
10883 PlayLevelSoundElementAction(x, y, element, ACTION_ACTIVE);
10887 PlayLevelSoundElementAction(x, y, element, ACTION_PASSING);
10890 case SAMPLE_exit_open:
10891 PlayLevelSoundElementAction(x, y, element, ACTION_OPENING);
10894 case SAMPLE_exit_leave:
10895 PlayLevelSoundElementAction(x, y, element, ACTION_PASSING);
10898 case SAMPLE_dynamite:
10899 PlayLevelSoundElementAction(x, y, element, ACTION_DROPPING);
10903 PlayLevelSoundElementAction(x, y, element, ACTION_ACTIVE);
10907 PlayLevelSoundElementAction(x, y, element, ACTION_ACTIVATING);
10911 PlayLevelSoundElementAction(x, y, element, ACTION_ACTIVE);
10915 PlayLevelSoundElementAction(x, y, element, ACTION_EXPLODING);
10919 PlayLevelSoundElementAction(x, y, element, ACTION_DYING);
10923 PlaySoundStereo(SND_GAME_RUNNING_OUT_OF_TIME, SOUND_MIDDLE);
10927 PlayLevelSoundElementAction(x, y, element, ACTION_DEFAULT);
10932 void RaiseScore(int value)
10934 local_player->score += value;
10936 DrawGameValue_Score(local_player->score);
10939 void RaiseScoreElement(int element)
10944 case EL_BD_DIAMOND:
10945 case EL_EMERALD_YELLOW:
10946 case EL_EMERALD_RED:
10947 case EL_EMERALD_PURPLE:
10948 case EL_SP_INFOTRON:
10949 RaiseScore(level.score[SC_EMERALD]);
10952 RaiseScore(level.score[SC_DIAMOND]);
10955 RaiseScore(level.score[SC_CRYSTAL]);
10958 RaiseScore(level.score[SC_PEARL]);
10961 case EL_BD_BUTTERFLY:
10962 case EL_SP_ELECTRON:
10963 RaiseScore(level.score[SC_BUG]);
10966 case EL_BD_FIREFLY:
10967 case EL_SP_SNIKSNAK:
10968 RaiseScore(level.score[SC_SPACESHIP]);
10971 case EL_DARK_YAMYAM:
10972 RaiseScore(level.score[SC_YAMYAM]);
10975 RaiseScore(level.score[SC_ROBOT]);
10978 RaiseScore(level.score[SC_PACMAN]);
10981 RaiseScore(level.score[SC_NUT]);
10984 case EL_SP_DISK_RED:
10985 case EL_DYNABOMB_INCREASE_NUMBER:
10986 case EL_DYNABOMB_INCREASE_SIZE:
10987 case EL_DYNABOMB_INCREASE_POWER:
10988 RaiseScore(level.score[SC_DYNAMITE]);
10990 case EL_SHIELD_NORMAL:
10991 case EL_SHIELD_DEADLY:
10992 RaiseScore(level.score[SC_SHIELD]);
10994 case EL_EXTRA_TIME:
10995 RaiseScore(level.extra_time_score);
11009 RaiseScore(level.score[SC_KEY]);
11012 RaiseScore(element_info[element].collect_score);
11017 void RequestQuitGame(boolean ask_if_really_quit)
11019 if (AllPlayersGone ||
11020 !ask_if_really_quit ||
11021 level_editor_test_game ||
11022 Request("Do you really want to quit the game ?",
11023 REQ_ASK | REQ_STAY_CLOSED))
11025 #if defined(NETWORK_AVALIABLE)
11026 if (options.network)
11027 SendToServer_StopPlaying();
11031 game_status = GAME_MODE_MAIN;
11037 if (tape.playing && tape.deactivate_display)
11038 TapeDeactivateDisplayOff(TRUE);
11040 OpenDoor(DOOR_OPEN_1 | DOOR_COPY_BACK);
11042 if (tape.playing && tape.deactivate_display)
11043 TapeDeactivateDisplayOn();
11048 /* ---------- new game button stuff ---------------------------------------- */
11050 /* graphic position values for game buttons */
11051 #define GAME_BUTTON_XSIZE 30
11052 #define GAME_BUTTON_YSIZE 30
11053 #define GAME_BUTTON_XPOS 5
11054 #define GAME_BUTTON_YPOS 215
11055 #define SOUND_BUTTON_XPOS 5
11056 #define SOUND_BUTTON_YPOS (GAME_BUTTON_YPOS + GAME_BUTTON_YSIZE)
11058 #define GAME_BUTTON_STOP_XPOS (GAME_BUTTON_XPOS + 0 * GAME_BUTTON_XSIZE)
11059 #define GAME_BUTTON_PAUSE_XPOS (GAME_BUTTON_XPOS + 1 * GAME_BUTTON_XSIZE)
11060 #define GAME_BUTTON_PLAY_XPOS (GAME_BUTTON_XPOS + 2 * GAME_BUTTON_XSIZE)
11061 #define SOUND_BUTTON_MUSIC_XPOS (SOUND_BUTTON_XPOS + 0 * GAME_BUTTON_XSIZE)
11062 #define SOUND_BUTTON_LOOPS_XPOS (SOUND_BUTTON_XPOS + 1 * GAME_BUTTON_XSIZE)
11063 #define SOUND_BUTTON_SIMPLE_XPOS (SOUND_BUTTON_XPOS + 2 * GAME_BUTTON_XSIZE)
11070 } gamebutton_info[NUM_GAME_BUTTONS] =
11073 GAME_BUTTON_STOP_XPOS, GAME_BUTTON_YPOS,
11078 GAME_BUTTON_PAUSE_XPOS, GAME_BUTTON_YPOS,
11079 GAME_CTRL_ID_PAUSE,
11083 GAME_BUTTON_PLAY_XPOS, GAME_BUTTON_YPOS,
11088 SOUND_BUTTON_MUSIC_XPOS, SOUND_BUTTON_YPOS,
11089 SOUND_CTRL_ID_MUSIC,
11090 "background music on/off"
11093 SOUND_BUTTON_LOOPS_XPOS, SOUND_BUTTON_YPOS,
11094 SOUND_CTRL_ID_LOOPS,
11095 "sound loops on/off"
11098 SOUND_BUTTON_SIMPLE_XPOS, SOUND_BUTTON_YPOS,
11099 SOUND_CTRL_ID_SIMPLE,
11100 "normal sounds on/off"
11104 void CreateGameButtons()
11108 for (i = 0; i < NUM_GAME_BUTTONS; i++)
11110 Bitmap *gd_bitmap = graphic_info[IMG_GLOBAL_DOOR].bitmap;
11111 struct GadgetInfo *gi;
11114 unsigned long event_mask;
11115 int gd_xoffset, gd_yoffset;
11116 int gd_x1, gd_x2, gd_y1, gd_y2;
11119 gd_xoffset = gamebutton_info[i].x;
11120 gd_yoffset = gamebutton_info[i].y;
11121 gd_x1 = DOOR_GFX_PAGEX4 + gd_xoffset;
11122 gd_x2 = DOOR_GFX_PAGEX3 + gd_xoffset;
11124 if (id == GAME_CTRL_ID_STOP ||
11125 id == GAME_CTRL_ID_PAUSE ||
11126 id == GAME_CTRL_ID_PLAY)
11128 button_type = GD_TYPE_NORMAL_BUTTON;
11130 event_mask = GD_EVENT_RELEASED;
11131 gd_y1 = DOOR_GFX_PAGEY1 + gd_yoffset - GAME_BUTTON_YSIZE;
11132 gd_y2 = DOOR_GFX_PAGEY1 + gd_yoffset - GAME_BUTTON_YSIZE;
11136 button_type = GD_TYPE_CHECK_BUTTON;
11138 ((id == SOUND_CTRL_ID_MUSIC && setup.sound_music) ||
11139 (id == SOUND_CTRL_ID_LOOPS && setup.sound_loops) ||
11140 (id == SOUND_CTRL_ID_SIMPLE && setup.sound_simple) ? TRUE : FALSE);
11141 event_mask = GD_EVENT_PRESSED;
11142 gd_y1 = DOOR_GFX_PAGEY1 + gd_yoffset;
11143 gd_y2 = DOOR_GFX_PAGEY1 + gd_yoffset - GAME_BUTTON_YSIZE;
11146 gi = CreateGadget(GDI_CUSTOM_ID, id,
11147 GDI_INFO_TEXT, gamebutton_info[i].infotext,
11148 GDI_X, DX + gd_xoffset,
11149 GDI_Y, DY + gd_yoffset,
11150 GDI_WIDTH, GAME_BUTTON_XSIZE,
11151 GDI_HEIGHT, GAME_BUTTON_YSIZE,
11152 GDI_TYPE, button_type,
11153 GDI_STATE, GD_BUTTON_UNPRESSED,
11154 GDI_CHECKED, checked,
11155 GDI_DESIGN_UNPRESSED, gd_bitmap, gd_x1, gd_y1,
11156 GDI_DESIGN_PRESSED, gd_bitmap, gd_x2, gd_y1,
11157 GDI_ALT_DESIGN_UNPRESSED, gd_bitmap, gd_x1, gd_y2,
11158 GDI_ALT_DESIGN_PRESSED, gd_bitmap, gd_x2, gd_y2,
11159 GDI_EVENT_MASK, event_mask,
11160 GDI_CALLBACK_ACTION, HandleGameButtons,
11164 Error(ERR_EXIT, "cannot create gadget");
11166 game_gadget[id] = gi;
11170 void FreeGameButtons()
11174 for (i = 0; i < NUM_GAME_BUTTONS; i++)
11175 FreeGadget(game_gadget[i]);
11178 static void MapGameButtons()
11182 for (i = 0; i < NUM_GAME_BUTTONS; i++)
11183 MapGadget(game_gadget[i]);
11186 void UnmapGameButtons()
11190 for (i = 0; i < NUM_GAME_BUTTONS; i++)
11191 UnmapGadget(game_gadget[i]);
11194 static void HandleGameButtons(struct GadgetInfo *gi)
11196 int id = gi->custom_id;
11198 if (game_status != GAME_MODE_PLAYING)
11203 case GAME_CTRL_ID_STOP:
11204 RequestQuitGame(TRUE);
11207 case GAME_CTRL_ID_PAUSE:
11208 if (options.network)
11210 #if defined(NETWORK_AVALIABLE)
11212 SendToServer_ContinuePlaying();
11214 SendToServer_PausePlaying();
11218 TapeTogglePause(TAPE_TOGGLE_MANUAL);
11221 case GAME_CTRL_ID_PLAY:
11224 #if defined(NETWORK_AVALIABLE)
11225 if (options.network)
11226 SendToServer_ContinuePlaying();
11230 tape.pausing = FALSE;
11231 DrawVideoDisplay(VIDEO_STATE_PAUSE_OFF,0);
11236 case SOUND_CTRL_ID_MUSIC:
11237 if (setup.sound_music)
11239 setup.sound_music = FALSE;
11242 else if (audio.music_available)
11244 setup.sound = setup.sound_music = TRUE;
11246 SetAudioMode(setup.sound);
11252 case SOUND_CTRL_ID_LOOPS:
11253 if (setup.sound_loops)
11254 setup.sound_loops = FALSE;
11255 else if (audio.loops_available)
11257 setup.sound = setup.sound_loops = TRUE;
11258 SetAudioMode(setup.sound);
11262 case SOUND_CTRL_ID_SIMPLE:
11263 if (setup.sound_simple)
11264 setup.sound_simple = FALSE;
11265 else if (audio.sound_available)
11267 setup.sound = setup.sound_simple = TRUE;
11268 SetAudioMode(setup.sound);