1 /***********************************************************
2 * Rocks'n'Diamonds -- McDuffin Strikes Back! *
3 *----------------------------------------------------------*
4 * (c) 1995-2006 Artsoft Entertainment *
6 * Detmolder Strasse 189 *
9 * e-mail: info@artsoft.org *
10 *----------------------------------------------------------*
12 ***********************************************************/
14 #include "libgame/libgame.h"
24 /* EXPERIMENTAL STUFF */
25 #define USE_NEW_AMOEBA_CODE FALSE
27 /* EXPERIMENTAL STUFF */
28 #define USE_NEW_STUFF ( 1)
30 #define USE_NEW_SP_SLIPPERY (USE_NEW_STUFF * 1)
31 #define USE_NEW_CUSTOM_VALUE (USE_NEW_STUFF * 1)
32 #define USE_NEW_PLAYER_ANIM (USE_NEW_STUFF * 1)
33 #define USE_NEW_ALL_SLIPPERY (USE_NEW_STUFF * 1)
34 #define USE_NEW_PLAYER_SPEED (USE_NEW_STUFF * 1)
35 #define USE_NEW_DELAYED_ACTION (USE_NEW_STUFF * 1)
36 #define USE_NEW_SNAP_DELAY (USE_NEW_STUFF * 1)
37 #define USE_ONLY_ONE_CHANGE_PER_FRAME (USE_NEW_STUFF * 1)
38 #define USE_ONE_MORE_CHANGE_PER_FRAME (USE_NEW_STUFF * 1)
39 #define USE_FIXED_DONT_RUN_INTO (USE_NEW_STUFF * 1)
40 #define USE_NEW_SPRING_BUMPER (USE_NEW_STUFF * 1)
41 #define USE_STOP_CHANGED_ELEMENTS (USE_NEW_STUFF * 1)
42 #define USE_ELEMENT_TOUCHING_BUGFIX (USE_NEW_STUFF * 1)
43 #define USE_NEW_CONTINUOUS_SNAPPING (USE_NEW_STUFF * 1)
44 #define USE_GFX_RESET_GFX_ANIMATION (USE_NEW_STUFF * 1)
45 #define USE_BOTH_SWITCHGATE_SWITCHES (USE_NEW_STUFF * 1)
46 #define USE_PLAYER_GRAVITY (USE_NEW_STUFF * 1)
47 #define USE_FIXED_BORDER_RUNNING_GFX (USE_NEW_STUFF * 1)
48 #define USE_QUICKSAND_BD_ROCK_BUGFIX (USE_NEW_STUFF * 0)
50 #define USE_QUICKSAND_IMPACT_BUGFIX (USE_NEW_STUFF * 0)
52 #define USE_CODE_THAT_BREAKS_SNAKE_BITE (USE_NEW_STUFF * 1)
54 #define USE_UFAST_PLAYER_EXIT_BUGFIX (USE_NEW_STUFF * 1)
62 /* for MovePlayer() */
63 #define MP_NO_ACTION 0
66 #define MP_DONT_RUN_INTO (MP_MOVING | MP_ACTION)
68 /* for ScrollPlayer() */
70 #define SCROLL_GO_ON 1
72 /* for Bang()/Explode() */
73 #define EX_PHASE_START 0
74 #define EX_TYPE_NONE 0
75 #define EX_TYPE_NORMAL (1 << 0)
76 #define EX_TYPE_CENTER (1 << 1)
77 #define EX_TYPE_BORDER (1 << 2)
78 #define EX_TYPE_CROSS (1 << 3)
79 #define EX_TYPE_DYNA (1 << 4)
80 #define EX_TYPE_SINGLE_TILE (EX_TYPE_CENTER | EX_TYPE_BORDER)
82 #define PANEL_DEACTIVATED(p) ((p).x < 0 || (p).y < 0)
84 /* special positions in the game control window (relative to control window) */
85 #define XX_LEVEL1 (game.panel.level.x)
86 #define XX_LEVEL2 (game.panel.level.x - 1)
87 #define YY_LEVEL (game.panel.level.y)
88 #define XX_EMERALDS (game.panel.gems.x)
89 #define YY_EMERALDS (game.panel.gems.y)
90 #define XX_DYNAMITE (game.panel.inventory.x)
91 #define YY_DYNAMITE (game.panel.inventory.y)
92 #define XX_KEYS (game.panel.keys.x)
93 #define YY_KEYS (game.panel.keys.y)
94 #define XX_SCORE (game.panel.score.x)
95 #define YY_SCORE (game.panel.score.y)
96 #define XX_TIME1 (game.panel.time.x)
97 #define XX_TIME2 (game.panel.time.x + 1)
98 #define YY_TIME (game.panel.time.y)
100 /* special positions in the game control window (relative to main window) */
101 #define DX_LEVEL1 (DX + XX_LEVEL1)
102 #define DX_LEVEL2 (DX + XX_LEVEL2)
103 #define DY_LEVEL (DY + YY_LEVEL)
104 #define DX_EMERALDS (DX + XX_EMERALDS)
105 #define DY_EMERALDS (DY + YY_EMERALDS)
106 #define DX_DYNAMITE (DX + XX_DYNAMITE)
107 #define DY_DYNAMITE (DY + YY_DYNAMITE)
108 #define DX_KEYS (DX + XX_KEYS)
109 #define DY_KEYS (DY + YY_KEYS)
110 #define DX_SCORE (DX + XX_SCORE)
111 #define DY_SCORE (DY + YY_SCORE)
112 #define DX_TIME1 (DX + XX_TIME1)
113 #define DX_TIME2 (DX + XX_TIME2)
114 #define DY_TIME (DY + YY_TIME)
116 /* values for delayed check of falling and moving elements and for collision */
117 #define CHECK_DELAY_MOVING 3
118 #define CHECK_DELAY_FALLING 3
119 #define CHECK_DELAY_COLLISION 2
121 /* values for initial player move delay (initial delay counter value) */
122 #define INITIAL_MOVE_DELAY_OFF -1
123 #define INITIAL_MOVE_DELAY_ON 0
125 /* values for player movement speed (which is in fact a delay value) */
126 #define MOVE_DELAY_MIN_SPEED 32
127 #define MOVE_DELAY_NORMAL_SPEED 8
128 #define MOVE_DELAY_HIGH_SPEED 4
129 #define MOVE_DELAY_MAX_SPEED 1
131 #define DOUBLE_MOVE_DELAY(x) (x = (x < MOVE_DELAY_MIN_SPEED ? x * 2 : x))
132 #define HALVE_MOVE_DELAY(x) (x = (x > MOVE_DELAY_MAX_SPEED ? x / 2 : x))
134 #define DOUBLE_PLAYER_SPEED(p) (HALVE_MOVE_DELAY( (p)->move_delay_value))
135 #define HALVE_PLAYER_SPEED(p) (DOUBLE_MOVE_DELAY((p)->move_delay_value))
137 /* values for other actions */
138 #define MOVE_STEPSIZE_NORMAL (TILEX / MOVE_DELAY_NORMAL_SPEED)
139 #define MOVE_STEPSIZE_MIN (1)
140 #define MOVE_STEPSIZE_MAX (TILEX)
142 #define GET_DX_FROM_DIR(d) ((d) == MV_LEFT ? -1 : (d) == MV_RIGHT ? 1 : 0)
143 #define GET_DY_FROM_DIR(d) ((d) == MV_UP ? -1 : (d) == MV_DOWN ? 1 : 0)
145 #define INIT_GFX_RANDOM() (GetSimpleRandom(1000000))
147 #define GET_NEW_PUSH_DELAY(e) ( (element_info[e].push_delay_fixed) + \
148 RND(element_info[e].push_delay_random))
149 #define GET_NEW_DROP_DELAY(e) ( (element_info[e].drop_delay_fixed) + \
150 RND(element_info[e].drop_delay_random))
151 #define GET_NEW_MOVE_DELAY(e) ( (element_info[e].move_delay_fixed) + \
152 RND(element_info[e].move_delay_random))
153 #define GET_MAX_MOVE_DELAY(e) ( (element_info[e].move_delay_fixed) + \
154 (element_info[e].move_delay_random))
155 #define GET_NEW_CE_VALUE(e) ( (element_info[e].ce_value_fixed_initial) +\
156 RND(element_info[e].ce_value_random_initial))
157 #define GET_CE_SCORE(e) ( (element_info[e].collect_score))
158 #define GET_CHANGE_DELAY(c) ( ((c)->delay_fixed * (c)->delay_frames) + \
159 RND((c)->delay_random * (c)->delay_frames))
160 #define GET_CE_DELAY_VALUE(c) ( ((c)->delay_fixed) + \
161 RND((c)->delay_random))
164 #define GET_VALID_RUNTIME_ELEMENT(e) \
165 ((e) >= NUM_RUNTIME_ELEMENTS ? EL_UNKNOWN : (e))
167 #define RESOLVED_REFERENCE_ELEMENT(be, e) \
168 ((be) + (e) - EL_SELF < EL_CUSTOM_START ? EL_CUSTOM_START : \
169 (be) + (e) - EL_SELF > EL_CUSTOM_END ? EL_CUSTOM_END : \
170 (be) + (e) - EL_SELF)
172 #define GET_TARGET_ELEMENT(be, e, ch, cv, cs) \
173 ((e) == EL_TRIGGER_PLAYER ? (ch)->actual_trigger_player : \
174 (e) == EL_TRIGGER_ELEMENT ? (ch)->actual_trigger_element : \
175 (e) == EL_TRIGGER_CE_VALUE ? (ch)->actual_trigger_ce_value : \
176 (e) == EL_TRIGGER_CE_SCORE ? (ch)->actual_trigger_ce_score : \
177 (e) == EL_CURRENT_CE_VALUE ? (cv) : \
178 (e) == EL_CURRENT_CE_SCORE ? (cs) : \
179 (e) >= EL_LAST_CE_8 && (e) <= EL_NEXT_CE_8 ? \
180 RESOLVED_REFERENCE_ELEMENT(be, e) : \
183 #define CAN_GROW_INTO(e) \
184 ((e) == EL_SAND || (IS_DIGGABLE(e) && level.grow_into_diggable))
186 #define ELEMENT_CAN_ENTER_FIELD_BASE_X(x, y, condition) \
187 (IN_LEV_FIELD(x, y) && (IS_FREE(x, y) || \
190 #define ELEMENT_CAN_ENTER_FIELD_BASE_2(e, x, y, condition) \
191 (IN_LEV_FIELD(x, y) && (IS_FREE(x, y) || \
192 (CAN_MOVE_INTO_ACID(e) && \
193 Feld[x][y] == EL_ACID) || \
196 #define ELEMENT_CAN_ENTER_FIELD_BASE_3(e, x, y, condition) \
197 (IN_LEV_FIELD(x, y) && (IS_FREE_OR_PLAYER(x, y) || \
198 (CAN_MOVE_INTO_ACID(e) && \
199 Feld[x][y] == EL_ACID) || \
202 #define ELEMENT_CAN_ENTER_FIELD_BASE_4(e, x, y, condition) \
203 (IN_LEV_FIELD(x, y) && (IS_FREE(x, y) || \
205 (CAN_MOVE_INTO_ACID(e) && \
206 Feld[x][y] == EL_ACID) || \
207 (DONT_COLLIDE_WITH(e) && \
209 !PLAYER_ENEMY_PROTECTED(x, y))))
211 #define ELEMENT_CAN_ENTER_FIELD(e, x, y) \
212 ELEMENT_CAN_ENTER_FIELD_BASE_4(e, x, y, 0)
214 #define SATELLITE_CAN_ENTER_FIELD(x, y) \
215 ELEMENT_CAN_ENTER_FIELD_BASE_2(EL_SATELLITE, x, y, 0)
217 #define ANDROID_CAN_ENTER_FIELD(e, x, y) \
218 ELEMENT_CAN_ENTER_FIELD_BASE_2(e, x, y, Feld[x][y] == EL_EMC_PLANT)
220 #define ANDROID_CAN_CLONE_FIELD(x, y) \
221 (IN_LEV_FIELD(x, y) && (CAN_BE_CLONED_BY_ANDROID(Feld[x][y]) || \
222 CAN_BE_CLONED_BY_ANDROID(EL_TRIGGER_ELEMENT)))
224 #define ENEMY_CAN_ENTER_FIELD(e, x, y) \
225 ELEMENT_CAN_ENTER_FIELD_BASE_2(e, x, y, 0)
227 #define YAMYAM_CAN_ENTER_FIELD(e, x, y) \
228 ELEMENT_CAN_ENTER_FIELD_BASE_3(e, x, y, Feld[x][y] == EL_DIAMOND)
230 #define DARK_YAMYAM_CAN_ENTER_FIELD(e, x, y) \
231 ELEMENT_CAN_ENTER_FIELD_BASE_3(e, x,y, IS_FOOD_DARK_YAMYAM(Feld[x][y]))
233 #define PACMAN_CAN_ENTER_FIELD(e, x, y) \
234 ELEMENT_CAN_ENTER_FIELD_BASE_3(e, x, y, IS_AMOEBOID(Feld[x][y]))
236 #define PIG_CAN_ENTER_FIELD(e, x, y) \
237 ELEMENT_CAN_ENTER_FIELD_BASE_2(e, x, y, IS_FOOD_PIG(Feld[x][y]))
239 #define PENGUIN_CAN_ENTER_FIELD(e, x, y) \
240 ELEMENT_CAN_ENTER_FIELD_BASE_2(e, x, y, (Feld[x][y] == EL_EXIT_OPEN ||\
241 IS_FOOD_PENGUIN(Feld[x][y])))
242 #define DRAGON_CAN_ENTER_FIELD(e, x, y) \
243 ELEMENT_CAN_ENTER_FIELD_BASE_2(e, x, y, 0)
245 #define MOLE_CAN_ENTER_FIELD(e, x, y, condition) \
246 ELEMENT_CAN_ENTER_FIELD_BASE_2(e, x, y, (condition))
248 #define SPRING_CAN_ENTER_FIELD(e, x, y) \
249 ELEMENT_CAN_ENTER_FIELD_BASE_2(e, x, y, 0)
251 #define SPRING_CAN_BUMP_FROM_FIELD(x, y) \
252 (IN_LEV_FIELD(x, y) && (Feld[x][y] == EL_EMC_SPRING_BUMPER || \
253 Feld[x][y] == EL_EMC_SPRING_BUMPER_ACTIVE))
255 #define MOVE_ENTER_EL(e) (element_info[e].move_enter_element)
257 #define CE_ENTER_FIELD_COND(e, x, y) \
258 (!IS_PLAYER(x, y) && \
259 IS_EQUAL_OR_IN_GROUP(Feld[x][y], MOVE_ENTER_EL(e)))
261 #define CUSTOM_ELEMENT_CAN_ENTER_FIELD(e, x, y) \
262 ELEMENT_CAN_ENTER_FIELD_BASE_4(e, x, y, CE_ENTER_FIELD_COND(e, x, y))
264 #define IN_LEV_FIELD_AND_IS_FREE(x, y) (IN_LEV_FIELD(x, y) && IS_FREE(x, y))
265 #define IN_LEV_FIELD_AND_NOT_FREE(x, y) (IN_LEV_FIELD(x, y) && !IS_FREE(x, y))
267 #define ACCESS_FROM(e, d) (element_info[e].access_direction &(d))
268 #define IS_WALKABLE_FROM(e, d) (IS_WALKABLE(e) && ACCESS_FROM(e, d))
269 #define IS_PASSABLE_FROM(e, d) (IS_PASSABLE(e) && ACCESS_FROM(e, d))
270 #define IS_ACCESSIBLE_FROM(e, d) (IS_ACCESSIBLE(e) && ACCESS_FROM(e, d))
272 /* game button identifiers */
273 #define GAME_CTRL_ID_STOP 0
274 #define GAME_CTRL_ID_PAUSE 1
275 #define GAME_CTRL_ID_PLAY 2
276 #define SOUND_CTRL_ID_MUSIC 3
277 #define SOUND_CTRL_ID_LOOPS 4
278 #define SOUND_CTRL_ID_SIMPLE 5
280 #define NUM_GAME_BUTTONS 6
283 /* forward declaration for internal use */
285 static void CreateField(int, int, int);
287 static void SetPlayerWaiting(struct PlayerInfo *, boolean);
288 static void AdvanceFrameAndPlayerCounters(int);
290 static boolean MovePlayerOneStep(struct PlayerInfo *, int, int, int, int);
291 static boolean MovePlayer(struct PlayerInfo *, int, int);
292 static void ScrollPlayer(struct PlayerInfo *, int);
293 static void ScrollScreen(struct PlayerInfo *, int);
295 int DigField(struct PlayerInfo *, int, int, int, int, int, int, int);
297 static void InitBeltMovement(void);
298 static void CloseAllOpenTimegates(void);
299 static void CheckGravityMovement(struct PlayerInfo *);
300 static void CheckGravityMovementWhenNotMoving(struct PlayerInfo *);
301 static void KillPlayerUnlessEnemyProtected(int, int);
302 static void KillPlayerUnlessExplosionProtected(int, int);
304 static void TestIfPlayerTouchesCustomElement(int, int);
305 static void TestIfElementTouchesCustomElement(int, int);
306 static void TestIfElementHitsCustomElement(int, int, int);
308 static void TestIfElementSmashesCustomElement(int, int, int);
311 static void HandleElementChange(int, int, int);
312 static void ExecuteCustomElementAction(int, int, int, int);
313 static boolean ChangeElement(int, int, int, int);
315 static boolean CheckTriggeredElementChangeExt(int, int, int, int, int,int,int);
316 #define CheckTriggeredElementChange(x, y, e, ev) \
317 CheckTriggeredElementChangeExt(x,y,e,ev, CH_PLAYER_ANY,CH_SIDE_ANY, -1)
318 #define CheckTriggeredElementChangeByPlayer(x, y, e, ev, p, s) \
319 CheckTriggeredElementChangeExt(x, y, e, ev, p, s, -1)
320 #define CheckTriggeredElementChangeBySide(x, y, e, ev, s) \
321 CheckTriggeredElementChangeExt(x, y, e, ev, CH_PLAYER_ANY, s, -1)
322 #define CheckTriggeredElementChangeByPage(x, y, e, ev, p) \
323 CheckTriggeredElementChangeExt(x,y,e,ev, CH_PLAYER_ANY, CH_SIDE_ANY, p)
325 static boolean CheckElementChangeExt(int, int, int, int, int, int, int);
326 #define CheckElementChange(x, y, e, te, ev) \
327 CheckElementChangeExt(x, y, e, te, ev, CH_PLAYER_ANY, CH_SIDE_ANY)
328 #define CheckElementChangeByPlayer(x, y, e, ev, p, s) \
329 CheckElementChangeExt(x, y, e, EL_EMPTY, ev, p, s)
330 #define CheckElementChangeBySide(x, y, e, te, ev, s) \
331 CheckElementChangeExt(x, y, e, te, ev, CH_PLAYER_ANY, s)
333 static void PlayLevelSound(int, int, int);
334 static void PlayLevelSoundNearest(int, int, int);
335 static void PlayLevelSoundAction(int, int, int);
336 static void PlayLevelSoundElementAction(int, int, int, int);
337 static void PlayLevelSoundElementActionIfLoop(int, int, int, int);
338 static void PlayLevelSoundActionIfLoop(int, int, int);
339 static void StopLevelSoundActionIfLoop(int, int, int);
340 static void PlayLevelMusic();
342 static void MapGameButtons();
343 static void HandleGameButtons(struct GadgetInfo *);
345 int AmoebeNachbarNr(int, int);
346 void AmoebeUmwandeln(int, int);
347 void ContinueMoving(int, int);
349 void InitMovDir(int, int);
350 void InitAmoebaNr(int, int);
351 int NewHiScore(void);
353 void TestIfGoodThingHitsBadThing(int, int, int);
354 void TestIfBadThingHitsGoodThing(int, int, int);
355 void TestIfPlayerTouchesBadThing(int, int);
356 void TestIfPlayerRunsIntoBadThing(int, int, int);
357 void TestIfBadThingTouchesPlayer(int, int);
358 void TestIfBadThingRunsIntoPlayer(int, int, int);
359 void TestIfFriendTouchesBadThing(int, int);
360 void TestIfBadThingTouchesFriend(int, int);
361 void TestIfBadThingTouchesOtherBadThing(int, int);
363 void KillPlayer(struct PlayerInfo *);
364 void BuryPlayer(struct PlayerInfo *);
365 void RemovePlayer(struct PlayerInfo *);
367 boolean SnapField(struct PlayerInfo *, int, int);
368 boolean DropElement(struct PlayerInfo *);
370 static int getInvisibleActiveFromInvisibleElement(int);
371 static int getInvisibleFromInvisibleActiveElement(int);
373 static struct GadgetInfo *game_gadget[NUM_GAME_BUTTONS];
376 /* ------------------------------------------------------------------------- */
377 /* definition of elements that automatically change to other elements after */
378 /* a specified time, eventually calling a function when changing */
379 /* ------------------------------------------------------------------------- */
381 /* forward declaration for changer functions */
382 static void InitBuggyBase(int, int);
383 static void WarnBuggyBase(int, int);
385 static void InitTrap(int, int);
386 static void ActivateTrap(int, int);
387 static void ChangeActiveTrap(int, int);
389 static void InitRobotWheel(int, int);
390 static void RunRobotWheel(int, int);
391 static void StopRobotWheel(int, int);
393 static void InitTimegateWheel(int, int);
394 static void RunTimegateWheel(int, int);
396 static void InitMagicBallDelay(int, int);
397 static void ActivateMagicBall(int, int);
399 struct ChangingElementInfo
404 void (*pre_change_function)(int x, int y);
405 void (*change_function)(int x, int y);
406 void (*post_change_function)(int x, int y);
409 static struct ChangingElementInfo change_delay_list[] =
460 EL_SWITCHGATE_OPENING,
468 EL_SWITCHGATE_CLOSING,
469 EL_SWITCHGATE_CLOSED,
501 EL_ACID_SPLASH_RIGHT,
510 EL_SP_BUGGY_BASE_ACTIVATING,
517 EL_SP_BUGGY_BASE_ACTIVATING,
518 EL_SP_BUGGY_BASE_ACTIVE,
525 EL_SP_BUGGY_BASE_ACTIVE,
549 EL_ROBOT_WHEEL_ACTIVE,
557 EL_TIMEGATE_SWITCH_ACTIVE,
565 EL_EMC_MAGIC_BALL_ACTIVE,
566 EL_EMC_MAGIC_BALL_ACTIVE,
573 EL_EMC_SPRING_BUMPER_ACTIVE,
574 EL_EMC_SPRING_BUMPER,
581 EL_DIAGONAL_SHRINKING,
610 int push_delay_fixed, push_delay_random;
615 { EL_BALLOON, 0, 0 },
617 { EL_SOKOBAN_OBJECT, 2, 0 },
618 { EL_SOKOBAN_FIELD_FULL, 2, 0 },
619 { EL_SATELLITE, 2, 0 },
620 { EL_SP_DISK_YELLOW, 2, 0 },
622 { EL_UNDEFINED, 0, 0 },
630 move_stepsize_list[] =
632 { EL_AMOEBA_DROP, 2 },
633 { EL_AMOEBA_DROPPING, 2 },
634 { EL_QUICKSAND_FILLING, 1 },
635 { EL_QUICKSAND_EMPTYING, 1 },
636 { EL_MAGIC_WALL_FILLING, 2 },
637 { EL_BD_MAGIC_WALL_FILLING, 2 },
638 { EL_MAGIC_WALL_EMPTYING, 2 },
639 { EL_BD_MAGIC_WALL_EMPTYING, 2 },
649 collect_count_list[] =
652 { EL_BD_DIAMOND, 1 },
653 { EL_EMERALD_YELLOW, 1 },
654 { EL_EMERALD_RED, 1 },
655 { EL_EMERALD_PURPLE, 1 },
657 { EL_SP_INFOTRON, 1 },
669 access_direction_list[] =
671 { EL_TUBE_ANY, MV_LEFT | MV_RIGHT | MV_UP | MV_DOWN },
672 { EL_TUBE_VERTICAL, MV_UP | MV_DOWN },
673 { EL_TUBE_HORIZONTAL, MV_LEFT | MV_RIGHT },
674 { EL_TUBE_VERTICAL_LEFT, MV_LEFT | MV_UP | MV_DOWN },
675 { EL_TUBE_VERTICAL_RIGHT, MV_RIGHT | MV_UP | MV_DOWN },
676 { EL_TUBE_HORIZONTAL_UP, MV_LEFT | MV_RIGHT | MV_UP },
677 { EL_TUBE_HORIZONTAL_DOWN, MV_LEFT | MV_RIGHT | MV_DOWN },
678 { EL_TUBE_LEFT_UP, MV_LEFT | MV_UP },
679 { EL_TUBE_LEFT_DOWN, MV_LEFT | MV_DOWN },
680 { EL_TUBE_RIGHT_UP, MV_RIGHT | MV_UP },
681 { EL_TUBE_RIGHT_DOWN, MV_RIGHT | MV_DOWN },
683 { EL_SP_PORT_LEFT, MV_RIGHT },
684 { EL_SP_PORT_RIGHT, MV_LEFT },
685 { EL_SP_PORT_UP, MV_DOWN },
686 { EL_SP_PORT_DOWN, MV_UP },
687 { EL_SP_PORT_HORIZONTAL, MV_LEFT | MV_RIGHT },
688 { EL_SP_PORT_VERTICAL, MV_UP | MV_DOWN },
689 { EL_SP_PORT_ANY, MV_LEFT | MV_RIGHT | MV_UP | MV_DOWN },
690 { EL_SP_GRAVITY_PORT_LEFT, MV_RIGHT },
691 { EL_SP_GRAVITY_PORT_RIGHT, MV_LEFT },
692 { EL_SP_GRAVITY_PORT_UP, MV_DOWN },
693 { EL_SP_GRAVITY_PORT_DOWN, MV_UP },
694 { EL_SP_GRAVITY_ON_PORT_LEFT, MV_RIGHT },
695 { EL_SP_GRAVITY_ON_PORT_RIGHT, MV_LEFT },
696 { EL_SP_GRAVITY_ON_PORT_UP, MV_DOWN },
697 { EL_SP_GRAVITY_ON_PORT_DOWN, MV_UP },
698 { EL_SP_GRAVITY_OFF_PORT_LEFT, MV_RIGHT },
699 { EL_SP_GRAVITY_OFF_PORT_RIGHT, MV_LEFT },
700 { EL_SP_GRAVITY_OFF_PORT_UP, MV_DOWN },
701 { EL_SP_GRAVITY_OFF_PORT_DOWN, MV_UP },
703 { EL_UNDEFINED, MV_NONE }
706 static boolean trigger_events[MAX_NUM_ELEMENTS][NUM_CHANGE_EVENTS];
708 #define IS_AUTO_CHANGING(e) (element_info[e].has_change_event[CE_DELAY])
709 #define IS_JUST_CHANGING(x, y) (ChangeDelay[x][y] != 0)
710 #define IS_CHANGING(x, y) (IS_AUTO_CHANGING(Feld[x][y]) || \
711 IS_JUST_CHANGING(x, y))
713 #define CE_PAGE(e, ce) (element_info[e].event_page[ce])
715 /* static variables for playfield scan mode (scanning forward or backward) */
716 static int playfield_scan_start_x = 0;
717 static int playfield_scan_start_y = 0;
718 static int playfield_scan_delta_x = 1;
719 static int playfield_scan_delta_y = 1;
721 #define SCAN_PLAYFIELD(x, y) for ((y) = playfield_scan_start_y; \
722 (y) >= 0 && (y) <= lev_fieldy - 1; \
723 (y) += playfield_scan_delta_y) \
724 for ((x) = playfield_scan_start_x; \
725 (x) >= 0 && (x) <= lev_fieldx - 1; \
726 (x) += playfield_scan_delta_x) \
729 void DEBUG_SetMaximumDynamite()
733 for (i = 0; i < MAX_INVENTORY_SIZE; i++)
734 if (local_player->inventory_size < MAX_INVENTORY_SIZE)
735 local_player->inventory_element[local_player->inventory_size++] =
740 static void InitPlayfieldScanModeVars()
742 if (game.use_reverse_scan_direction)
744 playfield_scan_start_x = lev_fieldx - 1;
745 playfield_scan_start_y = lev_fieldy - 1;
747 playfield_scan_delta_x = -1;
748 playfield_scan_delta_y = -1;
752 playfield_scan_start_x = 0;
753 playfield_scan_start_y = 0;
755 playfield_scan_delta_x = 1;
756 playfield_scan_delta_y = 1;
760 static void InitPlayfieldScanMode(int mode)
762 game.use_reverse_scan_direction =
763 (mode == CA_ARG_SCAN_MODE_REVERSE ? TRUE : FALSE);
765 InitPlayfieldScanModeVars();
768 static int get_move_delay_from_stepsize(int move_stepsize)
771 MIN(MAX(MOVE_STEPSIZE_MIN, move_stepsize), MOVE_STEPSIZE_MAX);
773 /* make sure that stepsize value is always a power of 2 */
774 move_stepsize = (1 << log_2(move_stepsize));
776 return TILEX / move_stepsize;
779 static void SetPlayerMoveSpeed(struct PlayerInfo *player, int move_stepsize,
782 int player_nr = player->index_nr;
783 int move_delay = get_move_delay_from_stepsize(move_stepsize);
784 boolean cannot_move = (move_stepsize == STEPSIZE_NOT_MOVING ? TRUE : FALSE);
786 /* do no immediately change move delay -- the player might just be moving */
787 player->move_delay_value_next = move_delay;
789 /* information if player can move must be set separately */
790 player->cannot_move = cannot_move;
794 player->move_delay = game.initial_move_delay[player_nr];
795 player->move_delay_value = game.initial_move_delay_value[player_nr];
797 player->move_delay_value_next = -1;
799 player->move_delay_reset_counter = 0;
803 void GetPlayerConfig()
805 if (!audio.sound_available)
806 setup.sound_simple = FALSE;
808 if (!audio.loops_available)
809 setup.sound_loops = FALSE;
811 if (!audio.music_available)
812 setup.sound_music = FALSE;
814 if (!video.fullscreen_available)
815 setup.fullscreen = FALSE;
817 setup.sound = (setup.sound_simple || setup.sound_loops || setup.sound_music);
819 SetAudioMode(setup.sound);
823 static int getBeltNrFromBeltElement(int element)
825 return (element < EL_CONVEYOR_BELT_2_LEFT ? 0 :
826 element < EL_CONVEYOR_BELT_3_LEFT ? 1 :
827 element < EL_CONVEYOR_BELT_4_LEFT ? 2 : 3);
830 static int getBeltNrFromBeltActiveElement(int element)
832 return (element < EL_CONVEYOR_BELT_2_LEFT_ACTIVE ? 0 :
833 element < EL_CONVEYOR_BELT_3_LEFT_ACTIVE ? 1 :
834 element < EL_CONVEYOR_BELT_4_LEFT_ACTIVE ? 2 : 3);
837 static int getBeltNrFromBeltSwitchElement(int element)
839 return (element < EL_CONVEYOR_BELT_2_SWITCH_LEFT ? 0 :
840 element < EL_CONVEYOR_BELT_3_SWITCH_LEFT ? 1 :
841 element < EL_CONVEYOR_BELT_4_SWITCH_LEFT ? 2 : 3);
844 static int getBeltDirNrFromBeltSwitchElement(int element)
846 static int belt_base_element[4] =
848 EL_CONVEYOR_BELT_1_SWITCH_LEFT,
849 EL_CONVEYOR_BELT_2_SWITCH_LEFT,
850 EL_CONVEYOR_BELT_3_SWITCH_LEFT,
851 EL_CONVEYOR_BELT_4_SWITCH_LEFT
854 int belt_nr = getBeltNrFromBeltSwitchElement(element);
855 int belt_dir_nr = element - belt_base_element[belt_nr];
857 return (belt_dir_nr % 3);
860 static int getBeltDirFromBeltSwitchElement(int element)
862 static int belt_move_dir[3] =
869 int belt_dir_nr = getBeltDirNrFromBeltSwitchElement(element);
871 return belt_move_dir[belt_dir_nr];
874 static int get_element_from_group_element(int element)
876 if (IS_GROUP_ELEMENT(element))
878 struct ElementGroupInfo *group = element_info[element].group;
879 int last_anim_random_frame = gfx.anim_random_frame;
882 if (group->choice_mode == ANIM_RANDOM)
883 gfx.anim_random_frame = RND(group->num_elements_resolved);
885 element_pos = getAnimationFrame(group->num_elements_resolved, 1,
886 group->choice_mode, 0,
889 if (group->choice_mode == ANIM_RANDOM)
890 gfx.anim_random_frame = last_anim_random_frame;
894 element = group->element_resolved[element_pos];
900 static void InitPlayerField(int x, int y, int element, boolean init_game)
902 if (element == EL_SP_MURPHY)
906 if (stored_player[0].present)
908 Feld[x][y] = EL_SP_MURPHY_CLONE;
914 stored_player[0].use_murphy = TRUE;
916 if (!level.use_artwork_element[0])
917 stored_player[0].artwork_element = EL_SP_MURPHY;
920 Feld[x][y] = EL_PLAYER_1;
926 struct PlayerInfo *player = &stored_player[Feld[x][y] - EL_PLAYER_1];
927 int jx = player->jx, jy = player->jy;
929 player->present = TRUE;
931 player->block_last_field = (element == EL_SP_MURPHY ?
932 level.sp_block_last_field :
933 level.block_last_field);
935 /* ---------- initialize player's last field block delay --------------- */
937 /* always start with reliable default value (no adjustment needed) */
938 player->block_delay_adjustment = 0;
940 /* special case 1: in Supaplex, Murphy blocks last field one more frame */
941 if (player->block_last_field && element == EL_SP_MURPHY)
942 player->block_delay_adjustment = 1;
944 /* special case 2: in game engines before 3.1.1, blocking was different */
945 if (game.use_block_last_field_bug)
946 player->block_delay_adjustment = (player->block_last_field ? -1 : 1);
948 if (!options.network || player->connected)
950 player->active = TRUE;
952 /* remove potentially duplicate players */
953 if (StorePlayer[jx][jy] == Feld[x][y])
954 StorePlayer[jx][jy] = 0;
956 StorePlayer[x][y] = Feld[x][y];
960 printf("Player %d activated.\n", player->element_nr);
961 printf("[Local player is %d and currently %s.]\n",
962 local_player->element_nr,
963 local_player->active ? "active" : "not active");
967 Feld[x][y] = EL_EMPTY;
969 player->jx = player->last_jx = x;
970 player->jy = player->last_jy = y;
974 static void InitField(int x, int y, boolean init_game)
976 int element = Feld[x][y];
985 InitPlayerField(x, y, element, init_game);
988 case EL_SOKOBAN_FIELD_PLAYER:
989 element = Feld[x][y] = EL_PLAYER_1;
990 InitField(x, y, init_game);
992 element = Feld[x][y] = EL_SOKOBAN_FIELD_EMPTY;
993 InitField(x, y, init_game);
996 case EL_SOKOBAN_FIELD_EMPTY:
997 local_player->sokobanfields_still_needed++;
1001 if (x < lev_fieldx-1 && Feld[x+1][y] == EL_ACID)
1002 Feld[x][y] = EL_ACID_POOL_TOPLEFT;
1003 else if (x > 0 && Feld[x-1][y] == EL_ACID)
1004 Feld[x][y] = EL_ACID_POOL_TOPRIGHT;
1005 else if (y > 0 && Feld[x][y-1] == EL_ACID_POOL_TOPLEFT)
1006 Feld[x][y] = EL_ACID_POOL_BOTTOMLEFT;
1007 else if (y > 0 && Feld[x][y-1] == EL_ACID)
1008 Feld[x][y] = EL_ACID_POOL_BOTTOM;
1009 else if (y > 0 && Feld[x][y-1] == EL_ACID_POOL_TOPRIGHT)
1010 Feld[x][y] = EL_ACID_POOL_BOTTOMRIGHT;
1019 case EL_SPACESHIP_RIGHT:
1020 case EL_SPACESHIP_UP:
1021 case EL_SPACESHIP_LEFT:
1022 case EL_SPACESHIP_DOWN:
1023 case EL_BD_BUTTERFLY:
1024 case EL_BD_BUTTERFLY_RIGHT:
1025 case EL_BD_BUTTERFLY_UP:
1026 case EL_BD_BUTTERFLY_LEFT:
1027 case EL_BD_BUTTERFLY_DOWN:
1029 case EL_BD_FIREFLY_RIGHT:
1030 case EL_BD_FIREFLY_UP:
1031 case EL_BD_FIREFLY_LEFT:
1032 case EL_BD_FIREFLY_DOWN:
1033 case EL_PACMAN_RIGHT:
1035 case EL_PACMAN_LEFT:
1036 case EL_PACMAN_DOWN:
1038 case EL_YAMYAM_LEFT:
1039 case EL_YAMYAM_RIGHT:
1041 case EL_YAMYAM_DOWN:
1042 case EL_DARK_YAMYAM:
1045 case EL_SP_SNIKSNAK:
1046 case EL_SP_ELECTRON:
1055 case EL_AMOEBA_FULL:
1060 case EL_AMOEBA_DROP:
1061 if (y == lev_fieldy - 1)
1063 Feld[x][y] = EL_AMOEBA_GROWING;
1064 Store[x][y] = EL_AMOEBA_WET;
1068 case EL_DYNAMITE_ACTIVE:
1069 case EL_SP_DISK_RED_ACTIVE:
1070 case EL_DYNABOMB_PLAYER_1_ACTIVE:
1071 case EL_DYNABOMB_PLAYER_2_ACTIVE:
1072 case EL_DYNABOMB_PLAYER_3_ACTIVE:
1073 case EL_DYNABOMB_PLAYER_4_ACTIVE:
1074 MovDelay[x][y] = 96;
1077 case EL_EM_DYNAMITE_ACTIVE:
1078 MovDelay[x][y] = 32;
1082 local_player->lights_still_needed++;
1086 local_player->friends_still_needed++;
1091 GfxDir[x][y] = MovDir[x][y] = 1 << RND(4);
1094 case EL_CONVEYOR_BELT_1_SWITCH_LEFT:
1095 case EL_CONVEYOR_BELT_1_SWITCH_MIDDLE:
1096 case EL_CONVEYOR_BELT_1_SWITCH_RIGHT:
1097 case EL_CONVEYOR_BELT_2_SWITCH_LEFT:
1098 case EL_CONVEYOR_BELT_2_SWITCH_MIDDLE:
1099 case EL_CONVEYOR_BELT_2_SWITCH_RIGHT:
1100 case EL_CONVEYOR_BELT_3_SWITCH_LEFT:
1101 case EL_CONVEYOR_BELT_3_SWITCH_MIDDLE:
1102 case EL_CONVEYOR_BELT_3_SWITCH_RIGHT:
1103 case EL_CONVEYOR_BELT_4_SWITCH_LEFT:
1104 case EL_CONVEYOR_BELT_4_SWITCH_MIDDLE:
1105 case EL_CONVEYOR_BELT_4_SWITCH_RIGHT:
1108 int belt_nr = getBeltNrFromBeltSwitchElement(Feld[x][y]);
1109 int belt_dir = getBeltDirFromBeltSwitchElement(Feld[x][y]);
1110 int belt_dir_nr = getBeltDirNrFromBeltSwitchElement(Feld[x][y]);
1112 if (game.belt_dir_nr[belt_nr] == 3) /* initial value */
1114 game.belt_dir[belt_nr] = belt_dir;
1115 game.belt_dir_nr[belt_nr] = belt_dir_nr;
1117 else /* more than one switch -- set it like the first switch */
1119 Feld[x][y] = Feld[x][y] - belt_dir_nr + game.belt_dir_nr[belt_nr];
1124 #if !USE_BOTH_SWITCHGATE_SWITCHES
1125 case EL_SWITCHGATE_SWITCH_DOWN: /* always start with same switch pos */
1127 Feld[x][y] = EL_SWITCHGATE_SWITCH_UP;
1131 case EL_LIGHT_SWITCH_ACTIVE:
1133 game.light_time_left = level.time_light * FRAMES_PER_SECOND;
1136 case EL_INVISIBLE_STEELWALL:
1137 case EL_INVISIBLE_WALL:
1138 case EL_INVISIBLE_SAND:
1139 if (game.light_time_left > 0 ||
1140 game.lenses_time_left > 0)
1141 Feld[x][y] = getInvisibleActiveFromInvisibleElement(element);
1144 case EL_EMC_MAGIC_BALL:
1145 if (game.ball_state)
1146 Feld[x][y] = EL_EMC_MAGIC_BALL_ACTIVE;
1149 case EL_EMC_MAGIC_BALL_SWITCH:
1150 if (game.ball_state)
1151 Feld[x][y] = EL_EMC_MAGIC_BALL_SWITCH_ACTIVE;
1155 if (IS_CUSTOM_ELEMENT(element))
1157 if (CAN_MOVE(element))
1160 #if USE_NEW_CUSTOM_VALUE
1161 if (!element_info[element].use_last_ce_value || init_game)
1162 CustomValue[x][y] = GET_NEW_CE_VALUE(Feld[x][y]);
1165 else if (IS_GROUP_ELEMENT(element))
1167 Feld[x][y] = get_element_from_group_element(element);
1169 InitField(x, y, init_game);
1176 CheckTriggeredElementChange(x, y, element, CE_CREATION_OF_X);
1179 static inline void InitField_WithBug1(int x, int y, boolean init_game)
1181 InitField(x, y, init_game);
1183 /* not needed to call InitMovDir() -- already done by InitField()! */
1184 if (game.engine_version < VERSION_IDENT(3,1,0,0) &&
1185 CAN_MOVE(Feld[x][y]))
1189 static inline void InitField_WithBug2(int x, int y, boolean init_game)
1191 int old_element = Feld[x][y];
1193 InitField(x, y, init_game);
1195 /* not needed to call InitMovDir() -- already done by InitField()! */
1196 if (game.engine_version < VERSION_IDENT(3,1,0,0) &&
1197 CAN_MOVE(old_element) &&
1198 (old_element < EL_MOLE_LEFT || old_element > EL_MOLE_DOWN))
1201 /* this case is in fact a combination of not less than three bugs:
1202 first, it calls InitMovDir() for elements that can move, although this is
1203 already done by InitField(); then, it checks the element that was at this
1204 field _before_ the call to InitField() (which can change it); lastly, it
1205 was not called for "mole with direction" elements, which were treated as
1206 "cannot move" due to (fixed) wrong element initialization in "src/init.c"
1210 inline void DrawGameValue_Emeralds(int value)
1212 int xpos = (3 * 14 - 3 * getFontWidth(FONT_TEXT_2)) / 2;
1214 if (PANEL_DEACTIVATED(game.panel.gems))
1217 DrawText(DX_EMERALDS + xpos, DY_EMERALDS, int2str(value, 3), FONT_TEXT_2);
1220 inline void DrawGameValue_Dynamite(int value)
1222 int xpos = (3 * 14 - 3 * getFontWidth(FONT_TEXT_2)) / 2;
1224 if (PANEL_DEACTIVATED(game.panel.inventory))
1227 DrawText(DX_DYNAMITE + xpos, DY_DYNAMITE, int2str(value, 3), FONT_TEXT_2);
1230 inline void DrawGameValue_Keys(int key[MAX_NUM_KEYS])
1232 int base_key_graphic = EL_KEY_1;
1235 if (PANEL_DEACTIVATED(game.panel.keys))
1238 if (level.game_engine_type == GAME_ENGINE_TYPE_EM)
1239 base_key_graphic = EL_EM_KEY_1;
1241 /* currently only 4 of 8 possible keys are displayed */
1242 for (i = 0; i < STD_NUM_KEYS; i++)
1244 int x = XX_KEYS + i * MINI_TILEX;
1248 DrawMiniGraphicExt(drawto, DX + x,DY + y, el2edimg(base_key_graphic + i));
1250 BlitBitmap(graphic_info[IMG_GLOBAL_DOOR].bitmap, drawto,
1251 DOOR_GFX_PAGEX5 + x, y, MINI_TILEX, MINI_TILEY, DX + x,DY + y);
1255 inline void DrawGameValue_Score(int value)
1257 int xpos = (5 * 14 - 5 * getFontWidth(FONT_TEXT_2)) / 2;
1259 if (PANEL_DEACTIVATED(game.panel.score))
1262 DrawText(DX_SCORE + xpos, DY_SCORE, int2str(value, 5), FONT_TEXT_2);
1265 inline void DrawGameValue_Time(int value)
1267 int xpos3 = (3 * 14 - 3 * getFontWidth(FONT_TEXT_2)) / 2;
1268 int xpos4 = (4 * 10 - 4 * getFontWidth(FONT_LEVEL_NUMBER)) / 2;
1270 if (PANEL_DEACTIVATED(game.panel.time))
1273 /* clear background if value just changed its size */
1274 if (value == 999 || value == 1000)
1275 ClearRectangleOnBackground(drawto, DX_TIME1, DY_TIME, 14 * 3, 14);
1278 DrawText(DX_TIME1 + xpos3, DY_TIME, int2str(value, 3), FONT_TEXT_2);
1280 DrawText(DX_TIME2 + xpos4, DY_TIME, int2str(value, 4), FONT_LEVEL_NUMBER);
1283 inline void DrawGameValue_Level(int value)
1285 if (PANEL_DEACTIVATED(game.panel.level))
1289 DrawText(DX_LEVEL1, DY_LEVEL, int2str(value, 2), FONT_TEXT_2);
1291 DrawText(DX_LEVEL2, DY_LEVEL, int2str(value, 3), FONT_LEVEL_NUMBER);
1294 void DrawAllGameValues(int emeralds, int dynamite, int score, int time,
1297 int key[MAX_NUM_KEYS];
1300 /* prevent EM engine from updating time/score values parallel to GameWon() */
1301 if (level.game_engine_type == GAME_ENGINE_TYPE_EM &&
1302 local_player->LevelSolved)
1305 for (i = 0; i < MAX_NUM_KEYS; i++)
1306 key[i] = key_bits & (1 << i);
1308 DrawGameValue_Level(level_nr);
1310 DrawGameValue_Emeralds(emeralds);
1311 DrawGameValue_Dynamite(dynamite);
1312 DrawGameValue_Score(score);
1313 DrawGameValue_Time(time);
1315 DrawGameValue_Keys(key);
1318 void DrawGameDoorValues()
1320 int time_value = (level.time == 0 ? TimePlayed : TimeLeft);
1321 int dynamite_value = 0;
1322 int score_value = (local_player->LevelSolved ? local_player->score_final :
1323 local_player->score);
1324 int gems_value = local_player->gems_still_needed;
1328 if (level.game_engine_type == GAME_ENGINE_TYPE_EM)
1330 DrawGameDoorValues_EM();
1335 if (game.centered_player_nr == -1)
1337 for (i = 0; i < MAX_PLAYERS; i++)
1339 for (j = 0; j < MAX_NUM_KEYS; j++)
1340 if (stored_player[i].key[j])
1341 key_bits |= (1 << j);
1343 dynamite_value += stored_player[i].inventory_size;
1348 int player_nr = game.centered_player_nr;
1350 for (i = 0; i < MAX_NUM_KEYS; i++)
1351 if (stored_player[player_nr].key[i])
1352 key_bits |= (1 << i);
1354 dynamite_value = stored_player[player_nr].inventory_size;
1357 DrawAllGameValues(gems_value, dynamite_value, score_value, time_value,
1363 =============================================================================
1365 -----------------------------------------------------------------------------
1366 initialize game engine due to level / tape version number
1367 =============================================================================
1370 static void InitGameEngine()
1372 int i, j, k, l, x, y;
1374 /* set game engine from tape file when re-playing, else from level file */
1375 game.engine_version = (tape.playing ? tape.engine_version :
1376 level.game_version);
1378 /* ---------------------------------------------------------------------- */
1379 /* set flags for bugs and changes according to active game engine version */
1380 /* ---------------------------------------------------------------------- */
1383 Summary of bugfix/change:
1384 Fixed handling for custom elements that change when pushed by the player.
1386 Fixed/changed in version:
1390 Before 3.1.0, custom elements that "change when pushing" changed directly
1391 after the player started pushing them (until then handled in "DigField()").
1392 Since 3.1.0, these custom elements are not changed until the "pushing"
1393 move of the element is finished (now handled in "ContinueMoving()").
1395 Affected levels/tapes:
1396 The first condition is generally needed for all levels/tapes before version
1397 3.1.0, which might use the old behaviour before it was changed; known tapes
1398 that are affected are some tapes from the level set "Walpurgis Gardens" by
1400 The second condition is an exception from the above case and is needed for
1401 the special case of tapes recorded with game (not engine!) version 3.1.0 or
1402 above (including some development versions of 3.1.0), but before it was
1403 known that this change would break tapes like the above and was fixed in
1404 3.1.1, so that the changed behaviour was active although the engine version
1405 while recording maybe was before 3.1.0. There is at least one tape that is
1406 affected by this exception, which is the tape for the one-level set "Bug
1407 Machine" by Juergen Bonhagen.
1410 game.use_change_when_pushing_bug =
1411 (game.engine_version < VERSION_IDENT(3,1,0,0) &&
1413 tape.game_version >= VERSION_IDENT(3,1,0,0) &&
1414 tape.game_version < VERSION_IDENT(3,1,1,0)));
1417 Summary of bugfix/change:
1418 Fixed handling for blocking the field the player leaves when moving.
1420 Fixed/changed in version:
1424 Before 3.1.1, when "block last field when moving" was enabled, the field
1425 the player is leaving when moving was blocked for the time of the move,
1426 and was directly unblocked afterwards. This resulted in the last field
1427 being blocked for exactly one less than the number of frames of one player
1428 move. Additionally, even when blocking was disabled, the last field was
1429 blocked for exactly one frame.
1430 Since 3.1.1, due to changes in player movement handling, the last field
1431 is not blocked at all when blocking is disabled. When blocking is enabled,
1432 the last field is blocked for exactly the number of frames of one player
1433 move. Additionally, if the player is Murphy, the hero of Supaplex, the
1434 last field is blocked for exactly one more than the number of frames of
1437 Affected levels/tapes:
1438 (!!! yet to be determined -- probably many !!!)
1441 game.use_block_last_field_bug =
1442 (game.engine_version < VERSION_IDENT(3,1,1,0));
1445 Summary of bugfix/change:
1446 Changed behaviour of CE changes with multiple changes per single frame.
1448 Fixed/changed in version:
1452 Before 3.2.0-6, only one single CE change was allowed in each engine frame.
1453 This resulted in race conditions where CEs seem to behave strange in some
1454 situations (where triggered CE changes were just skipped because there was
1455 already a CE change on that tile in the playfield in that engine frame).
1456 Since 3.2.0-6, this was changed to allow up to MAX_NUM_CHANGES_PER_FRAME.
1457 (The number of changes per frame must be limited in any case, because else
1458 it is easily possible to define CE changes that would result in an infinite
1459 loop, causing the whole game to freeze. The MAX_NUM_CHANGES_PER_FRAME value
1460 should be set large enough so that it would only be reached in cases where
1461 the corresponding CE change conditions run into a loop. Therefore, it seems
1462 to be reasonable to set MAX_NUM_CHANGES_PER_FRAME to the same value as the
1463 maximal number of change pages for custom elements.)
1465 Affected levels/tapes:
1469 #if USE_ONLY_ONE_CHANGE_PER_FRAME
1470 game.max_num_changes_per_frame = 1;
1472 game.max_num_changes_per_frame =
1473 (game.engine_version < VERSION_IDENT(3,2,0,6) ? 1 : 32);
1476 /* ---------------------------------------------------------------------- */
1478 /* default scan direction: scan playfield from top/left to bottom/right */
1479 InitPlayfieldScanMode(CA_ARG_SCAN_MODE_NORMAL);
1481 /* dynamically adjust element properties according to game engine version */
1482 InitElementPropertiesEngine(game.engine_version);
1485 printf("level %d: level version == %06d\n", level_nr, level.game_version);
1486 printf(" tape version == %06d [%s] [file: %06d]\n",
1487 tape.engine_version, (tape.playing ? "PLAYING" : "RECORDING"),
1489 printf(" => game.engine_version == %06d\n", game.engine_version);
1492 /* ---------- initialize player's initial move delay --------------------- */
1494 /* dynamically adjust player properties according to level information */
1495 for (i = 0; i < MAX_PLAYERS; i++)
1496 game.initial_move_delay_value[i] =
1497 get_move_delay_from_stepsize(level.initial_player_stepsize[i]);
1499 /* dynamically adjust player properties according to game engine version */
1500 for (i = 0; i < MAX_PLAYERS; i++)
1501 game.initial_move_delay[i] =
1502 (game.engine_version <= VERSION_IDENT(2,0,1,0) ?
1503 game.initial_move_delay_value[i] : 0);
1505 /* ---------- initialize player's initial push delay --------------------- */
1507 /* dynamically adjust player properties according to game engine version */
1508 game.initial_push_delay_value =
1509 (game.engine_version < VERSION_IDENT(3,0,7,1) ? 5 : -1);
1511 /* ---------- initialize changing elements ------------------------------- */
1513 /* initialize changing elements information */
1514 for (i = 0; i < MAX_NUM_ELEMENTS; i++)
1516 struct ElementInfo *ei = &element_info[i];
1518 /* this pointer might have been changed in the level editor */
1519 ei->change = &ei->change_page[0];
1521 if (!IS_CUSTOM_ELEMENT(i))
1523 ei->change->target_element = EL_EMPTY_SPACE;
1524 ei->change->delay_fixed = 0;
1525 ei->change->delay_random = 0;
1526 ei->change->delay_frames = 1;
1529 for (j = 0; j < NUM_CHANGE_EVENTS; j++)
1531 ei->has_change_event[j] = FALSE;
1533 ei->event_page_nr[j] = 0;
1534 ei->event_page[j] = &ei->change_page[0];
1538 /* add changing elements from pre-defined list */
1539 for (i = 0; change_delay_list[i].element != EL_UNDEFINED; i++)
1541 struct ChangingElementInfo *ch_delay = &change_delay_list[i];
1542 struct ElementInfo *ei = &element_info[ch_delay->element];
1544 ei->change->target_element = ch_delay->target_element;
1545 ei->change->delay_fixed = ch_delay->change_delay;
1547 ei->change->pre_change_function = ch_delay->pre_change_function;
1548 ei->change->change_function = ch_delay->change_function;
1549 ei->change->post_change_function = ch_delay->post_change_function;
1551 ei->change->can_change = TRUE;
1552 ei->change->can_change_or_has_action = TRUE;
1554 ei->has_change_event[CE_DELAY] = TRUE;
1556 SET_PROPERTY(ch_delay->element, EP_CAN_CHANGE, TRUE);
1557 SET_PROPERTY(ch_delay->element, EP_CAN_CHANGE_OR_HAS_ACTION, TRUE);
1560 /* ---------- initialize internal run-time variables ------------- */
1562 for (i = 0; i < NUM_CUSTOM_ELEMENTS; i++)
1564 struct ElementInfo *ei = &element_info[EL_CUSTOM_START + i];
1566 for (j = 0; j < ei->num_change_pages; j++)
1568 ei->change_page[j].can_change_or_has_action =
1569 (ei->change_page[j].can_change |
1570 ei->change_page[j].has_action);
1574 /* add change events from custom element configuration */
1575 for (i = 0; i < NUM_CUSTOM_ELEMENTS; i++)
1577 struct ElementInfo *ei = &element_info[EL_CUSTOM_START + i];
1579 for (j = 0; j < ei->num_change_pages; j++)
1581 if (!ei->change_page[j].can_change_or_has_action)
1584 for (k = 0; k < NUM_CHANGE_EVENTS; k++)
1586 /* only add event page for the first page found with this event */
1587 if (ei->change_page[j].has_event[k] && !(ei->has_change_event[k]))
1589 ei->has_change_event[k] = TRUE;
1591 ei->event_page_nr[k] = j;
1592 ei->event_page[k] = &ei->change_page[j];
1598 /* ---------- initialize run-time trigger player and element ------------- */
1600 for (i = 0; i < NUM_CUSTOM_ELEMENTS; i++)
1602 struct ElementInfo *ei = &element_info[EL_CUSTOM_START + i];
1604 for (j = 0; j < ei->num_change_pages; j++)
1606 ei->change_page[j].actual_trigger_element = EL_EMPTY;
1607 ei->change_page[j].actual_trigger_player = EL_PLAYER_1;
1608 ei->change_page[j].actual_trigger_side = CH_SIDE_NONE;
1609 ei->change_page[j].actual_trigger_ce_value = 0;
1610 ei->change_page[j].actual_trigger_ce_score = 0;
1614 /* ---------- initialize trigger events ---------------------------------- */
1616 /* initialize trigger events information */
1617 for (i = 0; i < MAX_NUM_ELEMENTS; i++)
1618 for (j = 0; j < NUM_CHANGE_EVENTS; j++)
1619 trigger_events[i][j] = FALSE;
1621 /* add trigger events from element change event properties */
1622 for (i = 0; i < MAX_NUM_ELEMENTS; i++)
1624 struct ElementInfo *ei = &element_info[i];
1626 for (j = 0; j < ei->num_change_pages; j++)
1628 if (!ei->change_page[j].can_change_or_has_action)
1631 if (ei->change_page[j].has_event[CE_BY_OTHER_ACTION])
1633 int trigger_element = ei->change_page[j].trigger_element;
1635 for (k = 0; k < NUM_CHANGE_EVENTS; k++)
1637 if (ei->change_page[j].has_event[k])
1639 if (IS_GROUP_ELEMENT(trigger_element))
1641 struct ElementGroupInfo *group =
1642 element_info[trigger_element].group;
1644 for (l = 0; l < group->num_elements_resolved; l++)
1645 trigger_events[group->element_resolved[l]][k] = TRUE;
1647 else if (trigger_element == EL_ANY_ELEMENT)
1648 for (l = 0; l < MAX_NUM_ELEMENTS; l++)
1649 trigger_events[l][k] = TRUE;
1651 trigger_events[trigger_element][k] = TRUE;
1658 /* ---------- initialize push delay -------------------------------------- */
1660 /* initialize push delay values to default */
1661 for (i = 0; i < MAX_NUM_ELEMENTS; i++)
1663 if (!IS_CUSTOM_ELEMENT(i))
1665 /* set default push delay values (corrected since version 3.0.7-1) */
1666 if (game.engine_version < VERSION_IDENT(3,0,7,1))
1668 element_info[i].push_delay_fixed = 2;
1669 element_info[i].push_delay_random = 8;
1673 element_info[i].push_delay_fixed = 8;
1674 element_info[i].push_delay_random = 8;
1679 /* set push delay value for certain elements from pre-defined list */
1680 for (i = 0; push_delay_list[i].element != EL_UNDEFINED; i++)
1682 int e = push_delay_list[i].element;
1684 element_info[e].push_delay_fixed = push_delay_list[i].push_delay_fixed;
1685 element_info[e].push_delay_random = push_delay_list[i].push_delay_random;
1688 /* set push delay value for Supaplex elements for newer engine versions */
1689 if (game.engine_version >= VERSION_IDENT(3,1,0,0))
1691 for (i = 0; i < MAX_NUM_ELEMENTS; i++)
1693 if (IS_SP_ELEMENT(i))
1695 /* set SP push delay to just enough to push under a falling zonk */
1696 int delay = (game.engine_version >= VERSION_IDENT(3,1,1,0) ? 8 : 6);
1698 element_info[i].push_delay_fixed = delay;
1699 element_info[i].push_delay_random = 0;
1704 /* ---------- initialize move stepsize ----------------------------------- */
1706 /* initialize move stepsize values to default */
1707 for (i = 0; i < MAX_NUM_ELEMENTS; i++)
1708 if (!IS_CUSTOM_ELEMENT(i))
1709 element_info[i].move_stepsize = MOVE_STEPSIZE_NORMAL;
1711 /* set move stepsize value for certain elements from pre-defined list */
1712 for (i = 0; move_stepsize_list[i].element != EL_UNDEFINED; i++)
1714 int e = move_stepsize_list[i].element;
1716 element_info[e].move_stepsize = move_stepsize_list[i].move_stepsize;
1719 /* ---------- initialize collect score ----------------------------------- */
1721 /* initialize collect score values for custom elements from initial value */
1722 for (i = 0; i < MAX_NUM_ELEMENTS; i++)
1723 if (IS_CUSTOM_ELEMENT(i))
1724 element_info[i].collect_score = element_info[i].collect_score_initial;
1726 /* ---------- initialize collect count ----------------------------------- */
1728 /* initialize collect count values for non-custom elements */
1729 for (i = 0; i < MAX_NUM_ELEMENTS; i++)
1730 if (!IS_CUSTOM_ELEMENT(i))
1731 element_info[i].collect_count_initial = 0;
1733 /* add collect count values for all elements from pre-defined list */
1734 for (i = 0; collect_count_list[i].element != EL_UNDEFINED; i++)
1735 element_info[collect_count_list[i].element].collect_count_initial =
1736 collect_count_list[i].count;
1738 /* ---------- initialize access direction -------------------------------- */
1740 /* initialize access direction values to default (access from every side) */
1741 for (i = 0; i < MAX_NUM_ELEMENTS; i++)
1742 if (!IS_CUSTOM_ELEMENT(i))
1743 element_info[i].access_direction = MV_ALL_DIRECTIONS;
1745 /* set access direction value for certain elements from pre-defined list */
1746 for (i = 0; access_direction_list[i].element != EL_UNDEFINED; i++)
1747 element_info[access_direction_list[i].element].access_direction =
1748 access_direction_list[i].direction;
1750 /* ---------- initialize explosion content ------------------------------- */
1751 for (i = 0; i < MAX_NUM_ELEMENTS; i++)
1753 if (IS_CUSTOM_ELEMENT(i))
1756 for (y = 0; y < 3; y++) for (x = 0; x < 3; x++)
1758 /* (content for EL_YAMYAM set at run-time with game.yamyam_content_nr) */
1760 element_info[i].content.e[x][y] =
1761 (i == EL_PLAYER_1 ? EL_EMERALD_YELLOW :
1762 i == EL_PLAYER_2 ? EL_EMERALD_RED :
1763 i == EL_PLAYER_3 ? EL_EMERALD :
1764 i == EL_PLAYER_4 ? EL_EMERALD_PURPLE :
1765 i == EL_MOLE ? EL_EMERALD_RED :
1766 i == EL_PENGUIN ? EL_EMERALD_PURPLE :
1767 i == EL_BUG ? (x == 1 && y == 1 ? EL_DIAMOND : EL_EMERALD) :
1768 i == EL_BD_BUTTERFLY ? EL_BD_DIAMOND :
1769 i == EL_SP_ELECTRON ? EL_SP_INFOTRON :
1770 i == EL_AMOEBA_TO_DIAMOND ? level.amoeba_content :
1771 i == EL_WALL_EMERALD ? EL_EMERALD :
1772 i == EL_WALL_DIAMOND ? EL_DIAMOND :
1773 i == EL_WALL_BD_DIAMOND ? EL_BD_DIAMOND :
1774 i == EL_WALL_EMERALD_YELLOW ? EL_EMERALD_YELLOW :
1775 i == EL_WALL_EMERALD_RED ? EL_EMERALD_RED :
1776 i == EL_WALL_EMERALD_PURPLE ? EL_EMERALD_PURPLE :
1777 i == EL_WALL_PEARL ? EL_PEARL :
1778 i == EL_WALL_CRYSTAL ? EL_CRYSTAL :
1784 int get_num_special_action(int element, int action_first, int action_last)
1786 int num_special_action = 0;
1789 for (i = action_first; i <= action_last; i++)
1791 boolean found = FALSE;
1793 for (j = 0; j < NUM_DIRECTIONS; j++)
1794 if (el_act_dir2img(element, i, j) !=
1795 el_act_dir2img(element, ACTION_DEFAULT, j))
1799 num_special_action++;
1804 return num_special_action;
1809 =============================================================================
1811 -----------------------------------------------------------------------------
1812 initialize and start new game
1813 =============================================================================
1818 boolean emulate_bd = TRUE; /* unless non-BOULDERDASH elements found */
1819 boolean emulate_sb = TRUE; /* unless non-SOKOBAN elements found */
1820 boolean emulate_sp = TRUE; /* unless non-SUPAPLEX elements found */
1821 boolean do_fading = (game_status == GAME_MODE_MAIN);
1824 game_status = GAME_MODE_PLAYING;
1828 /* don't play tapes over network */
1829 network_playing = (options.network && !tape.playing);
1831 for (i = 0; i < MAX_PLAYERS; i++)
1833 struct PlayerInfo *player = &stored_player[i];
1835 player->index_nr = i;
1836 player->index_bit = (1 << i);
1837 player->element_nr = EL_PLAYER_1 + i;
1839 player->present = FALSE;
1840 player->active = FALSE;
1843 player->effective_action = 0;
1844 player->programmed_action = 0;
1847 player->score_final = 0;
1849 player->gems_still_needed = level.gems_needed;
1850 player->sokobanfields_still_needed = 0;
1851 player->lights_still_needed = 0;
1852 player->friends_still_needed = 0;
1854 for (j = 0; j < MAX_NUM_KEYS; j++)
1855 player->key[j] = FALSE;
1857 player->dynabomb_count = 0;
1858 player->dynabomb_size = 1;
1859 player->dynabombs_left = 0;
1860 player->dynabomb_xl = FALSE;
1862 player->MovDir = MV_NONE;
1865 player->GfxDir = MV_NONE;
1866 player->GfxAction = ACTION_DEFAULT;
1868 player->StepFrame = 0;
1870 player->use_murphy = FALSE;
1871 player->artwork_element =
1872 (level.use_artwork_element[i] ? level.artwork_element[i] :
1873 player->element_nr);
1875 player->block_last_field = FALSE; /* initialized in InitPlayerField() */
1876 player->block_delay_adjustment = 0; /* initialized in InitPlayerField() */
1878 player->gravity = level.initial_player_gravity[i];
1880 player->can_fall_into_acid = CAN_MOVE_INTO_ACID(player->element_nr);
1882 player->actual_frame_counter = 0;
1884 player->step_counter = 0;
1886 player->last_move_dir = MV_NONE;
1888 player->is_active = FALSE;
1890 player->is_waiting = FALSE;
1891 player->is_moving = FALSE;
1892 player->is_auto_moving = FALSE;
1893 player->is_digging = FALSE;
1894 player->is_snapping = FALSE;
1895 player->is_collecting = FALSE;
1896 player->is_pushing = FALSE;
1897 player->is_switching = FALSE;
1898 player->is_dropping = FALSE;
1899 player->is_dropping_pressed = FALSE;
1901 player->is_bored = FALSE;
1902 player->is_sleeping = FALSE;
1904 player->frame_counter_bored = -1;
1905 player->frame_counter_sleeping = -1;
1907 player->anim_delay_counter = 0;
1908 player->post_delay_counter = 0;
1910 player->dir_waiting = MV_NONE;
1911 player->action_waiting = ACTION_DEFAULT;
1912 player->last_action_waiting = ACTION_DEFAULT;
1913 player->special_action_bored = ACTION_DEFAULT;
1914 player->special_action_sleeping = ACTION_DEFAULT;
1916 player->switch_x = -1;
1917 player->switch_y = -1;
1919 player->drop_x = -1;
1920 player->drop_y = -1;
1922 player->show_envelope = 0;
1924 SetPlayerMoveSpeed(player, level.initial_player_stepsize[i], TRUE);
1926 player->push_delay = -1; /* initialized when pushing starts */
1927 player->push_delay_value = game.initial_push_delay_value;
1929 player->drop_delay = 0;
1930 player->drop_pressed_delay = 0;
1932 player->last_jx = player->last_jy = 0;
1933 player->jx = player->jy = 0;
1935 player->shield_normal_time_left = 0;
1936 player->shield_deadly_time_left = 0;
1938 player->inventory_infinite_element = EL_UNDEFINED;
1939 player->inventory_size = 0;
1941 DigField(player, 0, 0, 0, 0, 0, 0, DF_NO_PUSH);
1942 SnapField(player, 0, 0);
1944 player->LevelSolved = FALSE;
1945 player->GameOver = FALSE;
1947 player->LevelSolved_GameEnd = FALSE;
1948 player->LevelSolved_SaveTape = FALSE;
1949 player->LevelSolved_SaveScore = FALSE;
1952 network_player_action_received = FALSE;
1954 #if defined(NETWORK_AVALIABLE)
1955 /* initial null action */
1956 if (network_playing)
1957 SendToServer_MovePlayer(MV_NONE);
1966 TimeLeft = level.time;
1969 ScreenMovDir = MV_NONE;
1973 ScrollStepSize = 0; /* will be correctly initialized by ScrollScreen() */
1975 AllPlayersGone = FALSE;
1977 game.yamyam_content_nr = 0;
1978 game.magic_wall_active = FALSE;
1979 game.magic_wall_time_left = 0;
1980 game.light_time_left = 0;
1981 game.timegate_time_left = 0;
1982 game.switchgate_pos = 0;
1983 game.wind_direction = level.wind_direction_initial;
1985 #if !USE_PLAYER_GRAVITY
1986 game.gravity = FALSE;
1987 game.explosions_delayed = TRUE;
1990 game.lenses_time_left = 0;
1991 game.magnify_time_left = 0;
1993 game.ball_state = level.ball_state_initial;
1994 game.ball_content_nr = 0;
1996 game.envelope_active = FALSE;
1998 /* set focus to local player for network games, else to all players */
1999 game.centered_player_nr = (network_playing ? local_player->index_nr : -1);
2000 game.centered_player_nr_next = game.centered_player_nr;
2001 game.set_centered_player = FALSE;
2003 if (network_playing && tape.recording)
2005 /* store client dependent player focus when recording network games */
2006 tape.centered_player_nr_next = game.centered_player_nr_next;
2007 tape.set_centered_player = TRUE;
2010 for (i = 0; i < NUM_BELTS; i++)
2012 game.belt_dir[i] = MV_NONE;
2013 game.belt_dir_nr[i] = 3; /* not moving, next moving left */
2016 for (i = 0; i < MAX_NUM_AMOEBA; i++)
2017 AmoebaCnt[i] = AmoebaCnt2[i] = 0;
2019 SCAN_PLAYFIELD(x, y)
2021 Feld[x][y] = level.field[x][y];
2022 MovPos[x][y] = MovDir[x][y] = MovDelay[x][y] = 0;
2023 ChangeDelay[x][y] = 0;
2024 ChangePage[x][y] = -1;
2025 #if USE_NEW_CUSTOM_VALUE
2026 CustomValue[x][y] = 0; /* initialized in InitField() */
2028 Store[x][y] = Store2[x][y] = StorePlayer[x][y] = Back[x][y] = 0;
2030 WasJustMoving[x][y] = 0;
2031 WasJustFalling[x][y] = 0;
2032 CheckCollision[x][y] = 0;
2034 Pushed[x][y] = FALSE;
2036 ChangeCount[x][y] = 0;
2037 ChangeEvent[x][y] = -1;
2039 ExplodePhase[x][y] = 0;
2040 ExplodeDelay[x][y] = 0;
2041 ExplodeField[x][y] = EX_TYPE_NONE;
2043 RunnerVisit[x][y] = 0;
2044 PlayerVisit[x][y] = 0;
2047 GfxRandom[x][y] = INIT_GFX_RANDOM();
2048 GfxElement[x][y] = EL_UNDEFINED;
2049 GfxAction[x][y] = ACTION_DEFAULT;
2050 GfxDir[x][y] = MV_NONE;
2053 SCAN_PLAYFIELD(x, y)
2055 if (emulate_bd && !IS_BD_ELEMENT(Feld[x][y]))
2057 if (emulate_sb && !IS_SB_ELEMENT(Feld[x][y]))
2059 if (emulate_sp && !IS_SP_ELEMENT(Feld[x][y]))
2062 InitField(x, y, TRUE);
2067 for (i = 0; i < MAX_PLAYERS; i++)
2069 struct PlayerInfo *player = &stored_player[i];
2071 /* set number of special actions for bored and sleeping animation */
2072 player->num_special_action_bored =
2073 get_num_special_action(player->artwork_element,
2074 ACTION_BORING_1, ACTION_BORING_LAST);
2075 player->num_special_action_sleeping =
2076 get_num_special_action(player->artwork_element,
2077 ACTION_SLEEPING_1, ACTION_SLEEPING_LAST);
2080 game.emulation = (emulate_bd ? EMU_BOULDERDASH :
2081 emulate_sb ? EMU_SOKOBAN :
2082 emulate_sp ? EMU_SUPAPLEX : EMU_NONE);
2084 #if USE_NEW_ALL_SLIPPERY
2085 /* initialize type of slippery elements */
2086 for (i = 0; i < MAX_NUM_ELEMENTS; i++)
2088 if (!IS_CUSTOM_ELEMENT(i))
2090 /* default: elements slip down either to the left or right randomly */
2091 element_info[i].slippery_type = SLIPPERY_ANY_RANDOM;
2093 /* SP style elements prefer to slip down on the left side */
2094 if (game.engine_version >= VERSION_IDENT(3,1,1,0) && IS_SP_ELEMENT(i))
2095 element_info[i].slippery_type = SLIPPERY_ANY_LEFT_RIGHT;
2097 /* BD style elements prefer to slip down on the left side */
2098 if (game.emulation == EMU_BOULDERDASH)
2099 element_info[i].slippery_type = SLIPPERY_ANY_LEFT_RIGHT;
2104 /* initialize explosion and ignition delay */
2105 for (i = 0; i < MAX_NUM_ELEMENTS; i++)
2107 if (!IS_CUSTOM_ELEMENT(i))
2110 int delay = (((IS_SP_ELEMENT(i) && i != EL_EMPTY_SPACE) &&
2111 game.engine_version >= VERSION_IDENT(3,1,0,0)) ||
2112 game.emulation == EMU_SUPAPLEX ? 3 : 2);
2113 int last_phase = (num_phase + 1) * delay;
2114 int half_phase = (num_phase / 2) * delay;
2116 element_info[i].explosion_delay = last_phase - 1;
2117 element_info[i].ignition_delay = half_phase;
2119 if (i == EL_BLACK_ORB)
2120 element_info[i].ignition_delay = 1;
2124 if (element_info[i].explosion_delay < 1) /* !!! check again !!! */
2125 element_info[i].explosion_delay = 1;
2127 if (element_info[i].ignition_delay < 1) /* !!! check again !!! */
2128 element_info[i].ignition_delay = 1;
2132 /* correct non-moving belts to start moving left */
2133 for (i = 0; i < NUM_BELTS; i++)
2134 if (game.belt_dir[i] == MV_NONE)
2135 game.belt_dir_nr[i] = 3; /* not moving, next moving left */
2137 /* check if any connected player was not found in playfield */
2138 for (i = 0; i < MAX_PLAYERS; i++)
2140 struct PlayerInfo *player = &stored_player[i];
2142 if (player->connected && !player->present)
2144 for (j = 0; j < MAX_PLAYERS; j++)
2146 struct PlayerInfo *some_player = &stored_player[j];
2147 int jx = some_player->jx, jy = some_player->jy;
2149 /* assign first free player found that is present in the playfield */
2150 if (some_player->present && !some_player->connected)
2152 player->present = TRUE;
2153 player->active = TRUE;
2155 some_player->present = FALSE;
2156 some_player->active = FALSE;
2158 player->artwork_element = some_player->artwork_element;
2160 player->block_last_field = some_player->block_last_field;
2161 player->block_delay_adjustment = some_player->block_delay_adjustment;
2163 StorePlayer[jx][jy] = player->element_nr;
2164 player->jx = player->last_jx = jx;
2165 player->jy = player->last_jy = jy;
2175 /* when playing a tape, eliminate all players who do not participate */
2177 for (i = 0; i < MAX_PLAYERS; i++)
2179 if (stored_player[i].active && !tape.player_participates[i])
2181 struct PlayerInfo *player = &stored_player[i];
2182 int jx = player->jx, jy = player->jy;
2184 player->active = FALSE;
2185 StorePlayer[jx][jy] = 0;
2186 Feld[jx][jy] = EL_EMPTY;
2190 else if (!options.network && !setup.team_mode) /* && !tape.playing */
2192 /* when in single player mode, eliminate all but the first active player */
2194 for (i = 0; i < MAX_PLAYERS; i++)
2196 if (stored_player[i].active)
2198 for (j = i + 1; j < MAX_PLAYERS; j++)
2200 if (stored_player[j].active)
2202 struct PlayerInfo *player = &stored_player[j];
2203 int jx = player->jx, jy = player->jy;
2205 player->active = FALSE;
2206 player->present = FALSE;
2208 StorePlayer[jx][jy] = 0;
2209 Feld[jx][jy] = EL_EMPTY;
2216 /* when recording the game, store which players take part in the game */
2219 for (i = 0; i < MAX_PLAYERS; i++)
2220 if (stored_player[i].active)
2221 tape.player_participates[i] = TRUE;
2226 for (i = 0; i < MAX_PLAYERS; i++)
2228 struct PlayerInfo *player = &stored_player[i];
2230 printf("Player %d: present == %d, connected == %d, active == %d.\n",
2235 if (local_player == player)
2236 printf("Player %d is local player.\n", i+1);
2240 if (BorderElement == EL_EMPTY)
2243 SBX_Right = lev_fieldx - SCR_FIELDX;
2245 SBY_Lower = lev_fieldy - SCR_FIELDY;
2250 SBX_Right = lev_fieldx - SCR_FIELDX + 1;
2252 SBY_Lower = lev_fieldy - SCR_FIELDY + 1;
2255 if (lev_fieldx + (SBX_Left == -1 ? 2 : 0) <= SCR_FIELDX)
2256 SBX_Left = SBX_Right = -1 * (SCR_FIELDX - lev_fieldx) / 2;
2258 if (lev_fieldy + (SBY_Upper == -1 ? 2 : 0) <= SCR_FIELDY)
2259 SBY_Upper = SBY_Lower = -1 * (SCR_FIELDY - lev_fieldy) / 2;
2261 /* if local player not found, look for custom element that might create
2262 the player (make some assumptions about the right custom element) */
2263 if (!local_player->present)
2265 int start_x = 0, start_y = 0;
2266 int found_rating = 0;
2267 int found_element = EL_UNDEFINED;
2268 int player_nr = local_player->index_nr;
2270 SCAN_PLAYFIELD(x, y)
2272 int element = Feld[x][y];
2277 if (level.use_start_element[player_nr] &&
2278 level.start_element[player_nr] == element &&
2285 found_element = element;
2288 if (!IS_CUSTOM_ELEMENT(element))
2291 if (CAN_CHANGE(element))
2293 for (i = 0; i < element_info[element].num_change_pages; i++)
2295 /* check for player created from custom element as single target */
2296 content = element_info[element].change_page[i].target_element;
2297 is_player = ELEM_IS_PLAYER(content);
2299 if (is_player && (found_rating < 3 || element < found_element))
2305 found_element = element;
2310 for (yy = 0; yy < 3; yy++) for (xx = 0; xx < 3; xx++)
2312 /* check for player created from custom element as explosion content */
2313 content = element_info[element].content.e[xx][yy];
2314 is_player = ELEM_IS_PLAYER(content);
2316 if (is_player && (found_rating < 2 || element < found_element))
2318 start_x = x + xx - 1;
2319 start_y = y + yy - 1;
2322 found_element = element;
2325 if (!CAN_CHANGE(element))
2328 for (i = 0; i < element_info[element].num_change_pages; i++)
2330 /* check for player created from custom element as extended target */
2332 element_info[element].change_page[i].target_content.e[xx][yy];
2334 is_player = ELEM_IS_PLAYER(content);
2336 if (is_player && (found_rating < 1 || element < found_element))
2338 start_x = x + xx - 1;
2339 start_y = y + yy - 1;
2342 found_element = element;
2348 scroll_x = (start_x < SBX_Left + MIDPOSX ? SBX_Left :
2349 start_x > SBX_Right + MIDPOSX ? SBX_Right :
2352 scroll_y = (start_y < SBY_Upper + MIDPOSY ? SBY_Upper :
2353 start_y > SBY_Lower + MIDPOSY ? SBY_Lower :
2358 scroll_x = (local_player->jx < SBX_Left + MIDPOSX ? SBX_Left :
2359 local_player->jx > SBX_Right + MIDPOSX ? SBX_Right :
2360 local_player->jx - MIDPOSX);
2362 scroll_y = (local_player->jy < SBY_Upper + MIDPOSY ? SBY_Upper :
2363 local_player->jy > SBY_Lower + MIDPOSY ? SBY_Lower :
2364 local_player->jy - MIDPOSY);
2369 if (!game.restart_level)
2370 CloseDoor(DOOR_CLOSE_1);
2373 FadeOut(REDRAW_FIELD);
2375 /* !!! FIX THIS (START) !!! */
2376 if (level.game_engine_type == GAME_ENGINE_TYPE_EM)
2378 InitGameEngine_EM();
2380 /* blit playfield from scroll buffer to normal back buffer for fading in */
2381 BlitScreenToBitmap_EM(backbuffer);
2388 /* after drawing the level, correct some elements */
2389 if (game.timegate_time_left == 0)
2390 CloseAllOpenTimegates();
2392 /* blit playfield from scroll buffer to normal back buffer for fading in */
2393 if (setup.soft_scrolling)
2394 BlitBitmap(fieldbuffer, backbuffer, FX, FY, SXSIZE, SYSIZE, SX, SY);
2396 redraw_mask |= REDRAW_FROM_BACKBUFFER;
2398 /* !!! FIX THIS (END) !!! */
2401 FadeIn(REDRAW_FIELD);
2405 if (!game.restart_level)
2407 /* copy default game door content to main double buffer */
2408 BlitBitmap(graphic_info[IMG_GLOBAL_DOOR].bitmap, drawto,
2409 DOOR_GFX_PAGEX5, DOOR_GFX_PAGEY1, DXSIZE, DYSIZE, DX, DY);
2412 SetPanelBackground();
2413 SetDrawBackgroundMask(REDRAW_DOOR_1);
2415 DrawGameDoorValues();
2417 if (!game.restart_level)
2421 game_gadget[SOUND_CTRL_ID_MUSIC]->checked = setup.sound_music;
2422 game_gadget[SOUND_CTRL_ID_LOOPS]->checked = setup.sound_loops;
2423 game_gadget[SOUND_CTRL_ID_SIMPLE]->checked = setup.sound_simple;
2427 /* copy actual game door content to door double buffer for OpenDoor() */
2428 BlitBitmap(drawto, bitmap_db_door,
2429 DX, DY, DXSIZE, DYSIZE, DOOR_GFX_PAGEX1, DOOR_GFX_PAGEY1);
2431 OpenDoor(DOOR_OPEN_ALL);
2433 PlaySound(SND_GAME_STARTING);
2435 if (setup.sound_music)
2438 KeyboardAutoRepeatOffUnlessAutoplay();
2442 for (i = 0; i < MAX_PLAYERS; i++)
2443 printf("Player %d %sactive.\n",
2444 i + 1, (stored_player[i].active ? "" : "not "));
2448 game.restart_level = FALSE;
2451 void UpdateEngineValues(int actual_scroll_x, int actual_scroll_y)
2453 /* this is used for non-R'n'D game engines to update certain engine values */
2455 /* needed to determine if sounds are played within the visible screen area */
2456 scroll_x = actual_scroll_x;
2457 scroll_y = actual_scroll_y;
2460 void InitMovDir(int x, int y)
2462 int i, element = Feld[x][y];
2463 static int xy[4][2] =
2470 static int direction[3][4] =
2472 { MV_RIGHT, MV_UP, MV_LEFT, MV_DOWN },
2473 { MV_LEFT, MV_DOWN, MV_RIGHT, MV_UP },
2474 { MV_LEFT, MV_RIGHT, MV_UP, MV_DOWN }
2483 Feld[x][y] = EL_BUG;
2484 MovDir[x][y] = direction[0][element - EL_BUG_RIGHT];
2487 case EL_SPACESHIP_RIGHT:
2488 case EL_SPACESHIP_UP:
2489 case EL_SPACESHIP_LEFT:
2490 case EL_SPACESHIP_DOWN:
2491 Feld[x][y] = EL_SPACESHIP;
2492 MovDir[x][y] = direction[0][element - EL_SPACESHIP_RIGHT];
2495 case EL_BD_BUTTERFLY_RIGHT:
2496 case EL_BD_BUTTERFLY_UP:
2497 case EL_BD_BUTTERFLY_LEFT:
2498 case EL_BD_BUTTERFLY_DOWN:
2499 Feld[x][y] = EL_BD_BUTTERFLY;
2500 MovDir[x][y] = direction[0][element - EL_BD_BUTTERFLY_RIGHT];
2503 case EL_BD_FIREFLY_RIGHT:
2504 case EL_BD_FIREFLY_UP:
2505 case EL_BD_FIREFLY_LEFT:
2506 case EL_BD_FIREFLY_DOWN:
2507 Feld[x][y] = EL_BD_FIREFLY;
2508 MovDir[x][y] = direction[0][element - EL_BD_FIREFLY_RIGHT];
2511 case EL_PACMAN_RIGHT:
2513 case EL_PACMAN_LEFT:
2514 case EL_PACMAN_DOWN:
2515 Feld[x][y] = EL_PACMAN;
2516 MovDir[x][y] = direction[0][element - EL_PACMAN_RIGHT];
2519 case EL_YAMYAM_LEFT:
2520 case EL_YAMYAM_RIGHT:
2522 case EL_YAMYAM_DOWN:
2523 Feld[x][y] = EL_YAMYAM;
2524 MovDir[x][y] = direction[2][element - EL_YAMYAM_LEFT];
2527 case EL_SP_SNIKSNAK:
2528 MovDir[x][y] = MV_UP;
2531 case EL_SP_ELECTRON:
2532 MovDir[x][y] = MV_LEFT;
2539 Feld[x][y] = EL_MOLE;
2540 MovDir[x][y] = direction[2][element - EL_MOLE_LEFT];
2544 if (IS_CUSTOM_ELEMENT(element))
2546 struct ElementInfo *ei = &element_info[element];
2547 int move_direction_initial = ei->move_direction_initial;
2548 int move_pattern = ei->move_pattern;
2550 if (move_direction_initial == MV_START_PREVIOUS)
2552 if (MovDir[x][y] != MV_NONE)
2555 move_direction_initial = MV_START_AUTOMATIC;
2558 if (move_direction_initial == MV_START_RANDOM)
2559 MovDir[x][y] = 1 << RND(4);
2560 else if (move_direction_initial & MV_ANY_DIRECTION)
2561 MovDir[x][y] = move_direction_initial;
2562 else if (move_pattern == MV_ALL_DIRECTIONS ||
2563 move_pattern == MV_TURNING_LEFT ||
2564 move_pattern == MV_TURNING_RIGHT ||
2565 move_pattern == MV_TURNING_LEFT_RIGHT ||
2566 move_pattern == MV_TURNING_RIGHT_LEFT ||
2567 move_pattern == MV_TURNING_RANDOM)
2568 MovDir[x][y] = 1 << RND(4);
2569 else if (move_pattern == MV_HORIZONTAL)
2570 MovDir[x][y] = (RND(2) ? MV_LEFT : MV_RIGHT);
2571 else if (move_pattern == MV_VERTICAL)
2572 MovDir[x][y] = (RND(2) ? MV_UP : MV_DOWN);
2573 else if (move_pattern & MV_ANY_DIRECTION)
2574 MovDir[x][y] = element_info[element].move_pattern;
2575 else if (move_pattern == MV_ALONG_LEFT_SIDE ||
2576 move_pattern == MV_ALONG_RIGHT_SIDE)
2578 /* use random direction as default start direction */
2579 if (game.engine_version >= VERSION_IDENT(3,1,0,0))
2580 MovDir[x][y] = 1 << RND(4);
2582 for (i = 0; i < NUM_DIRECTIONS; i++)
2584 int x1 = x + xy[i][0];
2585 int y1 = y + xy[i][1];
2587 if (!IN_LEV_FIELD(x1, y1) || !IS_FREE(x1, y1))
2589 if (move_pattern == MV_ALONG_RIGHT_SIDE)
2590 MovDir[x][y] = direction[0][i];
2592 MovDir[x][y] = direction[1][i];
2601 MovDir[x][y] = 1 << RND(4);
2603 if (element != EL_BUG &&
2604 element != EL_SPACESHIP &&
2605 element != EL_BD_BUTTERFLY &&
2606 element != EL_BD_FIREFLY)
2609 for (i = 0; i < NUM_DIRECTIONS; i++)
2611 int x1 = x + xy[i][0];
2612 int y1 = y + xy[i][1];
2614 if (!IN_LEV_FIELD(x1, y1) || !IS_FREE(x1, y1))
2616 if (element == EL_BUG || element == EL_BD_BUTTERFLY)
2618 MovDir[x][y] = direction[0][i];
2621 else if (element == EL_SPACESHIP || element == EL_BD_FIREFLY ||
2622 element == EL_SP_SNIKSNAK || element == EL_SP_ELECTRON)
2624 MovDir[x][y] = direction[1][i];
2633 GfxDir[x][y] = MovDir[x][y];
2636 void InitAmoebaNr(int x, int y)
2639 int group_nr = AmoebeNachbarNr(x, y);
2643 for (i = 1; i < MAX_NUM_AMOEBA; i++)
2645 if (AmoebaCnt[i] == 0)
2653 AmoebaNr[x][y] = group_nr;
2654 AmoebaCnt[group_nr]++;
2655 AmoebaCnt2[group_nr]++;
2658 static void PlayerWins(struct PlayerInfo *player)
2660 player->LevelSolved = TRUE;
2661 player->GameOver = TRUE;
2663 player->score_final = (level.game_engine_type == GAME_ENGINE_TYPE_EM ?
2664 level.native_em_level->lev->score : player->score);
2669 static int time, time_final;
2670 static int score, score_final;
2671 static int game_over_delay = 0;
2672 int game_over_delay_value = 50;
2674 if (!local_player->LevelSolved_GameEnd)
2678 /* do not start end game actions before the player stops moving (to exit) */
2679 if (local_player->MovPos)
2682 local_player->LevelSolved_GameEnd = TRUE;
2683 local_player->LevelSolved_SaveTape = tape.recording;
2684 local_player->LevelSolved_SaveScore = !tape.playing;
2686 if (tape.auto_play) /* tape might already be stopped here */
2687 tape.auto_play_level_solved = TRUE;
2693 game_over_delay = game_over_delay_value;
2695 time = time_final = (level.time == 0 ? TimePlayed : TimeLeft);
2696 score = score_final = local_player->score_final;
2701 score_final += TimeLeft * level.score[SC_TIME_BONUS];
2703 else if (level.time == 0 && TimePlayed < 999)
2706 score_final += (999 - TimePlayed) * level.score[SC_TIME_BONUS];
2709 local_player->score_final = score_final;
2711 if (level_editor_test_game)
2714 score = score_final;
2716 DrawGameValue_Time(time);
2717 DrawGameValue_Score(score);
2720 if (ExitX >= 0 && ExitY >= 0) /* local player has left the level */
2722 /* close exit door after last player */
2723 if (AllPlayersGone &&
2724 (Feld[ExitX][ExitY] == EL_EXIT_OPEN ||
2725 Feld[ExitX][ExitY] == EL_SP_EXIT_OPEN))
2727 int element = Feld[ExitX][ExitY];
2729 Feld[ExitX][ExitY] = (element == EL_EXIT_OPEN ? EL_EXIT_CLOSING :
2730 EL_SP_EXIT_CLOSING);
2732 PlayLevelSoundElementAction(ExitX, ExitY, element, ACTION_CLOSING);
2735 /* player disappears */
2736 DrawLevelField(ExitX, ExitY);
2739 for (i = 0; i < MAX_PLAYERS; i++)
2741 struct PlayerInfo *player = &stored_player[i];
2743 if (player->present)
2745 RemovePlayer(player);
2747 /* player disappears */
2748 DrawLevelField(player->jx, player->jy);
2752 PlaySound(SND_GAME_WINNING);
2755 if (game_over_delay > 0)
2762 if (time != time_final)
2764 int time_to_go = ABS(time_final - time);
2765 int time_count_dir = (time < time_final ? +1 : -1);
2766 int time_count_steps = (time_to_go > 100 && time_to_go % 10 == 0 ? 10 : 1);
2768 time += time_count_steps * time_count_dir;
2769 score += time_count_steps * level.score[SC_TIME_BONUS];
2771 DrawGameValue_Time(time);
2772 DrawGameValue_Score(score);
2774 if (time == time_final)
2775 StopSound(SND_GAME_LEVELTIME_BONUS);
2776 else if (setup.sound_loops)
2777 PlaySoundLoop(SND_GAME_LEVELTIME_BONUS);
2779 PlaySound(SND_GAME_LEVELTIME_BONUS);
2786 boolean raise_level = FALSE;
2788 CloseDoor(DOOR_CLOSE_1);
2790 if (local_player->LevelSolved_SaveTape)
2796 SaveTape(tape.level_nr); /* ask to save tape */
2799 if (level_editor_test_game)
2801 game_status = GAME_MODE_MAIN;
2808 if (!local_player->LevelSolved_SaveScore)
2810 FadeOut(REDRAW_FIELD);
2812 game_status = GAME_MODE_MAIN;
2814 DrawAndFadeInMainMenu(REDRAW_FIELD);
2819 if (level_nr == leveldir_current->handicap_level)
2821 leveldir_current->handicap_level++;
2822 SaveLevelSetup_SeriesInfo();
2825 if (level_nr < leveldir_current->last_level)
2826 raise_level = TRUE; /* advance to next level */
2828 if ((hi_pos = NewHiScore()) >= 0)
2830 game_status = GAME_MODE_SCORES;
2832 DrawHallOfFame(hi_pos);
2842 FadeOut(REDRAW_FIELD);
2844 game_status = GAME_MODE_MAIN;
2852 DrawAndFadeInMainMenu(REDRAW_FIELD);
2861 LoadScore(level_nr);
2863 if (strEqual(setup.player_name, EMPTY_PLAYER_NAME) ||
2864 local_player->score_final < highscore[MAX_SCORE_ENTRIES - 1].Score)
2867 for (k = 0; k < MAX_SCORE_ENTRIES; k++)
2869 if (local_player->score_final > highscore[k].Score)
2871 /* player has made it to the hall of fame */
2873 if (k < MAX_SCORE_ENTRIES - 1)
2875 int m = MAX_SCORE_ENTRIES - 1;
2878 for (l = k; l < MAX_SCORE_ENTRIES; l++)
2879 if (strEqual(setup.player_name, highscore[l].Name))
2881 if (m == k) /* player's new highscore overwrites his old one */
2885 for (l = m; l > k; l--)
2887 strcpy(highscore[l].Name, highscore[l - 1].Name);
2888 highscore[l].Score = highscore[l - 1].Score;
2895 strncpy(highscore[k].Name, setup.player_name, MAX_PLAYER_NAME_LEN);
2896 highscore[k].Name[MAX_PLAYER_NAME_LEN] = '\0';
2897 highscore[k].Score = local_player->score_final;
2903 else if (!strncmp(setup.player_name, highscore[k].Name,
2904 MAX_PLAYER_NAME_LEN))
2905 break; /* player already there with a higher score */
2911 SaveScore(level_nr);
2916 inline static int getElementMoveStepsize(int x, int y)
2918 int element = Feld[x][y];
2919 int direction = MovDir[x][y];
2920 int dx = (direction == MV_LEFT ? -1 : direction == MV_RIGHT ? +1 : 0);
2921 int dy = (direction == MV_UP ? -1 : direction == MV_DOWN ? +1 : 0);
2922 int horiz_move = (dx != 0);
2923 int sign = (horiz_move ? dx : dy);
2924 int step = sign * element_info[element].move_stepsize;
2926 /* special values for move stepsize for spring and things on conveyor belt */
2929 if (CAN_FALL(element) &&
2930 y < lev_fieldy - 1 && IS_BELT_ACTIVE(Feld[x][y + 1]))
2931 step = sign * MOVE_STEPSIZE_NORMAL / 2;
2932 else if (element == EL_SPRING)
2933 step = sign * MOVE_STEPSIZE_NORMAL * 2;
2939 void InitPlayerGfxAnimation(struct PlayerInfo *player, int action, int dir)
2941 if (player->GfxAction != action || player->GfxDir != dir)
2944 printf("Player frame reset! (%d => %d, %d => %d)\n",
2945 player->GfxAction, action, player->GfxDir, dir);
2948 player->GfxAction = action;
2949 player->GfxDir = dir;
2951 player->StepFrame = 0;
2955 #if USE_GFX_RESET_GFX_ANIMATION
2956 static void ResetGfxFrame(int x, int y, boolean redraw)
2958 int element = Feld[x][y];
2959 int graphic = el_act_dir2img(element, GfxAction[x][y], GfxDir[x][y]);
2960 int last_gfx_frame = GfxFrame[x][y];
2962 if (graphic_info[graphic].anim_global_sync)
2963 GfxFrame[x][y] = FrameCounter;
2964 else if (ANIM_MODE(graphic) == ANIM_CE_VALUE)
2965 GfxFrame[x][y] = CustomValue[x][y];
2966 else if (ANIM_MODE(graphic) == ANIM_CE_SCORE)
2967 GfxFrame[x][y] = element_info[element].collect_score;
2968 else if (ANIM_MODE(graphic) == ANIM_CE_DELAY)
2969 GfxFrame[x][y] = ChangeDelay[x][y];
2971 if (redraw && GfxFrame[x][y] != last_gfx_frame)
2972 DrawLevelGraphicAnimation(x, y, graphic);
2976 static void ResetGfxAnimation(int x, int y)
2978 GfxAction[x][y] = ACTION_DEFAULT;
2979 GfxDir[x][y] = MovDir[x][y];
2982 #if USE_GFX_RESET_GFX_ANIMATION
2983 ResetGfxFrame(x, y, FALSE);
2987 static void ResetRandomAnimationValue(int x, int y)
2989 GfxRandom[x][y] = INIT_GFX_RANDOM();
2992 void InitMovingField(int x, int y, int direction)
2994 int element = Feld[x][y];
2995 int dx = (direction == MV_LEFT ? -1 : direction == MV_RIGHT ? +1 : 0);
2996 int dy = (direction == MV_UP ? -1 : direction == MV_DOWN ? +1 : 0);
3000 if (!WasJustMoving[x][y] || direction != MovDir[x][y])
3001 ResetGfxAnimation(x, y);
3003 MovDir[x][y] = direction;
3004 GfxDir[x][y] = direction;
3005 GfxAction[x][y] = (direction == MV_DOWN && CAN_FALL(element) ?
3006 ACTION_FALLING : ACTION_MOVING);
3008 /* this is needed for CEs with property "can move" / "not moving" */
3010 if (getElementMoveStepsize(x, y) != 0) /* moving or being moved */
3012 if (Feld[newx][newy] == EL_EMPTY)
3013 Feld[newx][newy] = EL_BLOCKED;
3015 MovDir[newx][newy] = MovDir[x][y];
3017 #if USE_NEW_CUSTOM_VALUE
3018 CustomValue[newx][newy] = CustomValue[x][y];
3021 GfxFrame[newx][newy] = GfxFrame[x][y];
3022 GfxRandom[newx][newy] = GfxRandom[x][y];
3023 GfxAction[newx][newy] = GfxAction[x][y];
3024 GfxDir[newx][newy] = GfxDir[x][y];
3028 void Moving2Blocked(int x, int y, int *goes_to_x, int *goes_to_y)
3030 int direction = MovDir[x][y];
3031 int newx = x + (direction & MV_LEFT ? -1 : direction & MV_RIGHT ? +1 : 0);
3032 int newy = y + (direction & MV_UP ? -1 : direction & MV_DOWN ? +1 : 0);
3038 void Blocked2Moving(int x, int y, int *comes_from_x, int *comes_from_y)
3040 int oldx = x, oldy = y;
3041 int direction = MovDir[x][y];
3043 if (direction == MV_LEFT)
3045 else if (direction == MV_RIGHT)
3047 else if (direction == MV_UP)
3049 else if (direction == MV_DOWN)
3052 *comes_from_x = oldx;
3053 *comes_from_y = oldy;
3056 int MovingOrBlocked2Element(int x, int y)
3058 int element = Feld[x][y];
3060 if (element == EL_BLOCKED)
3064 Blocked2Moving(x, y, &oldx, &oldy);
3065 return Feld[oldx][oldy];
3071 static int MovingOrBlocked2ElementIfNotLeaving(int x, int y)
3073 /* like MovingOrBlocked2Element(), but if element is moving
3074 and (x,y) is the field the moving element is just leaving,
3075 return EL_BLOCKED instead of the element value */
3076 int element = Feld[x][y];
3078 if (IS_MOVING(x, y))
3080 if (element == EL_BLOCKED)
3084 Blocked2Moving(x, y, &oldx, &oldy);
3085 return Feld[oldx][oldy];
3094 static void RemoveField(int x, int y)
3096 Feld[x][y] = EL_EMPTY;
3102 #if USE_NEW_CUSTOM_VALUE
3103 CustomValue[x][y] = 0;
3107 ChangeDelay[x][y] = 0;
3108 ChangePage[x][y] = -1;
3109 Pushed[x][y] = FALSE;
3112 ExplodeField[x][y] = EX_TYPE_NONE;
3115 GfxElement[x][y] = EL_UNDEFINED;
3116 GfxAction[x][y] = ACTION_DEFAULT;
3117 GfxDir[x][y] = MV_NONE;
3120 void RemoveMovingField(int x, int y)
3122 int oldx = x, oldy = y, newx = x, newy = y;
3123 int element = Feld[x][y];
3124 int next_element = EL_UNDEFINED;
3126 if (element != EL_BLOCKED && !IS_MOVING(x, y))
3129 if (IS_MOVING(x, y))
3131 Moving2Blocked(x, y, &newx, &newy);
3133 if (Feld[newx][newy] != EL_BLOCKED)
3135 /* element is moving, but target field is not free (blocked), but
3136 already occupied by something different (example: acid pool);
3137 in this case, only remove the moving field, but not the target */
3139 RemoveField(oldx, oldy);
3141 Store[oldx][oldy] = Store2[oldx][oldy] = 0;
3143 DrawLevelField(oldx, oldy);
3148 else if (element == EL_BLOCKED)
3150 Blocked2Moving(x, y, &oldx, &oldy);
3151 if (!IS_MOVING(oldx, oldy))
3155 if (element == EL_BLOCKED &&
3156 (Feld[oldx][oldy] == EL_QUICKSAND_EMPTYING ||
3157 Feld[oldx][oldy] == EL_MAGIC_WALL_EMPTYING ||
3158 Feld[oldx][oldy] == EL_BD_MAGIC_WALL_EMPTYING ||
3159 Feld[oldx][oldy] == EL_AMOEBA_DROPPING))
3160 next_element = get_next_element(Feld[oldx][oldy]);
3162 RemoveField(oldx, oldy);
3163 RemoveField(newx, newy);
3165 Store[oldx][oldy] = Store2[oldx][oldy] = 0;
3167 if (next_element != EL_UNDEFINED)
3168 Feld[oldx][oldy] = next_element;
3170 DrawLevelField(oldx, oldy);
3171 DrawLevelField(newx, newy);
3174 void DrawDynamite(int x, int y)
3176 int sx = SCREENX(x), sy = SCREENY(y);
3177 int graphic = el2img(Feld[x][y]);
3180 if (!IN_SCR_FIELD(sx, sy) || IS_PLAYER(x, y))
3183 if (IS_WALKABLE_INSIDE(Back[x][y]))
3187 DrawGraphic(sx, sy, el2img(Back[x][y]), 0);
3188 else if (Store[x][y])
3189 DrawGraphic(sx, sy, el2img(Store[x][y]), 0);
3191 frame = getGraphicAnimationFrame(graphic, GfxFrame[x][y]);
3193 if (Back[x][y] || Store[x][y])
3194 DrawGraphicThruMask(sx, sy, graphic, frame);
3196 DrawGraphic(sx, sy, graphic, frame);
3199 void CheckDynamite(int x, int y)
3201 if (MovDelay[x][y] != 0) /* dynamite is still waiting to explode */
3205 if (MovDelay[x][y] != 0)
3208 PlayLevelSoundActionIfLoop(x, y, ACTION_ACTIVE);
3214 StopLevelSoundActionIfLoop(x, y, ACTION_ACTIVE);
3219 static void setMinimalPlayerBoundaries(int *sx1, int *sy1, int *sx2, int *sy2)
3221 boolean num_checked_players = 0;
3224 for (i = 0; i < MAX_PLAYERS; i++)
3226 if (stored_player[i].active)
3228 int sx = stored_player[i].jx;
3229 int sy = stored_player[i].jy;
3231 if (num_checked_players == 0)
3238 *sx1 = MIN(*sx1, sx);
3239 *sy1 = MIN(*sy1, sy);
3240 *sx2 = MAX(*sx2, sx);
3241 *sy2 = MAX(*sy2, sy);
3244 num_checked_players++;
3249 static boolean checkIfAllPlayersFitToScreen_RND()
3251 int sx1 = 0, sy1 = 0, sx2 = 0, sy2 = 0;
3253 setMinimalPlayerBoundaries(&sx1, &sy1, &sx2, &sy2);
3255 return (sx2 - sx1 < SCR_FIELDX &&
3256 sy2 - sy1 < SCR_FIELDY);
3259 static void setScreenCenteredToAllPlayers(int *sx, int *sy)
3261 int sx1 = scroll_x, sy1 = scroll_y, sx2 = scroll_x, sy2 = scroll_y;
3263 setMinimalPlayerBoundaries(&sx1, &sy1, &sx2, &sy2);
3265 *sx = (sx1 + sx2) / 2;
3266 *sy = (sy1 + sy2) / 2;
3269 void DrawRelocateScreen(int x, int y, int move_dir, boolean center_screen,
3270 boolean quick_relocation)
3272 boolean ffwd_delay = (tape.playing && tape.fast_forward);
3273 boolean no_delay = (tape.warp_forward);
3274 int frame_delay_value = (ffwd_delay ? FfwdFrameDelay : GameFrameDelay);
3275 int wait_delay_value = (no_delay ? 0 : frame_delay_value);
3277 if (quick_relocation)
3279 int offset = (setup.scroll_delay ? 3 : 0);
3281 if (!IN_VIS_FIELD(SCREENX(x), SCREENY(y)) || center_screen)
3283 scroll_x = (x < SBX_Left + MIDPOSX ? SBX_Left :
3284 x > SBX_Right + MIDPOSX ? SBX_Right :
3287 scroll_y = (y < SBY_Upper + MIDPOSY ? SBY_Upper :
3288 y > SBY_Lower + MIDPOSY ? SBY_Lower :
3293 if ((move_dir == MV_LEFT && scroll_x > x - MIDPOSX + offset) ||
3294 (move_dir == MV_RIGHT && scroll_x < x - MIDPOSX - offset))
3295 scroll_x = x - MIDPOSX + (scroll_x < x - MIDPOSX ? -offset : +offset);
3297 if ((move_dir == MV_UP && scroll_y > y - MIDPOSY + offset) ||
3298 (move_dir == MV_DOWN && scroll_y < y - MIDPOSY - offset))
3299 scroll_y = y - MIDPOSY + (scroll_y < y - MIDPOSY ? -offset : +offset);
3301 /* don't scroll over playfield boundaries */
3302 if (scroll_x < SBX_Left || scroll_x > SBX_Right)
3303 scroll_x = (scroll_x < SBX_Left ? SBX_Left : SBX_Right);
3305 /* don't scroll over playfield boundaries */
3306 if (scroll_y < SBY_Upper || scroll_y > SBY_Lower)
3307 scroll_y = (scroll_y < SBY_Upper ? SBY_Upper : SBY_Lower);
3310 RedrawPlayfield(TRUE, 0,0,0,0);
3314 int scroll_xx = (x < SBX_Left + MIDPOSX ? SBX_Left :
3315 x > SBX_Right + MIDPOSX ? SBX_Right :
3318 int scroll_yy = (y < SBY_Upper + MIDPOSY ? SBY_Upper :
3319 y > SBY_Lower + MIDPOSY ? SBY_Lower :
3322 ScrollScreen(NULL, SCROLL_GO_ON); /* scroll last frame to full tile */
3324 while (scroll_x != scroll_xx || scroll_y != scroll_yy)
3327 int fx = FX, fy = FY;
3329 dx = (scroll_xx < scroll_x ? +1 : scroll_xx > scroll_x ? -1 : 0);
3330 dy = (scroll_yy < scroll_y ? +1 : scroll_yy > scroll_y ? -1 : 0);
3332 if (dx == 0 && dy == 0) /* no scrolling needed at all */
3338 fx += dx * TILEX / 2;
3339 fy += dy * TILEY / 2;
3341 ScrollLevel(dx, dy);
3344 /* scroll in two steps of half tile size to make things smoother */
3345 BlitBitmap(drawto_field, window, fx, fy, SXSIZE, SYSIZE, SX, SY);
3347 Delay(wait_delay_value);
3349 /* scroll second step to align at full tile size */
3351 Delay(wait_delay_value);
3356 Delay(wait_delay_value);
3360 void RelocatePlayer(int jx, int jy, int el_player_raw)
3362 int el_player = GET_PLAYER_ELEMENT(el_player_raw);
3363 int player_nr = GET_PLAYER_NR(el_player);
3364 struct PlayerInfo *player = &stored_player[player_nr];
3365 boolean ffwd_delay = (tape.playing && tape.fast_forward);
3366 boolean no_delay = (tape.warp_forward);
3367 int frame_delay_value = (ffwd_delay ? FfwdFrameDelay : GameFrameDelay);
3368 int wait_delay_value = (no_delay ? 0 : frame_delay_value);
3369 int old_jx = player->jx;
3370 int old_jy = player->jy;
3371 int old_element = Feld[old_jx][old_jy];
3372 int element = Feld[jx][jy];
3373 boolean player_relocated = (old_jx != jx || old_jy != jy);
3375 int move_dir_horiz = (jx < old_jx ? MV_LEFT : jx > old_jx ? MV_RIGHT : 0);
3376 int move_dir_vert = (jy < old_jy ? MV_UP : jy > old_jy ? MV_DOWN : 0);
3377 int enter_side_horiz = MV_DIR_OPPOSITE(move_dir_horiz);
3378 int enter_side_vert = MV_DIR_OPPOSITE(move_dir_vert);
3379 int leave_side_horiz = move_dir_horiz;
3380 int leave_side_vert = move_dir_vert;
3381 int enter_side = enter_side_horiz | enter_side_vert;
3382 int leave_side = leave_side_horiz | leave_side_vert;
3384 if (player->GameOver) /* do not reanimate dead player */
3387 if (!player_relocated) /* no need to relocate the player */
3390 if (IS_PLAYER(jx, jy)) /* player already placed at new position */
3392 RemoveField(jx, jy); /* temporarily remove newly placed player */
3393 DrawLevelField(jx, jy);
3396 if (player->present)
3398 while (player->MovPos)
3400 ScrollPlayer(player, SCROLL_GO_ON);
3401 ScrollScreen(NULL, SCROLL_GO_ON);
3403 AdvanceFrameAndPlayerCounters(player->index_nr);
3408 Delay(wait_delay_value);
3411 DrawPlayer(player); /* needed here only to cleanup last field */
3412 DrawLevelField(player->jx, player->jy); /* remove player graphic */
3414 player->is_moving = FALSE;
3417 if (IS_CUSTOM_ELEMENT(old_element))
3418 CheckElementChangeByPlayer(old_jx, old_jy, old_element,
3420 player->index_bit, leave_side);
3422 CheckTriggeredElementChangeByPlayer(old_jx, old_jy, old_element,
3424 player->index_bit, leave_side);
3426 Feld[jx][jy] = el_player;
3427 InitPlayerField(jx, jy, el_player, TRUE);
3429 if (!ELEM_IS_PLAYER(element)) /* player may be set on walkable element */
3431 Feld[jx][jy] = element;
3432 InitField(jx, jy, FALSE);
3435 /* only visually relocate centered player */
3436 DrawRelocateScreen(player->jx, player->jy, player->MovDir, FALSE,
3437 level.instant_relocation);
3439 TestIfPlayerTouchesBadThing(jx, jy);
3440 TestIfPlayerTouchesCustomElement(jx, jy);
3442 if (IS_CUSTOM_ELEMENT(element))
3443 CheckElementChangeByPlayer(jx, jy, element, CE_ENTERED_BY_PLAYER,
3444 player->index_bit, enter_side);
3446 CheckTriggeredElementChangeByPlayer(jx, jy, element, CE_PLAYER_ENTERS_X,
3447 player->index_bit, enter_side);
3450 void Explode(int ex, int ey, int phase, int mode)
3456 /* !!! eliminate this variable !!! */
3457 int delay = (game.emulation == EMU_SUPAPLEX ? 3 : 2);
3459 if (game.explosions_delayed)
3461 ExplodeField[ex][ey] = mode;
3465 if (phase == EX_PHASE_START) /* initialize 'Store[][]' field */
3467 int center_element = Feld[ex][ey];
3468 int artwork_element, explosion_element; /* set these values later */
3471 /* --- This is only really needed (and now handled) in "Impact()". --- */
3472 /* do not explode moving elements that left the explode field in time */
3473 if (game.engine_version >= VERSION_IDENT(2,2,0,7) &&
3474 center_element == EL_EMPTY &&
3475 (mode == EX_TYPE_NORMAL || mode == EX_TYPE_CENTER))
3480 /* !!! at this place, the center element may be EL_BLOCKED !!! */
3481 if (mode == EX_TYPE_NORMAL ||
3482 mode == EX_TYPE_CENTER ||
3483 mode == EX_TYPE_CROSS)
3484 PlayLevelSoundElementAction(ex, ey, artwork_element, ACTION_EXPLODING);
3487 /* remove things displayed in background while burning dynamite */
3488 if (Back[ex][ey] != EL_EMPTY && !IS_INDESTRUCTIBLE(Back[ex][ey]))
3491 if (IS_MOVING(ex, ey) || IS_BLOCKED(ex, ey))
3493 /* put moving element to center field (and let it explode there) */
3494 center_element = MovingOrBlocked2Element(ex, ey);
3495 RemoveMovingField(ex, ey);
3496 Feld[ex][ey] = center_element;
3499 /* now "center_element" is finally determined -- set related values now */
3500 artwork_element = center_element; /* for custom player artwork */
3501 explosion_element = center_element; /* for custom player artwork */
3503 if (IS_PLAYER(ex, ey))
3505 int player_nr = GET_PLAYER_NR(StorePlayer[ex][ey]);
3507 artwork_element = stored_player[player_nr].artwork_element;
3509 if (level.use_explosion_element[player_nr])
3511 explosion_element = level.explosion_element[player_nr];
3512 artwork_element = explosion_element;
3517 if (mode == EX_TYPE_NORMAL ||
3518 mode == EX_TYPE_CENTER ||
3519 mode == EX_TYPE_CROSS)
3520 PlayLevelSoundElementAction(ex, ey, artwork_element, ACTION_EXPLODING);
3523 last_phase = element_info[explosion_element].explosion_delay + 1;
3525 for (y = ey - 1; y <= ey + 1; y++) for (x = ex - 1; x <= ex + 1; x++)
3527 int xx = x - ex + 1;
3528 int yy = y - ey + 1;
3531 if (!IN_LEV_FIELD(x, y) ||
3532 (mode & EX_TYPE_SINGLE_TILE && (x != ex || y != ey)) ||
3533 (mode == EX_TYPE_CROSS && (x != ex && y != ey)))
3536 element = Feld[x][y];
3538 if (IS_MOVING(x, y) || IS_BLOCKED(x, y))
3540 element = MovingOrBlocked2Element(x, y);
3542 if (!IS_EXPLOSION_PROOF(element))
3543 RemoveMovingField(x, y);
3546 /* indestructible elements can only explode in center (but not flames) */
3547 if ((IS_EXPLOSION_PROOF(element) && (x != ex || y != ey ||
3548 mode == EX_TYPE_BORDER)) ||
3549 element == EL_FLAMES)
3552 /* no idea why this was changed from 3.0.8 to 3.1.0 -- this causes buggy
3553 behaviour, for example when touching a yamyam that explodes to rocks
3554 with active deadly shield, a rock is created under the player !!! */
3555 /* (case 1 (surely buggy): >= 3.1.0, case 2 (maybe buggy): <= 3.0.8) */
3557 if (IS_PLAYER(x, y) && SHIELD_ON(PLAYERINFO(x, y)) &&
3558 (game.engine_version < VERSION_IDENT(3,1,0,0) ||
3559 (x == ex && y == ey && mode != EX_TYPE_BORDER)))
3561 if (IS_PLAYER(x, y) && SHIELD_ON(PLAYERINFO(x, y)))
3564 if (IS_ACTIVE_BOMB(element))
3566 /* re-activate things under the bomb like gate or penguin */
3567 Feld[x][y] = (Back[x][y] ? Back[x][y] : EL_EMPTY);
3574 /* save walkable background elements while explosion on same tile */
3575 if (IS_WALKABLE(element) && IS_INDESTRUCTIBLE(element) &&
3576 (x != ex || y != ey || mode == EX_TYPE_BORDER))
3577 Back[x][y] = element;
3579 /* ignite explodable elements reached by other explosion */
3580 if (element == EL_EXPLOSION)
3581 element = Store2[x][y];
3583 if (AmoebaNr[x][y] &&
3584 (element == EL_AMOEBA_FULL ||
3585 element == EL_BD_AMOEBA ||
3586 element == EL_AMOEBA_GROWING))
3588 AmoebaCnt[AmoebaNr[x][y]]--;
3589 AmoebaCnt2[AmoebaNr[x][y]]--;
3594 if (IS_PLAYER(ex, ey) && !PLAYER_EXPLOSION_PROTECTED(ex, ey))
3596 int player_nr = StorePlayer[ex][ey] - EL_PLAYER_1;
3598 Store[x][y] = EL_PLAYER_IS_EXPLODING_1 + player_nr;
3600 if (PLAYERINFO(ex, ey)->use_murphy)
3601 Store[x][y] = EL_EMPTY;
3604 /* !!! check this case -- currently needed for rnd_rado_negundo_v,
3605 !!! levels 015 018 019 020 021 022 023 026 027 028 !!! */
3606 else if (ELEM_IS_PLAYER(center_element))
3607 Store[x][y] = EL_EMPTY;
3608 else if (center_element == EL_YAMYAM)
3609 Store[x][y] = level.yamyam_content[game.yamyam_content_nr].e[xx][yy];
3610 else if (element_info[center_element].content.e[xx][yy] != EL_EMPTY)
3611 Store[x][y] = element_info[center_element].content.e[xx][yy];
3613 /* needed because EL_BD_BUTTERFLY is not defined as "CAN_EXPLODE"
3614 (killing EL_BD_BUTTERFLY with dynamite would result in BD diamond
3615 otherwise) -- FIX THIS !!! */
3616 else if (!CAN_EXPLODE(element) && element != EL_BD_BUTTERFLY)
3617 Store[x][y] = element_info[element].content.e[1][1];
3619 else if (!CAN_EXPLODE(element))
3620 Store[x][y] = element_info[element].content.e[1][1];
3623 Store[x][y] = EL_EMPTY;
3625 if (x != ex || y != ey || mode == EX_TYPE_BORDER ||
3626 center_element == EL_AMOEBA_TO_DIAMOND)
3627 Store2[x][y] = element;
3629 Feld[x][y] = EL_EXPLOSION;
3630 GfxElement[x][y] = artwork_element;
3632 ExplodePhase[x][y] = 1;
3633 ExplodeDelay[x][y] = last_phase;
3638 if (center_element == EL_YAMYAM)
3639 game.yamyam_content_nr =
3640 (game.yamyam_content_nr + 1) % level.num_yamyam_contents;
3652 GfxFrame[x][y] = 0; /* restart explosion animation */
3654 last_phase = ExplodeDelay[x][y];
3656 ExplodePhase[x][y] = (phase < last_phase ? phase + 1 : 0);
3660 /* activate this even in non-DEBUG version until cause for crash in
3661 getGraphicAnimationFrame() (see below) is found and eliminated */
3667 /* this can happen if the player leaves an explosion just in time */
3668 if (GfxElement[x][y] == EL_UNDEFINED)
3669 GfxElement[x][y] = EL_EMPTY;
3671 if (GfxElement[x][y] == EL_UNDEFINED)
3674 printf("Explode(): x = %d, y = %d: GfxElement == EL_UNDEFINED\n", x, y);
3675 printf("Explode(): This should never happen!\n");
3678 GfxElement[x][y] = EL_EMPTY;
3684 border_element = Store2[x][y];
3685 if (IS_PLAYER(x, y) && !PLAYER_EXPLOSION_PROTECTED(x, y))
3686 border_element = StorePlayer[x][y];
3688 if (phase == element_info[border_element].ignition_delay ||
3689 phase == last_phase)
3691 boolean border_explosion = FALSE;
3693 if (IS_PLAYER(x, y) && PLAYERINFO(x, y)->present &&
3694 !PLAYER_EXPLOSION_PROTECTED(x, y))
3696 KillPlayerUnlessExplosionProtected(x, y);
3697 border_explosion = TRUE;
3699 else if (CAN_EXPLODE_BY_EXPLOSION(border_element))
3701 Feld[x][y] = Store2[x][y];
3704 border_explosion = TRUE;
3706 else if (border_element == EL_AMOEBA_TO_DIAMOND)
3708 AmoebeUmwandeln(x, y);
3710 border_explosion = TRUE;
3713 /* if an element just explodes due to another explosion (chain-reaction),
3714 do not immediately end the new explosion when it was the last frame of
3715 the explosion (as it would be done in the following "if"-statement!) */
3716 if (border_explosion && phase == last_phase)
3720 if (phase == last_phase)
3724 element = Feld[x][y] = Store[x][y];
3725 Store[x][y] = Store2[x][y] = 0;
3726 GfxElement[x][y] = EL_UNDEFINED;
3728 /* player can escape from explosions and might therefore be still alive */
3729 if (element >= EL_PLAYER_IS_EXPLODING_1 &&
3730 element <= EL_PLAYER_IS_EXPLODING_4)
3732 int player_nr = element - EL_PLAYER_IS_EXPLODING_1;
3733 int explosion_element = EL_PLAYER_1 + player_nr;
3734 int xx = MIN(MAX(0, x - stored_player[player_nr].jx + 1), 2);
3735 int yy = MIN(MAX(0, y - stored_player[player_nr].jy + 1), 2);
3737 if (level.use_explosion_element[player_nr])
3738 explosion_element = level.explosion_element[player_nr];
3740 Feld[x][y] = (stored_player[player_nr].active ? EL_EMPTY :
3741 element_info[explosion_element].content.e[xx][yy]);
3744 /* restore probably existing indestructible background element */
3745 if (Back[x][y] && IS_INDESTRUCTIBLE(Back[x][y]))
3746 element = Feld[x][y] = Back[x][y];
3749 MovDir[x][y] = MovPos[x][y] = MovDelay[x][y] = 0;
3750 GfxDir[x][y] = MV_NONE;
3751 ChangeDelay[x][y] = 0;
3752 ChangePage[x][y] = -1;
3754 #if USE_NEW_CUSTOM_VALUE
3755 CustomValue[x][y] = 0;
3758 InitField_WithBug2(x, y, FALSE);
3760 DrawLevelField(x, y);
3762 TestIfElementTouchesCustomElement(x, y);
3764 if (GFX_CRUMBLED(element))
3765 DrawLevelFieldCrumbledSandNeighbours(x, y);
3767 if (IS_PLAYER(x, y) && !PLAYERINFO(x, y)->present)
3768 StorePlayer[x][y] = 0;
3770 if (ELEM_IS_PLAYER(element))
3771 RelocatePlayer(x, y, element);
3773 else if (IN_SCR_FIELD(SCREENX(x), SCREENY(y)))
3775 int graphic = el_act2img(GfxElement[x][y], ACTION_EXPLODING);
3776 int frame = getGraphicAnimationFrame(graphic, GfxFrame[x][y]);
3779 DrawLevelFieldCrumbledSand(x, y);
3781 if (IS_WALKABLE_OVER(Back[x][y]) && Back[x][y] != EL_EMPTY)
3783 DrawLevelElement(x, y, Back[x][y]);
3784 DrawGraphicThruMask(SCREENX(x), SCREENY(y), graphic, frame);
3786 else if (IS_WALKABLE_UNDER(Back[x][y]))
3788 DrawGraphic(SCREENX(x), SCREENY(y), graphic, frame);
3789 DrawLevelElementThruMask(x, y, Back[x][y]);
3791 else if (!IS_WALKABLE_INSIDE(Back[x][y]))
3792 DrawGraphic(SCREENX(x), SCREENY(y), graphic, frame);
3796 void DynaExplode(int ex, int ey)
3799 int dynabomb_element = Feld[ex][ey];
3800 int dynabomb_size = 1;
3801 boolean dynabomb_xl = FALSE;
3802 struct PlayerInfo *player;
3803 static int xy[4][2] =
3811 if (IS_ACTIVE_BOMB(dynabomb_element))
3813 player = &stored_player[dynabomb_element - EL_DYNABOMB_PLAYER_1_ACTIVE];
3814 dynabomb_size = player->dynabomb_size;
3815 dynabomb_xl = player->dynabomb_xl;
3816 player->dynabombs_left++;
3819 Explode(ex, ey, EX_PHASE_START, EX_TYPE_CENTER);
3821 for (i = 0; i < NUM_DIRECTIONS; i++)
3823 for (j = 1; j <= dynabomb_size; j++)
3825 int x = ex + j * xy[i][0];
3826 int y = ey + j * xy[i][1];
3829 if (!IN_LEV_FIELD(x, y) || IS_INDESTRUCTIBLE(Feld[x][y]))
3832 element = Feld[x][y];
3834 /* do not restart explosions of fields with active bombs */
3835 if (element == EL_EXPLOSION && IS_ACTIVE_BOMB(Store2[x][y]))
3838 Explode(x, y, EX_PHASE_START, EX_TYPE_BORDER);
3840 if (element != EL_EMPTY && element != EL_EXPLOSION &&
3841 !IS_DIGGABLE(element) && !dynabomb_xl)
3847 void Bang(int x, int y)
3849 int element = MovingOrBlocked2Element(x, y);
3850 int explosion_type = EX_TYPE_NORMAL;
3852 if (IS_PLAYER(x, y) && !PLAYER_EXPLOSION_PROTECTED(x, y))
3854 struct PlayerInfo *player = PLAYERINFO(x, y);
3856 element = Feld[x][y] = (player->use_murphy ? EL_SP_MURPHY :
3857 player->element_nr);
3859 if (level.use_explosion_element[player->index_nr])
3861 int explosion_element = level.explosion_element[player->index_nr];
3863 if (element_info[explosion_element].explosion_type == EXPLODES_CROSS)
3864 explosion_type = EX_TYPE_CROSS;
3865 else if (element_info[explosion_element].explosion_type == EXPLODES_1X1)
3866 explosion_type = EX_TYPE_CENTER;
3874 case EL_BD_BUTTERFLY:
3877 case EL_DARK_YAMYAM:
3881 RaiseScoreElement(element);
3884 case EL_DYNABOMB_PLAYER_1_ACTIVE:
3885 case EL_DYNABOMB_PLAYER_2_ACTIVE:
3886 case EL_DYNABOMB_PLAYER_3_ACTIVE:
3887 case EL_DYNABOMB_PLAYER_4_ACTIVE:
3888 case EL_DYNABOMB_INCREASE_NUMBER:
3889 case EL_DYNABOMB_INCREASE_SIZE:
3890 case EL_DYNABOMB_INCREASE_POWER:
3891 explosion_type = EX_TYPE_DYNA;
3896 case EL_LAMP_ACTIVE:
3897 case EL_AMOEBA_TO_DIAMOND:
3898 if (!IS_PLAYER(x, y)) /* penguin and player may be at same field */
3899 explosion_type = EX_TYPE_CENTER;
3903 if (element_info[element].explosion_type == EXPLODES_CROSS)
3904 explosion_type = EX_TYPE_CROSS;
3905 else if (element_info[element].explosion_type == EXPLODES_1X1)
3906 explosion_type = EX_TYPE_CENTER;
3910 if (explosion_type == EX_TYPE_DYNA)
3913 Explode(x, y, EX_PHASE_START, explosion_type);
3915 CheckTriggeredElementChange(x, y, element, CE_EXPLOSION_OF_X);
3918 void SplashAcid(int x, int y)
3920 if (IN_LEV_FIELD(x - 1, y - 1) && IS_FREE(x - 1, y - 1) &&
3921 (!IN_LEV_FIELD(x - 1, y - 2) ||
3922 !CAN_FALL(MovingOrBlocked2Element(x - 1, y - 2))))
3923 Feld[x - 1][y - 1] = EL_ACID_SPLASH_LEFT;
3925 if (IN_LEV_FIELD(x + 1, y - 1) && IS_FREE(x + 1, y - 1) &&
3926 (!IN_LEV_FIELD(x + 1, y - 2) ||
3927 !CAN_FALL(MovingOrBlocked2Element(x + 1, y - 2))))
3928 Feld[x + 1][y - 1] = EL_ACID_SPLASH_RIGHT;
3930 PlayLevelSound(x, y, SND_ACID_SPLASHING);
3933 static void InitBeltMovement()
3935 static int belt_base_element[4] =
3937 EL_CONVEYOR_BELT_1_LEFT,
3938 EL_CONVEYOR_BELT_2_LEFT,
3939 EL_CONVEYOR_BELT_3_LEFT,
3940 EL_CONVEYOR_BELT_4_LEFT
3942 static int belt_base_active_element[4] =
3944 EL_CONVEYOR_BELT_1_LEFT_ACTIVE,
3945 EL_CONVEYOR_BELT_2_LEFT_ACTIVE,
3946 EL_CONVEYOR_BELT_3_LEFT_ACTIVE,
3947 EL_CONVEYOR_BELT_4_LEFT_ACTIVE
3952 /* set frame order for belt animation graphic according to belt direction */
3953 for (i = 0; i < NUM_BELTS; i++)
3957 for (j = 0; j < NUM_BELT_PARTS; j++)
3959 int element = belt_base_active_element[belt_nr] + j;
3960 int graphic = el2img(element);
3962 if (game.belt_dir[i] == MV_LEFT)
3963 graphic_info[graphic].anim_mode &= ~ANIM_REVERSE;
3965 graphic_info[graphic].anim_mode |= ANIM_REVERSE;
3969 SCAN_PLAYFIELD(x, y)
3971 int element = Feld[x][y];
3973 for (i = 0; i < NUM_BELTS; i++)
3975 if (IS_BELT(element) && game.belt_dir[i] != MV_NONE)
3977 int e_belt_nr = getBeltNrFromBeltElement(element);
3980 if (e_belt_nr == belt_nr)
3982 int belt_part = Feld[x][y] - belt_base_element[belt_nr];
3984 Feld[x][y] = belt_base_active_element[belt_nr] + belt_part;
3991 static void ToggleBeltSwitch(int x, int y)
3993 static int belt_base_element[4] =
3995 EL_CONVEYOR_BELT_1_LEFT,
3996 EL_CONVEYOR_BELT_2_LEFT,
3997 EL_CONVEYOR_BELT_3_LEFT,
3998 EL_CONVEYOR_BELT_4_LEFT
4000 static int belt_base_active_element[4] =
4002 EL_CONVEYOR_BELT_1_LEFT_ACTIVE,
4003 EL_CONVEYOR_BELT_2_LEFT_ACTIVE,
4004 EL_CONVEYOR_BELT_3_LEFT_ACTIVE,
4005 EL_CONVEYOR_BELT_4_LEFT_ACTIVE
4007 static int belt_base_switch_element[4] =
4009 EL_CONVEYOR_BELT_1_SWITCH_LEFT,
4010 EL_CONVEYOR_BELT_2_SWITCH_LEFT,
4011 EL_CONVEYOR_BELT_3_SWITCH_LEFT,
4012 EL_CONVEYOR_BELT_4_SWITCH_LEFT
4014 static int belt_move_dir[4] =
4022 int element = Feld[x][y];
4023 int belt_nr = getBeltNrFromBeltSwitchElement(element);
4024 int belt_dir_nr = (game.belt_dir_nr[belt_nr] + 1) % 4;
4025 int belt_dir = belt_move_dir[belt_dir_nr];
4028 if (!IS_BELT_SWITCH(element))
4031 game.belt_dir_nr[belt_nr] = belt_dir_nr;
4032 game.belt_dir[belt_nr] = belt_dir;
4034 if (belt_dir_nr == 3)
4037 /* set frame order for belt animation graphic according to belt direction */
4038 for (i = 0; i < NUM_BELT_PARTS; i++)
4040 int element = belt_base_active_element[belt_nr] + i;
4041 int graphic = el2img(element);
4043 if (belt_dir == MV_LEFT)
4044 graphic_info[graphic].anim_mode &= ~ANIM_REVERSE;
4046 graphic_info[graphic].anim_mode |= ANIM_REVERSE;
4049 SCAN_PLAYFIELD(xx, yy)
4051 int element = Feld[xx][yy];
4053 if (IS_BELT_SWITCH(element))
4055 int e_belt_nr = getBeltNrFromBeltSwitchElement(element);
4057 if (e_belt_nr == belt_nr)
4059 Feld[xx][yy] = belt_base_switch_element[belt_nr] + belt_dir_nr;
4060 DrawLevelField(xx, yy);
4063 else if (IS_BELT(element) && belt_dir != MV_NONE)
4065 int e_belt_nr = getBeltNrFromBeltElement(element);
4067 if (e_belt_nr == belt_nr)
4069 int belt_part = Feld[xx][yy] - belt_base_element[belt_nr];
4071 Feld[xx][yy] = belt_base_active_element[belt_nr] + belt_part;
4072 DrawLevelField(xx, yy);
4075 else if (IS_BELT_ACTIVE(element) && belt_dir == MV_NONE)
4077 int e_belt_nr = getBeltNrFromBeltActiveElement(element);
4079 if (e_belt_nr == belt_nr)
4081 int belt_part = Feld[xx][yy] - belt_base_active_element[belt_nr];
4083 Feld[xx][yy] = belt_base_element[belt_nr] + belt_part;
4084 DrawLevelField(xx, yy);
4090 static void ToggleSwitchgateSwitch(int x, int y)
4094 game.switchgate_pos = !game.switchgate_pos;
4096 SCAN_PLAYFIELD(xx, yy)
4098 int element = Feld[xx][yy];
4100 #if !USE_BOTH_SWITCHGATE_SWITCHES
4101 if (element == EL_SWITCHGATE_SWITCH_UP ||
4102 element == EL_SWITCHGATE_SWITCH_DOWN)
4104 Feld[xx][yy] = EL_SWITCHGATE_SWITCH_UP + game.switchgate_pos;
4105 DrawLevelField(xx, yy);
4108 if (element == EL_SWITCHGATE_SWITCH_UP)
4110 Feld[xx][yy] = EL_SWITCHGATE_SWITCH_DOWN;
4111 DrawLevelField(xx, yy);
4113 else if (element == EL_SWITCHGATE_SWITCH_DOWN)
4115 Feld[xx][yy] = EL_SWITCHGATE_SWITCH_UP;
4116 DrawLevelField(xx, yy);
4119 else if (element == EL_SWITCHGATE_OPEN ||
4120 element == EL_SWITCHGATE_OPENING)
4122 Feld[xx][yy] = EL_SWITCHGATE_CLOSING;
4124 PlayLevelSoundAction(xx, yy, ACTION_CLOSING);
4126 else if (element == EL_SWITCHGATE_CLOSED ||
4127 element == EL_SWITCHGATE_CLOSING)
4129 Feld[xx][yy] = EL_SWITCHGATE_OPENING;
4131 PlayLevelSoundAction(xx, yy, ACTION_OPENING);
4136 static int getInvisibleActiveFromInvisibleElement(int element)
4138 return (element == EL_INVISIBLE_STEELWALL ? EL_INVISIBLE_STEELWALL_ACTIVE :
4139 element == EL_INVISIBLE_WALL ? EL_INVISIBLE_WALL_ACTIVE :
4140 element == EL_INVISIBLE_SAND ? EL_INVISIBLE_SAND_ACTIVE :
4144 static int getInvisibleFromInvisibleActiveElement(int element)
4146 return (element == EL_INVISIBLE_STEELWALL_ACTIVE ? EL_INVISIBLE_STEELWALL :
4147 element == EL_INVISIBLE_WALL_ACTIVE ? EL_INVISIBLE_WALL :
4148 element == EL_INVISIBLE_SAND_ACTIVE ? EL_INVISIBLE_SAND :
4152 static void RedrawAllLightSwitchesAndInvisibleElements()
4156 SCAN_PLAYFIELD(x, y)
4158 int element = Feld[x][y];
4160 if (element == EL_LIGHT_SWITCH &&
4161 game.light_time_left > 0)
4163 Feld[x][y] = EL_LIGHT_SWITCH_ACTIVE;
4164 DrawLevelField(x, y);
4166 else if (element == EL_LIGHT_SWITCH_ACTIVE &&
4167 game.light_time_left == 0)
4169 Feld[x][y] = EL_LIGHT_SWITCH;
4170 DrawLevelField(x, y);
4172 else if (element == EL_EMC_DRIPPER &&
4173 game.light_time_left > 0)
4175 Feld[x][y] = EL_EMC_DRIPPER_ACTIVE;
4176 DrawLevelField(x, y);
4178 else if (element == EL_EMC_DRIPPER_ACTIVE &&
4179 game.light_time_left == 0)
4181 Feld[x][y] = EL_EMC_DRIPPER;
4182 DrawLevelField(x, y);
4184 else if (element == EL_INVISIBLE_STEELWALL ||
4185 element == EL_INVISIBLE_WALL ||
4186 element == EL_INVISIBLE_SAND)
4188 if (game.light_time_left > 0)
4189 Feld[x][y] = getInvisibleActiveFromInvisibleElement(element);
4191 DrawLevelField(x, y);
4193 /* uncrumble neighbour fields, if needed */
4194 if (element == EL_INVISIBLE_SAND)
4195 DrawLevelFieldCrumbledSandNeighbours(x, y);
4197 else if (element == EL_INVISIBLE_STEELWALL_ACTIVE ||
4198 element == EL_INVISIBLE_WALL_ACTIVE ||
4199 element == EL_INVISIBLE_SAND_ACTIVE)
4201 if (game.light_time_left == 0)
4202 Feld[x][y] = getInvisibleFromInvisibleActiveElement(element);
4204 DrawLevelField(x, y);
4206 /* re-crumble neighbour fields, if needed */
4207 if (element == EL_INVISIBLE_SAND)
4208 DrawLevelFieldCrumbledSandNeighbours(x, y);
4213 static void RedrawAllInvisibleElementsForLenses()
4217 SCAN_PLAYFIELD(x, y)
4219 int element = Feld[x][y];
4221 if (element == EL_EMC_DRIPPER &&
4222 game.lenses_time_left > 0)
4224 Feld[x][y] = EL_EMC_DRIPPER_ACTIVE;
4225 DrawLevelField(x, y);
4227 else if (element == EL_EMC_DRIPPER_ACTIVE &&
4228 game.lenses_time_left == 0)
4230 Feld[x][y] = EL_EMC_DRIPPER;
4231 DrawLevelField(x, y);
4233 else if (element == EL_INVISIBLE_STEELWALL ||
4234 element == EL_INVISIBLE_WALL ||
4235 element == EL_INVISIBLE_SAND)
4237 if (game.lenses_time_left > 0)
4238 Feld[x][y] = getInvisibleActiveFromInvisibleElement(element);
4240 DrawLevelField(x, y);
4242 /* uncrumble neighbour fields, if needed */
4243 if (element == EL_INVISIBLE_SAND)
4244 DrawLevelFieldCrumbledSandNeighbours(x, y);
4246 else if (element == EL_INVISIBLE_STEELWALL_ACTIVE ||
4247 element == EL_INVISIBLE_WALL_ACTIVE ||
4248 element == EL_INVISIBLE_SAND_ACTIVE)
4250 if (game.lenses_time_left == 0)
4251 Feld[x][y] = getInvisibleFromInvisibleActiveElement(element);
4253 DrawLevelField(x, y);
4255 /* re-crumble neighbour fields, if needed */
4256 if (element == EL_INVISIBLE_SAND)
4257 DrawLevelFieldCrumbledSandNeighbours(x, y);
4262 static void RedrawAllInvisibleElementsForMagnifier()
4266 SCAN_PLAYFIELD(x, y)
4268 int element = Feld[x][y];
4270 if (element == EL_EMC_FAKE_GRASS &&
4271 game.magnify_time_left > 0)
4273 Feld[x][y] = EL_EMC_FAKE_GRASS_ACTIVE;
4274 DrawLevelField(x, y);
4276 else if (element == EL_EMC_FAKE_GRASS_ACTIVE &&
4277 game.magnify_time_left == 0)
4279 Feld[x][y] = EL_EMC_FAKE_GRASS;
4280 DrawLevelField(x, y);
4282 else if (IS_GATE_GRAY(element) &&
4283 game.magnify_time_left > 0)
4285 Feld[x][y] = (IS_RND_GATE_GRAY(element) ?
4286 element - EL_GATE_1_GRAY + EL_GATE_1_GRAY_ACTIVE :
4287 IS_EM_GATE_GRAY(element) ?
4288 element - EL_EM_GATE_1_GRAY + EL_EM_GATE_1_GRAY_ACTIVE :
4289 IS_EMC_GATE_GRAY(element) ?
4290 element - EL_EMC_GATE_5_GRAY + EL_EMC_GATE_5_GRAY_ACTIVE :
4292 DrawLevelField(x, y);
4294 else if (IS_GATE_GRAY_ACTIVE(element) &&
4295 game.magnify_time_left == 0)
4297 Feld[x][y] = (IS_RND_GATE_GRAY_ACTIVE(element) ?
4298 element - EL_GATE_1_GRAY_ACTIVE + EL_GATE_1_GRAY :
4299 IS_EM_GATE_GRAY_ACTIVE(element) ?
4300 element - EL_EM_GATE_1_GRAY_ACTIVE + EL_EM_GATE_1_GRAY :
4301 IS_EMC_GATE_GRAY_ACTIVE(element) ?
4302 element - EL_EMC_GATE_5_GRAY_ACTIVE + EL_EMC_GATE_5_GRAY :
4304 DrawLevelField(x, y);
4309 static void ToggleLightSwitch(int x, int y)
4311 int element = Feld[x][y];
4313 game.light_time_left =
4314 (element == EL_LIGHT_SWITCH ?
4315 level.time_light * FRAMES_PER_SECOND : 0);
4317 RedrawAllLightSwitchesAndInvisibleElements();
4320 static void ActivateTimegateSwitch(int x, int y)
4324 game.timegate_time_left = level.time_timegate * FRAMES_PER_SECOND;
4326 SCAN_PLAYFIELD(xx, yy)
4328 int element = Feld[xx][yy];
4330 if (element == EL_TIMEGATE_CLOSED ||
4331 element == EL_TIMEGATE_CLOSING)
4333 Feld[xx][yy] = EL_TIMEGATE_OPENING;
4334 PlayLevelSound(xx, yy, SND_TIMEGATE_OPENING);
4338 else if (element == EL_TIMEGATE_SWITCH_ACTIVE)
4340 Feld[xx][yy] = EL_TIMEGATE_SWITCH;
4341 DrawLevelField(xx, yy);
4347 Feld[x][y] = EL_TIMEGATE_SWITCH_ACTIVE;
4350 void Impact(int x, int y)
4352 boolean last_line = (y == lev_fieldy - 1);
4353 boolean object_hit = FALSE;
4354 boolean impact = (last_line || object_hit);
4355 int element = Feld[x][y];
4356 int smashed = EL_STEELWALL;
4358 if (!last_line) /* check if element below was hit */
4360 if (Feld[x][y + 1] == EL_PLAYER_IS_LEAVING)
4363 object_hit = (!IS_FREE(x, y + 1) && (!IS_MOVING(x, y + 1) ||
4364 MovDir[x][y + 1] != MV_DOWN ||
4365 MovPos[x][y + 1] <= TILEY / 2));
4367 /* do not smash moving elements that left the smashed field in time */
4368 if (game.engine_version >= VERSION_IDENT(2,2,0,7) && IS_MOVING(x, y + 1) &&
4369 ABS(MovPos[x][y + 1] + getElementMoveStepsize(x, y + 1)) >= TILEX)
4372 #if USE_QUICKSAND_IMPACT_BUGFIX
4373 if (Feld[x][y + 1] == EL_QUICKSAND_EMPTYING && object_hit == FALSE)
4375 RemoveMovingField(x, y + 1);
4376 Feld[x][y + 1] = EL_QUICKSAND_EMPTY;
4377 Feld[x][y + 2] = EL_ROCK;
4378 DrawLevelField(x, y + 2);
4385 smashed = MovingOrBlocked2Element(x, y + 1);
4387 impact = (last_line || object_hit);
4390 if (!last_line && smashed == EL_ACID) /* element falls into acid */
4392 SplashAcid(x, y + 1);
4396 /* !!! not sufficient for all cases -- see EL_PEARL below !!! */
4397 /* only reset graphic animation if graphic really changes after impact */
4399 el_act_dir2img(element, GfxAction[x][y], MV_DOWN) != el2img(element))
4401 ResetGfxAnimation(x, y);
4402 DrawLevelField(x, y);
4405 if (impact && CAN_EXPLODE_IMPACT(element))
4410 else if (impact && element == EL_PEARL)
4412 ResetGfxAnimation(x, y);
4414 Feld[x][y] = EL_PEARL_BREAKING;
4415 PlayLevelSound(x, y, SND_PEARL_BREAKING);
4418 else if (impact && CheckElementChange(x, y, element, smashed, CE_IMPACT))
4420 PlayLevelSoundElementAction(x, y, element, ACTION_IMPACT);
4425 if (impact && element == EL_AMOEBA_DROP)
4427 if (object_hit && IS_PLAYER(x, y + 1))
4428 KillPlayerUnlessEnemyProtected(x, y + 1);
4429 else if (object_hit && smashed == EL_PENGUIN)
4433 Feld[x][y] = EL_AMOEBA_GROWING;
4434 Store[x][y] = EL_AMOEBA_WET;
4436 ResetRandomAnimationValue(x, y);
4441 if (object_hit) /* check which object was hit */
4443 if (CAN_PASS_MAGIC_WALL(element) &&
4444 (smashed == EL_MAGIC_WALL ||
4445 smashed == EL_BD_MAGIC_WALL))
4448 int activated_magic_wall =
4449 (smashed == EL_MAGIC_WALL ? EL_MAGIC_WALL_ACTIVE :
4450 EL_BD_MAGIC_WALL_ACTIVE);
4452 /* activate magic wall / mill */
4453 SCAN_PLAYFIELD(xx, yy)
4454 if (Feld[xx][yy] == smashed)
4455 Feld[xx][yy] = activated_magic_wall;
4457 game.magic_wall_time_left = level.time_magic_wall * FRAMES_PER_SECOND;
4458 game.magic_wall_active = TRUE;
4460 PlayLevelSound(x, y, (smashed == EL_MAGIC_WALL ?
4461 SND_MAGIC_WALL_ACTIVATING :
4462 SND_BD_MAGIC_WALL_ACTIVATING));
4465 if (IS_PLAYER(x, y + 1))
4467 if (CAN_SMASH_PLAYER(element))
4469 KillPlayerUnlessEnemyProtected(x, y + 1);
4473 else if (smashed == EL_PENGUIN)
4475 if (CAN_SMASH_PLAYER(element))
4481 else if (element == EL_BD_DIAMOND)
4483 if (IS_CLASSIC_ENEMY(smashed) && IS_BD_ELEMENT(smashed))
4489 else if (((element == EL_SP_INFOTRON ||
4490 element == EL_SP_ZONK) &&
4491 (smashed == EL_SP_SNIKSNAK ||
4492 smashed == EL_SP_ELECTRON ||
4493 smashed == EL_SP_DISK_ORANGE)) ||
4494 (element == EL_SP_INFOTRON &&
4495 smashed == EL_SP_DISK_YELLOW))
4500 else if (CAN_SMASH_EVERYTHING(element))
4502 if (IS_CLASSIC_ENEMY(smashed) ||
4503 CAN_EXPLODE_SMASHED(smashed))
4508 else if (!IS_MOVING(x, y + 1) && !IS_BLOCKED(x, y + 1))
4510 if (smashed == EL_LAMP ||
4511 smashed == EL_LAMP_ACTIVE)
4516 else if (smashed == EL_NUT)
4518 Feld[x][y + 1] = EL_NUT_BREAKING;
4519 PlayLevelSound(x, y, SND_NUT_BREAKING);
4520 RaiseScoreElement(EL_NUT);
4523 else if (smashed == EL_PEARL)
4525 ResetGfxAnimation(x, y);
4527 Feld[x][y + 1] = EL_PEARL_BREAKING;
4528 PlayLevelSound(x, y, SND_PEARL_BREAKING);
4531 else if (smashed == EL_DIAMOND)
4533 Feld[x][y + 1] = EL_DIAMOND_BREAKING;
4534 PlayLevelSound(x, y, SND_DIAMOND_BREAKING);
4537 else if (IS_BELT_SWITCH(smashed))
4539 ToggleBeltSwitch(x, y + 1);
4541 else if (smashed == EL_SWITCHGATE_SWITCH_UP ||
4542 smashed == EL_SWITCHGATE_SWITCH_DOWN)
4544 ToggleSwitchgateSwitch(x, y + 1);
4546 else if (smashed == EL_LIGHT_SWITCH ||
4547 smashed == EL_LIGHT_SWITCH_ACTIVE)
4549 ToggleLightSwitch(x, y + 1);
4554 TestIfElementSmashesCustomElement(x, y, MV_DOWN);
4557 CheckElementChange(x, y + 1, smashed, element, CE_SMASHED);
4559 CheckElementChangeBySide(x, y + 1, smashed, element,
4560 CE_SWITCHED, CH_SIDE_TOP);
4561 CheckTriggeredElementChangeBySide(x, y + 1, smashed, CE_SWITCH_OF_X,
4567 CheckElementChange(x, y + 1, smashed, element, CE_SMASHED);
4572 /* play sound of magic wall / mill */
4574 (Feld[x][y + 1] == EL_MAGIC_WALL_ACTIVE ||
4575 Feld[x][y + 1] == EL_BD_MAGIC_WALL_ACTIVE))
4577 if (Feld[x][y + 1] == EL_MAGIC_WALL_ACTIVE)
4578 PlayLevelSound(x, y, SND_MAGIC_WALL_FILLING);
4579 else if (Feld[x][y + 1] == EL_BD_MAGIC_WALL_ACTIVE)
4580 PlayLevelSound(x, y, SND_BD_MAGIC_WALL_FILLING);
4585 /* play sound of object that hits the ground */
4586 if (last_line || object_hit)
4587 PlayLevelSoundElementAction(x, y, element, ACTION_IMPACT);
4590 inline static void TurnRoundExt(int x, int y)
4602 { 0, 0 }, { 0, 0 }, { 0, 0 },
4607 int left, right, back;
4611 { MV_DOWN, MV_UP, MV_RIGHT },
4612 { MV_UP, MV_DOWN, MV_LEFT },
4614 { MV_LEFT, MV_RIGHT, MV_DOWN },
4618 { MV_RIGHT, MV_LEFT, MV_UP }
4621 int element = Feld[x][y];
4622 int move_pattern = element_info[element].move_pattern;
4624 int old_move_dir = MovDir[x][y];
4625 int left_dir = turn[old_move_dir].left;
4626 int right_dir = turn[old_move_dir].right;
4627 int back_dir = turn[old_move_dir].back;
4629 int left_dx = move_xy[left_dir].dx, left_dy = move_xy[left_dir].dy;
4630 int right_dx = move_xy[right_dir].dx, right_dy = move_xy[right_dir].dy;
4631 int move_dx = move_xy[old_move_dir].dx, move_dy = move_xy[old_move_dir].dy;
4632 int back_dx = move_xy[back_dir].dx, back_dy = move_xy[back_dir].dy;
4634 int left_x = x + left_dx, left_y = y + left_dy;
4635 int right_x = x + right_dx, right_y = y + right_dy;
4636 int move_x = x + move_dx, move_y = y + move_dy;
4640 if (element == EL_BUG || element == EL_BD_BUTTERFLY)
4642 TestIfBadThingTouchesOtherBadThing(x, y);
4644 if (ENEMY_CAN_ENTER_FIELD(element, right_x, right_y))
4645 MovDir[x][y] = right_dir;
4646 else if (!ENEMY_CAN_ENTER_FIELD(element, move_x, move_y))
4647 MovDir[x][y] = left_dir;
4649 if (element == EL_BUG && MovDir[x][y] != old_move_dir)
4651 else if (element == EL_BD_BUTTERFLY) /* && MovDir[x][y] == left_dir) */
4654 else if (element == EL_SPACESHIP || element == EL_BD_FIREFLY)
4656 TestIfBadThingTouchesOtherBadThing(x, y);
4658 if (ENEMY_CAN_ENTER_FIELD(element, left_x, left_y))
4659 MovDir[x][y] = left_dir;
4660 else if (!ENEMY_CAN_ENTER_FIELD(element, move_x, move_y))
4661 MovDir[x][y] = right_dir;
4663 if (element == EL_SPACESHIP && MovDir[x][y] != old_move_dir)
4665 else if (element == EL_BD_FIREFLY) /* && MovDir[x][y] == right_dir) */
4668 else if (element == EL_SP_SNIKSNAK || element == EL_SP_ELECTRON)
4670 TestIfBadThingTouchesOtherBadThing(x, y);
4672 if (ELEMENT_CAN_ENTER_FIELD_BASE_4(element, left_x, left_y, 0))
4673 MovDir[x][y] = left_dir;
4674 else if (!ELEMENT_CAN_ENTER_FIELD_BASE_4(element, move_x, move_y, 0))
4675 MovDir[x][y] = right_dir;
4677 if (MovDir[x][y] != old_move_dir)
4680 else if (element == EL_YAMYAM)
4682 boolean can_turn_left = YAMYAM_CAN_ENTER_FIELD(element, left_x, left_y);
4683 boolean can_turn_right = YAMYAM_CAN_ENTER_FIELD(element, right_x, right_y);
4685 if (can_turn_left && can_turn_right)
4686 MovDir[x][y] = (RND(3) ? (RND(2) ? left_dir : right_dir) : back_dir);
4687 else if (can_turn_left)
4688 MovDir[x][y] = (RND(2) ? left_dir : back_dir);
4689 else if (can_turn_right)
4690 MovDir[x][y] = (RND(2) ? right_dir : back_dir);
4692 MovDir[x][y] = back_dir;
4694 MovDelay[x][y] = 16 + 16 * RND(3);
4696 else if (element == EL_DARK_YAMYAM)
4698 boolean can_turn_left = DARK_YAMYAM_CAN_ENTER_FIELD(element,
4700 boolean can_turn_right = DARK_YAMYAM_CAN_ENTER_FIELD(element,
4703 if (can_turn_left && can_turn_right)
4704 MovDir[x][y] = (RND(3) ? (RND(2) ? left_dir : right_dir) : back_dir);
4705 else if (can_turn_left)
4706 MovDir[x][y] = (RND(2) ? left_dir : back_dir);
4707 else if (can_turn_right)
4708 MovDir[x][y] = (RND(2) ? right_dir : back_dir);
4710 MovDir[x][y] = back_dir;
4712 MovDelay[x][y] = 16 + 16 * RND(3);
4714 else if (element == EL_PACMAN)
4716 boolean can_turn_left = PACMAN_CAN_ENTER_FIELD(element, left_x, left_y);
4717 boolean can_turn_right = PACMAN_CAN_ENTER_FIELD(element, right_x, right_y);
4719 if (can_turn_left && can_turn_right)
4720 MovDir[x][y] = (RND(3) ? (RND(2) ? left_dir : right_dir) : back_dir);
4721 else if (can_turn_left)
4722 MovDir[x][y] = (RND(2) ? left_dir : back_dir);
4723 else if (can_turn_right)
4724 MovDir[x][y] = (RND(2) ? right_dir : back_dir);
4726 MovDir[x][y] = back_dir;
4728 MovDelay[x][y] = 6 + RND(40);
4730 else if (element == EL_PIG)
4732 boolean can_turn_left = PIG_CAN_ENTER_FIELD(element, left_x, left_y);
4733 boolean can_turn_right = PIG_CAN_ENTER_FIELD(element, right_x, right_y);
4734 boolean can_move_on = PIG_CAN_ENTER_FIELD(element, move_x, move_y);
4735 boolean should_turn_left, should_turn_right, should_move_on;
4737 int rnd = RND(rnd_value);
4739 should_turn_left = (can_turn_left &&
4741 IN_LEV_FIELD_AND_NOT_FREE(x + back_dx + left_dx,
4742 y + back_dy + left_dy)));
4743 should_turn_right = (can_turn_right &&
4745 IN_LEV_FIELD_AND_NOT_FREE(x + back_dx + right_dx,
4746 y + back_dy + right_dy)));
4747 should_move_on = (can_move_on &&
4750 IN_LEV_FIELD_AND_NOT_FREE(x + move_dx + left_dx,
4751 y + move_dy + left_dy) ||
4752 IN_LEV_FIELD_AND_NOT_FREE(x + move_dx + right_dx,
4753 y + move_dy + right_dy)));
4755 if (should_turn_left || should_turn_right || should_move_on)
4757 if (should_turn_left && should_turn_right && should_move_on)
4758 MovDir[x][y] = (rnd < rnd_value / 3 ? left_dir :
4759 rnd < 2 * rnd_value / 3 ? right_dir :
4761 else if (should_turn_left && should_turn_right)
4762 MovDir[x][y] = (rnd < rnd_value / 2 ? left_dir : right_dir);
4763 else if (should_turn_left && should_move_on)
4764 MovDir[x][y] = (rnd < rnd_value / 2 ? left_dir : old_move_dir);
4765 else if (should_turn_right && should_move_on)
4766 MovDir[x][y] = (rnd < rnd_value / 2 ? right_dir : old_move_dir);
4767 else if (should_turn_left)
4768 MovDir[x][y] = left_dir;
4769 else if (should_turn_right)
4770 MovDir[x][y] = right_dir;
4771 else if (should_move_on)
4772 MovDir[x][y] = old_move_dir;
4774 else if (can_move_on && rnd > rnd_value / 8)
4775 MovDir[x][y] = old_move_dir;
4776 else if (can_turn_left && can_turn_right)
4777 MovDir[x][y] = (rnd < rnd_value / 2 ? left_dir : right_dir);
4778 else if (can_turn_left && rnd > rnd_value / 8)
4779 MovDir[x][y] = left_dir;
4780 else if (can_turn_right && rnd > rnd_value/8)
4781 MovDir[x][y] = right_dir;
4783 MovDir[x][y] = back_dir;
4785 xx = x + move_xy[MovDir[x][y]].dx;
4786 yy = y + move_xy[MovDir[x][y]].dy;
4788 if (!IN_LEV_FIELD(xx, yy) ||
4789 (!IS_FREE(xx, yy) && !IS_FOOD_PIG(Feld[xx][yy])))
4790 MovDir[x][y] = old_move_dir;
4794 else if (element == EL_DRAGON)
4796 boolean can_turn_left = DRAGON_CAN_ENTER_FIELD(element, left_x, left_y);
4797 boolean can_turn_right = DRAGON_CAN_ENTER_FIELD(element, right_x, right_y);
4798 boolean can_move_on = DRAGON_CAN_ENTER_FIELD(element, move_x, move_y);
4800 int rnd = RND(rnd_value);
4802 if (can_move_on && rnd > rnd_value / 8)
4803 MovDir[x][y] = old_move_dir;
4804 else if (can_turn_left && can_turn_right)
4805 MovDir[x][y] = (rnd < rnd_value / 2 ? left_dir : right_dir);
4806 else if (can_turn_left && rnd > rnd_value / 8)
4807 MovDir[x][y] = left_dir;
4808 else if (can_turn_right && rnd > rnd_value / 8)
4809 MovDir[x][y] = right_dir;
4811 MovDir[x][y] = back_dir;
4813 xx = x + move_xy[MovDir[x][y]].dx;
4814 yy = y + move_xy[MovDir[x][y]].dy;
4816 if (!IN_LEV_FIELD_AND_IS_FREE(xx, yy))
4817 MovDir[x][y] = old_move_dir;
4821 else if (element == EL_MOLE)
4823 boolean can_move_on =
4824 (MOLE_CAN_ENTER_FIELD(element, move_x, move_y,
4825 IS_AMOEBOID(Feld[move_x][move_y]) ||
4826 Feld[move_x][move_y] == EL_AMOEBA_SHRINKING));
4829 boolean can_turn_left =
4830 (MOLE_CAN_ENTER_FIELD(element, left_x, left_y,
4831 IS_AMOEBOID(Feld[left_x][left_y])));
4833 boolean can_turn_right =
4834 (MOLE_CAN_ENTER_FIELD(element, right_x, right_y,
4835 IS_AMOEBOID(Feld[right_x][right_y])));
4837 if (can_turn_left && can_turn_right)
4838 MovDir[x][y] = (RND(2) ? left_dir : right_dir);
4839 else if (can_turn_left)
4840 MovDir[x][y] = left_dir;
4842 MovDir[x][y] = right_dir;
4845 if (MovDir[x][y] != old_move_dir)
4848 else if (element == EL_BALLOON)
4850 MovDir[x][y] = game.wind_direction;
4853 else if (element == EL_SPRING)
4855 #if USE_NEW_SPRING_BUMPER
4856 if (MovDir[x][y] & MV_HORIZONTAL)
4858 if (SPRING_CAN_BUMP_FROM_FIELD(move_x, move_y) &&
4859 !SPRING_CAN_ENTER_FIELD(element, x, y + 1))
4861 Feld[move_x][move_y] = EL_EMC_SPRING_BUMPER_ACTIVE;
4862 ResetGfxAnimation(move_x, move_y);
4863 DrawLevelField(move_x, move_y);
4865 MovDir[x][y] = back_dir;
4867 else if (!SPRING_CAN_ENTER_FIELD(element, move_x, move_y) ||
4868 SPRING_CAN_ENTER_FIELD(element, x, y + 1))
4869 MovDir[x][y] = MV_NONE;
4872 if (MovDir[x][y] & MV_HORIZONTAL &&
4873 (!SPRING_CAN_ENTER_FIELD(element, move_x, move_y) ||
4874 SPRING_CAN_ENTER_FIELD(element, x, y + 1)))
4875 MovDir[x][y] = MV_NONE;
4880 else if (element == EL_ROBOT ||
4881 element == EL_SATELLITE ||
4882 element == EL_PENGUIN ||
4883 element == EL_EMC_ANDROID)
4885 int attr_x = -1, attr_y = -1;
4896 for (i = 0; i < MAX_PLAYERS; i++)
4898 struct PlayerInfo *player = &stored_player[i];
4899 int jx = player->jx, jy = player->jy;
4901 if (!player->active)
4905 ABS(jx - x) + ABS(jy - y) < ABS(attr_x - x) + ABS(attr_y - y))
4913 if (element == EL_ROBOT && ZX >= 0 && ZY >= 0 &&
4914 (Feld[ZX][ZY] == EL_ROBOT_WHEEL_ACTIVE ||
4915 game.engine_version < VERSION_IDENT(3,1,0,0)))
4921 if (element == EL_PENGUIN)
4924 static int xy[4][2] =
4932 for (i = 0; i < NUM_DIRECTIONS; i++)
4934 int ex = x + xy[i][0];
4935 int ey = y + xy[i][1];
4937 if (IN_LEV_FIELD(ex, ey) && Feld[ex][ey] == EL_EXIT_OPEN)
4946 MovDir[x][y] = MV_NONE;
4948 MovDir[x][y] |= (AllPlayersGone ? MV_RIGHT : MV_LEFT);
4949 else if (attr_x > x)
4950 MovDir[x][y] |= (AllPlayersGone ? MV_LEFT : MV_RIGHT);
4952 MovDir[x][y] |= (AllPlayersGone ? MV_DOWN : MV_UP);
4953 else if (attr_y > y)
4954 MovDir[x][y] |= (AllPlayersGone ? MV_UP : MV_DOWN);
4956 if (element == EL_ROBOT)
4960 if (MovDir[x][y] & MV_HORIZONTAL && MovDir[x][y] & MV_VERTICAL)
4961 MovDir[x][y] &= (RND(2) ? MV_HORIZONTAL : MV_VERTICAL);
4962 Moving2Blocked(x, y, &newx, &newy);
4964 if (IN_LEV_FIELD(newx, newy) && IS_FREE_OR_PLAYER(newx, newy))
4965 MovDelay[x][y] = 8 + 8 * !RND(3);
4967 MovDelay[x][y] = 16;
4969 else if (element == EL_PENGUIN)
4975 if (MovDir[x][y] & MV_HORIZONTAL && MovDir[x][y] & MV_VERTICAL)
4977 boolean first_horiz = RND(2);
4978 int new_move_dir = MovDir[x][y];
4981 new_move_dir & (first_horiz ? MV_HORIZONTAL : MV_VERTICAL);
4982 Moving2Blocked(x, y, &newx, &newy);
4984 if (PENGUIN_CAN_ENTER_FIELD(element, newx, newy))
4988 new_move_dir & (!first_horiz ? MV_HORIZONTAL : MV_VERTICAL);
4989 Moving2Blocked(x, y, &newx, &newy);
4991 if (PENGUIN_CAN_ENTER_FIELD(element, newx, newy))
4994 MovDir[x][y] = old_move_dir;
4998 else if (element == EL_SATELLITE)
5004 if (MovDir[x][y] & MV_HORIZONTAL && MovDir[x][y] & MV_VERTICAL)
5006 boolean first_horiz = RND(2);
5007 int new_move_dir = MovDir[x][y];
5010 new_move_dir & (first_horiz ? MV_HORIZONTAL : MV_VERTICAL);
5011 Moving2Blocked(x, y, &newx, &newy);
5013 if (SATELLITE_CAN_ENTER_FIELD(newx, newy))
5017 new_move_dir & (!first_horiz ? MV_HORIZONTAL : MV_VERTICAL);
5018 Moving2Blocked(x, y, &newx, &newy);
5020 if (SATELLITE_CAN_ENTER_FIELD(newx, newy))
5023 MovDir[x][y] = old_move_dir;
5027 else if (element == EL_EMC_ANDROID)
5029 static int check_pos[16] =
5031 -1, /* 0 => (invalid) */
5032 7, /* 1 => MV_LEFT */
5033 3, /* 2 => MV_RIGHT */
5034 -1, /* 3 => (invalid) */
5036 0, /* 5 => MV_LEFT | MV_UP */
5037 2, /* 6 => MV_RIGHT | MV_UP */
5038 -1, /* 7 => (invalid) */
5039 5, /* 8 => MV_DOWN */
5040 6, /* 9 => MV_LEFT | MV_DOWN */
5041 4, /* 10 => MV_RIGHT | MV_DOWN */
5042 -1, /* 11 => (invalid) */
5043 -1, /* 12 => (invalid) */
5044 -1, /* 13 => (invalid) */
5045 -1, /* 14 => (invalid) */
5046 -1, /* 15 => (invalid) */
5054 { -1, -1, MV_LEFT | MV_UP },
5056 { +1, -1, MV_RIGHT | MV_UP },
5057 { +1, 0, MV_RIGHT },
5058 { +1, +1, MV_RIGHT | MV_DOWN },
5060 { -1, +1, MV_LEFT | MV_DOWN },
5063 int start_pos, check_order;
5064 boolean can_clone = FALSE;
5067 /* check if there is any free field around current position */
5068 for (i = 0; i < 8; i++)
5070 int newx = x + check_xy[i].dx;
5071 int newy = y + check_xy[i].dy;
5073 if (IN_LEV_FIELD_AND_IS_FREE(newx, newy))
5081 if (can_clone) /* randomly find an element to clone */
5085 start_pos = check_pos[RND(8)];
5086 check_order = (RND(2) ? -1 : +1);
5088 for (i = 0; i < 8; i++)
5090 int pos_raw = start_pos + i * check_order;
5091 int pos = (pos_raw + 8) % 8;
5092 int newx = x + check_xy[pos].dx;
5093 int newy = y + check_xy[pos].dy;
5095 if (ANDROID_CAN_CLONE_FIELD(newx, newy))
5097 element_info[element].move_leave_type = LEAVE_TYPE_LIMITED;
5098 element_info[element].move_leave_element = EL_TRIGGER_ELEMENT;
5100 Store[x][y] = Feld[newx][newy];
5109 if (can_clone) /* randomly find a direction to move */
5113 start_pos = check_pos[RND(8)];
5114 check_order = (RND(2) ? -1 : +1);
5116 for (i = 0; i < 8; i++)
5118 int pos_raw = start_pos + i * check_order;
5119 int pos = (pos_raw + 8) % 8;
5120 int newx = x + check_xy[pos].dx;
5121 int newy = y + check_xy[pos].dy;
5122 int new_move_dir = check_xy[pos].dir;
5124 if (IN_LEV_FIELD_AND_IS_FREE(newx, newy))
5126 MovDir[x][y] = new_move_dir;
5127 MovDelay[x][y] = level.android_clone_time * 8 + 1;
5136 if (can_clone) /* cloning and moving successful */
5139 /* cannot clone -- try to move towards player */
5141 start_pos = check_pos[MovDir[x][y] & 0x0f];
5142 check_order = (RND(2) ? -1 : +1);
5144 for (i = 0; i < 3; i++)
5146 /* first check start_pos, then previous/next or (next/previous) pos */
5147 int pos_raw = start_pos + (i < 2 ? i : -1) * check_order;
5148 int pos = (pos_raw + 8) % 8;
5149 int newx = x + check_xy[pos].dx;
5150 int newy = y + check_xy[pos].dy;
5151 int new_move_dir = check_xy[pos].dir;
5153 if (IS_PLAYER(newx, newy))
5156 if (ANDROID_CAN_ENTER_FIELD(element, newx, newy))
5158 MovDir[x][y] = new_move_dir;
5159 MovDelay[x][y] = level.android_move_time * 8 + 1;
5166 else if (move_pattern == MV_TURNING_LEFT ||
5167 move_pattern == MV_TURNING_RIGHT ||
5168 move_pattern == MV_TURNING_LEFT_RIGHT ||
5169 move_pattern == MV_TURNING_RIGHT_LEFT ||
5170 move_pattern == MV_TURNING_RANDOM ||
5171 move_pattern == MV_ALL_DIRECTIONS)
5173 boolean can_turn_left =
5174 CUSTOM_ELEMENT_CAN_ENTER_FIELD(element, left_x, left_y);
5175 boolean can_turn_right =
5176 CUSTOM_ELEMENT_CAN_ENTER_FIELD(element, right_x,right_y);
5178 if (element_info[element].move_stepsize == 0) /* "not moving" */
5181 if (move_pattern == MV_TURNING_LEFT)
5182 MovDir[x][y] = left_dir;
5183 else if (move_pattern == MV_TURNING_RIGHT)
5184 MovDir[x][y] = right_dir;
5185 else if (move_pattern == MV_TURNING_LEFT_RIGHT)
5186 MovDir[x][y] = (can_turn_left || !can_turn_right ? left_dir : right_dir);
5187 else if (move_pattern == MV_TURNING_RIGHT_LEFT)
5188 MovDir[x][y] = (can_turn_right || !can_turn_left ? right_dir : left_dir);
5189 else if (move_pattern == MV_TURNING_RANDOM)
5190 MovDir[x][y] = (can_turn_left && !can_turn_right ? left_dir :
5191 can_turn_right && !can_turn_left ? right_dir :
5192 RND(2) ? left_dir : right_dir);
5193 else if (can_turn_left && can_turn_right)
5194 MovDir[x][y] = (RND(3) ? (RND(2) ? left_dir : right_dir) : back_dir);
5195 else if (can_turn_left)
5196 MovDir[x][y] = (RND(2) ? left_dir : back_dir);
5197 else if (can_turn_right)
5198 MovDir[x][y] = (RND(2) ? right_dir : back_dir);
5200 MovDir[x][y] = back_dir;
5202 MovDelay[x][y] = GET_NEW_MOVE_DELAY(element);
5204 else if (move_pattern == MV_HORIZONTAL ||
5205 move_pattern == MV_VERTICAL)
5207 if (move_pattern & old_move_dir)
5208 MovDir[x][y] = back_dir;
5209 else if (move_pattern == MV_HORIZONTAL)
5210 MovDir[x][y] = (RND(2) ? MV_LEFT : MV_RIGHT);
5211 else if (move_pattern == MV_VERTICAL)
5212 MovDir[x][y] = (RND(2) ? MV_UP : MV_DOWN);
5214 MovDelay[x][y] = GET_NEW_MOVE_DELAY(element);
5216 else if (move_pattern & MV_ANY_DIRECTION)
5218 MovDir[x][y] = move_pattern;
5219 MovDelay[x][y] = GET_NEW_MOVE_DELAY(element);
5221 else if (move_pattern & MV_WIND_DIRECTION)
5223 MovDir[x][y] = game.wind_direction;
5224 MovDelay[x][y] = GET_NEW_MOVE_DELAY(element);
5226 else if (move_pattern == MV_ALONG_LEFT_SIDE)
5228 if (CUSTOM_ELEMENT_CAN_ENTER_FIELD(element, left_x, left_y))
5229 MovDir[x][y] = left_dir;
5230 else if (!CUSTOM_ELEMENT_CAN_ENTER_FIELD(element, move_x, move_y))
5231 MovDir[x][y] = right_dir;
5233 if (MovDir[x][y] != old_move_dir)
5234 MovDelay[x][y] = GET_NEW_MOVE_DELAY(element);
5236 else if (move_pattern == MV_ALONG_RIGHT_SIDE)
5238 if (CUSTOM_ELEMENT_CAN_ENTER_FIELD(element, right_x, right_y))
5239 MovDir[x][y] = right_dir;
5240 else if (!CUSTOM_ELEMENT_CAN_ENTER_FIELD(element, move_x, move_y))
5241 MovDir[x][y] = left_dir;
5243 if (MovDir[x][y] != old_move_dir)
5244 MovDelay[x][y] = GET_NEW_MOVE_DELAY(element);
5246 else if (move_pattern == MV_TOWARDS_PLAYER ||
5247 move_pattern == MV_AWAY_FROM_PLAYER)
5249 int attr_x = -1, attr_y = -1;
5251 boolean move_away = (move_pattern == MV_AWAY_FROM_PLAYER);
5262 for (i = 0; i < MAX_PLAYERS; i++)
5264 struct PlayerInfo *player = &stored_player[i];
5265 int jx = player->jx, jy = player->jy;
5267 if (!player->active)
5271 ABS(jx - x) + ABS(jy - y) < ABS(attr_x - x) + ABS(attr_y - y))
5279 MovDir[x][y] = MV_NONE;
5281 MovDir[x][y] |= (move_away ? MV_RIGHT : MV_LEFT);
5282 else if (attr_x > x)
5283 MovDir[x][y] |= (move_away ? MV_LEFT : MV_RIGHT);
5285 MovDir[x][y] |= (move_away ? MV_DOWN : MV_UP);
5286 else if (attr_y > y)
5287 MovDir[x][y] |= (move_away ? MV_UP : MV_DOWN);
5289 MovDelay[x][y] = GET_NEW_MOVE_DELAY(element);
5291 if (MovDir[x][y] & MV_HORIZONTAL && MovDir[x][y] & MV_VERTICAL)
5293 boolean first_horiz = RND(2);
5294 int new_move_dir = MovDir[x][y];
5296 if (element_info[element].move_stepsize == 0) /* "not moving" */
5298 first_horiz = (ABS(attr_x - x) >= ABS(attr_y - y));
5299 MovDir[x][y] &= (first_horiz ? MV_HORIZONTAL : MV_VERTICAL);
5305 new_move_dir & (first_horiz ? MV_HORIZONTAL : MV_VERTICAL);
5306 Moving2Blocked(x, y, &newx, &newy);
5308 if (CUSTOM_ELEMENT_CAN_ENTER_FIELD(element, newx, newy))
5312 new_move_dir & (!first_horiz ? MV_HORIZONTAL : MV_VERTICAL);
5313 Moving2Blocked(x, y, &newx, &newy);
5315 if (CUSTOM_ELEMENT_CAN_ENTER_FIELD(element, newx, newy))
5318 MovDir[x][y] = old_move_dir;
5321 else if (move_pattern == MV_WHEN_PUSHED ||
5322 move_pattern == MV_WHEN_DROPPED)
5324 if (!CUSTOM_ELEMENT_CAN_ENTER_FIELD(element, move_x, move_y))
5325 MovDir[x][y] = MV_NONE;
5329 else if (move_pattern & MV_MAZE_RUNNER_STYLE)
5331 static int test_xy[7][2] =
5341 static int test_dir[7] =
5351 boolean hunter_mode = (move_pattern == MV_MAZE_HUNTER);
5352 int move_preference = -1000000; /* start with very low preference */
5353 int new_move_dir = MV_NONE;
5354 int start_test = RND(4);
5357 for (i = 0; i < NUM_DIRECTIONS; i++)
5359 int move_dir = test_dir[start_test + i];
5360 int move_dir_preference;
5362 xx = x + test_xy[start_test + i][0];
5363 yy = y + test_xy[start_test + i][1];
5365 if (hunter_mode && IN_LEV_FIELD(xx, yy) &&
5366 (IS_PLAYER(xx, yy) || Feld[xx][yy] == EL_PLAYER_IS_LEAVING))
5368 new_move_dir = move_dir;
5373 if (!CUSTOM_ELEMENT_CAN_ENTER_FIELD(element, xx, yy))
5376 move_dir_preference = -1 * RunnerVisit[xx][yy];
5377 if (hunter_mode && PlayerVisit[xx][yy] > 0)
5378 move_dir_preference = PlayerVisit[xx][yy];
5380 if (move_dir_preference > move_preference)
5382 /* prefer field that has not been visited for the longest time */
5383 move_preference = move_dir_preference;
5384 new_move_dir = move_dir;
5386 else if (move_dir_preference == move_preference &&
5387 move_dir == old_move_dir)
5389 /* prefer last direction when all directions are preferred equally */
5390 move_preference = move_dir_preference;
5391 new_move_dir = move_dir;
5395 MovDir[x][y] = new_move_dir;
5396 if (old_move_dir != new_move_dir)
5397 MovDelay[x][y] = GET_NEW_MOVE_DELAY(element);
5401 static void TurnRound(int x, int y)
5403 int direction = MovDir[x][y];
5407 GfxDir[x][y] = MovDir[x][y];
5409 if (direction != MovDir[x][y])
5413 GfxAction[x][y] = ACTION_TURNING_FROM_LEFT + MV_DIR_TO_BIT(direction);
5415 ResetGfxFrame(x, y, FALSE);
5418 static boolean JustBeingPushed(int x, int y)
5422 for (i = 0; i < MAX_PLAYERS; i++)
5424 struct PlayerInfo *player = &stored_player[i];
5426 if (player->active && player->is_pushing && player->MovPos)
5428 int next_jx = player->jx + (player->jx - player->last_jx);
5429 int next_jy = player->jy + (player->jy - player->last_jy);
5431 if (x == next_jx && y == next_jy)
5439 void StartMoving(int x, int y)
5441 boolean started_moving = FALSE; /* some elements can fall _and_ move */
5442 int element = Feld[x][y];
5447 if (MovDelay[x][y] == 0)
5448 GfxAction[x][y] = ACTION_DEFAULT;
5450 if (CAN_FALL(element) && y < lev_fieldy - 1)
5452 if ((x > 0 && IS_PLAYER(x - 1, y)) ||
5453 (x < lev_fieldx - 1 && IS_PLAYER(x + 1, y)))
5454 if (JustBeingPushed(x, y))
5457 if (element == EL_QUICKSAND_FULL)
5459 if (IS_FREE(x, y + 1))
5461 InitMovingField(x, y, MV_DOWN);
5462 started_moving = TRUE;
5464 Feld[x][y] = EL_QUICKSAND_EMPTYING;
5465 #if USE_QUICKSAND_BD_ROCK_BUGFIX
5466 if (Store[x][y] != EL_ROCK && Store[x][y] != EL_BD_ROCK)
5467 Store[x][y] = EL_ROCK;
5469 Store[x][y] = EL_ROCK;
5472 PlayLevelSoundAction(x, y, ACTION_EMPTYING);
5474 else if (Feld[x][y + 1] == EL_QUICKSAND_EMPTY)
5476 if (!MovDelay[x][y])
5477 MovDelay[x][y] = TILEY + 1;
5486 Feld[x][y] = EL_QUICKSAND_EMPTY;
5487 Feld[x][y + 1] = EL_QUICKSAND_FULL;
5488 Store[x][y + 1] = Store[x][y];
5491 PlayLevelSoundAction(x, y, ACTION_FILLING);
5494 else if ((element == EL_ROCK || element == EL_BD_ROCK) &&
5495 Feld[x][y + 1] == EL_QUICKSAND_EMPTY)
5497 InitMovingField(x, y, MV_DOWN);
5498 started_moving = TRUE;
5500 Feld[x][y] = EL_QUICKSAND_FILLING;
5501 Store[x][y] = element;
5503 PlayLevelSoundAction(x, y, ACTION_FILLING);
5505 else if (element == EL_MAGIC_WALL_FULL)
5507 if (IS_FREE(x, y + 1))
5509 InitMovingField(x, y, MV_DOWN);
5510 started_moving = TRUE;
5512 Feld[x][y] = EL_MAGIC_WALL_EMPTYING;
5513 Store[x][y] = EL_CHANGED(Store[x][y]);
5515 else if (Feld[x][y + 1] == EL_MAGIC_WALL_ACTIVE)
5517 if (!MovDelay[x][y])
5518 MovDelay[x][y] = TILEY/4 + 1;
5527 Feld[x][y] = EL_MAGIC_WALL_ACTIVE;
5528 Feld[x][y + 1] = EL_MAGIC_WALL_FULL;
5529 Store[x][y + 1] = EL_CHANGED(Store[x][y]);
5533 else if (element == EL_BD_MAGIC_WALL_FULL)
5535 if (IS_FREE(x, y + 1))
5537 InitMovingField(x, y, MV_DOWN);
5538 started_moving = TRUE;
5540 Feld[x][y] = EL_BD_MAGIC_WALL_EMPTYING;
5541 Store[x][y] = EL_CHANGED2(Store[x][y]);
5543 else if (Feld[x][y + 1] == EL_BD_MAGIC_WALL_ACTIVE)
5545 if (!MovDelay[x][y])
5546 MovDelay[x][y] = TILEY/4 + 1;
5555 Feld[x][y] = EL_BD_MAGIC_WALL_ACTIVE;
5556 Feld[x][y + 1] = EL_BD_MAGIC_WALL_FULL;
5557 Store[x][y + 1] = EL_CHANGED2(Store[x][y]);
5561 else if (CAN_PASS_MAGIC_WALL(element) &&
5562 (Feld[x][y + 1] == EL_MAGIC_WALL_ACTIVE ||
5563 Feld[x][y + 1] == EL_BD_MAGIC_WALL_ACTIVE))
5565 InitMovingField(x, y, MV_DOWN);
5566 started_moving = TRUE;
5569 (Feld[x][y + 1] == EL_MAGIC_WALL_ACTIVE ? EL_MAGIC_WALL_FILLING :
5570 EL_BD_MAGIC_WALL_FILLING);
5571 Store[x][y] = element;
5573 else if (CAN_FALL(element) && Feld[x][y + 1] == EL_ACID)
5575 SplashAcid(x, y + 1);
5577 InitMovingField(x, y, MV_DOWN);
5578 started_moving = TRUE;
5580 Store[x][y] = EL_ACID;
5582 else if ((game.engine_version >= VERSION_IDENT(3,1,0,0) &&
5583 CheckCollision[x][y] && !IS_FREE(x, y + 1)) ||
5585 (game.engine_version >= VERSION_IDENT(3,0,7,0) &&
5586 CAN_FALL(element) && WasJustFalling[x][y] &&
5587 (Feld[x][y + 1] == EL_BLOCKED || IS_PLAYER(x, y + 1))) ||
5589 (game.engine_version < VERSION_IDENT(2,2,0,7) &&
5590 CAN_FALL(element) && WasJustMoving[x][y] && !Pushed[x][y + 1] &&
5591 (Feld[x][y + 1] == EL_BLOCKED)))
5593 /* this is needed for a special case not covered by calling "Impact()"
5594 from "ContinueMoving()": if an element moves to a tile directly below
5595 another element which was just falling on that tile (which was empty
5596 in the previous frame), the falling element above would just stop
5597 instead of smashing the element below (in previous version, the above
5598 element was just checked for "moving" instead of "falling", resulting
5599 in incorrect smashes caused by horizontal movement of the above
5600 element; also, the case of the player being the element to smash was
5601 simply not covered here... :-/ ) */
5603 CheckCollision[x][y] = 0;
5607 else if (IS_FREE(x, y + 1) && element == EL_SPRING && level.use_spring_bug)
5609 if (MovDir[x][y] == MV_NONE)
5611 InitMovingField(x, y, MV_DOWN);
5612 started_moving = TRUE;
5615 else if (IS_FREE(x, y + 1) || Feld[x][y + 1] == EL_DIAMOND_BREAKING)
5617 if (WasJustFalling[x][y]) /* prevent animation from being restarted */
5618 MovDir[x][y] = MV_DOWN;
5620 InitMovingField(x, y, MV_DOWN);
5621 started_moving = TRUE;
5623 else if (element == EL_AMOEBA_DROP)
5625 Feld[x][y] = EL_AMOEBA_GROWING;
5626 Store[x][y] = EL_AMOEBA_WET;
5628 else if (((IS_SLIPPERY(Feld[x][y + 1]) && !IS_PLAYER(x, y + 1)) ||
5629 (IS_EM_SLIPPERY_WALL(Feld[x][y + 1]) && IS_GEM(element))) &&
5630 !IS_FALLING(x, y + 1) && !WasJustMoving[x][y + 1] &&
5631 element != EL_DX_SUPABOMB && element != EL_SP_DISK_ORANGE)
5633 boolean can_fall_left = (x > 0 && IS_FREE(x - 1, y) &&
5634 (IS_FREE(x - 1, y + 1) ||
5635 Feld[x - 1][y + 1] == EL_ACID));
5636 boolean can_fall_right = (x < lev_fieldx - 1 && IS_FREE(x + 1, y) &&
5637 (IS_FREE(x + 1, y + 1) ||
5638 Feld[x + 1][y + 1] == EL_ACID));
5639 boolean can_fall_any = (can_fall_left || can_fall_right);
5640 boolean can_fall_both = (can_fall_left && can_fall_right);
5641 int slippery_type = element_info[Feld[x][y + 1]].slippery_type;
5643 #if USE_NEW_ALL_SLIPPERY
5644 if (can_fall_any && slippery_type != SLIPPERY_ANY_RANDOM)
5646 if (slippery_type == SLIPPERY_ANY_LEFT_RIGHT && can_fall_both)
5647 can_fall_right = FALSE;
5648 else if (slippery_type == SLIPPERY_ANY_RIGHT_LEFT && can_fall_both)
5649 can_fall_left = FALSE;
5650 else if (slippery_type == SLIPPERY_ONLY_LEFT)
5651 can_fall_right = FALSE;
5652 else if (slippery_type == SLIPPERY_ONLY_RIGHT)
5653 can_fall_left = FALSE;
5655 can_fall_any = (can_fall_left || can_fall_right);
5656 can_fall_both = FALSE;
5659 if (can_fall_any && IS_CUSTOM_ELEMENT(Feld[x][y + 1]))
5661 if (slippery_type == SLIPPERY_ONLY_LEFT)
5662 can_fall_right = FALSE;
5663 else if (slippery_type == SLIPPERY_ONLY_RIGHT)
5664 can_fall_left = FALSE;
5665 else if (slippery_type == SLIPPERY_ANY_LEFT_RIGHT && can_fall_both)
5666 can_fall_right = FALSE;
5667 else if (slippery_type == SLIPPERY_ANY_RIGHT_LEFT && can_fall_both)
5668 can_fall_left = FALSE;
5670 can_fall_any = (can_fall_left || can_fall_right);
5671 can_fall_both = (can_fall_left && can_fall_right);
5675 #if USE_NEW_ALL_SLIPPERY
5677 #if USE_NEW_SP_SLIPPERY
5678 /* !!! better use the same properties as for custom elements here !!! */
5679 else if (game.engine_version >= VERSION_IDENT(3,1,1,0) &&
5680 can_fall_both && IS_SP_ELEMENT(Feld[x][y + 1]))
5682 can_fall_right = FALSE; /* slip down on left side */
5683 can_fall_both = FALSE;
5688 #if USE_NEW_ALL_SLIPPERY
5691 if (element == EL_BD_ROCK || element == EL_BD_DIAMOND)
5692 can_fall_right = FALSE; /* slip down on left side */
5694 can_fall_left = !(can_fall_right = RND(2));
5696 can_fall_both = FALSE;
5701 if (game.emulation == EMU_BOULDERDASH ||
5702 element == EL_BD_ROCK || element == EL_BD_DIAMOND)
5703 can_fall_right = FALSE; /* slip down on left side */
5705 can_fall_left = !(can_fall_right = RND(2));
5707 can_fall_both = FALSE;
5713 /* if not determined otherwise, prefer left side for slipping down */
5714 InitMovingField(x, y, can_fall_left ? MV_LEFT : MV_RIGHT);
5715 started_moving = TRUE;
5719 else if (IS_BELT_ACTIVE(Feld[x][y + 1]) && !CAN_MOVE(element))
5721 else if (IS_BELT_ACTIVE(Feld[x][y + 1]))
5724 boolean left_is_free = (x > 0 && IS_FREE(x - 1, y));
5725 boolean right_is_free = (x < lev_fieldx - 1 && IS_FREE(x + 1, y));
5726 int belt_nr = getBeltNrFromBeltActiveElement(Feld[x][y + 1]);
5727 int belt_dir = game.belt_dir[belt_nr];
5729 if ((belt_dir == MV_LEFT && left_is_free) ||
5730 (belt_dir == MV_RIGHT && right_is_free))
5732 int nextx = (belt_dir == MV_LEFT ? x - 1 : x + 1);
5734 InitMovingField(x, y, belt_dir);
5735 started_moving = TRUE;
5737 Pushed[x][y] = TRUE;
5738 Pushed[nextx][y] = TRUE;
5740 GfxAction[x][y] = ACTION_DEFAULT;
5744 MovDir[x][y] = 0; /* if element was moving, stop it */
5749 /* not "else if" because of elements that can fall and move (EL_SPRING) */
5751 if (CAN_MOVE(element) && !started_moving && MovDir[x][y] != MV_NONE)
5753 if (CAN_MOVE(element) && !started_moving)
5756 int move_pattern = element_info[element].move_pattern;
5761 if (MovDir[x][y] == MV_NONE)
5763 printf("StartMoving(): %d,%d: element %d ['%s'] not moving\n",
5764 x, y, element, element_info[element].token_name);
5765 printf("StartMoving(): This should never happen!\n");
5770 Moving2Blocked(x, y, &newx, &newy);
5772 if (IS_PUSHABLE(element) && JustBeingPushed(x, y))
5775 if (game.engine_version >= VERSION_IDENT(3,1,0,0) &&
5776 CheckCollision[x][y] && !IN_LEV_FIELD_AND_IS_FREE(newx, newy))
5778 WasJustMoving[x][y] = 0;
5779 CheckCollision[x][y] = 0;
5781 TestIfElementHitsCustomElement(x, y, MovDir[x][y]);
5783 if (Feld[x][y] != element) /* element has changed */
5787 if (!MovDelay[x][y]) /* start new movement phase */
5789 /* all objects that can change their move direction after each step
5790 (YAMYAM, DARK_YAMYAM and PACMAN go straight until they hit a wall */
5792 if (element != EL_YAMYAM &&
5793 element != EL_DARK_YAMYAM &&
5794 element != EL_PACMAN &&
5795 !(move_pattern & MV_ANY_DIRECTION) &&
5796 move_pattern != MV_TURNING_LEFT &&
5797 move_pattern != MV_TURNING_RIGHT &&
5798 move_pattern != MV_TURNING_LEFT_RIGHT &&
5799 move_pattern != MV_TURNING_RIGHT_LEFT &&
5800 move_pattern != MV_TURNING_RANDOM)
5804 if (MovDelay[x][y] && (element == EL_BUG ||
5805 element == EL_SPACESHIP ||
5806 element == EL_SP_SNIKSNAK ||
5807 element == EL_SP_ELECTRON ||
5808 element == EL_MOLE))
5809 DrawLevelField(x, y);
5813 if (MovDelay[x][y]) /* wait some time before next movement */
5817 if (element == EL_ROBOT ||
5818 element == EL_YAMYAM ||
5819 element == EL_DARK_YAMYAM)
5821 DrawLevelElementAnimationIfNeeded(x, y, element);
5822 PlayLevelSoundAction(x, y, ACTION_WAITING);
5824 else if (element == EL_SP_ELECTRON)
5825 DrawLevelElementAnimationIfNeeded(x, y, element);
5826 else if (element == EL_DRAGON)
5829 int dir = MovDir[x][y];
5830 int dx = (dir == MV_LEFT ? -1 : dir == MV_RIGHT ? +1 : 0);
5831 int dy = (dir == MV_UP ? -1 : dir == MV_DOWN ? +1 : 0);
5832 int graphic = (dir == MV_LEFT ? IMG_FLAMES_1_LEFT :
5833 dir == MV_RIGHT ? IMG_FLAMES_1_RIGHT :
5834 dir == MV_UP ? IMG_FLAMES_1_UP :
5835 dir == MV_DOWN ? IMG_FLAMES_1_DOWN : IMG_EMPTY);
5836 int frame = getGraphicAnimationFrame(graphic, GfxFrame[x][y]);
5838 GfxAction[x][y] = ACTION_ATTACKING;
5840 if (IS_PLAYER(x, y))
5841 DrawPlayerField(x, y);
5843 DrawLevelField(x, y);
5845 PlayLevelSoundActionIfLoop(x, y, ACTION_ATTACKING);
5847 for (i = 1; i <= 3; i++)
5849 int xx = x + i * dx;
5850 int yy = y + i * dy;
5851 int sx = SCREENX(xx);
5852 int sy = SCREENY(yy);
5853 int flame_graphic = graphic + (i - 1);
5855 if (!IN_LEV_FIELD(xx, yy) || IS_DRAGONFIRE_PROOF(Feld[xx][yy]))
5860 int flamed = MovingOrBlocked2Element(xx, yy);
5864 if (IS_CLASSIC_ENEMY(flamed) || CAN_EXPLODE_BY_DRAGONFIRE(flamed))
5866 else if (IS_MOVING(xx, yy) || IS_BLOCKED(xx, yy))
5867 RemoveMovingField(xx, yy);
5869 RemoveField(xx, yy);
5871 if (IS_CLASSIC_ENEMY(flamed) || CAN_EXPLODE_BY_DRAGONFIRE(flamed))
5874 RemoveMovingField(xx, yy);
5877 ChangeDelay[xx][yy] = 0;
5879 Feld[xx][yy] = EL_FLAMES;
5881 if (IN_SCR_FIELD(sx, sy))
5883 DrawLevelFieldCrumbledSand(xx, yy);
5884 DrawGraphic(sx, sy, flame_graphic, frame);
5889 if (Feld[xx][yy] == EL_FLAMES)
5890 Feld[xx][yy] = EL_EMPTY;
5891 DrawLevelField(xx, yy);
5896 if (MovDelay[x][y]) /* element still has to wait some time */
5898 PlayLevelSoundAction(x, y, ACTION_WAITING);
5904 /* now make next step */
5906 Moving2Blocked(x, y, &newx, &newy); /* get next screen position */
5908 if (DONT_COLLIDE_WITH(element) &&
5909 IN_LEV_FIELD(newx, newy) && IS_PLAYER(newx, newy) &&
5910 !PLAYER_ENEMY_PROTECTED(newx, newy))
5912 TestIfBadThingRunsIntoPlayer(x, y, MovDir[x][y]);
5917 else if (CAN_MOVE_INTO_ACID(element) &&
5918 IN_LEV_FIELD(newx, newy) && Feld[newx][newy] == EL_ACID &&
5919 !IS_MV_DIAGONAL(MovDir[x][y]) &&
5920 (MovDir[x][y] == MV_DOWN ||
5921 game.engine_version >= VERSION_IDENT(3,1,0,0)))
5923 SplashAcid(newx, newy);
5924 Store[x][y] = EL_ACID;
5926 else if (element == EL_PENGUIN && IN_LEV_FIELD(newx, newy))
5928 if (Feld[newx][newy] == EL_EXIT_OPEN)
5931 DrawLevelField(x, y);
5933 PlayLevelSound(newx, newy, SND_PENGUIN_PASSING);
5934 if (IN_SCR_FIELD(SCREENX(newx), SCREENY(newy)))
5935 DrawGraphicThruMask(SCREENX(newx),SCREENY(newy), el2img(element), 0);
5937 local_player->friends_still_needed--;
5938 if (!local_player->friends_still_needed &&
5939 !local_player->GameOver && AllPlayersGone)
5940 PlayerWins(local_player);
5944 else if (IS_FOOD_PENGUIN(Feld[newx][newy]))
5946 if (DigField(local_player, x, y, newx, newy, 0,0, DF_DIG) == MP_MOVING)
5947 DrawLevelField(newx, newy);
5949 GfxDir[x][y] = MovDir[x][y] = MV_NONE;
5951 else if (!IS_FREE(newx, newy))
5953 GfxAction[x][y] = ACTION_WAITING;
5955 if (IS_PLAYER(x, y))
5956 DrawPlayerField(x, y);
5958 DrawLevelField(x, y);
5963 else if (element == EL_PIG && IN_LEV_FIELD(newx, newy))
5965 if (IS_FOOD_PIG(Feld[newx][newy]))
5967 if (IS_MOVING(newx, newy))
5968 RemoveMovingField(newx, newy);
5971 Feld[newx][newy] = EL_EMPTY;
5972 DrawLevelField(newx, newy);
5975 PlayLevelSound(x, y, SND_PIG_DIGGING);
5977 else if (!IS_FREE(newx, newy))
5979 if (IS_PLAYER(x, y))
5980 DrawPlayerField(x, y);
5982 DrawLevelField(x, y);
5987 else if (element == EL_EMC_ANDROID && IN_LEV_FIELD(newx, newy))
5989 if (Store[x][y] != EL_EMPTY)
5991 boolean can_clone = FALSE;
5994 /* check if element to clone is still there */
5995 for (yy = y - 1; yy <= y + 1; yy++) for (xx = x - 1; xx <= x + 1; xx++)
5997 if (IN_LEV_FIELD(xx, yy) && Feld[xx][yy] == Store[x][y])
6005 /* cannot clone or target field not free anymore -- do not clone */
6006 if (!can_clone || !ANDROID_CAN_ENTER_FIELD(element, newx, newy))
6007 Store[x][y] = EL_EMPTY;
6010 if (ANDROID_CAN_ENTER_FIELD(element, newx, newy))
6012 if (IS_MV_DIAGONAL(MovDir[x][y]))
6014 int diagonal_move_dir = MovDir[x][y];
6015 int stored = Store[x][y];
6016 int change_delay = 8;
6019 /* android is moving diagonally */
6021 CreateField(x, y, EL_DIAGONAL_SHRINKING);
6023 Store[x][y] = (stored == EL_ACID ? EL_EMPTY : stored);
6024 GfxElement[x][y] = EL_EMC_ANDROID;
6025 GfxAction[x][y] = ACTION_SHRINKING;
6026 GfxDir[x][y] = diagonal_move_dir;
6027 ChangeDelay[x][y] = change_delay;
6029 graphic = el_act_dir2img(GfxElement[x][y], GfxAction[x][y],
6032 DrawLevelGraphicAnimation(x, y, graphic);
6033 PlayLevelSoundAction(x, y, ACTION_SHRINKING);
6035 if (Feld[newx][newy] == EL_ACID)
6037 SplashAcid(newx, newy);
6042 CreateField(newx, newy, EL_DIAGONAL_GROWING);
6044 Store[newx][newy] = EL_EMC_ANDROID;
6045 GfxElement[newx][newy] = EL_EMC_ANDROID;
6046 GfxAction[newx][newy] = ACTION_GROWING;
6047 GfxDir[newx][newy] = diagonal_move_dir;
6048 ChangeDelay[newx][newy] = change_delay;
6050 graphic = el_act_dir2img(GfxElement[newx][newy],
6051 GfxAction[newx][newy], GfxDir[newx][newy]);
6053 DrawLevelGraphicAnimation(newx, newy, graphic);
6054 PlayLevelSoundAction(newx, newy, ACTION_GROWING);
6060 Feld[newx][newy] = EL_EMPTY;
6061 DrawLevelField(newx, newy);
6063 PlayLevelSoundAction(x, y, ACTION_DIGGING);
6066 else if (!IS_FREE(newx, newy))
6069 if (IS_PLAYER(x, y))
6070 DrawPlayerField(x, y);
6072 DrawLevelField(x, y);
6078 else if (IS_CUSTOM_ELEMENT(element) &&
6079 CUSTOM_ELEMENT_CAN_ENTER_FIELD(element, newx, newy))
6081 int new_element = Feld[newx][newy];
6083 if (!IS_FREE(newx, newy))
6085 int action = (IS_DIGGABLE(new_element) ? ACTION_DIGGING :
6086 IS_COLLECTIBLE(new_element) ? ACTION_COLLECTING :
6089 /* no element can dig solid indestructible elements */
6090 if (IS_INDESTRUCTIBLE(new_element) &&
6091 !IS_DIGGABLE(new_element) &&
6092 !IS_COLLECTIBLE(new_element))
6095 if (AmoebaNr[newx][newy] &&
6096 (new_element == EL_AMOEBA_FULL ||
6097 new_element == EL_BD_AMOEBA ||
6098 new_element == EL_AMOEBA_GROWING))
6100 AmoebaCnt[AmoebaNr[newx][newy]]--;
6101 AmoebaCnt2[AmoebaNr[newx][newy]]--;
6104 if (IS_MOVING(newx, newy))
6105 RemoveMovingField(newx, newy);
6108 RemoveField(newx, newy);
6109 DrawLevelField(newx, newy);
6112 /* if digged element was about to explode, prevent the explosion */
6113 ExplodeField[newx][newy] = EX_TYPE_NONE;
6115 PlayLevelSoundAction(x, y, action);
6118 Store[newx][newy] = EL_EMPTY;
6120 /* this makes it possible to leave the removed element again */
6121 if (IS_EQUAL_OR_IN_GROUP(new_element, MOVE_ENTER_EL(element)))
6122 Store[newx][newy] = new_element;
6124 if (IS_EQUAL_OR_IN_GROUP(new_element, MOVE_ENTER_EL(element)))
6126 int move_leave_element = element_info[element].move_leave_element;
6128 /* this makes it possible to leave the removed element again */
6129 Store[newx][newy] = (move_leave_element == EL_TRIGGER_ELEMENT ?
6130 new_element : move_leave_element);
6134 if (move_pattern & MV_MAZE_RUNNER_STYLE)
6136 RunnerVisit[x][y] = FrameCounter;
6137 PlayerVisit[x][y] /= 8; /* expire player visit path */
6140 else if (element == EL_DRAGON && IN_LEV_FIELD(newx, newy))
6142 if (!IS_FREE(newx, newy))
6144 if (IS_PLAYER(x, y))
6145 DrawPlayerField(x, y);
6147 DrawLevelField(x, y);
6153 boolean wanna_flame = !RND(10);
6154 int dx = newx - x, dy = newy - y;
6155 int newx1 = newx + 1 * dx, newy1 = newy + 1 * dy;
6156 int newx2 = newx + 2 * dx, newy2 = newy + 2 * dy;
6157 int element1 = (IN_LEV_FIELD(newx1, newy1) ?
6158 MovingOrBlocked2Element(newx1, newy1) : EL_STEELWALL);
6159 int element2 = (IN_LEV_FIELD(newx2, newy2) ?
6160 MovingOrBlocked2Element(newx2, newy2) : EL_STEELWALL);
6163 IS_CLASSIC_ENEMY(element1) ||
6164 IS_CLASSIC_ENEMY(element2)) &&
6165 element1 != EL_DRAGON && element2 != EL_DRAGON &&
6166 element1 != EL_FLAMES && element2 != EL_FLAMES)
6168 ResetGfxAnimation(x, y);
6169 GfxAction[x][y] = ACTION_ATTACKING;
6171 if (IS_PLAYER(x, y))
6172 DrawPlayerField(x, y);
6174 DrawLevelField(x, y);
6176 PlayLevelSound(x, y, SND_DRAGON_ATTACKING);
6178 MovDelay[x][y] = 50;
6182 RemoveField(newx, newy);
6184 Feld[newx][newy] = EL_FLAMES;
6185 if (IN_LEV_FIELD(newx1, newy1) && Feld[newx1][newy1] == EL_EMPTY)
6188 RemoveField(newx1, newy1);
6190 Feld[newx1][newy1] = EL_FLAMES;
6192 if (IN_LEV_FIELD(newx2, newy2) && Feld[newx2][newy2] == EL_EMPTY)
6195 RemoveField(newx2, newy2);
6197 Feld[newx2][newy2] = EL_FLAMES;
6204 else if (element == EL_YAMYAM && IN_LEV_FIELD(newx, newy) &&
6205 Feld[newx][newy] == EL_DIAMOND)
6207 if (IS_MOVING(newx, newy))
6208 RemoveMovingField(newx, newy);
6211 Feld[newx][newy] = EL_EMPTY;
6212 DrawLevelField(newx, newy);
6215 PlayLevelSound(x, y, SND_YAMYAM_DIGGING);
6217 else if (element == EL_DARK_YAMYAM && IN_LEV_FIELD(newx, newy) &&
6218 IS_FOOD_DARK_YAMYAM(Feld[newx][newy]))
6220 if (AmoebaNr[newx][newy])
6222 AmoebaCnt2[AmoebaNr[newx][newy]]--;
6223 if (Feld[newx][newy] == EL_AMOEBA_FULL ||
6224 Feld[newx][newy] == EL_BD_AMOEBA)
6225 AmoebaCnt[AmoebaNr[newx][newy]]--;
6230 if (IS_MOVING(newx, newy) || IS_BLOCKED(newx, newy))
6232 RemoveMovingField(newx, newy);
6235 if (IS_MOVING(newx, newy))
6237 RemoveMovingField(newx, newy);
6242 Feld[newx][newy] = EL_EMPTY;
6243 DrawLevelField(newx, newy);
6246 PlayLevelSound(x, y, SND_DARK_YAMYAM_DIGGING);
6248 else if ((element == EL_PACMAN || element == EL_MOLE)
6249 && IN_LEV_FIELD(newx, newy) && IS_AMOEBOID(Feld[newx][newy]))
6251 if (AmoebaNr[newx][newy])
6253 AmoebaCnt2[AmoebaNr[newx][newy]]--;
6254 if (Feld[newx][newy] == EL_AMOEBA_FULL ||
6255 Feld[newx][newy] == EL_BD_AMOEBA)
6256 AmoebaCnt[AmoebaNr[newx][newy]]--;
6259 if (element == EL_MOLE)
6261 Feld[newx][newy] = EL_AMOEBA_SHRINKING;
6262 PlayLevelSound(x, y, SND_MOLE_DIGGING);
6264 ResetGfxAnimation(x, y);
6265 GfxAction[x][y] = ACTION_DIGGING;
6266 DrawLevelField(x, y);
6268 MovDelay[newx][newy] = 0; /* start amoeba shrinking delay */
6270 return; /* wait for shrinking amoeba */
6272 else /* element == EL_PACMAN */
6274 Feld[newx][newy] = EL_EMPTY;
6275 DrawLevelField(newx, newy);
6276 PlayLevelSound(x, y, SND_PACMAN_DIGGING);
6279 else if (element == EL_MOLE && IN_LEV_FIELD(newx, newy) &&
6280 (Feld[newx][newy] == EL_AMOEBA_SHRINKING ||
6281 (Feld[newx][newy] == EL_EMPTY && Stop[newx][newy])))
6283 /* wait for shrinking amoeba to completely disappear */
6286 else if (!IN_LEV_FIELD(newx, newy) || !IS_FREE(newx, newy))
6288 /* object was running against a wall */
6293 /* !!! NEW "CE_BLOCKED" STUFF !!! -- DOES NOT WORK YET... !!! */
6294 if (move_pattern & MV_ANY_DIRECTION &&
6295 move_pattern == MovDir[x][y])
6297 int blocking_element =
6298 (IN_LEV_FIELD(newx, newy) ? Feld[newx][newy] : BorderElement);
6300 CheckElementChangeBySide(x, y, element, blocking_element, CE_BLOCKED,
6303 element = Feld[x][y]; /* element might have changed */
6307 if (GFX_ELEMENT(element) != EL_SAND) /* !!! FIX THIS (crumble) !!! */
6308 DrawLevelElementAnimation(x, y, element);
6310 if (DONT_TOUCH(element))
6311 TestIfBadThingTouchesPlayer(x, y);
6316 InitMovingField(x, y, MovDir[x][y]);
6318 PlayLevelSoundAction(x, y, ACTION_MOVING);
6322 ContinueMoving(x, y);
6325 void ContinueMoving(int x, int y)
6327 int element = Feld[x][y];
6328 struct ElementInfo *ei = &element_info[element];
6329 int direction = MovDir[x][y];
6330 int dx = (direction == MV_LEFT ? -1 : direction == MV_RIGHT ? +1 : 0);
6331 int dy = (direction == MV_UP ? -1 : direction == MV_DOWN ? +1 : 0);
6332 int newx = x + dx, newy = y + dy;
6333 int stored = Store[x][y];
6334 int stored_new = Store[newx][newy];
6335 boolean pushed_by_player = (Pushed[x][y] && IS_PLAYER(x, y));
6336 boolean pushed_by_conveyor = (Pushed[x][y] && !IS_PLAYER(x, y));
6337 boolean last_line = (newy == lev_fieldy - 1);
6339 MovPos[x][y] += getElementMoveStepsize(x, y);
6341 if (pushed_by_player) /* special case: moving object pushed by player */
6342 MovPos[x][y] = SIGN(MovPos[x][y]) * (TILEX - ABS(PLAYERINFO(x,y)->MovPos));
6344 if (ABS(MovPos[x][y]) < TILEX)
6346 DrawLevelField(x, y);
6348 return; /* element is still moving */
6351 /* element reached destination field */
6353 Feld[x][y] = EL_EMPTY;
6354 Feld[newx][newy] = element;
6355 MovPos[x][y] = 0; /* force "not moving" for "crumbled sand" */
6357 if (Store[x][y] == EL_ACID) /* element is moving into acid pool */
6359 element = Feld[newx][newy] = EL_ACID;
6361 else if (element == EL_MOLE)
6363 Feld[x][y] = EL_SAND;
6365 DrawLevelFieldCrumbledSandNeighbours(x, y);
6367 else if (element == EL_QUICKSAND_FILLING)
6369 element = Feld[newx][newy] = get_next_element(element);
6370 Store[newx][newy] = Store[x][y];
6372 else if (element == EL_QUICKSAND_EMPTYING)
6374 Feld[x][y] = get_next_element(element);
6375 element = Feld[newx][newy] = Store[x][y];
6377 else if (element == EL_MAGIC_WALL_FILLING)
6379 element = Feld[newx][newy] = get_next_element(element);
6380 if (!game.magic_wall_active)
6381 element = Feld[newx][newy] = EL_MAGIC_WALL_DEAD;
6382 Store[newx][newy] = Store[x][y];
6384 else if (element == EL_MAGIC_WALL_EMPTYING)
6386 Feld[x][y] = get_next_element(element);
6387 if (!game.magic_wall_active)
6388 Feld[x][y] = EL_MAGIC_WALL_DEAD;
6389 element = Feld[newx][newy] = Store[x][y];
6391 #if USE_NEW_CUSTOM_VALUE
6392 InitField(newx, newy, FALSE);
6395 else if (element == EL_BD_MAGIC_WALL_FILLING)
6397 element = Feld[newx][newy] = get_next_element(element);
6398 if (!game.magic_wall_active)
6399 element = Feld[newx][newy] = EL_BD_MAGIC_WALL_DEAD;
6400 Store[newx][newy] = Store[x][y];
6402 else if (element == EL_BD_MAGIC_WALL_EMPTYING)
6404 Feld[x][y] = get_next_element(element);
6405 if (!game.magic_wall_active)
6406 Feld[x][y] = EL_BD_MAGIC_WALL_DEAD;
6407 element = Feld[newx][newy] = Store[x][y];
6409 #if USE_NEW_CUSTOM_VALUE
6410 InitField(newx, newy, FALSE);
6413 else if (element == EL_AMOEBA_DROPPING)
6415 Feld[x][y] = get_next_element(element);
6416 element = Feld[newx][newy] = Store[x][y];
6418 else if (element == EL_SOKOBAN_OBJECT)
6421 Feld[x][y] = Back[x][y];
6423 if (Back[newx][newy])
6424 Feld[newx][newy] = EL_SOKOBAN_FIELD_FULL;
6426 Back[x][y] = Back[newx][newy] = 0;
6429 Store[x][y] = EL_EMPTY;
6434 MovDelay[newx][newy] = 0;
6436 if (CAN_CHANGE_OR_HAS_ACTION(element))
6438 /* copy element change control values to new field */
6439 ChangeDelay[newx][newy] = ChangeDelay[x][y];
6440 ChangePage[newx][newy] = ChangePage[x][y];
6441 ChangeCount[newx][newy] = ChangeCount[x][y];
6442 ChangeEvent[newx][newy] = ChangeEvent[x][y];
6445 #if USE_NEW_CUSTOM_VALUE
6446 CustomValue[newx][newy] = CustomValue[x][y];
6449 ChangeDelay[x][y] = 0;
6450 ChangePage[x][y] = -1;
6451 ChangeCount[x][y] = 0;
6452 ChangeEvent[x][y] = -1;
6454 #if USE_NEW_CUSTOM_VALUE
6455 CustomValue[x][y] = 0;
6458 /* copy animation control values to new field */
6459 GfxFrame[newx][newy] = GfxFrame[x][y];
6460 GfxRandom[newx][newy] = GfxRandom[x][y]; /* keep same random value */
6461 GfxAction[newx][newy] = GfxAction[x][y]; /* keep action one frame */
6462 GfxDir[newx][newy] = GfxDir[x][y]; /* keep element direction */
6464 Pushed[x][y] = Pushed[newx][newy] = FALSE;
6466 /* some elements can leave other elements behind after moving */
6468 if (ei->move_leave_element != EL_EMPTY &&
6469 (ei->move_leave_type == LEAVE_TYPE_UNLIMITED || stored != EL_EMPTY) &&
6470 (!IS_PLAYER(x, y) || IS_WALKABLE(ei->move_leave_element)))
6472 if (IS_CUSTOM_ELEMENT(element) && ei->move_leave_element != EL_EMPTY &&
6473 (ei->move_leave_type == LEAVE_TYPE_UNLIMITED || stored != EL_EMPTY) &&
6474 (!IS_PLAYER(x, y) || IS_WALKABLE(ei->move_leave_element)))
6477 int move_leave_element = ei->move_leave_element;
6481 /* this makes it possible to leave the removed element again */
6482 if (ei->move_leave_element == EL_TRIGGER_ELEMENT)
6483 move_leave_element = (stored == EL_ACID ? EL_EMPTY : stored);
6485 /* this makes it possible to leave the removed element again */
6486 if (ei->move_leave_element == EL_TRIGGER_ELEMENT)
6487 move_leave_element = stored;
6490 /* this makes it possible to leave the removed element again */
6491 if (ei->move_leave_type == LEAVE_TYPE_LIMITED &&
6492 ei->move_leave_element == EL_TRIGGER_ELEMENT)
6493 move_leave_element = stored;
6496 Feld[x][y] = move_leave_element;
6498 if (element_info[Feld[x][y]].move_direction_initial == MV_START_PREVIOUS)
6499 MovDir[x][y] = direction;
6501 InitField(x, y, FALSE);
6503 if (GFX_CRUMBLED(Feld[x][y]))
6504 DrawLevelFieldCrumbledSandNeighbours(x, y);
6506 if (ELEM_IS_PLAYER(move_leave_element))
6507 RelocatePlayer(x, y, move_leave_element);
6510 /* do this after checking for left-behind element */
6511 ResetGfxAnimation(x, y); /* reset animation values for old field */
6513 if (!CAN_MOVE(element) ||
6514 (CAN_FALL(element) && direction == MV_DOWN &&
6515 (element == EL_SPRING ||
6516 element_info[element].move_pattern == MV_WHEN_PUSHED ||
6517 element_info[element].move_pattern == MV_WHEN_DROPPED)))
6518 GfxDir[x][y] = MovDir[newx][newy] = 0;
6520 DrawLevelField(x, y);
6521 DrawLevelField(newx, newy);
6523 Stop[newx][newy] = TRUE; /* ignore this element until the next frame */
6525 /* prevent pushed element from moving on in pushed direction */
6526 if (pushed_by_player && CAN_MOVE(element) &&
6527 element_info[element].move_pattern & MV_ANY_DIRECTION &&
6528 !(element_info[element].move_pattern & direction))
6529 TurnRound(newx, newy);
6531 /* prevent elements on conveyor belt from moving on in last direction */
6532 if (pushed_by_conveyor && CAN_FALL(element) &&
6533 direction & MV_HORIZONTAL)
6534 MovDir[newx][newy] = 0;
6536 if (!pushed_by_player)
6538 int nextx = newx + dx, nexty = newy + dy;
6539 boolean check_collision_again = IN_LEV_FIELD_AND_IS_FREE(nextx, nexty);
6541 WasJustMoving[newx][newy] = CHECK_DELAY_MOVING;
6543 if (CAN_FALL(element) && direction == MV_DOWN)
6544 WasJustFalling[newx][newy] = CHECK_DELAY_FALLING;
6546 if ((!CAN_FALL(element) || direction == MV_DOWN) && check_collision_again)
6547 CheckCollision[newx][newy] = CHECK_DELAY_COLLISION;
6550 if (DONT_TOUCH(element)) /* object may be nasty to player or others */
6552 TestIfBadThingTouchesPlayer(newx, newy);
6553 TestIfBadThingTouchesFriend(newx, newy);
6555 if (!IS_CUSTOM_ELEMENT(element))
6556 TestIfBadThingTouchesOtherBadThing(newx, newy);
6558 else if (element == EL_PENGUIN)
6559 TestIfFriendTouchesBadThing(newx, newy);
6561 /* give the player one last chance (one more frame) to move away */
6562 if (CAN_FALL(element) && direction == MV_DOWN &&
6563 (last_line || (!IS_FREE(x, newy + 1) &&
6564 (!IS_PLAYER(x, newy + 1) ||
6565 game.engine_version < VERSION_IDENT(3,1,1,0)))))
6568 if (pushed_by_player && !game.use_change_when_pushing_bug)
6570 int push_side = MV_DIR_OPPOSITE(direction);
6571 struct PlayerInfo *player = PLAYERINFO(x, y);
6573 CheckElementChangeByPlayer(newx, newy, element, CE_PUSHED_BY_PLAYER,
6574 player->index_bit, push_side);
6575 CheckTriggeredElementChangeByPlayer(newx,newy, element, CE_PLAYER_PUSHES_X,
6576 player->index_bit, push_side);
6579 if (element == EL_EMC_ANDROID && pushed_by_player) /* make another move */
6580 MovDelay[newx][newy] = 1;
6582 CheckTriggeredElementChangeBySide(x, y, element, CE_MOVE_OF_X, direction);
6584 TestIfElementTouchesCustomElement(x, y); /* empty or new element */
6587 if (ChangePage[newx][newy] != -1) /* delayed change */
6589 int page = ChangePage[newx][newy];
6590 struct ElementChangeInfo *change = &ei->change_page[page];
6592 ChangePage[newx][newy] = -1;
6594 if (change->can_change)
6596 if (ChangeElement(newx, newy, element, page))
6598 if (change->post_change_function)
6599 change->post_change_function(newx, newy);
6603 if (change->has_action)
6604 ExecuteCustomElementAction(newx, newy, element, page);
6608 TestIfElementHitsCustomElement(newx, newy, direction);
6609 TestIfPlayerTouchesCustomElement(newx, newy);
6610 TestIfElementTouchesCustomElement(newx, newy);
6612 if (IS_CUSTOM_ELEMENT(element) && ei->move_enter_element != EL_EMPTY &&
6613 IS_EQUAL_OR_IN_GROUP(stored_new, ei->move_enter_element))
6614 CheckElementChangeBySide(newx, newy, element, stored_new, CE_DIGGING_X,
6615 MV_DIR_OPPOSITE(direction));
6618 int AmoebeNachbarNr(int ax, int ay)
6621 int element = Feld[ax][ay];
6623 static int xy[4][2] =
6631 for (i = 0; i < NUM_DIRECTIONS; i++)
6633 int x = ax + xy[i][0];
6634 int y = ay + xy[i][1];
6636 if (!IN_LEV_FIELD(x, y))
6639 if (Feld[x][y] == element && AmoebaNr[x][y] > 0)
6640 group_nr = AmoebaNr[x][y];
6646 void AmoebenVereinigen(int ax, int ay)
6648 int i, x, y, xx, yy;
6649 int new_group_nr = AmoebaNr[ax][ay];
6650 static int xy[4][2] =
6658 if (new_group_nr == 0)
6661 for (i = 0; i < NUM_DIRECTIONS; i++)
6666 if (!IN_LEV_FIELD(x, y))
6669 if ((Feld[x][y] == EL_AMOEBA_FULL ||
6670 Feld[x][y] == EL_BD_AMOEBA ||
6671 Feld[x][y] == EL_AMOEBA_DEAD) &&
6672 AmoebaNr[x][y] != new_group_nr)
6674 int old_group_nr = AmoebaNr[x][y];
6676 if (old_group_nr == 0)
6679 AmoebaCnt[new_group_nr] += AmoebaCnt[old_group_nr];
6680 AmoebaCnt[old_group_nr] = 0;
6681 AmoebaCnt2[new_group_nr] += AmoebaCnt2[old_group_nr];
6682 AmoebaCnt2[old_group_nr] = 0;
6684 SCAN_PLAYFIELD(xx, yy)
6686 if (AmoebaNr[xx][yy] == old_group_nr)
6687 AmoebaNr[xx][yy] = new_group_nr;
6693 void AmoebeUmwandeln(int ax, int ay)
6697 if (Feld[ax][ay] == EL_AMOEBA_DEAD)
6699 int group_nr = AmoebaNr[ax][ay];
6704 printf("AmoebeUmwandeln(): ax = %d, ay = %d\n", ax, ay);
6705 printf("AmoebeUmwandeln(): This should never happen!\n");
6710 SCAN_PLAYFIELD(x, y)
6712 if (Feld[x][y] == EL_AMOEBA_DEAD && AmoebaNr[x][y] == group_nr)
6715 Feld[x][y] = EL_AMOEBA_TO_DIAMOND;
6719 PlayLevelSound(ax, ay, (IS_GEM(level.amoeba_content) ?
6720 SND_AMOEBA_TURNING_TO_GEM :
6721 SND_AMOEBA_TURNING_TO_ROCK));
6726 static int xy[4][2] =
6734 for (i = 0; i < NUM_DIRECTIONS; i++)
6739 if (!IN_LEV_FIELD(x, y))
6742 if (Feld[x][y] == EL_AMOEBA_TO_DIAMOND)
6744 PlayLevelSound(x, y, (IS_GEM(level.amoeba_content) ?
6745 SND_AMOEBA_TURNING_TO_GEM :
6746 SND_AMOEBA_TURNING_TO_ROCK));
6753 void AmoebeUmwandelnBD(int ax, int ay, int new_element)
6756 int group_nr = AmoebaNr[ax][ay];
6757 boolean done = FALSE;
6762 printf("AmoebeUmwandelnBD(): ax = %d, ay = %d\n", ax, ay);
6763 printf("AmoebeUmwandelnBD(): This should never happen!\n");
6768 SCAN_PLAYFIELD(x, y)
6770 if (AmoebaNr[x][y] == group_nr &&
6771 (Feld[x][y] == EL_AMOEBA_DEAD ||
6772 Feld[x][y] == EL_BD_AMOEBA ||
6773 Feld[x][y] == EL_AMOEBA_GROWING))
6776 Feld[x][y] = new_element;
6777 InitField(x, y, FALSE);
6778 DrawLevelField(x, y);
6784 PlayLevelSound(ax, ay, (new_element == EL_BD_ROCK ?
6785 SND_BD_AMOEBA_TURNING_TO_ROCK :
6786 SND_BD_AMOEBA_TURNING_TO_GEM));
6789 void AmoebeWaechst(int x, int y)
6791 static unsigned long sound_delay = 0;
6792 static unsigned long sound_delay_value = 0;
6794 if (!MovDelay[x][y]) /* start new growing cycle */
6798 if (DelayReached(&sound_delay, sound_delay_value))
6800 PlayLevelSoundElementAction(x, y, Store[x][y], ACTION_GROWING);
6801 sound_delay_value = 30;
6805 if (MovDelay[x][y]) /* wait some time before growing bigger */
6808 if (MovDelay[x][y]/2 && IN_SCR_FIELD(SCREENX(x), SCREENY(y)))
6810 int frame = getGraphicAnimationFrame(IMG_AMOEBA_GROWING,
6811 6 - MovDelay[x][y]);
6813 DrawGraphic(SCREENX(x), SCREENY(y), IMG_AMOEBA_GROWING, frame);
6816 if (!MovDelay[x][y])
6818 Feld[x][y] = Store[x][y];
6820 DrawLevelField(x, y);
6825 void AmoebaDisappearing(int x, int y)
6827 static unsigned long sound_delay = 0;
6828 static unsigned long sound_delay_value = 0;
6830 if (!MovDelay[x][y]) /* start new shrinking cycle */
6834 if (DelayReached(&sound_delay, sound_delay_value))
6835 sound_delay_value = 30;
6838 if (MovDelay[x][y]) /* wait some time before shrinking */
6841 if (MovDelay[x][y]/2 && IN_SCR_FIELD(SCREENX(x), SCREENY(y)))
6843 int frame = getGraphicAnimationFrame(IMG_AMOEBA_SHRINKING,
6844 6 - MovDelay[x][y]);
6846 DrawGraphic(SCREENX(x), SCREENY(y), IMG_AMOEBA_SHRINKING, frame);
6849 if (!MovDelay[x][y])
6851 Feld[x][y] = EL_EMPTY;
6852 DrawLevelField(x, y);
6854 /* don't let mole enter this field in this cycle;
6855 (give priority to objects falling to this field from above) */
6861 void AmoebeAbleger(int ax, int ay)
6864 int element = Feld[ax][ay];
6865 int graphic = el2img(element);
6866 int newax = ax, neway = ay;
6867 boolean can_drop = (element == EL_AMOEBA_WET || element == EL_EMC_DRIPPER);
6868 static int xy[4][2] =
6876 if (!level.amoeba_speed && element != EL_EMC_DRIPPER)
6878 Feld[ax][ay] = EL_AMOEBA_DEAD;
6879 DrawLevelField(ax, ay);
6883 if (IS_ANIMATED(graphic))
6884 DrawLevelGraphicAnimationIfNeeded(ax, ay, graphic);
6886 if (!MovDelay[ax][ay]) /* start making new amoeba field */
6887 MovDelay[ax][ay] = RND(FRAMES_PER_SECOND * 25 / (1 + level.amoeba_speed));
6889 if (MovDelay[ax][ay]) /* wait some time before making new amoeba */
6892 if (MovDelay[ax][ay])
6896 if (can_drop) /* EL_AMOEBA_WET or EL_EMC_DRIPPER */
6899 int x = ax + xy[start][0];
6900 int y = ay + xy[start][1];
6902 if (!IN_LEV_FIELD(x, y))
6905 if (IS_FREE(x, y) ||
6906 CAN_GROW_INTO(Feld[x][y]) ||
6907 Feld[x][y] == EL_QUICKSAND_EMPTY)
6913 if (newax == ax && neway == ay)
6916 else /* normal or "filled" (BD style) amoeba */
6919 boolean waiting_for_player = FALSE;
6921 for (i = 0; i < NUM_DIRECTIONS; i++)
6923 int j = (start + i) % 4;
6924 int x = ax + xy[j][0];
6925 int y = ay + xy[j][1];
6927 if (!IN_LEV_FIELD(x, y))
6930 if (IS_FREE(x, y) ||
6931 CAN_GROW_INTO(Feld[x][y]) ||
6932 Feld[x][y] == EL_QUICKSAND_EMPTY)
6938 else if (IS_PLAYER(x, y))
6939 waiting_for_player = TRUE;
6942 if (newax == ax && neway == ay) /* amoeba cannot grow */
6944 if (i == 4 && (!waiting_for_player || element == EL_BD_AMOEBA))
6946 Feld[ax][ay] = EL_AMOEBA_DEAD;
6947 DrawLevelField(ax, ay);
6948 AmoebaCnt[AmoebaNr[ax][ay]]--;
6950 if (AmoebaCnt[AmoebaNr[ax][ay]] <= 0) /* amoeba is completely dead */
6952 if (element == EL_AMOEBA_FULL)
6953 AmoebeUmwandeln(ax, ay);
6954 else if (element == EL_BD_AMOEBA)
6955 AmoebeUmwandelnBD(ax, ay, level.amoeba_content);
6960 else if (element == EL_AMOEBA_FULL || element == EL_BD_AMOEBA)
6962 /* amoeba gets larger by growing in some direction */
6964 int new_group_nr = AmoebaNr[ax][ay];
6967 if (new_group_nr == 0)
6969 printf("AmoebeAbleger(): newax = %d, neway = %d\n", newax, neway);
6970 printf("AmoebeAbleger(): This should never happen!\n");
6975 AmoebaNr[newax][neway] = new_group_nr;
6976 AmoebaCnt[new_group_nr]++;
6977 AmoebaCnt2[new_group_nr]++;
6979 /* if amoeba touches other amoeba(s) after growing, unify them */
6980 AmoebenVereinigen(newax, neway);
6982 if (element == EL_BD_AMOEBA && AmoebaCnt2[new_group_nr] >= 200)
6984 AmoebeUmwandelnBD(newax, neway, EL_BD_ROCK);
6990 if (!can_drop || neway < ay || !IS_FREE(newax, neway) ||
6991 (neway == lev_fieldy - 1 && newax != ax))
6993 Feld[newax][neway] = EL_AMOEBA_GROWING; /* creation of new amoeba */
6994 Store[newax][neway] = element;
6996 else if (neway == ay || element == EL_EMC_DRIPPER)
6998 Feld[newax][neway] = EL_AMOEBA_DROP; /* drop left/right of amoeba */
7000 PlayLevelSoundAction(newax, neway, ACTION_GROWING);
7004 InitMovingField(ax, ay, MV_DOWN); /* drop dripping from amoeba */
7005 Feld[ax][ay] = EL_AMOEBA_DROPPING;
7006 Store[ax][ay] = EL_AMOEBA_DROP;
7007 ContinueMoving(ax, ay);
7011 DrawLevelField(newax, neway);
7014 void Life(int ax, int ay)
7018 int element = Feld[ax][ay];
7019 int graphic = el2img(element);
7020 int *life_parameter = (element == EL_GAME_OF_LIFE ? level.game_of_life :
7022 boolean changed = FALSE;
7024 if (IS_ANIMATED(graphic))
7025 DrawLevelGraphicAnimationIfNeeded(ax, ay, graphic);
7030 if (!MovDelay[ax][ay]) /* start new "game of life" cycle */
7031 MovDelay[ax][ay] = life_time;
7033 if (MovDelay[ax][ay]) /* wait some time before next cycle */
7036 if (MovDelay[ax][ay])
7040 for (y1 = -1; y1 < 2; y1++) for (x1 = -1; x1 < 2; x1++)
7042 int xx = ax+x1, yy = ay+y1;
7045 if (!IN_LEV_FIELD(xx, yy))
7048 for (y2 = -1; y2 < 2; y2++) for (x2 = -1; x2 < 2; x2++)
7050 int x = xx+x2, y = yy+y2;
7052 if (!IN_LEV_FIELD(x, y) || (x == xx && y == yy))
7055 if (((Feld[x][y] == element ||
7056 (element == EL_GAME_OF_LIFE && IS_PLAYER(x, y))) &&
7058 (IS_FREE(x, y) && Stop[x][y]))
7062 if (xx == ax && yy == ay) /* field in the middle */
7064 if (nachbarn < life_parameter[0] ||
7065 nachbarn > life_parameter[1])
7067 Feld[xx][yy] = EL_EMPTY;
7069 DrawLevelField(xx, yy);
7070 Stop[xx][yy] = TRUE;
7074 else if (IS_FREE(xx, yy) || CAN_GROW_INTO(Feld[xx][yy]))
7075 { /* free border field */
7076 if (nachbarn >= life_parameter[2] &&
7077 nachbarn <= life_parameter[3])
7079 Feld[xx][yy] = element;
7080 MovDelay[xx][yy] = (element == EL_GAME_OF_LIFE ? 0 : life_time-1);
7082 DrawLevelField(xx, yy);
7083 Stop[xx][yy] = TRUE;
7090 PlayLevelSound(ax, ay, element == EL_BIOMAZE ? SND_BIOMAZE_GROWING :
7091 SND_GAME_OF_LIFE_GROWING);
7094 static void InitRobotWheel(int x, int y)
7096 ChangeDelay[x][y] = level.time_wheel * FRAMES_PER_SECOND;
7099 static void RunRobotWheel(int x, int y)
7101 PlayLevelSound(x, y, SND_ROBOT_WHEEL_ACTIVE);
7104 static void StopRobotWheel(int x, int y)
7106 if (ZX == x && ZY == y)
7110 static void InitTimegateWheel(int x, int y)
7112 ChangeDelay[x][y] = level.time_timegate * FRAMES_PER_SECOND;
7115 static void RunTimegateWheel(int x, int y)
7117 PlayLevelSound(x, y, SND_TIMEGATE_SWITCH_ACTIVE);
7120 static void InitMagicBallDelay(int x, int y)
7123 ChangeDelay[x][y] = (level.ball_time + 1) * 8 + 1;
7125 ChangeDelay[x][y] = level.ball_time * FRAMES_PER_SECOND + 1;
7129 static void ActivateMagicBall(int bx, int by)
7133 if (level.ball_random)
7135 int pos_border = RND(8); /* select one of the eight border elements */
7136 int pos_content = (pos_border > 3 ? pos_border + 1 : pos_border);
7137 int xx = pos_content % 3;
7138 int yy = pos_content / 3;
7143 if (IN_LEV_FIELD(x, y) && Feld[x][y] == EL_EMPTY)
7144 CreateField(x, y, level.ball_content[game.ball_content_nr].e[xx][yy]);
7148 for (y = by - 1; y <= by + 1; y++) for (x = bx - 1; x <= bx + 1; x++)
7150 int xx = x - bx + 1;
7151 int yy = y - by + 1;
7153 if (IN_LEV_FIELD(x, y) && Feld[x][y] == EL_EMPTY)
7154 CreateField(x, y, level.ball_content[game.ball_content_nr].e[xx][yy]);
7158 game.ball_content_nr = (game.ball_content_nr + 1) % level.num_ball_contents;
7161 void CheckExit(int x, int y)
7163 if (local_player->gems_still_needed > 0 ||
7164 local_player->sokobanfields_still_needed > 0 ||
7165 local_player->lights_still_needed > 0)
7167 int element = Feld[x][y];
7168 int graphic = el2img(element);
7170 if (IS_ANIMATED(graphic))
7171 DrawLevelGraphicAnimationIfNeeded(x, y, graphic);
7176 if (AllPlayersGone) /* do not re-open exit door closed after last player */
7179 Feld[x][y] = EL_EXIT_OPENING;
7181 PlayLevelSoundNearest(x, y, SND_CLASS_EXIT_OPENING);
7184 void CheckExitSP(int x, int y)
7186 if (local_player->gems_still_needed > 0)
7188 int element = Feld[x][y];
7189 int graphic = el2img(element);
7191 if (IS_ANIMATED(graphic))
7192 DrawLevelGraphicAnimationIfNeeded(x, y, graphic);
7197 if (AllPlayersGone) /* do not re-open exit door closed after last player */
7200 Feld[x][y] = EL_SP_EXIT_OPENING;
7202 PlayLevelSoundNearest(x, y, SND_CLASS_SP_EXIT_OPENING);
7205 static void CloseAllOpenTimegates()
7209 SCAN_PLAYFIELD(x, y)
7211 int element = Feld[x][y];
7213 if (element == EL_TIMEGATE_OPEN || element == EL_TIMEGATE_OPENING)
7215 Feld[x][y] = EL_TIMEGATE_CLOSING;
7217 PlayLevelSoundAction(x, y, ACTION_CLOSING);
7222 void EdelsteinFunkeln(int x, int y)
7224 if (!IN_SCR_FIELD(SCREENX(x), SCREENY(y)) || IS_MOVING(x, y))
7227 if (Feld[x][y] == EL_BD_DIAMOND)
7230 if (MovDelay[x][y] == 0) /* next animation frame */
7231 MovDelay[x][y] = 11 * !GetSimpleRandom(500);
7233 if (MovDelay[x][y] != 0) /* wait some time before next frame */
7237 if (setup.direct_draw && MovDelay[x][y])
7238 SetDrawtoField(DRAW_BUFFERED);
7240 DrawLevelElementAnimation(x, y, Feld[x][y]);
7242 if (MovDelay[x][y] != 0)
7244 int frame = getGraphicAnimationFrame(IMG_TWINKLE_WHITE,
7245 10 - MovDelay[x][y]);
7247 DrawGraphicThruMask(SCREENX(x), SCREENY(y), IMG_TWINKLE_WHITE, frame);
7249 if (setup.direct_draw)
7253 dest_x = FX + SCREENX(x) * TILEX;
7254 dest_y = FY + SCREENY(y) * TILEY;
7256 BlitBitmap(drawto_field, window,
7257 dest_x, dest_y, TILEX, TILEY, dest_x, dest_y);
7258 SetDrawtoField(DRAW_DIRECT);
7264 void MauerWaechst(int x, int y)
7268 if (!MovDelay[x][y]) /* next animation frame */
7269 MovDelay[x][y] = 3 * delay;
7271 if (MovDelay[x][y]) /* wait some time before next frame */
7275 if (IN_SCR_FIELD(SCREENX(x), SCREENY(y)))
7277 int graphic = el_dir2img(Feld[x][y], GfxDir[x][y]);
7278 int frame = getGraphicAnimationFrame(graphic, 17 - MovDelay[x][y]);
7280 DrawGraphic(SCREENX(x), SCREENY(y), graphic, frame);
7283 if (!MovDelay[x][y])
7285 if (MovDir[x][y] == MV_LEFT)
7287 if (IN_LEV_FIELD(x - 1, y) && IS_WALL(Feld[x - 1][y]))
7288 DrawLevelField(x - 1, y);
7290 else if (MovDir[x][y] == MV_RIGHT)
7292 if (IN_LEV_FIELD(x + 1, y) && IS_WALL(Feld[x + 1][y]))
7293 DrawLevelField(x + 1, y);
7295 else if (MovDir[x][y] == MV_UP)
7297 if (IN_LEV_FIELD(x, y - 1) && IS_WALL(Feld[x][y - 1]))
7298 DrawLevelField(x, y - 1);
7302 if (IN_LEV_FIELD(x, y + 1) && IS_WALL(Feld[x][y + 1]))
7303 DrawLevelField(x, y + 1);
7306 Feld[x][y] = Store[x][y];
7308 GfxDir[x][y] = MovDir[x][y] = MV_NONE;
7309 DrawLevelField(x, y);
7314 void MauerAbleger(int ax, int ay)
7316 int element = Feld[ax][ay];
7317 int graphic = el2img(element);
7318 boolean oben_frei = FALSE, unten_frei = FALSE;
7319 boolean links_frei = FALSE, rechts_frei = FALSE;
7320 boolean oben_massiv = FALSE, unten_massiv = FALSE;
7321 boolean links_massiv = FALSE, rechts_massiv = FALSE;
7322 boolean new_wall = FALSE;
7324 if (IS_ANIMATED(graphic))
7325 DrawLevelGraphicAnimationIfNeeded(ax, ay, graphic);
7327 if (!MovDelay[ax][ay]) /* start building new wall */
7328 MovDelay[ax][ay] = 6;
7330 if (MovDelay[ax][ay]) /* wait some time before building new wall */
7333 if (MovDelay[ax][ay])
7337 if (IN_LEV_FIELD(ax, ay-1) && IS_FREE(ax, ay-1))
7339 if (IN_LEV_FIELD(ax, ay+1) && IS_FREE(ax, ay+1))
7341 if (IN_LEV_FIELD(ax-1, ay) && IS_FREE(ax-1, ay))
7343 if (IN_LEV_FIELD(ax+1, ay) && IS_FREE(ax+1, ay))
7346 if (element == EL_EXPANDABLE_WALL_VERTICAL ||
7347 element == EL_EXPANDABLE_WALL_ANY)
7351 Feld[ax][ay-1] = EL_EXPANDABLE_WALL_GROWING;
7352 Store[ax][ay-1] = element;
7353 GfxDir[ax][ay-1] = MovDir[ax][ay-1] = MV_UP;
7354 if (IN_SCR_FIELD(SCREENX(ax), SCREENY(ay-1)))
7355 DrawGraphic(SCREENX(ax), SCREENY(ay - 1),
7356 IMG_EXPANDABLE_WALL_GROWING_UP, 0);
7361 Feld[ax][ay+1] = EL_EXPANDABLE_WALL_GROWING;
7362 Store[ax][ay+1] = element;
7363 GfxDir[ax][ay+1] = MovDir[ax][ay+1] = MV_DOWN;
7364 if (IN_SCR_FIELD(SCREENX(ax), SCREENY(ay+1)))
7365 DrawGraphic(SCREENX(ax), SCREENY(ay + 1),
7366 IMG_EXPANDABLE_WALL_GROWING_DOWN, 0);
7371 if (element == EL_EXPANDABLE_WALL_HORIZONTAL ||
7372 element == EL_EXPANDABLE_WALL_ANY ||
7373 element == EL_EXPANDABLE_WALL ||
7374 element == EL_BD_EXPANDABLE_WALL)
7378 Feld[ax-1][ay] = EL_EXPANDABLE_WALL_GROWING;
7379 Store[ax-1][ay] = element;
7380 GfxDir[ax-1][ay] = MovDir[ax-1][ay] = MV_LEFT;
7381 if (IN_SCR_FIELD(SCREENX(ax-1), SCREENY(ay)))
7382 DrawGraphic(SCREENX(ax - 1), SCREENY(ay),
7383 IMG_EXPANDABLE_WALL_GROWING_LEFT, 0);
7389 Feld[ax+1][ay] = EL_EXPANDABLE_WALL_GROWING;
7390 Store[ax+1][ay] = element;
7391 GfxDir[ax+1][ay] = MovDir[ax+1][ay] = MV_RIGHT;
7392 if (IN_SCR_FIELD(SCREENX(ax+1), SCREENY(ay)))
7393 DrawGraphic(SCREENX(ax + 1), SCREENY(ay),
7394 IMG_EXPANDABLE_WALL_GROWING_RIGHT, 0);
7399 if (element == EL_EXPANDABLE_WALL && (links_frei || rechts_frei))
7400 DrawLevelField(ax, ay);
7402 if (!IN_LEV_FIELD(ax, ay-1) || IS_WALL(Feld[ax][ay-1]))
7404 if (!IN_LEV_FIELD(ax, ay+1) || IS_WALL(Feld[ax][ay+1]))
7405 unten_massiv = TRUE;
7406 if (!IN_LEV_FIELD(ax-1, ay) || IS_WALL(Feld[ax-1][ay]))
7407 links_massiv = TRUE;
7408 if (!IN_LEV_FIELD(ax+1, ay) || IS_WALL(Feld[ax+1][ay]))
7409 rechts_massiv = TRUE;
7411 if (((oben_massiv && unten_massiv) ||
7412 element == EL_EXPANDABLE_WALL_HORIZONTAL ||
7413 element == EL_EXPANDABLE_WALL) &&
7414 ((links_massiv && rechts_massiv) ||
7415 element == EL_EXPANDABLE_WALL_VERTICAL))
7416 Feld[ax][ay] = EL_WALL;
7419 PlayLevelSoundAction(ax, ay, ACTION_GROWING);
7422 void CheckForDragon(int x, int y)
7425 boolean dragon_found = FALSE;
7426 static int xy[4][2] =
7434 for (i = 0; i < NUM_DIRECTIONS; i++)
7436 for (j = 0; j < 4; j++)
7438 int xx = x + j * xy[i][0], yy = y + j * xy[i][1];
7440 if (IN_LEV_FIELD(xx, yy) &&
7441 (Feld[xx][yy] == EL_FLAMES || Feld[xx][yy] == EL_DRAGON))
7443 if (Feld[xx][yy] == EL_DRAGON)
7444 dragon_found = TRUE;
7453 for (i = 0; i < NUM_DIRECTIONS; i++)
7455 for (j = 0; j < 3; j++)
7457 int xx = x + j * xy[i][0], yy = y + j * xy[i][1];
7459 if (IN_LEV_FIELD(xx, yy) && Feld[xx][yy] == EL_FLAMES)
7461 Feld[xx][yy] = EL_EMPTY;
7462 DrawLevelField(xx, yy);
7471 static void InitBuggyBase(int x, int y)
7473 int element = Feld[x][y];
7474 int activating_delay = FRAMES_PER_SECOND / 4;
7477 (element == EL_SP_BUGGY_BASE ?
7478 2 * FRAMES_PER_SECOND + RND(5 * FRAMES_PER_SECOND) - activating_delay :
7479 element == EL_SP_BUGGY_BASE_ACTIVATING ?
7481 element == EL_SP_BUGGY_BASE_ACTIVE ?
7482 1 * FRAMES_PER_SECOND + RND(1 * FRAMES_PER_SECOND) : 1);
7485 static void WarnBuggyBase(int x, int y)
7488 static int xy[4][2] =
7496 for (i = 0; i < NUM_DIRECTIONS; i++)
7498 int xx = x + xy[i][0];
7499 int yy = y + xy[i][1];
7501 if (IN_LEV_FIELD(xx, yy) && IS_PLAYER(xx, yy))
7503 PlayLevelSound(x, y, SND_SP_BUGGY_BASE_ACTIVE);
7510 static void InitTrap(int x, int y)
7512 ChangeDelay[x][y] = 2 * FRAMES_PER_SECOND + RND(5 * FRAMES_PER_SECOND);
7515 static void ActivateTrap(int x, int y)
7517 PlayLevelSound(x, y, SND_TRAP_ACTIVATING);
7520 static void ChangeActiveTrap(int x, int y)
7522 int graphic = IMG_TRAP_ACTIVE;
7524 /* if new animation frame was drawn, correct crumbled sand border */
7525 if (IS_NEW_FRAME(GfxFrame[x][y], graphic))
7526 DrawLevelFieldCrumbledSand(x, y);
7529 static int getSpecialActionElement(int element, int number, int base_element)
7531 return (element != EL_EMPTY ? element :
7532 number != -1 ? base_element + number - 1 :
7536 static int getModifiedActionNumber(int value_old, int operator, int operand,
7537 int value_min, int value_max)
7539 int value_new = (operator == CA_MODE_SET ? operand :
7540 operator == CA_MODE_ADD ? value_old + operand :
7541 operator == CA_MODE_SUBTRACT ? value_old - operand :
7542 operator == CA_MODE_MULTIPLY ? value_old * operand :
7543 operator == CA_MODE_DIVIDE ? value_old / MAX(1, operand) :
7544 operator == CA_MODE_MODULO ? value_old % MAX(1, operand) :
7547 return (value_new < value_min ? value_min :
7548 value_new > value_max ? value_max :
7552 static void ExecuteCustomElementAction(int x, int y, int element, int page)
7554 struct ElementInfo *ei = &element_info[element];
7555 struct ElementChangeInfo *change = &ei->change_page[page];
7556 int target_element = change->target_element;
7557 int action_type = change->action_type;
7558 int action_mode = change->action_mode;
7559 int action_arg = change->action_arg;
7562 if (!change->has_action)
7565 /* ---------- determine action paramater values -------------------------- */
7567 int level_time_value =
7568 (level.time > 0 ? TimeLeft :
7571 int action_arg_element =
7572 (action_arg == CA_ARG_PLAYER_TRIGGER ? change->actual_trigger_player :
7573 action_arg == CA_ARG_ELEMENT_TRIGGER ? change->actual_trigger_element :
7574 action_arg == CA_ARG_ELEMENT_TARGET ? change->target_element :
7577 int action_arg_direction =
7578 (action_arg >= CA_ARG_DIRECTION_LEFT &&
7579 action_arg <= CA_ARG_DIRECTION_DOWN ? action_arg - CA_ARG_DIRECTION :
7580 action_arg == CA_ARG_DIRECTION_TRIGGER ?
7581 change->actual_trigger_side :
7582 action_arg == CA_ARG_DIRECTION_TRIGGER_BACK ?
7583 MV_DIR_OPPOSITE(change->actual_trigger_side) :
7586 int action_arg_number_min =
7587 (action_type == CA_SET_PLAYER_SPEED ? STEPSIZE_NOT_MOVING :
7590 int action_arg_number_max =
7591 (action_type == CA_SET_PLAYER_SPEED ? STEPSIZE_EVEN_FASTER :
7592 action_type == CA_SET_LEVEL_GEMS ? 999 :
7593 action_type == CA_SET_LEVEL_TIME ? 9999 :
7594 action_type == CA_SET_LEVEL_SCORE ? 99999 :
7595 action_type == CA_SET_CE_VALUE ? 9999 :
7596 action_type == CA_SET_CE_SCORE ? 9999 :
7599 int action_arg_number_reset =
7600 (action_type == CA_SET_PLAYER_SPEED ? level.initial_player_stepsize[0] :
7601 action_type == CA_SET_LEVEL_GEMS ? level.gems_needed :
7602 action_type == CA_SET_LEVEL_TIME ? level.time :
7603 action_type == CA_SET_LEVEL_SCORE ? 0 :
7604 #if USE_NEW_CUSTOM_VALUE
7605 action_type == CA_SET_CE_VALUE ? GET_NEW_CE_VALUE(element) :
7607 action_type == CA_SET_CE_VALUE ? ei->custom_value_initial :
7609 action_type == CA_SET_CE_SCORE ? 0 :
7612 int action_arg_number =
7613 (action_arg <= CA_ARG_MAX ? action_arg :
7614 action_arg >= CA_ARG_SPEED_NOT_MOVING &&
7615 action_arg <= CA_ARG_SPEED_EVEN_FASTER ? (action_arg - CA_ARG_SPEED) :
7616 action_arg == CA_ARG_SPEED_RESET ? action_arg_number_reset :
7617 action_arg == CA_ARG_NUMBER_MIN ? action_arg_number_min :
7618 action_arg == CA_ARG_NUMBER_MAX ? action_arg_number_max :
7619 action_arg == CA_ARG_NUMBER_RESET ? action_arg_number_reset :
7620 #if USE_NEW_CUSTOM_VALUE
7621 action_arg == CA_ARG_NUMBER_CE_VALUE ? CustomValue[x][y] :
7623 action_arg == CA_ARG_NUMBER_CE_VALUE ? ei->custom_value_initial :
7625 action_arg == CA_ARG_NUMBER_CE_SCORE ? ei->collect_score :
7626 action_arg == CA_ARG_NUMBER_CE_DELAY ? GET_CE_DELAY_VALUE(change) :
7627 action_arg == CA_ARG_NUMBER_LEVEL_TIME ? level_time_value :
7628 action_arg == CA_ARG_NUMBER_LEVEL_GEMS ? local_player->gems_still_needed :
7629 action_arg == CA_ARG_NUMBER_LEVEL_SCORE ? local_player->score :
7630 action_arg == CA_ARG_ELEMENT_CV_TARGET ? GET_NEW_CE_VALUE(target_element):
7631 action_arg == CA_ARG_ELEMENT_CV_TRIGGER ? change->actual_trigger_ce_value:
7632 action_arg == CA_ARG_ELEMENT_CS_TARGET ? GET_CE_SCORE(target_element) :
7633 action_arg == CA_ARG_ELEMENT_CS_TRIGGER ? change->actual_trigger_ce_score:
7634 action_arg == CA_ARG_ELEMENT_NR_TARGET ? change->target_element :
7635 action_arg == CA_ARG_ELEMENT_NR_TRIGGER ? change->actual_trigger_element :
7638 int action_arg_number_old =
7639 (action_type == CA_SET_LEVEL_GEMS ? local_player->gems_still_needed :
7640 action_type == CA_SET_LEVEL_TIME ? TimeLeft :
7641 action_type == CA_SET_LEVEL_SCORE ? local_player->score :
7642 action_type == CA_SET_CE_VALUE ? CustomValue[x][y] :
7643 action_type == CA_SET_CE_SCORE ? ei->collect_score :
7646 int action_arg_number_new =
7647 getModifiedActionNumber(action_arg_number_old,
7648 action_mode, action_arg_number,
7649 action_arg_number_min, action_arg_number_max);
7651 int trigger_player_bits =
7652 (change->actual_trigger_player >= EL_PLAYER_1 &&
7653 change->actual_trigger_player <= EL_PLAYER_4 ?
7654 (1 << (change->actual_trigger_player - EL_PLAYER_1)) :
7657 int action_arg_player_bits =
7658 (action_arg >= CA_ARG_PLAYER_1 &&
7659 action_arg <= CA_ARG_PLAYER_4 ? action_arg - CA_ARG_PLAYER :
7660 action_arg == CA_ARG_PLAYER_TRIGGER ? trigger_player_bits :
7663 /* ---------- execute action -------------------------------------------- */
7672 /* ---------- level actions ------------------------------------------- */
7674 case CA_RESTART_LEVEL:
7676 game.restart_level = TRUE;
7681 case CA_SHOW_ENVELOPE:
7683 int element = getSpecialActionElement(action_arg_element,
7684 action_arg_number, EL_ENVELOPE_1);
7686 if (IS_ENVELOPE(element))
7687 local_player->show_envelope = element;
7692 case CA_SET_LEVEL_TIME:
7694 if (level.time > 0) /* only modify limited time value */
7696 TimeLeft = action_arg_number_new;
7698 DrawGameValue_Time(TimeLeft);
7700 if (!TimeLeft && setup.time_limit)
7701 for (i = 0; i < MAX_PLAYERS; i++)
7702 KillPlayer(&stored_player[i]);
7708 case CA_SET_LEVEL_SCORE:
7710 local_player->score = action_arg_number_new;
7712 DrawGameValue_Score(local_player->score);
7717 case CA_SET_LEVEL_GEMS:
7719 local_player->gems_still_needed = action_arg_number_new;
7721 DrawGameValue_Emeralds(local_player->gems_still_needed);
7726 #if !USE_PLAYER_GRAVITY
7727 case CA_SET_LEVEL_GRAVITY:
7729 game.gravity = (action_arg == CA_ARG_GRAVITY_OFF ? FALSE :
7730 action_arg == CA_ARG_GRAVITY_ON ? TRUE :
7731 action_arg == CA_ARG_GRAVITY_TOGGLE ? !game.gravity :
7737 case CA_SET_LEVEL_WIND:
7739 game.wind_direction = action_arg_direction;
7744 /* ---------- player actions ------------------------------------------ */
7746 case CA_MOVE_PLAYER:
7748 /* automatically move to the next field in specified direction */
7749 for (i = 0; i < MAX_PLAYERS; i++)
7750 if (trigger_player_bits & (1 << i))
7751 stored_player[i].programmed_action = action_arg_direction;
7756 case CA_EXIT_PLAYER:
7758 for (i = 0; i < MAX_PLAYERS; i++)
7759 if (action_arg_player_bits & (1 << i))
7760 PlayerWins(&stored_player[i]);
7765 case CA_KILL_PLAYER:
7767 for (i = 0; i < MAX_PLAYERS; i++)
7768 if (action_arg_player_bits & (1 << i))
7769 KillPlayer(&stored_player[i]);
7774 case CA_SET_PLAYER_KEYS:
7776 int key_state = (action_mode == CA_MODE_ADD ? TRUE : FALSE);
7777 int element = getSpecialActionElement(action_arg_element,
7778 action_arg_number, EL_KEY_1);
7780 if (IS_KEY(element))
7782 for (i = 0; i < MAX_PLAYERS; i++)
7784 if (trigger_player_bits & (1 << i))
7786 stored_player[i].key[KEY_NR(element)] = key_state;
7788 DrawGameDoorValues();
7796 case CA_SET_PLAYER_SPEED:
7798 for (i = 0; i < MAX_PLAYERS; i++)
7800 if (trigger_player_bits & (1 << i))
7802 int move_stepsize = TILEX / stored_player[i].move_delay_value;
7804 if (action_arg == CA_ARG_SPEED_FASTER &&
7805 stored_player[i].cannot_move)
7807 action_arg_number = STEPSIZE_VERY_SLOW;
7809 else if (action_arg == CA_ARG_SPEED_SLOWER ||
7810 action_arg == CA_ARG_SPEED_FASTER)
7812 action_arg_number = 2;
7813 action_mode = (action_arg == CA_ARG_SPEED_SLOWER ? CA_MODE_DIVIDE :
7816 else if (action_arg == CA_ARG_NUMBER_RESET)
7818 action_arg_number = level.initial_player_stepsize[i];
7822 getModifiedActionNumber(move_stepsize,
7825 action_arg_number_min,
7826 action_arg_number_max);
7828 SetPlayerMoveSpeed(&stored_player[i], move_stepsize, FALSE);
7835 case CA_SET_PLAYER_SHIELD:
7837 for (i = 0; i < MAX_PLAYERS; i++)
7839 if (trigger_player_bits & (1 << i))
7841 if (action_arg == CA_ARG_SHIELD_OFF)
7843 stored_player[i].shield_normal_time_left = 0;
7844 stored_player[i].shield_deadly_time_left = 0;
7846 else if (action_arg == CA_ARG_SHIELD_NORMAL)
7848 stored_player[i].shield_normal_time_left = 999999;
7850 else if (action_arg == CA_ARG_SHIELD_DEADLY)
7852 stored_player[i].shield_normal_time_left = 999999;
7853 stored_player[i].shield_deadly_time_left = 999999;
7861 #if USE_PLAYER_GRAVITY
7862 case CA_SET_PLAYER_GRAVITY:
7864 for (i = 0; i < MAX_PLAYERS; i++)
7866 if (trigger_player_bits & (1 << i))
7868 stored_player[i].gravity =
7869 (action_arg == CA_ARG_GRAVITY_OFF ? FALSE :
7870 action_arg == CA_ARG_GRAVITY_ON ? TRUE :
7871 action_arg == CA_ARG_GRAVITY_TOGGLE ? !stored_player[i].gravity :
7872 stored_player[i].gravity);
7880 case CA_SET_PLAYER_ARTWORK:
7882 for (i = 0; i < MAX_PLAYERS; i++)
7884 if (trigger_player_bits & (1 << i))
7886 int artwork_element = action_arg_element;
7888 if (action_arg == CA_ARG_ELEMENT_RESET)
7890 (level.use_artwork_element[i] ? level.artwork_element[i] :
7891 stored_player[i].element_nr);
7893 stored_player[i].artwork_element = artwork_element;
7895 SetPlayerWaiting(&stored_player[i], FALSE);
7897 /* set number of special actions for bored and sleeping animation */
7898 stored_player[i].num_special_action_bored =
7899 get_num_special_action(artwork_element,
7900 ACTION_BORING_1, ACTION_BORING_LAST);
7901 stored_player[i].num_special_action_sleeping =
7902 get_num_special_action(artwork_element,
7903 ACTION_SLEEPING_1, ACTION_SLEEPING_LAST);
7910 /* ---------- CE actions ---------------------------------------------- */
7912 case CA_SET_CE_VALUE:
7914 #if USE_NEW_CUSTOM_VALUE
7915 int last_ce_value = CustomValue[x][y];
7917 CustomValue[x][y] = action_arg_number_new;
7919 if (CustomValue[x][y] != last_ce_value)
7921 CheckElementChange(x, y, element, EL_UNDEFINED, CE_VALUE_CHANGES);
7922 CheckTriggeredElementChange(x, y, element, CE_VALUE_CHANGES_OF_X);
7924 if (CustomValue[x][y] == 0)
7926 CheckElementChange(x, y, element, EL_UNDEFINED, CE_VALUE_GETS_ZERO);
7927 CheckTriggeredElementChange(x, y, element, CE_VALUE_GETS_ZERO_OF_X);
7935 case CA_SET_CE_SCORE:
7937 #if USE_NEW_CUSTOM_VALUE
7938 int last_ce_score = ei->collect_score;
7940 ei->collect_score = action_arg_number_new;
7942 if (ei->collect_score != last_ce_score)
7944 CheckElementChange(x, y, element, EL_UNDEFINED, CE_SCORE_CHANGES);
7945 CheckTriggeredElementChange(x, y, element, CE_SCORE_CHANGES_OF_X);
7947 if (ei->collect_score == 0)
7951 CheckElementChange(x, y, element, EL_UNDEFINED, CE_SCORE_GETS_ZERO);
7952 CheckTriggeredElementChange(x, y, element, CE_SCORE_GETS_ZERO_OF_X);
7955 This is a very special case that seems to be a mixture between
7956 CheckElementChange() and CheckTriggeredElementChange(): while
7957 the first one only affects single elements that are triggered
7958 directly, the second one affects multiple elements in the playfield
7959 that are triggered indirectly by another element. This is a third
7960 case: Changing the CE score always affects multiple identical CEs,
7961 so every affected CE must be checked, not only the single CE for
7962 which the CE score was changed in the first place (as every instance
7963 of that CE shares the same CE score, and therefore also can change)!
7965 SCAN_PLAYFIELD(xx, yy)
7967 if (Feld[xx][yy] == element)
7968 CheckElementChange(xx, yy, element, EL_UNDEFINED,
7969 CE_SCORE_GETS_ZERO);
7978 /* ---------- engine actions ------------------------------------------ */
7980 case CA_SET_ENGINE_SCAN_MODE:
7982 InitPlayfieldScanMode(action_arg);
7992 static void CreateFieldExt(int x, int y, int element, boolean is_change)
7994 int old_element = Feld[x][y];
7995 int new_element = get_element_from_group_element(element);
7996 int previous_move_direction = MovDir[x][y];
7997 #if USE_NEW_CUSTOM_VALUE
7998 int last_ce_value = CustomValue[x][y];
8000 boolean new_element_is_player = ELEM_IS_PLAYER(new_element);
8001 boolean add_player_onto_element = (new_element_is_player &&
8002 #if USE_CODE_THAT_BREAKS_SNAKE_BITE
8003 /* this breaks SnakeBite when a snake is
8004 halfway through a door that closes */
8005 /* NOW FIXED AT LEVEL INIT IN files.c */
8006 new_element != EL_SOKOBAN_FIELD_PLAYER &&
8008 IS_WALKABLE(old_element));
8011 /* check if element under the player changes from accessible to unaccessible
8012 (needed for special case of dropping element which then changes) */
8013 if (IS_PLAYER(x, y) && !PLAYER_EXPLOSION_PROTECTED(x, y) &&
8014 IS_ACCESSIBLE(old_element) && !IS_ACCESSIBLE(new_element))
8022 if (!add_player_onto_element)
8024 if (IS_MOVING(x, y) || IS_BLOCKED(x, y))
8025 RemoveMovingField(x, y);
8029 Feld[x][y] = new_element;
8031 #if !USE_GFX_RESET_GFX_ANIMATION
8032 ResetGfxAnimation(x, y);
8033 ResetRandomAnimationValue(x, y);
8036 if (element_info[new_element].move_direction_initial == MV_START_PREVIOUS)
8037 MovDir[x][y] = previous_move_direction;
8039 #if USE_NEW_CUSTOM_VALUE
8040 if (element_info[new_element].use_last_ce_value)
8041 CustomValue[x][y] = last_ce_value;
8044 InitField_WithBug1(x, y, FALSE);
8046 new_element = Feld[x][y]; /* element may have changed */
8048 #if USE_GFX_RESET_GFX_ANIMATION
8049 ResetGfxAnimation(x, y);
8050 ResetRandomAnimationValue(x, y);
8053 DrawLevelField(x, y);
8055 if (GFX_CRUMBLED(new_element))
8056 DrawLevelFieldCrumbledSandNeighbours(x, y);
8060 /* check if element under the player changes from accessible to unaccessible
8061 (needed for special case of dropping element which then changes) */
8062 /* (must be checked after creating new element for walkable group elements) */
8063 if (IS_PLAYER(x, y) && !PLAYER_EXPLOSION_PROTECTED(x, y) &&
8064 IS_ACCESSIBLE(old_element) && !IS_ACCESSIBLE(new_element))
8072 /* "ChangeCount" not set yet to allow "entered by player" change one time */
8073 if (new_element_is_player)
8074 RelocatePlayer(x, y, new_element);
8077 ChangeCount[x][y]++; /* count number of changes in the same frame */
8079 TestIfBadThingTouchesPlayer(x, y);
8080 TestIfPlayerTouchesCustomElement(x, y);
8081 TestIfElementTouchesCustomElement(x, y);
8084 static void CreateField(int x, int y, int element)
8086 CreateFieldExt(x, y, element, FALSE);
8089 static void CreateElementFromChange(int x, int y, int element)
8091 element = GET_VALID_RUNTIME_ELEMENT(element);
8093 #if USE_STOP_CHANGED_ELEMENTS
8094 if (game.engine_version >= VERSION_IDENT(3,2,0,7))
8096 int old_element = Feld[x][y];
8098 /* prevent changed element from moving in same engine frame
8099 unless both old and new element can either fall or move */
8100 if ((!CAN_FALL(old_element) || !CAN_FALL(element)) &&
8101 (!CAN_MOVE(old_element) || !CAN_MOVE(element)))
8106 CreateFieldExt(x, y, element, TRUE);
8109 static boolean ChangeElement(int x, int y, int element, int page)
8111 struct ElementInfo *ei = &element_info[element];
8112 struct ElementChangeInfo *change = &ei->change_page[page];
8113 int ce_value = CustomValue[x][y];
8114 int ce_score = ei->collect_score;
8116 int old_element = Feld[x][y];
8118 /* always use default change event to prevent running into a loop */
8119 if (ChangeEvent[x][y] == -1)
8120 ChangeEvent[x][y] = CE_DELAY;
8122 if (ChangeEvent[x][y] == CE_DELAY)
8124 /* reset actual trigger element, trigger player and action element */
8125 change->actual_trigger_element = EL_EMPTY;
8126 change->actual_trigger_player = EL_PLAYER_1;
8127 change->actual_trigger_side = CH_SIDE_NONE;
8128 change->actual_trigger_ce_value = 0;
8129 change->actual_trigger_ce_score = 0;
8132 /* do not change elements more than a specified maximum number of changes */
8133 if (ChangeCount[x][y] >= game.max_num_changes_per_frame)
8136 ChangeCount[x][y]++; /* count number of changes in the same frame */
8138 if (change->explode)
8145 if (change->use_target_content)
8147 boolean complete_replace = TRUE;
8148 boolean can_replace[3][3];
8151 for (yy = 0; yy < 3; yy++) for (xx = 0; xx < 3 ; xx++)
8154 boolean is_walkable;
8155 boolean is_diggable;
8156 boolean is_collectible;
8157 boolean is_removable;
8158 boolean is_destructible;
8159 int ex = x + xx - 1;
8160 int ey = y + yy - 1;
8161 int content_element = change->target_content.e[xx][yy];
8164 can_replace[xx][yy] = TRUE;
8166 if (ex == x && ey == y) /* do not check changing element itself */
8169 if (content_element == EL_EMPTY_SPACE)
8171 can_replace[xx][yy] = FALSE; /* do not replace border with space */
8176 if (!IN_LEV_FIELD(ex, ey))
8178 can_replace[xx][yy] = FALSE;
8179 complete_replace = FALSE;
8186 if (IS_MOVING(ex, ey) || IS_BLOCKED(ex, ey))
8187 e = MovingOrBlocked2Element(ex, ey);
8189 is_empty = (IS_FREE(ex, ey) ||
8190 (IS_FREE_OR_PLAYER(ex, ey) && IS_WALKABLE(content_element)));
8192 is_walkable = (is_empty || IS_WALKABLE(e));
8193 is_diggable = (is_empty || IS_DIGGABLE(e));
8194 is_collectible = (is_empty || IS_COLLECTIBLE(e));
8195 is_destructible = (is_empty || !IS_INDESTRUCTIBLE(e));
8196 is_removable = (is_diggable || is_collectible);
8198 can_replace[xx][yy] =
8199 (((change->replace_when == CP_WHEN_EMPTY && is_empty) ||
8200 (change->replace_when == CP_WHEN_WALKABLE && is_walkable) ||
8201 (change->replace_when == CP_WHEN_DIGGABLE && is_diggable) ||
8202 (change->replace_when == CP_WHEN_COLLECTIBLE && is_collectible) ||
8203 (change->replace_when == CP_WHEN_REMOVABLE && is_removable) ||
8204 (change->replace_when == CP_WHEN_DESTRUCTIBLE && is_destructible)) &&
8205 !(IS_PLAYER(ex, ey) && ELEM_IS_PLAYER(content_element)));
8207 if (!can_replace[xx][yy])
8208 complete_replace = FALSE;
8211 if (!change->only_if_complete || complete_replace)
8213 boolean something_has_changed = FALSE;
8215 if (change->only_if_complete && change->use_random_replace &&
8216 RND(100) < change->random_percentage)
8219 for (yy = 0; yy < 3; yy++) for (xx = 0; xx < 3 ; xx++)
8221 int ex = x + xx - 1;
8222 int ey = y + yy - 1;
8223 int content_element;
8225 if (can_replace[xx][yy] && (!change->use_random_replace ||
8226 RND(100) < change->random_percentage))
8228 if (IS_MOVING(ex, ey) || IS_BLOCKED(ex, ey))
8229 RemoveMovingField(ex, ey);
8231 ChangeEvent[ex][ey] = ChangeEvent[x][y];
8233 content_element = change->target_content.e[xx][yy];
8234 target_element = GET_TARGET_ELEMENT(element, content_element, change,
8235 ce_value, ce_score);
8237 CreateElementFromChange(ex, ey, target_element);
8239 something_has_changed = TRUE;
8241 /* for symmetry reasons, freeze newly created border elements */
8242 if (ex != x || ey != y)
8243 Stop[ex][ey] = TRUE; /* no more moving in this frame */
8247 if (something_has_changed)
8249 PlayLevelSoundElementAction(x, y, element, ACTION_CHANGING);
8250 PlayLevelSoundElementAction(x, y, element, ACTION_PAGE_1 + page);
8256 target_element = GET_TARGET_ELEMENT(element, change->target_element, change,
8257 ce_value, ce_score);
8259 if (element == EL_DIAGONAL_GROWING ||
8260 element == EL_DIAGONAL_SHRINKING)
8262 target_element = Store[x][y];
8264 Store[x][y] = EL_EMPTY;
8267 CreateElementFromChange(x, y, target_element);
8269 PlayLevelSoundElementAction(x, y, element, ACTION_CHANGING);
8270 PlayLevelSoundElementAction(x, y, element, ACTION_PAGE_1 + page);
8273 /* this uses direct change before indirect change */
8274 CheckTriggeredElementChangeByPage(x, y, old_element, CE_CHANGE_OF_X, page);
8279 #if USE_NEW_DELAYED_ACTION
8281 static void HandleElementChange(int x, int y, int page)
8283 int element = MovingOrBlocked2Element(x, y);
8284 struct ElementInfo *ei = &element_info[element];
8285 struct ElementChangeInfo *change = &ei->change_page[page];
8288 if (!CAN_CHANGE_OR_HAS_ACTION(element) &&
8289 !CAN_CHANGE_OR_HAS_ACTION(Back[x][y]))
8292 printf("HandleElementChange(): %d,%d: element = %d ('%s')\n",
8293 x, y, element, element_info[element].token_name);
8294 printf("HandleElementChange(): This should never happen!\n");
8299 /* this can happen with classic bombs on walkable, changing elements */
8300 if (!CAN_CHANGE_OR_HAS_ACTION(element))
8303 if (!CAN_CHANGE(Back[x][y])) /* prevent permanent repetition */
8304 ChangeDelay[x][y] = 0;
8310 if (ChangeDelay[x][y] == 0) /* initialize element change */
8312 ChangeDelay[x][y] = GET_CHANGE_DELAY(change) + 1;
8314 if (change->can_change)
8316 ResetGfxAnimation(x, y);
8317 ResetRandomAnimationValue(x, y);
8319 if (change->pre_change_function)
8320 change->pre_change_function(x, y);
8324 ChangeDelay[x][y]--;
8326 if (ChangeDelay[x][y] != 0) /* continue element change */
8328 if (change->can_change)
8330 int graphic = el_act_dir2img(element, GfxAction[x][y], GfxDir[x][y]);
8332 if (IS_ANIMATED(graphic))
8333 DrawLevelGraphicAnimationIfNeeded(x, y, graphic);
8335 if (change->change_function)
8336 change->change_function(x, y);
8339 else /* finish element change */
8341 if (ChangePage[x][y] != -1) /* remember page from delayed change */
8343 page = ChangePage[x][y];
8344 ChangePage[x][y] = -1;
8346 change = &ei->change_page[page];
8349 if (IS_MOVING(x, y)) /* never change a running system ;-) */
8351 ChangeDelay[x][y] = 1; /* try change after next move step */
8352 ChangePage[x][y] = page; /* remember page to use for change */
8357 if (change->can_change)
8359 if (ChangeElement(x, y, element, page))
8361 if (change->post_change_function)
8362 change->post_change_function(x, y);
8366 if (change->has_action)
8367 ExecuteCustomElementAction(x, y, element, page);
8373 static void HandleElementChange(int x, int y, int page)
8375 int element = MovingOrBlocked2Element(x, y);
8376 struct ElementInfo *ei = &element_info[element];
8377 struct ElementChangeInfo *change = &ei->change_page[page];
8380 if (!CAN_CHANGE(element) && !CAN_CHANGE(Back[x][y]))
8383 printf("HandleElementChange(): %d,%d: element = %d ('%s')\n",
8384 x, y, element, element_info[element].token_name);
8385 printf("HandleElementChange(): This should never happen!\n");
8390 /* this can happen with classic bombs on walkable, changing elements */
8391 if (!CAN_CHANGE(element))
8394 if (!CAN_CHANGE(Back[x][y])) /* prevent permanent repetition */
8395 ChangeDelay[x][y] = 0;
8401 if (ChangeDelay[x][y] == 0) /* initialize element change */
8403 ChangeDelay[x][y] = GET_CHANGE_DELAY(change) + 1;
8405 ResetGfxAnimation(x, y);
8406 ResetRandomAnimationValue(x, y);
8408 if (change->pre_change_function)
8409 change->pre_change_function(x, y);
8412 ChangeDelay[x][y]--;
8414 if (ChangeDelay[x][y] != 0) /* continue element change */
8416 int graphic = el_act_dir2img(element, GfxAction[x][y], GfxDir[x][y]);
8418 if (IS_ANIMATED(graphic))
8419 DrawLevelGraphicAnimationIfNeeded(x, y, graphic);
8421 if (change->change_function)
8422 change->change_function(x, y);
8424 else /* finish element change */
8426 if (ChangePage[x][y] != -1) /* remember page from delayed change */
8428 page = ChangePage[x][y];
8429 ChangePage[x][y] = -1;
8431 change = &ei->change_page[page];
8434 if (IS_MOVING(x, y)) /* never change a running system ;-) */
8436 ChangeDelay[x][y] = 1; /* try change after next move step */
8437 ChangePage[x][y] = page; /* remember page to use for change */
8442 if (ChangeElement(x, y, element, page))
8444 if (change->post_change_function)
8445 change->post_change_function(x, y);
8452 static boolean CheckTriggeredElementChangeExt(int trigger_x, int trigger_y,
8453 int trigger_element,
8459 boolean change_done_any = FALSE;
8460 int trigger_page_bits = (trigger_page < 0 ? CH_PAGE_ANY : 1 << trigger_page);
8463 if (!(trigger_events[trigger_element][trigger_event]))
8466 for (i = 0; i < NUM_CUSTOM_ELEMENTS; i++)
8468 int element = EL_CUSTOM_START + i;
8469 boolean change_done = FALSE;
8472 if (!CAN_CHANGE_OR_HAS_ACTION(element) ||
8473 !HAS_ANY_CHANGE_EVENT(element, trigger_event))
8476 for (p = 0; p < element_info[element].num_change_pages; p++)
8478 struct ElementChangeInfo *change = &element_info[element].change_page[p];
8480 if (change->can_change_or_has_action &&
8481 change->has_event[trigger_event] &&
8482 change->trigger_side & trigger_side &&
8483 change->trigger_player & trigger_player &&
8484 change->trigger_page & trigger_page_bits &&
8485 IS_EQUAL_OR_IN_GROUP(trigger_element, change->trigger_element))
8487 change->actual_trigger_element = trigger_element;
8488 change->actual_trigger_player = EL_PLAYER_1 + log_2(trigger_player);
8489 change->actual_trigger_side = trigger_side;
8490 change->actual_trigger_ce_value = CustomValue[trigger_x][trigger_y];
8491 change->actual_trigger_ce_score = GET_CE_SCORE(trigger_element);
8493 if ((change->can_change && !change_done) || change->has_action)
8497 SCAN_PLAYFIELD(x, y)
8499 if (Feld[x][y] == element)
8501 if (change->can_change && !change_done)
8503 ChangeDelay[x][y] = 1;
8504 ChangeEvent[x][y] = trigger_event;
8506 HandleElementChange(x, y, p);
8508 #if USE_NEW_DELAYED_ACTION
8509 else if (change->has_action)
8511 ExecuteCustomElementAction(x, y, element, p);
8512 PlayLevelSoundElementAction(x, y, element, ACTION_PAGE_1 + p);
8515 if (change->has_action)
8517 ExecuteCustomElementAction(x, y, element, p);
8518 PlayLevelSoundElementAction(x, y, element, ACTION_PAGE_1 + p);
8524 if (change->can_change)
8527 change_done_any = TRUE;
8534 return change_done_any;
8537 static boolean CheckElementChangeExt(int x, int y,
8539 int trigger_element,
8544 boolean change_done = FALSE;
8547 if (!CAN_CHANGE_OR_HAS_ACTION(element) ||
8548 !HAS_ANY_CHANGE_EVENT(element, trigger_event))
8551 if (Feld[x][y] == EL_BLOCKED)
8553 Blocked2Moving(x, y, &x, &y);
8554 element = Feld[x][y];
8558 /* check if element has already changed */
8559 if (Feld[x][y] != element)
8562 /* check if element has already changed or is about to change after moving */
8563 if ((game.engine_version < VERSION_IDENT(3,2,0,7) &&
8564 Feld[x][y] != element) ||
8566 (game.engine_version >= VERSION_IDENT(3,2,0,7) &&
8567 (ChangeCount[x][y] >= game.max_num_changes_per_frame ||
8568 ChangePage[x][y] != -1)))
8572 for (p = 0; p < element_info[element].num_change_pages; p++)
8574 struct ElementChangeInfo *change = &element_info[element].change_page[p];
8576 boolean check_trigger_element =
8577 (trigger_event == CE_TOUCHING_X ||
8578 trigger_event == CE_HITTING_X ||
8579 trigger_event == CE_HIT_BY_X);
8581 if (change->can_change_or_has_action &&
8582 change->has_event[trigger_event] &&
8583 change->trigger_side & trigger_side &&
8584 change->trigger_player & trigger_player &&
8585 (!check_trigger_element ||
8586 IS_EQUAL_OR_IN_GROUP(trigger_element, change->trigger_element)))
8588 change->actual_trigger_element = trigger_element;
8589 change->actual_trigger_player = EL_PLAYER_1 + log_2(trigger_player);
8590 change->actual_trigger_side = trigger_side;
8591 change->actual_trigger_ce_value = CustomValue[x][y];
8592 change->actual_trigger_ce_score = GET_CE_SCORE(trigger_element);
8594 /* special case: trigger element not at (x,y) position for some events */
8595 if (check_trigger_element)
8607 { 0, 0 }, { 0, 0 }, { 0, 0 },
8611 int xx = x + move_xy[MV_DIR_OPPOSITE(trigger_side)].dx;
8612 int yy = y + move_xy[MV_DIR_OPPOSITE(trigger_side)].dy;
8614 change->actual_trigger_ce_value = CustomValue[xx][yy];
8615 change->actual_trigger_ce_score = GET_CE_SCORE(trigger_element);
8618 if (change->can_change && !change_done)
8620 ChangeDelay[x][y] = 1;
8621 ChangeEvent[x][y] = trigger_event;
8623 HandleElementChange(x, y, p);
8627 #if USE_NEW_DELAYED_ACTION
8628 else if (change->has_action)
8630 ExecuteCustomElementAction(x, y, element, p);
8631 PlayLevelSoundElementAction(x, y, element, ACTION_PAGE_1 + p);
8634 if (change->has_action)
8636 ExecuteCustomElementAction(x, y, element, p);
8637 PlayLevelSoundElementAction(x, y, element, ACTION_PAGE_1 + p);
8646 static void PlayPlayerSound(struct PlayerInfo *player)
8648 int jx = player->jx, jy = player->jy;
8649 int sound_element = player->artwork_element;
8650 int last_action = player->last_action_waiting;
8651 int action = player->action_waiting;
8653 if (player->is_waiting)
8655 if (action != last_action)
8656 PlayLevelSoundElementAction(jx, jy, sound_element, action);
8658 PlayLevelSoundElementActionIfLoop(jx, jy, sound_element, action);
8662 if (action != last_action)
8663 StopSound(element_info[sound_element].sound[last_action]);
8665 if (last_action == ACTION_SLEEPING)
8666 PlayLevelSoundElementAction(jx, jy, sound_element, ACTION_AWAKENING);
8670 static void PlayAllPlayersSound()
8674 for (i = 0; i < MAX_PLAYERS; i++)
8675 if (stored_player[i].active)
8676 PlayPlayerSound(&stored_player[i]);
8679 static void SetPlayerWaiting(struct PlayerInfo *player, boolean is_waiting)
8681 boolean last_waiting = player->is_waiting;
8682 int move_dir = player->MovDir;
8684 player->dir_waiting = move_dir;
8685 player->last_action_waiting = player->action_waiting;
8689 if (!last_waiting) /* not waiting -> waiting */
8691 player->is_waiting = TRUE;
8693 player->frame_counter_bored =
8695 game.player_boring_delay_fixed +
8696 GetSimpleRandom(game.player_boring_delay_random);
8697 player->frame_counter_sleeping =
8699 game.player_sleeping_delay_fixed +
8700 GetSimpleRandom(game.player_sleeping_delay_random);
8702 InitPlayerGfxAnimation(player, ACTION_WAITING, move_dir);
8705 if (game.player_sleeping_delay_fixed +
8706 game.player_sleeping_delay_random > 0 &&
8707 player->anim_delay_counter == 0 &&
8708 player->post_delay_counter == 0 &&
8709 FrameCounter >= player->frame_counter_sleeping)
8710 player->is_sleeping = TRUE;
8711 else if (game.player_boring_delay_fixed +
8712 game.player_boring_delay_random > 0 &&
8713 FrameCounter >= player->frame_counter_bored)
8714 player->is_bored = TRUE;
8716 player->action_waiting = (player->is_sleeping ? ACTION_SLEEPING :
8717 player->is_bored ? ACTION_BORING :
8720 if (player->is_sleeping && player->use_murphy)
8722 /* special case for sleeping Murphy when leaning against non-free tile */
8724 if (!IN_LEV_FIELD(player->jx - 1, player->jy) ||
8725 (Feld[player->jx - 1][player->jy] != EL_EMPTY &&
8726 !IS_MOVING(player->jx - 1, player->jy)))
8728 else if (!IN_LEV_FIELD(player->jx + 1, player->jy) ||
8729 (Feld[player->jx + 1][player->jy] != EL_EMPTY &&
8730 !IS_MOVING(player->jx + 1, player->jy)))
8731 move_dir = MV_RIGHT;
8733 player->is_sleeping = FALSE;
8735 player->dir_waiting = move_dir;
8738 if (player->is_sleeping)
8740 if (player->num_special_action_sleeping > 0)
8742 if (player->anim_delay_counter == 0 && player->post_delay_counter == 0)
8744 int last_special_action = player->special_action_sleeping;
8745 int num_special_action = player->num_special_action_sleeping;
8746 int special_action =
8747 (last_special_action == ACTION_DEFAULT ? ACTION_SLEEPING_1 :
8748 last_special_action == ACTION_SLEEPING ? ACTION_SLEEPING :
8749 last_special_action < ACTION_SLEEPING_1 + num_special_action - 1 ?
8750 last_special_action + 1 : ACTION_SLEEPING);
8751 int special_graphic =
8752 el_act_dir2img(player->artwork_element, special_action, move_dir);
8754 player->anim_delay_counter =
8755 graphic_info[special_graphic].anim_delay_fixed +
8756 GetSimpleRandom(graphic_info[special_graphic].anim_delay_random);
8757 player->post_delay_counter =
8758 graphic_info[special_graphic].post_delay_fixed +
8759 GetSimpleRandom(graphic_info[special_graphic].post_delay_random);
8761 player->special_action_sleeping = special_action;
8764 if (player->anim_delay_counter > 0)
8766 player->action_waiting = player->special_action_sleeping;
8767 player->anim_delay_counter--;
8769 else if (player->post_delay_counter > 0)
8771 player->post_delay_counter--;
8775 else if (player->is_bored)
8777 if (player->num_special_action_bored > 0)
8779 if (player->anim_delay_counter == 0 && player->post_delay_counter == 0)
8781 int special_action =
8782 ACTION_BORING_1 + GetSimpleRandom(player->num_special_action_bored);
8783 int special_graphic =
8784 el_act_dir2img(player->artwork_element, special_action, move_dir);
8786 player->anim_delay_counter =
8787 graphic_info[special_graphic].anim_delay_fixed +
8788 GetSimpleRandom(graphic_info[special_graphic].anim_delay_random);
8789 player->post_delay_counter =
8790 graphic_info[special_graphic].post_delay_fixed +
8791 GetSimpleRandom(graphic_info[special_graphic].post_delay_random);
8793 player->special_action_bored = special_action;
8796 if (player->anim_delay_counter > 0)
8798 player->action_waiting = player->special_action_bored;
8799 player->anim_delay_counter--;
8801 else if (player->post_delay_counter > 0)
8803 player->post_delay_counter--;
8808 else if (last_waiting) /* waiting -> not waiting */
8810 player->is_waiting = FALSE;
8811 player->is_bored = FALSE;
8812 player->is_sleeping = FALSE;
8814 player->frame_counter_bored = -1;
8815 player->frame_counter_sleeping = -1;
8817 player->anim_delay_counter = 0;
8818 player->post_delay_counter = 0;
8820 player->dir_waiting = player->MovDir;
8821 player->action_waiting = ACTION_DEFAULT;
8823 player->special_action_bored = ACTION_DEFAULT;
8824 player->special_action_sleeping = ACTION_DEFAULT;
8828 static byte PlayerActions(struct PlayerInfo *player, byte player_action)
8830 boolean moved = FALSE, snapped = FALSE, dropped = FALSE;
8831 int left = player_action & JOY_LEFT;
8832 int right = player_action & JOY_RIGHT;
8833 int up = player_action & JOY_UP;
8834 int down = player_action & JOY_DOWN;
8835 int button1 = player_action & JOY_BUTTON_1;
8836 int button2 = player_action & JOY_BUTTON_2;
8837 int dx = (left ? -1 : right ? 1 : 0);
8838 int dy = (up ? -1 : down ? 1 : 0);
8840 if (!player->active || tape.pausing)
8846 snapped = SnapField(player, dx, dy);
8850 dropped = DropElement(player);
8852 moved = MovePlayer(player, dx, dy);
8855 if (tape.single_step && tape.recording && !tape.pausing)
8857 if (button1 || (dropped && !moved))
8859 TapeTogglePause(TAPE_TOGGLE_AUTOMATIC);
8860 SnapField(player, 0, 0); /* stop snapping */
8864 SetPlayerWaiting(player, FALSE);
8866 return player_action;
8870 /* no actions for this player (no input at player's configured device) */
8872 DigField(player, 0, 0, 0, 0, 0, 0, DF_NO_PUSH);
8873 SnapField(player, 0, 0);
8874 CheckGravityMovementWhenNotMoving(player);
8876 if (player->MovPos == 0)
8877 SetPlayerWaiting(player, TRUE);
8879 if (player->MovPos == 0) /* needed for tape.playing */
8880 player->is_moving = FALSE;
8882 player->is_dropping = FALSE;
8883 player->is_dropping_pressed = FALSE;
8884 player->drop_pressed_delay = 0;
8890 static void CheckLevelTime()
8894 if (level.game_engine_type == GAME_ENGINE_TYPE_EM)
8896 if (level.native_em_level->lev->home == 0) /* all players at home */
8898 PlayerWins(local_player);
8900 AllPlayersGone = TRUE;
8902 level.native_em_level->lev->home = -1;
8905 if (level.native_em_level->ply[0]->alive == 0 &&
8906 level.native_em_level->ply[1]->alive == 0 &&
8907 level.native_em_level->ply[2]->alive == 0 &&
8908 level.native_em_level->ply[3]->alive == 0) /* all dead */
8909 AllPlayersGone = TRUE;
8912 if (TimeFrames >= FRAMES_PER_SECOND)
8917 for (i = 0; i < MAX_PLAYERS; i++)
8919 struct PlayerInfo *player = &stored_player[i];
8921 if (SHIELD_ON(player))
8923 player->shield_normal_time_left--;
8925 if (player->shield_deadly_time_left > 0)
8926 player->shield_deadly_time_left--;
8930 if (!local_player->LevelSolved && !level.use_step_counter)
8938 if (TimeLeft <= 10 && setup.time_limit)
8939 PlaySound(SND_GAME_RUNNING_OUT_OF_TIME);
8941 DrawGameValue_Time(TimeLeft);
8943 if (!TimeLeft && setup.time_limit)
8945 if (level.game_engine_type == GAME_ENGINE_TYPE_EM)
8946 level.native_em_level->lev->killed_out_of_time = TRUE;
8948 for (i = 0; i < MAX_PLAYERS; i++)
8949 KillPlayer(&stored_player[i]);
8952 else if (level.time == 0 && !AllPlayersGone) /* level w/o time limit */
8953 DrawGameValue_Time(TimePlayed);
8955 level.native_em_level->lev->time =
8956 (level.time == 0 ? TimePlayed : TimeLeft);
8959 if (tape.recording || tape.playing)
8960 DrawVideoDisplay(VIDEO_STATE_TIME_ON, TapeTime);
8964 void AdvanceFrameAndPlayerCounters(int player_nr)
8968 /* advance frame counters (global frame counter and time frame counter) */
8972 /* advance player counters (counters for move delay, move animation etc.) */
8973 for (i = 0; i < MAX_PLAYERS; i++)
8975 boolean advance_player_counters = (player_nr == -1 || player_nr == i);
8976 int move_delay_value = stored_player[i].move_delay_value;
8977 int move_frames = MOVE_DELAY_NORMAL_SPEED / move_delay_value;
8979 if (!advance_player_counters) /* not all players may be affected */
8982 #if USE_NEW_PLAYER_ANIM
8983 if (move_frames == 0) /* less than one move per game frame */
8985 int stepsize = TILEX / move_delay_value;
8986 int delay = move_delay_value / MOVE_DELAY_NORMAL_SPEED;
8987 int count = (stored_player[i].is_moving ?
8988 ABS(stored_player[i].MovPos) / stepsize : FrameCounter);
8990 if (count % delay == 0)
8995 stored_player[i].Frame += move_frames;
8997 if (stored_player[i].MovPos != 0)
8998 stored_player[i].StepFrame += move_frames;
9000 if (stored_player[i].move_delay > 0)
9001 stored_player[i].move_delay--;
9003 /* due to bugs in previous versions, counter must count up, not down */
9004 if (stored_player[i].push_delay != -1)
9005 stored_player[i].push_delay++;
9007 if (stored_player[i].drop_delay > 0)
9008 stored_player[i].drop_delay--;
9010 if (stored_player[i].is_dropping_pressed)
9011 stored_player[i].drop_pressed_delay++;
9015 void StartGameActions(boolean init_network_game, boolean record_tape,
9018 unsigned long new_random_seed = InitRND(random_seed);
9021 TapeStartRecording(new_random_seed);
9023 #if defined(NETWORK_AVALIABLE)
9024 if (init_network_game)
9026 SendToServer_StartPlaying();
9037 static unsigned long game_frame_delay = 0;
9038 unsigned long game_frame_delay_value;
9039 byte *recorded_player_action;
9040 byte summarized_player_action = 0;
9041 byte tape_action[MAX_PLAYERS];
9044 if (game.restart_level)
9045 StartGameActions(options.network, setup.autorecord, NEW_RANDOMIZE);
9047 if (level.game_engine_type == GAME_ENGINE_TYPE_EM)
9049 if (level.native_em_level->lev->home == 0) /* all players at home */
9051 PlayerWins(local_player);
9053 AllPlayersGone = TRUE;
9055 level.native_em_level->lev->home = -1;
9058 if (level.native_em_level->ply[0]->alive == 0 &&
9059 level.native_em_level->ply[1]->alive == 0 &&
9060 level.native_em_level->ply[2]->alive == 0 &&
9061 level.native_em_level->ply[3]->alive == 0) /* all dead */
9062 AllPlayersGone = TRUE;
9065 if (local_player->LevelSolved)
9068 if (AllPlayersGone && !TAPE_IS_STOPPED(tape))
9071 if (game_status != GAME_MODE_PLAYING) /* status might have changed */
9074 game_frame_delay_value =
9075 (tape.playing && tape.fast_forward ? FfwdFrameDelay : GameFrameDelay);
9077 if (tape.playing && tape.warp_forward && !tape.pausing)
9078 game_frame_delay_value = 0;
9080 /* ---------- main game synchronization point ---------- */
9082 WaitUntilDelayReached(&game_frame_delay, game_frame_delay_value);
9084 if (network_playing && !network_player_action_received)
9086 /* try to get network player actions in time */
9088 #if defined(NETWORK_AVALIABLE)
9089 /* last chance to get network player actions without main loop delay */
9093 /* game was quit by network peer */
9094 if (game_status != GAME_MODE_PLAYING)
9097 if (!network_player_action_received)
9098 return; /* failed to get network player actions in time */
9100 /* do not yet reset "network_player_action_received" (for tape.pausing) */
9106 /* at this point we know that we really continue executing the game */
9108 network_player_action_received = FALSE;
9110 /* when playing tape, read previously recorded player input from tape data */
9111 recorded_player_action = (tape.playing ? TapePlayAction() : NULL);
9114 /* TapePlayAction() may return NULL when toggling to "pause before death" */
9119 if (tape.set_centered_player)
9121 game.centered_player_nr_next = tape.centered_player_nr_next;
9122 game.set_centered_player = TRUE;
9125 for (i = 0; i < MAX_PLAYERS; i++)
9127 summarized_player_action |= stored_player[i].action;
9129 if (!network_playing)
9130 stored_player[i].effective_action = stored_player[i].action;
9133 #if defined(NETWORK_AVALIABLE)
9134 if (network_playing)
9135 SendToServer_MovePlayer(summarized_player_action);
9138 if (!options.network && !setup.team_mode)
9139 local_player->effective_action = summarized_player_action;
9141 if (setup.team_mode && setup.input_on_focus && game.centered_player_nr != -1)
9143 for (i = 0; i < MAX_PLAYERS; i++)
9144 stored_player[i].effective_action =
9145 (i == game.centered_player_nr ? summarized_player_action : 0);
9148 if (recorded_player_action != NULL)
9149 for (i = 0; i < MAX_PLAYERS; i++)
9150 stored_player[i].effective_action = recorded_player_action[i];
9152 for (i = 0; i < MAX_PLAYERS; i++)
9154 tape_action[i] = stored_player[i].effective_action;
9156 /* (this can only happen in the R'n'D game engine) */
9157 if (tape.recording && tape_action[i] && !tape.player_participates[i])
9158 tape.player_participates[i] = TRUE; /* player just appeared from CE */
9161 /* only record actions from input devices, but not programmed actions */
9163 TapeRecordAction(tape_action);
9165 if (level.game_engine_type == GAME_ENGINE_TYPE_EM)
9167 GameActions_EM_Main();
9175 void GameActions_EM_Main()
9177 byte effective_action[MAX_PLAYERS];
9178 boolean warp_mode = (tape.playing && tape.warp_forward && !tape.pausing);
9181 for (i = 0; i < MAX_PLAYERS; i++)
9182 effective_action[i] = stored_player[i].effective_action;
9184 GameActions_EM(effective_action, warp_mode);
9188 AdvanceFrameAndPlayerCounters(-1); /* advance counters for all players */
9191 void GameActions_RND()
9193 int magic_wall_x = 0, magic_wall_y = 0;
9194 int i, x, y, element, graphic;
9196 InitPlayfieldScanModeVars();
9198 #if USE_ONE_MORE_CHANGE_PER_FRAME
9199 if (game.engine_version >= VERSION_IDENT(3,2,0,7))
9201 SCAN_PLAYFIELD(x, y)
9203 ChangeCount[x][y] = 0;
9204 ChangeEvent[x][y] = -1;
9209 if (game.set_centered_player)
9211 boolean all_players_fit_to_screen = checkIfAllPlayersFitToScreen_RND();
9213 /* switching to "all players" only possible if all players fit to screen */
9214 if (game.centered_player_nr_next == -1 && !all_players_fit_to_screen)
9216 game.centered_player_nr_next = game.centered_player_nr;
9217 game.set_centered_player = FALSE;
9220 /* do not switch focus to non-existing (or non-active) player */
9221 if (game.centered_player_nr_next >= 0 &&
9222 !stored_player[game.centered_player_nr_next].active)
9224 game.centered_player_nr_next = game.centered_player_nr;
9225 game.set_centered_player = FALSE;
9229 if (game.set_centered_player &&
9230 ScreenMovPos == 0) /* screen currently aligned at tile position */
9234 if (game.centered_player_nr_next == -1)
9236 setScreenCenteredToAllPlayers(&sx, &sy);
9240 sx = stored_player[game.centered_player_nr_next].jx;
9241 sy = stored_player[game.centered_player_nr_next].jy;
9244 game.centered_player_nr = game.centered_player_nr_next;
9245 game.set_centered_player = FALSE;
9247 DrawRelocateScreen(sx, sy, MV_NONE, TRUE, setup.quick_switch);
9248 DrawGameDoorValues();
9251 for (i = 0; i < MAX_PLAYERS; i++)
9253 int actual_player_action = stored_player[i].effective_action;
9256 /* !!! THIS BREAKS THE FOLLOWING TAPES: !!!
9257 - rnd_equinox_tetrachloride 048
9258 - rnd_equinox_tetrachloride_ii 096
9259 - rnd_emanuel_schmieg 002
9260 - doctor_sloan_ww 001, 020
9262 if (stored_player[i].MovPos == 0)
9263 CheckGravityMovement(&stored_player[i]);
9266 /* overwrite programmed action with tape action */
9267 if (stored_player[i].programmed_action)
9268 actual_player_action = stored_player[i].programmed_action;
9270 PlayerActions(&stored_player[i], actual_player_action);
9272 ScrollPlayer(&stored_player[i], SCROLL_GO_ON);
9275 ScrollScreen(NULL, SCROLL_GO_ON);
9277 /* for backwards compatibility, the following code emulates a fixed bug that
9278 occured when pushing elements (causing elements that just made their last
9279 pushing step to already (if possible) make their first falling step in the
9280 same game frame, which is bad); this code is also needed to use the famous
9281 "spring push bug" which is used in older levels and might be wanted to be
9282 used also in newer levels, but in this case the buggy pushing code is only
9283 affecting the "spring" element and no other elements */
9285 if (game.engine_version < VERSION_IDENT(2,2,0,7) || level.use_spring_bug)
9287 for (i = 0; i < MAX_PLAYERS; i++)
9289 struct PlayerInfo *player = &stored_player[i];
9293 if (player->active && player->is_pushing && player->is_moving &&
9295 (game.engine_version < VERSION_IDENT(2,2,0,7) ||
9296 Feld[x][y] == EL_SPRING))
9298 ContinueMoving(x, y);
9300 /* continue moving after pushing (this is actually a bug) */
9301 if (!IS_MOVING(x, y))
9309 SCAN_PLAYFIELD(x, y)
9311 ChangeCount[x][y] = 0;
9312 ChangeEvent[x][y] = -1;
9314 /* this must be handled before main playfield loop */
9315 if (Feld[x][y] == EL_PLAYER_IS_LEAVING)
9318 if (MovDelay[x][y] <= 0)
9322 #if USE_NEW_SNAP_DELAY
9323 if (Feld[x][y] == EL_ELEMENT_SNAPPING)
9326 if (MovDelay[x][y] <= 0)
9329 DrawLevelField(x, y);
9331 TestIfElementTouchesCustomElement(x, y); /* for empty space */
9337 if (ChangePage[x][y] != -1 && ChangeDelay[x][y] != 1)
9339 printf("GameActions(): x = %d, y = %d: ChangePage != -1\n", x, y);
9340 printf("GameActions(): This should never happen!\n");
9342 ChangePage[x][y] = -1;
9347 if (WasJustMoving[x][y] > 0)
9348 WasJustMoving[x][y]--;
9349 if (WasJustFalling[x][y] > 0)
9350 WasJustFalling[x][y]--;
9351 if (CheckCollision[x][y] > 0)
9352 CheckCollision[x][y]--;
9356 /* reset finished pushing action (not done in ContinueMoving() to allow
9357 continuous pushing animation for elements with zero push delay) */
9358 if (GfxAction[x][y] == ACTION_PUSHING && !IS_MOVING(x, y))
9360 ResetGfxAnimation(x, y);
9361 DrawLevelField(x, y);
9365 if (IS_BLOCKED(x, y))
9369 Blocked2Moving(x, y, &oldx, &oldy);
9370 if (!IS_MOVING(oldx, oldy))
9372 printf("GameActions(): (BLOCKED => MOVING) context corrupted!\n");
9373 printf("GameActions(): BLOCKED: x = %d, y = %d\n", x, y);
9374 printf("GameActions(): !MOVING: oldx = %d, oldy = %d\n", oldx, oldy);
9375 printf("GameActions(): This should never happen!\n");
9381 SCAN_PLAYFIELD(x, y)
9383 element = Feld[x][y];
9384 graphic = el_act_dir2img(element, GfxAction[x][y], GfxDir[x][y]);
9386 ResetGfxFrame(x, y, TRUE);
9388 if (ANIM_MODE(graphic) == ANIM_RANDOM &&
9389 IS_NEXT_FRAME(GfxFrame[x][y], graphic))
9390 ResetRandomAnimationValue(x, y);
9392 SetRandomAnimationValue(x, y);
9394 PlayLevelSoundActionIfLoop(x, y, GfxAction[x][y]);
9396 if (IS_INACTIVE(element))
9398 if (IS_ANIMATED(graphic))
9399 DrawLevelGraphicAnimationIfNeeded(x, y, graphic);
9404 /* this may take place after moving, so 'element' may have changed */
9405 if (IS_CHANGING(x, y) &&
9406 (game.engine_version < VERSION_IDENT(3,0,7,1) || !Stop[x][y]))
9408 int page = element_info[element].event_page_nr[CE_DELAY];
9411 HandleElementChange(x, y, page);
9413 if (CAN_CHANGE(element))
9414 HandleElementChange(x, y, page);
9416 if (HAS_ACTION(element))
9417 ExecuteCustomElementAction(x, y, element, page);
9420 element = Feld[x][y];
9421 graphic = el_act_dir2img(element, GfxAction[x][y], GfxDir[x][y]);
9424 if (!IS_MOVING(x, y) && (CAN_FALL(element) || CAN_MOVE(element)))
9428 element = Feld[x][y];
9429 graphic = el_act_dir2img(element, GfxAction[x][y], GfxDir[x][y]);
9431 if (IS_ANIMATED(graphic) &&
9434 DrawLevelGraphicAnimationIfNeeded(x, y, graphic);
9436 if (IS_GEM(element) || element == EL_SP_INFOTRON)
9437 EdelsteinFunkeln(x, y);
9439 else if ((element == EL_ACID ||
9440 element == EL_EXIT_OPEN ||
9441 element == EL_SP_EXIT_OPEN ||
9442 element == EL_SP_TERMINAL ||
9443 element == EL_SP_TERMINAL_ACTIVE ||
9444 element == EL_EXTRA_TIME ||
9445 element == EL_SHIELD_NORMAL ||
9446 element == EL_SHIELD_DEADLY) &&
9447 IS_ANIMATED(graphic))
9448 DrawLevelGraphicAnimationIfNeeded(x, y, graphic);
9449 else if (IS_MOVING(x, y))
9450 ContinueMoving(x, y);
9451 else if (IS_ACTIVE_BOMB(element))
9452 CheckDynamite(x, y);
9453 else if (element == EL_AMOEBA_GROWING)
9454 AmoebeWaechst(x, y);
9455 else if (element == EL_AMOEBA_SHRINKING)
9456 AmoebaDisappearing(x, y);
9458 #if !USE_NEW_AMOEBA_CODE
9459 else if (IS_AMOEBALIVE(element))
9460 AmoebeAbleger(x, y);
9463 else if (element == EL_GAME_OF_LIFE || element == EL_BIOMAZE)
9465 else if (element == EL_EXIT_CLOSED)
9467 else if (element == EL_SP_EXIT_CLOSED)
9469 else if (element == EL_EXPANDABLE_WALL_GROWING)
9471 else if (element == EL_EXPANDABLE_WALL ||
9472 element == EL_EXPANDABLE_WALL_HORIZONTAL ||
9473 element == EL_EXPANDABLE_WALL_VERTICAL ||
9474 element == EL_EXPANDABLE_WALL_ANY ||
9475 element == EL_BD_EXPANDABLE_WALL)
9477 else if (element == EL_FLAMES)
9478 CheckForDragon(x, y);
9479 else if (element == EL_EXPLOSION)
9480 ; /* drawing of correct explosion animation is handled separately */
9481 else if (element == EL_ELEMENT_SNAPPING ||
9482 element == EL_DIAGONAL_SHRINKING ||
9483 element == EL_DIAGONAL_GROWING)
9485 graphic = el_act_dir2img(GfxElement[x][y], GfxAction[x][y],GfxDir[x][y]);
9487 DrawLevelGraphicAnimationIfNeeded(x, y, graphic);
9489 else if (IS_ANIMATED(graphic) && !IS_CHANGING(x, y))
9490 DrawLevelGraphicAnimationIfNeeded(x, y, graphic);
9492 if (IS_BELT_ACTIVE(element))
9493 PlayLevelSoundAction(x, y, ACTION_ACTIVE);
9495 if (game.magic_wall_active)
9497 int jx = local_player->jx, jy = local_player->jy;
9499 /* play the element sound at the position nearest to the player */
9500 if ((element == EL_MAGIC_WALL_FULL ||
9501 element == EL_MAGIC_WALL_ACTIVE ||
9502 element == EL_MAGIC_WALL_EMPTYING ||
9503 element == EL_BD_MAGIC_WALL_FULL ||
9504 element == EL_BD_MAGIC_WALL_ACTIVE ||
9505 element == EL_BD_MAGIC_WALL_EMPTYING) &&
9506 ABS(x-jx) + ABS(y-jy) < ABS(magic_wall_x-jx) + ABS(magic_wall_y-jy))
9514 #if USE_NEW_AMOEBA_CODE
9515 /* new experimental amoeba growth stuff */
9516 if (!(FrameCounter % 8))
9518 static unsigned long random = 1684108901;
9520 for (i = 0; i < level.amoeba_speed * 28 / 8; i++)
9522 x = RND(lev_fieldx);
9523 y = RND(lev_fieldy);
9524 element = Feld[x][y];
9526 if (!IS_PLAYER(x,y) &&
9527 (element == EL_EMPTY ||
9528 CAN_GROW_INTO(element) ||
9529 element == EL_QUICKSAND_EMPTY ||
9530 element == EL_ACID_SPLASH_LEFT ||
9531 element == EL_ACID_SPLASH_RIGHT))
9533 if ((IN_LEV_FIELD(x, y-1) && Feld[x][y-1] == EL_AMOEBA_WET) ||
9534 (IN_LEV_FIELD(x-1, y) && Feld[x-1][y] == EL_AMOEBA_WET) ||
9535 (IN_LEV_FIELD(x+1, y) && Feld[x+1][y] == EL_AMOEBA_WET) ||
9536 (IN_LEV_FIELD(x, y+1) && Feld[x][y+1] == EL_AMOEBA_WET))
9537 Feld[x][y] = EL_AMOEBA_DROP;
9540 random = random * 129 + 1;
9546 if (game.explosions_delayed)
9549 game.explosions_delayed = FALSE;
9551 SCAN_PLAYFIELD(x, y)
9553 element = Feld[x][y];
9555 if (ExplodeField[x][y])
9556 Explode(x, y, EX_PHASE_START, ExplodeField[x][y]);
9557 else if (element == EL_EXPLOSION)
9558 Explode(x, y, ExplodePhase[x][y], EX_TYPE_NORMAL);
9560 ExplodeField[x][y] = EX_TYPE_NONE;
9563 game.explosions_delayed = TRUE;
9566 if (game.magic_wall_active)
9568 if (!(game.magic_wall_time_left % 4))
9570 int element = Feld[magic_wall_x][magic_wall_y];
9572 if (element == EL_BD_MAGIC_WALL_FULL ||
9573 element == EL_BD_MAGIC_WALL_ACTIVE ||
9574 element == EL_BD_MAGIC_WALL_EMPTYING)
9575 PlayLevelSound(magic_wall_x, magic_wall_y, SND_BD_MAGIC_WALL_ACTIVE);
9577 PlayLevelSound(magic_wall_x, magic_wall_y, SND_MAGIC_WALL_ACTIVE);
9580 if (game.magic_wall_time_left > 0)
9582 game.magic_wall_time_left--;
9583 if (!game.magic_wall_time_left)
9585 SCAN_PLAYFIELD(x, y)
9587 element = Feld[x][y];
9589 if (element == EL_MAGIC_WALL_ACTIVE ||
9590 element == EL_MAGIC_WALL_FULL)
9592 Feld[x][y] = EL_MAGIC_WALL_DEAD;
9593 DrawLevelField(x, y);
9595 else if (element == EL_BD_MAGIC_WALL_ACTIVE ||
9596 element == EL_BD_MAGIC_WALL_FULL)
9598 Feld[x][y] = EL_BD_MAGIC_WALL_DEAD;
9599 DrawLevelField(x, y);
9603 game.magic_wall_active = FALSE;
9608 if (game.light_time_left > 0)
9610 game.light_time_left--;
9612 if (game.light_time_left == 0)
9613 RedrawAllLightSwitchesAndInvisibleElements();
9616 if (game.timegate_time_left > 0)
9618 game.timegate_time_left--;
9620 if (game.timegate_time_left == 0)
9621 CloseAllOpenTimegates();
9624 if (game.lenses_time_left > 0)
9626 game.lenses_time_left--;
9628 if (game.lenses_time_left == 0)
9629 RedrawAllInvisibleElementsForLenses();
9632 if (game.magnify_time_left > 0)
9634 game.magnify_time_left--;
9636 if (game.magnify_time_left == 0)
9637 RedrawAllInvisibleElementsForMagnifier();
9640 for (i = 0; i < MAX_PLAYERS; i++)
9642 struct PlayerInfo *player = &stored_player[i];
9644 if (SHIELD_ON(player))
9646 if (player->shield_deadly_time_left)
9647 PlayLevelSound(player->jx, player->jy, SND_SHIELD_DEADLY_ACTIVE);
9648 else if (player->shield_normal_time_left)
9649 PlayLevelSound(player->jx, player->jy, SND_SHIELD_NORMAL_ACTIVE);
9656 PlayAllPlayersSound();
9658 if (options.debug) /* calculate frames per second */
9660 static unsigned long fps_counter = 0;
9661 static int fps_frames = 0;
9662 unsigned long fps_delay_ms = Counter() - fps_counter;
9666 if (fps_delay_ms >= 500) /* calculate fps every 0.5 seconds */
9668 global.frames_per_second = 1000 * (float)fps_frames / fps_delay_ms;
9671 fps_counter = Counter();
9674 redraw_mask |= REDRAW_FPS;
9677 AdvanceFrameAndPlayerCounters(-1); /* advance counters for all players */
9679 if (local_player->show_envelope != 0 && local_player->MovPos == 0)
9681 ShowEnvelope(local_player->show_envelope - EL_ENVELOPE_1);
9683 local_player->show_envelope = 0;
9686 /* use random number generator in every frame to make it less predictable */
9687 if (game.engine_version >= VERSION_IDENT(3,1,1,0))
9691 static boolean AllPlayersInSight(struct PlayerInfo *player, int x, int y)
9693 int min_x = x, min_y = y, max_x = x, max_y = y;
9696 for (i = 0; i < MAX_PLAYERS; i++)
9698 int jx = stored_player[i].jx, jy = stored_player[i].jy;
9700 if (!stored_player[i].active || &stored_player[i] == player)
9703 min_x = MIN(min_x, jx);
9704 min_y = MIN(min_y, jy);
9705 max_x = MAX(max_x, jx);
9706 max_y = MAX(max_y, jy);
9709 return (max_x - min_x < SCR_FIELDX && max_y - min_y < SCR_FIELDY);
9712 static boolean AllPlayersInVisibleScreen()
9716 for (i = 0; i < MAX_PLAYERS; i++)
9718 int jx = stored_player[i].jx, jy = stored_player[i].jy;
9720 if (!stored_player[i].active)
9723 if (!IN_VIS_FIELD(SCREENX(jx), SCREENY(jy)))
9730 void ScrollLevel(int dx, int dy)
9732 int softscroll_offset = (setup.soft_scrolling ? TILEX : 0);
9735 BlitBitmap(drawto_field, drawto_field,
9736 FX + TILEX * (dx == -1) - softscroll_offset,
9737 FY + TILEY * (dy == -1) - softscroll_offset,
9738 SXSIZE - TILEX * (dx!=0) + 2 * softscroll_offset,
9739 SYSIZE - TILEY * (dy!=0) + 2 * softscroll_offset,
9740 FX + TILEX * (dx == 1) - softscroll_offset,
9741 FY + TILEY * (dy == 1) - softscroll_offset);
9745 x = (dx == 1 ? BX1 : BX2);
9746 for (y = BY1; y <= BY2; y++)
9747 DrawScreenField(x, y);
9752 y = (dy == 1 ? BY1 : BY2);
9753 for (x = BX1; x <= BX2; x++)
9754 DrawScreenField(x, y);
9757 redraw_mask |= REDRAW_FIELD;
9760 static boolean canFallDown(struct PlayerInfo *player)
9762 int jx = player->jx, jy = player->jy;
9764 return (IN_LEV_FIELD(jx, jy + 1) &&
9765 (IS_FREE(jx, jy + 1) ||
9766 (Feld[jx][jy + 1] == EL_ACID && player->can_fall_into_acid)) &&
9767 IS_WALKABLE_FROM(Feld[jx][jy], MV_DOWN) &&
9768 !IS_WALKABLE_INSIDE(Feld[jx][jy]));
9771 static boolean canPassField(int x, int y, int move_dir)
9773 int opposite_dir = MV_DIR_OPPOSITE(move_dir);
9774 int dx = (move_dir & MV_LEFT ? -1 : move_dir & MV_RIGHT ? +1 : 0);
9775 int dy = (move_dir & MV_UP ? -1 : move_dir & MV_DOWN ? +1 : 0);
9778 int element = Feld[x][y];
9780 return (IS_PASSABLE_FROM(element, opposite_dir) &&
9781 !CAN_MOVE(element) &&
9782 IN_LEV_FIELD(nextx, nexty) && !IS_PLAYER(nextx, nexty) &&
9783 IS_WALKABLE_FROM(Feld[nextx][nexty], move_dir) &&
9784 (level.can_pass_to_walkable || IS_FREE(nextx, nexty)));
9787 static boolean canMoveToValidFieldWithGravity(int x, int y, int move_dir)
9789 int opposite_dir = MV_DIR_OPPOSITE(move_dir);
9790 int dx = (move_dir & MV_LEFT ? -1 : move_dir & MV_RIGHT ? +1 : 0);
9791 int dy = (move_dir & MV_UP ? -1 : move_dir & MV_DOWN ? +1 : 0);
9795 return (IN_LEV_FIELD(newx, newy) && !IS_FREE_OR_PLAYER(newx, newy) &&
9796 IS_GRAVITY_REACHABLE(Feld[newx][newy]) &&
9797 (IS_DIGGABLE(Feld[newx][newy]) ||
9798 IS_WALKABLE_FROM(Feld[newx][newy], opposite_dir) ||
9799 canPassField(newx, newy, move_dir)));
9802 static void CheckGravityMovement(struct PlayerInfo *player)
9804 #if USE_PLAYER_GRAVITY
9805 if (player->gravity && !player->programmed_action)
9807 if (game.gravity && !player->programmed_action)
9810 int move_dir_horizontal = player->effective_action & MV_HORIZONTAL;
9811 int move_dir_vertical = player->effective_action & MV_VERTICAL;
9812 boolean player_is_snapping = (player->effective_action & JOY_BUTTON_1);
9813 int jx = player->jx, jy = player->jy;
9814 boolean player_is_moving_to_valid_field =
9815 (!player_is_snapping &&
9816 (canMoveToValidFieldWithGravity(jx, jy, move_dir_horizontal) ||
9817 canMoveToValidFieldWithGravity(jx, jy, move_dir_vertical)));
9818 boolean player_can_fall_down = canFallDown(player);
9820 if (player_can_fall_down &&
9821 !player_is_moving_to_valid_field)
9822 player->programmed_action = MV_DOWN;
9826 static void CheckGravityMovementWhenNotMoving(struct PlayerInfo *player)
9828 return CheckGravityMovement(player);
9830 #if USE_PLAYER_GRAVITY
9831 if (player->gravity && !player->programmed_action)
9833 if (game.gravity && !player->programmed_action)
9836 int jx = player->jx, jy = player->jy;
9837 boolean field_under_player_is_free =
9838 (IN_LEV_FIELD(jx, jy + 1) && IS_FREE(jx, jy + 1));
9839 boolean player_is_standing_on_valid_field =
9840 (IS_WALKABLE_INSIDE(Feld[jx][jy]) ||
9841 (IS_WALKABLE(Feld[jx][jy]) &&
9842 !(element_info[Feld[jx][jy]].access_direction & MV_DOWN)));
9844 if (field_under_player_is_free && !player_is_standing_on_valid_field)
9845 player->programmed_action = MV_DOWN;
9851 -----------------------------------------------------------------------------
9852 dx, dy: direction (non-diagonal) to try to move the player to
9853 real_dx, real_dy: direction as read from input device (can be diagonal)
9856 boolean MovePlayerOneStep(struct PlayerInfo *player,
9857 int dx, int dy, int real_dx, int real_dy)
9859 int jx = player->jx, jy = player->jy;
9860 int new_jx = jx + dx, new_jy = jy + dy;
9861 #if !USE_FIXED_DONT_RUN_INTO
9865 boolean player_can_move = !player->cannot_move;
9867 if (!player->active || (!dx && !dy))
9868 return MP_NO_ACTION;
9870 player->MovDir = (dx < 0 ? MV_LEFT :
9873 dy > 0 ? MV_DOWN : MV_NONE);
9875 if (!IN_LEV_FIELD(new_jx, new_jy))
9876 return MP_NO_ACTION;
9878 if (!player_can_move)
9880 if (player->MovPos == 0)
9882 player->is_moving = FALSE;
9883 player->is_digging = FALSE;
9884 player->is_collecting = FALSE;
9885 player->is_snapping = FALSE;
9886 player->is_pushing = FALSE;
9891 if (!options.network && game.centered_player_nr == -1 &&
9892 !AllPlayersInSight(player, new_jx, new_jy))
9893 return MP_NO_ACTION;
9895 if (!options.network && !AllPlayersInSight(player, new_jx, new_jy))
9896 return MP_NO_ACTION;
9899 #if !USE_FIXED_DONT_RUN_INTO
9900 element = MovingOrBlocked2ElementIfNotLeaving(new_jx, new_jy);
9902 /* (moved to DigField()) */
9903 if (player_can_move && DONT_RUN_INTO(element))
9905 if (element == EL_ACID && dx == 0 && dy == 1)
9907 SplashAcid(new_jx, new_jy);
9908 Feld[jx][jy] = EL_PLAYER_1;
9909 InitMovingField(jx, jy, MV_DOWN);
9910 Store[jx][jy] = EL_ACID;
9911 ContinueMoving(jx, jy);
9915 TestIfPlayerRunsIntoBadThing(jx, jy, player->MovDir);
9921 can_move = DigField(player, jx, jy, new_jx, new_jy, real_dx,real_dy, DF_DIG);
9922 if (can_move != MP_MOVING)
9925 /* check if DigField() has caused relocation of the player */
9926 if (player->jx != jx || player->jy != jy)
9927 return MP_NO_ACTION; /* <-- !!! CHECK THIS [-> MP_ACTION ?] !!! */
9929 StorePlayer[jx][jy] = 0;
9930 player->last_jx = jx;
9931 player->last_jy = jy;
9932 player->jx = new_jx;
9933 player->jy = new_jy;
9934 StorePlayer[new_jx][new_jy] = player->element_nr;
9936 if (player->move_delay_value_next != -1)
9938 player->move_delay_value = player->move_delay_value_next;
9939 player->move_delay_value_next = -1;
9943 (dx > 0 || dy > 0 ? -1 : 1) * (TILEX - TILEX / player->move_delay_value);
9945 player->step_counter++;
9947 PlayerVisit[jx][jy] = FrameCounter;
9949 #if USE_UFAST_PLAYER_EXIT_BUGFIX
9950 player->is_moving = TRUE;
9954 /* should better be called in MovePlayer(), but this breaks some tapes */
9955 ScrollPlayer(player, SCROLL_INIT);
9961 boolean MovePlayer(struct PlayerInfo *player, int dx, int dy)
9963 int jx = player->jx, jy = player->jy;
9964 int old_jx = jx, old_jy = jy;
9965 int moved = MP_NO_ACTION;
9967 if (!player->active)
9972 if (player->MovPos == 0)
9974 player->is_moving = FALSE;
9975 player->is_digging = FALSE;
9976 player->is_collecting = FALSE;
9977 player->is_snapping = FALSE;
9978 player->is_pushing = FALSE;
9984 if (player->move_delay > 0)
9987 player->move_delay = -1; /* set to "uninitialized" value */
9989 /* store if player is automatically moved to next field */
9990 player->is_auto_moving = (player->programmed_action != MV_NONE);
9992 /* remove the last programmed player action */
9993 player->programmed_action = 0;
9997 /* should only happen if pre-1.2 tape recordings are played */
9998 /* this is only for backward compatibility */
10000 int original_move_delay_value = player->move_delay_value;
10003 printf("THIS SHOULD ONLY HAPPEN WITH PRE-1.2 LEVEL TAPES. [%ld]\n",
10007 /* scroll remaining steps with finest movement resolution */
10008 player->move_delay_value = MOVE_DELAY_NORMAL_SPEED;
10010 while (player->MovPos)
10012 ScrollPlayer(player, SCROLL_GO_ON);
10013 ScrollScreen(NULL, SCROLL_GO_ON);
10015 AdvanceFrameAndPlayerCounters(player->index_nr);
10021 player->move_delay_value = original_move_delay_value;
10024 player->is_active = FALSE;
10026 if (player->last_move_dir & MV_HORIZONTAL)
10028 if (!(moved |= MovePlayerOneStep(player, 0, dy, dx, dy)))
10029 moved |= MovePlayerOneStep(player, dx, 0, dx, dy);
10033 if (!(moved |= MovePlayerOneStep(player, dx, 0, dx, dy)))
10034 moved |= MovePlayerOneStep(player, 0, dy, dx, dy);
10037 #if USE_FIXED_BORDER_RUNNING_GFX
10038 if (!moved && !player->is_active)
10040 player->is_moving = FALSE;
10041 player->is_digging = FALSE;
10042 player->is_collecting = FALSE;
10043 player->is_snapping = FALSE;
10044 player->is_pushing = FALSE;
10052 if (moved & MP_MOVING && !ScreenMovPos &&
10053 (player->index_nr == game.centered_player_nr ||
10054 game.centered_player_nr == -1))
10056 if (moved & MP_MOVING && !ScreenMovPos &&
10057 (player == local_player || !options.network))
10060 int old_scroll_x = scroll_x, old_scroll_y = scroll_y;
10061 int offset = (setup.scroll_delay ? 3 : 0);
10063 if (!IN_VIS_FIELD(SCREENX(jx), SCREENY(jy)))
10065 /* actual player has left the screen -- scroll in that direction */
10066 if (jx != old_jx) /* player has moved horizontally */
10067 scroll_x += (jx - old_jx);
10068 else /* player has moved vertically */
10069 scroll_y += (jy - old_jy);
10073 if (jx != old_jx) /* player has moved horizontally */
10075 if ((player->MovDir == MV_LEFT && scroll_x > jx - MIDPOSX + offset) ||
10076 (player->MovDir == MV_RIGHT && scroll_x < jx - MIDPOSX - offset))
10077 scroll_x = jx-MIDPOSX + (scroll_x < jx-MIDPOSX ? -offset : +offset);
10079 /* don't scroll over playfield boundaries */
10080 if (scroll_x < SBX_Left || scroll_x > SBX_Right)
10081 scroll_x = (scroll_x < SBX_Left ? SBX_Left : SBX_Right);
10083 /* don't scroll more than one field at a time */
10084 scroll_x = old_scroll_x + SIGN(scroll_x - old_scroll_x);
10086 /* don't scroll against the player's moving direction */
10087 if ((player->MovDir == MV_LEFT && scroll_x > old_scroll_x) ||
10088 (player->MovDir == MV_RIGHT && scroll_x < old_scroll_x))
10089 scroll_x = old_scroll_x;
10091 else /* player has moved vertically */
10093 if ((player->MovDir == MV_UP && scroll_y > jy - MIDPOSY + offset) ||
10094 (player->MovDir == MV_DOWN && scroll_y < jy - MIDPOSY - offset))
10095 scroll_y = jy-MIDPOSY + (scroll_y < jy-MIDPOSY ? -offset : +offset);
10097 /* don't scroll over playfield boundaries */
10098 if (scroll_y < SBY_Upper || scroll_y > SBY_Lower)
10099 scroll_y = (scroll_y < SBY_Upper ? SBY_Upper : SBY_Lower);
10101 /* don't scroll more than one field at a time */
10102 scroll_y = old_scroll_y + SIGN(scroll_y - old_scroll_y);
10104 /* don't scroll against the player's moving direction */
10105 if ((player->MovDir == MV_UP && scroll_y > old_scroll_y) ||
10106 (player->MovDir == MV_DOWN && scroll_y < old_scroll_y))
10107 scroll_y = old_scroll_y;
10111 if (scroll_x != old_scroll_x || scroll_y != old_scroll_y)
10114 if (!options.network && game.centered_player_nr == -1 &&
10115 !AllPlayersInVisibleScreen())
10117 scroll_x = old_scroll_x;
10118 scroll_y = old_scroll_y;
10122 if (!options.network && !AllPlayersInVisibleScreen())
10124 scroll_x = old_scroll_x;
10125 scroll_y = old_scroll_y;
10130 ScrollScreen(player, SCROLL_INIT);
10131 ScrollLevel(old_scroll_x - scroll_x, old_scroll_y - scroll_y);
10136 player->StepFrame = 0;
10138 if (moved & MP_MOVING)
10140 if (old_jx != jx && old_jy == jy)
10141 player->MovDir = (old_jx < jx ? MV_RIGHT : MV_LEFT);
10142 else if (old_jx == jx && old_jy != jy)
10143 player->MovDir = (old_jy < jy ? MV_DOWN : MV_UP);
10145 DrawLevelField(jx, jy); /* for "crumbled sand" */
10147 player->last_move_dir = player->MovDir;
10148 player->is_moving = TRUE;
10149 player->is_snapping = FALSE;
10150 player->is_switching = FALSE;
10151 player->is_dropping = FALSE;
10152 player->is_dropping_pressed = FALSE;
10153 player->drop_pressed_delay = 0;
10156 /* should better be called here than above, but this breaks some tapes */
10157 ScrollPlayer(player, SCROLL_INIT);
10162 CheckGravityMovementWhenNotMoving(player);
10164 player->is_moving = FALSE;
10166 /* at this point, the player is allowed to move, but cannot move right now
10167 (e.g. because of something blocking the way) -- ensure that the player
10168 is also allowed to move in the next frame (in old versions before 3.1.1,
10169 the player was forced to wait again for eight frames before next try) */
10171 if (game.engine_version >= VERSION_IDENT(3,1,1,0))
10172 player->move_delay = 0; /* allow direct movement in the next frame */
10175 if (player->move_delay == -1) /* not yet initialized by DigField() */
10176 player->move_delay = player->move_delay_value;
10178 if (game.engine_version < VERSION_IDENT(3,0,7,0))
10180 TestIfPlayerTouchesBadThing(jx, jy);
10181 TestIfPlayerTouchesCustomElement(jx, jy);
10184 if (!player->active)
10185 RemovePlayer(player);
10190 void ScrollPlayer(struct PlayerInfo *player, int mode)
10192 int jx = player->jx, jy = player->jy;
10193 int last_jx = player->last_jx, last_jy = player->last_jy;
10194 int move_stepsize = TILEX / player->move_delay_value;
10196 #if USE_NEW_PLAYER_SPEED
10197 if (!player->active)
10200 if (player->MovPos == 0 && mode == SCROLL_GO_ON) /* player not moving */
10203 if (!player->active || player->MovPos == 0)
10207 if (mode == SCROLL_INIT)
10209 player->actual_frame_counter = FrameCounter;
10210 player->GfxPos = move_stepsize * (player->MovPos / move_stepsize);
10212 if ((player->block_last_field || player->block_delay_adjustment > 0) &&
10213 Feld[last_jx][last_jy] == EL_EMPTY)
10215 int last_field_block_delay = 0; /* start with no blocking at all */
10216 int block_delay_adjustment = player->block_delay_adjustment;
10218 /* if player blocks last field, add delay for exactly one move */
10219 if (player->block_last_field)
10221 last_field_block_delay += player->move_delay_value;
10223 /* when blocking enabled, prevent moving up despite gravity */
10224 #if USE_PLAYER_GRAVITY
10225 if (player->gravity && player->MovDir == MV_UP)
10226 block_delay_adjustment = -1;
10228 if (game.gravity && player->MovDir == MV_UP)
10229 block_delay_adjustment = -1;
10233 /* add block delay adjustment (also possible when not blocking) */
10234 last_field_block_delay += block_delay_adjustment;
10236 Feld[last_jx][last_jy] = EL_PLAYER_IS_LEAVING;
10237 MovDelay[last_jx][last_jy] = last_field_block_delay + 1;
10240 #if USE_NEW_PLAYER_SPEED
10241 if (player->MovPos != 0) /* player has not yet reached destination */
10247 else if (!FrameReached(&player->actual_frame_counter, 1))
10250 #if USE_NEW_PLAYER_SPEED
10251 if (player->MovPos != 0)
10253 player->MovPos += (player->MovPos > 0 ? -1 : 1) * move_stepsize;
10254 player->GfxPos = move_stepsize * (player->MovPos / move_stepsize);
10256 /* before DrawPlayer() to draw correct player graphic for this case */
10257 if (player->MovPos == 0)
10258 CheckGravityMovement(player);
10261 player->MovPos += (player->MovPos > 0 ? -1 : 1) * move_stepsize;
10262 player->GfxPos = move_stepsize * (player->MovPos / move_stepsize);
10264 /* before DrawPlayer() to draw correct player graphic for this case */
10265 if (player->MovPos == 0)
10266 CheckGravityMovement(player);
10269 if (player->MovPos == 0) /* player reached destination field */
10271 if (player->move_delay_reset_counter > 0)
10273 player->move_delay_reset_counter--;
10275 if (player->move_delay_reset_counter == 0)
10277 /* continue with normal speed after quickly moving through gate */
10278 HALVE_PLAYER_SPEED(player);
10280 /* be able to make the next move without delay */
10281 player->move_delay = 0;
10285 player->last_jx = jx;
10286 player->last_jy = jy;
10288 if (Feld[jx][jy] == EL_EXIT_OPEN ||
10289 Feld[jx][jy] == EL_SP_EXIT_OPEN ||
10290 Feld[jx][jy] == EL_SP_EXIT_OPENING) /* <-- special case */
10292 DrawPlayer(player); /* needed here only to cleanup last field */
10293 RemovePlayer(player);
10295 if (local_player->friends_still_needed == 0 ||
10296 IS_SP_ELEMENT(Feld[jx][jy]))
10297 PlayerWins(player);
10300 /* this breaks one level: "machine", level 000 */
10302 int move_direction = player->MovDir;
10303 int enter_side = MV_DIR_OPPOSITE(move_direction);
10304 int leave_side = move_direction;
10305 int old_jx = last_jx;
10306 int old_jy = last_jy;
10307 int old_element = Feld[old_jx][old_jy];
10308 int new_element = Feld[jx][jy];
10310 if (IS_CUSTOM_ELEMENT(old_element))
10311 CheckElementChangeByPlayer(old_jx, old_jy, old_element,
10313 player->index_bit, leave_side);
10315 CheckTriggeredElementChangeByPlayer(old_jx, old_jy, old_element,
10316 CE_PLAYER_LEAVES_X,
10317 player->index_bit, leave_side);
10319 if (IS_CUSTOM_ELEMENT(new_element))
10320 CheckElementChangeByPlayer(jx, jy, new_element, CE_ENTERED_BY_PLAYER,
10321 player->index_bit, enter_side);
10323 CheckTriggeredElementChangeByPlayer(jx, jy, new_element,
10324 CE_PLAYER_ENTERS_X,
10325 player->index_bit, enter_side);
10327 CheckTriggeredElementChangeBySide(jx, jy, player->element_nr,
10328 CE_MOVE_OF_X, move_direction);
10331 if (game.engine_version >= VERSION_IDENT(3,0,7,0))
10333 TestIfPlayerTouchesBadThing(jx, jy);
10334 TestIfPlayerTouchesCustomElement(jx, jy);
10336 /* needed because pushed element has not yet reached its destination,
10337 so it would trigger a change event at its previous field location */
10338 if (!player->is_pushing)
10339 TestIfElementTouchesCustomElement(jx, jy); /* for empty space */
10341 if (!player->active)
10342 RemovePlayer(player);
10345 if (!local_player->LevelSolved && level.use_step_counter)
10355 if (TimeLeft <= 10 && setup.time_limit)
10356 PlaySound(SND_GAME_RUNNING_OUT_OF_TIME);
10358 DrawGameValue_Time(TimeLeft);
10360 if (!TimeLeft && setup.time_limit)
10361 for (i = 0; i < MAX_PLAYERS; i++)
10362 KillPlayer(&stored_player[i]);
10364 else if (level.time == 0 && !AllPlayersGone) /* level w/o time limit */
10365 DrawGameValue_Time(TimePlayed);
10368 if (tape.single_step && tape.recording && !tape.pausing &&
10369 !player->programmed_action)
10370 TapeTogglePause(TAPE_TOGGLE_AUTOMATIC);
10374 void ScrollScreen(struct PlayerInfo *player, int mode)
10376 static unsigned long screen_frame_counter = 0;
10378 if (mode == SCROLL_INIT)
10380 /* set scrolling step size according to actual player's moving speed */
10381 ScrollStepSize = TILEX / player->move_delay_value;
10383 screen_frame_counter = FrameCounter;
10384 ScreenMovDir = player->MovDir;
10385 ScreenMovPos = player->MovPos;
10386 ScreenGfxPos = ScrollStepSize * (ScreenMovPos / ScrollStepSize);
10389 else if (!FrameReached(&screen_frame_counter, 1))
10394 ScreenMovPos += (ScreenMovPos > 0 ? -1 : 1) * ScrollStepSize;
10395 ScreenGfxPos = ScrollStepSize * (ScreenMovPos / ScrollStepSize);
10396 redraw_mask |= REDRAW_FIELD;
10399 ScreenMovDir = MV_NONE;
10402 void TestIfPlayerTouchesCustomElement(int x, int y)
10404 static int xy[4][2] =
10411 static int trigger_sides[4][2] =
10413 /* center side border side */
10414 { CH_SIDE_TOP, CH_SIDE_BOTTOM }, /* check top */
10415 { CH_SIDE_LEFT, CH_SIDE_RIGHT }, /* check left */
10416 { CH_SIDE_RIGHT, CH_SIDE_LEFT }, /* check right */
10417 { CH_SIDE_BOTTOM, CH_SIDE_TOP } /* check bottom */
10419 static int touch_dir[4] =
10421 MV_LEFT | MV_RIGHT,
10426 int center_element = Feld[x][y]; /* should always be non-moving! */
10429 for (i = 0; i < NUM_DIRECTIONS; i++)
10431 int xx = x + xy[i][0];
10432 int yy = y + xy[i][1];
10433 int center_side = trigger_sides[i][0];
10434 int border_side = trigger_sides[i][1];
10435 int border_element;
10437 if (!IN_LEV_FIELD(xx, yy))
10440 if (IS_PLAYER(x, y))
10442 struct PlayerInfo *player = PLAYERINFO(x, y);
10444 if (game.engine_version < VERSION_IDENT(3,0,7,0))
10445 border_element = Feld[xx][yy]; /* may be moving! */
10446 else if (!IS_MOVING(xx, yy) && !IS_BLOCKED(xx, yy))
10447 border_element = Feld[xx][yy];
10448 else if (MovDir[xx][yy] & touch_dir[i]) /* elements are touching */
10449 border_element = MovingOrBlocked2Element(xx, yy);
10451 continue; /* center and border element do not touch */
10453 CheckElementChangeByPlayer(xx, yy, border_element, CE_TOUCHED_BY_PLAYER,
10454 player->index_bit, border_side);
10455 CheckTriggeredElementChangeByPlayer(xx, yy, border_element,
10456 CE_PLAYER_TOUCHES_X,
10457 player->index_bit, border_side);
10459 else if (IS_PLAYER(xx, yy))
10461 struct PlayerInfo *player = PLAYERINFO(xx, yy);
10463 if (game.engine_version >= VERSION_IDENT(3,0,7,0))
10465 if (player->MovPos != 0 && !(player->MovDir & touch_dir[i]))
10466 continue; /* center and border element do not touch */
10469 CheckElementChangeByPlayer(x, y, center_element, CE_TOUCHED_BY_PLAYER,
10470 player->index_bit, center_side);
10471 CheckTriggeredElementChangeByPlayer(x, y, center_element,
10472 CE_PLAYER_TOUCHES_X,
10473 player->index_bit, center_side);
10479 #if USE_ELEMENT_TOUCHING_BUGFIX
10481 void TestIfElementTouchesCustomElement(int x, int y)
10483 static int xy[4][2] =
10490 static int trigger_sides[4][2] =
10492 /* center side border side */
10493 { CH_SIDE_TOP, CH_SIDE_BOTTOM }, /* check top */
10494 { CH_SIDE_LEFT, CH_SIDE_RIGHT }, /* check left */
10495 { CH_SIDE_RIGHT, CH_SIDE_LEFT }, /* check right */
10496 { CH_SIDE_BOTTOM, CH_SIDE_TOP } /* check bottom */
10498 static int touch_dir[4] =
10500 MV_LEFT | MV_RIGHT,
10505 boolean change_center_element = FALSE;
10506 int center_element = Feld[x][y]; /* should always be non-moving! */
10507 int border_element_old[NUM_DIRECTIONS];
10510 for (i = 0; i < NUM_DIRECTIONS; i++)
10512 int xx = x + xy[i][0];
10513 int yy = y + xy[i][1];
10514 int border_element;
10516 border_element_old[i] = -1;
10518 if (!IN_LEV_FIELD(xx, yy))
10521 if (game.engine_version < VERSION_IDENT(3,0,7,0))
10522 border_element = Feld[xx][yy]; /* may be moving! */
10523 else if (!IS_MOVING(xx, yy) && !IS_BLOCKED(xx, yy))
10524 border_element = Feld[xx][yy];
10525 else if (MovDir[xx][yy] & touch_dir[i]) /* elements are touching */
10526 border_element = MovingOrBlocked2Element(xx, yy);
10528 continue; /* center and border element do not touch */
10530 border_element_old[i] = border_element;
10533 for (i = 0; i < NUM_DIRECTIONS; i++)
10535 int xx = x + xy[i][0];
10536 int yy = y + xy[i][1];
10537 int center_side = trigger_sides[i][0];
10538 int border_element = border_element_old[i];
10540 if (border_element == -1)
10543 /* check for change of border element */
10544 CheckElementChangeBySide(xx, yy, border_element, center_element,
10545 CE_TOUCHING_X, center_side);
10548 for (i = 0; i < NUM_DIRECTIONS; i++)
10550 int border_side = trigger_sides[i][1];
10551 int border_element = border_element_old[i];
10553 if (border_element == -1)
10556 /* check for change of center element (but change it only once) */
10557 if (!change_center_element)
10558 change_center_element =
10559 CheckElementChangeBySide(x, y, center_element, border_element,
10560 CE_TOUCHING_X, border_side);
10566 void TestIfElementTouchesCustomElement_OLD(int x, int y)
10568 static int xy[4][2] =
10575 static int trigger_sides[4][2] =
10577 /* center side border side */
10578 { CH_SIDE_TOP, CH_SIDE_BOTTOM }, /* check top */
10579 { CH_SIDE_LEFT, CH_SIDE_RIGHT }, /* check left */
10580 { CH_SIDE_RIGHT, CH_SIDE_LEFT }, /* check right */
10581 { CH_SIDE_BOTTOM, CH_SIDE_TOP } /* check bottom */
10583 static int touch_dir[4] =
10585 MV_LEFT | MV_RIGHT,
10590 boolean change_center_element = FALSE;
10591 int center_element = Feld[x][y]; /* should always be non-moving! */
10594 for (i = 0; i < NUM_DIRECTIONS; i++)
10596 int xx = x + xy[i][0];
10597 int yy = y + xy[i][1];
10598 int center_side = trigger_sides[i][0];
10599 int border_side = trigger_sides[i][1];
10600 int border_element;
10602 if (!IN_LEV_FIELD(xx, yy))
10605 if (game.engine_version < VERSION_IDENT(3,0,7,0))
10606 border_element = Feld[xx][yy]; /* may be moving! */
10607 else if (!IS_MOVING(xx, yy) && !IS_BLOCKED(xx, yy))
10608 border_element = Feld[xx][yy];
10609 else if (MovDir[xx][yy] & touch_dir[i]) /* elements are touching */
10610 border_element = MovingOrBlocked2Element(xx, yy);
10612 continue; /* center and border element do not touch */
10614 /* check for change of center element (but change it only once) */
10615 if (!change_center_element)
10616 change_center_element =
10617 CheckElementChangeBySide(x, y, center_element, border_element,
10618 CE_TOUCHING_X, border_side);
10620 /* check for change of border element */
10621 CheckElementChangeBySide(xx, yy, border_element, center_element,
10622 CE_TOUCHING_X, center_side);
10628 void TestIfElementHitsCustomElement(int x, int y, int direction)
10630 int dx = (direction == MV_LEFT ? -1 : direction == MV_RIGHT ? +1 : 0);
10631 int dy = (direction == MV_UP ? -1 : direction == MV_DOWN ? +1 : 0);
10632 int hitx = x + dx, hity = y + dy;
10633 int hitting_element = Feld[x][y];
10634 int touched_element;
10636 if (IN_LEV_FIELD(hitx, hity) && IS_FREE(hitx, hity))
10639 touched_element = (IN_LEV_FIELD(hitx, hity) ?
10640 MovingOrBlocked2Element(hitx, hity) : EL_STEELWALL);
10642 if (IN_LEV_FIELD(hitx, hity))
10644 int opposite_direction = MV_DIR_OPPOSITE(direction);
10645 int hitting_side = direction;
10646 int touched_side = opposite_direction;
10647 boolean object_hit = (!IS_MOVING(hitx, hity) ||
10648 MovDir[hitx][hity] != direction ||
10649 ABS(MovPos[hitx][hity]) <= TILEY / 2);
10655 CheckElementChangeBySide(x, y, hitting_element, touched_element,
10656 CE_HITTING_X, touched_side);
10658 CheckElementChangeBySide(hitx, hity, touched_element,
10659 hitting_element, CE_HIT_BY_X, hitting_side);
10661 CheckElementChangeBySide(hitx, hity, touched_element, hitting_element,
10662 CE_HIT_BY_SOMETHING, opposite_direction);
10666 /* "hitting something" is also true when hitting the playfield border */
10667 CheckElementChangeBySide(x, y, hitting_element, touched_element,
10668 CE_HITTING_SOMETHING, direction);
10672 void TestIfElementSmashesCustomElement(int x, int y, int direction)
10674 int dx = (direction == MV_LEFT ? -1 : direction == MV_RIGHT ? +1 : 0);
10675 int dy = (direction == MV_UP ? -1 : direction == MV_DOWN ? +1 : 0);
10676 int hitx = x + dx, hity = y + dy;
10677 int hitting_element = Feld[x][y];
10678 int touched_element;
10680 boolean object_hit = (IN_LEV_FIELD(hitx, hity) &&
10681 !IS_FREE(hitx, hity) &&
10682 (!IS_MOVING(hitx, hity) ||
10683 MovDir[hitx][hity] != direction ||
10684 ABS(MovPos[hitx][hity]) <= TILEY / 2));
10687 if (IN_LEV_FIELD(hitx, hity) && IS_FREE(hitx, hity))
10691 if (IN_LEV_FIELD(hitx, hity) && !object_hit)
10695 touched_element = (IN_LEV_FIELD(hitx, hity) ?
10696 MovingOrBlocked2Element(hitx, hity) : EL_STEELWALL);
10698 CheckElementChangeBySide(x, y, hitting_element, touched_element,
10699 EP_CAN_SMASH_EVERYTHING, direction);
10701 if (IN_LEV_FIELD(hitx, hity))
10703 int opposite_direction = MV_DIR_OPPOSITE(direction);
10704 int hitting_side = direction;
10705 int touched_side = opposite_direction;
10707 int touched_element = MovingOrBlocked2Element(hitx, hity);
10710 boolean object_hit = (!IS_MOVING(hitx, hity) ||
10711 MovDir[hitx][hity] != direction ||
10712 ABS(MovPos[hitx][hity]) <= TILEY / 2);
10721 CheckElementChangeBySide(hitx, hity, touched_element, hitting_element,
10722 CE_SMASHED_BY_SOMETHING, opposite_direction);
10724 CheckElementChangeBySide(x, y, hitting_element, touched_element,
10725 CE_OTHER_IS_SMASHING, touched_side);
10727 CheckElementChangeBySide(hitx, hity, touched_element, hitting_element,
10728 CE_OTHER_GETS_SMASHED, hitting_side);
10734 void TestIfGoodThingHitsBadThing(int good_x, int good_y, int good_move_dir)
10736 int i, kill_x = -1, kill_y = -1;
10738 int bad_element = -1;
10739 static int test_xy[4][2] =
10746 static int test_dir[4] =
10754 for (i = 0; i < NUM_DIRECTIONS; i++)
10756 int test_x, test_y, test_move_dir, test_element;
10758 test_x = good_x + test_xy[i][0];
10759 test_y = good_y + test_xy[i][1];
10761 if (!IN_LEV_FIELD(test_x, test_y))
10765 (IS_MOVING(test_x, test_y) ? MovDir[test_x][test_y] : MV_NONE);
10767 test_element = MovingOrBlocked2ElementIfNotLeaving(test_x, test_y);
10769 /* 1st case: good thing is moving towards DONT_RUN_INTO style bad thing;
10770 2nd case: DONT_TOUCH style bad thing does not move away from good thing
10772 if ((DONT_RUN_INTO(test_element) && good_move_dir == test_dir[i]) ||
10773 (DONT_TOUCH(test_element) && test_move_dir != test_dir[i]))
10777 bad_element = test_element;
10783 if (kill_x != -1 || kill_y != -1)
10785 if (IS_PLAYER(good_x, good_y))
10787 struct PlayerInfo *player = PLAYERINFO(good_x, good_y);
10789 if (player->shield_deadly_time_left > 0 &&
10790 !IS_INDESTRUCTIBLE(bad_element))
10791 Bang(kill_x, kill_y);
10792 else if (!PLAYER_ENEMY_PROTECTED(good_x, good_y))
10793 KillPlayer(player);
10796 Bang(good_x, good_y);
10800 void TestIfBadThingHitsGoodThing(int bad_x, int bad_y, int bad_move_dir)
10802 int i, kill_x = -1, kill_y = -1;
10803 int bad_element = Feld[bad_x][bad_y];
10804 static int test_xy[4][2] =
10811 static int touch_dir[4] =
10813 MV_LEFT | MV_RIGHT,
10818 static int test_dir[4] =
10826 if (bad_element == EL_EXPLOSION) /* skip just exploding bad things */
10829 for (i = 0; i < NUM_DIRECTIONS; i++)
10831 int test_x, test_y, test_move_dir, test_element;
10833 test_x = bad_x + test_xy[i][0];
10834 test_y = bad_y + test_xy[i][1];
10835 if (!IN_LEV_FIELD(test_x, test_y))
10839 (IS_MOVING(test_x, test_y) ? MovDir[test_x][test_y] : MV_NONE);
10841 test_element = Feld[test_x][test_y];
10843 /* 1st case: good thing is moving towards DONT_RUN_INTO style bad thing;
10844 2nd case: DONT_TOUCH style bad thing does not move away from good thing
10846 if ((DONT_RUN_INTO(bad_element) && bad_move_dir == test_dir[i]) ||
10847 (DONT_TOUCH(bad_element) && test_move_dir != test_dir[i]))
10849 /* good thing is player or penguin that does not move away */
10850 if (IS_PLAYER(test_x, test_y))
10852 struct PlayerInfo *player = PLAYERINFO(test_x, test_y);
10854 if (bad_element == EL_ROBOT && player->is_moving)
10855 continue; /* robot does not kill player if he is moving */
10857 if (game.engine_version >= VERSION_IDENT(3,0,7,0))
10859 if (player->MovPos != 0 && !(player->MovDir & touch_dir[i]))
10860 continue; /* center and border element do not touch */
10867 else if (test_element == EL_PENGUIN)
10876 if (kill_x != -1 || kill_y != -1)
10878 if (IS_PLAYER(kill_x, kill_y))
10880 struct PlayerInfo *player = PLAYERINFO(kill_x, kill_y);
10882 if (player->shield_deadly_time_left > 0 &&
10883 !IS_INDESTRUCTIBLE(bad_element))
10884 Bang(bad_x, bad_y);
10885 else if (!PLAYER_ENEMY_PROTECTED(kill_x, kill_y))
10886 KillPlayer(player);
10889 Bang(kill_x, kill_y);
10893 void TestIfPlayerTouchesBadThing(int x, int y)
10895 TestIfGoodThingHitsBadThing(x, y, MV_NONE);
10898 void TestIfPlayerRunsIntoBadThing(int x, int y, int move_dir)
10900 TestIfGoodThingHitsBadThing(x, y, move_dir);
10903 void TestIfBadThingTouchesPlayer(int x, int y)
10905 TestIfBadThingHitsGoodThing(x, y, MV_NONE);
10908 void TestIfBadThingRunsIntoPlayer(int x, int y, int move_dir)
10910 TestIfBadThingHitsGoodThing(x, y, move_dir);
10913 void TestIfFriendTouchesBadThing(int x, int y)
10915 TestIfGoodThingHitsBadThing(x, y, MV_NONE);
10918 void TestIfBadThingTouchesFriend(int x, int y)
10920 TestIfBadThingHitsGoodThing(x, y, MV_NONE);
10923 void TestIfBadThingTouchesOtherBadThing(int bad_x, int bad_y)
10925 int i, kill_x = bad_x, kill_y = bad_y;
10926 static int xy[4][2] =
10934 for (i = 0; i < NUM_DIRECTIONS; i++)
10938 x = bad_x + xy[i][0];
10939 y = bad_y + xy[i][1];
10940 if (!IN_LEV_FIELD(x, y))
10943 element = Feld[x][y];
10944 if (IS_AMOEBOID(element) || element == EL_GAME_OF_LIFE ||
10945 element == EL_AMOEBA_GROWING || element == EL_AMOEBA_DROP)
10953 if (kill_x != bad_x || kill_y != bad_y)
10954 Bang(bad_x, bad_y);
10957 void KillPlayer(struct PlayerInfo *player)
10959 int jx = player->jx, jy = player->jy;
10961 if (!player->active)
10964 /* remove accessible field at the player's position */
10965 Feld[jx][jy] = EL_EMPTY;
10967 /* deactivate shield (else Bang()/Explode() would not work right) */
10968 player->shield_normal_time_left = 0;
10969 player->shield_deadly_time_left = 0;
10972 BuryPlayer(player);
10975 static void KillPlayerUnlessEnemyProtected(int x, int y)
10977 if (!PLAYER_ENEMY_PROTECTED(x, y))
10978 KillPlayer(PLAYERINFO(x, y));
10981 static void KillPlayerUnlessExplosionProtected(int x, int y)
10983 if (!PLAYER_EXPLOSION_PROTECTED(x, y))
10984 KillPlayer(PLAYERINFO(x, y));
10987 void BuryPlayer(struct PlayerInfo *player)
10989 int jx = player->jx, jy = player->jy;
10991 if (!player->active)
10994 PlayLevelSoundElementAction(jx, jy, player->artwork_element, ACTION_DYING);
10995 PlayLevelSound(jx, jy, SND_GAME_LOSING);
10997 player->GameOver = TRUE;
10998 RemovePlayer(player);
11001 void RemovePlayer(struct PlayerInfo *player)
11003 int jx = player->jx, jy = player->jy;
11004 int i, found = FALSE;
11006 player->present = FALSE;
11007 player->active = FALSE;
11009 if (!ExplodeField[jx][jy])
11010 StorePlayer[jx][jy] = 0;
11012 if (player->is_moving)
11013 DrawLevelField(player->last_jx, player->last_jy);
11015 for (i = 0; i < MAX_PLAYERS; i++)
11016 if (stored_player[i].active)
11020 AllPlayersGone = TRUE;
11026 #if USE_NEW_SNAP_DELAY
11027 static void setFieldForSnapping(int x, int y, int element, int direction)
11029 struct ElementInfo *ei = &element_info[element];
11030 int direction_bit = MV_DIR_TO_BIT(direction);
11031 int graphic_snapping = ei->direction_graphic[ACTION_SNAPPING][direction_bit];
11032 int action = (graphic_snapping != IMG_EMPTY_SPACE ? ACTION_SNAPPING :
11033 IS_DIGGABLE(element) ? ACTION_DIGGING : ACTION_COLLECTING);
11035 Feld[x][y] = EL_ELEMENT_SNAPPING;
11036 MovDelay[x][y] = MOVE_DELAY_NORMAL_SPEED + 1 - 1;
11038 ResetGfxAnimation(x, y);
11040 GfxElement[x][y] = element;
11041 GfxAction[x][y] = action;
11042 GfxDir[x][y] = direction;
11043 GfxFrame[x][y] = -1;
11048 =============================================================================
11049 checkDiagonalPushing()
11050 -----------------------------------------------------------------------------
11051 check if diagonal input device direction results in pushing of object
11052 (by checking if the alternative direction is walkable, diggable, ...)
11053 =============================================================================
11056 static boolean checkDiagonalPushing(struct PlayerInfo *player,
11057 int x, int y, int real_dx, int real_dy)
11059 int jx, jy, dx, dy, xx, yy;
11061 if (real_dx == 0 || real_dy == 0) /* no diagonal direction => push */
11064 /* diagonal direction: check alternative direction */
11069 xx = jx + (dx == 0 ? real_dx : 0);
11070 yy = jy + (dy == 0 ? real_dy : 0);
11072 return (!IN_LEV_FIELD(xx, yy) || IS_SOLID_FOR_PUSHING(Feld[xx][yy]));
11076 =============================================================================
11078 -----------------------------------------------------------------------------
11079 x, y: field next to player (non-diagonal) to try to dig to
11080 real_dx, real_dy: direction as read from input device (can be diagonal)
11081 =============================================================================
11084 int DigField(struct PlayerInfo *player,
11085 int oldx, int oldy, int x, int y,
11086 int real_dx, int real_dy, int mode)
11088 boolean is_player = (IS_PLAYER(oldx, oldy) || mode != DF_DIG);
11089 boolean player_was_pushing = player->is_pushing;
11090 boolean player_can_move = (!player->cannot_move && mode != DF_SNAP);
11091 boolean player_can_move_or_snap = (!player->cannot_move || mode == DF_SNAP);
11092 int jx = oldx, jy = oldy;
11093 int dx = x - jx, dy = y - jy;
11094 int nextx = x + dx, nexty = y + dy;
11095 int move_direction = (dx == -1 ? MV_LEFT :
11096 dx == +1 ? MV_RIGHT :
11098 dy == +1 ? MV_DOWN : MV_NONE);
11099 int opposite_direction = MV_DIR_OPPOSITE(move_direction);
11100 int dig_side = MV_DIR_OPPOSITE(move_direction);
11101 int old_element = Feld[jx][jy];
11102 #if USE_FIXED_DONT_RUN_INTO
11103 int element = MovingOrBlocked2ElementIfNotLeaving(x, y);
11109 if (is_player) /* function can also be called by EL_PENGUIN */
11111 if (player->MovPos == 0)
11113 player->is_digging = FALSE;
11114 player->is_collecting = FALSE;
11117 if (player->MovPos == 0) /* last pushing move finished */
11118 player->is_pushing = FALSE;
11120 if (mode == DF_NO_PUSH) /* player just stopped pushing */
11122 player->is_switching = FALSE;
11123 player->push_delay = -1;
11125 return MP_NO_ACTION;
11129 #if !USE_FIXED_DONT_RUN_INTO
11130 if (IS_MOVING(x, y) || IS_PLAYER(x, y))
11131 return MP_NO_ACTION;
11134 if (IS_TUBE(Back[jx][jy]) && game.engine_version >= VERSION_IDENT(2,2,0,0))
11135 old_element = Back[jx][jy];
11137 /* in case of element dropped at player position, check background */
11138 else if (Back[jx][jy] != EL_EMPTY &&
11139 game.engine_version >= VERSION_IDENT(2,2,0,0))
11140 old_element = Back[jx][jy];
11142 if (IS_WALKABLE(old_element) && !ACCESS_FROM(old_element, move_direction))
11143 return MP_NO_ACTION; /* field has no opening in this direction */
11145 if (IS_PASSABLE(old_element) && !ACCESS_FROM(old_element,opposite_direction))
11146 return MP_NO_ACTION; /* field has no opening in this direction */
11148 #if USE_FIXED_DONT_RUN_INTO
11149 if (player_can_move && element == EL_ACID && move_direction == MV_DOWN)
11153 Feld[jx][jy] = player->artwork_element;
11154 InitMovingField(jx, jy, MV_DOWN);
11155 Store[jx][jy] = EL_ACID;
11156 ContinueMoving(jx, jy);
11157 BuryPlayer(player);
11159 return MP_DONT_RUN_INTO;
11163 #if USE_FIXED_DONT_RUN_INTO
11164 if (player_can_move && DONT_RUN_INTO(element))
11166 TestIfPlayerRunsIntoBadThing(jx, jy, player->MovDir);
11168 return MP_DONT_RUN_INTO;
11172 #if USE_FIXED_DONT_RUN_INTO
11173 if (IS_MOVING(x, y) || IS_PLAYER(x, y))
11174 return MP_NO_ACTION;
11177 #if !USE_FIXED_DONT_RUN_INTO
11178 element = Feld[x][y];
11181 collect_count = element_info[element].collect_count_initial;
11183 if (!is_player && !IS_COLLECTIBLE(element)) /* penguin cannot collect it */
11184 return MP_NO_ACTION;
11186 if (game.engine_version < VERSION_IDENT(2,2,0,0))
11187 player_can_move = player_can_move_or_snap;
11189 if (mode == DF_SNAP && !IS_SNAPPABLE(element) &&
11190 game.engine_version >= VERSION_IDENT(2,2,0,0))
11192 CheckElementChangeByPlayer(x, y, element, CE_SNAPPED_BY_PLAYER,
11193 player->index_bit, dig_side);
11194 CheckTriggeredElementChangeByPlayer(x, y, element, CE_PLAYER_SNAPS_X,
11195 player->index_bit, dig_side);
11197 if (Feld[x][y] != element) /* field changed by snapping */
11200 return MP_NO_ACTION;
11203 #if USE_PLAYER_GRAVITY
11204 if (player->gravity && is_player && !player->is_auto_moving &&
11205 canFallDown(player) && move_direction != MV_DOWN &&
11206 !canMoveToValidFieldWithGravity(jx, jy, move_direction))
11207 return MP_NO_ACTION; /* player cannot walk here due to gravity */
11209 if (game.gravity && is_player && !player->is_auto_moving &&
11210 canFallDown(player) && move_direction != MV_DOWN &&
11211 !canMoveToValidFieldWithGravity(jx, jy, move_direction))
11212 return MP_NO_ACTION; /* player cannot walk here due to gravity */
11215 if (player_can_move &&
11216 IS_WALKABLE(element) && ACCESS_FROM(element, opposite_direction))
11218 int sound_element = SND_ELEMENT(element);
11219 int sound_action = ACTION_WALKING;
11221 if (IS_RND_GATE(element))
11223 if (!player->key[RND_GATE_NR(element)])
11224 return MP_NO_ACTION;
11226 else if (IS_RND_GATE_GRAY(element))
11228 if (!player->key[RND_GATE_GRAY_NR(element)])
11229 return MP_NO_ACTION;
11231 else if (IS_RND_GATE_GRAY_ACTIVE(element))
11233 if (!player->key[RND_GATE_GRAY_ACTIVE_NR(element)])
11234 return MP_NO_ACTION;
11236 else if (element == EL_EXIT_OPEN ||
11237 element == EL_SP_EXIT_OPEN ||
11238 element == EL_SP_EXIT_OPENING)
11240 sound_action = ACTION_PASSING; /* player is passing exit */
11242 else if (element == EL_EMPTY)
11244 sound_action = ACTION_MOVING; /* nothing to walk on */
11247 /* play sound from background or player, whatever is available */
11248 if (element_info[sound_element].sound[sound_action] != SND_UNDEFINED)
11249 PlayLevelSoundElementAction(x, y, sound_element, sound_action);
11251 PlayLevelSoundElementAction(x, y, player->artwork_element, sound_action);
11253 else if (player_can_move &&
11254 IS_PASSABLE(element) && canPassField(x, y, move_direction))
11256 if (!ACCESS_FROM(element, opposite_direction))
11257 return MP_NO_ACTION; /* field not accessible from this direction */
11259 if (CAN_MOVE(element)) /* only fixed elements can be passed! */
11260 return MP_NO_ACTION;
11262 if (IS_EM_GATE(element))
11264 if (!player->key[EM_GATE_NR(element)])
11265 return MP_NO_ACTION;
11267 else if (IS_EM_GATE_GRAY(element))
11269 if (!player->key[EM_GATE_GRAY_NR(element)])
11270 return MP_NO_ACTION;
11272 else if (IS_EM_GATE_GRAY_ACTIVE(element))
11274 if (!player->key[EM_GATE_GRAY_ACTIVE_NR(element)])
11275 return MP_NO_ACTION;
11277 else if (IS_EMC_GATE(element))
11279 if (!player->key[EMC_GATE_NR(element)])
11280 return MP_NO_ACTION;
11282 else if (IS_EMC_GATE_GRAY(element))
11284 if (!player->key[EMC_GATE_GRAY_NR(element)])
11285 return MP_NO_ACTION;
11287 else if (IS_EMC_GATE_GRAY_ACTIVE(element))
11289 if (!player->key[EMC_GATE_GRAY_ACTIVE_NR(element)])
11290 return MP_NO_ACTION;
11292 else if (IS_SP_PORT(element))
11294 if (element == EL_SP_GRAVITY_PORT_LEFT ||
11295 element == EL_SP_GRAVITY_PORT_RIGHT ||
11296 element == EL_SP_GRAVITY_PORT_UP ||
11297 element == EL_SP_GRAVITY_PORT_DOWN)
11298 #if USE_PLAYER_GRAVITY
11299 player->gravity = !player->gravity;
11301 game.gravity = !game.gravity;
11303 else if (element == EL_SP_GRAVITY_ON_PORT_LEFT ||
11304 element == EL_SP_GRAVITY_ON_PORT_RIGHT ||
11305 element == EL_SP_GRAVITY_ON_PORT_UP ||
11306 element == EL_SP_GRAVITY_ON_PORT_DOWN)
11307 #if USE_PLAYER_GRAVITY
11308 player->gravity = TRUE;
11310 game.gravity = TRUE;
11312 else if (element == EL_SP_GRAVITY_OFF_PORT_LEFT ||
11313 element == EL_SP_GRAVITY_OFF_PORT_RIGHT ||
11314 element == EL_SP_GRAVITY_OFF_PORT_UP ||
11315 element == EL_SP_GRAVITY_OFF_PORT_DOWN)
11316 #if USE_PLAYER_GRAVITY
11317 player->gravity = FALSE;
11319 game.gravity = FALSE;
11323 /* automatically move to the next field with double speed */
11324 player->programmed_action = move_direction;
11326 if (player->move_delay_reset_counter == 0)
11328 player->move_delay_reset_counter = 2; /* two double speed steps */
11330 DOUBLE_PLAYER_SPEED(player);
11333 PlayLevelSoundAction(x, y, ACTION_PASSING);
11335 else if (player_can_move_or_snap && IS_DIGGABLE(element))
11339 if (mode != DF_SNAP)
11341 GfxElement[x][y] = GFX_ELEMENT(element);
11342 player->is_digging = TRUE;
11345 PlayLevelSoundElementAction(x, y, element, ACTION_DIGGING);
11347 CheckTriggeredElementChangeByPlayer(x, y, element, CE_PLAYER_DIGS_X,
11348 player->index_bit, dig_side);
11350 if (mode == DF_SNAP)
11352 #if USE_NEW_SNAP_DELAY
11353 if (level.block_snap_field)
11354 setFieldForSnapping(x, y, element, move_direction);
11356 TestIfElementTouchesCustomElement(x, y); /* for empty space */
11358 TestIfElementTouchesCustomElement(x, y); /* for empty space */
11361 CheckTriggeredElementChangeByPlayer(x, y, element, CE_PLAYER_SNAPS_X,
11362 player->index_bit, dig_side);
11365 else if (player_can_move_or_snap && IS_COLLECTIBLE(element))
11369 if (is_player && mode != DF_SNAP)
11371 GfxElement[x][y] = element;
11372 player->is_collecting = TRUE;
11375 if (element == EL_SPEED_PILL)
11377 player->move_delay_value = MOVE_DELAY_HIGH_SPEED;
11379 else if (element == EL_EXTRA_TIME && level.time > 0)
11381 TimeLeft += level.extra_time;
11382 DrawGameValue_Time(TimeLeft);
11384 else if (element == EL_SHIELD_NORMAL || element == EL_SHIELD_DEADLY)
11386 player->shield_normal_time_left += level.shield_normal_time;
11387 if (element == EL_SHIELD_DEADLY)
11388 player->shield_deadly_time_left += level.shield_deadly_time;
11390 else if (element == EL_DYNAMITE ||
11391 element == EL_EM_DYNAMITE ||
11392 element == EL_SP_DISK_RED)
11394 if (player->inventory_size < MAX_INVENTORY_SIZE)
11395 player->inventory_element[player->inventory_size++] = element;
11397 DrawGameDoorValues();
11399 else if (element == EL_DYNABOMB_INCREASE_NUMBER)
11401 player->dynabomb_count++;
11402 player->dynabombs_left++;
11404 else if (element == EL_DYNABOMB_INCREASE_SIZE)
11406 player->dynabomb_size++;
11408 else if (element == EL_DYNABOMB_INCREASE_POWER)
11410 player->dynabomb_xl = TRUE;
11412 else if (IS_KEY(element))
11414 player->key[KEY_NR(element)] = TRUE;
11416 DrawGameDoorValues();
11418 else if (IS_ENVELOPE(element))
11420 player->show_envelope = element;
11422 else if (element == EL_EMC_LENSES)
11424 game.lenses_time_left = level.lenses_time * FRAMES_PER_SECOND;
11426 RedrawAllInvisibleElementsForLenses();
11428 else if (element == EL_EMC_MAGNIFIER)
11430 game.magnify_time_left = level.magnify_time * FRAMES_PER_SECOND;
11432 RedrawAllInvisibleElementsForMagnifier();
11434 else if (IS_DROPPABLE(element) ||
11435 IS_THROWABLE(element)) /* can be collected and dropped */
11439 if (collect_count == 0)
11440 player->inventory_infinite_element = element;
11442 for (i = 0; i < collect_count; i++)
11443 if (player->inventory_size < MAX_INVENTORY_SIZE)
11444 player->inventory_element[player->inventory_size++] = element;
11446 DrawGameDoorValues();
11448 else if (collect_count > 0)
11450 local_player->gems_still_needed -= collect_count;
11451 if (local_player->gems_still_needed < 0)
11452 local_player->gems_still_needed = 0;
11454 DrawGameValue_Emeralds(local_player->gems_still_needed);
11457 RaiseScoreElement(element);
11458 PlayLevelSoundElementAction(x, y, element, ACTION_COLLECTING);
11461 CheckTriggeredElementChangeByPlayer(x, y, element, CE_PLAYER_COLLECTS_X,
11462 player->index_bit, dig_side);
11464 if (mode == DF_SNAP)
11466 #if USE_NEW_SNAP_DELAY
11467 if (level.block_snap_field)
11468 setFieldForSnapping(x, y, element, move_direction);
11470 TestIfElementTouchesCustomElement(x, y); /* for empty space */
11472 TestIfElementTouchesCustomElement(x, y); /* for empty space */
11475 CheckTriggeredElementChangeByPlayer(x, y, element, CE_PLAYER_SNAPS_X,
11476 player->index_bit, dig_side);
11479 else if (player_can_move_or_snap && IS_PUSHABLE(element))
11481 if (mode == DF_SNAP && element != EL_BD_ROCK)
11482 return MP_NO_ACTION;
11484 if (CAN_FALL(element) && dy)
11485 return MP_NO_ACTION;
11487 if (CAN_FALL(element) && IN_LEV_FIELD(x, y + 1) && IS_FREE(x, y + 1) &&
11488 !(element == EL_SPRING && level.use_spring_bug))
11489 return MP_NO_ACTION;
11491 if (CAN_MOVE(element) && GET_MAX_MOVE_DELAY(element) == 0 &&
11492 ((move_direction & MV_VERTICAL &&
11493 ((element_info[element].move_pattern & MV_LEFT &&
11494 IN_LEV_FIELD(x - 1, y) && IS_FREE(x - 1, y)) ||
11495 (element_info[element].move_pattern & MV_RIGHT &&
11496 IN_LEV_FIELD(x + 1, y) && IS_FREE(x + 1, y)))) ||
11497 (move_direction & MV_HORIZONTAL &&
11498 ((element_info[element].move_pattern & MV_UP &&
11499 IN_LEV_FIELD(x, y - 1) && IS_FREE(x, y - 1)) ||
11500 (element_info[element].move_pattern & MV_DOWN &&
11501 IN_LEV_FIELD(x, y + 1) && IS_FREE(x, y + 1))))))
11502 return MP_NO_ACTION;
11504 /* do not push elements already moving away faster than player */
11505 if (CAN_MOVE(element) && MovDir[x][y] == move_direction &&
11506 ABS(getElementMoveStepsize(x, y)) > MOVE_STEPSIZE_NORMAL)
11507 return MP_NO_ACTION;
11509 if (game.engine_version >= VERSION_IDENT(3,1,0,0))
11511 if (player->push_delay_value == -1 || !player_was_pushing)
11512 player->push_delay_value = GET_NEW_PUSH_DELAY(element);
11514 else if (game.engine_version >= VERSION_IDENT(3,0,7,1))
11516 if (player->push_delay_value == -1)
11517 player->push_delay_value = GET_NEW_PUSH_DELAY(element);
11519 else if (game.engine_version >= VERSION_IDENT(2,2,0,7))
11521 if (!player->is_pushing)
11522 player->push_delay_value = GET_NEW_PUSH_DELAY(element);
11525 player->is_pushing = TRUE;
11526 player->is_active = TRUE;
11528 if (!(IN_LEV_FIELD(nextx, nexty) &&
11529 (IS_FREE(nextx, nexty) ||
11530 (Feld[nextx][nexty] == EL_SOKOBAN_FIELD_EMPTY &&
11531 IS_SB_ELEMENT(element)))))
11532 return MP_NO_ACTION;
11534 if (!checkDiagonalPushing(player, x, y, real_dx, real_dy))
11535 return MP_NO_ACTION;
11537 if (player->push_delay == -1) /* new pushing; restart delay */
11538 player->push_delay = 0;
11540 if (player->push_delay < player->push_delay_value &&
11541 !(tape.playing && tape.file_version < FILE_VERSION_2_0) &&
11542 element != EL_SPRING && element != EL_BALLOON)
11544 /* make sure that there is no move delay before next try to push */
11545 if (game.engine_version >= VERSION_IDENT(3,0,7,1))
11546 player->move_delay = 0;
11548 return MP_NO_ACTION;
11551 if (IS_SB_ELEMENT(element))
11553 if (element == EL_SOKOBAN_FIELD_FULL)
11555 Back[x][y] = EL_SOKOBAN_FIELD_EMPTY;
11556 local_player->sokobanfields_still_needed++;
11559 if (Feld[nextx][nexty] == EL_SOKOBAN_FIELD_EMPTY)
11561 Back[nextx][nexty] = EL_SOKOBAN_FIELD_EMPTY;
11562 local_player->sokobanfields_still_needed--;
11565 Feld[x][y] = EL_SOKOBAN_OBJECT;
11567 if (Back[x][y] == Back[nextx][nexty])
11568 PlayLevelSoundAction(x, y, ACTION_PUSHING);
11569 else if (Back[x][y] != 0)
11570 PlayLevelSoundElementAction(x, y, EL_SOKOBAN_FIELD_FULL,
11573 PlayLevelSoundElementAction(nextx, nexty, EL_SOKOBAN_FIELD_EMPTY,
11576 if (local_player->sokobanfields_still_needed == 0 &&
11577 game.emulation == EMU_SOKOBAN)
11579 PlayerWins(player);
11581 PlayLevelSound(x, y, SND_GAME_SOKOBAN_SOLVING);
11585 PlayLevelSoundElementAction(x, y, element, ACTION_PUSHING);
11587 InitMovingField(x, y, move_direction);
11588 GfxAction[x][y] = ACTION_PUSHING;
11590 if (mode == DF_SNAP)
11591 ContinueMoving(x, y);
11593 MovPos[x][y] = (dx != 0 ? dx : dy);
11595 Pushed[x][y] = TRUE;
11596 Pushed[nextx][nexty] = TRUE;
11598 if (game.engine_version < VERSION_IDENT(2,2,0,7))
11599 player->push_delay_value = GET_NEW_PUSH_DELAY(element);
11601 player->push_delay_value = -1; /* get new value later */
11603 /* check for element change _after_ element has been pushed */
11604 if (game.use_change_when_pushing_bug)
11606 CheckElementChangeByPlayer(x, y, element, CE_PUSHED_BY_PLAYER,
11607 player->index_bit, dig_side);
11608 CheckTriggeredElementChangeByPlayer(x, y, element, CE_PLAYER_PUSHES_X,
11609 player->index_bit, dig_side);
11612 else if (IS_SWITCHABLE(element))
11614 if (PLAYER_SWITCHING(player, x, y))
11616 CheckTriggeredElementChangeByPlayer(x, y, element, CE_PLAYER_PRESSES_X,
11617 player->index_bit, dig_side);
11622 player->is_switching = TRUE;
11623 player->switch_x = x;
11624 player->switch_y = y;
11626 PlayLevelSoundElementAction(x, y, element, ACTION_ACTIVATING);
11628 if (element == EL_ROBOT_WHEEL)
11630 Feld[x][y] = EL_ROBOT_WHEEL_ACTIVE;
11634 DrawLevelField(x, y);
11636 else if (element == EL_SP_TERMINAL)
11640 SCAN_PLAYFIELD(xx, yy)
11642 if (Feld[xx][yy] == EL_SP_DISK_YELLOW)
11644 else if (Feld[xx][yy] == EL_SP_TERMINAL)
11645 Feld[xx][yy] = EL_SP_TERMINAL_ACTIVE;
11648 else if (IS_BELT_SWITCH(element))
11650 ToggleBeltSwitch(x, y);
11652 else if (element == EL_SWITCHGATE_SWITCH_UP ||
11653 element == EL_SWITCHGATE_SWITCH_DOWN)
11655 ToggleSwitchgateSwitch(x, y);
11657 else if (element == EL_LIGHT_SWITCH ||
11658 element == EL_LIGHT_SWITCH_ACTIVE)
11660 ToggleLightSwitch(x, y);
11662 else if (element == EL_TIMEGATE_SWITCH)
11664 ActivateTimegateSwitch(x, y);
11666 else if (element == EL_BALLOON_SWITCH_LEFT ||
11667 element == EL_BALLOON_SWITCH_RIGHT ||
11668 element == EL_BALLOON_SWITCH_UP ||
11669 element == EL_BALLOON_SWITCH_DOWN ||
11670 element == EL_BALLOON_SWITCH_NONE ||
11671 element == EL_BALLOON_SWITCH_ANY)
11673 game.wind_direction = (element == EL_BALLOON_SWITCH_LEFT ? MV_LEFT :
11674 element == EL_BALLOON_SWITCH_RIGHT ? MV_RIGHT :
11675 element == EL_BALLOON_SWITCH_UP ? MV_UP :
11676 element == EL_BALLOON_SWITCH_DOWN ? MV_DOWN :
11677 element == EL_BALLOON_SWITCH_NONE ? MV_NONE :
11680 else if (element == EL_LAMP)
11682 Feld[x][y] = EL_LAMP_ACTIVE;
11683 local_player->lights_still_needed--;
11685 ResetGfxAnimation(x, y);
11686 DrawLevelField(x, y);
11688 else if (element == EL_TIME_ORB_FULL)
11690 Feld[x][y] = EL_TIME_ORB_EMPTY;
11692 if (level.time > 0 || level.use_time_orb_bug)
11694 TimeLeft += level.time_orb_time;
11695 DrawGameValue_Time(TimeLeft);
11698 ResetGfxAnimation(x, y);
11699 DrawLevelField(x, y);
11701 else if (element == EL_EMC_MAGIC_BALL_SWITCH ||
11702 element == EL_EMC_MAGIC_BALL_SWITCH_ACTIVE)
11706 game.ball_state = !game.ball_state;
11708 SCAN_PLAYFIELD(xx, yy)
11710 int e = Feld[xx][yy];
11712 if (game.ball_state)
11714 if (e == EL_EMC_MAGIC_BALL)
11715 CreateField(xx, yy, EL_EMC_MAGIC_BALL_ACTIVE);
11716 else if (e == EL_EMC_MAGIC_BALL_SWITCH)
11717 CreateField(xx, yy, EL_EMC_MAGIC_BALL_SWITCH_ACTIVE);
11721 if (e == EL_EMC_MAGIC_BALL_ACTIVE)
11722 CreateField(xx, yy, EL_EMC_MAGIC_BALL);
11723 else if (e == EL_EMC_MAGIC_BALL_SWITCH_ACTIVE)
11724 CreateField(xx, yy, EL_EMC_MAGIC_BALL_SWITCH);
11729 CheckTriggeredElementChangeByPlayer(x, y, element, CE_SWITCH_OF_X,
11730 player->index_bit, dig_side);
11732 CheckTriggeredElementChangeByPlayer(x, y, element, CE_PLAYER_SWITCHES_X,
11733 player->index_bit, dig_side);
11735 CheckTriggeredElementChangeByPlayer(x, y, element, CE_PLAYER_PRESSES_X,
11736 player->index_bit, dig_side);
11742 if (!PLAYER_SWITCHING(player, x, y))
11744 player->is_switching = TRUE;
11745 player->switch_x = x;
11746 player->switch_y = y;
11748 CheckElementChangeByPlayer(x, y, element, CE_SWITCHED,
11749 player->index_bit, dig_side);
11750 CheckTriggeredElementChangeByPlayer(x, y, element, CE_SWITCH_OF_X,
11751 player->index_bit, dig_side);
11753 CheckElementChangeByPlayer(x, y, element, CE_SWITCHED_BY_PLAYER,
11754 player->index_bit, dig_side);
11755 CheckTriggeredElementChangeByPlayer(x, y, element, CE_PLAYER_SWITCHES_X,
11756 player->index_bit, dig_side);
11759 CheckElementChangeByPlayer(x, y, element, CE_PRESSED_BY_PLAYER,
11760 player->index_bit, dig_side);
11761 CheckTriggeredElementChangeByPlayer(x, y, element, CE_PLAYER_PRESSES_X,
11762 player->index_bit, dig_side);
11764 return MP_NO_ACTION;
11767 player->push_delay = -1;
11769 if (is_player) /* function can also be called by EL_PENGUIN */
11771 if (Feld[x][y] != element) /* really digged/collected something */
11773 player->is_collecting = !player->is_digging;
11774 player->is_active = TRUE;
11781 boolean SnapField(struct PlayerInfo *player, int dx, int dy)
11783 int jx = player->jx, jy = player->jy;
11784 int x = jx + dx, y = jy + dy;
11785 int snap_direction = (dx == -1 ? MV_LEFT :
11786 dx == +1 ? MV_RIGHT :
11788 dy == +1 ? MV_DOWN : MV_NONE);
11789 boolean can_continue_snapping = (level.continuous_snapping &&
11790 WasJustFalling[x][y] < CHECK_DELAY_FALLING);
11792 if (player->MovPos != 0 && game.engine_version >= VERSION_IDENT(2,2,0,0))
11795 if (!player->active || !IN_LEV_FIELD(x, y))
11803 if (player->MovPos == 0)
11804 player->is_pushing = FALSE;
11806 player->is_snapping = FALSE;
11808 if (player->MovPos == 0)
11810 player->is_moving = FALSE;
11811 player->is_digging = FALSE;
11812 player->is_collecting = FALSE;
11818 #if USE_NEW_CONTINUOUS_SNAPPING
11819 /* prevent snapping with already pressed snap key when not allowed */
11820 if (player->is_snapping && !can_continue_snapping)
11823 if (player->is_snapping)
11827 player->MovDir = snap_direction;
11829 if (player->MovPos == 0)
11831 player->is_moving = FALSE;
11832 player->is_digging = FALSE;
11833 player->is_collecting = FALSE;
11836 player->is_dropping = FALSE;
11837 player->is_dropping_pressed = FALSE;
11838 player->drop_pressed_delay = 0;
11840 if (DigField(player, jx, jy, x, y, 0, 0, DF_SNAP) == MP_NO_ACTION)
11843 player->is_snapping = TRUE;
11844 player->is_active = TRUE;
11846 if (player->MovPos == 0)
11848 player->is_moving = FALSE;
11849 player->is_digging = FALSE;
11850 player->is_collecting = FALSE;
11853 if (player->MovPos != 0) /* prevent graphic bugs in versions < 2.2.0 */
11854 DrawLevelField(player->last_jx, player->last_jy);
11856 DrawLevelField(x, y);
11861 boolean DropElement(struct PlayerInfo *player)
11863 int old_element, new_element;
11864 int dropx = player->jx, dropy = player->jy;
11865 int drop_direction = player->MovDir;
11866 int drop_side = drop_direction;
11867 int drop_element = (player->inventory_size > 0 ?
11868 player->inventory_element[player->inventory_size - 1] :
11869 player->inventory_infinite_element != EL_UNDEFINED ?
11870 player->inventory_infinite_element :
11871 player->dynabombs_left > 0 ?
11872 EL_DYNABOMB_PLAYER_1_ACTIVE + player->index_nr :
11875 player->is_dropping_pressed = TRUE;
11877 /* do not drop an element on top of another element; when holding drop key
11878 pressed without moving, dropped element must move away before the next
11879 element can be dropped (this is especially important if the next element
11880 is dynamite, which can be placed on background for historical reasons) */
11881 if (PLAYER_DROPPING(player, dropx, dropy) && Feld[dropx][dropy] != EL_EMPTY)
11884 if (IS_THROWABLE(drop_element))
11886 dropx += GET_DX_FROM_DIR(drop_direction);
11887 dropy += GET_DY_FROM_DIR(drop_direction);
11889 if (!IN_LEV_FIELD(dropx, dropy))
11893 old_element = Feld[dropx][dropy]; /* old element at dropping position */
11894 new_element = drop_element; /* default: no change when dropping */
11896 /* check if player is active, not moving and ready to drop */
11897 if (!player->active || player->MovPos || player->drop_delay > 0)
11900 /* check if player has anything that can be dropped */
11901 if (new_element == EL_UNDEFINED)
11904 /* check if drop key was pressed long enough for EM style dynamite */
11905 if (new_element == EL_EM_DYNAMITE && player->drop_pressed_delay < 40)
11908 /* check if anything can be dropped at the current position */
11909 if (IS_ACTIVE_BOMB(old_element) || old_element == EL_EXPLOSION)
11912 /* collected custom elements can only be dropped on empty fields */
11913 if (IS_CUSTOM_ELEMENT(new_element) && old_element != EL_EMPTY)
11916 if (old_element != EL_EMPTY)
11917 Back[dropx][dropy] = old_element; /* store old element on this field */
11919 ResetGfxAnimation(dropx, dropy);
11920 ResetRandomAnimationValue(dropx, dropy);
11922 if (player->inventory_size > 0 ||
11923 player->inventory_infinite_element != EL_UNDEFINED)
11925 if (player->inventory_size > 0)
11927 player->inventory_size--;
11929 DrawGameDoorValues();
11931 if (new_element == EL_DYNAMITE)
11932 new_element = EL_DYNAMITE_ACTIVE;
11933 else if (new_element == EL_EM_DYNAMITE)
11934 new_element = EL_EM_DYNAMITE_ACTIVE;
11935 else if (new_element == EL_SP_DISK_RED)
11936 new_element = EL_SP_DISK_RED_ACTIVE;
11939 Feld[dropx][dropy] = new_element;
11941 if (IN_SCR_FIELD(SCREENX(dropx), SCREENY(dropy)))
11942 DrawGraphicThruMask(SCREENX(dropx), SCREENY(dropy),
11943 el2img(Feld[dropx][dropy]), 0);
11945 PlayLevelSoundAction(dropx, dropy, ACTION_DROPPING);
11947 /* needed if previous element just changed to "empty" in the last frame */
11948 ChangeCount[dropx][dropy] = 0; /* allow at least one more change */
11950 CheckElementChangeByPlayer(dropx, dropy, new_element, CE_DROPPED_BY_PLAYER,
11951 player->index_bit, drop_side);
11952 CheckTriggeredElementChangeByPlayer(dropx, dropy, new_element,
11954 player->index_bit, drop_side);
11956 TestIfElementTouchesCustomElement(dropx, dropy);
11958 else /* player is dropping a dyna bomb */
11960 player->dynabombs_left--;
11962 Feld[dropx][dropy] = new_element;
11964 if (IN_SCR_FIELD(SCREENX(dropx), SCREENY(dropy)))
11965 DrawGraphicThruMask(SCREENX(dropx), SCREENY(dropy),
11966 el2img(Feld[dropx][dropy]), 0);
11968 PlayLevelSoundAction(dropx, dropy, ACTION_DROPPING);
11971 if (Feld[dropx][dropy] == new_element) /* uninitialized unless CE change */
11972 InitField_WithBug1(dropx, dropy, FALSE);
11974 new_element = Feld[dropx][dropy]; /* element might have changed */
11976 if (IS_CUSTOM_ELEMENT(new_element) && CAN_MOVE(new_element) &&
11977 element_info[new_element].move_pattern == MV_WHEN_DROPPED)
11979 int move_direction, nextx, nexty;
11981 if (element_info[new_element].move_direction_initial == MV_START_AUTOMATIC)
11982 MovDir[dropx][dropy] = drop_direction;
11984 move_direction = MovDir[dropx][dropy];
11985 nextx = dropx + GET_DX_FROM_DIR(move_direction);
11986 nexty = dropy + GET_DY_FROM_DIR(move_direction);
11988 ChangeCount[dropx][dropy] = 0; /* allow at least one more change */
11989 CheckCollision[dropx][dropy] = CHECK_DELAY_COLLISION;
11992 player->drop_delay = GET_NEW_DROP_DELAY(drop_element);
11993 player->is_dropping = TRUE;
11995 player->drop_pressed_delay = 0;
11996 player->is_dropping_pressed = FALSE;
11998 player->drop_x = dropx;
11999 player->drop_y = dropy;
12004 /* ------------------------------------------------------------------------- */
12005 /* game sound playing functions */
12006 /* ------------------------------------------------------------------------- */
12008 static int *loop_sound_frame = NULL;
12009 static int *loop_sound_volume = NULL;
12011 void InitPlayLevelSound()
12013 int num_sounds = getSoundListSize();
12015 checked_free(loop_sound_frame);
12016 checked_free(loop_sound_volume);
12018 loop_sound_frame = checked_calloc(num_sounds * sizeof(int));
12019 loop_sound_volume = checked_calloc(num_sounds * sizeof(int));
12022 static void PlayLevelSound(int x, int y, int nr)
12024 int sx = SCREENX(x), sy = SCREENY(y);
12025 int volume, stereo_position;
12026 int max_distance = 8;
12027 int type = (IS_LOOP_SOUND(nr) ? SND_CTRL_PLAY_LOOP : SND_CTRL_PLAY_SOUND);
12029 if ((!setup.sound_simple && !IS_LOOP_SOUND(nr)) ||
12030 (!setup.sound_loops && IS_LOOP_SOUND(nr)))
12033 if (!IN_LEV_FIELD(x, y) ||
12034 sx < -max_distance || sx >= SCR_FIELDX + max_distance ||
12035 sy < -max_distance || sy >= SCR_FIELDY + max_distance)
12038 volume = SOUND_MAX_VOLUME;
12040 if (!IN_SCR_FIELD(sx, sy))
12042 int dx = ABS(sx - SCR_FIELDX / 2) - SCR_FIELDX / 2;
12043 int dy = ABS(sy - SCR_FIELDY / 2) - SCR_FIELDY / 2;
12045 volume -= volume * (dx > dy ? dx : dy) / max_distance;
12048 stereo_position = (SOUND_MAX_LEFT +
12049 (sx + max_distance) * SOUND_MAX_LEFT2RIGHT /
12050 (SCR_FIELDX + 2 * max_distance));
12052 if (IS_LOOP_SOUND(nr))
12054 /* This assures that quieter loop sounds do not overwrite louder ones,
12055 while restarting sound volume comparison with each new game frame. */
12057 if (loop_sound_volume[nr] > volume && loop_sound_frame[nr] == FrameCounter)
12060 loop_sound_volume[nr] = volume;
12061 loop_sound_frame[nr] = FrameCounter;
12064 PlaySoundExt(nr, volume, stereo_position, type);
12067 static void PlayLevelSoundNearest(int x, int y, int sound_action)
12069 PlayLevelSound(x < LEVELX(BX1) ? LEVELX(BX1) :
12070 x > LEVELX(BX2) ? LEVELX(BX2) : x,
12071 y < LEVELY(BY1) ? LEVELY(BY1) :
12072 y > LEVELY(BY2) ? LEVELY(BY2) : y,
12076 static void PlayLevelSoundAction(int x, int y, int action)
12078 PlayLevelSoundElementAction(x, y, Feld[x][y], action);
12081 static void PlayLevelSoundElementAction(int x, int y, int element, int action)
12083 int sound_effect = element_info[SND_ELEMENT(element)].sound[action];
12085 if (sound_effect != SND_UNDEFINED)
12086 PlayLevelSound(x, y, sound_effect);
12089 static void PlayLevelSoundElementActionIfLoop(int x, int y, int element,
12092 int sound_effect = element_info[SND_ELEMENT(element)].sound[action];
12094 if (sound_effect != SND_UNDEFINED && IS_LOOP_SOUND(sound_effect))
12095 PlayLevelSound(x, y, sound_effect);
12098 static void PlayLevelSoundActionIfLoop(int x, int y, int action)
12100 int sound_effect = element_info[SND_ELEMENT(Feld[x][y])].sound[action];
12102 if (sound_effect != SND_UNDEFINED && IS_LOOP_SOUND(sound_effect))
12103 PlayLevelSound(x, y, sound_effect);
12106 static void StopLevelSoundActionIfLoop(int x, int y, int action)
12108 int sound_effect = element_info[SND_ELEMENT(Feld[x][y])].sound[action];
12110 if (sound_effect != SND_UNDEFINED && IS_LOOP_SOUND(sound_effect))
12111 StopSound(sound_effect);
12114 static void PlayLevelMusic()
12116 if (levelset.music[level_nr] != MUS_UNDEFINED)
12117 PlayMusic(levelset.music[level_nr]); /* from config file */
12119 PlayMusic(MAP_NOCONF_MUSIC(level_nr)); /* from music dir */
12122 void PlayLevelSound_EM(int xx, int yy, int element_em, int sample)
12124 int element = (element_em > -1 ? map_element_EM_to_RND(element_em) : 0);
12125 int offset = (BorderElement == EL_STEELWALL ? 1 : 0);
12126 int x = xx - 1 - offset;
12127 int y = yy - 1 - offset;
12132 PlayLevelSoundElementAction(x, y, element, ACTION_WALKING);
12136 PlayLevelSoundElementAction(x, y, element, ACTION_PUSHING);
12140 PlayLevelSoundElementAction(x, y, element, ACTION_IMPACT);
12144 PlayLevelSoundElementAction(x, y, element, ACTION_IMPACT);
12148 PlayLevelSoundElementAction(x, y, element, ACTION_BREAKING);
12152 PlayLevelSoundElementAction(x, y, element, ACTION_MOVING);
12156 PlayLevelSoundElementAction(x, y, element, ACTION_MOVING);
12159 case SAMPLE_android_clone:
12160 PlayLevelSoundElementAction(x, y, element, ACTION_DROPPING);
12163 case SAMPLE_android_move:
12164 PlayLevelSoundElementAction(x, y, element, ACTION_MOVING);
12167 case SAMPLE_spring:
12168 PlayLevelSoundElementAction(x, y, element, ACTION_IMPACT);
12172 PlayLevelSoundElementAction(x, y, element, ACTION_EATING);
12176 PlayLevelSoundElementAction(x, y, element, ACTION_WAITING);
12179 case SAMPLE_eater_eat:
12180 PlayLevelSoundElementAction(x, y, element, ACTION_DIGGING);
12184 PlayLevelSoundElementAction(x, y, element, ACTION_MOVING);
12187 case SAMPLE_collect:
12188 PlayLevelSoundElementAction(x, y, element, ACTION_COLLECTING);
12191 case SAMPLE_diamond:
12192 PlayLevelSoundElementAction(x, y, element, ACTION_IMPACT);
12195 case SAMPLE_squash:
12196 /* !!! CHECK THIS !!! */
12198 PlayLevelSoundElementAction(x, y, element, ACTION_BREAKING);
12200 PlayLevelSoundElementAction(x, y, element, ACTION_SMASHED_BY_ROCK);
12204 case SAMPLE_wonderfall:
12205 PlayLevelSoundElementAction(x, y, element, ACTION_FILLING);
12209 PlayLevelSoundElementAction(x, y, element, ACTION_IMPACT);
12213 PlayLevelSoundElementAction(x, y, element, ACTION_PUSHING);
12217 PlayLevelSoundElementAction(x, y, element, ACTION_DIGGING);
12221 PlayLevelSoundElementAction(x, y, element, ACTION_SPLASHING);
12225 PlayLevelSoundElementAction(x, y, element, ACTION_DROPPING);
12229 PlayLevelSoundElementAction(x, y, element, ACTION_GROWING);
12232 case SAMPLE_wonder:
12233 PlayLevelSoundElementAction(x, y, element, ACTION_ACTIVE);
12237 PlayLevelSoundElementAction(x, y, element, ACTION_PASSING);
12240 case SAMPLE_exit_open:
12241 PlayLevelSoundElementAction(x, y, element, ACTION_OPENING);
12244 case SAMPLE_exit_leave:
12245 PlayLevelSoundElementAction(x, y, element, ACTION_PASSING);
12248 case SAMPLE_dynamite:
12249 PlayLevelSoundElementAction(x, y, element, ACTION_DROPPING);
12253 PlayLevelSoundElementAction(x, y, element, ACTION_ACTIVE);
12257 PlayLevelSoundElementAction(x, y, element, ACTION_ACTIVATING);
12261 PlayLevelSoundElementAction(x, y, element, ACTION_ACTIVE);
12265 PlayLevelSoundElementAction(x, y, element, ACTION_EXPLODING);
12269 PlayLevelSoundElementAction(x, y, element, ACTION_DYING);
12273 PlaySound(SND_GAME_RUNNING_OUT_OF_TIME);
12277 PlayLevelSoundElementAction(x, y, element, ACTION_DEFAULT);
12283 void ChangeTime(int value)
12285 int *time = (level.time == 0 ? &TimePlayed : &TimeLeft);
12289 /* EMC game engine uses value from time counter of RND game engine */
12290 level.native_em_level->lev->time = *time;
12292 DrawGameValue_Time(*time);
12295 void RaiseScore(int value)
12297 /* EMC game engine and RND game engine have separate score counters */
12298 int *score = (level.game_engine_type == GAME_ENGINE_TYPE_EM ?
12299 &level.native_em_level->lev->score : &local_player->score);
12303 DrawGameValue_Score(*score);
12307 void RaiseScore(int value)
12309 local_player->score += value;
12311 DrawGameValue_Score(local_player->score);
12314 void RaiseScoreElement(int element)
12319 case EL_BD_DIAMOND:
12320 case EL_EMERALD_YELLOW:
12321 case EL_EMERALD_RED:
12322 case EL_EMERALD_PURPLE:
12323 case EL_SP_INFOTRON:
12324 RaiseScore(level.score[SC_EMERALD]);
12327 RaiseScore(level.score[SC_DIAMOND]);
12330 RaiseScore(level.score[SC_CRYSTAL]);
12333 RaiseScore(level.score[SC_PEARL]);
12336 case EL_BD_BUTTERFLY:
12337 case EL_SP_ELECTRON:
12338 RaiseScore(level.score[SC_BUG]);
12341 case EL_BD_FIREFLY:
12342 case EL_SP_SNIKSNAK:
12343 RaiseScore(level.score[SC_SPACESHIP]);
12346 case EL_DARK_YAMYAM:
12347 RaiseScore(level.score[SC_YAMYAM]);
12350 RaiseScore(level.score[SC_ROBOT]);
12353 RaiseScore(level.score[SC_PACMAN]);
12356 RaiseScore(level.score[SC_NUT]);
12359 case EL_EM_DYNAMITE:
12360 case EL_SP_DISK_RED:
12361 case EL_DYNABOMB_INCREASE_NUMBER:
12362 case EL_DYNABOMB_INCREASE_SIZE:
12363 case EL_DYNABOMB_INCREASE_POWER:
12364 RaiseScore(level.score[SC_DYNAMITE]);
12366 case EL_SHIELD_NORMAL:
12367 case EL_SHIELD_DEADLY:
12368 RaiseScore(level.score[SC_SHIELD]);
12370 case EL_EXTRA_TIME:
12371 RaiseScore(level.extra_time_score);
12385 RaiseScore(level.score[SC_KEY]);
12388 RaiseScore(element_info[element].collect_score);
12393 void RequestQuitGame(boolean ask_if_really_quit)
12395 if (AllPlayersGone ||
12396 !ask_if_really_quit ||
12397 level_editor_test_game ||
12398 Request("Do you really want to quit the game ?",
12399 REQ_ASK | REQ_STAY_CLOSED))
12401 #if defined(NETWORK_AVALIABLE)
12402 if (options.network)
12403 SendToServer_StopPlaying(NETWORK_STOP_BY_PLAYER);
12407 if (!ask_if_really_quit || level_editor_test_game)
12409 game_status = GAME_MODE_MAIN;
12415 FadeOut(REDRAW_FIELD);
12417 game_status = GAME_MODE_MAIN;
12419 DrawAndFadeInMainMenu(REDRAW_FIELD);
12425 if (tape.playing && tape.deactivate_display)
12426 TapeDeactivateDisplayOff(TRUE);
12428 OpenDoor(DOOR_OPEN_1 | DOOR_COPY_BACK);
12430 if (tape.playing && tape.deactivate_display)
12431 TapeDeactivateDisplayOn();
12436 /* ------------------------------------------------------------------------- */
12437 /* random generator functions */
12438 /* ------------------------------------------------------------------------- */
12440 unsigned int InitEngineRandom_RND(long seed)
12442 game.num_random_calls = 0;
12445 unsigned int rnd_seed = InitEngineRandom(seed);
12447 printf("::: START RND: %d\n", rnd_seed);
12452 return InitEngineRandom(seed);
12458 unsigned int RND(int max)
12462 game.num_random_calls++;
12464 return GetEngineRandom(max);
12471 /* ------------------------------------------------------------------------- */
12472 /* game engine snapshot handling functions */
12473 /* ------------------------------------------------------------------------- */
12475 #define ARGS_ADDRESS_AND_SIZEOF(x) (&(x)), (sizeof(x))
12477 struct EngineSnapshotInfo
12479 /* runtime values for custom element collect score */
12480 int collect_score[NUM_CUSTOM_ELEMENTS];
12482 /* runtime values for group element choice position */
12483 int choice_pos[NUM_GROUP_ELEMENTS];
12485 /* runtime values for belt position animations */
12486 int belt_graphic[4 * NUM_BELT_PARTS];
12487 int belt_anim_mode[4 * NUM_BELT_PARTS];
12490 struct EngineSnapshotNodeInfo
12497 static struct EngineSnapshotInfo engine_snapshot_rnd;
12498 static ListNode *engine_snapshot_list = NULL;
12499 static char *snapshot_level_identifier = NULL;
12500 static int snapshot_level_nr = -1;
12502 void FreeEngineSnapshot()
12504 while (engine_snapshot_list != NULL)
12505 deleteNodeFromList(&engine_snapshot_list, engine_snapshot_list->key,
12508 setString(&snapshot_level_identifier, NULL);
12509 snapshot_level_nr = -1;
12512 static void SaveEngineSnapshotValues_RND()
12514 static int belt_base_active_element[4] =
12516 EL_CONVEYOR_BELT_1_LEFT_ACTIVE,
12517 EL_CONVEYOR_BELT_2_LEFT_ACTIVE,
12518 EL_CONVEYOR_BELT_3_LEFT_ACTIVE,
12519 EL_CONVEYOR_BELT_4_LEFT_ACTIVE
12523 for (i = 0; i < NUM_CUSTOM_ELEMENTS; i++)
12525 int element = EL_CUSTOM_START + i;
12527 engine_snapshot_rnd.collect_score[i] = element_info[element].collect_score;
12530 for (i = 0; i < NUM_GROUP_ELEMENTS; i++)
12532 int element = EL_GROUP_START + i;
12534 engine_snapshot_rnd.choice_pos[i] = element_info[element].group->choice_pos;
12537 for (i = 0; i < 4; i++)
12539 for (j = 0; j < NUM_BELT_PARTS; j++)
12541 int element = belt_base_active_element[i] + j;
12542 int graphic = el2img(element);
12543 int anim_mode = graphic_info[graphic].anim_mode;
12545 engine_snapshot_rnd.belt_graphic[i * 4 + j] = graphic;
12546 engine_snapshot_rnd.belt_anim_mode[i * 4 + j] = anim_mode;
12551 printf("::: SAVE: %d RNDs\n", game.num_random_calls);
12555 static void LoadEngineSnapshotValues_RND()
12557 unsigned long num_random_calls = game.num_random_calls;
12560 for (i = 0; i < NUM_CUSTOM_ELEMENTS; i++)
12562 int element = EL_CUSTOM_START + i;
12564 element_info[element].collect_score = engine_snapshot_rnd.collect_score[i];
12567 for (i = 0; i < NUM_GROUP_ELEMENTS; i++)
12569 int element = EL_GROUP_START + i;
12571 element_info[element].group->choice_pos = engine_snapshot_rnd.choice_pos[i];
12574 for (i = 0; i < 4; i++)
12576 for (j = 0; j < NUM_BELT_PARTS; j++)
12578 int graphic = engine_snapshot_rnd.belt_graphic[i * 4 + j];
12579 int anim_mode = engine_snapshot_rnd.belt_anim_mode[i * 4 + j];
12581 graphic_info[graphic].anim_mode = anim_mode;
12586 printf("::: LOADING ... : %d RNDs\n", num_random_calls);
12589 if (level.game_engine_type == GAME_ENGINE_TYPE_RND)
12591 InitRND(tape.random_seed);
12592 for (i = 0; i < num_random_calls; i++)
12596 if (game.num_random_calls != num_random_calls)
12598 Error(ERR_RETURN, "number of random calls out of sync");
12599 Error(ERR_RETURN, "number of random calls should be %d", num_random_calls);
12600 Error(ERR_RETURN, "number of random calls is %d", game.num_random_calls);
12601 Error(ERR_EXIT, "this should not happen -- please debug");
12605 printf("::: LOADED: %d RNDs\n", num_random_calls);
12609 static void SaveEngineSnapshotBuffer(void *buffer, int size)
12611 struct EngineSnapshotNodeInfo *bi =
12612 checked_calloc(sizeof(struct EngineSnapshotNodeInfo));
12614 bi->buffer_orig = buffer;
12615 bi->buffer_copy = checked_malloc(size);
12618 memcpy(bi->buffer_copy, buffer, size);
12620 addNodeToList(&engine_snapshot_list, NULL, bi);
12623 void SaveEngineSnapshot()
12625 FreeEngineSnapshot(); /* free previous snapshot, if needed */
12627 /* copy some special values to a structure better suited for the snapshot */
12629 SaveEngineSnapshotValues_RND();
12630 SaveEngineSnapshotValues_EM();
12632 /* save values stored in special snapshot structure */
12634 SaveEngineSnapshotBuffer(ARGS_ADDRESS_AND_SIZEOF(engine_snapshot_rnd));
12635 SaveEngineSnapshotBuffer(ARGS_ADDRESS_AND_SIZEOF(engine_snapshot_em));
12637 /* save further RND engine values */
12639 SaveEngineSnapshotBuffer(ARGS_ADDRESS_AND_SIZEOF(stored_player));
12640 SaveEngineSnapshotBuffer(ARGS_ADDRESS_AND_SIZEOF(game));
12641 SaveEngineSnapshotBuffer(ARGS_ADDRESS_AND_SIZEOF(tape));
12643 SaveEngineSnapshotBuffer(ARGS_ADDRESS_AND_SIZEOF(ZX));
12644 SaveEngineSnapshotBuffer(ARGS_ADDRESS_AND_SIZEOF(ZY));
12645 SaveEngineSnapshotBuffer(ARGS_ADDRESS_AND_SIZEOF(ExitX));
12646 SaveEngineSnapshotBuffer(ARGS_ADDRESS_AND_SIZEOF(ExitY));
12648 SaveEngineSnapshotBuffer(ARGS_ADDRESS_AND_SIZEOF(FrameCounter));
12649 SaveEngineSnapshotBuffer(ARGS_ADDRESS_AND_SIZEOF(TimeFrames));
12650 SaveEngineSnapshotBuffer(ARGS_ADDRESS_AND_SIZEOF(TimePlayed));
12651 SaveEngineSnapshotBuffer(ARGS_ADDRESS_AND_SIZEOF(TimeLeft));
12652 SaveEngineSnapshotBuffer(ARGS_ADDRESS_AND_SIZEOF(TapeTime));
12654 SaveEngineSnapshotBuffer(ARGS_ADDRESS_AND_SIZEOF(ScreenMovDir));
12655 SaveEngineSnapshotBuffer(ARGS_ADDRESS_AND_SIZEOF(ScreenMovPos));
12656 SaveEngineSnapshotBuffer(ARGS_ADDRESS_AND_SIZEOF(ScreenGfxPos));
12658 SaveEngineSnapshotBuffer(ARGS_ADDRESS_AND_SIZEOF(ScrollStepSize));
12660 SaveEngineSnapshotBuffer(ARGS_ADDRESS_AND_SIZEOF(AllPlayersGone));
12662 SaveEngineSnapshotBuffer(ARGS_ADDRESS_AND_SIZEOF(AmoebaCnt));
12663 SaveEngineSnapshotBuffer(ARGS_ADDRESS_AND_SIZEOF(AmoebaCnt2));
12665 SaveEngineSnapshotBuffer(ARGS_ADDRESS_AND_SIZEOF(Feld));
12666 SaveEngineSnapshotBuffer(ARGS_ADDRESS_AND_SIZEOF(MovPos));
12667 SaveEngineSnapshotBuffer(ARGS_ADDRESS_AND_SIZEOF(MovDir));
12668 SaveEngineSnapshotBuffer(ARGS_ADDRESS_AND_SIZEOF(MovDelay));
12669 SaveEngineSnapshotBuffer(ARGS_ADDRESS_AND_SIZEOF(ChangeDelay));
12670 SaveEngineSnapshotBuffer(ARGS_ADDRESS_AND_SIZEOF(ChangePage));
12671 SaveEngineSnapshotBuffer(ARGS_ADDRESS_AND_SIZEOF(CustomValue));
12672 SaveEngineSnapshotBuffer(ARGS_ADDRESS_AND_SIZEOF(Store));
12673 SaveEngineSnapshotBuffer(ARGS_ADDRESS_AND_SIZEOF(Store2));
12674 SaveEngineSnapshotBuffer(ARGS_ADDRESS_AND_SIZEOF(StorePlayer));
12675 SaveEngineSnapshotBuffer(ARGS_ADDRESS_AND_SIZEOF(Back));
12676 SaveEngineSnapshotBuffer(ARGS_ADDRESS_AND_SIZEOF(AmoebaNr));
12677 SaveEngineSnapshotBuffer(ARGS_ADDRESS_AND_SIZEOF(WasJustMoving));
12678 SaveEngineSnapshotBuffer(ARGS_ADDRESS_AND_SIZEOF(WasJustFalling));
12679 SaveEngineSnapshotBuffer(ARGS_ADDRESS_AND_SIZEOF(CheckCollision));
12680 SaveEngineSnapshotBuffer(ARGS_ADDRESS_AND_SIZEOF(Stop));
12681 SaveEngineSnapshotBuffer(ARGS_ADDRESS_AND_SIZEOF(Pushed));
12683 SaveEngineSnapshotBuffer(ARGS_ADDRESS_AND_SIZEOF(ChangeCount));
12684 SaveEngineSnapshotBuffer(ARGS_ADDRESS_AND_SIZEOF(ChangeEvent));
12686 SaveEngineSnapshotBuffer(ARGS_ADDRESS_AND_SIZEOF(ExplodePhase));
12687 SaveEngineSnapshotBuffer(ARGS_ADDRESS_AND_SIZEOF(ExplodeDelay));
12688 SaveEngineSnapshotBuffer(ARGS_ADDRESS_AND_SIZEOF(ExplodeField));
12690 SaveEngineSnapshotBuffer(ARGS_ADDRESS_AND_SIZEOF(RunnerVisit));
12691 SaveEngineSnapshotBuffer(ARGS_ADDRESS_AND_SIZEOF(PlayerVisit));
12693 SaveEngineSnapshotBuffer(ARGS_ADDRESS_AND_SIZEOF(GfxFrame));
12694 SaveEngineSnapshotBuffer(ARGS_ADDRESS_AND_SIZEOF(GfxRandom));
12695 SaveEngineSnapshotBuffer(ARGS_ADDRESS_AND_SIZEOF(GfxElement));
12696 SaveEngineSnapshotBuffer(ARGS_ADDRESS_AND_SIZEOF(GfxAction));
12697 SaveEngineSnapshotBuffer(ARGS_ADDRESS_AND_SIZEOF(GfxDir));
12699 SaveEngineSnapshotBuffer(ARGS_ADDRESS_AND_SIZEOF(scroll_x));
12700 SaveEngineSnapshotBuffer(ARGS_ADDRESS_AND_SIZEOF(scroll_y));
12702 /* save level identification information */
12704 setString(&snapshot_level_identifier, leveldir_current->identifier);
12705 snapshot_level_nr = level_nr;
12708 ListNode *node = engine_snapshot_list;
12711 while (node != NULL)
12713 num_bytes += ((struct EngineSnapshotNodeInfo *)node->content)->size;
12718 printf("::: size of engine snapshot: %d bytes\n", num_bytes);
12722 static void LoadEngineSnapshotBuffer(struct EngineSnapshotNodeInfo *bi)
12724 memcpy(bi->buffer_orig, bi->buffer_copy, bi->size);
12727 void LoadEngineSnapshot()
12729 ListNode *node = engine_snapshot_list;
12731 if (engine_snapshot_list == NULL)
12734 while (node != NULL)
12736 LoadEngineSnapshotBuffer((struct EngineSnapshotNodeInfo *)node->content);
12741 /* restore special values from snapshot structure */
12743 LoadEngineSnapshotValues_RND();
12744 LoadEngineSnapshotValues_EM();
12747 boolean CheckEngineSnapshot()
12749 return (strEqual(snapshot_level_identifier, leveldir_current->identifier) &&
12750 snapshot_level_nr == level_nr);
12754 /* ---------- new game button stuff ---------------------------------------- */
12756 /* graphic position values for game buttons */
12757 #define GAME_BUTTON_XSIZE 30
12758 #define GAME_BUTTON_YSIZE 30
12759 #define GAME_BUTTON_XPOS 5
12760 #define GAME_BUTTON_YPOS 215
12761 #define SOUND_BUTTON_XPOS 5
12762 #define SOUND_BUTTON_YPOS (GAME_BUTTON_YPOS + GAME_BUTTON_YSIZE)
12764 #define GAME_BUTTON_STOP_XPOS (GAME_BUTTON_XPOS + 0 * GAME_BUTTON_XSIZE)
12765 #define GAME_BUTTON_PAUSE_XPOS (GAME_BUTTON_XPOS + 1 * GAME_BUTTON_XSIZE)
12766 #define GAME_BUTTON_PLAY_XPOS (GAME_BUTTON_XPOS + 2 * GAME_BUTTON_XSIZE)
12767 #define SOUND_BUTTON_MUSIC_XPOS (SOUND_BUTTON_XPOS + 0 * GAME_BUTTON_XSIZE)
12768 #define SOUND_BUTTON_LOOPS_XPOS (SOUND_BUTTON_XPOS + 1 * GAME_BUTTON_XSIZE)
12769 #define SOUND_BUTTON_SIMPLE_XPOS (SOUND_BUTTON_XPOS + 2 * GAME_BUTTON_XSIZE)
12776 } gamebutton_info[NUM_GAME_BUTTONS] =
12779 GAME_BUTTON_STOP_XPOS, GAME_BUTTON_YPOS,
12784 GAME_BUTTON_PAUSE_XPOS, GAME_BUTTON_YPOS,
12785 GAME_CTRL_ID_PAUSE,
12789 GAME_BUTTON_PLAY_XPOS, GAME_BUTTON_YPOS,
12794 SOUND_BUTTON_MUSIC_XPOS, SOUND_BUTTON_YPOS,
12795 SOUND_CTRL_ID_MUSIC,
12796 "background music on/off"
12799 SOUND_BUTTON_LOOPS_XPOS, SOUND_BUTTON_YPOS,
12800 SOUND_CTRL_ID_LOOPS,
12801 "sound loops on/off"
12804 SOUND_BUTTON_SIMPLE_XPOS, SOUND_BUTTON_YPOS,
12805 SOUND_CTRL_ID_SIMPLE,
12806 "normal sounds on/off"
12810 void CreateGameButtons()
12814 for (i = 0; i < NUM_GAME_BUTTONS; i++)
12816 Bitmap *gd_bitmap = graphic_info[IMG_GLOBAL_DOOR].bitmap;
12817 struct GadgetInfo *gi;
12820 unsigned long event_mask;
12821 int gd_xoffset, gd_yoffset;
12822 int gd_x1, gd_x2, gd_y1, gd_y2;
12825 gd_xoffset = gamebutton_info[i].x;
12826 gd_yoffset = gamebutton_info[i].y;
12827 gd_x1 = DOOR_GFX_PAGEX4 + gd_xoffset;
12828 gd_x2 = DOOR_GFX_PAGEX3 + gd_xoffset;
12830 if (id == GAME_CTRL_ID_STOP ||
12831 id == GAME_CTRL_ID_PAUSE ||
12832 id == GAME_CTRL_ID_PLAY)
12834 button_type = GD_TYPE_NORMAL_BUTTON;
12836 event_mask = GD_EVENT_RELEASED;
12837 gd_y1 = DOOR_GFX_PAGEY1 + gd_yoffset - GAME_BUTTON_YSIZE;
12838 gd_y2 = DOOR_GFX_PAGEY1 + gd_yoffset - GAME_BUTTON_YSIZE;
12842 button_type = GD_TYPE_CHECK_BUTTON;
12844 ((id == SOUND_CTRL_ID_MUSIC && setup.sound_music) ||
12845 (id == SOUND_CTRL_ID_LOOPS && setup.sound_loops) ||
12846 (id == SOUND_CTRL_ID_SIMPLE && setup.sound_simple) ? TRUE : FALSE);
12847 event_mask = GD_EVENT_PRESSED;
12848 gd_y1 = DOOR_GFX_PAGEY1 + gd_yoffset;
12849 gd_y2 = DOOR_GFX_PAGEY1 + gd_yoffset - GAME_BUTTON_YSIZE;
12852 gi = CreateGadget(GDI_CUSTOM_ID, id,
12853 GDI_INFO_TEXT, gamebutton_info[i].infotext,
12854 GDI_X, DX + gd_xoffset,
12855 GDI_Y, DY + gd_yoffset,
12856 GDI_WIDTH, GAME_BUTTON_XSIZE,
12857 GDI_HEIGHT, GAME_BUTTON_YSIZE,
12858 GDI_TYPE, button_type,
12859 GDI_STATE, GD_BUTTON_UNPRESSED,
12860 GDI_CHECKED, checked,
12861 GDI_DESIGN_UNPRESSED, gd_bitmap, gd_x1, gd_y1,
12862 GDI_DESIGN_PRESSED, gd_bitmap, gd_x2, gd_y1,
12863 GDI_ALT_DESIGN_UNPRESSED, gd_bitmap, gd_x1, gd_y2,
12864 GDI_ALT_DESIGN_PRESSED, gd_bitmap, gd_x2, gd_y2,
12865 GDI_EVENT_MASK, event_mask,
12866 GDI_CALLBACK_ACTION, HandleGameButtons,
12870 Error(ERR_EXIT, "cannot create gadget");
12872 game_gadget[id] = gi;
12876 void FreeGameButtons()
12880 for (i = 0; i < NUM_GAME_BUTTONS; i++)
12881 FreeGadget(game_gadget[i]);
12884 static void MapGameButtons()
12888 for (i = 0; i < NUM_GAME_BUTTONS; i++)
12889 MapGadget(game_gadget[i]);
12892 void UnmapGameButtons()
12896 for (i = 0; i < NUM_GAME_BUTTONS; i++)
12897 UnmapGadget(game_gadget[i]);
12900 static void HandleGameButtons(struct GadgetInfo *gi)
12902 int id = gi->custom_id;
12904 if (game_status != GAME_MODE_PLAYING)
12909 case GAME_CTRL_ID_STOP:
12913 RequestQuitGame(TRUE);
12916 case GAME_CTRL_ID_PAUSE:
12917 if (options.network)
12919 #if defined(NETWORK_AVALIABLE)
12921 SendToServer_ContinuePlaying();
12923 SendToServer_PausePlaying();
12927 TapeTogglePause(TAPE_TOGGLE_MANUAL);
12930 case GAME_CTRL_ID_PLAY:
12933 #if defined(NETWORK_AVALIABLE)
12934 if (options.network)
12935 SendToServer_ContinuePlaying();
12939 tape.pausing = FALSE;
12940 DrawVideoDisplay(VIDEO_STATE_PAUSE_OFF, 0);
12945 case SOUND_CTRL_ID_MUSIC:
12946 if (setup.sound_music)
12948 setup.sound_music = FALSE;
12951 else if (audio.music_available)
12953 setup.sound = setup.sound_music = TRUE;
12955 SetAudioMode(setup.sound);
12961 case SOUND_CTRL_ID_LOOPS:
12962 if (setup.sound_loops)
12963 setup.sound_loops = FALSE;
12964 else if (audio.loops_available)
12966 setup.sound = setup.sound_loops = TRUE;
12967 SetAudioMode(setup.sound);
12971 case SOUND_CTRL_ID_SIMPLE:
12972 if (setup.sound_simple)
12973 setup.sound_simple = FALSE;
12974 else if (audio.sound_available)
12976 setup.sound = setup.sound_simple = TRUE;
12977 SetAudioMode(setup.sound);