1 /***********************************************************
2 * Rocks'n'Diamonds -- McDuffin Strikes Back! *
3 *----------------------------------------------------------*
4 * (c) 1995-2002 Artsoft Entertainment *
6 * Detmolder Strasse 189 *
9 * e-mail: info@artsoft.org *
10 *----------------------------------------------------------*
12 ***********************************************************/
14 #include "libgame/libgame.h"
24 /* EXPERIMENTAL STUFF */
25 #define USE_NEW_AMOEBA_CODE FALSE
27 /* EXPERIMENTAL STUFF */
28 #define USE_NEW_STUFF ( 1)
30 #define USE_NEW_SP_SLIPPERY (USE_NEW_STUFF * 1)
31 #define USE_NEW_CUSTOM_VALUE (USE_NEW_STUFF * 1)
32 #define USE_NEW_PLAYER_ANIM (USE_NEW_STUFF * 1)
33 #define USE_NEW_ALL_SLIPPERY (USE_NEW_STUFF * 1)
34 #define USE_NEW_PLAYER_SPEED (USE_NEW_STUFF * 1)
35 #define USE_NEW_DELAYED_ACTION (USE_NEW_STUFF * 1)
36 #define USE_NEW_SNAP_DELAY (USE_NEW_STUFF * 1)
37 #define USE_ONLY_ONE_CHANGE_PER_FRAME (USE_NEW_STUFF * 1)
38 #define USE_ONE_MORE_CHANGE_PER_FRAME (USE_NEW_STUFF * 1)
39 #define USE_FIXED_DONT_RUN_INTO (USE_NEW_STUFF * 1)
40 #define USE_NEW_SPRING_BUMPER (USE_NEW_STUFF * 1)
41 #define USE_STOP_CHANGED_ELEMENTS (USE_NEW_STUFF * 1)
42 #define USE_ELEMENT_TOUCHING_BUGFIX (USE_NEW_STUFF * 1)
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)
55 #define USE_NEW_GAME_WON (USE_NEW_STUFF * 1)
63 /* for MovePlayer() */
64 #define MP_NO_ACTION 0
67 #define MP_DONT_RUN_INTO (MP_MOVING | MP_ACTION)
69 /* for ScrollPlayer() */
71 #define SCROLL_GO_ON 1
73 /* for Bang()/Explode() */
74 #define EX_PHASE_START 0
75 #define EX_TYPE_NONE 0
76 #define EX_TYPE_NORMAL (1 << 0)
77 #define EX_TYPE_CENTER (1 << 1)
78 #define EX_TYPE_BORDER (1 << 2)
79 #define EX_TYPE_CROSS (1 << 3)
80 #define EX_TYPE_DYNA (1 << 4)
81 #define EX_TYPE_SINGLE_TILE (EX_TYPE_CENTER | EX_TYPE_BORDER)
85 #define PANEL_DEACTIVATED(p) ((p).x < 0 || (p).y < 0)
87 /* special positions in the game control window (relative to control window) */
88 #define XX_LEVEL1 (game.panel.level.x)
89 #define XX_LEVEL2 (game.panel.level.x - 1)
90 #define YY_LEVEL (game.panel.level.y)
91 #define XX_EMERALDS (game.panel.gems.x)
92 #define YY_EMERALDS (game.panel.gems.y)
93 #define XX_DYNAMITE (game.panel.inventory.x)
94 #define YY_DYNAMITE (game.panel.inventory.y)
95 #define XX_KEYS (game.panel.keys.x)
96 #define YY_KEYS (game.panel.keys.y)
97 #define XX_SCORE (game.panel.score.x)
98 #define YY_SCORE (game.panel.score.y)
99 #define XX_TIME1 (game.panel.time.x)
100 #define XX_TIME2 (game.panel.time.x + 1)
101 #define YY_TIME (game.panel.time.y)
105 /* special positions in the game control window (relative to control window) */
108 #define XX_EMERALDS 29
109 #define YY_EMERALDS 54
110 #define XX_DYNAMITE 29
111 #define YY_DYNAMITE 89
122 /* special positions in the game control window (relative to main window) */
123 #define DX_LEVEL1 (DX + XX_LEVEL1)
124 #define DX_LEVEL2 (DX + XX_LEVEL2)
125 #define DY_LEVEL (DY + YY_LEVEL)
126 #define DX_EMERALDS (DX + XX_EMERALDS)
127 #define DY_EMERALDS (DY + YY_EMERALDS)
128 #define DX_DYNAMITE (DX + XX_DYNAMITE)
129 #define DY_DYNAMITE (DY + YY_DYNAMITE)
130 #define DX_KEYS (DX + XX_KEYS)
131 #define DY_KEYS (DY + YY_KEYS)
132 #define DX_SCORE (DX + XX_SCORE)
133 #define DY_SCORE (DY + YY_SCORE)
134 #define DX_TIME1 (DX + XX_TIME1)
135 #define DX_TIME2 (DX + XX_TIME2)
136 #define DY_TIME (DY + YY_TIME)
138 /* values for delayed check of falling and moving elements and for collision */
139 #define CHECK_DELAY_MOVING 3
140 #define CHECK_DELAY_FALLING 3
141 #define CHECK_DELAY_COLLISION 2
143 /* values for initial player move delay (initial delay counter value) */
144 #define INITIAL_MOVE_DELAY_OFF -1
145 #define INITIAL_MOVE_DELAY_ON 0
147 /* values for player movement speed (which is in fact a delay value) */
148 #define MOVE_DELAY_MIN_SPEED 32
149 #define MOVE_DELAY_NORMAL_SPEED 8
150 #define MOVE_DELAY_HIGH_SPEED 4
151 #define MOVE_DELAY_MAX_SPEED 1
154 #define DOUBLE_MOVE_DELAY(x) (x = (x <= MOVE_DELAY_HIGH_SPEED ? x * 2 : x))
155 #define HALVE_MOVE_DELAY(x) (x = (x >= MOVE_DELAY_HIGH_SPEED ? x / 2 : x))
157 #define DOUBLE_MOVE_DELAY(x) (x = (x < MOVE_DELAY_MIN_SPEED ? x * 2 : x))
158 #define HALVE_MOVE_DELAY(x) (x = (x > MOVE_DELAY_MAX_SPEED ? x / 2 : x))
160 #define DOUBLE_PLAYER_SPEED(p) (HALVE_MOVE_DELAY((p)->move_delay_value))
161 #define HALVE_PLAYER_SPEED(p) (DOUBLE_MOVE_DELAY((p)->move_delay_value))
163 /* values for other actions */
164 #define MOVE_STEPSIZE_NORMAL (TILEX / MOVE_DELAY_NORMAL_SPEED)
165 #define MOVE_STEPSIZE_MIN (1)
166 #define MOVE_STEPSIZE_MAX (TILEX)
168 #define GET_DX_FROM_DIR(d) ((d) == MV_LEFT ? -1 : (d) == MV_RIGHT ? 1 : 0)
169 #define GET_DY_FROM_DIR(d) ((d) == MV_UP ? -1 : (d) == MV_DOWN ? 1 : 0)
171 #define INIT_GFX_RANDOM() (SimpleRND(1000000))
173 #define GET_NEW_PUSH_DELAY(e) ( (element_info[e].push_delay_fixed) + \
174 RND(element_info[e].push_delay_random))
175 #define GET_NEW_DROP_DELAY(e) ( (element_info[e].drop_delay_fixed) + \
176 RND(element_info[e].drop_delay_random))
177 #define GET_NEW_MOVE_DELAY(e) ( (element_info[e].move_delay_fixed) + \
178 RND(element_info[e].move_delay_random))
179 #define GET_MAX_MOVE_DELAY(e) ( (element_info[e].move_delay_fixed) + \
180 (element_info[e].move_delay_random))
181 #define GET_NEW_CE_VALUE(e) ( (element_info[e].ce_value_fixed_initial) +\
182 RND(element_info[e].ce_value_random_initial))
183 #define GET_CE_SCORE(e) ( (element_info[e].collect_score))
184 #define GET_CHANGE_DELAY(c) ( ((c)->delay_fixed * (c)->delay_frames) + \
185 RND((c)->delay_random * (c)->delay_frames))
186 #define GET_CE_DELAY_VALUE(c) ( ((c)->delay_fixed) + \
187 RND((c)->delay_random))
191 #define GET_VALID_RUNTIME_ELEMENT(e) \
192 ((e) >= NUM_RUNTIME_ELEMENTS ? EL_UNKNOWN : (e))
194 #define GET_VALID_FILE_ELEMENT(e) \
195 ((e) >= NUM_FILE_ELEMENTS ? EL_UNKNOWN : (e))
198 #define RESOLVED_REFERENCE_ELEMENT(be, e) \
199 ((be) + (e) - EL_SELF < EL_CUSTOM_START ? EL_CUSTOM_START : \
200 (be) + (e) - EL_SELF > EL_CUSTOM_END ? EL_CUSTOM_END : \
201 (be) + (e) - EL_SELF)
203 #define GET_TARGET_ELEMENT(be, e, ch, cv, cs) \
204 ((e) == EL_TRIGGER_PLAYER ? (ch)->actual_trigger_player : \
205 (e) == EL_TRIGGER_ELEMENT ? (ch)->actual_trigger_element : \
206 (e) == EL_TRIGGER_CE_VALUE ? (ch)->actual_trigger_ce_value : \
207 (e) == EL_TRIGGER_CE_SCORE ? (ch)->actual_trigger_ce_score : \
208 (e) == EL_CURRENT_CE_VALUE ? (cv) : \
209 (e) == EL_CURRENT_CE_SCORE ? (cs) : \
210 (e) >= EL_LAST_CE_8 && (e) <= EL_NEXT_CE_8 ? \
211 RESOLVED_REFERENCE_ELEMENT(be, e) : \
214 #define CAN_GROW_INTO(e) \
215 ((e) == EL_SAND || (IS_DIGGABLE(e) && level.grow_into_diggable))
217 #define ELEMENT_CAN_ENTER_FIELD_BASE_X(x, y, condition) \
218 (IN_LEV_FIELD(x, y) && (IS_FREE(x, y) || \
221 #define ELEMENT_CAN_ENTER_FIELD_BASE_2(e, x, y, condition) \
222 (IN_LEV_FIELD(x, y) && (IS_FREE(x, y) || \
223 (CAN_MOVE_INTO_ACID(e) && \
224 Feld[x][y] == EL_ACID) || \
227 #define ELEMENT_CAN_ENTER_FIELD_BASE_3(e, x, y, condition) \
228 (IN_LEV_FIELD(x, y) && (IS_FREE_OR_PLAYER(x, y) || \
229 (CAN_MOVE_INTO_ACID(e) && \
230 Feld[x][y] == EL_ACID) || \
233 #define ELEMENT_CAN_ENTER_FIELD_BASE_4(e, x, y, condition) \
234 (IN_LEV_FIELD(x, y) && (IS_FREE(x, y) || \
236 (CAN_MOVE_INTO_ACID(e) && \
237 Feld[x][y] == EL_ACID) || \
238 (DONT_COLLIDE_WITH(e) && \
240 !PLAYER_ENEMY_PROTECTED(x, y))))
242 #define ELEMENT_CAN_ENTER_FIELD(e, x, y) \
243 ELEMENT_CAN_ENTER_FIELD_BASE_4(e, x, y, 0)
245 #define SATELLITE_CAN_ENTER_FIELD(x, y) \
246 ELEMENT_CAN_ENTER_FIELD_BASE_2(EL_SATELLITE, x, y, 0)
248 #define ANDROID_CAN_ENTER_FIELD(e, x, y) \
249 ELEMENT_CAN_ENTER_FIELD_BASE_2(e, x, y, Feld[x][y] == EL_EMC_PLANT)
251 #define ANDROID_CAN_CLONE_FIELD(x, y) \
252 (IN_LEV_FIELD(x, y) && (CAN_BE_CLONED_BY_ANDROID(Feld[x][y]) || \
253 CAN_BE_CLONED_BY_ANDROID(EL_TRIGGER_ELEMENT)))
255 #define ENEMY_CAN_ENTER_FIELD(e, x, y) \
256 ELEMENT_CAN_ENTER_FIELD_BASE_2(e, x, y, 0)
258 #define YAMYAM_CAN_ENTER_FIELD(e, x, y) \
259 ELEMENT_CAN_ENTER_FIELD_BASE_3(e, x, y, Feld[x][y] == EL_DIAMOND)
261 #define DARK_YAMYAM_CAN_ENTER_FIELD(e, x, y) \
262 ELEMENT_CAN_ENTER_FIELD_BASE_3(e, x,y, IS_FOOD_DARK_YAMYAM(Feld[x][y]))
264 #define PACMAN_CAN_ENTER_FIELD(e, x, y) \
265 ELEMENT_CAN_ENTER_FIELD_BASE_3(e, x, y, IS_AMOEBOID(Feld[x][y]))
267 #define PIG_CAN_ENTER_FIELD(e, x, y) \
268 ELEMENT_CAN_ENTER_FIELD_BASE_2(e, x, y, IS_FOOD_PIG(Feld[x][y]))
270 #define PENGUIN_CAN_ENTER_FIELD(e, x, y) \
271 ELEMENT_CAN_ENTER_FIELD_BASE_2(e, x, y, (Feld[x][y] == EL_EXIT_OPEN ||\
272 IS_FOOD_PENGUIN(Feld[x][y])))
273 #define DRAGON_CAN_ENTER_FIELD(e, x, y) \
274 ELEMENT_CAN_ENTER_FIELD_BASE_2(e, x, y, 0)
276 #define MOLE_CAN_ENTER_FIELD(e, x, y, condition) \
277 ELEMENT_CAN_ENTER_FIELD_BASE_2(e, x, y, (condition))
279 #define SPRING_CAN_ENTER_FIELD(e, x, y) \
280 ELEMENT_CAN_ENTER_FIELD_BASE_2(e, x, y, 0)
282 #define SPRING_CAN_BUMP_FROM_FIELD(x, y) \
283 (IN_LEV_FIELD(x, y) && (Feld[x][y] == EL_EMC_SPRING_BUMPER || \
284 Feld[x][y] == EL_EMC_SPRING_BUMPER_ACTIVE))
287 #define GROUP_NR(e) ((e) - EL_GROUP_START)
288 #define IS_IN_GROUP(e, nr) (element_info[e].in_group[nr] == TRUE)
289 #define IS_IN_GROUP_EL(e, ge) (IS_IN_GROUP(e, (ge) - EL_GROUP_START))
291 #define IS_EQUAL_OR_IN_GROUP(e, ge) \
292 (IS_GROUP_ELEMENT(ge) ? IS_IN_GROUP(e, GROUP_NR(ge)) : (e) == (ge))
295 #define MOVE_ENTER_EL(e) (element_info[e].move_enter_element)
297 #define CE_ENTER_FIELD_COND(e, x, y) \
298 (!IS_PLAYER(x, y) && \
299 IS_EQUAL_OR_IN_GROUP(Feld[x][y], MOVE_ENTER_EL(e)))
301 #define CUSTOM_ELEMENT_CAN_ENTER_FIELD(e, x, y) \
302 ELEMENT_CAN_ENTER_FIELD_BASE_4(e, x, y, CE_ENTER_FIELD_COND(e, x, y))
304 #define IN_LEV_FIELD_AND_IS_FREE(x, y) (IN_LEV_FIELD(x, y) && IS_FREE(x, y))
305 #define IN_LEV_FIELD_AND_NOT_FREE(x, y) (IN_LEV_FIELD(x, y) && !IS_FREE(x, y))
307 #define ACCESS_FROM(e, d) (element_info[e].access_direction &(d))
308 #define IS_WALKABLE_FROM(e, d) (IS_WALKABLE(e) && ACCESS_FROM(e, d))
309 #define IS_PASSABLE_FROM(e, d) (IS_PASSABLE(e) && ACCESS_FROM(e, d))
310 #define IS_ACCESSIBLE_FROM(e, d) (IS_ACCESSIBLE(e) && ACCESS_FROM(e, d))
312 /* game button identifiers */
313 #define GAME_CTRL_ID_STOP 0
314 #define GAME_CTRL_ID_PAUSE 1
315 #define GAME_CTRL_ID_PLAY 2
316 #define SOUND_CTRL_ID_MUSIC 3
317 #define SOUND_CTRL_ID_LOOPS 4
318 #define SOUND_CTRL_ID_SIMPLE 5
320 #define NUM_GAME_BUTTONS 6
323 /* forward declaration for internal use */
325 static void CreateField(int, int, int);
327 static void SetPlayerWaiting(struct PlayerInfo *, boolean);
328 static void AdvanceFrameAndPlayerCounters(int);
330 static boolean MovePlayerOneStep(struct PlayerInfo *, int, int, int, int);
331 static boolean MovePlayer(struct PlayerInfo *, int, int);
332 static void ScrollPlayer(struct PlayerInfo *, int);
333 static void ScrollScreen(struct PlayerInfo *, int);
335 int DigField(struct PlayerInfo *, int, int, int, int, int, int, int);
337 static void InitBeltMovement(void);
338 static void CloseAllOpenTimegates(void);
339 static void CheckGravityMovement(struct PlayerInfo *);
340 static void CheckGravityMovementWhenNotMoving(struct PlayerInfo *);
341 static void KillPlayerUnlessEnemyProtected(int, int);
342 static void KillPlayerUnlessExplosionProtected(int, int);
344 static void TestIfPlayerTouchesCustomElement(int, int);
345 static void TestIfElementTouchesCustomElement(int, int);
346 static void TestIfElementHitsCustomElement(int, int, int);
348 static void TestIfElementSmashesCustomElement(int, int, int);
351 static void HandleElementChange(int, int, int);
352 static void ExecuteCustomElementAction(int, int, int, int);
353 static boolean ChangeElement(int, int, int, int);
355 static boolean CheckTriggeredElementChangeExt(int, int, int, int, int,int,int);
356 #define CheckTriggeredElementChange(x, y, e, ev) \
357 CheckTriggeredElementChangeExt(x,y,e,ev, CH_PLAYER_ANY,CH_SIDE_ANY, -1)
358 #define CheckTriggeredElementChangeByPlayer(x, y, e, ev, p, s) \
359 CheckTriggeredElementChangeExt(x, y, e, ev, p, s, -1)
360 #define CheckTriggeredElementChangeBySide(x, y, e, ev, s) \
361 CheckTriggeredElementChangeExt(x, y, e, ev, CH_PLAYER_ANY, s, -1)
362 #define CheckTriggeredElementChangeByPage(x, y, e, ev, p) \
363 CheckTriggeredElementChangeExt(x,y,e,ev, CH_PLAYER_ANY, CH_SIDE_ANY, p)
365 static boolean CheckElementChangeExt(int, int, int, int, int, int, int);
366 #define CheckElementChange(x, y, e, te, ev) \
367 CheckElementChangeExt(x, y, e, te, ev, CH_PLAYER_ANY, CH_SIDE_ANY)
368 #define CheckElementChangeByPlayer(x, y, e, ev, p, s) \
369 CheckElementChangeExt(x, y, e, EL_EMPTY, ev, p, s)
370 #define CheckElementChangeBySide(x, y, e, te, ev, s) \
371 CheckElementChangeExt(x, y, e, te, ev, CH_PLAYER_ANY, s)
373 static void PlayLevelSound(int, int, int);
374 static void PlayLevelSoundNearest(int, int, int);
375 static void PlayLevelSoundAction(int, int, int);
376 static void PlayLevelSoundElementAction(int, int, int, int);
377 static void PlayLevelSoundElementActionIfLoop(int, int, int, int);
378 static void PlayLevelSoundActionIfLoop(int, int, int);
379 static void StopLevelSoundActionIfLoop(int, int, int);
380 static void PlayLevelMusic();
382 static void MapGameButtons();
383 static void HandleGameButtons(struct GadgetInfo *);
385 int AmoebeNachbarNr(int, int);
386 void AmoebeUmwandeln(int, int);
387 void ContinueMoving(int, int);
389 void InitMovDir(int, int);
390 void InitAmoebaNr(int, int);
391 int NewHiScore(void);
393 void TestIfGoodThingHitsBadThing(int, int, int);
394 void TestIfBadThingHitsGoodThing(int, int, int);
395 void TestIfPlayerTouchesBadThing(int, int);
396 void TestIfPlayerRunsIntoBadThing(int, int, int);
397 void TestIfBadThingTouchesPlayer(int, int);
398 void TestIfBadThingRunsIntoPlayer(int, int, int);
399 void TestIfFriendTouchesBadThing(int, int);
400 void TestIfBadThingTouchesFriend(int, int);
401 void TestIfBadThingTouchesOtherBadThing(int, int);
403 void KillPlayer(struct PlayerInfo *);
404 void BuryPlayer(struct PlayerInfo *);
405 void RemovePlayer(struct PlayerInfo *);
407 boolean SnapField(struct PlayerInfo *, int, int);
408 boolean DropElement(struct PlayerInfo *);
410 static int getInvisibleActiveFromInvisibleElement(int);
411 static int getInvisibleFromInvisibleActiveElement(int);
413 static struct GadgetInfo *game_gadget[NUM_GAME_BUTTONS];
416 /* ------------------------------------------------------------------------- */
417 /* definition of elements that automatically change to other elements after */
418 /* a specified time, eventually calling a function when changing */
419 /* ------------------------------------------------------------------------- */
421 /* forward declaration for changer functions */
422 static void InitBuggyBase(int, int);
423 static void WarnBuggyBase(int, int);
425 static void InitTrap(int, int);
426 static void ActivateTrap(int, int);
427 static void ChangeActiveTrap(int, int);
429 static void InitRobotWheel(int, int);
430 static void RunRobotWheel(int, int);
431 static void StopRobotWheel(int, int);
433 static void InitTimegateWheel(int, int);
434 static void RunTimegateWheel(int, int);
436 static void InitMagicBallDelay(int, int);
437 static void ActivateMagicBall(int, int);
439 static void InitDiagonalMovingElement(int, int);
441 struct ChangingElementInfo
446 void (*pre_change_function)(int x, int y);
447 void (*change_function)(int x, int y);
448 void (*post_change_function)(int x, int y);
451 static struct ChangingElementInfo change_delay_list[] =
502 EL_SWITCHGATE_OPENING,
510 EL_SWITCHGATE_CLOSING,
511 EL_SWITCHGATE_CLOSED,
543 EL_ACID_SPLASH_RIGHT,
552 EL_SP_BUGGY_BASE_ACTIVATING,
559 EL_SP_BUGGY_BASE_ACTIVATING,
560 EL_SP_BUGGY_BASE_ACTIVE,
567 EL_SP_BUGGY_BASE_ACTIVE,
591 EL_ROBOT_WHEEL_ACTIVE,
599 EL_TIMEGATE_SWITCH_ACTIVE,
607 EL_EMC_MAGIC_BALL_ACTIVE,
608 EL_EMC_MAGIC_BALL_ACTIVE,
615 EL_EMC_SPRING_BUMPER_ACTIVE,
616 EL_EMC_SPRING_BUMPER,
623 EL_DIAGONAL_SHRINKING,
636 InitDiagonalMovingElement
652 int push_delay_fixed, push_delay_random;
657 { EL_BALLOON, 0, 0 },
659 { EL_SOKOBAN_OBJECT, 2, 0 },
660 { EL_SOKOBAN_FIELD_FULL, 2, 0 },
661 { EL_SATELLITE, 2, 0 },
662 { EL_SP_DISK_YELLOW, 2, 0 },
664 { EL_UNDEFINED, 0, 0 },
672 move_stepsize_list[] =
674 { EL_AMOEBA_DROP, 2 },
675 { EL_AMOEBA_DROPPING, 2 },
676 { EL_QUICKSAND_FILLING, 1 },
677 { EL_QUICKSAND_EMPTYING, 1 },
678 { EL_MAGIC_WALL_FILLING, 2 },
679 { EL_BD_MAGIC_WALL_FILLING, 2 },
680 { EL_MAGIC_WALL_EMPTYING, 2 },
681 { EL_BD_MAGIC_WALL_EMPTYING, 2 },
691 collect_count_list[] =
694 { EL_BD_DIAMOND, 1 },
695 { EL_EMERALD_YELLOW, 1 },
696 { EL_EMERALD_RED, 1 },
697 { EL_EMERALD_PURPLE, 1 },
699 { EL_SP_INFOTRON, 1 },
711 access_direction_list[] =
713 { EL_TUBE_ANY, MV_LEFT | MV_RIGHT | MV_UP | MV_DOWN },
714 { EL_TUBE_VERTICAL, MV_UP | MV_DOWN },
715 { EL_TUBE_HORIZONTAL, MV_LEFT | MV_RIGHT },
716 { EL_TUBE_VERTICAL_LEFT, MV_LEFT | MV_UP | MV_DOWN },
717 { EL_TUBE_VERTICAL_RIGHT, MV_RIGHT | MV_UP | MV_DOWN },
718 { EL_TUBE_HORIZONTAL_UP, MV_LEFT | MV_RIGHT | MV_UP },
719 { EL_TUBE_HORIZONTAL_DOWN, MV_LEFT | MV_RIGHT | MV_DOWN },
720 { EL_TUBE_LEFT_UP, MV_LEFT | MV_UP },
721 { EL_TUBE_LEFT_DOWN, MV_LEFT | MV_DOWN },
722 { EL_TUBE_RIGHT_UP, MV_RIGHT | MV_UP },
723 { EL_TUBE_RIGHT_DOWN, MV_RIGHT | MV_DOWN },
725 { EL_SP_PORT_LEFT, MV_RIGHT },
726 { EL_SP_PORT_RIGHT, MV_LEFT },
727 { EL_SP_PORT_UP, MV_DOWN },
728 { EL_SP_PORT_DOWN, MV_UP },
729 { EL_SP_PORT_HORIZONTAL, MV_LEFT | MV_RIGHT },
730 { EL_SP_PORT_VERTICAL, MV_UP | MV_DOWN },
731 { EL_SP_PORT_ANY, MV_LEFT | MV_RIGHT | MV_UP | MV_DOWN },
732 { EL_SP_GRAVITY_PORT_LEFT, MV_RIGHT },
733 { EL_SP_GRAVITY_PORT_RIGHT, MV_LEFT },
734 { EL_SP_GRAVITY_PORT_UP, MV_DOWN },
735 { EL_SP_GRAVITY_PORT_DOWN, MV_UP },
736 { EL_SP_GRAVITY_ON_PORT_LEFT, MV_RIGHT },
737 { EL_SP_GRAVITY_ON_PORT_RIGHT, MV_LEFT },
738 { EL_SP_GRAVITY_ON_PORT_UP, MV_DOWN },
739 { EL_SP_GRAVITY_ON_PORT_DOWN, MV_UP },
740 { EL_SP_GRAVITY_OFF_PORT_LEFT, MV_RIGHT },
741 { EL_SP_GRAVITY_OFF_PORT_RIGHT, MV_LEFT },
742 { EL_SP_GRAVITY_OFF_PORT_UP, MV_DOWN },
743 { EL_SP_GRAVITY_OFF_PORT_DOWN, MV_UP },
745 { EL_UNDEFINED, MV_NONE }
748 static boolean trigger_events[MAX_NUM_ELEMENTS][NUM_CHANGE_EVENTS];
750 #define IS_AUTO_CHANGING(e) (element_info[e].has_change_event[CE_DELAY])
751 #define IS_JUST_CHANGING(x, y) (ChangeDelay[x][y] != 0)
752 #define IS_CHANGING(x, y) (IS_AUTO_CHANGING(Feld[x][y]) || \
753 IS_JUST_CHANGING(x, y))
755 #define CE_PAGE(e, ce) (element_info[e].event_page[ce])
757 /* static variables for playfield scan mode (scanning forward or backward) */
758 static int playfield_scan_start_x = 0;
759 static int playfield_scan_start_y = 0;
760 static int playfield_scan_delta_x = 1;
761 static int playfield_scan_delta_y = 1;
763 #define SCAN_PLAYFIELD(x, y) for ((y) = playfield_scan_start_y; \
764 (y) >= 0 && (y) <= lev_fieldy - 1; \
765 (y) += playfield_scan_delta_y) \
766 for ((x) = playfield_scan_start_x; \
767 (x) >= 0 && (x) <= lev_fieldx - 1; \
768 (x) += playfield_scan_delta_x) \
771 void DEBUG_SetMaximumDynamite()
775 for (i = 0; i < MAX_INVENTORY_SIZE; i++)
776 if (local_player->inventory_size < MAX_INVENTORY_SIZE)
777 local_player->inventory_element[local_player->inventory_size++] =
782 static void InitPlayfieldScanModeVars()
784 if (game.use_reverse_scan_direction)
786 playfield_scan_start_x = lev_fieldx - 1;
787 playfield_scan_start_y = lev_fieldy - 1;
789 playfield_scan_delta_x = -1;
790 playfield_scan_delta_y = -1;
794 playfield_scan_start_x = 0;
795 playfield_scan_start_y = 0;
797 playfield_scan_delta_x = 1;
798 playfield_scan_delta_y = 1;
802 static void InitPlayfieldScanMode(int mode)
804 game.use_reverse_scan_direction =
805 (mode == CA_ARG_SCAN_MODE_REVERSE ? TRUE : FALSE);
807 InitPlayfieldScanModeVars();
810 static int get_move_delay_from_stepsize(int move_stepsize)
813 MIN(MAX(MOVE_STEPSIZE_MIN, move_stepsize), MOVE_STEPSIZE_MAX);
815 /* make sure that stepsize value is always a power of 2 */
816 move_stepsize = (1 << log_2(move_stepsize));
818 return TILEX / move_stepsize;
821 static void SetPlayerMoveSpeed(struct PlayerInfo *player, int move_stepsize,
824 int player_nr = player->index_nr;
825 int move_delay = get_move_delay_from_stepsize(move_stepsize);
826 boolean cannot_move = (move_stepsize == STEPSIZE_NOT_MOVING ? TRUE : FALSE);
828 /* do no immediately change move delay -- the player might just be moving */
829 player->move_delay_value_next = move_delay;
831 /* information if player can move must be set separately */
832 player->cannot_move = cannot_move;
836 player->move_delay = game.initial_move_delay[player_nr];
837 player->move_delay_value = game.initial_move_delay_value[player_nr];
839 player->move_delay_value_next = -1;
841 player->move_delay_reset_counter = 0;
845 void GetPlayerConfig()
847 if (!audio.sound_available)
848 setup.sound_simple = FALSE;
850 if (!audio.loops_available)
851 setup.sound_loops = FALSE;
853 if (!audio.music_available)
854 setup.sound_music = FALSE;
856 if (!video.fullscreen_available)
857 setup.fullscreen = FALSE;
859 setup.sound = (setup.sound_simple || setup.sound_loops || setup.sound_music);
861 SetAudioMode(setup.sound);
865 static int getBeltNrFromBeltElement(int element)
867 return (element < EL_CONVEYOR_BELT_2_LEFT ? 0 :
868 element < EL_CONVEYOR_BELT_3_LEFT ? 1 :
869 element < EL_CONVEYOR_BELT_4_LEFT ? 2 : 3);
872 static int getBeltNrFromBeltActiveElement(int element)
874 return (element < EL_CONVEYOR_BELT_2_LEFT_ACTIVE ? 0 :
875 element < EL_CONVEYOR_BELT_3_LEFT_ACTIVE ? 1 :
876 element < EL_CONVEYOR_BELT_4_LEFT_ACTIVE ? 2 : 3);
879 static int getBeltNrFromBeltSwitchElement(int element)
881 return (element < EL_CONVEYOR_BELT_2_SWITCH_LEFT ? 0 :
882 element < EL_CONVEYOR_BELT_3_SWITCH_LEFT ? 1 :
883 element < EL_CONVEYOR_BELT_4_SWITCH_LEFT ? 2 : 3);
886 static int getBeltDirNrFromBeltSwitchElement(int element)
888 static int belt_base_element[4] =
890 EL_CONVEYOR_BELT_1_SWITCH_LEFT,
891 EL_CONVEYOR_BELT_2_SWITCH_LEFT,
892 EL_CONVEYOR_BELT_3_SWITCH_LEFT,
893 EL_CONVEYOR_BELT_4_SWITCH_LEFT
896 int belt_nr = getBeltNrFromBeltSwitchElement(element);
897 int belt_dir_nr = element - belt_base_element[belt_nr];
899 return (belt_dir_nr % 3);
902 static int getBeltDirFromBeltSwitchElement(int element)
904 static int belt_move_dir[3] =
911 int belt_dir_nr = getBeltDirNrFromBeltSwitchElement(element);
913 return belt_move_dir[belt_dir_nr];
916 static int get_element_from_group_element(int element)
918 if (IS_GROUP_ELEMENT(element))
920 struct ElementGroupInfo *group = element_info[element].group;
921 int last_anim_random_frame = gfx.anim_random_frame;
924 if (group->choice_mode == ANIM_RANDOM)
925 gfx.anim_random_frame = RND(group->num_elements_resolved);
927 element_pos = getAnimationFrame(group->num_elements_resolved, 1,
928 group->choice_mode, 0,
931 if (group->choice_mode == ANIM_RANDOM)
932 gfx.anim_random_frame = last_anim_random_frame;
936 element = group->element_resolved[element_pos];
942 static void InitPlayerField(int x, int y, int element, boolean init_game)
944 if (element == EL_SP_MURPHY)
948 if (stored_player[0].present)
950 Feld[x][y] = EL_SP_MURPHY_CLONE;
956 stored_player[0].use_murphy = TRUE;
958 if (!level.use_artwork_element[0])
959 stored_player[0].artwork_element = EL_SP_MURPHY;
962 Feld[x][y] = EL_PLAYER_1;
968 struct PlayerInfo *player = &stored_player[Feld[x][y] - EL_PLAYER_1];
969 int jx = player->jx, jy = player->jy;
971 player->present = TRUE;
973 player->block_last_field = (element == EL_SP_MURPHY ?
974 level.sp_block_last_field :
975 level.block_last_field);
977 /* ---------- initialize player's last field block delay --------------- */
979 /* always start with reliable default value (no adjustment needed) */
980 player->block_delay_adjustment = 0;
982 /* special case 1: in Supaplex, Murphy blocks last field one more frame */
983 if (player->block_last_field && element == EL_SP_MURPHY)
984 player->block_delay_adjustment = 1;
986 /* special case 2: in game engines before 3.1.1, blocking was different */
987 if (game.use_block_last_field_bug)
988 player->block_delay_adjustment = (player->block_last_field ? -1 : 1);
990 if (!options.network || player->connected)
992 player->active = TRUE;
994 /* remove potentially duplicate players */
995 if (StorePlayer[jx][jy] == Feld[x][y])
996 StorePlayer[jx][jy] = 0;
998 StorePlayer[x][y] = Feld[x][y];
1002 printf("Player %d activated.\n", player->element_nr);
1003 printf("[Local player is %d and currently %s.]\n",
1004 local_player->element_nr,
1005 local_player->active ? "active" : "not active");
1009 Feld[x][y] = EL_EMPTY;
1011 player->jx = player->last_jx = x;
1012 player->jy = player->last_jy = y;
1016 static void InitField(int x, int y, boolean init_game)
1018 int element = Feld[x][y];
1027 InitPlayerField(x, y, element, init_game);
1030 case EL_SOKOBAN_FIELD_PLAYER:
1031 element = Feld[x][y] = EL_PLAYER_1;
1032 InitField(x, y, init_game);
1034 element = Feld[x][y] = EL_SOKOBAN_FIELD_EMPTY;
1035 InitField(x, y, init_game);
1038 case EL_SOKOBAN_FIELD_EMPTY:
1039 local_player->sokobanfields_still_needed++;
1043 if (x < lev_fieldx-1 && Feld[x+1][y] == EL_ACID)
1044 Feld[x][y] = EL_ACID_POOL_TOPLEFT;
1045 else if (x > 0 && Feld[x-1][y] == EL_ACID)
1046 Feld[x][y] = EL_ACID_POOL_TOPRIGHT;
1047 else if (y > 0 && Feld[x][y-1] == EL_ACID_POOL_TOPLEFT)
1048 Feld[x][y] = EL_ACID_POOL_BOTTOMLEFT;
1049 else if (y > 0 && Feld[x][y-1] == EL_ACID)
1050 Feld[x][y] = EL_ACID_POOL_BOTTOM;
1051 else if (y > 0 && Feld[x][y-1] == EL_ACID_POOL_TOPRIGHT)
1052 Feld[x][y] = EL_ACID_POOL_BOTTOMRIGHT;
1061 case EL_SPACESHIP_RIGHT:
1062 case EL_SPACESHIP_UP:
1063 case EL_SPACESHIP_LEFT:
1064 case EL_SPACESHIP_DOWN:
1065 case EL_BD_BUTTERFLY:
1066 case EL_BD_BUTTERFLY_RIGHT:
1067 case EL_BD_BUTTERFLY_UP:
1068 case EL_BD_BUTTERFLY_LEFT:
1069 case EL_BD_BUTTERFLY_DOWN:
1071 case EL_BD_FIREFLY_RIGHT:
1072 case EL_BD_FIREFLY_UP:
1073 case EL_BD_FIREFLY_LEFT:
1074 case EL_BD_FIREFLY_DOWN:
1075 case EL_PACMAN_RIGHT:
1077 case EL_PACMAN_LEFT:
1078 case EL_PACMAN_DOWN:
1080 case EL_YAMYAM_LEFT:
1081 case EL_YAMYAM_RIGHT:
1083 case EL_YAMYAM_DOWN:
1084 case EL_DARK_YAMYAM:
1087 case EL_SP_SNIKSNAK:
1088 case EL_SP_ELECTRON:
1097 case EL_AMOEBA_FULL:
1102 case EL_AMOEBA_DROP:
1103 if (y == lev_fieldy - 1)
1105 Feld[x][y] = EL_AMOEBA_GROWING;
1106 Store[x][y] = EL_AMOEBA_WET;
1110 case EL_DYNAMITE_ACTIVE:
1111 case EL_SP_DISK_RED_ACTIVE:
1112 case EL_DYNABOMB_PLAYER_1_ACTIVE:
1113 case EL_DYNABOMB_PLAYER_2_ACTIVE:
1114 case EL_DYNABOMB_PLAYER_3_ACTIVE:
1115 case EL_DYNABOMB_PLAYER_4_ACTIVE:
1116 MovDelay[x][y] = 96;
1119 case EL_EM_DYNAMITE_ACTIVE:
1120 MovDelay[x][y] = 32;
1124 local_player->lights_still_needed++;
1128 local_player->friends_still_needed++;
1133 GfxDir[x][y] = MovDir[x][y] = 1 << RND(4);
1136 case EL_CONVEYOR_BELT_1_SWITCH_LEFT:
1137 case EL_CONVEYOR_BELT_1_SWITCH_MIDDLE:
1138 case EL_CONVEYOR_BELT_1_SWITCH_RIGHT:
1139 case EL_CONVEYOR_BELT_2_SWITCH_LEFT:
1140 case EL_CONVEYOR_BELT_2_SWITCH_MIDDLE:
1141 case EL_CONVEYOR_BELT_2_SWITCH_RIGHT:
1142 case EL_CONVEYOR_BELT_3_SWITCH_LEFT:
1143 case EL_CONVEYOR_BELT_3_SWITCH_MIDDLE:
1144 case EL_CONVEYOR_BELT_3_SWITCH_RIGHT:
1145 case EL_CONVEYOR_BELT_4_SWITCH_LEFT:
1146 case EL_CONVEYOR_BELT_4_SWITCH_MIDDLE:
1147 case EL_CONVEYOR_BELT_4_SWITCH_RIGHT:
1150 int belt_nr = getBeltNrFromBeltSwitchElement(Feld[x][y]);
1151 int belt_dir = getBeltDirFromBeltSwitchElement(Feld[x][y]);
1152 int belt_dir_nr = getBeltDirNrFromBeltSwitchElement(Feld[x][y]);
1154 if (game.belt_dir_nr[belt_nr] == 3) /* initial value */
1156 game.belt_dir[belt_nr] = belt_dir;
1157 game.belt_dir_nr[belt_nr] = belt_dir_nr;
1159 else /* more than one switch -- set it like the first switch */
1161 Feld[x][y] = Feld[x][y] - belt_dir_nr + game.belt_dir_nr[belt_nr];
1166 #if !USE_BOTH_SWITCHGATE_SWITCHES
1167 case EL_SWITCHGATE_SWITCH_DOWN: /* always start with same switch pos */
1169 Feld[x][y] = EL_SWITCHGATE_SWITCH_UP;
1173 case EL_LIGHT_SWITCH_ACTIVE:
1175 game.light_time_left = level.time_light * FRAMES_PER_SECOND;
1178 case EL_INVISIBLE_STEELWALL:
1179 case EL_INVISIBLE_WALL:
1180 case EL_INVISIBLE_SAND:
1181 if (game.light_time_left > 0 ||
1182 game.lenses_time_left > 0)
1183 Feld[x][y] = getInvisibleActiveFromInvisibleElement(element);
1186 case EL_EMC_MAGIC_BALL:
1187 if (game.ball_state)
1188 Feld[x][y] = EL_EMC_MAGIC_BALL_ACTIVE;
1191 case EL_EMC_MAGIC_BALL_SWITCH:
1192 if (game.ball_state)
1193 Feld[x][y] = EL_EMC_MAGIC_BALL_SWITCH_ACTIVE;
1198 if (IS_CUSTOM_ELEMENT(element))
1200 if (CAN_MOVE(element))
1203 #if USE_NEW_CUSTOM_VALUE
1204 if (!element_info[element].use_last_ce_value || init_game)
1205 CustomValue[x][y] = GET_NEW_CE_VALUE(Feld[x][y]);
1209 if (IS_CUSTOM_ELEMENT(element) && CAN_MOVE(element))
1212 else if (IS_GROUP_ELEMENT(element))
1215 Feld[x][y] = get_element_from_group_element(element);
1217 InitField(x, y, init_game);
1219 struct ElementGroupInfo *group = element_info[element].group;
1220 int last_anim_random_frame = gfx.anim_random_frame;
1223 if (group->choice_mode == ANIM_RANDOM)
1224 gfx.anim_random_frame = RND(group->num_elements_resolved);
1226 element_pos = getAnimationFrame(group->num_elements_resolved, 1,
1227 group->choice_mode, 0,
1230 if (group->choice_mode == ANIM_RANDOM)
1231 gfx.anim_random_frame = last_anim_random_frame;
1233 group->choice_pos++;
1235 Feld[x][y] = group->element_resolved[element_pos];
1237 InitField(x, y, init_game);
1246 CheckTriggeredElementChange(x, y, element, CE_CREATION_OF_X);
1251 #if USE_NEW_CUSTOM_VALUE
1254 CustomValue[x][y] = GET_NEW_CE_VALUE(Feld[x][y]);
1256 CustomValue[x][y] = element_info[Feld[x][y]].custom_value_initial;
1264 static inline void InitField_WithBug1(int x, int y, boolean init_game)
1266 InitField(x, y, init_game);
1268 /* not needed to call InitMovDir() -- already done by InitField()! */
1269 if (game.engine_version < VERSION_IDENT(3,1,0,0) &&
1270 CAN_MOVE(Feld[x][y]))
1274 static inline void InitField_WithBug2(int x, int y, boolean init_game)
1276 int old_element = Feld[x][y];
1278 InitField(x, y, init_game);
1280 /* not needed to call InitMovDir() -- already done by InitField()! */
1281 if (game.engine_version < VERSION_IDENT(3,1,0,0) &&
1282 CAN_MOVE(old_element) &&
1283 (old_element < EL_MOLE_LEFT || old_element > EL_MOLE_DOWN))
1286 /* this case is in fact a combination of not less than three bugs:
1287 first, it calls InitMovDir() for elements that can move, although this is
1288 already done by InitField(); then, it checks the element that was at this
1289 field _before_ the call to InitField() (which can change it); lastly, it
1290 was not called for "mole with direction" elements, which were treated as
1291 "cannot move" due to (fixed) wrong element initialization in "src/init.c"
1295 inline void DrawGameValue_Emeralds(int value)
1297 int xpos = (3 * 14 - 3 * getFontWidth(FONT_TEXT_2)) / 2;
1299 if (PANEL_DEACTIVATED(game.panel.gems))
1302 DrawText(DX_EMERALDS + xpos, DY_EMERALDS, int2str(value, 3), FONT_TEXT_2);
1305 inline void DrawGameValue_Dynamite(int value)
1307 int xpos = (3 * 14 - 3 * getFontWidth(FONT_TEXT_2)) / 2;
1309 if (PANEL_DEACTIVATED(game.panel.inventory))
1312 DrawText(DX_DYNAMITE + xpos, DY_DYNAMITE, int2str(value, 3), FONT_TEXT_2);
1315 inline void DrawGameValue_Keys(int key[MAX_NUM_KEYS])
1317 int base_key_graphic = EL_KEY_1;
1320 if (PANEL_DEACTIVATED(game.panel.keys))
1323 if (level.game_engine_type == GAME_ENGINE_TYPE_EM)
1324 base_key_graphic = EL_EM_KEY_1;
1326 /* currently only 4 of 8 possible keys are displayed */
1327 for (i = 0; i < STD_NUM_KEYS; i++)
1329 int x = XX_KEYS + i * MINI_TILEX;
1333 DrawMiniGraphicExt(drawto, DX + x,DY + y, el2edimg(base_key_graphic + i));
1335 BlitBitmap(graphic_info[IMG_GLOBAL_DOOR].bitmap, drawto,
1336 DOOR_GFX_PAGEX5 + x, y, MINI_TILEX, MINI_TILEY, DX + x,DY + y);
1340 inline void DrawGameValue_Score(int value)
1342 int xpos = (5 * 14 - 5 * getFontWidth(FONT_TEXT_2)) / 2;
1344 if (PANEL_DEACTIVATED(game.panel.score))
1347 DrawText(DX_SCORE + xpos, DY_SCORE, int2str(value, 5), FONT_TEXT_2);
1350 inline void DrawGameValue_Time(int value)
1352 int xpos3 = (3 * 14 - 3 * getFontWidth(FONT_TEXT_2)) / 2;
1353 int xpos4 = (4 * 10 - 4 * getFontWidth(FONT_LEVEL_NUMBER)) / 2;
1355 if (PANEL_DEACTIVATED(game.panel.time))
1358 /* clear background if value just changed its size */
1359 if (value == 999 || value == 1000)
1360 ClearRectangleOnBackground(drawto, DX_TIME1, DY_TIME, 14 * 3, 14);
1363 DrawText(DX_TIME1 + xpos3, DY_TIME, int2str(value, 3), FONT_TEXT_2);
1365 DrawText(DX_TIME2 + xpos4, DY_TIME, int2str(value, 4), FONT_LEVEL_NUMBER);
1368 inline void DrawGameValue_Level(int value)
1370 if (PANEL_DEACTIVATED(game.panel.level))
1374 DrawText(DX_LEVEL1, DY_LEVEL, int2str(value, 2), FONT_TEXT_2);
1377 DrawText(DX_LEVEL2, DY_LEVEL, int2str(value, 3), FONT_LEVEL_NUMBER);
1380 /* misuse area for displaying emeralds to draw bigger level number */
1381 DrawTextExt(drawto, DX_EMERALDS, DY_EMERALDS,
1382 int2str(value, 3), FONT_LEVEL_NUMBER, BLIT_OPAQUE);
1384 /* now copy it to the area for displaying level number */
1385 BlitBitmap(drawto, drawto,
1386 DX_EMERALDS, DY_EMERALDS + 1,
1387 getFontWidth(FONT_LEVEL_NUMBER) * 3,
1388 getFontHeight(FONT_LEVEL_NUMBER) - 1,
1389 DX_LEVEL - 1, DY_LEVEL + 1);
1391 /* restore the area for displaying emeralds */
1392 DrawGameValue_Emeralds(local_player->gems_still_needed);
1394 /* yes, this is all really ugly :-) */
1399 void DrawAllGameValues(int emeralds, int dynamite, int score, int time,
1402 int key[MAX_NUM_KEYS];
1405 for (i = 0; i < MAX_NUM_KEYS; i++)
1406 key[i] = key_bits & (1 << i);
1408 DrawGameValue_Level(level_nr);
1410 DrawGameValue_Emeralds(emeralds);
1411 DrawGameValue_Dynamite(dynamite);
1412 DrawGameValue_Score(score);
1413 DrawGameValue_Time(time);
1415 DrawGameValue_Keys(key);
1418 void DrawGameDoorValues()
1420 int time_value = (level.time == 0 ? TimePlayed : TimeLeft);
1421 int dynamite_state = 0;
1425 if (level.game_engine_type == GAME_ENGINE_TYPE_EM)
1427 DrawGameDoorValues_EM();
1433 DrawGameValue_Level(level_nr);
1435 DrawGameValue_Emeralds(local_player->gems_still_needed);
1436 DrawGameValue_Dynamite(local_player->inventory_size);
1437 DrawGameValue_Score(local_player->score);
1438 DrawGameValue_Time(TimeLeft);
1442 if (game.centered_player_nr == -1)
1444 for (i = 0; i < MAX_PLAYERS; i++)
1446 for (j = 0; j < MAX_NUM_KEYS; j++)
1447 if (stored_player[i].key[j])
1448 key_bits |= (1 << j);
1450 dynamite_state += stored_player[i].inventory_size;
1454 DrawGameValue_Keys(stored_player[i].key);
1459 int player_nr = game.centered_player_nr;
1461 for (i = 0; i < MAX_NUM_KEYS; i++)
1462 if (stored_player[player_nr].key[i])
1463 key_bits |= (1 << i);
1465 dynamite_state = stored_player[player_nr].inventory_size;
1468 DrawAllGameValues(local_player->gems_still_needed, dynamite_state,
1469 local_player->score, time_value, key_bits);
1474 static void resolve_group_element(int group_element, int recursion_depth)
1476 static int group_nr;
1477 static struct ElementGroupInfo *group;
1478 struct ElementGroupInfo *actual_group = element_info[group_element].group;
1481 if (recursion_depth > NUM_GROUP_ELEMENTS) /* recursion too deep */
1483 Error(ERR_WARN, "recursion too deep when resolving group element %d",
1484 group_element - EL_GROUP_START + 1);
1486 /* replace element which caused too deep recursion by question mark */
1487 group->element_resolved[group->num_elements_resolved++] = EL_UNKNOWN;
1492 if (recursion_depth == 0) /* initialization */
1494 group = element_info[group_element].group;
1495 group_nr = group_element - EL_GROUP_START;
1497 group->num_elements_resolved = 0;
1498 group->choice_pos = 0;
1501 for (i = 0; i < actual_group->num_elements; i++)
1503 int element = actual_group->element[i];
1505 if (group->num_elements_resolved == NUM_FILE_ELEMENTS)
1508 if (IS_GROUP_ELEMENT(element))
1509 resolve_group_element(element, recursion_depth + 1);
1512 group->element_resolved[group->num_elements_resolved++] = element;
1513 element_info[element].in_group[group_nr] = TRUE;
1520 static void replace_reference_element(int base_element, int *element)
1522 if (*element >= EL_LAST_CE_8 && *element <= EL_NEXT_CE_8)
1524 *element = base_element + *element - EL_SELF;
1525 *element = (*element < EL_CUSTOM_START ? EL_CUSTOM_START :
1526 *element > EL_CUSTOM_END ? EL_CUSTOM_END : *element);
1532 =============================================================================
1534 -----------------------------------------------------------------------------
1535 initialize game engine due to level / tape version number
1536 =============================================================================
1539 static void InitGameEngine()
1541 int i, j, k, l, x, y;
1543 /* set game engine from tape file when re-playing, else from level file */
1544 game.engine_version = (tape.playing ? tape.engine_version :
1545 level.game_version);
1547 /* ---------------------------------------------------------------------- */
1548 /* set flags for bugs and changes according to active game engine version */
1549 /* ---------------------------------------------------------------------- */
1552 Summary of bugfix/change:
1553 Fixed handling for custom elements that change when pushed by the player.
1555 Fixed/changed in version:
1559 Before 3.1.0, custom elements that "change when pushing" changed directly
1560 after the player started pushing them (until then handled in "DigField()").
1561 Since 3.1.0, these custom elements are not changed until the "pushing"
1562 move of the element is finished (now handled in "ContinueMoving()").
1564 Affected levels/tapes:
1565 The first condition is generally needed for all levels/tapes before version
1566 3.1.0, which might use the old behaviour before it was changed; known tapes
1567 that are affected are some tapes from the level set "Walpurgis Gardens" by
1569 The second condition is an exception from the above case and is needed for
1570 the special case of tapes recorded with game (not engine!) version 3.1.0 or
1571 above (including some development versions of 3.1.0), but before it was
1572 known that this change would break tapes like the above and was fixed in
1573 3.1.1, so that the changed behaviour was active although the engine version
1574 while recording maybe was before 3.1.0. There is at least one tape that is
1575 affected by this exception, which is the tape for the one-level set "Bug
1576 Machine" by Juergen Bonhagen.
1579 game.use_change_when_pushing_bug =
1580 (game.engine_version < VERSION_IDENT(3,1,0,0) &&
1582 tape.game_version >= VERSION_IDENT(3,1,0,0) &&
1583 tape.game_version < VERSION_IDENT(3,1,1,0)));
1586 Summary of bugfix/change:
1587 Fixed handling for blocking the field the player leaves when moving.
1589 Fixed/changed in version:
1593 Before 3.1.1, when "block last field when moving" was enabled, the field
1594 the player is leaving when moving was blocked for the time of the move,
1595 and was directly unblocked afterwards. This resulted in the last field
1596 being blocked for exactly one less than the number of frames of one player
1597 move. Additionally, even when blocking was disabled, the last field was
1598 blocked for exactly one frame.
1599 Since 3.1.1, due to changes in player movement handling, the last field
1600 is not blocked at all when blocking is disabled. When blocking is enabled,
1601 the last field is blocked for exactly the number of frames of one player
1602 move. Additionally, if the player is Murphy, the hero of Supaplex, the
1603 last field is blocked for exactly one more than the number of frames of
1606 Affected levels/tapes:
1607 (!!! yet to be determined -- probably many !!!)
1610 game.use_block_last_field_bug =
1611 (game.engine_version < VERSION_IDENT(3,1,1,0));
1614 Summary of bugfix/change:
1615 Changed behaviour of CE changes with multiple changes per single frame.
1617 Fixed/changed in version:
1621 Before 3.2.0-6, only one single CE change was allowed in each engine frame.
1622 This resulted in race conditions where CEs seem to behave strange in some
1623 situations (where triggered CE changes were just skipped because there was
1624 already a CE change on that tile in the playfield in that engine frame).
1625 Since 3.2.0-6, this was changed to allow up to MAX_NUM_CHANGES_PER_FRAME.
1626 (The number of changes per frame must be limited in any case, because else
1627 it is easily possible to define CE changes that would result in an infinite
1628 loop, causing the whole game to freeze. The MAX_NUM_CHANGES_PER_FRAME value
1629 should be set large enough so that it would only be reached in cases where
1630 the corresponding CE change conditions run into a loop. Therefore, it seems
1631 to be reasonable to set MAX_NUM_CHANGES_PER_FRAME to the same value as the
1632 maximal number of change pages for custom elements.)
1634 Affected levels/tapes:
1638 #if USE_ONLY_ONE_CHANGE_PER_FRAME
1639 game.max_num_changes_per_frame = 1;
1641 game.max_num_changes_per_frame =
1642 (game.engine_version < VERSION_IDENT(3,2,0,6) ? 1 : 32);
1645 /* ---------------------------------------------------------------------- */
1647 /* default scan direction: scan playfield from top/left to bottom/right */
1648 InitPlayfieldScanMode(CA_ARG_SCAN_MODE_NORMAL);
1650 /* dynamically adjust element properties according to game engine version */
1651 InitElementPropertiesEngine(game.engine_version);
1654 printf("level %d: level version == %06d\n", level_nr, level.game_version);
1655 printf(" tape version == %06d [%s] [file: %06d]\n",
1656 tape.engine_version, (tape.playing ? "PLAYING" : "RECORDING"),
1658 printf(" => game.engine_version == %06d\n", game.engine_version);
1662 /* ---------- recursively resolve group elements ------------------------- */
1664 for (i = 0; i < MAX_NUM_ELEMENTS; i++)
1665 for (j = 0; j < NUM_GROUP_ELEMENTS; j++)
1666 element_info[i].in_group[j] = FALSE;
1668 for (i = 0; i < NUM_GROUP_ELEMENTS; i++)
1669 resolve_group_element(EL_GROUP_START + i, 0);
1672 /* ---------- initialize player's initial move delay --------------------- */
1675 /* dynamically adjust player properties according to level information */
1676 for (i = 0; i < MAX_PLAYERS; i++)
1677 game.initial_move_delay_value[i] =
1678 get_move_delay_from_stepsize(level.initial_player_stepsize[i]);
1680 /* dynamically adjust player properties according to level information */
1681 game.initial_move_delay_value =
1682 (level.double_speed ? MOVE_DELAY_HIGH_SPEED : MOVE_DELAY_NORMAL_SPEED);
1685 /* dynamically adjust player properties according to game engine version */
1686 for (i = 0; i < MAX_PLAYERS; i++)
1687 game.initial_move_delay[i] =
1688 (game.engine_version <= VERSION_IDENT(2,0,1,0) ?
1689 game.initial_move_delay_value[i] : 0);
1691 /* ---------- initialize player's initial push delay --------------------- */
1693 /* dynamically adjust player properties according to game engine version */
1694 game.initial_push_delay_value =
1695 (game.engine_version < VERSION_IDENT(3,0,7,1) ? 5 : -1);
1697 /* ---------- initialize changing elements ------------------------------- */
1699 /* initialize changing elements information */
1700 for (i = 0; i < MAX_NUM_ELEMENTS; i++)
1702 struct ElementInfo *ei = &element_info[i];
1704 /* this pointer might have been changed in the level editor */
1705 ei->change = &ei->change_page[0];
1707 if (!IS_CUSTOM_ELEMENT(i))
1709 ei->change->target_element = EL_EMPTY_SPACE;
1710 ei->change->delay_fixed = 0;
1711 ei->change->delay_random = 0;
1712 ei->change->delay_frames = 1;
1715 for (j = 0; j < NUM_CHANGE_EVENTS; j++)
1717 ei->has_change_event[j] = FALSE;
1719 ei->event_page_nr[j] = 0;
1720 ei->event_page[j] = &ei->change_page[0];
1724 /* add changing elements from pre-defined list */
1725 for (i = 0; change_delay_list[i].element != EL_UNDEFINED; i++)
1727 struct ChangingElementInfo *ch_delay = &change_delay_list[i];
1728 struct ElementInfo *ei = &element_info[ch_delay->element];
1730 ei->change->target_element = ch_delay->target_element;
1731 ei->change->delay_fixed = ch_delay->change_delay;
1733 ei->change->pre_change_function = ch_delay->pre_change_function;
1734 ei->change->change_function = ch_delay->change_function;
1735 ei->change->post_change_function = ch_delay->post_change_function;
1737 ei->change->can_change = TRUE;
1738 ei->change->can_change_or_has_action = TRUE;
1740 ei->has_change_event[CE_DELAY] = TRUE;
1742 SET_PROPERTY(ch_delay->element, EP_CAN_CHANGE, TRUE);
1743 SET_PROPERTY(ch_delay->element, EP_CAN_CHANGE_OR_HAS_ACTION, TRUE);
1746 /* ---------- initialize internal run-time variables ------------- */
1748 for (i = 0; i < NUM_CUSTOM_ELEMENTS; i++)
1750 struct ElementInfo *ei = &element_info[EL_CUSTOM_START + i];
1752 for (j = 0; j < ei->num_change_pages; j++)
1754 ei->change_page[j].can_change_or_has_action =
1755 (ei->change_page[j].can_change |
1756 ei->change_page[j].has_action);
1760 /* add change events from custom element configuration */
1761 for (i = 0; i < NUM_CUSTOM_ELEMENTS; i++)
1763 struct ElementInfo *ei = &element_info[EL_CUSTOM_START + i];
1765 for (j = 0; j < ei->num_change_pages; j++)
1767 if (!ei->change_page[j].can_change_or_has_action)
1770 for (k = 0; k < NUM_CHANGE_EVENTS; k++)
1772 /* only add event page for the first page found with this event */
1773 if (ei->change_page[j].has_event[k] && !(ei->has_change_event[k]))
1775 ei->has_change_event[k] = TRUE;
1777 ei->event_page_nr[k] = j;
1778 ei->event_page[k] = &ei->change_page[j];
1784 /* ---------- initialize run-time trigger player and element ------------- */
1786 for (i = 0; i < NUM_CUSTOM_ELEMENTS; i++)
1788 struct ElementInfo *ei = &element_info[EL_CUSTOM_START + i];
1790 for (j = 0; j < ei->num_change_pages; j++)
1792 ei->change_page[j].actual_trigger_element = EL_EMPTY;
1793 ei->change_page[j].actual_trigger_player = EL_PLAYER_1;
1794 ei->change_page[j].actual_trigger_side = CH_SIDE_NONE;
1795 ei->change_page[j].actual_trigger_ce_value = 0;
1796 ei->change_page[j].actual_trigger_ce_score = 0;
1800 /* ---------- initialize trigger events ---------------------------------- */
1802 /* initialize trigger events information */
1803 for (i = 0; i < MAX_NUM_ELEMENTS; i++)
1804 for (j = 0; j < NUM_CHANGE_EVENTS; j++)
1805 trigger_events[i][j] = FALSE;
1807 /* add trigger events from element change event properties */
1808 for (i = 0; i < MAX_NUM_ELEMENTS; i++)
1810 struct ElementInfo *ei = &element_info[i];
1812 for (j = 0; j < ei->num_change_pages; j++)
1814 if (!ei->change_page[j].can_change_or_has_action)
1817 if (ei->change_page[j].has_event[CE_BY_OTHER_ACTION])
1819 int trigger_element = ei->change_page[j].trigger_element;
1821 for (k = 0; k < NUM_CHANGE_EVENTS; k++)
1823 if (ei->change_page[j].has_event[k])
1825 if (IS_GROUP_ELEMENT(trigger_element))
1827 struct ElementGroupInfo *group =
1828 element_info[trigger_element].group;
1830 for (l = 0; l < group->num_elements_resolved; l++)
1831 trigger_events[group->element_resolved[l]][k] = TRUE;
1834 else if (trigger_element == EL_ANY_ELEMENT)
1835 for (l = 0; l < MAX_NUM_ELEMENTS; l++)
1836 trigger_events[l][k] = TRUE;
1839 trigger_events[trigger_element][k] = TRUE;
1846 /* ---------- initialize push delay -------------------------------------- */
1848 /* initialize push delay values to default */
1849 for (i = 0; i < MAX_NUM_ELEMENTS; i++)
1851 if (!IS_CUSTOM_ELEMENT(i))
1854 /* set default push delay values (corrected since version 3.0.7-1) */
1855 if (game.engine_version < VERSION_IDENT(3,0,7,1))
1857 element_info[i].push_delay_fixed = 2;
1858 element_info[i].push_delay_random = 8;
1862 element_info[i].push_delay_fixed = 8;
1863 element_info[i].push_delay_random = 8;
1866 element_info[i].push_delay_fixed = game.default_push_delay_fixed;
1867 element_info[i].push_delay_random = game.default_push_delay_random;
1872 /* set push delay value for certain elements from pre-defined list */
1873 for (i = 0; push_delay_list[i].element != EL_UNDEFINED; i++)
1875 int e = push_delay_list[i].element;
1877 element_info[e].push_delay_fixed = push_delay_list[i].push_delay_fixed;
1878 element_info[e].push_delay_random = push_delay_list[i].push_delay_random;
1881 /* set push delay value for Supaplex elements for newer engine versions */
1882 if (game.engine_version >= VERSION_IDENT(3,1,0,0))
1884 for (i = 0; i < MAX_NUM_ELEMENTS; i++)
1886 if (IS_SP_ELEMENT(i))
1888 /* set SP push delay to just enough to push under a falling zonk */
1889 int delay = (game.engine_version >= VERSION_IDENT(3,1,1,0) ? 8 : 6);
1891 element_info[i].push_delay_fixed = delay;
1892 element_info[i].push_delay_random = 0;
1897 /* ---------- initialize move stepsize ----------------------------------- */
1899 /* initialize move stepsize values to default */
1900 for (i = 0; i < MAX_NUM_ELEMENTS; i++)
1901 if (!IS_CUSTOM_ELEMENT(i))
1902 element_info[i].move_stepsize = MOVE_STEPSIZE_NORMAL;
1904 /* set move stepsize value for certain elements from pre-defined list */
1905 for (i = 0; move_stepsize_list[i].element != EL_UNDEFINED; i++)
1907 int e = move_stepsize_list[i].element;
1909 element_info[e].move_stepsize = move_stepsize_list[i].move_stepsize;
1912 /* ---------- initialize collect score ----------------------------------- */
1914 /* initialize collect score values for custom elements from initial value */
1915 for (i = 0; i < MAX_NUM_ELEMENTS; i++)
1916 if (IS_CUSTOM_ELEMENT(i))
1917 element_info[i].collect_score = element_info[i].collect_score_initial;
1919 /* ---------- initialize collect count ----------------------------------- */
1921 /* initialize collect count values for non-custom elements */
1922 for (i = 0; i < MAX_NUM_ELEMENTS; i++)
1923 if (!IS_CUSTOM_ELEMENT(i))
1924 element_info[i].collect_count_initial = 0;
1926 /* add collect count values for all elements from pre-defined list */
1927 for (i = 0; collect_count_list[i].element != EL_UNDEFINED; i++)
1928 element_info[collect_count_list[i].element].collect_count_initial =
1929 collect_count_list[i].count;
1931 /* ---------- initialize access direction -------------------------------- */
1933 /* initialize access direction values to default (access from every side) */
1934 for (i = 0; i < MAX_NUM_ELEMENTS; i++)
1935 if (!IS_CUSTOM_ELEMENT(i))
1936 element_info[i].access_direction = MV_ALL_DIRECTIONS;
1938 /* set access direction value for certain elements from pre-defined list */
1939 for (i = 0; access_direction_list[i].element != EL_UNDEFINED; i++)
1940 element_info[access_direction_list[i].element].access_direction =
1941 access_direction_list[i].direction;
1943 /* ---------- initialize explosion content ------------------------------- */
1944 for (i = 0; i < MAX_NUM_ELEMENTS; i++)
1946 if (IS_CUSTOM_ELEMENT(i))
1949 for (y = 0; y < 3; y++) for (x = 0; x < 3; x++)
1951 /* (content for EL_YAMYAM set at run-time with game.yamyam_content_nr) */
1953 element_info[i].content.e[x][y] =
1954 (i == EL_PLAYER_1 ? EL_EMERALD_YELLOW :
1955 i == EL_PLAYER_2 ? EL_EMERALD_RED :
1956 i == EL_PLAYER_3 ? EL_EMERALD :
1957 i == EL_PLAYER_4 ? EL_EMERALD_PURPLE :
1958 i == EL_MOLE ? EL_EMERALD_RED :
1959 i == EL_PENGUIN ? EL_EMERALD_PURPLE :
1960 i == EL_BUG ? (x == 1 && y == 1 ? EL_DIAMOND : EL_EMERALD) :
1961 i == EL_BD_BUTTERFLY ? EL_BD_DIAMOND :
1962 i == EL_SP_ELECTRON ? EL_SP_INFOTRON :
1963 i == EL_AMOEBA_TO_DIAMOND ? level.amoeba_content :
1964 i == EL_WALL_EMERALD ? EL_EMERALD :
1965 i == EL_WALL_DIAMOND ? EL_DIAMOND :
1966 i == EL_WALL_BD_DIAMOND ? EL_BD_DIAMOND :
1967 i == EL_WALL_EMERALD_YELLOW ? EL_EMERALD_YELLOW :
1968 i == EL_WALL_EMERALD_RED ? EL_EMERALD_RED :
1969 i == EL_WALL_EMERALD_PURPLE ? EL_EMERALD_PURPLE :
1970 i == EL_WALL_PEARL ? EL_PEARL :
1971 i == EL_WALL_CRYSTAL ? EL_CRYSTAL :
1977 /* ---------- initialize reference elements ------------------------------- */
1978 for (i = 0; i < NUM_CUSTOM_ELEMENTS; i++)
1980 int element = EL_CUSTOM_START + i;
1981 struct ElementInfo *ei = &element_info[element];
1983 for (y = 0; y < 3; y++) for (x = 0; x < 3; x++)
1984 replace_reference_element(element, &ei->content.e[x][y]);
1986 for (j = 0; j < ei->num_change_pages; j++)
1988 struct ElementChangeInfo *change = &ei->change_page[j];
1990 replace_reference_element(element, &change->target_element);
1991 replace_reference_element(element, &change->trigger_element);
1993 for (y = 0; y < 3; y++) for (x = 0; x < 3; x++)
1994 replace_reference_element(element, &change->target_content.e[x][y]);
2000 int get_num_special_action(int element, int action_first, int action_last)
2002 int num_special_action = 0;
2005 for (i = action_first; i <= action_last; i++)
2007 boolean found = FALSE;
2009 for (j = 0; j < NUM_DIRECTIONS; j++)
2010 if (el_act_dir2img(element, i, j) !=
2011 el_act_dir2img(element, ACTION_DEFAULT, j))
2015 num_special_action++;
2021 printf("::: %d->%d: %d\n", action_first, action_last, num_special_action);
2024 return num_special_action;
2028 =============================================================================
2030 -----------------------------------------------------------------------------
2031 initialize and start new game
2032 =============================================================================
2037 boolean emulate_bd = TRUE; /* unless non-BOULDERDASH elements found */
2038 boolean emulate_sb = TRUE; /* unless non-SOKOBAN elements found */
2039 boolean emulate_sp = TRUE; /* unless non-SUPAPLEX elements found */
2044 /* don't play tapes over network */
2045 network_playing = (options.network && !tape.playing);
2047 for (i = 0; i < MAX_PLAYERS; i++)
2049 struct PlayerInfo *player = &stored_player[i];
2051 player->index_nr = i;
2052 player->index_bit = (1 << i);
2053 player->element_nr = EL_PLAYER_1 + i;
2055 player->present = FALSE;
2056 player->active = FALSE;
2059 player->effective_action = 0;
2060 player->programmed_action = 0;
2063 player->gems_still_needed = level.gems_needed;
2064 player->sokobanfields_still_needed = 0;
2065 player->lights_still_needed = 0;
2066 player->friends_still_needed = 0;
2068 for (j = 0; j < MAX_NUM_KEYS; j++)
2069 player->key[j] = FALSE;
2071 player->dynabomb_count = 0;
2072 player->dynabomb_size = 1;
2073 player->dynabombs_left = 0;
2074 player->dynabomb_xl = FALSE;
2076 player->MovDir = MV_NONE;
2079 player->GfxDir = MV_NONE;
2080 player->GfxAction = ACTION_DEFAULT;
2082 player->StepFrame = 0;
2084 player->use_murphy = FALSE;
2085 player->artwork_element =
2086 (level.use_artwork_element[i] ? level.artwork_element[i] :
2087 player->element_nr);
2089 player->block_last_field = FALSE; /* initialized in InitPlayerField() */
2090 player->block_delay_adjustment = 0; /* initialized in InitPlayerField() */
2092 player->gravity = level.initial_player_gravity[i];
2094 player->can_fall_into_acid = CAN_MOVE_INTO_ACID(player->element_nr);
2096 player->actual_frame_counter = 0;
2098 player->step_counter = 0;
2100 player->last_move_dir = MV_NONE;
2102 player->is_active = FALSE;
2104 player->is_waiting = FALSE;
2105 player->is_moving = FALSE;
2106 player->is_auto_moving = FALSE;
2107 player->is_digging = FALSE;
2108 player->is_snapping = FALSE;
2109 player->is_collecting = FALSE;
2110 player->is_pushing = FALSE;
2111 player->is_switching = FALSE;
2112 player->is_dropping = FALSE;
2113 player->is_dropping_pressed = FALSE;
2115 player->is_bored = FALSE;
2116 player->is_sleeping = FALSE;
2118 player->frame_counter_bored = -1;
2119 player->frame_counter_sleeping = -1;
2121 player->anim_delay_counter = 0;
2122 player->post_delay_counter = 0;
2124 player->dir_waiting = MV_NONE;
2125 player->action_waiting = ACTION_DEFAULT;
2126 player->last_action_waiting = ACTION_DEFAULT;
2127 player->special_action_bored = ACTION_DEFAULT;
2128 player->special_action_sleeping = ACTION_DEFAULT;
2131 /* cannot be set here -- could be modified in Init[Player]Field() below */
2133 /* set number of special actions for bored and sleeping animation */
2134 player->num_special_action_bored =
2135 get_num_special_action(player->artwork_element,
2136 ACTION_BORING_1, ACTION_BORING_LAST);
2137 player->num_special_action_sleeping =
2138 get_num_special_action(player->artwork_element,
2139 ACTION_SLEEPING_1, ACTION_SLEEPING_LAST);
2142 player->switch_x = -1;
2143 player->switch_y = -1;
2145 player->drop_x = -1;
2146 player->drop_y = -1;
2148 player->show_envelope = 0;
2151 SetPlayerMoveSpeed(player, level.initial_player_stepsize[i], TRUE);
2153 player->move_delay = game.initial_move_delay;
2154 player->move_delay_value = game.initial_move_delay_value;
2156 player->move_delay_value_next = -1;
2158 player->move_delay_reset_counter = 0;
2160 player->cannot_move = FALSE;
2163 player->push_delay = -1; /* initialized when pushing starts */
2164 player->push_delay_value = game.initial_push_delay_value;
2166 player->drop_delay = 0;
2167 player->drop_pressed_delay = 0;
2169 player->last_jx = player->last_jy = 0;
2170 player->jx = player->jy = 0;
2172 player->shield_normal_time_left = 0;
2173 player->shield_deadly_time_left = 0;
2175 player->inventory_infinite_element = EL_UNDEFINED;
2176 player->inventory_size = 0;
2178 DigField(player, 0, 0, 0, 0, 0, 0, DF_NO_PUSH);
2179 SnapField(player, 0, 0);
2181 player->LevelSolved = FALSE;
2182 player->GameOver = FALSE;
2184 player->LevelSolved_GameEnd = FALSE;
2185 player->LevelSolved_SaveTape = FALSE;
2186 player->LevelSolved_SaveScore = FALSE;
2189 network_player_action_received = FALSE;
2191 #if defined(NETWORK_AVALIABLE)
2192 /* initial null action */
2193 if (network_playing)
2194 SendToServer_MovePlayer(MV_NONE);
2203 TimeLeft = level.time;
2206 ScreenMovDir = MV_NONE;
2210 ScrollStepSize = 0; /* will be correctly initialized by ScrollScreen() */
2212 AllPlayersGone = FALSE;
2214 game.yamyam_content_nr = 0;
2215 game.magic_wall_active = FALSE;
2216 game.magic_wall_time_left = 0;
2217 game.light_time_left = 0;
2218 game.timegate_time_left = 0;
2219 game.switchgate_pos = 0;
2220 game.wind_direction = level.wind_direction_initial;
2222 #if !USE_PLAYER_GRAVITY
2224 game.gravity = FALSE;
2226 game.gravity = level.initial_gravity;
2228 game.explosions_delayed = TRUE;
2231 game.lenses_time_left = 0;
2232 game.magnify_time_left = 0;
2234 game.ball_state = level.ball_state_initial;
2235 game.ball_content_nr = 0;
2237 game.envelope_active = FALSE;
2239 /* set focus to local player for network games, else to all players */
2240 game.centered_player_nr = (network_playing ? local_player->index_nr : -1);
2241 game.centered_player_nr_next = game.centered_player_nr;
2242 game.set_centered_player = FALSE;
2244 if (network_playing && tape.recording)
2246 /* store client dependent player focus when recording network games */
2247 tape.centered_player_nr_next = game.centered_player_nr_next;
2248 tape.set_centered_player = TRUE;
2252 printf("::: focus set to player %d [%d]\n",
2253 game.centered_player_nr, local_player->index_nr);
2256 for (i = 0; i < NUM_BELTS; i++)
2258 game.belt_dir[i] = MV_NONE;
2259 game.belt_dir_nr[i] = 3; /* not moving, next moving left */
2262 for (i = 0; i < MAX_NUM_AMOEBA; i++)
2263 AmoebaCnt[i] = AmoebaCnt2[i] = 0;
2266 SCAN_PLAYFIELD(x, y)
2268 for (x = 0; x < lev_fieldx; x++) for (y = 0; y < lev_fieldy; y++)
2271 Feld[x][y] = level.field[x][y];
2272 MovPos[x][y] = MovDir[x][y] = MovDelay[x][y] = 0;
2273 ChangeDelay[x][y] = 0;
2274 ChangePage[x][y] = -1;
2275 #if USE_NEW_CUSTOM_VALUE
2276 CustomValue[x][y] = 0; /* initialized in InitField() */
2278 Store[x][y] = Store2[x][y] = StorePlayer[x][y] = Back[x][y] = 0;
2280 WasJustMoving[x][y] = 0;
2281 WasJustFalling[x][y] = 0;
2282 CheckCollision[x][y] = 0;
2284 Pushed[x][y] = FALSE;
2286 ChangeCount[x][y] = 0;
2287 ChangeEvent[x][y] = -1;
2289 ExplodePhase[x][y] = 0;
2290 ExplodeDelay[x][y] = 0;
2291 ExplodeField[x][y] = EX_TYPE_NONE;
2293 RunnerVisit[x][y] = 0;
2294 PlayerVisit[x][y] = 0;
2297 GfxRandom[x][y] = INIT_GFX_RANDOM();
2298 GfxElement[x][y] = EL_UNDEFINED;
2299 GfxAction[x][y] = ACTION_DEFAULT;
2300 GfxDir[x][y] = MV_NONE;
2304 SCAN_PLAYFIELD(x, y)
2306 for (y = 0; y < lev_fieldy; y++) for (x = 0; x < lev_fieldx; x++)
2309 if (emulate_bd && !IS_BD_ELEMENT(Feld[x][y]))
2311 if (emulate_sb && !IS_SB_ELEMENT(Feld[x][y]))
2313 if (emulate_sp && !IS_SP_ELEMENT(Feld[x][y]))
2316 InitField(x, y, TRUE);
2321 for (i = 0; i < MAX_PLAYERS; i++)
2323 struct PlayerInfo *player = &stored_player[i];
2326 /* set number of special actions for bored and sleeping animation */
2327 player->num_special_action_bored =
2328 get_num_special_action(player->artwork_element,
2329 ACTION_BORING_1, ACTION_BORING_LAST);
2330 player->num_special_action_sleeping =
2331 get_num_special_action(player->artwork_element,
2332 ACTION_SLEEPING_1, ACTION_SLEEPING_LAST);
2337 game.emulation = (emulate_bd ? EMU_BOULDERDASH :
2338 emulate_sb ? EMU_SOKOBAN :
2339 emulate_sp ? EMU_SUPAPLEX : EMU_NONE);
2341 #if USE_NEW_ALL_SLIPPERY
2342 /* initialize type of slippery elements */
2343 for (i = 0; i < MAX_NUM_ELEMENTS; i++)
2345 if (!IS_CUSTOM_ELEMENT(i))
2347 /* default: elements slip down either to the left or right randomly */
2348 element_info[i].slippery_type = SLIPPERY_ANY_RANDOM;
2350 /* SP style elements prefer to slip down on the left side */
2351 if (game.engine_version >= VERSION_IDENT(3,1,1,0) && IS_SP_ELEMENT(i))
2352 element_info[i].slippery_type = SLIPPERY_ANY_LEFT_RIGHT;
2354 /* BD style elements prefer to slip down on the left side */
2355 if (game.emulation == EMU_BOULDERDASH)
2356 element_info[i].slippery_type = SLIPPERY_ANY_LEFT_RIGHT;
2361 /* initialize explosion and ignition delay */
2362 for (i = 0; i < MAX_NUM_ELEMENTS; i++)
2364 if (!IS_CUSTOM_ELEMENT(i))
2367 int delay = (((IS_SP_ELEMENT(i) && i != EL_EMPTY_SPACE) &&
2368 game.engine_version >= VERSION_IDENT(3,1,0,0)) ||
2369 game.emulation == EMU_SUPAPLEX ? 3 : 2);
2370 int last_phase = (num_phase + 1) * delay;
2371 int half_phase = (num_phase / 2) * delay;
2373 element_info[i].explosion_delay = last_phase - 1;
2374 element_info[i].ignition_delay = half_phase;
2376 if (i == EL_BLACK_ORB)
2377 element_info[i].ignition_delay = 1;
2381 if (element_info[i].explosion_delay < 1) /* !!! check again !!! */
2382 element_info[i].explosion_delay = 1;
2384 if (element_info[i].ignition_delay < 1) /* !!! check again !!! */
2385 element_info[i].ignition_delay = 1;
2389 /* correct non-moving belts to start moving left */
2390 for (i = 0; i < NUM_BELTS; i++)
2391 if (game.belt_dir[i] == MV_NONE)
2392 game.belt_dir_nr[i] = 3; /* not moving, next moving left */
2394 /* check if any connected player was not found in playfield */
2395 for (i = 0; i < MAX_PLAYERS; i++)
2397 struct PlayerInfo *player = &stored_player[i];
2399 if (player->connected && !player->present)
2401 for (j = 0; j < MAX_PLAYERS; j++)
2403 struct PlayerInfo *some_player = &stored_player[j];
2404 int jx = some_player->jx, jy = some_player->jy;
2406 /* assign first free player found that is present in the playfield */
2407 if (some_player->present && !some_player->connected)
2409 player->present = TRUE;
2410 player->active = TRUE;
2412 some_player->present = FALSE;
2413 some_player->active = FALSE;
2416 player->element_nr = some_player->element_nr;
2419 player->artwork_element = some_player->artwork_element;
2421 player->block_last_field = some_player->block_last_field;
2422 player->block_delay_adjustment = some_player->block_delay_adjustment;
2424 StorePlayer[jx][jy] = player->element_nr;
2425 player->jx = player->last_jx = jx;
2426 player->jy = player->last_jy = jy;
2436 /* when playing a tape, eliminate all players who do not participate */
2438 for (i = 0; i < MAX_PLAYERS; i++)
2440 if (stored_player[i].active && !tape.player_participates[i])
2442 struct PlayerInfo *player = &stored_player[i];
2443 int jx = player->jx, jy = player->jy;
2445 player->active = FALSE;
2446 StorePlayer[jx][jy] = 0;
2447 Feld[jx][jy] = EL_EMPTY;
2451 else if (!options.network && !setup.team_mode) /* && !tape.playing */
2453 /* when in single player mode, eliminate all but the first active player */
2455 for (i = 0; i < MAX_PLAYERS; i++)
2457 if (stored_player[i].active)
2459 for (j = i + 1; j < MAX_PLAYERS; j++)
2461 if (stored_player[j].active)
2463 struct PlayerInfo *player = &stored_player[j];
2464 int jx = player->jx, jy = player->jy;
2466 player->active = FALSE;
2467 player->present = FALSE;
2469 StorePlayer[jx][jy] = 0;
2470 Feld[jx][jy] = EL_EMPTY;
2477 /* when recording the game, store which players take part in the game */
2480 for (i = 0; i < MAX_PLAYERS; i++)
2481 if (stored_player[i].active)
2482 tape.player_participates[i] = TRUE;
2487 for (i = 0; i < MAX_PLAYERS; i++)
2489 struct PlayerInfo *player = &stored_player[i];
2491 printf("Player %d: present == %d, connected == %d, active == %d.\n",
2496 if (local_player == player)
2497 printf("Player %d is local player.\n", i+1);
2501 if (BorderElement == EL_EMPTY)
2504 SBX_Right = lev_fieldx - SCR_FIELDX;
2506 SBY_Lower = lev_fieldy - SCR_FIELDY;
2511 SBX_Right = lev_fieldx - SCR_FIELDX + 1;
2513 SBY_Lower = lev_fieldy - SCR_FIELDY + 1;
2516 if (lev_fieldx + (SBX_Left == -1 ? 2 : 0) <= SCR_FIELDX)
2517 SBX_Left = SBX_Right = -1 * (SCR_FIELDX - lev_fieldx) / 2;
2519 if (lev_fieldy + (SBY_Upper == -1 ? 2 : 0) <= SCR_FIELDY)
2520 SBY_Upper = SBY_Lower = -1 * (SCR_FIELDY - lev_fieldy) / 2;
2522 /* if local player not found, look for custom element that might create
2523 the player (make some assumptions about the right custom element) */
2524 if (!local_player->present)
2526 int start_x = 0, start_y = 0;
2527 int found_rating = 0;
2528 int found_element = EL_UNDEFINED;
2529 int player_nr = local_player->index_nr;
2532 SCAN_PLAYFIELD(x, y)
2534 for (y = 0; y < lev_fieldy; y++) for (x = 0; x < lev_fieldx; x++)
2537 int element = Feld[x][y];
2542 if (level.use_start_element[player_nr] &&
2543 level.start_element[player_nr] == element &&
2550 found_element = element;
2553 if (!IS_CUSTOM_ELEMENT(element))
2556 if (CAN_CHANGE(element))
2558 for (i = 0; i < element_info[element].num_change_pages; i++)
2560 /* check for player created from custom element as single target */
2561 content = element_info[element].change_page[i].target_element;
2562 is_player = ELEM_IS_PLAYER(content);
2564 if (is_player && (found_rating < 3 || element < found_element))
2570 found_element = element;
2575 for (yy = 0; yy < 3; yy++) for (xx = 0; xx < 3; xx++)
2577 /* check for player created from custom element as explosion content */
2578 content = element_info[element].content.e[xx][yy];
2579 is_player = ELEM_IS_PLAYER(content);
2581 if (is_player && (found_rating < 2 || element < found_element))
2583 start_x = x + xx - 1;
2584 start_y = y + yy - 1;
2587 found_element = element;
2590 if (!CAN_CHANGE(element))
2593 for (i = 0; i < element_info[element].num_change_pages; i++)
2595 /* check for player created from custom element as extended target */
2597 element_info[element].change_page[i].target_content.e[xx][yy];
2599 is_player = ELEM_IS_PLAYER(content);
2601 if (is_player && (found_rating < 1 || element < found_element))
2603 start_x = x + xx - 1;
2604 start_y = y + yy - 1;
2607 found_element = element;
2613 scroll_x = (start_x < SBX_Left + MIDPOSX ? SBX_Left :
2614 start_x > SBX_Right + MIDPOSX ? SBX_Right :
2617 scroll_y = (start_y < SBY_Upper + MIDPOSY ? SBY_Upper :
2618 start_y > SBY_Lower + MIDPOSY ? SBY_Lower :
2623 scroll_x = (local_player->jx < SBX_Left + MIDPOSX ? SBX_Left :
2624 local_player->jx > SBX_Right + MIDPOSX ? SBX_Right :
2625 local_player->jx - MIDPOSX);
2627 scroll_y = (local_player->jy < SBY_Upper + MIDPOSY ? SBY_Upper :
2628 local_player->jy > SBY_Lower + MIDPOSY ? SBY_Lower :
2629 local_player->jy - MIDPOSY);
2632 if (!game.restart_level)
2633 CloseDoor(DOOR_CLOSE_1);
2635 /* !!! FIX THIS (START) !!! */
2636 if (level.game_engine_type == GAME_ENGINE_TYPE_EM)
2638 InitGameEngine_EM();
2645 /* after drawing the level, correct some elements */
2646 if (game.timegate_time_left == 0)
2647 CloseAllOpenTimegates();
2649 if (setup.soft_scrolling)
2650 BlitBitmap(fieldbuffer, backbuffer, FX, FY, SXSIZE, SYSIZE, SX, SY);
2652 redraw_mask |= REDRAW_FROM_BACKBUFFER;
2655 /* !!! FIX THIS (END) !!! */
2657 if (!game.restart_level)
2659 /* copy default game door content to main double buffer */
2660 BlitBitmap(graphic_info[IMG_GLOBAL_DOOR].bitmap, drawto,
2661 DOOR_GFX_PAGEX5, DOOR_GFX_PAGEY1, DXSIZE, DYSIZE, DX, DY);
2665 SetPanelBackground();
2666 SetDrawBackgroundMask(REDRAW_DOOR_1);
2669 DrawGameDoorValues();
2671 if (!game.restart_level)
2675 game_gadget[SOUND_CTRL_ID_MUSIC]->checked = setup.sound_music;
2676 game_gadget[SOUND_CTRL_ID_LOOPS]->checked = setup.sound_loops;
2677 game_gadget[SOUND_CTRL_ID_SIMPLE]->checked = setup.sound_simple;
2681 /* copy actual game door content to door double buffer for OpenDoor() */
2682 BlitBitmap(drawto, bitmap_db_door,
2683 DX, DY, DXSIZE, DYSIZE, DOOR_GFX_PAGEX1, DOOR_GFX_PAGEY1);
2685 OpenDoor(DOOR_OPEN_ALL);
2687 PlaySoundStereo(SND_GAME_STARTING, SOUND_MIDDLE);
2689 if (setup.sound_music)
2692 KeyboardAutoRepeatOffUnlessAutoplay();
2696 for (i = 0; i < MAX_PLAYERS; i++)
2697 printf("Player %d %sactive.\n",
2698 i + 1, (stored_player[i].active ? "" : "not "));
2702 game.restart_level = FALSE;
2705 void UpdateEngineValues(int actual_scroll_x, int actual_scroll_y)
2707 /* this is used for non-R'n'D game engines to update certain engine values */
2709 /* needed to determine if sounds are played within the visible screen area */
2710 scroll_x = actual_scroll_x;
2711 scroll_y = actual_scroll_y;
2714 void InitMovDir(int x, int y)
2716 int i, element = Feld[x][y];
2717 static int xy[4][2] =
2724 static int direction[3][4] =
2726 { MV_RIGHT, MV_UP, MV_LEFT, MV_DOWN },
2727 { MV_LEFT, MV_DOWN, MV_RIGHT, MV_UP },
2728 { MV_LEFT, MV_RIGHT, MV_UP, MV_DOWN }
2737 Feld[x][y] = EL_BUG;
2738 MovDir[x][y] = direction[0][element - EL_BUG_RIGHT];
2741 case EL_SPACESHIP_RIGHT:
2742 case EL_SPACESHIP_UP:
2743 case EL_SPACESHIP_LEFT:
2744 case EL_SPACESHIP_DOWN:
2745 Feld[x][y] = EL_SPACESHIP;
2746 MovDir[x][y] = direction[0][element - EL_SPACESHIP_RIGHT];
2749 case EL_BD_BUTTERFLY_RIGHT:
2750 case EL_BD_BUTTERFLY_UP:
2751 case EL_BD_BUTTERFLY_LEFT:
2752 case EL_BD_BUTTERFLY_DOWN:
2753 Feld[x][y] = EL_BD_BUTTERFLY;
2754 MovDir[x][y] = direction[0][element - EL_BD_BUTTERFLY_RIGHT];
2757 case EL_BD_FIREFLY_RIGHT:
2758 case EL_BD_FIREFLY_UP:
2759 case EL_BD_FIREFLY_LEFT:
2760 case EL_BD_FIREFLY_DOWN:
2761 Feld[x][y] = EL_BD_FIREFLY;
2762 MovDir[x][y] = direction[0][element - EL_BD_FIREFLY_RIGHT];
2765 case EL_PACMAN_RIGHT:
2767 case EL_PACMAN_LEFT:
2768 case EL_PACMAN_DOWN:
2769 Feld[x][y] = EL_PACMAN;
2770 MovDir[x][y] = direction[0][element - EL_PACMAN_RIGHT];
2773 case EL_YAMYAM_LEFT:
2774 case EL_YAMYAM_RIGHT:
2776 case EL_YAMYAM_DOWN:
2777 Feld[x][y] = EL_YAMYAM;
2778 MovDir[x][y] = direction[2][element - EL_YAMYAM_LEFT];
2781 case EL_SP_SNIKSNAK:
2782 MovDir[x][y] = MV_UP;
2785 case EL_SP_ELECTRON:
2786 MovDir[x][y] = MV_LEFT;
2793 Feld[x][y] = EL_MOLE;
2794 MovDir[x][y] = direction[2][element - EL_MOLE_LEFT];
2798 if (IS_CUSTOM_ELEMENT(element))
2800 struct ElementInfo *ei = &element_info[element];
2801 int move_direction_initial = ei->move_direction_initial;
2802 int move_pattern = ei->move_pattern;
2804 if (move_direction_initial == MV_START_PREVIOUS)
2806 if (MovDir[x][y] != MV_NONE)
2809 move_direction_initial = MV_START_AUTOMATIC;
2812 if (move_direction_initial == MV_START_RANDOM)
2813 MovDir[x][y] = 1 << RND(4);
2814 else if (move_direction_initial & MV_ANY_DIRECTION)
2815 MovDir[x][y] = move_direction_initial;
2816 else if (move_pattern == MV_ALL_DIRECTIONS ||
2817 move_pattern == MV_TURNING_LEFT ||
2818 move_pattern == MV_TURNING_RIGHT ||
2819 move_pattern == MV_TURNING_LEFT_RIGHT ||
2820 move_pattern == MV_TURNING_RIGHT_LEFT ||
2821 move_pattern == MV_TURNING_RANDOM)
2822 MovDir[x][y] = 1 << RND(4);
2823 else if (move_pattern == MV_HORIZONTAL)
2824 MovDir[x][y] = (RND(2) ? MV_LEFT : MV_RIGHT);
2825 else if (move_pattern == MV_VERTICAL)
2826 MovDir[x][y] = (RND(2) ? MV_UP : MV_DOWN);
2827 else if (move_pattern & MV_ANY_DIRECTION)
2828 MovDir[x][y] = element_info[element].move_pattern;
2829 else if (move_pattern == MV_ALONG_LEFT_SIDE ||
2830 move_pattern == MV_ALONG_RIGHT_SIDE)
2832 /* use random direction as default start direction */
2833 if (game.engine_version >= VERSION_IDENT(3,1,0,0))
2834 MovDir[x][y] = 1 << RND(4);
2836 for (i = 0; i < NUM_DIRECTIONS; i++)
2838 int x1 = x + xy[i][0];
2839 int y1 = y + xy[i][1];
2841 if (!IN_LEV_FIELD(x1, y1) || !IS_FREE(x1, y1))
2843 if (move_pattern == MV_ALONG_RIGHT_SIDE)
2844 MovDir[x][y] = direction[0][i];
2846 MovDir[x][y] = direction[1][i];
2855 MovDir[x][y] = 1 << RND(4);
2857 if (element != EL_BUG &&
2858 element != EL_SPACESHIP &&
2859 element != EL_BD_BUTTERFLY &&
2860 element != EL_BD_FIREFLY)
2863 for (i = 0; i < NUM_DIRECTIONS; i++)
2865 int x1 = x + xy[i][0];
2866 int y1 = y + xy[i][1];
2868 if (!IN_LEV_FIELD(x1, y1) || !IS_FREE(x1, y1))
2870 if (element == EL_BUG || element == EL_BD_BUTTERFLY)
2872 MovDir[x][y] = direction[0][i];
2875 else if (element == EL_SPACESHIP || element == EL_BD_FIREFLY ||
2876 element == EL_SP_SNIKSNAK || element == EL_SP_ELECTRON)
2878 MovDir[x][y] = direction[1][i];
2887 GfxDir[x][y] = MovDir[x][y];
2890 void InitAmoebaNr(int x, int y)
2893 int group_nr = AmoebeNachbarNr(x, y);
2897 for (i = 1; i < MAX_NUM_AMOEBA; i++)
2899 if (AmoebaCnt[i] == 0)
2907 AmoebaNr[x][y] = group_nr;
2908 AmoebaCnt[group_nr]++;
2909 AmoebaCnt2[group_nr]++;
2912 #if USE_NEW_GAME_WON
2916 static boolean score_done = FALSE;
2917 static boolean player_done = FALSE;
2918 static int game_over_delay = 0;
2919 int game_over_delay_value = 50;
2921 /* do not start end game actions before the player stops moving (to exit) */
2922 if (local_player->MovPos)
2925 if (tape.auto_play) /* tape might already be stopped here */
2926 tape.auto_play_level_solved = TRUE;
2928 if (!local_player->LevelSolved_GameEnd)
2930 local_player->LevelSolved_GameEnd = TRUE;
2931 local_player->LevelSolved_SaveTape = tape.recording;
2932 local_player->LevelSolved_SaveScore = !tape.playing;
2935 player_done = FALSE;
2936 game_over_delay = 0;
2939 PlaySoundStereo(SND_GAME_WINNING, SOUND_MIDDLE);
2945 if (setup.sound_loops)
2946 PlaySoundExt(SND_GAME_LEVELTIME_BONUS, SOUND_MAX_VOLUME, SOUND_MIDDLE,
2947 SND_CTRL_PLAY_LOOP);
2949 PlaySoundStereo(SND_GAME_LEVELTIME_BONUS, SOUND_MIDDLE);
2952 if (TimeLeft > 100 && TimeLeft % 10 == 0)
2955 RaiseScore(level.score[SC_TIME_BONUS] * 10);
2960 RaiseScore(level.score[SC_TIME_BONUS]);
2963 DrawGameValue_Time(TimeLeft);
2970 if (TimeLeft <= 0 && !tape.playing && setup.sound_loops)
2971 StopSound(SND_GAME_LEVELTIME_BONUS);
2973 else if (level.time == 0 && TimePlayed < 999) /* level without time limit */
2977 if (setup.sound_loops)
2978 PlaySoundExt(SND_GAME_LEVELTIME_BONUS, SOUND_MAX_VOLUME, SOUND_MIDDLE,
2979 SND_CTRL_PLAY_LOOP);
2981 PlaySoundStereo(SND_GAME_LEVELTIME_BONUS, SOUND_MIDDLE);
2984 if (TimePlayed < 900 && TimePlayed % 10 == 0)
2987 RaiseScore(level.score[SC_TIME_BONUS] * 10);
2992 RaiseScore(level.score[SC_TIME_BONUS]);
2995 DrawGameValue_Time(TimePlayed);
2997 if (TimePlayed >= 999 && !tape.playing && setup.sound_loops)
2998 StopSound(SND_GAME_LEVELTIME_BONUS);
3005 /* close exit door after last player */
3006 if (AllPlayersGone && ExitX >= 0 && ExitY >= 0 &&
3007 (Feld[ExitX][ExitY] == EL_EXIT_OPEN ||
3008 Feld[ExitX][ExitY] == EL_SP_EXIT_OPEN))
3010 int element = Feld[ExitX][ExitY];
3012 Feld[ExitX][ExitY] = (element == EL_EXIT_OPEN ? EL_EXIT_CLOSING :
3013 EL_SP_EXIT_CLOSING);
3015 PlayLevelSoundElementAction(ExitX, ExitY, element, ACTION_CLOSING);
3018 /* player disappears */
3019 if (ExitX >= 0 && ExitY >= 0 && !player_done)
3021 DrawLevelField(ExitX, ExitY);
3028 if (game_over_delay < game_over_delay_value || !score_done)
3035 boolean raise_level = FALSE;
3037 CloseDoor(DOOR_CLOSE_1);
3039 if (local_player->LevelSolved_SaveTape)
3043 SaveTape(tape.level_nr); /* Ask to save tape */
3046 if (!local_player->LevelSolved_SaveScore)
3048 game_status = GAME_MODE_MAIN;
3055 if (level_nr == leveldir_current->handicap_level)
3057 leveldir_current->handicap_level++;
3058 SaveLevelSetup_SeriesInfo();
3061 if (level_editor_test_game)
3062 local_player->score = -1; /* no highscore when playing from editor */
3063 else if (level_nr < leveldir_current->last_level)
3064 raise_level = TRUE; /* advance to next level */
3066 if ((hi_pos = NewHiScore()) >= 0)
3068 game_status = GAME_MODE_SCORES;
3070 DrawHallOfFame(hi_pos);
3080 game_status = GAME_MODE_MAIN;
3091 local_player->LevelSolved_SaveScore = FALSE;
3099 boolean raise_level = FALSE;
3101 if (local_player->MovPos)
3104 if (tape.auto_play) /* tape might already be stopped here */
3105 tape.auto_play_level_solved = TRUE;
3107 local_player->LevelSolved = FALSE;
3109 PlaySoundStereo(SND_GAME_WINNING, SOUND_MIDDLE);
3113 if (!tape.playing && setup.sound_loops)
3114 PlaySoundExt(SND_GAME_LEVELTIME_BONUS, SOUND_MAX_VOLUME, SOUND_MIDDLE,
3115 SND_CTRL_PLAY_LOOP);
3117 while (TimeLeft > 0)
3119 if (!tape.playing && !setup.sound_loops)
3120 PlaySoundStereo(SND_GAME_LEVELTIME_BONUS, SOUND_MIDDLE);
3122 if (TimeLeft > 100 && TimeLeft % 10 == 0)
3125 RaiseScore(level.score[SC_TIME_BONUS] * 10);
3130 RaiseScore(level.score[SC_TIME_BONUS]);
3133 DrawGameValue_Time(TimeLeft);
3141 if (!tape.playing && setup.sound_loops)
3142 StopSound(SND_GAME_LEVELTIME_BONUS);
3144 else if (level.time == 0) /* level without time limit */
3146 if (!tape.playing && setup.sound_loops)
3147 PlaySoundExt(SND_GAME_LEVELTIME_BONUS, SOUND_MAX_VOLUME, SOUND_MIDDLE,
3148 SND_CTRL_PLAY_LOOP);
3150 while (TimePlayed < 999)
3152 if (!tape.playing && !setup.sound_loops)
3153 PlaySoundStereo(SND_GAME_LEVELTIME_BONUS, SOUND_MIDDLE);
3155 if (TimePlayed < 900 && TimePlayed % 10 == 0)
3158 RaiseScore(level.score[SC_TIME_BONUS] * 10);
3163 RaiseScore(level.score[SC_TIME_BONUS]);
3166 DrawGameValue_Time(TimePlayed);
3174 if (!tape.playing && setup.sound_loops)
3175 StopSound(SND_GAME_LEVELTIME_BONUS);
3178 /* close exit door after last player */
3179 if (AllPlayersGone && ExitX >= 0 && ExitY >= 0 &&
3180 (Feld[ExitX][ExitY] == EL_EXIT_OPEN ||
3181 Feld[ExitX][ExitY] == EL_SP_EXIT_OPEN))
3183 int element = Feld[ExitX][ExitY];
3185 Feld[ExitX][ExitY] = (element == EL_EXIT_OPEN ? EL_EXIT_CLOSING :
3186 EL_SP_EXIT_CLOSING);
3188 PlayLevelSoundElementAction(ExitX, ExitY, element, ACTION_CLOSING);
3191 /* player disappears */
3192 if (ExitX >= 0 && ExitY >= 0)
3193 DrawLevelField(ExitX, ExitY);
3199 printf("::: TAPE PLAYING -> DO NOT SAVE SCORE\n");
3201 printf("::: NO TAPE PLAYING -> SAVING SCORE\n");
3207 CloseDoor(DOOR_CLOSE_1);
3212 SaveTape(tape.level_nr); /* Ask to save tape */
3215 if (level_nr == leveldir_current->handicap_level)
3217 leveldir_current->handicap_level++;
3218 SaveLevelSetup_SeriesInfo();
3221 if (level_editor_test_game)
3222 local_player->score = -1; /* no highscore when playing from editor */
3223 else if (level_nr < leveldir_current->last_level)
3224 raise_level = TRUE; /* advance to next level */
3226 if ((hi_pos = NewHiScore()) >= 0)
3228 game_status = GAME_MODE_SCORES;
3229 DrawHallOfFame(hi_pos);
3238 game_status = GAME_MODE_MAIN;
3257 LoadScore(level_nr);
3259 if (strEqual(setup.player_name, EMPTY_PLAYER_NAME) ||
3260 local_player->score < highscore[MAX_SCORE_ENTRIES - 1].Score)
3263 for (k = 0; k < MAX_SCORE_ENTRIES; k++)
3265 if (local_player->score > highscore[k].Score)
3267 /* player has made it to the hall of fame */
3269 if (k < MAX_SCORE_ENTRIES - 1)
3271 int m = MAX_SCORE_ENTRIES - 1;
3274 for (l = k; l < MAX_SCORE_ENTRIES; l++)
3275 if (strEqual(setup.player_name, highscore[l].Name))
3277 if (m == k) /* player's new highscore overwrites his old one */
3281 for (l = m; l > k; l--)
3283 strcpy(highscore[l].Name, highscore[l - 1].Name);
3284 highscore[l].Score = highscore[l - 1].Score;
3291 strncpy(highscore[k].Name, setup.player_name, MAX_PLAYER_NAME_LEN);
3292 highscore[k].Name[MAX_PLAYER_NAME_LEN] = '\0';
3293 highscore[k].Score = local_player->score;
3299 else if (!strncmp(setup.player_name, highscore[k].Name,
3300 MAX_PLAYER_NAME_LEN))
3301 break; /* player already there with a higher score */
3307 SaveScore(level_nr);
3312 inline static int getElementMoveStepsize(int x, int y)
3314 int element = Feld[x][y];
3315 int direction = MovDir[x][y];
3316 int dx = (direction == MV_LEFT ? -1 : direction == MV_RIGHT ? +1 : 0);
3317 int dy = (direction == MV_UP ? -1 : direction == MV_DOWN ? +1 : 0);
3318 int horiz_move = (dx != 0);
3319 int sign = (horiz_move ? dx : dy);
3320 int step = sign * element_info[element].move_stepsize;
3322 /* special values for move stepsize for spring and things on conveyor belt */
3326 if (element == EL_SPRING)
3327 step = sign * MOVE_STEPSIZE_NORMAL * 2;
3328 else if (CAN_FALL(element) && !CAN_MOVE(element) &&
3329 y < lev_fieldy - 1 && IS_BELT_ACTIVE(Feld[x][y + 1]))
3330 step = sign * MOVE_STEPSIZE_NORMAL / 2;
3332 if (CAN_FALL(element) &&
3333 y < lev_fieldy - 1 && IS_BELT_ACTIVE(Feld[x][y + 1]))
3334 step = sign * MOVE_STEPSIZE_NORMAL / 2;
3335 else if (element == EL_SPRING)
3336 step = sign * MOVE_STEPSIZE_NORMAL * 2;
3343 void InitPlayerGfxAnimation(struct PlayerInfo *player, int action, int dir)
3345 if (player->GfxAction != action || player->GfxDir != dir)
3348 printf("Player frame reset! (%d => %d, %d => %d)\n",
3349 player->GfxAction, action, player->GfxDir, dir);
3352 player->GfxAction = action;
3353 player->GfxDir = dir;
3355 player->StepFrame = 0;
3359 #if USE_GFX_RESET_GFX_ANIMATION
3360 static void ResetGfxFrame(int x, int y, boolean redraw)
3362 int element = Feld[x][y];
3363 int graphic = el_act_dir2img(element, GfxAction[x][y], GfxDir[x][y]);
3364 int last_gfx_frame = GfxFrame[x][y];
3366 if (graphic_info[graphic].anim_global_sync)
3367 GfxFrame[x][y] = FrameCounter;
3368 else if (ANIM_MODE(graphic) == ANIM_CE_VALUE)
3369 GfxFrame[x][y] = CustomValue[x][y];
3370 else if (ANIM_MODE(graphic) == ANIM_CE_SCORE)
3371 GfxFrame[x][y] = element_info[element].collect_score;
3372 else if (ANIM_MODE(graphic) == ANIM_CE_DELAY)
3373 GfxFrame[x][y] = ChangeDelay[x][y];
3375 if (redraw && GfxFrame[x][y] != last_gfx_frame)
3376 DrawLevelGraphicAnimation(x, y, graphic);
3380 static void ResetGfxAnimation(int x, int y)
3383 int element, graphic;
3386 GfxAction[x][y] = ACTION_DEFAULT;
3387 GfxDir[x][y] = MovDir[x][y];
3391 element = Feld[x][y];
3392 graphic = el_act_dir2img(element, GfxAction[x][y], GfxDir[x][y]);
3394 if (graphic_info[graphic].anim_global_sync)
3395 GfxFrame[x][y] = FrameCounter;
3396 else if (ANIM_MODE(graphic) == ANIM_CE_VALUE)
3397 GfxFrame[x][y] = CustomValue[x][y];
3398 else if (ANIM_MODE(graphic) == ANIM_CE_SCORE)
3399 GfxFrame[x][y] = element_info[element].collect_score;
3400 else if (ANIM_MODE(graphic) == ANIM_CE_DELAY)
3401 GfxFrame[x][y] = ChangeDelay[x][y];
3404 #if USE_GFX_RESET_GFX_ANIMATION
3405 ResetGfxFrame(x, y, FALSE);
3409 static void ResetRandomAnimationValue(int x, int y)
3411 GfxRandom[x][y] = INIT_GFX_RANDOM();
3414 void InitMovingField(int x, int y, int direction)
3416 int element = Feld[x][y];
3420 int dx = (direction == MV_LEFT ? -1 : direction == MV_RIGHT ? +1 : 0);
3421 int dy = (direction == MV_UP ? -1 : direction == MV_DOWN ? +1 : 0);
3425 if (!WasJustMoving[x][y] || direction != MovDir[x][y])
3426 ResetGfxAnimation(x, y);
3428 MovDir[x][y] = direction;
3429 GfxDir[x][y] = direction;
3430 GfxAction[x][y] = (direction == MV_DOWN && CAN_FALL(element) ?
3431 ACTION_FALLING : ACTION_MOVING);
3434 graphic = el_act_dir2img(element, GfxAction[x][y], GfxDir[x][y]);
3436 if (graphic_info[graphic].anim_global_sync)
3437 GfxFrame[x][y] = FrameCounter;
3438 else if (ANIM_MODE(graphic) == ANIM_CE_VALUE)
3439 GfxFrame[x][y] = CustomValue[x][y];
3440 else if (ANIM_MODE(graphic) == ANIM_CE_SCORE)
3441 GfxFrame[x][y] = element_info[element].collect_score;
3442 else if (ANIM_MODE(graphic) == ANIM_CE_DELAY)
3443 GfxFrame[x][y] = ChangeDelay[x][y];
3446 /* this is needed for CEs with property "can move" / "not moving" */
3448 if (getElementMoveStepsize(x, y) != 0) /* moving or being moved */
3450 if (Feld[newx][newy] == EL_EMPTY)
3451 Feld[newx][newy] = EL_BLOCKED;
3453 MovDir[newx][newy] = MovDir[x][y];
3455 #if USE_NEW_CUSTOM_VALUE
3456 CustomValue[newx][newy] = CustomValue[x][y];
3459 GfxFrame[newx][newy] = GfxFrame[x][y];
3460 GfxRandom[newx][newy] = GfxRandom[x][y];
3461 GfxAction[newx][newy] = GfxAction[x][y];
3462 GfxDir[newx][newy] = GfxDir[x][y];
3466 void Moving2Blocked(int x, int y, int *goes_to_x, int *goes_to_y)
3468 int direction = MovDir[x][y];
3470 int newx = x + (direction & MV_LEFT ? -1 : direction & MV_RIGHT ? +1 : 0);
3471 int newy = y + (direction & MV_UP ? -1 : direction & MV_DOWN ? +1 : 0);
3473 int newx = x + (direction == MV_LEFT ? -1 : direction == MV_RIGHT ? +1 : 0);
3474 int newy = y + (direction == MV_UP ? -1 : direction == MV_DOWN ? +1 : 0);
3481 void Blocked2Moving(int x, int y, int *comes_from_x, int *comes_from_y)
3483 int oldx = x, oldy = y;
3484 int direction = MovDir[x][y];
3486 if (direction == MV_LEFT)
3488 else if (direction == MV_RIGHT)
3490 else if (direction == MV_UP)
3492 else if (direction == MV_DOWN)
3495 *comes_from_x = oldx;
3496 *comes_from_y = oldy;
3499 int MovingOrBlocked2Element(int x, int y)
3501 int element = Feld[x][y];
3503 if (element == EL_BLOCKED)
3507 Blocked2Moving(x, y, &oldx, &oldy);
3508 return Feld[oldx][oldy];
3514 static int MovingOrBlocked2ElementIfNotLeaving(int x, int y)
3516 /* like MovingOrBlocked2Element(), but if element is moving
3517 and (x,y) is the field the moving element is just leaving,
3518 return EL_BLOCKED instead of the element value */
3519 int element = Feld[x][y];
3521 if (IS_MOVING(x, y))
3523 if (element == EL_BLOCKED)
3527 Blocked2Moving(x, y, &oldx, &oldy);
3528 return Feld[oldx][oldy];
3537 static void RemoveField(int x, int y)
3539 Feld[x][y] = EL_EMPTY;
3545 #if USE_NEW_CUSTOM_VALUE
3546 CustomValue[x][y] = 0;
3550 ChangeDelay[x][y] = 0;
3551 ChangePage[x][y] = -1;
3552 Pushed[x][y] = FALSE;
3555 ExplodeField[x][y] = EX_TYPE_NONE;
3558 GfxElement[x][y] = EL_UNDEFINED;
3559 GfxAction[x][y] = ACTION_DEFAULT;
3560 GfxDir[x][y] = MV_NONE;
3563 void RemoveMovingField(int x, int y)
3565 int oldx = x, oldy = y, newx = x, newy = y;
3566 int element = Feld[x][y];
3567 int next_element = EL_UNDEFINED;
3569 if (element != EL_BLOCKED && !IS_MOVING(x, y))
3572 if (IS_MOVING(x, y))
3574 Moving2Blocked(x, y, &newx, &newy);
3576 if (Feld[newx][newy] != EL_BLOCKED)
3578 /* element is moving, but target field is not free (blocked), but
3579 already occupied by something different (example: acid pool);
3580 in this case, only remove the moving field, but not the target */
3582 RemoveField(oldx, oldy);
3584 Store[oldx][oldy] = Store2[oldx][oldy] = 0;
3586 DrawLevelField(oldx, oldy);
3591 else if (element == EL_BLOCKED)
3593 Blocked2Moving(x, y, &oldx, &oldy);
3594 if (!IS_MOVING(oldx, oldy))
3598 if (element == EL_BLOCKED &&
3599 (Feld[oldx][oldy] == EL_QUICKSAND_EMPTYING ||
3600 Feld[oldx][oldy] == EL_MAGIC_WALL_EMPTYING ||
3601 Feld[oldx][oldy] == EL_BD_MAGIC_WALL_EMPTYING ||
3602 Feld[oldx][oldy] == EL_AMOEBA_DROPPING))
3603 next_element = get_next_element(Feld[oldx][oldy]);
3605 RemoveField(oldx, oldy);
3606 RemoveField(newx, newy);
3608 Store[oldx][oldy] = Store2[oldx][oldy] = 0;
3610 if (next_element != EL_UNDEFINED)
3611 Feld[oldx][oldy] = next_element;
3613 DrawLevelField(oldx, oldy);
3614 DrawLevelField(newx, newy);
3617 void DrawDynamite(int x, int y)
3619 int sx = SCREENX(x), sy = SCREENY(y);
3620 int graphic = el2img(Feld[x][y]);
3623 if (!IN_SCR_FIELD(sx, sy) || IS_PLAYER(x, y))
3626 if (IS_WALKABLE_INSIDE(Back[x][y]))
3630 DrawGraphic(sx, sy, el2img(Back[x][y]), 0);
3631 else if (Store[x][y])
3632 DrawGraphic(sx, sy, el2img(Store[x][y]), 0);
3634 frame = getGraphicAnimationFrame(graphic, GfxFrame[x][y]);
3636 if (Back[x][y] || Store[x][y])
3637 DrawGraphicThruMask(sx, sy, graphic, frame);
3639 DrawGraphic(sx, sy, graphic, frame);
3642 void CheckDynamite(int x, int y)
3644 if (MovDelay[x][y] != 0) /* dynamite is still waiting to explode */
3648 if (MovDelay[x][y] != 0)
3651 PlayLevelSoundActionIfLoop(x, y, ACTION_ACTIVE);
3657 StopLevelSoundActionIfLoop(x, y, ACTION_ACTIVE);
3664 static void setMinimalPlayerBoundaries(int *sx1, int *sy1, int *sx2, int *sy2)
3666 boolean num_checked_players = 0;
3669 for (i = 0; i < MAX_PLAYERS; i++)
3671 if (stored_player[i].active)
3673 int sx = stored_player[i].jx;
3674 int sy = stored_player[i].jy;
3676 if (num_checked_players == 0)
3683 *sx1 = MIN(*sx1, sx);
3684 *sy1 = MIN(*sy1, sy);
3685 *sx2 = MAX(*sx2, sx);
3686 *sy2 = MAX(*sy2, sy);
3689 num_checked_players++;
3694 static boolean checkIfAllPlayersFitToScreen_RND()
3696 int sx1 = 0, sy1 = 0, sx2 = 0, sy2 = 0;
3698 setMinimalPlayerBoundaries(&sx1, &sy1, &sx2, &sy2);
3700 return (sx2 - sx1 < SCR_FIELDX &&
3701 sy2 - sy1 < SCR_FIELDY);
3704 static void setScreenCenteredToAllPlayers(int *sx, int *sy)
3706 int sx1 = scroll_x, sy1 = scroll_y, sx2 = scroll_x, sy2 = scroll_y;
3708 setMinimalPlayerBoundaries(&sx1, &sy1, &sx2, &sy2);
3710 *sx = (sx1 + sx2) / 2;
3711 *sy = (sy1 + sy2) / 2;
3715 static void setMaxCenterDistanceForAllPlayers(int *max_dx, int *max_dy,
3716 int center_x, int center_y)
3718 int sx1 = center_x, sy1 = center_y, sx2 = center_x, sy2 = center_y;
3720 setMinimalPlayerBoundaries(&sx1, &sy1, &sx2, &sy2);
3722 *max_dx = MAX(ABS(sx1 - center_x), ABS(sx2 - center_x));
3723 *max_dy = MAX(ABS(sy1 - center_y), ABS(sy2 - center_y));
3726 static boolean checkIfAllPlayersAreVisible(int center_x, int center_y)
3730 setMaxCenterDistanceForAllPlayers(&max_dx, &max_dy, center_x, center_y);
3732 return (max_dx <= SCR_FIELDX / 2 &&
3733 max_dy <= SCR_FIELDY / 2);
3741 void DrawRelocateScreen(int x, int y, int move_dir, boolean center_screen,
3742 boolean quick_relocation)
3744 boolean ffwd_delay = (tape.playing && tape.fast_forward);
3745 boolean no_delay = (tape.warp_forward);
3746 int frame_delay_value = (ffwd_delay ? FfwdFrameDelay : GameFrameDelay);
3747 int wait_delay_value = (no_delay ? 0 : frame_delay_value);
3749 if (quick_relocation)
3751 int offset = (setup.scroll_delay ? 3 : 0);
3758 if (!IN_VIS_FIELD(SCREENX(x), SCREENY(y)) || center_screen)
3760 scroll_x = (x < SBX_Left + MIDPOSX ? SBX_Left :
3761 x > SBX_Right + MIDPOSX ? SBX_Right :
3764 scroll_y = (y < SBY_Upper + MIDPOSY ? SBY_Upper :
3765 y > SBY_Lower + MIDPOSY ? SBY_Lower :
3770 if ((move_dir == MV_LEFT && scroll_x > x - MIDPOSX + offset) ||
3771 (move_dir == MV_RIGHT && scroll_x < x - MIDPOSX - offset))
3772 scroll_x = x - MIDPOSX + (scroll_x < x - MIDPOSX ? -offset : +offset);
3774 if ((move_dir == MV_UP && scroll_y > y - MIDPOSY + offset) ||
3775 (move_dir == MV_DOWN && scroll_y < y - MIDPOSY - offset))
3776 scroll_y = y - MIDPOSY + (scroll_y < y - MIDPOSY ? -offset : +offset);
3778 /* don't scroll over playfield boundaries */
3779 if (scroll_x < SBX_Left || scroll_x > SBX_Right)
3780 scroll_x = (scroll_x < SBX_Left ? SBX_Left : SBX_Right);
3782 /* don't scroll over playfield boundaries */
3783 if (scroll_y < SBY_Upper || scroll_y > SBY_Lower)
3784 scroll_y = (scroll_y < SBY_Upper ? SBY_Upper : SBY_Lower);
3787 RedrawPlayfield(TRUE, 0,0,0,0);
3791 int scroll_xx = (x < SBX_Left + MIDPOSX ? SBX_Left :
3792 x > SBX_Right + MIDPOSX ? SBX_Right :
3795 int scroll_yy = (y < SBY_Upper + MIDPOSY ? SBY_Upper :
3796 y > SBY_Lower + MIDPOSY ? SBY_Lower :
3799 ScrollScreen(NULL, SCROLL_GO_ON); /* scroll last frame to full tile */
3801 while (scroll_x != scroll_xx || scroll_y != scroll_yy)
3804 int fx = FX, fy = FY;
3806 dx = (scroll_xx < scroll_x ? +1 : scroll_xx > scroll_x ? -1 : 0);
3807 dy = (scroll_yy < scroll_y ? +1 : scroll_yy > scroll_y ? -1 : 0);
3809 if (dx == 0 && dy == 0) /* no scrolling needed at all */
3815 fx += dx * TILEX / 2;
3816 fy += dy * TILEY / 2;
3818 ScrollLevel(dx, dy);
3821 /* scroll in two steps of half tile size to make things smoother */
3822 BlitBitmap(drawto_field, window, fx, fy, SXSIZE, SYSIZE, SX, SY);
3824 Delay(wait_delay_value);
3826 /* scroll second step to align at full tile size */
3828 Delay(wait_delay_value);
3833 Delay(wait_delay_value);
3839 void DrawRelocatePlayer(struct PlayerInfo *player, boolean quick_relocation)
3841 boolean ffwd_delay = (tape.playing && tape.fast_forward);
3842 boolean no_delay = (tape.warp_forward);
3843 int frame_delay_value = (ffwd_delay ? FfwdFrameDelay : GameFrameDelay);
3844 int wait_delay_value = (no_delay ? 0 : frame_delay_value);
3845 int jx = player->jx;
3846 int jy = player->jy;
3848 if (quick_relocation)
3850 int offset = (setup.scroll_delay ? 3 : 0);
3852 if (!IN_VIS_FIELD(SCREENX(jx), SCREENY(jy)))
3854 scroll_x = (player->jx < SBX_Left + MIDPOSX ? SBX_Left :
3855 player->jx > SBX_Right + MIDPOSX ? SBX_Right :
3856 player->jx - MIDPOSX);
3858 scroll_y = (player->jy < SBY_Upper + MIDPOSY ? SBY_Upper :
3859 player->jy > SBY_Lower + MIDPOSY ? SBY_Lower :
3860 player->jy - MIDPOSY);
3864 if ((player->MovDir == MV_LEFT && scroll_x > jx - MIDPOSX + offset) ||
3865 (player->MovDir == MV_RIGHT && scroll_x < jx - MIDPOSX - offset))
3866 scroll_x = jx - MIDPOSX + (scroll_x < jx-MIDPOSX ? -offset : +offset);
3868 if ((player->MovDir == MV_UP && scroll_y > jy - MIDPOSY + offset) ||
3869 (player->MovDir == MV_DOWN && scroll_y < jy - MIDPOSY - offset))
3870 scroll_y = jy - MIDPOSY + (scroll_y < jy-MIDPOSY ? -offset : +offset);
3872 /* don't scroll over playfield boundaries */
3873 if (scroll_x < SBX_Left || scroll_x > SBX_Right)
3874 scroll_x = (scroll_x < SBX_Left ? SBX_Left : SBX_Right);
3876 /* don't scroll over playfield boundaries */
3877 if (scroll_y < SBY_Upper || scroll_y > SBY_Lower)
3878 scroll_y = (scroll_y < SBY_Upper ? SBY_Upper : SBY_Lower);
3881 RedrawPlayfield(TRUE, 0,0,0,0);
3885 int scroll_xx = (player->jx < SBX_Left + MIDPOSX ? SBX_Left :
3886 player->jx > SBX_Right + MIDPOSX ? SBX_Right :
3887 player->jx - MIDPOSX);
3889 int scroll_yy = (player->jy < SBY_Upper + MIDPOSY ? SBY_Upper :
3890 player->jy > SBY_Lower + MIDPOSY ? SBY_Lower :
3891 player->jy - MIDPOSY);
3893 ScrollScreen(NULL, SCROLL_GO_ON); /* scroll last frame to full tile */
3895 while (scroll_x != scroll_xx || scroll_y != scroll_yy)
3898 int fx = FX, fy = FY;
3900 dx = (scroll_xx < scroll_x ? +1 : scroll_xx > scroll_x ? -1 : 0);
3901 dy = (scroll_yy < scroll_y ? +1 : scroll_yy > scroll_y ? -1 : 0);
3903 if (dx == 0 && dy == 0) /* no scrolling needed at all */
3909 fx += dx * TILEX / 2;
3910 fy += dy * TILEY / 2;
3912 ScrollLevel(dx, dy);
3915 /* scroll in two steps of half tile size to make things smoother */
3916 BlitBitmap(drawto_field, window, fx, fy, SXSIZE, SYSIZE, SX, SY);
3918 Delay(wait_delay_value);
3920 /* scroll second step to align at full tile size */
3922 Delay(wait_delay_value);
3927 Delay(wait_delay_value);
3933 void RelocatePlayer(int jx, int jy, int el_player_raw)
3935 int el_player = GET_PLAYER_ELEMENT(el_player_raw);
3936 int player_nr = GET_PLAYER_NR(el_player);
3937 struct PlayerInfo *player = &stored_player[player_nr];
3938 boolean ffwd_delay = (tape.playing && tape.fast_forward);
3939 boolean no_delay = (tape.warp_forward);
3940 int frame_delay_value = (ffwd_delay ? FfwdFrameDelay : GameFrameDelay);
3941 int wait_delay_value = (no_delay ? 0 : frame_delay_value);
3942 int old_jx = player->jx;
3943 int old_jy = player->jy;
3944 int old_element = Feld[old_jx][old_jy];
3945 int element = Feld[jx][jy];
3946 boolean player_relocated = (old_jx != jx || old_jy != jy);
3948 int move_dir_horiz = (jx < old_jx ? MV_LEFT : jx > old_jx ? MV_RIGHT : 0);
3949 int move_dir_vert = (jy < old_jy ? MV_UP : jy > old_jy ? MV_DOWN : 0);
3950 int enter_side_horiz = MV_DIR_OPPOSITE(move_dir_horiz);
3951 int enter_side_vert = MV_DIR_OPPOSITE(move_dir_vert);
3952 int leave_side_horiz = move_dir_horiz;
3953 int leave_side_vert = move_dir_vert;
3954 int enter_side = enter_side_horiz | enter_side_vert;
3955 int leave_side = leave_side_horiz | leave_side_vert;
3957 if (player->GameOver) /* do not reanimate dead player */
3960 if (!player_relocated) /* no need to relocate the player */
3963 if (IS_PLAYER(jx, jy)) /* player already placed at new position */
3965 RemoveField(jx, jy); /* temporarily remove newly placed player */
3966 DrawLevelField(jx, jy);
3969 if (player->present)
3971 while (player->MovPos)
3973 ScrollPlayer(player, SCROLL_GO_ON);
3974 ScrollScreen(NULL, SCROLL_GO_ON);
3976 AdvanceFrameAndPlayerCounters(player->index_nr);
3981 Delay(wait_delay_value);
3984 DrawPlayer(player); /* needed here only to cleanup last field */
3985 DrawLevelField(player->jx, player->jy); /* remove player graphic */
3987 player->is_moving = FALSE;
3990 if (IS_CUSTOM_ELEMENT(old_element))
3991 CheckElementChangeByPlayer(old_jx, old_jy, old_element,
3993 player->index_bit, leave_side);
3995 CheckTriggeredElementChangeByPlayer(old_jx, old_jy, old_element,
3997 player->index_bit, leave_side);
3999 Feld[jx][jy] = el_player;
4000 InitPlayerField(jx, jy, el_player, TRUE);
4002 if (!ELEM_IS_PLAYER(element)) /* player may be set on walkable element */
4004 Feld[jx][jy] = element;
4005 InitField(jx, jy, FALSE);
4009 /* only visually relocate centered player */
4011 DrawRelocateScreen(player->jx, player->jy, player->MovDir, FALSE,
4012 level.instant_relocation);
4014 if (player->index_nr == game.centered_player_nr)
4015 DrawRelocatePlayer(player, level.instant_relocation);
4018 if (player == local_player) /* only visually relocate local player */
4019 DrawRelocatePlayer(player, level.instant_relocation);
4022 TestIfPlayerTouchesBadThing(jx, jy);
4023 TestIfPlayerTouchesCustomElement(jx, jy);
4025 if (IS_CUSTOM_ELEMENT(element))
4026 CheckElementChangeByPlayer(jx, jy, element, CE_ENTERED_BY_PLAYER,
4027 player->index_bit, enter_side);
4029 CheckTriggeredElementChangeByPlayer(jx, jy, element, CE_PLAYER_ENTERS_X,
4030 player->index_bit, enter_side);
4033 void Explode(int ex, int ey, int phase, int mode)
4039 /* !!! eliminate this variable !!! */
4040 int delay = (game.emulation == EMU_SUPAPLEX ? 3 : 2);
4042 if (game.explosions_delayed)
4044 ExplodeField[ex][ey] = mode;
4048 if (phase == EX_PHASE_START) /* initialize 'Store[][]' field */
4050 int center_element = Feld[ex][ey];
4051 int artwork_element, explosion_element; /* set these values later */
4054 /* --- This is only really needed (and now handled) in "Impact()". --- */
4055 /* do not explode moving elements that left the explode field in time */
4056 if (game.engine_version >= VERSION_IDENT(2,2,0,7) &&
4057 center_element == EL_EMPTY &&
4058 (mode == EX_TYPE_NORMAL || mode == EX_TYPE_CENTER))
4063 /* !!! at this place, the center element may be EL_BLOCKED !!! */
4064 if (mode == EX_TYPE_NORMAL ||
4065 mode == EX_TYPE_CENTER ||
4066 mode == EX_TYPE_CROSS)
4067 PlayLevelSoundElementAction(ex, ey, artwork_element, ACTION_EXPLODING);
4070 /* remove things displayed in background while burning dynamite */
4071 if (Back[ex][ey] != EL_EMPTY && !IS_INDESTRUCTIBLE(Back[ex][ey]))
4074 if (IS_MOVING(ex, ey) || IS_BLOCKED(ex, ey))
4076 /* put moving element to center field (and let it explode there) */
4077 center_element = MovingOrBlocked2Element(ex, ey);
4078 RemoveMovingField(ex, ey);
4079 Feld[ex][ey] = center_element;
4082 /* now "center_element" is finally determined -- set related values now */
4083 artwork_element = center_element; /* for custom player artwork */
4084 explosion_element = center_element; /* for custom player artwork */
4086 if (IS_PLAYER(ex, ey))
4088 int player_nr = GET_PLAYER_NR(StorePlayer[ex][ey]);
4090 artwork_element = stored_player[player_nr].artwork_element;
4092 if (level.use_explosion_element[player_nr])
4094 explosion_element = level.explosion_element[player_nr];
4095 artwork_element = explosion_element;
4100 if (mode == EX_TYPE_NORMAL ||
4101 mode == EX_TYPE_CENTER ||
4102 mode == EX_TYPE_CROSS)
4103 PlayLevelSoundElementAction(ex, ey, artwork_element, ACTION_EXPLODING);
4107 last_phase = element_info[explosion_element].explosion_delay + 1;
4109 last_phase = element_info[center_element].explosion_delay + 1;
4112 for (y = ey - 1; y <= ey + 1; y++) for (x = ex - 1; x <= ex + 1; x++)
4114 int xx = x - ex + 1;
4115 int yy = y - ey + 1;
4118 if (!IN_LEV_FIELD(x, y) ||
4119 (mode & EX_TYPE_SINGLE_TILE && (x != ex || y != ey)) ||
4120 (mode == EX_TYPE_CROSS && (x != ex && y != ey)))
4123 element = Feld[x][y];
4125 if (IS_MOVING(x, y) || IS_BLOCKED(x, y))
4127 element = MovingOrBlocked2Element(x, y);
4129 if (!IS_EXPLOSION_PROOF(element))
4130 RemoveMovingField(x, y);
4133 /* indestructible elements can only explode in center (but not flames) */
4134 if ((IS_EXPLOSION_PROOF(element) && (x != ex || y != ey ||
4135 mode == EX_TYPE_BORDER)) ||
4136 element == EL_FLAMES)
4139 /* no idea why this was changed from 3.0.8 to 3.1.0 -- this causes buggy
4140 behaviour, for example when touching a yamyam that explodes to rocks
4141 with active deadly shield, a rock is created under the player !!! */
4142 /* (case 1 (surely buggy): >= 3.1.0, case 2 (maybe buggy): <= 3.0.8) */
4144 if (IS_PLAYER(x, y) && SHIELD_ON(PLAYERINFO(x, y)) &&
4145 (game.engine_version < VERSION_IDENT(3,1,0,0) ||
4146 (x == ex && y == ey && mode != EX_TYPE_BORDER)))
4148 if (IS_PLAYER(x, y) && SHIELD_ON(PLAYERINFO(x, y)))
4151 if (IS_ACTIVE_BOMB(element))
4153 /* re-activate things under the bomb like gate or penguin */
4154 Feld[x][y] = (Back[x][y] ? Back[x][y] : EL_EMPTY);
4161 /* save walkable background elements while explosion on same tile */
4162 if (IS_WALKABLE(element) && IS_INDESTRUCTIBLE(element) &&
4163 (x != ex || y != ey || mode == EX_TYPE_BORDER))
4164 Back[x][y] = element;
4166 /* ignite explodable elements reached by other explosion */
4167 if (element == EL_EXPLOSION)
4168 element = Store2[x][y];
4170 if (AmoebaNr[x][y] &&
4171 (element == EL_AMOEBA_FULL ||
4172 element == EL_BD_AMOEBA ||
4173 element == EL_AMOEBA_GROWING))
4175 AmoebaCnt[AmoebaNr[x][y]]--;
4176 AmoebaCnt2[AmoebaNr[x][y]]--;
4181 if (IS_PLAYER(ex, ey) && !PLAYER_EXPLOSION_PROTECTED(ex, ey))
4184 int player_nr = StorePlayer[ex][ey] - EL_PLAYER_1;
4186 Store[x][y] = EL_PLAYER_IS_EXPLODING_1 + player_nr;
4188 switch(StorePlayer[ex][ey])
4191 Store[x][y] = EL_PLAYER_IS_EXPLODING_2;
4194 Store[x][y] = EL_PLAYER_IS_EXPLODING_3;
4197 Store[x][y] = EL_PLAYER_IS_EXPLODING_4;
4201 Store[x][y] = EL_PLAYER_IS_EXPLODING_1;
4206 if (PLAYERINFO(ex, ey)->use_murphy)
4207 Store[x][y] = EL_EMPTY;
4210 /* !!! check this case -- currently needed for rnd_rado_negundo_v,
4211 !!! levels 015 018 019 020 021 022 023 026 027 028 !!! */
4212 else if (ELEM_IS_PLAYER(center_element))
4213 Store[x][y] = EL_EMPTY;
4214 else if (center_element == EL_YAMYAM)
4215 Store[x][y] = level.yamyam_content[game.yamyam_content_nr].e[xx][yy];
4216 else if (element_info[center_element].content.e[xx][yy] != EL_EMPTY)
4217 Store[x][y] = element_info[center_element].content.e[xx][yy];
4219 /* needed because EL_BD_BUTTERFLY is not defined as "CAN_EXPLODE"
4220 (killing EL_BD_BUTTERFLY with dynamite would result in BD diamond
4221 otherwise) -- FIX THIS !!! */
4222 else if (!CAN_EXPLODE(element) && element != EL_BD_BUTTERFLY)
4223 Store[x][y] = element_info[element].content.e[1][1];
4225 else if (!CAN_EXPLODE(element))
4226 Store[x][y] = element_info[element].content.e[1][1];
4229 Store[x][y] = EL_EMPTY;
4231 else if (center_element == EL_MOLE)
4232 Store[x][y] = EL_EMERALD_RED;
4233 else if (center_element == EL_PENGUIN)
4234 Store[x][y] = EL_EMERALD_PURPLE;
4235 else if (center_element == EL_BUG)
4236 Store[x][y] = ((x == ex && y == ey) ? EL_DIAMOND : EL_EMERALD);
4237 else if (center_element == EL_BD_BUTTERFLY)
4238 Store[x][y] = EL_BD_DIAMOND;
4239 else if (center_element == EL_SP_ELECTRON)
4240 Store[x][y] = EL_SP_INFOTRON;
4241 else if (center_element == EL_AMOEBA_TO_DIAMOND)
4242 Store[x][y] = level.amoeba_content;
4243 else if (center_element == EL_YAMYAM)
4244 Store[x][y] = level.yamyam_content[game.yamyam_content_nr].e[xx][yy];
4245 else if (IS_CUSTOM_ELEMENT(center_element) &&
4246 element_info[center_element].content.e[xx][yy] != EL_EMPTY)
4247 Store[x][y] = element_info[center_element].content.e[xx][yy];
4248 else if (element == EL_WALL_EMERALD)
4249 Store[x][y] = EL_EMERALD;
4250 else if (element == EL_WALL_DIAMOND)
4251 Store[x][y] = EL_DIAMOND;
4252 else if (element == EL_WALL_BD_DIAMOND)
4253 Store[x][y] = EL_BD_DIAMOND;
4254 else if (element == EL_WALL_EMERALD_YELLOW)
4255 Store[x][y] = EL_EMERALD_YELLOW;
4256 else if (element == EL_WALL_EMERALD_RED)
4257 Store[x][y] = EL_EMERALD_RED;
4258 else if (element == EL_WALL_EMERALD_PURPLE)
4259 Store[x][y] = EL_EMERALD_PURPLE;
4260 else if (element == EL_WALL_PEARL)
4261 Store[x][y] = EL_PEARL;
4262 else if (element == EL_WALL_CRYSTAL)
4263 Store[x][y] = EL_CRYSTAL;
4264 else if (IS_CUSTOM_ELEMENT(element) && !CAN_EXPLODE(element))
4265 Store[x][y] = element_info[element].content.e[1][1];
4267 Store[x][y] = EL_EMPTY;
4270 if (x != ex || y != ey || mode == EX_TYPE_BORDER ||
4271 center_element == EL_AMOEBA_TO_DIAMOND)
4272 Store2[x][y] = element;
4274 Feld[x][y] = EL_EXPLOSION;
4275 GfxElement[x][y] = artwork_element;
4278 printf(":: setting gfx(%d,%d) to %d ['%s']\n",
4279 x, y, artwork_element, EL_NAME(artwork_element));
4282 ExplodePhase[x][y] = 1;
4283 ExplodeDelay[x][y] = last_phase;
4288 if (center_element == EL_YAMYAM)
4289 game.yamyam_content_nr =
4290 (game.yamyam_content_nr + 1) % level.num_yamyam_contents;
4302 GfxFrame[x][y] = 0; /* restart explosion animation */
4304 last_phase = ExplodeDelay[x][y];
4306 ExplodePhase[x][y] = (phase < last_phase ? phase + 1 : 0);
4310 /* activate this even in non-DEBUG version until cause for crash in
4311 getGraphicAnimationFrame() (see below) is found and eliminated */
4317 /* this can happen if the player leaves an explosion just in time */
4318 if (GfxElement[x][y] == EL_UNDEFINED)
4319 GfxElement[x][y] = EL_EMPTY;
4321 if (GfxElement[x][y] == EL_UNDEFINED)
4324 printf("Explode(): x = %d, y = %d: GfxElement == EL_UNDEFINED\n", x, y);
4325 printf("Explode(): This should never happen!\n");
4328 GfxElement[x][y] = EL_EMPTY;
4334 border_element = Store2[x][y];
4335 if (IS_PLAYER(x, y) && !PLAYER_EXPLOSION_PROTECTED(x, y))
4336 border_element = StorePlayer[x][y];
4338 if (phase == element_info[border_element].ignition_delay ||
4339 phase == last_phase)
4341 boolean border_explosion = FALSE;
4343 if (IS_PLAYER(x, y) && PLAYERINFO(x, y)->present &&
4344 !PLAYER_EXPLOSION_PROTECTED(x, y))
4346 KillPlayerUnlessExplosionProtected(x, y);
4347 border_explosion = TRUE;
4349 else if (CAN_EXPLODE_BY_EXPLOSION(border_element))
4351 Feld[x][y] = Store2[x][y];
4354 border_explosion = TRUE;
4356 else if (border_element == EL_AMOEBA_TO_DIAMOND)
4358 AmoebeUmwandeln(x, y);
4360 border_explosion = TRUE;
4363 /* if an element just explodes due to another explosion (chain-reaction),
4364 do not immediately end the new explosion when it was the last frame of
4365 the explosion (as it would be done in the following "if"-statement!) */
4366 if (border_explosion && phase == last_phase)
4370 if (phase == last_phase)
4374 element = Feld[x][y] = Store[x][y];
4375 Store[x][y] = Store2[x][y] = 0;
4376 GfxElement[x][y] = EL_UNDEFINED;
4378 /* player can escape from explosions and might therefore be still alive */
4379 if (element >= EL_PLAYER_IS_EXPLODING_1 &&
4380 element <= EL_PLAYER_IS_EXPLODING_4)
4382 int player_nr = element - EL_PLAYER_IS_EXPLODING_1;
4383 int explosion_element = EL_PLAYER_1 + player_nr;
4384 int xx = MIN(MAX(0, x - stored_player[player_nr].jx + 1), 2);
4385 int yy = MIN(MAX(0, y - stored_player[player_nr].jy + 1), 2);
4387 if (level.use_explosion_element[player_nr])
4388 explosion_element = level.explosion_element[player_nr];
4390 Feld[x][y] = (stored_player[player_nr].active ? EL_EMPTY :
4391 element_info[explosion_element].content.e[xx][yy]);
4394 /* restore probably existing indestructible background element */
4395 if (Back[x][y] && IS_INDESTRUCTIBLE(Back[x][y]))
4396 element = Feld[x][y] = Back[x][y];
4399 MovDir[x][y] = MovPos[x][y] = MovDelay[x][y] = 0;
4400 GfxDir[x][y] = MV_NONE;
4401 ChangeDelay[x][y] = 0;
4402 ChangePage[x][y] = -1;
4404 #if USE_NEW_CUSTOM_VALUE
4405 CustomValue[x][y] = 0;
4408 InitField_WithBug2(x, y, FALSE);
4410 DrawLevelField(x, y);
4412 TestIfElementTouchesCustomElement(x, y);
4414 if (GFX_CRUMBLED(element))
4415 DrawLevelFieldCrumbledSandNeighbours(x, y);
4417 if (IS_PLAYER(x, y) && !PLAYERINFO(x, y)->present)
4418 StorePlayer[x][y] = 0;
4420 if (ELEM_IS_PLAYER(element))
4421 RelocatePlayer(x, y, element);
4423 else if (IN_SCR_FIELD(SCREENX(x), SCREENY(y)))
4425 int graphic = el_act2img(GfxElement[x][y], ACTION_EXPLODING);
4426 int frame = getGraphicAnimationFrame(graphic, GfxFrame[x][y]);
4429 DrawLevelFieldCrumbledSand(x, y);
4431 if (IS_WALKABLE_OVER(Back[x][y]) && Back[x][y] != EL_EMPTY)
4433 DrawLevelElement(x, y, Back[x][y]);
4434 DrawGraphicThruMask(SCREENX(x), SCREENY(y), graphic, frame);
4436 else if (IS_WALKABLE_UNDER(Back[x][y]))
4438 DrawGraphic(SCREENX(x), SCREENY(y), graphic, frame);
4439 DrawLevelElementThruMask(x, y, Back[x][y]);
4441 else if (!IS_WALKABLE_INSIDE(Back[x][y]))
4442 DrawGraphic(SCREENX(x), SCREENY(y), graphic, frame);
4446 void DynaExplode(int ex, int ey)
4449 int dynabomb_element = Feld[ex][ey];
4450 int dynabomb_size = 1;
4451 boolean dynabomb_xl = FALSE;
4452 struct PlayerInfo *player;
4453 static int xy[4][2] =
4461 if (IS_ACTIVE_BOMB(dynabomb_element))
4463 player = &stored_player[dynabomb_element - EL_DYNABOMB_PLAYER_1_ACTIVE];
4464 dynabomb_size = player->dynabomb_size;
4465 dynabomb_xl = player->dynabomb_xl;
4466 player->dynabombs_left++;
4469 Explode(ex, ey, EX_PHASE_START, EX_TYPE_CENTER);
4471 for (i = 0; i < NUM_DIRECTIONS; i++)
4473 for (j = 1; j <= dynabomb_size; j++)
4475 int x = ex + j * xy[i][0];
4476 int y = ey + j * xy[i][1];
4479 if (!IN_LEV_FIELD(x, y) || IS_INDESTRUCTIBLE(Feld[x][y]))
4482 element = Feld[x][y];
4484 /* do not restart explosions of fields with active bombs */
4485 if (element == EL_EXPLOSION && IS_ACTIVE_BOMB(Store2[x][y]))
4488 Explode(x, y, EX_PHASE_START, EX_TYPE_BORDER);
4490 if (element != EL_EMPTY && element != EL_EXPLOSION &&
4491 !IS_DIGGABLE(element) && !dynabomb_xl)
4497 void Bang(int x, int y)
4499 int element = MovingOrBlocked2Element(x, y);
4500 int explosion_type = EX_TYPE_NORMAL;
4502 if (IS_PLAYER(x, y) && !PLAYER_EXPLOSION_PROTECTED(x, y))
4504 struct PlayerInfo *player = PLAYERINFO(x, y);
4506 element = Feld[x][y] = (player->use_murphy ? EL_SP_MURPHY :
4507 player->element_nr);
4509 if (level.use_explosion_element[player->index_nr])
4511 int explosion_element = level.explosion_element[player->index_nr];
4513 if (element_info[explosion_element].explosion_type == EXPLODES_CROSS)
4514 explosion_type = EX_TYPE_CROSS;
4515 else if (element_info[explosion_element].explosion_type == EXPLODES_1X1)
4516 explosion_type = EX_TYPE_CENTER;
4524 case EL_BD_BUTTERFLY:
4527 case EL_DARK_YAMYAM:
4531 RaiseScoreElement(element);
4534 case EL_DYNABOMB_PLAYER_1_ACTIVE:
4535 case EL_DYNABOMB_PLAYER_2_ACTIVE:
4536 case EL_DYNABOMB_PLAYER_3_ACTIVE:
4537 case EL_DYNABOMB_PLAYER_4_ACTIVE:
4538 case EL_DYNABOMB_INCREASE_NUMBER:
4539 case EL_DYNABOMB_INCREASE_SIZE:
4540 case EL_DYNABOMB_INCREASE_POWER:
4541 explosion_type = EX_TYPE_DYNA;
4546 case EL_LAMP_ACTIVE:
4547 case EL_AMOEBA_TO_DIAMOND:
4548 if (!IS_PLAYER(x, y)) /* penguin and player may be at same field */
4549 explosion_type = EX_TYPE_CENTER;
4553 if (element_info[element].explosion_type == EXPLODES_CROSS)
4554 explosion_type = EX_TYPE_CROSS;
4555 else if (element_info[element].explosion_type == EXPLODES_1X1)
4556 explosion_type = EX_TYPE_CENTER;
4560 if (explosion_type == EX_TYPE_DYNA)
4563 Explode(x, y, EX_PHASE_START, explosion_type);
4565 CheckTriggeredElementChange(x, y, element, CE_EXPLOSION_OF_X);
4568 void SplashAcid(int x, int y)
4570 if (IN_LEV_FIELD(x - 1, y - 1) && IS_FREE(x - 1, y - 1) &&
4571 (!IN_LEV_FIELD(x - 1, y - 2) ||
4572 !CAN_FALL(MovingOrBlocked2Element(x - 1, y - 2))))
4573 Feld[x - 1][y - 1] = EL_ACID_SPLASH_LEFT;
4575 if (IN_LEV_FIELD(x + 1, y - 1) && IS_FREE(x + 1, y - 1) &&
4576 (!IN_LEV_FIELD(x + 1, y - 2) ||
4577 !CAN_FALL(MovingOrBlocked2Element(x + 1, y - 2))))
4578 Feld[x + 1][y - 1] = EL_ACID_SPLASH_RIGHT;
4580 PlayLevelSound(x, y, SND_ACID_SPLASHING);
4583 static void InitBeltMovement()
4585 static int belt_base_element[4] =
4587 EL_CONVEYOR_BELT_1_LEFT,
4588 EL_CONVEYOR_BELT_2_LEFT,
4589 EL_CONVEYOR_BELT_3_LEFT,
4590 EL_CONVEYOR_BELT_4_LEFT
4592 static int belt_base_active_element[4] =
4594 EL_CONVEYOR_BELT_1_LEFT_ACTIVE,
4595 EL_CONVEYOR_BELT_2_LEFT_ACTIVE,
4596 EL_CONVEYOR_BELT_3_LEFT_ACTIVE,
4597 EL_CONVEYOR_BELT_4_LEFT_ACTIVE
4602 /* set frame order for belt animation graphic according to belt direction */
4603 for (i = 0; i < NUM_BELTS; i++)
4607 for (j = 0; j < NUM_BELT_PARTS; j++)
4609 int element = belt_base_active_element[belt_nr] + j;
4610 int graphic = el2img(element);
4612 if (game.belt_dir[i] == MV_LEFT)
4613 graphic_info[graphic].anim_mode &= ~ANIM_REVERSE;
4615 graphic_info[graphic].anim_mode |= ANIM_REVERSE;
4620 SCAN_PLAYFIELD(x, y)
4622 for (y = 0; y < lev_fieldy; y++) for (x = 0; x < lev_fieldx; x++)
4625 int element = Feld[x][y];
4627 for (i = 0; i < NUM_BELTS; i++)
4629 if (IS_BELT(element) && game.belt_dir[i] != MV_NONE)
4631 int e_belt_nr = getBeltNrFromBeltElement(element);
4634 if (e_belt_nr == belt_nr)
4636 int belt_part = Feld[x][y] - belt_base_element[belt_nr];
4638 Feld[x][y] = belt_base_active_element[belt_nr] + belt_part;
4645 static void ToggleBeltSwitch(int x, int y)
4647 static int belt_base_element[4] =
4649 EL_CONVEYOR_BELT_1_LEFT,
4650 EL_CONVEYOR_BELT_2_LEFT,
4651 EL_CONVEYOR_BELT_3_LEFT,
4652 EL_CONVEYOR_BELT_4_LEFT
4654 static int belt_base_active_element[4] =
4656 EL_CONVEYOR_BELT_1_LEFT_ACTIVE,
4657 EL_CONVEYOR_BELT_2_LEFT_ACTIVE,
4658 EL_CONVEYOR_BELT_3_LEFT_ACTIVE,
4659 EL_CONVEYOR_BELT_4_LEFT_ACTIVE
4661 static int belt_base_switch_element[4] =
4663 EL_CONVEYOR_BELT_1_SWITCH_LEFT,
4664 EL_CONVEYOR_BELT_2_SWITCH_LEFT,
4665 EL_CONVEYOR_BELT_3_SWITCH_LEFT,
4666 EL_CONVEYOR_BELT_4_SWITCH_LEFT
4668 static int belt_move_dir[4] =
4676 int element = Feld[x][y];
4677 int belt_nr = getBeltNrFromBeltSwitchElement(element);
4678 int belt_dir_nr = (game.belt_dir_nr[belt_nr] + 1) % 4;
4679 int belt_dir = belt_move_dir[belt_dir_nr];
4682 if (!IS_BELT_SWITCH(element))
4685 game.belt_dir_nr[belt_nr] = belt_dir_nr;
4686 game.belt_dir[belt_nr] = belt_dir;
4688 if (belt_dir_nr == 3)
4691 /* set frame order for belt animation graphic according to belt direction */
4692 for (i = 0; i < NUM_BELT_PARTS; i++)
4694 int element = belt_base_active_element[belt_nr] + i;
4695 int graphic = el2img(element);
4697 if (belt_dir == MV_LEFT)
4698 graphic_info[graphic].anim_mode &= ~ANIM_REVERSE;
4700 graphic_info[graphic].anim_mode |= ANIM_REVERSE;
4704 SCAN_PLAYFIELD(xx, yy)
4706 for (yy = 0; yy < lev_fieldy; yy++) for (xx = 0; xx < lev_fieldx; xx++)
4709 int element = Feld[xx][yy];
4711 if (IS_BELT_SWITCH(element))
4713 int e_belt_nr = getBeltNrFromBeltSwitchElement(element);
4715 if (e_belt_nr == belt_nr)
4717 Feld[xx][yy] = belt_base_switch_element[belt_nr] + belt_dir_nr;
4718 DrawLevelField(xx, yy);
4721 else if (IS_BELT(element) && belt_dir != MV_NONE)
4723 int e_belt_nr = getBeltNrFromBeltElement(element);
4725 if (e_belt_nr == belt_nr)
4727 int belt_part = Feld[xx][yy] - belt_base_element[belt_nr];
4729 Feld[xx][yy] = belt_base_active_element[belt_nr] + belt_part;
4730 DrawLevelField(xx, yy);
4733 else if (IS_BELT_ACTIVE(element) && belt_dir == MV_NONE)
4735 int e_belt_nr = getBeltNrFromBeltActiveElement(element);
4737 if (e_belt_nr == belt_nr)
4739 int belt_part = Feld[xx][yy] - belt_base_active_element[belt_nr];
4741 Feld[xx][yy] = belt_base_element[belt_nr] + belt_part;
4742 DrawLevelField(xx, yy);
4748 static void ToggleSwitchgateSwitch(int x, int y)
4752 game.switchgate_pos = !game.switchgate_pos;
4755 SCAN_PLAYFIELD(xx, yy)
4757 for (yy = 0; yy < lev_fieldy; yy++) for (xx = 0; xx < lev_fieldx; xx++)
4760 int element = Feld[xx][yy];
4762 #if !USE_BOTH_SWITCHGATE_SWITCHES
4763 if (element == EL_SWITCHGATE_SWITCH_UP ||
4764 element == EL_SWITCHGATE_SWITCH_DOWN)
4766 Feld[xx][yy] = EL_SWITCHGATE_SWITCH_UP + game.switchgate_pos;
4767 DrawLevelField(xx, yy);
4770 if (element == EL_SWITCHGATE_SWITCH_UP)
4772 Feld[xx][yy] = EL_SWITCHGATE_SWITCH_DOWN;
4773 DrawLevelField(xx, yy);
4775 else if (element == EL_SWITCHGATE_SWITCH_DOWN)
4777 Feld[xx][yy] = EL_SWITCHGATE_SWITCH_UP;
4778 DrawLevelField(xx, yy);
4781 else if (element == EL_SWITCHGATE_OPEN ||
4782 element == EL_SWITCHGATE_OPENING)
4784 Feld[xx][yy] = EL_SWITCHGATE_CLOSING;
4786 PlayLevelSoundAction(xx, yy, ACTION_CLOSING);
4788 else if (element == EL_SWITCHGATE_CLOSED ||
4789 element == EL_SWITCHGATE_CLOSING)
4791 Feld[xx][yy] = EL_SWITCHGATE_OPENING;
4793 PlayLevelSoundAction(xx, yy, ACTION_OPENING);
4798 static int getInvisibleActiveFromInvisibleElement(int element)
4800 return (element == EL_INVISIBLE_STEELWALL ? EL_INVISIBLE_STEELWALL_ACTIVE :
4801 element == EL_INVISIBLE_WALL ? EL_INVISIBLE_WALL_ACTIVE :
4802 element == EL_INVISIBLE_SAND ? EL_INVISIBLE_SAND_ACTIVE :
4806 static int getInvisibleFromInvisibleActiveElement(int element)
4808 return (element == EL_INVISIBLE_STEELWALL_ACTIVE ? EL_INVISIBLE_STEELWALL :
4809 element == EL_INVISIBLE_WALL_ACTIVE ? EL_INVISIBLE_WALL :
4810 element == EL_INVISIBLE_SAND_ACTIVE ? EL_INVISIBLE_SAND :
4814 static void RedrawAllLightSwitchesAndInvisibleElements()
4819 SCAN_PLAYFIELD(x, y)
4821 for (y = 0; y < lev_fieldy; y++) for (x = 0; x < lev_fieldx; x++)
4824 int element = Feld[x][y];
4826 if (element == EL_LIGHT_SWITCH &&
4827 game.light_time_left > 0)
4829 Feld[x][y] = EL_LIGHT_SWITCH_ACTIVE;
4830 DrawLevelField(x, y);
4832 else if (element == EL_LIGHT_SWITCH_ACTIVE &&
4833 game.light_time_left == 0)
4835 Feld[x][y] = EL_LIGHT_SWITCH;
4836 DrawLevelField(x, y);
4838 else if (element == EL_EMC_DRIPPER &&
4839 game.light_time_left > 0)
4841 Feld[x][y] = EL_EMC_DRIPPER_ACTIVE;
4842 DrawLevelField(x, y);
4844 else if (element == EL_EMC_DRIPPER_ACTIVE &&
4845 game.light_time_left == 0)
4847 Feld[x][y] = EL_EMC_DRIPPER;
4848 DrawLevelField(x, y);
4850 else if (element == EL_INVISIBLE_STEELWALL ||
4851 element == EL_INVISIBLE_WALL ||
4852 element == EL_INVISIBLE_SAND)
4854 if (game.light_time_left > 0)
4855 Feld[x][y] = getInvisibleActiveFromInvisibleElement(element);
4857 DrawLevelField(x, y);
4859 /* uncrumble neighbour fields, if needed */
4860 if (element == EL_INVISIBLE_SAND)
4861 DrawLevelFieldCrumbledSandNeighbours(x, y);
4863 else if (element == EL_INVISIBLE_STEELWALL_ACTIVE ||
4864 element == EL_INVISIBLE_WALL_ACTIVE ||
4865 element == EL_INVISIBLE_SAND_ACTIVE)
4867 if (game.light_time_left == 0)
4868 Feld[x][y] = getInvisibleFromInvisibleActiveElement(element);
4870 DrawLevelField(x, y);
4872 /* re-crumble neighbour fields, if needed */
4873 if (element == EL_INVISIBLE_SAND)
4874 DrawLevelFieldCrumbledSandNeighbours(x, y);
4879 static void RedrawAllInvisibleElementsForLenses()
4884 SCAN_PLAYFIELD(x, y)
4886 for (y = 0; y < lev_fieldy; y++) for (x = 0; x < lev_fieldx; x++)
4889 int element = Feld[x][y];
4891 if (element == EL_EMC_DRIPPER &&
4892 game.lenses_time_left > 0)
4894 Feld[x][y] = EL_EMC_DRIPPER_ACTIVE;
4895 DrawLevelField(x, y);
4897 else if (element == EL_EMC_DRIPPER_ACTIVE &&
4898 game.lenses_time_left == 0)
4900 Feld[x][y] = EL_EMC_DRIPPER;
4901 DrawLevelField(x, y);
4903 else if (element == EL_INVISIBLE_STEELWALL ||
4904 element == EL_INVISIBLE_WALL ||
4905 element == EL_INVISIBLE_SAND)
4907 if (game.lenses_time_left > 0)
4908 Feld[x][y] = getInvisibleActiveFromInvisibleElement(element);
4910 DrawLevelField(x, y);
4912 /* uncrumble neighbour fields, if needed */
4913 if (element == EL_INVISIBLE_SAND)
4914 DrawLevelFieldCrumbledSandNeighbours(x, y);
4916 else if (element == EL_INVISIBLE_STEELWALL_ACTIVE ||
4917 element == EL_INVISIBLE_WALL_ACTIVE ||
4918 element == EL_INVISIBLE_SAND_ACTIVE)
4920 if (game.lenses_time_left == 0)
4921 Feld[x][y] = getInvisibleFromInvisibleActiveElement(element);
4923 DrawLevelField(x, y);
4925 /* re-crumble neighbour fields, if needed */
4926 if (element == EL_INVISIBLE_SAND)
4927 DrawLevelFieldCrumbledSandNeighbours(x, y);
4932 static void RedrawAllInvisibleElementsForMagnifier()
4937 SCAN_PLAYFIELD(x, y)
4939 for (y = 0; y < lev_fieldy; y++) for (x = 0; x < lev_fieldx; x++)
4942 int element = Feld[x][y];
4944 if (element == EL_EMC_FAKE_GRASS &&
4945 game.magnify_time_left > 0)
4947 Feld[x][y] = EL_EMC_FAKE_GRASS_ACTIVE;
4948 DrawLevelField(x, y);
4950 else if (element == EL_EMC_FAKE_GRASS_ACTIVE &&
4951 game.magnify_time_left == 0)
4953 Feld[x][y] = EL_EMC_FAKE_GRASS;
4954 DrawLevelField(x, y);
4956 else if (IS_GATE_GRAY(element) &&
4957 game.magnify_time_left > 0)
4959 Feld[x][y] = (IS_RND_GATE_GRAY(element) ?
4960 element - EL_GATE_1_GRAY + EL_GATE_1_GRAY_ACTIVE :
4961 IS_EM_GATE_GRAY(element) ?
4962 element - EL_EM_GATE_1_GRAY + EL_EM_GATE_1_GRAY_ACTIVE :
4963 IS_EMC_GATE_GRAY(element) ?
4964 element - EL_EMC_GATE_5_GRAY + EL_EMC_GATE_5_GRAY_ACTIVE :
4966 DrawLevelField(x, y);
4968 else if (IS_GATE_GRAY_ACTIVE(element) &&
4969 game.magnify_time_left == 0)
4971 Feld[x][y] = (IS_RND_GATE_GRAY_ACTIVE(element) ?
4972 element - EL_GATE_1_GRAY_ACTIVE + EL_GATE_1_GRAY :
4973 IS_EM_GATE_GRAY_ACTIVE(element) ?
4974 element - EL_EM_GATE_1_GRAY_ACTIVE + EL_EM_GATE_1_GRAY :
4975 IS_EMC_GATE_GRAY_ACTIVE(element) ?
4976 element - EL_EMC_GATE_5_GRAY_ACTIVE + EL_EMC_GATE_5_GRAY :
4978 DrawLevelField(x, y);
4983 static void ToggleLightSwitch(int x, int y)
4985 int element = Feld[x][y];
4987 game.light_time_left =
4988 (element == EL_LIGHT_SWITCH ?
4989 level.time_light * FRAMES_PER_SECOND : 0);
4991 RedrawAllLightSwitchesAndInvisibleElements();
4994 static void ActivateTimegateSwitch(int x, int y)
4998 game.timegate_time_left = level.time_timegate * FRAMES_PER_SECOND;
5001 SCAN_PLAYFIELD(xx, yy)
5003 for (yy = 0; yy < lev_fieldy; yy++) for (xx = 0; xx < lev_fieldx; xx++)
5006 int element = Feld[xx][yy];
5008 if (element == EL_TIMEGATE_CLOSED ||
5009 element == EL_TIMEGATE_CLOSING)
5011 Feld[xx][yy] = EL_TIMEGATE_OPENING;
5012 PlayLevelSound(xx, yy, SND_TIMEGATE_OPENING);
5016 else if (element == EL_TIMEGATE_SWITCH_ACTIVE)
5018 Feld[xx][yy] = EL_TIMEGATE_SWITCH;
5019 DrawLevelField(xx, yy);
5025 Feld[x][y] = EL_TIMEGATE_SWITCH_ACTIVE;
5028 void Impact(int x, int y)
5030 boolean last_line = (y == lev_fieldy - 1);
5031 boolean object_hit = FALSE;
5032 boolean impact = (last_line || object_hit);
5033 int element = Feld[x][y];
5034 int smashed = EL_STEELWALL;
5036 if (!last_line) /* check if element below was hit */
5038 if (Feld[x][y + 1] == EL_PLAYER_IS_LEAVING)
5041 object_hit = (!IS_FREE(x, y + 1) && (!IS_MOVING(x, y + 1) ||
5042 MovDir[x][y + 1] != MV_DOWN ||
5043 MovPos[x][y + 1] <= TILEY / 2));
5045 /* do not smash moving elements that left the smashed field in time */
5046 if (game.engine_version >= VERSION_IDENT(2,2,0,7) && IS_MOVING(x, y + 1) &&
5047 ABS(MovPos[x][y + 1] + getElementMoveStepsize(x, y + 1)) >= TILEX)
5050 #if USE_QUICKSAND_IMPACT_BUGFIX
5051 if (Feld[x][y + 1] == EL_QUICKSAND_EMPTYING && object_hit == FALSE)
5053 RemoveMovingField(x, y + 1);
5054 Feld[x][y + 1] = EL_QUICKSAND_EMPTY;
5055 Feld[x][y + 2] = EL_ROCK;
5056 DrawLevelField(x, y + 2);
5063 smashed = MovingOrBlocked2Element(x, y + 1);
5065 impact = (last_line || object_hit);
5068 if (!last_line && smashed == EL_ACID) /* element falls into acid */
5070 SplashAcid(x, y + 1);
5074 /* !!! not sufficient for all cases -- see EL_PEARL below !!! */
5075 /* only reset graphic animation if graphic really changes after impact */
5077 el_act_dir2img(element, GfxAction[x][y], MV_DOWN) != el2img(element))
5079 ResetGfxAnimation(x, y);
5080 DrawLevelField(x, y);
5083 if (impact && CAN_EXPLODE_IMPACT(element))
5088 else if (impact && element == EL_PEARL)
5090 ResetGfxAnimation(x, y);
5092 Feld[x][y] = EL_PEARL_BREAKING;
5093 PlayLevelSound(x, y, SND_PEARL_BREAKING);
5096 else if (impact && CheckElementChange(x, y, element, smashed, CE_IMPACT))
5098 PlayLevelSoundElementAction(x, y, element, ACTION_IMPACT);
5103 if (impact && element == EL_AMOEBA_DROP)
5105 if (object_hit && IS_PLAYER(x, y + 1))
5106 KillPlayerUnlessEnemyProtected(x, y + 1);
5107 else if (object_hit && smashed == EL_PENGUIN)
5111 Feld[x][y] = EL_AMOEBA_GROWING;
5112 Store[x][y] = EL_AMOEBA_WET;
5114 ResetRandomAnimationValue(x, y);
5119 if (object_hit) /* check which object was hit */
5121 if (CAN_PASS_MAGIC_WALL(element) &&
5122 (smashed == EL_MAGIC_WALL ||
5123 smashed == EL_BD_MAGIC_WALL))
5126 int activated_magic_wall =
5127 (smashed == EL_MAGIC_WALL ? EL_MAGIC_WALL_ACTIVE :
5128 EL_BD_MAGIC_WALL_ACTIVE);
5130 /* activate magic wall / mill */
5132 SCAN_PLAYFIELD(xx, yy)
5134 for (yy = 0; yy < lev_fieldy; yy++) for (xx = 0; xx < lev_fieldx; xx++)
5136 if (Feld[xx][yy] == smashed)
5137 Feld[xx][yy] = activated_magic_wall;
5139 game.magic_wall_time_left = level.time_magic_wall * FRAMES_PER_SECOND;
5140 game.magic_wall_active = TRUE;
5142 PlayLevelSound(x, y, (smashed == EL_MAGIC_WALL ?
5143 SND_MAGIC_WALL_ACTIVATING :
5144 SND_BD_MAGIC_WALL_ACTIVATING));
5147 if (IS_PLAYER(x, y + 1))
5149 if (CAN_SMASH_PLAYER(element))
5151 KillPlayerUnlessEnemyProtected(x, y + 1);
5155 else if (smashed == EL_PENGUIN)
5157 if (CAN_SMASH_PLAYER(element))
5163 else if (element == EL_BD_DIAMOND)
5165 if (IS_CLASSIC_ENEMY(smashed) && IS_BD_ELEMENT(smashed))
5171 else if (((element == EL_SP_INFOTRON ||
5172 element == EL_SP_ZONK) &&
5173 (smashed == EL_SP_SNIKSNAK ||
5174 smashed == EL_SP_ELECTRON ||
5175 smashed == EL_SP_DISK_ORANGE)) ||
5176 (element == EL_SP_INFOTRON &&
5177 smashed == EL_SP_DISK_YELLOW))
5182 else if (CAN_SMASH_EVERYTHING(element))
5184 if (IS_CLASSIC_ENEMY(smashed) ||
5185 CAN_EXPLODE_SMASHED(smashed))
5190 else if (!IS_MOVING(x, y + 1) && !IS_BLOCKED(x, y + 1))
5192 if (smashed == EL_LAMP ||
5193 smashed == EL_LAMP_ACTIVE)
5198 else if (smashed == EL_NUT)
5200 Feld[x][y + 1] = EL_NUT_BREAKING;
5201 PlayLevelSound(x, y, SND_NUT_BREAKING);
5202 RaiseScoreElement(EL_NUT);
5205 else if (smashed == EL_PEARL)
5207 ResetGfxAnimation(x, y);
5209 Feld[x][y + 1] = EL_PEARL_BREAKING;
5210 PlayLevelSound(x, y, SND_PEARL_BREAKING);
5213 else if (smashed == EL_DIAMOND)
5215 Feld[x][y + 1] = EL_DIAMOND_BREAKING;
5216 PlayLevelSound(x, y, SND_DIAMOND_BREAKING);
5219 else if (IS_BELT_SWITCH(smashed))
5221 ToggleBeltSwitch(x, y + 1);
5223 else if (smashed == EL_SWITCHGATE_SWITCH_UP ||
5224 smashed == EL_SWITCHGATE_SWITCH_DOWN)
5226 ToggleSwitchgateSwitch(x, y + 1);
5228 else if (smashed == EL_LIGHT_SWITCH ||
5229 smashed == EL_LIGHT_SWITCH_ACTIVE)
5231 ToggleLightSwitch(x, y + 1);
5236 TestIfElementSmashesCustomElement(x, y, MV_DOWN);
5239 CheckElementChange(x, y + 1, smashed, element, CE_SMASHED);
5241 CheckElementChangeBySide(x, y + 1, smashed, element,
5242 CE_SWITCHED, CH_SIDE_TOP);
5243 CheckTriggeredElementChangeBySide(x, y + 1, smashed, CE_SWITCH_OF_X,
5249 CheckElementChange(x, y + 1, smashed, element, CE_SMASHED);
5254 /* play sound of magic wall / mill */
5256 (Feld[x][y + 1] == EL_MAGIC_WALL_ACTIVE ||
5257 Feld[x][y + 1] == EL_BD_MAGIC_WALL_ACTIVE))
5259 if (Feld[x][y + 1] == EL_MAGIC_WALL_ACTIVE)
5260 PlayLevelSound(x, y, SND_MAGIC_WALL_FILLING);
5261 else if (Feld[x][y + 1] == EL_BD_MAGIC_WALL_ACTIVE)
5262 PlayLevelSound(x, y, SND_BD_MAGIC_WALL_FILLING);
5267 /* play sound of object that hits the ground */
5268 if (last_line || object_hit)
5269 PlayLevelSoundElementAction(x, y, element, ACTION_IMPACT);
5272 inline static void TurnRoundExt(int x, int y)
5284 { 0, 0 }, { 0, 0 }, { 0, 0 },
5289 int left, right, back;
5293 { MV_DOWN, MV_UP, MV_RIGHT },
5294 { MV_UP, MV_DOWN, MV_LEFT },
5296 { MV_LEFT, MV_RIGHT, MV_DOWN },
5300 { MV_RIGHT, MV_LEFT, MV_UP }
5303 int element = Feld[x][y];
5304 int move_pattern = element_info[element].move_pattern;
5306 int old_move_dir = MovDir[x][y];
5307 int left_dir = turn[old_move_dir].left;
5308 int right_dir = turn[old_move_dir].right;
5309 int back_dir = turn[old_move_dir].back;
5311 int left_dx = move_xy[left_dir].dx, left_dy = move_xy[left_dir].dy;
5312 int right_dx = move_xy[right_dir].dx, right_dy = move_xy[right_dir].dy;
5313 int move_dx = move_xy[old_move_dir].dx, move_dy = move_xy[old_move_dir].dy;
5314 int back_dx = move_xy[back_dir].dx, back_dy = move_xy[back_dir].dy;
5316 int left_x = x + left_dx, left_y = y + left_dy;
5317 int right_x = x + right_dx, right_y = y + right_dy;
5318 int move_x = x + move_dx, move_y = y + move_dy;
5322 if (element == EL_BUG || element == EL_BD_BUTTERFLY)
5324 TestIfBadThingTouchesOtherBadThing(x, y);
5326 if (ENEMY_CAN_ENTER_FIELD(element, right_x, right_y))
5327 MovDir[x][y] = right_dir;
5328 else if (!ENEMY_CAN_ENTER_FIELD(element, move_x, move_y))
5329 MovDir[x][y] = left_dir;
5331 if (element == EL_BUG && MovDir[x][y] != old_move_dir)
5333 else if (element == EL_BD_BUTTERFLY) /* && MovDir[x][y] == left_dir) */
5336 else if (element == EL_SPACESHIP || element == EL_BD_FIREFLY)
5338 TestIfBadThingTouchesOtherBadThing(x, y);
5340 if (ENEMY_CAN_ENTER_FIELD(element, left_x, left_y))
5341 MovDir[x][y] = left_dir;
5342 else if (!ENEMY_CAN_ENTER_FIELD(element, move_x, move_y))
5343 MovDir[x][y] = right_dir;
5345 if (element == EL_SPACESHIP && MovDir[x][y] != old_move_dir)
5347 else if (element == EL_BD_FIREFLY) /* && MovDir[x][y] == right_dir) */
5350 else if (element == EL_SP_SNIKSNAK || element == EL_SP_ELECTRON)
5352 TestIfBadThingTouchesOtherBadThing(x, y);
5354 if (ELEMENT_CAN_ENTER_FIELD_BASE_4(element, left_x, left_y, 0))
5355 MovDir[x][y] = left_dir;
5356 else if (!ELEMENT_CAN_ENTER_FIELD_BASE_4(element, move_x, move_y, 0))
5357 MovDir[x][y] = right_dir;
5359 if (MovDir[x][y] != old_move_dir)
5362 else if (element == EL_YAMYAM)
5364 boolean can_turn_left = YAMYAM_CAN_ENTER_FIELD(element, left_x, left_y);
5365 boolean can_turn_right = YAMYAM_CAN_ENTER_FIELD(element, right_x, right_y);
5367 if (can_turn_left && can_turn_right)
5368 MovDir[x][y] = (RND(3) ? (RND(2) ? left_dir : right_dir) : back_dir);
5369 else if (can_turn_left)
5370 MovDir[x][y] = (RND(2) ? left_dir : back_dir);
5371 else if (can_turn_right)
5372 MovDir[x][y] = (RND(2) ? right_dir : back_dir);
5374 MovDir[x][y] = back_dir;
5376 MovDelay[x][y] = 16 + 16 * RND(3);
5378 else if (element == EL_DARK_YAMYAM)
5380 boolean can_turn_left = DARK_YAMYAM_CAN_ENTER_FIELD(element,
5382 boolean can_turn_right = DARK_YAMYAM_CAN_ENTER_FIELD(element,
5385 if (can_turn_left && can_turn_right)
5386 MovDir[x][y] = (RND(3) ? (RND(2) ? left_dir : right_dir) : back_dir);
5387 else if (can_turn_left)
5388 MovDir[x][y] = (RND(2) ? left_dir : back_dir);
5389 else if (can_turn_right)
5390 MovDir[x][y] = (RND(2) ? right_dir : back_dir);
5392 MovDir[x][y] = back_dir;
5394 MovDelay[x][y] = 16 + 16 * RND(3);
5396 else if (element == EL_PACMAN)
5398 boolean can_turn_left = PACMAN_CAN_ENTER_FIELD(element, left_x, left_y);
5399 boolean can_turn_right = PACMAN_CAN_ENTER_FIELD(element, right_x, right_y);
5401 if (can_turn_left && can_turn_right)
5402 MovDir[x][y] = (RND(3) ? (RND(2) ? left_dir : right_dir) : back_dir);
5403 else if (can_turn_left)
5404 MovDir[x][y] = (RND(2) ? left_dir : back_dir);
5405 else if (can_turn_right)
5406 MovDir[x][y] = (RND(2) ? right_dir : back_dir);
5408 MovDir[x][y] = back_dir;
5410 MovDelay[x][y] = 6 + RND(40);
5412 else if (element == EL_PIG)
5414 boolean can_turn_left = PIG_CAN_ENTER_FIELD(element, left_x, left_y);
5415 boolean can_turn_right = PIG_CAN_ENTER_FIELD(element, right_x, right_y);
5416 boolean can_move_on = PIG_CAN_ENTER_FIELD(element, move_x, move_y);
5417 boolean should_turn_left, should_turn_right, should_move_on;
5419 int rnd = RND(rnd_value);
5421 should_turn_left = (can_turn_left &&
5423 IN_LEV_FIELD_AND_NOT_FREE(x + back_dx + left_dx,
5424 y + back_dy + left_dy)));
5425 should_turn_right = (can_turn_right &&
5427 IN_LEV_FIELD_AND_NOT_FREE(x + back_dx + right_dx,
5428 y + back_dy + right_dy)));
5429 should_move_on = (can_move_on &&
5432 IN_LEV_FIELD_AND_NOT_FREE(x + move_dx + left_dx,
5433 y + move_dy + left_dy) ||
5434 IN_LEV_FIELD_AND_NOT_FREE(x + move_dx + right_dx,
5435 y + move_dy + right_dy)));
5437 if (should_turn_left || should_turn_right || should_move_on)
5439 if (should_turn_left && should_turn_right && should_move_on)
5440 MovDir[x][y] = (rnd < rnd_value / 3 ? left_dir :
5441 rnd < 2 * rnd_value / 3 ? right_dir :
5443 else if (should_turn_left && should_turn_right)
5444 MovDir[x][y] = (rnd < rnd_value / 2 ? left_dir : right_dir);
5445 else if (should_turn_left && should_move_on)
5446 MovDir[x][y] = (rnd < rnd_value / 2 ? left_dir : old_move_dir);
5447 else if (should_turn_right && should_move_on)
5448 MovDir[x][y] = (rnd < rnd_value / 2 ? right_dir : old_move_dir);
5449 else if (should_turn_left)
5450 MovDir[x][y] = left_dir;
5451 else if (should_turn_right)
5452 MovDir[x][y] = right_dir;
5453 else if (should_move_on)
5454 MovDir[x][y] = old_move_dir;
5456 else if (can_move_on && rnd > rnd_value / 8)
5457 MovDir[x][y] = old_move_dir;
5458 else if (can_turn_left && can_turn_right)
5459 MovDir[x][y] = (rnd < rnd_value / 2 ? left_dir : right_dir);
5460 else if (can_turn_left && rnd > rnd_value / 8)
5461 MovDir[x][y] = left_dir;
5462 else if (can_turn_right && rnd > rnd_value/8)
5463 MovDir[x][y] = right_dir;
5465 MovDir[x][y] = back_dir;
5467 xx = x + move_xy[MovDir[x][y]].dx;
5468 yy = y + move_xy[MovDir[x][y]].dy;
5470 if (!IN_LEV_FIELD(xx, yy) ||
5471 (!IS_FREE(xx, yy) && !IS_FOOD_PIG(Feld[xx][yy])))
5472 MovDir[x][y] = old_move_dir;
5476 else if (element == EL_DRAGON)
5478 boolean can_turn_left = DRAGON_CAN_ENTER_FIELD(element, left_x, left_y);
5479 boolean can_turn_right = DRAGON_CAN_ENTER_FIELD(element, right_x, right_y);
5480 boolean can_move_on = DRAGON_CAN_ENTER_FIELD(element, move_x, move_y);
5482 int rnd = RND(rnd_value);
5484 if (can_move_on && rnd > rnd_value / 8)
5485 MovDir[x][y] = old_move_dir;
5486 else if (can_turn_left && can_turn_right)
5487 MovDir[x][y] = (rnd < rnd_value / 2 ? left_dir : right_dir);
5488 else if (can_turn_left && rnd > rnd_value / 8)
5489 MovDir[x][y] = left_dir;
5490 else if (can_turn_right && rnd > rnd_value / 8)
5491 MovDir[x][y] = right_dir;
5493 MovDir[x][y] = back_dir;
5495 xx = x + move_xy[MovDir[x][y]].dx;
5496 yy = y + move_xy[MovDir[x][y]].dy;
5498 if (!IN_LEV_FIELD_AND_IS_FREE(xx, yy))
5499 MovDir[x][y] = old_move_dir;
5503 else if (element == EL_MOLE)
5505 boolean can_move_on =
5506 (MOLE_CAN_ENTER_FIELD(element, move_x, move_y,
5507 IS_AMOEBOID(Feld[move_x][move_y]) ||
5508 Feld[move_x][move_y] == EL_AMOEBA_SHRINKING));
5511 boolean can_turn_left =
5512 (MOLE_CAN_ENTER_FIELD(element, left_x, left_y,
5513 IS_AMOEBOID(Feld[left_x][left_y])));
5515 boolean can_turn_right =
5516 (MOLE_CAN_ENTER_FIELD(element, right_x, right_y,
5517 IS_AMOEBOID(Feld[right_x][right_y])));
5519 if (can_turn_left && can_turn_right)
5520 MovDir[x][y] = (RND(2) ? left_dir : right_dir);
5521 else if (can_turn_left)
5522 MovDir[x][y] = left_dir;
5524 MovDir[x][y] = right_dir;
5527 if (MovDir[x][y] != old_move_dir)
5530 else if (element == EL_BALLOON)
5532 MovDir[x][y] = game.wind_direction;
5535 else if (element == EL_SPRING)
5537 #if USE_NEW_SPRING_BUMPER
5538 if (MovDir[x][y] & MV_HORIZONTAL)
5540 if (SPRING_CAN_BUMP_FROM_FIELD(move_x, move_y) &&
5541 !SPRING_CAN_ENTER_FIELD(element, x, y + 1))
5543 Feld[move_x][move_y] = EL_EMC_SPRING_BUMPER_ACTIVE;
5544 ResetGfxAnimation(move_x, move_y);
5545 DrawLevelField(move_x, move_y);
5547 MovDir[x][y] = back_dir;
5549 else if (!SPRING_CAN_ENTER_FIELD(element, move_x, move_y) ||
5550 SPRING_CAN_ENTER_FIELD(element, x, y + 1))
5551 MovDir[x][y] = MV_NONE;
5554 if (MovDir[x][y] & MV_HORIZONTAL &&
5555 (!SPRING_CAN_ENTER_FIELD(element, move_x, move_y) ||
5556 SPRING_CAN_ENTER_FIELD(element, x, y + 1)))
5557 MovDir[x][y] = MV_NONE;
5562 else if (element == EL_ROBOT ||
5563 element == EL_SATELLITE ||
5564 element == EL_PENGUIN ||
5565 element == EL_EMC_ANDROID)
5567 int attr_x = -1, attr_y = -1;
5578 for (i = 0; i < MAX_PLAYERS; i++)
5580 struct PlayerInfo *player = &stored_player[i];
5581 int jx = player->jx, jy = player->jy;
5583 if (!player->active)
5587 ABS(jx - x) + ABS(jy - y) < ABS(attr_x - x) + ABS(attr_y - y))
5595 if (element == EL_ROBOT && ZX >= 0 && ZY >= 0 &&
5596 (Feld[ZX][ZY] == EL_ROBOT_WHEEL_ACTIVE ||
5597 game.engine_version < VERSION_IDENT(3,1,0,0)))
5603 if (element == EL_PENGUIN)
5606 static int xy[4][2] =
5614 for (i = 0; i < NUM_DIRECTIONS; i++)
5616 int ex = x + xy[i][0];
5617 int ey = y + xy[i][1];
5619 if (IN_LEV_FIELD(ex, ey) && Feld[ex][ey] == EL_EXIT_OPEN)
5628 MovDir[x][y] = MV_NONE;
5630 MovDir[x][y] |= (AllPlayersGone ? MV_RIGHT : MV_LEFT);
5631 else if (attr_x > x)
5632 MovDir[x][y] |= (AllPlayersGone ? MV_LEFT : MV_RIGHT);
5634 MovDir[x][y] |= (AllPlayersGone ? MV_DOWN : MV_UP);
5635 else if (attr_y > y)
5636 MovDir[x][y] |= (AllPlayersGone ? MV_UP : MV_DOWN);
5638 if (element == EL_ROBOT)
5642 if (MovDir[x][y] & MV_HORIZONTAL && MovDir[x][y] & MV_VERTICAL)
5643 MovDir[x][y] &= (RND(2) ? MV_HORIZONTAL : MV_VERTICAL);
5644 Moving2Blocked(x, y, &newx, &newy);
5646 if (IN_LEV_FIELD(newx, newy) && IS_FREE_OR_PLAYER(newx, newy))
5647 MovDelay[x][y] = 8 + 8 * !RND(3);
5649 MovDelay[x][y] = 16;
5651 else if (element == EL_PENGUIN)
5657 if (MovDir[x][y] & MV_HORIZONTAL && MovDir[x][y] & MV_VERTICAL)
5659 boolean first_horiz = RND(2);
5660 int new_move_dir = MovDir[x][y];
5663 new_move_dir & (first_horiz ? MV_HORIZONTAL : MV_VERTICAL);
5664 Moving2Blocked(x, y, &newx, &newy);
5666 if (PENGUIN_CAN_ENTER_FIELD(element, newx, newy))
5670 new_move_dir & (!first_horiz ? MV_HORIZONTAL : MV_VERTICAL);
5671 Moving2Blocked(x, y, &newx, &newy);
5673 if (PENGUIN_CAN_ENTER_FIELD(element, newx, newy))
5676 MovDir[x][y] = old_move_dir;
5680 else if (element == EL_SATELLITE)
5686 if (MovDir[x][y] & MV_HORIZONTAL && MovDir[x][y] & MV_VERTICAL)
5688 boolean first_horiz = RND(2);
5689 int new_move_dir = MovDir[x][y];
5692 new_move_dir & (first_horiz ? MV_HORIZONTAL : MV_VERTICAL);
5693 Moving2Blocked(x, y, &newx, &newy);
5695 if (SATELLITE_CAN_ENTER_FIELD(newx, newy))
5699 new_move_dir & (!first_horiz ? MV_HORIZONTAL : MV_VERTICAL);
5700 Moving2Blocked(x, y, &newx, &newy);
5702 if (SATELLITE_CAN_ENTER_FIELD(newx, newy))
5705 MovDir[x][y] = old_move_dir;
5709 else if (element == EL_EMC_ANDROID)
5711 static int check_pos[16] =
5713 -1, /* 0 => (invalid) */
5714 7, /* 1 => MV_LEFT */
5715 3, /* 2 => MV_RIGHT */
5716 -1, /* 3 => (invalid) */
5718 0, /* 5 => MV_LEFT | MV_UP */
5719 2, /* 6 => MV_RIGHT | MV_UP */
5720 -1, /* 7 => (invalid) */
5721 5, /* 8 => MV_DOWN */
5722 6, /* 9 => MV_LEFT | MV_DOWN */
5723 4, /* 10 => MV_RIGHT | MV_DOWN */
5724 -1, /* 11 => (invalid) */
5725 -1, /* 12 => (invalid) */
5726 -1, /* 13 => (invalid) */
5727 -1, /* 14 => (invalid) */
5728 -1, /* 15 => (invalid) */
5736 { -1, -1, MV_LEFT | MV_UP },
5738 { +1, -1, MV_RIGHT | MV_UP },
5739 { +1, 0, MV_RIGHT },
5740 { +1, +1, MV_RIGHT | MV_DOWN },
5742 { -1, +1, MV_LEFT | MV_DOWN },
5745 int start_pos, check_order;
5746 boolean can_clone = FALSE;
5749 /* check if there is any free field around current position */
5750 for (i = 0; i < 8; i++)
5752 int newx = x + check_xy[i].dx;
5753 int newy = y + check_xy[i].dy;
5755 if (IN_LEV_FIELD_AND_IS_FREE(newx, newy))
5763 if (can_clone) /* randomly find an element to clone */
5767 start_pos = check_pos[RND(8)];
5768 check_order = (RND(2) ? -1 : +1);
5770 for (i = 0; i < 8; i++)
5772 int pos_raw = start_pos + i * check_order;
5773 int pos = (pos_raw + 8) % 8;
5774 int newx = x + check_xy[pos].dx;
5775 int newy = y + check_xy[pos].dy;
5777 if (ANDROID_CAN_CLONE_FIELD(newx, newy))
5779 element_info[element].move_leave_type = LEAVE_TYPE_LIMITED;
5780 element_info[element].move_leave_element = EL_TRIGGER_ELEMENT;
5782 Store[x][y] = Feld[newx][newy];
5791 if (can_clone) /* randomly find a direction to move */
5795 start_pos = check_pos[RND(8)];
5796 check_order = (RND(2) ? -1 : +1);
5798 for (i = 0; i < 8; i++)
5800 int pos_raw = start_pos + i * check_order;
5801 int pos = (pos_raw + 8) % 8;
5802 int newx = x + check_xy[pos].dx;
5803 int newy = y + check_xy[pos].dy;
5804 int new_move_dir = check_xy[pos].dir;
5806 if (IN_LEV_FIELD_AND_IS_FREE(newx, newy))
5808 MovDir[x][y] = new_move_dir;
5809 MovDelay[x][y] = level.android_clone_time * 8 + 1;
5818 if (can_clone) /* cloning and moving successful */
5821 /* cannot clone -- try to move towards player */
5823 start_pos = check_pos[MovDir[x][y] & 0x0f];
5824 check_order = (RND(2) ? -1 : +1);
5826 for (i = 0; i < 3; i++)
5828 /* first check start_pos, then previous/next or (next/previous) pos */
5829 int pos_raw = start_pos + (i < 2 ? i : -1) * check_order;
5830 int pos = (pos_raw + 8) % 8;
5831 int newx = x + check_xy[pos].dx;
5832 int newy = y + check_xy[pos].dy;
5833 int new_move_dir = check_xy[pos].dir;
5835 if (IS_PLAYER(newx, newy))
5838 if (ANDROID_CAN_ENTER_FIELD(element, newx, newy))
5840 MovDir[x][y] = new_move_dir;
5841 MovDelay[x][y] = level.android_move_time * 8 + 1;
5848 else if (move_pattern == MV_TURNING_LEFT ||
5849 move_pattern == MV_TURNING_RIGHT ||
5850 move_pattern == MV_TURNING_LEFT_RIGHT ||
5851 move_pattern == MV_TURNING_RIGHT_LEFT ||
5852 move_pattern == MV_TURNING_RANDOM ||
5853 move_pattern == MV_ALL_DIRECTIONS)
5855 boolean can_turn_left =
5856 CUSTOM_ELEMENT_CAN_ENTER_FIELD(element, left_x, left_y);
5857 boolean can_turn_right =
5858 CUSTOM_ELEMENT_CAN_ENTER_FIELD(element, right_x,right_y);
5860 if (element_info[element].move_stepsize == 0) /* "not moving" */
5863 if (move_pattern == MV_TURNING_LEFT)
5864 MovDir[x][y] = left_dir;
5865 else if (move_pattern == MV_TURNING_RIGHT)
5866 MovDir[x][y] = right_dir;
5867 else if (move_pattern == MV_TURNING_LEFT_RIGHT)
5868 MovDir[x][y] = (can_turn_left || !can_turn_right ? left_dir : right_dir);
5869 else if (move_pattern == MV_TURNING_RIGHT_LEFT)
5870 MovDir[x][y] = (can_turn_right || !can_turn_left ? right_dir : left_dir);
5871 else if (move_pattern == MV_TURNING_RANDOM)
5872 MovDir[x][y] = (can_turn_left && !can_turn_right ? left_dir :
5873 can_turn_right && !can_turn_left ? right_dir :
5874 RND(2) ? left_dir : right_dir);
5875 else if (can_turn_left && can_turn_right)
5876 MovDir[x][y] = (RND(3) ? (RND(2) ? left_dir : right_dir) : back_dir);
5877 else if (can_turn_left)
5878 MovDir[x][y] = (RND(2) ? left_dir : back_dir);
5879 else if (can_turn_right)
5880 MovDir[x][y] = (RND(2) ? right_dir : back_dir);
5882 MovDir[x][y] = back_dir;
5884 MovDelay[x][y] = GET_NEW_MOVE_DELAY(element);
5886 else if (move_pattern == MV_HORIZONTAL ||
5887 move_pattern == MV_VERTICAL)
5889 if (move_pattern & old_move_dir)
5890 MovDir[x][y] = back_dir;
5891 else if (move_pattern == MV_HORIZONTAL)
5892 MovDir[x][y] = (RND(2) ? MV_LEFT : MV_RIGHT);
5893 else if (move_pattern == MV_VERTICAL)
5894 MovDir[x][y] = (RND(2) ? MV_UP : MV_DOWN);
5896 MovDelay[x][y] = GET_NEW_MOVE_DELAY(element);
5898 else if (move_pattern & MV_ANY_DIRECTION)
5900 MovDir[x][y] = move_pattern;
5901 MovDelay[x][y] = GET_NEW_MOVE_DELAY(element);
5903 else if (move_pattern & MV_WIND_DIRECTION)
5905 MovDir[x][y] = game.wind_direction;
5906 MovDelay[x][y] = GET_NEW_MOVE_DELAY(element);
5908 else if (move_pattern == MV_ALONG_LEFT_SIDE)
5910 if (CUSTOM_ELEMENT_CAN_ENTER_FIELD(element, left_x, left_y))
5911 MovDir[x][y] = left_dir;
5912 else if (!CUSTOM_ELEMENT_CAN_ENTER_FIELD(element, move_x, move_y))
5913 MovDir[x][y] = right_dir;
5915 if (MovDir[x][y] != old_move_dir)
5916 MovDelay[x][y] = GET_NEW_MOVE_DELAY(element);
5918 else if (move_pattern == MV_ALONG_RIGHT_SIDE)
5920 if (CUSTOM_ELEMENT_CAN_ENTER_FIELD(element, right_x, right_y))
5921 MovDir[x][y] = right_dir;
5922 else if (!CUSTOM_ELEMENT_CAN_ENTER_FIELD(element, move_x, move_y))
5923 MovDir[x][y] = left_dir;
5925 if (MovDir[x][y] != old_move_dir)
5926 MovDelay[x][y] = GET_NEW_MOVE_DELAY(element);
5928 else if (move_pattern == MV_TOWARDS_PLAYER ||
5929 move_pattern == MV_AWAY_FROM_PLAYER)
5931 int attr_x = -1, attr_y = -1;
5933 boolean move_away = (move_pattern == MV_AWAY_FROM_PLAYER);
5944 for (i = 0; i < MAX_PLAYERS; i++)
5946 struct PlayerInfo *player = &stored_player[i];
5947 int jx = player->jx, jy = player->jy;
5949 if (!player->active)
5953 ABS(jx - x) + ABS(jy - y) < ABS(attr_x - x) + ABS(attr_y - y))
5961 MovDir[x][y] = MV_NONE;
5963 MovDir[x][y] |= (move_away ? MV_RIGHT : MV_LEFT);
5964 else if (attr_x > x)
5965 MovDir[x][y] |= (move_away ? MV_LEFT : MV_RIGHT);
5967 MovDir[x][y] |= (move_away ? MV_DOWN : MV_UP);
5968 else if (attr_y > y)
5969 MovDir[x][y] |= (move_away ? MV_UP : MV_DOWN);
5971 MovDelay[x][y] = GET_NEW_MOVE_DELAY(element);
5973 if (MovDir[x][y] & MV_HORIZONTAL && MovDir[x][y] & MV_VERTICAL)
5975 boolean first_horiz = RND(2);
5976 int new_move_dir = MovDir[x][y];
5978 if (element_info[element].move_stepsize == 0) /* "not moving" */
5980 first_horiz = (ABS(attr_x - x) >= ABS(attr_y - y));
5981 MovDir[x][y] &= (first_horiz ? MV_HORIZONTAL : MV_VERTICAL);
5987 new_move_dir & (first_horiz ? MV_HORIZONTAL : MV_VERTICAL);
5988 Moving2Blocked(x, y, &newx, &newy);
5990 if (CUSTOM_ELEMENT_CAN_ENTER_FIELD(element, newx, newy))
5994 new_move_dir & (!first_horiz ? MV_HORIZONTAL : MV_VERTICAL);
5995 Moving2Blocked(x, y, &newx, &newy);
5997 if (CUSTOM_ELEMENT_CAN_ENTER_FIELD(element, newx, newy))
6000 MovDir[x][y] = old_move_dir;
6003 else if (move_pattern == MV_WHEN_PUSHED ||
6004 move_pattern == MV_WHEN_DROPPED)
6006 if (!CUSTOM_ELEMENT_CAN_ENTER_FIELD(element, move_x, move_y))
6007 MovDir[x][y] = MV_NONE;
6011 else if (move_pattern & MV_MAZE_RUNNER_STYLE)
6013 static int test_xy[7][2] =
6023 static int test_dir[7] =
6033 boolean hunter_mode = (move_pattern == MV_MAZE_HUNTER);
6034 int move_preference = -1000000; /* start with very low preference */
6035 int new_move_dir = MV_NONE;
6036 int start_test = RND(4);
6039 for (i = 0; i < NUM_DIRECTIONS; i++)
6041 int move_dir = test_dir[start_test + i];
6042 int move_dir_preference;
6044 xx = x + test_xy[start_test + i][0];
6045 yy = y + test_xy[start_test + i][1];
6047 if (hunter_mode && IN_LEV_FIELD(xx, yy) &&
6048 (IS_PLAYER(xx, yy) || Feld[xx][yy] == EL_PLAYER_IS_LEAVING))
6050 new_move_dir = move_dir;
6055 if (!CUSTOM_ELEMENT_CAN_ENTER_FIELD(element, xx, yy))
6058 move_dir_preference = -1 * RunnerVisit[xx][yy];
6059 if (hunter_mode && PlayerVisit[xx][yy] > 0)
6060 move_dir_preference = PlayerVisit[xx][yy];
6062 if (move_dir_preference > move_preference)
6064 /* prefer field that has not been visited for the longest time */
6065 move_preference = move_dir_preference;
6066 new_move_dir = move_dir;
6068 else if (move_dir_preference == move_preference &&
6069 move_dir == old_move_dir)
6071 /* prefer last direction when all directions are preferred equally */
6072 move_preference = move_dir_preference;
6073 new_move_dir = move_dir;
6077 MovDir[x][y] = new_move_dir;
6078 if (old_move_dir != new_move_dir)
6079 MovDelay[x][y] = GET_NEW_MOVE_DELAY(element);
6083 static void TurnRound(int x, int y)
6085 int direction = MovDir[x][y];
6087 int element, graphic;
6092 GfxDir[x][y] = MovDir[x][y];
6094 if (direction != MovDir[x][y])
6098 GfxAction[x][y] = ACTION_TURNING_FROM_LEFT + MV_DIR_TO_BIT(direction);
6101 ResetGfxFrame(x, y, FALSE);
6103 element = Feld[x][y];
6104 graphic = el_act_dir2img(element, GfxAction[x][y], GfxDir[x][y]);
6106 if (graphic_info[graphic].anim_global_sync)
6107 GfxFrame[x][y] = FrameCounter;
6108 else if (ANIM_MODE(graphic) == ANIM_CE_VALUE)
6109 GfxFrame[x][y] = CustomValue[x][y];
6110 else if (ANIM_MODE(graphic) == ANIM_CE_SCORE)
6111 GfxFrame[x][y] = element_info[element].collect_score;
6112 else if (ANIM_MODE(graphic) == ANIM_CE_DELAY)
6113 GfxFrame[x][y] = ChangeDelay[x][y];
6117 static boolean JustBeingPushed(int x, int y)
6121 for (i = 0; i < MAX_PLAYERS; i++)
6123 struct PlayerInfo *player = &stored_player[i];
6125 if (player->active && player->is_pushing && player->MovPos)
6127 int next_jx = player->jx + (player->jx - player->last_jx);
6128 int next_jy = player->jy + (player->jy - player->last_jy);
6130 if (x == next_jx && y == next_jy)
6138 void StartMoving(int x, int y)
6140 boolean started_moving = FALSE; /* some elements can fall _and_ move */
6141 int element = Feld[x][y];
6146 if (MovDelay[x][y] == 0)
6147 GfxAction[x][y] = ACTION_DEFAULT;
6149 if (CAN_FALL(element) && y < lev_fieldy - 1)
6151 if ((x > 0 && IS_PLAYER(x - 1, y)) ||
6152 (x < lev_fieldx - 1 && IS_PLAYER(x + 1, y)))
6153 if (JustBeingPushed(x, y))
6156 if (element == EL_QUICKSAND_FULL)
6158 if (IS_FREE(x, y + 1))
6160 InitMovingField(x, y, MV_DOWN);
6161 started_moving = TRUE;
6163 Feld[x][y] = EL_QUICKSAND_EMPTYING;
6164 #if USE_QUICKSAND_BD_ROCK_BUGFIX
6165 if (Store[x][y] != EL_ROCK && Store[x][y] != EL_BD_ROCK)
6166 Store[x][y] = EL_ROCK;
6168 Store[x][y] = EL_ROCK;
6171 PlayLevelSoundAction(x, y, ACTION_EMPTYING);
6173 else if (Feld[x][y + 1] == EL_QUICKSAND_EMPTY)
6175 if (!MovDelay[x][y])
6176 MovDelay[x][y] = TILEY + 1;
6185 Feld[x][y] = EL_QUICKSAND_EMPTY;
6186 Feld[x][y + 1] = EL_QUICKSAND_FULL;
6187 Store[x][y + 1] = Store[x][y];
6190 PlayLevelSoundAction(x, y, ACTION_FILLING);
6193 else if ((element == EL_ROCK || element == EL_BD_ROCK) &&
6194 Feld[x][y + 1] == EL_QUICKSAND_EMPTY)
6196 InitMovingField(x, y, MV_DOWN);
6197 started_moving = TRUE;
6199 Feld[x][y] = EL_QUICKSAND_FILLING;
6200 Store[x][y] = element;
6202 PlayLevelSoundAction(x, y, ACTION_FILLING);
6204 else if (element == EL_MAGIC_WALL_FULL)
6206 if (IS_FREE(x, y + 1))
6208 InitMovingField(x, y, MV_DOWN);
6209 started_moving = TRUE;
6211 Feld[x][y] = EL_MAGIC_WALL_EMPTYING;
6212 Store[x][y] = EL_CHANGED(Store[x][y]);
6214 else if (Feld[x][y + 1] == EL_MAGIC_WALL_ACTIVE)
6216 if (!MovDelay[x][y])
6217 MovDelay[x][y] = TILEY/4 + 1;
6226 Feld[x][y] = EL_MAGIC_WALL_ACTIVE;
6227 Feld[x][y + 1] = EL_MAGIC_WALL_FULL;
6228 Store[x][y + 1] = EL_CHANGED(Store[x][y]);
6232 else if (element == EL_BD_MAGIC_WALL_FULL)
6234 if (IS_FREE(x, y + 1))
6236 InitMovingField(x, y, MV_DOWN);
6237 started_moving = TRUE;
6239 Feld[x][y] = EL_BD_MAGIC_WALL_EMPTYING;
6240 Store[x][y] = EL_CHANGED2(Store[x][y]);
6242 else if (Feld[x][y + 1] == EL_BD_MAGIC_WALL_ACTIVE)
6244 if (!MovDelay[x][y])
6245 MovDelay[x][y] = TILEY/4 + 1;
6254 Feld[x][y] = EL_BD_MAGIC_WALL_ACTIVE;
6255 Feld[x][y + 1] = EL_BD_MAGIC_WALL_FULL;
6256 Store[x][y + 1] = EL_CHANGED2(Store[x][y]);
6260 else if (CAN_PASS_MAGIC_WALL(element) &&
6261 (Feld[x][y + 1] == EL_MAGIC_WALL_ACTIVE ||
6262 Feld[x][y + 1] == EL_BD_MAGIC_WALL_ACTIVE))
6264 InitMovingField(x, y, MV_DOWN);
6265 started_moving = TRUE;
6268 (Feld[x][y + 1] == EL_MAGIC_WALL_ACTIVE ? EL_MAGIC_WALL_FILLING :
6269 EL_BD_MAGIC_WALL_FILLING);
6270 Store[x][y] = element;
6272 else if (CAN_FALL(element) && Feld[x][y + 1] == EL_ACID)
6274 SplashAcid(x, y + 1);
6276 InitMovingField(x, y, MV_DOWN);
6277 started_moving = TRUE;
6279 Store[x][y] = EL_ACID;
6281 else if ((game.engine_version >= VERSION_IDENT(3,1,0,0) &&
6282 CheckCollision[x][y] && !IS_FREE(x, y + 1)) ||
6284 (game.engine_version >= VERSION_IDENT(3,0,7,0) &&
6285 CAN_FALL(element) && WasJustFalling[x][y] &&
6286 (Feld[x][y + 1] == EL_BLOCKED || IS_PLAYER(x, y + 1))) ||
6288 (game.engine_version < VERSION_IDENT(2,2,0,7) &&
6289 CAN_FALL(element) && WasJustMoving[x][y] && !Pushed[x][y + 1] &&
6290 (Feld[x][y + 1] == EL_BLOCKED)))
6292 /* this is needed for a special case not covered by calling "Impact()"
6293 from "ContinueMoving()": if an element moves to a tile directly below
6294 another element which was just falling on that tile (which was empty
6295 in the previous frame), the falling element above would just stop
6296 instead of smashing the element below (in previous version, the above
6297 element was just checked for "moving" instead of "falling", resulting
6298 in incorrect smashes caused by horizontal movement of the above
6299 element; also, the case of the player being the element to smash was
6300 simply not covered here... :-/ ) */
6302 CheckCollision[x][y] = 0;
6306 else if (IS_FREE(x, y + 1) && element == EL_SPRING && level.use_spring_bug)
6308 if (MovDir[x][y] == MV_NONE)
6310 InitMovingField(x, y, MV_DOWN);
6311 started_moving = TRUE;
6314 else if (IS_FREE(x, y + 1) || Feld[x][y + 1] == EL_DIAMOND_BREAKING)
6316 if (WasJustFalling[x][y]) /* prevent animation from being restarted */
6317 MovDir[x][y] = MV_DOWN;
6319 InitMovingField(x, y, MV_DOWN);
6320 started_moving = TRUE;
6322 else if (element == EL_AMOEBA_DROP)
6324 Feld[x][y] = EL_AMOEBA_GROWING;
6325 Store[x][y] = EL_AMOEBA_WET;
6327 else if (((IS_SLIPPERY(Feld[x][y + 1]) && !IS_PLAYER(x, y + 1)) ||
6328 (IS_EM_SLIPPERY_WALL(Feld[x][y + 1]) && IS_GEM(element))) &&
6329 !IS_FALLING(x, y + 1) && !WasJustMoving[x][y + 1] &&
6330 element != EL_DX_SUPABOMB && element != EL_SP_DISK_ORANGE)
6332 boolean can_fall_left = (x > 0 && IS_FREE(x - 1, y) &&
6333 (IS_FREE(x - 1, y + 1) ||
6334 Feld[x - 1][y + 1] == EL_ACID));
6335 boolean can_fall_right = (x < lev_fieldx - 1 && IS_FREE(x + 1, y) &&
6336 (IS_FREE(x + 1, y + 1) ||
6337 Feld[x + 1][y + 1] == EL_ACID));
6338 boolean can_fall_any = (can_fall_left || can_fall_right);
6339 boolean can_fall_both = (can_fall_left && can_fall_right);
6340 int slippery_type = element_info[Feld[x][y + 1]].slippery_type;
6342 #if USE_NEW_ALL_SLIPPERY
6343 if (can_fall_any && slippery_type != SLIPPERY_ANY_RANDOM)
6345 if (slippery_type == SLIPPERY_ANY_LEFT_RIGHT && can_fall_both)
6346 can_fall_right = FALSE;
6347 else if (slippery_type == SLIPPERY_ANY_RIGHT_LEFT && can_fall_both)
6348 can_fall_left = FALSE;
6349 else if (slippery_type == SLIPPERY_ONLY_LEFT)
6350 can_fall_right = FALSE;
6351 else if (slippery_type == SLIPPERY_ONLY_RIGHT)
6352 can_fall_left = FALSE;
6354 can_fall_any = (can_fall_left || can_fall_right);
6355 can_fall_both = FALSE;
6358 if (can_fall_any && IS_CUSTOM_ELEMENT(Feld[x][y + 1]))
6360 if (slippery_type == SLIPPERY_ONLY_LEFT)
6361 can_fall_right = FALSE;
6362 else if (slippery_type == SLIPPERY_ONLY_RIGHT)
6363 can_fall_left = FALSE;
6364 else if (slippery_type == SLIPPERY_ANY_LEFT_RIGHT && can_fall_both)
6365 can_fall_right = FALSE;
6366 else if (slippery_type == SLIPPERY_ANY_RIGHT_LEFT && can_fall_both)
6367 can_fall_left = FALSE;
6369 can_fall_any = (can_fall_left || can_fall_right);
6370 can_fall_both = (can_fall_left && can_fall_right);
6374 #if USE_NEW_ALL_SLIPPERY
6376 #if USE_NEW_SP_SLIPPERY
6377 /* !!! better use the same properties as for custom elements here !!! */
6378 else if (game.engine_version >= VERSION_IDENT(3,1,1,0) &&
6379 can_fall_both && IS_SP_ELEMENT(Feld[x][y + 1]))
6381 can_fall_right = FALSE; /* slip down on left side */
6382 can_fall_both = FALSE;
6387 #if USE_NEW_ALL_SLIPPERY
6390 if (element == EL_BD_ROCK || element == EL_BD_DIAMOND)
6391 can_fall_right = FALSE; /* slip down on left side */
6393 can_fall_left = !(can_fall_right = RND(2));
6395 can_fall_both = FALSE;
6400 if (game.emulation == EMU_BOULDERDASH ||
6401 element == EL_BD_ROCK || element == EL_BD_DIAMOND)
6402 can_fall_right = FALSE; /* slip down on left side */
6404 can_fall_left = !(can_fall_right = RND(2));
6406 can_fall_both = FALSE;
6412 /* if not determined otherwise, prefer left side for slipping down */
6413 InitMovingField(x, y, can_fall_left ? MV_LEFT : MV_RIGHT);
6414 started_moving = TRUE;
6418 else if (IS_BELT_ACTIVE(Feld[x][y + 1]) && !CAN_MOVE(element))
6420 else if (IS_BELT_ACTIVE(Feld[x][y + 1]))
6423 boolean left_is_free = (x > 0 && IS_FREE(x - 1, y));
6424 boolean right_is_free = (x < lev_fieldx - 1 && IS_FREE(x + 1, y));
6425 int belt_nr = getBeltNrFromBeltActiveElement(Feld[x][y + 1]);
6426 int belt_dir = game.belt_dir[belt_nr];
6428 if ((belt_dir == MV_LEFT && left_is_free) ||
6429 (belt_dir == MV_RIGHT && right_is_free))
6431 int nextx = (belt_dir == MV_LEFT ? x - 1 : x + 1);
6433 InitMovingField(x, y, belt_dir);
6434 started_moving = TRUE;
6436 Pushed[x][y] = TRUE;
6437 Pushed[nextx][y] = TRUE;
6439 GfxAction[x][y] = ACTION_DEFAULT;
6443 MovDir[x][y] = 0; /* if element was moving, stop it */
6448 /* not "else if" because of elements that can fall and move (EL_SPRING) */
6450 if (CAN_MOVE(element) && !started_moving && MovDir[x][y] != MV_NONE)
6452 if (CAN_MOVE(element) && !started_moving)
6455 int move_pattern = element_info[element].move_pattern;
6460 if (MovDir[x][y] == MV_NONE)
6462 printf("StartMoving(): %d,%d: element %d ['%s'] not moving\n",
6463 x, y, element, element_info[element].token_name);
6464 printf("StartMoving(): This should never happen!\n");
6469 Moving2Blocked(x, y, &newx, &newy);
6471 if (IS_PUSHABLE(element) && JustBeingPushed(x, y))
6474 if (game.engine_version >= VERSION_IDENT(3,1,0,0) &&
6475 CheckCollision[x][y] && !IN_LEV_FIELD_AND_IS_FREE(newx, newy))
6477 WasJustMoving[x][y] = 0;
6478 CheckCollision[x][y] = 0;
6480 TestIfElementHitsCustomElement(x, y, MovDir[x][y]);
6482 if (Feld[x][y] != element) /* element has changed */
6486 if (!MovDelay[x][y]) /* start new movement phase */
6488 /* all objects that can change their move direction after each step
6489 (YAMYAM, DARK_YAMYAM and PACMAN go straight until they hit a wall */
6491 if (element != EL_YAMYAM &&
6492 element != EL_DARK_YAMYAM &&
6493 element != EL_PACMAN &&
6494 !(move_pattern & MV_ANY_DIRECTION) &&
6495 move_pattern != MV_TURNING_LEFT &&
6496 move_pattern != MV_TURNING_RIGHT &&
6497 move_pattern != MV_TURNING_LEFT_RIGHT &&
6498 move_pattern != MV_TURNING_RIGHT_LEFT &&
6499 move_pattern != MV_TURNING_RANDOM)
6503 if (MovDelay[x][y] && (element == EL_BUG ||
6504 element == EL_SPACESHIP ||
6505 element == EL_SP_SNIKSNAK ||
6506 element == EL_SP_ELECTRON ||
6507 element == EL_MOLE))
6508 DrawLevelField(x, y);
6512 if (MovDelay[x][y]) /* wait some time before next movement */
6516 if (element == EL_ROBOT ||
6517 element == EL_YAMYAM ||
6518 element == EL_DARK_YAMYAM)
6520 DrawLevelElementAnimationIfNeeded(x, y, element);
6521 PlayLevelSoundAction(x, y, ACTION_WAITING);
6523 else if (element == EL_SP_ELECTRON)
6524 DrawLevelElementAnimationIfNeeded(x, y, element);
6525 else if (element == EL_DRAGON)
6528 int dir = MovDir[x][y];
6529 int dx = (dir == MV_LEFT ? -1 : dir == MV_RIGHT ? +1 : 0);
6530 int dy = (dir == MV_UP ? -1 : dir == MV_DOWN ? +1 : 0);
6531 int graphic = (dir == MV_LEFT ? IMG_FLAMES_1_LEFT :
6532 dir == MV_RIGHT ? IMG_FLAMES_1_RIGHT :
6533 dir == MV_UP ? IMG_FLAMES_1_UP :
6534 dir == MV_DOWN ? IMG_FLAMES_1_DOWN : IMG_EMPTY);
6535 int frame = getGraphicAnimationFrame(graphic, GfxFrame[x][y]);
6537 GfxAction[x][y] = ACTION_ATTACKING;
6539 if (IS_PLAYER(x, y))
6540 DrawPlayerField(x, y);
6542 DrawLevelField(x, y);
6544 PlayLevelSoundActionIfLoop(x, y, ACTION_ATTACKING);
6546 for (i = 1; i <= 3; i++)
6548 int xx = x + i * dx;
6549 int yy = y + i * dy;
6550 int sx = SCREENX(xx);
6551 int sy = SCREENY(yy);
6552 int flame_graphic = graphic + (i - 1);
6554 if (!IN_LEV_FIELD(xx, yy) || IS_DRAGONFIRE_PROOF(Feld[xx][yy]))
6559 int flamed = MovingOrBlocked2Element(xx, yy);
6563 if (IS_CLASSIC_ENEMY(flamed) || CAN_EXPLODE_BY_DRAGONFIRE(flamed))
6565 else if (IS_MOVING(xx, yy) || IS_BLOCKED(xx, yy))
6566 RemoveMovingField(xx, yy);
6568 RemoveField(xx, yy);
6570 if (IS_CLASSIC_ENEMY(flamed) || CAN_EXPLODE_BY_DRAGONFIRE(flamed))
6573 RemoveMovingField(xx, yy);
6576 ChangeDelay[xx][yy] = 0;
6578 Feld[xx][yy] = EL_FLAMES;
6580 if (IN_SCR_FIELD(sx, sy))
6582 DrawLevelFieldCrumbledSand(xx, yy);
6583 DrawGraphic(sx, sy, flame_graphic, frame);
6588 if (Feld[xx][yy] == EL_FLAMES)
6589 Feld[xx][yy] = EL_EMPTY;
6590 DrawLevelField(xx, yy);
6595 if (MovDelay[x][y]) /* element still has to wait some time */
6597 PlayLevelSoundAction(x, y, ACTION_WAITING);
6603 /* now make next step */
6605 Moving2Blocked(x, y, &newx, &newy); /* get next screen position */
6607 if (DONT_COLLIDE_WITH(element) &&
6608 IN_LEV_FIELD(newx, newy) && IS_PLAYER(newx, newy) &&
6609 !PLAYER_ENEMY_PROTECTED(newx, newy))
6611 TestIfBadThingRunsIntoPlayer(x, y, MovDir[x][y]);
6616 else if (CAN_MOVE_INTO_ACID(element) &&
6617 IN_LEV_FIELD(newx, newy) && Feld[newx][newy] == EL_ACID &&
6618 !IS_MV_DIAGONAL(MovDir[x][y]) &&
6619 (MovDir[x][y] == MV_DOWN ||
6620 game.engine_version >= VERSION_IDENT(3,1,0,0)))
6622 SplashAcid(newx, newy);
6623 Store[x][y] = EL_ACID;
6625 else if (element == EL_PENGUIN && IN_LEV_FIELD(newx, newy))
6627 if (Feld[newx][newy] == EL_EXIT_OPEN)
6630 DrawLevelField(x, y);
6632 PlayLevelSound(newx, newy, SND_PENGUIN_PASSING);
6633 if (IN_SCR_FIELD(SCREENX(newx), SCREENY(newy)))
6634 DrawGraphicThruMask(SCREENX(newx),SCREENY(newy), el2img(element), 0);
6636 local_player->friends_still_needed--;
6637 if (!local_player->friends_still_needed &&
6638 !local_player->GameOver && AllPlayersGone)
6639 local_player->LevelSolved = local_player->GameOver = TRUE;
6643 else if (IS_FOOD_PENGUIN(Feld[newx][newy]))
6645 if (DigField(local_player, x, y, newx, newy, 0,0, DF_DIG) == MP_MOVING)
6646 DrawLevelField(newx, newy);
6648 GfxDir[x][y] = MovDir[x][y] = MV_NONE;
6650 else if (!IS_FREE(newx, newy))
6652 GfxAction[x][y] = ACTION_WAITING;
6654 if (IS_PLAYER(x, y))
6655 DrawPlayerField(x, y);
6657 DrawLevelField(x, y);
6662 else if (element == EL_PIG && IN_LEV_FIELD(newx, newy))
6664 if (IS_FOOD_PIG(Feld[newx][newy]))
6666 if (IS_MOVING(newx, newy))
6667 RemoveMovingField(newx, newy);
6670 Feld[newx][newy] = EL_EMPTY;
6671 DrawLevelField(newx, newy);
6674 PlayLevelSound(x, y, SND_PIG_DIGGING);
6676 else if (!IS_FREE(newx, newy))
6678 if (IS_PLAYER(x, y))
6679 DrawPlayerField(x, y);
6681 DrawLevelField(x, y);
6686 else if (element == EL_EMC_ANDROID && IN_LEV_FIELD(newx, newy))
6688 if (Store[x][y] != EL_EMPTY)
6690 boolean can_clone = FALSE;
6693 /* check if element to clone is still there */
6694 for (yy = y - 1; yy <= y + 1; yy++) for (xx = x - 1; xx <= x + 1; xx++)
6696 if (IN_LEV_FIELD(xx, yy) && Feld[xx][yy] == Store[x][y])
6704 /* cannot clone or target field not free anymore -- do not clone */
6705 if (!can_clone || !ANDROID_CAN_ENTER_FIELD(element, newx, newy))
6706 Store[x][y] = EL_EMPTY;
6709 if (ANDROID_CAN_ENTER_FIELD(element, newx, newy))
6711 if (IS_MV_DIAGONAL(MovDir[x][y]))
6713 int diagonal_move_dir = MovDir[x][y];
6714 int stored = Store[x][y];
6715 int change_delay = 8;
6718 /* android is moving diagonally */
6720 CreateField(x, y, EL_DIAGONAL_SHRINKING);
6722 Store[x][y] = (stored == EL_ACID ? EL_EMPTY : stored);
6723 GfxElement[x][y] = EL_EMC_ANDROID;
6724 GfxAction[x][y] = ACTION_SHRINKING;
6725 GfxDir[x][y] = diagonal_move_dir;
6726 ChangeDelay[x][y] = change_delay;
6728 graphic = el_act_dir2img(GfxElement[x][y], GfxAction[x][y],
6731 DrawLevelGraphicAnimation(x, y, graphic);
6732 PlayLevelSoundAction(x, y, ACTION_SHRINKING);
6734 if (Feld[newx][newy] == EL_ACID)
6736 SplashAcid(newx, newy);
6741 CreateField(newx, newy, EL_DIAGONAL_GROWING);
6743 Store[newx][newy] = EL_EMC_ANDROID;
6744 GfxElement[newx][newy] = EL_EMC_ANDROID;
6745 GfxAction[newx][newy] = ACTION_GROWING;
6746 GfxDir[newx][newy] = diagonal_move_dir;
6747 ChangeDelay[newx][newy] = change_delay;
6749 graphic = el_act_dir2img(GfxElement[newx][newy],
6750 GfxAction[newx][newy], GfxDir[newx][newy]);
6752 DrawLevelGraphicAnimation(newx, newy, graphic);
6753 PlayLevelSoundAction(newx, newy, ACTION_GROWING);
6759 Feld[newx][newy] = EL_EMPTY;
6760 DrawLevelField(newx, newy);
6762 PlayLevelSoundAction(x, y, ACTION_DIGGING);
6765 else if (!IS_FREE(newx, newy))
6768 if (IS_PLAYER(x, y))
6769 DrawPlayerField(x, y);
6771 DrawLevelField(x, y);
6777 else if (IS_CUSTOM_ELEMENT(element) &&
6778 CUSTOM_ELEMENT_CAN_ENTER_FIELD(element, newx, newy))
6780 int new_element = Feld[newx][newy];
6782 if (!IS_FREE(newx, newy))
6784 int action = (IS_DIGGABLE(new_element) ? ACTION_DIGGING :
6785 IS_COLLECTIBLE(new_element) ? ACTION_COLLECTING :
6788 /* no element can dig solid indestructible elements */
6789 if (IS_INDESTRUCTIBLE(new_element) &&
6790 !IS_DIGGABLE(new_element) &&
6791 !IS_COLLECTIBLE(new_element))
6794 if (AmoebaNr[newx][newy] &&
6795 (new_element == EL_AMOEBA_FULL ||
6796 new_element == EL_BD_AMOEBA ||
6797 new_element == EL_AMOEBA_GROWING))
6799 AmoebaCnt[AmoebaNr[newx][newy]]--;
6800 AmoebaCnt2[AmoebaNr[newx][newy]]--;
6803 if (IS_MOVING(newx, newy))
6804 RemoveMovingField(newx, newy);
6807 RemoveField(newx, newy);
6808 DrawLevelField(newx, newy);
6811 /* if digged element was about to explode, prevent the explosion */
6812 ExplodeField[newx][newy] = EX_TYPE_NONE;
6814 PlayLevelSoundAction(x, y, action);
6817 Store[newx][newy] = EL_EMPTY;
6819 /* this makes it possible to leave the removed element again */
6820 if (IS_EQUAL_OR_IN_GROUP(new_element, MOVE_ENTER_EL(element)))
6821 Store[newx][newy] = new_element;
6823 if (IS_EQUAL_OR_IN_GROUP(new_element, MOVE_ENTER_EL(element)))
6825 int move_leave_element = element_info[element].move_leave_element;
6827 /* this makes it possible to leave the removed element again */
6828 Store[newx][newy] = (move_leave_element == EL_TRIGGER_ELEMENT ?
6829 new_element : move_leave_element);
6833 if (move_pattern & MV_MAZE_RUNNER_STYLE)
6835 RunnerVisit[x][y] = FrameCounter;
6836 PlayerVisit[x][y] /= 8; /* expire player visit path */
6839 else if (element == EL_DRAGON && IN_LEV_FIELD(newx, newy))
6841 if (!IS_FREE(newx, newy))
6843 if (IS_PLAYER(x, y))
6844 DrawPlayerField(x, y);
6846 DrawLevelField(x, y);
6852 boolean wanna_flame = !RND(10);
6853 int dx = newx - x, dy = newy - y;
6854 int newx1 = newx + 1 * dx, newy1 = newy + 1 * dy;
6855 int newx2 = newx + 2 * dx, newy2 = newy + 2 * dy;
6856 int element1 = (IN_LEV_FIELD(newx1, newy1) ?
6857 MovingOrBlocked2Element(newx1, newy1) : EL_STEELWALL);
6858 int element2 = (IN_LEV_FIELD(newx2, newy2) ?
6859 MovingOrBlocked2Element(newx2, newy2) : EL_STEELWALL);
6862 IS_CLASSIC_ENEMY(element1) ||
6863 IS_CLASSIC_ENEMY(element2)) &&
6864 element1 != EL_DRAGON && element2 != EL_DRAGON &&
6865 element1 != EL_FLAMES && element2 != EL_FLAMES)
6867 ResetGfxAnimation(x, y);
6868 GfxAction[x][y] = ACTION_ATTACKING;
6870 if (IS_PLAYER(x, y))
6871 DrawPlayerField(x, y);
6873 DrawLevelField(x, y);
6875 PlayLevelSound(x, y, SND_DRAGON_ATTACKING);
6877 MovDelay[x][y] = 50;
6881 RemoveField(newx, newy);
6883 Feld[newx][newy] = EL_FLAMES;
6884 if (IN_LEV_FIELD(newx1, newy1) && Feld[newx1][newy1] == EL_EMPTY)
6887 RemoveField(newx1, newy1);
6889 Feld[newx1][newy1] = EL_FLAMES;
6891 if (IN_LEV_FIELD(newx2, newy2) && Feld[newx2][newy2] == EL_EMPTY)
6894 RemoveField(newx2, newy2);
6896 Feld[newx2][newy2] = EL_FLAMES;
6903 else if (element == EL_YAMYAM && IN_LEV_FIELD(newx, newy) &&
6904 Feld[newx][newy] == EL_DIAMOND)
6906 if (IS_MOVING(newx, newy))
6907 RemoveMovingField(newx, newy);
6910 Feld[newx][newy] = EL_EMPTY;
6911 DrawLevelField(newx, newy);
6914 PlayLevelSound(x, y, SND_YAMYAM_DIGGING);
6916 else if (element == EL_DARK_YAMYAM && IN_LEV_FIELD(newx, newy) &&
6917 IS_FOOD_DARK_YAMYAM(Feld[newx][newy]))
6919 if (AmoebaNr[newx][newy])
6921 AmoebaCnt2[AmoebaNr[newx][newy]]--;
6922 if (Feld[newx][newy] == EL_AMOEBA_FULL ||
6923 Feld[newx][newy] == EL_BD_AMOEBA)
6924 AmoebaCnt[AmoebaNr[newx][newy]]--;
6929 if (IS_MOVING(newx, newy) || IS_BLOCKED(newx, newy))
6931 RemoveMovingField(newx, newy);
6934 if (IS_MOVING(newx, newy))
6936 RemoveMovingField(newx, newy);
6941 Feld[newx][newy] = EL_EMPTY;
6942 DrawLevelField(newx, newy);
6945 PlayLevelSound(x, y, SND_DARK_YAMYAM_DIGGING);
6947 else if ((element == EL_PACMAN || element == EL_MOLE)
6948 && IN_LEV_FIELD(newx, newy) && IS_AMOEBOID(Feld[newx][newy]))
6950 if (AmoebaNr[newx][newy])
6952 AmoebaCnt2[AmoebaNr[newx][newy]]--;
6953 if (Feld[newx][newy] == EL_AMOEBA_FULL ||
6954 Feld[newx][newy] == EL_BD_AMOEBA)
6955 AmoebaCnt[AmoebaNr[newx][newy]]--;
6958 if (element == EL_MOLE)
6960 Feld[newx][newy] = EL_AMOEBA_SHRINKING;
6961 PlayLevelSound(x, y, SND_MOLE_DIGGING);
6963 ResetGfxAnimation(x, y);
6964 GfxAction[x][y] = ACTION_DIGGING;
6965 DrawLevelField(x, y);
6967 MovDelay[newx][newy] = 0; /* start amoeba shrinking delay */
6969 return; /* wait for shrinking amoeba */
6971 else /* element == EL_PACMAN */
6973 Feld[newx][newy] = EL_EMPTY;
6974 DrawLevelField(newx, newy);
6975 PlayLevelSound(x, y, SND_PACMAN_DIGGING);
6978 else if (element == EL_MOLE && IN_LEV_FIELD(newx, newy) &&
6979 (Feld[newx][newy] == EL_AMOEBA_SHRINKING ||
6980 (Feld[newx][newy] == EL_EMPTY && Stop[newx][newy])))
6982 /* wait for shrinking amoeba to completely disappear */
6985 else if (!IN_LEV_FIELD(newx, newy) || !IS_FREE(newx, newy))
6987 /* object was running against a wall */
6992 /* !!! NEW "CE_BLOCKED" STUFF !!! -- DOES NOT WORK YET... !!! */
6993 if (move_pattern & MV_ANY_DIRECTION &&
6994 move_pattern == MovDir[x][y])
6996 int blocking_element =
6997 (IN_LEV_FIELD(newx, newy) ? Feld[newx][newy] : BorderElement);
6999 CheckElementChangeBySide(x, y, element, blocking_element, CE_BLOCKED,
7002 element = Feld[x][y]; /* element might have changed */
7006 if (GFX_ELEMENT(element) != EL_SAND) /* !!! FIX THIS (crumble) !!! */
7007 DrawLevelElementAnimation(x, y, element);
7009 if (DONT_TOUCH(element))
7010 TestIfBadThingTouchesPlayer(x, y);
7015 InitMovingField(x, y, MovDir[x][y]);
7017 PlayLevelSoundAction(x, y, ACTION_MOVING);
7021 ContinueMoving(x, y);
7024 void ContinueMoving(int x, int y)
7026 int element = Feld[x][y];
7027 struct ElementInfo *ei = &element_info[element];
7028 int direction = MovDir[x][y];
7029 int dx = (direction == MV_LEFT ? -1 : direction == MV_RIGHT ? +1 : 0);
7030 int dy = (direction == MV_UP ? -1 : direction == MV_DOWN ? +1 : 0);
7031 int newx = x + dx, newy = y + dy;
7032 int stored = Store[x][y];
7033 int stored_new = Store[newx][newy];
7034 boolean pushed_by_player = (Pushed[x][y] && IS_PLAYER(x, y));
7035 boolean pushed_by_conveyor = (Pushed[x][y] && !IS_PLAYER(x, y));
7036 boolean last_line = (newy == lev_fieldy - 1);
7038 MovPos[x][y] += getElementMoveStepsize(x, y);
7040 if (pushed_by_player) /* special case: moving object pushed by player */
7041 MovPos[x][y] = SIGN(MovPos[x][y]) * (TILEX - ABS(PLAYERINFO(x,y)->MovPos));
7043 if (ABS(MovPos[x][y]) < TILEX)
7045 DrawLevelField(x, y);
7047 return; /* element is still moving */
7050 /* element reached destination field */
7052 Feld[x][y] = EL_EMPTY;
7053 Feld[newx][newy] = element;
7054 MovPos[x][y] = 0; /* force "not moving" for "crumbled sand" */
7056 if (Store[x][y] == EL_ACID) /* element is moving into acid pool */
7058 element = Feld[newx][newy] = EL_ACID;
7060 else if (element == EL_MOLE)
7062 Feld[x][y] = EL_SAND;
7064 DrawLevelFieldCrumbledSandNeighbours(x, y);
7066 else if (element == EL_QUICKSAND_FILLING)
7068 element = Feld[newx][newy] = get_next_element(element);
7069 Store[newx][newy] = Store[x][y];
7071 else if (element == EL_QUICKSAND_EMPTYING)
7073 Feld[x][y] = get_next_element(element);
7074 element = Feld[newx][newy] = Store[x][y];
7076 else if (element == EL_MAGIC_WALL_FILLING)
7078 element = Feld[newx][newy] = get_next_element(element);
7079 if (!game.magic_wall_active)
7080 element = Feld[newx][newy] = EL_MAGIC_WALL_DEAD;
7081 Store[newx][newy] = Store[x][y];
7083 else if (element == EL_MAGIC_WALL_EMPTYING)
7085 Feld[x][y] = get_next_element(element);
7086 if (!game.magic_wall_active)
7087 Feld[x][y] = EL_MAGIC_WALL_DEAD;
7088 element = Feld[newx][newy] = Store[x][y];
7090 #if USE_NEW_CUSTOM_VALUE
7091 InitField(newx, newy, FALSE);
7094 else if (element == EL_BD_MAGIC_WALL_FILLING)
7096 element = Feld[newx][newy] = get_next_element(element);
7097 if (!game.magic_wall_active)
7098 element = Feld[newx][newy] = EL_BD_MAGIC_WALL_DEAD;
7099 Store[newx][newy] = Store[x][y];
7101 else if (element == EL_BD_MAGIC_WALL_EMPTYING)
7103 Feld[x][y] = get_next_element(element);
7104 if (!game.magic_wall_active)
7105 Feld[x][y] = EL_BD_MAGIC_WALL_DEAD;
7106 element = Feld[newx][newy] = Store[x][y];
7108 #if USE_NEW_CUSTOM_VALUE
7109 InitField(newx, newy, FALSE);
7112 else if (element == EL_AMOEBA_DROPPING)
7114 Feld[x][y] = get_next_element(element);
7115 element = Feld[newx][newy] = Store[x][y];
7117 else if (element == EL_SOKOBAN_OBJECT)
7120 Feld[x][y] = Back[x][y];
7122 if (Back[newx][newy])
7123 Feld[newx][newy] = EL_SOKOBAN_FIELD_FULL;
7125 Back[x][y] = Back[newx][newy] = 0;
7128 Store[x][y] = EL_EMPTY;
7133 MovDelay[newx][newy] = 0;
7136 if (CAN_CHANGE_OR_HAS_ACTION(element))
7138 if (CAN_CHANGE(element))
7141 /* copy element change control values to new field */
7142 ChangeDelay[newx][newy] = ChangeDelay[x][y];
7143 ChangePage[newx][newy] = ChangePage[x][y];
7144 ChangeCount[newx][newy] = ChangeCount[x][y];
7145 ChangeEvent[newx][newy] = ChangeEvent[x][y];
7148 #if USE_NEW_CUSTOM_VALUE
7149 CustomValue[newx][newy] = CustomValue[x][y];
7155 #if USE_NEW_CUSTOM_VALUE
7156 CustomValue[newx][newy] = CustomValue[x][y];
7160 ChangeDelay[x][y] = 0;
7161 ChangePage[x][y] = -1;
7162 ChangeCount[x][y] = 0;
7163 ChangeEvent[x][y] = -1;
7165 #if USE_NEW_CUSTOM_VALUE
7166 CustomValue[x][y] = 0;
7169 /* copy animation control values to new field */
7170 GfxFrame[newx][newy] = GfxFrame[x][y];
7171 GfxRandom[newx][newy] = GfxRandom[x][y]; /* keep same random value */
7172 GfxAction[newx][newy] = GfxAction[x][y]; /* keep action one frame */
7173 GfxDir[newx][newy] = GfxDir[x][y]; /* keep element direction */
7175 Pushed[x][y] = Pushed[newx][newy] = FALSE;
7177 /* some elements can leave other elements behind after moving */
7179 if (ei->move_leave_element != EL_EMPTY &&
7180 (ei->move_leave_type == LEAVE_TYPE_UNLIMITED || stored != EL_EMPTY) &&
7181 (!IS_PLAYER(x, y) || IS_WALKABLE(ei->move_leave_element)))
7183 if (IS_CUSTOM_ELEMENT(element) && ei->move_leave_element != EL_EMPTY &&
7184 (ei->move_leave_type == LEAVE_TYPE_UNLIMITED || stored != EL_EMPTY) &&
7185 (!IS_PLAYER(x, y) || IS_WALKABLE(ei->move_leave_element)))
7188 int move_leave_element = ei->move_leave_element;
7192 /* this makes it possible to leave the removed element again */
7193 if (ei->move_leave_element == EL_TRIGGER_ELEMENT)
7194 move_leave_element = (stored == EL_ACID ? EL_EMPTY : stored);
7196 /* this makes it possible to leave the removed element again */
7197 if (ei->move_leave_element == EL_TRIGGER_ELEMENT)
7198 move_leave_element = stored;
7201 /* this makes it possible to leave the removed element again */
7202 if (ei->move_leave_type == LEAVE_TYPE_LIMITED &&
7203 ei->move_leave_element == EL_TRIGGER_ELEMENT)
7204 move_leave_element = stored;
7207 Feld[x][y] = move_leave_element;
7209 if (element_info[Feld[x][y]].move_direction_initial == MV_START_PREVIOUS)
7210 MovDir[x][y] = direction;
7212 InitField(x, y, FALSE);
7214 if (GFX_CRUMBLED(Feld[x][y]))
7215 DrawLevelFieldCrumbledSandNeighbours(x, y);
7217 if (ELEM_IS_PLAYER(move_leave_element))
7218 RelocatePlayer(x, y, move_leave_element);
7221 /* do this after checking for left-behind element */
7222 ResetGfxAnimation(x, y); /* reset animation values for old field */
7224 if (!CAN_MOVE(element) ||
7225 (CAN_FALL(element) && direction == MV_DOWN &&
7226 (element == EL_SPRING ||
7227 element_info[element].move_pattern == MV_WHEN_PUSHED ||
7228 element_info[element].move_pattern == MV_WHEN_DROPPED)))
7229 GfxDir[x][y] = MovDir[newx][newy] = 0;
7231 DrawLevelField(x, y);
7232 DrawLevelField(newx, newy);
7234 Stop[newx][newy] = TRUE; /* ignore this element until the next frame */
7236 /* prevent pushed element from moving on in pushed direction */
7237 if (pushed_by_player && CAN_MOVE(element) &&
7238 element_info[element].move_pattern & MV_ANY_DIRECTION &&
7239 !(element_info[element].move_pattern & direction))
7240 TurnRound(newx, newy);
7242 /* prevent elements on conveyor belt from moving on in last direction */
7243 if (pushed_by_conveyor && CAN_FALL(element) &&
7244 direction & MV_HORIZONTAL)
7245 MovDir[newx][newy] = 0;
7247 if (!pushed_by_player)
7249 int nextx = newx + dx, nexty = newy + dy;
7250 boolean check_collision_again = IN_LEV_FIELD_AND_IS_FREE(nextx, nexty);
7252 WasJustMoving[newx][newy] = CHECK_DELAY_MOVING;
7254 if (CAN_FALL(element) && direction == MV_DOWN)
7255 WasJustFalling[newx][newy] = CHECK_DELAY_FALLING;
7257 if ((!CAN_FALL(element) || direction == MV_DOWN) && check_collision_again)
7258 CheckCollision[newx][newy] = CHECK_DELAY_COLLISION;
7261 if (DONT_TOUCH(element)) /* object may be nasty to player or others */
7263 TestIfBadThingTouchesPlayer(newx, newy);
7264 TestIfBadThingTouchesFriend(newx, newy);
7266 if (!IS_CUSTOM_ELEMENT(element))
7267 TestIfBadThingTouchesOtherBadThing(newx, newy);
7269 else if (element == EL_PENGUIN)
7270 TestIfFriendTouchesBadThing(newx, newy);
7272 /* give the player one last chance (one more frame) to move away */
7273 if (CAN_FALL(element) && direction == MV_DOWN &&
7274 (last_line || (!IS_FREE(x, newy + 1) &&
7275 (!IS_PLAYER(x, newy + 1) ||
7276 game.engine_version < VERSION_IDENT(3,1,1,0)))))
7279 if (pushed_by_player && !game.use_change_when_pushing_bug)
7281 int push_side = MV_DIR_OPPOSITE(direction);
7282 struct PlayerInfo *player = PLAYERINFO(x, y);
7284 CheckElementChangeByPlayer(newx, newy, element, CE_PUSHED_BY_PLAYER,
7285 player->index_bit, push_side);
7286 CheckTriggeredElementChangeByPlayer(newx,newy, element, CE_PLAYER_PUSHES_X,
7287 player->index_bit, push_side);
7290 if (element == EL_EMC_ANDROID && pushed_by_player) /* make another move */
7291 MovDelay[newx][newy] = 1;
7293 CheckTriggeredElementChangeBySide(x, y, element, CE_MOVE_OF_X, direction);
7295 TestIfElementTouchesCustomElement(x, y); /* empty or new element */
7298 if (ChangePage[newx][newy] != -1) /* delayed change */
7300 int page = ChangePage[newx][newy];
7301 struct ElementChangeInfo *change = &ei->change_page[page];
7303 ChangePage[newx][newy] = -1;
7305 if (change->can_change)
7307 if (ChangeElement(newx, newy, element, page))
7309 if (change->post_change_function)
7310 change->post_change_function(newx, newy);
7314 if (change->has_action)
7315 ExecuteCustomElementAction(newx, newy, element, page);
7319 TestIfElementHitsCustomElement(newx, newy, direction);
7320 TestIfPlayerTouchesCustomElement(newx, newy);
7321 TestIfElementTouchesCustomElement(newx, newy);
7324 if (IS_CUSTOM_ELEMENT(element) && ei->move_enter_element != EL_EMPTY &&
7325 IS_EQUAL_OR_IN_GROUP(stored_new, ei->move_enter_element))
7326 CheckElementChangeBySide(newx, newy, element, stored_new, CE_DIGGING_X,
7327 MV_DIR_OPPOSITE(direction));
7331 int AmoebeNachbarNr(int ax, int ay)
7334 int element = Feld[ax][ay];
7336 static int xy[4][2] =
7344 for (i = 0; i < NUM_DIRECTIONS; i++)
7346 int x = ax + xy[i][0];
7347 int y = ay + xy[i][1];
7349 if (!IN_LEV_FIELD(x, y))
7352 if (Feld[x][y] == element && AmoebaNr[x][y] > 0)
7353 group_nr = AmoebaNr[x][y];
7359 void AmoebenVereinigen(int ax, int ay)
7361 int i, x, y, xx, yy;
7362 int new_group_nr = AmoebaNr[ax][ay];
7363 static int xy[4][2] =
7371 if (new_group_nr == 0)
7374 for (i = 0; i < NUM_DIRECTIONS; i++)
7379 if (!IN_LEV_FIELD(x, y))
7382 if ((Feld[x][y] == EL_AMOEBA_FULL ||
7383 Feld[x][y] == EL_BD_AMOEBA ||
7384 Feld[x][y] == EL_AMOEBA_DEAD) &&
7385 AmoebaNr[x][y] != new_group_nr)
7387 int old_group_nr = AmoebaNr[x][y];
7389 if (old_group_nr == 0)
7392 AmoebaCnt[new_group_nr] += AmoebaCnt[old_group_nr];
7393 AmoebaCnt[old_group_nr] = 0;
7394 AmoebaCnt2[new_group_nr] += AmoebaCnt2[old_group_nr];
7395 AmoebaCnt2[old_group_nr] = 0;
7398 SCAN_PLAYFIELD(xx, yy)
7400 for (yy = 0; yy < lev_fieldy; yy++) for (xx = 0; xx < lev_fieldx; xx++)
7403 if (AmoebaNr[xx][yy] == old_group_nr)
7404 AmoebaNr[xx][yy] = new_group_nr;
7410 void AmoebeUmwandeln(int ax, int ay)
7414 if (Feld[ax][ay] == EL_AMOEBA_DEAD)
7416 int group_nr = AmoebaNr[ax][ay];
7421 printf("AmoebeUmwandeln(): ax = %d, ay = %d\n", ax, ay);
7422 printf("AmoebeUmwandeln(): This should never happen!\n");
7428 SCAN_PLAYFIELD(x, y)
7430 for (y = 0; y < lev_fieldy; y++) for (x = 0; x < lev_fieldx; x++)
7433 if (Feld[x][y] == EL_AMOEBA_DEAD && AmoebaNr[x][y] == group_nr)
7436 Feld[x][y] = EL_AMOEBA_TO_DIAMOND;
7440 PlayLevelSound(ax, ay, (IS_GEM(level.amoeba_content) ?
7441 SND_AMOEBA_TURNING_TO_GEM :
7442 SND_AMOEBA_TURNING_TO_ROCK));
7447 static int xy[4][2] =
7455 for (i = 0; i < NUM_DIRECTIONS; i++)
7460 if (!IN_LEV_FIELD(x, y))
7463 if (Feld[x][y] == EL_AMOEBA_TO_DIAMOND)
7465 PlayLevelSound(x, y, (IS_GEM(level.amoeba_content) ?
7466 SND_AMOEBA_TURNING_TO_GEM :
7467 SND_AMOEBA_TURNING_TO_ROCK));
7474 void AmoebeUmwandelnBD(int ax, int ay, int new_element)
7477 int group_nr = AmoebaNr[ax][ay];
7478 boolean done = FALSE;
7483 printf("AmoebeUmwandelnBD(): ax = %d, ay = %d\n", ax, ay);
7484 printf("AmoebeUmwandelnBD(): This should never happen!\n");
7490 SCAN_PLAYFIELD(x, y)
7492 for (y = 0; y < lev_fieldy; y++) for (x = 0; x < lev_fieldx; x++)
7495 if (AmoebaNr[x][y] == group_nr &&
7496 (Feld[x][y] == EL_AMOEBA_DEAD ||
7497 Feld[x][y] == EL_BD_AMOEBA ||
7498 Feld[x][y] == EL_AMOEBA_GROWING))
7501 Feld[x][y] = new_element;
7502 InitField(x, y, FALSE);
7503 DrawLevelField(x, y);
7509 PlayLevelSound(ax, ay, (new_element == EL_BD_ROCK ?
7510 SND_BD_AMOEBA_TURNING_TO_ROCK :
7511 SND_BD_AMOEBA_TURNING_TO_GEM));
7514 void AmoebeWaechst(int x, int y)
7516 static unsigned long sound_delay = 0;
7517 static unsigned long sound_delay_value = 0;
7519 if (!MovDelay[x][y]) /* start new growing cycle */
7523 if (DelayReached(&sound_delay, sound_delay_value))
7525 PlayLevelSoundElementAction(x, y, Store[x][y], ACTION_GROWING);
7526 sound_delay_value = 30;
7530 if (MovDelay[x][y]) /* wait some time before growing bigger */
7533 if (MovDelay[x][y]/2 && IN_SCR_FIELD(SCREENX(x), SCREENY(y)))
7535 int frame = getGraphicAnimationFrame(IMG_AMOEBA_GROWING,
7536 6 - MovDelay[x][y]);
7538 DrawGraphic(SCREENX(x), SCREENY(y), IMG_AMOEBA_GROWING, frame);
7541 if (!MovDelay[x][y])
7543 Feld[x][y] = Store[x][y];
7545 DrawLevelField(x, y);
7550 void AmoebaDisappearing(int x, int y)
7552 static unsigned long sound_delay = 0;
7553 static unsigned long sound_delay_value = 0;
7555 if (!MovDelay[x][y]) /* start new shrinking cycle */
7559 if (DelayReached(&sound_delay, sound_delay_value))
7560 sound_delay_value = 30;
7563 if (MovDelay[x][y]) /* wait some time before shrinking */
7566 if (MovDelay[x][y]/2 && IN_SCR_FIELD(SCREENX(x), SCREENY(y)))
7568 int frame = getGraphicAnimationFrame(IMG_AMOEBA_SHRINKING,
7569 6 - MovDelay[x][y]);
7571 DrawGraphic(SCREENX(x), SCREENY(y), IMG_AMOEBA_SHRINKING, frame);
7574 if (!MovDelay[x][y])
7576 Feld[x][y] = EL_EMPTY;
7577 DrawLevelField(x, y);
7579 /* don't let mole enter this field in this cycle;
7580 (give priority to objects falling to this field from above) */
7586 void AmoebeAbleger(int ax, int ay)
7589 int element = Feld[ax][ay];
7590 int graphic = el2img(element);
7591 int newax = ax, neway = ay;
7592 boolean can_drop = (element == EL_AMOEBA_WET || element == EL_EMC_DRIPPER);
7593 static int xy[4][2] =
7601 if (!level.amoeba_speed && element != EL_EMC_DRIPPER)
7603 Feld[ax][ay] = EL_AMOEBA_DEAD;
7604 DrawLevelField(ax, ay);
7608 if (IS_ANIMATED(graphic))
7609 DrawLevelGraphicAnimationIfNeeded(ax, ay, graphic);
7611 if (!MovDelay[ax][ay]) /* start making new amoeba field */
7612 MovDelay[ax][ay] = RND(FRAMES_PER_SECOND * 25 / (1 + level.amoeba_speed));
7614 if (MovDelay[ax][ay]) /* wait some time before making new amoeba */
7617 if (MovDelay[ax][ay])
7621 if (can_drop) /* EL_AMOEBA_WET or EL_EMC_DRIPPER */
7624 int x = ax + xy[start][0];
7625 int y = ay + xy[start][1];
7627 if (!IN_LEV_FIELD(x, y))
7630 if (IS_FREE(x, y) ||
7631 CAN_GROW_INTO(Feld[x][y]) ||
7632 Feld[x][y] == EL_QUICKSAND_EMPTY)
7638 if (newax == ax && neway == ay)
7641 else /* normal or "filled" (BD style) amoeba */
7644 boolean waiting_for_player = FALSE;
7646 for (i = 0; i < NUM_DIRECTIONS; i++)
7648 int j = (start + i) % 4;
7649 int x = ax + xy[j][0];
7650 int y = ay + xy[j][1];
7652 if (!IN_LEV_FIELD(x, y))
7655 if (IS_FREE(x, y) ||
7656 CAN_GROW_INTO(Feld[x][y]) ||
7657 Feld[x][y] == EL_QUICKSAND_EMPTY)
7663 else if (IS_PLAYER(x, y))
7664 waiting_for_player = TRUE;
7667 if (newax == ax && neway == ay) /* amoeba cannot grow */
7669 if (i == 4 && (!waiting_for_player || element == EL_BD_AMOEBA))
7671 Feld[ax][ay] = EL_AMOEBA_DEAD;
7672 DrawLevelField(ax, ay);
7673 AmoebaCnt[AmoebaNr[ax][ay]]--;
7675 if (AmoebaCnt[AmoebaNr[ax][ay]] <= 0) /* amoeba is completely dead */
7677 if (element == EL_AMOEBA_FULL)
7678 AmoebeUmwandeln(ax, ay);
7679 else if (element == EL_BD_AMOEBA)
7680 AmoebeUmwandelnBD(ax, ay, level.amoeba_content);
7685 else if (element == EL_AMOEBA_FULL || element == EL_BD_AMOEBA)
7687 /* amoeba gets larger by growing in some direction */
7689 int new_group_nr = AmoebaNr[ax][ay];
7692 if (new_group_nr == 0)
7694 printf("AmoebeAbleger(): newax = %d, neway = %d\n", newax, neway);
7695 printf("AmoebeAbleger(): This should never happen!\n");
7700 AmoebaNr[newax][neway] = new_group_nr;
7701 AmoebaCnt[new_group_nr]++;
7702 AmoebaCnt2[new_group_nr]++;
7704 /* if amoeba touches other amoeba(s) after growing, unify them */
7705 AmoebenVereinigen(newax, neway);
7707 if (element == EL_BD_AMOEBA && AmoebaCnt2[new_group_nr] >= 200)
7709 AmoebeUmwandelnBD(newax, neway, EL_BD_ROCK);
7715 if (!can_drop || neway < ay || !IS_FREE(newax, neway) ||
7716 (neway == lev_fieldy - 1 && newax != ax))
7718 Feld[newax][neway] = EL_AMOEBA_GROWING; /* creation of new amoeba */
7719 Store[newax][neway] = element;
7721 else if (neway == ay || element == EL_EMC_DRIPPER)
7723 Feld[newax][neway] = EL_AMOEBA_DROP; /* drop left/right of amoeba */
7725 PlayLevelSoundAction(newax, neway, ACTION_GROWING);
7729 InitMovingField(ax, ay, MV_DOWN); /* drop dripping from amoeba */
7730 Feld[ax][ay] = EL_AMOEBA_DROPPING;
7731 Store[ax][ay] = EL_AMOEBA_DROP;
7732 ContinueMoving(ax, ay);
7736 DrawLevelField(newax, neway);
7739 void Life(int ax, int ay)
7743 static int life[4] = { 2, 3, 3, 3 }; /* parameters for "game of life" */
7746 int element = Feld[ax][ay];
7747 int graphic = el2img(element);
7748 int *life_parameter = (element == EL_GAME_OF_LIFE ? level.game_of_life :
7750 boolean changed = FALSE;
7752 if (IS_ANIMATED(graphic))
7753 DrawLevelGraphicAnimationIfNeeded(ax, ay, graphic);
7758 if (!MovDelay[ax][ay]) /* start new "game of life" cycle */
7759 MovDelay[ax][ay] = life_time;
7761 if (MovDelay[ax][ay]) /* wait some time before next cycle */
7764 if (MovDelay[ax][ay])
7768 for (y1 = -1; y1 < 2; y1++) for (x1 = -1; x1 < 2; x1++)
7770 int xx = ax+x1, yy = ay+y1;
7773 if (!IN_LEV_FIELD(xx, yy))
7776 for (y2 = -1; y2 < 2; y2++) for (x2 = -1; x2 < 2; x2++)
7778 int x = xx+x2, y = yy+y2;
7780 if (!IN_LEV_FIELD(x, y) || (x == xx && y == yy))
7783 if (((Feld[x][y] == element ||
7784 (element == EL_GAME_OF_LIFE && IS_PLAYER(x, y))) &&
7786 (IS_FREE(x, y) && Stop[x][y]))
7790 if (xx == ax && yy == ay) /* field in the middle */
7792 if (nachbarn < life_parameter[0] ||
7793 nachbarn > life_parameter[1])
7795 Feld[xx][yy] = EL_EMPTY;
7797 DrawLevelField(xx, yy);
7798 Stop[xx][yy] = TRUE;
7802 else if (IS_FREE(xx, yy) || CAN_GROW_INTO(Feld[xx][yy]))
7803 { /* free border field */
7804 if (nachbarn >= life_parameter[2] &&
7805 nachbarn <= life_parameter[3])
7807 Feld[xx][yy] = element;
7808 MovDelay[xx][yy] = (element == EL_GAME_OF_LIFE ? 0 : life_time-1);
7810 DrawLevelField(xx, yy);
7811 Stop[xx][yy] = TRUE;
7818 PlayLevelSound(ax, ay, element == EL_BIOMAZE ? SND_BIOMAZE_GROWING :
7819 SND_GAME_OF_LIFE_GROWING);
7822 static void InitRobotWheel(int x, int y)
7824 ChangeDelay[x][y] = level.time_wheel * FRAMES_PER_SECOND;
7827 static void RunRobotWheel(int x, int y)
7829 PlayLevelSound(x, y, SND_ROBOT_WHEEL_ACTIVE);
7832 static void StopRobotWheel(int x, int y)
7834 if (ZX == x && ZY == y)
7838 static void InitTimegateWheel(int x, int y)
7840 ChangeDelay[x][y] = level.time_timegate * FRAMES_PER_SECOND;
7843 static void RunTimegateWheel(int x, int y)
7845 PlayLevelSound(x, y, SND_TIMEGATE_SWITCH_ACTIVE);
7848 static void InitMagicBallDelay(int x, int y)
7851 ChangeDelay[x][y] = (level.ball_time + 1) * 8 + 1;
7853 ChangeDelay[x][y] = level.ball_time * FRAMES_PER_SECOND + 1;
7857 static void ActivateMagicBall(int bx, int by)
7861 if (level.ball_random)
7863 int pos_border = RND(8); /* select one of the eight border elements */
7864 int pos_content = (pos_border > 3 ? pos_border + 1 : pos_border);
7865 int xx = pos_content % 3;
7866 int yy = pos_content / 3;
7871 if (IN_LEV_FIELD(x, y) && Feld[x][y] == EL_EMPTY)
7872 CreateField(x, y, level.ball_content[game.ball_content_nr].e[xx][yy]);
7876 for (y = by - 1; y <= by + 1; y++) for (x = bx - 1; x <= bx + 1; x++)
7878 int xx = x - bx + 1;
7879 int yy = y - by + 1;
7881 if (IN_LEV_FIELD(x, y) && Feld[x][y] == EL_EMPTY)
7882 CreateField(x, y, level.ball_content[game.ball_content_nr].e[xx][yy]);
7886 game.ball_content_nr = (game.ball_content_nr + 1) % level.num_ball_contents;
7889 static void InitDiagonalMovingElement(int x, int y)
7892 MovDelay[x][y] = level.android_move_time;
7896 void CheckExit(int x, int y)
7898 if (local_player->gems_still_needed > 0 ||
7899 local_player->sokobanfields_still_needed > 0 ||
7900 local_player->lights_still_needed > 0)
7902 int element = Feld[x][y];
7903 int graphic = el2img(element);
7905 if (IS_ANIMATED(graphic))
7906 DrawLevelGraphicAnimationIfNeeded(x, y, graphic);
7911 if (AllPlayersGone) /* do not re-open exit door closed after last player */
7914 Feld[x][y] = EL_EXIT_OPENING;
7916 PlayLevelSoundNearest(x, y, SND_CLASS_EXIT_OPENING);
7919 void CheckExitSP(int x, int y)
7921 if (local_player->gems_still_needed > 0)
7923 int element = Feld[x][y];
7924 int graphic = el2img(element);
7926 if (IS_ANIMATED(graphic))
7927 DrawLevelGraphicAnimationIfNeeded(x, y, graphic);
7932 if (AllPlayersGone) /* do not re-open exit door closed after last player */
7935 Feld[x][y] = EL_SP_EXIT_OPENING;
7937 PlayLevelSoundNearest(x, y, SND_CLASS_SP_EXIT_OPENING);
7940 static void CloseAllOpenTimegates()
7945 SCAN_PLAYFIELD(x, y)
7947 for (y = 0; y < lev_fieldy; y++) for (x = 0; x < lev_fieldx; x++)
7950 int element = Feld[x][y];
7952 if (element == EL_TIMEGATE_OPEN || element == EL_TIMEGATE_OPENING)
7954 Feld[x][y] = EL_TIMEGATE_CLOSING;
7956 PlayLevelSoundAction(x, y, ACTION_CLOSING);
7961 void EdelsteinFunkeln(int x, int y)
7963 if (!IN_SCR_FIELD(SCREENX(x), SCREENY(y)) || IS_MOVING(x, y))
7966 if (Feld[x][y] == EL_BD_DIAMOND)
7969 if (MovDelay[x][y] == 0) /* next animation frame */
7970 MovDelay[x][y] = 11 * !SimpleRND(500);
7972 if (MovDelay[x][y] != 0) /* wait some time before next frame */
7976 if (setup.direct_draw && MovDelay[x][y])
7977 SetDrawtoField(DRAW_BUFFERED);
7979 DrawLevelElementAnimation(x, y, Feld[x][y]);
7981 if (MovDelay[x][y] != 0)
7983 int frame = getGraphicAnimationFrame(IMG_TWINKLE_WHITE,
7984 10 - MovDelay[x][y]);
7986 DrawGraphicThruMask(SCREENX(x), SCREENY(y), IMG_TWINKLE_WHITE, frame);
7988 if (setup.direct_draw)
7992 dest_x = FX + SCREENX(x) * TILEX;
7993 dest_y = FY + SCREENY(y) * TILEY;
7995 BlitBitmap(drawto_field, window,
7996 dest_x, dest_y, TILEX, TILEY, dest_x, dest_y);
7997 SetDrawtoField(DRAW_DIRECT);
8003 void MauerWaechst(int x, int y)
8007 if (!MovDelay[x][y]) /* next animation frame */
8008 MovDelay[x][y] = 3 * delay;
8010 if (MovDelay[x][y]) /* wait some time before next frame */
8014 if (IN_SCR_FIELD(SCREENX(x), SCREENY(y)))
8016 int graphic = el_dir2img(Feld[x][y], GfxDir[x][y]);
8017 int frame = getGraphicAnimationFrame(graphic, 17 - MovDelay[x][y]);
8019 DrawGraphic(SCREENX(x), SCREENY(y), graphic, frame);
8022 if (!MovDelay[x][y])
8024 if (MovDir[x][y] == MV_LEFT)
8026 if (IN_LEV_FIELD(x - 1, y) && IS_WALL(Feld[x - 1][y]))
8027 DrawLevelField(x - 1, y);
8029 else if (MovDir[x][y] == MV_RIGHT)
8031 if (IN_LEV_FIELD(x + 1, y) && IS_WALL(Feld[x + 1][y]))
8032 DrawLevelField(x + 1, y);
8034 else if (MovDir[x][y] == MV_UP)
8036 if (IN_LEV_FIELD(x, y - 1) && IS_WALL(Feld[x][y - 1]))
8037 DrawLevelField(x, y - 1);
8041 if (IN_LEV_FIELD(x, y + 1) && IS_WALL(Feld[x][y + 1]))
8042 DrawLevelField(x, y + 1);
8045 Feld[x][y] = Store[x][y];
8047 GfxDir[x][y] = MovDir[x][y] = MV_NONE;
8048 DrawLevelField(x, y);
8053 void MauerAbleger(int ax, int ay)
8055 int element = Feld[ax][ay];
8056 int graphic = el2img(element);
8057 boolean oben_frei = FALSE, unten_frei = FALSE;
8058 boolean links_frei = FALSE, rechts_frei = FALSE;
8059 boolean oben_massiv = FALSE, unten_massiv = FALSE;
8060 boolean links_massiv = FALSE, rechts_massiv = FALSE;
8061 boolean new_wall = FALSE;
8063 if (IS_ANIMATED(graphic))
8064 DrawLevelGraphicAnimationIfNeeded(ax, ay, graphic);
8066 if (!MovDelay[ax][ay]) /* start building new wall */
8067 MovDelay[ax][ay] = 6;
8069 if (MovDelay[ax][ay]) /* wait some time before building new wall */
8072 if (MovDelay[ax][ay])
8076 if (IN_LEV_FIELD(ax, ay-1) && IS_FREE(ax, ay-1))
8078 if (IN_LEV_FIELD(ax, ay+1) && IS_FREE(ax, ay+1))
8080 if (IN_LEV_FIELD(ax-1, ay) && IS_FREE(ax-1, ay))
8082 if (IN_LEV_FIELD(ax+1, ay) && IS_FREE(ax+1, ay))
8085 if (element == EL_EXPANDABLE_WALL_VERTICAL ||
8086 element == EL_EXPANDABLE_WALL_ANY)
8090 Feld[ax][ay-1] = EL_EXPANDABLE_WALL_GROWING;
8091 Store[ax][ay-1] = element;
8092 GfxDir[ax][ay-1] = MovDir[ax][ay-1] = MV_UP;
8093 if (IN_SCR_FIELD(SCREENX(ax), SCREENY(ay-1)))
8094 DrawGraphic(SCREENX(ax), SCREENY(ay - 1),
8095 IMG_EXPANDABLE_WALL_GROWING_UP, 0);
8100 Feld[ax][ay+1] = EL_EXPANDABLE_WALL_GROWING;
8101 Store[ax][ay+1] = element;
8102 GfxDir[ax][ay+1] = MovDir[ax][ay+1] = MV_DOWN;
8103 if (IN_SCR_FIELD(SCREENX(ax), SCREENY(ay+1)))
8104 DrawGraphic(SCREENX(ax), SCREENY(ay + 1),
8105 IMG_EXPANDABLE_WALL_GROWING_DOWN, 0);
8110 if (element == EL_EXPANDABLE_WALL_HORIZONTAL ||
8111 element == EL_EXPANDABLE_WALL_ANY ||
8112 element == EL_EXPANDABLE_WALL ||
8113 element == EL_BD_EXPANDABLE_WALL)
8117 Feld[ax-1][ay] = EL_EXPANDABLE_WALL_GROWING;
8118 Store[ax-1][ay] = element;
8119 GfxDir[ax-1][ay] = MovDir[ax-1][ay] = MV_LEFT;
8120 if (IN_SCR_FIELD(SCREENX(ax-1), SCREENY(ay)))
8121 DrawGraphic(SCREENX(ax - 1), SCREENY(ay),
8122 IMG_EXPANDABLE_WALL_GROWING_LEFT, 0);
8128 Feld[ax+1][ay] = EL_EXPANDABLE_WALL_GROWING;
8129 Store[ax+1][ay] = element;
8130 GfxDir[ax+1][ay] = MovDir[ax+1][ay] = MV_RIGHT;
8131 if (IN_SCR_FIELD(SCREENX(ax+1), SCREENY(ay)))
8132 DrawGraphic(SCREENX(ax + 1), SCREENY(ay),
8133 IMG_EXPANDABLE_WALL_GROWING_RIGHT, 0);
8138 if (element == EL_EXPANDABLE_WALL && (links_frei || rechts_frei))
8139 DrawLevelField(ax, ay);
8141 if (!IN_LEV_FIELD(ax, ay-1) || IS_WALL(Feld[ax][ay-1]))
8143 if (!IN_LEV_FIELD(ax, ay+1) || IS_WALL(Feld[ax][ay+1]))
8144 unten_massiv = TRUE;
8145 if (!IN_LEV_FIELD(ax-1, ay) || IS_WALL(Feld[ax-1][ay]))
8146 links_massiv = TRUE;
8147 if (!IN_LEV_FIELD(ax+1, ay) || IS_WALL(Feld[ax+1][ay]))
8148 rechts_massiv = TRUE;
8150 if (((oben_massiv && unten_massiv) ||
8151 element == EL_EXPANDABLE_WALL_HORIZONTAL ||
8152 element == EL_EXPANDABLE_WALL) &&
8153 ((links_massiv && rechts_massiv) ||
8154 element == EL_EXPANDABLE_WALL_VERTICAL))
8155 Feld[ax][ay] = EL_WALL;
8158 PlayLevelSoundAction(ax, ay, ACTION_GROWING);
8161 void CheckForDragon(int x, int y)
8164 boolean dragon_found = FALSE;
8165 static int xy[4][2] =
8173 for (i = 0; i < NUM_DIRECTIONS; i++)
8175 for (j = 0; j < 4; j++)
8177 int xx = x + j * xy[i][0], yy = y + j * xy[i][1];
8179 if (IN_LEV_FIELD(xx, yy) &&
8180 (Feld[xx][yy] == EL_FLAMES || Feld[xx][yy] == EL_DRAGON))
8182 if (Feld[xx][yy] == EL_DRAGON)
8183 dragon_found = TRUE;
8192 for (i = 0; i < NUM_DIRECTIONS; i++)
8194 for (j = 0; j < 3; j++)
8196 int xx = x + j * xy[i][0], yy = y + j * xy[i][1];
8198 if (IN_LEV_FIELD(xx, yy) && Feld[xx][yy] == EL_FLAMES)
8200 Feld[xx][yy] = EL_EMPTY;
8201 DrawLevelField(xx, yy);
8210 static void InitBuggyBase(int x, int y)
8212 int element = Feld[x][y];
8213 int activating_delay = FRAMES_PER_SECOND / 4;
8216 (element == EL_SP_BUGGY_BASE ?
8217 2 * FRAMES_PER_SECOND + RND(5 * FRAMES_PER_SECOND) - activating_delay :
8218 element == EL_SP_BUGGY_BASE_ACTIVATING ?
8220 element == EL_SP_BUGGY_BASE_ACTIVE ?
8221 1 * FRAMES_PER_SECOND + RND(1 * FRAMES_PER_SECOND) : 1);
8224 static void WarnBuggyBase(int x, int y)
8227 static int xy[4][2] =
8235 for (i = 0; i < NUM_DIRECTIONS; i++)
8237 int xx = x + xy[i][0];
8238 int yy = y + xy[i][1];
8240 if (IN_LEV_FIELD(xx, yy) && IS_PLAYER(xx, yy))
8242 PlayLevelSound(x, y, SND_SP_BUGGY_BASE_ACTIVE);
8249 static void InitTrap(int x, int y)
8251 ChangeDelay[x][y] = 2 * FRAMES_PER_SECOND + RND(5 * FRAMES_PER_SECOND);
8254 static void ActivateTrap(int x, int y)
8256 PlayLevelSound(x, y, SND_TRAP_ACTIVATING);
8259 static void ChangeActiveTrap(int x, int y)
8261 int graphic = IMG_TRAP_ACTIVE;
8263 /* if new animation frame was drawn, correct crumbled sand border */
8264 if (IS_NEW_FRAME(GfxFrame[x][y], graphic))
8265 DrawLevelFieldCrumbledSand(x, y);
8268 static int getSpecialActionElement(int element, int number, int base_element)
8270 return (element != EL_EMPTY ? element :
8271 number != -1 ? base_element + number - 1 :
8275 static int getModifiedActionNumber(int value_old, int operator, int operand,
8276 int value_min, int value_max)
8278 int value_new = (operator == CA_MODE_SET ? operand :
8279 operator == CA_MODE_ADD ? value_old + operand :
8280 operator == CA_MODE_SUBTRACT ? value_old - operand :
8281 operator == CA_MODE_MULTIPLY ? value_old * operand :
8282 operator == CA_MODE_DIVIDE ? value_old / MAX(1, operand) :
8283 operator == CA_MODE_MODULO ? value_old % MAX(1, operand) :
8286 return (value_new < value_min ? value_min :
8287 value_new > value_max ? value_max :
8291 static void ExecuteCustomElementAction(int x, int y, int element, int page)
8293 struct ElementInfo *ei = &element_info[element];
8294 struct ElementChangeInfo *change = &ei->change_page[page];
8295 int target_element = change->target_element;
8296 int action_type = change->action_type;
8297 int action_mode = change->action_mode;
8298 int action_arg = change->action_arg;
8301 if (!change->has_action)
8304 /* ---------- determine action paramater values -------------------------- */
8306 int level_time_value =
8307 (level.time > 0 ? TimeLeft :
8310 int action_arg_element =
8311 (action_arg == CA_ARG_PLAYER_TRIGGER ? change->actual_trigger_player :
8312 action_arg == CA_ARG_ELEMENT_TRIGGER ? change->actual_trigger_element :
8313 action_arg == CA_ARG_ELEMENT_TARGET ? change->target_element :
8316 int action_arg_direction =
8317 (action_arg >= CA_ARG_DIRECTION_LEFT &&
8318 action_arg <= CA_ARG_DIRECTION_DOWN ? action_arg - CA_ARG_DIRECTION :
8319 action_arg == CA_ARG_DIRECTION_TRIGGER ?
8320 change->actual_trigger_side :
8321 action_arg == CA_ARG_DIRECTION_TRIGGER_BACK ?
8322 MV_DIR_OPPOSITE(change->actual_trigger_side) :
8325 int action_arg_number_min =
8326 (action_type == CA_SET_PLAYER_SPEED ? STEPSIZE_NOT_MOVING :
8329 int action_arg_number_max =
8330 (action_type == CA_SET_PLAYER_SPEED ? STEPSIZE_EVEN_FASTER :
8331 action_type == CA_SET_LEVEL_GEMS ? 999 :
8332 action_type == CA_SET_LEVEL_TIME ? 9999 :
8333 action_type == CA_SET_LEVEL_SCORE ? 99999 :
8334 action_type == CA_SET_CE_VALUE ? 9999 :
8335 action_type == CA_SET_CE_SCORE ? 9999 :
8338 int action_arg_number_reset =
8339 (action_type == CA_SET_PLAYER_SPEED ? level.initial_player_stepsize[0] :
8340 action_type == CA_SET_LEVEL_GEMS ? level.gems_needed :
8341 action_type == CA_SET_LEVEL_TIME ? level.time :
8342 action_type == CA_SET_LEVEL_SCORE ? 0 :
8344 action_type == CA_SET_CE_VALUE ? GET_NEW_CE_VALUE(element) :
8346 action_type == CA_SET_CE_VALUE ? ei->custom_value_initial :
8348 action_type == CA_SET_CE_SCORE ? 0 :
8351 int action_arg_number =
8352 (action_arg <= CA_ARG_MAX ? action_arg :
8353 action_arg >= CA_ARG_SPEED_NOT_MOVING &&
8354 action_arg <= CA_ARG_SPEED_EVEN_FASTER ? (action_arg - CA_ARG_SPEED) :
8355 action_arg == CA_ARG_SPEED_RESET ? action_arg_number_reset :
8356 action_arg == CA_ARG_NUMBER_MIN ? action_arg_number_min :
8357 action_arg == CA_ARG_NUMBER_MAX ? action_arg_number_max :
8358 action_arg == CA_ARG_NUMBER_RESET ? action_arg_number_reset :
8359 #if USE_NEW_CUSTOM_VALUE
8360 action_arg == CA_ARG_NUMBER_CE_VALUE ? CustomValue[x][y] :
8362 action_arg == CA_ARG_NUMBER_CE_VALUE ? ei->custom_value_initial :
8364 action_arg == CA_ARG_NUMBER_CE_SCORE ? ei->collect_score :
8365 action_arg == CA_ARG_NUMBER_CE_DELAY ? GET_CE_DELAY_VALUE(change) :
8366 action_arg == CA_ARG_NUMBER_LEVEL_TIME ? level_time_value :
8367 action_arg == CA_ARG_NUMBER_LEVEL_GEMS ? local_player->gems_still_needed :
8368 action_arg == CA_ARG_NUMBER_LEVEL_SCORE ? local_player->score :
8369 action_arg == CA_ARG_ELEMENT_CV_TARGET ? GET_NEW_CE_VALUE(target_element):
8370 action_arg == CA_ARG_ELEMENT_CV_TRIGGER ? change->actual_trigger_ce_value:
8371 action_arg == CA_ARG_ELEMENT_CS_TARGET ? GET_CE_SCORE(target_element) :
8372 action_arg == CA_ARG_ELEMENT_CS_TRIGGER ? change->actual_trigger_ce_score:
8373 action_arg == CA_ARG_ELEMENT_NR_TARGET ? change->target_element :
8374 action_arg == CA_ARG_ELEMENT_NR_TRIGGER ? change->actual_trigger_element :
8377 int action_arg_number_old =
8378 (action_type == CA_SET_LEVEL_GEMS ? local_player->gems_still_needed :
8379 action_type == CA_SET_LEVEL_TIME ? TimeLeft :
8380 action_type == CA_SET_LEVEL_SCORE ? local_player->score :
8381 action_type == CA_SET_CE_VALUE ? CustomValue[x][y] :
8382 action_type == CA_SET_CE_SCORE ? ei->collect_score :
8385 int action_arg_number_new =
8386 getModifiedActionNumber(action_arg_number_old,
8387 action_mode, action_arg_number,
8388 action_arg_number_min, action_arg_number_max);
8390 int trigger_player_bits =
8391 (change->actual_trigger_player >= EL_PLAYER_1 &&
8392 change->actual_trigger_player <= EL_PLAYER_4 ?
8393 (1 << (change->actual_trigger_player - EL_PLAYER_1)) :
8396 int action_arg_player_bits =
8397 (action_arg >= CA_ARG_PLAYER_1 &&
8398 action_arg <= CA_ARG_PLAYER_4 ? action_arg - CA_ARG_PLAYER :
8399 action_arg == CA_ARG_PLAYER_TRIGGER ? trigger_player_bits :
8402 /* ---------- execute action -------------------------------------------- */
8411 /* ---------- level actions ------------------------------------------- */
8413 case CA_RESTART_LEVEL:
8415 game.restart_level = TRUE;
8420 case CA_SHOW_ENVELOPE:
8422 int element = getSpecialActionElement(action_arg_element,
8423 action_arg_number, EL_ENVELOPE_1);
8425 if (IS_ENVELOPE(element))
8426 local_player->show_envelope = element;
8431 case CA_SET_LEVEL_TIME:
8433 if (level.time > 0) /* only modify limited time value */
8435 TimeLeft = action_arg_number_new;
8437 DrawGameValue_Time(TimeLeft);
8439 if (!TimeLeft && setup.time_limit)
8440 for (i = 0; i < MAX_PLAYERS; i++)
8441 KillPlayer(&stored_player[i]);
8447 case CA_SET_LEVEL_SCORE:
8449 local_player->score = action_arg_number_new;
8451 DrawGameValue_Score(local_player->score);
8456 case CA_SET_LEVEL_GEMS:
8458 local_player->gems_still_needed = action_arg_number_new;
8460 DrawGameValue_Emeralds(local_player->gems_still_needed);
8465 #if !USE_PLAYER_GRAVITY
8466 case CA_SET_LEVEL_GRAVITY:
8468 game.gravity = (action_arg == CA_ARG_GRAVITY_OFF ? FALSE :
8469 action_arg == CA_ARG_GRAVITY_ON ? TRUE :
8470 action_arg == CA_ARG_GRAVITY_TOGGLE ? !game.gravity :
8476 case CA_SET_LEVEL_WIND:
8478 game.wind_direction = action_arg_direction;
8483 /* ---------- player actions ------------------------------------------ */
8485 case CA_MOVE_PLAYER:
8487 /* automatically move to the next field in specified direction */
8488 for (i = 0; i < MAX_PLAYERS; i++)
8489 if (trigger_player_bits & (1 << i))
8490 stored_player[i].programmed_action = action_arg_direction;
8495 case CA_EXIT_PLAYER:
8497 for (i = 0; i < MAX_PLAYERS; i++)
8498 if (action_arg_player_bits & (1 << i))
8499 stored_player[i].LevelSolved = stored_player[i].GameOver = TRUE;
8504 case CA_KILL_PLAYER:
8506 for (i = 0; i < MAX_PLAYERS; i++)
8507 if (action_arg_player_bits & (1 << i))
8508 KillPlayer(&stored_player[i]);
8513 case CA_SET_PLAYER_KEYS:
8515 int key_state = (action_mode == CA_MODE_ADD ? TRUE : FALSE);
8516 int element = getSpecialActionElement(action_arg_element,
8517 action_arg_number, EL_KEY_1);
8519 if (IS_KEY(element))
8521 for (i = 0; i < MAX_PLAYERS; i++)
8523 if (trigger_player_bits & (1 << i))
8525 stored_player[i].key[KEY_NR(element)] = key_state;
8528 DrawGameDoorValues();
8530 DrawGameValue_Keys(stored_player[i].key);
8533 redraw_mask |= REDRAW_DOOR_1;
8541 case CA_SET_PLAYER_SPEED:
8543 for (i = 0; i < MAX_PLAYERS; i++)
8545 if (trigger_player_bits & (1 << i))
8547 int move_stepsize = TILEX / stored_player[i].move_delay_value;
8549 if (action_arg == CA_ARG_SPEED_FASTER &&
8550 stored_player[i].cannot_move)
8552 action_arg_number = STEPSIZE_VERY_SLOW;
8554 else if (action_arg == CA_ARG_SPEED_SLOWER ||
8555 action_arg == CA_ARG_SPEED_FASTER)
8557 action_arg_number = 2;
8558 action_mode = (action_arg == CA_ARG_SPEED_SLOWER ? CA_MODE_DIVIDE :
8561 else if (action_arg == CA_ARG_NUMBER_RESET)
8563 action_arg_number = level.initial_player_stepsize[i];
8567 getModifiedActionNumber(move_stepsize,
8570 action_arg_number_min,
8571 action_arg_number_max);
8574 SetPlayerMoveSpeed(&stored_player[i], move_stepsize, FALSE);
8576 /* make sure that value is power of 2 */
8577 move_stepsize = (1 << log_2(move_stepsize));
8579 /* do no immediately change -- the player might just be moving */
8580 stored_player[i].move_delay_value_next = TILEX / move_stepsize;
8582 stored_player[i].cannot_move =
8583 (action_arg == CA_ARG_SPEED_NOT_MOVING ? TRUE : FALSE);
8591 case CA_SET_PLAYER_SHIELD:
8593 for (i = 0; i < MAX_PLAYERS; i++)
8595 if (trigger_player_bits & (1 << i))
8597 if (action_arg == CA_ARG_SHIELD_OFF)
8599 stored_player[i].shield_normal_time_left = 0;
8600 stored_player[i].shield_deadly_time_left = 0;
8602 else if (action_arg == CA_ARG_SHIELD_NORMAL)
8604 stored_player[i].shield_normal_time_left = 999999;
8606 else if (action_arg == CA_ARG_SHIELD_DEADLY)
8608 stored_player[i].shield_normal_time_left = 999999;
8609 stored_player[i].shield_deadly_time_left = 999999;
8617 #if USE_PLAYER_GRAVITY
8618 case CA_SET_PLAYER_GRAVITY:
8620 for (i = 0; i < MAX_PLAYERS; i++)
8622 if (trigger_player_bits & (1 << i))
8624 stored_player[i].gravity =
8625 (action_arg == CA_ARG_GRAVITY_OFF ? FALSE :
8626 action_arg == CA_ARG_GRAVITY_ON ? TRUE :
8627 action_arg == CA_ARG_GRAVITY_TOGGLE ? !stored_player[i].gravity :
8628 stored_player[i].gravity);
8636 case CA_SET_PLAYER_ARTWORK:
8638 for (i = 0; i < MAX_PLAYERS; i++)
8640 if (trigger_player_bits & (1 << i))
8642 int artwork_element = action_arg_element;
8644 if (action_arg == CA_ARG_ELEMENT_RESET)
8646 (level.use_artwork_element[i] ? level.artwork_element[i] :
8647 stored_player[i].element_nr);
8649 stored_player[i].artwork_element = artwork_element;
8651 SetPlayerWaiting(&stored_player[i], FALSE);
8653 /* set number of special actions for bored and sleeping animation */
8654 stored_player[i].num_special_action_bored =
8655 get_num_special_action(artwork_element,
8656 ACTION_BORING_1, ACTION_BORING_LAST);
8657 stored_player[i].num_special_action_sleeping =
8658 get_num_special_action(artwork_element,
8659 ACTION_SLEEPING_1, ACTION_SLEEPING_LAST);
8666 /* ---------- CE actions ---------------------------------------------- */
8668 case CA_SET_CE_VALUE:
8670 #if USE_NEW_CUSTOM_VALUE
8671 int last_ce_value = CustomValue[x][y];
8673 CustomValue[x][y] = action_arg_number_new;
8676 printf("::: CE value == %d\n", CustomValue[x][y]);
8679 if (CustomValue[x][y] != last_ce_value)
8681 CheckElementChange(x, y, element, EL_UNDEFINED, CE_VALUE_CHANGES);
8682 CheckTriggeredElementChange(x, y, element, CE_VALUE_CHANGES_OF_X);
8684 if (CustomValue[x][y] == 0)
8687 printf("::: CE_VALUE_GETS_ZERO\n");
8690 CheckElementChange(x, y, element, EL_UNDEFINED, CE_VALUE_GETS_ZERO);
8691 CheckTriggeredElementChange(x, y, element, CE_VALUE_GETS_ZERO_OF_X);
8694 printf("::: RESULT: %d, %d\n", Feld[x][y], ChangePage[x][y]);
8704 case CA_SET_CE_SCORE:
8706 #if USE_NEW_CUSTOM_VALUE
8707 int last_ce_score = ei->collect_score;
8709 ei->collect_score = action_arg_number_new;
8712 printf("::: CE score == %d\n", ei->collect_score);
8715 if (ei->collect_score != last_ce_score)
8717 CheckElementChange(x, y, element, EL_UNDEFINED, CE_SCORE_CHANGES);
8718 CheckTriggeredElementChange(x, y, element, CE_SCORE_CHANGES_OF_X);
8720 if (ei->collect_score == 0)
8725 printf("::: CE_SCORE_GETS_ZERO\n");
8728 CheckElementChange(x, y, element, EL_UNDEFINED, CE_SCORE_GETS_ZERO);
8729 CheckTriggeredElementChange(x, y, element, CE_SCORE_GETS_ZERO_OF_X);
8732 printf("::: RESULT: %d, %d\n", Feld[x][y], ChangePage[x][y]);
8737 This is a very special case that seems to be a mixture between
8738 CheckElementChange() and CheckTriggeredElementChange(): while
8739 the first one only affects single elements that are triggered
8740 directly, the second one affects multiple elements in the playfield
8741 that are triggered indirectly by another element. This is a third
8742 case: Changing the CE score always affects multiple identical CEs,
8743 so every affected CE must be checked, not only the single CE for
8744 which the CE score was changed in the first place (as every instance
8745 of that CE shares the same CE score, and therefore also can change)!
8747 SCAN_PLAYFIELD(xx, yy)
8749 if (Feld[xx][yy] == element)
8750 CheckElementChange(xx, yy, element, EL_UNDEFINED,
8751 CE_SCORE_GETS_ZERO);
8762 /* ---------- engine actions ------------------------------------------ */
8764 case CA_SET_ENGINE_SCAN_MODE:
8766 InitPlayfieldScanMode(action_arg);
8776 static void CreateFieldExt(int x, int y, int element, boolean is_change)
8778 int old_element = Feld[x][y];
8779 int new_element = get_element_from_group_element(element);
8780 int previous_move_direction = MovDir[x][y];
8781 #if USE_NEW_CUSTOM_VALUE
8782 int last_ce_value = CustomValue[x][y];
8784 boolean new_element_is_player = ELEM_IS_PLAYER(new_element);
8785 boolean add_player_onto_element = (new_element_is_player &&
8786 #if USE_CODE_THAT_BREAKS_SNAKE_BITE
8787 /* this breaks SnakeBite when a snake is
8788 halfway through a door that closes */
8789 /* NOW FIXED AT LEVEL INIT IN files.c */
8790 new_element != EL_SOKOBAN_FIELD_PLAYER &&
8792 IS_WALKABLE(old_element));
8795 /* check if element under the player changes from accessible to unaccessible
8796 (needed for special case of dropping element which then changes) */
8797 if (IS_PLAYER(x, y) && !PLAYER_EXPLOSION_PROTECTED(x, y) &&
8798 IS_ACCESSIBLE(old_element) && !IS_ACCESSIBLE(new_element))
8806 if (!add_player_onto_element)
8808 if (IS_MOVING(x, y) || IS_BLOCKED(x, y))
8809 RemoveMovingField(x, y);
8813 Feld[x][y] = new_element;
8815 #if !USE_GFX_RESET_GFX_ANIMATION
8816 ResetGfxAnimation(x, y);
8817 ResetRandomAnimationValue(x, y);
8820 if (element_info[new_element].move_direction_initial == MV_START_PREVIOUS)
8821 MovDir[x][y] = previous_move_direction;
8823 #if USE_NEW_CUSTOM_VALUE
8824 if (element_info[new_element].use_last_ce_value)
8825 CustomValue[x][y] = last_ce_value;
8828 InitField_WithBug1(x, y, FALSE);
8830 new_element = Feld[x][y]; /* element may have changed */
8832 #if USE_GFX_RESET_GFX_ANIMATION
8833 ResetGfxAnimation(x, y);
8834 ResetRandomAnimationValue(x, y);
8837 DrawLevelField(x, y);
8839 if (GFX_CRUMBLED(new_element))
8840 DrawLevelFieldCrumbledSandNeighbours(x, y);
8844 /* check if element under the player changes from accessible to unaccessible
8845 (needed for special case of dropping element which then changes) */
8846 /* (must be checked after creating new element for walkable group elements) */
8847 if (IS_PLAYER(x, y) && !PLAYER_EXPLOSION_PROTECTED(x, y) &&
8848 IS_ACCESSIBLE(old_element) && !IS_ACCESSIBLE(new_element))
8856 /* "ChangeCount" not set yet to allow "entered by player" change one time */
8857 if (new_element_is_player)
8858 RelocatePlayer(x, y, new_element);
8861 ChangeCount[x][y]++; /* count number of changes in the same frame */
8863 TestIfBadThingTouchesPlayer(x, y);
8864 TestIfPlayerTouchesCustomElement(x, y);
8865 TestIfElementTouchesCustomElement(x, y);
8868 static void CreateField(int x, int y, int element)
8870 CreateFieldExt(x, y, element, FALSE);
8873 static void CreateElementFromChange(int x, int y, int element)
8875 element = GET_VALID_RUNTIME_ELEMENT(element);
8877 #if USE_STOP_CHANGED_ELEMENTS
8878 if (game.engine_version >= VERSION_IDENT(3,2,0,7))
8880 int old_element = Feld[x][y];
8882 /* prevent changed element from moving in same engine frame
8883 unless both old and new element can either fall or move */
8884 if ((!CAN_FALL(old_element) || !CAN_FALL(element)) &&
8885 (!CAN_MOVE(old_element) || !CAN_MOVE(element)))
8890 CreateFieldExt(x, y, element, TRUE);
8893 static boolean ChangeElement(int x, int y, int element, int page)
8895 struct ElementInfo *ei = &element_info[element];
8896 struct ElementChangeInfo *change = &ei->change_page[page];
8897 int ce_value = CustomValue[x][y];
8898 int ce_score = ei->collect_score;
8900 int old_element = Feld[x][y];
8902 /* always use default change event to prevent running into a loop */
8903 if (ChangeEvent[x][y] == -1)
8904 ChangeEvent[x][y] = CE_DELAY;
8906 if (ChangeEvent[x][y] == CE_DELAY)
8908 /* reset actual trigger element, trigger player and action element */
8909 change->actual_trigger_element = EL_EMPTY;
8910 change->actual_trigger_player = EL_PLAYER_1;
8911 change->actual_trigger_side = CH_SIDE_NONE;
8912 change->actual_trigger_ce_value = 0;
8913 change->actual_trigger_ce_score = 0;
8916 /* do not change elements more than a specified maximum number of changes */
8917 if (ChangeCount[x][y] >= game.max_num_changes_per_frame)
8920 ChangeCount[x][y]++; /* count number of changes in the same frame */
8922 if (change->explode)
8929 if (change->use_target_content)
8931 boolean complete_replace = TRUE;
8932 boolean can_replace[3][3];
8935 for (yy = 0; yy < 3; yy++) for (xx = 0; xx < 3 ; xx++)
8938 boolean is_walkable;
8939 boolean is_diggable;
8940 boolean is_collectible;
8941 boolean is_removable;
8942 boolean is_destructible;
8943 int ex = x + xx - 1;
8944 int ey = y + yy - 1;
8945 int content_element = change->target_content.e[xx][yy];
8948 can_replace[xx][yy] = TRUE;
8950 if (ex == x && ey == y) /* do not check changing element itself */
8953 if (content_element == EL_EMPTY_SPACE)
8955 can_replace[xx][yy] = FALSE; /* do not replace border with space */
8960 if (!IN_LEV_FIELD(ex, ey))
8962 can_replace[xx][yy] = FALSE;
8963 complete_replace = FALSE;
8970 if (IS_MOVING(ex, ey) || IS_BLOCKED(ex, ey))
8971 e = MovingOrBlocked2Element(ex, ey);
8973 is_empty = (IS_FREE(ex, ey) ||
8974 (IS_FREE_OR_PLAYER(ex, ey) && IS_WALKABLE(content_element)));
8976 is_walkable = (is_empty || IS_WALKABLE(e));
8977 is_diggable = (is_empty || IS_DIGGABLE(e));
8978 is_collectible = (is_empty || IS_COLLECTIBLE(e));
8979 is_destructible = (is_empty || !IS_INDESTRUCTIBLE(e));
8980 is_removable = (is_diggable || is_collectible);
8982 can_replace[xx][yy] =
8983 (((change->replace_when == CP_WHEN_EMPTY && is_empty) ||
8984 (change->replace_when == CP_WHEN_WALKABLE && is_walkable) ||
8985 (change->replace_when == CP_WHEN_DIGGABLE && is_diggable) ||
8986 (change->replace_when == CP_WHEN_COLLECTIBLE && is_collectible) ||
8987 (change->replace_when == CP_WHEN_REMOVABLE && is_removable) ||
8988 (change->replace_when == CP_WHEN_DESTRUCTIBLE && is_destructible)) &&
8989 !(IS_PLAYER(ex, ey) && ELEM_IS_PLAYER(content_element)));
8991 if (!can_replace[xx][yy])
8992 complete_replace = FALSE;
8995 if (!change->only_if_complete || complete_replace)
8997 boolean something_has_changed = FALSE;
8999 if (change->only_if_complete && change->use_random_replace &&
9000 RND(100) < change->random_percentage)
9003 for (yy = 0; yy < 3; yy++) for (xx = 0; xx < 3 ; xx++)
9005 int ex = x + xx - 1;
9006 int ey = y + yy - 1;
9007 int content_element;
9009 if (can_replace[xx][yy] && (!change->use_random_replace ||
9010 RND(100) < change->random_percentage))
9012 if (IS_MOVING(ex, ey) || IS_BLOCKED(ex, ey))
9013 RemoveMovingField(ex, ey);
9015 ChangeEvent[ex][ey] = ChangeEvent[x][y];
9017 content_element = change->target_content.e[xx][yy];
9018 target_element = GET_TARGET_ELEMENT(element, content_element, change,
9019 ce_value, ce_score);
9021 CreateElementFromChange(ex, ey, target_element);
9023 something_has_changed = TRUE;
9025 /* for symmetry reasons, freeze newly created border elements */
9026 if (ex != x || ey != y)
9027 Stop[ex][ey] = TRUE; /* no more moving in this frame */
9031 if (something_has_changed)
9033 PlayLevelSoundElementAction(x, y, element, ACTION_CHANGING);
9034 PlayLevelSoundElementAction(x, y, element, ACTION_PAGE_1 + page);
9040 target_element = GET_TARGET_ELEMENT(element, change->target_element, change,
9041 ce_value, ce_score);
9043 if (element == EL_DIAGONAL_GROWING ||
9044 element == EL_DIAGONAL_SHRINKING)
9046 target_element = Store[x][y];
9048 Store[x][y] = EL_EMPTY;
9051 CreateElementFromChange(x, y, target_element);
9053 PlayLevelSoundElementAction(x, y, element, ACTION_CHANGING);
9054 PlayLevelSoundElementAction(x, y, element, ACTION_PAGE_1 + page);
9057 /* this uses direct change before indirect change */
9058 CheckTriggeredElementChangeByPage(x, y, old_element, CE_CHANGE_OF_X, page);
9063 #if USE_NEW_DELAYED_ACTION
9065 static void HandleElementChange(int x, int y, int page)
9067 int element = MovingOrBlocked2Element(x, y);
9068 struct ElementInfo *ei = &element_info[element];
9069 struct ElementChangeInfo *change = &ei->change_page[page];
9072 if (!CAN_CHANGE_OR_HAS_ACTION(element) &&
9073 !CAN_CHANGE_OR_HAS_ACTION(Back[x][y]))
9076 printf("HandleElementChange(): %d,%d: element = %d ('%s')\n",
9077 x, y, element, element_info[element].token_name);
9078 printf("HandleElementChange(): This should never happen!\n");
9083 /* this can happen with classic bombs on walkable, changing elements */
9084 if (!CAN_CHANGE_OR_HAS_ACTION(element))
9087 if (!CAN_CHANGE(Back[x][y])) /* prevent permanent repetition */
9088 ChangeDelay[x][y] = 0;
9094 if (ChangeDelay[x][y] == 0) /* initialize element change */
9096 ChangeDelay[x][y] = GET_CHANGE_DELAY(change) + 1;
9098 if (change->can_change)
9100 ResetGfxAnimation(x, y);
9101 ResetRandomAnimationValue(x, y);
9103 if (change->pre_change_function)
9104 change->pre_change_function(x, y);
9108 ChangeDelay[x][y]--;
9110 if (ChangeDelay[x][y] != 0) /* continue element change */
9112 if (change->can_change)
9114 int graphic = el_act_dir2img(element, GfxAction[x][y], GfxDir[x][y]);
9116 if (IS_ANIMATED(graphic))
9117 DrawLevelGraphicAnimationIfNeeded(x, y, graphic);
9119 if (change->change_function)
9120 change->change_function(x, y);
9123 else /* finish element change */
9125 if (ChangePage[x][y] != -1) /* remember page from delayed change */
9127 page = ChangePage[x][y];
9128 ChangePage[x][y] = -1;
9130 change = &ei->change_page[page];
9133 if (IS_MOVING(x, y)) /* never change a running system ;-) */
9135 ChangeDelay[x][y] = 1; /* try change after next move step */
9136 ChangePage[x][y] = page; /* remember page to use for change */
9141 if (change->can_change)
9143 if (ChangeElement(x, y, element, page))
9145 if (change->post_change_function)
9146 change->post_change_function(x, y);
9150 if (change->has_action)
9151 ExecuteCustomElementAction(x, y, element, page);
9157 static void HandleElementChange(int x, int y, int page)
9159 int element = MovingOrBlocked2Element(x, y);
9160 struct ElementInfo *ei = &element_info[element];
9161 struct ElementChangeInfo *change = &ei->change_page[page];
9164 if (!CAN_CHANGE(element) && !CAN_CHANGE(Back[x][y]))
9167 printf("HandleElementChange(): %d,%d: element = %d ('%s')\n",
9168 x, y, element, element_info[element].token_name);
9169 printf("HandleElementChange(): This should never happen!\n");
9174 /* this can happen with classic bombs on walkable, changing elements */
9175 if (!CAN_CHANGE(element))
9178 if (!CAN_CHANGE(Back[x][y])) /* prevent permanent repetition */
9179 ChangeDelay[x][y] = 0;
9185 if (ChangeDelay[x][y] == 0) /* initialize element change */
9187 ChangeDelay[x][y] = GET_CHANGE_DELAY(change) + 1;
9189 ResetGfxAnimation(x, y);
9190 ResetRandomAnimationValue(x, y);
9192 if (change->pre_change_function)
9193 change->pre_change_function(x, y);
9196 ChangeDelay[x][y]--;
9198 if (ChangeDelay[x][y] != 0) /* continue element change */
9200 int graphic = el_act_dir2img(element, GfxAction[x][y], GfxDir[x][y]);
9202 if (IS_ANIMATED(graphic))
9203 DrawLevelGraphicAnimationIfNeeded(x, y, graphic);
9205 if (change->change_function)
9206 change->change_function(x, y);
9208 else /* finish element change */
9210 if (ChangePage[x][y] != -1) /* remember page from delayed change */
9212 page = ChangePage[x][y];
9213 ChangePage[x][y] = -1;
9215 change = &ei->change_page[page];
9218 if (IS_MOVING(x, y)) /* never change a running system ;-) */
9220 ChangeDelay[x][y] = 1; /* try change after next move step */
9221 ChangePage[x][y] = page; /* remember page to use for change */
9226 if (ChangeElement(x, y, element, page))
9228 if (change->post_change_function)
9229 change->post_change_function(x, y);
9236 static boolean CheckTriggeredElementChangeExt(int trigger_x, int trigger_y,
9237 int trigger_element,
9243 boolean change_done_any = FALSE;
9244 int trigger_page_bits = (trigger_page < 0 ? CH_PAGE_ANY : 1 << trigger_page);
9247 if (!(trigger_events[trigger_element][trigger_event]))
9250 for (i = 0; i < NUM_CUSTOM_ELEMENTS; i++)
9252 int element = EL_CUSTOM_START + i;
9253 boolean change_done = FALSE;
9256 if (!CAN_CHANGE_OR_HAS_ACTION(element) ||
9257 !HAS_ANY_CHANGE_EVENT(element, trigger_event))
9260 for (p = 0; p < element_info[element].num_change_pages; p++)
9262 struct ElementChangeInfo *change = &element_info[element].change_page[p];
9264 if (change->can_change_or_has_action &&
9265 change->has_event[trigger_event] &&
9266 change->trigger_side & trigger_side &&
9267 change->trigger_player & trigger_player &&
9268 change->trigger_page & trigger_page_bits &&
9269 IS_EQUAL_OR_IN_GROUP(trigger_element, change->trigger_element))
9271 change->actual_trigger_element = trigger_element;
9272 change->actual_trigger_player = EL_PLAYER_1 + log_2(trigger_player);
9273 change->actual_trigger_side = trigger_side;
9274 change->actual_trigger_ce_value = CustomValue[trigger_x][trigger_y];
9275 change->actual_trigger_ce_score = GET_CE_SCORE(trigger_element);
9277 if ((change->can_change && !change_done) || change->has_action)
9282 SCAN_PLAYFIELD(x, y)
9284 for (y = 0; y < lev_fieldy; y++) for (x = 0; x < lev_fieldx; x++)
9287 if (Feld[x][y] == element)
9289 if (change->can_change && !change_done)
9291 ChangeDelay[x][y] = 1;
9292 ChangeEvent[x][y] = trigger_event;
9294 HandleElementChange(x, y, p);
9296 #if USE_NEW_DELAYED_ACTION
9297 else if (change->has_action)
9299 ExecuteCustomElementAction(x, y, element, p);
9300 PlayLevelSoundElementAction(x, y, element, ACTION_PAGE_1 + p);
9303 if (change->has_action)
9305 ExecuteCustomElementAction(x, y, element, p);
9306 PlayLevelSoundElementAction(x, y, element, ACTION_PAGE_1 + p);
9312 if (change->can_change)
9315 change_done_any = TRUE;
9322 return change_done_any;
9325 static boolean CheckElementChangeExt(int x, int y,
9327 int trigger_element,
9332 boolean change_done = FALSE;
9335 if (!CAN_CHANGE_OR_HAS_ACTION(element) ||
9336 !HAS_ANY_CHANGE_EVENT(element, trigger_event))
9339 if (Feld[x][y] == EL_BLOCKED)
9341 Blocked2Moving(x, y, &x, &y);
9342 element = Feld[x][y];
9346 /* check if element has already changed */
9347 if (Feld[x][y] != element)
9350 /* check if element has already changed or is about to change after moving */
9351 if ((game.engine_version < VERSION_IDENT(3,2,0,7) &&
9352 Feld[x][y] != element) ||
9354 (game.engine_version >= VERSION_IDENT(3,2,0,7) &&
9355 (ChangeCount[x][y] >= game.max_num_changes_per_frame ||
9356 ChangePage[x][y] != -1)))
9360 for (p = 0; p < element_info[element].num_change_pages; p++)
9362 struct ElementChangeInfo *change = &element_info[element].change_page[p];
9364 boolean check_trigger_element =
9365 (trigger_event == CE_TOUCHING_X ||
9366 trigger_event == CE_HITTING_X ||
9367 trigger_event == CE_HIT_BY_X);
9369 if (change->can_change_or_has_action &&
9370 change->has_event[trigger_event] &&
9371 change->trigger_side & trigger_side &&
9372 change->trigger_player & trigger_player &&
9373 (!check_trigger_element ||
9374 IS_EQUAL_OR_IN_GROUP(trigger_element, change->trigger_element)))
9376 change->actual_trigger_element = trigger_element;
9377 change->actual_trigger_player = EL_PLAYER_1 + log_2(trigger_player);
9378 change->actual_trigger_side = trigger_side;
9379 change->actual_trigger_ce_value = CustomValue[x][y];
9380 change->actual_trigger_ce_score = GET_CE_SCORE(trigger_element);
9382 /* special case: trigger element not at (x,y) position for some events */
9383 if (check_trigger_element)
9395 { 0, 0 }, { 0, 0 }, { 0, 0 },
9399 int xx = x + move_xy[MV_DIR_OPPOSITE(trigger_side)].dx;
9400 int yy = y + move_xy[MV_DIR_OPPOSITE(trigger_side)].dy;
9402 change->actual_trigger_ce_value = CustomValue[xx][yy];
9403 change->actual_trigger_ce_score = GET_CE_SCORE(trigger_element);
9406 if (change->can_change && !change_done)
9408 ChangeDelay[x][y] = 1;
9409 ChangeEvent[x][y] = trigger_event;
9411 HandleElementChange(x, y, p);
9415 #if USE_NEW_DELAYED_ACTION
9416 else if (change->has_action)
9418 ExecuteCustomElementAction(x, y, element, p);
9419 PlayLevelSoundElementAction(x, y, element, ACTION_PAGE_1 + p);
9422 if (change->has_action)
9424 ExecuteCustomElementAction(x, y, element, p);
9425 PlayLevelSoundElementAction(x, y, element, ACTION_PAGE_1 + p);
9434 static void PlayPlayerSound(struct PlayerInfo *player)
9436 int jx = player->jx, jy = player->jy;
9437 int sound_element = player->artwork_element;
9438 int last_action = player->last_action_waiting;
9439 int action = player->action_waiting;
9441 if (player->is_waiting)
9443 if (action != last_action)
9444 PlayLevelSoundElementAction(jx, jy, sound_element, action);
9446 PlayLevelSoundElementActionIfLoop(jx, jy, sound_element, action);
9450 if (action != last_action)
9451 StopSound(element_info[sound_element].sound[last_action]);
9453 if (last_action == ACTION_SLEEPING)
9454 PlayLevelSoundElementAction(jx, jy, sound_element, ACTION_AWAKENING);
9458 static void PlayAllPlayersSound()
9462 for (i = 0; i < MAX_PLAYERS; i++)
9463 if (stored_player[i].active)
9464 PlayPlayerSound(&stored_player[i]);
9467 static void SetPlayerWaiting(struct PlayerInfo *player, boolean is_waiting)
9469 boolean last_waiting = player->is_waiting;
9470 int move_dir = player->MovDir;
9472 player->dir_waiting = move_dir;
9473 player->last_action_waiting = player->action_waiting;
9477 if (!last_waiting) /* not waiting -> waiting */
9479 player->is_waiting = TRUE;
9481 player->frame_counter_bored =
9483 game.player_boring_delay_fixed +
9484 SimpleRND(game.player_boring_delay_random);
9485 player->frame_counter_sleeping =
9487 game.player_sleeping_delay_fixed +
9488 SimpleRND(game.player_sleeping_delay_random);
9491 InitPlayerGfxAnimation(player, ACTION_WAITING, move_dir);
9493 InitPlayerGfxAnimation(player, ACTION_WAITING, player->MovDir);
9497 if (game.player_sleeping_delay_fixed +
9498 game.player_sleeping_delay_random > 0 &&
9499 player->anim_delay_counter == 0 &&
9500 player->post_delay_counter == 0 &&
9501 FrameCounter >= player->frame_counter_sleeping)
9502 player->is_sleeping = TRUE;
9503 else if (game.player_boring_delay_fixed +
9504 game.player_boring_delay_random > 0 &&
9505 FrameCounter >= player->frame_counter_bored)
9506 player->is_bored = TRUE;
9508 player->action_waiting = (player->is_sleeping ? ACTION_SLEEPING :
9509 player->is_bored ? ACTION_BORING :
9513 if (player->is_sleeping && player->use_murphy)
9515 /* special case for sleeping Murphy when leaning against non-free tile */
9517 if (!IN_LEV_FIELD(player->jx - 1, player->jy) ||
9518 (Feld[player->jx - 1][player->jy] != EL_EMPTY &&
9519 !IS_MOVING(player->jx - 1, player->jy)))
9521 else if (!IN_LEV_FIELD(player->jx + 1, player->jy) ||
9522 (Feld[player->jx + 1][player->jy] != EL_EMPTY &&
9523 !IS_MOVING(player->jx + 1, player->jy)))
9524 move_dir = MV_RIGHT;
9526 player->is_sleeping = FALSE;
9528 player->dir_waiting = move_dir;
9532 if (player->is_sleeping)
9534 if (player->num_special_action_sleeping > 0)
9536 if (player->anim_delay_counter == 0 && player->post_delay_counter == 0)
9538 int last_special_action = player->special_action_sleeping;
9539 int num_special_action = player->num_special_action_sleeping;
9540 int special_action =
9541 (last_special_action == ACTION_DEFAULT ? ACTION_SLEEPING_1 :
9542 last_special_action == ACTION_SLEEPING ? ACTION_SLEEPING :
9543 last_special_action < ACTION_SLEEPING_1 + num_special_action - 1 ?
9544 last_special_action + 1 : ACTION_SLEEPING);
9545 int special_graphic =
9546 el_act_dir2img(player->artwork_element, special_action, move_dir);
9548 player->anim_delay_counter =
9549 graphic_info[special_graphic].anim_delay_fixed +
9550 SimpleRND(graphic_info[special_graphic].anim_delay_random);
9551 player->post_delay_counter =
9552 graphic_info[special_graphic].post_delay_fixed +
9553 SimpleRND(graphic_info[special_graphic].post_delay_random);
9555 player->special_action_sleeping = special_action;
9558 if (player->anim_delay_counter > 0)
9560 player->action_waiting = player->special_action_sleeping;
9561 player->anim_delay_counter--;
9563 else if (player->post_delay_counter > 0)
9565 player->post_delay_counter--;
9569 else if (player->is_bored)
9571 if (player->num_special_action_bored > 0)
9573 if (player->anim_delay_counter == 0 && player->post_delay_counter == 0)
9575 int special_action =
9576 ACTION_BORING_1 + SimpleRND(player->num_special_action_bored);
9577 int special_graphic =
9578 el_act_dir2img(player->artwork_element, special_action, move_dir);
9580 player->anim_delay_counter =
9581 graphic_info[special_graphic].anim_delay_fixed +
9582 SimpleRND(graphic_info[special_graphic].anim_delay_random);
9583 player->post_delay_counter =
9584 graphic_info[special_graphic].post_delay_fixed +
9585 SimpleRND(graphic_info[special_graphic].post_delay_random);
9587 player->special_action_bored = special_action;
9590 if (player->anim_delay_counter > 0)
9592 player->action_waiting = player->special_action_bored;
9593 player->anim_delay_counter--;
9595 else if (player->post_delay_counter > 0)
9597 player->post_delay_counter--;
9602 else if (last_waiting) /* waiting -> not waiting */
9604 player->is_waiting = FALSE;
9605 player->is_bored = FALSE;
9606 player->is_sleeping = FALSE;
9608 player->frame_counter_bored = -1;
9609 player->frame_counter_sleeping = -1;
9611 player->anim_delay_counter = 0;
9612 player->post_delay_counter = 0;
9614 player->dir_waiting = player->MovDir;
9615 player->action_waiting = ACTION_DEFAULT;
9617 player->special_action_bored = ACTION_DEFAULT;
9618 player->special_action_sleeping = ACTION_DEFAULT;
9622 static byte PlayerActions(struct PlayerInfo *player, byte player_action)
9624 boolean moved = FALSE, snapped = FALSE, dropped = FALSE;
9625 int left = player_action & JOY_LEFT;
9626 int right = player_action & JOY_RIGHT;
9627 int up = player_action & JOY_UP;
9628 int down = player_action & JOY_DOWN;
9629 int button1 = player_action & JOY_BUTTON_1;
9630 int button2 = player_action & JOY_BUTTON_2;
9631 int dx = (left ? -1 : right ? 1 : 0);
9632 int dy = (up ? -1 : down ? 1 : 0);
9634 if (!player->active || tape.pausing)
9640 snapped = SnapField(player, dx, dy);
9644 dropped = DropElement(player);
9646 moved = MovePlayer(player, dx, dy);
9649 if (tape.single_step && tape.recording && !tape.pausing)
9651 if (button1 || (dropped && !moved))
9653 TapeTogglePause(TAPE_TOGGLE_AUTOMATIC);
9654 SnapField(player, 0, 0); /* stop snapping */
9658 SetPlayerWaiting(player, FALSE);
9660 return player_action;
9664 /* no actions for this player (no input at player's configured device) */
9666 DigField(player, 0, 0, 0, 0, 0, 0, DF_NO_PUSH);
9667 SnapField(player, 0, 0);
9668 CheckGravityMovementWhenNotMoving(player);
9670 if (player->MovPos == 0)
9671 SetPlayerWaiting(player, TRUE);
9673 if (player->MovPos == 0) /* needed for tape.playing */
9674 player->is_moving = FALSE;
9676 player->is_dropping = FALSE;
9677 player->is_dropping_pressed = FALSE;
9678 player->drop_pressed_delay = 0;
9684 static void CheckLevelTime()
9688 if (level.game_engine_type == GAME_ENGINE_TYPE_EM)
9690 if (level.native_em_level->lev->home == 0) /* all players at home */
9692 local_player->LevelSolved = TRUE;
9693 AllPlayersGone = TRUE;
9695 level.native_em_level->lev->home = -1;
9698 if (level.native_em_level->ply[0]->alive == 0 &&
9699 level.native_em_level->ply[1]->alive == 0 &&
9700 level.native_em_level->ply[2]->alive == 0 &&
9701 level.native_em_level->ply[3]->alive == 0) /* all dead */
9702 AllPlayersGone = TRUE;
9705 if (TimeFrames >= FRAMES_PER_SECOND)
9710 for (i = 0; i < MAX_PLAYERS; i++)
9712 struct PlayerInfo *player = &stored_player[i];
9714 if (SHIELD_ON(player))
9716 player->shield_normal_time_left--;
9718 if (player->shield_deadly_time_left > 0)
9719 player->shield_deadly_time_left--;
9723 if (!level.use_step_counter)
9731 if (TimeLeft <= 10 && setup.time_limit)
9732 PlaySoundStereo(SND_GAME_RUNNING_OUT_OF_TIME, SOUND_MIDDLE);
9734 DrawGameValue_Time(TimeLeft);
9736 if (!TimeLeft && setup.time_limit)
9738 if (level.game_engine_type == GAME_ENGINE_TYPE_EM)
9739 level.native_em_level->lev->killed_out_of_time = TRUE;
9741 for (i = 0; i < MAX_PLAYERS; i++)
9742 KillPlayer(&stored_player[i]);
9745 else if (level.time == 0 && !AllPlayersGone) /* level w/o time limit */
9746 DrawGameValue_Time(TimePlayed);
9748 level.native_em_level->lev->time =
9749 (level.time == 0 ? TimePlayed : TimeLeft);
9752 if (tape.recording || tape.playing)
9753 DrawVideoDisplay(VIDEO_STATE_TIME_ON, TapeTime);
9757 void AdvanceFrameAndPlayerCounters(int player_nr)
9762 Error(ERR_NETWORK_CLIENT, "advancing frame counter from %d to %d",
9763 FrameCounter, FrameCounter + 1);
9766 /* advance frame counters (global frame counter and time frame counter) */
9770 /* advance player counters (counters for move delay, move animation etc.) */
9771 for (i = 0; i < MAX_PLAYERS; i++)
9773 boolean advance_player_counters = (player_nr == -1 || player_nr == i);
9774 int move_delay_value = stored_player[i].move_delay_value;
9775 int move_frames = MOVE_DELAY_NORMAL_SPEED / move_delay_value;
9777 if (!advance_player_counters) /* not all players may be affected */
9780 #if USE_NEW_PLAYER_ANIM
9781 if (move_frames == 0) /* less than one move per game frame */
9783 int stepsize = TILEX / move_delay_value;
9784 int delay = move_delay_value / MOVE_DELAY_NORMAL_SPEED;
9785 int count = (stored_player[i].is_moving ?
9786 ABS(stored_player[i].MovPos) / stepsize : FrameCounter);
9788 if (count % delay == 0)
9793 stored_player[i].Frame += move_frames;
9795 if (stored_player[i].MovPos != 0)
9796 stored_player[i].StepFrame += move_frames;
9798 if (stored_player[i].move_delay > 0)
9799 stored_player[i].move_delay--;
9801 /* due to bugs in previous versions, counter must count up, not down */
9802 if (stored_player[i].push_delay != -1)
9803 stored_player[i].push_delay++;
9805 if (stored_player[i].drop_delay > 0)
9806 stored_player[i].drop_delay--;
9808 if (stored_player[i].is_dropping_pressed)
9809 stored_player[i].drop_pressed_delay++;
9813 void StartGameActions(boolean init_network_game, boolean record_tape,
9816 unsigned long new_random_seed = InitRND(random_seed);
9819 TapeStartRecording(new_random_seed);
9821 #if defined(NETWORK_AVALIABLE)
9822 if (init_network_game)
9824 SendToServer_StartPlaying();
9832 game_status = GAME_MODE_PLAYING;
9839 static unsigned long game_frame_delay = 0;
9840 unsigned long game_frame_delay_value;
9841 byte *recorded_player_action;
9842 byte summarized_player_action = 0;
9843 byte tape_action[MAX_PLAYERS];
9846 if (game.restart_level)
9847 StartGameActions(options.network, setup.autorecord, NEW_RANDOMIZE);
9849 if (level.game_engine_type == GAME_ENGINE_TYPE_EM)
9851 if (level.native_em_level->lev->home == 0) /* all players at home */
9853 local_player->LevelSolved = TRUE;
9854 AllPlayersGone = TRUE;
9856 level.native_em_level->lev->home = -1;
9859 if (level.native_em_level->ply[0]->alive == 0 &&
9860 level.native_em_level->ply[1]->alive == 0 &&
9861 level.native_em_level->ply[2]->alive == 0 &&
9862 level.native_em_level->ply[3]->alive == 0) /* all dead */
9863 AllPlayersGone = TRUE;
9866 if (local_player->LevelSolved)
9869 if (AllPlayersGone && !TAPE_IS_STOPPED(tape))
9872 if (game_status != GAME_MODE_PLAYING) /* status might have changed */
9875 game_frame_delay_value =
9876 (tape.playing && tape.fast_forward ? FfwdFrameDelay : GameFrameDelay);
9878 if (tape.playing && tape.warp_forward && !tape.pausing)
9879 game_frame_delay_value = 0;
9881 /* ---------- main game synchronization point ---------- */
9883 WaitUntilDelayReached(&game_frame_delay, game_frame_delay_value);
9885 if (network_playing && !network_player_action_received)
9887 /* try to get network player actions in time */
9889 #if defined(NETWORK_AVALIABLE)
9890 /* last chance to get network player actions without main loop delay */
9894 /* game was quit by network peer */
9895 if (game_status != GAME_MODE_PLAYING)
9898 if (!network_player_action_received)
9899 return; /* failed to get network player actions in time */
9901 /* do not yet reset "network_player_action_received" (for tape.pausing) */
9907 /* at this point we know that we really continue executing the game */
9910 network_player_action_received = FALSE;
9913 recorded_player_action = (tape.playing ? TapePlayAction() : NULL);
9915 if (tape.set_centered_player)
9917 game.centered_player_nr_next = tape.centered_player_nr_next;
9918 game.set_centered_player = TRUE;
9921 for (i = 0; i < MAX_PLAYERS; i++)
9923 summarized_player_action |= stored_player[i].action;
9925 if (!network_playing)
9926 stored_player[i].effective_action = stored_player[i].action;
9929 #if defined(NETWORK_AVALIABLE)
9930 if (network_playing)
9931 SendToServer_MovePlayer(summarized_player_action);
9934 if (!options.network && !setup.team_mode)
9935 local_player->effective_action = summarized_player_action;
9937 if (setup.team_mode && setup.input_on_focus && game.centered_player_nr != -1)
9939 for (i = 0; i < MAX_PLAYERS; i++)
9940 stored_player[i].effective_action =
9941 (i == game.centered_player_nr ? summarized_player_action : 0);
9944 if (recorded_player_action != NULL)
9945 for (i = 0; i < MAX_PLAYERS; i++)
9946 stored_player[i].effective_action = recorded_player_action[i];
9948 for (i = 0; i < MAX_PLAYERS; i++)
9950 tape_action[i] = stored_player[i].effective_action;
9952 /* (this can only happen in the R'n'D game engine) */
9953 if (tape.recording && tape_action[i] && !tape.player_participates[i])
9954 tape.player_participates[i] = TRUE; /* player just appeared from CE */
9957 /* only record actions from input devices, but not programmed actions */
9959 TapeRecordAction(tape_action);
9961 if (level.game_engine_type == GAME_ENGINE_TYPE_EM)
9963 GameActions_EM_Main();
9971 void GameActions_EM_Main()
9973 byte effective_action[MAX_PLAYERS];
9974 boolean warp_mode = (tape.playing && tape.warp_forward && !tape.pausing);
9977 for (i = 0; i < MAX_PLAYERS; i++)
9978 effective_action[i] = stored_player[i].effective_action;
9981 printf("::: %04d: %08x\n", FrameCounter, effective_action[0]);
9984 GameActions_EM(effective_action, warp_mode);
9988 AdvanceFrameAndPlayerCounters(-1); /* advance counters for all players */
9991 void GameActions_RND()
9993 int magic_wall_x = 0, magic_wall_y = 0;
9994 int i, x, y, element, graphic;
9996 InitPlayfieldScanModeVars();
9998 #if USE_ONE_MORE_CHANGE_PER_FRAME
9999 if (game.engine_version >= VERSION_IDENT(3,2,0,7))
10001 SCAN_PLAYFIELD(x, y)
10003 ChangeCount[x][y] = 0;
10004 ChangeEvent[x][y] = -1;
10010 if (game.set_centered_player)
10012 boolean all_players_fit_to_screen = checkIfAllPlayersFitToScreen_RND();
10014 /* switching to "all players" only possible if all players fit to screen */
10015 if (game.centered_player_nr_next == -1 && !all_players_fit_to_screen)
10017 game.centered_player_nr_next = game.centered_player_nr;
10018 game.set_centered_player = FALSE;
10021 /* do not switch focus to non-existing (or non-active) player */
10022 if (game.centered_player_nr_next >= 0 &&
10023 !stored_player[game.centered_player_nr_next].active)
10025 game.centered_player_nr_next = game.centered_player_nr;
10026 game.set_centered_player = FALSE;
10030 if (game.set_centered_player &&
10031 ScreenMovPos == 0) /* screen currently aligned at tile position */
10035 if (game.centered_player_nr_next == -1)
10037 setScreenCenteredToAllPlayers(&sx, &sy);
10041 sx = stored_player[game.centered_player_nr_next].jx;
10042 sy = stored_player[game.centered_player_nr_next].jy;
10045 game.centered_player_nr = game.centered_player_nr_next;
10046 game.set_centered_player = FALSE;
10048 DrawRelocateScreen(sx, sy, MV_NONE, TRUE, setup.quick_switch);
10049 DrawGameDoorValues();
10053 for (i = 0; i < MAX_PLAYERS; i++)
10055 int actual_player_action = stored_player[i].effective_action;
10058 /* !!! THIS BREAKS THE FOLLOWING TAPES: !!!
10059 - rnd_equinox_tetrachloride 048
10060 - rnd_equinox_tetrachloride_ii 096
10061 - rnd_emanuel_schmieg 002
10062 - doctor_sloan_ww 001, 020
10064 if (stored_player[i].MovPos == 0)
10065 CheckGravityMovement(&stored_player[i]);
10068 /* overwrite programmed action with tape action */
10069 if (stored_player[i].programmed_action)
10070 actual_player_action = stored_player[i].programmed_action;
10073 PlayerActions(&stored_player[i], actual_player_action);
10075 tape_action[i] = PlayerActions(&stored_player[i], actual_player_action);
10077 if (tape.recording && tape_action[i] && !tape.player_participates[i])
10078 tape.player_participates[i] = TRUE; /* player just appeared from CE */
10081 ScrollPlayer(&stored_player[i], SCROLL_GO_ON);
10085 network_player_action_received = FALSE;
10088 ScrollScreen(NULL, SCROLL_GO_ON);
10090 /* for backwards compatibility, the following code emulates a fixed bug that
10091 occured when pushing elements (causing elements that just made their last
10092 pushing step to already (if possible) make their first falling step in the
10093 same game frame, which is bad); this code is also needed to use the famous
10094 "spring push bug" which is used in older levels and might be wanted to be
10095 used also in newer levels, but in this case the buggy pushing code is only
10096 affecting the "spring" element and no other elements */
10098 if (game.engine_version < VERSION_IDENT(2,2,0,7) || level.use_spring_bug)
10100 for (i = 0; i < MAX_PLAYERS; i++)
10102 struct PlayerInfo *player = &stored_player[i];
10103 int x = player->jx;
10104 int y = player->jy;
10106 if (player->active && player->is_pushing && player->is_moving &&
10108 (game.engine_version < VERSION_IDENT(2,2,0,7) ||
10109 Feld[x][y] == EL_SPRING))
10111 ContinueMoving(x, y);
10113 /* continue moving after pushing (this is actually a bug) */
10114 if (!IS_MOVING(x, y))
10116 Stop[x][y] = FALSE;
10123 SCAN_PLAYFIELD(x, y)
10125 for (y = 0; y < lev_fieldy; y++) for (x = 0; x < lev_fieldx; x++)
10128 ChangeCount[x][y] = 0;
10129 ChangeEvent[x][y] = -1;
10131 /* this must be handled before main playfield loop */
10132 if (Feld[x][y] == EL_PLAYER_IS_LEAVING)
10135 if (MovDelay[x][y] <= 0)
10139 #if USE_NEW_SNAP_DELAY
10140 if (Feld[x][y] == EL_ELEMENT_SNAPPING)
10143 if (MovDelay[x][y] <= 0)
10146 DrawLevelField(x, y);
10148 TestIfElementTouchesCustomElement(x, y); /* for empty space */
10154 if (ChangePage[x][y] != -1 && ChangeDelay[x][y] != 1)
10156 printf("GameActions(): x = %d, y = %d: ChangePage != -1\n", x, y);
10157 printf("GameActions(): This should never happen!\n");
10159 ChangePage[x][y] = -1;
10163 Stop[x][y] = FALSE;
10164 if (WasJustMoving[x][y] > 0)
10165 WasJustMoving[x][y]--;
10166 if (WasJustFalling[x][y] > 0)
10167 WasJustFalling[x][y]--;
10168 if (CheckCollision[x][y] > 0)
10169 CheckCollision[x][y]--;
10173 /* reset finished pushing action (not done in ContinueMoving() to allow
10174 continuous pushing animation for elements with zero push delay) */
10175 if (GfxAction[x][y] == ACTION_PUSHING && !IS_MOVING(x, y))
10177 ResetGfxAnimation(x, y);
10178 DrawLevelField(x, y);
10182 if (IS_BLOCKED(x, y))
10186 Blocked2Moving(x, y, &oldx, &oldy);
10187 if (!IS_MOVING(oldx, oldy))
10189 printf("GameActions(): (BLOCKED => MOVING) context corrupted!\n");
10190 printf("GameActions(): BLOCKED: x = %d, y = %d\n", x, y);
10191 printf("GameActions(): !MOVING: oldx = %d, oldy = %d\n", oldx, oldy);
10192 printf("GameActions(): This should never happen!\n");
10199 SCAN_PLAYFIELD(x, y)
10201 for (y = 0; y < lev_fieldy; y++) for (x = 0; x < lev_fieldx; x++)
10204 element = Feld[x][y];
10205 graphic = el_act_dir2img(element, GfxAction[x][y], GfxDir[x][y]);
10208 printf("::: %d,%d\n", x, y);
10210 if (element == EL_ROCK)
10211 printf("::: Yo man! Rocks can fall!\n");
10215 ResetGfxFrame(x, y, TRUE);
10217 if (graphic_info[graphic].anim_global_sync)
10218 GfxFrame[x][y] = FrameCounter;
10219 else if (ANIM_MODE(graphic) == ANIM_CE_VALUE)
10221 int old_gfx_frame = GfxFrame[x][y];
10223 GfxFrame[x][y] = CustomValue[x][y];
10226 if (GfxFrame[x][y] != old_gfx_frame)
10228 DrawLevelGraphicAnimation(x, y, graphic);
10230 else if (ANIM_MODE(graphic) == ANIM_CE_SCORE)
10232 int old_gfx_frame = GfxFrame[x][y];
10234 GfxFrame[x][y] = element_info[element].collect_score;
10237 if (GfxFrame[x][y] != old_gfx_frame)
10239 DrawLevelGraphicAnimation(x, y, graphic);
10241 else if (ANIM_MODE(graphic) == ANIM_CE_DELAY)
10243 int old_gfx_frame = GfxFrame[x][y];
10245 GfxFrame[x][y] = ChangeDelay[x][y];
10248 if (GfxFrame[x][y] != old_gfx_frame)
10250 DrawLevelGraphicAnimation(x, y, graphic);
10254 if (ANIM_MODE(graphic) == ANIM_RANDOM &&
10255 IS_NEXT_FRAME(GfxFrame[x][y], graphic))
10256 ResetRandomAnimationValue(x, y);
10258 SetRandomAnimationValue(x, y);
10260 PlayLevelSoundActionIfLoop(x, y, GfxAction[x][y]);
10262 if (IS_INACTIVE(element))
10264 if (IS_ANIMATED(graphic))
10265 DrawLevelGraphicAnimationIfNeeded(x, y, graphic);
10270 /* this may take place after moving, so 'element' may have changed */
10271 if (IS_CHANGING(x, y) &&
10272 (game.engine_version < VERSION_IDENT(3,0,7,1) || !Stop[x][y]))
10274 int page = element_info[element].event_page_nr[CE_DELAY];
10276 HandleElementChange(x, y, ChangePage[x][y] != -1 ? ChangePage[x][y] : page);
10280 printf("::: ChangeDelay == %d\n", ChangeDelay[x][y]);
10284 if (element == EL_CUSTOM_255)
10285 printf("::: ChangeDelay == %d\n", ChangeDelay[x][y]);
10289 HandleElementChange(x, y, page);
10291 if (CAN_CHANGE(element))
10292 HandleElementChange(x, y, page);
10294 if (HAS_ACTION(element))
10295 ExecuteCustomElementAction(x, y, element, page);
10300 element = Feld[x][y];
10301 graphic = el_act_dir2img(element, GfxAction[x][y], GfxDir[x][y]);
10304 if (!IS_MOVING(x, y) && (CAN_FALL(element) || CAN_MOVE(element)))
10308 element = Feld[x][y];
10309 graphic = el_act_dir2img(element, GfxAction[x][y], GfxDir[x][y]);
10311 if (IS_ANIMATED(graphic) &&
10312 !IS_MOVING(x, y) &&
10314 DrawLevelGraphicAnimationIfNeeded(x, y, graphic);
10316 if (IS_GEM(element) || element == EL_SP_INFOTRON)
10317 EdelsteinFunkeln(x, y);
10319 else if ((element == EL_ACID ||
10320 element == EL_EXIT_OPEN ||
10321 element == EL_SP_EXIT_OPEN ||
10322 element == EL_SP_TERMINAL ||
10323 element == EL_SP_TERMINAL_ACTIVE ||
10324 element == EL_EXTRA_TIME ||
10325 element == EL_SHIELD_NORMAL ||
10326 element == EL_SHIELD_DEADLY) &&
10327 IS_ANIMATED(graphic))
10328 DrawLevelGraphicAnimationIfNeeded(x, y, graphic);
10329 else if (IS_MOVING(x, y))
10330 ContinueMoving(x, y);
10331 else if (IS_ACTIVE_BOMB(element))
10332 CheckDynamite(x, y);
10333 else if (element == EL_AMOEBA_GROWING)
10334 AmoebeWaechst(x, y);
10335 else if (element == EL_AMOEBA_SHRINKING)
10336 AmoebaDisappearing(x, y);
10338 #if !USE_NEW_AMOEBA_CODE
10339 else if (IS_AMOEBALIVE(element))
10340 AmoebeAbleger(x, y);
10343 else if (element == EL_GAME_OF_LIFE || element == EL_BIOMAZE)
10345 else if (element == EL_EXIT_CLOSED)
10347 else if (element == EL_SP_EXIT_CLOSED)
10349 else if (element == EL_EXPANDABLE_WALL_GROWING)
10350 MauerWaechst(x, y);
10351 else if (element == EL_EXPANDABLE_WALL ||
10352 element == EL_EXPANDABLE_WALL_HORIZONTAL ||
10353 element == EL_EXPANDABLE_WALL_VERTICAL ||
10354 element == EL_EXPANDABLE_WALL_ANY ||
10355 element == EL_BD_EXPANDABLE_WALL)
10356 MauerAbleger(x, y);
10357 else if (element == EL_FLAMES)
10358 CheckForDragon(x, y);
10359 else if (element == EL_EXPLOSION)
10360 ; /* drawing of correct explosion animation is handled separately */
10361 else if (element == EL_ELEMENT_SNAPPING ||
10362 element == EL_DIAGONAL_SHRINKING ||
10363 element == EL_DIAGONAL_GROWING)
10366 graphic = el_act_dir2img(GfxElement[x][y], GfxAction[x][y],GfxDir[x][y]);
10368 DrawLevelGraphicAnimationIfNeeded(x, y, graphic);
10371 else if (IS_ANIMATED(graphic) && !IS_CHANGING(x, y))
10372 DrawLevelGraphicAnimationIfNeeded(x, y, graphic);
10375 if (element == EL_CUSTOM_255 ||
10376 element == EL_CUSTOM_256)
10377 DrawLevelGraphicAnimation(x, y, graphic);
10380 if (IS_BELT_ACTIVE(element))
10381 PlayLevelSoundAction(x, y, ACTION_ACTIVE);
10383 if (game.magic_wall_active)
10385 int jx = local_player->jx, jy = local_player->jy;
10387 /* play the element sound at the position nearest to the player */
10388 if ((element == EL_MAGIC_WALL_FULL ||
10389 element == EL_MAGIC_WALL_ACTIVE ||
10390 element == EL_MAGIC_WALL_EMPTYING ||
10391 element == EL_BD_MAGIC_WALL_FULL ||
10392 element == EL_BD_MAGIC_WALL_ACTIVE ||
10393 element == EL_BD_MAGIC_WALL_EMPTYING) &&
10394 ABS(x-jx) + ABS(y-jy) < ABS(magic_wall_x-jx) + ABS(magic_wall_y-jy))
10402 #if USE_NEW_AMOEBA_CODE
10403 /* new experimental amoeba growth stuff */
10404 if (!(FrameCounter % 8))
10406 static unsigned long random = 1684108901;
10408 for (i = 0; i < level.amoeba_speed * 28 / 8; i++)
10410 x = RND(lev_fieldx);
10411 y = RND(lev_fieldy);
10412 element = Feld[x][y];
10414 if (!IS_PLAYER(x,y) &&
10415 (element == EL_EMPTY ||
10416 CAN_GROW_INTO(element) ||
10417 element == EL_QUICKSAND_EMPTY ||
10418 element == EL_ACID_SPLASH_LEFT ||
10419 element == EL_ACID_SPLASH_RIGHT))
10421 if ((IN_LEV_FIELD(x, y-1) && Feld[x][y-1] == EL_AMOEBA_WET) ||
10422 (IN_LEV_FIELD(x-1, y) && Feld[x-1][y] == EL_AMOEBA_WET) ||
10423 (IN_LEV_FIELD(x+1, y) && Feld[x+1][y] == EL_AMOEBA_WET) ||
10424 (IN_LEV_FIELD(x, y+1) && Feld[x][y+1] == EL_AMOEBA_WET))
10425 Feld[x][y] = EL_AMOEBA_DROP;
10428 random = random * 129 + 1;
10434 if (game.explosions_delayed)
10437 game.explosions_delayed = FALSE;
10440 SCAN_PLAYFIELD(x, y)
10442 for (y = 0; y < lev_fieldy; y++) for (x = 0; x < lev_fieldx; x++)
10445 element = Feld[x][y];
10447 if (ExplodeField[x][y])
10448 Explode(x, y, EX_PHASE_START, ExplodeField[x][y]);
10449 else if (element == EL_EXPLOSION)
10450 Explode(x, y, ExplodePhase[x][y], EX_TYPE_NORMAL);
10452 ExplodeField[x][y] = EX_TYPE_NONE;
10455 game.explosions_delayed = TRUE;
10458 if (game.magic_wall_active)
10460 if (!(game.magic_wall_time_left % 4))
10462 int element = Feld[magic_wall_x][magic_wall_y];
10464 if (element == EL_BD_MAGIC_WALL_FULL ||
10465 element == EL_BD_MAGIC_WALL_ACTIVE ||
10466 element == EL_BD_MAGIC_WALL_EMPTYING)
10467 PlayLevelSound(magic_wall_x, magic_wall_y, SND_BD_MAGIC_WALL_ACTIVE);
10469 PlayLevelSound(magic_wall_x, magic_wall_y, SND_MAGIC_WALL_ACTIVE);
10472 if (game.magic_wall_time_left > 0)
10474 game.magic_wall_time_left--;
10475 if (!game.magic_wall_time_left)
10478 SCAN_PLAYFIELD(x, y)
10480 for (y = 0; y < lev_fieldy; y++) for (x = 0; x < lev_fieldx; x++)
10483 element = Feld[x][y];
10485 if (element == EL_MAGIC_WALL_ACTIVE ||
10486 element == EL_MAGIC_WALL_FULL)
10488 Feld[x][y] = EL_MAGIC_WALL_DEAD;
10489 DrawLevelField(x, y);
10491 else if (element == EL_BD_MAGIC_WALL_ACTIVE ||
10492 element == EL_BD_MAGIC_WALL_FULL)
10494 Feld[x][y] = EL_BD_MAGIC_WALL_DEAD;
10495 DrawLevelField(x, y);
10499 game.magic_wall_active = FALSE;
10504 if (game.light_time_left > 0)
10506 game.light_time_left--;
10508 if (game.light_time_left == 0)
10509 RedrawAllLightSwitchesAndInvisibleElements();
10512 if (game.timegate_time_left > 0)
10514 game.timegate_time_left--;
10516 if (game.timegate_time_left == 0)
10517 CloseAllOpenTimegates();
10520 if (game.lenses_time_left > 0)
10522 game.lenses_time_left--;
10524 if (game.lenses_time_left == 0)
10525 RedrawAllInvisibleElementsForLenses();
10528 if (game.magnify_time_left > 0)
10530 game.magnify_time_left--;
10532 if (game.magnify_time_left == 0)
10533 RedrawAllInvisibleElementsForMagnifier();
10536 for (i = 0; i < MAX_PLAYERS; i++)
10538 struct PlayerInfo *player = &stored_player[i];
10540 if (SHIELD_ON(player))
10542 if (player->shield_deadly_time_left)
10543 PlayLevelSound(player->jx, player->jy, SND_SHIELD_DEADLY_ACTIVE);
10544 else if (player->shield_normal_time_left)
10545 PlayLevelSound(player->jx, player->jy, SND_SHIELD_NORMAL_ACTIVE);
10552 PlayAllPlayersSound();
10554 if (options.debug) /* calculate frames per second */
10556 static unsigned long fps_counter = 0;
10557 static int fps_frames = 0;
10558 unsigned long fps_delay_ms = Counter() - fps_counter;
10562 if (fps_delay_ms >= 500) /* calculate fps every 0.5 seconds */
10564 global.frames_per_second = 1000 * (float)fps_frames / fps_delay_ms;
10567 fps_counter = Counter();
10570 redraw_mask |= REDRAW_FPS;
10573 AdvanceFrameAndPlayerCounters(-1); /* advance counters for all players */
10575 if (local_player->show_envelope != 0 && local_player->MovPos == 0)
10577 ShowEnvelope(local_player->show_envelope - EL_ENVELOPE_1);
10579 local_player->show_envelope = 0;
10582 /* use random number generator in every frame to make it less predictable */
10583 if (game.engine_version >= VERSION_IDENT(3,1,1,0))
10587 static boolean AllPlayersInSight(struct PlayerInfo *player, int x, int y)
10589 int min_x = x, min_y = y, max_x = x, max_y = y;
10592 for (i = 0; i < MAX_PLAYERS; i++)
10594 int jx = stored_player[i].jx, jy = stored_player[i].jy;
10596 if (!stored_player[i].active || &stored_player[i] == player)
10599 min_x = MIN(min_x, jx);
10600 min_y = MIN(min_y, jy);
10601 max_x = MAX(max_x, jx);
10602 max_y = MAX(max_y, jy);
10605 return (max_x - min_x < SCR_FIELDX && max_y - min_y < SCR_FIELDY);
10608 static boolean AllPlayersInVisibleScreen()
10612 for (i = 0; i < MAX_PLAYERS; i++)
10614 int jx = stored_player[i].jx, jy = stored_player[i].jy;
10616 if (!stored_player[i].active)
10619 if (!IN_VIS_FIELD(SCREENX(jx), SCREENY(jy)))
10626 void ScrollLevel(int dx, int dy)
10628 int softscroll_offset = (setup.soft_scrolling ? TILEX : 0);
10631 BlitBitmap(drawto_field, drawto_field,
10632 FX + TILEX * (dx == -1) - softscroll_offset,
10633 FY + TILEY * (dy == -1) - softscroll_offset,
10634 SXSIZE - TILEX * (dx!=0) + 2 * softscroll_offset,
10635 SYSIZE - TILEY * (dy!=0) + 2 * softscroll_offset,
10636 FX + TILEX * (dx == 1) - softscroll_offset,
10637 FY + TILEY * (dy == 1) - softscroll_offset);
10641 x = (dx == 1 ? BX1 : BX2);
10642 for (y = BY1; y <= BY2; y++)
10643 DrawScreenField(x, y);
10648 y = (dy == 1 ? BY1 : BY2);
10649 for (x = BX1; x <= BX2; x++)
10650 DrawScreenField(x, y);
10653 redraw_mask |= REDRAW_FIELD;
10656 static boolean canFallDown(struct PlayerInfo *player)
10658 int jx = player->jx, jy = player->jy;
10660 return (IN_LEV_FIELD(jx, jy + 1) &&
10661 (IS_FREE(jx, jy + 1) ||
10662 (Feld[jx][jy + 1] == EL_ACID && player->can_fall_into_acid)) &&
10663 IS_WALKABLE_FROM(Feld[jx][jy], MV_DOWN) &&
10664 !IS_WALKABLE_INSIDE(Feld[jx][jy]));
10667 static boolean canPassField(int x, int y, int move_dir)
10669 int opposite_dir = MV_DIR_OPPOSITE(move_dir);
10670 int dx = (move_dir & MV_LEFT ? -1 : move_dir & MV_RIGHT ? +1 : 0);
10671 int dy = (move_dir & MV_UP ? -1 : move_dir & MV_DOWN ? +1 : 0);
10672 int nextx = x + dx;
10673 int nexty = y + dy;
10674 int element = Feld[x][y];
10676 return (IS_PASSABLE_FROM(element, opposite_dir) &&
10677 !CAN_MOVE(element) &&
10678 IN_LEV_FIELD(nextx, nexty) && !IS_PLAYER(nextx, nexty) &&
10679 IS_WALKABLE_FROM(Feld[nextx][nexty], move_dir) &&
10680 (level.can_pass_to_walkable || IS_FREE(nextx, nexty)));
10683 static boolean canMoveToValidFieldWithGravity(int x, int y, int move_dir)
10685 int opposite_dir = MV_DIR_OPPOSITE(move_dir);
10686 int dx = (move_dir & MV_LEFT ? -1 : move_dir & MV_RIGHT ? +1 : 0);
10687 int dy = (move_dir & MV_UP ? -1 : move_dir & MV_DOWN ? +1 : 0);
10691 return (IN_LEV_FIELD(newx, newy) && !IS_FREE_OR_PLAYER(newx, newy) &&
10692 IS_GRAVITY_REACHABLE(Feld[newx][newy]) &&
10693 (IS_DIGGABLE(Feld[newx][newy]) ||
10694 IS_WALKABLE_FROM(Feld[newx][newy], opposite_dir) ||
10695 canPassField(newx, newy, move_dir)));
10698 static void CheckGravityMovement(struct PlayerInfo *player)
10700 #if USE_PLAYER_GRAVITY
10701 if (player->gravity && !player->programmed_action)
10703 if (game.gravity && !player->programmed_action)
10706 int move_dir_horizontal = player->effective_action & MV_HORIZONTAL;
10707 int move_dir_vertical = player->effective_action & MV_VERTICAL;
10708 boolean player_is_snapping = (player->effective_action & JOY_BUTTON_1);
10709 int jx = player->jx, jy = player->jy;
10710 boolean player_is_moving_to_valid_field =
10711 (!player_is_snapping &&
10712 (canMoveToValidFieldWithGravity(jx, jy, move_dir_horizontal) ||
10713 canMoveToValidFieldWithGravity(jx, jy, move_dir_vertical)));
10714 boolean player_can_fall_down = canFallDown(player);
10716 if (player_can_fall_down &&
10717 !player_is_moving_to_valid_field)
10718 player->programmed_action = MV_DOWN;
10722 static void CheckGravityMovementWhenNotMoving(struct PlayerInfo *player)
10724 return CheckGravityMovement(player);
10726 #if USE_PLAYER_GRAVITY
10727 if (player->gravity && !player->programmed_action)
10729 if (game.gravity && !player->programmed_action)
10732 int jx = player->jx, jy = player->jy;
10733 boolean field_under_player_is_free =
10734 (IN_LEV_FIELD(jx, jy + 1) && IS_FREE(jx, jy + 1));
10735 boolean player_is_standing_on_valid_field =
10736 (IS_WALKABLE_INSIDE(Feld[jx][jy]) ||
10737 (IS_WALKABLE(Feld[jx][jy]) &&
10738 !(element_info[Feld[jx][jy]].access_direction & MV_DOWN)));
10740 if (field_under_player_is_free && !player_is_standing_on_valid_field)
10741 player->programmed_action = MV_DOWN;
10746 MovePlayerOneStep()
10747 -----------------------------------------------------------------------------
10748 dx, dy: direction (non-diagonal) to try to move the player to
10749 real_dx, real_dy: direction as read from input device (can be diagonal)
10752 boolean MovePlayerOneStep(struct PlayerInfo *player,
10753 int dx, int dy, int real_dx, int real_dy)
10755 int jx = player->jx, jy = player->jy;
10756 int new_jx = jx + dx, new_jy = jy + dy;
10757 #if !USE_FIXED_DONT_RUN_INTO
10761 boolean player_can_move = !player->cannot_move;
10763 if (!player->active || (!dx && !dy))
10764 return MP_NO_ACTION;
10766 player->MovDir = (dx < 0 ? MV_LEFT :
10767 dx > 0 ? MV_RIGHT :
10769 dy > 0 ? MV_DOWN : MV_NONE);
10771 if (!IN_LEV_FIELD(new_jx, new_jy))
10772 return MP_NO_ACTION;
10774 if (!player_can_move)
10777 if (player->MovPos == 0)
10779 player->is_moving = FALSE;
10780 player->is_digging = FALSE;
10781 player->is_collecting = FALSE;
10782 player->is_snapping = FALSE;
10783 player->is_pushing = FALSE;
10786 DigField(player, 0, 0, 0, 0, 0, 0, DF_NO_PUSH);
10787 SnapField(player, 0, 0);
10791 return MP_NO_ACTION;
10796 if (!options.network && game.centered_player_nr == -1 &&
10797 !AllPlayersInSight(player, new_jx, new_jy))
10798 return MP_NO_ACTION;
10800 if (!options.network && !AllPlayersInSight(player, new_jx, new_jy))
10801 return MP_NO_ACTION;
10804 #if !USE_FIXED_DONT_RUN_INTO
10805 element = MovingOrBlocked2ElementIfNotLeaving(new_jx, new_jy);
10807 /* (moved to DigField()) */
10808 if (player_can_move && DONT_RUN_INTO(element))
10810 if (element == EL_ACID && dx == 0 && dy == 1)
10812 SplashAcid(new_jx, new_jy);
10813 Feld[jx][jy] = EL_PLAYER_1;
10814 InitMovingField(jx, jy, MV_DOWN);
10815 Store[jx][jy] = EL_ACID;
10816 ContinueMoving(jx, jy);
10817 BuryPlayer(player);
10820 TestIfPlayerRunsIntoBadThing(jx, jy, player->MovDir);
10826 can_move = DigField(player, jx, jy, new_jx, new_jy, real_dx,real_dy, DF_DIG);
10828 #if USE_FIXED_DONT_RUN_INTO
10829 if (can_move == MP_DONT_RUN_INTO)
10833 if (can_move != MP_MOVING)
10836 #if USE_FIXED_DONT_RUN_INTO
10839 /* check if DigField() has caused relocation of the player */
10840 if (player->jx != jx || player->jy != jy)
10841 return MP_NO_ACTION; /* <-- !!! CHECK THIS [-> MP_ACTION ?] !!! */
10843 StorePlayer[jx][jy] = 0;
10844 player->last_jx = jx;
10845 player->last_jy = jy;
10846 player->jx = new_jx;
10847 player->jy = new_jy;
10848 StorePlayer[new_jx][new_jy] = player->element_nr;
10850 if (player->move_delay_value_next != -1)
10852 player->move_delay_value = player->move_delay_value_next;
10853 player->move_delay_value_next = -1;
10857 (dx > 0 || dy > 0 ? -1 : 1) * (TILEX - TILEX / player->move_delay_value);
10859 player->step_counter++;
10861 PlayerVisit[jx][jy] = FrameCounter;
10863 #if USE_UFAST_PLAYER_EXIT_BUGFIX
10864 player->is_moving = TRUE;
10868 /* should better be called in MovePlayer(), but this breaks some tapes */
10869 ScrollPlayer(player, SCROLL_INIT);
10875 boolean MovePlayer(struct PlayerInfo *player, int dx, int dy)
10877 int jx = player->jx, jy = player->jy;
10878 int old_jx = jx, old_jy = jy;
10879 int moved = MP_NO_ACTION;
10881 if (!player->active)
10886 if (player->MovPos == 0)
10888 player->is_moving = FALSE;
10889 player->is_digging = FALSE;
10890 player->is_collecting = FALSE;
10891 player->is_snapping = FALSE;
10892 player->is_pushing = FALSE;
10898 if (player->move_delay > 0)
10901 player->move_delay = -1; /* set to "uninitialized" value */
10903 /* store if player is automatically moved to next field */
10904 player->is_auto_moving = (player->programmed_action != MV_NONE);
10906 /* remove the last programmed player action */
10907 player->programmed_action = 0;
10909 if (player->MovPos)
10911 /* should only happen if pre-1.2 tape recordings are played */
10912 /* this is only for backward compatibility */
10914 int original_move_delay_value = player->move_delay_value;
10917 printf("THIS SHOULD ONLY HAPPEN WITH PRE-1.2 LEVEL TAPES. [%ld]\n",
10921 /* scroll remaining steps with finest movement resolution */
10922 player->move_delay_value = MOVE_DELAY_NORMAL_SPEED;
10924 while (player->MovPos)
10926 ScrollPlayer(player, SCROLL_GO_ON);
10927 ScrollScreen(NULL, SCROLL_GO_ON);
10929 AdvanceFrameAndPlayerCounters(player->index_nr);
10935 player->move_delay_value = original_move_delay_value;
10938 player->is_active = FALSE;
10940 if (player->last_move_dir & MV_HORIZONTAL)
10942 if (!(moved |= MovePlayerOneStep(player, 0, dy, dx, dy)))
10943 moved |= MovePlayerOneStep(player, dx, 0, dx, dy);
10947 if (!(moved |= MovePlayerOneStep(player, dx, 0, dx, dy)))
10948 moved |= MovePlayerOneStep(player, 0, dy, dx, dy);
10951 #if USE_FIXED_BORDER_RUNNING_GFX
10952 if (!moved && !player->is_active)
10954 player->is_moving = FALSE;
10955 player->is_digging = FALSE;
10956 player->is_collecting = FALSE;
10957 player->is_snapping = FALSE;
10958 player->is_pushing = FALSE;
10966 if (moved & MP_MOVING && !ScreenMovPos &&
10967 (player->index_nr == game.centered_player_nr ||
10968 game.centered_player_nr == -1))
10970 if (moved & MP_MOVING && !ScreenMovPos &&
10971 (player == local_player || !options.network))
10974 int old_scroll_x = scroll_x, old_scroll_y = scroll_y;
10975 int offset = (setup.scroll_delay ? 3 : 0);
10977 if (!IN_VIS_FIELD(SCREENX(jx), SCREENY(jy)))
10979 /* actual player has left the screen -- scroll in that direction */
10980 if (jx != old_jx) /* player has moved horizontally */
10981 scroll_x += (jx - old_jx);
10982 else /* player has moved vertically */
10983 scroll_y += (jy - old_jy);
10987 if (jx != old_jx) /* player has moved horizontally */
10989 if ((player->MovDir == MV_LEFT && scroll_x > jx - MIDPOSX + offset) ||
10990 (player->MovDir == MV_RIGHT && scroll_x < jx - MIDPOSX - offset))
10991 scroll_x = jx-MIDPOSX + (scroll_x < jx-MIDPOSX ? -offset : +offset);
10993 /* don't scroll over playfield boundaries */
10994 if (scroll_x < SBX_Left || scroll_x > SBX_Right)
10995 scroll_x = (scroll_x < SBX_Left ? SBX_Left : SBX_Right);
10997 /* don't scroll more than one field at a time */
10998 scroll_x = old_scroll_x + SIGN(scroll_x - old_scroll_x);
11000 /* don't scroll against the player's moving direction */
11001 if ((player->MovDir == MV_LEFT && scroll_x > old_scroll_x) ||
11002 (player->MovDir == MV_RIGHT && scroll_x < old_scroll_x))
11003 scroll_x = old_scroll_x;
11005 else /* player has moved vertically */
11007 if ((player->MovDir == MV_UP && scroll_y > jy - MIDPOSY + offset) ||
11008 (player->MovDir == MV_DOWN && scroll_y < jy - MIDPOSY - offset))
11009 scroll_y = jy-MIDPOSY + (scroll_y < jy-MIDPOSY ? -offset : +offset);
11011 /* don't scroll over playfield boundaries */
11012 if (scroll_y < SBY_Upper || scroll_y > SBY_Lower)
11013 scroll_y = (scroll_y < SBY_Upper ? SBY_Upper : SBY_Lower);
11015 /* don't scroll more than one field at a time */
11016 scroll_y = old_scroll_y + SIGN(scroll_y - old_scroll_y);
11018 /* don't scroll against the player's moving direction */
11019 if ((player->MovDir == MV_UP && scroll_y > old_scroll_y) ||
11020 (player->MovDir == MV_DOWN && scroll_y < old_scroll_y))
11021 scroll_y = old_scroll_y;
11025 if (scroll_x != old_scroll_x || scroll_y != old_scroll_y)
11028 if (!options.network && game.centered_player_nr == -1 &&
11029 !AllPlayersInVisibleScreen())
11031 scroll_x = old_scroll_x;
11032 scroll_y = old_scroll_y;
11036 if (!options.network && !AllPlayersInVisibleScreen())
11038 scroll_x = old_scroll_x;
11039 scroll_y = old_scroll_y;
11044 ScrollScreen(player, SCROLL_INIT);
11045 ScrollLevel(old_scroll_x - scroll_x, old_scroll_y - scroll_y);
11050 player->StepFrame = 0;
11052 if (moved & MP_MOVING)
11054 if (old_jx != jx && old_jy == jy)
11055 player->MovDir = (old_jx < jx ? MV_RIGHT : MV_LEFT);
11056 else if (old_jx == jx && old_jy != jy)
11057 player->MovDir = (old_jy < jy ? MV_DOWN : MV_UP);
11059 DrawLevelField(jx, jy); /* for "crumbled sand" */
11061 player->last_move_dir = player->MovDir;
11062 player->is_moving = TRUE;
11063 player->is_snapping = FALSE;
11064 player->is_switching = FALSE;
11065 player->is_dropping = FALSE;
11066 player->is_dropping_pressed = FALSE;
11067 player->drop_pressed_delay = 0;
11070 /* should better be called here than above, but this breaks some tapes */
11071 ScrollPlayer(player, SCROLL_INIT);
11076 CheckGravityMovementWhenNotMoving(player);
11078 player->is_moving = FALSE;
11080 /* at this point, the player is allowed to move, but cannot move right now
11081 (e.g. because of something blocking the way) -- ensure that the player
11082 is also allowed to move in the next frame (in old versions before 3.1.1,
11083 the player was forced to wait again for eight frames before next try) */
11085 if (game.engine_version >= VERSION_IDENT(3,1,1,0))
11086 player->move_delay = 0; /* allow direct movement in the next frame */
11089 if (player->move_delay == -1) /* not yet initialized by DigField() */
11090 player->move_delay = player->move_delay_value;
11092 if (game.engine_version < VERSION_IDENT(3,0,7,0))
11094 TestIfPlayerTouchesBadThing(jx, jy);
11095 TestIfPlayerTouchesCustomElement(jx, jy);
11098 if (!player->active)
11099 RemovePlayer(player);
11104 void ScrollPlayer(struct PlayerInfo *player, int mode)
11106 int jx = player->jx, jy = player->jy;
11107 int last_jx = player->last_jx, last_jy = player->last_jy;
11108 int move_stepsize = TILEX / player->move_delay_value;
11110 #if USE_NEW_PLAYER_SPEED
11111 if (!player->active)
11114 if (player->MovPos == 0 && mode == SCROLL_GO_ON) /* player not moving */
11117 if (!player->active || player->MovPos == 0)
11121 if (mode == SCROLL_INIT)
11123 player->actual_frame_counter = FrameCounter;
11124 player->GfxPos = move_stepsize * (player->MovPos / move_stepsize);
11126 if ((player->block_last_field || player->block_delay_adjustment > 0) &&
11127 Feld[last_jx][last_jy] == EL_EMPTY)
11129 int last_field_block_delay = 0; /* start with no blocking at all */
11130 int block_delay_adjustment = player->block_delay_adjustment;
11132 /* if player blocks last field, add delay for exactly one move */
11133 if (player->block_last_field)
11135 last_field_block_delay += player->move_delay_value;
11137 /* when blocking enabled, prevent moving up despite gravity */
11138 #if USE_PLAYER_GRAVITY
11139 if (player->gravity && player->MovDir == MV_UP)
11140 block_delay_adjustment = -1;
11142 if (game.gravity && player->MovDir == MV_UP)
11143 block_delay_adjustment = -1;
11147 /* add block delay adjustment (also possible when not blocking) */
11148 last_field_block_delay += block_delay_adjustment;
11150 Feld[last_jx][last_jy] = EL_PLAYER_IS_LEAVING;
11151 MovDelay[last_jx][last_jy] = last_field_block_delay + 1;
11154 #if USE_NEW_PLAYER_SPEED
11155 if (player->MovPos != 0) /* player has not yet reached destination */
11161 else if (!FrameReached(&player->actual_frame_counter, 1))
11165 printf("::: player->MovPos: %d -> %d\n",
11167 player->MovPos + (player->MovPos > 0 ? -1 : 1) * move_stepsize);
11170 #if USE_NEW_PLAYER_SPEED
11171 if (player->MovPos != 0)
11173 player->MovPos += (player->MovPos > 0 ? -1 : 1) * move_stepsize;
11174 player->GfxPos = move_stepsize * (player->MovPos / move_stepsize);
11176 /* before DrawPlayer() to draw correct player graphic for this case */
11177 if (player->MovPos == 0)
11178 CheckGravityMovement(player);
11181 player->MovPos += (player->MovPos > 0 ? -1 : 1) * move_stepsize;
11182 player->GfxPos = move_stepsize * (player->MovPos / move_stepsize);
11184 /* before DrawPlayer() to draw correct player graphic for this case */
11185 if (player->MovPos == 0)
11186 CheckGravityMovement(player);
11189 if (player->MovPos == 0) /* player reached destination field */
11192 printf("::: player reached destination field\n");
11195 if (player->move_delay_reset_counter > 0)
11197 player->move_delay_reset_counter--;
11199 if (player->move_delay_reset_counter == 0)
11201 /* continue with normal speed after quickly moving through gate */
11202 HALVE_PLAYER_SPEED(player);
11204 /* be able to make the next move without delay */
11205 player->move_delay = 0;
11209 player->last_jx = jx;
11210 player->last_jy = jy;
11212 if (Feld[jx][jy] == EL_EXIT_OPEN ||
11213 Feld[jx][jy] == EL_SP_EXIT_OPEN ||
11214 Feld[jx][jy] == EL_SP_EXIT_OPENING) /* <-- special case */
11216 DrawPlayer(player); /* needed here only to cleanup last field */
11217 RemovePlayer(player);
11219 if (local_player->friends_still_needed == 0 ||
11220 IS_SP_ELEMENT(Feld[jx][jy]))
11221 player->LevelSolved = player->GameOver = TRUE;
11224 /* this breaks one level: "machine", level 000 */
11226 int move_direction = player->MovDir;
11227 int enter_side = MV_DIR_OPPOSITE(move_direction);
11228 int leave_side = move_direction;
11229 int old_jx = last_jx;
11230 int old_jy = last_jy;
11231 int old_element = Feld[old_jx][old_jy];
11232 int new_element = Feld[jx][jy];
11234 if (IS_CUSTOM_ELEMENT(old_element))
11235 CheckElementChangeByPlayer(old_jx, old_jy, old_element,
11237 player->index_bit, leave_side);
11239 CheckTriggeredElementChangeByPlayer(old_jx, old_jy, old_element,
11240 CE_PLAYER_LEAVES_X,
11241 player->index_bit, leave_side);
11243 if (IS_CUSTOM_ELEMENT(new_element))
11244 CheckElementChangeByPlayer(jx, jy, new_element, CE_ENTERED_BY_PLAYER,
11245 player->index_bit, enter_side);
11247 CheckTriggeredElementChangeByPlayer(jx, jy, new_element,
11248 CE_PLAYER_ENTERS_X,
11249 player->index_bit, enter_side);
11251 CheckTriggeredElementChangeBySide(jx, jy, player->element_nr,
11252 CE_MOVE_OF_X, move_direction);
11255 if (game.engine_version >= VERSION_IDENT(3,0,7,0))
11257 TestIfPlayerTouchesBadThing(jx, jy);
11258 TestIfPlayerTouchesCustomElement(jx, jy);
11260 /* needed because pushed element has not yet reached its destination,
11261 so it would trigger a change event at its previous field location */
11262 if (!player->is_pushing)
11263 TestIfElementTouchesCustomElement(jx, jy); /* for empty space */
11265 if (!player->active)
11266 RemovePlayer(player);
11269 if (level.use_step_counter)
11279 if (TimeLeft <= 10 && setup.time_limit)
11280 PlaySoundStereo(SND_GAME_RUNNING_OUT_OF_TIME, SOUND_MIDDLE);
11282 DrawGameValue_Time(TimeLeft);
11284 if (!TimeLeft && setup.time_limit)
11285 for (i = 0; i < MAX_PLAYERS; i++)
11286 KillPlayer(&stored_player[i]);
11288 else if (level.time == 0 && !AllPlayersGone) /* level w/o time limit */
11289 DrawGameValue_Time(TimePlayed);
11292 if (tape.single_step && tape.recording && !tape.pausing &&
11293 !player->programmed_action)
11294 TapeTogglePause(TAPE_TOGGLE_AUTOMATIC);
11298 void ScrollScreen(struct PlayerInfo *player, int mode)
11300 static unsigned long screen_frame_counter = 0;
11302 if (mode == SCROLL_INIT)
11304 /* set scrolling step size according to actual player's moving speed */
11305 ScrollStepSize = TILEX / player->move_delay_value;
11307 screen_frame_counter = FrameCounter;
11308 ScreenMovDir = player->MovDir;
11309 ScreenMovPos = player->MovPos;
11310 ScreenGfxPos = ScrollStepSize * (ScreenMovPos / ScrollStepSize);
11313 else if (!FrameReached(&screen_frame_counter, 1))
11318 ScreenMovPos += (ScreenMovPos > 0 ? -1 : 1) * ScrollStepSize;
11319 ScreenGfxPos = ScrollStepSize * (ScreenMovPos / ScrollStepSize);
11320 redraw_mask |= REDRAW_FIELD;
11323 ScreenMovDir = MV_NONE;
11326 void TestIfPlayerTouchesCustomElement(int x, int y)
11328 static int xy[4][2] =
11335 static int trigger_sides[4][2] =
11337 /* center side border side */
11338 { CH_SIDE_TOP, CH_SIDE_BOTTOM }, /* check top */
11339 { CH_SIDE_LEFT, CH_SIDE_RIGHT }, /* check left */
11340 { CH_SIDE_RIGHT, CH_SIDE_LEFT }, /* check right */
11341 { CH_SIDE_BOTTOM, CH_SIDE_TOP } /* check bottom */
11343 static int touch_dir[4] =
11345 MV_LEFT | MV_RIGHT,
11350 int center_element = Feld[x][y]; /* should always be non-moving! */
11353 for (i = 0; i < NUM_DIRECTIONS; i++)
11355 int xx = x + xy[i][0];
11356 int yy = y + xy[i][1];
11357 int center_side = trigger_sides[i][0];
11358 int border_side = trigger_sides[i][1];
11359 int border_element;
11361 if (!IN_LEV_FIELD(xx, yy))
11364 if (IS_PLAYER(x, y))
11366 struct PlayerInfo *player = PLAYERINFO(x, y);
11368 if (game.engine_version < VERSION_IDENT(3,0,7,0))
11369 border_element = Feld[xx][yy]; /* may be moving! */
11370 else if (!IS_MOVING(xx, yy) && !IS_BLOCKED(xx, yy))
11371 border_element = Feld[xx][yy];
11372 else if (MovDir[xx][yy] & touch_dir[i]) /* elements are touching */
11373 border_element = MovingOrBlocked2Element(xx, yy);
11375 continue; /* center and border element do not touch */
11377 CheckElementChangeByPlayer(xx, yy, border_element, CE_TOUCHED_BY_PLAYER,
11378 player->index_bit, border_side);
11379 CheckTriggeredElementChangeByPlayer(xx, yy, border_element,
11380 CE_PLAYER_TOUCHES_X,
11381 player->index_bit, border_side);
11383 else if (IS_PLAYER(xx, yy))
11385 struct PlayerInfo *player = PLAYERINFO(xx, yy);
11387 if (game.engine_version >= VERSION_IDENT(3,0,7,0))
11389 if (player->MovPos != 0 && !(player->MovDir & touch_dir[i]))
11390 continue; /* center and border element do not touch */
11393 CheckElementChangeByPlayer(x, y, center_element, CE_TOUCHED_BY_PLAYER,
11394 player->index_bit, center_side);
11395 CheckTriggeredElementChangeByPlayer(x, y, center_element,
11396 CE_PLAYER_TOUCHES_X,
11397 player->index_bit, center_side);
11403 #if USE_ELEMENT_TOUCHING_BUGFIX
11405 void TestIfElementTouchesCustomElement(int x, int y)
11407 static int xy[4][2] =
11414 static int trigger_sides[4][2] =
11416 /* center side border side */
11417 { CH_SIDE_TOP, CH_SIDE_BOTTOM }, /* check top */
11418 { CH_SIDE_LEFT, CH_SIDE_RIGHT }, /* check left */
11419 { CH_SIDE_RIGHT, CH_SIDE_LEFT }, /* check right */
11420 { CH_SIDE_BOTTOM, CH_SIDE_TOP } /* check bottom */
11422 static int touch_dir[4] =
11424 MV_LEFT | MV_RIGHT,
11429 boolean change_center_element = FALSE;
11430 int center_element = Feld[x][y]; /* should always be non-moving! */
11431 int border_element_old[NUM_DIRECTIONS];
11434 for (i = 0; i < NUM_DIRECTIONS; i++)
11436 int xx = x + xy[i][0];
11437 int yy = y + xy[i][1];
11438 int border_element;
11440 border_element_old[i] = -1;
11442 if (!IN_LEV_FIELD(xx, yy))
11445 if (game.engine_version < VERSION_IDENT(3,0,7,0))
11446 border_element = Feld[xx][yy]; /* may be moving! */
11447 else if (!IS_MOVING(xx, yy) && !IS_BLOCKED(xx, yy))
11448 border_element = Feld[xx][yy];
11449 else if (MovDir[xx][yy] & touch_dir[i]) /* elements are touching */
11450 border_element = MovingOrBlocked2Element(xx, yy);
11452 continue; /* center and border element do not touch */
11454 border_element_old[i] = border_element;
11457 for (i = 0; i < NUM_DIRECTIONS; i++)
11459 int xx = x + xy[i][0];
11460 int yy = y + xy[i][1];
11461 int center_side = trigger_sides[i][0];
11462 int border_element = border_element_old[i];
11464 if (border_element == -1)
11467 /* check for change of border element */
11468 CheckElementChangeBySide(xx, yy, border_element, center_element,
11469 CE_TOUCHING_X, center_side);
11472 for (i = 0; i < NUM_DIRECTIONS; i++)
11474 int border_side = trigger_sides[i][1];
11475 int border_element = border_element_old[i];
11477 if (border_element == -1)
11480 /* check for change of center element (but change it only once) */
11481 if (!change_center_element)
11482 change_center_element =
11483 CheckElementChangeBySide(x, y, center_element, border_element,
11484 CE_TOUCHING_X, border_side);
11490 void TestIfElementTouchesCustomElement_OLD(int x, int y)
11492 static int xy[4][2] =
11499 static int trigger_sides[4][2] =
11501 /* center side border side */
11502 { CH_SIDE_TOP, CH_SIDE_BOTTOM }, /* check top */
11503 { CH_SIDE_LEFT, CH_SIDE_RIGHT }, /* check left */
11504 { CH_SIDE_RIGHT, CH_SIDE_LEFT }, /* check right */
11505 { CH_SIDE_BOTTOM, CH_SIDE_TOP } /* check bottom */
11507 static int touch_dir[4] =
11509 MV_LEFT | MV_RIGHT,
11514 boolean change_center_element = FALSE;
11515 int center_element = Feld[x][y]; /* should always be non-moving! */
11518 for (i = 0; i < NUM_DIRECTIONS; i++)
11520 int xx = x + xy[i][0];
11521 int yy = y + xy[i][1];
11522 int center_side = trigger_sides[i][0];
11523 int border_side = trigger_sides[i][1];
11524 int border_element;
11526 if (!IN_LEV_FIELD(xx, yy))
11529 if (game.engine_version < VERSION_IDENT(3,0,7,0))
11530 border_element = Feld[xx][yy]; /* may be moving! */
11531 else if (!IS_MOVING(xx, yy) && !IS_BLOCKED(xx, yy))
11532 border_element = Feld[xx][yy];
11533 else if (MovDir[xx][yy] & touch_dir[i]) /* elements are touching */
11534 border_element = MovingOrBlocked2Element(xx, yy);
11536 continue; /* center and border element do not touch */
11538 /* check for change of center element (but change it only once) */
11539 if (!change_center_element)
11540 change_center_element =
11541 CheckElementChangeBySide(x, y, center_element, border_element,
11542 CE_TOUCHING_X, border_side);
11544 /* check for change of border element */
11545 CheckElementChangeBySide(xx, yy, border_element, center_element,
11546 CE_TOUCHING_X, center_side);
11552 void TestIfElementHitsCustomElement(int x, int y, int direction)
11554 int dx = (direction == MV_LEFT ? -1 : direction == MV_RIGHT ? +1 : 0);
11555 int dy = (direction == MV_UP ? -1 : direction == MV_DOWN ? +1 : 0);
11556 int hitx = x + dx, hity = y + dy;
11557 int hitting_element = Feld[x][y];
11558 int touched_element;
11560 if (IN_LEV_FIELD(hitx, hity) && IS_FREE(hitx, hity))
11563 touched_element = (IN_LEV_FIELD(hitx, hity) ?
11564 MovingOrBlocked2Element(hitx, hity) : EL_STEELWALL);
11566 if (IN_LEV_FIELD(hitx, hity))
11568 int opposite_direction = MV_DIR_OPPOSITE(direction);
11569 int hitting_side = direction;
11570 int touched_side = opposite_direction;
11571 boolean object_hit = (!IS_MOVING(hitx, hity) ||
11572 MovDir[hitx][hity] != direction ||
11573 ABS(MovPos[hitx][hity]) <= TILEY / 2);
11579 CheckElementChangeBySide(x, y, hitting_element, touched_element,
11580 CE_HITTING_X, touched_side);
11582 CheckElementChangeBySide(hitx, hity, touched_element,
11583 hitting_element, CE_HIT_BY_X, hitting_side);
11585 CheckElementChangeBySide(hitx, hity, touched_element, hitting_element,
11586 CE_HIT_BY_SOMETHING, opposite_direction);
11590 /* "hitting something" is also true when hitting the playfield border */
11591 CheckElementChangeBySide(x, y, hitting_element, touched_element,
11592 CE_HITTING_SOMETHING, direction);
11596 void TestIfElementSmashesCustomElement(int x, int y, int direction)
11598 int dx = (direction == MV_LEFT ? -1 : direction == MV_RIGHT ? +1 : 0);
11599 int dy = (direction == MV_UP ? -1 : direction == MV_DOWN ? +1 : 0);
11600 int hitx = x + dx, hity = y + dy;
11601 int hitting_element = Feld[x][y];
11602 int touched_element;
11604 boolean object_hit = (IN_LEV_FIELD(hitx, hity) &&
11605 !IS_FREE(hitx, hity) &&
11606 (!IS_MOVING(hitx, hity) ||
11607 MovDir[hitx][hity] != direction ||
11608 ABS(MovPos[hitx][hity]) <= TILEY / 2));
11611 if (IN_LEV_FIELD(hitx, hity) && IS_FREE(hitx, hity))
11615 if (IN_LEV_FIELD(hitx, hity) && !object_hit)
11619 touched_element = (IN_LEV_FIELD(hitx, hity) ?
11620 MovingOrBlocked2Element(hitx, hity) : EL_STEELWALL);
11622 CheckElementChangeBySide(x, y, hitting_element, touched_element,
11623 EP_CAN_SMASH_EVERYTHING, direction);
11625 if (IN_LEV_FIELD(hitx, hity))
11627 int opposite_direction = MV_DIR_OPPOSITE(direction);
11628 int hitting_side = direction;
11629 int touched_side = opposite_direction;
11631 int touched_element = MovingOrBlocked2Element(hitx, hity);
11634 boolean object_hit = (!IS_MOVING(hitx, hity) ||
11635 MovDir[hitx][hity] != direction ||
11636 ABS(MovPos[hitx][hity]) <= TILEY / 2);
11645 CheckElementChangeBySide(hitx, hity, touched_element, hitting_element,
11646 CE_SMASHED_BY_SOMETHING, opposite_direction);
11648 CheckElementChangeBySide(x, y, hitting_element, touched_element,
11649 CE_OTHER_IS_SMASHING, touched_side);
11651 CheckElementChangeBySide(hitx, hity, touched_element, hitting_element,
11652 CE_OTHER_GETS_SMASHED, hitting_side);
11658 void TestIfGoodThingHitsBadThing(int good_x, int good_y, int good_move_dir)
11660 int i, kill_x = -1, kill_y = -1;
11662 int bad_element = -1;
11663 static int test_xy[4][2] =
11670 static int test_dir[4] =
11678 for (i = 0; i < NUM_DIRECTIONS; i++)
11680 int test_x, test_y, test_move_dir, test_element;
11682 test_x = good_x + test_xy[i][0];
11683 test_y = good_y + test_xy[i][1];
11685 if (!IN_LEV_FIELD(test_x, test_y))
11689 (IS_MOVING(test_x, test_y) ? MovDir[test_x][test_y] : MV_NONE);
11691 test_element = MovingOrBlocked2ElementIfNotLeaving(test_x, test_y);
11693 /* 1st case: good thing is moving towards DONT_RUN_INTO style bad thing;
11694 2nd case: DONT_TOUCH style bad thing does not move away from good thing
11696 if ((DONT_RUN_INTO(test_element) && good_move_dir == test_dir[i]) ||
11697 (DONT_TOUCH(test_element) && test_move_dir != test_dir[i]))
11701 bad_element = test_element;
11707 if (kill_x != -1 || kill_y != -1)
11709 if (IS_PLAYER(good_x, good_y))
11711 struct PlayerInfo *player = PLAYERINFO(good_x, good_y);
11713 if (player->shield_deadly_time_left > 0 &&
11714 !IS_INDESTRUCTIBLE(bad_element))
11715 Bang(kill_x, kill_y);
11716 else if (!PLAYER_ENEMY_PROTECTED(good_x, good_y))
11717 KillPlayer(player);
11720 Bang(good_x, good_y);
11724 void TestIfBadThingHitsGoodThing(int bad_x, int bad_y, int bad_move_dir)
11726 int i, kill_x = -1, kill_y = -1;
11727 int bad_element = Feld[bad_x][bad_y];
11728 static int test_xy[4][2] =
11735 static int touch_dir[4] =
11737 MV_LEFT | MV_RIGHT,
11742 static int test_dir[4] =
11750 if (bad_element == EL_EXPLOSION) /* skip just exploding bad things */
11753 for (i = 0; i < NUM_DIRECTIONS; i++)
11755 int test_x, test_y, test_move_dir, test_element;
11757 test_x = bad_x + test_xy[i][0];
11758 test_y = bad_y + test_xy[i][1];
11759 if (!IN_LEV_FIELD(test_x, test_y))
11763 (IS_MOVING(test_x, test_y) ? MovDir[test_x][test_y] : MV_NONE);
11765 test_element = Feld[test_x][test_y];
11767 /* 1st case: good thing is moving towards DONT_RUN_INTO style bad thing;
11768 2nd case: DONT_TOUCH style bad thing does not move away from good thing
11770 if ((DONT_RUN_INTO(bad_element) && bad_move_dir == test_dir[i]) ||
11771 (DONT_TOUCH(bad_element) && test_move_dir != test_dir[i]))
11773 /* good thing is player or penguin that does not move away */
11774 if (IS_PLAYER(test_x, test_y))
11776 struct PlayerInfo *player = PLAYERINFO(test_x, test_y);
11778 if (bad_element == EL_ROBOT && player->is_moving)
11779 continue; /* robot does not kill player if he is moving */
11781 if (game.engine_version >= VERSION_IDENT(3,0,7,0))
11783 if (player->MovPos != 0 && !(player->MovDir & touch_dir[i]))
11784 continue; /* center and border element do not touch */
11791 else if (test_element == EL_PENGUIN)
11800 if (kill_x != -1 || kill_y != -1)
11802 if (IS_PLAYER(kill_x, kill_y))
11804 struct PlayerInfo *player = PLAYERINFO(kill_x, kill_y);
11806 if (player->shield_deadly_time_left > 0 &&
11807 !IS_INDESTRUCTIBLE(bad_element))
11808 Bang(bad_x, bad_y);
11809 else if (!PLAYER_ENEMY_PROTECTED(kill_x, kill_y))
11810 KillPlayer(player);
11813 Bang(kill_x, kill_y);
11817 void TestIfPlayerTouchesBadThing(int x, int y)
11819 TestIfGoodThingHitsBadThing(x, y, MV_NONE);
11822 void TestIfPlayerRunsIntoBadThing(int x, int y, int move_dir)
11824 TestIfGoodThingHitsBadThing(x, y, move_dir);
11827 void TestIfBadThingTouchesPlayer(int x, int y)
11829 TestIfBadThingHitsGoodThing(x, y, MV_NONE);
11832 void TestIfBadThingRunsIntoPlayer(int x, int y, int move_dir)
11834 TestIfBadThingHitsGoodThing(x, y, move_dir);
11837 void TestIfFriendTouchesBadThing(int x, int y)
11839 TestIfGoodThingHitsBadThing(x, y, MV_NONE);
11842 void TestIfBadThingTouchesFriend(int x, int y)
11844 TestIfBadThingHitsGoodThing(x, y, MV_NONE);
11847 void TestIfBadThingTouchesOtherBadThing(int bad_x, int bad_y)
11849 int i, kill_x = bad_x, kill_y = bad_y;
11850 static int xy[4][2] =
11858 for (i = 0; i < NUM_DIRECTIONS; i++)
11862 x = bad_x + xy[i][0];
11863 y = bad_y + xy[i][1];
11864 if (!IN_LEV_FIELD(x, y))
11867 element = Feld[x][y];
11868 if (IS_AMOEBOID(element) || element == EL_GAME_OF_LIFE ||
11869 element == EL_AMOEBA_GROWING || element == EL_AMOEBA_DROP)
11877 if (kill_x != bad_x || kill_y != bad_y)
11878 Bang(bad_x, bad_y);
11881 void KillPlayer(struct PlayerInfo *player)
11883 int jx = player->jx, jy = player->jy;
11885 if (!player->active)
11888 /* remove accessible field at the player's position */
11889 Feld[jx][jy] = EL_EMPTY;
11891 /* deactivate shield (else Bang()/Explode() would not work right) */
11892 player->shield_normal_time_left = 0;
11893 player->shield_deadly_time_left = 0;
11896 BuryPlayer(player);
11899 static void KillPlayerUnlessEnemyProtected(int x, int y)
11901 if (!PLAYER_ENEMY_PROTECTED(x, y))
11902 KillPlayer(PLAYERINFO(x, y));
11905 static void KillPlayerUnlessExplosionProtected(int x, int y)
11907 if (!PLAYER_EXPLOSION_PROTECTED(x, y))
11908 KillPlayer(PLAYERINFO(x, y));
11911 void BuryPlayer(struct PlayerInfo *player)
11913 int jx = player->jx, jy = player->jy;
11915 if (!player->active)
11918 PlayLevelSoundElementAction(jx, jy, player->artwork_element, ACTION_DYING);
11919 PlayLevelSound(jx, jy, SND_GAME_LOSING);
11921 player->GameOver = TRUE;
11922 RemovePlayer(player);
11925 void RemovePlayer(struct PlayerInfo *player)
11927 int jx = player->jx, jy = player->jy;
11928 int i, found = FALSE;
11930 player->present = FALSE;
11931 player->active = FALSE;
11933 if (!ExplodeField[jx][jy])
11934 StorePlayer[jx][jy] = 0;
11936 if (player->is_moving)
11937 DrawLevelField(player->last_jx, player->last_jy);
11939 for (i = 0; i < MAX_PLAYERS; i++)
11940 if (stored_player[i].active)
11944 AllPlayersGone = TRUE;
11950 #if USE_NEW_SNAP_DELAY
11951 static void setFieldForSnapping(int x, int y, int element, int direction)
11953 struct ElementInfo *ei = &element_info[element];
11954 int direction_bit = MV_DIR_TO_BIT(direction);
11955 int graphic_snapping = ei->direction_graphic[ACTION_SNAPPING][direction_bit];
11956 int action = (graphic_snapping != IMG_EMPTY_SPACE ? ACTION_SNAPPING :
11957 IS_DIGGABLE(element) ? ACTION_DIGGING : ACTION_COLLECTING);
11959 Feld[x][y] = EL_ELEMENT_SNAPPING;
11960 MovDelay[x][y] = MOVE_DELAY_NORMAL_SPEED + 1 - 1;
11962 ResetGfxAnimation(x, y);
11964 GfxElement[x][y] = element;
11965 GfxAction[x][y] = action;
11966 GfxDir[x][y] = direction;
11967 GfxFrame[x][y] = -1;
11972 =============================================================================
11973 checkDiagonalPushing()
11974 -----------------------------------------------------------------------------
11975 check if diagonal input device direction results in pushing of object
11976 (by checking if the alternative direction is walkable, diggable, ...)
11977 =============================================================================
11980 static boolean checkDiagonalPushing(struct PlayerInfo *player,
11981 int x, int y, int real_dx, int real_dy)
11983 int jx, jy, dx, dy, xx, yy;
11985 if (real_dx == 0 || real_dy == 0) /* no diagonal direction => push */
11988 /* diagonal direction: check alternative direction */
11993 xx = jx + (dx == 0 ? real_dx : 0);
11994 yy = jy + (dy == 0 ? real_dy : 0);
11996 return (!IN_LEV_FIELD(xx, yy) || IS_SOLID_FOR_PUSHING(Feld[xx][yy]));
12000 =============================================================================
12002 -----------------------------------------------------------------------------
12003 x, y: field next to player (non-diagonal) to try to dig to
12004 real_dx, real_dy: direction as read from input device (can be diagonal)
12005 =============================================================================
12008 int DigField(struct PlayerInfo *player,
12009 int oldx, int oldy, int x, int y,
12010 int real_dx, int real_dy, int mode)
12012 boolean is_player = (IS_PLAYER(oldx, oldy) || mode != DF_DIG);
12013 boolean player_was_pushing = player->is_pushing;
12014 boolean player_can_move = (!player->cannot_move && mode != DF_SNAP);
12015 boolean player_can_move_or_snap = (!player->cannot_move || mode == DF_SNAP);
12016 int jx = oldx, jy = oldy;
12017 int dx = x - jx, dy = y - jy;
12018 int nextx = x + dx, nexty = y + dy;
12019 int move_direction = (dx == -1 ? MV_LEFT :
12020 dx == +1 ? MV_RIGHT :
12022 dy == +1 ? MV_DOWN : MV_NONE);
12023 int opposite_direction = MV_DIR_OPPOSITE(move_direction);
12024 int dig_side = MV_DIR_OPPOSITE(move_direction);
12025 int old_element = Feld[jx][jy];
12026 #if USE_FIXED_DONT_RUN_INTO
12027 int element = MovingOrBlocked2ElementIfNotLeaving(x, y);
12033 if (is_player) /* function can also be called by EL_PENGUIN */
12035 if (player->MovPos == 0)
12037 player->is_digging = FALSE;
12038 player->is_collecting = FALSE;
12041 if (player->MovPos == 0) /* last pushing move finished */
12042 player->is_pushing = FALSE;
12044 if (mode == DF_NO_PUSH) /* player just stopped pushing */
12046 player->is_switching = FALSE;
12047 player->push_delay = -1;
12049 return MP_NO_ACTION;
12053 #if !USE_FIXED_DONT_RUN_INTO
12054 if (IS_MOVING(x, y) || IS_PLAYER(x, y))
12055 return MP_NO_ACTION;
12058 if (IS_TUBE(Back[jx][jy]) && game.engine_version >= VERSION_IDENT(2,2,0,0))
12059 old_element = Back[jx][jy];
12061 /* in case of element dropped at player position, check background */
12062 else if (Back[jx][jy] != EL_EMPTY &&
12063 game.engine_version >= VERSION_IDENT(2,2,0,0))
12064 old_element = Back[jx][jy];
12066 /* checking here causes player to move into acid even if the current field
12067 cannot be left to that direction */
12069 #if USE_FIXED_DONT_RUN_INTO
12070 if (player_can_move && DONT_RUN_INTO(element))
12072 if (element == EL_ACID && dx == 0 && dy == 1)
12075 Feld[jx][jy] = EL_PLAYER_1;
12076 InitMovingField(jx, jy, MV_DOWN);
12077 Store[jx][jy] = EL_ACID;
12078 ContinueMoving(jx, jy);
12079 BuryPlayer(player);
12082 TestIfPlayerRunsIntoBadThing(jx, jy, player->MovDir);
12084 return MP_DONT_RUN_INTO;
12089 #if 1 /* ------------------------------ NEW ------------------------------ */
12091 if (IS_WALKABLE(old_element) && !ACCESS_FROM(old_element, move_direction))
12092 return MP_NO_ACTION; /* field has no opening in this direction */
12094 if (IS_PASSABLE(old_element) && !ACCESS_FROM(old_element,opposite_direction))
12095 return MP_NO_ACTION; /* field has no opening in this direction */
12097 #if USE_FIXED_DONT_RUN_INTO
12098 if (player_can_move && element == EL_ACID && move_direction == MV_DOWN)
12102 Feld[jx][jy] = player->artwork_element;
12104 Feld[jx][jy] = EL_PLAYER_1;
12106 InitMovingField(jx, jy, MV_DOWN);
12107 Store[jx][jy] = EL_ACID;
12108 ContinueMoving(jx, jy);
12109 BuryPlayer(player);
12111 return MP_DONT_RUN_INTO;
12115 #if USE_FIXED_DONT_RUN_INTO
12116 if (player_can_move && DONT_RUN_INTO(element))
12118 TestIfPlayerRunsIntoBadThing(jx, jy, player->MovDir);
12120 return MP_DONT_RUN_INTO;
12124 #else /* ------------------------------ OLD ------------------------------ */
12127 #if USE_FIXED_DONT_RUN_INTO
12128 if (player_can_move && DONT_RUN_INTO(element))
12130 TestIfPlayerRunsIntoBadThing(jx, jy, player->MovDir);
12132 return MP_DONT_RUN_INTO;
12137 if (IS_WALKABLE(old_element) && !ACCESS_FROM(old_element, move_direction))
12138 return MP_NO_ACTION; /* field has no opening in this direction */
12140 if (IS_PASSABLE(old_element) && !ACCESS_FROM(old_element,opposite_direction))
12141 return MP_NO_ACTION; /* field has no opening in this direction */
12143 /* checking here causes player to explode when moving into acid */
12145 #if USE_FIXED_DONT_RUN_INTO
12146 if (player_can_move && element == EL_ACID && move_direction == MV_DOWN)
12149 Feld[jx][jy] = EL_PLAYER_1;
12150 InitMovingField(jx, jy, MV_DOWN);
12151 Store[jx][jy] = EL_ACID;
12152 ContinueMoving(jx, jy);
12153 BuryPlayer(player);
12155 return MP_DONT_RUN_INTO;
12160 #endif /* ------------------------------ END ------------------------------ */
12163 #if USE_FIXED_DONT_RUN_INTO
12164 if (player_can_move && DONT_RUN_INTO(element))
12166 if (element == EL_ACID && dx == 0 && dy == 1)
12169 Feld[jx][jy] = EL_PLAYER_1;
12170 InitMovingField(jx, jy, MV_DOWN);
12171 Store[jx][jy] = EL_ACID;
12172 ContinueMoving(jx, jy);
12173 BuryPlayer(player);
12176 TestIfPlayerRunsIntoBadThing(jx, jy, player->MovDir);
12178 return MP_DONT_RUN_INTO;
12183 #if USE_FIXED_DONT_RUN_INTO
12184 if (IS_MOVING(x, y) || IS_PLAYER(x, y))
12185 return MP_NO_ACTION;
12188 #if !USE_FIXED_DONT_RUN_INTO
12189 element = Feld[x][y];
12192 collect_count = element_info[element].collect_count_initial;
12194 if (!is_player && !IS_COLLECTIBLE(element)) /* penguin cannot collect it */
12195 return MP_NO_ACTION;
12197 if (game.engine_version < VERSION_IDENT(2,2,0,0))
12198 player_can_move = player_can_move_or_snap;
12200 if (mode == DF_SNAP && !IS_SNAPPABLE(element) &&
12201 game.engine_version >= VERSION_IDENT(2,2,0,0))
12203 CheckElementChangeByPlayer(x, y, element, CE_SNAPPED_BY_PLAYER,
12204 player->index_bit, dig_side);
12205 CheckTriggeredElementChangeByPlayer(x, y, element, CE_PLAYER_SNAPS_X,
12206 player->index_bit, dig_side);
12208 if (Feld[x][y] != element) /* field changed by snapping */
12211 return MP_NO_ACTION;
12214 #if USE_PLAYER_GRAVITY
12215 if (player->gravity && is_player && !player->is_auto_moving &&
12216 canFallDown(player) && move_direction != MV_DOWN &&
12217 !canMoveToValidFieldWithGravity(jx, jy, move_direction))
12218 return MP_NO_ACTION; /* player cannot walk here due to gravity */
12220 if (game.gravity && is_player && !player->is_auto_moving &&
12221 canFallDown(player) && move_direction != MV_DOWN &&
12222 !canMoveToValidFieldWithGravity(jx, jy, move_direction))
12223 return MP_NO_ACTION; /* player cannot walk here due to gravity */
12226 if (player_can_move &&
12227 IS_WALKABLE(element) && ACCESS_FROM(element, opposite_direction))
12229 int sound_element = SND_ELEMENT(element);
12230 int sound_action = ACTION_WALKING;
12232 if (IS_RND_GATE(element))
12234 if (!player->key[RND_GATE_NR(element)])
12235 return MP_NO_ACTION;
12237 else if (IS_RND_GATE_GRAY(element))
12239 if (!player->key[RND_GATE_GRAY_NR(element)])
12240 return MP_NO_ACTION;
12242 else if (IS_RND_GATE_GRAY_ACTIVE(element))
12244 if (!player->key[RND_GATE_GRAY_ACTIVE_NR(element)])
12245 return MP_NO_ACTION;
12247 else if (element == EL_EXIT_OPEN ||
12248 element == EL_SP_EXIT_OPEN ||
12249 element == EL_SP_EXIT_OPENING)
12251 sound_action = ACTION_PASSING; /* player is passing exit */
12253 else if (element == EL_EMPTY)
12255 sound_action = ACTION_MOVING; /* nothing to walk on */
12258 /* play sound from background or player, whatever is available */
12259 if (element_info[sound_element].sound[sound_action] != SND_UNDEFINED)
12260 PlayLevelSoundElementAction(x, y, sound_element, sound_action);
12262 PlayLevelSoundElementAction(x, y, player->artwork_element, sound_action);
12264 else if (player_can_move &&
12265 IS_PASSABLE(element) && canPassField(x, y, move_direction))
12267 if (!ACCESS_FROM(element, opposite_direction))
12268 return MP_NO_ACTION; /* field not accessible from this direction */
12270 if (CAN_MOVE(element)) /* only fixed elements can be passed! */
12271 return MP_NO_ACTION;
12273 if (IS_EM_GATE(element))
12275 if (!player->key[EM_GATE_NR(element)])
12276 return MP_NO_ACTION;
12278 else if (IS_EM_GATE_GRAY(element))
12280 if (!player->key[EM_GATE_GRAY_NR(element)])
12281 return MP_NO_ACTION;
12283 else if (IS_EM_GATE_GRAY_ACTIVE(element))
12285 if (!player->key[EM_GATE_GRAY_ACTIVE_NR(element)])
12286 return MP_NO_ACTION;
12288 else if (IS_EMC_GATE(element))
12290 if (!player->key[EMC_GATE_NR(element)])
12291 return MP_NO_ACTION;
12293 else if (IS_EMC_GATE_GRAY(element))
12295 if (!player->key[EMC_GATE_GRAY_NR(element)])
12296 return MP_NO_ACTION;
12298 else if (IS_EMC_GATE_GRAY_ACTIVE(element))
12300 if (!player->key[EMC_GATE_GRAY_ACTIVE_NR(element)])
12301 return MP_NO_ACTION;
12303 else if (IS_SP_PORT(element))
12305 if (element == EL_SP_GRAVITY_PORT_LEFT ||
12306 element == EL_SP_GRAVITY_PORT_RIGHT ||
12307 element == EL_SP_GRAVITY_PORT_UP ||
12308 element == EL_SP_GRAVITY_PORT_DOWN)
12309 #if USE_PLAYER_GRAVITY
12310 player->gravity = !player->gravity;
12312 game.gravity = !game.gravity;
12314 else if (element == EL_SP_GRAVITY_ON_PORT_LEFT ||
12315 element == EL_SP_GRAVITY_ON_PORT_RIGHT ||
12316 element == EL_SP_GRAVITY_ON_PORT_UP ||
12317 element == EL_SP_GRAVITY_ON_PORT_DOWN)
12318 #if USE_PLAYER_GRAVITY
12319 player->gravity = TRUE;
12321 game.gravity = TRUE;
12323 else if (element == EL_SP_GRAVITY_OFF_PORT_LEFT ||
12324 element == EL_SP_GRAVITY_OFF_PORT_RIGHT ||
12325 element == EL_SP_GRAVITY_OFF_PORT_UP ||
12326 element == EL_SP_GRAVITY_OFF_PORT_DOWN)
12327 #if USE_PLAYER_GRAVITY
12328 player->gravity = FALSE;
12330 game.gravity = FALSE;
12334 /* automatically move to the next field with double speed */
12335 player->programmed_action = move_direction;
12337 if (player->move_delay_reset_counter == 0)
12339 player->move_delay_reset_counter = 2; /* two double speed steps */
12341 DOUBLE_PLAYER_SPEED(player);
12344 PlayLevelSoundAction(x, y, ACTION_PASSING);
12346 else if (player_can_move_or_snap && IS_DIGGABLE(element))
12350 if (mode != DF_SNAP)
12352 GfxElement[x][y] = GFX_ELEMENT(element);
12353 player->is_digging = TRUE;
12356 PlayLevelSoundElementAction(x, y, element, ACTION_DIGGING);
12358 CheckTriggeredElementChangeByPlayer(x, y, element, CE_PLAYER_DIGS_X,
12359 player->index_bit, dig_side);
12361 if (mode == DF_SNAP)
12363 #if USE_NEW_SNAP_DELAY
12364 if (level.block_snap_field)
12365 setFieldForSnapping(x, y, element, move_direction);
12367 TestIfElementTouchesCustomElement(x, y); /* for empty space */
12369 TestIfElementTouchesCustomElement(x, y); /* for empty space */
12372 CheckTriggeredElementChangeByPlayer(x, y, element, CE_PLAYER_SNAPS_X,
12373 player->index_bit, dig_side);
12376 else if (player_can_move_or_snap && IS_COLLECTIBLE(element))
12380 if (is_player && mode != DF_SNAP)
12382 GfxElement[x][y] = element;
12383 player->is_collecting = TRUE;
12386 if (element == EL_SPEED_PILL)
12388 player->move_delay_value = MOVE_DELAY_HIGH_SPEED;
12390 else if (element == EL_EXTRA_TIME && level.time > 0)
12392 TimeLeft += level.extra_time;
12393 DrawGameValue_Time(TimeLeft);
12395 else if (element == EL_SHIELD_NORMAL || element == EL_SHIELD_DEADLY)
12397 player->shield_normal_time_left += level.shield_normal_time;
12398 if (element == EL_SHIELD_DEADLY)
12399 player->shield_deadly_time_left += level.shield_deadly_time;
12401 else if (element == EL_DYNAMITE ||
12402 element == EL_EM_DYNAMITE ||
12403 element == EL_SP_DISK_RED)
12405 if (player->inventory_size < MAX_INVENTORY_SIZE)
12406 player->inventory_element[player->inventory_size++] = element;
12409 DrawGameDoorValues();
12411 DrawGameValue_Dynamite(local_player->inventory_size);
12414 else if (element == EL_DYNABOMB_INCREASE_NUMBER)
12416 player->dynabomb_count++;
12417 player->dynabombs_left++;
12419 else if (element == EL_DYNABOMB_INCREASE_SIZE)
12421 player->dynabomb_size++;
12423 else if (element == EL_DYNABOMB_INCREASE_POWER)
12425 player->dynabomb_xl = TRUE;
12427 else if (IS_KEY(element))
12429 player->key[KEY_NR(element)] = TRUE;
12432 DrawGameDoorValues();
12434 DrawGameValue_Keys(player->key);
12437 redraw_mask |= REDRAW_DOOR_1;
12439 else if (IS_ENVELOPE(element))
12441 player->show_envelope = element;
12443 else if (element == EL_EMC_LENSES)
12445 game.lenses_time_left = level.lenses_time * FRAMES_PER_SECOND;
12447 RedrawAllInvisibleElementsForLenses();
12449 else if (element == EL_EMC_MAGNIFIER)
12451 game.magnify_time_left = level.magnify_time * FRAMES_PER_SECOND;
12453 RedrawAllInvisibleElementsForMagnifier();
12455 else if (IS_DROPPABLE(element) ||
12456 IS_THROWABLE(element)) /* can be collected and dropped */
12460 if (collect_count == 0)
12461 player->inventory_infinite_element = element;
12463 for (i = 0; i < collect_count; i++)
12464 if (player->inventory_size < MAX_INVENTORY_SIZE)
12465 player->inventory_element[player->inventory_size++] = element;
12468 DrawGameDoorValues();
12470 DrawGameValue_Dynamite(local_player->inventory_size);
12473 else if (collect_count > 0)
12475 local_player->gems_still_needed -= collect_count;
12476 if (local_player->gems_still_needed < 0)
12477 local_player->gems_still_needed = 0;
12479 DrawGameValue_Emeralds(local_player->gems_still_needed);
12482 RaiseScoreElement(element);
12483 PlayLevelSoundElementAction(x, y, element, ACTION_COLLECTING);
12486 CheckTriggeredElementChangeByPlayer(x, y, element, CE_PLAYER_COLLECTS_X,
12487 player->index_bit, dig_side);
12489 if (mode == DF_SNAP)
12491 #if USE_NEW_SNAP_DELAY
12492 if (level.block_snap_field)
12493 setFieldForSnapping(x, y, element, move_direction);
12495 TestIfElementTouchesCustomElement(x, y); /* for empty space */
12497 TestIfElementTouchesCustomElement(x, y); /* for empty space */
12500 CheckTriggeredElementChangeByPlayer(x, y, element, CE_PLAYER_SNAPS_X,
12501 player->index_bit, dig_side);
12504 else if (player_can_move_or_snap && IS_PUSHABLE(element))
12506 if (mode == DF_SNAP && element != EL_BD_ROCK)
12507 return MP_NO_ACTION;
12509 if (CAN_FALL(element) && dy)
12510 return MP_NO_ACTION;
12512 if (CAN_FALL(element) && IN_LEV_FIELD(x, y + 1) && IS_FREE(x, y + 1) &&
12513 !(element == EL_SPRING && level.use_spring_bug))
12514 return MP_NO_ACTION;
12516 if (CAN_MOVE(element) && GET_MAX_MOVE_DELAY(element) == 0 &&
12517 ((move_direction & MV_VERTICAL &&
12518 ((element_info[element].move_pattern & MV_LEFT &&
12519 IN_LEV_FIELD(x - 1, y) && IS_FREE(x - 1, y)) ||
12520 (element_info[element].move_pattern & MV_RIGHT &&
12521 IN_LEV_FIELD(x + 1, y) && IS_FREE(x + 1, y)))) ||
12522 (move_direction & MV_HORIZONTAL &&
12523 ((element_info[element].move_pattern & MV_UP &&
12524 IN_LEV_FIELD(x, y - 1) && IS_FREE(x, y - 1)) ||
12525 (element_info[element].move_pattern & MV_DOWN &&
12526 IN_LEV_FIELD(x, y + 1) && IS_FREE(x, y + 1))))))
12527 return MP_NO_ACTION;
12529 /* do not push elements already moving away faster than player */
12530 if (CAN_MOVE(element) && MovDir[x][y] == move_direction &&
12531 ABS(getElementMoveStepsize(x, y)) > MOVE_STEPSIZE_NORMAL)
12532 return MP_NO_ACTION;
12534 if (game.engine_version >= VERSION_IDENT(3,1,0,0))
12536 if (player->push_delay_value == -1 || !player_was_pushing)
12537 player->push_delay_value = GET_NEW_PUSH_DELAY(element);
12539 else if (game.engine_version >= VERSION_IDENT(3,0,7,1))
12541 if (player->push_delay_value == -1)
12542 player->push_delay_value = GET_NEW_PUSH_DELAY(element);
12544 else if (game.engine_version >= VERSION_IDENT(2,2,0,7))
12546 if (!player->is_pushing)
12547 player->push_delay_value = GET_NEW_PUSH_DELAY(element);
12550 player->is_pushing = TRUE;
12551 player->is_active = TRUE;
12553 if (!(IN_LEV_FIELD(nextx, nexty) &&
12554 (IS_FREE(nextx, nexty) ||
12555 (Feld[nextx][nexty] == EL_SOKOBAN_FIELD_EMPTY &&
12556 IS_SB_ELEMENT(element)))))
12557 return MP_NO_ACTION;
12559 if (!checkDiagonalPushing(player, x, y, real_dx, real_dy))
12560 return MP_NO_ACTION;
12562 if (player->push_delay == -1) /* new pushing; restart delay */
12563 player->push_delay = 0;
12565 if (player->push_delay < player->push_delay_value &&
12566 !(tape.playing && tape.file_version < FILE_VERSION_2_0) &&
12567 element != EL_SPRING && element != EL_BALLOON)
12569 /* make sure that there is no move delay before next try to push */
12570 if (game.engine_version >= VERSION_IDENT(3,0,7,1))
12571 player->move_delay = 0;
12573 return MP_NO_ACTION;
12576 if (IS_SB_ELEMENT(element))
12578 if (element == EL_SOKOBAN_FIELD_FULL)
12580 Back[x][y] = EL_SOKOBAN_FIELD_EMPTY;
12581 local_player->sokobanfields_still_needed++;
12584 if (Feld[nextx][nexty] == EL_SOKOBAN_FIELD_EMPTY)
12586 Back[nextx][nexty] = EL_SOKOBAN_FIELD_EMPTY;
12587 local_player->sokobanfields_still_needed--;
12590 Feld[x][y] = EL_SOKOBAN_OBJECT;
12592 if (Back[x][y] == Back[nextx][nexty])
12593 PlayLevelSoundAction(x, y, ACTION_PUSHING);
12594 else if (Back[x][y] != 0)
12595 PlayLevelSoundElementAction(x, y, EL_SOKOBAN_FIELD_FULL,
12598 PlayLevelSoundElementAction(nextx, nexty, EL_SOKOBAN_FIELD_EMPTY,
12601 if (local_player->sokobanfields_still_needed == 0 &&
12602 game.emulation == EMU_SOKOBAN)
12604 player->LevelSolved = player->GameOver = TRUE;
12605 PlayLevelSound(x, y, SND_GAME_SOKOBAN_SOLVING);
12609 PlayLevelSoundElementAction(x, y, element, ACTION_PUSHING);
12611 InitMovingField(x, y, move_direction);
12612 GfxAction[x][y] = ACTION_PUSHING;
12614 if (mode == DF_SNAP)
12615 ContinueMoving(x, y);
12617 MovPos[x][y] = (dx != 0 ? dx : dy);
12619 Pushed[x][y] = TRUE;
12620 Pushed[nextx][nexty] = TRUE;
12622 if (game.engine_version < VERSION_IDENT(2,2,0,7))
12623 player->push_delay_value = GET_NEW_PUSH_DELAY(element);
12625 player->push_delay_value = -1; /* get new value later */
12627 /* check for element change _after_ element has been pushed */
12628 if (game.use_change_when_pushing_bug)
12630 CheckElementChangeByPlayer(x, y, element, CE_PUSHED_BY_PLAYER,
12631 player->index_bit, dig_side);
12632 CheckTriggeredElementChangeByPlayer(x, y, element, CE_PLAYER_PUSHES_X,
12633 player->index_bit, dig_side);
12636 else if (IS_SWITCHABLE(element))
12638 if (PLAYER_SWITCHING(player, x, y))
12640 CheckTriggeredElementChangeByPlayer(x, y, element, CE_PLAYER_PRESSES_X,
12641 player->index_bit, dig_side);
12646 player->is_switching = TRUE;
12647 player->switch_x = x;
12648 player->switch_y = y;
12650 PlayLevelSoundElementAction(x, y, element, ACTION_ACTIVATING);
12652 if (element == EL_ROBOT_WHEEL)
12654 Feld[x][y] = EL_ROBOT_WHEEL_ACTIVE;
12658 DrawLevelField(x, y);
12660 else if (element == EL_SP_TERMINAL)
12665 SCAN_PLAYFIELD(xx, yy)
12667 for (yy = 0; yy < lev_fieldy; yy++) for (xx = 0; xx < lev_fieldx; xx++)
12670 if (Feld[xx][yy] == EL_SP_DISK_YELLOW)
12672 else if (Feld[xx][yy] == EL_SP_TERMINAL)
12673 Feld[xx][yy] = EL_SP_TERMINAL_ACTIVE;
12676 else if (IS_BELT_SWITCH(element))
12678 ToggleBeltSwitch(x, y);
12680 else if (element == EL_SWITCHGATE_SWITCH_UP ||
12681 element == EL_SWITCHGATE_SWITCH_DOWN)
12683 ToggleSwitchgateSwitch(x, y);
12685 else if (element == EL_LIGHT_SWITCH ||
12686 element == EL_LIGHT_SWITCH_ACTIVE)
12688 ToggleLightSwitch(x, y);
12690 else if (element == EL_TIMEGATE_SWITCH)
12692 ActivateTimegateSwitch(x, y);
12694 else if (element == EL_BALLOON_SWITCH_LEFT ||
12695 element == EL_BALLOON_SWITCH_RIGHT ||
12696 element == EL_BALLOON_SWITCH_UP ||
12697 element == EL_BALLOON_SWITCH_DOWN ||
12698 element == EL_BALLOON_SWITCH_NONE ||
12699 element == EL_BALLOON_SWITCH_ANY)
12701 game.wind_direction = (element == EL_BALLOON_SWITCH_LEFT ? MV_LEFT :
12702 element == EL_BALLOON_SWITCH_RIGHT ? MV_RIGHT :
12703 element == EL_BALLOON_SWITCH_UP ? MV_UP :
12704 element == EL_BALLOON_SWITCH_DOWN ? MV_DOWN :
12705 element == EL_BALLOON_SWITCH_NONE ? MV_NONE :
12708 else if (element == EL_LAMP)
12710 Feld[x][y] = EL_LAMP_ACTIVE;
12711 local_player->lights_still_needed--;
12713 ResetGfxAnimation(x, y);
12714 DrawLevelField(x, y);
12716 else if (element == EL_TIME_ORB_FULL)
12718 Feld[x][y] = EL_TIME_ORB_EMPTY;
12720 if (level.time > 0 || level.use_time_orb_bug)
12722 TimeLeft += level.time_orb_time;
12723 DrawGameValue_Time(TimeLeft);
12726 ResetGfxAnimation(x, y);
12727 DrawLevelField(x, y);
12729 else if (element == EL_EMC_MAGIC_BALL_SWITCH ||
12730 element == EL_EMC_MAGIC_BALL_SWITCH_ACTIVE)
12734 game.ball_state = !game.ball_state;
12737 SCAN_PLAYFIELD(xx, yy)
12739 for (yy = 0; yy < lev_fieldy; yy++) for (xx = 0; xx < lev_fieldx; xx++)
12742 int e = Feld[xx][yy];
12744 if (game.ball_state)
12746 if (e == EL_EMC_MAGIC_BALL)
12747 CreateField(xx, yy, EL_EMC_MAGIC_BALL_ACTIVE);
12748 else if (e == EL_EMC_MAGIC_BALL_SWITCH)
12749 CreateField(xx, yy, EL_EMC_MAGIC_BALL_SWITCH_ACTIVE);
12753 if (e == EL_EMC_MAGIC_BALL_ACTIVE)
12754 CreateField(xx, yy, EL_EMC_MAGIC_BALL);
12755 else if (e == EL_EMC_MAGIC_BALL_SWITCH_ACTIVE)
12756 CreateField(xx, yy, EL_EMC_MAGIC_BALL_SWITCH);
12761 CheckTriggeredElementChangeByPlayer(x, y, element, CE_SWITCH_OF_X,
12762 player->index_bit, dig_side);
12764 CheckTriggeredElementChangeByPlayer(x, y, element, CE_PLAYER_SWITCHES_X,
12765 player->index_bit, dig_side);
12767 CheckTriggeredElementChangeByPlayer(x, y, element, CE_PLAYER_PRESSES_X,
12768 player->index_bit, dig_side);
12774 if (!PLAYER_SWITCHING(player, x, y))
12776 player->is_switching = TRUE;
12777 player->switch_x = x;
12778 player->switch_y = y;
12780 CheckElementChangeByPlayer(x, y, element, CE_SWITCHED,
12781 player->index_bit, dig_side);
12782 CheckTriggeredElementChangeByPlayer(x, y, element, CE_SWITCH_OF_X,
12783 player->index_bit, dig_side);
12785 CheckElementChangeByPlayer(x, y, element, CE_SWITCHED_BY_PLAYER,
12786 player->index_bit, dig_side);
12787 CheckTriggeredElementChangeByPlayer(x, y, element, CE_PLAYER_SWITCHES_X,
12788 player->index_bit, dig_side);
12791 CheckElementChangeByPlayer(x, y, element, CE_PRESSED_BY_PLAYER,
12792 player->index_bit, dig_side);
12793 CheckTriggeredElementChangeByPlayer(x, y, element, CE_PLAYER_PRESSES_X,
12794 player->index_bit, dig_side);
12796 return MP_NO_ACTION;
12799 player->push_delay = -1;
12801 if (is_player) /* function can also be called by EL_PENGUIN */
12803 if (Feld[x][y] != element) /* really digged/collected something */
12805 player->is_collecting = !player->is_digging;
12806 player->is_active = TRUE;
12813 boolean SnapField(struct PlayerInfo *player, int dx, int dy)
12815 int jx = player->jx, jy = player->jy;
12816 int x = jx + dx, y = jy + dy;
12817 int snap_direction = (dx == -1 ? MV_LEFT :
12818 dx == +1 ? MV_RIGHT :
12820 dy == +1 ? MV_DOWN : MV_NONE);
12821 boolean can_continue_snapping = (level.continuous_snapping &&
12822 WasJustFalling[x][y] < CHECK_DELAY_FALLING);
12824 if (player->MovPos != 0 && game.engine_version >= VERSION_IDENT(2,2,0,0))
12827 if (!player->active || !IN_LEV_FIELD(x, y))
12835 if (player->MovPos == 0)
12836 player->is_pushing = FALSE;
12838 player->is_snapping = FALSE;
12840 if (player->MovPos == 0)
12842 player->is_moving = FALSE;
12843 player->is_digging = FALSE;
12844 player->is_collecting = FALSE;
12850 #if USE_NEW_CONTINUOUS_SNAPPING
12851 /* prevent snapping with already pressed snap key when not allowed */
12852 if (player->is_snapping && !can_continue_snapping)
12855 if (player->is_snapping)
12859 player->MovDir = snap_direction;
12861 if (player->MovPos == 0)
12863 player->is_moving = FALSE;
12864 player->is_digging = FALSE;
12865 player->is_collecting = FALSE;
12868 player->is_dropping = FALSE;
12869 player->is_dropping_pressed = FALSE;
12870 player->drop_pressed_delay = 0;
12872 if (DigField(player, jx, jy, x, y, 0, 0, DF_SNAP) == MP_NO_ACTION)
12875 player->is_snapping = TRUE;
12876 player->is_active = TRUE;
12878 if (player->MovPos == 0)
12880 player->is_moving = FALSE;
12881 player->is_digging = FALSE;
12882 player->is_collecting = FALSE;
12885 if (player->MovPos != 0) /* prevent graphic bugs in versions < 2.2.0 */
12886 DrawLevelField(player->last_jx, player->last_jy);
12888 DrawLevelField(x, y);
12893 boolean DropElement(struct PlayerInfo *player)
12895 int old_element, new_element;
12896 int dropx = player->jx, dropy = player->jy;
12897 int drop_direction = player->MovDir;
12898 int drop_side = drop_direction;
12899 int drop_element = (player->inventory_size > 0 ?
12900 player->inventory_element[player->inventory_size - 1] :
12901 player->inventory_infinite_element != EL_UNDEFINED ?
12902 player->inventory_infinite_element :
12903 player->dynabombs_left > 0 ?
12904 EL_DYNABOMB_PLAYER_1_ACTIVE + player->index_nr :
12907 player->is_dropping_pressed = TRUE;
12909 /* do not drop an element on top of another element; when holding drop key
12910 pressed without moving, dropped element must move away before the next
12911 element can be dropped (this is especially important if the next element
12912 is dynamite, which can be placed on background for historical reasons) */
12913 if (PLAYER_DROPPING(player, dropx, dropy) && Feld[dropx][dropy] != EL_EMPTY)
12916 if (IS_THROWABLE(drop_element))
12918 dropx += GET_DX_FROM_DIR(drop_direction);
12919 dropy += GET_DY_FROM_DIR(drop_direction);
12921 if (!IN_LEV_FIELD(dropx, dropy))
12925 old_element = Feld[dropx][dropy]; /* old element at dropping position */
12926 new_element = drop_element; /* default: no change when dropping */
12928 /* check if player is active, not moving and ready to drop */
12929 if (!player->active || player->MovPos || player->drop_delay > 0)
12932 /* check if player has anything that can be dropped */
12933 if (new_element == EL_UNDEFINED)
12936 /* check if drop key was pressed long enough for EM style dynamite */
12937 if (new_element == EL_EM_DYNAMITE && player->drop_pressed_delay < 40)
12940 /* check if anything can be dropped at the current position */
12941 if (IS_ACTIVE_BOMB(old_element) || old_element == EL_EXPLOSION)
12944 /* collected custom elements can only be dropped on empty fields */
12945 if (IS_CUSTOM_ELEMENT(new_element) && old_element != EL_EMPTY)
12948 if (old_element != EL_EMPTY)
12949 Back[dropx][dropy] = old_element; /* store old element on this field */
12951 ResetGfxAnimation(dropx, dropy);
12952 ResetRandomAnimationValue(dropx, dropy);
12954 if (player->inventory_size > 0 ||
12955 player->inventory_infinite_element != EL_UNDEFINED)
12957 if (player->inventory_size > 0)
12959 player->inventory_size--;
12962 DrawGameDoorValues();
12964 DrawGameValue_Dynamite(local_player->inventory_size);
12967 if (new_element == EL_DYNAMITE)
12968 new_element = EL_DYNAMITE_ACTIVE;
12969 else if (new_element == EL_EM_DYNAMITE)
12970 new_element = EL_EM_DYNAMITE_ACTIVE;
12971 else if (new_element == EL_SP_DISK_RED)
12972 new_element = EL_SP_DISK_RED_ACTIVE;
12975 Feld[dropx][dropy] = new_element;
12977 if (IN_SCR_FIELD(SCREENX(dropx), SCREENY(dropy)))
12978 DrawGraphicThruMask(SCREENX(dropx), SCREENY(dropy),
12979 el2img(Feld[dropx][dropy]), 0);
12981 PlayLevelSoundAction(dropx, dropy, ACTION_DROPPING);
12983 /* needed if previous element just changed to "empty" in the last frame */
12984 ChangeCount[dropx][dropy] = 0; /* allow at least one more change */
12986 CheckElementChangeByPlayer(dropx, dropy, new_element, CE_DROPPED_BY_PLAYER,
12987 player->index_bit, drop_side);
12988 CheckTriggeredElementChangeByPlayer(dropx, dropy, new_element,
12990 player->index_bit, drop_side);
12992 TestIfElementTouchesCustomElement(dropx, dropy);
12994 else /* player is dropping a dyna bomb */
12996 player->dynabombs_left--;
12998 Feld[dropx][dropy] = new_element;
13000 if (IN_SCR_FIELD(SCREENX(dropx), SCREENY(dropy)))
13001 DrawGraphicThruMask(SCREENX(dropx), SCREENY(dropy),
13002 el2img(Feld[dropx][dropy]), 0);
13004 PlayLevelSoundAction(dropx, dropy, ACTION_DROPPING);
13007 if (Feld[dropx][dropy] == new_element) /* uninitialized unless CE change */
13008 InitField_WithBug1(dropx, dropy, FALSE);
13010 new_element = Feld[dropx][dropy]; /* element might have changed */
13012 if (IS_CUSTOM_ELEMENT(new_element) && CAN_MOVE(new_element) &&
13013 element_info[new_element].move_pattern == MV_WHEN_DROPPED)
13015 int move_direction, nextx, nexty;
13017 if (element_info[new_element].move_direction_initial == MV_START_AUTOMATIC)
13018 MovDir[dropx][dropy] = drop_direction;
13020 move_direction = MovDir[dropx][dropy];
13021 nextx = dropx + GET_DX_FROM_DIR(move_direction);
13022 nexty = dropy + GET_DY_FROM_DIR(move_direction);
13024 ChangeCount[dropx][dropy] = 0; /* allow at least one more change */
13025 CheckCollision[dropx][dropy] = CHECK_DELAY_COLLISION;
13028 player->drop_delay = GET_NEW_DROP_DELAY(drop_element);
13029 player->is_dropping = TRUE;
13031 player->drop_pressed_delay = 0;
13032 player->is_dropping_pressed = FALSE;
13034 player->drop_x = dropx;
13035 player->drop_y = dropy;
13040 /* ------------------------------------------------------------------------- */
13041 /* game sound playing functions */
13042 /* ------------------------------------------------------------------------- */
13044 static int *loop_sound_frame = NULL;
13045 static int *loop_sound_volume = NULL;
13047 void InitPlayLevelSound()
13049 int num_sounds = getSoundListSize();
13051 checked_free(loop_sound_frame);
13052 checked_free(loop_sound_volume);
13054 loop_sound_frame = checked_calloc(num_sounds * sizeof(int));
13055 loop_sound_volume = checked_calloc(num_sounds * sizeof(int));
13058 static void PlayLevelSound(int x, int y, int nr)
13060 int sx = SCREENX(x), sy = SCREENY(y);
13061 int volume, stereo_position;
13062 int max_distance = 8;
13063 int type = (IS_LOOP_SOUND(nr) ? SND_CTRL_PLAY_LOOP : SND_CTRL_PLAY_SOUND);
13065 if ((!setup.sound_simple && !IS_LOOP_SOUND(nr)) ||
13066 (!setup.sound_loops && IS_LOOP_SOUND(nr)))
13069 if (!IN_LEV_FIELD(x, y) ||
13070 sx < -max_distance || sx >= SCR_FIELDX + max_distance ||
13071 sy < -max_distance || sy >= SCR_FIELDY + max_distance)
13074 volume = SOUND_MAX_VOLUME;
13076 if (!IN_SCR_FIELD(sx, sy))
13078 int dx = ABS(sx - SCR_FIELDX / 2) - SCR_FIELDX / 2;
13079 int dy = ABS(sy - SCR_FIELDY / 2) - SCR_FIELDY / 2;
13081 volume -= volume * (dx > dy ? dx : dy) / max_distance;
13084 stereo_position = (SOUND_MAX_LEFT +
13085 (sx + max_distance) * SOUND_MAX_LEFT2RIGHT /
13086 (SCR_FIELDX + 2 * max_distance));
13088 if (IS_LOOP_SOUND(nr))
13090 /* This assures that quieter loop sounds do not overwrite louder ones,
13091 while restarting sound volume comparison with each new game frame. */
13093 if (loop_sound_volume[nr] > volume && loop_sound_frame[nr] == FrameCounter)
13096 loop_sound_volume[nr] = volume;
13097 loop_sound_frame[nr] = FrameCounter;
13100 PlaySoundExt(nr, volume, stereo_position, type);
13103 static void PlayLevelSoundNearest(int x, int y, int sound_action)
13105 PlayLevelSound(x < LEVELX(BX1) ? LEVELX(BX1) :
13106 x > LEVELX(BX2) ? LEVELX(BX2) : x,
13107 y < LEVELY(BY1) ? LEVELY(BY1) :
13108 y > LEVELY(BY2) ? LEVELY(BY2) : y,
13112 static void PlayLevelSoundAction(int x, int y, int action)
13114 PlayLevelSoundElementAction(x, y, Feld[x][y], action);
13117 static void PlayLevelSoundElementAction(int x, int y, int element, int action)
13119 int sound_effect = element_info[SND_ELEMENT(element)].sound[action];
13121 if (sound_effect != SND_UNDEFINED)
13122 PlayLevelSound(x, y, sound_effect);
13125 static void PlayLevelSoundElementActionIfLoop(int x, int y, int element,
13128 int sound_effect = element_info[SND_ELEMENT(element)].sound[action];
13130 if (sound_effect != SND_UNDEFINED && IS_LOOP_SOUND(sound_effect))
13131 PlayLevelSound(x, y, sound_effect);
13134 static void PlayLevelSoundActionIfLoop(int x, int y, int action)
13136 int sound_effect = element_info[SND_ELEMENT(Feld[x][y])].sound[action];
13138 if (sound_effect != SND_UNDEFINED && IS_LOOP_SOUND(sound_effect))
13139 PlayLevelSound(x, y, sound_effect);
13142 static void StopLevelSoundActionIfLoop(int x, int y, int action)
13144 int sound_effect = element_info[SND_ELEMENT(Feld[x][y])].sound[action];
13146 if (sound_effect != SND_UNDEFINED && IS_LOOP_SOUND(sound_effect))
13147 StopSound(sound_effect);
13150 static void PlayLevelMusic()
13152 if (levelset.music[level_nr] != MUS_UNDEFINED)
13153 PlayMusic(levelset.music[level_nr]); /* from config file */
13155 PlayMusic(MAP_NOCONF_MUSIC(level_nr)); /* from music dir */
13158 void PlayLevelSound_EM(int x, int y, int element_em, int sample)
13160 int element = (element_em > -1 ? map_element_EM_to_RND(element_em) : 0);
13165 PlayLevelSoundElementAction(x, y, element, ACTION_WALKING);
13169 PlayLevelSoundElementAction(x, y, element, ACTION_PUSHING);
13173 PlayLevelSoundElementAction(x, y, element, ACTION_IMPACT);
13177 PlayLevelSoundElementAction(x, y, element, ACTION_IMPACT);
13181 PlayLevelSoundElementAction(x, y, element, ACTION_BREAKING);
13185 PlayLevelSoundElementAction(x, y, element, ACTION_MOVING);
13189 PlayLevelSoundElementAction(x, y, element, ACTION_MOVING);
13192 case SAMPLE_android_clone:
13193 PlayLevelSoundElementAction(x, y, element, ACTION_DROPPING);
13196 case SAMPLE_android_move:
13197 PlayLevelSoundElementAction(x, y, element, ACTION_MOVING);
13200 case SAMPLE_spring:
13201 PlayLevelSoundElementAction(x, y, element, ACTION_IMPACT);
13205 PlayLevelSoundElementAction(x, y, element, ACTION_EATING);
13209 PlayLevelSoundElementAction(x, y, element, ACTION_WAITING);
13212 case SAMPLE_eater_eat:
13213 PlayLevelSoundElementAction(x, y, element, ACTION_DIGGING);
13217 PlayLevelSoundElementAction(x, y, element, ACTION_MOVING);
13220 case SAMPLE_collect:
13221 PlayLevelSoundElementAction(x, y, element, ACTION_COLLECTING);
13224 case SAMPLE_diamond:
13225 PlayLevelSoundElementAction(x, y, element, ACTION_IMPACT);
13228 case SAMPLE_squash:
13229 /* !!! CHECK THIS !!! */
13231 PlayLevelSoundElementAction(x, y, element, ACTION_BREAKING);
13233 PlayLevelSoundElementAction(x, y, element, ACTION_SMASHED_BY_ROCK);
13237 case SAMPLE_wonderfall:
13238 PlayLevelSoundElementAction(x, y, element, ACTION_FILLING);
13242 PlayLevelSoundElementAction(x, y, element, ACTION_IMPACT);
13246 PlayLevelSoundElementAction(x, y, element, ACTION_PUSHING);
13250 PlayLevelSoundElementAction(x, y, element, ACTION_DIGGING);
13254 PlayLevelSoundElementAction(x, y, element, ACTION_SPLASHING);
13258 PlayLevelSoundElementAction(x, y, element, ACTION_DROPPING);
13262 PlayLevelSoundElementAction(x, y, element, ACTION_GROWING);
13265 case SAMPLE_wonder:
13266 PlayLevelSoundElementAction(x, y, element, ACTION_ACTIVE);
13270 PlayLevelSoundElementAction(x, y, element, ACTION_PASSING);
13273 case SAMPLE_exit_open:
13274 PlayLevelSoundElementAction(x, y, element, ACTION_OPENING);
13277 case SAMPLE_exit_leave:
13278 PlayLevelSoundElementAction(x, y, element, ACTION_PASSING);
13281 case SAMPLE_dynamite:
13282 PlayLevelSoundElementAction(x, y, element, ACTION_DROPPING);
13286 PlayLevelSoundElementAction(x, y, element, ACTION_ACTIVE);
13290 PlayLevelSoundElementAction(x, y, element, ACTION_ACTIVATING);
13294 PlayLevelSoundElementAction(x, y, element, ACTION_ACTIVE);
13298 PlayLevelSoundElementAction(x, y, element, ACTION_EXPLODING);
13302 PlayLevelSoundElementAction(x, y, element, ACTION_DYING);
13306 PlaySoundStereo(SND_GAME_RUNNING_OUT_OF_TIME, SOUND_MIDDLE);
13310 PlayLevelSoundElementAction(x, y, element, ACTION_DEFAULT);
13315 void RaiseScore(int value)
13317 local_player->score += value;
13319 DrawGameValue_Score(local_player->score);
13322 void RaiseScoreElement(int element)
13327 case EL_BD_DIAMOND:
13328 case EL_EMERALD_YELLOW:
13329 case EL_EMERALD_RED:
13330 case EL_EMERALD_PURPLE:
13331 case EL_SP_INFOTRON:
13332 RaiseScore(level.score[SC_EMERALD]);
13335 RaiseScore(level.score[SC_DIAMOND]);
13338 RaiseScore(level.score[SC_CRYSTAL]);
13341 RaiseScore(level.score[SC_PEARL]);
13344 case EL_BD_BUTTERFLY:
13345 case EL_SP_ELECTRON:
13346 RaiseScore(level.score[SC_BUG]);
13349 case EL_BD_FIREFLY:
13350 case EL_SP_SNIKSNAK:
13351 RaiseScore(level.score[SC_SPACESHIP]);
13354 case EL_DARK_YAMYAM:
13355 RaiseScore(level.score[SC_YAMYAM]);
13358 RaiseScore(level.score[SC_ROBOT]);
13361 RaiseScore(level.score[SC_PACMAN]);
13364 RaiseScore(level.score[SC_NUT]);
13367 case EL_EM_DYNAMITE:
13368 case EL_SP_DISK_RED:
13369 case EL_DYNABOMB_INCREASE_NUMBER:
13370 case EL_DYNABOMB_INCREASE_SIZE:
13371 case EL_DYNABOMB_INCREASE_POWER:
13372 RaiseScore(level.score[SC_DYNAMITE]);
13374 case EL_SHIELD_NORMAL:
13375 case EL_SHIELD_DEADLY:
13376 RaiseScore(level.score[SC_SHIELD]);
13378 case EL_EXTRA_TIME:
13379 RaiseScore(level.extra_time_score);
13393 RaiseScore(level.score[SC_KEY]);
13396 RaiseScore(element_info[element].collect_score);
13401 void RequestQuitGame(boolean ask_if_really_quit)
13403 if (AllPlayersGone ||
13404 !ask_if_really_quit ||
13405 level_editor_test_game ||
13406 Request("Do you really want to quit the game ?",
13407 REQ_ASK | REQ_STAY_CLOSED))
13409 #if defined(NETWORK_AVALIABLE)
13410 if (options.network)
13411 SendToServer_StopPlaying(NETWORK_STOP_BY_PLAYER);
13415 game_status = GAME_MODE_MAIN;
13421 if (tape.playing && tape.deactivate_display)
13422 TapeDeactivateDisplayOff(TRUE);
13424 OpenDoor(DOOR_OPEN_1 | DOOR_COPY_BACK);
13426 if (tape.playing && tape.deactivate_display)
13427 TapeDeactivateDisplayOn();
13432 /* ---------- new game button stuff ---------------------------------------- */
13434 /* graphic position values for game buttons */
13435 #define GAME_BUTTON_XSIZE 30
13436 #define GAME_BUTTON_YSIZE 30
13437 #define GAME_BUTTON_XPOS 5
13438 #define GAME_BUTTON_YPOS 215
13439 #define SOUND_BUTTON_XPOS 5
13440 #define SOUND_BUTTON_YPOS (GAME_BUTTON_YPOS + GAME_BUTTON_YSIZE)
13442 #define GAME_BUTTON_STOP_XPOS (GAME_BUTTON_XPOS + 0 * GAME_BUTTON_XSIZE)
13443 #define GAME_BUTTON_PAUSE_XPOS (GAME_BUTTON_XPOS + 1 * GAME_BUTTON_XSIZE)
13444 #define GAME_BUTTON_PLAY_XPOS (GAME_BUTTON_XPOS + 2 * GAME_BUTTON_XSIZE)
13445 #define SOUND_BUTTON_MUSIC_XPOS (SOUND_BUTTON_XPOS + 0 * GAME_BUTTON_XSIZE)
13446 #define SOUND_BUTTON_LOOPS_XPOS (SOUND_BUTTON_XPOS + 1 * GAME_BUTTON_XSIZE)
13447 #define SOUND_BUTTON_SIMPLE_XPOS (SOUND_BUTTON_XPOS + 2 * GAME_BUTTON_XSIZE)
13454 } gamebutton_info[NUM_GAME_BUTTONS] =
13457 GAME_BUTTON_STOP_XPOS, GAME_BUTTON_YPOS,
13462 GAME_BUTTON_PAUSE_XPOS, GAME_BUTTON_YPOS,
13463 GAME_CTRL_ID_PAUSE,
13467 GAME_BUTTON_PLAY_XPOS, GAME_BUTTON_YPOS,
13472 SOUND_BUTTON_MUSIC_XPOS, SOUND_BUTTON_YPOS,
13473 SOUND_CTRL_ID_MUSIC,
13474 "background music on/off"
13477 SOUND_BUTTON_LOOPS_XPOS, SOUND_BUTTON_YPOS,
13478 SOUND_CTRL_ID_LOOPS,
13479 "sound loops on/off"
13482 SOUND_BUTTON_SIMPLE_XPOS, SOUND_BUTTON_YPOS,
13483 SOUND_CTRL_ID_SIMPLE,
13484 "normal sounds on/off"
13488 void CreateGameButtons()
13492 for (i = 0; i < NUM_GAME_BUTTONS; i++)
13494 Bitmap *gd_bitmap = graphic_info[IMG_GLOBAL_DOOR].bitmap;
13495 struct GadgetInfo *gi;
13498 unsigned long event_mask;
13499 int gd_xoffset, gd_yoffset;
13500 int gd_x1, gd_x2, gd_y1, gd_y2;
13503 gd_xoffset = gamebutton_info[i].x;
13504 gd_yoffset = gamebutton_info[i].y;
13505 gd_x1 = DOOR_GFX_PAGEX4 + gd_xoffset;
13506 gd_x2 = DOOR_GFX_PAGEX3 + gd_xoffset;
13508 if (id == GAME_CTRL_ID_STOP ||
13509 id == GAME_CTRL_ID_PAUSE ||
13510 id == GAME_CTRL_ID_PLAY)
13512 button_type = GD_TYPE_NORMAL_BUTTON;
13514 event_mask = GD_EVENT_RELEASED;
13515 gd_y1 = DOOR_GFX_PAGEY1 + gd_yoffset - GAME_BUTTON_YSIZE;
13516 gd_y2 = DOOR_GFX_PAGEY1 + gd_yoffset - GAME_BUTTON_YSIZE;
13520 button_type = GD_TYPE_CHECK_BUTTON;
13522 ((id == SOUND_CTRL_ID_MUSIC && setup.sound_music) ||
13523 (id == SOUND_CTRL_ID_LOOPS && setup.sound_loops) ||
13524 (id == SOUND_CTRL_ID_SIMPLE && setup.sound_simple) ? TRUE : FALSE);
13525 event_mask = GD_EVENT_PRESSED;
13526 gd_y1 = DOOR_GFX_PAGEY1 + gd_yoffset;
13527 gd_y2 = DOOR_GFX_PAGEY1 + gd_yoffset - GAME_BUTTON_YSIZE;
13530 gi = CreateGadget(GDI_CUSTOM_ID, id,
13531 GDI_INFO_TEXT, gamebutton_info[i].infotext,
13532 GDI_X, DX + gd_xoffset,
13533 GDI_Y, DY + gd_yoffset,
13534 GDI_WIDTH, GAME_BUTTON_XSIZE,
13535 GDI_HEIGHT, GAME_BUTTON_YSIZE,
13536 GDI_TYPE, button_type,
13537 GDI_STATE, GD_BUTTON_UNPRESSED,
13538 GDI_CHECKED, checked,
13539 GDI_DESIGN_UNPRESSED, gd_bitmap, gd_x1, gd_y1,
13540 GDI_DESIGN_PRESSED, gd_bitmap, gd_x2, gd_y1,
13541 GDI_ALT_DESIGN_UNPRESSED, gd_bitmap, gd_x1, gd_y2,
13542 GDI_ALT_DESIGN_PRESSED, gd_bitmap, gd_x2, gd_y2,
13543 GDI_EVENT_MASK, event_mask,
13544 GDI_CALLBACK_ACTION, HandleGameButtons,
13548 Error(ERR_EXIT, "cannot create gadget");
13550 game_gadget[id] = gi;
13554 void FreeGameButtons()
13558 for (i = 0; i < NUM_GAME_BUTTONS; i++)
13559 FreeGadget(game_gadget[i]);
13562 static void MapGameButtons()
13566 for (i = 0; i < NUM_GAME_BUTTONS; i++)
13567 MapGadget(game_gadget[i]);
13570 void UnmapGameButtons()
13574 for (i = 0; i < NUM_GAME_BUTTONS; i++)
13575 UnmapGadget(game_gadget[i]);
13578 static void HandleGameButtons(struct GadgetInfo *gi)
13580 int id = gi->custom_id;
13582 if (game_status != GAME_MODE_PLAYING)
13587 case GAME_CTRL_ID_STOP:
13591 RequestQuitGame(TRUE);
13594 case GAME_CTRL_ID_PAUSE:
13595 if (options.network)
13597 #if defined(NETWORK_AVALIABLE)
13599 SendToServer_ContinuePlaying();
13601 SendToServer_PausePlaying();
13605 TapeTogglePause(TAPE_TOGGLE_MANUAL);
13608 case GAME_CTRL_ID_PLAY:
13611 #if defined(NETWORK_AVALIABLE)
13612 if (options.network)
13613 SendToServer_ContinuePlaying();
13617 tape.pausing = FALSE;
13618 DrawVideoDisplay(VIDEO_STATE_PAUSE_OFF, 0);
13623 case SOUND_CTRL_ID_MUSIC:
13624 if (setup.sound_music)
13626 setup.sound_music = FALSE;
13629 else if (audio.music_available)
13631 setup.sound = setup.sound_music = TRUE;
13633 SetAudioMode(setup.sound);
13639 case SOUND_CTRL_ID_LOOPS:
13640 if (setup.sound_loops)
13641 setup.sound_loops = FALSE;
13642 else if (audio.loops_available)
13644 setup.sound = setup.sound_loops = TRUE;
13645 SetAudioMode(setup.sound);
13649 case SOUND_CTRL_ID_SIMPLE:
13650 if (setup.sound_simple)
13651 setup.sound_simple = FALSE;
13652 else if (audio.sound_available)
13654 setup.sound = setup.sound_simple = TRUE;
13655 SetAudioMode(setup.sound);