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 static void resolve_group_element(int group_element, int recursion_depth)
1129 static int group_nr;
1130 static struct ElementGroupInfo *group;
1131 struct ElementGroupInfo *actual_group = element_info[group_element].group;
1134 if (recursion_depth > NUM_GROUP_ELEMENTS) /* recursion too deep */
1136 Error(ERR_WARN, "recursion too deep when resolving group element %d",
1137 group_element - EL_GROUP_START + 1);
1139 /* replace element which caused too deep recursion by question mark */
1140 group->element_resolved[group->num_elements_resolved++] = EL_UNKNOWN;
1145 if (recursion_depth == 0) /* initialization */
1147 group = element_info[group_element].group;
1148 group_nr = group_element - EL_GROUP_START;
1150 group->num_elements_resolved = 0;
1151 group->choice_pos = 0;
1154 for (i = 0; i < actual_group->num_elements; i++)
1156 int element = actual_group->element[i];
1158 if (group->num_elements_resolved == NUM_FILE_ELEMENTS)
1161 if (IS_GROUP_ELEMENT(element))
1162 resolve_group_element(element, recursion_depth + 1);
1165 group->element_resolved[group->num_elements_resolved++] = element;
1166 element_info[element].in_group[group_nr] = TRUE;
1171 if (recursion_depth == 0 && group_element <= EL_GROUP_4)
1173 printf("::: group %d: %d resolved elements\n",
1174 group_element - EL_GROUP_START, group->num_elements_resolved);
1175 for (i = 0; i < group->num_elements_resolved; i++)
1176 printf("::: - %d ['%s']\n", group->element_resolved[i],
1177 element_info[group->element_resolved[i]].token_name);
1184 =============================================================================
1186 -----------------------------------------------------------------------------
1187 initialize game engine due to level / tape version number
1188 =============================================================================
1191 static void InitGameEngine()
1195 /* set game engine from tape file when re-playing, else from level file */
1196 game.engine_version = (tape.playing ? tape.engine_version :
1197 level.game_version);
1199 /* ---------------------------------------------------------------------- */
1200 /* set flags for bugs and changes according to active game engine version */
1201 /* ---------------------------------------------------------------------- */
1205 Before 3.1.0, custom elements that "change when pushing" changed directly
1206 after the player started pushing them (until then handled in "DigField()").
1207 Since 3.1.0, these custom elements are not changed until the "pushing"
1208 move of the element is finished (now handled in "ContinueMoving()").
1210 Affected levels/tapes:
1211 The first condition is generally needed for all levels/tapes before version
1212 3.1.0, which might use the old behaviour before it was changed; known tapes
1213 that are affected are some tapes from the level set "Walpurgis Gardens" by
1215 The second condition is an exception from the above case and is needed for
1216 the special case of tapes recorded with game (not engine!) version 3.1.0 or
1217 above (including some development versions of 3.1.0), but before it was
1218 known that this change would break tapes like the above and was fixed in
1219 3.1.1, so that the changed behaviour was active although the engine version
1220 while recording maybe was before 3.1.0. There is at least one tape that is
1221 affected by this exception, which is the tape for the one-level set "Bug
1222 Machine" by Juergen Bonhagen.
1225 game.use_bug_change_when_pushing =
1226 (game.engine_version < VERSION_IDENT(3,1,0,0) &&
1228 tape.game_version >= VERSION_IDENT(3,1,0,0) &&
1229 tape.game_version < VERSION_IDENT(3,1,1,0)));
1231 /* ---------------------------------------------------------------------- */
1233 /* dynamically adjust element properties according to game engine version */
1234 InitElementPropertiesEngine(game.engine_version);
1237 printf("level %d: level version == %06d\n", level_nr, level.game_version);
1238 printf(" tape version == %06d [%s] [file: %06d]\n",
1239 tape.engine_version, (tape.playing ? "PLAYING" : "RECORDING"),
1241 printf(" => game.engine_version == %06d\n", game.engine_version);
1244 /* ---------- recursively resolve group elements ------------------------- */
1246 for (i = 0; i < MAX_NUM_ELEMENTS; i++)
1247 for (j = 0; j < NUM_GROUP_ELEMENTS; j++)
1248 element_info[i].in_group[j] = FALSE;
1250 for (i = 0; i < NUM_GROUP_ELEMENTS; i++)
1251 resolve_group_element(EL_GROUP_START + i, 0);
1253 /* ---------- initialize player's initial move delay --------------------- */
1255 #if USE_NEW_MOVE_DELAY
1256 /* dynamically adjust player properties according to level information */
1257 game.initial_move_delay_value =
1258 (level.double_speed ? MOVE_DELAY_HIGH_SPEED : MOVE_DELAY_NORMAL_SPEED);
1260 /* dynamically adjust player properties according to game engine version */
1261 game.initial_move_delay = (game.engine_version <= VERSION_IDENT(2,0,1,0) ?
1262 game.initial_move_delay_value : 0);
1264 /* dynamically adjust player properties according to game engine version */
1265 game.initial_move_delay =
1266 (game.engine_version <= VERSION_IDENT(2,0,1,0) ? INITIAL_MOVE_DELAY_ON :
1267 INITIAL_MOVE_DELAY_OFF);
1269 /* dynamically adjust player properties according to level information */
1270 game.initial_move_delay_value =
1271 (level.double_speed ? MOVE_DELAY_HIGH_SPEED : MOVE_DELAY_NORMAL_SPEED);
1274 /* ---------- initialize player's initial push delay --------------------- */
1276 /* dynamically adjust player properties according to game engine version */
1277 game.initial_push_delay_value =
1278 (game.engine_version < VERSION_IDENT(3,0,7,1) ? 5 : -1);
1280 /* ---------- initialize changing elements ------------------------------- */
1282 /* initialize changing elements information */
1283 for (i = 0; i < MAX_NUM_ELEMENTS; i++)
1285 struct ElementInfo *ei = &element_info[i];
1287 /* this pointer might have been changed in the level editor */
1288 ei->change = &ei->change_page[0];
1290 if (!IS_CUSTOM_ELEMENT(i))
1292 ei->change->target_element = EL_EMPTY_SPACE;
1293 ei->change->delay_fixed = 0;
1294 ei->change->delay_random = 0;
1295 ei->change->delay_frames = 1;
1298 ei->change_events = CE_BITMASK_DEFAULT;
1299 for (j = 0; j < NUM_CHANGE_EVENTS; j++)
1301 ei->event_page_nr[j] = 0;
1302 ei->event_page[j] = &ei->change_page[0];
1306 /* add changing elements from pre-defined list */
1307 for (i = 0; change_delay_list[i].element != EL_UNDEFINED; i++)
1309 struct ChangingElementInfo *ch_delay = &change_delay_list[i];
1310 struct ElementInfo *ei = &element_info[ch_delay->element];
1312 ei->change->target_element = ch_delay->target_element;
1313 ei->change->delay_fixed = ch_delay->change_delay;
1315 ei->change->pre_change_function = ch_delay->pre_change_function;
1316 ei->change->change_function = ch_delay->change_function;
1317 ei->change->post_change_function = ch_delay->post_change_function;
1319 ei->change_events |= CH_EVENT_BIT(CE_DELAY);
1322 SET_PROPERTY(ch_delay->element, EP_CAN_CHANGE, TRUE);
1327 /* add change events from custom element configuration */
1328 for (i = 0; i < NUM_CUSTOM_ELEMENTS; i++)
1330 struct ElementInfo *ei = &element_info[EL_CUSTOM_START + i];
1332 for (j = 0; j < ei->num_change_pages; j++)
1334 if (!ei->change_page[j].can_change)
1337 for (k = 0; k < NUM_CHANGE_EVENTS; k++)
1339 /* only add event page for the first page found with this event */
1340 if (ei->change_page[j].events & CH_EVENT_BIT(k) &&
1341 !(ei->change_events & CH_EVENT_BIT(k)))
1343 ei->change_events |= CH_EVENT_BIT(k);
1344 ei->event_page_nr[k] = j;
1345 ei->event_page[k] = &ei->change_page[j];
1353 /* add change events from custom element configuration */
1354 for (i = 0; i < NUM_CUSTOM_ELEMENTS; i++)
1356 int element = EL_CUSTOM_START + i;
1358 /* only add custom elements that change after fixed/random frame delay */
1359 if (CAN_CHANGE(element) && HAS_CHANGE_EVENT(element, CE_DELAY))
1360 element_info[element].change_events |= CH_EVENT_BIT(CE_DELAY);
1364 /* ---------- initialize run-time trigger player and element ------------- */
1366 for (i = 0; i < NUM_CUSTOM_ELEMENTS; i++)
1368 struct ElementInfo *ei = &element_info[EL_CUSTOM_START + i];
1370 for (j = 0; j < ei->num_change_pages; j++)
1372 ei->change_page[j].actual_trigger_element = EL_EMPTY;
1373 ei->change_page[j].actual_trigger_player = EL_PLAYER_1;
1377 /* ---------- initialize trigger events ---------------------------------- */
1379 /* initialize trigger events information */
1380 for (i = 0; i < MAX_NUM_ELEMENTS; i++)
1381 trigger_events[i] = EP_BITMASK_DEFAULT;
1384 /* add trigger events from element change event properties */
1385 for (i = 0; i < MAX_NUM_ELEMENTS; i++)
1387 struct ElementInfo *ei = &element_info[i];
1389 for (j = 0; j < ei->num_change_pages; j++)
1391 if (!ei->change_page[j].can_change)
1394 if (ei->change_page[j].events & CH_EVENT_BIT(CE_BY_OTHER_ACTION))
1396 int trigger_element = ei->change_page[j].trigger_element;
1398 if (IS_GROUP_ELEMENT(trigger_element))
1400 struct ElementGroupInfo *group = element_info[trigger_element].group;
1402 for (k = 0; k < group->num_elements_resolved; k++)
1403 trigger_events[group->element_resolved[k]]
1404 |= ei->change_page[j].events;
1407 trigger_events[trigger_element] |= ei->change_page[j].events;
1412 /* add trigger events from element change event properties */
1413 for (i = 0; i < MAX_NUM_ELEMENTS; i++)
1414 if (HAS_CHANGE_EVENT(i, CE_BY_OTHER_ACTION))
1415 trigger_events[element_info[i].change->trigger_element] |=
1416 element_info[i].change->events;
1419 /* ---------- initialize push delay -------------------------------------- */
1421 /* initialize push delay values to default */
1422 for (i = 0; i < MAX_NUM_ELEMENTS; i++)
1424 if (!IS_CUSTOM_ELEMENT(i))
1426 element_info[i].push_delay_fixed = game.default_push_delay_fixed;
1427 element_info[i].push_delay_random = game.default_push_delay_random;
1431 /* set push delay value for certain elements from pre-defined list */
1432 for (i = 0; push_delay_list[i].element != EL_UNDEFINED; i++)
1434 int e = push_delay_list[i].element;
1436 element_info[e].push_delay_fixed = push_delay_list[i].push_delay_fixed;
1437 element_info[e].push_delay_random = push_delay_list[i].push_delay_random;
1440 /* set push delay value for Supaplex elements for newer engine versions */
1441 if (game.engine_version >= VERSION_IDENT(3,1,0,0))
1443 for (i = 0; i < MAX_NUM_ELEMENTS; i++)
1445 if (IS_SP_ELEMENT(i))
1447 #if USE_NEW_MOVE_STYLE
1448 /* set SP push delay to just enough to push under a falling zonk */
1449 int delay = (game.engine_version >= VERSION_IDENT(3,1,1,0) ? 8 : 6);
1451 element_info[i].push_delay_fixed = delay;
1452 element_info[i].push_delay_random = 0;
1454 element_info[i].push_delay_fixed = 6; /* just enough to escape ... */
1455 element_info[i].push_delay_random = 0; /* ... from falling zonk */
1461 /* ---------- initialize move stepsize ----------------------------------- */
1463 /* initialize move stepsize values to default */
1464 for (i = 0; i < MAX_NUM_ELEMENTS; i++)
1465 if (!IS_CUSTOM_ELEMENT(i))
1466 element_info[i].move_stepsize = MOVE_STEPSIZE_NORMAL;
1468 /* set move stepsize value for certain elements from pre-defined list */
1469 for (i = 0; move_stepsize_list[i].element != EL_UNDEFINED; i++)
1471 int e = move_stepsize_list[i].element;
1473 element_info[e].move_stepsize = move_stepsize_list[i].move_stepsize;
1477 /* ---------- initialize move dig/leave ---------------------------------- */
1479 for (i = 0; i < MAX_NUM_ELEMENTS; i++)
1481 element_info[i].can_leave_element = FALSE;
1482 element_info[i].can_leave_element_last = FALSE;
1486 /* ---------- initialize gem count --------------------------------------- */
1488 /* initialize gem count values for each element */
1489 for (i = 0; i < MAX_NUM_ELEMENTS; i++)
1490 if (!IS_CUSTOM_ELEMENT(i))
1491 element_info[i].collect_count = 0;
1493 /* add gem count values for all elements from pre-defined list */
1494 for (i = 0; collect_count_list[i].element != EL_UNDEFINED; i++)
1495 element_info[collect_count_list[i].element].collect_count =
1496 collect_count_list[i].count;
1498 /* ---------- initialize access direction -------------------------------- */
1500 /* initialize access direction values to default (access from every side) */
1501 for (i = 0; i < MAX_NUM_ELEMENTS; i++)
1502 if (!IS_CUSTOM_ELEMENT(i))
1503 element_info[i].access_direction = MV_ALL_DIRECTIONS;
1505 /* set access direction value for certain elements from pre-defined list */
1506 for (i = 0; access_direction_list[i].element != EL_UNDEFINED; i++)
1507 element_info[access_direction_list[i].element].access_direction =
1508 access_direction_list[i].direction;
1513 =============================================================================
1515 -----------------------------------------------------------------------------
1516 initialize and start new game
1517 =============================================================================
1522 boolean emulate_bd = TRUE; /* unless non-BOULDERDASH elements found */
1523 boolean emulate_sb = TRUE; /* unless non-SOKOBAN elements found */
1524 boolean emulate_sp = TRUE; /* unless non-SUPAPLEX elements found */
1531 #if USE_NEW_AMOEBA_CODE
1532 printf("Using new amoeba code.\n");
1534 printf("Using old amoeba code.\n");
1539 /* don't play tapes over network */
1540 network_playing = (options.network && !tape.playing);
1542 for (i = 0; i < MAX_PLAYERS; i++)
1544 struct PlayerInfo *player = &stored_player[i];
1546 player->index_nr = i;
1547 player->index_bit = (1 << i);
1548 player->element_nr = EL_PLAYER_1 + i;
1550 player->present = FALSE;
1551 player->active = FALSE;
1554 player->effective_action = 0;
1555 player->programmed_action = 0;
1558 player->gems_still_needed = level.gems_needed;
1559 player->sokobanfields_still_needed = 0;
1560 player->lights_still_needed = 0;
1561 player->friends_still_needed = 0;
1563 for (j = 0; j < MAX_KEYS; j++)
1564 player->key[j] = FALSE;
1566 player->dynabomb_count = 0;
1567 player->dynabomb_size = 1;
1568 player->dynabombs_left = 0;
1569 player->dynabomb_xl = FALSE;
1571 player->MovDir = MV_NO_MOVING;
1574 player->GfxDir = MV_NO_MOVING;
1575 player->GfxAction = ACTION_DEFAULT;
1577 player->StepFrame = 0;
1579 player->use_murphy_graphic = FALSE;
1581 player->block_last_field = FALSE; /* initialized in InitPlayerField() */
1582 player->block_delay = -1; /* initialized in InitPlayerField() */
1584 player->can_fall_into_acid = CAN_MOVE_INTO_ACID(player->element_nr);
1586 player->actual_frame_counter = 0;
1588 player->step_counter = 0;
1590 player->last_move_dir = MV_NO_MOVING;
1592 player->is_waiting = FALSE;
1593 player->is_moving = FALSE;
1594 player->is_auto_moving = FALSE;
1595 player->is_digging = FALSE;
1596 player->is_snapping = FALSE;
1597 player->is_collecting = FALSE;
1598 player->is_pushing = FALSE;
1599 player->is_switching = FALSE;
1600 player->is_dropping = FALSE;
1602 player->is_bored = FALSE;
1603 player->is_sleeping = FALSE;
1605 player->frame_counter_bored = -1;
1606 player->frame_counter_sleeping = -1;
1608 player->anim_delay_counter = 0;
1609 player->post_delay_counter = 0;
1611 player->action_waiting = ACTION_DEFAULT;
1612 player->last_action_waiting = ACTION_DEFAULT;
1613 player->special_action_bored = ACTION_DEFAULT;
1614 player->special_action_sleeping = ACTION_DEFAULT;
1616 player->num_special_action_bored = 0;
1617 player->num_special_action_sleeping = 0;
1619 /* determine number of special actions for bored and sleeping animation */
1620 for (j = ACTION_BORING_1; j <= ACTION_BORING_LAST; j++)
1622 boolean found = FALSE;
1624 for (k = 0; k < NUM_DIRECTIONS; k++)
1625 if (el_act_dir2img(player->element_nr, j, k) !=
1626 el_act_dir2img(player->element_nr, ACTION_DEFAULT, k))
1630 player->num_special_action_bored++;
1634 for (j = ACTION_SLEEPING_1; j <= ACTION_SLEEPING_LAST; j++)
1636 boolean found = FALSE;
1638 for (k = 0; k < NUM_DIRECTIONS; k++)
1639 if (el_act_dir2img(player->element_nr, j, k) !=
1640 el_act_dir2img(player->element_nr, ACTION_DEFAULT, k))
1644 player->num_special_action_sleeping++;
1649 player->switch_x = -1;
1650 player->switch_y = -1;
1652 player->show_envelope = 0;
1654 player->move_delay = game.initial_move_delay;
1655 player->move_delay_value = game.initial_move_delay_value;
1657 player->move_delay_reset_counter = 0;
1659 #if USE_NEW_PUSH_DELAY
1660 player->push_delay = -1; /* initialized when pushing starts */
1661 player->push_delay_value = game.initial_push_delay_value;
1663 player->push_delay = 0;
1664 player->push_delay_value = game.initial_push_delay_value;
1667 player->drop_delay = 0;
1669 player->last_jx = player->last_jy = 0;
1670 player->jx = player->jy = 0;
1672 player->shield_normal_time_left = 0;
1673 player->shield_deadly_time_left = 0;
1675 player->inventory_infinite_element = EL_UNDEFINED;
1676 player->inventory_size = 0;
1678 DigField(player, 0, 0, 0, 0, 0, 0, DF_NO_PUSH);
1679 SnapField(player, 0, 0);
1681 player->LevelSolved = FALSE;
1682 player->GameOver = FALSE;
1685 network_player_action_received = FALSE;
1687 #if defined(NETWORK_AVALIABLE)
1688 /* initial null action */
1689 if (network_playing)
1690 SendToServer_MovePlayer(MV_NO_MOVING);
1698 TimeLeft = level.time;
1701 ScreenMovDir = MV_NO_MOVING;
1705 ScrollStepSize = 0; /* will be correctly initialized by ScrollScreen() */
1707 AllPlayersGone = FALSE;
1709 game.yamyam_content_nr = 0;
1710 game.magic_wall_active = FALSE;
1711 game.magic_wall_time_left = 0;
1712 game.light_time_left = 0;
1713 game.timegate_time_left = 0;
1714 game.switchgate_pos = 0;
1715 game.balloon_dir = MV_NO_MOVING;
1716 game.gravity = level.initial_gravity;
1717 game.explosions_delayed = TRUE;
1719 game.envelope_active = FALSE;
1721 for (i = 0; i < NUM_BELTS; i++)
1723 game.belt_dir[i] = MV_NO_MOVING;
1724 game.belt_dir_nr[i] = 3; /* not moving, next moving left */
1727 for (i = 0; i < MAX_NUM_AMOEBA; i++)
1728 AmoebaCnt[i] = AmoebaCnt2[i] = 0;
1730 for (x = 0; x < lev_fieldx; x++)
1732 for (y = 0; y < lev_fieldy; y++)
1734 Feld[x][y] = level.field[x][y];
1735 MovPos[x][y] = MovDir[x][y] = MovDelay[x][y] = 0;
1736 ChangeDelay[x][y] = 0;
1737 ChangePage[x][y] = -1;
1738 Store[x][y] = Store2[x][y] = StorePlayer[x][y] = Back[x][y] = 0;
1740 WasJustMoving[x][y] = 0;
1741 WasJustFalling[x][y] = 0;
1742 CheckCollision[x][y] = 0;
1744 Pushed[x][y] = FALSE;
1746 Changed[x][y] = CE_BITMASK_DEFAULT;
1747 ChangeEvent[x][y] = CE_BITMASK_DEFAULT;
1749 ExplodePhase[x][y] = 0;
1750 ExplodeDelay[x][y] = 0;
1751 ExplodeField[x][y] = EX_TYPE_NONE;
1753 RunnerVisit[x][y] = 0;
1754 PlayerVisit[x][y] = 0;
1757 GfxRandom[x][y] = INIT_GFX_RANDOM();
1758 GfxElement[x][y] = EL_UNDEFINED;
1759 GfxAction[x][y] = ACTION_DEFAULT;
1760 GfxDir[x][y] = MV_NO_MOVING;
1764 for (y = 0; y < lev_fieldy; y++)
1766 for (x = 0; x < lev_fieldx; x++)
1768 if (emulate_bd && !IS_BD_ELEMENT(Feld[x][y]))
1770 if (emulate_sb && !IS_SB_ELEMENT(Feld[x][y]))
1772 if (emulate_sp && !IS_SP_ELEMENT(Feld[x][y]))
1775 InitField(x, y, TRUE);
1781 game.emulation = (emulate_bd ? EMU_BOULDERDASH :
1782 emulate_sb ? EMU_SOKOBAN :
1783 emulate_sp ? EMU_SUPAPLEX : EMU_NONE);
1785 /* initialize explosion and ignition delay */
1786 for (i = 0; i < MAX_NUM_ELEMENTS; i++)
1788 if (!IS_CUSTOM_ELEMENT(i))
1791 int delay = (((IS_SP_ELEMENT(i) && i != EL_EMPTY_SPACE) &&
1792 game.engine_version >= VERSION_IDENT(3,1,0,0)) ||
1793 game.emulation == EMU_SUPAPLEX ? 3 : 2);
1794 int last_phase = (num_phase + 1) * delay;
1795 int half_phase = (num_phase / 2) * delay;
1797 element_info[i].explosion_delay = last_phase - 1;
1798 element_info[i].ignition_delay = half_phase;
1801 if (i == EL_BLACK_ORB)
1802 element_info[i].ignition_delay = 0;
1804 if (i == EL_BLACK_ORB)
1805 element_info[i].ignition_delay = 1;
1810 if (element_info[i].explosion_delay < 1) /* !!! check again !!! */
1811 element_info[i].explosion_delay = 1;
1813 if (element_info[i].ignition_delay < 1) /* !!! check again !!! */
1814 element_info[i].ignition_delay = 1;
1818 /* correct non-moving belts to start moving left */
1819 for (i = 0; i < NUM_BELTS; i++)
1820 if (game.belt_dir[i] == MV_NO_MOVING)
1821 game.belt_dir_nr[i] = 3; /* not moving, next moving left */
1823 /* check if any connected player was not found in playfield */
1824 for (i = 0; i < MAX_PLAYERS; i++)
1826 struct PlayerInfo *player = &stored_player[i];
1828 if (player->connected && !player->present)
1830 for (j = 0; j < MAX_PLAYERS; j++)
1832 struct PlayerInfo *some_player = &stored_player[j];
1833 int jx = some_player->jx, jy = some_player->jy;
1835 /* assign first free player found that is present in the playfield */
1836 if (some_player->present && !some_player->connected)
1838 player->present = TRUE;
1839 player->active = TRUE;
1841 some_player->present = FALSE;
1842 some_player->active = FALSE;
1845 player->element_nr = some_player->element_nr;
1848 #if USE_NEW_BLOCK_STYLE
1849 player->block_last_field = some_player->block_last_field;
1850 player->block_delay = some_player->block_delay;
1853 StorePlayer[jx][jy] = player->element_nr;
1854 player->jx = player->last_jx = jx;
1855 player->jy = player->last_jy = jy;
1865 /* when playing a tape, eliminate all players which do not participate */
1867 for (i = 0; i < MAX_PLAYERS; i++)
1869 if (stored_player[i].active && !tape.player_participates[i])
1871 struct PlayerInfo *player = &stored_player[i];
1872 int jx = player->jx, jy = player->jy;
1874 player->active = FALSE;
1875 StorePlayer[jx][jy] = 0;
1876 Feld[jx][jy] = EL_EMPTY;
1880 else if (!options.network && !setup.team_mode) /* && !tape.playing */
1882 /* when in single player mode, eliminate all but the first active player */
1884 for (i = 0; i < MAX_PLAYERS; i++)
1886 if (stored_player[i].active)
1888 for (j = i + 1; j < MAX_PLAYERS; j++)
1890 if (stored_player[j].active)
1892 struct PlayerInfo *player = &stored_player[j];
1893 int jx = player->jx, jy = player->jy;
1895 player->active = FALSE;
1896 player->present = FALSE;
1898 StorePlayer[jx][jy] = 0;
1899 Feld[jx][jy] = EL_EMPTY;
1906 /* when recording the game, store which players take part in the game */
1909 for (i = 0; i < MAX_PLAYERS; i++)
1910 if (stored_player[i].active)
1911 tape.player_participates[i] = TRUE;
1916 for (i = 0; i < MAX_PLAYERS; i++)
1918 struct PlayerInfo *player = &stored_player[i];
1920 printf("Player %d: present == %d, connected == %d, active == %d.\n",
1925 if (local_player == player)
1926 printf("Player %d is local player.\n", i+1);
1930 if (BorderElement == EL_EMPTY)
1933 SBX_Right = lev_fieldx - SCR_FIELDX;
1935 SBY_Lower = lev_fieldy - SCR_FIELDY;
1940 SBX_Right = lev_fieldx - SCR_FIELDX + 1;
1942 SBY_Lower = lev_fieldy - SCR_FIELDY + 1;
1945 if (lev_fieldx + (SBX_Left == -1 ? 2 : 0) <= SCR_FIELDX)
1946 SBX_Left = SBX_Right = -1 * (SCR_FIELDX - lev_fieldx) / 2;
1948 if (lev_fieldy + (SBY_Upper == -1 ? 2 : 0) <= SCR_FIELDY)
1949 SBY_Upper = SBY_Lower = -1 * (SCR_FIELDY - lev_fieldy) / 2;
1951 /* if local player not found, look for custom element that might create
1952 the player (make some assumptions about the right custom element) */
1953 if (!local_player->present)
1955 int start_x = 0, start_y = 0;
1956 int found_rating = 0;
1957 int found_element = EL_UNDEFINED;
1959 for (y = 0; y < lev_fieldy; y++) for (x = 0; x < lev_fieldx; x++)
1961 int element = Feld[x][y];
1966 if (!IS_CUSTOM_ELEMENT(element))
1969 if (CAN_CHANGE(element))
1971 for (i = 0; i < element_info[element].num_change_pages; i++)
1973 content = element_info[element].change_page[i].target_element;
1974 is_player = ELEM_IS_PLAYER(content);
1976 if (is_player && (found_rating < 3 || element < found_element))
1982 found_element = element;
1987 for (yy = 0; yy < 3; yy++) for (xx = 0; xx < 3; xx++)
1989 content = element_info[element].content[xx][yy];
1990 is_player = ELEM_IS_PLAYER(content);
1992 if (is_player && (found_rating < 2 || element < found_element))
1994 start_x = x + xx - 1;
1995 start_y = y + yy - 1;
1998 found_element = element;
2001 if (!CAN_CHANGE(element))
2004 for (i = 0; i < element_info[element].num_change_pages; i++)
2006 content= element_info[element].change_page[i].target_content[xx][yy];
2007 is_player = ELEM_IS_PLAYER(content);
2009 if (is_player && (found_rating < 1 || element < found_element))
2011 start_x = x + xx - 1;
2012 start_y = y + yy - 1;
2015 found_element = element;
2021 scroll_x = (start_x < SBX_Left + MIDPOSX ? SBX_Left :
2022 start_x > SBX_Right + MIDPOSX ? SBX_Right :
2025 scroll_y = (start_y < SBY_Upper + MIDPOSY ? SBY_Upper :
2026 start_y > SBY_Lower + MIDPOSY ? SBY_Lower :
2032 scroll_x = (local_player->jx < SBX_Left + MIDPOSX ? SBX_Left :
2033 local_player->jx > SBX_Right + MIDPOSX ? SBX_Right :
2034 local_player->jx - MIDPOSX);
2036 scroll_y = (local_player->jy < SBY_Upper + MIDPOSY ? SBY_Upper :
2037 local_player->jy > SBY_Lower + MIDPOSY ? SBY_Lower :
2038 local_player->jy - MIDPOSY);
2040 scroll_x = SBX_Left;
2041 scroll_y = SBY_Upper;
2042 if (local_player->jx >= SBX_Left + MIDPOSX)
2043 scroll_x = (local_player->jx <= SBX_Right + MIDPOSX ?
2044 local_player->jx - MIDPOSX :
2046 if (local_player->jy >= SBY_Upper + MIDPOSY)
2047 scroll_y = (local_player->jy <= SBY_Lower + MIDPOSY ?
2048 local_player->jy - MIDPOSY :
2053 CloseDoor(DOOR_CLOSE_1);
2058 /* after drawing the level, correct some elements */
2059 if (game.timegate_time_left == 0)
2060 CloseAllOpenTimegates();
2062 if (setup.soft_scrolling)
2063 BlitBitmap(fieldbuffer, backbuffer, FX, FY, SXSIZE, SYSIZE, SX, SY);
2065 redraw_mask |= REDRAW_FROM_BACKBUFFER;
2068 /* copy default game door content to main double buffer */
2069 BlitBitmap(graphic_info[IMG_GLOBAL_DOOR].bitmap, drawto,
2070 DOOR_GFX_PAGEX5, DOOR_GFX_PAGEY1, DXSIZE, DYSIZE, DX, DY);
2072 DrawGameDoorValues();
2076 game_gadget[SOUND_CTRL_ID_MUSIC]->checked = setup.sound_music;
2077 game_gadget[SOUND_CTRL_ID_LOOPS]->checked = setup.sound_loops;
2078 game_gadget[SOUND_CTRL_ID_SIMPLE]->checked = setup.sound_simple;
2082 /* copy actual game door content to door double buffer for OpenDoor() */
2083 BlitBitmap(drawto, bitmap_db_door,
2084 DX, DY, DXSIZE, DYSIZE, DOOR_GFX_PAGEX1, DOOR_GFX_PAGEY1);
2086 OpenDoor(DOOR_OPEN_ALL);
2088 PlaySoundStereo(SND_GAME_STARTING, SOUND_MIDDLE);
2090 if (setup.sound_music)
2093 KeyboardAutoRepeatOffUnlessAutoplay();
2097 for (i = 0; i < MAX_PLAYERS; i++)
2098 printf("Player %d %sactive.\n",
2099 i + 1, (stored_player[i].active ? "" : "not "));
2103 printf("::: starting game [%d]\n", FrameCounter);
2107 void InitMovDir(int x, int y)
2109 int i, element = Feld[x][y];
2110 static int xy[4][2] =
2117 static int direction[3][4] =
2119 { MV_RIGHT, MV_UP, MV_LEFT, MV_DOWN },
2120 { MV_LEFT, MV_DOWN, MV_RIGHT, MV_UP },
2121 { MV_LEFT, MV_RIGHT, MV_UP, MV_DOWN }
2130 Feld[x][y] = EL_BUG;
2131 MovDir[x][y] = direction[0][element - EL_BUG_RIGHT];
2134 case EL_SPACESHIP_RIGHT:
2135 case EL_SPACESHIP_UP:
2136 case EL_SPACESHIP_LEFT:
2137 case EL_SPACESHIP_DOWN:
2138 Feld[x][y] = EL_SPACESHIP;
2139 MovDir[x][y] = direction[0][element - EL_SPACESHIP_RIGHT];
2142 case EL_BD_BUTTERFLY_RIGHT:
2143 case EL_BD_BUTTERFLY_UP:
2144 case EL_BD_BUTTERFLY_LEFT:
2145 case EL_BD_BUTTERFLY_DOWN:
2146 Feld[x][y] = EL_BD_BUTTERFLY;
2147 MovDir[x][y] = direction[0][element - EL_BD_BUTTERFLY_RIGHT];
2150 case EL_BD_FIREFLY_RIGHT:
2151 case EL_BD_FIREFLY_UP:
2152 case EL_BD_FIREFLY_LEFT:
2153 case EL_BD_FIREFLY_DOWN:
2154 Feld[x][y] = EL_BD_FIREFLY;
2155 MovDir[x][y] = direction[0][element - EL_BD_FIREFLY_RIGHT];
2158 case EL_PACMAN_RIGHT:
2160 case EL_PACMAN_LEFT:
2161 case EL_PACMAN_DOWN:
2162 Feld[x][y] = EL_PACMAN;
2163 MovDir[x][y] = direction[0][element - EL_PACMAN_RIGHT];
2166 case EL_SP_SNIKSNAK:
2167 MovDir[x][y] = MV_UP;
2170 case EL_SP_ELECTRON:
2171 MovDir[x][y] = MV_LEFT;
2178 Feld[x][y] = EL_MOLE;
2179 MovDir[x][y] = direction[2][element - EL_MOLE_LEFT];
2183 if (IS_CUSTOM_ELEMENT(element))
2185 struct ElementInfo *ei = &element_info[element];
2186 int move_direction_initial = ei->move_direction_initial;
2187 int move_pattern = ei->move_pattern;
2189 if (move_direction_initial == MV_START_PREVIOUS)
2191 if (MovDir[x][y] != MV_NO_MOVING)
2194 move_direction_initial = MV_START_AUTOMATIC;
2197 if (move_direction_initial == MV_START_RANDOM)
2198 MovDir[x][y] = 1 << RND(4);
2199 else if (move_direction_initial & MV_ANY_DIRECTION)
2200 MovDir[x][y] = move_direction_initial;
2201 else if (move_pattern == MV_ALL_DIRECTIONS ||
2202 move_pattern == MV_TURNING_LEFT ||
2203 move_pattern == MV_TURNING_RIGHT ||
2204 move_pattern == MV_TURNING_LEFT_RIGHT ||
2205 move_pattern == MV_TURNING_RIGHT_LEFT ||
2206 move_pattern == MV_TURNING_RANDOM)
2207 MovDir[x][y] = 1 << RND(4);
2208 else if (move_pattern == MV_HORIZONTAL)
2209 MovDir[x][y] = (RND(2) ? MV_LEFT : MV_RIGHT);
2210 else if (move_pattern == MV_VERTICAL)
2211 MovDir[x][y] = (RND(2) ? MV_UP : MV_DOWN);
2212 else if (move_pattern & MV_ANY_DIRECTION)
2213 MovDir[x][y] = element_info[element].move_pattern;
2214 else if (move_pattern == MV_ALONG_LEFT_SIDE ||
2215 move_pattern == MV_ALONG_RIGHT_SIDE)
2218 /* use random direction as default start direction */
2219 if (game.engine_version >= VERSION_IDENT(3,1,0,0))
2220 MovDir[x][y] = 1 << RND(4);
2223 for (i = 0; i < NUM_DIRECTIONS; i++)
2225 int x1 = x + xy[i][0];
2226 int y1 = y + xy[i][1];
2228 if (!IN_LEV_FIELD(x1, y1) || !IS_FREE(x1, y1))
2230 if (move_pattern == MV_ALONG_RIGHT_SIDE)
2231 MovDir[x][y] = direction[0][i];
2233 MovDir[x][y] = direction[1][i];
2242 MovDir[x][y] = 1 << RND(4);
2244 if (element != EL_BUG &&
2245 element != EL_SPACESHIP &&
2246 element != EL_BD_BUTTERFLY &&
2247 element != EL_BD_FIREFLY)
2250 for (i = 0; i < NUM_DIRECTIONS; i++)
2252 int x1 = x + xy[i][0];
2253 int y1 = y + xy[i][1];
2255 if (!IN_LEV_FIELD(x1, y1) || !IS_FREE(x1, y1))
2257 if (element == EL_BUG || element == EL_BD_BUTTERFLY)
2259 MovDir[x][y] = direction[0][i];
2262 else if (element == EL_SPACESHIP || element == EL_BD_FIREFLY ||
2263 element == EL_SP_SNIKSNAK || element == EL_SP_ELECTRON)
2265 MovDir[x][y] = direction[1][i];
2274 GfxDir[x][y] = MovDir[x][y];
2277 void InitAmoebaNr(int x, int y)
2280 int group_nr = AmoebeNachbarNr(x, y);
2284 for (i = 1; i < MAX_NUM_AMOEBA; i++)
2286 if (AmoebaCnt[i] == 0)
2294 AmoebaNr[x][y] = group_nr;
2295 AmoebaCnt[group_nr]++;
2296 AmoebaCnt2[group_nr]++;
2302 boolean raise_level = FALSE;
2304 if (local_player->MovPos)
2308 if (tape.auto_play) /* tape might already be stopped here */
2309 tape.auto_play_level_solved = TRUE;
2311 if (tape.playing && tape.auto_play)
2312 tape.auto_play_level_solved = TRUE;
2315 local_player->LevelSolved = FALSE;
2317 PlaySoundStereo(SND_GAME_WINNING, SOUND_MIDDLE);
2321 if (!tape.playing && setup.sound_loops)
2322 PlaySoundExt(SND_GAME_LEVELTIME_BONUS, SOUND_MAX_VOLUME, SOUND_MIDDLE,
2323 SND_CTRL_PLAY_LOOP);
2325 while (TimeLeft > 0)
2327 if (!tape.playing && !setup.sound_loops)
2328 PlaySoundStereo(SND_GAME_LEVELTIME_BONUS, SOUND_MIDDLE);
2329 if (TimeLeft > 0 && !(TimeLeft % 10))
2330 RaiseScore(level.score[SC_TIME_BONUS]);
2331 if (TimeLeft > 100 && !(TimeLeft % 10))
2336 DrawGameValue_Time(TimeLeft);
2344 if (!tape.playing && setup.sound_loops)
2345 StopSound(SND_GAME_LEVELTIME_BONUS);
2347 else if (level.time == 0) /* level without time limit */
2349 if (!tape.playing && setup.sound_loops)
2350 PlaySoundExt(SND_GAME_LEVELTIME_BONUS, SOUND_MAX_VOLUME, SOUND_MIDDLE,
2351 SND_CTRL_PLAY_LOOP);
2353 while (TimePlayed < 999)
2355 if (!tape.playing && !setup.sound_loops)
2356 PlaySoundStereo(SND_GAME_LEVELTIME_BONUS, SOUND_MIDDLE);
2357 if (TimePlayed < 999 && !(TimePlayed % 10))
2358 RaiseScore(level.score[SC_TIME_BONUS]);
2359 if (TimePlayed < 900 && !(TimePlayed % 10))
2364 DrawGameValue_Time(TimePlayed);
2372 if (!tape.playing && setup.sound_loops)
2373 StopSound(SND_GAME_LEVELTIME_BONUS);
2376 /* close exit door after last player */
2377 if ((Feld[ExitX][ExitY] == EL_EXIT_OPEN ||
2378 Feld[ExitX][ExitY] == EL_SP_EXIT_OPEN) && AllPlayersGone)
2380 int element = Feld[ExitX][ExitY];
2382 Feld[ExitX][ExitY] = (element == EL_EXIT_OPEN ? EL_EXIT_CLOSING :
2383 EL_SP_EXIT_CLOSING);
2385 PlayLevelSoundElementAction(ExitX, ExitY, element, ACTION_CLOSING);
2388 /* Hero disappears */
2389 DrawLevelField(ExitX, ExitY);
2395 CloseDoor(DOOR_CLOSE_1);
2400 SaveTape(tape.level_nr); /* Ask to save tape */
2403 if (level_nr == leveldir_current->handicap_level)
2405 leveldir_current->handicap_level++;
2406 SaveLevelSetup_SeriesInfo();
2409 if (level_editor_test_game)
2410 local_player->score = -1; /* no highscore when playing from editor */
2411 else if (level_nr < leveldir_current->last_level)
2412 raise_level = TRUE; /* advance to next level */
2414 if ((hi_pos = NewHiScore()) >= 0)
2416 game_status = GAME_MODE_SCORES;
2417 DrawHallOfFame(hi_pos);
2426 game_status = GAME_MODE_MAIN;
2443 LoadScore(level_nr);
2445 if (strcmp(setup.player_name, EMPTY_PLAYER_NAME) == 0 ||
2446 local_player->score < highscore[MAX_SCORE_ENTRIES - 1].Score)
2449 for (k = 0; k < MAX_SCORE_ENTRIES; k++)
2451 if (local_player->score > highscore[k].Score)
2453 /* player has made it to the hall of fame */
2455 if (k < MAX_SCORE_ENTRIES - 1)
2457 int m = MAX_SCORE_ENTRIES - 1;
2460 for (l = k; l < MAX_SCORE_ENTRIES; l++)
2461 if (!strcmp(setup.player_name, highscore[l].Name))
2463 if (m == k) /* player's new highscore overwrites his old one */
2467 for (l = m; l > k; l--)
2469 strcpy(highscore[l].Name, highscore[l - 1].Name);
2470 highscore[l].Score = highscore[l - 1].Score;
2477 strncpy(highscore[k].Name, setup.player_name, MAX_PLAYER_NAME_LEN);
2478 highscore[k].Name[MAX_PLAYER_NAME_LEN] = '\0';
2479 highscore[k].Score = local_player->score;
2485 else if (!strncmp(setup.player_name, highscore[k].Name,
2486 MAX_PLAYER_NAME_LEN))
2487 break; /* player already there with a higher score */
2493 SaveScore(level_nr);
2498 void InitPlayerGfxAnimation(struct PlayerInfo *player, int action, int dir)
2500 if (player->GfxAction != action || player->GfxDir != dir)
2503 printf("Player frame reset! (%d => %d, %d => %d)\n",
2504 player->GfxAction, action, player->GfxDir, dir);
2507 player->GfxAction = action;
2508 player->GfxDir = dir;
2510 player->StepFrame = 0;
2514 static void ResetRandomAnimationValue(int x, int y)
2516 GfxRandom[x][y] = INIT_GFX_RANDOM();
2519 static void ResetGfxAnimation(int x, int y)
2522 GfxAction[x][y] = ACTION_DEFAULT;
2523 GfxDir[x][y] = MovDir[x][y];
2526 void InitMovingField(int x, int y, int direction)
2528 int element = Feld[x][y];
2529 int dx = (direction == MV_LEFT ? -1 : direction == MV_RIGHT ? +1 : 0);
2530 int dy = (direction == MV_UP ? -1 : direction == MV_DOWN ? +1 : 0);
2534 if (!WasJustMoving[x][y] || direction != MovDir[x][y])
2535 ResetGfxAnimation(x, y);
2537 MovDir[newx][newy] = MovDir[x][y] = direction;
2538 GfxDir[x][y] = direction;
2540 if (Feld[newx][newy] == EL_EMPTY)
2541 Feld[newx][newy] = EL_BLOCKED;
2543 if (direction == MV_DOWN && CAN_FALL(element))
2544 GfxAction[x][y] = ACTION_FALLING;
2546 GfxAction[x][y] = ACTION_MOVING;
2548 GfxFrame[newx][newy] = GfxFrame[x][y];
2549 GfxRandom[newx][newy] = GfxRandom[x][y];
2550 GfxAction[newx][newy] = GfxAction[x][y];
2551 GfxDir[newx][newy] = GfxDir[x][y];
2554 void Moving2Blocked(int x, int y, int *goes_to_x, int *goes_to_y)
2556 int direction = MovDir[x][y];
2557 int newx = x + (direction == MV_LEFT ? -1 : direction == MV_RIGHT ? +1 : 0);
2558 int newy = y + (direction == MV_UP ? -1 : direction == MV_DOWN ? +1 : 0);
2564 void Blocked2Moving(int x, int y, int *comes_from_x, int *comes_from_y)
2566 int oldx = x, oldy = y;
2567 int direction = MovDir[x][y];
2569 if (direction == MV_LEFT)
2571 else if (direction == MV_RIGHT)
2573 else if (direction == MV_UP)
2575 else if (direction == MV_DOWN)
2578 *comes_from_x = oldx;
2579 *comes_from_y = oldy;
2582 int MovingOrBlocked2Element(int x, int y)
2584 int element = Feld[x][y];
2586 if (element == EL_BLOCKED)
2590 Blocked2Moving(x, y, &oldx, &oldy);
2591 return Feld[oldx][oldy];
2597 static int MovingOrBlocked2ElementIfNotLeaving(int x, int y)
2599 /* like MovingOrBlocked2Element(), but if element is moving
2600 and (x,y) is the field the moving element is just leaving,
2601 return EL_BLOCKED instead of the element value */
2602 int element = Feld[x][y];
2604 if (IS_MOVING(x, y))
2606 if (element == EL_BLOCKED)
2610 Blocked2Moving(x, y, &oldx, &oldy);
2611 return Feld[oldx][oldy];
2620 static void RemoveField(int x, int y)
2622 Feld[x][y] = EL_EMPTY;
2629 ChangeDelay[x][y] = 0;
2630 ChangePage[x][y] = -1;
2631 Pushed[x][y] = FALSE;
2634 ExplodeField[x][y] = EX_TYPE_NONE;
2637 GfxElement[x][y] = EL_UNDEFINED;
2638 GfxAction[x][y] = ACTION_DEFAULT;
2639 GfxDir[x][y] = MV_NO_MOVING;
2642 void RemoveMovingField(int x, int y)
2644 int oldx = x, oldy = y, newx = x, newy = y;
2645 int element = Feld[x][y];
2646 int next_element = EL_UNDEFINED;
2648 if (element != EL_BLOCKED && !IS_MOVING(x, y))
2651 if (IS_MOVING(x, y))
2653 Moving2Blocked(x, y, &newx, &newy);
2655 if (Feld[newx][newy] != EL_BLOCKED)
2658 if (Feld[newx][newy] != EL_BLOCKED)
2660 /* element is moving, but target field is not free (blocked), but
2661 already occupied by something different (example: acid pool);
2662 in this case, only remove the moving field, but not the target */
2664 RemoveField(oldx, oldy);
2666 Store[oldx][oldy] = Store2[oldx][oldy] = 0;
2668 DrawLevelField(oldx, oldy);
2674 else if (element == EL_BLOCKED)
2676 Blocked2Moving(x, y, &oldx, &oldy);
2677 if (!IS_MOVING(oldx, oldy))
2681 if (element == EL_BLOCKED &&
2682 (Feld[oldx][oldy] == EL_QUICKSAND_EMPTYING ||
2683 Feld[oldx][oldy] == EL_MAGIC_WALL_EMPTYING ||
2684 Feld[oldx][oldy] == EL_BD_MAGIC_WALL_EMPTYING ||
2685 Feld[oldx][oldy] == EL_AMOEBA_DROPPING))
2686 next_element = get_next_element(Feld[oldx][oldy]);
2688 RemoveField(oldx, oldy);
2689 RemoveField(newx, newy);
2691 Store[oldx][oldy] = Store2[oldx][oldy] = 0;
2693 if (next_element != EL_UNDEFINED)
2694 Feld[oldx][oldy] = next_element;
2696 DrawLevelField(oldx, oldy);
2697 DrawLevelField(newx, newy);
2700 void DrawDynamite(int x, int y)
2702 int sx = SCREENX(x), sy = SCREENY(y);
2703 int graphic = el2img(Feld[x][y]);
2706 if (!IN_SCR_FIELD(sx, sy) || IS_PLAYER(x, y))
2709 if (IS_WALKABLE_INSIDE(Back[x][y]))
2713 DrawGraphic(sx, sy, el2img(Back[x][y]), 0);
2714 else if (Store[x][y])
2715 DrawGraphic(sx, sy, el2img(Store[x][y]), 0);
2717 frame = getGraphicAnimationFrame(graphic, GfxFrame[x][y]);
2720 if (Back[x][y] || Store[x][y])
2721 DrawGraphicThruMask(sx, sy, graphic, frame);
2723 DrawGraphic(sx, sy, graphic, frame);
2725 if (game.emulation == EMU_SUPAPLEX)
2726 DrawGraphic(sx, sy, IMG_SP_DISK_RED, frame);
2727 else if (Store[x][y])
2728 DrawGraphicThruMask(sx, sy, graphic, frame);
2730 DrawGraphic(sx, sy, graphic, frame);
2734 void CheckDynamite(int x, int y)
2736 if (MovDelay[x][y] != 0) /* dynamite is still waiting to explode */
2740 if (MovDelay[x][y] != 0)
2743 PlayLevelSoundActionIfLoop(x, y, ACTION_ACTIVE);
2750 StopLevelSoundActionIfLoop(x, y, ACTION_ACTIVE);
2752 if (Feld[x][y] == EL_DYNAMITE_ACTIVE ||
2753 Feld[x][y] == EL_SP_DISK_RED_ACTIVE)
2754 StopSound(SND_DYNAMITE_ACTIVE);
2756 StopSound(SND_DYNABOMB_ACTIVE);
2762 void DrawRelocatePlayer(struct PlayerInfo *player)
2764 boolean ffwd_delay = (tape.playing && tape.fast_forward);
2765 boolean no_delay = (tape.warp_forward);
2766 int frame_delay_value = (ffwd_delay ? FfwdFrameDelay : GameFrameDelay);
2767 int wait_delay_value = (no_delay ? 0 : frame_delay_value);
2768 int jx = player->jx;
2769 int jy = player->jy;
2771 if (level.instant_relocation)
2774 int offset = (setup.scroll_delay ? 3 : 0);
2776 if (!IN_VIS_FIELD(SCREENX(jx), SCREENY(jy)))
2778 scroll_x = (local_player->jx < SBX_Left + MIDPOSX ? SBX_Left :
2779 local_player->jx > SBX_Right + MIDPOSX ? SBX_Right :
2780 local_player->jx - MIDPOSX);
2782 scroll_y = (local_player->jy < SBY_Upper + MIDPOSY ? SBY_Upper :
2783 local_player->jy > SBY_Lower + MIDPOSY ? SBY_Lower :
2784 local_player->jy - MIDPOSY);
2788 if ((player->MovDir == MV_LEFT && scroll_x > jx - MIDPOSX + offset) ||
2789 (player->MovDir == MV_RIGHT && scroll_x < jx - MIDPOSX - offset))
2790 scroll_x = jx - MIDPOSX + (scroll_x < jx-MIDPOSX ? -offset : +offset);
2792 if ((player->MovDir == MV_UP && scroll_y > jy - MIDPOSY + offset) ||
2793 (player->MovDir == MV_DOWN && scroll_y < jy - MIDPOSY - offset))
2794 scroll_y = jy - MIDPOSY + (scroll_y < jy-MIDPOSY ? -offset : +offset);
2796 /* don't scroll over playfield boundaries */
2797 if (scroll_x < SBX_Left || scroll_x > SBX_Right)
2798 scroll_x = (scroll_x < SBX_Left ? SBX_Left : SBX_Right);
2800 /* don't scroll over playfield boundaries */
2801 if (scroll_y < SBY_Upper || scroll_y > SBY_Lower)
2802 scroll_y = (scroll_y < SBY_Upper ? SBY_Upper : SBY_Lower);
2805 scroll_x += (local_player->jx - old_jx);
2806 scroll_y += (local_player->jy - old_jy);
2808 /* don't scroll over playfield boundaries */
2809 if (scroll_x < SBX_Left || scroll_x > SBX_Right)
2810 scroll_x = (scroll_x < SBX_Left ? SBX_Left : SBX_Right);
2812 /* don't scroll over playfield boundaries */
2813 if (scroll_y < SBY_Upper || scroll_y > SBY_Lower)
2814 scroll_y = (scroll_y < SBY_Upper ? SBY_Upper : SBY_Lower);
2817 RedrawPlayfield(TRUE, 0,0,0,0);
2823 int offset = (setup.scroll_delay ? 3 : 0);
2825 int scroll_xx = -999, scroll_yy = -999;
2827 ScrollScreen(NULL, SCROLL_GO_ON); /* scroll last frame to full tile */
2829 while (scroll_xx != scroll_x || scroll_yy != scroll_y)
2832 int fx = FX, fy = FY;
2834 scroll_xx = (local_player->jx < SBX_Left + MIDPOSX ? SBX_Left :
2835 local_player->jx > SBX_Right + MIDPOSX ? SBX_Right :
2836 local_player->jx - MIDPOSX);
2838 scroll_yy = (local_player->jy < SBY_Upper + MIDPOSY ? SBY_Upper :
2839 local_player->jy > SBY_Lower + MIDPOSY ? SBY_Lower :
2840 local_player->jy - MIDPOSY);
2842 dx = (scroll_xx < scroll_x ? +1 : scroll_xx > scroll_x ? -1 : 0);
2843 dy = (scroll_yy < scroll_y ? +1 : scroll_yy > scroll_y ? -1 : 0);
2846 if (dx == 0 && dy == 0) /* no scrolling needed at all */
2849 if (scroll_xx == scroll_x && scroll_yy == scroll_y)
2856 fx += dx * TILEX / 2;
2857 fy += dy * TILEY / 2;
2859 ScrollLevel(dx, dy);
2862 /* scroll in two steps of half tile size to make things smoother */
2863 BlitBitmap(drawto_field, window, fx, fy, SXSIZE, SYSIZE, SX, SY);
2865 Delay(wait_delay_value);
2867 /* scroll second step to align at full tile size */
2869 Delay(wait_delay_value);
2872 int scroll_xx = -999, scroll_yy = -999;
2874 ScrollScreen(NULL, SCROLL_GO_ON); /* scroll last frame to full tile */
2876 while (scroll_xx != scroll_x || scroll_yy != scroll_y)
2879 int fx = FX, fy = FY;
2881 scroll_xx = (local_player->jx < SBX_Left + MIDPOSX ? SBX_Left :
2882 local_player->jx > SBX_Right + MIDPOSX ? SBX_Right :
2883 local_player->jx - MIDPOSX);
2885 scroll_yy = (local_player->jy < SBY_Upper + MIDPOSY ? SBY_Upper :
2886 local_player->jy > SBY_Lower + MIDPOSY ? SBY_Lower :
2887 local_player->jy - MIDPOSY);
2889 dx = (scroll_xx < scroll_x ? +1 : scroll_xx > scroll_x ? -1 : 0);
2890 dy = (scroll_yy < scroll_y ? +1 : scroll_yy > scroll_y ? -1 : 0);
2893 if (dx == 0 && dy == 0) /* no scrolling needed at all */
2896 if (scroll_xx == scroll_x && scroll_yy == scroll_y)
2903 fx += dx * TILEX / 2;
2904 fy += dy * TILEY / 2;
2906 ScrollLevel(dx, dy);
2909 /* scroll in two steps of half tile size to make things smoother */
2910 BlitBitmap(drawto_field, window, fx, fy, SXSIZE, SYSIZE, SX, SY);
2912 Delay(wait_delay_value);
2914 /* scroll second step to align at full tile size */
2916 Delay(wait_delay_value);
2922 Delay(wait_delay_value);
2926 void RelocatePlayer(int jx, int jy, int el_player_raw)
2929 int el_player = GET_VALID_PLAYER_ELEMENT(el_player_raw);
2931 int el_player = (el_player_raw == EL_SP_MURPHY ? EL_PLAYER_1 :el_player_raw);
2933 struct PlayerInfo *player = &stored_player[el_player - EL_PLAYER_1];
2934 boolean ffwd_delay = (tape.playing && tape.fast_forward);
2935 boolean no_delay = (tape.warp_forward);
2936 int frame_delay_value = (ffwd_delay ? FfwdFrameDelay : GameFrameDelay);
2937 int wait_delay_value = (no_delay ? 0 : frame_delay_value);
2938 int old_jx = player->jx;
2939 int old_jy = player->jy;
2940 int old_element = Feld[old_jx][old_jy];
2941 int element = Feld[jx][jy];
2942 boolean player_relocated = (old_jx != jx || old_jy != jy);
2944 int move_dir_horiz = (jx < old_jx ? MV_LEFT : jx > old_jx ? MV_RIGHT : 0);
2945 int move_dir_vert = (jy < old_jy ? MV_UP : jy > old_jy ? MV_DOWN : 0);
2947 int enter_side_horiz = MV_DIR_OPPOSITE(move_dir_horiz);
2948 int enter_side_vert = MV_DIR_OPPOSITE(move_dir_vert);
2949 int leave_side_horiz = move_dir_horiz;
2950 int leave_side_vert = move_dir_vert;
2952 static int trigger_sides[4][2] =
2954 /* enter side leave side */
2955 { CH_SIDE_RIGHT, CH_SIDE_LEFT }, /* moving left */
2956 { CH_SIDE_LEFT, CH_SIDE_RIGHT }, /* moving right */
2957 { CH_SIDE_BOTTOM, CH_SIDE_TOP }, /* moving up */
2958 { CH_SIDE_TOP, CH_SIDE_BOTTOM } /* moving down */
2960 int enter_side_horiz = trigger_sides[MV_DIR_BIT(move_dir_horiz)][0];
2961 int enter_side_vert = trigger_sides[MV_DIR_BIT(move_dir_vert)][0];
2962 int leave_side_horiz = trigger_sides[MV_DIR_BIT(move_dir_horiz)][1];
2963 int leave_side_vert = trigger_sides[MV_DIR_BIT(move_dir_vert)][1];
2965 int enter_side = enter_side_horiz | enter_side_vert;
2966 int leave_side = leave_side_horiz | leave_side_vert;
2968 if (player->GameOver) /* do not reanimate dead player */
2971 if (!player_relocated) /* no need to relocate the player */
2974 if (IS_PLAYER(jx, jy)) /* player already placed at new position */
2976 RemoveField(jx, jy); /* temporarily remove newly placed player */
2977 DrawLevelField(jx, jy);
2980 if (player->present)
2982 while (player->MovPos)
2984 ScrollPlayer(player, SCROLL_GO_ON);
2985 ScrollScreen(NULL, SCROLL_GO_ON);
2987 #if USE_NEW_MOVE_DELAY
2988 AdvanceFrameAndPlayerCounters(player->index_nr);
2996 Delay(wait_delay_value);
2999 DrawPlayer(player); /* needed here only to cleanup last field */
3000 DrawLevelField(player->jx, player->jy); /* remove player graphic */
3002 player->is_moving = FALSE;
3006 if (IS_CUSTOM_ELEMENT(old_element))
3007 CheckElementChangeByPlayer(old_jx, old_jy, old_element,
3009 player->index_bit, leave_side);
3011 CheckTriggeredElementChangeByPlayer(old_jx, old_jy, old_element,
3013 player->index_bit, leave_side);
3016 Feld[jx][jy] = el_player;
3017 InitPlayerField(jx, jy, el_player, TRUE);
3019 if (!ELEM_IS_PLAYER(element)) /* player may be set on walkable element */
3021 Feld[jx][jy] = element;
3022 InitField(jx, jy, FALSE);
3026 if (player == local_player) /* only visually relocate local player */
3027 DrawRelocatePlayer(player);
3031 TestIfHeroTouchesBadThing(jx, jy);
3032 TestIfPlayerTouchesCustomElement(jx, jy);
3036 printf("::: %d,%d: %d\n", jx, jy-1, Changed[jx][jy-1]);
3041 /* needed to allow change of walkable custom element by entering player */
3042 if (!(Changed[jx][jy] & CH_EVENT_BIT(CE_ENTERED_BY_PLAYER)))
3043 Changed[jx][jy] = 0; /* allow another change (but prevent loop) */
3045 /* needed to allow change of walkable custom element by entering player */
3046 Changed[jx][jy] = 0; /* allow another change */
3051 printf("::: player entering %d, %d from %s ...\n", jx, jy,
3052 enter_side == MV_LEFT ? "left" :
3053 enter_side == MV_RIGHT ? "right" :
3054 enter_side == MV_UP ? "top" :
3055 enter_side == MV_DOWN ? "bottom" : "oops! no idea!");
3059 if (IS_CUSTOM_ELEMENT(element))
3060 CheckElementChangeByPlayer(jx, jy, element, CE_ENTERED_BY_PLAYER,
3061 player->index_bit, enter_side);
3063 CheckTriggeredElementChangeByPlayer(jx, jy, element,
3064 CE_OTHER_GETS_ENTERED,
3065 player->index_bit, enter_side);
3069 void Explode(int ex, int ey, int phase, int mode)
3076 /* !!! eliminate this variable !!! */
3077 int delay = (game.emulation == EMU_SUPAPLEX ? 3 : 2);
3082 int last_phase = num_phase * delay;
3083 int half_phase = (num_phase / 2) * delay;
3084 int first_phase_after_start = EX_PHASE_START + 1;
3088 if (game.explosions_delayed)
3090 ExplodeField[ex][ey] = mode;
3094 if (phase == EX_PHASE_START) /* initialize 'Store[][]' field */
3096 int center_element = Feld[ex][ey];
3099 printf("::: start explosion %d,%d [%d]\n", ex, ey, FrameCounter);
3103 /* --- This is only really needed (and now handled) in "Impact()". --- */
3104 /* do not explode moving elements that left the explode field in time */
3105 if (game.engine_version >= VERSION_IDENT(2,2,0,7) &&
3106 center_element == EL_EMPTY &&
3107 (mode == EX_TYPE_NORMAL || mode == EX_TYPE_CENTER))
3111 if (mode == EX_TYPE_NORMAL || mode == EX_TYPE_CENTER)
3112 PlayLevelSoundAction(ex, ey, ACTION_EXPLODING);
3114 /* remove things displayed in background while burning dynamite */
3115 if (Back[ex][ey] != EL_EMPTY && !IS_INDESTRUCTIBLE(Back[ex][ey]))
3118 if (IS_MOVING(ex, ey) || IS_BLOCKED(ex, ey))
3120 /* put moving element to center field (and let it explode there) */
3121 center_element = MovingOrBlocked2Element(ex, ey);
3122 RemoveMovingField(ex, ey);
3123 Feld[ex][ey] = center_element;
3129 last_phase = element_info[center_element].explosion_delay + 1;
3131 last_phase = element_info[center_element].explosion_delay;
3135 printf("::: %d -> %d\n", center_element, last_phase);
3139 for (y = ey - 1; y <= ey + 1; y++) for (x = ex - 1; x <= ex + 1; x++)
3141 int xx = x - ex + 1;
3142 int yy = y - ey + 1;
3147 if (!IN_LEV_FIELD(x, y) ||
3148 (mode & EX_TYPE_SINGLE_TILE && (x != ex || y != ey)) ||
3149 (mode == EX_TYPE_CROSS && (x != ex && y != ey)))
3152 if (!IN_LEV_FIELD(x, y) ||
3153 (mode != EX_TYPE_NORMAL && (x != ex || y != ey)))
3157 if (!IN_LEV_FIELD(x, y) ||
3158 ((mode != EX_TYPE_NORMAL ||
3159 center_element == EL_AMOEBA_TO_DIAMOND) &&
3160 (x != ex || y != ey)))
3164 element = Feld[x][y];
3166 if (IS_MOVING(x, y) || IS_BLOCKED(x, y))
3168 element = MovingOrBlocked2Element(x, y);
3170 if (!IS_EXPLOSION_PROOF(element))
3171 RemoveMovingField(x, y);
3177 if (IS_EXPLOSION_PROOF(element))
3180 /* indestructible elements can only explode in center (but not flames) */
3182 if ((IS_EXPLOSION_PROOF(element) && (x != ex || y != ey ||
3183 mode == EX_TYPE_BORDER)) ||
3184 element == EL_FLAMES)
3187 if ((IS_EXPLOSION_PROOF(element) && (x != ex || y != ey)) ||
3188 element == EL_FLAMES)
3194 if ((IS_INDESTRUCTIBLE(element) &&
3195 (game.engine_version < VERSION_IDENT(2,2,0,0) ||
3196 (!IS_WALKABLE_OVER(element) && !IS_WALKABLE_UNDER(element)))) ||
3197 element == EL_FLAMES)
3202 if (IS_PLAYER(x, y) && SHIELD_ON(PLAYERINFO(x, y)) &&
3203 (game.engine_version < VERSION_IDENT(3,1,0,0) ||
3204 (x == ex && y == ey && mode != EX_TYPE_BORDER)))
3206 if (IS_PLAYER(x, y) && SHIELD_ON(PLAYERINFO(x, y)))
3209 if (IS_ACTIVE_BOMB(element))
3211 /* re-activate things under the bomb like gate or penguin */
3213 Feld[x][y] = (Back[x][y] ? Back[x][y] : EL_EMPTY);
3216 Feld[x][y] = (Store[x][y] ? Store[x][y] : EL_EMPTY);
3221 printf("::: %d,%d: %d %s [%d, %d]\n", x, y, Feld[x][y],
3222 element_info[Feld[x][y]].token_name,
3223 Store[x][y], Store2[x][y]);
3230 /* save walkable background elements while explosion on same tile */
3232 if (IS_INDESTRUCTIBLE(element))
3233 Back[x][y] = element;
3237 if (IS_WALKABLE(element) && IS_INDESTRUCTIBLE(element) &&
3238 (x != ex || y != ey || mode == EX_TYPE_BORDER))
3239 Back[x][y] = element;
3241 if (IS_WALKABLE(element) && IS_INDESTRUCTIBLE(element) &&
3242 (x != ex || y != ey))
3243 Back[x][y] = element;
3246 if (IS_WALKABLE(element) && IS_INDESTRUCTIBLE(element))
3247 Back[x][y] = element;
3251 /* ignite explodable elements reached by other explosion */
3252 if (element == EL_EXPLOSION)
3253 element = Store2[x][y];
3256 if (AmoebaNr[x][y] &&
3257 (element == EL_AMOEBA_FULL ||
3258 element == EL_BD_AMOEBA ||
3259 element == EL_AMOEBA_GROWING))
3261 AmoebaCnt[AmoebaNr[x][y]]--;
3262 AmoebaCnt2[AmoebaNr[x][y]]--;
3268 if (IS_PLAYER(ex, ey) && !PLAYER_EXPLOSION_PROTECTED(ex, ey))
3270 switch(StorePlayer[ex][ey])
3273 Store[x][y] = EL_PLAYER_IS_EXPLODING_2;
3276 Store[x][y] = EL_PLAYER_IS_EXPLODING_3;
3279 Store[x][y] = EL_PLAYER_IS_EXPLODING_4;
3283 Store[x][y] = EL_PLAYER_IS_EXPLODING_1;
3288 if (PLAYERINFO(ex, ey)->use_murphy_graphic)
3289 Store[x][y] = EL_EMPTY;
3291 if (game.emulation == EMU_SUPAPLEX)
3292 Store[x][y] = EL_EMPTY;
3295 else if (center_element == EL_MOLE)
3296 Store[x][y] = EL_EMERALD_RED;
3297 else if (center_element == EL_PENGUIN)
3298 Store[x][y] = EL_EMERALD_PURPLE;
3299 else if (center_element == EL_BUG)
3300 Store[x][y] = ((x == ex && y == ey) ? EL_DIAMOND : EL_EMERALD);
3301 else if (center_element == EL_BD_BUTTERFLY)
3302 Store[x][y] = EL_BD_DIAMOND;
3303 else if (center_element == EL_SP_ELECTRON)
3304 Store[x][y] = EL_SP_INFOTRON;
3305 else if (center_element == EL_AMOEBA_TO_DIAMOND)
3306 Store[x][y] = level.amoeba_content;
3307 else if (center_element == EL_YAMYAM)
3308 Store[x][y] = level.yamyam_content[game.yamyam_content_nr][xx][yy];
3309 else if (IS_CUSTOM_ELEMENT(center_element) &&
3310 element_info[center_element].content[xx][yy] != EL_EMPTY)
3311 Store[x][y] = element_info[center_element].content[xx][yy];
3312 else if (element == EL_WALL_EMERALD)
3313 Store[x][y] = EL_EMERALD;
3314 else if (element == EL_WALL_DIAMOND)
3315 Store[x][y] = EL_DIAMOND;
3316 else if (element == EL_WALL_BD_DIAMOND)
3317 Store[x][y] = EL_BD_DIAMOND;
3318 else if (element == EL_WALL_EMERALD_YELLOW)
3319 Store[x][y] = EL_EMERALD_YELLOW;
3320 else if (element == EL_WALL_EMERALD_RED)
3321 Store[x][y] = EL_EMERALD_RED;
3322 else if (element == EL_WALL_EMERALD_PURPLE)
3323 Store[x][y] = EL_EMERALD_PURPLE;
3324 else if (element == EL_WALL_PEARL)
3325 Store[x][y] = EL_PEARL;
3326 else if (element == EL_WALL_CRYSTAL)
3327 Store[x][y] = EL_CRYSTAL;
3328 else if (IS_CUSTOM_ELEMENT(element) && !CAN_EXPLODE(element))
3329 Store[x][y] = element_info[element].content[1][1];
3331 Store[x][y] = EL_EMPTY;
3333 if (x != ex || y != ey || mode == EX_TYPE_BORDER ||
3334 center_element == EL_AMOEBA_TO_DIAMOND)
3335 Store2[x][y] = element;
3338 printf("::: %d,%d: %d %s\n", x, y, Store2[x][y],
3339 element_info[Store2[x][y]].token_name);
3343 if (AmoebaNr[x][y] &&
3344 (element == EL_AMOEBA_FULL ||
3345 element == EL_BD_AMOEBA ||
3346 element == EL_AMOEBA_GROWING))
3348 AmoebaCnt[AmoebaNr[x][y]]--;
3349 AmoebaCnt2[AmoebaNr[x][y]]--;
3355 MovDir[x][y] = MovPos[x][y] = 0;
3356 GfxDir[x][y] = MovDir[x][y];
3361 Feld[x][y] = EL_EXPLOSION;
3363 GfxElement[x][y] = center_element;
3365 GfxElement[x][y] = EL_UNDEFINED;
3368 ExplodePhase[x][y] = 1;
3370 ExplodeDelay[x][y] = last_phase;
3375 GfxFrame[x][y] = 0; /* animation does not start until next frame */
3377 GfxFrame[x][y] = -1; /* animation does not start until next frame */
3384 if (center_element == EL_YAMYAM)
3385 game.yamyam_content_nr =
3386 (game.yamyam_content_nr + 1) % level.num_yamyam_contents;
3389 printf("::: %d,%d: %d %s [%d]\n", ex + 1, ey, Feld[ex + 1][ey],
3390 element_info[Feld[ex + 1][ey]].token_name, Store2[ex + 1][ey]);
3404 GfxFrame[x][y] = 0; /* restart explosion animation */
3408 printf(":X: phase == %d [%d]\n", phase, GfxFrame[x][y]);
3412 last_phase = ExplodeDelay[x][y];
3415 ExplodePhase[x][y] = (phase < last_phase ? phase + 1 : 0);
3419 /* activate this even in non-DEBUG version until cause for crash in
3420 getGraphicAnimationFrame() (see below) is found and eliminated */
3424 if (GfxElement[x][y] == EL_UNDEFINED)
3427 printf("Explode(): x = %d, y = %d: GfxElement == EL_UNDEFINED\n", x, y);
3428 printf("Explode(): This should never happen!\n");
3431 GfxElement[x][y] = EL_EMPTY;
3437 border_element = Store2[x][y];
3439 if (IS_PLAYER(x, y) && !PLAYER_EXPLOSION_PROTECTED(x, y))
3440 border_element = StorePlayer[x][y];
3442 if (IS_PLAYER(x, y))
3443 border_element = StorePlayer[x][y];
3447 printf("::: %d,%d: %d %s [%d]\n", x, y, border_element,
3448 element_info[border_element].token_name, Store2[x][y]);
3452 printf("::: phase == %d\n", phase);
3455 if (phase == element_info[border_element].ignition_delay ||
3456 phase == last_phase)
3458 boolean border_explosion = FALSE;
3462 if (IS_PLAYER(x, y) && PLAYERINFO(x, y)->present &&
3463 !PLAYER_EXPLOSION_PROTECTED(x, y))
3465 if (IS_PLAYER(x, y) && PLAYERINFO(x, y)->present)
3468 if (IS_PLAYER(x, y))
3471 KillHeroUnlessExplosionProtected(x, y);
3472 border_explosion = TRUE;
3475 if (phase == last_phase)
3476 printf("::: IS_PLAYER\n");
3479 else if (CAN_EXPLODE_BY_EXPLOSION(border_element))
3482 printf("::: %d,%d: %d %s\n", x, y, border_element,
3483 element_info[border_element].token_name);
3486 Feld[x][y] = Store2[x][y];
3489 border_explosion = TRUE;
3492 if (phase == last_phase)
3493 printf("::: CAN_EXPLODE_BY_EXPLOSION\n");
3496 else if (border_element == EL_AMOEBA_TO_DIAMOND)
3498 AmoebeUmwandeln(x, y);
3500 border_explosion = TRUE;
3503 if (phase == last_phase)
3504 printf("::: EL_AMOEBA_TO_DIAMOND [%d, %d] [%d]\n",
3505 element_info[border_element].explosion_delay,
3506 element_info[border_element].ignition_delay,
3512 /* if an element just explodes due to another explosion (chain-reaction),
3513 do not immediately end the new explosion when it was the last frame of
3514 the explosion (as it would be done in the following "if"-statement!) */
3515 if (border_explosion && phase == last_phase)
3522 if (phase == first_phase_after_start)
3524 int element = Store2[x][y];
3526 if (element == EL_BLACK_ORB)
3528 Feld[x][y] = Store2[x][y];
3533 else if (phase == half_phase)
3535 int element = Store2[x][y];
3537 if (IS_PLAYER(x, y))
3538 KillHeroUnlessExplosionProtected(x, y);
3539 else if (CAN_EXPLODE_BY_EXPLOSION(element))
3541 Feld[x][y] = Store2[x][y];
3545 else if (element == EL_AMOEBA_TO_DIAMOND)
3546 AmoebeUmwandeln(x, y);
3550 if (phase == last_phase)
3555 printf("::: done: phase == %d\n", phase);
3559 printf("::: explosion %d,%d done [%d]\n", x, y, FrameCounter);
3562 element = Feld[x][y] = Store[x][y];
3563 Store[x][y] = Store2[x][y] = 0;
3564 GfxElement[x][y] = EL_UNDEFINED;
3566 /* player can escape from explosions and might therefore be still alive */
3567 if (element >= EL_PLAYER_IS_EXPLODING_1 &&
3568 element <= EL_PLAYER_IS_EXPLODING_4)
3569 Feld[x][y] = (stored_player[element - EL_PLAYER_IS_EXPLODING_1].active ?
3571 element == EL_PLAYER_IS_EXPLODING_1 ? EL_EMERALD_YELLOW :
3572 element == EL_PLAYER_IS_EXPLODING_2 ? EL_EMERALD_RED :
3573 element == EL_PLAYER_IS_EXPLODING_3 ? EL_EMERALD :
3576 /* restore probably existing indestructible background element */
3577 if (Back[x][y] && IS_INDESTRUCTIBLE(Back[x][y]))
3578 element = Feld[x][y] = Back[x][y];
3581 MovDir[x][y] = MovPos[x][y] = MovDelay[x][y] = 0;
3582 GfxDir[x][y] = MV_NO_MOVING;
3583 ChangeDelay[x][y] = 0;
3584 ChangePage[x][y] = -1;
3587 InitField_WithBug2(x, y, FALSE);
3589 InitField(x, y, FALSE);
3591 /* !!! not needed !!! */
3593 if (game.engine_version < VERSION_IDENT(3,1,0,0) &&
3594 CAN_MOVE(Feld[x][y]) && Feld[x][y] != EL_MOLE)
3597 if (CAN_MOVE(element))
3602 DrawLevelField(x, y);
3604 TestIfElementTouchesCustomElement(x, y);
3606 if (GFX_CRUMBLED(element))
3607 DrawLevelFieldCrumbledSandNeighbours(x, y);
3609 if (IS_PLAYER(x, y) && !PLAYERINFO(x, y)->present)
3610 StorePlayer[x][y] = 0;
3612 if (ELEM_IS_PLAYER(element))
3613 RelocatePlayer(x, y, element);
3616 else if (IN_SCR_FIELD(SCREENX(x), SCREENY(y)))
3618 else if (phase >= delay && IN_SCR_FIELD(SCREENX(x), SCREENY(y)))
3622 int graphic = el_act2img(GfxElement[x][y], ACTION_EXPLODING);
3624 int stored = Store[x][y];
3625 int graphic = (game.emulation != EMU_SUPAPLEX ? IMG_EXPLOSION :
3626 stored == EL_SP_INFOTRON ? IMG_SP_EXPLOSION_INFOTRON :
3630 int frame = getGraphicAnimationFrame(graphic, GfxFrame[x][y]);
3632 int frame = getGraphicAnimationFrame(graphic, phase - delay);
3636 printf("::: phase == %d [%d]\n", phase, GfxFrame[x][y]);
3640 printf("::: %d / %d [%d - %d]\n",
3641 GfxFrame[x][y], phase - delay, phase, delay);
3645 printf("::: %d ['%s'] -> %d\n", GfxElement[x][y],
3646 element_info[GfxElement[x][y]].token_name,
3651 DrawLevelFieldCrumbledSand(x, y);
3653 if (IS_WALKABLE_OVER(Back[x][y]) && Back[x][y] != EL_EMPTY)
3655 DrawLevelElement(x, y, Back[x][y]);
3656 DrawGraphicThruMask(SCREENX(x), SCREENY(y), graphic, frame);
3658 else if (IS_WALKABLE_UNDER(Back[x][y]))
3660 DrawGraphic(SCREENX(x), SCREENY(y), graphic, frame);
3661 DrawLevelElementThruMask(x, y, Back[x][y]);
3663 else if (!IS_WALKABLE_INSIDE(Back[x][y]))
3664 DrawGraphic(SCREENX(x), SCREENY(y), graphic, frame);
3668 void DynaExplode(int ex, int ey)
3671 int dynabomb_element = Feld[ex][ey];
3672 int dynabomb_size = 1;
3673 boolean dynabomb_xl = FALSE;
3674 struct PlayerInfo *player;
3675 static int xy[4][2] =
3683 if (IS_ACTIVE_BOMB(dynabomb_element))
3685 player = &stored_player[dynabomb_element - EL_DYNABOMB_PLAYER_1_ACTIVE];
3686 dynabomb_size = player->dynabomb_size;
3687 dynabomb_xl = player->dynabomb_xl;
3688 player->dynabombs_left++;
3691 Explode(ex, ey, EX_PHASE_START, EX_TYPE_CENTER);
3693 for (i = 0; i < NUM_DIRECTIONS; i++)
3695 for (j = 1; j <= dynabomb_size; j++)
3697 int x = ex + j * xy[i][0];
3698 int y = ey + j * xy[i][1];
3701 if (!IN_LEV_FIELD(x, y) || IS_INDESTRUCTIBLE(Feld[x][y]))
3704 element = Feld[x][y];
3706 /* do not restart explosions of fields with active bombs */
3707 if (element == EL_EXPLOSION && IS_ACTIVE_BOMB(Store2[x][y]))
3710 Explode(x, y, EX_PHASE_START, EX_TYPE_BORDER);
3714 if (element != EL_EMPTY && element != EL_EXPLOSION &&
3715 !IS_DIGGABLE(element) && !dynabomb_xl)
3718 if (element != EL_EMPTY && element != EL_EXPLOSION &&
3719 !CAN_GROW_INTO(element) && !dynabomb_xl)
3723 /* !!! extend EL_SAND to anything diggable (but maybe not SP_BASE) !!! */
3724 if (element != EL_EMPTY && element != EL_EXPLOSION &&
3725 element != EL_SAND && !dynabomb_xl)
3732 void Bang(int x, int y)
3735 int element = MovingOrBlocked2Element(x, y);
3737 int element = Feld[x][y];
3741 if (IS_PLAYER(x, y) && !PLAYER_EXPLOSION_PROTECTED(x, y))
3743 if (IS_PLAYER(x, y))
3746 struct PlayerInfo *player = PLAYERINFO(x, y);
3748 element = Feld[x][y] = (player->use_murphy_graphic ? EL_SP_MURPHY :
3749 player->element_nr);
3754 PlayLevelSoundAction(x, y, ACTION_EXPLODING);
3756 if (game.emulation == EMU_SUPAPLEX)
3757 PlayLevelSound(x, y, SND_SP_ELEMENT_EXPLODING);
3759 PlayLevelSound(x, y, SND_ELEMENT_EXPLODING);
3764 if (IS_PLAYER(x, y)) /* remove objects that might cause smaller explosion */
3772 case EL_BD_BUTTERFLY:
3775 case EL_DARK_YAMYAM:
3779 RaiseScoreElement(element);
3780 Explode(x, y, EX_PHASE_START, EX_TYPE_NORMAL);
3782 case EL_DYNABOMB_PLAYER_1_ACTIVE:
3783 case EL_DYNABOMB_PLAYER_2_ACTIVE:
3784 case EL_DYNABOMB_PLAYER_3_ACTIVE:
3785 case EL_DYNABOMB_PLAYER_4_ACTIVE:
3786 case EL_DYNABOMB_INCREASE_NUMBER:
3787 case EL_DYNABOMB_INCREASE_SIZE:
3788 case EL_DYNABOMB_INCREASE_POWER:
3793 case EL_LAMP_ACTIVE:
3795 case EL_AMOEBA_TO_DIAMOND:
3797 if (IS_PLAYER(x, y))
3798 Explode(x, y, EX_PHASE_START, EX_TYPE_NORMAL);
3800 Explode(x, y, EX_PHASE_START, EX_TYPE_CENTER);
3804 if (element_info[element].explosion_type == EXPLODES_CROSS)
3806 if (CAN_EXPLODE_CROSS(element))
3809 Explode(x, y, EX_PHASE_START, EX_TYPE_CROSS);
3814 else if (element_info[element].explosion_type == EXPLODES_1X1)
3816 else if (CAN_EXPLODE_1X1(element))
3818 Explode(x, y, EX_PHASE_START, EX_TYPE_CENTER);
3820 Explode(x, y, EX_PHASE_START, EX_TYPE_NORMAL);
3824 CheckTriggeredElementChange(x, y, element, CE_OTHER_IS_EXPLODING);
3827 void SplashAcid(int x, int y)
3830 if (IN_LEV_FIELD(x - 1, y - 1) && IS_FREE(x - 1, y - 1) &&
3831 (!IN_LEV_FIELD(x - 1, y - 2) ||
3832 !CAN_FALL(MovingOrBlocked2Element(x - 1, y - 2))))
3833 Feld[x - 1][y - 1] = EL_ACID_SPLASH_LEFT;
3835 if (IN_LEV_FIELD(x + 1, y - 1) && IS_FREE(x + 1, y - 1) &&
3836 (!IN_LEV_FIELD(x + 1, y - 2) ||
3837 !CAN_FALL(MovingOrBlocked2Element(x + 1, y - 2))))
3838 Feld[x + 1][y - 1] = EL_ACID_SPLASH_RIGHT;
3840 PlayLevelSound(x, y, SND_ACID_SPLASHING);
3842 /* input: position of element entering acid (obsolete) */
3844 int element = Feld[x][y];
3846 if (!IN_LEV_FIELD(x, y + 1) || Feld[x][y + 1] != EL_ACID)
3849 if (element != EL_ACID_SPLASH_LEFT &&
3850 element != EL_ACID_SPLASH_RIGHT)
3852 PlayLevelSound(x, y, SND_ACID_SPLASHING);
3854 if (IN_LEV_FIELD(x - 1, y) && IS_FREE(x - 1, y) &&
3855 (!IN_LEV_FIELD(x - 1, y - 1) ||
3856 !CAN_FALL(MovingOrBlocked2Element(x - 1, y - 1))))
3857 Feld[x - 1][y] = EL_ACID_SPLASH_LEFT;
3859 if (IN_LEV_FIELD(x + 1, y) && IS_FREE(x + 1, y) &&
3860 (!IN_LEV_FIELD(x + 1, y - 1) ||
3861 !CAN_FALL(MovingOrBlocked2Element(x + 1, y - 1))))
3862 Feld[x + 1][y] = EL_ACID_SPLASH_RIGHT;
3867 static void InitBeltMovement()
3869 static int belt_base_element[4] =
3871 EL_CONVEYOR_BELT_1_LEFT,
3872 EL_CONVEYOR_BELT_2_LEFT,
3873 EL_CONVEYOR_BELT_3_LEFT,
3874 EL_CONVEYOR_BELT_4_LEFT
3876 static int belt_base_active_element[4] =
3878 EL_CONVEYOR_BELT_1_LEFT_ACTIVE,
3879 EL_CONVEYOR_BELT_2_LEFT_ACTIVE,
3880 EL_CONVEYOR_BELT_3_LEFT_ACTIVE,
3881 EL_CONVEYOR_BELT_4_LEFT_ACTIVE
3886 /* set frame order for belt animation graphic according to belt direction */
3887 for (i = 0; i < NUM_BELTS; i++)
3891 for (j = 0; j < NUM_BELT_PARTS; j++)
3893 int element = belt_base_active_element[belt_nr] + j;
3894 int graphic = el2img(element);
3896 if (game.belt_dir[i] == MV_LEFT)
3897 graphic_info[graphic].anim_mode &= ~ANIM_REVERSE;
3899 graphic_info[graphic].anim_mode |= ANIM_REVERSE;
3903 for (y = 0; y < lev_fieldy; y++)
3905 for (x = 0; x < lev_fieldx; x++)
3907 int element = Feld[x][y];
3909 for (i = 0; i < NUM_BELTS; i++)
3911 if (IS_BELT(element) && game.belt_dir[i] != MV_NO_MOVING)
3913 int e_belt_nr = getBeltNrFromBeltElement(element);
3916 if (e_belt_nr == belt_nr)
3918 int belt_part = Feld[x][y] - belt_base_element[belt_nr];
3920 Feld[x][y] = belt_base_active_element[belt_nr] + belt_part;
3928 static void ToggleBeltSwitch(int x, int y)
3930 static int belt_base_element[4] =
3932 EL_CONVEYOR_BELT_1_LEFT,
3933 EL_CONVEYOR_BELT_2_LEFT,
3934 EL_CONVEYOR_BELT_3_LEFT,
3935 EL_CONVEYOR_BELT_4_LEFT
3937 static int belt_base_active_element[4] =
3939 EL_CONVEYOR_BELT_1_LEFT_ACTIVE,
3940 EL_CONVEYOR_BELT_2_LEFT_ACTIVE,
3941 EL_CONVEYOR_BELT_3_LEFT_ACTIVE,
3942 EL_CONVEYOR_BELT_4_LEFT_ACTIVE
3944 static int belt_base_switch_element[4] =
3946 EL_CONVEYOR_BELT_1_SWITCH_LEFT,
3947 EL_CONVEYOR_BELT_2_SWITCH_LEFT,
3948 EL_CONVEYOR_BELT_3_SWITCH_LEFT,
3949 EL_CONVEYOR_BELT_4_SWITCH_LEFT
3951 static int belt_move_dir[4] =
3959 int element = Feld[x][y];
3960 int belt_nr = getBeltNrFromBeltSwitchElement(element);
3961 int belt_dir_nr = (game.belt_dir_nr[belt_nr] + 1) % 4;
3962 int belt_dir = belt_move_dir[belt_dir_nr];
3965 if (!IS_BELT_SWITCH(element))
3968 game.belt_dir_nr[belt_nr] = belt_dir_nr;
3969 game.belt_dir[belt_nr] = belt_dir;
3971 if (belt_dir_nr == 3)
3974 /* set frame order for belt animation graphic according to belt direction */
3975 for (i = 0; i < NUM_BELT_PARTS; i++)
3977 int element = belt_base_active_element[belt_nr] + i;
3978 int graphic = el2img(element);
3980 if (belt_dir == MV_LEFT)
3981 graphic_info[graphic].anim_mode &= ~ANIM_REVERSE;
3983 graphic_info[graphic].anim_mode |= ANIM_REVERSE;
3986 for (yy = 0; yy < lev_fieldy; yy++)
3988 for (xx = 0; xx < lev_fieldx; xx++)
3990 int element = Feld[xx][yy];
3992 if (IS_BELT_SWITCH(element))
3994 int e_belt_nr = getBeltNrFromBeltSwitchElement(element);
3996 if (e_belt_nr == belt_nr)
3998 Feld[xx][yy] = belt_base_switch_element[belt_nr] + belt_dir_nr;
3999 DrawLevelField(xx, yy);
4002 else if (IS_BELT(element) && belt_dir != MV_NO_MOVING)
4004 int e_belt_nr = getBeltNrFromBeltElement(element);
4006 if (e_belt_nr == belt_nr)
4008 int belt_part = Feld[xx][yy] - belt_base_element[belt_nr];
4010 Feld[xx][yy] = belt_base_active_element[belt_nr] + belt_part;
4011 DrawLevelField(xx, yy);
4014 else if (IS_BELT_ACTIVE(element) && belt_dir == MV_NO_MOVING)
4016 int e_belt_nr = getBeltNrFromBeltActiveElement(element);
4018 if (e_belt_nr == belt_nr)
4020 int belt_part = Feld[xx][yy] - belt_base_active_element[belt_nr];
4022 Feld[xx][yy] = belt_base_element[belt_nr] + belt_part;
4023 DrawLevelField(xx, yy);
4030 static void ToggleSwitchgateSwitch(int x, int y)
4034 game.switchgate_pos = !game.switchgate_pos;
4036 for (yy = 0; yy < lev_fieldy; yy++)
4038 for (xx = 0; xx < lev_fieldx; xx++)
4040 int element = Feld[xx][yy];
4042 if (element == EL_SWITCHGATE_SWITCH_UP ||
4043 element == EL_SWITCHGATE_SWITCH_DOWN)
4045 Feld[xx][yy] = EL_SWITCHGATE_SWITCH_UP + game.switchgate_pos;
4046 DrawLevelField(xx, yy);
4048 else if (element == EL_SWITCHGATE_OPEN ||
4049 element == EL_SWITCHGATE_OPENING)
4051 Feld[xx][yy] = EL_SWITCHGATE_CLOSING;
4053 PlayLevelSoundAction(xx, yy, ACTION_CLOSING);
4055 PlayLevelSound(xx, yy, SND_SWITCHGATE_CLOSING);
4058 else if (element == EL_SWITCHGATE_CLOSED ||
4059 element == EL_SWITCHGATE_CLOSING)
4061 Feld[xx][yy] = EL_SWITCHGATE_OPENING;
4063 PlayLevelSoundAction(xx, yy, ACTION_OPENING);
4065 PlayLevelSound(xx, yy, SND_SWITCHGATE_OPENING);
4072 static int getInvisibleActiveFromInvisibleElement(int element)
4074 return (element == EL_INVISIBLE_STEELWALL ? EL_INVISIBLE_STEELWALL_ACTIVE :
4075 element == EL_INVISIBLE_WALL ? EL_INVISIBLE_WALL_ACTIVE :
4076 element == EL_INVISIBLE_SAND ? EL_INVISIBLE_SAND_ACTIVE :
4080 static int getInvisibleFromInvisibleActiveElement(int element)
4082 return (element == EL_INVISIBLE_STEELWALL_ACTIVE ? EL_INVISIBLE_STEELWALL :
4083 element == EL_INVISIBLE_WALL_ACTIVE ? EL_INVISIBLE_WALL :
4084 element == EL_INVISIBLE_SAND_ACTIVE ? EL_INVISIBLE_SAND :
4088 static void RedrawAllLightSwitchesAndInvisibleElements()
4092 for (y = 0; y < lev_fieldy; y++)
4094 for (x = 0; x < lev_fieldx; x++)
4096 int element = Feld[x][y];
4098 if (element == EL_LIGHT_SWITCH &&
4099 game.light_time_left > 0)
4101 Feld[x][y] = EL_LIGHT_SWITCH_ACTIVE;
4102 DrawLevelField(x, y);
4104 else if (element == EL_LIGHT_SWITCH_ACTIVE &&
4105 game.light_time_left == 0)
4107 Feld[x][y] = EL_LIGHT_SWITCH;
4108 DrawLevelField(x, y);
4110 else if (element == EL_INVISIBLE_STEELWALL ||
4111 element == EL_INVISIBLE_WALL ||
4112 element == EL_INVISIBLE_SAND)
4114 if (game.light_time_left > 0)
4115 Feld[x][y] = getInvisibleActiveFromInvisibleElement(element);
4117 DrawLevelField(x, y);
4119 else if (element == EL_INVISIBLE_STEELWALL_ACTIVE ||
4120 element == EL_INVISIBLE_WALL_ACTIVE ||
4121 element == EL_INVISIBLE_SAND_ACTIVE)
4123 if (game.light_time_left == 0)
4124 Feld[x][y] = getInvisibleFromInvisibleActiveElement(element);
4126 DrawLevelField(x, y);
4132 static void ToggleLightSwitch(int x, int y)
4134 int element = Feld[x][y];
4136 game.light_time_left =
4137 (element == EL_LIGHT_SWITCH ?
4138 level.time_light * FRAMES_PER_SECOND : 0);
4140 RedrawAllLightSwitchesAndInvisibleElements();
4143 static void ActivateTimegateSwitch(int x, int y)
4147 game.timegate_time_left = level.time_timegate * FRAMES_PER_SECOND;
4149 for (yy = 0; yy < lev_fieldy; yy++)
4151 for (xx = 0; xx < lev_fieldx; xx++)
4153 int element = Feld[xx][yy];
4155 if (element == EL_TIMEGATE_CLOSED ||
4156 element == EL_TIMEGATE_CLOSING)
4158 Feld[xx][yy] = EL_TIMEGATE_OPENING;
4159 PlayLevelSound(xx, yy, SND_TIMEGATE_OPENING);
4163 else if (element == EL_TIMEGATE_SWITCH_ACTIVE)
4165 Feld[xx][yy] = EL_TIMEGATE_SWITCH;
4166 DrawLevelField(xx, yy);
4173 Feld[x][y] = EL_TIMEGATE_SWITCH_ACTIVE;
4176 inline static int getElementMoveStepsize(int x, int y)
4178 int element = Feld[x][y];
4179 int direction = MovDir[x][y];
4180 int dx = (direction == MV_LEFT ? -1 : direction == MV_RIGHT ? +1 : 0);
4181 int dy = (direction == MV_UP ? -1 : direction == MV_DOWN ? +1 : 0);
4182 int horiz_move = (dx != 0);
4183 int sign = (horiz_move ? dx : dy);
4184 int step = sign * element_info[element].move_stepsize;
4186 /* special values for move stepsize for spring and things on conveyor belt */
4190 if (element == EL_SPRING)
4191 step = sign * MOVE_STEPSIZE_NORMAL * 2;
4192 else if (CAN_FALL(element) && !CAN_MOVE(element) &&
4193 y < lev_fieldy - 1 && IS_BELT_ACTIVE(Feld[x][y + 1]))
4194 step = sign * MOVE_STEPSIZE_NORMAL / 2;
4196 if (CAN_FALL(element) &&
4197 y < lev_fieldy - 1 && IS_BELT_ACTIVE(Feld[x][y + 1]))
4198 step = sign * MOVE_STEPSIZE_NORMAL / 2;
4199 else if (element == EL_SPRING)
4200 step = sign * MOVE_STEPSIZE_NORMAL * 2;
4207 void Impact(int x, int y)
4209 boolean lastline = (y == lev_fieldy-1);
4210 boolean object_hit = FALSE;
4211 boolean impact = (lastline || object_hit);
4212 int element = Feld[x][y];
4213 int smashed = EL_STEELWALL;
4215 if (!lastline) /* check if element below was hit */
4217 if (Feld[x][y + 1] == EL_PLAYER_IS_LEAVING)
4220 object_hit = (!IS_FREE(x, y + 1) && (!IS_MOVING(x, y + 1) ||
4221 MovDir[x][y + 1] != MV_DOWN ||
4222 MovPos[x][y + 1] <= TILEY / 2));
4225 object_hit = !IS_FREE(x, y + 1);
4228 /* do not smash moving elements that left the smashed field in time */
4229 if (game.engine_version >= VERSION_IDENT(2,2,0,7) && IS_MOVING(x, y + 1) &&
4230 ABS(MovPos[x][y + 1] + getElementMoveStepsize(x, y + 1)) >= TILEX)
4234 smashed = MovingOrBlocked2Element(x, y + 1);
4236 impact = (lastline || object_hit);
4239 if (!lastline && smashed == EL_ACID) /* element falls into acid */
4241 SplashAcid(x, y + 1);
4245 /* !!! not sufficient for all cases -- see EL_PEARL below !!! */
4246 /* only reset graphic animation if graphic really changes after impact */
4248 el_act_dir2img(element, GfxAction[x][y], MV_DOWN) != el2img(element))
4250 ResetGfxAnimation(x, y);
4251 DrawLevelField(x, y);
4254 if (impact && CAN_EXPLODE_IMPACT(element))
4259 else if (impact && element == EL_PEARL)
4261 ResetGfxAnimation(x, y);
4263 Feld[x][y] = EL_PEARL_BREAKING;
4264 PlayLevelSound(x, y, SND_PEARL_BREAKING);
4267 else if (impact && CheckElementChange(x, y, element, smashed, CE_IMPACT))
4269 PlayLevelSoundElementAction(x, y, element, ACTION_IMPACT);
4274 if (impact && element == EL_AMOEBA_DROP)
4276 if (object_hit && IS_PLAYER(x, y + 1))
4277 KillHeroUnlessEnemyProtected(x, y + 1);
4278 else if (object_hit && smashed == EL_PENGUIN)
4282 Feld[x][y] = EL_AMOEBA_GROWING;
4283 Store[x][y] = EL_AMOEBA_WET;
4285 ResetRandomAnimationValue(x, y);
4290 if (object_hit) /* check which object was hit */
4292 if (CAN_PASS_MAGIC_WALL(element) &&
4293 (smashed == EL_MAGIC_WALL ||
4294 smashed == EL_BD_MAGIC_WALL))
4297 int activated_magic_wall =
4298 (smashed == EL_MAGIC_WALL ? EL_MAGIC_WALL_ACTIVE :
4299 EL_BD_MAGIC_WALL_ACTIVE);
4301 /* activate magic wall / mill */
4302 for (yy = 0; yy < lev_fieldy; yy++)
4303 for (xx = 0; xx < lev_fieldx; xx++)
4304 if (Feld[xx][yy] == smashed)
4305 Feld[xx][yy] = activated_magic_wall;
4307 game.magic_wall_time_left = level.time_magic_wall * FRAMES_PER_SECOND;
4308 game.magic_wall_active = TRUE;
4310 PlayLevelSound(x, y, (smashed == EL_MAGIC_WALL ?
4311 SND_MAGIC_WALL_ACTIVATING :
4312 SND_BD_MAGIC_WALL_ACTIVATING));
4315 if (IS_PLAYER(x, y + 1))
4317 if (CAN_SMASH_PLAYER(element))
4319 KillHeroUnlessEnemyProtected(x, y + 1);
4323 else if (smashed == EL_PENGUIN)
4325 if (CAN_SMASH_PLAYER(element))
4331 else if (element == EL_BD_DIAMOND)
4333 if (IS_CLASSIC_ENEMY(smashed) && IS_BD_ELEMENT(smashed))
4339 else if (((element == EL_SP_INFOTRON ||
4340 element == EL_SP_ZONK) &&
4341 (smashed == EL_SP_SNIKSNAK ||
4342 smashed == EL_SP_ELECTRON ||
4343 smashed == EL_SP_DISK_ORANGE)) ||
4344 (element == EL_SP_INFOTRON &&
4345 smashed == EL_SP_DISK_YELLOW))
4351 else if (CAN_SMASH_ENEMIES(element) && IS_CLASSIC_ENEMY(smashed))
4357 else if (CAN_SMASH_EVERYTHING(element))
4359 if (IS_CLASSIC_ENEMY(smashed) ||
4360 CAN_EXPLODE_SMASHED(smashed))
4365 else if (!IS_MOVING(x, y + 1) && !IS_BLOCKED(x, y + 1))
4367 if (smashed == EL_LAMP ||
4368 smashed == EL_LAMP_ACTIVE)
4373 else if (smashed == EL_NUT)
4375 Feld[x][y + 1] = EL_NUT_BREAKING;
4376 PlayLevelSound(x, y, SND_NUT_BREAKING);
4377 RaiseScoreElement(EL_NUT);
4380 else if (smashed == EL_PEARL)
4382 ResetGfxAnimation(x, y);
4384 Feld[x][y + 1] = EL_PEARL_BREAKING;
4385 PlayLevelSound(x, y, SND_PEARL_BREAKING);
4388 else if (smashed == EL_DIAMOND)
4390 Feld[x][y + 1] = EL_DIAMOND_BREAKING;
4391 PlayLevelSound(x, y, SND_DIAMOND_BREAKING);
4394 else if (IS_BELT_SWITCH(smashed))
4396 ToggleBeltSwitch(x, y + 1);
4398 else if (smashed == EL_SWITCHGATE_SWITCH_UP ||
4399 smashed == EL_SWITCHGATE_SWITCH_DOWN)
4401 ToggleSwitchgateSwitch(x, y + 1);
4403 else if (smashed == EL_LIGHT_SWITCH ||
4404 smashed == EL_LIGHT_SWITCH_ACTIVE)
4406 ToggleLightSwitch(x, y + 1);
4411 TestIfElementSmashesCustomElement(x, y, MV_DOWN);
4414 CheckElementChange(x, y + 1, smashed, element, CE_SMASHED);
4417 /* !!! TEST ONLY !!! */
4418 CheckElementChangeBySide(x, y + 1, smashed, element,
4419 CE_SWITCHED, CH_SIDE_TOP);
4420 CheckTriggeredElementChangeBySide(x, y + 1, smashed,
4421 CE_OTHER_IS_SWITCHING,CH_SIDE_TOP);
4423 CheckTriggeredElementChangeBySide(x, y + 1, smashed,
4424 CE_OTHER_IS_SWITCHING,CH_SIDE_TOP);
4425 CheckElementChangeBySide(x, y + 1, smashed, element,
4426 CE_SWITCHED, CH_SIDE_TOP);
4432 CheckElementChange(x, y + 1, smashed, element, CE_SMASHED);
4437 /* play sound of magic wall / mill */
4439 (Feld[x][y + 1] == EL_MAGIC_WALL_ACTIVE ||
4440 Feld[x][y + 1] == EL_BD_MAGIC_WALL_ACTIVE))
4442 if (Feld[x][y + 1] == EL_MAGIC_WALL_ACTIVE)
4443 PlayLevelSound(x, y, SND_MAGIC_WALL_FILLING);
4444 else if (Feld[x][y + 1] == EL_BD_MAGIC_WALL_ACTIVE)
4445 PlayLevelSound(x, y, SND_BD_MAGIC_WALL_FILLING);
4450 /* play sound of object that hits the ground */
4451 if (lastline || object_hit)
4452 PlayLevelSoundElementAction(x, y, element, ACTION_IMPACT);
4455 inline static void TurnRoundExt(int x, int y)
4467 { 0, 0 }, { 0, 0 }, { 0, 0 },
4472 int left, right, back;
4476 { MV_DOWN, MV_UP, MV_RIGHT },
4477 { MV_UP, MV_DOWN, MV_LEFT },
4479 { MV_LEFT, MV_RIGHT, MV_DOWN },
4483 { MV_RIGHT, MV_LEFT, MV_UP }
4486 int element = Feld[x][y];
4487 int move_pattern = element_info[element].move_pattern;
4489 int old_move_dir = MovDir[x][y];
4490 int left_dir = turn[old_move_dir].left;
4491 int right_dir = turn[old_move_dir].right;
4492 int back_dir = turn[old_move_dir].back;
4494 int left_dx = move_xy[left_dir].x, left_dy = move_xy[left_dir].y;
4495 int right_dx = move_xy[right_dir].x, right_dy = move_xy[right_dir].y;
4496 int move_dx = move_xy[old_move_dir].x, move_dy = move_xy[old_move_dir].y;
4497 int back_dx = move_xy[back_dir].x, back_dy = move_xy[back_dir].y;
4499 int left_x = x + left_dx, left_y = y + left_dy;
4500 int right_x = x + right_dx, right_y = y + right_dy;
4501 int move_x = x + move_dx, move_y = y + move_dy;
4505 if (element == EL_BUG || element == EL_BD_BUTTERFLY)
4507 TestIfBadThingTouchesOtherBadThing(x, y);
4509 if (ENEMY_CAN_ENTER_FIELD(element, right_x, right_y))
4510 MovDir[x][y] = right_dir;
4511 else if (!ENEMY_CAN_ENTER_FIELD(element, move_x, move_y))
4512 MovDir[x][y] = left_dir;
4514 if (element == EL_BUG && MovDir[x][y] != old_move_dir)
4516 else if (element == EL_BD_BUTTERFLY) /* && MovDir[x][y] == left_dir) */
4520 else if (element == EL_SPACESHIP || element == EL_BD_FIREFLY ||
4521 element == EL_SP_SNIKSNAK || element == EL_SP_ELECTRON)
4523 TestIfBadThingTouchesOtherBadThing(x, y);
4525 if (ENEMY_CAN_ENTER_FIELD(element, left_x, left_y))
4526 MovDir[x][y] = left_dir;
4527 else if (!ENEMY_CAN_ENTER_FIELD(element, move_x, move_y))
4528 MovDir[x][y] = right_dir;
4530 if ((element == EL_SPACESHIP ||
4531 element == EL_SP_SNIKSNAK ||
4532 element == EL_SP_ELECTRON)
4533 && MovDir[x][y] != old_move_dir)
4535 else if (element == EL_BD_FIREFLY) /* && MovDir[x][y] == right_dir) */
4539 else if (element == EL_SPACESHIP || element == EL_BD_FIREFLY)
4541 TestIfBadThingTouchesOtherBadThing(x, y);
4543 if (ENEMY_CAN_ENTER_FIELD(element, left_x, left_y))
4544 MovDir[x][y] = left_dir;
4545 else if (!ENEMY_CAN_ENTER_FIELD(element, move_x, move_y))
4546 MovDir[x][y] = right_dir;
4548 if (element == EL_SPACESHIP && MovDir[x][y] != old_move_dir)
4550 else if (element == EL_BD_FIREFLY) /* && MovDir[x][y] == right_dir) */
4553 else if (element == EL_SP_SNIKSNAK || element == EL_SP_ELECTRON)
4555 TestIfBadThingTouchesOtherBadThing(x, y);
4557 if (ELEMENT_CAN_ENTER_FIELD_BASE_4(element, left_x, left_y, 0))
4558 MovDir[x][y] = left_dir;
4559 else if (!ELEMENT_CAN_ENTER_FIELD_BASE_4(element, move_x, move_y, 0))
4560 MovDir[x][y] = right_dir;
4562 if (MovDir[x][y] != old_move_dir)
4566 else if (element == EL_YAMYAM)
4568 boolean can_turn_left = YAMYAM_CAN_ENTER_FIELD(element, left_x, left_y);
4569 boolean can_turn_right = YAMYAM_CAN_ENTER_FIELD(element, right_x, right_y);
4571 if (can_turn_left && can_turn_right)
4572 MovDir[x][y] = (RND(3) ? (RND(2) ? left_dir : right_dir) : back_dir);
4573 else if (can_turn_left)
4574 MovDir[x][y] = (RND(2) ? left_dir : back_dir);
4575 else if (can_turn_right)
4576 MovDir[x][y] = (RND(2) ? right_dir : back_dir);
4578 MovDir[x][y] = back_dir;
4580 MovDelay[x][y] = 16 + 16 * RND(3);
4582 else if (element == EL_DARK_YAMYAM)
4584 boolean can_turn_left = DARK_YAMYAM_CAN_ENTER_FIELD(element,
4586 boolean can_turn_right = DARK_YAMYAM_CAN_ENTER_FIELD(element,
4589 if (can_turn_left && can_turn_right)
4590 MovDir[x][y] = (RND(3) ? (RND(2) ? left_dir : right_dir) : back_dir);
4591 else if (can_turn_left)
4592 MovDir[x][y] = (RND(2) ? left_dir : back_dir);
4593 else if (can_turn_right)
4594 MovDir[x][y] = (RND(2) ? right_dir : back_dir);
4596 MovDir[x][y] = back_dir;
4598 MovDelay[x][y] = 16 + 16 * RND(3);
4600 else if (element == EL_PACMAN)
4602 boolean can_turn_left = PACMAN_CAN_ENTER_FIELD(element, left_x, left_y);
4603 boolean can_turn_right = PACMAN_CAN_ENTER_FIELD(element, right_x, right_y);
4605 if (can_turn_left && can_turn_right)
4606 MovDir[x][y] = (RND(3) ? (RND(2) ? left_dir : right_dir) : back_dir);
4607 else if (can_turn_left)
4608 MovDir[x][y] = (RND(2) ? left_dir : back_dir);
4609 else if (can_turn_right)
4610 MovDir[x][y] = (RND(2) ? right_dir : back_dir);
4612 MovDir[x][y] = back_dir;
4614 MovDelay[x][y] = 6 + RND(40);
4616 else if (element == EL_PIG)
4618 boolean can_turn_left = PIG_CAN_ENTER_FIELD(element, left_x, left_y);
4619 boolean can_turn_right = PIG_CAN_ENTER_FIELD(element, right_x, right_y);
4620 boolean can_move_on = PIG_CAN_ENTER_FIELD(element, move_x, move_y);
4621 boolean should_turn_left, should_turn_right, should_move_on;
4623 int rnd = RND(rnd_value);
4625 should_turn_left = (can_turn_left &&
4627 IN_LEV_FIELD_AND_NOT_FREE(x + back_dx + left_dx,
4628 y + back_dy + left_dy)));
4629 should_turn_right = (can_turn_right &&
4631 IN_LEV_FIELD_AND_NOT_FREE(x + back_dx + right_dx,
4632 y + back_dy + right_dy)));
4633 should_move_on = (can_move_on &&
4636 IN_LEV_FIELD_AND_NOT_FREE(x + move_dx + left_dx,
4637 y + move_dy + left_dy) ||
4638 IN_LEV_FIELD_AND_NOT_FREE(x + move_dx + right_dx,
4639 y + move_dy + right_dy)));
4641 if (should_turn_left || should_turn_right || should_move_on)
4643 if (should_turn_left && should_turn_right && should_move_on)
4644 MovDir[x][y] = (rnd < rnd_value / 3 ? left_dir :
4645 rnd < 2 * rnd_value / 3 ? right_dir :
4647 else if (should_turn_left && should_turn_right)
4648 MovDir[x][y] = (rnd < rnd_value / 2 ? left_dir : right_dir);
4649 else if (should_turn_left && should_move_on)
4650 MovDir[x][y] = (rnd < rnd_value / 2 ? left_dir : old_move_dir);
4651 else if (should_turn_right && should_move_on)
4652 MovDir[x][y] = (rnd < rnd_value / 2 ? right_dir : old_move_dir);
4653 else if (should_turn_left)
4654 MovDir[x][y] = left_dir;
4655 else if (should_turn_right)
4656 MovDir[x][y] = right_dir;
4657 else if (should_move_on)
4658 MovDir[x][y] = old_move_dir;
4660 else if (can_move_on && rnd > rnd_value / 8)
4661 MovDir[x][y] = old_move_dir;
4662 else if (can_turn_left && can_turn_right)
4663 MovDir[x][y] = (rnd < rnd_value / 2 ? left_dir : right_dir);
4664 else if (can_turn_left && rnd > rnd_value / 8)
4665 MovDir[x][y] = left_dir;
4666 else if (can_turn_right && rnd > rnd_value/8)
4667 MovDir[x][y] = right_dir;
4669 MovDir[x][y] = back_dir;
4671 xx = x + move_xy[MovDir[x][y]].x;
4672 yy = y + move_xy[MovDir[x][y]].y;
4675 /* !!! this bugfix breaks at least BD2K3, level 010 !!! [re-recorded] */
4676 if (!IN_LEV_FIELD(xx, yy) ||
4677 (!IS_FREE(xx, yy) && !IS_FOOD_PIG(Feld[xx][yy])))
4678 MovDir[x][y] = old_move_dir;
4680 if (!IS_FREE(xx, yy) && !IS_FOOD_PIG(Feld[xx][yy]))
4681 MovDir[x][y] = old_move_dir;
4686 else if (element == EL_DRAGON)
4688 boolean can_turn_left = DRAGON_CAN_ENTER_FIELD(element, left_x, left_y);
4689 boolean can_turn_right = DRAGON_CAN_ENTER_FIELD(element, right_x, right_y);
4690 boolean can_move_on = DRAGON_CAN_ENTER_FIELD(element, move_x, move_y);
4692 int rnd = RND(rnd_value);
4695 if (FrameCounter < 1 && x == 0 && y == 29)
4696 printf(":2: %d/%d: %d [%d]\n", x, y, MovDir[x][y], FrameCounter);
4699 if (can_move_on && rnd > rnd_value / 8)
4700 MovDir[x][y] = old_move_dir;
4701 else if (can_turn_left && can_turn_right)
4702 MovDir[x][y] = (rnd < rnd_value / 2 ? left_dir : right_dir);
4703 else if (can_turn_left && rnd > rnd_value / 8)
4704 MovDir[x][y] = left_dir;
4705 else if (can_turn_right && rnd > rnd_value / 8)
4706 MovDir[x][y] = right_dir;
4708 MovDir[x][y] = back_dir;
4710 xx = x + move_xy[MovDir[x][y]].x;
4711 yy = y + move_xy[MovDir[x][y]].y;
4714 if (FrameCounter < 1 && x == 0 && y == 29)
4715 printf(":3: %d/%d: %d (%d/%d: %d) [%d]\n", x, y, MovDir[x][y],
4716 xx, yy, Feld[xx][yy],
4721 if (!IN_LEV_FIELD_AND_IS_FREE(xx, yy))
4722 MovDir[x][y] = old_move_dir;
4724 if (!IS_FREE(xx, yy))
4725 MovDir[x][y] = old_move_dir;
4729 if (FrameCounter < 1 && x == 0 && y == 29)
4730 printf(":4: %d/%d: %d [%d]\n", x, y, MovDir[x][y], FrameCounter);
4735 else if (element == EL_MOLE)
4737 boolean can_move_on =
4738 (MOLE_CAN_ENTER_FIELD(element, move_x, move_y,
4739 IS_AMOEBOID(Feld[move_x][move_y]) ||
4740 Feld[move_x][move_y] == EL_AMOEBA_SHRINKING));
4743 boolean can_turn_left =
4744 (MOLE_CAN_ENTER_FIELD(element, left_x, left_y,
4745 IS_AMOEBOID(Feld[left_x][left_y])));
4747 boolean can_turn_right =
4748 (MOLE_CAN_ENTER_FIELD(element, right_x, right_y,
4749 IS_AMOEBOID(Feld[right_x][right_y])));
4751 if (can_turn_left && can_turn_right)
4752 MovDir[x][y] = (RND(2) ? left_dir : right_dir);
4753 else if (can_turn_left)
4754 MovDir[x][y] = left_dir;
4756 MovDir[x][y] = right_dir;
4759 if (MovDir[x][y] != old_move_dir)
4762 else if (element == EL_BALLOON)
4764 MovDir[x][y] = game.balloon_dir;
4767 else if (element == EL_SPRING)
4770 if (MovDir[x][y] & MV_HORIZONTAL &&
4771 !SPRING_CAN_ENTER_FIELD(element, move_x, move_y))
4772 MovDir[x][y] = MV_NO_MOVING;
4774 if (MovDir[x][y] & MV_HORIZONTAL &&
4775 (!SPRING_CAN_ENTER_FIELD(element, move_x, move_y) ||
4776 SPRING_CAN_ENTER_FIELD(element, x, y + 1)))
4777 MovDir[x][y] = MV_NO_MOVING;
4782 else if (element == EL_ROBOT ||
4783 element == EL_SATELLITE ||
4784 element == EL_PENGUIN)
4786 int attr_x = -1, attr_y = -1;
4797 for (i = 0; i < MAX_PLAYERS; i++)
4799 struct PlayerInfo *player = &stored_player[i];
4800 int jx = player->jx, jy = player->jy;
4802 if (!player->active)
4806 ABS(jx - x) + ABS(jy - y) < ABS(attr_x - x) + ABS(attr_y - y))
4815 if (element == EL_ROBOT && ZX >= 0 && ZY >= 0 &&
4816 (Feld[ZX][ZY] == EL_ROBOT_WHEEL_ACTIVE ||
4817 game.engine_version < VERSION_IDENT(3,1,0,0)))
4819 if (element == EL_ROBOT && ZX >= 0 && ZY >= 0)
4826 if (element == EL_PENGUIN)
4829 static int xy[4][2] =
4837 for (i = 0; i < NUM_DIRECTIONS; i++)
4839 int ex = x + xy[i][0];
4840 int ey = y + xy[i][1];
4842 if (IN_LEV_FIELD(ex, ey) && Feld[ex][ey] == EL_EXIT_OPEN)
4851 MovDir[x][y] = MV_NO_MOVING;
4853 MovDir[x][y] |= (AllPlayersGone ? MV_RIGHT : MV_LEFT);
4854 else if (attr_x > x)
4855 MovDir[x][y] |= (AllPlayersGone ? MV_LEFT : MV_RIGHT);
4857 MovDir[x][y] |= (AllPlayersGone ? MV_DOWN : MV_UP);
4858 else if (attr_y > y)
4859 MovDir[x][y] |= (AllPlayersGone ? MV_UP : MV_DOWN);
4861 if (element == EL_ROBOT)
4865 if (MovDir[x][y] & MV_HORIZONTAL && MovDir[x][y] & MV_VERTICAL)
4866 MovDir[x][y] &= (RND(2) ? MV_HORIZONTAL : MV_VERTICAL);
4867 Moving2Blocked(x, y, &newx, &newy);
4869 if (IN_LEV_FIELD(newx, newy) && IS_FREE_OR_PLAYER(newx, newy))
4870 MovDelay[x][y] = 8 + 8 * !RND(3);
4872 MovDelay[x][y] = 16;
4874 else if (element == EL_PENGUIN)
4880 if (MovDir[x][y] & MV_HORIZONTAL && MovDir[x][y] & MV_VERTICAL)
4882 boolean first_horiz = RND(2);
4883 int new_move_dir = MovDir[x][y];
4886 new_move_dir & (first_horiz ? MV_HORIZONTAL : MV_VERTICAL);
4887 Moving2Blocked(x, y, &newx, &newy);
4889 if (PENGUIN_CAN_ENTER_FIELD(EL_PENGUIN, newx, newy))
4893 new_move_dir & (!first_horiz ? MV_HORIZONTAL : MV_VERTICAL);
4894 Moving2Blocked(x, y, &newx, &newy);
4896 if (PENGUIN_CAN_ENTER_FIELD(EL_PENGUIN, newx, newy))
4899 MovDir[x][y] = old_move_dir;
4903 else /* (element == EL_SATELLITE) */
4909 if (MovDir[x][y] & MV_HORIZONTAL && MovDir[x][y] & MV_VERTICAL)
4911 boolean first_horiz = RND(2);
4912 int new_move_dir = MovDir[x][y];
4915 new_move_dir & (first_horiz ? MV_HORIZONTAL : MV_VERTICAL);
4916 Moving2Blocked(x, y, &newx, &newy);
4918 if (SATELLITE_CAN_ENTER_FIELD(newx, newy))
4922 new_move_dir & (!first_horiz ? MV_HORIZONTAL : MV_VERTICAL);
4923 Moving2Blocked(x, y, &newx, &newy);
4925 if (SATELLITE_CAN_ENTER_FIELD(newx, newy))
4928 MovDir[x][y] = old_move_dir;
4933 else if (move_pattern == MV_TURNING_LEFT ||
4934 move_pattern == MV_TURNING_RIGHT ||
4935 move_pattern == MV_TURNING_LEFT_RIGHT ||
4936 move_pattern == MV_TURNING_RIGHT_LEFT ||
4937 move_pattern == MV_TURNING_RANDOM ||
4938 move_pattern == MV_ALL_DIRECTIONS)
4940 boolean can_turn_left =
4941 CUSTOM_ELEMENT_CAN_ENTER_FIELD(element, left_x, left_y);
4942 boolean can_turn_right =
4943 CUSTOM_ELEMENT_CAN_ENTER_FIELD(element, right_x,right_y);
4945 if (move_pattern == MV_TURNING_LEFT)
4946 MovDir[x][y] = left_dir;
4947 else if (move_pattern == MV_TURNING_RIGHT)
4948 MovDir[x][y] = right_dir;
4949 else if (move_pattern == MV_TURNING_LEFT_RIGHT)
4950 MovDir[x][y] = (can_turn_left || !can_turn_right ? left_dir : right_dir);
4951 else if (move_pattern == MV_TURNING_RIGHT_LEFT)
4952 MovDir[x][y] = (can_turn_right || !can_turn_left ? right_dir : left_dir);
4953 else if (move_pattern == MV_TURNING_RANDOM)
4954 MovDir[x][y] = (can_turn_left && !can_turn_right ? left_dir :
4955 can_turn_right && !can_turn_left ? right_dir :
4956 RND(2) ? left_dir : right_dir);
4957 else if (can_turn_left && can_turn_right)
4958 MovDir[x][y] = (RND(3) ? (RND(2) ? left_dir : right_dir) : back_dir);
4959 else if (can_turn_left)
4960 MovDir[x][y] = (RND(2) ? left_dir : back_dir);
4961 else if (can_turn_right)
4962 MovDir[x][y] = (RND(2) ? right_dir : back_dir);
4964 MovDir[x][y] = back_dir;
4966 MovDelay[x][y] = GET_NEW_MOVE_DELAY(element);
4968 else if (move_pattern == MV_HORIZONTAL ||
4969 move_pattern == MV_VERTICAL)
4971 if (move_pattern & old_move_dir)
4972 MovDir[x][y] = back_dir;
4973 else if (move_pattern == MV_HORIZONTAL)
4974 MovDir[x][y] = (RND(2) ? MV_LEFT : MV_RIGHT);
4975 else if (move_pattern == MV_VERTICAL)
4976 MovDir[x][y] = (RND(2) ? MV_UP : MV_DOWN);
4978 MovDelay[x][y] = GET_NEW_MOVE_DELAY(element);
4980 else if (move_pattern & MV_ANY_DIRECTION)
4982 MovDir[x][y] = move_pattern;
4983 MovDelay[x][y] = GET_NEW_MOVE_DELAY(element);
4985 else if (move_pattern == MV_ALONG_LEFT_SIDE)
4987 if (CUSTOM_ELEMENT_CAN_ENTER_FIELD(element, left_x, left_y))
4988 MovDir[x][y] = left_dir;
4989 else if (!CUSTOM_ELEMENT_CAN_ENTER_FIELD(element, move_x, move_y))
4990 MovDir[x][y] = right_dir;
4992 if (MovDir[x][y] != old_move_dir)
4993 MovDelay[x][y] = GET_NEW_MOVE_DELAY(element);
4995 else if (move_pattern == MV_ALONG_RIGHT_SIDE)
4997 if (CUSTOM_ELEMENT_CAN_ENTER_FIELD(element, right_x, right_y))
4998 MovDir[x][y] = right_dir;
4999 else if (!CUSTOM_ELEMENT_CAN_ENTER_FIELD(element, move_x, move_y))
5000 MovDir[x][y] = left_dir;
5002 if (MovDir[x][y] != old_move_dir)
5003 MovDelay[x][y] = GET_NEW_MOVE_DELAY(element);
5005 else if (move_pattern == MV_TOWARDS_PLAYER ||
5006 move_pattern == MV_AWAY_FROM_PLAYER)
5008 int attr_x = -1, attr_y = -1;
5010 boolean move_away = (move_pattern == MV_AWAY_FROM_PLAYER);
5021 for (i = 0; i < MAX_PLAYERS; i++)
5023 struct PlayerInfo *player = &stored_player[i];
5024 int jx = player->jx, jy = player->jy;
5026 if (!player->active)
5030 ABS(jx - x) + ABS(jy - y) < ABS(attr_x - x) + ABS(attr_y - y))
5038 MovDir[x][y] = MV_NO_MOVING;
5040 MovDir[x][y] |= (move_away ? MV_RIGHT : MV_LEFT);
5041 else if (attr_x > x)
5042 MovDir[x][y] |= (move_away ? MV_LEFT : MV_RIGHT);
5044 MovDir[x][y] |= (move_away ? MV_DOWN : MV_UP);
5045 else if (attr_y > y)
5046 MovDir[x][y] |= (move_away ? MV_UP : MV_DOWN);
5048 MovDelay[x][y] = GET_NEW_MOVE_DELAY(element);
5050 if (MovDir[x][y] & MV_HORIZONTAL && MovDir[x][y] & MV_VERTICAL)
5052 boolean first_horiz = RND(2);
5053 int new_move_dir = MovDir[x][y];
5056 new_move_dir & (first_horiz ? MV_HORIZONTAL : MV_VERTICAL);
5057 Moving2Blocked(x, y, &newx, &newy);
5059 if (CUSTOM_ELEMENT_CAN_ENTER_FIELD(element, newx, newy))
5063 new_move_dir & (!first_horiz ? MV_HORIZONTAL : MV_VERTICAL);
5064 Moving2Blocked(x, y, &newx, &newy);
5066 if (CUSTOM_ELEMENT_CAN_ENTER_FIELD(element, newx, newy))
5069 MovDir[x][y] = old_move_dir;
5072 else if (move_pattern == MV_WHEN_PUSHED ||
5073 move_pattern == MV_WHEN_DROPPED)
5075 if (!CUSTOM_ELEMENT_CAN_ENTER_FIELD(element, move_x, move_y))
5076 MovDir[x][y] = MV_NO_MOVING;
5080 else if (move_pattern & MV_MAZE_RUNNER_STYLE)
5082 static int test_xy[7][2] =
5092 static int test_dir[7] =
5102 boolean hunter_mode = (move_pattern == MV_MAZE_HUNTER);
5103 int move_preference = -1000000; /* start with very low preference */
5104 int new_move_dir = MV_NO_MOVING;
5105 int start_test = RND(4);
5108 for (i = 0; i < NUM_DIRECTIONS; i++)
5110 int move_dir = test_dir[start_test + i];
5111 int move_dir_preference;
5113 xx = x + test_xy[start_test + i][0];
5114 yy = y + test_xy[start_test + i][1];
5116 if (hunter_mode && IN_LEV_FIELD(xx, yy) &&
5117 (IS_PLAYER(xx, yy) || Feld[xx][yy] == EL_PLAYER_IS_LEAVING))
5119 new_move_dir = move_dir;
5124 if (!CUSTOM_ELEMENT_CAN_ENTER_FIELD(element, xx, yy))
5127 move_dir_preference = -1 * RunnerVisit[xx][yy];
5128 if (hunter_mode && PlayerVisit[xx][yy] > 0)
5129 move_dir_preference = PlayerVisit[xx][yy];
5131 if (move_dir_preference > move_preference)
5133 /* prefer field that has not been visited for the longest time */
5134 move_preference = move_dir_preference;
5135 new_move_dir = move_dir;
5137 else if (move_dir_preference == move_preference &&
5138 move_dir == old_move_dir)
5140 /* prefer last direction when all directions are preferred equally */
5141 move_preference = move_dir_preference;
5142 new_move_dir = move_dir;
5146 MovDir[x][y] = new_move_dir;
5147 if (old_move_dir != new_move_dir)
5150 MovDelay[x][y] = GET_NEW_MOVE_DELAY(element);
5158 static void TurnRound(int x, int y)
5160 int direction = MovDir[x][y];
5163 GfxDir[x][y] = MovDir[x][y];
5169 GfxDir[x][y] = MovDir[x][y];
5172 if (direction != MovDir[x][y])
5177 GfxAction[x][y] = ACTION_TURNING_FROM_LEFT + MV_DIR_BIT(direction);
5180 GfxAction[x][y] = ACTION_WAITING;
5184 static boolean JustBeingPushed(int x, int y)
5188 for (i = 0; i < MAX_PLAYERS; i++)
5190 struct PlayerInfo *player = &stored_player[i];
5192 if (player->active && player->is_pushing && player->MovPos)
5194 int next_jx = player->jx + (player->jx - player->last_jx);
5195 int next_jy = player->jy + (player->jy - player->last_jy);
5197 if (x == next_jx && y == next_jy)
5205 void StartMoving(int x, int y)
5208 boolean use_spring_bug = (game.engine_version < VERSION_IDENT(2,2,0,0));
5210 boolean started_moving = FALSE; /* some elements can fall _and_ move */
5211 int element = Feld[x][y];
5217 if (MovDelay[x][y] == 0)
5218 GfxAction[x][y] = ACTION_DEFAULT;
5220 /* !!! this should be handled more generic (not only for mole) !!! */
5221 if (element != EL_MOLE && GfxAction[x][y] != ACTION_DIGGING)
5222 GfxAction[x][y] = ACTION_DEFAULT;
5225 if (CAN_FALL(element) && y < lev_fieldy - 1)
5227 if ((x > 0 && IS_PLAYER(x - 1, y)) ||
5228 (x < lev_fieldx - 1 && IS_PLAYER(x + 1, y)))
5229 if (JustBeingPushed(x, y))
5232 if (element == EL_QUICKSAND_FULL)
5234 if (IS_FREE(x, y + 1))
5236 InitMovingField(x, y, MV_DOWN);
5237 started_moving = TRUE;
5239 Feld[x][y] = EL_QUICKSAND_EMPTYING;
5240 Store[x][y] = EL_ROCK;
5242 PlayLevelSoundAction(x, y, ACTION_EMPTYING);
5244 PlayLevelSound(x, y, SND_QUICKSAND_EMPTYING);
5247 else if (Feld[x][y + 1] == EL_QUICKSAND_EMPTY)
5249 if (!MovDelay[x][y])
5250 MovDelay[x][y] = TILEY + 1;
5259 Feld[x][y] = EL_QUICKSAND_EMPTY;
5260 Feld[x][y + 1] = EL_QUICKSAND_FULL;
5261 Store[x][y + 1] = Store[x][y];
5264 PlayLevelSoundAction(x, y, ACTION_FILLING);
5266 PlayLevelSound(x, y, SND_QUICKSAND_FILLING);
5270 else if ((element == EL_ROCK || element == EL_BD_ROCK) &&
5271 Feld[x][y + 1] == EL_QUICKSAND_EMPTY)
5273 InitMovingField(x, y, MV_DOWN);
5274 started_moving = TRUE;
5276 Feld[x][y] = EL_QUICKSAND_FILLING;
5277 Store[x][y] = element;
5279 PlayLevelSoundAction(x, y, ACTION_FILLING);
5281 PlayLevelSound(x, y, SND_QUICKSAND_FILLING);
5284 else if (element == EL_MAGIC_WALL_FULL)
5286 if (IS_FREE(x, y + 1))
5288 InitMovingField(x, y, MV_DOWN);
5289 started_moving = TRUE;
5291 Feld[x][y] = EL_MAGIC_WALL_EMPTYING;
5292 Store[x][y] = EL_CHANGED(Store[x][y]);
5294 else if (Feld[x][y + 1] == EL_MAGIC_WALL_ACTIVE)
5296 if (!MovDelay[x][y])
5297 MovDelay[x][y] = TILEY/4 + 1;
5306 Feld[x][y] = EL_MAGIC_WALL_ACTIVE;
5307 Feld[x][y + 1] = EL_MAGIC_WALL_FULL;
5308 Store[x][y + 1] = EL_CHANGED(Store[x][y]);
5312 else if (element == EL_BD_MAGIC_WALL_FULL)
5314 if (IS_FREE(x, y + 1))
5316 InitMovingField(x, y, MV_DOWN);
5317 started_moving = TRUE;
5319 Feld[x][y] = EL_BD_MAGIC_WALL_EMPTYING;
5320 Store[x][y] = EL_CHANGED2(Store[x][y]);
5322 else if (Feld[x][y + 1] == EL_BD_MAGIC_WALL_ACTIVE)
5324 if (!MovDelay[x][y])
5325 MovDelay[x][y] = TILEY/4 + 1;
5334 Feld[x][y] = EL_BD_MAGIC_WALL_ACTIVE;
5335 Feld[x][y + 1] = EL_BD_MAGIC_WALL_FULL;
5336 Store[x][y + 1] = EL_CHANGED2(Store[x][y]);
5340 else if (CAN_PASS_MAGIC_WALL(element) &&
5341 (Feld[x][y + 1] == EL_MAGIC_WALL_ACTIVE ||
5342 Feld[x][y + 1] == EL_BD_MAGIC_WALL_ACTIVE))
5344 InitMovingField(x, y, MV_DOWN);
5345 started_moving = TRUE;
5348 (Feld[x][y + 1] == EL_MAGIC_WALL_ACTIVE ? EL_MAGIC_WALL_FILLING :
5349 EL_BD_MAGIC_WALL_FILLING);
5350 Store[x][y] = element;
5353 else if (CAN_SMASH(element) && Feld[x][y + 1] == EL_ACID)
5355 else if (CAN_FALL(element) && Feld[x][y + 1] == EL_ACID)
5358 SplashAcid(x, y + 1);
5360 InitMovingField(x, y, MV_DOWN);
5361 started_moving = TRUE;
5363 Store[x][y] = EL_ACID;
5365 /* !!! TEST !!! better use "_FALLING" etc. !!! */
5366 GfxAction[x][y + 1] = ACTION_ACTIVE;
5370 else if ((game.engine_version >= VERSION_IDENT(3,1,0,0) &&
5371 CheckCollision[x][y] && !IS_FREE(x, y + 1)) ||
5373 (game.engine_version >= VERSION_IDENT(3,0,7,0) &&
5374 CAN_SMASH(element) && WasJustFalling[x][y] &&
5375 (Feld[x][y + 1] == EL_BLOCKED || IS_PLAYER(x, y + 1))) ||
5377 (game.engine_version < VERSION_IDENT(2,2,0,7) &&
5378 CAN_SMASH(element) && WasJustMoving[x][y] && !Pushed[x][y + 1] &&
5379 (Feld[x][y + 1] == EL_BLOCKED)))
5383 else if (game.engine_version < VERSION_IDENT(2,2,0,7) &&
5384 CAN_SMASH(element) && Feld[x][y + 1] == EL_BLOCKED &&
5385 WasJustMoving[x][y] && !Pushed[x][y + 1])
5387 else if (CAN_SMASH(element) && Feld[x][y + 1] == EL_BLOCKED &&
5388 WasJustMoving[x][y])
5393 /* this is needed for a special case not covered by calling "Impact()"
5394 from "ContinueMoving()": if an element moves to a tile directly below
5395 another element which was just falling on that tile (which was empty
5396 in the previous frame), the falling element above would just stop
5397 instead of smashing the element below (in previous version, the above
5398 element was just checked for "moving" instead of "falling", resulting
5399 in incorrect smashes caused by horizontal movement of the above
5400 element; also, the case of the player being the element to smash was
5401 simply not covered here... :-/ ) */
5404 WasJustMoving[x][y] = 0;
5405 WasJustFalling[x][y] = 0;
5408 CheckCollision[x][y] = 0;
5411 if (IS_PLAYER(x, y + 1))
5412 printf("::: we ARE now killing the player [%d]\n", FrameCounter);
5417 else if (IS_FREE(x, y + 1) && element == EL_SPRING && level.use_spring_bug)
5419 if (MovDir[x][y] == MV_NO_MOVING)
5421 InitMovingField(x, y, MV_DOWN);
5422 started_moving = TRUE;
5425 else if (IS_FREE(x, y + 1) || Feld[x][y + 1] == EL_DIAMOND_BREAKING)
5427 if (WasJustFalling[x][y]) /* prevent animation from being restarted */
5428 MovDir[x][y] = MV_DOWN;
5430 InitMovingField(x, y, MV_DOWN);
5431 started_moving = TRUE;
5433 else if (element == EL_AMOEBA_DROP)
5435 Feld[x][y] = EL_AMOEBA_GROWING;
5436 Store[x][y] = EL_AMOEBA_WET;
5438 /* Store[x][y + 1] must be zero, because:
5439 (EL_QUICKSAND_FULL -> EL_ROCK): Store[x][y + 1] == EL_QUICKSAND_EMPTY
5442 #if OLD_GAME_BEHAVIOUR
5443 else if (IS_SLIPPERY(Feld[x][y + 1]) && !Store[x][y + 1])
5445 else if (IS_SLIPPERY(Feld[x][y + 1]) && !Store[x][y + 1] &&
5446 !IS_FALLING(x, y + 1) && !WasJustMoving[x][y + 1] &&
5447 element != EL_DX_SUPABOMB)
5450 else if (((IS_SLIPPERY(Feld[x][y + 1]) && !IS_PLAYER(x, y + 1)) ||
5451 (IS_EM_SLIPPERY_WALL(Feld[x][y + 1]) && IS_GEM(element))) &&
5452 !IS_FALLING(x, y + 1) && !WasJustMoving[x][y + 1] &&
5453 element != EL_DX_SUPABOMB && element != EL_SP_DISK_ORANGE)
5456 boolean can_fall_left = (x > 0 && IS_FREE(x - 1, y) &&
5457 (IS_FREE(x - 1, y + 1) ||
5458 Feld[x - 1][y + 1] == EL_ACID));
5459 boolean can_fall_right = (x < lev_fieldx - 1 && IS_FREE(x + 1, y) &&
5460 (IS_FREE(x + 1, y + 1) ||
5461 Feld[x + 1][y + 1] == EL_ACID));
5462 boolean can_fall_any = (can_fall_left || can_fall_right);
5463 boolean can_fall_both = (can_fall_left && can_fall_right);
5465 if (can_fall_any && IS_CUSTOM_ELEMENT(Feld[x][y + 1]))
5467 int slippery_type = element_info[Feld[x][y + 1]].slippery_type;
5469 if (slippery_type == SLIPPERY_ONLY_LEFT)
5470 can_fall_right = FALSE;
5471 else if (slippery_type == SLIPPERY_ONLY_RIGHT)
5472 can_fall_left = FALSE;
5473 else if (slippery_type == SLIPPERY_ANY_LEFT_RIGHT && can_fall_both)
5474 can_fall_right = FALSE;
5475 else if (slippery_type == SLIPPERY_ANY_RIGHT_LEFT && can_fall_both)
5476 can_fall_left = FALSE;
5478 can_fall_any = (can_fall_left || can_fall_right);
5479 can_fall_both = (can_fall_left && can_fall_right);
5482 #if USE_NEW_SP_SLIPPERY
5483 /* !!! better use the same properties as for custom elements here !!! */
5484 else if (game.engine_version >= VERSION_IDENT(3,1,1,0) &&
5485 can_fall_both && IS_SP_ELEMENT(Feld[x][y + 1]))
5487 can_fall_right = FALSE; /* slip down on left side */
5488 can_fall_both = FALSE;
5495 if (game.emulation == EMU_BOULDERDASH ||
5496 element == EL_BD_ROCK || element == EL_BD_DIAMOND)
5497 can_fall_right = FALSE; /* slip down on left side */
5499 can_fall_left = !(can_fall_right = RND(2));
5501 can_fall_both = FALSE;
5508 if (can_fall_both &&
5509 (game.emulation != EMU_BOULDERDASH &&
5510 element != EL_BD_ROCK && element != EL_BD_DIAMOND))
5511 can_fall_left = !(can_fall_right = RND(2));
5514 /* if not determined otherwise, prefer left side for slipping down */
5515 InitMovingField(x, y, can_fall_left ? MV_LEFT : MV_RIGHT);
5516 started_moving = TRUE;
5520 else if (IS_BELT_ACTIVE(Feld[x][y + 1]) && !CAN_MOVE(element))
5522 else if (IS_BELT_ACTIVE(Feld[x][y + 1]))
5525 boolean left_is_free = (x > 0 && IS_FREE(x - 1, y));
5526 boolean right_is_free = (x < lev_fieldx - 1 && IS_FREE(x + 1, y));
5527 int belt_nr = getBeltNrFromBeltActiveElement(Feld[x][y + 1]);
5528 int belt_dir = game.belt_dir[belt_nr];
5530 if ((belt_dir == MV_LEFT && left_is_free) ||
5531 (belt_dir == MV_RIGHT && right_is_free))
5534 int nextx = (belt_dir == MV_LEFT ? x - 1 : x + 1);
5537 InitMovingField(x, y, belt_dir);
5538 started_moving = TRUE;
5541 Pushed[x][y] = TRUE;
5542 Pushed[nextx][y] = TRUE;
5545 GfxAction[x][y] = ACTION_DEFAULT;
5549 MovDir[x][y] = 0; /* if element was moving, stop it */
5554 /* not "else if" because of elements that can fall and move (EL_SPRING) */
5556 if (CAN_MOVE(element) && !started_moving && MovDir[x][y] != MV_NO_MOVING)
5558 if (CAN_MOVE(element) && !started_moving)
5561 int move_pattern = element_info[element].move_pattern;
5566 if (MovDir[x][y] == MV_NO_MOVING)
5568 printf("StartMoving(): %d,%d: element %d ['%s'] not moving\n",
5569 x, y, element, element_info[element].token_name);
5570 printf("StartMoving(): This should never happen!\n");
5575 Moving2Blocked(x, y, &newx, &newy);
5578 if (IS_PUSHABLE(element) && JustBeingPushed(x, y))
5581 if ((element == EL_SATELLITE ||
5582 element == EL_BALLOON ||
5583 element == EL_SPRING)
5584 && JustBeingPushed(x, y))
5591 if (game.engine_version >= VERSION_IDENT(3,1,0,0) &&
5592 CheckCollision[x][y] && !IN_LEV_FIELD_AND_IS_FREE(newx, newy))
5594 if (game.engine_version >= VERSION_IDENT(3,1,0,0) &&
5595 WasJustMoving[x][y] && IN_LEV_FIELD(newx, newy) &&
5596 (Feld[newx][newy] == EL_BLOCKED || IS_PLAYER(newx, newy)))
5600 printf("::: element %d '%s' WasJustMoving %d [%d, %d, %d, %d]\n",
5601 element, element_info[element].token_name,
5602 WasJustMoving[x][y],
5603 HAS_ANY_CHANGE_EVENT(element, CE_HITTING_SOMETHING),
5604 HAS_ANY_CHANGE_EVENT(element, CE_HIT_BY_SOMETHING),
5605 HAS_ANY_CHANGE_EVENT(element, CE_OTHER_IS_HITTING),
5606 HAS_ANY_CHANGE_EVENT(element, CE_OTHER_GETS_HIT));
5610 WasJustMoving[x][y] = 0;
5613 CheckCollision[x][y] = 0;
5615 TestIfElementHitsCustomElement(x, y, MovDir[x][y]);
5618 if (Feld[x][y] != element) /* element has changed */
5620 element = Feld[x][y];
5621 move_pattern = element_info[element].move_pattern;
5623 if (!CAN_MOVE(element))
5627 if (Feld[x][y] != element) /* element has changed */
5635 if (element == EL_SPRING && MovDir[x][y] == MV_DOWN)
5636 Feld[x][y + 1] = EL_EMPTY; /* was set to EL_BLOCKED above */
5638 if (element == EL_SPRING && MovDir[x][y] != MV_NO_MOVING)
5640 Moving2Blocked(x, y, &newx, &newy);
5641 if (Feld[newx][newy] == EL_BLOCKED)
5642 Feld[newx][newy] = EL_EMPTY; /* was set to EL_BLOCKED above */
5648 if (FrameCounter < 1 && x == 0 && y == 29)
5649 printf(":1: %d/%d: %d [%d]\n", x, y, MovDir[x][y], FrameCounter);
5652 if (!MovDelay[x][y]) /* start new movement phase */
5654 /* all objects that can change their move direction after each step
5655 (YAMYAM, DARK_YAMYAM and PACMAN go straight until they hit a wall */
5657 if (element != EL_YAMYAM &&
5658 element != EL_DARK_YAMYAM &&
5659 element != EL_PACMAN &&
5660 !(move_pattern & MV_ANY_DIRECTION) &&
5661 move_pattern != MV_TURNING_LEFT &&
5662 move_pattern != MV_TURNING_RIGHT &&
5663 move_pattern != MV_TURNING_LEFT_RIGHT &&
5664 move_pattern != MV_TURNING_RIGHT_LEFT &&
5665 move_pattern != MV_TURNING_RANDOM)
5670 if (FrameCounter < 1 && x == 0 && y == 29)
5671 printf(":9: %d: %d [%d]\n", y, MovDir[x][y], FrameCounter);
5674 if (MovDelay[x][y] && (element == EL_BUG ||
5675 element == EL_SPACESHIP ||
5676 element == EL_SP_SNIKSNAK ||
5677 element == EL_SP_ELECTRON ||
5678 element == EL_MOLE))
5679 DrawLevelField(x, y);
5683 if (MovDelay[x][y]) /* wait some time before next movement */
5688 if (element == EL_YAMYAM)
5691 el_act_dir2img(EL_YAMYAM, ACTION_WAITING, MV_LEFT));
5692 DrawLevelElementAnimation(x, y, element);
5696 if (MovDelay[x][y]) /* element still has to wait some time */
5699 /* !!! PLACE THIS SOMEWHERE AFTER "TurnRound()" !!! */
5700 ResetGfxAnimation(x, y);
5704 if (GfxAction[x][y] != ACTION_WAITING)
5705 printf("::: %d: %d != ACTION_WAITING\n", element, GfxAction[x][y]);
5707 GfxAction[x][y] = ACTION_WAITING;
5711 if (element == EL_ROBOT ||
5713 element == EL_PACMAN ||
5715 element == EL_YAMYAM ||
5716 element == EL_DARK_YAMYAM)
5719 DrawLevelElementAnimation(x, y, element);
5721 DrawLevelElementAnimationIfNeeded(x, y, element);
5723 PlayLevelSoundAction(x, y, ACTION_WAITING);
5725 else if (element == EL_SP_ELECTRON)
5726 DrawLevelElementAnimationIfNeeded(x, y, element);
5727 else if (element == EL_DRAGON)
5730 int dir = MovDir[x][y];
5731 int dx = (dir == MV_LEFT ? -1 : dir == MV_RIGHT ? +1 : 0);
5732 int dy = (dir == MV_UP ? -1 : dir == MV_DOWN ? +1 : 0);
5733 int graphic = (dir == MV_LEFT ? IMG_FLAMES_1_LEFT :
5734 dir == MV_RIGHT ? IMG_FLAMES_1_RIGHT :
5735 dir == MV_UP ? IMG_FLAMES_1_UP :
5736 dir == MV_DOWN ? IMG_FLAMES_1_DOWN : IMG_EMPTY);
5737 int frame = getGraphicAnimationFrame(graphic, GfxFrame[x][y]);
5740 printf("::: %d, %d\n", GfxAction[x][y], GfxFrame[x][y]);
5743 GfxAction[x][y] = ACTION_ATTACKING;
5745 if (IS_PLAYER(x, y))
5746 DrawPlayerField(x, y);
5748 DrawLevelField(x, y);
5750 PlayLevelSoundActionIfLoop(x, y, ACTION_ATTACKING);
5752 for (i = 1; i <= 3; i++)
5754 int xx = x + i * dx;
5755 int yy = y + i * dy;
5756 int sx = SCREENX(xx);
5757 int sy = SCREENY(yy);
5758 int flame_graphic = graphic + (i - 1);
5760 if (!IN_LEV_FIELD(xx, yy) || IS_DRAGONFIRE_PROOF(Feld[xx][yy]))
5765 int flamed = MovingOrBlocked2Element(xx, yy);
5769 if (IS_CLASSIC_ENEMY(flamed) || CAN_EXPLODE_BY_DRAGONFIRE(flamed))
5771 else if (IS_MOVING(xx, yy) || IS_BLOCKED(xx, yy))
5772 RemoveMovingField(xx, yy);
5774 RemoveField(xx, yy);
5776 if (IS_CLASSIC_ENEMY(flamed) || CAN_EXPLODE_BY_DRAGONFIRE(flamed))
5779 RemoveMovingField(xx, yy);
5783 if (ChangeDelay[xx][yy])
5784 printf("::: !!! [%d]\n", (IS_MOVING(xx, yy) ||
5785 Feld[xx][yy] == EL_BLOCKED));
5789 ChangeDelay[xx][yy] = 0;
5791 Feld[xx][yy] = EL_FLAMES;
5792 if (IN_SCR_FIELD(sx, sy))
5794 DrawLevelFieldCrumbledSand(xx, yy);
5795 DrawGraphic(sx, sy, flame_graphic, frame);
5800 if (Feld[xx][yy] == EL_FLAMES)
5801 Feld[xx][yy] = EL_EMPTY;
5802 DrawLevelField(xx, yy);
5807 if (MovDelay[x][y]) /* element still has to wait some time */
5809 PlayLevelSoundAction(x, y, ACTION_WAITING);
5815 /* special case of "moving" animation of waiting elements (FIX THIS !!!);
5816 for all other elements GfxAction will be set by InitMovingField() */
5817 if (element == EL_BD_BUTTERFLY || element == EL_BD_FIREFLY)
5818 GfxAction[x][y] = ACTION_MOVING;
5822 /* now make next step */
5824 Moving2Blocked(x, y, &newx, &newy); /* get next screen position */
5826 if (DONT_COLLIDE_WITH(element) &&
5827 IN_LEV_FIELD(newx, newy) && IS_PLAYER(newx, newy) &&
5828 !PLAYER_ENEMY_PROTECTED(newx, newy))
5831 TestIfBadThingRunsIntoHero(x, y, MovDir[x][y]);
5835 /* player killed by element which is deadly when colliding with */
5837 KillHero(PLAYERINFO(newx, newy));
5844 else if (CAN_MOVE_INTO_ACID(element) &&
5845 IN_LEV_FIELD(newx, newy) && Feld[newx][newy] == EL_ACID &&
5846 (MovDir[x][y] == MV_DOWN ||
5847 game.engine_version >= VERSION_IDENT(3,1,0,0)))
5849 else if (CAN_MOVE_INTO_ACID(element) && MovDir[x][y] == MV_DOWN &&
5850 IN_LEV_FIELD(newx, newy) && Feld[newx][newy] == EL_ACID)
5854 else if ((element == EL_PENGUIN ||
5855 element == EL_ROBOT ||
5856 element == EL_SATELLITE ||
5857 element == EL_BALLOON ||
5858 IS_CUSTOM_ELEMENT(element)) &&
5859 IN_LEV_FIELD(newx, newy) &&
5860 MovDir[x][y] == MV_DOWN && Feld[newx][newy] == EL_ACID)
5863 SplashAcid(newx, newy);
5864 Store[x][y] = EL_ACID;
5866 else if (element == EL_PENGUIN && IN_LEV_FIELD(newx, newy))
5868 if (Feld[newx][newy] == EL_EXIT_OPEN)
5872 DrawLevelField(x, y);
5874 Feld[x][y] = EL_EMPTY;
5875 DrawLevelField(x, y);
5878 PlayLevelSound(newx, newy, SND_PENGUIN_PASSING);
5879 if (IN_SCR_FIELD(SCREENX(newx), SCREENY(newy)))
5880 DrawGraphicThruMask(SCREENX(newx),SCREENY(newy), el2img(element), 0);
5882 local_player->friends_still_needed--;
5883 if (!local_player->friends_still_needed &&
5884 !local_player->GameOver && AllPlayersGone)
5885 local_player->LevelSolved = local_player->GameOver = TRUE;
5889 else if (IS_FOOD_PENGUIN(Feld[newx][newy]))
5891 if (DigField(local_player, x, y, newx, newy, 0,0, DF_DIG) == MF_MOVING)
5892 DrawLevelField(newx, newy);
5894 GfxDir[x][y] = MovDir[x][y] = MV_NO_MOVING;
5896 else if (!IS_FREE(newx, newy))
5898 GfxAction[x][y] = ACTION_WAITING;
5900 if (IS_PLAYER(x, y))
5901 DrawPlayerField(x, y);
5903 DrawLevelField(x, y);
5908 else if (element == EL_PIG && IN_LEV_FIELD(newx, newy))
5910 if (IS_FOOD_PIG(Feld[newx][newy]))
5912 if (IS_MOVING(newx, newy))
5913 RemoveMovingField(newx, newy);
5916 Feld[newx][newy] = EL_EMPTY;
5917 DrawLevelField(newx, newy);
5920 PlayLevelSound(x, y, SND_PIG_DIGGING);
5922 else if (!IS_FREE(newx, newy))
5924 if (IS_PLAYER(x, y))
5925 DrawPlayerField(x, y);
5927 DrawLevelField(x, y);
5936 else if (move_pattern & MV_MAZE_RUNNER_STYLE && IN_LEV_FIELD(newx, newy))
5939 else if (IS_CUSTOM_ELEMENT(element) &&
5940 CUSTOM_ELEMENT_CAN_ENTER_FIELD(element, newx, newy)
5944 !IS_FREE(newx, newy)
5949 int new_element = Feld[newx][newy];
5952 printf("::: '%s' digs '%s' [%d]\n",
5953 element_info[element].token_name,
5954 element_info[Feld[newx][newy]].token_name,
5955 StorePlayer[newx][newy]);
5958 if (!IS_FREE(newx, newy))
5960 int action = (IS_DIGGABLE(new_element) ? ACTION_DIGGING :
5961 IS_COLLECTIBLE(new_element) ? ACTION_COLLECTING :
5964 /* no element can dig solid indestructible elements */
5965 if (IS_INDESTRUCTIBLE(new_element) &&
5966 !IS_DIGGABLE(new_element) &&
5967 !IS_COLLECTIBLE(new_element))
5970 if (AmoebaNr[newx][newy] &&
5971 (new_element == EL_AMOEBA_FULL ||
5972 new_element == EL_BD_AMOEBA ||
5973 new_element == EL_AMOEBA_GROWING))
5975 AmoebaCnt[AmoebaNr[newx][newy]]--;
5976 AmoebaCnt2[AmoebaNr[newx][newy]]--;
5979 if (IS_MOVING(newx, newy))
5980 RemoveMovingField(newx, newy);
5983 RemoveField(newx, newy);
5984 DrawLevelField(newx, newy);
5987 /* if digged element was about to explode, prevent the explosion */
5988 ExplodeField[newx][newy] = EX_TYPE_NONE;
5990 PlayLevelSoundAction(x, y, action);
5995 Store[newx][newy] = EL_EMPTY;
5996 if (IS_EQUAL_OR_IN_GROUP(new_element, MOVE_ENTER_EL(element)))
5997 Store[newx][newy] = element_info[element].move_leave_element;
5999 Store[newx][newy] = EL_EMPTY;
6000 if (IS_EQUAL_OR_IN_GROUP(new_element, MOVE_ENTER_EL(element)) ||
6001 element_info[element].move_leave_type == LEAVE_TYPE_UNLIMITED)
6002 Store[newx][newy] = element_info[element].move_leave_element;
6005 if (IS_EQUAL_OR_IN_GROUP(new_element, MOVE_ENTER_EL(element)))
6006 element_info[element].can_leave_element = TRUE;
6009 if (move_pattern & MV_MAZE_RUNNER_STYLE)
6011 RunnerVisit[x][y] = FrameCounter;
6012 PlayerVisit[x][y] /= 8; /* expire player visit path */
6018 else if (element == EL_DRAGON && IN_LEV_FIELD(newx, newy))
6020 if (!IS_FREE(newx, newy))
6022 if (IS_PLAYER(x, y))
6023 DrawPlayerField(x, y);
6025 DrawLevelField(x, y);
6031 boolean wanna_flame = !RND(10);
6032 int dx = newx - x, dy = newy - y;
6033 int newx1 = newx + 1 * dx, newy1 = newy + 1 * dy;
6034 int newx2 = newx + 2 * dx, newy2 = newy + 2 * dy;
6035 int element1 = (IN_LEV_FIELD(newx1, newy1) ?
6036 MovingOrBlocked2Element(newx1, newy1) : EL_STEELWALL);
6037 int element2 = (IN_LEV_FIELD(newx2, newy2) ?
6038 MovingOrBlocked2Element(newx2, newy2) : EL_STEELWALL);
6041 IS_CLASSIC_ENEMY(element1) ||
6042 IS_CLASSIC_ENEMY(element2)) &&
6043 element1 != EL_DRAGON && element2 != EL_DRAGON &&
6044 element1 != EL_FLAMES && element2 != EL_FLAMES)
6047 ResetGfxAnimation(x, y);
6048 GfxAction[x][y] = ACTION_ATTACKING;
6051 if (IS_PLAYER(x, y))
6052 DrawPlayerField(x, y);
6054 DrawLevelField(x, y);
6056 PlayLevelSound(x, y, SND_DRAGON_ATTACKING);
6058 MovDelay[x][y] = 50;
6062 RemoveField(newx, newy);
6064 Feld[newx][newy] = EL_FLAMES;
6065 if (IN_LEV_FIELD(newx1, newy1) && Feld[newx1][newy1] == EL_EMPTY)
6068 RemoveField(newx1, newy1);
6070 Feld[newx1][newy1] = EL_FLAMES;
6072 if (IN_LEV_FIELD(newx2, newy2) && Feld[newx2][newy2] == EL_EMPTY)
6075 RemoveField(newx2, newy2);
6077 Feld[newx2][newy2] = EL_FLAMES;
6084 else if (element == EL_YAMYAM && IN_LEV_FIELD(newx, newy) &&
6085 Feld[newx][newy] == EL_DIAMOND)
6087 if (IS_MOVING(newx, newy))
6088 RemoveMovingField(newx, newy);
6091 Feld[newx][newy] = EL_EMPTY;
6092 DrawLevelField(newx, newy);
6095 PlayLevelSound(x, y, SND_YAMYAM_DIGGING);
6097 else if (element == EL_DARK_YAMYAM && IN_LEV_FIELD(newx, newy) &&
6098 IS_FOOD_DARK_YAMYAM(Feld[newx][newy]))
6100 if (AmoebaNr[newx][newy])
6102 AmoebaCnt2[AmoebaNr[newx][newy]]--;
6103 if (Feld[newx][newy] == EL_AMOEBA_FULL ||
6104 Feld[newx][newy] == EL_BD_AMOEBA)
6105 AmoebaCnt[AmoebaNr[newx][newy]]--;
6110 if (IS_MOVING(newx, newy) || IS_BLOCKED(newx, newy))
6112 if (IS_MOVING(newx, newy))
6115 RemoveMovingField(newx, newy);
6119 Feld[newx][newy] = EL_EMPTY;
6120 DrawLevelField(newx, newy);
6123 PlayLevelSound(x, y, SND_DARK_YAMYAM_DIGGING);
6125 else if ((element == EL_PACMAN || element == EL_MOLE)
6126 && IN_LEV_FIELD(newx, newy) && IS_AMOEBOID(Feld[newx][newy]))
6128 if (AmoebaNr[newx][newy])
6130 AmoebaCnt2[AmoebaNr[newx][newy]]--;
6131 if (Feld[newx][newy] == EL_AMOEBA_FULL ||
6132 Feld[newx][newy] == EL_BD_AMOEBA)
6133 AmoebaCnt[AmoebaNr[newx][newy]]--;
6136 if (element == EL_MOLE)
6138 Feld[newx][newy] = EL_AMOEBA_SHRINKING;
6139 PlayLevelSound(x, y, SND_MOLE_DIGGING);
6141 ResetGfxAnimation(x, y);
6142 GfxAction[x][y] = ACTION_DIGGING;
6143 DrawLevelField(x, y);
6145 MovDelay[newx][newy] = 0; /* start amoeba shrinking delay */
6147 return; /* wait for shrinking amoeba */
6149 else /* element == EL_PACMAN */
6151 Feld[newx][newy] = EL_EMPTY;
6152 DrawLevelField(newx, newy);
6153 PlayLevelSound(x, y, SND_PACMAN_DIGGING);
6156 else if (element == EL_MOLE && IN_LEV_FIELD(newx, newy) &&
6157 (Feld[newx][newy] == EL_AMOEBA_SHRINKING ||
6158 (Feld[newx][newy] == EL_EMPTY && Stop[newx][newy])))
6160 /* wait for shrinking amoeba to completely disappear */
6163 else if (!IN_LEV_FIELD(newx, newy) || !IS_FREE(newx, newy))
6165 /* object was running against a wall */
6170 if (move_pattern & MV_ANY_DIRECTION &&
6171 move_pattern == MovDir[x][y])
6173 int blocking_element =
6174 (IN_LEV_FIELD(newx, newy) ? Feld[newx][newy] : BorderElement);
6177 printf("::: '%s' is blocked by '%s'! [%d,%d -> %d,%d]\n",
6178 element_info[element].token_name,
6179 element_info[blocking_element].token_name,
6183 CheckElementChangeBySide(x, y, element, blocking_element, CE_BLOCKED,
6186 element = Feld[x][y]; /* element might have changed */
6191 if (GFX_ELEMENT(element) != EL_SAND) /* !!! FIX THIS (crumble) !!! */
6192 DrawLevelElementAnimation(x, y, element);
6194 if (element == EL_BUG ||
6195 element == EL_SPACESHIP ||
6196 element == EL_SP_SNIKSNAK)
6197 DrawLevelField(x, y);
6198 else if (element == EL_MOLE)
6199 DrawLevelField(x, y);
6200 else if (element == EL_BD_BUTTERFLY ||
6201 element == EL_BD_FIREFLY)
6202 DrawLevelElementAnimationIfNeeded(x, y, element);
6203 else if (element == EL_SATELLITE)
6204 DrawLevelElementAnimationIfNeeded(x, y, element);
6205 else if (element == EL_SP_ELECTRON)
6206 DrawLevelElementAnimationIfNeeded(x, y, element);
6209 if (DONT_TOUCH(element))
6210 TestIfBadThingTouchesHero(x, y);
6213 PlayLevelSoundAction(x, y, ACTION_WAITING);
6219 InitMovingField(x, y, MovDir[x][y]);
6221 PlayLevelSoundAction(x, y, ACTION_MOVING);
6225 ContinueMoving(x, y);
6228 void ContinueMoving(int x, int y)
6230 int element = Feld[x][y];
6231 int stored = Store[x][y];
6232 struct ElementInfo *ei = &element_info[element];
6233 int direction = MovDir[x][y];
6234 int dx = (direction == MV_LEFT ? -1 : direction == MV_RIGHT ? +1 : 0);
6235 int dy = (direction == MV_UP ? -1 : direction == MV_DOWN ? +1 : 0);
6236 int newx = x + dx, newy = y + dy;
6238 int nextx = newx + dx, nexty = newy + dy;
6241 boolean pushed_by_player = (Pushed[x][y] && IS_PLAYER(x, y));
6242 boolean pushed_by_conveyor = (Pushed[x][y] && !IS_PLAYER(x, y));
6244 boolean pushed_by_player = Pushed[x][y];
6247 MovPos[x][y] += getElementMoveStepsize(x, y);
6250 if (pushed_by_player && IS_PLAYER(x, y))
6252 /* special case: moving object pushed by player */
6253 MovPos[x][y] = SIGN(MovPos[x][y]) * (TILEX - ABS(PLAYERINFO(x,y)->MovPos));
6256 if (pushed_by_player) /* special case: moving object pushed by player */
6257 MovPos[x][y] = SIGN(MovPos[x][y]) * (TILEX - ABS(PLAYERINFO(x,y)->MovPos));
6260 if (ABS(MovPos[x][y]) < TILEX)
6262 DrawLevelField(x, y);
6264 return; /* element is still moving */
6267 /* element reached destination field */
6269 Feld[x][y] = EL_EMPTY;
6270 Feld[newx][newy] = element;
6271 MovPos[x][y] = 0; /* force "not moving" for "crumbled sand" */
6274 if (Store[x][y] == EL_ACID) /* element is moving into acid pool */
6276 element = Feld[newx][newy] = EL_ACID;
6279 else if (element == EL_MOLE)
6281 Feld[x][y] = EL_SAND;
6283 DrawLevelFieldCrumbledSandNeighbours(x, y);
6285 else if (element == EL_QUICKSAND_FILLING)
6287 element = Feld[newx][newy] = get_next_element(element);
6288 Store[newx][newy] = Store[x][y];
6290 else if (element == EL_QUICKSAND_EMPTYING)
6292 Feld[x][y] = get_next_element(element);
6293 element = Feld[newx][newy] = Store[x][y];
6295 else if (element == EL_MAGIC_WALL_FILLING)
6297 element = Feld[newx][newy] = get_next_element(element);
6298 if (!game.magic_wall_active)
6299 element = Feld[newx][newy] = EL_MAGIC_WALL_DEAD;
6300 Store[newx][newy] = Store[x][y];
6302 else if (element == EL_MAGIC_WALL_EMPTYING)
6304 Feld[x][y] = get_next_element(element);
6305 if (!game.magic_wall_active)
6306 Feld[x][y] = EL_MAGIC_WALL_DEAD;
6307 element = Feld[newx][newy] = Store[x][y];
6309 else if (element == EL_BD_MAGIC_WALL_FILLING)
6311 element = Feld[newx][newy] = get_next_element(element);
6312 if (!game.magic_wall_active)
6313 element = Feld[newx][newy] = EL_BD_MAGIC_WALL_DEAD;
6314 Store[newx][newy] = Store[x][y];
6316 else if (element == EL_BD_MAGIC_WALL_EMPTYING)
6318 Feld[x][y] = get_next_element(element);
6319 if (!game.magic_wall_active)
6320 Feld[x][y] = EL_BD_MAGIC_WALL_DEAD;
6321 element = Feld[newx][newy] = Store[x][y];
6323 else if (element == EL_AMOEBA_DROPPING)
6325 Feld[x][y] = get_next_element(element);
6326 element = Feld[newx][newy] = Store[x][y];
6328 else if (element == EL_SOKOBAN_OBJECT)
6331 Feld[x][y] = Back[x][y];
6333 if (Back[newx][newy])
6334 Feld[newx][newy] = EL_SOKOBAN_FIELD_FULL;
6336 Back[x][y] = Back[newx][newy] = 0;
6339 else if (Store[x][y] == EL_ACID)
6341 element = Feld[newx][newy] = EL_ACID;
6345 else if (IS_CUSTOM_ELEMENT(element) && !IS_PLAYER(x, y) &&
6346 ei->move_leave_element != EL_EMPTY &&
6347 (ei->move_leave_type == LEAVE_TYPE_UNLIMITED ||
6348 Store[x][y] != EL_EMPTY))
6350 /* some elements can leave other elements behind after moving */
6352 Feld[x][y] = ei->move_leave_element;
6353 InitField(x, y, FALSE);
6355 if (GFX_CRUMBLED(Feld[x][y]))
6356 DrawLevelFieldCrumbledSandNeighbours(x, y);
6360 Store[x][y] = EL_EMPTY;
6361 MovPos[x][y] = MovDir[x][y] = MovDelay[x][y] = 0;
6362 MovDelay[newx][newy] = 0;
6364 if (CAN_CHANGE(element))
6366 /* copy element change control values to new field */
6367 ChangeDelay[newx][newy] = ChangeDelay[x][y];
6368 ChangePage[newx][newy] = ChangePage[x][y];
6369 Changed[newx][newy] = Changed[x][y];
6370 ChangeEvent[newx][newy] = ChangeEvent[x][y];
6373 ChangeDelay[x][y] = 0;
6374 ChangePage[x][y] = -1;
6375 Changed[x][y] = CE_BITMASK_DEFAULT;
6376 ChangeEvent[x][y] = CE_BITMASK_DEFAULT;
6378 /* copy animation control values to new field */
6379 GfxFrame[newx][newy] = GfxFrame[x][y];
6380 GfxRandom[newx][newy] = GfxRandom[x][y]; /* keep same random value */
6381 GfxAction[newx][newy] = GfxAction[x][y]; /* keep action one frame */
6382 GfxDir[newx][newy] = GfxDir[x][y]; /* keep element direction */
6384 Pushed[x][y] = Pushed[newx][newy] = FALSE;
6386 ResetGfxAnimation(x, y); /* reset animation values for old field */
6389 /* some elements can leave other elements behind after moving */
6391 if (IS_CUSTOM_ELEMENT(element) && ei->move_leave_element != EL_EMPTY &&
6392 (ei->move_leave_type == LEAVE_TYPE_UNLIMITED || stored != EL_EMPTY) &&
6393 (!IS_PLAYER(x, y) || IS_WALKABLE(ei->move_leave_element)))
6395 if (IS_CUSTOM_ELEMENT(element) && ei->move_leave_element != EL_EMPTY &&
6396 (ei->move_leave_type == LEAVE_TYPE_UNLIMITED || stored != EL_EMPTY) &&
6400 int move_leave_element = ei->move_leave_element;
6402 Feld[x][y] = move_leave_element;
6403 InitField(x, y, FALSE);
6405 if (GFX_CRUMBLED(Feld[x][y]))
6406 DrawLevelFieldCrumbledSandNeighbours(x, y);
6408 if (ELEM_IS_PLAYER(move_leave_element))
6409 RelocatePlayer(x, y, move_leave_element);
6414 /* some elements can leave other elements behind after moving */
6415 if (IS_CUSTOM_ELEMENT(element) && !IS_PLAYER(x, y) &&
6416 ei->move_leave_element != EL_EMPTY &&
6417 (ei->move_leave_type == LEAVE_TYPE_UNLIMITED ||
6418 ei->can_leave_element_last))
6420 Feld[x][y] = ei->move_leave_element;
6421 InitField(x, y, FALSE);
6423 if (GFX_CRUMBLED(Feld[x][y]))
6424 DrawLevelFieldCrumbledSandNeighbours(x, y);
6427 ei->can_leave_element_last = ei->can_leave_element;
6428 ei->can_leave_element = FALSE;
6432 /* 2.1.1 (does not work correctly for spring) */
6433 if (!CAN_MOVE(element))
6434 MovDir[newx][newy] = 0;
6438 /* (does not work for falling objects that slide horizontally) */
6439 if (CAN_FALL(element) && MovDir[newx][newy] == MV_DOWN)
6440 MovDir[newx][newy] = 0;
6443 if (!CAN_MOVE(element) ||
6444 (element == EL_SPRING && MovDir[newx][newy] == MV_DOWN))
6445 MovDir[newx][newy] = 0;
6449 if (!CAN_MOVE(element) ||
6450 (CAN_FALL(element) && direction == MV_DOWN))
6451 GfxDir[x][y] = MovDir[newx][newy] = 0;
6453 if (!CAN_MOVE(element) ||
6454 (CAN_FALL(element) && direction == MV_DOWN &&
6455 (element == EL_SPRING ||
6456 element_info[element].move_pattern == MV_WHEN_PUSHED ||
6457 element_info[element].move_pattern == MV_WHEN_DROPPED)))
6458 GfxDir[x][y] = MovDir[newx][newy] = 0;
6464 DrawLevelField(x, y);
6465 DrawLevelField(newx, newy);
6467 Stop[newx][newy] = TRUE; /* ignore this element until the next frame */
6469 /* prevent pushed element from moving on in pushed direction */
6470 if (pushed_by_player && CAN_MOVE(element) &&
6471 element_info[element].move_pattern & MV_ANY_DIRECTION &&
6472 !(element_info[element].move_pattern & direction))
6473 TurnRound(newx, newy);
6476 /* prevent elements on conveyor belt from moving on in last direction */
6477 if (pushed_by_conveyor && CAN_FALL(element) &&
6478 direction & MV_HORIZONTAL)
6481 if (CAN_MOVE(element))
6482 InitMovDir(newx, newy);
6484 MovDir[newx][newy] = 0;
6486 MovDir[newx][newy] = 0;
6491 if (!pushed_by_player)
6493 int nextx = newx + dx, nexty = newy + dy;
6494 boolean check_collision_again = IN_LEV_FIELD_AND_IS_FREE(nextx, nexty);
6496 WasJustMoving[newx][newy] = 3;
6498 if (CAN_FALL(element) && direction == MV_DOWN)
6499 WasJustFalling[newx][newy] = 3;
6501 if ((!CAN_FALL(element) || direction == MV_DOWN) && check_collision_again)
6502 CheckCollision[newx][newy] = 2;
6505 if (DONT_TOUCH(element)) /* object may be nasty to player or others */
6507 TestIfBadThingTouchesHero(newx, newy);
6508 TestIfBadThingTouchesFriend(newx, newy);
6510 if (!IS_CUSTOM_ELEMENT(element))
6511 TestIfBadThingTouchesOtherBadThing(newx, newy);
6513 else if (element == EL_PENGUIN)
6514 TestIfFriendTouchesBadThing(newx, newy);
6516 #if USE_NEW_MOVE_STYLE
6518 if (CAN_FALL(element) && direction == MV_DOWN &&
6519 (newy == lev_fieldy - 1 || !IS_FREE(x, newy + 1)) &&
6520 IS_PLAYER(x, newy + 1))
6521 printf("::: we would now kill the player [%d]\n", FrameCounter);
6524 /* give the player one last chance (one more frame) to move away */
6525 if (CAN_FALL(element) && direction == MV_DOWN &&
6526 (newy == lev_fieldy - 1 || !IS_FREE(x, newy + 1)) &&
6527 (!IS_PLAYER(x, newy + 1) ||
6528 game.engine_version < VERSION_IDENT(3,1,1,0)))
6531 if (CAN_FALL(element) && direction == MV_DOWN &&
6532 (newy == lev_fieldy - 1 || !IS_FREE(x, newy + 1)))
6540 if (pushed_by_player && !game.use_bug_change_when_pushing)
6542 if (pushed_by_player && game.engine_version >= VERSION_IDENT(3,1,0,0))
6545 if (pushed_by_player)
6550 int dig_side = MV_DIR_OPPOSITE(direction);
6552 static int trigger_sides[4] =
6554 CH_SIDE_RIGHT, /* moving left */
6555 CH_SIDE_LEFT, /* moving right */
6556 CH_SIDE_BOTTOM, /* moving up */
6557 CH_SIDE_TOP, /* moving down */
6559 int dig_side = trigger_sides[MV_DIR_BIT(direction)];
6561 struct PlayerInfo *player = PLAYERINFO(x, y);
6563 CheckElementChangeByPlayer(newx, newy, element, CE_PUSHED_BY_PLAYER,
6564 player->index_bit, dig_side);
6565 CheckTriggeredElementChangeByPlayer(newx,newy,element,CE_OTHER_GETS_PUSHED,
6566 player->index_bit, dig_side);
6571 TestIfElementTouchesCustomElement(x, y); /* empty or new element */
6575 if (ChangePage[newx][newy] != -1) /* delayed change */
6576 ChangeElement(newx, newy, ChangePage[newx][newy]);
6581 TestIfElementHitsCustomElement(newx, newy, direction);
6585 if (!IN_LEV_FIELD(nextx, nexty) || !IS_FREE(nextx, nexty))
6587 int hitting_element = Feld[newx][newy];
6589 /* !!! fix side (direction) orientation here and elsewhere !!! */
6590 CheckElementChangeBySide(newx, newy, hitting_element, CE_HITTING_SOMETHING,
6594 if (IN_LEV_FIELD(nextx, nexty))
6596 int opposite_direction = MV_DIR_OPPOSITE(direction);
6597 int hitting_side = direction;
6598 int touched_side = opposite_direction;
6599 int touched_element = MovingOrBlocked2Element(nextx, nexty);
6600 boolean object_hit = (!IS_MOVING(nextx, nexty) ||
6601 MovDir[nextx][nexty] != direction ||
6602 ABS(MovPos[nextx][nexty]) <= TILEY / 2);
6608 CheckElementChangeBySide(nextx, nexty, touched_element,
6609 CE_HIT_BY_SOMETHING, opposite_direction);
6611 if (IS_CUSTOM_ELEMENT(hitting_element) &&
6612 HAS_ANY_CHANGE_EVENT(hitting_element, CE_OTHER_IS_HITTING))
6614 for (i = 0; i < element_info[hitting_element].num_change_pages; i++)
6616 struct ElementChangeInfo *change =
6617 &element_info[hitting_element].change_page[i];
6619 if (change->can_change &&
6620 change->events & CH_EVENT_BIT(CE_OTHER_IS_HITTING) &&
6621 change->trigger_side & touched_side &&
6622 change->trigger_element == touched_element)
6624 CheckElementChangeByPage(newx, newy, hitting_element,
6625 touched_element, CE_OTHER_IS_HITTING,i);
6631 if (IS_CUSTOM_ELEMENT(touched_element) &&
6632 HAS_ANY_CHANGE_EVENT(touched_element, CE_OTHER_GETS_HIT))
6634 for (i = 0; i < element_info[touched_element].num_change_pages; i++)
6636 struct ElementChangeInfo *change =
6637 &element_info[touched_element].change_page[i];
6639 if (change->can_change &&
6640 change->events & CH_EVENT_BIT(CE_OTHER_GETS_HIT) &&
6641 change->trigger_side & hitting_side &&
6642 change->trigger_element == hitting_element)
6644 CheckElementChangeByPage(nextx, nexty, touched_element,
6645 hitting_element, CE_OTHER_GETS_HIT, i);
6656 TestIfPlayerTouchesCustomElement(newx, newy);
6657 TestIfElementTouchesCustomElement(newx, newy);
6660 int AmoebeNachbarNr(int ax, int ay)
6663 int element = Feld[ax][ay];
6665 static int xy[4][2] =
6673 for (i = 0; i < NUM_DIRECTIONS; i++)
6675 int x = ax + xy[i][0];
6676 int y = ay + xy[i][1];
6678 if (!IN_LEV_FIELD(x, y))
6681 if (Feld[x][y] == element && AmoebaNr[x][y] > 0)
6682 group_nr = AmoebaNr[x][y];
6688 void AmoebenVereinigen(int ax, int ay)
6690 int i, x, y, xx, yy;
6691 int new_group_nr = AmoebaNr[ax][ay];
6692 static int xy[4][2] =
6700 if (new_group_nr == 0)
6703 for (i = 0; i < NUM_DIRECTIONS; i++)
6708 if (!IN_LEV_FIELD(x, y))
6711 if ((Feld[x][y] == EL_AMOEBA_FULL ||
6712 Feld[x][y] == EL_BD_AMOEBA ||
6713 Feld[x][y] == EL_AMOEBA_DEAD) &&
6714 AmoebaNr[x][y] != new_group_nr)
6716 int old_group_nr = AmoebaNr[x][y];
6718 if (old_group_nr == 0)
6721 AmoebaCnt[new_group_nr] += AmoebaCnt[old_group_nr];
6722 AmoebaCnt[old_group_nr] = 0;
6723 AmoebaCnt2[new_group_nr] += AmoebaCnt2[old_group_nr];
6724 AmoebaCnt2[old_group_nr] = 0;
6726 for (yy = 0; yy < lev_fieldy; yy++)
6728 for (xx = 0; xx < lev_fieldx; xx++)
6730 if (AmoebaNr[xx][yy] == old_group_nr)
6731 AmoebaNr[xx][yy] = new_group_nr;
6738 void AmoebeUmwandeln(int ax, int ay)
6742 if (Feld[ax][ay] == EL_AMOEBA_DEAD)
6744 int group_nr = AmoebaNr[ax][ay];
6749 printf("AmoebeUmwandeln(): ax = %d, ay = %d\n", ax, ay);
6750 printf("AmoebeUmwandeln(): This should never happen!\n");
6755 for (y = 0; y < lev_fieldy; y++)
6757 for (x = 0; x < lev_fieldx; x++)
6759 if (Feld[x][y] == EL_AMOEBA_DEAD && AmoebaNr[x][y] == group_nr)
6762 Feld[x][y] = EL_AMOEBA_TO_DIAMOND;
6766 PlayLevelSound(ax, ay, (IS_GEM(level.amoeba_content) ?
6767 SND_AMOEBA_TURNING_TO_GEM :
6768 SND_AMOEBA_TURNING_TO_ROCK));
6773 static int xy[4][2] =
6781 for (i = 0; i < NUM_DIRECTIONS; i++)
6786 if (!IN_LEV_FIELD(x, y))
6789 if (Feld[x][y] == EL_AMOEBA_TO_DIAMOND)
6791 PlayLevelSound(x, y, (IS_GEM(level.amoeba_content) ?
6792 SND_AMOEBA_TURNING_TO_GEM :
6793 SND_AMOEBA_TURNING_TO_ROCK));
6800 void AmoebeUmwandelnBD(int ax, int ay, int new_element)
6803 int group_nr = AmoebaNr[ax][ay];
6804 boolean done = FALSE;
6809 printf("AmoebeUmwandelnBD(): ax = %d, ay = %d\n", ax, ay);
6810 printf("AmoebeUmwandelnBD(): This should never happen!\n");
6815 for (y = 0; y < lev_fieldy; y++)
6817 for (x = 0; x < lev_fieldx; x++)
6819 if (AmoebaNr[x][y] == group_nr &&
6820 (Feld[x][y] == EL_AMOEBA_DEAD ||
6821 Feld[x][y] == EL_BD_AMOEBA ||
6822 Feld[x][y] == EL_AMOEBA_GROWING))
6825 Feld[x][y] = new_element;
6826 InitField(x, y, FALSE);
6827 DrawLevelField(x, y);
6834 PlayLevelSound(ax, ay, (new_element == EL_BD_ROCK ?
6835 SND_BD_AMOEBA_TURNING_TO_ROCK :
6836 SND_BD_AMOEBA_TURNING_TO_GEM));
6839 void AmoebeWaechst(int x, int y)
6841 static unsigned long sound_delay = 0;
6842 static unsigned long sound_delay_value = 0;
6844 if (!MovDelay[x][y]) /* start new growing cycle */
6848 if (DelayReached(&sound_delay, sound_delay_value))
6851 PlayLevelSoundElementAction(x, y, Store[x][y], ACTION_GROWING);
6853 if (Store[x][y] == EL_BD_AMOEBA)
6854 PlayLevelSound(x, y, SND_BD_AMOEBA_GROWING);
6856 PlayLevelSound(x, y, SND_AMOEBA_GROWING);
6858 sound_delay_value = 30;
6862 if (MovDelay[x][y]) /* wait some time before growing bigger */
6865 if (MovDelay[x][y]/2 && IN_SCR_FIELD(SCREENX(x), SCREENY(y)))
6867 int frame = getGraphicAnimationFrame(IMG_AMOEBA_GROWING,
6868 6 - MovDelay[x][y]);
6870 DrawGraphic(SCREENX(x), SCREENY(y), IMG_AMOEBA_GROWING, frame);
6873 if (!MovDelay[x][y])
6875 Feld[x][y] = Store[x][y];
6877 DrawLevelField(x, y);
6882 void AmoebaDisappearing(int x, int y)
6884 static unsigned long sound_delay = 0;
6885 static unsigned long sound_delay_value = 0;
6887 if (!MovDelay[x][y]) /* start new shrinking cycle */
6891 if (DelayReached(&sound_delay, sound_delay_value))
6892 sound_delay_value = 30;
6895 if (MovDelay[x][y]) /* wait some time before shrinking */
6898 if (MovDelay[x][y]/2 && IN_SCR_FIELD(SCREENX(x), SCREENY(y)))
6900 int frame = getGraphicAnimationFrame(IMG_AMOEBA_SHRINKING,
6901 6 - MovDelay[x][y]);
6903 DrawGraphic(SCREENX(x), SCREENY(y), IMG_AMOEBA_SHRINKING, frame);
6906 if (!MovDelay[x][y])
6908 Feld[x][y] = EL_EMPTY;
6909 DrawLevelField(x, y);
6911 /* don't let mole enter this field in this cycle;
6912 (give priority to objects falling to this field from above) */
6918 void AmoebeAbleger(int ax, int ay)
6921 int element = Feld[ax][ay];
6922 int graphic = el2img(element);
6923 int newax = ax, neway = ay;
6924 static int xy[4][2] =
6932 if (!level.amoeba_speed)
6934 Feld[ax][ay] = EL_AMOEBA_DEAD;
6935 DrawLevelField(ax, ay);
6939 if (IS_ANIMATED(graphic))
6940 DrawLevelGraphicAnimationIfNeeded(ax, ay, graphic);
6942 if (!MovDelay[ax][ay]) /* start making new amoeba field */
6943 MovDelay[ax][ay] = RND(FRAMES_PER_SECOND * 25 / (1 + level.amoeba_speed));
6945 if (MovDelay[ax][ay]) /* wait some time before making new amoeba */
6948 if (MovDelay[ax][ay])
6952 if (element == EL_AMOEBA_WET) /* object is an acid / amoeba drop */
6955 int x = ax + xy[start][0];
6956 int y = ay + xy[start][1];
6958 if (!IN_LEV_FIELD(x, y))
6962 if (IS_FREE(x, y) ||
6963 CAN_GROW_INTO(Feld[x][y]) ||
6964 Feld[x][y] == EL_QUICKSAND_EMPTY)
6970 /* !!! extend EL_SAND to anything diggable (but maybe not SP_BASE) !!! */
6971 if (IS_FREE(x, y) ||
6972 Feld[x][y] == EL_SAND || Feld[x][y] == EL_QUICKSAND_EMPTY)
6979 if (newax == ax && neway == ay)
6982 else /* normal or "filled" (BD style) amoeba */
6985 boolean waiting_for_player = FALSE;
6987 for (i = 0; i < NUM_DIRECTIONS; i++)
6989 int j = (start + i) % 4;
6990 int x = ax + xy[j][0];
6991 int y = ay + xy[j][1];
6993 if (!IN_LEV_FIELD(x, y))
6997 if (IS_FREE(x, y) ||
6998 CAN_GROW_INTO(Feld[x][y]) ||
6999 Feld[x][y] == EL_QUICKSAND_EMPTY)
7006 /* !!! extend EL_SAND to anything diggable (but maybe not SP_BASE) !!! */
7007 if (IS_FREE(x, y) ||
7008 Feld[x][y] == EL_SAND || Feld[x][y] == EL_QUICKSAND_EMPTY)
7015 else if (IS_PLAYER(x, y))
7016 waiting_for_player = TRUE;
7019 if (newax == ax && neway == ay) /* amoeba cannot grow */
7022 if (i == 4 && (!waiting_for_player || element == EL_BD_AMOEBA))
7024 if (i == 4 && (!waiting_for_player || game.emulation == EMU_BOULDERDASH))
7027 Feld[ax][ay] = EL_AMOEBA_DEAD;
7028 DrawLevelField(ax, ay);
7029 AmoebaCnt[AmoebaNr[ax][ay]]--;
7031 if (AmoebaCnt[AmoebaNr[ax][ay]] <= 0) /* amoeba is completely dead */
7033 if (element == EL_AMOEBA_FULL)
7034 AmoebeUmwandeln(ax, ay);
7035 else if (element == EL_BD_AMOEBA)
7036 AmoebeUmwandelnBD(ax, ay, level.amoeba_content);
7041 else if (element == EL_AMOEBA_FULL || element == EL_BD_AMOEBA)
7043 /* amoeba gets larger by growing in some direction */
7045 int new_group_nr = AmoebaNr[ax][ay];
7048 if (new_group_nr == 0)
7050 printf("AmoebeAbleger(): newax = %d, neway = %d\n", newax, neway);
7051 printf("AmoebeAbleger(): This should never happen!\n");
7056 AmoebaNr[newax][neway] = new_group_nr;
7057 AmoebaCnt[new_group_nr]++;
7058 AmoebaCnt2[new_group_nr]++;
7060 /* if amoeba touches other amoeba(s) after growing, unify them */
7061 AmoebenVereinigen(newax, neway);
7063 if (element == EL_BD_AMOEBA && AmoebaCnt2[new_group_nr] >= 200)
7065 AmoebeUmwandelnBD(newax, neway, EL_BD_ROCK);
7071 if (element != EL_AMOEBA_WET || neway < ay || !IS_FREE(newax, neway) ||
7072 (neway == lev_fieldy - 1 && newax != ax))
7074 Feld[newax][neway] = EL_AMOEBA_GROWING; /* creation of new amoeba */
7075 Store[newax][neway] = element;
7077 else if (neway == ay)
7079 Feld[newax][neway] = EL_AMOEBA_DROP; /* drop left/right of amoeba */
7081 PlayLevelSoundAction(newax, neway, ACTION_GROWING);
7083 PlayLevelSound(newax, neway, SND_AMOEBA_GROWING);
7088 InitMovingField(ax, ay, MV_DOWN); /* drop dripping from amoeba */
7089 Feld[ax][ay] = EL_AMOEBA_DROPPING;
7090 Store[ax][ay] = EL_AMOEBA_DROP;
7091 ContinueMoving(ax, ay);
7095 DrawLevelField(newax, neway);
7098 void Life(int ax, int ay)
7101 static int life[4] = { 2, 3, 3, 3 }; /* parameters for "game of life" */
7103 int element = Feld[ax][ay];
7104 int graphic = el2img(element);
7105 boolean changed = FALSE;
7107 if (IS_ANIMATED(graphic))
7108 DrawLevelGraphicAnimationIfNeeded(ax, ay, graphic);
7113 if (!MovDelay[ax][ay]) /* start new "game of life" cycle */
7114 MovDelay[ax][ay] = life_time;
7116 if (MovDelay[ax][ay]) /* wait some time before next cycle */
7119 if (MovDelay[ax][ay])
7123 for (y1 = -1; y1 < 2; y1++) for (x1 = -1; x1 < 2; x1++)
7125 int xx = ax+x1, yy = ay+y1;
7128 if (!IN_LEV_FIELD(xx, yy))
7131 for (y2 = -1; y2 < 2; y2++) for (x2 = -1; x2 < 2; x2++)
7133 int x = xx+x2, y = yy+y2;
7135 if (!IN_LEV_FIELD(x, y) || (x == xx && y == yy))
7138 if (((Feld[x][y] == element ||
7139 (element == EL_GAME_OF_LIFE && IS_PLAYER(x, y))) &&
7141 (IS_FREE(x, y) && Stop[x][y]))
7145 if (xx == ax && yy == ay) /* field in the middle */
7147 if (nachbarn < life[0] || nachbarn > life[1])
7149 Feld[xx][yy] = EL_EMPTY;
7151 DrawLevelField(xx, yy);
7152 Stop[xx][yy] = TRUE;
7157 else if (IS_FREE(xx, yy) || CAN_GROW_INTO(Feld[xx][yy]))
7158 { /* free border field */
7159 if (nachbarn >= life[2] && nachbarn <= life[3])
7161 Feld[xx][yy] = element;
7162 MovDelay[xx][yy] = (element == EL_GAME_OF_LIFE ? 0 : life_time-1);
7164 DrawLevelField(xx, yy);
7165 Stop[xx][yy] = TRUE;
7170 /* !!! extend EL_SAND to anything diggable (but maybe not SP_BASE) !!! */
7171 else if (IS_FREE(xx, yy) || Feld[xx][yy] == EL_SAND)
7172 { /* free border field */
7173 if (nachbarn >= life[2] && nachbarn <= life[3])
7175 Feld[xx][yy] = element;
7176 MovDelay[xx][yy] = (element == EL_GAME_OF_LIFE ? 0 : life_time-1);
7178 DrawLevelField(xx, yy);
7179 Stop[xx][yy] = TRUE;
7187 PlayLevelSound(ax, ay, element == EL_BIOMAZE ? SND_BIOMAZE_GROWING :
7188 SND_GAME_OF_LIFE_GROWING);
7191 static void InitRobotWheel(int x, int y)
7193 ChangeDelay[x][y] = level.time_wheel * FRAMES_PER_SECOND;
7196 static void RunRobotWheel(int x, int y)
7198 PlayLevelSound(x, y, SND_ROBOT_WHEEL_ACTIVE);
7201 static void StopRobotWheel(int x, int y)
7203 if (ZX == x && ZY == y)
7207 static void InitTimegateWheel(int x, int y)
7210 ChangeDelay[x][y] = level.time_timegate * FRAMES_PER_SECOND;
7212 /* another brainless, "type style" bug ... :-( */
7213 ChangeDelay[x][y] = level.time_wheel * FRAMES_PER_SECOND;
7217 static void RunTimegateWheel(int x, int y)
7219 PlayLevelSound(x, y, SND_TIMEGATE_SWITCH_ACTIVE);
7222 void CheckExit(int x, int y)
7224 if (local_player->gems_still_needed > 0 ||
7225 local_player->sokobanfields_still_needed > 0 ||
7226 local_player->lights_still_needed > 0)
7228 int element = Feld[x][y];
7229 int graphic = el2img(element);
7231 if (IS_ANIMATED(graphic))
7232 DrawLevelGraphicAnimationIfNeeded(x, y, graphic);
7237 if (AllPlayersGone) /* do not re-open exit door closed after last player */
7240 Feld[x][y] = EL_EXIT_OPENING;
7242 PlayLevelSoundNearest(x, y, SND_CLASS_EXIT_OPENING);
7245 void CheckExitSP(int x, int y)
7247 if (local_player->gems_still_needed > 0)
7249 int element = Feld[x][y];
7250 int graphic = el2img(element);
7252 if (IS_ANIMATED(graphic))
7253 DrawLevelGraphicAnimationIfNeeded(x, y, graphic);
7258 if (AllPlayersGone) /* do not re-open exit door closed after last player */
7261 Feld[x][y] = EL_SP_EXIT_OPENING;
7263 PlayLevelSoundNearest(x, y, SND_CLASS_SP_EXIT_OPENING);
7266 static void CloseAllOpenTimegates()
7270 for (y = 0; y < lev_fieldy; y++)
7272 for (x = 0; x < lev_fieldx; x++)
7274 int element = Feld[x][y];
7276 if (element == EL_TIMEGATE_OPEN || element == EL_TIMEGATE_OPENING)
7278 Feld[x][y] = EL_TIMEGATE_CLOSING;
7280 PlayLevelSoundAction(x, y, ACTION_CLOSING);
7282 PlayLevelSound(x, y, SND_TIMEGATE_CLOSING);
7289 void EdelsteinFunkeln(int x, int y)
7291 if (!IN_SCR_FIELD(SCREENX(x), SCREENY(y)) || IS_MOVING(x, y))
7294 if (Feld[x][y] == EL_BD_DIAMOND)
7297 if (MovDelay[x][y] == 0) /* next animation frame */
7298 MovDelay[x][y] = 11 * !SimpleRND(500);
7300 if (MovDelay[x][y] != 0) /* wait some time before next frame */
7304 if (setup.direct_draw && MovDelay[x][y])
7305 SetDrawtoField(DRAW_BUFFERED);
7307 DrawLevelElementAnimation(x, y, Feld[x][y]);
7309 if (MovDelay[x][y] != 0)
7311 int frame = getGraphicAnimationFrame(IMG_TWINKLE_WHITE,
7312 10 - MovDelay[x][y]);
7314 DrawGraphicThruMask(SCREENX(x), SCREENY(y), IMG_TWINKLE_WHITE, frame);
7316 if (setup.direct_draw)
7320 dest_x = FX + SCREENX(x) * TILEX;
7321 dest_y = FY + SCREENY(y) * TILEY;
7323 BlitBitmap(drawto_field, window,
7324 dest_x, dest_y, TILEX, TILEY, dest_x, dest_y);
7325 SetDrawtoField(DRAW_DIRECT);
7331 void MauerWaechst(int x, int y)
7335 if (!MovDelay[x][y]) /* next animation frame */
7336 MovDelay[x][y] = 3 * delay;
7338 if (MovDelay[x][y]) /* wait some time before next frame */
7342 if (IN_SCR_FIELD(SCREENX(x), SCREENY(y)))
7344 int graphic = el_dir2img(Feld[x][y], GfxDir[x][y]);
7345 int frame = getGraphicAnimationFrame(graphic, 17 - MovDelay[x][y]);
7347 DrawGraphic(SCREENX(x), SCREENY(y), graphic, frame);
7350 if (!MovDelay[x][y])
7352 if (MovDir[x][y] == MV_LEFT)
7354 if (IN_LEV_FIELD(x - 1, y) && IS_WALL(Feld[x - 1][y]))
7355 DrawLevelField(x - 1, y);
7357 else if (MovDir[x][y] == MV_RIGHT)
7359 if (IN_LEV_FIELD(x + 1, y) && IS_WALL(Feld[x + 1][y]))
7360 DrawLevelField(x + 1, y);
7362 else if (MovDir[x][y] == MV_UP)
7364 if (IN_LEV_FIELD(x, y - 1) && IS_WALL(Feld[x][y - 1]))
7365 DrawLevelField(x, y - 1);
7369 if (IN_LEV_FIELD(x, y + 1) && IS_WALL(Feld[x][y + 1]))
7370 DrawLevelField(x, y + 1);
7373 Feld[x][y] = Store[x][y];
7375 GfxDir[x][y] = MovDir[x][y] = MV_NO_MOVING;
7376 DrawLevelField(x, y);
7381 void MauerAbleger(int ax, int ay)
7383 int element = Feld[ax][ay];
7384 int graphic = el2img(element);
7385 boolean oben_frei = FALSE, unten_frei = FALSE;
7386 boolean links_frei = FALSE, rechts_frei = FALSE;
7387 boolean oben_massiv = FALSE, unten_massiv = FALSE;
7388 boolean links_massiv = FALSE, rechts_massiv = FALSE;
7389 boolean new_wall = FALSE;
7391 if (IS_ANIMATED(graphic))
7392 DrawLevelGraphicAnimationIfNeeded(ax, ay, graphic);
7394 if (!MovDelay[ax][ay]) /* start building new wall */
7395 MovDelay[ax][ay] = 6;
7397 if (MovDelay[ax][ay]) /* wait some time before building new wall */
7400 if (MovDelay[ax][ay])
7404 if (IN_LEV_FIELD(ax, ay-1) && IS_FREE(ax, ay-1))
7406 if (IN_LEV_FIELD(ax, ay+1) && IS_FREE(ax, ay+1))
7408 if (IN_LEV_FIELD(ax-1, ay) && IS_FREE(ax-1, ay))
7410 if (IN_LEV_FIELD(ax+1, ay) && IS_FREE(ax+1, ay))
7413 if (element == EL_EXPANDABLE_WALL_VERTICAL ||
7414 element == EL_EXPANDABLE_WALL_ANY)
7418 Feld[ax][ay-1] = EL_EXPANDABLE_WALL_GROWING;
7419 Store[ax][ay-1] = element;
7420 GfxDir[ax][ay-1] = MovDir[ax][ay-1] = MV_UP;
7421 if (IN_SCR_FIELD(SCREENX(ax), SCREENY(ay-1)))
7422 DrawGraphic(SCREENX(ax), SCREENY(ay - 1),
7423 IMG_EXPANDABLE_WALL_GROWING_UP, 0);
7428 Feld[ax][ay+1] = EL_EXPANDABLE_WALL_GROWING;
7429 Store[ax][ay+1] = element;
7430 GfxDir[ax][ay+1] = MovDir[ax][ay+1] = MV_DOWN;
7431 if (IN_SCR_FIELD(SCREENX(ax), SCREENY(ay+1)))
7432 DrawGraphic(SCREENX(ax), SCREENY(ay + 1),
7433 IMG_EXPANDABLE_WALL_GROWING_DOWN, 0);
7438 if (element == EL_EXPANDABLE_WALL_HORIZONTAL ||
7439 element == EL_EXPANDABLE_WALL_ANY ||
7440 element == EL_EXPANDABLE_WALL)
7444 Feld[ax-1][ay] = EL_EXPANDABLE_WALL_GROWING;
7445 Store[ax-1][ay] = element;
7446 GfxDir[ax-1][ay] = MovDir[ax-1][ay] = MV_LEFT;
7447 if (IN_SCR_FIELD(SCREENX(ax-1), SCREENY(ay)))
7448 DrawGraphic(SCREENX(ax - 1), SCREENY(ay),
7449 IMG_EXPANDABLE_WALL_GROWING_LEFT, 0);
7455 Feld[ax+1][ay] = EL_EXPANDABLE_WALL_GROWING;
7456 Store[ax+1][ay] = element;
7457 GfxDir[ax+1][ay] = MovDir[ax+1][ay] = MV_RIGHT;
7458 if (IN_SCR_FIELD(SCREENX(ax+1), SCREENY(ay)))
7459 DrawGraphic(SCREENX(ax + 1), SCREENY(ay),
7460 IMG_EXPANDABLE_WALL_GROWING_RIGHT, 0);
7465 if (element == EL_EXPANDABLE_WALL && (links_frei || rechts_frei))
7466 DrawLevelField(ax, ay);
7468 if (!IN_LEV_FIELD(ax, ay-1) || IS_WALL(Feld[ax][ay-1]))
7470 if (!IN_LEV_FIELD(ax, ay+1) || IS_WALL(Feld[ax][ay+1]))
7471 unten_massiv = TRUE;
7472 if (!IN_LEV_FIELD(ax-1, ay) || IS_WALL(Feld[ax-1][ay]))
7473 links_massiv = TRUE;
7474 if (!IN_LEV_FIELD(ax+1, ay) || IS_WALL(Feld[ax+1][ay]))
7475 rechts_massiv = TRUE;
7477 if (((oben_massiv && unten_massiv) ||
7478 element == EL_EXPANDABLE_WALL_HORIZONTAL ||
7479 element == EL_EXPANDABLE_WALL) &&
7480 ((links_massiv && rechts_massiv) ||
7481 element == EL_EXPANDABLE_WALL_VERTICAL))
7482 Feld[ax][ay] = EL_WALL;
7486 PlayLevelSoundAction(ax, ay, ACTION_GROWING);
7488 PlayLevelSound(ax, ay, SND_EXPANDABLE_WALL_GROWING);
7492 void CheckForDragon(int x, int y)
7495 boolean dragon_found = FALSE;
7496 static int xy[4][2] =
7504 for (i = 0; i < NUM_DIRECTIONS; i++)
7506 for (j = 0; j < 4; j++)
7508 int xx = x + j * xy[i][0], yy = y + j * xy[i][1];
7510 if (IN_LEV_FIELD(xx, yy) &&
7511 (Feld[xx][yy] == EL_FLAMES || Feld[xx][yy] == EL_DRAGON))
7513 if (Feld[xx][yy] == EL_DRAGON)
7514 dragon_found = TRUE;
7523 for (i = 0; i < NUM_DIRECTIONS; i++)
7525 for (j = 0; j < 3; j++)
7527 int xx = x + j * xy[i][0], yy = y + j * xy[i][1];
7529 if (IN_LEV_FIELD(xx, yy) && Feld[xx][yy] == EL_FLAMES)
7531 Feld[xx][yy] = EL_EMPTY;
7532 DrawLevelField(xx, yy);
7541 static void InitBuggyBase(int x, int y)
7543 int element = Feld[x][y];
7544 int activating_delay = FRAMES_PER_SECOND / 4;
7547 (element == EL_SP_BUGGY_BASE ?
7548 2 * FRAMES_PER_SECOND + RND(5 * FRAMES_PER_SECOND) - activating_delay :
7549 element == EL_SP_BUGGY_BASE_ACTIVATING ?
7551 element == EL_SP_BUGGY_BASE_ACTIVE ?
7552 1 * FRAMES_PER_SECOND + RND(1 * FRAMES_PER_SECOND) : 1);
7555 static void WarnBuggyBase(int x, int y)
7558 static int xy[4][2] =
7566 for (i = 0; i < NUM_DIRECTIONS; i++)
7568 int xx = x + xy[i][0], yy = y + xy[i][1];
7570 if (IS_PLAYER(xx, yy))
7572 PlayLevelSound(x, y, SND_SP_BUGGY_BASE_ACTIVE);
7579 static void InitTrap(int x, int y)
7581 ChangeDelay[x][y] = 2 * FRAMES_PER_SECOND + RND(5 * FRAMES_PER_SECOND);
7584 static void ActivateTrap(int x, int y)
7586 PlayLevelSound(x, y, SND_TRAP_ACTIVATING);
7589 static void ChangeActiveTrap(int x, int y)
7591 int graphic = IMG_TRAP_ACTIVE;
7593 /* if new animation frame was drawn, correct crumbled sand border */
7594 if (IS_NEW_FRAME(GfxFrame[x][y], graphic))
7595 DrawLevelFieldCrumbledSand(x, y);
7598 static void ChangeElementNowExt(int x, int y, int target_element)
7600 int previous_move_direction = MovDir[x][y];
7602 boolean add_player = (ELEM_IS_PLAYER(target_element) &&
7603 IS_WALKABLE(Feld[x][y]));
7605 boolean add_player = (ELEM_IS_PLAYER(target_element) &&
7606 IS_WALKABLE(Feld[x][y]) &&
7610 /* check if element under player changes from accessible to unaccessible
7611 (needed for special case of dropping element which then changes) */
7612 if (IS_PLAYER(x, y) && !PLAYER_EXPLOSION_PROTECTED(x, y) &&
7613 IS_ACCESSIBLE(Feld[x][y]) && !IS_ACCESSIBLE(target_element))
7616 printf("::: BOOOM! [%d, '%s']\n", target_element,
7617 element_info[target_element].token_name);
7629 if (IS_MOVING(x, y) || IS_BLOCKED(x, y))
7630 RemoveMovingField(x, y);
7634 Feld[x][y] = target_element;
7637 Feld[x][y] = target_element;
7640 ResetGfxAnimation(x, y);
7641 ResetRandomAnimationValue(x, y);
7643 if (element_info[Feld[x][y]].move_direction_initial == MV_START_PREVIOUS)
7644 MovDir[x][y] = previous_move_direction;
7647 InitField_WithBug1(x, y, FALSE);
7649 InitField(x, y, FALSE);
7650 if (CAN_MOVE(Feld[x][y]))
7654 DrawLevelField(x, y);
7656 if (GFX_CRUMBLED(Feld[x][y]))
7657 DrawLevelFieldCrumbledSandNeighbours(x, y);
7661 Changed[x][y] |= ChangeEvent[x][y]; /* ignore same changes in this frame */
7665 TestIfBadThingTouchesHero(x, y);
7666 TestIfPlayerTouchesCustomElement(x, y);
7667 TestIfElementTouchesCustomElement(x, y);
7670 /* "Changed[][]" not set yet to allow "entered by player" change one time */
7671 if (ELEM_IS_PLAYER(target_element))
7672 RelocatePlayer(x, y, target_element);
7675 Changed[x][y] |= ChangeEvent[x][y]; /* ignore same changes in this frame */
7679 TestIfBadThingTouchesHero(x, y);
7680 TestIfPlayerTouchesCustomElement(x, y);
7681 TestIfElementTouchesCustomElement(x, y);
7685 static boolean ChangeElementNow(int x, int y, int element, int page)
7687 struct ElementChangeInfo *change = &element_info[element].change_page[page];
7689 int old_element = Feld[x][y];
7691 /* always use default change event to prevent running into a loop */
7692 if (ChangeEvent[x][y] == CE_BITMASK_DEFAULT)
7693 ChangeEvent[x][y] = CH_EVENT_BIT(CE_DELAY);
7695 if (ChangeEvent[x][y] == CH_EVENT_BIT(CE_DELAY))
7697 /* reset actual trigger element and player */
7698 change->actual_trigger_element = EL_EMPTY;
7699 change->actual_trigger_player = EL_PLAYER_1;
7702 /* do not change already changed elements with same change event */
7704 if (Changed[x][y] & ChangeEvent[x][y])
7711 Changed[x][y] |= ChangeEvent[x][y]; /* ignore same changes in this frame */
7714 /* !!! indirect change before direct change !!! */
7715 CheckTriggeredElementChangeByPage(x,y,Feld[x][y], CE_OTHER_IS_CHANGING,page);
7718 if (change->explode)
7725 if (change->use_target_content)
7727 boolean complete_replace = TRUE;
7728 boolean can_replace[3][3];
7731 for (yy = 0; yy < 3; yy++) for (xx = 0; xx < 3 ; xx++)
7734 boolean is_walkable;
7735 boolean is_diggable;
7736 boolean is_collectible;
7737 boolean is_removable;
7738 boolean is_destructible;
7739 int ex = x + xx - 1;
7740 int ey = y + yy - 1;
7741 int content_element = change->target_content[xx][yy];
7744 can_replace[xx][yy] = TRUE;
7746 if (ex == x && ey == y) /* do not check changing element itself */
7749 if (content_element == EL_EMPTY_SPACE)
7751 can_replace[xx][yy] = FALSE; /* do not replace border with space */
7756 if (!IN_LEV_FIELD(ex, ey))
7758 can_replace[xx][yy] = FALSE;
7759 complete_replace = FALSE;
7765 if (Changed[ex][ey]) /* do not change already changed elements */
7767 can_replace[xx][yy] = FALSE;
7768 complete_replace = FALSE;
7776 if (IS_MOVING(ex, ey) || IS_BLOCKED(ex, ey))
7777 e = MovingOrBlocked2Element(ex, ey);
7782 is_empty = (IS_FREE(ex, ey) ||
7783 (IS_PLAYER(ex, ey) && IS_WALKABLE(content_element)) ||
7784 (IS_WALKABLE(e) && ELEM_IS_PLAYER(content_element) &&
7785 !IS_MOVING(ex, ey) && !IS_BLOCKED(ex, ey)));
7789 is_empty = (IS_FREE(ex, ey) ||
7790 (IS_PLAYER(ex, ey) && IS_WALKABLE(content_element)));
7792 is_empty = (IS_FREE(ex, ey) ||
7793 (IS_FREE_OR_PLAYER(ex, ey) && IS_WALKABLE(content_element)));
7798 is_walkable = (is_empty || IS_WALKABLE(e));
7799 is_diggable = (is_empty || IS_DIGGABLE(e));
7800 is_collectible = (is_empty || IS_COLLECTIBLE(e));
7801 is_destructible = (is_empty || !IS_INDESTRUCTIBLE(e));
7802 is_removable = (is_diggable || is_collectible);
7804 can_replace[xx][yy] =
7805 (((change->replace_when == CP_WHEN_EMPTY && is_empty) ||
7806 (change->replace_when == CP_WHEN_WALKABLE && is_walkable) ||
7807 (change->replace_when == CP_WHEN_DIGGABLE && is_diggable) ||
7808 (change->replace_when == CP_WHEN_COLLECTIBLE && is_collectible) ||
7809 (change->replace_when == CP_WHEN_REMOVABLE && is_removable) ||
7810 (change->replace_when == CP_WHEN_DESTRUCTIBLE && is_destructible)) &&
7811 !(IS_PLAYER(ex, ey) && ELEM_IS_PLAYER(content_element)));
7813 if (!can_replace[xx][yy])
7814 complete_replace = FALSE;
7816 empty_for_element = (IS_FREE(ex, ey) || (IS_FREE_OR_PLAYER(ex, ey) &&
7817 IS_WALKABLE(content_element)));
7819 half_destructible = (empty_for_element || IS_DIGGABLE(e));
7821 half_destructible = (IS_FREE(ex, ey) || IS_DIGGABLE(e));
7824 if ((change->replace_when <= CP_WHEN_EMPTY && !empty_for_element) ||
7825 (change->replace_when <= CP_WHEN_DIGGABLE && !half_destructible) ||
7826 (change->replace_when <= CP_WHEN_DESTRUCTIBLE && IS_INDESTRUCTIBLE(e)))
7828 can_replace[xx][yy] = FALSE;
7829 complete_replace = FALSE;
7834 if (!change->only_if_complete || complete_replace)
7836 boolean something_has_changed = FALSE;
7838 if (change->only_if_complete && change->use_random_replace &&
7839 RND(100) < change->random_percentage)
7842 for (yy = 0; yy < 3; yy++) for (xx = 0; xx < 3 ; xx++)
7844 int ex = x + xx - 1;
7845 int ey = y + yy - 1;
7846 int content_element;
7848 if (can_replace[xx][yy] && (!change->use_random_replace ||
7849 RND(100) < change->random_percentage))
7851 if (IS_MOVING(ex, ey) || IS_BLOCKED(ex, ey))
7852 RemoveMovingField(ex, ey);
7854 ChangeEvent[ex][ey] = ChangeEvent[x][y];
7856 content_element = change->target_content[xx][yy];
7857 target_element = GET_TARGET_ELEMENT(content_element, change);
7859 ChangeElementNowExt(ex, ey, target_element);
7861 something_has_changed = TRUE;
7863 /* for symmetry reasons, freeze newly created border elements */
7864 if (ex != x || ey != y)
7865 Stop[ex][ey] = TRUE; /* no more moving in this frame */
7869 if (something_has_changed)
7870 PlayLevelSoundElementAction(x, y, element, ACTION_CHANGING);
7875 target_element = GET_TARGET_ELEMENT(change->target_element, change);
7877 ChangeElementNowExt(x, y, target_element);
7879 PlayLevelSoundElementAction(x, y, element, ACTION_CHANGING);
7883 /* this uses direct change before indirect change */
7884 CheckTriggeredElementChangeByPage(x,y,old_element,CE_OTHER_IS_CHANGING,page);
7890 static void ChangeElement(int x, int y, int page)
7892 int element = MovingOrBlocked2Element(x, y);
7893 struct ElementInfo *ei = &element_info[element];
7894 struct ElementChangeInfo *change = &ei->change_page[page];
7897 if (!CAN_CHANGE(element) && !CAN_CHANGE(Back[x][y]))
7900 printf("ChangeElement(): %d,%d: element = %d ('%s')\n",
7901 x, y, element, element_info[element].token_name);
7902 printf("ChangeElement(): This should never happen!\n");
7907 /* this can happen with classic bombs on walkable, changing elements */
7908 if (!CAN_CHANGE(element))
7911 if (!CAN_CHANGE(Back[x][y])) /* prevent permanent repetition */
7912 ChangeDelay[x][y] = 0;
7918 if (ChangeDelay[x][y] == 0) /* initialize element change */
7920 ChangeDelay[x][y] = ( change->delay_fixed * change->delay_frames +
7921 RND(change->delay_random * change->delay_frames)) + 1;
7923 ResetGfxAnimation(x, y);
7924 ResetRandomAnimationValue(x, y);
7926 if (change->pre_change_function)
7927 change->pre_change_function(x, y);
7930 ChangeDelay[x][y]--;
7932 if (ChangeDelay[x][y] != 0) /* continue element change */
7934 int graphic = el_act_dir2img(element, GfxAction[x][y], GfxDir[x][y]);
7936 if (IS_ANIMATED(graphic))
7937 DrawLevelGraphicAnimationIfNeeded(x, y, graphic);
7939 if (change->change_function)
7940 change->change_function(x, y);
7942 else /* finish element change */
7944 if (ChangePage[x][y] != -1) /* remember page from delayed change */
7946 page = ChangePage[x][y];
7947 ChangePage[x][y] = -1;
7949 change = &ei->change_page[page];
7953 if (IS_MOVING(x, y) && !change->explode)
7955 if (IS_MOVING(x, y)) /* never change a running system ;-) */
7958 ChangeDelay[x][y] = 1; /* try change after next move step */
7959 ChangePage[x][y] = page; /* remember page to use for change */
7964 if (ChangeElementNow(x, y, element, page))
7966 if (change->post_change_function)
7967 change->post_change_function(x, y);
7972 static boolean CheckTriggeredElementChangeExt(int lx, int ly,
7973 int trigger_element,
7980 int trigger_page_bits = (trigger_page < 0 ? CH_PAGE_ANY : 1 << trigger_page);
7982 if (!(trigger_events[trigger_element] & CH_EVENT_BIT(trigger_event)))
7985 for (i = 0; i < NUM_CUSTOM_ELEMENTS; i++)
7987 int element = EL_CUSTOM_START + i;
7989 boolean change_element = FALSE;
7992 if (!CAN_CHANGE(element) || !HAS_ANY_CHANGE_EVENT(element, trigger_event))
7995 for (j = 0; j < element_info[element].num_change_pages; j++)
7997 struct ElementChangeInfo *change = &element_info[element].change_page[j];
7999 if (change->can_change &&
8000 change->events & CH_EVENT_BIT(trigger_event) &&
8001 change->trigger_side & trigger_side &&
8002 change->trigger_player & trigger_player &&
8003 change->trigger_page & trigger_page_bits &&
8004 IS_EQUAL_OR_IN_GROUP(trigger_element, change->trigger_element))
8007 if (!(change->events & CH_EVENT_BIT(trigger_event)))
8008 printf("::: !!! %d triggers %d: using wrong page %d [event %d]\n",
8009 trigger_element-EL_CUSTOM_START+1, i+1, j, trigger_event);
8012 change_element = TRUE;
8015 change->actual_trigger_element = trigger_element;
8016 change->actual_trigger_player = EL_PLAYER_1 + log_2(trigger_player);
8022 if (!change_element)
8025 for (y = 0; y < lev_fieldy; y++) for (x = 0; x < lev_fieldx; x++)
8028 if (x == lx && y == ly) /* do not change trigger element itself */
8032 if (Feld[x][y] == element)
8034 ChangeDelay[x][y] = 1;
8035 ChangeEvent[x][y] = CH_EVENT_BIT(trigger_event);
8036 ChangeElement(x, y, page);
8044 static boolean CheckElementChangeExt(int x, int y,
8046 int trigger_element,
8052 if (!CAN_CHANGE(element) || !HAS_ANY_CHANGE_EVENT(element, trigger_event))
8055 if (Feld[x][y] == EL_BLOCKED)
8057 Blocked2Moving(x, y, &x, &y);
8058 element = Feld[x][y];
8062 if (Feld[x][y] != element) /* check if element has already changed */
8065 printf("::: %d ('%s') != %d ('%s') [%d]\n",
8066 Feld[x][y], element_info[Feld[x][y]].token_name,
8067 element, element_info[element].token_name,
8076 if (trigger_page < 0)
8078 boolean change_element = FALSE;
8081 for (i = 0; i < element_info[element].num_change_pages; i++)
8083 struct ElementChangeInfo *change = &element_info[element].change_page[i];
8085 if (change->can_change &&
8086 change->events & CH_EVENT_BIT(trigger_event) &&
8087 change->trigger_side & trigger_side &&
8088 change->trigger_player & trigger_player)
8090 change_element = TRUE;
8093 change->actual_trigger_element = trigger_element;
8094 change->actual_trigger_player = EL_PLAYER_1 + log_2(trigger_player);
8100 if (!change_element)
8105 struct ElementInfo *ei = &element_info[element];
8106 struct ElementChangeInfo *change = &ei->change_page[trigger_page];
8108 change->actual_trigger_element = trigger_element;
8109 change->actual_trigger_player = EL_PLAYER_1; /* unused */
8114 /* !!! this check misses pages with same event, but different side !!! */
8116 if (trigger_page < 0)
8117 trigger_page = element_info[element].event_page_nr[trigger_event];
8119 if (!(element_info[element].change_page[trigger_page].trigger_side & trigger_side))
8123 ChangeDelay[x][y] = 1;
8124 ChangeEvent[x][y] = CH_EVENT_BIT(trigger_event);
8125 ChangeElement(x, y, trigger_page);
8130 static void PlayPlayerSound(struct PlayerInfo *player)
8132 int jx = player->jx, jy = player->jy;
8133 int element = player->element_nr;
8134 int last_action = player->last_action_waiting;
8135 int action = player->action_waiting;
8137 if (player->is_waiting)
8139 if (action != last_action)
8140 PlayLevelSoundElementAction(jx, jy, element, action);
8142 PlayLevelSoundElementActionIfLoop(jx, jy, element, action);
8146 if (action != last_action)
8147 StopSound(element_info[element].sound[last_action]);
8149 if (last_action == ACTION_SLEEPING)
8150 PlayLevelSoundElementAction(jx, jy, element, ACTION_AWAKENING);
8154 static void PlayAllPlayersSound()
8158 for (i = 0; i < MAX_PLAYERS; i++)
8159 if (stored_player[i].active)
8160 PlayPlayerSound(&stored_player[i]);
8163 static void SetPlayerWaiting(struct PlayerInfo *player, boolean is_waiting)
8165 boolean last_waiting = player->is_waiting;
8166 int move_dir = player->MovDir;
8168 player->last_action_waiting = player->action_waiting;
8172 if (!last_waiting) /* not waiting -> waiting */
8174 player->is_waiting = TRUE;
8176 player->frame_counter_bored =
8178 game.player_boring_delay_fixed +
8179 SimpleRND(game.player_boring_delay_random);
8180 player->frame_counter_sleeping =
8182 game.player_sleeping_delay_fixed +
8183 SimpleRND(game.player_sleeping_delay_random);
8185 InitPlayerGfxAnimation(player, ACTION_WAITING, player->MovDir);
8188 if (game.player_sleeping_delay_fixed +
8189 game.player_sleeping_delay_random > 0 &&
8190 player->anim_delay_counter == 0 &&
8191 player->post_delay_counter == 0 &&
8192 FrameCounter >= player->frame_counter_sleeping)
8193 player->is_sleeping = TRUE;
8194 else if (game.player_boring_delay_fixed +
8195 game.player_boring_delay_random > 0 &&
8196 FrameCounter >= player->frame_counter_bored)
8197 player->is_bored = TRUE;
8199 player->action_waiting = (player->is_sleeping ? ACTION_SLEEPING :
8200 player->is_bored ? ACTION_BORING :
8203 if (player->is_sleeping)
8205 if (player->num_special_action_sleeping > 0)
8207 if (player->anim_delay_counter == 0 && player->post_delay_counter == 0)
8209 int last_special_action = player->special_action_sleeping;
8210 int num_special_action = player->num_special_action_sleeping;
8211 int special_action =
8212 (last_special_action == ACTION_DEFAULT ? ACTION_SLEEPING_1 :
8213 last_special_action == ACTION_SLEEPING ? ACTION_SLEEPING :
8214 last_special_action < ACTION_SLEEPING_1 + num_special_action - 1 ?
8215 last_special_action + 1 : ACTION_SLEEPING);
8216 int special_graphic =
8217 el_act_dir2img(player->element_nr, special_action, move_dir);
8219 player->anim_delay_counter =
8220 graphic_info[special_graphic].anim_delay_fixed +
8221 SimpleRND(graphic_info[special_graphic].anim_delay_random);
8222 player->post_delay_counter =
8223 graphic_info[special_graphic].post_delay_fixed +
8224 SimpleRND(graphic_info[special_graphic].post_delay_random);
8226 player->special_action_sleeping = special_action;
8229 if (player->anim_delay_counter > 0)
8231 player->action_waiting = player->special_action_sleeping;
8232 player->anim_delay_counter--;
8234 else if (player->post_delay_counter > 0)
8236 player->post_delay_counter--;
8240 else if (player->is_bored)
8242 if (player->num_special_action_bored > 0)
8244 if (player->anim_delay_counter == 0 && player->post_delay_counter == 0)
8246 int special_action =
8247 ACTION_BORING_1 + SimpleRND(player->num_special_action_bored);
8248 int special_graphic =
8249 el_act_dir2img(player->element_nr, special_action, move_dir);
8251 player->anim_delay_counter =
8252 graphic_info[special_graphic].anim_delay_fixed +
8253 SimpleRND(graphic_info[special_graphic].anim_delay_random);
8254 player->post_delay_counter =
8255 graphic_info[special_graphic].post_delay_fixed +
8256 SimpleRND(graphic_info[special_graphic].post_delay_random);
8258 player->special_action_bored = special_action;
8261 if (player->anim_delay_counter > 0)
8263 player->action_waiting = player->special_action_bored;
8264 player->anim_delay_counter--;
8266 else if (player->post_delay_counter > 0)
8268 player->post_delay_counter--;
8273 else if (last_waiting) /* waiting -> not waiting */
8275 player->is_waiting = FALSE;
8276 player->is_bored = FALSE;
8277 player->is_sleeping = FALSE;
8279 player->frame_counter_bored = -1;
8280 player->frame_counter_sleeping = -1;
8282 player->anim_delay_counter = 0;
8283 player->post_delay_counter = 0;
8285 player->action_waiting = ACTION_DEFAULT;
8287 player->special_action_bored = ACTION_DEFAULT;
8288 player->special_action_sleeping = ACTION_DEFAULT;
8293 static byte PlayerActions(struct PlayerInfo *player, byte player_action)
8296 static byte stored_player_action[MAX_PLAYERS];
8297 static int num_stored_actions = 0;
8299 boolean moved = FALSE, snapped = FALSE, dropped = FALSE;
8300 int left = player_action & JOY_LEFT;
8301 int right = player_action & JOY_RIGHT;
8302 int up = player_action & JOY_UP;
8303 int down = player_action & JOY_DOWN;
8304 int button1 = player_action & JOY_BUTTON_1;
8305 int button2 = player_action & JOY_BUTTON_2;
8306 int dx = (left ? -1 : right ? 1 : 0);
8307 int dy = (up ? -1 : down ? 1 : 0);
8310 stored_player_action[player->index_nr] = 0;
8311 num_stored_actions++;
8315 printf("::: player %d [%d]\n", player->index_nr, FrameCounter);
8318 if (!player->active || tape.pausing)
8322 printf("::: [%d %d %d %d] [%d %d]\n",
8323 left, right, up, down, button1, button2);
8329 printf("::: player %d acts [%d]\n", player->index_nr, FrameCounter);
8334 if (player->MovPos == 0)
8335 CheckGravityMovement(player);
8338 snapped = SnapField(player, dx, dy);
8342 dropped = DropElement(player);
8344 moved = MovePlayer(player, dx, dy);
8347 if (tape.single_step && tape.recording && !tape.pausing)
8349 if (button1 || (dropped && !moved))
8351 TapeTogglePause(TAPE_TOGGLE_AUTOMATIC);
8352 SnapField(player, 0, 0); /* stop snapping */
8356 SetPlayerWaiting(player, FALSE);
8359 return player_action;
8361 stored_player_action[player->index_nr] = player_action;
8367 printf("::: player %d waits [%d]\n", player->index_nr, FrameCounter);
8370 /* no actions for this player (no input at player's configured device) */
8372 DigField(player, 0, 0, 0, 0, 0, 0, DF_NO_PUSH);
8373 SnapField(player, 0, 0);
8374 CheckGravityMovementWhenNotMoving(player);
8376 if (player->MovPos == 0)
8377 SetPlayerWaiting(player, TRUE);
8379 if (player->MovPos == 0) /* needed for tape.playing */
8380 player->is_moving = FALSE;
8382 player->is_dropping = FALSE;
8388 if (tape.recording && num_stored_actions >= MAX_PLAYERS)
8390 printf("::: player %d recorded [%d]\n", player->index_nr, FrameCounter);
8392 TapeRecordAction(stored_player_action);
8393 num_stored_actions = 0;
8400 static void PlayerActions(struct PlayerInfo *player, byte player_action)
8402 static byte stored_player_action[MAX_PLAYERS];
8403 static int num_stored_actions = 0;
8404 boolean moved = FALSE, snapped = FALSE, dropped = FALSE;
8405 int left = player_action & JOY_LEFT;
8406 int right = player_action & JOY_RIGHT;
8407 int up = player_action & JOY_UP;
8408 int down = player_action & JOY_DOWN;
8409 int button1 = player_action & JOY_BUTTON_1;
8410 int button2 = player_action & JOY_BUTTON_2;
8411 int dx = (left ? -1 : right ? 1 : 0);
8412 int dy = (up ? -1 : down ? 1 : 0);
8414 stored_player_action[player->index_nr] = 0;
8415 num_stored_actions++;
8417 printf("::: player %d [%d]\n", player->index_nr, FrameCounter);
8419 if (!player->active || tape.pausing)
8424 printf("::: player %d acts [%d]\n", player->index_nr, FrameCounter);
8427 snapped = SnapField(player, dx, dy);
8431 dropped = DropElement(player);
8433 moved = MovePlayer(player, dx, dy);
8436 if (tape.single_step && tape.recording && !tape.pausing)
8438 if (button1 || (dropped && !moved))
8440 TapeTogglePause(TAPE_TOGGLE_AUTOMATIC);
8441 SnapField(player, 0, 0); /* stop snapping */
8445 stored_player_action[player->index_nr] = player_action;
8449 printf("::: player %d waits [%d]\n", player->index_nr, FrameCounter);
8451 /* no actions for this player (no input at player's configured device) */
8453 DigField(player, 0, 0, 0, 0, 0, 0, DF_NO_PUSH);
8454 SnapField(player, 0, 0);
8455 CheckGravityMovementWhenNotMoving(player);
8457 if (player->MovPos == 0)
8458 InitPlayerGfxAnimation(player, ACTION_DEFAULT, player->MovDir);
8460 if (player->MovPos == 0) /* needed for tape.playing */
8461 player->is_moving = FALSE;
8464 if (tape.recording && num_stored_actions >= MAX_PLAYERS)
8466 printf("::: player %d recorded [%d]\n", player->index_nr, FrameCounter);
8468 TapeRecordAction(stored_player_action);
8469 num_stored_actions = 0;
8474 void AdvanceFrameAndPlayerCounters(int player_nr)
8478 /* advance frame counters (global frame counter and time frame counter) */
8482 /* advance player counters (counters for move delay, move animation etc.) */
8483 for (i = 0; i < MAX_PLAYERS; i++)
8485 boolean advance_player_counters = (player_nr == -1 || player_nr == i);
8487 MOVE_DELAY_NORMAL_SPEED / stored_player[i].move_delay_value;
8489 if (!advance_player_counters) /* not all players may be affected */
8492 stored_player[i].Frame += move_frames;
8494 if (stored_player[i].MovPos != 0)
8495 stored_player[i].StepFrame += move_frames;
8497 #if USE_NEW_MOVE_DELAY
8498 if (stored_player[i].move_delay > 0)
8499 stored_player[i].move_delay--;
8502 #if USE_NEW_PUSH_DELAY
8503 /* due to bugs in previous versions, counter must count up, not down */
8504 if (stored_player[i].push_delay != -1)
8505 stored_player[i].push_delay++;
8508 if (stored_player[i].drop_delay > 0)
8509 stored_player[i].drop_delay--;
8515 static unsigned long action_delay = 0;
8516 unsigned long action_delay_value;
8517 int magic_wall_x = 0, magic_wall_y = 0;
8518 int i, x, y, element, graphic;
8519 byte *recorded_player_action;
8520 byte summarized_player_action = 0;
8522 byte tape_action[MAX_PLAYERS];
8525 if (game_status != GAME_MODE_PLAYING)
8528 action_delay_value =
8529 (tape.playing && tape.fast_forward ? FfwdFrameDelay : GameFrameDelay);
8531 if (tape.playing && tape.warp_forward && !tape.pausing)
8532 action_delay_value = 0;
8534 /* ---------- main game synchronization point ---------- */
8536 WaitUntilDelayReached(&action_delay, action_delay_value);
8538 if (network_playing && !network_player_action_received)
8542 printf("DEBUG: try to get network player actions in time\n");
8546 #if defined(NETWORK_AVALIABLE)
8547 /* last chance to get network player actions without main loop delay */
8551 if (game_status != GAME_MODE_PLAYING)
8554 if (!network_player_action_received)
8558 printf("DEBUG: failed to get network player actions in time\n");
8569 printf("::: getting new tape action [%d]\n", FrameCounter);
8572 recorded_player_action = (tape.playing ? TapePlayAction() : NULL);
8575 if (recorded_player_action == NULL && tape.pausing)
8580 printf("::: %d\n", stored_player[0].action);
8584 if (recorded_player_action != NULL)
8585 for (i = 0; i < MAX_PLAYERS; i++)
8586 stored_player[i].action = recorded_player_action[i];
8589 for (i = 0; i < MAX_PLAYERS; i++)
8591 summarized_player_action |= stored_player[i].action;
8593 if (!network_playing)
8594 stored_player[i].effective_action = stored_player[i].action;
8597 #if defined(NETWORK_AVALIABLE)
8598 if (network_playing)
8599 SendToServer_MovePlayer(summarized_player_action);
8602 if (!options.network && !setup.team_mode)
8603 local_player->effective_action = summarized_player_action;
8606 if (recorded_player_action != NULL)
8607 for (i = 0; i < MAX_PLAYERS; i++)
8608 stored_player[i].effective_action = recorded_player_action[i];
8612 for (i = 0; i < MAX_PLAYERS; i++)
8614 tape_action[i] = stored_player[i].effective_action;
8616 if (tape.recording && tape_action[i] && !tape.player_participates[i])
8617 tape.player_participates[i] = TRUE; /* player just appeared from CE */
8620 /* only save actions from input devices, but not programmed actions */
8622 TapeRecordAction(tape_action);
8625 for (i = 0; i < MAX_PLAYERS; i++)
8627 int actual_player_action = stored_player[i].effective_action;
8630 /* !!! THIS BREAKS THE FOLLOWING TAPES: !!!
8631 - rnd_equinox_tetrachloride 048
8632 - rnd_equinox_tetrachloride_ii 096
8633 - rnd_emanuel_schmieg 002
8634 - doctor_sloan_ww 001, 020
8636 if (stored_player[i].MovPos == 0)
8637 CheckGravityMovement(&stored_player[i]);
8641 /* overwrite programmed action with tape action */
8642 if (stored_player[i].programmed_action)
8643 actual_player_action = stored_player[i].programmed_action;
8647 if (stored_player[i].programmed_action)
8648 printf("::: %d\n", stored_player[i].programmed_action);
8651 if (recorded_player_action)
8654 if (stored_player[i].programmed_action &&
8655 stored_player[i].programmed_action != recorded_player_action[i])
8656 printf("::: %d: %d <-> %d\n", i,
8657 stored_player[i].programmed_action, recorded_player_action[i]);
8661 actual_player_action = recorded_player_action[i];
8666 /* overwrite tape action with programmed action */
8667 if (stored_player[i].programmed_action)
8668 actual_player_action = stored_player[i].programmed_action;
8673 printf("::: action: %d: %x [%d]\n",
8674 stored_player[i].MovPos, actual_player_action, FrameCounter);
8678 PlayerActions(&stored_player[i], actual_player_action);
8680 tape_action[i] = PlayerActions(&stored_player[i], actual_player_action);
8682 if (tape.recording && tape_action[i] && !tape.player_participates[i])
8683 tape.player_participates[i] = TRUE; /* player just appeared from CE */
8686 ScrollPlayer(&stored_player[i], SCROLL_GO_ON);
8691 TapeRecordAction(tape_action);
8694 network_player_action_received = FALSE;
8696 ScrollScreen(NULL, SCROLL_GO_ON);
8702 for (i = 0; i < MAX_PLAYERS; i++)
8703 stored_player[i].Frame++;
8707 /* for backwards compatibility, the following code emulates a fixed bug that
8708 occured when pushing elements (causing elements that just made their last
8709 pushing step to already (if possible) make their first falling step in the
8710 same game frame, which is bad); this code is also needed to use the famous
8711 "spring push bug" which is used in older levels and might be wanted to be
8712 used also in newer levels, but in this case the buggy pushing code is only
8713 affecting the "spring" element and no other elements */
8716 if (game.engine_version < VERSION_IDENT(2,2,0,7) || level.use_spring_bug)
8718 if (game.engine_version < VERSION_IDENT(2,2,0,7))
8721 for (i = 0; i < MAX_PLAYERS; i++)
8723 struct PlayerInfo *player = &stored_player[i];
8728 if (player->active && player->is_pushing && player->is_moving &&
8730 (game.engine_version < VERSION_IDENT(2,2,0,7) ||
8731 Feld[x][y] == EL_SPRING))
8733 if (player->active && player->is_pushing && player->is_moving &&
8737 ContinueMoving(x, y);
8739 /* continue moving after pushing (this is actually a bug) */
8740 if (!IS_MOVING(x, y))
8749 for (y = 0; y < lev_fieldy; y++) for (x = 0; x < lev_fieldx; x++)
8751 Changed[x][y] = CE_BITMASK_DEFAULT;
8752 ChangeEvent[x][y] = CE_BITMASK_DEFAULT;
8754 #if USE_NEW_BLOCK_STYLE
8755 /* this must be handled before main playfield loop */
8756 if (Feld[x][y] == EL_PLAYER_IS_LEAVING)
8759 if (MovDelay[x][y] <= 0)
8765 if (ChangePage[x][y] != -1 && ChangeDelay[x][y] != 1)
8767 printf("GameActions(): x = %d, y = %d: ChangePage != -1\n", x, y);
8768 printf("GameActions(): This should never happen!\n");
8770 ChangePage[x][y] = -1;
8775 if (WasJustMoving[x][y] > 0)
8776 WasJustMoving[x][y]--;
8777 if (WasJustFalling[x][y] > 0)
8778 WasJustFalling[x][y]--;
8779 if (CheckCollision[x][y] > 0)
8780 CheckCollision[x][y]--;
8785 /* reset finished pushing action (not done in ContinueMoving() to allow
8786 continous pushing animation for elements with zero push delay) */
8787 if (GfxAction[x][y] == ACTION_PUSHING && !IS_MOVING(x, y))
8789 ResetGfxAnimation(x, y);
8790 DrawLevelField(x, y);
8795 if (IS_BLOCKED(x, y))
8799 Blocked2Moving(x, y, &oldx, &oldy);
8800 if (!IS_MOVING(oldx, oldy))
8802 printf("GameActions(): (BLOCKED => MOVING) context corrupted!\n");
8803 printf("GameActions(): BLOCKED: x = %d, y = %d\n", x, y);
8804 printf("GameActions(): !MOVING: oldx = %d, oldy = %d\n", oldx, oldy);
8805 printf("GameActions(): This should never happen!\n");
8811 for (y = 0; y < lev_fieldy; y++) for (x = 0; x < lev_fieldx; x++)
8813 element = Feld[x][y];
8815 graphic = el_act_dir2img(element, GfxAction[x][y], GfxDir[x][y]);
8817 graphic = el2img(element);
8823 printf("::: %d,%d: %d [%d]\n", x, y, element, FrameCounter);
8825 element = graphic = 0;
8829 if (graphic_info[graphic].anim_global_sync)
8830 GfxFrame[x][y] = FrameCounter;
8832 if (ANIM_MODE(graphic) == ANIM_RANDOM &&
8833 IS_NEXT_FRAME(GfxFrame[x][y], graphic))
8834 ResetRandomAnimationValue(x, y);
8836 SetRandomAnimationValue(x, y);
8839 PlayLevelSoundActionIfLoop(x, y, GfxAction[x][y]);
8842 if (IS_INACTIVE(element))
8844 if (IS_ANIMATED(graphic))
8845 DrawLevelGraphicAnimationIfNeeded(x, y, graphic);
8851 /* this may take place after moving, so 'element' may have changed */
8853 if (IS_CHANGING(x, y))
8855 if (IS_CHANGING(x, y) &&
8856 (game.engine_version < VERSION_IDENT(3,0,7,1) || !Stop[x][y]))
8860 ChangeElement(x, y, ChangePage[x][y] != -1 ? ChangePage[x][y] :
8861 element_info[element].event_page_nr[CE_DELAY]);
8863 ChangeElement(x, y, element_info[element].event_page_nr[CE_DELAY]);
8866 element = Feld[x][y];
8867 graphic = el_act_dir2img(element, GfxAction[x][y], GfxDir[x][y]);
8871 if (!IS_MOVING(x, y) && (CAN_FALL(element) || CAN_MOVE(element)))
8876 element = Feld[x][y];
8877 graphic = el_act_dir2img(element, GfxAction[x][y], GfxDir[x][y]);
8879 if (element == EL_MOLE)
8880 printf("::: %d, %d, %d [%d]\n",
8881 IS_ANIMATED(graphic), IS_MOVING(x, y), Stop[x][y],
8885 if (element == EL_YAMYAM)
8886 printf("::: %d, %d, %d\n",
8887 IS_ANIMATED(graphic), IS_MOVING(x, y), Stop[x][y]);
8891 if (IS_ANIMATED(graphic) &&
8895 DrawLevelGraphicAnimationIfNeeded(x, y, graphic);
8898 if (element == EL_BUG)
8899 printf("::: %d, %d\n", graphic, GfxFrame[x][y]);
8903 if (element == EL_MOLE)
8904 printf("::: %d, %d\n", graphic, GfxFrame[x][y]);
8908 if (IS_GEM(element) || element == EL_SP_INFOTRON)
8909 EdelsteinFunkeln(x, y);
8911 else if ((element == EL_ACID ||
8912 element == EL_EXIT_OPEN ||
8913 element == EL_SP_EXIT_OPEN ||
8914 element == EL_SP_TERMINAL ||
8915 element == EL_SP_TERMINAL_ACTIVE ||
8916 element == EL_EXTRA_TIME ||
8917 element == EL_SHIELD_NORMAL ||
8918 element == EL_SHIELD_DEADLY) &&
8919 IS_ANIMATED(graphic))
8920 DrawLevelGraphicAnimationIfNeeded(x, y, graphic);
8921 else if (IS_MOVING(x, y))
8922 ContinueMoving(x, y);
8923 else if (IS_ACTIVE_BOMB(element))
8924 CheckDynamite(x, y);
8926 else if (element == EL_EXPLOSION && !game.explosions_delayed)
8927 Explode(x, y, ExplodePhase[x][y], EX_TYPE_NORMAL);
8929 else if (element == EL_AMOEBA_GROWING)
8930 AmoebeWaechst(x, y);
8931 else if (element == EL_AMOEBA_SHRINKING)
8932 AmoebaDisappearing(x, y);
8934 #if !USE_NEW_AMOEBA_CODE
8935 else if (IS_AMOEBALIVE(element))
8936 AmoebeAbleger(x, y);
8939 else if (element == EL_GAME_OF_LIFE || element == EL_BIOMAZE)
8941 else if (element == EL_EXIT_CLOSED)
8943 else if (element == EL_SP_EXIT_CLOSED)
8945 else if (element == EL_EXPANDABLE_WALL_GROWING)
8947 else if (element == EL_EXPANDABLE_WALL ||
8948 element == EL_EXPANDABLE_WALL_HORIZONTAL ||
8949 element == EL_EXPANDABLE_WALL_VERTICAL ||
8950 element == EL_EXPANDABLE_WALL_ANY)
8952 else if (element == EL_FLAMES)
8953 CheckForDragon(x, y);
8955 else if (IS_AUTO_CHANGING(element))
8956 ChangeElement(x, y);
8958 else if (element == EL_EXPLOSION)
8959 ; /* drawing of correct explosion animation is handled separately */
8960 else if (IS_ANIMATED(graphic) && !IS_CHANGING(x, y))
8961 DrawLevelGraphicAnimationIfNeeded(x, y, graphic);
8964 /* this may take place after moving, so 'element' may have changed */
8965 if (IS_AUTO_CHANGING(Feld[x][y]))
8966 ChangeElement(x, y);
8969 if (IS_BELT_ACTIVE(element))
8970 PlayLevelSoundAction(x, y, ACTION_ACTIVE);
8972 if (game.magic_wall_active)
8974 int jx = local_player->jx, jy = local_player->jy;
8976 /* play the element sound at the position nearest to the player */
8977 if ((element == EL_MAGIC_WALL_FULL ||
8978 element == EL_MAGIC_WALL_ACTIVE ||
8979 element == EL_MAGIC_WALL_EMPTYING ||
8980 element == EL_BD_MAGIC_WALL_FULL ||
8981 element == EL_BD_MAGIC_WALL_ACTIVE ||
8982 element == EL_BD_MAGIC_WALL_EMPTYING) &&
8983 ABS(x-jx) + ABS(y-jy) < ABS(magic_wall_x-jx) + ABS(magic_wall_y-jy))
8991 #if USE_NEW_AMOEBA_CODE
8992 /* new experimental amoeba growth stuff */
8994 if (!(FrameCounter % 8))
8997 static unsigned long random = 1684108901;
8999 for (i = 0; i < level.amoeba_speed * 28 / 8; i++)
9002 x = (random >> 10) % lev_fieldx;
9003 y = (random >> 20) % lev_fieldy;
9005 x = RND(lev_fieldx);
9006 y = RND(lev_fieldy);
9008 element = Feld[x][y];
9011 if (!IS_PLAYER(x,y) &&
9012 (element == EL_EMPTY ||
9013 CAN_GROW_INTO(element) ||
9014 element == EL_QUICKSAND_EMPTY ||
9015 element == EL_ACID_SPLASH_LEFT ||
9016 element == EL_ACID_SPLASH_RIGHT))
9018 if ((IN_LEV_FIELD(x, y-1) && Feld[x][y-1] == EL_AMOEBA_WET) ||
9019 (IN_LEV_FIELD(x-1, y) && Feld[x-1][y] == EL_AMOEBA_WET) ||
9020 (IN_LEV_FIELD(x+1, y) && Feld[x+1][y] == EL_AMOEBA_WET) ||
9021 (IN_LEV_FIELD(x, y+1) && Feld[x][y+1] == EL_AMOEBA_WET))
9022 Feld[x][y] = EL_AMOEBA_DROP;
9025 /* !!! extend EL_SAND to anything diggable (but maybe not SP_BASE) !!! */
9026 if (!IS_PLAYER(x,y) &&
9027 (element == EL_EMPTY ||
9028 element == EL_SAND ||
9029 element == EL_QUICKSAND_EMPTY ||
9030 element == EL_ACID_SPLASH_LEFT ||
9031 element == EL_ACID_SPLASH_RIGHT))
9033 if ((IN_LEV_FIELD(x, y-1) && Feld[x][y-1] == EL_AMOEBA_WET) ||
9034 (IN_LEV_FIELD(x-1, y) && Feld[x-1][y] == EL_AMOEBA_WET) ||
9035 (IN_LEV_FIELD(x+1, y) && Feld[x+1][y] == EL_AMOEBA_WET) ||
9036 (IN_LEV_FIELD(x, y+1) && Feld[x][y+1] == EL_AMOEBA_WET))
9037 Feld[x][y] = EL_AMOEBA_DROP;
9041 random = random * 129 + 1;
9047 if (game.explosions_delayed)
9050 game.explosions_delayed = FALSE;
9052 for (y = 0; y < lev_fieldy; y++) for (x = 0; x < lev_fieldx; x++)
9054 element = Feld[x][y];
9056 if (ExplodeField[x][y])
9057 Explode(x, y, EX_PHASE_START, ExplodeField[x][y]);
9058 else if (element == EL_EXPLOSION)
9059 Explode(x, y, ExplodePhase[x][y], EX_TYPE_NORMAL);
9061 ExplodeField[x][y] = EX_TYPE_NONE;
9064 game.explosions_delayed = TRUE;
9067 if (game.magic_wall_active)
9069 if (!(game.magic_wall_time_left % 4))
9071 int element = Feld[magic_wall_x][magic_wall_y];
9073 if (element == EL_BD_MAGIC_WALL_FULL ||
9074 element == EL_BD_MAGIC_WALL_ACTIVE ||
9075 element == EL_BD_MAGIC_WALL_EMPTYING)
9076 PlayLevelSound(magic_wall_x, magic_wall_y, SND_BD_MAGIC_WALL_ACTIVE);
9078 PlayLevelSound(magic_wall_x, magic_wall_y, SND_MAGIC_WALL_ACTIVE);
9081 if (game.magic_wall_time_left > 0)
9083 game.magic_wall_time_left--;
9084 if (!game.magic_wall_time_left)
9086 for (y = 0; y < lev_fieldy; y++) for (x = 0; x < lev_fieldx; x++)
9088 element = Feld[x][y];
9090 if (element == EL_MAGIC_WALL_ACTIVE ||
9091 element == EL_MAGIC_WALL_FULL)
9093 Feld[x][y] = EL_MAGIC_WALL_DEAD;
9094 DrawLevelField(x, y);
9096 else if (element == EL_BD_MAGIC_WALL_ACTIVE ||
9097 element == EL_BD_MAGIC_WALL_FULL)
9099 Feld[x][y] = EL_BD_MAGIC_WALL_DEAD;
9100 DrawLevelField(x, y);
9104 game.magic_wall_active = FALSE;
9109 if (game.light_time_left > 0)
9111 game.light_time_left--;
9113 if (game.light_time_left == 0)
9114 RedrawAllLightSwitchesAndInvisibleElements();
9117 if (game.timegate_time_left > 0)
9119 game.timegate_time_left--;
9121 if (game.timegate_time_left == 0)
9122 CloseAllOpenTimegates();
9125 for (i = 0; i < MAX_PLAYERS; i++)
9127 struct PlayerInfo *player = &stored_player[i];
9129 if (SHIELD_ON(player))
9131 if (player->shield_deadly_time_left)
9132 PlayLevelSound(player->jx, player->jy, SND_SHIELD_DEADLY_ACTIVE);
9133 else if (player->shield_normal_time_left)
9134 PlayLevelSound(player->jx, player->jy, SND_SHIELD_NORMAL_ACTIVE);
9138 if (TimeFrames >= FRAMES_PER_SECOND)
9143 for (i = 0; i < MAX_PLAYERS; i++)
9145 struct PlayerInfo *player = &stored_player[i];
9147 if (SHIELD_ON(player))
9149 player->shield_normal_time_left--;
9151 if (player->shield_deadly_time_left > 0)
9152 player->shield_deadly_time_left--;
9156 if (!level.use_step_counter)
9164 if (TimeLeft <= 10 && setup.time_limit)
9165 PlaySoundStereo(SND_GAME_RUNNING_OUT_OF_TIME, SOUND_MIDDLE);
9167 DrawGameValue_Time(TimeLeft);
9169 if (!TimeLeft && setup.time_limit)
9170 for (i = 0; i < MAX_PLAYERS; i++)
9171 KillHero(&stored_player[i]);
9173 else if (level.time == 0 && !AllPlayersGone) /* level w/o time limit */
9174 DrawGameValue_Time(TimePlayed);
9177 if (tape.recording || tape.playing)
9178 DrawVideoDisplay(VIDEO_STATE_TIME_ON, TapeTime);
9182 PlayAllPlayersSound();
9184 if (options.debug) /* calculate frames per second */
9186 static unsigned long fps_counter = 0;
9187 static int fps_frames = 0;
9188 unsigned long fps_delay_ms = Counter() - fps_counter;
9192 if (fps_delay_ms >= 500) /* calculate fps every 0.5 seconds */
9194 global.frames_per_second = 1000 * (float)fps_frames / fps_delay_ms;
9197 fps_counter = Counter();
9200 redraw_mask |= REDRAW_FPS;
9204 if (stored_player[0].jx != stored_player[0].last_jx ||
9205 stored_player[0].jy != stored_player[0].last_jy)
9206 printf("::: %d, %d, %d, %d, %d\n",
9207 stored_player[0].MovDir,
9208 stored_player[0].MovPos,
9209 stored_player[0].GfxPos,
9210 stored_player[0].Frame,
9211 stored_player[0].StepFrame);
9214 #if USE_NEW_MOVE_DELAY
9215 AdvanceFrameAndPlayerCounters(-1); /* advance counters for all players */
9220 for (i = 0; i < MAX_PLAYERS; i++)
9223 MOVE_DELAY_NORMAL_SPEED / stored_player[i].move_delay_value;
9225 stored_player[i].Frame += move_frames;
9227 if (stored_player[i].MovPos != 0)
9228 stored_player[i].StepFrame += move_frames;
9230 #if USE_NEW_MOVE_DELAY
9231 if (stored_player[i].move_delay > 0)
9232 stored_player[i].move_delay--;
9235 if (stored_player[i].drop_delay > 0)
9236 stored_player[i].drop_delay--;
9241 if (local_player->show_envelope != 0 && local_player->MovPos == 0)
9243 ShowEnvelope(local_player->show_envelope - EL_ENVELOPE_1);
9245 local_player->show_envelope = 0;
9249 #if USE_NEW_RANDOMIZE
9250 /* use random number generator in every frame to make it less predictable */
9251 if (game.engine_version >= VERSION_IDENT(3,1,1,0))
9256 static boolean AllPlayersInSight(struct PlayerInfo *player, int x, int y)
9258 int min_x = x, min_y = y, max_x = x, max_y = y;
9261 for (i = 0; i < MAX_PLAYERS; i++)
9263 int jx = stored_player[i].jx, jy = stored_player[i].jy;
9265 if (!stored_player[i].active || &stored_player[i] == player)
9268 min_x = MIN(min_x, jx);
9269 min_y = MIN(min_y, jy);
9270 max_x = MAX(max_x, jx);
9271 max_y = MAX(max_y, jy);
9274 return (max_x - min_x < SCR_FIELDX && max_y - min_y < SCR_FIELDY);
9277 static boolean AllPlayersInVisibleScreen()
9281 for (i = 0; i < MAX_PLAYERS; i++)
9283 int jx = stored_player[i].jx, jy = stored_player[i].jy;
9285 if (!stored_player[i].active)
9288 if (!IN_VIS_FIELD(SCREENX(jx), SCREENY(jy)))
9295 void ScrollLevel(int dx, int dy)
9297 int softscroll_offset = (setup.soft_scrolling ? TILEX : 0);
9300 BlitBitmap(drawto_field, drawto_field,
9301 FX + TILEX * (dx == -1) - softscroll_offset,
9302 FY + TILEY * (dy == -1) - softscroll_offset,
9303 SXSIZE - TILEX * (dx!=0) + 2 * softscroll_offset,
9304 SYSIZE - TILEY * (dy!=0) + 2 * softscroll_offset,
9305 FX + TILEX * (dx == 1) - softscroll_offset,
9306 FY + TILEY * (dy == 1) - softscroll_offset);
9310 x = (dx == 1 ? BX1 : BX2);
9311 for (y = BY1; y <= BY2; y++)
9312 DrawScreenField(x, y);
9317 y = (dy == 1 ? BY1 : BY2);
9318 for (x = BX1; x <= BX2; x++)
9319 DrawScreenField(x, y);
9322 redraw_mask |= REDRAW_FIELD;
9326 static boolean canEnterSupaplexPort(int x, int y, int dx, int dy)
9328 int nextx = x + dx, nexty = y + dy;
9329 int element = Feld[x][y];
9332 element != EL_SP_PORT_LEFT &&
9333 element != EL_SP_GRAVITY_PORT_LEFT &&
9334 element != EL_SP_PORT_HORIZONTAL &&
9335 element != EL_SP_PORT_ANY) ||
9337 element != EL_SP_PORT_RIGHT &&
9338 element != EL_SP_GRAVITY_PORT_RIGHT &&
9339 element != EL_SP_PORT_HORIZONTAL &&
9340 element != EL_SP_PORT_ANY) ||
9342 element != EL_SP_PORT_UP &&
9343 element != EL_SP_GRAVITY_PORT_UP &&
9344 element != EL_SP_PORT_VERTICAL &&
9345 element != EL_SP_PORT_ANY) ||
9347 element != EL_SP_PORT_DOWN &&
9348 element != EL_SP_GRAVITY_PORT_DOWN &&
9349 element != EL_SP_PORT_VERTICAL &&
9350 element != EL_SP_PORT_ANY) ||
9351 !IN_LEV_FIELD(nextx, nexty) ||
9352 !IS_FREE(nextx, nexty))
9359 static boolean canFallDown(struct PlayerInfo *player)
9361 int jx = player->jx, jy = player->jy;
9363 return (IN_LEV_FIELD(jx, jy + 1) &&
9364 (IS_FREE(jx, jy + 1) ||
9365 (Feld[jx][jy + 1] == EL_ACID && player->can_fall_into_acid)) &&
9366 IS_WALKABLE_FROM(Feld[jx][jy], MV_DOWN) &&
9367 !IS_WALKABLE_INSIDE(Feld[jx][jy]));
9370 static boolean canPassField(int x, int y, int move_dir)
9372 int opposite_dir = MV_DIR_OPPOSITE(move_dir);
9373 int dx = (move_dir & MV_LEFT ? -1 : move_dir & MV_RIGHT ? +1 : 0);
9374 int dy = (move_dir & MV_UP ? -1 : move_dir & MV_DOWN ? +1 : 0);
9377 int element = Feld[x][y];
9379 return (IS_PASSABLE_FROM(element, opposite_dir) &&
9380 !CAN_MOVE(element) &&
9381 IN_LEV_FIELD(nextx, nexty) && !IS_PLAYER(nextx, nexty) &&
9382 IS_WALKABLE_FROM(Feld[nextx][nexty], move_dir) &&
9383 (level.can_pass_to_walkable || IS_FREE(nextx, nexty)));
9386 static boolean canMoveToValidFieldWithGravity(int x, int y, int move_dir)
9388 int opposite_dir = MV_DIR_OPPOSITE(move_dir);
9389 int dx = (move_dir & MV_LEFT ? -1 : move_dir & MV_RIGHT ? +1 : 0);
9390 int dy = (move_dir & MV_UP ? -1 : move_dir & MV_DOWN ? +1 : 0);
9394 int nextx = newx + dx;
9395 int nexty = newy + dy;
9399 return (IN_LEV_FIELD(newx, newy) && !IS_FREE_OR_PLAYER(newx, newy) &&
9400 IS_GRAVITY_REACHABLE(Feld[newx][newy]) &&
9402 (!IS_SP_PORT(Feld[newx][newy]) || move_dir == MV_UP) &&
9404 (IS_DIGGABLE(Feld[newx][newy]) ||
9405 IS_WALKABLE_FROM(Feld[newx][newy], opposite_dir) ||
9406 canPassField(newx, newy, move_dir)));
9409 return (IN_LEV_FIELD(newx, newy) && !IS_FREE_OR_PLAYER(newx, newy) &&
9410 IS_GRAVITY_REACHABLE(Feld[newx][newy]) &&
9411 (IS_DIGGABLE(Feld[newx][newy]) ||
9412 IS_WALKABLE_FROM(Feld[newx][newy], opposite_dir) ||
9413 canPassField(newx, newy, move_dir)));
9416 return (IN_LEV_FIELD(newx, newy) && !IS_FREE_OR_PLAYER(newx, newy) &&
9417 (IS_DIGGABLE_WITH_GRAVITY(Feld[newx][newy]) ||
9418 IS_WALKABLE_FROM(Feld[newx][newy], opposite_dir) ||
9419 canPassField(newx, newy, move_dir)));
9421 return (IN_LEV_FIELD(newx, newy) && !IS_FREE_OR_PLAYER(newx, newy) &&
9422 (IS_DIGGABLE(Feld[newx][newy]) ||
9423 IS_WALKABLE_FROM(Feld[newx][newy], opposite_dir) ||
9424 (IS_PASSABLE_FROM(Feld[newx][newy], opposite_dir) &&
9425 !CAN_MOVE(Feld[newx][newy]) &&
9426 IN_LEV_FIELD(nextx, nexty) && !IS_PLAYER(nextx, nexty) &&
9427 IS_WALKABLE_FROM(Feld[nextx][nexty], move_dir) &&
9428 (level.can_pass_to_walkable || IS_FREE(nextx, nexty)))));
9434 static void CheckGravityMovement(struct PlayerInfo *player)
9436 if (game.gravity && !player->programmed_action)
9439 int move_dir_horizontal = player->effective_action & MV_HORIZONTAL;
9440 int move_dir_vertical = player->effective_action & MV_VERTICAL;
9442 int move_dir_horizontal = player->action & MV_HORIZONTAL;
9443 int move_dir_vertical = player->action & MV_VERTICAL;
9447 boolean player_is_snapping = player->effective_action & JOY_BUTTON_1;
9449 boolean player_is_snapping = player->action & JOY_BUTTON_1;
9452 int jx = player->jx, jy = player->jy;
9454 boolean player_is_moving_to_valid_field =
9455 (!player_is_snapping &&
9456 (canMoveToValidFieldWithGravity(jx, jy, move_dir_horizontal) ||
9457 canMoveToValidFieldWithGravity(jx, jy, move_dir_vertical)));
9461 (player->last_move_dir & MV_HORIZONTAL ?
9462 (move_dir_vertical ? move_dir_vertical : move_dir_horizontal) :
9463 (move_dir_horizontal ? move_dir_horizontal : move_dir_vertical));
9467 int opposite_dir = MV_DIR_OPPOSITE(move_dir);
9468 int dx = (move_dir & MV_LEFT ? -1 : move_dir & MV_RIGHT ? +1 : 0);
9469 int dy = (move_dir & MV_UP ? -1 : move_dir & MV_DOWN ? +1 : 0);
9470 int new_jx = jx + dx, new_jy = jy + dy;
9471 int nextx = new_jx + dx, nexty = new_jy + dy;
9477 boolean player_can_fall_down = canFallDown(player);
9479 boolean player_can_fall_down =
9480 (IN_LEV_FIELD(jx, jy + 1) &&
9481 (IS_FREE(jx, jy + 1) ||
9482 (Feld[jx][jy + 1] == EL_ACID && player->can_fall_into_acid)));
9486 boolean player_can_fall_down =
9487 (IN_LEV_FIELD(jx, jy + 1) &&
9488 (IS_FREE(jx, jy + 1)));
9492 boolean player_is_moving_to_valid_field =
9495 !player_is_snapping &&
9499 IN_LEV_FIELD(new_jx, new_jy) &&
9500 (IS_DIGGABLE(Feld[new_jx][new_jy]) ||
9501 (IS_SP_PORT(Feld[new_jx][new_jy]) &&
9502 element_info[Feld[new_jx][new_jy]].access_direction & opposite_dir &&
9503 IN_LEV_FIELD(nextx, nexty) &&
9504 element_info[Feld[nextx][nexty]].access_direction & move_dir))
9506 IN_LEV_FIELD(new_jx, new_jy) &&
9507 (Feld[new_jx][new_jy] == EL_SP_BASE ||
9508 Feld[new_jx][new_jy] == EL_SAND ||
9509 (IS_SP_PORT(Feld[new_jx][new_jy]) &&
9510 canEnterSupaplexPort(new_jx, new_jy, dx, dy)))
9511 /* !!! extend EL_SAND to anything diggable !!! */
9517 boolean player_is_standing_on_valid_field =
9518 (IS_WALKABLE_INSIDE(Feld[jx][jy]) ||
9519 (IS_WALKABLE(Feld[jx][jy]) && !ACCESS_FROM(Feld[jx][jy], MV_DOWN)));
9523 printf("::: checking gravity NOW [%d, %d, %d] [%d] [%d / %d] ...\n",
9524 player_can_fall_down,
9525 player_is_standing_on_valid_field,
9526 player_is_moving_to_valid_field,
9527 (player_is_moving_to_valid_field ? Feld[new_jx][new_jy] : -1),
9528 player->effective_action,
9529 player->can_fall_into_acid);
9532 if (player_can_fall_down &&
9534 !player_is_standing_on_valid_field &&
9536 !player_is_moving_to_valid_field)
9539 printf("::: setting programmed_action to MV_DOWN [%d,%d - %d] ...\n",
9540 jx, jy, FrameCounter);
9543 player->programmed_action = MV_DOWN;
9548 static void CheckGravityMovementWhenNotMoving(struct PlayerInfo *player)
9551 return CheckGravityMovement(player);
9554 if (game.gravity && !player->programmed_action)
9556 int jx = player->jx, jy = player->jy;
9557 boolean field_under_player_is_free =
9558 (IN_LEV_FIELD(jx, jy + 1) && IS_FREE(jx, jy + 1));
9559 boolean player_is_standing_on_valid_field =
9560 (IS_WALKABLE_INSIDE(Feld[jx][jy]) ||
9561 (IS_WALKABLE(Feld[jx][jy]) &&
9562 !(element_info[Feld[jx][jy]].access_direction & MV_DOWN)));
9564 if (field_under_player_is_free && !player_is_standing_on_valid_field)
9565 player->programmed_action = MV_DOWN;
9571 -----------------------------------------------------------------------------
9572 dx, dy: direction (non-diagonal) to try to move the player to
9573 real_dx, real_dy: direction as read from input device (can be diagonal)
9576 boolean MovePlayerOneStep(struct PlayerInfo *player,
9577 int dx, int dy, int real_dx, int real_dy)
9580 static int trigger_sides[4][2] =
9582 /* enter side leave side */
9583 { CH_SIDE_RIGHT, CH_SIDE_LEFT }, /* moving left */
9584 { CH_SIDE_LEFT, CH_SIDE_RIGHT }, /* moving right */
9585 { CH_SIDE_BOTTOM, CH_SIDE_TOP }, /* moving up */
9586 { CH_SIDE_TOP, CH_SIDE_BOTTOM } /* moving down */
9588 int move_direction = (dx == -1 ? MV_LEFT :
9589 dx == +1 ? MV_RIGHT :
9591 dy == +1 ? MV_DOWN : MV_NO_MOVING);
9592 int enter_side = trigger_sides[MV_DIR_BIT(move_direction)][0];
9593 int leave_side = trigger_sides[MV_DIR_BIT(move_direction)][1];
9595 int jx = player->jx, jy = player->jy;
9596 int new_jx = jx + dx, new_jy = jy + dy;
9600 if (!player->active || (!dx && !dy))
9601 return MF_NO_ACTION;
9603 player->MovDir = (dx < 0 ? MV_LEFT :
9606 dy > 0 ? MV_DOWN : MV_NO_MOVING);
9608 if (!IN_LEV_FIELD(new_jx, new_jy))
9609 return MF_NO_ACTION;
9611 if (!options.network && !AllPlayersInSight(player, new_jx, new_jy))
9612 return MF_NO_ACTION;
9615 element = MovingOrBlocked2Element(new_jx, new_jy);
9617 element = MovingOrBlocked2ElementIfNotLeaving(new_jx, new_jy);
9620 if (DONT_RUN_INTO(element))
9622 if (element == EL_ACID && dx == 0 && dy == 1)
9624 SplashAcid(new_jx, new_jy);
9625 Feld[jx][jy] = EL_PLAYER_1;
9626 InitMovingField(jx, jy, MV_DOWN);
9627 Store[jx][jy] = EL_ACID;
9628 ContinueMoving(jx, jy);
9632 TestIfHeroRunsIntoBadThing(jx, jy, player->MovDir);
9637 can_move = DigField(player, jx, jy, new_jx, new_jy, real_dx,real_dy, DF_DIG);
9638 if (can_move != MF_MOVING)
9641 /* check if DigField() has caused relocation of the player */
9642 if (player->jx != jx || player->jy != jy)
9643 return MF_NO_ACTION;
9645 StorePlayer[jx][jy] = 0;
9646 player->last_jx = jx;
9647 player->last_jy = jy;
9648 player->jx = new_jx;
9649 player->jy = new_jy;
9650 StorePlayer[new_jx][new_jy] = player->element_nr;
9653 (dx > 0 || dy > 0 ? -1 : 1) * (TILEX - TILEX / player->move_delay_value);
9655 player->step_counter++;
9658 player->drop_delay = 0;
9661 PlayerVisit[jx][jy] = FrameCounter;
9663 ScrollPlayer(player, SCROLL_INIT);
9666 if (IS_CUSTOM_ELEMENT(Feld[jx][jy]))
9668 CheckTriggeredElementChangeBySide(jx, jy, Feld[jx][jy], CE_OTHER_GETS_LEFT,
9670 CheckElementChangeBySide(jx,jy, Feld[jx][jy],CE_LEFT_BY_PLAYER,leave_side);
9673 if (IS_CUSTOM_ELEMENT(Feld[new_jx][new_jy]))
9675 CheckTriggeredElementChangeBySide(new_jx, new_jy, Feld[new_jx][new_jy],
9676 CE_OTHER_GETS_ENTERED, enter_side);
9677 CheckElementChangeBySide(new_jx, new_jy, Feld[new_jx][new_jy],
9678 CE_ENTERED_BY_PLAYER, enter_side);
9685 boolean MovePlayer(struct PlayerInfo *player, int dx, int dy)
9687 int jx = player->jx, jy = player->jy;
9688 int old_jx = jx, old_jy = jy;
9689 int moved = MF_NO_ACTION;
9692 if (!player->active)
9697 if (player->MovPos == 0)
9699 player->is_moving = FALSE;
9700 player->is_digging = FALSE;
9701 player->is_collecting = FALSE;
9702 player->is_snapping = FALSE;
9703 player->is_pushing = FALSE;
9709 if (!player->active || (!dx && !dy))
9714 if (!FrameReached(&player->move_delay, player->move_delay_value) &&
9722 printf("::: %d <= %d < %d ?\n", player->move_delay, FrameCounter,
9723 player->move_delay + player->move_delay_value);
9726 #if USE_NEW_MOVE_DELAY
9727 if (player->move_delay > 0)
9729 if (!FrameReached(&player->move_delay, player->move_delay_value))
9733 printf("::: can NOT move\n");
9739 if (!FrameReached(&player->move_delay, player->move_delay_value) &&
9740 !(tape.playing && tape.file_version < FILE_VERSION_2_0))
9747 printf("::: COULD move now\n");
9750 #if USE_NEW_MOVE_DELAY
9751 player->move_delay = -1; /* set to "uninitialized" value */
9754 /* store if player is automatically moved to next field */
9755 player->is_auto_moving = (player->programmed_action != MV_NO_MOVING);
9757 /* remove the last programmed player action */
9758 player->programmed_action = 0;
9762 /* should only happen if pre-1.2 tape recordings are played */
9763 /* this is only for backward compatibility */
9765 int original_move_delay_value = player->move_delay_value;
9768 printf("THIS SHOULD ONLY HAPPEN WITH PRE-1.2 LEVEL TAPES. [%ld]\n",
9772 /* scroll remaining steps with finest movement resolution */
9773 player->move_delay_value = MOVE_DELAY_NORMAL_SPEED;
9775 while (player->MovPos)
9777 ScrollPlayer(player, SCROLL_GO_ON);
9778 ScrollScreen(NULL, SCROLL_GO_ON);
9780 #if USE_NEW_MOVE_DELAY
9781 AdvanceFrameAndPlayerCounters(player->index_nr);
9790 player->move_delay_value = original_move_delay_value;
9793 if (player->last_move_dir & MV_HORIZONTAL)
9795 if (!(moved |= MovePlayerOneStep(player, 0, dy, dx, dy)))
9796 moved |= MovePlayerOneStep(player, dx, 0, dx, dy);
9800 if (!(moved |= MovePlayerOneStep(player, dx, 0, dx, dy)))
9801 moved |= MovePlayerOneStep(player, 0, dy, dx, dy);
9807 if (moved & MF_MOVING && !ScreenMovPos &&
9808 (player == local_player || !options.network))
9810 int old_scroll_x = scroll_x, old_scroll_y = scroll_y;
9811 int offset = (setup.scroll_delay ? 3 : 0);
9813 if (!IN_VIS_FIELD(SCREENX(jx), SCREENY(jy)))
9815 /* actual player has left the screen -- scroll in that direction */
9816 if (jx != old_jx) /* player has moved horizontally */
9817 scroll_x += (jx - old_jx);
9818 else /* player has moved vertically */
9819 scroll_y += (jy - old_jy);
9823 if (jx != old_jx) /* player has moved horizontally */
9825 if ((player->MovDir == MV_LEFT && scroll_x > jx - MIDPOSX + offset) ||
9826 (player->MovDir == MV_RIGHT && scroll_x < jx - MIDPOSX - offset))
9827 scroll_x = jx-MIDPOSX + (scroll_x < jx-MIDPOSX ? -offset : +offset);
9829 /* don't scroll over playfield boundaries */
9830 if (scroll_x < SBX_Left || scroll_x > SBX_Right)
9831 scroll_x = (scroll_x < SBX_Left ? SBX_Left : SBX_Right);
9833 /* don't scroll more than one field at a time */
9834 scroll_x = old_scroll_x + SIGN(scroll_x - old_scroll_x);
9836 /* don't scroll against the player's moving direction */
9837 if ((player->MovDir == MV_LEFT && scroll_x > old_scroll_x) ||
9838 (player->MovDir == MV_RIGHT && scroll_x < old_scroll_x))
9839 scroll_x = old_scroll_x;
9841 else /* player has moved vertically */
9843 if ((player->MovDir == MV_UP && scroll_y > jy - MIDPOSY + offset) ||
9844 (player->MovDir == MV_DOWN && scroll_y < jy - MIDPOSY - offset))
9845 scroll_y = jy-MIDPOSY + (scroll_y < jy-MIDPOSY ? -offset : +offset);
9847 /* don't scroll over playfield boundaries */
9848 if (scroll_y < SBY_Upper || scroll_y > SBY_Lower)
9849 scroll_y = (scroll_y < SBY_Upper ? SBY_Upper : SBY_Lower);
9851 /* don't scroll more than one field at a time */
9852 scroll_y = old_scroll_y + SIGN(scroll_y - old_scroll_y);
9854 /* don't scroll against the player's moving direction */
9855 if ((player->MovDir == MV_UP && scroll_y > old_scroll_y) ||
9856 (player->MovDir == MV_DOWN && scroll_y < old_scroll_y))
9857 scroll_y = old_scroll_y;
9861 if (scroll_x != old_scroll_x || scroll_y != old_scroll_y)
9863 if (!options.network && !AllPlayersInVisibleScreen())
9865 scroll_x = old_scroll_x;
9866 scroll_y = old_scroll_y;
9870 ScrollScreen(player, SCROLL_INIT);
9871 ScrollLevel(old_scroll_x - scroll_x, old_scroll_y - scroll_y);
9878 InitPlayerGfxAnimation(player, ACTION_DEFAULT);
9880 if (!(moved & MF_MOVING) && !player->is_pushing)
9885 player->StepFrame = 0;
9887 if (moved & MF_MOVING)
9890 printf("::: REALLY moves now\n");
9893 if (old_jx != jx && old_jy == jy)
9894 player->MovDir = (old_jx < jx ? MV_RIGHT : MV_LEFT);
9895 else if (old_jx == jx && old_jy != jy)
9896 player->MovDir = (old_jy < jy ? MV_DOWN : MV_UP);
9898 DrawLevelField(jx, jy); /* for "crumbled sand" */
9900 player->last_move_dir = player->MovDir;
9901 player->is_moving = TRUE;
9903 player->is_snapping = FALSE;
9907 player->is_switching = FALSE;
9910 player->is_dropping = FALSE;
9914 /* !!! ENABLE THIS FOR OLD VERSIONS !!! */
9917 if (game.engine_version < VERSION_IDENT(3,1,0,0))
9920 int move_direction = player->MovDir;
9922 int enter_side = MV_DIR_OPPOSITE(move_direction);
9923 int leave_side = move_direction;
9925 static int trigger_sides[4][2] =
9927 /* enter side leave side */
9928 { CH_SIDE_RIGHT, CH_SIDE_LEFT }, /* moving left */
9929 { CH_SIDE_LEFT, CH_SIDE_RIGHT }, /* moving right */
9930 { CH_SIDE_BOTTOM, CH_SIDE_TOP }, /* moving up */
9931 { CH_SIDE_TOP, CH_SIDE_BOTTOM } /* moving down */
9933 int enter_side = trigger_sides[MV_DIR_BIT(move_direction)][0];
9934 int leave_side = trigger_sides[MV_DIR_BIT(move_direction)][1];
9936 int old_element = Feld[old_jx][old_jy];
9937 int new_element = Feld[jx][jy];
9940 /* !!! TEST ONLY !!! */
9941 if (IS_CUSTOM_ELEMENT(old_element))
9942 CheckElementChangeByPlayer(old_jx, old_jy, old_element,
9944 player->index_bit, leave_side);
9946 CheckTriggeredElementChangeByPlayer(old_jx, old_jy, old_element,
9948 player->index_bit, leave_side);
9950 if (IS_CUSTOM_ELEMENT(new_element))
9951 CheckElementChangeByPlayer(jx, jy, new_element, CE_ENTERED_BY_PLAYER,
9952 player->index_bit, enter_side);
9954 CheckTriggeredElementChangeByPlayer(jx, jy, new_element,
9955 CE_OTHER_GETS_ENTERED,
9956 player->index_bit, enter_side);
9966 CheckGravityMovementWhenNotMoving(player);
9969 player->last_move_dir = MV_NO_MOVING;
9971 player->is_moving = FALSE;
9973 #if USE_NEW_MOVE_STYLE
9974 /* player is ALLOWED to move, but CANNOT move (something blocks his way) */
9975 /* ensure that the player is also allowed to move in the next frame */
9976 /* (currently, the player is forced to wait eight frames before he can try
9979 if (game.engine_version >= VERSION_IDENT(3,1,1,0))
9980 player->move_delay = 0; /* allow direct movement in the next frame */
9984 #if USE_NEW_MOVE_DELAY
9985 if (player->move_delay == -1) /* not yet initialized by DigField() */
9986 player->move_delay = player->move_delay_value;
9989 if (game.engine_version < VERSION_IDENT(3,0,7,0))
9991 TestIfHeroTouchesBadThing(jx, jy);
9992 TestIfPlayerTouchesCustomElement(jx, jy);
9995 if (!player->active)
10001 void ScrollPlayer(struct PlayerInfo *player, int mode)
10003 int jx = player->jx, jy = player->jy;
10004 int last_jx = player->last_jx, last_jy = player->last_jy;
10005 int move_stepsize = TILEX / player->move_delay_value;
10007 if (!player->active || !player->MovPos)
10010 if (mode == SCROLL_INIT)
10012 player->actual_frame_counter = FrameCounter;
10013 player->GfxPos = move_stepsize * (player->MovPos / move_stepsize);
10016 printf("::: %06d: %d,%d: %d (%d) [%d]\n",
10018 last_jx, last_jy, Feld[last_jx][last_jy], EL_EXPLOSION,
10019 player->block_delay);
10022 #if USE_NEW_BLOCK_STYLE
10025 if (player->block_delay <= 0)
10026 printf("::: ALERT! block_delay == %d\n", player->block_delay);
10029 if (player->block_delay > 0 &&
10030 Feld[last_jx][last_jy] == EL_EMPTY)
10032 Feld[last_jx][last_jy] = EL_PLAYER_IS_LEAVING;
10033 MovDelay[last_jx][last_jy] = player->block_delay + 1;
10036 #if USE_NEW_MOVE_STYLE
10037 if ((game.engine_version < VERSION_IDENT(3,1,1,0) ||
10038 player->block_last_field) &&
10039 Feld[last_jx][last_jy] == EL_EMPTY)
10040 Feld[last_jx][last_jy] = EL_PLAYER_IS_LEAVING;
10042 if (Feld[last_jx][last_jy] == EL_EMPTY)
10043 Feld[last_jx][last_jy] = EL_PLAYER_IS_LEAVING;
10048 DrawPlayer(player);
10053 else if (!FrameReached(&player->actual_frame_counter, 1))
10056 player->MovPos += (player->MovPos > 0 ? -1 : 1) * move_stepsize;
10057 player->GfxPos = move_stepsize * (player->MovPos / move_stepsize);
10059 #if USE_NEW_BLOCK_STYLE
10061 if (!player->block_last_field &&
10062 Feld[last_jx][last_jy] == EL_PLAYER_IS_LEAVING)
10064 RemoveField(last_jx, last_jy);
10066 Feld[last_jx][last_jy] = EL_EMPTY;
10070 /* before DrawPlayer() to draw correct player graphic for this case */
10071 if (player->MovPos == 0)
10072 CheckGravityMovement(player);
10075 DrawPlayer(player); /* needed here only to cleanup last field */
10078 if (player->MovPos == 0) /* player reached destination field */
10081 if (player->move_delay_reset_counter > 0)
10083 player->move_delay_reset_counter--;
10085 if (player->move_delay_reset_counter == 0)
10087 /* continue with normal speed after quickly moving through gate */
10088 HALVE_PLAYER_SPEED(player);
10090 /* be able to make the next move without delay */
10091 player->move_delay = 0;
10095 if (IS_PASSABLE(Feld[last_jx][last_jy]))
10097 /* continue with normal speed after quickly moving through gate */
10098 HALVE_PLAYER_SPEED(player);
10100 /* be able to make the next move without delay */
10101 player->move_delay = 0;
10105 #if USE_NEW_BLOCK_STYLE
10107 if (player->block_last_field &&
10108 Feld[last_jx][last_jy] == EL_PLAYER_IS_LEAVING)
10110 RemoveField(last_jx, last_jy);
10112 Feld[last_jx][last_jy] = EL_EMPTY;
10116 player->last_jx = jx;
10117 player->last_jy = jy;
10119 if (Feld[jx][jy] == EL_EXIT_OPEN ||
10120 Feld[jx][jy] == EL_SP_EXIT_OPEN ||
10121 Feld[jx][jy] == EL_SP_EXIT_OPENING) /* <-- special case */
10123 DrawPlayer(player); /* needed here only to cleanup last field */
10124 RemoveHero(player);
10126 if (local_player->friends_still_needed == 0 ||
10127 IS_SP_ELEMENT(Feld[jx][jy]))
10128 player->LevelSolved = player->GameOver = TRUE;
10132 /* !!! ENABLE THIS FOR NEW VERSIONS !!! */
10133 /* this breaks one level: "machine", level 000 */
10135 if (game.engine_version >= VERSION_IDENT(3,1,0,0))
10138 int move_direction = player->MovDir;
10140 int enter_side = MV_DIR_OPPOSITE(move_direction);
10141 int leave_side = move_direction;
10143 static int trigger_sides[4][2] =
10145 /* enter side leave side */
10146 { CH_SIDE_RIGHT, CH_SIDE_LEFT }, /* moving left */
10147 { CH_SIDE_LEFT, CH_SIDE_RIGHT }, /* moving right */
10148 { CH_SIDE_BOTTOM, CH_SIDE_TOP }, /* moving up */
10149 { CH_SIDE_TOP, CH_SIDE_BOTTOM } /* moving down */
10151 int enter_side = trigger_sides[MV_DIR_BIT(move_direction)][0];
10152 int leave_side = trigger_sides[MV_DIR_BIT(move_direction)][1];
10154 int old_jx = last_jx;
10155 int old_jy = last_jy;
10156 int old_element = Feld[old_jx][old_jy];
10157 int new_element = Feld[jx][jy];
10160 /* !!! TEST ONLY !!! */
10161 if (IS_CUSTOM_ELEMENT(old_element))
10162 CheckElementChangeByPlayer(old_jx, old_jy, old_element,
10164 player->index_bit, leave_side);
10166 CheckTriggeredElementChangeByPlayer(old_jx, old_jy, old_element,
10167 CE_OTHER_GETS_LEFT,
10168 player->index_bit, leave_side);
10170 if (IS_CUSTOM_ELEMENT(new_element))
10171 CheckElementChangeByPlayer(jx, jy, new_element, CE_ENTERED_BY_PLAYER,
10172 player->index_bit, enter_side);
10174 CheckTriggeredElementChangeByPlayer(jx, jy, new_element,
10175 CE_OTHER_GETS_ENTERED,
10176 player->index_bit, enter_side);
10182 if (game.engine_version >= VERSION_IDENT(3,0,7,0))
10184 TestIfHeroTouchesBadThing(jx, jy);
10185 TestIfPlayerTouchesCustomElement(jx, jy);
10188 /* needed because pushed element has not yet reached its destination,
10189 so it would trigger a change event at its previous field location */
10190 if (!player->is_pushing)
10192 TestIfElementTouchesCustomElement(jx, jy); /* for empty space */
10195 if (!player->active)
10196 RemoveHero(player);
10199 if (level.use_step_counter)
10209 if (TimeLeft <= 10 && setup.time_limit)
10210 PlaySoundStereo(SND_GAME_RUNNING_OUT_OF_TIME, SOUND_MIDDLE);
10212 DrawGameValue_Time(TimeLeft);
10214 if (!TimeLeft && setup.time_limit)
10215 for (i = 0; i < MAX_PLAYERS; i++)
10216 KillHero(&stored_player[i]);
10218 else if (level.time == 0 && !AllPlayersGone) /* level w/o time limit */
10219 DrawGameValue_Time(TimePlayed);
10222 if (tape.single_step && tape.recording && !tape.pausing &&
10223 !player->programmed_action)
10224 TapeTogglePause(TAPE_TOGGLE_AUTOMATIC);
10228 void ScrollScreen(struct PlayerInfo *player, int mode)
10230 static unsigned long screen_frame_counter = 0;
10232 if (mode == SCROLL_INIT)
10234 /* set scrolling step size according to actual player's moving speed */
10235 ScrollStepSize = TILEX / player->move_delay_value;
10237 screen_frame_counter = FrameCounter;
10238 ScreenMovDir = player->MovDir;
10239 ScreenMovPos = player->MovPos;
10240 ScreenGfxPos = ScrollStepSize * (ScreenMovPos / ScrollStepSize);
10243 else if (!FrameReached(&screen_frame_counter, 1))
10248 ScreenMovPos += (ScreenMovPos > 0 ? -1 : 1) * ScrollStepSize;
10249 ScreenGfxPos = ScrollStepSize * (ScreenMovPos / ScrollStepSize);
10250 redraw_mask |= REDRAW_FIELD;
10253 ScreenMovDir = MV_NO_MOVING;
10256 void TestIfPlayerTouchesCustomElement(int x, int y)
10258 static int xy[4][2] =
10265 static int trigger_sides[4][2] =
10267 /* center side border side */
10268 { CH_SIDE_TOP, CH_SIDE_BOTTOM }, /* check top */
10269 { CH_SIDE_LEFT, CH_SIDE_RIGHT }, /* check left */
10270 { CH_SIDE_RIGHT, CH_SIDE_LEFT }, /* check right */
10271 { CH_SIDE_BOTTOM, CH_SIDE_TOP } /* check bottom */
10273 static int touch_dir[4] =
10275 MV_LEFT | MV_RIGHT,
10280 int center_element = Feld[x][y]; /* should always be non-moving! */
10283 for (i = 0; i < NUM_DIRECTIONS; i++)
10285 int xx = x + xy[i][0];
10286 int yy = y + xy[i][1];
10287 int center_side = trigger_sides[i][0];
10288 int border_side = trigger_sides[i][1];
10289 int border_element;
10291 if (!IN_LEV_FIELD(xx, yy))
10294 if (IS_PLAYER(x, y))
10296 struct PlayerInfo *player = PLAYERINFO(x, y);
10298 if (game.engine_version < VERSION_IDENT(3,0,7,0))
10299 border_element = Feld[xx][yy]; /* may be moving! */
10300 else if (!IS_MOVING(xx, yy) && !IS_BLOCKED(xx, yy))
10301 border_element = Feld[xx][yy];
10302 else if (MovDir[xx][yy] & touch_dir[i]) /* elements are touching */
10303 border_element = MovingOrBlocked2Element(xx, yy);
10305 continue; /* center and border element do not touch */
10308 /* !!! TEST ONLY !!! */
10309 CheckElementChangeByPlayer(xx, yy, border_element, CE_TOUCHED_BY_PLAYER,
10310 player->index_bit, border_side);
10311 CheckTriggeredElementChangeByPlayer(xx, yy, border_element,
10312 CE_OTHER_GETS_TOUCHED,
10313 player->index_bit, border_side);
10315 CheckTriggeredElementChangeByPlayer(xx, yy, border_element,
10316 CE_OTHER_GETS_TOUCHED,
10317 player->index_bit, border_side);
10318 CheckElementChangeByPlayer(xx, yy, border_element, CE_TOUCHED_BY_PLAYER,
10319 player->index_bit, border_side);
10322 else if (IS_PLAYER(xx, yy))
10324 struct PlayerInfo *player = PLAYERINFO(xx, yy);
10326 if (game.engine_version >= VERSION_IDENT(3,0,7,0))
10328 if (player->MovPos != 0 && !(player->MovDir & touch_dir[i]))
10329 continue; /* center and border element do not touch */
10333 /* !!! TEST ONLY !!! */
10334 CheckElementChangeByPlayer(x, y, center_element, CE_TOUCHED_BY_PLAYER,
10335 player->index_bit, center_side);
10336 CheckTriggeredElementChangeByPlayer(x, y, center_element,
10337 CE_OTHER_GETS_TOUCHED,
10338 player->index_bit, center_side);
10340 CheckTriggeredElementChangeByPlayer(x, y, center_element,
10341 CE_OTHER_GETS_TOUCHED,
10342 player->index_bit, center_side);
10343 CheckElementChangeByPlayer(x, y, center_element, CE_TOUCHED_BY_PLAYER,
10344 player->index_bit, center_side);
10352 void TestIfElementTouchesCustomElement(int x, int y)
10354 static int xy[4][2] =
10361 static int trigger_sides[4][2] =
10363 /* center side border side */
10364 { CH_SIDE_TOP, CH_SIDE_BOTTOM }, /* check top */
10365 { CH_SIDE_LEFT, CH_SIDE_RIGHT }, /* check left */
10366 { CH_SIDE_RIGHT, CH_SIDE_LEFT }, /* check right */
10367 { CH_SIDE_BOTTOM, CH_SIDE_TOP } /* check bottom */
10369 static int touch_dir[4] =
10371 MV_LEFT | MV_RIGHT,
10376 boolean change_center_element = FALSE;
10377 int center_element_change_page = 0;
10378 int center_element = Feld[x][y]; /* should always be non-moving! */
10379 int border_trigger_element = EL_UNDEFINED;
10382 for (i = 0; i < NUM_DIRECTIONS; i++)
10384 int xx = x + xy[i][0];
10385 int yy = y + xy[i][1];
10386 int center_side = trigger_sides[i][0];
10387 int border_side = trigger_sides[i][1];
10388 int border_element;
10390 if (!IN_LEV_FIELD(xx, yy))
10393 if (game.engine_version < VERSION_IDENT(3,0,7,0))
10394 border_element = Feld[xx][yy]; /* may be moving! */
10395 else if (!IS_MOVING(xx, yy) && !IS_BLOCKED(xx, yy))
10396 border_element = Feld[xx][yy];
10397 else if (MovDir[xx][yy] & touch_dir[i]) /* elements are touching */
10398 border_element = MovingOrBlocked2Element(xx, yy);
10400 continue; /* center and border element do not touch */
10402 /* check for change of center element (but change it only once) */
10403 if (IS_CUSTOM_ELEMENT(center_element) &&
10404 HAS_ANY_CHANGE_EVENT(center_element, CE_OTHER_IS_TOUCHING) &&
10405 !change_center_element)
10407 for (j = 0; j < element_info[center_element].num_change_pages; j++)
10409 struct ElementChangeInfo *change =
10410 &element_info[center_element].change_page[j];
10412 if (change->can_change &&
10413 change->events & CH_EVENT_BIT(CE_OTHER_IS_TOUCHING) &&
10414 change->trigger_side & border_side &&
10416 IS_EQUAL_OR_IN_GROUP(border_element, change->trigger_element)
10418 change->trigger_element == border_element
10422 change_center_element = TRUE;
10423 center_element_change_page = j;
10424 border_trigger_element = border_element;
10431 /* check for change of border element */
10432 if (IS_CUSTOM_ELEMENT(border_element) &&
10433 HAS_ANY_CHANGE_EVENT(border_element, CE_OTHER_IS_TOUCHING))
10435 for (j = 0; j < element_info[border_element].num_change_pages; j++)
10437 struct ElementChangeInfo *change =
10438 &element_info[border_element].change_page[j];
10440 if (change->can_change &&
10441 change->events & CH_EVENT_BIT(CE_OTHER_IS_TOUCHING) &&
10442 change->trigger_side & center_side &&
10444 IS_EQUAL_OR_IN_GROUP(center_element, change->trigger_element)
10446 change->trigger_element == center_element
10451 printf("::: border_element %d, %d\n", x, y);
10454 CheckElementChangeByPage(xx, yy, border_element, center_element,
10455 CE_OTHER_IS_TOUCHING, j);
10462 if (change_center_element)
10465 printf("::: center_element %d, %d\n", x, y);
10468 CheckElementChangeByPage(x, y, center_element, border_trigger_element,
10469 CE_OTHER_IS_TOUCHING, center_element_change_page);
10473 void TestIfElementHitsCustomElement(int x, int y, int direction)
10475 int dx = (direction == MV_LEFT ? -1 : direction == MV_RIGHT ? +1 : 0);
10476 int dy = (direction == MV_UP ? -1 : direction == MV_DOWN ? +1 : 0);
10477 int hitx = x + dx, hity = y + dy;
10478 int hitting_element = Feld[x][y];
10479 int touched_element;
10481 boolean object_hit = (IN_LEV_FIELD(hitx, hity) &&
10482 !IS_FREE(hitx, hity) &&
10483 (!IS_MOVING(hitx, hity) ||
10484 MovDir[hitx][hity] != direction ||
10485 ABS(MovPos[hitx][hity]) <= TILEY / 2));
10488 if (IN_LEV_FIELD(hitx, hity) && IS_FREE(hitx, hity))
10492 if (IN_LEV_FIELD(hitx, hity) && !object_hit)
10496 touched_element = (IN_LEV_FIELD(hitx, hity) ?
10497 MovingOrBlocked2Element(hitx, hity) : EL_STEELWALL);
10499 CheckElementChangeBySide(x, y, hitting_element, touched_element,
10500 CE_HITTING_SOMETHING, direction);
10502 if (IN_LEV_FIELD(hitx, hity))
10504 int opposite_direction = MV_DIR_OPPOSITE(direction);
10505 int hitting_side = direction;
10506 int touched_side = opposite_direction;
10508 int touched_element = MovingOrBlocked2Element(hitx, hity);
10511 boolean object_hit = (!IS_MOVING(hitx, hity) ||
10512 MovDir[hitx][hity] != direction ||
10513 ABS(MovPos[hitx][hity]) <= TILEY / 2);
10522 CheckElementChangeBySide(hitx, hity, touched_element, hitting_element,
10523 CE_HIT_BY_SOMETHING, opposite_direction);
10525 if (IS_CUSTOM_ELEMENT(hitting_element) &&
10526 HAS_ANY_CHANGE_EVENT(hitting_element, CE_OTHER_IS_HITTING))
10528 for (i = 0; i < element_info[hitting_element].num_change_pages; i++)
10530 struct ElementChangeInfo *change =
10531 &element_info[hitting_element].change_page[i];
10533 if (change->can_change &&
10534 change->events & CH_EVENT_BIT(CE_OTHER_IS_HITTING) &&
10535 change->trigger_side & touched_side &&
10538 IS_EQUAL_OR_IN_GROUP(touched_element, change->trigger_element)
10540 change->trigger_element == touched_element
10544 CheckElementChangeByPage(x, y, hitting_element, touched_element,
10545 CE_OTHER_IS_HITTING, i);
10551 if (IS_CUSTOM_ELEMENT(touched_element) &&
10552 HAS_ANY_CHANGE_EVENT(touched_element, CE_OTHER_GETS_HIT))
10554 for (i = 0; i < element_info[touched_element].num_change_pages; i++)
10556 struct ElementChangeInfo *change =
10557 &element_info[touched_element].change_page[i];
10559 if (change->can_change &&
10560 change->events & CH_EVENT_BIT(CE_OTHER_GETS_HIT) &&
10561 change->trigger_side & hitting_side &&
10563 IS_EQUAL_OR_IN_GROUP(hitting_element, change->trigger_element)
10565 change->trigger_element == hitting_element
10569 CheckElementChangeByPage(hitx, hity, touched_element,
10570 hitting_element, CE_OTHER_GETS_HIT, i);
10580 void TestIfElementSmashesCustomElement(int x, int y, int direction)
10582 int dx = (direction == MV_LEFT ? -1 : direction == MV_RIGHT ? +1 : 0);
10583 int dy = (direction == MV_UP ? -1 : direction == MV_DOWN ? +1 : 0);
10584 int hitx = x + dx, hity = y + dy;
10585 int hitting_element = Feld[x][y];
10586 int touched_element;
10588 boolean object_hit = (IN_LEV_FIELD(hitx, hity) &&
10589 !IS_FREE(hitx, hity) &&
10590 (!IS_MOVING(hitx, hity) ||
10591 MovDir[hitx][hity] != direction ||
10592 ABS(MovPos[hitx][hity]) <= TILEY / 2));
10595 if (IN_LEV_FIELD(hitx, hity) && IS_FREE(hitx, hity))
10599 if (IN_LEV_FIELD(hitx, hity) && !object_hit)
10603 touched_element = (IN_LEV_FIELD(hitx, hity) ?
10604 MovingOrBlocked2Element(hitx, hity) : EL_STEELWALL);
10606 CheckElementChangeBySide(x, y, hitting_element, touched_element,
10607 EP_CAN_SMASH_EVERYTHING, direction);
10609 if (IN_LEV_FIELD(hitx, hity))
10611 int opposite_direction = MV_DIR_OPPOSITE(direction);
10612 int hitting_side = direction;
10613 int touched_side = opposite_direction;
10615 int touched_element = MovingOrBlocked2Element(hitx, hity);
10618 boolean object_hit = (!IS_MOVING(hitx, hity) ||
10619 MovDir[hitx][hity] != direction ||
10620 ABS(MovPos[hitx][hity]) <= TILEY / 2);
10629 CheckElementChangeBySide(hitx, hity, touched_element, hitting_element,
10630 CE_SMASHED_BY_SOMETHING, opposite_direction);
10632 if (IS_CUSTOM_ELEMENT(hitting_element) &&
10633 HAS_ANY_CHANGE_EVENT(hitting_element, CE_OTHER_IS_SMASHING))
10635 for (i = 0; i < element_info[hitting_element].num_change_pages; i++)
10637 struct ElementChangeInfo *change =
10638 &element_info[hitting_element].change_page[i];
10640 if (change->can_change &&
10641 change->events & CH_EVENT_BIT(CE_OTHER_IS_SMASHING) &&
10642 change->trigger_side & touched_side &&
10645 IS_EQUAL_OR_IN_GROUP(touched_element, change->trigger_element)
10647 change->trigger_element == touched_element
10651 CheckElementChangeByPage(x, y, hitting_element, touched_element,
10652 CE_OTHER_IS_SMASHING, i);
10658 if (IS_CUSTOM_ELEMENT(touched_element) &&
10659 HAS_ANY_CHANGE_EVENT(touched_element, CE_OTHER_GETS_SMASHED))
10661 for (i = 0; i < element_info[touched_element].num_change_pages; i++)
10663 struct ElementChangeInfo *change =
10664 &element_info[touched_element].change_page[i];
10666 if (change->can_change &&
10667 change->events & CH_EVENT_BIT(CE_OTHER_GETS_SMASHED) &&
10668 change->trigger_side & hitting_side &&
10670 IS_EQUAL_OR_IN_GROUP(hitting_element, change->trigger_element)
10672 change->trigger_element == hitting_element
10676 CheckElementChangeByPage(hitx, hity, touched_element,
10677 hitting_element, CE_OTHER_GETS_SMASHED,i);
10687 void TestIfGoodThingHitsBadThing(int good_x, int good_y, int good_move_dir)
10689 int i, kill_x = -1, kill_y = -1;
10690 int bad_element = -1;
10691 static int test_xy[4][2] =
10698 static int test_dir[4] =
10706 for (i = 0; i < NUM_DIRECTIONS; i++)
10708 int test_x, test_y, test_move_dir, test_element;
10710 test_x = good_x + test_xy[i][0];
10711 test_y = good_y + test_xy[i][1];
10713 if (!IN_LEV_FIELD(test_x, test_y))
10717 (IS_MOVING(test_x, test_y) ? MovDir[test_x][test_y] : MV_NO_MOVING);
10720 test_element = Feld[test_x][test_y];
10722 test_element = MovingOrBlocked2ElementIfNotLeaving(test_x, test_y);
10725 /* 1st case: good thing is moving towards DONT_RUN_INTO style bad thing;
10726 2nd case: DONT_TOUCH style bad thing does not move away from good thing
10728 if ((DONT_RUN_INTO(test_element) && good_move_dir == test_dir[i]) ||
10729 (DONT_TOUCH(test_element) && test_move_dir != test_dir[i]))
10733 bad_element = test_element;
10739 if (kill_x != -1 || kill_y != -1)
10741 if (IS_PLAYER(good_x, good_y))
10743 struct PlayerInfo *player = PLAYERINFO(good_x, good_y);
10746 if (player->shield_deadly_time_left > 0 &&
10747 !IS_INDESTRUCTIBLE(bad_element))
10748 Bang(kill_x, kill_y);
10749 else if (!PLAYER_ENEMY_PROTECTED(good_x, good_y))
10752 if (player->shield_deadly_time_left > 0)
10753 Bang(kill_x, kill_y);
10754 else if (!PLAYER_ENEMY_PROTECTED(good_x, good_y))
10759 Bang(good_x, good_y);
10763 void TestIfBadThingHitsGoodThing(int bad_x, int bad_y, int bad_move_dir)
10765 int i, kill_x = -1, kill_y = -1;
10766 int bad_element = Feld[bad_x][bad_y];
10767 static int test_xy[4][2] =
10774 static int touch_dir[4] =
10776 MV_LEFT | MV_RIGHT,
10781 static int test_dir[4] =
10789 if (bad_element == EL_EXPLOSION) /* skip just exploding bad things */
10792 for (i = 0; i < NUM_DIRECTIONS; i++)
10794 int test_x, test_y, test_move_dir, test_element;
10796 test_x = bad_x + test_xy[i][0];
10797 test_y = bad_y + test_xy[i][1];
10798 if (!IN_LEV_FIELD(test_x, test_y))
10802 (IS_MOVING(test_x, test_y) ? MovDir[test_x][test_y] : MV_NO_MOVING);
10804 test_element = Feld[test_x][test_y];
10806 /* 1st case: good thing is moving towards DONT_RUN_INTO style bad thing;
10807 2nd case: DONT_TOUCH style bad thing does not move away from good thing
10809 if ((DONT_RUN_INTO(bad_element) && bad_move_dir == test_dir[i]) ||
10810 (DONT_TOUCH(bad_element) && test_move_dir != test_dir[i]))
10812 /* good thing is player or penguin that does not move away */
10813 if (IS_PLAYER(test_x, test_y))
10815 struct PlayerInfo *player = PLAYERINFO(test_x, test_y);
10817 if (bad_element == EL_ROBOT && player->is_moving)
10818 continue; /* robot does not kill player if he is moving */
10820 if (game.engine_version >= VERSION_IDENT(3,0,7,0))
10822 if (player->MovPos != 0 && !(player->MovDir & touch_dir[i]))
10823 continue; /* center and border element do not touch */
10830 else if (test_element == EL_PENGUIN)
10839 if (kill_x != -1 || kill_y != -1)
10841 if (IS_PLAYER(kill_x, kill_y))
10843 struct PlayerInfo *player = PLAYERINFO(kill_x, kill_y);
10846 if (player->shield_deadly_time_left > 0 &&
10847 !IS_INDESTRUCTIBLE(bad_element))
10848 Bang(bad_x, bad_y);
10849 else if (!PLAYER_ENEMY_PROTECTED(kill_x, kill_y))
10852 if (player->shield_deadly_time_left > 0)
10853 Bang(bad_x, bad_y);
10854 else if (!PLAYER_ENEMY_PROTECTED(kill_x, kill_y))
10859 Bang(kill_x, kill_y);
10863 void TestIfHeroTouchesBadThing(int x, int y)
10865 TestIfGoodThingHitsBadThing(x, y, MV_NO_MOVING);
10868 void TestIfHeroRunsIntoBadThing(int x, int y, int move_dir)
10870 TestIfGoodThingHitsBadThing(x, y, move_dir);
10873 void TestIfBadThingTouchesHero(int x, int y)
10875 TestIfBadThingHitsGoodThing(x, y, MV_NO_MOVING);
10878 void TestIfBadThingRunsIntoHero(int x, int y, int move_dir)
10880 TestIfBadThingHitsGoodThing(x, y, move_dir);
10883 void TestIfFriendTouchesBadThing(int x, int y)
10885 TestIfGoodThingHitsBadThing(x, y, MV_NO_MOVING);
10888 void TestIfBadThingTouchesFriend(int x, int y)
10890 TestIfBadThingHitsGoodThing(x, y, MV_NO_MOVING);
10893 void TestIfBadThingTouchesOtherBadThing(int bad_x, int bad_y)
10895 int i, kill_x = bad_x, kill_y = bad_y;
10896 static int xy[4][2] =
10904 for (i = 0; i < NUM_DIRECTIONS; i++)
10908 x = bad_x + xy[i][0];
10909 y = bad_y + xy[i][1];
10910 if (!IN_LEV_FIELD(x, y))
10913 element = Feld[x][y];
10914 if (IS_AMOEBOID(element) || element == EL_GAME_OF_LIFE ||
10915 element == EL_AMOEBA_GROWING || element == EL_AMOEBA_DROP)
10923 if (kill_x != bad_x || kill_y != bad_y)
10924 Bang(bad_x, bad_y);
10927 void KillHero(struct PlayerInfo *player)
10929 int jx = player->jx, jy = player->jy;
10931 if (!player->active)
10934 /* remove accessible field at the player's position */
10935 Feld[jx][jy] = EL_EMPTY;
10937 /* deactivate shield (else Bang()/Explode() would not work right) */
10938 player->shield_normal_time_left = 0;
10939 player->shield_deadly_time_left = 0;
10945 static void KillHeroUnlessEnemyProtected(int x, int y)
10947 if (!PLAYER_ENEMY_PROTECTED(x, y))
10948 KillHero(PLAYERINFO(x, y));
10951 static void KillHeroUnlessExplosionProtected(int x, int y)
10953 if (!PLAYER_EXPLOSION_PROTECTED(x, y))
10954 KillHero(PLAYERINFO(x, y));
10957 void BuryHero(struct PlayerInfo *player)
10959 int jx = player->jx, jy = player->jy;
10961 if (!player->active)
10965 PlayLevelSoundElementAction(jx, jy, player->element_nr, ACTION_DYING);
10967 PlayLevelSound(jx, jy, SND_CLASS_PLAYER_DYING);
10969 PlayLevelSound(jx, jy, SND_GAME_LOSING);
10971 player->GameOver = TRUE;
10972 RemoveHero(player);
10975 void RemoveHero(struct PlayerInfo *player)
10977 int jx = player->jx, jy = player->jy;
10978 int i, found = FALSE;
10980 player->present = FALSE;
10981 player->active = FALSE;
10983 if (!ExplodeField[jx][jy])
10984 StorePlayer[jx][jy] = 0;
10986 for (i = 0; i < MAX_PLAYERS; i++)
10987 if (stored_player[i].active)
10991 AllPlayersGone = TRUE;
10998 =============================================================================
10999 checkDiagonalPushing()
11000 -----------------------------------------------------------------------------
11001 check if diagonal input device direction results in pushing of object
11002 (by checking if the alternative direction is walkable, diggable, ...)
11003 =============================================================================
11006 static boolean checkDiagonalPushing(struct PlayerInfo *player,
11007 int x, int y, int real_dx, int real_dy)
11009 int jx, jy, dx, dy, xx, yy;
11011 if (real_dx == 0 || real_dy == 0) /* no diagonal direction => push */
11014 /* diagonal direction: check alternative direction */
11019 xx = jx + (dx == 0 ? real_dx : 0);
11020 yy = jy + (dy == 0 ? real_dy : 0);
11022 return (!IN_LEV_FIELD(xx, yy) || IS_SOLID_FOR_PUSHING(Feld[xx][yy]));
11026 =============================================================================
11028 -----------------------------------------------------------------------------
11029 x, y: field next to player (non-diagonal) to try to dig to
11030 real_dx, real_dy: direction as read from input device (can be diagonal)
11031 =============================================================================
11034 int DigField(struct PlayerInfo *player,
11035 int oldx, int oldy, int x, int y,
11036 int real_dx, int real_dy, int mode)
11039 boolean use_spring_bug = (game.engine_version < VERSION_IDENT(2,2,0,0));
11041 boolean is_player = (IS_PLAYER(oldx, oldy) || mode != DF_DIG);
11042 boolean player_was_pushing = player->is_pushing;
11043 int jx = oldx, jy = oldy;
11044 int dx = x - jx, dy = y - jy;
11045 int nextx = x + dx, nexty = y + dy;
11046 int move_direction = (dx == -1 ? MV_LEFT :
11047 dx == +1 ? MV_RIGHT :
11049 dy == +1 ? MV_DOWN : MV_NO_MOVING);
11050 int opposite_direction = MV_DIR_OPPOSITE(move_direction);
11052 int dig_side = MV_DIR_OPPOSITE(move_direction);
11054 static int trigger_sides[4] =
11056 CH_SIDE_RIGHT, /* moving left */
11057 CH_SIDE_LEFT, /* moving right */
11058 CH_SIDE_BOTTOM, /* moving up */
11059 CH_SIDE_TOP, /* moving down */
11061 int dig_side = trigger_sides[MV_DIR_BIT(move_direction)];
11063 int old_element = Feld[jx][jy];
11066 if (is_player) /* function can also be called by EL_PENGUIN */
11068 if (player->MovPos == 0)
11070 player->is_digging = FALSE;
11071 player->is_collecting = FALSE;
11074 if (player->MovPos == 0) /* last pushing move finished */
11075 player->is_pushing = FALSE;
11077 if (mode == DF_NO_PUSH) /* player just stopped pushing */
11079 player->is_switching = FALSE;
11080 #if USE_NEW_PUSH_DELAY
11081 player->push_delay = -1;
11083 player->push_delay = 0;
11086 return MF_NO_ACTION;
11090 if (IS_MOVING(x, y) || IS_PLAYER(x, y))
11091 return MF_NO_ACTION;
11096 if (IS_TUBE(Feld[jx][jy]) || IS_TUBE(Back[jx][jy]))
11098 if (IS_TUBE(Feld[jx][jy]) ||
11099 (IS_TUBE(Back[jx][jy]) && game.engine_version >= VERSION_IDENT(2,2,0,0)))
11103 int tube_element = (IS_TUBE(Feld[jx][jy]) ? Feld[jx][jy] : Back[jx][jy]);
11104 int tube_leave_directions[][2] =
11106 { EL_TUBE_ANY, MV_LEFT | MV_RIGHT | MV_UP | MV_DOWN },
11107 { EL_TUBE_VERTICAL, MV_UP | MV_DOWN },
11108 { EL_TUBE_HORIZONTAL, MV_LEFT | MV_RIGHT },
11109 { EL_TUBE_VERTICAL_LEFT, MV_LEFT | MV_UP | MV_DOWN },
11110 { EL_TUBE_VERTICAL_RIGHT, MV_RIGHT | MV_UP | MV_DOWN },
11111 { EL_TUBE_HORIZONTAL_UP, MV_LEFT | MV_RIGHT | MV_UP },
11112 { EL_TUBE_HORIZONTAL_DOWN, MV_LEFT | MV_RIGHT | MV_DOWN },
11113 { EL_TUBE_LEFT_UP, MV_LEFT | MV_UP },
11114 { EL_TUBE_LEFT_DOWN, MV_LEFT | MV_DOWN },
11115 { EL_TUBE_RIGHT_UP, MV_RIGHT | MV_UP },
11116 { EL_TUBE_RIGHT_DOWN, MV_RIGHT | MV_DOWN },
11117 { -1, MV_LEFT | MV_RIGHT | MV_UP | MV_DOWN }
11120 while (tube_leave_directions[i][0] != tube_element)
11123 if (tube_leave_directions[i][0] == -1) /* should not happen */
11127 if (!(tube_leave_directions[i][1] & move_direction))
11128 return MF_NO_ACTION; /* tube has no opening in this direction */
11133 if (IS_TUBE(Back[jx][jy]) && game.engine_version >= VERSION_IDENT(2,2,0,0))
11134 old_element = Back[jx][jy];
11138 if (IS_WALKABLE(old_element) && !ACCESS_FROM(old_element, move_direction))
11139 return MF_NO_ACTION; /* field has no opening in this direction */
11141 if (IS_PASSABLE(old_element) && !ACCESS_FROM(old_element,opposite_direction))
11142 return MF_NO_ACTION; /* field has no opening in this direction */
11144 element = Feld[x][y];
11146 if (!is_player && !IS_COLLECTIBLE(element)) /* penguin cannot collect it */
11147 return MF_NO_ACTION;
11149 if (mode == DF_SNAP && !IS_SNAPPABLE(element) &&
11150 game.engine_version >= VERSION_IDENT(2,2,0,0))
11151 return MF_NO_ACTION;
11154 if (game.gravity && is_player && !player->is_auto_moving &&
11155 canFallDown(player) && move_direction != MV_DOWN &&
11156 !canMoveToValidFieldWithGravity(jx, jy, move_direction))
11157 return MF_NO_ACTION; /* player cannot walk here due to gravity */
11161 if (element == EL_EMPTY_SPACE &&
11162 game.gravity && !player->is_auto_moving &&
11163 canFallDown(player) && move_direction != MV_DOWN)
11164 return MF_NO_ACTION; /* player cannot walk here due to gravity */
11170 case EL_SP_PORT_LEFT:
11171 case EL_SP_PORT_RIGHT:
11172 case EL_SP_PORT_UP:
11173 case EL_SP_PORT_DOWN:
11174 case EL_SP_PORT_HORIZONTAL:
11175 case EL_SP_PORT_VERTICAL:
11176 case EL_SP_PORT_ANY:
11177 case EL_SP_GRAVITY_PORT_LEFT:
11178 case EL_SP_GRAVITY_PORT_RIGHT:
11179 case EL_SP_GRAVITY_PORT_UP:
11180 case EL_SP_GRAVITY_PORT_DOWN:
11182 if (!canEnterSupaplexPort(x, y, dx, dy))
11183 return MF_NO_ACTION;
11186 element != EL_SP_PORT_LEFT &&
11187 element != EL_SP_GRAVITY_PORT_LEFT &&
11188 element != EL_SP_PORT_HORIZONTAL &&
11189 element != EL_SP_PORT_ANY) ||
11191 element != EL_SP_PORT_RIGHT &&
11192 element != EL_SP_GRAVITY_PORT_RIGHT &&
11193 element != EL_SP_PORT_HORIZONTAL &&
11194 element != EL_SP_PORT_ANY) ||
11196 element != EL_SP_PORT_UP &&
11197 element != EL_SP_GRAVITY_PORT_UP &&
11198 element != EL_SP_PORT_VERTICAL &&
11199 element != EL_SP_PORT_ANY) ||
11201 element != EL_SP_PORT_DOWN &&
11202 element != EL_SP_GRAVITY_PORT_DOWN &&
11203 element != EL_SP_PORT_VERTICAL &&
11204 element != EL_SP_PORT_ANY) ||
11205 !IN_LEV_FIELD(nextx, nexty) ||
11206 !IS_FREE(nextx, nexty))
11207 return MF_NO_ACTION;
11210 if (element == EL_SP_GRAVITY_PORT_LEFT ||
11211 element == EL_SP_GRAVITY_PORT_RIGHT ||
11212 element == EL_SP_GRAVITY_PORT_UP ||
11213 element == EL_SP_GRAVITY_PORT_DOWN)
11214 game.gravity = !game.gravity;
11216 /* automatically move to the next field with double speed */
11217 player->programmed_action = move_direction;
11219 if (player->move_delay_reset_counter == 0)
11221 player->move_delay_reset_counter = 2; /* two double speed steps */
11223 DOUBLE_PLAYER_SPEED(player);
11226 player->move_delay_reset_counter = 2;
11228 DOUBLE_PLAYER_SPEED(player);
11232 printf("::: passing port %d,%d [%d]\n", x, y, FrameCounter);
11235 PlayLevelSound(x, y, SND_CLASS_SP_PORT_PASSING);
11241 case EL_TUBE_VERTICAL:
11242 case EL_TUBE_HORIZONTAL:
11243 case EL_TUBE_VERTICAL_LEFT:
11244 case EL_TUBE_VERTICAL_RIGHT:
11245 case EL_TUBE_HORIZONTAL_UP:
11246 case EL_TUBE_HORIZONTAL_DOWN:
11247 case EL_TUBE_LEFT_UP:
11248 case EL_TUBE_LEFT_DOWN:
11249 case EL_TUBE_RIGHT_UP:
11250 case EL_TUBE_RIGHT_DOWN:
11253 int tube_enter_directions[][2] =
11255 { EL_TUBE_ANY, MV_LEFT | MV_RIGHT | MV_UP | MV_DOWN },
11256 { EL_TUBE_VERTICAL, MV_UP | MV_DOWN },
11257 { EL_TUBE_HORIZONTAL, MV_LEFT | MV_RIGHT },
11258 { EL_TUBE_VERTICAL_LEFT, MV_RIGHT | MV_UP | MV_DOWN },
11259 { EL_TUBE_VERTICAL_RIGHT, MV_LEFT | MV_UP | MV_DOWN },
11260 { EL_TUBE_HORIZONTAL_UP, MV_LEFT | MV_RIGHT | MV_DOWN },
11261 { EL_TUBE_HORIZONTAL_DOWN, MV_LEFT | MV_RIGHT | MV_UP },
11262 { EL_TUBE_LEFT_UP, MV_RIGHT | MV_DOWN },
11263 { EL_TUBE_LEFT_DOWN, MV_RIGHT | MV_UP },
11264 { EL_TUBE_RIGHT_UP, MV_LEFT | MV_DOWN },
11265 { EL_TUBE_RIGHT_DOWN, MV_LEFT | MV_UP },
11266 { -1, MV_NO_MOVING }
11269 while (tube_enter_directions[i][0] != element)
11272 if (tube_enter_directions[i][0] == -1) /* should not happen */
11276 if (!(tube_enter_directions[i][1] & move_direction))
11277 return MF_NO_ACTION; /* tube has no opening in this direction */
11279 PlayLevelSound(x, y, SND_CLASS_TUBE_WALKING);
11287 if (IS_WALKABLE(element) && ACCESS_FROM(element, opposite_direction))
11289 if (IS_WALKABLE(element))
11292 int sound_element = SND_ELEMENT(element);
11293 int sound_action = ACTION_WALKING;
11296 if (!ACCESS_FROM(element, opposite_direction))
11297 return MF_NO_ACTION; /* field not accessible from this direction */
11301 if (element == EL_EMPTY_SPACE &&
11302 game.gravity && !player->is_auto_moving &&
11303 canFallDown(player) && move_direction != MV_DOWN)
11304 return MF_NO_ACTION; /* player cannot walk here due to gravity */
11307 if (IS_GATE(element))
11309 if (!player->key[element - EL_GATE_1])
11310 return MF_NO_ACTION;
11312 else if (IS_GATE_GRAY(element))
11314 if (!player->key[element - EL_GATE_1_GRAY])
11315 return MF_NO_ACTION;
11317 else if (element == EL_EXIT_OPEN ||
11318 element == EL_SP_EXIT_OPEN ||
11319 element == EL_SP_EXIT_OPENING)
11321 sound_action = ACTION_PASSING; /* player is passing exit */
11323 else if (element == EL_EMPTY)
11325 sound_action = ACTION_MOVING; /* nothing to walk on */
11328 /* play sound from background or player, whatever is available */
11329 if (element_info[sound_element].sound[sound_action] != SND_UNDEFINED)
11330 PlayLevelSoundElementAction(x, y, sound_element, sound_action);
11332 PlayLevelSoundElementAction(x, y, player->element_nr, sound_action);
11337 else if (IS_PASSABLE(element) && canPassField(x, y, move_direction))
11339 else if (IS_PASSABLE(element))
11343 if (!canPassField(x, y, move_direction))
11344 return MF_NO_ACTION;
11349 if (!IN_LEV_FIELD(nextx, nexty) || IS_PLAYER(nextx, nexty) ||
11350 !IS_WALKABLE_FROM(Feld[nextx][nexty], move_direction) ||
11351 (!level.can_pass_to_walkable && !IS_FREE(nextx, nexty)))
11352 return MF_NO_ACTION;
11354 if (!IN_LEV_FIELD(nextx, nexty) || !IS_FREE(nextx, nexty))
11355 return MF_NO_ACTION;
11360 if (!ACCESS_FROM(element, opposite_direction))
11361 return MF_NO_ACTION; /* field not accessible from this direction */
11363 if (IS_CUSTOM_ELEMENT(element) &&
11364 !ACCESS_FROM(element, opposite_direction))
11365 return MF_NO_ACTION; /* field not accessible from this direction */
11369 if (CAN_MOVE(element)) /* only fixed elements can be passed! */
11370 return MF_NO_ACTION;
11375 if (IS_EM_GATE(element))
11377 if (!player->key[element - EL_EM_GATE_1])
11378 return MF_NO_ACTION;
11380 else if (IS_EM_GATE_GRAY(element))
11382 if (!player->key[element - EL_EM_GATE_1_GRAY])
11383 return MF_NO_ACTION;
11385 else if (IS_SP_PORT(element))
11387 if (element == EL_SP_GRAVITY_PORT_LEFT ||
11388 element == EL_SP_GRAVITY_PORT_RIGHT ||
11389 element == EL_SP_GRAVITY_PORT_UP ||
11390 element == EL_SP_GRAVITY_PORT_DOWN)
11391 game.gravity = !game.gravity;
11392 else if (element == EL_SP_GRAVITY_ON_PORT_LEFT ||
11393 element == EL_SP_GRAVITY_ON_PORT_RIGHT ||
11394 element == EL_SP_GRAVITY_ON_PORT_UP ||
11395 element == EL_SP_GRAVITY_ON_PORT_DOWN)
11396 game.gravity = TRUE;
11397 else if (element == EL_SP_GRAVITY_OFF_PORT_LEFT ||
11398 element == EL_SP_GRAVITY_OFF_PORT_RIGHT ||
11399 element == EL_SP_GRAVITY_OFF_PORT_UP ||
11400 element == EL_SP_GRAVITY_OFF_PORT_DOWN)
11401 game.gravity = FALSE;
11404 /* automatically move to the next field with double speed */
11405 player->programmed_action = move_direction;
11407 if (player->move_delay_reset_counter == 0)
11409 player->move_delay_reset_counter = 2; /* two double speed steps */
11411 DOUBLE_PLAYER_SPEED(player);
11414 player->move_delay_reset_counter = 2;
11416 DOUBLE_PLAYER_SPEED(player);
11419 PlayLevelSoundAction(x, y, ACTION_PASSING);
11423 else if (IS_DIGGABLE(element))
11427 if (mode != DF_SNAP)
11430 GfxElement[x][y] = GFX_ELEMENT(element);
11433 (GFX_CRUMBLED(element) ? EL_SAND : GFX_ELEMENT(element));
11435 player->is_digging = TRUE;
11438 PlayLevelSoundElementAction(x, y, element, ACTION_DIGGING);
11440 CheckTriggeredElementChangeByPlayer(x, y, element,CE_OTHER_GETS_DIGGED,
11441 player->index_bit, dig_side);
11444 if (mode == DF_SNAP)
11445 TestIfElementTouchesCustomElement(x, y); /* for empty space */
11450 else if (IS_COLLECTIBLE(element))
11454 if (is_player && mode != DF_SNAP)
11456 GfxElement[x][y] = element;
11457 player->is_collecting = TRUE;
11460 if (element == EL_SPEED_PILL)
11461 player->move_delay_value = MOVE_DELAY_HIGH_SPEED;
11462 else if (element == EL_EXTRA_TIME && level.time > 0)
11465 DrawGameValue_Time(TimeLeft);
11467 else if (element == EL_SHIELD_NORMAL || element == EL_SHIELD_DEADLY)
11469 player->shield_normal_time_left += 10;
11470 if (element == EL_SHIELD_DEADLY)
11471 player->shield_deadly_time_left += 10;
11473 else if (element == EL_DYNAMITE || element == EL_SP_DISK_RED)
11475 if (player->inventory_size < MAX_INVENTORY_SIZE)
11476 player->inventory_element[player->inventory_size++] = element;
11478 DrawGameValue_Dynamite(local_player->inventory_size);
11480 else if (element == EL_DYNABOMB_INCREASE_NUMBER)
11482 player->dynabomb_count++;
11483 player->dynabombs_left++;
11485 else if (element == EL_DYNABOMB_INCREASE_SIZE)
11487 player->dynabomb_size++;
11489 else if (element == EL_DYNABOMB_INCREASE_POWER)
11491 player->dynabomb_xl = TRUE;
11493 else if ((element >= EL_KEY_1 && element <= EL_KEY_4) ||
11494 (element >= EL_EM_KEY_1 && element <= EL_EM_KEY_4))
11496 int key_nr = (element >= EL_KEY_1 && element <= EL_KEY_4 ?
11497 element - EL_KEY_1 : element - EL_EM_KEY_1);
11499 player->key[key_nr] = TRUE;
11501 DrawGameValue_Keys(player);
11503 redraw_mask |= REDRAW_DOOR_1;
11505 else if (IS_ENVELOPE(element))
11508 player->show_envelope = element;
11510 ShowEnvelope(element - EL_ENVELOPE_1);
11513 else if (IS_DROPPABLE(element) ||
11514 IS_THROWABLE(element)) /* can be collected and dropped */
11518 if (element_info[element].collect_count == 0)
11519 player->inventory_infinite_element = element;
11521 for (i = 0; i < element_info[element].collect_count; i++)
11522 if (player->inventory_size < MAX_INVENTORY_SIZE)
11523 player->inventory_element[player->inventory_size++] = element;
11525 DrawGameValue_Dynamite(local_player->inventory_size);
11527 else if (element_info[element].collect_count > 0)
11529 local_player->gems_still_needed -=
11530 element_info[element].collect_count;
11531 if (local_player->gems_still_needed < 0)
11532 local_player->gems_still_needed = 0;
11534 DrawGameValue_Emeralds(local_player->gems_still_needed);
11537 RaiseScoreElement(element);
11538 PlayLevelSoundElementAction(x, y, element, ACTION_COLLECTING);
11541 CheckTriggeredElementChangeByPlayer(x, y, element,
11542 CE_OTHER_GETS_COLLECTED,
11543 player->index_bit, dig_side);
11546 if (mode == DF_SNAP)
11547 TestIfElementTouchesCustomElement(x, y); /* for empty space */
11552 else if (IS_PUSHABLE(element))
11554 if (mode == DF_SNAP && element != EL_BD_ROCK)
11555 return MF_NO_ACTION;
11557 if (CAN_FALL(element) && dy)
11558 return MF_NO_ACTION;
11560 if (CAN_FALL(element) && IN_LEV_FIELD(x, y + 1) && IS_FREE(x, y + 1) &&
11561 !(element == EL_SPRING && level.use_spring_bug))
11562 return MF_NO_ACTION;
11565 if (CAN_MOVE(element) && GET_MAX_MOVE_DELAY(element) == 0 &&
11566 ((move_direction & MV_VERTICAL &&
11567 ((element_info[element].move_pattern & MV_LEFT &&
11568 IN_LEV_FIELD(x - 1, y) && IS_FREE(x - 1, y)) ||
11569 (element_info[element].move_pattern & MV_RIGHT &&
11570 IN_LEV_FIELD(x + 1, y) && IS_FREE(x + 1, y)))) ||
11571 (move_direction & MV_HORIZONTAL &&
11572 ((element_info[element].move_pattern & MV_UP &&
11573 IN_LEV_FIELD(x, y - 1) && IS_FREE(x, y - 1)) ||
11574 (element_info[element].move_pattern & MV_DOWN &&
11575 IN_LEV_FIELD(x, y + 1) && IS_FREE(x, y + 1))))))
11576 return MF_NO_ACTION;
11580 /* do not push elements already moving away faster than player */
11581 if (CAN_MOVE(element) && MovDir[x][y] == move_direction &&
11582 ABS(getElementMoveStepsize(x, y)) > MOVE_STEPSIZE_NORMAL)
11583 return MF_NO_ACTION;
11585 if (element == EL_SPRING && MovDir[x][y] != MV_NO_MOVING)
11586 return MF_NO_ACTION;
11592 if (game.engine_version >= VERSION_IDENT(3,1,0,0))
11594 if (player->push_delay_value == -1 || !player_was_pushing)
11595 player->push_delay_value = GET_NEW_PUSH_DELAY(element);
11597 else if (game.engine_version >= VERSION_IDENT(3,0,7,1))
11599 if (player->push_delay_value == -1)
11600 player->push_delay_value = GET_NEW_PUSH_DELAY(element);
11603 if (game.engine_version >= VERSION_IDENT(3,0,7,1))
11605 if (player->push_delay_value == -1 || !player_was_pushing)
11606 player->push_delay_value = GET_NEW_PUSH_DELAY(element);
11609 else if (game.engine_version >= VERSION_IDENT(2,2,0,7))
11611 if (!player->is_pushing)
11612 player->push_delay_value = GET_NEW_PUSH_DELAY(element);
11616 if (game.engine_version >= VERSION_IDENT(2,2,0,7) &&
11617 (game.engine_version < VERSION_IDENT(3,0,7,1) ||
11618 !player_is_pushing))
11619 player->push_delay_value = GET_NEW_PUSH_DELAY(element);
11622 if (!player->is_pushing &&
11623 game.engine_version >= VERSION_IDENT(2,2,0,7))
11624 player->push_delay_value = GET_NEW_PUSH_DELAY(element);
11628 printf("::: push delay: %ld -> %ld [%d, %d] [%d / %d] [%d '%s': %d]\n",
11629 player->push_delay, player->push_delay_value,
11630 FrameCounter, game.engine_version,
11631 player_was_pushing, player->is_pushing,
11632 element, element_info[element].token_name,
11633 GET_NEW_PUSH_DELAY(element));
11636 player->is_pushing = TRUE;
11638 if (!(IN_LEV_FIELD(nextx, nexty) &&
11639 (IS_FREE(nextx, nexty) ||
11640 (Feld[nextx][nexty] == EL_SOKOBAN_FIELD_EMPTY &&
11641 IS_SB_ELEMENT(element)))))
11642 return MF_NO_ACTION;
11644 if (!checkDiagonalPushing(player, x, y, real_dx, real_dy))
11645 return MF_NO_ACTION;
11647 #if USE_NEW_PUSH_DELAY
11650 if ( (player->push_delay == -1) != (player->push_delay2 == 0) )
11651 printf("::: ALERT: %d, %d [%d / %d]\n",
11652 player->push_delay, player->push_delay2,
11653 FrameCounter, FrameCounter / 50);
11656 if (player->push_delay == -1) /* new pushing; restart delay */
11657 player->push_delay = 0;
11659 if (player->push_delay == 0) /* new pushing; restart delay */
11660 player->push_delay = FrameCounter;
11663 #if USE_NEW_PUSH_DELAY
11665 if ( (player->push_delay > 0) != (!xxx_fr) )
11666 printf("::: PUSH BUG! %d, (%d -> %d) %d [%d / %d]\n",
11667 player->push_delay,
11668 xxx_pdv2, player->push_delay2, player->push_delay_value,
11669 FrameCounter, FrameCounter / 50);
11673 if (player->push_delay > 0 &&
11674 !(tape.playing && tape.file_version < FILE_VERSION_2_0) &&
11675 element != EL_SPRING && element != EL_BALLOON)
11678 if (player->push_delay < player->push_delay_value &&
11679 !(tape.playing && tape.file_version < FILE_VERSION_2_0) &&
11680 element != EL_SPRING && element != EL_BALLOON)
11684 if (!FrameReached(&player->push_delay, player->push_delay_value) &&
11685 !(tape.playing && tape.file_version < FILE_VERSION_2_0) &&
11686 element != EL_SPRING && element != EL_BALLOON)
11689 /* make sure that there is no move delay before next try to push */
11690 #if USE_NEW_MOVE_DELAY
11691 if (game.engine_version >= VERSION_IDENT(3,0,7,1))
11692 player->move_delay = 0;
11694 if (game.engine_version >= VERSION_IDENT(3,0,7,1))
11695 player->move_delay = INITIAL_MOVE_DELAY_OFF;
11698 return MF_NO_ACTION;
11702 printf("::: NOW PUSHING... [%d]\n", FrameCounter);
11705 if (IS_SB_ELEMENT(element))
11707 if (element == EL_SOKOBAN_FIELD_FULL)
11709 Back[x][y] = EL_SOKOBAN_FIELD_EMPTY;
11710 local_player->sokobanfields_still_needed++;
11713 if (Feld[nextx][nexty] == EL_SOKOBAN_FIELD_EMPTY)
11715 Back[nextx][nexty] = EL_SOKOBAN_FIELD_EMPTY;
11716 local_player->sokobanfields_still_needed--;
11719 Feld[x][y] = EL_SOKOBAN_OBJECT;
11721 if (Back[x][y] == Back[nextx][nexty])
11722 PlayLevelSoundAction(x, y, ACTION_PUSHING);
11723 else if (Back[x][y] != 0)
11724 PlayLevelSoundElementAction(x, y, EL_SOKOBAN_FIELD_FULL,
11727 PlayLevelSoundElementAction(nextx, nexty, EL_SOKOBAN_FIELD_EMPTY,
11730 if (local_player->sokobanfields_still_needed == 0 &&
11731 game.emulation == EMU_SOKOBAN)
11733 player->LevelSolved = player->GameOver = TRUE;
11734 PlayLevelSound(x, y, SND_GAME_SOKOBAN_SOLVING);
11738 PlayLevelSoundElementAction(x, y, element, ACTION_PUSHING);
11740 InitMovingField(x, y, move_direction);
11741 GfxAction[x][y] = ACTION_PUSHING;
11743 if (mode == DF_SNAP)
11744 ContinueMoving(x, y);
11746 MovPos[x][y] = (dx != 0 ? dx : dy);
11748 Pushed[x][y] = TRUE;
11749 Pushed[nextx][nexty] = TRUE;
11751 if (game.engine_version < VERSION_IDENT(2,2,0,7))
11752 player->push_delay_value = GET_NEW_PUSH_DELAY(element);
11754 player->push_delay_value = -1; /* get new value later */
11756 #if USE_PUSH_BUGFIX
11757 /* now: check for element change _after_ element has been pushed! */
11759 if (game.use_bug_change_when_pushing)
11761 if (game.engine_version < VERSION_IDENT(3,1,0,0))
11764 CheckElementChangeByPlayer(x, y, element, CE_PUSHED_BY_PLAYER,
11765 player->index_bit, dig_side);
11766 CheckTriggeredElementChangeByPlayer(x,y,element,CE_OTHER_GETS_PUSHED,
11767 player->index_bit, dig_side);
11773 /* check for element change _after_ element has been pushed! */
11777 /* !!! TEST ONLY !!! */
11778 CheckElementChangeByPlayer(x, y, element, CE_PUSHED_BY_PLAYER,
11779 player->index_bit, dig_side);
11780 CheckTriggeredElementChangeByPlayer(x, y, element,CE_OTHER_GETS_PUSHED,
11781 player->index_bit, dig_side);
11783 CheckTriggeredElementChangeByPlayer(x, y, element,CE_OTHER_GETS_PUSHED,
11784 player->index_bit, dig_side);
11785 CheckElementChangeByPlayer(x, y, element, CE_PUSHED_BY_PLAYER,
11786 player->index_bit, dig_side);
11794 else if (IS_SWITCHABLE(element))
11796 if (PLAYER_SWITCHING(player, x, y))
11798 CheckTriggeredElementChangeByPlayer(x,y, element,
11799 CE_OTHER_GETS_PRESSED,
11800 player->index_bit, dig_side);
11805 player->is_switching = TRUE;
11806 player->switch_x = x;
11807 player->switch_y = y;
11809 PlayLevelSoundElementAction(x, y, element, ACTION_ACTIVATING);
11811 if (element == EL_ROBOT_WHEEL)
11813 Feld[x][y] = EL_ROBOT_WHEEL_ACTIVE;
11817 DrawLevelField(x, y);
11819 else if (element == EL_SP_TERMINAL)
11823 for (yy = 0; yy < lev_fieldy; yy++) for (xx=0; xx < lev_fieldx; xx++)
11825 if (Feld[xx][yy] == EL_SP_DISK_YELLOW)
11827 else if (Feld[xx][yy] == EL_SP_TERMINAL)
11828 Feld[xx][yy] = EL_SP_TERMINAL_ACTIVE;
11831 else if (IS_BELT_SWITCH(element))
11833 ToggleBeltSwitch(x, y);
11835 else if (element == EL_SWITCHGATE_SWITCH_UP ||
11836 element == EL_SWITCHGATE_SWITCH_DOWN)
11838 ToggleSwitchgateSwitch(x, y);
11840 else if (element == EL_LIGHT_SWITCH ||
11841 element == EL_LIGHT_SWITCH_ACTIVE)
11843 ToggleLightSwitch(x, y);
11846 PlayLevelSound(x, y, element == EL_LIGHT_SWITCH ?
11847 SND_LIGHT_SWITCH_ACTIVATING :
11848 SND_LIGHT_SWITCH_DEACTIVATING);
11851 else if (element == EL_TIMEGATE_SWITCH)
11853 ActivateTimegateSwitch(x, y);
11855 else if (element == EL_BALLOON_SWITCH_LEFT ||
11856 element == EL_BALLOON_SWITCH_RIGHT ||
11857 element == EL_BALLOON_SWITCH_UP ||
11858 element == EL_BALLOON_SWITCH_DOWN ||
11859 element == EL_BALLOON_SWITCH_ANY)
11861 if (element == EL_BALLOON_SWITCH_ANY)
11862 game.balloon_dir = move_direction;
11864 game.balloon_dir = (element == EL_BALLOON_SWITCH_LEFT ? MV_LEFT :
11865 element == EL_BALLOON_SWITCH_RIGHT ? MV_RIGHT :
11866 element == EL_BALLOON_SWITCH_UP ? MV_UP :
11867 element == EL_BALLOON_SWITCH_DOWN ? MV_DOWN :
11870 else if (element == EL_LAMP)
11872 Feld[x][y] = EL_LAMP_ACTIVE;
11873 local_player->lights_still_needed--;
11875 DrawLevelField(x, y);
11877 else if (element == EL_TIME_ORB_FULL)
11879 Feld[x][y] = EL_TIME_ORB_EMPTY;
11881 DrawGameValue_Time(TimeLeft);
11883 DrawLevelField(x, y);
11886 PlaySoundStereo(SND_TIME_ORB_FULL_COLLECTING, SOUND_MIDDLE);
11890 CheckTriggeredElementChangeByPlayer(x, y, element,
11891 CE_OTHER_IS_SWITCHING,
11892 player->index_bit, dig_side);
11894 CheckTriggeredElementChangeByPlayer(x,y, element,CE_OTHER_GETS_PRESSED,
11895 player->index_bit, dig_side);
11901 if (!PLAYER_SWITCHING(player, x, y))
11903 player->is_switching = TRUE;
11904 player->switch_x = x;
11905 player->switch_y = y;
11908 /* !!! TEST ONLY !!! */
11909 CheckElementChangeByPlayer(x, y, element, CE_SWITCHED,
11910 player->index_bit, dig_side);
11911 CheckTriggeredElementChangeByPlayer(x, y, element,
11912 CE_OTHER_IS_SWITCHING,
11913 player->index_bit, dig_side);
11915 CheckTriggeredElementChangeByPlayer(x, y, element,
11916 CE_OTHER_IS_SWITCHING,
11917 player->index_bit, dig_side);
11918 CheckElementChangeByPlayer(x, y, element, CE_SWITCHED,
11919 player->index_bit, dig_side);
11924 /* !!! TEST ONLY !!! (this breaks "machine", level 000) */
11925 CheckElementChangeByPlayer(x, y, element, CE_PRESSED_BY_PLAYER,
11926 player->index_bit, dig_side);
11927 CheckTriggeredElementChangeByPlayer(x,y, element,CE_OTHER_GETS_PRESSED,
11928 player->index_bit, dig_side);
11930 CheckTriggeredElementChangeByPlayer(x,y, element,CE_OTHER_GETS_PRESSED,
11931 player->index_bit, dig_side);
11932 CheckElementChangeByPlayer(x, y, element, CE_PRESSED_BY_PLAYER,
11933 player->index_bit, dig_side);
11937 return MF_NO_ACTION;
11940 #if USE_NEW_PUSH_DELAY
11941 player->push_delay = -1;
11943 player->push_delay = 0;
11946 if (Feld[x][y] != element) /* really digged/collected something */
11947 player->is_collecting = !player->is_digging;
11952 boolean SnapField(struct PlayerInfo *player, int dx, int dy)
11954 int jx = player->jx, jy = player->jy;
11955 int x = jx + dx, y = jy + dy;
11956 int snap_direction = (dx == -1 ? MV_LEFT :
11957 dx == +1 ? MV_RIGHT :
11959 dy == +1 ? MV_DOWN : MV_NO_MOVING);
11962 if (player->MovPos != 0)
11965 if (player->MovPos != 0 && game.engine_version >= VERSION_IDENT(2,2,0,0))
11969 if (!player->active || !IN_LEV_FIELD(x, y))
11977 if (player->MovPos == 0)
11978 player->is_pushing = FALSE;
11980 player->is_snapping = FALSE;
11982 if (player->MovPos == 0)
11984 player->is_moving = FALSE;
11985 player->is_digging = FALSE;
11986 player->is_collecting = FALSE;
11992 if (player->is_snapping)
11995 player->MovDir = snap_direction;
11998 if (player->MovPos == 0)
12001 player->is_moving = FALSE;
12002 player->is_digging = FALSE;
12003 player->is_collecting = FALSE;
12006 player->is_dropping = FALSE;
12008 if (DigField(player, jx, jy, x, y, 0, 0, DF_SNAP) == MF_NO_ACTION)
12011 player->is_snapping = TRUE;
12014 if (player->MovPos == 0)
12017 player->is_moving = FALSE;
12018 player->is_digging = FALSE;
12019 player->is_collecting = FALSE;
12023 if (player->MovPos != 0) /* prevent graphic bugs in versions < 2.2.0 */
12024 DrawLevelField(player->last_jx, player->last_jy);
12027 DrawLevelField(x, y);
12036 boolean DropElement(struct PlayerInfo *player)
12038 int old_element, new_element;
12039 int dropx = player->jx, dropy = player->jy;
12040 int drop_direction = player->MovDir;
12042 int drop_side = drop_direction;
12044 static int trigger_sides[4] =
12046 CH_SIDE_LEFT, /* dropping left */
12047 CH_SIDE_RIGHT, /* dropping right */
12048 CH_SIDE_TOP, /* dropping up */
12049 CH_SIDE_BOTTOM, /* dropping down */
12051 int drop_side = trigger_sides[MV_DIR_BIT(drop_direction)];
12053 int drop_element = (player->inventory_size > 0 ?
12054 player->inventory_element[player->inventory_size - 1] :
12055 player->inventory_infinite_element != EL_UNDEFINED ?
12056 player->inventory_infinite_element :
12057 player->dynabombs_left > 0 ?
12058 EL_DYNABOMB_PLAYER_1_ACTIVE + player->index_nr :
12061 if (IS_THROWABLE(drop_element))
12063 dropx += GET_DX_FROM_DIR(drop_direction);
12064 dropy += GET_DY_FROM_DIR(drop_direction);
12066 if (!IN_LEV_FIELD(dropx, dropy))
12070 old_element = Feld[dropx][dropy]; /* old element at dropping position */
12071 new_element = drop_element; /* default: no change when dropping */
12073 /* check if player is active, not moving and ready to drop */
12074 if (!player->active || player->MovPos || player->drop_delay > 0)
12077 /* check if player has anything that can be dropped */
12079 if (new_element == EL_UNDEFINED)
12082 if (player->inventory_size == 0 &&
12083 player->inventory_infinite_element == EL_UNDEFINED &&
12084 player->dynabombs_left == 0)
12088 /* check if anything can be dropped at the current position */
12089 if (IS_ACTIVE_BOMB(old_element) || old_element == EL_EXPLOSION)
12092 /* collected custom elements can only be dropped on empty fields */
12094 if (IS_CUSTOM_ELEMENT(new_element) && old_element != EL_EMPTY)
12097 if (player->inventory_size > 0 &&
12098 IS_CUSTOM_ELEMENT(player->inventory_element[player->inventory_size - 1])
12099 && old_element != EL_EMPTY)
12103 if (old_element != EL_EMPTY)
12104 Back[dropx][dropy] = old_element; /* store old element on this field */
12106 ResetGfxAnimation(dropx, dropy);
12107 ResetRandomAnimationValue(dropx, dropy);
12109 if (player->inventory_size > 0 ||
12110 player->inventory_infinite_element != EL_UNDEFINED)
12112 if (player->inventory_size > 0)
12114 player->inventory_size--;
12117 new_element = player->inventory_element[player->inventory_size];
12120 DrawGameValue_Dynamite(local_player->inventory_size);
12122 if (new_element == EL_DYNAMITE)
12123 new_element = EL_DYNAMITE_ACTIVE;
12124 else if (new_element == EL_SP_DISK_RED)
12125 new_element = EL_SP_DISK_RED_ACTIVE;
12128 Feld[dropx][dropy] = new_element;
12130 if (IN_SCR_FIELD(SCREENX(dropx), SCREENY(dropy)))
12131 DrawGraphicThruMask(SCREENX(dropx), SCREENY(dropy),
12132 el2img(Feld[dropx][dropy]), 0);
12134 PlayLevelSoundAction(dropx, dropy, ACTION_DROPPING);
12137 /* needed if previous element just changed to "empty" in the last frame */
12138 Changed[dropx][dropy] = 0; /* allow another change */
12142 /* !!! TEST ONLY !!! */
12143 CheckElementChangeByPlayer(dropx, dropy, new_element, CE_DROPPED_BY_PLAYER,
12144 player->index_bit, drop_side);
12145 CheckTriggeredElementChangeByPlayer(dropx, dropy, new_element,
12146 CE_OTHER_GETS_DROPPED,
12147 player->index_bit, drop_side);
12149 CheckTriggeredElementChangeByPlayer(dropx, dropy, new_element,
12150 CE_OTHER_GETS_DROPPED,
12151 player->index_bit, drop_side);
12152 CheckElementChangeByPlayer(dropx, dropy, new_element, CE_DROPPED_BY_PLAYER,
12153 player->index_bit, drop_side);
12156 TestIfElementTouchesCustomElement(dropx, dropy);
12158 else /* player is dropping a dyna bomb */
12160 player->dynabombs_left--;
12163 new_element = EL_DYNABOMB_PLAYER_1_ACTIVE + player->index_nr;
12166 Feld[dropx][dropy] = new_element;
12168 if (IN_SCR_FIELD(SCREENX(dropx), SCREENY(dropy)))
12169 DrawGraphicThruMask(SCREENX(dropx), SCREENY(dropy),
12170 el2img(Feld[dropx][dropy]), 0);
12172 PlayLevelSoundAction(dropx, dropy, ACTION_DROPPING);
12179 if (Feld[dropx][dropy] == new_element) /* uninitialized unless CE change */
12182 InitField_WithBug1(dropx, dropy, FALSE);
12184 InitField(dropx, dropy, FALSE);
12185 if (CAN_MOVE(Feld[dropx][dropy]))
12186 InitMovDir(dropx, dropy);
12190 new_element = Feld[dropx][dropy]; /* element might have changed */
12192 if (IS_CUSTOM_ELEMENT(new_element) && CAN_MOVE(new_element) &&
12193 element_info[new_element].move_pattern == MV_WHEN_DROPPED)
12196 int move_stepsize = element_info[new_element].move_stepsize;
12198 int move_direction, nextx, nexty;
12200 if (element_info[new_element].move_direction_initial == MV_START_AUTOMATIC)
12201 MovDir[dropx][dropy] = drop_direction;
12203 move_direction = MovDir[dropx][dropy];
12204 nextx = dropx + GET_DX_FROM_DIR(move_direction);
12205 nexty = dropy + GET_DY_FROM_DIR(move_direction);
12208 Changed[dropx][dropy] = 0; /* allow another change */
12209 CheckCollision[dropx][dropy] = 2;
12212 if (IN_LEV_FIELD_AND_IS_FREE(nextx, nexty))
12215 WasJustMoving[dropx][dropy] = 3;
12218 InitMovingField(dropx, dropy, move_direction);
12219 ContinueMoving(dropx, dropy);
12224 /* !!! commented out from 3.1.0-4 to 3.1.0-5 !!! */
12227 Changed[dropx][dropy] = 0; /* allow another change */
12230 TestIfElementHitsCustomElement(dropx, dropy, move_direction);
12232 CheckElementChangeBySide(dropx, dropy, new_element, touched_element,
12233 CE_HITTING_SOMETHING, move_direction);
12241 player->drop_delay = 2 * TILEX / move_stepsize + 1;
12246 player->drop_delay = 8 + 8 + 8;
12250 player->drop_delay = GET_NEW_DROP_DELAY(drop_element);
12255 player->is_dropping = TRUE;
12261 /* ------------------------------------------------------------------------- */
12262 /* game sound playing functions */
12263 /* ------------------------------------------------------------------------- */
12265 static int *loop_sound_frame = NULL;
12266 static int *loop_sound_volume = NULL;
12268 void InitPlayLevelSound()
12270 int num_sounds = getSoundListSize();
12272 checked_free(loop_sound_frame);
12273 checked_free(loop_sound_volume);
12275 loop_sound_frame = checked_calloc(num_sounds * sizeof(int));
12276 loop_sound_volume = checked_calloc(num_sounds * sizeof(int));
12279 static void PlayLevelSound(int x, int y, int nr)
12281 int sx = SCREENX(x), sy = SCREENY(y);
12282 int volume, stereo_position;
12283 int max_distance = 8;
12284 int type = (IS_LOOP_SOUND(nr) ? SND_CTRL_PLAY_LOOP : SND_CTRL_PLAY_SOUND);
12286 if ((!setup.sound_simple && !IS_LOOP_SOUND(nr)) ||
12287 (!setup.sound_loops && IS_LOOP_SOUND(nr)))
12290 if (!IN_LEV_FIELD(x, y) ||
12291 sx < -max_distance || sx >= SCR_FIELDX + max_distance ||
12292 sy < -max_distance || sy >= SCR_FIELDY + max_distance)
12295 volume = SOUND_MAX_VOLUME;
12297 if (!IN_SCR_FIELD(sx, sy))
12299 int dx = ABS(sx - SCR_FIELDX / 2) - SCR_FIELDX / 2;
12300 int dy = ABS(sy - SCR_FIELDY / 2) - SCR_FIELDY / 2;
12302 volume -= volume * (dx > dy ? dx : dy) / max_distance;
12305 stereo_position = (SOUND_MAX_LEFT +
12306 (sx + max_distance) * SOUND_MAX_LEFT2RIGHT /
12307 (SCR_FIELDX + 2 * max_distance));
12309 if (IS_LOOP_SOUND(nr))
12311 /* This assures that quieter loop sounds do not overwrite louder ones,
12312 while restarting sound volume comparison with each new game frame. */
12314 if (loop_sound_volume[nr] > volume && loop_sound_frame[nr] == FrameCounter)
12317 loop_sound_volume[nr] = volume;
12318 loop_sound_frame[nr] = FrameCounter;
12321 PlaySoundExt(nr, volume, stereo_position, type);
12324 static void PlayLevelSoundNearest(int x, int y, int sound_action)
12326 PlayLevelSound(x < LEVELX(BX1) ? LEVELX(BX1) :
12327 x > LEVELX(BX2) ? LEVELX(BX2) : x,
12328 y < LEVELY(BY1) ? LEVELY(BY1) :
12329 y > LEVELY(BY2) ? LEVELY(BY2) : y,
12333 static void PlayLevelSoundAction(int x, int y, int action)
12335 PlayLevelSoundElementAction(x, y, Feld[x][y], action);
12338 static void PlayLevelSoundElementAction(int x, int y, int element, int action)
12340 int sound_effect = element_info[SND_ELEMENT(element)].sound[action];
12342 if (sound_effect != SND_UNDEFINED)
12343 PlayLevelSound(x, y, sound_effect);
12346 static void PlayLevelSoundElementActionIfLoop(int x, int y, int element,
12349 int sound_effect = element_info[SND_ELEMENT(element)].sound[action];
12351 if (sound_effect != SND_UNDEFINED && IS_LOOP_SOUND(sound_effect))
12352 PlayLevelSound(x, y, sound_effect);
12355 static void PlayLevelSoundActionIfLoop(int x, int y, int action)
12357 int sound_effect = element_info[SND_ELEMENT(Feld[x][y])].sound[action];
12359 if (sound_effect != SND_UNDEFINED && IS_LOOP_SOUND(sound_effect))
12360 PlayLevelSound(x, y, sound_effect);
12363 static void StopLevelSoundActionIfLoop(int x, int y, int action)
12365 int sound_effect = element_info[SND_ELEMENT(Feld[x][y])].sound[action];
12367 if (sound_effect != SND_UNDEFINED && IS_LOOP_SOUND(sound_effect))
12368 StopSound(sound_effect);
12371 static void PlayLevelMusic()
12373 if (levelset.music[level_nr] != MUS_UNDEFINED)
12374 PlayMusic(levelset.music[level_nr]); /* from config file */
12376 PlayMusic(MAP_NOCONF_MUSIC(level_nr)); /* from music dir */
12379 void RaiseScore(int value)
12381 local_player->score += value;
12383 DrawGameValue_Score(local_player->score);
12386 void RaiseScoreElement(int element)
12391 case EL_BD_DIAMOND:
12392 case EL_EMERALD_YELLOW:
12393 case EL_EMERALD_RED:
12394 case EL_EMERALD_PURPLE:
12395 case EL_SP_INFOTRON:
12396 RaiseScore(level.score[SC_EMERALD]);
12399 RaiseScore(level.score[SC_DIAMOND]);
12402 RaiseScore(level.score[SC_CRYSTAL]);
12405 RaiseScore(level.score[SC_PEARL]);
12408 case EL_BD_BUTTERFLY:
12409 case EL_SP_ELECTRON:
12410 RaiseScore(level.score[SC_BUG]);
12413 case EL_BD_FIREFLY:
12414 case EL_SP_SNIKSNAK:
12415 RaiseScore(level.score[SC_SPACESHIP]);
12418 case EL_DARK_YAMYAM:
12419 RaiseScore(level.score[SC_YAMYAM]);
12422 RaiseScore(level.score[SC_ROBOT]);
12425 RaiseScore(level.score[SC_PACMAN]);
12428 RaiseScore(level.score[SC_NUT]);
12431 case EL_SP_DISK_RED:
12432 case EL_DYNABOMB_INCREASE_NUMBER:
12433 case EL_DYNABOMB_INCREASE_SIZE:
12434 case EL_DYNABOMB_INCREASE_POWER:
12435 RaiseScore(level.score[SC_DYNAMITE]);
12437 case EL_SHIELD_NORMAL:
12438 case EL_SHIELD_DEADLY:
12439 RaiseScore(level.score[SC_SHIELD]);
12441 case EL_EXTRA_TIME:
12442 RaiseScore(level.score[SC_TIME_BONUS]);
12448 RaiseScore(level.score[SC_KEY]);
12451 RaiseScore(element_info[element].collect_score);
12456 void RequestQuitGame(boolean ask_if_really_quit)
12458 if (AllPlayersGone ||
12459 !ask_if_really_quit ||
12460 level_editor_test_game ||
12461 Request("Do you really want to quit the game ?",
12462 REQ_ASK | REQ_STAY_CLOSED))
12464 #if defined(NETWORK_AVALIABLE)
12465 if (options.network)
12466 SendToServer_StopPlaying();
12470 game_status = GAME_MODE_MAIN;
12478 if (tape.playing && tape.deactivate_display)
12479 TapeDeactivateDisplayOff(TRUE);
12482 OpenDoor(DOOR_OPEN_1 | DOOR_COPY_BACK);
12485 if (tape.playing && tape.deactivate_display)
12486 TapeDeactivateDisplayOn();
12493 /* ---------- new game button stuff ---------------------------------------- */
12495 /* graphic position values for game buttons */
12496 #define GAME_BUTTON_XSIZE 30
12497 #define GAME_BUTTON_YSIZE 30
12498 #define GAME_BUTTON_XPOS 5
12499 #define GAME_BUTTON_YPOS 215
12500 #define SOUND_BUTTON_XPOS 5
12501 #define SOUND_BUTTON_YPOS (GAME_BUTTON_YPOS + GAME_BUTTON_YSIZE)
12503 #define GAME_BUTTON_STOP_XPOS (GAME_BUTTON_XPOS + 0 * GAME_BUTTON_XSIZE)
12504 #define GAME_BUTTON_PAUSE_XPOS (GAME_BUTTON_XPOS + 1 * GAME_BUTTON_XSIZE)
12505 #define GAME_BUTTON_PLAY_XPOS (GAME_BUTTON_XPOS + 2 * GAME_BUTTON_XSIZE)
12506 #define SOUND_BUTTON_MUSIC_XPOS (SOUND_BUTTON_XPOS + 0 * GAME_BUTTON_XSIZE)
12507 #define SOUND_BUTTON_LOOPS_XPOS (SOUND_BUTTON_XPOS + 1 * GAME_BUTTON_XSIZE)
12508 #define SOUND_BUTTON_SIMPLE_XPOS (SOUND_BUTTON_XPOS + 2 * GAME_BUTTON_XSIZE)
12515 } gamebutton_info[NUM_GAME_BUTTONS] =
12518 GAME_BUTTON_STOP_XPOS, GAME_BUTTON_YPOS,
12523 GAME_BUTTON_PAUSE_XPOS, GAME_BUTTON_YPOS,
12524 GAME_CTRL_ID_PAUSE,
12528 GAME_BUTTON_PLAY_XPOS, GAME_BUTTON_YPOS,
12533 SOUND_BUTTON_MUSIC_XPOS, SOUND_BUTTON_YPOS,
12534 SOUND_CTRL_ID_MUSIC,
12535 "background music on/off"
12538 SOUND_BUTTON_LOOPS_XPOS, SOUND_BUTTON_YPOS,
12539 SOUND_CTRL_ID_LOOPS,
12540 "sound loops on/off"
12543 SOUND_BUTTON_SIMPLE_XPOS, SOUND_BUTTON_YPOS,
12544 SOUND_CTRL_ID_SIMPLE,
12545 "normal sounds on/off"
12549 void CreateGameButtons()
12553 for (i = 0; i < NUM_GAME_BUTTONS; i++)
12555 Bitmap *gd_bitmap = graphic_info[IMG_GLOBAL_DOOR].bitmap;
12556 struct GadgetInfo *gi;
12559 unsigned long event_mask;
12560 int gd_xoffset, gd_yoffset;
12561 int gd_x1, gd_x2, gd_y1, gd_y2;
12564 gd_xoffset = gamebutton_info[i].x;
12565 gd_yoffset = gamebutton_info[i].y;
12566 gd_x1 = DOOR_GFX_PAGEX4 + gd_xoffset;
12567 gd_x2 = DOOR_GFX_PAGEX3 + gd_xoffset;
12569 if (id == GAME_CTRL_ID_STOP ||
12570 id == GAME_CTRL_ID_PAUSE ||
12571 id == GAME_CTRL_ID_PLAY)
12573 button_type = GD_TYPE_NORMAL_BUTTON;
12575 event_mask = GD_EVENT_RELEASED;
12576 gd_y1 = DOOR_GFX_PAGEY1 + gd_yoffset - GAME_BUTTON_YSIZE;
12577 gd_y2 = DOOR_GFX_PAGEY1 + gd_yoffset - GAME_BUTTON_YSIZE;
12581 button_type = GD_TYPE_CHECK_BUTTON;
12583 ((id == SOUND_CTRL_ID_MUSIC && setup.sound_music) ||
12584 (id == SOUND_CTRL_ID_LOOPS && setup.sound_loops) ||
12585 (id == SOUND_CTRL_ID_SIMPLE && setup.sound_simple) ? TRUE : FALSE);
12586 event_mask = GD_EVENT_PRESSED;
12587 gd_y1 = DOOR_GFX_PAGEY1 + gd_yoffset;
12588 gd_y2 = DOOR_GFX_PAGEY1 + gd_yoffset - GAME_BUTTON_YSIZE;
12591 gi = CreateGadget(GDI_CUSTOM_ID, id,
12592 GDI_INFO_TEXT, gamebutton_info[i].infotext,
12593 GDI_X, DX + gd_xoffset,
12594 GDI_Y, DY + gd_yoffset,
12595 GDI_WIDTH, GAME_BUTTON_XSIZE,
12596 GDI_HEIGHT, GAME_BUTTON_YSIZE,
12597 GDI_TYPE, button_type,
12598 GDI_STATE, GD_BUTTON_UNPRESSED,
12599 GDI_CHECKED, checked,
12600 GDI_DESIGN_UNPRESSED, gd_bitmap, gd_x1, gd_y1,
12601 GDI_DESIGN_PRESSED, gd_bitmap, gd_x2, gd_y1,
12602 GDI_ALT_DESIGN_UNPRESSED, gd_bitmap, gd_x1, gd_y2,
12603 GDI_ALT_DESIGN_PRESSED, gd_bitmap, gd_x2, gd_y2,
12604 GDI_EVENT_MASK, event_mask,
12605 GDI_CALLBACK_ACTION, HandleGameButtons,
12609 Error(ERR_EXIT, "cannot create gadget");
12611 game_gadget[id] = gi;
12615 void FreeGameButtons()
12619 for (i = 0; i < NUM_GAME_BUTTONS; i++)
12620 FreeGadget(game_gadget[i]);
12623 static void MapGameButtons()
12627 for (i = 0; i < NUM_GAME_BUTTONS; i++)
12628 MapGadget(game_gadget[i]);
12631 void UnmapGameButtons()
12635 for (i = 0; i < NUM_GAME_BUTTONS; i++)
12636 UnmapGadget(game_gadget[i]);
12639 static void HandleGameButtons(struct GadgetInfo *gi)
12641 int id = gi->custom_id;
12643 if (game_status != GAME_MODE_PLAYING)
12648 case GAME_CTRL_ID_STOP:
12649 RequestQuitGame(TRUE);
12652 case GAME_CTRL_ID_PAUSE:
12653 if (options.network)
12655 #if defined(NETWORK_AVALIABLE)
12657 SendToServer_ContinuePlaying();
12659 SendToServer_PausePlaying();
12663 TapeTogglePause(TAPE_TOGGLE_MANUAL);
12666 case GAME_CTRL_ID_PLAY:
12669 #if defined(NETWORK_AVALIABLE)
12670 if (options.network)
12671 SendToServer_ContinuePlaying();
12675 tape.pausing = FALSE;
12676 DrawVideoDisplay(VIDEO_STATE_PAUSE_OFF,0);
12681 case SOUND_CTRL_ID_MUSIC:
12682 if (setup.sound_music)
12684 setup.sound_music = FALSE;
12687 else if (audio.music_available)
12689 setup.sound = setup.sound_music = TRUE;
12691 SetAudioMode(setup.sound);
12697 case SOUND_CTRL_ID_LOOPS:
12698 if (setup.sound_loops)
12699 setup.sound_loops = FALSE;
12700 else if (audio.loops_available)
12702 setup.sound = setup.sound_loops = TRUE;
12703 SetAudioMode(setup.sound);
12707 case SOUND_CTRL_ID_SIMPLE:
12708 if (setup.sound_simple)
12709 setup.sound_simple = FALSE;
12710 else if (audio.sound_available)
12712 setup.sound = setup.sound_simple = TRUE;
12713 SetAudioMode(setup.sound);