1 /***********************************************************
2 * Rocks'n'Diamonds -- McDuffin Strikes Back! *
3 *----------------------------------------------------------*
4 * (c) 1995-2002 Artsoft Entertainment *
6 * Detmolder Strasse 189 *
9 * e-mail: info@artsoft.org *
10 *----------------------------------------------------------*
12 ***********************************************************/
14 #include "libgame/libgame.h"
24 /* this switch controls how rocks move horizontally */
25 #define OLD_GAME_BEHAVIOUR FALSE
27 /* EXPERIMENTAL STUFF */
28 #define USE_NEW_AMOEBA_CODE FALSE
30 /* EXPERIMENTAL STUFF */
31 #define USE_NEW_STUFF TRUE * 1
33 #define USE_NEW_MOVE_STYLE TRUE * USE_NEW_STUFF * 1
34 #define USE_NEW_MOVE_DELAY TRUE * USE_NEW_STUFF * 1
35 #define USE_NEW_PUSH_DELAY TRUE * USE_NEW_STUFF * 1
36 #define USE_NEW_BLOCK_STYLE TRUE * USE_NEW_STUFF * 1 * 1
37 #define USE_NEW_SP_SLIPPERY TRUE * USE_NEW_STUFF * 1
38 #define USE_NEW_RANDOMIZE TRUE * USE_NEW_STUFF * 1
40 #define USE_PUSH_BUGFIX TRUE * USE_NEW_STUFF * 1
47 /* for MovePlayer() */
48 #define MF_NO_ACTION 0
52 /* for ScrollPlayer() */
54 #define SCROLL_GO_ON 1
57 #define EX_PHASE_START 0
58 #define EX_TYPE_NONE 0
59 #define EX_TYPE_NORMAL (1 << 0)
60 #define EX_TYPE_CENTER (1 << 1)
61 #define EX_TYPE_BORDER (1 << 2)
62 #define EX_TYPE_CROSS (1 << 3)
63 #define EX_TYPE_SINGLE_TILE (EX_TYPE_CENTER | EX_TYPE_BORDER)
65 /* special positions in the game control window (relative to control window) */
68 #define XX_EMERALDS 29
69 #define YY_EMERALDS 54
70 #define XX_DYNAMITE 29
71 #define YY_DYNAMITE 89
80 /* special positions in the game control window (relative to main window) */
81 #define DX_LEVEL (DX + XX_LEVEL)
82 #define DY_LEVEL (DY + YY_LEVEL)
83 #define DX_EMERALDS (DX + XX_EMERALDS)
84 #define DY_EMERALDS (DY + YY_EMERALDS)
85 #define DX_DYNAMITE (DX + XX_DYNAMITE)
86 #define DY_DYNAMITE (DY + YY_DYNAMITE)
87 #define DX_KEYS (DX + XX_KEYS)
88 #define DY_KEYS (DY + YY_KEYS)
89 #define DX_SCORE (DX + XX_SCORE)
90 #define DY_SCORE (DY + YY_SCORE)
91 #define DX_TIME1 (DX + XX_TIME1)
92 #define DX_TIME2 (DX + XX_TIME2)
93 #define DY_TIME (DY + YY_TIME)
95 /* values for initial player move delay (initial delay counter value) */
96 #define INITIAL_MOVE_DELAY_OFF -1
97 #define INITIAL_MOVE_DELAY_ON 0
99 /* values for player movement speed (which is in fact a delay value) */
100 #define MOVE_DELAY_NORMAL_SPEED 8
101 #define MOVE_DELAY_HIGH_SPEED 4
103 #define DOUBLE_MOVE_DELAY(x) (x = (x <= MOVE_DELAY_HIGH_SPEED ? x * 2 : x))
104 #define HALVE_MOVE_DELAY(x) (x = (x >= MOVE_DELAY_HIGH_SPEED ? x / 2 : x))
105 #define DOUBLE_PLAYER_SPEED(p) (HALVE_MOVE_DELAY((p)->move_delay_value))
106 #define HALVE_PLAYER_SPEED(p) (DOUBLE_MOVE_DELAY((p)->move_delay_value))
108 /* values for other actions */
109 #define MOVE_STEPSIZE_NORMAL (TILEX / MOVE_DELAY_NORMAL_SPEED)
111 #define GET_DX_FROM_DIR(d) ((d) == MV_LEFT ? -1 : (d) == MV_RIGHT ? 1 : 0)
112 #define GET_DY_FROM_DIR(d) ((d) == MV_UP ? -1 : (d) == MV_DOWN ? 1 : 0)
114 #define INIT_GFX_RANDOM() (SimpleRND(1000000))
116 #define GET_NEW_PUSH_DELAY(e) ( (element_info[e].push_delay_fixed) + \
117 RND(element_info[e].push_delay_random))
118 #define GET_NEW_DROP_DELAY(e) ( (element_info[e].drop_delay_fixed) + \
119 RND(element_info[e].drop_delay_random))
120 #define GET_NEW_MOVE_DELAY(e) ( (element_info[e].move_delay_fixed) + \
121 RND(element_info[e].move_delay_random))
122 #define GET_MAX_MOVE_DELAY(e) ( (element_info[e].move_delay_fixed) + \
123 (element_info[e].move_delay_random))
125 #define GET_TARGET_ELEMENT(e, ch) \
126 ((e) == EL_TRIGGER_ELEMENT ? (ch)->actual_trigger_element : \
127 (e) == EL_TRIGGER_PLAYER ? (ch)->actual_trigger_player : (e))
129 #define GET_VALID_PLAYER_ELEMENT(e) \
130 ((e) >= EL_PLAYER_1 && (e) <= EL_PLAYER_4 ? (e) : EL_PLAYER_1)
132 #define CAN_GROW_INTO(e) \
133 ((e) == EL_SAND || (IS_DIGGABLE(e) && level.grow_into_diggable))
135 #define ELEMENT_CAN_ENTER_FIELD_BASE_X(x, y, condition) \
136 (IN_LEV_FIELD(x, y) && (IS_FREE(x, y) || \
139 #define ELEMENT_CAN_ENTER_FIELD_BASE_2(e, x, y, condition) \
140 (IN_LEV_FIELD(x, y) && (IS_FREE(x, y) || \
141 (CAN_MOVE_INTO_ACID(e) && \
142 Feld[x][y] == EL_ACID) || \
145 #define ELEMENT_CAN_ENTER_FIELD_BASE_3(e, x, y, condition) \
146 (IN_LEV_FIELD(x, y) && (IS_FREE_OR_PLAYER(x, y) || \
147 (CAN_MOVE_INTO_ACID(e) && \
148 Feld[x][y] == EL_ACID) || \
151 #define ELEMENT_CAN_ENTER_FIELD_BASE_4(e, x, y, condition) \
152 (IN_LEV_FIELD(x, y) && (IS_FREE(x, y) || \
154 (CAN_MOVE_INTO_ACID(e) && \
155 Feld[x][y] == EL_ACID) || \
156 (DONT_COLLIDE_WITH(e) && \
158 !PLAYER_ENEMY_PROTECTED(x, y))))
161 #define ELEMENT_CAN_ENTER_FIELD_GENERIC(e, x, y, condition) \
162 (IN_LEV_FIELD(x, y) && (IS_FREE(x, y) || \
164 (DONT_COLLIDE_WITH(e) && \
166 !PLAYER_ENEMY_PROTECTED(x, y))))
169 #define ELEMENT_CAN_ENTER_FIELD(e, x, y) \
170 ELEMENT_CAN_ENTER_FIELD_BASE_4(e, x, y, 0)
173 #define SATELLITE_CAN_ENTER_FIELD(x, y) \
174 ELEMENT_CAN_ENTER_FIELD_BASE_2(EL_SATELLITE, x, y, 0)
176 #define SATELLITE_CAN_ENTER_FIELD(x, y) \
177 ELEMENT_CAN_ENTER_FIELD_BASE_X(x, y, Feld[x][y] == EL_ACID)
181 #define ENEMY_CAN_ENTER_FIELD(e, x, y) (IN_LEV_FIELD(x, y) && IS_FREE(x, y))
184 #define ENEMY_CAN_ENTER_FIELD(e, x, y) \
185 ELEMENT_CAN_ENTER_FIELD_BASE_2(e, x, y, 0)
189 #define YAMYAM_CAN_ENTER_FIELD(e, x, y) \
190 ELEMENT_CAN_ENTER_FIELD_BASE_3(e, x, y, Feld[x][y] == EL_DIAMOND)
192 #define DARK_YAMYAM_CAN_ENTER_FIELD(e, x, y) \
193 ELEMENT_CAN_ENTER_FIELD_BASE_3(e, x,y, IS_FOOD_DARK_YAMYAM(Feld[x][y]))
195 #define PACMAN_CAN_ENTER_FIELD(e, x, y) \
196 ELEMENT_CAN_ENTER_FIELD_BASE_3(e, x, y, IS_AMOEBOID(Feld[x][y]))
198 #define PIG_CAN_ENTER_FIELD(e, x, y) \
199 ELEMENT_CAN_ENTER_FIELD_BASE_2(e, x, y, IS_FOOD_PIG(Feld[x][y]))
201 #define PENGUIN_CAN_ENTER_FIELD(e, x, y) \
202 ELEMENT_CAN_ENTER_FIELD_BASE_2(e, x, y, (Feld[x][y] == EL_EXIT_OPEN ||\
203 IS_FOOD_PENGUIN(Feld[x][y])))
204 #define DRAGON_CAN_ENTER_FIELD(e, x, y) \
205 ELEMENT_CAN_ENTER_FIELD_BASE_2(e, x, y, 0)
207 #define MOLE_CAN_ENTER_FIELD(e, x, y, condition) \
208 ELEMENT_CAN_ENTER_FIELD_BASE_2(e, x, y, (condition))
210 #define SPRING_CAN_ENTER_FIELD(e, x, y) \
211 ELEMENT_CAN_ENTER_FIELD_BASE_2(e, x, y, 0)
215 #define YAMYAM_CAN_ENTER_FIELD(e, x, y) \
216 (IN_LEV_FIELD(x, y) && (IS_FREE_OR_PLAYER(x, y) || \
217 (CAN_MOVE_INTO_ACID(e) && \
218 Feld[x][y] == EL_ACID) || \
219 Feld[x][y] == EL_DIAMOND))
221 #define DARK_YAMYAM_CAN_ENTER_FIELD(e, x, y) \
222 (IN_LEV_FIELD(x, y) && (IS_FREE_OR_PLAYER(x, y) || \
223 (CAN_MOVE_INTO_ACID(e) && \
224 Feld[x][y] == EL_ACID) || \
225 IS_FOOD_DARK_YAMYAM(Feld[x][y])))
227 #define PACMAN_CAN_ENTER_FIELD(e, x, y) \
228 (IN_LEV_FIELD(x, y) && (IS_FREE_OR_PLAYER(x, y) || \
229 (CAN_MOVE_INTO_ACID(e) && \
230 Feld[x][y] == EL_ACID) || \
231 IS_AMOEBOID(Feld[x][y])))
233 #define PIG_CAN_ENTER_FIELD(e, x, y) \
234 (IN_LEV_FIELD(x, y) && (IS_FREE(x, y) || \
235 (CAN_MOVE_INTO_ACID(e) && \
236 Feld[x][y] == EL_ACID) || \
237 IS_FOOD_PIG(Feld[x][y])))
239 #define PENGUIN_CAN_ENTER_FIELD(e, x, y) \
240 (IN_LEV_FIELD(x, y) && (IS_FREE(x, y) || \
241 (CAN_MOVE_INTO_ACID(e) && \
242 Feld[x][y] == EL_ACID) || \
243 IS_FOOD_PENGUIN(Feld[x][y]) || \
244 Feld[x][y] == EL_EXIT_OPEN))
246 #define DRAGON_CAN_ENTER_FIELD(e, x, y) \
247 (IN_LEV_FIELD(x, y) && (IS_FREE(x, y) || \
248 (CAN_MOVE_INTO_ACID(e) && \
249 Feld[x][y] == EL_ACID)))
251 #define MOLE_CAN_ENTER_FIELD(e, x, y, condition) \
252 (IN_LEV_FIELD(x, y) && (IS_FREE(x, y) || \
253 (CAN_MOVE_INTO_ACID(e) && \
254 Feld[x][y] == EL_ACID) || \
257 #define SPRING_CAN_ENTER_FIELD(e, x, y) \
258 (IN_LEV_FIELD(x, y) && (IS_FREE(x, y) || \
259 (CAN_MOVE_INTO_ACID(e) && \
260 Feld[x][y] == EL_ACID)))
264 #define GROUP_NR(e) ((e) - EL_GROUP_START)
265 #define MOVE_ENTER_EL(e) (element_info[e].move_enter_element)
266 #define IS_IN_GROUP(e, nr) (element_info[e].in_group[nr] == TRUE)
267 #define IS_IN_GROUP_EL(e, ge) (IS_IN_GROUP(e, (ge) - EL_GROUP_START))
269 #define IS_EQUAL_OR_IN_GROUP(e, ge) \
270 (IS_GROUP_ELEMENT(ge) ? IS_IN_GROUP(e, GROUP_NR(ge)) : (e) == (ge))
273 #define CE_ENTER_FIELD_COND(e, x, y) \
274 (!IS_PLAYER(x, y) && \
275 (Feld[x][y] == EL_ACID || \
276 IS_EQUAL_OR_IN_GROUP(Feld[x][y], MOVE_ENTER_EL(e))))
278 #define CE_ENTER_FIELD_COND(e, x, y) \
279 (!IS_PLAYER(x, y) && \
280 IS_EQUAL_OR_IN_GROUP(Feld[x][y], MOVE_ENTER_EL(e)))
283 #define CUSTOM_ELEMENT_CAN_ENTER_FIELD(e, x, y) \
284 ELEMENT_CAN_ENTER_FIELD_BASE_4(e, x, y, CE_ENTER_FIELD_COND(e, x, y))
286 #define IN_LEV_FIELD_AND_IS_FREE(x, y) (IN_LEV_FIELD(x, y) && IS_FREE(x, y))
287 #define IN_LEV_FIELD_AND_NOT_FREE(x, y) (IN_LEV_FIELD(x, y) && !IS_FREE(x, y))
289 #define ACCESS_FROM(e, d) (element_info[e].access_direction &(d))
290 #define IS_WALKABLE_FROM(e, d) (IS_WALKABLE(e) && ACCESS_FROM(e, d))
291 #define IS_PASSABLE_FROM(e, d) (IS_PASSABLE(e) && ACCESS_FROM(e, d))
292 #define IS_ACCESSIBLE_FROM(e, d) (IS_ACCESSIBLE(e) && ACCESS_FROM(e, d))
294 /* game button identifiers */
295 #define GAME_CTRL_ID_STOP 0
296 #define GAME_CTRL_ID_PAUSE 1
297 #define GAME_CTRL_ID_PLAY 2
298 #define SOUND_CTRL_ID_MUSIC 3
299 #define SOUND_CTRL_ID_LOOPS 4
300 #define SOUND_CTRL_ID_SIMPLE 5
302 #define NUM_GAME_BUTTONS 6
305 /* forward declaration for internal use */
307 static void AdvanceFrameAndPlayerCounters(int);
309 static boolean MovePlayerOneStep(struct PlayerInfo *, int, int, int, int);
310 static boolean MovePlayer(struct PlayerInfo *, int, int);
311 static void ScrollPlayer(struct PlayerInfo *, int);
312 static void ScrollScreen(struct PlayerInfo *, int);
314 int DigField(struct PlayerInfo *, int, int, int, int, int, int, int);
316 static void InitBeltMovement(void);
317 static void CloseAllOpenTimegates(void);
318 static void CheckGravityMovement(struct PlayerInfo *);
319 static void CheckGravityMovementWhenNotMoving(struct PlayerInfo *);
320 static void KillHeroUnlessEnemyProtected(int, int);
321 static void KillHeroUnlessExplosionProtected(int, int);
323 static void TestIfPlayerTouchesCustomElement(int, int);
324 static void TestIfElementTouchesCustomElement(int, int);
325 static void TestIfElementHitsCustomElement(int, int, int);
327 static void TestIfElementSmashesCustomElement(int, int, int);
330 static void ChangeElement(int, int, int);
332 static boolean CheckTriggeredElementChangeExt(int, int, int, int, int,int,int);
333 #define CheckTriggeredElementChange(x, y, e, ev) \
334 CheckTriggeredElementChangeExt(x, y, e, ev, CH_PLAYER_ANY, \
336 #define CheckTriggeredElementChangeByPlayer(x, y, e, ev, p, s) \
337 CheckTriggeredElementChangeExt(x, y, e, ev, p, s, -1)
338 #define CheckTriggeredElementChangeBySide(x, y, e, ev, s) \
339 CheckTriggeredElementChangeExt(x, y, e, ev, CH_PLAYER_ANY, s, -1)
340 #define CheckTriggeredElementChangeByPage(x, y, e, ev, p) \
341 CheckTriggeredElementChangeExt(x, y, e, ev, CH_PLAYER_ANY, \
344 static boolean CheckElementChangeExt(int, int, int, int, int, int, int, int);
345 #define CheckElementChange(x, y, e, te, ev) \
346 CheckElementChangeExt(x, y, e, te, ev, CH_PLAYER_ANY, CH_SIDE_ANY, -1)
347 #define CheckElementChangeByPlayer(x, y, e, ev, p, s) \
348 CheckElementChangeExt(x, y, e, EL_EMPTY, ev, p, s, CH_PAGE_ANY)
349 #define CheckElementChangeBySide(x, y, e, te, ev, s) \
350 CheckElementChangeExt(x, y, e, te, ev, CH_PLAYER_ANY, s, CH_PAGE_ANY)
351 #define CheckElementChangeByPage(x, y, e, te, ev, p) \
352 CheckElementChangeExt(x, y, e, te, ev, CH_PLAYER_ANY, CH_SIDE_ANY, p)
354 static void PlayLevelSound(int, int, int);
355 static void PlayLevelSoundNearest(int, int, int);
356 static void PlayLevelSoundAction(int, int, int);
357 static void PlayLevelSoundElementAction(int, int, int, int);
358 static void PlayLevelSoundElementActionIfLoop(int, int, int, int);
359 static void PlayLevelSoundActionIfLoop(int, int, int);
360 static void StopLevelSoundActionIfLoop(int, int, int);
361 static void PlayLevelMusic();
363 static void MapGameButtons();
364 static void HandleGameButtons(struct GadgetInfo *);
366 static struct GadgetInfo *game_gadget[NUM_GAME_BUTTONS];
369 /* ------------------------------------------------------------------------- */
370 /* definition of elements that automatically change to other elements after */
371 /* a specified time, eventually calling a function when changing */
372 /* ------------------------------------------------------------------------- */
374 /* forward declaration for changer functions */
375 static void InitBuggyBase(int x, int y);
376 static void WarnBuggyBase(int x, int y);
378 static void InitTrap(int x, int y);
379 static void ActivateTrap(int x, int y);
380 static void ChangeActiveTrap(int x, int y);
382 static void InitRobotWheel(int x, int y);
383 static void RunRobotWheel(int x, int y);
384 static void StopRobotWheel(int x, int y);
386 static void InitTimegateWheel(int x, int y);
387 static void RunTimegateWheel(int x, int y);
389 struct ChangingElementInfo
394 void (*pre_change_function)(int x, int y);
395 void (*change_function)(int x, int y);
396 void (*post_change_function)(int x, int y);
399 static struct ChangingElementInfo change_delay_list[] =
450 EL_SWITCHGATE_OPENING,
458 EL_SWITCHGATE_CLOSING,
459 EL_SWITCHGATE_CLOSED,
491 EL_ACID_SPLASH_RIGHT,
500 EL_SP_BUGGY_BASE_ACTIVATING,
507 EL_SP_BUGGY_BASE_ACTIVATING,
508 EL_SP_BUGGY_BASE_ACTIVE,
515 EL_SP_BUGGY_BASE_ACTIVE,
539 EL_ROBOT_WHEEL_ACTIVE,
547 EL_TIMEGATE_SWITCH_ACTIVE,
568 int push_delay_fixed, push_delay_random;
573 { EL_BALLOON, 0, 0 },
575 { EL_SOKOBAN_OBJECT, 2, 0 },
576 { EL_SOKOBAN_FIELD_FULL, 2, 0 },
577 { EL_SATELLITE, 2, 0 },
578 { EL_SP_DISK_YELLOW, 2, 0 },
580 { EL_UNDEFINED, 0, 0 },
588 move_stepsize_list[] =
590 { EL_AMOEBA_DROP, 2 },
591 { EL_AMOEBA_DROPPING, 2 },
592 { EL_QUICKSAND_FILLING, 1 },
593 { EL_QUICKSAND_EMPTYING, 1 },
594 { EL_MAGIC_WALL_FILLING, 2 },
595 { EL_BD_MAGIC_WALL_FILLING, 2 },
596 { EL_MAGIC_WALL_EMPTYING, 2 },
597 { EL_BD_MAGIC_WALL_EMPTYING, 2 },
607 collect_count_list[] =
610 { EL_BD_DIAMOND, 1 },
611 { EL_EMERALD_YELLOW, 1 },
612 { EL_EMERALD_RED, 1 },
613 { EL_EMERALD_PURPLE, 1 },
615 { EL_SP_INFOTRON, 1 },
627 access_direction_list[] =
629 { EL_TUBE_ANY, MV_LEFT | MV_RIGHT | MV_UP | MV_DOWN },
630 { EL_TUBE_VERTICAL, MV_UP | MV_DOWN },
631 { EL_TUBE_HORIZONTAL, MV_LEFT | MV_RIGHT },
632 { EL_TUBE_VERTICAL_LEFT, MV_LEFT | MV_UP | MV_DOWN },
633 { EL_TUBE_VERTICAL_RIGHT, MV_RIGHT | MV_UP | MV_DOWN },
634 { EL_TUBE_HORIZONTAL_UP, MV_LEFT | MV_RIGHT | MV_UP },
635 { EL_TUBE_HORIZONTAL_DOWN, MV_LEFT | MV_RIGHT | MV_DOWN },
636 { EL_TUBE_LEFT_UP, MV_LEFT | MV_UP },
637 { EL_TUBE_LEFT_DOWN, MV_LEFT | MV_DOWN },
638 { EL_TUBE_RIGHT_UP, MV_RIGHT | MV_UP },
639 { EL_TUBE_RIGHT_DOWN, MV_RIGHT | MV_DOWN },
641 { EL_SP_PORT_LEFT, MV_RIGHT },
642 { EL_SP_PORT_RIGHT, MV_LEFT },
643 { EL_SP_PORT_UP, MV_DOWN },
644 { EL_SP_PORT_DOWN, MV_UP },
645 { EL_SP_PORT_HORIZONTAL, MV_LEFT | MV_RIGHT },
646 { EL_SP_PORT_VERTICAL, MV_UP | MV_DOWN },
647 { EL_SP_PORT_ANY, MV_LEFT | MV_RIGHT | MV_UP | MV_DOWN },
648 { EL_SP_GRAVITY_PORT_LEFT, MV_RIGHT },
649 { EL_SP_GRAVITY_PORT_RIGHT, MV_LEFT },
650 { EL_SP_GRAVITY_PORT_UP, MV_DOWN },
651 { EL_SP_GRAVITY_PORT_DOWN, MV_UP },
652 { EL_SP_GRAVITY_ON_PORT_LEFT, MV_RIGHT },
653 { EL_SP_GRAVITY_ON_PORT_RIGHT, MV_LEFT },
654 { EL_SP_GRAVITY_ON_PORT_UP, MV_DOWN },
655 { EL_SP_GRAVITY_ON_PORT_DOWN, MV_UP },
656 { EL_SP_GRAVITY_OFF_PORT_LEFT, MV_RIGHT },
657 { EL_SP_GRAVITY_OFF_PORT_RIGHT, MV_LEFT },
658 { EL_SP_GRAVITY_OFF_PORT_UP, MV_DOWN },
659 { EL_SP_GRAVITY_OFF_PORT_DOWN, MV_UP },
661 { EL_UNDEFINED, MV_NO_MOVING }
664 static unsigned long trigger_events[MAX_NUM_ELEMENTS];
666 #define IS_AUTO_CHANGING(e) (element_info[e].change_events & \
667 CH_EVENT_BIT(CE_DELAY))
668 #define IS_JUST_CHANGING(x, y) (ChangeDelay[x][y] != 0)
669 #define IS_CHANGING(x, y) (IS_AUTO_CHANGING(Feld[x][y]) || \
670 IS_JUST_CHANGING(x, y))
672 #define CE_PAGE(e, ce) (element_info[e].event_page[ce])
675 void GetPlayerConfig()
677 if (!audio.sound_available)
678 setup.sound_simple = FALSE;
680 if (!audio.loops_available)
681 setup.sound_loops = FALSE;
683 if (!audio.music_available)
684 setup.sound_music = FALSE;
686 if (!video.fullscreen_available)
687 setup.fullscreen = FALSE;
689 setup.sound = (setup.sound_simple || setup.sound_loops || setup.sound_music);
691 SetAudioMode(setup.sound);
695 static int getBeltNrFromBeltElement(int element)
697 return (element < EL_CONVEYOR_BELT_2_LEFT ? 0 :
698 element < EL_CONVEYOR_BELT_3_LEFT ? 1 :
699 element < EL_CONVEYOR_BELT_4_LEFT ? 2 : 3);
702 static int getBeltNrFromBeltActiveElement(int element)
704 return (element < EL_CONVEYOR_BELT_2_LEFT_ACTIVE ? 0 :
705 element < EL_CONVEYOR_BELT_3_LEFT_ACTIVE ? 1 :
706 element < EL_CONVEYOR_BELT_4_LEFT_ACTIVE ? 2 : 3);
709 static int getBeltNrFromBeltSwitchElement(int element)
711 return (element < EL_CONVEYOR_BELT_2_SWITCH_LEFT ? 0 :
712 element < EL_CONVEYOR_BELT_3_SWITCH_LEFT ? 1 :
713 element < EL_CONVEYOR_BELT_4_SWITCH_LEFT ? 2 : 3);
716 static int getBeltDirNrFromBeltSwitchElement(int element)
718 static int belt_base_element[4] =
720 EL_CONVEYOR_BELT_1_SWITCH_LEFT,
721 EL_CONVEYOR_BELT_2_SWITCH_LEFT,
722 EL_CONVEYOR_BELT_3_SWITCH_LEFT,
723 EL_CONVEYOR_BELT_4_SWITCH_LEFT
726 int belt_nr = getBeltNrFromBeltSwitchElement(element);
727 int belt_dir_nr = element - belt_base_element[belt_nr];
729 return (belt_dir_nr % 3);
732 static int getBeltDirFromBeltSwitchElement(int element)
734 static int belt_move_dir[3] =
741 int belt_dir_nr = getBeltDirNrFromBeltSwitchElement(element);
743 return belt_move_dir[belt_dir_nr];
746 static void InitPlayerField(int x, int y, int element, boolean init_game)
748 if (element == EL_SP_MURPHY)
752 if (stored_player[0].present)
754 Feld[x][y] = EL_SP_MURPHY_CLONE;
760 stored_player[0].use_murphy_graphic = TRUE;
763 Feld[x][y] = EL_PLAYER_1;
769 struct PlayerInfo *player = &stored_player[Feld[x][y] - EL_PLAYER_1];
770 int jx = player->jx, jy = player->jy;
772 player->present = TRUE;
774 player->block_last_field = (element == EL_SP_MURPHY ?
775 level.sp_block_last_field :
776 level.block_last_field);
778 #if USE_NEW_BLOCK_STYLE
780 player->block_delay = (player->block_last_field ?
781 (element == EL_SP_MURPHY ?
782 level.sp_block_delay :
783 level.block_delay) : 0);
785 player->block_delay = (element == EL_SP_MURPHY ?
786 (player->block_last_field ? 7 : 1) :
787 (player->block_last_field ? 7 : 1));
791 printf("::: block_last_field == %d, block_delay = %d\n",
792 player->block_last_field, player->block_delay);
796 if (!options.network || player->connected)
798 player->active = TRUE;
800 /* remove potentially duplicate players */
801 if (StorePlayer[jx][jy] == Feld[x][y])
802 StorePlayer[jx][jy] = 0;
804 StorePlayer[x][y] = Feld[x][y];
808 printf("Player %d activated.\n", player->element_nr);
809 printf("[Local player is %d and currently %s.]\n",
810 local_player->element_nr,
811 local_player->active ? "active" : "not active");
815 Feld[x][y] = EL_EMPTY;
817 player->jx = player->last_jx = x;
818 player->jy = player->last_jy = y;
822 static void InitField(int x, int y, boolean init_game)
824 int element = Feld[x][y];
833 InitPlayerField(x, y, element, init_game);
836 case EL_SOKOBAN_FIELD_PLAYER:
837 element = Feld[x][y] = EL_PLAYER_1;
838 InitField(x, y, init_game);
840 element = Feld[x][y] = EL_SOKOBAN_FIELD_EMPTY;
841 InitField(x, y, init_game);
844 case EL_SOKOBAN_FIELD_EMPTY:
845 local_player->sokobanfields_still_needed++;
849 if (x < lev_fieldx-1 && Feld[x+1][y] == EL_ACID)
850 Feld[x][y] = EL_ACID_POOL_TOPLEFT;
851 else if (x > 0 && Feld[x-1][y] == EL_ACID)
852 Feld[x][y] = EL_ACID_POOL_TOPRIGHT;
853 else if (y > 0 && Feld[x][y-1] == EL_ACID_POOL_TOPLEFT)
854 Feld[x][y] = EL_ACID_POOL_BOTTOMLEFT;
855 else if (y > 0 && Feld[x][y-1] == EL_ACID)
856 Feld[x][y] = EL_ACID_POOL_BOTTOM;
857 else if (y > 0 && Feld[x][y-1] == EL_ACID_POOL_TOPRIGHT)
858 Feld[x][y] = EL_ACID_POOL_BOTTOMRIGHT;
866 case EL_SPACESHIP_RIGHT:
867 case EL_SPACESHIP_UP:
868 case EL_SPACESHIP_LEFT:
869 case EL_SPACESHIP_DOWN:
871 case EL_BD_BUTTERFLY_RIGHT:
872 case EL_BD_BUTTERFLY_UP:
873 case EL_BD_BUTTERFLY_LEFT:
874 case EL_BD_BUTTERFLY_DOWN:
875 case EL_BD_BUTTERFLY:
876 case EL_BD_FIREFLY_RIGHT:
877 case EL_BD_FIREFLY_UP:
878 case EL_BD_FIREFLY_LEFT:
879 case EL_BD_FIREFLY_DOWN:
881 case EL_PACMAN_RIGHT:
905 if (y == lev_fieldy - 1)
907 Feld[x][y] = EL_AMOEBA_GROWING;
908 Store[x][y] = EL_AMOEBA_WET;
912 case EL_DYNAMITE_ACTIVE:
913 case EL_SP_DISK_RED_ACTIVE:
914 case EL_DYNABOMB_PLAYER_1_ACTIVE:
915 case EL_DYNABOMB_PLAYER_2_ACTIVE:
916 case EL_DYNABOMB_PLAYER_3_ACTIVE:
917 case EL_DYNABOMB_PLAYER_4_ACTIVE:
922 local_player->lights_still_needed++;
926 local_player->friends_still_needed++;
931 GfxDir[x][y] = MovDir[x][y] = 1 << RND(4);
936 Feld[x][y] = EL_EMPTY;
941 case EL_EM_KEY_1_FILE:
942 Feld[x][y] = EL_EM_KEY_1;
944 case EL_EM_KEY_2_FILE:
945 Feld[x][y] = EL_EM_KEY_2;
947 case EL_EM_KEY_3_FILE:
948 Feld[x][y] = EL_EM_KEY_3;
950 case EL_EM_KEY_4_FILE:
951 Feld[x][y] = EL_EM_KEY_4;
955 case EL_CONVEYOR_BELT_1_SWITCH_LEFT:
956 case EL_CONVEYOR_BELT_1_SWITCH_MIDDLE:
957 case EL_CONVEYOR_BELT_1_SWITCH_RIGHT:
958 case EL_CONVEYOR_BELT_2_SWITCH_LEFT:
959 case EL_CONVEYOR_BELT_2_SWITCH_MIDDLE:
960 case EL_CONVEYOR_BELT_2_SWITCH_RIGHT:
961 case EL_CONVEYOR_BELT_3_SWITCH_LEFT:
962 case EL_CONVEYOR_BELT_3_SWITCH_MIDDLE:
963 case EL_CONVEYOR_BELT_3_SWITCH_RIGHT:
964 case EL_CONVEYOR_BELT_4_SWITCH_LEFT:
965 case EL_CONVEYOR_BELT_4_SWITCH_MIDDLE:
966 case EL_CONVEYOR_BELT_4_SWITCH_RIGHT:
969 int belt_nr = getBeltNrFromBeltSwitchElement(Feld[x][y]);
970 int belt_dir = getBeltDirFromBeltSwitchElement(Feld[x][y]);
971 int belt_dir_nr = getBeltDirNrFromBeltSwitchElement(Feld[x][y]);
973 if (game.belt_dir_nr[belt_nr] == 3) /* initial value */
975 game.belt_dir[belt_nr] = belt_dir;
976 game.belt_dir_nr[belt_nr] = belt_dir_nr;
978 else /* more than one switch -- set it like the first switch */
980 Feld[x][y] = Feld[x][y] - belt_dir_nr + game.belt_dir_nr[belt_nr];
985 case EL_SWITCHGATE_SWITCH_DOWN: /* always start with same switch pos */
987 Feld[x][y] = EL_SWITCHGATE_SWITCH_UP;
990 case EL_LIGHT_SWITCH_ACTIVE:
992 game.light_time_left = level.time_light * FRAMES_PER_SECOND;
996 if (IS_CUSTOM_ELEMENT(element) && CAN_MOVE(element))
998 else if (IS_GROUP_ELEMENT(element))
1000 struct ElementGroupInfo *group = element_info[element].group;
1001 int last_anim_random_frame = gfx.anim_random_frame;
1004 if (group->choice_mode == ANIM_RANDOM)
1005 gfx.anim_random_frame = RND(group->num_elements_resolved);
1007 element_pos = getAnimationFrame(group->num_elements_resolved, 1,
1008 group->choice_mode, 0,
1011 if (group->choice_mode == ANIM_RANDOM)
1012 gfx.anim_random_frame = last_anim_random_frame;
1014 group->choice_pos++;
1016 Feld[x][y] = group->element_resolved[element_pos];
1018 InitField(x, y, init_game);
1024 static inline void InitField_WithBug1(int x, int y, boolean init_game)
1026 InitField(x, y, init_game);
1028 /* not needed to call InitMovDir() -- already done by InitField()! */
1029 if (game.engine_version < VERSION_IDENT(3,1,0,0) &&
1030 CAN_MOVE(Feld[x][y]))
1034 static inline void InitField_WithBug2(int x, int y, boolean init_game)
1036 int old_element = Feld[x][y];
1038 InitField(x, y, init_game);
1040 /* not needed to call InitMovDir() -- already done by InitField()! */
1041 if (game.engine_version < VERSION_IDENT(3,1,0,0) &&
1042 CAN_MOVE(old_element) &&
1043 (old_element < EL_MOLE_LEFT || old_element > EL_MOLE_DOWN))
1046 /* this case is in fact a combination of not less than three bugs:
1047 first, it calls InitMovDir() for elements that can move, although this is
1048 already done by InitField(); then, it checks the element that was at this
1049 field _before_ the call to InitField() (which can change it); lastly, it
1050 was not called for "mole with direction" elements, which were treated as
1051 "cannot move" due to (fixed) wrong element initialization in "src/init.c"
1055 inline void DrawGameValue_Emeralds(int value)
1057 DrawText(DX_EMERALDS, DY_EMERALDS, int2str(value, 3), FONT_TEXT_2);
1060 inline void DrawGameValue_Dynamite(int value)
1062 DrawText(DX_DYNAMITE, DY_DYNAMITE, int2str(value, 3), FONT_TEXT_2);
1065 inline void DrawGameValue_Keys(struct PlayerInfo *player)
1069 for (i = 0; i < MAX_KEYS; i++)
1071 DrawMiniGraphicExt(drawto, DX_KEYS + i * MINI_TILEX, DY_KEYS,
1072 el2edimg(EL_KEY_1 + i));
1075 inline void DrawGameValue_Score(int value)
1077 DrawText(DX_SCORE, DY_SCORE, int2str(value, 5), FONT_TEXT_2);
1080 inline void DrawGameValue_Time(int value)
1083 DrawText(DX_TIME1, DY_TIME, int2str(value, 3), FONT_TEXT_2);
1085 DrawText(DX_TIME2, DY_TIME, int2str(value, 4), FONT_LEVEL_NUMBER);
1088 inline void DrawGameValue_Level(int value)
1091 DrawText(DX_LEVEL, DY_LEVEL, int2str(value, 2), FONT_TEXT_2);
1094 /* misuse area for displaying emeralds to draw bigger level number */
1095 DrawTextExt(drawto, DX_EMERALDS, DY_EMERALDS,
1096 int2str(value, 3), FONT_LEVEL_NUMBER, BLIT_OPAQUE);
1098 /* now copy it to the area for displaying level number */
1099 BlitBitmap(drawto, drawto,
1100 DX_EMERALDS, DY_EMERALDS + 1,
1101 getFontWidth(FONT_LEVEL_NUMBER) * 3,
1102 getFontHeight(FONT_LEVEL_NUMBER) - 1,
1103 DX_LEVEL - 1, DY_LEVEL + 1);
1105 /* restore the area for displaying emeralds */
1106 DrawGameValue_Emeralds(local_player->gems_still_needed);
1108 /* yes, this is all really ugly :-) */
1112 void DrawGameDoorValues()
1116 DrawGameValue_Level(level_nr);
1118 for (i = 0; i < MAX_PLAYERS; i++)
1119 DrawGameValue_Keys(&stored_player[i]);
1121 DrawGameValue_Emeralds(local_player->gems_still_needed);
1122 DrawGameValue_Dynamite(local_player->inventory_size);
1123 DrawGameValue_Score(local_player->score);
1124 DrawGameValue_Time(TimeLeft);
1127 void DrawGameDoorValues_EM(int emeralds, int dynamite, int score, int time)
1129 DrawGameValue_Emeralds(emeralds);
1130 DrawGameValue_Dynamite(dynamite);
1131 DrawGameValue_Score(score);
1132 DrawGameValue_Time(time);
1135 static void resolve_group_element(int group_element, int recursion_depth)
1137 static int group_nr;
1138 static struct ElementGroupInfo *group;
1139 struct ElementGroupInfo *actual_group = element_info[group_element].group;
1142 if (recursion_depth > NUM_GROUP_ELEMENTS) /* recursion too deep */
1144 Error(ERR_WARN, "recursion too deep when resolving group element %d",
1145 group_element - EL_GROUP_START + 1);
1147 /* replace element which caused too deep recursion by question mark */
1148 group->element_resolved[group->num_elements_resolved++] = EL_UNKNOWN;
1153 if (recursion_depth == 0) /* initialization */
1155 group = element_info[group_element].group;
1156 group_nr = group_element - EL_GROUP_START;
1158 group->num_elements_resolved = 0;
1159 group->choice_pos = 0;
1162 for (i = 0; i < actual_group->num_elements; i++)
1164 int element = actual_group->element[i];
1166 if (group->num_elements_resolved == NUM_FILE_ELEMENTS)
1169 if (IS_GROUP_ELEMENT(element))
1170 resolve_group_element(element, recursion_depth + 1);
1173 group->element_resolved[group->num_elements_resolved++] = element;
1174 element_info[element].in_group[group_nr] = TRUE;
1179 if (recursion_depth == 0 && group_element <= EL_GROUP_4)
1181 printf("::: group %d: %d resolved elements\n",
1182 group_element - EL_GROUP_START, group->num_elements_resolved);
1183 for (i = 0; i < group->num_elements_resolved; i++)
1184 printf("::: - %d ['%s']\n", group->element_resolved[i],
1185 element_info[group->element_resolved[i]].token_name);
1192 =============================================================================
1194 -----------------------------------------------------------------------------
1195 initialize game engine due to level / tape version number
1196 =============================================================================
1199 static void InitGameEngine()
1203 /* set game engine from tape file when re-playing, else from level file */
1204 game.engine_version = (tape.playing ? tape.engine_version :
1205 level.game_version);
1207 /* ---------------------------------------------------------------------- */
1208 /* set flags for bugs and changes according to active game engine version */
1209 /* ---------------------------------------------------------------------- */
1213 Before 3.1.0, custom elements that "change when pushing" changed directly
1214 after the player started pushing them (until then handled in "DigField()").
1215 Since 3.1.0, these custom elements are not changed until the "pushing"
1216 move of the element is finished (now handled in "ContinueMoving()").
1218 Affected levels/tapes:
1219 The first condition is generally needed for all levels/tapes before version
1220 3.1.0, which might use the old behaviour before it was changed; known tapes
1221 that are affected are some tapes from the level set "Walpurgis Gardens" by
1223 The second condition is an exception from the above case and is needed for
1224 the special case of tapes recorded with game (not engine!) version 3.1.0 or
1225 above (including some development versions of 3.1.0), but before it was
1226 known that this change would break tapes like the above and was fixed in
1227 3.1.1, so that the changed behaviour was active although the engine version
1228 while recording maybe was before 3.1.0. There is at least one tape that is
1229 affected by this exception, which is the tape for the one-level set "Bug
1230 Machine" by Juergen Bonhagen.
1233 game.use_bug_change_when_pushing =
1234 (game.engine_version < VERSION_IDENT(3,1,0,0) &&
1236 tape.game_version >= VERSION_IDENT(3,1,0,0) &&
1237 tape.game_version < VERSION_IDENT(3,1,1,0)));
1239 /* ---------------------------------------------------------------------- */
1241 /* dynamically adjust element properties according to game engine version */
1242 InitElementPropertiesEngine(game.engine_version);
1245 printf("level %d: level version == %06d\n", level_nr, level.game_version);
1246 printf(" tape version == %06d [%s] [file: %06d]\n",
1247 tape.engine_version, (tape.playing ? "PLAYING" : "RECORDING"),
1249 printf(" => game.engine_version == %06d\n", game.engine_version);
1252 /* ---------- recursively resolve group elements ------------------------- */
1254 for (i = 0; i < MAX_NUM_ELEMENTS; i++)
1255 for (j = 0; j < NUM_GROUP_ELEMENTS; j++)
1256 element_info[i].in_group[j] = FALSE;
1258 for (i = 0; i < NUM_GROUP_ELEMENTS; i++)
1259 resolve_group_element(EL_GROUP_START + i, 0);
1261 /* ---------- initialize player's initial move delay --------------------- */
1263 #if USE_NEW_MOVE_DELAY
1264 /* dynamically adjust player properties according to level information */
1265 game.initial_move_delay_value =
1266 (level.double_speed ? MOVE_DELAY_HIGH_SPEED : MOVE_DELAY_NORMAL_SPEED);
1268 /* dynamically adjust player properties according to game engine version */
1269 game.initial_move_delay = (game.engine_version <= VERSION_IDENT(2,0,1,0) ?
1270 game.initial_move_delay_value : 0);
1272 /* dynamically adjust player properties according to game engine version */
1273 game.initial_move_delay =
1274 (game.engine_version <= VERSION_IDENT(2,0,1,0) ? INITIAL_MOVE_DELAY_ON :
1275 INITIAL_MOVE_DELAY_OFF);
1277 /* dynamically adjust player properties according to level information */
1278 game.initial_move_delay_value =
1279 (level.double_speed ? MOVE_DELAY_HIGH_SPEED : MOVE_DELAY_NORMAL_SPEED);
1282 /* ---------- initialize player's initial push delay --------------------- */
1284 /* dynamically adjust player properties according to game engine version */
1285 game.initial_push_delay_value =
1286 (game.engine_version < VERSION_IDENT(3,0,7,1) ? 5 : -1);
1288 /* ---------- initialize changing elements ------------------------------- */
1290 /* initialize changing elements information */
1291 for (i = 0; i < MAX_NUM_ELEMENTS; i++)
1293 struct ElementInfo *ei = &element_info[i];
1295 /* this pointer might have been changed in the level editor */
1296 ei->change = &ei->change_page[0];
1298 if (!IS_CUSTOM_ELEMENT(i))
1300 ei->change->target_element = EL_EMPTY_SPACE;
1301 ei->change->delay_fixed = 0;
1302 ei->change->delay_random = 0;
1303 ei->change->delay_frames = 1;
1306 ei->change_events = CE_BITMASK_DEFAULT;
1307 for (j = 0; j < NUM_CHANGE_EVENTS; j++)
1309 ei->event_page_nr[j] = 0;
1310 ei->event_page[j] = &ei->change_page[0];
1314 /* add changing elements from pre-defined list */
1315 for (i = 0; change_delay_list[i].element != EL_UNDEFINED; i++)
1317 struct ChangingElementInfo *ch_delay = &change_delay_list[i];
1318 struct ElementInfo *ei = &element_info[ch_delay->element];
1320 ei->change->target_element = ch_delay->target_element;
1321 ei->change->delay_fixed = ch_delay->change_delay;
1323 ei->change->pre_change_function = ch_delay->pre_change_function;
1324 ei->change->change_function = ch_delay->change_function;
1325 ei->change->post_change_function = ch_delay->post_change_function;
1327 ei->change_events |= CH_EVENT_BIT(CE_DELAY);
1330 SET_PROPERTY(ch_delay->element, EP_CAN_CHANGE, TRUE);
1335 /* add change events from custom element configuration */
1336 for (i = 0; i < NUM_CUSTOM_ELEMENTS; i++)
1338 struct ElementInfo *ei = &element_info[EL_CUSTOM_START + i];
1340 for (j = 0; j < ei->num_change_pages; j++)
1342 if (!ei->change_page[j].can_change)
1345 for (k = 0; k < NUM_CHANGE_EVENTS; k++)
1347 /* only add event page for the first page found with this event */
1348 if (ei->change_page[j].events & CH_EVENT_BIT(k) &&
1349 !(ei->change_events & CH_EVENT_BIT(k)))
1351 ei->change_events |= CH_EVENT_BIT(k);
1352 ei->event_page_nr[k] = j;
1353 ei->event_page[k] = &ei->change_page[j];
1361 /* add change events from custom element configuration */
1362 for (i = 0; i < NUM_CUSTOM_ELEMENTS; i++)
1364 int element = EL_CUSTOM_START + i;
1366 /* only add custom elements that change after fixed/random frame delay */
1367 if (CAN_CHANGE(element) && HAS_CHANGE_EVENT(element, CE_DELAY))
1368 element_info[element].change_events |= CH_EVENT_BIT(CE_DELAY);
1372 /* ---------- initialize run-time trigger player and element ------------- */
1374 for (i = 0; i < NUM_CUSTOM_ELEMENTS; i++)
1376 struct ElementInfo *ei = &element_info[EL_CUSTOM_START + i];
1378 for (j = 0; j < ei->num_change_pages; j++)
1380 ei->change_page[j].actual_trigger_element = EL_EMPTY;
1381 ei->change_page[j].actual_trigger_player = EL_PLAYER_1;
1385 /* ---------- initialize trigger events ---------------------------------- */
1387 /* initialize trigger events information */
1388 for (i = 0; i < MAX_NUM_ELEMENTS; i++)
1389 trigger_events[i] = EP_BITMASK_DEFAULT;
1392 /* add trigger events from element change event properties */
1393 for (i = 0; i < MAX_NUM_ELEMENTS; i++)
1395 struct ElementInfo *ei = &element_info[i];
1397 for (j = 0; j < ei->num_change_pages; j++)
1399 if (!ei->change_page[j].can_change)
1402 if (ei->change_page[j].events & CH_EVENT_BIT(CE_BY_OTHER_ACTION))
1404 int trigger_element = ei->change_page[j].trigger_element;
1406 if (IS_GROUP_ELEMENT(trigger_element))
1408 struct ElementGroupInfo *group = element_info[trigger_element].group;
1410 for (k = 0; k < group->num_elements_resolved; k++)
1411 trigger_events[group->element_resolved[k]]
1412 |= ei->change_page[j].events;
1415 trigger_events[trigger_element] |= ei->change_page[j].events;
1420 /* add trigger events from element change event properties */
1421 for (i = 0; i < MAX_NUM_ELEMENTS; i++)
1422 if (HAS_CHANGE_EVENT(i, CE_BY_OTHER_ACTION))
1423 trigger_events[element_info[i].change->trigger_element] |=
1424 element_info[i].change->events;
1427 /* ---------- initialize push delay -------------------------------------- */
1429 /* initialize push delay values to default */
1430 for (i = 0; i < MAX_NUM_ELEMENTS; i++)
1432 if (!IS_CUSTOM_ELEMENT(i))
1434 element_info[i].push_delay_fixed = game.default_push_delay_fixed;
1435 element_info[i].push_delay_random = game.default_push_delay_random;
1439 /* set push delay value for certain elements from pre-defined list */
1440 for (i = 0; push_delay_list[i].element != EL_UNDEFINED; i++)
1442 int e = push_delay_list[i].element;
1444 element_info[e].push_delay_fixed = push_delay_list[i].push_delay_fixed;
1445 element_info[e].push_delay_random = push_delay_list[i].push_delay_random;
1448 /* set push delay value for Supaplex elements for newer engine versions */
1449 if (game.engine_version >= VERSION_IDENT(3,1,0,0))
1451 for (i = 0; i < MAX_NUM_ELEMENTS; i++)
1453 if (IS_SP_ELEMENT(i))
1455 #if USE_NEW_MOVE_STYLE
1456 /* set SP push delay to just enough to push under a falling zonk */
1457 int delay = (game.engine_version >= VERSION_IDENT(3,1,1,0) ? 8 : 6);
1459 element_info[i].push_delay_fixed = delay;
1460 element_info[i].push_delay_random = 0;
1462 element_info[i].push_delay_fixed = 6; /* just enough to escape ... */
1463 element_info[i].push_delay_random = 0; /* ... from falling zonk */
1469 /* ---------- initialize move stepsize ----------------------------------- */
1471 /* initialize move stepsize values to default */
1472 for (i = 0; i < MAX_NUM_ELEMENTS; i++)
1473 if (!IS_CUSTOM_ELEMENT(i))
1474 element_info[i].move_stepsize = MOVE_STEPSIZE_NORMAL;
1476 /* set move stepsize value for certain elements from pre-defined list */
1477 for (i = 0; move_stepsize_list[i].element != EL_UNDEFINED; i++)
1479 int e = move_stepsize_list[i].element;
1481 element_info[e].move_stepsize = move_stepsize_list[i].move_stepsize;
1485 /* ---------- initialize move dig/leave ---------------------------------- */
1487 for (i = 0; i < MAX_NUM_ELEMENTS; i++)
1489 element_info[i].can_leave_element = FALSE;
1490 element_info[i].can_leave_element_last = FALSE;
1494 /* ---------- initialize gem count --------------------------------------- */
1496 /* initialize gem count values for each element */
1497 for (i = 0; i < MAX_NUM_ELEMENTS; i++)
1498 if (!IS_CUSTOM_ELEMENT(i))
1499 element_info[i].collect_count = 0;
1501 /* add gem count values for all elements from pre-defined list */
1502 for (i = 0; collect_count_list[i].element != EL_UNDEFINED; i++)
1503 element_info[collect_count_list[i].element].collect_count =
1504 collect_count_list[i].count;
1506 /* ---------- initialize access direction -------------------------------- */
1508 /* initialize access direction values to default (access from every side) */
1509 for (i = 0; i < MAX_NUM_ELEMENTS; i++)
1510 if (!IS_CUSTOM_ELEMENT(i))
1511 element_info[i].access_direction = MV_ALL_DIRECTIONS;
1513 /* set access direction value for certain elements from pre-defined list */
1514 for (i = 0; access_direction_list[i].element != EL_UNDEFINED; i++)
1515 element_info[access_direction_list[i].element].access_direction =
1516 access_direction_list[i].direction;
1521 =============================================================================
1523 -----------------------------------------------------------------------------
1524 initialize and start new game
1525 =============================================================================
1530 boolean emulate_bd = TRUE; /* unless non-BOULDERDASH elements found */
1531 boolean emulate_sb = TRUE; /* unless non-SOKOBAN elements found */
1532 boolean emulate_sp = TRUE; /* unless non-SUPAPLEX elements found */
1539 #if USE_NEW_AMOEBA_CODE
1540 printf("Using new amoeba code.\n");
1542 printf("Using old amoeba code.\n");
1547 /* don't play tapes over network */
1548 network_playing = (options.network && !tape.playing);
1550 for (i = 0; i < MAX_PLAYERS; i++)
1552 struct PlayerInfo *player = &stored_player[i];
1554 player->index_nr = i;
1555 player->index_bit = (1 << i);
1556 player->element_nr = EL_PLAYER_1 + i;
1558 player->present = FALSE;
1559 player->active = FALSE;
1562 player->effective_action = 0;
1563 player->programmed_action = 0;
1566 player->gems_still_needed = level.gems_needed;
1567 player->sokobanfields_still_needed = 0;
1568 player->lights_still_needed = 0;
1569 player->friends_still_needed = 0;
1571 for (j = 0; j < MAX_KEYS; j++)
1572 player->key[j] = FALSE;
1574 player->dynabomb_count = 0;
1575 player->dynabomb_size = 1;
1576 player->dynabombs_left = 0;
1577 player->dynabomb_xl = FALSE;
1579 player->MovDir = MV_NO_MOVING;
1582 player->GfxDir = MV_NO_MOVING;
1583 player->GfxAction = ACTION_DEFAULT;
1585 player->StepFrame = 0;
1587 player->use_murphy_graphic = FALSE;
1589 player->block_last_field = FALSE; /* initialized in InitPlayerField() */
1590 player->block_delay = -1; /* initialized in InitPlayerField() */
1592 player->can_fall_into_acid = CAN_MOVE_INTO_ACID(player->element_nr);
1594 player->actual_frame_counter = 0;
1596 player->step_counter = 0;
1598 player->last_move_dir = MV_NO_MOVING;
1600 player->is_waiting = FALSE;
1601 player->is_moving = FALSE;
1602 player->is_auto_moving = FALSE;
1603 player->is_digging = FALSE;
1604 player->is_snapping = FALSE;
1605 player->is_collecting = FALSE;
1606 player->is_pushing = FALSE;
1607 player->is_switching = FALSE;
1608 player->is_dropping = FALSE;
1610 player->is_bored = FALSE;
1611 player->is_sleeping = FALSE;
1613 player->frame_counter_bored = -1;
1614 player->frame_counter_sleeping = -1;
1616 player->anim_delay_counter = 0;
1617 player->post_delay_counter = 0;
1619 player->action_waiting = ACTION_DEFAULT;
1620 player->last_action_waiting = ACTION_DEFAULT;
1621 player->special_action_bored = ACTION_DEFAULT;
1622 player->special_action_sleeping = ACTION_DEFAULT;
1624 player->num_special_action_bored = 0;
1625 player->num_special_action_sleeping = 0;
1627 /* determine number of special actions for bored and sleeping animation */
1628 for (j = ACTION_BORING_1; j <= ACTION_BORING_LAST; j++)
1630 boolean found = FALSE;
1632 for (k = 0; k < NUM_DIRECTIONS; k++)
1633 if (el_act_dir2img(player->element_nr, j, k) !=
1634 el_act_dir2img(player->element_nr, ACTION_DEFAULT, k))
1638 player->num_special_action_bored++;
1642 for (j = ACTION_SLEEPING_1; j <= ACTION_SLEEPING_LAST; j++)
1644 boolean found = FALSE;
1646 for (k = 0; k < NUM_DIRECTIONS; k++)
1647 if (el_act_dir2img(player->element_nr, j, k) !=
1648 el_act_dir2img(player->element_nr, ACTION_DEFAULT, k))
1652 player->num_special_action_sleeping++;
1657 player->switch_x = -1;
1658 player->switch_y = -1;
1660 player->show_envelope = 0;
1662 player->move_delay = game.initial_move_delay;
1663 player->move_delay_value = game.initial_move_delay_value;
1665 player->move_delay_reset_counter = 0;
1667 #if USE_NEW_PUSH_DELAY
1668 player->push_delay = -1; /* initialized when pushing starts */
1669 player->push_delay_value = game.initial_push_delay_value;
1671 player->push_delay = 0;
1672 player->push_delay_value = game.initial_push_delay_value;
1675 player->drop_delay = 0;
1677 player->last_jx = player->last_jy = 0;
1678 player->jx = player->jy = 0;
1680 player->shield_normal_time_left = 0;
1681 player->shield_deadly_time_left = 0;
1683 player->inventory_infinite_element = EL_UNDEFINED;
1684 player->inventory_size = 0;
1686 DigField(player, 0, 0, 0, 0, 0, 0, DF_NO_PUSH);
1687 SnapField(player, 0, 0);
1689 player->LevelSolved = FALSE;
1690 player->GameOver = FALSE;
1693 network_player_action_received = FALSE;
1695 #if defined(NETWORK_AVALIABLE)
1696 /* initial null action */
1697 if (network_playing)
1698 SendToServer_MovePlayer(MV_NO_MOVING);
1706 TimeLeft = level.time;
1709 ScreenMovDir = MV_NO_MOVING;
1713 ScrollStepSize = 0; /* will be correctly initialized by ScrollScreen() */
1715 AllPlayersGone = FALSE;
1717 game.yamyam_content_nr = 0;
1718 game.magic_wall_active = FALSE;
1719 game.magic_wall_time_left = 0;
1720 game.light_time_left = 0;
1721 game.timegate_time_left = 0;
1722 game.switchgate_pos = 0;
1723 game.balloon_dir = MV_NO_MOVING;
1724 game.gravity = level.initial_gravity;
1725 game.explosions_delayed = TRUE;
1727 game.envelope_active = FALSE;
1729 for (i = 0; i < NUM_BELTS; i++)
1731 game.belt_dir[i] = MV_NO_MOVING;
1732 game.belt_dir_nr[i] = 3; /* not moving, next moving left */
1735 for (i = 0; i < MAX_NUM_AMOEBA; i++)
1736 AmoebaCnt[i] = AmoebaCnt2[i] = 0;
1738 for (x = 0; x < lev_fieldx; x++)
1740 for (y = 0; y < lev_fieldy; y++)
1742 Feld[x][y] = level.field[x][y];
1743 MovPos[x][y] = MovDir[x][y] = MovDelay[x][y] = 0;
1744 ChangeDelay[x][y] = 0;
1745 ChangePage[x][y] = -1;
1746 Store[x][y] = Store2[x][y] = StorePlayer[x][y] = Back[x][y] = 0;
1748 WasJustMoving[x][y] = 0;
1749 WasJustFalling[x][y] = 0;
1750 CheckCollision[x][y] = 0;
1752 Pushed[x][y] = FALSE;
1754 Changed[x][y] = CE_BITMASK_DEFAULT;
1755 ChangeEvent[x][y] = CE_BITMASK_DEFAULT;
1757 ExplodePhase[x][y] = 0;
1758 ExplodeDelay[x][y] = 0;
1759 ExplodeField[x][y] = EX_TYPE_NONE;
1761 RunnerVisit[x][y] = 0;
1762 PlayerVisit[x][y] = 0;
1765 GfxRandom[x][y] = INIT_GFX_RANDOM();
1766 GfxElement[x][y] = EL_UNDEFINED;
1767 GfxAction[x][y] = ACTION_DEFAULT;
1768 GfxDir[x][y] = MV_NO_MOVING;
1772 for (y = 0; y < lev_fieldy; y++)
1774 for (x = 0; x < lev_fieldx; x++)
1776 if (emulate_bd && !IS_BD_ELEMENT(Feld[x][y]))
1778 if (emulate_sb && !IS_SB_ELEMENT(Feld[x][y]))
1780 if (emulate_sp && !IS_SP_ELEMENT(Feld[x][y]))
1783 InitField(x, y, TRUE);
1789 game.emulation = (emulate_bd ? EMU_BOULDERDASH :
1790 emulate_sb ? EMU_SOKOBAN :
1791 emulate_sp ? EMU_SUPAPLEX : EMU_NONE);
1793 /* initialize explosion and ignition delay */
1794 for (i = 0; i < MAX_NUM_ELEMENTS; i++)
1796 if (!IS_CUSTOM_ELEMENT(i))
1799 int delay = (((IS_SP_ELEMENT(i) && i != EL_EMPTY_SPACE) &&
1800 game.engine_version >= VERSION_IDENT(3,1,0,0)) ||
1801 game.emulation == EMU_SUPAPLEX ? 3 : 2);
1802 int last_phase = (num_phase + 1) * delay;
1803 int half_phase = (num_phase / 2) * delay;
1805 element_info[i].explosion_delay = last_phase - 1;
1806 element_info[i].ignition_delay = half_phase;
1809 if (i == EL_BLACK_ORB)
1810 element_info[i].ignition_delay = 0;
1812 if (i == EL_BLACK_ORB)
1813 element_info[i].ignition_delay = 1;
1818 if (element_info[i].explosion_delay < 1) /* !!! check again !!! */
1819 element_info[i].explosion_delay = 1;
1821 if (element_info[i].ignition_delay < 1) /* !!! check again !!! */
1822 element_info[i].ignition_delay = 1;
1826 /* correct non-moving belts to start moving left */
1827 for (i = 0; i < NUM_BELTS; i++)
1828 if (game.belt_dir[i] == MV_NO_MOVING)
1829 game.belt_dir_nr[i] = 3; /* not moving, next moving left */
1831 /* check if any connected player was not found in playfield */
1832 for (i = 0; i < MAX_PLAYERS; i++)
1834 struct PlayerInfo *player = &stored_player[i];
1836 if (player->connected && !player->present)
1838 for (j = 0; j < MAX_PLAYERS; j++)
1840 struct PlayerInfo *some_player = &stored_player[j];
1841 int jx = some_player->jx, jy = some_player->jy;
1843 /* assign first free player found that is present in the playfield */
1844 if (some_player->present && !some_player->connected)
1846 player->present = TRUE;
1847 player->active = TRUE;
1849 some_player->present = FALSE;
1850 some_player->active = FALSE;
1853 player->element_nr = some_player->element_nr;
1856 #if USE_NEW_BLOCK_STYLE
1857 player->block_last_field = some_player->block_last_field;
1858 player->block_delay = some_player->block_delay;
1861 StorePlayer[jx][jy] = player->element_nr;
1862 player->jx = player->last_jx = jx;
1863 player->jy = player->last_jy = jy;
1873 /* when playing a tape, eliminate all players which do not participate */
1875 for (i = 0; i < MAX_PLAYERS; i++)
1877 if (stored_player[i].active && !tape.player_participates[i])
1879 struct PlayerInfo *player = &stored_player[i];
1880 int jx = player->jx, jy = player->jy;
1882 player->active = FALSE;
1883 StorePlayer[jx][jy] = 0;
1884 Feld[jx][jy] = EL_EMPTY;
1888 else if (!options.network && !setup.team_mode) /* && !tape.playing */
1890 /* when in single player mode, eliminate all but the first active player */
1892 for (i = 0; i < MAX_PLAYERS; i++)
1894 if (stored_player[i].active)
1896 for (j = i + 1; j < MAX_PLAYERS; j++)
1898 if (stored_player[j].active)
1900 struct PlayerInfo *player = &stored_player[j];
1901 int jx = player->jx, jy = player->jy;
1903 player->active = FALSE;
1904 player->present = FALSE;
1906 StorePlayer[jx][jy] = 0;
1907 Feld[jx][jy] = EL_EMPTY;
1914 /* when recording the game, store which players take part in the game */
1917 for (i = 0; i < MAX_PLAYERS; i++)
1918 if (stored_player[i].active)
1919 tape.player_participates[i] = TRUE;
1924 for (i = 0; i < MAX_PLAYERS; i++)
1926 struct PlayerInfo *player = &stored_player[i];
1928 printf("Player %d: present == %d, connected == %d, active == %d.\n",
1933 if (local_player == player)
1934 printf("Player %d is local player.\n", i+1);
1938 if (BorderElement == EL_EMPTY)
1941 SBX_Right = lev_fieldx - SCR_FIELDX;
1943 SBY_Lower = lev_fieldy - SCR_FIELDY;
1948 SBX_Right = lev_fieldx - SCR_FIELDX + 1;
1950 SBY_Lower = lev_fieldy - SCR_FIELDY + 1;
1953 if (lev_fieldx + (SBX_Left == -1 ? 2 : 0) <= SCR_FIELDX)
1954 SBX_Left = SBX_Right = -1 * (SCR_FIELDX - lev_fieldx) / 2;
1956 if (lev_fieldy + (SBY_Upper == -1 ? 2 : 0) <= SCR_FIELDY)
1957 SBY_Upper = SBY_Lower = -1 * (SCR_FIELDY - lev_fieldy) / 2;
1959 /* if local player not found, look for custom element that might create
1960 the player (make some assumptions about the right custom element) */
1961 if (!local_player->present)
1963 int start_x = 0, start_y = 0;
1964 int found_rating = 0;
1965 int found_element = EL_UNDEFINED;
1967 for (y = 0; y < lev_fieldy; y++) for (x = 0; x < lev_fieldx; x++)
1969 int element = Feld[x][y];
1974 if (!IS_CUSTOM_ELEMENT(element))
1977 if (CAN_CHANGE(element))
1979 for (i = 0; i < element_info[element].num_change_pages; i++)
1981 content = element_info[element].change_page[i].target_element;
1982 is_player = ELEM_IS_PLAYER(content);
1984 if (is_player && (found_rating < 3 || element < found_element))
1990 found_element = element;
1995 for (yy = 0; yy < 3; yy++) for (xx = 0; xx < 3; xx++)
1997 content = element_info[element].content[xx][yy];
1998 is_player = ELEM_IS_PLAYER(content);
2000 if (is_player && (found_rating < 2 || element < found_element))
2002 start_x = x + xx - 1;
2003 start_y = y + yy - 1;
2006 found_element = element;
2009 if (!CAN_CHANGE(element))
2012 for (i = 0; i < element_info[element].num_change_pages; i++)
2014 content= element_info[element].change_page[i].target_content[xx][yy];
2015 is_player = ELEM_IS_PLAYER(content);
2017 if (is_player && (found_rating < 1 || element < found_element))
2019 start_x = x + xx - 1;
2020 start_y = y + yy - 1;
2023 found_element = element;
2029 scroll_x = (start_x < SBX_Left + MIDPOSX ? SBX_Left :
2030 start_x > SBX_Right + MIDPOSX ? SBX_Right :
2033 scroll_y = (start_y < SBY_Upper + MIDPOSY ? SBY_Upper :
2034 start_y > SBY_Lower + MIDPOSY ? SBY_Lower :
2040 scroll_x = (local_player->jx < SBX_Left + MIDPOSX ? SBX_Left :
2041 local_player->jx > SBX_Right + MIDPOSX ? SBX_Right :
2042 local_player->jx - MIDPOSX);
2044 scroll_y = (local_player->jy < SBY_Upper + MIDPOSY ? SBY_Upper :
2045 local_player->jy > SBY_Lower + MIDPOSY ? SBY_Lower :
2046 local_player->jy - MIDPOSY);
2048 scroll_x = SBX_Left;
2049 scroll_y = SBY_Upper;
2050 if (local_player->jx >= SBX_Left + MIDPOSX)
2051 scroll_x = (local_player->jx <= SBX_Right + MIDPOSX ?
2052 local_player->jx - MIDPOSX :
2054 if (local_player->jy >= SBY_Upper + MIDPOSY)
2055 scroll_y = (local_player->jy <= SBY_Lower + MIDPOSY ?
2056 local_player->jy - MIDPOSY :
2061 CloseDoor(DOOR_CLOSE_1);
2063 /* !!! FIX THIS (START) !!! */
2064 if (level.game_engine_type == GAME_ENGINE_TYPE_EM)
2066 InitGameEngine_EM();
2073 /* after drawing the level, correct some elements */
2074 if (game.timegate_time_left == 0)
2075 CloseAllOpenTimegates();
2077 if (setup.soft_scrolling)
2078 BlitBitmap(fieldbuffer, backbuffer, FX, FY, SXSIZE, SYSIZE, SX, SY);
2080 redraw_mask |= REDRAW_FROM_BACKBUFFER;
2083 /* !!! FIX THIS (END) !!! */
2085 /* copy default game door content to main double buffer */
2086 BlitBitmap(graphic_info[IMG_GLOBAL_DOOR].bitmap, drawto,
2087 DOOR_GFX_PAGEX5, DOOR_GFX_PAGEY1, DXSIZE, DYSIZE, DX, DY);
2089 DrawGameDoorValues();
2093 game_gadget[SOUND_CTRL_ID_MUSIC]->checked = setup.sound_music;
2094 game_gadget[SOUND_CTRL_ID_LOOPS]->checked = setup.sound_loops;
2095 game_gadget[SOUND_CTRL_ID_SIMPLE]->checked = setup.sound_simple;
2099 /* copy actual game door content to door double buffer for OpenDoor() */
2100 BlitBitmap(drawto, bitmap_db_door,
2101 DX, DY, DXSIZE, DYSIZE, DOOR_GFX_PAGEX1, DOOR_GFX_PAGEY1);
2103 OpenDoor(DOOR_OPEN_ALL);
2105 PlaySoundStereo(SND_GAME_STARTING, SOUND_MIDDLE);
2107 if (setup.sound_music)
2110 KeyboardAutoRepeatOffUnlessAutoplay();
2114 for (i = 0; i < MAX_PLAYERS; i++)
2115 printf("Player %d %sactive.\n",
2116 i + 1, (stored_player[i].active ? "" : "not "));
2120 printf("::: starting game [%d]\n", FrameCounter);
2124 void UpdateEngineValues(int actual_scroll_x, int actual_scroll_y)
2126 /* this is used for non-R'n'D game engines to update certain engine values */
2128 /* needed to determine if sounds are played within the visible screen area */
2129 scroll_x = actual_scroll_x;
2130 scroll_y = actual_scroll_y;
2133 void InitMovDir(int x, int y)
2135 int i, element = Feld[x][y];
2136 static int xy[4][2] =
2143 static int direction[3][4] =
2145 { MV_RIGHT, MV_UP, MV_LEFT, MV_DOWN },
2146 { MV_LEFT, MV_DOWN, MV_RIGHT, MV_UP },
2147 { MV_LEFT, MV_RIGHT, MV_UP, MV_DOWN }
2156 Feld[x][y] = EL_BUG;
2157 MovDir[x][y] = direction[0][element - EL_BUG_RIGHT];
2160 case EL_SPACESHIP_RIGHT:
2161 case EL_SPACESHIP_UP:
2162 case EL_SPACESHIP_LEFT:
2163 case EL_SPACESHIP_DOWN:
2164 Feld[x][y] = EL_SPACESHIP;
2165 MovDir[x][y] = direction[0][element - EL_SPACESHIP_RIGHT];
2168 case EL_BD_BUTTERFLY_RIGHT:
2169 case EL_BD_BUTTERFLY_UP:
2170 case EL_BD_BUTTERFLY_LEFT:
2171 case EL_BD_BUTTERFLY_DOWN:
2172 Feld[x][y] = EL_BD_BUTTERFLY;
2173 MovDir[x][y] = direction[0][element - EL_BD_BUTTERFLY_RIGHT];
2176 case EL_BD_FIREFLY_RIGHT:
2177 case EL_BD_FIREFLY_UP:
2178 case EL_BD_FIREFLY_LEFT:
2179 case EL_BD_FIREFLY_DOWN:
2180 Feld[x][y] = EL_BD_FIREFLY;
2181 MovDir[x][y] = direction[0][element - EL_BD_FIREFLY_RIGHT];
2184 case EL_PACMAN_RIGHT:
2186 case EL_PACMAN_LEFT:
2187 case EL_PACMAN_DOWN:
2188 Feld[x][y] = EL_PACMAN;
2189 MovDir[x][y] = direction[0][element - EL_PACMAN_RIGHT];
2192 case EL_SP_SNIKSNAK:
2193 MovDir[x][y] = MV_UP;
2196 case EL_SP_ELECTRON:
2197 MovDir[x][y] = MV_LEFT;
2204 Feld[x][y] = EL_MOLE;
2205 MovDir[x][y] = direction[2][element - EL_MOLE_LEFT];
2209 if (IS_CUSTOM_ELEMENT(element))
2211 struct ElementInfo *ei = &element_info[element];
2212 int move_direction_initial = ei->move_direction_initial;
2213 int move_pattern = ei->move_pattern;
2215 if (move_direction_initial == MV_START_PREVIOUS)
2217 if (MovDir[x][y] != MV_NO_MOVING)
2220 move_direction_initial = MV_START_AUTOMATIC;
2223 if (move_direction_initial == MV_START_RANDOM)
2224 MovDir[x][y] = 1 << RND(4);
2225 else if (move_direction_initial & MV_ANY_DIRECTION)
2226 MovDir[x][y] = move_direction_initial;
2227 else if (move_pattern == MV_ALL_DIRECTIONS ||
2228 move_pattern == MV_TURNING_LEFT ||
2229 move_pattern == MV_TURNING_RIGHT ||
2230 move_pattern == MV_TURNING_LEFT_RIGHT ||
2231 move_pattern == MV_TURNING_RIGHT_LEFT ||
2232 move_pattern == MV_TURNING_RANDOM)
2233 MovDir[x][y] = 1 << RND(4);
2234 else if (move_pattern == MV_HORIZONTAL)
2235 MovDir[x][y] = (RND(2) ? MV_LEFT : MV_RIGHT);
2236 else if (move_pattern == MV_VERTICAL)
2237 MovDir[x][y] = (RND(2) ? MV_UP : MV_DOWN);
2238 else if (move_pattern & MV_ANY_DIRECTION)
2239 MovDir[x][y] = element_info[element].move_pattern;
2240 else if (move_pattern == MV_ALONG_LEFT_SIDE ||
2241 move_pattern == MV_ALONG_RIGHT_SIDE)
2244 /* use random direction as default start direction */
2245 if (game.engine_version >= VERSION_IDENT(3,1,0,0))
2246 MovDir[x][y] = 1 << RND(4);
2249 for (i = 0; i < NUM_DIRECTIONS; i++)
2251 int x1 = x + xy[i][0];
2252 int y1 = y + xy[i][1];
2254 if (!IN_LEV_FIELD(x1, y1) || !IS_FREE(x1, y1))
2256 if (move_pattern == MV_ALONG_RIGHT_SIDE)
2257 MovDir[x][y] = direction[0][i];
2259 MovDir[x][y] = direction[1][i];
2268 MovDir[x][y] = 1 << RND(4);
2270 if (element != EL_BUG &&
2271 element != EL_SPACESHIP &&
2272 element != EL_BD_BUTTERFLY &&
2273 element != EL_BD_FIREFLY)
2276 for (i = 0; i < NUM_DIRECTIONS; i++)
2278 int x1 = x + xy[i][0];
2279 int y1 = y + xy[i][1];
2281 if (!IN_LEV_FIELD(x1, y1) || !IS_FREE(x1, y1))
2283 if (element == EL_BUG || element == EL_BD_BUTTERFLY)
2285 MovDir[x][y] = direction[0][i];
2288 else if (element == EL_SPACESHIP || element == EL_BD_FIREFLY ||
2289 element == EL_SP_SNIKSNAK || element == EL_SP_ELECTRON)
2291 MovDir[x][y] = direction[1][i];
2300 GfxDir[x][y] = MovDir[x][y];
2303 void InitAmoebaNr(int x, int y)
2306 int group_nr = AmoebeNachbarNr(x, y);
2310 for (i = 1; i < MAX_NUM_AMOEBA; i++)
2312 if (AmoebaCnt[i] == 0)
2320 AmoebaNr[x][y] = group_nr;
2321 AmoebaCnt[group_nr]++;
2322 AmoebaCnt2[group_nr]++;
2328 boolean raise_level = FALSE;
2330 if (local_player->MovPos)
2334 if (tape.auto_play) /* tape might already be stopped here */
2335 tape.auto_play_level_solved = TRUE;
2337 if (tape.playing && tape.auto_play)
2338 tape.auto_play_level_solved = TRUE;
2341 local_player->LevelSolved = FALSE;
2343 PlaySoundStereo(SND_GAME_WINNING, SOUND_MIDDLE);
2347 if (!tape.playing && setup.sound_loops)
2348 PlaySoundExt(SND_GAME_LEVELTIME_BONUS, SOUND_MAX_VOLUME, SOUND_MIDDLE,
2349 SND_CTRL_PLAY_LOOP);
2351 while (TimeLeft > 0)
2353 if (!tape.playing && !setup.sound_loops)
2354 PlaySoundStereo(SND_GAME_LEVELTIME_BONUS, SOUND_MIDDLE);
2355 if (TimeLeft > 0 && !(TimeLeft % 10))
2356 RaiseScore(level.score[SC_TIME_BONUS]);
2357 if (TimeLeft > 100 && !(TimeLeft % 10))
2362 DrawGameValue_Time(TimeLeft);
2370 if (!tape.playing && setup.sound_loops)
2371 StopSound(SND_GAME_LEVELTIME_BONUS);
2373 else if (level.time == 0) /* level without time limit */
2375 if (!tape.playing && setup.sound_loops)
2376 PlaySoundExt(SND_GAME_LEVELTIME_BONUS, SOUND_MAX_VOLUME, SOUND_MIDDLE,
2377 SND_CTRL_PLAY_LOOP);
2379 while (TimePlayed < 999)
2381 if (!tape.playing && !setup.sound_loops)
2382 PlaySoundStereo(SND_GAME_LEVELTIME_BONUS, SOUND_MIDDLE);
2383 if (TimePlayed < 999 && !(TimePlayed % 10))
2384 RaiseScore(level.score[SC_TIME_BONUS]);
2385 if (TimePlayed < 900 && !(TimePlayed % 10))
2390 DrawGameValue_Time(TimePlayed);
2398 if (!tape.playing && setup.sound_loops)
2399 StopSound(SND_GAME_LEVELTIME_BONUS);
2402 /* close exit door after last player */
2403 if ((Feld[ExitX][ExitY] == EL_EXIT_OPEN ||
2404 Feld[ExitX][ExitY] == EL_SP_EXIT_OPEN) && AllPlayersGone)
2406 int element = Feld[ExitX][ExitY];
2408 Feld[ExitX][ExitY] = (element == EL_EXIT_OPEN ? EL_EXIT_CLOSING :
2409 EL_SP_EXIT_CLOSING);
2411 PlayLevelSoundElementAction(ExitX, ExitY, element, ACTION_CLOSING);
2414 /* Hero disappears */
2415 DrawLevelField(ExitX, ExitY);
2421 CloseDoor(DOOR_CLOSE_1);
2426 SaveTape(tape.level_nr); /* Ask to save tape */
2429 if (level_nr == leveldir_current->handicap_level)
2431 leveldir_current->handicap_level++;
2432 SaveLevelSetup_SeriesInfo();
2435 if (level_editor_test_game)
2436 local_player->score = -1; /* no highscore when playing from editor */
2437 else if (level_nr < leveldir_current->last_level)
2438 raise_level = TRUE; /* advance to next level */
2440 if ((hi_pos = NewHiScore()) >= 0)
2442 game_status = GAME_MODE_SCORES;
2443 DrawHallOfFame(hi_pos);
2452 game_status = GAME_MODE_MAIN;
2469 LoadScore(level_nr);
2471 if (strcmp(setup.player_name, EMPTY_PLAYER_NAME) == 0 ||
2472 local_player->score < highscore[MAX_SCORE_ENTRIES - 1].Score)
2475 for (k = 0; k < MAX_SCORE_ENTRIES; k++)
2477 if (local_player->score > highscore[k].Score)
2479 /* player has made it to the hall of fame */
2481 if (k < MAX_SCORE_ENTRIES - 1)
2483 int m = MAX_SCORE_ENTRIES - 1;
2486 for (l = k; l < MAX_SCORE_ENTRIES; l++)
2487 if (!strcmp(setup.player_name, highscore[l].Name))
2489 if (m == k) /* player's new highscore overwrites his old one */
2493 for (l = m; l > k; l--)
2495 strcpy(highscore[l].Name, highscore[l - 1].Name);
2496 highscore[l].Score = highscore[l - 1].Score;
2503 strncpy(highscore[k].Name, setup.player_name, MAX_PLAYER_NAME_LEN);
2504 highscore[k].Name[MAX_PLAYER_NAME_LEN] = '\0';
2505 highscore[k].Score = local_player->score;
2511 else if (!strncmp(setup.player_name, highscore[k].Name,
2512 MAX_PLAYER_NAME_LEN))
2513 break; /* player already there with a higher score */
2519 SaveScore(level_nr);
2524 void InitPlayerGfxAnimation(struct PlayerInfo *player, int action, int dir)
2526 if (player->GfxAction != action || player->GfxDir != dir)
2529 printf("Player frame reset! (%d => %d, %d => %d)\n",
2530 player->GfxAction, action, player->GfxDir, dir);
2533 player->GfxAction = action;
2534 player->GfxDir = dir;
2536 player->StepFrame = 0;
2540 static void ResetRandomAnimationValue(int x, int y)
2542 GfxRandom[x][y] = INIT_GFX_RANDOM();
2545 static void ResetGfxAnimation(int x, int y)
2548 GfxAction[x][y] = ACTION_DEFAULT;
2549 GfxDir[x][y] = MovDir[x][y];
2552 void InitMovingField(int x, int y, int direction)
2554 int element = Feld[x][y];
2555 int dx = (direction == MV_LEFT ? -1 : direction == MV_RIGHT ? +1 : 0);
2556 int dy = (direction == MV_UP ? -1 : direction == MV_DOWN ? +1 : 0);
2560 if (!WasJustMoving[x][y] || direction != MovDir[x][y])
2561 ResetGfxAnimation(x, y);
2563 MovDir[newx][newy] = MovDir[x][y] = direction;
2564 GfxDir[x][y] = direction;
2566 if (Feld[newx][newy] == EL_EMPTY)
2567 Feld[newx][newy] = EL_BLOCKED;
2569 if (direction == MV_DOWN && CAN_FALL(element))
2570 GfxAction[x][y] = ACTION_FALLING;
2572 GfxAction[x][y] = ACTION_MOVING;
2574 GfxFrame[newx][newy] = GfxFrame[x][y];
2575 GfxRandom[newx][newy] = GfxRandom[x][y];
2576 GfxAction[newx][newy] = GfxAction[x][y];
2577 GfxDir[newx][newy] = GfxDir[x][y];
2580 void Moving2Blocked(int x, int y, int *goes_to_x, int *goes_to_y)
2582 int direction = MovDir[x][y];
2583 int newx = x + (direction == MV_LEFT ? -1 : direction == MV_RIGHT ? +1 : 0);
2584 int newy = y + (direction == MV_UP ? -1 : direction == MV_DOWN ? +1 : 0);
2590 void Blocked2Moving(int x, int y, int *comes_from_x, int *comes_from_y)
2592 int oldx = x, oldy = y;
2593 int direction = MovDir[x][y];
2595 if (direction == MV_LEFT)
2597 else if (direction == MV_RIGHT)
2599 else if (direction == MV_UP)
2601 else if (direction == MV_DOWN)
2604 *comes_from_x = oldx;
2605 *comes_from_y = oldy;
2608 int MovingOrBlocked2Element(int x, int y)
2610 int element = Feld[x][y];
2612 if (element == EL_BLOCKED)
2616 Blocked2Moving(x, y, &oldx, &oldy);
2617 return Feld[oldx][oldy];
2623 static int MovingOrBlocked2ElementIfNotLeaving(int x, int y)
2625 /* like MovingOrBlocked2Element(), but if element is moving
2626 and (x,y) is the field the moving element is just leaving,
2627 return EL_BLOCKED instead of the element value */
2628 int element = Feld[x][y];
2630 if (IS_MOVING(x, y))
2632 if (element == EL_BLOCKED)
2636 Blocked2Moving(x, y, &oldx, &oldy);
2637 return Feld[oldx][oldy];
2646 static void RemoveField(int x, int y)
2648 Feld[x][y] = EL_EMPTY;
2655 ChangeDelay[x][y] = 0;
2656 ChangePage[x][y] = -1;
2657 Pushed[x][y] = FALSE;
2660 ExplodeField[x][y] = EX_TYPE_NONE;
2663 GfxElement[x][y] = EL_UNDEFINED;
2664 GfxAction[x][y] = ACTION_DEFAULT;
2665 GfxDir[x][y] = MV_NO_MOVING;
2668 void RemoveMovingField(int x, int y)
2670 int oldx = x, oldy = y, newx = x, newy = y;
2671 int element = Feld[x][y];
2672 int next_element = EL_UNDEFINED;
2674 if (element != EL_BLOCKED && !IS_MOVING(x, y))
2677 if (IS_MOVING(x, y))
2679 Moving2Blocked(x, y, &newx, &newy);
2681 if (Feld[newx][newy] != EL_BLOCKED)
2684 if (Feld[newx][newy] != EL_BLOCKED)
2686 /* element is moving, but target field is not free (blocked), but
2687 already occupied by something different (example: acid pool);
2688 in this case, only remove the moving field, but not the target */
2690 RemoveField(oldx, oldy);
2692 Store[oldx][oldy] = Store2[oldx][oldy] = 0;
2694 DrawLevelField(oldx, oldy);
2700 else if (element == EL_BLOCKED)
2702 Blocked2Moving(x, y, &oldx, &oldy);
2703 if (!IS_MOVING(oldx, oldy))
2707 if (element == EL_BLOCKED &&
2708 (Feld[oldx][oldy] == EL_QUICKSAND_EMPTYING ||
2709 Feld[oldx][oldy] == EL_MAGIC_WALL_EMPTYING ||
2710 Feld[oldx][oldy] == EL_BD_MAGIC_WALL_EMPTYING ||
2711 Feld[oldx][oldy] == EL_AMOEBA_DROPPING))
2712 next_element = get_next_element(Feld[oldx][oldy]);
2714 RemoveField(oldx, oldy);
2715 RemoveField(newx, newy);
2717 Store[oldx][oldy] = Store2[oldx][oldy] = 0;
2719 if (next_element != EL_UNDEFINED)
2720 Feld[oldx][oldy] = next_element;
2722 DrawLevelField(oldx, oldy);
2723 DrawLevelField(newx, newy);
2726 void DrawDynamite(int x, int y)
2728 int sx = SCREENX(x), sy = SCREENY(y);
2729 int graphic = el2img(Feld[x][y]);
2732 if (!IN_SCR_FIELD(sx, sy) || IS_PLAYER(x, y))
2735 if (IS_WALKABLE_INSIDE(Back[x][y]))
2739 DrawGraphic(sx, sy, el2img(Back[x][y]), 0);
2740 else if (Store[x][y])
2741 DrawGraphic(sx, sy, el2img(Store[x][y]), 0);
2743 frame = getGraphicAnimationFrame(graphic, GfxFrame[x][y]);
2746 if (Back[x][y] || Store[x][y])
2747 DrawGraphicThruMask(sx, sy, graphic, frame);
2749 DrawGraphic(sx, sy, graphic, frame);
2751 if (game.emulation == EMU_SUPAPLEX)
2752 DrawGraphic(sx, sy, IMG_SP_DISK_RED, frame);
2753 else if (Store[x][y])
2754 DrawGraphicThruMask(sx, sy, graphic, frame);
2756 DrawGraphic(sx, sy, graphic, frame);
2760 void CheckDynamite(int x, int y)
2762 if (MovDelay[x][y] != 0) /* dynamite is still waiting to explode */
2766 if (MovDelay[x][y] != 0)
2769 PlayLevelSoundActionIfLoop(x, y, ACTION_ACTIVE);
2776 StopLevelSoundActionIfLoop(x, y, ACTION_ACTIVE);
2778 if (Feld[x][y] == EL_DYNAMITE_ACTIVE ||
2779 Feld[x][y] == EL_SP_DISK_RED_ACTIVE)
2780 StopSound(SND_DYNAMITE_ACTIVE);
2782 StopSound(SND_DYNABOMB_ACTIVE);
2788 void DrawRelocatePlayer(struct PlayerInfo *player)
2790 boolean ffwd_delay = (tape.playing && tape.fast_forward);
2791 boolean no_delay = (tape.warp_forward);
2792 int frame_delay_value = (ffwd_delay ? FfwdFrameDelay : GameFrameDelay);
2793 int wait_delay_value = (no_delay ? 0 : frame_delay_value);
2794 int jx = player->jx;
2795 int jy = player->jy;
2797 if (level.instant_relocation)
2800 int offset = (setup.scroll_delay ? 3 : 0);
2802 if (!IN_VIS_FIELD(SCREENX(jx), SCREENY(jy)))
2804 scroll_x = (local_player->jx < SBX_Left + MIDPOSX ? SBX_Left :
2805 local_player->jx > SBX_Right + MIDPOSX ? SBX_Right :
2806 local_player->jx - MIDPOSX);
2808 scroll_y = (local_player->jy < SBY_Upper + MIDPOSY ? SBY_Upper :
2809 local_player->jy > SBY_Lower + MIDPOSY ? SBY_Lower :
2810 local_player->jy - MIDPOSY);
2814 if ((player->MovDir == MV_LEFT && scroll_x > jx - MIDPOSX + offset) ||
2815 (player->MovDir == MV_RIGHT && scroll_x < jx - MIDPOSX - offset))
2816 scroll_x = jx - MIDPOSX + (scroll_x < jx-MIDPOSX ? -offset : +offset);
2818 if ((player->MovDir == MV_UP && scroll_y > jy - MIDPOSY + offset) ||
2819 (player->MovDir == MV_DOWN && scroll_y < jy - MIDPOSY - offset))
2820 scroll_y = jy - MIDPOSY + (scroll_y < jy-MIDPOSY ? -offset : +offset);
2822 /* don't scroll over playfield boundaries */
2823 if (scroll_x < SBX_Left || scroll_x > SBX_Right)
2824 scroll_x = (scroll_x < SBX_Left ? SBX_Left : SBX_Right);
2826 /* don't scroll over playfield boundaries */
2827 if (scroll_y < SBY_Upper || scroll_y > SBY_Lower)
2828 scroll_y = (scroll_y < SBY_Upper ? SBY_Upper : SBY_Lower);
2831 scroll_x += (local_player->jx - old_jx);
2832 scroll_y += (local_player->jy - old_jy);
2834 /* don't scroll over playfield boundaries */
2835 if (scroll_x < SBX_Left || scroll_x > SBX_Right)
2836 scroll_x = (scroll_x < SBX_Left ? SBX_Left : SBX_Right);
2838 /* don't scroll over playfield boundaries */
2839 if (scroll_y < SBY_Upper || scroll_y > SBY_Lower)
2840 scroll_y = (scroll_y < SBY_Upper ? SBY_Upper : SBY_Lower);
2843 RedrawPlayfield(TRUE, 0,0,0,0);
2849 int offset = (setup.scroll_delay ? 3 : 0);
2851 int scroll_xx = -999, scroll_yy = -999;
2853 ScrollScreen(NULL, SCROLL_GO_ON); /* scroll last frame to full tile */
2855 while (scroll_xx != scroll_x || scroll_yy != scroll_y)
2858 int fx = FX, fy = FY;
2860 scroll_xx = (local_player->jx < SBX_Left + MIDPOSX ? SBX_Left :
2861 local_player->jx > SBX_Right + MIDPOSX ? SBX_Right :
2862 local_player->jx - MIDPOSX);
2864 scroll_yy = (local_player->jy < SBY_Upper + MIDPOSY ? SBY_Upper :
2865 local_player->jy > SBY_Lower + MIDPOSY ? SBY_Lower :
2866 local_player->jy - MIDPOSY);
2868 dx = (scroll_xx < scroll_x ? +1 : scroll_xx > scroll_x ? -1 : 0);
2869 dy = (scroll_yy < scroll_y ? +1 : scroll_yy > scroll_y ? -1 : 0);
2872 if (dx == 0 && dy == 0) /* no scrolling needed at all */
2875 if (scroll_xx == scroll_x && scroll_yy == scroll_y)
2882 fx += dx * TILEX / 2;
2883 fy += dy * TILEY / 2;
2885 ScrollLevel(dx, dy);
2888 /* scroll in two steps of half tile size to make things smoother */
2889 BlitBitmap(drawto_field, window, fx, fy, SXSIZE, SYSIZE, SX, SY);
2891 Delay(wait_delay_value);
2893 /* scroll second step to align at full tile size */
2895 Delay(wait_delay_value);
2898 int scroll_xx = -999, scroll_yy = -999;
2900 ScrollScreen(NULL, SCROLL_GO_ON); /* scroll last frame to full tile */
2902 while (scroll_xx != scroll_x || scroll_yy != scroll_y)
2905 int fx = FX, fy = FY;
2907 scroll_xx = (local_player->jx < SBX_Left + MIDPOSX ? SBX_Left :
2908 local_player->jx > SBX_Right + MIDPOSX ? SBX_Right :
2909 local_player->jx - MIDPOSX);
2911 scroll_yy = (local_player->jy < SBY_Upper + MIDPOSY ? SBY_Upper :
2912 local_player->jy > SBY_Lower + MIDPOSY ? SBY_Lower :
2913 local_player->jy - MIDPOSY);
2915 dx = (scroll_xx < scroll_x ? +1 : scroll_xx > scroll_x ? -1 : 0);
2916 dy = (scroll_yy < scroll_y ? +1 : scroll_yy > scroll_y ? -1 : 0);
2919 if (dx == 0 && dy == 0) /* no scrolling needed at all */
2922 if (scroll_xx == scroll_x && scroll_yy == scroll_y)
2929 fx += dx * TILEX / 2;
2930 fy += dy * TILEY / 2;
2932 ScrollLevel(dx, dy);
2935 /* scroll in two steps of half tile size to make things smoother */
2936 BlitBitmap(drawto_field, window, fx, fy, SXSIZE, SYSIZE, SX, SY);
2938 Delay(wait_delay_value);
2940 /* scroll second step to align at full tile size */
2942 Delay(wait_delay_value);
2948 Delay(wait_delay_value);
2952 void RelocatePlayer(int jx, int jy, int el_player_raw)
2955 int el_player = GET_VALID_PLAYER_ELEMENT(el_player_raw);
2957 int el_player = (el_player_raw == EL_SP_MURPHY ? EL_PLAYER_1 :el_player_raw);
2959 struct PlayerInfo *player = &stored_player[el_player - EL_PLAYER_1];
2960 boolean ffwd_delay = (tape.playing && tape.fast_forward);
2961 boolean no_delay = (tape.warp_forward);
2962 int frame_delay_value = (ffwd_delay ? FfwdFrameDelay : GameFrameDelay);
2963 int wait_delay_value = (no_delay ? 0 : frame_delay_value);
2964 int old_jx = player->jx;
2965 int old_jy = player->jy;
2966 int old_element = Feld[old_jx][old_jy];
2967 int element = Feld[jx][jy];
2968 boolean player_relocated = (old_jx != jx || old_jy != jy);
2970 int move_dir_horiz = (jx < old_jx ? MV_LEFT : jx > old_jx ? MV_RIGHT : 0);
2971 int move_dir_vert = (jy < old_jy ? MV_UP : jy > old_jy ? MV_DOWN : 0);
2973 int enter_side_horiz = MV_DIR_OPPOSITE(move_dir_horiz);
2974 int enter_side_vert = MV_DIR_OPPOSITE(move_dir_vert);
2975 int leave_side_horiz = move_dir_horiz;
2976 int leave_side_vert = move_dir_vert;
2978 static int trigger_sides[4][2] =
2980 /* enter side leave side */
2981 { CH_SIDE_RIGHT, CH_SIDE_LEFT }, /* moving left */
2982 { CH_SIDE_LEFT, CH_SIDE_RIGHT }, /* moving right */
2983 { CH_SIDE_BOTTOM, CH_SIDE_TOP }, /* moving up */
2984 { CH_SIDE_TOP, CH_SIDE_BOTTOM } /* moving down */
2986 int enter_side_horiz = trigger_sides[MV_DIR_BIT(move_dir_horiz)][0];
2987 int enter_side_vert = trigger_sides[MV_DIR_BIT(move_dir_vert)][0];
2988 int leave_side_horiz = trigger_sides[MV_DIR_BIT(move_dir_horiz)][1];
2989 int leave_side_vert = trigger_sides[MV_DIR_BIT(move_dir_vert)][1];
2991 int enter_side = enter_side_horiz | enter_side_vert;
2992 int leave_side = leave_side_horiz | leave_side_vert;
2994 if (player->GameOver) /* do not reanimate dead player */
2997 if (!player_relocated) /* no need to relocate the player */
3000 if (IS_PLAYER(jx, jy)) /* player already placed at new position */
3002 RemoveField(jx, jy); /* temporarily remove newly placed player */
3003 DrawLevelField(jx, jy);
3006 if (player->present)
3008 while (player->MovPos)
3010 ScrollPlayer(player, SCROLL_GO_ON);
3011 ScrollScreen(NULL, SCROLL_GO_ON);
3013 #if USE_NEW_MOVE_DELAY
3014 AdvanceFrameAndPlayerCounters(player->index_nr);
3022 Delay(wait_delay_value);
3025 DrawPlayer(player); /* needed here only to cleanup last field */
3026 DrawLevelField(player->jx, player->jy); /* remove player graphic */
3028 player->is_moving = FALSE;
3032 if (IS_CUSTOM_ELEMENT(old_element))
3033 CheckElementChangeByPlayer(old_jx, old_jy, old_element,
3035 player->index_bit, leave_side);
3037 CheckTriggeredElementChangeByPlayer(old_jx, old_jy, old_element,
3039 player->index_bit, leave_side);
3042 Feld[jx][jy] = el_player;
3043 InitPlayerField(jx, jy, el_player, TRUE);
3045 if (!ELEM_IS_PLAYER(element)) /* player may be set on walkable element */
3047 Feld[jx][jy] = element;
3048 InitField(jx, jy, FALSE);
3052 if (player == local_player) /* only visually relocate local player */
3053 DrawRelocatePlayer(player);
3057 TestIfHeroTouchesBadThing(jx, jy);
3058 TestIfPlayerTouchesCustomElement(jx, jy);
3062 printf("::: %d,%d: %d\n", jx, jy-1, Changed[jx][jy-1]);
3067 /* needed to allow change of walkable custom element by entering player */
3068 if (!(Changed[jx][jy] & CH_EVENT_BIT(CE_ENTERED_BY_PLAYER)))
3069 Changed[jx][jy] = 0; /* allow another change (but prevent loop) */
3071 /* needed to allow change of walkable custom element by entering player */
3072 Changed[jx][jy] = 0; /* allow another change */
3077 printf("::: player entering %d, %d from %s ...\n", jx, jy,
3078 enter_side == MV_LEFT ? "left" :
3079 enter_side == MV_RIGHT ? "right" :
3080 enter_side == MV_UP ? "top" :
3081 enter_side == MV_DOWN ? "bottom" : "oops! no idea!");
3085 if (IS_CUSTOM_ELEMENT(element))
3086 CheckElementChangeByPlayer(jx, jy, element, CE_ENTERED_BY_PLAYER,
3087 player->index_bit, enter_side);
3089 CheckTriggeredElementChangeByPlayer(jx, jy, element,
3090 CE_OTHER_GETS_ENTERED,
3091 player->index_bit, enter_side);
3095 void Explode(int ex, int ey, int phase, int mode)
3102 /* !!! eliminate this variable !!! */
3103 int delay = (game.emulation == EMU_SUPAPLEX ? 3 : 2);
3108 int last_phase = num_phase * delay;
3109 int half_phase = (num_phase / 2) * delay;
3110 int first_phase_after_start = EX_PHASE_START + 1;
3114 if (game.explosions_delayed)
3116 ExplodeField[ex][ey] = mode;
3120 if (phase == EX_PHASE_START) /* initialize 'Store[][]' field */
3122 int center_element = Feld[ex][ey];
3125 printf("::: start explosion %d,%d [%d]\n", ex, ey, FrameCounter);
3129 /* --- This is only really needed (and now handled) in "Impact()". --- */
3130 /* do not explode moving elements that left the explode field in time */
3131 if (game.engine_version >= VERSION_IDENT(2,2,0,7) &&
3132 center_element == EL_EMPTY &&
3133 (mode == EX_TYPE_NORMAL || mode == EX_TYPE_CENTER))
3138 if (mode == EX_TYPE_NORMAL ||
3139 mode == EX_TYPE_CENTER ||
3140 mode == EX_TYPE_CROSS)
3141 PlayLevelSoundAction(ex, ey, ACTION_EXPLODING);
3143 if (mode == EX_TYPE_NORMAL || mode == EX_TYPE_CENTER)
3144 PlayLevelSoundAction(ex, ey, ACTION_EXPLODING);
3147 /* remove things displayed in background while burning dynamite */
3148 if (Back[ex][ey] != EL_EMPTY && !IS_INDESTRUCTIBLE(Back[ex][ey]))
3151 if (IS_MOVING(ex, ey) || IS_BLOCKED(ex, ey))
3153 /* put moving element to center field (and let it explode there) */
3154 center_element = MovingOrBlocked2Element(ex, ey);
3155 RemoveMovingField(ex, ey);
3156 Feld[ex][ey] = center_element;
3162 last_phase = element_info[center_element].explosion_delay + 1;
3164 last_phase = element_info[center_element].explosion_delay;
3168 printf("::: %d -> %d\n", center_element, last_phase);
3172 for (y = ey - 1; y <= ey + 1; y++) for (x = ex - 1; x <= ex + 1; x++)
3174 int xx = x - ex + 1;
3175 int yy = y - ey + 1;
3180 if (!IN_LEV_FIELD(x, y) ||
3181 (mode & EX_TYPE_SINGLE_TILE && (x != ex || y != ey)) ||
3182 (mode == EX_TYPE_CROSS && (x != ex && y != ey)))
3185 if (!IN_LEV_FIELD(x, y) ||
3186 (mode != EX_TYPE_NORMAL && (x != ex || y != ey)))
3190 if (!IN_LEV_FIELD(x, y) ||
3191 ((mode != EX_TYPE_NORMAL ||
3192 center_element == EL_AMOEBA_TO_DIAMOND) &&
3193 (x != ex || y != ey)))
3197 element = Feld[x][y];
3199 if (IS_MOVING(x, y) || IS_BLOCKED(x, y))
3201 element = MovingOrBlocked2Element(x, y);
3203 if (!IS_EXPLOSION_PROOF(element))
3204 RemoveMovingField(x, y);
3210 if (IS_EXPLOSION_PROOF(element))
3213 /* indestructible elements can only explode in center (but not flames) */
3215 if ((IS_EXPLOSION_PROOF(element) && (x != ex || y != ey ||
3216 mode == EX_TYPE_BORDER)) ||
3217 element == EL_FLAMES)
3220 if ((IS_EXPLOSION_PROOF(element) && (x != ex || y != ey)) ||
3221 element == EL_FLAMES)
3227 if ((IS_INDESTRUCTIBLE(element) &&
3228 (game.engine_version < VERSION_IDENT(2,2,0,0) ||
3229 (!IS_WALKABLE_OVER(element) && !IS_WALKABLE_UNDER(element)))) ||
3230 element == EL_FLAMES)
3235 if (IS_PLAYER(x, y) && SHIELD_ON(PLAYERINFO(x, y)) &&
3236 (game.engine_version < VERSION_IDENT(3,1,0,0) ||
3237 (x == ex && y == ey && mode != EX_TYPE_BORDER)))
3239 if (IS_PLAYER(x, y) && SHIELD_ON(PLAYERINFO(x, y)))
3242 if (IS_ACTIVE_BOMB(element))
3244 /* re-activate things under the bomb like gate or penguin */
3246 Feld[x][y] = (Back[x][y] ? Back[x][y] : EL_EMPTY);
3249 Feld[x][y] = (Store[x][y] ? Store[x][y] : EL_EMPTY);
3254 printf("::: %d,%d: %d %s [%d, %d]\n", x, y, Feld[x][y],
3255 element_info[Feld[x][y]].token_name,
3256 Store[x][y], Store2[x][y]);
3263 /* save walkable background elements while explosion on same tile */
3265 if (IS_INDESTRUCTIBLE(element))
3266 Back[x][y] = element;
3270 if (IS_WALKABLE(element) && IS_INDESTRUCTIBLE(element) &&
3271 (x != ex || y != ey || mode == EX_TYPE_BORDER))
3272 Back[x][y] = element;
3274 if (IS_WALKABLE(element) && IS_INDESTRUCTIBLE(element) &&
3275 (x != ex || y != ey))
3276 Back[x][y] = element;
3279 if (IS_WALKABLE(element) && IS_INDESTRUCTIBLE(element))
3280 Back[x][y] = element;
3284 /* ignite explodable elements reached by other explosion */
3285 if (element == EL_EXPLOSION)
3286 element = Store2[x][y];
3289 if (AmoebaNr[x][y] &&
3290 (element == EL_AMOEBA_FULL ||
3291 element == EL_BD_AMOEBA ||
3292 element == EL_AMOEBA_GROWING))
3294 AmoebaCnt[AmoebaNr[x][y]]--;
3295 AmoebaCnt2[AmoebaNr[x][y]]--;
3301 if (IS_PLAYER(ex, ey) && !PLAYER_EXPLOSION_PROTECTED(ex, ey))
3303 switch(StorePlayer[ex][ey])
3306 Store[x][y] = EL_PLAYER_IS_EXPLODING_2;
3309 Store[x][y] = EL_PLAYER_IS_EXPLODING_3;
3312 Store[x][y] = EL_PLAYER_IS_EXPLODING_4;
3316 Store[x][y] = EL_PLAYER_IS_EXPLODING_1;
3321 if (PLAYERINFO(ex, ey)->use_murphy_graphic)
3322 Store[x][y] = EL_EMPTY;
3324 if (game.emulation == EMU_SUPAPLEX)
3325 Store[x][y] = EL_EMPTY;
3328 else if (center_element == EL_MOLE)
3329 Store[x][y] = EL_EMERALD_RED;
3330 else if (center_element == EL_PENGUIN)
3331 Store[x][y] = EL_EMERALD_PURPLE;
3332 else if (center_element == EL_BUG)
3333 Store[x][y] = ((x == ex && y == ey) ? EL_DIAMOND : EL_EMERALD);
3334 else if (center_element == EL_BD_BUTTERFLY)
3335 Store[x][y] = EL_BD_DIAMOND;
3336 else if (center_element == EL_SP_ELECTRON)
3337 Store[x][y] = EL_SP_INFOTRON;
3338 else if (center_element == EL_AMOEBA_TO_DIAMOND)
3339 Store[x][y] = level.amoeba_content;
3340 else if (center_element == EL_YAMYAM)
3341 Store[x][y] = level.yamyam_content[game.yamyam_content_nr][xx][yy];
3342 else if (IS_CUSTOM_ELEMENT(center_element) &&
3343 element_info[center_element].content[xx][yy] != EL_EMPTY)
3344 Store[x][y] = element_info[center_element].content[xx][yy];
3345 else if (element == EL_WALL_EMERALD)
3346 Store[x][y] = EL_EMERALD;
3347 else if (element == EL_WALL_DIAMOND)
3348 Store[x][y] = EL_DIAMOND;
3349 else if (element == EL_WALL_BD_DIAMOND)
3350 Store[x][y] = EL_BD_DIAMOND;
3351 else if (element == EL_WALL_EMERALD_YELLOW)
3352 Store[x][y] = EL_EMERALD_YELLOW;
3353 else if (element == EL_WALL_EMERALD_RED)
3354 Store[x][y] = EL_EMERALD_RED;
3355 else if (element == EL_WALL_EMERALD_PURPLE)
3356 Store[x][y] = EL_EMERALD_PURPLE;
3357 else if (element == EL_WALL_PEARL)
3358 Store[x][y] = EL_PEARL;
3359 else if (element == EL_WALL_CRYSTAL)
3360 Store[x][y] = EL_CRYSTAL;
3361 else if (IS_CUSTOM_ELEMENT(element) && !CAN_EXPLODE(element))
3362 Store[x][y] = element_info[element].content[1][1];
3364 Store[x][y] = EL_EMPTY;
3366 if (x != ex || y != ey || mode == EX_TYPE_BORDER ||
3367 center_element == EL_AMOEBA_TO_DIAMOND)
3368 Store2[x][y] = element;
3371 printf("::: %d,%d: %d %s\n", x, y, Store2[x][y],
3372 element_info[Store2[x][y]].token_name);
3376 if (AmoebaNr[x][y] &&
3377 (element == EL_AMOEBA_FULL ||
3378 element == EL_BD_AMOEBA ||
3379 element == EL_AMOEBA_GROWING))
3381 AmoebaCnt[AmoebaNr[x][y]]--;
3382 AmoebaCnt2[AmoebaNr[x][y]]--;
3388 MovDir[x][y] = MovPos[x][y] = 0;
3389 GfxDir[x][y] = MovDir[x][y];
3394 Feld[x][y] = EL_EXPLOSION;
3396 GfxElement[x][y] = center_element;
3398 GfxElement[x][y] = EL_UNDEFINED;
3401 ExplodePhase[x][y] = 1;
3403 ExplodeDelay[x][y] = last_phase;
3408 GfxFrame[x][y] = 0; /* animation does not start until next frame */
3410 GfxFrame[x][y] = -1; /* animation does not start until next frame */
3417 if (center_element == EL_YAMYAM)
3418 game.yamyam_content_nr =
3419 (game.yamyam_content_nr + 1) % level.num_yamyam_contents;
3422 printf("::: %d,%d: %d %s [%d]\n", ex + 1, ey, Feld[ex + 1][ey],
3423 element_info[Feld[ex + 1][ey]].token_name, Store2[ex + 1][ey]);
3437 GfxFrame[x][y] = 0; /* restart explosion animation */
3441 printf(":X: phase == %d [%d]\n", phase, GfxFrame[x][y]);
3445 last_phase = ExplodeDelay[x][y];
3448 ExplodePhase[x][y] = (phase < last_phase ? phase + 1 : 0);
3452 /* activate this even in non-DEBUG version until cause for crash in
3453 getGraphicAnimationFrame() (see below) is found and eliminated */
3457 if (GfxElement[x][y] == EL_UNDEFINED)
3460 printf("Explode(): x = %d, y = %d: GfxElement == EL_UNDEFINED\n", x, y);
3461 printf("Explode(): This should never happen!\n");
3464 GfxElement[x][y] = EL_EMPTY;
3470 border_element = Store2[x][y];
3472 if (IS_PLAYER(x, y) && !PLAYER_EXPLOSION_PROTECTED(x, y))
3473 border_element = StorePlayer[x][y];
3475 if (IS_PLAYER(x, y))
3476 border_element = StorePlayer[x][y];
3480 printf("::: %d,%d: %d %s [%d]\n", x, y, border_element,
3481 element_info[border_element].token_name, Store2[x][y]);
3485 printf("::: phase == %d\n", phase);
3488 if (phase == element_info[border_element].ignition_delay ||
3489 phase == last_phase)
3491 boolean border_explosion = FALSE;
3495 if (IS_PLAYER(x, y) && PLAYERINFO(x, y)->present &&
3496 !PLAYER_EXPLOSION_PROTECTED(x, y))
3498 if (IS_PLAYER(x, y) && PLAYERINFO(x, y)->present)
3501 if (IS_PLAYER(x, y))
3504 KillHeroUnlessExplosionProtected(x, y);
3505 border_explosion = TRUE;
3508 if (phase == last_phase)
3509 printf("::: IS_PLAYER\n");
3512 else if (CAN_EXPLODE_BY_EXPLOSION(border_element))
3515 printf("::: %d,%d: %d %s\n", x, y, border_element,
3516 element_info[border_element].token_name);
3519 Feld[x][y] = Store2[x][y];
3522 border_explosion = TRUE;
3525 if (phase == last_phase)
3526 printf("::: CAN_EXPLODE_BY_EXPLOSION\n");
3529 else if (border_element == EL_AMOEBA_TO_DIAMOND)
3531 AmoebeUmwandeln(x, y);
3533 border_explosion = TRUE;
3536 if (phase == last_phase)
3537 printf("::: EL_AMOEBA_TO_DIAMOND [%d, %d] [%d]\n",
3538 element_info[border_element].explosion_delay,
3539 element_info[border_element].ignition_delay,
3545 /* if an element just explodes due to another explosion (chain-reaction),
3546 do not immediately end the new explosion when it was the last frame of
3547 the explosion (as it would be done in the following "if"-statement!) */
3548 if (border_explosion && phase == last_phase)
3555 if (phase == first_phase_after_start)
3557 int element = Store2[x][y];
3559 if (element == EL_BLACK_ORB)
3561 Feld[x][y] = Store2[x][y];
3566 else if (phase == half_phase)
3568 int element = Store2[x][y];
3570 if (IS_PLAYER(x, y))
3571 KillHeroUnlessExplosionProtected(x, y);
3572 else if (CAN_EXPLODE_BY_EXPLOSION(element))
3574 Feld[x][y] = Store2[x][y];
3578 else if (element == EL_AMOEBA_TO_DIAMOND)
3579 AmoebeUmwandeln(x, y);
3583 if (phase == last_phase)
3588 printf("::: done: phase == %d\n", phase);
3592 printf("::: explosion %d,%d done [%d]\n", x, y, FrameCounter);
3595 element = Feld[x][y] = Store[x][y];
3596 Store[x][y] = Store2[x][y] = 0;
3597 GfxElement[x][y] = EL_UNDEFINED;
3599 /* player can escape from explosions and might therefore be still alive */
3600 if (element >= EL_PLAYER_IS_EXPLODING_1 &&
3601 element <= EL_PLAYER_IS_EXPLODING_4)
3602 Feld[x][y] = (stored_player[element - EL_PLAYER_IS_EXPLODING_1].active ?
3604 element == EL_PLAYER_IS_EXPLODING_1 ? EL_EMERALD_YELLOW :
3605 element == EL_PLAYER_IS_EXPLODING_2 ? EL_EMERALD_RED :
3606 element == EL_PLAYER_IS_EXPLODING_3 ? EL_EMERALD :
3609 /* restore probably existing indestructible background element */
3610 if (Back[x][y] && IS_INDESTRUCTIBLE(Back[x][y]))
3611 element = Feld[x][y] = Back[x][y];
3614 MovDir[x][y] = MovPos[x][y] = MovDelay[x][y] = 0;
3615 GfxDir[x][y] = MV_NO_MOVING;
3616 ChangeDelay[x][y] = 0;
3617 ChangePage[x][y] = -1;
3620 InitField_WithBug2(x, y, FALSE);
3622 InitField(x, y, FALSE);
3624 /* !!! not needed !!! */
3626 if (game.engine_version < VERSION_IDENT(3,1,0,0) &&
3627 CAN_MOVE(Feld[x][y]) && Feld[x][y] != EL_MOLE)
3630 if (CAN_MOVE(element))
3635 DrawLevelField(x, y);
3637 TestIfElementTouchesCustomElement(x, y);
3639 if (GFX_CRUMBLED(element))
3640 DrawLevelFieldCrumbledSandNeighbours(x, y);
3642 if (IS_PLAYER(x, y) && !PLAYERINFO(x, y)->present)
3643 StorePlayer[x][y] = 0;
3645 if (ELEM_IS_PLAYER(element))
3646 RelocatePlayer(x, y, element);
3649 else if (IN_SCR_FIELD(SCREENX(x), SCREENY(y)))
3651 else if (phase >= delay && IN_SCR_FIELD(SCREENX(x), SCREENY(y)))
3655 int graphic = el_act2img(GfxElement[x][y], ACTION_EXPLODING);
3657 int stored = Store[x][y];
3658 int graphic = (game.emulation != EMU_SUPAPLEX ? IMG_EXPLOSION :
3659 stored == EL_SP_INFOTRON ? IMG_SP_EXPLOSION_INFOTRON :
3663 int frame = getGraphicAnimationFrame(graphic, GfxFrame[x][y]);
3665 int frame = getGraphicAnimationFrame(graphic, phase - delay);
3669 printf("::: phase == %d [%d]\n", phase, GfxFrame[x][y]);
3673 printf("::: %d / %d [%d - %d]\n",
3674 GfxFrame[x][y], phase - delay, phase, delay);
3678 printf("::: %d ['%s'] -> %d\n", GfxElement[x][y],
3679 element_info[GfxElement[x][y]].token_name,
3684 DrawLevelFieldCrumbledSand(x, y);
3686 if (IS_WALKABLE_OVER(Back[x][y]) && Back[x][y] != EL_EMPTY)
3688 DrawLevelElement(x, y, Back[x][y]);
3689 DrawGraphicThruMask(SCREENX(x), SCREENY(y), graphic, frame);
3691 else if (IS_WALKABLE_UNDER(Back[x][y]))
3693 DrawGraphic(SCREENX(x), SCREENY(y), graphic, frame);
3694 DrawLevelElementThruMask(x, y, Back[x][y]);
3696 else if (!IS_WALKABLE_INSIDE(Back[x][y]))
3697 DrawGraphic(SCREENX(x), SCREENY(y), graphic, frame);
3701 void DynaExplode(int ex, int ey)
3704 int dynabomb_element = Feld[ex][ey];
3705 int dynabomb_size = 1;
3706 boolean dynabomb_xl = FALSE;
3707 struct PlayerInfo *player;
3708 static int xy[4][2] =
3716 if (IS_ACTIVE_BOMB(dynabomb_element))
3718 player = &stored_player[dynabomb_element - EL_DYNABOMB_PLAYER_1_ACTIVE];
3719 dynabomb_size = player->dynabomb_size;
3720 dynabomb_xl = player->dynabomb_xl;
3721 player->dynabombs_left++;
3724 Explode(ex, ey, EX_PHASE_START, EX_TYPE_CENTER);
3726 for (i = 0; i < NUM_DIRECTIONS; i++)
3728 for (j = 1; j <= dynabomb_size; j++)
3730 int x = ex + j * xy[i][0];
3731 int y = ey + j * xy[i][1];
3734 if (!IN_LEV_FIELD(x, y) || IS_INDESTRUCTIBLE(Feld[x][y]))
3737 element = Feld[x][y];
3739 /* do not restart explosions of fields with active bombs */
3740 if (element == EL_EXPLOSION && IS_ACTIVE_BOMB(Store2[x][y]))
3743 Explode(x, y, EX_PHASE_START, EX_TYPE_BORDER);
3747 if (element != EL_EMPTY && element != EL_EXPLOSION &&
3748 !IS_DIGGABLE(element) && !dynabomb_xl)
3751 if (element != EL_EMPTY && element != EL_EXPLOSION &&
3752 !CAN_GROW_INTO(element) && !dynabomb_xl)
3756 /* !!! extend EL_SAND to anything diggable (but maybe not SP_BASE) !!! */
3757 if (element != EL_EMPTY && element != EL_EXPLOSION &&
3758 element != EL_SAND && !dynabomb_xl)
3765 void Bang(int x, int y)
3768 int element = MovingOrBlocked2Element(x, y);
3770 int element = Feld[x][y];
3774 if (IS_PLAYER(x, y) && !PLAYER_EXPLOSION_PROTECTED(x, y))
3776 if (IS_PLAYER(x, y))
3779 struct PlayerInfo *player = PLAYERINFO(x, y);
3781 element = Feld[x][y] = (player->use_murphy_graphic ? EL_SP_MURPHY :
3782 player->element_nr);
3787 PlayLevelSoundAction(x, y, ACTION_EXPLODING);
3789 if (game.emulation == EMU_SUPAPLEX)
3790 PlayLevelSound(x, y, SND_SP_ELEMENT_EXPLODING);
3792 PlayLevelSound(x, y, SND_ELEMENT_EXPLODING);
3797 if (IS_PLAYER(x, y)) /* remove objects that might cause smaller explosion */
3805 case EL_BD_BUTTERFLY:
3808 case EL_DARK_YAMYAM:
3812 RaiseScoreElement(element);
3813 Explode(x, y, EX_PHASE_START, EX_TYPE_NORMAL);
3815 case EL_DYNABOMB_PLAYER_1_ACTIVE:
3816 case EL_DYNABOMB_PLAYER_2_ACTIVE:
3817 case EL_DYNABOMB_PLAYER_3_ACTIVE:
3818 case EL_DYNABOMB_PLAYER_4_ACTIVE:
3819 case EL_DYNABOMB_INCREASE_NUMBER:
3820 case EL_DYNABOMB_INCREASE_SIZE:
3821 case EL_DYNABOMB_INCREASE_POWER:
3826 case EL_LAMP_ACTIVE:
3828 case EL_AMOEBA_TO_DIAMOND:
3830 if (IS_PLAYER(x, y))
3831 Explode(x, y, EX_PHASE_START, EX_TYPE_NORMAL);
3833 Explode(x, y, EX_PHASE_START, EX_TYPE_CENTER);
3837 if (element_info[element].explosion_type == EXPLODES_CROSS)
3839 if (CAN_EXPLODE_CROSS(element))
3842 Explode(x, y, EX_PHASE_START, EX_TYPE_CROSS);
3847 else if (element_info[element].explosion_type == EXPLODES_1X1)
3849 else if (CAN_EXPLODE_1X1(element))
3851 Explode(x, y, EX_PHASE_START, EX_TYPE_CENTER);
3853 Explode(x, y, EX_PHASE_START, EX_TYPE_NORMAL);
3857 CheckTriggeredElementChange(x, y, element, CE_OTHER_IS_EXPLODING);
3860 void SplashAcid(int x, int y)
3863 if (IN_LEV_FIELD(x - 1, y - 1) && IS_FREE(x - 1, y - 1) &&
3864 (!IN_LEV_FIELD(x - 1, y - 2) ||
3865 !CAN_FALL(MovingOrBlocked2Element(x - 1, y - 2))))
3866 Feld[x - 1][y - 1] = EL_ACID_SPLASH_LEFT;
3868 if (IN_LEV_FIELD(x + 1, y - 1) && IS_FREE(x + 1, y - 1) &&
3869 (!IN_LEV_FIELD(x + 1, y - 2) ||
3870 !CAN_FALL(MovingOrBlocked2Element(x + 1, y - 2))))
3871 Feld[x + 1][y - 1] = EL_ACID_SPLASH_RIGHT;
3873 PlayLevelSound(x, y, SND_ACID_SPLASHING);
3875 /* input: position of element entering acid (obsolete) */
3877 int element = Feld[x][y];
3879 if (!IN_LEV_FIELD(x, y + 1) || Feld[x][y + 1] != EL_ACID)
3882 if (element != EL_ACID_SPLASH_LEFT &&
3883 element != EL_ACID_SPLASH_RIGHT)
3885 PlayLevelSound(x, y, SND_ACID_SPLASHING);
3887 if (IN_LEV_FIELD(x - 1, y) && IS_FREE(x - 1, y) &&
3888 (!IN_LEV_FIELD(x - 1, y - 1) ||
3889 !CAN_FALL(MovingOrBlocked2Element(x - 1, y - 1))))
3890 Feld[x - 1][y] = EL_ACID_SPLASH_LEFT;
3892 if (IN_LEV_FIELD(x + 1, y) && IS_FREE(x + 1, y) &&
3893 (!IN_LEV_FIELD(x + 1, y - 1) ||
3894 !CAN_FALL(MovingOrBlocked2Element(x + 1, y - 1))))
3895 Feld[x + 1][y] = EL_ACID_SPLASH_RIGHT;
3900 static void InitBeltMovement()
3902 static int belt_base_element[4] =
3904 EL_CONVEYOR_BELT_1_LEFT,
3905 EL_CONVEYOR_BELT_2_LEFT,
3906 EL_CONVEYOR_BELT_3_LEFT,
3907 EL_CONVEYOR_BELT_4_LEFT
3909 static int belt_base_active_element[4] =
3911 EL_CONVEYOR_BELT_1_LEFT_ACTIVE,
3912 EL_CONVEYOR_BELT_2_LEFT_ACTIVE,
3913 EL_CONVEYOR_BELT_3_LEFT_ACTIVE,
3914 EL_CONVEYOR_BELT_4_LEFT_ACTIVE
3919 /* set frame order for belt animation graphic according to belt direction */
3920 for (i = 0; i < NUM_BELTS; i++)
3924 for (j = 0; j < NUM_BELT_PARTS; j++)
3926 int element = belt_base_active_element[belt_nr] + j;
3927 int graphic = el2img(element);
3929 if (game.belt_dir[i] == MV_LEFT)
3930 graphic_info[graphic].anim_mode &= ~ANIM_REVERSE;
3932 graphic_info[graphic].anim_mode |= ANIM_REVERSE;
3936 for (y = 0; y < lev_fieldy; y++)
3938 for (x = 0; x < lev_fieldx; x++)
3940 int element = Feld[x][y];
3942 for (i = 0; i < NUM_BELTS; i++)
3944 if (IS_BELT(element) && game.belt_dir[i] != MV_NO_MOVING)
3946 int e_belt_nr = getBeltNrFromBeltElement(element);
3949 if (e_belt_nr == belt_nr)
3951 int belt_part = Feld[x][y] - belt_base_element[belt_nr];
3953 Feld[x][y] = belt_base_active_element[belt_nr] + belt_part;
3961 static void ToggleBeltSwitch(int x, int y)
3963 static int belt_base_element[4] =
3965 EL_CONVEYOR_BELT_1_LEFT,
3966 EL_CONVEYOR_BELT_2_LEFT,
3967 EL_CONVEYOR_BELT_3_LEFT,
3968 EL_CONVEYOR_BELT_4_LEFT
3970 static int belt_base_active_element[4] =
3972 EL_CONVEYOR_BELT_1_LEFT_ACTIVE,
3973 EL_CONVEYOR_BELT_2_LEFT_ACTIVE,
3974 EL_CONVEYOR_BELT_3_LEFT_ACTIVE,
3975 EL_CONVEYOR_BELT_4_LEFT_ACTIVE
3977 static int belt_base_switch_element[4] =
3979 EL_CONVEYOR_BELT_1_SWITCH_LEFT,
3980 EL_CONVEYOR_BELT_2_SWITCH_LEFT,
3981 EL_CONVEYOR_BELT_3_SWITCH_LEFT,
3982 EL_CONVEYOR_BELT_4_SWITCH_LEFT
3984 static int belt_move_dir[4] =
3992 int element = Feld[x][y];
3993 int belt_nr = getBeltNrFromBeltSwitchElement(element);
3994 int belt_dir_nr = (game.belt_dir_nr[belt_nr] + 1) % 4;
3995 int belt_dir = belt_move_dir[belt_dir_nr];
3998 if (!IS_BELT_SWITCH(element))
4001 game.belt_dir_nr[belt_nr] = belt_dir_nr;
4002 game.belt_dir[belt_nr] = belt_dir;
4004 if (belt_dir_nr == 3)
4007 /* set frame order for belt animation graphic according to belt direction */
4008 for (i = 0; i < NUM_BELT_PARTS; i++)
4010 int element = belt_base_active_element[belt_nr] + i;
4011 int graphic = el2img(element);
4013 if (belt_dir == MV_LEFT)
4014 graphic_info[graphic].anim_mode &= ~ANIM_REVERSE;
4016 graphic_info[graphic].anim_mode |= ANIM_REVERSE;
4019 for (yy = 0; yy < lev_fieldy; yy++)
4021 for (xx = 0; xx < lev_fieldx; xx++)
4023 int element = Feld[xx][yy];
4025 if (IS_BELT_SWITCH(element))
4027 int e_belt_nr = getBeltNrFromBeltSwitchElement(element);
4029 if (e_belt_nr == belt_nr)
4031 Feld[xx][yy] = belt_base_switch_element[belt_nr] + belt_dir_nr;
4032 DrawLevelField(xx, yy);
4035 else if (IS_BELT(element) && belt_dir != MV_NO_MOVING)
4037 int e_belt_nr = getBeltNrFromBeltElement(element);
4039 if (e_belt_nr == belt_nr)
4041 int belt_part = Feld[xx][yy] - belt_base_element[belt_nr];
4043 Feld[xx][yy] = belt_base_active_element[belt_nr] + belt_part;
4044 DrawLevelField(xx, yy);
4047 else if (IS_BELT_ACTIVE(element) && belt_dir == MV_NO_MOVING)
4049 int e_belt_nr = getBeltNrFromBeltActiveElement(element);
4051 if (e_belt_nr == belt_nr)
4053 int belt_part = Feld[xx][yy] - belt_base_active_element[belt_nr];
4055 Feld[xx][yy] = belt_base_element[belt_nr] + belt_part;
4056 DrawLevelField(xx, yy);
4063 static void ToggleSwitchgateSwitch(int x, int y)
4067 game.switchgate_pos = !game.switchgate_pos;
4069 for (yy = 0; yy < lev_fieldy; yy++)
4071 for (xx = 0; xx < lev_fieldx; xx++)
4073 int element = Feld[xx][yy];
4075 if (element == EL_SWITCHGATE_SWITCH_UP ||
4076 element == EL_SWITCHGATE_SWITCH_DOWN)
4078 Feld[xx][yy] = EL_SWITCHGATE_SWITCH_UP + game.switchgate_pos;
4079 DrawLevelField(xx, yy);
4081 else if (element == EL_SWITCHGATE_OPEN ||
4082 element == EL_SWITCHGATE_OPENING)
4084 Feld[xx][yy] = EL_SWITCHGATE_CLOSING;
4086 PlayLevelSoundAction(xx, yy, ACTION_CLOSING);
4088 PlayLevelSound(xx, yy, SND_SWITCHGATE_CLOSING);
4091 else if (element == EL_SWITCHGATE_CLOSED ||
4092 element == EL_SWITCHGATE_CLOSING)
4094 Feld[xx][yy] = EL_SWITCHGATE_OPENING;
4096 PlayLevelSoundAction(xx, yy, ACTION_OPENING);
4098 PlayLevelSound(xx, yy, SND_SWITCHGATE_OPENING);
4105 static int getInvisibleActiveFromInvisibleElement(int element)
4107 return (element == EL_INVISIBLE_STEELWALL ? EL_INVISIBLE_STEELWALL_ACTIVE :
4108 element == EL_INVISIBLE_WALL ? EL_INVISIBLE_WALL_ACTIVE :
4109 element == EL_INVISIBLE_SAND ? EL_INVISIBLE_SAND_ACTIVE :
4113 static int getInvisibleFromInvisibleActiveElement(int element)
4115 return (element == EL_INVISIBLE_STEELWALL_ACTIVE ? EL_INVISIBLE_STEELWALL :
4116 element == EL_INVISIBLE_WALL_ACTIVE ? EL_INVISIBLE_WALL :
4117 element == EL_INVISIBLE_SAND_ACTIVE ? EL_INVISIBLE_SAND :
4121 static void RedrawAllLightSwitchesAndInvisibleElements()
4125 for (y = 0; y < lev_fieldy; y++)
4127 for (x = 0; x < lev_fieldx; x++)
4129 int element = Feld[x][y];
4131 if (element == EL_LIGHT_SWITCH &&
4132 game.light_time_left > 0)
4134 Feld[x][y] = EL_LIGHT_SWITCH_ACTIVE;
4135 DrawLevelField(x, y);
4137 else if (element == EL_LIGHT_SWITCH_ACTIVE &&
4138 game.light_time_left == 0)
4140 Feld[x][y] = EL_LIGHT_SWITCH;
4141 DrawLevelField(x, y);
4143 else if (element == EL_INVISIBLE_STEELWALL ||
4144 element == EL_INVISIBLE_WALL ||
4145 element == EL_INVISIBLE_SAND)
4147 if (game.light_time_left > 0)
4148 Feld[x][y] = getInvisibleActiveFromInvisibleElement(element);
4150 DrawLevelField(x, y);
4152 else if (element == EL_INVISIBLE_STEELWALL_ACTIVE ||
4153 element == EL_INVISIBLE_WALL_ACTIVE ||
4154 element == EL_INVISIBLE_SAND_ACTIVE)
4156 if (game.light_time_left == 0)
4157 Feld[x][y] = getInvisibleFromInvisibleActiveElement(element);
4159 DrawLevelField(x, y);
4165 static void ToggleLightSwitch(int x, int y)
4167 int element = Feld[x][y];
4169 game.light_time_left =
4170 (element == EL_LIGHT_SWITCH ?
4171 level.time_light * FRAMES_PER_SECOND : 0);
4173 RedrawAllLightSwitchesAndInvisibleElements();
4176 static void ActivateTimegateSwitch(int x, int y)
4180 game.timegate_time_left = level.time_timegate * FRAMES_PER_SECOND;
4182 for (yy = 0; yy < lev_fieldy; yy++)
4184 for (xx = 0; xx < lev_fieldx; xx++)
4186 int element = Feld[xx][yy];
4188 if (element == EL_TIMEGATE_CLOSED ||
4189 element == EL_TIMEGATE_CLOSING)
4191 Feld[xx][yy] = EL_TIMEGATE_OPENING;
4192 PlayLevelSound(xx, yy, SND_TIMEGATE_OPENING);
4196 else if (element == EL_TIMEGATE_SWITCH_ACTIVE)
4198 Feld[xx][yy] = EL_TIMEGATE_SWITCH;
4199 DrawLevelField(xx, yy);
4206 Feld[x][y] = EL_TIMEGATE_SWITCH_ACTIVE;
4209 inline static int getElementMoveStepsize(int x, int y)
4211 int element = Feld[x][y];
4212 int direction = MovDir[x][y];
4213 int dx = (direction == MV_LEFT ? -1 : direction == MV_RIGHT ? +1 : 0);
4214 int dy = (direction == MV_UP ? -1 : direction == MV_DOWN ? +1 : 0);
4215 int horiz_move = (dx != 0);
4216 int sign = (horiz_move ? dx : dy);
4217 int step = sign * element_info[element].move_stepsize;
4219 /* special values for move stepsize for spring and things on conveyor belt */
4223 if (element == EL_SPRING)
4224 step = sign * MOVE_STEPSIZE_NORMAL * 2;
4225 else if (CAN_FALL(element) && !CAN_MOVE(element) &&
4226 y < lev_fieldy - 1 && IS_BELT_ACTIVE(Feld[x][y + 1]))
4227 step = sign * MOVE_STEPSIZE_NORMAL / 2;
4229 if (CAN_FALL(element) &&
4230 y < lev_fieldy - 1 && IS_BELT_ACTIVE(Feld[x][y + 1]))
4231 step = sign * MOVE_STEPSIZE_NORMAL / 2;
4232 else if (element == EL_SPRING)
4233 step = sign * MOVE_STEPSIZE_NORMAL * 2;
4240 void Impact(int x, int y)
4242 boolean lastline = (y == lev_fieldy-1);
4243 boolean object_hit = FALSE;
4244 boolean impact = (lastline || object_hit);
4245 int element = Feld[x][y];
4246 int smashed = EL_STEELWALL;
4248 if (!lastline) /* check if element below was hit */
4250 if (Feld[x][y + 1] == EL_PLAYER_IS_LEAVING)
4253 object_hit = (!IS_FREE(x, y + 1) && (!IS_MOVING(x, y + 1) ||
4254 MovDir[x][y + 1] != MV_DOWN ||
4255 MovPos[x][y + 1] <= TILEY / 2));
4258 object_hit = !IS_FREE(x, y + 1);
4261 /* do not smash moving elements that left the smashed field in time */
4262 if (game.engine_version >= VERSION_IDENT(2,2,0,7) && IS_MOVING(x, y + 1) &&
4263 ABS(MovPos[x][y + 1] + getElementMoveStepsize(x, y + 1)) >= TILEX)
4267 smashed = MovingOrBlocked2Element(x, y + 1);
4269 impact = (lastline || object_hit);
4272 if (!lastline && smashed == EL_ACID) /* element falls into acid */
4274 SplashAcid(x, y + 1);
4278 /* !!! not sufficient for all cases -- see EL_PEARL below !!! */
4279 /* only reset graphic animation if graphic really changes after impact */
4281 el_act_dir2img(element, GfxAction[x][y], MV_DOWN) != el2img(element))
4283 ResetGfxAnimation(x, y);
4284 DrawLevelField(x, y);
4287 if (impact && CAN_EXPLODE_IMPACT(element))
4292 else if (impact && element == EL_PEARL)
4294 ResetGfxAnimation(x, y);
4296 Feld[x][y] = EL_PEARL_BREAKING;
4297 PlayLevelSound(x, y, SND_PEARL_BREAKING);
4300 else if (impact && CheckElementChange(x, y, element, smashed, CE_IMPACT))
4302 PlayLevelSoundElementAction(x, y, element, ACTION_IMPACT);
4307 if (impact && element == EL_AMOEBA_DROP)
4309 if (object_hit && IS_PLAYER(x, y + 1))
4310 KillHeroUnlessEnemyProtected(x, y + 1);
4311 else if (object_hit && smashed == EL_PENGUIN)
4315 Feld[x][y] = EL_AMOEBA_GROWING;
4316 Store[x][y] = EL_AMOEBA_WET;
4318 ResetRandomAnimationValue(x, y);
4323 if (object_hit) /* check which object was hit */
4325 if (CAN_PASS_MAGIC_WALL(element) &&
4326 (smashed == EL_MAGIC_WALL ||
4327 smashed == EL_BD_MAGIC_WALL))
4330 int activated_magic_wall =
4331 (smashed == EL_MAGIC_WALL ? EL_MAGIC_WALL_ACTIVE :
4332 EL_BD_MAGIC_WALL_ACTIVE);
4334 /* activate magic wall / mill */
4335 for (yy = 0; yy < lev_fieldy; yy++)
4336 for (xx = 0; xx < lev_fieldx; xx++)
4337 if (Feld[xx][yy] == smashed)
4338 Feld[xx][yy] = activated_magic_wall;
4340 game.magic_wall_time_left = level.time_magic_wall * FRAMES_PER_SECOND;
4341 game.magic_wall_active = TRUE;
4343 PlayLevelSound(x, y, (smashed == EL_MAGIC_WALL ?
4344 SND_MAGIC_WALL_ACTIVATING :
4345 SND_BD_MAGIC_WALL_ACTIVATING));
4348 if (IS_PLAYER(x, y + 1))
4350 if (CAN_SMASH_PLAYER(element))
4352 KillHeroUnlessEnemyProtected(x, y + 1);
4356 else if (smashed == EL_PENGUIN)
4358 if (CAN_SMASH_PLAYER(element))
4364 else if (element == EL_BD_DIAMOND)
4366 if (IS_CLASSIC_ENEMY(smashed) && IS_BD_ELEMENT(smashed))
4372 else if (((element == EL_SP_INFOTRON ||
4373 element == EL_SP_ZONK) &&
4374 (smashed == EL_SP_SNIKSNAK ||
4375 smashed == EL_SP_ELECTRON ||
4376 smashed == EL_SP_DISK_ORANGE)) ||
4377 (element == EL_SP_INFOTRON &&
4378 smashed == EL_SP_DISK_YELLOW))
4384 else if (CAN_SMASH_ENEMIES(element) && IS_CLASSIC_ENEMY(smashed))
4390 else if (CAN_SMASH_EVERYTHING(element))
4392 if (IS_CLASSIC_ENEMY(smashed) ||
4393 CAN_EXPLODE_SMASHED(smashed))
4398 else if (!IS_MOVING(x, y + 1) && !IS_BLOCKED(x, y + 1))
4400 if (smashed == EL_LAMP ||
4401 smashed == EL_LAMP_ACTIVE)
4406 else if (smashed == EL_NUT)
4408 Feld[x][y + 1] = EL_NUT_BREAKING;
4409 PlayLevelSound(x, y, SND_NUT_BREAKING);
4410 RaiseScoreElement(EL_NUT);
4413 else if (smashed == EL_PEARL)
4415 ResetGfxAnimation(x, y);
4417 Feld[x][y + 1] = EL_PEARL_BREAKING;
4418 PlayLevelSound(x, y, SND_PEARL_BREAKING);
4421 else if (smashed == EL_DIAMOND)
4423 Feld[x][y + 1] = EL_DIAMOND_BREAKING;
4424 PlayLevelSound(x, y, SND_DIAMOND_BREAKING);
4427 else if (IS_BELT_SWITCH(smashed))
4429 ToggleBeltSwitch(x, y + 1);
4431 else if (smashed == EL_SWITCHGATE_SWITCH_UP ||
4432 smashed == EL_SWITCHGATE_SWITCH_DOWN)
4434 ToggleSwitchgateSwitch(x, y + 1);
4436 else if (smashed == EL_LIGHT_SWITCH ||
4437 smashed == EL_LIGHT_SWITCH_ACTIVE)
4439 ToggleLightSwitch(x, y + 1);
4444 TestIfElementSmashesCustomElement(x, y, MV_DOWN);
4447 CheckElementChange(x, y + 1, smashed, element, CE_SMASHED);
4450 /* !!! TEST ONLY !!! */
4451 CheckElementChangeBySide(x, y + 1, smashed, element,
4452 CE_SWITCHED, CH_SIDE_TOP);
4453 CheckTriggeredElementChangeBySide(x, y + 1, smashed,
4454 CE_OTHER_IS_SWITCHING,CH_SIDE_TOP);
4456 CheckTriggeredElementChangeBySide(x, y + 1, smashed,
4457 CE_OTHER_IS_SWITCHING,CH_SIDE_TOP);
4458 CheckElementChangeBySide(x, y + 1, smashed, element,
4459 CE_SWITCHED, CH_SIDE_TOP);
4465 CheckElementChange(x, y + 1, smashed, element, CE_SMASHED);
4470 /* play sound of magic wall / mill */
4472 (Feld[x][y + 1] == EL_MAGIC_WALL_ACTIVE ||
4473 Feld[x][y + 1] == EL_BD_MAGIC_WALL_ACTIVE))
4475 if (Feld[x][y + 1] == EL_MAGIC_WALL_ACTIVE)
4476 PlayLevelSound(x, y, SND_MAGIC_WALL_FILLING);
4477 else if (Feld[x][y + 1] == EL_BD_MAGIC_WALL_ACTIVE)
4478 PlayLevelSound(x, y, SND_BD_MAGIC_WALL_FILLING);
4483 /* play sound of object that hits the ground */
4484 if (lastline || object_hit)
4485 PlayLevelSoundElementAction(x, y, element, ACTION_IMPACT);
4488 inline static void TurnRoundExt(int x, int y)
4500 { 0, 0 }, { 0, 0 }, { 0, 0 },
4505 int left, right, back;
4509 { MV_DOWN, MV_UP, MV_RIGHT },
4510 { MV_UP, MV_DOWN, MV_LEFT },
4512 { MV_LEFT, MV_RIGHT, MV_DOWN },
4516 { MV_RIGHT, MV_LEFT, MV_UP }
4519 int element = Feld[x][y];
4520 int move_pattern = element_info[element].move_pattern;
4522 int old_move_dir = MovDir[x][y];
4523 int left_dir = turn[old_move_dir].left;
4524 int right_dir = turn[old_move_dir].right;
4525 int back_dir = turn[old_move_dir].back;
4527 int left_dx = move_xy[left_dir].x, left_dy = move_xy[left_dir].y;
4528 int right_dx = move_xy[right_dir].x, right_dy = move_xy[right_dir].y;
4529 int move_dx = move_xy[old_move_dir].x, move_dy = move_xy[old_move_dir].y;
4530 int back_dx = move_xy[back_dir].x, back_dy = move_xy[back_dir].y;
4532 int left_x = x + left_dx, left_y = y + left_dy;
4533 int right_x = x + right_dx, right_y = y + right_dy;
4534 int move_x = x + move_dx, move_y = y + move_dy;
4538 if (element == EL_BUG || element == EL_BD_BUTTERFLY)
4540 TestIfBadThingTouchesOtherBadThing(x, y);
4542 if (ENEMY_CAN_ENTER_FIELD(element, right_x, right_y))
4543 MovDir[x][y] = right_dir;
4544 else if (!ENEMY_CAN_ENTER_FIELD(element, move_x, move_y))
4545 MovDir[x][y] = left_dir;
4547 if (element == EL_BUG && MovDir[x][y] != old_move_dir)
4549 else if (element == EL_BD_BUTTERFLY) /* && MovDir[x][y] == left_dir) */
4553 else if (element == EL_SPACESHIP || element == EL_BD_FIREFLY ||
4554 element == EL_SP_SNIKSNAK || element == EL_SP_ELECTRON)
4556 TestIfBadThingTouchesOtherBadThing(x, y);
4558 if (ENEMY_CAN_ENTER_FIELD(element, left_x, left_y))
4559 MovDir[x][y] = left_dir;
4560 else if (!ENEMY_CAN_ENTER_FIELD(element, move_x, move_y))
4561 MovDir[x][y] = right_dir;
4563 if ((element == EL_SPACESHIP ||
4564 element == EL_SP_SNIKSNAK ||
4565 element == EL_SP_ELECTRON)
4566 && MovDir[x][y] != old_move_dir)
4568 else if (element == EL_BD_FIREFLY) /* && MovDir[x][y] == right_dir) */
4572 else if (element == EL_SPACESHIP || element == EL_BD_FIREFLY)
4574 TestIfBadThingTouchesOtherBadThing(x, y);
4576 if (ENEMY_CAN_ENTER_FIELD(element, left_x, left_y))
4577 MovDir[x][y] = left_dir;
4578 else if (!ENEMY_CAN_ENTER_FIELD(element, move_x, move_y))
4579 MovDir[x][y] = right_dir;
4581 if (element == EL_SPACESHIP && MovDir[x][y] != old_move_dir)
4583 else if (element == EL_BD_FIREFLY) /* && MovDir[x][y] == right_dir) */
4586 else if (element == EL_SP_SNIKSNAK || element == EL_SP_ELECTRON)
4588 TestIfBadThingTouchesOtherBadThing(x, y);
4590 if (ELEMENT_CAN_ENTER_FIELD_BASE_4(element, left_x, left_y, 0))
4591 MovDir[x][y] = left_dir;
4592 else if (!ELEMENT_CAN_ENTER_FIELD_BASE_4(element, move_x, move_y, 0))
4593 MovDir[x][y] = right_dir;
4595 if (MovDir[x][y] != old_move_dir)
4599 else if (element == EL_YAMYAM)
4601 boolean can_turn_left = YAMYAM_CAN_ENTER_FIELD(element, left_x, left_y);
4602 boolean can_turn_right = YAMYAM_CAN_ENTER_FIELD(element, right_x, right_y);
4604 if (can_turn_left && can_turn_right)
4605 MovDir[x][y] = (RND(3) ? (RND(2) ? left_dir : right_dir) : back_dir);
4606 else if (can_turn_left)
4607 MovDir[x][y] = (RND(2) ? left_dir : back_dir);
4608 else if (can_turn_right)
4609 MovDir[x][y] = (RND(2) ? right_dir : back_dir);
4611 MovDir[x][y] = back_dir;
4613 MovDelay[x][y] = 16 + 16 * RND(3);
4615 else if (element == EL_DARK_YAMYAM)
4617 boolean can_turn_left = DARK_YAMYAM_CAN_ENTER_FIELD(element,
4619 boolean can_turn_right = DARK_YAMYAM_CAN_ENTER_FIELD(element,
4622 if (can_turn_left && can_turn_right)
4623 MovDir[x][y] = (RND(3) ? (RND(2) ? left_dir : right_dir) : back_dir);
4624 else if (can_turn_left)
4625 MovDir[x][y] = (RND(2) ? left_dir : back_dir);
4626 else if (can_turn_right)
4627 MovDir[x][y] = (RND(2) ? right_dir : back_dir);
4629 MovDir[x][y] = back_dir;
4631 MovDelay[x][y] = 16 + 16 * RND(3);
4633 else if (element == EL_PACMAN)
4635 boolean can_turn_left = PACMAN_CAN_ENTER_FIELD(element, left_x, left_y);
4636 boolean can_turn_right = PACMAN_CAN_ENTER_FIELD(element, right_x, right_y);
4638 if (can_turn_left && can_turn_right)
4639 MovDir[x][y] = (RND(3) ? (RND(2) ? left_dir : right_dir) : back_dir);
4640 else if (can_turn_left)
4641 MovDir[x][y] = (RND(2) ? left_dir : back_dir);
4642 else if (can_turn_right)
4643 MovDir[x][y] = (RND(2) ? right_dir : back_dir);
4645 MovDir[x][y] = back_dir;
4647 MovDelay[x][y] = 6 + RND(40);
4649 else if (element == EL_PIG)
4651 boolean can_turn_left = PIG_CAN_ENTER_FIELD(element, left_x, left_y);
4652 boolean can_turn_right = PIG_CAN_ENTER_FIELD(element, right_x, right_y);
4653 boolean can_move_on = PIG_CAN_ENTER_FIELD(element, move_x, move_y);
4654 boolean should_turn_left, should_turn_right, should_move_on;
4656 int rnd = RND(rnd_value);
4658 should_turn_left = (can_turn_left &&
4660 IN_LEV_FIELD_AND_NOT_FREE(x + back_dx + left_dx,
4661 y + back_dy + left_dy)));
4662 should_turn_right = (can_turn_right &&
4664 IN_LEV_FIELD_AND_NOT_FREE(x + back_dx + right_dx,
4665 y + back_dy + right_dy)));
4666 should_move_on = (can_move_on &&
4669 IN_LEV_FIELD_AND_NOT_FREE(x + move_dx + left_dx,
4670 y + move_dy + left_dy) ||
4671 IN_LEV_FIELD_AND_NOT_FREE(x + move_dx + right_dx,
4672 y + move_dy + right_dy)));
4674 if (should_turn_left || should_turn_right || should_move_on)
4676 if (should_turn_left && should_turn_right && should_move_on)
4677 MovDir[x][y] = (rnd < rnd_value / 3 ? left_dir :
4678 rnd < 2 * rnd_value / 3 ? right_dir :
4680 else if (should_turn_left && should_turn_right)
4681 MovDir[x][y] = (rnd < rnd_value / 2 ? left_dir : right_dir);
4682 else if (should_turn_left && should_move_on)
4683 MovDir[x][y] = (rnd < rnd_value / 2 ? left_dir : old_move_dir);
4684 else if (should_turn_right && should_move_on)
4685 MovDir[x][y] = (rnd < rnd_value / 2 ? right_dir : old_move_dir);
4686 else if (should_turn_left)
4687 MovDir[x][y] = left_dir;
4688 else if (should_turn_right)
4689 MovDir[x][y] = right_dir;
4690 else if (should_move_on)
4691 MovDir[x][y] = old_move_dir;
4693 else if (can_move_on && rnd > rnd_value / 8)
4694 MovDir[x][y] = old_move_dir;
4695 else if (can_turn_left && can_turn_right)
4696 MovDir[x][y] = (rnd < rnd_value / 2 ? left_dir : right_dir);
4697 else if (can_turn_left && rnd > rnd_value / 8)
4698 MovDir[x][y] = left_dir;
4699 else if (can_turn_right && rnd > rnd_value/8)
4700 MovDir[x][y] = right_dir;
4702 MovDir[x][y] = back_dir;
4704 xx = x + move_xy[MovDir[x][y]].x;
4705 yy = y + move_xy[MovDir[x][y]].y;
4708 /* !!! this bugfix breaks at least BD2K3, level 010 !!! [re-recorded] */
4709 if (!IN_LEV_FIELD(xx, yy) ||
4710 (!IS_FREE(xx, yy) && !IS_FOOD_PIG(Feld[xx][yy])))
4711 MovDir[x][y] = old_move_dir;
4713 if (!IS_FREE(xx, yy) && !IS_FOOD_PIG(Feld[xx][yy]))
4714 MovDir[x][y] = old_move_dir;
4719 else if (element == EL_DRAGON)
4721 boolean can_turn_left = DRAGON_CAN_ENTER_FIELD(element, left_x, left_y);
4722 boolean can_turn_right = DRAGON_CAN_ENTER_FIELD(element, right_x, right_y);
4723 boolean can_move_on = DRAGON_CAN_ENTER_FIELD(element, move_x, move_y);
4725 int rnd = RND(rnd_value);
4728 if (FrameCounter < 1 && x == 0 && y == 29)
4729 printf(":2: %d/%d: %d [%d]\n", x, y, MovDir[x][y], FrameCounter);
4732 if (can_move_on && rnd > rnd_value / 8)
4733 MovDir[x][y] = old_move_dir;
4734 else if (can_turn_left && can_turn_right)
4735 MovDir[x][y] = (rnd < rnd_value / 2 ? left_dir : right_dir);
4736 else if (can_turn_left && rnd > rnd_value / 8)
4737 MovDir[x][y] = left_dir;
4738 else if (can_turn_right && rnd > rnd_value / 8)
4739 MovDir[x][y] = right_dir;
4741 MovDir[x][y] = back_dir;
4743 xx = x + move_xy[MovDir[x][y]].x;
4744 yy = y + move_xy[MovDir[x][y]].y;
4747 if (FrameCounter < 1 && x == 0 && y == 29)
4748 printf(":3: %d/%d: %d (%d/%d: %d) [%d]\n", x, y, MovDir[x][y],
4749 xx, yy, Feld[xx][yy],
4754 if (!IN_LEV_FIELD_AND_IS_FREE(xx, yy))
4755 MovDir[x][y] = old_move_dir;
4757 if (!IS_FREE(xx, yy))
4758 MovDir[x][y] = old_move_dir;
4762 if (FrameCounter < 1 && x == 0 && y == 29)
4763 printf(":4: %d/%d: %d [%d]\n", x, y, MovDir[x][y], FrameCounter);
4768 else if (element == EL_MOLE)
4770 boolean can_move_on =
4771 (MOLE_CAN_ENTER_FIELD(element, move_x, move_y,
4772 IS_AMOEBOID(Feld[move_x][move_y]) ||
4773 Feld[move_x][move_y] == EL_AMOEBA_SHRINKING));
4776 boolean can_turn_left =
4777 (MOLE_CAN_ENTER_FIELD(element, left_x, left_y,
4778 IS_AMOEBOID(Feld[left_x][left_y])));
4780 boolean can_turn_right =
4781 (MOLE_CAN_ENTER_FIELD(element, right_x, right_y,
4782 IS_AMOEBOID(Feld[right_x][right_y])));
4784 if (can_turn_left && can_turn_right)
4785 MovDir[x][y] = (RND(2) ? left_dir : right_dir);
4786 else if (can_turn_left)
4787 MovDir[x][y] = left_dir;
4789 MovDir[x][y] = right_dir;
4792 if (MovDir[x][y] != old_move_dir)
4795 else if (element == EL_BALLOON)
4797 MovDir[x][y] = game.balloon_dir;
4800 else if (element == EL_SPRING)
4803 if (MovDir[x][y] & MV_HORIZONTAL &&
4804 !SPRING_CAN_ENTER_FIELD(element, move_x, move_y))
4805 MovDir[x][y] = MV_NO_MOVING;
4807 if (MovDir[x][y] & MV_HORIZONTAL &&
4808 (!SPRING_CAN_ENTER_FIELD(element, move_x, move_y) ||
4809 SPRING_CAN_ENTER_FIELD(element, x, y + 1)))
4810 MovDir[x][y] = MV_NO_MOVING;
4815 else if (element == EL_ROBOT ||
4816 element == EL_SATELLITE ||
4817 element == EL_PENGUIN)
4819 int attr_x = -1, attr_y = -1;
4830 for (i = 0; i < MAX_PLAYERS; i++)
4832 struct PlayerInfo *player = &stored_player[i];
4833 int jx = player->jx, jy = player->jy;
4835 if (!player->active)
4839 ABS(jx - x) + ABS(jy - y) < ABS(attr_x - x) + ABS(attr_y - y))
4848 if (element == EL_ROBOT && ZX >= 0 && ZY >= 0 &&
4849 (Feld[ZX][ZY] == EL_ROBOT_WHEEL_ACTIVE ||
4850 game.engine_version < VERSION_IDENT(3,1,0,0)))
4852 if (element == EL_ROBOT && ZX >= 0 && ZY >= 0)
4859 if (element == EL_PENGUIN)
4862 static int xy[4][2] =
4870 for (i = 0; i < NUM_DIRECTIONS; i++)
4872 int ex = x + xy[i][0];
4873 int ey = y + xy[i][1];
4875 if (IN_LEV_FIELD(ex, ey) && Feld[ex][ey] == EL_EXIT_OPEN)
4884 MovDir[x][y] = MV_NO_MOVING;
4886 MovDir[x][y] |= (AllPlayersGone ? MV_RIGHT : MV_LEFT);
4887 else if (attr_x > x)
4888 MovDir[x][y] |= (AllPlayersGone ? MV_LEFT : MV_RIGHT);
4890 MovDir[x][y] |= (AllPlayersGone ? MV_DOWN : MV_UP);
4891 else if (attr_y > y)
4892 MovDir[x][y] |= (AllPlayersGone ? MV_UP : MV_DOWN);
4894 if (element == EL_ROBOT)
4898 if (MovDir[x][y] & MV_HORIZONTAL && MovDir[x][y] & MV_VERTICAL)
4899 MovDir[x][y] &= (RND(2) ? MV_HORIZONTAL : MV_VERTICAL);
4900 Moving2Blocked(x, y, &newx, &newy);
4902 if (IN_LEV_FIELD(newx, newy) && IS_FREE_OR_PLAYER(newx, newy))
4903 MovDelay[x][y] = 8 + 8 * !RND(3);
4905 MovDelay[x][y] = 16;
4907 else if (element == EL_PENGUIN)
4913 if (MovDir[x][y] & MV_HORIZONTAL && MovDir[x][y] & MV_VERTICAL)
4915 boolean first_horiz = RND(2);
4916 int new_move_dir = MovDir[x][y];
4919 new_move_dir & (first_horiz ? MV_HORIZONTAL : MV_VERTICAL);
4920 Moving2Blocked(x, y, &newx, &newy);
4922 if (PENGUIN_CAN_ENTER_FIELD(EL_PENGUIN, newx, newy))
4926 new_move_dir & (!first_horiz ? MV_HORIZONTAL : MV_VERTICAL);
4927 Moving2Blocked(x, y, &newx, &newy);
4929 if (PENGUIN_CAN_ENTER_FIELD(EL_PENGUIN, newx, newy))
4932 MovDir[x][y] = old_move_dir;
4936 else /* (element == EL_SATELLITE) */
4942 if (MovDir[x][y] & MV_HORIZONTAL && MovDir[x][y] & MV_VERTICAL)
4944 boolean first_horiz = RND(2);
4945 int new_move_dir = MovDir[x][y];
4948 new_move_dir & (first_horiz ? MV_HORIZONTAL : MV_VERTICAL);
4949 Moving2Blocked(x, y, &newx, &newy);
4951 if (SATELLITE_CAN_ENTER_FIELD(newx, newy))
4955 new_move_dir & (!first_horiz ? MV_HORIZONTAL : MV_VERTICAL);
4956 Moving2Blocked(x, y, &newx, &newy);
4958 if (SATELLITE_CAN_ENTER_FIELD(newx, newy))
4961 MovDir[x][y] = old_move_dir;
4966 else if (move_pattern == MV_TURNING_LEFT ||
4967 move_pattern == MV_TURNING_RIGHT ||
4968 move_pattern == MV_TURNING_LEFT_RIGHT ||
4969 move_pattern == MV_TURNING_RIGHT_LEFT ||
4970 move_pattern == MV_TURNING_RANDOM ||
4971 move_pattern == MV_ALL_DIRECTIONS)
4973 boolean can_turn_left =
4974 CUSTOM_ELEMENT_CAN_ENTER_FIELD(element, left_x, left_y);
4975 boolean can_turn_right =
4976 CUSTOM_ELEMENT_CAN_ENTER_FIELD(element, right_x,right_y);
4978 if (move_pattern == MV_TURNING_LEFT)
4979 MovDir[x][y] = left_dir;
4980 else if (move_pattern == MV_TURNING_RIGHT)
4981 MovDir[x][y] = right_dir;
4982 else if (move_pattern == MV_TURNING_LEFT_RIGHT)
4983 MovDir[x][y] = (can_turn_left || !can_turn_right ? left_dir : right_dir);
4984 else if (move_pattern == MV_TURNING_RIGHT_LEFT)
4985 MovDir[x][y] = (can_turn_right || !can_turn_left ? right_dir : left_dir);
4986 else if (move_pattern == MV_TURNING_RANDOM)
4987 MovDir[x][y] = (can_turn_left && !can_turn_right ? left_dir :
4988 can_turn_right && !can_turn_left ? right_dir :
4989 RND(2) ? left_dir : right_dir);
4990 else if (can_turn_left && can_turn_right)
4991 MovDir[x][y] = (RND(3) ? (RND(2) ? left_dir : right_dir) : back_dir);
4992 else if (can_turn_left)
4993 MovDir[x][y] = (RND(2) ? left_dir : back_dir);
4994 else if (can_turn_right)
4995 MovDir[x][y] = (RND(2) ? right_dir : back_dir);
4997 MovDir[x][y] = back_dir;
4999 MovDelay[x][y] = GET_NEW_MOVE_DELAY(element);
5001 else if (move_pattern == MV_HORIZONTAL ||
5002 move_pattern == MV_VERTICAL)
5004 if (move_pattern & old_move_dir)
5005 MovDir[x][y] = back_dir;
5006 else if (move_pattern == MV_HORIZONTAL)
5007 MovDir[x][y] = (RND(2) ? MV_LEFT : MV_RIGHT);
5008 else if (move_pattern == MV_VERTICAL)
5009 MovDir[x][y] = (RND(2) ? MV_UP : MV_DOWN);
5011 MovDelay[x][y] = GET_NEW_MOVE_DELAY(element);
5013 else if (move_pattern & MV_ANY_DIRECTION)
5015 MovDir[x][y] = move_pattern;
5016 MovDelay[x][y] = GET_NEW_MOVE_DELAY(element);
5018 else if (move_pattern == MV_ALONG_LEFT_SIDE)
5020 if (CUSTOM_ELEMENT_CAN_ENTER_FIELD(element, left_x, left_y))
5021 MovDir[x][y] = left_dir;
5022 else if (!CUSTOM_ELEMENT_CAN_ENTER_FIELD(element, move_x, move_y))
5023 MovDir[x][y] = right_dir;
5025 if (MovDir[x][y] != old_move_dir)
5026 MovDelay[x][y] = GET_NEW_MOVE_DELAY(element);
5028 else if (move_pattern == MV_ALONG_RIGHT_SIDE)
5030 if (CUSTOM_ELEMENT_CAN_ENTER_FIELD(element, right_x, right_y))
5031 MovDir[x][y] = right_dir;
5032 else if (!CUSTOM_ELEMENT_CAN_ENTER_FIELD(element, move_x, move_y))
5033 MovDir[x][y] = left_dir;
5035 if (MovDir[x][y] != old_move_dir)
5036 MovDelay[x][y] = GET_NEW_MOVE_DELAY(element);
5038 else if (move_pattern == MV_TOWARDS_PLAYER ||
5039 move_pattern == MV_AWAY_FROM_PLAYER)
5041 int attr_x = -1, attr_y = -1;
5043 boolean move_away = (move_pattern == MV_AWAY_FROM_PLAYER);
5054 for (i = 0; i < MAX_PLAYERS; i++)
5056 struct PlayerInfo *player = &stored_player[i];
5057 int jx = player->jx, jy = player->jy;
5059 if (!player->active)
5063 ABS(jx - x) + ABS(jy - y) < ABS(attr_x - x) + ABS(attr_y - y))
5071 MovDir[x][y] = MV_NO_MOVING;
5073 MovDir[x][y] |= (move_away ? MV_RIGHT : MV_LEFT);
5074 else if (attr_x > x)
5075 MovDir[x][y] |= (move_away ? MV_LEFT : MV_RIGHT);
5077 MovDir[x][y] |= (move_away ? MV_DOWN : MV_UP);
5078 else if (attr_y > y)
5079 MovDir[x][y] |= (move_away ? MV_UP : MV_DOWN);
5081 MovDelay[x][y] = GET_NEW_MOVE_DELAY(element);
5083 if (MovDir[x][y] & MV_HORIZONTAL && MovDir[x][y] & MV_VERTICAL)
5085 boolean first_horiz = RND(2);
5086 int new_move_dir = MovDir[x][y];
5089 new_move_dir & (first_horiz ? MV_HORIZONTAL : MV_VERTICAL);
5090 Moving2Blocked(x, y, &newx, &newy);
5092 if (CUSTOM_ELEMENT_CAN_ENTER_FIELD(element, newx, newy))
5096 new_move_dir & (!first_horiz ? MV_HORIZONTAL : MV_VERTICAL);
5097 Moving2Blocked(x, y, &newx, &newy);
5099 if (CUSTOM_ELEMENT_CAN_ENTER_FIELD(element, newx, newy))
5102 MovDir[x][y] = old_move_dir;
5105 else if (move_pattern == MV_WHEN_PUSHED ||
5106 move_pattern == MV_WHEN_DROPPED)
5108 if (!CUSTOM_ELEMENT_CAN_ENTER_FIELD(element, move_x, move_y))
5109 MovDir[x][y] = MV_NO_MOVING;
5113 else if (move_pattern & MV_MAZE_RUNNER_STYLE)
5115 static int test_xy[7][2] =
5125 static int test_dir[7] =
5135 boolean hunter_mode = (move_pattern == MV_MAZE_HUNTER);
5136 int move_preference = -1000000; /* start with very low preference */
5137 int new_move_dir = MV_NO_MOVING;
5138 int start_test = RND(4);
5141 for (i = 0; i < NUM_DIRECTIONS; i++)
5143 int move_dir = test_dir[start_test + i];
5144 int move_dir_preference;
5146 xx = x + test_xy[start_test + i][0];
5147 yy = y + test_xy[start_test + i][1];
5149 if (hunter_mode && IN_LEV_FIELD(xx, yy) &&
5150 (IS_PLAYER(xx, yy) || Feld[xx][yy] == EL_PLAYER_IS_LEAVING))
5152 new_move_dir = move_dir;
5157 if (!CUSTOM_ELEMENT_CAN_ENTER_FIELD(element, xx, yy))
5160 move_dir_preference = -1 * RunnerVisit[xx][yy];
5161 if (hunter_mode && PlayerVisit[xx][yy] > 0)
5162 move_dir_preference = PlayerVisit[xx][yy];
5164 if (move_dir_preference > move_preference)
5166 /* prefer field that has not been visited for the longest time */
5167 move_preference = move_dir_preference;
5168 new_move_dir = move_dir;
5170 else if (move_dir_preference == move_preference &&
5171 move_dir == old_move_dir)
5173 /* prefer last direction when all directions are preferred equally */
5174 move_preference = move_dir_preference;
5175 new_move_dir = move_dir;
5179 MovDir[x][y] = new_move_dir;
5180 if (old_move_dir != new_move_dir)
5183 MovDelay[x][y] = GET_NEW_MOVE_DELAY(element);
5191 static void TurnRound(int x, int y)
5193 int direction = MovDir[x][y];
5196 GfxDir[x][y] = MovDir[x][y];
5202 GfxDir[x][y] = MovDir[x][y];
5205 if (direction != MovDir[x][y])
5210 GfxAction[x][y] = ACTION_TURNING_FROM_LEFT + MV_DIR_BIT(direction);
5213 GfxAction[x][y] = ACTION_WAITING;
5217 static boolean JustBeingPushed(int x, int y)
5221 for (i = 0; i < MAX_PLAYERS; i++)
5223 struct PlayerInfo *player = &stored_player[i];
5225 if (player->active && player->is_pushing && player->MovPos)
5227 int next_jx = player->jx + (player->jx - player->last_jx);
5228 int next_jy = player->jy + (player->jy - player->last_jy);
5230 if (x == next_jx && y == next_jy)
5238 void StartMoving(int x, int y)
5241 boolean use_spring_bug = (game.engine_version < VERSION_IDENT(2,2,0,0));
5243 boolean started_moving = FALSE; /* some elements can fall _and_ move */
5244 int element = Feld[x][y];
5250 if (MovDelay[x][y] == 0)
5251 GfxAction[x][y] = ACTION_DEFAULT;
5253 /* !!! this should be handled more generic (not only for mole) !!! */
5254 if (element != EL_MOLE && GfxAction[x][y] != ACTION_DIGGING)
5255 GfxAction[x][y] = ACTION_DEFAULT;
5258 if (CAN_FALL(element) && y < lev_fieldy - 1)
5260 if ((x > 0 && IS_PLAYER(x - 1, y)) ||
5261 (x < lev_fieldx - 1 && IS_PLAYER(x + 1, y)))
5262 if (JustBeingPushed(x, y))
5265 if (element == EL_QUICKSAND_FULL)
5267 if (IS_FREE(x, y + 1))
5269 InitMovingField(x, y, MV_DOWN);
5270 started_moving = TRUE;
5272 Feld[x][y] = EL_QUICKSAND_EMPTYING;
5273 Store[x][y] = EL_ROCK;
5275 PlayLevelSoundAction(x, y, ACTION_EMPTYING);
5277 PlayLevelSound(x, y, SND_QUICKSAND_EMPTYING);
5280 else if (Feld[x][y + 1] == EL_QUICKSAND_EMPTY)
5282 if (!MovDelay[x][y])
5283 MovDelay[x][y] = TILEY + 1;
5292 Feld[x][y] = EL_QUICKSAND_EMPTY;
5293 Feld[x][y + 1] = EL_QUICKSAND_FULL;
5294 Store[x][y + 1] = Store[x][y];
5297 PlayLevelSoundAction(x, y, ACTION_FILLING);
5299 PlayLevelSound(x, y, SND_QUICKSAND_FILLING);
5303 else if ((element == EL_ROCK || element == EL_BD_ROCK) &&
5304 Feld[x][y + 1] == EL_QUICKSAND_EMPTY)
5306 InitMovingField(x, y, MV_DOWN);
5307 started_moving = TRUE;
5309 Feld[x][y] = EL_QUICKSAND_FILLING;
5310 Store[x][y] = element;
5312 PlayLevelSoundAction(x, y, ACTION_FILLING);
5314 PlayLevelSound(x, y, SND_QUICKSAND_FILLING);
5317 else if (element == EL_MAGIC_WALL_FULL)
5319 if (IS_FREE(x, y + 1))
5321 InitMovingField(x, y, MV_DOWN);
5322 started_moving = TRUE;
5324 Feld[x][y] = EL_MAGIC_WALL_EMPTYING;
5325 Store[x][y] = EL_CHANGED(Store[x][y]);
5327 else if (Feld[x][y + 1] == EL_MAGIC_WALL_ACTIVE)
5329 if (!MovDelay[x][y])
5330 MovDelay[x][y] = TILEY/4 + 1;
5339 Feld[x][y] = EL_MAGIC_WALL_ACTIVE;
5340 Feld[x][y + 1] = EL_MAGIC_WALL_FULL;
5341 Store[x][y + 1] = EL_CHANGED(Store[x][y]);
5345 else if (element == EL_BD_MAGIC_WALL_FULL)
5347 if (IS_FREE(x, y + 1))
5349 InitMovingField(x, y, MV_DOWN);
5350 started_moving = TRUE;
5352 Feld[x][y] = EL_BD_MAGIC_WALL_EMPTYING;
5353 Store[x][y] = EL_CHANGED2(Store[x][y]);
5355 else if (Feld[x][y + 1] == EL_BD_MAGIC_WALL_ACTIVE)
5357 if (!MovDelay[x][y])
5358 MovDelay[x][y] = TILEY/4 + 1;
5367 Feld[x][y] = EL_BD_MAGIC_WALL_ACTIVE;
5368 Feld[x][y + 1] = EL_BD_MAGIC_WALL_FULL;
5369 Store[x][y + 1] = EL_CHANGED2(Store[x][y]);
5373 else if (CAN_PASS_MAGIC_WALL(element) &&
5374 (Feld[x][y + 1] == EL_MAGIC_WALL_ACTIVE ||
5375 Feld[x][y + 1] == EL_BD_MAGIC_WALL_ACTIVE))
5377 InitMovingField(x, y, MV_DOWN);
5378 started_moving = TRUE;
5381 (Feld[x][y + 1] == EL_MAGIC_WALL_ACTIVE ? EL_MAGIC_WALL_FILLING :
5382 EL_BD_MAGIC_WALL_FILLING);
5383 Store[x][y] = element;
5386 else if (CAN_SMASH(element) && Feld[x][y + 1] == EL_ACID)
5388 else if (CAN_FALL(element) && Feld[x][y + 1] == EL_ACID)
5391 SplashAcid(x, y + 1);
5393 InitMovingField(x, y, MV_DOWN);
5394 started_moving = TRUE;
5396 Store[x][y] = EL_ACID;
5398 /* !!! TEST !!! better use "_FALLING" etc. !!! */
5399 GfxAction[x][y + 1] = ACTION_ACTIVE;
5403 else if ((game.engine_version >= VERSION_IDENT(3,1,0,0) &&
5404 CheckCollision[x][y] && !IS_FREE(x, y + 1)) ||
5406 (game.engine_version >= VERSION_IDENT(3,0,7,0) &&
5407 CAN_SMASH(element) && WasJustFalling[x][y] &&
5408 (Feld[x][y + 1] == EL_BLOCKED || IS_PLAYER(x, y + 1))) ||
5410 (game.engine_version < VERSION_IDENT(2,2,0,7) &&
5411 CAN_SMASH(element) && WasJustMoving[x][y] && !Pushed[x][y + 1] &&
5412 (Feld[x][y + 1] == EL_BLOCKED)))
5416 else if (game.engine_version < VERSION_IDENT(2,2,0,7) &&
5417 CAN_SMASH(element) && Feld[x][y + 1] == EL_BLOCKED &&
5418 WasJustMoving[x][y] && !Pushed[x][y + 1])
5420 else if (CAN_SMASH(element) && Feld[x][y + 1] == EL_BLOCKED &&
5421 WasJustMoving[x][y])
5426 /* this is needed for a special case not covered by calling "Impact()"
5427 from "ContinueMoving()": if an element moves to a tile directly below
5428 another element which was just falling on that tile (which was empty
5429 in the previous frame), the falling element above would just stop
5430 instead of smashing the element below (in previous version, the above
5431 element was just checked for "moving" instead of "falling", resulting
5432 in incorrect smashes caused by horizontal movement of the above
5433 element; also, the case of the player being the element to smash was
5434 simply not covered here... :-/ ) */
5437 WasJustMoving[x][y] = 0;
5438 WasJustFalling[x][y] = 0;
5441 CheckCollision[x][y] = 0;
5444 if (IS_PLAYER(x, y + 1))
5445 printf("::: we ARE now killing the player [%d]\n", FrameCounter);
5450 else if (IS_FREE(x, y + 1) && element == EL_SPRING && level.use_spring_bug)
5452 if (MovDir[x][y] == MV_NO_MOVING)
5454 InitMovingField(x, y, MV_DOWN);
5455 started_moving = TRUE;
5458 else if (IS_FREE(x, y + 1) || Feld[x][y + 1] == EL_DIAMOND_BREAKING)
5460 if (WasJustFalling[x][y]) /* prevent animation from being restarted */
5461 MovDir[x][y] = MV_DOWN;
5463 InitMovingField(x, y, MV_DOWN);
5464 started_moving = TRUE;
5466 else if (element == EL_AMOEBA_DROP)
5468 Feld[x][y] = EL_AMOEBA_GROWING;
5469 Store[x][y] = EL_AMOEBA_WET;
5471 /* Store[x][y + 1] must be zero, because:
5472 (EL_QUICKSAND_FULL -> EL_ROCK): Store[x][y + 1] == EL_QUICKSAND_EMPTY
5475 #if OLD_GAME_BEHAVIOUR
5476 else if (IS_SLIPPERY(Feld[x][y + 1]) && !Store[x][y + 1])
5478 else if (IS_SLIPPERY(Feld[x][y + 1]) && !Store[x][y + 1] &&
5479 !IS_FALLING(x, y + 1) && !WasJustMoving[x][y + 1] &&
5480 element != EL_DX_SUPABOMB)
5483 else if (((IS_SLIPPERY(Feld[x][y + 1]) && !IS_PLAYER(x, y + 1)) ||
5484 (IS_EM_SLIPPERY_WALL(Feld[x][y + 1]) && IS_GEM(element))) &&
5485 !IS_FALLING(x, y + 1) && !WasJustMoving[x][y + 1] &&
5486 element != EL_DX_SUPABOMB && element != EL_SP_DISK_ORANGE)
5489 boolean can_fall_left = (x > 0 && IS_FREE(x - 1, y) &&
5490 (IS_FREE(x - 1, y + 1) ||
5491 Feld[x - 1][y + 1] == EL_ACID));
5492 boolean can_fall_right = (x < lev_fieldx - 1 && IS_FREE(x + 1, y) &&
5493 (IS_FREE(x + 1, y + 1) ||
5494 Feld[x + 1][y + 1] == EL_ACID));
5495 boolean can_fall_any = (can_fall_left || can_fall_right);
5496 boolean can_fall_both = (can_fall_left && can_fall_right);
5498 if (can_fall_any && IS_CUSTOM_ELEMENT(Feld[x][y + 1]))
5500 int slippery_type = element_info[Feld[x][y + 1]].slippery_type;
5502 if (slippery_type == SLIPPERY_ONLY_LEFT)
5503 can_fall_right = FALSE;
5504 else if (slippery_type == SLIPPERY_ONLY_RIGHT)
5505 can_fall_left = FALSE;
5506 else if (slippery_type == SLIPPERY_ANY_LEFT_RIGHT && can_fall_both)
5507 can_fall_right = FALSE;
5508 else if (slippery_type == SLIPPERY_ANY_RIGHT_LEFT && can_fall_both)
5509 can_fall_left = FALSE;
5511 can_fall_any = (can_fall_left || can_fall_right);
5512 can_fall_both = (can_fall_left && can_fall_right);
5515 #if USE_NEW_SP_SLIPPERY
5516 /* !!! better use the same properties as for custom elements here !!! */
5517 else if (game.engine_version >= VERSION_IDENT(3,1,1,0) &&
5518 can_fall_both && IS_SP_ELEMENT(Feld[x][y + 1]))
5520 can_fall_right = FALSE; /* slip down on left side */
5521 can_fall_both = FALSE;
5528 if (game.emulation == EMU_BOULDERDASH ||
5529 element == EL_BD_ROCK || element == EL_BD_DIAMOND)
5530 can_fall_right = FALSE; /* slip down on left side */
5532 can_fall_left = !(can_fall_right = RND(2));
5534 can_fall_both = FALSE;
5541 if (can_fall_both &&
5542 (game.emulation != EMU_BOULDERDASH &&
5543 element != EL_BD_ROCK && element != EL_BD_DIAMOND))
5544 can_fall_left = !(can_fall_right = RND(2));
5547 /* if not determined otherwise, prefer left side for slipping down */
5548 InitMovingField(x, y, can_fall_left ? MV_LEFT : MV_RIGHT);
5549 started_moving = TRUE;
5553 else if (IS_BELT_ACTIVE(Feld[x][y + 1]) && !CAN_MOVE(element))
5555 else if (IS_BELT_ACTIVE(Feld[x][y + 1]))
5558 boolean left_is_free = (x > 0 && IS_FREE(x - 1, y));
5559 boolean right_is_free = (x < lev_fieldx - 1 && IS_FREE(x + 1, y));
5560 int belt_nr = getBeltNrFromBeltActiveElement(Feld[x][y + 1]);
5561 int belt_dir = game.belt_dir[belt_nr];
5563 if ((belt_dir == MV_LEFT && left_is_free) ||
5564 (belt_dir == MV_RIGHT && right_is_free))
5567 int nextx = (belt_dir == MV_LEFT ? x - 1 : x + 1);
5570 InitMovingField(x, y, belt_dir);
5571 started_moving = TRUE;
5574 Pushed[x][y] = TRUE;
5575 Pushed[nextx][y] = TRUE;
5578 GfxAction[x][y] = ACTION_DEFAULT;
5582 MovDir[x][y] = 0; /* if element was moving, stop it */
5587 /* not "else if" because of elements that can fall and move (EL_SPRING) */
5589 if (CAN_MOVE(element) && !started_moving && MovDir[x][y] != MV_NO_MOVING)
5591 if (CAN_MOVE(element) && !started_moving)
5594 int move_pattern = element_info[element].move_pattern;
5599 if (MovDir[x][y] == MV_NO_MOVING)
5601 printf("StartMoving(): %d,%d: element %d ['%s'] not moving\n",
5602 x, y, element, element_info[element].token_name);
5603 printf("StartMoving(): This should never happen!\n");
5608 Moving2Blocked(x, y, &newx, &newy);
5611 if (IS_PUSHABLE(element) && JustBeingPushed(x, y))
5614 if ((element == EL_SATELLITE ||
5615 element == EL_BALLOON ||
5616 element == EL_SPRING)
5617 && JustBeingPushed(x, y))
5624 if (game.engine_version >= VERSION_IDENT(3,1,0,0) &&
5625 CheckCollision[x][y] && !IN_LEV_FIELD_AND_IS_FREE(newx, newy))
5627 if (game.engine_version >= VERSION_IDENT(3,1,0,0) &&
5628 WasJustMoving[x][y] && IN_LEV_FIELD(newx, newy) &&
5629 (Feld[newx][newy] == EL_BLOCKED || IS_PLAYER(newx, newy)))
5633 printf("::: element %d '%s' WasJustMoving %d [%d, %d, %d, %d]\n",
5634 element, element_info[element].token_name,
5635 WasJustMoving[x][y],
5636 HAS_ANY_CHANGE_EVENT(element, CE_HITTING_SOMETHING),
5637 HAS_ANY_CHANGE_EVENT(element, CE_HIT_BY_SOMETHING),
5638 HAS_ANY_CHANGE_EVENT(element, CE_OTHER_IS_HITTING),
5639 HAS_ANY_CHANGE_EVENT(element, CE_OTHER_GETS_HIT));
5643 WasJustMoving[x][y] = 0;
5646 CheckCollision[x][y] = 0;
5648 TestIfElementHitsCustomElement(x, y, MovDir[x][y]);
5651 if (Feld[x][y] != element) /* element has changed */
5653 element = Feld[x][y];
5654 move_pattern = element_info[element].move_pattern;
5656 if (!CAN_MOVE(element))
5660 if (Feld[x][y] != element) /* element has changed */
5668 if (element == EL_SPRING && MovDir[x][y] == MV_DOWN)
5669 Feld[x][y + 1] = EL_EMPTY; /* was set to EL_BLOCKED above */
5671 if (element == EL_SPRING && MovDir[x][y] != MV_NO_MOVING)
5673 Moving2Blocked(x, y, &newx, &newy);
5674 if (Feld[newx][newy] == EL_BLOCKED)
5675 Feld[newx][newy] = EL_EMPTY; /* was set to EL_BLOCKED above */
5681 if (FrameCounter < 1 && x == 0 && y == 29)
5682 printf(":1: %d/%d: %d [%d]\n", x, y, MovDir[x][y], FrameCounter);
5685 if (!MovDelay[x][y]) /* start new movement phase */
5687 /* all objects that can change their move direction after each step
5688 (YAMYAM, DARK_YAMYAM and PACMAN go straight until they hit a wall */
5690 if (element != EL_YAMYAM &&
5691 element != EL_DARK_YAMYAM &&
5692 element != EL_PACMAN &&
5693 !(move_pattern & MV_ANY_DIRECTION) &&
5694 move_pattern != MV_TURNING_LEFT &&
5695 move_pattern != MV_TURNING_RIGHT &&
5696 move_pattern != MV_TURNING_LEFT_RIGHT &&
5697 move_pattern != MV_TURNING_RIGHT_LEFT &&
5698 move_pattern != MV_TURNING_RANDOM)
5703 if (FrameCounter < 1 && x == 0 && y == 29)
5704 printf(":9: %d: %d [%d]\n", y, MovDir[x][y], FrameCounter);
5707 if (MovDelay[x][y] && (element == EL_BUG ||
5708 element == EL_SPACESHIP ||
5709 element == EL_SP_SNIKSNAK ||
5710 element == EL_SP_ELECTRON ||
5711 element == EL_MOLE))
5712 DrawLevelField(x, y);
5716 if (MovDelay[x][y]) /* wait some time before next movement */
5721 if (element == EL_YAMYAM)
5724 el_act_dir2img(EL_YAMYAM, ACTION_WAITING, MV_LEFT));
5725 DrawLevelElementAnimation(x, y, element);
5729 if (MovDelay[x][y]) /* element still has to wait some time */
5732 /* !!! PLACE THIS SOMEWHERE AFTER "TurnRound()" !!! */
5733 ResetGfxAnimation(x, y);
5737 if (GfxAction[x][y] != ACTION_WAITING)
5738 printf("::: %d: %d != ACTION_WAITING\n", element, GfxAction[x][y]);
5740 GfxAction[x][y] = ACTION_WAITING;
5744 if (element == EL_ROBOT ||
5746 element == EL_PACMAN ||
5748 element == EL_YAMYAM ||
5749 element == EL_DARK_YAMYAM)
5752 DrawLevelElementAnimation(x, y, element);
5754 DrawLevelElementAnimationIfNeeded(x, y, element);
5756 PlayLevelSoundAction(x, y, ACTION_WAITING);
5758 else if (element == EL_SP_ELECTRON)
5759 DrawLevelElementAnimationIfNeeded(x, y, element);
5760 else if (element == EL_DRAGON)
5763 int dir = MovDir[x][y];
5764 int dx = (dir == MV_LEFT ? -1 : dir == MV_RIGHT ? +1 : 0);
5765 int dy = (dir == MV_UP ? -1 : dir == MV_DOWN ? +1 : 0);
5766 int graphic = (dir == MV_LEFT ? IMG_FLAMES_1_LEFT :
5767 dir == MV_RIGHT ? IMG_FLAMES_1_RIGHT :
5768 dir == MV_UP ? IMG_FLAMES_1_UP :
5769 dir == MV_DOWN ? IMG_FLAMES_1_DOWN : IMG_EMPTY);
5770 int frame = getGraphicAnimationFrame(graphic, GfxFrame[x][y]);
5773 printf("::: %d, %d\n", GfxAction[x][y], GfxFrame[x][y]);
5776 GfxAction[x][y] = ACTION_ATTACKING;
5778 if (IS_PLAYER(x, y))
5779 DrawPlayerField(x, y);
5781 DrawLevelField(x, y);
5783 PlayLevelSoundActionIfLoop(x, y, ACTION_ATTACKING);
5785 for (i = 1; i <= 3; i++)
5787 int xx = x + i * dx;
5788 int yy = y + i * dy;
5789 int sx = SCREENX(xx);
5790 int sy = SCREENY(yy);
5791 int flame_graphic = graphic + (i - 1);
5793 if (!IN_LEV_FIELD(xx, yy) || IS_DRAGONFIRE_PROOF(Feld[xx][yy]))
5798 int flamed = MovingOrBlocked2Element(xx, yy);
5802 if (IS_CLASSIC_ENEMY(flamed) || CAN_EXPLODE_BY_DRAGONFIRE(flamed))
5804 else if (IS_MOVING(xx, yy) || IS_BLOCKED(xx, yy))
5805 RemoveMovingField(xx, yy);
5807 RemoveField(xx, yy);
5809 if (IS_CLASSIC_ENEMY(flamed) || CAN_EXPLODE_BY_DRAGONFIRE(flamed))
5812 RemoveMovingField(xx, yy);
5816 if (ChangeDelay[xx][yy])
5817 printf("::: !!! [%d]\n", (IS_MOVING(xx, yy) ||
5818 Feld[xx][yy] == EL_BLOCKED));
5822 ChangeDelay[xx][yy] = 0;
5824 Feld[xx][yy] = EL_FLAMES;
5825 if (IN_SCR_FIELD(sx, sy))
5827 DrawLevelFieldCrumbledSand(xx, yy);
5828 DrawGraphic(sx, sy, flame_graphic, frame);
5833 if (Feld[xx][yy] == EL_FLAMES)
5834 Feld[xx][yy] = EL_EMPTY;
5835 DrawLevelField(xx, yy);
5840 if (MovDelay[x][y]) /* element still has to wait some time */
5842 PlayLevelSoundAction(x, y, ACTION_WAITING);
5848 /* special case of "moving" animation of waiting elements (FIX THIS !!!);
5849 for all other elements GfxAction will be set by InitMovingField() */
5850 if (element == EL_BD_BUTTERFLY || element == EL_BD_FIREFLY)
5851 GfxAction[x][y] = ACTION_MOVING;
5855 /* now make next step */
5857 Moving2Blocked(x, y, &newx, &newy); /* get next screen position */
5859 if (DONT_COLLIDE_WITH(element) &&
5860 IN_LEV_FIELD(newx, newy) && IS_PLAYER(newx, newy) &&
5861 !PLAYER_ENEMY_PROTECTED(newx, newy))
5864 TestIfBadThingRunsIntoHero(x, y, MovDir[x][y]);
5868 /* player killed by element which is deadly when colliding with */
5870 KillHero(PLAYERINFO(newx, newy));
5877 else if (CAN_MOVE_INTO_ACID(element) &&
5878 IN_LEV_FIELD(newx, newy) && Feld[newx][newy] == EL_ACID &&
5879 (MovDir[x][y] == MV_DOWN ||
5880 game.engine_version >= VERSION_IDENT(3,1,0,0)))
5882 else if (CAN_MOVE_INTO_ACID(element) && MovDir[x][y] == MV_DOWN &&
5883 IN_LEV_FIELD(newx, newy) && Feld[newx][newy] == EL_ACID)
5887 else if ((element == EL_PENGUIN ||
5888 element == EL_ROBOT ||
5889 element == EL_SATELLITE ||
5890 element == EL_BALLOON ||
5891 IS_CUSTOM_ELEMENT(element)) &&
5892 IN_LEV_FIELD(newx, newy) &&
5893 MovDir[x][y] == MV_DOWN && Feld[newx][newy] == EL_ACID)
5896 SplashAcid(newx, newy);
5897 Store[x][y] = EL_ACID;
5899 else if (element == EL_PENGUIN && IN_LEV_FIELD(newx, newy))
5901 if (Feld[newx][newy] == EL_EXIT_OPEN)
5905 DrawLevelField(x, y);
5907 Feld[x][y] = EL_EMPTY;
5908 DrawLevelField(x, y);
5911 PlayLevelSound(newx, newy, SND_PENGUIN_PASSING);
5912 if (IN_SCR_FIELD(SCREENX(newx), SCREENY(newy)))
5913 DrawGraphicThruMask(SCREENX(newx),SCREENY(newy), el2img(element), 0);
5915 local_player->friends_still_needed--;
5916 if (!local_player->friends_still_needed &&
5917 !local_player->GameOver && AllPlayersGone)
5918 local_player->LevelSolved = local_player->GameOver = TRUE;
5922 else if (IS_FOOD_PENGUIN(Feld[newx][newy]))
5924 if (DigField(local_player, x, y, newx, newy, 0,0, DF_DIG) == MF_MOVING)
5925 DrawLevelField(newx, newy);
5927 GfxDir[x][y] = MovDir[x][y] = MV_NO_MOVING;
5929 else if (!IS_FREE(newx, newy))
5931 GfxAction[x][y] = ACTION_WAITING;
5933 if (IS_PLAYER(x, y))
5934 DrawPlayerField(x, y);
5936 DrawLevelField(x, y);
5941 else if (element == EL_PIG && IN_LEV_FIELD(newx, newy))
5943 if (IS_FOOD_PIG(Feld[newx][newy]))
5945 if (IS_MOVING(newx, newy))
5946 RemoveMovingField(newx, newy);
5949 Feld[newx][newy] = EL_EMPTY;
5950 DrawLevelField(newx, newy);
5953 PlayLevelSound(x, y, SND_PIG_DIGGING);
5955 else if (!IS_FREE(newx, newy))
5957 if (IS_PLAYER(x, y))
5958 DrawPlayerField(x, y);
5960 DrawLevelField(x, y);
5969 else if (move_pattern & MV_MAZE_RUNNER_STYLE && IN_LEV_FIELD(newx, newy))
5972 else if (IS_CUSTOM_ELEMENT(element) &&
5973 CUSTOM_ELEMENT_CAN_ENTER_FIELD(element, newx, newy)
5977 !IS_FREE(newx, newy)
5982 int new_element = Feld[newx][newy];
5985 printf("::: '%s' digs '%s' [%d]\n",
5986 element_info[element].token_name,
5987 element_info[Feld[newx][newy]].token_name,
5988 StorePlayer[newx][newy]);
5991 if (!IS_FREE(newx, newy))
5993 int action = (IS_DIGGABLE(new_element) ? ACTION_DIGGING :
5994 IS_COLLECTIBLE(new_element) ? ACTION_COLLECTING :
5997 /* no element can dig solid indestructible elements */
5998 if (IS_INDESTRUCTIBLE(new_element) &&
5999 !IS_DIGGABLE(new_element) &&
6000 !IS_COLLECTIBLE(new_element))
6003 if (AmoebaNr[newx][newy] &&
6004 (new_element == EL_AMOEBA_FULL ||
6005 new_element == EL_BD_AMOEBA ||
6006 new_element == EL_AMOEBA_GROWING))
6008 AmoebaCnt[AmoebaNr[newx][newy]]--;
6009 AmoebaCnt2[AmoebaNr[newx][newy]]--;
6012 if (IS_MOVING(newx, newy))
6013 RemoveMovingField(newx, newy);
6016 RemoveField(newx, newy);
6017 DrawLevelField(newx, newy);
6020 /* if digged element was about to explode, prevent the explosion */
6021 ExplodeField[newx][newy] = EX_TYPE_NONE;
6023 PlayLevelSoundAction(x, y, action);
6028 Store[newx][newy] = EL_EMPTY;
6029 if (IS_EQUAL_OR_IN_GROUP(new_element, MOVE_ENTER_EL(element)))
6030 Store[newx][newy] = element_info[element].move_leave_element;
6032 Store[newx][newy] = EL_EMPTY;
6033 if (IS_EQUAL_OR_IN_GROUP(new_element, MOVE_ENTER_EL(element)) ||
6034 element_info[element].move_leave_type == LEAVE_TYPE_UNLIMITED)
6035 Store[newx][newy] = element_info[element].move_leave_element;
6038 if (IS_EQUAL_OR_IN_GROUP(new_element, MOVE_ENTER_EL(element)))
6039 element_info[element].can_leave_element = TRUE;
6042 if (move_pattern & MV_MAZE_RUNNER_STYLE)
6044 RunnerVisit[x][y] = FrameCounter;
6045 PlayerVisit[x][y] /= 8; /* expire player visit path */
6051 else if (element == EL_DRAGON && IN_LEV_FIELD(newx, newy))
6053 if (!IS_FREE(newx, newy))
6055 if (IS_PLAYER(x, y))
6056 DrawPlayerField(x, y);
6058 DrawLevelField(x, y);
6064 boolean wanna_flame = !RND(10);
6065 int dx = newx - x, dy = newy - y;
6066 int newx1 = newx + 1 * dx, newy1 = newy + 1 * dy;
6067 int newx2 = newx + 2 * dx, newy2 = newy + 2 * dy;
6068 int element1 = (IN_LEV_FIELD(newx1, newy1) ?
6069 MovingOrBlocked2Element(newx1, newy1) : EL_STEELWALL);
6070 int element2 = (IN_LEV_FIELD(newx2, newy2) ?
6071 MovingOrBlocked2Element(newx2, newy2) : EL_STEELWALL);
6074 IS_CLASSIC_ENEMY(element1) ||
6075 IS_CLASSIC_ENEMY(element2)) &&
6076 element1 != EL_DRAGON && element2 != EL_DRAGON &&
6077 element1 != EL_FLAMES && element2 != EL_FLAMES)
6080 ResetGfxAnimation(x, y);
6081 GfxAction[x][y] = ACTION_ATTACKING;
6084 if (IS_PLAYER(x, y))
6085 DrawPlayerField(x, y);
6087 DrawLevelField(x, y);
6089 PlayLevelSound(x, y, SND_DRAGON_ATTACKING);
6091 MovDelay[x][y] = 50;
6095 RemoveField(newx, newy);
6097 Feld[newx][newy] = EL_FLAMES;
6098 if (IN_LEV_FIELD(newx1, newy1) && Feld[newx1][newy1] == EL_EMPTY)
6101 RemoveField(newx1, newy1);
6103 Feld[newx1][newy1] = EL_FLAMES;
6105 if (IN_LEV_FIELD(newx2, newy2) && Feld[newx2][newy2] == EL_EMPTY)
6108 RemoveField(newx2, newy2);
6110 Feld[newx2][newy2] = EL_FLAMES;
6117 else if (element == EL_YAMYAM && IN_LEV_FIELD(newx, newy) &&
6118 Feld[newx][newy] == EL_DIAMOND)
6120 if (IS_MOVING(newx, newy))
6121 RemoveMovingField(newx, newy);
6124 Feld[newx][newy] = EL_EMPTY;
6125 DrawLevelField(newx, newy);
6128 PlayLevelSound(x, y, SND_YAMYAM_DIGGING);
6130 else if (element == EL_DARK_YAMYAM && IN_LEV_FIELD(newx, newy) &&
6131 IS_FOOD_DARK_YAMYAM(Feld[newx][newy]))
6133 if (AmoebaNr[newx][newy])
6135 AmoebaCnt2[AmoebaNr[newx][newy]]--;
6136 if (Feld[newx][newy] == EL_AMOEBA_FULL ||
6137 Feld[newx][newy] == EL_BD_AMOEBA)
6138 AmoebaCnt[AmoebaNr[newx][newy]]--;
6143 if (IS_MOVING(newx, newy) || IS_BLOCKED(newx, newy))
6145 if (IS_MOVING(newx, newy))
6148 RemoveMovingField(newx, newy);
6152 Feld[newx][newy] = EL_EMPTY;
6153 DrawLevelField(newx, newy);
6156 PlayLevelSound(x, y, SND_DARK_YAMYAM_DIGGING);
6158 else if ((element == EL_PACMAN || element == EL_MOLE)
6159 && IN_LEV_FIELD(newx, newy) && IS_AMOEBOID(Feld[newx][newy]))
6161 if (AmoebaNr[newx][newy])
6163 AmoebaCnt2[AmoebaNr[newx][newy]]--;
6164 if (Feld[newx][newy] == EL_AMOEBA_FULL ||
6165 Feld[newx][newy] == EL_BD_AMOEBA)
6166 AmoebaCnt[AmoebaNr[newx][newy]]--;
6169 if (element == EL_MOLE)
6171 Feld[newx][newy] = EL_AMOEBA_SHRINKING;
6172 PlayLevelSound(x, y, SND_MOLE_DIGGING);
6174 ResetGfxAnimation(x, y);
6175 GfxAction[x][y] = ACTION_DIGGING;
6176 DrawLevelField(x, y);
6178 MovDelay[newx][newy] = 0; /* start amoeba shrinking delay */
6180 return; /* wait for shrinking amoeba */
6182 else /* element == EL_PACMAN */
6184 Feld[newx][newy] = EL_EMPTY;
6185 DrawLevelField(newx, newy);
6186 PlayLevelSound(x, y, SND_PACMAN_DIGGING);
6189 else if (element == EL_MOLE && IN_LEV_FIELD(newx, newy) &&
6190 (Feld[newx][newy] == EL_AMOEBA_SHRINKING ||
6191 (Feld[newx][newy] == EL_EMPTY && Stop[newx][newy])))
6193 /* wait for shrinking amoeba to completely disappear */
6196 else if (!IN_LEV_FIELD(newx, newy) || !IS_FREE(newx, newy))
6198 /* object was running against a wall */
6203 if (move_pattern & MV_ANY_DIRECTION &&
6204 move_pattern == MovDir[x][y])
6206 int blocking_element =
6207 (IN_LEV_FIELD(newx, newy) ? Feld[newx][newy] : BorderElement);
6210 printf("::: '%s' is blocked by '%s'! [%d,%d -> %d,%d]\n",
6211 element_info[element].token_name,
6212 element_info[blocking_element].token_name,
6216 CheckElementChangeBySide(x, y, element, blocking_element, CE_BLOCKED,
6219 element = Feld[x][y]; /* element might have changed */
6224 if (GFX_ELEMENT(element) != EL_SAND) /* !!! FIX THIS (crumble) !!! */
6225 DrawLevelElementAnimation(x, y, element);
6227 if (element == EL_BUG ||
6228 element == EL_SPACESHIP ||
6229 element == EL_SP_SNIKSNAK)
6230 DrawLevelField(x, y);
6231 else if (element == EL_MOLE)
6232 DrawLevelField(x, y);
6233 else if (element == EL_BD_BUTTERFLY ||
6234 element == EL_BD_FIREFLY)
6235 DrawLevelElementAnimationIfNeeded(x, y, element);
6236 else if (element == EL_SATELLITE)
6237 DrawLevelElementAnimationIfNeeded(x, y, element);
6238 else if (element == EL_SP_ELECTRON)
6239 DrawLevelElementAnimationIfNeeded(x, y, element);
6242 if (DONT_TOUCH(element))
6243 TestIfBadThingTouchesHero(x, y);
6246 PlayLevelSoundAction(x, y, ACTION_WAITING);
6252 InitMovingField(x, y, MovDir[x][y]);
6254 PlayLevelSoundAction(x, y, ACTION_MOVING);
6258 ContinueMoving(x, y);
6261 void ContinueMoving(int x, int y)
6263 int element = Feld[x][y];
6264 int stored = Store[x][y];
6265 struct ElementInfo *ei = &element_info[element];
6266 int direction = MovDir[x][y];
6267 int dx = (direction == MV_LEFT ? -1 : direction == MV_RIGHT ? +1 : 0);
6268 int dy = (direction == MV_UP ? -1 : direction == MV_DOWN ? +1 : 0);
6269 int newx = x + dx, newy = y + dy;
6271 int nextx = newx + dx, nexty = newy + dy;
6274 boolean pushed_by_player = (Pushed[x][y] && IS_PLAYER(x, y));
6275 boolean pushed_by_conveyor = (Pushed[x][y] && !IS_PLAYER(x, y));
6277 boolean pushed_by_player = Pushed[x][y];
6280 MovPos[x][y] += getElementMoveStepsize(x, y);
6283 if (pushed_by_player && IS_PLAYER(x, y))
6285 /* special case: moving object pushed by player */
6286 MovPos[x][y] = SIGN(MovPos[x][y]) * (TILEX - ABS(PLAYERINFO(x,y)->MovPos));
6289 if (pushed_by_player) /* special case: moving object pushed by player */
6290 MovPos[x][y] = SIGN(MovPos[x][y]) * (TILEX - ABS(PLAYERINFO(x,y)->MovPos));
6293 if (ABS(MovPos[x][y]) < TILEX)
6295 DrawLevelField(x, y);
6297 return; /* element is still moving */
6300 /* element reached destination field */
6302 Feld[x][y] = EL_EMPTY;
6303 Feld[newx][newy] = element;
6304 MovPos[x][y] = 0; /* force "not moving" for "crumbled sand" */
6307 if (Store[x][y] == EL_ACID) /* element is moving into acid pool */
6309 element = Feld[newx][newy] = EL_ACID;
6312 else if (element == EL_MOLE)
6314 Feld[x][y] = EL_SAND;
6316 DrawLevelFieldCrumbledSandNeighbours(x, y);
6318 else if (element == EL_QUICKSAND_FILLING)
6320 element = Feld[newx][newy] = get_next_element(element);
6321 Store[newx][newy] = Store[x][y];
6323 else if (element == EL_QUICKSAND_EMPTYING)
6325 Feld[x][y] = get_next_element(element);
6326 element = Feld[newx][newy] = Store[x][y];
6328 else if (element == EL_MAGIC_WALL_FILLING)
6330 element = Feld[newx][newy] = get_next_element(element);
6331 if (!game.magic_wall_active)
6332 element = Feld[newx][newy] = EL_MAGIC_WALL_DEAD;
6333 Store[newx][newy] = Store[x][y];
6335 else if (element == EL_MAGIC_WALL_EMPTYING)
6337 Feld[x][y] = get_next_element(element);
6338 if (!game.magic_wall_active)
6339 Feld[x][y] = EL_MAGIC_WALL_DEAD;
6340 element = Feld[newx][newy] = Store[x][y];
6342 else if (element == EL_BD_MAGIC_WALL_FILLING)
6344 element = Feld[newx][newy] = get_next_element(element);
6345 if (!game.magic_wall_active)
6346 element = Feld[newx][newy] = EL_BD_MAGIC_WALL_DEAD;
6347 Store[newx][newy] = Store[x][y];
6349 else if (element == EL_BD_MAGIC_WALL_EMPTYING)
6351 Feld[x][y] = get_next_element(element);
6352 if (!game.magic_wall_active)
6353 Feld[x][y] = EL_BD_MAGIC_WALL_DEAD;
6354 element = Feld[newx][newy] = Store[x][y];
6356 else if (element == EL_AMOEBA_DROPPING)
6358 Feld[x][y] = get_next_element(element);
6359 element = Feld[newx][newy] = Store[x][y];
6361 else if (element == EL_SOKOBAN_OBJECT)
6364 Feld[x][y] = Back[x][y];
6366 if (Back[newx][newy])
6367 Feld[newx][newy] = EL_SOKOBAN_FIELD_FULL;
6369 Back[x][y] = Back[newx][newy] = 0;
6372 else if (Store[x][y] == EL_ACID)
6374 element = Feld[newx][newy] = EL_ACID;
6378 else if (IS_CUSTOM_ELEMENT(element) && !IS_PLAYER(x, y) &&
6379 ei->move_leave_element != EL_EMPTY &&
6380 (ei->move_leave_type == LEAVE_TYPE_UNLIMITED ||
6381 Store[x][y] != EL_EMPTY))
6383 /* some elements can leave other elements behind after moving */
6385 Feld[x][y] = ei->move_leave_element;
6386 InitField(x, y, FALSE);
6388 if (GFX_CRUMBLED(Feld[x][y]))
6389 DrawLevelFieldCrumbledSandNeighbours(x, y);
6393 Store[x][y] = EL_EMPTY;
6394 MovPos[x][y] = MovDir[x][y] = MovDelay[x][y] = 0;
6395 MovDelay[newx][newy] = 0;
6397 if (CAN_CHANGE(element))
6399 /* copy element change control values to new field */
6400 ChangeDelay[newx][newy] = ChangeDelay[x][y];
6401 ChangePage[newx][newy] = ChangePage[x][y];
6402 Changed[newx][newy] = Changed[x][y];
6403 ChangeEvent[newx][newy] = ChangeEvent[x][y];
6406 ChangeDelay[x][y] = 0;
6407 ChangePage[x][y] = -1;
6408 Changed[x][y] = CE_BITMASK_DEFAULT;
6409 ChangeEvent[x][y] = CE_BITMASK_DEFAULT;
6411 /* copy animation control values to new field */
6412 GfxFrame[newx][newy] = GfxFrame[x][y];
6413 GfxRandom[newx][newy] = GfxRandom[x][y]; /* keep same random value */
6414 GfxAction[newx][newy] = GfxAction[x][y]; /* keep action one frame */
6415 GfxDir[newx][newy] = GfxDir[x][y]; /* keep element direction */
6417 Pushed[x][y] = Pushed[newx][newy] = FALSE;
6419 ResetGfxAnimation(x, y); /* reset animation values for old field */
6422 /* some elements can leave other elements behind after moving */
6424 if (IS_CUSTOM_ELEMENT(element) && ei->move_leave_element != EL_EMPTY &&
6425 (ei->move_leave_type == LEAVE_TYPE_UNLIMITED || stored != EL_EMPTY) &&
6426 (!IS_PLAYER(x, y) || IS_WALKABLE(ei->move_leave_element)))
6428 if (IS_CUSTOM_ELEMENT(element) && ei->move_leave_element != EL_EMPTY &&
6429 (ei->move_leave_type == LEAVE_TYPE_UNLIMITED || stored != EL_EMPTY) &&
6433 int move_leave_element = ei->move_leave_element;
6435 Feld[x][y] = move_leave_element;
6436 InitField(x, y, FALSE);
6438 if (GFX_CRUMBLED(Feld[x][y]))
6439 DrawLevelFieldCrumbledSandNeighbours(x, y);
6441 if (ELEM_IS_PLAYER(move_leave_element))
6442 RelocatePlayer(x, y, move_leave_element);
6447 /* some elements can leave other elements behind after moving */
6448 if (IS_CUSTOM_ELEMENT(element) && !IS_PLAYER(x, y) &&
6449 ei->move_leave_element != EL_EMPTY &&
6450 (ei->move_leave_type == LEAVE_TYPE_UNLIMITED ||
6451 ei->can_leave_element_last))
6453 Feld[x][y] = ei->move_leave_element;
6454 InitField(x, y, FALSE);
6456 if (GFX_CRUMBLED(Feld[x][y]))
6457 DrawLevelFieldCrumbledSandNeighbours(x, y);
6460 ei->can_leave_element_last = ei->can_leave_element;
6461 ei->can_leave_element = FALSE;
6465 /* 2.1.1 (does not work correctly for spring) */
6466 if (!CAN_MOVE(element))
6467 MovDir[newx][newy] = 0;
6471 /* (does not work for falling objects that slide horizontally) */
6472 if (CAN_FALL(element) && MovDir[newx][newy] == MV_DOWN)
6473 MovDir[newx][newy] = 0;
6476 if (!CAN_MOVE(element) ||
6477 (element == EL_SPRING && MovDir[newx][newy] == MV_DOWN))
6478 MovDir[newx][newy] = 0;
6482 if (!CAN_MOVE(element) ||
6483 (CAN_FALL(element) && direction == MV_DOWN))
6484 GfxDir[x][y] = MovDir[newx][newy] = 0;
6486 if (!CAN_MOVE(element) ||
6487 (CAN_FALL(element) && direction == MV_DOWN &&
6488 (element == EL_SPRING ||
6489 element_info[element].move_pattern == MV_WHEN_PUSHED ||
6490 element_info[element].move_pattern == MV_WHEN_DROPPED)))
6491 GfxDir[x][y] = MovDir[newx][newy] = 0;
6497 DrawLevelField(x, y);
6498 DrawLevelField(newx, newy);
6500 Stop[newx][newy] = TRUE; /* ignore this element until the next frame */
6502 /* prevent pushed element from moving on in pushed direction */
6503 if (pushed_by_player && CAN_MOVE(element) &&
6504 element_info[element].move_pattern & MV_ANY_DIRECTION &&
6505 !(element_info[element].move_pattern & direction))
6506 TurnRound(newx, newy);
6509 /* prevent elements on conveyor belt from moving on in last direction */
6510 if (pushed_by_conveyor && CAN_FALL(element) &&
6511 direction & MV_HORIZONTAL)
6514 if (CAN_MOVE(element))
6515 InitMovDir(newx, newy);
6517 MovDir[newx][newy] = 0;
6519 MovDir[newx][newy] = 0;
6524 if (!pushed_by_player)
6526 int nextx = newx + dx, nexty = newy + dy;
6527 boolean check_collision_again = IN_LEV_FIELD_AND_IS_FREE(nextx, nexty);
6529 WasJustMoving[newx][newy] = 3;
6531 if (CAN_FALL(element) && direction == MV_DOWN)
6532 WasJustFalling[newx][newy] = 3;
6534 if ((!CAN_FALL(element) || direction == MV_DOWN) && check_collision_again)
6535 CheckCollision[newx][newy] = 2;
6538 if (DONT_TOUCH(element)) /* object may be nasty to player or others */
6540 TestIfBadThingTouchesHero(newx, newy);
6541 TestIfBadThingTouchesFriend(newx, newy);
6543 if (!IS_CUSTOM_ELEMENT(element))
6544 TestIfBadThingTouchesOtherBadThing(newx, newy);
6546 else if (element == EL_PENGUIN)
6547 TestIfFriendTouchesBadThing(newx, newy);
6549 #if USE_NEW_MOVE_STYLE
6551 if (CAN_FALL(element) && direction == MV_DOWN &&
6552 (newy == lev_fieldy - 1 || !IS_FREE(x, newy + 1)) &&
6553 IS_PLAYER(x, newy + 1))
6554 printf("::: we would now kill the player [%d]\n", FrameCounter);
6557 /* give the player one last chance (one more frame) to move away */
6558 if (CAN_FALL(element) && direction == MV_DOWN &&
6559 (newy == lev_fieldy - 1 || !IS_FREE(x, newy + 1)) &&
6560 (!IS_PLAYER(x, newy + 1) ||
6561 game.engine_version < VERSION_IDENT(3,1,1,0)))
6564 if (CAN_FALL(element) && direction == MV_DOWN &&
6565 (newy == lev_fieldy - 1 || !IS_FREE(x, newy + 1)))
6573 if (pushed_by_player && !game.use_bug_change_when_pushing)
6575 if (pushed_by_player && game.engine_version >= VERSION_IDENT(3,1,0,0))
6578 if (pushed_by_player)
6583 int dig_side = MV_DIR_OPPOSITE(direction);
6585 static int trigger_sides[4] =
6587 CH_SIDE_RIGHT, /* moving left */
6588 CH_SIDE_LEFT, /* moving right */
6589 CH_SIDE_BOTTOM, /* moving up */
6590 CH_SIDE_TOP, /* moving down */
6592 int dig_side = trigger_sides[MV_DIR_BIT(direction)];
6594 struct PlayerInfo *player = PLAYERINFO(x, y);
6596 CheckElementChangeByPlayer(newx, newy, element, CE_PUSHED_BY_PLAYER,
6597 player->index_bit, dig_side);
6598 CheckTriggeredElementChangeByPlayer(newx,newy,element,CE_OTHER_GETS_PUSHED,
6599 player->index_bit, dig_side);
6604 TestIfElementTouchesCustomElement(x, y); /* empty or new element */
6608 if (ChangePage[newx][newy] != -1) /* delayed change */
6609 ChangeElement(newx, newy, ChangePage[newx][newy]);
6614 TestIfElementHitsCustomElement(newx, newy, direction);
6618 if (!IN_LEV_FIELD(nextx, nexty) || !IS_FREE(nextx, nexty))
6620 int hitting_element = Feld[newx][newy];
6622 /* !!! fix side (direction) orientation here and elsewhere !!! */
6623 CheckElementChangeBySide(newx, newy, hitting_element, CE_HITTING_SOMETHING,
6627 if (IN_LEV_FIELD(nextx, nexty))
6629 int opposite_direction = MV_DIR_OPPOSITE(direction);
6630 int hitting_side = direction;
6631 int touched_side = opposite_direction;
6632 int touched_element = MovingOrBlocked2Element(nextx, nexty);
6633 boolean object_hit = (!IS_MOVING(nextx, nexty) ||
6634 MovDir[nextx][nexty] != direction ||
6635 ABS(MovPos[nextx][nexty]) <= TILEY / 2);
6641 CheckElementChangeBySide(nextx, nexty, touched_element,
6642 CE_HIT_BY_SOMETHING, opposite_direction);
6644 if (IS_CUSTOM_ELEMENT(hitting_element) &&
6645 HAS_ANY_CHANGE_EVENT(hitting_element, CE_OTHER_IS_HITTING))
6647 for (i = 0; i < element_info[hitting_element].num_change_pages; i++)
6649 struct ElementChangeInfo *change =
6650 &element_info[hitting_element].change_page[i];
6652 if (change->can_change &&
6653 change->events & CH_EVENT_BIT(CE_OTHER_IS_HITTING) &&
6654 change->trigger_side & touched_side &&
6655 change->trigger_element == touched_element)
6657 CheckElementChangeByPage(newx, newy, hitting_element,
6658 touched_element, CE_OTHER_IS_HITTING,i);
6664 if (IS_CUSTOM_ELEMENT(touched_element) &&
6665 HAS_ANY_CHANGE_EVENT(touched_element, CE_OTHER_GETS_HIT))
6667 for (i = 0; i < element_info[touched_element].num_change_pages; i++)
6669 struct ElementChangeInfo *change =
6670 &element_info[touched_element].change_page[i];
6672 if (change->can_change &&
6673 change->events & CH_EVENT_BIT(CE_OTHER_GETS_HIT) &&
6674 change->trigger_side & hitting_side &&
6675 change->trigger_element == hitting_element)
6677 CheckElementChangeByPage(nextx, nexty, touched_element,
6678 hitting_element, CE_OTHER_GETS_HIT, i);
6689 TestIfPlayerTouchesCustomElement(newx, newy);
6690 TestIfElementTouchesCustomElement(newx, newy);
6693 int AmoebeNachbarNr(int ax, int ay)
6696 int element = Feld[ax][ay];
6698 static int xy[4][2] =
6706 for (i = 0; i < NUM_DIRECTIONS; i++)
6708 int x = ax + xy[i][0];
6709 int y = ay + xy[i][1];
6711 if (!IN_LEV_FIELD(x, y))
6714 if (Feld[x][y] == element && AmoebaNr[x][y] > 0)
6715 group_nr = AmoebaNr[x][y];
6721 void AmoebenVereinigen(int ax, int ay)
6723 int i, x, y, xx, yy;
6724 int new_group_nr = AmoebaNr[ax][ay];
6725 static int xy[4][2] =
6733 if (new_group_nr == 0)
6736 for (i = 0; i < NUM_DIRECTIONS; i++)
6741 if (!IN_LEV_FIELD(x, y))
6744 if ((Feld[x][y] == EL_AMOEBA_FULL ||
6745 Feld[x][y] == EL_BD_AMOEBA ||
6746 Feld[x][y] == EL_AMOEBA_DEAD) &&
6747 AmoebaNr[x][y] != new_group_nr)
6749 int old_group_nr = AmoebaNr[x][y];
6751 if (old_group_nr == 0)
6754 AmoebaCnt[new_group_nr] += AmoebaCnt[old_group_nr];
6755 AmoebaCnt[old_group_nr] = 0;
6756 AmoebaCnt2[new_group_nr] += AmoebaCnt2[old_group_nr];
6757 AmoebaCnt2[old_group_nr] = 0;
6759 for (yy = 0; yy < lev_fieldy; yy++)
6761 for (xx = 0; xx < lev_fieldx; xx++)
6763 if (AmoebaNr[xx][yy] == old_group_nr)
6764 AmoebaNr[xx][yy] = new_group_nr;
6771 void AmoebeUmwandeln(int ax, int ay)
6775 if (Feld[ax][ay] == EL_AMOEBA_DEAD)
6777 int group_nr = AmoebaNr[ax][ay];
6782 printf("AmoebeUmwandeln(): ax = %d, ay = %d\n", ax, ay);
6783 printf("AmoebeUmwandeln(): This should never happen!\n");
6788 for (y = 0; y < lev_fieldy; y++)
6790 for (x = 0; x < lev_fieldx; x++)
6792 if (Feld[x][y] == EL_AMOEBA_DEAD && AmoebaNr[x][y] == group_nr)
6795 Feld[x][y] = EL_AMOEBA_TO_DIAMOND;
6799 PlayLevelSound(ax, ay, (IS_GEM(level.amoeba_content) ?
6800 SND_AMOEBA_TURNING_TO_GEM :
6801 SND_AMOEBA_TURNING_TO_ROCK));
6806 static int xy[4][2] =
6814 for (i = 0; i < NUM_DIRECTIONS; i++)
6819 if (!IN_LEV_FIELD(x, y))
6822 if (Feld[x][y] == EL_AMOEBA_TO_DIAMOND)
6824 PlayLevelSound(x, y, (IS_GEM(level.amoeba_content) ?
6825 SND_AMOEBA_TURNING_TO_GEM :
6826 SND_AMOEBA_TURNING_TO_ROCK));
6833 void AmoebeUmwandelnBD(int ax, int ay, int new_element)
6836 int group_nr = AmoebaNr[ax][ay];
6837 boolean done = FALSE;
6842 printf("AmoebeUmwandelnBD(): ax = %d, ay = %d\n", ax, ay);
6843 printf("AmoebeUmwandelnBD(): This should never happen!\n");
6848 for (y = 0; y < lev_fieldy; y++)
6850 for (x = 0; x < lev_fieldx; x++)
6852 if (AmoebaNr[x][y] == group_nr &&
6853 (Feld[x][y] == EL_AMOEBA_DEAD ||
6854 Feld[x][y] == EL_BD_AMOEBA ||
6855 Feld[x][y] == EL_AMOEBA_GROWING))
6858 Feld[x][y] = new_element;
6859 InitField(x, y, FALSE);
6860 DrawLevelField(x, y);
6867 PlayLevelSound(ax, ay, (new_element == EL_BD_ROCK ?
6868 SND_BD_AMOEBA_TURNING_TO_ROCK :
6869 SND_BD_AMOEBA_TURNING_TO_GEM));
6872 void AmoebeWaechst(int x, int y)
6874 static unsigned long sound_delay = 0;
6875 static unsigned long sound_delay_value = 0;
6877 if (!MovDelay[x][y]) /* start new growing cycle */
6881 if (DelayReached(&sound_delay, sound_delay_value))
6884 PlayLevelSoundElementAction(x, y, Store[x][y], ACTION_GROWING);
6886 if (Store[x][y] == EL_BD_AMOEBA)
6887 PlayLevelSound(x, y, SND_BD_AMOEBA_GROWING);
6889 PlayLevelSound(x, y, SND_AMOEBA_GROWING);
6891 sound_delay_value = 30;
6895 if (MovDelay[x][y]) /* wait some time before growing bigger */
6898 if (MovDelay[x][y]/2 && IN_SCR_FIELD(SCREENX(x), SCREENY(y)))
6900 int frame = getGraphicAnimationFrame(IMG_AMOEBA_GROWING,
6901 6 - MovDelay[x][y]);
6903 DrawGraphic(SCREENX(x), SCREENY(y), IMG_AMOEBA_GROWING, frame);
6906 if (!MovDelay[x][y])
6908 Feld[x][y] = Store[x][y];
6910 DrawLevelField(x, y);
6915 void AmoebaDisappearing(int x, int y)
6917 static unsigned long sound_delay = 0;
6918 static unsigned long sound_delay_value = 0;
6920 if (!MovDelay[x][y]) /* start new shrinking cycle */
6924 if (DelayReached(&sound_delay, sound_delay_value))
6925 sound_delay_value = 30;
6928 if (MovDelay[x][y]) /* wait some time before shrinking */
6931 if (MovDelay[x][y]/2 && IN_SCR_FIELD(SCREENX(x), SCREENY(y)))
6933 int frame = getGraphicAnimationFrame(IMG_AMOEBA_SHRINKING,
6934 6 - MovDelay[x][y]);
6936 DrawGraphic(SCREENX(x), SCREENY(y), IMG_AMOEBA_SHRINKING, frame);
6939 if (!MovDelay[x][y])
6941 Feld[x][y] = EL_EMPTY;
6942 DrawLevelField(x, y);
6944 /* don't let mole enter this field in this cycle;
6945 (give priority to objects falling to this field from above) */
6951 void AmoebeAbleger(int ax, int ay)
6954 int element = Feld[ax][ay];
6955 int graphic = el2img(element);
6956 int newax = ax, neway = ay;
6957 static int xy[4][2] =
6965 if (!level.amoeba_speed)
6967 Feld[ax][ay] = EL_AMOEBA_DEAD;
6968 DrawLevelField(ax, ay);
6972 if (IS_ANIMATED(graphic))
6973 DrawLevelGraphicAnimationIfNeeded(ax, ay, graphic);
6975 if (!MovDelay[ax][ay]) /* start making new amoeba field */
6976 MovDelay[ax][ay] = RND(FRAMES_PER_SECOND * 25 / (1 + level.amoeba_speed));
6978 if (MovDelay[ax][ay]) /* wait some time before making new amoeba */
6981 if (MovDelay[ax][ay])
6985 if (element == EL_AMOEBA_WET) /* object is an acid / amoeba drop */
6988 int x = ax + xy[start][0];
6989 int y = ay + xy[start][1];
6991 if (!IN_LEV_FIELD(x, y))
6995 if (IS_FREE(x, y) ||
6996 CAN_GROW_INTO(Feld[x][y]) ||
6997 Feld[x][y] == EL_QUICKSAND_EMPTY)
7003 /* !!! extend EL_SAND to anything diggable (but maybe not SP_BASE) !!! */
7004 if (IS_FREE(x, y) ||
7005 Feld[x][y] == EL_SAND || Feld[x][y] == EL_QUICKSAND_EMPTY)
7012 if (newax == ax && neway == ay)
7015 else /* normal or "filled" (BD style) amoeba */
7018 boolean waiting_for_player = FALSE;
7020 for (i = 0; i < NUM_DIRECTIONS; i++)
7022 int j = (start + i) % 4;
7023 int x = ax + xy[j][0];
7024 int y = ay + xy[j][1];
7026 if (!IN_LEV_FIELD(x, y))
7030 if (IS_FREE(x, y) ||
7031 CAN_GROW_INTO(Feld[x][y]) ||
7032 Feld[x][y] == EL_QUICKSAND_EMPTY)
7039 /* !!! extend EL_SAND to anything diggable (but maybe not SP_BASE) !!! */
7040 if (IS_FREE(x, y) ||
7041 Feld[x][y] == EL_SAND || Feld[x][y] == EL_QUICKSAND_EMPTY)
7048 else if (IS_PLAYER(x, y))
7049 waiting_for_player = TRUE;
7052 if (newax == ax && neway == ay) /* amoeba cannot grow */
7055 if (i == 4 && (!waiting_for_player || element == EL_BD_AMOEBA))
7057 if (i == 4 && (!waiting_for_player || game.emulation == EMU_BOULDERDASH))
7060 Feld[ax][ay] = EL_AMOEBA_DEAD;
7061 DrawLevelField(ax, ay);
7062 AmoebaCnt[AmoebaNr[ax][ay]]--;
7064 if (AmoebaCnt[AmoebaNr[ax][ay]] <= 0) /* amoeba is completely dead */
7066 if (element == EL_AMOEBA_FULL)
7067 AmoebeUmwandeln(ax, ay);
7068 else if (element == EL_BD_AMOEBA)
7069 AmoebeUmwandelnBD(ax, ay, level.amoeba_content);
7074 else if (element == EL_AMOEBA_FULL || element == EL_BD_AMOEBA)
7076 /* amoeba gets larger by growing in some direction */
7078 int new_group_nr = AmoebaNr[ax][ay];
7081 if (new_group_nr == 0)
7083 printf("AmoebeAbleger(): newax = %d, neway = %d\n", newax, neway);
7084 printf("AmoebeAbleger(): This should never happen!\n");
7089 AmoebaNr[newax][neway] = new_group_nr;
7090 AmoebaCnt[new_group_nr]++;
7091 AmoebaCnt2[new_group_nr]++;
7093 /* if amoeba touches other amoeba(s) after growing, unify them */
7094 AmoebenVereinigen(newax, neway);
7096 if (element == EL_BD_AMOEBA && AmoebaCnt2[new_group_nr] >= 200)
7098 AmoebeUmwandelnBD(newax, neway, EL_BD_ROCK);
7104 if (element != EL_AMOEBA_WET || neway < ay || !IS_FREE(newax, neway) ||
7105 (neway == lev_fieldy - 1 && newax != ax))
7107 Feld[newax][neway] = EL_AMOEBA_GROWING; /* creation of new amoeba */
7108 Store[newax][neway] = element;
7110 else if (neway == ay)
7112 Feld[newax][neway] = EL_AMOEBA_DROP; /* drop left/right of amoeba */
7114 PlayLevelSoundAction(newax, neway, ACTION_GROWING);
7116 PlayLevelSound(newax, neway, SND_AMOEBA_GROWING);
7121 InitMovingField(ax, ay, MV_DOWN); /* drop dripping from amoeba */
7122 Feld[ax][ay] = EL_AMOEBA_DROPPING;
7123 Store[ax][ay] = EL_AMOEBA_DROP;
7124 ContinueMoving(ax, ay);
7128 DrawLevelField(newax, neway);
7131 void Life(int ax, int ay)
7134 static int life[4] = { 2, 3, 3, 3 }; /* parameters for "game of life" */
7136 int element = Feld[ax][ay];
7137 int graphic = el2img(element);
7138 boolean changed = FALSE;
7140 if (IS_ANIMATED(graphic))
7141 DrawLevelGraphicAnimationIfNeeded(ax, ay, graphic);
7146 if (!MovDelay[ax][ay]) /* start new "game of life" cycle */
7147 MovDelay[ax][ay] = life_time;
7149 if (MovDelay[ax][ay]) /* wait some time before next cycle */
7152 if (MovDelay[ax][ay])
7156 for (y1 = -1; y1 < 2; y1++) for (x1 = -1; x1 < 2; x1++)
7158 int xx = ax+x1, yy = ay+y1;
7161 if (!IN_LEV_FIELD(xx, yy))
7164 for (y2 = -1; y2 < 2; y2++) for (x2 = -1; x2 < 2; x2++)
7166 int x = xx+x2, y = yy+y2;
7168 if (!IN_LEV_FIELD(x, y) || (x == xx && y == yy))
7171 if (((Feld[x][y] == element ||
7172 (element == EL_GAME_OF_LIFE && IS_PLAYER(x, y))) &&
7174 (IS_FREE(x, y) && Stop[x][y]))
7178 if (xx == ax && yy == ay) /* field in the middle */
7180 if (nachbarn < life[0] || nachbarn > life[1])
7182 Feld[xx][yy] = EL_EMPTY;
7184 DrawLevelField(xx, yy);
7185 Stop[xx][yy] = TRUE;
7190 else if (IS_FREE(xx, yy) || CAN_GROW_INTO(Feld[xx][yy]))
7191 { /* free border field */
7192 if (nachbarn >= life[2] && nachbarn <= life[3])
7194 Feld[xx][yy] = element;
7195 MovDelay[xx][yy] = (element == EL_GAME_OF_LIFE ? 0 : life_time-1);
7197 DrawLevelField(xx, yy);
7198 Stop[xx][yy] = TRUE;
7203 /* !!! extend EL_SAND to anything diggable (but maybe not SP_BASE) !!! */
7204 else if (IS_FREE(xx, yy) || Feld[xx][yy] == EL_SAND)
7205 { /* free border field */
7206 if (nachbarn >= life[2] && nachbarn <= life[3])
7208 Feld[xx][yy] = element;
7209 MovDelay[xx][yy] = (element == EL_GAME_OF_LIFE ? 0 : life_time-1);
7211 DrawLevelField(xx, yy);
7212 Stop[xx][yy] = TRUE;
7220 PlayLevelSound(ax, ay, element == EL_BIOMAZE ? SND_BIOMAZE_GROWING :
7221 SND_GAME_OF_LIFE_GROWING);
7224 static void InitRobotWheel(int x, int y)
7226 ChangeDelay[x][y] = level.time_wheel * FRAMES_PER_SECOND;
7229 static void RunRobotWheel(int x, int y)
7231 PlayLevelSound(x, y, SND_ROBOT_WHEEL_ACTIVE);
7234 static void StopRobotWheel(int x, int y)
7236 if (ZX == x && ZY == y)
7240 static void InitTimegateWheel(int x, int y)
7243 ChangeDelay[x][y] = level.time_timegate * FRAMES_PER_SECOND;
7245 /* another brainless, "type style" bug ... :-( */
7246 ChangeDelay[x][y] = level.time_wheel * FRAMES_PER_SECOND;
7250 static void RunTimegateWheel(int x, int y)
7252 PlayLevelSound(x, y, SND_TIMEGATE_SWITCH_ACTIVE);
7255 void CheckExit(int x, int y)
7257 if (local_player->gems_still_needed > 0 ||
7258 local_player->sokobanfields_still_needed > 0 ||
7259 local_player->lights_still_needed > 0)
7261 int element = Feld[x][y];
7262 int graphic = el2img(element);
7264 if (IS_ANIMATED(graphic))
7265 DrawLevelGraphicAnimationIfNeeded(x, y, graphic);
7270 if (AllPlayersGone) /* do not re-open exit door closed after last player */
7273 Feld[x][y] = EL_EXIT_OPENING;
7275 PlayLevelSoundNearest(x, y, SND_CLASS_EXIT_OPENING);
7278 void CheckExitSP(int x, int y)
7280 if (local_player->gems_still_needed > 0)
7282 int element = Feld[x][y];
7283 int graphic = el2img(element);
7285 if (IS_ANIMATED(graphic))
7286 DrawLevelGraphicAnimationIfNeeded(x, y, graphic);
7291 if (AllPlayersGone) /* do not re-open exit door closed after last player */
7294 Feld[x][y] = EL_SP_EXIT_OPENING;
7296 PlayLevelSoundNearest(x, y, SND_CLASS_SP_EXIT_OPENING);
7299 static void CloseAllOpenTimegates()
7303 for (y = 0; y < lev_fieldy; y++)
7305 for (x = 0; x < lev_fieldx; x++)
7307 int element = Feld[x][y];
7309 if (element == EL_TIMEGATE_OPEN || element == EL_TIMEGATE_OPENING)
7311 Feld[x][y] = EL_TIMEGATE_CLOSING;
7313 PlayLevelSoundAction(x, y, ACTION_CLOSING);
7315 PlayLevelSound(x, y, SND_TIMEGATE_CLOSING);
7322 void EdelsteinFunkeln(int x, int y)
7324 if (!IN_SCR_FIELD(SCREENX(x), SCREENY(y)) || IS_MOVING(x, y))
7327 if (Feld[x][y] == EL_BD_DIAMOND)
7330 if (MovDelay[x][y] == 0) /* next animation frame */
7331 MovDelay[x][y] = 11 * !SimpleRND(500);
7333 if (MovDelay[x][y] != 0) /* wait some time before next frame */
7337 if (setup.direct_draw && MovDelay[x][y])
7338 SetDrawtoField(DRAW_BUFFERED);
7340 DrawLevelElementAnimation(x, y, Feld[x][y]);
7342 if (MovDelay[x][y] != 0)
7344 int frame = getGraphicAnimationFrame(IMG_TWINKLE_WHITE,
7345 10 - MovDelay[x][y]);
7347 DrawGraphicThruMask(SCREENX(x), SCREENY(y), IMG_TWINKLE_WHITE, frame);
7349 if (setup.direct_draw)
7353 dest_x = FX + SCREENX(x) * TILEX;
7354 dest_y = FY + SCREENY(y) * TILEY;
7356 BlitBitmap(drawto_field, window,
7357 dest_x, dest_y, TILEX, TILEY, dest_x, dest_y);
7358 SetDrawtoField(DRAW_DIRECT);
7364 void MauerWaechst(int x, int y)
7368 if (!MovDelay[x][y]) /* next animation frame */
7369 MovDelay[x][y] = 3 * delay;
7371 if (MovDelay[x][y]) /* wait some time before next frame */
7375 if (IN_SCR_FIELD(SCREENX(x), SCREENY(y)))
7377 int graphic = el_dir2img(Feld[x][y], GfxDir[x][y]);
7378 int frame = getGraphicAnimationFrame(graphic, 17 - MovDelay[x][y]);
7380 DrawGraphic(SCREENX(x), SCREENY(y), graphic, frame);
7383 if (!MovDelay[x][y])
7385 if (MovDir[x][y] == MV_LEFT)
7387 if (IN_LEV_FIELD(x - 1, y) && IS_WALL(Feld[x - 1][y]))
7388 DrawLevelField(x - 1, y);
7390 else if (MovDir[x][y] == MV_RIGHT)
7392 if (IN_LEV_FIELD(x + 1, y) && IS_WALL(Feld[x + 1][y]))
7393 DrawLevelField(x + 1, y);
7395 else if (MovDir[x][y] == MV_UP)
7397 if (IN_LEV_FIELD(x, y - 1) && IS_WALL(Feld[x][y - 1]))
7398 DrawLevelField(x, y - 1);
7402 if (IN_LEV_FIELD(x, y + 1) && IS_WALL(Feld[x][y + 1]))
7403 DrawLevelField(x, y + 1);
7406 Feld[x][y] = Store[x][y];
7408 GfxDir[x][y] = MovDir[x][y] = MV_NO_MOVING;
7409 DrawLevelField(x, y);
7414 void MauerAbleger(int ax, int ay)
7416 int element = Feld[ax][ay];
7417 int graphic = el2img(element);
7418 boolean oben_frei = FALSE, unten_frei = FALSE;
7419 boolean links_frei = FALSE, rechts_frei = FALSE;
7420 boolean oben_massiv = FALSE, unten_massiv = FALSE;
7421 boolean links_massiv = FALSE, rechts_massiv = FALSE;
7422 boolean new_wall = FALSE;
7424 if (IS_ANIMATED(graphic))
7425 DrawLevelGraphicAnimationIfNeeded(ax, ay, graphic);
7427 if (!MovDelay[ax][ay]) /* start building new wall */
7428 MovDelay[ax][ay] = 6;
7430 if (MovDelay[ax][ay]) /* wait some time before building new wall */
7433 if (MovDelay[ax][ay])
7437 if (IN_LEV_FIELD(ax, ay-1) && IS_FREE(ax, ay-1))
7439 if (IN_LEV_FIELD(ax, ay+1) && IS_FREE(ax, ay+1))
7441 if (IN_LEV_FIELD(ax-1, ay) && IS_FREE(ax-1, ay))
7443 if (IN_LEV_FIELD(ax+1, ay) && IS_FREE(ax+1, ay))
7446 if (element == EL_EXPANDABLE_WALL_VERTICAL ||
7447 element == EL_EXPANDABLE_WALL_ANY)
7451 Feld[ax][ay-1] = EL_EXPANDABLE_WALL_GROWING;
7452 Store[ax][ay-1] = element;
7453 GfxDir[ax][ay-1] = MovDir[ax][ay-1] = MV_UP;
7454 if (IN_SCR_FIELD(SCREENX(ax), SCREENY(ay-1)))
7455 DrawGraphic(SCREENX(ax), SCREENY(ay - 1),
7456 IMG_EXPANDABLE_WALL_GROWING_UP, 0);
7461 Feld[ax][ay+1] = EL_EXPANDABLE_WALL_GROWING;
7462 Store[ax][ay+1] = element;
7463 GfxDir[ax][ay+1] = MovDir[ax][ay+1] = MV_DOWN;
7464 if (IN_SCR_FIELD(SCREENX(ax), SCREENY(ay+1)))
7465 DrawGraphic(SCREENX(ax), SCREENY(ay + 1),
7466 IMG_EXPANDABLE_WALL_GROWING_DOWN, 0);
7471 if (element == EL_EXPANDABLE_WALL_HORIZONTAL ||
7472 element == EL_EXPANDABLE_WALL_ANY ||
7473 element == EL_EXPANDABLE_WALL)
7477 Feld[ax-1][ay] = EL_EXPANDABLE_WALL_GROWING;
7478 Store[ax-1][ay] = element;
7479 GfxDir[ax-1][ay] = MovDir[ax-1][ay] = MV_LEFT;
7480 if (IN_SCR_FIELD(SCREENX(ax-1), SCREENY(ay)))
7481 DrawGraphic(SCREENX(ax - 1), SCREENY(ay),
7482 IMG_EXPANDABLE_WALL_GROWING_LEFT, 0);
7488 Feld[ax+1][ay] = EL_EXPANDABLE_WALL_GROWING;
7489 Store[ax+1][ay] = element;
7490 GfxDir[ax+1][ay] = MovDir[ax+1][ay] = MV_RIGHT;
7491 if (IN_SCR_FIELD(SCREENX(ax+1), SCREENY(ay)))
7492 DrawGraphic(SCREENX(ax + 1), SCREENY(ay),
7493 IMG_EXPANDABLE_WALL_GROWING_RIGHT, 0);
7498 if (element == EL_EXPANDABLE_WALL && (links_frei || rechts_frei))
7499 DrawLevelField(ax, ay);
7501 if (!IN_LEV_FIELD(ax, ay-1) || IS_WALL(Feld[ax][ay-1]))
7503 if (!IN_LEV_FIELD(ax, ay+1) || IS_WALL(Feld[ax][ay+1]))
7504 unten_massiv = TRUE;
7505 if (!IN_LEV_FIELD(ax-1, ay) || IS_WALL(Feld[ax-1][ay]))
7506 links_massiv = TRUE;
7507 if (!IN_LEV_FIELD(ax+1, ay) || IS_WALL(Feld[ax+1][ay]))
7508 rechts_massiv = TRUE;
7510 if (((oben_massiv && unten_massiv) ||
7511 element == EL_EXPANDABLE_WALL_HORIZONTAL ||
7512 element == EL_EXPANDABLE_WALL) &&
7513 ((links_massiv && rechts_massiv) ||
7514 element == EL_EXPANDABLE_WALL_VERTICAL))
7515 Feld[ax][ay] = EL_WALL;
7519 PlayLevelSoundAction(ax, ay, ACTION_GROWING);
7521 PlayLevelSound(ax, ay, SND_EXPANDABLE_WALL_GROWING);
7525 void CheckForDragon(int x, int y)
7528 boolean dragon_found = FALSE;
7529 static int xy[4][2] =
7537 for (i = 0; i < NUM_DIRECTIONS; i++)
7539 for (j = 0; j < 4; j++)
7541 int xx = x + j * xy[i][0], yy = y + j * xy[i][1];
7543 if (IN_LEV_FIELD(xx, yy) &&
7544 (Feld[xx][yy] == EL_FLAMES || Feld[xx][yy] == EL_DRAGON))
7546 if (Feld[xx][yy] == EL_DRAGON)
7547 dragon_found = TRUE;
7556 for (i = 0; i < NUM_DIRECTIONS; i++)
7558 for (j = 0; j < 3; j++)
7560 int xx = x + j * xy[i][0], yy = y + j * xy[i][1];
7562 if (IN_LEV_FIELD(xx, yy) && Feld[xx][yy] == EL_FLAMES)
7564 Feld[xx][yy] = EL_EMPTY;
7565 DrawLevelField(xx, yy);
7574 static void InitBuggyBase(int x, int y)
7576 int element = Feld[x][y];
7577 int activating_delay = FRAMES_PER_SECOND / 4;
7580 (element == EL_SP_BUGGY_BASE ?
7581 2 * FRAMES_PER_SECOND + RND(5 * FRAMES_PER_SECOND) - activating_delay :
7582 element == EL_SP_BUGGY_BASE_ACTIVATING ?
7584 element == EL_SP_BUGGY_BASE_ACTIVE ?
7585 1 * FRAMES_PER_SECOND + RND(1 * FRAMES_PER_SECOND) : 1);
7588 static void WarnBuggyBase(int x, int y)
7591 static int xy[4][2] =
7599 for (i = 0; i < NUM_DIRECTIONS; i++)
7601 int xx = x + xy[i][0], yy = y + xy[i][1];
7603 if (IS_PLAYER(xx, yy))
7605 PlayLevelSound(x, y, SND_SP_BUGGY_BASE_ACTIVE);
7612 static void InitTrap(int x, int y)
7614 ChangeDelay[x][y] = 2 * FRAMES_PER_SECOND + RND(5 * FRAMES_PER_SECOND);
7617 static void ActivateTrap(int x, int y)
7619 PlayLevelSound(x, y, SND_TRAP_ACTIVATING);
7622 static void ChangeActiveTrap(int x, int y)
7624 int graphic = IMG_TRAP_ACTIVE;
7626 /* if new animation frame was drawn, correct crumbled sand border */
7627 if (IS_NEW_FRAME(GfxFrame[x][y], graphic))
7628 DrawLevelFieldCrumbledSand(x, y);
7631 static void ChangeElementNowExt(int x, int y, int target_element)
7633 int previous_move_direction = MovDir[x][y];
7635 boolean add_player = (ELEM_IS_PLAYER(target_element) &&
7636 IS_WALKABLE(Feld[x][y]));
7638 boolean add_player = (ELEM_IS_PLAYER(target_element) &&
7639 IS_WALKABLE(Feld[x][y]) &&
7643 /* check if element under player changes from accessible to unaccessible
7644 (needed for special case of dropping element which then changes) */
7645 if (IS_PLAYER(x, y) && !PLAYER_EXPLOSION_PROTECTED(x, y) &&
7646 IS_ACCESSIBLE(Feld[x][y]) && !IS_ACCESSIBLE(target_element))
7649 printf("::: BOOOM! [%d, '%s']\n", target_element,
7650 element_info[target_element].token_name);
7662 if (IS_MOVING(x, y) || IS_BLOCKED(x, y))
7663 RemoveMovingField(x, y);
7667 Feld[x][y] = target_element;
7670 Feld[x][y] = target_element;
7673 ResetGfxAnimation(x, y);
7674 ResetRandomAnimationValue(x, y);
7676 if (element_info[Feld[x][y]].move_direction_initial == MV_START_PREVIOUS)
7677 MovDir[x][y] = previous_move_direction;
7680 InitField_WithBug1(x, y, FALSE);
7682 InitField(x, y, FALSE);
7683 if (CAN_MOVE(Feld[x][y]))
7687 DrawLevelField(x, y);
7689 if (GFX_CRUMBLED(Feld[x][y]))
7690 DrawLevelFieldCrumbledSandNeighbours(x, y);
7694 Changed[x][y] |= ChangeEvent[x][y]; /* ignore same changes in this frame */
7698 TestIfBadThingTouchesHero(x, y);
7699 TestIfPlayerTouchesCustomElement(x, y);
7700 TestIfElementTouchesCustomElement(x, y);
7703 /* "Changed[][]" not set yet to allow "entered by player" change one time */
7704 if (ELEM_IS_PLAYER(target_element))
7705 RelocatePlayer(x, y, target_element);
7708 Changed[x][y] |= ChangeEvent[x][y]; /* ignore same changes in this frame */
7712 TestIfBadThingTouchesHero(x, y);
7713 TestIfPlayerTouchesCustomElement(x, y);
7714 TestIfElementTouchesCustomElement(x, y);
7718 static boolean ChangeElementNow(int x, int y, int element, int page)
7720 struct ElementChangeInfo *change = &element_info[element].change_page[page];
7722 int old_element = Feld[x][y];
7724 /* always use default change event to prevent running into a loop */
7725 if (ChangeEvent[x][y] == CE_BITMASK_DEFAULT)
7726 ChangeEvent[x][y] = CH_EVENT_BIT(CE_DELAY);
7728 if (ChangeEvent[x][y] == CH_EVENT_BIT(CE_DELAY))
7730 /* reset actual trigger element and player */
7731 change->actual_trigger_element = EL_EMPTY;
7732 change->actual_trigger_player = EL_PLAYER_1;
7735 /* do not change already changed elements with same change event */
7737 if (Changed[x][y] & ChangeEvent[x][y])
7744 Changed[x][y] |= ChangeEvent[x][y]; /* ignore same changes in this frame */
7747 /* !!! indirect change before direct change !!! */
7748 CheckTriggeredElementChangeByPage(x,y,Feld[x][y], CE_OTHER_IS_CHANGING,page);
7751 if (change->explode)
7758 if (change->use_target_content)
7760 boolean complete_replace = TRUE;
7761 boolean can_replace[3][3];
7764 for (yy = 0; yy < 3; yy++) for (xx = 0; xx < 3 ; xx++)
7767 boolean is_walkable;
7768 boolean is_diggable;
7769 boolean is_collectible;
7770 boolean is_removable;
7771 boolean is_destructible;
7772 int ex = x + xx - 1;
7773 int ey = y + yy - 1;
7774 int content_element = change->target_content[xx][yy];
7777 can_replace[xx][yy] = TRUE;
7779 if (ex == x && ey == y) /* do not check changing element itself */
7782 if (content_element == EL_EMPTY_SPACE)
7784 can_replace[xx][yy] = FALSE; /* do not replace border with space */
7789 if (!IN_LEV_FIELD(ex, ey))
7791 can_replace[xx][yy] = FALSE;
7792 complete_replace = FALSE;
7798 if (Changed[ex][ey]) /* do not change already changed elements */
7800 can_replace[xx][yy] = FALSE;
7801 complete_replace = FALSE;
7809 if (IS_MOVING(ex, ey) || IS_BLOCKED(ex, ey))
7810 e = MovingOrBlocked2Element(ex, ey);
7815 is_empty = (IS_FREE(ex, ey) ||
7816 (IS_PLAYER(ex, ey) && IS_WALKABLE(content_element)) ||
7817 (IS_WALKABLE(e) && ELEM_IS_PLAYER(content_element) &&
7818 !IS_MOVING(ex, ey) && !IS_BLOCKED(ex, ey)));
7822 is_empty = (IS_FREE(ex, ey) ||
7823 (IS_PLAYER(ex, ey) && IS_WALKABLE(content_element)));
7825 is_empty = (IS_FREE(ex, ey) ||
7826 (IS_FREE_OR_PLAYER(ex, ey) && IS_WALKABLE(content_element)));
7831 is_walkable = (is_empty || IS_WALKABLE(e));
7832 is_diggable = (is_empty || IS_DIGGABLE(e));
7833 is_collectible = (is_empty || IS_COLLECTIBLE(e));
7834 is_destructible = (is_empty || !IS_INDESTRUCTIBLE(e));
7835 is_removable = (is_diggable || is_collectible);
7837 can_replace[xx][yy] =
7838 (((change->replace_when == CP_WHEN_EMPTY && is_empty) ||
7839 (change->replace_when == CP_WHEN_WALKABLE && is_walkable) ||
7840 (change->replace_when == CP_WHEN_DIGGABLE && is_diggable) ||
7841 (change->replace_when == CP_WHEN_COLLECTIBLE && is_collectible) ||
7842 (change->replace_when == CP_WHEN_REMOVABLE && is_removable) ||
7843 (change->replace_when == CP_WHEN_DESTRUCTIBLE && is_destructible)) &&
7844 !(IS_PLAYER(ex, ey) && ELEM_IS_PLAYER(content_element)));
7846 if (!can_replace[xx][yy])
7847 complete_replace = FALSE;
7849 empty_for_element = (IS_FREE(ex, ey) || (IS_FREE_OR_PLAYER(ex, ey) &&
7850 IS_WALKABLE(content_element)));
7852 half_destructible = (empty_for_element || IS_DIGGABLE(e));
7854 half_destructible = (IS_FREE(ex, ey) || IS_DIGGABLE(e));
7857 if ((change->replace_when <= CP_WHEN_EMPTY && !empty_for_element) ||
7858 (change->replace_when <= CP_WHEN_DIGGABLE && !half_destructible) ||
7859 (change->replace_when <= CP_WHEN_DESTRUCTIBLE && IS_INDESTRUCTIBLE(e)))
7861 can_replace[xx][yy] = FALSE;
7862 complete_replace = FALSE;
7867 if (!change->only_if_complete || complete_replace)
7869 boolean something_has_changed = FALSE;
7871 if (change->only_if_complete && change->use_random_replace &&
7872 RND(100) < change->random_percentage)
7875 for (yy = 0; yy < 3; yy++) for (xx = 0; xx < 3 ; xx++)
7877 int ex = x + xx - 1;
7878 int ey = y + yy - 1;
7879 int content_element;
7881 if (can_replace[xx][yy] && (!change->use_random_replace ||
7882 RND(100) < change->random_percentage))
7884 if (IS_MOVING(ex, ey) || IS_BLOCKED(ex, ey))
7885 RemoveMovingField(ex, ey);
7887 ChangeEvent[ex][ey] = ChangeEvent[x][y];
7889 content_element = change->target_content[xx][yy];
7890 target_element = GET_TARGET_ELEMENT(content_element, change);
7892 ChangeElementNowExt(ex, ey, target_element);
7894 something_has_changed = TRUE;
7896 /* for symmetry reasons, freeze newly created border elements */
7897 if (ex != x || ey != y)
7898 Stop[ex][ey] = TRUE; /* no more moving in this frame */
7902 if (something_has_changed)
7903 PlayLevelSoundElementAction(x, y, element, ACTION_CHANGING);
7908 target_element = GET_TARGET_ELEMENT(change->target_element, change);
7910 ChangeElementNowExt(x, y, target_element);
7912 PlayLevelSoundElementAction(x, y, element, ACTION_CHANGING);
7916 /* this uses direct change before indirect change */
7917 CheckTriggeredElementChangeByPage(x,y,old_element,CE_OTHER_IS_CHANGING,page);
7923 static void ChangeElement(int x, int y, int page)
7925 int element = MovingOrBlocked2Element(x, y);
7926 struct ElementInfo *ei = &element_info[element];
7927 struct ElementChangeInfo *change = &ei->change_page[page];
7930 if (!CAN_CHANGE(element) && !CAN_CHANGE(Back[x][y]))
7933 printf("ChangeElement(): %d,%d: element = %d ('%s')\n",
7934 x, y, element, element_info[element].token_name);
7935 printf("ChangeElement(): This should never happen!\n");
7940 /* this can happen with classic bombs on walkable, changing elements */
7941 if (!CAN_CHANGE(element))
7944 if (!CAN_CHANGE(Back[x][y])) /* prevent permanent repetition */
7945 ChangeDelay[x][y] = 0;
7951 if (ChangeDelay[x][y] == 0) /* initialize element change */
7953 ChangeDelay[x][y] = ( change->delay_fixed * change->delay_frames +
7954 RND(change->delay_random * change->delay_frames)) + 1;
7956 ResetGfxAnimation(x, y);
7957 ResetRandomAnimationValue(x, y);
7959 if (change->pre_change_function)
7960 change->pre_change_function(x, y);
7963 ChangeDelay[x][y]--;
7965 if (ChangeDelay[x][y] != 0) /* continue element change */
7967 int graphic = el_act_dir2img(element, GfxAction[x][y], GfxDir[x][y]);
7969 if (IS_ANIMATED(graphic))
7970 DrawLevelGraphicAnimationIfNeeded(x, y, graphic);
7972 if (change->change_function)
7973 change->change_function(x, y);
7975 else /* finish element change */
7977 if (ChangePage[x][y] != -1) /* remember page from delayed change */
7979 page = ChangePage[x][y];
7980 ChangePage[x][y] = -1;
7982 change = &ei->change_page[page];
7986 if (IS_MOVING(x, y) && !change->explode)
7988 if (IS_MOVING(x, y)) /* never change a running system ;-) */
7991 ChangeDelay[x][y] = 1; /* try change after next move step */
7992 ChangePage[x][y] = page; /* remember page to use for change */
7997 if (ChangeElementNow(x, y, element, page))
7999 if (change->post_change_function)
8000 change->post_change_function(x, y);
8005 static boolean CheckTriggeredElementChangeExt(int lx, int ly,
8006 int trigger_element,
8013 int trigger_page_bits = (trigger_page < 0 ? CH_PAGE_ANY : 1 << trigger_page);
8015 if (!(trigger_events[trigger_element] & CH_EVENT_BIT(trigger_event)))
8018 for (i = 0; i < NUM_CUSTOM_ELEMENTS; i++)
8020 int element = EL_CUSTOM_START + i;
8022 boolean change_element = FALSE;
8025 if (!CAN_CHANGE(element) || !HAS_ANY_CHANGE_EVENT(element, trigger_event))
8028 for (j = 0; j < element_info[element].num_change_pages; j++)
8030 struct ElementChangeInfo *change = &element_info[element].change_page[j];
8032 if (change->can_change &&
8033 change->events & CH_EVENT_BIT(trigger_event) &&
8034 change->trigger_side & trigger_side &&
8035 change->trigger_player & trigger_player &&
8036 change->trigger_page & trigger_page_bits &&
8037 IS_EQUAL_OR_IN_GROUP(trigger_element, change->trigger_element))
8040 if (!(change->events & CH_EVENT_BIT(trigger_event)))
8041 printf("::: !!! %d triggers %d: using wrong page %d [event %d]\n",
8042 trigger_element-EL_CUSTOM_START+1, i+1, j, trigger_event);
8045 change_element = TRUE;
8048 change->actual_trigger_element = trigger_element;
8049 change->actual_trigger_player = EL_PLAYER_1 + log_2(trigger_player);
8055 if (!change_element)
8058 for (y = 0; y < lev_fieldy; y++) for (x = 0; x < lev_fieldx; x++)
8061 if (x == lx && y == ly) /* do not change trigger element itself */
8065 if (Feld[x][y] == element)
8067 ChangeDelay[x][y] = 1;
8068 ChangeEvent[x][y] = CH_EVENT_BIT(trigger_event);
8069 ChangeElement(x, y, page);
8077 static boolean CheckElementChangeExt(int x, int y,
8079 int trigger_element,
8085 if (!CAN_CHANGE(element) || !HAS_ANY_CHANGE_EVENT(element, trigger_event))
8088 if (Feld[x][y] == EL_BLOCKED)
8090 Blocked2Moving(x, y, &x, &y);
8091 element = Feld[x][y];
8095 if (Feld[x][y] != element) /* check if element has already changed */
8098 printf("::: %d ('%s') != %d ('%s') [%d]\n",
8099 Feld[x][y], element_info[Feld[x][y]].token_name,
8100 element, element_info[element].token_name,
8109 if (trigger_page < 0)
8111 boolean change_element = FALSE;
8114 for (i = 0; i < element_info[element].num_change_pages; i++)
8116 struct ElementChangeInfo *change = &element_info[element].change_page[i];
8118 if (change->can_change &&
8119 change->events & CH_EVENT_BIT(trigger_event) &&
8120 change->trigger_side & trigger_side &&
8121 change->trigger_player & trigger_player)
8123 change_element = TRUE;
8126 change->actual_trigger_element = trigger_element;
8127 change->actual_trigger_player = EL_PLAYER_1 + log_2(trigger_player);
8133 if (!change_element)
8138 struct ElementInfo *ei = &element_info[element];
8139 struct ElementChangeInfo *change = &ei->change_page[trigger_page];
8141 change->actual_trigger_element = trigger_element;
8142 change->actual_trigger_player = EL_PLAYER_1; /* unused */
8147 /* !!! this check misses pages with same event, but different side !!! */
8149 if (trigger_page < 0)
8150 trigger_page = element_info[element].event_page_nr[trigger_event];
8152 if (!(element_info[element].change_page[trigger_page].trigger_side & trigger_side))
8156 ChangeDelay[x][y] = 1;
8157 ChangeEvent[x][y] = CH_EVENT_BIT(trigger_event);
8158 ChangeElement(x, y, trigger_page);
8163 static void PlayPlayerSound(struct PlayerInfo *player)
8165 int jx = player->jx, jy = player->jy;
8166 int element = player->element_nr;
8167 int last_action = player->last_action_waiting;
8168 int action = player->action_waiting;
8170 if (player->is_waiting)
8172 if (action != last_action)
8173 PlayLevelSoundElementAction(jx, jy, element, action);
8175 PlayLevelSoundElementActionIfLoop(jx, jy, element, action);
8179 if (action != last_action)
8180 StopSound(element_info[element].sound[last_action]);
8182 if (last_action == ACTION_SLEEPING)
8183 PlayLevelSoundElementAction(jx, jy, element, ACTION_AWAKENING);
8187 static void PlayAllPlayersSound()
8191 for (i = 0; i < MAX_PLAYERS; i++)
8192 if (stored_player[i].active)
8193 PlayPlayerSound(&stored_player[i]);
8196 static void SetPlayerWaiting(struct PlayerInfo *player, boolean is_waiting)
8198 boolean last_waiting = player->is_waiting;
8199 int move_dir = player->MovDir;
8201 player->last_action_waiting = player->action_waiting;
8205 if (!last_waiting) /* not waiting -> waiting */
8207 player->is_waiting = TRUE;
8209 player->frame_counter_bored =
8211 game.player_boring_delay_fixed +
8212 SimpleRND(game.player_boring_delay_random);
8213 player->frame_counter_sleeping =
8215 game.player_sleeping_delay_fixed +
8216 SimpleRND(game.player_sleeping_delay_random);
8218 InitPlayerGfxAnimation(player, ACTION_WAITING, player->MovDir);
8221 if (game.player_sleeping_delay_fixed +
8222 game.player_sleeping_delay_random > 0 &&
8223 player->anim_delay_counter == 0 &&
8224 player->post_delay_counter == 0 &&
8225 FrameCounter >= player->frame_counter_sleeping)
8226 player->is_sleeping = TRUE;
8227 else if (game.player_boring_delay_fixed +
8228 game.player_boring_delay_random > 0 &&
8229 FrameCounter >= player->frame_counter_bored)
8230 player->is_bored = TRUE;
8232 player->action_waiting = (player->is_sleeping ? ACTION_SLEEPING :
8233 player->is_bored ? ACTION_BORING :
8236 if (player->is_sleeping)
8238 if (player->num_special_action_sleeping > 0)
8240 if (player->anim_delay_counter == 0 && player->post_delay_counter == 0)
8242 int last_special_action = player->special_action_sleeping;
8243 int num_special_action = player->num_special_action_sleeping;
8244 int special_action =
8245 (last_special_action == ACTION_DEFAULT ? ACTION_SLEEPING_1 :
8246 last_special_action == ACTION_SLEEPING ? ACTION_SLEEPING :
8247 last_special_action < ACTION_SLEEPING_1 + num_special_action - 1 ?
8248 last_special_action + 1 : ACTION_SLEEPING);
8249 int special_graphic =
8250 el_act_dir2img(player->element_nr, special_action, move_dir);
8252 player->anim_delay_counter =
8253 graphic_info[special_graphic].anim_delay_fixed +
8254 SimpleRND(graphic_info[special_graphic].anim_delay_random);
8255 player->post_delay_counter =
8256 graphic_info[special_graphic].post_delay_fixed +
8257 SimpleRND(graphic_info[special_graphic].post_delay_random);
8259 player->special_action_sleeping = special_action;
8262 if (player->anim_delay_counter > 0)
8264 player->action_waiting = player->special_action_sleeping;
8265 player->anim_delay_counter--;
8267 else if (player->post_delay_counter > 0)
8269 player->post_delay_counter--;
8273 else if (player->is_bored)
8275 if (player->num_special_action_bored > 0)
8277 if (player->anim_delay_counter == 0 && player->post_delay_counter == 0)
8279 int special_action =
8280 ACTION_BORING_1 + SimpleRND(player->num_special_action_bored);
8281 int special_graphic =
8282 el_act_dir2img(player->element_nr, special_action, move_dir);
8284 player->anim_delay_counter =
8285 graphic_info[special_graphic].anim_delay_fixed +
8286 SimpleRND(graphic_info[special_graphic].anim_delay_random);
8287 player->post_delay_counter =
8288 graphic_info[special_graphic].post_delay_fixed +
8289 SimpleRND(graphic_info[special_graphic].post_delay_random);
8291 player->special_action_bored = special_action;
8294 if (player->anim_delay_counter > 0)
8296 player->action_waiting = player->special_action_bored;
8297 player->anim_delay_counter--;
8299 else if (player->post_delay_counter > 0)
8301 player->post_delay_counter--;
8306 else if (last_waiting) /* waiting -> not waiting */
8308 player->is_waiting = FALSE;
8309 player->is_bored = FALSE;
8310 player->is_sleeping = FALSE;
8312 player->frame_counter_bored = -1;
8313 player->frame_counter_sleeping = -1;
8315 player->anim_delay_counter = 0;
8316 player->post_delay_counter = 0;
8318 player->action_waiting = ACTION_DEFAULT;
8320 player->special_action_bored = ACTION_DEFAULT;
8321 player->special_action_sleeping = ACTION_DEFAULT;
8326 static byte PlayerActions(struct PlayerInfo *player, byte player_action)
8329 static byte stored_player_action[MAX_PLAYERS];
8330 static int num_stored_actions = 0;
8332 boolean moved = FALSE, snapped = FALSE, dropped = FALSE;
8333 int left = player_action & JOY_LEFT;
8334 int right = player_action & JOY_RIGHT;
8335 int up = player_action & JOY_UP;
8336 int down = player_action & JOY_DOWN;
8337 int button1 = player_action & JOY_BUTTON_1;
8338 int button2 = player_action & JOY_BUTTON_2;
8339 int dx = (left ? -1 : right ? 1 : 0);
8340 int dy = (up ? -1 : down ? 1 : 0);
8343 stored_player_action[player->index_nr] = 0;
8344 num_stored_actions++;
8348 printf("::: player %d [%d]\n", player->index_nr, FrameCounter);
8351 if (!player->active || tape.pausing)
8355 printf("::: [%d %d %d %d] [%d %d]\n",
8356 left, right, up, down, button1, button2);
8362 printf("::: player %d acts [%d]\n", player->index_nr, FrameCounter);
8367 if (player->MovPos == 0)
8368 CheckGravityMovement(player);
8371 snapped = SnapField(player, dx, dy);
8375 dropped = DropElement(player);
8377 moved = MovePlayer(player, dx, dy);
8380 if (tape.single_step && tape.recording && !tape.pausing)
8382 if (button1 || (dropped && !moved))
8384 TapeTogglePause(TAPE_TOGGLE_AUTOMATIC);
8385 SnapField(player, 0, 0); /* stop snapping */
8389 SetPlayerWaiting(player, FALSE);
8392 return player_action;
8394 stored_player_action[player->index_nr] = player_action;
8400 printf("::: player %d waits [%d]\n", player->index_nr, FrameCounter);
8403 /* no actions for this player (no input at player's configured device) */
8405 DigField(player, 0, 0, 0, 0, 0, 0, DF_NO_PUSH);
8406 SnapField(player, 0, 0);
8407 CheckGravityMovementWhenNotMoving(player);
8409 if (player->MovPos == 0)
8410 SetPlayerWaiting(player, TRUE);
8412 if (player->MovPos == 0) /* needed for tape.playing */
8413 player->is_moving = FALSE;
8415 player->is_dropping = FALSE;
8421 if (tape.recording && num_stored_actions >= MAX_PLAYERS)
8423 printf("::: player %d recorded [%d]\n", player->index_nr, FrameCounter);
8425 TapeRecordAction(stored_player_action);
8426 num_stored_actions = 0;
8433 static void PlayerActions(struct PlayerInfo *player, byte player_action)
8435 static byte stored_player_action[MAX_PLAYERS];
8436 static int num_stored_actions = 0;
8437 boolean moved = FALSE, snapped = FALSE, dropped = FALSE;
8438 int left = player_action & JOY_LEFT;
8439 int right = player_action & JOY_RIGHT;
8440 int up = player_action & JOY_UP;
8441 int down = player_action & JOY_DOWN;
8442 int button1 = player_action & JOY_BUTTON_1;
8443 int button2 = player_action & JOY_BUTTON_2;
8444 int dx = (left ? -1 : right ? 1 : 0);
8445 int dy = (up ? -1 : down ? 1 : 0);
8447 stored_player_action[player->index_nr] = 0;
8448 num_stored_actions++;
8450 printf("::: player %d [%d]\n", player->index_nr, FrameCounter);
8452 if (!player->active || tape.pausing)
8457 printf("::: player %d acts [%d]\n", player->index_nr, FrameCounter);
8460 snapped = SnapField(player, dx, dy);
8464 dropped = DropElement(player);
8466 moved = MovePlayer(player, dx, dy);
8469 if (tape.single_step && tape.recording && !tape.pausing)
8471 if (button1 || (dropped && !moved))
8473 TapeTogglePause(TAPE_TOGGLE_AUTOMATIC);
8474 SnapField(player, 0, 0); /* stop snapping */
8478 stored_player_action[player->index_nr] = player_action;
8482 printf("::: player %d waits [%d]\n", player->index_nr, FrameCounter);
8484 /* no actions for this player (no input at player's configured device) */
8486 DigField(player, 0, 0, 0, 0, 0, 0, DF_NO_PUSH);
8487 SnapField(player, 0, 0);
8488 CheckGravityMovementWhenNotMoving(player);
8490 if (player->MovPos == 0)
8491 InitPlayerGfxAnimation(player, ACTION_DEFAULT, player->MovDir);
8493 if (player->MovPos == 0) /* needed for tape.playing */
8494 player->is_moving = FALSE;
8497 if (tape.recording && num_stored_actions >= MAX_PLAYERS)
8499 printf("::: player %d recorded [%d]\n", player->index_nr, FrameCounter);
8501 TapeRecordAction(stored_player_action);
8502 num_stored_actions = 0;
8507 void AdvanceFrameAndPlayerCounters(int player_nr)
8511 /* advance frame counters (global frame counter and time frame counter) */
8515 /* advance player counters (counters for move delay, move animation etc.) */
8516 for (i = 0; i < MAX_PLAYERS; i++)
8518 boolean advance_player_counters = (player_nr == -1 || player_nr == i);
8520 MOVE_DELAY_NORMAL_SPEED / stored_player[i].move_delay_value;
8522 if (!advance_player_counters) /* not all players may be affected */
8525 stored_player[i].Frame += move_frames;
8527 if (stored_player[i].MovPos != 0)
8528 stored_player[i].StepFrame += move_frames;
8530 #if USE_NEW_MOVE_DELAY
8531 if (stored_player[i].move_delay > 0)
8532 stored_player[i].move_delay--;
8535 #if USE_NEW_PUSH_DELAY
8536 /* due to bugs in previous versions, counter must count up, not down */
8537 if (stored_player[i].push_delay != -1)
8538 stored_player[i].push_delay++;
8541 if (stored_player[i].drop_delay > 0)
8542 stored_player[i].drop_delay--;
8548 static unsigned long game_frame_delay = 0;
8549 unsigned long game_frame_delay_value;
8550 int magic_wall_x = 0, magic_wall_y = 0;
8551 int i, x, y, element, graphic;
8552 byte *recorded_player_action;
8553 byte summarized_player_action = 0;
8555 byte tape_action[MAX_PLAYERS];
8558 if (game_status != GAME_MODE_PLAYING)
8561 game_frame_delay_value =
8562 (tape.playing && tape.fast_forward ? FfwdFrameDelay : GameFrameDelay);
8564 if (tape.playing && tape.warp_forward && !tape.pausing)
8565 game_frame_delay_value = 0;
8567 /* ---------- main game synchronization point ---------- */
8569 WaitUntilDelayReached(&game_frame_delay, game_frame_delay_value);
8571 if (network_playing && !network_player_action_received)
8575 printf("DEBUG: try to get network player actions in time\n");
8579 #if defined(NETWORK_AVALIABLE)
8580 /* last chance to get network player actions without main loop delay */
8584 if (game_status != GAME_MODE_PLAYING)
8587 if (!network_player_action_received)
8591 printf("DEBUG: failed to get network player actions in time\n");
8602 printf("::: getting new tape action [%d]\n", FrameCounter);
8605 recorded_player_action = (tape.playing ? TapePlayAction() : NULL);
8608 /* !!! CHECK THIS (tape.pausing is always FALSE here!) !!! */
8609 if (recorded_player_action == NULL && tape.pausing)
8614 printf("::: %d\n", stored_player[0].action);
8618 if (recorded_player_action != NULL)
8619 for (i = 0; i < MAX_PLAYERS; i++)
8620 stored_player[i].action = recorded_player_action[i];
8623 for (i = 0; i < MAX_PLAYERS; i++)
8625 summarized_player_action |= stored_player[i].action;
8627 if (!network_playing)
8628 stored_player[i].effective_action = stored_player[i].action;
8631 #if defined(NETWORK_AVALIABLE)
8632 if (network_playing)
8633 SendToServer_MovePlayer(summarized_player_action);
8636 if (!options.network && !setup.team_mode)
8637 local_player->effective_action = summarized_player_action;
8640 if (recorded_player_action != NULL)
8641 for (i = 0; i < MAX_PLAYERS; i++)
8642 stored_player[i].effective_action = recorded_player_action[i];
8646 for (i = 0; i < MAX_PLAYERS; i++)
8648 tape_action[i] = stored_player[i].effective_action;
8650 if (tape.recording && tape_action[i] && !tape.player_participates[i])
8651 tape.player_participates[i] = TRUE; /* player just appeared from CE */
8654 /* only save actions from input devices, but not programmed actions */
8656 TapeRecordAction(tape_action);
8659 for (i = 0; i < MAX_PLAYERS; i++)
8661 int actual_player_action = stored_player[i].effective_action;
8664 /* !!! THIS BREAKS THE FOLLOWING TAPES: !!!
8665 - rnd_equinox_tetrachloride 048
8666 - rnd_equinox_tetrachloride_ii 096
8667 - rnd_emanuel_schmieg 002
8668 - doctor_sloan_ww 001, 020
8670 if (stored_player[i].MovPos == 0)
8671 CheckGravityMovement(&stored_player[i]);
8675 /* overwrite programmed action with tape action */
8676 if (stored_player[i].programmed_action)
8677 actual_player_action = stored_player[i].programmed_action;
8681 if (stored_player[i].programmed_action)
8682 printf("::: %d\n", stored_player[i].programmed_action);
8685 if (recorded_player_action)
8688 if (stored_player[i].programmed_action &&
8689 stored_player[i].programmed_action != recorded_player_action[i])
8690 printf("::: %d: %d <-> %d\n", i,
8691 stored_player[i].programmed_action, recorded_player_action[i]);
8695 actual_player_action = recorded_player_action[i];
8700 /* overwrite tape action with programmed action */
8701 if (stored_player[i].programmed_action)
8702 actual_player_action = stored_player[i].programmed_action;
8707 printf("::: action: %d: %x [%d]\n",
8708 stored_player[i].MovPos, actual_player_action, FrameCounter);
8712 PlayerActions(&stored_player[i], actual_player_action);
8714 tape_action[i] = PlayerActions(&stored_player[i], actual_player_action);
8716 if (tape.recording && tape_action[i] && !tape.player_participates[i])
8717 tape.player_participates[i] = TRUE; /* player just appeared from CE */
8720 ScrollPlayer(&stored_player[i], SCROLL_GO_ON);
8725 TapeRecordAction(tape_action);
8728 network_player_action_received = FALSE;
8730 ScrollScreen(NULL, SCROLL_GO_ON);
8736 for (i = 0; i < MAX_PLAYERS; i++)
8737 stored_player[i].Frame++;
8741 /* for backwards compatibility, the following code emulates a fixed bug that
8742 occured when pushing elements (causing elements that just made their last
8743 pushing step to already (if possible) make their first falling step in the
8744 same game frame, which is bad); this code is also needed to use the famous
8745 "spring push bug" which is used in older levels and might be wanted to be
8746 used also in newer levels, but in this case the buggy pushing code is only
8747 affecting the "spring" element and no other elements */
8750 if (game.engine_version < VERSION_IDENT(2,2,0,7) || level.use_spring_bug)
8752 if (game.engine_version < VERSION_IDENT(2,2,0,7))
8755 for (i = 0; i < MAX_PLAYERS; i++)
8757 struct PlayerInfo *player = &stored_player[i];
8762 if (player->active && player->is_pushing && player->is_moving &&
8764 (game.engine_version < VERSION_IDENT(2,2,0,7) ||
8765 Feld[x][y] == EL_SPRING))
8767 if (player->active && player->is_pushing && player->is_moving &&
8771 ContinueMoving(x, y);
8773 /* continue moving after pushing (this is actually a bug) */
8774 if (!IS_MOVING(x, y))
8783 for (y = 0; y < lev_fieldy; y++) for (x = 0; x < lev_fieldx; x++)
8785 Changed[x][y] = CE_BITMASK_DEFAULT;
8786 ChangeEvent[x][y] = CE_BITMASK_DEFAULT;
8788 #if USE_NEW_BLOCK_STYLE
8789 /* this must be handled before main playfield loop */
8790 if (Feld[x][y] == EL_PLAYER_IS_LEAVING)
8793 if (MovDelay[x][y] <= 0)
8799 if (ChangePage[x][y] != -1 && ChangeDelay[x][y] != 1)
8801 printf("GameActions(): x = %d, y = %d: ChangePage != -1\n", x, y);
8802 printf("GameActions(): This should never happen!\n");
8804 ChangePage[x][y] = -1;
8809 if (WasJustMoving[x][y] > 0)
8810 WasJustMoving[x][y]--;
8811 if (WasJustFalling[x][y] > 0)
8812 WasJustFalling[x][y]--;
8813 if (CheckCollision[x][y] > 0)
8814 CheckCollision[x][y]--;
8819 /* reset finished pushing action (not done in ContinueMoving() to allow
8820 continous pushing animation for elements with zero push delay) */
8821 if (GfxAction[x][y] == ACTION_PUSHING && !IS_MOVING(x, y))
8823 ResetGfxAnimation(x, y);
8824 DrawLevelField(x, y);
8829 if (IS_BLOCKED(x, y))
8833 Blocked2Moving(x, y, &oldx, &oldy);
8834 if (!IS_MOVING(oldx, oldy))
8836 printf("GameActions(): (BLOCKED => MOVING) context corrupted!\n");
8837 printf("GameActions(): BLOCKED: x = %d, y = %d\n", x, y);
8838 printf("GameActions(): !MOVING: oldx = %d, oldy = %d\n", oldx, oldy);
8839 printf("GameActions(): This should never happen!\n");
8845 for (y = 0; y < lev_fieldy; y++) for (x = 0; x < lev_fieldx; x++)
8847 element = Feld[x][y];
8849 graphic = el_act_dir2img(element, GfxAction[x][y], GfxDir[x][y]);
8851 graphic = el2img(element);
8857 printf("::: %d,%d: %d [%d]\n", x, y, element, FrameCounter);
8859 element = graphic = 0;
8863 if (graphic_info[graphic].anim_global_sync)
8864 GfxFrame[x][y] = FrameCounter;
8866 if (ANIM_MODE(graphic) == ANIM_RANDOM &&
8867 IS_NEXT_FRAME(GfxFrame[x][y], graphic))
8868 ResetRandomAnimationValue(x, y);
8870 SetRandomAnimationValue(x, y);
8873 PlayLevelSoundActionIfLoop(x, y, GfxAction[x][y]);
8876 if (IS_INACTIVE(element))
8878 if (IS_ANIMATED(graphic))
8879 DrawLevelGraphicAnimationIfNeeded(x, y, graphic);
8885 /* this may take place after moving, so 'element' may have changed */
8887 if (IS_CHANGING(x, y))
8889 if (IS_CHANGING(x, y) &&
8890 (game.engine_version < VERSION_IDENT(3,0,7,1) || !Stop[x][y]))
8894 ChangeElement(x, y, ChangePage[x][y] != -1 ? ChangePage[x][y] :
8895 element_info[element].event_page_nr[CE_DELAY]);
8897 ChangeElement(x, y, element_info[element].event_page_nr[CE_DELAY]);
8900 element = Feld[x][y];
8901 graphic = el_act_dir2img(element, GfxAction[x][y], GfxDir[x][y]);
8905 if (!IS_MOVING(x, y) && (CAN_FALL(element) || CAN_MOVE(element)))
8910 element = Feld[x][y];
8911 graphic = el_act_dir2img(element, GfxAction[x][y], GfxDir[x][y]);
8913 if (element == EL_MOLE)
8914 printf("::: %d, %d, %d [%d]\n",
8915 IS_ANIMATED(graphic), IS_MOVING(x, y), Stop[x][y],
8919 if (element == EL_YAMYAM)
8920 printf("::: %d, %d, %d\n",
8921 IS_ANIMATED(graphic), IS_MOVING(x, y), Stop[x][y]);
8925 if (IS_ANIMATED(graphic) &&
8929 DrawLevelGraphicAnimationIfNeeded(x, y, graphic);
8932 if (element == EL_BUG)
8933 printf("::: %d, %d\n", graphic, GfxFrame[x][y]);
8937 if (element == EL_MOLE)
8938 printf("::: %d, %d\n", graphic, GfxFrame[x][y]);
8942 if (IS_GEM(element) || element == EL_SP_INFOTRON)
8943 EdelsteinFunkeln(x, y);
8945 else if ((element == EL_ACID ||
8946 element == EL_EXIT_OPEN ||
8947 element == EL_SP_EXIT_OPEN ||
8948 element == EL_SP_TERMINAL ||
8949 element == EL_SP_TERMINAL_ACTIVE ||
8950 element == EL_EXTRA_TIME ||
8951 element == EL_SHIELD_NORMAL ||
8952 element == EL_SHIELD_DEADLY) &&
8953 IS_ANIMATED(graphic))
8954 DrawLevelGraphicAnimationIfNeeded(x, y, graphic);
8955 else if (IS_MOVING(x, y))
8956 ContinueMoving(x, y);
8957 else if (IS_ACTIVE_BOMB(element))
8958 CheckDynamite(x, y);
8960 else if (element == EL_EXPLOSION && !game.explosions_delayed)
8961 Explode(x, y, ExplodePhase[x][y], EX_TYPE_NORMAL);
8963 else if (element == EL_AMOEBA_GROWING)
8964 AmoebeWaechst(x, y);
8965 else if (element == EL_AMOEBA_SHRINKING)
8966 AmoebaDisappearing(x, y);
8968 #if !USE_NEW_AMOEBA_CODE
8969 else if (IS_AMOEBALIVE(element))
8970 AmoebeAbleger(x, y);
8973 else if (element == EL_GAME_OF_LIFE || element == EL_BIOMAZE)
8975 else if (element == EL_EXIT_CLOSED)
8977 else if (element == EL_SP_EXIT_CLOSED)
8979 else if (element == EL_EXPANDABLE_WALL_GROWING)
8981 else if (element == EL_EXPANDABLE_WALL ||
8982 element == EL_EXPANDABLE_WALL_HORIZONTAL ||
8983 element == EL_EXPANDABLE_WALL_VERTICAL ||
8984 element == EL_EXPANDABLE_WALL_ANY)
8986 else if (element == EL_FLAMES)
8987 CheckForDragon(x, y);
8989 else if (IS_AUTO_CHANGING(element))
8990 ChangeElement(x, y);
8992 else if (element == EL_EXPLOSION)
8993 ; /* drawing of correct explosion animation is handled separately */
8994 else if (IS_ANIMATED(graphic) && !IS_CHANGING(x, y))
8995 DrawLevelGraphicAnimationIfNeeded(x, y, graphic);
8998 /* this may take place after moving, so 'element' may have changed */
8999 if (IS_AUTO_CHANGING(Feld[x][y]))
9000 ChangeElement(x, y);
9003 if (IS_BELT_ACTIVE(element))
9004 PlayLevelSoundAction(x, y, ACTION_ACTIVE);
9006 if (game.magic_wall_active)
9008 int jx = local_player->jx, jy = local_player->jy;
9010 /* play the element sound at the position nearest to the player */
9011 if ((element == EL_MAGIC_WALL_FULL ||
9012 element == EL_MAGIC_WALL_ACTIVE ||
9013 element == EL_MAGIC_WALL_EMPTYING ||
9014 element == EL_BD_MAGIC_WALL_FULL ||
9015 element == EL_BD_MAGIC_WALL_ACTIVE ||
9016 element == EL_BD_MAGIC_WALL_EMPTYING) &&
9017 ABS(x-jx) + ABS(y-jy) < ABS(magic_wall_x-jx) + ABS(magic_wall_y-jy))
9025 #if USE_NEW_AMOEBA_CODE
9026 /* new experimental amoeba growth stuff */
9028 if (!(FrameCounter % 8))
9031 static unsigned long random = 1684108901;
9033 for (i = 0; i < level.amoeba_speed * 28 / 8; i++)
9036 x = (random >> 10) % lev_fieldx;
9037 y = (random >> 20) % lev_fieldy;
9039 x = RND(lev_fieldx);
9040 y = RND(lev_fieldy);
9042 element = Feld[x][y];
9045 if (!IS_PLAYER(x,y) &&
9046 (element == EL_EMPTY ||
9047 CAN_GROW_INTO(element) ||
9048 element == EL_QUICKSAND_EMPTY ||
9049 element == EL_ACID_SPLASH_LEFT ||
9050 element == EL_ACID_SPLASH_RIGHT))
9052 if ((IN_LEV_FIELD(x, y-1) && Feld[x][y-1] == EL_AMOEBA_WET) ||
9053 (IN_LEV_FIELD(x-1, y) && Feld[x-1][y] == EL_AMOEBA_WET) ||
9054 (IN_LEV_FIELD(x+1, y) && Feld[x+1][y] == EL_AMOEBA_WET) ||
9055 (IN_LEV_FIELD(x, y+1) && Feld[x][y+1] == EL_AMOEBA_WET))
9056 Feld[x][y] = EL_AMOEBA_DROP;
9059 /* !!! extend EL_SAND to anything diggable (but maybe not SP_BASE) !!! */
9060 if (!IS_PLAYER(x,y) &&
9061 (element == EL_EMPTY ||
9062 element == EL_SAND ||
9063 element == EL_QUICKSAND_EMPTY ||
9064 element == EL_ACID_SPLASH_LEFT ||
9065 element == EL_ACID_SPLASH_RIGHT))
9067 if ((IN_LEV_FIELD(x, y-1) && Feld[x][y-1] == EL_AMOEBA_WET) ||
9068 (IN_LEV_FIELD(x-1, y) && Feld[x-1][y] == EL_AMOEBA_WET) ||
9069 (IN_LEV_FIELD(x+1, y) && Feld[x+1][y] == EL_AMOEBA_WET) ||
9070 (IN_LEV_FIELD(x, y+1) && Feld[x][y+1] == EL_AMOEBA_WET))
9071 Feld[x][y] = EL_AMOEBA_DROP;
9075 random = random * 129 + 1;
9081 if (game.explosions_delayed)
9084 game.explosions_delayed = FALSE;
9086 for (y = 0; y < lev_fieldy; y++) for (x = 0; x < lev_fieldx; x++)
9088 element = Feld[x][y];
9090 if (ExplodeField[x][y])
9091 Explode(x, y, EX_PHASE_START, ExplodeField[x][y]);
9092 else if (element == EL_EXPLOSION)
9093 Explode(x, y, ExplodePhase[x][y], EX_TYPE_NORMAL);
9095 ExplodeField[x][y] = EX_TYPE_NONE;
9098 game.explosions_delayed = TRUE;
9101 if (game.magic_wall_active)
9103 if (!(game.magic_wall_time_left % 4))
9105 int element = Feld[magic_wall_x][magic_wall_y];
9107 if (element == EL_BD_MAGIC_WALL_FULL ||
9108 element == EL_BD_MAGIC_WALL_ACTIVE ||
9109 element == EL_BD_MAGIC_WALL_EMPTYING)
9110 PlayLevelSound(magic_wall_x, magic_wall_y, SND_BD_MAGIC_WALL_ACTIVE);
9112 PlayLevelSound(magic_wall_x, magic_wall_y, SND_MAGIC_WALL_ACTIVE);
9115 if (game.magic_wall_time_left > 0)
9117 game.magic_wall_time_left--;
9118 if (!game.magic_wall_time_left)
9120 for (y = 0; y < lev_fieldy; y++) for (x = 0; x < lev_fieldx; x++)
9122 element = Feld[x][y];
9124 if (element == EL_MAGIC_WALL_ACTIVE ||
9125 element == EL_MAGIC_WALL_FULL)
9127 Feld[x][y] = EL_MAGIC_WALL_DEAD;
9128 DrawLevelField(x, y);
9130 else if (element == EL_BD_MAGIC_WALL_ACTIVE ||
9131 element == EL_BD_MAGIC_WALL_FULL)
9133 Feld[x][y] = EL_BD_MAGIC_WALL_DEAD;
9134 DrawLevelField(x, y);
9138 game.magic_wall_active = FALSE;
9143 if (game.light_time_left > 0)
9145 game.light_time_left--;
9147 if (game.light_time_left == 0)
9148 RedrawAllLightSwitchesAndInvisibleElements();
9151 if (game.timegate_time_left > 0)
9153 game.timegate_time_left--;
9155 if (game.timegate_time_left == 0)
9156 CloseAllOpenTimegates();
9159 for (i = 0; i < MAX_PLAYERS; i++)
9161 struct PlayerInfo *player = &stored_player[i];
9163 if (SHIELD_ON(player))
9165 if (player->shield_deadly_time_left)
9166 PlayLevelSound(player->jx, player->jy, SND_SHIELD_DEADLY_ACTIVE);
9167 else if (player->shield_normal_time_left)
9168 PlayLevelSound(player->jx, player->jy, SND_SHIELD_NORMAL_ACTIVE);
9172 if (TimeFrames >= FRAMES_PER_SECOND)
9177 for (i = 0; i < MAX_PLAYERS; i++)
9179 struct PlayerInfo *player = &stored_player[i];
9181 if (SHIELD_ON(player))
9183 player->shield_normal_time_left--;
9185 if (player->shield_deadly_time_left > 0)
9186 player->shield_deadly_time_left--;
9190 if (!level.use_step_counter)
9198 if (TimeLeft <= 10 && setup.time_limit)
9199 PlaySoundStereo(SND_GAME_RUNNING_OUT_OF_TIME, SOUND_MIDDLE);
9201 DrawGameValue_Time(TimeLeft);
9203 if (!TimeLeft && setup.time_limit)
9204 for (i = 0; i < MAX_PLAYERS; i++)
9205 KillHero(&stored_player[i]);
9207 else if (level.time == 0 && !AllPlayersGone) /* level w/o time limit */
9208 DrawGameValue_Time(TimePlayed);
9211 if (tape.recording || tape.playing)
9212 DrawVideoDisplay(VIDEO_STATE_TIME_ON, TapeTime);
9216 PlayAllPlayersSound();
9218 if (options.debug) /* calculate frames per second */
9220 static unsigned long fps_counter = 0;
9221 static int fps_frames = 0;
9222 unsigned long fps_delay_ms = Counter() - fps_counter;
9226 if (fps_delay_ms >= 500) /* calculate fps every 0.5 seconds */
9228 global.frames_per_second = 1000 * (float)fps_frames / fps_delay_ms;
9231 fps_counter = Counter();
9234 redraw_mask |= REDRAW_FPS;
9238 if (stored_player[0].jx != stored_player[0].last_jx ||
9239 stored_player[0].jy != stored_player[0].last_jy)
9240 printf("::: %d, %d, %d, %d, %d\n",
9241 stored_player[0].MovDir,
9242 stored_player[0].MovPos,
9243 stored_player[0].GfxPos,
9244 stored_player[0].Frame,
9245 stored_player[0].StepFrame);
9248 #if USE_NEW_MOVE_DELAY
9249 AdvanceFrameAndPlayerCounters(-1); /* advance counters for all players */
9254 for (i = 0; i < MAX_PLAYERS; i++)
9257 MOVE_DELAY_NORMAL_SPEED / stored_player[i].move_delay_value;
9259 stored_player[i].Frame += move_frames;
9261 if (stored_player[i].MovPos != 0)
9262 stored_player[i].StepFrame += move_frames;
9264 #if USE_NEW_MOVE_DELAY
9265 if (stored_player[i].move_delay > 0)
9266 stored_player[i].move_delay--;
9269 if (stored_player[i].drop_delay > 0)
9270 stored_player[i].drop_delay--;
9275 if (local_player->show_envelope != 0 && local_player->MovPos == 0)
9277 ShowEnvelope(local_player->show_envelope - EL_ENVELOPE_1);
9279 local_player->show_envelope = 0;
9283 #if USE_NEW_RANDOMIZE
9284 /* use random number generator in every frame to make it less predictable */
9285 if (game.engine_version >= VERSION_IDENT(3,1,1,0))
9290 static boolean AllPlayersInSight(struct PlayerInfo *player, int x, int y)
9292 int min_x = x, min_y = y, max_x = x, max_y = y;
9295 for (i = 0; i < MAX_PLAYERS; i++)
9297 int jx = stored_player[i].jx, jy = stored_player[i].jy;
9299 if (!stored_player[i].active || &stored_player[i] == player)
9302 min_x = MIN(min_x, jx);
9303 min_y = MIN(min_y, jy);
9304 max_x = MAX(max_x, jx);
9305 max_y = MAX(max_y, jy);
9308 return (max_x - min_x < SCR_FIELDX && max_y - min_y < SCR_FIELDY);
9311 static boolean AllPlayersInVisibleScreen()
9315 for (i = 0; i < MAX_PLAYERS; i++)
9317 int jx = stored_player[i].jx, jy = stored_player[i].jy;
9319 if (!stored_player[i].active)
9322 if (!IN_VIS_FIELD(SCREENX(jx), SCREENY(jy)))
9329 void ScrollLevel(int dx, int dy)
9331 int softscroll_offset = (setup.soft_scrolling ? TILEX : 0);
9334 BlitBitmap(drawto_field, drawto_field,
9335 FX + TILEX * (dx == -1) - softscroll_offset,
9336 FY + TILEY * (dy == -1) - softscroll_offset,
9337 SXSIZE - TILEX * (dx!=0) + 2 * softscroll_offset,
9338 SYSIZE - TILEY * (dy!=0) + 2 * softscroll_offset,
9339 FX + TILEX * (dx == 1) - softscroll_offset,
9340 FY + TILEY * (dy == 1) - softscroll_offset);
9344 x = (dx == 1 ? BX1 : BX2);
9345 for (y = BY1; y <= BY2; y++)
9346 DrawScreenField(x, y);
9351 y = (dy == 1 ? BY1 : BY2);
9352 for (x = BX1; x <= BX2; x++)
9353 DrawScreenField(x, y);
9356 redraw_mask |= REDRAW_FIELD;
9360 static boolean canEnterSupaplexPort(int x, int y, int dx, int dy)
9362 int nextx = x + dx, nexty = y + dy;
9363 int element = Feld[x][y];
9366 element != EL_SP_PORT_LEFT &&
9367 element != EL_SP_GRAVITY_PORT_LEFT &&
9368 element != EL_SP_PORT_HORIZONTAL &&
9369 element != EL_SP_PORT_ANY) ||
9371 element != EL_SP_PORT_RIGHT &&
9372 element != EL_SP_GRAVITY_PORT_RIGHT &&
9373 element != EL_SP_PORT_HORIZONTAL &&
9374 element != EL_SP_PORT_ANY) ||
9376 element != EL_SP_PORT_UP &&
9377 element != EL_SP_GRAVITY_PORT_UP &&
9378 element != EL_SP_PORT_VERTICAL &&
9379 element != EL_SP_PORT_ANY) ||
9381 element != EL_SP_PORT_DOWN &&
9382 element != EL_SP_GRAVITY_PORT_DOWN &&
9383 element != EL_SP_PORT_VERTICAL &&
9384 element != EL_SP_PORT_ANY) ||
9385 !IN_LEV_FIELD(nextx, nexty) ||
9386 !IS_FREE(nextx, nexty))
9393 static boolean canFallDown(struct PlayerInfo *player)
9395 int jx = player->jx, jy = player->jy;
9397 return (IN_LEV_FIELD(jx, jy + 1) &&
9398 (IS_FREE(jx, jy + 1) ||
9399 (Feld[jx][jy + 1] == EL_ACID && player->can_fall_into_acid)) &&
9400 IS_WALKABLE_FROM(Feld[jx][jy], MV_DOWN) &&
9401 !IS_WALKABLE_INSIDE(Feld[jx][jy]));
9404 static boolean canPassField(int x, int y, int move_dir)
9406 int opposite_dir = MV_DIR_OPPOSITE(move_dir);
9407 int dx = (move_dir & MV_LEFT ? -1 : move_dir & MV_RIGHT ? +1 : 0);
9408 int dy = (move_dir & MV_UP ? -1 : move_dir & MV_DOWN ? +1 : 0);
9411 int element = Feld[x][y];
9413 return (IS_PASSABLE_FROM(element, opposite_dir) &&
9414 !CAN_MOVE(element) &&
9415 IN_LEV_FIELD(nextx, nexty) && !IS_PLAYER(nextx, nexty) &&
9416 IS_WALKABLE_FROM(Feld[nextx][nexty], move_dir) &&
9417 (level.can_pass_to_walkable || IS_FREE(nextx, nexty)));
9420 static boolean canMoveToValidFieldWithGravity(int x, int y, int move_dir)
9422 int opposite_dir = MV_DIR_OPPOSITE(move_dir);
9423 int dx = (move_dir & MV_LEFT ? -1 : move_dir & MV_RIGHT ? +1 : 0);
9424 int dy = (move_dir & MV_UP ? -1 : move_dir & MV_DOWN ? +1 : 0);
9428 int nextx = newx + dx;
9429 int nexty = newy + dy;
9433 return (IN_LEV_FIELD(newx, newy) && !IS_FREE_OR_PLAYER(newx, newy) &&
9434 IS_GRAVITY_REACHABLE(Feld[newx][newy]) &&
9436 (!IS_SP_PORT(Feld[newx][newy]) || move_dir == MV_UP) &&
9438 (IS_DIGGABLE(Feld[newx][newy]) ||
9439 IS_WALKABLE_FROM(Feld[newx][newy], opposite_dir) ||
9440 canPassField(newx, newy, move_dir)));
9443 return (IN_LEV_FIELD(newx, newy) && !IS_FREE_OR_PLAYER(newx, newy) &&
9444 IS_GRAVITY_REACHABLE(Feld[newx][newy]) &&
9445 (IS_DIGGABLE(Feld[newx][newy]) ||
9446 IS_WALKABLE_FROM(Feld[newx][newy], opposite_dir) ||
9447 canPassField(newx, newy, move_dir)));
9450 return (IN_LEV_FIELD(newx, newy) && !IS_FREE_OR_PLAYER(newx, newy) &&
9451 (IS_DIGGABLE_WITH_GRAVITY(Feld[newx][newy]) ||
9452 IS_WALKABLE_FROM(Feld[newx][newy], opposite_dir) ||
9453 canPassField(newx, newy, move_dir)));
9455 return (IN_LEV_FIELD(newx, newy) && !IS_FREE_OR_PLAYER(newx, newy) &&
9456 (IS_DIGGABLE(Feld[newx][newy]) ||
9457 IS_WALKABLE_FROM(Feld[newx][newy], opposite_dir) ||
9458 (IS_PASSABLE_FROM(Feld[newx][newy], opposite_dir) &&
9459 !CAN_MOVE(Feld[newx][newy]) &&
9460 IN_LEV_FIELD(nextx, nexty) && !IS_PLAYER(nextx, nexty) &&
9461 IS_WALKABLE_FROM(Feld[nextx][nexty], move_dir) &&
9462 (level.can_pass_to_walkable || IS_FREE(nextx, nexty)))));
9468 static void CheckGravityMovement(struct PlayerInfo *player)
9470 if (game.gravity && !player->programmed_action)
9473 int move_dir_horizontal = player->effective_action & MV_HORIZONTAL;
9474 int move_dir_vertical = player->effective_action & MV_VERTICAL;
9476 int move_dir_horizontal = player->action & MV_HORIZONTAL;
9477 int move_dir_vertical = player->action & MV_VERTICAL;
9481 boolean player_is_snapping = player->effective_action & JOY_BUTTON_1;
9483 boolean player_is_snapping = player->action & JOY_BUTTON_1;
9486 int jx = player->jx, jy = player->jy;
9488 boolean player_is_moving_to_valid_field =
9489 (!player_is_snapping &&
9490 (canMoveToValidFieldWithGravity(jx, jy, move_dir_horizontal) ||
9491 canMoveToValidFieldWithGravity(jx, jy, move_dir_vertical)));
9495 (player->last_move_dir & MV_HORIZONTAL ?
9496 (move_dir_vertical ? move_dir_vertical : move_dir_horizontal) :
9497 (move_dir_horizontal ? move_dir_horizontal : move_dir_vertical));
9501 int opposite_dir = MV_DIR_OPPOSITE(move_dir);
9502 int dx = (move_dir & MV_LEFT ? -1 : move_dir & MV_RIGHT ? +1 : 0);
9503 int dy = (move_dir & MV_UP ? -1 : move_dir & MV_DOWN ? +1 : 0);
9504 int new_jx = jx + dx, new_jy = jy + dy;
9505 int nextx = new_jx + dx, nexty = new_jy + dy;
9511 boolean player_can_fall_down = canFallDown(player);
9513 boolean player_can_fall_down =
9514 (IN_LEV_FIELD(jx, jy + 1) &&
9515 (IS_FREE(jx, jy + 1) ||
9516 (Feld[jx][jy + 1] == EL_ACID && player->can_fall_into_acid)));
9520 boolean player_can_fall_down =
9521 (IN_LEV_FIELD(jx, jy + 1) &&
9522 (IS_FREE(jx, jy + 1)));
9526 boolean player_is_moving_to_valid_field =
9529 !player_is_snapping &&
9533 IN_LEV_FIELD(new_jx, new_jy) &&
9534 (IS_DIGGABLE(Feld[new_jx][new_jy]) ||
9535 (IS_SP_PORT(Feld[new_jx][new_jy]) &&
9536 element_info[Feld[new_jx][new_jy]].access_direction & opposite_dir &&
9537 IN_LEV_FIELD(nextx, nexty) &&
9538 element_info[Feld[nextx][nexty]].access_direction & move_dir))
9540 IN_LEV_FIELD(new_jx, new_jy) &&
9541 (Feld[new_jx][new_jy] == EL_SP_BASE ||
9542 Feld[new_jx][new_jy] == EL_SAND ||
9543 (IS_SP_PORT(Feld[new_jx][new_jy]) &&
9544 canEnterSupaplexPort(new_jx, new_jy, dx, dy)))
9545 /* !!! extend EL_SAND to anything diggable !!! */
9551 boolean player_is_standing_on_valid_field =
9552 (IS_WALKABLE_INSIDE(Feld[jx][jy]) ||
9553 (IS_WALKABLE(Feld[jx][jy]) && !ACCESS_FROM(Feld[jx][jy], MV_DOWN)));
9557 printf("::: checking gravity NOW [%d, %d, %d] [%d] [%d / %d] ...\n",
9558 player_can_fall_down,
9559 player_is_standing_on_valid_field,
9560 player_is_moving_to_valid_field,
9561 (player_is_moving_to_valid_field ? Feld[new_jx][new_jy] : -1),
9562 player->effective_action,
9563 player->can_fall_into_acid);
9566 if (player_can_fall_down &&
9568 !player_is_standing_on_valid_field &&
9570 !player_is_moving_to_valid_field)
9573 printf("::: setting programmed_action to MV_DOWN [%d,%d - %d] ...\n",
9574 jx, jy, FrameCounter);
9577 player->programmed_action = MV_DOWN;
9582 static void CheckGravityMovementWhenNotMoving(struct PlayerInfo *player)
9585 return CheckGravityMovement(player);
9588 if (game.gravity && !player->programmed_action)
9590 int jx = player->jx, jy = player->jy;
9591 boolean field_under_player_is_free =
9592 (IN_LEV_FIELD(jx, jy + 1) && IS_FREE(jx, jy + 1));
9593 boolean player_is_standing_on_valid_field =
9594 (IS_WALKABLE_INSIDE(Feld[jx][jy]) ||
9595 (IS_WALKABLE(Feld[jx][jy]) &&
9596 !(element_info[Feld[jx][jy]].access_direction & MV_DOWN)));
9598 if (field_under_player_is_free && !player_is_standing_on_valid_field)
9599 player->programmed_action = MV_DOWN;
9605 -----------------------------------------------------------------------------
9606 dx, dy: direction (non-diagonal) to try to move the player to
9607 real_dx, real_dy: direction as read from input device (can be diagonal)
9610 boolean MovePlayerOneStep(struct PlayerInfo *player,
9611 int dx, int dy, int real_dx, int real_dy)
9614 static int trigger_sides[4][2] =
9616 /* enter side leave side */
9617 { CH_SIDE_RIGHT, CH_SIDE_LEFT }, /* moving left */
9618 { CH_SIDE_LEFT, CH_SIDE_RIGHT }, /* moving right */
9619 { CH_SIDE_BOTTOM, CH_SIDE_TOP }, /* moving up */
9620 { CH_SIDE_TOP, CH_SIDE_BOTTOM } /* moving down */
9622 int move_direction = (dx == -1 ? MV_LEFT :
9623 dx == +1 ? MV_RIGHT :
9625 dy == +1 ? MV_DOWN : MV_NO_MOVING);
9626 int enter_side = trigger_sides[MV_DIR_BIT(move_direction)][0];
9627 int leave_side = trigger_sides[MV_DIR_BIT(move_direction)][1];
9629 int jx = player->jx, jy = player->jy;
9630 int new_jx = jx + dx, new_jy = jy + dy;
9634 if (!player->active || (!dx && !dy))
9635 return MF_NO_ACTION;
9637 player->MovDir = (dx < 0 ? MV_LEFT :
9640 dy > 0 ? MV_DOWN : MV_NO_MOVING);
9642 if (!IN_LEV_FIELD(new_jx, new_jy))
9643 return MF_NO_ACTION;
9645 if (!options.network && !AllPlayersInSight(player, new_jx, new_jy))
9646 return MF_NO_ACTION;
9649 element = MovingOrBlocked2Element(new_jx, new_jy);
9651 element = MovingOrBlocked2ElementIfNotLeaving(new_jx, new_jy);
9654 if (DONT_RUN_INTO(element))
9656 if (element == EL_ACID && dx == 0 && dy == 1)
9658 SplashAcid(new_jx, new_jy);
9659 Feld[jx][jy] = EL_PLAYER_1;
9660 InitMovingField(jx, jy, MV_DOWN);
9661 Store[jx][jy] = EL_ACID;
9662 ContinueMoving(jx, jy);
9666 TestIfHeroRunsIntoBadThing(jx, jy, player->MovDir);
9671 can_move = DigField(player, jx, jy, new_jx, new_jy, real_dx,real_dy, DF_DIG);
9672 if (can_move != MF_MOVING)
9675 /* check if DigField() has caused relocation of the player */
9676 if (player->jx != jx || player->jy != jy)
9677 return MF_NO_ACTION;
9679 StorePlayer[jx][jy] = 0;
9680 player->last_jx = jx;
9681 player->last_jy = jy;
9682 player->jx = new_jx;
9683 player->jy = new_jy;
9684 StorePlayer[new_jx][new_jy] = player->element_nr;
9687 (dx > 0 || dy > 0 ? -1 : 1) * (TILEX - TILEX / player->move_delay_value);
9689 player->step_counter++;
9692 player->drop_delay = 0;
9695 PlayerVisit[jx][jy] = FrameCounter;
9697 ScrollPlayer(player, SCROLL_INIT);
9700 if (IS_CUSTOM_ELEMENT(Feld[jx][jy]))
9702 CheckTriggeredElementChangeBySide(jx, jy, Feld[jx][jy], CE_OTHER_GETS_LEFT,
9704 CheckElementChangeBySide(jx,jy, Feld[jx][jy],CE_LEFT_BY_PLAYER,leave_side);
9707 if (IS_CUSTOM_ELEMENT(Feld[new_jx][new_jy]))
9709 CheckTriggeredElementChangeBySide(new_jx, new_jy, Feld[new_jx][new_jy],
9710 CE_OTHER_GETS_ENTERED, enter_side);
9711 CheckElementChangeBySide(new_jx, new_jy, Feld[new_jx][new_jy],
9712 CE_ENTERED_BY_PLAYER, enter_side);
9719 boolean MovePlayer(struct PlayerInfo *player, int dx, int dy)
9721 int jx = player->jx, jy = player->jy;
9722 int old_jx = jx, old_jy = jy;
9723 int moved = MF_NO_ACTION;
9726 if (!player->active)
9731 if (player->MovPos == 0)
9733 player->is_moving = FALSE;
9734 player->is_digging = FALSE;
9735 player->is_collecting = FALSE;
9736 player->is_snapping = FALSE;
9737 player->is_pushing = FALSE;
9743 if (!player->active || (!dx && !dy))
9748 if (!FrameReached(&player->move_delay, player->move_delay_value) &&
9756 printf("::: %d <= %d < %d ?\n", player->move_delay, FrameCounter,
9757 player->move_delay + player->move_delay_value);
9760 #if USE_NEW_MOVE_DELAY
9761 if (player->move_delay > 0)
9763 if (!FrameReached(&player->move_delay, player->move_delay_value))
9767 printf("::: can NOT move\n");
9773 if (!FrameReached(&player->move_delay, player->move_delay_value) &&
9774 !(tape.playing && tape.file_version < FILE_VERSION_2_0))
9781 printf("::: COULD move now\n");
9784 #if USE_NEW_MOVE_DELAY
9785 player->move_delay = -1; /* set to "uninitialized" value */
9788 /* store if player is automatically moved to next field */
9789 player->is_auto_moving = (player->programmed_action != MV_NO_MOVING);
9791 /* remove the last programmed player action */
9792 player->programmed_action = 0;
9796 /* should only happen if pre-1.2 tape recordings are played */
9797 /* this is only for backward compatibility */
9799 int original_move_delay_value = player->move_delay_value;
9802 printf("THIS SHOULD ONLY HAPPEN WITH PRE-1.2 LEVEL TAPES. [%ld]\n",
9806 /* scroll remaining steps with finest movement resolution */
9807 player->move_delay_value = MOVE_DELAY_NORMAL_SPEED;
9809 while (player->MovPos)
9811 ScrollPlayer(player, SCROLL_GO_ON);
9812 ScrollScreen(NULL, SCROLL_GO_ON);
9814 #if USE_NEW_MOVE_DELAY
9815 AdvanceFrameAndPlayerCounters(player->index_nr);
9824 player->move_delay_value = original_move_delay_value;
9827 if (player->last_move_dir & MV_HORIZONTAL)
9829 if (!(moved |= MovePlayerOneStep(player, 0, dy, dx, dy)))
9830 moved |= MovePlayerOneStep(player, dx, 0, dx, dy);
9834 if (!(moved |= MovePlayerOneStep(player, dx, 0, dx, dy)))
9835 moved |= MovePlayerOneStep(player, 0, dy, dx, dy);
9841 if (moved & MF_MOVING && !ScreenMovPos &&
9842 (player == local_player || !options.network))
9844 int old_scroll_x = scroll_x, old_scroll_y = scroll_y;
9845 int offset = (setup.scroll_delay ? 3 : 0);
9847 if (!IN_VIS_FIELD(SCREENX(jx), SCREENY(jy)))
9849 /* actual player has left the screen -- scroll in that direction */
9850 if (jx != old_jx) /* player has moved horizontally */
9851 scroll_x += (jx - old_jx);
9852 else /* player has moved vertically */
9853 scroll_y += (jy - old_jy);
9857 if (jx != old_jx) /* player has moved horizontally */
9859 if ((player->MovDir == MV_LEFT && scroll_x > jx - MIDPOSX + offset) ||
9860 (player->MovDir == MV_RIGHT && scroll_x < jx - MIDPOSX - offset))
9861 scroll_x = jx-MIDPOSX + (scroll_x < jx-MIDPOSX ? -offset : +offset);
9863 /* don't scroll over playfield boundaries */
9864 if (scroll_x < SBX_Left || scroll_x > SBX_Right)
9865 scroll_x = (scroll_x < SBX_Left ? SBX_Left : SBX_Right);
9867 /* don't scroll more than one field at a time */
9868 scroll_x = old_scroll_x + SIGN(scroll_x - old_scroll_x);
9870 /* don't scroll against the player's moving direction */
9871 if ((player->MovDir == MV_LEFT && scroll_x > old_scroll_x) ||
9872 (player->MovDir == MV_RIGHT && scroll_x < old_scroll_x))
9873 scroll_x = old_scroll_x;
9875 else /* player has moved vertically */
9877 if ((player->MovDir == MV_UP && scroll_y > jy - MIDPOSY + offset) ||
9878 (player->MovDir == MV_DOWN && scroll_y < jy - MIDPOSY - offset))
9879 scroll_y = jy-MIDPOSY + (scroll_y < jy-MIDPOSY ? -offset : +offset);
9881 /* don't scroll over playfield boundaries */
9882 if (scroll_y < SBY_Upper || scroll_y > SBY_Lower)
9883 scroll_y = (scroll_y < SBY_Upper ? SBY_Upper : SBY_Lower);
9885 /* don't scroll more than one field at a time */
9886 scroll_y = old_scroll_y + SIGN(scroll_y - old_scroll_y);
9888 /* don't scroll against the player's moving direction */
9889 if ((player->MovDir == MV_UP && scroll_y > old_scroll_y) ||
9890 (player->MovDir == MV_DOWN && scroll_y < old_scroll_y))
9891 scroll_y = old_scroll_y;
9895 if (scroll_x != old_scroll_x || scroll_y != old_scroll_y)
9897 if (!options.network && !AllPlayersInVisibleScreen())
9899 scroll_x = old_scroll_x;
9900 scroll_y = old_scroll_y;
9904 ScrollScreen(player, SCROLL_INIT);
9905 ScrollLevel(old_scroll_x - scroll_x, old_scroll_y - scroll_y);
9912 InitPlayerGfxAnimation(player, ACTION_DEFAULT);
9914 if (!(moved & MF_MOVING) && !player->is_pushing)
9919 player->StepFrame = 0;
9921 if (moved & MF_MOVING)
9924 printf("::: REALLY moves now\n");
9927 if (old_jx != jx && old_jy == jy)
9928 player->MovDir = (old_jx < jx ? MV_RIGHT : MV_LEFT);
9929 else if (old_jx == jx && old_jy != jy)
9930 player->MovDir = (old_jy < jy ? MV_DOWN : MV_UP);
9932 DrawLevelField(jx, jy); /* for "crumbled sand" */
9934 player->last_move_dir = player->MovDir;
9935 player->is_moving = TRUE;
9937 player->is_snapping = FALSE;
9941 player->is_switching = FALSE;
9944 player->is_dropping = FALSE;
9948 /* !!! ENABLE THIS FOR OLD VERSIONS !!! */
9951 if (game.engine_version < VERSION_IDENT(3,1,0,0))
9954 int move_direction = player->MovDir;
9956 int enter_side = MV_DIR_OPPOSITE(move_direction);
9957 int leave_side = move_direction;
9959 static int trigger_sides[4][2] =
9961 /* enter side leave side */
9962 { CH_SIDE_RIGHT, CH_SIDE_LEFT }, /* moving left */
9963 { CH_SIDE_LEFT, CH_SIDE_RIGHT }, /* moving right */
9964 { CH_SIDE_BOTTOM, CH_SIDE_TOP }, /* moving up */
9965 { CH_SIDE_TOP, CH_SIDE_BOTTOM } /* moving down */
9967 int enter_side = trigger_sides[MV_DIR_BIT(move_direction)][0];
9968 int leave_side = trigger_sides[MV_DIR_BIT(move_direction)][1];
9970 int old_element = Feld[old_jx][old_jy];
9971 int new_element = Feld[jx][jy];
9974 /* !!! TEST ONLY !!! */
9975 if (IS_CUSTOM_ELEMENT(old_element))
9976 CheckElementChangeByPlayer(old_jx, old_jy, old_element,
9978 player->index_bit, leave_side);
9980 CheckTriggeredElementChangeByPlayer(old_jx, old_jy, old_element,
9982 player->index_bit, leave_side);
9984 if (IS_CUSTOM_ELEMENT(new_element))
9985 CheckElementChangeByPlayer(jx, jy, new_element, CE_ENTERED_BY_PLAYER,
9986 player->index_bit, enter_side);
9988 CheckTriggeredElementChangeByPlayer(jx, jy, new_element,
9989 CE_OTHER_GETS_ENTERED,
9990 player->index_bit, enter_side);
10000 CheckGravityMovementWhenNotMoving(player);
10003 player->last_move_dir = MV_NO_MOVING;
10005 player->is_moving = FALSE;
10007 #if USE_NEW_MOVE_STYLE
10008 /* player is ALLOWED to move, but CANNOT move (something blocks his way) */
10009 /* ensure that the player is also allowed to move in the next frame */
10010 /* (currently, the player is forced to wait eight frames before he can try
10013 if (game.engine_version >= VERSION_IDENT(3,1,1,0))
10014 player->move_delay = 0; /* allow direct movement in the next frame */
10018 #if USE_NEW_MOVE_DELAY
10019 if (player->move_delay == -1) /* not yet initialized by DigField() */
10020 player->move_delay = player->move_delay_value;
10023 if (game.engine_version < VERSION_IDENT(3,0,7,0))
10025 TestIfHeroTouchesBadThing(jx, jy);
10026 TestIfPlayerTouchesCustomElement(jx, jy);
10029 if (!player->active)
10030 RemoveHero(player);
10035 void ScrollPlayer(struct PlayerInfo *player, int mode)
10037 int jx = player->jx, jy = player->jy;
10038 int last_jx = player->last_jx, last_jy = player->last_jy;
10039 int move_stepsize = TILEX / player->move_delay_value;
10041 if (!player->active || !player->MovPos)
10044 if (mode == SCROLL_INIT)
10046 player->actual_frame_counter = FrameCounter;
10047 player->GfxPos = move_stepsize * (player->MovPos / move_stepsize);
10050 printf("::: %06d: %d,%d: %d (%d) [%d]\n",
10052 last_jx, last_jy, Feld[last_jx][last_jy], EL_EXPLOSION,
10053 player->block_delay);
10056 #if USE_NEW_BLOCK_STYLE
10059 if (player->block_delay <= 0)
10060 printf("::: ALERT! block_delay == %d\n", player->block_delay);
10063 if (player->block_delay > 0 &&
10064 Feld[last_jx][last_jy] == EL_EMPTY)
10066 Feld[last_jx][last_jy] = EL_PLAYER_IS_LEAVING;
10067 MovDelay[last_jx][last_jy] = player->block_delay + 1;
10070 #if USE_NEW_MOVE_STYLE
10071 if ((game.engine_version < VERSION_IDENT(3,1,1,0) ||
10072 player->block_last_field) &&
10073 Feld[last_jx][last_jy] == EL_EMPTY)
10074 Feld[last_jx][last_jy] = EL_PLAYER_IS_LEAVING;
10076 if (Feld[last_jx][last_jy] == EL_EMPTY)
10077 Feld[last_jx][last_jy] = EL_PLAYER_IS_LEAVING;
10082 DrawPlayer(player);
10087 else if (!FrameReached(&player->actual_frame_counter, 1))
10090 player->MovPos += (player->MovPos > 0 ? -1 : 1) * move_stepsize;
10091 player->GfxPos = move_stepsize * (player->MovPos / move_stepsize);
10093 #if USE_NEW_BLOCK_STYLE
10095 if (!player->block_last_field &&
10096 Feld[last_jx][last_jy] == EL_PLAYER_IS_LEAVING)
10098 RemoveField(last_jx, last_jy);
10100 Feld[last_jx][last_jy] = EL_EMPTY;
10104 /* before DrawPlayer() to draw correct player graphic for this case */
10105 if (player->MovPos == 0)
10106 CheckGravityMovement(player);
10109 DrawPlayer(player); /* needed here only to cleanup last field */
10112 if (player->MovPos == 0) /* player reached destination field */
10115 if (player->move_delay_reset_counter > 0)
10117 player->move_delay_reset_counter--;
10119 if (player->move_delay_reset_counter == 0)
10121 /* continue with normal speed after quickly moving through gate */
10122 HALVE_PLAYER_SPEED(player);
10124 /* be able to make the next move without delay */
10125 player->move_delay = 0;
10129 if (IS_PASSABLE(Feld[last_jx][last_jy]))
10131 /* continue with normal speed after quickly moving through gate */
10132 HALVE_PLAYER_SPEED(player);
10134 /* be able to make the next move without delay */
10135 player->move_delay = 0;
10139 #if USE_NEW_BLOCK_STYLE
10141 if (player->block_last_field &&
10142 Feld[last_jx][last_jy] == EL_PLAYER_IS_LEAVING)
10144 RemoveField(last_jx, last_jy);
10146 Feld[last_jx][last_jy] = EL_EMPTY;
10150 player->last_jx = jx;
10151 player->last_jy = jy;
10153 if (Feld[jx][jy] == EL_EXIT_OPEN ||
10154 Feld[jx][jy] == EL_SP_EXIT_OPEN ||
10155 Feld[jx][jy] == EL_SP_EXIT_OPENING) /* <-- special case */
10157 DrawPlayer(player); /* needed here only to cleanup last field */
10158 RemoveHero(player);
10160 if (local_player->friends_still_needed == 0 ||
10161 IS_SP_ELEMENT(Feld[jx][jy]))
10162 player->LevelSolved = player->GameOver = TRUE;
10166 /* !!! ENABLE THIS FOR NEW VERSIONS !!! */
10167 /* this breaks one level: "machine", level 000 */
10169 if (game.engine_version >= VERSION_IDENT(3,1,0,0))
10172 int move_direction = player->MovDir;
10174 int enter_side = MV_DIR_OPPOSITE(move_direction);
10175 int leave_side = move_direction;
10177 static int trigger_sides[4][2] =
10179 /* enter side leave side */
10180 { CH_SIDE_RIGHT, CH_SIDE_LEFT }, /* moving left */
10181 { CH_SIDE_LEFT, CH_SIDE_RIGHT }, /* moving right */
10182 { CH_SIDE_BOTTOM, CH_SIDE_TOP }, /* moving up */
10183 { CH_SIDE_TOP, CH_SIDE_BOTTOM } /* moving down */
10185 int enter_side = trigger_sides[MV_DIR_BIT(move_direction)][0];
10186 int leave_side = trigger_sides[MV_DIR_BIT(move_direction)][1];
10188 int old_jx = last_jx;
10189 int old_jy = last_jy;
10190 int old_element = Feld[old_jx][old_jy];
10191 int new_element = Feld[jx][jy];
10194 /* !!! TEST ONLY !!! */
10195 if (IS_CUSTOM_ELEMENT(old_element))
10196 CheckElementChangeByPlayer(old_jx, old_jy, old_element,
10198 player->index_bit, leave_side);
10200 CheckTriggeredElementChangeByPlayer(old_jx, old_jy, old_element,
10201 CE_OTHER_GETS_LEFT,
10202 player->index_bit, leave_side);
10204 if (IS_CUSTOM_ELEMENT(new_element))
10205 CheckElementChangeByPlayer(jx, jy, new_element, CE_ENTERED_BY_PLAYER,
10206 player->index_bit, enter_side);
10208 CheckTriggeredElementChangeByPlayer(jx, jy, new_element,
10209 CE_OTHER_GETS_ENTERED,
10210 player->index_bit, enter_side);
10216 if (game.engine_version >= VERSION_IDENT(3,0,7,0))
10218 TestIfHeroTouchesBadThing(jx, jy);
10219 TestIfPlayerTouchesCustomElement(jx, jy);
10222 /* needed because pushed element has not yet reached its destination,
10223 so it would trigger a change event at its previous field location */
10224 if (!player->is_pushing)
10226 TestIfElementTouchesCustomElement(jx, jy); /* for empty space */
10229 if (!player->active)
10230 RemoveHero(player);
10233 if (level.use_step_counter)
10243 if (TimeLeft <= 10 && setup.time_limit)
10244 PlaySoundStereo(SND_GAME_RUNNING_OUT_OF_TIME, SOUND_MIDDLE);
10246 DrawGameValue_Time(TimeLeft);
10248 if (!TimeLeft && setup.time_limit)
10249 for (i = 0; i < MAX_PLAYERS; i++)
10250 KillHero(&stored_player[i]);
10252 else if (level.time == 0 && !AllPlayersGone) /* level w/o time limit */
10253 DrawGameValue_Time(TimePlayed);
10256 if (tape.single_step && tape.recording && !tape.pausing &&
10257 !player->programmed_action)
10258 TapeTogglePause(TAPE_TOGGLE_AUTOMATIC);
10262 void ScrollScreen(struct PlayerInfo *player, int mode)
10264 static unsigned long screen_frame_counter = 0;
10266 if (mode == SCROLL_INIT)
10268 /* set scrolling step size according to actual player's moving speed */
10269 ScrollStepSize = TILEX / player->move_delay_value;
10271 screen_frame_counter = FrameCounter;
10272 ScreenMovDir = player->MovDir;
10273 ScreenMovPos = player->MovPos;
10274 ScreenGfxPos = ScrollStepSize * (ScreenMovPos / ScrollStepSize);
10277 else if (!FrameReached(&screen_frame_counter, 1))
10282 ScreenMovPos += (ScreenMovPos > 0 ? -1 : 1) * ScrollStepSize;
10283 ScreenGfxPos = ScrollStepSize * (ScreenMovPos / ScrollStepSize);
10284 redraw_mask |= REDRAW_FIELD;
10287 ScreenMovDir = MV_NO_MOVING;
10290 void TestIfPlayerTouchesCustomElement(int x, int y)
10292 static int xy[4][2] =
10299 static int trigger_sides[4][2] =
10301 /* center side border side */
10302 { CH_SIDE_TOP, CH_SIDE_BOTTOM }, /* check top */
10303 { CH_SIDE_LEFT, CH_SIDE_RIGHT }, /* check left */
10304 { CH_SIDE_RIGHT, CH_SIDE_LEFT }, /* check right */
10305 { CH_SIDE_BOTTOM, CH_SIDE_TOP } /* check bottom */
10307 static int touch_dir[4] =
10309 MV_LEFT | MV_RIGHT,
10314 int center_element = Feld[x][y]; /* should always be non-moving! */
10317 for (i = 0; i < NUM_DIRECTIONS; i++)
10319 int xx = x + xy[i][0];
10320 int yy = y + xy[i][1];
10321 int center_side = trigger_sides[i][0];
10322 int border_side = trigger_sides[i][1];
10323 int border_element;
10325 if (!IN_LEV_FIELD(xx, yy))
10328 if (IS_PLAYER(x, y))
10330 struct PlayerInfo *player = PLAYERINFO(x, y);
10332 if (game.engine_version < VERSION_IDENT(3,0,7,0))
10333 border_element = Feld[xx][yy]; /* may be moving! */
10334 else if (!IS_MOVING(xx, yy) && !IS_BLOCKED(xx, yy))
10335 border_element = Feld[xx][yy];
10336 else if (MovDir[xx][yy] & touch_dir[i]) /* elements are touching */
10337 border_element = MovingOrBlocked2Element(xx, yy);
10339 continue; /* center and border element do not touch */
10342 /* !!! TEST ONLY !!! */
10343 CheckElementChangeByPlayer(xx, yy, border_element, CE_TOUCHED_BY_PLAYER,
10344 player->index_bit, border_side);
10345 CheckTriggeredElementChangeByPlayer(xx, yy, border_element,
10346 CE_OTHER_GETS_TOUCHED,
10347 player->index_bit, border_side);
10349 CheckTriggeredElementChangeByPlayer(xx, yy, border_element,
10350 CE_OTHER_GETS_TOUCHED,
10351 player->index_bit, border_side);
10352 CheckElementChangeByPlayer(xx, yy, border_element, CE_TOUCHED_BY_PLAYER,
10353 player->index_bit, border_side);
10356 else if (IS_PLAYER(xx, yy))
10358 struct PlayerInfo *player = PLAYERINFO(xx, yy);
10360 if (game.engine_version >= VERSION_IDENT(3,0,7,0))
10362 if (player->MovPos != 0 && !(player->MovDir & touch_dir[i]))
10363 continue; /* center and border element do not touch */
10367 /* !!! TEST ONLY !!! */
10368 CheckElementChangeByPlayer(x, y, center_element, CE_TOUCHED_BY_PLAYER,
10369 player->index_bit, center_side);
10370 CheckTriggeredElementChangeByPlayer(x, y, center_element,
10371 CE_OTHER_GETS_TOUCHED,
10372 player->index_bit, center_side);
10374 CheckTriggeredElementChangeByPlayer(x, y, center_element,
10375 CE_OTHER_GETS_TOUCHED,
10376 player->index_bit, center_side);
10377 CheckElementChangeByPlayer(x, y, center_element, CE_TOUCHED_BY_PLAYER,
10378 player->index_bit, center_side);
10386 void TestIfElementTouchesCustomElement(int x, int y)
10388 static int xy[4][2] =
10395 static int trigger_sides[4][2] =
10397 /* center side border side */
10398 { CH_SIDE_TOP, CH_SIDE_BOTTOM }, /* check top */
10399 { CH_SIDE_LEFT, CH_SIDE_RIGHT }, /* check left */
10400 { CH_SIDE_RIGHT, CH_SIDE_LEFT }, /* check right */
10401 { CH_SIDE_BOTTOM, CH_SIDE_TOP } /* check bottom */
10403 static int touch_dir[4] =
10405 MV_LEFT | MV_RIGHT,
10410 boolean change_center_element = FALSE;
10411 int center_element_change_page = 0;
10412 int center_element = Feld[x][y]; /* should always be non-moving! */
10413 int border_trigger_element = EL_UNDEFINED;
10416 for (i = 0; i < NUM_DIRECTIONS; i++)
10418 int xx = x + xy[i][0];
10419 int yy = y + xy[i][1];
10420 int center_side = trigger_sides[i][0];
10421 int border_side = trigger_sides[i][1];
10422 int border_element;
10424 if (!IN_LEV_FIELD(xx, yy))
10427 if (game.engine_version < VERSION_IDENT(3,0,7,0))
10428 border_element = Feld[xx][yy]; /* may be moving! */
10429 else if (!IS_MOVING(xx, yy) && !IS_BLOCKED(xx, yy))
10430 border_element = Feld[xx][yy];
10431 else if (MovDir[xx][yy] & touch_dir[i]) /* elements are touching */
10432 border_element = MovingOrBlocked2Element(xx, yy);
10434 continue; /* center and border element do not touch */
10436 /* check for change of center element (but change it only once) */
10437 if (IS_CUSTOM_ELEMENT(center_element) &&
10438 HAS_ANY_CHANGE_EVENT(center_element, CE_OTHER_IS_TOUCHING) &&
10439 !change_center_element)
10441 for (j = 0; j < element_info[center_element].num_change_pages; j++)
10443 struct ElementChangeInfo *change =
10444 &element_info[center_element].change_page[j];
10446 if (change->can_change &&
10447 change->events & CH_EVENT_BIT(CE_OTHER_IS_TOUCHING) &&
10448 change->trigger_side & border_side &&
10450 IS_EQUAL_OR_IN_GROUP(border_element, change->trigger_element)
10452 change->trigger_element == border_element
10456 change_center_element = TRUE;
10457 center_element_change_page = j;
10458 border_trigger_element = border_element;
10465 /* check for change of border element */
10466 if (IS_CUSTOM_ELEMENT(border_element) &&
10467 HAS_ANY_CHANGE_EVENT(border_element, CE_OTHER_IS_TOUCHING))
10469 for (j = 0; j < element_info[border_element].num_change_pages; j++)
10471 struct ElementChangeInfo *change =
10472 &element_info[border_element].change_page[j];
10474 if (change->can_change &&
10475 change->events & CH_EVENT_BIT(CE_OTHER_IS_TOUCHING) &&
10476 change->trigger_side & center_side &&
10478 IS_EQUAL_OR_IN_GROUP(center_element, change->trigger_element)
10480 change->trigger_element == center_element
10485 printf("::: border_element %d, %d\n", x, y);
10488 CheckElementChangeByPage(xx, yy, border_element, center_element,
10489 CE_OTHER_IS_TOUCHING, j);
10496 if (change_center_element)
10499 printf("::: center_element %d, %d\n", x, y);
10502 CheckElementChangeByPage(x, y, center_element, border_trigger_element,
10503 CE_OTHER_IS_TOUCHING, center_element_change_page);
10507 void TestIfElementHitsCustomElement(int x, int y, int direction)
10509 int dx = (direction == MV_LEFT ? -1 : direction == MV_RIGHT ? +1 : 0);
10510 int dy = (direction == MV_UP ? -1 : direction == MV_DOWN ? +1 : 0);
10511 int hitx = x + dx, hity = y + dy;
10512 int hitting_element = Feld[x][y];
10513 int touched_element;
10515 boolean object_hit = (IN_LEV_FIELD(hitx, hity) &&
10516 !IS_FREE(hitx, hity) &&
10517 (!IS_MOVING(hitx, hity) ||
10518 MovDir[hitx][hity] != direction ||
10519 ABS(MovPos[hitx][hity]) <= TILEY / 2));
10522 if (IN_LEV_FIELD(hitx, hity) && IS_FREE(hitx, hity))
10526 if (IN_LEV_FIELD(hitx, hity) && !object_hit)
10530 touched_element = (IN_LEV_FIELD(hitx, hity) ?
10531 MovingOrBlocked2Element(hitx, hity) : EL_STEELWALL);
10533 CheckElementChangeBySide(x, y, hitting_element, touched_element,
10534 CE_HITTING_SOMETHING, direction);
10536 if (IN_LEV_FIELD(hitx, hity))
10538 int opposite_direction = MV_DIR_OPPOSITE(direction);
10539 int hitting_side = direction;
10540 int touched_side = opposite_direction;
10542 int touched_element = MovingOrBlocked2Element(hitx, hity);
10545 boolean object_hit = (!IS_MOVING(hitx, hity) ||
10546 MovDir[hitx][hity] != direction ||
10547 ABS(MovPos[hitx][hity]) <= TILEY / 2);
10556 CheckElementChangeBySide(hitx, hity, touched_element, hitting_element,
10557 CE_HIT_BY_SOMETHING, opposite_direction);
10559 if (IS_CUSTOM_ELEMENT(hitting_element) &&
10560 HAS_ANY_CHANGE_EVENT(hitting_element, CE_OTHER_IS_HITTING))
10562 for (i = 0; i < element_info[hitting_element].num_change_pages; i++)
10564 struct ElementChangeInfo *change =
10565 &element_info[hitting_element].change_page[i];
10567 if (change->can_change &&
10568 change->events & CH_EVENT_BIT(CE_OTHER_IS_HITTING) &&
10569 change->trigger_side & touched_side &&
10572 IS_EQUAL_OR_IN_GROUP(touched_element, change->trigger_element)
10574 change->trigger_element == touched_element
10578 CheckElementChangeByPage(x, y, hitting_element, touched_element,
10579 CE_OTHER_IS_HITTING, i);
10585 if (IS_CUSTOM_ELEMENT(touched_element) &&
10586 HAS_ANY_CHANGE_EVENT(touched_element, CE_OTHER_GETS_HIT))
10588 for (i = 0; i < element_info[touched_element].num_change_pages; i++)
10590 struct ElementChangeInfo *change =
10591 &element_info[touched_element].change_page[i];
10593 if (change->can_change &&
10594 change->events & CH_EVENT_BIT(CE_OTHER_GETS_HIT) &&
10595 change->trigger_side & hitting_side &&
10597 IS_EQUAL_OR_IN_GROUP(hitting_element, change->trigger_element)
10599 change->trigger_element == hitting_element
10603 CheckElementChangeByPage(hitx, hity, touched_element,
10604 hitting_element, CE_OTHER_GETS_HIT, i);
10614 void TestIfElementSmashesCustomElement(int x, int y, int direction)
10616 int dx = (direction == MV_LEFT ? -1 : direction == MV_RIGHT ? +1 : 0);
10617 int dy = (direction == MV_UP ? -1 : direction == MV_DOWN ? +1 : 0);
10618 int hitx = x + dx, hity = y + dy;
10619 int hitting_element = Feld[x][y];
10620 int touched_element;
10622 boolean object_hit = (IN_LEV_FIELD(hitx, hity) &&
10623 !IS_FREE(hitx, hity) &&
10624 (!IS_MOVING(hitx, hity) ||
10625 MovDir[hitx][hity] != direction ||
10626 ABS(MovPos[hitx][hity]) <= TILEY / 2));
10629 if (IN_LEV_FIELD(hitx, hity) && IS_FREE(hitx, hity))
10633 if (IN_LEV_FIELD(hitx, hity) && !object_hit)
10637 touched_element = (IN_LEV_FIELD(hitx, hity) ?
10638 MovingOrBlocked2Element(hitx, hity) : EL_STEELWALL);
10640 CheckElementChangeBySide(x, y, hitting_element, touched_element,
10641 EP_CAN_SMASH_EVERYTHING, direction);
10643 if (IN_LEV_FIELD(hitx, hity))
10645 int opposite_direction = MV_DIR_OPPOSITE(direction);
10646 int hitting_side = direction;
10647 int touched_side = opposite_direction;
10649 int touched_element = MovingOrBlocked2Element(hitx, hity);
10652 boolean object_hit = (!IS_MOVING(hitx, hity) ||
10653 MovDir[hitx][hity] != direction ||
10654 ABS(MovPos[hitx][hity]) <= TILEY / 2);
10663 CheckElementChangeBySide(hitx, hity, touched_element, hitting_element,
10664 CE_SMASHED_BY_SOMETHING, opposite_direction);
10666 if (IS_CUSTOM_ELEMENT(hitting_element) &&
10667 HAS_ANY_CHANGE_EVENT(hitting_element, CE_OTHER_IS_SMASHING))
10669 for (i = 0; i < element_info[hitting_element].num_change_pages; i++)
10671 struct ElementChangeInfo *change =
10672 &element_info[hitting_element].change_page[i];
10674 if (change->can_change &&
10675 change->events & CH_EVENT_BIT(CE_OTHER_IS_SMASHING) &&
10676 change->trigger_side & touched_side &&
10679 IS_EQUAL_OR_IN_GROUP(touched_element, change->trigger_element)
10681 change->trigger_element == touched_element
10685 CheckElementChangeByPage(x, y, hitting_element, touched_element,
10686 CE_OTHER_IS_SMASHING, i);
10692 if (IS_CUSTOM_ELEMENT(touched_element) &&
10693 HAS_ANY_CHANGE_EVENT(touched_element, CE_OTHER_GETS_SMASHED))
10695 for (i = 0; i < element_info[touched_element].num_change_pages; i++)
10697 struct ElementChangeInfo *change =
10698 &element_info[touched_element].change_page[i];
10700 if (change->can_change &&
10701 change->events & CH_EVENT_BIT(CE_OTHER_GETS_SMASHED) &&
10702 change->trigger_side & hitting_side &&
10704 IS_EQUAL_OR_IN_GROUP(hitting_element, change->trigger_element)
10706 change->trigger_element == hitting_element
10710 CheckElementChangeByPage(hitx, hity, touched_element,
10711 hitting_element, CE_OTHER_GETS_SMASHED,i);
10721 void TestIfGoodThingHitsBadThing(int good_x, int good_y, int good_move_dir)
10723 int i, kill_x = -1, kill_y = -1;
10724 int bad_element = -1;
10725 static int test_xy[4][2] =
10732 static int test_dir[4] =
10740 for (i = 0; i < NUM_DIRECTIONS; i++)
10742 int test_x, test_y, test_move_dir, test_element;
10744 test_x = good_x + test_xy[i][0];
10745 test_y = good_y + test_xy[i][1];
10747 if (!IN_LEV_FIELD(test_x, test_y))
10751 (IS_MOVING(test_x, test_y) ? MovDir[test_x][test_y] : MV_NO_MOVING);
10754 test_element = Feld[test_x][test_y];
10756 test_element = MovingOrBlocked2ElementIfNotLeaving(test_x, test_y);
10759 /* 1st case: good thing is moving towards DONT_RUN_INTO style bad thing;
10760 2nd case: DONT_TOUCH style bad thing does not move away from good thing
10762 if ((DONT_RUN_INTO(test_element) && good_move_dir == test_dir[i]) ||
10763 (DONT_TOUCH(test_element) && test_move_dir != test_dir[i]))
10767 bad_element = test_element;
10773 if (kill_x != -1 || kill_y != -1)
10775 if (IS_PLAYER(good_x, good_y))
10777 struct PlayerInfo *player = PLAYERINFO(good_x, good_y);
10780 if (player->shield_deadly_time_left > 0 &&
10781 !IS_INDESTRUCTIBLE(bad_element))
10782 Bang(kill_x, kill_y);
10783 else if (!PLAYER_ENEMY_PROTECTED(good_x, good_y))
10786 if (player->shield_deadly_time_left > 0)
10787 Bang(kill_x, kill_y);
10788 else if (!PLAYER_ENEMY_PROTECTED(good_x, good_y))
10793 Bang(good_x, good_y);
10797 void TestIfBadThingHitsGoodThing(int bad_x, int bad_y, int bad_move_dir)
10799 int i, kill_x = -1, kill_y = -1;
10800 int bad_element = Feld[bad_x][bad_y];
10801 static int test_xy[4][2] =
10808 static int touch_dir[4] =
10810 MV_LEFT | MV_RIGHT,
10815 static int test_dir[4] =
10823 if (bad_element == EL_EXPLOSION) /* skip just exploding bad things */
10826 for (i = 0; i < NUM_DIRECTIONS; i++)
10828 int test_x, test_y, test_move_dir, test_element;
10830 test_x = bad_x + test_xy[i][0];
10831 test_y = bad_y + test_xy[i][1];
10832 if (!IN_LEV_FIELD(test_x, test_y))
10836 (IS_MOVING(test_x, test_y) ? MovDir[test_x][test_y] : MV_NO_MOVING);
10838 test_element = Feld[test_x][test_y];
10840 /* 1st case: good thing is moving towards DONT_RUN_INTO style bad thing;
10841 2nd case: DONT_TOUCH style bad thing does not move away from good thing
10843 if ((DONT_RUN_INTO(bad_element) && bad_move_dir == test_dir[i]) ||
10844 (DONT_TOUCH(bad_element) && test_move_dir != test_dir[i]))
10846 /* good thing is player or penguin that does not move away */
10847 if (IS_PLAYER(test_x, test_y))
10849 struct PlayerInfo *player = PLAYERINFO(test_x, test_y);
10851 if (bad_element == EL_ROBOT && player->is_moving)
10852 continue; /* robot does not kill player if he is moving */
10854 if (game.engine_version >= VERSION_IDENT(3,0,7,0))
10856 if (player->MovPos != 0 && !(player->MovDir & touch_dir[i]))
10857 continue; /* center and border element do not touch */
10864 else if (test_element == EL_PENGUIN)
10873 if (kill_x != -1 || kill_y != -1)
10875 if (IS_PLAYER(kill_x, kill_y))
10877 struct PlayerInfo *player = PLAYERINFO(kill_x, kill_y);
10880 if (player->shield_deadly_time_left > 0 &&
10881 !IS_INDESTRUCTIBLE(bad_element))
10882 Bang(bad_x, bad_y);
10883 else if (!PLAYER_ENEMY_PROTECTED(kill_x, kill_y))
10886 if (player->shield_deadly_time_left > 0)
10887 Bang(bad_x, bad_y);
10888 else if (!PLAYER_ENEMY_PROTECTED(kill_x, kill_y))
10893 Bang(kill_x, kill_y);
10897 void TestIfHeroTouchesBadThing(int x, int y)
10899 TestIfGoodThingHitsBadThing(x, y, MV_NO_MOVING);
10902 void TestIfHeroRunsIntoBadThing(int x, int y, int move_dir)
10904 TestIfGoodThingHitsBadThing(x, y, move_dir);
10907 void TestIfBadThingTouchesHero(int x, int y)
10909 TestIfBadThingHitsGoodThing(x, y, MV_NO_MOVING);
10912 void TestIfBadThingRunsIntoHero(int x, int y, int move_dir)
10914 TestIfBadThingHitsGoodThing(x, y, move_dir);
10917 void TestIfFriendTouchesBadThing(int x, int y)
10919 TestIfGoodThingHitsBadThing(x, y, MV_NO_MOVING);
10922 void TestIfBadThingTouchesFriend(int x, int y)
10924 TestIfBadThingHitsGoodThing(x, y, MV_NO_MOVING);
10927 void TestIfBadThingTouchesOtherBadThing(int bad_x, int bad_y)
10929 int i, kill_x = bad_x, kill_y = bad_y;
10930 static int xy[4][2] =
10938 for (i = 0; i < NUM_DIRECTIONS; i++)
10942 x = bad_x + xy[i][0];
10943 y = bad_y + xy[i][1];
10944 if (!IN_LEV_FIELD(x, y))
10947 element = Feld[x][y];
10948 if (IS_AMOEBOID(element) || element == EL_GAME_OF_LIFE ||
10949 element == EL_AMOEBA_GROWING || element == EL_AMOEBA_DROP)
10957 if (kill_x != bad_x || kill_y != bad_y)
10958 Bang(bad_x, bad_y);
10961 void KillHero(struct PlayerInfo *player)
10963 int jx = player->jx, jy = player->jy;
10965 if (!player->active)
10968 /* remove accessible field at the player's position */
10969 Feld[jx][jy] = EL_EMPTY;
10971 /* deactivate shield (else Bang()/Explode() would not work right) */
10972 player->shield_normal_time_left = 0;
10973 player->shield_deadly_time_left = 0;
10979 static void KillHeroUnlessEnemyProtected(int x, int y)
10981 if (!PLAYER_ENEMY_PROTECTED(x, y))
10982 KillHero(PLAYERINFO(x, y));
10985 static void KillHeroUnlessExplosionProtected(int x, int y)
10987 if (!PLAYER_EXPLOSION_PROTECTED(x, y))
10988 KillHero(PLAYERINFO(x, y));
10991 void BuryHero(struct PlayerInfo *player)
10993 int jx = player->jx, jy = player->jy;
10995 if (!player->active)
10999 PlayLevelSoundElementAction(jx, jy, player->element_nr, ACTION_DYING);
11001 PlayLevelSound(jx, jy, SND_CLASS_PLAYER_DYING);
11003 PlayLevelSound(jx, jy, SND_GAME_LOSING);
11005 player->GameOver = TRUE;
11006 RemoveHero(player);
11009 void RemoveHero(struct PlayerInfo *player)
11011 int jx = player->jx, jy = player->jy;
11012 int i, found = FALSE;
11014 player->present = FALSE;
11015 player->active = FALSE;
11017 if (!ExplodeField[jx][jy])
11018 StorePlayer[jx][jy] = 0;
11020 for (i = 0; i < MAX_PLAYERS; i++)
11021 if (stored_player[i].active)
11025 AllPlayersGone = TRUE;
11032 =============================================================================
11033 checkDiagonalPushing()
11034 -----------------------------------------------------------------------------
11035 check if diagonal input device direction results in pushing of object
11036 (by checking if the alternative direction is walkable, diggable, ...)
11037 =============================================================================
11040 static boolean checkDiagonalPushing(struct PlayerInfo *player,
11041 int x, int y, int real_dx, int real_dy)
11043 int jx, jy, dx, dy, xx, yy;
11045 if (real_dx == 0 || real_dy == 0) /* no diagonal direction => push */
11048 /* diagonal direction: check alternative direction */
11053 xx = jx + (dx == 0 ? real_dx : 0);
11054 yy = jy + (dy == 0 ? real_dy : 0);
11056 return (!IN_LEV_FIELD(xx, yy) || IS_SOLID_FOR_PUSHING(Feld[xx][yy]));
11060 =============================================================================
11062 -----------------------------------------------------------------------------
11063 x, y: field next to player (non-diagonal) to try to dig to
11064 real_dx, real_dy: direction as read from input device (can be diagonal)
11065 =============================================================================
11068 int DigField(struct PlayerInfo *player,
11069 int oldx, int oldy, int x, int y,
11070 int real_dx, int real_dy, int mode)
11073 boolean use_spring_bug = (game.engine_version < VERSION_IDENT(2,2,0,0));
11075 boolean is_player = (IS_PLAYER(oldx, oldy) || mode != DF_DIG);
11076 boolean player_was_pushing = player->is_pushing;
11077 int jx = oldx, jy = oldy;
11078 int dx = x - jx, dy = y - jy;
11079 int nextx = x + dx, nexty = y + dy;
11080 int move_direction = (dx == -1 ? MV_LEFT :
11081 dx == +1 ? MV_RIGHT :
11083 dy == +1 ? MV_DOWN : MV_NO_MOVING);
11084 int opposite_direction = MV_DIR_OPPOSITE(move_direction);
11086 int dig_side = MV_DIR_OPPOSITE(move_direction);
11088 static int trigger_sides[4] =
11090 CH_SIDE_RIGHT, /* moving left */
11091 CH_SIDE_LEFT, /* moving right */
11092 CH_SIDE_BOTTOM, /* moving up */
11093 CH_SIDE_TOP, /* moving down */
11095 int dig_side = trigger_sides[MV_DIR_BIT(move_direction)];
11097 int old_element = Feld[jx][jy];
11100 if (is_player) /* function can also be called by EL_PENGUIN */
11102 if (player->MovPos == 0)
11104 player->is_digging = FALSE;
11105 player->is_collecting = FALSE;
11108 if (player->MovPos == 0) /* last pushing move finished */
11109 player->is_pushing = FALSE;
11111 if (mode == DF_NO_PUSH) /* player just stopped pushing */
11113 player->is_switching = FALSE;
11114 #if USE_NEW_PUSH_DELAY
11115 player->push_delay = -1;
11117 player->push_delay = 0;
11120 return MF_NO_ACTION;
11124 if (IS_MOVING(x, y) || IS_PLAYER(x, y))
11125 return MF_NO_ACTION;
11130 if (IS_TUBE(Feld[jx][jy]) || IS_TUBE(Back[jx][jy]))
11132 if (IS_TUBE(Feld[jx][jy]) ||
11133 (IS_TUBE(Back[jx][jy]) && game.engine_version >= VERSION_IDENT(2,2,0,0)))
11137 int tube_element = (IS_TUBE(Feld[jx][jy]) ? Feld[jx][jy] : Back[jx][jy]);
11138 int tube_leave_directions[][2] =
11140 { EL_TUBE_ANY, MV_LEFT | MV_RIGHT | MV_UP | MV_DOWN },
11141 { EL_TUBE_VERTICAL, MV_UP | MV_DOWN },
11142 { EL_TUBE_HORIZONTAL, MV_LEFT | MV_RIGHT },
11143 { EL_TUBE_VERTICAL_LEFT, MV_LEFT | MV_UP | MV_DOWN },
11144 { EL_TUBE_VERTICAL_RIGHT, MV_RIGHT | MV_UP | MV_DOWN },
11145 { EL_TUBE_HORIZONTAL_UP, MV_LEFT | MV_RIGHT | MV_UP },
11146 { EL_TUBE_HORIZONTAL_DOWN, MV_LEFT | MV_RIGHT | MV_DOWN },
11147 { EL_TUBE_LEFT_UP, MV_LEFT | MV_UP },
11148 { EL_TUBE_LEFT_DOWN, MV_LEFT | MV_DOWN },
11149 { EL_TUBE_RIGHT_UP, MV_RIGHT | MV_UP },
11150 { EL_TUBE_RIGHT_DOWN, MV_RIGHT | MV_DOWN },
11151 { -1, MV_LEFT | MV_RIGHT | MV_UP | MV_DOWN }
11154 while (tube_leave_directions[i][0] != tube_element)
11157 if (tube_leave_directions[i][0] == -1) /* should not happen */
11161 if (!(tube_leave_directions[i][1] & move_direction))
11162 return MF_NO_ACTION; /* tube has no opening in this direction */
11167 if (IS_TUBE(Back[jx][jy]) && game.engine_version >= VERSION_IDENT(2,2,0,0))
11168 old_element = Back[jx][jy];
11172 if (IS_WALKABLE(old_element) && !ACCESS_FROM(old_element, move_direction))
11173 return MF_NO_ACTION; /* field has no opening in this direction */
11175 if (IS_PASSABLE(old_element) && !ACCESS_FROM(old_element,opposite_direction))
11176 return MF_NO_ACTION; /* field has no opening in this direction */
11178 element = Feld[x][y];
11180 if (!is_player && !IS_COLLECTIBLE(element)) /* penguin cannot collect it */
11181 return MF_NO_ACTION;
11183 if (mode == DF_SNAP && !IS_SNAPPABLE(element) &&
11184 game.engine_version >= VERSION_IDENT(2,2,0,0))
11185 return MF_NO_ACTION;
11188 if (game.gravity && is_player && !player->is_auto_moving &&
11189 canFallDown(player) && move_direction != MV_DOWN &&
11190 !canMoveToValidFieldWithGravity(jx, jy, move_direction))
11191 return MF_NO_ACTION; /* player cannot walk here due to gravity */
11195 if (element == EL_EMPTY_SPACE &&
11196 game.gravity && !player->is_auto_moving &&
11197 canFallDown(player) && move_direction != MV_DOWN)
11198 return MF_NO_ACTION; /* player cannot walk here due to gravity */
11204 case EL_SP_PORT_LEFT:
11205 case EL_SP_PORT_RIGHT:
11206 case EL_SP_PORT_UP:
11207 case EL_SP_PORT_DOWN:
11208 case EL_SP_PORT_HORIZONTAL:
11209 case EL_SP_PORT_VERTICAL:
11210 case EL_SP_PORT_ANY:
11211 case EL_SP_GRAVITY_PORT_LEFT:
11212 case EL_SP_GRAVITY_PORT_RIGHT:
11213 case EL_SP_GRAVITY_PORT_UP:
11214 case EL_SP_GRAVITY_PORT_DOWN:
11216 if (!canEnterSupaplexPort(x, y, dx, dy))
11217 return MF_NO_ACTION;
11220 element != EL_SP_PORT_LEFT &&
11221 element != EL_SP_GRAVITY_PORT_LEFT &&
11222 element != EL_SP_PORT_HORIZONTAL &&
11223 element != EL_SP_PORT_ANY) ||
11225 element != EL_SP_PORT_RIGHT &&
11226 element != EL_SP_GRAVITY_PORT_RIGHT &&
11227 element != EL_SP_PORT_HORIZONTAL &&
11228 element != EL_SP_PORT_ANY) ||
11230 element != EL_SP_PORT_UP &&
11231 element != EL_SP_GRAVITY_PORT_UP &&
11232 element != EL_SP_PORT_VERTICAL &&
11233 element != EL_SP_PORT_ANY) ||
11235 element != EL_SP_PORT_DOWN &&
11236 element != EL_SP_GRAVITY_PORT_DOWN &&
11237 element != EL_SP_PORT_VERTICAL &&
11238 element != EL_SP_PORT_ANY) ||
11239 !IN_LEV_FIELD(nextx, nexty) ||
11240 !IS_FREE(nextx, nexty))
11241 return MF_NO_ACTION;
11244 if (element == EL_SP_GRAVITY_PORT_LEFT ||
11245 element == EL_SP_GRAVITY_PORT_RIGHT ||
11246 element == EL_SP_GRAVITY_PORT_UP ||
11247 element == EL_SP_GRAVITY_PORT_DOWN)
11248 game.gravity = !game.gravity;
11250 /* automatically move to the next field with double speed */
11251 player->programmed_action = move_direction;
11253 if (player->move_delay_reset_counter == 0)
11255 player->move_delay_reset_counter = 2; /* two double speed steps */
11257 DOUBLE_PLAYER_SPEED(player);
11260 player->move_delay_reset_counter = 2;
11262 DOUBLE_PLAYER_SPEED(player);
11266 printf("::: passing port %d,%d [%d]\n", x, y, FrameCounter);
11269 PlayLevelSound(x, y, SND_CLASS_SP_PORT_PASSING);
11275 case EL_TUBE_VERTICAL:
11276 case EL_TUBE_HORIZONTAL:
11277 case EL_TUBE_VERTICAL_LEFT:
11278 case EL_TUBE_VERTICAL_RIGHT:
11279 case EL_TUBE_HORIZONTAL_UP:
11280 case EL_TUBE_HORIZONTAL_DOWN:
11281 case EL_TUBE_LEFT_UP:
11282 case EL_TUBE_LEFT_DOWN:
11283 case EL_TUBE_RIGHT_UP:
11284 case EL_TUBE_RIGHT_DOWN:
11287 int tube_enter_directions[][2] =
11289 { EL_TUBE_ANY, MV_LEFT | MV_RIGHT | MV_UP | MV_DOWN },
11290 { EL_TUBE_VERTICAL, MV_UP | MV_DOWN },
11291 { EL_TUBE_HORIZONTAL, MV_LEFT | MV_RIGHT },
11292 { EL_TUBE_VERTICAL_LEFT, MV_RIGHT | MV_UP | MV_DOWN },
11293 { EL_TUBE_VERTICAL_RIGHT, MV_LEFT | MV_UP | MV_DOWN },
11294 { EL_TUBE_HORIZONTAL_UP, MV_LEFT | MV_RIGHT | MV_DOWN },
11295 { EL_TUBE_HORIZONTAL_DOWN, MV_LEFT | MV_RIGHT | MV_UP },
11296 { EL_TUBE_LEFT_UP, MV_RIGHT | MV_DOWN },
11297 { EL_TUBE_LEFT_DOWN, MV_RIGHT | MV_UP },
11298 { EL_TUBE_RIGHT_UP, MV_LEFT | MV_DOWN },
11299 { EL_TUBE_RIGHT_DOWN, MV_LEFT | MV_UP },
11300 { -1, MV_NO_MOVING }
11303 while (tube_enter_directions[i][0] != element)
11306 if (tube_enter_directions[i][0] == -1) /* should not happen */
11310 if (!(tube_enter_directions[i][1] & move_direction))
11311 return MF_NO_ACTION; /* tube has no opening in this direction */
11313 PlayLevelSound(x, y, SND_CLASS_TUBE_WALKING);
11321 if (IS_WALKABLE(element) && ACCESS_FROM(element, opposite_direction))
11323 if (IS_WALKABLE(element))
11326 int sound_element = SND_ELEMENT(element);
11327 int sound_action = ACTION_WALKING;
11330 if (!ACCESS_FROM(element, opposite_direction))
11331 return MF_NO_ACTION; /* field not accessible from this direction */
11335 if (element == EL_EMPTY_SPACE &&
11336 game.gravity && !player->is_auto_moving &&
11337 canFallDown(player) && move_direction != MV_DOWN)
11338 return MF_NO_ACTION; /* player cannot walk here due to gravity */
11341 if (IS_GATE(element))
11343 if (!player->key[element - EL_GATE_1])
11344 return MF_NO_ACTION;
11346 else if (IS_GATE_GRAY(element))
11348 if (!player->key[element - EL_GATE_1_GRAY])
11349 return MF_NO_ACTION;
11351 else if (element == EL_EXIT_OPEN ||
11352 element == EL_SP_EXIT_OPEN ||
11353 element == EL_SP_EXIT_OPENING)
11355 sound_action = ACTION_PASSING; /* player is passing exit */
11357 else if (element == EL_EMPTY)
11359 sound_action = ACTION_MOVING; /* nothing to walk on */
11362 /* play sound from background or player, whatever is available */
11363 if (element_info[sound_element].sound[sound_action] != SND_UNDEFINED)
11364 PlayLevelSoundElementAction(x, y, sound_element, sound_action);
11366 PlayLevelSoundElementAction(x, y, player->element_nr, sound_action);
11371 else if (IS_PASSABLE(element) && canPassField(x, y, move_direction))
11373 else if (IS_PASSABLE(element))
11377 if (!canPassField(x, y, move_direction))
11378 return MF_NO_ACTION;
11383 if (!IN_LEV_FIELD(nextx, nexty) || IS_PLAYER(nextx, nexty) ||
11384 !IS_WALKABLE_FROM(Feld[nextx][nexty], move_direction) ||
11385 (!level.can_pass_to_walkable && !IS_FREE(nextx, nexty)))
11386 return MF_NO_ACTION;
11388 if (!IN_LEV_FIELD(nextx, nexty) || !IS_FREE(nextx, nexty))
11389 return MF_NO_ACTION;
11394 if (!ACCESS_FROM(element, opposite_direction))
11395 return MF_NO_ACTION; /* field not accessible from this direction */
11397 if (IS_CUSTOM_ELEMENT(element) &&
11398 !ACCESS_FROM(element, opposite_direction))
11399 return MF_NO_ACTION; /* field not accessible from this direction */
11403 if (CAN_MOVE(element)) /* only fixed elements can be passed! */
11404 return MF_NO_ACTION;
11409 if (IS_EM_GATE(element))
11411 if (!player->key[element - EL_EM_GATE_1])
11412 return MF_NO_ACTION;
11414 else if (IS_EM_GATE_GRAY(element))
11416 if (!player->key[element - EL_EM_GATE_1_GRAY])
11417 return MF_NO_ACTION;
11419 else if (IS_SP_PORT(element))
11421 if (element == EL_SP_GRAVITY_PORT_LEFT ||
11422 element == EL_SP_GRAVITY_PORT_RIGHT ||
11423 element == EL_SP_GRAVITY_PORT_UP ||
11424 element == EL_SP_GRAVITY_PORT_DOWN)
11425 game.gravity = !game.gravity;
11426 else if (element == EL_SP_GRAVITY_ON_PORT_LEFT ||
11427 element == EL_SP_GRAVITY_ON_PORT_RIGHT ||
11428 element == EL_SP_GRAVITY_ON_PORT_UP ||
11429 element == EL_SP_GRAVITY_ON_PORT_DOWN)
11430 game.gravity = TRUE;
11431 else if (element == EL_SP_GRAVITY_OFF_PORT_LEFT ||
11432 element == EL_SP_GRAVITY_OFF_PORT_RIGHT ||
11433 element == EL_SP_GRAVITY_OFF_PORT_UP ||
11434 element == EL_SP_GRAVITY_OFF_PORT_DOWN)
11435 game.gravity = FALSE;
11438 /* automatically move to the next field with double speed */
11439 player->programmed_action = move_direction;
11441 if (player->move_delay_reset_counter == 0)
11443 player->move_delay_reset_counter = 2; /* two double speed steps */
11445 DOUBLE_PLAYER_SPEED(player);
11448 player->move_delay_reset_counter = 2;
11450 DOUBLE_PLAYER_SPEED(player);
11453 PlayLevelSoundAction(x, y, ACTION_PASSING);
11457 else if (IS_DIGGABLE(element))
11461 if (mode != DF_SNAP)
11464 GfxElement[x][y] = GFX_ELEMENT(element);
11467 (GFX_CRUMBLED(element) ? EL_SAND : GFX_ELEMENT(element));
11469 player->is_digging = TRUE;
11472 PlayLevelSoundElementAction(x, y, element, ACTION_DIGGING);
11474 CheckTriggeredElementChangeByPlayer(x, y, element,CE_OTHER_GETS_DIGGED,
11475 player->index_bit, dig_side);
11478 if (mode == DF_SNAP)
11479 TestIfElementTouchesCustomElement(x, y); /* for empty space */
11484 else if (IS_COLLECTIBLE(element))
11488 if (is_player && mode != DF_SNAP)
11490 GfxElement[x][y] = element;
11491 player->is_collecting = TRUE;
11494 if (element == EL_SPEED_PILL)
11495 player->move_delay_value = MOVE_DELAY_HIGH_SPEED;
11496 else if (element == EL_EXTRA_TIME && level.time > 0)
11499 DrawGameValue_Time(TimeLeft);
11501 else if (element == EL_SHIELD_NORMAL || element == EL_SHIELD_DEADLY)
11503 player->shield_normal_time_left += 10;
11504 if (element == EL_SHIELD_DEADLY)
11505 player->shield_deadly_time_left += 10;
11507 else if (element == EL_DYNAMITE || element == EL_SP_DISK_RED)
11509 if (player->inventory_size < MAX_INVENTORY_SIZE)
11510 player->inventory_element[player->inventory_size++] = element;
11512 DrawGameValue_Dynamite(local_player->inventory_size);
11514 else if (element == EL_DYNABOMB_INCREASE_NUMBER)
11516 player->dynabomb_count++;
11517 player->dynabombs_left++;
11519 else if (element == EL_DYNABOMB_INCREASE_SIZE)
11521 player->dynabomb_size++;
11523 else if (element == EL_DYNABOMB_INCREASE_POWER)
11525 player->dynabomb_xl = TRUE;
11527 else if ((element >= EL_KEY_1 && element <= EL_KEY_4) ||
11528 (element >= EL_EM_KEY_1 && element <= EL_EM_KEY_4))
11530 int key_nr = (element >= EL_KEY_1 && element <= EL_KEY_4 ?
11531 element - EL_KEY_1 : element - EL_EM_KEY_1);
11533 player->key[key_nr] = TRUE;
11535 DrawGameValue_Keys(player);
11537 redraw_mask |= REDRAW_DOOR_1;
11539 else if (IS_ENVELOPE(element))
11542 player->show_envelope = element;
11544 ShowEnvelope(element - EL_ENVELOPE_1);
11547 else if (IS_DROPPABLE(element) ||
11548 IS_THROWABLE(element)) /* can be collected and dropped */
11552 if (element_info[element].collect_count == 0)
11553 player->inventory_infinite_element = element;
11555 for (i = 0; i < element_info[element].collect_count; i++)
11556 if (player->inventory_size < MAX_INVENTORY_SIZE)
11557 player->inventory_element[player->inventory_size++] = element;
11559 DrawGameValue_Dynamite(local_player->inventory_size);
11561 else if (element_info[element].collect_count > 0)
11563 local_player->gems_still_needed -=
11564 element_info[element].collect_count;
11565 if (local_player->gems_still_needed < 0)
11566 local_player->gems_still_needed = 0;
11568 DrawGameValue_Emeralds(local_player->gems_still_needed);
11571 RaiseScoreElement(element);
11572 PlayLevelSoundElementAction(x, y, element, ACTION_COLLECTING);
11575 CheckTriggeredElementChangeByPlayer(x, y, element,
11576 CE_OTHER_GETS_COLLECTED,
11577 player->index_bit, dig_side);
11580 if (mode == DF_SNAP)
11581 TestIfElementTouchesCustomElement(x, y); /* for empty space */
11586 else if (IS_PUSHABLE(element))
11588 if (mode == DF_SNAP && element != EL_BD_ROCK)
11589 return MF_NO_ACTION;
11591 if (CAN_FALL(element) && dy)
11592 return MF_NO_ACTION;
11594 if (CAN_FALL(element) && IN_LEV_FIELD(x, y + 1) && IS_FREE(x, y + 1) &&
11595 !(element == EL_SPRING && level.use_spring_bug))
11596 return MF_NO_ACTION;
11599 if (CAN_MOVE(element) && GET_MAX_MOVE_DELAY(element) == 0 &&
11600 ((move_direction & MV_VERTICAL &&
11601 ((element_info[element].move_pattern & MV_LEFT &&
11602 IN_LEV_FIELD(x - 1, y) && IS_FREE(x - 1, y)) ||
11603 (element_info[element].move_pattern & MV_RIGHT &&
11604 IN_LEV_FIELD(x + 1, y) && IS_FREE(x + 1, y)))) ||
11605 (move_direction & MV_HORIZONTAL &&
11606 ((element_info[element].move_pattern & MV_UP &&
11607 IN_LEV_FIELD(x, y - 1) && IS_FREE(x, y - 1)) ||
11608 (element_info[element].move_pattern & MV_DOWN &&
11609 IN_LEV_FIELD(x, y + 1) && IS_FREE(x, y + 1))))))
11610 return MF_NO_ACTION;
11614 /* do not push elements already moving away faster than player */
11615 if (CAN_MOVE(element) && MovDir[x][y] == move_direction &&
11616 ABS(getElementMoveStepsize(x, y)) > MOVE_STEPSIZE_NORMAL)
11617 return MF_NO_ACTION;
11619 if (element == EL_SPRING && MovDir[x][y] != MV_NO_MOVING)
11620 return MF_NO_ACTION;
11626 if (game.engine_version >= VERSION_IDENT(3,1,0,0))
11628 if (player->push_delay_value == -1 || !player_was_pushing)
11629 player->push_delay_value = GET_NEW_PUSH_DELAY(element);
11631 else if (game.engine_version >= VERSION_IDENT(3,0,7,1))
11633 if (player->push_delay_value == -1)
11634 player->push_delay_value = GET_NEW_PUSH_DELAY(element);
11637 if (game.engine_version >= VERSION_IDENT(3,0,7,1))
11639 if (player->push_delay_value == -1 || !player_was_pushing)
11640 player->push_delay_value = GET_NEW_PUSH_DELAY(element);
11643 else if (game.engine_version >= VERSION_IDENT(2,2,0,7))
11645 if (!player->is_pushing)
11646 player->push_delay_value = GET_NEW_PUSH_DELAY(element);
11650 if (game.engine_version >= VERSION_IDENT(2,2,0,7) &&
11651 (game.engine_version < VERSION_IDENT(3,0,7,1) ||
11652 !player_is_pushing))
11653 player->push_delay_value = GET_NEW_PUSH_DELAY(element);
11656 if (!player->is_pushing &&
11657 game.engine_version >= VERSION_IDENT(2,2,0,7))
11658 player->push_delay_value = GET_NEW_PUSH_DELAY(element);
11662 printf("::: push delay: %ld -> %ld [%d, %d] [%d / %d] [%d '%s': %d]\n",
11663 player->push_delay, player->push_delay_value,
11664 FrameCounter, game.engine_version,
11665 player_was_pushing, player->is_pushing,
11666 element, element_info[element].token_name,
11667 GET_NEW_PUSH_DELAY(element));
11670 player->is_pushing = TRUE;
11672 if (!(IN_LEV_FIELD(nextx, nexty) &&
11673 (IS_FREE(nextx, nexty) ||
11674 (Feld[nextx][nexty] == EL_SOKOBAN_FIELD_EMPTY &&
11675 IS_SB_ELEMENT(element)))))
11676 return MF_NO_ACTION;
11678 if (!checkDiagonalPushing(player, x, y, real_dx, real_dy))
11679 return MF_NO_ACTION;
11681 #if USE_NEW_PUSH_DELAY
11684 if ( (player->push_delay == -1) != (player->push_delay2 == 0) )
11685 printf("::: ALERT: %d, %d [%d / %d]\n",
11686 player->push_delay, player->push_delay2,
11687 FrameCounter, FrameCounter / 50);
11690 if (player->push_delay == -1) /* new pushing; restart delay */
11691 player->push_delay = 0;
11693 if (player->push_delay == 0) /* new pushing; restart delay */
11694 player->push_delay = FrameCounter;
11697 #if USE_NEW_PUSH_DELAY
11699 if ( (player->push_delay > 0) != (!xxx_fr) )
11700 printf("::: PUSH BUG! %d, (%d -> %d) %d [%d / %d]\n",
11701 player->push_delay,
11702 xxx_pdv2, player->push_delay2, player->push_delay_value,
11703 FrameCounter, FrameCounter / 50);
11707 if (player->push_delay > 0 &&
11708 !(tape.playing && tape.file_version < FILE_VERSION_2_0) &&
11709 element != EL_SPRING && element != EL_BALLOON)
11712 if (player->push_delay < player->push_delay_value &&
11713 !(tape.playing && tape.file_version < FILE_VERSION_2_0) &&
11714 element != EL_SPRING && element != EL_BALLOON)
11718 if (!FrameReached(&player->push_delay, player->push_delay_value) &&
11719 !(tape.playing && tape.file_version < FILE_VERSION_2_0) &&
11720 element != EL_SPRING && element != EL_BALLOON)
11723 /* make sure that there is no move delay before next try to push */
11724 #if USE_NEW_MOVE_DELAY
11725 if (game.engine_version >= VERSION_IDENT(3,0,7,1))
11726 player->move_delay = 0;
11728 if (game.engine_version >= VERSION_IDENT(3,0,7,1))
11729 player->move_delay = INITIAL_MOVE_DELAY_OFF;
11732 return MF_NO_ACTION;
11736 printf("::: NOW PUSHING... [%d]\n", FrameCounter);
11739 if (IS_SB_ELEMENT(element))
11741 if (element == EL_SOKOBAN_FIELD_FULL)
11743 Back[x][y] = EL_SOKOBAN_FIELD_EMPTY;
11744 local_player->sokobanfields_still_needed++;
11747 if (Feld[nextx][nexty] == EL_SOKOBAN_FIELD_EMPTY)
11749 Back[nextx][nexty] = EL_SOKOBAN_FIELD_EMPTY;
11750 local_player->sokobanfields_still_needed--;
11753 Feld[x][y] = EL_SOKOBAN_OBJECT;
11755 if (Back[x][y] == Back[nextx][nexty])
11756 PlayLevelSoundAction(x, y, ACTION_PUSHING);
11757 else if (Back[x][y] != 0)
11758 PlayLevelSoundElementAction(x, y, EL_SOKOBAN_FIELD_FULL,
11761 PlayLevelSoundElementAction(nextx, nexty, EL_SOKOBAN_FIELD_EMPTY,
11764 if (local_player->sokobanfields_still_needed == 0 &&
11765 game.emulation == EMU_SOKOBAN)
11767 player->LevelSolved = player->GameOver = TRUE;
11768 PlayLevelSound(x, y, SND_GAME_SOKOBAN_SOLVING);
11772 PlayLevelSoundElementAction(x, y, element, ACTION_PUSHING);
11774 InitMovingField(x, y, move_direction);
11775 GfxAction[x][y] = ACTION_PUSHING;
11777 if (mode == DF_SNAP)
11778 ContinueMoving(x, y);
11780 MovPos[x][y] = (dx != 0 ? dx : dy);
11782 Pushed[x][y] = TRUE;
11783 Pushed[nextx][nexty] = TRUE;
11785 if (game.engine_version < VERSION_IDENT(2,2,0,7))
11786 player->push_delay_value = GET_NEW_PUSH_DELAY(element);
11788 player->push_delay_value = -1; /* get new value later */
11790 #if USE_PUSH_BUGFIX
11791 /* now: check for element change _after_ element has been pushed! */
11793 if (game.use_bug_change_when_pushing)
11795 if (game.engine_version < VERSION_IDENT(3,1,0,0))
11798 CheckElementChangeByPlayer(x, y, element, CE_PUSHED_BY_PLAYER,
11799 player->index_bit, dig_side);
11800 CheckTriggeredElementChangeByPlayer(x,y,element,CE_OTHER_GETS_PUSHED,
11801 player->index_bit, dig_side);
11807 /* check for element change _after_ element has been pushed! */
11811 /* !!! TEST ONLY !!! */
11812 CheckElementChangeByPlayer(x, y, element, CE_PUSHED_BY_PLAYER,
11813 player->index_bit, dig_side);
11814 CheckTriggeredElementChangeByPlayer(x, y, element,CE_OTHER_GETS_PUSHED,
11815 player->index_bit, dig_side);
11817 CheckTriggeredElementChangeByPlayer(x, y, element,CE_OTHER_GETS_PUSHED,
11818 player->index_bit, dig_side);
11819 CheckElementChangeByPlayer(x, y, element, CE_PUSHED_BY_PLAYER,
11820 player->index_bit, dig_side);
11828 else if (IS_SWITCHABLE(element))
11830 if (PLAYER_SWITCHING(player, x, y))
11832 CheckTriggeredElementChangeByPlayer(x,y, element,
11833 CE_OTHER_GETS_PRESSED,
11834 player->index_bit, dig_side);
11839 player->is_switching = TRUE;
11840 player->switch_x = x;
11841 player->switch_y = y;
11843 PlayLevelSoundElementAction(x, y, element, ACTION_ACTIVATING);
11845 if (element == EL_ROBOT_WHEEL)
11847 Feld[x][y] = EL_ROBOT_WHEEL_ACTIVE;
11851 DrawLevelField(x, y);
11853 else if (element == EL_SP_TERMINAL)
11857 for (yy = 0; yy < lev_fieldy; yy++) for (xx=0; xx < lev_fieldx; xx++)
11859 if (Feld[xx][yy] == EL_SP_DISK_YELLOW)
11861 else if (Feld[xx][yy] == EL_SP_TERMINAL)
11862 Feld[xx][yy] = EL_SP_TERMINAL_ACTIVE;
11865 else if (IS_BELT_SWITCH(element))
11867 ToggleBeltSwitch(x, y);
11869 else if (element == EL_SWITCHGATE_SWITCH_UP ||
11870 element == EL_SWITCHGATE_SWITCH_DOWN)
11872 ToggleSwitchgateSwitch(x, y);
11874 else if (element == EL_LIGHT_SWITCH ||
11875 element == EL_LIGHT_SWITCH_ACTIVE)
11877 ToggleLightSwitch(x, y);
11880 PlayLevelSound(x, y, element == EL_LIGHT_SWITCH ?
11881 SND_LIGHT_SWITCH_ACTIVATING :
11882 SND_LIGHT_SWITCH_DEACTIVATING);
11885 else if (element == EL_TIMEGATE_SWITCH)
11887 ActivateTimegateSwitch(x, y);
11889 else if (element == EL_BALLOON_SWITCH_LEFT ||
11890 element == EL_BALLOON_SWITCH_RIGHT ||
11891 element == EL_BALLOON_SWITCH_UP ||
11892 element == EL_BALLOON_SWITCH_DOWN ||
11893 element == EL_BALLOON_SWITCH_ANY)
11895 if (element == EL_BALLOON_SWITCH_ANY)
11896 game.balloon_dir = move_direction;
11898 game.balloon_dir = (element == EL_BALLOON_SWITCH_LEFT ? MV_LEFT :
11899 element == EL_BALLOON_SWITCH_RIGHT ? MV_RIGHT :
11900 element == EL_BALLOON_SWITCH_UP ? MV_UP :
11901 element == EL_BALLOON_SWITCH_DOWN ? MV_DOWN :
11904 else if (element == EL_LAMP)
11906 Feld[x][y] = EL_LAMP_ACTIVE;
11907 local_player->lights_still_needed--;
11909 DrawLevelField(x, y);
11911 else if (element == EL_TIME_ORB_FULL)
11913 Feld[x][y] = EL_TIME_ORB_EMPTY;
11915 DrawGameValue_Time(TimeLeft);
11917 DrawLevelField(x, y);
11920 PlaySoundStereo(SND_TIME_ORB_FULL_COLLECTING, SOUND_MIDDLE);
11924 CheckTriggeredElementChangeByPlayer(x, y, element,
11925 CE_OTHER_IS_SWITCHING,
11926 player->index_bit, dig_side);
11928 CheckTriggeredElementChangeByPlayer(x,y, element,CE_OTHER_GETS_PRESSED,
11929 player->index_bit, dig_side);
11935 if (!PLAYER_SWITCHING(player, x, y))
11937 player->is_switching = TRUE;
11938 player->switch_x = x;
11939 player->switch_y = y;
11942 /* !!! TEST ONLY !!! */
11943 CheckElementChangeByPlayer(x, y, element, CE_SWITCHED,
11944 player->index_bit, dig_side);
11945 CheckTriggeredElementChangeByPlayer(x, y, element,
11946 CE_OTHER_IS_SWITCHING,
11947 player->index_bit, dig_side);
11949 CheckTriggeredElementChangeByPlayer(x, y, element,
11950 CE_OTHER_IS_SWITCHING,
11951 player->index_bit, dig_side);
11952 CheckElementChangeByPlayer(x, y, element, CE_SWITCHED,
11953 player->index_bit, dig_side);
11958 /* !!! TEST ONLY !!! (this breaks "machine", level 000) */
11959 CheckElementChangeByPlayer(x, y, element, CE_PRESSED_BY_PLAYER,
11960 player->index_bit, dig_side);
11961 CheckTriggeredElementChangeByPlayer(x,y, element,CE_OTHER_GETS_PRESSED,
11962 player->index_bit, dig_side);
11964 CheckTriggeredElementChangeByPlayer(x,y, element,CE_OTHER_GETS_PRESSED,
11965 player->index_bit, dig_side);
11966 CheckElementChangeByPlayer(x, y, element, CE_PRESSED_BY_PLAYER,
11967 player->index_bit, dig_side);
11971 return MF_NO_ACTION;
11974 #if USE_NEW_PUSH_DELAY
11975 player->push_delay = -1;
11977 player->push_delay = 0;
11980 if (Feld[x][y] != element) /* really digged/collected something */
11981 player->is_collecting = !player->is_digging;
11986 boolean SnapField(struct PlayerInfo *player, int dx, int dy)
11988 int jx = player->jx, jy = player->jy;
11989 int x = jx + dx, y = jy + dy;
11990 int snap_direction = (dx == -1 ? MV_LEFT :
11991 dx == +1 ? MV_RIGHT :
11993 dy == +1 ? MV_DOWN : MV_NO_MOVING);
11996 if (player->MovPos != 0)
11999 if (player->MovPos != 0 && game.engine_version >= VERSION_IDENT(2,2,0,0))
12003 if (!player->active || !IN_LEV_FIELD(x, y))
12011 if (player->MovPos == 0)
12012 player->is_pushing = FALSE;
12014 player->is_snapping = FALSE;
12016 if (player->MovPos == 0)
12018 player->is_moving = FALSE;
12019 player->is_digging = FALSE;
12020 player->is_collecting = FALSE;
12026 if (player->is_snapping)
12029 player->MovDir = snap_direction;
12032 if (player->MovPos == 0)
12035 player->is_moving = FALSE;
12036 player->is_digging = FALSE;
12037 player->is_collecting = FALSE;
12040 player->is_dropping = FALSE;
12042 if (DigField(player, jx, jy, x, y, 0, 0, DF_SNAP) == MF_NO_ACTION)
12045 player->is_snapping = TRUE;
12048 if (player->MovPos == 0)
12051 player->is_moving = FALSE;
12052 player->is_digging = FALSE;
12053 player->is_collecting = FALSE;
12057 if (player->MovPos != 0) /* prevent graphic bugs in versions < 2.2.0 */
12058 DrawLevelField(player->last_jx, player->last_jy);
12061 DrawLevelField(x, y);
12070 boolean DropElement(struct PlayerInfo *player)
12072 int old_element, new_element;
12073 int dropx = player->jx, dropy = player->jy;
12074 int drop_direction = player->MovDir;
12076 int drop_side = drop_direction;
12078 static int trigger_sides[4] =
12080 CH_SIDE_LEFT, /* dropping left */
12081 CH_SIDE_RIGHT, /* dropping right */
12082 CH_SIDE_TOP, /* dropping up */
12083 CH_SIDE_BOTTOM, /* dropping down */
12085 int drop_side = trigger_sides[MV_DIR_BIT(drop_direction)];
12087 int drop_element = (player->inventory_size > 0 ?
12088 player->inventory_element[player->inventory_size - 1] :
12089 player->inventory_infinite_element != EL_UNDEFINED ?
12090 player->inventory_infinite_element :
12091 player->dynabombs_left > 0 ?
12092 EL_DYNABOMB_PLAYER_1_ACTIVE + player->index_nr :
12095 if (IS_THROWABLE(drop_element))
12097 dropx += GET_DX_FROM_DIR(drop_direction);
12098 dropy += GET_DY_FROM_DIR(drop_direction);
12100 if (!IN_LEV_FIELD(dropx, dropy))
12104 old_element = Feld[dropx][dropy]; /* old element at dropping position */
12105 new_element = drop_element; /* default: no change when dropping */
12107 /* check if player is active, not moving and ready to drop */
12108 if (!player->active || player->MovPos || player->drop_delay > 0)
12111 /* check if player has anything that can be dropped */
12113 if (new_element == EL_UNDEFINED)
12116 if (player->inventory_size == 0 &&
12117 player->inventory_infinite_element == EL_UNDEFINED &&
12118 player->dynabombs_left == 0)
12122 /* check if anything can be dropped at the current position */
12123 if (IS_ACTIVE_BOMB(old_element) || old_element == EL_EXPLOSION)
12126 /* collected custom elements can only be dropped on empty fields */
12128 if (IS_CUSTOM_ELEMENT(new_element) && old_element != EL_EMPTY)
12131 if (player->inventory_size > 0 &&
12132 IS_CUSTOM_ELEMENT(player->inventory_element[player->inventory_size - 1])
12133 && old_element != EL_EMPTY)
12137 if (old_element != EL_EMPTY)
12138 Back[dropx][dropy] = old_element; /* store old element on this field */
12140 ResetGfxAnimation(dropx, dropy);
12141 ResetRandomAnimationValue(dropx, dropy);
12143 if (player->inventory_size > 0 ||
12144 player->inventory_infinite_element != EL_UNDEFINED)
12146 if (player->inventory_size > 0)
12148 player->inventory_size--;
12151 new_element = player->inventory_element[player->inventory_size];
12154 DrawGameValue_Dynamite(local_player->inventory_size);
12156 if (new_element == EL_DYNAMITE)
12157 new_element = EL_DYNAMITE_ACTIVE;
12158 else if (new_element == EL_SP_DISK_RED)
12159 new_element = EL_SP_DISK_RED_ACTIVE;
12162 Feld[dropx][dropy] = new_element;
12164 if (IN_SCR_FIELD(SCREENX(dropx), SCREENY(dropy)))
12165 DrawGraphicThruMask(SCREENX(dropx), SCREENY(dropy),
12166 el2img(Feld[dropx][dropy]), 0);
12168 PlayLevelSoundAction(dropx, dropy, ACTION_DROPPING);
12171 /* needed if previous element just changed to "empty" in the last frame */
12172 Changed[dropx][dropy] = 0; /* allow another change */
12176 /* !!! TEST ONLY !!! */
12177 CheckElementChangeByPlayer(dropx, dropy, new_element, CE_DROPPED_BY_PLAYER,
12178 player->index_bit, drop_side);
12179 CheckTriggeredElementChangeByPlayer(dropx, dropy, new_element,
12180 CE_OTHER_GETS_DROPPED,
12181 player->index_bit, drop_side);
12183 CheckTriggeredElementChangeByPlayer(dropx, dropy, new_element,
12184 CE_OTHER_GETS_DROPPED,
12185 player->index_bit, drop_side);
12186 CheckElementChangeByPlayer(dropx, dropy, new_element, CE_DROPPED_BY_PLAYER,
12187 player->index_bit, drop_side);
12190 TestIfElementTouchesCustomElement(dropx, dropy);
12192 else /* player is dropping a dyna bomb */
12194 player->dynabombs_left--;
12197 new_element = EL_DYNABOMB_PLAYER_1_ACTIVE + player->index_nr;
12200 Feld[dropx][dropy] = new_element;
12202 if (IN_SCR_FIELD(SCREENX(dropx), SCREENY(dropy)))
12203 DrawGraphicThruMask(SCREENX(dropx), SCREENY(dropy),
12204 el2img(Feld[dropx][dropy]), 0);
12206 PlayLevelSoundAction(dropx, dropy, ACTION_DROPPING);
12213 if (Feld[dropx][dropy] == new_element) /* uninitialized unless CE change */
12216 InitField_WithBug1(dropx, dropy, FALSE);
12218 InitField(dropx, dropy, FALSE);
12219 if (CAN_MOVE(Feld[dropx][dropy]))
12220 InitMovDir(dropx, dropy);
12224 new_element = Feld[dropx][dropy]; /* element might have changed */
12226 if (IS_CUSTOM_ELEMENT(new_element) && CAN_MOVE(new_element) &&
12227 element_info[new_element].move_pattern == MV_WHEN_DROPPED)
12230 int move_stepsize = element_info[new_element].move_stepsize;
12232 int move_direction, nextx, nexty;
12234 if (element_info[new_element].move_direction_initial == MV_START_AUTOMATIC)
12235 MovDir[dropx][dropy] = drop_direction;
12237 move_direction = MovDir[dropx][dropy];
12238 nextx = dropx + GET_DX_FROM_DIR(move_direction);
12239 nexty = dropy + GET_DY_FROM_DIR(move_direction);
12242 Changed[dropx][dropy] = 0; /* allow another change */
12243 CheckCollision[dropx][dropy] = 2;
12246 if (IN_LEV_FIELD_AND_IS_FREE(nextx, nexty))
12249 WasJustMoving[dropx][dropy] = 3;
12252 InitMovingField(dropx, dropy, move_direction);
12253 ContinueMoving(dropx, dropy);
12258 /* !!! commented out from 3.1.0-4 to 3.1.0-5 !!! */
12261 Changed[dropx][dropy] = 0; /* allow another change */
12264 TestIfElementHitsCustomElement(dropx, dropy, move_direction);
12266 CheckElementChangeBySide(dropx, dropy, new_element, touched_element,
12267 CE_HITTING_SOMETHING, move_direction);
12275 player->drop_delay = 2 * TILEX / move_stepsize + 1;
12280 player->drop_delay = 8 + 8 + 8;
12284 player->drop_delay = GET_NEW_DROP_DELAY(drop_element);
12289 player->is_dropping = TRUE;
12295 /* ------------------------------------------------------------------------- */
12296 /* game sound playing functions */
12297 /* ------------------------------------------------------------------------- */
12299 static int *loop_sound_frame = NULL;
12300 static int *loop_sound_volume = NULL;
12302 void InitPlayLevelSound()
12304 int num_sounds = getSoundListSize();
12306 checked_free(loop_sound_frame);
12307 checked_free(loop_sound_volume);
12309 loop_sound_frame = checked_calloc(num_sounds * sizeof(int));
12310 loop_sound_volume = checked_calloc(num_sounds * sizeof(int));
12313 static void PlayLevelSound(int x, int y, int nr)
12315 int sx = SCREENX(x), sy = SCREENY(y);
12316 int volume, stereo_position;
12317 int max_distance = 8;
12318 int type = (IS_LOOP_SOUND(nr) ? SND_CTRL_PLAY_LOOP : SND_CTRL_PLAY_SOUND);
12320 if ((!setup.sound_simple && !IS_LOOP_SOUND(nr)) ||
12321 (!setup.sound_loops && IS_LOOP_SOUND(nr)))
12324 if (!IN_LEV_FIELD(x, y) ||
12325 sx < -max_distance || sx >= SCR_FIELDX + max_distance ||
12326 sy < -max_distance || sy >= SCR_FIELDY + max_distance)
12329 volume = SOUND_MAX_VOLUME;
12331 if (!IN_SCR_FIELD(sx, sy))
12333 int dx = ABS(sx - SCR_FIELDX / 2) - SCR_FIELDX / 2;
12334 int dy = ABS(sy - SCR_FIELDY / 2) - SCR_FIELDY / 2;
12336 volume -= volume * (dx > dy ? dx : dy) / max_distance;
12339 stereo_position = (SOUND_MAX_LEFT +
12340 (sx + max_distance) * SOUND_MAX_LEFT2RIGHT /
12341 (SCR_FIELDX + 2 * max_distance));
12343 if (IS_LOOP_SOUND(nr))
12345 /* This assures that quieter loop sounds do not overwrite louder ones,
12346 while restarting sound volume comparison with each new game frame. */
12348 if (loop_sound_volume[nr] > volume && loop_sound_frame[nr] == FrameCounter)
12351 loop_sound_volume[nr] = volume;
12352 loop_sound_frame[nr] = FrameCounter;
12355 PlaySoundExt(nr, volume, stereo_position, type);
12358 static void PlayLevelSoundNearest(int x, int y, int sound_action)
12360 PlayLevelSound(x < LEVELX(BX1) ? LEVELX(BX1) :
12361 x > LEVELX(BX2) ? LEVELX(BX2) : x,
12362 y < LEVELY(BY1) ? LEVELY(BY1) :
12363 y > LEVELY(BY2) ? LEVELY(BY2) : y,
12367 static void PlayLevelSoundAction(int x, int y, int action)
12369 PlayLevelSoundElementAction(x, y, Feld[x][y], action);
12372 static void PlayLevelSoundElementAction(int x, int y, int element, int action)
12374 int sound_effect = element_info[SND_ELEMENT(element)].sound[action];
12376 if (sound_effect != SND_UNDEFINED)
12377 PlayLevelSound(x, y, sound_effect);
12380 static void PlayLevelSoundElementActionIfLoop(int x, int y, int element,
12383 int sound_effect = element_info[SND_ELEMENT(element)].sound[action];
12385 if (sound_effect != SND_UNDEFINED && IS_LOOP_SOUND(sound_effect))
12386 PlayLevelSound(x, y, sound_effect);
12389 static void PlayLevelSoundActionIfLoop(int x, int y, int action)
12391 int sound_effect = element_info[SND_ELEMENT(Feld[x][y])].sound[action];
12393 if (sound_effect != SND_UNDEFINED && IS_LOOP_SOUND(sound_effect))
12394 PlayLevelSound(x, y, sound_effect);
12397 static void StopLevelSoundActionIfLoop(int x, int y, int action)
12399 int sound_effect = element_info[SND_ELEMENT(Feld[x][y])].sound[action];
12401 if (sound_effect != SND_UNDEFINED && IS_LOOP_SOUND(sound_effect))
12402 StopSound(sound_effect);
12405 static void PlayLevelMusic()
12407 if (levelset.music[level_nr] != MUS_UNDEFINED)
12408 PlayMusic(levelset.music[level_nr]); /* from config file */
12410 PlayMusic(MAP_NOCONF_MUSIC(level_nr)); /* from music dir */
12413 void PlayLevelSound_EM(int x, int y, int element_em, int sample)
12415 int element = (element_em > -1 ? map_element_EM_to_RND(element_em) : 0);
12418 if (sample == SAMPLE_bug)
12419 printf("::: PlayLevelSound_EM: %d, %d: %d\n", x, y, sample);
12425 PlayLevelSoundElementAction(x, y, element, ACTION_WALKING);
12429 PlayLevelSoundElementAction(x, y, element, ACTION_PUSHING);
12433 PlayLevelSoundElementAction(x, y, element, ACTION_IMPACT);
12437 PlayLevelSoundElementAction(x, y, element, ACTION_IMPACT);
12441 PlayLevelSoundElementAction(x, y, element, ACTION_BREAKING);
12445 PlayLevelSoundElementAction(x, y, EL_BUG, ACTION_MOVING);
12449 PlayLevelSoundElementAction(x, y, EL_SPACESHIP, ACTION_MOVING);
12452 case SAMPLE_android:
12453 PlayLevelSoundElementAction(x, y, element, ACTION_DROPPING);
12456 case SAMPLE_spring:
12457 PlayLevelSoundElementAction(x, y, element, ACTION_IMPACT);
12461 PlayLevelSoundElementAction(x, y, element, ACTION_SLURPED_BY_SPRING);
12465 PlayLevelSoundElementAction(x, y, EL_YAMYAM, ACTION_WAITING);
12469 PlayLevelSoundElementAction(x, y, element, ACTION_MOVING);
12472 case SAMPLE_collect:
12473 PlayLevelSoundElementAction(x, y, element, ACTION_COLLECTING);
12476 case SAMPLE_diamond:
12477 PlayLevelSoundElementAction(x, y, element, ACTION_IMPACT);
12480 case SAMPLE_squash:
12481 PlayLevelSoundElementAction(x, y, element, ACTION_SMASHED_BY_ROCK);
12484 case SAMPLE_wonderfall:
12485 PlayLevelSoundElementAction(x, y, EL_MAGIC_WALL, ACTION_FILLING);
12489 PlayLevelSoundElementAction(x, y, element, ACTION_IMPACT);
12493 PlayLevelSoundElementAction(x, y, element, ACTION_PUSHING);
12497 PlayLevelSoundElementAction(x, y, element, ACTION_DIGGING);
12501 PlayLevelSound(x, y, SND_ACID_SPLASHING);
12505 PlayLevelSoundElementAction(x, y, element, ACTION_DROPPING);
12509 PlayLevelSoundElementAction(x, y, element, ACTION_GROWING);
12512 case SAMPLE_wonder:
12513 PlayLevelSoundElementAction(x, y, element, ACTION_ACTIVE);
12517 PlayLevelSoundElementAction(x, y, element, ACTION_PASSING);
12521 PlayLevelSoundElementAction(x, y, element, ACTION_PASSING);
12524 case SAMPLE_dynamite:
12525 PlayLevelSoundElementAction(x, y, element, ACTION_DROPPING);
12529 PlayLevelSoundElementAction(x, y, element, ACTION_ACTIVE);
12533 PlayLevelSoundElementAction(x, y, element, ACTION_ACTIVATING);
12537 PlayLevelSound(x, y, SND_ROBOT_WHEEL_ACTIVE);
12541 PlayLevelSoundElementAction(x, y, element, ACTION_EXPLODING);
12545 PlaySoundStereo(SND_GAME_RUNNING_OUT_OF_TIME, SOUND_MIDDLE);
12549 PlayLevelSoundElementAction(x, y, element, ACTION_DYING);
12553 PlayLevelSoundElementAction(x, y, element, ACTION_DEFAULT);
12558 void RaiseScore(int value)
12560 local_player->score += value;
12562 DrawGameValue_Score(local_player->score);
12565 void RaiseScoreElement(int element)
12570 case EL_BD_DIAMOND:
12571 case EL_EMERALD_YELLOW:
12572 case EL_EMERALD_RED:
12573 case EL_EMERALD_PURPLE:
12574 case EL_SP_INFOTRON:
12575 RaiseScore(level.score[SC_EMERALD]);
12578 RaiseScore(level.score[SC_DIAMOND]);
12581 RaiseScore(level.score[SC_CRYSTAL]);
12584 RaiseScore(level.score[SC_PEARL]);
12587 case EL_BD_BUTTERFLY:
12588 case EL_SP_ELECTRON:
12589 RaiseScore(level.score[SC_BUG]);
12592 case EL_BD_FIREFLY:
12593 case EL_SP_SNIKSNAK:
12594 RaiseScore(level.score[SC_SPACESHIP]);
12597 case EL_DARK_YAMYAM:
12598 RaiseScore(level.score[SC_YAMYAM]);
12601 RaiseScore(level.score[SC_ROBOT]);
12604 RaiseScore(level.score[SC_PACMAN]);
12607 RaiseScore(level.score[SC_NUT]);
12610 case EL_SP_DISK_RED:
12611 case EL_DYNABOMB_INCREASE_NUMBER:
12612 case EL_DYNABOMB_INCREASE_SIZE:
12613 case EL_DYNABOMB_INCREASE_POWER:
12614 RaiseScore(level.score[SC_DYNAMITE]);
12616 case EL_SHIELD_NORMAL:
12617 case EL_SHIELD_DEADLY:
12618 RaiseScore(level.score[SC_SHIELD]);
12620 case EL_EXTRA_TIME:
12621 RaiseScore(level.score[SC_TIME_BONUS]);
12627 RaiseScore(level.score[SC_KEY]);
12630 RaiseScore(element_info[element].collect_score);
12635 void RequestQuitGame(boolean ask_if_really_quit)
12637 if (AllPlayersGone ||
12638 !ask_if_really_quit ||
12639 level_editor_test_game ||
12640 Request("Do you really want to quit the game ?",
12641 REQ_ASK | REQ_STAY_CLOSED))
12643 #if defined(NETWORK_AVALIABLE)
12644 if (options.network)
12645 SendToServer_StopPlaying();
12649 game_status = GAME_MODE_MAIN;
12657 if (tape.playing && tape.deactivate_display)
12658 TapeDeactivateDisplayOff(TRUE);
12661 OpenDoor(DOOR_OPEN_1 | DOOR_COPY_BACK);
12664 if (tape.playing && tape.deactivate_display)
12665 TapeDeactivateDisplayOn();
12672 /* ---------- new game button stuff ---------------------------------------- */
12674 /* graphic position values for game buttons */
12675 #define GAME_BUTTON_XSIZE 30
12676 #define GAME_BUTTON_YSIZE 30
12677 #define GAME_BUTTON_XPOS 5
12678 #define GAME_BUTTON_YPOS 215
12679 #define SOUND_BUTTON_XPOS 5
12680 #define SOUND_BUTTON_YPOS (GAME_BUTTON_YPOS + GAME_BUTTON_YSIZE)
12682 #define GAME_BUTTON_STOP_XPOS (GAME_BUTTON_XPOS + 0 * GAME_BUTTON_XSIZE)
12683 #define GAME_BUTTON_PAUSE_XPOS (GAME_BUTTON_XPOS + 1 * GAME_BUTTON_XSIZE)
12684 #define GAME_BUTTON_PLAY_XPOS (GAME_BUTTON_XPOS + 2 * GAME_BUTTON_XSIZE)
12685 #define SOUND_BUTTON_MUSIC_XPOS (SOUND_BUTTON_XPOS + 0 * GAME_BUTTON_XSIZE)
12686 #define SOUND_BUTTON_LOOPS_XPOS (SOUND_BUTTON_XPOS + 1 * GAME_BUTTON_XSIZE)
12687 #define SOUND_BUTTON_SIMPLE_XPOS (SOUND_BUTTON_XPOS + 2 * GAME_BUTTON_XSIZE)
12694 } gamebutton_info[NUM_GAME_BUTTONS] =
12697 GAME_BUTTON_STOP_XPOS, GAME_BUTTON_YPOS,
12702 GAME_BUTTON_PAUSE_XPOS, GAME_BUTTON_YPOS,
12703 GAME_CTRL_ID_PAUSE,
12707 GAME_BUTTON_PLAY_XPOS, GAME_BUTTON_YPOS,
12712 SOUND_BUTTON_MUSIC_XPOS, SOUND_BUTTON_YPOS,
12713 SOUND_CTRL_ID_MUSIC,
12714 "background music on/off"
12717 SOUND_BUTTON_LOOPS_XPOS, SOUND_BUTTON_YPOS,
12718 SOUND_CTRL_ID_LOOPS,
12719 "sound loops on/off"
12722 SOUND_BUTTON_SIMPLE_XPOS, SOUND_BUTTON_YPOS,
12723 SOUND_CTRL_ID_SIMPLE,
12724 "normal sounds on/off"
12728 void CreateGameButtons()
12732 for (i = 0; i < NUM_GAME_BUTTONS; i++)
12734 Bitmap *gd_bitmap = graphic_info[IMG_GLOBAL_DOOR].bitmap;
12735 struct GadgetInfo *gi;
12738 unsigned long event_mask;
12739 int gd_xoffset, gd_yoffset;
12740 int gd_x1, gd_x2, gd_y1, gd_y2;
12743 gd_xoffset = gamebutton_info[i].x;
12744 gd_yoffset = gamebutton_info[i].y;
12745 gd_x1 = DOOR_GFX_PAGEX4 + gd_xoffset;
12746 gd_x2 = DOOR_GFX_PAGEX3 + gd_xoffset;
12748 if (id == GAME_CTRL_ID_STOP ||
12749 id == GAME_CTRL_ID_PAUSE ||
12750 id == GAME_CTRL_ID_PLAY)
12752 button_type = GD_TYPE_NORMAL_BUTTON;
12754 event_mask = GD_EVENT_RELEASED;
12755 gd_y1 = DOOR_GFX_PAGEY1 + gd_yoffset - GAME_BUTTON_YSIZE;
12756 gd_y2 = DOOR_GFX_PAGEY1 + gd_yoffset - GAME_BUTTON_YSIZE;
12760 button_type = GD_TYPE_CHECK_BUTTON;
12762 ((id == SOUND_CTRL_ID_MUSIC && setup.sound_music) ||
12763 (id == SOUND_CTRL_ID_LOOPS && setup.sound_loops) ||
12764 (id == SOUND_CTRL_ID_SIMPLE && setup.sound_simple) ? TRUE : FALSE);
12765 event_mask = GD_EVENT_PRESSED;
12766 gd_y1 = DOOR_GFX_PAGEY1 + gd_yoffset;
12767 gd_y2 = DOOR_GFX_PAGEY1 + gd_yoffset - GAME_BUTTON_YSIZE;
12770 gi = CreateGadget(GDI_CUSTOM_ID, id,
12771 GDI_INFO_TEXT, gamebutton_info[i].infotext,
12772 GDI_X, DX + gd_xoffset,
12773 GDI_Y, DY + gd_yoffset,
12774 GDI_WIDTH, GAME_BUTTON_XSIZE,
12775 GDI_HEIGHT, GAME_BUTTON_YSIZE,
12776 GDI_TYPE, button_type,
12777 GDI_STATE, GD_BUTTON_UNPRESSED,
12778 GDI_CHECKED, checked,
12779 GDI_DESIGN_UNPRESSED, gd_bitmap, gd_x1, gd_y1,
12780 GDI_DESIGN_PRESSED, gd_bitmap, gd_x2, gd_y1,
12781 GDI_ALT_DESIGN_UNPRESSED, gd_bitmap, gd_x1, gd_y2,
12782 GDI_ALT_DESIGN_PRESSED, gd_bitmap, gd_x2, gd_y2,
12783 GDI_EVENT_MASK, event_mask,
12784 GDI_CALLBACK_ACTION, HandleGameButtons,
12788 Error(ERR_EXIT, "cannot create gadget");
12790 game_gadget[id] = gi;
12794 void FreeGameButtons()
12798 for (i = 0; i < NUM_GAME_BUTTONS; i++)
12799 FreeGadget(game_gadget[i]);
12802 static void MapGameButtons()
12806 for (i = 0; i < NUM_GAME_BUTTONS; i++)
12807 MapGadget(game_gadget[i]);
12810 void UnmapGameButtons()
12814 for (i = 0; i < NUM_GAME_BUTTONS; i++)
12815 UnmapGadget(game_gadget[i]);
12818 static void HandleGameButtons(struct GadgetInfo *gi)
12820 int id = gi->custom_id;
12822 if (game_status != GAME_MODE_PLAYING)
12827 case GAME_CTRL_ID_STOP:
12828 RequestQuitGame(TRUE);
12831 case GAME_CTRL_ID_PAUSE:
12832 if (options.network)
12834 #if defined(NETWORK_AVALIABLE)
12836 SendToServer_ContinuePlaying();
12838 SendToServer_PausePlaying();
12842 TapeTogglePause(TAPE_TOGGLE_MANUAL);
12845 case GAME_CTRL_ID_PLAY:
12848 #if defined(NETWORK_AVALIABLE)
12849 if (options.network)
12850 SendToServer_ContinuePlaying();
12854 tape.pausing = FALSE;
12855 DrawVideoDisplay(VIDEO_STATE_PAUSE_OFF,0);
12860 case SOUND_CTRL_ID_MUSIC:
12861 if (setup.sound_music)
12863 setup.sound_music = FALSE;
12866 else if (audio.music_available)
12868 setup.sound = setup.sound_music = TRUE;
12870 SetAudioMode(setup.sound);
12876 case SOUND_CTRL_ID_LOOPS:
12877 if (setup.sound_loops)
12878 setup.sound_loops = FALSE;
12879 else if (audio.loops_available)
12881 setup.sound = setup.sound_loops = TRUE;
12882 SetAudioMode(setup.sound);
12886 case SOUND_CTRL_ID_SIMPLE:
12887 if (setup.sound_simple)
12888 setup.sound_simple = FALSE;
12889 else if (audio.sound_available)
12891 setup.sound = setup.sound_simple = TRUE;
12892 SetAudioMode(setup.sound);