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 /* this switch controls how rocks move horizontally */
25 #define OLD_GAME_BEHAVIOUR FALSE
27 /* EXPERIMENTAL STUFF */
28 #define USE_NEW_AMOEBA_CODE FALSE
30 /* EXPERIMENTAL STUFF */
31 #define USE_NEW_STUFF TRUE * 1
33 #define USE_NEW_MOVE_STYLE TRUE * USE_NEW_STUFF * 1
34 #define USE_NEW_MOVE_DELAY TRUE * USE_NEW_STUFF * 1
35 #define USE_NEW_PUSH_DELAY TRUE * USE_NEW_STUFF * 1
36 #define USE_NEW_BLOCK_STYLE TRUE * USE_NEW_STUFF * 1 * 1
37 #define USE_NEW_SP_SLIPPERY TRUE * USE_NEW_STUFF * 1
38 #define USE_NEW_RANDOMIZE TRUE * USE_NEW_STUFF * 1
40 #define USE_PUSH_BUGFIX TRUE * USE_NEW_STUFF * 1
47 /* for MovePlayer() */
48 #define MF_NO_ACTION 0
52 /* for ScrollPlayer() */
54 #define SCROLL_GO_ON 1
57 #define EX_PHASE_START 0
58 #define EX_TYPE_NONE 0
59 #define EX_TYPE_NORMAL (1 << 0)
60 #define EX_TYPE_CENTER (1 << 1)
61 #define EX_TYPE_BORDER (1 << 2)
62 #define EX_TYPE_CROSS (1 << 3)
63 #define EX_TYPE_SINGLE_TILE (EX_TYPE_CENTER | EX_TYPE_BORDER)
65 /* special positions in the game control window (relative to control window) */
68 #define XX_EMERALDS 29
69 #define YY_EMERALDS 54
70 #define XX_DYNAMITE 29
71 #define YY_DYNAMITE 89
80 /* special positions in the game control window (relative to main window) */
81 #define DX_LEVEL (DX + XX_LEVEL)
82 #define DY_LEVEL (DY + YY_LEVEL)
83 #define DX_EMERALDS (DX + XX_EMERALDS)
84 #define DY_EMERALDS (DY + YY_EMERALDS)
85 #define DX_DYNAMITE (DX + XX_DYNAMITE)
86 #define DY_DYNAMITE (DY + YY_DYNAMITE)
87 #define DX_KEYS (DX + XX_KEYS)
88 #define DY_KEYS (DY + YY_KEYS)
89 #define DX_SCORE (DX + XX_SCORE)
90 #define DY_SCORE (DY + YY_SCORE)
91 #define DX_TIME1 (DX + XX_TIME1)
92 #define DX_TIME2 (DX + XX_TIME2)
93 #define DY_TIME (DY + YY_TIME)
95 /* values for initial player move delay (initial delay counter value) */
96 #define INITIAL_MOVE_DELAY_OFF -1
97 #define INITIAL_MOVE_DELAY_ON 0
99 /* values for player movement speed (which is in fact a delay value) */
100 #define MOVE_DELAY_NORMAL_SPEED 8
101 #define MOVE_DELAY_HIGH_SPEED 4
103 #define DOUBLE_MOVE_DELAY(x) (x = (x <= MOVE_DELAY_HIGH_SPEED ? x * 2 : x))
104 #define HALVE_MOVE_DELAY(x) (x = (x >= MOVE_DELAY_HIGH_SPEED ? x / 2 : x))
105 #define DOUBLE_PLAYER_SPEED(p) (HALVE_MOVE_DELAY((p)->move_delay_value))
106 #define HALVE_PLAYER_SPEED(p) (DOUBLE_MOVE_DELAY((p)->move_delay_value))
108 /* values for other actions */
109 #define MOVE_STEPSIZE_NORMAL (TILEX / MOVE_DELAY_NORMAL_SPEED)
111 #define GET_DX_FROM_DIR(d) ((d) == MV_LEFT ? -1 : (d) == MV_RIGHT ? 1 : 0)
112 #define GET_DY_FROM_DIR(d) ((d) == MV_UP ? -1 : (d) == MV_DOWN ? 1 : 0)
114 #define INIT_GFX_RANDOM() (SimpleRND(1000000))
116 #define GET_NEW_PUSH_DELAY(e) ( (element_info[e].push_delay_fixed) + \
117 RND(element_info[e].push_delay_random))
118 #define GET_NEW_DROP_DELAY(e) ( (element_info[e].drop_delay_fixed) + \
119 RND(element_info[e].drop_delay_random))
120 #define GET_NEW_MOVE_DELAY(e) ( (element_info[e].move_delay_fixed) + \
121 RND(element_info[e].move_delay_random))
122 #define GET_MAX_MOVE_DELAY(e) ( (element_info[e].move_delay_fixed) + \
123 (element_info[e].move_delay_random))
125 #define GET_TARGET_ELEMENT(e, ch) \
126 ((e) == EL_TRIGGER_ELEMENT ? (ch)->actual_trigger_element : \
127 (e) == EL_TRIGGER_PLAYER ? (ch)->actual_trigger_player : (e))
129 #define GET_VALID_PLAYER_ELEMENT(e) \
130 ((e) >= EL_PLAYER_1 && (e) <= EL_PLAYER_4 ? (e) : EL_PLAYER_1)
132 #define CAN_GROW_INTO(e) \
133 ((e) == EL_SAND || (IS_DIGGABLE(e) && level.grow_into_diggable))
135 #define ELEMENT_CAN_ENTER_FIELD_BASE_X(x, y, condition) \
136 (IN_LEV_FIELD(x, y) && (IS_FREE(x, y) || \
139 #define ELEMENT_CAN_ENTER_FIELD_BASE_2(e, x, y, condition) \
140 (IN_LEV_FIELD(x, y) && (IS_FREE(x, y) || \
141 (CAN_MOVE_INTO_ACID(e) && \
142 Feld[x][y] == EL_ACID) || \
145 #define ELEMENT_CAN_ENTER_FIELD_BASE_3(e, x, y, condition) \
146 (IN_LEV_FIELD(x, y) && (IS_FREE_OR_PLAYER(x, y) || \
147 (CAN_MOVE_INTO_ACID(e) && \
148 Feld[x][y] == EL_ACID) || \
151 #define ELEMENT_CAN_ENTER_FIELD_BASE_4(e, x, y, condition) \
152 (IN_LEV_FIELD(x, y) && (IS_FREE(x, y) || \
154 (CAN_MOVE_INTO_ACID(e) && \
155 Feld[x][y] == EL_ACID) || \
156 (DONT_COLLIDE_WITH(e) && \
158 !PLAYER_ENEMY_PROTECTED(x, y))))
161 #define ELEMENT_CAN_ENTER_FIELD_GENERIC(e, x, y, condition) \
162 (IN_LEV_FIELD(x, y) && (IS_FREE(x, y) || \
164 (DONT_COLLIDE_WITH(e) && \
166 !PLAYER_ENEMY_PROTECTED(x, y))))
169 #define ELEMENT_CAN_ENTER_FIELD(e, x, y) \
170 ELEMENT_CAN_ENTER_FIELD_BASE_4(e, x, y, 0)
173 #define SATELLITE_CAN_ENTER_FIELD(x, y) \
174 ELEMENT_CAN_ENTER_FIELD_BASE_2(EL_SATELLITE, x, y, 0)
176 #define SATELLITE_CAN_ENTER_FIELD(x, y) \
177 ELEMENT_CAN_ENTER_FIELD_BASE_X(x, y, Feld[x][y] == EL_ACID)
181 #define ENEMY_CAN_ENTER_FIELD(e, x, y) (IN_LEV_FIELD(x, y) && IS_FREE(x, y))
184 #define ENEMY_CAN_ENTER_FIELD(e, x, y) \
185 ELEMENT_CAN_ENTER_FIELD_BASE_2(e, x, y, 0)
189 #define YAMYAM_CAN_ENTER_FIELD(e, x, y) \
190 ELEMENT_CAN_ENTER_FIELD_BASE_3(e, x, y, Feld[x][y] == EL_DIAMOND)
192 #define DARK_YAMYAM_CAN_ENTER_FIELD(e, x, y) \
193 ELEMENT_CAN_ENTER_FIELD_BASE_3(e, x,y, IS_FOOD_DARK_YAMYAM(Feld[x][y]))
195 #define PACMAN_CAN_ENTER_FIELD(e, x, y) \
196 ELEMENT_CAN_ENTER_FIELD_BASE_3(e, x, y, IS_AMOEBOID(Feld[x][y]))
198 #define PIG_CAN_ENTER_FIELD(e, x, y) \
199 ELEMENT_CAN_ENTER_FIELD_BASE_2(e, x, y, IS_FOOD_PIG(Feld[x][y]))
201 #define PENGUIN_CAN_ENTER_FIELD(e, x, y) \
202 ELEMENT_CAN_ENTER_FIELD_BASE_2(e, x, y, (Feld[x][y] == EL_EXIT_OPEN ||\
203 IS_FOOD_PENGUIN(Feld[x][y])))
204 #define DRAGON_CAN_ENTER_FIELD(e, x, y) \
205 ELEMENT_CAN_ENTER_FIELD_BASE_2(e, x, y, 0)
207 #define MOLE_CAN_ENTER_FIELD(e, x, y, condition) \
208 ELEMENT_CAN_ENTER_FIELD_BASE_2(e, x, y, (condition))
210 #define SPRING_CAN_ENTER_FIELD(e, x, y) \
211 ELEMENT_CAN_ENTER_FIELD_BASE_2(e, x, y, 0)
215 #define YAMYAM_CAN_ENTER_FIELD(e, x, y) \
216 (IN_LEV_FIELD(x, y) && (IS_FREE_OR_PLAYER(x, y) || \
217 (CAN_MOVE_INTO_ACID(e) && \
218 Feld[x][y] == EL_ACID) || \
219 Feld[x][y] == EL_DIAMOND))
221 #define DARK_YAMYAM_CAN_ENTER_FIELD(e, x, y) \
222 (IN_LEV_FIELD(x, y) && (IS_FREE_OR_PLAYER(x, y) || \
223 (CAN_MOVE_INTO_ACID(e) && \
224 Feld[x][y] == EL_ACID) || \
225 IS_FOOD_DARK_YAMYAM(Feld[x][y])))
227 #define PACMAN_CAN_ENTER_FIELD(e, x, y) \
228 (IN_LEV_FIELD(x, y) && (IS_FREE_OR_PLAYER(x, y) || \
229 (CAN_MOVE_INTO_ACID(e) && \
230 Feld[x][y] == EL_ACID) || \
231 IS_AMOEBOID(Feld[x][y])))
233 #define PIG_CAN_ENTER_FIELD(e, x, y) \
234 (IN_LEV_FIELD(x, y) && (IS_FREE(x, y) || \
235 (CAN_MOVE_INTO_ACID(e) && \
236 Feld[x][y] == EL_ACID) || \
237 IS_FOOD_PIG(Feld[x][y])))
239 #define PENGUIN_CAN_ENTER_FIELD(e, x, y) \
240 (IN_LEV_FIELD(x, y) && (IS_FREE(x, y) || \
241 (CAN_MOVE_INTO_ACID(e) && \
242 Feld[x][y] == EL_ACID) || \
243 IS_FOOD_PENGUIN(Feld[x][y]) || \
244 Feld[x][y] == EL_EXIT_OPEN))
246 #define DRAGON_CAN_ENTER_FIELD(e, x, y) \
247 (IN_LEV_FIELD(x, y) && (IS_FREE(x, y) || \
248 (CAN_MOVE_INTO_ACID(e) && \
249 Feld[x][y] == EL_ACID)))
251 #define MOLE_CAN_ENTER_FIELD(e, x, y, condition) \
252 (IN_LEV_FIELD(x, y) && (IS_FREE(x, y) || \
253 (CAN_MOVE_INTO_ACID(e) && \
254 Feld[x][y] == EL_ACID) || \
257 #define SPRING_CAN_ENTER_FIELD(e, x, y) \
258 (IN_LEV_FIELD(x, y) && (IS_FREE(x, y) || \
259 (CAN_MOVE_INTO_ACID(e) && \
260 Feld[x][y] == EL_ACID)))
264 #define GROUP_NR(e) ((e) - EL_GROUP_START)
265 #define MOVE_ENTER_EL(e) (element_info[e].move_enter_element)
266 #define IS_IN_GROUP(e, nr) (element_info[e].in_group[nr] == TRUE)
267 #define IS_IN_GROUP_EL(e, ge) (IS_IN_GROUP(e, (ge) - EL_GROUP_START))
269 #define IS_EQUAL_OR_IN_GROUP(e, ge) \
270 (IS_GROUP_ELEMENT(ge) ? IS_IN_GROUP(e, GROUP_NR(ge)) : (e) == (ge))
273 #define CE_ENTER_FIELD_COND(e, x, y) \
274 (!IS_PLAYER(x, y) && \
275 (Feld[x][y] == EL_ACID || \
276 IS_EQUAL_OR_IN_GROUP(Feld[x][y], MOVE_ENTER_EL(e))))
278 #define CE_ENTER_FIELD_COND(e, x, y) \
279 (!IS_PLAYER(x, y) && \
280 IS_EQUAL_OR_IN_GROUP(Feld[x][y], MOVE_ENTER_EL(e)))
283 #define CUSTOM_ELEMENT_CAN_ENTER_FIELD(e, x, y) \
284 ELEMENT_CAN_ENTER_FIELD_BASE_4(e, x, y, CE_ENTER_FIELD_COND(e, x, y))
286 #define IN_LEV_FIELD_AND_IS_FREE(x, y) (IN_LEV_FIELD(x, y) && IS_FREE(x, y))
287 #define IN_LEV_FIELD_AND_NOT_FREE(x, y) (IN_LEV_FIELD(x, y) && !IS_FREE(x, y))
289 #define ACCESS_FROM(e, d) (element_info[e].access_direction &(d))
290 #define IS_WALKABLE_FROM(e, d) (IS_WALKABLE(e) && ACCESS_FROM(e, d))
291 #define IS_PASSABLE_FROM(e, d) (IS_PASSABLE(e) && ACCESS_FROM(e, d))
292 #define IS_ACCESSIBLE_FROM(e, d) (IS_ACCESSIBLE(e) && ACCESS_FROM(e, d))
294 /* game button identifiers */
295 #define GAME_CTRL_ID_STOP 0
296 #define GAME_CTRL_ID_PAUSE 1
297 #define GAME_CTRL_ID_PLAY 2
298 #define SOUND_CTRL_ID_MUSIC 3
299 #define SOUND_CTRL_ID_LOOPS 4
300 #define SOUND_CTRL_ID_SIMPLE 5
302 #define NUM_GAME_BUTTONS 6
305 /* forward declaration for internal use */
307 static void AdvanceFrameAndPlayerCounters(int);
309 static boolean MovePlayerOneStep(struct PlayerInfo *, int, int, int, int);
310 static boolean MovePlayer(struct PlayerInfo *, int, int);
311 static void ScrollPlayer(struct PlayerInfo *, int);
312 static void ScrollScreen(struct PlayerInfo *, int);
314 int DigField(struct PlayerInfo *, int, int, int, int, int, int, int);
316 static void InitBeltMovement(void);
317 static void CloseAllOpenTimegates(void);
318 static void CheckGravityMovement(struct PlayerInfo *);
319 static void CheckGravityMovementWhenNotMoving(struct PlayerInfo *);
320 static void KillHeroUnlessEnemyProtected(int, int);
321 static void KillHeroUnlessExplosionProtected(int, int);
323 static void TestIfPlayerTouchesCustomElement(int, int);
324 static void TestIfElementTouchesCustomElement(int, int);
325 static void TestIfElementHitsCustomElement(int, int, int);
327 static void TestIfElementSmashesCustomElement(int, int, int);
330 static void ChangeElement(int, int, int);
332 static boolean CheckTriggeredElementChangeExt(int, int, int, int, int,int,int);
333 #define CheckTriggeredElementChange(x, y, e, ev) \
334 CheckTriggeredElementChangeExt(x, y, e, ev, CH_PLAYER_ANY, \
336 #define CheckTriggeredElementChangeByPlayer(x, y, e, ev, p, s) \
337 CheckTriggeredElementChangeExt(x, y, e, ev, p, s, -1)
338 #define CheckTriggeredElementChangeBySide(x, y, e, ev, s) \
339 CheckTriggeredElementChangeExt(x, y, e, ev, CH_PLAYER_ANY, s, -1)
340 #define CheckTriggeredElementChangeByPage(x, y, e, ev, p) \
341 CheckTriggeredElementChangeExt(x, y, e, ev, CH_PLAYER_ANY, \
344 static boolean CheckElementChangeExt(int, int, int, int, int, int, int, int);
345 #define CheckElementChange(x, y, e, te, ev) \
346 CheckElementChangeExt(x, y, e, te, ev, CH_PLAYER_ANY, CH_SIDE_ANY, -1)
347 #define CheckElementChangeByPlayer(x, y, e, ev, p, s) \
348 CheckElementChangeExt(x, y, e, EL_EMPTY, ev, p, s, CH_PAGE_ANY)
349 #define CheckElementChangeBySide(x, y, e, te, ev, s) \
350 CheckElementChangeExt(x, y, e, te, ev, CH_PLAYER_ANY, s, CH_PAGE_ANY)
351 #define CheckElementChangeByPage(x, y, e, te, ev, p) \
352 CheckElementChangeExt(x, y, e, te, ev, CH_PLAYER_ANY, CH_SIDE_ANY, p)
354 static void PlayLevelSound(int, int, int);
355 static void PlayLevelSoundNearest(int, int, int);
356 static void PlayLevelSoundAction(int, int, int);
357 static void PlayLevelSoundElementAction(int, int, int, int);
358 static void PlayLevelSoundElementActionIfLoop(int, int, int, int);
359 static void PlayLevelSoundActionIfLoop(int, int, int);
360 static void StopLevelSoundActionIfLoop(int, int, int);
361 static void PlayLevelMusic();
363 static void MapGameButtons();
364 static void HandleGameButtons(struct GadgetInfo *);
366 static struct GadgetInfo *game_gadget[NUM_GAME_BUTTONS];
369 /* ------------------------------------------------------------------------- */
370 /* definition of elements that automatically change to other elements after */
371 /* a specified time, eventually calling a function when changing */
372 /* ------------------------------------------------------------------------- */
374 /* forward declaration for changer functions */
375 static void InitBuggyBase(int x, int y);
376 static void WarnBuggyBase(int x, int y);
378 static void InitTrap(int x, int y);
379 static void ActivateTrap(int x, int y);
380 static void ChangeActiveTrap(int x, int y);
382 static void InitRobotWheel(int x, int y);
383 static void RunRobotWheel(int x, int y);
384 static void StopRobotWheel(int x, int y);
386 static void InitTimegateWheel(int x, int y);
387 static void RunTimegateWheel(int x, int y);
389 struct ChangingElementInfo
394 void (*pre_change_function)(int x, int y);
395 void (*change_function)(int x, int y);
396 void (*post_change_function)(int x, int y);
399 static struct ChangingElementInfo change_delay_list[] =
450 EL_SWITCHGATE_OPENING,
458 EL_SWITCHGATE_CLOSING,
459 EL_SWITCHGATE_CLOSED,
491 EL_ACID_SPLASH_RIGHT,
500 EL_SP_BUGGY_BASE_ACTIVATING,
507 EL_SP_BUGGY_BASE_ACTIVATING,
508 EL_SP_BUGGY_BASE_ACTIVE,
515 EL_SP_BUGGY_BASE_ACTIVE,
539 EL_ROBOT_WHEEL_ACTIVE,
547 EL_TIMEGATE_SWITCH_ACTIVE,
568 int push_delay_fixed, push_delay_random;
573 { EL_BALLOON, 0, 0 },
575 { EL_SOKOBAN_OBJECT, 2, 0 },
576 { EL_SOKOBAN_FIELD_FULL, 2, 0 },
577 { EL_SATELLITE, 2, 0 },
578 { EL_SP_DISK_YELLOW, 2, 0 },
580 { EL_UNDEFINED, 0, 0 },
588 move_stepsize_list[] =
590 { EL_AMOEBA_DROP, 2 },
591 { EL_AMOEBA_DROPPING, 2 },
592 { EL_QUICKSAND_FILLING, 1 },
593 { EL_QUICKSAND_EMPTYING, 1 },
594 { EL_MAGIC_WALL_FILLING, 2 },
595 { EL_BD_MAGIC_WALL_FILLING, 2 },
596 { EL_MAGIC_WALL_EMPTYING, 2 },
597 { EL_BD_MAGIC_WALL_EMPTYING, 2 },
607 collect_count_list[] =
610 { EL_BD_DIAMOND, 1 },
611 { EL_EMERALD_YELLOW, 1 },
612 { EL_EMERALD_RED, 1 },
613 { EL_EMERALD_PURPLE, 1 },
615 { EL_SP_INFOTRON, 1 },
627 access_direction_list[] =
629 { EL_TUBE_ANY, MV_LEFT | MV_RIGHT | MV_UP | MV_DOWN },
630 { EL_TUBE_VERTICAL, MV_UP | MV_DOWN },
631 { EL_TUBE_HORIZONTAL, MV_LEFT | MV_RIGHT },
632 { EL_TUBE_VERTICAL_LEFT, MV_LEFT | MV_UP | MV_DOWN },
633 { EL_TUBE_VERTICAL_RIGHT, MV_RIGHT | MV_UP | MV_DOWN },
634 { EL_TUBE_HORIZONTAL_UP, MV_LEFT | MV_RIGHT | MV_UP },
635 { EL_TUBE_HORIZONTAL_DOWN, MV_LEFT | MV_RIGHT | MV_DOWN },
636 { EL_TUBE_LEFT_UP, MV_LEFT | MV_UP },
637 { EL_TUBE_LEFT_DOWN, MV_LEFT | MV_DOWN },
638 { EL_TUBE_RIGHT_UP, MV_RIGHT | MV_UP },
639 { EL_TUBE_RIGHT_DOWN, MV_RIGHT | MV_DOWN },
641 { EL_SP_PORT_LEFT, MV_RIGHT },
642 { EL_SP_PORT_RIGHT, MV_LEFT },
643 { EL_SP_PORT_UP, MV_DOWN },
644 { EL_SP_PORT_DOWN, MV_UP },
645 { EL_SP_PORT_HORIZONTAL, MV_LEFT | MV_RIGHT },
646 { EL_SP_PORT_VERTICAL, MV_UP | MV_DOWN },
647 { EL_SP_PORT_ANY, MV_LEFT | MV_RIGHT | MV_UP | MV_DOWN },
648 { EL_SP_GRAVITY_PORT_LEFT, MV_RIGHT },
649 { EL_SP_GRAVITY_PORT_RIGHT, MV_LEFT },
650 { EL_SP_GRAVITY_PORT_UP, MV_DOWN },
651 { EL_SP_GRAVITY_PORT_DOWN, MV_UP },
652 { EL_SP_GRAVITY_ON_PORT_LEFT, MV_RIGHT },
653 { EL_SP_GRAVITY_ON_PORT_RIGHT, MV_LEFT },
654 { EL_SP_GRAVITY_ON_PORT_UP, MV_DOWN },
655 { EL_SP_GRAVITY_ON_PORT_DOWN, MV_UP },
656 { EL_SP_GRAVITY_OFF_PORT_LEFT, MV_RIGHT },
657 { EL_SP_GRAVITY_OFF_PORT_RIGHT, MV_LEFT },
658 { EL_SP_GRAVITY_OFF_PORT_UP, MV_DOWN },
659 { EL_SP_GRAVITY_OFF_PORT_DOWN, MV_UP },
661 { EL_UNDEFINED, MV_NO_MOVING }
664 static unsigned long trigger_events[MAX_NUM_ELEMENTS];
666 #define IS_AUTO_CHANGING(e) (element_info[e].change_events & \
667 CH_EVENT_BIT(CE_DELAY))
668 #define IS_JUST_CHANGING(x, y) (ChangeDelay[x][y] != 0)
669 #define IS_CHANGING(x, y) (IS_AUTO_CHANGING(Feld[x][y]) || \
670 IS_JUST_CHANGING(x, y))
672 #define CE_PAGE(e, ce) (element_info[e].event_page[ce])
675 void GetPlayerConfig()
677 if (!audio.sound_available)
678 setup.sound_simple = FALSE;
680 if (!audio.loops_available)
681 setup.sound_loops = FALSE;
683 if (!audio.music_available)
684 setup.sound_music = FALSE;
686 if (!video.fullscreen_available)
687 setup.fullscreen = FALSE;
689 setup.sound = (setup.sound_simple || setup.sound_loops || setup.sound_music);
691 SetAudioMode(setup.sound);
695 static int getBeltNrFromBeltElement(int element)
697 return (element < EL_CONVEYOR_BELT_2_LEFT ? 0 :
698 element < EL_CONVEYOR_BELT_3_LEFT ? 1 :
699 element < EL_CONVEYOR_BELT_4_LEFT ? 2 : 3);
702 static int getBeltNrFromBeltActiveElement(int element)
704 return (element < EL_CONVEYOR_BELT_2_LEFT_ACTIVE ? 0 :
705 element < EL_CONVEYOR_BELT_3_LEFT_ACTIVE ? 1 :
706 element < EL_CONVEYOR_BELT_4_LEFT_ACTIVE ? 2 : 3);
709 static int getBeltNrFromBeltSwitchElement(int element)
711 return (element < EL_CONVEYOR_BELT_2_SWITCH_LEFT ? 0 :
712 element < EL_CONVEYOR_BELT_3_SWITCH_LEFT ? 1 :
713 element < EL_CONVEYOR_BELT_4_SWITCH_LEFT ? 2 : 3);
716 static int getBeltDirNrFromBeltSwitchElement(int element)
718 static int belt_base_element[4] =
720 EL_CONVEYOR_BELT_1_SWITCH_LEFT,
721 EL_CONVEYOR_BELT_2_SWITCH_LEFT,
722 EL_CONVEYOR_BELT_3_SWITCH_LEFT,
723 EL_CONVEYOR_BELT_4_SWITCH_LEFT
726 int belt_nr = getBeltNrFromBeltSwitchElement(element);
727 int belt_dir_nr = element - belt_base_element[belt_nr];
729 return (belt_dir_nr % 3);
732 static int getBeltDirFromBeltSwitchElement(int element)
734 static int belt_move_dir[3] =
741 int belt_dir_nr = getBeltDirNrFromBeltSwitchElement(element);
743 return belt_move_dir[belt_dir_nr];
746 static void InitPlayerField(int x, int y, int element, boolean init_game)
748 if (element == EL_SP_MURPHY)
752 if (stored_player[0].present)
754 Feld[x][y] = EL_SP_MURPHY_CLONE;
760 stored_player[0].use_murphy_graphic = TRUE;
763 Feld[x][y] = EL_PLAYER_1;
769 struct PlayerInfo *player = &stored_player[Feld[x][y] - EL_PLAYER_1];
770 int jx = player->jx, jy = player->jy;
772 player->present = TRUE;
774 player->block_last_field = (element == EL_SP_MURPHY ?
775 level.sp_block_last_field :
776 level.block_last_field);
778 #if USE_NEW_BLOCK_STYLE
780 player->block_delay = (player->block_last_field ?
781 (element == EL_SP_MURPHY ?
782 level.sp_block_delay :
783 level.block_delay) : 0);
785 player->block_delay = (element == EL_SP_MURPHY ?
786 (player->block_last_field ? 7 : 1) :
787 (player->block_last_field ? 7 : 1));
791 printf("::: block_last_field == %d, block_delay = %d\n",
792 player->block_last_field, player->block_delay);
796 if (!options.network || player->connected)
798 player->active = TRUE;
800 /* remove potentially duplicate players */
801 if (StorePlayer[jx][jy] == Feld[x][y])
802 StorePlayer[jx][jy] = 0;
804 StorePlayer[x][y] = Feld[x][y];
808 printf("Player %d activated.\n", player->element_nr);
809 printf("[Local player is %d and currently %s.]\n",
810 local_player->element_nr,
811 local_player->active ? "active" : "not active");
815 Feld[x][y] = EL_EMPTY;
817 player->jx = player->last_jx = x;
818 player->jy = player->last_jy = y;
822 static void InitField(int x, int y, boolean init_game)
824 int element = Feld[x][y];
833 InitPlayerField(x, y, element, init_game);
836 case EL_SOKOBAN_FIELD_PLAYER:
837 element = Feld[x][y] = EL_PLAYER_1;
838 InitField(x, y, init_game);
840 element = Feld[x][y] = EL_SOKOBAN_FIELD_EMPTY;
841 InitField(x, y, init_game);
844 case EL_SOKOBAN_FIELD_EMPTY:
845 local_player->sokobanfields_still_needed++;
849 if (x < lev_fieldx-1 && Feld[x+1][y] == EL_ACID)
850 Feld[x][y] = EL_ACID_POOL_TOPLEFT;
851 else if (x > 0 && Feld[x-1][y] == EL_ACID)
852 Feld[x][y] = EL_ACID_POOL_TOPRIGHT;
853 else if (y > 0 && Feld[x][y-1] == EL_ACID_POOL_TOPLEFT)
854 Feld[x][y] = EL_ACID_POOL_BOTTOMLEFT;
855 else if (y > 0 && Feld[x][y-1] == EL_ACID)
856 Feld[x][y] = EL_ACID_POOL_BOTTOM;
857 else if (y > 0 && Feld[x][y-1] == EL_ACID_POOL_TOPRIGHT)
858 Feld[x][y] = EL_ACID_POOL_BOTTOMRIGHT;
866 case EL_SPACESHIP_RIGHT:
867 case EL_SPACESHIP_UP:
868 case EL_SPACESHIP_LEFT:
869 case EL_SPACESHIP_DOWN:
871 case EL_BD_BUTTERFLY_RIGHT:
872 case EL_BD_BUTTERFLY_UP:
873 case EL_BD_BUTTERFLY_LEFT:
874 case EL_BD_BUTTERFLY_DOWN:
875 case EL_BD_BUTTERFLY:
876 case EL_BD_FIREFLY_RIGHT:
877 case EL_BD_FIREFLY_UP:
878 case EL_BD_FIREFLY_LEFT:
879 case EL_BD_FIREFLY_DOWN:
881 case EL_PACMAN_RIGHT:
905 if (y == lev_fieldy - 1)
907 Feld[x][y] = EL_AMOEBA_GROWING;
908 Store[x][y] = EL_AMOEBA_WET;
912 case EL_DYNAMITE_ACTIVE:
913 case EL_SP_DISK_RED_ACTIVE:
914 case EL_DYNABOMB_PLAYER_1_ACTIVE:
915 case EL_DYNABOMB_PLAYER_2_ACTIVE:
916 case EL_DYNABOMB_PLAYER_3_ACTIVE:
917 case EL_DYNABOMB_PLAYER_4_ACTIVE:
922 local_player->lights_still_needed++;
926 local_player->friends_still_needed++;
931 GfxDir[x][y] = MovDir[x][y] = 1 << RND(4);
936 Feld[x][y] = EL_EMPTY;
941 case EL_EM_KEY_1_FILE:
942 Feld[x][y] = EL_EM_KEY_1;
944 case EL_EM_KEY_2_FILE:
945 Feld[x][y] = EL_EM_KEY_2;
947 case EL_EM_KEY_3_FILE:
948 Feld[x][y] = EL_EM_KEY_3;
950 case EL_EM_KEY_4_FILE:
951 Feld[x][y] = EL_EM_KEY_4;
955 case EL_CONVEYOR_BELT_1_SWITCH_LEFT:
956 case EL_CONVEYOR_BELT_1_SWITCH_MIDDLE:
957 case EL_CONVEYOR_BELT_1_SWITCH_RIGHT:
958 case EL_CONVEYOR_BELT_2_SWITCH_LEFT:
959 case EL_CONVEYOR_BELT_2_SWITCH_MIDDLE:
960 case EL_CONVEYOR_BELT_2_SWITCH_RIGHT:
961 case EL_CONVEYOR_BELT_3_SWITCH_LEFT:
962 case EL_CONVEYOR_BELT_3_SWITCH_MIDDLE:
963 case EL_CONVEYOR_BELT_3_SWITCH_RIGHT:
964 case EL_CONVEYOR_BELT_4_SWITCH_LEFT:
965 case EL_CONVEYOR_BELT_4_SWITCH_MIDDLE:
966 case EL_CONVEYOR_BELT_4_SWITCH_RIGHT:
969 int belt_nr = getBeltNrFromBeltSwitchElement(Feld[x][y]);
970 int belt_dir = getBeltDirFromBeltSwitchElement(Feld[x][y]);
971 int belt_dir_nr = getBeltDirNrFromBeltSwitchElement(Feld[x][y]);
973 if (game.belt_dir_nr[belt_nr] == 3) /* initial value */
975 game.belt_dir[belt_nr] = belt_dir;
976 game.belt_dir_nr[belt_nr] = belt_dir_nr;
978 else /* more than one switch -- set it like the first switch */
980 Feld[x][y] = Feld[x][y] - belt_dir_nr + game.belt_dir_nr[belt_nr];
985 case EL_SWITCHGATE_SWITCH_DOWN: /* always start with same switch pos */
987 Feld[x][y] = EL_SWITCHGATE_SWITCH_UP;
990 case EL_LIGHT_SWITCH_ACTIVE:
992 game.light_time_left = level.time_light * FRAMES_PER_SECOND;
996 if (IS_CUSTOM_ELEMENT(element) && CAN_MOVE(element))
998 else if (IS_GROUP_ELEMENT(element))
1000 struct ElementGroupInfo *group = element_info[element].group;
1001 int last_anim_random_frame = gfx.anim_random_frame;
1004 if (group->choice_mode == ANIM_RANDOM)
1005 gfx.anim_random_frame = RND(group->num_elements_resolved);
1007 element_pos = getAnimationFrame(group->num_elements_resolved, 1,
1008 group->choice_mode, 0,
1011 if (group->choice_mode == ANIM_RANDOM)
1012 gfx.anim_random_frame = last_anim_random_frame;
1014 group->choice_pos++;
1016 Feld[x][y] = group->element_resolved[element_pos];
1018 InitField(x, y, init_game);
1024 static inline void InitField_WithBug1(int x, int y, boolean init_game)
1026 InitField(x, y, init_game);
1028 /* not needed to call InitMovDir() -- already done by InitField()! */
1029 if (game.engine_version < VERSION_IDENT(3,1,0,0) &&
1030 CAN_MOVE(Feld[x][y]))
1034 static inline void InitField_WithBug2(int x, int y, boolean init_game)
1036 int old_element = Feld[x][y];
1038 InitField(x, y, init_game);
1040 /* not needed to call InitMovDir() -- already done by InitField()! */
1041 if (game.engine_version < VERSION_IDENT(3,1,0,0) &&
1042 CAN_MOVE(old_element) &&
1043 (old_element < EL_MOLE_LEFT || old_element > EL_MOLE_DOWN))
1046 /* this case is in fact a combination of not less than three bugs:
1047 first, it calls InitMovDir() for elements that can move, although this is
1048 already done by InitField(); then, it checks the element that was at this
1049 field _before_ the call to InitField() (which can change it); lastly, it
1050 was not called for "mole with direction" elements, which were treated as
1051 "cannot move" due to (fixed) wrong element initialization in "src/init.c"
1055 inline void DrawGameValue_Emeralds(int value)
1057 DrawText(DX_EMERALDS, DY_EMERALDS, int2str(value, 3), FONT_TEXT_2);
1060 inline void DrawGameValue_Dynamite(int value)
1062 DrawText(DX_DYNAMITE, DY_DYNAMITE, int2str(value, 3), FONT_TEXT_2);
1065 inline void DrawGameValue_Keys(struct PlayerInfo *player)
1069 for (i = 0; i < MAX_KEYS; i++)
1071 DrawMiniGraphicExt(drawto, DX_KEYS + i * MINI_TILEX, DY_KEYS,
1072 el2edimg(EL_KEY_1 + i));
1075 inline void DrawGameValue_Score(int value)
1077 DrawText(DX_SCORE, DY_SCORE, int2str(value, 5), FONT_TEXT_2);
1080 inline void DrawGameValue_Time(int value)
1083 DrawText(DX_TIME1, DY_TIME, int2str(value, 3), FONT_TEXT_2);
1085 DrawText(DX_TIME2, DY_TIME, int2str(value, 4), FONT_LEVEL_NUMBER);
1088 inline void DrawGameValue_Level(int value)
1091 DrawText(DX_LEVEL, DY_LEVEL, int2str(value, 2), FONT_TEXT_2);
1094 /* misuse area for displaying emeralds to draw bigger level number */
1095 DrawTextExt(drawto, DX_EMERALDS, DY_EMERALDS,
1096 int2str(value, 3), FONT_LEVEL_NUMBER, BLIT_OPAQUE);
1098 /* now copy it to the area for displaying level number */
1099 BlitBitmap(drawto, drawto,
1100 DX_EMERALDS, DY_EMERALDS + 1,
1101 getFontWidth(FONT_LEVEL_NUMBER) * 3,
1102 getFontHeight(FONT_LEVEL_NUMBER) - 1,
1103 DX_LEVEL - 1, DY_LEVEL + 1);
1105 /* restore the area for displaying emeralds */
1106 DrawGameValue_Emeralds(local_player->gems_still_needed);
1108 /* yes, this is all really ugly :-) */
1112 void DrawGameDoorValues()
1116 DrawGameValue_Level(level_nr);
1118 for (i = 0; i < MAX_PLAYERS; i++)
1119 DrawGameValue_Keys(&stored_player[i]);
1121 DrawGameValue_Emeralds(local_player->gems_still_needed);
1122 DrawGameValue_Dynamite(local_player->inventory_size);
1123 DrawGameValue_Score(local_player->score);
1124 DrawGameValue_Time(TimeLeft);
1127 void DrawGameDoorValues_EM(int emeralds, int dynamite, int score, int time)
1129 DrawGameValue_Emeralds(emeralds);
1130 DrawGameValue_Dynamite(dynamite);
1131 DrawGameValue_Score(score);
1132 DrawGameValue_Time(time);
1135 static void resolve_group_element(int group_element, int recursion_depth)
1137 static int group_nr;
1138 static struct ElementGroupInfo *group;
1139 struct ElementGroupInfo *actual_group = element_info[group_element].group;
1142 if (recursion_depth > NUM_GROUP_ELEMENTS) /* recursion too deep */
1144 Error(ERR_WARN, "recursion too deep when resolving group element %d",
1145 group_element - EL_GROUP_START + 1);
1147 /* replace element which caused too deep recursion by question mark */
1148 group->element_resolved[group->num_elements_resolved++] = EL_UNKNOWN;
1153 if (recursion_depth == 0) /* initialization */
1155 group = element_info[group_element].group;
1156 group_nr = group_element - EL_GROUP_START;
1158 group->num_elements_resolved = 0;
1159 group->choice_pos = 0;
1162 for (i = 0; i < actual_group->num_elements; i++)
1164 int element = actual_group->element[i];
1166 if (group->num_elements_resolved == NUM_FILE_ELEMENTS)
1169 if (IS_GROUP_ELEMENT(element))
1170 resolve_group_element(element, recursion_depth + 1);
1173 group->element_resolved[group->num_elements_resolved++] = element;
1174 element_info[element].in_group[group_nr] = TRUE;
1179 if (recursion_depth == 0 && group_element <= EL_GROUP_4)
1181 printf("::: group %d: %d resolved elements\n",
1182 group_element - EL_GROUP_START, group->num_elements_resolved);
1183 for (i = 0; i < group->num_elements_resolved; i++)
1184 printf("::: - %d ['%s']\n", group->element_resolved[i],
1185 element_info[group->element_resolved[i]].token_name);
1192 =============================================================================
1194 -----------------------------------------------------------------------------
1195 initialize game engine due to level / tape version number
1196 =============================================================================
1199 static void InitGameEngine()
1203 /* set game engine from tape file when re-playing, else from level file */
1204 game.engine_version = (tape.playing ? tape.engine_version :
1205 level.game_version);
1207 /* ---------------------------------------------------------------------- */
1208 /* set flags for bugs and changes according to active game engine version */
1209 /* ---------------------------------------------------------------------- */
1213 Before 3.1.0, custom elements that "change when pushing" changed directly
1214 after the player started pushing them (until then handled in "DigField()").
1215 Since 3.1.0, these custom elements are not changed until the "pushing"
1216 move of the element is finished (now handled in "ContinueMoving()").
1218 Affected levels/tapes:
1219 The first condition is generally needed for all levels/tapes before version
1220 3.1.0, which might use the old behaviour before it was changed; known tapes
1221 that are affected are some tapes from the level set "Walpurgis Gardens" by
1223 The second condition is an exception from the above case and is needed for
1224 the special case of tapes recorded with game (not engine!) version 3.1.0 or
1225 above (including some development versions of 3.1.0), but before it was
1226 known that this change would break tapes like the above and was fixed in
1227 3.1.1, so that the changed behaviour was active although the engine version
1228 while recording maybe was before 3.1.0. There is at least one tape that is
1229 affected by this exception, which is the tape for the one-level set "Bug
1230 Machine" by Juergen Bonhagen.
1233 game.use_bug_change_when_pushing =
1234 (game.engine_version < VERSION_IDENT(3,1,0,0) &&
1236 tape.game_version >= VERSION_IDENT(3,1,0,0) &&
1237 tape.game_version < VERSION_IDENT(3,1,1,0)));
1239 /* ---------------------------------------------------------------------- */
1241 /* dynamically adjust element properties according to game engine version */
1242 InitElementPropertiesEngine(game.engine_version);
1245 printf("level %d: level version == %06d\n", level_nr, level.game_version);
1246 printf(" tape version == %06d [%s] [file: %06d]\n",
1247 tape.engine_version, (tape.playing ? "PLAYING" : "RECORDING"),
1249 printf(" => game.engine_version == %06d\n", game.engine_version);
1252 /* ---------- recursively resolve group elements ------------------------- */
1254 for (i = 0; i < MAX_NUM_ELEMENTS; i++)
1255 for (j = 0; j < NUM_GROUP_ELEMENTS; j++)
1256 element_info[i].in_group[j] = FALSE;
1258 for (i = 0; i < NUM_GROUP_ELEMENTS; i++)
1259 resolve_group_element(EL_GROUP_START + i, 0);
1261 /* ---------- initialize player's initial move delay --------------------- */
1263 #if USE_NEW_MOVE_DELAY
1264 /* dynamically adjust player properties according to level information */
1265 game.initial_move_delay_value =
1266 (level.double_speed ? MOVE_DELAY_HIGH_SPEED : MOVE_DELAY_NORMAL_SPEED);
1268 /* dynamically adjust player properties according to game engine version */
1269 game.initial_move_delay = (game.engine_version <= VERSION_IDENT(2,0,1,0) ?
1270 game.initial_move_delay_value : 0);
1272 /* dynamically adjust player properties according to game engine version */
1273 game.initial_move_delay =
1274 (game.engine_version <= VERSION_IDENT(2,0,1,0) ? INITIAL_MOVE_DELAY_ON :
1275 INITIAL_MOVE_DELAY_OFF);
1277 /* dynamically adjust player properties according to level information */
1278 game.initial_move_delay_value =
1279 (level.double_speed ? MOVE_DELAY_HIGH_SPEED : MOVE_DELAY_NORMAL_SPEED);
1282 /* ---------- initialize player's initial push delay --------------------- */
1284 /* dynamically adjust player properties according to game engine version */
1285 game.initial_push_delay_value =
1286 (game.engine_version < VERSION_IDENT(3,0,7,1) ? 5 : -1);
1288 /* ---------- initialize changing elements ------------------------------- */
1290 /* initialize changing elements information */
1291 for (i = 0; i < MAX_NUM_ELEMENTS; i++)
1293 struct ElementInfo *ei = &element_info[i];
1295 /* this pointer might have been changed in the level editor */
1296 ei->change = &ei->change_page[0];
1298 if (!IS_CUSTOM_ELEMENT(i))
1300 ei->change->target_element = EL_EMPTY_SPACE;
1301 ei->change->delay_fixed = 0;
1302 ei->change->delay_random = 0;
1303 ei->change->delay_frames = 1;
1306 ei->change_events = CE_BITMASK_DEFAULT;
1307 for (j = 0; j < NUM_CHANGE_EVENTS; j++)
1309 ei->event_page_nr[j] = 0;
1310 ei->event_page[j] = &ei->change_page[0];
1314 /* add changing elements from pre-defined list */
1315 for (i = 0; change_delay_list[i].element != EL_UNDEFINED; i++)
1317 struct ChangingElementInfo *ch_delay = &change_delay_list[i];
1318 struct ElementInfo *ei = &element_info[ch_delay->element];
1320 ei->change->target_element = ch_delay->target_element;
1321 ei->change->delay_fixed = ch_delay->change_delay;
1323 ei->change->pre_change_function = ch_delay->pre_change_function;
1324 ei->change->change_function = ch_delay->change_function;
1325 ei->change->post_change_function = ch_delay->post_change_function;
1327 ei->change_events |= CH_EVENT_BIT(CE_DELAY);
1330 SET_PROPERTY(ch_delay->element, EP_CAN_CHANGE, TRUE);
1335 /* add change events from custom element configuration */
1336 for (i = 0; i < NUM_CUSTOM_ELEMENTS; i++)
1338 struct ElementInfo *ei = &element_info[EL_CUSTOM_START + i];
1340 for (j = 0; j < ei->num_change_pages; j++)
1342 if (!ei->change_page[j].can_change)
1345 for (k = 0; k < NUM_CHANGE_EVENTS; k++)
1347 /* only add event page for the first page found with this event */
1348 if (ei->change_page[j].events & CH_EVENT_BIT(k) &&
1349 !(ei->change_events & CH_EVENT_BIT(k)))
1351 ei->change_events |= CH_EVENT_BIT(k);
1352 ei->event_page_nr[k] = j;
1353 ei->event_page[k] = &ei->change_page[j];
1361 /* add change events from custom element configuration */
1362 for (i = 0; i < NUM_CUSTOM_ELEMENTS; i++)
1364 int element = EL_CUSTOM_START + i;
1366 /* only add custom elements that change after fixed/random frame delay */
1367 if (CAN_CHANGE(element) && HAS_CHANGE_EVENT(element, CE_DELAY))
1368 element_info[element].change_events |= CH_EVENT_BIT(CE_DELAY);
1372 /* ---------- initialize run-time trigger player and element ------------- */
1374 for (i = 0; i < NUM_CUSTOM_ELEMENTS; i++)
1376 struct ElementInfo *ei = &element_info[EL_CUSTOM_START + i];
1378 for (j = 0; j < ei->num_change_pages; j++)
1380 ei->change_page[j].actual_trigger_element = EL_EMPTY;
1381 ei->change_page[j].actual_trigger_player = EL_PLAYER_1;
1385 /* ---------- initialize trigger events ---------------------------------- */
1387 /* initialize trigger events information */
1388 for (i = 0; i < MAX_NUM_ELEMENTS; i++)
1389 trigger_events[i] = EP_BITMASK_DEFAULT;
1392 /* add trigger events from element change event properties */
1393 for (i = 0; i < MAX_NUM_ELEMENTS; i++)
1395 struct ElementInfo *ei = &element_info[i];
1397 for (j = 0; j < ei->num_change_pages; j++)
1399 if (!ei->change_page[j].can_change)
1402 if (ei->change_page[j].events & CH_EVENT_BIT(CE_BY_OTHER_ACTION))
1404 int trigger_element = ei->change_page[j].trigger_element;
1406 if (IS_GROUP_ELEMENT(trigger_element))
1408 struct ElementGroupInfo *group = element_info[trigger_element].group;
1410 for (k = 0; k < group->num_elements_resolved; k++)
1411 trigger_events[group->element_resolved[k]]
1412 |= ei->change_page[j].events;
1415 trigger_events[trigger_element] |= ei->change_page[j].events;
1420 /* add trigger events from element change event properties */
1421 for (i = 0; i < MAX_NUM_ELEMENTS; i++)
1422 if (HAS_CHANGE_EVENT(i, CE_BY_OTHER_ACTION))
1423 trigger_events[element_info[i].change->trigger_element] |=
1424 element_info[i].change->events;
1427 /* ---------- initialize push delay -------------------------------------- */
1429 /* initialize push delay values to default */
1430 for (i = 0; i < MAX_NUM_ELEMENTS; i++)
1432 if (!IS_CUSTOM_ELEMENT(i))
1434 element_info[i].push_delay_fixed = game.default_push_delay_fixed;
1435 element_info[i].push_delay_random = game.default_push_delay_random;
1439 /* set push delay value for certain elements from pre-defined list */
1440 for (i = 0; push_delay_list[i].element != EL_UNDEFINED; i++)
1442 int e = push_delay_list[i].element;
1444 element_info[e].push_delay_fixed = push_delay_list[i].push_delay_fixed;
1445 element_info[e].push_delay_random = push_delay_list[i].push_delay_random;
1448 /* set push delay value for Supaplex elements for newer engine versions */
1449 if (game.engine_version >= VERSION_IDENT(3,1,0,0))
1451 for (i = 0; i < MAX_NUM_ELEMENTS; i++)
1453 if (IS_SP_ELEMENT(i))
1455 #if USE_NEW_MOVE_STYLE
1456 /* set SP push delay to just enough to push under a falling zonk */
1457 int delay = (game.engine_version >= VERSION_IDENT(3,1,1,0) ? 8 : 6);
1459 element_info[i].push_delay_fixed = delay;
1460 element_info[i].push_delay_random = 0;
1462 element_info[i].push_delay_fixed = 6; /* just enough to escape ... */
1463 element_info[i].push_delay_random = 0; /* ... from falling zonk */
1469 /* ---------- initialize move stepsize ----------------------------------- */
1471 /* initialize move stepsize values to default */
1472 for (i = 0; i < MAX_NUM_ELEMENTS; i++)
1473 if (!IS_CUSTOM_ELEMENT(i))
1474 element_info[i].move_stepsize = MOVE_STEPSIZE_NORMAL;
1476 /* set move stepsize value for certain elements from pre-defined list */
1477 for (i = 0; move_stepsize_list[i].element != EL_UNDEFINED; i++)
1479 int e = move_stepsize_list[i].element;
1481 element_info[e].move_stepsize = move_stepsize_list[i].move_stepsize;
1485 /* ---------- initialize move dig/leave ---------------------------------- */
1487 for (i = 0; i < MAX_NUM_ELEMENTS; i++)
1489 element_info[i].can_leave_element = FALSE;
1490 element_info[i].can_leave_element_last = FALSE;
1494 /* ---------- initialize gem count --------------------------------------- */
1496 /* initialize gem count values for each element */
1497 for (i = 0; i < MAX_NUM_ELEMENTS; i++)
1498 if (!IS_CUSTOM_ELEMENT(i))
1499 element_info[i].collect_count = 0;
1501 /* add gem count values for all elements from pre-defined list */
1502 for (i = 0; collect_count_list[i].element != EL_UNDEFINED; i++)
1503 element_info[collect_count_list[i].element].collect_count =
1504 collect_count_list[i].count;
1506 /* ---------- initialize access direction -------------------------------- */
1508 /* initialize access direction values to default (access from every side) */
1509 for (i = 0; i < MAX_NUM_ELEMENTS; i++)
1510 if (!IS_CUSTOM_ELEMENT(i))
1511 element_info[i].access_direction = MV_ALL_DIRECTIONS;
1513 /* set access direction value for certain elements from pre-defined list */
1514 for (i = 0; access_direction_list[i].element != EL_UNDEFINED; i++)
1515 element_info[access_direction_list[i].element].access_direction =
1516 access_direction_list[i].direction;
1521 =============================================================================
1523 -----------------------------------------------------------------------------
1524 initialize and start new game
1525 =============================================================================
1530 boolean emulate_bd = TRUE; /* unless non-BOULDERDASH elements found */
1531 boolean emulate_sb = TRUE; /* unless non-SOKOBAN elements found */
1532 boolean emulate_sp = TRUE; /* unless non-SUPAPLEX elements found */
1539 #if USE_NEW_AMOEBA_CODE
1540 printf("Using new amoeba code.\n");
1542 printf("Using old amoeba code.\n");
1547 /* don't play tapes over network */
1548 network_playing = (options.network && !tape.playing);
1550 for (i = 0; i < MAX_PLAYERS; i++)
1552 struct PlayerInfo *player = &stored_player[i];
1554 player->index_nr = i;
1555 player->index_bit = (1 << i);
1556 player->element_nr = EL_PLAYER_1 + i;
1558 player->present = FALSE;
1559 player->active = FALSE;
1562 player->effective_action = 0;
1563 player->programmed_action = 0;
1566 player->gems_still_needed = level.gems_needed;
1567 player->sokobanfields_still_needed = 0;
1568 player->lights_still_needed = 0;
1569 player->friends_still_needed = 0;
1571 for (j = 0; j < MAX_KEYS; j++)
1572 player->key[j] = FALSE;
1574 player->dynabomb_count = 0;
1575 player->dynabomb_size = 1;
1576 player->dynabombs_left = 0;
1577 player->dynabomb_xl = FALSE;
1579 player->MovDir = MV_NO_MOVING;
1582 player->GfxDir = MV_NO_MOVING;
1583 player->GfxAction = ACTION_DEFAULT;
1585 player->StepFrame = 0;
1587 player->use_murphy_graphic = FALSE;
1589 player->block_last_field = FALSE; /* initialized in InitPlayerField() */
1590 player->block_delay = -1; /* initialized in InitPlayerField() */
1592 player->can_fall_into_acid = CAN_MOVE_INTO_ACID(player->element_nr);
1594 player->actual_frame_counter = 0;
1596 player->step_counter = 0;
1598 player->last_move_dir = MV_NO_MOVING;
1600 player->is_waiting = FALSE;
1601 player->is_moving = FALSE;
1602 player->is_auto_moving = FALSE;
1603 player->is_digging = FALSE;
1604 player->is_snapping = FALSE;
1605 player->is_collecting = FALSE;
1606 player->is_pushing = FALSE;
1607 player->is_switching = FALSE;
1608 player->is_dropping = FALSE;
1610 player->is_bored = FALSE;
1611 player->is_sleeping = FALSE;
1613 player->frame_counter_bored = -1;
1614 player->frame_counter_sleeping = -1;
1616 player->anim_delay_counter = 0;
1617 player->post_delay_counter = 0;
1619 player->action_waiting = ACTION_DEFAULT;
1620 player->last_action_waiting = ACTION_DEFAULT;
1621 player->special_action_bored = ACTION_DEFAULT;
1622 player->special_action_sleeping = ACTION_DEFAULT;
1624 player->num_special_action_bored = 0;
1625 player->num_special_action_sleeping = 0;
1627 /* determine number of special actions for bored and sleeping animation */
1628 for (j = ACTION_BORING_1; j <= ACTION_BORING_LAST; j++)
1630 boolean found = FALSE;
1632 for (k = 0; k < NUM_DIRECTIONS; k++)
1633 if (el_act_dir2img(player->element_nr, j, k) !=
1634 el_act_dir2img(player->element_nr, ACTION_DEFAULT, k))
1638 player->num_special_action_bored++;
1642 for (j = ACTION_SLEEPING_1; j <= ACTION_SLEEPING_LAST; j++)
1644 boolean found = FALSE;
1646 for (k = 0; k < NUM_DIRECTIONS; k++)
1647 if (el_act_dir2img(player->element_nr, j, k) !=
1648 el_act_dir2img(player->element_nr, ACTION_DEFAULT, k))
1652 player->num_special_action_sleeping++;
1657 player->switch_x = -1;
1658 player->switch_y = -1;
1660 player->show_envelope = 0;
1662 player->move_delay = game.initial_move_delay;
1663 player->move_delay_value = game.initial_move_delay_value;
1665 player->move_delay_reset_counter = 0;
1667 #if USE_NEW_PUSH_DELAY
1668 player->push_delay = -1; /* initialized when pushing starts */
1669 player->push_delay_value = game.initial_push_delay_value;
1671 player->push_delay = 0;
1672 player->push_delay_value = game.initial_push_delay_value;
1675 player->drop_delay = 0;
1677 player->last_jx = player->last_jy = 0;
1678 player->jx = player->jy = 0;
1680 player->shield_normal_time_left = 0;
1681 player->shield_deadly_time_left = 0;
1683 player->inventory_infinite_element = EL_UNDEFINED;
1684 player->inventory_size = 0;
1686 DigField(player, 0, 0, 0, 0, 0, 0, DF_NO_PUSH);
1687 SnapField(player, 0, 0);
1689 player->LevelSolved = FALSE;
1690 player->GameOver = FALSE;
1693 network_player_action_received = FALSE;
1695 #if defined(NETWORK_AVALIABLE)
1696 /* initial null action */
1697 if (network_playing)
1698 SendToServer_MovePlayer(MV_NO_MOVING);
1706 TimeLeft = level.time;
1709 ScreenMovDir = MV_NO_MOVING;
1713 ScrollStepSize = 0; /* will be correctly initialized by ScrollScreen() */
1715 AllPlayersGone = FALSE;
1717 game.yamyam_content_nr = 0;
1718 game.magic_wall_active = FALSE;
1719 game.magic_wall_time_left = 0;
1720 game.light_time_left = 0;
1721 game.timegate_time_left = 0;
1722 game.switchgate_pos = 0;
1723 game.balloon_dir = MV_NO_MOVING;
1724 game.gravity = level.initial_gravity;
1725 game.explosions_delayed = TRUE;
1727 game.envelope_active = FALSE;
1729 for (i = 0; i < NUM_BELTS; i++)
1731 game.belt_dir[i] = MV_NO_MOVING;
1732 game.belt_dir_nr[i] = 3; /* not moving, next moving left */
1735 for (i = 0; i < MAX_NUM_AMOEBA; i++)
1736 AmoebaCnt[i] = AmoebaCnt2[i] = 0;
1738 for (x = 0; x < lev_fieldx; x++)
1740 for (y = 0; y < lev_fieldy; y++)
1742 Feld[x][y] = level.field[x][y];
1743 MovPos[x][y] = MovDir[x][y] = MovDelay[x][y] = 0;
1744 ChangeDelay[x][y] = 0;
1745 ChangePage[x][y] = -1;
1746 Store[x][y] = Store2[x][y] = StorePlayer[x][y] = Back[x][y] = 0;
1748 WasJustMoving[x][y] = 0;
1749 WasJustFalling[x][y] = 0;
1750 CheckCollision[x][y] = 0;
1752 Pushed[x][y] = FALSE;
1754 Changed[x][y] = CE_BITMASK_DEFAULT;
1755 ChangeEvent[x][y] = CE_BITMASK_DEFAULT;
1757 ExplodePhase[x][y] = 0;
1758 ExplodeDelay[x][y] = 0;
1759 ExplodeField[x][y] = EX_TYPE_NONE;
1761 RunnerVisit[x][y] = 0;
1762 PlayerVisit[x][y] = 0;
1765 GfxRandom[x][y] = INIT_GFX_RANDOM();
1766 GfxElement[x][y] = EL_UNDEFINED;
1767 GfxAction[x][y] = ACTION_DEFAULT;
1768 GfxDir[x][y] = MV_NO_MOVING;
1772 for (y = 0; y < lev_fieldy; y++)
1774 for (x = 0; x < lev_fieldx; x++)
1776 if (emulate_bd && !IS_BD_ELEMENT(Feld[x][y]))
1778 if (emulate_sb && !IS_SB_ELEMENT(Feld[x][y]))
1780 if (emulate_sp && !IS_SP_ELEMENT(Feld[x][y]))
1783 InitField(x, y, TRUE);
1789 game.emulation = (emulate_bd ? EMU_BOULDERDASH :
1790 emulate_sb ? EMU_SOKOBAN :
1791 emulate_sp ? EMU_SUPAPLEX : EMU_NONE);
1793 /* initialize explosion and ignition delay */
1794 for (i = 0; i < MAX_NUM_ELEMENTS; i++)
1796 if (!IS_CUSTOM_ELEMENT(i))
1799 int delay = (((IS_SP_ELEMENT(i) && i != EL_EMPTY_SPACE) &&
1800 game.engine_version >= VERSION_IDENT(3,1,0,0)) ||
1801 game.emulation == EMU_SUPAPLEX ? 3 : 2);
1802 int last_phase = (num_phase + 1) * delay;
1803 int half_phase = (num_phase / 2) * delay;
1805 element_info[i].explosion_delay = last_phase - 1;
1806 element_info[i].ignition_delay = half_phase;
1809 if (i == EL_BLACK_ORB)
1810 element_info[i].ignition_delay = 0;
1812 if (i == EL_BLACK_ORB)
1813 element_info[i].ignition_delay = 1;
1818 if (element_info[i].explosion_delay < 1) /* !!! check again !!! */
1819 element_info[i].explosion_delay = 1;
1821 if (element_info[i].ignition_delay < 1) /* !!! check again !!! */
1822 element_info[i].ignition_delay = 1;
1826 /* correct non-moving belts to start moving left */
1827 for (i = 0; i < NUM_BELTS; i++)
1828 if (game.belt_dir[i] == MV_NO_MOVING)
1829 game.belt_dir_nr[i] = 3; /* not moving, next moving left */
1831 /* check if any connected player was not found in playfield */
1832 for (i = 0; i < MAX_PLAYERS; i++)
1834 struct PlayerInfo *player = &stored_player[i];
1836 if (player->connected && !player->present)
1838 for (j = 0; j < MAX_PLAYERS; j++)
1840 struct PlayerInfo *some_player = &stored_player[j];
1841 int jx = some_player->jx, jy = some_player->jy;
1843 /* assign first free player found that is present in the playfield */
1844 if (some_player->present && !some_player->connected)
1846 player->present = TRUE;
1847 player->active = TRUE;
1849 some_player->present = FALSE;
1850 some_player->active = FALSE;
1853 player->element_nr = some_player->element_nr;
1856 #if USE_NEW_BLOCK_STYLE
1857 player->block_last_field = some_player->block_last_field;
1858 player->block_delay = some_player->block_delay;
1861 StorePlayer[jx][jy] = player->element_nr;
1862 player->jx = player->last_jx = jx;
1863 player->jy = player->last_jy = jy;
1873 /* when playing a tape, eliminate all players which do not participate */
1875 for (i = 0; i < MAX_PLAYERS; i++)
1877 if (stored_player[i].active && !tape.player_participates[i])
1879 struct PlayerInfo *player = &stored_player[i];
1880 int jx = player->jx, jy = player->jy;
1882 player->active = FALSE;
1883 StorePlayer[jx][jy] = 0;
1884 Feld[jx][jy] = EL_EMPTY;
1888 else if (!options.network && !setup.team_mode) /* && !tape.playing */
1890 /* when in single player mode, eliminate all but the first active player */
1892 for (i = 0; i < MAX_PLAYERS; i++)
1894 if (stored_player[i].active)
1896 for (j = i + 1; j < MAX_PLAYERS; j++)
1898 if (stored_player[j].active)
1900 struct PlayerInfo *player = &stored_player[j];
1901 int jx = player->jx, jy = player->jy;
1903 player->active = FALSE;
1904 player->present = FALSE;
1906 StorePlayer[jx][jy] = 0;
1907 Feld[jx][jy] = EL_EMPTY;
1914 /* when recording the game, store which players take part in the game */
1917 for (i = 0; i < MAX_PLAYERS; i++)
1918 if (stored_player[i].active)
1919 tape.player_participates[i] = TRUE;
1924 for (i = 0; i < MAX_PLAYERS; i++)
1926 struct PlayerInfo *player = &stored_player[i];
1928 printf("Player %d: present == %d, connected == %d, active == %d.\n",
1933 if (local_player == player)
1934 printf("Player %d is local player.\n", i+1);
1938 if (BorderElement == EL_EMPTY)
1941 SBX_Right = lev_fieldx - SCR_FIELDX;
1943 SBY_Lower = lev_fieldy - SCR_FIELDY;
1948 SBX_Right = lev_fieldx - SCR_FIELDX + 1;
1950 SBY_Lower = lev_fieldy - SCR_FIELDY + 1;
1953 if (lev_fieldx + (SBX_Left == -1 ? 2 : 0) <= SCR_FIELDX)
1954 SBX_Left = SBX_Right = -1 * (SCR_FIELDX - lev_fieldx) / 2;
1956 if (lev_fieldy + (SBY_Upper == -1 ? 2 : 0) <= SCR_FIELDY)
1957 SBY_Upper = SBY_Lower = -1 * (SCR_FIELDY - lev_fieldy) / 2;
1959 /* if local player not found, look for custom element that might create
1960 the player (make some assumptions about the right custom element) */
1961 if (!local_player->present)
1963 int start_x = 0, start_y = 0;
1964 int found_rating = 0;
1965 int found_element = EL_UNDEFINED;
1967 for (y = 0; y < lev_fieldy; y++) for (x = 0; x < lev_fieldx; x++)
1969 int element = Feld[x][y];
1974 if (!IS_CUSTOM_ELEMENT(element))
1977 if (CAN_CHANGE(element))
1979 for (i = 0; i < element_info[element].num_change_pages; i++)
1981 content = element_info[element].change_page[i].target_element;
1982 is_player = ELEM_IS_PLAYER(content);
1984 if (is_player && (found_rating < 3 || element < found_element))
1990 found_element = element;
1995 for (yy = 0; yy < 3; yy++) for (xx = 0; xx < 3; xx++)
1997 content = element_info[element].content[xx][yy];
1998 is_player = ELEM_IS_PLAYER(content);
2000 if (is_player && (found_rating < 2 || element < found_element))
2002 start_x = x + xx - 1;
2003 start_y = y + yy - 1;
2006 found_element = element;
2009 if (!CAN_CHANGE(element))
2012 for (i = 0; i < element_info[element].num_change_pages; i++)
2014 content= element_info[element].change_page[i].target_content[xx][yy];
2015 is_player = ELEM_IS_PLAYER(content);
2017 if (is_player && (found_rating < 1 || element < found_element))
2019 start_x = x + xx - 1;
2020 start_y = y + yy - 1;
2023 found_element = element;
2029 scroll_x = (start_x < SBX_Left + MIDPOSX ? SBX_Left :
2030 start_x > SBX_Right + MIDPOSX ? SBX_Right :
2033 scroll_y = (start_y < SBY_Upper + MIDPOSY ? SBY_Upper :
2034 start_y > SBY_Lower + MIDPOSY ? SBY_Lower :
2040 scroll_x = (local_player->jx < SBX_Left + MIDPOSX ? SBX_Left :
2041 local_player->jx > SBX_Right + MIDPOSX ? SBX_Right :
2042 local_player->jx - MIDPOSX);
2044 scroll_y = (local_player->jy < SBY_Upper + MIDPOSY ? SBY_Upper :
2045 local_player->jy > SBY_Lower + MIDPOSY ? SBY_Lower :
2046 local_player->jy - MIDPOSY);
2048 scroll_x = SBX_Left;
2049 scroll_y = SBY_Upper;
2050 if (local_player->jx >= SBX_Left + MIDPOSX)
2051 scroll_x = (local_player->jx <= SBX_Right + MIDPOSX ?
2052 local_player->jx - MIDPOSX :
2054 if (local_player->jy >= SBY_Upper + MIDPOSY)
2055 scroll_y = (local_player->jy <= SBY_Lower + MIDPOSY ?
2056 local_player->jy - MIDPOSY :
2061 CloseDoor(DOOR_CLOSE_1);
2063 /* !!! FIX THIS (START) !!! */
2064 if (level.game_engine_type == GAME_ENGINE_TYPE_EM)
2066 InitGameEngine_EM();
2073 /* after drawing the level, correct some elements */
2074 if (game.timegate_time_left == 0)
2075 CloseAllOpenTimegates();
2077 if (setup.soft_scrolling)
2078 BlitBitmap(fieldbuffer, backbuffer, FX, FY, SXSIZE, SYSIZE, SX, SY);
2080 redraw_mask |= REDRAW_FROM_BACKBUFFER;
2083 /* !!! FIX THIS (END) !!! */
2085 /* copy default game door content to main double buffer */
2086 BlitBitmap(graphic_info[IMG_GLOBAL_DOOR].bitmap, drawto,
2087 DOOR_GFX_PAGEX5, DOOR_GFX_PAGEY1, DXSIZE, DYSIZE, DX, DY);
2089 DrawGameDoorValues();
2093 game_gadget[SOUND_CTRL_ID_MUSIC]->checked = setup.sound_music;
2094 game_gadget[SOUND_CTRL_ID_LOOPS]->checked = setup.sound_loops;
2095 game_gadget[SOUND_CTRL_ID_SIMPLE]->checked = setup.sound_simple;
2099 /* copy actual game door content to door double buffer for OpenDoor() */
2100 BlitBitmap(drawto, bitmap_db_door,
2101 DX, DY, DXSIZE, DYSIZE, DOOR_GFX_PAGEX1, DOOR_GFX_PAGEY1);
2103 OpenDoor(DOOR_OPEN_ALL);
2105 PlaySoundStereo(SND_GAME_STARTING, SOUND_MIDDLE);
2107 if (setup.sound_music)
2110 KeyboardAutoRepeatOffUnlessAutoplay();
2114 for (i = 0; i < MAX_PLAYERS; i++)
2115 printf("Player %d %sactive.\n",
2116 i + 1, (stored_player[i].active ? "" : "not "));
2120 printf("::: starting game [%d]\n", FrameCounter);
2124 void UpdateEngineValues(int actual_scroll_x, int actual_scroll_y)
2126 /* this is used for non-R'n'D game engines to update certain engine values */
2128 /* needed to determine if sounds are played within the visible screen area */
2129 scroll_x = actual_scroll_x;
2130 scroll_y = actual_scroll_y;
2133 void InitMovDir(int x, int y)
2135 int i, element = Feld[x][y];
2136 static int xy[4][2] =
2143 static int direction[3][4] =
2145 { MV_RIGHT, MV_UP, MV_LEFT, MV_DOWN },
2146 { MV_LEFT, MV_DOWN, MV_RIGHT, MV_UP },
2147 { MV_LEFT, MV_RIGHT, MV_UP, MV_DOWN }
2156 Feld[x][y] = EL_BUG;
2157 MovDir[x][y] = direction[0][element - EL_BUG_RIGHT];
2160 case EL_SPACESHIP_RIGHT:
2161 case EL_SPACESHIP_UP:
2162 case EL_SPACESHIP_LEFT:
2163 case EL_SPACESHIP_DOWN:
2164 Feld[x][y] = EL_SPACESHIP;
2165 MovDir[x][y] = direction[0][element - EL_SPACESHIP_RIGHT];
2168 case EL_BD_BUTTERFLY_RIGHT:
2169 case EL_BD_BUTTERFLY_UP:
2170 case EL_BD_BUTTERFLY_LEFT:
2171 case EL_BD_BUTTERFLY_DOWN:
2172 Feld[x][y] = EL_BD_BUTTERFLY;
2173 MovDir[x][y] = direction[0][element - EL_BD_BUTTERFLY_RIGHT];
2176 case EL_BD_FIREFLY_RIGHT:
2177 case EL_BD_FIREFLY_UP:
2178 case EL_BD_FIREFLY_LEFT:
2179 case EL_BD_FIREFLY_DOWN:
2180 Feld[x][y] = EL_BD_FIREFLY;
2181 MovDir[x][y] = direction[0][element - EL_BD_FIREFLY_RIGHT];
2184 case EL_PACMAN_RIGHT:
2186 case EL_PACMAN_LEFT:
2187 case EL_PACMAN_DOWN:
2188 Feld[x][y] = EL_PACMAN;
2189 MovDir[x][y] = direction[0][element - EL_PACMAN_RIGHT];
2192 case EL_SP_SNIKSNAK:
2193 MovDir[x][y] = MV_UP;
2196 case EL_SP_ELECTRON:
2197 MovDir[x][y] = MV_LEFT;
2204 Feld[x][y] = EL_MOLE;
2205 MovDir[x][y] = direction[2][element - EL_MOLE_LEFT];
2209 if (IS_CUSTOM_ELEMENT(element))
2211 struct ElementInfo *ei = &element_info[element];
2212 int move_direction_initial = ei->move_direction_initial;
2213 int move_pattern = ei->move_pattern;
2215 if (move_direction_initial == MV_START_PREVIOUS)
2217 if (MovDir[x][y] != MV_NO_MOVING)
2220 move_direction_initial = MV_START_AUTOMATIC;
2223 if (move_direction_initial == MV_START_RANDOM)
2224 MovDir[x][y] = 1 << RND(4);
2225 else if (move_direction_initial & MV_ANY_DIRECTION)
2226 MovDir[x][y] = move_direction_initial;
2227 else if (move_pattern == MV_ALL_DIRECTIONS ||
2228 move_pattern == MV_TURNING_LEFT ||
2229 move_pattern == MV_TURNING_RIGHT ||
2230 move_pattern == MV_TURNING_LEFT_RIGHT ||
2231 move_pattern == MV_TURNING_RIGHT_LEFT ||
2232 move_pattern == MV_TURNING_RANDOM)
2233 MovDir[x][y] = 1 << RND(4);
2234 else if (move_pattern == MV_HORIZONTAL)
2235 MovDir[x][y] = (RND(2) ? MV_LEFT : MV_RIGHT);
2236 else if (move_pattern == MV_VERTICAL)
2237 MovDir[x][y] = (RND(2) ? MV_UP : MV_DOWN);
2238 else if (move_pattern & MV_ANY_DIRECTION)
2239 MovDir[x][y] = element_info[element].move_pattern;
2240 else if (move_pattern == MV_ALONG_LEFT_SIDE ||
2241 move_pattern == MV_ALONG_RIGHT_SIDE)
2244 /* use random direction as default start direction */
2245 if (game.engine_version >= VERSION_IDENT(3,1,0,0))
2246 MovDir[x][y] = 1 << RND(4);
2249 for (i = 0; i < NUM_DIRECTIONS; i++)
2251 int x1 = x + xy[i][0];
2252 int y1 = y + xy[i][1];
2254 if (!IN_LEV_FIELD(x1, y1) || !IS_FREE(x1, y1))
2256 if (move_pattern == MV_ALONG_RIGHT_SIDE)
2257 MovDir[x][y] = direction[0][i];
2259 MovDir[x][y] = direction[1][i];
2268 MovDir[x][y] = 1 << RND(4);
2270 if (element != EL_BUG &&
2271 element != EL_SPACESHIP &&
2272 element != EL_BD_BUTTERFLY &&
2273 element != EL_BD_FIREFLY)
2276 for (i = 0; i < NUM_DIRECTIONS; i++)
2278 int x1 = x + xy[i][0];
2279 int y1 = y + xy[i][1];
2281 if (!IN_LEV_FIELD(x1, y1) || !IS_FREE(x1, y1))
2283 if (element == EL_BUG || element == EL_BD_BUTTERFLY)
2285 MovDir[x][y] = direction[0][i];
2288 else if (element == EL_SPACESHIP || element == EL_BD_FIREFLY ||
2289 element == EL_SP_SNIKSNAK || element == EL_SP_ELECTRON)
2291 MovDir[x][y] = direction[1][i];
2300 GfxDir[x][y] = MovDir[x][y];
2303 void InitAmoebaNr(int x, int y)
2306 int group_nr = AmoebeNachbarNr(x, y);
2310 for (i = 1; i < MAX_NUM_AMOEBA; i++)
2312 if (AmoebaCnt[i] == 0)
2320 AmoebaNr[x][y] = group_nr;
2321 AmoebaCnt[group_nr]++;
2322 AmoebaCnt2[group_nr]++;
2328 boolean raise_level = FALSE;
2330 if (local_player->MovPos)
2334 if (tape.auto_play) /* tape might already be stopped here */
2335 tape.auto_play_level_solved = TRUE;
2337 if (tape.playing && tape.auto_play)
2338 tape.auto_play_level_solved = TRUE;
2341 local_player->LevelSolved = FALSE;
2343 PlaySoundStereo(SND_GAME_WINNING, SOUND_MIDDLE);
2347 if (!tape.playing && setup.sound_loops)
2348 PlaySoundExt(SND_GAME_LEVELTIME_BONUS, SOUND_MAX_VOLUME, SOUND_MIDDLE,
2349 SND_CTRL_PLAY_LOOP);
2351 while (TimeLeft > 0)
2353 if (!tape.playing && !setup.sound_loops)
2354 PlaySoundStereo(SND_GAME_LEVELTIME_BONUS, SOUND_MIDDLE);
2355 if (TimeLeft > 0 && !(TimeLeft % 10))
2356 RaiseScore(level.score[SC_TIME_BONUS]);
2357 if (TimeLeft > 100 && !(TimeLeft % 10))
2362 DrawGameValue_Time(TimeLeft);
2370 if (!tape.playing && setup.sound_loops)
2371 StopSound(SND_GAME_LEVELTIME_BONUS);
2373 else if (level.time == 0) /* level without time limit */
2375 if (!tape.playing && setup.sound_loops)
2376 PlaySoundExt(SND_GAME_LEVELTIME_BONUS, SOUND_MAX_VOLUME, SOUND_MIDDLE,
2377 SND_CTRL_PLAY_LOOP);
2379 while (TimePlayed < 999)
2381 if (!tape.playing && !setup.sound_loops)
2382 PlaySoundStereo(SND_GAME_LEVELTIME_BONUS, SOUND_MIDDLE);
2383 if (TimePlayed < 999 && !(TimePlayed % 10))
2384 RaiseScore(level.score[SC_TIME_BONUS]);
2385 if (TimePlayed < 900 && !(TimePlayed % 10))
2390 DrawGameValue_Time(TimePlayed);
2398 if (!tape.playing && setup.sound_loops)
2399 StopSound(SND_GAME_LEVELTIME_BONUS);
2402 /* close exit door after last player */
2403 if ((Feld[ExitX][ExitY] == EL_EXIT_OPEN ||
2404 Feld[ExitX][ExitY] == EL_SP_EXIT_OPEN) && AllPlayersGone)
2406 int element = Feld[ExitX][ExitY];
2408 Feld[ExitX][ExitY] = (element == EL_EXIT_OPEN ? EL_EXIT_CLOSING :
2409 EL_SP_EXIT_CLOSING);
2411 PlayLevelSoundElementAction(ExitX, ExitY, element, ACTION_CLOSING);
2414 /* Hero disappears */
2415 DrawLevelField(ExitX, ExitY);
2421 CloseDoor(DOOR_CLOSE_1);
2426 SaveTape(tape.level_nr); /* Ask to save tape */
2429 if (level_nr == leveldir_current->handicap_level)
2431 leveldir_current->handicap_level++;
2432 SaveLevelSetup_SeriesInfo();
2435 if (level_editor_test_game)
2436 local_player->score = -1; /* no highscore when playing from editor */
2437 else if (level_nr < leveldir_current->last_level)
2438 raise_level = TRUE; /* advance to next level */
2440 if ((hi_pos = NewHiScore()) >= 0)
2442 game_status = GAME_MODE_SCORES;
2443 DrawHallOfFame(hi_pos);
2452 game_status = GAME_MODE_MAIN;
2469 LoadScore(level_nr);
2471 if (strcmp(setup.player_name, EMPTY_PLAYER_NAME) == 0 ||
2472 local_player->score < highscore[MAX_SCORE_ENTRIES - 1].Score)
2475 for (k = 0; k < MAX_SCORE_ENTRIES; k++)
2477 if (local_player->score > highscore[k].Score)
2479 /* player has made it to the hall of fame */
2481 if (k < MAX_SCORE_ENTRIES - 1)
2483 int m = MAX_SCORE_ENTRIES - 1;
2486 for (l = k; l < MAX_SCORE_ENTRIES; l++)
2487 if (!strcmp(setup.player_name, highscore[l].Name))
2489 if (m == k) /* player's new highscore overwrites his old one */
2493 for (l = m; l > k; l--)
2495 strcpy(highscore[l].Name, highscore[l - 1].Name);
2496 highscore[l].Score = highscore[l - 1].Score;
2503 strncpy(highscore[k].Name, setup.player_name, MAX_PLAYER_NAME_LEN);
2504 highscore[k].Name[MAX_PLAYER_NAME_LEN] = '\0';
2505 highscore[k].Score = local_player->score;
2511 else if (!strncmp(setup.player_name, highscore[k].Name,
2512 MAX_PLAYER_NAME_LEN))
2513 break; /* player already there with a higher score */
2519 SaveScore(level_nr);
2524 void InitPlayerGfxAnimation(struct PlayerInfo *player, int action, int dir)
2526 if (player->GfxAction != action || player->GfxDir != dir)
2529 printf("Player frame reset! (%d => %d, %d => %d)\n",
2530 player->GfxAction, action, player->GfxDir, dir);
2533 player->GfxAction = action;
2534 player->GfxDir = dir;
2536 player->StepFrame = 0;
2540 static void ResetRandomAnimationValue(int x, int y)
2542 GfxRandom[x][y] = INIT_GFX_RANDOM();
2545 static void ResetGfxAnimation(int x, int y)
2548 GfxAction[x][y] = ACTION_DEFAULT;
2549 GfxDir[x][y] = MovDir[x][y];
2552 void InitMovingField(int x, int y, int direction)
2554 int element = Feld[x][y];
2555 int dx = (direction == MV_LEFT ? -1 : direction == MV_RIGHT ? +1 : 0);
2556 int dy = (direction == MV_UP ? -1 : direction == MV_DOWN ? +1 : 0);
2560 if (!WasJustMoving[x][y] || direction != MovDir[x][y])
2561 ResetGfxAnimation(x, y);
2563 MovDir[newx][newy] = MovDir[x][y] = direction;
2564 GfxDir[x][y] = direction;
2566 if (Feld[newx][newy] == EL_EMPTY)
2567 Feld[newx][newy] = EL_BLOCKED;
2569 if (direction == MV_DOWN && CAN_FALL(element))
2570 GfxAction[x][y] = ACTION_FALLING;
2572 GfxAction[x][y] = ACTION_MOVING;
2574 GfxFrame[newx][newy] = GfxFrame[x][y];
2575 GfxRandom[newx][newy] = GfxRandom[x][y];
2576 GfxAction[newx][newy] = GfxAction[x][y];
2577 GfxDir[newx][newy] = GfxDir[x][y];
2580 void Moving2Blocked(int x, int y, int *goes_to_x, int *goes_to_y)
2582 int direction = MovDir[x][y];
2583 int newx = x + (direction == MV_LEFT ? -1 : direction == MV_RIGHT ? +1 : 0);
2584 int newy = y + (direction == MV_UP ? -1 : direction == MV_DOWN ? +1 : 0);
2590 void Blocked2Moving(int x, int y, int *comes_from_x, int *comes_from_y)
2592 int oldx = x, oldy = y;
2593 int direction = MovDir[x][y];
2595 if (direction == MV_LEFT)
2597 else if (direction == MV_RIGHT)
2599 else if (direction == MV_UP)
2601 else if (direction == MV_DOWN)
2604 *comes_from_x = oldx;
2605 *comes_from_y = oldy;
2608 int MovingOrBlocked2Element(int x, int y)
2610 int element = Feld[x][y];
2612 if (element == EL_BLOCKED)
2616 Blocked2Moving(x, y, &oldx, &oldy);
2617 return Feld[oldx][oldy];
2623 static int MovingOrBlocked2ElementIfNotLeaving(int x, int y)
2625 /* like MovingOrBlocked2Element(), but if element is moving
2626 and (x,y) is the field the moving element is just leaving,
2627 return EL_BLOCKED instead of the element value */
2628 int element = Feld[x][y];
2630 if (IS_MOVING(x, y))
2632 if (element == EL_BLOCKED)
2636 Blocked2Moving(x, y, &oldx, &oldy);
2637 return Feld[oldx][oldy];
2646 static void RemoveField(int x, int y)
2648 Feld[x][y] = EL_EMPTY;
2655 ChangeDelay[x][y] = 0;
2656 ChangePage[x][y] = -1;
2657 Pushed[x][y] = FALSE;
2660 ExplodeField[x][y] = EX_TYPE_NONE;
2663 GfxElement[x][y] = EL_UNDEFINED;
2664 GfxAction[x][y] = ACTION_DEFAULT;
2665 GfxDir[x][y] = MV_NO_MOVING;
2668 void RemoveMovingField(int x, int y)
2670 int oldx = x, oldy = y, newx = x, newy = y;
2671 int element = Feld[x][y];
2672 int next_element = EL_UNDEFINED;
2674 if (element != EL_BLOCKED && !IS_MOVING(x, y))
2677 if (IS_MOVING(x, y))
2679 Moving2Blocked(x, y, &newx, &newy);
2681 if (Feld[newx][newy] != EL_BLOCKED)
2684 if (Feld[newx][newy] != EL_BLOCKED)
2686 /* element is moving, but target field is not free (blocked), but
2687 already occupied by something different (example: acid pool);
2688 in this case, only remove the moving field, but not the target */
2690 RemoveField(oldx, oldy);
2692 Store[oldx][oldy] = Store2[oldx][oldy] = 0;
2694 DrawLevelField(oldx, oldy);
2700 else if (element == EL_BLOCKED)
2702 Blocked2Moving(x, y, &oldx, &oldy);
2703 if (!IS_MOVING(oldx, oldy))
2707 if (element == EL_BLOCKED &&
2708 (Feld[oldx][oldy] == EL_QUICKSAND_EMPTYING ||
2709 Feld[oldx][oldy] == EL_MAGIC_WALL_EMPTYING ||
2710 Feld[oldx][oldy] == EL_BD_MAGIC_WALL_EMPTYING ||
2711 Feld[oldx][oldy] == EL_AMOEBA_DROPPING))
2712 next_element = get_next_element(Feld[oldx][oldy]);
2714 RemoveField(oldx, oldy);
2715 RemoveField(newx, newy);
2717 Store[oldx][oldy] = Store2[oldx][oldy] = 0;
2719 if (next_element != EL_UNDEFINED)
2720 Feld[oldx][oldy] = next_element;
2722 DrawLevelField(oldx, oldy);
2723 DrawLevelField(newx, newy);
2726 void DrawDynamite(int x, int y)
2728 int sx = SCREENX(x), sy = SCREENY(y);
2729 int graphic = el2img(Feld[x][y]);
2732 if (!IN_SCR_FIELD(sx, sy) || IS_PLAYER(x, y))
2735 if (IS_WALKABLE_INSIDE(Back[x][y]))
2739 DrawGraphic(sx, sy, el2img(Back[x][y]), 0);
2740 else if (Store[x][y])
2741 DrawGraphic(sx, sy, el2img(Store[x][y]), 0);
2743 frame = getGraphicAnimationFrame(graphic, GfxFrame[x][y]);
2746 if (Back[x][y] || Store[x][y])
2747 DrawGraphicThruMask(sx, sy, graphic, frame);
2749 DrawGraphic(sx, sy, graphic, frame);
2751 if (game.emulation == EMU_SUPAPLEX)
2752 DrawGraphic(sx, sy, IMG_SP_DISK_RED, frame);
2753 else if (Store[x][y])
2754 DrawGraphicThruMask(sx, sy, graphic, frame);
2756 DrawGraphic(sx, sy, graphic, frame);
2760 void CheckDynamite(int x, int y)
2762 if (MovDelay[x][y] != 0) /* dynamite is still waiting to explode */
2766 if (MovDelay[x][y] != 0)
2769 PlayLevelSoundActionIfLoop(x, y, ACTION_ACTIVE);
2776 StopLevelSoundActionIfLoop(x, y, ACTION_ACTIVE);
2778 if (Feld[x][y] == EL_DYNAMITE_ACTIVE ||
2779 Feld[x][y] == EL_SP_DISK_RED_ACTIVE)
2780 StopSound(SND_DYNAMITE_ACTIVE);
2782 StopSound(SND_DYNABOMB_ACTIVE);
2788 void DrawRelocatePlayer(struct PlayerInfo *player)
2790 boolean ffwd_delay = (tape.playing && tape.fast_forward);
2791 boolean no_delay = (tape.warp_forward);
2792 int frame_delay_value = (ffwd_delay ? FfwdFrameDelay : GameFrameDelay);
2793 int wait_delay_value = (no_delay ? 0 : frame_delay_value);
2794 int jx = player->jx;
2795 int jy = player->jy;
2797 if (level.instant_relocation)
2800 int offset = (setup.scroll_delay ? 3 : 0);
2802 if (!IN_VIS_FIELD(SCREENX(jx), SCREENY(jy)))
2804 scroll_x = (local_player->jx < SBX_Left + MIDPOSX ? SBX_Left :
2805 local_player->jx > SBX_Right + MIDPOSX ? SBX_Right :
2806 local_player->jx - MIDPOSX);
2808 scroll_y = (local_player->jy < SBY_Upper + MIDPOSY ? SBY_Upper :
2809 local_player->jy > SBY_Lower + MIDPOSY ? SBY_Lower :
2810 local_player->jy - MIDPOSY);
2814 if ((player->MovDir == MV_LEFT && scroll_x > jx - MIDPOSX + offset) ||
2815 (player->MovDir == MV_RIGHT && scroll_x < jx - MIDPOSX - offset))
2816 scroll_x = jx - MIDPOSX + (scroll_x < jx-MIDPOSX ? -offset : +offset);
2818 if ((player->MovDir == MV_UP && scroll_y > jy - MIDPOSY + offset) ||
2819 (player->MovDir == MV_DOWN && scroll_y < jy - MIDPOSY - offset))
2820 scroll_y = jy - MIDPOSY + (scroll_y < jy-MIDPOSY ? -offset : +offset);
2822 /* don't scroll over playfield boundaries */
2823 if (scroll_x < SBX_Left || scroll_x > SBX_Right)
2824 scroll_x = (scroll_x < SBX_Left ? SBX_Left : SBX_Right);
2826 /* don't scroll over playfield boundaries */
2827 if (scroll_y < SBY_Upper || scroll_y > SBY_Lower)
2828 scroll_y = (scroll_y < SBY_Upper ? SBY_Upper : SBY_Lower);
2831 scroll_x += (local_player->jx - old_jx);
2832 scroll_y += (local_player->jy - old_jy);
2834 /* don't scroll over playfield boundaries */
2835 if (scroll_x < SBX_Left || scroll_x > SBX_Right)
2836 scroll_x = (scroll_x < SBX_Left ? SBX_Left : SBX_Right);
2838 /* don't scroll over playfield boundaries */
2839 if (scroll_y < SBY_Upper || scroll_y > SBY_Lower)
2840 scroll_y = (scroll_y < SBY_Upper ? SBY_Upper : SBY_Lower);
2843 RedrawPlayfield(TRUE, 0,0,0,0);
2849 int offset = (setup.scroll_delay ? 3 : 0);
2851 int scroll_xx = -999, scroll_yy = -999;
2853 ScrollScreen(NULL, SCROLL_GO_ON); /* scroll last frame to full tile */
2855 while (scroll_xx != scroll_x || scroll_yy != scroll_y)
2858 int fx = FX, fy = FY;
2860 scroll_xx = (local_player->jx < SBX_Left + MIDPOSX ? SBX_Left :
2861 local_player->jx > SBX_Right + MIDPOSX ? SBX_Right :
2862 local_player->jx - MIDPOSX);
2864 scroll_yy = (local_player->jy < SBY_Upper + MIDPOSY ? SBY_Upper :
2865 local_player->jy > SBY_Lower + MIDPOSY ? SBY_Lower :
2866 local_player->jy - MIDPOSY);
2868 dx = (scroll_xx < scroll_x ? +1 : scroll_xx > scroll_x ? -1 : 0);
2869 dy = (scroll_yy < scroll_y ? +1 : scroll_yy > scroll_y ? -1 : 0);
2872 if (dx == 0 && dy == 0) /* no scrolling needed at all */
2875 if (scroll_xx == scroll_x && scroll_yy == scroll_y)
2882 fx += dx * TILEX / 2;
2883 fy += dy * TILEY / 2;
2885 ScrollLevel(dx, dy);
2888 /* scroll in two steps of half tile size to make things smoother */
2889 BlitBitmap(drawto_field, window, fx, fy, SXSIZE, SYSIZE, SX, SY);
2891 Delay(wait_delay_value);
2893 /* scroll second step to align at full tile size */
2895 Delay(wait_delay_value);
2898 int scroll_xx = -999, scroll_yy = -999;
2900 ScrollScreen(NULL, SCROLL_GO_ON); /* scroll last frame to full tile */
2902 while (scroll_xx != scroll_x || scroll_yy != scroll_y)
2905 int fx = FX, fy = FY;
2907 scroll_xx = (local_player->jx < SBX_Left + MIDPOSX ? SBX_Left :
2908 local_player->jx > SBX_Right + MIDPOSX ? SBX_Right :
2909 local_player->jx - MIDPOSX);
2911 scroll_yy = (local_player->jy < SBY_Upper + MIDPOSY ? SBY_Upper :
2912 local_player->jy > SBY_Lower + MIDPOSY ? SBY_Lower :
2913 local_player->jy - MIDPOSY);
2915 dx = (scroll_xx < scroll_x ? +1 : scroll_xx > scroll_x ? -1 : 0);
2916 dy = (scroll_yy < scroll_y ? +1 : scroll_yy > scroll_y ? -1 : 0);
2919 if (dx == 0 && dy == 0) /* no scrolling needed at all */
2922 if (scroll_xx == scroll_x && scroll_yy == scroll_y)
2929 fx += dx * TILEX / 2;
2930 fy += dy * TILEY / 2;
2932 ScrollLevel(dx, dy);
2935 /* scroll in two steps of half tile size to make things smoother */
2936 BlitBitmap(drawto_field, window, fx, fy, SXSIZE, SYSIZE, SX, SY);
2938 Delay(wait_delay_value);
2940 /* scroll second step to align at full tile size */
2942 Delay(wait_delay_value);
2948 Delay(wait_delay_value);
2952 void RelocatePlayer(int jx, int jy, int el_player_raw)
2955 int el_player = GET_VALID_PLAYER_ELEMENT(el_player_raw);
2957 int el_player = (el_player_raw == EL_SP_MURPHY ? EL_PLAYER_1 :el_player_raw);
2959 struct PlayerInfo *player = &stored_player[el_player - EL_PLAYER_1];
2960 boolean ffwd_delay = (tape.playing && tape.fast_forward);
2961 boolean no_delay = (tape.warp_forward);
2962 int frame_delay_value = (ffwd_delay ? FfwdFrameDelay : GameFrameDelay);
2963 int wait_delay_value = (no_delay ? 0 : frame_delay_value);
2964 int old_jx = player->jx;
2965 int old_jy = player->jy;
2966 int old_element = Feld[old_jx][old_jy];
2967 int element = Feld[jx][jy];
2968 boolean player_relocated = (old_jx != jx || old_jy != jy);
2970 int move_dir_horiz = (jx < old_jx ? MV_LEFT : jx > old_jx ? MV_RIGHT : 0);
2971 int move_dir_vert = (jy < old_jy ? MV_UP : jy > old_jy ? MV_DOWN : 0);
2973 int enter_side_horiz = MV_DIR_OPPOSITE(move_dir_horiz);
2974 int enter_side_vert = MV_DIR_OPPOSITE(move_dir_vert);
2975 int leave_side_horiz = move_dir_horiz;
2976 int leave_side_vert = move_dir_vert;
2978 static int trigger_sides[4][2] =
2980 /* enter side leave side */
2981 { CH_SIDE_RIGHT, CH_SIDE_LEFT }, /* moving left */
2982 { CH_SIDE_LEFT, CH_SIDE_RIGHT }, /* moving right */
2983 { CH_SIDE_BOTTOM, CH_SIDE_TOP }, /* moving up */
2984 { CH_SIDE_TOP, CH_SIDE_BOTTOM } /* moving down */
2986 int enter_side_horiz = trigger_sides[MV_DIR_BIT(move_dir_horiz)][0];
2987 int enter_side_vert = trigger_sides[MV_DIR_BIT(move_dir_vert)][0];
2988 int leave_side_horiz = trigger_sides[MV_DIR_BIT(move_dir_horiz)][1];
2989 int leave_side_vert = trigger_sides[MV_DIR_BIT(move_dir_vert)][1];
2991 int enter_side = enter_side_horiz | enter_side_vert;
2992 int leave_side = leave_side_horiz | leave_side_vert;
2994 if (player->GameOver) /* do not reanimate dead player */
2997 if (!player_relocated) /* no need to relocate the player */
3000 if (IS_PLAYER(jx, jy)) /* player already placed at new position */
3002 RemoveField(jx, jy); /* temporarily remove newly placed player */
3003 DrawLevelField(jx, jy);
3006 if (player->present)
3008 while (player->MovPos)
3010 ScrollPlayer(player, SCROLL_GO_ON);
3011 ScrollScreen(NULL, SCROLL_GO_ON);
3013 #if USE_NEW_MOVE_DELAY
3014 AdvanceFrameAndPlayerCounters(player->index_nr);
3022 Delay(wait_delay_value);
3025 DrawPlayer(player); /* needed here only to cleanup last field */
3026 DrawLevelField(player->jx, player->jy); /* remove player graphic */
3028 player->is_moving = FALSE;
3032 if (IS_CUSTOM_ELEMENT(old_element))
3033 CheckElementChangeByPlayer(old_jx, old_jy, old_element,
3035 player->index_bit, leave_side);
3037 CheckTriggeredElementChangeByPlayer(old_jx, old_jy, old_element,
3039 player->index_bit, leave_side);
3042 Feld[jx][jy] = el_player;
3043 InitPlayerField(jx, jy, el_player, TRUE);
3045 if (!ELEM_IS_PLAYER(element)) /* player may be set on walkable element */
3047 Feld[jx][jy] = element;
3048 InitField(jx, jy, FALSE);
3052 if (player == local_player) /* only visually relocate local player */
3053 DrawRelocatePlayer(player);
3057 TestIfHeroTouchesBadThing(jx, jy);
3058 TestIfPlayerTouchesCustomElement(jx, jy);
3062 printf("::: %d,%d: %d\n", jx, jy-1, Changed[jx][jy-1]);
3067 /* needed to allow change of walkable custom element by entering player */
3068 if (!(Changed[jx][jy] & CH_EVENT_BIT(CE_ENTERED_BY_PLAYER)))
3069 Changed[jx][jy] = 0; /* allow another change (but prevent loop) */
3071 /* needed to allow change of walkable custom element by entering player */
3072 Changed[jx][jy] = 0; /* allow another change */
3077 printf("::: player entering %d, %d from %s ...\n", jx, jy,
3078 enter_side == MV_LEFT ? "left" :
3079 enter_side == MV_RIGHT ? "right" :
3080 enter_side == MV_UP ? "top" :
3081 enter_side == MV_DOWN ? "bottom" : "oops! no idea!");
3085 if (IS_CUSTOM_ELEMENT(element))
3086 CheckElementChangeByPlayer(jx, jy, element, CE_ENTERED_BY_PLAYER,
3087 player->index_bit, enter_side);
3089 CheckTriggeredElementChangeByPlayer(jx, jy, element,
3090 CE_OTHER_GETS_ENTERED,
3091 player->index_bit, enter_side);
3095 void Explode(int ex, int ey, int phase, int mode)
3102 /* !!! eliminate this variable !!! */
3103 int delay = (game.emulation == EMU_SUPAPLEX ? 3 : 2);
3108 int last_phase = num_phase * delay;
3109 int half_phase = (num_phase / 2) * delay;
3110 int first_phase_after_start = EX_PHASE_START + 1;
3114 if (game.explosions_delayed)
3116 ExplodeField[ex][ey] = mode;
3120 if (phase == EX_PHASE_START) /* initialize 'Store[][]' field */
3122 int center_element = Feld[ex][ey];
3125 printf("::: start explosion %d,%d [%d]\n", ex, ey, FrameCounter);
3129 /* --- This is only really needed (and now handled) in "Impact()". --- */
3130 /* do not explode moving elements that left the explode field in time */
3131 if (game.engine_version >= VERSION_IDENT(2,2,0,7) &&
3132 center_element == EL_EMPTY &&
3133 (mode == EX_TYPE_NORMAL || mode == EX_TYPE_CENTER))
3137 if (mode == EX_TYPE_NORMAL || mode == EX_TYPE_CENTER)
3138 PlayLevelSoundAction(ex, ey, ACTION_EXPLODING);
3140 /* remove things displayed in background while burning dynamite */
3141 if (Back[ex][ey] != EL_EMPTY && !IS_INDESTRUCTIBLE(Back[ex][ey]))
3144 if (IS_MOVING(ex, ey) || IS_BLOCKED(ex, ey))
3146 /* put moving element to center field (and let it explode there) */
3147 center_element = MovingOrBlocked2Element(ex, ey);
3148 RemoveMovingField(ex, ey);
3149 Feld[ex][ey] = center_element;
3155 last_phase = element_info[center_element].explosion_delay + 1;
3157 last_phase = element_info[center_element].explosion_delay;
3161 printf("::: %d -> %d\n", center_element, last_phase);
3165 for (y = ey - 1; y <= ey + 1; y++) for (x = ex - 1; x <= ex + 1; x++)
3167 int xx = x - ex + 1;
3168 int yy = y - ey + 1;
3173 if (!IN_LEV_FIELD(x, y) ||
3174 (mode & EX_TYPE_SINGLE_TILE && (x != ex || y != ey)) ||
3175 (mode == EX_TYPE_CROSS && (x != ex && y != ey)))
3178 if (!IN_LEV_FIELD(x, y) ||
3179 (mode != EX_TYPE_NORMAL && (x != ex || y != ey)))
3183 if (!IN_LEV_FIELD(x, y) ||
3184 ((mode != EX_TYPE_NORMAL ||
3185 center_element == EL_AMOEBA_TO_DIAMOND) &&
3186 (x != ex || y != ey)))
3190 element = Feld[x][y];
3192 if (IS_MOVING(x, y) || IS_BLOCKED(x, y))
3194 element = MovingOrBlocked2Element(x, y);
3196 if (!IS_EXPLOSION_PROOF(element))
3197 RemoveMovingField(x, y);
3203 if (IS_EXPLOSION_PROOF(element))
3206 /* indestructible elements can only explode in center (but not flames) */
3208 if ((IS_EXPLOSION_PROOF(element) && (x != ex || y != ey ||
3209 mode == EX_TYPE_BORDER)) ||
3210 element == EL_FLAMES)
3213 if ((IS_EXPLOSION_PROOF(element) && (x != ex || y != ey)) ||
3214 element == EL_FLAMES)
3220 if ((IS_INDESTRUCTIBLE(element) &&
3221 (game.engine_version < VERSION_IDENT(2,2,0,0) ||
3222 (!IS_WALKABLE_OVER(element) && !IS_WALKABLE_UNDER(element)))) ||
3223 element == EL_FLAMES)
3228 if (IS_PLAYER(x, y) && SHIELD_ON(PLAYERINFO(x, y)) &&
3229 (game.engine_version < VERSION_IDENT(3,1,0,0) ||
3230 (x == ex && y == ey && mode != EX_TYPE_BORDER)))
3232 if (IS_PLAYER(x, y) && SHIELD_ON(PLAYERINFO(x, y)))
3235 if (IS_ACTIVE_BOMB(element))
3237 /* re-activate things under the bomb like gate or penguin */
3239 Feld[x][y] = (Back[x][y] ? Back[x][y] : EL_EMPTY);
3242 Feld[x][y] = (Store[x][y] ? Store[x][y] : EL_EMPTY);
3247 printf("::: %d,%d: %d %s [%d, %d]\n", x, y, Feld[x][y],
3248 element_info[Feld[x][y]].token_name,
3249 Store[x][y], Store2[x][y]);
3256 /* save walkable background elements while explosion on same tile */
3258 if (IS_INDESTRUCTIBLE(element))
3259 Back[x][y] = element;
3263 if (IS_WALKABLE(element) && IS_INDESTRUCTIBLE(element) &&
3264 (x != ex || y != ey || mode == EX_TYPE_BORDER))
3265 Back[x][y] = element;
3267 if (IS_WALKABLE(element) && IS_INDESTRUCTIBLE(element) &&
3268 (x != ex || y != ey))
3269 Back[x][y] = element;
3272 if (IS_WALKABLE(element) && IS_INDESTRUCTIBLE(element))
3273 Back[x][y] = element;
3277 /* ignite explodable elements reached by other explosion */
3278 if (element == EL_EXPLOSION)
3279 element = Store2[x][y];
3282 if (AmoebaNr[x][y] &&
3283 (element == EL_AMOEBA_FULL ||
3284 element == EL_BD_AMOEBA ||
3285 element == EL_AMOEBA_GROWING))
3287 AmoebaCnt[AmoebaNr[x][y]]--;
3288 AmoebaCnt2[AmoebaNr[x][y]]--;
3294 if (IS_PLAYER(ex, ey) && !PLAYER_EXPLOSION_PROTECTED(ex, ey))
3296 switch(StorePlayer[ex][ey])
3299 Store[x][y] = EL_PLAYER_IS_EXPLODING_2;
3302 Store[x][y] = EL_PLAYER_IS_EXPLODING_3;
3305 Store[x][y] = EL_PLAYER_IS_EXPLODING_4;
3309 Store[x][y] = EL_PLAYER_IS_EXPLODING_1;
3314 if (PLAYERINFO(ex, ey)->use_murphy_graphic)
3315 Store[x][y] = EL_EMPTY;
3317 if (game.emulation == EMU_SUPAPLEX)
3318 Store[x][y] = EL_EMPTY;
3321 else if (center_element == EL_MOLE)
3322 Store[x][y] = EL_EMERALD_RED;
3323 else if (center_element == EL_PENGUIN)
3324 Store[x][y] = EL_EMERALD_PURPLE;
3325 else if (center_element == EL_BUG)
3326 Store[x][y] = ((x == ex && y == ey) ? EL_DIAMOND : EL_EMERALD);
3327 else if (center_element == EL_BD_BUTTERFLY)
3328 Store[x][y] = EL_BD_DIAMOND;
3329 else if (center_element == EL_SP_ELECTRON)
3330 Store[x][y] = EL_SP_INFOTRON;
3331 else if (center_element == EL_AMOEBA_TO_DIAMOND)
3332 Store[x][y] = level.amoeba_content;
3333 else if (center_element == EL_YAMYAM)
3334 Store[x][y] = level.yamyam_content[game.yamyam_content_nr][xx][yy];
3335 else if (IS_CUSTOM_ELEMENT(center_element) &&
3336 element_info[center_element].content[xx][yy] != EL_EMPTY)
3337 Store[x][y] = element_info[center_element].content[xx][yy];
3338 else if (element == EL_WALL_EMERALD)
3339 Store[x][y] = EL_EMERALD;
3340 else if (element == EL_WALL_DIAMOND)
3341 Store[x][y] = EL_DIAMOND;
3342 else if (element == EL_WALL_BD_DIAMOND)
3343 Store[x][y] = EL_BD_DIAMOND;
3344 else if (element == EL_WALL_EMERALD_YELLOW)
3345 Store[x][y] = EL_EMERALD_YELLOW;
3346 else if (element == EL_WALL_EMERALD_RED)
3347 Store[x][y] = EL_EMERALD_RED;
3348 else if (element == EL_WALL_EMERALD_PURPLE)
3349 Store[x][y] = EL_EMERALD_PURPLE;
3350 else if (element == EL_WALL_PEARL)
3351 Store[x][y] = EL_PEARL;
3352 else if (element == EL_WALL_CRYSTAL)
3353 Store[x][y] = EL_CRYSTAL;
3354 else if (IS_CUSTOM_ELEMENT(element) && !CAN_EXPLODE(element))
3355 Store[x][y] = element_info[element].content[1][1];
3357 Store[x][y] = EL_EMPTY;
3359 if (x != ex || y != ey || mode == EX_TYPE_BORDER ||
3360 center_element == EL_AMOEBA_TO_DIAMOND)
3361 Store2[x][y] = element;
3364 printf("::: %d,%d: %d %s\n", x, y, Store2[x][y],
3365 element_info[Store2[x][y]].token_name);
3369 if (AmoebaNr[x][y] &&
3370 (element == EL_AMOEBA_FULL ||
3371 element == EL_BD_AMOEBA ||
3372 element == EL_AMOEBA_GROWING))
3374 AmoebaCnt[AmoebaNr[x][y]]--;
3375 AmoebaCnt2[AmoebaNr[x][y]]--;
3381 MovDir[x][y] = MovPos[x][y] = 0;
3382 GfxDir[x][y] = MovDir[x][y];
3387 Feld[x][y] = EL_EXPLOSION;
3389 GfxElement[x][y] = center_element;
3391 GfxElement[x][y] = EL_UNDEFINED;
3394 ExplodePhase[x][y] = 1;
3396 ExplodeDelay[x][y] = last_phase;
3401 GfxFrame[x][y] = 0; /* animation does not start until next frame */
3403 GfxFrame[x][y] = -1; /* animation does not start until next frame */
3410 if (center_element == EL_YAMYAM)
3411 game.yamyam_content_nr =
3412 (game.yamyam_content_nr + 1) % level.num_yamyam_contents;
3415 printf("::: %d,%d: %d %s [%d]\n", ex + 1, ey, Feld[ex + 1][ey],
3416 element_info[Feld[ex + 1][ey]].token_name, Store2[ex + 1][ey]);
3430 GfxFrame[x][y] = 0; /* restart explosion animation */
3434 printf(":X: phase == %d [%d]\n", phase, GfxFrame[x][y]);
3438 last_phase = ExplodeDelay[x][y];
3441 ExplodePhase[x][y] = (phase < last_phase ? phase + 1 : 0);
3445 /* activate this even in non-DEBUG version until cause for crash in
3446 getGraphicAnimationFrame() (see below) is found and eliminated */
3450 if (GfxElement[x][y] == EL_UNDEFINED)
3453 printf("Explode(): x = %d, y = %d: GfxElement == EL_UNDEFINED\n", x, y);
3454 printf("Explode(): This should never happen!\n");
3457 GfxElement[x][y] = EL_EMPTY;
3463 border_element = Store2[x][y];
3465 if (IS_PLAYER(x, y) && !PLAYER_EXPLOSION_PROTECTED(x, y))
3466 border_element = StorePlayer[x][y];
3468 if (IS_PLAYER(x, y))
3469 border_element = StorePlayer[x][y];
3473 printf("::: %d,%d: %d %s [%d]\n", x, y, border_element,
3474 element_info[border_element].token_name, Store2[x][y]);
3478 printf("::: phase == %d\n", phase);
3481 if (phase == element_info[border_element].ignition_delay ||
3482 phase == last_phase)
3484 boolean border_explosion = FALSE;
3488 if (IS_PLAYER(x, y) && PLAYERINFO(x, y)->present &&
3489 !PLAYER_EXPLOSION_PROTECTED(x, y))
3491 if (IS_PLAYER(x, y) && PLAYERINFO(x, y)->present)
3494 if (IS_PLAYER(x, y))
3497 KillHeroUnlessExplosionProtected(x, y);
3498 border_explosion = TRUE;
3501 if (phase == last_phase)
3502 printf("::: IS_PLAYER\n");
3505 else if (CAN_EXPLODE_BY_EXPLOSION(border_element))
3508 printf("::: %d,%d: %d %s\n", x, y, border_element,
3509 element_info[border_element].token_name);
3512 Feld[x][y] = Store2[x][y];
3515 border_explosion = TRUE;
3518 if (phase == last_phase)
3519 printf("::: CAN_EXPLODE_BY_EXPLOSION\n");
3522 else if (border_element == EL_AMOEBA_TO_DIAMOND)
3524 AmoebeUmwandeln(x, y);
3526 border_explosion = TRUE;
3529 if (phase == last_phase)
3530 printf("::: EL_AMOEBA_TO_DIAMOND [%d, %d] [%d]\n",
3531 element_info[border_element].explosion_delay,
3532 element_info[border_element].ignition_delay,
3538 /* if an element just explodes due to another explosion (chain-reaction),
3539 do not immediately end the new explosion when it was the last frame of
3540 the explosion (as it would be done in the following "if"-statement!) */
3541 if (border_explosion && phase == last_phase)
3548 if (phase == first_phase_after_start)
3550 int element = Store2[x][y];
3552 if (element == EL_BLACK_ORB)
3554 Feld[x][y] = Store2[x][y];
3559 else if (phase == half_phase)
3561 int element = Store2[x][y];
3563 if (IS_PLAYER(x, y))
3564 KillHeroUnlessExplosionProtected(x, y);
3565 else if (CAN_EXPLODE_BY_EXPLOSION(element))
3567 Feld[x][y] = Store2[x][y];
3571 else if (element == EL_AMOEBA_TO_DIAMOND)
3572 AmoebeUmwandeln(x, y);
3576 if (phase == last_phase)
3581 printf("::: done: phase == %d\n", phase);
3585 printf("::: explosion %d,%d done [%d]\n", x, y, FrameCounter);
3588 element = Feld[x][y] = Store[x][y];
3589 Store[x][y] = Store2[x][y] = 0;
3590 GfxElement[x][y] = EL_UNDEFINED;
3592 /* player can escape from explosions and might therefore be still alive */
3593 if (element >= EL_PLAYER_IS_EXPLODING_1 &&
3594 element <= EL_PLAYER_IS_EXPLODING_4)
3595 Feld[x][y] = (stored_player[element - EL_PLAYER_IS_EXPLODING_1].active ?
3597 element == EL_PLAYER_IS_EXPLODING_1 ? EL_EMERALD_YELLOW :
3598 element == EL_PLAYER_IS_EXPLODING_2 ? EL_EMERALD_RED :
3599 element == EL_PLAYER_IS_EXPLODING_3 ? EL_EMERALD :
3602 /* restore probably existing indestructible background element */
3603 if (Back[x][y] && IS_INDESTRUCTIBLE(Back[x][y]))
3604 element = Feld[x][y] = Back[x][y];
3607 MovDir[x][y] = MovPos[x][y] = MovDelay[x][y] = 0;
3608 GfxDir[x][y] = MV_NO_MOVING;
3609 ChangeDelay[x][y] = 0;
3610 ChangePage[x][y] = -1;
3613 InitField_WithBug2(x, y, FALSE);
3615 InitField(x, y, FALSE);
3617 /* !!! not needed !!! */
3619 if (game.engine_version < VERSION_IDENT(3,1,0,0) &&
3620 CAN_MOVE(Feld[x][y]) && Feld[x][y] != EL_MOLE)
3623 if (CAN_MOVE(element))
3628 DrawLevelField(x, y);
3630 TestIfElementTouchesCustomElement(x, y);
3632 if (GFX_CRUMBLED(element))
3633 DrawLevelFieldCrumbledSandNeighbours(x, y);
3635 if (IS_PLAYER(x, y) && !PLAYERINFO(x, y)->present)
3636 StorePlayer[x][y] = 0;
3638 if (ELEM_IS_PLAYER(element))
3639 RelocatePlayer(x, y, element);
3642 else if (IN_SCR_FIELD(SCREENX(x), SCREENY(y)))
3644 else if (phase >= delay && IN_SCR_FIELD(SCREENX(x), SCREENY(y)))
3648 int graphic = el_act2img(GfxElement[x][y], ACTION_EXPLODING);
3650 int stored = Store[x][y];
3651 int graphic = (game.emulation != EMU_SUPAPLEX ? IMG_EXPLOSION :
3652 stored == EL_SP_INFOTRON ? IMG_SP_EXPLOSION_INFOTRON :
3656 int frame = getGraphicAnimationFrame(graphic, GfxFrame[x][y]);
3658 int frame = getGraphicAnimationFrame(graphic, phase - delay);
3662 printf("::: phase == %d [%d]\n", phase, GfxFrame[x][y]);
3666 printf("::: %d / %d [%d - %d]\n",
3667 GfxFrame[x][y], phase - delay, phase, delay);
3671 printf("::: %d ['%s'] -> %d\n", GfxElement[x][y],
3672 element_info[GfxElement[x][y]].token_name,
3677 DrawLevelFieldCrumbledSand(x, y);
3679 if (IS_WALKABLE_OVER(Back[x][y]) && Back[x][y] != EL_EMPTY)
3681 DrawLevelElement(x, y, Back[x][y]);
3682 DrawGraphicThruMask(SCREENX(x), SCREENY(y), graphic, frame);
3684 else if (IS_WALKABLE_UNDER(Back[x][y]))
3686 DrawGraphic(SCREENX(x), SCREENY(y), graphic, frame);
3687 DrawLevelElementThruMask(x, y, Back[x][y]);
3689 else if (!IS_WALKABLE_INSIDE(Back[x][y]))
3690 DrawGraphic(SCREENX(x), SCREENY(y), graphic, frame);
3694 void DynaExplode(int ex, int ey)
3697 int dynabomb_element = Feld[ex][ey];
3698 int dynabomb_size = 1;
3699 boolean dynabomb_xl = FALSE;
3700 struct PlayerInfo *player;
3701 static int xy[4][2] =
3709 if (IS_ACTIVE_BOMB(dynabomb_element))
3711 player = &stored_player[dynabomb_element - EL_DYNABOMB_PLAYER_1_ACTIVE];
3712 dynabomb_size = player->dynabomb_size;
3713 dynabomb_xl = player->dynabomb_xl;
3714 player->dynabombs_left++;
3717 Explode(ex, ey, EX_PHASE_START, EX_TYPE_CENTER);
3719 for (i = 0; i < NUM_DIRECTIONS; i++)
3721 for (j = 1; j <= dynabomb_size; j++)
3723 int x = ex + j * xy[i][0];
3724 int y = ey + j * xy[i][1];
3727 if (!IN_LEV_FIELD(x, y) || IS_INDESTRUCTIBLE(Feld[x][y]))
3730 element = Feld[x][y];
3732 /* do not restart explosions of fields with active bombs */
3733 if (element == EL_EXPLOSION && IS_ACTIVE_BOMB(Store2[x][y]))
3736 Explode(x, y, EX_PHASE_START, EX_TYPE_BORDER);
3740 if (element != EL_EMPTY && element != EL_EXPLOSION &&
3741 !IS_DIGGABLE(element) && !dynabomb_xl)
3744 if (element != EL_EMPTY && element != EL_EXPLOSION &&
3745 !CAN_GROW_INTO(element) && !dynabomb_xl)
3749 /* !!! extend EL_SAND to anything diggable (but maybe not SP_BASE) !!! */
3750 if (element != EL_EMPTY && element != EL_EXPLOSION &&
3751 element != EL_SAND && !dynabomb_xl)
3758 void Bang(int x, int y)
3761 int element = MovingOrBlocked2Element(x, y);
3763 int element = Feld[x][y];
3767 if (IS_PLAYER(x, y) && !PLAYER_EXPLOSION_PROTECTED(x, y))
3769 if (IS_PLAYER(x, y))
3772 struct PlayerInfo *player = PLAYERINFO(x, y);
3774 element = Feld[x][y] = (player->use_murphy_graphic ? EL_SP_MURPHY :
3775 player->element_nr);
3780 PlayLevelSoundAction(x, y, ACTION_EXPLODING);
3782 if (game.emulation == EMU_SUPAPLEX)
3783 PlayLevelSound(x, y, SND_SP_ELEMENT_EXPLODING);
3785 PlayLevelSound(x, y, SND_ELEMENT_EXPLODING);
3790 if (IS_PLAYER(x, y)) /* remove objects that might cause smaller explosion */
3798 case EL_BD_BUTTERFLY:
3801 case EL_DARK_YAMYAM:
3805 RaiseScoreElement(element);
3806 Explode(x, y, EX_PHASE_START, EX_TYPE_NORMAL);
3808 case EL_DYNABOMB_PLAYER_1_ACTIVE:
3809 case EL_DYNABOMB_PLAYER_2_ACTIVE:
3810 case EL_DYNABOMB_PLAYER_3_ACTIVE:
3811 case EL_DYNABOMB_PLAYER_4_ACTIVE:
3812 case EL_DYNABOMB_INCREASE_NUMBER:
3813 case EL_DYNABOMB_INCREASE_SIZE:
3814 case EL_DYNABOMB_INCREASE_POWER:
3819 case EL_LAMP_ACTIVE:
3821 case EL_AMOEBA_TO_DIAMOND:
3823 if (IS_PLAYER(x, y))
3824 Explode(x, y, EX_PHASE_START, EX_TYPE_NORMAL);
3826 Explode(x, y, EX_PHASE_START, EX_TYPE_CENTER);
3830 if (element_info[element].explosion_type == EXPLODES_CROSS)
3832 if (CAN_EXPLODE_CROSS(element))
3835 Explode(x, y, EX_PHASE_START, EX_TYPE_CROSS);
3840 else if (element_info[element].explosion_type == EXPLODES_1X1)
3842 else if (CAN_EXPLODE_1X1(element))
3844 Explode(x, y, EX_PHASE_START, EX_TYPE_CENTER);
3846 Explode(x, y, EX_PHASE_START, EX_TYPE_NORMAL);
3850 CheckTriggeredElementChange(x, y, element, CE_OTHER_IS_EXPLODING);
3853 void SplashAcid(int x, int y)
3856 if (IN_LEV_FIELD(x - 1, y - 1) && IS_FREE(x - 1, y - 1) &&
3857 (!IN_LEV_FIELD(x - 1, y - 2) ||
3858 !CAN_FALL(MovingOrBlocked2Element(x - 1, y - 2))))
3859 Feld[x - 1][y - 1] = EL_ACID_SPLASH_LEFT;
3861 if (IN_LEV_FIELD(x + 1, y - 1) && IS_FREE(x + 1, y - 1) &&
3862 (!IN_LEV_FIELD(x + 1, y - 2) ||
3863 !CAN_FALL(MovingOrBlocked2Element(x + 1, y - 2))))
3864 Feld[x + 1][y - 1] = EL_ACID_SPLASH_RIGHT;
3866 PlayLevelSound(x, y, SND_ACID_SPLASHING);
3868 /* input: position of element entering acid (obsolete) */
3870 int element = Feld[x][y];
3872 if (!IN_LEV_FIELD(x, y + 1) || Feld[x][y + 1] != EL_ACID)
3875 if (element != EL_ACID_SPLASH_LEFT &&
3876 element != EL_ACID_SPLASH_RIGHT)
3878 PlayLevelSound(x, y, SND_ACID_SPLASHING);
3880 if (IN_LEV_FIELD(x - 1, y) && IS_FREE(x - 1, y) &&
3881 (!IN_LEV_FIELD(x - 1, y - 1) ||
3882 !CAN_FALL(MovingOrBlocked2Element(x - 1, y - 1))))
3883 Feld[x - 1][y] = EL_ACID_SPLASH_LEFT;
3885 if (IN_LEV_FIELD(x + 1, y) && IS_FREE(x + 1, y) &&
3886 (!IN_LEV_FIELD(x + 1, y - 1) ||
3887 !CAN_FALL(MovingOrBlocked2Element(x + 1, y - 1))))
3888 Feld[x + 1][y] = EL_ACID_SPLASH_RIGHT;
3893 static void InitBeltMovement()
3895 static int belt_base_element[4] =
3897 EL_CONVEYOR_BELT_1_LEFT,
3898 EL_CONVEYOR_BELT_2_LEFT,
3899 EL_CONVEYOR_BELT_3_LEFT,
3900 EL_CONVEYOR_BELT_4_LEFT
3902 static int belt_base_active_element[4] =
3904 EL_CONVEYOR_BELT_1_LEFT_ACTIVE,
3905 EL_CONVEYOR_BELT_2_LEFT_ACTIVE,
3906 EL_CONVEYOR_BELT_3_LEFT_ACTIVE,
3907 EL_CONVEYOR_BELT_4_LEFT_ACTIVE
3912 /* set frame order for belt animation graphic according to belt direction */
3913 for (i = 0; i < NUM_BELTS; i++)
3917 for (j = 0; j < NUM_BELT_PARTS; j++)
3919 int element = belt_base_active_element[belt_nr] + j;
3920 int graphic = el2img(element);
3922 if (game.belt_dir[i] == MV_LEFT)
3923 graphic_info[graphic].anim_mode &= ~ANIM_REVERSE;
3925 graphic_info[graphic].anim_mode |= ANIM_REVERSE;
3929 for (y = 0; y < lev_fieldy; y++)
3931 for (x = 0; x < lev_fieldx; x++)
3933 int element = Feld[x][y];
3935 for (i = 0; i < NUM_BELTS; i++)
3937 if (IS_BELT(element) && game.belt_dir[i] != MV_NO_MOVING)
3939 int e_belt_nr = getBeltNrFromBeltElement(element);
3942 if (e_belt_nr == belt_nr)
3944 int belt_part = Feld[x][y] - belt_base_element[belt_nr];
3946 Feld[x][y] = belt_base_active_element[belt_nr] + belt_part;
3954 static void ToggleBeltSwitch(int x, int y)
3956 static int belt_base_element[4] =
3958 EL_CONVEYOR_BELT_1_LEFT,
3959 EL_CONVEYOR_BELT_2_LEFT,
3960 EL_CONVEYOR_BELT_3_LEFT,
3961 EL_CONVEYOR_BELT_4_LEFT
3963 static int belt_base_active_element[4] =
3965 EL_CONVEYOR_BELT_1_LEFT_ACTIVE,
3966 EL_CONVEYOR_BELT_2_LEFT_ACTIVE,
3967 EL_CONVEYOR_BELT_3_LEFT_ACTIVE,
3968 EL_CONVEYOR_BELT_4_LEFT_ACTIVE
3970 static int belt_base_switch_element[4] =
3972 EL_CONVEYOR_BELT_1_SWITCH_LEFT,
3973 EL_CONVEYOR_BELT_2_SWITCH_LEFT,
3974 EL_CONVEYOR_BELT_3_SWITCH_LEFT,
3975 EL_CONVEYOR_BELT_4_SWITCH_LEFT
3977 static int belt_move_dir[4] =
3985 int element = Feld[x][y];
3986 int belt_nr = getBeltNrFromBeltSwitchElement(element);
3987 int belt_dir_nr = (game.belt_dir_nr[belt_nr] + 1) % 4;
3988 int belt_dir = belt_move_dir[belt_dir_nr];
3991 if (!IS_BELT_SWITCH(element))
3994 game.belt_dir_nr[belt_nr] = belt_dir_nr;
3995 game.belt_dir[belt_nr] = belt_dir;
3997 if (belt_dir_nr == 3)
4000 /* set frame order for belt animation graphic according to belt direction */
4001 for (i = 0; i < NUM_BELT_PARTS; i++)
4003 int element = belt_base_active_element[belt_nr] + i;
4004 int graphic = el2img(element);
4006 if (belt_dir == MV_LEFT)
4007 graphic_info[graphic].anim_mode &= ~ANIM_REVERSE;
4009 graphic_info[graphic].anim_mode |= ANIM_REVERSE;
4012 for (yy = 0; yy < lev_fieldy; yy++)
4014 for (xx = 0; xx < lev_fieldx; xx++)
4016 int element = Feld[xx][yy];
4018 if (IS_BELT_SWITCH(element))
4020 int e_belt_nr = getBeltNrFromBeltSwitchElement(element);
4022 if (e_belt_nr == belt_nr)
4024 Feld[xx][yy] = belt_base_switch_element[belt_nr] + belt_dir_nr;
4025 DrawLevelField(xx, yy);
4028 else if (IS_BELT(element) && belt_dir != MV_NO_MOVING)
4030 int e_belt_nr = getBeltNrFromBeltElement(element);
4032 if (e_belt_nr == belt_nr)
4034 int belt_part = Feld[xx][yy] - belt_base_element[belt_nr];
4036 Feld[xx][yy] = belt_base_active_element[belt_nr] + belt_part;
4037 DrawLevelField(xx, yy);
4040 else if (IS_BELT_ACTIVE(element) && belt_dir == MV_NO_MOVING)
4042 int e_belt_nr = getBeltNrFromBeltActiveElement(element);
4044 if (e_belt_nr == belt_nr)
4046 int belt_part = Feld[xx][yy] - belt_base_active_element[belt_nr];
4048 Feld[xx][yy] = belt_base_element[belt_nr] + belt_part;
4049 DrawLevelField(xx, yy);
4056 static void ToggleSwitchgateSwitch(int x, int y)
4060 game.switchgate_pos = !game.switchgate_pos;
4062 for (yy = 0; yy < lev_fieldy; yy++)
4064 for (xx = 0; xx < lev_fieldx; xx++)
4066 int element = Feld[xx][yy];
4068 if (element == EL_SWITCHGATE_SWITCH_UP ||
4069 element == EL_SWITCHGATE_SWITCH_DOWN)
4071 Feld[xx][yy] = EL_SWITCHGATE_SWITCH_UP + game.switchgate_pos;
4072 DrawLevelField(xx, yy);
4074 else if (element == EL_SWITCHGATE_OPEN ||
4075 element == EL_SWITCHGATE_OPENING)
4077 Feld[xx][yy] = EL_SWITCHGATE_CLOSING;
4079 PlayLevelSoundAction(xx, yy, ACTION_CLOSING);
4081 PlayLevelSound(xx, yy, SND_SWITCHGATE_CLOSING);
4084 else if (element == EL_SWITCHGATE_CLOSED ||
4085 element == EL_SWITCHGATE_CLOSING)
4087 Feld[xx][yy] = EL_SWITCHGATE_OPENING;
4089 PlayLevelSoundAction(xx, yy, ACTION_OPENING);
4091 PlayLevelSound(xx, yy, SND_SWITCHGATE_OPENING);
4098 static int getInvisibleActiveFromInvisibleElement(int element)
4100 return (element == EL_INVISIBLE_STEELWALL ? EL_INVISIBLE_STEELWALL_ACTIVE :
4101 element == EL_INVISIBLE_WALL ? EL_INVISIBLE_WALL_ACTIVE :
4102 element == EL_INVISIBLE_SAND ? EL_INVISIBLE_SAND_ACTIVE :
4106 static int getInvisibleFromInvisibleActiveElement(int element)
4108 return (element == EL_INVISIBLE_STEELWALL_ACTIVE ? EL_INVISIBLE_STEELWALL :
4109 element == EL_INVISIBLE_WALL_ACTIVE ? EL_INVISIBLE_WALL :
4110 element == EL_INVISIBLE_SAND_ACTIVE ? EL_INVISIBLE_SAND :
4114 static void RedrawAllLightSwitchesAndInvisibleElements()
4118 for (y = 0; y < lev_fieldy; y++)
4120 for (x = 0; x < lev_fieldx; x++)
4122 int element = Feld[x][y];
4124 if (element == EL_LIGHT_SWITCH &&
4125 game.light_time_left > 0)
4127 Feld[x][y] = EL_LIGHT_SWITCH_ACTIVE;
4128 DrawLevelField(x, y);
4130 else if (element == EL_LIGHT_SWITCH_ACTIVE &&
4131 game.light_time_left == 0)
4133 Feld[x][y] = EL_LIGHT_SWITCH;
4134 DrawLevelField(x, y);
4136 else if (element == EL_INVISIBLE_STEELWALL ||
4137 element == EL_INVISIBLE_WALL ||
4138 element == EL_INVISIBLE_SAND)
4140 if (game.light_time_left > 0)
4141 Feld[x][y] = getInvisibleActiveFromInvisibleElement(element);
4143 DrawLevelField(x, y);
4145 else if (element == EL_INVISIBLE_STEELWALL_ACTIVE ||
4146 element == EL_INVISIBLE_WALL_ACTIVE ||
4147 element == EL_INVISIBLE_SAND_ACTIVE)
4149 if (game.light_time_left == 0)
4150 Feld[x][y] = getInvisibleFromInvisibleActiveElement(element);
4152 DrawLevelField(x, y);
4158 static void ToggleLightSwitch(int x, int y)
4160 int element = Feld[x][y];
4162 game.light_time_left =
4163 (element == EL_LIGHT_SWITCH ?
4164 level.time_light * FRAMES_PER_SECOND : 0);
4166 RedrawAllLightSwitchesAndInvisibleElements();
4169 static void ActivateTimegateSwitch(int x, int y)
4173 game.timegate_time_left = level.time_timegate * FRAMES_PER_SECOND;
4175 for (yy = 0; yy < lev_fieldy; yy++)
4177 for (xx = 0; xx < lev_fieldx; xx++)
4179 int element = Feld[xx][yy];
4181 if (element == EL_TIMEGATE_CLOSED ||
4182 element == EL_TIMEGATE_CLOSING)
4184 Feld[xx][yy] = EL_TIMEGATE_OPENING;
4185 PlayLevelSound(xx, yy, SND_TIMEGATE_OPENING);
4189 else if (element == EL_TIMEGATE_SWITCH_ACTIVE)
4191 Feld[xx][yy] = EL_TIMEGATE_SWITCH;
4192 DrawLevelField(xx, yy);
4199 Feld[x][y] = EL_TIMEGATE_SWITCH_ACTIVE;
4202 inline static int getElementMoveStepsize(int x, int y)
4204 int element = Feld[x][y];
4205 int direction = MovDir[x][y];
4206 int dx = (direction == MV_LEFT ? -1 : direction == MV_RIGHT ? +1 : 0);
4207 int dy = (direction == MV_UP ? -1 : direction == MV_DOWN ? +1 : 0);
4208 int horiz_move = (dx != 0);
4209 int sign = (horiz_move ? dx : dy);
4210 int step = sign * element_info[element].move_stepsize;
4212 /* special values for move stepsize for spring and things on conveyor belt */
4216 if (element == EL_SPRING)
4217 step = sign * MOVE_STEPSIZE_NORMAL * 2;
4218 else if (CAN_FALL(element) && !CAN_MOVE(element) &&
4219 y < lev_fieldy - 1 && IS_BELT_ACTIVE(Feld[x][y + 1]))
4220 step = sign * MOVE_STEPSIZE_NORMAL / 2;
4222 if (CAN_FALL(element) &&
4223 y < lev_fieldy - 1 && IS_BELT_ACTIVE(Feld[x][y + 1]))
4224 step = sign * MOVE_STEPSIZE_NORMAL / 2;
4225 else if (element == EL_SPRING)
4226 step = sign * MOVE_STEPSIZE_NORMAL * 2;
4233 void Impact(int x, int y)
4235 boolean lastline = (y == lev_fieldy-1);
4236 boolean object_hit = FALSE;
4237 boolean impact = (lastline || object_hit);
4238 int element = Feld[x][y];
4239 int smashed = EL_STEELWALL;
4241 if (!lastline) /* check if element below was hit */
4243 if (Feld[x][y + 1] == EL_PLAYER_IS_LEAVING)
4246 object_hit = (!IS_FREE(x, y + 1) && (!IS_MOVING(x, y + 1) ||
4247 MovDir[x][y + 1] != MV_DOWN ||
4248 MovPos[x][y + 1] <= TILEY / 2));
4251 object_hit = !IS_FREE(x, y + 1);
4254 /* do not smash moving elements that left the smashed field in time */
4255 if (game.engine_version >= VERSION_IDENT(2,2,0,7) && IS_MOVING(x, y + 1) &&
4256 ABS(MovPos[x][y + 1] + getElementMoveStepsize(x, y + 1)) >= TILEX)
4260 smashed = MovingOrBlocked2Element(x, y + 1);
4262 impact = (lastline || object_hit);
4265 if (!lastline && smashed == EL_ACID) /* element falls into acid */
4267 SplashAcid(x, y + 1);
4271 /* !!! not sufficient for all cases -- see EL_PEARL below !!! */
4272 /* only reset graphic animation if graphic really changes after impact */
4274 el_act_dir2img(element, GfxAction[x][y], MV_DOWN) != el2img(element))
4276 ResetGfxAnimation(x, y);
4277 DrawLevelField(x, y);
4280 if (impact && CAN_EXPLODE_IMPACT(element))
4285 else if (impact && element == EL_PEARL)
4287 ResetGfxAnimation(x, y);
4289 Feld[x][y] = EL_PEARL_BREAKING;
4290 PlayLevelSound(x, y, SND_PEARL_BREAKING);
4293 else if (impact && CheckElementChange(x, y, element, smashed, CE_IMPACT))
4295 PlayLevelSoundElementAction(x, y, element, ACTION_IMPACT);
4300 if (impact && element == EL_AMOEBA_DROP)
4302 if (object_hit && IS_PLAYER(x, y + 1))
4303 KillHeroUnlessEnemyProtected(x, y + 1);
4304 else if (object_hit && smashed == EL_PENGUIN)
4308 Feld[x][y] = EL_AMOEBA_GROWING;
4309 Store[x][y] = EL_AMOEBA_WET;
4311 ResetRandomAnimationValue(x, y);
4316 if (object_hit) /* check which object was hit */
4318 if (CAN_PASS_MAGIC_WALL(element) &&
4319 (smashed == EL_MAGIC_WALL ||
4320 smashed == EL_BD_MAGIC_WALL))
4323 int activated_magic_wall =
4324 (smashed == EL_MAGIC_WALL ? EL_MAGIC_WALL_ACTIVE :
4325 EL_BD_MAGIC_WALL_ACTIVE);
4327 /* activate magic wall / mill */
4328 for (yy = 0; yy < lev_fieldy; yy++)
4329 for (xx = 0; xx < lev_fieldx; xx++)
4330 if (Feld[xx][yy] == smashed)
4331 Feld[xx][yy] = activated_magic_wall;
4333 game.magic_wall_time_left = level.time_magic_wall * FRAMES_PER_SECOND;
4334 game.magic_wall_active = TRUE;
4336 PlayLevelSound(x, y, (smashed == EL_MAGIC_WALL ?
4337 SND_MAGIC_WALL_ACTIVATING :
4338 SND_BD_MAGIC_WALL_ACTIVATING));
4341 if (IS_PLAYER(x, y + 1))
4343 if (CAN_SMASH_PLAYER(element))
4345 KillHeroUnlessEnemyProtected(x, y + 1);
4349 else if (smashed == EL_PENGUIN)
4351 if (CAN_SMASH_PLAYER(element))
4357 else if (element == EL_BD_DIAMOND)
4359 if (IS_CLASSIC_ENEMY(smashed) && IS_BD_ELEMENT(smashed))
4365 else if (((element == EL_SP_INFOTRON ||
4366 element == EL_SP_ZONK) &&
4367 (smashed == EL_SP_SNIKSNAK ||
4368 smashed == EL_SP_ELECTRON ||
4369 smashed == EL_SP_DISK_ORANGE)) ||
4370 (element == EL_SP_INFOTRON &&
4371 smashed == EL_SP_DISK_YELLOW))
4377 else if (CAN_SMASH_ENEMIES(element) && IS_CLASSIC_ENEMY(smashed))
4383 else if (CAN_SMASH_EVERYTHING(element))
4385 if (IS_CLASSIC_ENEMY(smashed) ||
4386 CAN_EXPLODE_SMASHED(smashed))
4391 else if (!IS_MOVING(x, y + 1) && !IS_BLOCKED(x, y + 1))
4393 if (smashed == EL_LAMP ||
4394 smashed == EL_LAMP_ACTIVE)
4399 else if (smashed == EL_NUT)
4401 Feld[x][y + 1] = EL_NUT_BREAKING;
4402 PlayLevelSound(x, y, SND_NUT_BREAKING);
4403 RaiseScoreElement(EL_NUT);
4406 else if (smashed == EL_PEARL)
4408 ResetGfxAnimation(x, y);
4410 Feld[x][y + 1] = EL_PEARL_BREAKING;
4411 PlayLevelSound(x, y, SND_PEARL_BREAKING);
4414 else if (smashed == EL_DIAMOND)
4416 Feld[x][y + 1] = EL_DIAMOND_BREAKING;
4417 PlayLevelSound(x, y, SND_DIAMOND_BREAKING);
4420 else if (IS_BELT_SWITCH(smashed))
4422 ToggleBeltSwitch(x, y + 1);
4424 else if (smashed == EL_SWITCHGATE_SWITCH_UP ||
4425 smashed == EL_SWITCHGATE_SWITCH_DOWN)
4427 ToggleSwitchgateSwitch(x, y + 1);
4429 else if (smashed == EL_LIGHT_SWITCH ||
4430 smashed == EL_LIGHT_SWITCH_ACTIVE)
4432 ToggleLightSwitch(x, y + 1);
4437 TestIfElementSmashesCustomElement(x, y, MV_DOWN);
4440 CheckElementChange(x, y + 1, smashed, element, CE_SMASHED);
4443 /* !!! TEST ONLY !!! */
4444 CheckElementChangeBySide(x, y + 1, smashed, element,
4445 CE_SWITCHED, CH_SIDE_TOP);
4446 CheckTriggeredElementChangeBySide(x, y + 1, smashed,
4447 CE_OTHER_IS_SWITCHING,CH_SIDE_TOP);
4449 CheckTriggeredElementChangeBySide(x, y + 1, smashed,
4450 CE_OTHER_IS_SWITCHING,CH_SIDE_TOP);
4451 CheckElementChangeBySide(x, y + 1, smashed, element,
4452 CE_SWITCHED, CH_SIDE_TOP);
4458 CheckElementChange(x, y + 1, smashed, element, CE_SMASHED);
4463 /* play sound of magic wall / mill */
4465 (Feld[x][y + 1] == EL_MAGIC_WALL_ACTIVE ||
4466 Feld[x][y + 1] == EL_BD_MAGIC_WALL_ACTIVE))
4468 if (Feld[x][y + 1] == EL_MAGIC_WALL_ACTIVE)
4469 PlayLevelSound(x, y, SND_MAGIC_WALL_FILLING);
4470 else if (Feld[x][y + 1] == EL_BD_MAGIC_WALL_ACTIVE)
4471 PlayLevelSound(x, y, SND_BD_MAGIC_WALL_FILLING);
4476 /* play sound of object that hits the ground */
4477 if (lastline || object_hit)
4478 PlayLevelSoundElementAction(x, y, element, ACTION_IMPACT);
4481 inline static void TurnRoundExt(int x, int y)
4493 { 0, 0 }, { 0, 0 }, { 0, 0 },
4498 int left, right, back;
4502 { MV_DOWN, MV_UP, MV_RIGHT },
4503 { MV_UP, MV_DOWN, MV_LEFT },
4505 { MV_LEFT, MV_RIGHT, MV_DOWN },
4509 { MV_RIGHT, MV_LEFT, MV_UP }
4512 int element = Feld[x][y];
4513 int move_pattern = element_info[element].move_pattern;
4515 int old_move_dir = MovDir[x][y];
4516 int left_dir = turn[old_move_dir].left;
4517 int right_dir = turn[old_move_dir].right;
4518 int back_dir = turn[old_move_dir].back;
4520 int left_dx = move_xy[left_dir].x, left_dy = move_xy[left_dir].y;
4521 int right_dx = move_xy[right_dir].x, right_dy = move_xy[right_dir].y;
4522 int move_dx = move_xy[old_move_dir].x, move_dy = move_xy[old_move_dir].y;
4523 int back_dx = move_xy[back_dir].x, back_dy = move_xy[back_dir].y;
4525 int left_x = x + left_dx, left_y = y + left_dy;
4526 int right_x = x + right_dx, right_y = y + right_dy;
4527 int move_x = x + move_dx, move_y = y + move_dy;
4531 if (element == EL_BUG || element == EL_BD_BUTTERFLY)
4533 TestIfBadThingTouchesOtherBadThing(x, y);
4535 if (ENEMY_CAN_ENTER_FIELD(element, right_x, right_y))
4536 MovDir[x][y] = right_dir;
4537 else if (!ENEMY_CAN_ENTER_FIELD(element, move_x, move_y))
4538 MovDir[x][y] = left_dir;
4540 if (element == EL_BUG && MovDir[x][y] != old_move_dir)
4542 else if (element == EL_BD_BUTTERFLY) /* && MovDir[x][y] == left_dir) */
4546 else if (element == EL_SPACESHIP || element == EL_BD_FIREFLY ||
4547 element == EL_SP_SNIKSNAK || element == EL_SP_ELECTRON)
4549 TestIfBadThingTouchesOtherBadThing(x, y);
4551 if (ENEMY_CAN_ENTER_FIELD(element, left_x, left_y))
4552 MovDir[x][y] = left_dir;
4553 else if (!ENEMY_CAN_ENTER_FIELD(element, move_x, move_y))
4554 MovDir[x][y] = right_dir;
4556 if ((element == EL_SPACESHIP ||
4557 element == EL_SP_SNIKSNAK ||
4558 element == EL_SP_ELECTRON)
4559 && MovDir[x][y] != old_move_dir)
4561 else if (element == EL_BD_FIREFLY) /* && MovDir[x][y] == right_dir) */
4565 else if (element == EL_SPACESHIP || element == EL_BD_FIREFLY)
4567 TestIfBadThingTouchesOtherBadThing(x, y);
4569 if (ENEMY_CAN_ENTER_FIELD(element, left_x, left_y))
4570 MovDir[x][y] = left_dir;
4571 else if (!ENEMY_CAN_ENTER_FIELD(element, move_x, move_y))
4572 MovDir[x][y] = right_dir;
4574 if (element == EL_SPACESHIP && MovDir[x][y] != old_move_dir)
4576 else if (element == EL_BD_FIREFLY) /* && MovDir[x][y] == right_dir) */
4579 else if (element == EL_SP_SNIKSNAK || element == EL_SP_ELECTRON)
4581 TestIfBadThingTouchesOtherBadThing(x, y);
4583 if (ELEMENT_CAN_ENTER_FIELD_BASE_4(element, left_x, left_y, 0))
4584 MovDir[x][y] = left_dir;
4585 else if (!ELEMENT_CAN_ENTER_FIELD_BASE_4(element, move_x, move_y, 0))
4586 MovDir[x][y] = right_dir;
4588 if (MovDir[x][y] != old_move_dir)
4592 else if (element == EL_YAMYAM)
4594 boolean can_turn_left = YAMYAM_CAN_ENTER_FIELD(element, left_x, left_y);
4595 boolean can_turn_right = YAMYAM_CAN_ENTER_FIELD(element, right_x, right_y);
4597 if (can_turn_left && can_turn_right)
4598 MovDir[x][y] = (RND(3) ? (RND(2) ? left_dir : right_dir) : back_dir);
4599 else if (can_turn_left)
4600 MovDir[x][y] = (RND(2) ? left_dir : back_dir);
4601 else if (can_turn_right)
4602 MovDir[x][y] = (RND(2) ? right_dir : back_dir);
4604 MovDir[x][y] = back_dir;
4606 MovDelay[x][y] = 16 + 16 * RND(3);
4608 else if (element == EL_DARK_YAMYAM)
4610 boolean can_turn_left = DARK_YAMYAM_CAN_ENTER_FIELD(element,
4612 boolean can_turn_right = DARK_YAMYAM_CAN_ENTER_FIELD(element,
4615 if (can_turn_left && can_turn_right)
4616 MovDir[x][y] = (RND(3) ? (RND(2) ? left_dir : right_dir) : back_dir);
4617 else if (can_turn_left)
4618 MovDir[x][y] = (RND(2) ? left_dir : back_dir);
4619 else if (can_turn_right)
4620 MovDir[x][y] = (RND(2) ? right_dir : back_dir);
4622 MovDir[x][y] = back_dir;
4624 MovDelay[x][y] = 16 + 16 * RND(3);
4626 else if (element == EL_PACMAN)
4628 boolean can_turn_left = PACMAN_CAN_ENTER_FIELD(element, left_x, left_y);
4629 boolean can_turn_right = PACMAN_CAN_ENTER_FIELD(element, right_x, right_y);
4631 if (can_turn_left && can_turn_right)
4632 MovDir[x][y] = (RND(3) ? (RND(2) ? left_dir : right_dir) : back_dir);
4633 else if (can_turn_left)
4634 MovDir[x][y] = (RND(2) ? left_dir : back_dir);
4635 else if (can_turn_right)
4636 MovDir[x][y] = (RND(2) ? right_dir : back_dir);
4638 MovDir[x][y] = back_dir;
4640 MovDelay[x][y] = 6 + RND(40);
4642 else if (element == EL_PIG)
4644 boolean can_turn_left = PIG_CAN_ENTER_FIELD(element, left_x, left_y);
4645 boolean can_turn_right = PIG_CAN_ENTER_FIELD(element, right_x, right_y);
4646 boolean can_move_on = PIG_CAN_ENTER_FIELD(element, move_x, move_y);
4647 boolean should_turn_left, should_turn_right, should_move_on;
4649 int rnd = RND(rnd_value);
4651 should_turn_left = (can_turn_left &&
4653 IN_LEV_FIELD_AND_NOT_FREE(x + back_dx + left_dx,
4654 y + back_dy + left_dy)));
4655 should_turn_right = (can_turn_right &&
4657 IN_LEV_FIELD_AND_NOT_FREE(x + back_dx + right_dx,
4658 y + back_dy + right_dy)));
4659 should_move_on = (can_move_on &&
4662 IN_LEV_FIELD_AND_NOT_FREE(x + move_dx + left_dx,
4663 y + move_dy + left_dy) ||
4664 IN_LEV_FIELD_AND_NOT_FREE(x + move_dx + right_dx,
4665 y + move_dy + right_dy)));
4667 if (should_turn_left || should_turn_right || should_move_on)
4669 if (should_turn_left && should_turn_right && should_move_on)
4670 MovDir[x][y] = (rnd < rnd_value / 3 ? left_dir :
4671 rnd < 2 * rnd_value / 3 ? right_dir :
4673 else if (should_turn_left && should_turn_right)
4674 MovDir[x][y] = (rnd < rnd_value / 2 ? left_dir : right_dir);
4675 else if (should_turn_left && should_move_on)
4676 MovDir[x][y] = (rnd < rnd_value / 2 ? left_dir : old_move_dir);
4677 else if (should_turn_right && should_move_on)
4678 MovDir[x][y] = (rnd < rnd_value / 2 ? right_dir : old_move_dir);
4679 else if (should_turn_left)
4680 MovDir[x][y] = left_dir;
4681 else if (should_turn_right)
4682 MovDir[x][y] = right_dir;
4683 else if (should_move_on)
4684 MovDir[x][y] = old_move_dir;
4686 else if (can_move_on && rnd > rnd_value / 8)
4687 MovDir[x][y] = old_move_dir;
4688 else if (can_turn_left && can_turn_right)
4689 MovDir[x][y] = (rnd < rnd_value / 2 ? left_dir : right_dir);
4690 else if (can_turn_left && rnd > rnd_value / 8)
4691 MovDir[x][y] = left_dir;
4692 else if (can_turn_right && rnd > rnd_value/8)
4693 MovDir[x][y] = right_dir;
4695 MovDir[x][y] = back_dir;
4697 xx = x + move_xy[MovDir[x][y]].x;
4698 yy = y + move_xy[MovDir[x][y]].y;
4701 /* !!! this bugfix breaks at least BD2K3, level 010 !!! [re-recorded] */
4702 if (!IN_LEV_FIELD(xx, yy) ||
4703 (!IS_FREE(xx, yy) && !IS_FOOD_PIG(Feld[xx][yy])))
4704 MovDir[x][y] = old_move_dir;
4706 if (!IS_FREE(xx, yy) && !IS_FOOD_PIG(Feld[xx][yy]))
4707 MovDir[x][y] = old_move_dir;
4712 else if (element == EL_DRAGON)
4714 boolean can_turn_left = DRAGON_CAN_ENTER_FIELD(element, left_x, left_y);
4715 boolean can_turn_right = DRAGON_CAN_ENTER_FIELD(element, right_x, right_y);
4716 boolean can_move_on = DRAGON_CAN_ENTER_FIELD(element, move_x, move_y);
4718 int rnd = RND(rnd_value);
4721 if (FrameCounter < 1 && x == 0 && y == 29)
4722 printf(":2: %d/%d: %d [%d]\n", x, y, MovDir[x][y], FrameCounter);
4725 if (can_move_on && rnd > rnd_value / 8)
4726 MovDir[x][y] = old_move_dir;
4727 else if (can_turn_left && can_turn_right)
4728 MovDir[x][y] = (rnd < rnd_value / 2 ? left_dir : right_dir);
4729 else if (can_turn_left && rnd > rnd_value / 8)
4730 MovDir[x][y] = left_dir;
4731 else if (can_turn_right && rnd > rnd_value / 8)
4732 MovDir[x][y] = right_dir;
4734 MovDir[x][y] = back_dir;
4736 xx = x + move_xy[MovDir[x][y]].x;
4737 yy = y + move_xy[MovDir[x][y]].y;
4740 if (FrameCounter < 1 && x == 0 && y == 29)
4741 printf(":3: %d/%d: %d (%d/%d: %d) [%d]\n", x, y, MovDir[x][y],
4742 xx, yy, Feld[xx][yy],
4747 if (!IN_LEV_FIELD_AND_IS_FREE(xx, yy))
4748 MovDir[x][y] = old_move_dir;
4750 if (!IS_FREE(xx, yy))
4751 MovDir[x][y] = old_move_dir;
4755 if (FrameCounter < 1 && x == 0 && y == 29)
4756 printf(":4: %d/%d: %d [%d]\n", x, y, MovDir[x][y], FrameCounter);
4761 else if (element == EL_MOLE)
4763 boolean can_move_on =
4764 (MOLE_CAN_ENTER_FIELD(element, move_x, move_y,
4765 IS_AMOEBOID(Feld[move_x][move_y]) ||
4766 Feld[move_x][move_y] == EL_AMOEBA_SHRINKING));
4769 boolean can_turn_left =
4770 (MOLE_CAN_ENTER_FIELD(element, left_x, left_y,
4771 IS_AMOEBOID(Feld[left_x][left_y])));
4773 boolean can_turn_right =
4774 (MOLE_CAN_ENTER_FIELD(element, right_x, right_y,
4775 IS_AMOEBOID(Feld[right_x][right_y])));
4777 if (can_turn_left && can_turn_right)
4778 MovDir[x][y] = (RND(2) ? left_dir : right_dir);
4779 else if (can_turn_left)
4780 MovDir[x][y] = left_dir;
4782 MovDir[x][y] = right_dir;
4785 if (MovDir[x][y] != old_move_dir)
4788 else if (element == EL_BALLOON)
4790 MovDir[x][y] = game.balloon_dir;
4793 else if (element == EL_SPRING)
4796 if (MovDir[x][y] & MV_HORIZONTAL &&
4797 !SPRING_CAN_ENTER_FIELD(element, move_x, move_y))
4798 MovDir[x][y] = MV_NO_MOVING;
4800 if (MovDir[x][y] & MV_HORIZONTAL &&
4801 (!SPRING_CAN_ENTER_FIELD(element, move_x, move_y) ||
4802 SPRING_CAN_ENTER_FIELD(element, x, y + 1)))
4803 MovDir[x][y] = MV_NO_MOVING;
4808 else if (element == EL_ROBOT ||
4809 element == EL_SATELLITE ||
4810 element == EL_PENGUIN)
4812 int attr_x = -1, attr_y = -1;
4823 for (i = 0; i < MAX_PLAYERS; i++)
4825 struct PlayerInfo *player = &stored_player[i];
4826 int jx = player->jx, jy = player->jy;
4828 if (!player->active)
4832 ABS(jx - x) + ABS(jy - y) < ABS(attr_x - x) + ABS(attr_y - y))
4841 if (element == EL_ROBOT && ZX >= 0 && ZY >= 0 &&
4842 (Feld[ZX][ZY] == EL_ROBOT_WHEEL_ACTIVE ||
4843 game.engine_version < VERSION_IDENT(3,1,0,0)))
4845 if (element == EL_ROBOT && ZX >= 0 && ZY >= 0)
4852 if (element == EL_PENGUIN)
4855 static int xy[4][2] =
4863 for (i = 0; i < NUM_DIRECTIONS; i++)
4865 int ex = x + xy[i][0];
4866 int ey = y + xy[i][1];
4868 if (IN_LEV_FIELD(ex, ey) && Feld[ex][ey] == EL_EXIT_OPEN)
4877 MovDir[x][y] = MV_NO_MOVING;
4879 MovDir[x][y] |= (AllPlayersGone ? MV_RIGHT : MV_LEFT);
4880 else if (attr_x > x)
4881 MovDir[x][y] |= (AllPlayersGone ? MV_LEFT : MV_RIGHT);
4883 MovDir[x][y] |= (AllPlayersGone ? MV_DOWN : MV_UP);
4884 else if (attr_y > y)
4885 MovDir[x][y] |= (AllPlayersGone ? MV_UP : MV_DOWN);
4887 if (element == EL_ROBOT)
4891 if (MovDir[x][y] & MV_HORIZONTAL && MovDir[x][y] & MV_VERTICAL)
4892 MovDir[x][y] &= (RND(2) ? MV_HORIZONTAL : MV_VERTICAL);
4893 Moving2Blocked(x, y, &newx, &newy);
4895 if (IN_LEV_FIELD(newx, newy) && IS_FREE_OR_PLAYER(newx, newy))
4896 MovDelay[x][y] = 8 + 8 * !RND(3);
4898 MovDelay[x][y] = 16;
4900 else if (element == EL_PENGUIN)
4906 if (MovDir[x][y] & MV_HORIZONTAL && MovDir[x][y] & MV_VERTICAL)
4908 boolean first_horiz = RND(2);
4909 int new_move_dir = MovDir[x][y];
4912 new_move_dir & (first_horiz ? MV_HORIZONTAL : MV_VERTICAL);
4913 Moving2Blocked(x, y, &newx, &newy);
4915 if (PENGUIN_CAN_ENTER_FIELD(EL_PENGUIN, newx, newy))
4919 new_move_dir & (!first_horiz ? MV_HORIZONTAL : MV_VERTICAL);
4920 Moving2Blocked(x, y, &newx, &newy);
4922 if (PENGUIN_CAN_ENTER_FIELD(EL_PENGUIN, newx, newy))
4925 MovDir[x][y] = old_move_dir;
4929 else /* (element == EL_SATELLITE) */
4935 if (MovDir[x][y] & MV_HORIZONTAL && MovDir[x][y] & MV_VERTICAL)
4937 boolean first_horiz = RND(2);
4938 int new_move_dir = MovDir[x][y];
4941 new_move_dir & (first_horiz ? MV_HORIZONTAL : MV_VERTICAL);
4942 Moving2Blocked(x, y, &newx, &newy);
4944 if (SATELLITE_CAN_ENTER_FIELD(newx, newy))
4948 new_move_dir & (!first_horiz ? MV_HORIZONTAL : MV_VERTICAL);
4949 Moving2Blocked(x, y, &newx, &newy);
4951 if (SATELLITE_CAN_ENTER_FIELD(newx, newy))
4954 MovDir[x][y] = old_move_dir;
4959 else if (move_pattern == MV_TURNING_LEFT ||
4960 move_pattern == MV_TURNING_RIGHT ||
4961 move_pattern == MV_TURNING_LEFT_RIGHT ||
4962 move_pattern == MV_TURNING_RIGHT_LEFT ||
4963 move_pattern == MV_TURNING_RANDOM ||
4964 move_pattern == MV_ALL_DIRECTIONS)
4966 boolean can_turn_left =
4967 CUSTOM_ELEMENT_CAN_ENTER_FIELD(element, left_x, left_y);
4968 boolean can_turn_right =
4969 CUSTOM_ELEMENT_CAN_ENTER_FIELD(element, right_x,right_y);
4971 if (move_pattern == MV_TURNING_LEFT)
4972 MovDir[x][y] = left_dir;
4973 else if (move_pattern == MV_TURNING_RIGHT)
4974 MovDir[x][y] = right_dir;
4975 else if (move_pattern == MV_TURNING_LEFT_RIGHT)
4976 MovDir[x][y] = (can_turn_left || !can_turn_right ? left_dir : right_dir);
4977 else if (move_pattern == MV_TURNING_RIGHT_LEFT)
4978 MovDir[x][y] = (can_turn_right || !can_turn_left ? right_dir : left_dir);
4979 else if (move_pattern == MV_TURNING_RANDOM)
4980 MovDir[x][y] = (can_turn_left && !can_turn_right ? left_dir :
4981 can_turn_right && !can_turn_left ? right_dir :
4982 RND(2) ? left_dir : right_dir);
4983 else if (can_turn_left && can_turn_right)
4984 MovDir[x][y] = (RND(3) ? (RND(2) ? left_dir : right_dir) : back_dir);
4985 else if (can_turn_left)
4986 MovDir[x][y] = (RND(2) ? left_dir : back_dir);
4987 else if (can_turn_right)
4988 MovDir[x][y] = (RND(2) ? right_dir : back_dir);
4990 MovDir[x][y] = back_dir;
4992 MovDelay[x][y] = GET_NEW_MOVE_DELAY(element);
4994 else if (move_pattern == MV_HORIZONTAL ||
4995 move_pattern == MV_VERTICAL)
4997 if (move_pattern & old_move_dir)
4998 MovDir[x][y] = back_dir;
4999 else if (move_pattern == MV_HORIZONTAL)
5000 MovDir[x][y] = (RND(2) ? MV_LEFT : MV_RIGHT);
5001 else if (move_pattern == MV_VERTICAL)
5002 MovDir[x][y] = (RND(2) ? MV_UP : MV_DOWN);
5004 MovDelay[x][y] = GET_NEW_MOVE_DELAY(element);
5006 else if (move_pattern & MV_ANY_DIRECTION)
5008 MovDir[x][y] = move_pattern;
5009 MovDelay[x][y] = GET_NEW_MOVE_DELAY(element);
5011 else if (move_pattern == MV_ALONG_LEFT_SIDE)
5013 if (CUSTOM_ELEMENT_CAN_ENTER_FIELD(element, left_x, left_y))
5014 MovDir[x][y] = left_dir;
5015 else if (!CUSTOM_ELEMENT_CAN_ENTER_FIELD(element, move_x, move_y))
5016 MovDir[x][y] = right_dir;
5018 if (MovDir[x][y] != old_move_dir)
5019 MovDelay[x][y] = GET_NEW_MOVE_DELAY(element);
5021 else if (move_pattern == MV_ALONG_RIGHT_SIDE)
5023 if (CUSTOM_ELEMENT_CAN_ENTER_FIELD(element, right_x, right_y))
5024 MovDir[x][y] = right_dir;
5025 else if (!CUSTOM_ELEMENT_CAN_ENTER_FIELD(element, move_x, move_y))
5026 MovDir[x][y] = left_dir;
5028 if (MovDir[x][y] != old_move_dir)
5029 MovDelay[x][y] = GET_NEW_MOVE_DELAY(element);
5031 else if (move_pattern == MV_TOWARDS_PLAYER ||
5032 move_pattern == MV_AWAY_FROM_PLAYER)
5034 int attr_x = -1, attr_y = -1;
5036 boolean move_away = (move_pattern == MV_AWAY_FROM_PLAYER);
5047 for (i = 0; i < MAX_PLAYERS; i++)
5049 struct PlayerInfo *player = &stored_player[i];
5050 int jx = player->jx, jy = player->jy;
5052 if (!player->active)
5056 ABS(jx - x) + ABS(jy - y) < ABS(attr_x - x) + ABS(attr_y - y))
5064 MovDir[x][y] = MV_NO_MOVING;
5066 MovDir[x][y] |= (move_away ? MV_RIGHT : MV_LEFT);
5067 else if (attr_x > x)
5068 MovDir[x][y] |= (move_away ? MV_LEFT : MV_RIGHT);
5070 MovDir[x][y] |= (move_away ? MV_DOWN : MV_UP);
5071 else if (attr_y > y)
5072 MovDir[x][y] |= (move_away ? MV_UP : MV_DOWN);
5074 MovDelay[x][y] = GET_NEW_MOVE_DELAY(element);
5076 if (MovDir[x][y] & MV_HORIZONTAL && MovDir[x][y] & MV_VERTICAL)
5078 boolean first_horiz = RND(2);
5079 int new_move_dir = MovDir[x][y];
5082 new_move_dir & (first_horiz ? MV_HORIZONTAL : MV_VERTICAL);
5083 Moving2Blocked(x, y, &newx, &newy);
5085 if (CUSTOM_ELEMENT_CAN_ENTER_FIELD(element, newx, newy))
5089 new_move_dir & (!first_horiz ? MV_HORIZONTAL : MV_VERTICAL);
5090 Moving2Blocked(x, y, &newx, &newy);
5092 if (CUSTOM_ELEMENT_CAN_ENTER_FIELD(element, newx, newy))
5095 MovDir[x][y] = old_move_dir;
5098 else if (move_pattern == MV_WHEN_PUSHED ||
5099 move_pattern == MV_WHEN_DROPPED)
5101 if (!CUSTOM_ELEMENT_CAN_ENTER_FIELD(element, move_x, move_y))
5102 MovDir[x][y] = MV_NO_MOVING;
5106 else if (move_pattern & MV_MAZE_RUNNER_STYLE)
5108 static int test_xy[7][2] =
5118 static int test_dir[7] =
5128 boolean hunter_mode = (move_pattern == MV_MAZE_HUNTER);
5129 int move_preference = -1000000; /* start with very low preference */
5130 int new_move_dir = MV_NO_MOVING;
5131 int start_test = RND(4);
5134 for (i = 0; i < NUM_DIRECTIONS; i++)
5136 int move_dir = test_dir[start_test + i];
5137 int move_dir_preference;
5139 xx = x + test_xy[start_test + i][0];
5140 yy = y + test_xy[start_test + i][1];
5142 if (hunter_mode && IN_LEV_FIELD(xx, yy) &&
5143 (IS_PLAYER(xx, yy) || Feld[xx][yy] == EL_PLAYER_IS_LEAVING))
5145 new_move_dir = move_dir;
5150 if (!CUSTOM_ELEMENT_CAN_ENTER_FIELD(element, xx, yy))
5153 move_dir_preference = -1 * RunnerVisit[xx][yy];
5154 if (hunter_mode && PlayerVisit[xx][yy] > 0)
5155 move_dir_preference = PlayerVisit[xx][yy];
5157 if (move_dir_preference > move_preference)
5159 /* prefer field that has not been visited for the longest time */
5160 move_preference = move_dir_preference;
5161 new_move_dir = move_dir;
5163 else if (move_dir_preference == move_preference &&
5164 move_dir == old_move_dir)
5166 /* prefer last direction when all directions are preferred equally */
5167 move_preference = move_dir_preference;
5168 new_move_dir = move_dir;
5172 MovDir[x][y] = new_move_dir;
5173 if (old_move_dir != new_move_dir)
5176 MovDelay[x][y] = GET_NEW_MOVE_DELAY(element);
5184 static void TurnRound(int x, int y)
5186 int direction = MovDir[x][y];
5189 GfxDir[x][y] = MovDir[x][y];
5195 GfxDir[x][y] = MovDir[x][y];
5198 if (direction != MovDir[x][y])
5203 GfxAction[x][y] = ACTION_TURNING_FROM_LEFT + MV_DIR_BIT(direction);
5206 GfxAction[x][y] = ACTION_WAITING;
5210 static boolean JustBeingPushed(int x, int y)
5214 for (i = 0; i < MAX_PLAYERS; i++)
5216 struct PlayerInfo *player = &stored_player[i];
5218 if (player->active && player->is_pushing && player->MovPos)
5220 int next_jx = player->jx + (player->jx - player->last_jx);
5221 int next_jy = player->jy + (player->jy - player->last_jy);
5223 if (x == next_jx && y == next_jy)
5231 void StartMoving(int x, int y)
5234 boolean use_spring_bug = (game.engine_version < VERSION_IDENT(2,2,0,0));
5236 boolean started_moving = FALSE; /* some elements can fall _and_ move */
5237 int element = Feld[x][y];
5243 if (MovDelay[x][y] == 0)
5244 GfxAction[x][y] = ACTION_DEFAULT;
5246 /* !!! this should be handled more generic (not only for mole) !!! */
5247 if (element != EL_MOLE && GfxAction[x][y] != ACTION_DIGGING)
5248 GfxAction[x][y] = ACTION_DEFAULT;
5251 if (CAN_FALL(element) && y < lev_fieldy - 1)
5253 if ((x > 0 && IS_PLAYER(x - 1, y)) ||
5254 (x < lev_fieldx - 1 && IS_PLAYER(x + 1, y)))
5255 if (JustBeingPushed(x, y))
5258 if (element == EL_QUICKSAND_FULL)
5260 if (IS_FREE(x, y + 1))
5262 InitMovingField(x, y, MV_DOWN);
5263 started_moving = TRUE;
5265 Feld[x][y] = EL_QUICKSAND_EMPTYING;
5266 Store[x][y] = EL_ROCK;
5268 PlayLevelSoundAction(x, y, ACTION_EMPTYING);
5270 PlayLevelSound(x, y, SND_QUICKSAND_EMPTYING);
5273 else if (Feld[x][y + 1] == EL_QUICKSAND_EMPTY)
5275 if (!MovDelay[x][y])
5276 MovDelay[x][y] = TILEY + 1;
5285 Feld[x][y] = EL_QUICKSAND_EMPTY;
5286 Feld[x][y + 1] = EL_QUICKSAND_FULL;
5287 Store[x][y + 1] = Store[x][y];
5290 PlayLevelSoundAction(x, y, ACTION_FILLING);
5292 PlayLevelSound(x, y, SND_QUICKSAND_FILLING);
5296 else if ((element == EL_ROCK || element == EL_BD_ROCK) &&
5297 Feld[x][y + 1] == EL_QUICKSAND_EMPTY)
5299 InitMovingField(x, y, MV_DOWN);
5300 started_moving = TRUE;
5302 Feld[x][y] = EL_QUICKSAND_FILLING;
5303 Store[x][y] = element;
5305 PlayLevelSoundAction(x, y, ACTION_FILLING);
5307 PlayLevelSound(x, y, SND_QUICKSAND_FILLING);
5310 else if (element == EL_MAGIC_WALL_FULL)
5312 if (IS_FREE(x, y + 1))
5314 InitMovingField(x, y, MV_DOWN);
5315 started_moving = TRUE;
5317 Feld[x][y] = EL_MAGIC_WALL_EMPTYING;
5318 Store[x][y] = EL_CHANGED(Store[x][y]);
5320 else if (Feld[x][y + 1] == EL_MAGIC_WALL_ACTIVE)
5322 if (!MovDelay[x][y])
5323 MovDelay[x][y] = TILEY/4 + 1;
5332 Feld[x][y] = EL_MAGIC_WALL_ACTIVE;
5333 Feld[x][y + 1] = EL_MAGIC_WALL_FULL;
5334 Store[x][y + 1] = EL_CHANGED(Store[x][y]);
5338 else if (element == EL_BD_MAGIC_WALL_FULL)
5340 if (IS_FREE(x, y + 1))
5342 InitMovingField(x, y, MV_DOWN);
5343 started_moving = TRUE;
5345 Feld[x][y] = EL_BD_MAGIC_WALL_EMPTYING;
5346 Store[x][y] = EL_CHANGED2(Store[x][y]);
5348 else if (Feld[x][y + 1] == EL_BD_MAGIC_WALL_ACTIVE)
5350 if (!MovDelay[x][y])
5351 MovDelay[x][y] = TILEY/4 + 1;
5360 Feld[x][y] = EL_BD_MAGIC_WALL_ACTIVE;
5361 Feld[x][y + 1] = EL_BD_MAGIC_WALL_FULL;
5362 Store[x][y + 1] = EL_CHANGED2(Store[x][y]);
5366 else if (CAN_PASS_MAGIC_WALL(element) &&
5367 (Feld[x][y + 1] == EL_MAGIC_WALL_ACTIVE ||
5368 Feld[x][y + 1] == EL_BD_MAGIC_WALL_ACTIVE))
5370 InitMovingField(x, y, MV_DOWN);
5371 started_moving = TRUE;
5374 (Feld[x][y + 1] == EL_MAGIC_WALL_ACTIVE ? EL_MAGIC_WALL_FILLING :
5375 EL_BD_MAGIC_WALL_FILLING);
5376 Store[x][y] = element;
5379 else if (CAN_SMASH(element) && Feld[x][y + 1] == EL_ACID)
5381 else if (CAN_FALL(element) && Feld[x][y + 1] == EL_ACID)
5384 SplashAcid(x, y + 1);
5386 InitMovingField(x, y, MV_DOWN);
5387 started_moving = TRUE;
5389 Store[x][y] = EL_ACID;
5391 /* !!! TEST !!! better use "_FALLING" etc. !!! */
5392 GfxAction[x][y + 1] = ACTION_ACTIVE;
5396 else if ((game.engine_version >= VERSION_IDENT(3,1,0,0) &&
5397 CheckCollision[x][y] && !IS_FREE(x, y + 1)) ||
5399 (game.engine_version >= VERSION_IDENT(3,0,7,0) &&
5400 CAN_SMASH(element) && WasJustFalling[x][y] &&
5401 (Feld[x][y + 1] == EL_BLOCKED || IS_PLAYER(x, y + 1))) ||
5403 (game.engine_version < VERSION_IDENT(2,2,0,7) &&
5404 CAN_SMASH(element) && WasJustMoving[x][y] && !Pushed[x][y + 1] &&
5405 (Feld[x][y + 1] == EL_BLOCKED)))
5409 else if (game.engine_version < VERSION_IDENT(2,2,0,7) &&
5410 CAN_SMASH(element) && Feld[x][y + 1] == EL_BLOCKED &&
5411 WasJustMoving[x][y] && !Pushed[x][y + 1])
5413 else if (CAN_SMASH(element) && Feld[x][y + 1] == EL_BLOCKED &&
5414 WasJustMoving[x][y])
5419 /* this is needed for a special case not covered by calling "Impact()"
5420 from "ContinueMoving()": if an element moves to a tile directly below
5421 another element which was just falling on that tile (which was empty
5422 in the previous frame), the falling element above would just stop
5423 instead of smashing the element below (in previous version, the above
5424 element was just checked for "moving" instead of "falling", resulting
5425 in incorrect smashes caused by horizontal movement of the above
5426 element; also, the case of the player being the element to smash was
5427 simply not covered here... :-/ ) */
5430 WasJustMoving[x][y] = 0;
5431 WasJustFalling[x][y] = 0;
5434 CheckCollision[x][y] = 0;
5437 if (IS_PLAYER(x, y + 1))
5438 printf("::: we ARE now killing the player [%d]\n", FrameCounter);
5443 else if (IS_FREE(x, y + 1) && element == EL_SPRING && level.use_spring_bug)
5445 if (MovDir[x][y] == MV_NO_MOVING)
5447 InitMovingField(x, y, MV_DOWN);
5448 started_moving = TRUE;
5451 else if (IS_FREE(x, y + 1) || Feld[x][y + 1] == EL_DIAMOND_BREAKING)
5453 if (WasJustFalling[x][y]) /* prevent animation from being restarted */
5454 MovDir[x][y] = MV_DOWN;
5456 InitMovingField(x, y, MV_DOWN);
5457 started_moving = TRUE;
5459 else if (element == EL_AMOEBA_DROP)
5461 Feld[x][y] = EL_AMOEBA_GROWING;
5462 Store[x][y] = EL_AMOEBA_WET;
5464 /* Store[x][y + 1] must be zero, because:
5465 (EL_QUICKSAND_FULL -> EL_ROCK): Store[x][y + 1] == EL_QUICKSAND_EMPTY
5468 #if OLD_GAME_BEHAVIOUR
5469 else if (IS_SLIPPERY(Feld[x][y + 1]) && !Store[x][y + 1])
5471 else if (IS_SLIPPERY(Feld[x][y + 1]) && !Store[x][y + 1] &&
5472 !IS_FALLING(x, y + 1) && !WasJustMoving[x][y + 1] &&
5473 element != EL_DX_SUPABOMB)
5476 else if (((IS_SLIPPERY(Feld[x][y + 1]) && !IS_PLAYER(x, y + 1)) ||
5477 (IS_EM_SLIPPERY_WALL(Feld[x][y + 1]) && IS_GEM(element))) &&
5478 !IS_FALLING(x, y + 1) && !WasJustMoving[x][y + 1] &&
5479 element != EL_DX_SUPABOMB && element != EL_SP_DISK_ORANGE)
5482 boolean can_fall_left = (x > 0 && IS_FREE(x - 1, y) &&
5483 (IS_FREE(x - 1, y + 1) ||
5484 Feld[x - 1][y + 1] == EL_ACID));
5485 boolean can_fall_right = (x < lev_fieldx - 1 && IS_FREE(x + 1, y) &&
5486 (IS_FREE(x + 1, y + 1) ||
5487 Feld[x + 1][y + 1] == EL_ACID));
5488 boolean can_fall_any = (can_fall_left || can_fall_right);
5489 boolean can_fall_both = (can_fall_left && can_fall_right);
5491 if (can_fall_any && IS_CUSTOM_ELEMENT(Feld[x][y + 1]))
5493 int slippery_type = element_info[Feld[x][y + 1]].slippery_type;
5495 if (slippery_type == SLIPPERY_ONLY_LEFT)
5496 can_fall_right = FALSE;
5497 else if (slippery_type == SLIPPERY_ONLY_RIGHT)
5498 can_fall_left = FALSE;
5499 else if (slippery_type == SLIPPERY_ANY_LEFT_RIGHT && can_fall_both)
5500 can_fall_right = FALSE;
5501 else if (slippery_type == SLIPPERY_ANY_RIGHT_LEFT && can_fall_both)
5502 can_fall_left = FALSE;
5504 can_fall_any = (can_fall_left || can_fall_right);
5505 can_fall_both = (can_fall_left && can_fall_right);
5508 #if USE_NEW_SP_SLIPPERY
5509 /* !!! better use the same properties as for custom elements here !!! */
5510 else if (game.engine_version >= VERSION_IDENT(3,1,1,0) &&
5511 can_fall_both && IS_SP_ELEMENT(Feld[x][y + 1]))
5513 can_fall_right = FALSE; /* slip down on left side */
5514 can_fall_both = FALSE;
5521 if (game.emulation == EMU_BOULDERDASH ||
5522 element == EL_BD_ROCK || element == EL_BD_DIAMOND)
5523 can_fall_right = FALSE; /* slip down on left side */
5525 can_fall_left = !(can_fall_right = RND(2));
5527 can_fall_both = FALSE;
5534 if (can_fall_both &&
5535 (game.emulation != EMU_BOULDERDASH &&
5536 element != EL_BD_ROCK && element != EL_BD_DIAMOND))
5537 can_fall_left = !(can_fall_right = RND(2));
5540 /* if not determined otherwise, prefer left side for slipping down */
5541 InitMovingField(x, y, can_fall_left ? MV_LEFT : MV_RIGHT);
5542 started_moving = TRUE;
5546 else if (IS_BELT_ACTIVE(Feld[x][y + 1]) && !CAN_MOVE(element))
5548 else if (IS_BELT_ACTIVE(Feld[x][y + 1]))
5551 boolean left_is_free = (x > 0 && IS_FREE(x - 1, y));
5552 boolean right_is_free = (x < lev_fieldx - 1 && IS_FREE(x + 1, y));
5553 int belt_nr = getBeltNrFromBeltActiveElement(Feld[x][y + 1]);
5554 int belt_dir = game.belt_dir[belt_nr];
5556 if ((belt_dir == MV_LEFT && left_is_free) ||
5557 (belt_dir == MV_RIGHT && right_is_free))
5560 int nextx = (belt_dir == MV_LEFT ? x - 1 : x + 1);
5563 InitMovingField(x, y, belt_dir);
5564 started_moving = TRUE;
5567 Pushed[x][y] = TRUE;
5568 Pushed[nextx][y] = TRUE;
5571 GfxAction[x][y] = ACTION_DEFAULT;
5575 MovDir[x][y] = 0; /* if element was moving, stop it */
5580 /* not "else if" because of elements that can fall and move (EL_SPRING) */
5582 if (CAN_MOVE(element) && !started_moving && MovDir[x][y] != MV_NO_MOVING)
5584 if (CAN_MOVE(element) && !started_moving)
5587 int move_pattern = element_info[element].move_pattern;
5592 if (MovDir[x][y] == MV_NO_MOVING)
5594 printf("StartMoving(): %d,%d: element %d ['%s'] not moving\n",
5595 x, y, element, element_info[element].token_name);
5596 printf("StartMoving(): This should never happen!\n");
5601 Moving2Blocked(x, y, &newx, &newy);
5604 if (IS_PUSHABLE(element) && JustBeingPushed(x, y))
5607 if ((element == EL_SATELLITE ||
5608 element == EL_BALLOON ||
5609 element == EL_SPRING)
5610 && JustBeingPushed(x, y))
5617 if (game.engine_version >= VERSION_IDENT(3,1,0,0) &&
5618 CheckCollision[x][y] && !IN_LEV_FIELD_AND_IS_FREE(newx, newy))
5620 if (game.engine_version >= VERSION_IDENT(3,1,0,0) &&
5621 WasJustMoving[x][y] && IN_LEV_FIELD(newx, newy) &&
5622 (Feld[newx][newy] == EL_BLOCKED || IS_PLAYER(newx, newy)))
5626 printf("::: element %d '%s' WasJustMoving %d [%d, %d, %d, %d]\n",
5627 element, element_info[element].token_name,
5628 WasJustMoving[x][y],
5629 HAS_ANY_CHANGE_EVENT(element, CE_HITTING_SOMETHING),
5630 HAS_ANY_CHANGE_EVENT(element, CE_HIT_BY_SOMETHING),
5631 HAS_ANY_CHANGE_EVENT(element, CE_OTHER_IS_HITTING),
5632 HAS_ANY_CHANGE_EVENT(element, CE_OTHER_GETS_HIT));
5636 WasJustMoving[x][y] = 0;
5639 CheckCollision[x][y] = 0;
5641 TestIfElementHitsCustomElement(x, y, MovDir[x][y]);
5644 if (Feld[x][y] != element) /* element has changed */
5646 element = Feld[x][y];
5647 move_pattern = element_info[element].move_pattern;
5649 if (!CAN_MOVE(element))
5653 if (Feld[x][y] != element) /* element has changed */
5661 if (element == EL_SPRING && MovDir[x][y] == MV_DOWN)
5662 Feld[x][y + 1] = EL_EMPTY; /* was set to EL_BLOCKED above */
5664 if (element == EL_SPRING && MovDir[x][y] != MV_NO_MOVING)
5666 Moving2Blocked(x, y, &newx, &newy);
5667 if (Feld[newx][newy] == EL_BLOCKED)
5668 Feld[newx][newy] = EL_EMPTY; /* was set to EL_BLOCKED above */
5674 if (FrameCounter < 1 && x == 0 && y == 29)
5675 printf(":1: %d/%d: %d [%d]\n", x, y, MovDir[x][y], FrameCounter);
5678 if (!MovDelay[x][y]) /* start new movement phase */
5680 /* all objects that can change their move direction after each step
5681 (YAMYAM, DARK_YAMYAM and PACMAN go straight until they hit a wall */
5683 if (element != EL_YAMYAM &&
5684 element != EL_DARK_YAMYAM &&
5685 element != EL_PACMAN &&
5686 !(move_pattern & MV_ANY_DIRECTION) &&
5687 move_pattern != MV_TURNING_LEFT &&
5688 move_pattern != MV_TURNING_RIGHT &&
5689 move_pattern != MV_TURNING_LEFT_RIGHT &&
5690 move_pattern != MV_TURNING_RIGHT_LEFT &&
5691 move_pattern != MV_TURNING_RANDOM)
5696 if (FrameCounter < 1 && x == 0 && y == 29)
5697 printf(":9: %d: %d [%d]\n", y, MovDir[x][y], FrameCounter);
5700 if (MovDelay[x][y] && (element == EL_BUG ||
5701 element == EL_SPACESHIP ||
5702 element == EL_SP_SNIKSNAK ||
5703 element == EL_SP_ELECTRON ||
5704 element == EL_MOLE))
5705 DrawLevelField(x, y);
5709 if (MovDelay[x][y]) /* wait some time before next movement */
5714 if (element == EL_YAMYAM)
5717 el_act_dir2img(EL_YAMYAM, ACTION_WAITING, MV_LEFT));
5718 DrawLevelElementAnimation(x, y, element);
5722 if (MovDelay[x][y]) /* element still has to wait some time */
5725 /* !!! PLACE THIS SOMEWHERE AFTER "TurnRound()" !!! */
5726 ResetGfxAnimation(x, y);
5730 if (GfxAction[x][y] != ACTION_WAITING)
5731 printf("::: %d: %d != ACTION_WAITING\n", element, GfxAction[x][y]);
5733 GfxAction[x][y] = ACTION_WAITING;
5737 if (element == EL_ROBOT ||
5739 element == EL_PACMAN ||
5741 element == EL_YAMYAM ||
5742 element == EL_DARK_YAMYAM)
5745 DrawLevelElementAnimation(x, y, element);
5747 DrawLevelElementAnimationIfNeeded(x, y, element);
5749 PlayLevelSoundAction(x, y, ACTION_WAITING);
5751 else if (element == EL_SP_ELECTRON)
5752 DrawLevelElementAnimationIfNeeded(x, y, element);
5753 else if (element == EL_DRAGON)
5756 int dir = MovDir[x][y];
5757 int dx = (dir == MV_LEFT ? -1 : dir == MV_RIGHT ? +1 : 0);
5758 int dy = (dir == MV_UP ? -1 : dir == MV_DOWN ? +1 : 0);
5759 int graphic = (dir == MV_LEFT ? IMG_FLAMES_1_LEFT :
5760 dir == MV_RIGHT ? IMG_FLAMES_1_RIGHT :
5761 dir == MV_UP ? IMG_FLAMES_1_UP :
5762 dir == MV_DOWN ? IMG_FLAMES_1_DOWN : IMG_EMPTY);
5763 int frame = getGraphicAnimationFrame(graphic, GfxFrame[x][y]);
5766 printf("::: %d, %d\n", GfxAction[x][y], GfxFrame[x][y]);
5769 GfxAction[x][y] = ACTION_ATTACKING;
5771 if (IS_PLAYER(x, y))
5772 DrawPlayerField(x, y);
5774 DrawLevelField(x, y);
5776 PlayLevelSoundActionIfLoop(x, y, ACTION_ATTACKING);
5778 for (i = 1; i <= 3; i++)
5780 int xx = x + i * dx;
5781 int yy = y + i * dy;
5782 int sx = SCREENX(xx);
5783 int sy = SCREENY(yy);
5784 int flame_graphic = graphic + (i - 1);
5786 if (!IN_LEV_FIELD(xx, yy) || IS_DRAGONFIRE_PROOF(Feld[xx][yy]))
5791 int flamed = MovingOrBlocked2Element(xx, yy);
5795 if (IS_CLASSIC_ENEMY(flamed) || CAN_EXPLODE_BY_DRAGONFIRE(flamed))
5797 else if (IS_MOVING(xx, yy) || IS_BLOCKED(xx, yy))
5798 RemoveMovingField(xx, yy);
5800 RemoveField(xx, yy);
5802 if (IS_CLASSIC_ENEMY(flamed) || CAN_EXPLODE_BY_DRAGONFIRE(flamed))
5805 RemoveMovingField(xx, yy);
5809 if (ChangeDelay[xx][yy])
5810 printf("::: !!! [%d]\n", (IS_MOVING(xx, yy) ||
5811 Feld[xx][yy] == EL_BLOCKED));
5815 ChangeDelay[xx][yy] = 0;
5817 Feld[xx][yy] = EL_FLAMES;
5818 if (IN_SCR_FIELD(sx, sy))
5820 DrawLevelFieldCrumbledSand(xx, yy);
5821 DrawGraphic(sx, sy, flame_graphic, frame);
5826 if (Feld[xx][yy] == EL_FLAMES)
5827 Feld[xx][yy] = EL_EMPTY;
5828 DrawLevelField(xx, yy);
5833 if (MovDelay[x][y]) /* element still has to wait some time */
5835 PlayLevelSoundAction(x, y, ACTION_WAITING);
5841 /* special case of "moving" animation of waiting elements (FIX THIS !!!);
5842 for all other elements GfxAction will be set by InitMovingField() */
5843 if (element == EL_BD_BUTTERFLY || element == EL_BD_FIREFLY)
5844 GfxAction[x][y] = ACTION_MOVING;
5848 /* now make next step */
5850 Moving2Blocked(x, y, &newx, &newy); /* get next screen position */
5852 if (DONT_COLLIDE_WITH(element) &&
5853 IN_LEV_FIELD(newx, newy) && IS_PLAYER(newx, newy) &&
5854 !PLAYER_ENEMY_PROTECTED(newx, newy))
5857 TestIfBadThingRunsIntoHero(x, y, MovDir[x][y]);
5861 /* player killed by element which is deadly when colliding with */
5863 KillHero(PLAYERINFO(newx, newy));
5870 else if (CAN_MOVE_INTO_ACID(element) &&
5871 IN_LEV_FIELD(newx, newy) && Feld[newx][newy] == EL_ACID &&
5872 (MovDir[x][y] == MV_DOWN ||
5873 game.engine_version >= VERSION_IDENT(3,1,0,0)))
5875 else if (CAN_MOVE_INTO_ACID(element) && MovDir[x][y] == MV_DOWN &&
5876 IN_LEV_FIELD(newx, newy) && Feld[newx][newy] == EL_ACID)
5880 else if ((element == EL_PENGUIN ||
5881 element == EL_ROBOT ||
5882 element == EL_SATELLITE ||
5883 element == EL_BALLOON ||
5884 IS_CUSTOM_ELEMENT(element)) &&
5885 IN_LEV_FIELD(newx, newy) &&
5886 MovDir[x][y] == MV_DOWN && Feld[newx][newy] == EL_ACID)
5889 SplashAcid(newx, newy);
5890 Store[x][y] = EL_ACID;
5892 else if (element == EL_PENGUIN && IN_LEV_FIELD(newx, newy))
5894 if (Feld[newx][newy] == EL_EXIT_OPEN)
5898 DrawLevelField(x, y);
5900 Feld[x][y] = EL_EMPTY;
5901 DrawLevelField(x, y);
5904 PlayLevelSound(newx, newy, SND_PENGUIN_PASSING);
5905 if (IN_SCR_FIELD(SCREENX(newx), SCREENY(newy)))
5906 DrawGraphicThruMask(SCREENX(newx),SCREENY(newy), el2img(element), 0);
5908 local_player->friends_still_needed--;
5909 if (!local_player->friends_still_needed &&
5910 !local_player->GameOver && AllPlayersGone)
5911 local_player->LevelSolved = local_player->GameOver = TRUE;
5915 else if (IS_FOOD_PENGUIN(Feld[newx][newy]))
5917 if (DigField(local_player, x, y, newx, newy, 0,0, DF_DIG) == MF_MOVING)
5918 DrawLevelField(newx, newy);
5920 GfxDir[x][y] = MovDir[x][y] = MV_NO_MOVING;
5922 else if (!IS_FREE(newx, newy))
5924 GfxAction[x][y] = ACTION_WAITING;
5926 if (IS_PLAYER(x, y))
5927 DrawPlayerField(x, y);
5929 DrawLevelField(x, y);
5934 else if (element == EL_PIG && IN_LEV_FIELD(newx, newy))
5936 if (IS_FOOD_PIG(Feld[newx][newy]))
5938 if (IS_MOVING(newx, newy))
5939 RemoveMovingField(newx, newy);
5942 Feld[newx][newy] = EL_EMPTY;
5943 DrawLevelField(newx, newy);
5946 PlayLevelSound(x, y, SND_PIG_DIGGING);
5948 else if (!IS_FREE(newx, newy))
5950 if (IS_PLAYER(x, y))
5951 DrawPlayerField(x, y);
5953 DrawLevelField(x, y);
5962 else if (move_pattern & MV_MAZE_RUNNER_STYLE && IN_LEV_FIELD(newx, newy))
5965 else if (IS_CUSTOM_ELEMENT(element) &&
5966 CUSTOM_ELEMENT_CAN_ENTER_FIELD(element, newx, newy)
5970 !IS_FREE(newx, newy)
5975 int new_element = Feld[newx][newy];
5978 printf("::: '%s' digs '%s' [%d]\n",
5979 element_info[element].token_name,
5980 element_info[Feld[newx][newy]].token_name,
5981 StorePlayer[newx][newy]);
5984 if (!IS_FREE(newx, newy))
5986 int action = (IS_DIGGABLE(new_element) ? ACTION_DIGGING :
5987 IS_COLLECTIBLE(new_element) ? ACTION_COLLECTING :
5990 /* no element can dig solid indestructible elements */
5991 if (IS_INDESTRUCTIBLE(new_element) &&
5992 !IS_DIGGABLE(new_element) &&
5993 !IS_COLLECTIBLE(new_element))
5996 if (AmoebaNr[newx][newy] &&
5997 (new_element == EL_AMOEBA_FULL ||
5998 new_element == EL_BD_AMOEBA ||
5999 new_element == EL_AMOEBA_GROWING))
6001 AmoebaCnt[AmoebaNr[newx][newy]]--;
6002 AmoebaCnt2[AmoebaNr[newx][newy]]--;
6005 if (IS_MOVING(newx, newy))
6006 RemoveMovingField(newx, newy);
6009 RemoveField(newx, newy);
6010 DrawLevelField(newx, newy);
6013 /* if digged element was about to explode, prevent the explosion */
6014 ExplodeField[newx][newy] = EX_TYPE_NONE;
6016 PlayLevelSoundAction(x, y, action);
6021 Store[newx][newy] = EL_EMPTY;
6022 if (IS_EQUAL_OR_IN_GROUP(new_element, MOVE_ENTER_EL(element)))
6023 Store[newx][newy] = element_info[element].move_leave_element;
6025 Store[newx][newy] = EL_EMPTY;
6026 if (IS_EQUAL_OR_IN_GROUP(new_element, MOVE_ENTER_EL(element)) ||
6027 element_info[element].move_leave_type == LEAVE_TYPE_UNLIMITED)
6028 Store[newx][newy] = element_info[element].move_leave_element;
6031 if (IS_EQUAL_OR_IN_GROUP(new_element, MOVE_ENTER_EL(element)))
6032 element_info[element].can_leave_element = TRUE;
6035 if (move_pattern & MV_MAZE_RUNNER_STYLE)
6037 RunnerVisit[x][y] = FrameCounter;
6038 PlayerVisit[x][y] /= 8; /* expire player visit path */
6044 else if (element == EL_DRAGON && IN_LEV_FIELD(newx, newy))
6046 if (!IS_FREE(newx, newy))
6048 if (IS_PLAYER(x, y))
6049 DrawPlayerField(x, y);
6051 DrawLevelField(x, y);
6057 boolean wanna_flame = !RND(10);
6058 int dx = newx - x, dy = newy - y;
6059 int newx1 = newx + 1 * dx, newy1 = newy + 1 * dy;
6060 int newx2 = newx + 2 * dx, newy2 = newy + 2 * dy;
6061 int element1 = (IN_LEV_FIELD(newx1, newy1) ?
6062 MovingOrBlocked2Element(newx1, newy1) : EL_STEELWALL);
6063 int element2 = (IN_LEV_FIELD(newx2, newy2) ?
6064 MovingOrBlocked2Element(newx2, newy2) : EL_STEELWALL);
6067 IS_CLASSIC_ENEMY(element1) ||
6068 IS_CLASSIC_ENEMY(element2)) &&
6069 element1 != EL_DRAGON && element2 != EL_DRAGON &&
6070 element1 != EL_FLAMES && element2 != EL_FLAMES)
6073 ResetGfxAnimation(x, y);
6074 GfxAction[x][y] = ACTION_ATTACKING;
6077 if (IS_PLAYER(x, y))
6078 DrawPlayerField(x, y);
6080 DrawLevelField(x, y);
6082 PlayLevelSound(x, y, SND_DRAGON_ATTACKING);
6084 MovDelay[x][y] = 50;
6088 RemoveField(newx, newy);
6090 Feld[newx][newy] = EL_FLAMES;
6091 if (IN_LEV_FIELD(newx1, newy1) && Feld[newx1][newy1] == EL_EMPTY)
6094 RemoveField(newx1, newy1);
6096 Feld[newx1][newy1] = EL_FLAMES;
6098 if (IN_LEV_FIELD(newx2, newy2) && Feld[newx2][newy2] == EL_EMPTY)
6101 RemoveField(newx2, newy2);
6103 Feld[newx2][newy2] = EL_FLAMES;
6110 else if (element == EL_YAMYAM && IN_LEV_FIELD(newx, newy) &&
6111 Feld[newx][newy] == EL_DIAMOND)
6113 if (IS_MOVING(newx, newy))
6114 RemoveMovingField(newx, newy);
6117 Feld[newx][newy] = EL_EMPTY;
6118 DrawLevelField(newx, newy);
6121 PlayLevelSound(x, y, SND_YAMYAM_DIGGING);
6123 else if (element == EL_DARK_YAMYAM && IN_LEV_FIELD(newx, newy) &&
6124 IS_FOOD_DARK_YAMYAM(Feld[newx][newy]))
6126 if (AmoebaNr[newx][newy])
6128 AmoebaCnt2[AmoebaNr[newx][newy]]--;
6129 if (Feld[newx][newy] == EL_AMOEBA_FULL ||
6130 Feld[newx][newy] == EL_BD_AMOEBA)
6131 AmoebaCnt[AmoebaNr[newx][newy]]--;
6136 if (IS_MOVING(newx, newy) || IS_BLOCKED(newx, newy))
6138 if (IS_MOVING(newx, newy))
6141 RemoveMovingField(newx, newy);
6145 Feld[newx][newy] = EL_EMPTY;
6146 DrawLevelField(newx, newy);
6149 PlayLevelSound(x, y, SND_DARK_YAMYAM_DIGGING);
6151 else if ((element == EL_PACMAN || element == EL_MOLE)
6152 && IN_LEV_FIELD(newx, newy) && IS_AMOEBOID(Feld[newx][newy]))
6154 if (AmoebaNr[newx][newy])
6156 AmoebaCnt2[AmoebaNr[newx][newy]]--;
6157 if (Feld[newx][newy] == EL_AMOEBA_FULL ||
6158 Feld[newx][newy] == EL_BD_AMOEBA)
6159 AmoebaCnt[AmoebaNr[newx][newy]]--;
6162 if (element == EL_MOLE)
6164 Feld[newx][newy] = EL_AMOEBA_SHRINKING;
6165 PlayLevelSound(x, y, SND_MOLE_DIGGING);
6167 ResetGfxAnimation(x, y);
6168 GfxAction[x][y] = ACTION_DIGGING;
6169 DrawLevelField(x, y);
6171 MovDelay[newx][newy] = 0; /* start amoeba shrinking delay */
6173 return; /* wait for shrinking amoeba */
6175 else /* element == EL_PACMAN */
6177 Feld[newx][newy] = EL_EMPTY;
6178 DrawLevelField(newx, newy);
6179 PlayLevelSound(x, y, SND_PACMAN_DIGGING);
6182 else if (element == EL_MOLE && IN_LEV_FIELD(newx, newy) &&
6183 (Feld[newx][newy] == EL_AMOEBA_SHRINKING ||
6184 (Feld[newx][newy] == EL_EMPTY && Stop[newx][newy])))
6186 /* wait for shrinking amoeba to completely disappear */
6189 else if (!IN_LEV_FIELD(newx, newy) || !IS_FREE(newx, newy))
6191 /* object was running against a wall */
6196 if (move_pattern & MV_ANY_DIRECTION &&
6197 move_pattern == MovDir[x][y])
6199 int blocking_element =
6200 (IN_LEV_FIELD(newx, newy) ? Feld[newx][newy] : BorderElement);
6203 printf("::: '%s' is blocked by '%s'! [%d,%d -> %d,%d]\n",
6204 element_info[element].token_name,
6205 element_info[blocking_element].token_name,
6209 CheckElementChangeBySide(x, y, element, blocking_element, CE_BLOCKED,
6212 element = Feld[x][y]; /* element might have changed */
6217 if (GFX_ELEMENT(element) != EL_SAND) /* !!! FIX THIS (crumble) !!! */
6218 DrawLevelElementAnimation(x, y, element);
6220 if (element == EL_BUG ||
6221 element == EL_SPACESHIP ||
6222 element == EL_SP_SNIKSNAK)
6223 DrawLevelField(x, y);
6224 else if (element == EL_MOLE)
6225 DrawLevelField(x, y);
6226 else if (element == EL_BD_BUTTERFLY ||
6227 element == EL_BD_FIREFLY)
6228 DrawLevelElementAnimationIfNeeded(x, y, element);
6229 else if (element == EL_SATELLITE)
6230 DrawLevelElementAnimationIfNeeded(x, y, element);
6231 else if (element == EL_SP_ELECTRON)
6232 DrawLevelElementAnimationIfNeeded(x, y, element);
6235 if (DONT_TOUCH(element))
6236 TestIfBadThingTouchesHero(x, y);
6239 PlayLevelSoundAction(x, y, ACTION_WAITING);
6245 InitMovingField(x, y, MovDir[x][y]);
6247 PlayLevelSoundAction(x, y, ACTION_MOVING);
6251 ContinueMoving(x, y);
6254 void ContinueMoving(int x, int y)
6256 int element = Feld[x][y];
6257 int stored = Store[x][y];
6258 struct ElementInfo *ei = &element_info[element];
6259 int direction = MovDir[x][y];
6260 int dx = (direction == MV_LEFT ? -1 : direction == MV_RIGHT ? +1 : 0);
6261 int dy = (direction == MV_UP ? -1 : direction == MV_DOWN ? +1 : 0);
6262 int newx = x + dx, newy = y + dy;
6264 int nextx = newx + dx, nexty = newy + dy;
6267 boolean pushed_by_player = (Pushed[x][y] && IS_PLAYER(x, y));
6268 boolean pushed_by_conveyor = (Pushed[x][y] && !IS_PLAYER(x, y));
6270 boolean pushed_by_player = Pushed[x][y];
6273 MovPos[x][y] += getElementMoveStepsize(x, y);
6276 if (pushed_by_player && IS_PLAYER(x, y))
6278 /* special case: moving object pushed by player */
6279 MovPos[x][y] = SIGN(MovPos[x][y]) * (TILEX - ABS(PLAYERINFO(x,y)->MovPos));
6282 if (pushed_by_player) /* special case: moving object pushed by player */
6283 MovPos[x][y] = SIGN(MovPos[x][y]) * (TILEX - ABS(PLAYERINFO(x,y)->MovPos));
6286 if (ABS(MovPos[x][y]) < TILEX)
6288 DrawLevelField(x, y);
6290 return; /* element is still moving */
6293 /* element reached destination field */
6295 Feld[x][y] = EL_EMPTY;
6296 Feld[newx][newy] = element;
6297 MovPos[x][y] = 0; /* force "not moving" for "crumbled sand" */
6300 if (Store[x][y] == EL_ACID) /* element is moving into acid pool */
6302 element = Feld[newx][newy] = EL_ACID;
6305 else if (element == EL_MOLE)
6307 Feld[x][y] = EL_SAND;
6309 DrawLevelFieldCrumbledSandNeighbours(x, y);
6311 else if (element == EL_QUICKSAND_FILLING)
6313 element = Feld[newx][newy] = get_next_element(element);
6314 Store[newx][newy] = Store[x][y];
6316 else if (element == EL_QUICKSAND_EMPTYING)
6318 Feld[x][y] = get_next_element(element);
6319 element = Feld[newx][newy] = Store[x][y];
6321 else if (element == EL_MAGIC_WALL_FILLING)
6323 element = Feld[newx][newy] = get_next_element(element);
6324 if (!game.magic_wall_active)
6325 element = Feld[newx][newy] = EL_MAGIC_WALL_DEAD;
6326 Store[newx][newy] = Store[x][y];
6328 else if (element == EL_MAGIC_WALL_EMPTYING)
6330 Feld[x][y] = get_next_element(element);
6331 if (!game.magic_wall_active)
6332 Feld[x][y] = EL_MAGIC_WALL_DEAD;
6333 element = Feld[newx][newy] = Store[x][y];
6335 else if (element == EL_BD_MAGIC_WALL_FILLING)
6337 element = Feld[newx][newy] = get_next_element(element);
6338 if (!game.magic_wall_active)
6339 element = Feld[newx][newy] = EL_BD_MAGIC_WALL_DEAD;
6340 Store[newx][newy] = Store[x][y];
6342 else if (element == EL_BD_MAGIC_WALL_EMPTYING)
6344 Feld[x][y] = get_next_element(element);
6345 if (!game.magic_wall_active)
6346 Feld[x][y] = EL_BD_MAGIC_WALL_DEAD;
6347 element = Feld[newx][newy] = Store[x][y];
6349 else if (element == EL_AMOEBA_DROPPING)
6351 Feld[x][y] = get_next_element(element);
6352 element = Feld[newx][newy] = Store[x][y];
6354 else if (element == EL_SOKOBAN_OBJECT)
6357 Feld[x][y] = Back[x][y];
6359 if (Back[newx][newy])
6360 Feld[newx][newy] = EL_SOKOBAN_FIELD_FULL;
6362 Back[x][y] = Back[newx][newy] = 0;
6365 else if (Store[x][y] == EL_ACID)
6367 element = Feld[newx][newy] = EL_ACID;
6371 else if (IS_CUSTOM_ELEMENT(element) && !IS_PLAYER(x, y) &&
6372 ei->move_leave_element != EL_EMPTY &&
6373 (ei->move_leave_type == LEAVE_TYPE_UNLIMITED ||
6374 Store[x][y] != EL_EMPTY))
6376 /* some elements can leave other elements behind after moving */
6378 Feld[x][y] = ei->move_leave_element;
6379 InitField(x, y, FALSE);
6381 if (GFX_CRUMBLED(Feld[x][y]))
6382 DrawLevelFieldCrumbledSandNeighbours(x, y);
6386 Store[x][y] = EL_EMPTY;
6387 MovPos[x][y] = MovDir[x][y] = MovDelay[x][y] = 0;
6388 MovDelay[newx][newy] = 0;
6390 if (CAN_CHANGE(element))
6392 /* copy element change control values to new field */
6393 ChangeDelay[newx][newy] = ChangeDelay[x][y];
6394 ChangePage[newx][newy] = ChangePage[x][y];
6395 Changed[newx][newy] = Changed[x][y];
6396 ChangeEvent[newx][newy] = ChangeEvent[x][y];
6399 ChangeDelay[x][y] = 0;
6400 ChangePage[x][y] = -1;
6401 Changed[x][y] = CE_BITMASK_DEFAULT;
6402 ChangeEvent[x][y] = CE_BITMASK_DEFAULT;
6404 /* copy animation control values to new field */
6405 GfxFrame[newx][newy] = GfxFrame[x][y];
6406 GfxRandom[newx][newy] = GfxRandom[x][y]; /* keep same random value */
6407 GfxAction[newx][newy] = GfxAction[x][y]; /* keep action one frame */
6408 GfxDir[newx][newy] = GfxDir[x][y]; /* keep element direction */
6410 Pushed[x][y] = Pushed[newx][newy] = FALSE;
6412 ResetGfxAnimation(x, y); /* reset animation values for old field */
6415 /* some elements can leave other elements behind after moving */
6417 if (IS_CUSTOM_ELEMENT(element) && ei->move_leave_element != EL_EMPTY &&
6418 (ei->move_leave_type == LEAVE_TYPE_UNLIMITED || stored != EL_EMPTY) &&
6419 (!IS_PLAYER(x, y) || IS_WALKABLE(ei->move_leave_element)))
6421 if (IS_CUSTOM_ELEMENT(element) && ei->move_leave_element != EL_EMPTY &&
6422 (ei->move_leave_type == LEAVE_TYPE_UNLIMITED || stored != EL_EMPTY) &&
6426 int move_leave_element = ei->move_leave_element;
6428 Feld[x][y] = move_leave_element;
6429 InitField(x, y, FALSE);
6431 if (GFX_CRUMBLED(Feld[x][y]))
6432 DrawLevelFieldCrumbledSandNeighbours(x, y);
6434 if (ELEM_IS_PLAYER(move_leave_element))
6435 RelocatePlayer(x, y, move_leave_element);
6440 /* some elements can leave other elements behind after moving */
6441 if (IS_CUSTOM_ELEMENT(element) && !IS_PLAYER(x, y) &&
6442 ei->move_leave_element != EL_EMPTY &&
6443 (ei->move_leave_type == LEAVE_TYPE_UNLIMITED ||
6444 ei->can_leave_element_last))
6446 Feld[x][y] = ei->move_leave_element;
6447 InitField(x, y, FALSE);
6449 if (GFX_CRUMBLED(Feld[x][y]))
6450 DrawLevelFieldCrumbledSandNeighbours(x, y);
6453 ei->can_leave_element_last = ei->can_leave_element;
6454 ei->can_leave_element = FALSE;
6458 /* 2.1.1 (does not work correctly for spring) */
6459 if (!CAN_MOVE(element))
6460 MovDir[newx][newy] = 0;
6464 /* (does not work for falling objects that slide horizontally) */
6465 if (CAN_FALL(element) && MovDir[newx][newy] == MV_DOWN)
6466 MovDir[newx][newy] = 0;
6469 if (!CAN_MOVE(element) ||
6470 (element == EL_SPRING && MovDir[newx][newy] == MV_DOWN))
6471 MovDir[newx][newy] = 0;
6475 if (!CAN_MOVE(element) ||
6476 (CAN_FALL(element) && direction == MV_DOWN))
6477 GfxDir[x][y] = MovDir[newx][newy] = 0;
6479 if (!CAN_MOVE(element) ||
6480 (CAN_FALL(element) && direction == MV_DOWN &&
6481 (element == EL_SPRING ||
6482 element_info[element].move_pattern == MV_WHEN_PUSHED ||
6483 element_info[element].move_pattern == MV_WHEN_DROPPED)))
6484 GfxDir[x][y] = MovDir[newx][newy] = 0;
6490 DrawLevelField(x, y);
6491 DrawLevelField(newx, newy);
6493 Stop[newx][newy] = TRUE; /* ignore this element until the next frame */
6495 /* prevent pushed element from moving on in pushed direction */
6496 if (pushed_by_player && CAN_MOVE(element) &&
6497 element_info[element].move_pattern & MV_ANY_DIRECTION &&
6498 !(element_info[element].move_pattern & direction))
6499 TurnRound(newx, newy);
6502 /* prevent elements on conveyor belt from moving on in last direction */
6503 if (pushed_by_conveyor && CAN_FALL(element) &&
6504 direction & MV_HORIZONTAL)
6507 if (CAN_MOVE(element))
6508 InitMovDir(newx, newy);
6510 MovDir[newx][newy] = 0;
6512 MovDir[newx][newy] = 0;
6517 if (!pushed_by_player)
6519 int nextx = newx + dx, nexty = newy + dy;
6520 boolean check_collision_again = IN_LEV_FIELD_AND_IS_FREE(nextx, nexty);
6522 WasJustMoving[newx][newy] = 3;
6524 if (CAN_FALL(element) && direction == MV_DOWN)
6525 WasJustFalling[newx][newy] = 3;
6527 if ((!CAN_FALL(element) || direction == MV_DOWN) && check_collision_again)
6528 CheckCollision[newx][newy] = 2;
6531 if (DONT_TOUCH(element)) /* object may be nasty to player or others */
6533 TestIfBadThingTouchesHero(newx, newy);
6534 TestIfBadThingTouchesFriend(newx, newy);
6536 if (!IS_CUSTOM_ELEMENT(element))
6537 TestIfBadThingTouchesOtherBadThing(newx, newy);
6539 else if (element == EL_PENGUIN)
6540 TestIfFriendTouchesBadThing(newx, newy);
6542 #if USE_NEW_MOVE_STYLE
6544 if (CAN_FALL(element) && direction == MV_DOWN &&
6545 (newy == lev_fieldy - 1 || !IS_FREE(x, newy + 1)) &&
6546 IS_PLAYER(x, newy + 1))
6547 printf("::: we would now kill the player [%d]\n", FrameCounter);
6550 /* give the player one last chance (one more frame) to move away */
6551 if (CAN_FALL(element) && direction == MV_DOWN &&
6552 (newy == lev_fieldy - 1 || !IS_FREE(x, newy + 1)) &&
6553 (!IS_PLAYER(x, newy + 1) ||
6554 game.engine_version < VERSION_IDENT(3,1,1,0)))
6557 if (CAN_FALL(element) && direction == MV_DOWN &&
6558 (newy == lev_fieldy - 1 || !IS_FREE(x, newy + 1)))
6566 if (pushed_by_player && !game.use_bug_change_when_pushing)
6568 if (pushed_by_player && game.engine_version >= VERSION_IDENT(3,1,0,0))
6571 if (pushed_by_player)
6576 int dig_side = MV_DIR_OPPOSITE(direction);
6578 static int trigger_sides[4] =
6580 CH_SIDE_RIGHT, /* moving left */
6581 CH_SIDE_LEFT, /* moving right */
6582 CH_SIDE_BOTTOM, /* moving up */
6583 CH_SIDE_TOP, /* moving down */
6585 int dig_side = trigger_sides[MV_DIR_BIT(direction)];
6587 struct PlayerInfo *player = PLAYERINFO(x, y);
6589 CheckElementChangeByPlayer(newx, newy, element, CE_PUSHED_BY_PLAYER,
6590 player->index_bit, dig_side);
6591 CheckTriggeredElementChangeByPlayer(newx,newy,element,CE_OTHER_GETS_PUSHED,
6592 player->index_bit, dig_side);
6597 TestIfElementTouchesCustomElement(x, y); /* empty or new element */
6601 if (ChangePage[newx][newy] != -1) /* delayed change */
6602 ChangeElement(newx, newy, ChangePage[newx][newy]);
6607 TestIfElementHitsCustomElement(newx, newy, direction);
6611 if (!IN_LEV_FIELD(nextx, nexty) || !IS_FREE(nextx, nexty))
6613 int hitting_element = Feld[newx][newy];
6615 /* !!! fix side (direction) orientation here and elsewhere !!! */
6616 CheckElementChangeBySide(newx, newy, hitting_element, CE_HITTING_SOMETHING,
6620 if (IN_LEV_FIELD(nextx, nexty))
6622 int opposite_direction = MV_DIR_OPPOSITE(direction);
6623 int hitting_side = direction;
6624 int touched_side = opposite_direction;
6625 int touched_element = MovingOrBlocked2Element(nextx, nexty);
6626 boolean object_hit = (!IS_MOVING(nextx, nexty) ||
6627 MovDir[nextx][nexty] != direction ||
6628 ABS(MovPos[nextx][nexty]) <= TILEY / 2);
6634 CheckElementChangeBySide(nextx, nexty, touched_element,
6635 CE_HIT_BY_SOMETHING, opposite_direction);
6637 if (IS_CUSTOM_ELEMENT(hitting_element) &&
6638 HAS_ANY_CHANGE_EVENT(hitting_element, CE_OTHER_IS_HITTING))
6640 for (i = 0; i < element_info[hitting_element].num_change_pages; i++)
6642 struct ElementChangeInfo *change =
6643 &element_info[hitting_element].change_page[i];
6645 if (change->can_change &&
6646 change->events & CH_EVENT_BIT(CE_OTHER_IS_HITTING) &&
6647 change->trigger_side & touched_side &&
6648 change->trigger_element == touched_element)
6650 CheckElementChangeByPage(newx, newy, hitting_element,
6651 touched_element, CE_OTHER_IS_HITTING,i);
6657 if (IS_CUSTOM_ELEMENT(touched_element) &&
6658 HAS_ANY_CHANGE_EVENT(touched_element, CE_OTHER_GETS_HIT))
6660 for (i = 0; i < element_info[touched_element].num_change_pages; i++)
6662 struct ElementChangeInfo *change =
6663 &element_info[touched_element].change_page[i];
6665 if (change->can_change &&
6666 change->events & CH_EVENT_BIT(CE_OTHER_GETS_HIT) &&
6667 change->trigger_side & hitting_side &&
6668 change->trigger_element == hitting_element)
6670 CheckElementChangeByPage(nextx, nexty, touched_element,
6671 hitting_element, CE_OTHER_GETS_HIT, i);
6682 TestIfPlayerTouchesCustomElement(newx, newy);
6683 TestIfElementTouchesCustomElement(newx, newy);
6686 int AmoebeNachbarNr(int ax, int ay)
6689 int element = Feld[ax][ay];
6691 static int xy[4][2] =
6699 for (i = 0; i < NUM_DIRECTIONS; i++)
6701 int x = ax + xy[i][0];
6702 int y = ay + xy[i][1];
6704 if (!IN_LEV_FIELD(x, y))
6707 if (Feld[x][y] == element && AmoebaNr[x][y] > 0)
6708 group_nr = AmoebaNr[x][y];
6714 void AmoebenVereinigen(int ax, int ay)
6716 int i, x, y, xx, yy;
6717 int new_group_nr = AmoebaNr[ax][ay];
6718 static int xy[4][2] =
6726 if (new_group_nr == 0)
6729 for (i = 0; i < NUM_DIRECTIONS; i++)
6734 if (!IN_LEV_FIELD(x, y))
6737 if ((Feld[x][y] == EL_AMOEBA_FULL ||
6738 Feld[x][y] == EL_BD_AMOEBA ||
6739 Feld[x][y] == EL_AMOEBA_DEAD) &&
6740 AmoebaNr[x][y] != new_group_nr)
6742 int old_group_nr = AmoebaNr[x][y];
6744 if (old_group_nr == 0)
6747 AmoebaCnt[new_group_nr] += AmoebaCnt[old_group_nr];
6748 AmoebaCnt[old_group_nr] = 0;
6749 AmoebaCnt2[new_group_nr] += AmoebaCnt2[old_group_nr];
6750 AmoebaCnt2[old_group_nr] = 0;
6752 for (yy = 0; yy < lev_fieldy; yy++)
6754 for (xx = 0; xx < lev_fieldx; xx++)
6756 if (AmoebaNr[xx][yy] == old_group_nr)
6757 AmoebaNr[xx][yy] = new_group_nr;
6764 void AmoebeUmwandeln(int ax, int ay)
6768 if (Feld[ax][ay] == EL_AMOEBA_DEAD)
6770 int group_nr = AmoebaNr[ax][ay];
6775 printf("AmoebeUmwandeln(): ax = %d, ay = %d\n", ax, ay);
6776 printf("AmoebeUmwandeln(): This should never happen!\n");
6781 for (y = 0; y < lev_fieldy; y++)
6783 for (x = 0; x < lev_fieldx; x++)
6785 if (Feld[x][y] == EL_AMOEBA_DEAD && AmoebaNr[x][y] == group_nr)
6788 Feld[x][y] = EL_AMOEBA_TO_DIAMOND;
6792 PlayLevelSound(ax, ay, (IS_GEM(level.amoeba_content) ?
6793 SND_AMOEBA_TURNING_TO_GEM :
6794 SND_AMOEBA_TURNING_TO_ROCK));
6799 static int xy[4][2] =
6807 for (i = 0; i < NUM_DIRECTIONS; i++)
6812 if (!IN_LEV_FIELD(x, y))
6815 if (Feld[x][y] == EL_AMOEBA_TO_DIAMOND)
6817 PlayLevelSound(x, y, (IS_GEM(level.amoeba_content) ?
6818 SND_AMOEBA_TURNING_TO_GEM :
6819 SND_AMOEBA_TURNING_TO_ROCK));
6826 void AmoebeUmwandelnBD(int ax, int ay, int new_element)
6829 int group_nr = AmoebaNr[ax][ay];
6830 boolean done = FALSE;
6835 printf("AmoebeUmwandelnBD(): ax = %d, ay = %d\n", ax, ay);
6836 printf("AmoebeUmwandelnBD(): This should never happen!\n");
6841 for (y = 0; y < lev_fieldy; y++)
6843 for (x = 0; x < lev_fieldx; x++)
6845 if (AmoebaNr[x][y] == group_nr &&
6846 (Feld[x][y] == EL_AMOEBA_DEAD ||
6847 Feld[x][y] == EL_BD_AMOEBA ||
6848 Feld[x][y] == EL_AMOEBA_GROWING))
6851 Feld[x][y] = new_element;
6852 InitField(x, y, FALSE);
6853 DrawLevelField(x, y);
6860 PlayLevelSound(ax, ay, (new_element == EL_BD_ROCK ?
6861 SND_BD_AMOEBA_TURNING_TO_ROCK :
6862 SND_BD_AMOEBA_TURNING_TO_GEM));
6865 void AmoebeWaechst(int x, int y)
6867 static unsigned long sound_delay = 0;
6868 static unsigned long sound_delay_value = 0;
6870 if (!MovDelay[x][y]) /* start new growing cycle */
6874 if (DelayReached(&sound_delay, sound_delay_value))
6877 PlayLevelSoundElementAction(x, y, Store[x][y], ACTION_GROWING);
6879 if (Store[x][y] == EL_BD_AMOEBA)
6880 PlayLevelSound(x, y, SND_BD_AMOEBA_GROWING);
6882 PlayLevelSound(x, y, SND_AMOEBA_GROWING);
6884 sound_delay_value = 30;
6888 if (MovDelay[x][y]) /* wait some time before growing bigger */
6891 if (MovDelay[x][y]/2 && IN_SCR_FIELD(SCREENX(x), SCREENY(y)))
6893 int frame = getGraphicAnimationFrame(IMG_AMOEBA_GROWING,
6894 6 - MovDelay[x][y]);
6896 DrawGraphic(SCREENX(x), SCREENY(y), IMG_AMOEBA_GROWING, frame);
6899 if (!MovDelay[x][y])
6901 Feld[x][y] = Store[x][y];
6903 DrawLevelField(x, y);
6908 void AmoebaDisappearing(int x, int y)
6910 static unsigned long sound_delay = 0;
6911 static unsigned long sound_delay_value = 0;
6913 if (!MovDelay[x][y]) /* start new shrinking cycle */
6917 if (DelayReached(&sound_delay, sound_delay_value))
6918 sound_delay_value = 30;
6921 if (MovDelay[x][y]) /* wait some time before shrinking */
6924 if (MovDelay[x][y]/2 && IN_SCR_FIELD(SCREENX(x), SCREENY(y)))
6926 int frame = getGraphicAnimationFrame(IMG_AMOEBA_SHRINKING,
6927 6 - MovDelay[x][y]);
6929 DrawGraphic(SCREENX(x), SCREENY(y), IMG_AMOEBA_SHRINKING, frame);
6932 if (!MovDelay[x][y])
6934 Feld[x][y] = EL_EMPTY;
6935 DrawLevelField(x, y);
6937 /* don't let mole enter this field in this cycle;
6938 (give priority to objects falling to this field from above) */
6944 void AmoebeAbleger(int ax, int ay)
6947 int element = Feld[ax][ay];
6948 int graphic = el2img(element);
6949 int newax = ax, neway = ay;
6950 static int xy[4][2] =
6958 if (!level.amoeba_speed)
6960 Feld[ax][ay] = EL_AMOEBA_DEAD;
6961 DrawLevelField(ax, ay);
6965 if (IS_ANIMATED(graphic))
6966 DrawLevelGraphicAnimationIfNeeded(ax, ay, graphic);
6968 if (!MovDelay[ax][ay]) /* start making new amoeba field */
6969 MovDelay[ax][ay] = RND(FRAMES_PER_SECOND * 25 / (1 + level.amoeba_speed));
6971 if (MovDelay[ax][ay]) /* wait some time before making new amoeba */
6974 if (MovDelay[ax][ay])
6978 if (element == EL_AMOEBA_WET) /* object is an acid / amoeba drop */
6981 int x = ax + xy[start][0];
6982 int y = ay + xy[start][1];
6984 if (!IN_LEV_FIELD(x, y))
6988 if (IS_FREE(x, y) ||
6989 CAN_GROW_INTO(Feld[x][y]) ||
6990 Feld[x][y] == EL_QUICKSAND_EMPTY)
6996 /* !!! extend EL_SAND to anything diggable (but maybe not SP_BASE) !!! */
6997 if (IS_FREE(x, y) ||
6998 Feld[x][y] == EL_SAND || Feld[x][y] == EL_QUICKSAND_EMPTY)
7005 if (newax == ax && neway == ay)
7008 else /* normal or "filled" (BD style) amoeba */
7011 boolean waiting_for_player = FALSE;
7013 for (i = 0; i < NUM_DIRECTIONS; i++)
7015 int j = (start + i) % 4;
7016 int x = ax + xy[j][0];
7017 int y = ay + xy[j][1];
7019 if (!IN_LEV_FIELD(x, y))
7023 if (IS_FREE(x, y) ||
7024 CAN_GROW_INTO(Feld[x][y]) ||
7025 Feld[x][y] == EL_QUICKSAND_EMPTY)
7032 /* !!! extend EL_SAND to anything diggable (but maybe not SP_BASE) !!! */
7033 if (IS_FREE(x, y) ||
7034 Feld[x][y] == EL_SAND || Feld[x][y] == EL_QUICKSAND_EMPTY)
7041 else if (IS_PLAYER(x, y))
7042 waiting_for_player = TRUE;
7045 if (newax == ax && neway == ay) /* amoeba cannot grow */
7048 if (i == 4 && (!waiting_for_player || element == EL_BD_AMOEBA))
7050 if (i == 4 && (!waiting_for_player || game.emulation == EMU_BOULDERDASH))
7053 Feld[ax][ay] = EL_AMOEBA_DEAD;
7054 DrawLevelField(ax, ay);
7055 AmoebaCnt[AmoebaNr[ax][ay]]--;
7057 if (AmoebaCnt[AmoebaNr[ax][ay]] <= 0) /* amoeba is completely dead */
7059 if (element == EL_AMOEBA_FULL)
7060 AmoebeUmwandeln(ax, ay);
7061 else if (element == EL_BD_AMOEBA)
7062 AmoebeUmwandelnBD(ax, ay, level.amoeba_content);
7067 else if (element == EL_AMOEBA_FULL || element == EL_BD_AMOEBA)
7069 /* amoeba gets larger by growing in some direction */
7071 int new_group_nr = AmoebaNr[ax][ay];
7074 if (new_group_nr == 0)
7076 printf("AmoebeAbleger(): newax = %d, neway = %d\n", newax, neway);
7077 printf("AmoebeAbleger(): This should never happen!\n");
7082 AmoebaNr[newax][neway] = new_group_nr;
7083 AmoebaCnt[new_group_nr]++;
7084 AmoebaCnt2[new_group_nr]++;
7086 /* if amoeba touches other amoeba(s) after growing, unify them */
7087 AmoebenVereinigen(newax, neway);
7089 if (element == EL_BD_AMOEBA && AmoebaCnt2[new_group_nr] >= 200)
7091 AmoebeUmwandelnBD(newax, neway, EL_BD_ROCK);
7097 if (element != EL_AMOEBA_WET || neway < ay || !IS_FREE(newax, neway) ||
7098 (neway == lev_fieldy - 1 && newax != ax))
7100 Feld[newax][neway] = EL_AMOEBA_GROWING; /* creation of new amoeba */
7101 Store[newax][neway] = element;
7103 else if (neway == ay)
7105 Feld[newax][neway] = EL_AMOEBA_DROP; /* drop left/right of amoeba */
7107 PlayLevelSoundAction(newax, neway, ACTION_GROWING);
7109 PlayLevelSound(newax, neway, SND_AMOEBA_GROWING);
7114 InitMovingField(ax, ay, MV_DOWN); /* drop dripping from amoeba */
7115 Feld[ax][ay] = EL_AMOEBA_DROPPING;
7116 Store[ax][ay] = EL_AMOEBA_DROP;
7117 ContinueMoving(ax, ay);
7121 DrawLevelField(newax, neway);
7124 void Life(int ax, int ay)
7127 static int life[4] = { 2, 3, 3, 3 }; /* parameters for "game of life" */
7129 int element = Feld[ax][ay];
7130 int graphic = el2img(element);
7131 boolean changed = FALSE;
7133 if (IS_ANIMATED(graphic))
7134 DrawLevelGraphicAnimationIfNeeded(ax, ay, graphic);
7139 if (!MovDelay[ax][ay]) /* start new "game of life" cycle */
7140 MovDelay[ax][ay] = life_time;
7142 if (MovDelay[ax][ay]) /* wait some time before next cycle */
7145 if (MovDelay[ax][ay])
7149 for (y1 = -1; y1 < 2; y1++) for (x1 = -1; x1 < 2; x1++)
7151 int xx = ax+x1, yy = ay+y1;
7154 if (!IN_LEV_FIELD(xx, yy))
7157 for (y2 = -1; y2 < 2; y2++) for (x2 = -1; x2 < 2; x2++)
7159 int x = xx+x2, y = yy+y2;
7161 if (!IN_LEV_FIELD(x, y) || (x == xx && y == yy))
7164 if (((Feld[x][y] == element ||
7165 (element == EL_GAME_OF_LIFE && IS_PLAYER(x, y))) &&
7167 (IS_FREE(x, y) && Stop[x][y]))
7171 if (xx == ax && yy == ay) /* field in the middle */
7173 if (nachbarn < life[0] || nachbarn > life[1])
7175 Feld[xx][yy] = EL_EMPTY;
7177 DrawLevelField(xx, yy);
7178 Stop[xx][yy] = TRUE;
7183 else if (IS_FREE(xx, yy) || CAN_GROW_INTO(Feld[xx][yy]))
7184 { /* free border field */
7185 if (nachbarn >= life[2] && nachbarn <= life[3])
7187 Feld[xx][yy] = element;
7188 MovDelay[xx][yy] = (element == EL_GAME_OF_LIFE ? 0 : life_time-1);
7190 DrawLevelField(xx, yy);
7191 Stop[xx][yy] = TRUE;
7196 /* !!! extend EL_SAND to anything diggable (but maybe not SP_BASE) !!! */
7197 else if (IS_FREE(xx, yy) || Feld[xx][yy] == EL_SAND)
7198 { /* free border field */
7199 if (nachbarn >= life[2] && nachbarn <= life[3])
7201 Feld[xx][yy] = element;
7202 MovDelay[xx][yy] = (element == EL_GAME_OF_LIFE ? 0 : life_time-1);
7204 DrawLevelField(xx, yy);
7205 Stop[xx][yy] = TRUE;
7213 PlayLevelSound(ax, ay, element == EL_BIOMAZE ? SND_BIOMAZE_GROWING :
7214 SND_GAME_OF_LIFE_GROWING);
7217 static void InitRobotWheel(int x, int y)
7219 ChangeDelay[x][y] = level.time_wheel * FRAMES_PER_SECOND;
7222 static void RunRobotWheel(int x, int y)
7224 PlayLevelSound(x, y, SND_ROBOT_WHEEL_ACTIVE);
7227 static void StopRobotWheel(int x, int y)
7229 if (ZX == x && ZY == y)
7233 static void InitTimegateWheel(int x, int y)
7236 ChangeDelay[x][y] = level.time_timegate * FRAMES_PER_SECOND;
7238 /* another brainless, "type style" bug ... :-( */
7239 ChangeDelay[x][y] = level.time_wheel * FRAMES_PER_SECOND;
7243 static void RunTimegateWheel(int x, int y)
7245 PlayLevelSound(x, y, SND_TIMEGATE_SWITCH_ACTIVE);
7248 void CheckExit(int x, int y)
7250 if (local_player->gems_still_needed > 0 ||
7251 local_player->sokobanfields_still_needed > 0 ||
7252 local_player->lights_still_needed > 0)
7254 int element = Feld[x][y];
7255 int graphic = el2img(element);
7257 if (IS_ANIMATED(graphic))
7258 DrawLevelGraphicAnimationIfNeeded(x, y, graphic);
7263 if (AllPlayersGone) /* do not re-open exit door closed after last player */
7266 Feld[x][y] = EL_EXIT_OPENING;
7268 PlayLevelSoundNearest(x, y, SND_CLASS_EXIT_OPENING);
7271 void CheckExitSP(int x, int y)
7273 if (local_player->gems_still_needed > 0)
7275 int element = Feld[x][y];
7276 int graphic = el2img(element);
7278 if (IS_ANIMATED(graphic))
7279 DrawLevelGraphicAnimationIfNeeded(x, y, graphic);
7284 if (AllPlayersGone) /* do not re-open exit door closed after last player */
7287 Feld[x][y] = EL_SP_EXIT_OPENING;
7289 PlayLevelSoundNearest(x, y, SND_CLASS_SP_EXIT_OPENING);
7292 static void CloseAllOpenTimegates()
7296 for (y = 0; y < lev_fieldy; y++)
7298 for (x = 0; x < lev_fieldx; x++)
7300 int element = Feld[x][y];
7302 if (element == EL_TIMEGATE_OPEN || element == EL_TIMEGATE_OPENING)
7304 Feld[x][y] = EL_TIMEGATE_CLOSING;
7306 PlayLevelSoundAction(x, y, ACTION_CLOSING);
7308 PlayLevelSound(x, y, SND_TIMEGATE_CLOSING);
7315 void EdelsteinFunkeln(int x, int y)
7317 if (!IN_SCR_FIELD(SCREENX(x), SCREENY(y)) || IS_MOVING(x, y))
7320 if (Feld[x][y] == EL_BD_DIAMOND)
7323 if (MovDelay[x][y] == 0) /* next animation frame */
7324 MovDelay[x][y] = 11 * !SimpleRND(500);
7326 if (MovDelay[x][y] != 0) /* wait some time before next frame */
7330 if (setup.direct_draw && MovDelay[x][y])
7331 SetDrawtoField(DRAW_BUFFERED);
7333 DrawLevelElementAnimation(x, y, Feld[x][y]);
7335 if (MovDelay[x][y] != 0)
7337 int frame = getGraphicAnimationFrame(IMG_TWINKLE_WHITE,
7338 10 - MovDelay[x][y]);
7340 DrawGraphicThruMask(SCREENX(x), SCREENY(y), IMG_TWINKLE_WHITE, frame);
7342 if (setup.direct_draw)
7346 dest_x = FX + SCREENX(x) * TILEX;
7347 dest_y = FY + SCREENY(y) * TILEY;
7349 BlitBitmap(drawto_field, window,
7350 dest_x, dest_y, TILEX, TILEY, dest_x, dest_y);
7351 SetDrawtoField(DRAW_DIRECT);
7357 void MauerWaechst(int x, int y)
7361 if (!MovDelay[x][y]) /* next animation frame */
7362 MovDelay[x][y] = 3 * delay;
7364 if (MovDelay[x][y]) /* wait some time before next frame */
7368 if (IN_SCR_FIELD(SCREENX(x), SCREENY(y)))
7370 int graphic = el_dir2img(Feld[x][y], GfxDir[x][y]);
7371 int frame = getGraphicAnimationFrame(graphic, 17 - MovDelay[x][y]);
7373 DrawGraphic(SCREENX(x), SCREENY(y), graphic, frame);
7376 if (!MovDelay[x][y])
7378 if (MovDir[x][y] == MV_LEFT)
7380 if (IN_LEV_FIELD(x - 1, y) && IS_WALL(Feld[x - 1][y]))
7381 DrawLevelField(x - 1, y);
7383 else if (MovDir[x][y] == MV_RIGHT)
7385 if (IN_LEV_FIELD(x + 1, y) && IS_WALL(Feld[x + 1][y]))
7386 DrawLevelField(x + 1, y);
7388 else if (MovDir[x][y] == MV_UP)
7390 if (IN_LEV_FIELD(x, y - 1) && IS_WALL(Feld[x][y - 1]))
7391 DrawLevelField(x, y - 1);
7395 if (IN_LEV_FIELD(x, y + 1) && IS_WALL(Feld[x][y + 1]))
7396 DrawLevelField(x, y + 1);
7399 Feld[x][y] = Store[x][y];
7401 GfxDir[x][y] = MovDir[x][y] = MV_NO_MOVING;
7402 DrawLevelField(x, y);
7407 void MauerAbleger(int ax, int ay)
7409 int element = Feld[ax][ay];
7410 int graphic = el2img(element);
7411 boolean oben_frei = FALSE, unten_frei = FALSE;
7412 boolean links_frei = FALSE, rechts_frei = FALSE;
7413 boolean oben_massiv = FALSE, unten_massiv = FALSE;
7414 boolean links_massiv = FALSE, rechts_massiv = FALSE;
7415 boolean new_wall = FALSE;
7417 if (IS_ANIMATED(graphic))
7418 DrawLevelGraphicAnimationIfNeeded(ax, ay, graphic);
7420 if (!MovDelay[ax][ay]) /* start building new wall */
7421 MovDelay[ax][ay] = 6;
7423 if (MovDelay[ax][ay]) /* wait some time before building new wall */
7426 if (MovDelay[ax][ay])
7430 if (IN_LEV_FIELD(ax, ay-1) && IS_FREE(ax, ay-1))
7432 if (IN_LEV_FIELD(ax, ay+1) && IS_FREE(ax, ay+1))
7434 if (IN_LEV_FIELD(ax-1, ay) && IS_FREE(ax-1, ay))
7436 if (IN_LEV_FIELD(ax+1, ay) && IS_FREE(ax+1, ay))
7439 if (element == EL_EXPANDABLE_WALL_VERTICAL ||
7440 element == EL_EXPANDABLE_WALL_ANY)
7444 Feld[ax][ay-1] = EL_EXPANDABLE_WALL_GROWING;
7445 Store[ax][ay-1] = element;
7446 GfxDir[ax][ay-1] = MovDir[ax][ay-1] = MV_UP;
7447 if (IN_SCR_FIELD(SCREENX(ax), SCREENY(ay-1)))
7448 DrawGraphic(SCREENX(ax), SCREENY(ay - 1),
7449 IMG_EXPANDABLE_WALL_GROWING_UP, 0);
7454 Feld[ax][ay+1] = EL_EXPANDABLE_WALL_GROWING;
7455 Store[ax][ay+1] = element;
7456 GfxDir[ax][ay+1] = MovDir[ax][ay+1] = MV_DOWN;
7457 if (IN_SCR_FIELD(SCREENX(ax), SCREENY(ay+1)))
7458 DrawGraphic(SCREENX(ax), SCREENY(ay + 1),
7459 IMG_EXPANDABLE_WALL_GROWING_DOWN, 0);
7464 if (element == EL_EXPANDABLE_WALL_HORIZONTAL ||
7465 element == EL_EXPANDABLE_WALL_ANY ||
7466 element == EL_EXPANDABLE_WALL)
7470 Feld[ax-1][ay] = EL_EXPANDABLE_WALL_GROWING;
7471 Store[ax-1][ay] = element;
7472 GfxDir[ax-1][ay] = MovDir[ax-1][ay] = MV_LEFT;
7473 if (IN_SCR_FIELD(SCREENX(ax-1), SCREENY(ay)))
7474 DrawGraphic(SCREENX(ax - 1), SCREENY(ay),
7475 IMG_EXPANDABLE_WALL_GROWING_LEFT, 0);
7481 Feld[ax+1][ay] = EL_EXPANDABLE_WALL_GROWING;
7482 Store[ax+1][ay] = element;
7483 GfxDir[ax+1][ay] = MovDir[ax+1][ay] = MV_RIGHT;
7484 if (IN_SCR_FIELD(SCREENX(ax+1), SCREENY(ay)))
7485 DrawGraphic(SCREENX(ax + 1), SCREENY(ay),
7486 IMG_EXPANDABLE_WALL_GROWING_RIGHT, 0);
7491 if (element == EL_EXPANDABLE_WALL && (links_frei || rechts_frei))
7492 DrawLevelField(ax, ay);
7494 if (!IN_LEV_FIELD(ax, ay-1) || IS_WALL(Feld[ax][ay-1]))
7496 if (!IN_LEV_FIELD(ax, ay+1) || IS_WALL(Feld[ax][ay+1]))
7497 unten_massiv = TRUE;
7498 if (!IN_LEV_FIELD(ax-1, ay) || IS_WALL(Feld[ax-1][ay]))
7499 links_massiv = TRUE;
7500 if (!IN_LEV_FIELD(ax+1, ay) || IS_WALL(Feld[ax+1][ay]))
7501 rechts_massiv = TRUE;
7503 if (((oben_massiv && unten_massiv) ||
7504 element == EL_EXPANDABLE_WALL_HORIZONTAL ||
7505 element == EL_EXPANDABLE_WALL) &&
7506 ((links_massiv && rechts_massiv) ||
7507 element == EL_EXPANDABLE_WALL_VERTICAL))
7508 Feld[ax][ay] = EL_WALL;
7512 PlayLevelSoundAction(ax, ay, ACTION_GROWING);
7514 PlayLevelSound(ax, ay, SND_EXPANDABLE_WALL_GROWING);
7518 void CheckForDragon(int x, int y)
7521 boolean dragon_found = FALSE;
7522 static int xy[4][2] =
7530 for (i = 0; i < NUM_DIRECTIONS; i++)
7532 for (j = 0; j < 4; j++)
7534 int xx = x + j * xy[i][0], yy = y + j * xy[i][1];
7536 if (IN_LEV_FIELD(xx, yy) &&
7537 (Feld[xx][yy] == EL_FLAMES || Feld[xx][yy] == EL_DRAGON))
7539 if (Feld[xx][yy] == EL_DRAGON)
7540 dragon_found = TRUE;
7549 for (i = 0; i < NUM_DIRECTIONS; i++)
7551 for (j = 0; j < 3; j++)
7553 int xx = x + j * xy[i][0], yy = y + j * xy[i][1];
7555 if (IN_LEV_FIELD(xx, yy) && Feld[xx][yy] == EL_FLAMES)
7557 Feld[xx][yy] = EL_EMPTY;
7558 DrawLevelField(xx, yy);
7567 static void InitBuggyBase(int x, int y)
7569 int element = Feld[x][y];
7570 int activating_delay = FRAMES_PER_SECOND / 4;
7573 (element == EL_SP_BUGGY_BASE ?
7574 2 * FRAMES_PER_SECOND + RND(5 * FRAMES_PER_SECOND) - activating_delay :
7575 element == EL_SP_BUGGY_BASE_ACTIVATING ?
7577 element == EL_SP_BUGGY_BASE_ACTIVE ?
7578 1 * FRAMES_PER_SECOND + RND(1 * FRAMES_PER_SECOND) : 1);
7581 static void WarnBuggyBase(int x, int y)
7584 static int xy[4][2] =
7592 for (i = 0; i < NUM_DIRECTIONS; i++)
7594 int xx = x + xy[i][0], yy = y + xy[i][1];
7596 if (IS_PLAYER(xx, yy))
7598 PlayLevelSound(x, y, SND_SP_BUGGY_BASE_ACTIVE);
7605 static void InitTrap(int x, int y)
7607 ChangeDelay[x][y] = 2 * FRAMES_PER_SECOND + RND(5 * FRAMES_PER_SECOND);
7610 static void ActivateTrap(int x, int y)
7612 PlayLevelSound(x, y, SND_TRAP_ACTIVATING);
7615 static void ChangeActiveTrap(int x, int y)
7617 int graphic = IMG_TRAP_ACTIVE;
7619 /* if new animation frame was drawn, correct crumbled sand border */
7620 if (IS_NEW_FRAME(GfxFrame[x][y], graphic))
7621 DrawLevelFieldCrumbledSand(x, y);
7624 static void ChangeElementNowExt(int x, int y, int target_element)
7626 int previous_move_direction = MovDir[x][y];
7628 boolean add_player = (ELEM_IS_PLAYER(target_element) &&
7629 IS_WALKABLE(Feld[x][y]));
7631 boolean add_player = (ELEM_IS_PLAYER(target_element) &&
7632 IS_WALKABLE(Feld[x][y]) &&
7636 /* check if element under player changes from accessible to unaccessible
7637 (needed for special case of dropping element which then changes) */
7638 if (IS_PLAYER(x, y) && !PLAYER_EXPLOSION_PROTECTED(x, y) &&
7639 IS_ACCESSIBLE(Feld[x][y]) && !IS_ACCESSIBLE(target_element))
7642 printf("::: BOOOM! [%d, '%s']\n", target_element,
7643 element_info[target_element].token_name);
7655 if (IS_MOVING(x, y) || IS_BLOCKED(x, y))
7656 RemoveMovingField(x, y);
7660 Feld[x][y] = target_element;
7663 Feld[x][y] = target_element;
7666 ResetGfxAnimation(x, y);
7667 ResetRandomAnimationValue(x, y);
7669 if (element_info[Feld[x][y]].move_direction_initial == MV_START_PREVIOUS)
7670 MovDir[x][y] = previous_move_direction;
7673 InitField_WithBug1(x, y, FALSE);
7675 InitField(x, y, FALSE);
7676 if (CAN_MOVE(Feld[x][y]))
7680 DrawLevelField(x, y);
7682 if (GFX_CRUMBLED(Feld[x][y]))
7683 DrawLevelFieldCrumbledSandNeighbours(x, y);
7687 Changed[x][y] |= ChangeEvent[x][y]; /* ignore same changes in this frame */
7691 TestIfBadThingTouchesHero(x, y);
7692 TestIfPlayerTouchesCustomElement(x, y);
7693 TestIfElementTouchesCustomElement(x, y);
7696 /* "Changed[][]" not set yet to allow "entered by player" change one time */
7697 if (ELEM_IS_PLAYER(target_element))
7698 RelocatePlayer(x, y, target_element);
7701 Changed[x][y] |= ChangeEvent[x][y]; /* ignore same changes in this frame */
7705 TestIfBadThingTouchesHero(x, y);
7706 TestIfPlayerTouchesCustomElement(x, y);
7707 TestIfElementTouchesCustomElement(x, y);
7711 static boolean ChangeElementNow(int x, int y, int element, int page)
7713 struct ElementChangeInfo *change = &element_info[element].change_page[page];
7715 int old_element = Feld[x][y];
7717 /* always use default change event to prevent running into a loop */
7718 if (ChangeEvent[x][y] == CE_BITMASK_DEFAULT)
7719 ChangeEvent[x][y] = CH_EVENT_BIT(CE_DELAY);
7721 if (ChangeEvent[x][y] == CH_EVENT_BIT(CE_DELAY))
7723 /* reset actual trigger element and player */
7724 change->actual_trigger_element = EL_EMPTY;
7725 change->actual_trigger_player = EL_PLAYER_1;
7728 /* do not change already changed elements with same change event */
7730 if (Changed[x][y] & ChangeEvent[x][y])
7737 Changed[x][y] |= ChangeEvent[x][y]; /* ignore same changes in this frame */
7740 /* !!! indirect change before direct change !!! */
7741 CheckTriggeredElementChangeByPage(x,y,Feld[x][y], CE_OTHER_IS_CHANGING,page);
7744 if (change->explode)
7751 if (change->use_target_content)
7753 boolean complete_replace = TRUE;
7754 boolean can_replace[3][3];
7757 for (yy = 0; yy < 3; yy++) for (xx = 0; xx < 3 ; xx++)
7760 boolean is_walkable;
7761 boolean is_diggable;
7762 boolean is_collectible;
7763 boolean is_removable;
7764 boolean is_destructible;
7765 int ex = x + xx - 1;
7766 int ey = y + yy - 1;
7767 int content_element = change->target_content[xx][yy];
7770 can_replace[xx][yy] = TRUE;
7772 if (ex == x && ey == y) /* do not check changing element itself */
7775 if (content_element == EL_EMPTY_SPACE)
7777 can_replace[xx][yy] = FALSE; /* do not replace border with space */
7782 if (!IN_LEV_FIELD(ex, ey))
7784 can_replace[xx][yy] = FALSE;
7785 complete_replace = FALSE;
7791 if (Changed[ex][ey]) /* do not change already changed elements */
7793 can_replace[xx][yy] = FALSE;
7794 complete_replace = FALSE;
7802 if (IS_MOVING(ex, ey) || IS_BLOCKED(ex, ey))
7803 e = MovingOrBlocked2Element(ex, ey);
7808 is_empty = (IS_FREE(ex, ey) ||
7809 (IS_PLAYER(ex, ey) && IS_WALKABLE(content_element)) ||
7810 (IS_WALKABLE(e) && ELEM_IS_PLAYER(content_element) &&
7811 !IS_MOVING(ex, ey) && !IS_BLOCKED(ex, ey)));
7815 is_empty = (IS_FREE(ex, ey) ||
7816 (IS_PLAYER(ex, ey) && IS_WALKABLE(content_element)));
7818 is_empty = (IS_FREE(ex, ey) ||
7819 (IS_FREE_OR_PLAYER(ex, ey) && IS_WALKABLE(content_element)));
7824 is_walkable = (is_empty || IS_WALKABLE(e));
7825 is_diggable = (is_empty || IS_DIGGABLE(e));
7826 is_collectible = (is_empty || IS_COLLECTIBLE(e));
7827 is_destructible = (is_empty || !IS_INDESTRUCTIBLE(e));
7828 is_removable = (is_diggable || is_collectible);
7830 can_replace[xx][yy] =
7831 (((change->replace_when == CP_WHEN_EMPTY && is_empty) ||
7832 (change->replace_when == CP_WHEN_WALKABLE && is_walkable) ||
7833 (change->replace_when == CP_WHEN_DIGGABLE && is_diggable) ||
7834 (change->replace_when == CP_WHEN_COLLECTIBLE && is_collectible) ||
7835 (change->replace_when == CP_WHEN_REMOVABLE && is_removable) ||
7836 (change->replace_when == CP_WHEN_DESTRUCTIBLE && is_destructible)) &&
7837 !(IS_PLAYER(ex, ey) && ELEM_IS_PLAYER(content_element)));
7839 if (!can_replace[xx][yy])
7840 complete_replace = FALSE;
7842 empty_for_element = (IS_FREE(ex, ey) || (IS_FREE_OR_PLAYER(ex, ey) &&
7843 IS_WALKABLE(content_element)));
7845 half_destructible = (empty_for_element || IS_DIGGABLE(e));
7847 half_destructible = (IS_FREE(ex, ey) || IS_DIGGABLE(e));
7850 if ((change->replace_when <= CP_WHEN_EMPTY && !empty_for_element) ||
7851 (change->replace_when <= CP_WHEN_DIGGABLE && !half_destructible) ||
7852 (change->replace_when <= CP_WHEN_DESTRUCTIBLE && IS_INDESTRUCTIBLE(e)))
7854 can_replace[xx][yy] = FALSE;
7855 complete_replace = FALSE;
7860 if (!change->only_if_complete || complete_replace)
7862 boolean something_has_changed = FALSE;
7864 if (change->only_if_complete && change->use_random_replace &&
7865 RND(100) < change->random_percentage)
7868 for (yy = 0; yy < 3; yy++) for (xx = 0; xx < 3 ; xx++)
7870 int ex = x + xx - 1;
7871 int ey = y + yy - 1;
7872 int content_element;
7874 if (can_replace[xx][yy] && (!change->use_random_replace ||
7875 RND(100) < change->random_percentage))
7877 if (IS_MOVING(ex, ey) || IS_BLOCKED(ex, ey))
7878 RemoveMovingField(ex, ey);
7880 ChangeEvent[ex][ey] = ChangeEvent[x][y];
7882 content_element = change->target_content[xx][yy];
7883 target_element = GET_TARGET_ELEMENT(content_element, change);
7885 ChangeElementNowExt(ex, ey, target_element);
7887 something_has_changed = TRUE;
7889 /* for symmetry reasons, freeze newly created border elements */
7890 if (ex != x || ey != y)
7891 Stop[ex][ey] = TRUE; /* no more moving in this frame */
7895 if (something_has_changed)
7896 PlayLevelSoundElementAction(x, y, element, ACTION_CHANGING);
7901 target_element = GET_TARGET_ELEMENT(change->target_element, change);
7903 ChangeElementNowExt(x, y, target_element);
7905 PlayLevelSoundElementAction(x, y, element, ACTION_CHANGING);
7909 /* this uses direct change before indirect change */
7910 CheckTriggeredElementChangeByPage(x,y,old_element,CE_OTHER_IS_CHANGING,page);
7916 static void ChangeElement(int x, int y, int page)
7918 int element = MovingOrBlocked2Element(x, y);
7919 struct ElementInfo *ei = &element_info[element];
7920 struct ElementChangeInfo *change = &ei->change_page[page];
7923 if (!CAN_CHANGE(element) && !CAN_CHANGE(Back[x][y]))
7926 printf("ChangeElement(): %d,%d: element = %d ('%s')\n",
7927 x, y, element, element_info[element].token_name);
7928 printf("ChangeElement(): This should never happen!\n");
7933 /* this can happen with classic bombs on walkable, changing elements */
7934 if (!CAN_CHANGE(element))
7937 if (!CAN_CHANGE(Back[x][y])) /* prevent permanent repetition */
7938 ChangeDelay[x][y] = 0;
7944 if (ChangeDelay[x][y] == 0) /* initialize element change */
7946 ChangeDelay[x][y] = ( change->delay_fixed * change->delay_frames +
7947 RND(change->delay_random * change->delay_frames)) + 1;
7949 ResetGfxAnimation(x, y);
7950 ResetRandomAnimationValue(x, y);
7952 if (change->pre_change_function)
7953 change->pre_change_function(x, y);
7956 ChangeDelay[x][y]--;
7958 if (ChangeDelay[x][y] != 0) /* continue element change */
7960 int graphic = el_act_dir2img(element, GfxAction[x][y], GfxDir[x][y]);
7962 if (IS_ANIMATED(graphic))
7963 DrawLevelGraphicAnimationIfNeeded(x, y, graphic);
7965 if (change->change_function)
7966 change->change_function(x, y);
7968 else /* finish element change */
7970 if (ChangePage[x][y] != -1) /* remember page from delayed change */
7972 page = ChangePage[x][y];
7973 ChangePage[x][y] = -1;
7975 change = &ei->change_page[page];
7979 if (IS_MOVING(x, y) && !change->explode)
7981 if (IS_MOVING(x, y)) /* never change a running system ;-) */
7984 ChangeDelay[x][y] = 1; /* try change after next move step */
7985 ChangePage[x][y] = page; /* remember page to use for change */
7990 if (ChangeElementNow(x, y, element, page))
7992 if (change->post_change_function)
7993 change->post_change_function(x, y);
7998 static boolean CheckTriggeredElementChangeExt(int lx, int ly,
7999 int trigger_element,
8006 int trigger_page_bits = (trigger_page < 0 ? CH_PAGE_ANY : 1 << trigger_page);
8008 if (!(trigger_events[trigger_element] & CH_EVENT_BIT(trigger_event)))
8011 for (i = 0; i < NUM_CUSTOM_ELEMENTS; i++)
8013 int element = EL_CUSTOM_START + i;
8015 boolean change_element = FALSE;
8018 if (!CAN_CHANGE(element) || !HAS_ANY_CHANGE_EVENT(element, trigger_event))
8021 for (j = 0; j < element_info[element].num_change_pages; j++)
8023 struct ElementChangeInfo *change = &element_info[element].change_page[j];
8025 if (change->can_change &&
8026 change->events & CH_EVENT_BIT(trigger_event) &&
8027 change->trigger_side & trigger_side &&
8028 change->trigger_player & trigger_player &&
8029 change->trigger_page & trigger_page_bits &&
8030 IS_EQUAL_OR_IN_GROUP(trigger_element, change->trigger_element))
8033 if (!(change->events & CH_EVENT_BIT(trigger_event)))
8034 printf("::: !!! %d triggers %d: using wrong page %d [event %d]\n",
8035 trigger_element-EL_CUSTOM_START+1, i+1, j, trigger_event);
8038 change_element = TRUE;
8041 change->actual_trigger_element = trigger_element;
8042 change->actual_trigger_player = EL_PLAYER_1 + log_2(trigger_player);
8048 if (!change_element)
8051 for (y = 0; y < lev_fieldy; y++) for (x = 0; x < lev_fieldx; x++)
8054 if (x == lx && y == ly) /* do not change trigger element itself */
8058 if (Feld[x][y] == element)
8060 ChangeDelay[x][y] = 1;
8061 ChangeEvent[x][y] = CH_EVENT_BIT(trigger_event);
8062 ChangeElement(x, y, page);
8070 static boolean CheckElementChangeExt(int x, int y,
8072 int trigger_element,
8078 if (!CAN_CHANGE(element) || !HAS_ANY_CHANGE_EVENT(element, trigger_event))
8081 if (Feld[x][y] == EL_BLOCKED)
8083 Blocked2Moving(x, y, &x, &y);
8084 element = Feld[x][y];
8088 if (Feld[x][y] != element) /* check if element has already changed */
8091 printf("::: %d ('%s') != %d ('%s') [%d]\n",
8092 Feld[x][y], element_info[Feld[x][y]].token_name,
8093 element, element_info[element].token_name,
8102 if (trigger_page < 0)
8104 boolean change_element = FALSE;
8107 for (i = 0; i < element_info[element].num_change_pages; i++)
8109 struct ElementChangeInfo *change = &element_info[element].change_page[i];
8111 if (change->can_change &&
8112 change->events & CH_EVENT_BIT(trigger_event) &&
8113 change->trigger_side & trigger_side &&
8114 change->trigger_player & trigger_player)
8116 change_element = TRUE;
8119 change->actual_trigger_element = trigger_element;
8120 change->actual_trigger_player = EL_PLAYER_1 + log_2(trigger_player);
8126 if (!change_element)
8131 struct ElementInfo *ei = &element_info[element];
8132 struct ElementChangeInfo *change = &ei->change_page[trigger_page];
8134 change->actual_trigger_element = trigger_element;
8135 change->actual_trigger_player = EL_PLAYER_1; /* unused */
8140 /* !!! this check misses pages with same event, but different side !!! */
8142 if (trigger_page < 0)
8143 trigger_page = element_info[element].event_page_nr[trigger_event];
8145 if (!(element_info[element].change_page[trigger_page].trigger_side & trigger_side))
8149 ChangeDelay[x][y] = 1;
8150 ChangeEvent[x][y] = CH_EVENT_BIT(trigger_event);
8151 ChangeElement(x, y, trigger_page);
8156 static void PlayPlayerSound(struct PlayerInfo *player)
8158 int jx = player->jx, jy = player->jy;
8159 int element = player->element_nr;
8160 int last_action = player->last_action_waiting;
8161 int action = player->action_waiting;
8163 if (player->is_waiting)
8165 if (action != last_action)
8166 PlayLevelSoundElementAction(jx, jy, element, action);
8168 PlayLevelSoundElementActionIfLoop(jx, jy, element, action);
8172 if (action != last_action)
8173 StopSound(element_info[element].sound[last_action]);
8175 if (last_action == ACTION_SLEEPING)
8176 PlayLevelSoundElementAction(jx, jy, element, ACTION_AWAKENING);
8180 static void PlayAllPlayersSound()
8184 for (i = 0; i < MAX_PLAYERS; i++)
8185 if (stored_player[i].active)
8186 PlayPlayerSound(&stored_player[i]);
8189 static void SetPlayerWaiting(struct PlayerInfo *player, boolean is_waiting)
8191 boolean last_waiting = player->is_waiting;
8192 int move_dir = player->MovDir;
8194 player->last_action_waiting = player->action_waiting;
8198 if (!last_waiting) /* not waiting -> waiting */
8200 player->is_waiting = TRUE;
8202 player->frame_counter_bored =
8204 game.player_boring_delay_fixed +
8205 SimpleRND(game.player_boring_delay_random);
8206 player->frame_counter_sleeping =
8208 game.player_sleeping_delay_fixed +
8209 SimpleRND(game.player_sleeping_delay_random);
8211 InitPlayerGfxAnimation(player, ACTION_WAITING, player->MovDir);
8214 if (game.player_sleeping_delay_fixed +
8215 game.player_sleeping_delay_random > 0 &&
8216 player->anim_delay_counter == 0 &&
8217 player->post_delay_counter == 0 &&
8218 FrameCounter >= player->frame_counter_sleeping)
8219 player->is_sleeping = TRUE;
8220 else if (game.player_boring_delay_fixed +
8221 game.player_boring_delay_random > 0 &&
8222 FrameCounter >= player->frame_counter_bored)
8223 player->is_bored = TRUE;
8225 player->action_waiting = (player->is_sleeping ? ACTION_SLEEPING :
8226 player->is_bored ? ACTION_BORING :
8229 if (player->is_sleeping)
8231 if (player->num_special_action_sleeping > 0)
8233 if (player->anim_delay_counter == 0 && player->post_delay_counter == 0)
8235 int last_special_action = player->special_action_sleeping;
8236 int num_special_action = player->num_special_action_sleeping;
8237 int special_action =
8238 (last_special_action == ACTION_DEFAULT ? ACTION_SLEEPING_1 :
8239 last_special_action == ACTION_SLEEPING ? ACTION_SLEEPING :
8240 last_special_action < ACTION_SLEEPING_1 + num_special_action - 1 ?
8241 last_special_action + 1 : ACTION_SLEEPING);
8242 int special_graphic =
8243 el_act_dir2img(player->element_nr, special_action, move_dir);
8245 player->anim_delay_counter =
8246 graphic_info[special_graphic].anim_delay_fixed +
8247 SimpleRND(graphic_info[special_graphic].anim_delay_random);
8248 player->post_delay_counter =
8249 graphic_info[special_graphic].post_delay_fixed +
8250 SimpleRND(graphic_info[special_graphic].post_delay_random);
8252 player->special_action_sleeping = special_action;
8255 if (player->anim_delay_counter > 0)
8257 player->action_waiting = player->special_action_sleeping;
8258 player->anim_delay_counter--;
8260 else if (player->post_delay_counter > 0)
8262 player->post_delay_counter--;
8266 else if (player->is_bored)
8268 if (player->num_special_action_bored > 0)
8270 if (player->anim_delay_counter == 0 && player->post_delay_counter == 0)
8272 int special_action =
8273 ACTION_BORING_1 + SimpleRND(player->num_special_action_bored);
8274 int special_graphic =
8275 el_act_dir2img(player->element_nr, special_action, move_dir);
8277 player->anim_delay_counter =
8278 graphic_info[special_graphic].anim_delay_fixed +
8279 SimpleRND(graphic_info[special_graphic].anim_delay_random);
8280 player->post_delay_counter =
8281 graphic_info[special_graphic].post_delay_fixed +
8282 SimpleRND(graphic_info[special_graphic].post_delay_random);
8284 player->special_action_bored = special_action;
8287 if (player->anim_delay_counter > 0)
8289 player->action_waiting = player->special_action_bored;
8290 player->anim_delay_counter--;
8292 else if (player->post_delay_counter > 0)
8294 player->post_delay_counter--;
8299 else if (last_waiting) /* waiting -> not waiting */
8301 player->is_waiting = FALSE;
8302 player->is_bored = FALSE;
8303 player->is_sleeping = FALSE;
8305 player->frame_counter_bored = -1;
8306 player->frame_counter_sleeping = -1;
8308 player->anim_delay_counter = 0;
8309 player->post_delay_counter = 0;
8311 player->action_waiting = ACTION_DEFAULT;
8313 player->special_action_bored = ACTION_DEFAULT;
8314 player->special_action_sleeping = ACTION_DEFAULT;
8319 static byte PlayerActions(struct PlayerInfo *player, byte player_action)
8322 static byte stored_player_action[MAX_PLAYERS];
8323 static int num_stored_actions = 0;
8325 boolean moved = FALSE, snapped = FALSE, dropped = FALSE;
8326 int left = player_action & JOY_LEFT;
8327 int right = player_action & JOY_RIGHT;
8328 int up = player_action & JOY_UP;
8329 int down = player_action & JOY_DOWN;
8330 int button1 = player_action & JOY_BUTTON_1;
8331 int button2 = player_action & JOY_BUTTON_2;
8332 int dx = (left ? -1 : right ? 1 : 0);
8333 int dy = (up ? -1 : down ? 1 : 0);
8336 stored_player_action[player->index_nr] = 0;
8337 num_stored_actions++;
8341 printf("::: player %d [%d]\n", player->index_nr, FrameCounter);
8344 if (!player->active || tape.pausing)
8348 printf("::: [%d %d %d %d] [%d %d]\n",
8349 left, right, up, down, button1, button2);
8355 printf("::: player %d acts [%d]\n", player->index_nr, FrameCounter);
8360 if (player->MovPos == 0)
8361 CheckGravityMovement(player);
8364 snapped = SnapField(player, dx, dy);
8368 dropped = DropElement(player);
8370 moved = MovePlayer(player, dx, dy);
8373 if (tape.single_step && tape.recording && !tape.pausing)
8375 if (button1 || (dropped && !moved))
8377 TapeTogglePause(TAPE_TOGGLE_AUTOMATIC);
8378 SnapField(player, 0, 0); /* stop snapping */
8382 SetPlayerWaiting(player, FALSE);
8385 return player_action;
8387 stored_player_action[player->index_nr] = player_action;
8393 printf("::: player %d waits [%d]\n", player->index_nr, FrameCounter);
8396 /* no actions for this player (no input at player's configured device) */
8398 DigField(player, 0, 0, 0, 0, 0, 0, DF_NO_PUSH);
8399 SnapField(player, 0, 0);
8400 CheckGravityMovementWhenNotMoving(player);
8402 if (player->MovPos == 0)
8403 SetPlayerWaiting(player, TRUE);
8405 if (player->MovPos == 0) /* needed for tape.playing */
8406 player->is_moving = FALSE;
8408 player->is_dropping = FALSE;
8414 if (tape.recording && num_stored_actions >= MAX_PLAYERS)
8416 printf("::: player %d recorded [%d]\n", player->index_nr, FrameCounter);
8418 TapeRecordAction(stored_player_action);
8419 num_stored_actions = 0;
8426 static void PlayerActions(struct PlayerInfo *player, byte player_action)
8428 static byte stored_player_action[MAX_PLAYERS];
8429 static int num_stored_actions = 0;
8430 boolean moved = FALSE, snapped = FALSE, dropped = FALSE;
8431 int left = player_action & JOY_LEFT;
8432 int right = player_action & JOY_RIGHT;
8433 int up = player_action & JOY_UP;
8434 int down = player_action & JOY_DOWN;
8435 int button1 = player_action & JOY_BUTTON_1;
8436 int button2 = player_action & JOY_BUTTON_2;
8437 int dx = (left ? -1 : right ? 1 : 0);
8438 int dy = (up ? -1 : down ? 1 : 0);
8440 stored_player_action[player->index_nr] = 0;
8441 num_stored_actions++;
8443 printf("::: player %d [%d]\n", player->index_nr, FrameCounter);
8445 if (!player->active || tape.pausing)
8450 printf("::: player %d acts [%d]\n", player->index_nr, FrameCounter);
8453 snapped = SnapField(player, dx, dy);
8457 dropped = DropElement(player);
8459 moved = MovePlayer(player, dx, dy);
8462 if (tape.single_step && tape.recording && !tape.pausing)
8464 if (button1 || (dropped && !moved))
8466 TapeTogglePause(TAPE_TOGGLE_AUTOMATIC);
8467 SnapField(player, 0, 0); /* stop snapping */
8471 stored_player_action[player->index_nr] = player_action;
8475 printf("::: player %d waits [%d]\n", player->index_nr, FrameCounter);
8477 /* no actions for this player (no input at player's configured device) */
8479 DigField(player, 0, 0, 0, 0, 0, 0, DF_NO_PUSH);
8480 SnapField(player, 0, 0);
8481 CheckGravityMovementWhenNotMoving(player);
8483 if (player->MovPos == 0)
8484 InitPlayerGfxAnimation(player, ACTION_DEFAULT, player->MovDir);
8486 if (player->MovPos == 0) /* needed for tape.playing */
8487 player->is_moving = FALSE;
8490 if (tape.recording && num_stored_actions >= MAX_PLAYERS)
8492 printf("::: player %d recorded [%d]\n", player->index_nr, FrameCounter);
8494 TapeRecordAction(stored_player_action);
8495 num_stored_actions = 0;
8500 void AdvanceFrameAndPlayerCounters(int player_nr)
8504 /* advance frame counters (global frame counter and time frame counter) */
8508 /* advance player counters (counters for move delay, move animation etc.) */
8509 for (i = 0; i < MAX_PLAYERS; i++)
8511 boolean advance_player_counters = (player_nr == -1 || player_nr == i);
8513 MOVE_DELAY_NORMAL_SPEED / stored_player[i].move_delay_value;
8515 if (!advance_player_counters) /* not all players may be affected */
8518 stored_player[i].Frame += move_frames;
8520 if (stored_player[i].MovPos != 0)
8521 stored_player[i].StepFrame += move_frames;
8523 #if USE_NEW_MOVE_DELAY
8524 if (stored_player[i].move_delay > 0)
8525 stored_player[i].move_delay--;
8528 #if USE_NEW_PUSH_DELAY
8529 /* due to bugs in previous versions, counter must count up, not down */
8530 if (stored_player[i].push_delay != -1)
8531 stored_player[i].push_delay++;
8534 if (stored_player[i].drop_delay > 0)
8535 stored_player[i].drop_delay--;
8541 static unsigned long game_frame_delay = 0;
8542 unsigned long game_frame_delay_value;
8543 int magic_wall_x = 0, magic_wall_y = 0;
8544 int i, x, y, element, graphic;
8545 byte *recorded_player_action;
8546 byte summarized_player_action = 0;
8548 byte tape_action[MAX_PLAYERS];
8551 if (game_status != GAME_MODE_PLAYING)
8554 game_frame_delay_value =
8555 (tape.playing && tape.fast_forward ? FfwdFrameDelay : GameFrameDelay);
8557 if (tape.playing && tape.warp_forward && !tape.pausing)
8558 game_frame_delay_value = 0;
8560 /* ---------- main game synchronization point ---------- */
8562 WaitUntilDelayReached(&game_frame_delay, game_frame_delay_value);
8564 if (network_playing && !network_player_action_received)
8568 printf("DEBUG: try to get network player actions in time\n");
8572 #if defined(NETWORK_AVALIABLE)
8573 /* last chance to get network player actions without main loop delay */
8577 if (game_status != GAME_MODE_PLAYING)
8580 if (!network_player_action_received)
8584 printf("DEBUG: failed to get network player actions in time\n");
8595 printf("::: getting new tape action [%d]\n", FrameCounter);
8598 recorded_player_action = (tape.playing ? TapePlayAction() : NULL);
8601 /* !!! CHECK THIS (tape.pausing is always FALSE here!) !!! */
8602 if (recorded_player_action == NULL && tape.pausing)
8607 printf("::: %d\n", stored_player[0].action);
8611 if (recorded_player_action != NULL)
8612 for (i = 0; i < MAX_PLAYERS; i++)
8613 stored_player[i].action = recorded_player_action[i];
8616 for (i = 0; i < MAX_PLAYERS; i++)
8618 summarized_player_action |= stored_player[i].action;
8620 if (!network_playing)
8621 stored_player[i].effective_action = stored_player[i].action;
8624 #if defined(NETWORK_AVALIABLE)
8625 if (network_playing)
8626 SendToServer_MovePlayer(summarized_player_action);
8629 if (!options.network && !setup.team_mode)
8630 local_player->effective_action = summarized_player_action;
8633 if (recorded_player_action != NULL)
8634 for (i = 0; i < MAX_PLAYERS; i++)
8635 stored_player[i].effective_action = recorded_player_action[i];
8639 for (i = 0; i < MAX_PLAYERS; i++)
8641 tape_action[i] = stored_player[i].effective_action;
8643 if (tape.recording && tape_action[i] && !tape.player_participates[i])
8644 tape.player_participates[i] = TRUE; /* player just appeared from CE */
8647 /* only save actions from input devices, but not programmed actions */
8649 TapeRecordAction(tape_action);
8652 for (i = 0; i < MAX_PLAYERS; i++)
8654 int actual_player_action = stored_player[i].effective_action;
8657 /* !!! THIS BREAKS THE FOLLOWING TAPES: !!!
8658 - rnd_equinox_tetrachloride 048
8659 - rnd_equinox_tetrachloride_ii 096
8660 - rnd_emanuel_schmieg 002
8661 - doctor_sloan_ww 001, 020
8663 if (stored_player[i].MovPos == 0)
8664 CheckGravityMovement(&stored_player[i]);
8668 /* overwrite programmed action with tape action */
8669 if (stored_player[i].programmed_action)
8670 actual_player_action = stored_player[i].programmed_action;
8674 if (stored_player[i].programmed_action)
8675 printf("::: %d\n", stored_player[i].programmed_action);
8678 if (recorded_player_action)
8681 if (stored_player[i].programmed_action &&
8682 stored_player[i].programmed_action != recorded_player_action[i])
8683 printf("::: %d: %d <-> %d\n", i,
8684 stored_player[i].programmed_action, recorded_player_action[i]);
8688 actual_player_action = recorded_player_action[i];
8693 /* overwrite tape action with programmed action */
8694 if (stored_player[i].programmed_action)
8695 actual_player_action = stored_player[i].programmed_action;
8700 printf("::: action: %d: %x [%d]\n",
8701 stored_player[i].MovPos, actual_player_action, FrameCounter);
8705 PlayerActions(&stored_player[i], actual_player_action);
8707 tape_action[i] = PlayerActions(&stored_player[i], actual_player_action);
8709 if (tape.recording && tape_action[i] && !tape.player_participates[i])
8710 tape.player_participates[i] = TRUE; /* player just appeared from CE */
8713 ScrollPlayer(&stored_player[i], SCROLL_GO_ON);
8718 TapeRecordAction(tape_action);
8721 network_player_action_received = FALSE;
8723 ScrollScreen(NULL, SCROLL_GO_ON);
8729 for (i = 0; i < MAX_PLAYERS; i++)
8730 stored_player[i].Frame++;
8734 /* for backwards compatibility, the following code emulates a fixed bug that
8735 occured when pushing elements (causing elements that just made their last
8736 pushing step to already (if possible) make their first falling step in the
8737 same game frame, which is bad); this code is also needed to use the famous
8738 "spring push bug" which is used in older levels and might be wanted to be
8739 used also in newer levels, but in this case the buggy pushing code is only
8740 affecting the "spring" element and no other elements */
8743 if (game.engine_version < VERSION_IDENT(2,2,0,7) || level.use_spring_bug)
8745 if (game.engine_version < VERSION_IDENT(2,2,0,7))
8748 for (i = 0; i < MAX_PLAYERS; i++)
8750 struct PlayerInfo *player = &stored_player[i];
8755 if (player->active && player->is_pushing && player->is_moving &&
8757 (game.engine_version < VERSION_IDENT(2,2,0,7) ||
8758 Feld[x][y] == EL_SPRING))
8760 if (player->active && player->is_pushing && player->is_moving &&
8764 ContinueMoving(x, y);
8766 /* continue moving after pushing (this is actually a bug) */
8767 if (!IS_MOVING(x, y))
8776 for (y = 0; y < lev_fieldy; y++) for (x = 0; x < lev_fieldx; x++)
8778 Changed[x][y] = CE_BITMASK_DEFAULT;
8779 ChangeEvent[x][y] = CE_BITMASK_DEFAULT;
8781 #if USE_NEW_BLOCK_STYLE
8782 /* this must be handled before main playfield loop */
8783 if (Feld[x][y] == EL_PLAYER_IS_LEAVING)
8786 if (MovDelay[x][y] <= 0)
8792 if (ChangePage[x][y] != -1 && ChangeDelay[x][y] != 1)
8794 printf("GameActions(): x = %d, y = %d: ChangePage != -1\n", x, y);
8795 printf("GameActions(): This should never happen!\n");
8797 ChangePage[x][y] = -1;
8802 if (WasJustMoving[x][y] > 0)
8803 WasJustMoving[x][y]--;
8804 if (WasJustFalling[x][y] > 0)
8805 WasJustFalling[x][y]--;
8806 if (CheckCollision[x][y] > 0)
8807 CheckCollision[x][y]--;
8812 /* reset finished pushing action (not done in ContinueMoving() to allow
8813 continous pushing animation for elements with zero push delay) */
8814 if (GfxAction[x][y] == ACTION_PUSHING && !IS_MOVING(x, y))
8816 ResetGfxAnimation(x, y);
8817 DrawLevelField(x, y);
8822 if (IS_BLOCKED(x, y))
8826 Blocked2Moving(x, y, &oldx, &oldy);
8827 if (!IS_MOVING(oldx, oldy))
8829 printf("GameActions(): (BLOCKED => MOVING) context corrupted!\n");
8830 printf("GameActions(): BLOCKED: x = %d, y = %d\n", x, y);
8831 printf("GameActions(): !MOVING: oldx = %d, oldy = %d\n", oldx, oldy);
8832 printf("GameActions(): This should never happen!\n");
8838 for (y = 0; y < lev_fieldy; y++) for (x = 0; x < lev_fieldx; x++)
8840 element = Feld[x][y];
8842 graphic = el_act_dir2img(element, GfxAction[x][y], GfxDir[x][y]);
8844 graphic = el2img(element);
8850 printf("::: %d,%d: %d [%d]\n", x, y, element, FrameCounter);
8852 element = graphic = 0;
8856 if (graphic_info[graphic].anim_global_sync)
8857 GfxFrame[x][y] = FrameCounter;
8859 if (ANIM_MODE(graphic) == ANIM_RANDOM &&
8860 IS_NEXT_FRAME(GfxFrame[x][y], graphic))
8861 ResetRandomAnimationValue(x, y);
8863 SetRandomAnimationValue(x, y);
8866 PlayLevelSoundActionIfLoop(x, y, GfxAction[x][y]);
8869 if (IS_INACTIVE(element))
8871 if (IS_ANIMATED(graphic))
8872 DrawLevelGraphicAnimationIfNeeded(x, y, graphic);
8878 /* this may take place after moving, so 'element' may have changed */
8880 if (IS_CHANGING(x, y))
8882 if (IS_CHANGING(x, y) &&
8883 (game.engine_version < VERSION_IDENT(3,0,7,1) || !Stop[x][y]))
8887 ChangeElement(x, y, ChangePage[x][y] != -1 ? ChangePage[x][y] :
8888 element_info[element].event_page_nr[CE_DELAY]);
8890 ChangeElement(x, y, element_info[element].event_page_nr[CE_DELAY]);
8893 element = Feld[x][y];
8894 graphic = el_act_dir2img(element, GfxAction[x][y], GfxDir[x][y]);
8898 if (!IS_MOVING(x, y) && (CAN_FALL(element) || CAN_MOVE(element)))
8903 element = Feld[x][y];
8904 graphic = el_act_dir2img(element, GfxAction[x][y], GfxDir[x][y]);
8906 if (element == EL_MOLE)
8907 printf("::: %d, %d, %d [%d]\n",
8908 IS_ANIMATED(graphic), IS_MOVING(x, y), Stop[x][y],
8912 if (element == EL_YAMYAM)
8913 printf("::: %d, %d, %d\n",
8914 IS_ANIMATED(graphic), IS_MOVING(x, y), Stop[x][y]);
8918 if (IS_ANIMATED(graphic) &&
8922 DrawLevelGraphicAnimationIfNeeded(x, y, graphic);
8925 if (element == EL_BUG)
8926 printf("::: %d, %d\n", graphic, GfxFrame[x][y]);
8930 if (element == EL_MOLE)
8931 printf("::: %d, %d\n", graphic, GfxFrame[x][y]);
8935 if (IS_GEM(element) || element == EL_SP_INFOTRON)
8936 EdelsteinFunkeln(x, y);
8938 else if ((element == EL_ACID ||
8939 element == EL_EXIT_OPEN ||
8940 element == EL_SP_EXIT_OPEN ||
8941 element == EL_SP_TERMINAL ||
8942 element == EL_SP_TERMINAL_ACTIVE ||
8943 element == EL_EXTRA_TIME ||
8944 element == EL_SHIELD_NORMAL ||
8945 element == EL_SHIELD_DEADLY) &&
8946 IS_ANIMATED(graphic))
8947 DrawLevelGraphicAnimationIfNeeded(x, y, graphic);
8948 else if (IS_MOVING(x, y))
8949 ContinueMoving(x, y);
8950 else if (IS_ACTIVE_BOMB(element))
8951 CheckDynamite(x, y);
8953 else if (element == EL_EXPLOSION && !game.explosions_delayed)
8954 Explode(x, y, ExplodePhase[x][y], EX_TYPE_NORMAL);
8956 else if (element == EL_AMOEBA_GROWING)
8957 AmoebeWaechst(x, y);
8958 else if (element == EL_AMOEBA_SHRINKING)
8959 AmoebaDisappearing(x, y);
8961 #if !USE_NEW_AMOEBA_CODE
8962 else if (IS_AMOEBALIVE(element))
8963 AmoebeAbleger(x, y);
8966 else if (element == EL_GAME_OF_LIFE || element == EL_BIOMAZE)
8968 else if (element == EL_EXIT_CLOSED)
8970 else if (element == EL_SP_EXIT_CLOSED)
8972 else if (element == EL_EXPANDABLE_WALL_GROWING)
8974 else if (element == EL_EXPANDABLE_WALL ||
8975 element == EL_EXPANDABLE_WALL_HORIZONTAL ||
8976 element == EL_EXPANDABLE_WALL_VERTICAL ||
8977 element == EL_EXPANDABLE_WALL_ANY)
8979 else if (element == EL_FLAMES)
8980 CheckForDragon(x, y);
8982 else if (IS_AUTO_CHANGING(element))
8983 ChangeElement(x, y);
8985 else if (element == EL_EXPLOSION)
8986 ; /* drawing of correct explosion animation is handled separately */
8987 else if (IS_ANIMATED(graphic) && !IS_CHANGING(x, y))
8988 DrawLevelGraphicAnimationIfNeeded(x, y, graphic);
8991 /* this may take place after moving, so 'element' may have changed */
8992 if (IS_AUTO_CHANGING(Feld[x][y]))
8993 ChangeElement(x, y);
8996 if (IS_BELT_ACTIVE(element))
8997 PlayLevelSoundAction(x, y, ACTION_ACTIVE);
8999 if (game.magic_wall_active)
9001 int jx = local_player->jx, jy = local_player->jy;
9003 /* play the element sound at the position nearest to the player */
9004 if ((element == EL_MAGIC_WALL_FULL ||
9005 element == EL_MAGIC_WALL_ACTIVE ||
9006 element == EL_MAGIC_WALL_EMPTYING ||
9007 element == EL_BD_MAGIC_WALL_FULL ||
9008 element == EL_BD_MAGIC_WALL_ACTIVE ||
9009 element == EL_BD_MAGIC_WALL_EMPTYING) &&
9010 ABS(x-jx) + ABS(y-jy) < ABS(magic_wall_x-jx) + ABS(magic_wall_y-jy))
9018 #if USE_NEW_AMOEBA_CODE
9019 /* new experimental amoeba growth stuff */
9021 if (!(FrameCounter % 8))
9024 static unsigned long random = 1684108901;
9026 for (i = 0; i < level.amoeba_speed * 28 / 8; i++)
9029 x = (random >> 10) % lev_fieldx;
9030 y = (random >> 20) % lev_fieldy;
9032 x = RND(lev_fieldx);
9033 y = RND(lev_fieldy);
9035 element = Feld[x][y];
9038 if (!IS_PLAYER(x,y) &&
9039 (element == EL_EMPTY ||
9040 CAN_GROW_INTO(element) ||
9041 element == EL_QUICKSAND_EMPTY ||
9042 element == EL_ACID_SPLASH_LEFT ||
9043 element == EL_ACID_SPLASH_RIGHT))
9045 if ((IN_LEV_FIELD(x, y-1) && Feld[x][y-1] == EL_AMOEBA_WET) ||
9046 (IN_LEV_FIELD(x-1, y) && Feld[x-1][y] == EL_AMOEBA_WET) ||
9047 (IN_LEV_FIELD(x+1, y) && Feld[x+1][y] == EL_AMOEBA_WET) ||
9048 (IN_LEV_FIELD(x, y+1) && Feld[x][y+1] == EL_AMOEBA_WET))
9049 Feld[x][y] = EL_AMOEBA_DROP;
9052 /* !!! extend EL_SAND to anything diggable (but maybe not SP_BASE) !!! */
9053 if (!IS_PLAYER(x,y) &&
9054 (element == EL_EMPTY ||
9055 element == EL_SAND ||
9056 element == EL_QUICKSAND_EMPTY ||
9057 element == EL_ACID_SPLASH_LEFT ||
9058 element == EL_ACID_SPLASH_RIGHT))
9060 if ((IN_LEV_FIELD(x, y-1) && Feld[x][y-1] == EL_AMOEBA_WET) ||
9061 (IN_LEV_FIELD(x-1, y) && Feld[x-1][y] == EL_AMOEBA_WET) ||
9062 (IN_LEV_FIELD(x+1, y) && Feld[x+1][y] == EL_AMOEBA_WET) ||
9063 (IN_LEV_FIELD(x, y+1) && Feld[x][y+1] == EL_AMOEBA_WET))
9064 Feld[x][y] = EL_AMOEBA_DROP;
9068 random = random * 129 + 1;
9074 if (game.explosions_delayed)
9077 game.explosions_delayed = FALSE;
9079 for (y = 0; y < lev_fieldy; y++) for (x = 0; x < lev_fieldx; x++)
9081 element = Feld[x][y];
9083 if (ExplodeField[x][y])
9084 Explode(x, y, EX_PHASE_START, ExplodeField[x][y]);
9085 else if (element == EL_EXPLOSION)
9086 Explode(x, y, ExplodePhase[x][y], EX_TYPE_NORMAL);
9088 ExplodeField[x][y] = EX_TYPE_NONE;
9091 game.explosions_delayed = TRUE;
9094 if (game.magic_wall_active)
9096 if (!(game.magic_wall_time_left % 4))
9098 int element = Feld[magic_wall_x][magic_wall_y];
9100 if (element == EL_BD_MAGIC_WALL_FULL ||
9101 element == EL_BD_MAGIC_WALL_ACTIVE ||
9102 element == EL_BD_MAGIC_WALL_EMPTYING)
9103 PlayLevelSound(magic_wall_x, magic_wall_y, SND_BD_MAGIC_WALL_ACTIVE);
9105 PlayLevelSound(magic_wall_x, magic_wall_y, SND_MAGIC_WALL_ACTIVE);
9108 if (game.magic_wall_time_left > 0)
9110 game.magic_wall_time_left--;
9111 if (!game.magic_wall_time_left)
9113 for (y = 0; y < lev_fieldy; y++) for (x = 0; x < lev_fieldx; x++)
9115 element = Feld[x][y];
9117 if (element == EL_MAGIC_WALL_ACTIVE ||
9118 element == EL_MAGIC_WALL_FULL)
9120 Feld[x][y] = EL_MAGIC_WALL_DEAD;
9121 DrawLevelField(x, y);
9123 else if (element == EL_BD_MAGIC_WALL_ACTIVE ||
9124 element == EL_BD_MAGIC_WALL_FULL)
9126 Feld[x][y] = EL_BD_MAGIC_WALL_DEAD;
9127 DrawLevelField(x, y);
9131 game.magic_wall_active = FALSE;
9136 if (game.light_time_left > 0)
9138 game.light_time_left--;
9140 if (game.light_time_left == 0)
9141 RedrawAllLightSwitchesAndInvisibleElements();
9144 if (game.timegate_time_left > 0)
9146 game.timegate_time_left--;
9148 if (game.timegate_time_left == 0)
9149 CloseAllOpenTimegates();
9152 for (i = 0; i < MAX_PLAYERS; i++)
9154 struct PlayerInfo *player = &stored_player[i];
9156 if (SHIELD_ON(player))
9158 if (player->shield_deadly_time_left)
9159 PlayLevelSound(player->jx, player->jy, SND_SHIELD_DEADLY_ACTIVE);
9160 else if (player->shield_normal_time_left)
9161 PlayLevelSound(player->jx, player->jy, SND_SHIELD_NORMAL_ACTIVE);
9165 if (TimeFrames >= FRAMES_PER_SECOND)
9170 for (i = 0; i < MAX_PLAYERS; i++)
9172 struct PlayerInfo *player = &stored_player[i];
9174 if (SHIELD_ON(player))
9176 player->shield_normal_time_left--;
9178 if (player->shield_deadly_time_left > 0)
9179 player->shield_deadly_time_left--;
9183 if (!level.use_step_counter)
9191 if (TimeLeft <= 10 && setup.time_limit)
9192 PlaySoundStereo(SND_GAME_RUNNING_OUT_OF_TIME, SOUND_MIDDLE);
9194 DrawGameValue_Time(TimeLeft);
9196 if (!TimeLeft && setup.time_limit)
9197 for (i = 0; i < MAX_PLAYERS; i++)
9198 KillHero(&stored_player[i]);
9200 else if (level.time == 0 && !AllPlayersGone) /* level w/o time limit */
9201 DrawGameValue_Time(TimePlayed);
9204 if (tape.recording || tape.playing)
9205 DrawVideoDisplay(VIDEO_STATE_TIME_ON, TapeTime);
9209 PlayAllPlayersSound();
9211 if (options.debug) /* calculate frames per second */
9213 static unsigned long fps_counter = 0;
9214 static int fps_frames = 0;
9215 unsigned long fps_delay_ms = Counter() - fps_counter;
9219 if (fps_delay_ms >= 500) /* calculate fps every 0.5 seconds */
9221 global.frames_per_second = 1000 * (float)fps_frames / fps_delay_ms;
9224 fps_counter = Counter();
9227 redraw_mask |= REDRAW_FPS;
9231 if (stored_player[0].jx != stored_player[0].last_jx ||
9232 stored_player[0].jy != stored_player[0].last_jy)
9233 printf("::: %d, %d, %d, %d, %d\n",
9234 stored_player[0].MovDir,
9235 stored_player[0].MovPos,
9236 stored_player[0].GfxPos,
9237 stored_player[0].Frame,
9238 stored_player[0].StepFrame);
9241 #if USE_NEW_MOVE_DELAY
9242 AdvanceFrameAndPlayerCounters(-1); /* advance counters for all players */
9247 for (i = 0; i < MAX_PLAYERS; i++)
9250 MOVE_DELAY_NORMAL_SPEED / stored_player[i].move_delay_value;
9252 stored_player[i].Frame += move_frames;
9254 if (stored_player[i].MovPos != 0)
9255 stored_player[i].StepFrame += move_frames;
9257 #if USE_NEW_MOVE_DELAY
9258 if (stored_player[i].move_delay > 0)
9259 stored_player[i].move_delay--;
9262 if (stored_player[i].drop_delay > 0)
9263 stored_player[i].drop_delay--;
9268 if (local_player->show_envelope != 0 && local_player->MovPos == 0)
9270 ShowEnvelope(local_player->show_envelope - EL_ENVELOPE_1);
9272 local_player->show_envelope = 0;
9276 #if USE_NEW_RANDOMIZE
9277 /* use random number generator in every frame to make it less predictable */
9278 if (game.engine_version >= VERSION_IDENT(3,1,1,0))
9283 static boolean AllPlayersInSight(struct PlayerInfo *player, int x, int y)
9285 int min_x = x, min_y = y, max_x = x, max_y = y;
9288 for (i = 0; i < MAX_PLAYERS; i++)
9290 int jx = stored_player[i].jx, jy = stored_player[i].jy;
9292 if (!stored_player[i].active || &stored_player[i] == player)
9295 min_x = MIN(min_x, jx);
9296 min_y = MIN(min_y, jy);
9297 max_x = MAX(max_x, jx);
9298 max_y = MAX(max_y, jy);
9301 return (max_x - min_x < SCR_FIELDX && max_y - min_y < SCR_FIELDY);
9304 static boolean AllPlayersInVisibleScreen()
9308 for (i = 0; i < MAX_PLAYERS; i++)
9310 int jx = stored_player[i].jx, jy = stored_player[i].jy;
9312 if (!stored_player[i].active)
9315 if (!IN_VIS_FIELD(SCREENX(jx), SCREENY(jy)))
9322 void ScrollLevel(int dx, int dy)
9324 int softscroll_offset = (setup.soft_scrolling ? TILEX : 0);
9327 BlitBitmap(drawto_field, drawto_field,
9328 FX + TILEX * (dx == -1) - softscroll_offset,
9329 FY + TILEY * (dy == -1) - softscroll_offset,
9330 SXSIZE - TILEX * (dx!=0) + 2 * softscroll_offset,
9331 SYSIZE - TILEY * (dy!=0) + 2 * softscroll_offset,
9332 FX + TILEX * (dx == 1) - softscroll_offset,
9333 FY + TILEY * (dy == 1) - softscroll_offset);
9337 x = (dx == 1 ? BX1 : BX2);
9338 for (y = BY1; y <= BY2; y++)
9339 DrawScreenField(x, y);
9344 y = (dy == 1 ? BY1 : BY2);
9345 for (x = BX1; x <= BX2; x++)
9346 DrawScreenField(x, y);
9349 redraw_mask |= REDRAW_FIELD;
9353 static boolean canEnterSupaplexPort(int x, int y, int dx, int dy)
9355 int nextx = x + dx, nexty = y + dy;
9356 int element = Feld[x][y];
9359 element != EL_SP_PORT_LEFT &&
9360 element != EL_SP_GRAVITY_PORT_LEFT &&
9361 element != EL_SP_PORT_HORIZONTAL &&
9362 element != EL_SP_PORT_ANY) ||
9364 element != EL_SP_PORT_RIGHT &&
9365 element != EL_SP_GRAVITY_PORT_RIGHT &&
9366 element != EL_SP_PORT_HORIZONTAL &&
9367 element != EL_SP_PORT_ANY) ||
9369 element != EL_SP_PORT_UP &&
9370 element != EL_SP_GRAVITY_PORT_UP &&
9371 element != EL_SP_PORT_VERTICAL &&
9372 element != EL_SP_PORT_ANY) ||
9374 element != EL_SP_PORT_DOWN &&
9375 element != EL_SP_GRAVITY_PORT_DOWN &&
9376 element != EL_SP_PORT_VERTICAL &&
9377 element != EL_SP_PORT_ANY) ||
9378 !IN_LEV_FIELD(nextx, nexty) ||
9379 !IS_FREE(nextx, nexty))
9386 static boolean canFallDown(struct PlayerInfo *player)
9388 int jx = player->jx, jy = player->jy;
9390 return (IN_LEV_FIELD(jx, jy + 1) &&
9391 (IS_FREE(jx, jy + 1) ||
9392 (Feld[jx][jy + 1] == EL_ACID && player->can_fall_into_acid)) &&
9393 IS_WALKABLE_FROM(Feld[jx][jy], MV_DOWN) &&
9394 !IS_WALKABLE_INSIDE(Feld[jx][jy]));
9397 static boolean canPassField(int x, int y, int move_dir)
9399 int opposite_dir = MV_DIR_OPPOSITE(move_dir);
9400 int dx = (move_dir & MV_LEFT ? -1 : move_dir & MV_RIGHT ? +1 : 0);
9401 int dy = (move_dir & MV_UP ? -1 : move_dir & MV_DOWN ? +1 : 0);
9404 int element = Feld[x][y];
9406 return (IS_PASSABLE_FROM(element, opposite_dir) &&
9407 !CAN_MOVE(element) &&
9408 IN_LEV_FIELD(nextx, nexty) && !IS_PLAYER(nextx, nexty) &&
9409 IS_WALKABLE_FROM(Feld[nextx][nexty], move_dir) &&
9410 (level.can_pass_to_walkable || IS_FREE(nextx, nexty)));
9413 static boolean canMoveToValidFieldWithGravity(int x, int y, int move_dir)
9415 int opposite_dir = MV_DIR_OPPOSITE(move_dir);
9416 int dx = (move_dir & MV_LEFT ? -1 : move_dir & MV_RIGHT ? +1 : 0);
9417 int dy = (move_dir & MV_UP ? -1 : move_dir & MV_DOWN ? +1 : 0);
9421 int nextx = newx + dx;
9422 int nexty = newy + dy;
9426 return (IN_LEV_FIELD(newx, newy) && !IS_FREE_OR_PLAYER(newx, newy) &&
9427 IS_GRAVITY_REACHABLE(Feld[newx][newy]) &&
9429 (!IS_SP_PORT(Feld[newx][newy]) || move_dir == MV_UP) &&
9431 (IS_DIGGABLE(Feld[newx][newy]) ||
9432 IS_WALKABLE_FROM(Feld[newx][newy], opposite_dir) ||
9433 canPassField(newx, newy, move_dir)));
9436 return (IN_LEV_FIELD(newx, newy) && !IS_FREE_OR_PLAYER(newx, newy) &&
9437 IS_GRAVITY_REACHABLE(Feld[newx][newy]) &&
9438 (IS_DIGGABLE(Feld[newx][newy]) ||
9439 IS_WALKABLE_FROM(Feld[newx][newy], opposite_dir) ||
9440 canPassField(newx, newy, move_dir)));
9443 return (IN_LEV_FIELD(newx, newy) && !IS_FREE_OR_PLAYER(newx, newy) &&
9444 (IS_DIGGABLE_WITH_GRAVITY(Feld[newx][newy]) ||
9445 IS_WALKABLE_FROM(Feld[newx][newy], opposite_dir) ||
9446 canPassField(newx, newy, move_dir)));
9448 return (IN_LEV_FIELD(newx, newy) && !IS_FREE_OR_PLAYER(newx, newy) &&
9449 (IS_DIGGABLE(Feld[newx][newy]) ||
9450 IS_WALKABLE_FROM(Feld[newx][newy], opposite_dir) ||
9451 (IS_PASSABLE_FROM(Feld[newx][newy], opposite_dir) &&
9452 !CAN_MOVE(Feld[newx][newy]) &&
9453 IN_LEV_FIELD(nextx, nexty) && !IS_PLAYER(nextx, nexty) &&
9454 IS_WALKABLE_FROM(Feld[nextx][nexty], move_dir) &&
9455 (level.can_pass_to_walkable || IS_FREE(nextx, nexty)))));
9461 static void CheckGravityMovement(struct PlayerInfo *player)
9463 if (game.gravity && !player->programmed_action)
9466 int move_dir_horizontal = player->effective_action & MV_HORIZONTAL;
9467 int move_dir_vertical = player->effective_action & MV_VERTICAL;
9469 int move_dir_horizontal = player->action & MV_HORIZONTAL;
9470 int move_dir_vertical = player->action & MV_VERTICAL;
9474 boolean player_is_snapping = player->effective_action & JOY_BUTTON_1;
9476 boolean player_is_snapping = player->action & JOY_BUTTON_1;
9479 int jx = player->jx, jy = player->jy;
9481 boolean player_is_moving_to_valid_field =
9482 (!player_is_snapping &&
9483 (canMoveToValidFieldWithGravity(jx, jy, move_dir_horizontal) ||
9484 canMoveToValidFieldWithGravity(jx, jy, move_dir_vertical)));
9488 (player->last_move_dir & MV_HORIZONTAL ?
9489 (move_dir_vertical ? move_dir_vertical : move_dir_horizontal) :
9490 (move_dir_horizontal ? move_dir_horizontal : move_dir_vertical));
9494 int opposite_dir = MV_DIR_OPPOSITE(move_dir);
9495 int dx = (move_dir & MV_LEFT ? -1 : move_dir & MV_RIGHT ? +1 : 0);
9496 int dy = (move_dir & MV_UP ? -1 : move_dir & MV_DOWN ? +1 : 0);
9497 int new_jx = jx + dx, new_jy = jy + dy;
9498 int nextx = new_jx + dx, nexty = new_jy + dy;
9504 boolean player_can_fall_down = canFallDown(player);
9506 boolean player_can_fall_down =
9507 (IN_LEV_FIELD(jx, jy + 1) &&
9508 (IS_FREE(jx, jy + 1) ||
9509 (Feld[jx][jy + 1] == EL_ACID && player->can_fall_into_acid)));
9513 boolean player_can_fall_down =
9514 (IN_LEV_FIELD(jx, jy + 1) &&
9515 (IS_FREE(jx, jy + 1)));
9519 boolean player_is_moving_to_valid_field =
9522 !player_is_snapping &&
9526 IN_LEV_FIELD(new_jx, new_jy) &&
9527 (IS_DIGGABLE(Feld[new_jx][new_jy]) ||
9528 (IS_SP_PORT(Feld[new_jx][new_jy]) &&
9529 element_info[Feld[new_jx][new_jy]].access_direction & opposite_dir &&
9530 IN_LEV_FIELD(nextx, nexty) &&
9531 element_info[Feld[nextx][nexty]].access_direction & move_dir))
9533 IN_LEV_FIELD(new_jx, new_jy) &&
9534 (Feld[new_jx][new_jy] == EL_SP_BASE ||
9535 Feld[new_jx][new_jy] == EL_SAND ||
9536 (IS_SP_PORT(Feld[new_jx][new_jy]) &&
9537 canEnterSupaplexPort(new_jx, new_jy, dx, dy)))
9538 /* !!! extend EL_SAND to anything diggable !!! */
9544 boolean player_is_standing_on_valid_field =
9545 (IS_WALKABLE_INSIDE(Feld[jx][jy]) ||
9546 (IS_WALKABLE(Feld[jx][jy]) && !ACCESS_FROM(Feld[jx][jy], MV_DOWN)));
9550 printf("::: checking gravity NOW [%d, %d, %d] [%d] [%d / %d] ...\n",
9551 player_can_fall_down,
9552 player_is_standing_on_valid_field,
9553 player_is_moving_to_valid_field,
9554 (player_is_moving_to_valid_field ? Feld[new_jx][new_jy] : -1),
9555 player->effective_action,
9556 player->can_fall_into_acid);
9559 if (player_can_fall_down &&
9561 !player_is_standing_on_valid_field &&
9563 !player_is_moving_to_valid_field)
9566 printf("::: setting programmed_action to MV_DOWN [%d,%d - %d] ...\n",
9567 jx, jy, FrameCounter);
9570 player->programmed_action = MV_DOWN;
9575 static void CheckGravityMovementWhenNotMoving(struct PlayerInfo *player)
9578 return CheckGravityMovement(player);
9581 if (game.gravity && !player->programmed_action)
9583 int jx = player->jx, jy = player->jy;
9584 boolean field_under_player_is_free =
9585 (IN_LEV_FIELD(jx, jy + 1) && IS_FREE(jx, jy + 1));
9586 boolean player_is_standing_on_valid_field =
9587 (IS_WALKABLE_INSIDE(Feld[jx][jy]) ||
9588 (IS_WALKABLE(Feld[jx][jy]) &&
9589 !(element_info[Feld[jx][jy]].access_direction & MV_DOWN)));
9591 if (field_under_player_is_free && !player_is_standing_on_valid_field)
9592 player->programmed_action = MV_DOWN;
9598 -----------------------------------------------------------------------------
9599 dx, dy: direction (non-diagonal) to try to move the player to
9600 real_dx, real_dy: direction as read from input device (can be diagonal)
9603 boolean MovePlayerOneStep(struct PlayerInfo *player,
9604 int dx, int dy, int real_dx, int real_dy)
9607 static int trigger_sides[4][2] =
9609 /* enter side leave side */
9610 { CH_SIDE_RIGHT, CH_SIDE_LEFT }, /* moving left */
9611 { CH_SIDE_LEFT, CH_SIDE_RIGHT }, /* moving right */
9612 { CH_SIDE_BOTTOM, CH_SIDE_TOP }, /* moving up */
9613 { CH_SIDE_TOP, CH_SIDE_BOTTOM } /* moving down */
9615 int move_direction = (dx == -1 ? MV_LEFT :
9616 dx == +1 ? MV_RIGHT :
9618 dy == +1 ? MV_DOWN : MV_NO_MOVING);
9619 int enter_side = trigger_sides[MV_DIR_BIT(move_direction)][0];
9620 int leave_side = trigger_sides[MV_DIR_BIT(move_direction)][1];
9622 int jx = player->jx, jy = player->jy;
9623 int new_jx = jx + dx, new_jy = jy + dy;
9627 if (!player->active || (!dx && !dy))
9628 return MF_NO_ACTION;
9630 player->MovDir = (dx < 0 ? MV_LEFT :
9633 dy > 0 ? MV_DOWN : MV_NO_MOVING);
9635 if (!IN_LEV_FIELD(new_jx, new_jy))
9636 return MF_NO_ACTION;
9638 if (!options.network && !AllPlayersInSight(player, new_jx, new_jy))
9639 return MF_NO_ACTION;
9642 element = MovingOrBlocked2Element(new_jx, new_jy);
9644 element = MovingOrBlocked2ElementIfNotLeaving(new_jx, new_jy);
9647 if (DONT_RUN_INTO(element))
9649 if (element == EL_ACID && dx == 0 && dy == 1)
9651 SplashAcid(new_jx, new_jy);
9652 Feld[jx][jy] = EL_PLAYER_1;
9653 InitMovingField(jx, jy, MV_DOWN);
9654 Store[jx][jy] = EL_ACID;
9655 ContinueMoving(jx, jy);
9659 TestIfHeroRunsIntoBadThing(jx, jy, player->MovDir);
9664 can_move = DigField(player, jx, jy, new_jx, new_jy, real_dx,real_dy, DF_DIG);
9665 if (can_move != MF_MOVING)
9668 /* check if DigField() has caused relocation of the player */
9669 if (player->jx != jx || player->jy != jy)
9670 return MF_NO_ACTION;
9672 StorePlayer[jx][jy] = 0;
9673 player->last_jx = jx;
9674 player->last_jy = jy;
9675 player->jx = new_jx;
9676 player->jy = new_jy;
9677 StorePlayer[new_jx][new_jy] = player->element_nr;
9680 (dx > 0 || dy > 0 ? -1 : 1) * (TILEX - TILEX / player->move_delay_value);
9682 player->step_counter++;
9685 player->drop_delay = 0;
9688 PlayerVisit[jx][jy] = FrameCounter;
9690 ScrollPlayer(player, SCROLL_INIT);
9693 if (IS_CUSTOM_ELEMENT(Feld[jx][jy]))
9695 CheckTriggeredElementChangeBySide(jx, jy, Feld[jx][jy], CE_OTHER_GETS_LEFT,
9697 CheckElementChangeBySide(jx,jy, Feld[jx][jy],CE_LEFT_BY_PLAYER,leave_side);
9700 if (IS_CUSTOM_ELEMENT(Feld[new_jx][new_jy]))
9702 CheckTriggeredElementChangeBySide(new_jx, new_jy, Feld[new_jx][new_jy],
9703 CE_OTHER_GETS_ENTERED, enter_side);
9704 CheckElementChangeBySide(new_jx, new_jy, Feld[new_jx][new_jy],
9705 CE_ENTERED_BY_PLAYER, enter_side);
9712 boolean MovePlayer(struct PlayerInfo *player, int dx, int dy)
9714 int jx = player->jx, jy = player->jy;
9715 int old_jx = jx, old_jy = jy;
9716 int moved = MF_NO_ACTION;
9719 if (!player->active)
9724 if (player->MovPos == 0)
9726 player->is_moving = FALSE;
9727 player->is_digging = FALSE;
9728 player->is_collecting = FALSE;
9729 player->is_snapping = FALSE;
9730 player->is_pushing = FALSE;
9736 if (!player->active || (!dx && !dy))
9741 if (!FrameReached(&player->move_delay, player->move_delay_value) &&
9749 printf("::: %d <= %d < %d ?\n", player->move_delay, FrameCounter,
9750 player->move_delay + player->move_delay_value);
9753 #if USE_NEW_MOVE_DELAY
9754 if (player->move_delay > 0)
9756 if (!FrameReached(&player->move_delay, player->move_delay_value))
9760 printf("::: can NOT move\n");
9766 if (!FrameReached(&player->move_delay, player->move_delay_value) &&
9767 !(tape.playing && tape.file_version < FILE_VERSION_2_0))
9774 printf("::: COULD move now\n");
9777 #if USE_NEW_MOVE_DELAY
9778 player->move_delay = -1; /* set to "uninitialized" value */
9781 /* store if player is automatically moved to next field */
9782 player->is_auto_moving = (player->programmed_action != MV_NO_MOVING);
9784 /* remove the last programmed player action */
9785 player->programmed_action = 0;
9789 /* should only happen if pre-1.2 tape recordings are played */
9790 /* this is only for backward compatibility */
9792 int original_move_delay_value = player->move_delay_value;
9795 printf("THIS SHOULD ONLY HAPPEN WITH PRE-1.2 LEVEL TAPES. [%ld]\n",
9799 /* scroll remaining steps with finest movement resolution */
9800 player->move_delay_value = MOVE_DELAY_NORMAL_SPEED;
9802 while (player->MovPos)
9804 ScrollPlayer(player, SCROLL_GO_ON);
9805 ScrollScreen(NULL, SCROLL_GO_ON);
9807 #if USE_NEW_MOVE_DELAY
9808 AdvanceFrameAndPlayerCounters(player->index_nr);
9817 player->move_delay_value = original_move_delay_value;
9820 if (player->last_move_dir & MV_HORIZONTAL)
9822 if (!(moved |= MovePlayerOneStep(player, 0, dy, dx, dy)))
9823 moved |= MovePlayerOneStep(player, dx, 0, dx, dy);
9827 if (!(moved |= MovePlayerOneStep(player, dx, 0, dx, dy)))
9828 moved |= MovePlayerOneStep(player, 0, dy, dx, dy);
9834 if (moved & MF_MOVING && !ScreenMovPos &&
9835 (player == local_player || !options.network))
9837 int old_scroll_x = scroll_x, old_scroll_y = scroll_y;
9838 int offset = (setup.scroll_delay ? 3 : 0);
9840 if (!IN_VIS_FIELD(SCREENX(jx), SCREENY(jy)))
9842 /* actual player has left the screen -- scroll in that direction */
9843 if (jx != old_jx) /* player has moved horizontally */
9844 scroll_x += (jx - old_jx);
9845 else /* player has moved vertically */
9846 scroll_y += (jy - old_jy);
9850 if (jx != old_jx) /* player has moved horizontally */
9852 if ((player->MovDir == MV_LEFT && scroll_x > jx - MIDPOSX + offset) ||
9853 (player->MovDir == MV_RIGHT && scroll_x < jx - MIDPOSX - offset))
9854 scroll_x = jx-MIDPOSX + (scroll_x < jx-MIDPOSX ? -offset : +offset);
9856 /* don't scroll over playfield boundaries */
9857 if (scroll_x < SBX_Left || scroll_x > SBX_Right)
9858 scroll_x = (scroll_x < SBX_Left ? SBX_Left : SBX_Right);
9860 /* don't scroll more than one field at a time */
9861 scroll_x = old_scroll_x + SIGN(scroll_x - old_scroll_x);
9863 /* don't scroll against the player's moving direction */
9864 if ((player->MovDir == MV_LEFT && scroll_x > old_scroll_x) ||
9865 (player->MovDir == MV_RIGHT && scroll_x < old_scroll_x))
9866 scroll_x = old_scroll_x;
9868 else /* player has moved vertically */
9870 if ((player->MovDir == MV_UP && scroll_y > jy - MIDPOSY + offset) ||
9871 (player->MovDir == MV_DOWN && scroll_y < jy - MIDPOSY - offset))
9872 scroll_y = jy-MIDPOSY + (scroll_y < jy-MIDPOSY ? -offset : +offset);
9874 /* don't scroll over playfield boundaries */
9875 if (scroll_y < SBY_Upper || scroll_y > SBY_Lower)
9876 scroll_y = (scroll_y < SBY_Upper ? SBY_Upper : SBY_Lower);
9878 /* don't scroll more than one field at a time */
9879 scroll_y = old_scroll_y + SIGN(scroll_y - old_scroll_y);
9881 /* don't scroll against the player's moving direction */
9882 if ((player->MovDir == MV_UP && scroll_y > old_scroll_y) ||
9883 (player->MovDir == MV_DOWN && scroll_y < old_scroll_y))
9884 scroll_y = old_scroll_y;
9888 if (scroll_x != old_scroll_x || scroll_y != old_scroll_y)
9890 if (!options.network && !AllPlayersInVisibleScreen())
9892 scroll_x = old_scroll_x;
9893 scroll_y = old_scroll_y;
9897 ScrollScreen(player, SCROLL_INIT);
9898 ScrollLevel(old_scroll_x - scroll_x, old_scroll_y - scroll_y);
9905 InitPlayerGfxAnimation(player, ACTION_DEFAULT);
9907 if (!(moved & MF_MOVING) && !player->is_pushing)
9912 player->StepFrame = 0;
9914 if (moved & MF_MOVING)
9917 printf("::: REALLY moves now\n");
9920 if (old_jx != jx && old_jy == jy)
9921 player->MovDir = (old_jx < jx ? MV_RIGHT : MV_LEFT);
9922 else if (old_jx == jx && old_jy != jy)
9923 player->MovDir = (old_jy < jy ? MV_DOWN : MV_UP);
9925 DrawLevelField(jx, jy); /* for "crumbled sand" */
9927 player->last_move_dir = player->MovDir;
9928 player->is_moving = TRUE;
9930 player->is_snapping = FALSE;
9934 player->is_switching = FALSE;
9937 player->is_dropping = FALSE;
9941 /* !!! ENABLE THIS FOR OLD VERSIONS !!! */
9944 if (game.engine_version < VERSION_IDENT(3,1,0,0))
9947 int move_direction = player->MovDir;
9949 int enter_side = MV_DIR_OPPOSITE(move_direction);
9950 int leave_side = move_direction;
9952 static int trigger_sides[4][2] =
9954 /* enter side leave side */
9955 { CH_SIDE_RIGHT, CH_SIDE_LEFT }, /* moving left */
9956 { CH_SIDE_LEFT, CH_SIDE_RIGHT }, /* moving right */
9957 { CH_SIDE_BOTTOM, CH_SIDE_TOP }, /* moving up */
9958 { CH_SIDE_TOP, CH_SIDE_BOTTOM } /* moving down */
9960 int enter_side = trigger_sides[MV_DIR_BIT(move_direction)][0];
9961 int leave_side = trigger_sides[MV_DIR_BIT(move_direction)][1];
9963 int old_element = Feld[old_jx][old_jy];
9964 int new_element = Feld[jx][jy];
9967 /* !!! TEST ONLY !!! */
9968 if (IS_CUSTOM_ELEMENT(old_element))
9969 CheckElementChangeByPlayer(old_jx, old_jy, old_element,
9971 player->index_bit, leave_side);
9973 CheckTriggeredElementChangeByPlayer(old_jx, old_jy, old_element,
9975 player->index_bit, leave_side);
9977 if (IS_CUSTOM_ELEMENT(new_element))
9978 CheckElementChangeByPlayer(jx, jy, new_element, CE_ENTERED_BY_PLAYER,
9979 player->index_bit, enter_side);
9981 CheckTriggeredElementChangeByPlayer(jx, jy, new_element,
9982 CE_OTHER_GETS_ENTERED,
9983 player->index_bit, enter_side);
9993 CheckGravityMovementWhenNotMoving(player);
9996 player->last_move_dir = MV_NO_MOVING;
9998 player->is_moving = FALSE;
10000 #if USE_NEW_MOVE_STYLE
10001 /* player is ALLOWED to move, but CANNOT move (something blocks his way) */
10002 /* ensure that the player is also allowed to move in the next frame */
10003 /* (currently, the player is forced to wait eight frames before he can try
10006 if (game.engine_version >= VERSION_IDENT(3,1,1,0))
10007 player->move_delay = 0; /* allow direct movement in the next frame */
10011 #if USE_NEW_MOVE_DELAY
10012 if (player->move_delay == -1) /* not yet initialized by DigField() */
10013 player->move_delay = player->move_delay_value;
10016 if (game.engine_version < VERSION_IDENT(3,0,7,0))
10018 TestIfHeroTouchesBadThing(jx, jy);
10019 TestIfPlayerTouchesCustomElement(jx, jy);
10022 if (!player->active)
10023 RemoveHero(player);
10028 void ScrollPlayer(struct PlayerInfo *player, int mode)
10030 int jx = player->jx, jy = player->jy;
10031 int last_jx = player->last_jx, last_jy = player->last_jy;
10032 int move_stepsize = TILEX / player->move_delay_value;
10034 if (!player->active || !player->MovPos)
10037 if (mode == SCROLL_INIT)
10039 player->actual_frame_counter = FrameCounter;
10040 player->GfxPos = move_stepsize * (player->MovPos / move_stepsize);
10043 printf("::: %06d: %d,%d: %d (%d) [%d]\n",
10045 last_jx, last_jy, Feld[last_jx][last_jy], EL_EXPLOSION,
10046 player->block_delay);
10049 #if USE_NEW_BLOCK_STYLE
10052 if (player->block_delay <= 0)
10053 printf("::: ALERT! block_delay == %d\n", player->block_delay);
10056 if (player->block_delay > 0 &&
10057 Feld[last_jx][last_jy] == EL_EMPTY)
10059 Feld[last_jx][last_jy] = EL_PLAYER_IS_LEAVING;
10060 MovDelay[last_jx][last_jy] = player->block_delay + 1;
10063 #if USE_NEW_MOVE_STYLE
10064 if ((game.engine_version < VERSION_IDENT(3,1,1,0) ||
10065 player->block_last_field) &&
10066 Feld[last_jx][last_jy] == EL_EMPTY)
10067 Feld[last_jx][last_jy] = EL_PLAYER_IS_LEAVING;
10069 if (Feld[last_jx][last_jy] == EL_EMPTY)
10070 Feld[last_jx][last_jy] = EL_PLAYER_IS_LEAVING;
10075 DrawPlayer(player);
10080 else if (!FrameReached(&player->actual_frame_counter, 1))
10083 player->MovPos += (player->MovPos > 0 ? -1 : 1) * move_stepsize;
10084 player->GfxPos = move_stepsize * (player->MovPos / move_stepsize);
10086 #if USE_NEW_BLOCK_STYLE
10088 if (!player->block_last_field &&
10089 Feld[last_jx][last_jy] == EL_PLAYER_IS_LEAVING)
10091 RemoveField(last_jx, last_jy);
10093 Feld[last_jx][last_jy] = EL_EMPTY;
10097 /* before DrawPlayer() to draw correct player graphic for this case */
10098 if (player->MovPos == 0)
10099 CheckGravityMovement(player);
10102 DrawPlayer(player); /* needed here only to cleanup last field */
10105 if (player->MovPos == 0) /* player reached destination field */
10108 if (player->move_delay_reset_counter > 0)
10110 player->move_delay_reset_counter--;
10112 if (player->move_delay_reset_counter == 0)
10114 /* continue with normal speed after quickly moving through gate */
10115 HALVE_PLAYER_SPEED(player);
10117 /* be able to make the next move without delay */
10118 player->move_delay = 0;
10122 if (IS_PASSABLE(Feld[last_jx][last_jy]))
10124 /* continue with normal speed after quickly moving through gate */
10125 HALVE_PLAYER_SPEED(player);
10127 /* be able to make the next move without delay */
10128 player->move_delay = 0;
10132 #if USE_NEW_BLOCK_STYLE
10134 if (player->block_last_field &&
10135 Feld[last_jx][last_jy] == EL_PLAYER_IS_LEAVING)
10137 RemoveField(last_jx, last_jy);
10139 Feld[last_jx][last_jy] = EL_EMPTY;
10143 player->last_jx = jx;
10144 player->last_jy = jy;
10146 if (Feld[jx][jy] == EL_EXIT_OPEN ||
10147 Feld[jx][jy] == EL_SP_EXIT_OPEN ||
10148 Feld[jx][jy] == EL_SP_EXIT_OPENING) /* <-- special case */
10150 DrawPlayer(player); /* needed here only to cleanup last field */
10151 RemoveHero(player);
10153 if (local_player->friends_still_needed == 0 ||
10154 IS_SP_ELEMENT(Feld[jx][jy]))
10155 player->LevelSolved = player->GameOver = TRUE;
10159 /* !!! ENABLE THIS FOR NEW VERSIONS !!! */
10160 /* this breaks one level: "machine", level 000 */
10162 if (game.engine_version >= VERSION_IDENT(3,1,0,0))
10165 int move_direction = player->MovDir;
10167 int enter_side = MV_DIR_OPPOSITE(move_direction);
10168 int leave_side = move_direction;
10170 static int trigger_sides[4][2] =
10172 /* enter side leave side */
10173 { CH_SIDE_RIGHT, CH_SIDE_LEFT }, /* moving left */
10174 { CH_SIDE_LEFT, CH_SIDE_RIGHT }, /* moving right */
10175 { CH_SIDE_BOTTOM, CH_SIDE_TOP }, /* moving up */
10176 { CH_SIDE_TOP, CH_SIDE_BOTTOM } /* moving down */
10178 int enter_side = trigger_sides[MV_DIR_BIT(move_direction)][0];
10179 int leave_side = trigger_sides[MV_DIR_BIT(move_direction)][1];
10181 int old_jx = last_jx;
10182 int old_jy = last_jy;
10183 int old_element = Feld[old_jx][old_jy];
10184 int new_element = Feld[jx][jy];
10187 /* !!! TEST ONLY !!! */
10188 if (IS_CUSTOM_ELEMENT(old_element))
10189 CheckElementChangeByPlayer(old_jx, old_jy, old_element,
10191 player->index_bit, leave_side);
10193 CheckTriggeredElementChangeByPlayer(old_jx, old_jy, old_element,
10194 CE_OTHER_GETS_LEFT,
10195 player->index_bit, leave_side);
10197 if (IS_CUSTOM_ELEMENT(new_element))
10198 CheckElementChangeByPlayer(jx, jy, new_element, CE_ENTERED_BY_PLAYER,
10199 player->index_bit, enter_side);
10201 CheckTriggeredElementChangeByPlayer(jx, jy, new_element,
10202 CE_OTHER_GETS_ENTERED,
10203 player->index_bit, enter_side);
10209 if (game.engine_version >= VERSION_IDENT(3,0,7,0))
10211 TestIfHeroTouchesBadThing(jx, jy);
10212 TestIfPlayerTouchesCustomElement(jx, jy);
10215 /* needed because pushed element has not yet reached its destination,
10216 so it would trigger a change event at its previous field location */
10217 if (!player->is_pushing)
10219 TestIfElementTouchesCustomElement(jx, jy); /* for empty space */
10222 if (!player->active)
10223 RemoveHero(player);
10226 if (level.use_step_counter)
10236 if (TimeLeft <= 10 && setup.time_limit)
10237 PlaySoundStereo(SND_GAME_RUNNING_OUT_OF_TIME, SOUND_MIDDLE);
10239 DrawGameValue_Time(TimeLeft);
10241 if (!TimeLeft && setup.time_limit)
10242 for (i = 0; i < MAX_PLAYERS; i++)
10243 KillHero(&stored_player[i]);
10245 else if (level.time == 0 && !AllPlayersGone) /* level w/o time limit */
10246 DrawGameValue_Time(TimePlayed);
10249 if (tape.single_step && tape.recording && !tape.pausing &&
10250 !player->programmed_action)
10251 TapeTogglePause(TAPE_TOGGLE_AUTOMATIC);
10255 void ScrollScreen(struct PlayerInfo *player, int mode)
10257 static unsigned long screen_frame_counter = 0;
10259 if (mode == SCROLL_INIT)
10261 /* set scrolling step size according to actual player's moving speed */
10262 ScrollStepSize = TILEX / player->move_delay_value;
10264 screen_frame_counter = FrameCounter;
10265 ScreenMovDir = player->MovDir;
10266 ScreenMovPos = player->MovPos;
10267 ScreenGfxPos = ScrollStepSize * (ScreenMovPos / ScrollStepSize);
10270 else if (!FrameReached(&screen_frame_counter, 1))
10275 ScreenMovPos += (ScreenMovPos > 0 ? -1 : 1) * ScrollStepSize;
10276 ScreenGfxPos = ScrollStepSize * (ScreenMovPos / ScrollStepSize);
10277 redraw_mask |= REDRAW_FIELD;
10280 ScreenMovDir = MV_NO_MOVING;
10283 void TestIfPlayerTouchesCustomElement(int x, int y)
10285 static int xy[4][2] =
10292 static int trigger_sides[4][2] =
10294 /* center side border side */
10295 { CH_SIDE_TOP, CH_SIDE_BOTTOM }, /* check top */
10296 { CH_SIDE_LEFT, CH_SIDE_RIGHT }, /* check left */
10297 { CH_SIDE_RIGHT, CH_SIDE_LEFT }, /* check right */
10298 { CH_SIDE_BOTTOM, CH_SIDE_TOP } /* check bottom */
10300 static int touch_dir[4] =
10302 MV_LEFT | MV_RIGHT,
10307 int center_element = Feld[x][y]; /* should always be non-moving! */
10310 for (i = 0; i < NUM_DIRECTIONS; i++)
10312 int xx = x + xy[i][0];
10313 int yy = y + xy[i][1];
10314 int center_side = trigger_sides[i][0];
10315 int border_side = trigger_sides[i][1];
10316 int border_element;
10318 if (!IN_LEV_FIELD(xx, yy))
10321 if (IS_PLAYER(x, y))
10323 struct PlayerInfo *player = PLAYERINFO(x, y);
10325 if (game.engine_version < VERSION_IDENT(3,0,7,0))
10326 border_element = Feld[xx][yy]; /* may be moving! */
10327 else if (!IS_MOVING(xx, yy) && !IS_BLOCKED(xx, yy))
10328 border_element = Feld[xx][yy];
10329 else if (MovDir[xx][yy] & touch_dir[i]) /* elements are touching */
10330 border_element = MovingOrBlocked2Element(xx, yy);
10332 continue; /* center and border element do not touch */
10335 /* !!! TEST ONLY !!! */
10336 CheckElementChangeByPlayer(xx, yy, border_element, CE_TOUCHED_BY_PLAYER,
10337 player->index_bit, border_side);
10338 CheckTriggeredElementChangeByPlayer(xx, yy, border_element,
10339 CE_OTHER_GETS_TOUCHED,
10340 player->index_bit, border_side);
10342 CheckTriggeredElementChangeByPlayer(xx, yy, border_element,
10343 CE_OTHER_GETS_TOUCHED,
10344 player->index_bit, border_side);
10345 CheckElementChangeByPlayer(xx, yy, border_element, CE_TOUCHED_BY_PLAYER,
10346 player->index_bit, border_side);
10349 else if (IS_PLAYER(xx, yy))
10351 struct PlayerInfo *player = PLAYERINFO(xx, yy);
10353 if (game.engine_version >= VERSION_IDENT(3,0,7,0))
10355 if (player->MovPos != 0 && !(player->MovDir & touch_dir[i]))
10356 continue; /* center and border element do not touch */
10360 /* !!! TEST ONLY !!! */
10361 CheckElementChangeByPlayer(x, y, center_element, CE_TOUCHED_BY_PLAYER,
10362 player->index_bit, center_side);
10363 CheckTriggeredElementChangeByPlayer(x, y, center_element,
10364 CE_OTHER_GETS_TOUCHED,
10365 player->index_bit, center_side);
10367 CheckTriggeredElementChangeByPlayer(x, y, center_element,
10368 CE_OTHER_GETS_TOUCHED,
10369 player->index_bit, center_side);
10370 CheckElementChangeByPlayer(x, y, center_element, CE_TOUCHED_BY_PLAYER,
10371 player->index_bit, center_side);
10379 void TestIfElementTouchesCustomElement(int x, int y)
10381 static int xy[4][2] =
10388 static int trigger_sides[4][2] =
10390 /* center side border side */
10391 { CH_SIDE_TOP, CH_SIDE_BOTTOM }, /* check top */
10392 { CH_SIDE_LEFT, CH_SIDE_RIGHT }, /* check left */
10393 { CH_SIDE_RIGHT, CH_SIDE_LEFT }, /* check right */
10394 { CH_SIDE_BOTTOM, CH_SIDE_TOP } /* check bottom */
10396 static int touch_dir[4] =
10398 MV_LEFT | MV_RIGHT,
10403 boolean change_center_element = FALSE;
10404 int center_element_change_page = 0;
10405 int center_element = Feld[x][y]; /* should always be non-moving! */
10406 int border_trigger_element = EL_UNDEFINED;
10409 for (i = 0; i < NUM_DIRECTIONS; i++)
10411 int xx = x + xy[i][0];
10412 int yy = y + xy[i][1];
10413 int center_side = trigger_sides[i][0];
10414 int border_side = trigger_sides[i][1];
10415 int border_element;
10417 if (!IN_LEV_FIELD(xx, yy))
10420 if (game.engine_version < VERSION_IDENT(3,0,7,0))
10421 border_element = Feld[xx][yy]; /* may be moving! */
10422 else if (!IS_MOVING(xx, yy) && !IS_BLOCKED(xx, yy))
10423 border_element = Feld[xx][yy];
10424 else if (MovDir[xx][yy] & touch_dir[i]) /* elements are touching */
10425 border_element = MovingOrBlocked2Element(xx, yy);
10427 continue; /* center and border element do not touch */
10429 /* check for change of center element (but change it only once) */
10430 if (IS_CUSTOM_ELEMENT(center_element) &&
10431 HAS_ANY_CHANGE_EVENT(center_element, CE_OTHER_IS_TOUCHING) &&
10432 !change_center_element)
10434 for (j = 0; j < element_info[center_element].num_change_pages; j++)
10436 struct ElementChangeInfo *change =
10437 &element_info[center_element].change_page[j];
10439 if (change->can_change &&
10440 change->events & CH_EVENT_BIT(CE_OTHER_IS_TOUCHING) &&
10441 change->trigger_side & border_side &&
10443 IS_EQUAL_OR_IN_GROUP(border_element, change->trigger_element)
10445 change->trigger_element == border_element
10449 change_center_element = TRUE;
10450 center_element_change_page = j;
10451 border_trigger_element = border_element;
10458 /* check for change of border element */
10459 if (IS_CUSTOM_ELEMENT(border_element) &&
10460 HAS_ANY_CHANGE_EVENT(border_element, CE_OTHER_IS_TOUCHING))
10462 for (j = 0; j < element_info[border_element].num_change_pages; j++)
10464 struct ElementChangeInfo *change =
10465 &element_info[border_element].change_page[j];
10467 if (change->can_change &&
10468 change->events & CH_EVENT_BIT(CE_OTHER_IS_TOUCHING) &&
10469 change->trigger_side & center_side &&
10471 IS_EQUAL_OR_IN_GROUP(center_element, change->trigger_element)
10473 change->trigger_element == center_element
10478 printf("::: border_element %d, %d\n", x, y);
10481 CheckElementChangeByPage(xx, yy, border_element, center_element,
10482 CE_OTHER_IS_TOUCHING, j);
10489 if (change_center_element)
10492 printf("::: center_element %d, %d\n", x, y);
10495 CheckElementChangeByPage(x, y, center_element, border_trigger_element,
10496 CE_OTHER_IS_TOUCHING, center_element_change_page);
10500 void TestIfElementHitsCustomElement(int x, int y, int direction)
10502 int dx = (direction == MV_LEFT ? -1 : direction == MV_RIGHT ? +1 : 0);
10503 int dy = (direction == MV_UP ? -1 : direction == MV_DOWN ? +1 : 0);
10504 int hitx = x + dx, hity = y + dy;
10505 int hitting_element = Feld[x][y];
10506 int touched_element;
10508 boolean object_hit = (IN_LEV_FIELD(hitx, hity) &&
10509 !IS_FREE(hitx, hity) &&
10510 (!IS_MOVING(hitx, hity) ||
10511 MovDir[hitx][hity] != direction ||
10512 ABS(MovPos[hitx][hity]) <= TILEY / 2));
10515 if (IN_LEV_FIELD(hitx, hity) && IS_FREE(hitx, hity))
10519 if (IN_LEV_FIELD(hitx, hity) && !object_hit)
10523 touched_element = (IN_LEV_FIELD(hitx, hity) ?
10524 MovingOrBlocked2Element(hitx, hity) : EL_STEELWALL);
10526 CheckElementChangeBySide(x, y, hitting_element, touched_element,
10527 CE_HITTING_SOMETHING, direction);
10529 if (IN_LEV_FIELD(hitx, hity))
10531 int opposite_direction = MV_DIR_OPPOSITE(direction);
10532 int hitting_side = direction;
10533 int touched_side = opposite_direction;
10535 int touched_element = MovingOrBlocked2Element(hitx, hity);
10538 boolean object_hit = (!IS_MOVING(hitx, hity) ||
10539 MovDir[hitx][hity] != direction ||
10540 ABS(MovPos[hitx][hity]) <= TILEY / 2);
10549 CheckElementChangeBySide(hitx, hity, touched_element, hitting_element,
10550 CE_HIT_BY_SOMETHING, opposite_direction);
10552 if (IS_CUSTOM_ELEMENT(hitting_element) &&
10553 HAS_ANY_CHANGE_EVENT(hitting_element, CE_OTHER_IS_HITTING))
10555 for (i = 0; i < element_info[hitting_element].num_change_pages; i++)
10557 struct ElementChangeInfo *change =
10558 &element_info[hitting_element].change_page[i];
10560 if (change->can_change &&
10561 change->events & CH_EVENT_BIT(CE_OTHER_IS_HITTING) &&
10562 change->trigger_side & touched_side &&
10565 IS_EQUAL_OR_IN_GROUP(touched_element, change->trigger_element)
10567 change->trigger_element == touched_element
10571 CheckElementChangeByPage(x, y, hitting_element, touched_element,
10572 CE_OTHER_IS_HITTING, i);
10578 if (IS_CUSTOM_ELEMENT(touched_element) &&
10579 HAS_ANY_CHANGE_EVENT(touched_element, CE_OTHER_GETS_HIT))
10581 for (i = 0; i < element_info[touched_element].num_change_pages; i++)
10583 struct ElementChangeInfo *change =
10584 &element_info[touched_element].change_page[i];
10586 if (change->can_change &&
10587 change->events & CH_EVENT_BIT(CE_OTHER_GETS_HIT) &&
10588 change->trigger_side & hitting_side &&
10590 IS_EQUAL_OR_IN_GROUP(hitting_element, change->trigger_element)
10592 change->trigger_element == hitting_element
10596 CheckElementChangeByPage(hitx, hity, touched_element,
10597 hitting_element, CE_OTHER_GETS_HIT, i);
10607 void TestIfElementSmashesCustomElement(int x, int y, int direction)
10609 int dx = (direction == MV_LEFT ? -1 : direction == MV_RIGHT ? +1 : 0);
10610 int dy = (direction == MV_UP ? -1 : direction == MV_DOWN ? +1 : 0);
10611 int hitx = x + dx, hity = y + dy;
10612 int hitting_element = Feld[x][y];
10613 int touched_element;
10615 boolean object_hit = (IN_LEV_FIELD(hitx, hity) &&
10616 !IS_FREE(hitx, hity) &&
10617 (!IS_MOVING(hitx, hity) ||
10618 MovDir[hitx][hity] != direction ||
10619 ABS(MovPos[hitx][hity]) <= TILEY / 2));
10622 if (IN_LEV_FIELD(hitx, hity) && IS_FREE(hitx, hity))
10626 if (IN_LEV_FIELD(hitx, hity) && !object_hit)
10630 touched_element = (IN_LEV_FIELD(hitx, hity) ?
10631 MovingOrBlocked2Element(hitx, hity) : EL_STEELWALL);
10633 CheckElementChangeBySide(x, y, hitting_element, touched_element,
10634 EP_CAN_SMASH_EVERYTHING, direction);
10636 if (IN_LEV_FIELD(hitx, hity))
10638 int opposite_direction = MV_DIR_OPPOSITE(direction);
10639 int hitting_side = direction;
10640 int touched_side = opposite_direction;
10642 int touched_element = MovingOrBlocked2Element(hitx, hity);
10645 boolean object_hit = (!IS_MOVING(hitx, hity) ||
10646 MovDir[hitx][hity] != direction ||
10647 ABS(MovPos[hitx][hity]) <= TILEY / 2);
10656 CheckElementChangeBySide(hitx, hity, touched_element, hitting_element,
10657 CE_SMASHED_BY_SOMETHING, opposite_direction);
10659 if (IS_CUSTOM_ELEMENT(hitting_element) &&
10660 HAS_ANY_CHANGE_EVENT(hitting_element, CE_OTHER_IS_SMASHING))
10662 for (i = 0; i < element_info[hitting_element].num_change_pages; i++)
10664 struct ElementChangeInfo *change =
10665 &element_info[hitting_element].change_page[i];
10667 if (change->can_change &&
10668 change->events & CH_EVENT_BIT(CE_OTHER_IS_SMASHING) &&
10669 change->trigger_side & touched_side &&
10672 IS_EQUAL_OR_IN_GROUP(touched_element, change->trigger_element)
10674 change->trigger_element == touched_element
10678 CheckElementChangeByPage(x, y, hitting_element, touched_element,
10679 CE_OTHER_IS_SMASHING, i);
10685 if (IS_CUSTOM_ELEMENT(touched_element) &&
10686 HAS_ANY_CHANGE_EVENT(touched_element, CE_OTHER_GETS_SMASHED))
10688 for (i = 0; i < element_info[touched_element].num_change_pages; i++)
10690 struct ElementChangeInfo *change =
10691 &element_info[touched_element].change_page[i];
10693 if (change->can_change &&
10694 change->events & CH_EVENT_BIT(CE_OTHER_GETS_SMASHED) &&
10695 change->trigger_side & hitting_side &&
10697 IS_EQUAL_OR_IN_GROUP(hitting_element, change->trigger_element)
10699 change->trigger_element == hitting_element
10703 CheckElementChangeByPage(hitx, hity, touched_element,
10704 hitting_element, CE_OTHER_GETS_SMASHED,i);
10714 void TestIfGoodThingHitsBadThing(int good_x, int good_y, int good_move_dir)
10716 int i, kill_x = -1, kill_y = -1;
10717 int bad_element = -1;
10718 static int test_xy[4][2] =
10725 static int test_dir[4] =
10733 for (i = 0; i < NUM_DIRECTIONS; i++)
10735 int test_x, test_y, test_move_dir, test_element;
10737 test_x = good_x + test_xy[i][0];
10738 test_y = good_y + test_xy[i][1];
10740 if (!IN_LEV_FIELD(test_x, test_y))
10744 (IS_MOVING(test_x, test_y) ? MovDir[test_x][test_y] : MV_NO_MOVING);
10747 test_element = Feld[test_x][test_y];
10749 test_element = MovingOrBlocked2ElementIfNotLeaving(test_x, test_y);
10752 /* 1st case: good thing is moving towards DONT_RUN_INTO style bad thing;
10753 2nd case: DONT_TOUCH style bad thing does not move away from good thing
10755 if ((DONT_RUN_INTO(test_element) && good_move_dir == test_dir[i]) ||
10756 (DONT_TOUCH(test_element) && test_move_dir != test_dir[i]))
10760 bad_element = test_element;
10766 if (kill_x != -1 || kill_y != -1)
10768 if (IS_PLAYER(good_x, good_y))
10770 struct PlayerInfo *player = PLAYERINFO(good_x, good_y);
10773 if (player->shield_deadly_time_left > 0 &&
10774 !IS_INDESTRUCTIBLE(bad_element))
10775 Bang(kill_x, kill_y);
10776 else if (!PLAYER_ENEMY_PROTECTED(good_x, good_y))
10779 if (player->shield_deadly_time_left > 0)
10780 Bang(kill_x, kill_y);
10781 else if (!PLAYER_ENEMY_PROTECTED(good_x, good_y))
10786 Bang(good_x, good_y);
10790 void TestIfBadThingHitsGoodThing(int bad_x, int bad_y, int bad_move_dir)
10792 int i, kill_x = -1, kill_y = -1;
10793 int bad_element = Feld[bad_x][bad_y];
10794 static int test_xy[4][2] =
10801 static int touch_dir[4] =
10803 MV_LEFT | MV_RIGHT,
10808 static int test_dir[4] =
10816 if (bad_element == EL_EXPLOSION) /* skip just exploding bad things */
10819 for (i = 0; i < NUM_DIRECTIONS; i++)
10821 int test_x, test_y, test_move_dir, test_element;
10823 test_x = bad_x + test_xy[i][0];
10824 test_y = bad_y + test_xy[i][1];
10825 if (!IN_LEV_FIELD(test_x, test_y))
10829 (IS_MOVING(test_x, test_y) ? MovDir[test_x][test_y] : MV_NO_MOVING);
10831 test_element = Feld[test_x][test_y];
10833 /* 1st case: good thing is moving towards DONT_RUN_INTO style bad thing;
10834 2nd case: DONT_TOUCH style bad thing does not move away from good thing
10836 if ((DONT_RUN_INTO(bad_element) && bad_move_dir == test_dir[i]) ||
10837 (DONT_TOUCH(bad_element) && test_move_dir != test_dir[i]))
10839 /* good thing is player or penguin that does not move away */
10840 if (IS_PLAYER(test_x, test_y))
10842 struct PlayerInfo *player = PLAYERINFO(test_x, test_y);
10844 if (bad_element == EL_ROBOT && player->is_moving)
10845 continue; /* robot does not kill player if he is moving */
10847 if (game.engine_version >= VERSION_IDENT(3,0,7,0))
10849 if (player->MovPos != 0 && !(player->MovDir & touch_dir[i]))
10850 continue; /* center and border element do not touch */
10857 else if (test_element == EL_PENGUIN)
10866 if (kill_x != -1 || kill_y != -1)
10868 if (IS_PLAYER(kill_x, kill_y))
10870 struct PlayerInfo *player = PLAYERINFO(kill_x, kill_y);
10873 if (player->shield_deadly_time_left > 0 &&
10874 !IS_INDESTRUCTIBLE(bad_element))
10875 Bang(bad_x, bad_y);
10876 else if (!PLAYER_ENEMY_PROTECTED(kill_x, kill_y))
10879 if (player->shield_deadly_time_left > 0)
10880 Bang(bad_x, bad_y);
10881 else if (!PLAYER_ENEMY_PROTECTED(kill_x, kill_y))
10886 Bang(kill_x, kill_y);
10890 void TestIfHeroTouchesBadThing(int x, int y)
10892 TestIfGoodThingHitsBadThing(x, y, MV_NO_MOVING);
10895 void TestIfHeroRunsIntoBadThing(int x, int y, int move_dir)
10897 TestIfGoodThingHitsBadThing(x, y, move_dir);
10900 void TestIfBadThingTouchesHero(int x, int y)
10902 TestIfBadThingHitsGoodThing(x, y, MV_NO_MOVING);
10905 void TestIfBadThingRunsIntoHero(int x, int y, int move_dir)
10907 TestIfBadThingHitsGoodThing(x, y, move_dir);
10910 void TestIfFriendTouchesBadThing(int x, int y)
10912 TestIfGoodThingHitsBadThing(x, y, MV_NO_MOVING);
10915 void TestIfBadThingTouchesFriend(int x, int y)
10917 TestIfBadThingHitsGoodThing(x, y, MV_NO_MOVING);
10920 void TestIfBadThingTouchesOtherBadThing(int bad_x, int bad_y)
10922 int i, kill_x = bad_x, kill_y = bad_y;
10923 static int xy[4][2] =
10931 for (i = 0; i < NUM_DIRECTIONS; i++)
10935 x = bad_x + xy[i][0];
10936 y = bad_y + xy[i][1];
10937 if (!IN_LEV_FIELD(x, y))
10940 element = Feld[x][y];
10941 if (IS_AMOEBOID(element) || element == EL_GAME_OF_LIFE ||
10942 element == EL_AMOEBA_GROWING || element == EL_AMOEBA_DROP)
10950 if (kill_x != bad_x || kill_y != bad_y)
10951 Bang(bad_x, bad_y);
10954 void KillHero(struct PlayerInfo *player)
10956 int jx = player->jx, jy = player->jy;
10958 if (!player->active)
10961 /* remove accessible field at the player's position */
10962 Feld[jx][jy] = EL_EMPTY;
10964 /* deactivate shield (else Bang()/Explode() would not work right) */
10965 player->shield_normal_time_left = 0;
10966 player->shield_deadly_time_left = 0;
10972 static void KillHeroUnlessEnemyProtected(int x, int y)
10974 if (!PLAYER_ENEMY_PROTECTED(x, y))
10975 KillHero(PLAYERINFO(x, y));
10978 static void KillHeroUnlessExplosionProtected(int x, int y)
10980 if (!PLAYER_EXPLOSION_PROTECTED(x, y))
10981 KillHero(PLAYERINFO(x, y));
10984 void BuryHero(struct PlayerInfo *player)
10986 int jx = player->jx, jy = player->jy;
10988 if (!player->active)
10992 PlayLevelSoundElementAction(jx, jy, player->element_nr, ACTION_DYING);
10994 PlayLevelSound(jx, jy, SND_CLASS_PLAYER_DYING);
10996 PlayLevelSound(jx, jy, SND_GAME_LOSING);
10998 player->GameOver = TRUE;
10999 RemoveHero(player);
11002 void RemoveHero(struct PlayerInfo *player)
11004 int jx = player->jx, jy = player->jy;
11005 int i, found = FALSE;
11007 player->present = FALSE;
11008 player->active = FALSE;
11010 if (!ExplodeField[jx][jy])
11011 StorePlayer[jx][jy] = 0;
11013 for (i = 0; i < MAX_PLAYERS; i++)
11014 if (stored_player[i].active)
11018 AllPlayersGone = TRUE;
11025 =============================================================================
11026 checkDiagonalPushing()
11027 -----------------------------------------------------------------------------
11028 check if diagonal input device direction results in pushing of object
11029 (by checking if the alternative direction is walkable, diggable, ...)
11030 =============================================================================
11033 static boolean checkDiagonalPushing(struct PlayerInfo *player,
11034 int x, int y, int real_dx, int real_dy)
11036 int jx, jy, dx, dy, xx, yy;
11038 if (real_dx == 0 || real_dy == 0) /* no diagonal direction => push */
11041 /* diagonal direction: check alternative direction */
11046 xx = jx + (dx == 0 ? real_dx : 0);
11047 yy = jy + (dy == 0 ? real_dy : 0);
11049 return (!IN_LEV_FIELD(xx, yy) || IS_SOLID_FOR_PUSHING(Feld[xx][yy]));
11053 =============================================================================
11055 -----------------------------------------------------------------------------
11056 x, y: field next to player (non-diagonal) to try to dig to
11057 real_dx, real_dy: direction as read from input device (can be diagonal)
11058 =============================================================================
11061 int DigField(struct PlayerInfo *player,
11062 int oldx, int oldy, int x, int y,
11063 int real_dx, int real_dy, int mode)
11066 boolean use_spring_bug = (game.engine_version < VERSION_IDENT(2,2,0,0));
11068 boolean is_player = (IS_PLAYER(oldx, oldy) || mode != DF_DIG);
11069 boolean player_was_pushing = player->is_pushing;
11070 int jx = oldx, jy = oldy;
11071 int dx = x - jx, dy = y - jy;
11072 int nextx = x + dx, nexty = y + dy;
11073 int move_direction = (dx == -1 ? MV_LEFT :
11074 dx == +1 ? MV_RIGHT :
11076 dy == +1 ? MV_DOWN : MV_NO_MOVING);
11077 int opposite_direction = MV_DIR_OPPOSITE(move_direction);
11079 int dig_side = MV_DIR_OPPOSITE(move_direction);
11081 static int trigger_sides[4] =
11083 CH_SIDE_RIGHT, /* moving left */
11084 CH_SIDE_LEFT, /* moving right */
11085 CH_SIDE_BOTTOM, /* moving up */
11086 CH_SIDE_TOP, /* moving down */
11088 int dig_side = trigger_sides[MV_DIR_BIT(move_direction)];
11090 int old_element = Feld[jx][jy];
11093 if (is_player) /* function can also be called by EL_PENGUIN */
11095 if (player->MovPos == 0)
11097 player->is_digging = FALSE;
11098 player->is_collecting = FALSE;
11101 if (player->MovPos == 0) /* last pushing move finished */
11102 player->is_pushing = FALSE;
11104 if (mode == DF_NO_PUSH) /* player just stopped pushing */
11106 player->is_switching = FALSE;
11107 #if USE_NEW_PUSH_DELAY
11108 player->push_delay = -1;
11110 player->push_delay = 0;
11113 return MF_NO_ACTION;
11117 if (IS_MOVING(x, y) || IS_PLAYER(x, y))
11118 return MF_NO_ACTION;
11123 if (IS_TUBE(Feld[jx][jy]) || IS_TUBE(Back[jx][jy]))
11125 if (IS_TUBE(Feld[jx][jy]) ||
11126 (IS_TUBE(Back[jx][jy]) && game.engine_version >= VERSION_IDENT(2,2,0,0)))
11130 int tube_element = (IS_TUBE(Feld[jx][jy]) ? Feld[jx][jy] : Back[jx][jy]);
11131 int tube_leave_directions[][2] =
11133 { EL_TUBE_ANY, MV_LEFT | MV_RIGHT | MV_UP | MV_DOWN },
11134 { EL_TUBE_VERTICAL, MV_UP | MV_DOWN },
11135 { EL_TUBE_HORIZONTAL, MV_LEFT | MV_RIGHT },
11136 { EL_TUBE_VERTICAL_LEFT, MV_LEFT | MV_UP | MV_DOWN },
11137 { EL_TUBE_VERTICAL_RIGHT, MV_RIGHT | MV_UP | MV_DOWN },
11138 { EL_TUBE_HORIZONTAL_UP, MV_LEFT | MV_RIGHT | MV_UP },
11139 { EL_TUBE_HORIZONTAL_DOWN, MV_LEFT | MV_RIGHT | MV_DOWN },
11140 { EL_TUBE_LEFT_UP, MV_LEFT | MV_UP },
11141 { EL_TUBE_LEFT_DOWN, MV_LEFT | MV_DOWN },
11142 { EL_TUBE_RIGHT_UP, MV_RIGHT | MV_UP },
11143 { EL_TUBE_RIGHT_DOWN, MV_RIGHT | MV_DOWN },
11144 { -1, MV_LEFT | MV_RIGHT | MV_UP | MV_DOWN }
11147 while (tube_leave_directions[i][0] != tube_element)
11150 if (tube_leave_directions[i][0] == -1) /* should not happen */
11154 if (!(tube_leave_directions[i][1] & move_direction))
11155 return MF_NO_ACTION; /* tube has no opening in this direction */
11160 if (IS_TUBE(Back[jx][jy]) && game.engine_version >= VERSION_IDENT(2,2,0,0))
11161 old_element = Back[jx][jy];
11165 if (IS_WALKABLE(old_element) && !ACCESS_FROM(old_element, move_direction))
11166 return MF_NO_ACTION; /* field has no opening in this direction */
11168 if (IS_PASSABLE(old_element) && !ACCESS_FROM(old_element,opposite_direction))
11169 return MF_NO_ACTION; /* field has no opening in this direction */
11171 element = Feld[x][y];
11173 if (!is_player && !IS_COLLECTIBLE(element)) /* penguin cannot collect it */
11174 return MF_NO_ACTION;
11176 if (mode == DF_SNAP && !IS_SNAPPABLE(element) &&
11177 game.engine_version >= VERSION_IDENT(2,2,0,0))
11178 return MF_NO_ACTION;
11181 if (game.gravity && is_player && !player->is_auto_moving &&
11182 canFallDown(player) && move_direction != MV_DOWN &&
11183 !canMoveToValidFieldWithGravity(jx, jy, move_direction))
11184 return MF_NO_ACTION; /* player cannot walk here due to gravity */
11188 if (element == EL_EMPTY_SPACE &&
11189 game.gravity && !player->is_auto_moving &&
11190 canFallDown(player) && move_direction != MV_DOWN)
11191 return MF_NO_ACTION; /* player cannot walk here due to gravity */
11197 case EL_SP_PORT_LEFT:
11198 case EL_SP_PORT_RIGHT:
11199 case EL_SP_PORT_UP:
11200 case EL_SP_PORT_DOWN:
11201 case EL_SP_PORT_HORIZONTAL:
11202 case EL_SP_PORT_VERTICAL:
11203 case EL_SP_PORT_ANY:
11204 case EL_SP_GRAVITY_PORT_LEFT:
11205 case EL_SP_GRAVITY_PORT_RIGHT:
11206 case EL_SP_GRAVITY_PORT_UP:
11207 case EL_SP_GRAVITY_PORT_DOWN:
11209 if (!canEnterSupaplexPort(x, y, dx, dy))
11210 return MF_NO_ACTION;
11213 element != EL_SP_PORT_LEFT &&
11214 element != EL_SP_GRAVITY_PORT_LEFT &&
11215 element != EL_SP_PORT_HORIZONTAL &&
11216 element != EL_SP_PORT_ANY) ||
11218 element != EL_SP_PORT_RIGHT &&
11219 element != EL_SP_GRAVITY_PORT_RIGHT &&
11220 element != EL_SP_PORT_HORIZONTAL &&
11221 element != EL_SP_PORT_ANY) ||
11223 element != EL_SP_PORT_UP &&
11224 element != EL_SP_GRAVITY_PORT_UP &&
11225 element != EL_SP_PORT_VERTICAL &&
11226 element != EL_SP_PORT_ANY) ||
11228 element != EL_SP_PORT_DOWN &&
11229 element != EL_SP_GRAVITY_PORT_DOWN &&
11230 element != EL_SP_PORT_VERTICAL &&
11231 element != EL_SP_PORT_ANY) ||
11232 !IN_LEV_FIELD(nextx, nexty) ||
11233 !IS_FREE(nextx, nexty))
11234 return MF_NO_ACTION;
11237 if (element == EL_SP_GRAVITY_PORT_LEFT ||
11238 element == EL_SP_GRAVITY_PORT_RIGHT ||
11239 element == EL_SP_GRAVITY_PORT_UP ||
11240 element == EL_SP_GRAVITY_PORT_DOWN)
11241 game.gravity = !game.gravity;
11243 /* automatically move to the next field with double speed */
11244 player->programmed_action = move_direction;
11246 if (player->move_delay_reset_counter == 0)
11248 player->move_delay_reset_counter = 2; /* two double speed steps */
11250 DOUBLE_PLAYER_SPEED(player);
11253 player->move_delay_reset_counter = 2;
11255 DOUBLE_PLAYER_SPEED(player);
11259 printf("::: passing port %d,%d [%d]\n", x, y, FrameCounter);
11262 PlayLevelSound(x, y, SND_CLASS_SP_PORT_PASSING);
11268 case EL_TUBE_VERTICAL:
11269 case EL_TUBE_HORIZONTAL:
11270 case EL_TUBE_VERTICAL_LEFT:
11271 case EL_TUBE_VERTICAL_RIGHT:
11272 case EL_TUBE_HORIZONTAL_UP:
11273 case EL_TUBE_HORIZONTAL_DOWN:
11274 case EL_TUBE_LEFT_UP:
11275 case EL_TUBE_LEFT_DOWN:
11276 case EL_TUBE_RIGHT_UP:
11277 case EL_TUBE_RIGHT_DOWN:
11280 int tube_enter_directions[][2] =
11282 { EL_TUBE_ANY, MV_LEFT | MV_RIGHT | MV_UP | MV_DOWN },
11283 { EL_TUBE_VERTICAL, MV_UP | MV_DOWN },
11284 { EL_TUBE_HORIZONTAL, MV_LEFT | MV_RIGHT },
11285 { EL_TUBE_VERTICAL_LEFT, MV_RIGHT | MV_UP | MV_DOWN },
11286 { EL_TUBE_VERTICAL_RIGHT, MV_LEFT | MV_UP | MV_DOWN },
11287 { EL_TUBE_HORIZONTAL_UP, MV_LEFT | MV_RIGHT | MV_DOWN },
11288 { EL_TUBE_HORIZONTAL_DOWN, MV_LEFT | MV_RIGHT | MV_UP },
11289 { EL_TUBE_LEFT_UP, MV_RIGHT | MV_DOWN },
11290 { EL_TUBE_LEFT_DOWN, MV_RIGHT | MV_UP },
11291 { EL_TUBE_RIGHT_UP, MV_LEFT | MV_DOWN },
11292 { EL_TUBE_RIGHT_DOWN, MV_LEFT | MV_UP },
11293 { -1, MV_NO_MOVING }
11296 while (tube_enter_directions[i][0] != element)
11299 if (tube_enter_directions[i][0] == -1) /* should not happen */
11303 if (!(tube_enter_directions[i][1] & move_direction))
11304 return MF_NO_ACTION; /* tube has no opening in this direction */
11306 PlayLevelSound(x, y, SND_CLASS_TUBE_WALKING);
11314 if (IS_WALKABLE(element) && ACCESS_FROM(element, opposite_direction))
11316 if (IS_WALKABLE(element))
11319 int sound_element = SND_ELEMENT(element);
11320 int sound_action = ACTION_WALKING;
11323 if (!ACCESS_FROM(element, opposite_direction))
11324 return MF_NO_ACTION; /* field not accessible from this direction */
11328 if (element == EL_EMPTY_SPACE &&
11329 game.gravity && !player->is_auto_moving &&
11330 canFallDown(player) && move_direction != MV_DOWN)
11331 return MF_NO_ACTION; /* player cannot walk here due to gravity */
11334 if (IS_GATE(element))
11336 if (!player->key[element - EL_GATE_1])
11337 return MF_NO_ACTION;
11339 else if (IS_GATE_GRAY(element))
11341 if (!player->key[element - EL_GATE_1_GRAY])
11342 return MF_NO_ACTION;
11344 else if (element == EL_EXIT_OPEN ||
11345 element == EL_SP_EXIT_OPEN ||
11346 element == EL_SP_EXIT_OPENING)
11348 sound_action = ACTION_PASSING; /* player is passing exit */
11350 else if (element == EL_EMPTY)
11352 sound_action = ACTION_MOVING; /* nothing to walk on */
11355 /* play sound from background or player, whatever is available */
11356 if (element_info[sound_element].sound[sound_action] != SND_UNDEFINED)
11357 PlayLevelSoundElementAction(x, y, sound_element, sound_action);
11359 PlayLevelSoundElementAction(x, y, player->element_nr, sound_action);
11364 else if (IS_PASSABLE(element) && canPassField(x, y, move_direction))
11366 else if (IS_PASSABLE(element))
11370 if (!canPassField(x, y, move_direction))
11371 return MF_NO_ACTION;
11376 if (!IN_LEV_FIELD(nextx, nexty) || IS_PLAYER(nextx, nexty) ||
11377 !IS_WALKABLE_FROM(Feld[nextx][nexty], move_direction) ||
11378 (!level.can_pass_to_walkable && !IS_FREE(nextx, nexty)))
11379 return MF_NO_ACTION;
11381 if (!IN_LEV_FIELD(nextx, nexty) || !IS_FREE(nextx, nexty))
11382 return MF_NO_ACTION;
11387 if (!ACCESS_FROM(element, opposite_direction))
11388 return MF_NO_ACTION; /* field not accessible from this direction */
11390 if (IS_CUSTOM_ELEMENT(element) &&
11391 !ACCESS_FROM(element, opposite_direction))
11392 return MF_NO_ACTION; /* field not accessible from this direction */
11396 if (CAN_MOVE(element)) /* only fixed elements can be passed! */
11397 return MF_NO_ACTION;
11402 if (IS_EM_GATE(element))
11404 if (!player->key[element - EL_EM_GATE_1])
11405 return MF_NO_ACTION;
11407 else if (IS_EM_GATE_GRAY(element))
11409 if (!player->key[element - EL_EM_GATE_1_GRAY])
11410 return MF_NO_ACTION;
11412 else if (IS_SP_PORT(element))
11414 if (element == EL_SP_GRAVITY_PORT_LEFT ||
11415 element == EL_SP_GRAVITY_PORT_RIGHT ||
11416 element == EL_SP_GRAVITY_PORT_UP ||
11417 element == EL_SP_GRAVITY_PORT_DOWN)
11418 game.gravity = !game.gravity;
11419 else if (element == EL_SP_GRAVITY_ON_PORT_LEFT ||
11420 element == EL_SP_GRAVITY_ON_PORT_RIGHT ||
11421 element == EL_SP_GRAVITY_ON_PORT_UP ||
11422 element == EL_SP_GRAVITY_ON_PORT_DOWN)
11423 game.gravity = TRUE;
11424 else if (element == EL_SP_GRAVITY_OFF_PORT_LEFT ||
11425 element == EL_SP_GRAVITY_OFF_PORT_RIGHT ||
11426 element == EL_SP_GRAVITY_OFF_PORT_UP ||
11427 element == EL_SP_GRAVITY_OFF_PORT_DOWN)
11428 game.gravity = FALSE;
11431 /* automatically move to the next field with double speed */
11432 player->programmed_action = move_direction;
11434 if (player->move_delay_reset_counter == 0)
11436 player->move_delay_reset_counter = 2; /* two double speed steps */
11438 DOUBLE_PLAYER_SPEED(player);
11441 player->move_delay_reset_counter = 2;
11443 DOUBLE_PLAYER_SPEED(player);
11446 PlayLevelSoundAction(x, y, ACTION_PASSING);
11450 else if (IS_DIGGABLE(element))
11454 if (mode != DF_SNAP)
11457 GfxElement[x][y] = GFX_ELEMENT(element);
11460 (GFX_CRUMBLED(element) ? EL_SAND : GFX_ELEMENT(element));
11462 player->is_digging = TRUE;
11465 PlayLevelSoundElementAction(x, y, element, ACTION_DIGGING);
11467 CheckTriggeredElementChangeByPlayer(x, y, element,CE_OTHER_GETS_DIGGED,
11468 player->index_bit, dig_side);
11471 if (mode == DF_SNAP)
11472 TestIfElementTouchesCustomElement(x, y); /* for empty space */
11477 else if (IS_COLLECTIBLE(element))
11481 if (is_player && mode != DF_SNAP)
11483 GfxElement[x][y] = element;
11484 player->is_collecting = TRUE;
11487 if (element == EL_SPEED_PILL)
11488 player->move_delay_value = MOVE_DELAY_HIGH_SPEED;
11489 else if (element == EL_EXTRA_TIME && level.time > 0)
11492 DrawGameValue_Time(TimeLeft);
11494 else if (element == EL_SHIELD_NORMAL || element == EL_SHIELD_DEADLY)
11496 player->shield_normal_time_left += 10;
11497 if (element == EL_SHIELD_DEADLY)
11498 player->shield_deadly_time_left += 10;
11500 else if (element == EL_DYNAMITE || element == EL_SP_DISK_RED)
11502 if (player->inventory_size < MAX_INVENTORY_SIZE)
11503 player->inventory_element[player->inventory_size++] = element;
11505 DrawGameValue_Dynamite(local_player->inventory_size);
11507 else if (element == EL_DYNABOMB_INCREASE_NUMBER)
11509 player->dynabomb_count++;
11510 player->dynabombs_left++;
11512 else if (element == EL_DYNABOMB_INCREASE_SIZE)
11514 player->dynabomb_size++;
11516 else if (element == EL_DYNABOMB_INCREASE_POWER)
11518 player->dynabomb_xl = TRUE;
11520 else if ((element >= EL_KEY_1 && element <= EL_KEY_4) ||
11521 (element >= EL_EM_KEY_1 && element <= EL_EM_KEY_4))
11523 int key_nr = (element >= EL_KEY_1 && element <= EL_KEY_4 ?
11524 element - EL_KEY_1 : element - EL_EM_KEY_1);
11526 player->key[key_nr] = TRUE;
11528 DrawGameValue_Keys(player);
11530 redraw_mask |= REDRAW_DOOR_1;
11532 else if (IS_ENVELOPE(element))
11535 player->show_envelope = element;
11537 ShowEnvelope(element - EL_ENVELOPE_1);
11540 else if (IS_DROPPABLE(element) ||
11541 IS_THROWABLE(element)) /* can be collected and dropped */
11545 if (element_info[element].collect_count == 0)
11546 player->inventory_infinite_element = element;
11548 for (i = 0; i < element_info[element].collect_count; i++)
11549 if (player->inventory_size < MAX_INVENTORY_SIZE)
11550 player->inventory_element[player->inventory_size++] = element;
11552 DrawGameValue_Dynamite(local_player->inventory_size);
11554 else if (element_info[element].collect_count > 0)
11556 local_player->gems_still_needed -=
11557 element_info[element].collect_count;
11558 if (local_player->gems_still_needed < 0)
11559 local_player->gems_still_needed = 0;
11561 DrawGameValue_Emeralds(local_player->gems_still_needed);
11564 RaiseScoreElement(element);
11565 PlayLevelSoundElementAction(x, y, element, ACTION_COLLECTING);
11568 CheckTriggeredElementChangeByPlayer(x, y, element,
11569 CE_OTHER_GETS_COLLECTED,
11570 player->index_bit, dig_side);
11573 if (mode == DF_SNAP)
11574 TestIfElementTouchesCustomElement(x, y); /* for empty space */
11579 else if (IS_PUSHABLE(element))
11581 if (mode == DF_SNAP && element != EL_BD_ROCK)
11582 return MF_NO_ACTION;
11584 if (CAN_FALL(element) && dy)
11585 return MF_NO_ACTION;
11587 if (CAN_FALL(element) && IN_LEV_FIELD(x, y + 1) && IS_FREE(x, y + 1) &&
11588 !(element == EL_SPRING && level.use_spring_bug))
11589 return MF_NO_ACTION;
11592 if (CAN_MOVE(element) && GET_MAX_MOVE_DELAY(element) == 0 &&
11593 ((move_direction & MV_VERTICAL &&
11594 ((element_info[element].move_pattern & MV_LEFT &&
11595 IN_LEV_FIELD(x - 1, y) && IS_FREE(x - 1, y)) ||
11596 (element_info[element].move_pattern & MV_RIGHT &&
11597 IN_LEV_FIELD(x + 1, y) && IS_FREE(x + 1, y)))) ||
11598 (move_direction & MV_HORIZONTAL &&
11599 ((element_info[element].move_pattern & MV_UP &&
11600 IN_LEV_FIELD(x, y - 1) && IS_FREE(x, y - 1)) ||
11601 (element_info[element].move_pattern & MV_DOWN &&
11602 IN_LEV_FIELD(x, y + 1) && IS_FREE(x, y + 1))))))
11603 return MF_NO_ACTION;
11607 /* do not push elements already moving away faster than player */
11608 if (CAN_MOVE(element) && MovDir[x][y] == move_direction &&
11609 ABS(getElementMoveStepsize(x, y)) > MOVE_STEPSIZE_NORMAL)
11610 return MF_NO_ACTION;
11612 if (element == EL_SPRING && MovDir[x][y] != MV_NO_MOVING)
11613 return MF_NO_ACTION;
11619 if (game.engine_version >= VERSION_IDENT(3,1,0,0))
11621 if (player->push_delay_value == -1 || !player_was_pushing)
11622 player->push_delay_value = GET_NEW_PUSH_DELAY(element);
11624 else if (game.engine_version >= VERSION_IDENT(3,0,7,1))
11626 if (player->push_delay_value == -1)
11627 player->push_delay_value = GET_NEW_PUSH_DELAY(element);
11630 if (game.engine_version >= VERSION_IDENT(3,0,7,1))
11632 if (player->push_delay_value == -1 || !player_was_pushing)
11633 player->push_delay_value = GET_NEW_PUSH_DELAY(element);
11636 else if (game.engine_version >= VERSION_IDENT(2,2,0,7))
11638 if (!player->is_pushing)
11639 player->push_delay_value = GET_NEW_PUSH_DELAY(element);
11643 if (game.engine_version >= VERSION_IDENT(2,2,0,7) &&
11644 (game.engine_version < VERSION_IDENT(3,0,7,1) ||
11645 !player_is_pushing))
11646 player->push_delay_value = GET_NEW_PUSH_DELAY(element);
11649 if (!player->is_pushing &&
11650 game.engine_version >= VERSION_IDENT(2,2,0,7))
11651 player->push_delay_value = GET_NEW_PUSH_DELAY(element);
11655 printf("::: push delay: %ld -> %ld [%d, %d] [%d / %d] [%d '%s': %d]\n",
11656 player->push_delay, player->push_delay_value,
11657 FrameCounter, game.engine_version,
11658 player_was_pushing, player->is_pushing,
11659 element, element_info[element].token_name,
11660 GET_NEW_PUSH_DELAY(element));
11663 player->is_pushing = TRUE;
11665 if (!(IN_LEV_FIELD(nextx, nexty) &&
11666 (IS_FREE(nextx, nexty) ||
11667 (Feld[nextx][nexty] == EL_SOKOBAN_FIELD_EMPTY &&
11668 IS_SB_ELEMENT(element)))))
11669 return MF_NO_ACTION;
11671 if (!checkDiagonalPushing(player, x, y, real_dx, real_dy))
11672 return MF_NO_ACTION;
11674 #if USE_NEW_PUSH_DELAY
11677 if ( (player->push_delay == -1) != (player->push_delay2 == 0) )
11678 printf("::: ALERT: %d, %d [%d / %d]\n",
11679 player->push_delay, player->push_delay2,
11680 FrameCounter, FrameCounter / 50);
11683 if (player->push_delay == -1) /* new pushing; restart delay */
11684 player->push_delay = 0;
11686 if (player->push_delay == 0) /* new pushing; restart delay */
11687 player->push_delay = FrameCounter;
11690 #if USE_NEW_PUSH_DELAY
11692 if ( (player->push_delay > 0) != (!xxx_fr) )
11693 printf("::: PUSH BUG! %d, (%d -> %d) %d [%d / %d]\n",
11694 player->push_delay,
11695 xxx_pdv2, player->push_delay2, player->push_delay_value,
11696 FrameCounter, FrameCounter / 50);
11700 if (player->push_delay > 0 &&
11701 !(tape.playing && tape.file_version < FILE_VERSION_2_0) &&
11702 element != EL_SPRING && element != EL_BALLOON)
11705 if (player->push_delay < player->push_delay_value &&
11706 !(tape.playing && tape.file_version < FILE_VERSION_2_0) &&
11707 element != EL_SPRING && element != EL_BALLOON)
11711 if (!FrameReached(&player->push_delay, player->push_delay_value) &&
11712 !(tape.playing && tape.file_version < FILE_VERSION_2_0) &&
11713 element != EL_SPRING && element != EL_BALLOON)
11716 /* make sure that there is no move delay before next try to push */
11717 #if USE_NEW_MOVE_DELAY
11718 if (game.engine_version >= VERSION_IDENT(3,0,7,1))
11719 player->move_delay = 0;
11721 if (game.engine_version >= VERSION_IDENT(3,0,7,1))
11722 player->move_delay = INITIAL_MOVE_DELAY_OFF;
11725 return MF_NO_ACTION;
11729 printf("::: NOW PUSHING... [%d]\n", FrameCounter);
11732 if (IS_SB_ELEMENT(element))
11734 if (element == EL_SOKOBAN_FIELD_FULL)
11736 Back[x][y] = EL_SOKOBAN_FIELD_EMPTY;
11737 local_player->sokobanfields_still_needed++;
11740 if (Feld[nextx][nexty] == EL_SOKOBAN_FIELD_EMPTY)
11742 Back[nextx][nexty] = EL_SOKOBAN_FIELD_EMPTY;
11743 local_player->sokobanfields_still_needed--;
11746 Feld[x][y] = EL_SOKOBAN_OBJECT;
11748 if (Back[x][y] == Back[nextx][nexty])
11749 PlayLevelSoundAction(x, y, ACTION_PUSHING);
11750 else if (Back[x][y] != 0)
11751 PlayLevelSoundElementAction(x, y, EL_SOKOBAN_FIELD_FULL,
11754 PlayLevelSoundElementAction(nextx, nexty, EL_SOKOBAN_FIELD_EMPTY,
11757 if (local_player->sokobanfields_still_needed == 0 &&
11758 game.emulation == EMU_SOKOBAN)
11760 player->LevelSolved = player->GameOver = TRUE;
11761 PlayLevelSound(x, y, SND_GAME_SOKOBAN_SOLVING);
11765 PlayLevelSoundElementAction(x, y, element, ACTION_PUSHING);
11767 InitMovingField(x, y, move_direction);
11768 GfxAction[x][y] = ACTION_PUSHING;
11770 if (mode == DF_SNAP)
11771 ContinueMoving(x, y);
11773 MovPos[x][y] = (dx != 0 ? dx : dy);
11775 Pushed[x][y] = TRUE;
11776 Pushed[nextx][nexty] = TRUE;
11778 if (game.engine_version < VERSION_IDENT(2,2,0,7))
11779 player->push_delay_value = GET_NEW_PUSH_DELAY(element);
11781 player->push_delay_value = -1; /* get new value later */
11783 #if USE_PUSH_BUGFIX
11784 /* now: check for element change _after_ element has been pushed! */
11786 if (game.use_bug_change_when_pushing)
11788 if (game.engine_version < VERSION_IDENT(3,1,0,0))
11791 CheckElementChangeByPlayer(x, y, element, CE_PUSHED_BY_PLAYER,
11792 player->index_bit, dig_side);
11793 CheckTriggeredElementChangeByPlayer(x,y,element,CE_OTHER_GETS_PUSHED,
11794 player->index_bit, dig_side);
11800 /* check for element change _after_ element has been pushed! */
11804 /* !!! TEST ONLY !!! */
11805 CheckElementChangeByPlayer(x, y, element, CE_PUSHED_BY_PLAYER,
11806 player->index_bit, dig_side);
11807 CheckTriggeredElementChangeByPlayer(x, y, element,CE_OTHER_GETS_PUSHED,
11808 player->index_bit, dig_side);
11810 CheckTriggeredElementChangeByPlayer(x, y, element,CE_OTHER_GETS_PUSHED,
11811 player->index_bit, dig_side);
11812 CheckElementChangeByPlayer(x, y, element, CE_PUSHED_BY_PLAYER,
11813 player->index_bit, dig_side);
11821 else if (IS_SWITCHABLE(element))
11823 if (PLAYER_SWITCHING(player, x, y))
11825 CheckTriggeredElementChangeByPlayer(x,y, element,
11826 CE_OTHER_GETS_PRESSED,
11827 player->index_bit, dig_side);
11832 player->is_switching = TRUE;
11833 player->switch_x = x;
11834 player->switch_y = y;
11836 PlayLevelSoundElementAction(x, y, element, ACTION_ACTIVATING);
11838 if (element == EL_ROBOT_WHEEL)
11840 Feld[x][y] = EL_ROBOT_WHEEL_ACTIVE;
11844 DrawLevelField(x, y);
11846 else if (element == EL_SP_TERMINAL)
11850 for (yy = 0; yy < lev_fieldy; yy++) for (xx=0; xx < lev_fieldx; xx++)
11852 if (Feld[xx][yy] == EL_SP_DISK_YELLOW)
11854 else if (Feld[xx][yy] == EL_SP_TERMINAL)
11855 Feld[xx][yy] = EL_SP_TERMINAL_ACTIVE;
11858 else if (IS_BELT_SWITCH(element))
11860 ToggleBeltSwitch(x, y);
11862 else if (element == EL_SWITCHGATE_SWITCH_UP ||
11863 element == EL_SWITCHGATE_SWITCH_DOWN)
11865 ToggleSwitchgateSwitch(x, y);
11867 else if (element == EL_LIGHT_SWITCH ||
11868 element == EL_LIGHT_SWITCH_ACTIVE)
11870 ToggleLightSwitch(x, y);
11873 PlayLevelSound(x, y, element == EL_LIGHT_SWITCH ?
11874 SND_LIGHT_SWITCH_ACTIVATING :
11875 SND_LIGHT_SWITCH_DEACTIVATING);
11878 else if (element == EL_TIMEGATE_SWITCH)
11880 ActivateTimegateSwitch(x, y);
11882 else if (element == EL_BALLOON_SWITCH_LEFT ||
11883 element == EL_BALLOON_SWITCH_RIGHT ||
11884 element == EL_BALLOON_SWITCH_UP ||
11885 element == EL_BALLOON_SWITCH_DOWN ||
11886 element == EL_BALLOON_SWITCH_ANY)
11888 if (element == EL_BALLOON_SWITCH_ANY)
11889 game.balloon_dir = move_direction;
11891 game.balloon_dir = (element == EL_BALLOON_SWITCH_LEFT ? MV_LEFT :
11892 element == EL_BALLOON_SWITCH_RIGHT ? MV_RIGHT :
11893 element == EL_BALLOON_SWITCH_UP ? MV_UP :
11894 element == EL_BALLOON_SWITCH_DOWN ? MV_DOWN :
11897 else if (element == EL_LAMP)
11899 Feld[x][y] = EL_LAMP_ACTIVE;
11900 local_player->lights_still_needed--;
11902 DrawLevelField(x, y);
11904 else if (element == EL_TIME_ORB_FULL)
11906 Feld[x][y] = EL_TIME_ORB_EMPTY;
11908 DrawGameValue_Time(TimeLeft);
11910 DrawLevelField(x, y);
11913 PlaySoundStereo(SND_TIME_ORB_FULL_COLLECTING, SOUND_MIDDLE);
11917 CheckTriggeredElementChangeByPlayer(x, y, element,
11918 CE_OTHER_IS_SWITCHING,
11919 player->index_bit, dig_side);
11921 CheckTriggeredElementChangeByPlayer(x,y, element,CE_OTHER_GETS_PRESSED,
11922 player->index_bit, dig_side);
11928 if (!PLAYER_SWITCHING(player, x, y))
11930 player->is_switching = TRUE;
11931 player->switch_x = x;
11932 player->switch_y = y;
11935 /* !!! TEST ONLY !!! */
11936 CheckElementChangeByPlayer(x, y, element, CE_SWITCHED,
11937 player->index_bit, dig_side);
11938 CheckTriggeredElementChangeByPlayer(x, y, element,
11939 CE_OTHER_IS_SWITCHING,
11940 player->index_bit, dig_side);
11942 CheckTriggeredElementChangeByPlayer(x, y, element,
11943 CE_OTHER_IS_SWITCHING,
11944 player->index_bit, dig_side);
11945 CheckElementChangeByPlayer(x, y, element, CE_SWITCHED,
11946 player->index_bit, dig_side);
11951 /* !!! TEST ONLY !!! (this breaks "machine", level 000) */
11952 CheckElementChangeByPlayer(x, y, element, CE_PRESSED_BY_PLAYER,
11953 player->index_bit, dig_side);
11954 CheckTriggeredElementChangeByPlayer(x,y, element,CE_OTHER_GETS_PRESSED,
11955 player->index_bit, dig_side);
11957 CheckTriggeredElementChangeByPlayer(x,y, element,CE_OTHER_GETS_PRESSED,
11958 player->index_bit, dig_side);
11959 CheckElementChangeByPlayer(x, y, element, CE_PRESSED_BY_PLAYER,
11960 player->index_bit, dig_side);
11964 return MF_NO_ACTION;
11967 #if USE_NEW_PUSH_DELAY
11968 player->push_delay = -1;
11970 player->push_delay = 0;
11973 if (Feld[x][y] != element) /* really digged/collected something */
11974 player->is_collecting = !player->is_digging;
11979 boolean SnapField(struct PlayerInfo *player, int dx, int dy)
11981 int jx = player->jx, jy = player->jy;
11982 int x = jx + dx, y = jy + dy;
11983 int snap_direction = (dx == -1 ? MV_LEFT :
11984 dx == +1 ? MV_RIGHT :
11986 dy == +1 ? MV_DOWN : MV_NO_MOVING);
11989 if (player->MovPos != 0)
11992 if (player->MovPos != 0 && game.engine_version >= VERSION_IDENT(2,2,0,0))
11996 if (!player->active || !IN_LEV_FIELD(x, y))
12004 if (player->MovPos == 0)
12005 player->is_pushing = FALSE;
12007 player->is_snapping = FALSE;
12009 if (player->MovPos == 0)
12011 player->is_moving = FALSE;
12012 player->is_digging = FALSE;
12013 player->is_collecting = FALSE;
12019 if (player->is_snapping)
12022 player->MovDir = snap_direction;
12025 if (player->MovPos == 0)
12028 player->is_moving = FALSE;
12029 player->is_digging = FALSE;
12030 player->is_collecting = FALSE;
12033 player->is_dropping = FALSE;
12035 if (DigField(player, jx, jy, x, y, 0, 0, DF_SNAP) == MF_NO_ACTION)
12038 player->is_snapping = TRUE;
12041 if (player->MovPos == 0)
12044 player->is_moving = FALSE;
12045 player->is_digging = FALSE;
12046 player->is_collecting = FALSE;
12050 if (player->MovPos != 0) /* prevent graphic bugs in versions < 2.2.0 */
12051 DrawLevelField(player->last_jx, player->last_jy);
12054 DrawLevelField(x, y);
12063 boolean DropElement(struct PlayerInfo *player)
12065 int old_element, new_element;
12066 int dropx = player->jx, dropy = player->jy;
12067 int drop_direction = player->MovDir;
12069 int drop_side = drop_direction;
12071 static int trigger_sides[4] =
12073 CH_SIDE_LEFT, /* dropping left */
12074 CH_SIDE_RIGHT, /* dropping right */
12075 CH_SIDE_TOP, /* dropping up */
12076 CH_SIDE_BOTTOM, /* dropping down */
12078 int drop_side = trigger_sides[MV_DIR_BIT(drop_direction)];
12080 int drop_element = (player->inventory_size > 0 ?
12081 player->inventory_element[player->inventory_size - 1] :
12082 player->inventory_infinite_element != EL_UNDEFINED ?
12083 player->inventory_infinite_element :
12084 player->dynabombs_left > 0 ?
12085 EL_DYNABOMB_PLAYER_1_ACTIVE + player->index_nr :
12088 if (IS_THROWABLE(drop_element))
12090 dropx += GET_DX_FROM_DIR(drop_direction);
12091 dropy += GET_DY_FROM_DIR(drop_direction);
12093 if (!IN_LEV_FIELD(dropx, dropy))
12097 old_element = Feld[dropx][dropy]; /* old element at dropping position */
12098 new_element = drop_element; /* default: no change when dropping */
12100 /* check if player is active, not moving and ready to drop */
12101 if (!player->active || player->MovPos || player->drop_delay > 0)
12104 /* check if player has anything that can be dropped */
12106 if (new_element == EL_UNDEFINED)
12109 if (player->inventory_size == 0 &&
12110 player->inventory_infinite_element == EL_UNDEFINED &&
12111 player->dynabombs_left == 0)
12115 /* check if anything can be dropped at the current position */
12116 if (IS_ACTIVE_BOMB(old_element) || old_element == EL_EXPLOSION)
12119 /* collected custom elements can only be dropped on empty fields */
12121 if (IS_CUSTOM_ELEMENT(new_element) && old_element != EL_EMPTY)
12124 if (player->inventory_size > 0 &&
12125 IS_CUSTOM_ELEMENT(player->inventory_element[player->inventory_size - 1])
12126 && old_element != EL_EMPTY)
12130 if (old_element != EL_EMPTY)
12131 Back[dropx][dropy] = old_element; /* store old element on this field */
12133 ResetGfxAnimation(dropx, dropy);
12134 ResetRandomAnimationValue(dropx, dropy);
12136 if (player->inventory_size > 0 ||
12137 player->inventory_infinite_element != EL_UNDEFINED)
12139 if (player->inventory_size > 0)
12141 player->inventory_size--;
12144 new_element = player->inventory_element[player->inventory_size];
12147 DrawGameValue_Dynamite(local_player->inventory_size);
12149 if (new_element == EL_DYNAMITE)
12150 new_element = EL_DYNAMITE_ACTIVE;
12151 else if (new_element == EL_SP_DISK_RED)
12152 new_element = EL_SP_DISK_RED_ACTIVE;
12155 Feld[dropx][dropy] = new_element;
12157 if (IN_SCR_FIELD(SCREENX(dropx), SCREENY(dropy)))
12158 DrawGraphicThruMask(SCREENX(dropx), SCREENY(dropy),
12159 el2img(Feld[dropx][dropy]), 0);
12161 PlayLevelSoundAction(dropx, dropy, ACTION_DROPPING);
12164 /* needed if previous element just changed to "empty" in the last frame */
12165 Changed[dropx][dropy] = 0; /* allow another change */
12169 /* !!! TEST ONLY !!! */
12170 CheckElementChangeByPlayer(dropx, dropy, new_element, CE_DROPPED_BY_PLAYER,
12171 player->index_bit, drop_side);
12172 CheckTriggeredElementChangeByPlayer(dropx, dropy, new_element,
12173 CE_OTHER_GETS_DROPPED,
12174 player->index_bit, drop_side);
12176 CheckTriggeredElementChangeByPlayer(dropx, dropy, new_element,
12177 CE_OTHER_GETS_DROPPED,
12178 player->index_bit, drop_side);
12179 CheckElementChangeByPlayer(dropx, dropy, new_element, CE_DROPPED_BY_PLAYER,
12180 player->index_bit, drop_side);
12183 TestIfElementTouchesCustomElement(dropx, dropy);
12185 else /* player is dropping a dyna bomb */
12187 player->dynabombs_left--;
12190 new_element = EL_DYNABOMB_PLAYER_1_ACTIVE + player->index_nr;
12193 Feld[dropx][dropy] = new_element;
12195 if (IN_SCR_FIELD(SCREENX(dropx), SCREENY(dropy)))
12196 DrawGraphicThruMask(SCREENX(dropx), SCREENY(dropy),
12197 el2img(Feld[dropx][dropy]), 0);
12199 PlayLevelSoundAction(dropx, dropy, ACTION_DROPPING);
12206 if (Feld[dropx][dropy] == new_element) /* uninitialized unless CE change */
12209 InitField_WithBug1(dropx, dropy, FALSE);
12211 InitField(dropx, dropy, FALSE);
12212 if (CAN_MOVE(Feld[dropx][dropy]))
12213 InitMovDir(dropx, dropy);
12217 new_element = Feld[dropx][dropy]; /* element might have changed */
12219 if (IS_CUSTOM_ELEMENT(new_element) && CAN_MOVE(new_element) &&
12220 element_info[new_element].move_pattern == MV_WHEN_DROPPED)
12223 int move_stepsize = element_info[new_element].move_stepsize;
12225 int move_direction, nextx, nexty;
12227 if (element_info[new_element].move_direction_initial == MV_START_AUTOMATIC)
12228 MovDir[dropx][dropy] = drop_direction;
12230 move_direction = MovDir[dropx][dropy];
12231 nextx = dropx + GET_DX_FROM_DIR(move_direction);
12232 nexty = dropy + GET_DY_FROM_DIR(move_direction);
12235 Changed[dropx][dropy] = 0; /* allow another change */
12236 CheckCollision[dropx][dropy] = 2;
12239 if (IN_LEV_FIELD_AND_IS_FREE(nextx, nexty))
12242 WasJustMoving[dropx][dropy] = 3;
12245 InitMovingField(dropx, dropy, move_direction);
12246 ContinueMoving(dropx, dropy);
12251 /* !!! commented out from 3.1.0-4 to 3.1.0-5 !!! */
12254 Changed[dropx][dropy] = 0; /* allow another change */
12257 TestIfElementHitsCustomElement(dropx, dropy, move_direction);
12259 CheckElementChangeBySide(dropx, dropy, new_element, touched_element,
12260 CE_HITTING_SOMETHING, move_direction);
12268 player->drop_delay = 2 * TILEX / move_stepsize + 1;
12273 player->drop_delay = 8 + 8 + 8;
12277 player->drop_delay = GET_NEW_DROP_DELAY(drop_element);
12282 player->is_dropping = TRUE;
12288 /* ------------------------------------------------------------------------- */
12289 /* game sound playing functions */
12290 /* ------------------------------------------------------------------------- */
12292 static int *loop_sound_frame = NULL;
12293 static int *loop_sound_volume = NULL;
12295 void InitPlayLevelSound()
12297 int num_sounds = getSoundListSize();
12299 checked_free(loop_sound_frame);
12300 checked_free(loop_sound_volume);
12302 loop_sound_frame = checked_calloc(num_sounds * sizeof(int));
12303 loop_sound_volume = checked_calloc(num_sounds * sizeof(int));
12306 static void PlayLevelSound(int x, int y, int nr)
12308 int sx = SCREENX(x), sy = SCREENY(y);
12309 int volume, stereo_position;
12310 int max_distance = 8;
12311 int type = (IS_LOOP_SOUND(nr) ? SND_CTRL_PLAY_LOOP : SND_CTRL_PLAY_SOUND);
12313 if ((!setup.sound_simple && !IS_LOOP_SOUND(nr)) ||
12314 (!setup.sound_loops && IS_LOOP_SOUND(nr)))
12317 if (!IN_LEV_FIELD(x, y) ||
12318 sx < -max_distance || sx >= SCR_FIELDX + max_distance ||
12319 sy < -max_distance || sy >= SCR_FIELDY + max_distance)
12322 volume = SOUND_MAX_VOLUME;
12324 if (!IN_SCR_FIELD(sx, sy))
12326 int dx = ABS(sx - SCR_FIELDX / 2) - SCR_FIELDX / 2;
12327 int dy = ABS(sy - SCR_FIELDY / 2) - SCR_FIELDY / 2;
12329 volume -= volume * (dx > dy ? dx : dy) / max_distance;
12332 stereo_position = (SOUND_MAX_LEFT +
12333 (sx + max_distance) * SOUND_MAX_LEFT2RIGHT /
12334 (SCR_FIELDX + 2 * max_distance));
12336 if (IS_LOOP_SOUND(nr))
12338 /* This assures that quieter loop sounds do not overwrite louder ones,
12339 while restarting sound volume comparison with each new game frame. */
12341 if (loop_sound_volume[nr] > volume && loop_sound_frame[nr] == FrameCounter)
12344 loop_sound_volume[nr] = volume;
12345 loop_sound_frame[nr] = FrameCounter;
12348 PlaySoundExt(nr, volume, stereo_position, type);
12351 static void PlayLevelSoundNearest(int x, int y, int sound_action)
12353 PlayLevelSound(x < LEVELX(BX1) ? LEVELX(BX1) :
12354 x > LEVELX(BX2) ? LEVELX(BX2) : x,
12355 y < LEVELY(BY1) ? LEVELY(BY1) :
12356 y > LEVELY(BY2) ? LEVELY(BY2) : y,
12360 static void PlayLevelSoundAction(int x, int y, int action)
12362 PlayLevelSoundElementAction(x, y, Feld[x][y], action);
12365 static void PlayLevelSoundElementAction(int x, int y, int element, int action)
12367 int sound_effect = element_info[SND_ELEMENT(element)].sound[action];
12369 if (sound_effect != SND_UNDEFINED)
12370 PlayLevelSound(x, y, sound_effect);
12373 static void PlayLevelSoundElementActionIfLoop(int x, int y, int element,
12376 int sound_effect = element_info[SND_ELEMENT(element)].sound[action];
12378 if (sound_effect != SND_UNDEFINED && IS_LOOP_SOUND(sound_effect))
12379 PlayLevelSound(x, y, sound_effect);
12382 static void PlayLevelSoundActionIfLoop(int x, int y, int action)
12384 int sound_effect = element_info[SND_ELEMENT(Feld[x][y])].sound[action];
12386 if (sound_effect != SND_UNDEFINED && IS_LOOP_SOUND(sound_effect))
12387 PlayLevelSound(x, y, sound_effect);
12390 static void StopLevelSoundActionIfLoop(int x, int y, int action)
12392 int sound_effect = element_info[SND_ELEMENT(Feld[x][y])].sound[action];
12394 if (sound_effect != SND_UNDEFINED && IS_LOOP_SOUND(sound_effect))
12395 StopSound(sound_effect);
12398 static void PlayLevelMusic()
12400 if (levelset.music[level_nr] != MUS_UNDEFINED)
12401 PlayMusic(levelset.music[level_nr]); /* from config file */
12403 PlayMusic(MAP_NOCONF_MUSIC(level_nr)); /* from music dir */
12406 void PlayLevelSound_EM(int x, int y, int element_em, int sample)
12408 int element = (element_em > -1 ? map_element_EM_to_RND(element_em) : 0);
12411 if (sample == SAMPLE_bug)
12412 printf("::: PlayLevelSound_EM: %d, %d: %d\n", x, y, sample);
12418 PlayLevelSoundElementAction(x, y, element, ACTION_WALKING);
12422 PlayLevelSoundElementAction(x, y, element, ACTION_PUSHING);
12426 PlayLevelSoundElementAction(x, y, element, ACTION_IMPACT);
12430 PlayLevelSoundElementAction(x, y, element, ACTION_IMPACT);
12434 PlayLevelSoundElementAction(x, y, element, ACTION_BREAKING);
12438 PlayLevelSoundElementAction(x, y, EL_BUG, ACTION_MOVING);
12442 PlayLevelSoundElementAction(x, y, EL_SPACESHIP, ACTION_MOVING);
12445 case SAMPLE_android:
12446 PlayLevelSoundElementAction(x, y, element, ACTION_DROPPING);
12449 case SAMPLE_spring:
12450 PlayLevelSoundElementAction(x, y, element, ACTION_IMPACT);
12454 PlayLevelSoundElementAction(x, y, element, ACTION_DYING);
12458 PlayLevelSoundElementAction(x, y, EL_YAMYAM, ACTION_WAITING);
12462 PlayLevelSoundElementAction(x, y, element, ACTION_MOVING);
12465 case SAMPLE_collect:
12466 PlayLevelSoundElementAction(x, y, element, ACTION_COLLECTING);
12469 case SAMPLE_diamond:
12470 PlayLevelSoundElementAction(x, y, element, ACTION_IMPACT);
12473 case SAMPLE_squash:
12474 PlayLevelSoundElementAction(x, y, element, ACTION_BREAKING);
12477 case SAMPLE_wonderfall:
12478 PlayLevelSoundElementAction(x, y, EL_MAGIC_WALL, ACTION_FILLING);
12482 PlayLevelSoundElementAction(x, y, element, ACTION_IMPACT);
12486 PlayLevelSoundElementAction(x, y, element, ACTION_PUSHING);
12490 PlayLevelSoundElementAction(x, y, element, ACTION_DIGGING);
12494 PlayLevelSound(x, y, SND_ACID_SPLASHING);
12498 PlayLevelSoundElementAction(x, y, element, ACTION_DROPPING);
12502 PlayLevelSoundElementAction(x, y, element, ACTION_GROWING);
12505 case SAMPLE_wonder:
12506 PlayLevelSoundElementAction(x, y, element, ACTION_ACTIVE);
12510 PlayLevelSoundElementAction(x, y, element, ACTION_PASSING);
12514 PlayLevelSoundElementAction(x, y, element, ACTION_PASSING);
12517 case SAMPLE_dynamite:
12518 PlayLevelSoundElementAction(x, y, element, ACTION_DROPPING);
12522 PlayLevelSoundElementAction(x, y, element, ACTION_ACTIVE);
12526 PlayLevelSoundElementAction(x, y, element, ACTION_ACTIVATING);
12530 PlaySoundStereo(SND_MAGIC_WALL_ACTIVE, SOUND_MIDDLE);
12534 PlayLevelSoundElementAction(x, y, element, ACTION_EXPLODING);
12538 PlaySoundStereo(SND_GAME_RUNNING_OUT_OF_TIME, SOUND_MIDDLE);
12542 PlayLevelSoundElementAction(x, y, element, ACTION_DYING);
12546 PlayLevelSoundElementAction(x, y, element, ACTION_DEFAULT);
12551 void RaiseScore(int value)
12553 local_player->score += value;
12555 DrawGameValue_Score(local_player->score);
12558 void RaiseScoreElement(int element)
12563 case EL_BD_DIAMOND:
12564 case EL_EMERALD_YELLOW:
12565 case EL_EMERALD_RED:
12566 case EL_EMERALD_PURPLE:
12567 case EL_SP_INFOTRON:
12568 RaiseScore(level.score[SC_EMERALD]);
12571 RaiseScore(level.score[SC_DIAMOND]);
12574 RaiseScore(level.score[SC_CRYSTAL]);
12577 RaiseScore(level.score[SC_PEARL]);
12580 case EL_BD_BUTTERFLY:
12581 case EL_SP_ELECTRON:
12582 RaiseScore(level.score[SC_BUG]);
12585 case EL_BD_FIREFLY:
12586 case EL_SP_SNIKSNAK:
12587 RaiseScore(level.score[SC_SPACESHIP]);
12590 case EL_DARK_YAMYAM:
12591 RaiseScore(level.score[SC_YAMYAM]);
12594 RaiseScore(level.score[SC_ROBOT]);
12597 RaiseScore(level.score[SC_PACMAN]);
12600 RaiseScore(level.score[SC_NUT]);
12603 case EL_SP_DISK_RED:
12604 case EL_DYNABOMB_INCREASE_NUMBER:
12605 case EL_DYNABOMB_INCREASE_SIZE:
12606 case EL_DYNABOMB_INCREASE_POWER:
12607 RaiseScore(level.score[SC_DYNAMITE]);
12609 case EL_SHIELD_NORMAL:
12610 case EL_SHIELD_DEADLY:
12611 RaiseScore(level.score[SC_SHIELD]);
12613 case EL_EXTRA_TIME:
12614 RaiseScore(level.score[SC_TIME_BONUS]);
12620 RaiseScore(level.score[SC_KEY]);
12623 RaiseScore(element_info[element].collect_score);
12628 void RequestQuitGame(boolean ask_if_really_quit)
12630 if (AllPlayersGone ||
12631 !ask_if_really_quit ||
12632 level_editor_test_game ||
12633 Request("Do you really want to quit the game ?",
12634 REQ_ASK | REQ_STAY_CLOSED))
12636 #if defined(NETWORK_AVALIABLE)
12637 if (options.network)
12638 SendToServer_StopPlaying();
12642 game_status = GAME_MODE_MAIN;
12650 if (tape.playing && tape.deactivate_display)
12651 TapeDeactivateDisplayOff(TRUE);
12654 OpenDoor(DOOR_OPEN_1 | DOOR_COPY_BACK);
12657 if (tape.playing && tape.deactivate_display)
12658 TapeDeactivateDisplayOn();
12665 /* ---------- new game button stuff ---------------------------------------- */
12667 /* graphic position values for game buttons */
12668 #define GAME_BUTTON_XSIZE 30
12669 #define GAME_BUTTON_YSIZE 30
12670 #define GAME_BUTTON_XPOS 5
12671 #define GAME_BUTTON_YPOS 215
12672 #define SOUND_BUTTON_XPOS 5
12673 #define SOUND_BUTTON_YPOS (GAME_BUTTON_YPOS + GAME_BUTTON_YSIZE)
12675 #define GAME_BUTTON_STOP_XPOS (GAME_BUTTON_XPOS + 0 * GAME_BUTTON_XSIZE)
12676 #define GAME_BUTTON_PAUSE_XPOS (GAME_BUTTON_XPOS + 1 * GAME_BUTTON_XSIZE)
12677 #define GAME_BUTTON_PLAY_XPOS (GAME_BUTTON_XPOS + 2 * GAME_BUTTON_XSIZE)
12678 #define SOUND_BUTTON_MUSIC_XPOS (SOUND_BUTTON_XPOS + 0 * GAME_BUTTON_XSIZE)
12679 #define SOUND_BUTTON_LOOPS_XPOS (SOUND_BUTTON_XPOS + 1 * GAME_BUTTON_XSIZE)
12680 #define SOUND_BUTTON_SIMPLE_XPOS (SOUND_BUTTON_XPOS + 2 * GAME_BUTTON_XSIZE)
12687 } gamebutton_info[NUM_GAME_BUTTONS] =
12690 GAME_BUTTON_STOP_XPOS, GAME_BUTTON_YPOS,
12695 GAME_BUTTON_PAUSE_XPOS, GAME_BUTTON_YPOS,
12696 GAME_CTRL_ID_PAUSE,
12700 GAME_BUTTON_PLAY_XPOS, GAME_BUTTON_YPOS,
12705 SOUND_BUTTON_MUSIC_XPOS, SOUND_BUTTON_YPOS,
12706 SOUND_CTRL_ID_MUSIC,
12707 "background music on/off"
12710 SOUND_BUTTON_LOOPS_XPOS, SOUND_BUTTON_YPOS,
12711 SOUND_CTRL_ID_LOOPS,
12712 "sound loops on/off"
12715 SOUND_BUTTON_SIMPLE_XPOS, SOUND_BUTTON_YPOS,
12716 SOUND_CTRL_ID_SIMPLE,
12717 "normal sounds on/off"
12721 void CreateGameButtons()
12725 for (i = 0; i < NUM_GAME_BUTTONS; i++)
12727 Bitmap *gd_bitmap = graphic_info[IMG_GLOBAL_DOOR].bitmap;
12728 struct GadgetInfo *gi;
12731 unsigned long event_mask;
12732 int gd_xoffset, gd_yoffset;
12733 int gd_x1, gd_x2, gd_y1, gd_y2;
12736 gd_xoffset = gamebutton_info[i].x;
12737 gd_yoffset = gamebutton_info[i].y;
12738 gd_x1 = DOOR_GFX_PAGEX4 + gd_xoffset;
12739 gd_x2 = DOOR_GFX_PAGEX3 + gd_xoffset;
12741 if (id == GAME_CTRL_ID_STOP ||
12742 id == GAME_CTRL_ID_PAUSE ||
12743 id == GAME_CTRL_ID_PLAY)
12745 button_type = GD_TYPE_NORMAL_BUTTON;
12747 event_mask = GD_EVENT_RELEASED;
12748 gd_y1 = DOOR_GFX_PAGEY1 + gd_yoffset - GAME_BUTTON_YSIZE;
12749 gd_y2 = DOOR_GFX_PAGEY1 + gd_yoffset - GAME_BUTTON_YSIZE;
12753 button_type = GD_TYPE_CHECK_BUTTON;
12755 ((id == SOUND_CTRL_ID_MUSIC && setup.sound_music) ||
12756 (id == SOUND_CTRL_ID_LOOPS && setup.sound_loops) ||
12757 (id == SOUND_CTRL_ID_SIMPLE && setup.sound_simple) ? TRUE : FALSE);
12758 event_mask = GD_EVENT_PRESSED;
12759 gd_y1 = DOOR_GFX_PAGEY1 + gd_yoffset;
12760 gd_y2 = DOOR_GFX_PAGEY1 + gd_yoffset - GAME_BUTTON_YSIZE;
12763 gi = CreateGadget(GDI_CUSTOM_ID, id,
12764 GDI_INFO_TEXT, gamebutton_info[i].infotext,
12765 GDI_X, DX + gd_xoffset,
12766 GDI_Y, DY + gd_yoffset,
12767 GDI_WIDTH, GAME_BUTTON_XSIZE,
12768 GDI_HEIGHT, GAME_BUTTON_YSIZE,
12769 GDI_TYPE, button_type,
12770 GDI_STATE, GD_BUTTON_UNPRESSED,
12771 GDI_CHECKED, checked,
12772 GDI_DESIGN_UNPRESSED, gd_bitmap, gd_x1, gd_y1,
12773 GDI_DESIGN_PRESSED, gd_bitmap, gd_x2, gd_y1,
12774 GDI_ALT_DESIGN_UNPRESSED, gd_bitmap, gd_x1, gd_y2,
12775 GDI_ALT_DESIGN_PRESSED, gd_bitmap, gd_x2, gd_y2,
12776 GDI_EVENT_MASK, event_mask,
12777 GDI_CALLBACK_ACTION, HandleGameButtons,
12781 Error(ERR_EXIT, "cannot create gadget");
12783 game_gadget[id] = gi;
12787 void FreeGameButtons()
12791 for (i = 0; i < NUM_GAME_BUTTONS; i++)
12792 FreeGadget(game_gadget[i]);
12795 static void MapGameButtons()
12799 for (i = 0; i < NUM_GAME_BUTTONS; i++)
12800 MapGadget(game_gadget[i]);
12803 void UnmapGameButtons()
12807 for (i = 0; i < NUM_GAME_BUTTONS; i++)
12808 UnmapGadget(game_gadget[i]);
12811 static void HandleGameButtons(struct GadgetInfo *gi)
12813 int id = gi->custom_id;
12815 if (game_status != GAME_MODE_PLAYING)
12820 case GAME_CTRL_ID_STOP:
12821 RequestQuitGame(TRUE);
12824 case GAME_CTRL_ID_PAUSE:
12825 if (options.network)
12827 #if defined(NETWORK_AVALIABLE)
12829 SendToServer_ContinuePlaying();
12831 SendToServer_PausePlaying();
12835 TapeTogglePause(TAPE_TOGGLE_MANUAL);
12838 case GAME_CTRL_ID_PLAY:
12841 #if defined(NETWORK_AVALIABLE)
12842 if (options.network)
12843 SendToServer_ContinuePlaying();
12847 tape.pausing = FALSE;
12848 DrawVideoDisplay(VIDEO_STATE_PAUSE_OFF,0);
12853 case SOUND_CTRL_ID_MUSIC:
12854 if (setup.sound_music)
12856 setup.sound_music = FALSE;
12859 else if (audio.music_available)
12861 setup.sound = setup.sound_music = TRUE;
12863 SetAudioMode(setup.sound);
12869 case SOUND_CTRL_ID_LOOPS:
12870 if (setup.sound_loops)
12871 setup.sound_loops = FALSE;
12872 else if (audio.loops_available)
12874 setup.sound = setup.sound_loops = TRUE;
12875 SetAudioMode(setup.sound);
12879 case SOUND_CTRL_ID_SIMPLE:
12880 if (setup.sound_simple)
12881 setup.sound_simple = FALSE;
12882 else if (audio.sound_available)
12884 setup.sound = setup.sound_simple = TRUE;
12885 SetAudioMode(setup.sound);