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)
49 #define USE_QUICKSAND_IMPACT_BUGFIX (USE_NEW_STUFF * 0)
56 /* for MovePlayer() */
57 #define MP_NO_ACTION 0
60 #define MP_DONT_RUN_INTO (MP_MOVING | MP_ACTION)
62 /* for ScrollPlayer() */
64 #define SCROLL_GO_ON 1
66 /* for Bang()/Explode() */
67 #define EX_PHASE_START 0
68 #define EX_TYPE_NONE 0
69 #define EX_TYPE_NORMAL (1 << 0)
70 #define EX_TYPE_CENTER (1 << 1)
71 #define EX_TYPE_BORDER (1 << 2)
72 #define EX_TYPE_CROSS (1 << 3)
73 #define EX_TYPE_DYNA (1 << 4)
74 #define EX_TYPE_SINGLE_TILE (EX_TYPE_CENTER | EX_TYPE_BORDER)
76 /* special positions in the game control window (relative to control window) */
79 #define XX_EMERALDS 29
80 #define YY_EMERALDS 54
81 #define XX_DYNAMITE 29
82 #define YY_DYNAMITE 89
91 /* special positions in the game control window (relative to main window) */
92 #define DX_LEVEL (DX + XX_LEVEL)
93 #define DY_LEVEL (DY + YY_LEVEL)
94 #define DX_EMERALDS (DX + XX_EMERALDS)
95 #define DY_EMERALDS (DY + YY_EMERALDS)
96 #define DX_DYNAMITE (DX + XX_DYNAMITE)
97 #define DY_DYNAMITE (DY + YY_DYNAMITE)
98 #define DX_KEYS (DX + XX_KEYS)
99 #define DY_KEYS (DY + YY_KEYS)
100 #define DX_SCORE (DX + XX_SCORE)
101 #define DY_SCORE (DY + YY_SCORE)
102 #define DX_TIME1 (DX + XX_TIME1)
103 #define DX_TIME2 (DX + XX_TIME2)
104 #define DY_TIME (DY + YY_TIME)
106 /* values for delayed check of falling and moving elements and for collision */
107 #define CHECK_DELAY_MOVING 3
108 #define CHECK_DELAY_FALLING 3
109 #define CHECK_DELAY_COLLISION 2
111 /* values for initial player move delay (initial delay counter value) */
112 #define INITIAL_MOVE_DELAY_OFF -1
113 #define INITIAL_MOVE_DELAY_ON 0
115 /* values for player movement speed (which is in fact a delay value) */
116 #define MOVE_DELAY_MIN_SPEED 32
117 #define MOVE_DELAY_NORMAL_SPEED 8
118 #define MOVE_DELAY_HIGH_SPEED 4
119 #define MOVE_DELAY_MAX_SPEED 1
122 #define DOUBLE_MOVE_DELAY(x) (x = (x <= MOVE_DELAY_HIGH_SPEED ? x * 2 : x))
123 #define HALVE_MOVE_DELAY(x) (x = (x >= MOVE_DELAY_HIGH_SPEED ? x / 2 : x))
125 #define DOUBLE_MOVE_DELAY(x) (x = (x < MOVE_DELAY_MIN_SPEED ? x * 2 : x))
126 #define HALVE_MOVE_DELAY(x) (x = (x > MOVE_DELAY_MAX_SPEED ? x / 2 : x))
128 #define DOUBLE_PLAYER_SPEED(p) (HALVE_MOVE_DELAY((p)->move_delay_value))
129 #define HALVE_PLAYER_SPEED(p) (DOUBLE_MOVE_DELAY((p)->move_delay_value))
131 /* values for other actions */
132 #define MOVE_STEPSIZE_NORMAL (TILEX / MOVE_DELAY_NORMAL_SPEED)
133 #define MOVE_STEPSIZE_MIN (1)
134 #define MOVE_STEPSIZE_MAX (TILEX)
136 #define GET_DX_FROM_DIR(d) ((d) == MV_LEFT ? -1 : (d) == MV_RIGHT ? 1 : 0)
137 #define GET_DY_FROM_DIR(d) ((d) == MV_UP ? -1 : (d) == MV_DOWN ? 1 : 0)
139 #define INIT_GFX_RANDOM() (SimpleRND(1000000))
141 #define GET_NEW_PUSH_DELAY(e) ( (element_info[e].push_delay_fixed) + \
142 RND(element_info[e].push_delay_random))
143 #define GET_NEW_DROP_DELAY(e) ( (element_info[e].drop_delay_fixed) + \
144 RND(element_info[e].drop_delay_random))
145 #define GET_NEW_MOVE_DELAY(e) ( (element_info[e].move_delay_fixed) + \
146 RND(element_info[e].move_delay_random))
147 #define GET_MAX_MOVE_DELAY(e) ( (element_info[e].move_delay_fixed) + \
148 (element_info[e].move_delay_random))
149 #define GET_NEW_CE_VALUE(e) ( (element_info[e].ce_value_fixed_initial) +\
150 RND(element_info[e].ce_value_random_initial))
151 #define GET_CE_SCORE(e) ( (element_info[e].collect_score))
152 #define GET_CHANGE_DELAY(c) ( ((c)->delay_fixed * (c)->delay_frames) + \
153 RND((c)->delay_random * (c)->delay_frames))
154 #define GET_CE_DELAY_VALUE(c) ( ((c)->delay_fixed) + \
155 RND((c)->delay_random))
159 #define GET_VALID_RUNTIME_ELEMENT(e) \
160 ((e) >= NUM_RUNTIME_ELEMENTS ? EL_UNKNOWN : (e))
162 #define GET_VALID_FILE_ELEMENT(e) \
163 ((e) >= NUM_FILE_ELEMENTS ? EL_UNKNOWN : (e))
166 #define GET_TARGET_ELEMENT(e, ch, cv, cs) \
167 ((e) == EL_TRIGGER_PLAYER ? (ch)->actual_trigger_player : \
168 (e) == EL_TRIGGER_ELEMENT ? (ch)->actual_trigger_element : \
169 (e) == EL_TRIGGER_CE_VALUE ? (ch)->actual_trigger_ce_value : \
170 (e) == EL_TRIGGER_CE_SCORE ? (ch)->actual_trigger_ce_score : \
171 (e) == EL_CURRENT_CE_VALUE ? (cv) : \
172 (e) == EL_CURRENT_CE_SCORE ? (cs) : (e))
174 #define CAN_GROW_INTO(e) \
175 ((e) == EL_SAND || (IS_DIGGABLE(e) && level.grow_into_diggable))
177 #define ELEMENT_CAN_ENTER_FIELD_BASE_X(x, y, condition) \
178 (IN_LEV_FIELD(x, y) && (IS_FREE(x, y) || \
181 #define ELEMENT_CAN_ENTER_FIELD_BASE_2(e, x, y, condition) \
182 (IN_LEV_FIELD(x, y) && (IS_FREE(x, y) || \
183 (CAN_MOVE_INTO_ACID(e) && \
184 Feld[x][y] == EL_ACID) || \
187 #define ELEMENT_CAN_ENTER_FIELD_BASE_3(e, x, y, condition) \
188 (IN_LEV_FIELD(x, y) && (IS_FREE_OR_PLAYER(x, y) || \
189 (CAN_MOVE_INTO_ACID(e) && \
190 Feld[x][y] == EL_ACID) || \
193 #define ELEMENT_CAN_ENTER_FIELD_BASE_4(e, x, y, condition) \
194 (IN_LEV_FIELD(x, y) && (IS_FREE(x, y) || \
196 (CAN_MOVE_INTO_ACID(e) && \
197 Feld[x][y] == EL_ACID) || \
198 (DONT_COLLIDE_WITH(e) && \
200 !PLAYER_ENEMY_PROTECTED(x, y))))
202 #define ELEMENT_CAN_ENTER_FIELD(e, x, y) \
203 ELEMENT_CAN_ENTER_FIELD_BASE_4(e, x, y, 0)
205 #define SATELLITE_CAN_ENTER_FIELD(x, y) \
206 ELEMENT_CAN_ENTER_FIELD_BASE_2(EL_SATELLITE, x, y, 0)
208 #define ANDROID_CAN_ENTER_FIELD(e, x, y) \
209 ELEMENT_CAN_ENTER_FIELD_BASE_2(e, x, y, Feld[x][y] == EL_EMC_PLANT)
211 #define ANDROID_CAN_CLONE_FIELD(x, y) \
212 (IN_LEV_FIELD(x, y) && (CAN_BE_CLONED_BY_ANDROID(Feld[x][y]) || \
213 CAN_BE_CLONED_BY_ANDROID(EL_TRIGGER_ELEMENT)))
215 #define ENEMY_CAN_ENTER_FIELD(e, x, y) \
216 ELEMENT_CAN_ENTER_FIELD_BASE_2(e, x, y, 0)
218 #define YAMYAM_CAN_ENTER_FIELD(e, x, y) \
219 ELEMENT_CAN_ENTER_FIELD_BASE_3(e, x, y, Feld[x][y] == EL_DIAMOND)
221 #define DARK_YAMYAM_CAN_ENTER_FIELD(e, x, y) \
222 ELEMENT_CAN_ENTER_FIELD_BASE_3(e, x,y, IS_FOOD_DARK_YAMYAM(Feld[x][y]))
224 #define PACMAN_CAN_ENTER_FIELD(e, x, y) \
225 ELEMENT_CAN_ENTER_FIELD_BASE_3(e, x, y, IS_AMOEBOID(Feld[x][y]))
227 #define PIG_CAN_ENTER_FIELD(e, x, y) \
228 ELEMENT_CAN_ENTER_FIELD_BASE_2(e, x, y, IS_FOOD_PIG(Feld[x][y]))
230 #define PENGUIN_CAN_ENTER_FIELD(e, x, y) \
231 ELEMENT_CAN_ENTER_FIELD_BASE_2(e, x, y, (Feld[x][y] == EL_EXIT_OPEN ||\
232 IS_FOOD_PENGUIN(Feld[x][y])))
233 #define DRAGON_CAN_ENTER_FIELD(e, x, y) \
234 ELEMENT_CAN_ENTER_FIELD_BASE_2(e, x, y, 0)
236 #define MOLE_CAN_ENTER_FIELD(e, x, y, condition) \
237 ELEMENT_CAN_ENTER_FIELD_BASE_2(e, x, y, (condition))
239 #define SPRING_CAN_ENTER_FIELD(e, x, y) \
240 ELEMENT_CAN_ENTER_FIELD_BASE_2(e, x, y, 0)
242 #define SPRING_CAN_BUMP_FROM_FIELD(x, y) \
243 (IN_LEV_FIELD(x, y) && (Feld[x][y] == EL_EMC_SPRING_BUMPER || \
244 Feld[x][y] == EL_EMC_SPRING_BUMPER_ACTIVE))
247 #define GROUP_NR(e) ((e) - EL_GROUP_START)
248 #define IS_IN_GROUP(e, nr) (element_info[e].in_group[nr] == TRUE)
249 #define IS_IN_GROUP_EL(e, ge) (IS_IN_GROUP(e, (ge) - EL_GROUP_START))
251 #define IS_EQUAL_OR_IN_GROUP(e, ge) \
252 (IS_GROUP_ELEMENT(ge) ? IS_IN_GROUP(e, GROUP_NR(ge)) : (e) == (ge))
255 #define MOVE_ENTER_EL(e) (element_info[e].move_enter_element)
257 #define CE_ENTER_FIELD_COND(e, x, y) \
258 (!IS_PLAYER(x, y) && \
259 IS_EQUAL_OR_IN_GROUP(Feld[x][y], MOVE_ENTER_EL(e)))
261 #define CUSTOM_ELEMENT_CAN_ENTER_FIELD(e, x, y) \
262 ELEMENT_CAN_ENTER_FIELD_BASE_4(e, x, y, CE_ENTER_FIELD_COND(e, x, y))
264 #define IN_LEV_FIELD_AND_IS_FREE(x, y) (IN_LEV_FIELD(x, y) && IS_FREE(x, y))
265 #define IN_LEV_FIELD_AND_NOT_FREE(x, y) (IN_LEV_FIELD(x, y) && !IS_FREE(x, y))
267 #define ACCESS_FROM(e, d) (element_info[e].access_direction &(d))
268 #define IS_WALKABLE_FROM(e, d) (IS_WALKABLE(e) && ACCESS_FROM(e, d))
269 #define IS_PASSABLE_FROM(e, d) (IS_PASSABLE(e) && ACCESS_FROM(e, d))
270 #define IS_ACCESSIBLE_FROM(e, d) (IS_ACCESSIBLE(e) && ACCESS_FROM(e, d))
272 /* game button identifiers */
273 #define GAME_CTRL_ID_STOP 0
274 #define GAME_CTRL_ID_PAUSE 1
275 #define GAME_CTRL_ID_PLAY 2
276 #define SOUND_CTRL_ID_MUSIC 3
277 #define SOUND_CTRL_ID_LOOPS 4
278 #define SOUND_CTRL_ID_SIMPLE 5
280 #define NUM_GAME_BUTTONS 6
283 /* forward declaration for internal use */
285 static void CreateField(int, int, int);
287 static void SetPlayerWaiting(struct PlayerInfo *, boolean);
288 static void AdvanceFrameAndPlayerCounters(int);
290 static boolean MovePlayerOneStep(struct PlayerInfo *, int, int, int, int);
291 static boolean MovePlayer(struct PlayerInfo *, int, int);
292 static void ScrollPlayer(struct PlayerInfo *, int);
293 static void ScrollScreen(struct PlayerInfo *, int);
295 int DigField(struct PlayerInfo *, int, int, int, int, int, int, int);
297 static void InitBeltMovement(void);
298 static void CloseAllOpenTimegates(void);
299 static void CheckGravityMovement(struct PlayerInfo *);
300 static void CheckGravityMovementWhenNotMoving(struct PlayerInfo *);
301 static void KillPlayerUnlessEnemyProtected(int, int);
302 static void KillPlayerUnlessExplosionProtected(int, int);
304 static void TestIfPlayerTouchesCustomElement(int, int);
305 static void TestIfElementTouchesCustomElement(int, int);
306 static void TestIfElementHitsCustomElement(int, int, int);
308 static void TestIfElementSmashesCustomElement(int, int, int);
311 static void HandleElementChange(int, int, int);
312 static void ExecuteCustomElementAction(int, int, int, int);
313 static boolean ChangeElement(int, int, int, int);
315 static boolean CheckTriggeredElementChangeExt(int, int, int, int, int,int,int);
316 #define CheckTriggeredElementChange(x, y, e, ev) \
317 CheckTriggeredElementChangeExt(x,y,e,ev, CH_PLAYER_ANY,CH_SIDE_ANY, -1)
318 #define CheckTriggeredElementChangeByPlayer(x, y, e, ev, p, s) \
319 CheckTriggeredElementChangeExt(x, y, e, ev, p, s, -1)
320 #define CheckTriggeredElementChangeBySide(x, y, e, ev, s) \
321 CheckTriggeredElementChangeExt(x, y, e, ev, CH_PLAYER_ANY, s, -1)
322 #define CheckTriggeredElementChangeByPage(x, y, e, ev, p) \
323 CheckTriggeredElementChangeExt(x,y,e,ev, CH_PLAYER_ANY, CH_SIDE_ANY, p)
325 static boolean CheckElementChangeExt(int, int, int, int, int, int, int);
326 #define CheckElementChange(x, y, e, te, ev) \
327 CheckElementChangeExt(x, y, e, te, ev, CH_PLAYER_ANY, CH_SIDE_ANY)
328 #define CheckElementChangeByPlayer(x, y, e, ev, p, s) \
329 CheckElementChangeExt(x, y, e, EL_EMPTY, ev, p, s)
330 #define CheckElementChangeBySide(x, y, e, te, ev, s) \
331 CheckElementChangeExt(x, y, e, te, ev, CH_PLAYER_ANY, s)
333 static void PlayLevelSound(int, int, int);
334 static void PlayLevelSoundNearest(int, int, int);
335 static void PlayLevelSoundAction(int, int, int);
336 static void PlayLevelSoundElementAction(int, int, int, int);
337 static void PlayLevelSoundElementActionIfLoop(int, int, int, int);
338 static void PlayLevelSoundActionIfLoop(int, int, int);
339 static void StopLevelSoundActionIfLoop(int, int, int);
340 static void PlayLevelMusic();
342 static void MapGameButtons();
343 static void HandleGameButtons(struct GadgetInfo *);
345 int AmoebeNachbarNr(int, int);
346 void AmoebeUmwandeln(int, int);
347 void ContinueMoving(int, int);
349 void InitMovDir(int, int);
350 void InitAmoebaNr(int, int);
351 int NewHiScore(void);
353 void TestIfGoodThingHitsBadThing(int, int, int);
354 void TestIfBadThingHitsGoodThing(int, int, int);
355 void TestIfPlayerTouchesBadThing(int, int);
356 void TestIfPlayerRunsIntoBadThing(int, int, int);
357 void TestIfBadThingTouchesPlayer(int, int);
358 void TestIfBadThingRunsIntoPlayer(int, int, int);
359 void TestIfFriendTouchesBadThing(int, int);
360 void TestIfBadThingTouchesFriend(int, int);
361 void TestIfBadThingTouchesOtherBadThing(int, int);
363 void KillPlayer(struct PlayerInfo *);
364 void BuryPlayer(struct PlayerInfo *);
365 void RemovePlayer(struct PlayerInfo *);
367 boolean SnapField(struct PlayerInfo *, int, int);
368 boolean DropElement(struct PlayerInfo *);
370 static int getInvisibleActiveFromInvisibleElement(int);
371 static int getInvisibleFromInvisibleActiveElement(int);
373 static struct GadgetInfo *game_gadget[NUM_GAME_BUTTONS];
376 /* ------------------------------------------------------------------------- */
377 /* definition of elements that automatically change to other elements after */
378 /* a specified time, eventually calling a function when changing */
379 /* ------------------------------------------------------------------------- */
381 /* forward declaration for changer functions */
382 static void InitBuggyBase(int, int);
383 static void WarnBuggyBase(int, int);
385 static void InitTrap(int, int);
386 static void ActivateTrap(int, int);
387 static void ChangeActiveTrap(int, int);
389 static void InitRobotWheel(int, int);
390 static void RunRobotWheel(int, int);
391 static void StopRobotWheel(int, int);
393 static void InitTimegateWheel(int, int);
394 static void RunTimegateWheel(int, int);
396 static void InitMagicBallDelay(int, int);
397 static void ActivateMagicBall(int, int);
399 static void InitDiagonalMovingElement(int, int);
401 struct ChangingElementInfo
406 void (*pre_change_function)(int x, int y);
407 void (*change_function)(int x, int y);
408 void (*post_change_function)(int x, int y);
411 static struct ChangingElementInfo change_delay_list[] =
462 EL_SWITCHGATE_OPENING,
470 EL_SWITCHGATE_CLOSING,
471 EL_SWITCHGATE_CLOSED,
503 EL_ACID_SPLASH_RIGHT,
512 EL_SP_BUGGY_BASE_ACTIVATING,
519 EL_SP_BUGGY_BASE_ACTIVATING,
520 EL_SP_BUGGY_BASE_ACTIVE,
527 EL_SP_BUGGY_BASE_ACTIVE,
551 EL_ROBOT_WHEEL_ACTIVE,
559 EL_TIMEGATE_SWITCH_ACTIVE,
567 EL_EMC_MAGIC_BALL_ACTIVE,
568 EL_EMC_MAGIC_BALL_ACTIVE,
575 EL_EMC_SPRING_BUMPER_ACTIVE,
576 EL_EMC_SPRING_BUMPER,
583 EL_DIAGONAL_SHRINKING,
596 InitDiagonalMovingElement
612 int push_delay_fixed, push_delay_random;
617 { EL_BALLOON, 0, 0 },
619 { EL_SOKOBAN_OBJECT, 2, 0 },
620 { EL_SOKOBAN_FIELD_FULL, 2, 0 },
621 { EL_SATELLITE, 2, 0 },
622 { EL_SP_DISK_YELLOW, 2, 0 },
624 { EL_UNDEFINED, 0, 0 },
632 move_stepsize_list[] =
634 { EL_AMOEBA_DROP, 2 },
635 { EL_AMOEBA_DROPPING, 2 },
636 { EL_QUICKSAND_FILLING, 1 },
637 { EL_QUICKSAND_EMPTYING, 1 },
638 { EL_MAGIC_WALL_FILLING, 2 },
639 { EL_BD_MAGIC_WALL_FILLING, 2 },
640 { EL_MAGIC_WALL_EMPTYING, 2 },
641 { EL_BD_MAGIC_WALL_EMPTYING, 2 },
651 collect_count_list[] =
654 { EL_BD_DIAMOND, 1 },
655 { EL_EMERALD_YELLOW, 1 },
656 { EL_EMERALD_RED, 1 },
657 { EL_EMERALD_PURPLE, 1 },
659 { EL_SP_INFOTRON, 1 },
671 access_direction_list[] =
673 { EL_TUBE_ANY, MV_LEFT | MV_RIGHT | MV_UP | MV_DOWN },
674 { EL_TUBE_VERTICAL, MV_UP | MV_DOWN },
675 { EL_TUBE_HORIZONTAL, MV_LEFT | MV_RIGHT },
676 { EL_TUBE_VERTICAL_LEFT, MV_LEFT | MV_UP | MV_DOWN },
677 { EL_TUBE_VERTICAL_RIGHT, MV_RIGHT | MV_UP | MV_DOWN },
678 { EL_TUBE_HORIZONTAL_UP, MV_LEFT | MV_RIGHT | MV_UP },
679 { EL_TUBE_HORIZONTAL_DOWN, MV_LEFT | MV_RIGHT | MV_DOWN },
680 { EL_TUBE_LEFT_UP, MV_LEFT | MV_UP },
681 { EL_TUBE_LEFT_DOWN, MV_LEFT | MV_DOWN },
682 { EL_TUBE_RIGHT_UP, MV_RIGHT | MV_UP },
683 { EL_TUBE_RIGHT_DOWN, MV_RIGHT | MV_DOWN },
685 { EL_SP_PORT_LEFT, MV_RIGHT },
686 { EL_SP_PORT_RIGHT, MV_LEFT },
687 { EL_SP_PORT_UP, MV_DOWN },
688 { EL_SP_PORT_DOWN, MV_UP },
689 { EL_SP_PORT_HORIZONTAL, MV_LEFT | MV_RIGHT },
690 { EL_SP_PORT_VERTICAL, MV_UP | MV_DOWN },
691 { EL_SP_PORT_ANY, MV_LEFT | MV_RIGHT | MV_UP | MV_DOWN },
692 { EL_SP_GRAVITY_PORT_LEFT, MV_RIGHT },
693 { EL_SP_GRAVITY_PORT_RIGHT, MV_LEFT },
694 { EL_SP_GRAVITY_PORT_UP, MV_DOWN },
695 { EL_SP_GRAVITY_PORT_DOWN, MV_UP },
696 { EL_SP_GRAVITY_ON_PORT_LEFT, MV_RIGHT },
697 { EL_SP_GRAVITY_ON_PORT_RIGHT, MV_LEFT },
698 { EL_SP_GRAVITY_ON_PORT_UP, MV_DOWN },
699 { EL_SP_GRAVITY_ON_PORT_DOWN, MV_UP },
700 { EL_SP_GRAVITY_OFF_PORT_LEFT, MV_RIGHT },
701 { EL_SP_GRAVITY_OFF_PORT_RIGHT, MV_LEFT },
702 { EL_SP_GRAVITY_OFF_PORT_UP, MV_DOWN },
703 { EL_SP_GRAVITY_OFF_PORT_DOWN, MV_UP },
705 { EL_UNDEFINED, MV_NONE }
708 static boolean trigger_events[MAX_NUM_ELEMENTS][NUM_CHANGE_EVENTS];
710 #define IS_AUTO_CHANGING(e) (element_info[e].has_change_event[CE_DELAY])
711 #define IS_JUST_CHANGING(x, y) (ChangeDelay[x][y] != 0)
712 #define IS_CHANGING(x, y) (IS_AUTO_CHANGING(Feld[x][y]) || \
713 IS_JUST_CHANGING(x, y))
715 #define CE_PAGE(e, ce) (element_info[e].event_page[ce])
717 /* static variables for playfield scan mode (scanning forward or backward) */
718 static int playfield_scan_start_x = 0;
719 static int playfield_scan_start_y = 0;
720 static int playfield_scan_delta_x = 1;
721 static int playfield_scan_delta_y = 1;
723 #define SCAN_PLAYFIELD(x, y) for ((y) = playfield_scan_start_y; \
724 (y) >= 0 && (y) <= lev_fieldy - 1; \
725 (y) += playfield_scan_delta_y) \
726 for ((x) = playfield_scan_start_x; \
727 (x) >= 0 && (x) <= lev_fieldx - 1; \
728 (x) += playfield_scan_delta_x) \
731 void DEBUG_SetMaximumDynamite()
735 for (i = 0; i < MAX_INVENTORY_SIZE; i++)
736 if (local_player->inventory_size < MAX_INVENTORY_SIZE)
737 local_player->inventory_element[local_player->inventory_size++] =
742 static void InitPlayfieldScanModeVars()
744 if (game.use_reverse_scan_direction)
746 playfield_scan_start_x = lev_fieldx - 1;
747 playfield_scan_start_y = lev_fieldy - 1;
749 playfield_scan_delta_x = -1;
750 playfield_scan_delta_y = -1;
754 playfield_scan_start_x = 0;
755 playfield_scan_start_y = 0;
757 playfield_scan_delta_x = 1;
758 playfield_scan_delta_y = 1;
762 static void InitPlayfieldScanMode(int mode)
764 game.use_reverse_scan_direction =
765 (mode == CA_ARG_SCAN_MODE_REVERSE ? TRUE : FALSE);
767 InitPlayfieldScanModeVars();
770 static int get_move_delay_from_stepsize(int move_stepsize)
773 MIN(MAX(MOVE_STEPSIZE_MIN, move_stepsize), MOVE_STEPSIZE_MAX);
775 /* make sure that stepsize value is always a power of 2 */
776 move_stepsize = (1 << log_2(move_stepsize));
778 return TILEX / move_stepsize;
781 static void SetPlayerMoveSpeed(struct PlayerInfo *player, int move_stepsize,
784 int player_nr = player->index_nr;
785 int move_delay = get_move_delay_from_stepsize(move_stepsize);
786 boolean cannot_move = (move_stepsize == STEPSIZE_NOT_MOVING ? TRUE : FALSE);
788 /* do no immediately change move delay -- the player might just be moving */
789 player->move_delay_value_next = move_delay;
791 /* information if player can move must be set separately */
792 player->cannot_move = cannot_move;
796 player->move_delay = game.initial_move_delay[player_nr];
797 player->move_delay_value = game.initial_move_delay_value[player_nr];
799 player->move_delay_value_next = -1;
801 player->move_delay_reset_counter = 0;
805 void GetPlayerConfig()
807 if (!audio.sound_available)
808 setup.sound_simple = FALSE;
810 if (!audio.loops_available)
811 setup.sound_loops = FALSE;
813 if (!audio.music_available)
814 setup.sound_music = FALSE;
816 if (!video.fullscreen_available)
817 setup.fullscreen = FALSE;
819 setup.sound = (setup.sound_simple || setup.sound_loops || setup.sound_music);
821 SetAudioMode(setup.sound);
825 static int getBeltNrFromBeltElement(int element)
827 return (element < EL_CONVEYOR_BELT_2_LEFT ? 0 :
828 element < EL_CONVEYOR_BELT_3_LEFT ? 1 :
829 element < EL_CONVEYOR_BELT_4_LEFT ? 2 : 3);
832 static int getBeltNrFromBeltActiveElement(int element)
834 return (element < EL_CONVEYOR_BELT_2_LEFT_ACTIVE ? 0 :
835 element < EL_CONVEYOR_BELT_3_LEFT_ACTIVE ? 1 :
836 element < EL_CONVEYOR_BELT_4_LEFT_ACTIVE ? 2 : 3);
839 static int getBeltNrFromBeltSwitchElement(int element)
841 return (element < EL_CONVEYOR_BELT_2_SWITCH_LEFT ? 0 :
842 element < EL_CONVEYOR_BELT_3_SWITCH_LEFT ? 1 :
843 element < EL_CONVEYOR_BELT_4_SWITCH_LEFT ? 2 : 3);
846 static int getBeltDirNrFromBeltSwitchElement(int element)
848 static int belt_base_element[4] =
850 EL_CONVEYOR_BELT_1_SWITCH_LEFT,
851 EL_CONVEYOR_BELT_2_SWITCH_LEFT,
852 EL_CONVEYOR_BELT_3_SWITCH_LEFT,
853 EL_CONVEYOR_BELT_4_SWITCH_LEFT
856 int belt_nr = getBeltNrFromBeltSwitchElement(element);
857 int belt_dir_nr = element - belt_base_element[belt_nr];
859 return (belt_dir_nr % 3);
862 static int getBeltDirFromBeltSwitchElement(int element)
864 static int belt_move_dir[3] =
871 int belt_dir_nr = getBeltDirNrFromBeltSwitchElement(element);
873 return belt_move_dir[belt_dir_nr];
876 static int get_element_from_group_element(int element)
878 if (IS_GROUP_ELEMENT(element))
880 struct ElementGroupInfo *group = element_info[element].group;
881 int last_anim_random_frame = gfx.anim_random_frame;
884 if (group->choice_mode == ANIM_RANDOM)
885 gfx.anim_random_frame = RND(group->num_elements_resolved);
887 element_pos = getAnimationFrame(group->num_elements_resolved, 1,
888 group->choice_mode, 0,
891 if (group->choice_mode == ANIM_RANDOM)
892 gfx.anim_random_frame = last_anim_random_frame;
896 element = group->element_resolved[element_pos];
902 static void InitPlayerField(int x, int y, int element, boolean init_game)
904 if (element == EL_SP_MURPHY)
908 if (stored_player[0].present)
910 Feld[x][y] = EL_SP_MURPHY_CLONE;
916 stored_player[0].use_murphy = TRUE;
918 if (!level.use_artwork_element[0])
919 stored_player[0].artwork_element = EL_SP_MURPHY;
922 Feld[x][y] = EL_PLAYER_1;
928 struct PlayerInfo *player = &stored_player[Feld[x][y] - EL_PLAYER_1];
929 int jx = player->jx, jy = player->jy;
931 player->present = TRUE;
933 player->block_last_field = (element == EL_SP_MURPHY ?
934 level.sp_block_last_field :
935 level.block_last_field);
937 /* ---------- initialize player's last field block delay --------------- */
939 /* always start with reliable default value (no adjustment needed) */
940 player->block_delay_adjustment = 0;
942 /* special case 1: in Supaplex, Murphy blocks last field one more frame */
943 if (player->block_last_field && element == EL_SP_MURPHY)
944 player->block_delay_adjustment = 1;
946 /* special case 2: in game engines before 3.1.1, blocking was different */
947 if (game.use_block_last_field_bug)
948 player->block_delay_adjustment = (player->block_last_field ? -1 : 1);
950 if (!options.network || player->connected)
952 player->active = TRUE;
954 /* remove potentially duplicate players */
955 if (StorePlayer[jx][jy] == Feld[x][y])
956 StorePlayer[jx][jy] = 0;
958 StorePlayer[x][y] = Feld[x][y];
962 printf("Player %d activated.\n", player->element_nr);
963 printf("[Local player is %d and currently %s.]\n",
964 local_player->element_nr,
965 local_player->active ? "active" : "not active");
969 Feld[x][y] = EL_EMPTY;
971 player->jx = player->last_jx = x;
972 player->jy = player->last_jy = y;
976 static void InitField(int x, int y, boolean init_game)
978 int element = Feld[x][y];
987 InitPlayerField(x, y, element, init_game);
990 case EL_SOKOBAN_FIELD_PLAYER:
991 element = Feld[x][y] = EL_PLAYER_1;
992 InitField(x, y, init_game);
994 element = Feld[x][y] = EL_SOKOBAN_FIELD_EMPTY;
995 InitField(x, y, init_game);
998 case EL_SOKOBAN_FIELD_EMPTY:
999 local_player->sokobanfields_still_needed++;
1003 if (x < lev_fieldx-1 && Feld[x+1][y] == EL_ACID)
1004 Feld[x][y] = EL_ACID_POOL_TOPLEFT;
1005 else if (x > 0 && Feld[x-1][y] == EL_ACID)
1006 Feld[x][y] = EL_ACID_POOL_TOPRIGHT;
1007 else if (y > 0 && Feld[x][y-1] == EL_ACID_POOL_TOPLEFT)
1008 Feld[x][y] = EL_ACID_POOL_BOTTOMLEFT;
1009 else if (y > 0 && Feld[x][y-1] == EL_ACID)
1010 Feld[x][y] = EL_ACID_POOL_BOTTOM;
1011 else if (y > 0 && Feld[x][y-1] == EL_ACID_POOL_TOPRIGHT)
1012 Feld[x][y] = EL_ACID_POOL_BOTTOMRIGHT;
1021 case EL_SPACESHIP_RIGHT:
1022 case EL_SPACESHIP_UP:
1023 case EL_SPACESHIP_LEFT:
1024 case EL_SPACESHIP_DOWN:
1025 case EL_BD_BUTTERFLY:
1026 case EL_BD_BUTTERFLY_RIGHT:
1027 case EL_BD_BUTTERFLY_UP:
1028 case EL_BD_BUTTERFLY_LEFT:
1029 case EL_BD_BUTTERFLY_DOWN:
1031 case EL_BD_FIREFLY_RIGHT:
1032 case EL_BD_FIREFLY_UP:
1033 case EL_BD_FIREFLY_LEFT:
1034 case EL_BD_FIREFLY_DOWN:
1035 case EL_PACMAN_RIGHT:
1037 case EL_PACMAN_LEFT:
1038 case EL_PACMAN_DOWN:
1040 case EL_YAMYAM_LEFT:
1041 case EL_YAMYAM_RIGHT:
1043 case EL_YAMYAM_DOWN:
1044 case EL_DARK_YAMYAM:
1047 case EL_SP_SNIKSNAK:
1048 case EL_SP_ELECTRON:
1057 case EL_AMOEBA_FULL:
1062 case EL_AMOEBA_DROP:
1063 if (y == lev_fieldy - 1)
1065 Feld[x][y] = EL_AMOEBA_GROWING;
1066 Store[x][y] = EL_AMOEBA_WET;
1070 case EL_DYNAMITE_ACTIVE:
1071 case EL_SP_DISK_RED_ACTIVE:
1072 case EL_DYNABOMB_PLAYER_1_ACTIVE:
1073 case EL_DYNABOMB_PLAYER_2_ACTIVE:
1074 case EL_DYNABOMB_PLAYER_3_ACTIVE:
1075 case EL_DYNABOMB_PLAYER_4_ACTIVE:
1076 MovDelay[x][y] = 96;
1079 case EL_EM_DYNAMITE_ACTIVE:
1080 MovDelay[x][y] = 32;
1084 local_player->lights_still_needed++;
1088 local_player->friends_still_needed++;
1093 GfxDir[x][y] = MovDir[x][y] = 1 << RND(4);
1096 case EL_CONVEYOR_BELT_1_SWITCH_LEFT:
1097 case EL_CONVEYOR_BELT_1_SWITCH_MIDDLE:
1098 case EL_CONVEYOR_BELT_1_SWITCH_RIGHT:
1099 case EL_CONVEYOR_BELT_2_SWITCH_LEFT:
1100 case EL_CONVEYOR_BELT_2_SWITCH_MIDDLE:
1101 case EL_CONVEYOR_BELT_2_SWITCH_RIGHT:
1102 case EL_CONVEYOR_BELT_3_SWITCH_LEFT:
1103 case EL_CONVEYOR_BELT_3_SWITCH_MIDDLE:
1104 case EL_CONVEYOR_BELT_3_SWITCH_RIGHT:
1105 case EL_CONVEYOR_BELT_4_SWITCH_LEFT:
1106 case EL_CONVEYOR_BELT_4_SWITCH_MIDDLE:
1107 case EL_CONVEYOR_BELT_4_SWITCH_RIGHT:
1110 int belt_nr = getBeltNrFromBeltSwitchElement(Feld[x][y]);
1111 int belt_dir = getBeltDirFromBeltSwitchElement(Feld[x][y]);
1112 int belt_dir_nr = getBeltDirNrFromBeltSwitchElement(Feld[x][y]);
1114 if (game.belt_dir_nr[belt_nr] == 3) /* initial value */
1116 game.belt_dir[belt_nr] = belt_dir;
1117 game.belt_dir_nr[belt_nr] = belt_dir_nr;
1119 else /* more than one switch -- set it like the first switch */
1121 Feld[x][y] = Feld[x][y] - belt_dir_nr + game.belt_dir_nr[belt_nr];
1126 #if !USE_BOTH_SWITCHGATE_SWITCHES
1127 case EL_SWITCHGATE_SWITCH_DOWN: /* always start with same switch pos */
1129 Feld[x][y] = EL_SWITCHGATE_SWITCH_UP;
1133 case EL_LIGHT_SWITCH_ACTIVE:
1135 game.light_time_left = level.time_light * FRAMES_PER_SECOND;
1138 case EL_INVISIBLE_STEELWALL:
1139 case EL_INVISIBLE_WALL:
1140 case EL_INVISIBLE_SAND:
1141 if (game.light_time_left > 0 ||
1142 game.lenses_time_left > 0)
1143 Feld[x][y] = getInvisibleActiveFromInvisibleElement(element);
1146 case EL_EMC_MAGIC_BALL:
1147 if (game.ball_state)
1148 Feld[x][y] = EL_EMC_MAGIC_BALL_ACTIVE;
1151 case EL_EMC_MAGIC_BALL_SWITCH:
1152 if (game.ball_state)
1153 Feld[x][y] = EL_EMC_MAGIC_BALL_SWITCH_ACTIVE;
1158 if (IS_CUSTOM_ELEMENT(element))
1160 if (CAN_MOVE(element))
1163 #if USE_NEW_CUSTOM_VALUE
1164 if (!element_info[element].use_last_ce_value || init_game)
1165 CustomValue[x][y] = GET_NEW_CE_VALUE(Feld[x][y]);
1169 if (IS_CUSTOM_ELEMENT(element) && CAN_MOVE(element))
1172 else if (IS_GROUP_ELEMENT(element))
1175 Feld[x][y] = get_element_from_group_element(element);
1177 InitField(x, y, init_game);
1179 struct ElementGroupInfo *group = element_info[element].group;
1180 int last_anim_random_frame = gfx.anim_random_frame;
1183 if (group->choice_mode == ANIM_RANDOM)
1184 gfx.anim_random_frame = RND(group->num_elements_resolved);
1186 element_pos = getAnimationFrame(group->num_elements_resolved, 1,
1187 group->choice_mode, 0,
1190 if (group->choice_mode == ANIM_RANDOM)
1191 gfx.anim_random_frame = last_anim_random_frame;
1193 group->choice_pos++;
1195 Feld[x][y] = group->element_resolved[element_pos];
1197 InitField(x, y, init_game);
1205 CheckTriggeredElementChange(x, y, element, CE_CREATION_OF_X);
1210 #if USE_NEW_CUSTOM_VALUE
1213 CustomValue[x][y] = GET_NEW_CE_VALUE(Feld[x][y]);
1215 CustomValue[x][y] = element_info[Feld[x][y]].custom_value_initial;
1223 static inline void InitField_WithBug1(int x, int y, boolean init_game)
1225 InitField(x, y, init_game);
1227 /* not needed to call InitMovDir() -- already done by InitField()! */
1228 if (game.engine_version < VERSION_IDENT(3,1,0,0) &&
1229 CAN_MOVE(Feld[x][y]))
1233 static inline void InitField_WithBug2(int x, int y, boolean init_game)
1235 int old_element = Feld[x][y];
1237 InitField(x, y, init_game);
1239 /* not needed to call InitMovDir() -- already done by InitField()! */
1240 if (game.engine_version < VERSION_IDENT(3,1,0,0) &&
1241 CAN_MOVE(old_element) &&
1242 (old_element < EL_MOLE_LEFT || old_element > EL_MOLE_DOWN))
1245 /* this case is in fact a combination of not less than three bugs:
1246 first, it calls InitMovDir() for elements that can move, although this is
1247 already done by InitField(); then, it checks the element that was at this
1248 field _before_ the call to InitField() (which can change it); lastly, it
1249 was not called for "mole with direction" elements, which were treated as
1250 "cannot move" due to (fixed) wrong element initialization in "src/init.c"
1254 inline void DrawGameValue_Emeralds(int value)
1256 int xpos = (3 * 14 - 3 * getFontWidth(FONT_TEXT_2)) / 2;
1258 DrawText(DX_EMERALDS + xpos, DY_EMERALDS, int2str(value, 3), FONT_TEXT_2);
1261 inline void DrawGameValue_Dynamite(int value)
1263 int xpos = (3 * 14 - 3 * getFontWidth(FONT_TEXT_2)) / 2;
1265 DrawText(DX_DYNAMITE + xpos, DY_DYNAMITE, int2str(value, 3), FONT_TEXT_2);
1268 inline void DrawGameValue_Keys(int key[MAX_NUM_KEYS])
1270 int base_key_graphic = EL_KEY_1;
1273 if (level.game_engine_type == GAME_ENGINE_TYPE_EM)
1274 base_key_graphic = EL_EM_KEY_1;
1276 /* currently only 4 of 8 possible keys are displayed */
1277 for (i = 0; i < STD_NUM_KEYS; i++)
1280 DrawMiniGraphicExt(drawto, DX_KEYS + i * MINI_TILEX, DY_KEYS,
1281 el2edimg(base_key_graphic + i));
1283 BlitBitmap(graphic_info[IMG_GLOBAL_DOOR].bitmap, drawto,
1284 DOOR_GFX_PAGEX5 + XX_KEYS + i * MINI_TILEX, YY_KEYS,
1285 MINI_TILEX, MINI_TILEY, DX_KEYS + i * MINI_TILEX, DY_KEYS);
1289 inline void DrawGameValue_Score(int value)
1291 int xpos = (5 * 14 - 5 * getFontWidth(FONT_TEXT_2)) / 2;
1293 DrawText(DX_SCORE + xpos, DY_SCORE, int2str(value, 5), FONT_TEXT_2);
1296 inline void DrawGameValue_Time(int value)
1298 int xpos3 = (3 * 14 - 3 * getFontWidth(FONT_TEXT_2)) / 2;
1299 int xpos4 = (4 * 10 - 4 * getFontWidth(FONT_LEVEL_NUMBER)) / 2;
1301 /* clear background if value just changed its size */
1302 if (value == 999 || value == 1000)
1303 ClearRectangle(drawto, DX_TIME1, DY_TIME, 14 * 3, 14);
1306 DrawText(DX_TIME1 + xpos3, DY_TIME, int2str(value, 3), FONT_TEXT_2);
1308 DrawText(DX_TIME2 + xpos4, DY_TIME, int2str(value, 4), FONT_LEVEL_NUMBER);
1311 inline void DrawGameValue_Level(int value)
1314 DrawText(DX_LEVEL, DY_LEVEL, int2str(value, 2), FONT_TEXT_2);
1317 /* misuse area for displaying emeralds to draw bigger level number */
1318 DrawTextExt(drawto, DX_EMERALDS, DY_EMERALDS,
1319 int2str(value, 3), FONT_LEVEL_NUMBER, BLIT_OPAQUE);
1321 /* now copy it to the area for displaying level number */
1322 BlitBitmap(drawto, drawto,
1323 DX_EMERALDS, DY_EMERALDS + 1,
1324 getFontWidth(FONT_LEVEL_NUMBER) * 3,
1325 getFontHeight(FONT_LEVEL_NUMBER) - 1,
1326 DX_LEVEL - 1, DY_LEVEL + 1);
1328 /* restore the area for displaying emeralds */
1329 DrawGameValue_Emeralds(local_player->gems_still_needed);
1331 /* yes, this is all really ugly :-) */
1335 void DrawAllGameValues(int emeralds, int dynamite, int score, int time,
1338 int key[MAX_NUM_KEYS];
1341 for (i = 0; i < MAX_NUM_KEYS; i++)
1342 key[i] = key_bits & (1 << i);
1344 DrawGameValue_Level(level_nr);
1346 DrawGameValue_Emeralds(emeralds);
1347 DrawGameValue_Dynamite(dynamite);
1348 DrawGameValue_Score(score);
1349 DrawGameValue_Time(time);
1351 DrawGameValue_Keys(key);
1354 void DrawGameDoorValues()
1356 int dynamite_state = 0;
1360 if (level.game_engine_type == GAME_ENGINE_TYPE_EM)
1362 DrawGameDoorValues_EM();
1368 DrawGameValue_Level(level_nr);
1370 DrawGameValue_Emeralds(local_player->gems_still_needed);
1371 DrawGameValue_Dynamite(local_player->inventory_size);
1372 DrawGameValue_Score(local_player->score);
1373 DrawGameValue_Time(TimeLeft);
1377 if (game.centered_player_nr == -1)
1379 for (i = 0; i < MAX_PLAYERS; i++)
1381 for (j = 0; j < MAX_NUM_KEYS; j++)
1382 if (stored_player[i].key[j])
1383 key_bits |= (1 << j);
1385 dynamite_state += stored_player[i].inventory_size;
1389 DrawGameValue_Keys(stored_player[i].key);
1394 int player_nr = game.centered_player_nr;
1396 for (i = 0; i < MAX_NUM_KEYS; i++)
1397 if (stored_player[player_nr].key[i])
1398 key_bits |= (1 << i);
1400 dynamite_state = stored_player[player_nr].inventory_size;
1403 DrawAllGameValues(local_player->gems_still_needed, dynamite_state,
1404 local_player->score, TimeLeft, key_bits);
1409 static void resolve_group_element(int group_element, int recursion_depth)
1411 static int group_nr;
1412 static struct ElementGroupInfo *group;
1413 struct ElementGroupInfo *actual_group = element_info[group_element].group;
1416 if (recursion_depth > NUM_GROUP_ELEMENTS) /* recursion too deep */
1418 Error(ERR_WARN, "recursion too deep when resolving group element %d",
1419 group_element - EL_GROUP_START + 1);
1421 /* replace element which caused too deep recursion by question mark */
1422 group->element_resolved[group->num_elements_resolved++] = EL_UNKNOWN;
1427 if (recursion_depth == 0) /* initialization */
1429 group = element_info[group_element].group;
1430 group_nr = group_element - EL_GROUP_START;
1432 group->num_elements_resolved = 0;
1433 group->choice_pos = 0;
1436 for (i = 0; i < actual_group->num_elements; i++)
1438 int element = actual_group->element[i];
1440 if (group->num_elements_resolved == NUM_FILE_ELEMENTS)
1443 if (IS_GROUP_ELEMENT(element))
1444 resolve_group_element(element, recursion_depth + 1);
1447 group->element_resolved[group->num_elements_resolved++] = element;
1448 element_info[element].in_group[group_nr] = TRUE;
1455 =============================================================================
1457 -----------------------------------------------------------------------------
1458 initialize game engine due to level / tape version number
1459 =============================================================================
1462 static void InitGameEngine()
1464 int i, j, k, l, x, y;
1466 /* set game engine from tape file when re-playing, else from level file */
1467 game.engine_version = (tape.playing ? tape.engine_version :
1468 level.game_version);
1470 /* ---------------------------------------------------------------------- */
1471 /* set flags for bugs and changes according to active game engine version */
1472 /* ---------------------------------------------------------------------- */
1475 Summary of bugfix/change:
1476 Fixed handling for custom elements that change when pushed by the player.
1478 Fixed/changed in version:
1482 Before 3.1.0, custom elements that "change when pushing" changed directly
1483 after the player started pushing them (until then handled in "DigField()").
1484 Since 3.1.0, these custom elements are not changed until the "pushing"
1485 move of the element is finished (now handled in "ContinueMoving()").
1487 Affected levels/tapes:
1488 The first condition is generally needed for all levels/tapes before version
1489 3.1.0, which might use the old behaviour before it was changed; known tapes
1490 that are affected are some tapes from the level set "Walpurgis Gardens" by
1492 The second condition is an exception from the above case and is needed for
1493 the special case of tapes recorded with game (not engine!) version 3.1.0 or
1494 above (including some development versions of 3.1.0), but before it was
1495 known that this change would break tapes like the above and was fixed in
1496 3.1.1, so that the changed behaviour was active although the engine version
1497 while recording maybe was before 3.1.0. There is at least one tape that is
1498 affected by this exception, which is the tape for the one-level set "Bug
1499 Machine" by Juergen Bonhagen.
1502 game.use_change_when_pushing_bug =
1503 (game.engine_version < VERSION_IDENT(3,1,0,0) &&
1505 tape.game_version >= VERSION_IDENT(3,1,0,0) &&
1506 tape.game_version < VERSION_IDENT(3,1,1,0)));
1509 Summary of bugfix/change:
1510 Fixed handling for blocking the field the player leaves when moving.
1512 Fixed/changed in version:
1516 Before 3.1.1, when "block last field when moving" was enabled, the field
1517 the player is leaving when moving was blocked for the time of the move,
1518 and was directly unblocked afterwards. This resulted in the last field
1519 being blocked for exactly one less than the number of frames of one player
1520 move. Additionally, even when blocking was disabled, the last field was
1521 blocked for exactly one frame.
1522 Since 3.1.1, due to changes in player movement handling, the last field
1523 is not blocked at all when blocking is disabled. When blocking is enabled,
1524 the last field is blocked for exactly the number of frames of one player
1525 move. Additionally, if the player is Murphy, the hero of Supaplex, the
1526 last field is blocked for exactly one more than the number of frames of
1529 Affected levels/tapes:
1530 (!!! yet to be determined -- probably many !!!)
1533 game.use_block_last_field_bug =
1534 (game.engine_version < VERSION_IDENT(3,1,1,0));
1537 Summary of bugfix/change:
1538 Changed behaviour of CE changes with multiple changes per single frame.
1540 Fixed/changed in version:
1544 Before 3.2.0-6, only one single CE change was allowed in each engine frame.
1545 This resulted in race conditions where CEs seem to behave strange in some
1546 situations (where triggered CE changes were just skipped because there was
1547 already a CE change on that tile in the playfield in that engine frame).
1548 Since 3.2.0-6, this was changed to allow up to MAX_NUM_CHANGES_PER_FRAME.
1549 (The number of changes per frame must be limited in any case, because else
1550 it is easily possible to define CE changes that would result in an infinite
1551 loop, causing the whole game to freeze. The MAX_NUM_CHANGES_PER_FRAME value
1552 should be set large enough so that it would only be reached in cases where
1553 the corresponding CE change conditions run into a loop. Therefore, it seems
1554 to be reasonable to set MAX_NUM_CHANGES_PER_FRAME to the same value as the
1555 maximal number of change pages for custom elements.)
1557 Affected levels/tapes:
1561 #if USE_ONLY_ONE_CHANGE_PER_FRAME
1562 game.max_num_changes_per_frame = 1;
1564 game.max_num_changes_per_frame =
1565 (game.engine_version < VERSION_IDENT(3,2,0,6) ? 1 : 32);
1568 /* ---------------------------------------------------------------------- */
1570 /* default scan direction: scan playfield from top/left to bottom/right */
1571 InitPlayfieldScanMode(CA_ARG_SCAN_MODE_NORMAL);
1573 /* dynamically adjust element properties according to game engine version */
1574 InitElementPropertiesEngine(game.engine_version);
1577 printf("level %d: level version == %06d\n", level_nr, level.game_version);
1578 printf(" tape version == %06d [%s] [file: %06d]\n",
1579 tape.engine_version, (tape.playing ? "PLAYING" : "RECORDING"),
1581 printf(" => game.engine_version == %06d\n", game.engine_version);
1585 /* ---------- recursively resolve group elements ------------------------- */
1587 for (i = 0; i < MAX_NUM_ELEMENTS; i++)
1588 for (j = 0; j < NUM_GROUP_ELEMENTS; j++)
1589 element_info[i].in_group[j] = FALSE;
1591 for (i = 0; i < NUM_GROUP_ELEMENTS; i++)
1592 resolve_group_element(EL_GROUP_START + i, 0);
1595 /* ---------- initialize player's initial move delay --------------------- */
1598 /* dynamically adjust player properties according to level information */
1599 for (i = 0; i < MAX_PLAYERS; i++)
1600 game.initial_move_delay_value[i] =
1601 get_move_delay_from_stepsize(level.initial_player_stepsize[i]);
1603 /* dynamically adjust player properties according to level information */
1604 game.initial_move_delay_value =
1605 (level.double_speed ? MOVE_DELAY_HIGH_SPEED : MOVE_DELAY_NORMAL_SPEED);
1608 /* dynamically adjust player properties according to game engine version */
1609 for (i = 0; i < MAX_PLAYERS; i++)
1610 game.initial_move_delay[i] =
1611 (game.engine_version <= VERSION_IDENT(2,0,1,0) ?
1612 game.initial_move_delay_value[i] : 0);
1614 /* ---------- initialize player's initial push delay --------------------- */
1616 /* dynamically adjust player properties according to game engine version */
1617 game.initial_push_delay_value =
1618 (game.engine_version < VERSION_IDENT(3,0,7,1) ? 5 : -1);
1620 /* ---------- initialize changing elements ------------------------------- */
1622 /* initialize changing elements information */
1623 for (i = 0; i < MAX_NUM_ELEMENTS; i++)
1625 struct ElementInfo *ei = &element_info[i];
1627 /* this pointer might have been changed in the level editor */
1628 ei->change = &ei->change_page[0];
1630 if (!IS_CUSTOM_ELEMENT(i))
1632 ei->change->target_element = EL_EMPTY_SPACE;
1633 ei->change->delay_fixed = 0;
1634 ei->change->delay_random = 0;
1635 ei->change->delay_frames = 1;
1638 for (j = 0; j < NUM_CHANGE_EVENTS; j++)
1640 ei->has_change_event[j] = FALSE;
1642 ei->event_page_nr[j] = 0;
1643 ei->event_page[j] = &ei->change_page[0];
1647 /* add changing elements from pre-defined list */
1648 for (i = 0; change_delay_list[i].element != EL_UNDEFINED; i++)
1650 struct ChangingElementInfo *ch_delay = &change_delay_list[i];
1651 struct ElementInfo *ei = &element_info[ch_delay->element];
1653 ei->change->target_element = ch_delay->target_element;
1654 ei->change->delay_fixed = ch_delay->change_delay;
1656 ei->change->pre_change_function = ch_delay->pre_change_function;
1657 ei->change->change_function = ch_delay->change_function;
1658 ei->change->post_change_function = ch_delay->post_change_function;
1660 ei->change->can_change = TRUE;
1661 ei->change->can_change_or_has_action = TRUE;
1663 ei->has_change_event[CE_DELAY] = TRUE;
1665 SET_PROPERTY(ch_delay->element, EP_CAN_CHANGE, TRUE);
1666 SET_PROPERTY(ch_delay->element, EP_CAN_CHANGE_OR_HAS_ACTION, TRUE);
1669 /* ---------- initialize internal run-time variables ------------- */
1671 for (i = 0; i < NUM_CUSTOM_ELEMENTS; i++)
1673 struct ElementInfo *ei = &element_info[EL_CUSTOM_START + i];
1675 for (j = 0; j < ei->num_change_pages; j++)
1677 ei->change_page[j].can_change_or_has_action =
1678 (ei->change_page[j].can_change |
1679 ei->change_page[j].has_action);
1683 /* add change events from custom element configuration */
1684 for (i = 0; i < NUM_CUSTOM_ELEMENTS; i++)
1686 struct ElementInfo *ei = &element_info[EL_CUSTOM_START + i];
1688 for (j = 0; j < ei->num_change_pages; j++)
1690 if (!ei->change_page[j].can_change_or_has_action)
1693 for (k = 0; k < NUM_CHANGE_EVENTS; k++)
1695 /* only add event page for the first page found with this event */
1696 if (ei->change_page[j].has_event[k] && !(ei->has_change_event[k]))
1698 ei->has_change_event[k] = TRUE;
1700 ei->event_page_nr[k] = j;
1701 ei->event_page[k] = &ei->change_page[j];
1707 /* ---------- initialize run-time trigger player and element ------------- */
1709 for (i = 0; i < NUM_CUSTOM_ELEMENTS; i++)
1711 struct ElementInfo *ei = &element_info[EL_CUSTOM_START + i];
1713 for (j = 0; j < ei->num_change_pages; j++)
1715 ei->change_page[j].actual_trigger_element = EL_EMPTY;
1716 ei->change_page[j].actual_trigger_player = EL_PLAYER_1;
1717 ei->change_page[j].actual_trigger_side = CH_SIDE_NONE;
1718 ei->change_page[j].actual_trigger_ce_value = 0;
1719 ei->change_page[j].actual_trigger_ce_score = 0;
1723 /* ---------- initialize trigger events ---------------------------------- */
1725 /* initialize trigger events information */
1726 for (i = 0; i < MAX_NUM_ELEMENTS; i++)
1727 for (j = 0; j < NUM_CHANGE_EVENTS; j++)
1728 trigger_events[i][j] = FALSE;
1730 /* add trigger events from element change event properties */
1731 for (i = 0; i < MAX_NUM_ELEMENTS; i++)
1733 struct ElementInfo *ei = &element_info[i];
1735 for (j = 0; j < ei->num_change_pages; j++)
1737 if (!ei->change_page[j].can_change_or_has_action)
1740 if (ei->change_page[j].has_event[CE_BY_OTHER_ACTION])
1742 int trigger_element = ei->change_page[j].trigger_element;
1744 for (k = 0; k < NUM_CHANGE_EVENTS; k++)
1746 if (ei->change_page[j].has_event[k])
1748 if (IS_GROUP_ELEMENT(trigger_element))
1750 struct ElementGroupInfo *group =
1751 element_info[trigger_element].group;
1753 for (l = 0; l < group->num_elements_resolved; l++)
1754 trigger_events[group->element_resolved[l]][k] = TRUE;
1757 trigger_events[trigger_element][k] = TRUE;
1764 /* ---------- initialize push delay -------------------------------------- */
1766 /* initialize push delay values to default */
1767 for (i = 0; i < MAX_NUM_ELEMENTS; i++)
1769 if (!IS_CUSTOM_ELEMENT(i))
1772 /* set default push delay values (corrected since version 3.0.7-1) */
1773 if (game.engine_version < VERSION_IDENT(3,0,7,1))
1775 element_info[i].push_delay_fixed = 2;
1776 element_info[i].push_delay_random = 8;
1780 element_info[i].push_delay_fixed = 8;
1781 element_info[i].push_delay_random = 8;
1784 element_info[i].push_delay_fixed = game.default_push_delay_fixed;
1785 element_info[i].push_delay_random = game.default_push_delay_random;
1790 /* set push delay value for certain elements from pre-defined list */
1791 for (i = 0; push_delay_list[i].element != EL_UNDEFINED; i++)
1793 int e = push_delay_list[i].element;
1795 element_info[e].push_delay_fixed = push_delay_list[i].push_delay_fixed;
1796 element_info[e].push_delay_random = push_delay_list[i].push_delay_random;
1799 /* set push delay value for Supaplex elements for newer engine versions */
1800 if (game.engine_version >= VERSION_IDENT(3,1,0,0))
1802 for (i = 0; i < MAX_NUM_ELEMENTS; i++)
1804 if (IS_SP_ELEMENT(i))
1806 /* set SP push delay to just enough to push under a falling zonk */
1807 int delay = (game.engine_version >= VERSION_IDENT(3,1,1,0) ? 8 : 6);
1809 element_info[i].push_delay_fixed = delay;
1810 element_info[i].push_delay_random = 0;
1815 /* ---------- initialize move stepsize ----------------------------------- */
1817 /* initialize move stepsize values to default */
1818 for (i = 0; i < MAX_NUM_ELEMENTS; i++)
1819 if (!IS_CUSTOM_ELEMENT(i))
1820 element_info[i].move_stepsize = MOVE_STEPSIZE_NORMAL;
1822 /* set move stepsize value for certain elements from pre-defined list */
1823 for (i = 0; move_stepsize_list[i].element != EL_UNDEFINED; i++)
1825 int e = move_stepsize_list[i].element;
1827 element_info[e].move_stepsize = move_stepsize_list[i].move_stepsize;
1830 /* ---------- initialize collect score ----------------------------------- */
1832 /* initialize collect score values for custom elements from initial value */
1833 for (i = 0; i < MAX_NUM_ELEMENTS; i++)
1834 if (IS_CUSTOM_ELEMENT(i))
1835 element_info[i].collect_score = element_info[i].collect_score_initial;
1837 /* ---------- initialize collect count ----------------------------------- */
1839 /* initialize collect count values for non-custom elements */
1840 for (i = 0; i < MAX_NUM_ELEMENTS; i++)
1841 if (!IS_CUSTOM_ELEMENT(i))
1842 element_info[i].collect_count_initial = 0;
1844 /* add collect count values for all elements from pre-defined list */
1845 for (i = 0; collect_count_list[i].element != EL_UNDEFINED; i++)
1846 element_info[collect_count_list[i].element].collect_count_initial =
1847 collect_count_list[i].count;
1849 /* ---------- initialize access direction -------------------------------- */
1851 /* initialize access direction values to default (access from every side) */
1852 for (i = 0; i < MAX_NUM_ELEMENTS; i++)
1853 if (!IS_CUSTOM_ELEMENT(i))
1854 element_info[i].access_direction = MV_ALL_DIRECTIONS;
1856 /* set access direction value for certain elements from pre-defined list */
1857 for (i = 0; access_direction_list[i].element != EL_UNDEFINED; i++)
1858 element_info[access_direction_list[i].element].access_direction =
1859 access_direction_list[i].direction;
1861 /* ---------- initialize explosion content ------------------------------- */
1862 for (i = 0; i < MAX_NUM_ELEMENTS; i++)
1864 if (IS_CUSTOM_ELEMENT(i))
1867 for (y = 0; y < 3; y++) for (x = 0; x < 3; x++)
1869 /* (content for EL_YAMYAM set at run-time with game.yamyam_content_nr) */
1871 element_info[i].content.e[x][y] =
1872 (i == EL_PLAYER_1 ? EL_EMERALD_YELLOW :
1873 i == EL_PLAYER_2 ? EL_EMERALD_RED :
1874 i == EL_PLAYER_3 ? EL_EMERALD :
1875 i == EL_PLAYER_4 ? EL_EMERALD_PURPLE :
1876 i == EL_MOLE ? EL_EMERALD_RED :
1877 i == EL_PENGUIN ? EL_EMERALD_PURPLE :
1878 i == EL_BUG ? (x == 1 && y == 1 ? EL_DIAMOND : EL_EMERALD) :
1879 i == EL_BD_BUTTERFLY ? EL_BD_DIAMOND :
1880 i == EL_SP_ELECTRON ? EL_SP_INFOTRON :
1881 i == EL_AMOEBA_TO_DIAMOND ? level.amoeba_content :
1882 i == EL_WALL_EMERALD ? EL_EMERALD :
1883 i == EL_WALL_DIAMOND ? EL_DIAMOND :
1884 i == EL_WALL_BD_DIAMOND ? EL_BD_DIAMOND :
1885 i == EL_WALL_EMERALD_YELLOW ? EL_EMERALD_YELLOW :
1886 i == EL_WALL_EMERALD_RED ? EL_EMERALD_RED :
1887 i == EL_WALL_EMERALD_PURPLE ? EL_EMERALD_PURPLE :
1888 i == EL_WALL_PEARL ? EL_PEARL :
1889 i == EL_WALL_CRYSTAL ? EL_CRYSTAL :
1895 int get_num_special_action(int element, int action_first, int action_last)
1897 int num_special_action = 0;
1900 for (i = action_first; i <= action_last; i++)
1902 boolean found = FALSE;
1904 for (j = 0; j < NUM_DIRECTIONS; j++)
1905 if (el_act_dir2img(element, i, j) !=
1906 el_act_dir2img(element, ACTION_DEFAULT, j))
1910 num_special_action++;
1916 printf("::: %d->%d: %d\n", action_first, action_last, num_special_action);
1919 return num_special_action;
1923 =============================================================================
1925 -----------------------------------------------------------------------------
1926 initialize and start new game
1927 =============================================================================
1932 boolean emulate_bd = TRUE; /* unless non-BOULDERDASH elements found */
1933 boolean emulate_sb = TRUE; /* unless non-SOKOBAN elements found */
1934 boolean emulate_sp = TRUE; /* unless non-SUPAPLEX elements found */
1939 /* don't play tapes over network */
1940 network_playing = (options.network && !tape.playing);
1942 for (i = 0; i < MAX_PLAYERS; i++)
1944 struct PlayerInfo *player = &stored_player[i];
1946 player->index_nr = i;
1947 player->index_bit = (1 << i);
1948 player->element_nr = EL_PLAYER_1 + i;
1950 player->present = FALSE;
1951 player->active = FALSE;
1954 player->effective_action = 0;
1955 player->programmed_action = 0;
1958 player->gems_still_needed = level.gems_needed;
1959 player->sokobanfields_still_needed = 0;
1960 player->lights_still_needed = 0;
1961 player->friends_still_needed = 0;
1963 for (j = 0; j < MAX_NUM_KEYS; j++)
1964 player->key[j] = FALSE;
1966 player->dynabomb_count = 0;
1967 player->dynabomb_size = 1;
1968 player->dynabombs_left = 0;
1969 player->dynabomb_xl = FALSE;
1971 player->MovDir = MV_NONE;
1974 player->GfxDir = MV_NONE;
1975 player->GfxAction = ACTION_DEFAULT;
1977 player->StepFrame = 0;
1979 player->use_murphy = FALSE;
1980 player->artwork_element =
1981 (level.use_artwork_element[i] ? level.artwork_element[i] :
1982 player->element_nr);
1984 player->block_last_field = FALSE; /* initialized in InitPlayerField() */
1985 player->block_delay_adjustment = 0; /* initialized in InitPlayerField() */
1987 player->gravity = level.initial_player_gravity[i];
1989 player->can_fall_into_acid = CAN_MOVE_INTO_ACID(player->element_nr);
1991 player->actual_frame_counter = 0;
1993 player->step_counter = 0;
1995 player->last_move_dir = MV_NONE;
1997 player->is_active = FALSE;
1999 player->is_waiting = FALSE;
2000 player->is_moving = FALSE;
2001 player->is_auto_moving = FALSE;
2002 player->is_digging = FALSE;
2003 player->is_snapping = FALSE;
2004 player->is_collecting = FALSE;
2005 player->is_pushing = FALSE;
2006 player->is_switching = FALSE;
2007 player->is_dropping = FALSE;
2008 player->is_dropping_pressed = FALSE;
2010 player->is_bored = FALSE;
2011 player->is_sleeping = FALSE;
2013 player->frame_counter_bored = -1;
2014 player->frame_counter_sleeping = -1;
2016 player->anim_delay_counter = 0;
2017 player->post_delay_counter = 0;
2019 player->dir_waiting = MV_NONE;
2020 player->action_waiting = ACTION_DEFAULT;
2021 player->last_action_waiting = ACTION_DEFAULT;
2022 player->special_action_bored = ACTION_DEFAULT;
2023 player->special_action_sleeping = ACTION_DEFAULT;
2026 /* cannot be set here -- could be modified in Init[Player]Field() below */
2028 /* set number of special actions for bored and sleeping animation */
2029 player->num_special_action_bored =
2030 get_num_special_action(player->artwork_element,
2031 ACTION_BORING_1, ACTION_BORING_LAST);
2032 player->num_special_action_sleeping =
2033 get_num_special_action(player->artwork_element,
2034 ACTION_SLEEPING_1, ACTION_SLEEPING_LAST);
2037 player->switch_x = -1;
2038 player->switch_y = -1;
2040 player->drop_x = -1;
2041 player->drop_y = -1;
2043 player->show_envelope = 0;
2046 SetPlayerMoveSpeed(player, level.initial_player_stepsize[i], TRUE);
2048 player->move_delay = game.initial_move_delay;
2049 player->move_delay_value = game.initial_move_delay_value;
2051 player->move_delay_value_next = -1;
2053 player->move_delay_reset_counter = 0;
2055 player->cannot_move = FALSE;
2058 player->push_delay = -1; /* initialized when pushing starts */
2059 player->push_delay_value = game.initial_push_delay_value;
2061 player->drop_delay = 0;
2062 player->drop_pressed_delay = 0;
2064 player->last_jx = player->last_jy = 0;
2065 player->jx = player->jy = 0;
2067 player->shield_normal_time_left = 0;
2068 player->shield_deadly_time_left = 0;
2070 player->inventory_infinite_element = EL_UNDEFINED;
2071 player->inventory_size = 0;
2073 DigField(player, 0, 0, 0, 0, 0, 0, DF_NO_PUSH);
2074 SnapField(player, 0, 0);
2076 player->LevelSolved = FALSE;
2077 player->GameOver = FALSE;
2080 network_player_action_received = FALSE;
2082 #if defined(NETWORK_AVALIABLE)
2083 /* initial null action */
2084 if (network_playing)
2085 SendToServer_MovePlayer(MV_NONE);
2094 TimeLeft = level.time;
2097 ScreenMovDir = MV_NONE;
2101 ScrollStepSize = 0; /* will be correctly initialized by ScrollScreen() */
2103 AllPlayersGone = FALSE;
2105 game.yamyam_content_nr = 0;
2106 game.magic_wall_active = FALSE;
2107 game.magic_wall_time_left = 0;
2108 game.light_time_left = 0;
2109 game.timegate_time_left = 0;
2110 game.switchgate_pos = 0;
2111 game.wind_direction = level.wind_direction_initial;
2113 #if !USE_PLAYER_GRAVITY
2115 game.gravity = FALSE;
2117 game.gravity = level.initial_gravity;
2119 game.explosions_delayed = TRUE;
2122 game.lenses_time_left = 0;
2123 game.magnify_time_left = 0;
2125 game.ball_state = level.ball_state_initial;
2126 game.ball_content_nr = 0;
2128 game.envelope_active = FALSE;
2130 /* set focus to local player for network games, else to all players */
2131 game.centered_player_nr = (network_playing ? local_player->index_nr : -1);
2132 game.centered_player_nr_next = game.centered_player_nr;
2133 game.set_centered_player = FALSE;
2135 if (network_playing && tape.recording)
2137 /* store client dependent player focus when recording network games */
2138 tape.centered_player_nr_next = game.centered_player_nr_next;
2139 tape.set_centered_player = TRUE;
2143 printf("::: focus set to player %d [%d]\n",
2144 game.centered_player_nr, local_player->index_nr);
2147 for (i = 0; i < NUM_BELTS; i++)
2149 game.belt_dir[i] = MV_NONE;
2150 game.belt_dir_nr[i] = 3; /* not moving, next moving left */
2153 for (i = 0; i < MAX_NUM_AMOEBA; i++)
2154 AmoebaCnt[i] = AmoebaCnt2[i] = 0;
2157 SCAN_PLAYFIELD(x, y)
2159 for (x = 0; x < lev_fieldx; x++) for (y = 0; y < lev_fieldy; y++)
2162 Feld[x][y] = level.field[x][y];
2163 MovPos[x][y] = MovDir[x][y] = MovDelay[x][y] = 0;
2164 ChangeDelay[x][y] = 0;
2165 ChangePage[x][y] = -1;
2166 #if USE_NEW_CUSTOM_VALUE
2167 CustomValue[x][y] = 0; /* initialized in InitField() */
2169 Store[x][y] = Store2[x][y] = StorePlayer[x][y] = Back[x][y] = 0;
2171 WasJustMoving[x][y] = 0;
2172 WasJustFalling[x][y] = 0;
2173 CheckCollision[x][y] = 0;
2175 Pushed[x][y] = FALSE;
2177 ChangeCount[x][y] = 0;
2178 ChangeEvent[x][y] = -1;
2180 ExplodePhase[x][y] = 0;
2181 ExplodeDelay[x][y] = 0;
2182 ExplodeField[x][y] = EX_TYPE_NONE;
2184 RunnerVisit[x][y] = 0;
2185 PlayerVisit[x][y] = 0;
2188 GfxRandom[x][y] = INIT_GFX_RANDOM();
2189 GfxElement[x][y] = EL_UNDEFINED;
2190 GfxAction[x][y] = ACTION_DEFAULT;
2191 GfxDir[x][y] = MV_NONE;
2195 SCAN_PLAYFIELD(x, y)
2197 for (y = 0; y < lev_fieldy; y++) for (x = 0; x < lev_fieldx; x++)
2200 if (emulate_bd && !IS_BD_ELEMENT(Feld[x][y]))
2202 if (emulate_sb && !IS_SB_ELEMENT(Feld[x][y]))
2204 if (emulate_sp && !IS_SP_ELEMENT(Feld[x][y]))
2207 InitField(x, y, TRUE);
2212 for (i = 0; i < MAX_PLAYERS; i++)
2214 struct PlayerInfo *player = &stored_player[i];
2217 /* set number of special actions for bored and sleeping animation */
2218 player->num_special_action_bored =
2219 get_num_special_action(player->artwork_element,
2220 ACTION_BORING_1, ACTION_BORING_LAST);
2221 player->num_special_action_sleeping =
2222 get_num_special_action(player->artwork_element,
2223 ACTION_SLEEPING_1, ACTION_SLEEPING_LAST);
2228 game.emulation = (emulate_bd ? EMU_BOULDERDASH :
2229 emulate_sb ? EMU_SOKOBAN :
2230 emulate_sp ? EMU_SUPAPLEX : EMU_NONE);
2232 #if USE_NEW_ALL_SLIPPERY
2233 /* initialize type of slippery elements */
2234 for (i = 0; i < MAX_NUM_ELEMENTS; i++)
2236 if (!IS_CUSTOM_ELEMENT(i))
2238 /* default: elements slip down either to the left or right randomly */
2239 element_info[i].slippery_type = SLIPPERY_ANY_RANDOM;
2241 /* SP style elements prefer to slip down on the left side */
2242 if (game.engine_version >= VERSION_IDENT(3,1,1,0) && IS_SP_ELEMENT(i))
2243 element_info[i].slippery_type = SLIPPERY_ANY_LEFT_RIGHT;
2245 /* BD style elements prefer to slip down on the left side */
2246 if (game.emulation == EMU_BOULDERDASH)
2247 element_info[i].slippery_type = SLIPPERY_ANY_LEFT_RIGHT;
2252 /* initialize explosion and ignition delay */
2253 for (i = 0; i < MAX_NUM_ELEMENTS; i++)
2255 if (!IS_CUSTOM_ELEMENT(i))
2258 int delay = (((IS_SP_ELEMENT(i) && i != EL_EMPTY_SPACE) &&
2259 game.engine_version >= VERSION_IDENT(3,1,0,0)) ||
2260 game.emulation == EMU_SUPAPLEX ? 3 : 2);
2261 int last_phase = (num_phase + 1) * delay;
2262 int half_phase = (num_phase / 2) * delay;
2264 element_info[i].explosion_delay = last_phase - 1;
2265 element_info[i].ignition_delay = half_phase;
2267 if (i == EL_BLACK_ORB)
2268 element_info[i].ignition_delay = 1;
2272 if (element_info[i].explosion_delay < 1) /* !!! check again !!! */
2273 element_info[i].explosion_delay = 1;
2275 if (element_info[i].ignition_delay < 1) /* !!! check again !!! */
2276 element_info[i].ignition_delay = 1;
2280 /* correct non-moving belts to start moving left */
2281 for (i = 0; i < NUM_BELTS; i++)
2282 if (game.belt_dir[i] == MV_NONE)
2283 game.belt_dir_nr[i] = 3; /* not moving, next moving left */
2285 /* check if any connected player was not found in playfield */
2286 for (i = 0; i < MAX_PLAYERS; i++)
2288 struct PlayerInfo *player = &stored_player[i];
2290 if (player->connected && !player->present)
2292 for (j = 0; j < MAX_PLAYERS; j++)
2294 struct PlayerInfo *some_player = &stored_player[j];
2295 int jx = some_player->jx, jy = some_player->jy;
2297 /* assign first free player found that is present in the playfield */
2298 if (some_player->present && !some_player->connected)
2300 player->present = TRUE;
2301 player->active = TRUE;
2303 some_player->present = FALSE;
2304 some_player->active = FALSE;
2307 player->element_nr = some_player->element_nr;
2310 player->artwork_element = some_player->artwork_element;
2312 player->block_last_field = some_player->block_last_field;
2313 player->block_delay_adjustment = some_player->block_delay_adjustment;
2315 StorePlayer[jx][jy] = player->element_nr;
2316 player->jx = player->last_jx = jx;
2317 player->jy = player->last_jy = jy;
2327 /* when playing a tape, eliminate all players who do not participate */
2329 for (i = 0; i < MAX_PLAYERS; i++)
2331 if (stored_player[i].active && !tape.player_participates[i])
2333 struct PlayerInfo *player = &stored_player[i];
2334 int jx = player->jx, jy = player->jy;
2336 player->active = FALSE;
2337 StorePlayer[jx][jy] = 0;
2338 Feld[jx][jy] = EL_EMPTY;
2342 else if (!options.network && !setup.team_mode) /* && !tape.playing */
2344 /* when in single player mode, eliminate all but the first active player */
2346 for (i = 0; i < MAX_PLAYERS; i++)
2348 if (stored_player[i].active)
2350 for (j = i + 1; j < MAX_PLAYERS; j++)
2352 if (stored_player[j].active)
2354 struct PlayerInfo *player = &stored_player[j];
2355 int jx = player->jx, jy = player->jy;
2357 player->active = FALSE;
2358 player->present = FALSE;
2360 StorePlayer[jx][jy] = 0;
2361 Feld[jx][jy] = EL_EMPTY;
2368 /* when recording the game, store which players take part in the game */
2371 for (i = 0; i < MAX_PLAYERS; i++)
2372 if (stored_player[i].active)
2373 tape.player_participates[i] = TRUE;
2378 for (i = 0; i < MAX_PLAYERS; i++)
2380 struct PlayerInfo *player = &stored_player[i];
2382 printf("Player %d: present == %d, connected == %d, active == %d.\n",
2387 if (local_player == player)
2388 printf("Player %d is local player.\n", i+1);
2392 if (BorderElement == EL_EMPTY)
2395 SBX_Right = lev_fieldx - SCR_FIELDX;
2397 SBY_Lower = lev_fieldy - SCR_FIELDY;
2402 SBX_Right = lev_fieldx - SCR_FIELDX + 1;
2404 SBY_Lower = lev_fieldy - SCR_FIELDY + 1;
2407 if (lev_fieldx + (SBX_Left == -1 ? 2 : 0) <= SCR_FIELDX)
2408 SBX_Left = SBX_Right = -1 * (SCR_FIELDX - lev_fieldx) / 2;
2410 if (lev_fieldy + (SBY_Upper == -1 ? 2 : 0) <= SCR_FIELDY)
2411 SBY_Upper = SBY_Lower = -1 * (SCR_FIELDY - lev_fieldy) / 2;
2413 /* if local player not found, look for custom element that might create
2414 the player (make some assumptions about the right custom element) */
2415 if (!local_player->present)
2417 int start_x = 0, start_y = 0;
2418 int found_rating = 0;
2419 int found_element = EL_UNDEFINED;
2420 int player_nr = local_player->index_nr;
2423 SCAN_PLAYFIELD(x, y)
2425 for (y = 0; y < lev_fieldy; y++) for (x = 0; x < lev_fieldx; x++)
2428 int element = Feld[x][y];
2433 if (level.use_start_element[player_nr] &&
2434 level.start_element[player_nr] == element &&
2441 found_element = element;
2444 if (!IS_CUSTOM_ELEMENT(element))
2447 if (CAN_CHANGE(element))
2449 for (i = 0; i < element_info[element].num_change_pages; i++)
2451 /* check for player created from custom element as single target */
2452 content = element_info[element].change_page[i].target_element;
2453 is_player = ELEM_IS_PLAYER(content);
2455 if (is_player && (found_rating < 3 || element < found_element))
2461 found_element = element;
2466 for (yy = 0; yy < 3; yy++) for (xx = 0; xx < 3; xx++)
2468 /* check for player created from custom element as explosion content */
2469 content = element_info[element].content.e[xx][yy];
2470 is_player = ELEM_IS_PLAYER(content);
2472 if (is_player && (found_rating < 2 || element < found_element))
2474 start_x = x + xx - 1;
2475 start_y = y + yy - 1;
2478 found_element = element;
2481 if (!CAN_CHANGE(element))
2484 for (i = 0; i < element_info[element].num_change_pages; i++)
2486 /* check for player created from custom element as extended target */
2488 element_info[element].change_page[i].target_content.e[xx][yy];
2490 is_player = ELEM_IS_PLAYER(content);
2492 if (is_player && (found_rating < 1 || element < found_element))
2494 start_x = x + xx - 1;
2495 start_y = y + yy - 1;
2498 found_element = element;
2504 scroll_x = (start_x < SBX_Left + MIDPOSX ? SBX_Left :
2505 start_x > SBX_Right + MIDPOSX ? SBX_Right :
2508 scroll_y = (start_y < SBY_Upper + MIDPOSY ? SBY_Upper :
2509 start_y > SBY_Lower + MIDPOSY ? SBY_Lower :
2514 scroll_x = (local_player->jx < SBX_Left + MIDPOSX ? SBX_Left :
2515 local_player->jx > SBX_Right + MIDPOSX ? SBX_Right :
2516 local_player->jx - MIDPOSX);
2518 scroll_y = (local_player->jy < SBY_Upper + MIDPOSY ? SBY_Upper :
2519 local_player->jy > SBY_Lower + MIDPOSY ? SBY_Lower :
2520 local_player->jy - MIDPOSY);
2523 if (!game.restart_level)
2524 CloseDoor(DOOR_CLOSE_1);
2526 /* !!! FIX THIS (START) !!! */
2527 if (level.game_engine_type == GAME_ENGINE_TYPE_EM)
2529 InitGameEngine_EM();
2536 /* after drawing the level, correct some elements */
2537 if (game.timegate_time_left == 0)
2538 CloseAllOpenTimegates();
2540 if (setup.soft_scrolling)
2541 BlitBitmap(fieldbuffer, backbuffer, FX, FY, SXSIZE, SYSIZE, SX, SY);
2543 redraw_mask |= REDRAW_FROM_BACKBUFFER;
2546 /* !!! FIX THIS (END) !!! */
2548 if (!game.restart_level)
2550 /* copy default game door content to main double buffer */
2551 BlitBitmap(graphic_info[IMG_GLOBAL_DOOR].bitmap, drawto,
2552 DOOR_GFX_PAGEX5, DOOR_GFX_PAGEY1, DXSIZE, DYSIZE, DX, DY);
2555 DrawGameDoorValues();
2557 if (!game.restart_level)
2561 game_gadget[SOUND_CTRL_ID_MUSIC]->checked = setup.sound_music;
2562 game_gadget[SOUND_CTRL_ID_LOOPS]->checked = setup.sound_loops;
2563 game_gadget[SOUND_CTRL_ID_SIMPLE]->checked = setup.sound_simple;
2567 /* copy actual game door content to door double buffer for OpenDoor() */
2568 BlitBitmap(drawto, bitmap_db_door,
2569 DX, DY, DXSIZE, DYSIZE, DOOR_GFX_PAGEX1, DOOR_GFX_PAGEY1);
2571 OpenDoor(DOOR_OPEN_ALL);
2573 PlaySoundStereo(SND_GAME_STARTING, SOUND_MIDDLE);
2575 if (setup.sound_music)
2578 KeyboardAutoRepeatOffUnlessAutoplay();
2582 for (i = 0; i < MAX_PLAYERS; i++)
2583 printf("Player %d %sactive.\n",
2584 i + 1, (stored_player[i].active ? "" : "not "));
2588 game.restart_level = FALSE;
2591 void UpdateEngineValues(int actual_scroll_x, int actual_scroll_y)
2593 /* this is used for non-R'n'D game engines to update certain engine values */
2595 /* needed to determine if sounds are played within the visible screen area */
2596 scroll_x = actual_scroll_x;
2597 scroll_y = actual_scroll_y;
2600 void InitMovDir(int x, int y)
2602 int i, element = Feld[x][y];
2603 static int xy[4][2] =
2610 static int direction[3][4] =
2612 { MV_RIGHT, MV_UP, MV_LEFT, MV_DOWN },
2613 { MV_LEFT, MV_DOWN, MV_RIGHT, MV_UP },
2614 { MV_LEFT, MV_RIGHT, MV_UP, MV_DOWN }
2623 Feld[x][y] = EL_BUG;
2624 MovDir[x][y] = direction[0][element - EL_BUG_RIGHT];
2627 case EL_SPACESHIP_RIGHT:
2628 case EL_SPACESHIP_UP:
2629 case EL_SPACESHIP_LEFT:
2630 case EL_SPACESHIP_DOWN:
2631 Feld[x][y] = EL_SPACESHIP;
2632 MovDir[x][y] = direction[0][element - EL_SPACESHIP_RIGHT];
2635 case EL_BD_BUTTERFLY_RIGHT:
2636 case EL_BD_BUTTERFLY_UP:
2637 case EL_BD_BUTTERFLY_LEFT:
2638 case EL_BD_BUTTERFLY_DOWN:
2639 Feld[x][y] = EL_BD_BUTTERFLY;
2640 MovDir[x][y] = direction[0][element - EL_BD_BUTTERFLY_RIGHT];
2643 case EL_BD_FIREFLY_RIGHT:
2644 case EL_BD_FIREFLY_UP:
2645 case EL_BD_FIREFLY_LEFT:
2646 case EL_BD_FIREFLY_DOWN:
2647 Feld[x][y] = EL_BD_FIREFLY;
2648 MovDir[x][y] = direction[0][element - EL_BD_FIREFLY_RIGHT];
2651 case EL_PACMAN_RIGHT:
2653 case EL_PACMAN_LEFT:
2654 case EL_PACMAN_DOWN:
2655 Feld[x][y] = EL_PACMAN;
2656 MovDir[x][y] = direction[0][element - EL_PACMAN_RIGHT];
2659 case EL_YAMYAM_LEFT:
2660 case EL_YAMYAM_RIGHT:
2662 case EL_YAMYAM_DOWN:
2663 Feld[x][y] = EL_YAMYAM;
2664 MovDir[x][y] = direction[2][element - EL_YAMYAM_LEFT];
2667 case EL_SP_SNIKSNAK:
2668 MovDir[x][y] = MV_UP;
2671 case EL_SP_ELECTRON:
2672 MovDir[x][y] = MV_LEFT;
2679 Feld[x][y] = EL_MOLE;
2680 MovDir[x][y] = direction[2][element - EL_MOLE_LEFT];
2684 if (IS_CUSTOM_ELEMENT(element))
2686 struct ElementInfo *ei = &element_info[element];
2687 int move_direction_initial = ei->move_direction_initial;
2688 int move_pattern = ei->move_pattern;
2690 if (move_direction_initial == MV_START_PREVIOUS)
2692 if (MovDir[x][y] != MV_NONE)
2695 move_direction_initial = MV_START_AUTOMATIC;
2698 if (move_direction_initial == MV_START_RANDOM)
2699 MovDir[x][y] = 1 << RND(4);
2700 else if (move_direction_initial & MV_ANY_DIRECTION)
2701 MovDir[x][y] = move_direction_initial;
2702 else if (move_pattern == MV_ALL_DIRECTIONS ||
2703 move_pattern == MV_TURNING_LEFT ||
2704 move_pattern == MV_TURNING_RIGHT ||
2705 move_pattern == MV_TURNING_LEFT_RIGHT ||
2706 move_pattern == MV_TURNING_RIGHT_LEFT ||
2707 move_pattern == MV_TURNING_RANDOM)
2708 MovDir[x][y] = 1 << RND(4);
2709 else if (move_pattern == MV_HORIZONTAL)
2710 MovDir[x][y] = (RND(2) ? MV_LEFT : MV_RIGHT);
2711 else if (move_pattern == MV_VERTICAL)
2712 MovDir[x][y] = (RND(2) ? MV_UP : MV_DOWN);
2713 else if (move_pattern & MV_ANY_DIRECTION)
2714 MovDir[x][y] = element_info[element].move_pattern;
2715 else if (move_pattern == MV_ALONG_LEFT_SIDE ||
2716 move_pattern == MV_ALONG_RIGHT_SIDE)
2718 /* use random direction as default start direction */
2719 if (game.engine_version >= VERSION_IDENT(3,1,0,0))
2720 MovDir[x][y] = 1 << RND(4);
2722 for (i = 0; i < NUM_DIRECTIONS; i++)
2724 int x1 = x + xy[i][0];
2725 int y1 = y + xy[i][1];
2727 if (!IN_LEV_FIELD(x1, y1) || !IS_FREE(x1, y1))
2729 if (move_pattern == MV_ALONG_RIGHT_SIDE)
2730 MovDir[x][y] = direction[0][i];
2732 MovDir[x][y] = direction[1][i];
2741 MovDir[x][y] = 1 << RND(4);
2743 if (element != EL_BUG &&
2744 element != EL_SPACESHIP &&
2745 element != EL_BD_BUTTERFLY &&
2746 element != EL_BD_FIREFLY)
2749 for (i = 0; i < NUM_DIRECTIONS; i++)
2751 int x1 = x + xy[i][0];
2752 int y1 = y + xy[i][1];
2754 if (!IN_LEV_FIELD(x1, y1) || !IS_FREE(x1, y1))
2756 if (element == EL_BUG || element == EL_BD_BUTTERFLY)
2758 MovDir[x][y] = direction[0][i];
2761 else if (element == EL_SPACESHIP || element == EL_BD_FIREFLY ||
2762 element == EL_SP_SNIKSNAK || element == EL_SP_ELECTRON)
2764 MovDir[x][y] = direction[1][i];
2773 GfxDir[x][y] = MovDir[x][y];
2776 void InitAmoebaNr(int x, int y)
2779 int group_nr = AmoebeNachbarNr(x, y);
2783 for (i = 1; i < MAX_NUM_AMOEBA; i++)
2785 if (AmoebaCnt[i] == 0)
2793 AmoebaNr[x][y] = group_nr;
2794 AmoebaCnt[group_nr]++;
2795 AmoebaCnt2[group_nr]++;
2801 boolean raise_level = FALSE;
2803 if (local_player->MovPos)
2806 if (tape.auto_play) /* tape might already be stopped here */
2807 tape.auto_play_level_solved = TRUE;
2809 local_player->LevelSolved = FALSE;
2811 PlaySoundStereo(SND_GAME_WINNING, SOUND_MIDDLE);
2815 if (!tape.playing && setup.sound_loops)
2816 PlaySoundExt(SND_GAME_LEVELTIME_BONUS, SOUND_MAX_VOLUME, SOUND_MIDDLE,
2817 SND_CTRL_PLAY_LOOP);
2819 while (TimeLeft > 0)
2821 if (!tape.playing && !setup.sound_loops)
2822 PlaySoundStereo(SND_GAME_LEVELTIME_BONUS, SOUND_MIDDLE);
2824 if (TimeLeft > 100 && TimeLeft % 10 == 0)
2827 RaiseScore(level.score[SC_TIME_BONUS] * 10);
2832 RaiseScore(level.score[SC_TIME_BONUS]);
2835 DrawGameValue_Time(TimeLeft);
2843 if (!tape.playing && setup.sound_loops)
2844 StopSound(SND_GAME_LEVELTIME_BONUS);
2846 else if (level.time == 0) /* level without time limit */
2848 if (!tape.playing && setup.sound_loops)
2849 PlaySoundExt(SND_GAME_LEVELTIME_BONUS, SOUND_MAX_VOLUME, SOUND_MIDDLE,
2850 SND_CTRL_PLAY_LOOP);
2852 while (TimePlayed < 999)
2854 if (!tape.playing && !setup.sound_loops)
2855 PlaySoundStereo(SND_GAME_LEVELTIME_BONUS, SOUND_MIDDLE);
2857 if (TimePlayed < 900 && TimePlayed % 10 == 0)
2860 RaiseScore(level.score[SC_TIME_BONUS] * 10);
2865 RaiseScore(level.score[SC_TIME_BONUS]);
2868 DrawGameValue_Time(TimePlayed);
2876 if (!tape.playing && setup.sound_loops)
2877 StopSound(SND_GAME_LEVELTIME_BONUS);
2880 /* close exit door after last player */
2881 if (AllPlayersGone && ExitX >= 0 && ExitY >= 0 &&
2882 (Feld[ExitX][ExitY] == EL_EXIT_OPEN ||
2883 Feld[ExitX][ExitY] == EL_SP_EXIT_OPEN))
2885 int element = Feld[ExitX][ExitY];
2887 Feld[ExitX][ExitY] = (element == EL_EXIT_OPEN ? EL_EXIT_CLOSING :
2888 EL_SP_EXIT_CLOSING);
2890 PlayLevelSoundElementAction(ExitX, ExitY, element, ACTION_CLOSING);
2893 /* player disappears */
2894 if (ExitX >= 0 && ExitY >= 0)
2895 DrawLevelField(ExitX, ExitY);
2901 printf("::: TAPE PLAYING -> DO NOT SAVE SCORE\n");
2903 printf("::: NO TAPE PLAYING -> SAVING SCORE\n");
2909 CloseDoor(DOOR_CLOSE_1);
2914 SaveTape(tape.level_nr); /* Ask to save tape */
2917 if (level_nr == leveldir_current->handicap_level)
2919 leveldir_current->handicap_level++;
2920 SaveLevelSetup_SeriesInfo();
2923 if (level_editor_test_game)
2924 local_player->score = -1; /* no highscore when playing from editor */
2925 else if (level_nr < leveldir_current->last_level)
2926 raise_level = TRUE; /* advance to next level */
2928 if ((hi_pos = NewHiScore()) >= 0)
2930 game_status = GAME_MODE_SCORES;
2931 DrawHallOfFame(hi_pos);
2940 game_status = GAME_MODE_MAIN;
2957 LoadScore(level_nr);
2959 if (strEqual(setup.player_name, EMPTY_PLAYER_NAME) ||
2960 local_player->score < highscore[MAX_SCORE_ENTRIES - 1].Score)
2963 for (k = 0; k < MAX_SCORE_ENTRIES; k++)
2965 if (local_player->score > highscore[k].Score)
2967 /* player has made it to the hall of fame */
2969 if (k < MAX_SCORE_ENTRIES - 1)
2971 int m = MAX_SCORE_ENTRIES - 1;
2974 for (l = k; l < MAX_SCORE_ENTRIES; l++)
2975 if (strEqual(setup.player_name, highscore[l].Name))
2977 if (m == k) /* player's new highscore overwrites his old one */
2981 for (l = m; l > k; l--)
2983 strcpy(highscore[l].Name, highscore[l - 1].Name);
2984 highscore[l].Score = highscore[l - 1].Score;
2991 strncpy(highscore[k].Name, setup.player_name, MAX_PLAYER_NAME_LEN);
2992 highscore[k].Name[MAX_PLAYER_NAME_LEN] = '\0';
2993 highscore[k].Score = local_player->score;
2999 else if (!strncmp(setup.player_name, highscore[k].Name,
3000 MAX_PLAYER_NAME_LEN))
3001 break; /* player already there with a higher score */
3007 SaveScore(level_nr);
3012 inline static int getElementMoveStepsize(int x, int y)
3014 int element = Feld[x][y];
3015 int direction = MovDir[x][y];
3016 int dx = (direction == MV_LEFT ? -1 : direction == MV_RIGHT ? +1 : 0);
3017 int dy = (direction == MV_UP ? -1 : direction == MV_DOWN ? +1 : 0);
3018 int horiz_move = (dx != 0);
3019 int sign = (horiz_move ? dx : dy);
3020 int step = sign * element_info[element].move_stepsize;
3022 /* special values for move stepsize for spring and things on conveyor belt */
3026 if (element == EL_SPRING)
3027 step = sign * MOVE_STEPSIZE_NORMAL * 2;
3028 else if (CAN_FALL(element) && !CAN_MOVE(element) &&
3029 y < lev_fieldy - 1 && IS_BELT_ACTIVE(Feld[x][y + 1]))
3030 step = sign * MOVE_STEPSIZE_NORMAL / 2;
3032 if (CAN_FALL(element) &&
3033 y < lev_fieldy - 1 && IS_BELT_ACTIVE(Feld[x][y + 1]))
3034 step = sign * MOVE_STEPSIZE_NORMAL / 2;
3035 else if (element == EL_SPRING)
3036 step = sign * MOVE_STEPSIZE_NORMAL * 2;
3043 void InitPlayerGfxAnimation(struct PlayerInfo *player, int action, int dir)
3045 if (player->GfxAction != action || player->GfxDir != dir)
3048 printf("Player frame reset! (%d => %d, %d => %d)\n",
3049 player->GfxAction, action, player->GfxDir, dir);
3052 player->GfxAction = action;
3053 player->GfxDir = dir;
3055 player->StepFrame = 0;
3059 #if USE_GFX_RESET_GFX_ANIMATION
3060 static void ResetGfxFrame(int x, int y, boolean redraw)
3062 int element = Feld[x][y];
3063 int graphic = el_act_dir2img(element, GfxAction[x][y], GfxDir[x][y]);
3064 int last_gfx_frame = GfxFrame[x][y];
3066 if (graphic_info[graphic].anim_global_sync)
3067 GfxFrame[x][y] = FrameCounter;
3068 else if (ANIM_MODE(graphic) == ANIM_CE_VALUE)
3069 GfxFrame[x][y] = CustomValue[x][y];
3070 else if (ANIM_MODE(graphic) == ANIM_CE_SCORE)
3071 GfxFrame[x][y] = element_info[element].collect_score;
3072 else if (ANIM_MODE(graphic) == ANIM_CE_DELAY)
3073 GfxFrame[x][y] = ChangeDelay[x][y];
3075 if (redraw && GfxFrame[x][y] != last_gfx_frame)
3076 DrawLevelGraphicAnimation(x, y, graphic);
3080 static void ResetGfxAnimation(int x, int y)
3083 int element, graphic;
3086 GfxAction[x][y] = ACTION_DEFAULT;
3087 GfxDir[x][y] = MovDir[x][y];
3091 element = Feld[x][y];
3092 graphic = el_act_dir2img(element, GfxAction[x][y], GfxDir[x][y]);
3094 if (graphic_info[graphic].anim_global_sync)
3095 GfxFrame[x][y] = FrameCounter;
3096 else if (ANIM_MODE(graphic) == ANIM_CE_VALUE)
3097 GfxFrame[x][y] = CustomValue[x][y];
3098 else if (ANIM_MODE(graphic) == ANIM_CE_SCORE)
3099 GfxFrame[x][y] = element_info[element].collect_score;
3100 else if (ANIM_MODE(graphic) == ANIM_CE_DELAY)
3101 GfxFrame[x][y] = ChangeDelay[x][y];
3104 #if USE_GFX_RESET_GFX_ANIMATION
3105 ResetGfxFrame(x, y, FALSE);
3109 static void ResetRandomAnimationValue(int x, int y)
3111 GfxRandom[x][y] = INIT_GFX_RANDOM();
3114 void InitMovingField(int x, int y, int direction)
3116 int element = Feld[x][y];
3120 int dx = (direction == MV_LEFT ? -1 : direction == MV_RIGHT ? +1 : 0);
3121 int dy = (direction == MV_UP ? -1 : direction == MV_DOWN ? +1 : 0);
3125 if (!WasJustMoving[x][y] || direction != MovDir[x][y])
3126 ResetGfxAnimation(x, y);
3128 MovDir[x][y] = direction;
3129 GfxDir[x][y] = direction;
3130 GfxAction[x][y] = (direction == MV_DOWN && CAN_FALL(element) ?
3131 ACTION_FALLING : ACTION_MOVING);
3134 graphic = el_act_dir2img(element, GfxAction[x][y], GfxDir[x][y]);
3136 if (graphic_info[graphic].anim_global_sync)
3137 GfxFrame[x][y] = FrameCounter;
3138 else if (ANIM_MODE(graphic) == ANIM_CE_VALUE)
3139 GfxFrame[x][y] = CustomValue[x][y];
3140 else if (ANIM_MODE(graphic) == ANIM_CE_SCORE)
3141 GfxFrame[x][y] = element_info[element].collect_score;
3142 else if (ANIM_MODE(graphic) == ANIM_CE_DELAY)
3143 GfxFrame[x][y] = ChangeDelay[x][y];
3146 /* this is needed for CEs with property "can move" / "not moving" */
3148 if (getElementMoveStepsize(x, y) != 0) /* moving or being moved */
3150 if (Feld[newx][newy] == EL_EMPTY)
3151 Feld[newx][newy] = EL_BLOCKED;
3153 MovDir[newx][newy] = MovDir[x][y];
3155 #if USE_NEW_CUSTOM_VALUE
3156 CustomValue[newx][newy] = CustomValue[x][y];
3159 GfxFrame[newx][newy] = GfxFrame[x][y];
3160 GfxRandom[newx][newy] = GfxRandom[x][y];
3161 GfxAction[newx][newy] = GfxAction[x][y];
3162 GfxDir[newx][newy] = GfxDir[x][y];
3166 void Moving2Blocked(int x, int y, int *goes_to_x, int *goes_to_y)
3168 int direction = MovDir[x][y];
3170 int newx = x + (direction & MV_LEFT ? -1 : direction & MV_RIGHT ? +1 : 0);
3171 int newy = y + (direction & MV_UP ? -1 : direction & MV_DOWN ? +1 : 0);
3173 int newx = x + (direction == MV_LEFT ? -1 : direction == MV_RIGHT ? +1 : 0);
3174 int newy = y + (direction == MV_UP ? -1 : direction == MV_DOWN ? +1 : 0);
3181 void Blocked2Moving(int x, int y, int *comes_from_x, int *comes_from_y)
3183 int oldx = x, oldy = y;
3184 int direction = MovDir[x][y];
3186 if (direction == MV_LEFT)
3188 else if (direction == MV_RIGHT)
3190 else if (direction == MV_UP)
3192 else if (direction == MV_DOWN)
3195 *comes_from_x = oldx;
3196 *comes_from_y = oldy;
3199 int MovingOrBlocked2Element(int x, int y)
3201 int element = Feld[x][y];
3203 if (element == EL_BLOCKED)
3207 Blocked2Moving(x, y, &oldx, &oldy);
3208 return Feld[oldx][oldy];
3214 static int MovingOrBlocked2ElementIfNotLeaving(int x, int y)
3216 /* like MovingOrBlocked2Element(), but if element is moving
3217 and (x,y) is the field the moving element is just leaving,
3218 return EL_BLOCKED instead of the element value */
3219 int element = Feld[x][y];
3221 if (IS_MOVING(x, y))
3223 if (element == EL_BLOCKED)
3227 Blocked2Moving(x, y, &oldx, &oldy);
3228 return Feld[oldx][oldy];
3237 static void RemoveField(int x, int y)
3239 Feld[x][y] = EL_EMPTY;
3245 #if USE_NEW_CUSTOM_VALUE
3246 CustomValue[x][y] = 0;
3250 ChangeDelay[x][y] = 0;
3251 ChangePage[x][y] = -1;
3252 Pushed[x][y] = FALSE;
3255 ExplodeField[x][y] = EX_TYPE_NONE;
3258 GfxElement[x][y] = EL_UNDEFINED;
3259 GfxAction[x][y] = ACTION_DEFAULT;
3260 GfxDir[x][y] = MV_NONE;
3263 void RemoveMovingField(int x, int y)
3265 int oldx = x, oldy = y, newx = x, newy = y;
3266 int element = Feld[x][y];
3267 int next_element = EL_UNDEFINED;
3269 if (element != EL_BLOCKED && !IS_MOVING(x, y))
3272 if (IS_MOVING(x, y))
3274 Moving2Blocked(x, y, &newx, &newy);
3276 if (Feld[newx][newy] != EL_BLOCKED)
3278 /* element is moving, but target field is not free (blocked), but
3279 already occupied by something different (example: acid pool);
3280 in this case, only remove the moving field, but not the target */
3282 RemoveField(oldx, oldy);
3284 Store[oldx][oldy] = Store2[oldx][oldy] = 0;
3286 DrawLevelField(oldx, oldy);
3291 else if (element == EL_BLOCKED)
3293 Blocked2Moving(x, y, &oldx, &oldy);
3294 if (!IS_MOVING(oldx, oldy))
3298 if (element == EL_BLOCKED &&
3299 (Feld[oldx][oldy] == EL_QUICKSAND_EMPTYING ||
3300 Feld[oldx][oldy] == EL_MAGIC_WALL_EMPTYING ||
3301 Feld[oldx][oldy] == EL_BD_MAGIC_WALL_EMPTYING ||
3302 Feld[oldx][oldy] == EL_AMOEBA_DROPPING))
3303 next_element = get_next_element(Feld[oldx][oldy]);
3305 RemoveField(oldx, oldy);
3306 RemoveField(newx, newy);
3308 Store[oldx][oldy] = Store2[oldx][oldy] = 0;
3310 if (next_element != EL_UNDEFINED)
3311 Feld[oldx][oldy] = next_element;
3313 DrawLevelField(oldx, oldy);
3314 DrawLevelField(newx, newy);
3317 void DrawDynamite(int x, int y)
3319 int sx = SCREENX(x), sy = SCREENY(y);
3320 int graphic = el2img(Feld[x][y]);
3323 if (!IN_SCR_FIELD(sx, sy) || IS_PLAYER(x, y))
3326 if (IS_WALKABLE_INSIDE(Back[x][y]))
3330 DrawGraphic(sx, sy, el2img(Back[x][y]), 0);
3331 else if (Store[x][y])
3332 DrawGraphic(sx, sy, el2img(Store[x][y]), 0);
3334 frame = getGraphicAnimationFrame(graphic, GfxFrame[x][y]);
3336 if (Back[x][y] || Store[x][y])
3337 DrawGraphicThruMask(sx, sy, graphic, frame);
3339 DrawGraphic(sx, sy, graphic, frame);
3342 void CheckDynamite(int x, int y)
3344 if (MovDelay[x][y] != 0) /* dynamite is still waiting to explode */
3348 if (MovDelay[x][y] != 0)
3351 PlayLevelSoundActionIfLoop(x, y, ACTION_ACTIVE);
3357 StopLevelSoundActionIfLoop(x, y, ACTION_ACTIVE);
3364 static void setMinimalPlayerBoundaries(int *sx1, int *sy1, int *sx2, int *sy2)
3366 boolean num_checked_players = 0;
3369 for (i = 0; i < MAX_PLAYERS; i++)
3371 if (stored_player[i].active)
3373 int sx = stored_player[i].jx;
3374 int sy = stored_player[i].jy;
3376 if (num_checked_players == 0)
3383 *sx1 = MIN(*sx1, sx);
3384 *sy1 = MIN(*sy1, sy);
3385 *sx2 = MAX(*sx2, sx);
3386 *sy2 = MAX(*sy2, sy);
3389 num_checked_players++;
3394 static boolean checkIfAllPlayersFitToScreen_RND()
3396 int sx1 = 0, sy1 = 0, sx2 = 0, sy2 = 0;
3398 setMinimalPlayerBoundaries(&sx1, &sy1, &sx2, &sy2);
3400 return (sx2 - sx1 < SCR_FIELDX &&
3401 sy2 - sy1 < SCR_FIELDY);
3404 static void setScreenCenteredToAllPlayers(int *sx, int *sy)
3406 int sx1 = scroll_x, sy1 = scroll_y, sx2 = scroll_x, sy2 = scroll_y;
3408 setMinimalPlayerBoundaries(&sx1, &sy1, &sx2, &sy2);
3410 *sx = (sx1 + sx2) / 2;
3411 *sy = (sy1 + sy2) / 2;
3415 static void setMaxCenterDistanceForAllPlayers(int *max_dx, int *max_dy,
3416 int center_x, int center_y)
3418 int sx1 = center_x, sy1 = center_y, sx2 = center_x, sy2 = center_y;
3420 setMinimalPlayerBoundaries(&sx1, &sy1, &sx2, &sy2);
3422 *max_dx = MAX(ABS(sx1 - center_x), ABS(sx2 - center_x));
3423 *max_dy = MAX(ABS(sy1 - center_y), ABS(sy2 - center_y));
3426 static boolean checkIfAllPlayersAreVisible(int center_x, int center_y)
3430 setMaxCenterDistanceForAllPlayers(&max_dx, &max_dy, center_x, center_y);
3432 return (max_dx <= SCR_FIELDX / 2 &&
3433 max_dy <= SCR_FIELDY / 2);
3441 void DrawRelocateScreen(int x, int y, int move_dir, boolean center_screen,
3442 boolean quick_relocation)
3444 boolean ffwd_delay = (tape.playing && tape.fast_forward);
3445 boolean no_delay = (tape.warp_forward);
3446 int frame_delay_value = (ffwd_delay ? FfwdFrameDelay : GameFrameDelay);
3447 int wait_delay_value = (no_delay ? 0 : frame_delay_value);
3449 if (quick_relocation)
3451 int offset = (setup.scroll_delay ? 3 : 0);
3458 if (!IN_VIS_FIELD(SCREENX(x), SCREENY(y)) || center_screen)
3460 scroll_x = (x < SBX_Left + MIDPOSX ? SBX_Left :
3461 x > SBX_Right + MIDPOSX ? SBX_Right :
3464 scroll_y = (y < SBY_Upper + MIDPOSY ? SBY_Upper :
3465 y > SBY_Lower + MIDPOSY ? SBY_Lower :
3470 if ((move_dir == MV_LEFT && scroll_x > x - MIDPOSX + offset) ||
3471 (move_dir == MV_RIGHT && scroll_x < x - MIDPOSX - offset))
3472 scroll_x = x - MIDPOSX + (scroll_x < x - MIDPOSX ? -offset : +offset);
3474 if ((move_dir == MV_UP && scroll_y > y - MIDPOSY + offset) ||
3475 (move_dir == MV_DOWN && scroll_y < y - MIDPOSY - offset))
3476 scroll_y = y - MIDPOSY + (scroll_y < y - MIDPOSY ? -offset : +offset);
3478 /* don't scroll over playfield boundaries */
3479 if (scroll_x < SBX_Left || scroll_x > SBX_Right)
3480 scroll_x = (scroll_x < SBX_Left ? SBX_Left : SBX_Right);
3482 /* don't scroll over playfield boundaries */
3483 if (scroll_y < SBY_Upper || scroll_y > SBY_Lower)
3484 scroll_y = (scroll_y < SBY_Upper ? SBY_Upper : SBY_Lower);
3487 RedrawPlayfield(TRUE, 0,0,0,0);
3491 int scroll_xx = (x < SBX_Left + MIDPOSX ? SBX_Left :
3492 x > SBX_Right + MIDPOSX ? SBX_Right :
3495 int scroll_yy = (y < SBY_Upper + MIDPOSY ? SBY_Upper :
3496 y > SBY_Lower + MIDPOSY ? SBY_Lower :
3499 ScrollScreen(NULL, SCROLL_GO_ON); /* scroll last frame to full tile */
3501 while (scroll_x != scroll_xx || scroll_y != scroll_yy)
3504 int fx = FX, fy = FY;
3506 dx = (scroll_xx < scroll_x ? +1 : scroll_xx > scroll_x ? -1 : 0);
3507 dy = (scroll_yy < scroll_y ? +1 : scroll_yy > scroll_y ? -1 : 0);
3509 if (dx == 0 && dy == 0) /* no scrolling needed at all */
3515 fx += dx * TILEX / 2;
3516 fy += dy * TILEY / 2;
3518 ScrollLevel(dx, dy);
3521 /* scroll in two steps of half tile size to make things smoother */
3522 BlitBitmap(drawto_field, window, fx, fy, SXSIZE, SYSIZE, SX, SY);
3524 Delay(wait_delay_value);
3526 /* scroll second step to align at full tile size */
3528 Delay(wait_delay_value);
3533 Delay(wait_delay_value);
3539 void DrawRelocatePlayer(struct PlayerInfo *player, boolean quick_relocation)
3541 boolean ffwd_delay = (tape.playing && tape.fast_forward);
3542 boolean no_delay = (tape.warp_forward);
3543 int frame_delay_value = (ffwd_delay ? FfwdFrameDelay : GameFrameDelay);
3544 int wait_delay_value = (no_delay ? 0 : frame_delay_value);
3545 int jx = player->jx;
3546 int jy = player->jy;
3548 if (quick_relocation)
3550 int offset = (setup.scroll_delay ? 3 : 0);
3552 if (!IN_VIS_FIELD(SCREENX(jx), SCREENY(jy)))
3554 scroll_x = (player->jx < SBX_Left + MIDPOSX ? SBX_Left :
3555 player->jx > SBX_Right + MIDPOSX ? SBX_Right :
3556 player->jx - MIDPOSX);
3558 scroll_y = (player->jy < SBY_Upper + MIDPOSY ? SBY_Upper :
3559 player->jy > SBY_Lower + MIDPOSY ? SBY_Lower :
3560 player->jy - MIDPOSY);
3564 if ((player->MovDir == MV_LEFT && scroll_x > jx - MIDPOSX + offset) ||
3565 (player->MovDir == MV_RIGHT && scroll_x < jx - MIDPOSX - offset))
3566 scroll_x = jx - MIDPOSX + (scroll_x < jx-MIDPOSX ? -offset : +offset);
3568 if ((player->MovDir == MV_UP && scroll_y > jy - MIDPOSY + offset) ||
3569 (player->MovDir == MV_DOWN && scroll_y < jy - MIDPOSY - offset))
3570 scroll_y = jy - MIDPOSY + (scroll_y < jy-MIDPOSY ? -offset : +offset);
3572 /* don't scroll over playfield boundaries */
3573 if (scroll_x < SBX_Left || scroll_x > SBX_Right)
3574 scroll_x = (scroll_x < SBX_Left ? SBX_Left : SBX_Right);
3576 /* don't scroll over playfield boundaries */
3577 if (scroll_y < SBY_Upper || scroll_y > SBY_Lower)
3578 scroll_y = (scroll_y < SBY_Upper ? SBY_Upper : SBY_Lower);
3581 RedrawPlayfield(TRUE, 0,0,0,0);
3585 int scroll_xx = (player->jx < SBX_Left + MIDPOSX ? SBX_Left :
3586 player->jx > SBX_Right + MIDPOSX ? SBX_Right :
3587 player->jx - MIDPOSX);
3589 int scroll_yy = (player->jy < SBY_Upper + MIDPOSY ? SBY_Upper :
3590 player->jy > SBY_Lower + MIDPOSY ? SBY_Lower :
3591 player->jy - MIDPOSY);
3593 ScrollScreen(NULL, SCROLL_GO_ON); /* scroll last frame to full tile */
3595 while (scroll_x != scroll_xx || scroll_y != scroll_yy)
3598 int fx = FX, fy = FY;
3600 dx = (scroll_xx < scroll_x ? +1 : scroll_xx > scroll_x ? -1 : 0);
3601 dy = (scroll_yy < scroll_y ? +1 : scroll_yy > scroll_y ? -1 : 0);
3603 if (dx == 0 && dy == 0) /* no scrolling needed at all */
3609 fx += dx * TILEX / 2;
3610 fy += dy * TILEY / 2;
3612 ScrollLevel(dx, dy);
3615 /* scroll in two steps of half tile size to make things smoother */
3616 BlitBitmap(drawto_field, window, fx, fy, SXSIZE, SYSIZE, SX, SY);
3618 Delay(wait_delay_value);
3620 /* scroll second step to align at full tile size */
3622 Delay(wait_delay_value);
3627 Delay(wait_delay_value);
3633 void RelocatePlayer(int jx, int jy, int el_player_raw)
3635 int el_player = GET_PLAYER_ELEMENT(el_player_raw);
3636 int player_nr = GET_PLAYER_NR(el_player);
3637 struct PlayerInfo *player = &stored_player[player_nr];
3638 boolean ffwd_delay = (tape.playing && tape.fast_forward);
3639 boolean no_delay = (tape.warp_forward);
3640 int frame_delay_value = (ffwd_delay ? FfwdFrameDelay : GameFrameDelay);
3641 int wait_delay_value = (no_delay ? 0 : frame_delay_value);
3642 int old_jx = player->jx;
3643 int old_jy = player->jy;
3644 int old_element = Feld[old_jx][old_jy];
3645 int element = Feld[jx][jy];
3646 boolean player_relocated = (old_jx != jx || old_jy != jy);
3648 int move_dir_horiz = (jx < old_jx ? MV_LEFT : jx > old_jx ? MV_RIGHT : 0);
3649 int move_dir_vert = (jy < old_jy ? MV_UP : jy > old_jy ? MV_DOWN : 0);
3650 int enter_side_horiz = MV_DIR_OPPOSITE(move_dir_horiz);
3651 int enter_side_vert = MV_DIR_OPPOSITE(move_dir_vert);
3652 int leave_side_horiz = move_dir_horiz;
3653 int leave_side_vert = move_dir_vert;
3654 int enter_side = enter_side_horiz | enter_side_vert;
3655 int leave_side = leave_side_horiz | leave_side_vert;
3657 if (player->GameOver) /* do not reanimate dead player */
3660 if (!player_relocated) /* no need to relocate the player */
3663 if (IS_PLAYER(jx, jy)) /* player already placed at new position */
3665 RemoveField(jx, jy); /* temporarily remove newly placed player */
3666 DrawLevelField(jx, jy);
3669 if (player->present)
3671 while (player->MovPos)
3673 ScrollPlayer(player, SCROLL_GO_ON);
3674 ScrollScreen(NULL, SCROLL_GO_ON);
3676 AdvanceFrameAndPlayerCounters(player->index_nr);
3681 Delay(wait_delay_value);
3684 DrawPlayer(player); /* needed here only to cleanup last field */
3685 DrawLevelField(player->jx, player->jy); /* remove player graphic */
3687 player->is_moving = FALSE;
3690 if (IS_CUSTOM_ELEMENT(old_element))
3691 CheckElementChangeByPlayer(old_jx, old_jy, old_element,
3693 player->index_bit, leave_side);
3695 CheckTriggeredElementChangeByPlayer(old_jx, old_jy, old_element,
3697 player->index_bit, leave_side);
3699 Feld[jx][jy] = el_player;
3700 InitPlayerField(jx, jy, el_player, TRUE);
3702 if (!ELEM_IS_PLAYER(element)) /* player may be set on walkable element */
3704 Feld[jx][jy] = element;
3705 InitField(jx, jy, FALSE);
3709 /* only visually relocate centered player */
3711 DrawRelocateScreen(player->jx, player->jy, player->MovDir, FALSE,
3712 level.instant_relocation);
3714 if (player->index_nr == game.centered_player_nr)
3715 DrawRelocatePlayer(player, level.instant_relocation);
3718 if (player == local_player) /* only visually relocate local player */
3719 DrawRelocatePlayer(player, level.instant_relocation);
3722 TestIfPlayerTouchesBadThing(jx, jy);
3723 TestIfPlayerTouchesCustomElement(jx, jy);
3725 if (IS_CUSTOM_ELEMENT(element))
3726 CheckElementChangeByPlayer(jx, jy, element, CE_ENTERED_BY_PLAYER,
3727 player->index_bit, enter_side);
3729 CheckTriggeredElementChangeByPlayer(jx, jy, element, CE_PLAYER_ENTERS_X,
3730 player->index_bit, enter_side);
3733 void Explode(int ex, int ey, int phase, int mode)
3739 /* !!! eliminate this variable !!! */
3740 int delay = (game.emulation == EMU_SUPAPLEX ? 3 : 2);
3742 if (game.explosions_delayed)
3744 ExplodeField[ex][ey] = mode;
3748 if (phase == EX_PHASE_START) /* initialize 'Store[][]' field */
3750 int center_element = Feld[ex][ey];
3751 int artwork_element, explosion_element; /* set these values later */
3754 /* --- This is only really needed (and now handled) in "Impact()". --- */
3755 /* do not explode moving elements that left the explode field in time */
3756 if (game.engine_version >= VERSION_IDENT(2,2,0,7) &&
3757 center_element == EL_EMPTY &&
3758 (mode == EX_TYPE_NORMAL || mode == EX_TYPE_CENTER))
3763 /* !!! at this place, the center element may be EL_BLOCKED !!! */
3764 if (mode == EX_TYPE_NORMAL ||
3765 mode == EX_TYPE_CENTER ||
3766 mode == EX_TYPE_CROSS)
3767 PlayLevelSoundElementAction(ex, ey, artwork_element, ACTION_EXPLODING);
3770 /* remove things displayed in background while burning dynamite */
3771 if (Back[ex][ey] != EL_EMPTY && !IS_INDESTRUCTIBLE(Back[ex][ey]))
3774 if (IS_MOVING(ex, ey) || IS_BLOCKED(ex, ey))
3776 /* put moving element to center field (and let it explode there) */
3777 center_element = MovingOrBlocked2Element(ex, ey);
3778 RemoveMovingField(ex, ey);
3779 Feld[ex][ey] = center_element;
3782 /* now "center_element" is finally determined -- set related values now */
3783 artwork_element = center_element; /* for custom player artwork */
3784 explosion_element = center_element; /* for custom player artwork */
3786 if (IS_PLAYER(ex, ey))
3788 int player_nr = GET_PLAYER_NR(StorePlayer[ex][ey]);
3790 artwork_element = stored_player[player_nr].artwork_element;
3792 if (level.use_explosion_element[player_nr])
3794 explosion_element = level.explosion_element[player_nr];
3795 artwork_element = explosion_element;
3800 if (mode == EX_TYPE_NORMAL ||
3801 mode == EX_TYPE_CENTER ||
3802 mode == EX_TYPE_CROSS)
3803 PlayLevelSoundElementAction(ex, ey, artwork_element, ACTION_EXPLODING);
3807 last_phase = element_info[explosion_element].explosion_delay + 1;
3809 last_phase = element_info[center_element].explosion_delay + 1;
3812 for (y = ey - 1; y <= ey + 1; y++) for (x = ex - 1; x <= ex + 1; x++)
3814 int xx = x - ex + 1;
3815 int yy = y - ey + 1;
3818 if (!IN_LEV_FIELD(x, y) ||
3819 (mode & EX_TYPE_SINGLE_TILE && (x != ex || y != ey)) ||
3820 (mode == EX_TYPE_CROSS && (x != ex && y != ey)))
3823 element = Feld[x][y];
3825 if (IS_MOVING(x, y) || IS_BLOCKED(x, y))
3827 element = MovingOrBlocked2Element(x, y);
3829 if (!IS_EXPLOSION_PROOF(element))
3830 RemoveMovingField(x, y);
3833 /* indestructible elements can only explode in center (but not flames) */
3834 if ((IS_EXPLOSION_PROOF(element) && (x != ex || y != ey ||
3835 mode == EX_TYPE_BORDER)) ||
3836 element == EL_FLAMES)
3839 /* no idea why this was changed from 3.0.8 to 3.1.0 -- this causes buggy
3840 behaviour, for example when touching a yamyam that explodes to rocks
3841 with active deadly shield, a rock is created under the player !!! */
3842 /* (case 1 (surely buggy): >= 3.1.0, case 2 (maybe buggy): <= 3.0.8) */
3844 if (IS_PLAYER(x, y) && SHIELD_ON(PLAYERINFO(x, y)) &&
3845 (game.engine_version < VERSION_IDENT(3,1,0,0) ||
3846 (x == ex && y == ey && mode != EX_TYPE_BORDER)))
3848 if (IS_PLAYER(x, y) && SHIELD_ON(PLAYERINFO(x, y)))
3851 if (IS_ACTIVE_BOMB(element))
3853 /* re-activate things under the bomb like gate or penguin */
3854 Feld[x][y] = (Back[x][y] ? Back[x][y] : EL_EMPTY);
3861 /* save walkable background elements while explosion on same tile */
3862 if (IS_WALKABLE(element) && IS_INDESTRUCTIBLE(element) &&
3863 (x != ex || y != ey || mode == EX_TYPE_BORDER))
3864 Back[x][y] = element;
3866 /* ignite explodable elements reached by other explosion */
3867 if (element == EL_EXPLOSION)
3868 element = Store2[x][y];
3870 if (AmoebaNr[x][y] &&
3871 (element == EL_AMOEBA_FULL ||
3872 element == EL_BD_AMOEBA ||
3873 element == EL_AMOEBA_GROWING))
3875 AmoebaCnt[AmoebaNr[x][y]]--;
3876 AmoebaCnt2[AmoebaNr[x][y]]--;
3881 if (IS_PLAYER(ex, ey) && !PLAYER_EXPLOSION_PROTECTED(ex, ey))
3884 int player_nr = StorePlayer[ex][ey] - EL_PLAYER_1;
3886 Store[x][y] = EL_PLAYER_IS_EXPLODING_1 + player_nr;
3888 switch(StorePlayer[ex][ey])
3891 Store[x][y] = EL_PLAYER_IS_EXPLODING_2;
3894 Store[x][y] = EL_PLAYER_IS_EXPLODING_3;
3897 Store[x][y] = EL_PLAYER_IS_EXPLODING_4;
3901 Store[x][y] = EL_PLAYER_IS_EXPLODING_1;
3906 if (PLAYERINFO(ex, ey)->use_murphy)
3907 Store[x][y] = EL_EMPTY;
3910 /* !!! check this case -- currently needed for rnd_rado_negundo_v,
3911 !!! levels 015 018 019 020 021 022 023 026 027 028 !!! */
3912 else if (ELEM_IS_PLAYER(center_element))
3913 Store[x][y] = EL_EMPTY;
3914 else if (center_element == EL_YAMYAM)
3915 Store[x][y] = level.yamyam_content[game.yamyam_content_nr].e[xx][yy];
3916 else if (element_info[center_element].content.e[xx][yy] != EL_EMPTY)
3917 Store[x][y] = element_info[center_element].content.e[xx][yy];
3919 /* needed because EL_BD_BUTTERFLY is not defined as "CAN_EXPLODE"
3920 (killing EL_BD_BUTTERFLY with dynamite would result in BD diamond
3921 otherwise) -- FIX THIS !!! */
3922 else if (!CAN_EXPLODE(element) && element != EL_BD_BUTTERFLY)
3923 Store[x][y] = element_info[element].content.e[1][1];
3925 else if (!CAN_EXPLODE(element))
3926 Store[x][y] = element_info[element].content.e[1][1];
3929 Store[x][y] = EL_EMPTY;
3931 else if (center_element == EL_MOLE)
3932 Store[x][y] = EL_EMERALD_RED;
3933 else if (center_element == EL_PENGUIN)
3934 Store[x][y] = EL_EMERALD_PURPLE;
3935 else if (center_element == EL_BUG)
3936 Store[x][y] = ((x == ex && y == ey) ? EL_DIAMOND : EL_EMERALD);
3937 else if (center_element == EL_BD_BUTTERFLY)
3938 Store[x][y] = EL_BD_DIAMOND;
3939 else if (center_element == EL_SP_ELECTRON)
3940 Store[x][y] = EL_SP_INFOTRON;
3941 else if (center_element == EL_AMOEBA_TO_DIAMOND)
3942 Store[x][y] = level.amoeba_content;
3943 else if (center_element == EL_YAMYAM)
3944 Store[x][y] = level.yamyam_content[game.yamyam_content_nr].e[xx][yy];
3945 else if (IS_CUSTOM_ELEMENT(center_element) &&
3946 element_info[center_element].content.e[xx][yy] != EL_EMPTY)
3947 Store[x][y] = element_info[center_element].content.e[xx][yy];
3948 else if (element == EL_WALL_EMERALD)
3949 Store[x][y] = EL_EMERALD;
3950 else if (element == EL_WALL_DIAMOND)
3951 Store[x][y] = EL_DIAMOND;
3952 else if (element == EL_WALL_BD_DIAMOND)
3953 Store[x][y] = EL_BD_DIAMOND;
3954 else if (element == EL_WALL_EMERALD_YELLOW)
3955 Store[x][y] = EL_EMERALD_YELLOW;
3956 else if (element == EL_WALL_EMERALD_RED)
3957 Store[x][y] = EL_EMERALD_RED;
3958 else if (element == EL_WALL_EMERALD_PURPLE)
3959 Store[x][y] = EL_EMERALD_PURPLE;
3960 else if (element == EL_WALL_PEARL)
3961 Store[x][y] = EL_PEARL;
3962 else if (element == EL_WALL_CRYSTAL)
3963 Store[x][y] = EL_CRYSTAL;
3964 else if (IS_CUSTOM_ELEMENT(element) && !CAN_EXPLODE(element))
3965 Store[x][y] = element_info[element].content.e[1][1];
3967 Store[x][y] = EL_EMPTY;
3970 if (x != ex || y != ey || mode == EX_TYPE_BORDER ||
3971 center_element == EL_AMOEBA_TO_DIAMOND)
3972 Store2[x][y] = element;
3974 Feld[x][y] = EL_EXPLOSION;
3975 GfxElement[x][y] = artwork_element;
3978 printf(":: setting gfx(%d,%d) to %d ['%s']\n",
3979 x, y, artwork_element, EL_NAME(artwork_element));
3982 ExplodePhase[x][y] = 1;
3983 ExplodeDelay[x][y] = last_phase;
3988 if (center_element == EL_YAMYAM)
3989 game.yamyam_content_nr =
3990 (game.yamyam_content_nr + 1) % level.num_yamyam_contents;
4002 GfxFrame[x][y] = 0; /* restart explosion animation */
4004 last_phase = ExplodeDelay[x][y];
4006 ExplodePhase[x][y] = (phase < last_phase ? phase + 1 : 0);
4010 /* activate this even in non-DEBUG version until cause for crash in
4011 getGraphicAnimationFrame() (see below) is found and eliminated */
4017 /* this can happen if the player leaves an explosion just in time */
4018 if (GfxElement[x][y] == EL_UNDEFINED)
4019 GfxElement[x][y] = EL_EMPTY;
4021 if (GfxElement[x][y] == EL_UNDEFINED)
4024 printf("Explode(): x = %d, y = %d: GfxElement == EL_UNDEFINED\n", x, y);
4025 printf("Explode(): This should never happen!\n");
4028 GfxElement[x][y] = EL_EMPTY;
4034 border_element = Store2[x][y];
4035 if (IS_PLAYER(x, y) && !PLAYER_EXPLOSION_PROTECTED(x, y))
4036 border_element = StorePlayer[x][y];
4038 if (phase == element_info[border_element].ignition_delay ||
4039 phase == last_phase)
4041 boolean border_explosion = FALSE;
4043 if (IS_PLAYER(x, y) && PLAYERINFO(x, y)->present &&
4044 !PLAYER_EXPLOSION_PROTECTED(x, y))
4046 KillPlayerUnlessExplosionProtected(x, y);
4047 border_explosion = TRUE;
4049 else if (CAN_EXPLODE_BY_EXPLOSION(border_element))
4051 Feld[x][y] = Store2[x][y];
4054 border_explosion = TRUE;
4056 else if (border_element == EL_AMOEBA_TO_DIAMOND)
4058 AmoebeUmwandeln(x, y);
4060 border_explosion = TRUE;
4063 /* if an element just explodes due to another explosion (chain-reaction),
4064 do not immediately end the new explosion when it was the last frame of
4065 the explosion (as it would be done in the following "if"-statement!) */
4066 if (border_explosion && phase == last_phase)
4070 if (phase == last_phase)
4074 element = Feld[x][y] = Store[x][y];
4075 Store[x][y] = Store2[x][y] = 0;
4076 GfxElement[x][y] = EL_UNDEFINED;
4078 /* player can escape from explosions and might therefore be still alive */
4079 if (element >= EL_PLAYER_IS_EXPLODING_1 &&
4080 element <= EL_PLAYER_IS_EXPLODING_4)
4082 int player_nr = element - EL_PLAYER_IS_EXPLODING_1;
4083 int explosion_element = EL_PLAYER_1 + player_nr;
4084 int xx = MIN(MAX(0, x - stored_player[player_nr].jx + 1), 2);
4085 int yy = MIN(MAX(0, y - stored_player[player_nr].jy + 1), 2);
4087 if (level.use_explosion_element[player_nr])
4088 explosion_element = level.explosion_element[player_nr];
4090 Feld[x][y] = (stored_player[player_nr].active ? EL_EMPTY :
4091 element_info[explosion_element].content.e[xx][yy]);
4094 /* restore probably existing indestructible background element */
4095 if (Back[x][y] && IS_INDESTRUCTIBLE(Back[x][y]))
4096 element = Feld[x][y] = Back[x][y];
4099 MovDir[x][y] = MovPos[x][y] = MovDelay[x][y] = 0;
4100 GfxDir[x][y] = MV_NONE;
4101 ChangeDelay[x][y] = 0;
4102 ChangePage[x][y] = -1;
4104 #if USE_NEW_CUSTOM_VALUE
4105 CustomValue[x][y] = 0;
4108 InitField_WithBug2(x, y, FALSE);
4110 DrawLevelField(x, y);
4112 TestIfElementTouchesCustomElement(x, y);
4114 if (GFX_CRUMBLED(element))
4115 DrawLevelFieldCrumbledSandNeighbours(x, y);
4117 if (IS_PLAYER(x, y) && !PLAYERINFO(x, y)->present)
4118 StorePlayer[x][y] = 0;
4120 if (ELEM_IS_PLAYER(element))
4121 RelocatePlayer(x, y, element);
4123 else if (IN_SCR_FIELD(SCREENX(x), SCREENY(y)))
4125 int graphic = el_act2img(GfxElement[x][y], ACTION_EXPLODING);
4126 int frame = getGraphicAnimationFrame(graphic, GfxFrame[x][y]);
4129 DrawLevelFieldCrumbledSand(x, y);
4131 if (IS_WALKABLE_OVER(Back[x][y]) && Back[x][y] != EL_EMPTY)
4133 DrawLevelElement(x, y, Back[x][y]);
4134 DrawGraphicThruMask(SCREENX(x), SCREENY(y), graphic, frame);
4136 else if (IS_WALKABLE_UNDER(Back[x][y]))
4138 DrawGraphic(SCREENX(x), SCREENY(y), graphic, frame);
4139 DrawLevelElementThruMask(x, y, Back[x][y]);
4141 else if (!IS_WALKABLE_INSIDE(Back[x][y]))
4142 DrawGraphic(SCREENX(x), SCREENY(y), graphic, frame);
4146 void DynaExplode(int ex, int ey)
4149 int dynabomb_element = Feld[ex][ey];
4150 int dynabomb_size = 1;
4151 boolean dynabomb_xl = FALSE;
4152 struct PlayerInfo *player;
4153 static int xy[4][2] =
4161 if (IS_ACTIVE_BOMB(dynabomb_element))
4163 player = &stored_player[dynabomb_element - EL_DYNABOMB_PLAYER_1_ACTIVE];
4164 dynabomb_size = player->dynabomb_size;
4165 dynabomb_xl = player->dynabomb_xl;
4166 player->dynabombs_left++;
4169 Explode(ex, ey, EX_PHASE_START, EX_TYPE_CENTER);
4171 for (i = 0; i < NUM_DIRECTIONS; i++)
4173 for (j = 1; j <= dynabomb_size; j++)
4175 int x = ex + j * xy[i][0];
4176 int y = ey + j * xy[i][1];
4179 if (!IN_LEV_FIELD(x, y) || IS_INDESTRUCTIBLE(Feld[x][y]))
4182 element = Feld[x][y];
4184 /* do not restart explosions of fields with active bombs */
4185 if (element == EL_EXPLOSION && IS_ACTIVE_BOMB(Store2[x][y]))
4188 Explode(x, y, EX_PHASE_START, EX_TYPE_BORDER);
4190 if (element != EL_EMPTY && element != EL_EXPLOSION &&
4191 !IS_DIGGABLE(element) && !dynabomb_xl)
4197 void Bang(int x, int y)
4199 int element = MovingOrBlocked2Element(x, y);
4200 int explosion_type = EX_TYPE_NORMAL;
4202 if (IS_PLAYER(x, y) && !PLAYER_EXPLOSION_PROTECTED(x, y))
4204 struct PlayerInfo *player = PLAYERINFO(x, y);
4206 element = Feld[x][y] = (player->use_murphy ? EL_SP_MURPHY :
4207 player->element_nr);
4209 if (level.use_explosion_element[player->index_nr])
4211 int explosion_element = level.explosion_element[player->index_nr];
4213 if (element_info[explosion_element].explosion_type == EXPLODES_CROSS)
4214 explosion_type = EX_TYPE_CROSS;
4215 else if (element_info[explosion_element].explosion_type == EXPLODES_1X1)
4216 explosion_type = EX_TYPE_CENTER;
4224 case EL_BD_BUTTERFLY:
4227 case EL_DARK_YAMYAM:
4231 RaiseScoreElement(element);
4234 case EL_DYNABOMB_PLAYER_1_ACTIVE:
4235 case EL_DYNABOMB_PLAYER_2_ACTIVE:
4236 case EL_DYNABOMB_PLAYER_3_ACTIVE:
4237 case EL_DYNABOMB_PLAYER_4_ACTIVE:
4238 case EL_DYNABOMB_INCREASE_NUMBER:
4239 case EL_DYNABOMB_INCREASE_SIZE:
4240 case EL_DYNABOMB_INCREASE_POWER:
4241 explosion_type = EX_TYPE_DYNA;
4246 case EL_LAMP_ACTIVE:
4247 case EL_AMOEBA_TO_DIAMOND:
4248 if (!IS_PLAYER(x, y)) /* penguin and player may be at same field */
4249 explosion_type = EX_TYPE_CENTER;
4253 if (element_info[element].explosion_type == EXPLODES_CROSS)
4254 explosion_type = EX_TYPE_CROSS;
4255 else if (element_info[element].explosion_type == EXPLODES_1X1)
4256 explosion_type = EX_TYPE_CENTER;
4260 if (explosion_type == EX_TYPE_DYNA)
4263 Explode(x, y, EX_PHASE_START, explosion_type);
4265 CheckTriggeredElementChange(x, y, element, CE_EXPLOSION_OF_X);
4268 void SplashAcid(int x, int y)
4270 if (IN_LEV_FIELD(x - 1, y - 1) && IS_FREE(x - 1, y - 1) &&
4271 (!IN_LEV_FIELD(x - 1, y - 2) ||
4272 !CAN_FALL(MovingOrBlocked2Element(x - 1, y - 2))))
4273 Feld[x - 1][y - 1] = EL_ACID_SPLASH_LEFT;
4275 if (IN_LEV_FIELD(x + 1, y - 1) && IS_FREE(x + 1, y - 1) &&
4276 (!IN_LEV_FIELD(x + 1, y - 2) ||
4277 !CAN_FALL(MovingOrBlocked2Element(x + 1, y - 2))))
4278 Feld[x + 1][y - 1] = EL_ACID_SPLASH_RIGHT;
4280 PlayLevelSound(x, y, SND_ACID_SPLASHING);
4283 static void InitBeltMovement()
4285 static int belt_base_element[4] =
4287 EL_CONVEYOR_BELT_1_LEFT,
4288 EL_CONVEYOR_BELT_2_LEFT,
4289 EL_CONVEYOR_BELT_3_LEFT,
4290 EL_CONVEYOR_BELT_4_LEFT
4292 static int belt_base_active_element[4] =
4294 EL_CONVEYOR_BELT_1_LEFT_ACTIVE,
4295 EL_CONVEYOR_BELT_2_LEFT_ACTIVE,
4296 EL_CONVEYOR_BELT_3_LEFT_ACTIVE,
4297 EL_CONVEYOR_BELT_4_LEFT_ACTIVE
4302 /* set frame order for belt animation graphic according to belt direction */
4303 for (i = 0; i < NUM_BELTS; i++)
4307 for (j = 0; j < NUM_BELT_PARTS; j++)
4309 int element = belt_base_active_element[belt_nr] + j;
4310 int graphic = el2img(element);
4312 if (game.belt_dir[i] == MV_LEFT)
4313 graphic_info[graphic].anim_mode &= ~ANIM_REVERSE;
4315 graphic_info[graphic].anim_mode |= ANIM_REVERSE;
4320 SCAN_PLAYFIELD(x, y)
4322 for (y = 0; y < lev_fieldy; y++) for (x = 0; x < lev_fieldx; x++)
4325 int element = Feld[x][y];
4327 for (i = 0; i < NUM_BELTS; i++)
4329 if (IS_BELT(element) && game.belt_dir[i] != MV_NONE)
4331 int e_belt_nr = getBeltNrFromBeltElement(element);
4334 if (e_belt_nr == belt_nr)
4336 int belt_part = Feld[x][y] - belt_base_element[belt_nr];
4338 Feld[x][y] = belt_base_active_element[belt_nr] + belt_part;
4345 static void ToggleBeltSwitch(int x, int y)
4347 static int belt_base_element[4] =
4349 EL_CONVEYOR_BELT_1_LEFT,
4350 EL_CONVEYOR_BELT_2_LEFT,
4351 EL_CONVEYOR_BELT_3_LEFT,
4352 EL_CONVEYOR_BELT_4_LEFT
4354 static int belt_base_active_element[4] =
4356 EL_CONVEYOR_BELT_1_LEFT_ACTIVE,
4357 EL_CONVEYOR_BELT_2_LEFT_ACTIVE,
4358 EL_CONVEYOR_BELT_3_LEFT_ACTIVE,
4359 EL_CONVEYOR_BELT_4_LEFT_ACTIVE
4361 static int belt_base_switch_element[4] =
4363 EL_CONVEYOR_BELT_1_SWITCH_LEFT,
4364 EL_CONVEYOR_BELT_2_SWITCH_LEFT,
4365 EL_CONVEYOR_BELT_3_SWITCH_LEFT,
4366 EL_CONVEYOR_BELT_4_SWITCH_LEFT
4368 static int belt_move_dir[4] =
4376 int element = Feld[x][y];
4377 int belt_nr = getBeltNrFromBeltSwitchElement(element);
4378 int belt_dir_nr = (game.belt_dir_nr[belt_nr] + 1) % 4;
4379 int belt_dir = belt_move_dir[belt_dir_nr];
4382 if (!IS_BELT_SWITCH(element))
4385 game.belt_dir_nr[belt_nr] = belt_dir_nr;
4386 game.belt_dir[belt_nr] = belt_dir;
4388 if (belt_dir_nr == 3)
4391 /* set frame order for belt animation graphic according to belt direction */
4392 for (i = 0; i < NUM_BELT_PARTS; i++)
4394 int element = belt_base_active_element[belt_nr] + i;
4395 int graphic = el2img(element);
4397 if (belt_dir == MV_LEFT)
4398 graphic_info[graphic].anim_mode &= ~ANIM_REVERSE;
4400 graphic_info[graphic].anim_mode |= ANIM_REVERSE;
4404 SCAN_PLAYFIELD(xx, yy)
4406 for (yy = 0; yy < lev_fieldy; yy++) for (xx = 0; xx < lev_fieldx; xx++)
4409 int element = Feld[xx][yy];
4411 if (IS_BELT_SWITCH(element))
4413 int e_belt_nr = getBeltNrFromBeltSwitchElement(element);
4415 if (e_belt_nr == belt_nr)
4417 Feld[xx][yy] = belt_base_switch_element[belt_nr] + belt_dir_nr;
4418 DrawLevelField(xx, yy);
4421 else if (IS_BELT(element) && belt_dir != MV_NONE)
4423 int e_belt_nr = getBeltNrFromBeltElement(element);
4425 if (e_belt_nr == belt_nr)
4427 int belt_part = Feld[xx][yy] - belt_base_element[belt_nr];
4429 Feld[xx][yy] = belt_base_active_element[belt_nr] + belt_part;
4430 DrawLevelField(xx, yy);
4433 else if (IS_BELT_ACTIVE(element) && belt_dir == MV_NONE)
4435 int e_belt_nr = getBeltNrFromBeltActiveElement(element);
4437 if (e_belt_nr == belt_nr)
4439 int belt_part = Feld[xx][yy] - belt_base_active_element[belt_nr];
4441 Feld[xx][yy] = belt_base_element[belt_nr] + belt_part;
4442 DrawLevelField(xx, yy);
4448 static void ToggleSwitchgateSwitch(int x, int y)
4452 game.switchgate_pos = !game.switchgate_pos;
4455 SCAN_PLAYFIELD(xx, yy)
4457 for (yy = 0; yy < lev_fieldy; yy++) for (xx = 0; xx < lev_fieldx; xx++)
4460 int element = Feld[xx][yy];
4462 #if !USE_BOTH_SWITCHGATE_SWITCHES
4463 if (element == EL_SWITCHGATE_SWITCH_UP ||
4464 element == EL_SWITCHGATE_SWITCH_DOWN)
4466 Feld[xx][yy] = EL_SWITCHGATE_SWITCH_UP + game.switchgate_pos;
4467 DrawLevelField(xx, yy);
4470 if (element == EL_SWITCHGATE_SWITCH_UP)
4472 Feld[xx][yy] = EL_SWITCHGATE_SWITCH_DOWN;
4473 DrawLevelField(xx, yy);
4475 else if (element == EL_SWITCHGATE_SWITCH_DOWN)
4477 Feld[xx][yy] = EL_SWITCHGATE_SWITCH_UP;
4478 DrawLevelField(xx, yy);
4481 else if (element == EL_SWITCHGATE_OPEN ||
4482 element == EL_SWITCHGATE_OPENING)
4484 Feld[xx][yy] = EL_SWITCHGATE_CLOSING;
4486 PlayLevelSoundAction(xx, yy, ACTION_CLOSING);
4488 else if (element == EL_SWITCHGATE_CLOSED ||
4489 element == EL_SWITCHGATE_CLOSING)
4491 Feld[xx][yy] = EL_SWITCHGATE_OPENING;
4493 PlayLevelSoundAction(xx, yy, ACTION_OPENING);
4498 static int getInvisibleActiveFromInvisibleElement(int element)
4500 return (element == EL_INVISIBLE_STEELWALL ? EL_INVISIBLE_STEELWALL_ACTIVE :
4501 element == EL_INVISIBLE_WALL ? EL_INVISIBLE_WALL_ACTIVE :
4502 element == EL_INVISIBLE_SAND ? EL_INVISIBLE_SAND_ACTIVE :
4506 static int getInvisibleFromInvisibleActiveElement(int element)
4508 return (element == EL_INVISIBLE_STEELWALL_ACTIVE ? EL_INVISIBLE_STEELWALL :
4509 element == EL_INVISIBLE_WALL_ACTIVE ? EL_INVISIBLE_WALL :
4510 element == EL_INVISIBLE_SAND_ACTIVE ? EL_INVISIBLE_SAND :
4514 static void RedrawAllLightSwitchesAndInvisibleElements()
4519 SCAN_PLAYFIELD(x, y)
4521 for (y = 0; y < lev_fieldy; y++) for (x = 0; x < lev_fieldx; x++)
4524 int element = Feld[x][y];
4526 if (element == EL_LIGHT_SWITCH &&
4527 game.light_time_left > 0)
4529 Feld[x][y] = EL_LIGHT_SWITCH_ACTIVE;
4530 DrawLevelField(x, y);
4532 else if (element == EL_LIGHT_SWITCH_ACTIVE &&
4533 game.light_time_left == 0)
4535 Feld[x][y] = EL_LIGHT_SWITCH;
4536 DrawLevelField(x, y);
4538 else if (element == EL_EMC_DRIPPER &&
4539 game.light_time_left > 0)
4541 Feld[x][y] = EL_EMC_DRIPPER_ACTIVE;
4542 DrawLevelField(x, y);
4544 else if (element == EL_EMC_DRIPPER_ACTIVE &&
4545 game.light_time_left == 0)
4547 Feld[x][y] = EL_EMC_DRIPPER;
4548 DrawLevelField(x, y);
4550 else if (element == EL_INVISIBLE_STEELWALL ||
4551 element == EL_INVISIBLE_WALL ||
4552 element == EL_INVISIBLE_SAND)
4554 if (game.light_time_left > 0)
4555 Feld[x][y] = getInvisibleActiveFromInvisibleElement(element);
4557 DrawLevelField(x, y);
4559 /* uncrumble neighbour fields, if needed */
4560 if (element == EL_INVISIBLE_SAND)
4561 DrawLevelFieldCrumbledSandNeighbours(x, y);
4563 else if (element == EL_INVISIBLE_STEELWALL_ACTIVE ||
4564 element == EL_INVISIBLE_WALL_ACTIVE ||
4565 element == EL_INVISIBLE_SAND_ACTIVE)
4567 if (game.light_time_left == 0)
4568 Feld[x][y] = getInvisibleFromInvisibleActiveElement(element);
4570 DrawLevelField(x, y);
4572 /* re-crumble neighbour fields, if needed */
4573 if (element == EL_INVISIBLE_SAND)
4574 DrawLevelFieldCrumbledSandNeighbours(x, y);
4579 static void RedrawAllInvisibleElementsForLenses()
4584 SCAN_PLAYFIELD(x, y)
4586 for (y = 0; y < lev_fieldy; y++) for (x = 0; x < lev_fieldx; x++)
4589 int element = Feld[x][y];
4591 if (element == EL_EMC_DRIPPER &&
4592 game.lenses_time_left > 0)
4594 Feld[x][y] = EL_EMC_DRIPPER_ACTIVE;
4595 DrawLevelField(x, y);
4597 else if (element == EL_EMC_DRIPPER_ACTIVE &&
4598 game.lenses_time_left == 0)
4600 Feld[x][y] = EL_EMC_DRIPPER;
4601 DrawLevelField(x, y);
4603 else if (element == EL_INVISIBLE_STEELWALL ||
4604 element == EL_INVISIBLE_WALL ||
4605 element == EL_INVISIBLE_SAND)
4607 if (game.lenses_time_left > 0)
4608 Feld[x][y] = getInvisibleActiveFromInvisibleElement(element);
4610 DrawLevelField(x, y);
4612 /* uncrumble neighbour fields, if needed */
4613 if (element == EL_INVISIBLE_SAND)
4614 DrawLevelFieldCrumbledSandNeighbours(x, y);
4616 else if (element == EL_INVISIBLE_STEELWALL_ACTIVE ||
4617 element == EL_INVISIBLE_WALL_ACTIVE ||
4618 element == EL_INVISIBLE_SAND_ACTIVE)
4620 if (game.lenses_time_left == 0)
4621 Feld[x][y] = getInvisibleFromInvisibleActiveElement(element);
4623 DrawLevelField(x, y);
4625 /* re-crumble neighbour fields, if needed */
4626 if (element == EL_INVISIBLE_SAND)
4627 DrawLevelFieldCrumbledSandNeighbours(x, y);
4632 static void RedrawAllInvisibleElementsForMagnifier()
4637 SCAN_PLAYFIELD(x, y)
4639 for (y = 0; y < lev_fieldy; y++) for (x = 0; x < lev_fieldx; x++)
4642 int element = Feld[x][y];
4644 if (element == EL_EMC_FAKE_GRASS &&
4645 game.magnify_time_left > 0)
4647 Feld[x][y] = EL_EMC_FAKE_GRASS_ACTIVE;
4648 DrawLevelField(x, y);
4650 else if (element == EL_EMC_FAKE_GRASS_ACTIVE &&
4651 game.magnify_time_left == 0)
4653 Feld[x][y] = EL_EMC_FAKE_GRASS;
4654 DrawLevelField(x, y);
4656 else if (IS_GATE_GRAY(element) &&
4657 game.magnify_time_left > 0)
4659 Feld[x][y] = (IS_RND_GATE_GRAY(element) ?
4660 element - EL_GATE_1_GRAY + EL_GATE_1_GRAY_ACTIVE :
4661 IS_EM_GATE_GRAY(element) ?
4662 element - EL_EM_GATE_1_GRAY + EL_EM_GATE_1_GRAY_ACTIVE :
4663 IS_EMC_GATE_GRAY(element) ?
4664 element - EL_EMC_GATE_5_GRAY + EL_EMC_GATE_5_GRAY_ACTIVE :
4666 DrawLevelField(x, y);
4668 else if (IS_GATE_GRAY_ACTIVE(element) &&
4669 game.magnify_time_left == 0)
4671 Feld[x][y] = (IS_RND_GATE_GRAY_ACTIVE(element) ?
4672 element - EL_GATE_1_GRAY_ACTIVE + EL_GATE_1_GRAY :
4673 IS_EM_GATE_GRAY_ACTIVE(element) ?
4674 element - EL_EM_GATE_1_GRAY_ACTIVE + EL_EM_GATE_1_GRAY :
4675 IS_EMC_GATE_GRAY_ACTIVE(element) ?
4676 element - EL_EMC_GATE_5_GRAY_ACTIVE + EL_EMC_GATE_5_GRAY :
4678 DrawLevelField(x, y);
4683 static void ToggleLightSwitch(int x, int y)
4685 int element = Feld[x][y];
4687 game.light_time_left =
4688 (element == EL_LIGHT_SWITCH ?
4689 level.time_light * FRAMES_PER_SECOND : 0);
4691 RedrawAllLightSwitchesAndInvisibleElements();
4694 static void ActivateTimegateSwitch(int x, int y)
4698 game.timegate_time_left = level.time_timegate * FRAMES_PER_SECOND;
4701 SCAN_PLAYFIELD(xx, yy)
4703 for (yy = 0; yy < lev_fieldy; yy++) for (xx = 0; xx < lev_fieldx; xx++)
4706 int element = Feld[xx][yy];
4708 if (element == EL_TIMEGATE_CLOSED ||
4709 element == EL_TIMEGATE_CLOSING)
4711 Feld[xx][yy] = EL_TIMEGATE_OPENING;
4712 PlayLevelSound(xx, yy, SND_TIMEGATE_OPENING);
4716 else if (element == EL_TIMEGATE_SWITCH_ACTIVE)
4718 Feld[xx][yy] = EL_TIMEGATE_SWITCH;
4719 DrawLevelField(xx, yy);
4725 Feld[x][y] = EL_TIMEGATE_SWITCH_ACTIVE;
4728 void Impact(int x, int y)
4730 boolean last_line = (y == lev_fieldy - 1);
4731 boolean object_hit = FALSE;
4732 boolean impact = (last_line || object_hit);
4733 int element = Feld[x][y];
4734 int smashed = EL_STEELWALL;
4736 if (!last_line) /* check if element below was hit */
4738 if (Feld[x][y + 1] == EL_PLAYER_IS_LEAVING)
4741 object_hit = (!IS_FREE(x, y + 1) && (!IS_MOVING(x, y + 1) ||
4742 MovDir[x][y + 1] != MV_DOWN ||
4743 MovPos[x][y + 1] <= TILEY / 2));
4745 /* do not smash moving elements that left the smashed field in time */
4746 if (game.engine_version >= VERSION_IDENT(2,2,0,7) && IS_MOVING(x, y + 1) &&
4747 ABS(MovPos[x][y + 1] + getElementMoveStepsize(x, y + 1)) >= TILEX)
4750 #if USE_QUICKSAND_IMPACT_BUGFIX
4751 if (Feld[x][y + 1] == EL_QUICKSAND_EMPTYING && object_hit == FALSE)
4753 RemoveMovingField(x, y + 1);
4754 Feld[x][y + 1] = EL_QUICKSAND_EMPTY;
4755 Feld[x][y + 2] = EL_ROCK;
4756 DrawLevelField(x, y + 2);
4763 smashed = MovingOrBlocked2Element(x, y + 1);
4765 impact = (last_line || object_hit);
4768 if (!last_line && smashed == EL_ACID) /* element falls into acid */
4770 SplashAcid(x, y + 1);
4774 /* !!! not sufficient for all cases -- see EL_PEARL below !!! */
4775 /* only reset graphic animation if graphic really changes after impact */
4777 el_act_dir2img(element, GfxAction[x][y], MV_DOWN) != el2img(element))
4779 ResetGfxAnimation(x, y);
4780 DrawLevelField(x, y);
4783 if (impact && CAN_EXPLODE_IMPACT(element))
4788 else if (impact && element == EL_PEARL)
4790 ResetGfxAnimation(x, y);
4792 Feld[x][y] = EL_PEARL_BREAKING;
4793 PlayLevelSound(x, y, SND_PEARL_BREAKING);
4796 else if (impact && CheckElementChange(x, y, element, smashed, CE_IMPACT))
4798 PlayLevelSoundElementAction(x, y, element, ACTION_IMPACT);
4803 if (impact && element == EL_AMOEBA_DROP)
4805 if (object_hit && IS_PLAYER(x, y + 1))
4806 KillPlayerUnlessEnemyProtected(x, y + 1);
4807 else if (object_hit && smashed == EL_PENGUIN)
4811 Feld[x][y] = EL_AMOEBA_GROWING;
4812 Store[x][y] = EL_AMOEBA_WET;
4814 ResetRandomAnimationValue(x, y);
4819 if (object_hit) /* check which object was hit */
4821 if (CAN_PASS_MAGIC_WALL(element) &&
4822 (smashed == EL_MAGIC_WALL ||
4823 smashed == EL_BD_MAGIC_WALL))
4826 int activated_magic_wall =
4827 (smashed == EL_MAGIC_WALL ? EL_MAGIC_WALL_ACTIVE :
4828 EL_BD_MAGIC_WALL_ACTIVE);
4830 /* activate magic wall / mill */
4832 SCAN_PLAYFIELD(xx, yy)
4834 for (yy = 0; yy < lev_fieldy; yy++) for (xx = 0; xx < lev_fieldx; xx++)
4836 if (Feld[xx][yy] == smashed)
4837 Feld[xx][yy] = activated_magic_wall;
4839 game.magic_wall_time_left = level.time_magic_wall * FRAMES_PER_SECOND;
4840 game.magic_wall_active = TRUE;
4842 PlayLevelSound(x, y, (smashed == EL_MAGIC_WALL ?
4843 SND_MAGIC_WALL_ACTIVATING :
4844 SND_BD_MAGIC_WALL_ACTIVATING));
4847 if (IS_PLAYER(x, y + 1))
4849 if (CAN_SMASH_PLAYER(element))
4851 KillPlayerUnlessEnemyProtected(x, y + 1);
4855 else if (smashed == EL_PENGUIN)
4857 if (CAN_SMASH_PLAYER(element))
4863 else if (element == EL_BD_DIAMOND)
4865 if (IS_CLASSIC_ENEMY(smashed) && IS_BD_ELEMENT(smashed))
4871 else if (((element == EL_SP_INFOTRON ||
4872 element == EL_SP_ZONK) &&
4873 (smashed == EL_SP_SNIKSNAK ||
4874 smashed == EL_SP_ELECTRON ||
4875 smashed == EL_SP_DISK_ORANGE)) ||
4876 (element == EL_SP_INFOTRON &&
4877 smashed == EL_SP_DISK_YELLOW))
4882 else if (CAN_SMASH_EVERYTHING(element))
4884 if (IS_CLASSIC_ENEMY(smashed) ||
4885 CAN_EXPLODE_SMASHED(smashed))
4890 else if (!IS_MOVING(x, y + 1) && !IS_BLOCKED(x, y + 1))
4892 if (smashed == EL_LAMP ||
4893 smashed == EL_LAMP_ACTIVE)
4898 else if (smashed == EL_NUT)
4900 Feld[x][y + 1] = EL_NUT_BREAKING;
4901 PlayLevelSound(x, y, SND_NUT_BREAKING);
4902 RaiseScoreElement(EL_NUT);
4905 else if (smashed == EL_PEARL)
4907 ResetGfxAnimation(x, y);
4909 Feld[x][y + 1] = EL_PEARL_BREAKING;
4910 PlayLevelSound(x, y, SND_PEARL_BREAKING);
4913 else if (smashed == EL_DIAMOND)
4915 Feld[x][y + 1] = EL_DIAMOND_BREAKING;
4916 PlayLevelSound(x, y, SND_DIAMOND_BREAKING);
4919 else if (IS_BELT_SWITCH(smashed))
4921 ToggleBeltSwitch(x, y + 1);
4923 else if (smashed == EL_SWITCHGATE_SWITCH_UP ||
4924 smashed == EL_SWITCHGATE_SWITCH_DOWN)
4926 ToggleSwitchgateSwitch(x, y + 1);
4928 else if (smashed == EL_LIGHT_SWITCH ||
4929 smashed == EL_LIGHT_SWITCH_ACTIVE)
4931 ToggleLightSwitch(x, y + 1);
4936 TestIfElementSmashesCustomElement(x, y, MV_DOWN);
4939 CheckElementChange(x, y + 1, smashed, element, CE_SMASHED);
4941 CheckElementChangeBySide(x, y + 1, smashed, element,
4942 CE_SWITCHED, CH_SIDE_TOP);
4943 CheckTriggeredElementChangeBySide(x, y + 1, smashed, CE_SWITCH_OF_X,
4949 CheckElementChange(x, y + 1, smashed, element, CE_SMASHED);
4954 /* play sound of magic wall / mill */
4956 (Feld[x][y + 1] == EL_MAGIC_WALL_ACTIVE ||
4957 Feld[x][y + 1] == EL_BD_MAGIC_WALL_ACTIVE))
4959 if (Feld[x][y + 1] == EL_MAGIC_WALL_ACTIVE)
4960 PlayLevelSound(x, y, SND_MAGIC_WALL_FILLING);
4961 else if (Feld[x][y + 1] == EL_BD_MAGIC_WALL_ACTIVE)
4962 PlayLevelSound(x, y, SND_BD_MAGIC_WALL_FILLING);
4967 /* play sound of object that hits the ground */
4968 if (last_line || object_hit)
4969 PlayLevelSoundElementAction(x, y, element, ACTION_IMPACT);
4972 inline static void TurnRoundExt(int x, int y)
4984 { 0, 0 }, { 0, 0 }, { 0, 0 },
4989 int left, right, back;
4993 { MV_DOWN, MV_UP, MV_RIGHT },
4994 { MV_UP, MV_DOWN, MV_LEFT },
4996 { MV_LEFT, MV_RIGHT, MV_DOWN },
5000 { MV_RIGHT, MV_LEFT, MV_UP }
5003 int element = Feld[x][y];
5004 int move_pattern = element_info[element].move_pattern;
5006 int old_move_dir = MovDir[x][y];
5007 int left_dir = turn[old_move_dir].left;
5008 int right_dir = turn[old_move_dir].right;
5009 int back_dir = turn[old_move_dir].back;
5011 int left_dx = move_xy[left_dir].dx, left_dy = move_xy[left_dir].dy;
5012 int right_dx = move_xy[right_dir].dx, right_dy = move_xy[right_dir].dy;
5013 int move_dx = move_xy[old_move_dir].dx, move_dy = move_xy[old_move_dir].dy;
5014 int back_dx = move_xy[back_dir].dx, back_dy = move_xy[back_dir].dy;
5016 int left_x = x + left_dx, left_y = y + left_dy;
5017 int right_x = x + right_dx, right_y = y + right_dy;
5018 int move_x = x + move_dx, move_y = y + move_dy;
5022 if (element == EL_BUG || element == EL_BD_BUTTERFLY)
5024 TestIfBadThingTouchesOtherBadThing(x, y);
5026 if (ENEMY_CAN_ENTER_FIELD(element, right_x, right_y))
5027 MovDir[x][y] = right_dir;
5028 else if (!ENEMY_CAN_ENTER_FIELD(element, move_x, move_y))
5029 MovDir[x][y] = left_dir;
5031 if (element == EL_BUG && MovDir[x][y] != old_move_dir)
5033 else if (element == EL_BD_BUTTERFLY) /* && MovDir[x][y] == left_dir) */
5036 else if (element == EL_SPACESHIP || element == EL_BD_FIREFLY)
5038 TestIfBadThingTouchesOtherBadThing(x, y);
5040 if (ENEMY_CAN_ENTER_FIELD(element, left_x, left_y))
5041 MovDir[x][y] = left_dir;
5042 else if (!ENEMY_CAN_ENTER_FIELD(element, move_x, move_y))
5043 MovDir[x][y] = right_dir;
5045 if (element == EL_SPACESHIP && MovDir[x][y] != old_move_dir)
5047 else if (element == EL_BD_FIREFLY) /* && MovDir[x][y] == right_dir) */
5050 else if (element == EL_SP_SNIKSNAK || element == EL_SP_ELECTRON)
5052 TestIfBadThingTouchesOtherBadThing(x, y);
5054 if (ELEMENT_CAN_ENTER_FIELD_BASE_4(element, left_x, left_y, 0))
5055 MovDir[x][y] = left_dir;
5056 else if (!ELEMENT_CAN_ENTER_FIELD_BASE_4(element, move_x, move_y, 0))
5057 MovDir[x][y] = right_dir;
5059 if (MovDir[x][y] != old_move_dir)
5062 else if (element == EL_YAMYAM)
5064 boolean can_turn_left = YAMYAM_CAN_ENTER_FIELD(element, left_x, left_y);
5065 boolean can_turn_right = YAMYAM_CAN_ENTER_FIELD(element, right_x, right_y);
5067 if (can_turn_left && can_turn_right)
5068 MovDir[x][y] = (RND(3) ? (RND(2) ? left_dir : right_dir) : back_dir);
5069 else if (can_turn_left)
5070 MovDir[x][y] = (RND(2) ? left_dir : back_dir);
5071 else if (can_turn_right)
5072 MovDir[x][y] = (RND(2) ? right_dir : back_dir);
5074 MovDir[x][y] = back_dir;
5076 MovDelay[x][y] = 16 + 16 * RND(3);
5078 else if (element == EL_DARK_YAMYAM)
5080 boolean can_turn_left = DARK_YAMYAM_CAN_ENTER_FIELD(element,
5082 boolean can_turn_right = DARK_YAMYAM_CAN_ENTER_FIELD(element,
5085 if (can_turn_left && can_turn_right)
5086 MovDir[x][y] = (RND(3) ? (RND(2) ? left_dir : right_dir) : back_dir);
5087 else if (can_turn_left)
5088 MovDir[x][y] = (RND(2) ? left_dir : back_dir);
5089 else if (can_turn_right)
5090 MovDir[x][y] = (RND(2) ? right_dir : back_dir);
5092 MovDir[x][y] = back_dir;
5094 MovDelay[x][y] = 16 + 16 * RND(3);
5096 else if (element == EL_PACMAN)
5098 boolean can_turn_left = PACMAN_CAN_ENTER_FIELD(element, left_x, left_y);
5099 boolean can_turn_right = PACMAN_CAN_ENTER_FIELD(element, right_x, right_y);
5101 if (can_turn_left && can_turn_right)
5102 MovDir[x][y] = (RND(3) ? (RND(2) ? left_dir : right_dir) : back_dir);
5103 else if (can_turn_left)
5104 MovDir[x][y] = (RND(2) ? left_dir : back_dir);
5105 else if (can_turn_right)
5106 MovDir[x][y] = (RND(2) ? right_dir : back_dir);
5108 MovDir[x][y] = back_dir;
5110 MovDelay[x][y] = 6 + RND(40);
5112 else if (element == EL_PIG)
5114 boolean can_turn_left = PIG_CAN_ENTER_FIELD(element, left_x, left_y);
5115 boolean can_turn_right = PIG_CAN_ENTER_FIELD(element, right_x, right_y);
5116 boolean can_move_on = PIG_CAN_ENTER_FIELD(element, move_x, move_y);
5117 boolean should_turn_left, should_turn_right, should_move_on;
5119 int rnd = RND(rnd_value);
5121 should_turn_left = (can_turn_left &&
5123 IN_LEV_FIELD_AND_NOT_FREE(x + back_dx + left_dx,
5124 y + back_dy + left_dy)));
5125 should_turn_right = (can_turn_right &&
5127 IN_LEV_FIELD_AND_NOT_FREE(x + back_dx + right_dx,
5128 y + back_dy + right_dy)));
5129 should_move_on = (can_move_on &&
5132 IN_LEV_FIELD_AND_NOT_FREE(x + move_dx + left_dx,
5133 y + move_dy + left_dy) ||
5134 IN_LEV_FIELD_AND_NOT_FREE(x + move_dx + right_dx,
5135 y + move_dy + right_dy)));
5137 if (should_turn_left || should_turn_right || should_move_on)
5139 if (should_turn_left && should_turn_right && should_move_on)
5140 MovDir[x][y] = (rnd < rnd_value / 3 ? left_dir :
5141 rnd < 2 * rnd_value / 3 ? right_dir :
5143 else if (should_turn_left && should_turn_right)
5144 MovDir[x][y] = (rnd < rnd_value / 2 ? left_dir : right_dir);
5145 else if (should_turn_left && should_move_on)
5146 MovDir[x][y] = (rnd < rnd_value / 2 ? left_dir : old_move_dir);
5147 else if (should_turn_right && should_move_on)
5148 MovDir[x][y] = (rnd < rnd_value / 2 ? right_dir : old_move_dir);
5149 else if (should_turn_left)
5150 MovDir[x][y] = left_dir;
5151 else if (should_turn_right)
5152 MovDir[x][y] = right_dir;
5153 else if (should_move_on)
5154 MovDir[x][y] = old_move_dir;
5156 else if (can_move_on && rnd > rnd_value / 8)
5157 MovDir[x][y] = old_move_dir;
5158 else if (can_turn_left && can_turn_right)
5159 MovDir[x][y] = (rnd < rnd_value / 2 ? left_dir : right_dir);
5160 else if (can_turn_left && rnd > rnd_value / 8)
5161 MovDir[x][y] = left_dir;
5162 else if (can_turn_right && rnd > rnd_value/8)
5163 MovDir[x][y] = right_dir;
5165 MovDir[x][y] = back_dir;
5167 xx = x + move_xy[MovDir[x][y]].dx;
5168 yy = y + move_xy[MovDir[x][y]].dy;
5170 if (!IN_LEV_FIELD(xx, yy) ||
5171 (!IS_FREE(xx, yy) && !IS_FOOD_PIG(Feld[xx][yy])))
5172 MovDir[x][y] = old_move_dir;
5176 else if (element == EL_DRAGON)
5178 boolean can_turn_left = DRAGON_CAN_ENTER_FIELD(element, left_x, left_y);
5179 boolean can_turn_right = DRAGON_CAN_ENTER_FIELD(element, right_x, right_y);
5180 boolean can_move_on = DRAGON_CAN_ENTER_FIELD(element, move_x, move_y);
5182 int rnd = RND(rnd_value);
5184 if (can_move_on && rnd > rnd_value / 8)
5185 MovDir[x][y] = old_move_dir;
5186 else if (can_turn_left && can_turn_right)
5187 MovDir[x][y] = (rnd < rnd_value / 2 ? left_dir : right_dir);
5188 else if (can_turn_left && rnd > rnd_value / 8)
5189 MovDir[x][y] = left_dir;
5190 else if (can_turn_right && rnd > rnd_value / 8)
5191 MovDir[x][y] = right_dir;
5193 MovDir[x][y] = back_dir;
5195 xx = x + move_xy[MovDir[x][y]].dx;
5196 yy = y + move_xy[MovDir[x][y]].dy;
5198 if (!IN_LEV_FIELD_AND_IS_FREE(xx, yy))
5199 MovDir[x][y] = old_move_dir;
5203 else if (element == EL_MOLE)
5205 boolean can_move_on =
5206 (MOLE_CAN_ENTER_FIELD(element, move_x, move_y,
5207 IS_AMOEBOID(Feld[move_x][move_y]) ||
5208 Feld[move_x][move_y] == EL_AMOEBA_SHRINKING));
5211 boolean can_turn_left =
5212 (MOLE_CAN_ENTER_FIELD(element, left_x, left_y,
5213 IS_AMOEBOID(Feld[left_x][left_y])));
5215 boolean can_turn_right =
5216 (MOLE_CAN_ENTER_FIELD(element, right_x, right_y,
5217 IS_AMOEBOID(Feld[right_x][right_y])));
5219 if (can_turn_left && can_turn_right)
5220 MovDir[x][y] = (RND(2) ? left_dir : right_dir);
5221 else if (can_turn_left)
5222 MovDir[x][y] = left_dir;
5224 MovDir[x][y] = right_dir;
5227 if (MovDir[x][y] != old_move_dir)
5230 else if (element == EL_BALLOON)
5232 MovDir[x][y] = game.wind_direction;
5235 else if (element == EL_SPRING)
5237 #if USE_NEW_SPRING_BUMPER
5238 if (MovDir[x][y] & MV_HORIZONTAL)
5240 if (SPRING_CAN_BUMP_FROM_FIELD(move_x, move_y) &&
5241 !SPRING_CAN_ENTER_FIELD(element, x, y + 1))
5243 Feld[move_x][move_y] = EL_EMC_SPRING_BUMPER_ACTIVE;
5244 ResetGfxAnimation(move_x, move_y);
5245 DrawLevelField(move_x, move_y);
5247 MovDir[x][y] = back_dir;
5249 else if (!SPRING_CAN_ENTER_FIELD(element, move_x, move_y) ||
5250 SPRING_CAN_ENTER_FIELD(element, x, y + 1))
5251 MovDir[x][y] = MV_NONE;
5254 if (MovDir[x][y] & MV_HORIZONTAL &&
5255 (!SPRING_CAN_ENTER_FIELD(element, move_x, move_y) ||
5256 SPRING_CAN_ENTER_FIELD(element, x, y + 1)))
5257 MovDir[x][y] = MV_NONE;
5262 else if (element == EL_ROBOT ||
5263 element == EL_SATELLITE ||
5264 element == EL_PENGUIN ||
5265 element == EL_EMC_ANDROID)
5267 int attr_x = -1, attr_y = -1;
5278 for (i = 0; i < MAX_PLAYERS; i++)
5280 struct PlayerInfo *player = &stored_player[i];
5281 int jx = player->jx, jy = player->jy;
5283 if (!player->active)
5287 ABS(jx - x) + ABS(jy - y) < ABS(attr_x - x) + ABS(attr_y - y))
5295 if (element == EL_ROBOT && ZX >= 0 && ZY >= 0 &&
5296 (Feld[ZX][ZY] == EL_ROBOT_WHEEL_ACTIVE ||
5297 game.engine_version < VERSION_IDENT(3,1,0,0)))
5303 if (element == EL_PENGUIN)
5306 static int xy[4][2] =
5314 for (i = 0; i < NUM_DIRECTIONS; i++)
5316 int ex = x + xy[i][0];
5317 int ey = y + xy[i][1];
5319 if (IN_LEV_FIELD(ex, ey) && Feld[ex][ey] == EL_EXIT_OPEN)
5328 MovDir[x][y] = MV_NONE;
5330 MovDir[x][y] |= (AllPlayersGone ? MV_RIGHT : MV_LEFT);
5331 else if (attr_x > x)
5332 MovDir[x][y] |= (AllPlayersGone ? MV_LEFT : MV_RIGHT);
5334 MovDir[x][y] |= (AllPlayersGone ? MV_DOWN : MV_UP);
5335 else if (attr_y > y)
5336 MovDir[x][y] |= (AllPlayersGone ? MV_UP : MV_DOWN);
5338 if (element == EL_ROBOT)
5342 if (MovDir[x][y] & MV_HORIZONTAL && MovDir[x][y] & MV_VERTICAL)
5343 MovDir[x][y] &= (RND(2) ? MV_HORIZONTAL : MV_VERTICAL);
5344 Moving2Blocked(x, y, &newx, &newy);
5346 if (IN_LEV_FIELD(newx, newy) && IS_FREE_OR_PLAYER(newx, newy))
5347 MovDelay[x][y] = 8 + 8 * !RND(3);
5349 MovDelay[x][y] = 16;
5351 else if (element == EL_PENGUIN)
5357 if (MovDir[x][y] & MV_HORIZONTAL && MovDir[x][y] & MV_VERTICAL)
5359 boolean first_horiz = RND(2);
5360 int new_move_dir = MovDir[x][y];
5363 new_move_dir & (first_horiz ? MV_HORIZONTAL : MV_VERTICAL);
5364 Moving2Blocked(x, y, &newx, &newy);
5366 if (PENGUIN_CAN_ENTER_FIELD(element, newx, newy))
5370 new_move_dir & (!first_horiz ? MV_HORIZONTAL : MV_VERTICAL);
5371 Moving2Blocked(x, y, &newx, &newy);
5373 if (PENGUIN_CAN_ENTER_FIELD(element, newx, newy))
5376 MovDir[x][y] = old_move_dir;
5380 else if (element == EL_SATELLITE)
5386 if (MovDir[x][y] & MV_HORIZONTAL && MovDir[x][y] & MV_VERTICAL)
5388 boolean first_horiz = RND(2);
5389 int new_move_dir = MovDir[x][y];
5392 new_move_dir & (first_horiz ? MV_HORIZONTAL : MV_VERTICAL);
5393 Moving2Blocked(x, y, &newx, &newy);
5395 if (SATELLITE_CAN_ENTER_FIELD(newx, newy))
5399 new_move_dir & (!first_horiz ? MV_HORIZONTAL : MV_VERTICAL);
5400 Moving2Blocked(x, y, &newx, &newy);
5402 if (SATELLITE_CAN_ENTER_FIELD(newx, newy))
5405 MovDir[x][y] = old_move_dir;
5409 else if (element == EL_EMC_ANDROID)
5411 static int check_pos[16] =
5413 -1, /* 0 => (invalid) */
5414 7, /* 1 => MV_LEFT */
5415 3, /* 2 => MV_RIGHT */
5416 -1, /* 3 => (invalid) */
5418 0, /* 5 => MV_LEFT | MV_UP */
5419 2, /* 6 => MV_RIGHT | MV_UP */
5420 -1, /* 7 => (invalid) */
5421 5, /* 8 => MV_DOWN */
5422 6, /* 9 => MV_LEFT | MV_DOWN */
5423 4, /* 10 => MV_RIGHT | MV_DOWN */
5424 -1, /* 11 => (invalid) */
5425 -1, /* 12 => (invalid) */
5426 -1, /* 13 => (invalid) */
5427 -1, /* 14 => (invalid) */
5428 -1, /* 15 => (invalid) */
5436 { -1, -1, MV_LEFT | MV_UP },
5438 { +1, -1, MV_RIGHT | MV_UP },
5439 { +1, 0, MV_RIGHT },
5440 { +1, +1, MV_RIGHT | MV_DOWN },
5442 { -1, +1, MV_LEFT | MV_DOWN },
5445 int start_pos, check_order;
5446 boolean can_clone = FALSE;
5449 /* check if there is any free field around current position */
5450 for (i = 0; i < 8; i++)
5452 int newx = x + check_xy[i].dx;
5453 int newy = y + check_xy[i].dy;
5455 if (IN_LEV_FIELD_AND_IS_FREE(newx, newy))
5463 if (can_clone) /* randomly find an element to clone */
5467 start_pos = check_pos[RND(8)];
5468 check_order = (RND(2) ? -1 : +1);
5470 for (i = 0; i < 8; i++)
5472 int pos_raw = start_pos + i * check_order;
5473 int pos = (pos_raw + 8) % 8;
5474 int newx = x + check_xy[pos].dx;
5475 int newy = y + check_xy[pos].dy;
5477 if (ANDROID_CAN_CLONE_FIELD(newx, newy))
5479 element_info[element].move_leave_type = LEAVE_TYPE_LIMITED;
5480 element_info[element].move_leave_element = EL_TRIGGER_ELEMENT;
5482 Store[x][y] = Feld[newx][newy];
5491 if (can_clone) /* randomly find a direction to move */
5495 start_pos = check_pos[RND(8)];
5496 check_order = (RND(2) ? -1 : +1);
5498 for (i = 0; i < 8; i++)
5500 int pos_raw = start_pos + i * check_order;
5501 int pos = (pos_raw + 8) % 8;
5502 int newx = x + check_xy[pos].dx;
5503 int newy = y + check_xy[pos].dy;
5504 int new_move_dir = check_xy[pos].dir;
5506 if (IN_LEV_FIELD_AND_IS_FREE(newx, newy))
5508 MovDir[x][y] = new_move_dir;
5509 MovDelay[x][y] = level.android_clone_time * 8 + 1;
5518 if (can_clone) /* cloning and moving successful */
5521 /* cannot clone -- try to move towards player */
5523 start_pos = check_pos[MovDir[x][y] & 0x0f];
5524 check_order = (RND(2) ? -1 : +1);
5526 for (i = 0; i < 3; i++)
5528 /* first check start_pos, then previous/next or (next/previous) pos */
5529 int pos_raw = start_pos + (i < 2 ? i : -1) * check_order;
5530 int pos = (pos_raw + 8) % 8;
5531 int newx = x + check_xy[pos].dx;
5532 int newy = y + check_xy[pos].dy;
5533 int new_move_dir = check_xy[pos].dir;
5535 if (IS_PLAYER(newx, newy))
5538 if (ANDROID_CAN_ENTER_FIELD(element, newx, newy))
5540 MovDir[x][y] = new_move_dir;
5541 MovDelay[x][y] = level.android_move_time * 8 + 1;
5548 else if (move_pattern == MV_TURNING_LEFT ||
5549 move_pattern == MV_TURNING_RIGHT ||
5550 move_pattern == MV_TURNING_LEFT_RIGHT ||
5551 move_pattern == MV_TURNING_RIGHT_LEFT ||
5552 move_pattern == MV_TURNING_RANDOM ||
5553 move_pattern == MV_ALL_DIRECTIONS)
5555 boolean can_turn_left =
5556 CUSTOM_ELEMENT_CAN_ENTER_FIELD(element, left_x, left_y);
5557 boolean can_turn_right =
5558 CUSTOM_ELEMENT_CAN_ENTER_FIELD(element, right_x,right_y);
5560 if (element_info[element].move_stepsize == 0) /* "not moving" */
5563 if (move_pattern == MV_TURNING_LEFT)
5564 MovDir[x][y] = left_dir;
5565 else if (move_pattern == MV_TURNING_RIGHT)
5566 MovDir[x][y] = right_dir;
5567 else if (move_pattern == MV_TURNING_LEFT_RIGHT)
5568 MovDir[x][y] = (can_turn_left || !can_turn_right ? left_dir : right_dir);
5569 else if (move_pattern == MV_TURNING_RIGHT_LEFT)
5570 MovDir[x][y] = (can_turn_right || !can_turn_left ? right_dir : left_dir);
5571 else if (move_pattern == MV_TURNING_RANDOM)
5572 MovDir[x][y] = (can_turn_left && !can_turn_right ? left_dir :
5573 can_turn_right && !can_turn_left ? right_dir :
5574 RND(2) ? left_dir : right_dir);
5575 else if (can_turn_left && can_turn_right)
5576 MovDir[x][y] = (RND(3) ? (RND(2) ? left_dir : right_dir) : back_dir);
5577 else if (can_turn_left)
5578 MovDir[x][y] = (RND(2) ? left_dir : back_dir);
5579 else if (can_turn_right)
5580 MovDir[x][y] = (RND(2) ? right_dir : back_dir);
5582 MovDir[x][y] = back_dir;
5584 MovDelay[x][y] = GET_NEW_MOVE_DELAY(element);
5586 else if (move_pattern == MV_HORIZONTAL ||
5587 move_pattern == MV_VERTICAL)
5589 if (move_pattern & old_move_dir)
5590 MovDir[x][y] = back_dir;
5591 else if (move_pattern == MV_HORIZONTAL)
5592 MovDir[x][y] = (RND(2) ? MV_LEFT : MV_RIGHT);
5593 else if (move_pattern == MV_VERTICAL)
5594 MovDir[x][y] = (RND(2) ? MV_UP : MV_DOWN);
5596 MovDelay[x][y] = GET_NEW_MOVE_DELAY(element);
5598 else if (move_pattern & MV_ANY_DIRECTION)
5600 MovDir[x][y] = move_pattern;
5601 MovDelay[x][y] = GET_NEW_MOVE_DELAY(element);
5603 else if (move_pattern & MV_WIND_DIRECTION)
5605 MovDir[x][y] = game.wind_direction;
5606 MovDelay[x][y] = GET_NEW_MOVE_DELAY(element);
5608 else if (move_pattern == MV_ALONG_LEFT_SIDE)
5610 if (CUSTOM_ELEMENT_CAN_ENTER_FIELD(element, left_x, left_y))
5611 MovDir[x][y] = left_dir;
5612 else if (!CUSTOM_ELEMENT_CAN_ENTER_FIELD(element, move_x, move_y))
5613 MovDir[x][y] = right_dir;
5615 if (MovDir[x][y] != old_move_dir)
5616 MovDelay[x][y] = GET_NEW_MOVE_DELAY(element);
5618 else if (move_pattern == MV_ALONG_RIGHT_SIDE)
5620 if (CUSTOM_ELEMENT_CAN_ENTER_FIELD(element, right_x, right_y))
5621 MovDir[x][y] = right_dir;
5622 else if (!CUSTOM_ELEMENT_CAN_ENTER_FIELD(element, move_x, move_y))
5623 MovDir[x][y] = left_dir;
5625 if (MovDir[x][y] != old_move_dir)
5626 MovDelay[x][y] = GET_NEW_MOVE_DELAY(element);
5628 else if (move_pattern == MV_TOWARDS_PLAYER ||
5629 move_pattern == MV_AWAY_FROM_PLAYER)
5631 int attr_x = -1, attr_y = -1;
5633 boolean move_away = (move_pattern == MV_AWAY_FROM_PLAYER);
5644 for (i = 0; i < MAX_PLAYERS; i++)
5646 struct PlayerInfo *player = &stored_player[i];
5647 int jx = player->jx, jy = player->jy;
5649 if (!player->active)
5653 ABS(jx - x) + ABS(jy - y) < ABS(attr_x - x) + ABS(attr_y - y))
5661 MovDir[x][y] = MV_NONE;
5663 MovDir[x][y] |= (move_away ? MV_RIGHT : MV_LEFT);
5664 else if (attr_x > x)
5665 MovDir[x][y] |= (move_away ? MV_LEFT : MV_RIGHT);
5667 MovDir[x][y] |= (move_away ? MV_DOWN : MV_UP);
5668 else if (attr_y > y)
5669 MovDir[x][y] |= (move_away ? MV_UP : MV_DOWN);
5671 MovDelay[x][y] = GET_NEW_MOVE_DELAY(element);
5673 if (MovDir[x][y] & MV_HORIZONTAL && MovDir[x][y] & MV_VERTICAL)
5675 boolean first_horiz = RND(2);
5676 int new_move_dir = MovDir[x][y];
5678 if (element_info[element].move_stepsize == 0) /* "not moving" */
5680 first_horiz = (ABS(attr_x - x) >= ABS(attr_y - y));
5681 MovDir[x][y] &= (first_horiz ? MV_HORIZONTAL : MV_VERTICAL);
5687 new_move_dir & (first_horiz ? MV_HORIZONTAL : MV_VERTICAL);
5688 Moving2Blocked(x, y, &newx, &newy);
5690 if (CUSTOM_ELEMENT_CAN_ENTER_FIELD(element, newx, newy))
5694 new_move_dir & (!first_horiz ? MV_HORIZONTAL : MV_VERTICAL);
5695 Moving2Blocked(x, y, &newx, &newy);
5697 if (CUSTOM_ELEMENT_CAN_ENTER_FIELD(element, newx, newy))
5700 MovDir[x][y] = old_move_dir;
5703 else if (move_pattern == MV_WHEN_PUSHED ||
5704 move_pattern == MV_WHEN_DROPPED)
5706 if (!CUSTOM_ELEMENT_CAN_ENTER_FIELD(element, move_x, move_y))
5707 MovDir[x][y] = MV_NONE;
5711 else if (move_pattern & MV_MAZE_RUNNER_STYLE)
5713 static int test_xy[7][2] =
5723 static int test_dir[7] =
5733 boolean hunter_mode = (move_pattern == MV_MAZE_HUNTER);
5734 int move_preference = -1000000; /* start with very low preference */
5735 int new_move_dir = MV_NONE;
5736 int start_test = RND(4);
5739 for (i = 0; i < NUM_DIRECTIONS; i++)
5741 int move_dir = test_dir[start_test + i];
5742 int move_dir_preference;
5744 xx = x + test_xy[start_test + i][0];
5745 yy = y + test_xy[start_test + i][1];
5747 if (hunter_mode && IN_LEV_FIELD(xx, yy) &&
5748 (IS_PLAYER(xx, yy) || Feld[xx][yy] == EL_PLAYER_IS_LEAVING))
5750 new_move_dir = move_dir;
5755 if (!CUSTOM_ELEMENT_CAN_ENTER_FIELD(element, xx, yy))
5758 move_dir_preference = -1 * RunnerVisit[xx][yy];
5759 if (hunter_mode && PlayerVisit[xx][yy] > 0)
5760 move_dir_preference = PlayerVisit[xx][yy];
5762 if (move_dir_preference > move_preference)
5764 /* prefer field that has not been visited for the longest time */
5765 move_preference = move_dir_preference;
5766 new_move_dir = move_dir;
5768 else if (move_dir_preference == move_preference &&
5769 move_dir == old_move_dir)
5771 /* prefer last direction when all directions are preferred equally */
5772 move_preference = move_dir_preference;
5773 new_move_dir = move_dir;
5777 MovDir[x][y] = new_move_dir;
5778 if (old_move_dir != new_move_dir)
5779 MovDelay[x][y] = GET_NEW_MOVE_DELAY(element);
5783 static void TurnRound(int x, int y)
5785 int direction = MovDir[x][y];
5787 int element, graphic;
5792 GfxDir[x][y] = MovDir[x][y];
5794 if (direction != MovDir[x][y])
5798 GfxAction[x][y] = ACTION_TURNING_FROM_LEFT + MV_DIR_TO_BIT(direction);
5801 ResetGfxFrame(x, y, FALSE);
5803 element = Feld[x][y];
5804 graphic = el_act_dir2img(element, GfxAction[x][y], GfxDir[x][y]);
5806 if (graphic_info[graphic].anim_global_sync)
5807 GfxFrame[x][y] = FrameCounter;
5808 else if (ANIM_MODE(graphic) == ANIM_CE_VALUE)
5809 GfxFrame[x][y] = CustomValue[x][y];
5810 else if (ANIM_MODE(graphic) == ANIM_CE_SCORE)
5811 GfxFrame[x][y] = element_info[element].collect_score;
5812 else if (ANIM_MODE(graphic) == ANIM_CE_DELAY)
5813 GfxFrame[x][y] = ChangeDelay[x][y];
5817 static boolean JustBeingPushed(int x, int y)
5821 for (i = 0; i < MAX_PLAYERS; i++)
5823 struct PlayerInfo *player = &stored_player[i];
5825 if (player->active && player->is_pushing && player->MovPos)
5827 int next_jx = player->jx + (player->jx - player->last_jx);
5828 int next_jy = player->jy + (player->jy - player->last_jy);
5830 if (x == next_jx && y == next_jy)
5838 void StartMoving(int x, int y)
5840 boolean started_moving = FALSE; /* some elements can fall _and_ move */
5841 int element = Feld[x][y];
5846 if (MovDelay[x][y] == 0)
5847 GfxAction[x][y] = ACTION_DEFAULT;
5849 if (CAN_FALL(element) && y < lev_fieldy - 1)
5851 if ((x > 0 && IS_PLAYER(x - 1, y)) ||
5852 (x < lev_fieldx - 1 && IS_PLAYER(x + 1, y)))
5853 if (JustBeingPushed(x, y))
5856 if (element == EL_QUICKSAND_FULL)
5858 if (IS_FREE(x, y + 1))
5860 InitMovingField(x, y, MV_DOWN);
5861 started_moving = TRUE;
5863 Feld[x][y] = EL_QUICKSAND_EMPTYING;
5864 Store[x][y] = EL_ROCK;
5866 PlayLevelSoundAction(x, y, ACTION_EMPTYING);
5868 else if (Feld[x][y + 1] == EL_QUICKSAND_EMPTY)
5870 if (!MovDelay[x][y])
5871 MovDelay[x][y] = TILEY + 1;
5880 Feld[x][y] = EL_QUICKSAND_EMPTY;
5881 Feld[x][y + 1] = EL_QUICKSAND_FULL;
5882 Store[x][y + 1] = Store[x][y];
5885 PlayLevelSoundAction(x, y, ACTION_FILLING);
5888 else if ((element == EL_ROCK || element == EL_BD_ROCK) &&
5889 Feld[x][y + 1] == EL_QUICKSAND_EMPTY)
5891 InitMovingField(x, y, MV_DOWN);
5892 started_moving = TRUE;
5894 Feld[x][y] = EL_QUICKSAND_FILLING;
5895 Store[x][y] = element;
5897 PlayLevelSoundAction(x, y, ACTION_FILLING);
5899 else if (element == EL_MAGIC_WALL_FULL)
5901 if (IS_FREE(x, y + 1))
5903 InitMovingField(x, y, MV_DOWN);
5904 started_moving = TRUE;
5906 Feld[x][y] = EL_MAGIC_WALL_EMPTYING;
5907 Store[x][y] = EL_CHANGED(Store[x][y]);
5909 else if (Feld[x][y + 1] == EL_MAGIC_WALL_ACTIVE)
5911 if (!MovDelay[x][y])
5912 MovDelay[x][y] = TILEY/4 + 1;
5921 Feld[x][y] = EL_MAGIC_WALL_ACTIVE;
5922 Feld[x][y + 1] = EL_MAGIC_WALL_FULL;
5923 Store[x][y + 1] = EL_CHANGED(Store[x][y]);
5927 else if (element == EL_BD_MAGIC_WALL_FULL)
5929 if (IS_FREE(x, y + 1))
5931 InitMovingField(x, y, MV_DOWN);
5932 started_moving = TRUE;
5934 Feld[x][y] = EL_BD_MAGIC_WALL_EMPTYING;
5935 Store[x][y] = EL_CHANGED2(Store[x][y]);
5937 else if (Feld[x][y + 1] == EL_BD_MAGIC_WALL_ACTIVE)
5939 if (!MovDelay[x][y])
5940 MovDelay[x][y] = TILEY/4 + 1;
5949 Feld[x][y] = EL_BD_MAGIC_WALL_ACTIVE;
5950 Feld[x][y + 1] = EL_BD_MAGIC_WALL_FULL;
5951 Store[x][y + 1] = EL_CHANGED2(Store[x][y]);
5955 else if (CAN_PASS_MAGIC_WALL(element) &&
5956 (Feld[x][y + 1] == EL_MAGIC_WALL_ACTIVE ||
5957 Feld[x][y + 1] == EL_BD_MAGIC_WALL_ACTIVE))
5959 InitMovingField(x, y, MV_DOWN);
5960 started_moving = TRUE;
5963 (Feld[x][y + 1] == EL_MAGIC_WALL_ACTIVE ? EL_MAGIC_WALL_FILLING :
5964 EL_BD_MAGIC_WALL_FILLING);
5965 Store[x][y] = element;
5967 else if (CAN_FALL(element) && Feld[x][y + 1] == EL_ACID)
5969 SplashAcid(x, y + 1);
5971 InitMovingField(x, y, MV_DOWN);
5972 started_moving = TRUE;
5974 Store[x][y] = EL_ACID;
5976 else if ((game.engine_version >= VERSION_IDENT(3,1,0,0) &&
5977 CheckCollision[x][y] && !IS_FREE(x, y + 1)) ||
5979 (game.engine_version >= VERSION_IDENT(3,0,7,0) &&
5980 CAN_FALL(element) && WasJustFalling[x][y] &&
5981 (Feld[x][y + 1] == EL_BLOCKED || IS_PLAYER(x, y + 1))) ||
5983 (game.engine_version < VERSION_IDENT(2,2,0,7) &&
5984 CAN_FALL(element) && WasJustMoving[x][y] && !Pushed[x][y + 1] &&
5985 (Feld[x][y + 1] == EL_BLOCKED)))
5987 /* this is needed for a special case not covered by calling "Impact()"
5988 from "ContinueMoving()": if an element moves to a tile directly below
5989 another element which was just falling on that tile (which was empty
5990 in the previous frame), the falling element above would just stop
5991 instead of smashing the element below (in previous version, the above
5992 element was just checked for "moving" instead of "falling", resulting
5993 in incorrect smashes caused by horizontal movement of the above
5994 element; also, the case of the player being the element to smash was
5995 simply not covered here... :-/ ) */
5997 CheckCollision[x][y] = 0;
6001 else if (IS_FREE(x, y + 1) && element == EL_SPRING && level.use_spring_bug)
6003 if (MovDir[x][y] == MV_NONE)
6005 InitMovingField(x, y, MV_DOWN);
6006 started_moving = TRUE;
6009 else if (IS_FREE(x, y + 1) || Feld[x][y + 1] == EL_DIAMOND_BREAKING)
6011 if (WasJustFalling[x][y]) /* prevent animation from being restarted */
6012 MovDir[x][y] = MV_DOWN;
6014 InitMovingField(x, y, MV_DOWN);
6015 started_moving = TRUE;
6017 else if (element == EL_AMOEBA_DROP)
6019 Feld[x][y] = EL_AMOEBA_GROWING;
6020 Store[x][y] = EL_AMOEBA_WET;
6022 else if (((IS_SLIPPERY(Feld[x][y + 1]) && !IS_PLAYER(x, y + 1)) ||
6023 (IS_EM_SLIPPERY_WALL(Feld[x][y + 1]) && IS_GEM(element))) &&
6024 !IS_FALLING(x, y + 1) && !WasJustMoving[x][y + 1] &&
6025 element != EL_DX_SUPABOMB && element != EL_SP_DISK_ORANGE)
6027 boolean can_fall_left = (x > 0 && IS_FREE(x - 1, y) &&
6028 (IS_FREE(x - 1, y + 1) ||
6029 Feld[x - 1][y + 1] == EL_ACID));
6030 boolean can_fall_right = (x < lev_fieldx - 1 && IS_FREE(x + 1, y) &&
6031 (IS_FREE(x + 1, y + 1) ||
6032 Feld[x + 1][y + 1] == EL_ACID));
6033 boolean can_fall_any = (can_fall_left || can_fall_right);
6034 boolean can_fall_both = (can_fall_left && can_fall_right);
6035 int slippery_type = element_info[Feld[x][y + 1]].slippery_type;
6037 #if USE_NEW_ALL_SLIPPERY
6038 if (can_fall_any && slippery_type != SLIPPERY_ANY_RANDOM)
6040 if (slippery_type == SLIPPERY_ANY_LEFT_RIGHT && can_fall_both)
6041 can_fall_right = FALSE;
6042 else if (slippery_type == SLIPPERY_ANY_RIGHT_LEFT && can_fall_both)
6043 can_fall_left = FALSE;
6044 else if (slippery_type == SLIPPERY_ONLY_LEFT)
6045 can_fall_right = FALSE;
6046 else if (slippery_type == SLIPPERY_ONLY_RIGHT)
6047 can_fall_left = FALSE;
6049 can_fall_any = (can_fall_left || can_fall_right);
6050 can_fall_both = FALSE;
6053 if (can_fall_any && IS_CUSTOM_ELEMENT(Feld[x][y + 1]))
6055 if (slippery_type == SLIPPERY_ONLY_LEFT)
6056 can_fall_right = FALSE;
6057 else if (slippery_type == SLIPPERY_ONLY_RIGHT)
6058 can_fall_left = FALSE;
6059 else if (slippery_type == SLIPPERY_ANY_LEFT_RIGHT && can_fall_both)
6060 can_fall_right = FALSE;
6061 else if (slippery_type == SLIPPERY_ANY_RIGHT_LEFT && can_fall_both)
6062 can_fall_left = FALSE;
6064 can_fall_any = (can_fall_left || can_fall_right);
6065 can_fall_both = (can_fall_left && can_fall_right);
6069 #if USE_NEW_ALL_SLIPPERY
6071 #if USE_NEW_SP_SLIPPERY
6072 /* !!! better use the same properties as for custom elements here !!! */
6073 else if (game.engine_version >= VERSION_IDENT(3,1,1,0) &&
6074 can_fall_both && IS_SP_ELEMENT(Feld[x][y + 1]))
6076 can_fall_right = FALSE; /* slip down on left side */
6077 can_fall_both = FALSE;
6082 #if USE_NEW_ALL_SLIPPERY
6085 if (element == EL_BD_ROCK || element == EL_BD_DIAMOND)
6086 can_fall_right = FALSE; /* slip down on left side */
6088 can_fall_left = !(can_fall_right = RND(2));
6090 can_fall_both = FALSE;
6095 if (game.emulation == EMU_BOULDERDASH ||
6096 element == EL_BD_ROCK || element == EL_BD_DIAMOND)
6097 can_fall_right = FALSE; /* slip down on left side */
6099 can_fall_left = !(can_fall_right = RND(2));
6101 can_fall_both = FALSE;
6107 /* if not determined otherwise, prefer left side for slipping down */
6108 InitMovingField(x, y, can_fall_left ? MV_LEFT : MV_RIGHT);
6109 started_moving = TRUE;
6113 else if (IS_BELT_ACTIVE(Feld[x][y + 1]) && !CAN_MOVE(element))
6115 else if (IS_BELT_ACTIVE(Feld[x][y + 1]))
6118 boolean left_is_free = (x > 0 && IS_FREE(x - 1, y));
6119 boolean right_is_free = (x < lev_fieldx - 1 && IS_FREE(x + 1, y));
6120 int belt_nr = getBeltNrFromBeltActiveElement(Feld[x][y + 1]);
6121 int belt_dir = game.belt_dir[belt_nr];
6123 if ((belt_dir == MV_LEFT && left_is_free) ||
6124 (belt_dir == MV_RIGHT && right_is_free))
6126 int nextx = (belt_dir == MV_LEFT ? x - 1 : x + 1);
6128 InitMovingField(x, y, belt_dir);
6129 started_moving = TRUE;
6131 Pushed[x][y] = TRUE;
6132 Pushed[nextx][y] = TRUE;
6134 GfxAction[x][y] = ACTION_DEFAULT;
6138 MovDir[x][y] = 0; /* if element was moving, stop it */
6143 /* not "else if" because of elements that can fall and move (EL_SPRING) */
6145 if (CAN_MOVE(element) && !started_moving && MovDir[x][y] != MV_NONE)
6147 if (CAN_MOVE(element) && !started_moving)
6150 int move_pattern = element_info[element].move_pattern;
6155 if (MovDir[x][y] == MV_NONE)
6157 printf("StartMoving(): %d,%d: element %d ['%s'] not moving\n",
6158 x, y, element, element_info[element].token_name);
6159 printf("StartMoving(): This should never happen!\n");
6164 Moving2Blocked(x, y, &newx, &newy);
6166 if (IS_PUSHABLE(element) && JustBeingPushed(x, y))
6169 if (game.engine_version >= VERSION_IDENT(3,1,0,0) &&
6170 CheckCollision[x][y] && !IN_LEV_FIELD_AND_IS_FREE(newx, newy))
6172 WasJustMoving[x][y] = 0;
6173 CheckCollision[x][y] = 0;
6175 TestIfElementHitsCustomElement(x, y, MovDir[x][y]);
6177 if (Feld[x][y] != element) /* element has changed */
6181 if (!MovDelay[x][y]) /* start new movement phase */
6183 /* all objects that can change their move direction after each step
6184 (YAMYAM, DARK_YAMYAM and PACMAN go straight until they hit a wall */
6186 if (element != EL_YAMYAM &&
6187 element != EL_DARK_YAMYAM &&
6188 element != EL_PACMAN &&
6189 !(move_pattern & MV_ANY_DIRECTION) &&
6190 move_pattern != MV_TURNING_LEFT &&
6191 move_pattern != MV_TURNING_RIGHT &&
6192 move_pattern != MV_TURNING_LEFT_RIGHT &&
6193 move_pattern != MV_TURNING_RIGHT_LEFT &&
6194 move_pattern != MV_TURNING_RANDOM)
6198 if (MovDelay[x][y] && (element == EL_BUG ||
6199 element == EL_SPACESHIP ||
6200 element == EL_SP_SNIKSNAK ||
6201 element == EL_SP_ELECTRON ||
6202 element == EL_MOLE))
6203 DrawLevelField(x, y);
6207 if (MovDelay[x][y]) /* wait some time before next movement */
6211 if (element == EL_ROBOT ||
6212 element == EL_YAMYAM ||
6213 element == EL_DARK_YAMYAM)
6215 DrawLevelElementAnimationIfNeeded(x, y, element);
6216 PlayLevelSoundAction(x, y, ACTION_WAITING);
6218 else if (element == EL_SP_ELECTRON)
6219 DrawLevelElementAnimationIfNeeded(x, y, element);
6220 else if (element == EL_DRAGON)
6223 int dir = MovDir[x][y];
6224 int dx = (dir == MV_LEFT ? -1 : dir == MV_RIGHT ? +1 : 0);
6225 int dy = (dir == MV_UP ? -1 : dir == MV_DOWN ? +1 : 0);
6226 int graphic = (dir == MV_LEFT ? IMG_FLAMES_1_LEFT :
6227 dir == MV_RIGHT ? IMG_FLAMES_1_RIGHT :
6228 dir == MV_UP ? IMG_FLAMES_1_UP :
6229 dir == MV_DOWN ? IMG_FLAMES_1_DOWN : IMG_EMPTY);
6230 int frame = getGraphicAnimationFrame(graphic, GfxFrame[x][y]);
6232 GfxAction[x][y] = ACTION_ATTACKING;
6234 if (IS_PLAYER(x, y))
6235 DrawPlayerField(x, y);
6237 DrawLevelField(x, y);
6239 PlayLevelSoundActionIfLoop(x, y, ACTION_ATTACKING);
6241 for (i = 1; i <= 3; i++)
6243 int xx = x + i * dx;
6244 int yy = y + i * dy;
6245 int sx = SCREENX(xx);
6246 int sy = SCREENY(yy);
6247 int flame_graphic = graphic + (i - 1);
6249 if (!IN_LEV_FIELD(xx, yy) || IS_DRAGONFIRE_PROOF(Feld[xx][yy]))
6254 int flamed = MovingOrBlocked2Element(xx, yy);
6258 if (IS_CLASSIC_ENEMY(flamed) || CAN_EXPLODE_BY_DRAGONFIRE(flamed))
6260 else if (IS_MOVING(xx, yy) || IS_BLOCKED(xx, yy))
6261 RemoveMovingField(xx, yy);
6263 RemoveField(xx, yy);
6265 if (IS_CLASSIC_ENEMY(flamed) || CAN_EXPLODE_BY_DRAGONFIRE(flamed))
6268 RemoveMovingField(xx, yy);
6271 ChangeDelay[xx][yy] = 0;
6273 Feld[xx][yy] = EL_FLAMES;
6275 if (IN_SCR_FIELD(sx, sy))
6277 DrawLevelFieldCrumbledSand(xx, yy);
6278 DrawGraphic(sx, sy, flame_graphic, frame);
6283 if (Feld[xx][yy] == EL_FLAMES)
6284 Feld[xx][yy] = EL_EMPTY;
6285 DrawLevelField(xx, yy);
6290 if (MovDelay[x][y]) /* element still has to wait some time */
6292 PlayLevelSoundAction(x, y, ACTION_WAITING);
6298 /* now make next step */
6300 Moving2Blocked(x, y, &newx, &newy); /* get next screen position */
6302 if (DONT_COLLIDE_WITH(element) &&
6303 IN_LEV_FIELD(newx, newy) && IS_PLAYER(newx, newy) &&
6304 !PLAYER_ENEMY_PROTECTED(newx, newy))
6306 TestIfBadThingRunsIntoPlayer(x, y, MovDir[x][y]);
6311 else if (CAN_MOVE_INTO_ACID(element) &&
6312 IN_LEV_FIELD(newx, newy) && Feld[newx][newy] == EL_ACID &&
6313 !IS_MV_DIAGONAL(MovDir[x][y]) &&
6314 (MovDir[x][y] == MV_DOWN ||
6315 game.engine_version >= VERSION_IDENT(3,1,0,0)))
6317 SplashAcid(newx, newy);
6318 Store[x][y] = EL_ACID;
6320 else if (element == EL_PENGUIN && IN_LEV_FIELD(newx, newy))
6322 if (Feld[newx][newy] == EL_EXIT_OPEN)
6325 DrawLevelField(x, y);
6327 PlayLevelSound(newx, newy, SND_PENGUIN_PASSING);
6328 if (IN_SCR_FIELD(SCREENX(newx), SCREENY(newy)))
6329 DrawGraphicThruMask(SCREENX(newx),SCREENY(newy), el2img(element), 0);
6331 local_player->friends_still_needed--;
6332 if (!local_player->friends_still_needed &&
6333 !local_player->GameOver && AllPlayersGone)
6334 local_player->LevelSolved = local_player->GameOver = TRUE;
6338 else if (IS_FOOD_PENGUIN(Feld[newx][newy]))
6340 if (DigField(local_player, x, y, newx, newy, 0,0, DF_DIG) == MP_MOVING)
6341 DrawLevelField(newx, newy);
6343 GfxDir[x][y] = MovDir[x][y] = MV_NONE;
6345 else if (!IS_FREE(newx, newy))
6347 GfxAction[x][y] = ACTION_WAITING;
6349 if (IS_PLAYER(x, y))
6350 DrawPlayerField(x, y);
6352 DrawLevelField(x, y);
6357 else if (element == EL_PIG && IN_LEV_FIELD(newx, newy))
6359 if (IS_FOOD_PIG(Feld[newx][newy]))
6361 if (IS_MOVING(newx, newy))
6362 RemoveMovingField(newx, newy);
6365 Feld[newx][newy] = EL_EMPTY;
6366 DrawLevelField(newx, newy);
6369 PlayLevelSound(x, y, SND_PIG_DIGGING);
6371 else if (!IS_FREE(newx, newy))
6373 if (IS_PLAYER(x, y))
6374 DrawPlayerField(x, y);
6376 DrawLevelField(x, y);
6381 else if (element == EL_EMC_ANDROID && IN_LEV_FIELD(newx, newy))
6383 if (Store[x][y] != EL_EMPTY)
6385 boolean can_clone = FALSE;
6388 /* check if element to clone is still there */
6389 for (yy = y - 1; yy <= y + 1; yy++) for (xx = x - 1; xx <= x + 1; xx++)
6391 if (IN_LEV_FIELD(xx, yy) && Feld[xx][yy] == Store[x][y])
6399 /* cannot clone or target field not free anymore -- do not clone */
6400 if (!can_clone || !ANDROID_CAN_ENTER_FIELD(element, newx, newy))
6401 Store[x][y] = EL_EMPTY;
6404 if (ANDROID_CAN_ENTER_FIELD(element, newx, newy))
6406 if (IS_MV_DIAGONAL(MovDir[x][y]))
6408 int diagonal_move_dir = MovDir[x][y];
6409 int stored = Store[x][y];
6410 int change_delay = 8;
6413 /* android is moving diagonally */
6415 CreateField(x, y, EL_DIAGONAL_SHRINKING);
6417 Store[x][y] = (stored == EL_ACID ? EL_EMPTY : stored);
6418 GfxElement[x][y] = EL_EMC_ANDROID;
6419 GfxAction[x][y] = ACTION_SHRINKING;
6420 GfxDir[x][y] = diagonal_move_dir;
6421 ChangeDelay[x][y] = change_delay;
6423 graphic = el_act_dir2img(GfxElement[x][y], GfxAction[x][y],
6426 DrawLevelGraphicAnimation(x, y, graphic);
6427 PlayLevelSoundAction(x, y, ACTION_SHRINKING);
6429 if (Feld[newx][newy] == EL_ACID)
6431 SplashAcid(newx, newy);
6436 CreateField(newx, newy, EL_DIAGONAL_GROWING);
6438 Store[newx][newy] = EL_EMC_ANDROID;
6439 GfxElement[newx][newy] = EL_EMC_ANDROID;
6440 GfxAction[newx][newy] = ACTION_GROWING;
6441 GfxDir[newx][newy] = diagonal_move_dir;
6442 ChangeDelay[newx][newy] = change_delay;
6444 graphic = el_act_dir2img(GfxElement[newx][newy],
6445 GfxAction[newx][newy], GfxDir[newx][newy]);
6447 DrawLevelGraphicAnimation(newx, newy, graphic);
6448 PlayLevelSoundAction(newx, newy, ACTION_GROWING);
6454 Feld[newx][newy] = EL_EMPTY;
6455 DrawLevelField(newx, newy);
6457 PlayLevelSoundAction(x, y, ACTION_DIGGING);
6460 else if (!IS_FREE(newx, newy))
6463 if (IS_PLAYER(x, y))
6464 DrawPlayerField(x, y);
6466 DrawLevelField(x, y);
6472 else if (IS_CUSTOM_ELEMENT(element) &&
6473 CUSTOM_ELEMENT_CAN_ENTER_FIELD(element, newx, newy))
6475 int new_element = Feld[newx][newy];
6477 if (!IS_FREE(newx, newy))
6479 int action = (IS_DIGGABLE(new_element) ? ACTION_DIGGING :
6480 IS_COLLECTIBLE(new_element) ? ACTION_COLLECTING :
6483 /* no element can dig solid indestructible elements */
6484 if (IS_INDESTRUCTIBLE(new_element) &&
6485 !IS_DIGGABLE(new_element) &&
6486 !IS_COLLECTIBLE(new_element))
6489 if (AmoebaNr[newx][newy] &&
6490 (new_element == EL_AMOEBA_FULL ||
6491 new_element == EL_BD_AMOEBA ||
6492 new_element == EL_AMOEBA_GROWING))
6494 AmoebaCnt[AmoebaNr[newx][newy]]--;
6495 AmoebaCnt2[AmoebaNr[newx][newy]]--;
6498 if (IS_MOVING(newx, newy))
6499 RemoveMovingField(newx, newy);
6502 RemoveField(newx, newy);
6503 DrawLevelField(newx, newy);
6506 /* if digged element was about to explode, prevent the explosion */
6507 ExplodeField[newx][newy] = EX_TYPE_NONE;
6509 PlayLevelSoundAction(x, y, action);
6512 Store[newx][newy] = EL_EMPTY;
6514 /* this makes it possible to leave the removed element again */
6515 if (IS_EQUAL_OR_IN_GROUP(new_element, MOVE_ENTER_EL(element)))
6516 Store[newx][newy] = new_element;
6518 if (IS_EQUAL_OR_IN_GROUP(new_element, MOVE_ENTER_EL(element)))
6520 int move_leave_element = element_info[element].move_leave_element;
6522 /* this makes it possible to leave the removed element again */
6523 Store[newx][newy] = (move_leave_element == EL_TRIGGER_ELEMENT ?
6524 new_element : move_leave_element);
6528 if (move_pattern & MV_MAZE_RUNNER_STYLE)
6530 RunnerVisit[x][y] = FrameCounter;
6531 PlayerVisit[x][y] /= 8; /* expire player visit path */
6534 else if (element == EL_DRAGON && IN_LEV_FIELD(newx, newy))
6536 if (!IS_FREE(newx, newy))
6538 if (IS_PLAYER(x, y))
6539 DrawPlayerField(x, y);
6541 DrawLevelField(x, y);
6547 boolean wanna_flame = !RND(10);
6548 int dx = newx - x, dy = newy - y;
6549 int newx1 = newx + 1 * dx, newy1 = newy + 1 * dy;
6550 int newx2 = newx + 2 * dx, newy2 = newy + 2 * dy;
6551 int element1 = (IN_LEV_FIELD(newx1, newy1) ?
6552 MovingOrBlocked2Element(newx1, newy1) : EL_STEELWALL);
6553 int element2 = (IN_LEV_FIELD(newx2, newy2) ?
6554 MovingOrBlocked2Element(newx2, newy2) : EL_STEELWALL);
6557 IS_CLASSIC_ENEMY(element1) ||
6558 IS_CLASSIC_ENEMY(element2)) &&
6559 element1 != EL_DRAGON && element2 != EL_DRAGON &&
6560 element1 != EL_FLAMES && element2 != EL_FLAMES)
6562 ResetGfxAnimation(x, y);
6563 GfxAction[x][y] = ACTION_ATTACKING;
6565 if (IS_PLAYER(x, y))
6566 DrawPlayerField(x, y);
6568 DrawLevelField(x, y);
6570 PlayLevelSound(x, y, SND_DRAGON_ATTACKING);
6572 MovDelay[x][y] = 50;
6576 RemoveField(newx, newy);
6578 Feld[newx][newy] = EL_FLAMES;
6579 if (IN_LEV_FIELD(newx1, newy1) && Feld[newx1][newy1] == EL_EMPTY)
6582 RemoveField(newx1, newy1);
6584 Feld[newx1][newy1] = EL_FLAMES;
6586 if (IN_LEV_FIELD(newx2, newy2) && Feld[newx2][newy2] == EL_EMPTY)
6589 RemoveField(newx2, newy2);
6591 Feld[newx2][newy2] = EL_FLAMES;
6598 else if (element == EL_YAMYAM && IN_LEV_FIELD(newx, newy) &&
6599 Feld[newx][newy] == EL_DIAMOND)
6601 if (IS_MOVING(newx, newy))
6602 RemoveMovingField(newx, newy);
6605 Feld[newx][newy] = EL_EMPTY;
6606 DrawLevelField(newx, newy);
6609 PlayLevelSound(x, y, SND_YAMYAM_DIGGING);
6611 else if (element == EL_DARK_YAMYAM && IN_LEV_FIELD(newx, newy) &&
6612 IS_FOOD_DARK_YAMYAM(Feld[newx][newy]))
6614 if (AmoebaNr[newx][newy])
6616 AmoebaCnt2[AmoebaNr[newx][newy]]--;
6617 if (Feld[newx][newy] == EL_AMOEBA_FULL ||
6618 Feld[newx][newy] == EL_BD_AMOEBA)
6619 AmoebaCnt[AmoebaNr[newx][newy]]--;
6624 if (IS_MOVING(newx, newy) || IS_BLOCKED(newx, newy))
6626 RemoveMovingField(newx, newy);
6629 if (IS_MOVING(newx, newy))
6631 RemoveMovingField(newx, newy);
6636 Feld[newx][newy] = EL_EMPTY;
6637 DrawLevelField(newx, newy);
6640 PlayLevelSound(x, y, SND_DARK_YAMYAM_DIGGING);
6642 else if ((element == EL_PACMAN || element == EL_MOLE)
6643 && IN_LEV_FIELD(newx, newy) && IS_AMOEBOID(Feld[newx][newy]))
6645 if (AmoebaNr[newx][newy])
6647 AmoebaCnt2[AmoebaNr[newx][newy]]--;
6648 if (Feld[newx][newy] == EL_AMOEBA_FULL ||
6649 Feld[newx][newy] == EL_BD_AMOEBA)
6650 AmoebaCnt[AmoebaNr[newx][newy]]--;
6653 if (element == EL_MOLE)
6655 Feld[newx][newy] = EL_AMOEBA_SHRINKING;
6656 PlayLevelSound(x, y, SND_MOLE_DIGGING);
6658 ResetGfxAnimation(x, y);
6659 GfxAction[x][y] = ACTION_DIGGING;
6660 DrawLevelField(x, y);
6662 MovDelay[newx][newy] = 0; /* start amoeba shrinking delay */
6664 return; /* wait for shrinking amoeba */
6666 else /* element == EL_PACMAN */
6668 Feld[newx][newy] = EL_EMPTY;
6669 DrawLevelField(newx, newy);
6670 PlayLevelSound(x, y, SND_PACMAN_DIGGING);
6673 else if (element == EL_MOLE && IN_LEV_FIELD(newx, newy) &&
6674 (Feld[newx][newy] == EL_AMOEBA_SHRINKING ||
6675 (Feld[newx][newy] == EL_EMPTY && Stop[newx][newy])))
6677 /* wait for shrinking amoeba to completely disappear */
6680 else if (!IN_LEV_FIELD(newx, newy) || !IS_FREE(newx, newy))
6682 /* object was running against a wall */
6687 /* !!! NEW "CE_BLOCKED" STUFF !!! -- DOES NOT WORK YET... !!! */
6688 if (move_pattern & MV_ANY_DIRECTION &&
6689 move_pattern == MovDir[x][y])
6691 int blocking_element =
6692 (IN_LEV_FIELD(newx, newy) ? Feld[newx][newy] : BorderElement);
6694 CheckElementChangeBySide(x, y, element, blocking_element, CE_BLOCKED,
6697 element = Feld[x][y]; /* element might have changed */
6701 if (GFX_ELEMENT(element) != EL_SAND) /* !!! FIX THIS (crumble) !!! */
6702 DrawLevelElementAnimation(x, y, element);
6704 if (DONT_TOUCH(element))
6705 TestIfBadThingTouchesPlayer(x, y);
6710 InitMovingField(x, y, MovDir[x][y]);
6712 PlayLevelSoundAction(x, y, ACTION_MOVING);
6716 ContinueMoving(x, y);
6719 void ContinueMoving(int x, int y)
6721 int element = Feld[x][y];
6722 struct ElementInfo *ei = &element_info[element];
6723 int direction = MovDir[x][y];
6724 int dx = (direction == MV_LEFT ? -1 : direction == MV_RIGHT ? +1 : 0);
6725 int dy = (direction == MV_UP ? -1 : direction == MV_DOWN ? +1 : 0);
6726 int newx = x + dx, newy = y + dy;
6727 int stored = Store[x][y];
6728 int stored_new = Store[newx][newy];
6729 boolean pushed_by_player = (Pushed[x][y] && IS_PLAYER(x, y));
6730 boolean pushed_by_conveyor = (Pushed[x][y] && !IS_PLAYER(x, y));
6731 boolean last_line = (newy == lev_fieldy - 1);
6733 MovPos[x][y] += getElementMoveStepsize(x, y);
6735 if (pushed_by_player) /* special case: moving object pushed by player */
6736 MovPos[x][y] = SIGN(MovPos[x][y]) * (TILEX - ABS(PLAYERINFO(x,y)->MovPos));
6738 if (ABS(MovPos[x][y]) < TILEX)
6740 DrawLevelField(x, y);
6742 return; /* element is still moving */
6745 /* element reached destination field */
6747 Feld[x][y] = EL_EMPTY;
6748 Feld[newx][newy] = element;
6749 MovPos[x][y] = 0; /* force "not moving" for "crumbled sand" */
6751 if (Store[x][y] == EL_ACID) /* element is moving into acid pool */
6753 element = Feld[newx][newy] = EL_ACID;
6755 else if (element == EL_MOLE)
6757 Feld[x][y] = EL_SAND;
6759 DrawLevelFieldCrumbledSandNeighbours(x, y);
6761 else if (element == EL_QUICKSAND_FILLING)
6763 element = Feld[newx][newy] = get_next_element(element);
6764 Store[newx][newy] = Store[x][y];
6766 else if (element == EL_QUICKSAND_EMPTYING)
6768 Feld[x][y] = get_next_element(element);
6769 element = Feld[newx][newy] = Store[x][y];
6771 else if (element == EL_MAGIC_WALL_FILLING)
6773 element = Feld[newx][newy] = get_next_element(element);
6774 if (!game.magic_wall_active)
6775 element = Feld[newx][newy] = EL_MAGIC_WALL_DEAD;
6776 Store[newx][newy] = Store[x][y];
6778 else if (element == EL_MAGIC_WALL_EMPTYING)
6780 Feld[x][y] = get_next_element(element);
6781 if (!game.magic_wall_active)
6782 Feld[x][y] = EL_MAGIC_WALL_DEAD;
6783 element = Feld[newx][newy] = Store[x][y];
6785 #if USE_NEW_CUSTOM_VALUE
6786 InitField(newx, newy, FALSE);
6789 else if (element == EL_BD_MAGIC_WALL_FILLING)
6791 element = Feld[newx][newy] = get_next_element(element);
6792 if (!game.magic_wall_active)
6793 element = Feld[newx][newy] = EL_BD_MAGIC_WALL_DEAD;
6794 Store[newx][newy] = Store[x][y];
6796 else if (element == EL_BD_MAGIC_WALL_EMPTYING)
6798 Feld[x][y] = get_next_element(element);
6799 if (!game.magic_wall_active)
6800 Feld[x][y] = EL_BD_MAGIC_WALL_DEAD;
6801 element = Feld[newx][newy] = Store[x][y];
6803 #if USE_NEW_CUSTOM_VALUE
6804 InitField(newx, newy, FALSE);
6807 else if (element == EL_AMOEBA_DROPPING)
6809 Feld[x][y] = get_next_element(element);
6810 element = Feld[newx][newy] = Store[x][y];
6812 else if (element == EL_SOKOBAN_OBJECT)
6815 Feld[x][y] = Back[x][y];
6817 if (Back[newx][newy])
6818 Feld[newx][newy] = EL_SOKOBAN_FIELD_FULL;
6820 Back[x][y] = Back[newx][newy] = 0;
6823 Store[x][y] = EL_EMPTY;
6828 MovDelay[newx][newy] = 0;
6831 if (CAN_CHANGE_OR_HAS_ACTION(element))
6833 if (CAN_CHANGE(element))
6836 /* copy element change control values to new field */
6837 ChangeDelay[newx][newy] = ChangeDelay[x][y];
6838 ChangePage[newx][newy] = ChangePage[x][y];
6839 ChangeCount[newx][newy] = ChangeCount[x][y];
6840 ChangeEvent[newx][newy] = ChangeEvent[x][y];
6843 #if USE_NEW_CUSTOM_VALUE
6844 CustomValue[newx][newy] = CustomValue[x][y];
6850 #if USE_NEW_CUSTOM_VALUE
6851 CustomValue[newx][newy] = CustomValue[x][y];
6855 ChangeDelay[x][y] = 0;
6856 ChangePage[x][y] = -1;
6857 ChangeCount[x][y] = 0;
6858 ChangeEvent[x][y] = -1;
6860 #if USE_NEW_CUSTOM_VALUE
6861 CustomValue[x][y] = 0;
6864 /* copy animation control values to new field */
6865 GfxFrame[newx][newy] = GfxFrame[x][y];
6866 GfxRandom[newx][newy] = GfxRandom[x][y]; /* keep same random value */
6867 GfxAction[newx][newy] = GfxAction[x][y]; /* keep action one frame */
6868 GfxDir[newx][newy] = GfxDir[x][y]; /* keep element direction */
6870 Pushed[x][y] = Pushed[newx][newy] = FALSE;
6872 /* some elements can leave other elements behind after moving */
6874 if (ei->move_leave_element != EL_EMPTY &&
6875 (ei->move_leave_type == LEAVE_TYPE_UNLIMITED || stored != EL_EMPTY) &&
6876 (!IS_PLAYER(x, y) || IS_WALKABLE(ei->move_leave_element)))
6878 if (IS_CUSTOM_ELEMENT(element) && ei->move_leave_element != EL_EMPTY &&
6879 (ei->move_leave_type == LEAVE_TYPE_UNLIMITED || stored != EL_EMPTY) &&
6880 (!IS_PLAYER(x, y) || IS_WALKABLE(ei->move_leave_element)))
6883 int move_leave_element = ei->move_leave_element;
6887 /* this makes it possible to leave the removed element again */
6888 if (ei->move_leave_element == EL_TRIGGER_ELEMENT)
6889 move_leave_element = (stored == EL_ACID ? EL_EMPTY : stored);
6891 /* this makes it possible to leave the removed element again */
6892 if (ei->move_leave_element == EL_TRIGGER_ELEMENT)
6893 move_leave_element = stored;
6896 /* this makes it possible to leave the removed element again */
6897 if (ei->move_leave_type == LEAVE_TYPE_LIMITED &&
6898 ei->move_leave_element == EL_TRIGGER_ELEMENT)
6899 move_leave_element = stored;
6902 Feld[x][y] = move_leave_element;
6904 if (element_info[Feld[x][y]].move_direction_initial == MV_START_PREVIOUS)
6905 MovDir[x][y] = direction;
6907 InitField(x, y, FALSE);
6909 if (GFX_CRUMBLED(Feld[x][y]))
6910 DrawLevelFieldCrumbledSandNeighbours(x, y);
6912 if (ELEM_IS_PLAYER(move_leave_element))
6913 RelocatePlayer(x, y, move_leave_element);
6916 /* do this after checking for left-behind element */
6917 ResetGfxAnimation(x, y); /* reset animation values for old field */
6919 if (!CAN_MOVE(element) ||
6920 (CAN_FALL(element) && direction == MV_DOWN &&
6921 (element == EL_SPRING ||
6922 element_info[element].move_pattern == MV_WHEN_PUSHED ||
6923 element_info[element].move_pattern == MV_WHEN_DROPPED)))
6924 GfxDir[x][y] = MovDir[newx][newy] = 0;
6926 DrawLevelField(x, y);
6927 DrawLevelField(newx, newy);
6929 Stop[newx][newy] = TRUE; /* ignore this element until the next frame */
6931 /* prevent pushed element from moving on in pushed direction */
6932 if (pushed_by_player && CAN_MOVE(element) &&
6933 element_info[element].move_pattern & MV_ANY_DIRECTION &&
6934 !(element_info[element].move_pattern & direction))
6935 TurnRound(newx, newy);
6937 /* prevent elements on conveyor belt from moving on in last direction */
6938 if (pushed_by_conveyor && CAN_FALL(element) &&
6939 direction & MV_HORIZONTAL)
6940 MovDir[newx][newy] = 0;
6942 if (!pushed_by_player)
6944 int nextx = newx + dx, nexty = newy + dy;
6945 boolean check_collision_again = IN_LEV_FIELD_AND_IS_FREE(nextx, nexty);
6947 WasJustMoving[newx][newy] = CHECK_DELAY_MOVING;
6949 if (CAN_FALL(element) && direction == MV_DOWN)
6950 WasJustFalling[newx][newy] = CHECK_DELAY_FALLING;
6952 if ((!CAN_FALL(element) || direction == MV_DOWN) && check_collision_again)
6953 CheckCollision[newx][newy] = CHECK_DELAY_COLLISION;
6956 if (DONT_TOUCH(element)) /* object may be nasty to player or others */
6958 TestIfBadThingTouchesPlayer(newx, newy);
6959 TestIfBadThingTouchesFriend(newx, newy);
6961 if (!IS_CUSTOM_ELEMENT(element))
6962 TestIfBadThingTouchesOtherBadThing(newx, newy);
6964 else if (element == EL_PENGUIN)
6965 TestIfFriendTouchesBadThing(newx, newy);
6967 /* give the player one last chance (one more frame) to move away */
6968 if (CAN_FALL(element) && direction == MV_DOWN &&
6969 (last_line || (!IS_FREE(x, newy + 1) &&
6970 (!IS_PLAYER(x, newy + 1) ||
6971 game.engine_version < VERSION_IDENT(3,1,1,0)))))
6974 if (pushed_by_player && !game.use_change_when_pushing_bug)
6976 int push_side = MV_DIR_OPPOSITE(direction);
6977 struct PlayerInfo *player = PLAYERINFO(x, y);
6979 CheckElementChangeByPlayer(newx, newy, element, CE_PUSHED_BY_PLAYER,
6980 player->index_bit, push_side);
6981 CheckTriggeredElementChangeByPlayer(newx,newy, element, CE_PLAYER_PUSHES_X,
6982 player->index_bit, push_side);
6985 if (element == EL_EMC_ANDROID && pushed_by_player) /* make another move */
6986 MovDelay[newx][newy] = 1;
6988 CheckTriggeredElementChangeBySide(x, y, element, CE_MOVE_OF_X, direction);
6990 TestIfElementTouchesCustomElement(x, y); /* empty or new element */
6993 if (ChangePage[newx][newy] != -1) /* delayed change */
6995 int page = ChangePage[newx][newy];
6996 struct ElementChangeInfo *change = &ei->change_page[page];
6998 ChangePage[newx][newy] = -1;
7000 if (change->can_change)
7002 if (ChangeElement(newx, newy, element, page))
7004 if (change->post_change_function)
7005 change->post_change_function(newx, newy);
7009 if (change->has_action)
7010 ExecuteCustomElementAction(newx, newy, element, page);
7014 TestIfElementHitsCustomElement(newx, newy, direction);
7015 TestIfPlayerTouchesCustomElement(newx, newy);
7016 TestIfElementTouchesCustomElement(newx, newy);
7019 if (IS_CUSTOM_ELEMENT(element) && ei->move_enter_element != EL_EMPTY &&
7020 IS_EQUAL_OR_IN_GROUP(stored_new, ei->move_enter_element))
7021 CheckElementChangeBySide(newx, newy, element, stored_new, CE_DIGGING_X,
7022 MV_DIR_OPPOSITE(direction));
7026 int AmoebeNachbarNr(int ax, int ay)
7029 int element = Feld[ax][ay];
7031 static int xy[4][2] =
7039 for (i = 0; i < NUM_DIRECTIONS; i++)
7041 int x = ax + xy[i][0];
7042 int y = ay + xy[i][1];
7044 if (!IN_LEV_FIELD(x, y))
7047 if (Feld[x][y] == element && AmoebaNr[x][y] > 0)
7048 group_nr = AmoebaNr[x][y];
7054 void AmoebenVereinigen(int ax, int ay)
7056 int i, x, y, xx, yy;
7057 int new_group_nr = AmoebaNr[ax][ay];
7058 static int xy[4][2] =
7066 if (new_group_nr == 0)
7069 for (i = 0; i < NUM_DIRECTIONS; i++)
7074 if (!IN_LEV_FIELD(x, y))
7077 if ((Feld[x][y] == EL_AMOEBA_FULL ||
7078 Feld[x][y] == EL_BD_AMOEBA ||
7079 Feld[x][y] == EL_AMOEBA_DEAD) &&
7080 AmoebaNr[x][y] != new_group_nr)
7082 int old_group_nr = AmoebaNr[x][y];
7084 if (old_group_nr == 0)
7087 AmoebaCnt[new_group_nr] += AmoebaCnt[old_group_nr];
7088 AmoebaCnt[old_group_nr] = 0;
7089 AmoebaCnt2[new_group_nr] += AmoebaCnt2[old_group_nr];
7090 AmoebaCnt2[old_group_nr] = 0;
7093 SCAN_PLAYFIELD(xx, yy)
7095 for (yy = 0; yy < lev_fieldy; yy++) for (xx = 0; xx < lev_fieldx; xx++)
7098 if (AmoebaNr[xx][yy] == old_group_nr)
7099 AmoebaNr[xx][yy] = new_group_nr;
7105 void AmoebeUmwandeln(int ax, int ay)
7109 if (Feld[ax][ay] == EL_AMOEBA_DEAD)
7111 int group_nr = AmoebaNr[ax][ay];
7116 printf("AmoebeUmwandeln(): ax = %d, ay = %d\n", ax, ay);
7117 printf("AmoebeUmwandeln(): This should never happen!\n");
7123 SCAN_PLAYFIELD(x, y)
7125 for (y = 0; y < lev_fieldy; y++) for (x = 0; x < lev_fieldx; x++)
7128 if (Feld[x][y] == EL_AMOEBA_DEAD && AmoebaNr[x][y] == group_nr)
7131 Feld[x][y] = EL_AMOEBA_TO_DIAMOND;
7135 PlayLevelSound(ax, ay, (IS_GEM(level.amoeba_content) ?
7136 SND_AMOEBA_TURNING_TO_GEM :
7137 SND_AMOEBA_TURNING_TO_ROCK));
7142 static int xy[4][2] =
7150 for (i = 0; i < NUM_DIRECTIONS; i++)
7155 if (!IN_LEV_FIELD(x, y))
7158 if (Feld[x][y] == EL_AMOEBA_TO_DIAMOND)
7160 PlayLevelSound(x, y, (IS_GEM(level.amoeba_content) ?
7161 SND_AMOEBA_TURNING_TO_GEM :
7162 SND_AMOEBA_TURNING_TO_ROCK));
7169 void AmoebeUmwandelnBD(int ax, int ay, int new_element)
7172 int group_nr = AmoebaNr[ax][ay];
7173 boolean done = FALSE;
7178 printf("AmoebeUmwandelnBD(): ax = %d, ay = %d\n", ax, ay);
7179 printf("AmoebeUmwandelnBD(): This should never happen!\n");
7185 SCAN_PLAYFIELD(x, y)
7187 for (y = 0; y < lev_fieldy; y++) for (x = 0; x < lev_fieldx; x++)
7190 if (AmoebaNr[x][y] == group_nr &&
7191 (Feld[x][y] == EL_AMOEBA_DEAD ||
7192 Feld[x][y] == EL_BD_AMOEBA ||
7193 Feld[x][y] == EL_AMOEBA_GROWING))
7196 Feld[x][y] = new_element;
7197 InitField(x, y, FALSE);
7198 DrawLevelField(x, y);
7204 PlayLevelSound(ax, ay, (new_element == EL_BD_ROCK ?
7205 SND_BD_AMOEBA_TURNING_TO_ROCK :
7206 SND_BD_AMOEBA_TURNING_TO_GEM));
7209 void AmoebeWaechst(int x, int y)
7211 static unsigned long sound_delay = 0;
7212 static unsigned long sound_delay_value = 0;
7214 if (!MovDelay[x][y]) /* start new growing cycle */
7218 if (DelayReached(&sound_delay, sound_delay_value))
7220 PlayLevelSoundElementAction(x, y, Store[x][y], ACTION_GROWING);
7221 sound_delay_value = 30;
7225 if (MovDelay[x][y]) /* wait some time before growing bigger */
7228 if (MovDelay[x][y]/2 && IN_SCR_FIELD(SCREENX(x), SCREENY(y)))
7230 int frame = getGraphicAnimationFrame(IMG_AMOEBA_GROWING,
7231 6 - MovDelay[x][y]);
7233 DrawGraphic(SCREENX(x), SCREENY(y), IMG_AMOEBA_GROWING, frame);
7236 if (!MovDelay[x][y])
7238 Feld[x][y] = Store[x][y];
7240 DrawLevelField(x, y);
7245 void AmoebaDisappearing(int x, int y)
7247 static unsigned long sound_delay = 0;
7248 static unsigned long sound_delay_value = 0;
7250 if (!MovDelay[x][y]) /* start new shrinking cycle */
7254 if (DelayReached(&sound_delay, sound_delay_value))
7255 sound_delay_value = 30;
7258 if (MovDelay[x][y]) /* wait some time before shrinking */
7261 if (MovDelay[x][y]/2 && IN_SCR_FIELD(SCREENX(x), SCREENY(y)))
7263 int frame = getGraphicAnimationFrame(IMG_AMOEBA_SHRINKING,
7264 6 - MovDelay[x][y]);
7266 DrawGraphic(SCREENX(x), SCREENY(y), IMG_AMOEBA_SHRINKING, frame);
7269 if (!MovDelay[x][y])
7271 Feld[x][y] = EL_EMPTY;
7272 DrawLevelField(x, y);
7274 /* don't let mole enter this field in this cycle;
7275 (give priority to objects falling to this field from above) */
7281 void AmoebeAbleger(int ax, int ay)
7284 int element = Feld[ax][ay];
7285 int graphic = el2img(element);
7286 int newax = ax, neway = ay;
7287 boolean can_drop = (element == EL_AMOEBA_WET || element == EL_EMC_DRIPPER);
7288 static int xy[4][2] =
7296 if (!level.amoeba_speed && element != EL_EMC_DRIPPER)
7298 Feld[ax][ay] = EL_AMOEBA_DEAD;
7299 DrawLevelField(ax, ay);
7303 if (IS_ANIMATED(graphic))
7304 DrawLevelGraphicAnimationIfNeeded(ax, ay, graphic);
7306 if (!MovDelay[ax][ay]) /* start making new amoeba field */
7307 MovDelay[ax][ay] = RND(FRAMES_PER_SECOND * 25 / (1 + level.amoeba_speed));
7309 if (MovDelay[ax][ay]) /* wait some time before making new amoeba */
7312 if (MovDelay[ax][ay])
7316 if (can_drop) /* EL_AMOEBA_WET or EL_EMC_DRIPPER */
7319 int x = ax + xy[start][0];
7320 int y = ay + xy[start][1];
7322 if (!IN_LEV_FIELD(x, y))
7325 if (IS_FREE(x, y) ||
7326 CAN_GROW_INTO(Feld[x][y]) ||
7327 Feld[x][y] == EL_QUICKSAND_EMPTY)
7333 if (newax == ax && neway == ay)
7336 else /* normal or "filled" (BD style) amoeba */
7339 boolean waiting_for_player = FALSE;
7341 for (i = 0; i < NUM_DIRECTIONS; i++)
7343 int j = (start + i) % 4;
7344 int x = ax + xy[j][0];
7345 int y = ay + xy[j][1];
7347 if (!IN_LEV_FIELD(x, y))
7350 if (IS_FREE(x, y) ||
7351 CAN_GROW_INTO(Feld[x][y]) ||
7352 Feld[x][y] == EL_QUICKSAND_EMPTY)
7358 else if (IS_PLAYER(x, y))
7359 waiting_for_player = TRUE;
7362 if (newax == ax && neway == ay) /* amoeba cannot grow */
7364 if (i == 4 && (!waiting_for_player || element == EL_BD_AMOEBA))
7366 Feld[ax][ay] = EL_AMOEBA_DEAD;
7367 DrawLevelField(ax, ay);
7368 AmoebaCnt[AmoebaNr[ax][ay]]--;
7370 if (AmoebaCnt[AmoebaNr[ax][ay]] <= 0) /* amoeba is completely dead */
7372 if (element == EL_AMOEBA_FULL)
7373 AmoebeUmwandeln(ax, ay);
7374 else if (element == EL_BD_AMOEBA)
7375 AmoebeUmwandelnBD(ax, ay, level.amoeba_content);
7380 else if (element == EL_AMOEBA_FULL || element == EL_BD_AMOEBA)
7382 /* amoeba gets larger by growing in some direction */
7384 int new_group_nr = AmoebaNr[ax][ay];
7387 if (new_group_nr == 0)
7389 printf("AmoebeAbleger(): newax = %d, neway = %d\n", newax, neway);
7390 printf("AmoebeAbleger(): This should never happen!\n");
7395 AmoebaNr[newax][neway] = new_group_nr;
7396 AmoebaCnt[new_group_nr]++;
7397 AmoebaCnt2[new_group_nr]++;
7399 /* if amoeba touches other amoeba(s) after growing, unify them */
7400 AmoebenVereinigen(newax, neway);
7402 if (element == EL_BD_AMOEBA && AmoebaCnt2[new_group_nr] >= 200)
7404 AmoebeUmwandelnBD(newax, neway, EL_BD_ROCK);
7410 if (!can_drop || neway < ay || !IS_FREE(newax, neway) ||
7411 (neway == lev_fieldy - 1 && newax != ax))
7413 Feld[newax][neway] = EL_AMOEBA_GROWING; /* creation of new amoeba */
7414 Store[newax][neway] = element;
7416 else if (neway == ay || element == EL_EMC_DRIPPER)
7418 Feld[newax][neway] = EL_AMOEBA_DROP; /* drop left/right of amoeba */
7420 PlayLevelSoundAction(newax, neway, ACTION_GROWING);
7424 InitMovingField(ax, ay, MV_DOWN); /* drop dripping from amoeba */
7425 Feld[ax][ay] = EL_AMOEBA_DROPPING;
7426 Store[ax][ay] = EL_AMOEBA_DROP;
7427 ContinueMoving(ax, ay);
7431 DrawLevelField(newax, neway);
7434 void Life(int ax, int ay)
7438 static int life[4] = { 2, 3, 3, 3 }; /* parameters for "game of life" */
7441 int element = Feld[ax][ay];
7442 int graphic = el2img(element);
7443 int *life_parameter = (element == EL_GAME_OF_LIFE ? level.game_of_life :
7445 boolean changed = FALSE;
7447 if (IS_ANIMATED(graphic))
7448 DrawLevelGraphicAnimationIfNeeded(ax, ay, graphic);
7453 if (!MovDelay[ax][ay]) /* start new "game of life" cycle */
7454 MovDelay[ax][ay] = life_time;
7456 if (MovDelay[ax][ay]) /* wait some time before next cycle */
7459 if (MovDelay[ax][ay])
7463 for (y1 = -1; y1 < 2; y1++) for (x1 = -1; x1 < 2; x1++)
7465 int xx = ax+x1, yy = ay+y1;
7468 if (!IN_LEV_FIELD(xx, yy))
7471 for (y2 = -1; y2 < 2; y2++) for (x2 = -1; x2 < 2; x2++)
7473 int x = xx+x2, y = yy+y2;
7475 if (!IN_LEV_FIELD(x, y) || (x == xx && y == yy))
7478 if (((Feld[x][y] == element ||
7479 (element == EL_GAME_OF_LIFE && IS_PLAYER(x, y))) &&
7481 (IS_FREE(x, y) && Stop[x][y]))
7485 if (xx == ax && yy == ay) /* field in the middle */
7487 if (nachbarn < life_parameter[0] ||
7488 nachbarn > life_parameter[1])
7490 Feld[xx][yy] = EL_EMPTY;
7492 DrawLevelField(xx, yy);
7493 Stop[xx][yy] = TRUE;
7497 else if (IS_FREE(xx, yy) || CAN_GROW_INTO(Feld[xx][yy]))
7498 { /* free border field */
7499 if (nachbarn >= life_parameter[2] &&
7500 nachbarn <= life_parameter[3])
7502 Feld[xx][yy] = element;
7503 MovDelay[xx][yy] = (element == EL_GAME_OF_LIFE ? 0 : life_time-1);
7505 DrawLevelField(xx, yy);
7506 Stop[xx][yy] = TRUE;
7513 PlayLevelSound(ax, ay, element == EL_BIOMAZE ? SND_BIOMAZE_GROWING :
7514 SND_GAME_OF_LIFE_GROWING);
7517 static void InitRobotWheel(int x, int y)
7519 ChangeDelay[x][y] = level.time_wheel * FRAMES_PER_SECOND;
7522 static void RunRobotWheel(int x, int y)
7524 PlayLevelSound(x, y, SND_ROBOT_WHEEL_ACTIVE);
7527 static void StopRobotWheel(int x, int y)
7529 if (ZX == x && ZY == y)
7533 static void InitTimegateWheel(int x, int y)
7535 ChangeDelay[x][y] = level.time_timegate * FRAMES_PER_SECOND;
7538 static void RunTimegateWheel(int x, int y)
7540 PlayLevelSound(x, y, SND_TIMEGATE_SWITCH_ACTIVE);
7543 static void InitMagicBallDelay(int x, int y)
7546 ChangeDelay[x][y] = (level.ball_time + 1) * 8 + 1;
7548 ChangeDelay[x][y] = level.ball_time * FRAMES_PER_SECOND + 1;
7552 static void ActivateMagicBall(int bx, int by)
7556 if (level.ball_random)
7558 int pos_border = RND(8); /* select one of the eight border elements */
7559 int pos_content = (pos_border > 3 ? pos_border + 1 : pos_border);
7560 int xx = pos_content % 3;
7561 int yy = pos_content / 3;
7566 if (IN_LEV_FIELD(x, y) && Feld[x][y] == EL_EMPTY)
7567 CreateField(x, y, level.ball_content[game.ball_content_nr].e[xx][yy]);
7571 for (y = by - 1; y <= by + 1; y++) for (x = bx - 1; x <= bx + 1; x++)
7573 int xx = x - bx + 1;
7574 int yy = y - by + 1;
7576 if (IN_LEV_FIELD(x, y) && Feld[x][y] == EL_EMPTY)
7577 CreateField(x, y, level.ball_content[game.ball_content_nr].e[xx][yy]);
7581 game.ball_content_nr = (game.ball_content_nr + 1) % level.num_ball_contents;
7584 static void InitDiagonalMovingElement(int x, int y)
7587 MovDelay[x][y] = level.android_move_time;
7591 void CheckExit(int x, int y)
7593 if (local_player->gems_still_needed > 0 ||
7594 local_player->sokobanfields_still_needed > 0 ||
7595 local_player->lights_still_needed > 0)
7597 int element = Feld[x][y];
7598 int graphic = el2img(element);
7600 if (IS_ANIMATED(graphic))
7601 DrawLevelGraphicAnimationIfNeeded(x, y, graphic);
7606 if (AllPlayersGone) /* do not re-open exit door closed after last player */
7609 Feld[x][y] = EL_EXIT_OPENING;
7611 PlayLevelSoundNearest(x, y, SND_CLASS_EXIT_OPENING);
7614 void CheckExitSP(int x, int y)
7616 if (local_player->gems_still_needed > 0)
7618 int element = Feld[x][y];
7619 int graphic = el2img(element);
7621 if (IS_ANIMATED(graphic))
7622 DrawLevelGraphicAnimationIfNeeded(x, y, graphic);
7627 if (AllPlayersGone) /* do not re-open exit door closed after last player */
7630 Feld[x][y] = EL_SP_EXIT_OPENING;
7632 PlayLevelSoundNearest(x, y, SND_CLASS_SP_EXIT_OPENING);
7635 static void CloseAllOpenTimegates()
7640 SCAN_PLAYFIELD(x, y)
7642 for (y = 0; y < lev_fieldy; y++) for (x = 0; x < lev_fieldx; x++)
7645 int element = Feld[x][y];
7647 if (element == EL_TIMEGATE_OPEN || element == EL_TIMEGATE_OPENING)
7649 Feld[x][y] = EL_TIMEGATE_CLOSING;
7651 PlayLevelSoundAction(x, y, ACTION_CLOSING);
7656 void EdelsteinFunkeln(int x, int y)
7658 if (!IN_SCR_FIELD(SCREENX(x), SCREENY(y)) || IS_MOVING(x, y))
7661 if (Feld[x][y] == EL_BD_DIAMOND)
7664 if (MovDelay[x][y] == 0) /* next animation frame */
7665 MovDelay[x][y] = 11 * !SimpleRND(500);
7667 if (MovDelay[x][y] != 0) /* wait some time before next frame */
7671 if (setup.direct_draw && MovDelay[x][y])
7672 SetDrawtoField(DRAW_BUFFERED);
7674 DrawLevelElementAnimation(x, y, Feld[x][y]);
7676 if (MovDelay[x][y] != 0)
7678 int frame = getGraphicAnimationFrame(IMG_TWINKLE_WHITE,
7679 10 - MovDelay[x][y]);
7681 DrawGraphicThruMask(SCREENX(x), SCREENY(y), IMG_TWINKLE_WHITE, frame);
7683 if (setup.direct_draw)
7687 dest_x = FX + SCREENX(x) * TILEX;
7688 dest_y = FY + SCREENY(y) * TILEY;
7690 BlitBitmap(drawto_field, window,
7691 dest_x, dest_y, TILEX, TILEY, dest_x, dest_y);
7692 SetDrawtoField(DRAW_DIRECT);
7698 void MauerWaechst(int x, int y)
7702 if (!MovDelay[x][y]) /* next animation frame */
7703 MovDelay[x][y] = 3 * delay;
7705 if (MovDelay[x][y]) /* wait some time before next frame */
7709 if (IN_SCR_FIELD(SCREENX(x), SCREENY(y)))
7711 int graphic = el_dir2img(Feld[x][y], GfxDir[x][y]);
7712 int frame = getGraphicAnimationFrame(graphic, 17 - MovDelay[x][y]);
7714 DrawGraphic(SCREENX(x), SCREENY(y), graphic, frame);
7717 if (!MovDelay[x][y])
7719 if (MovDir[x][y] == MV_LEFT)
7721 if (IN_LEV_FIELD(x - 1, y) && IS_WALL(Feld[x - 1][y]))
7722 DrawLevelField(x - 1, y);
7724 else if (MovDir[x][y] == MV_RIGHT)
7726 if (IN_LEV_FIELD(x + 1, y) && IS_WALL(Feld[x + 1][y]))
7727 DrawLevelField(x + 1, y);
7729 else if (MovDir[x][y] == MV_UP)
7731 if (IN_LEV_FIELD(x, y - 1) && IS_WALL(Feld[x][y - 1]))
7732 DrawLevelField(x, y - 1);
7736 if (IN_LEV_FIELD(x, y + 1) && IS_WALL(Feld[x][y + 1]))
7737 DrawLevelField(x, y + 1);
7740 Feld[x][y] = Store[x][y];
7742 GfxDir[x][y] = MovDir[x][y] = MV_NONE;
7743 DrawLevelField(x, y);
7748 void MauerAbleger(int ax, int ay)
7750 int element = Feld[ax][ay];
7751 int graphic = el2img(element);
7752 boolean oben_frei = FALSE, unten_frei = FALSE;
7753 boolean links_frei = FALSE, rechts_frei = FALSE;
7754 boolean oben_massiv = FALSE, unten_massiv = FALSE;
7755 boolean links_massiv = FALSE, rechts_massiv = FALSE;
7756 boolean new_wall = FALSE;
7758 if (IS_ANIMATED(graphic))
7759 DrawLevelGraphicAnimationIfNeeded(ax, ay, graphic);
7761 if (!MovDelay[ax][ay]) /* start building new wall */
7762 MovDelay[ax][ay] = 6;
7764 if (MovDelay[ax][ay]) /* wait some time before building new wall */
7767 if (MovDelay[ax][ay])
7771 if (IN_LEV_FIELD(ax, ay-1) && IS_FREE(ax, ay-1))
7773 if (IN_LEV_FIELD(ax, ay+1) && IS_FREE(ax, ay+1))
7775 if (IN_LEV_FIELD(ax-1, ay) && IS_FREE(ax-1, ay))
7777 if (IN_LEV_FIELD(ax+1, ay) && IS_FREE(ax+1, ay))
7780 if (element == EL_EXPANDABLE_WALL_VERTICAL ||
7781 element == EL_EXPANDABLE_WALL_ANY)
7785 Feld[ax][ay-1] = EL_EXPANDABLE_WALL_GROWING;
7786 Store[ax][ay-1] = element;
7787 GfxDir[ax][ay-1] = MovDir[ax][ay-1] = MV_UP;
7788 if (IN_SCR_FIELD(SCREENX(ax), SCREENY(ay-1)))
7789 DrawGraphic(SCREENX(ax), SCREENY(ay - 1),
7790 IMG_EXPANDABLE_WALL_GROWING_UP, 0);
7795 Feld[ax][ay+1] = EL_EXPANDABLE_WALL_GROWING;
7796 Store[ax][ay+1] = element;
7797 GfxDir[ax][ay+1] = MovDir[ax][ay+1] = MV_DOWN;
7798 if (IN_SCR_FIELD(SCREENX(ax), SCREENY(ay+1)))
7799 DrawGraphic(SCREENX(ax), SCREENY(ay + 1),
7800 IMG_EXPANDABLE_WALL_GROWING_DOWN, 0);
7805 if (element == EL_EXPANDABLE_WALL_HORIZONTAL ||
7806 element == EL_EXPANDABLE_WALL_ANY ||
7807 element == EL_EXPANDABLE_WALL)
7811 Feld[ax-1][ay] = EL_EXPANDABLE_WALL_GROWING;
7812 Store[ax-1][ay] = element;
7813 GfxDir[ax-1][ay] = MovDir[ax-1][ay] = MV_LEFT;
7814 if (IN_SCR_FIELD(SCREENX(ax-1), SCREENY(ay)))
7815 DrawGraphic(SCREENX(ax - 1), SCREENY(ay),
7816 IMG_EXPANDABLE_WALL_GROWING_LEFT, 0);
7822 Feld[ax+1][ay] = EL_EXPANDABLE_WALL_GROWING;
7823 Store[ax+1][ay] = element;
7824 GfxDir[ax+1][ay] = MovDir[ax+1][ay] = MV_RIGHT;
7825 if (IN_SCR_FIELD(SCREENX(ax+1), SCREENY(ay)))
7826 DrawGraphic(SCREENX(ax + 1), SCREENY(ay),
7827 IMG_EXPANDABLE_WALL_GROWING_RIGHT, 0);
7832 if (element == EL_EXPANDABLE_WALL && (links_frei || rechts_frei))
7833 DrawLevelField(ax, ay);
7835 if (!IN_LEV_FIELD(ax, ay-1) || IS_WALL(Feld[ax][ay-1]))
7837 if (!IN_LEV_FIELD(ax, ay+1) || IS_WALL(Feld[ax][ay+1]))
7838 unten_massiv = TRUE;
7839 if (!IN_LEV_FIELD(ax-1, ay) || IS_WALL(Feld[ax-1][ay]))
7840 links_massiv = TRUE;
7841 if (!IN_LEV_FIELD(ax+1, ay) || IS_WALL(Feld[ax+1][ay]))
7842 rechts_massiv = TRUE;
7844 if (((oben_massiv && unten_massiv) ||
7845 element == EL_EXPANDABLE_WALL_HORIZONTAL ||
7846 element == EL_EXPANDABLE_WALL) &&
7847 ((links_massiv && rechts_massiv) ||
7848 element == EL_EXPANDABLE_WALL_VERTICAL))
7849 Feld[ax][ay] = EL_WALL;
7852 PlayLevelSoundAction(ax, ay, ACTION_GROWING);
7855 void CheckForDragon(int x, int y)
7858 boolean dragon_found = FALSE;
7859 static int xy[4][2] =
7867 for (i = 0; i < NUM_DIRECTIONS; i++)
7869 for (j = 0; j < 4; j++)
7871 int xx = x + j * xy[i][0], yy = y + j * xy[i][1];
7873 if (IN_LEV_FIELD(xx, yy) &&
7874 (Feld[xx][yy] == EL_FLAMES || Feld[xx][yy] == EL_DRAGON))
7876 if (Feld[xx][yy] == EL_DRAGON)
7877 dragon_found = TRUE;
7886 for (i = 0; i < NUM_DIRECTIONS; i++)
7888 for (j = 0; j < 3; j++)
7890 int xx = x + j * xy[i][0], yy = y + j * xy[i][1];
7892 if (IN_LEV_FIELD(xx, yy) && Feld[xx][yy] == EL_FLAMES)
7894 Feld[xx][yy] = EL_EMPTY;
7895 DrawLevelField(xx, yy);
7904 static void InitBuggyBase(int x, int y)
7906 int element = Feld[x][y];
7907 int activating_delay = FRAMES_PER_SECOND / 4;
7910 (element == EL_SP_BUGGY_BASE ?
7911 2 * FRAMES_PER_SECOND + RND(5 * FRAMES_PER_SECOND) - activating_delay :
7912 element == EL_SP_BUGGY_BASE_ACTIVATING ?
7914 element == EL_SP_BUGGY_BASE_ACTIVE ?
7915 1 * FRAMES_PER_SECOND + RND(1 * FRAMES_PER_SECOND) : 1);
7918 static void WarnBuggyBase(int x, int y)
7921 static int xy[4][2] =
7929 for (i = 0; i < NUM_DIRECTIONS; i++)
7931 int xx = x + xy[i][0];
7932 int yy = y + xy[i][1];
7934 if (IN_LEV_FIELD(xx, yy) && IS_PLAYER(xx, yy))
7936 PlayLevelSound(x, y, SND_SP_BUGGY_BASE_ACTIVE);
7943 static void InitTrap(int x, int y)
7945 ChangeDelay[x][y] = 2 * FRAMES_PER_SECOND + RND(5 * FRAMES_PER_SECOND);
7948 static void ActivateTrap(int x, int y)
7950 PlayLevelSound(x, y, SND_TRAP_ACTIVATING);
7953 static void ChangeActiveTrap(int x, int y)
7955 int graphic = IMG_TRAP_ACTIVE;
7957 /* if new animation frame was drawn, correct crumbled sand border */
7958 if (IS_NEW_FRAME(GfxFrame[x][y], graphic))
7959 DrawLevelFieldCrumbledSand(x, y);
7962 static int getSpecialActionElement(int element, int number, int base_element)
7964 return (element != EL_EMPTY ? element :
7965 number != -1 ? base_element + number - 1 :
7969 static int getModifiedActionNumber(int value_old, int operator, int operand,
7970 int value_min, int value_max)
7972 int value_new = (operator == CA_MODE_SET ? operand :
7973 operator == CA_MODE_ADD ? value_old + operand :
7974 operator == CA_MODE_SUBTRACT ? value_old - operand :
7975 operator == CA_MODE_MULTIPLY ? value_old * operand :
7976 operator == CA_MODE_DIVIDE ? value_old / MAX(1, operand) :
7977 operator == CA_MODE_MODULO ? value_old % MAX(1, operand) :
7980 return (value_new < value_min ? value_min :
7981 value_new > value_max ? value_max :
7985 static void ExecuteCustomElementAction(int x, int y, int element, int page)
7987 struct ElementInfo *ei = &element_info[element];
7988 struct ElementChangeInfo *change = &ei->change_page[page];
7989 int target_element = change->target_element;
7990 int action_type = change->action_type;
7991 int action_mode = change->action_mode;
7992 int action_arg = change->action_arg;
7995 if (!change->has_action)
7998 /* ---------- determine action paramater values -------------------------- */
8000 int level_time_value =
8001 (level.time > 0 ? TimeLeft :
8004 int action_arg_element =
8005 (action_arg == CA_ARG_PLAYER_TRIGGER ? change->actual_trigger_player :
8006 action_arg == CA_ARG_ELEMENT_TRIGGER ? change->actual_trigger_element :
8007 action_arg == CA_ARG_ELEMENT_TARGET ? change->target_element :
8010 int action_arg_direction =
8011 (action_arg >= CA_ARG_DIRECTION_LEFT &&
8012 action_arg <= CA_ARG_DIRECTION_DOWN ? action_arg - CA_ARG_DIRECTION :
8013 action_arg == CA_ARG_DIRECTION_TRIGGER ?
8014 change->actual_trigger_side :
8015 action_arg == CA_ARG_DIRECTION_TRIGGER_BACK ?
8016 MV_DIR_OPPOSITE(change->actual_trigger_side) :
8019 int action_arg_number_min =
8020 (action_type == CA_SET_PLAYER_SPEED ? STEPSIZE_NOT_MOVING :
8023 int action_arg_number_max =
8024 (action_type == CA_SET_PLAYER_SPEED ? STEPSIZE_EVEN_FASTER :
8025 action_type == CA_SET_LEVEL_GEMS ? 999 :
8026 action_type == CA_SET_LEVEL_TIME ? 9999 :
8027 action_type == CA_SET_LEVEL_SCORE ? 99999 :
8028 action_type == CA_SET_CE_VALUE ? 9999 :
8029 action_type == CA_SET_CE_SCORE ? 9999 :
8032 int action_arg_number_reset =
8033 (action_type == CA_SET_PLAYER_SPEED ? level.initial_player_stepsize[0] :
8034 action_type == CA_SET_LEVEL_GEMS ? level.gems_needed :
8035 action_type == CA_SET_LEVEL_TIME ? level.time :
8036 action_type == CA_SET_LEVEL_SCORE ? 0 :
8038 action_type == CA_SET_CE_VALUE ? GET_NEW_CE_VALUE(element) :
8040 action_type == CA_SET_CE_VALUE ? ei->custom_value_initial :
8042 action_type == CA_SET_CE_SCORE ? 0 :
8045 int action_arg_number =
8046 (action_arg <= CA_ARG_MAX ? action_arg :
8047 action_arg >= CA_ARG_SPEED_NOT_MOVING &&
8048 action_arg <= CA_ARG_SPEED_EVEN_FASTER ? (action_arg - CA_ARG_SPEED) :
8049 action_arg == CA_ARG_SPEED_RESET ? action_arg_number_reset :
8050 action_arg == CA_ARG_NUMBER_MIN ? action_arg_number_min :
8051 action_arg == CA_ARG_NUMBER_MAX ? action_arg_number_max :
8052 action_arg == CA_ARG_NUMBER_RESET ? action_arg_number_reset :
8053 #if USE_NEW_CUSTOM_VALUE
8054 action_arg == CA_ARG_NUMBER_CE_VALUE ? CustomValue[x][y] :
8056 action_arg == CA_ARG_NUMBER_CE_VALUE ? ei->custom_value_initial :
8058 action_arg == CA_ARG_NUMBER_CE_SCORE ? ei->collect_score :
8059 action_arg == CA_ARG_NUMBER_CE_DELAY ? GET_CE_DELAY_VALUE(change) :
8060 action_arg == CA_ARG_NUMBER_LEVEL_TIME ? level_time_value :
8061 action_arg == CA_ARG_NUMBER_LEVEL_GEMS ? local_player->gems_still_needed :
8062 action_arg == CA_ARG_NUMBER_LEVEL_SCORE ? local_player->score :
8063 action_arg == CA_ARG_ELEMENT_CV_TARGET ? GET_NEW_CE_VALUE(target_element):
8064 action_arg == CA_ARG_ELEMENT_CV_TRIGGER ? change->actual_trigger_ce_value:
8065 action_arg == CA_ARG_ELEMENT_CS_TARGET ? GET_CE_SCORE(target_element) :
8066 action_arg == CA_ARG_ELEMENT_CS_TRIGGER ? change->actual_trigger_ce_score:
8067 action_arg == CA_ARG_ELEMENT_NR_TARGET ? change->target_element :
8068 action_arg == CA_ARG_ELEMENT_NR_TRIGGER ? change->actual_trigger_element :
8071 int action_arg_number_old =
8072 (action_type == CA_SET_LEVEL_GEMS ? local_player->gems_still_needed :
8073 action_type == CA_SET_LEVEL_TIME ? TimeLeft :
8074 action_type == CA_SET_LEVEL_SCORE ? local_player->score :
8075 action_type == CA_SET_CE_VALUE ? CustomValue[x][y] :
8076 action_type == CA_SET_CE_SCORE ? ei->collect_score :
8079 int action_arg_number_new =
8080 getModifiedActionNumber(action_arg_number_old,
8081 action_mode, action_arg_number,
8082 action_arg_number_min, action_arg_number_max);
8084 int trigger_player_bits =
8085 (change->actual_trigger_player >= EL_PLAYER_1 &&
8086 change->actual_trigger_player <= EL_PLAYER_4 ?
8087 (1 << (change->actual_trigger_player - EL_PLAYER_1)) :
8090 int action_arg_player_bits =
8091 (action_arg >= CA_ARG_PLAYER_1 &&
8092 action_arg <= CA_ARG_PLAYER_4 ? action_arg - CA_ARG_PLAYER :
8093 action_arg == CA_ARG_PLAYER_TRIGGER ? trigger_player_bits :
8096 /* ---------- execute action -------------------------------------------- */
8105 /* ---------- level actions ------------------------------------------- */
8107 case CA_RESTART_LEVEL:
8109 game.restart_level = TRUE;
8114 case CA_SHOW_ENVELOPE:
8116 int element = getSpecialActionElement(action_arg_element,
8117 action_arg_number, EL_ENVELOPE_1);
8119 if (IS_ENVELOPE(element))
8120 local_player->show_envelope = element;
8125 case CA_SET_LEVEL_TIME:
8127 if (level.time > 0) /* only modify limited time value */
8129 TimeLeft = action_arg_number_new;
8131 DrawGameValue_Time(TimeLeft);
8133 if (!TimeLeft && setup.time_limit)
8134 for (i = 0; i < MAX_PLAYERS; i++)
8135 KillPlayer(&stored_player[i]);
8141 case CA_SET_LEVEL_SCORE:
8143 local_player->score = action_arg_number_new;
8145 DrawGameValue_Score(local_player->score);
8150 case CA_SET_LEVEL_GEMS:
8152 local_player->gems_still_needed = action_arg_number_new;
8154 DrawGameValue_Emeralds(local_player->gems_still_needed);
8159 #if !USE_PLAYER_GRAVITY
8160 case CA_SET_LEVEL_GRAVITY:
8162 game.gravity = (action_arg == CA_ARG_GRAVITY_OFF ? FALSE :
8163 action_arg == CA_ARG_GRAVITY_ON ? TRUE :
8164 action_arg == CA_ARG_GRAVITY_TOGGLE ? !game.gravity :
8170 case CA_SET_LEVEL_WIND:
8172 game.wind_direction = action_arg_direction;
8177 /* ---------- player actions ------------------------------------------ */
8179 case CA_MOVE_PLAYER:
8181 /* automatically move to the next field in specified direction */
8182 for (i = 0; i < MAX_PLAYERS; i++)
8183 if (trigger_player_bits & (1 << i))
8184 stored_player[i].programmed_action = action_arg_direction;
8189 case CA_EXIT_PLAYER:
8191 for (i = 0; i < MAX_PLAYERS; i++)
8192 if (action_arg_player_bits & (1 << i))
8193 stored_player[i].LevelSolved = stored_player[i].GameOver = TRUE;
8198 case CA_KILL_PLAYER:
8200 for (i = 0; i < MAX_PLAYERS; i++)
8201 if (action_arg_player_bits & (1 << i))
8202 KillPlayer(&stored_player[i]);
8207 case CA_SET_PLAYER_KEYS:
8209 int key_state = (action_mode == CA_MODE_ADD ? TRUE : FALSE);
8210 int element = getSpecialActionElement(action_arg_element,
8211 action_arg_number, EL_KEY_1);
8213 if (IS_KEY(element))
8215 for (i = 0; i < MAX_PLAYERS; i++)
8217 if (trigger_player_bits & (1 << i))
8219 stored_player[i].key[KEY_NR(element)] = key_state;
8222 DrawGameDoorValues();
8224 DrawGameValue_Keys(stored_player[i].key);
8227 redraw_mask |= REDRAW_DOOR_1;
8235 case CA_SET_PLAYER_SPEED:
8237 for (i = 0; i < MAX_PLAYERS; i++)
8239 if (trigger_player_bits & (1 << i))
8241 int move_stepsize = TILEX / stored_player[i].move_delay_value;
8243 if (action_arg == CA_ARG_SPEED_FASTER &&
8244 stored_player[i].cannot_move)
8246 action_arg_number = STEPSIZE_VERY_SLOW;
8248 else if (action_arg == CA_ARG_SPEED_SLOWER ||
8249 action_arg == CA_ARG_SPEED_FASTER)
8251 action_arg_number = 2;
8252 action_mode = (action_arg == CA_ARG_SPEED_SLOWER ? CA_MODE_DIVIDE :
8255 else if (action_arg == CA_ARG_NUMBER_RESET)
8257 action_arg_number = level.initial_player_stepsize[i];
8261 getModifiedActionNumber(move_stepsize,
8264 action_arg_number_min,
8265 action_arg_number_max);
8268 SetPlayerMoveSpeed(&stored_player[i], move_stepsize, FALSE);
8270 /* make sure that value is power of 2 */
8271 move_stepsize = (1 << log_2(move_stepsize));
8273 /* do no immediately change -- the player might just be moving */
8274 stored_player[i].move_delay_value_next = TILEX / move_stepsize;
8276 stored_player[i].cannot_move =
8277 (action_arg == CA_ARG_SPEED_NOT_MOVING ? TRUE : FALSE);
8285 case CA_SET_PLAYER_SHIELD:
8287 for (i = 0; i < MAX_PLAYERS; i++)
8289 if (trigger_player_bits & (1 << i))
8291 if (action_arg == CA_ARG_SHIELD_OFF)
8293 stored_player[i].shield_normal_time_left = 0;
8294 stored_player[i].shield_deadly_time_left = 0;
8296 else if (action_arg == CA_ARG_SHIELD_NORMAL)
8298 stored_player[i].shield_normal_time_left = 999999;
8300 else if (action_arg == CA_ARG_SHIELD_DEADLY)
8302 stored_player[i].shield_normal_time_left = 999999;
8303 stored_player[i].shield_deadly_time_left = 999999;
8311 #if USE_PLAYER_GRAVITY
8312 case CA_SET_PLAYER_GRAVITY:
8314 for (i = 0; i < MAX_PLAYERS; i++)
8316 if (trigger_player_bits & (1 << i))
8318 stored_player[i].gravity =
8319 (action_arg == CA_ARG_GRAVITY_OFF ? FALSE :
8320 action_arg == CA_ARG_GRAVITY_ON ? TRUE :
8321 action_arg == CA_ARG_GRAVITY_TOGGLE ? !stored_player[i].gravity :
8322 stored_player[i].gravity);
8330 case CA_SET_PLAYER_ARTWORK:
8332 for (i = 0; i < MAX_PLAYERS; i++)
8334 if (trigger_player_bits & (1 << i))
8336 int artwork_element = action_arg_element;
8338 if (action_arg == CA_ARG_ELEMENT_RESET)
8340 (level.use_artwork_element[i] ? level.artwork_element[i] :
8341 stored_player[i].element_nr);
8343 stored_player[i].artwork_element = artwork_element;
8345 SetPlayerWaiting(&stored_player[i], FALSE);
8347 /* set number of special actions for bored and sleeping animation */
8348 stored_player[i].num_special_action_bored =
8349 get_num_special_action(artwork_element,
8350 ACTION_BORING_1, ACTION_BORING_LAST);
8351 stored_player[i].num_special_action_sleeping =
8352 get_num_special_action(artwork_element,
8353 ACTION_SLEEPING_1, ACTION_SLEEPING_LAST);
8360 /* ---------- CE actions ---------------------------------------------- */
8362 case CA_SET_CE_VALUE:
8364 #if USE_NEW_CUSTOM_VALUE
8365 int last_ce_value = CustomValue[x][y];
8367 CustomValue[x][y] = action_arg_number_new;
8370 printf("::: CE value == %d\n", CustomValue[x][y]);
8373 if (CustomValue[x][y] != last_ce_value)
8375 CheckElementChange(x, y, element, EL_UNDEFINED, CE_VALUE_CHANGES);
8376 CheckTriggeredElementChange(x, y, element, CE_VALUE_CHANGES_OF_X);
8378 if (CustomValue[x][y] == 0)
8381 printf("::: CE_VALUE_GETS_ZERO\n");
8384 CheckElementChange(x, y, element, EL_UNDEFINED, CE_VALUE_GETS_ZERO);
8385 CheckTriggeredElementChange(x, y, element, CE_VALUE_GETS_ZERO_OF_X);
8388 printf("::: RESULT: %d, %d\n", Feld[x][y], ChangePage[x][y]);
8398 case CA_SET_CE_SCORE:
8400 #if USE_NEW_CUSTOM_VALUE
8401 int last_ce_score = ei->collect_score;
8403 ei->collect_score = action_arg_number_new;
8406 printf("::: CE score == %d\n", ei->collect_score);
8409 if (ei->collect_score != last_ce_score)
8411 CheckElementChange(x, y, element, EL_UNDEFINED, CE_SCORE_CHANGES);
8412 CheckTriggeredElementChange(x, y, element, CE_SCORE_CHANGES_OF_X);
8414 if (ei->collect_score == 0)
8417 printf("::: CE_SCORE_GETS_ZERO\n");
8420 CheckElementChange(x, y, element, EL_UNDEFINED, CE_SCORE_GETS_ZERO);
8421 CheckTriggeredElementChange(x, y, element, CE_SCORE_GETS_ZERO_OF_X);
8424 printf("::: RESULT: %d, %d\n", Feld[x][y], ChangePage[x][y]);
8434 /* ---------- engine actions ------------------------------------------ */
8436 case CA_SET_ENGINE_SCAN_MODE:
8438 InitPlayfieldScanMode(action_arg);
8448 static void CreateFieldExt(int x, int y, int element, boolean is_change)
8450 int old_element = Feld[x][y];
8451 int new_element = get_element_from_group_element(element);
8452 int previous_move_direction = MovDir[x][y];
8453 #if USE_NEW_CUSTOM_VALUE
8454 int last_ce_value = CustomValue[x][y];
8456 boolean new_element_is_player = ELEM_IS_PLAYER(new_element);
8457 boolean add_player_onto_element = (new_element_is_player &&
8458 new_element != EL_SOKOBAN_FIELD_PLAYER &&
8459 IS_WALKABLE(old_element));
8462 /* check if element under the player changes from accessible to unaccessible
8463 (needed for special case of dropping element which then changes) */
8464 if (IS_PLAYER(x, y) && !PLAYER_EXPLOSION_PROTECTED(x, y) &&
8465 IS_ACCESSIBLE(old_element) && !IS_ACCESSIBLE(new_element))
8473 if (!add_player_onto_element)
8475 if (IS_MOVING(x, y) || IS_BLOCKED(x, y))
8476 RemoveMovingField(x, y);
8480 Feld[x][y] = new_element;
8482 #if !USE_GFX_RESET_GFX_ANIMATION
8483 ResetGfxAnimation(x, y);
8484 ResetRandomAnimationValue(x, y);
8487 if (element_info[new_element].move_direction_initial == MV_START_PREVIOUS)
8488 MovDir[x][y] = previous_move_direction;
8490 #if USE_NEW_CUSTOM_VALUE
8491 if (element_info[new_element].use_last_ce_value)
8492 CustomValue[x][y] = last_ce_value;
8495 InitField_WithBug1(x, y, FALSE);
8497 new_element = Feld[x][y]; /* element may have changed */
8499 #if USE_GFX_RESET_GFX_ANIMATION
8500 ResetGfxAnimation(x, y);
8501 ResetRandomAnimationValue(x, y);
8504 DrawLevelField(x, y);
8506 if (GFX_CRUMBLED(new_element))
8507 DrawLevelFieldCrumbledSandNeighbours(x, y);
8511 /* check if element under the player changes from accessible to unaccessible
8512 (needed for special case of dropping element which then changes) */
8513 /* (must be checked after creating new element for walkable group elements) */
8514 if (IS_PLAYER(x, y) && !PLAYER_EXPLOSION_PROTECTED(x, y) &&
8515 IS_ACCESSIBLE(old_element) && !IS_ACCESSIBLE(new_element))
8523 /* "ChangeCount" not set yet to allow "entered by player" change one time */
8524 if (new_element_is_player)
8525 RelocatePlayer(x, y, new_element);
8528 ChangeCount[x][y]++; /* count number of changes in the same frame */
8530 TestIfBadThingTouchesPlayer(x, y);
8531 TestIfPlayerTouchesCustomElement(x, y);
8532 TestIfElementTouchesCustomElement(x, y);
8535 static void CreateField(int x, int y, int element)
8537 CreateFieldExt(x, y, element, FALSE);
8540 static void CreateElementFromChange(int x, int y, int element)
8542 element = GET_VALID_RUNTIME_ELEMENT(element);
8544 #if USE_STOP_CHANGED_ELEMENTS
8545 if (game.engine_version >= VERSION_IDENT(3,2,0,7))
8547 int old_element = Feld[x][y];
8549 /* prevent changed element from moving in same engine frame
8550 unless both old and new element can either fall or move */
8551 if ((!CAN_FALL(old_element) || !CAN_FALL(element)) &&
8552 (!CAN_MOVE(old_element) || !CAN_MOVE(element)))
8557 CreateFieldExt(x, y, element, TRUE);
8560 static boolean ChangeElement(int x, int y, int element, int page)
8562 struct ElementInfo *ei = &element_info[element];
8563 struct ElementChangeInfo *change = &ei->change_page[page];
8564 int ce_value = CustomValue[x][y];
8565 int ce_score = ei->collect_score;
8567 int old_element = Feld[x][y];
8569 /* always use default change event to prevent running into a loop */
8570 if (ChangeEvent[x][y] == -1)
8571 ChangeEvent[x][y] = CE_DELAY;
8573 if (ChangeEvent[x][y] == CE_DELAY)
8575 /* reset actual trigger element, trigger player and action element */
8576 change->actual_trigger_element = EL_EMPTY;
8577 change->actual_trigger_player = EL_PLAYER_1;
8578 change->actual_trigger_side = CH_SIDE_NONE;
8579 change->actual_trigger_ce_value = 0;
8580 change->actual_trigger_ce_score = 0;
8583 /* do not change elements more than a specified maximum number of changes */
8584 if (ChangeCount[x][y] >= game.max_num_changes_per_frame)
8587 ChangeCount[x][y]++; /* count number of changes in the same frame */
8589 if (change->explode)
8596 if (change->use_target_content)
8598 boolean complete_replace = TRUE;
8599 boolean can_replace[3][3];
8602 for (yy = 0; yy < 3; yy++) for (xx = 0; xx < 3 ; xx++)
8605 boolean is_walkable;
8606 boolean is_diggable;
8607 boolean is_collectible;
8608 boolean is_removable;
8609 boolean is_destructible;
8610 int ex = x + xx - 1;
8611 int ey = y + yy - 1;
8612 int content_element = change->target_content.e[xx][yy];
8615 can_replace[xx][yy] = TRUE;
8617 if (ex == x && ey == y) /* do not check changing element itself */
8620 if (content_element == EL_EMPTY_SPACE)
8622 can_replace[xx][yy] = FALSE; /* do not replace border with space */
8627 if (!IN_LEV_FIELD(ex, ey))
8629 can_replace[xx][yy] = FALSE;
8630 complete_replace = FALSE;
8637 if (IS_MOVING(ex, ey) || IS_BLOCKED(ex, ey))
8638 e = MovingOrBlocked2Element(ex, ey);
8640 is_empty = (IS_FREE(ex, ey) ||
8641 (IS_FREE_OR_PLAYER(ex, ey) && IS_WALKABLE(content_element)));
8643 is_walkable = (is_empty || IS_WALKABLE(e));
8644 is_diggable = (is_empty || IS_DIGGABLE(e));
8645 is_collectible = (is_empty || IS_COLLECTIBLE(e));
8646 is_destructible = (is_empty || !IS_INDESTRUCTIBLE(e));
8647 is_removable = (is_diggable || is_collectible);
8649 can_replace[xx][yy] =
8650 (((change->replace_when == CP_WHEN_EMPTY && is_empty) ||
8651 (change->replace_when == CP_WHEN_WALKABLE && is_walkable) ||
8652 (change->replace_when == CP_WHEN_DIGGABLE && is_diggable) ||
8653 (change->replace_when == CP_WHEN_COLLECTIBLE && is_collectible) ||
8654 (change->replace_when == CP_WHEN_REMOVABLE && is_removable) ||
8655 (change->replace_when == CP_WHEN_DESTRUCTIBLE && is_destructible)) &&
8656 !(IS_PLAYER(ex, ey) && ELEM_IS_PLAYER(content_element)));
8658 if (!can_replace[xx][yy])
8659 complete_replace = FALSE;
8662 if (!change->only_if_complete || complete_replace)
8664 boolean something_has_changed = FALSE;
8666 if (change->only_if_complete && change->use_random_replace &&
8667 RND(100) < change->random_percentage)
8670 for (yy = 0; yy < 3; yy++) for (xx = 0; xx < 3 ; xx++)
8672 int ex = x + xx - 1;
8673 int ey = y + yy - 1;
8674 int content_element;
8676 if (can_replace[xx][yy] && (!change->use_random_replace ||
8677 RND(100) < change->random_percentage))
8679 if (IS_MOVING(ex, ey) || IS_BLOCKED(ex, ey))
8680 RemoveMovingField(ex, ey);
8682 ChangeEvent[ex][ey] = ChangeEvent[x][y];
8684 content_element = change->target_content.e[xx][yy];
8685 target_element = GET_TARGET_ELEMENT(content_element, change,
8686 ce_value, ce_score);
8688 CreateElementFromChange(ex, ey, target_element);
8690 something_has_changed = TRUE;
8692 /* for symmetry reasons, freeze newly created border elements */
8693 if (ex != x || ey != y)
8694 Stop[ex][ey] = TRUE; /* no more moving in this frame */
8698 if (something_has_changed)
8700 PlayLevelSoundElementAction(x, y, element, ACTION_CHANGING);
8701 PlayLevelSoundElementAction(x, y, element, ACTION_PAGE_1 + page);
8707 target_element = GET_TARGET_ELEMENT(change->target_element, change,
8708 ce_value, ce_score);
8710 if (element == EL_DIAGONAL_GROWING ||
8711 element == EL_DIAGONAL_SHRINKING)
8713 target_element = Store[x][y];
8715 Store[x][y] = EL_EMPTY;
8718 CreateElementFromChange(x, y, target_element);
8720 PlayLevelSoundElementAction(x, y, element, ACTION_CHANGING);
8721 PlayLevelSoundElementAction(x, y, element, ACTION_PAGE_1 + page);
8724 /* this uses direct change before indirect change */
8725 CheckTriggeredElementChangeByPage(x, y, old_element, CE_CHANGE_OF_X, page);
8730 #if USE_NEW_DELAYED_ACTION
8732 static void HandleElementChange(int x, int y, int page)
8734 int element = MovingOrBlocked2Element(x, y);
8735 struct ElementInfo *ei = &element_info[element];
8736 struct ElementChangeInfo *change = &ei->change_page[page];
8739 if (!CAN_CHANGE_OR_HAS_ACTION(element) &&
8740 !CAN_CHANGE_OR_HAS_ACTION(Back[x][y]))
8743 printf("HandleElementChange(): %d,%d: element = %d ('%s')\n",
8744 x, y, element, element_info[element].token_name);
8745 printf("HandleElementChange(): This should never happen!\n");
8750 /* this can happen with classic bombs on walkable, changing elements */
8751 if (!CAN_CHANGE_OR_HAS_ACTION(element))
8754 if (!CAN_CHANGE(Back[x][y])) /* prevent permanent repetition */
8755 ChangeDelay[x][y] = 0;
8761 if (ChangeDelay[x][y] == 0) /* initialize element change */
8763 ChangeDelay[x][y] = GET_CHANGE_DELAY(change) + 1;
8765 if (change->can_change)
8767 ResetGfxAnimation(x, y);
8768 ResetRandomAnimationValue(x, y);
8770 if (change->pre_change_function)
8771 change->pre_change_function(x, y);
8775 ChangeDelay[x][y]--;
8777 if (ChangeDelay[x][y] != 0) /* continue element change */
8779 if (change->can_change)
8781 int graphic = el_act_dir2img(element, GfxAction[x][y], GfxDir[x][y]);
8783 if (IS_ANIMATED(graphic))
8784 DrawLevelGraphicAnimationIfNeeded(x, y, graphic);
8786 if (change->change_function)
8787 change->change_function(x, y);
8790 else /* finish element change */
8792 if (ChangePage[x][y] != -1) /* remember page from delayed change */
8794 page = ChangePage[x][y];
8795 ChangePage[x][y] = -1;
8797 change = &ei->change_page[page];
8800 if (IS_MOVING(x, y)) /* never change a running system ;-) */
8802 ChangeDelay[x][y] = 1; /* try change after next move step */
8803 ChangePage[x][y] = page; /* remember page to use for change */
8808 if (change->can_change)
8810 if (ChangeElement(x, y, element, page))
8812 if (change->post_change_function)
8813 change->post_change_function(x, y);
8817 if (change->has_action)
8818 ExecuteCustomElementAction(x, y, element, page);
8824 static void HandleElementChange(int x, int y, int page)
8826 int element = MovingOrBlocked2Element(x, y);
8827 struct ElementInfo *ei = &element_info[element];
8828 struct ElementChangeInfo *change = &ei->change_page[page];
8831 if (!CAN_CHANGE(element) && !CAN_CHANGE(Back[x][y]))
8834 printf("HandleElementChange(): %d,%d: element = %d ('%s')\n",
8835 x, y, element, element_info[element].token_name);
8836 printf("HandleElementChange(): This should never happen!\n");
8841 /* this can happen with classic bombs on walkable, changing elements */
8842 if (!CAN_CHANGE(element))
8845 if (!CAN_CHANGE(Back[x][y])) /* prevent permanent repetition */
8846 ChangeDelay[x][y] = 0;
8852 if (ChangeDelay[x][y] == 0) /* initialize element change */
8854 ChangeDelay[x][y] = GET_CHANGE_DELAY(change) + 1;
8856 ResetGfxAnimation(x, y);
8857 ResetRandomAnimationValue(x, y);
8859 if (change->pre_change_function)
8860 change->pre_change_function(x, y);
8863 ChangeDelay[x][y]--;
8865 if (ChangeDelay[x][y] != 0) /* continue element change */
8867 int graphic = el_act_dir2img(element, GfxAction[x][y], GfxDir[x][y]);
8869 if (IS_ANIMATED(graphic))
8870 DrawLevelGraphicAnimationIfNeeded(x, y, graphic);
8872 if (change->change_function)
8873 change->change_function(x, y);
8875 else /* finish element change */
8877 if (ChangePage[x][y] != -1) /* remember page from delayed change */
8879 page = ChangePage[x][y];
8880 ChangePage[x][y] = -1;
8882 change = &ei->change_page[page];
8885 if (IS_MOVING(x, y)) /* never change a running system ;-) */
8887 ChangeDelay[x][y] = 1; /* try change after next move step */
8888 ChangePage[x][y] = page; /* remember page to use for change */
8893 if (ChangeElement(x, y, element, page))
8895 if (change->post_change_function)
8896 change->post_change_function(x, y);
8903 static boolean CheckTriggeredElementChangeExt(int trigger_x, int trigger_y,
8904 int trigger_element,
8910 boolean change_done_any = FALSE;
8911 int trigger_page_bits = (trigger_page < 0 ? CH_PAGE_ANY : 1 << trigger_page);
8914 if (!(trigger_events[trigger_element][trigger_event]))
8917 for (i = 0; i < NUM_CUSTOM_ELEMENTS; i++)
8919 int element = EL_CUSTOM_START + i;
8920 boolean change_done = FALSE;
8923 if (!CAN_CHANGE_OR_HAS_ACTION(element) ||
8924 !HAS_ANY_CHANGE_EVENT(element, trigger_event))
8927 for (p = 0; p < element_info[element].num_change_pages; p++)
8929 struct ElementChangeInfo *change = &element_info[element].change_page[p];
8931 if (change->can_change_or_has_action &&
8932 change->has_event[trigger_event] &&
8933 change->trigger_side & trigger_side &&
8934 change->trigger_player & trigger_player &&
8935 change->trigger_page & trigger_page_bits &&
8936 IS_EQUAL_OR_IN_GROUP(trigger_element, change->trigger_element))
8938 change->actual_trigger_element = trigger_element;
8939 change->actual_trigger_player = EL_PLAYER_1 + log_2(trigger_player);
8940 change->actual_trigger_side = trigger_side;
8941 change->actual_trigger_ce_value = CustomValue[trigger_x][trigger_y];
8942 change->actual_trigger_ce_score = GET_CE_SCORE(trigger_element);
8944 if ((change->can_change && !change_done) || change->has_action)
8949 SCAN_PLAYFIELD(x, y)
8951 for (y = 0; y < lev_fieldy; y++) for (x = 0; x < lev_fieldx; x++)
8954 if (Feld[x][y] == element)
8956 if (change->can_change && !change_done)
8958 ChangeDelay[x][y] = 1;
8959 ChangeEvent[x][y] = trigger_event;
8961 HandleElementChange(x, y, p);
8963 #if USE_NEW_DELAYED_ACTION
8964 else if (change->has_action)
8966 ExecuteCustomElementAction(x, y, element, p);
8967 PlayLevelSoundElementAction(x, y, element, ACTION_PAGE_1 + p);
8970 if (change->has_action)
8972 ExecuteCustomElementAction(x, y, element, p);
8973 PlayLevelSoundElementAction(x, y, element, ACTION_PAGE_1 + p);
8979 if (change->can_change)
8982 change_done_any = TRUE;
8989 return change_done_any;
8992 static boolean CheckElementChangeExt(int x, int y,
8994 int trigger_element,
8999 boolean change_done = FALSE;
9002 if (!CAN_CHANGE_OR_HAS_ACTION(element) ||
9003 !HAS_ANY_CHANGE_EVENT(element, trigger_event))
9006 if (Feld[x][y] == EL_BLOCKED)
9008 Blocked2Moving(x, y, &x, &y);
9009 element = Feld[x][y];
9013 /* check if element has already changed */
9014 if (Feld[x][y] != element)
9017 /* check if element has already changed or is about to change after moving */
9018 if ((game.engine_version < VERSION_IDENT(3,2,0,7) &&
9019 Feld[x][y] != element) ||
9021 (game.engine_version >= VERSION_IDENT(3,2,0,7) &&
9022 (ChangeCount[x][y] >= game.max_num_changes_per_frame ||
9023 ChangePage[x][y] != -1)))
9027 for (p = 0; p < element_info[element].num_change_pages; p++)
9029 struct ElementChangeInfo *change = &element_info[element].change_page[p];
9031 boolean check_trigger_element =
9032 (trigger_event == CE_TOUCHING_X ||
9033 trigger_event == CE_HITTING_X ||
9034 trigger_event == CE_HIT_BY_X);
9036 if (change->can_change_or_has_action &&
9037 change->has_event[trigger_event] &&
9038 change->trigger_side & trigger_side &&
9039 change->trigger_player & trigger_player &&
9040 (!check_trigger_element ||
9041 IS_EQUAL_OR_IN_GROUP(trigger_element, change->trigger_element)))
9043 change->actual_trigger_element = trigger_element;
9044 change->actual_trigger_player = EL_PLAYER_1 + log_2(trigger_player);
9045 change->actual_trigger_side = trigger_side;
9046 change->actual_trigger_ce_value = CustomValue[x][y];
9047 change->actual_trigger_ce_score = GET_CE_SCORE(trigger_element);
9049 /* special case: trigger element not at (x,y) position for some events */
9050 if (check_trigger_element)
9062 { 0, 0 }, { 0, 0 }, { 0, 0 },
9066 int xx = x + move_xy[MV_DIR_OPPOSITE(trigger_side)].dx;
9067 int yy = y + move_xy[MV_DIR_OPPOSITE(trigger_side)].dy;
9069 change->actual_trigger_ce_value = CustomValue[xx][yy];
9070 change->actual_trigger_ce_score = GET_CE_SCORE(trigger_element);
9073 if (change->can_change && !change_done)
9075 ChangeDelay[x][y] = 1;
9076 ChangeEvent[x][y] = trigger_event;
9078 HandleElementChange(x, y, p);
9082 #if USE_NEW_DELAYED_ACTION
9083 else if (change->has_action)
9085 ExecuteCustomElementAction(x, y, element, p);
9086 PlayLevelSoundElementAction(x, y, element, ACTION_PAGE_1 + p);
9089 if (change->has_action)
9091 ExecuteCustomElementAction(x, y, element, p);
9092 PlayLevelSoundElementAction(x, y, element, ACTION_PAGE_1 + p);
9101 static void PlayPlayerSound(struct PlayerInfo *player)
9103 int jx = player->jx, jy = player->jy;
9104 int sound_element = player->artwork_element;
9105 int last_action = player->last_action_waiting;
9106 int action = player->action_waiting;
9108 if (player->is_waiting)
9110 if (action != last_action)
9111 PlayLevelSoundElementAction(jx, jy, sound_element, action);
9113 PlayLevelSoundElementActionIfLoop(jx, jy, sound_element, action);
9117 if (action != last_action)
9118 StopSound(element_info[sound_element].sound[last_action]);
9120 if (last_action == ACTION_SLEEPING)
9121 PlayLevelSoundElementAction(jx, jy, sound_element, ACTION_AWAKENING);
9125 static void PlayAllPlayersSound()
9129 for (i = 0; i < MAX_PLAYERS; i++)
9130 if (stored_player[i].active)
9131 PlayPlayerSound(&stored_player[i]);
9134 static void SetPlayerWaiting(struct PlayerInfo *player, boolean is_waiting)
9136 boolean last_waiting = player->is_waiting;
9137 int move_dir = player->MovDir;
9139 player->dir_waiting = move_dir;
9140 player->last_action_waiting = player->action_waiting;
9144 if (!last_waiting) /* not waiting -> waiting */
9146 player->is_waiting = TRUE;
9148 player->frame_counter_bored =
9150 game.player_boring_delay_fixed +
9151 SimpleRND(game.player_boring_delay_random);
9152 player->frame_counter_sleeping =
9154 game.player_sleeping_delay_fixed +
9155 SimpleRND(game.player_sleeping_delay_random);
9158 InitPlayerGfxAnimation(player, ACTION_WAITING, move_dir);
9160 InitPlayerGfxAnimation(player, ACTION_WAITING, player->MovDir);
9164 if (game.player_sleeping_delay_fixed +
9165 game.player_sleeping_delay_random > 0 &&
9166 player->anim_delay_counter == 0 &&
9167 player->post_delay_counter == 0 &&
9168 FrameCounter >= player->frame_counter_sleeping)
9169 player->is_sleeping = TRUE;
9170 else if (game.player_boring_delay_fixed +
9171 game.player_boring_delay_random > 0 &&
9172 FrameCounter >= player->frame_counter_bored)
9173 player->is_bored = TRUE;
9175 player->action_waiting = (player->is_sleeping ? ACTION_SLEEPING :
9176 player->is_bored ? ACTION_BORING :
9180 if (player->is_sleeping && player->use_murphy)
9182 /* special case for sleeping Murphy when leaning against non-free tile */
9184 if (!IN_LEV_FIELD(player->jx - 1, player->jy) ||
9185 (Feld[player->jx - 1][player->jy] != EL_EMPTY &&
9186 !IS_MOVING(player->jx - 1, player->jy)))
9188 else if (!IN_LEV_FIELD(player->jx + 1, player->jy) ||
9189 (Feld[player->jx + 1][player->jy] != EL_EMPTY &&
9190 !IS_MOVING(player->jx + 1, player->jy)))
9191 move_dir = MV_RIGHT;
9193 player->is_sleeping = FALSE;
9195 player->dir_waiting = move_dir;
9199 if (player->is_sleeping)
9201 if (player->num_special_action_sleeping > 0)
9203 if (player->anim_delay_counter == 0 && player->post_delay_counter == 0)
9205 int last_special_action = player->special_action_sleeping;
9206 int num_special_action = player->num_special_action_sleeping;
9207 int special_action =
9208 (last_special_action == ACTION_DEFAULT ? ACTION_SLEEPING_1 :
9209 last_special_action == ACTION_SLEEPING ? ACTION_SLEEPING :
9210 last_special_action < ACTION_SLEEPING_1 + num_special_action - 1 ?
9211 last_special_action + 1 : ACTION_SLEEPING);
9212 int special_graphic =
9213 el_act_dir2img(player->artwork_element, special_action, move_dir);
9215 player->anim_delay_counter =
9216 graphic_info[special_graphic].anim_delay_fixed +
9217 SimpleRND(graphic_info[special_graphic].anim_delay_random);
9218 player->post_delay_counter =
9219 graphic_info[special_graphic].post_delay_fixed +
9220 SimpleRND(graphic_info[special_graphic].post_delay_random);
9222 player->special_action_sleeping = special_action;
9225 if (player->anim_delay_counter > 0)
9227 player->action_waiting = player->special_action_sleeping;
9228 player->anim_delay_counter--;
9230 else if (player->post_delay_counter > 0)
9232 player->post_delay_counter--;
9236 else if (player->is_bored)
9238 if (player->num_special_action_bored > 0)
9240 if (player->anim_delay_counter == 0 && player->post_delay_counter == 0)
9242 int special_action =
9243 ACTION_BORING_1 + SimpleRND(player->num_special_action_bored);
9244 int special_graphic =
9245 el_act_dir2img(player->artwork_element, special_action, move_dir);
9247 player->anim_delay_counter =
9248 graphic_info[special_graphic].anim_delay_fixed +
9249 SimpleRND(graphic_info[special_graphic].anim_delay_random);
9250 player->post_delay_counter =
9251 graphic_info[special_graphic].post_delay_fixed +
9252 SimpleRND(graphic_info[special_graphic].post_delay_random);
9254 player->special_action_bored = special_action;
9257 if (player->anim_delay_counter > 0)
9259 player->action_waiting = player->special_action_bored;
9260 player->anim_delay_counter--;
9262 else if (player->post_delay_counter > 0)
9264 player->post_delay_counter--;
9269 else if (last_waiting) /* waiting -> not waiting */
9271 player->is_waiting = FALSE;
9272 player->is_bored = FALSE;
9273 player->is_sleeping = FALSE;
9275 player->frame_counter_bored = -1;
9276 player->frame_counter_sleeping = -1;
9278 player->anim_delay_counter = 0;
9279 player->post_delay_counter = 0;
9281 player->dir_waiting = player->MovDir;
9282 player->action_waiting = ACTION_DEFAULT;
9284 player->special_action_bored = ACTION_DEFAULT;
9285 player->special_action_sleeping = ACTION_DEFAULT;
9289 static byte PlayerActions(struct PlayerInfo *player, byte player_action)
9291 boolean moved = FALSE, snapped = FALSE, dropped = FALSE;
9292 int left = player_action & JOY_LEFT;
9293 int right = player_action & JOY_RIGHT;
9294 int up = player_action & JOY_UP;
9295 int down = player_action & JOY_DOWN;
9296 int button1 = player_action & JOY_BUTTON_1;
9297 int button2 = player_action & JOY_BUTTON_2;
9298 int dx = (left ? -1 : right ? 1 : 0);
9299 int dy = (up ? -1 : down ? 1 : 0);
9301 if (!player->active || tape.pausing)
9307 snapped = SnapField(player, dx, dy);
9311 dropped = DropElement(player);
9313 moved = MovePlayer(player, dx, dy);
9316 if (tape.single_step && tape.recording && !tape.pausing)
9318 if (button1 || (dropped && !moved))
9320 TapeTogglePause(TAPE_TOGGLE_AUTOMATIC);
9321 SnapField(player, 0, 0); /* stop snapping */
9325 SetPlayerWaiting(player, FALSE);
9327 return player_action;
9331 /* no actions for this player (no input at player's configured device) */
9333 DigField(player, 0, 0, 0, 0, 0, 0, DF_NO_PUSH);
9334 SnapField(player, 0, 0);
9335 CheckGravityMovementWhenNotMoving(player);
9337 if (player->MovPos == 0)
9338 SetPlayerWaiting(player, TRUE);
9340 if (player->MovPos == 0) /* needed for tape.playing */
9341 player->is_moving = FALSE;
9343 player->is_dropping = FALSE;
9344 player->is_dropping_pressed = FALSE;
9345 player->drop_pressed_delay = 0;
9351 static void CheckLevelTime()
9355 if (level.game_engine_type == GAME_ENGINE_TYPE_EM)
9357 if (level.native_em_level->lev->home == 0) /* all players at home */
9359 local_player->LevelSolved = TRUE;
9360 AllPlayersGone = TRUE;
9362 level.native_em_level->lev->home = -1;
9365 if (level.native_em_level->ply[0]->alive == 0 &&
9366 level.native_em_level->ply[1]->alive == 0 &&
9367 level.native_em_level->ply[2]->alive == 0 &&
9368 level.native_em_level->ply[3]->alive == 0) /* all dead */
9369 AllPlayersGone = TRUE;
9372 if (TimeFrames >= FRAMES_PER_SECOND)
9377 for (i = 0; i < MAX_PLAYERS; i++)
9379 struct PlayerInfo *player = &stored_player[i];
9381 if (SHIELD_ON(player))
9383 player->shield_normal_time_left--;
9385 if (player->shield_deadly_time_left > 0)
9386 player->shield_deadly_time_left--;
9390 if (!level.use_step_counter)
9398 if (TimeLeft <= 10 && setup.time_limit)
9399 PlaySoundStereo(SND_GAME_RUNNING_OUT_OF_TIME, SOUND_MIDDLE);
9401 DrawGameValue_Time(TimeLeft);
9403 if (!TimeLeft && setup.time_limit)
9405 if (level.game_engine_type == GAME_ENGINE_TYPE_EM)
9406 level.native_em_level->lev->killed_out_of_time = TRUE;
9408 for (i = 0; i < MAX_PLAYERS; i++)
9409 KillPlayer(&stored_player[i]);
9412 else if (level.time == 0 && !AllPlayersGone) /* level w/o time limit */
9413 DrawGameValue_Time(TimePlayed);
9415 level.native_em_level->lev->time =
9416 (level.time == 0 ? TimePlayed : TimeLeft);
9419 if (tape.recording || tape.playing)
9420 DrawVideoDisplay(VIDEO_STATE_TIME_ON, TapeTime);
9424 void AdvanceFrameAndPlayerCounters(int player_nr)
9429 Error(ERR_NETWORK_CLIENT, "advancing frame counter from %d to %d",
9430 FrameCounter, FrameCounter + 1);
9433 /* advance frame counters (global frame counter and time frame counter) */
9437 /* advance player counters (counters for move delay, move animation etc.) */
9438 for (i = 0; i < MAX_PLAYERS; i++)
9440 boolean advance_player_counters = (player_nr == -1 || player_nr == i);
9441 int move_delay_value = stored_player[i].move_delay_value;
9442 int move_frames = MOVE_DELAY_NORMAL_SPEED / move_delay_value;
9444 if (!advance_player_counters) /* not all players may be affected */
9447 #if USE_NEW_PLAYER_ANIM
9448 if (move_frames == 0) /* less than one move per game frame */
9450 int stepsize = TILEX / move_delay_value;
9451 int delay = move_delay_value / MOVE_DELAY_NORMAL_SPEED;
9452 int count = (stored_player[i].is_moving ?
9453 ABS(stored_player[i].MovPos) / stepsize : FrameCounter);
9455 if (count % delay == 0)
9460 stored_player[i].Frame += move_frames;
9462 if (stored_player[i].MovPos != 0)
9463 stored_player[i].StepFrame += move_frames;
9465 if (stored_player[i].move_delay > 0)
9466 stored_player[i].move_delay--;
9468 /* due to bugs in previous versions, counter must count up, not down */
9469 if (stored_player[i].push_delay != -1)
9470 stored_player[i].push_delay++;
9472 if (stored_player[i].drop_delay > 0)
9473 stored_player[i].drop_delay--;
9475 if (stored_player[i].is_dropping_pressed)
9476 stored_player[i].drop_pressed_delay++;
9480 void StartGameActions(boolean init_network_game, boolean record_tape,
9483 unsigned long new_random_seed = InitRND(random_seed);
9486 TapeStartRecording(new_random_seed);
9488 #if defined(NETWORK_AVALIABLE)
9489 if (init_network_game)
9491 SendToServer_StartPlaying();
9499 game_status = GAME_MODE_PLAYING;
9506 static unsigned long game_frame_delay = 0;
9507 unsigned long game_frame_delay_value;
9508 byte *recorded_player_action;
9509 byte summarized_player_action = 0;
9510 byte tape_action[MAX_PLAYERS];
9513 if (game.restart_level)
9514 StartGameActions(options.network, setup.autorecord, NEW_RANDOMIZE);
9516 if (level.game_engine_type == GAME_ENGINE_TYPE_EM)
9518 if (level.native_em_level->lev->home == 0) /* all players at home */
9520 local_player->LevelSolved = TRUE;
9521 AllPlayersGone = TRUE;
9523 level.native_em_level->lev->home = -1;
9526 if (level.native_em_level->ply[0]->alive == 0 &&
9527 level.native_em_level->ply[1]->alive == 0 &&
9528 level.native_em_level->ply[2]->alive == 0 &&
9529 level.native_em_level->ply[3]->alive == 0) /* all dead */
9530 AllPlayersGone = TRUE;
9533 if (local_player->LevelSolved)
9536 if (AllPlayersGone && !TAPE_IS_STOPPED(tape))
9539 if (game_status != GAME_MODE_PLAYING) /* status might have changed */
9542 game_frame_delay_value =
9543 (tape.playing && tape.fast_forward ? FfwdFrameDelay : GameFrameDelay);
9545 if (tape.playing && tape.warp_forward && !tape.pausing)
9546 game_frame_delay_value = 0;
9548 /* ---------- main game synchronization point ---------- */
9550 WaitUntilDelayReached(&game_frame_delay, game_frame_delay_value);
9552 if (network_playing && !network_player_action_received)
9554 /* try to get network player actions in time */
9556 #if defined(NETWORK_AVALIABLE)
9557 /* last chance to get network player actions without main loop delay */
9561 /* game was quit by network peer */
9562 if (game_status != GAME_MODE_PLAYING)
9565 if (!network_player_action_received)
9566 return; /* failed to get network player actions in time */
9568 /* do not yet reset "network_player_action_received" (for tape.pausing) */
9574 /* at this point we know that we really continue executing the game */
9577 network_player_action_received = FALSE;
9580 recorded_player_action = (tape.playing ? TapePlayAction() : NULL);
9582 if (tape.set_centered_player)
9584 game.centered_player_nr_next = tape.centered_player_nr_next;
9585 game.set_centered_player = TRUE;
9588 for (i = 0; i < MAX_PLAYERS; i++)
9590 summarized_player_action |= stored_player[i].action;
9592 if (!network_playing)
9593 stored_player[i].effective_action = stored_player[i].action;
9596 #if defined(NETWORK_AVALIABLE)
9597 if (network_playing)
9598 SendToServer_MovePlayer(summarized_player_action);
9601 if (!options.network && !setup.team_mode)
9602 local_player->effective_action = summarized_player_action;
9604 if (setup.team_mode && setup.input_on_focus && game.centered_player_nr != -1)
9606 for (i = 0; i < MAX_PLAYERS; i++)
9607 stored_player[i].effective_action =
9608 (i == game.centered_player_nr ? summarized_player_action : 0);
9611 if (recorded_player_action != NULL)
9612 for (i = 0; i < MAX_PLAYERS; i++)
9613 stored_player[i].effective_action = recorded_player_action[i];
9615 for (i = 0; i < MAX_PLAYERS; i++)
9617 tape_action[i] = stored_player[i].effective_action;
9619 /* (this can only happen in the R'n'D game engine) */
9620 if (tape.recording && tape_action[i] && !tape.player_participates[i])
9621 tape.player_participates[i] = TRUE; /* player just appeared from CE */
9624 /* only record actions from input devices, but not programmed actions */
9626 TapeRecordAction(tape_action);
9628 if (level.game_engine_type == GAME_ENGINE_TYPE_EM)
9630 GameActions_EM_Main();
9638 void GameActions_EM_Main()
9640 byte effective_action[MAX_PLAYERS];
9641 boolean warp_mode = (tape.playing && tape.warp_forward && !tape.pausing);
9644 for (i = 0; i < MAX_PLAYERS; i++)
9645 effective_action[i] = stored_player[i].effective_action;
9647 GameActions_EM(effective_action, warp_mode);
9651 AdvanceFrameAndPlayerCounters(-1); /* advance counters for all players */
9654 void GameActions_RND()
9656 int magic_wall_x = 0, magic_wall_y = 0;
9657 int i, x, y, element, graphic;
9659 InitPlayfieldScanModeVars();
9661 #if USE_ONE_MORE_CHANGE_PER_FRAME
9662 if (game.engine_version >= VERSION_IDENT(3,2,0,7))
9664 SCAN_PLAYFIELD(x, y)
9666 ChangeCount[x][y] = 0;
9667 ChangeEvent[x][y] = -1;
9673 if (game.set_centered_player)
9675 boolean all_players_fit_to_screen = checkIfAllPlayersFitToScreen_RND();
9677 /* switching to "all players" only possible if all players fit to screen */
9678 if (game.centered_player_nr_next == -1 && !all_players_fit_to_screen)
9680 game.centered_player_nr_next = game.centered_player_nr;
9681 game.set_centered_player = FALSE;
9684 /* do not switch focus to non-existing (or non-active) player */
9685 if (game.centered_player_nr_next >= 0 &&
9686 !stored_player[game.centered_player_nr_next].active)
9688 game.centered_player_nr_next = game.centered_player_nr;
9689 game.set_centered_player = FALSE;
9693 if (game.set_centered_player &&
9694 ScreenMovPos == 0) /* screen currently aligned at tile position */
9698 if (game.centered_player_nr_next == -1)
9700 setScreenCenteredToAllPlayers(&sx, &sy);
9704 sx = stored_player[game.centered_player_nr_next].jx;
9705 sy = stored_player[game.centered_player_nr_next].jy;
9708 game.centered_player_nr = game.centered_player_nr_next;
9709 game.set_centered_player = FALSE;
9711 DrawRelocateScreen(sx, sy, MV_NONE, TRUE, setup.quick_switch);
9712 DrawGameDoorValues();
9716 for (i = 0; i < MAX_PLAYERS; i++)
9718 int actual_player_action = stored_player[i].effective_action;
9721 /* !!! THIS BREAKS THE FOLLOWING TAPES: !!!
9722 - rnd_equinox_tetrachloride 048
9723 - rnd_equinox_tetrachloride_ii 096
9724 - rnd_emanuel_schmieg 002
9725 - doctor_sloan_ww 001, 020
9727 if (stored_player[i].MovPos == 0)
9728 CheckGravityMovement(&stored_player[i]);
9731 /* overwrite programmed action with tape action */
9732 if (stored_player[i].programmed_action)
9733 actual_player_action = stored_player[i].programmed_action;
9736 PlayerActions(&stored_player[i], actual_player_action);
9738 tape_action[i] = PlayerActions(&stored_player[i], actual_player_action);
9740 if (tape.recording && tape_action[i] && !tape.player_participates[i])
9741 tape.player_participates[i] = TRUE; /* player just appeared from CE */
9744 ScrollPlayer(&stored_player[i], SCROLL_GO_ON);
9748 network_player_action_received = FALSE;
9751 ScrollScreen(NULL, SCROLL_GO_ON);
9753 /* for backwards compatibility, the following code emulates a fixed bug that
9754 occured when pushing elements (causing elements that just made their last
9755 pushing step to already (if possible) make their first falling step in the
9756 same game frame, which is bad); this code is also needed to use the famous
9757 "spring push bug" which is used in older levels and might be wanted to be
9758 used also in newer levels, but in this case the buggy pushing code is only
9759 affecting the "spring" element and no other elements */
9761 if (game.engine_version < VERSION_IDENT(2,2,0,7) || level.use_spring_bug)
9763 for (i = 0; i < MAX_PLAYERS; i++)
9765 struct PlayerInfo *player = &stored_player[i];
9769 if (player->active && player->is_pushing && player->is_moving &&
9771 (game.engine_version < VERSION_IDENT(2,2,0,7) ||
9772 Feld[x][y] == EL_SPRING))
9774 ContinueMoving(x, y);
9776 /* continue moving after pushing (this is actually a bug) */
9777 if (!IS_MOVING(x, y))
9786 SCAN_PLAYFIELD(x, y)
9788 for (y = 0; y < lev_fieldy; y++) for (x = 0; x < lev_fieldx; x++)
9791 ChangeCount[x][y] = 0;
9792 ChangeEvent[x][y] = -1;
9794 /* this must be handled before main playfield loop */
9795 if (Feld[x][y] == EL_PLAYER_IS_LEAVING)
9798 if (MovDelay[x][y] <= 0)
9802 #if USE_NEW_SNAP_DELAY
9803 if (Feld[x][y] == EL_ELEMENT_SNAPPING)
9806 if (MovDelay[x][y] <= 0)
9809 DrawLevelField(x, y);
9811 TestIfElementTouchesCustomElement(x, y); /* for empty space */
9817 if (ChangePage[x][y] != -1 && ChangeDelay[x][y] != 1)
9819 printf("GameActions(): x = %d, y = %d: ChangePage != -1\n", x, y);
9820 printf("GameActions(): This should never happen!\n");
9822 ChangePage[x][y] = -1;
9827 if (WasJustMoving[x][y] > 0)
9828 WasJustMoving[x][y]--;
9829 if (WasJustFalling[x][y] > 0)
9830 WasJustFalling[x][y]--;
9831 if (CheckCollision[x][y] > 0)
9832 CheckCollision[x][y]--;
9836 /* reset finished pushing action (not done in ContinueMoving() to allow
9837 continuous pushing animation for elements with zero push delay) */
9838 if (GfxAction[x][y] == ACTION_PUSHING && !IS_MOVING(x, y))
9840 ResetGfxAnimation(x, y);
9841 DrawLevelField(x, y);
9845 if (IS_BLOCKED(x, y))
9849 Blocked2Moving(x, y, &oldx, &oldy);
9850 if (!IS_MOVING(oldx, oldy))
9852 printf("GameActions(): (BLOCKED => MOVING) context corrupted!\n");
9853 printf("GameActions(): BLOCKED: x = %d, y = %d\n", x, y);
9854 printf("GameActions(): !MOVING: oldx = %d, oldy = %d\n", oldx, oldy);
9855 printf("GameActions(): This should never happen!\n");
9862 SCAN_PLAYFIELD(x, y)
9864 for (y = 0; y < lev_fieldy; y++) for (x = 0; x < lev_fieldx; x++)
9867 element = Feld[x][y];
9868 graphic = el_act_dir2img(element, GfxAction[x][y], GfxDir[x][y]);
9871 printf("::: %d,%d\n", x, y);
9873 if (element == EL_ROCK)
9874 printf("::: Yo man! Rocks can fall!\n");
9878 ResetGfxFrame(x, y, TRUE);
9880 if (graphic_info[graphic].anim_global_sync)
9881 GfxFrame[x][y] = FrameCounter;
9882 else if (ANIM_MODE(graphic) == ANIM_CE_VALUE)
9884 int old_gfx_frame = GfxFrame[x][y];
9886 GfxFrame[x][y] = CustomValue[x][y];
9889 if (GfxFrame[x][y] != old_gfx_frame)
9891 DrawLevelGraphicAnimation(x, y, graphic);
9893 else if (ANIM_MODE(graphic) == ANIM_CE_SCORE)
9895 int old_gfx_frame = GfxFrame[x][y];
9897 GfxFrame[x][y] = element_info[element].collect_score;
9900 if (GfxFrame[x][y] != old_gfx_frame)
9902 DrawLevelGraphicAnimation(x, y, graphic);
9904 else if (ANIM_MODE(graphic) == ANIM_CE_DELAY)
9906 int old_gfx_frame = GfxFrame[x][y];
9908 GfxFrame[x][y] = ChangeDelay[x][y];
9911 if (GfxFrame[x][y] != old_gfx_frame)
9913 DrawLevelGraphicAnimation(x, y, graphic);
9917 if (ANIM_MODE(graphic) == ANIM_RANDOM &&
9918 IS_NEXT_FRAME(GfxFrame[x][y], graphic))
9919 ResetRandomAnimationValue(x, y);
9921 SetRandomAnimationValue(x, y);
9923 PlayLevelSoundActionIfLoop(x, y, GfxAction[x][y]);
9925 if (IS_INACTIVE(element))
9927 if (IS_ANIMATED(graphic))
9928 DrawLevelGraphicAnimationIfNeeded(x, y, graphic);
9933 /* this may take place after moving, so 'element' may have changed */
9934 if (IS_CHANGING(x, y) &&
9935 (game.engine_version < VERSION_IDENT(3,0,7,1) || !Stop[x][y]))
9937 int page = element_info[element].event_page_nr[CE_DELAY];
9939 HandleElementChange(x, y, ChangePage[x][y] != -1 ? ChangePage[x][y] : page);
9943 printf("::: ChangeDelay == %d\n", ChangeDelay[x][y]);
9947 if (element == EL_CUSTOM_255)
9948 printf("::: ChangeDelay == %d\n", ChangeDelay[x][y]);
9952 HandleElementChange(x, y, page);
9954 if (CAN_CHANGE(element))
9955 HandleElementChange(x, y, page);
9957 if (HAS_ACTION(element))
9958 ExecuteCustomElementAction(x, y, element, page);
9963 element = Feld[x][y];
9964 graphic = el_act_dir2img(element, GfxAction[x][y], GfxDir[x][y]);
9967 if (!IS_MOVING(x, y) && (CAN_FALL(element) || CAN_MOVE(element)))
9971 element = Feld[x][y];
9972 graphic = el_act_dir2img(element, GfxAction[x][y], GfxDir[x][y]);
9974 if (IS_ANIMATED(graphic) &&
9977 DrawLevelGraphicAnimationIfNeeded(x, y, graphic);
9979 if (IS_GEM(element) || element == EL_SP_INFOTRON)
9980 EdelsteinFunkeln(x, y);
9982 else if ((element == EL_ACID ||
9983 element == EL_EXIT_OPEN ||
9984 element == EL_SP_EXIT_OPEN ||
9985 element == EL_SP_TERMINAL ||
9986 element == EL_SP_TERMINAL_ACTIVE ||
9987 element == EL_EXTRA_TIME ||
9988 element == EL_SHIELD_NORMAL ||
9989 element == EL_SHIELD_DEADLY) &&
9990 IS_ANIMATED(graphic))
9991 DrawLevelGraphicAnimationIfNeeded(x, y, graphic);
9992 else if (IS_MOVING(x, y))
9993 ContinueMoving(x, y);
9994 else if (IS_ACTIVE_BOMB(element))
9995 CheckDynamite(x, y);
9996 else if (element == EL_AMOEBA_GROWING)
9997 AmoebeWaechst(x, y);
9998 else if (element == EL_AMOEBA_SHRINKING)
9999 AmoebaDisappearing(x, y);
10001 #if !USE_NEW_AMOEBA_CODE
10002 else if (IS_AMOEBALIVE(element))
10003 AmoebeAbleger(x, y);
10006 else if (element == EL_GAME_OF_LIFE || element == EL_BIOMAZE)
10008 else if (element == EL_EXIT_CLOSED)
10010 else if (element == EL_SP_EXIT_CLOSED)
10012 else if (element == EL_EXPANDABLE_WALL_GROWING)
10013 MauerWaechst(x, y);
10014 else if (element == EL_EXPANDABLE_WALL ||
10015 element == EL_EXPANDABLE_WALL_HORIZONTAL ||
10016 element == EL_EXPANDABLE_WALL_VERTICAL ||
10017 element == EL_EXPANDABLE_WALL_ANY)
10018 MauerAbleger(x, y);
10019 else if (element == EL_FLAMES)
10020 CheckForDragon(x, y);
10021 else if (element == EL_EXPLOSION)
10022 ; /* drawing of correct explosion animation is handled separately */
10023 else if (element == EL_ELEMENT_SNAPPING ||
10024 element == EL_DIAGONAL_SHRINKING ||
10025 element == EL_DIAGONAL_GROWING)
10028 graphic = el_act_dir2img(GfxElement[x][y], GfxAction[x][y],GfxDir[x][y]);
10030 DrawLevelGraphicAnimationIfNeeded(x, y, graphic);
10033 else if (IS_ANIMATED(graphic) && !IS_CHANGING(x, y))
10034 DrawLevelGraphicAnimationIfNeeded(x, y, graphic);
10037 if (element == EL_CUSTOM_255 ||
10038 element == EL_CUSTOM_256)
10039 DrawLevelGraphicAnimation(x, y, graphic);
10042 if (IS_BELT_ACTIVE(element))
10043 PlayLevelSoundAction(x, y, ACTION_ACTIVE);
10045 if (game.magic_wall_active)
10047 int jx = local_player->jx, jy = local_player->jy;
10049 /* play the element sound at the position nearest to the player */
10050 if ((element == EL_MAGIC_WALL_FULL ||
10051 element == EL_MAGIC_WALL_ACTIVE ||
10052 element == EL_MAGIC_WALL_EMPTYING ||
10053 element == EL_BD_MAGIC_WALL_FULL ||
10054 element == EL_BD_MAGIC_WALL_ACTIVE ||
10055 element == EL_BD_MAGIC_WALL_EMPTYING) &&
10056 ABS(x-jx) + ABS(y-jy) < ABS(magic_wall_x-jx) + ABS(magic_wall_y-jy))
10064 #if USE_NEW_AMOEBA_CODE
10065 /* new experimental amoeba growth stuff */
10066 if (!(FrameCounter % 8))
10068 static unsigned long random = 1684108901;
10070 for (i = 0; i < level.amoeba_speed * 28 / 8; i++)
10072 x = RND(lev_fieldx);
10073 y = RND(lev_fieldy);
10074 element = Feld[x][y];
10076 if (!IS_PLAYER(x,y) &&
10077 (element == EL_EMPTY ||
10078 CAN_GROW_INTO(element) ||
10079 element == EL_QUICKSAND_EMPTY ||
10080 element == EL_ACID_SPLASH_LEFT ||
10081 element == EL_ACID_SPLASH_RIGHT))
10083 if ((IN_LEV_FIELD(x, y-1) && Feld[x][y-1] == EL_AMOEBA_WET) ||
10084 (IN_LEV_FIELD(x-1, y) && Feld[x-1][y] == EL_AMOEBA_WET) ||
10085 (IN_LEV_FIELD(x+1, y) && Feld[x+1][y] == EL_AMOEBA_WET) ||
10086 (IN_LEV_FIELD(x, y+1) && Feld[x][y+1] == EL_AMOEBA_WET))
10087 Feld[x][y] = EL_AMOEBA_DROP;
10090 random = random * 129 + 1;
10096 if (game.explosions_delayed)
10099 game.explosions_delayed = FALSE;
10102 SCAN_PLAYFIELD(x, y)
10104 for (y = 0; y < lev_fieldy; y++) for (x = 0; x < lev_fieldx; x++)
10107 element = Feld[x][y];
10109 if (ExplodeField[x][y])
10110 Explode(x, y, EX_PHASE_START, ExplodeField[x][y]);
10111 else if (element == EL_EXPLOSION)
10112 Explode(x, y, ExplodePhase[x][y], EX_TYPE_NORMAL);
10114 ExplodeField[x][y] = EX_TYPE_NONE;
10117 game.explosions_delayed = TRUE;
10120 if (game.magic_wall_active)
10122 if (!(game.magic_wall_time_left % 4))
10124 int element = Feld[magic_wall_x][magic_wall_y];
10126 if (element == EL_BD_MAGIC_WALL_FULL ||
10127 element == EL_BD_MAGIC_WALL_ACTIVE ||
10128 element == EL_BD_MAGIC_WALL_EMPTYING)
10129 PlayLevelSound(magic_wall_x, magic_wall_y, SND_BD_MAGIC_WALL_ACTIVE);
10131 PlayLevelSound(magic_wall_x, magic_wall_y, SND_MAGIC_WALL_ACTIVE);
10134 if (game.magic_wall_time_left > 0)
10136 game.magic_wall_time_left--;
10137 if (!game.magic_wall_time_left)
10140 SCAN_PLAYFIELD(x, y)
10142 for (y = 0; y < lev_fieldy; y++) for (x = 0; x < lev_fieldx; x++)
10145 element = Feld[x][y];
10147 if (element == EL_MAGIC_WALL_ACTIVE ||
10148 element == EL_MAGIC_WALL_FULL)
10150 Feld[x][y] = EL_MAGIC_WALL_DEAD;
10151 DrawLevelField(x, y);
10153 else if (element == EL_BD_MAGIC_WALL_ACTIVE ||
10154 element == EL_BD_MAGIC_WALL_FULL)
10156 Feld[x][y] = EL_BD_MAGIC_WALL_DEAD;
10157 DrawLevelField(x, y);
10161 game.magic_wall_active = FALSE;
10166 if (game.light_time_left > 0)
10168 game.light_time_left--;
10170 if (game.light_time_left == 0)
10171 RedrawAllLightSwitchesAndInvisibleElements();
10174 if (game.timegate_time_left > 0)
10176 game.timegate_time_left--;
10178 if (game.timegate_time_left == 0)
10179 CloseAllOpenTimegates();
10182 if (game.lenses_time_left > 0)
10184 game.lenses_time_left--;
10186 if (game.lenses_time_left == 0)
10187 RedrawAllInvisibleElementsForLenses();
10190 if (game.magnify_time_left > 0)
10192 game.magnify_time_left--;
10194 if (game.magnify_time_left == 0)
10195 RedrawAllInvisibleElementsForMagnifier();
10198 for (i = 0; i < MAX_PLAYERS; i++)
10200 struct PlayerInfo *player = &stored_player[i];
10202 if (SHIELD_ON(player))
10204 if (player->shield_deadly_time_left)
10205 PlayLevelSound(player->jx, player->jy, SND_SHIELD_DEADLY_ACTIVE);
10206 else if (player->shield_normal_time_left)
10207 PlayLevelSound(player->jx, player->jy, SND_SHIELD_NORMAL_ACTIVE);
10214 PlayAllPlayersSound();
10216 if (options.debug) /* calculate frames per second */
10218 static unsigned long fps_counter = 0;
10219 static int fps_frames = 0;
10220 unsigned long fps_delay_ms = Counter() - fps_counter;
10224 if (fps_delay_ms >= 500) /* calculate fps every 0.5 seconds */
10226 global.frames_per_second = 1000 * (float)fps_frames / fps_delay_ms;
10229 fps_counter = Counter();
10232 redraw_mask |= REDRAW_FPS;
10235 AdvanceFrameAndPlayerCounters(-1); /* advance counters for all players */
10237 if (local_player->show_envelope != 0 && local_player->MovPos == 0)
10239 ShowEnvelope(local_player->show_envelope - EL_ENVELOPE_1);
10241 local_player->show_envelope = 0;
10244 /* use random number generator in every frame to make it less predictable */
10245 if (game.engine_version >= VERSION_IDENT(3,1,1,0))
10249 static boolean AllPlayersInSight(struct PlayerInfo *player, int x, int y)
10251 int min_x = x, min_y = y, max_x = x, max_y = y;
10254 for (i = 0; i < MAX_PLAYERS; i++)
10256 int jx = stored_player[i].jx, jy = stored_player[i].jy;
10258 if (!stored_player[i].active || &stored_player[i] == player)
10261 min_x = MIN(min_x, jx);
10262 min_y = MIN(min_y, jy);
10263 max_x = MAX(max_x, jx);
10264 max_y = MAX(max_y, jy);
10267 return (max_x - min_x < SCR_FIELDX && max_y - min_y < SCR_FIELDY);
10270 static boolean AllPlayersInVisibleScreen()
10274 for (i = 0; i < MAX_PLAYERS; i++)
10276 int jx = stored_player[i].jx, jy = stored_player[i].jy;
10278 if (!stored_player[i].active)
10281 if (!IN_VIS_FIELD(SCREENX(jx), SCREENY(jy)))
10288 void ScrollLevel(int dx, int dy)
10290 int softscroll_offset = (setup.soft_scrolling ? TILEX : 0);
10293 BlitBitmap(drawto_field, drawto_field,
10294 FX + TILEX * (dx == -1) - softscroll_offset,
10295 FY + TILEY * (dy == -1) - softscroll_offset,
10296 SXSIZE - TILEX * (dx!=0) + 2 * softscroll_offset,
10297 SYSIZE - TILEY * (dy!=0) + 2 * softscroll_offset,
10298 FX + TILEX * (dx == 1) - softscroll_offset,
10299 FY + TILEY * (dy == 1) - softscroll_offset);
10303 x = (dx == 1 ? BX1 : BX2);
10304 for (y = BY1; y <= BY2; y++)
10305 DrawScreenField(x, y);
10310 y = (dy == 1 ? BY1 : BY2);
10311 for (x = BX1; x <= BX2; x++)
10312 DrawScreenField(x, y);
10315 redraw_mask |= REDRAW_FIELD;
10318 static boolean canFallDown(struct PlayerInfo *player)
10320 int jx = player->jx, jy = player->jy;
10322 return (IN_LEV_FIELD(jx, jy + 1) &&
10323 (IS_FREE(jx, jy + 1) ||
10324 (Feld[jx][jy + 1] == EL_ACID && player->can_fall_into_acid)) &&
10325 IS_WALKABLE_FROM(Feld[jx][jy], MV_DOWN) &&
10326 !IS_WALKABLE_INSIDE(Feld[jx][jy]));
10329 static boolean canPassField(int x, int y, int move_dir)
10331 int opposite_dir = MV_DIR_OPPOSITE(move_dir);
10332 int dx = (move_dir & MV_LEFT ? -1 : move_dir & MV_RIGHT ? +1 : 0);
10333 int dy = (move_dir & MV_UP ? -1 : move_dir & MV_DOWN ? +1 : 0);
10334 int nextx = x + dx;
10335 int nexty = y + dy;
10336 int element = Feld[x][y];
10338 return (IS_PASSABLE_FROM(element, opposite_dir) &&
10339 !CAN_MOVE(element) &&
10340 IN_LEV_FIELD(nextx, nexty) && !IS_PLAYER(nextx, nexty) &&
10341 IS_WALKABLE_FROM(Feld[nextx][nexty], move_dir) &&
10342 (level.can_pass_to_walkable || IS_FREE(nextx, nexty)));
10345 static boolean canMoveToValidFieldWithGravity(int x, int y, int move_dir)
10347 int opposite_dir = MV_DIR_OPPOSITE(move_dir);
10348 int dx = (move_dir & MV_LEFT ? -1 : move_dir & MV_RIGHT ? +1 : 0);
10349 int dy = (move_dir & MV_UP ? -1 : move_dir & MV_DOWN ? +1 : 0);
10353 return (IN_LEV_FIELD(newx, newy) && !IS_FREE_OR_PLAYER(newx, newy) &&
10354 IS_GRAVITY_REACHABLE(Feld[newx][newy]) &&
10355 (IS_DIGGABLE(Feld[newx][newy]) ||
10356 IS_WALKABLE_FROM(Feld[newx][newy], opposite_dir) ||
10357 canPassField(newx, newy, move_dir)));
10360 static void CheckGravityMovement(struct PlayerInfo *player)
10362 #if USE_PLAYER_GRAVITY
10363 if (player->gravity && !player->programmed_action)
10365 if (game.gravity && !player->programmed_action)
10368 int move_dir_horizontal = player->effective_action & MV_HORIZONTAL;
10369 int move_dir_vertical = player->effective_action & MV_VERTICAL;
10370 boolean player_is_snapping = player->effective_action & JOY_BUTTON_1;
10371 int jx = player->jx, jy = player->jy;
10372 boolean player_is_moving_to_valid_field =
10373 (!player_is_snapping &&
10374 (canMoveToValidFieldWithGravity(jx, jy, move_dir_horizontal) ||
10375 canMoveToValidFieldWithGravity(jx, jy, move_dir_vertical)));
10376 boolean player_can_fall_down = canFallDown(player);
10378 if (player_can_fall_down &&
10379 !player_is_moving_to_valid_field)
10380 player->programmed_action = MV_DOWN;
10384 static void CheckGravityMovementWhenNotMoving(struct PlayerInfo *player)
10386 return CheckGravityMovement(player);
10388 #if USE_PLAYER_GRAVITY
10389 if (player->gravity && !player->programmed_action)
10391 if (game.gravity && !player->programmed_action)
10394 int jx = player->jx, jy = player->jy;
10395 boolean field_under_player_is_free =
10396 (IN_LEV_FIELD(jx, jy + 1) && IS_FREE(jx, jy + 1));
10397 boolean player_is_standing_on_valid_field =
10398 (IS_WALKABLE_INSIDE(Feld[jx][jy]) ||
10399 (IS_WALKABLE(Feld[jx][jy]) &&
10400 !(element_info[Feld[jx][jy]].access_direction & MV_DOWN)));
10402 if (field_under_player_is_free && !player_is_standing_on_valid_field)
10403 player->programmed_action = MV_DOWN;
10408 MovePlayerOneStep()
10409 -----------------------------------------------------------------------------
10410 dx, dy: direction (non-diagonal) to try to move the player to
10411 real_dx, real_dy: direction as read from input device (can be diagonal)
10414 boolean MovePlayerOneStep(struct PlayerInfo *player,
10415 int dx, int dy, int real_dx, int real_dy)
10417 int jx = player->jx, jy = player->jy;
10418 int new_jx = jx + dx, new_jy = jy + dy;
10419 #if !USE_FIXED_DONT_RUN_INTO
10423 boolean player_can_move = !player->cannot_move;
10425 if (!player->active || (!dx && !dy))
10426 return MP_NO_ACTION;
10428 player->MovDir = (dx < 0 ? MV_LEFT :
10429 dx > 0 ? MV_RIGHT :
10431 dy > 0 ? MV_DOWN : MV_NONE);
10433 if (!IN_LEV_FIELD(new_jx, new_jy))
10434 return MP_NO_ACTION;
10436 if (!player_can_move)
10439 if (player->MovPos == 0)
10441 player->is_moving = FALSE;
10442 player->is_digging = FALSE;
10443 player->is_collecting = FALSE;
10444 player->is_snapping = FALSE;
10445 player->is_pushing = FALSE;
10448 DigField(player, 0, 0, 0, 0, 0, 0, DF_NO_PUSH);
10449 SnapField(player, 0, 0);
10453 return MP_NO_ACTION;
10458 if (!options.network && game.centered_player_nr == -1 &&
10459 !AllPlayersInSight(player, new_jx, new_jy))
10460 return MP_NO_ACTION;
10462 if (!options.network && !AllPlayersInSight(player, new_jx, new_jy))
10463 return MP_NO_ACTION;
10466 #if !USE_FIXED_DONT_RUN_INTO
10467 element = MovingOrBlocked2ElementIfNotLeaving(new_jx, new_jy);
10469 /* (moved to DigField()) */
10470 if (player_can_move && DONT_RUN_INTO(element))
10472 if (element == EL_ACID && dx == 0 && dy == 1)
10474 SplashAcid(new_jx, new_jy);
10475 Feld[jx][jy] = EL_PLAYER_1;
10476 InitMovingField(jx, jy, MV_DOWN);
10477 Store[jx][jy] = EL_ACID;
10478 ContinueMoving(jx, jy);
10479 BuryPlayer(player);
10482 TestIfPlayerRunsIntoBadThing(jx, jy, player->MovDir);
10488 can_move = DigField(player, jx, jy, new_jx, new_jy, real_dx,real_dy, DF_DIG);
10490 #if USE_FIXED_DONT_RUN_INTO
10491 if (can_move == MP_DONT_RUN_INTO)
10495 if (can_move != MP_MOVING)
10498 #if USE_FIXED_DONT_RUN_INTO
10501 /* check if DigField() has caused relocation of the player */
10502 if (player->jx != jx || player->jy != jy)
10503 return MP_NO_ACTION; /* <-- !!! CHECK THIS [-> MP_ACTION ?] !!! */
10505 StorePlayer[jx][jy] = 0;
10506 player->last_jx = jx;
10507 player->last_jy = jy;
10508 player->jx = new_jx;
10509 player->jy = new_jy;
10510 StorePlayer[new_jx][new_jy] = player->element_nr;
10512 if (player->move_delay_value_next != -1)
10514 player->move_delay_value = player->move_delay_value_next;
10515 player->move_delay_value_next = -1;
10519 (dx > 0 || dy > 0 ? -1 : 1) * (TILEX - TILEX / player->move_delay_value);
10521 player->step_counter++;
10523 PlayerVisit[jx][jy] = FrameCounter;
10525 ScrollPlayer(player, SCROLL_INIT);
10530 boolean MovePlayer(struct PlayerInfo *player, int dx, int dy)
10532 int jx = player->jx, jy = player->jy;
10533 int old_jx = jx, old_jy = jy;
10534 int moved = MP_NO_ACTION;
10536 if (!player->active)
10541 if (player->MovPos == 0)
10543 player->is_moving = FALSE;
10544 player->is_digging = FALSE;
10545 player->is_collecting = FALSE;
10546 player->is_snapping = FALSE;
10547 player->is_pushing = FALSE;
10553 if (player->move_delay > 0)
10556 player->move_delay = -1; /* set to "uninitialized" value */
10558 /* store if player is automatically moved to next field */
10559 player->is_auto_moving = (player->programmed_action != MV_NONE);
10561 /* remove the last programmed player action */
10562 player->programmed_action = 0;
10564 if (player->MovPos)
10566 /* should only happen if pre-1.2 tape recordings are played */
10567 /* this is only for backward compatibility */
10569 int original_move_delay_value = player->move_delay_value;
10572 printf("THIS SHOULD ONLY HAPPEN WITH PRE-1.2 LEVEL TAPES. [%ld]\n",
10576 /* scroll remaining steps with finest movement resolution */
10577 player->move_delay_value = MOVE_DELAY_NORMAL_SPEED;
10579 while (player->MovPos)
10581 ScrollPlayer(player, SCROLL_GO_ON);
10582 ScrollScreen(NULL, SCROLL_GO_ON);
10584 AdvanceFrameAndPlayerCounters(player->index_nr);
10590 player->move_delay_value = original_move_delay_value;
10593 player->is_active = FALSE;
10595 if (player->last_move_dir & MV_HORIZONTAL)
10597 if (!(moved |= MovePlayerOneStep(player, 0, dy, dx, dy)))
10598 moved |= MovePlayerOneStep(player, dx, 0, dx, dy);
10602 if (!(moved |= MovePlayerOneStep(player, dx, 0, dx, dy)))
10603 moved |= MovePlayerOneStep(player, 0, dy, dx, dy);
10606 #if USE_FIXED_BORDER_RUNNING_GFX
10607 if (!moved && !player->is_active)
10609 player->is_moving = FALSE;
10610 player->is_digging = FALSE;
10611 player->is_collecting = FALSE;
10612 player->is_snapping = FALSE;
10613 player->is_pushing = FALSE;
10621 if (moved & MP_MOVING && !ScreenMovPos &&
10622 (player->index_nr == game.centered_player_nr ||
10623 game.centered_player_nr == -1))
10625 if (moved & MP_MOVING && !ScreenMovPos &&
10626 (player == local_player || !options.network))
10629 int old_scroll_x = scroll_x, old_scroll_y = scroll_y;
10630 int offset = (setup.scroll_delay ? 3 : 0);
10632 if (!IN_VIS_FIELD(SCREENX(jx), SCREENY(jy)))
10634 /* actual player has left the screen -- scroll in that direction */
10635 if (jx != old_jx) /* player has moved horizontally */
10636 scroll_x += (jx - old_jx);
10637 else /* player has moved vertically */
10638 scroll_y += (jy - old_jy);
10642 if (jx != old_jx) /* player has moved horizontally */
10644 if ((player->MovDir == MV_LEFT && scroll_x > jx - MIDPOSX + offset) ||
10645 (player->MovDir == MV_RIGHT && scroll_x < jx - MIDPOSX - offset))
10646 scroll_x = jx-MIDPOSX + (scroll_x < jx-MIDPOSX ? -offset : +offset);
10648 /* don't scroll over playfield boundaries */
10649 if (scroll_x < SBX_Left || scroll_x > SBX_Right)
10650 scroll_x = (scroll_x < SBX_Left ? SBX_Left : SBX_Right);
10652 /* don't scroll more than one field at a time */
10653 scroll_x = old_scroll_x + SIGN(scroll_x - old_scroll_x);
10655 /* don't scroll against the player's moving direction */
10656 if ((player->MovDir == MV_LEFT && scroll_x > old_scroll_x) ||
10657 (player->MovDir == MV_RIGHT && scroll_x < old_scroll_x))
10658 scroll_x = old_scroll_x;
10660 else /* player has moved vertically */
10662 if ((player->MovDir == MV_UP && scroll_y > jy - MIDPOSY + offset) ||
10663 (player->MovDir == MV_DOWN && scroll_y < jy - MIDPOSY - offset))
10664 scroll_y = jy-MIDPOSY + (scroll_y < jy-MIDPOSY ? -offset : +offset);
10666 /* don't scroll over playfield boundaries */
10667 if (scroll_y < SBY_Upper || scroll_y > SBY_Lower)
10668 scroll_y = (scroll_y < SBY_Upper ? SBY_Upper : SBY_Lower);
10670 /* don't scroll more than one field at a time */
10671 scroll_y = old_scroll_y + SIGN(scroll_y - old_scroll_y);
10673 /* don't scroll against the player's moving direction */
10674 if ((player->MovDir == MV_UP && scroll_y > old_scroll_y) ||
10675 (player->MovDir == MV_DOWN && scroll_y < old_scroll_y))
10676 scroll_y = old_scroll_y;
10680 if (scroll_x != old_scroll_x || scroll_y != old_scroll_y)
10683 if (!options.network && game.centered_player_nr == -1 &&
10684 !AllPlayersInVisibleScreen())
10686 scroll_x = old_scroll_x;
10687 scroll_y = old_scroll_y;
10691 if (!options.network && !AllPlayersInVisibleScreen())
10693 scroll_x = old_scroll_x;
10694 scroll_y = old_scroll_y;
10699 ScrollScreen(player, SCROLL_INIT);
10700 ScrollLevel(old_scroll_x - scroll_x, old_scroll_y - scroll_y);
10705 player->StepFrame = 0;
10707 if (moved & MP_MOVING)
10709 if (old_jx != jx && old_jy == jy)
10710 player->MovDir = (old_jx < jx ? MV_RIGHT : MV_LEFT);
10711 else if (old_jx == jx && old_jy != jy)
10712 player->MovDir = (old_jy < jy ? MV_DOWN : MV_UP);
10714 DrawLevelField(jx, jy); /* for "crumbled sand" */
10716 player->last_move_dir = player->MovDir;
10717 player->is_moving = TRUE;
10718 player->is_snapping = FALSE;
10719 player->is_switching = FALSE;
10720 player->is_dropping = FALSE;
10721 player->is_dropping_pressed = FALSE;
10722 player->drop_pressed_delay = 0;
10726 CheckGravityMovementWhenNotMoving(player);
10728 player->is_moving = FALSE;
10730 /* at this point, the player is allowed to move, but cannot move right now
10731 (e.g. because of something blocking the way) -- ensure that the player
10732 is also allowed to move in the next frame (in old versions before 3.1.1,
10733 the player was forced to wait again for eight frames before next try) */
10735 if (game.engine_version >= VERSION_IDENT(3,1,1,0))
10736 player->move_delay = 0; /* allow direct movement in the next frame */
10739 if (player->move_delay == -1) /* not yet initialized by DigField() */
10740 player->move_delay = player->move_delay_value;
10742 if (game.engine_version < VERSION_IDENT(3,0,7,0))
10744 TestIfPlayerTouchesBadThing(jx, jy);
10745 TestIfPlayerTouchesCustomElement(jx, jy);
10748 if (!player->active)
10749 RemovePlayer(player);
10754 void ScrollPlayer(struct PlayerInfo *player, int mode)
10756 int jx = player->jx, jy = player->jy;
10757 int last_jx = player->last_jx, last_jy = player->last_jy;
10758 int move_stepsize = TILEX / player->move_delay_value;
10760 #if USE_NEW_PLAYER_SPEED
10761 if (!player->active)
10764 if (player->MovPos == 0 && mode == SCROLL_GO_ON) /* player not moving */
10767 if (!player->active || player->MovPos == 0)
10771 if (mode == SCROLL_INIT)
10773 player->actual_frame_counter = FrameCounter;
10774 player->GfxPos = move_stepsize * (player->MovPos / move_stepsize);
10776 if ((player->block_last_field || player->block_delay_adjustment > 0) &&
10777 Feld[last_jx][last_jy] == EL_EMPTY)
10779 int last_field_block_delay = 0; /* start with no blocking at all */
10780 int block_delay_adjustment = player->block_delay_adjustment;
10782 /* if player blocks last field, add delay for exactly one move */
10783 if (player->block_last_field)
10785 last_field_block_delay += player->move_delay_value;
10787 /* when blocking enabled, prevent moving up despite gravity */
10788 #if USE_PLAYER_GRAVITY
10789 if (player->gravity && player->MovDir == MV_UP)
10790 block_delay_adjustment = -1;
10792 if (game.gravity && player->MovDir == MV_UP)
10793 block_delay_adjustment = -1;
10797 /* add block delay adjustment (also possible when not blocking) */
10798 last_field_block_delay += block_delay_adjustment;
10800 Feld[last_jx][last_jy] = EL_PLAYER_IS_LEAVING;
10801 MovDelay[last_jx][last_jy] = last_field_block_delay + 1;
10804 #if USE_NEW_PLAYER_SPEED
10805 if (player->MovPos != 0) /* player has not yet reached destination */
10811 else if (!FrameReached(&player->actual_frame_counter, 1))
10815 printf("::: player->MovPos: %d -> %d\n",
10817 player->MovPos + (player->MovPos > 0 ? -1 : 1) * move_stepsize);
10820 #if USE_NEW_PLAYER_SPEED
10821 if (player->MovPos != 0)
10823 player->MovPos += (player->MovPos > 0 ? -1 : 1) * move_stepsize;
10824 player->GfxPos = move_stepsize * (player->MovPos / move_stepsize);
10826 /* before DrawPlayer() to draw correct player graphic for this case */
10827 if (player->MovPos == 0)
10828 CheckGravityMovement(player);
10831 player->MovPos += (player->MovPos > 0 ? -1 : 1) * move_stepsize;
10832 player->GfxPos = move_stepsize * (player->MovPos / move_stepsize);
10834 /* before DrawPlayer() to draw correct player graphic for this case */
10835 if (player->MovPos == 0)
10836 CheckGravityMovement(player);
10839 if (player->MovPos == 0) /* player reached destination field */
10842 printf("::: player reached destination field\n");
10845 if (player->move_delay_reset_counter > 0)
10847 player->move_delay_reset_counter--;
10849 if (player->move_delay_reset_counter == 0)
10851 /* continue with normal speed after quickly moving through gate */
10852 HALVE_PLAYER_SPEED(player);
10854 /* be able to make the next move without delay */
10855 player->move_delay = 0;
10859 player->last_jx = jx;
10860 player->last_jy = jy;
10862 if (Feld[jx][jy] == EL_EXIT_OPEN ||
10863 Feld[jx][jy] == EL_SP_EXIT_OPEN ||
10864 Feld[jx][jy] == EL_SP_EXIT_OPENING) /* <-- special case */
10866 DrawPlayer(player); /* needed here only to cleanup last field */
10867 RemovePlayer(player);
10869 if (local_player->friends_still_needed == 0 ||
10870 IS_SP_ELEMENT(Feld[jx][jy]))
10871 player->LevelSolved = player->GameOver = TRUE;
10874 /* this breaks one level: "machine", level 000 */
10876 int move_direction = player->MovDir;
10877 int enter_side = MV_DIR_OPPOSITE(move_direction);
10878 int leave_side = move_direction;
10879 int old_jx = last_jx;
10880 int old_jy = last_jy;
10881 int old_element = Feld[old_jx][old_jy];
10882 int new_element = Feld[jx][jy];
10884 if (IS_CUSTOM_ELEMENT(old_element))
10885 CheckElementChangeByPlayer(old_jx, old_jy, old_element,
10887 player->index_bit, leave_side);
10889 CheckTriggeredElementChangeByPlayer(old_jx, old_jy, old_element,
10890 CE_PLAYER_LEAVES_X,
10891 player->index_bit, leave_side);
10893 if (IS_CUSTOM_ELEMENT(new_element))
10894 CheckElementChangeByPlayer(jx, jy, new_element, CE_ENTERED_BY_PLAYER,
10895 player->index_bit, enter_side);
10897 CheckTriggeredElementChangeByPlayer(jx, jy, new_element,
10898 CE_PLAYER_ENTERS_X,
10899 player->index_bit, enter_side);
10901 CheckTriggeredElementChangeBySide(jx, jy, player->element_nr,
10902 CE_MOVE_OF_X, move_direction);
10905 if (game.engine_version >= VERSION_IDENT(3,0,7,0))
10907 TestIfPlayerTouchesBadThing(jx, jy);
10908 TestIfPlayerTouchesCustomElement(jx, jy);
10910 /* needed because pushed element has not yet reached its destination,
10911 so it would trigger a change event at its previous field location */
10912 if (!player->is_pushing)
10913 TestIfElementTouchesCustomElement(jx, jy); /* for empty space */
10915 if (!player->active)
10916 RemovePlayer(player);
10919 if (level.use_step_counter)
10929 if (TimeLeft <= 10 && setup.time_limit)
10930 PlaySoundStereo(SND_GAME_RUNNING_OUT_OF_TIME, SOUND_MIDDLE);
10932 DrawGameValue_Time(TimeLeft);
10934 if (!TimeLeft && setup.time_limit)
10935 for (i = 0; i < MAX_PLAYERS; i++)
10936 KillPlayer(&stored_player[i]);
10938 else if (level.time == 0 && !AllPlayersGone) /* level w/o time limit */
10939 DrawGameValue_Time(TimePlayed);
10942 if (tape.single_step && tape.recording && !tape.pausing &&
10943 !player->programmed_action)
10944 TapeTogglePause(TAPE_TOGGLE_AUTOMATIC);
10948 void ScrollScreen(struct PlayerInfo *player, int mode)
10950 static unsigned long screen_frame_counter = 0;
10952 if (mode == SCROLL_INIT)
10954 /* set scrolling step size according to actual player's moving speed */
10955 ScrollStepSize = TILEX / player->move_delay_value;
10957 screen_frame_counter = FrameCounter;
10958 ScreenMovDir = player->MovDir;
10959 ScreenMovPos = player->MovPos;
10960 ScreenGfxPos = ScrollStepSize * (ScreenMovPos / ScrollStepSize);
10963 else if (!FrameReached(&screen_frame_counter, 1))
10968 ScreenMovPos += (ScreenMovPos > 0 ? -1 : 1) * ScrollStepSize;
10969 ScreenGfxPos = ScrollStepSize * (ScreenMovPos / ScrollStepSize);
10970 redraw_mask |= REDRAW_FIELD;
10973 ScreenMovDir = MV_NONE;
10976 void TestIfPlayerTouchesCustomElement(int x, int y)
10978 static int xy[4][2] =
10985 static int trigger_sides[4][2] =
10987 /* center side border side */
10988 { CH_SIDE_TOP, CH_SIDE_BOTTOM }, /* check top */
10989 { CH_SIDE_LEFT, CH_SIDE_RIGHT }, /* check left */
10990 { CH_SIDE_RIGHT, CH_SIDE_LEFT }, /* check right */
10991 { CH_SIDE_BOTTOM, CH_SIDE_TOP } /* check bottom */
10993 static int touch_dir[4] =
10995 MV_LEFT | MV_RIGHT,
11000 int center_element = Feld[x][y]; /* should always be non-moving! */
11003 for (i = 0; i < NUM_DIRECTIONS; i++)
11005 int xx = x + xy[i][0];
11006 int yy = y + xy[i][1];
11007 int center_side = trigger_sides[i][0];
11008 int border_side = trigger_sides[i][1];
11009 int border_element;
11011 if (!IN_LEV_FIELD(xx, yy))
11014 if (IS_PLAYER(x, y))
11016 struct PlayerInfo *player = PLAYERINFO(x, y);
11018 if (game.engine_version < VERSION_IDENT(3,0,7,0))
11019 border_element = Feld[xx][yy]; /* may be moving! */
11020 else if (!IS_MOVING(xx, yy) && !IS_BLOCKED(xx, yy))
11021 border_element = Feld[xx][yy];
11022 else if (MovDir[xx][yy] & touch_dir[i]) /* elements are touching */
11023 border_element = MovingOrBlocked2Element(xx, yy);
11025 continue; /* center and border element do not touch */
11027 CheckElementChangeByPlayer(xx, yy, border_element, CE_TOUCHED_BY_PLAYER,
11028 player->index_bit, border_side);
11029 CheckTriggeredElementChangeByPlayer(xx, yy, border_element,
11030 CE_PLAYER_TOUCHES_X,
11031 player->index_bit, border_side);
11033 else if (IS_PLAYER(xx, yy))
11035 struct PlayerInfo *player = PLAYERINFO(xx, yy);
11037 if (game.engine_version >= VERSION_IDENT(3,0,7,0))
11039 if (player->MovPos != 0 && !(player->MovDir & touch_dir[i]))
11040 continue; /* center and border element do not touch */
11043 CheckElementChangeByPlayer(x, y, center_element, CE_TOUCHED_BY_PLAYER,
11044 player->index_bit, center_side);
11045 CheckTriggeredElementChangeByPlayer(x, y, center_element,
11046 CE_PLAYER_TOUCHES_X,
11047 player->index_bit, center_side);
11053 #if USE_ELEMENT_TOUCHING_BUGFIX
11055 void TestIfElementTouchesCustomElement(int x, int y)
11057 static int xy[4][2] =
11064 static int trigger_sides[4][2] =
11066 /* center side border side */
11067 { CH_SIDE_TOP, CH_SIDE_BOTTOM }, /* check top */
11068 { CH_SIDE_LEFT, CH_SIDE_RIGHT }, /* check left */
11069 { CH_SIDE_RIGHT, CH_SIDE_LEFT }, /* check right */
11070 { CH_SIDE_BOTTOM, CH_SIDE_TOP } /* check bottom */
11072 static int touch_dir[4] =
11074 MV_LEFT | MV_RIGHT,
11079 boolean change_center_element = FALSE;
11080 int center_element = Feld[x][y]; /* should always be non-moving! */
11081 int border_element_old[NUM_DIRECTIONS];
11084 for (i = 0; i < NUM_DIRECTIONS; i++)
11086 int xx = x + xy[i][0];
11087 int yy = y + xy[i][1];
11088 int border_element;
11090 border_element_old[i] = -1;
11092 if (!IN_LEV_FIELD(xx, yy))
11095 if (game.engine_version < VERSION_IDENT(3,0,7,0))
11096 border_element = Feld[xx][yy]; /* may be moving! */
11097 else if (!IS_MOVING(xx, yy) && !IS_BLOCKED(xx, yy))
11098 border_element = Feld[xx][yy];
11099 else if (MovDir[xx][yy] & touch_dir[i]) /* elements are touching */
11100 border_element = MovingOrBlocked2Element(xx, yy);
11102 continue; /* center and border element do not touch */
11104 border_element_old[i] = border_element;
11107 for (i = 0; i < NUM_DIRECTIONS; i++)
11109 int xx = x + xy[i][0];
11110 int yy = y + xy[i][1];
11111 int center_side = trigger_sides[i][0];
11112 int border_element = border_element_old[i];
11114 if (border_element == -1)
11117 /* check for change of border element */
11118 CheckElementChangeBySide(xx, yy, border_element, center_element,
11119 CE_TOUCHING_X, center_side);
11122 for (i = 0; i < NUM_DIRECTIONS; i++)
11124 int border_side = trigger_sides[i][1];
11125 int border_element = border_element_old[i];
11127 if (border_element == -1)
11130 /* check for change of center element (but change it only once) */
11131 if (!change_center_element)
11132 change_center_element =
11133 CheckElementChangeBySide(x, y, center_element, border_element,
11134 CE_TOUCHING_X, border_side);
11140 void TestIfElementTouchesCustomElement_OLD(int x, int y)
11142 static int xy[4][2] =
11149 static int trigger_sides[4][2] =
11151 /* center side border side */
11152 { CH_SIDE_TOP, CH_SIDE_BOTTOM }, /* check top */
11153 { CH_SIDE_LEFT, CH_SIDE_RIGHT }, /* check left */
11154 { CH_SIDE_RIGHT, CH_SIDE_LEFT }, /* check right */
11155 { CH_SIDE_BOTTOM, CH_SIDE_TOP } /* check bottom */
11157 static int touch_dir[4] =
11159 MV_LEFT | MV_RIGHT,
11164 boolean change_center_element = FALSE;
11165 int center_element = Feld[x][y]; /* should always be non-moving! */
11168 for (i = 0; i < NUM_DIRECTIONS; i++)
11170 int xx = x + xy[i][0];
11171 int yy = y + xy[i][1];
11172 int center_side = trigger_sides[i][0];
11173 int border_side = trigger_sides[i][1];
11174 int border_element;
11176 if (!IN_LEV_FIELD(xx, yy))
11179 if (game.engine_version < VERSION_IDENT(3,0,7,0))
11180 border_element = Feld[xx][yy]; /* may be moving! */
11181 else if (!IS_MOVING(xx, yy) && !IS_BLOCKED(xx, yy))
11182 border_element = Feld[xx][yy];
11183 else if (MovDir[xx][yy] & touch_dir[i]) /* elements are touching */
11184 border_element = MovingOrBlocked2Element(xx, yy);
11186 continue; /* center and border element do not touch */
11188 /* check for change of center element (but change it only once) */
11189 if (!change_center_element)
11190 change_center_element =
11191 CheckElementChangeBySide(x, y, center_element, border_element,
11192 CE_TOUCHING_X, border_side);
11194 /* check for change of border element */
11195 CheckElementChangeBySide(xx, yy, border_element, center_element,
11196 CE_TOUCHING_X, center_side);
11202 void TestIfElementHitsCustomElement(int x, int y, int direction)
11204 int dx = (direction == MV_LEFT ? -1 : direction == MV_RIGHT ? +1 : 0);
11205 int dy = (direction == MV_UP ? -1 : direction == MV_DOWN ? +1 : 0);
11206 int hitx = x + dx, hity = y + dy;
11207 int hitting_element = Feld[x][y];
11208 int touched_element;
11210 if (IN_LEV_FIELD(hitx, hity) && IS_FREE(hitx, hity))
11213 touched_element = (IN_LEV_FIELD(hitx, hity) ?
11214 MovingOrBlocked2Element(hitx, hity) : EL_STEELWALL);
11216 if (IN_LEV_FIELD(hitx, hity))
11218 int opposite_direction = MV_DIR_OPPOSITE(direction);
11219 int hitting_side = direction;
11220 int touched_side = opposite_direction;
11221 boolean object_hit = (!IS_MOVING(hitx, hity) ||
11222 MovDir[hitx][hity] != direction ||
11223 ABS(MovPos[hitx][hity]) <= TILEY / 2);
11229 CheckElementChangeBySide(x, y, hitting_element, touched_element,
11230 CE_HITTING_X, touched_side);
11232 CheckElementChangeBySide(hitx, hity, touched_element,
11233 hitting_element, CE_HIT_BY_X, hitting_side);
11235 CheckElementChangeBySide(hitx, hity, touched_element, hitting_element,
11236 CE_HIT_BY_SOMETHING, opposite_direction);
11240 /* "hitting something" is also true when hitting the playfield border */
11241 CheckElementChangeBySide(x, y, hitting_element, touched_element,
11242 CE_HITTING_SOMETHING, direction);
11246 void TestIfElementSmashesCustomElement(int x, int y, int direction)
11248 int dx = (direction == MV_LEFT ? -1 : direction == MV_RIGHT ? +1 : 0);
11249 int dy = (direction == MV_UP ? -1 : direction == MV_DOWN ? +1 : 0);
11250 int hitx = x + dx, hity = y + dy;
11251 int hitting_element = Feld[x][y];
11252 int touched_element;
11254 boolean object_hit = (IN_LEV_FIELD(hitx, hity) &&
11255 !IS_FREE(hitx, hity) &&
11256 (!IS_MOVING(hitx, hity) ||
11257 MovDir[hitx][hity] != direction ||
11258 ABS(MovPos[hitx][hity]) <= TILEY / 2));
11261 if (IN_LEV_FIELD(hitx, hity) && IS_FREE(hitx, hity))
11265 if (IN_LEV_FIELD(hitx, hity) && !object_hit)
11269 touched_element = (IN_LEV_FIELD(hitx, hity) ?
11270 MovingOrBlocked2Element(hitx, hity) : EL_STEELWALL);
11272 CheckElementChangeBySide(x, y, hitting_element, touched_element,
11273 EP_CAN_SMASH_EVERYTHING, direction);
11275 if (IN_LEV_FIELD(hitx, hity))
11277 int opposite_direction = MV_DIR_OPPOSITE(direction);
11278 int hitting_side = direction;
11279 int touched_side = opposite_direction;
11281 int touched_element = MovingOrBlocked2Element(hitx, hity);
11284 boolean object_hit = (!IS_MOVING(hitx, hity) ||
11285 MovDir[hitx][hity] != direction ||
11286 ABS(MovPos[hitx][hity]) <= TILEY / 2);
11295 CheckElementChangeBySide(hitx, hity, touched_element, hitting_element,
11296 CE_SMASHED_BY_SOMETHING, opposite_direction);
11298 CheckElementChangeBySide(x, y, hitting_element, touched_element,
11299 CE_OTHER_IS_SMASHING, touched_side);
11301 CheckElementChangeBySide(hitx, hity, touched_element, hitting_element,
11302 CE_OTHER_GETS_SMASHED, hitting_side);
11308 void TestIfGoodThingHitsBadThing(int good_x, int good_y, int good_move_dir)
11310 int i, kill_x = -1, kill_y = -1;
11312 int bad_element = -1;
11313 static int test_xy[4][2] =
11320 static int test_dir[4] =
11328 for (i = 0; i < NUM_DIRECTIONS; i++)
11330 int test_x, test_y, test_move_dir, test_element;
11332 test_x = good_x + test_xy[i][0];
11333 test_y = good_y + test_xy[i][1];
11335 if (!IN_LEV_FIELD(test_x, test_y))
11339 (IS_MOVING(test_x, test_y) ? MovDir[test_x][test_y] : MV_NONE);
11341 test_element = MovingOrBlocked2ElementIfNotLeaving(test_x, test_y);
11343 /* 1st case: good thing is moving towards DONT_RUN_INTO style bad thing;
11344 2nd case: DONT_TOUCH style bad thing does not move away from good thing
11346 if ((DONT_RUN_INTO(test_element) && good_move_dir == test_dir[i]) ||
11347 (DONT_TOUCH(test_element) && test_move_dir != test_dir[i]))
11351 bad_element = test_element;
11357 if (kill_x != -1 || kill_y != -1)
11359 if (IS_PLAYER(good_x, good_y))
11361 struct PlayerInfo *player = PLAYERINFO(good_x, good_y);
11363 if (player->shield_deadly_time_left > 0 &&
11364 !IS_INDESTRUCTIBLE(bad_element))
11365 Bang(kill_x, kill_y);
11366 else if (!PLAYER_ENEMY_PROTECTED(good_x, good_y))
11367 KillPlayer(player);
11370 Bang(good_x, good_y);
11374 void TestIfBadThingHitsGoodThing(int bad_x, int bad_y, int bad_move_dir)
11376 int i, kill_x = -1, kill_y = -1;
11377 int bad_element = Feld[bad_x][bad_y];
11378 static int test_xy[4][2] =
11385 static int touch_dir[4] =
11387 MV_LEFT | MV_RIGHT,
11392 static int test_dir[4] =
11400 if (bad_element == EL_EXPLOSION) /* skip just exploding bad things */
11403 for (i = 0; i < NUM_DIRECTIONS; i++)
11405 int test_x, test_y, test_move_dir, test_element;
11407 test_x = bad_x + test_xy[i][0];
11408 test_y = bad_y + test_xy[i][1];
11409 if (!IN_LEV_FIELD(test_x, test_y))
11413 (IS_MOVING(test_x, test_y) ? MovDir[test_x][test_y] : MV_NONE);
11415 test_element = Feld[test_x][test_y];
11417 /* 1st case: good thing is moving towards DONT_RUN_INTO style bad thing;
11418 2nd case: DONT_TOUCH style bad thing does not move away from good thing
11420 if ((DONT_RUN_INTO(bad_element) && bad_move_dir == test_dir[i]) ||
11421 (DONT_TOUCH(bad_element) && test_move_dir != test_dir[i]))
11423 /* good thing is player or penguin that does not move away */
11424 if (IS_PLAYER(test_x, test_y))
11426 struct PlayerInfo *player = PLAYERINFO(test_x, test_y);
11428 if (bad_element == EL_ROBOT && player->is_moving)
11429 continue; /* robot does not kill player if he is moving */
11431 if (game.engine_version >= VERSION_IDENT(3,0,7,0))
11433 if (player->MovPos != 0 && !(player->MovDir & touch_dir[i]))
11434 continue; /* center and border element do not touch */
11441 else if (test_element == EL_PENGUIN)
11450 if (kill_x != -1 || kill_y != -1)
11452 if (IS_PLAYER(kill_x, kill_y))
11454 struct PlayerInfo *player = PLAYERINFO(kill_x, kill_y);
11456 if (player->shield_deadly_time_left > 0 &&
11457 !IS_INDESTRUCTIBLE(bad_element))
11458 Bang(bad_x, bad_y);
11459 else if (!PLAYER_ENEMY_PROTECTED(kill_x, kill_y))
11460 KillPlayer(player);
11463 Bang(kill_x, kill_y);
11467 void TestIfPlayerTouchesBadThing(int x, int y)
11469 TestIfGoodThingHitsBadThing(x, y, MV_NONE);
11472 void TestIfPlayerRunsIntoBadThing(int x, int y, int move_dir)
11474 TestIfGoodThingHitsBadThing(x, y, move_dir);
11477 void TestIfBadThingTouchesPlayer(int x, int y)
11479 TestIfBadThingHitsGoodThing(x, y, MV_NONE);
11482 void TestIfBadThingRunsIntoPlayer(int x, int y, int move_dir)
11484 TestIfBadThingHitsGoodThing(x, y, move_dir);
11487 void TestIfFriendTouchesBadThing(int x, int y)
11489 TestIfGoodThingHitsBadThing(x, y, MV_NONE);
11492 void TestIfBadThingTouchesFriend(int x, int y)
11494 TestIfBadThingHitsGoodThing(x, y, MV_NONE);
11497 void TestIfBadThingTouchesOtherBadThing(int bad_x, int bad_y)
11499 int i, kill_x = bad_x, kill_y = bad_y;
11500 static int xy[4][2] =
11508 for (i = 0; i < NUM_DIRECTIONS; i++)
11512 x = bad_x + xy[i][0];
11513 y = bad_y + xy[i][1];
11514 if (!IN_LEV_FIELD(x, y))
11517 element = Feld[x][y];
11518 if (IS_AMOEBOID(element) || element == EL_GAME_OF_LIFE ||
11519 element == EL_AMOEBA_GROWING || element == EL_AMOEBA_DROP)
11527 if (kill_x != bad_x || kill_y != bad_y)
11528 Bang(bad_x, bad_y);
11531 void KillPlayer(struct PlayerInfo *player)
11533 int jx = player->jx, jy = player->jy;
11535 if (!player->active)
11538 /* remove accessible field at the player's position */
11539 Feld[jx][jy] = EL_EMPTY;
11541 /* deactivate shield (else Bang()/Explode() would not work right) */
11542 player->shield_normal_time_left = 0;
11543 player->shield_deadly_time_left = 0;
11546 BuryPlayer(player);
11549 static void KillPlayerUnlessEnemyProtected(int x, int y)
11551 if (!PLAYER_ENEMY_PROTECTED(x, y))
11552 KillPlayer(PLAYERINFO(x, y));
11555 static void KillPlayerUnlessExplosionProtected(int x, int y)
11557 if (!PLAYER_EXPLOSION_PROTECTED(x, y))
11558 KillPlayer(PLAYERINFO(x, y));
11561 void BuryPlayer(struct PlayerInfo *player)
11563 int jx = player->jx, jy = player->jy;
11565 if (!player->active)
11568 PlayLevelSoundElementAction(jx, jy, player->artwork_element, ACTION_DYING);
11569 PlayLevelSound(jx, jy, SND_GAME_LOSING);
11571 player->GameOver = TRUE;
11572 RemovePlayer(player);
11575 void RemovePlayer(struct PlayerInfo *player)
11577 int jx = player->jx, jy = player->jy;
11578 int i, found = FALSE;
11580 player->present = FALSE;
11581 player->active = FALSE;
11583 if (!ExplodeField[jx][jy])
11584 StorePlayer[jx][jy] = 0;
11586 if (player->is_moving)
11587 DrawLevelField(player->last_jx, player->last_jy);
11589 for (i = 0; i < MAX_PLAYERS; i++)
11590 if (stored_player[i].active)
11594 AllPlayersGone = TRUE;
11600 #if USE_NEW_SNAP_DELAY
11601 static void setFieldForSnapping(int x, int y, int element, int direction)
11603 struct ElementInfo *ei = &element_info[element];
11604 int direction_bit = MV_DIR_TO_BIT(direction);
11605 int graphic_snapping = ei->direction_graphic[ACTION_SNAPPING][direction_bit];
11606 int action = (graphic_snapping != IMG_EMPTY_SPACE ? ACTION_SNAPPING :
11607 IS_DIGGABLE(element) ? ACTION_DIGGING : ACTION_COLLECTING);
11609 Feld[x][y] = EL_ELEMENT_SNAPPING;
11610 MovDelay[x][y] = MOVE_DELAY_NORMAL_SPEED + 1 - 1;
11612 ResetGfxAnimation(x, y);
11614 GfxElement[x][y] = element;
11615 GfxAction[x][y] = action;
11616 GfxDir[x][y] = direction;
11617 GfxFrame[x][y] = -1;
11622 =============================================================================
11623 checkDiagonalPushing()
11624 -----------------------------------------------------------------------------
11625 check if diagonal input device direction results in pushing of object
11626 (by checking if the alternative direction is walkable, diggable, ...)
11627 =============================================================================
11630 static boolean checkDiagonalPushing(struct PlayerInfo *player,
11631 int x, int y, int real_dx, int real_dy)
11633 int jx, jy, dx, dy, xx, yy;
11635 if (real_dx == 0 || real_dy == 0) /* no diagonal direction => push */
11638 /* diagonal direction: check alternative direction */
11643 xx = jx + (dx == 0 ? real_dx : 0);
11644 yy = jy + (dy == 0 ? real_dy : 0);
11646 return (!IN_LEV_FIELD(xx, yy) || IS_SOLID_FOR_PUSHING(Feld[xx][yy]));
11650 =============================================================================
11652 -----------------------------------------------------------------------------
11653 x, y: field next to player (non-diagonal) to try to dig to
11654 real_dx, real_dy: direction as read from input device (can be diagonal)
11655 =============================================================================
11658 int DigField(struct PlayerInfo *player,
11659 int oldx, int oldy, int x, int y,
11660 int real_dx, int real_dy, int mode)
11662 boolean is_player = (IS_PLAYER(oldx, oldy) || mode != DF_DIG);
11663 boolean player_was_pushing = player->is_pushing;
11664 boolean player_can_move = (!player->cannot_move && mode != DF_SNAP);
11665 boolean player_can_move_or_snap = (!player->cannot_move || mode == DF_SNAP);
11666 int jx = oldx, jy = oldy;
11667 int dx = x - jx, dy = y - jy;
11668 int nextx = x + dx, nexty = y + dy;
11669 int move_direction = (dx == -1 ? MV_LEFT :
11670 dx == +1 ? MV_RIGHT :
11672 dy == +1 ? MV_DOWN : MV_NONE);
11673 int opposite_direction = MV_DIR_OPPOSITE(move_direction);
11674 int dig_side = MV_DIR_OPPOSITE(move_direction);
11675 int old_element = Feld[jx][jy];
11676 #if USE_FIXED_DONT_RUN_INTO
11677 int element = MovingOrBlocked2ElementIfNotLeaving(x, y);
11683 if (is_player) /* function can also be called by EL_PENGUIN */
11685 if (player->MovPos == 0)
11687 player->is_digging = FALSE;
11688 player->is_collecting = FALSE;
11691 if (player->MovPos == 0) /* last pushing move finished */
11692 player->is_pushing = FALSE;
11694 if (mode == DF_NO_PUSH) /* player just stopped pushing */
11696 player->is_switching = FALSE;
11697 player->push_delay = -1;
11699 return MP_NO_ACTION;
11703 #if !USE_FIXED_DONT_RUN_INTO
11704 if (IS_MOVING(x, y) || IS_PLAYER(x, y))
11705 return MP_NO_ACTION;
11708 if (IS_TUBE(Back[jx][jy]) && game.engine_version >= VERSION_IDENT(2,2,0,0))
11709 old_element = Back[jx][jy];
11711 /* in case of element dropped at player position, check background */
11712 else if (Back[jx][jy] != EL_EMPTY &&
11713 game.engine_version >= VERSION_IDENT(2,2,0,0))
11714 old_element = Back[jx][jy];
11716 /* checking here causes player to move into acid even if the current field
11717 cannot be left to that direction */
11719 #if USE_FIXED_DONT_RUN_INTO
11720 if (player_can_move && DONT_RUN_INTO(element))
11722 if (element == EL_ACID && dx == 0 && dy == 1)
11725 Feld[jx][jy] = EL_PLAYER_1;
11726 InitMovingField(jx, jy, MV_DOWN);
11727 Store[jx][jy] = EL_ACID;
11728 ContinueMoving(jx, jy);
11729 BuryPlayer(player);
11732 TestIfPlayerRunsIntoBadThing(jx, jy, player->MovDir);
11734 return MP_DONT_RUN_INTO;
11739 #if 1 /* ------------------------------ NEW ------------------------------ */
11741 if (IS_WALKABLE(old_element) && !ACCESS_FROM(old_element, move_direction))
11742 return MP_NO_ACTION; /* field has no opening in this direction */
11744 if (IS_PASSABLE(old_element) && !ACCESS_FROM(old_element,opposite_direction))
11745 return MP_NO_ACTION; /* field has no opening in this direction */
11747 #if USE_FIXED_DONT_RUN_INTO
11748 if (player_can_move && element == EL_ACID && move_direction == MV_DOWN)
11752 Feld[jx][jy] = player->artwork_element;
11754 Feld[jx][jy] = EL_PLAYER_1;
11756 InitMovingField(jx, jy, MV_DOWN);
11757 Store[jx][jy] = EL_ACID;
11758 ContinueMoving(jx, jy);
11759 BuryPlayer(player);
11761 return MP_DONT_RUN_INTO;
11765 #if USE_FIXED_DONT_RUN_INTO
11766 if (player_can_move && DONT_RUN_INTO(element))
11768 TestIfPlayerRunsIntoBadThing(jx, jy, player->MovDir);
11770 return MP_DONT_RUN_INTO;
11774 #else /* ------------------------------ OLD ------------------------------ */
11777 #if USE_FIXED_DONT_RUN_INTO
11778 if (player_can_move && DONT_RUN_INTO(element))
11780 TestIfPlayerRunsIntoBadThing(jx, jy, player->MovDir);
11782 return MP_DONT_RUN_INTO;
11787 if (IS_WALKABLE(old_element) && !ACCESS_FROM(old_element, move_direction))
11788 return MP_NO_ACTION; /* field has no opening in this direction */
11790 if (IS_PASSABLE(old_element) && !ACCESS_FROM(old_element,opposite_direction))
11791 return MP_NO_ACTION; /* field has no opening in this direction */
11793 /* checking here causes player to explode when moving into acid */
11795 #if USE_FIXED_DONT_RUN_INTO
11796 if (player_can_move && element == EL_ACID && move_direction == MV_DOWN)
11799 Feld[jx][jy] = EL_PLAYER_1;
11800 InitMovingField(jx, jy, MV_DOWN);
11801 Store[jx][jy] = EL_ACID;
11802 ContinueMoving(jx, jy);
11803 BuryPlayer(player);
11805 return MP_DONT_RUN_INTO;
11810 #endif /* ------------------------------ END ------------------------------ */
11813 #if USE_FIXED_DONT_RUN_INTO
11814 if (player_can_move && DONT_RUN_INTO(element))
11816 if (element == EL_ACID && dx == 0 && dy == 1)
11819 Feld[jx][jy] = EL_PLAYER_1;
11820 InitMovingField(jx, jy, MV_DOWN);
11821 Store[jx][jy] = EL_ACID;
11822 ContinueMoving(jx, jy);
11823 BuryPlayer(player);
11826 TestIfPlayerRunsIntoBadThing(jx, jy, player->MovDir);
11828 return MP_DONT_RUN_INTO;
11833 #if USE_FIXED_DONT_RUN_INTO
11834 if (IS_MOVING(x, y) || IS_PLAYER(x, y))
11835 return MP_NO_ACTION;
11838 #if !USE_FIXED_DONT_RUN_INTO
11839 element = Feld[x][y];
11842 collect_count = element_info[element].collect_count_initial;
11844 if (!is_player && !IS_COLLECTIBLE(element)) /* penguin cannot collect it */
11845 return MP_NO_ACTION;
11847 if (game.engine_version < VERSION_IDENT(2,2,0,0))
11848 player_can_move = player_can_move_or_snap;
11850 if (mode == DF_SNAP && !IS_SNAPPABLE(element) &&
11851 game.engine_version >= VERSION_IDENT(2,2,0,0))
11853 CheckElementChangeByPlayer(x, y, element, CE_SNAPPED_BY_PLAYER,
11854 player->index_bit, dig_side);
11855 CheckTriggeredElementChangeByPlayer(x, y, element, CE_PLAYER_SNAPS_X,
11856 player->index_bit, dig_side);
11858 if (Feld[x][y] != element) /* field changed by snapping */
11861 return MP_NO_ACTION;
11864 #if USE_PLAYER_GRAVITY
11865 if (player->gravity && is_player && !player->is_auto_moving &&
11866 canFallDown(player) && move_direction != MV_DOWN &&
11867 !canMoveToValidFieldWithGravity(jx, jy, move_direction))
11868 return MP_NO_ACTION; /* player cannot walk here due to gravity */
11870 if (game.gravity && is_player && !player->is_auto_moving &&
11871 canFallDown(player) && move_direction != MV_DOWN &&
11872 !canMoveToValidFieldWithGravity(jx, jy, move_direction))
11873 return MP_NO_ACTION; /* player cannot walk here due to gravity */
11876 if (player_can_move &&
11877 IS_WALKABLE(element) && ACCESS_FROM(element, opposite_direction))
11879 int sound_element = SND_ELEMENT(element);
11880 int sound_action = ACTION_WALKING;
11882 if (IS_RND_GATE(element))
11884 if (!player->key[RND_GATE_NR(element)])
11885 return MP_NO_ACTION;
11887 else if (IS_RND_GATE_GRAY(element))
11889 if (!player->key[RND_GATE_GRAY_NR(element)])
11890 return MP_NO_ACTION;
11892 else if (IS_RND_GATE_GRAY_ACTIVE(element))
11894 if (!player->key[RND_GATE_GRAY_ACTIVE_NR(element)])
11895 return MP_NO_ACTION;
11897 else if (element == EL_EXIT_OPEN ||
11898 element == EL_SP_EXIT_OPEN ||
11899 element == EL_SP_EXIT_OPENING)
11901 sound_action = ACTION_PASSING; /* player is passing exit */
11903 else if (element == EL_EMPTY)
11905 sound_action = ACTION_MOVING; /* nothing to walk on */
11908 /* play sound from background or player, whatever is available */
11909 if (element_info[sound_element].sound[sound_action] != SND_UNDEFINED)
11910 PlayLevelSoundElementAction(x, y, sound_element, sound_action);
11912 PlayLevelSoundElementAction(x, y, player->artwork_element, sound_action);
11914 else if (player_can_move &&
11915 IS_PASSABLE(element) && canPassField(x, y, move_direction))
11917 if (!ACCESS_FROM(element, opposite_direction))
11918 return MP_NO_ACTION; /* field not accessible from this direction */
11920 if (CAN_MOVE(element)) /* only fixed elements can be passed! */
11921 return MP_NO_ACTION;
11923 if (IS_EM_GATE(element))
11925 if (!player->key[EM_GATE_NR(element)])
11926 return MP_NO_ACTION;
11928 else if (IS_EM_GATE_GRAY(element))
11930 if (!player->key[EM_GATE_GRAY_NR(element)])
11931 return MP_NO_ACTION;
11933 else if (IS_EM_GATE_GRAY_ACTIVE(element))
11935 if (!player->key[EM_GATE_GRAY_ACTIVE_NR(element)])
11936 return MP_NO_ACTION;
11938 else if (IS_EMC_GATE(element))
11940 if (!player->key[EMC_GATE_NR(element)])
11941 return MP_NO_ACTION;
11943 else if (IS_EMC_GATE_GRAY(element))
11945 if (!player->key[EMC_GATE_GRAY_NR(element)])
11946 return MP_NO_ACTION;
11948 else if (IS_EMC_GATE_GRAY_ACTIVE(element))
11950 if (!player->key[EMC_GATE_GRAY_ACTIVE_NR(element)])
11951 return MP_NO_ACTION;
11953 else if (IS_SP_PORT(element))
11955 if (element == EL_SP_GRAVITY_PORT_LEFT ||
11956 element == EL_SP_GRAVITY_PORT_RIGHT ||
11957 element == EL_SP_GRAVITY_PORT_UP ||
11958 element == EL_SP_GRAVITY_PORT_DOWN)
11959 #if USE_PLAYER_GRAVITY
11960 player->gravity = !player->gravity;
11962 game.gravity = !game.gravity;
11964 else if (element == EL_SP_GRAVITY_ON_PORT_LEFT ||
11965 element == EL_SP_GRAVITY_ON_PORT_RIGHT ||
11966 element == EL_SP_GRAVITY_ON_PORT_UP ||
11967 element == EL_SP_GRAVITY_ON_PORT_DOWN)
11968 #if USE_PLAYER_GRAVITY
11969 player->gravity = TRUE;
11971 game.gravity = TRUE;
11973 else if (element == EL_SP_GRAVITY_OFF_PORT_LEFT ||
11974 element == EL_SP_GRAVITY_OFF_PORT_RIGHT ||
11975 element == EL_SP_GRAVITY_OFF_PORT_UP ||
11976 element == EL_SP_GRAVITY_OFF_PORT_DOWN)
11977 #if USE_PLAYER_GRAVITY
11978 player->gravity = FALSE;
11980 game.gravity = FALSE;
11984 /* automatically move to the next field with double speed */
11985 player->programmed_action = move_direction;
11987 if (player->move_delay_reset_counter == 0)
11989 player->move_delay_reset_counter = 2; /* two double speed steps */
11991 DOUBLE_PLAYER_SPEED(player);
11994 PlayLevelSoundAction(x, y, ACTION_PASSING);
11996 else if (player_can_move_or_snap && IS_DIGGABLE(element))
12000 if (mode != DF_SNAP)
12002 GfxElement[x][y] = GFX_ELEMENT(element);
12003 player->is_digging = TRUE;
12006 PlayLevelSoundElementAction(x, y, element, ACTION_DIGGING);
12008 CheckTriggeredElementChangeByPlayer(x, y, element, CE_PLAYER_DIGS_X,
12009 player->index_bit, dig_side);
12011 if (mode == DF_SNAP)
12013 #if USE_NEW_SNAP_DELAY
12014 if (level.block_snap_field)
12015 setFieldForSnapping(x, y, element, move_direction);
12017 TestIfElementTouchesCustomElement(x, y); /* for empty space */
12019 TestIfElementTouchesCustomElement(x, y); /* for empty space */
12022 CheckTriggeredElementChangeByPlayer(x, y, element, CE_PLAYER_SNAPS_X,
12023 player->index_bit, dig_side);
12026 else if (player_can_move_or_snap && IS_COLLECTIBLE(element))
12030 if (is_player && mode != DF_SNAP)
12032 GfxElement[x][y] = element;
12033 player->is_collecting = TRUE;
12036 if (element == EL_SPEED_PILL)
12038 player->move_delay_value = MOVE_DELAY_HIGH_SPEED;
12040 else if (element == EL_EXTRA_TIME && level.time > 0)
12042 TimeLeft += level.extra_time;
12043 DrawGameValue_Time(TimeLeft);
12045 else if (element == EL_SHIELD_NORMAL || element == EL_SHIELD_DEADLY)
12047 player->shield_normal_time_left += level.shield_normal_time;
12048 if (element == EL_SHIELD_DEADLY)
12049 player->shield_deadly_time_left += level.shield_deadly_time;
12051 else if (element == EL_DYNAMITE ||
12052 element == EL_EM_DYNAMITE ||
12053 element == EL_SP_DISK_RED)
12055 if (player->inventory_size < MAX_INVENTORY_SIZE)
12056 player->inventory_element[player->inventory_size++] = element;
12059 DrawGameDoorValues();
12061 DrawGameValue_Dynamite(local_player->inventory_size);
12064 else if (element == EL_DYNABOMB_INCREASE_NUMBER)
12066 player->dynabomb_count++;
12067 player->dynabombs_left++;
12069 else if (element == EL_DYNABOMB_INCREASE_SIZE)
12071 player->dynabomb_size++;
12073 else if (element == EL_DYNABOMB_INCREASE_POWER)
12075 player->dynabomb_xl = TRUE;
12077 else if (IS_KEY(element))
12079 player->key[KEY_NR(element)] = TRUE;
12082 DrawGameDoorValues();
12084 DrawGameValue_Keys(player->key);
12087 redraw_mask |= REDRAW_DOOR_1;
12089 else if (IS_ENVELOPE(element))
12091 player->show_envelope = element;
12093 else if (element == EL_EMC_LENSES)
12095 game.lenses_time_left = level.lenses_time * FRAMES_PER_SECOND;
12097 RedrawAllInvisibleElementsForLenses();
12099 else if (element == EL_EMC_MAGNIFIER)
12101 game.magnify_time_left = level.magnify_time * FRAMES_PER_SECOND;
12103 RedrawAllInvisibleElementsForMagnifier();
12105 else if (IS_DROPPABLE(element) ||
12106 IS_THROWABLE(element)) /* can be collected and dropped */
12110 if (collect_count == 0)
12111 player->inventory_infinite_element = element;
12113 for (i = 0; i < collect_count; i++)
12114 if (player->inventory_size < MAX_INVENTORY_SIZE)
12115 player->inventory_element[player->inventory_size++] = element;
12118 DrawGameDoorValues();
12120 DrawGameValue_Dynamite(local_player->inventory_size);
12123 else if (collect_count > 0)
12125 local_player->gems_still_needed -= collect_count;
12126 if (local_player->gems_still_needed < 0)
12127 local_player->gems_still_needed = 0;
12129 DrawGameValue_Emeralds(local_player->gems_still_needed);
12132 RaiseScoreElement(element);
12133 PlayLevelSoundElementAction(x, y, element, ACTION_COLLECTING);
12136 CheckTriggeredElementChangeByPlayer(x, y, element, CE_PLAYER_COLLECTS_X,
12137 player->index_bit, dig_side);
12139 if (mode == DF_SNAP)
12141 #if USE_NEW_SNAP_DELAY
12142 if (level.block_snap_field)
12143 setFieldForSnapping(x, y, element, move_direction);
12145 TestIfElementTouchesCustomElement(x, y); /* for empty space */
12147 TestIfElementTouchesCustomElement(x, y); /* for empty space */
12150 CheckTriggeredElementChangeByPlayer(x, y, element, CE_PLAYER_SNAPS_X,
12151 player->index_bit, dig_side);
12154 else if (player_can_move_or_snap && IS_PUSHABLE(element))
12156 if (mode == DF_SNAP && element != EL_BD_ROCK)
12157 return MP_NO_ACTION;
12159 if (CAN_FALL(element) && dy)
12160 return MP_NO_ACTION;
12162 if (CAN_FALL(element) && IN_LEV_FIELD(x, y + 1) && IS_FREE(x, y + 1) &&
12163 !(element == EL_SPRING && level.use_spring_bug))
12164 return MP_NO_ACTION;
12166 if (CAN_MOVE(element) && GET_MAX_MOVE_DELAY(element) == 0 &&
12167 ((move_direction & MV_VERTICAL &&
12168 ((element_info[element].move_pattern & MV_LEFT &&
12169 IN_LEV_FIELD(x - 1, y) && IS_FREE(x - 1, y)) ||
12170 (element_info[element].move_pattern & MV_RIGHT &&
12171 IN_LEV_FIELD(x + 1, y) && IS_FREE(x + 1, y)))) ||
12172 (move_direction & MV_HORIZONTAL &&
12173 ((element_info[element].move_pattern & MV_UP &&
12174 IN_LEV_FIELD(x, y - 1) && IS_FREE(x, y - 1)) ||
12175 (element_info[element].move_pattern & MV_DOWN &&
12176 IN_LEV_FIELD(x, y + 1) && IS_FREE(x, y + 1))))))
12177 return MP_NO_ACTION;
12179 /* do not push elements already moving away faster than player */
12180 if (CAN_MOVE(element) && MovDir[x][y] == move_direction &&
12181 ABS(getElementMoveStepsize(x, y)) > MOVE_STEPSIZE_NORMAL)
12182 return MP_NO_ACTION;
12184 if (game.engine_version >= VERSION_IDENT(3,1,0,0))
12186 if (player->push_delay_value == -1 || !player_was_pushing)
12187 player->push_delay_value = GET_NEW_PUSH_DELAY(element);
12189 else if (game.engine_version >= VERSION_IDENT(3,0,7,1))
12191 if (player->push_delay_value == -1)
12192 player->push_delay_value = GET_NEW_PUSH_DELAY(element);
12194 else if (game.engine_version >= VERSION_IDENT(2,2,0,7))
12196 if (!player->is_pushing)
12197 player->push_delay_value = GET_NEW_PUSH_DELAY(element);
12200 player->is_pushing = TRUE;
12201 player->is_active = TRUE;
12203 if (!(IN_LEV_FIELD(nextx, nexty) &&
12204 (IS_FREE(nextx, nexty) ||
12205 (Feld[nextx][nexty] == EL_SOKOBAN_FIELD_EMPTY &&
12206 IS_SB_ELEMENT(element)))))
12207 return MP_NO_ACTION;
12209 if (!checkDiagonalPushing(player, x, y, real_dx, real_dy))
12210 return MP_NO_ACTION;
12212 if (player->push_delay == -1) /* new pushing; restart delay */
12213 player->push_delay = 0;
12215 if (player->push_delay < player->push_delay_value &&
12216 !(tape.playing && tape.file_version < FILE_VERSION_2_0) &&
12217 element != EL_SPRING && element != EL_BALLOON)
12219 /* make sure that there is no move delay before next try to push */
12220 if (game.engine_version >= VERSION_IDENT(3,0,7,1))
12221 player->move_delay = 0;
12223 return MP_NO_ACTION;
12226 if (IS_SB_ELEMENT(element))
12228 if (element == EL_SOKOBAN_FIELD_FULL)
12230 Back[x][y] = EL_SOKOBAN_FIELD_EMPTY;
12231 local_player->sokobanfields_still_needed++;
12234 if (Feld[nextx][nexty] == EL_SOKOBAN_FIELD_EMPTY)
12236 Back[nextx][nexty] = EL_SOKOBAN_FIELD_EMPTY;
12237 local_player->sokobanfields_still_needed--;
12240 Feld[x][y] = EL_SOKOBAN_OBJECT;
12242 if (Back[x][y] == Back[nextx][nexty])
12243 PlayLevelSoundAction(x, y, ACTION_PUSHING);
12244 else if (Back[x][y] != 0)
12245 PlayLevelSoundElementAction(x, y, EL_SOKOBAN_FIELD_FULL,
12248 PlayLevelSoundElementAction(nextx, nexty, EL_SOKOBAN_FIELD_EMPTY,
12251 if (local_player->sokobanfields_still_needed == 0 &&
12252 game.emulation == EMU_SOKOBAN)
12254 player->LevelSolved = player->GameOver = TRUE;
12255 PlayLevelSound(x, y, SND_GAME_SOKOBAN_SOLVING);
12259 PlayLevelSoundElementAction(x, y, element, ACTION_PUSHING);
12261 InitMovingField(x, y, move_direction);
12262 GfxAction[x][y] = ACTION_PUSHING;
12264 if (mode == DF_SNAP)
12265 ContinueMoving(x, y);
12267 MovPos[x][y] = (dx != 0 ? dx : dy);
12269 Pushed[x][y] = TRUE;
12270 Pushed[nextx][nexty] = TRUE;
12272 if (game.engine_version < VERSION_IDENT(2,2,0,7))
12273 player->push_delay_value = GET_NEW_PUSH_DELAY(element);
12275 player->push_delay_value = -1; /* get new value later */
12277 /* check for element change _after_ element has been pushed */
12278 if (game.use_change_when_pushing_bug)
12280 CheckElementChangeByPlayer(x, y, element, CE_PUSHED_BY_PLAYER,
12281 player->index_bit, dig_side);
12282 CheckTriggeredElementChangeByPlayer(x, y, element, CE_PLAYER_PUSHES_X,
12283 player->index_bit, dig_side);
12286 else if (IS_SWITCHABLE(element))
12288 if (PLAYER_SWITCHING(player, x, y))
12290 CheckTriggeredElementChangeByPlayer(x, y, element, CE_PLAYER_PRESSES_X,
12291 player->index_bit, dig_side);
12296 player->is_switching = TRUE;
12297 player->switch_x = x;
12298 player->switch_y = y;
12300 PlayLevelSoundElementAction(x, y, element, ACTION_ACTIVATING);
12302 if (element == EL_ROBOT_WHEEL)
12304 Feld[x][y] = EL_ROBOT_WHEEL_ACTIVE;
12308 DrawLevelField(x, y);
12310 else if (element == EL_SP_TERMINAL)
12315 SCAN_PLAYFIELD(xx, yy)
12317 for (yy = 0; yy < lev_fieldy; yy++) for (xx = 0; xx < lev_fieldx; xx++)
12320 if (Feld[xx][yy] == EL_SP_DISK_YELLOW)
12322 else if (Feld[xx][yy] == EL_SP_TERMINAL)
12323 Feld[xx][yy] = EL_SP_TERMINAL_ACTIVE;
12326 else if (IS_BELT_SWITCH(element))
12328 ToggleBeltSwitch(x, y);
12330 else if (element == EL_SWITCHGATE_SWITCH_UP ||
12331 element == EL_SWITCHGATE_SWITCH_DOWN)
12333 ToggleSwitchgateSwitch(x, y);
12335 else if (element == EL_LIGHT_SWITCH ||
12336 element == EL_LIGHT_SWITCH_ACTIVE)
12338 ToggleLightSwitch(x, y);
12340 else if (element == EL_TIMEGATE_SWITCH)
12342 ActivateTimegateSwitch(x, y);
12344 else if (element == EL_BALLOON_SWITCH_LEFT ||
12345 element == EL_BALLOON_SWITCH_RIGHT ||
12346 element == EL_BALLOON_SWITCH_UP ||
12347 element == EL_BALLOON_SWITCH_DOWN ||
12348 element == EL_BALLOON_SWITCH_NONE ||
12349 element == EL_BALLOON_SWITCH_ANY)
12351 game.wind_direction = (element == EL_BALLOON_SWITCH_LEFT ? MV_LEFT :
12352 element == EL_BALLOON_SWITCH_RIGHT ? MV_RIGHT :
12353 element == EL_BALLOON_SWITCH_UP ? MV_UP :
12354 element == EL_BALLOON_SWITCH_DOWN ? MV_DOWN :
12355 element == EL_BALLOON_SWITCH_NONE ? MV_NONE :
12358 else if (element == EL_LAMP)
12360 Feld[x][y] = EL_LAMP_ACTIVE;
12361 local_player->lights_still_needed--;
12363 ResetGfxAnimation(x, y);
12364 DrawLevelField(x, y);
12366 else if (element == EL_TIME_ORB_FULL)
12368 Feld[x][y] = EL_TIME_ORB_EMPTY;
12370 if (level.time > 0 || level.use_time_orb_bug)
12372 TimeLeft += level.time_orb_time;
12373 DrawGameValue_Time(TimeLeft);
12376 ResetGfxAnimation(x, y);
12377 DrawLevelField(x, y);
12379 else if (element == EL_EMC_MAGIC_BALL_SWITCH ||
12380 element == EL_EMC_MAGIC_BALL_SWITCH_ACTIVE)
12384 game.ball_state = !game.ball_state;
12387 SCAN_PLAYFIELD(xx, yy)
12389 for (yy = 0; yy < lev_fieldy; yy++) for (xx = 0; xx < lev_fieldx; xx++)
12392 int e = Feld[xx][yy];
12394 if (game.ball_state)
12396 if (e == EL_EMC_MAGIC_BALL)
12397 CreateField(xx, yy, EL_EMC_MAGIC_BALL_ACTIVE);
12398 else if (e == EL_EMC_MAGIC_BALL_SWITCH)
12399 CreateField(xx, yy, EL_EMC_MAGIC_BALL_SWITCH_ACTIVE);
12403 if (e == EL_EMC_MAGIC_BALL_ACTIVE)
12404 CreateField(xx, yy, EL_EMC_MAGIC_BALL);
12405 else if (e == EL_EMC_MAGIC_BALL_SWITCH_ACTIVE)
12406 CreateField(xx, yy, EL_EMC_MAGIC_BALL_SWITCH);
12411 CheckTriggeredElementChangeByPlayer(x, y, element, CE_SWITCH_OF_X,
12412 player->index_bit, dig_side);
12414 CheckTriggeredElementChangeByPlayer(x, y, element, CE_PLAYER_SWITCHES_X,
12415 player->index_bit, dig_side);
12417 CheckTriggeredElementChangeByPlayer(x, y, element, CE_PLAYER_PRESSES_X,
12418 player->index_bit, dig_side);
12424 if (!PLAYER_SWITCHING(player, x, y))
12426 player->is_switching = TRUE;
12427 player->switch_x = x;
12428 player->switch_y = y;
12430 CheckElementChangeByPlayer(x, y, element, CE_SWITCHED,
12431 player->index_bit, dig_side);
12432 CheckTriggeredElementChangeByPlayer(x, y, element, CE_SWITCH_OF_X,
12433 player->index_bit, dig_side);
12435 CheckElementChangeByPlayer(x, y, element, CE_SWITCHED_BY_PLAYER,
12436 player->index_bit, dig_side);
12437 CheckTriggeredElementChangeByPlayer(x, y, element, CE_PLAYER_SWITCHES_X,
12438 player->index_bit, dig_side);
12441 CheckElementChangeByPlayer(x, y, element, CE_PRESSED_BY_PLAYER,
12442 player->index_bit, dig_side);
12443 CheckTriggeredElementChangeByPlayer(x, y, element, CE_PLAYER_PRESSES_X,
12444 player->index_bit, dig_side);
12446 return MP_NO_ACTION;
12449 player->push_delay = -1;
12451 if (is_player) /* function can also be called by EL_PENGUIN */
12453 if (Feld[x][y] != element) /* really digged/collected something */
12455 player->is_collecting = !player->is_digging;
12456 player->is_active = TRUE;
12463 boolean SnapField(struct PlayerInfo *player, int dx, int dy)
12465 int jx = player->jx, jy = player->jy;
12466 int x = jx + dx, y = jy + dy;
12467 int snap_direction = (dx == -1 ? MV_LEFT :
12468 dx == +1 ? MV_RIGHT :
12470 dy == +1 ? MV_DOWN : MV_NONE);
12471 boolean can_continue_snapping = (level.continuous_snapping &&
12472 WasJustFalling[x][y] < CHECK_DELAY_FALLING);
12474 if (player->MovPos != 0 && game.engine_version >= VERSION_IDENT(2,2,0,0))
12477 if (!player->active || !IN_LEV_FIELD(x, y))
12485 if (player->MovPos == 0)
12486 player->is_pushing = FALSE;
12488 player->is_snapping = FALSE;
12490 if (player->MovPos == 0)
12492 player->is_moving = FALSE;
12493 player->is_digging = FALSE;
12494 player->is_collecting = FALSE;
12500 #if USE_NEW_CONTINUOUS_SNAPPING
12501 /* prevent snapping with already pressed snap key when not allowed */
12502 if (player->is_snapping && !can_continue_snapping)
12505 if (player->is_snapping)
12509 player->MovDir = snap_direction;
12511 if (player->MovPos == 0)
12513 player->is_moving = FALSE;
12514 player->is_digging = FALSE;
12515 player->is_collecting = FALSE;
12518 player->is_dropping = FALSE;
12519 player->is_dropping_pressed = FALSE;
12520 player->drop_pressed_delay = 0;
12522 if (DigField(player, jx, jy, x, y, 0, 0, DF_SNAP) == MP_NO_ACTION)
12525 player->is_snapping = TRUE;
12526 player->is_active = TRUE;
12528 if (player->MovPos == 0)
12530 player->is_moving = FALSE;
12531 player->is_digging = FALSE;
12532 player->is_collecting = FALSE;
12535 if (player->MovPos != 0) /* prevent graphic bugs in versions < 2.2.0 */
12536 DrawLevelField(player->last_jx, player->last_jy);
12538 DrawLevelField(x, y);
12543 boolean DropElement(struct PlayerInfo *player)
12545 int old_element, new_element;
12546 int dropx = player->jx, dropy = player->jy;
12547 int drop_direction = player->MovDir;
12548 int drop_side = drop_direction;
12549 int drop_element = (player->inventory_size > 0 ?
12550 player->inventory_element[player->inventory_size - 1] :
12551 player->inventory_infinite_element != EL_UNDEFINED ?
12552 player->inventory_infinite_element :
12553 player->dynabombs_left > 0 ?
12554 EL_DYNABOMB_PLAYER_1_ACTIVE + player->index_nr :
12557 player->is_dropping_pressed = TRUE;
12559 /* do not drop an element on top of another element; when holding drop key
12560 pressed without moving, dropped element must move away before the next
12561 element can be dropped (this is especially important if the next element
12562 is dynamite, which can be placed on background for historical reasons) */
12563 if (PLAYER_DROPPING(player, dropx, dropy) && Feld[dropx][dropy] != EL_EMPTY)
12566 if (IS_THROWABLE(drop_element))
12568 dropx += GET_DX_FROM_DIR(drop_direction);
12569 dropy += GET_DY_FROM_DIR(drop_direction);
12571 if (!IN_LEV_FIELD(dropx, dropy))
12575 old_element = Feld[dropx][dropy]; /* old element at dropping position */
12576 new_element = drop_element; /* default: no change when dropping */
12578 /* check if player is active, not moving and ready to drop */
12579 if (!player->active || player->MovPos || player->drop_delay > 0)
12582 /* check if player has anything that can be dropped */
12583 if (new_element == EL_UNDEFINED)
12586 /* check if drop key was pressed long enough for EM style dynamite */
12587 if (new_element == EL_EM_DYNAMITE && player->drop_pressed_delay < 40)
12590 /* check if anything can be dropped at the current position */
12591 if (IS_ACTIVE_BOMB(old_element) || old_element == EL_EXPLOSION)
12594 /* collected custom elements can only be dropped on empty fields */
12595 if (IS_CUSTOM_ELEMENT(new_element) && old_element != EL_EMPTY)
12598 if (old_element != EL_EMPTY)
12599 Back[dropx][dropy] = old_element; /* store old element on this field */
12601 ResetGfxAnimation(dropx, dropy);
12602 ResetRandomAnimationValue(dropx, dropy);
12604 if (player->inventory_size > 0 ||
12605 player->inventory_infinite_element != EL_UNDEFINED)
12607 if (player->inventory_size > 0)
12609 player->inventory_size--;
12612 DrawGameDoorValues();
12614 DrawGameValue_Dynamite(local_player->inventory_size);
12617 if (new_element == EL_DYNAMITE)
12618 new_element = EL_DYNAMITE_ACTIVE;
12619 else if (new_element == EL_EM_DYNAMITE)
12620 new_element = EL_EM_DYNAMITE_ACTIVE;
12621 else if (new_element == EL_SP_DISK_RED)
12622 new_element = EL_SP_DISK_RED_ACTIVE;
12625 Feld[dropx][dropy] = new_element;
12627 if (IN_SCR_FIELD(SCREENX(dropx), SCREENY(dropy)))
12628 DrawGraphicThruMask(SCREENX(dropx), SCREENY(dropy),
12629 el2img(Feld[dropx][dropy]), 0);
12631 PlayLevelSoundAction(dropx, dropy, ACTION_DROPPING);
12633 /* needed if previous element just changed to "empty" in the last frame */
12634 ChangeCount[dropx][dropy] = 0; /* allow at least one more change */
12636 CheckElementChangeByPlayer(dropx, dropy, new_element, CE_DROPPED_BY_PLAYER,
12637 player->index_bit, drop_side);
12638 CheckTriggeredElementChangeByPlayer(dropx, dropy, new_element,
12640 player->index_bit, drop_side);
12642 TestIfElementTouchesCustomElement(dropx, dropy);
12644 else /* player is dropping a dyna bomb */
12646 player->dynabombs_left--;
12648 Feld[dropx][dropy] = new_element;
12650 if (IN_SCR_FIELD(SCREENX(dropx), SCREENY(dropy)))
12651 DrawGraphicThruMask(SCREENX(dropx), SCREENY(dropy),
12652 el2img(Feld[dropx][dropy]), 0);
12654 PlayLevelSoundAction(dropx, dropy, ACTION_DROPPING);
12657 if (Feld[dropx][dropy] == new_element) /* uninitialized unless CE change */
12658 InitField_WithBug1(dropx, dropy, FALSE);
12660 new_element = Feld[dropx][dropy]; /* element might have changed */
12662 if (IS_CUSTOM_ELEMENT(new_element) && CAN_MOVE(new_element) &&
12663 element_info[new_element].move_pattern == MV_WHEN_DROPPED)
12665 int move_direction, nextx, nexty;
12667 if (element_info[new_element].move_direction_initial == MV_START_AUTOMATIC)
12668 MovDir[dropx][dropy] = drop_direction;
12670 move_direction = MovDir[dropx][dropy];
12671 nextx = dropx + GET_DX_FROM_DIR(move_direction);
12672 nexty = dropy + GET_DY_FROM_DIR(move_direction);
12674 ChangeCount[dropx][dropy] = 0; /* allow at least one more change */
12675 CheckCollision[dropx][dropy] = CHECK_DELAY_COLLISION;
12678 player->drop_delay = GET_NEW_DROP_DELAY(drop_element);
12679 player->is_dropping = TRUE;
12681 player->drop_pressed_delay = 0;
12682 player->is_dropping_pressed = FALSE;
12684 player->drop_x = dropx;
12685 player->drop_y = dropy;
12690 /* ------------------------------------------------------------------------- */
12691 /* game sound playing functions */
12692 /* ------------------------------------------------------------------------- */
12694 static int *loop_sound_frame = NULL;
12695 static int *loop_sound_volume = NULL;
12697 void InitPlayLevelSound()
12699 int num_sounds = getSoundListSize();
12701 checked_free(loop_sound_frame);
12702 checked_free(loop_sound_volume);
12704 loop_sound_frame = checked_calloc(num_sounds * sizeof(int));
12705 loop_sound_volume = checked_calloc(num_sounds * sizeof(int));
12708 static void PlayLevelSound(int x, int y, int nr)
12710 int sx = SCREENX(x), sy = SCREENY(y);
12711 int volume, stereo_position;
12712 int max_distance = 8;
12713 int type = (IS_LOOP_SOUND(nr) ? SND_CTRL_PLAY_LOOP : SND_CTRL_PLAY_SOUND);
12715 if ((!setup.sound_simple && !IS_LOOP_SOUND(nr)) ||
12716 (!setup.sound_loops && IS_LOOP_SOUND(nr)))
12719 if (!IN_LEV_FIELD(x, y) ||
12720 sx < -max_distance || sx >= SCR_FIELDX + max_distance ||
12721 sy < -max_distance || sy >= SCR_FIELDY + max_distance)
12724 volume = SOUND_MAX_VOLUME;
12726 if (!IN_SCR_FIELD(sx, sy))
12728 int dx = ABS(sx - SCR_FIELDX / 2) - SCR_FIELDX / 2;
12729 int dy = ABS(sy - SCR_FIELDY / 2) - SCR_FIELDY / 2;
12731 volume -= volume * (dx > dy ? dx : dy) / max_distance;
12734 stereo_position = (SOUND_MAX_LEFT +
12735 (sx + max_distance) * SOUND_MAX_LEFT2RIGHT /
12736 (SCR_FIELDX + 2 * max_distance));
12738 if (IS_LOOP_SOUND(nr))
12740 /* This assures that quieter loop sounds do not overwrite louder ones,
12741 while restarting sound volume comparison with each new game frame. */
12743 if (loop_sound_volume[nr] > volume && loop_sound_frame[nr] == FrameCounter)
12746 loop_sound_volume[nr] = volume;
12747 loop_sound_frame[nr] = FrameCounter;
12750 PlaySoundExt(nr, volume, stereo_position, type);
12753 static void PlayLevelSoundNearest(int x, int y, int sound_action)
12755 PlayLevelSound(x < LEVELX(BX1) ? LEVELX(BX1) :
12756 x > LEVELX(BX2) ? LEVELX(BX2) : x,
12757 y < LEVELY(BY1) ? LEVELY(BY1) :
12758 y > LEVELY(BY2) ? LEVELY(BY2) : y,
12762 static void PlayLevelSoundAction(int x, int y, int action)
12764 PlayLevelSoundElementAction(x, y, Feld[x][y], action);
12767 static void PlayLevelSoundElementAction(int x, int y, int element, int action)
12769 int sound_effect = element_info[SND_ELEMENT(element)].sound[action];
12771 if (sound_effect != SND_UNDEFINED)
12772 PlayLevelSound(x, y, sound_effect);
12775 static void PlayLevelSoundElementActionIfLoop(int x, int y, int element,
12778 int sound_effect = element_info[SND_ELEMENT(element)].sound[action];
12780 if (sound_effect != SND_UNDEFINED && IS_LOOP_SOUND(sound_effect))
12781 PlayLevelSound(x, y, sound_effect);
12784 static void PlayLevelSoundActionIfLoop(int x, int y, int action)
12786 int sound_effect = element_info[SND_ELEMENT(Feld[x][y])].sound[action];
12788 if (sound_effect != SND_UNDEFINED && IS_LOOP_SOUND(sound_effect))
12789 PlayLevelSound(x, y, sound_effect);
12792 static void StopLevelSoundActionIfLoop(int x, int y, int action)
12794 int sound_effect = element_info[SND_ELEMENT(Feld[x][y])].sound[action];
12796 if (sound_effect != SND_UNDEFINED && IS_LOOP_SOUND(sound_effect))
12797 StopSound(sound_effect);
12800 static void PlayLevelMusic()
12802 if (levelset.music[level_nr] != MUS_UNDEFINED)
12803 PlayMusic(levelset.music[level_nr]); /* from config file */
12805 PlayMusic(MAP_NOCONF_MUSIC(level_nr)); /* from music dir */
12808 void PlayLevelSound_EM(int x, int y, int element_em, int sample)
12810 int element = (element_em > -1 ? map_element_EM_to_RND(element_em) : 0);
12815 PlayLevelSoundElementAction(x, y, element, ACTION_WALKING);
12819 PlayLevelSoundElementAction(x, y, element, ACTION_PUSHING);
12823 PlayLevelSoundElementAction(x, y, element, ACTION_IMPACT);
12827 PlayLevelSoundElementAction(x, y, element, ACTION_IMPACT);
12831 PlayLevelSoundElementAction(x, y, element, ACTION_BREAKING);
12835 PlayLevelSoundElementAction(x, y, element, ACTION_MOVING);
12839 PlayLevelSoundElementAction(x, y, element, ACTION_MOVING);
12842 case SAMPLE_android_clone:
12843 PlayLevelSoundElementAction(x, y, element, ACTION_DROPPING);
12846 case SAMPLE_android_move:
12847 PlayLevelSoundElementAction(x, y, element, ACTION_MOVING);
12850 case SAMPLE_spring:
12851 PlayLevelSoundElementAction(x, y, element, ACTION_IMPACT);
12855 PlayLevelSoundElementAction(x, y, element, ACTION_EATING);
12859 PlayLevelSoundElementAction(x, y, element, ACTION_WAITING);
12862 case SAMPLE_eater_eat:
12863 PlayLevelSoundElementAction(x, y, element, ACTION_DIGGING);
12867 PlayLevelSoundElementAction(x, y, element, ACTION_MOVING);
12870 case SAMPLE_collect:
12871 PlayLevelSoundElementAction(x, y, element, ACTION_COLLECTING);
12874 case SAMPLE_diamond:
12875 PlayLevelSoundElementAction(x, y, element, ACTION_IMPACT);
12878 case SAMPLE_squash:
12879 /* !!! CHECK THIS !!! */
12881 PlayLevelSoundElementAction(x, y, element, ACTION_BREAKING);
12883 PlayLevelSoundElementAction(x, y, element, ACTION_SMASHED_BY_ROCK);
12887 case SAMPLE_wonderfall:
12888 PlayLevelSoundElementAction(x, y, element, ACTION_FILLING);
12892 PlayLevelSoundElementAction(x, y, element, ACTION_IMPACT);
12896 PlayLevelSoundElementAction(x, y, element, ACTION_PUSHING);
12900 PlayLevelSoundElementAction(x, y, element, ACTION_DIGGING);
12904 PlayLevelSoundElementAction(x, y, element, ACTION_SPLASHING);
12908 PlayLevelSoundElementAction(x, y, element, ACTION_DROPPING);
12912 PlayLevelSoundElementAction(x, y, element, ACTION_GROWING);
12915 case SAMPLE_wonder:
12916 PlayLevelSoundElementAction(x, y, element, ACTION_ACTIVE);
12920 PlayLevelSoundElementAction(x, y, element, ACTION_PASSING);
12923 case SAMPLE_exit_open:
12924 PlayLevelSoundElementAction(x, y, element, ACTION_OPENING);
12927 case SAMPLE_exit_leave:
12928 PlayLevelSoundElementAction(x, y, element, ACTION_PASSING);
12931 case SAMPLE_dynamite:
12932 PlayLevelSoundElementAction(x, y, element, ACTION_DROPPING);
12936 PlayLevelSoundElementAction(x, y, element, ACTION_ACTIVE);
12940 PlayLevelSoundElementAction(x, y, element, ACTION_ACTIVATING);
12944 PlayLevelSoundElementAction(x, y, element, ACTION_ACTIVE);
12948 PlayLevelSoundElementAction(x, y, element, ACTION_EXPLODING);
12952 PlayLevelSoundElementAction(x, y, element, ACTION_DYING);
12956 PlaySoundStereo(SND_GAME_RUNNING_OUT_OF_TIME, SOUND_MIDDLE);
12960 PlayLevelSoundElementAction(x, y, element, ACTION_DEFAULT);
12965 void RaiseScore(int value)
12967 local_player->score += value;
12969 DrawGameValue_Score(local_player->score);
12972 void RaiseScoreElement(int element)
12977 case EL_BD_DIAMOND:
12978 case EL_EMERALD_YELLOW:
12979 case EL_EMERALD_RED:
12980 case EL_EMERALD_PURPLE:
12981 case EL_SP_INFOTRON:
12982 RaiseScore(level.score[SC_EMERALD]);
12985 RaiseScore(level.score[SC_DIAMOND]);
12988 RaiseScore(level.score[SC_CRYSTAL]);
12991 RaiseScore(level.score[SC_PEARL]);
12994 case EL_BD_BUTTERFLY:
12995 case EL_SP_ELECTRON:
12996 RaiseScore(level.score[SC_BUG]);
12999 case EL_BD_FIREFLY:
13000 case EL_SP_SNIKSNAK:
13001 RaiseScore(level.score[SC_SPACESHIP]);
13004 case EL_DARK_YAMYAM:
13005 RaiseScore(level.score[SC_YAMYAM]);
13008 RaiseScore(level.score[SC_ROBOT]);
13011 RaiseScore(level.score[SC_PACMAN]);
13014 RaiseScore(level.score[SC_NUT]);
13017 case EL_EM_DYNAMITE:
13018 case EL_SP_DISK_RED:
13019 case EL_DYNABOMB_INCREASE_NUMBER:
13020 case EL_DYNABOMB_INCREASE_SIZE:
13021 case EL_DYNABOMB_INCREASE_POWER:
13022 RaiseScore(level.score[SC_DYNAMITE]);
13024 case EL_SHIELD_NORMAL:
13025 case EL_SHIELD_DEADLY:
13026 RaiseScore(level.score[SC_SHIELD]);
13028 case EL_EXTRA_TIME:
13029 RaiseScore(level.extra_time_score);
13043 RaiseScore(level.score[SC_KEY]);
13046 RaiseScore(element_info[element].collect_score);
13051 void RequestQuitGame(boolean ask_if_really_quit)
13053 if (AllPlayersGone ||
13054 !ask_if_really_quit ||
13055 level_editor_test_game ||
13056 Request("Do you really want to quit the game ?",
13057 REQ_ASK | REQ_STAY_CLOSED))
13059 #if defined(NETWORK_AVALIABLE)
13060 if (options.network)
13061 SendToServer_StopPlaying(NETWORK_STOP_BY_PLAYER);
13065 game_status = GAME_MODE_MAIN;
13071 if (tape.playing && tape.deactivate_display)
13072 TapeDeactivateDisplayOff(TRUE);
13074 OpenDoor(DOOR_OPEN_1 | DOOR_COPY_BACK);
13076 if (tape.playing && tape.deactivate_display)
13077 TapeDeactivateDisplayOn();
13082 /* ---------- new game button stuff ---------------------------------------- */
13084 /* graphic position values for game buttons */
13085 #define GAME_BUTTON_XSIZE 30
13086 #define GAME_BUTTON_YSIZE 30
13087 #define GAME_BUTTON_XPOS 5
13088 #define GAME_BUTTON_YPOS 215
13089 #define SOUND_BUTTON_XPOS 5
13090 #define SOUND_BUTTON_YPOS (GAME_BUTTON_YPOS + GAME_BUTTON_YSIZE)
13092 #define GAME_BUTTON_STOP_XPOS (GAME_BUTTON_XPOS + 0 * GAME_BUTTON_XSIZE)
13093 #define GAME_BUTTON_PAUSE_XPOS (GAME_BUTTON_XPOS + 1 * GAME_BUTTON_XSIZE)
13094 #define GAME_BUTTON_PLAY_XPOS (GAME_BUTTON_XPOS + 2 * GAME_BUTTON_XSIZE)
13095 #define SOUND_BUTTON_MUSIC_XPOS (SOUND_BUTTON_XPOS + 0 * GAME_BUTTON_XSIZE)
13096 #define SOUND_BUTTON_LOOPS_XPOS (SOUND_BUTTON_XPOS + 1 * GAME_BUTTON_XSIZE)
13097 #define SOUND_BUTTON_SIMPLE_XPOS (SOUND_BUTTON_XPOS + 2 * GAME_BUTTON_XSIZE)
13104 } gamebutton_info[NUM_GAME_BUTTONS] =
13107 GAME_BUTTON_STOP_XPOS, GAME_BUTTON_YPOS,
13112 GAME_BUTTON_PAUSE_XPOS, GAME_BUTTON_YPOS,
13113 GAME_CTRL_ID_PAUSE,
13117 GAME_BUTTON_PLAY_XPOS, GAME_BUTTON_YPOS,
13122 SOUND_BUTTON_MUSIC_XPOS, SOUND_BUTTON_YPOS,
13123 SOUND_CTRL_ID_MUSIC,
13124 "background music on/off"
13127 SOUND_BUTTON_LOOPS_XPOS, SOUND_BUTTON_YPOS,
13128 SOUND_CTRL_ID_LOOPS,
13129 "sound loops on/off"
13132 SOUND_BUTTON_SIMPLE_XPOS, SOUND_BUTTON_YPOS,
13133 SOUND_CTRL_ID_SIMPLE,
13134 "normal sounds on/off"
13138 void CreateGameButtons()
13142 for (i = 0; i < NUM_GAME_BUTTONS; i++)
13144 Bitmap *gd_bitmap = graphic_info[IMG_GLOBAL_DOOR].bitmap;
13145 struct GadgetInfo *gi;
13148 unsigned long event_mask;
13149 int gd_xoffset, gd_yoffset;
13150 int gd_x1, gd_x2, gd_y1, gd_y2;
13153 gd_xoffset = gamebutton_info[i].x;
13154 gd_yoffset = gamebutton_info[i].y;
13155 gd_x1 = DOOR_GFX_PAGEX4 + gd_xoffset;
13156 gd_x2 = DOOR_GFX_PAGEX3 + gd_xoffset;
13158 if (id == GAME_CTRL_ID_STOP ||
13159 id == GAME_CTRL_ID_PAUSE ||
13160 id == GAME_CTRL_ID_PLAY)
13162 button_type = GD_TYPE_NORMAL_BUTTON;
13164 event_mask = GD_EVENT_RELEASED;
13165 gd_y1 = DOOR_GFX_PAGEY1 + gd_yoffset - GAME_BUTTON_YSIZE;
13166 gd_y2 = DOOR_GFX_PAGEY1 + gd_yoffset - GAME_BUTTON_YSIZE;
13170 button_type = GD_TYPE_CHECK_BUTTON;
13172 ((id == SOUND_CTRL_ID_MUSIC && setup.sound_music) ||
13173 (id == SOUND_CTRL_ID_LOOPS && setup.sound_loops) ||
13174 (id == SOUND_CTRL_ID_SIMPLE && setup.sound_simple) ? TRUE : FALSE);
13175 event_mask = GD_EVENT_PRESSED;
13176 gd_y1 = DOOR_GFX_PAGEY1 + gd_yoffset;
13177 gd_y2 = DOOR_GFX_PAGEY1 + gd_yoffset - GAME_BUTTON_YSIZE;
13180 gi = CreateGadget(GDI_CUSTOM_ID, id,
13181 GDI_INFO_TEXT, gamebutton_info[i].infotext,
13182 GDI_X, DX + gd_xoffset,
13183 GDI_Y, DY + gd_yoffset,
13184 GDI_WIDTH, GAME_BUTTON_XSIZE,
13185 GDI_HEIGHT, GAME_BUTTON_YSIZE,
13186 GDI_TYPE, button_type,
13187 GDI_STATE, GD_BUTTON_UNPRESSED,
13188 GDI_CHECKED, checked,
13189 GDI_DESIGN_UNPRESSED, gd_bitmap, gd_x1, gd_y1,
13190 GDI_DESIGN_PRESSED, gd_bitmap, gd_x2, gd_y1,
13191 GDI_ALT_DESIGN_UNPRESSED, gd_bitmap, gd_x1, gd_y2,
13192 GDI_ALT_DESIGN_PRESSED, gd_bitmap, gd_x2, gd_y2,
13193 GDI_EVENT_MASK, event_mask,
13194 GDI_CALLBACK_ACTION, HandleGameButtons,
13198 Error(ERR_EXIT, "cannot create gadget");
13200 game_gadget[id] = gi;
13204 void FreeGameButtons()
13208 for (i = 0; i < NUM_GAME_BUTTONS; i++)
13209 FreeGadget(game_gadget[i]);
13212 static void MapGameButtons()
13216 for (i = 0; i < NUM_GAME_BUTTONS; i++)
13217 MapGadget(game_gadget[i]);
13220 void UnmapGameButtons()
13224 for (i = 0; i < NUM_GAME_BUTTONS; i++)
13225 UnmapGadget(game_gadget[i]);
13228 static void HandleGameButtons(struct GadgetInfo *gi)
13230 int id = gi->custom_id;
13232 if (game_status != GAME_MODE_PLAYING)
13237 case GAME_CTRL_ID_STOP:
13241 RequestQuitGame(TRUE);
13244 case GAME_CTRL_ID_PAUSE:
13245 if (options.network)
13247 #if defined(NETWORK_AVALIABLE)
13249 SendToServer_ContinuePlaying();
13251 SendToServer_PausePlaying();
13255 TapeTogglePause(TAPE_TOGGLE_MANUAL);
13258 case GAME_CTRL_ID_PLAY:
13261 #if defined(NETWORK_AVALIABLE)
13262 if (options.network)
13263 SendToServer_ContinuePlaying();
13267 tape.pausing = FALSE;
13268 DrawVideoDisplay(VIDEO_STATE_PAUSE_OFF, 0);
13273 case SOUND_CTRL_ID_MUSIC:
13274 if (setup.sound_music)
13276 setup.sound_music = FALSE;
13279 else if (audio.music_available)
13281 setup.sound = setup.sound_music = TRUE;
13283 SetAudioMode(setup.sound);
13289 case SOUND_CTRL_ID_LOOPS:
13290 if (setup.sound_loops)
13291 setup.sound_loops = FALSE;
13292 else if (audio.loops_available)
13294 setup.sound = setup.sound_loops = TRUE;
13295 SetAudioMode(setup.sound);
13299 case SOUND_CTRL_ID_SIMPLE:
13300 if (setup.sound_simple)
13301 setup.sound_simple = FALSE;
13302 else if (audio.sound_available)
13304 setup.sound = setup.sound_simple = TRUE;
13305 SetAudioMode(setup.sound);