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
45 /* for MovePlayer() */
46 #define MF_NO_ACTION 0
50 /* for ScrollPlayer() */
52 #define SCROLL_GO_ON 1
55 #define EX_PHASE_START 0
56 #define EX_TYPE_NONE 0
57 #define EX_TYPE_NORMAL (1 << 0)
58 #define EX_TYPE_CENTER (1 << 1)
59 #define EX_TYPE_BORDER (1 << 2)
60 #define EX_TYPE_CROSS (1 << 3)
61 #define EX_TYPE_SINGLE_TILE (EX_TYPE_CENTER | EX_TYPE_BORDER)
63 /* special positions in the game control window (relative to control window) */
66 #define XX_EMERALDS 29
67 #define YY_EMERALDS 54
68 #define XX_DYNAMITE 29
69 #define YY_DYNAMITE 89
78 /* special positions in the game control window (relative to main window) */
79 #define DX_LEVEL (DX + XX_LEVEL)
80 #define DY_LEVEL (DY + YY_LEVEL)
81 #define DX_EMERALDS (DX + XX_EMERALDS)
82 #define DY_EMERALDS (DY + YY_EMERALDS)
83 #define DX_DYNAMITE (DX + XX_DYNAMITE)
84 #define DY_DYNAMITE (DY + YY_DYNAMITE)
85 #define DX_KEYS (DX + XX_KEYS)
86 #define DY_KEYS (DY + YY_KEYS)
87 #define DX_SCORE (DX + XX_SCORE)
88 #define DY_SCORE (DY + YY_SCORE)
89 #define DX_TIME1 (DX + XX_TIME1)
90 #define DX_TIME2 (DX + XX_TIME2)
91 #define DY_TIME (DY + YY_TIME)
93 /* values for initial player move delay (initial delay counter value) */
94 #define INITIAL_MOVE_DELAY_OFF -1
95 #define INITIAL_MOVE_DELAY_ON 0
97 /* values for player movement speed (which is in fact a delay value) */
98 #define MOVE_DELAY_NORMAL_SPEED 8
99 #define MOVE_DELAY_HIGH_SPEED 4
101 #define DOUBLE_MOVE_DELAY(x) (x = (x <= MOVE_DELAY_HIGH_SPEED ? x * 2 : x))
102 #define HALVE_MOVE_DELAY(x) (x = (x >= MOVE_DELAY_HIGH_SPEED ? x / 2 : x))
103 #define DOUBLE_PLAYER_SPEED(p) (HALVE_MOVE_DELAY((p)->move_delay_value))
104 #define HALVE_PLAYER_SPEED(p) (DOUBLE_MOVE_DELAY((p)->move_delay_value))
106 /* values for other actions */
107 #define MOVE_STEPSIZE_NORMAL (TILEX / MOVE_DELAY_NORMAL_SPEED)
109 #define GET_DX_FROM_DIR(d) ((d) == MV_LEFT ? -1 : (d) == MV_RIGHT ? 1 : 0)
110 #define GET_DY_FROM_DIR(d) ((d) == MV_UP ? -1 : (d) == MV_DOWN ? 1 : 0)
112 #define INIT_GFX_RANDOM() (SimpleRND(1000000))
114 #define GET_NEW_PUSH_DELAY(e) ( (element_info[e].push_delay_fixed) + \
115 RND(element_info[e].push_delay_random))
116 #define GET_NEW_DROP_DELAY(e) ( (element_info[e].drop_delay_fixed) + \
117 RND(element_info[e].drop_delay_random))
118 #define GET_NEW_MOVE_DELAY(e) ( (element_info[e].move_delay_fixed) + \
119 RND(element_info[e].move_delay_random))
120 #define GET_MAX_MOVE_DELAY(e) ( (element_info[e].move_delay_fixed) + \
121 (element_info[e].move_delay_random))
123 #define GET_TARGET_ELEMENT(e, ch) \
124 ((e) == EL_TRIGGER_ELEMENT ? (ch)->actual_trigger_element : \
125 (e) == EL_TRIGGER_PLAYER ? (ch)->actual_trigger_player : (e))
127 #define GET_VALID_PLAYER_ELEMENT(e) \
128 ((e) >= EL_PLAYER_1 && (e) <= EL_PLAYER_4 ? (e) : EL_PLAYER_1)
130 #define CAN_GROW_INTO(e) \
131 ((e) == EL_SAND || (IS_DIGGABLE(e) && level.grow_into_diggable))
133 #define ELEMENT_CAN_ENTER_FIELD_BASE_X(x, y, condition) \
134 (IN_LEV_FIELD(x, y) && (IS_FREE(x, y) || \
137 #define ELEMENT_CAN_ENTER_FIELD_BASE_2(e, x, y, condition) \
138 (IN_LEV_FIELD(x, y) && (IS_FREE(x, y) || \
139 (CAN_MOVE_INTO_ACID(e) && \
140 Feld[x][y] == EL_ACID) || \
143 #define ELEMENT_CAN_ENTER_FIELD_BASE_3(e, x, y, condition) \
144 (IN_LEV_FIELD(x, y) && (IS_FREE_OR_PLAYER(x, y) || \
145 (CAN_MOVE_INTO_ACID(e) && \
146 Feld[x][y] == EL_ACID) || \
149 #define ELEMENT_CAN_ENTER_FIELD_BASE_4(e, x, y, condition) \
150 (IN_LEV_FIELD(x, y) && (IS_FREE(x, y) || \
152 (CAN_MOVE_INTO_ACID(e) && \
153 Feld[x][y] == EL_ACID) || \
154 (DONT_COLLIDE_WITH(e) && \
156 !PLAYER_ENEMY_PROTECTED(x, y))))
159 #define ELEMENT_CAN_ENTER_FIELD_GENERIC(e, x, y, condition) \
160 (IN_LEV_FIELD(x, y) && (IS_FREE(x, y) || \
162 (DONT_COLLIDE_WITH(e) && \
164 !PLAYER_ENEMY_PROTECTED(x, y))))
167 #define ELEMENT_CAN_ENTER_FIELD(e, x, y) \
168 ELEMENT_CAN_ENTER_FIELD_BASE_4(e, x, y, 0)
171 #define SATELLITE_CAN_ENTER_FIELD(x, y) \
172 ELEMENT_CAN_ENTER_FIELD_BASE_2(EL_SATELLITE, x, y, 0)
174 #define SATELLITE_CAN_ENTER_FIELD(x, y) \
175 ELEMENT_CAN_ENTER_FIELD_BASE_X(x, y, Feld[x][y] == EL_ACID)
179 #define ENEMY_CAN_ENTER_FIELD(e, x, y) (IN_LEV_FIELD(x, y) && IS_FREE(x, y))
182 #define ENEMY_CAN_ENTER_FIELD(e, x, y) \
183 ELEMENT_CAN_ENTER_FIELD_BASE_2(e, x, y, 0)
187 #define YAMYAM_CAN_ENTER_FIELD(e, x, y) \
188 ELEMENT_CAN_ENTER_FIELD_BASE_3(e, x, y, Feld[x][y] == EL_DIAMOND)
190 #define DARK_YAMYAM_CAN_ENTER_FIELD(e, x, y) \
191 ELEMENT_CAN_ENTER_FIELD_BASE_3(e, x,y, IS_FOOD_DARK_YAMYAM(Feld[x][y]))
193 #define PACMAN_CAN_ENTER_FIELD(e, x, y) \
194 ELEMENT_CAN_ENTER_FIELD_BASE_3(e, x, y, IS_AMOEBOID(Feld[x][y]))
196 #define PIG_CAN_ENTER_FIELD(e, x, y) \
197 ELEMENT_CAN_ENTER_FIELD_BASE_2(e, x, y, IS_FOOD_PIG(Feld[x][y]))
199 #define PENGUIN_CAN_ENTER_FIELD(e, x, y) \
200 ELEMENT_CAN_ENTER_FIELD_BASE_2(e, x, y, (Feld[x][y] == EL_EXIT_OPEN ||\
201 IS_FOOD_PENGUIN(Feld[x][y])))
202 #define DRAGON_CAN_ENTER_FIELD(e, x, y) \
203 ELEMENT_CAN_ENTER_FIELD_BASE_2(e, x, y, 0)
205 #define MOLE_CAN_ENTER_FIELD(e, x, y, condition) \
206 ELEMENT_CAN_ENTER_FIELD_BASE_2(e, x, y, (condition))
208 #define SPRING_CAN_ENTER_FIELD(e, x, y) \
209 ELEMENT_CAN_ENTER_FIELD_BASE_2(e, x, y, 0)
213 #define YAMYAM_CAN_ENTER_FIELD(e, x, y) \
214 (IN_LEV_FIELD(x, y) && (IS_FREE_OR_PLAYER(x, y) || \
215 (CAN_MOVE_INTO_ACID(e) && \
216 Feld[x][y] == EL_ACID) || \
217 Feld[x][y] == EL_DIAMOND))
219 #define DARK_YAMYAM_CAN_ENTER_FIELD(e, x, y) \
220 (IN_LEV_FIELD(x, y) && (IS_FREE_OR_PLAYER(x, y) || \
221 (CAN_MOVE_INTO_ACID(e) && \
222 Feld[x][y] == EL_ACID) || \
223 IS_FOOD_DARK_YAMYAM(Feld[x][y])))
225 #define PACMAN_CAN_ENTER_FIELD(e, x, y) \
226 (IN_LEV_FIELD(x, y) && (IS_FREE_OR_PLAYER(x, y) || \
227 (CAN_MOVE_INTO_ACID(e) && \
228 Feld[x][y] == EL_ACID) || \
229 IS_AMOEBOID(Feld[x][y])))
231 #define PIG_CAN_ENTER_FIELD(e, x, y) \
232 (IN_LEV_FIELD(x, y) && (IS_FREE(x, y) || \
233 (CAN_MOVE_INTO_ACID(e) && \
234 Feld[x][y] == EL_ACID) || \
235 IS_FOOD_PIG(Feld[x][y])))
237 #define PENGUIN_CAN_ENTER_FIELD(e, x, y) \
238 (IN_LEV_FIELD(x, y) && (IS_FREE(x, y) || \
239 (CAN_MOVE_INTO_ACID(e) && \
240 Feld[x][y] == EL_ACID) || \
241 IS_FOOD_PENGUIN(Feld[x][y]) || \
242 Feld[x][y] == EL_EXIT_OPEN))
244 #define DRAGON_CAN_ENTER_FIELD(e, x, y) \
245 (IN_LEV_FIELD(x, y) && (IS_FREE(x, y) || \
246 (CAN_MOVE_INTO_ACID(e) && \
247 Feld[x][y] == EL_ACID)))
249 #define MOLE_CAN_ENTER_FIELD(e, x, y, condition) \
250 (IN_LEV_FIELD(x, y) && (IS_FREE(x, y) || \
251 (CAN_MOVE_INTO_ACID(e) && \
252 Feld[x][y] == EL_ACID) || \
255 #define SPRING_CAN_ENTER_FIELD(e, x, y) \
256 (IN_LEV_FIELD(x, y) && (IS_FREE(x, y) || \
257 (CAN_MOVE_INTO_ACID(e) && \
258 Feld[x][y] == EL_ACID)))
262 #define GROUP_NR(e) ((e) - EL_GROUP_START)
263 #define MOVE_ENTER_EL(e) (element_info[e].move_enter_element)
264 #define IS_IN_GROUP(e, nr) (element_info[e].in_group[nr] == TRUE)
265 #define IS_IN_GROUP_EL(e, ge) (IS_IN_GROUP(e, (ge) - EL_GROUP_START))
267 #define IS_EQUAL_OR_IN_GROUP(e, ge) \
268 (IS_GROUP_ELEMENT(ge) ? IS_IN_GROUP(e, GROUP_NR(ge)) : (e) == (ge))
271 #define CE_ENTER_FIELD_COND(e, x, y) \
272 (!IS_PLAYER(x, y) && \
273 (Feld[x][y] == EL_ACID || \
274 IS_EQUAL_OR_IN_GROUP(Feld[x][y], MOVE_ENTER_EL(e))))
276 #define CE_ENTER_FIELD_COND(e, x, y) \
277 (!IS_PLAYER(x, y) && \
278 IS_EQUAL_OR_IN_GROUP(Feld[x][y], MOVE_ENTER_EL(e)))
281 #define CUSTOM_ELEMENT_CAN_ENTER_FIELD(e, x, y) \
282 ELEMENT_CAN_ENTER_FIELD_BASE_4(e, x, y, CE_ENTER_FIELD_COND(e, x, y))
284 #define IN_LEV_FIELD_AND_IS_FREE(x, y) (IN_LEV_FIELD(x, y) && IS_FREE(x, y))
285 #define IN_LEV_FIELD_AND_NOT_FREE(x, y) (IN_LEV_FIELD(x, y) && !IS_FREE(x, y))
287 #define ACCESS_FROM(e, d) (element_info[e].access_direction &(d))
288 #define IS_WALKABLE_FROM(e, d) (IS_WALKABLE(e) && ACCESS_FROM(e, d))
289 #define IS_PASSABLE_FROM(e, d) (IS_PASSABLE(e) && ACCESS_FROM(e, d))
290 #define IS_ACCESSIBLE_FROM(e, d) (IS_ACCESSIBLE(e) && ACCESS_FROM(e, d))
292 /* game button identifiers */
293 #define GAME_CTRL_ID_STOP 0
294 #define GAME_CTRL_ID_PAUSE 1
295 #define GAME_CTRL_ID_PLAY 2
296 #define SOUND_CTRL_ID_MUSIC 3
297 #define SOUND_CTRL_ID_LOOPS 4
298 #define SOUND_CTRL_ID_SIMPLE 5
300 #define NUM_GAME_BUTTONS 6
303 /* forward declaration for internal use */
305 static void AdvanceFrameAndPlayerCounters(int);
307 static boolean MovePlayerOneStep(struct PlayerInfo *, int, int, int, int);
308 static boolean MovePlayer(struct PlayerInfo *, int, int);
309 static void ScrollPlayer(struct PlayerInfo *, int);
310 static void ScrollScreen(struct PlayerInfo *, int);
312 int DigField(struct PlayerInfo *, int, int, int, int, int, int, int);
314 static void InitBeltMovement(void);
315 static void CloseAllOpenTimegates(void);
316 static void CheckGravityMovement(struct PlayerInfo *);
317 static void CheckGravityMovementWhenNotMoving(struct PlayerInfo *);
318 static void KillHeroUnlessEnemyProtected(int, int);
319 static void KillHeroUnlessExplosionProtected(int, int);
321 static void TestIfPlayerTouchesCustomElement(int, int);
322 static void TestIfElementTouchesCustomElement(int, int);
323 static void TestIfElementHitsCustomElement(int, int, int);
325 static void TestIfElementSmashesCustomElement(int, int, int);
328 static void ChangeElement(int, int, int);
330 static boolean CheckTriggeredElementChangeExt(int, int, int, int, int,int,int);
331 #define CheckTriggeredElementChange(x, y, e, ev) \
332 CheckTriggeredElementChangeExt(x, y, e, ev, CH_PLAYER_ANY, \
334 #define CheckTriggeredElementChangeByPlayer(x, y, e, ev, p, s) \
335 CheckTriggeredElementChangeExt(x, y, e, ev, p, s, -1)
336 #define CheckTriggeredElementChangeBySide(x, y, e, ev, s) \
337 CheckTriggeredElementChangeExt(x, y, e, ev, CH_PLAYER_ANY, s, -1)
338 #define CheckTriggeredElementChangeByPage(x, y, e, ev, p) \
339 CheckTriggeredElementChangeExt(x, y, e, ev, CH_PLAYER_ANY, \
342 static boolean CheckElementChangeExt(int, int, int, int, int, int, int, int);
343 #define CheckElementChange(x, y, e, te, ev) \
344 CheckElementChangeExt(x, y, e, te, ev, CH_PLAYER_ANY, CH_SIDE_ANY, -1)
345 #define CheckElementChangeByPlayer(x, y, e, ev, p, s) \
346 CheckElementChangeExt(x, y, e, EL_EMPTY, ev, p, s, CH_PAGE_ANY)
347 #define CheckElementChangeBySide(x, y, e, te, ev, s) \
348 CheckElementChangeExt(x, y, e, te, ev, CH_PLAYER_ANY, s, CH_PAGE_ANY)
349 #define CheckElementChangeByPage(x, y, e, te, ev, p) \
350 CheckElementChangeExt(x, y, e, te, ev, CH_PLAYER_ANY, CH_SIDE_ANY, p)
352 static void PlayLevelSound(int, int, int);
353 static void PlayLevelSoundNearest(int, int, int);
354 static void PlayLevelSoundAction(int, int, int);
355 static void PlayLevelSoundElementAction(int, int, int, int);
356 static void PlayLevelSoundElementActionIfLoop(int, int, int, int);
357 static void PlayLevelSoundActionIfLoop(int, int, int);
358 static void StopLevelSoundActionIfLoop(int, int, int);
359 static void PlayLevelMusic();
361 static void MapGameButtons();
362 static void HandleGameButtons(struct GadgetInfo *);
364 static struct GadgetInfo *game_gadget[NUM_GAME_BUTTONS];
367 /* ------------------------------------------------------------------------- */
368 /* definition of elements that automatically change to other elements after */
369 /* a specified time, eventually calling a function when changing */
370 /* ------------------------------------------------------------------------- */
372 /* forward declaration for changer functions */
373 static void InitBuggyBase(int x, int y);
374 static void WarnBuggyBase(int x, int y);
376 static void InitTrap(int x, int y);
377 static void ActivateTrap(int x, int y);
378 static void ChangeActiveTrap(int x, int y);
380 static void InitRobotWheel(int x, int y);
381 static void RunRobotWheel(int x, int y);
382 static void StopRobotWheel(int x, int y);
384 static void InitTimegateWheel(int x, int y);
385 static void RunTimegateWheel(int x, int y);
387 struct ChangingElementInfo
392 void (*pre_change_function)(int x, int y);
393 void (*change_function)(int x, int y);
394 void (*post_change_function)(int x, int y);
397 static struct ChangingElementInfo change_delay_list[] =
448 EL_SWITCHGATE_OPENING,
456 EL_SWITCHGATE_CLOSING,
457 EL_SWITCHGATE_CLOSED,
489 EL_ACID_SPLASH_RIGHT,
498 EL_SP_BUGGY_BASE_ACTIVATING,
505 EL_SP_BUGGY_BASE_ACTIVATING,
506 EL_SP_BUGGY_BASE_ACTIVE,
513 EL_SP_BUGGY_BASE_ACTIVE,
537 EL_ROBOT_WHEEL_ACTIVE,
545 EL_TIMEGATE_SWITCH_ACTIVE,
566 int push_delay_fixed, push_delay_random;
571 { EL_BALLOON, 0, 0 },
573 { EL_SOKOBAN_OBJECT, 2, 0 },
574 { EL_SOKOBAN_FIELD_FULL, 2, 0 },
575 { EL_SATELLITE, 2, 0 },
576 { EL_SP_DISK_YELLOW, 2, 0 },
578 { EL_UNDEFINED, 0, 0 },
586 move_stepsize_list[] =
588 { EL_AMOEBA_DROP, 2 },
589 { EL_AMOEBA_DROPPING, 2 },
590 { EL_QUICKSAND_FILLING, 1 },
591 { EL_QUICKSAND_EMPTYING, 1 },
592 { EL_MAGIC_WALL_FILLING, 2 },
593 { EL_BD_MAGIC_WALL_FILLING, 2 },
594 { EL_MAGIC_WALL_EMPTYING, 2 },
595 { EL_BD_MAGIC_WALL_EMPTYING, 2 },
605 collect_count_list[] =
608 { EL_BD_DIAMOND, 1 },
609 { EL_EMERALD_YELLOW, 1 },
610 { EL_EMERALD_RED, 1 },
611 { EL_EMERALD_PURPLE, 1 },
613 { EL_SP_INFOTRON, 1 },
625 access_direction_list[] =
627 { EL_TUBE_ANY, MV_LEFT | MV_RIGHT | MV_UP | MV_DOWN },
628 { EL_TUBE_VERTICAL, MV_UP | MV_DOWN },
629 { EL_TUBE_HORIZONTAL, MV_LEFT | MV_RIGHT },
630 { EL_TUBE_VERTICAL_LEFT, MV_LEFT | MV_UP | MV_DOWN },
631 { EL_TUBE_VERTICAL_RIGHT, MV_RIGHT | MV_UP | MV_DOWN },
632 { EL_TUBE_HORIZONTAL_UP, MV_LEFT | MV_RIGHT | MV_UP },
633 { EL_TUBE_HORIZONTAL_DOWN, MV_LEFT | MV_RIGHT | MV_DOWN },
634 { EL_TUBE_LEFT_UP, MV_LEFT | MV_UP },
635 { EL_TUBE_LEFT_DOWN, MV_LEFT | MV_DOWN },
636 { EL_TUBE_RIGHT_UP, MV_RIGHT | MV_UP },
637 { EL_TUBE_RIGHT_DOWN, MV_RIGHT | MV_DOWN },
639 { EL_SP_PORT_LEFT, MV_RIGHT },
640 { EL_SP_PORT_RIGHT, MV_LEFT },
641 { EL_SP_PORT_UP, MV_DOWN },
642 { EL_SP_PORT_DOWN, MV_UP },
643 { EL_SP_PORT_HORIZONTAL, MV_LEFT | MV_RIGHT },
644 { EL_SP_PORT_VERTICAL, MV_UP | MV_DOWN },
645 { EL_SP_PORT_ANY, MV_LEFT | MV_RIGHT | MV_UP | MV_DOWN },
646 { EL_SP_GRAVITY_PORT_LEFT, MV_RIGHT },
647 { EL_SP_GRAVITY_PORT_RIGHT, MV_LEFT },
648 { EL_SP_GRAVITY_PORT_UP, MV_DOWN },
649 { EL_SP_GRAVITY_PORT_DOWN, MV_UP },
650 { EL_SP_GRAVITY_ON_PORT_LEFT, MV_RIGHT },
651 { EL_SP_GRAVITY_ON_PORT_RIGHT, MV_LEFT },
652 { EL_SP_GRAVITY_ON_PORT_UP, MV_DOWN },
653 { EL_SP_GRAVITY_ON_PORT_DOWN, MV_UP },
654 { EL_SP_GRAVITY_OFF_PORT_LEFT, MV_RIGHT },
655 { EL_SP_GRAVITY_OFF_PORT_RIGHT, MV_LEFT },
656 { EL_SP_GRAVITY_OFF_PORT_UP, MV_DOWN },
657 { EL_SP_GRAVITY_OFF_PORT_DOWN, MV_UP },
659 { EL_UNDEFINED, MV_NO_MOVING }
662 static unsigned long trigger_events[MAX_NUM_ELEMENTS];
664 #define IS_AUTO_CHANGING(e) (element_info[e].change_events & \
665 CH_EVENT_BIT(CE_DELAY))
666 #define IS_JUST_CHANGING(x, y) (ChangeDelay[x][y] != 0)
667 #define IS_CHANGING(x, y) (IS_AUTO_CHANGING(Feld[x][y]) || \
668 IS_JUST_CHANGING(x, y))
670 #define CE_PAGE(e, ce) (element_info[e].event_page[ce])
673 void GetPlayerConfig()
675 if (!audio.sound_available)
676 setup.sound_simple = FALSE;
678 if (!audio.loops_available)
679 setup.sound_loops = FALSE;
681 if (!audio.music_available)
682 setup.sound_music = FALSE;
684 if (!video.fullscreen_available)
685 setup.fullscreen = FALSE;
687 setup.sound = (setup.sound_simple || setup.sound_loops || setup.sound_music);
689 SetAudioMode(setup.sound);
693 static int getBeltNrFromBeltElement(int element)
695 return (element < EL_CONVEYOR_BELT_2_LEFT ? 0 :
696 element < EL_CONVEYOR_BELT_3_LEFT ? 1 :
697 element < EL_CONVEYOR_BELT_4_LEFT ? 2 : 3);
700 static int getBeltNrFromBeltActiveElement(int element)
702 return (element < EL_CONVEYOR_BELT_2_LEFT_ACTIVE ? 0 :
703 element < EL_CONVEYOR_BELT_3_LEFT_ACTIVE ? 1 :
704 element < EL_CONVEYOR_BELT_4_LEFT_ACTIVE ? 2 : 3);
707 static int getBeltNrFromBeltSwitchElement(int element)
709 return (element < EL_CONVEYOR_BELT_2_SWITCH_LEFT ? 0 :
710 element < EL_CONVEYOR_BELT_3_SWITCH_LEFT ? 1 :
711 element < EL_CONVEYOR_BELT_4_SWITCH_LEFT ? 2 : 3);
714 static int getBeltDirNrFromBeltSwitchElement(int element)
716 static int belt_base_element[4] =
718 EL_CONVEYOR_BELT_1_SWITCH_LEFT,
719 EL_CONVEYOR_BELT_2_SWITCH_LEFT,
720 EL_CONVEYOR_BELT_3_SWITCH_LEFT,
721 EL_CONVEYOR_BELT_4_SWITCH_LEFT
724 int belt_nr = getBeltNrFromBeltSwitchElement(element);
725 int belt_dir_nr = element - belt_base_element[belt_nr];
727 return (belt_dir_nr % 3);
730 static int getBeltDirFromBeltSwitchElement(int element)
732 static int belt_move_dir[3] =
739 int belt_dir_nr = getBeltDirNrFromBeltSwitchElement(element);
741 return belt_move_dir[belt_dir_nr];
744 static void InitPlayerField(int x, int y, int element, boolean init_game)
746 if (element == EL_SP_MURPHY)
750 if (stored_player[0].present)
752 Feld[x][y] = EL_SP_MURPHY_CLONE;
758 stored_player[0].use_murphy_graphic = TRUE;
761 Feld[x][y] = EL_PLAYER_1;
767 struct PlayerInfo *player = &stored_player[Feld[x][y] - EL_PLAYER_1];
768 int jx = player->jx, jy = player->jy;
770 player->present = TRUE;
772 player->block_last_field = (element == EL_SP_MURPHY ?
773 level.sp_block_last_field :
774 level.block_last_field);
776 #if USE_NEW_BLOCK_STYLE
778 player->block_delay = (player->block_last_field ?
779 (element == EL_SP_MURPHY ?
780 level.sp_block_delay :
781 level.block_delay) : 0);
783 player->block_delay = (element == EL_SP_MURPHY ?
784 (player->block_last_field ? 7 : 1) :
785 (player->block_last_field ? 7 : 1));
789 printf("::: block_last_field == %d, block_delay = %d\n",
790 player->block_last_field, player->block_delay);
794 if (!options.network || player->connected)
796 player->active = TRUE;
798 /* remove potentially duplicate players */
799 if (StorePlayer[jx][jy] == Feld[x][y])
800 StorePlayer[jx][jy] = 0;
802 StorePlayer[x][y] = Feld[x][y];
806 printf("Player %d activated.\n", player->element_nr);
807 printf("[Local player is %d and currently %s.]\n",
808 local_player->element_nr,
809 local_player->active ? "active" : "not active");
813 Feld[x][y] = EL_EMPTY;
815 player->jx = player->last_jx = x;
816 player->jy = player->last_jy = y;
820 static void InitField(int x, int y, boolean init_game)
822 int element = Feld[x][y];
831 InitPlayerField(x, y, element, init_game);
834 case EL_SOKOBAN_FIELD_PLAYER:
835 element = Feld[x][y] = EL_PLAYER_1;
836 InitField(x, y, init_game);
838 element = Feld[x][y] = EL_SOKOBAN_FIELD_EMPTY;
839 InitField(x, y, init_game);
842 case EL_SOKOBAN_FIELD_EMPTY:
843 local_player->sokobanfields_still_needed++;
847 if (x < lev_fieldx-1 && Feld[x+1][y] == EL_ACID)
848 Feld[x][y] = EL_ACID_POOL_TOPLEFT;
849 else if (x > 0 && Feld[x-1][y] == EL_ACID)
850 Feld[x][y] = EL_ACID_POOL_TOPRIGHT;
851 else if (y > 0 && Feld[x][y-1] == EL_ACID_POOL_TOPLEFT)
852 Feld[x][y] = EL_ACID_POOL_BOTTOMLEFT;
853 else if (y > 0 && Feld[x][y-1] == EL_ACID)
854 Feld[x][y] = EL_ACID_POOL_BOTTOM;
855 else if (y > 0 && Feld[x][y-1] == EL_ACID_POOL_TOPRIGHT)
856 Feld[x][y] = EL_ACID_POOL_BOTTOMRIGHT;
864 case EL_SPACESHIP_RIGHT:
865 case EL_SPACESHIP_UP:
866 case EL_SPACESHIP_LEFT:
867 case EL_SPACESHIP_DOWN:
869 case EL_BD_BUTTERFLY_RIGHT:
870 case EL_BD_BUTTERFLY_UP:
871 case EL_BD_BUTTERFLY_LEFT:
872 case EL_BD_BUTTERFLY_DOWN:
873 case EL_BD_BUTTERFLY:
874 case EL_BD_FIREFLY_RIGHT:
875 case EL_BD_FIREFLY_UP:
876 case EL_BD_FIREFLY_LEFT:
877 case EL_BD_FIREFLY_DOWN:
879 case EL_PACMAN_RIGHT:
903 if (y == lev_fieldy - 1)
905 Feld[x][y] = EL_AMOEBA_GROWING;
906 Store[x][y] = EL_AMOEBA_WET;
910 case EL_DYNAMITE_ACTIVE:
911 case EL_SP_DISK_RED_ACTIVE:
912 case EL_DYNABOMB_PLAYER_1_ACTIVE:
913 case EL_DYNABOMB_PLAYER_2_ACTIVE:
914 case EL_DYNABOMB_PLAYER_3_ACTIVE:
915 case EL_DYNABOMB_PLAYER_4_ACTIVE:
920 local_player->lights_still_needed++;
924 local_player->friends_still_needed++;
929 GfxDir[x][y] = MovDir[x][y] = 1 << RND(4);
934 Feld[x][y] = EL_EMPTY;
939 case EL_EM_KEY_1_FILE:
940 Feld[x][y] = EL_EM_KEY_1;
942 case EL_EM_KEY_2_FILE:
943 Feld[x][y] = EL_EM_KEY_2;
945 case EL_EM_KEY_3_FILE:
946 Feld[x][y] = EL_EM_KEY_3;
948 case EL_EM_KEY_4_FILE:
949 Feld[x][y] = EL_EM_KEY_4;
953 case EL_CONVEYOR_BELT_1_SWITCH_LEFT:
954 case EL_CONVEYOR_BELT_1_SWITCH_MIDDLE:
955 case EL_CONVEYOR_BELT_1_SWITCH_RIGHT:
956 case EL_CONVEYOR_BELT_2_SWITCH_LEFT:
957 case EL_CONVEYOR_BELT_2_SWITCH_MIDDLE:
958 case EL_CONVEYOR_BELT_2_SWITCH_RIGHT:
959 case EL_CONVEYOR_BELT_3_SWITCH_LEFT:
960 case EL_CONVEYOR_BELT_3_SWITCH_MIDDLE:
961 case EL_CONVEYOR_BELT_3_SWITCH_RIGHT:
962 case EL_CONVEYOR_BELT_4_SWITCH_LEFT:
963 case EL_CONVEYOR_BELT_4_SWITCH_MIDDLE:
964 case EL_CONVEYOR_BELT_4_SWITCH_RIGHT:
967 int belt_nr = getBeltNrFromBeltSwitchElement(Feld[x][y]);
968 int belt_dir = getBeltDirFromBeltSwitchElement(Feld[x][y]);
969 int belt_dir_nr = getBeltDirNrFromBeltSwitchElement(Feld[x][y]);
971 if (game.belt_dir_nr[belt_nr] == 3) /* initial value */
973 game.belt_dir[belt_nr] = belt_dir;
974 game.belt_dir_nr[belt_nr] = belt_dir_nr;
976 else /* more than one switch -- set it like the first switch */
978 Feld[x][y] = Feld[x][y] - belt_dir_nr + game.belt_dir_nr[belt_nr];
983 case EL_SWITCHGATE_SWITCH_DOWN: /* always start with same switch pos */
985 Feld[x][y] = EL_SWITCHGATE_SWITCH_UP;
988 case EL_LIGHT_SWITCH_ACTIVE:
990 game.light_time_left = level.time_light * FRAMES_PER_SECOND;
994 if (IS_CUSTOM_ELEMENT(element) && CAN_MOVE(element))
996 else if (IS_GROUP_ELEMENT(element))
998 struct ElementGroupInfo *group = element_info[element].group;
999 int last_anim_random_frame = gfx.anim_random_frame;
1002 if (group->choice_mode == ANIM_RANDOM)
1003 gfx.anim_random_frame = RND(group->num_elements_resolved);
1005 element_pos = getAnimationFrame(group->num_elements_resolved, 1,
1006 group->choice_mode, 0,
1009 if (group->choice_mode == ANIM_RANDOM)
1010 gfx.anim_random_frame = last_anim_random_frame;
1012 group->choice_pos++;
1014 Feld[x][y] = group->element_resolved[element_pos];
1016 InitField(x, y, init_game);
1022 static inline void InitField_WithBug1(int x, int y, boolean init_game)
1024 InitField(x, y, init_game);
1026 /* not needed to call InitMovDir() -- already done by InitField()! */
1027 if (game.engine_version < VERSION_IDENT(3,1,0,0) &&
1028 CAN_MOVE(Feld[x][y]))
1032 static inline void InitField_WithBug2(int x, int y, boolean init_game)
1034 int old_element = Feld[x][y];
1036 InitField(x, y, init_game);
1038 /* not needed to call InitMovDir() -- already done by InitField()! */
1039 if (game.engine_version < VERSION_IDENT(3,1,0,0) &&
1040 CAN_MOVE(old_element) &&
1041 (old_element < EL_MOLE_LEFT || old_element > EL_MOLE_DOWN))
1044 /* this case is in fact a combination of not less than three bugs:
1045 first, it calls InitMovDir() for elements that can move, although this is
1046 already done by InitField(); then, it checks the element that was at this
1047 field _before_ the call to InitField() (which can change it); lastly, it
1048 was not called for "mole with direction" elements, which were treated as
1049 "cannot move" due to (fixed) wrong element initialization in "src/init.c"
1053 inline void DrawGameValue_Emeralds(int value)
1055 DrawText(DX_EMERALDS, DY_EMERALDS, int2str(value, 3), FONT_TEXT_2);
1058 inline void DrawGameValue_Dynamite(int value)
1060 DrawText(DX_DYNAMITE, DY_DYNAMITE, int2str(value, 3), FONT_TEXT_2);
1063 inline void DrawGameValue_Keys(struct PlayerInfo *player)
1067 for (i = 0; i < MAX_KEYS; i++)
1069 DrawMiniGraphicExt(drawto, DX_KEYS + i * MINI_TILEX, DY_KEYS,
1070 el2edimg(EL_KEY_1 + i));
1073 inline void DrawGameValue_Score(int value)
1075 DrawText(DX_SCORE, DY_SCORE, int2str(value, 5), FONT_TEXT_2);
1078 inline void DrawGameValue_Time(int value)
1081 DrawText(DX_TIME1, DY_TIME, int2str(value, 3), FONT_TEXT_2);
1083 DrawText(DX_TIME2, DY_TIME, int2str(value, 4), FONT_LEVEL_NUMBER);
1086 inline void DrawGameValue_Level(int value)
1089 DrawText(DX_LEVEL, DY_LEVEL, int2str(value, 2), FONT_TEXT_2);
1092 /* misuse area for displaying emeralds to draw bigger level number */
1093 DrawTextExt(drawto, DX_EMERALDS, DY_EMERALDS,
1094 int2str(value, 3), FONT_LEVEL_NUMBER, BLIT_OPAQUE);
1096 /* now copy it to the area for displaying level number */
1097 BlitBitmap(drawto, drawto,
1098 DX_EMERALDS, DY_EMERALDS + 1,
1099 getFontWidth(FONT_LEVEL_NUMBER) * 3,
1100 getFontHeight(FONT_LEVEL_NUMBER) - 1,
1101 DX_LEVEL - 1, DY_LEVEL + 1);
1103 /* restore the area for displaying emeralds */
1104 DrawGameValue_Emeralds(local_player->gems_still_needed);
1106 /* yes, this is all really ugly :-) */
1110 void DrawGameDoorValues()
1114 DrawGameValue_Level(level_nr);
1116 for (i = 0; i < MAX_PLAYERS; i++)
1117 DrawGameValue_Keys(&stored_player[i]);
1119 DrawGameValue_Emeralds(local_player->gems_still_needed);
1120 DrawGameValue_Dynamite(local_player->inventory_size);
1121 DrawGameValue_Score(local_player->score);
1122 DrawGameValue_Time(TimeLeft);
1125 static void resolve_group_element(int group_element, int recursion_depth)
1127 static int group_nr;
1128 static struct ElementGroupInfo *group;
1129 struct ElementGroupInfo *actual_group = element_info[group_element].group;
1132 if (recursion_depth > NUM_GROUP_ELEMENTS) /* recursion too deep */
1134 Error(ERR_WARN, "recursion too deep when resolving group element %d",
1135 group_element - EL_GROUP_START + 1);
1137 /* replace element which caused too deep recursion by question mark */
1138 group->element_resolved[group->num_elements_resolved++] = EL_UNKNOWN;
1143 if (recursion_depth == 0) /* initialization */
1145 group = element_info[group_element].group;
1146 group_nr = group_element - EL_GROUP_START;
1148 group->num_elements_resolved = 0;
1149 group->choice_pos = 0;
1152 for (i = 0; i < actual_group->num_elements; i++)
1154 int element = actual_group->element[i];
1156 if (group->num_elements_resolved == NUM_FILE_ELEMENTS)
1159 if (IS_GROUP_ELEMENT(element))
1160 resolve_group_element(element, recursion_depth + 1);
1163 group->element_resolved[group->num_elements_resolved++] = element;
1164 element_info[element].in_group[group_nr] = TRUE;
1169 if (recursion_depth == 0 && group_element <= EL_GROUP_4)
1171 printf("::: group %d: %d resolved elements\n",
1172 group_element - EL_GROUP_START, group->num_elements_resolved);
1173 for (i = 0; i < group->num_elements_resolved; i++)
1174 printf("::: - %d ['%s']\n", group->element_resolved[i],
1175 element_info[group->element_resolved[i]].token_name);
1182 =============================================================================
1184 -----------------------------------------------------------------------------
1185 initialize game engine due to level / tape version number
1186 =============================================================================
1189 static void InitGameEngine()
1193 /* set game engine from tape file when re-playing, else from level file */
1194 game.engine_version = (tape.playing ? tape.engine_version :
1195 level.game_version);
1197 /* dynamically adjust element properties according to game engine version */
1198 InitElementPropertiesEngine(game.engine_version);
1201 printf("level %d: level version == %06d\n", level_nr, level.game_version);
1202 printf(" tape version == %06d [%s] [file: %06d]\n",
1203 tape.engine_version, (tape.playing ? "PLAYING" : "RECORDING"),
1205 printf(" => game.engine_version == %06d\n", game.engine_version);
1208 /* ---------- recursively resolve group elements ------------------------- */
1210 for (i = 0; i < MAX_NUM_ELEMENTS; i++)
1211 for (j = 0; j < NUM_GROUP_ELEMENTS; j++)
1212 element_info[i].in_group[j] = FALSE;
1214 for (i = 0; i < NUM_GROUP_ELEMENTS; i++)
1215 resolve_group_element(EL_GROUP_START + i, 0);
1217 /* ---------- initialize player's initial move delay --------------------- */
1219 #if USE_NEW_MOVE_DELAY
1220 /* dynamically adjust player properties according to level information */
1221 game.initial_move_delay_value =
1222 (level.double_speed ? MOVE_DELAY_HIGH_SPEED : MOVE_DELAY_NORMAL_SPEED);
1224 /* dynamically adjust player properties according to game engine version */
1225 game.initial_move_delay = (game.engine_version <= VERSION_IDENT(2,0,1,0) ?
1226 game.initial_move_delay_value : 0);
1228 /* dynamically adjust player properties according to game engine version */
1229 game.initial_move_delay =
1230 (game.engine_version <= VERSION_IDENT(2,0,1,0) ? INITIAL_MOVE_DELAY_ON :
1231 INITIAL_MOVE_DELAY_OFF);
1233 /* dynamically adjust player properties according to level information */
1234 game.initial_move_delay_value =
1235 (level.double_speed ? MOVE_DELAY_HIGH_SPEED : MOVE_DELAY_NORMAL_SPEED);
1238 /* ---------- initialize player's initial push delay --------------------- */
1240 /* dynamically adjust player properties according to game engine version */
1241 game.initial_push_delay_value =
1242 (game.engine_version < VERSION_IDENT(3,0,7,1) ? 5 : -1);
1244 /* ---------- initialize changing elements ------------------------------- */
1246 /* initialize changing elements information */
1247 for (i = 0; i < MAX_NUM_ELEMENTS; i++)
1249 struct ElementInfo *ei = &element_info[i];
1251 /* this pointer might have been changed in the level editor */
1252 ei->change = &ei->change_page[0];
1254 if (!IS_CUSTOM_ELEMENT(i))
1256 ei->change->target_element = EL_EMPTY_SPACE;
1257 ei->change->delay_fixed = 0;
1258 ei->change->delay_random = 0;
1259 ei->change->delay_frames = 1;
1262 ei->change_events = CE_BITMASK_DEFAULT;
1263 for (j = 0; j < NUM_CHANGE_EVENTS; j++)
1265 ei->event_page_nr[j] = 0;
1266 ei->event_page[j] = &ei->change_page[0];
1270 /* add changing elements from pre-defined list */
1271 for (i = 0; change_delay_list[i].element != EL_UNDEFINED; i++)
1273 struct ChangingElementInfo *ch_delay = &change_delay_list[i];
1274 struct ElementInfo *ei = &element_info[ch_delay->element];
1276 ei->change->target_element = ch_delay->target_element;
1277 ei->change->delay_fixed = ch_delay->change_delay;
1279 ei->change->pre_change_function = ch_delay->pre_change_function;
1280 ei->change->change_function = ch_delay->change_function;
1281 ei->change->post_change_function = ch_delay->post_change_function;
1283 ei->change_events |= CH_EVENT_BIT(CE_DELAY);
1286 SET_PROPERTY(ch_delay->element, EP_CAN_CHANGE, TRUE);
1291 /* add change events from custom element configuration */
1292 for (i = 0; i < NUM_CUSTOM_ELEMENTS; i++)
1294 struct ElementInfo *ei = &element_info[EL_CUSTOM_START + i];
1296 for (j = 0; j < ei->num_change_pages; j++)
1298 if (!ei->change_page[j].can_change)
1301 for (k = 0; k < NUM_CHANGE_EVENTS; k++)
1303 /* only add event page for the first page found with this event */
1304 if (ei->change_page[j].events & CH_EVENT_BIT(k) &&
1305 !(ei->change_events & CH_EVENT_BIT(k)))
1307 ei->change_events |= CH_EVENT_BIT(k);
1308 ei->event_page_nr[k] = j;
1309 ei->event_page[k] = &ei->change_page[j];
1317 /* add change events from custom element configuration */
1318 for (i = 0; i < NUM_CUSTOM_ELEMENTS; i++)
1320 int element = EL_CUSTOM_START + i;
1322 /* only add custom elements that change after fixed/random frame delay */
1323 if (CAN_CHANGE(element) && HAS_CHANGE_EVENT(element, CE_DELAY))
1324 element_info[element].change_events |= CH_EVENT_BIT(CE_DELAY);
1328 /* ---------- initialize run-time trigger player and element ------------- */
1330 for (i = 0; i < NUM_CUSTOM_ELEMENTS; i++)
1332 struct ElementInfo *ei = &element_info[EL_CUSTOM_START + i];
1334 for (j = 0; j < ei->num_change_pages; j++)
1336 ei->change_page[j].actual_trigger_element = EL_EMPTY;
1337 ei->change_page[j].actual_trigger_player = EL_PLAYER_1;
1341 /* ---------- initialize trigger events ---------------------------------- */
1343 /* initialize trigger events information */
1344 for (i = 0; i < MAX_NUM_ELEMENTS; i++)
1345 trigger_events[i] = EP_BITMASK_DEFAULT;
1348 /* add trigger events from element change event properties */
1349 for (i = 0; i < MAX_NUM_ELEMENTS; i++)
1351 struct ElementInfo *ei = &element_info[i];
1353 for (j = 0; j < ei->num_change_pages; j++)
1355 if (!ei->change_page[j].can_change)
1358 if (ei->change_page[j].events & CH_EVENT_BIT(CE_BY_OTHER_ACTION))
1360 int trigger_element = ei->change_page[j].trigger_element;
1362 if (IS_GROUP_ELEMENT(trigger_element))
1364 struct ElementGroupInfo *group = element_info[trigger_element].group;
1366 for (k = 0; k < group->num_elements_resolved; k++)
1367 trigger_events[group->element_resolved[k]]
1368 |= ei->change_page[j].events;
1371 trigger_events[trigger_element] |= ei->change_page[j].events;
1376 /* add trigger events from element change event properties */
1377 for (i = 0; i < MAX_NUM_ELEMENTS; i++)
1378 if (HAS_CHANGE_EVENT(i, CE_BY_OTHER_ACTION))
1379 trigger_events[element_info[i].change->trigger_element] |=
1380 element_info[i].change->events;
1383 /* ---------- initialize push delay -------------------------------------- */
1385 /* initialize push delay values to default */
1386 for (i = 0; i < MAX_NUM_ELEMENTS; i++)
1388 if (!IS_CUSTOM_ELEMENT(i))
1390 element_info[i].push_delay_fixed = game.default_push_delay_fixed;
1391 element_info[i].push_delay_random = game.default_push_delay_random;
1395 /* set push delay value for certain elements from pre-defined list */
1396 for (i = 0; push_delay_list[i].element != EL_UNDEFINED; i++)
1398 int e = push_delay_list[i].element;
1400 element_info[e].push_delay_fixed = push_delay_list[i].push_delay_fixed;
1401 element_info[e].push_delay_random = push_delay_list[i].push_delay_random;
1404 /* set push delay value for Supaplex elements for newer engine versions */
1405 if (game.engine_version >= VERSION_IDENT(3,1,0,0))
1407 for (i = 0; i < MAX_NUM_ELEMENTS; i++)
1409 if (IS_SP_ELEMENT(i))
1411 #if USE_NEW_MOVE_STYLE
1412 /* set SP push delay to just enough to push under a falling zonk */
1413 int delay = (game.engine_version >= VERSION_IDENT(3,1,1,0) ? 8 : 6);
1415 element_info[i].push_delay_fixed = delay;
1416 element_info[i].push_delay_random = 0;
1418 element_info[i].push_delay_fixed = 6; /* just enough to escape ... */
1419 element_info[i].push_delay_random = 0; /* ... from falling zonk */
1425 /* ---------- initialize move stepsize ----------------------------------- */
1427 /* initialize move stepsize values to default */
1428 for (i = 0; i < MAX_NUM_ELEMENTS; i++)
1429 if (!IS_CUSTOM_ELEMENT(i))
1430 element_info[i].move_stepsize = MOVE_STEPSIZE_NORMAL;
1432 /* set move stepsize value for certain elements from pre-defined list */
1433 for (i = 0; move_stepsize_list[i].element != EL_UNDEFINED; i++)
1435 int e = move_stepsize_list[i].element;
1437 element_info[e].move_stepsize = move_stepsize_list[i].move_stepsize;
1441 /* ---------- initialize move dig/leave ---------------------------------- */
1443 for (i = 0; i < MAX_NUM_ELEMENTS; i++)
1445 element_info[i].can_leave_element = FALSE;
1446 element_info[i].can_leave_element_last = FALSE;
1450 /* ---------- initialize gem count --------------------------------------- */
1452 /* initialize gem count values for each element */
1453 for (i = 0; i < MAX_NUM_ELEMENTS; i++)
1454 if (!IS_CUSTOM_ELEMENT(i))
1455 element_info[i].collect_count = 0;
1457 /* add gem count values for all elements from pre-defined list */
1458 for (i = 0; collect_count_list[i].element != EL_UNDEFINED; i++)
1459 element_info[collect_count_list[i].element].collect_count =
1460 collect_count_list[i].count;
1462 /* ---------- initialize access direction -------------------------------- */
1464 /* initialize access direction values to default (access from every side) */
1465 for (i = 0; i < MAX_NUM_ELEMENTS; i++)
1466 if (!IS_CUSTOM_ELEMENT(i))
1467 element_info[i].access_direction = MV_ALL_DIRECTIONS;
1469 /* set access direction value for certain elements from pre-defined list */
1470 for (i = 0; access_direction_list[i].element != EL_UNDEFINED; i++)
1471 element_info[access_direction_list[i].element].access_direction =
1472 access_direction_list[i].direction;
1477 =============================================================================
1479 -----------------------------------------------------------------------------
1480 initialize and start new game
1481 =============================================================================
1486 boolean emulate_bd = TRUE; /* unless non-BOULDERDASH elements found */
1487 boolean emulate_sb = TRUE; /* unless non-SOKOBAN elements found */
1488 boolean emulate_sp = TRUE; /* unless non-SUPAPLEX elements found */
1495 #if USE_NEW_AMOEBA_CODE
1496 printf("Using new amoeba code.\n");
1498 printf("Using old amoeba code.\n");
1503 /* don't play tapes over network */
1504 network_playing = (options.network && !tape.playing);
1506 for (i = 0; i < MAX_PLAYERS; i++)
1508 struct PlayerInfo *player = &stored_player[i];
1510 player->index_nr = i;
1511 player->index_bit = (1 << i);
1512 player->element_nr = EL_PLAYER_1 + i;
1514 player->present = FALSE;
1515 player->active = FALSE;
1518 player->effective_action = 0;
1519 player->programmed_action = 0;
1522 player->gems_still_needed = level.gems_needed;
1523 player->sokobanfields_still_needed = 0;
1524 player->lights_still_needed = 0;
1525 player->friends_still_needed = 0;
1527 for (j = 0; j < MAX_KEYS; j++)
1528 player->key[j] = FALSE;
1530 player->dynabomb_count = 0;
1531 player->dynabomb_size = 1;
1532 player->dynabombs_left = 0;
1533 player->dynabomb_xl = FALSE;
1535 player->MovDir = MV_NO_MOVING;
1538 player->GfxDir = MV_NO_MOVING;
1539 player->GfxAction = ACTION_DEFAULT;
1541 player->StepFrame = 0;
1543 player->use_murphy_graphic = FALSE;
1545 player->block_last_field = FALSE; /* initialized in InitPlayerField() */
1546 player->block_delay = -1; /* initialized in InitPlayerField() */
1548 player->can_fall_into_acid = CAN_MOVE_INTO_ACID(player->element_nr);
1550 player->actual_frame_counter = 0;
1552 player->step_counter = 0;
1554 player->last_move_dir = MV_NO_MOVING;
1556 player->is_waiting = FALSE;
1557 player->is_moving = FALSE;
1558 player->is_auto_moving = FALSE;
1559 player->is_digging = FALSE;
1560 player->is_snapping = FALSE;
1561 player->is_collecting = FALSE;
1562 player->is_pushing = FALSE;
1563 player->is_switching = FALSE;
1564 player->is_dropping = FALSE;
1566 player->is_bored = FALSE;
1567 player->is_sleeping = FALSE;
1569 player->frame_counter_bored = -1;
1570 player->frame_counter_sleeping = -1;
1572 player->anim_delay_counter = 0;
1573 player->post_delay_counter = 0;
1575 player->action_waiting = ACTION_DEFAULT;
1576 player->last_action_waiting = ACTION_DEFAULT;
1577 player->special_action_bored = ACTION_DEFAULT;
1578 player->special_action_sleeping = ACTION_DEFAULT;
1580 player->num_special_action_bored = 0;
1581 player->num_special_action_sleeping = 0;
1583 /* determine number of special actions for bored and sleeping animation */
1584 for (j = ACTION_BORING_1; j <= ACTION_BORING_LAST; j++)
1586 boolean found = FALSE;
1588 for (k = 0; k < NUM_DIRECTIONS; k++)
1589 if (el_act_dir2img(player->element_nr, j, k) !=
1590 el_act_dir2img(player->element_nr, ACTION_DEFAULT, k))
1594 player->num_special_action_bored++;
1598 for (j = ACTION_SLEEPING_1; j <= ACTION_SLEEPING_LAST; j++)
1600 boolean found = FALSE;
1602 for (k = 0; k < NUM_DIRECTIONS; k++)
1603 if (el_act_dir2img(player->element_nr, j, k) !=
1604 el_act_dir2img(player->element_nr, ACTION_DEFAULT, k))
1608 player->num_special_action_sleeping++;
1613 player->switch_x = -1;
1614 player->switch_y = -1;
1616 player->show_envelope = 0;
1618 player->move_delay = game.initial_move_delay;
1619 player->move_delay_value = game.initial_move_delay_value;
1621 player->move_delay_reset_counter = 0;
1623 #if USE_NEW_PUSH_DELAY
1624 player->push_delay = -1; /* initialized when pushing starts */
1625 player->push_delay_value = game.initial_push_delay_value;
1627 player->push_delay = 0;
1628 player->push_delay_value = game.initial_push_delay_value;
1631 player->drop_delay = 0;
1633 player->last_jx = player->last_jy = 0;
1634 player->jx = player->jy = 0;
1636 player->shield_normal_time_left = 0;
1637 player->shield_deadly_time_left = 0;
1639 player->inventory_infinite_element = EL_UNDEFINED;
1640 player->inventory_size = 0;
1642 DigField(player, 0, 0, 0, 0, 0, 0, DF_NO_PUSH);
1643 SnapField(player, 0, 0);
1645 player->LevelSolved = FALSE;
1646 player->GameOver = FALSE;
1649 network_player_action_received = FALSE;
1651 #if defined(NETWORK_AVALIABLE)
1652 /* initial null action */
1653 if (network_playing)
1654 SendToServer_MovePlayer(MV_NO_MOVING);
1662 TimeLeft = level.time;
1665 ScreenMovDir = MV_NO_MOVING;
1669 ScrollStepSize = 0; /* will be correctly initialized by ScrollScreen() */
1671 AllPlayersGone = FALSE;
1673 game.yamyam_content_nr = 0;
1674 game.magic_wall_active = FALSE;
1675 game.magic_wall_time_left = 0;
1676 game.light_time_left = 0;
1677 game.timegate_time_left = 0;
1678 game.switchgate_pos = 0;
1679 game.balloon_dir = MV_NO_MOVING;
1680 game.gravity = level.initial_gravity;
1681 game.explosions_delayed = TRUE;
1683 game.envelope_active = FALSE;
1685 for (i = 0; i < NUM_BELTS; i++)
1687 game.belt_dir[i] = MV_NO_MOVING;
1688 game.belt_dir_nr[i] = 3; /* not moving, next moving left */
1691 for (i = 0; i < MAX_NUM_AMOEBA; i++)
1692 AmoebaCnt[i] = AmoebaCnt2[i] = 0;
1694 for (x = 0; x < lev_fieldx; x++)
1696 for (y = 0; y < lev_fieldy; y++)
1698 Feld[x][y] = level.field[x][y];
1699 MovPos[x][y] = MovDir[x][y] = MovDelay[x][y] = 0;
1700 ChangeDelay[x][y] = 0;
1701 ChangePage[x][y] = -1;
1702 Store[x][y] = Store2[x][y] = StorePlayer[x][y] = Back[x][y] = 0;
1704 WasJustMoving[x][y] = 0;
1705 WasJustFalling[x][y] = 0;
1706 CheckCollision[x][y] = 0;
1708 Pushed[x][y] = FALSE;
1710 Changed[x][y] = CE_BITMASK_DEFAULT;
1711 ChangeEvent[x][y] = CE_BITMASK_DEFAULT;
1713 ExplodePhase[x][y] = 0;
1714 ExplodeDelay[x][y] = 0;
1715 ExplodeField[x][y] = EX_TYPE_NONE;
1717 RunnerVisit[x][y] = 0;
1718 PlayerVisit[x][y] = 0;
1721 GfxRandom[x][y] = INIT_GFX_RANDOM();
1722 GfxElement[x][y] = EL_UNDEFINED;
1723 GfxAction[x][y] = ACTION_DEFAULT;
1724 GfxDir[x][y] = MV_NO_MOVING;
1728 for (y = 0; y < lev_fieldy; y++)
1730 for (x = 0; x < lev_fieldx; x++)
1732 if (emulate_bd && !IS_BD_ELEMENT(Feld[x][y]))
1734 if (emulate_sb && !IS_SB_ELEMENT(Feld[x][y]))
1736 if (emulate_sp && !IS_SP_ELEMENT(Feld[x][y]))
1739 InitField(x, y, TRUE);
1745 game.emulation = (emulate_bd ? EMU_BOULDERDASH :
1746 emulate_sb ? EMU_SOKOBAN :
1747 emulate_sp ? EMU_SUPAPLEX : EMU_NONE);
1749 /* initialize explosion and ignition delay */
1750 for (i = 0; i < MAX_NUM_ELEMENTS; i++)
1752 if (!IS_CUSTOM_ELEMENT(i))
1755 int delay = (((IS_SP_ELEMENT(i) && i != EL_EMPTY_SPACE) &&
1756 game.engine_version >= VERSION_IDENT(3,1,0,0)) ||
1757 game.emulation == EMU_SUPAPLEX ? 3 : 2);
1758 int last_phase = (num_phase + 1) * delay;
1759 int half_phase = (num_phase / 2) * delay;
1761 element_info[i].explosion_delay = last_phase - 1;
1762 element_info[i].ignition_delay = half_phase;
1765 if (i == EL_BLACK_ORB)
1766 element_info[i].ignition_delay = 0;
1768 if (i == EL_BLACK_ORB)
1769 element_info[i].ignition_delay = 1;
1774 if (element_info[i].explosion_delay < 1) /* !!! check again !!! */
1775 element_info[i].explosion_delay = 1;
1777 if (element_info[i].ignition_delay < 1) /* !!! check again !!! */
1778 element_info[i].ignition_delay = 1;
1782 /* correct non-moving belts to start moving left */
1783 for (i = 0; i < NUM_BELTS; i++)
1784 if (game.belt_dir[i] == MV_NO_MOVING)
1785 game.belt_dir_nr[i] = 3; /* not moving, next moving left */
1787 /* check if any connected player was not found in playfield */
1788 for (i = 0; i < MAX_PLAYERS; i++)
1790 struct PlayerInfo *player = &stored_player[i];
1792 if (player->connected && !player->present)
1794 for (j = 0; j < MAX_PLAYERS; j++)
1796 struct PlayerInfo *some_player = &stored_player[j];
1797 int jx = some_player->jx, jy = some_player->jy;
1799 /* assign first free player found that is present in the playfield */
1800 if (some_player->present && !some_player->connected)
1802 player->present = TRUE;
1803 player->active = TRUE;
1805 some_player->present = FALSE;
1806 some_player->active = FALSE;
1809 player->element_nr = some_player->element_nr;
1812 #if USE_NEW_BLOCK_STYLE
1813 player->block_last_field = some_player->block_last_field;
1814 player->block_delay = some_player->block_delay;
1817 StorePlayer[jx][jy] = player->element_nr;
1818 player->jx = player->last_jx = jx;
1819 player->jy = player->last_jy = jy;
1829 /* when playing a tape, eliminate all players which do not participate */
1831 for (i = 0; i < MAX_PLAYERS; i++)
1833 if (stored_player[i].active && !tape.player_participates[i])
1835 struct PlayerInfo *player = &stored_player[i];
1836 int jx = player->jx, jy = player->jy;
1838 player->active = FALSE;
1839 StorePlayer[jx][jy] = 0;
1840 Feld[jx][jy] = EL_EMPTY;
1844 else if (!options.network && !setup.team_mode) /* && !tape.playing */
1846 /* when in single player mode, eliminate all but the first active player */
1848 for (i = 0; i < MAX_PLAYERS; i++)
1850 if (stored_player[i].active)
1852 for (j = i + 1; j < MAX_PLAYERS; j++)
1854 if (stored_player[j].active)
1856 struct PlayerInfo *player = &stored_player[j];
1857 int jx = player->jx, jy = player->jy;
1859 player->active = FALSE;
1860 player->present = FALSE;
1862 StorePlayer[jx][jy] = 0;
1863 Feld[jx][jy] = EL_EMPTY;
1870 /* when recording the game, store which players take part in the game */
1873 for (i = 0; i < MAX_PLAYERS; i++)
1874 if (stored_player[i].active)
1875 tape.player_participates[i] = TRUE;
1880 for (i = 0; i < MAX_PLAYERS; i++)
1882 struct PlayerInfo *player = &stored_player[i];
1884 printf("Player %d: present == %d, connected == %d, active == %d.\n",
1889 if (local_player == player)
1890 printf("Player %d is local player.\n", i+1);
1894 if (BorderElement == EL_EMPTY)
1897 SBX_Right = lev_fieldx - SCR_FIELDX;
1899 SBY_Lower = lev_fieldy - SCR_FIELDY;
1904 SBX_Right = lev_fieldx - SCR_FIELDX + 1;
1906 SBY_Lower = lev_fieldy - SCR_FIELDY + 1;
1909 if (lev_fieldx + (SBX_Left == -1 ? 2 : 0) <= SCR_FIELDX)
1910 SBX_Left = SBX_Right = -1 * (SCR_FIELDX - lev_fieldx) / 2;
1912 if (lev_fieldy + (SBY_Upper == -1 ? 2 : 0) <= SCR_FIELDY)
1913 SBY_Upper = SBY_Lower = -1 * (SCR_FIELDY - lev_fieldy) / 2;
1915 /* if local player not found, look for custom element that might create
1916 the player (make some assumptions about the right custom element) */
1917 if (!local_player->present)
1919 int start_x = 0, start_y = 0;
1920 int found_rating = 0;
1921 int found_element = EL_UNDEFINED;
1923 for (y = 0; y < lev_fieldy; y++) for (x = 0; x < lev_fieldx; x++)
1925 int element = Feld[x][y];
1930 if (!IS_CUSTOM_ELEMENT(element))
1933 if (CAN_CHANGE(element))
1935 for (i = 0; i < element_info[element].num_change_pages; i++)
1937 content = element_info[element].change_page[i].target_element;
1938 is_player = ELEM_IS_PLAYER(content);
1940 if (is_player && (found_rating < 3 || element < found_element))
1946 found_element = element;
1951 for (yy = 0; yy < 3; yy++) for (xx = 0; xx < 3; xx++)
1953 content = element_info[element].content[xx][yy];
1954 is_player = ELEM_IS_PLAYER(content);
1956 if (is_player && (found_rating < 2 || element < found_element))
1958 start_x = x + xx - 1;
1959 start_y = y + yy - 1;
1962 found_element = element;
1965 if (!CAN_CHANGE(element))
1968 for (i = 0; i < element_info[element].num_change_pages; i++)
1970 content= element_info[element].change_page[i].target_content[xx][yy];
1971 is_player = ELEM_IS_PLAYER(content);
1973 if (is_player && (found_rating < 1 || element < found_element))
1975 start_x = x + xx - 1;
1976 start_y = y + yy - 1;
1979 found_element = element;
1985 scroll_x = (start_x < SBX_Left + MIDPOSX ? SBX_Left :
1986 start_x > SBX_Right + MIDPOSX ? SBX_Right :
1989 scroll_y = (start_y < SBY_Upper + MIDPOSY ? SBY_Upper :
1990 start_y > SBY_Lower + MIDPOSY ? SBY_Lower :
1996 scroll_x = (local_player->jx < SBX_Left + MIDPOSX ? SBX_Left :
1997 local_player->jx > SBX_Right + MIDPOSX ? SBX_Right :
1998 local_player->jx - MIDPOSX);
2000 scroll_y = (local_player->jy < SBY_Upper + MIDPOSY ? SBY_Upper :
2001 local_player->jy > SBY_Lower + MIDPOSY ? SBY_Lower :
2002 local_player->jy - MIDPOSY);
2004 scroll_x = SBX_Left;
2005 scroll_y = SBY_Upper;
2006 if (local_player->jx >= SBX_Left + MIDPOSX)
2007 scroll_x = (local_player->jx <= SBX_Right + MIDPOSX ?
2008 local_player->jx - MIDPOSX :
2010 if (local_player->jy >= SBY_Upper + MIDPOSY)
2011 scroll_y = (local_player->jy <= SBY_Lower + MIDPOSY ?
2012 local_player->jy - MIDPOSY :
2017 CloseDoor(DOOR_CLOSE_1);
2022 /* after drawing the level, correct some elements */
2023 if (game.timegate_time_left == 0)
2024 CloseAllOpenTimegates();
2026 if (setup.soft_scrolling)
2027 BlitBitmap(fieldbuffer, backbuffer, FX, FY, SXSIZE, SYSIZE, SX, SY);
2029 redraw_mask |= REDRAW_FROM_BACKBUFFER;
2032 /* copy default game door content to main double buffer */
2033 BlitBitmap(graphic_info[IMG_GLOBAL_DOOR].bitmap, drawto,
2034 DOOR_GFX_PAGEX5, DOOR_GFX_PAGEY1, DXSIZE, DYSIZE, DX, DY);
2036 DrawGameDoorValues();
2040 game_gadget[SOUND_CTRL_ID_MUSIC]->checked = setup.sound_music;
2041 game_gadget[SOUND_CTRL_ID_LOOPS]->checked = setup.sound_loops;
2042 game_gadget[SOUND_CTRL_ID_SIMPLE]->checked = setup.sound_simple;
2046 /* copy actual game door content to door double buffer for OpenDoor() */
2047 BlitBitmap(drawto, bitmap_db_door,
2048 DX, DY, DXSIZE, DYSIZE, DOOR_GFX_PAGEX1, DOOR_GFX_PAGEY1);
2050 OpenDoor(DOOR_OPEN_ALL);
2052 PlaySoundStereo(SND_GAME_STARTING, SOUND_MIDDLE);
2054 if (setup.sound_music)
2057 KeyboardAutoRepeatOffUnlessAutoplay();
2061 for (i = 0; i < MAX_PLAYERS; i++)
2062 printf("Player %d %sactive.\n",
2063 i + 1, (stored_player[i].active ? "" : "not "));
2067 printf("::: starting game [%d]\n", FrameCounter);
2071 void InitMovDir(int x, int y)
2073 int i, element = Feld[x][y];
2074 static int xy[4][2] =
2081 static int direction[3][4] =
2083 { MV_RIGHT, MV_UP, MV_LEFT, MV_DOWN },
2084 { MV_LEFT, MV_DOWN, MV_RIGHT, MV_UP },
2085 { MV_LEFT, MV_RIGHT, MV_UP, MV_DOWN }
2094 Feld[x][y] = EL_BUG;
2095 MovDir[x][y] = direction[0][element - EL_BUG_RIGHT];
2098 case EL_SPACESHIP_RIGHT:
2099 case EL_SPACESHIP_UP:
2100 case EL_SPACESHIP_LEFT:
2101 case EL_SPACESHIP_DOWN:
2102 Feld[x][y] = EL_SPACESHIP;
2103 MovDir[x][y] = direction[0][element - EL_SPACESHIP_RIGHT];
2106 case EL_BD_BUTTERFLY_RIGHT:
2107 case EL_BD_BUTTERFLY_UP:
2108 case EL_BD_BUTTERFLY_LEFT:
2109 case EL_BD_BUTTERFLY_DOWN:
2110 Feld[x][y] = EL_BD_BUTTERFLY;
2111 MovDir[x][y] = direction[0][element - EL_BD_BUTTERFLY_RIGHT];
2114 case EL_BD_FIREFLY_RIGHT:
2115 case EL_BD_FIREFLY_UP:
2116 case EL_BD_FIREFLY_LEFT:
2117 case EL_BD_FIREFLY_DOWN:
2118 Feld[x][y] = EL_BD_FIREFLY;
2119 MovDir[x][y] = direction[0][element - EL_BD_FIREFLY_RIGHT];
2122 case EL_PACMAN_RIGHT:
2124 case EL_PACMAN_LEFT:
2125 case EL_PACMAN_DOWN:
2126 Feld[x][y] = EL_PACMAN;
2127 MovDir[x][y] = direction[0][element - EL_PACMAN_RIGHT];
2130 case EL_SP_SNIKSNAK:
2131 MovDir[x][y] = MV_UP;
2134 case EL_SP_ELECTRON:
2135 MovDir[x][y] = MV_LEFT;
2142 Feld[x][y] = EL_MOLE;
2143 MovDir[x][y] = direction[2][element - EL_MOLE_LEFT];
2147 if (IS_CUSTOM_ELEMENT(element))
2149 struct ElementInfo *ei = &element_info[element];
2150 int move_direction_initial = ei->move_direction_initial;
2151 int move_pattern = ei->move_pattern;
2153 if (move_direction_initial == MV_START_PREVIOUS)
2155 if (MovDir[x][y] != MV_NO_MOVING)
2158 move_direction_initial = MV_START_AUTOMATIC;
2161 if (move_direction_initial == MV_START_RANDOM)
2162 MovDir[x][y] = 1 << RND(4);
2163 else if (move_direction_initial & MV_ANY_DIRECTION)
2164 MovDir[x][y] = move_direction_initial;
2165 else if (move_pattern == MV_ALL_DIRECTIONS ||
2166 move_pattern == MV_TURNING_LEFT ||
2167 move_pattern == MV_TURNING_RIGHT ||
2168 move_pattern == MV_TURNING_LEFT_RIGHT ||
2169 move_pattern == MV_TURNING_RIGHT_LEFT ||
2170 move_pattern == MV_TURNING_RANDOM)
2171 MovDir[x][y] = 1 << RND(4);
2172 else if (move_pattern == MV_HORIZONTAL)
2173 MovDir[x][y] = (RND(2) ? MV_LEFT : MV_RIGHT);
2174 else if (move_pattern == MV_VERTICAL)
2175 MovDir[x][y] = (RND(2) ? MV_UP : MV_DOWN);
2176 else if (move_pattern & MV_ANY_DIRECTION)
2177 MovDir[x][y] = element_info[element].move_pattern;
2178 else if (move_pattern == MV_ALONG_LEFT_SIDE ||
2179 move_pattern == MV_ALONG_RIGHT_SIDE)
2182 /* use random direction as default start direction */
2183 if (game.engine_version >= VERSION_IDENT(3,1,0,0))
2184 MovDir[x][y] = 1 << RND(4);
2187 for (i = 0; i < NUM_DIRECTIONS; i++)
2189 int x1 = x + xy[i][0];
2190 int y1 = y + xy[i][1];
2192 if (!IN_LEV_FIELD(x1, y1) || !IS_FREE(x1, y1))
2194 if (move_pattern == MV_ALONG_RIGHT_SIDE)
2195 MovDir[x][y] = direction[0][i];
2197 MovDir[x][y] = direction[1][i];
2206 MovDir[x][y] = 1 << RND(4);
2208 if (element != EL_BUG &&
2209 element != EL_SPACESHIP &&
2210 element != EL_BD_BUTTERFLY &&
2211 element != EL_BD_FIREFLY)
2214 for (i = 0; i < NUM_DIRECTIONS; i++)
2216 int x1 = x + xy[i][0];
2217 int y1 = y + xy[i][1];
2219 if (!IN_LEV_FIELD(x1, y1) || !IS_FREE(x1, y1))
2221 if (element == EL_BUG || element == EL_BD_BUTTERFLY)
2223 MovDir[x][y] = direction[0][i];
2226 else if (element == EL_SPACESHIP || element == EL_BD_FIREFLY ||
2227 element == EL_SP_SNIKSNAK || element == EL_SP_ELECTRON)
2229 MovDir[x][y] = direction[1][i];
2238 GfxDir[x][y] = MovDir[x][y];
2241 void InitAmoebaNr(int x, int y)
2244 int group_nr = AmoebeNachbarNr(x, y);
2248 for (i = 1; i < MAX_NUM_AMOEBA; i++)
2250 if (AmoebaCnt[i] == 0)
2258 AmoebaNr[x][y] = group_nr;
2259 AmoebaCnt[group_nr]++;
2260 AmoebaCnt2[group_nr]++;
2266 boolean raise_level = FALSE;
2268 if (local_player->MovPos)
2272 if (tape.auto_play) /* tape might already be stopped here */
2273 tape.auto_play_level_solved = TRUE;
2275 if (tape.playing && tape.auto_play)
2276 tape.auto_play_level_solved = TRUE;
2279 local_player->LevelSolved = FALSE;
2281 PlaySoundStereo(SND_GAME_WINNING, SOUND_MIDDLE);
2285 if (!tape.playing && setup.sound_loops)
2286 PlaySoundExt(SND_GAME_LEVELTIME_BONUS, SOUND_MAX_VOLUME, SOUND_MIDDLE,
2287 SND_CTRL_PLAY_LOOP);
2289 while (TimeLeft > 0)
2291 if (!tape.playing && !setup.sound_loops)
2292 PlaySoundStereo(SND_GAME_LEVELTIME_BONUS, SOUND_MIDDLE);
2293 if (TimeLeft > 0 && !(TimeLeft % 10))
2294 RaiseScore(level.score[SC_TIME_BONUS]);
2295 if (TimeLeft > 100 && !(TimeLeft % 10))
2300 DrawGameValue_Time(TimeLeft);
2308 if (!tape.playing && setup.sound_loops)
2309 StopSound(SND_GAME_LEVELTIME_BONUS);
2311 else if (level.time == 0) /* level without time limit */
2313 if (!tape.playing && setup.sound_loops)
2314 PlaySoundExt(SND_GAME_LEVELTIME_BONUS, SOUND_MAX_VOLUME, SOUND_MIDDLE,
2315 SND_CTRL_PLAY_LOOP);
2317 while (TimePlayed < 999)
2319 if (!tape.playing && !setup.sound_loops)
2320 PlaySoundStereo(SND_GAME_LEVELTIME_BONUS, SOUND_MIDDLE);
2321 if (TimePlayed < 999 && !(TimePlayed % 10))
2322 RaiseScore(level.score[SC_TIME_BONUS]);
2323 if (TimePlayed < 900 && !(TimePlayed % 10))
2328 DrawGameValue_Time(TimePlayed);
2336 if (!tape.playing && setup.sound_loops)
2337 StopSound(SND_GAME_LEVELTIME_BONUS);
2340 /* close exit door after last player */
2341 if ((Feld[ExitX][ExitY] == EL_EXIT_OPEN ||
2342 Feld[ExitX][ExitY] == EL_SP_EXIT_OPEN) && AllPlayersGone)
2344 int element = Feld[ExitX][ExitY];
2346 Feld[ExitX][ExitY] = (element == EL_EXIT_OPEN ? EL_EXIT_CLOSING :
2347 EL_SP_EXIT_CLOSING);
2349 PlayLevelSoundElementAction(ExitX, ExitY, element, ACTION_CLOSING);
2352 /* Hero disappears */
2353 DrawLevelField(ExitX, ExitY);
2359 CloseDoor(DOOR_CLOSE_1);
2364 SaveTape(tape.level_nr); /* Ask to save tape */
2367 if (level_nr == leveldir_current->handicap_level)
2369 leveldir_current->handicap_level++;
2370 SaveLevelSetup_SeriesInfo();
2373 if (level_editor_test_game)
2374 local_player->score = -1; /* no highscore when playing from editor */
2375 else if (level_nr < leveldir_current->last_level)
2376 raise_level = TRUE; /* advance to next level */
2378 if ((hi_pos = NewHiScore()) >= 0)
2380 game_status = GAME_MODE_SCORES;
2381 DrawHallOfFame(hi_pos);
2390 game_status = GAME_MODE_MAIN;
2407 LoadScore(level_nr);
2409 if (strcmp(setup.player_name, EMPTY_PLAYER_NAME) == 0 ||
2410 local_player->score < highscore[MAX_SCORE_ENTRIES - 1].Score)
2413 for (k = 0; k < MAX_SCORE_ENTRIES; k++)
2415 if (local_player->score > highscore[k].Score)
2417 /* player has made it to the hall of fame */
2419 if (k < MAX_SCORE_ENTRIES - 1)
2421 int m = MAX_SCORE_ENTRIES - 1;
2424 for (l = k; l < MAX_SCORE_ENTRIES; l++)
2425 if (!strcmp(setup.player_name, highscore[l].Name))
2427 if (m == k) /* player's new highscore overwrites his old one */
2431 for (l = m; l > k; l--)
2433 strcpy(highscore[l].Name, highscore[l - 1].Name);
2434 highscore[l].Score = highscore[l - 1].Score;
2441 strncpy(highscore[k].Name, setup.player_name, MAX_PLAYER_NAME_LEN);
2442 highscore[k].Name[MAX_PLAYER_NAME_LEN] = '\0';
2443 highscore[k].Score = local_player->score;
2449 else if (!strncmp(setup.player_name, highscore[k].Name,
2450 MAX_PLAYER_NAME_LEN))
2451 break; /* player already there with a higher score */
2457 SaveScore(level_nr);
2462 void InitPlayerGfxAnimation(struct PlayerInfo *player, int action, int dir)
2464 if (player->GfxAction != action || player->GfxDir != dir)
2467 printf("Player frame reset! (%d => %d, %d => %d)\n",
2468 player->GfxAction, action, player->GfxDir, dir);
2471 player->GfxAction = action;
2472 player->GfxDir = dir;
2474 player->StepFrame = 0;
2478 static void ResetRandomAnimationValue(int x, int y)
2480 GfxRandom[x][y] = INIT_GFX_RANDOM();
2483 static void ResetGfxAnimation(int x, int y)
2486 GfxAction[x][y] = ACTION_DEFAULT;
2487 GfxDir[x][y] = MovDir[x][y];
2490 void InitMovingField(int x, int y, int direction)
2492 int element = Feld[x][y];
2493 int dx = (direction == MV_LEFT ? -1 : direction == MV_RIGHT ? +1 : 0);
2494 int dy = (direction == MV_UP ? -1 : direction == MV_DOWN ? +1 : 0);
2498 if (!WasJustMoving[x][y] || direction != MovDir[x][y])
2499 ResetGfxAnimation(x, y);
2501 MovDir[newx][newy] = MovDir[x][y] = direction;
2502 GfxDir[x][y] = direction;
2504 if (Feld[newx][newy] == EL_EMPTY)
2505 Feld[newx][newy] = EL_BLOCKED;
2507 if (direction == MV_DOWN && CAN_FALL(element))
2508 GfxAction[x][y] = ACTION_FALLING;
2510 GfxAction[x][y] = ACTION_MOVING;
2512 GfxFrame[newx][newy] = GfxFrame[x][y];
2513 GfxRandom[newx][newy] = GfxRandom[x][y];
2514 GfxAction[newx][newy] = GfxAction[x][y];
2515 GfxDir[newx][newy] = GfxDir[x][y];
2518 void Moving2Blocked(int x, int y, int *goes_to_x, int *goes_to_y)
2520 int direction = MovDir[x][y];
2521 int newx = x + (direction == MV_LEFT ? -1 : direction == MV_RIGHT ? +1 : 0);
2522 int newy = y + (direction == MV_UP ? -1 : direction == MV_DOWN ? +1 : 0);
2528 void Blocked2Moving(int x, int y, int *comes_from_x, int *comes_from_y)
2530 int oldx = x, oldy = y;
2531 int direction = MovDir[x][y];
2533 if (direction == MV_LEFT)
2535 else if (direction == MV_RIGHT)
2537 else if (direction == MV_UP)
2539 else if (direction == MV_DOWN)
2542 *comes_from_x = oldx;
2543 *comes_from_y = oldy;
2546 int MovingOrBlocked2Element(int x, int y)
2548 int element = Feld[x][y];
2550 if (element == EL_BLOCKED)
2554 Blocked2Moving(x, y, &oldx, &oldy);
2555 return Feld[oldx][oldy];
2561 static int MovingOrBlocked2ElementIfNotLeaving(int x, int y)
2563 /* like MovingOrBlocked2Element(), but if element is moving
2564 and (x,y) is the field the moving element is just leaving,
2565 return EL_BLOCKED instead of the element value */
2566 int element = Feld[x][y];
2568 if (IS_MOVING(x, y))
2570 if (element == EL_BLOCKED)
2574 Blocked2Moving(x, y, &oldx, &oldy);
2575 return Feld[oldx][oldy];
2584 static void RemoveField(int x, int y)
2586 Feld[x][y] = EL_EMPTY;
2593 ChangeDelay[x][y] = 0;
2594 ChangePage[x][y] = -1;
2595 Pushed[x][y] = FALSE;
2598 ExplodeField[x][y] = EX_TYPE_NONE;
2601 GfxElement[x][y] = EL_UNDEFINED;
2602 GfxAction[x][y] = ACTION_DEFAULT;
2603 GfxDir[x][y] = MV_NO_MOVING;
2606 void RemoveMovingField(int x, int y)
2608 int oldx = x, oldy = y, newx = x, newy = y;
2609 int element = Feld[x][y];
2610 int next_element = EL_UNDEFINED;
2612 if (element != EL_BLOCKED && !IS_MOVING(x, y))
2615 if (IS_MOVING(x, y))
2617 Moving2Blocked(x, y, &newx, &newy);
2619 if (Feld[newx][newy] != EL_BLOCKED)
2622 if (Feld[newx][newy] != EL_BLOCKED)
2624 /* element is moving, but target field is not free (blocked), but
2625 already occupied by something different (example: acid pool);
2626 in this case, only remove the moving field, but not the target */
2628 RemoveField(oldx, oldy);
2630 Store[oldx][oldy] = Store2[oldx][oldy] = 0;
2632 DrawLevelField(oldx, oldy);
2638 else if (element == EL_BLOCKED)
2640 Blocked2Moving(x, y, &oldx, &oldy);
2641 if (!IS_MOVING(oldx, oldy))
2645 if (element == EL_BLOCKED &&
2646 (Feld[oldx][oldy] == EL_QUICKSAND_EMPTYING ||
2647 Feld[oldx][oldy] == EL_MAGIC_WALL_EMPTYING ||
2648 Feld[oldx][oldy] == EL_BD_MAGIC_WALL_EMPTYING ||
2649 Feld[oldx][oldy] == EL_AMOEBA_DROPPING))
2650 next_element = get_next_element(Feld[oldx][oldy]);
2652 RemoveField(oldx, oldy);
2653 RemoveField(newx, newy);
2655 Store[oldx][oldy] = Store2[oldx][oldy] = 0;
2657 if (next_element != EL_UNDEFINED)
2658 Feld[oldx][oldy] = next_element;
2660 DrawLevelField(oldx, oldy);
2661 DrawLevelField(newx, newy);
2664 void DrawDynamite(int x, int y)
2666 int sx = SCREENX(x), sy = SCREENY(y);
2667 int graphic = el2img(Feld[x][y]);
2670 if (!IN_SCR_FIELD(sx, sy) || IS_PLAYER(x, y))
2673 if (IS_WALKABLE_INSIDE(Back[x][y]))
2677 DrawGraphic(sx, sy, el2img(Back[x][y]), 0);
2678 else if (Store[x][y])
2679 DrawGraphic(sx, sy, el2img(Store[x][y]), 0);
2681 frame = getGraphicAnimationFrame(graphic, GfxFrame[x][y]);
2684 if (Back[x][y] || Store[x][y])
2685 DrawGraphicThruMask(sx, sy, graphic, frame);
2687 DrawGraphic(sx, sy, graphic, frame);
2689 if (game.emulation == EMU_SUPAPLEX)
2690 DrawGraphic(sx, sy, IMG_SP_DISK_RED, frame);
2691 else if (Store[x][y])
2692 DrawGraphicThruMask(sx, sy, graphic, frame);
2694 DrawGraphic(sx, sy, graphic, frame);
2698 void CheckDynamite(int x, int y)
2700 if (MovDelay[x][y] != 0) /* dynamite is still waiting to explode */
2704 if (MovDelay[x][y] != 0)
2707 PlayLevelSoundActionIfLoop(x, y, ACTION_ACTIVE);
2714 StopLevelSoundActionIfLoop(x, y, ACTION_ACTIVE);
2716 if (Feld[x][y] == EL_DYNAMITE_ACTIVE ||
2717 Feld[x][y] == EL_SP_DISK_RED_ACTIVE)
2718 StopSound(SND_DYNAMITE_ACTIVE);
2720 StopSound(SND_DYNABOMB_ACTIVE);
2726 void DrawRelocatePlayer(struct PlayerInfo *player)
2728 boolean ffwd_delay = (tape.playing && tape.fast_forward);
2729 boolean no_delay = (tape.warp_forward);
2730 int frame_delay_value = (ffwd_delay ? FfwdFrameDelay : GameFrameDelay);
2731 int wait_delay_value = (no_delay ? 0 : frame_delay_value);
2732 int jx = player->jx;
2733 int jy = player->jy;
2735 if (level.instant_relocation)
2738 int offset = (setup.scroll_delay ? 3 : 0);
2740 if (!IN_VIS_FIELD(SCREENX(jx), SCREENY(jy)))
2742 scroll_x = (local_player->jx < SBX_Left + MIDPOSX ? SBX_Left :
2743 local_player->jx > SBX_Right + MIDPOSX ? SBX_Right :
2744 local_player->jx - MIDPOSX);
2746 scroll_y = (local_player->jy < SBY_Upper + MIDPOSY ? SBY_Upper :
2747 local_player->jy > SBY_Lower + MIDPOSY ? SBY_Lower :
2748 local_player->jy - MIDPOSY);
2752 if ((player->MovDir == MV_LEFT && scroll_x > jx - MIDPOSX + offset) ||
2753 (player->MovDir == MV_RIGHT && scroll_x < jx - MIDPOSX - offset))
2754 scroll_x = jx - MIDPOSX + (scroll_x < jx-MIDPOSX ? -offset : +offset);
2756 if ((player->MovDir == MV_UP && scroll_y > jy - MIDPOSY + offset) ||
2757 (player->MovDir == MV_DOWN && scroll_y < jy - MIDPOSY - offset))
2758 scroll_y = jy - MIDPOSY + (scroll_y < jy-MIDPOSY ? -offset : +offset);
2760 /* don't scroll over playfield boundaries */
2761 if (scroll_x < SBX_Left || scroll_x > SBX_Right)
2762 scroll_x = (scroll_x < SBX_Left ? SBX_Left : SBX_Right);
2764 /* don't scroll over playfield boundaries */
2765 if (scroll_y < SBY_Upper || scroll_y > SBY_Lower)
2766 scroll_y = (scroll_y < SBY_Upper ? SBY_Upper : SBY_Lower);
2769 scroll_x += (local_player->jx - old_jx);
2770 scroll_y += (local_player->jy - old_jy);
2772 /* don't scroll over playfield boundaries */
2773 if (scroll_x < SBX_Left || scroll_x > SBX_Right)
2774 scroll_x = (scroll_x < SBX_Left ? SBX_Left : SBX_Right);
2776 /* don't scroll over playfield boundaries */
2777 if (scroll_y < SBY_Upper || scroll_y > SBY_Lower)
2778 scroll_y = (scroll_y < SBY_Upper ? SBY_Upper : SBY_Lower);
2781 RedrawPlayfield(TRUE, 0,0,0,0);
2787 int offset = (setup.scroll_delay ? 3 : 0);
2789 int scroll_xx = -999, scroll_yy = -999;
2791 ScrollScreen(NULL, SCROLL_GO_ON); /* scroll last frame to full tile */
2793 while (scroll_xx != scroll_x || scroll_yy != scroll_y)
2796 int fx = FX, fy = FY;
2798 scroll_xx = (local_player->jx < SBX_Left + MIDPOSX ? SBX_Left :
2799 local_player->jx > SBX_Right + MIDPOSX ? SBX_Right :
2800 local_player->jx - MIDPOSX);
2802 scroll_yy = (local_player->jy < SBY_Upper + MIDPOSY ? SBY_Upper :
2803 local_player->jy > SBY_Lower + MIDPOSY ? SBY_Lower :
2804 local_player->jy - MIDPOSY);
2806 dx = (scroll_xx < scroll_x ? +1 : scroll_xx > scroll_x ? -1 : 0);
2807 dy = (scroll_yy < scroll_y ? +1 : scroll_yy > scroll_y ? -1 : 0);
2810 if (dx == 0 && dy == 0) /* no scrolling needed at all */
2813 if (scroll_xx == scroll_x && scroll_yy == scroll_y)
2820 fx += dx * TILEX / 2;
2821 fy += dy * TILEY / 2;
2823 ScrollLevel(dx, dy);
2826 /* scroll in two steps of half tile size to make things smoother */
2827 BlitBitmap(drawto_field, window, fx, fy, SXSIZE, SYSIZE, SX, SY);
2829 Delay(wait_delay_value);
2831 /* scroll second step to align at full tile size */
2833 Delay(wait_delay_value);
2836 int scroll_xx = -999, scroll_yy = -999;
2838 ScrollScreen(NULL, SCROLL_GO_ON); /* scroll last frame to full tile */
2840 while (scroll_xx != scroll_x || scroll_yy != scroll_y)
2843 int fx = FX, fy = FY;
2845 scroll_xx = (local_player->jx < SBX_Left + MIDPOSX ? SBX_Left :
2846 local_player->jx > SBX_Right + MIDPOSX ? SBX_Right :
2847 local_player->jx - MIDPOSX);
2849 scroll_yy = (local_player->jy < SBY_Upper + MIDPOSY ? SBY_Upper :
2850 local_player->jy > SBY_Lower + MIDPOSY ? SBY_Lower :
2851 local_player->jy - MIDPOSY);
2853 dx = (scroll_xx < scroll_x ? +1 : scroll_xx > scroll_x ? -1 : 0);
2854 dy = (scroll_yy < scroll_y ? +1 : scroll_yy > scroll_y ? -1 : 0);
2857 if (dx == 0 && dy == 0) /* no scrolling needed at all */
2860 if (scroll_xx == scroll_x && scroll_yy == scroll_y)
2867 fx += dx * TILEX / 2;
2868 fy += dy * TILEY / 2;
2870 ScrollLevel(dx, dy);
2873 /* scroll in two steps of half tile size to make things smoother */
2874 BlitBitmap(drawto_field, window, fx, fy, SXSIZE, SYSIZE, SX, SY);
2876 Delay(wait_delay_value);
2878 /* scroll second step to align at full tile size */
2880 Delay(wait_delay_value);
2886 Delay(wait_delay_value);
2890 void RelocatePlayer(int jx, int jy, int el_player_raw)
2893 int el_player = GET_VALID_PLAYER_ELEMENT(el_player_raw);
2895 int el_player = (el_player_raw == EL_SP_MURPHY ? EL_PLAYER_1 :el_player_raw);
2897 struct PlayerInfo *player = &stored_player[el_player - EL_PLAYER_1];
2898 boolean ffwd_delay = (tape.playing && tape.fast_forward);
2899 boolean no_delay = (tape.warp_forward);
2900 int frame_delay_value = (ffwd_delay ? FfwdFrameDelay : GameFrameDelay);
2901 int wait_delay_value = (no_delay ? 0 : frame_delay_value);
2902 int old_jx = player->jx;
2903 int old_jy = player->jy;
2904 int old_element = Feld[old_jx][old_jy];
2905 int element = Feld[jx][jy];
2906 boolean player_relocated = (old_jx != jx || old_jy != jy);
2908 int move_dir_horiz = (jx < old_jx ? MV_LEFT : jx > old_jx ? MV_RIGHT : 0);
2909 int move_dir_vert = (jy < old_jy ? MV_UP : jy > old_jy ? MV_DOWN : 0);
2911 int enter_side_horiz = MV_DIR_OPPOSITE(move_dir_horiz);
2912 int enter_side_vert = MV_DIR_OPPOSITE(move_dir_vert);
2913 int leave_side_horiz = move_dir_horiz;
2914 int leave_side_vert = move_dir_vert;
2916 static int trigger_sides[4][2] =
2918 /* enter side leave side */
2919 { CH_SIDE_RIGHT, CH_SIDE_LEFT }, /* moving left */
2920 { CH_SIDE_LEFT, CH_SIDE_RIGHT }, /* moving right */
2921 { CH_SIDE_BOTTOM, CH_SIDE_TOP }, /* moving up */
2922 { CH_SIDE_TOP, CH_SIDE_BOTTOM } /* moving down */
2924 int enter_side_horiz = trigger_sides[MV_DIR_BIT(move_dir_horiz)][0];
2925 int enter_side_vert = trigger_sides[MV_DIR_BIT(move_dir_vert)][0];
2926 int leave_side_horiz = trigger_sides[MV_DIR_BIT(move_dir_horiz)][1];
2927 int leave_side_vert = trigger_sides[MV_DIR_BIT(move_dir_vert)][1];
2929 int enter_side = enter_side_horiz | enter_side_vert;
2930 int leave_side = leave_side_horiz | leave_side_vert;
2932 if (player->GameOver) /* do not reanimate dead player */
2935 if (!player_relocated) /* no need to relocate the player */
2938 if (IS_PLAYER(jx, jy)) /* player already placed at new position */
2940 RemoveField(jx, jy); /* temporarily remove newly placed player */
2941 DrawLevelField(jx, jy);
2944 if (player->present)
2946 while (player->MovPos)
2948 ScrollPlayer(player, SCROLL_GO_ON);
2949 ScrollScreen(NULL, SCROLL_GO_ON);
2951 #if USE_NEW_MOVE_DELAY
2952 AdvanceFrameAndPlayerCounters(player->index_nr);
2960 Delay(wait_delay_value);
2963 DrawPlayer(player); /* needed here only to cleanup last field */
2964 DrawLevelField(player->jx, player->jy); /* remove player graphic */
2966 player->is_moving = FALSE;
2970 if (IS_CUSTOM_ELEMENT(old_element))
2971 CheckElementChangeByPlayer(old_jx, old_jy, old_element,
2973 player->index_bit, leave_side);
2975 CheckTriggeredElementChangeByPlayer(old_jx, old_jy, old_element,
2977 player->index_bit, leave_side);
2980 Feld[jx][jy] = el_player;
2981 InitPlayerField(jx, jy, el_player, TRUE);
2983 if (!ELEM_IS_PLAYER(element)) /* player may be set on walkable element */
2985 Feld[jx][jy] = element;
2986 InitField(jx, jy, FALSE);
2990 if (player == local_player) /* only visually relocate local player */
2991 DrawRelocatePlayer(player);
2995 TestIfHeroTouchesBadThing(jx, jy);
2996 TestIfPlayerTouchesCustomElement(jx, jy);
3000 printf("::: %d,%d: %d\n", jx, jy-1, Changed[jx][jy-1]);
3005 /* needed to allow change of walkable custom element by entering player */
3006 if (!(Changed[jx][jy] & CH_EVENT_BIT(CE_ENTERED_BY_PLAYER)))
3007 Changed[jx][jy] = 0; /* allow another change (but prevent loop) */
3009 /* needed to allow change of walkable custom element by entering player */
3010 Changed[jx][jy] = 0; /* allow another change */
3015 printf("::: player entering %d, %d from %s ...\n", jx, jy,
3016 enter_side == MV_LEFT ? "left" :
3017 enter_side == MV_RIGHT ? "right" :
3018 enter_side == MV_UP ? "top" :
3019 enter_side == MV_DOWN ? "bottom" : "oops! no idea!");
3023 if (IS_CUSTOM_ELEMENT(element))
3024 CheckElementChangeByPlayer(jx, jy, element, CE_ENTERED_BY_PLAYER,
3025 player->index_bit, enter_side);
3027 CheckTriggeredElementChangeByPlayer(jx, jy, element,
3028 CE_OTHER_GETS_ENTERED,
3029 player->index_bit, enter_side);
3033 void Explode(int ex, int ey, int phase, int mode)
3040 /* !!! eliminate this variable !!! */
3041 int delay = (game.emulation == EMU_SUPAPLEX ? 3 : 2);
3046 int last_phase = num_phase * delay;
3047 int half_phase = (num_phase / 2) * delay;
3048 int first_phase_after_start = EX_PHASE_START + 1;
3052 if (game.explosions_delayed)
3054 ExplodeField[ex][ey] = mode;
3058 if (phase == EX_PHASE_START) /* initialize 'Store[][]' field */
3060 int center_element = Feld[ex][ey];
3063 printf("::: start explosion %d,%d [%d]\n", ex, ey, FrameCounter);
3067 /* --- This is only really needed (and now handled) in "Impact()". --- */
3068 /* do not explode moving elements that left the explode field in time */
3069 if (game.engine_version >= VERSION_IDENT(2,2,0,7) &&
3070 center_element == EL_EMPTY &&
3071 (mode == EX_TYPE_NORMAL || mode == EX_TYPE_CENTER))
3075 if (mode == EX_TYPE_NORMAL || mode == EX_TYPE_CENTER)
3076 PlayLevelSoundAction(ex, ey, ACTION_EXPLODING);
3078 /* remove things displayed in background while burning dynamite */
3079 if (Back[ex][ey] != EL_EMPTY && !IS_INDESTRUCTIBLE(Back[ex][ey]))
3082 if (IS_MOVING(ex, ey) || IS_BLOCKED(ex, ey))
3084 /* put moving element to center field (and let it explode there) */
3085 center_element = MovingOrBlocked2Element(ex, ey);
3086 RemoveMovingField(ex, ey);
3087 Feld[ex][ey] = center_element;
3093 last_phase = element_info[center_element].explosion_delay + 1;
3095 last_phase = element_info[center_element].explosion_delay;
3099 printf("::: %d -> %d\n", center_element, last_phase);
3103 for (y = ey - 1; y <= ey + 1; y++) for (x = ex - 1; x <= ex + 1; x++)
3105 int xx = x - ex + 1;
3106 int yy = y - ey + 1;
3111 if (!IN_LEV_FIELD(x, y) ||
3112 (mode & EX_TYPE_SINGLE_TILE && (x != ex || y != ey)) ||
3113 (mode == EX_TYPE_CROSS && (x != ex && y != ey)))
3116 if (!IN_LEV_FIELD(x, y) ||
3117 (mode != EX_TYPE_NORMAL && (x != ex || y != ey)))
3121 if (!IN_LEV_FIELD(x, y) ||
3122 ((mode != EX_TYPE_NORMAL ||
3123 center_element == EL_AMOEBA_TO_DIAMOND) &&
3124 (x != ex || y != ey)))
3128 element = Feld[x][y];
3130 if (IS_MOVING(x, y) || IS_BLOCKED(x, y))
3132 element = MovingOrBlocked2Element(x, y);
3134 if (!IS_EXPLOSION_PROOF(element))
3135 RemoveMovingField(x, y);
3141 if (IS_EXPLOSION_PROOF(element))
3144 /* indestructible elements can only explode in center (but not flames) */
3146 if ((IS_EXPLOSION_PROOF(element) && (x != ex || y != ey ||
3147 mode == EX_TYPE_BORDER)) ||
3148 element == EL_FLAMES)
3151 if ((IS_EXPLOSION_PROOF(element) && (x != ex || y != ey)) ||
3152 element == EL_FLAMES)
3158 if ((IS_INDESTRUCTIBLE(element) &&
3159 (game.engine_version < VERSION_IDENT(2,2,0,0) ||
3160 (!IS_WALKABLE_OVER(element) && !IS_WALKABLE_UNDER(element)))) ||
3161 element == EL_FLAMES)
3166 if (IS_PLAYER(x, y) && SHIELD_ON(PLAYERINFO(x, y)) &&
3167 (game.engine_version < VERSION_IDENT(3,1,0,0) ||
3168 (x == ex && y == ey && mode != EX_TYPE_BORDER)))
3170 if (IS_PLAYER(x, y) && SHIELD_ON(PLAYERINFO(x, y)))
3173 if (IS_ACTIVE_BOMB(element))
3175 /* re-activate things under the bomb like gate or penguin */
3177 Feld[x][y] = (Back[x][y] ? Back[x][y] : EL_EMPTY);
3180 Feld[x][y] = (Store[x][y] ? Store[x][y] : EL_EMPTY);
3185 printf("::: %d,%d: %d %s [%d, %d]\n", x, y, Feld[x][y],
3186 element_info[Feld[x][y]].token_name,
3187 Store[x][y], Store2[x][y]);
3194 /* save walkable background elements while explosion on same tile */
3196 if (IS_INDESTRUCTIBLE(element))
3197 Back[x][y] = element;
3201 if (IS_WALKABLE(element) && IS_INDESTRUCTIBLE(element) &&
3202 (x != ex || y != ey || mode == EX_TYPE_BORDER))
3203 Back[x][y] = element;
3205 if (IS_WALKABLE(element) && IS_INDESTRUCTIBLE(element) &&
3206 (x != ex || y != ey))
3207 Back[x][y] = element;
3210 if (IS_WALKABLE(element) && IS_INDESTRUCTIBLE(element))
3211 Back[x][y] = element;
3215 /* ignite explodable elements reached by other explosion */
3216 if (element == EL_EXPLOSION)
3217 element = Store2[x][y];
3220 if (AmoebaNr[x][y] &&
3221 (element == EL_AMOEBA_FULL ||
3222 element == EL_BD_AMOEBA ||
3223 element == EL_AMOEBA_GROWING))
3225 AmoebaCnt[AmoebaNr[x][y]]--;
3226 AmoebaCnt2[AmoebaNr[x][y]]--;
3232 if (IS_PLAYER(ex, ey) && !PLAYER_EXPLOSION_PROTECTED(ex, ey))
3234 switch(StorePlayer[ex][ey])
3237 Store[x][y] = EL_PLAYER_IS_EXPLODING_2;
3240 Store[x][y] = EL_PLAYER_IS_EXPLODING_3;
3243 Store[x][y] = EL_PLAYER_IS_EXPLODING_4;
3247 Store[x][y] = EL_PLAYER_IS_EXPLODING_1;
3252 if (PLAYERINFO(ex, ey)->use_murphy_graphic)
3253 Store[x][y] = EL_EMPTY;
3255 if (game.emulation == EMU_SUPAPLEX)
3256 Store[x][y] = EL_EMPTY;
3259 else if (center_element == EL_MOLE)
3260 Store[x][y] = EL_EMERALD_RED;
3261 else if (center_element == EL_PENGUIN)
3262 Store[x][y] = EL_EMERALD_PURPLE;
3263 else if (center_element == EL_BUG)
3264 Store[x][y] = ((x == ex && y == ey) ? EL_DIAMOND : EL_EMERALD);
3265 else if (center_element == EL_BD_BUTTERFLY)
3266 Store[x][y] = EL_BD_DIAMOND;
3267 else if (center_element == EL_SP_ELECTRON)
3268 Store[x][y] = EL_SP_INFOTRON;
3269 else if (center_element == EL_AMOEBA_TO_DIAMOND)
3270 Store[x][y] = level.amoeba_content;
3271 else if (center_element == EL_YAMYAM)
3272 Store[x][y] = level.yamyam_content[game.yamyam_content_nr][xx][yy];
3273 else if (IS_CUSTOM_ELEMENT(center_element) &&
3274 element_info[center_element].content[xx][yy] != EL_EMPTY)
3275 Store[x][y] = element_info[center_element].content[xx][yy];
3276 else if (element == EL_WALL_EMERALD)
3277 Store[x][y] = EL_EMERALD;
3278 else if (element == EL_WALL_DIAMOND)
3279 Store[x][y] = EL_DIAMOND;
3280 else if (element == EL_WALL_BD_DIAMOND)
3281 Store[x][y] = EL_BD_DIAMOND;
3282 else if (element == EL_WALL_EMERALD_YELLOW)
3283 Store[x][y] = EL_EMERALD_YELLOW;
3284 else if (element == EL_WALL_EMERALD_RED)
3285 Store[x][y] = EL_EMERALD_RED;
3286 else if (element == EL_WALL_EMERALD_PURPLE)
3287 Store[x][y] = EL_EMERALD_PURPLE;
3288 else if (element == EL_WALL_PEARL)
3289 Store[x][y] = EL_PEARL;
3290 else if (element == EL_WALL_CRYSTAL)
3291 Store[x][y] = EL_CRYSTAL;
3292 else if (IS_CUSTOM_ELEMENT(element) && !CAN_EXPLODE(element))
3293 Store[x][y] = element_info[element].content[1][1];
3295 Store[x][y] = EL_EMPTY;
3297 if (x != ex || y != ey || mode == EX_TYPE_BORDER ||
3298 center_element == EL_AMOEBA_TO_DIAMOND)
3299 Store2[x][y] = element;
3302 printf("::: %d,%d: %d %s\n", x, y, Store2[x][y],
3303 element_info[Store2[x][y]].token_name);
3307 if (AmoebaNr[x][y] &&
3308 (element == EL_AMOEBA_FULL ||
3309 element == EL_BD_AMOEBA ||
3310 element == EL_AMOEBA_GROWING))
3312 AmoebaCnt[AmoebaNr[x][y]]--;
3313 AmoebaCnt2[AmoebaNr[x][y]]--;
3319 MovDir[x][y] = MovPos[x][y] = 0;
3320 GfxDir[x][y] = MovDir[x][y];
3325 Feld[x][y] = EL_EXPLOSION;
3327 GfxElement[x][y] = center_element;
3329 GfxElement[x][y] = EL_UNDEFINED;
3332 ExplodePhase[x][y] = 1;
3334 ExplodeDelay[x][y] = last_phase;
3339 GfxFrame[x][y] = 0; /* animation does not start until next frame */
3341 GfxFrame[x][y] = -1; /* animation does not start until next frame */
3348 if (center_element == EL_YAMYAM)
3349 game.yamyam_content_nr =
3350 (game.yamyam_content_nr + 1) % level.num_yamyam_contents;
3353 printf("::: %d,%d: %d %s [%d]\n", ex + 1, ey, Feld[ex + 1][ey],
3354 element_info[Feld[ex + 1][ey]].token_name, Store2[ex + 1][ey]);
3368 GfxFrame[x][y] = 0; /* restart explosion animation */
3372 printf(":X: phase == %d [%d]\n", phase, GfxFrame[x][y]);
3376 last_phase = ExplodeDelay[x][y];
3379 ExplodePhase[x][y] = (phase < last_phase ? phase + 1 : 0);
3383 /* activate this even in non-DEBUG version until cause for crash in
3384 getGraphicAnimationFrame() (see below) is found and eliminated */
3388 if (GfxElement[x][y] == EL_UNDEFINED)
3391 printf("Explode(): x = %d, y = %d: GfxElement == EL_UNDEFINED\n", x, y);
3392 printf("Explode(): This should never happen!\n");
3395 GfxElement[x][y] = EL_EMPTY;
3401 border_element = Store2[x][y];
3403 if (IS_PLAYER(x, y) && !PLAYER_EXPLOSION_PROTECTED(x, y))
3404 border_element = StorePlayer[x][y];
3406 if (IS_PLAYER(x, y))
3407 border_element = StorePlayer[x][y];
3411 printf("::: %d,%d: %d %s [%d]\n", x, y, border_element,
3412 element_info[border_element].token_name, Store2[x][y]);
3416 printf("::: phase == %d\n", phase);
3419 if (phase == element_info[border_element].ignition_delay ||
3420 phase == last_phase)
3422 boolean border_explosion = FALSE;
3426 if (IS_PLAYER(x, y) && PLAYERINFO(x, y)->present &&
3427 !PLAYER_EXPLOSION_PROTECTED(x, y))
3429 if (IS_PLAYER(x, y) && PLAYERINFO(x, y)->present)
3432 if (IS_PLAYER(x, y))
3435 KillHeroUnlessExplosionProtected(x, y);
3436 border_explosion = TRUE;
3439 if (phase == last_phase)
3440 printf("::: IS_PLAYER\n");
3443 else if (CAN_EXPLODE_BY_EXPLOSION(border_element))
3446 printf("::: %d,%d: %d %s\n", x, y, border_element,
3447 element_info[border_element].token_name);
3450 Feld[x][y] = Store2[x][y];
3453 border_explosion = TRUE;
3456 if (phase == last_phase)
3457 printf("::: CAN_EXPLODE_BY_EXPLOSION\n");
3460 else if (border_element == EL_AMOEBA_TO_DIAMOND)
3462 AmoebeUmwandeln(x, y);
3464 border_explosion = TRUE;
3467 if (phase == last_phase)
3468 printf("::: EL_AMOEBA_TO_DIAMOND [%d, %d] [%d]\n",
3469 element_info[border_element].explosion_delay,
3470 element_info[border_element].ignition_delay,
3476 /* if an element just explodes due to another explosion (chain-reaction),
3477 do not immediately end the new explosion when it was the last frame of
3478 the explosion (as it would be done in the following "if"-statement!) */
3479 if (border_explosion && phase == last_phase)
3486 if (phase == first_phase_after_start)
3488 int element = Store2[x][y];
3490 if (element == EL_BLACK_ORB)
3492 Feld[x][y] = Store2[x][y];
3497 else if (phase == half_phase)
3499 int element = Store2[x][y];
3501 if (IS_PLAYER(x, y))
3502 KillHeroUnlessExplosionProtected(x, y);
3503 else if (CAN_EXPLODE_BY_EXPLOSION(element))
3505 Feld[x][y] = Store2[x][y];
3509 else if (element == EL_AMOEBA_TO_DIAMOND)
3510 AmoebeUmwandeln(x, y);
3514 if (phase == last_phase)
3519 printf("::: done: phase == %d\n", phase);
3523 printf("::: explosion %d,%d done [%d]\n", x, y, FrameCounter);
3526 element = Feld[x][y] = Store[x][y];
3527 Store[x][y] = Store2[x][y] = 0;
3528 GfxElement[x][y] = EL_UNDEFINED;
3530 /* player can escape from explosions and might therefore be still alive */
3531 if (element >= EL_PLAYER_IS_EXPLODING_1 &&
3532 element <= EL_PLAYER_IS_EXPLODING_4)
3533 Feld[x][y] = (stored_player[element - EL_PLAYER_IS_EXPLODING_1].active ?
3535 element == EL_PLAYER_IS_EXPLODING_1 ? EL_EMERALD_YELLOW :
3536 element == EL_PLAYER_IS_EXPLODING_2 ? EL_EMERALD_RED :
3537 element == EL_PLAYER_IS_EXPLODING_3 ? EL_EMERALD :
3540 /* restore probably existing indestructible background element */
3541 if (Back[x][y] && IS_INDESTRUCTIBLE(Back[x][y]))
3542 element = Feld[x][y] = Back[x][y];
3545 MovDir[x][y] = MovPos[x][y] = MovDelay[x][y] = 0;
3546 GfxDir[x][y] = MV_NO_MOVING;
3547 ChangeDelay[x][y] = 0;
3548 ChangePage[x][y] = -1;
3551 InitField_WithBug2(x, y, FALSE);
3553 InitField(x, y, FALSE);
3555 /* !!! not needed !!! */
3557 if (game.engine_version < VERSION_IDENT(3,1,0,0) &&
3558 CAN_MOVE(Feld[x][y]) && Feld[x][y] != EL_MOLE)
3561 if (CAN_MOVE(element))
3566 DrawLevelField(x, y);
3568 TestIfElementTouchesCustomElement(x, y);
3570 if (GFX_CRUMBLED(element))
3571 DrawLevelFieldCrumbledSandNeighbours(x, y);
3573 if (IS_PLAYER(x, y) && !PLAYERINFO(x, y)->present)
3574 StorePlayer[x][y] = 0;
3576 if (ELEM_IS_PLAYER(element))
3577 RelocatePlayer(x, y, element);
3580 else if (IN_SCR_FIELD(SCREENX(x), SCREENY(y)))
3582 else if (phase >= delay && IN_SCR_FIELD(SCREENX(x), SCREENY(y)))
3586 int graphic = el_act2img(GfxElement[x][y], ACTION_EXPLODING);
3588 int stored = Store[x][y];
3589 int graphic = (game.emulation != EMU_SUPAPLEX ? IMG_EXPLOSION :
3590 stored == EL_SP_INFOTRON ? IMG_SP_EXPLOSION_INFOTRON :
3594 int frame = getGraphicAnimationFrame(graphic, GfxFrame[x][y]);
3596 int frame = getGraphicAnimationFrame(graphic, phase - delay);
3600 printf("::: phase == %d [%d]\n", phase, GfxFrame[x][y]);
3604 printf("::: %d / %d [%d - %d]\n",
3605 GfxFrame[x][y], phase - delay, phase, delay);
3609 printf("::: %d ['%s'] -> %d\n", GfxElement[x][y],
3610 element_info[GfxElement[x][y]].token_name,
3615 DrawLevelFieldCrumbledSand(x, y);
3617 if (IS_WALKABLE_OVER(Back[x][y]) && Back[x][y] != EL_EMPTY)
3619 DrawLevelElement(x, y, Back[x][y]);
3620 DrawGraphicThruMask(SCREENX(x), SCREENY(y), graphic, frame);
3622 else if (IS_WALKABLE_UNDER(Back[x][y]))
3624 DrawGraphic(SCREENX(x), SCREENY(y), graphic, frame);
3625 DrawLevelElementThruMask(x, y, Back[x][y]);
3627 else if (!IS_WALKABLE_INSIDE(Back[x][y]))
3628 DrawGraphic(SCREENX(x), SCREENY(y), graphic, frame);
3632 void DynaExplode(int ex, int ey)
3635 int dynabomb_element = Feld[ex][ey];
3636 int dynabomb_size = 1;
3637 boolean dynabomb_xl = FALSE;
3638 struct PlayerInfo *player;
3639 static int xy[4][2] =
3647 if (IS_ACTIVE_BOMB(dynabomb_element))
3649 player = &stored_player[dynabomb_element - EL_DYNABOMB_PLAYER_1_ACTIVE];
3650 dynabomb_size = player->dynabomb_size;
3651 dynabomb_xl = player->dynabomb_xl;
3652 player->dynabombs_left++;
3655 Explode(ex, ey, EX_PHASE_START, EX_TYPE_CENTER);
3657 for (i = 0; i < NUM_DIRECTIONS; i++)
3659 for (j = 1; j <= dynabomb_size; j++)
3661 int x = ex + j * xy[i][0];
3662 int y = ey + j * xy[i][1];
3665 if (!IN_LEV_FIELD(x, y) || IS_INDESTRUCTIBLE(Feld[x][y]))
3668 element = Feld[x][y];
3670 /* do not restart explosions of fields with active bombs */
3671 if (element == EL_EXPLOSION && IS_ACTIVE_BOMB(Store2[x][y]))
3674 Explode(x, y, EX_PHASE_START, EX_TYPE_BORDER);
3678 if (element != EL_EMPTY && element != EL_EXPLOSION &&
3679 !IS_DIGGABLE(element) && !dynabomb_xl)
3682 if (element != EL_EMPTY && element != EL_EXPLOSION &&
3683 !CAN_GROW_INTO(element) && !dynabomb_xl)
3687 /* !!! extend EL_SAND to anything diggable (but maybe not SP_BASE) !!! */
3688 if (element != EL_EMPTY && element != EL_EXPLOSION &&
3689 element != EL_SAND && !dynabomb_xl)
3696 void Bang(int x, int y)
3699 int element = MovingOrBlocked2Element(x, y);
3701 int element = Feld[x][y];
3705 if (IS_PLAYER(x, y) && !PLAYER_EXPLOSION_PROTECTED(x, y))
3707 if (IS_PLAYER(x, y))
3710 struct PlayerInfo *player = PLAYERINFO(x, y);
3712 element = Feld[x][y] = (player->use_murphy_graphic ? EL_SP_MURPHY :
3713 player->element_nr);
3718 PlayLevelSoundAction(x, y, ACTION_EXPLODING);
3720 if (game.emulation == EMU_SUPAPLEX)
3721 PlayLevelSound(x, y, SND_SP_ELEMENT_EXPLODING);
3723 PlayLevelSound(x, y, SND_ELEMENT_EXPLODING);
3728 if (IS_PLAYER(x, y)) /* remove objects that might cause smaller explosion */
3736 case EL_BD_BUTTERFLY:
3739 case EL_DARK_YAMYAM:
3743 RaiseScoreElement(element);
3744 Explode(x, y, EX_PHASE_START, EX_TYPE_NORMAL);
3746 case EL_DYNABOMB_PLAYER_1_ACTIVE:
3747 case EL_DYNABOMB_PLAYER_2_ACTIVE:
3748 case EL_DYNABOMB_PLAYER_3_ACTIVE:
3749 case EL_DYNABOMB_PLAYER_4_ACTIVE:
3750 case EL_DYNABOMB_INCREASE_NUMBER:
3751 case EL_DYNABOMB_INCREASE_SIZE:
3752 case EL_DYNABOMB_INCREASE_POWER:
3757 case EL_LAMP_ACTIVE:
3759 case EL_AMOEBA_TO_DIAMOND:
3761 if (IS_PLAYER(x, y))
3762 Explode(x, y, EX_PHASE_START, EX_TYPE_NORMAL);
3764 Explode(x, y, EX_PHASE_START, EX_TYPE_CENTER);
3768 if (element_info[element].explosion_type == EXPLODES_CROSS)
3770 if (CAN_EXPLODE_CROSS(element))
3773 Explode(x, y, EX_PHASE_START, EX_TYPE_CROSS);
3778 else if (element_info[element].explosion_type == EXPLODES_1X1)
3780 else if (CAN_EXPLODE_1X1(element))
3782 Explode(x, y, EX_PHASE_START, EX_TYPE_CENTER);
3784 Explode(x, y, EX_PHASE_START, EX_TYPE_NORMAL);
3788 CheckTriggeredElementChange(x, y, element, CE_OTHER_IS_EXPLODING);
3791 void SplashAcid(int x, int y)
3794 if (IN_LEV_FIELD(x - 1, y - 1) && IS_FREE(x - 1, y - 1) &&
3795 (!IN_LEV_FIELD(x - 1, y - 2) ||
3796 !CAN_FALL(MovingOrBlocked2Element(x - 1, y - 2))))
3797 Feld[x - 1][y - 1] = EL_ACID_SPLASH_LEFT;
3799 if (IN_LEV_FIELD(x + 1, y - 1) && IS_FREE(x + 1, y - 1) &&
3800 (!IN_LEV_FIELD(x + 1, y - 2) ||
3801 !CAN_FALL(MovingOrBlocked2Element(x + 1, y - 2))))
3802 Feld[x + 1][y - 1] = EL_ACID_SPLASH_RIGHT;
3804 PlayLevelSound(x, y, SND_ACID_SPLASHING);
3806 /* input: position of element entering acid (obsolete) */
3808 int element = Feld[x][y];
3810 if (!IN_LEV_FIELD(x, y + 1) || Feld[x][y + 1] != EL_ACID)
3813 if (element != EL_ACID_SPLASH_LEFT &&
3814 element != EL_ACID_SPLASH_RIGHT)
3816 PlayLevelSound(x, y, SND_ACID_SPLASHING);
3818 if (IN_LEV_FIELD(x - 1, y) && IS_FREE(x - 1, y) &&
3819 (!IN_LEV_FIELD(x - 1, y - 1) ||
3820 !CAN_FALL(MovingOrBlocked2Element(x - 1, y - 1))))
3821 Feld[x - 1][y] = EL_ACID_SPLASH_LEFT;
3823 if (IN_LEV_FIELD(x + 1, y) && IS_FREE(x + 1, y) &&
3824 (!IN_LEV_FIELD(x + 1, y - 1) ||
3825 !CAN_FALL(MovingOrBlocked2Element(x + 1, y - 1))))
3826 Feld[x + 1][y] = EL_ACID_SPLASH_RIGHT;
3831 static void InitBeltMovement()
3833 static int belt_base_element[4] =
3835 EL_CONVEYOR_BELT_1_LEFT,
3836 EL_CONVEYOR_BELT_2_LEFT,
3837 EL_CONVEYOR_BELT_3_LEFT,
3838 EL_CONVEYOR_BELT_4_LEFT
3840 static int belt_base_active_element[4] =
3842 EL_CONVEYOR_BELT_1_LEFT_ACTIVE,
3843 EL_CONVEYOR_BELT_2_LEFT_ACTIVE,
3844 EL_CONVEYOR_BELT_3_LEFT_ACTIVE,
3845 EL_CONVEYOR_BELT_4_LEFT_ACTIVE
3850 /* set frame order for belt animation graphic according to belt direction */
3851 for (i = 0; i < NUM_BELTS; i++)
3855 for (j = 0; j < NUM_BELT_PARTS; j++)
3857 int element = belt_base_active_element[belt_nr] + j;
3858 int graphic = el2img(element);
3860 if (game.belt_dir[i] == MV_LEFT)
3861 graphic_info[graphic].anim_mode &= ~ANIM_REVERSE;
3863 graphic_info[graphic].anim_mode |= ANIM_REVERSE;
3867 for (y = 0; y < lev_fieldy; y++)
3869 for (x = 0; x < lev_fieldx; x++)
3871 int element = Feld[x][y];
3873 for (i = 0; i < NUM_BELTS; i++)
3875 if (IS_BELT(element) && game.belt_dir[i] != MV_NO_MOVING)
3877 int e_belt_nr = getBeltNrFromBeltElement(element);
3880 if (e_belt_nr == belt_nr)
3882 int belt_part = Feld[x][y] - belt_base_element[belt_nr];
3884 Feld[x][y] = belt_base_active_element[belt_nr] + belt_part;
3892 static void ToggleBeltSwitch(int x, int y)
3894 static int belt_base_element[4] =
3896 EL_CONVEYOR_BELT_1_LEFT,
3897 EL_CONVEYOR_BELT_2_LEFT,
3898 EL_CONVEYOR_BELT_3_LEFT,
3899 EL_CONVEYOR_BELT_4_LEFT
3901 static int belt_base_active_element[4] =
3903 EL_CONVEYOR_BELT_1_LEFT_ACTIVE,
3904 EL_CONVEYOR_BELT_2_LEFT_ACTIVE,
3905 EL_CONVEYOR_BELT_3_LEFT_ACTIVE,
3906 EL_CONVEYOR_BELT_4_LEFT_ACTIVE
3908 static int belt_base_switch_element[4] =
3910 EL_CONVEYOR_BELT_1_SWITCH_LEFT,
3911 EL_CONVEYOR_BELT_2_SWITCH_LEFT,
3912 EL_CONVEYOR_BELT_3_SWITCH_LEFT,
3913 EL_CONVEYOR_BELT_4_SWITCH_LEFT
3915 static int belt_move_dir[4] =
3923 int element = Feld[x][y];
3924 int belt_nr = getBeltNrFromBeltSwitchElement(element);
3925 int belt_dir_nr = (game.belt_dir_nr[belt_nr] + 1) % 4;
3926 int belt_dir = belt_move_dir[belt_dir_nr];
3929 if (!IS_BELT_SWITCH(element))
3932 game.belt_dir_nr[belt_nr] = belt_dir_nr;
3933 game.belt_dir[belt_nr] = belt_dir;
3935 if (belt_dir_nr == 3)
3938 /* set frame order for belt animation graphic according to belt direction */
3939 for (i = 0; i < NUM_BELT_PARTS; i++)
3941 int element = belt_base_active_element[belt_nr] + i;
3942 int graphic = el2img(element);
3944 if (belt_dir == MV_LEFT)
3945 graphic_info[graphic].anim_mode &= ~ANIM_REVERSE;
3947 graphic_info[graphic].anim_mode |= ANIM_REVERSE;
3950 for (yy = 0; yy < lev_fieldy; yy++)
3952 for (xx = 0; xx < lev_fieldx; xx++)
3954 int element = Feld[xx][yy];
3956 if (IS_BELT_SWITCH(element))
3958 int e_belt_nr = getBeltNrFromBeltSwitchElement(element);
3960 if (e_belt_nr == belt_nr)
3962 Feld[xx][yy] = belt_base_switch_element[belt_nr] + belt_dir_nr;
3963 DrawLevelField(xx, yy);
3966 else if (IS_BELT(element) && belt_dir != MV_NO_MOVING)
3968 int e_belt_nr = getBeltNrFromBeltElement(element);
3970 if (e_belt_nr == belt_nr)
3972 int belt_part = Feld[xx][yy] - belt_base_element[belt_nr];
3974 Feld[xx][yy] = belt_base_active_element[belt_nr] + belt_part;
3975 DrawLevelField(xx, yy);
3978 else if (IS_BELT_ACTIVE(element) && belt_dir == MV_NO_MOVING)
3980 int e_belt_nr = getBeltNrFromBeltActiveElement(element);
3982 if (e_belt_nr == belt_nr)
3984 int belt_part = Feld[xx][yy] - belt_base_active_element[belt_nr];
3986 Feld[xx][yy] = belt_base_element[belt_nr] + belt_part;
3987 DrawLevelField(xx, yy);
3994 static void ToggleSwitchgateSwitch(int x, int y)
3998 game.switchgate_pos = !game.switchgate_pos;
4000 for (yy = 0; yy < lev_fieldy; yy++)
4002 for (xx = 0; xx < lev_fieldx; xx++)
4004 int element = Feld[xx][yy];
4006 if (element == EL_SWITCHGATE_SWITCH_UP ||
4007 element == EL_SWITCHGATE_SWITCH_DOWN)
4009 Feld[xx][yy] = EL_SWITCHGATE_SWITCH_UP + game.switchgate_pos;
4010 DrawLevelField(xx, yy);
4012 else if (element == EL_SWITCHGATE_OPEN ||
4013 element == EL_SWITCHGATE_OPENING)
4015 Feld[xx][yy] = EL_SWITCHGATE_CLOSING;
4017 PlayLevelSoundAction(xx, yy, ACTION_CLOSING);
4019 PlayLevelSound(xx, yy, SND_SWITCHGATE_CLOSING);
4022 else if (element == EL_SWITCHGATE_CLOSED ||
4023 element == EL_SWITCHGATE_CLOSING)
4025 Feld[xx][yy] = EL_SWITCHGATE_OPENING;
4027 PlayLevelSoundAction(xx, yy, ACTION_OPENING);
4029 PlayLevelSound(xx, yy, SND_SWITCHGATE_OPENING);
4036 static int getInvisibleActiveFromInvisibleElement(int element)
4038 return (element == EL_INVISIBLE_STEELWALL ? EL_INVISIBLE_STEELWALL_ACTIVE :
4039 element == EL_INVISIBLE_WALL ? EL_INVISIBLE_WALL_ACTIVE :
4040 element == EL_INVISIBLE_SAND ? EL_INVISIBLE_SAND_ACTIVE :
4044 static int getInvisibleFromInvisibleActiveElement(int element)
4046 return (element == EL_INVISIBLE_STEELWALL_ACTIVE ? EL_INVISIBLE_STEELWALL :
4047 element == EL_INVISIBLE_WALL_ACTIVE ? EL_INVISIBLE_WALL :
4048 element == EL_INVISIBLE_SAND_ACTIVE ? EL_INVISIBLE_SAND :
4052 static void RedrawAllLightSwitchesAndInvisibleElements()
4056 for (y = 0; y < lev_fieldy; y++)
4058 for (x = 0; x < lev_fieldx; x++)
4060 int element = Feld[x][y];
4062 if (element == EL_LIGHT_SWITCH &&
4063 game.light_time_left > 0)
4065 Feld[x][y] = EL_LIGHT_SWITCH_ACTIVE;
4066 DrawLevelField(x, y);
4068 else if (element == EL_LIGHT_SWITCH_ACTIVE &&
4069 game.light_time_left == 0)
4071 Feld[x][y] = EL_LIGHT_SWITCH;
4072 DrawLevelField(x, y);
4074 else if (element == EL_INVISIBLE_STEELWALL ||
4075 element == EL_INVISIBLE_WALL ||
4076 element == EL_INVISIBLE_SAND)
4078 if (game.light_time_left > 0)
4079 Feld[x][y] = getInvisibleActiveFromInvisibleElement(element);
4081 DrawLevelField(x, y);
4083 else if (element == EL_INVISIBLE_STEELWALL_ACTIVE ||
4084 element == EL_INVISIBLE_WALL_ACTIVE ||
4085 element == EL_INVISIBLE_SAND_ACTIVE)
4087 if (game.light_time_left == 0)
4088 Feld[x][y] = getInvisibleFromInvisibleActiveElement(element);
4090 DrawLevelField(x, y);
4096 static void ToggleLightSwitch(int x, int y)
4098 int element = Feld[x][y];
4100 game.light_time_left =
4101 (element == EL_LIGHT_SWITCH ?
4102 level.time_light * FRAMES_PER_SECOND : 0);
4104 RedrawAllLightSwitchesAndInvisibleElements();
4107 static void ActivateTimegateSwitch(int x, int y)
4111 game.timegate_time_left = level.time_timegate * FRAMES_PER_SECOND;
4113 for (yy = 0; yy < lev_fieldy; yy++)
4115 for (xx = 0; xx < lev_fieldx; xx++)
4117 int element = Feld[xx][yy];
4119 if (element == EL_TIMEGATE_CLOSED ||
4120 element == EL_TIMEGATE_CLOSING)
4122 Feld[xx][yy] = EL_TIMEGATE_OPENING;
4123 PlayLevelSound(xx, yy, SND_TIMEGATE_OPENING);
4127 else if (element == EL_TIMEGATE_SWITCH_ACTIVE)
4129 Feld[xx][yy] = EL_TIMEGATE_SWITCH;
4130 DrawLevelField(xx, yy);
4137 Feld[x][y] = EL_TIMEGATE_SWITCH_ACTIVE;
4140 inline static int getElementMoveStepsize(int x, int y)
4142 int element = Feld[x][y];
4143 int direction = MovDir[x][y];
4144 int dx = (direction == MV_LEFT ? -1 : direction == MV_RIGHT ? +1 : 0);
4145 int dy = (direction == MV_UP ? -1 : direction == MV_DOWN ? +1 : 0);
4146 int horiz_move = (dx != 0);
4147 int sign = (horiz_move ? dx : dy);
4148 int step = sign * element_info[element].move_stepsize;
4150 /* special values for move stepsize for spring and things on conveyor belt */
4154 if (element == EL_SPRING)
4155 step = sign * MOVE_STEPSIZE_NORMAL * 2;
4156 else if (CAN_FALL(element) && !CAN_MOVE(element) &&
4157 y < lev_fieldy - 1 && IS_BELT_ACTIVE(Feld[x][y + 1]))
4158 step = sign * MOVE_STEPSIZE_NORMAL / 2;
4160 if (CAN_FALL(element) &&
4161 y < lev_fieldy - 1 && IS_BELT_ACTIVE(Feld[x][y + 1]))
4162 step = sign * MOVE_STEPSIZE_NORMAL / 2;
4163 else if (element == EL_SPRING)
4164 step = sign * MOVE_STEPSIZE_NORMAL * 2;
4171 void Impact(int x, int y)
4173 boolean lastline = (y == lev_fieldy-1);
4174 boolean object_hit = FALSE;
4175 boolean impact = (lastline || object_hit);
4176 int element = Feld[x][y];
4177 int smashed = EL_STEELWALL;
4179 if (!lastline) /* check if element below was hit */
4181 if (Feld[x][y + 1] == EL_PLAYER_IS_LEAVING)
4184 object_hit = (!IS_FREE(x, y + 1) && (!IS_MOVING(x, y + 1) ||
4185 MovDir[x][y + 1] != MV_DOWN ||
4186 MovPos[x][y + 1] <= TILEY / 2));
4189 object_hit = !IS_FREE(x, y + 1);
4192 /* do not smash moving elements that left the smashed field in time */
4193 if (game.engine_version >= VERSION_IDENT(2,2,0,7) && IS_MOVING(x, y + 1) &&
4194 ABS(MovPos[x][y + 1] + getElementMoveStepsize(x, y + 1)) >= TILEX)
4198 smashed = MovingOrBlocked2Element(x, y + 1);
4200 impact = (lastline || object_hit);
4203 if (!lastline && smashed == EL_ACID) /* element falls into acid */
4205 SplashAcid(x, y + 1);
4209 /* !!! not sufficient for all cases -- see EL_PEARL below !!! */
4210 /* only reset graphic animation if graphic really changes after impact */
4212 el_act_dir2img(element, GfxAction[x][y], MV_DOWN) != el2img(element))
4214 ResetGfxAnimation(x, y);
4215 DrawLevelField(x, y);
4218 if (impact && CAN_EXPLODE_IMPACT(element))
4223 else if (impact && element == EL_PEARL)
4225 ResetGfxAnimation(x, y);
4227 Feld[x][y] = EL_PEARL_BREAKING;
4228 PlayLevelSound(x, y, SND_PEARL_BREAKING);
4231 else if (impact && CheckElementChange(x, y, element, smashed, CE_IMPACT))
4233 PlayLevelSoundElementAction(x, y, element, ACTION_IMPACT);
4238 if (impact && element == EL_AMOEBA_DROP)
4240 if (object_hit && IS_PLAYER(x, y + 1))
4241 KillHeroUnlessEnemyProtected(x, y + 1);
4242 else if (object_hit && smashed == EL_PENGUIN)
4246 Feld[x][y] = EL_AMOEBA_GROWING;
4247 Store[x][y] = EL_AMOEBA_WET;
4249 ResetRandomAnimationValue(x, y);
4254 if (object_hit) /* check which object was hit */
4256 if (CAN_PASS_MAGIC_WALL(element) &&
4257 (smashed == EL_MAGIC_WALL ||
4258 smashed == EL_BD_MAGIC_WALL))
4261 int activated_magic_wall =
4262 (smashed == EL_MAGIC_WALL ? EL_MAGIC_WALL_ACTIVE :
4263 EL_BD_MAGIC_WALL_ACTIVE);
4265 /* activate magic wall / mill */
4266 for (yy = 0; yy < lev_fieldy; yy++)
4267 for (xx = 0; xx < lev_fieldx; xx++)
4268 if (Feld[xx][yy] == smashed)
4269 Feld[xx][yy] = activated_magic_wall;
4271 game.magic_wall_time_left = level.time_magic_wall * FRAMES_PER_SECOND;
4272 game.magic_wall_active = TRUE;
4274 PlayLevelSound(x, y, (smashed == EL_MAGIC_WALL ?
4275 SND_MAGIC_WALL_ACTIVATING :
4276 SND_BD_MAGIC_WALL_ACTIVATING));
4279 if (IS_PLAYER(x, y + 1))
4281 if (CAN_SMASH_PLAYER(element))
4283 KillHeroUnlessEnemyProtected(x, y + 1);
4287 else if (smashed == EL_PENGUIN)
4289 if (CAN_SMASH_PLAYER(element))
4295 else if (element == EL_BD_DIAMOND)
4297 if (IS_CLASSIC_ENEMY(smashed) && IS_BD_ELEMENT(smashed))
4303 else if (((element == EL_SP_INFOTRON ||
4304 element == EL_SP_ZONK) &&
4305 (smashed == EL_SP_SNIKSNAK ||
4306 smashed == EL_SP_ELECTRON ||
4307 smashed == EL_SP_DISK_ORANGE)) ||
4308 (element == EL_SP_INFOTRON &&
4309 smashed == EL_SP_DISK_YELLOW))
4315 else if (CAN_SMASH_ENEMIES(element) && IS_CLASSIC_ENEMY(smashed))
4321 else if (CAN_SMASH_EVERYTHING(element))
4323 if (IS_CLASSIC_ENEMY(smashed) ||
4324 CAN_EXPLODE_SMASHED(smashed))
4329 else if (!IS_MOVING(x, y + 1) && !IS_BLOCKED(x, y + 1))
4331 if (smashed == EL_LAMP ||
4332 smashed == EL_LAMP_ACTIVE)
4337 else if (smashed == EL_NUT)
4339 Feld[x][y + 1] = EL_NUT_BREAKING;
4340 PlayLevelSound(x, y, SND_NUT_BREAKING);
4341 RaiseScoreElement(EL_NUT);
4344 else if (smashed == EL_PEARL)
4346 ResetGfxAnimation(x, y);
4348 Feld[x][y + 1] = EL_PEARL_BREAKING;
4349 PlayLevelSound(x, y, SND_PEARL_BREAKING);
4352 else if (smashed == EL_DIAMOND)
4354 Feld[x][y + 1] = EL_DIAMOND_BREAKING;
4355 PlayLevelSound(x, y, SND_DIAMOND_BREAKING);
4358 else if (IS_BELT_SWITCH(smashed))
4360 ToggleBeltSwitch(x, y + 1);
4362 else if (smashed == EL_SWITCHGATE_SWITCH_UP ||
4363 smashed == EL_SWITCHGATE_SWITCH_DOWN)
4365 ToggleSwitchgateSwitch(x, y + 1);
4367 else if (smashed == EL_LIGHT_SWITCH ||
4368 smashed == EL_LIGHT_SWITCH_ACTIVE)
4370 ToggleLightSwitch(x, y + 1);
4375 TestIfElementSmashesCustomElement(x, y, MV_DOWN);
4378 CheckElementChange(x, y + 1, smashed, element, CE_SMASHED);
4381 /* !!! TEST ONLY !!! */
4382 CheckElementChangeBySide(x, y + 1, smashed, element,
4383 CE_SWITCHED, CH_SIDE_TOP);
4384 CheckTriggeredElementChangeBySide(x, y + 1, smashed,
4385 CE_OTHER_IS_SWITCHING,CH_SIDE_TOP);
4387 CheckTriggeredElementChangeBySide(x, y + 1, smashed,
4388 CE_OTHER_IS_SWITCHING,CH_SIDE_TOP);
4389 CheckElementChangeBySide(x, y + 1, smashed, element,
4390 CE_SWITCHED, CH_SIDE_TOP);
4396 CheckElementChange(x, y + 1, smashed, element, CE_SMASHED);
4401 /* play sound of magic wall / mill */
4403 (Feld[x][y + 1] == EL_MAGIC_WALL_ACTIVE ||
4404 Feld[x][y + 1] == EL_BD_MAGIC_WALL_ACTIVE))
4406 if (Feld[x][y + 1] == EL_MAGIC_WALL_ACTIVE)
4407 PlayLevelSound(x, y, SND_MAGIC_WALL_FILLING);
4408 else if (Feld[x][y + 1] == EL_BD_MAGIC_WALL_ACTIVE)
4409 PlayLevelSound(x, y, SND_BD_MAGIC_WALL_FILLING);
4414 /* play sound of object that hits the ground */
4415 if (lastline || object_hit)
4416 PlayLevelSoundElementAction(x, y, element, ACTION_IMPACT);
4419 inline static void TurnRoundExt(int x, int y)
4431 { 0, 0 }, { 0, 0 }, { 0, 0 },
4436 int left, right, back;
4440 { MV_DOWN, MV_UP, MV_RIGHT },
4441 { MV_UP, MV_DOWN, MV_LEFT },
4443 { MV_LEFT, MV_RIGHT, MV_DOWN },
4447 { MV_RIGHT, MV_LEFT, MV_UP }
4450 int element = Feld[x][y];
4451 int move_pattern = element_info[element].move_pattern;
4453 int old_move_dir = MovDir[x][y];
4454 int left_dir = turn[old_move_dir].left;
4455 int right_dir = turn[old_move_dir].right;
4456 int back_dir = turn[old_move_dir].back;
4458 int left_dx = move_xy[left_dir].x, left_dy = move_xy[left_dir].y;
4459 int right_dx = move_xy[right_dir].x, right_dy = move_xy[right_dir].y;
4460 int move_dx = move_xy[old_move_dir].x, move_dy = move_xy[old_move_dir].y;
4461 int back_dx = move_xy[back_dir].x, back_dy = move_xy[back_dir].y;
4463 int left_x = x + left_dx, left_y = y + left_dy;
4464 int right_x = x + right_dx, right_y = y + right_dy;
4465 int move_x = x + move_dx, move_y = y + move_dy;
4469 if (element == EL_BUG || element == EL_BD_BUTTERFLY)
4471 TestIfBadThingTouchesOtherBadThing(x, y);
4473 if (ENEMY_CAN_ENTER_FIELD(element, right_x, right_y))
4474 MovDir[x][y] = right_dir;
4475 else if (!ENEMY_CAN_ENTER_FIELD(element, move_x, move_y))
4476 MovDir[x][y] = left_dir;
4478 if (element == EL_BUG && MovDir[x][y] != old_move_dir)
4480 else if (element == EL_BD_BUTTERFLY) /* && MovDir[x][y] == left_dir) */
4484 else if (element == EL_SPACESHIP || element == EL_BD_FIREFLY ||
4485 element == EL_SP_SNIKSNAK || element == EL_SP_ELECTRON)
4487 TestIfBadThingTouchesOtherBadThing(x, y);
4489 if (ENEMY_CAN_ENTER_FIELD(element, left_x, left_y))
4490 MovDir[x][y] = left_dir;
4491 else if (!ENEMY_CAN_ENTER_FIELD(element, move_x, move_y))
4492 MovDir[x][y] = right_dir;
4494 if ((element == EL_SPACESHIP ||
4495 element == EL_SP_SNIKSNAK ||
4496 element == EL_SP_ELECTRON)
4497 && MovDir[x][y] != old_move_dir)
4499 else if (element == EL_BD_FIREFLY) /* && MovDir[x][y] == right_dir) */
4503 else if (element == EL_SPACESHIP || element == EL_BD_FIREFLY)
4505 TestIfBadThingTouchesOtherBadThing(x, y);
4507 if (ENEMY_CAN_ENTER_FIELD(element, left_x, left_y))
4508 MovDir[x][y] = left_dir;
4509 else if (!ENEMY_CAN_ENTER_FIELD(element, move_x, move_y))
4510 MovDir[x][y] = right_dir;
4512 if (element == EL_SPACESHIP && MovDir[x][y] != old_move_dir)
4514 else if (element == EL_BD_FIREFLY) /* && MovDir[x][y] == right_dir) */
4517 else if (element == EL_SP_SNIKSNAK || element == EL_SP_ELECTRON)
4519 TestIfBadThingTouchesOtherBadThing(x, y);
4521 if (ELEMENT_CAN_ENTER_FIELD_BASE_4(element, left_x, left_y, 0))
4522 MovDir[x][y] = left_dir;
4523 else if (!ELEMENT_CAN_ENTER_FIELD_BASE_4(element, move_x, move_y, 0))
4524 MovDir[x][y] = right_dir;
4526 if (MovDir[x][y] != old_move_dir)
4530 else if (element == EL_YAMYAM)
4532 boolean can_turn_left = YAMYAM_CAN_ENTER_FIELD(element, left_x, left_y);
4533 boolean can_turn_right = YAMYAM_CAN_ENTER_FIELD(element, right_x, right_y);
4535 if (can_turn_left && can_turn_right)
4536 MovDir[x][y] = (RND(3) ? (RND(2) ? left_dir : right_dir) : back_dir);
4537 else if (can_turn_left)
4538 MovDir[x][y] = (RND(2) ? left_dir : back_dir);
4539 else if (can_turn_right)
4540 MovDir[x][y] = (RND(2) ? right_dir : back_dir);
4542 MovDir[x][y] = back_dir;
4544 MovDelay[x][y] = 16 + 16 * RND(3);
4546 else if (element == EL_DARK_YAMYAM)
4548 boolean can_turn_left = DARK_YAMYAM_CAN_ENTER_FIELD(element,
4550 boolean can_turn_right = DARK_YAMYAM_CAN_ENTER_FIELD(element,
4553 if (can_turn_left && can_turn_right)
4554 MovDir[x][y] = (RND(3) ? (RND(2) ? left_dir : right_dir) : back_dir);
4555 else if (can_turn_left)
4556 MovDir[x][y] = (RND(2) ? left_dir : back_dir);
4557 else if (can_turn_right)
4558 MovDir[x][y] = (RND(2) ? right_dir : back_dir);
4560 MovDir[x][y] = back_dir;
4562 MovDelay[x][y] = 16 + 16 * RND(3);
4564 else if (element == EL_PACMAN)
4566 boolean can_turn_left = PACMAN_CAN_ENTER_FIELD(element, left_x, left_y);
4567 boolean can_turn_right = PACMAN_CAN_ENTER_FIELD(element, right_x, right_y);
4569 if (can_turn_left && can_turn_right)
4570 MovDir[x][y] = (RND(3) ? (RND(2) ? left_dir : right_dir) : back_dir);
4571 else if (can_turn_left)
4572 MovDir[x][y] = (RND(2) ? left_dir : back_dir);
4573 else if (can_turn_right)
4574 MovDir[x][y] = (RND(2) ? right_dir : back_dir);
4576 MovDir[x][y] = back_dir;
4578 MovDelay[x][y] = 6 + RND(40);
4580 else if (element == EL_PIG)
4582 boolean can_turn_left = PIG_CAN_ENTER_FIELD(element, left_x, left_y);
4583 boolean can_turn_right = PIG_CAN_ENTER_FIELD(element, right_x, right_y);
4584 boolean can_move_on = PIG_CAN_ENTER_FIELD(element, move_x, move_y);
4585 boolean should_turn_left, should_turn_right, should_move_on;
4587 int rnd = RND(rnd_value);
4589 should_turn_left = (can_turn_left &&
4591 IN_LEV_FIELD_AND_NOT_FREE(x + back_dx + left_dx,
4592 y + back_dy + left_dy)));
4593 should_turn_right = (can_turn_right &&
4595 IN_LEV_FIELD_AND_NOT_FREE(x + back_dx + right_dx,
4596 y + back_dy + right_dy)));
4597 should_move_on = (can_move_on &&
4600 IN_LEV_FIELD_AND_NOT_FREE(x + move_dx + left_dx,
4601 y + move_dy + left_dy) ||
4602 IN_LEV_FIELD_AND_NOT_FREE(x + move_dx + right_dx,
4603 y + move_dy + right_dy)));
4605 if (should_turn_left || should_turn_right || should_move_on)
4607 if (should_turn_left && should_turn_right && should_move_on)
4608 MovDir[x][y] = (rnd < rnd_value / 3 ? left_dir :
4609 rnd < 2 * rnd_value / 3 ? right_dir :
4611 else if (should_turn_left && should_turn_right)
4612 MovDir[x][y] = (rnd < rnd_value / 2 ? left_dir : right_dir);
4613 else if (should_turn_left && should_move_on)
4614 MovDir[x][y] = (rnd < rnd_value / 2 ? left_dir : old_move_dir);
4615 else if (should_turn_right && should_move_on)
4616 MovDir[x][y] = (rnd < rnd_value / 2 ? right_dir : old_move_dir);
4617 else if (should_turn_left)
4618 MovDir[x][y] = left_dir;
4619 else if (should_turn_right)
4620 MovDir[x][y] = right_dir;
4621 else if (should_move_on)
4622 MovDir[x][y] = old_move_dir;
4624 else if (can_move_on && rnd > rnd_value / 8)
4625 MovDir[x][y] = old_move_dir;
4626 else if (can_turn_left && can_turn_right)
4627 MovDir[x][y] = (rnd < rnd_value / 2 ? left_dir : right_dir);
4628 else if (can_turn_left && rnd > rnd_value / 8)
4629 MovDir[x][y] = left_dir;
4630 else if (can_turn_right && rnd > rnd_value/8)
4631 MovDir[x][y] = right_dir;
4633 MovDir[x][y] = back_dir;
4635 xx = x + move_xy[MovDir[x][y]].x;
4636 yy = y + move_xy[MovDir[x][y]].y;
4639 /* !!! this bugfix breaks at least BD2K3, level 010 !!! */
4640 if (!IN_LEV_FIELD(xx, yy) ||
4641 (!IS_FREE(xx, yy) && !IS_FOOD_PIG(Feld[xx][yy])))
4642 MovDir[x][y] = old_move_dir;
4644 if (!IS_FREE(xx, yy) && !IS_FOOD_PIG(Feld[xx][yy]))
4645 MovDir[x][y] = old_move_dir;
4650 else if (element == EL_DRAGON)
4652 boolean can_turn_left = DRAGON_CAN_ENTER_FIELD(element, left_x, left_y);
4653 boolean can_turn_right = DRAGON_CAN_ENTER_FIELD(element, right_x, right_y);
4654 boolean can_move_on = DRAGON_CAN_ENTER_FIELD(element, move_x, move_y);
4656 int rnd = RND(rnd_value);
4659 if (FrameCounter < 1 && x == 0 && y == 29)
4660 printf(":2: %d/%d: %d [%d]\n", x, y, MovDir[x][y], FrameCounter);
4663 if (can_move_on && rnd > rnd_value / 8)
4664 MovDir[x][y] = old_move_dir;
4665 else if (can_turn_left && can_turn_right)
4666 MovDir[x][y] = (rnd < rnd_value / 2 ? left_dir : right_dir);
4667 else if (can_turn_left && rnd > rnd_value / 8)
4668 MovDir[x][y] = left_dir;
4669 else if (can_turn_right && rnd > rnd_value / 8)
4670 MovDir[x][y] = right_dir;
4672 MovDir[x][y] = back_dir;
4674 xx = x + move_xy[MovDir[x][y]].x;
4675 yy = y + move_xy[MovDir[x][y]].y;
4678 if (FrameCounter < 1 && x == 0 && y == 29)
4679 printf(":3: %d/%d: %d (%d/%d: %d) [%d]\n", x, y, MovDir[x][y],
4680 xx, yy, Feld[xx][yy],
4685 if (!IN_LEV_FIELD_AND_IS_FREE(xx, yy))
4686 MovDir[x][y] = old_move_dir;
4688 if (!IS_FREE(xx, yy))
4689 MovDir[x][y] = old_move_dir;
4693 if (FrameCounter < 1 && x == 0 && y == 29)
4694 printf(":4: %d/%d: %d [%d]\n", x, y, MovDir[x][y], FrameCounter);
4699 else if (element == EL_MOLE)
4701 boolean can_move_on =
4702 (MOLE_CAN_ENTER_FIELD(element, move_x, move_y,
4703 IS_AMOEBOID(Feld[move_x][move_y]) ||
4704 Feld[move_x][move_y] == EL_AMOEBA_SHRINKING));
4707 boolean can_turn_left =
4708 (MOLE_CAN_ENTER_FIELD(element, left_x, left_y,
4709 IS_AMOEBOID(Feld[left_x][left_y])));
4711 boolean can_turn_right =
4712 (MOLE_CAN_ENTER_FIELD(element, right_x, right_y,
4713 IS_AMOEBOID(Feld[right_x][right_y])));
4715 if (can_turn_left && can_turn_right)
4716 MovDir[x][y] = (RND(2) ? left_dir : right_dir);
4717 else if (can_turn_left)
4718 MovDir[x][y] = left_dir;
4720 MovDir[x][y] = right_dir;
4723 if (MovDir[x][y] != old_move_dir)
4726 else if (element == EL_BALLOON)
4728 MovDir[x][y] = game.balloon_dir;
4731 else if (element == EL_SPRING)
4734 if (MovDir[x][y] & MV_HORIZONTAL &&
4735 !SPRING_CAN_ENTER_FIELD(element, move_x, move_y))
4736 MovDir[x][y] = MV_NO_MOVING;
4738 if (MovDir[x][y] & MV_HORIZONTAL &&
4739 (!SPRING_CAN_ENTER_FIELD(element, move_x, move_y) ||
4740 SPRING_CAN_ENTER_FIELD(element, x, y + 1)))
4741 MovDir[x][y] = MV_NO_MOVING;
4746 else if (element == EL_ROBOT ||
4747 element == EL_SATELLITE ||
4748 element == EL_PENGUIN)
4750 int attr_x = -1, attr_y = -1;
4761 for (i = 0; i < MAX_PLAYERS; i++)
4763 struct PlayerInfo *player = &stored_player[i];
4764 int jx = player->jx, jy = player->jy;
4766 if (!player->active)
4770 ABS(jx - x) + ABS(jy - y) < ABS(attr_x - x) + ABS(attr_y - y))
4779 if (element == EL_ROBOT && ZX >= 0 && ZY >= 0 &&
4780 (Feld[ZX][ZY] == EL_ROBOT_WHEEL_ACTIVE ||
4781 game.engine_version < VERSION_IDENT(3,1,0,0)))
4783 if (element == EL_ROBOT && ZX >= 0 && ZY >= 0)
4790 if (element == EL_PENGUIN)
4793 static int xy[4][2] =
4801 for (i = 0; i < NUM_DIRECTIONS; i++)
4803 int ex = x + xy[i][0];
4804 int ey = y + xy[i][1];
4806 if (IN_LEV_FIELD(ex, ey) && Feld[ex][ey] == EL_EXIT_OPEN)
4815 MovDir[x][y] = MV_NO_MOVING;
4817 MovDir[x][y] |= (AllPlayersGone ? MV_RIGHT : MV_LEFT);
4818 else if (attr_x > x)
4819 MovDir[x][y] |= (AllPlayersGone ? MV_LEFT : MV_RIGHT);
4821 MovDir[x][y] |= (AllPlayersGone ? MV_DOWN : MV_UP);
4822 else if (attr_y > y)
4823 MovDir[x][y] |= (AllPlayersGone ? MV_UP : MV_DOWN);
4825 if (element == EL_ROBOT)
4829 if (MovDir[x][y] & MV_HORIZONTAL && MovDir[x][y] & MV_VERTICAL)
4830 MovDir[x][y] &= (RND(2) ? MV_HORIZONTAL : MV_VERTICAL);
4831 Moving2Blocked(x, y, &newx, &newy);
4833 if (IN_LEV_FIELD(newx, newy) && IS_FREE_OR_PLAYER(newx, newy))
4834 MovDelay[x][y] = 8 + 8 * !RND(3);
4836 MovDelay[x][y] = 16;
4838 else if (element == EL_PENGUIN)
4844 if (MovDir[x][y] & MV_HORIZONTAL && MovDir[x][y] & MV_VERTICAL)
4846 boolean first_horiz = RND(2);
4847 int new_move_dir = MovDir[x][y];
4850 new_move_dir & (first_horiz ? MV_HORIZONTAL : MV_VERTICAL);
4851 Moving2Blocked(x, y, &newx, &newy);
4853 if (PENGUIN_CAN_ENTER_FIELD(EL_PENGUIN, newx, newy))
4857 new_move_dir & (!first_horiz ? MV_HORIZONTAL : MV_VERTICAL);
4858 Moving2Blocked(x, y, &newx, &newy);
4860 if (PENGUIN_CAN_ENTER_FIELD(EL_PENGUIN, newx, newy))
4863 MovDir[x][y] = old_move_dir;
4867 else /* (element == EL_SATELLITE) */
4873 if (MovDir[x][y] & MV_HORIZONTAL && MovDir[x][y] & MV_VERTICAL)
4875 boolean first_horiz = RND(2);
4876 int new_move_dir = MovDir[x][y];
4879 new_move_dir & (first_horiz ? MV_HORIZONTAL : MV_VERTICAL);
4880 Moving2Blocked(x, y, &newx, &newy);
4882 if (SATELLITE_CAN_ENTER_FIELD(newx, newy))
4886 new_move_dir & (!first_horiz ? MV_HORIZONTAL : MV_VERTICAL);
4887 Moving2Blocked(x, y, &newx, &newy);
4889 if (SATELLITE_CAN_ENTER_FIELD(newx, newy))
4892 MovDir[x][y] = old_move_dir;
4897 else if (move_pattern == MV_TURNING_LEFT ||
4898 move_pattern == MV_TURNING_RIGHT ||
4899 move_pattern == MV_TURNING_LEFT_RIGHT ||
4900 move_pattern == MV_TURNING_RIGHT_LEFT ||
4901 move_pattern == MV_TURNING_RANDOM ||
4902 move_pattern == MV_ALL_DIRECTIONS)
4904 boolean can_turn_left =
4905 CUSTOM_ELEMENT_CAN_ENTER_FIELD(element, left_x, left_y);
4906 boolean can_turn_right =
4907 CUSTOM_ELEMENT_CAN_ENTER_FIELD(element, right_x,right_y);
4909 if (move_pattern == MV_TURNING_LEFT)
4910 MovDir[x][y] = left_dir;
4911 else if (move_pattern == MV_TURNING_RIGHT)
4912 MovDir[x][y] = right_dir;
4913 else if (move_pattern == MV_TURNING_LEFT_RIGHT)
4914 MovDir[x][y] = (can_turn_left || !can_turn_right ? left_dir : right_dir);
4915 else if (move_pattern == MV_TURNING_RIGHT_LEFT)
4916 MovDir[x][y] = (can_turn_right || !can_turn_left ? right_dir : left_dir);
4917 else if (move_pattern == MV_TURNING_RANDOM)
4918 MovDir[x][y] = (can_turn_left && !can_turn_right ? left_dir :
4919 can_turn_right && !can_turn_left ? right_dir :
4920 RND(2) ? left_dir : right_dir);
4921 else if (can_turn_left && can_turn_right)
4922 MovDir[x][y] = (RND(3) ? (RND(2) ? left_dir : right_dir) : back_dir);
4923 else if (can_turn_left)
4924 MovDir[x][y] = (RND(2) ? left_dir : back_dir);
4925 else if (can_turn_right)
4926 MovDir[x][y] = (RND(2) ? right_dir : back_dir);
4928 MovDir[x][y] = back_dir;
4930 MovDelay[x][y] = GET_NEW_MOVE_DELAY(element);
4932 else if (move_pattern == MV_HORIZONTAL ||
4933 move_pattern == MV_VERTICAL)
4935 if (move_pattern & old_move_dir)
4936 MovDir[x][y] = back_dir;
4937 else if (move_pattern == MV_HORIZONTAL)
4938 MovDir[x][y] = (RND(2) ? MV_LEFT : MV_RIGHT);
4939 else if (move_pattern == MV_VERTICAL)
4940 MovDir[x][y] = (RND(2) ? MV_UP : MV_DOWN);
4942 MovDelay[x][y] = GET_NEW_MOVE_DELAY(element);
4944 else if (move_pattern & MV_ANY_DIRECTION)
4946 MovDir[x][y] = move_pattern;
4947 MovDelay[x][y] = GET_NEW_MOVE_DELAY(element);
4949 else if (move_pattern == MV_ALONG_LEFT_SIDE)
4951 if (CUSTOM_ELEMENT_CAN_ENTER_FIELD(element, left_x, left_y))
4952 MovDir[x][y] = left_dir;
4953 else if (!CUSTOM_ELEMENT_CAN_ENTER_FIELD(element, move_x, move_y))
4954 MovDir[x][y] = right_dir;
4956 if (MovDir[x][y] != old_move_dir)
4957 MovDelay[x][y] = GET_NEW_MOVE_DELAY(element);
4959 else if (move_pattern == MV_ALONG_RIGHT_SIDE)
4961 if (CUSTOM_ELEMENT_CAN_ENTER_FIELD(element, right_x, right_y))
4962 MovDir[x][y] = right_dir;
4963 else if (!CUSTOM_ELEMENT_CAN_ENTER_FIELD(element, move_x, move_y))
4964 MovDir[x][y] = left_dir;
4966 if (MovDir[x][y] != old_move_dir)
4967 MovDelay[x][y] = GET_NEW_MOVE_DELAY(element);
4969 else if (move_pattern == MV_TOWARDS_PLAYER ||
4970 move_pattern == MV_AWAY_FROM_PLAYER)
4972 int attr_x = -1, attr_y = -1;
4974 boolean move_away = (move_pattern == MV_AWAY_FROM_PLAYER);
4985 for (i = 0; i < MAX_PLAYERS; i++)
4987 struct PlayerInfo *player = &stored_player[i];
4988 int jx = player->jx, jy = player->jy;
4990 if (!player->active)
4994 ABS(jx - x) + ABS(jy - y) < ABS(attr_x - x) + ABS(attr_y - y))
5002 MovDir[x][y] = MV_NO_MOVING;
5004 MovDir[x][y] |= (move_away ? MV_RIGHT : MV_LEFT);
5005 else if (attr_x > x)
5006 MovDir[x][y] |= (move_away ? MV_LEFT : MV_RIGHT);
5008 MovDir[x][y] |= (move_away ? MV_DOWN : MV_UP);
5009 else if (attr_y > y)
5010 MovDir[x][y] |= (move_away ? MV_UP : MV_DOWN);
5012 MovDelay[x][y] = GET_NEW_MOVE_DELAY(element);
5014 if (MovDir[x][y] & MV_HORIZONTAL && MovDir[x][y] & MV_VERTICAL)
5016 boolean first_horiz = RND(2);
5017 int new_move_dir = MovDir[x][y];
5020 new_move_dir & (first_horiz ? MV_HORIZONTAL : MV_VERTICAL);
5021 Moving2Blocked(x, y, &newx, &newy);
5023 if (CUSTOM_ELEMENT_CAN_ENTER_FIELD(element, newx, newy))
5027 new_move_dir & (!first_horiz ? MV_HORIZONTAL : MV_VERTICAL);
5028 Moving2Blocked(x, y, &newx, &newy);
5030 if (CUSTOM_ELEMENT_CAN_ENTER_FIELD(element, newx, newy))
5033 MovDir[x][y] = old_move_dir;
5036 else if (move_pattern == MV_WHEN_PUSHED ||
5037 move_pattern == MV_WHEN_DROPPED)
5039 if (!CUSTOM_ELEMENT_CAN_ENTER_FIELD(element, move_x, move_y))
5040 MovDir[x][y] = MV_NO_MOVING;
5044 else if (move_pattern & MV_MAZE_RUNNER_STYLE)
5046 static int test_xy[7][2] =
5056 static int test_dir[7] =
5066 boolean hunter_mode = (move_pattern == MV_MAZE_HUNTER);
5067 int move_preference = -1000000; /* start with very low preference */
5068 int new_move_dir = MV_NO_MOVING;
5069 int start_test = RND(4);
5072 for (i = 0; i < NUM_DIRECTIONS; i++)
5074 int move_dir = test_dir[start_test + i];
5075 int move_dir_preference;
5077 xx = x + test_xy[start_test + i][0];
5078 yy = y + test_xy[start_test + i][1];
5080 if (hunter_mode && IN_LEV_FIELD(xx, yy) &&
5081 (IS_PLAYER(xx, yy) || Feld[xx][yy] == EL_PLAYER_IS_LEAVING))
5083 new_move_dir = move_dir;
5088 if (!CUSTOM_ELEMENT_CAN_ENTER_FIELD(element, xx, yy))
5091 move_dir_preference = -1 * RunnerVisit[xx][yy];
5092 if (hunter_mode && PlayerVisit[xx][yy] > 0)
5093 move_dir_preference = PlayerVisit[xx][yy];
5095 if (move_dir_preference > move_preference)
5097 /* prefer field that has not been visited for the longest time */
5098 move_preference = move_dir_preference;
5099 new_move_dir = move_dir;
5101 else if (move_dir_preference == move_preference &&
5102 move_dir == old_move_dir)
5104 /* prefer last direction when all directions are preferred equally */
5105 move_preference = move_dir_preference;
5106 new_move_dir = move_dir;
5110 MovDir[x][y] = new_move_dir;
5111 if (old_move_dir != new_move_dir)
5116 static void TurnRound(int x, int y)
5118 int direction = MovDir[x][y];
5121 GfxDir[x][y] = MovDir[x][y];
5127 GfxDir[x][y] = MovDir[x][y];
5130 if (direction != MovDir[x][y])
5135 GfxAction[x][y] = ACTION_TURNING_FROM_LEFT + MV_DIR_BIT(direction);
5138 GfxAction[x][y] = ACTION_WAITING;
5142 static boolean JustBeingPushed(int x, int y)
5146 for (i = 0; i < MAX_PLAYERS; i++)
5148 struct PlayerInfo *player = &stored_player[i];
5150 if (player->active && player->is_pushing && player->MovPos)
5152 int next_jx = player->jx + (player->jx - player->last_jx);
5153 int next_jy = player->jy + (player->jy - player->last_jy);
5155 if (x == next_jx && y == next_jy)
5163 void StartMoving(int x, int y)
5166 boolean use_spring_bug = (game.engine_version < VERSION_IDENT(2,2,0,0));
5168 boolean started_moving = FALSE; /* some elements can fall _and_ move */
5169 int element = Feld[x][y];
5175 if (MovDelay[x][y] == 0)
5176 GfxAction[x][y] = ACTION_DEFAULT;
5178 /* !!! this should be handled more generic (not only for mole) !!! */
5179 if (element != EL_MOLE && GfxAction[x][y] != ACTION_DIGGING)
5180 GfxAction[x][y] = ACTION_DEFAULT;
5183 if (CAN_FALL(element) && y < lev_fieldy - 1)
5185 if ((x > 0 && IS_PLAYER(x - 1, y)) ||
5186 (x < lev_fieldx - 1 && IS_PLAYER(x + 1, y)))
5187 if (JustBeingPushed(x, y))
5190 if (element == EL_QUICKSAND_FULL)
5192 if (IS_FREE(x, y + 1))
5194 InitMovingField(x, y, MV_DOWN);
5195 started_moving = TRUE;
5197 Feld[x][y] = EL_QUICKSAND_EMPTYING;
5198 Store[x][y] = EL_ROCK;
5200 PlayLevelSoundAction(x, y, ACTION_EMPTYING);
5202 PlayLevelSound(x, y, SND_QUICKSAND_EMPTYING);
5205 else if (Feld[x][y + 1] == EL_QUICKSAND_EMPTY)
5207 if (!MovDelay[x][y])
5208 MovDelay[x][y] = TILEY + 1;
5217 Feld[x][y] = EL_QUICKSAND_EMPTY;
5218 Feld[x][y + 1] = EL_QUICKSAND_FULL;
5219 Store[x][y + 1] = Store[x][y];
5222 PlayLevelSoundAction(x, y, ACTION_FILLING);
5224 PlayLevelSound(x, y, SND_QUICKSAND_FILLING);
5228 else if ((element == EL_ROCK || element == EL_BD_ROCK) &&
5229 Feld[x][y + 1] == EL_QUICKSAND_EMPTY)
5231 InitMovingField(x, y, MV_DOWN);
5232 started_moving = TRUE;
5234 Feld[x][y] = EL_QUICKSAND_FILLING;
5235 Store[x][y] = element;
5237 PlayLevelSoundAction(x, y, ACTION_FILLING);
5239 PlayLevelSound(x, y, SND_QUICKSAND_FILLING);
5242 else if (element == EL_MAGIC_WALL_FULL)
5244 if (IS_FREE(x, y + 1))
5246 InitMovingField(x, y, MV_DOWN);
5247 started_moving = TRUE;
5249 Feld[x][y] = EL_MAGIC_WALL_EMPTYING;
5250 Store[x][y] = EL_CHANGED(Store[x][y]);
5252 else if (Feld[x][y + 1] == EL_MAGIC_WALL_ACTIVE)
5254 if (!MovDelay[x][y])
5255 MovDelay[x][y] = TILEY/4 + 1;
5264 Feld[x][y] = EL_MAGIC_WALL_ACTIVE;
5265 Feld[x][y + 1] = EL_MAGIC_WALL_FULL;
5266 Store[x][y + 1] = EL_CHANGED(Store[x][y]);
5270 else if (element == EL_BD_MAGIC_WALL_FULL)
5272 if (IS_FREE(x, y + 1))
5274 InitMovingField(x, y, MV_DOWN);
5275 started_moving = TRUE;
5277 Feld[x][y] = EL_BD_MAGIC_WALL_EMPTYING;
5278 Store[x][y] = EL_CHANGED2(Store[x][y]);
5280 else if (Feld[x][y + 1] == EL_BD_MAGIC_WALL_ACTIVE)
5282 if (!MovDelay[x][y])
5283 MovDelay[x][y] = TILEY/4 + 1;
5292 Feld[x][y] = EL_BD_MAGIC_WALL_ACTIVE;
5293 Feld[x][y + 1] = EL_BD_MAGIC_WALL_FULL;
5294 Store[x][y + 1] = EL_CHANGED2(Store[x][y]);
5298 else if (CAN_PASS_MAGIC_WALL(element) &&
5299 (Feld[x][y + 1] == EL_MAGIC_WALL_ACTIVE ||
5300 Feld[x][y + 1] == EL_BD_MAGIC_WALL_ACTIVE))
5302 InitMovingField(x, y, MV_DOWN);
5303 started_moving = TRUE;
5306 (Feld[x][y + 1] == EL_MAGIC_WALL_ACTIVE ? EL_MAGIC_WALL_FILLING :
5307 EL_BD_MAGIC_WALL_FILLING);
5308 Store[x][y] = element;
5311 else if (CAN_SMASH(element) && Feld[x][y + 1] == EL_ACID)
5313 else if (CAN_FALL(element) && Feld[x][y + 1] == EL_ACID)
5316 SplashAcid(x, y + 1);
5318 InitMovingField(x, y, MV_DOWN);
5319 started_moving = TRUE;
5321 Store[x][y] = EL_ACID;
5323 /* !!! TEST !!! better use "_FALLING" etc. !!! */
5324 GfxAction[x][y + 1] = ACTION_ACTIVE;
5328 else if ((game.engine_version >= VERSION_IDENT(3,1,0,0) &&
5329 CheckCollision[x][y] && !IS_FREE(x, y + 1)) ||
5331 (game.engine_version >= VERSION_IDENT(3,0,7,0) &&
5332 CAN_SMASH(element) && WasJustFalling[x][y] &&
5333 (Feld[x][y + 1] == EL_BLOCKED || IS_PLAYER(x, y + 1))) ||
5335 (game.engine_version < VERSION_IDENT(2,2,0,7) &&
5336 CAN_SMASH(element) && WasJustMoving[x][y] && !Pushed[x][y + 1] &&
5337 (Feld[x][y + 1] == EL_BLOCKED)))
5341 else if (game.engine_version < VERSION_IDENT(2,2,0,7) &&
5342 CAN_SMASH(element) && Feld[x][y + 1] == EL_BLOCKED &&
5343 WasJustMoving[x][y] && !Pushed[x][y + 1])
5345 else if (CAN_SMASH(element) && Feld[x][y + 1] == EL_BLOCKED &&
5346 WasJustMoving[x][y])
5351 /* this is needed for a special case not covered by calling "Impact()"
5352 from "ContinueMoving()": if an element moves to a tile directly below
5353 another element which was just falling on that tile (which was empty
5354 in the previous frame), the falling element above would just stop
5355 instead of smashing the element below (in previous version, the above
5356 element was just checked for "moving" instead of "falling", resulting
5357 in incorrect smashes caused by horizontal movement of the above
5358 element; also, the case of the player being the element to smash was
5359 simply not covered here... :-/ ) */
5362 WasJustMoving[x][y] = 0;
5363 WasJustFalling[x][y] = 0;
5366 CheckCollision[x][y] = 0;
5369 if (IS_PLAYER(x, y + 1))
5370 printf("::: we ARE now killing the player [%d]\n", FrameCounter);
5375 else if (IS_FREE(x, y + 1) && element == EL_SPRING && level.use_spring_bug)
5377 if (MovDir[x][y] == MV_NO_MOVING)
5379 InitMovingField(x, y, MV_DOWN);
5380 started_moving = TRUE;
5383 else if (IS_FREE(x, y + 1) || Feld[x][y + 1] == EL_DIAMOND_BREAKING)
5385 if (WasJustFalling[x][y]) /* prevent animation from being restarted */
5386 MovDir[x][y] = MV_DOWN;
5388 InitMovingField(x, y, MV_DOWN);
5389 started_moving = TRUE;
5391 else if (element == EL_AMOEBA_DROP)
5393 Feld[x][y] = EL_AMOEBA_GROWING;
5394 Store[x][y] = EL_AMOEBA_WET;
5396 /* Store[x][y + 1] must be zero, because:
5397 (EL_QUICKSAND_FULL -> EL_ROCK): Store[x][y + 1] == EL_QUICKSAND_EMPTY
5400 #if OLD_GAME_BEHAVIOUR
5401 else if (IS_SLIPPERY(Feld[x][y + 1]) && !Store[x][y + 1])
5403 else if (IS_SLIPPERY(Feld[x][y + 1]) && !Store[x][y + 1] &&
5404 !IS_FALLING(x, y + 1) && !WasJustMoving[x][y + 1] &&
5405 element != EL_DX_SUPABOMB)
5408 else if (((IS_SLIPPERY(Feld[x][y + 1]) && !IS_PLAYER(x, y + 1)) ||
5409 (IS_EM_SLIPPERY_WALL(Feld[x][y + 1]) && IS_GEM(element))) &&
5410 !IS_FALLING(x, y + 1) && !WasJustMoving[x][y + 1] &&
5411 element != EL_DX_SUPABOMB && element != EL_SP_DISK_ORANGE)
5414 boolean can_fall_left = (x > 0 && IS_FREE(x - 1, y) &&
5415 (IS_FREE(x - 1, y + 1) ||
5416 Feld[x - 1][y + 1] == EL_ACID));
5417 boolean can_fall_right = (x < lev_fieldx - 1 && IS_FREE(x + 1, y) &&
5418 (IS_FREE(x + 1, y + 1) ||
5419 Feld[x + 1][y + 1] == EL_ACID));
5420 boolean can_fall_any = (can_fall_left || can_fall_right);
5421 boolean can_fall_both = (can_fall_left && can_fall_right);
5423 if (can_fall_any && IS_CUSTOM_ELEMENT(Feld[x][y + 1]))
5425 int slippery_type = element_info[Feld[x][y + 1]].slippery_type;
5427 if (slippery_type == SLIPPERY_ONLY_LEFT)
5428 can_fall_right = FALSE;
5429 else if (slippery_type == SLIPPERY_ONLY_RIGHT)
5430 can_fall_left = FALSE;
5431 else if (slippery_type == SLIPPERY_ANY_LEFT_RIGHT && can_fall_both)
5432 can_fall_right = FALSE;
5433 else if (slippery_type == SLIPPERY_ANY_RIGHT_LEFT && can_fall_both)
5434 can_fall_left = FALSE;
5436 can_fall_any = (can_fall_left || can_fall_right);
5437 can_fall_both = (can_fall_left && can_fall_right);
5440 #if USE_NEW_SP_SLIPPERY
5441 /* !!! better use the same properties as for custom elements here !!! */
5442 else if (game.engine_version >= VERSION_IDENT(3,1,1,0) &&
5443 can_fall_both && IS_SP_ELEMENT(Feld[x][y + 1]))
5445 can_fall_right = FALSE; /* slip down on left side */
5446 can_fall_both = FALSE;
5453 if (game.emulation == EMU_BOULDERDASH ||
5454 element == EL_BD_ROCK || element == EL_BD_DIAMOND)
5455 can_fall_right = FALSE; /* slip down on left side */
5457 can_fall_left = !(can_fall_right = RND(2));
5459 can_fall_both = FALSE;
5466 if (can_fall_both &&
5467 (game.emulation != EMU_BOULDERDASH &&
5468 element != EL_BD_ROCK && element != EL_BD_DIAMOND))
5469 can_fall_left = !(can_fall_right = RND(2));
5472 /* if not determined otherwise, prefer left side for slipping down */
5473 InitMovingField(x, y, can_fall_left ? MV_LEFT : MV_RIGHT);
5474 started_moving = TRUE;
5478 else if (IS_BELT_ACTIVE(Feld[x][y + 1]) && !CAN_MOVE(element))
5480 else if (IS_BELT_ACTIVE(Feld[x][y + 1]))
5483 boolean left_is_free = (x > 0 && IS_FREE(x - 1, y));
5484 boolean right_is_free = (x < lev_fieldx - 1 && IS_FREE(x + 1, y));
5485 int belt_nr = getBeltNrFromBeltActiveElement(Feld[x][y + 1]);
5486 int belt_dir = game.belt_dir[belt_nr];
5488 if ((belt_dir == MV_LEFT && left_is_free) ||
5489 (belt_dir == MV_RIGHT && right_is_free))
5492 int nextx = (belt_dir == MV_LEFT ? x - 1 : x + 1);
5495 InitMovingField(x, y, belt_dir);
5496 started_moving = TRUE;
5499 Pushed[x][y] = TRUE;
5500 Pushed[nextx][y] = TRUE;
5503 GfxAction[x][y] = ACTION_DEFAULT;
5507 MovDir[x][y] = 0; /* if element was moving, stop it */
5512 /* not "else if" because of elements that can fall and move (EL_SPRING) */
5514 if (CAN_MOVE(element) && !started_moving && MovDir[x][y] != MV_NO_MOVING)
5516 if (CAN_MOVE(element) && !started_moving)
5519 int move_pattern = element_info[element].move_pattern;
5524 if (MovDir[x][y] == MV_NO_MOVING)
5526 printf("StartMoving(): %d,%d: element %d ['%s'] not moving\n",
5527 x, y, element, element_info[element].token_name);
5528 printf("StartMoving(): This should never happen!\n");
5533 Moving2Blocked(x, y, &newx, &newy);
5536 if (IS_PUSHABLE(element) && JustBeingPushed(x, y))
5539 if ((element == EL_SATELLITE ||
5540 element == EL_BALLOON ||
5541 element == EL_SPRING)
5542 && JustBeingPushed(x, y))
5549 if (game.engine_version >= VERSION_IDENT(3,1,0,0) &&
5550 CheckCollision[x][y] && !IN_LEV_FIELD_AND_IS_FREE(newx, newy))
5552 if (game.engine_version >= VERSION_IDENT(3,1,0,0) &&
5553 WasJustMoving[x][y] && IN_LEV_FIELD(newx, newy) &&
5554 (Feld[newx][newy] == EL_BLOCKED || IS_PLAYER(newx, newy)))
5558 printf("::: element %d '%s' WasJustMoving %d [%d, %d, %d, %d]\n",
5559 element, element_info[element].token_name,
5560 WasJustMoving[x][y],
5561 HAS_ANY_CHANGE_EVENT(element, CE_HITTING_SOMETHING),
5562 HAS_ANY_CHANGE_EVENT(element, CE_HIT_BY_SOMETHING),
5563 HAS_ANY_CHANGE_EVENT(element, CE_OTHER_IS_HITTING),
5564 HAS_ANY_CHANGE_EVENT(element, CE_OTHER_GETS_HIT));
5568 WasJustMoving[x][y] = 0;
5571 CheckCollision[x][y] = 0;
5573 TestIfElementHitsCustomElement(x, y, MovDir[x][y]);
5576 if (Feld[x][y] != element) /* element has changed */
5578 element = Feld[x][y];
5579 move_pattern = element_info[element].move_pattern;
5581 if (!CAN_MOVE(element))
5585 if (Feld[x][y] != element) /* element has changed */
5593 if (element == EL_SPRING && MovDir[x][y] == MV_DOWN)
5594 Feld[x][y + 1] = EL_EMPTY; /* was set to EL_BLOCKED above */
5596 if (element == EL_SPRING && MovDir[x][y] != MV_NO_MOVING)
5598 Moving2Blocked(x, y, &newx, &newy);
5599 if (Feld[newx][newy] == EL_BLOCKED)
5600 Feld[newx][newy] = EL_EMPTY; /* was set to EL_BLOCKED above */
5606 if (FrameCounter < 1 && x == 0 && y == 29)
5607 printf(":1: %d/%d: %d [%d]\n", x, y, MovDir[x][y], FrameCounter);
5610 if (!MovDelay[x][y]) /* start new movement phase */
5612 /* all objects that can change their move direction after each step
5613 (YAMYAM, DARK_YAMYAM and PACMAN go straight until they hit a wall */
5615 if (element != EL_YAMYAM &&
5616 element != EL_DARK_YAMYAM &&
5617 element != EL_PACMAN &&
5618 !(move_pattern & MV_ANY_DIRECTION) &&
5619 move_pattern != MV_TURNING_LEFT &&
5620 move_pattern != MV_TURNING_RIGHT &&
5621 move_pattern != MV_TURNING_LEFT_RIGHT &&
5622 move_pattern != MV_TURNING_RIGHT_LEFT &&
5623 move_pattern != MV_TURNING_RANDOM)
5628 if (FrameCounter < 1 && x == 0 && y == 29)
5629 printf(":9: %d: %d [%d]\n", y, MovDir[x][y], FrameCounter);
5632 if (MovDelay[x][y] && (element == EL_BUG ||
5633 element == EL_SPACESHIP ||
5634 element == EL_SP_SNIKSNAK ||
5635 element == EL_SP_ELECTRON ||
5636 element == EL_MOLE))
5637 DrawLevelField(x, y);
5641 if (MovDelay[x][y]) /* wait some time before next movement */
5646 if (element == EL_YAMYAM)
5649 el_act_dir2img(EL_YAMYAM, ACTION_WAITING, MV_LEFT));
5650 DrawLevelElementAnimation(x, y, element);
5654 if (MovDelay[x][y]) /* element still has to wait some time */
5657 /* !!! PLACE THIS SOMEWHERE AFTER "TurnRound()" !!! */
5658 ResetGfxAnimation(x, y);
5662 if (GfxAction[x][y] != ACTION_WAITING)
5663 printf("::: %d: %d != ACTION_WAITING\n", element, GfxAction[x][y]);
5665 GfxAction[x][y] = ACTION_WAITING;
5669 if (element == EL_ROBOT ||
5671 element == EL_PACMAN ||
5673 element == EL_YAMYAM ||
5674 element == EL_DARK_YAMYAM)
5677 DrawLevelElementAnimation(x, y, element);
5679 DrawLevelElementAnimationIfNeeded(x, y, element);
5681 PlayLevelSoundAction(x, y, ACTION_WAITING);
5683 else if (element == EL_SP_ELECTRON)
5684 DrawLevelElementAnimationIfNeeded(x, y, element);
5685 else if (element == EL_DRAGON)
5688 int dir = MovDir[x][y];
5689 int dx = (dir == MV_LEFT ? -1 : dir == MV_RIGHT ? +1 : 0);
5690 int dy = (dir == MV_UP ? -1 : dir == MV_DOWN ? +1 : 0);
5691 int graphic = (dir == MV_LEFT ? IMG_FLAMES_1_LEFT :
5692 dir == MV_RIGHT ? IMG_FLAMES_1_RIGHT :
5693 dir == MV_UP ? IMG_FLAMES_1_UP :
5694 dir == MV_DOWN ? IMG_FLAMES_1_DOWN : IMG_EMPTY);
5695 int frame = getGraphicAnimationFrame(graphic, GfxFrame[x][y]);
5698 printf("::: %d, %d\n", GfxAction[x][y], GfxFrame[x][y]);
5701 GfxAction[x][y] = ACTION_ATTACKING;
5703 if (IS_PLAYER(x, y))
5704 DrawPlayerField(x, y);
5706 DrawLevelField(x, y);
5708 PlayLevelSoundActionIfLoop(x, y, ACTION_ATTACKING);
5710 for (i = 1; i <= 3; i++)
5712 int xx = x + i * dx;
5713 int yy = y + i * dy;
5714 int sx = SCREENX(xx);
5715 int sy = SCREENY(yy);
5716 int flame_graphic = graphic + (i - 1);
5718 if (!IN_LEV_FIELD(xx, yy) || IS_DRAGONFIRE_PROOF(Feld[xx][yy]))
5723 int flamed = MovingOrBlocked2Element(xx, yy);
5727 if (IS_CLASSIC_ENEMY(flamed) || CAN_EXPLODE_BY_DRAGONFIRE(flamed))
5729 else if (IS_MOVING(xx, yy) || IS_BLOCKED(xx, yy))
5730 RemoveMovingField(xx, yy);
5732 RemoveField(xx, yy);
5734 if (IS_CLASSIC_ENEMY(flamed) || CAN_EXPLODE_BY_DRAGONFIRE(flamed))
5737 RemoveMovingField(xx, yy);
5741 if (ChangeDelay[xx][yy])
5742 printf("::: !!! [%d]\n", (IS_MOVING(xx, yy) ||
5743 Feld[xx][yy] == EL_BLOCKED));
5747 ChangeDelay[xx][yy] = 0;
5749 Feld[xx][yy] = EL_FLAMES;
5750 if (IN_SCR_FIELD(sx, sy))
5752 DrawLevelFieldCrumbledSand(xx, yy);
5753 DrawGraphic(sx, sy, flame_graphic, frame);
5758 if (Feld[xx][yy] == EL_FLAMES)
5759 Feld[xx][yy] = EL_EMPTY;
5760 DrawLevelField(xx, yy);
5765 if (MovDelay[x][y]) /* element still has to wait some time */
5767 PlayLevelSoundAction(x, y, ACTION_WAITING);
5773 /* special case of "moving" animation of waiting elements (FIX THIS !!!);
5774 for all other elements GfxAction will be set by InitMovingField() */
5775 if (element == EL_BD_BUTTERFLY || element == EL_BD_FIREFLY)
5776 GfxAction[x][y] = ACTION_MOVING;
5780 /* now make next step */
5782 Moving2Blocked(x, y, &newx, &newy); /* get next screen position */
5784 if (DONT_COLLIDE_WITH(element) &&
5785 IN_LEV_FIELD(newx, newy) && IS_PLAYER(newx, newy) &&
5786 !PLAYER_ENEMY_PROTECTED(newx, newy))
5789 TestIfBadThingRunsIntoHero(x, y, MovDir[x][y]);
5793 /* player killed by element which is deadly when colliding with */
5795 KillHero(PLAYERINFO(newx, newy));
5802 else if (CAN_MOVE_INTO_ACID(element) &&
5803 IN_LEV_FIELD(newx, newy) && Feld[newx][newy] == EL_ACID &&
5804 (MovDir[x][y] == MV_DOWN ||
5805 game.engine_version >= VERSION_IDENT(3,1,0,0)))
5807 else if (CAN_MOVE_INTO_ACID(element) && MovDir[x][y] == MV_DOWN &&
5808 IN_LEV_FIELD(newx, newy) && Feld[newx][newy] == EL_ACID)
5812 else if ((element == EL_PENGUIN ||
5813 element == EL_ROBOT ||
5814 element == EL_SATELLITE ||
5815 element == EL_BALLOON ||
5816 IS_CUSTOM_ELEMENT(element)) &&
5817 IN_LEV_FIELD(newx, newy) &&
5818 MovDir[x][y] == MV_DOWN && Feld[newx][newy] == EL_ACID)
5821 SplashAcid(newx, newy);
5822 Store[x][y] = EL_ACID;
5824 else if (element == EL_PENGUIN && IN_LEV_FIELD(newx, newy))
5826 if (Feld[newx][newy] == EL_EXIT_OPEN)
5830 DrawLevelField(x, y);
5832 Feld[x][y] = EL_EMPTY;
5833 DrawLevelField(x, y);
5836 PlayLevelSound(newx, newy, SND_PENGUIN_PASSING);
5837 if (IN_SCR_FIELD(SCREENX(newx), SCREENY(newy)))
5838 DrawGraphicThruMask(SCREENX(newx),SCREENY(newy), el2img(element), 0);
5840 local_player->friends_still_needed--;
5841 if (!local_player->friends_still_needed &&
5842 !local_player->GameOver && AllPlayersGone)
5843 local_player->LevelSolved = local_player->GameOver = TRUE;
5847 else if (IS_FOOD_PENGUIN(Feld[newx][newy]))
5849 if (DigField(local_player, x, y, newx, newy, 0,0, DF_DIG) == MF_MOVING)
5850 DrawLevelField(newx, newy);
5852 GfxDir[x][y] = MovDir[x][y] = MV_NO_MOVING;
5854 else if (!IS_FREE(newx, newy))
5856 GfxAction[x][y] = ACTION_WAITING;
5858 if (IS_PLAYER(x, y))
5859 DrawPlayerField(x, y);
5861 DrawLevelField(x, y);
5866 else if (element == EL_PIG && IN_LEV_FIELD(newx, newy))
5868 if (IS_FOOD_PIG(Feld[newx][newy]))
5870 if (IS_MOVING(newx, newy))
5871 RemoveMovingField(newx, newy);
5874 Feld[newx][newy] = EL_EMPTY;
5875 DrawLevelField(newx, newy);
5878 PlayLevelSound(x, y, SND_PIG_DIGGING);
5880 else if (!IS_FREE(newx, newy))
5882 if (IS_PLAYER(x, y))
5883 DrawPlayerField(x, y);
5885 DrawLevelField(x, y);
5894 else if (move_pattern & MV_MAZE_RUNNER_STYLE && IN_LEV_FIELD(newx, newy))
5897 else if (IS_CUSTOM_ELEMENT(element) &&
5898 CUSTOM_ELEMENT_CAN_ENTER_FIELD(element, newx, newy)
5902 !IS_FREE(newx, newy)
5907 int new_element = Feld[newx][newy];
5910 printf("::: '%s' digs '%s' [%d]\n",
5911 element_info[element].token_name,
5912 element_info[Feld[newx][newy]].token_name,
5913 StorePlayer[newx][newy]);
5916 if (!IS_FREE(newx, newy))
5918 int action = (IS_DIGGABLE(new_element) ? ACTION_DIGGING :
5919 IS_COLLECTIBLE(new_element) ? ACTION_COLLECTING :
5922 /* no element can dig solid indestructible elements */
5923 if (IS_INDESTRUCTIBLE(new_element) &&
5924 !IS_DIGGABLE(new_element) &&
5925 !IS_COLLECTIBLE(new_element))
5928 if (AmoebaNr[newx][newy] &&
5929 (new_element == EL_AMOEBA_FULL ||
5930 new_element == EL_BD_AMOEBA ||
5931 new_element == EL_AMOEBA_GROWING))
5933 AmoebaCnt[AmoebaNr[newx][newy]]--;
5934 AmoebaCnt2[AmoebaNr[newx][newy]]--;
5937 if (IS_MOVING(newx, newy))
5938 RemoveMovingField(newx, newy);
5941 RemoveField(newx, newy);
5942 DrawLevelField(newx, newy);
5945 /* if digged element was about to explode, prevent the explosion */
5946 ExplodeField[newx][newy] = EX_TYPE_NONE;
5948 PlayLevelSoundAction(x, y, action);
5953 Store[newx][newy] = EL_EMPTY;
5954 if (IS_EQUAL_OR_IN_GROUP(new_element, MOVE_ENTER_EL(element)))
5955 Store[newx][newy] = element_info[element].move_leave_element;
5957 Store[newx][newy] = EL_EMPTY;
5958 if (IS_EQUAL_OR_IN_GROUP(new_element, MOVE_ENTER_EL(element)) ||
5959 element_info[element].move_leave_type == LEAVE_TYPE_UNLIMITED)
5960 Store[newx][newy] = element_info[element].move_leave_element;
5963 if (IS_EQUAL_OR_IN_GROUP(new_element, MOVE_ENTER_EL(element)))
5964 element_info[element].can_leave_element = TRUE;
5967 if (move_pattern & MV_MAZE_RUNNER_STYLE)
5969 RunnerVisit[x][y] = FrameCounter;
5970 PlayerVisit[x][y] /= 8; /* expire player visit path */
5976 else if (element == EL_DRAGON && IN_LEV_FIELD(newx, newy))
5978 if (!IS_FREE(newx, newy))
5980 if (IS_PLAYER(x, y))
5981 DrawPlayerField(x, y);
5983 DrawLevelField(x, y);
5989 boolean wanna_flame = !RND(10);
5990 int dx = newx - x, dy = newy - y;
5991 int newx1 = newx + 1 * dx, newy1 = newy + 1 * dy;
5992 int newx2 = newx + 2 * dx, newy2 = newy + 2 * dy;
5993 int element1 = (IN_LEV_FIELD(newx1, newy1) ?
5994 MovingOrBlocked2Element(newx1, newy1) : EL_STEELWALL);
5995 int element2 = (IN_LEV_FIELD(newx2, newy2) ?
5996 MovingOrBlocked2Element(newx2, newy2) : EL_STEELWALL);
5999 IS_CLASSIC_ENEMY(element1) ||
6000 IS_CLASSIC_ENEMY(element2)) &&
6001 element1 != EL_DRAGON && element2 != EL_DRAGON &&
6002 element1 != EL_FLAMES && element2 != EL_FLAMES)
6005 ResetGfxAnimation(x, y);
6006 GfxAction[x][y] = ACTION_ATTACKING;
6009 if (IS_PLAYER(x, y))
6010 DrawPlayerField(x, y);
6012 DrawLevelField(x, y);
6014 PlayLevelSound(x, y, SND_DRAGON_ATTACKING);
6016 MovDelay[x][y] = 50;
6020 RemoveField(newx, newy);
6022 Feld[newx][newy] = EL_FLAMES;
6023 if (IN_LEV_FIELD(newx1, newy1) && Feld[newx1][newy1] == EL_EMPTY)
6026 RemoveField(newx1, newy1);
6028 Feld[newx1][newy1] = EL_FLAMES;
6030 if (IN_LEV_FIELD(newx2, newy2) && Feld[newx2][newy2] == EL_EMPTY)
6033 RemoveField(newx2, newy2);
6035 Feld[newx2][newy2] = EL_FLAMES;
6042 else if (element == EL_YAMYAM && IN_LEV_FIELD(newx, newy) &&
6043 Feld[newx][newy] == EL_DIAMOND)
6045 if (IS_MOVING(newx, newy))
6046 RemoveMovingField(newx, newy);
6049 Feld[newx][newy] = EL_EMPTY;
6050 DrawLevelField(newx, newy);
6053 PlayLevelSound(x, y, SND_YAMYAM_DIGGING);
6055 else if (element == EL_DARK_YAMYAM && IN_LEV_FIELD(newx, newy) &&
6056 IS_FOOD_DARK_YAMYAM(Feld[newx][newy]))
6058 if (AmoebaNr[newx][newy])
6060 AmoebaCnt2[AmoebaNr[newx][newy]]--;
6061 if (Feld[newx][newy] == EL_AMOEBA_FULL ||
6062 Feld[newx][newy] == EL_BD_AMOEBA)
6063 AmoebaCnt[AmoebaNr[newx][newy]]--;
6068 if (IS_MOVING(newx, newy) || IS_BLOCKED(newx, newy))
6070 if (IS_MOVING(newx, newy))
6073 RemoveMovingField(newx, newy);
6077 Feld[newx][newy] = EL_EMPTY;
6078 DrawLevelField(newx, newy);
6081 PlayLevelSound(x, y, SND_DARK_YAMYAM_DIGGING);
6083 else if ((element == EL_PACMAN || element == EL_MOLE)
6084 && IN_LEV_FIELD(newx, newy) && IS_AMOEBOID(Feld[newx][newy]))
6086 if (AmoebaNr[newx][newy])
6088 AmoebaCnt2[AmoebaNr[newx][newy]]--;
6089 if (Feld[newx][newy] == EL_AMOEBA_FULL ||
6090 Feld[newx][newy] == EL_BD_AMOEBA)
6091 AmoebaCnt[AmoebaNr[newx][newy]]--;
6094 if (element == EL_MOLE)
6096 Feld[newx][newy] = EL_AMOEBA_SHRINKING;
6097 PlayLevelSound(x, y, SND_MOLE_DIGGING);
6099 ResetGfxAnimation(x, y);
6100 GfxAction[x][y] = ACTION_DIGGING;
6101 DrawLevelField(x, y);
6103 MovDelay[newx][newy] = 0; /* start amoeba shrinking delay */
6105 return; /* wait for shrinking amoeba */
6107 else /* element == EL_PACMAN */
6109 Feld[newx][newy] = EL_EMPTY;
6110 DrawLevelField(newx, newy);
6111 PlayLevelSound(x, y, SND_PACMAN_DIGGING);
6114 else if (element == EL_MOLE && IN_LEV_FIELD(newx, newy) &&
6115 (Feld[newx][newy] == EL_AMOEBA_SHRINKING ||
6116 (Feld[newx][newy] == EL_EMPTY && Stop[newx][newy])))
6118 /* wait for shrinking amoeba to completely disappear */
6121 else if (!IN_LEV_FIELD(newx, newy) || !IS_FREE(newx, newy))
6123 /* object was running against a wall */
6128 if (move_pattern & MV_ANY_DIRECTION &&
6129 move_pattern == MovDir[x][y])
6131 int blocking_element =
6132 (IN_LEV_FIELD(newx, newy) ? Feld[newx][newy] : BorderElement);
6135 printf("::: '%s' is blocked by '%s'! [%d,%d -> %d,%d]\n",
6136 element_info[element].token_name,
6137 element_info[blocking_element].token_name,
6141 CheckElementChangeBySide(x, y, element, blocking_element, CE_BLOCKED,
6144 element = Feld[x][y]; /* element might have changed */
6149 if (GFX_ELEMENT(element) != EL_SAND) /* !!! FIX THIS (crumble) !!! */
6150 DrawLevelElementAnimation(x, y, element);
6152 if (element == EL_BUG ||
6153 element == EL_SPACESHIP ||
6154 element == EL_SP_SNIKSNAK)
6155 DrawLevelField(x, y);
6156 else if (element == EL_MOLE)
6157 DrawLevelField(x, y);
6158 else if (element == EL_BD_BUTTERFLY ||
6159 element == EL_BD_FIREFLY)
6160 DrawLevelElementAnimationIfNeeded(x, y, element);
6161 else if (element == EL_SATELLITE)
6162 DrawLevelElementAnimationIfNeeded(x, y, element);
6163 else if (element == EL_SP_ELECTRON)
6164 DrawLevelElementAnimationIfNeeded(x, y, element);
6167 if (DONT_TOUCH(element))
6168 TestIfBadThingTouchesHero(x, y);
6171 PlayLevelSoundAction(x, y, ACTION_WAITING);
6177 InitMovingField(x, y, MovDir[x][y]);
6179 PlayLevelSoundAction(x, y, ACTION_MOVING);
6183 ContinueMoving(x, y);
6186 void ContinueMoving(int x, int y)
6188 int element = Feld[x][y];
6189 int stored = Store[x][y];
6190 struct ElementInfo *ei = &element_info[element];
6191 int direction = MovDir[x][y];
6192 int dx = (direction == MV_LEFT ? -1 : direction == MV_RIGHT ? +1 : 0);
6193 int dy = (direction == MV_UP ? -1 : direction == MV_DOWN ? +1 : 0);
6194 int newx = x + dx, newy = y + dy;
6196 int nextx = newx + dx, nexty = newy + dy;
6199 boolean pushed_by_player = (Pushed[x][y] && IS_PLAYER(x, y));
6200 boolean pushed_by_conveyor = (Pushed[x][y] && !IS_PLAYER(x, y));
6202 boolean pushed_by_player = Pushed[x][y];
6205 MovPos[x][y] += getElementMoveStepsize(x, y);
6208 if (pushed_by_player && IS_PLAYER(x, y))
6210 /* special case: moving object pushed by player */
6211 MovPos[x][y] = SIGN(MovPos[x][y]) * (TILEX - ABS(PLAYERINFO(x,y)->MovPos));
6214 if (pushed_by_player) /* special case: moving object pushed by player */
6215 MovPos[x][y] = SIGN(MovPos[x][y]) * (TILEX - ABS(PLAYERINFO(x,y)->MovPos));
6218 if (ABS(MovPos[x][y]) < TILEX)
6220 DrawLevelField(x, y);
6222 return; /* element is still moving */
6225 /* element reached destination field */
6227 Feld[x][y] = EL_EMPTY;
6228 Feld[newx][newy] = element;
6229 MovPos[x][y] = 0; /* force "not moving" for "crumbled sand" */
6232 if (Store[x][y] == EL_ACID) /* element is moving into acid pool */
6234 element = Feld[newx][newy] = EL_ACID;
6237 else if (element == EL_MOLE)
6239 Feld[x][y] = EL_SAND;
6241 DrawLevelFieldCrumbledSandNeighbours(x, y);
6243 else if (element == EL_QUICKSAND_FILLING)
6245 element = Feld[newx][newy] = get_next_element(element);
6246 Store[newx][newy] = Store[x][y];
6248 else if (element == EL_QUICKSAND_EMPTYING)
6250 Feld[x][y] = get_next_element(element);
6251 element = Feld[newx][newy] = Store[x][y];
6253 else if (element == EL_MAGIC_WALL_FILLING)
6255 element = Feld[newx][newy] = get_next_element(element);
6256 if (!game.magic_wall_active)
6257 element = Feld[newx][newy] = EL_MAGIC_WALL_DEAD;
6258 Store[newx][newy] = Store[x][y];
6260 else if (element == EL_MAGIC_WALL_EMPTYING)
6262 Feld[x][y] = get_next_element(element);
6263 if (!game.magic_wall_active)
6264 Feld[x][y] = EL_MAGIC_WALL_DEAD;
6265 element = Feld[newx][newy] = Store[x][y];
6267 else if (element == EL_BD_MAGIC_WALL_FILLING)
6269 element = Feld[newx][newy] = get_next_element(element);
6270 if (!game.magic_wall_active)
6271 element = Feld[newx][newy] = EL_BD_MAGIC_WALL_DEAD;
6272 Store[newx][newy] = Store[x][y];
6274 else if (element == EL_BD_MAGIC_WALL_EMPTYING)
6276 Feld[x][y] = get_next_element(element);
6277 if (!game.magic_wall_active)
6278 Feld[x][y] = EL_BD_MAGIC_WALL_DEAD;
6279 element = Feld[newx][newy] = Store[x][y];
6281 else if (element == EL_AMOEBA_DROPPING)
6283 Feld[x][y] = get_next_element(element);
6284 element = Feld[newx][newy] = Store[x][y];
6286 else if (element == EL_SOKOBAN_OBJECT)
6289 Feld[x][y] = Back[x][y];
6291 if (Back[newx][newy])
6292 Feld[newx][newy] = EL_SOKOBAN_FIELD_FULL;
6294 Back[x][y] = Back[newx][newy] = 0;
6297 else if (Store[x][y] == EL_ACID)
6299 element = Feld[newx][newy] = EL_ACID;
6303 else if (IS_CUSTOM_ELEMENT(element) && !IS_PLAYER(x, y) &&
6304 ei->move_leave_element != EL_EMPTY &&
6305 (ei->move_leave_type == LEAVE_TYPE_UNLIMITED ||
6306 Store[x][y] != EL_EMPTY))
6308 /* some elements can leave other elements behind after moving */
6310 Feld[x][y] = ei->move_leave_element;
6311 InitField(x, y, FALSE);
6313 if (GFX_CRUMBLED(Feld[x][y]))
6314 DrawLevelFieldCrumbledSandNeighbours(x, y);
6318 Store[x][y] = EL_EMPTY;
6319 MovPos[x][y] = MovDir[x][y] = MovDelay[x][y] = 0;
6320 MovDelay[newx][newy] = 0;
6322 if (CAN_CHANGE(element))
6324 /* copy element change control values to new field */
6325 ChangeDelay[newx][newy] = ChangeDelay[x][y];
6326 ChangePage[newx][newy] = ChangePage[x][y];
6327 Changed[newx][newy] = Changed[x][y];
6328 ChangeEvent[newx][newy] = ChangeEvent[x][y];
6331 ChangeDelay[x][y] = 0;
6332 ChangePage[x][y] = -1;
6333 Changed[x][y] = CE_BITMASK_DEFAULT;
6334 ChangeEvent[x][y] = CE_BITMASK_DEFAULT;
6336 /* copy animation control values to new field */
6337 GfxFrame[newx][newy] = GfxFrame[x][y];
6338 GfxRandom[newx][newy] = GfxRandom[x][y]; /* keep same random value */
6339 GfxAction[newx][newy] = GfxAction[x][y]; /* keep action one frame */
6340 GfxDir[newx][newy] = GfxDir[x][y]; /* keep element direction */
6342 Pushed[x][y] = Pushed[newx][newy] = FALSE;
6344 ResetGfxAnimation(x, y); /* reset animation values for old field */
6347 /* some elements can leave other elements behind after moving */
6349 if (IS_CUSTOM_ELEMENT(element) && ei->move_leave_element != EL_EMPTY &&
6350 (ei->move_leave_type == LEAVE_TYPE_UNLIMITED || stored != EL_EMPTY) &&
6351 (!IS_PLAYER(x, y) || IS_WALKABLE(ei->move_leave_element)))
6353 if (IS_CUSTOM_ELEMENT(element) && ei->move_leave_element != EL_EMPTY &&
6354 (ei->move_leave_type == LEAVE_TYPE_UNLIMITED || stored != EL_EMPTY) &&
6358 int move_leave_element = ei->move_leave_element;
6360 Feld[x][y] = move_leave_element;
6361 InitField(x, y, FALSE);
6363 if (GFX_CRUMBLED(Feld[x][y]))
6364 DrawLevelFieldCrumbledSandNeighbours(x, y);
6366 if (ELEM_IS_PLAYER(move_leave_element))
6367 RelocatePlayer(x, y, move_leave_element);
6372 /* some elements can leave other elements behind after moving */
6373 if (IS_CUSTOM_ELEMENT(element) && !IS_PLAYER(x, y) &&
6374 ei->move_leave_element != EL_EMPTY &&
6375 (ei->move_leave_type == LEAVE_TYPE_UNLIMITED ||
6376 ei->can_leave_element_last))
6378 Feld[x][y] = ei->move_leave_element;
6379 InitField(x, y, FALSE);
6381 if (GFX_CRUMBLED(Feld[x][y]))
6382 DrawLevelFieldCrumbledSandNeighbours(x, y);
6385 ei->can_leave_element_last = ei->can_leave_element;
6386 ei->can_leave_element = FALSE;
6390 /* 2.1.1 (does not work correctly for spring) */
6391 if (!CAN_MOVE(element))
6392 MovDir[newx][newy] = 0;
6396 /* (does not work for falling objects that slide horizontally) */
6397 if (CAN_FALL(element) && MovDir[newx][newy] == MV_DOWN)
6398 MovDir[newx][newy] = 0;
6401 if (!CAN_MOVE(element) ||
6402 (element == EL_SPRING && MovDir[newx][newy] == MV_DOWN))
6403 MovDir[newx][newy] = 0;
6407 if (!CAN_MOVE(element) ||
6408 (CAN_FALL(element) && direction == MV_DOWN))
6409 GfxDir[x][y] = MovDir[newx][newy] = 0;
6411 if (!CAN_MOVE(element) ||
6412 (CAN_FALL(element) && direction == MV_DOWN &&
6413 (element == EL_SPRING ||
6414 element_info[element].move_pattern == MV_WHEN_PUSHED ||
6415 element_info[element].move_pattern == MV_WHEN_DROPPED)))
6416 GfxDir[x][y] = MovDir[newx][newy] = 0;
6422 DrawLevelField(x, y);
6423 DrawLevelField(newx, newy);
6425 Stop[newx][newy] = TRUE; /* ignore this element until the next frame */
6427 /* prevent pushed element from moving on in pushed direction */
6428 if (pushed_by_player && CAN_MOVE(element) &&
6429 element_info[element].move_pattern & MV_ANY_DIRECTION &&
6430 !(element_info[element].move_pattern & direction))
6431 TurnRound(newx, newy);
6434 /* prevent elements on conveyor belt from moving on in last direction */
6435 if (pushed_by_conveyor && CAN_FALL(element) &&
6436 direction & MV_HORIZONTAL)
6439 if (CAN_MOVE(element))
6440 InitMovDir(newx, newy);
6442 MovDir[newx][newy] = 0;
6444 MovDir[newx][newy] = 0;
6449 if (!pushed_by_player)
6451 int nextx = newx + dx, nexty = newy + dy;
6452 boolean check_collision_again = IN_LEV_FIELD_AND_IS_FREE(nextx, nexty);
6454 WasJustMoving[newx][newy] = 3;
6456 if (CAN_FALL(element) && direction == MV_DOWN)
6457 WasJustFalling[newx][newy] = 3;
6459 if ((!CAN_FALL(element) || direction == MV_DOWN) && check_collision_again)
6460 CheckCollision[newx][newy] = 2;
6463 if (DONT_TOUCH(element)) /* object may be nasty to player or others */
6465 TestIfBadThingTouchesHero(newx, newy);
6466 TestIfBadThingTouchesFriend(newx, newy);
6468 if (!IS_CUSTOM_ELEMENT(element))
6469 TestIfBadThingTouchesOtherBadThing(newx, newy);
6471 else if (element == EL_PENGUIN)
6472 TestIfFriendTouchesBadThing(newx, newy);
6474 #if USE_NEW_MOVE_STYLE
6476 if (CAN_FALL(element) && direction == MV_DOWN &&
6477 (newy == lev_fieldy - 1 || !IS_FREE(x, newy + 1)) &&
6478 IS_PLAYER(x, newy + 1))
6479 printf("::: we would now kill the player [%d]\n", FrameCounter);
6482 /* give the player one last chance (one more frame) to move away */
6483 if (CAN_FALL(element) && direction == MV_DOWN &&
6484 (newy == lev_fieldy - 1 || !IS_FREE(x, newy + 1)) &&
6485 (!IS_PLAYER(x, newy + 1) ||
6486 game.engine_version < VERSION_IDENT(3,1,1,0)))
6489 if (CAN_FALL(element) && direction == MV_DOWN &&
6490 (newy == lev_fieldy - 1 || !IS_FREE(x, newy + 1)))
6495 if (pushed_by_player)
6498 int dig_side = MV_DIR_OPPOSITE(direction);
6500 static int trigger_sides[4] =
6502 CH_SIDE_RIGHT, /* moving left */
6503 CH_SIDE_LEFT, /* moving right */
6504 CH_SIDE_BOTTOM, /* moving up */
6505 CH_SIDE_TOP, /* moving down */
6507 int dig_side = trigger_sides[MV_DIR_BIT(direction)];
6509 struct PlayerInfo *player = PLAYERINFO(x, y);
6511 CheckElementChangeByPlayer(newx, newy, element, CE_PUSHED_BY_PLAYER,
6512 player->index_bit, dig_side);
6513 CheckTriggeredElementChangeByPlayer(newx,newy,element,CE_OTHER_GETS_PUSHED,
6514 player->index_bit, dig_side);
6519 TestIfElementTouchesCustomElement(x, y); /* empty or new element */
6523 if (ChangePage[newx][newy] != -1) /* delayed change */
6524 ChangeElement(newx, newy, ChangePage[newx][newy]);
6529 TestIfElementHitsCustomElement(newx, newy, direction);
6533 if (!IN_LEV_FIELD(nextx, nexty) || !IS_FREE(nextx, nexty))
6535 int hitting_element = Feld[newx][newy];
6537 /* !!! fix side (direction) orientation here and elsewhere !!! */
6538 CheckElementChangeBySide(newx, newy, hitting_element, CE_HITTING_SOMETHING,
6542 if (IN_LEV_FIELD(nextx, nexty))
6544 int opposite_direction = MV_DIR_OPPOSITE(direction);
6545 int hitting_side = direction;
6546 int touched_side = opposite_direction;
6547 int touched_element = MovingOrBlocked2Element(nextx, nexty);
6548 boolean object_hit = (!IS_MOVING(nextx, nexty) ||
6549 MovDir[nextx][nexty] != direction ||
6550 ABS(MovPos[nextx][nexty]) <= TILEY / 2);
6556 CheckElementChangeBySide(nextx, nexty, touched_element,
6557 CE_HIT_BY_SOMETHING, opposite_direction);
6559 if (IS_CUSTOM_ELEMENT(hitting_element) &&
6560 HAS_ANY_CHANGE_EVENT(hitting_element, CE_OTHER_IS_HITTING))
6562 for (i = 0; i < element_info[hitting_element].num_change_pages; i++)
6564 struct ElementChangeInfo *change =
6565 &element_info[hitting_element].change_page[i];
6567 if (change->can_change &&
6568 change->events & CH_EVENT_BIT(CE_OTHER_IS_HITTING) &&
6569 change->trigger_side & touched_side &&
6570 change->trigger_element == touched_element)
6572 CheckElementChangeByPage(newx, newy, hitting_element,
6573 touched_element, CE_OTHER_IS_HITTING,i);
6579 if (IS_CUSTOM_ELEMENT(touched_element) &&
6580 HAS_ANY_CHANGE_EVENT(touched_element, CE_OTHER_GETS_HIT))
6582 for (i = 0; i < element_info[touched_element].num_change_pages; i++)
6584 struct ElementChangeInfo *change =
6585 &element_info[touched_element].change_page[i];
6587 if (change->can_change &&
6588 change->events & CH_EVENT_BIT(CE_OTHER_GETS_HIT) &&
6589 change->trigger_side & hitting_side &&
6590 change->trigger_element == hitting_element)
6592 CheckElementChangeByPage(nextx, nexty, touched_element,
6593 hitting_element, CE_OTHER_GETS_HIT, i);
6604 TestIfPlayerTouchesCustomElement(newx, newy);
6605 TestIfElementTouchesCustomElement(newx, newy);
6608 int AmoebeNachbarNr(int ax, int ay)
6611 int element = Feld[ax][ay];
6613 static int xy[4][2] =
6621 for (i = 0; i < NUM_DIRECTIONS; i++)
6623 int x = ax + xy[i][0];
6624 int y = ay + xy[i][1];
6626 if (!IN_LEV_FIELD(x, y))
6629 if (Feld[x][y] == element && AmoebaNr[x][y] > 0)
6630 group_nr = AmoebaNr[x][y];
6636 void AmoebenVereinigen(int ax, int ay)
6638 int i, x, y, xx, yy;
6639 int new_group_nr = AmoebaNr[ax][ay];
6640 static int xy[4][2] =
6648 if (new_group_nr == 0)
6651 for (i = 0; i < NUM_DIRECTIONS; i++)
6656 if (!IN_LEV_FIELD(x, y))
6659 if ((Feld[x][y] == EL_AMOEBA_FULL ||
6660 Feld[x][y] == EL_BD_AMOEBA ||
6661 Feld[x][y] == EL_AMOEBA_DEAD) &&
6662 AmoebaNr[x][y] != new_group_nr)
6664 int old_group_nr = AmoebaNr[x][y];
6666 if (old_group_nr == 0)
6669 AmoebaCnt[new_group_nr] += AmoebaCnt[old_group_nr];
6670 AmoebaCnt[old_group_nr] = 0;
6671 AmoebaCnt2[new_group_nr] += AmoebaCnt2[old_group_nr];
6672 AmoebaCnt2[old_group_nr] = 0;
6674 for (yy = 0; yy < lev_fieldy; yy++)
6676 for (xx = 0; xx < lev_fieldx; xx++)
6678 if (AmoebaNr[xx][yy] == old_group_nr)
6679 AmoebaNr[xx][yy] = new_group_nr;
6686 void AmoebeUmwandeln(int ax, int ay)
6690 if (Feld[ax][ay] == EL_AMOEBA_DEAD)
6692 int group_nr = AmoebaNr[ax][ay];
6697 printf("AmoebeUmwandeln(): ax = %d, ay = %d\n", ax, ay);
6698 printf("AmoebeUmwandeln(): This should never happen!\n");
6703 for (y = 0; y < lev_fieldy; y++)
6705 for (x = 0; x < lev_fieldx; x++)
6707 if (Feld[x][y] == EL_AMOEBA_DEAD && AmoebaNr[x][y] == group_nr)
6710 Feld[x][y] = EL_AMOEBA_TO_DIAMOND;
6714 PlayLevelSound(ax, ay, (IS_GEM(level.amoeba_content) ?
6715 SND_AMOEBA_TURNING_TO_GEM :
6716 SND_AMOEBA_TURNING_TO_ROCK));
6721 static int xy[4][2] =
6729 for (i = 0; i < NUM_DIRECTIONS; i++)
6734 if (!IN_LEV_FIELD(x, y))
6737 if (Feld[x][y] == EL_AMOEBA_TO_DIAMOND)
6739 PlayLevelSound(x, y, (IS_GEM(level.amoeba_content) ?
6740 SND_AMOEBA_TURNING_TO_GEM :
6741 SND_AMOEBA_TURNING_TO_ROCK));
6748 void AmoebeUmwandelnBD(int ax, int ay, int new_element)
6751 int group_nr = AmoebaNr[ax][ay];
6752 boolean done = FALSE;
6757 printf("AmoebeUmwandelnBD(): ax = %d, ay = %d\n", ax, ay);
6758 printf("AmoebeUmwandelnBD(): This should never happen!\n");
6763 for (y = 0; y < lev_fieldy; y++)
6765 for (x = 0; x < lev_fieldx; x++)
6767 if (AmoebaNr[x][y] == group_nr &&
6768 (Feld[x][y] == EL_AMOEBA_DEAD ||
6769 Feld[x][y] == EL_BD_AMOEBA ||
6770 Feld[x][y] == EL_AMOEBA_GROWING))
6773 Feld[x][y] = new_element;
6774 InitField(x, y, FALSE);
6775 DrawLevelField(x, y);
6782 PlayLevelSound(ax, ay, (new_element == EL_BD_ROCK ?
6783 SND_BD_AMOEBA_TURNING_TO_ROCK :
6784 SND_BD_AMOEBA_TURNING_TO_GEM));
6787 void AmoebeWaechst(int x, int y)
6789 static unsigned long sound_delay = 0;
6790 static unsigned long sound_delay_value = 0;
6792 if (!MovDelay[x][y]) /* start new growing cycle */
6796 if (DelayReached(&sound_delay, sound_delay_value))
6799 PlayLevelSoundElementAction(x, y, Store[x][y], ACTION_GROWING);
6801 if (Store[x][y] == EL_BD_AMOEBA)
6802 PlayLevelSound(x, y, SND_BD_AMOEBA_GROWING);
6804 PlayLevelSound(x, y, SND_AMOEBA_GROWING);
6806 sound_delay_value = 30;
6810 if (MovDelay[x][y]) /* wait some time before growing bigger */
6813 if (MovDelay[x][y]/2 && IN_SCR_FIELD(SCREENX(x), SCREENY(y)))
6815 int frame = getGraphicAnimationFrame(IMG_AMOEBA_GROWING,
6816 6 - MovDelay[x][y]);
6818 DrawGraphic(SCREENX(x), SCREENY(y), IMG_AMOEBA_GROWING, frame);
6821 if (!MovDelay[x][y])
6823 Feld[x][y] = Store[x][y];
6825 DrawLevelField(x, y);
6830 void AmoebaDisappearing(int x, int y)
6832 static unsigned long sound_delay = 0;
6833 static unsigned long sound_delay_value = 0;
6835 if (!MovDelay[x][y]) /* start new shrinking cycle */
6839 if (DelayReached(&sound_delay, sound_delay_value))
6840 sound_delay_value = 30;
6843 if (MovDelay[x][y]) /* wait some time before shrinking */
6846 if (MovDelay[x][y]/2 && IN_SCR_FIELD(SCREENX(x), SCREENY(y)))
6848 int frame = getGraphicAnimationFrame(IMG_AMOEBA_SHRINKING,
6849 6 - MovDelay[x][y]);
6851 DrawGraphic(SCREENX(x), SCREENY(y), IMG_AMOEBA_SHRINKING, frame);
6854 if (!MovDelay[x][y])
6856 Feld[x][y] = EL_EMPTY;
6857 DrawLevelField(x, y);
6859 /* don't let mole enter this field in this cycle;
6860 (give priority to objects falling to this field from above) */
6866 void AmoebeAbleger(int ax, int ay)
6869 int element = Feld[ax][ay];
6870 int graphic = el2img(element);
6871 int newax = ax, neway = ay;
6872 static int xy[4][2] =
6880 if (!level.amoeba_speed)
6882 Feld[ax][ay] = EL_AMOEBA_DEAD;
6883 DrawLevelField(ax, ay);
6887 if (IS_ANIMATED(graphic))
6888 DrawLevelGraphicAnimationIfNeeded(ax, ay, graphic);
6890 if (!MovDelay[ax][ay]) /* start making new amoeba field */
6891 MovDelay[ax][ay] = RND(FRAMES_PER_SECOND * 25 / (1 + level.amoeba_speed));
6893 if (MovDelay[ax][ay]) /* wait some time before making new amoeba */
6896 if (MovDelay[ax][ay])
6900 if (element == EL_AMOEBA_WET) /* object is an acid / amoeba drop */
6903 int x = ax + xy[start][0];
6904 int y = ay + xy[start][1];
6906 if (!IN_LEV_FIELD(x, y))
6910 if (IS_FREE(x, y) ||
6911 CAN_GROW_INTO(Feld[x][y]) ||
6912 Feld[x][y] == EL_QUICKSAND_EMPTY)
6918 /* !!! extend EL_SAND to anything diggable (but maybe not SP_BASE) !!! */
6919 if (IS_FREE(x, y) ||
6920 Feld[x][y] == EL_SAND || Feld[x][y] == EL_QUICKSAND_EMPTY)
6927 if (newax == ax && neway == ay)
6930 else /* normal or "filled" (BD style) amoeba */
6933 boolean waiting_for_player = FALSE;
6935 for (i = 0; i < NUM_DIRECTIONS; i++)
6937 int j = (start + i) % 4;
6938 int x = ax + xy[j][0];
6939 int y = ay + xy[j][1];
6941 if (!IN_LEV_FIELD(x, y))
6945 if (IS_FREE(x, y) ||
6946 CAN_GROW_INTO(Feld[x][y]) ||
6947 Feld[x][y] == EL_QUICKSAND_EMPTY)
6954 /* !!! extend EL_SAND to anything diggable (but maybe not SP_BASE) !!! */
6955 if (IS_FREE(x, y) ||
6956 Feld[x][y] == EL_SAND || Feld[x][y] == EL_QUICKSAND_EMPTY)
6963 else if (IS_PLAYER(x, y))
6964 waiting_for_player = TRUE;
6967 if (newax == ax && neway == ay) /* amoeba cannot grow */
6970 if (i == 4 && (!waiting_for_player || element == EL_BD_AMOEBA))
6972 if (i == 4 && (!waiting_for_player || game.emulation == EMU_BOULDERDASH))
6975 Feld[ax][ay] = EL_AMOEBA_DEAD;
6976 DrawLevelField(ax, ay);
6977 AmoebaCnt[AmoebaNr[ax][ay]]--;
6979 if (AmoebaCnt[AmoebaNr[ax][ay]] <= 0) /* amoeba is completely dead */
6981 if (element == EL_AMOEBA_FULL)
6982 AmoebeUmwandeln(ax, ay);
6983 else if (element == EL_BD_AMOEBA)
6984 AmoebeUmwandelnBD(ax, ay, level.amoeba_content);
6989 else if (element == EL_AMOEBA_FULL || element == EL_BD_AMOEBA)
6991 /* amoeba gets larger by growing in some direction */
6993 int new_group_nr = AmoebaNr[ax][ay];
6996 if (new_group_nr == 0)
6998 printf("AmoebeAbleger(): newax = %d, neway = %d\n", newax, neway);
6999 printf("AmoebeAbleger(): This should never happen!\n");
7004 AmoebaNr[newax][neway] = new_group_nr;
7005 AmoebaCnt[new_group_nr]++;
7006 AmoebaCnt2[new_group_nr]++;
7008 /* if amoeba touches other amoeba(s) after growing, unify them */
7009 AmoebenVereinigen(newax, neway);
7011 if (element == EL_BD_AMOEBA && AmoebaCnt2[new_group_nr] >= 200)
7013 AmoebeUmwandelnBD(newax, neway, EL_BD_ROCK);
7019 if (element != EL_AMOEBA_WET || neway < ay || !IS_FREE(newax, neway) ||
7020 (neway == lev_fieldy - 1 && newax != ax))
7022 Feld[newax][neway] = EL_AMOEBA_GROWING; /* creation of new amoeba */
7023 Store[newax][neway] = element;
7025 else if (neway == ay)
7027 Feld[newax][neway] = EL_AMOEBA_DROP; /* drop left/right of amoeba */
7029 PlayLevelSoundAction(newax, neway, ACTION_GROWING);
7031 PlayLevelSound(newax, neway, SND_AMOEBA_GROWING);
7036 InitMovingField(ax, ay, MV_DOWN); /* drop dripping from amoeba */
7037 Feld[ax][ay] = EL_AMOEBA_DROPPING;
7038 Store[ax][ay] = EL_AMOEBA_DROP;
7039 ContinueMoving(ax, ay);
7043 DrawLevelField(newax, neway);
7046 void Life(int ax, int ay)
7049 static int life[4] = { 2, 3, 3, 3 }; /* parameters for "game of life" */
7051 int element = Feld[ax][ay];
7052 int graphic = el2img(element);
7053 boolean changed = FALSE;
7055 if (IS_ANIMATED(graphic))
7056 DrawLevelGraphicAnimationIfNeeded(ax, ay, graphic);
7061 if (!MovDelay[ax][ay]) /* start new "game of life" cycle */
7062 MovDelay[ax][ay] = life_time;
7064 if (MovDelay[ax][ay]) /* wait some time before next cycle */
7067 if (MovDelay[ax][ay])
7071 for (y1 = -1; y1 < 2; y1++) for (x1 = -1; x1 < 2; x1++)
7073 int xx = ax+x1, yy = ay+y1;
7076 if (!IN_LEV_FIELD(xx, yy))
7079 for (y2 = -1; y2 < 2; y2++) for (x2 = -1; x2 < 2; x2++)
7081 int x = xx+x2, y = yy+y2;
7083 if (!IN_LEV_FIELD(x, y) || (x == xx && y == yy))
7086 if (((Feld[x][y] == element ||
7087 (element == EL_GAME_OF_LIFE && IS_PLAYER(x, y))) &&
7089 (IS_FREE(x, y) && Stop[x][y]))
7093 if (xx == ax && yy == ay) /* field in the middle */
7095 if (nachbarn < life[0] || nachbarn > life[1])
7097 Feld[xx][yy] = EL_EMPTY;
7099 DrawLevelField(xx, yy);
7100 Stop[xx][yy] = TRUE;
7105 else if (IS_FREE(xx, yy) || CAN_GROW_INTO(Feld[xx][yy]))
7106 { /* free border field */
7107 if (nachbarn >= life[2] && nachbarn <= life[3])
7109 Feld[xx][yy] = element;
7110 MovDelay[xx][yy] = (element == EL_GAME_OF_LIFE ? 0 : life_time-1);
7112 DrawLevelField(xx, yy);
7113 Stop[xx][yy] = TRUE;
7118 /* !!! extend EL_SAND to anything diggable (but maybe not SP_BASE) !!! */
7119 else if (IS_FREE(xx, yy) || Feld[xx][yy] == EL_SAND)
7120 { /* free border field */
7121 if (nachbarn >= life[2] && nachbarn <= life[3])
7123 Feld[xx][yy] = element;
7124 MovDelay[xx][yy] = (element == EL_GAME_OF_LIFE ? 0 : life_time-1);
7126 DrawLevelField(xx, yy);
7127 Stop[xx][yy] = TRUE;
7135 PlayLevelSound(ax, ay, element == EL_BIOMAZE ? SND_BIOMAZE_GROWING :
7136 SND_GAME_OF_LIFE_GROWING);
7139 static void InitRobotWheel(int x, int y)
7141 ChangeDelay[x][y] = level.time_wheel * FRAMES_PER_SECOND;
7144 static void RunRobotWheel(int x, int y)
7146 PlayLevelSound(x, y, SND_ROBOT_WHEEL_ACTIVE);
7149 static void StopRobotWheel(int x, int y)
7151 if (ZX == x && ZY == y)
7155 static void InitTimegateWheel(int x, int y)
7158 ChangeDelay[x][y] = level.time_timegate * FRAMES_PER_SECOND;
7160 /* another brainless, "type style" bug ... :-( */
7161 ChangeDelay[x][y] = level.time_wheel * FRAMES_PER_SECOND;
7165 static void RunTimegateWheel(int x, int y)
7167 PlayLevelSound(x, y, SND_TIMEGATE_SWITCH_ACTIVE);
7170 void CheckExit(int x, int y)
7172 if (local_player->gems_still_needed > 0 ||
7173 local_player->sokobanfields_still_needed > 0 ||
7174 local_player->lights_still_needed > 0)
7176 int element = Feld[x][y];
7177 int graphic = el2img(element);
7179 if (IS_ANIMATED(graphic))
7180 DrawLevelGraphicAnimationIfNeeded(x, y, graphic);
7185 if (AllPlayersGone) /* do not re-open exit door closed after last player */
7188 Feld[x][y] = EL_EXIT_OPENING;
7190 PlayLevelSoundNearest(x, y, SND_CLASS_EXIT_OPENING);
7193 void CheckExitSP(int x, int y)
7195 if (local_player->gems_still_needed > 0)
7197 int element = Feld[x][y];
7198 int graphic = el2img(element);
7200 if (IS_ANIMATED(graphic))
7201 DrawLevelGraphicAnimationIfNeeded(x, y, graphic);
7206 if (AllPlayersGone) /* do not re-open exit door closed after last player */
7209 Feld[x][y] = EL_SP_EXIT_OPENING;
7211 PlayLevelSoundNearest(x, y, SND_CLASS_SP_EXIT_OPENING);
7214 static void CloseAllOpenTimegates()
7218 for (y = 0; y < lev_fieldy; y++)
7220 for (x = 0; x < lev_fieldx; x++)
7222 int element = Feld[x][y];
7224 if (element == EL_TIMEGATE_OPEN || element == EL_TIMEGATE_OPENING)
7226 Feld[x][y] = EL_TIMEGATE_CLOSING;
7228 PlayLevelSoundAction(x, y, ACTION_CLOSING);
7230 PlayLevelSound(x, y, SND_TIMEGATE_CLOSING);
7237 void EdelsteinFunkeln(int x, int y)
7239 if (!IN_SCR_FIELD(SCREENX(x), SCREENY(y)) || IS_MOVING(x, y))
7242 if (Feld[x][y] == EL_BD_DIAMOND)
7245 if (MovDelay[x][y] == 0) /* next animation frame */
7246 MovDelay[x][y] = 11 * !SimpleRND(500);
7248 if (MovDelay[x][y] != 0) /* wait some time before next frame */
7252 if (setup.direct_draw && MovDelay[x][y])
7253 SetDrawtoField(DRAW_BUFFERED);
7255 DrawLevelElementAnimation(x, y, Feld[x][y]);
7257 if (MovDelay[x][y] != 0)
7259 int frame = getGraphicAnimationFrame(IMG_TWINKLE_WHITE,
7260 10 - MovDelay[x][y]);
7262 DrawGraphicThruMask(SCREENX(x), SCREENY(y), IMG_TWINKLE_WHITE, frame);
7264 if (setup.direct_draw)
7268 dest_x = FX + SCREENX(x) * TILEX;
7269 dest_y = FY + SCREENY(y) * TILEY;
7271 BlitBitmap(drawto_field, window,
7272 dest_x, dest_y, TILEX, TILEY, dest_x, dest_y);
7273 SetDrawtoField(DRAW_DIRECT);
7279 void MauerWaechst(int x, int y)
7283 if (!MovDelay[x][y]) /* next animation frame */
7284 MovDelay[x][y] = 3 * delay;
7286 if (MovDelay[x][y]) /* wait some time before next frame */
7290 if (IN_SCR_FIELD(SCREENX(x), SCREENY(y)))
7292 int graphic = el_dir2img(Feld[x][y], GfxDir[x][y]);
7293 int frame = getGraphicAnimationFrame(graphic, 17 - MovDelay[x][y]);
7295 DrawGraphic(SCREENX(x), SCREENY(y), graphic, frame);
7298 if (!MovDelay[x][y])
7300 if (MovDir[x][y] == MV_LEFT)
7302 if (IN_LEV_FIELD(x - 1, y) && IS_WALL(Feld[x - 1][y]))
7303 DrawLevelField(x - 1, y);
7305 else if (MovDir[x][y] == MV_RIGHT)
7307 if (IN_LEV_FIELD(x + 1, y) && IS_WALL(Feld[x + 1][y]))
7308 DrawLevelField(x + 1, y);
7310 else if (MovDir[x][y] == MV_UP)
7312 if (IN_LEV_FIELD(x, y - 1) && IS_WALL(Feld[x][y - 1]))
7313 DrawLevelField(x, y - 1);
7317 if (IN_LEV_FIELD(x, y + 1) && IS_WALL(Feld[x][y + 1]))
7318 DrawLevelField(x, y + 1);
7321 Feld[x][y] = Store[x][y];
7323 GfxDir[x][y] = MovDir[x][y] = MV_NO_MOVING;
7324 DrawLevelField(x, y);
7329 void MauerAbleger(int ax, int ay)
7331 int element = Feld[ax][ay];
7332 int graphic = el2img(element);
7333 boolean oben_frei = FALSE, unten_frei = FALSE;
7334 boolean links_frei = FALSE, rechts_frei = FALSE;
7335 boolean oben_massiv = FALSE, unten_massiv = FALSE;
7336 boolean links_massiv = FALSE, rechts_massiv = FALSE;
7337 boolean new_wall = FALSE;
7339 if (IS_ANIMATED(graphic))
7340 DrawLevelGraphicAnimationIfNeeded(ax, ay, graphic);
7342 if (!MovDelay[ax][ay]) /* start building new wall */
7343 MovDelay[ax][ay] = 6;
7345 if (MovDelay[ax][ay]) /* wait some time before building new wall */
7348 if (MovDelay[ax][ay])
7352 if (IN_LEV_FIELD(ax, ay-1) && IS_FREE(ax, ay-1))
7354 if (IN_LEV_FIELD(ax, ay+1) && IS_FREE(ax, ay+1))
7356 if (IN_LEV_FIELD(ax-1, ay) && IS_FREE(ax-1, ay))
7358 if (IN_LEV_FIELD(ax+1, ay) && IS_FREE(ax+1, ay))
7361 if (element == EL_EXPANDABLE_WALL_VERTICAL ||
7362 element == EL_EXPANDABLE_WALL_ANY)
7366 Feld[ax][ay-1] = EL_EXPANDABLE_WALL_GROWING;
7367 Store[ax][ay-1] = element;
7368 GfxDir[ax][ay-1] = MovDir[ax][ay-1] = MV_UP;
7369 if (IN_SCR_FIELD(SCREENX(ax), SCREENY(ay-1)))
7370 DrawGraphic(SCREENX(ax), SCREENY(ay - 1),
7371 IMG_EXPANDABLE_WALL_GROWING_UP, 0);
7376 Feld[ax][ay+1] = EL_EXPANDABLE_WALL_GROWING;
7377 Store[ax][ay+1] = element;
7378 GfxDir[ax][ay+1] = MovDir[ax][ay+1] = MV_DOWN;
7379 if (IN_SCR_FIELD(SCREENX(ax), SCREENY(ay+1)))
7380 DrawGraphic(SCREENX(ax), SCREENY(ay + 1),
7381 IMG_EXPANDABLE_WALL_GROWING_DOWN, 0);
7386 if (element == EL_EXPANDABLE_WALL_HORIZONTAL ||
7387 element == EL_EXPANDABLE_WALL_ANY ||
7388 element == EL_EXPANDABLE_WALL)
7392 Feld[ax-1][ay] = EL_EXPANDABLE_WALL_GROWING;
7393 Store[ax-1][ay] = element;
7394 GfxDir[ax-1][ay] = MovDir[ax-1][ay] = MV_LEFT;
7395 if (IN_SCR_FIELD(SCREENX(ax-1), SCREENY(ay)))
7396 DrawGraphic(SCREENX(ax - 1), SCREENY(ay),
7397 IMG_EXPANDABLE_WALL_GROWING_LEFT, 0);
7403 Feld[ax+1][ay] = EL_EXPANDABLE_WALL_GROWING;
7404 Store[ax+1][ay] = element;
7405 GfxDir[ax+1][ay] = MovDir[ax+1][ay] = MV_RIGHT;
7406 if (IN_SCR_FIELD(SCREENX(ax+1), SCREENY(ay)))
7407 DrawGraphic(SCREENX(ax + 1), SCREENY(ay),
7408 IMG_EXPANDABLE_WALL_GROWING_RIGHT, 0);
7413 if (element == EL_EXPANDABLE_WALL && (links_frei || rechts_frei))
7414 DrawLevelField(ax, ay);
7416 if (!IN_LEV_FIELD(ax, ay-1) || IS_WALL(Feld[ax][ay-1]))
7418 if (!IN_LEV_FIELD(ax, ay+1) || IS_WALL(Feld[ax][ay+1]))
7419 unten_massiv = TRUE;
7420 if (!IN_LEV_FIELD(ax-1, ay) || IS_WALL(Feld[ax-1][ay]))
7421 links_massiv = TRUE;
7422 if (!IN_LEV_FIELD(ax+1, ay) || IS_WALL(Feld[ax+1][ay]))
7423 rechts_massiv = TRUE;
7425 if (((oben_massiv && unten_massiv) ||
7426 element == EL_EXPANDABLE_WALL_HORIZONTAL ||
7427 element == EL_EXPANDABLE_WALL) &&
7428 ((links_massiv && rechts_massiv) ||
7429 element == EL_EXPANDABLE_WALL_VERTICAL))
7430 Feld[ax][ay] = EL_WALL;
7434 PlayLevelSoundAction(ax, ay, ACTION_GROWING);
7436 PlayLevelSound(ax, ay, SND_EXPANDABLE_WALL_GROWING);
7440 void CheckForDragon(int x, int y)
7443 boolean dragon_found = FALSE;
7444 static int xy[4][2] =
7452 for (i = 0; i < NUM_DIRECTIONS; i++)
7454 for (j = 0; j < 4; j++)
7456 int xx = x + j * xy[i][0], yy = y + j * xy[i][1];
7458 if (IN_LEV_FIELD(xx, yy) &&
7459 (Feld[xx][yy] == EL_FLAMES || Feld[xx][yy] == EL_DRAGON))
7461 if (Feld[xx][yy] == EL_DRAGON)
7462 dragon_found = TRUE;
7471 for (i = 0; i < NUM_DIRECTIONS; i++)
7473 for (j = 0; j < 3; j++)
7475 int xx = x + j * xy[i][0], yy = y + j * xy[i][1];
7477 if (IN_LEV_FIELD(xx, yy) && Feld[xx][yy] == EL_FLAMES)
7479 Feld[xx][yy] = EL_EMPTY;
7480 DrawLevelField(xx, yy);
7489 static void InitBuggyBase(int x, int y)
7491 int element = Feld[x][y];
7492 int activating_delay = FRAMES_PER_SECOND / 4;
7495 (element == EL_SP_BUGGY_BASE ?
7496 2 * FRAMES_PER_SECOND + RND(5 * FRAMES_PER_SECOND) - activating_delay :
7497 element == EL_SP_BUGGY_BASE_ACTIVATING ?
7499 element == EL_SP_BUGGY_BASE_ACTIVE ?
7500 1 * FRAMES_PER_SECOND + RND(1 * FRAMES_PER_SECOND) : 1);
7503 static void WarnBuggyBase(int x, int y)
7506 static int xy[4][2] =
7514 for (i = 0; i < NUM_DIRECTIONS; i++)
7516 int xx = x + xy[i][0], yy = y + xy[i][1];
7518 if (IS_PLAYER(xx, yy))
7520 PlayLevelSound(x, y, SND_SP_BUGGY_BASE_ACTIVE);
7527 static void InitTrap(int x, int y)
7529 ChangeDelay[x][y] = 2 * FRAMES_PER_SECOND + RND(5 * FRAMES_PER_SECOND);
7532 static void ActivateTrap(int x, int y)
7534 PlayLevelSound(x, y, SND_TRAP_ACTIVATING);
7537 static void ChangeActiveTrap(int x, int y)
7539 int graphic = IMG_TRAP_ACTIVE;
7541 /* if new animation frame was drawn, correct crumbled sand border */
7542 if (IS_NEW_FRAME(GfxFrame[x][y], graphic))
7543 DrawLevelFieldCrumbledSand(x, y);
7546 static void ChangeElementNowExt(int x, int y, int target_element)
7548 int previous_move_direction = MovDir[x][y];
7550 boolean add_player = (ELEM_IS_PLAYER(target_element) &&
7551 IS_WALKABLE(Feld[x][y]));
7553 boolean add_player = (ELEM_IS_PLAYER(target_element) &&
7554 IS_WALKABLE(Feld[x][y]) &&
7558 /* check if element under player changes from accessible to unaccessible
7559 (needed for special case of dropping element which then changes) */
7560 if (IS_PLAYER(x, y) && !PLAYER_EXPLOSION_PROTECTED(x, y) &&
7561 IS_ACCESSIBLE(Feld[x][y]) && !IS_ACCESSIBLE(target_element))
7564 printf("::: BOOOM! [%d, '%s']\n", target_element,
7565 element_info[target_element].token_name);
7577 if (IS_MOVING(x, y) || IS_BLOCKED(x, y))
7578 RemoveMovingField(x, y);
7582 Feld[x][y] = target_element;
7585 Feld[x][y] = target_element;
7588 ResetGfxAnimation(x, y);
7589 ResetRandomAnimationValue(x, y);
7591 if (element_info[Feld[x][y]].move_direction_initial == MV_START_PREVIOUS)
7592 MovDir[x][y] = previous_move_direction;
7595 InitField_WithBug1(x, y, FALSE);
7597 InitField(x, y, FALSE);
7598 if (CAN_MOVE(Feld[x][y]))
7602 DrawLevelField(x, y);
7604 if (GFX_CRUMBLED(Feld[x][y]))
7605 DrawLevelFieldCrumbledSandNeighbours(x, y);
7609 Changed[x][y] |= ChangeEvent[x][y]; /* ignore same changes in this frame */
7613 TestIfBadThingTouchesHero(x, y);
7614 TestIfPlayerTouchesCustomElement(x, y);
7615 TestIfElementTouchesCustomElement(x, y);
7618 /* "Changed[][]" not set yet to allow "entered by player" change one time */
7619 if (ELEM_IS_PLAYER(target_element))
7620 RelocatePlayer(x, y, target_element);
7623 Changed[x][y] |= ChangeEvent[x][y]; /* ignore same changes in this frame */
7627 TestIfBadThingTouchesHero(x, y);
7628 TestIfPlayerTouchesCustomElement(x, y);
7629 TestIfElementTouchesCustomElement(x, y);
7633 static boolean ChangeElementNow(int x, int y, int element, int page)
7635 struct ElementChangeInfo *change = &element_info[element].change_page[page];
7637 int old_element = Feld[x][y];
7639 /* always use default change event to prevent running into a loop */
7640 if (ChangeEvent[x][y] == CE_BITMASK_DEFAULT)
7641 ChangeEvent[x][y] = CH_EVENT_BIT(CE_DELAY);
7643 if (ChangeEvent[x][y] == CH_EVENT_BIT(CE_DELAY))
7645 /* reset actual trigger element and player */
7646 change->actual_trigger_element = EL_EMPTY;
7647 change->actual_trigger_player = EL_PLAYER_1;
7650 /* do not change already changed elements with same change event */
7652 if (Changed[x][y] & ChangeEvent[x][y])
7659 Changed[x][y] |= ChangeEvent[x][y]; /* ignore same changes in this frame */
7662 /* !!! indirect change before direct change !!! */
7663 CheckTriggeredElementChangeByPage(x,y,Feld[x][y], CE_OTHER_IS_CHANGING,page);
7666 if (change->explode)
7673 if (change->use_target_content)
7675 boolean complete_replace = TRUE;
7676 boolean can_replace[3][3];
7679 for (yy = 0; yy < 3; yy++) for (xx = 0; xx < 3 ; xx++)
7682 boolean is_walkable;
7683 boolean is_diggable;
7684 boolean is_collectible;
7685 boolean is_removable;
7686 boolean is_destructible;
7687 int ex = x + xx - 1;
7688 int ey = y + yy - 1;
7689 int content_element = change->target_content[xx][yy];
7692 can_replace[xx][yy] = TRUE;
7694 if (ex == x && ey == y) /* do not check changing element itself */
7697 if (content_element == EL_EMPTY_SPACE)
7699 can_replace[xx][yy] = FALSE; /* do not replace border with space */
7704 if (!IN_LEV_FIELD(ex, ey))
7706 can_replace[xx][yy] = FALSE;
7707 complete_replace = FALSE;
7713 if (Changed[ex][ey]) /* do not change already changed elements */
7715 can_replace[xx][yy] = FALSE;
7716 complete_replace = FALSE;
7724 if (IS_MOVING(ex, ey) || IS_BLOCKED(ex, ey))
7725 e = MovingOrBlocked2Element(ex, ey);
7730 is_empty = (IS_FREE(ex, ey) ||
7731 (IS_PLAYER(ex, ey) && IS_WALKABLE(content_element)) ||
7732 (IS_WALKABLE(e) && ELEM_IS_PLAYER(content_element) &&
7733 !IS_MOVING(ex, ey) && !IS_BLOCKED(ex, ey)));
7737 is_empty = (IS_FREE(ex, ey) ||
7738 (IS_PLAYER(ex, ey) && IS_WALKABLE(content_element)));
7740 is_empty = (IS_FREE(ex, ey) ||
7741 (IS_FREE_OR_PLAYER(ex, ey) && IS_WALKABLE(content_element)));
7746 is_walkable = (is_empty || IS_WALKABLE(e));
7747 is_diggable = (is_empty || IS_DIGGABLE(e));
7748 is_collectible = (is_empty || IS_COLLECTIBLE(e));
7749 is_destructible = (is_empty || !IS_INDESTRUCTIBLE(e));
7750 is_removable = (is_diggable || is_collectible);
7752 can_replace[xx][yy] =
7753 (((change->replace_when == CP_WHEN_EMPTY && is_empty) ||
7754 (change->replace_when == CP_WHEN_WALKABLE && is_walkable) ||
7755 (change->replace_when == CP_WHEN_DIGGABLE && is_diggable) ||
7756 (change->replace_when == CP_WHEN_COLLECTIBLE && is_collectible) ||
7757 (change->replace_when == CP_WHEN_REMOVABLE && is_removable) ||
7758 (change->replace_when == CP_WHEN_DESTRUCTIBLE && is_destructible)) &&
7759 !(IS_PLAYER(ex, ey) && ELEM_IS_PLAYER(content_element)));
7761 if (!can_replace[xx][yy])
7762 complete_replace = FALSE;
7764 empty_for_element = (IS_FREE(ex, ey) || (IS_FREE_OR_PLAYER(ex, ey) &&
7765 IS_WALKABLE(content_element)));
7767 half_destructible = (empty_for_element || IS_DIGGABLE(e));
7769 half_destructible = (IS_FREE(ex, ey) || IS_DIGGABLE(e));
7772 if ((change->replace_when <= CP_WHEN_EMPTY && !empty_for_element) ||
7773 (change->replace_when <= CP_WHEN_DIGGABLE && !half_destructible) ||
7774 (change->replace_when <= CP_WHEN_DESTRUCTIBLE && IS_INDESTRUCTIBLE(e)))
7776 can_replace[xx][yy] = FALSE;
7777 complete_replace = FALSE;
7782 if (!change->only_if_complete || complete_replace)
7784 boolean something_has_changed = FALSE;
7786 if (change->only_if_complete && change->use_random_replace &&
7787 RND(100) < change->random_percentage)
7790 for (yy = 0; yy < 3; yy++) for (xx = 0; xx < 3 ; xx++)
7792 int ex = x + xx - 1;
7793 int ey = y + yy - 1;
7794 int content_element;
7796 if (can_replace[xx][yy] && (!change->use_random_replace ||
7797 RND(100) < change->random_percentage))
7799 if (IS_MOVING(ex, ey) || IS_BLOCKED(ex, ey))
7800 RemoveMovingField(ex, ey);
7802 ChangeEvent[ex][ey] = ChangeEvent[x][y];
7804 content_element = change->target_content[xx][yy];
7805 target_element = GET_TARGET_ELEMENT(content_element, change);
7807 ChangeElementNowExt(ex, ey, target_element);
7809 something_has_changed = TRUE;
7811 /* for symmetry reasons, freeze newly created border elements */
7812 if (ex != x || ey != y)
7813 Stop[ex][ey] = TRUE; /* no more moving in this frame */
7817 if (something_has_changed)
7818 PlayLevelSoundElementAction(x, y, element, ACTION_CHANGING);
7823 target_element = GET_TARGET_ELEMENT(change->target_element, change);
7825 ChangeElementNowExt(x, y, target_element);
7827 PlayLevelSoundElementAction(x, y, element, ACTION_CHANGING);
7831 /* this uses direct change before indirect change */
7832 CheckTriggeredElementChangeByPage(x,y,old_element,CE_OTHER_IS_CHANGING,page);
7838 static void ChangeElement(int x, int y, int page)
7840 int element = MovingOrBlocked2Element(x, y);
7841 struct ElementInfo *ei = &element_info[element];
7842 struct ElementChangeInfo *change = &ei->change_page[page];
7845 if (!CAN_CHANGE(element) && !CAN_CHANGE(Back[x][y]))
7848 printf("ChangeElement(): %d,%d: element = %d ('%s')\n",
7849 x, y, element, element_info[element].token_name);
7850 printf("ChangeElement(): This should never happen!\n");
7855 /* this can happen with classic bombs on walkable, changing elements */
7856 if (!CAN_CHANGE(element))
7859 if (!CAN_CHANGE(Back[x][y])) /* prevent permanent repetition */
7860 ChangeDelay[x][y] = 0;
7866 if (ChangeDelay[x][y] == 0) /* initialize element change */
7868 ChangeDelay[x][y] = ( change->delay_fixed * change->delay_frames +
7869 RND(change->delay_random * change->delay_frames)) + 1;
7871 ResetGfxAnimation(x, y);
7872 ResetRandomAnimationValue(x, y);
7874 if (change->pre_change_function)
7875 change->pre_change_function(x, y);
7878 ChangeDelay[x][y]--;
7880 if (ChangeDelay[x][y] != 0) /* continue element change */
7882 int graphic = el_act_dir2img(element, GfxAction[x][y], GfxDir[x][y]);
7884 if (IS_ANIMATED(graphic))
7885 DrawLevelGraphicAnimationIfNeeded(x, y, graphic);
7887 if (change->change_function)
7888 change->change_function(x, y);
7890 else /* finish element change */
7892 if (ChangePage[x][y] != -1) /* remember page from delayed change */
7894 page = ChangePage[x][y];
7895 ChangePage[x][y] = -1;
7897 change = &ei->change_page[page];
7901 if (IS_MOVING(x, y) && !change->explode)
7903 if (IS_MOVING(x, y)) /* never change a running system ;-) */
7906 ChangeDelay[x][y] = 1; /* try change after next move step */
7907 ChangePage[x][y] = page; /* remember page to use for change */
7912 if (ChangeElementNow(x, y, element, page))
7914 if (change->post_change_function)
7915 change->post_change_function(x, y);
7920 static boolean CheckTriggeredElementChangeExt(int lx, int ly,
7921 int trigger_element,
7928 int trigger_page_bits = (trigger_page < 0 ? CH_PAGE_ANY : 1 << trigger_page);
7930 if (!(trigger_events[trigger_element] & CH_EVENT_BIT(trigger_event)))
7933 for (i = 0; i < NUM_CUSTOM_ELEMENTS; i++)
7935 int element = EL_CUSTOM_START + i;
7937 boolean change_element = FALSE;
7940 if (!CAN_CHANGE(element) || !HAS_ANY_CHANGE_EVENT(element, trigger_event))
7943 for (j = 0; j < element_info[element].num_change_pages; j++)
7945 struct ElementChangeInfo *change = &element_info[element].change_page[j];
7947 if (change->can_change &&
7948 change->events & CH_EVENT_BIT(trigger_event) &&
7949 change->trigger_side & trigger_side &&
7950 change->trigger_player & trigger_player &&
7951 change->trigger_page & trigger_page_bits &&
7952 IS_EQUAL_OR_IN_GROUP(trigger_element, change->trigger_element))
7955 if (!(change->events & CH_EVENT_BIT(trigger_event)))
7956 printf("::: !!! %d triggers %d: using wrong page %d [event %d]\n",
7957 trigger_element-EL_CUSTOM_START+1, i+1, j, trigger_event);
7960 change_element = TRUE;
7963 change->actual_trigger_element = trigger_element;
7964 change->actual_trigger_player = EL_PLAYER_1 + log_2(trigger_player);
7970 if (!change_element)
7973 for (y = 0; y < lev_fieldy; y++) for (x = 0; x < lev_fieldx; x++)
7976 if (x == lx && y == ly) /* do not change trigger element itself */
7980 if (Feld[x][y] == element)
7982 ChangeDelay[x][y] = 1;
7983 ChangeEvent[x][y] = CH_EVENT_BIT(trigger_event);
7984 ChangeElement(x, y, page);
7992 static boolean CheckElementChangeExt(int x, int y,
7994 int trigger_element,
8000 if (!CAN_CHANGE(element) || !HAS_ANY_CHANGE_EVENT(element, trigger_event))
8003 if (Feld[x][y] == EL_BLOCKED)
8005 Blocked2Moving(x, y, &x, &y);
8006 element = Feld[x][y];
8010 if (Feld[x][y] != element) /* check if element has already changed */
8013 printf("::: %d ('%s') != %d ('%s') [%d]\n",
8014 Feld[x][y], element_info[Feld[x][y]].token_name,
8015 element, element_info[element].token_name,
8024 if (trigger_page < 0)
8026 boolean change_element = FALSE;
8029 for (i = 0; i < element_info[element].num_change_pages; i++)
8031 struct ElementChangeInfo *change = &element_info[element].change_page[i];
8033 if (change->can_change &&
8034 change->events & CH_EVENT_BIT(trigger_event) &&
8035 change->trigger_side & trigger_side &&
8036 change->trigger_player & trigger_player)
8038 change_element = TRUE;
8041 change->actual_trigger_element = trigger_element;
8042 change->actual_trigger_player = EL_PLAYER_1 + log_2(trigger_player);
8048 if (!change_element)
8053 struct ElementInfo *ei = &element_info[element];
8054 struct ElementChangeInfo *change = &ei->change_page[trigger_page];
8056 change->actual_trigger_element = trigger_element;
8057 change->actual_trigger_player = EL_PLAYER_1; /* unused */
8062 /* !!! this check misses pages with same event, but different side !!! */
8064 if (trigger_page < 0)
8065 trigger_page = element_info[element].event_page_nr[trigger_event];
8067 if (!(element_info[element].change_page[trigger_page].trigger_side & trigger_side))
8071 ChangeDelay[x][y] = 1;
8072 ChangeEvent[x][y] = CH_EVENT_BIT(trigger_event);
8073 ChangeElement(x, y, trigger_page);
8078 static void PlayPlayerSound(struct PlayerInfo *player)
8080 int jx = player->jx, jy = player->jy;
8081 int element = player->element_nr;
8082 int last_action = player->last_action_waiting;
8083 int action = player->action_waiting;
8085 if (player->is_waiting)
8087 if (action != last_action)
8088 PlayLevelSoundElementAction(jx, jy, element, action);
8090 PlayLevelSoundElementActionIfLoop(jx, jy, element, action);
8094 if (action != last_action)
8095 StopSound(element_info[element].sound[last_action]);
8097 if (last_action == ACTION_SLEEPING)
8098 PlayLevelSoundElementAction(jx, jy, element, ACTION_AWAKENING);
8102 static void PlayAllPlayersSound()
8106 for (i = 0; i < MAX_PLAYERS; i++)
8107 if (stored_player[i].active)
8108 PlayPlayerSound(&stored_player[i]);
8111 static void SetPlayerWaiting(struct PlayerInfo *player, boolean is_waiting)
8113 boolean last_waiting = player->is_waiting;
8114 int move_dir = player->MovDir;
8116 player->last_action_waiting = player->action_waiting;
8120 if (!last_waiting) /* not waiting -> waiting */
8122 player->is_waiting = TRUE;
8124 player->frame_counter_bored =
8126 game.player_boring_delay_fixed +
8127 SimpleRND(game.player_boring_delay_random);
8128 player->frame_counter_sleeping =
8130 game.player_sleeping_delay_fixed +
8131 SimpleRND(game.player_sleeping_delay_random);
8133 InitPlayerGfxAnimation(player, ACTION_WAITING, player->MovDir);
8136 if (game.player_sleeping_delay_fixed +
8137 game.player_sleeping_delay_random > 0 &&
8138 player->anim_delay_counter == 0 &&
8139 player->post_delay_counter == 0 &&
8140 FrameCounter >= player->frame_counter_sleeping)
8141 player->is_sleeping = TRUE;
8142 else if (game.player_boring_delay_fixed +
8143 game.player_boring_delay_random > 0 &&
8144 FrameCounter >= player->frame_counter_bored)
8145 player->is_bored = TRUE;
8147 player->action_waiting = (player->is_sleeping ? ACTION_SLEEPING :
8148 player->is_bored ? ACTION_BORING :
8151 if (player->is_sleeping)
8153 if (player->num_special_action_sleeping > 0)
8155 if (player->anim_delay_counter == 0 && player->post_delay_counter == 0)
8157 int last_special_action = player->special_action_sleeping;
8158 int num_special_action = player->num_special_action_sleeping;
8159 int special_action =
8160 (last_special_action == ACTION_DEFAULT ? ACTION_SLEEPING_1 :
8161 last_special_action == ACTION_SLEEPING ? ACTION_SLEEPING :
8162 last_special_action < ACTION_SLEEPING_1 + num_special_action - 1 ?
8163 last_special_action + 1 : ACTION_SLEEPING);
8164 int special_graphic =
8165 el_act_dir2img(player->element_nr, special_action, move_dir);
8167 player->anim_delay_counter =
8168 graphic_info[special_graphic].anim_delay_fixed +
8169 SimpleRND(graphic_info[special_graphic].anim_delay_random);
8170 player->post_delay_counter =
8171 graphic_info[special_graphic].post_delay_fixed +
8172 SimpleRND(graphic_info[special_graphic].post_delay_random);
8174 player->special_action_sleeping = special_action;
8177 if (player->anim_delay_counter > 0)
8179 player->action_waiting = player->special_action_sleeping;
8180 player->anim_delay_counter--;
8182 else if (player->post_delay_counter > 0)
8184 player->post_delay_counter--;
8188 else if (player->is_bored)
8190 if (player->num_special_action_bored > 0)
8192 if (player->anim_delay_counter == 0 && player->post_delay_counter == 0)
8194 int special_action =
8195 ACTION_BORING_1 + SimpleRND(player->num_special_action_bored);
8196 int special_graphic =
8197 el_act_dir2img(player->element_nr, special_action, move_dir);
8199 player->anim_delay_counter =
8200 graphic_info[special_graphic].anim_delay_fixed +
8201 SimpleRND(graphic_info[special_graphic].anim_delay_random);
8202 player->post_delay_counter =
8203 graphic_info[special_graphic].post_delay_fixed +
8204 SimpleRND(graphic_info[special_graphic].post_delay_random);
8206 player->special_action_bored = special_action;
8209 if (player->anim_delay_counter > 0)
8211 player->action_waiting = player->special_action_bored;
8212 player->anim_delay_counter--;
8214 else if (player->post_delay_counter > 0)
8216 player->post_delay_counter--;
8221 else if (last_waiting) /* waiting -> not waiting */
8223 player->is_waiting = FALSE;
8224 player->is_bored = FALSE;
8225 player->is_sleeping = FALSE;
8227 player->frame_counter_bored = -1;
8228 player->frame_counter_sleeping = -1;
8230 player->anim_delay_counter = 0;
8231 player->post_delay_counter = 0;
8233 player->action_waiting = ACTION_DEFAULT;
8235 player->special_action_bored = ACTION_DEFAULT;
8236 player->special_action_sleeping = ACTION_DEFAULT;
8241 static byte PlayerActions(struct PlayerInfo *player, byte player_action)
8244 static byte stored_player_action[MAX_PLAYERS];
8245 static int num_stored_actions = 0;
8247 boolean moved = FALSE, snapped = FALSE, dropped = FALSE;
8248 int left = player_action & JOY_LEFT;
8249 int right = player_action & JOY_RIGHT;
8250 int up = player_action & JOY_UP;
8251 int down = player_action & JOY_DOWN;
8252 int button1 = player_action & JOY_BUTTON_1;
8253 int button2 = player_action & JOY_BUTTON_2;
8254 int dx = (left ? -1 : right ? 1 : 0);
8255 int dy = (up ? -1 : down ? 1 : 0);
8258 stored_player_action[player->index_nr] = 0;
8259 num_stored_actions++;
8263 printf("::: player %d [%d]\n", player->index_nr, FrameCounter);
8266 if (!player->active || tape.pausing)
8270 printf("::: [%d %d %d %d] [%d %d]\n",
8271 left, right, up, down, button1, button2);
8277 printf("::: player %d acts [%d]\n", player->index_nr, FrameCounter);
8282 if (player->MovPos == 0)
8283 CheckGravityMovement(player);
8286 snapped = SnapField(player, dx, dy);
8290 dropped = DropElement(player);
8292 moved = MovePlayer(player, dx, dy);
8295 if (tape.single_step && tape.recording && !tape.pausing)
8297 if (button1 || (dropped && !moved))
8299 TapeTogglePause(TAPE_TOGGLE_AUTOMATIC);
8300 SnapField(player, 0, 0); /* stop snapping */
8304 SetPlayerWaiting(player, FALSE);
8307 return player_action;
8309 stored_player_action[player->index_nr] = player_action;
8315 printf("::: player %d waits [%d]\n", player->index_nr, FrameCounter);
8318 /* no actions for this player (no input at player's configured device) */
8320 DigField(player, 0, 0, 0, 0, 0, 0, DF_NO_PUSH);
8321 SnapField(player, 0, 0);
8322 CheckGravityMovementWhenNotMoving(player);
8324 if (player->MovPos == 0)
8325 SetPlayerWaiting(player, TRUE);
8327 if (player->MovPos == 0) /* needed for tape.playing */
8328 player->is_moving = FALSE;
8330 player->is_dropping = FALSE;
8336 if (tape.recording && num_stored_actions >= MAX_PLAYERS)
8338 printf("::: player %d recorded [%d]\n", player->index_nr, FrameCounter);
8340 TapeRecordAction(stored_player_action);
8341 num_stored_actions = 0;
8348 static void PlayerActions(struct PlayerInfo *player, byte player_action)
8350 static byte stored_player_action[MAX_PLAYERS];
8351 static int num_stored_actions = 0;
8352 boolean moved = FALSE, snapped = FALSE, dropped = FALSE;
8353 int left = player_action & JOY_LEFT;
8354 int right = player_action & JOY_RIGHT;
8355 int up = player_action & JOY_UP;
8356 int down = player_action & JOY_DOWN;
8357 int button1 = player_action & JOY_BUTTON_1;
8358 int button2 = player_action & JOY_BUTTON_2;
8359 int dx = (left ? -1 : right ? 1 : 0);
8360 int dy = (up ? -1 : down ? 1 : 0);
8362 stored_player_action[player->index_nr] = 0;
8363 num_stored_actions++;
8365 printf("::: player %d [%d]\n", player->index_nr, FrameCounter);
8367 if (!player->active || tape.pausing)
8372 printf("::: player %d acts [%d]\n", player->index_nr, FrameCounter);
8375 snapped = SnapField(player, dx, dy);
8379 dropped = DropElement(player);
8381 moved = MovePlayer(player, dx, dy);
8384 if (tape.single_step && tape.recording && !tape.pausing)
8386 if (button1 || (dropped && !moved))
8388 TapeTogglePause(TAPE_TOGGLE_AUTOMATIC);
8389 SnapField(player, 0, 0); /* stop snapping */
8393 stored_player_action[player->index_nr] = player_action;
8397 printf("::: player %d waits [%d]\n", player->index_nr, FrameCounter);
8399 /* no actions for this player (no input at player's configured device) */
8401 DigField(player, 0, 0, 0, 0, 0, 0, DF_NO_PUSH);
8402 SnapField(player, 0, 0);
8403 CheckGravityMovementWhenNotMoving(player);
8405 if (player->MovPos == 0)
8406 InitPlayerGfxAnimation(player, ACTION_DEFAULT, player->MovDir);
8408 if (player->MovPos == 0) /* needed for tape.playing */
8409 player->is_moving = FALSE;
8412 if (tape.recording && num_stored_actions >= MAX_PLAYERS)
8414 printf("::: player %d recorded [%d]\n", player->index_nr, FrameCounter);
8416 TapeRecordAction(stored_player_action);
8417 num_stored_actions = 0;
8422 void AdvanceFrameAndPlayerCounters(int player_nr)
8426 /* advance frame counters (global frame counter and time frame counter) */
8430 /* advance player counters (counters for move delay, move animation etc.) */
8431 for (i = 0; i < MAX_PLAYERS; i++)
8433 boolean advance_player_counters = (player_nr == -1 || player_nr == i);
8435 MOVE_DELAY_NORMAL_SPEED / stored_player[i].move_delay_value;
8437 if (!advance_player_counters) /* not all players may be affected */
8440 stored_player[i].Frame += move_frames;
8442 if (stored_player[i].MovPos != 0)
8443 stored_player[i].StepFrame += move_frames;
8445 #if USE_NEW_MOVE_DELAY
8446 if (stored_player[i].move_delay > 0)
8447 stored_player[i].move_delay--;
8450 #if USE_NEW_PUSH_DELAY
8451 /* due to bugs in previous versions, counter must count up, not down */
8452 if (stored_player[i].push_delay != -1)
8453 stored_player[i].push_delay++;
8456 if (stored_player[i].drop_delay > 0)
8457 stored_player[i].drop_delay--;
8463 static unsigned long action_delay = 0;
8464 unsigned long action_delay_value;
8465 int magic_wall_x = 0, magic_wall_y = 0;
8466 int i, x, y, element, graphic;
8467 byte *recorded_player_action;
8468 byte summarized_player_action = 0;
8470 byte tape_action[MAX_PLAYERS];
8473 if (game_status != GAME_MODE_PLAYING)
8476 action_delay_value =
8477 (tape.playing && tape.fast_forward ? FfwdFrameDelay : GameFrameDelay);
8479 if (tape.playing && tape.warp_forward && !tape.pausing)
8480 action_delay_value = 0;
8482 /* ---------- main game synchronization point ---------- */
8484 WaitUntilDelayReached(&action_delay, action_delay_value);
8486 if (network_playing && !network_player_action_received)
8490 printf("DEBUG: try to get network player actions in time\n");
8494 #if defined(NETWORK_AVALIABLE)
8495 /* last chance to get network player actions without main loop delay */
8499 if (game_status != GAME_MODE_PLAYING)
8502 if (!network_player_action_received)
8506 printf("DEBUG: failed to get network player actions in time\n");
8517 printf("::: getting new tape action [%d]\n", FrameCounter);
8520 recorded_player_action = (tape.playing ? TapePlayAction() : NULL);
8523 if (recorded_player_action == NULL && tape.pausing)
8528 printf("::: %d\n", stored_player[0].action);
8532 if (recorded_player_action != NULL)
8533 for (i = 0; i < MAX_PLAYERS; i++)
8534 stored_player[i].action = recorded_player_action[i];
8537 for (i = 0; i < MAX_PLAYERS; i++)
8539 summarized_player_action |= stored_player[i].action;
8541 if (!network_playing)
8542 stored_player[i].effective_action = stored_player[i].action;
8545 #if defined(NETWORK_AVALIABLE)
8546 if (network_playing)
8547 SendToServer_MovePlayer(summarized_player_action);
8550 if (!options.network && !setup.team_mode)
8551 local_player->effective_action = summarized_player_action;
8554 if (recorded_player_action != NULL)
8555 for (i = 0; i < MAX_PLAYERS; i++)
8556 stored_player[i].effective_action = recorded_player_action[i];
8560 for (i = 0; i < MAX_PLAYERS; i++)
8562 tape_action[i] = stored_player[i].effective_action;
8564 if (tape.recording && tape_action[i] && !tape.player_participates[i])
8565 tape.player_participates[i] = TRUE; /* player just appeared from CE */
8568 /* only save actions from input devices, but not programmed actions */
8570 TapeRecordAction(tape_action);
8573 for (i = 0; i < MAX_PLAYERS; i++)
8575 int actual_player_action = stored_player[i].effective_action;
8578 /* !!! THIS BREAKS THE FOLLOWING TAPES: !!!
8579 - rnd_equinox_tetrachloride 048
8580 - rnd_equinox_tetrachloride_ii 096
8581 - rnd_emanuel_schmieg 002
8582 - doctor_sloan_ww 001, 020
8584 if (stored_player[i].MovPos == 0)
8585 CheckGravityMovement(&stored_player[i]);
8589 /* overwrite programmed action with tape action */
8590 if (stored_player[i].programmed_action)
8591 actual_player_action = stored_player[i].programmed_action;
8595 if (stored_player[i].programmed_action)
8596 printf("::: %d\n", stored_player[i].programmed_action);
8599 if (recorded_player_action)
8602 if (stored_player[i].programmed_action &&
8603 stored_player[i].programmed_action != recorded_player_action[i])
8604 printf("::: %d: %d <-> %d\n", i,
8605 stored_player[i].programmed_action, recorded_player_action[i]);
8609 actual_player_action = recorded_player_action[i];
8614 /* overwrite tape action with programmed action */
8615 if (stored_player[i].programmed_action)
8616 actual_player_action = stored_player[i].programmed_action;
8621 printf("::: action: %d: %x [%d]\n",
8622 stored_player[i].MovPos, actual_player_action, FrameCounter);
8626 PlayerActions(&stored_player[i], actual_player_action);
8628 tape_action[i] = PlayerActions(&stored_player[i], actual_player_action);
8630 if (tape.recording && tape_action[i] && !tape.player_participates[i])
8631 tape.player_participates[i] = TRUE; /* player just appeared from CE */
8634 ScrollPlayer(&stored_player[i], SCROLL_GO_ON);
8639 TapeRecordAction(tape_action);
8642 network_player_action_received = FALSE;
8644 ScrollScreen(NULL, SCROLL_GO_ON);
8650 for (i = 0; i < MAX_PLAYERS; i++)
8651 stored_player[i].Frame++;
8655 /* for downwards compatibility, the following code emulates a fixed bug that
8656 occured when pushing elements (causing elements that just made their last
8657 pushing step to already (if possible) make their first falling step in the
8658 same game frame, which is bad); this code is also needed to use the famous
8659 "spring push bug" which is used in older levels and might be wanted to be
8660 used also in newer levels, but in this case the buggy pushing code is only
8661 affecting the "spring" element and no other elements */
8664 if (game.engine_version < VERSION_IDENT(2,2,0,7) || level.use_spring_bug)
8666 if (game.engine_version < VERSION_IDENT(2,2,0,7))
8669 for (i = 0; i < MAX_PLAYERS; i++)
8671 struct PlayerInfo *player = &stored_player[i];
8676 if (player->active && player->is_pushing && player->is_moving &&
8678 (game.engine_version < VERSION_IDENT(2,2,0,7) ||
8679 Feld[x][y] == EL_SPRING))
8681 if (player->active && player->is_pushing && player->is_moving &&
8685 ContinueMoving(x, y);
8687 /* continue moving after pushing (this is actually a bug) */
8688 if (!IS_MOVING(x, y))
8697 for (y = 0; y < lev_fieldy; y++) for (x = 0; x < lev_fieldx; x++)
8699 Changed[x][y] = CE_BITMASK_DEFAULT;
8700 ChangeEvent[x][y] = CE_BITMASK_DEFAULT;
8702 #if USE_NEW_BLOCK_STYLE
8703 /* this must be handled before main playfield loop */
8704 if (Feld[x][y] == EL_PLAYER_IS_LEAVING)
8707 if (MovDelay[x][y] <= 0)
8713 if (ChangePage[x][y] != -1 && ChangeDelay[x][y] != 1)
8715 printf("GameActions(): x = %d, y = %d: ChangePage != -1\n", x, y);
8716 printf("GameActions(): This should never happen!\n");
8718 ChangePage[x][y] = -1;
8723 if (WasJustMoving[x][y] > 0)
8724 WasJustMoving[x][y]--;
8725 if (WasJustFalling[x][y] > 0)
8726 WasJustFalling[x][y]--;
8727 if (CheckCollision[x][y] > 0)
8728 CheckCollision[x][y]--;
8733 /* reset finished pushing action (not done in ContinueMoving() to allow
8734 continous pushing animation for elements with zero push delay) */
8735 if (GfxAction[x][y] == ACTION_PUSHING && !IS_MOVING(x, y))
8737 ResetGfxAnimation(x, y);
8738 DrawLevelField(x, y);
8743 if (IS_BLOCKED(x, y))
8747 Blocked2Moving(x, y, &oldx, &oldy);
8748 if (!IS_MOVING(oldx, oldy))
8750 printf("GameActions(): (BLOCKED => MOVING) context corrupted!\n");
8751 printf("GameActions(): BLOCKED: x = %d, y = %d\n", x, y);
8752 printf("GameActions(): !MOVING: oldx = %d, oldy = %d\n", oldx, oldy);
8753 printf("GameActions(): This should never happen!\n");
8759 for (y = 0; y < lev_fieldy; y++) for (x = 0; x < lev_fieldx; x++)
8761 element = Feld[x][y];
8763 graphic = el_act_dir2img(element, GfxAction[x][y], GfxDir[x][y]);
8765 graphic = el2img(element);
8771 printf("::: %d,%d: %d [%d]\n", x, y, element, FrameCounter);
8773 element = graphic = 0;
8777 if (graphic_info[graphic].anim_global_sync)
8778 GfxFrame[x][y] = FrameCounter;
8780 if (ANIM_MODE(graphic) == ANIM_RANDOM &&
8781 IS_NEXT_FRAME(GfxFrame[x][y], graphic))
8782 ResetRandomAnimationValue(x, y);
8784 SetRandomAnimationValue(x, y);
8787 PlayLevelSoundActionIfLoop(x, y, GfxAction[x][y]);
8790 if (IS_INACTIVE(element))
8792 if (IS_ANIMATED(graphic))
8793 DrawLevelGraphicAnimationIfNeeded(x, y, graphic);
8799 /* this may take place after moving, so 'element' may have changed */
8801 if (IS_CHANGING(x, y))
8803 if (IS_CHANGING(x, y) &&
8804 (game.engine_version < VERSION_IDENT(3,0,7,1) || !Stop[x][y]))
8808 ChangeElement(x, y, ChangePage[x][y] != -1 ? ChangePage[x][y] :
8809 element_info[element].event_page_nr[CE_DELAY]);
8811 ChangeElement(x, y, element_info[element].event_page_nr[CE_DELAY]);
8814 element = Feld[x][y];
8815 graphic = el_act_dir2img(element, GfxAction[x][y], GfxDir[x][y]);
8819 if (!IS_MOVING(x, y) && (CAN_FALL(element) || CAN_MOVE(element)))
8824 element = Feld[x][y];
8825 graphic = el_act_dir2img(element, GfxAction[x][y], GfxDir[x][y]);
8827 if (element == EL_MOLE)
8828 printf("::: %d, %d, %d [%d]\n",
8829 IS_ANIMATED(graphic), IS_MOVING(x, y), Stop[x][y],
8833 if (element == EL_YAMYAM)
8834 printf("::: %d, %d, %d\n",
8835 IS_ANIMATED(graphic), IS_MOVING(x, y), Stop[x][y]);
8839 if (IS_ANIMATED(graphic) &&
8843 DrawLevelGraphicAnimationIfNeeded(x, y, graphic);
8846 if (element == EL_BUG)
8847 printf("::: %d, %d\n", graphic, GfxFrame[x][y]);
8851 if (element == EL_MOLE)
8852 printf("::: %d, %d\n", graphic, GfxFrame[x][y]);
8856 if (IS_GEM(element) || element == EL_SP_INFOTRON)
8857 EdelsteinFunkeln(x, y);
8859 else if ((element == EL_ACID ||
8860 element == EL_EXIT_OPEN ||
8861 element == EL_SP_EXIT_OPEN ||
8862 element == EL_SP_TERMINAL ||
8863 element == EL_SP_TERMINAL_ACTIVE ||
8864 element == EL_EXTRA_TIME ||
8865 element == EL_SHIELD_NORMAL ||
8866 element == EL_SHIELD_DEADLY) &&
8867 IS_ANIMATED(graphic))
8868 DrawLevelGraphicAnimationIfNeeded(x, y, graphic);
8869 else if (IS_MOVING(x, y))
8870 ContinueMoving(x, y);
8871 else if (IS_ACTIVE_BOMB(element))
8872 CheckDynamite(x, y);
8874 else if (element == EL_EXPLOSION && !game.explosions_delayed)
8875 Explode(x, y, ExplodePhase[x][y], EX_TYPE_NORMAL);
8877 else if (element == EL_AMOEBA_GROWING)
8878 AmoebeWaechst(x, y);
8879 else if (element == EL_AMOEBA_SHRINKING)
8880 AmoebaDisappearing(x, y);
8882 #if !USE_NEW_AMOEBA_CODE
8883 else if (IS_AMOEBALIVE(element))
8884 AmoebeAbleger(x, y);
8887 else if (element == EL_GAME_OF_LIFE || element == EL_BIOMAZE)
8889 else if (element == EL_EXIT_CLOSED)
8891 else if (element == EL_SP_EXIT_CLOSED)
8893 else if (element == EL_EXPANDABLE_WALL_GROWING)
8895 else if (element == EL_EXPANDABLE_WALL ||
8896 element == EL_EXPANDABLE_WALL_HORIZONTAL ||
8897 element == EL_EXPANDABLE_WALL_VERTICAL ||
8898 element == EL_EXPANDABLE_WALL_ANY)
8900 else if (element == EL_FLAMES)
8901 CheckForDragon(x, y);
8903 else if (IS_AUTO_CHANGING(element))
8904 ChangeElement(x, y);
8906 else if (element == EL_EXPLOSION)
8907 ; /* drawing of correct explosion animation is handled separately */
8908 else if (IS_ANIMATED(graphic) && !IS_CHANGING(x, y))
8909 DrawLevelGraphicAnimationIfNeeded(x, y, graphic);
8912 /* this may take place after moving, so 'element' may have changed */
8913 if (IS_AUTO_CHANGING(Feld[x][y]))
8914 ChangeElement(x, y);
8917 if (IS_BELT_ACTIVE(element))
8918 PlayLevelSoundAction(x, y, ACTION_ACTIVE);
8920 if (game.magic_wall_active)
8922 int jx = local_player->jx, jy = local_player->jy;
8924 /* play the element sound at the position nearest to the player */
8925 if ((element == EL_MAGIC_WALL_FULL ||
8926 element == EL_MAGIC_WALL_ACTIVE ||
8927 element == EL_MAGIC_WALL_EMPTYING ||
8928 element == EL_BD_MAGIC_WALL_FULL ||
8929 element == EL_BD_MAGIC_WALL_ACTIVE ||
8930 element == EL_BD_MAGIC_WALL_EMPTYING) &&
8931 ABS(x-jx) + ABS(y-jy) < ABS(magic_wall_x-jx) + ABS(magic_wall_y-jy))
8939 #if USE_NEW_AMOEBA_CODE
8940 /* new experimental amoeba growth stuff */
8942 if (!(FrameCounter % 8))
8945 static unsigned long random = 1684108901;
8947 for (i = 0; i < level.amoeba_speed * 28 / 8; i++)
8950 x = (random >> 10) % lev_fieldx;
8951 y = (random >> 20) % lev_fieldy;
8953 x = RND(lev_fieldx);
8954 y = RND(lev_fieldy);
8956 element = Feld[x][y];
8959 if (!IS_PLAYER(x,y) &&
8960 (element == EL_EMPTY ||
8961 CAN_GROW_INTO(element) ||
8962 element == EL_QUICKSAND_EMPTY ||
8963 element == EL_ACID_SPLASH_LEFT ||
8964 element == EL_ACID_SPLASH_RIGHT))
8966 if ((IN_LEV_FIELD(x, y-1) && Feld[x][y-1] == EL_AMOEBA_WET) ||
8967 (IN_LEV_FIELD(x-1, y) && Feld[x-1][y] == EL_AMOEBA_WET) ||
8968 (IN_LEV_FIELD(x+1, y) && Feld[x+1][y] == EL_AMOEBA_WET) ||
8969 (IN_LEV_FIELD(x, y+1) && Feld[x][y+1] == EL_AMOEBA_WET))
8970 Feld[x][y] = EL_AMOEBA_DROP;
8973 /* !!! extend EL_SAND to anything diggable (but maybe not SP_BASE) !!! */
8974 if (!IS_PLAYER(x,y) &&
8975 (element == EL_EMPTY ||
8976 element == EL_SAND ||
8977 element == EL_QUICKSAND_EMPTY ||
8978 element == EL_ACID_SPLASH_LEFT ||
8979 element == EL_ACID_SPLASH_RIGHT))
8981 if ((IN_LEV_FIELD(x, y-1) && Feld[x][y-1] == EL_AMOEBA_WET) ||
8982 (IN_LEV_FIELD(x-1, y) && Feld[x-1][y] == EL_AMOEBA_WET) ||
8983 (IN_LEV_FIELD(x+1, y) && Feld[x+1][y] == EL_AMOEBA_WET) ||
8984 (IN_LEV_FIELD(x, y+1) && Feld[x][y+1] == EL_AMOEBA_WET))
8985 Feld[x][y] = EL_AMOEBA_DROP;
8989 random = random * 129 + 1;
8995 if (game.explosions_delayed)
8998 game.explosions_delayed = FALSE;
9000 for (y = 0; y < lev_fieldy; y++) for (x = 0; x < lev_fieldx; x++)
9002 element = Feld[x][y];
9004 if (ExplodeField[x][y])
9005 Explode(x, y, EX_PHASE_START, ExplodeField[x][y]);
9006 else if (element == EL_EXPLOSION)
9007 Explode(x, y, ExplodePhase[x][y], EX_TYPE_NORMAL);
9009 ExplodeField[x][y] = EX_TYPE_NONE;
9012 game.explosions_delayed = TRUE;
9015 if (game.magic_wall_active)
9017 if (!(game.magic_wall_time_left % 4))
9019 int element = Feld[magic_wall_x][magic_wall_y];
9021 if (element == EL_BD_MAGIC_WALL_FULL ||
9022 element == EL_BD_MAGIC_WALL_ACTIVE ||
9023 element == EL_BD_MAGIC_WALL_EMPTYING)
9024 PlayLevelSound(magic_wall_x, magic_wall_y, SND_BD_MAGIC_WALL_ACTIVE);
9026 PlayLevelSound(magic_wall_x, magic_wall_y, SND_MAGIC_WALL_ACTIVE);
9029 if (game.magic_wall_time_left > 0)
9031 game.magic_wall_time_left--;
9032 if (!game.magic_wall_time_left)
9034 for (y = 0; y < lev_fieldy; y++) for (x = 0; x < lev_fieldx; x++)
9036 element = Feld[x][y];
9038 if (element == EL_MAGIC_WALL_ACTIVE ||
9039 element == EL_MAGIC_WALL_FULL)
9041 Feld[x][y] = EL_MAGIC_WALL_DEAD;
9042 DrawLevelField(x, y);
9044 else if (element == EL_BD_MAGIC_WALL_ACTIVE ||
9045 element == EL_BD_MAGIC_WALL_FULL)
9047 Feld[x][y] = EL_BD_MAGIC_WALL_DEAD;
9048 DrawLevelField(x, y);
9052 game.magic_wall_active = FALSE;
9057 if (game.light_time_left > 0)
9059 game.light_time_left--;
9061 if (game.light_time_left == 0)
9062 RedrawAllLightSwitchesAndInvisibleElements();
9065 if (game.timegate_time_left > 0)
9067 game.timegate_time_left--;
9069 if (game.timegate_time_left == 0)
9070 CloseAllOpenTimegates();
9073 for (i = 0; i < MAX_PLAYERS; i++)
9075 struct PlayerInfo *player = &stored_player[i];
9077 if (SHIELD_ON(player))
9079 if (player->shield_deadly_time_left)
9080 PlayLevelSound(player->jx, player->jy, SND_SHIELD_DEADLY_ACTIVE);
9081 else if (player->shield_normal_time_left)
9082 PlayLevelSound(player->jx, player->jy, SND_SHIELD_NORMAL_ACTIVE);
9086 if (TimeFrames >= FRAMES_PER_SECOND)
9091 for (i = 0; i < MAX_PLAYERS; i++)
9093 struct PlayerInfo *player = &stored_player[i];
9095 if (SHIELD_ON(player))
9097 player->shield_normal_time_left--;
9099 if (player->shield_deadly_time_left > 0)
9100 player->shield_deadly_time_left--;
9104 if (!level.use_step_counter)
9112 if (TimeLeft <= 10 && setup.time_limit)
9113 PlaySoundStereo(SND_GAME_RUNNING_OUT_OF_TIME, SOUND_MIDDLE);
9115 DrawGameValue_Time(TimeLeft);
9117 if (!TimeLeft && setup.time_limit)
9118 for (i = 0; i < MAX_PLAYERS; i++)
9119 KillHero(&stored_player[i]);
9121 else if (level.time == 0 && !AllPlayersGone) /* level w/o time limit */
9122 DrawGameValue_Time(TimePlayed);
9125 if (tape.recording || tape.playing)
9126 DrawVideoDisplay(VIDEO_STATE_TIME_ON, TapeTime);
9130 PlayAllPlayersSound();
9132 if (options.debug) /* calculate frames per second */
9134 static unsigned long fps_counter = 0;
9135 static int fps_frames = 0;
9136 unsigned long fps_delay_ms = Counter() - fps_counter;
9140 if (fps_delay_ms >= 500) /* calculate fps every 0.5 seconds */
9142 global.frames_per_second = 1000 * (float)fps_frames / fps_delay_ms;
9145 fps_counter = Counter();
9148 redraw_mask |= REDRAW_FPS;
9152 if (stored_player[0].jx != stored_player[0].last_jx ||
9153 stored_player[0].jy != stored_player[0].last_jy)
9154 printf("::: %d, %d, %d, %d, %d\n",
9155 stored_player[0].MovDir,
9156 stored_player[0].MovPos,
9157 stored_player[0].GfxPos,
9158 stored_player[0].Frame,
9159 stored_player[0].StepFrame);
9162 #if USE_NEW_MOVE_DELAY
9163 AdvanceFrameAndPlayerCounters(-1); /* advance counters for all players */
9168 for (i = 0; i < MAX_PLAYERS; i++)
9171 MOVE_DELAY_NORMAL_SPEED / stored_player[i].move_delay_value;
9173 stored_player[i].Frame += move_frames;
9175 if (stored_player[i].MovPos != 0)
9176 stored_player[i].StepFrame += move_frames;
9178 #if USE_NEW_MOVE_DELAY
9179 if (stored_player[i].move_delay > 0)
9180 stored_player[i].move_delay--;
9183 if (stored_player[i].drop_delay > 0)
9184 stored_player[i].drop_delay--;
9189 if (local_player->show_envelope != 0 && local_player->MovPos == 0)
9191 ShowEnvelope(local_player->show_envelope - EL_ENVELOPE_1);
9193 local_player->show_envelope = 0;
9197 #if USE_NEW_RANDOMIZE
9198 /* use random number generator in every frame to make it less predictable */
9199 if (game.engine_version >= VERSION_IDENT(3,1,1,0))
9204 static boolean AllPlayersInSight(struct PlayerInfo *player, int x, int y)
9206 int min_x = x, min_y = y, max_x = x, max_y = y;
9209 for (i = 0; i < MAX_PLAYERS; i++)
9211 int jx = stored_player[i].jx, jy = stored_player[i].jy;
9213 if (!stored_player[i].active || &stored_player[i] == player)
9216 min_x = MIN(min_x, jx);
9217 min_y = MIN(min_y, jy);
9218 max_x = MAX(max_x, jx);
9219 max_y = MAX(max_y, jy);
9222 return (max_x - min_x < SCR_FIELDX && max_y - min_y < SCR_FIELDY);
9225 static boolean AllPlayersInVisibleScreen()
9229 for (i = 0; i < MAX_PLAYERS; i++)
9231 int jx = stored_player[i].jx, jy = stored_player[i].jy;
9233 if (!stored_player[i].active)
9236 if (!IN_VIS_FIELD(SCREENX(jx), SCREENY(jy)))
9243 void ScrollLevel(int dx, int dy)
9245 int softscroll_offset = (setup.soft_scrolling ? TILEX : 0);
9248 BlitBitmap(drawto_field, drawto_field,
9249 FX + TILEX * (dx == -1) - softscroll_offset,
9250 FY + TILEY * (dy == -1) - softscroll_offset,
9251 SXSIZE - TILEX * (dx!=0) + 2 * softscroll_offset,
9252 SYSIZE - TILEY * (dy!=0) + 2 * softscroll_offset,
9253 FX + TILEX * (dx == 1) - softscroll_offset,
9254 FY + TILEY * (dy == 1) - softscroll_offset);
9258 x = (dx == 1 ? BX1 : BX2);
9259 for (y = BY1; y <= BY2; y++)
9260 DrawScreenField(x, y);
9265 y = (dy == 1 ? BY1 : BY2);
9266 for (x = BX1; x <= BX2; x++)
9267 DrawScreenField(x, y);
9270 redraw_mask |= REDRAW_FIELD;
9274 static boolean canEnterSupaplexPort(int x, int y, int dx, int dy)
9276 int nextx = x + dx, nexty = y + dy;
9277 int element = Feld[x][y];
9280 element != EL_SP_PORT_LEFT &&
9281 element != EL_SP_GRAVITY_PORT_LEFT &&
9282 element != EL_SP_PORT_HORIZONTAL &&
9283 element != EL_SP_PORT_ANY) ||
9285 element != EL_SP_PORT_RIGHT &&
9286 element != EL_SP_GRAVITY_PORT_RIGHT &&
9287 element != EL_SP_PORT_HORIZONTAL &&
9288 element != EL_SP_PORT_ANY) ||
9290 element != EL_SP_PORT_UP &&
9291 element != EL_SP_GRAVITY_PORT_UP &&
9292 element != EL_SP_PORT_VERTICAL &&
9293 element != EL_SP_PORT_ANY) ||
9295 element != EL_SP_PORT_DOWN &&
9296 element != EL_SP_GRAVITY_PORT_DOWN &&
9297 element != EL_SP_PORT_VERTICAL &&
9298 element != EL_SP_PORT_ANY) ||
9299 !IN_LEV_FIELD(nextx, nexty) ||
9300 !IS_FREE(nextx, nexty))
9307 static boolean canFallDown(struct PlayerInfo *player)
9309 int jx = player->jx, jy = player->jy;
9311 return (IN_LEV_FIELD(jx, jy + 1) &&
9312 (IS_FREE(jx, jy + 1) ||
9313 (Feld[jx][jy + 1] == EL_ACID && player->can_fall_into_acid)) &&
9314 IS_WALKABLE_FROM(Feld[jx][jy], MV_DOWN) &&
9315 !IS_WALKABLE_INSIDE(Feld[jx][jy]));
9318 static boolean canPassField(int x, int y, int move_dir)
9320 int opposite_dir = MV_DIR_OPPOSITE(move_dir);
9321 int dx = (move_dir & MV_LEFT ? -1 : move_dir & MV_RIGHT ? +1 : 0);
9322 int dy = (move_dir & MV_UP ? -1 : move_dir & MV_DOWN ? +1 : 0);
9325 int element = Feld[x][y];
9327 return (IS_PASSABLE_FROM(element, opposite_dir) &&
9328 !CAN_MOVE(element) &&
9329 IN_LEV_FIELD(nextx, nexty) && !IS_PLAYER(nextx, nexty) &&
9330 IS_WALKABLE_FROM(Feld[nextx][nexty], move_dir) &&
9331 (level.can_pass_to_walkable || IS_FREE(nextx, nexty)));
9334 static boolean canMoveToValidFieldWithGravity(int x, int y, int move_dir)
9336 int opposite_dir = MV_DIR_OPPOSITE(move_dir);
9337 int dx = (move_dir & MV_LEFT ? -1 : move_dir & MV_RIGHT ? +1 : 0);
9338 int dy = (move_dir & MV_UP ? -1 : move_dir & MV_DOWN ? +1 : 0);
9342 int nextx = newx + dx;
9343 int nexty = newy + dy;
9347 return (IN_LEV_FIELD(newx, newy) && !IS_FREE_OR_PLAYER(newx, newy) &&
9348 IS_GRAVITY_REACHABLE(Feld[newx][newy]) &&
9350 (!IS_SP_PORT(Feld[newx][newy]) || move_dir == MV_UP) &&
9352 (IS_DIGGABLE(Feld[newx][newy]) ||
9353 IS_WALKABLE_FROM(Feld[newx][newy], opposite_dir) ||
9354 canPassField(newx, newy, move_dir)));
9357 return (IN_LEV_FIELD(newx, newy) && !IS_FREE_OR_PLAYER(newx, newy) &&
9358 IS_GRAVITY_REACHABLE(Feld[newx][newy]) &&
9359 (IS_DIGGABLE(Feld[newx][newy]) ||
9360 IS_WALKABLE_FROM(Feld[newx][newy], opposite_dir) ||
9361 canPassField(newx, newy, move_dir)));
9364 return (IN_LEV_FIELD(newx, newy) && !IS_FREE_OR_PLAYER(newx, newy) &&
9365 (IS_DIGGABLE_WITH_GRAVITY(Feld[newx][newy]) ||
9366 IS_WALKABLE_FROM(Feld[newx][newy], opposite_dir) ||
9367 canPassField(newx, newy, move_dir)));
9369 return (IN_LEV_FIELD(newx, newy) && !IS_FREE_OR_PLAYER(newx, newy) &&
9370 (IS_DIGGABLE(Feld[newx][newy]) ||
9371 IS_WALKABLE_FROM(Feld[newx][newy], opposite_dir) ||
9372 (IS_PASSABLE_FROM(Feld[newx][newy], opposite_dir) &&
9373 !CAN_MOVE(Feld[newx][newy]) &&
9374 IN_LEV_FIELD(nextx, nexty) && !IS_PLAYER(nextx, nexty) &&
9375 IS_WALKABLE_FROM(Feld[nextx][nexty], move_dir) &&
9376 (level.can_pass_to_walkable || IS_FREE(nextx, nexty)))));
9382 static void CheckGravityMovement(struct PlayerInfo *player)
9384 if (game.gravity && !player->programmed_action)
9387 int move_dir_horizontal = player->effective_action & MV_HORIZONTAL;
9388 int move_dir_vertical = player->effective_action & MV_VERTICAL;
9390 int move_dir_horizontal = player->action & MV_HORIZONTAL;
9391 int move_dir_vertical = player->action & MV_VERTICAL;
9395 boolean player_is_snapping = player->effective_action & JOY_BUTTON_1;
9397 boolean player_is_snapping = player->action & JOY_BUTTON_1;
9400 int jx = player->jx, jy = player->jy;
9402 boolean player_is_moving_to_valid_field =
9403 (!player_is_snapping &&
9404 (canMoveToValidFieldWithGravity(jx, jy, move_dir_horizontal) ||
9405 canMoveToValidFieldWithGravity(jx, jy, move_dir_vertical)));
9409 (player->last_move_dir & MV_HORIZONTAL ?
9410 (move_dir_vertical ? move_dir_vertical : move_dir_horizontal) :
9411 (move_dir_horizontal ? move_dir_horizontal : move_dir_vertical));
9415 int opposite_dir = MV_DIR_OPPOSITE(move_dir);
9416 int dx = (move_dir & MV_LEFT ? -1 : move_dir & MV_RIGHT ? +1 : 0);
9417 int dy = (move_dir & MV_UP ? -1 : move_dir & MV_DOWN ? +1 : 0);
9418 int new_jx = jx + dx, new_jy = jy + dy;
9419 int nextx = new_jx + dx, nexty = new_jy + dy;
9425 boolean player_can_fall_down = canFallDown(player);
9427 boolean player_can_fall_down =
9428 (IN_LEV_FIELD(jx, jy + 1) &&
9429 (IS_FREE(jx, jy + 1) ||
9430 (Feld[jx][jy + 1] == EL_ACID && player->can_fall_into_acid)));
9434 boolean player_can_fall_down =
9435 (IN_LEV_FIELD(jx, jy + 1) &&
9436 (IS_FREE(jx, jy + 1)));
9440 boolean player_is_moving_to_valid_field =
9443 !player_is_snapping &&
9447 IN_LEV_FIELD(new_jx, new_jy) &&
9448 (IS_DIGGABLE(Feld[new_jx][new_jy]) ||
9449 (IS_SP_PORT(Feld[new_jx][new_jy]) &&
9450 element_info[Feld[new_jx][new_jy]].access_direction & opposite_dir &&
9451 IN_LEV_FIELD(nextx, nexty) &&
9452 element_info[Feld[nextx][nexty]].access_direction & move_dir))
9454 IN_LEV_FIELD(new_jx, new_jy) &&
9455 (Feld[new_jx][new_jy] == EL_SP_BASE ||
9456 Feld[new_jx][new_jy] == EL_SAND ||
9457 (IS_SP_PORT(Feld[new_jx][new_jy]) &&
9458 canEnterSupaplexPort(new_jx, new_jy, dx, dy)))
9459 /* !!! extend EL_SAND to anything diggable !!! */
9465 boolean player_is_standing_on_valid_field =
9466 (IS_WALKABLE_INSIDE(Feld[jx][jy]) ||
9467 (IS_WALKABLE(Feld[jx][jy]) && !ACCESS_FROM(Feld[jx][jy], MV_DOWN)));
9471 printf("::: checking gravity NOW [%d, %d, %d] [%d] [%d / %d] ...\n",
9472 player_can_fall_down,
9473 player_is_standing_on_valid_field,
9474 player_is_moving_to_valid_field,
9475 (player_is_moving_to_valid_field ? Feld[new_jx][new_jy] : -1),
9476 player->effective_action,
9477 player->can_fall_into_acid);
9480 if (player_can_fall_down &&
9482 !player_is_standing_on_valid_field &&
9484 !player_is_moving_to_valid_field)
9487 printf("::: setting programmed_action to MV_DOWN [%d,%d - %d] ...\n",
9488 jx, jy, FrameCounter);
9491 player->programmed_action = MV_DOWN;
9496 static void CheckGravityMovementWhenNotMoving(struct PlayerInfo *player)
9499 return CheckGravityMovement(player);
9502 if (game.gravity && !player->programmed_action)
9504 int jx = player->jx, jy = player->jy;
9505 boolean field_under_player_is_free =
9506 (IN_LEV_FIELD(jx, jy + 1) && IS_FREE(jx, jy + 1));
9507 boolean player_is_standing_on_valid_field =
9508 (IS_WALKABLE_INSIDE(Feld[jx][jy]) ||
9509 (IS_WALKABLE(Feld[jx][jy]) &&
9510 !(element_info[Feld[jx][jy]].access_direction & MV_DOWN)));
9512 if (field_under_player_is_free && !player_is_standing_on_valid_field)
9513 player->programmed_action = MV_DOWN;
9519 -----------------------------------------------------------------------------
9520 dx, dy: direction (non-diagonal) to try to move the player to
9521 real_dx, real_dy: direction as read from input device (can be diagonal)
9524 boolean MovePlayerOneStep(struct PlayerInfo *player,
9525 int dx, int dy, int real_dx, int real_dy)
9528 static int trigger_sides[4][2] =
9530 /* enter side leave side */
9531 { CH_SIDE_RIGHT, CH_SIDE_LEFT }, /* moving left */
9532 { CH_SIDE_LEFT, CH_SIDE_RIGHT }, /* moving right */
9533 { CH_SIDE_BOTTOM, CH_SIDE_TOP }, /* moving up */
9534 { CH_SIDE_TOP, CH_SIDE_BOTTOM } /* moving down */
9536 int move_direction = (dx == -1 ? MV_LEFT :
9537 dx == +1 ? MV_RIGHT :
9539 dy == +1 ? MV_DOWN : MV_NO_MOVING);
9540 int enter_side = trigger_sides[MV_DIR_BIT(move_direction)][0];
9541 int leave_side = trigger_sides[MV_DIR_BIT(move_direction)][1];
9543 int jx = player->jx, jy = player->jy;
9544 int new_jx = jx + dx, new_jy = jy + dy;
9548 if (!player->active || (!dx && !dy))
9549 return MF_NO_ACTION;
9551 player->MovDir = (dx < 0 ? MV_LEFT :
9554 dy > 0 ? MV_DOWN : MV_NO_MOVING);
9556 if (!IN_LEV_FIELD(new_jx, new_jy))
9557 return MF_NO_ACTION;
9559 if (!options.network && !AllPlayersInSight(player, new_jx, new_jy))
9560 return MF_NO_ACTION;
9563 element = MovingOrBlocked2Element(new_jx, new_jy);
9565 element = MovingOrBlocked2ElementIfNotLeaving(new_jx, new_jy);
9568 if (DONT_RUN_INTO(element))
9570 if (element == EL_ACID && dx == 0 && dy == 1)
9572 SplashAcid(new_jx, new_jy);
9573 Feld[jx][jy] = EL_PLAYER_1;
9574 InitMovingField(jx, jy, MV_DOWN);
9575 Store[jx][jy] = EL_ACID;
9576 ContinueMoving(jx, jy);
9580 TestIfHeroRunsIntoBadThing(jx, jy, player->MovDir);
9585 can_move = DigField(player, jx, jy, new_jx, new_jy, real_dx,real_dy, DF_DIG);
9586 if (can_move != MF_MOVING)
9589 /* check if DigField() has caused relocation of the player */
9590 if (player->jx != jx || player->jy != jy)
9591 return MF_NO_ACTION;
9593 StorePlayer[jx][jy] = 0;
9594 player->last_jx = jx;
9595 player->last_jy = jy;
9596 player->jx = new_jx;
9597 player->jy = new_jy;
9598 StorePlayer[new_jx][new_jy] = player->element_nr;
9601 (dx > 0 || dy > 0 ? -1 : 1) * (TILEX - TILEX / player->move_delay_value);
9603 player->step_counter++;
9606 player->drop_delay = 0;
9609 PlayerVisit[jx][jy] = FrameCounter;
9611 ScrollPlayer(player, SCROLL_INIT);
9614 if (IS_CUSTOM_ELEMENT(Feld[jx][jy]))
9616 CheckTriggeredElementChangeBySide(jx, jy, Feld[jx][jy], CE_OTHER_GETS_LEFT,
9618 CheckElementChangeBySide(jx,jy, Feld[jx][jy],CE_LEFT_BY_PLAYER,leave_side);
9621 if (IS_CUSTOM_ELEMENT(Feld[new_jx][new_jy]))
9623 CheckTriggeredElementChangeBySide(new_jx, new_jy, Feld[new_jx][new_jy],
9624 CE_OTHER_GETS_ENTERED, enter_side);
9625 CheckElementChangeBySide(new_jx, new_jy, Feld[new_jx][new_jy],
9626 CE_ENTERED_BY_PLAYER, enter_side);
9633 boolean MovePlayer(struct PlayerInfo *player, int dx, int dy)
9635 int jx = player->jx, jy = player->jy;
9636 int old_jx = jx, old_jy = jy;
9637 int moved = MF_NO_ACTION;
9640 if (!player->active)
9645 if (player->MovPos == 0)
9647 player->is_moving = FALSE;
9648 player->is_digging = FALSE;
9649 player->is_collecting = FALSE;
9650 player->is_snapping = FALSE;
9651 player->is_pushing = FALSE;
9657 if (!player->active || (!dx && !dy))
9662 if (!FrameReached(&player->move_delay, player->move_delay_value) &&
9670 printf("::: %d <= %d < %d ?\n", player->move_delay, FrameCounter,
9671 player->move_delay + player->move_delay_value);
9674 #if USE_NEW_MOVE_DELAY
9675 if (player->move_delay > 0)
9677 if (!FrameReached(&player->move_delay, player->move_delay_value))
9681 printf("::: can NOT move\n");
9687 if (!FrameReached(&player->move_delay, player->move_delay_value) &&
9688 !(tape.playing && tape.file_version < FILE_VERSION_2_0))
9695 printf("::: COULD move now\n");
9698 #if USE_NEW_MOVE_DELAY
9699 player->move_delay = -1; /* set to "uninitialized" value */
9702 /* store if player is automatically moved to next field */
9703 player->is_auto_moving = (player->programmed_action != MV_NO_MOVING);
9705 /* remove the last programmed player action */
9706 player->programmed_action = 0;
9710 /* should only happen if pre-1.2 tape recordings are played */
9711 /* this is only for backward compatibility */
9713 int original_move_delay_value = player->move_delay_value;
9716 printf("THIS SHOULD ONLY HAPPEN WITH PRE-1.2 LEVEL TAPES. [%ld]\n",
9720 /* scroll remaining steps with finest movement resolution */
9721 player->move_delay_value = MOVE_DELAY_NORMAL_SPEED;
9723 while (player->MovPos)
9725 ScrollPlayer(player, SCROLL_GO_ON);
9726 ScrollScreen(NULL, SCROLL_GO_ON);
9728 #if USE_NEW_MOVE_DELAY
9729 AdvanceFrameAndPlayerCounters(player->index_nr);
9738 player->move_delay_value = original_move_delay_value;
9741 if (player->last_move_dir & MV_HORIZONTAL)
9743 if (!(moved |= MovePlayerOneStep(player, 0, dy, dx, dy)))
9744 moved |= MovePlayerOneStep(player, dx, 0, dx, dy);
9748 if (!(moved |= MovePlayerOneStep(player, dx, 0, dx, dy)))
9749 moved |= MovePlayerOneStep(player, 0, dy, dx, dy);
9755 if (moved & MF_MOVING && !ScreenMovPos &&
9756 (player == local_player || !options.network))
9758 int old_scroll_x = scroll_x, old_scroll_y = scroll_y;
9759 int offset = (setup.scroll_delay ? 3 : 0);
9761 if (!IN_VIS_FIELD(SCREENX(jx), SCREENY(jy)))
9763 /* actual player has left the screen -- scroll in that direction */
9764 if (jx != old_jx) /* player has moved horizontally */
9765 scroll_x += (jx - old_jx);
9766 else /* player has moved vertically */
9767 scroll_y += (jy - old_jy);
9771 if (jx != old_jx) /* player has moved horizontally */
9773 if ((player->MovDir == MV_LEFT && scroll_x > jx - MIDPOSX + offset) ||
9774 (player->MovDir == MV_RIGHT && scroll_x < jx - MIDPOSX - offset))
9775 scroll_x = jx-MIDPOSX + (scroll_x < jx-MIDPOSX ? -offset : +offset);
9777 /* don't scroll over playfield boundaries */
9778 if (scroll_x < SBX_Left || scroll_x > SBX_Right)
9779 scroll_x = (scroll_x < SBX_Left ? SBX_Left : SBX_Right);
9781 /* don't scroll more than one field at a time */
9782 scroll_x = old_scroll_x + SIGN(scroll_x - old_scroll_x);
9784 /* don't scroll against the player's moving direction */
9785 if ((player->MovDir == MV_LEFT && scroll_x > old_scroll_x) ||
9786 (player->MovDir == MV_RIGHT && scroll_x < old_scroll_x))
9787 scroll_x = old_scroll_x;
9789 else /* player has moved vertically */
9791 if ((player->MovDir == MV_UP && scroll_y > jy - MIDPOSY + offset) ||
9792 (player->MovDir == MV_DOWN && scroll_y < jy - MIDPOSY - offset))
9793 scroll_y = jy-MIDPOSY + (scroll_y < jy-MIDPOSY ? -offset : +offset);
9795 /* don't scroll over playfield boundaries */
9796 if (scroll_y < SBY_Upper || scroll_y > SBY_Lower)
9797 scroll_y = (scroll_y < SBY_Upper ? SBY_Upper : SBY_Lower);
9799 /* don't scroll more than one field at a time */
9800 scroll_y = old_scroll_y + SIGN(scroll_y - old_scroll_y);
9802 /* don't scroll against the player's moving direction */
9803 if ((player->MovDir == MV_UP && scroll_y > old_scroll_y) ||
9804 (player->MovDir == MV_DOWN && scroll_y < old_scroll_y))
9805 scroll_y = old_scroll_y;
9809 if (scroll_x != old_scroll_x || scroll_y != old_scroll_y)
9811 if (!options.network && !AllPlayersInVisibleScreen())
9813 scroll_x = old_scroll_x;
9814 scroll_y = old_scroll_y;
9818 ScrollScreen(player, SCROLL_INIT);
9819 ScrollLevel(old_scroll_x - scroll_x, old_scroll_y - scroll_y);
9826 InitPlayerGfxAnimation(player, ACTION_DEFAULT);
9828 if (!(moved & MF_MOVING) && !player->is_pushing)
9833 player->StepFrame = 0;
9835 if (moved & MF_MOVING)
9838 printf("::: REALLY moves now\n");
9841 if (old_jx != jx && old_jy == jy)
9842 player->MovDir = (old_jx < jx ? MV_RIGHT : MV_LEFT);
9843 else if (old_jx == jx && old_jy != jy)
9844 player->MovDir = (old_jy < jy ? MV_DOWN : MV_UP);
9846 DrawLevelField(jx, jy); /* for "crumbled sand" */
9848 player->last_move_dir = player->MovDir;
9849 player->is_moving = TRUE;
9851 player->is_snapping = FALSE;
9855 player->is_switching = FALSE;
9858 player->is_dropping = FALSE;
9862 /* !!! ENABLE THIS FOR OLD VERSIONS !!! */
9865 if (game.engine_version < VERSION_IDENT(3,1,0,0))
9868 int move_direction = player->MovDir;
9870 int enter_side = MV_DIR_OPPOSITE(move_direction);
9871 int leave_side = move_direction;
9873 static int trigger_sides[4][2] =
9875 /* enter side leave side */
9876 { CH_SIDE_RIGHT, CH_SIDE_LEFT }, /* moving left */
9877 { CH_SIDE_LEFT, CH_SIDE_RIGHT }, /* moving right */
9878 { CH_SIDE_BOTTOM, CH_SIDE_TOP }, /* moving up */
9879 { CH_SIDE_TOP, CH_SIDE_BOTTOM } /* moving down */
9881 int enter_side = trigger_sides[MV_DIR_BIT(move_direction)][0];
9882 int leave_side = trigger_sides[MV_DIR_BIT(move_direction)][1];
9884 int old_element = Feld[old_jx][old_jy];
9885 int new_element = Feld[jx][jy];
9888 /* !!! TEST ONLY !!! */
9889 if (IS_CUSTOM_ELEMENT(old_element))
9890 CheckElementChangeByPlayer(old_jx, old_jy, old_element,
9892 player->index_bit, leave_side);
9894 CheckTriggeredElementChangeByPlayer(old_jx, old_jy, old_element,
9896 player->index_bit, leave_side);
9898 if (IS_CUSTOM_ELEMENT(new_element))
9899 CheckElementChangeByPlayer(jx, jy, new_element, CE_ENTERED_BY_PLAYER,
9900 player->index_bit, enter_side);
9902 CheckTriggeredElementChangeByPlayer(jx, jy, new_element,
9903 CE_OTHER_GETS_ENTERED,
9904 player->index_bit, enter_side);
9914 CheckGravityMovementWhenNotMoving(player);
9917 player->last_move_dir = MV_NO_MOVING;
9919 player->is_moving = FALSE;
9921 #if USE_NEW_MOVE_STYLE
9922 /* player is ALLOWED to move, but CANNOT move (something blocks his way) */
9923 /* ensure that the player is also allowed to move in the next frame */
9924 /* (currently, the player is forced to wait eight frames before he can try
9927 if (game.engine_version >= VERSION_IDENT(3,1,1,0))
9928 player->move_delay = 0; /* allow direct movement in the next frame */
9932 #if USE_NEW_MOVE_DELAY
9933 if (player->move_delay == -1) /* not yet initialized by DigField() */
9934 player->move_delay = player->move_delay_value;
9937 if (game.engine_version < VERSION_IDENT(3,0,7,0))
9939 TestIfHeroTouchesBadThing(jx, jy);
9940 TestIfPlayerTouchesCustomElement(jx, jy);
9943 if (!player->active)
9949 void ScrollPlayer(struct PlayerInfo *player, int mode)
9951 int jx = player->jx, jy = player->jy;
9952 int last_jx = player->last_jx, last_jy = player->last_jy;
9953 int move_stepsize = TILEX / player->move_delay_value;
9955 if (!player->active || !player->MovPos)
9958 if (mode == SCROLL_INIT)
9960 player->actual_frame_counter = FrameCounter;
9961 player->GfxPos = move_stepsize * (player->MovPos / move_stepsize);
9964 printf("::: %06d: %d,%d: %d (%d) [%d]\n",
9966 last_jx, last_jy, Feld[last_jx][last_jy], EL_EXPLOSION,
9967 player->block_delay);
9970 #if USE_NEW_BLOCK_STYLE
9973 if (player->block_delay <= 0)
9974 printf("::: ALERT! block_delay == %d\n", player->block_delay);
9977 if (player->block_delay > 0 &&
9978 Feld[last_jx][last_jy] == EL_EMPTY)
9980 Feld[last_jx][last_jy] = EL_PLAYER_IS_LEAVING;
9981 MovDelay[last_jx][last_jy] = player->block_delay + 1;
9984 #if USE_NEW_MOVE_STYLE
9985 if ((game.engine_version < VERSION_IDENT(3,1,1,0) ||
9986 player->block_last_field) &&
9987 Feld[last_jx][last_jy] == EL_EMPTY)
9988 Feld[last_jx][last_jy] = EL_PLAYER_IS_LEAVING;
9990 if (Feld[last_jx][last_jy] == EL_EMPTY)
9991 Feld[last_jx][last_jy] = EL_PLAYER_IS_LEAVING;
10001 else if (!FrameReached(&player->actual_frame_counter, 1))
10004 player->MovPos += (player->MovPos > 0 ? -1 : 1) * move_stepsize;
10005 player->GfxPos = move_stepsize * (player->MovPos / move_stepsize);
10007 #if USE_NEW_BLOCK_STYLE
10009 if (!player->block_last_field &&
10010 Feld[last_jx][last_jy] == EL_PLAYER_IS_LEAVING)
10012 RemoveField(last_jx, last_jy);
10014 Feld[last_jx][last_jy] = EL_EMPTY;
10018 /* before DrawPlayer() to draw correct player graphic for this case */
10019 if (player->MovPos == 0)
10020 CheckGravityMovement(player);
10023 DrawPlayer(player); /* needed here only to cleanup last field */
10026 if (player->MovPos == 0) /* player reached destination field */
10029 if (player->move_delay_reset_counter > 0)
10031 player->move_delay_reset_counter--;
10033 if (player->move_delay_reset_counter == 0)
10035 /* continue with normal speed after quickly moving through gate */
10036 HALVE_PLAYER_SPEED(player);
10038 /* be able to make the next move without delay */
10039 player->move_delay = 0;
10043 if (IS_PASSABLE(Feld[last_jx][last_jy]))
10045 /* continue with normal speed after quickly moving through gate */
10046 HALVE_PLAYER_SPEED(player);
10048 /* be able to make the next move without delay */
10049 player->move_delay = 0;
10053 #if USE_NEW_BLOCK_STYLE
10055 if (player->block_last_field &&
10056 Feld[last_jx][last_jy] == EL_PLAYER_IS_LEAVING)
10058 RemoveField(last_jx, last_jy);
10060 Feld[last_jx][last_jy] = EL_EMPTY;
10064 player->last_jx = jx;
10065 player->last_jy = jy;
10067 if (Feld[jx][jy] == EL_EXIT_OPEN ||
10068 Feld[jx][jy] == EL_SP_EXIT_OPEN ||
10069 Feld[jx][jy] == EL_SP_EXIT_OPENING) /* <-- special case */
10071 DrawPlayer(player); /* needed here only to cleanup last field */
10072 RemoveHero(player);
10074 if (local_player->friends_still_needed == 0 ||
10075 IS_SP_ELEMENT(Feld[jx][jy]))
10076 player->LevelSolved = player->GameOver = TRUE;
10080 /* !!! ENABLE THIS FOR NEW VERSIONS !!! */
10081 /* this breaks one level: "machine", level 000 */
10083 if (game.engine_version >= VERSION_IDENT(3,1,0,0))
10086 int move_direction = player->MovDir;
10088 int enter_side = MV_DIR_OPPOSITE(move_direction);
10089 int leave_side = move_direction;
10091 static int trigger_sides[4][2] =
10093 /* enter side leave side */
10094 { CH_SIDE_RIGHT, CH_SIDE_LEFT }, /* moving left */
10095 { CH_SIDE_LEFT, CH_SIDE_RIGHT }, /* moving right */
10096 { CH_SIDE_BOTTOM, CH_SIDE_TOP }, /* moving up */
10097 { CH_SIDE_TOP, CH_SIDE_BOTTOM } /* moving down */
10099 int enter_side = trigger_sides[MV_DIR_BIT(move_direction)][0];
10100 int leave_side = trigger_sides[MV_DIR_BIT(move_direction)][1];
10102 int old_jx = last_jx;
10103 int old_jy = last_jy;
10104 int old_element = Feld[old_jx][old_jy];
10105 int new_element = Feld[jx][jy];
10108 /* !!! TEST ONLY !!! */
10109 if (IS_CUSTOM_ELEMENT(old_element))
10110 CheckElementChangeByPlayer(old_jx, old_jy, old_element,
10112 player->index_bit, leave_side);
10114 CheckTriggeredElementChangeByPlayer(old_jx, old_jy, old_element,
10115 CE_OTHER_GETS_LEFT,
10116 player->index_bit, leave_side);
10118 if (IS_CUSTOM_ELEMENT(new_element))
10119 CheckElementChangeByPlayer(jx, jy, new_element, CE_ENTERED_BY_PLAYER,
10120 player->index_bit, enter_side);
10122 CheckTriggeredElementChangeByPlayer(jx, jy, new_element,
10123 CE_OTHER_GETS_ENTERED,
10124 player->index_bit, enter_side);
10130 if (game.engine_version >= VERSION_IDENT(3,0,7,0))
10132 TestIfHeroTouchesBadThing(jx, jy);
10133 TestIfPlayerTouchesCustomElement(jx, jy);
10136 /* needed because pushed element has not yet reached its destination,
10137 so it would trigger a change event at its previous field location */
10138 if (!player->is_pushing)
10140 TestIfElementTouchesCustomElement(jx, jy); /* for empty space */
10143 if (!player->active)
10144 RemoveHero(player);
10147 if (level.use_step_counter)
10157 if (TimeLeft <= 10 && setup.time_limit)
10158 PlaySoundStereo(SND_GAME_RUNNING_OUT_OF_TIME, SOUND_MIDDLE);
10160 DrawGameValue_Time(TimeLeft);
10162 if (!TimeLeft && setup.time_limit)
10163 for (i = 0; i < MAX_PLAYERS; i++)
10164 KillHero(&stored_player[i]);
10166 else if (level.time == 0 && !AllPlayersGone) /* level w/o time limit */
10167 DrawGameValue_Time(TimePlayed);
10170 if (tape.single_step && tape.recording && !tape.pausing &&
10171 !player->programmed_action)
10172 TapeTogglePause(TAPE_TOGGLE_AUTOMATIC);
10176 void ScrollScreen(struct PlayerInfo *player, int mode)
10178 static unsigned long screen_frame_counter = 0;
10180 if (mode == SCROLL_INIT)
10182 /* set scrolling step size according to actual player's moving speed */
10183 ScrollStepSize = TILEX / player->move_delay_value;
10185 screen_frame_counter = FrameCounter;
10186 ScreenMovDir = player->MovDir;
10187 ScreenMovPos = player->MovPos;
10188 ScreenGfxPos = ScrollStepSize * (ScreenMovPos / ScrollStepSize);
10191 else if (!FrameReached(&screen_frame_counter, 1))
10196 ScreenMovPos += (ScreenMovPos > 0 ? -1 : 1) * ScrollStepSize;
10197 ScreenGfxPos = ScrollStepSize * (ScreenMovPos / ScrollStepSize);
10198 redraw_mask |= REDRAW_FIELD;
10201 ScreenMovDir = MV_NO_MOVING;
10204 void TestIfPlayerTouchesCustomElement(int x, int y)
10206 static int xy[4][2] =
10213 static int trigger_sides[4][2] =
10215 /* center side border side */
10216 { CH_SIDE_TOP, CH_SIDE_BOTTOM }, /* check top */
10217 { CH_SIDE_LEFT, CH_SIDE_RIGHT }, /* check left */
10218 { CH_SIDE_RIGHT, CH_SIDE_LEFT }, /* check right */
10219 { CH_SIDE_BOTTOM, CH_SIDE_TOP } /* check bottom */
10221 static int touch_dir[4] =
10223 MV_LEFT | MV_RIGHT,
10228 int center_element = Feld[x][y]; /* should always be non-moving! */
10231 for (i = 0; i < NUM_DIRECTIONS; i++)
10233 int xx = x + xy[i][0];
10234 int yy = y + xy[i][1];
10235 int center_side = trigger_sides[i][0];
10236 int border_side = trigger_sides[i][1];
10237 int border_element;
10239 if (!IN_LEV_FIELD(xx, yy))
10242 if (IS_PLAYER(x, y))
10244 struct PlayerInfo *player = PLAYERINFO(x, y);
10246 if (game.engine_version < VERSION_IDENT(3,0,7,0))
10247 border_element = Feld[xx][yy]; /* may be moving! */
10248 else if (!IS_MOVING(xx, yy) && !IS_BLOCKED(xx, yy))
10249 border_element = Feld[xx][yy];
10250 else if (MovDir[xx][yy] & touch_dir[i]) /* elements are touching */
10251 border_element = MovingOrBlocked2Element(xx, yy);
10253 continue; /* center and border element do not touch */
10256 /* !!! TEST ONLY !!! */
10257 CheckElementChangeByPlayer(xx, yy, border_element, CE_TOUCHED_BY_PLAYER,
10258 player->index_bit, border_side);
10259 CheckTriggeredElementChangeByPlayer(xx, yy, border_element,
10260 CE_OTHER_GETS_TOUCHED,
10261 player->index_bit, border_side);
10263 CheckTriggeredElementChangeByPlayer(xx, yy, border_element,
10264 CE_OTHER_GETS_TOUCHED,
10265 player->index_bit, border_side);
10266 CheckElementChangeByPlayer(xx, yy, border_element, CE_TOUCHED_BY_PLAYER,
10267 player->index_bit, border_side);
10270 else if (IS_PLAYER(xx, yy))
10272 struct PlayerInfo *player = PLAYERINFO(xx, yy);
10274 if (game.engine_version >= VERSION_IDENT(3,0,7,0))
10276 if (player->MovPos != 0 && !(player->MovDir & touch_dir[i]))
10277 continue; /* center and border element do not touch */
10281 /* !!! TEST ONLY !!! */
10282 CheckElementChangeByPlayer(x, y, center_element, CE_TOUCHED_BY_PLAYER,
10283 player->index_bit, center_side);
10284 CheckTriggeredElementChangeByPlayer(x, y, center_element,
10285 CE_OTHER_GETS_TOUCHED,
10286 player->index_bit, center_side);
10288 CheckTriggeredElementChangeByPlayer(x, y, center_element,
10289 CE_OTHER_GETS_TOUCHED,
10290 player->index_bit, center_side);
10291 CheckElementChangeByPlayer(x, y, center_element, CE_TOUCHED_BY_PLAYER,
10292 player->index_bit, center_side);
10300 void TestIfElementTouchesCustomElement(int x, int y)
10302 static int xy[4][2] =
10309 static int trigger_sides[4][2] =
10311 /* center side border side */
10312 { CH_SIDE_TOP, CH_SIDE_BOTTOM }, /* check top */
10313 { CH_SIDE_LEFT, CH_SIDE_RIGHT }, /* check left */
10314 { CH_SIDE_RIGHT, CH_SIDE_LEFT }, /* check right */
10315 { CH_SIDE_BOTTOM, CH_SIDE_TOP } /* check bottom */
10317 static int touch_dir[4] =
10319 MV_LEFT | MV_RIGHT,
10324 boolean change_center_element = FALSE;
10325 int center_element_change_page = 0;
10326 int center_element = Feld[x][y]; /* should always be non-moving! */
10327 int border_trigger_element = EL_UNDEFINED;
10330 for (i = 0; i < NUM_DIRECTIONS; i++)
10332 int xx = x + xy[i][0];
10333 int yy = y + xy[i][1];
10334 int center_side = trigger_sides[i][0];
10335 int border_side = trigger_sides[i][1];
10336 int border_element;
10338 if (!IN_LEV_FIELD(xx, yy))
10341 if (game.engine_version < VERSION_IDENT(3,0,7,0))
10342 border_element = Feld[xx][yy]; /* may be moving! */
10343 else if (!IS_MOVING(xx, yy) && !IS_BLOCKED(xx, yy))
10344 border_element = Feld[xx][yy];
10345 else if (MovDir[xx][yy] & touch_dir[i]) /* elements are touching */
10346 border_element = MovingOrBlocked2Element(xx, yy);
10348 continue; /* center and border element do not touch */
10350 /* check for change of center element (but change it only once) */
10351 if (IS_CUSTOM_ELEMENT(center_element) &&
10352 HAS_ANY_CHANGE_EVENT(center_element, CE_OTHER_IS_TOUCHING) &&
10353 !change_center_element)
10355 for (j = 0; j < element_info[center_element].num_change_pages; j++)
10357 struct ElementChangeInfo *change =
10358 &element_info[center_element].change_page[j];
10360 if (change->can_change &&
10361 change->events & CH_EVENT_BIT(CE_OTHER_IS_TOUCHING) &&
10362 change->trigger_side & border_side &&
10364 IS_EQUAL_OR_IN_GROUP(border_element, change->trigger_element)
10366 change->trigger_element == border_element
10370 change_center_element = TRUE;
10371 center_element_change_page = j;
10372 border_trigger_element = border_element;
10379 /* check for change of border element */
10380 if (IS_CUSTOM_ELEMENT(border_element) &&
10381 HAS_ANY_CHANGE_EVENT(border_element, CE_OTHER_IS_TOUCHING))
10383 for (j = 0; j < element_info[border_element].num_change_pages; j++)
10385 struct ElementChangeInfo *change =
10386 &element_info[border_element].change_page[j];
10388 if (change->can_change &&
10389 change->events & CH_EVENT_BIT(CE_OTHER_IS_TOUCHING) &&
10390 change->trigger_side & center_side &&
10392 IS_EQUAL_OR_IN_GROUP(center_element, change->trigger_element)
10394 change->trigger_element == center_element
10399 printf("::: border_element %d, %d\n", x, y);
10402 CheckElementChangeByPage(xx, yy, border_element, center_element,
10403 CE_OTHER_IS_TOUCHING, j);
10410 if (change_center_element)
10413 printf("::: center_element %d, %d\n", x, y);
10416 CheckElementChangeByPage(x, y, center_element, border_trigger_element,
10417 CE_OTHER_IS_TOUCHING, center_element_change_page);
10421 void TestIfElementHitsCustomElement(int x, int y, int direction)
10423 int dx = (direction == MV_LEFT ? -1 : direction == MV_RIGHT ? +1 : 0);
10424 int dy = (direction == MV_UP ? -1 : direction == MV_DOWN ? +1 : 0);
10425 int hitx = x + dx, hity = y + dy;
10426 int hitting_element = Feld[x][y];
10427 int touched_element;
10429 boolean object_hit = (IN_LEV_FIELD(hitx, hity) &&
10430 !IS_FREE(hitx, hity) &&
10431 (!IS_MOVING(hitx, hity) ||
10432 MovDir[hitx][hity] != direction ||
10433 ABS(MovPos[hitx][hity]) <= TILEY / 2));
10436 if (IN_LEV_FIELD(hitx, hity) && IS_FREE(hitx, hity))
10440 if (IN_LEV_FIELD(hitx, hity) && !object_hit)
10444 touched_element = (IN_LEV_FIELD(hitx, hity) ?
10445 MovingOrBlocked2Element(hitx, hity) : EL_STEELWALL);
10447 CheckElementChangeBySide(x, y, hitting_element, touched_element,
10448 CE_HITTING_SOMETHING, direction);
10450 if (IN_LEV_FIELD(hitx, hity))
10452 int opposite_direction = MV_DIR_OPPOSITE(direction);
10453 int hitting_side = direction;
10454 int touched_side = opposite_direction;
10456 int touched_element = MovingOrBlocked2Element(hitx, hity);
10459 boolean object_hit = (!IS_MOVING(hitx, hity) ||
10460 MovDir[hitx][hity] != direction ||
10461 ABS(MovPos[hitx][hity]) <= TILEY / 2);
10470 CheckElementChangeBySide(hitx, hity, touched_element, hitting_element,
10471 CE_HIT_BY_SOMETHING, opposite_direction);
10473 if (IS_CUSTOM_ELEMENT(hitting_element) &&
10474 HAS_ANY_CHANGE_EVENT(hitting_element, CE_OTHER_IS_HITTING))
10476 for (i = 0; i < element_info[hitting_element].num_change_pages; i++)
10478 struct ElementChangeInfo *change =
10479 &element_info[hitting_element].change_page[i];
10481 if (change->can_change &&
10482 change->events & CH_EVENT_BIT(CE_OTHER_IS_HITTING) &&
10483 change->trigger_side & touched_side &&
10486 IS_EQUAL_OR_IN_GROUP(touched_element, change->trigger_element)
10488 change->trigger_element == touched_element
10492 CheckElementChangeByPage(x, y, hitting_element, touched_element,
10493 CE_OTHER_IS_HITTING, i);
10499 if (IS_CUSTOM_ELEMENT(touched_element) &&
10500 HAS_ANY_CHANGE_EVENT(touched_element, CE_OTHER_GETS_HIT))
10502 for (i = 0; i < element_info[touched_element].num_change_pages; i++)
10504 struct ElementChangeInfo *change =
10505 &element_info[touched_element].change_page[i];
10507 if (change->can_change &&
10508 change->events & CH_EVENT_BIT(CE_OTHER_GETS_HIT) &&
10509 change->trigger_side & hitting_side &&
10511 IS_EQUAL_OR_IN_GROUP(hitting_element, change->trigger_element)
10513 change->trigger_element == hitting_element
10517 CheckElementChangeByPage(hitx, hity, touched_element,
10518 hitting_element, CE_OTHER_GETS_HIT, i);
10528 void TestIfElementSmashesCustomElement(int x, int y, int direction)
10530 int dx = (direction == MV_LEFT ? -1 : direction == MV_RIGHT ? +1 : 0);
10531 int dy = (direction == MV_UP ? -1 : direction == MV_DOWN ? +1 : 0);
10532 int hitx = x + dx, hity = y + dy;
10533 int hitting_element = Feld[x][y];
10534 int touched_element;
10536 boolean object_hit = (IN_LEV_FIELD(hitx, hity) &&
10537 !IS_FREE(hitx, hity) &&
10538 (!IS_MOVING(hitx, hity) ||
10539 MovDir[hitx][hity] != direction ||
10540 ABS(MovPos[hitx][hity]) <= TILEY / 2));
10543 if (IN_LEV_FIELD(hitx, hity) && IS_FREE(hitx, hity))
10547 if (IN_LEV_FIELD(hitx, hity) && !object_hit)
10551 touched_element = (IN_LEV_FIELD(hitx, hity) ?
10552 MovingOrBlocked2Element(hitx, hity) : EL_STEELWALL);
10554 CheckElementChangeBySide(x, y, hitting_element, touched_element,
10555 EP_CAN_SMASH_EVERYTHING, direction);
10557 if (IN_LEV_FIELD(hitx, hity))
10559 int opposite_direction = MV_DIR_OPPOSITE(direction);
10560 int hitting_side = direction;
10561 int touched_side = opposite_direction;
10563 int touched_element = MovingOrBlocked2Element(hitx, hity);
10566 boolean object_hit = (!IS_MOVING(hitx, hity) ||
10567 MovDir[hitx][hity] != direction ||
10568 ABS(MovPos[hitx][hity]) <= TILEY / 2);
10577 CheckElementChangeBySide(hitx, hity, touched_element, hitting_element,
10578 CE_SMASHED_BY_SOMETHING, opposite_direction);
10580 if (IS_CUSTOM_ELEMENT(hitting_element) &&
10581 HAS_ANY_CHANGE_EVENT(hitting_element, CE_OTHER_IS_SMASHING))
10583 for (i = 0; i < element_info[hitting_element].num_change_pages; i++)
10585 struct ElementChangeInfo *change =
10586 &element_info[hitting_element].change_page[i];
10588 if (change->can_change &&
10589 change->events & CH_EVENT_BIT(CE_OTHER_IS_SMASHING) &&
10590 change->trigger_side & touched_side &&
10593 IS_EQUAL_OR_IN_GROUP(touched_element, change->trigger_element)
10595 change->trigger_element == touched_element
10599 CheckElementChangeByPage(x, y, hitting_element, touched_element,
10600 CE_OTHER_IS_SMASHING, i);
10606 if (IS_CUSTOM_ELEMENT(touched_element) &&
10607 HAS_ANY_CHANGE_EVENT(touched_element, CE_OTHER_GETS_SMASHED))
10609 for (i = 0; i < element_info[touched_element].num_change_pages; i++)
10611 struct ElementChangeInfo *change =
10612 &element_info[touched_element].change_page[i];
10614 if (change->can_change &&
10615 change->events & CH_EVENT_BIT(CE_OTHER_GETS_SMASHED) &&
10616 change->trigger_side & hitting_side &&
10618 IS_EQUAL_OR_IN_GROUP(hitting_element, change->trigger_element)
10620 change->trigger_element == hitting_element
10624 CheckElementChangeByPage(hitx, hity, touched_element,
10625 hitting_element, CE_OTHER_GETS_SMASHED,i);
10635 void TestIfGoodThingHitsBadThing(int good_x, int good_y, int good_move_dir)
10637 int i, kill_x = -1, kill_y = -1;
10638 int bad_element = -1;
10639 static int test_xy[4][2] =
10646 static int test_dir[4] =
10654 for (i = 0; i < NUM_DIRECTIONS; i++)
10656 int test_x, test_y, test_move_dir, test_element;
10658 test_x = good_x + test_xy[i][0];
10659 test_y = good_y + test_xy[i][1];
10661 if (!IN_LEV_FIELD(test_x, test_y))
10665 (IS_MOVING(test_x, test_y) ? MovDir[test_x][test_y] : MV_NO_MOVING);
10668 test_element = Feld[test_x][test_y];
10670 test_element = MovingOrBlocked2ElementIfNotLeaving(test_x, test_y);
10673 /* 1st case: good thing is moving towards DONT_RUN_INTO style bad thing;
10674 2nd case: DONT_TOUCH style bad thing does not move away from good thing
10676 if ((DONT_RUN_INTO(test_element) && good_move_dir == test_dir[i]) ||
10677 (DONT_TOUCH(test_element) && test_move_dir != test_dir[i]))
10681 bad_element = test_element;
10687 if (kill_x != -1 || kill_y != -1)
10689 if (IS_PLAYER(good_x, good_y))
10691 struct PlayerInfo *player = PLAYERINFO(good_x, good_y);
10694 if (player->shield_deadly_time_left > 0 &&
10695 !IS_INDESTRUCTIBLE(bad_element))
10696 Bang(kill_x, kill_y);
10697 else if (!PLAYER_ENEMY_PROTECTED(good_x, good_y))
10700 if (player->shield_deadly_time_left > 0)
10701 Bang(kill_x, kill_y);
10702 else if (!PLAYER_ENEMY_PROTECTED(good_x, good_y))
10707 Bang(good_x, good_y);
10711 void TestIfBadThingHitsGoodThing(int bad_x, int bad_y, int bad_move_dir)
10713 int i, kill_x = -1, kill_y = -1;
10714 int bad_element = Feld[bad_x][bad_y];
10715 static int test_xy[4][2] =
10722 static int touch_dir[4] =
10724 MV_LEFT | MV_RIGHT,
10729 static int test_dir[4] =
10737 if (bad_element == EL_EXPLOSION) /* skip just exploding bad things */
10740 for (i = 0; i < NUM_DIRECTIONS; i++)
10742 int test_x, test_y, test_move_dir, test_element;
10744 test_x = bad_x + test_xy[i][0];
10745 test_y = bad_y + test_xy[i][1];
10746 if (!IN_LEV_FIELD(test_x, test_y))
10750 (IS_MOVING(test_x, test_y) ? MovDir[test_x][test_y] : MV_NO_MOVING);
10752 test_element = Feld[test_x][test_y];
10754 /* 1st case: good thing is moving towards DONT_RUN_INTO style bad thing;
10755 2nd case: DONT_TOUCH style bad thing does not move away from good thing
10757 if ((DONT_RUN_INTO(bad_element) && bad_move_dir == test_dir[i]) ||
10758 (DONT_TOUCH(bad_element) && test_move_dir != test_dir[i]))
10760 /* good thing is player or penguin that does not move away */
10761 if (IS_PLAYER(test_x, test_y))
10763 struct PlayerInfo *player = PLAYERINFO(test_x, test_y);
10765 if (bad_element == EL_ROBOT && player->is_moving)
10766 continue; /* robot does not kill player if he is moving */
10768 if (game.engine_version >= VERSION_IDENT(3,0,7,0))
10770 if (player->MovPos != 0 && !(player->MovDir & touch_dir[i]))
10771 continue; /* center and border element do not touch */
10778 else if (test_element == EL_PENGUIN)
10787 if (kill_x != -1 || kill_y != -1)
10789 if (IS_PLAYER(kill_x, kill_y))
10791 struct PlayerInfo *player = PLAYERINFO(kill_x, kill_y);
10794 if (player->shield_deadly_time_left > 0 &&
10795 !IS_INDESTRUCTIBLE(bad_element))
10796 Bang(bad_x, bad_y);
10797 else if (!PLAYER_ENEMY_PROTECTED(kill_x, kill_y))
10800 if (player->shield_deadly_time_left > 0)
10801 Bang(bad_x, bad_y);
10802 else if (!PLAYER_ENEMY_PROTECTED(kill_x, kill_y))
10807 Bang(kill_x, kill_y);
10811 void TestIfHeroTouchesBadThing(int x, int y)
10813 TestIfGoodThingHitsBadThing(x, y, MV_NO_MOVING);
10816 void TestIfHeroRunsIntoBadThing(int x, int y, int move_dir)
10818 TestIfGoodThingHitsBadThing(x, y, move_dir);
10821 void TestIfBadThingTouchesHero(int x, int y)
10823 TestIfBadThingHitsGoodThing(x, y, MV_NO_MOVING);
10826 void TestIfBadThingRunsIntoHero(int x, int y, int move_dir)
10828 TestIfBadThingHitsGoodThing(x, y, move_dir);
10831 void TestIfFriendTouchesBadThing(int x, int y)
10833 TestIfGoodThingHitsBadThing(x, y, MV_NO_MOVING);
10836 void TestIfBadThingTouchesFriend(int x, int y)
10838 TestIfBadThingHitsGoodThing(x, y, MV_NO_MOVING);
10841 void TestIfBadThingTouchesOtherBadThing(int bad_x, int bad_y)
10843 int i, kill_x = bad_x, kill_y = bad_y;
10844 static int xy[4][2] =
10852 for (i = 0; i < NUM_DIRECTIONS; i++)
10856 x = bad_x + xy[i][0];
10857 y = bad_y + xy[i][1];
10858 if (!IN_LEV_FIELD(x, y))
10861 element = Feld[x][y];
10862 if (IS_AMOEBOID(element) || element == EL_GAME_OF_LIFE ||
10863 element == EL_AMOEBA_GROWING || element == EL_AMOEBA_DROP)
10871 if (kill_x != bad_x || kill_y != bad_y)
10872 Bang(bad_x, bad_y);
10875 void KillHero(struct PlayerInfo *player)
10877 int jx = player->jx, jy = player->jy;
10879 if (!player->active)
10882 /* remove accessible field at the player's position */
10883 Feld[jx][jy] = EL_EMPTY;
10885 /* deactivate shield (else Bang()/Explode() would not work right) */
10886 player->shield_normal_time_left = 0;
10887 player->shield_deadly_time_left = 0;
10893 static void KillHeroUnlessEnemyProtected(int x, int y)
10895 if (!PLAYER_ENEMY_PROTECTED(x, y))
10896 KillHero(PLAYERINFO(x, y));
10899 static void KillHeroUnlessExplosionProtected(int x, int y)
10901 if (!PLAYER_EXPLOSION_PROTECTED(x, y))
10902 KillHero(PLAYERINFO(x, y));
10905 void BuryHero(struct PlayerInfo *player)
10907 int jx = player->jx, jy = player->jy;
10909 if (!player->active)
10913 PlayLevelSoundElementAction(jx, jy, player->element_nr, ACTION_DYING);
10915 PlayLevelSound(jx, jy, SND_CLASS_PLAYER_DYING);
10917 PlayLevelSound(jx, jy, SND_GAME_LOSING);
10919 player->GameOver = TRUE;
10920 RemoveHero(player);
10923 void RemoveHero(struct PlayerInfo *player)
10925 int jx = player->jx, jy = player->jy;
10926 int i, found = FALSE;
10928 player->present = FALSE;
10929 player->active = FALSE;
10931 if (!ExplodeField[jx][jy])
10932 StorePlayer[jx][jy] = 0;
10934 for (i = 0; i < MAX_PLAYERS; i++)
10935 if (stored_player[i].active)
10939 AllPlayersGone = TRUE;
10946 =============================================================================
10947 checkDiagonalPushing()
10948 -----------------------------------------------------------------------------
10949 check if diagonal input device direction results in pushing of object
10950 (by checking if the alternative direction is walkable, diggable, ...)
10951 =============================================================================
10954 static boolean checkDiagonalPushing(struct PlayerInfo *player,
10955 int x, int y, int real_dx, int real_dy)
10957 int jx, jy, dx, dy, xx, yy;
10959 if (real_dx == 0 || real_dy == 0) /* no diagonal direction => push */
10962 /* diagonal direction: check alternative direction */
10967 xx = jx + (dx == 0 ? real_dx : 0);
10968 yy = jy + (dy == 0 ? real_dy : 0);
10970 return (!IN_LEV_FIELD(xx, yy) || IS_SOLID_FOR_PUSHING(Feld[xx][yy]));
10974 =============================================================================
10976 -----------------------------------------------------------------------------
10977 x, y: field next to player (non-diagonal) to try to dig to
10978 real_dx, real_dy: direction as read from input device (can be diagonal)
10979 =============================================================================
10982 int DigField(struct PlayerInfo *player,
10983 int oldx, int oldy, int x, int y,
10984 int real_dx, int real_dy, int mode)
10987 boolean use_spring_bug = (game.engine_version < VERSION_IDENT(2,2,0,0));
10989 boolean is_player = (IS_PLAYER(oldx, oldy) || mode != DF_DIG);
10990 boolean player_was_pushing = player->is_pushing;
10991 int jx = oldx, jy = oldy;
10992 int dx = x - jx, dy = y - jy;
10993 int nextx = x + dx, nexty = y + dy;
10994 int move_direction = (dx == -1 ? MV_LEFT :
10995 dx == +1 ? MV_RIGHT :
10997 dy == +1 ? MV_DOWN : MV_NO_MOVING);
10998 int opposite_direction = MV_DIR_OPPOSITE(move_direction);
11000 int dig_side = MV_DIR_OPPOSITE(move_direction);
11002 static int trigger_sides[4] =
11004 CH_SIDE_RIGHT, /* moving left */
11005 CH_SIDE_LEFT, /* moving right */
11006 CH_SIDE_BOTTOM, /* moving up */
11007 CH_SIDE_TOP, /* moving down */
11009 int dig_side = trigger_sides[MV_DIR_BIT(move_direction)];
11011 int old_element = Feld[jx][jy];
11014 if (is_player) /* function can also be called by EL_PENGUIN */
11016 if (player->MovPos == 0)
11018 player->is_digging = FALSE;
11019 player->is_collecting = FALSE;
11022 if (player->MovPos == 0) /* last pushing move finished */
11023 player->is_pushing = FALSE;
11025 if (mode == DF_NO_PUSH) /* player just stopped pushing */
11027 player->is_switching = FALSE;
11028 #if USE_NEW_PUSH_DELAY
11029 player->push_delay = -1;
11031 player->push_delay = 0;
11034 return MF_NO_ACTION;
11038 if (IS_MOVING(x, y) || IS_PLAYER(x, y))
11039 return MF_NO_ACTION;
11044 if (IS_TUBE(Feld[jx][jy]) || IS_TUBE(Back[jx][jy]))
11046 if (IS_TUBE(Feld[jx][jy]) ||
11047 (IS_TUBE(Back[jx][jy]) && game.engine_version >= VERSION_IDENT(2,2,0,0)))
11051 int tube_element = (IS_TUBE(Feld[jx][jy]) ? Feld[jx][jy] : Back[jx][jy]);
11052 int tube_leave_directions[][2] =
11054 { EL_TUBE_ANY, MV_LEFT | MV_RIGHT | MV_UP | MV_DOWN },
11055 { EL_TUBE_VERTICAL, MV_UP | MV_DOWN },
11056 { EL_TUBE_HORIZONTAL, MV_LEFT | MV_RIGHT },
11057 { EL_TUBE_VERTICAL_LEFT, MV_LEFT | MV_UP | MV_DOWN },
11058 { EL_TUBE_VERTICAL_RIGHT, MV_RIGHT | MV_UP | MV_DOWN },
11059 { EL_TUBE_HORIZONTAL_UP, MV_LEFT | MV_RIGHT | MV_UP },
11060 { EL_TUBE_HORIZONTAL_DOWN, MV_LEFT | MV_RIGHT | MV_DOWN },
11061 { EL_TUBE_LEFT_UP, MV_LEFT | MV_UP },
11062 { EL_TUBE_LEFT_DOWN, MV_LEFT | MV_DOWN },
11063 { EL_TUBE_RIGHT_UP, MV_RIGHT | MV_UP },
11064 { EL_TUBE_RIGHT_DOWN, MV_RIGHT | MV_DOWN },
11065 { -1, MV_LEFT | MV_RIGHT | MV_UP | MV_DOWN }
11068 while (tube_leave_directions[i][0] != tube_element)
11071 if (tube_leave_directions[i][0] == -1) /* should not happen */
11075 if (!(tube_leave_directions[i][1] & move_direction))
11076 return MF_NO_ACTION; /* tube has no opening in this direction */
11081 if (IS_TUBE(Back[jx][jy]) && game.engine_version >= VERSION_IDENT(2,2,0,0))
11082 old_element = Back[jx][jy];
11086 if (IS_WALKABLE(old_element) && !ACCESS_FROM(old_element, move_direction))
11087 return MF_NO_ACTION; /* field has no opening in this direction */
11089 if (IS_PASSABLE(old_element) && !ACCESS_FROM(old_element,opposite_direction))
11090 return MF_NO_ACTION; /* field has no opening in this direction */
11092 element = Feld[x][y];
11094 if (!is_player && !IS_COLLECTIBLE(element)) /* penguin cannot collect it */
11095 return MF_NO_ACTION;
11097 if (mode == DF_SNAP && !IS_SNAPPABLE(element) &&
11098 game.engine_version >= VERSION_IDENT(2,2,0,0))
11099 return MF_NO_ACTION;
11102 if (game.gravity && is_player && !player->is_auto_moving &&
11103 canFallDown(player) && move_direction != MV_DOWN &&
11104 !canMoveToValidFieldWithGravity(jx, jy, move_direction))
11105 return MF_NO_ACTION; /* player cannot walk here due to gravity */
11109 if (element == EL_EMPTY_SPACE &&
11110 game.gravity && !player->is_auto_moving &&
11111 canFallDown(player) && move_direction != MV_DOWN)
11112 return MF_NO_ACTION; /* player cannot walk here due to gravity */
11118 case EL_SP_PORT_LEFT:
11119 case EL_SP_PORT_RIGHT:
11120 case EL_SP_PORT_UP:
11121 case EL_SP_PORT_DOWN:
11122 case EL_SP_PORT_HORIZONTAL:
11123 case EL_SP_PORT_VERTICAL:
11124 case EL_SP_PORT_ANY:
11125 case EL_SP_GRAVITY_PORT_LEFT:
11126 case EL_SP_GRAVITY_PORT_RIGHT:
11127 case EL_SP_GRAVITY_PORT_UP:
11128 case EL_SP_GRAVITY_PORT_DOWN:
11130 if (!canEnterSupaplexPort(x, y, dx, dy))
11131 return MF_NO_ACTION;
11134 element != EL_SP_PORT_LEFT &&
11135 element != EL_SP_GRAVITY_PORT_LEFT &&
11136 element != EL_SP_PORT_HORIZONTAL &&
11137 element != EL_SP_PORT_ANY) ||
11139 element != EL_SP_PORT_RIGHT &&
11140 element != EL_SP_GRAVITY_PORT_RIGHT &&
11141 element != EL_SP_PORT_HORIZONTAL &&
11142 element != EL_SP_PORT_ANY) ||
11144 element != EL_SP_PORT_UP &&
11145 element != EL_SP_GRAVITY_PORT_UP &&
11146 element != EL_SP_PORT_VERTICAL &&
11147 element != EL_SP_PORT_ANY) ||
11149 element != EL_SP_PORT_DOWN &&
11150 element != EL_SP_GRAVITY_PORT_DOWN &&
11151 element != EL_SP_PORT_VERTICAL &&
11152 element != EL_SP_PORT_ANY) ||
11153 !IN_LEV_FIELD(nextx, nexty) ||
11154 !IS_FREE(nextx, nexty))
11155 return MF_NO_ACTION;
11158 if (element == EL_SP_GRAVITY_PORT_LEFT ||
11159 element == EL_SP_GRAVITY_PORT_RIGHT ||
11160 element == EL_SP_GRAVITY_PORT_UP ||
11161 element == EL_SP_GRAVITY_PORT_DOWN)
11162 game.gravity = !game.gravity;
11164 /* automatically move to the next field with double speed */
11165 player->programmed_action = move_direction;
11167 if (player->move_delay_reset_counter == 0)
11169 player->move_delay_reset_counter = 2; /* two double speed steps */
11171 DOUBLE_PLAYER_SPEED(player);
11174 player->move_delay_reset_counter = 2;
11176 DOUBLE_PLAYER_SPEED(player);
11180 printf("::: passing port %d,%d [%d]\n", x, y, FrameCounter);
11183 PlayLevelSound(x, y, SND_CLASS_SP_PORT_PASSING);
11189 case EL_TUBE_VERTICAL:
11190 case EL_TUBE_HORIZONTAL:
11191 case EL_TUBE_VERTICAL_LEFT:
11192 case EL_TUBE_VERTICAL_RIGHT:
11193 case EL_TUBE_HORIZONTAL_UP:
11194 case EL_TUBE_HORIZONTAL_DOWN:
11195 case EL_TUBE_LEFT_UP:
11196 case EL_TUBE_LEFT_DOWN:
11197 case EL_TUBE_RIGHT_UP:
11198 case EL_TUBE_RIGHT_DOWN:
11201 int tube_enter_directions[][2] =
11203 { EL_TUBE_ANY, MV_LEFT | MV_RIGHT | MV_UP | MV_DOWN },
11204 { EL_TUBE_VERTICAL, MV_UP | MV_DOWN },
11205 { EL_TUBE_HORIZONTAL, MV_LEFT | MV_RIGHT },
11206 { EL_TUBE_VERTICAL_LEFT, MV_RIGHT | MV_UP | MV_DOWN },
11207 { EL_TUBE_VERTICAL_RIGHT, MV_LEFT | MV_UP | MV_DOWN },
11208 { EL_TUBE_HORIZONTAL_UP, MV_LEFT | MV_RIGHT | MV_DOWN },
11209 { EL_TUBE_HORIZONTAL_DOWN, MV_LEFT | MV_RIGHT | MV_UP },
11210 { EL_TUBE_LEFT_UP, MV_RIGHT | MV_DOWN },
11211 { EL_TUBE_LEFT_DOWN, MV_RIGHT | MV_UP },
11212 { EL_TUBE_RIGHT_UP, MV_LEFT | MV_DOWN },
11213 { EL_TUBE_RIGHT_DOWN, MV_LEFT | MV_UP },
11214 { -1, MV_NO_MOVING }
11217 while (tube_enter_directions[i][0] != element)
11220 if (tube_enter_directions[i][0] == -1) /* should not happen */
11224 if (!(tube_enter_directions[i][1] & move_direction))
11225 return MF_NO_ACTION; /* tube has no opening in this direction */
11227 PlayLevelSound(x, y, SND_CLASS_TUBE_WALKING);
11235 if (IS_WALKABLE(element) && ACCESS_FROM(element, opposite_direction))
11237 if (IS_WALKABLE(element))
11240 int sound_element = SND_ELEMENT(element);
11241 int sound_action = ACTION_WALKING;
11244 if (!ACCESS_FROM(element, opposite_direction))
11245 return MF_NO_ACTION; /* field not accessible from this direction */
11249 if (element == EL_EMPTY_SPACE &&
11250 game.gravity && !player->is_auto_moving &&
11251 canFallDown(player) && move_direction != MV_DOWN)
11252 return MF_NO_ACTION; /* player cannot walk here due to gravity */
11255 if (IS_GATE(element))
11257 if (!player->key[element - EL_GATE_1])
11258 return MF_NO_ACTION;
11260 else if (IS_GATE_GRAY(element))
11262 if (!player->key[element - EL_GATE_1_GRAY])
11263 return MF_NO_ACTION;
11265 else if (element == EL_EXIT_OPEN ||
11266 element == EL_SP_EXIT_OPEN ||
11267 element == EL_SP_EXIT_OPENING)
11269 sound_action = ACTION_PASSING; /* player is passing exit */
11271 else if (element == EL_EMPTY)
11273 sound_action = ACTION_MOVING; /* nothing to walk on */
11276 /* play sound from background or player, whatever is available */
11277 if (element_info[sound_element].sound[sound_action] != SND_UNDEFINED)
11278 PlayLevelSoundElementAction(x, y, sound_element, sound_action);
11280 PlayLevelSoundElementAction(x, y, player->element_nr, sound_action);
11285 else if (IS_PASSABLE(element) && canPassField(x, y, move_direction))
11287 else if (IS_PASSABLE(element))
11291 if (!canPassField(x, y, move_direction))
11292 return MF_NO_ACTION;
11297 if (!IN_LEV_FIELD(nextx, nexty) || IS_PLAYER(nextx, nexty) ||
11298 !IS_WALKABLE_FROM(Feld[nextx][nexty], move_direction) ||
11299 (!level.can_pass_to_walkable && !IS_FREE(nextx, nexty)))
11300 return MF_NO_ACTION;
11302 if (!IN_LEV_FIELD(nextx, nexty) || !IS_FREE(nextx, nexty))
11303 return MF_NO_ACTION;
11308 if (!ACCESS_FROM(element, opposite_direction))
11309 return MF_NO_ACTION; /* field not accessible from this direction */
11311 if (IS_CUSTOM_ELEMENT(element) &&
11312 !ACCESS_FROM(element, opposite_direction))
11313 return MF_NO_ACTION; /* field not accessible from this direction */
11317 if (CAN_MOVE(element)) /* only fixed elements can be passed! */
11318 return MF_NO_ACTION;
11323 if (IS_EM_GATE(element))
11325 if (!player->key[element - EL_EM_GATE_1])
11326 return MF_NO_ACTION;
11328 else if (IS_EM_GATE_GRAY(element))
11330 if (!player->key[element - EL_EM_GATE_1_GRAY])
11331 return MF_NO_ACTION;
11333 else if (IS_SP_PORT(element))
11335 if (element == EL_SP_GRAVITY_PORT_LEFT ||
11336 element == EL_SP_GRAVITY_PORT_RIGHT ||
11337 element == EL_SP_GRAVITY_PORT_UP ||
11338 element == EL_SP_GRAVITY_PORT_DOWN)
11339 game.gravity = !game.gravity;
11340 else if (element == EL_SP_GRAVITY_ON_PORT_LEFT ||
11341 element == EL_SP_GRAVITY_ON_PORT_RIGHT ||
11342 element == EL_SP_GRAVITY_ON_PORT_UP ||
11343 element == EL_SP_GRAVITY_ON_PORT_DOWN)
11344 game.gravity = TRUE;
11345 else if (element == EL_SP_GRAVITY_OFF_PORT_LEFT ||
11346 element == EL_SP_GRAVITY_OFF_PORT_RIGHT ||
11347 element == EL_SP_GRAVITY_OFF_PORT_UP ||
11348 element == EL_SP_GRAVITY_OFF_PORT_DOWN)
11349 game.gravity = FALSE;
11352 /* automatically move to the next field with double speed */
11353 player->programmed_action = move_direction;
11355 if (player->move_delay_reset_counter == 0)
11357 player->move_delay_reset_counter = 2; /* two double speed steps */
11359 DOUBLE_PLAYER_SPEED(player);
11362 player->move_delay_reset_counter = 2;
11364 DOUBLE_PLAYER_SPEED(player);
11367 PlayLevelSoundAction(x, y, ACTION_PASSING);
11371 else if (IS_DIGGABLE(element))
11375 if (mode != DF_SNAP)
11378 GfxElement[x][y] = GFX_ELEMENT(element);
11381 (GFX_CRUMBLED(element) ? EL_SAND : GFX_ELEMENT(element));
11383 player->is_digging = TRUE;
11386 PlayLevelSoundElementAction(x, y, element, ACTION_DIGGING);
11388 CheckTriggeredElementChangeByPlayer(x, y, element,CE_OTHER_GETS_DIGGED,
11389 player->index_bit, dig_side);
11392 if (mode == DF_SNAP)
11393 TestIfElementTouchesCustomElement(x, y); /* for empty space */
11398 else if (IS_COLLECTIBLE(element))
11402 if (is_player && mode != DF_SNAP)
11404 GfxElement[x][y] = element;
11405 player->is_collecting = TRUE;
11408 if (element == EL_SPEED_PILL)
11409 player->move_delay_value = MOVE_DELAY_HIGH_SPEED;
11410 else if (element == EL_EXTRA_TIME && level.time > 0)
11413 DrawGameValue_Time(TimeLeft);
11415 else if (element == EL_SHIELD_NORMAL || element == EL_SHIELD_DEADLY)
11417 player->shield_normal_time_left += 10;
11418 if (element == EL_SHIELD_DEADLY)
11419 player->shield_deadly_time_left += 10;
11421 else if (element == EL_DYNAMITE || element == EL_SP_DISK_RED)
11423 if (player->inventory_size < MAX_INVENTORY_SIZE)
11424 player->inventory_element[player->inventory_size++] = element;
11426 DrawGameValue_Dynamite(local_player->inventory_size);
11428 else if (element == EL_DYNABOMB_INCREASE_NUMBER)
11430 player->dynabomb_count++;
11431 player->dynabombs_left++;
11433 else if (element == EL_DYNABOMB_INCREASE_SIZE)
11435 player->dynabomb_size++;
11437 else if (element == EL_DYNABOMB_INCREASE_POWER)
11439 player->dynabomb_xl = TRUE;
11441 else if ((element >= EL_KEY_1 && element <= EL_KEY_4) ||
11442 (element >= EL_EM_KEY_1 && element <= EL_EM_KEY_4))
11444 int key_nr = (element >= EL_KEY_1 && element <= EL_KEY_4 ?
11445 element - EL_KEY_1 : element - EL_EM_KEY_1);
11447 player->key[key_nr] = TRUE;
11449 DrawGameValue_Keys(player);
11451 redraw_mask |= REDRAW_DOOR_1;
11453 else if (IS_ENVELOPE(element))
11456 player->show_envelope = element;
11458 ShowEnvelope(element - EL_ENVELOPE_1);
11461 else if (IS_DROPPABLE(element) ||
11462 IS_THROWABLE(element)) /* can be collected and dropped */
11466 if (element_info[element].collect_count == 0)
11467 player->inventory_infinite_element = element;
11469 for (i = 0; i < element_info[element].collect_count; i++)
11470 if (player->inventory_size < MAX_INVENTORY_SIZE)
11471 player->inventory_element[player->inventory_size++] = element;
11473 DrawGameValue_Dynamite(local_player->inventory_size);
11475 else if (element_info[element].collect_count > 0)
11477 local_player->gems_still_needed -=
11478 element_info[element].collect_count;
11479 if (local_player->gems_still_needed < 0)
11480 local_player->gems_still_needed = 0;
11482 DrawGameValue_Emeralds(local_player->gems_still_needed);
11485 RaiseScoreElement(element);
11486 PlayLevelSoundElementAction(x, y, element, ACTION_COLLECTING);
11489 CheckTriggeredElementChangeByPlayer(x, y, element,
11490 CE_OTHER_GETS_COLLECTED,
11491 player->index_bit, dig_side);
11494 if (mode == DF_SNAP)
11495 TestIfElementTouchesCustomElement(x, y); /* for empty space */
11500 else if (IS_PUSHABLE(element))
11502 if (mode == DF_SNAP && element != EL_BD_ROCK)
11503 return MF_NO_ACTION;
11505 if (CAN_FALL(element) && dy)
11506 return MF_NO_ACTION;
11508 if (CAN_FALL(element) && IN_LEV_FIELD(x, y + 1) && IS_FREE(x, y + 1) &&
11509 !(element == EL_SPRING && level.use_spring_bug))
11510 return MF_NO_ACTION;
11513 if (CAN_MOVE(element) && GET_MAX_MOVE_DELAY(element) == 0 &&
11514 ((move_direction & MV_VERTICAL &&
11515 ((element_info[element].move_pattern & MV_LEFT &&
11516 IN_LEV_FIELD(x - 1, y) && IS_FREE(x - 1, y)) ||
11517 (element_info[element].move_pattern & MV_RIGHT &&
11518 IN_LEV_FIELD(x + 1, y) && IS_FREE(x + 1, y)))) ||
11519 (move_direction & MV_HORIZONTAL &&
11520 ((element_info[element].move_pattern & MV_UP &&
11521 IN_LEV_FIELD(x, y - 1) && IS_FREE(x, y - 1)) ||
11522 (element_info[element].move_pattern & MV_DOWN &&
11523 IN_LEV_FIELD(x, y + 1) && IS_FREE(x, y + 1))))))
11524 return MF_NO_ACTION;
11528 /* do not push elements already moving away faster than player */
11529 if (CAN_MOVE(element) && MovDir[x][y] == move_direction &&
11530 ABS(getElementMoveStepsize(x, y)) > MOVE_STEPSIZE_NORMAL)
11531 return MF_NO_ACTION;
11533 if (element == EL_SPRING && MovDir[x][y] != MV_NO_MOVING)
11534 return MF_NO_ACTION;
11540 if (game.engine_version >= VERSION_IDENT(3,1,0,0))
11542 if (player->push_delay_value == -1 || !player_was_pushing)
11543 player->push_delay_value = GET_NEW_PUSH_DELAY(element);
11545 else if (game.engine_version >= VERSION_IDENT(3,0,7,1))
11547 if (player->push_delay_value == -1)
11548 player->push_delay_value = GET_NEW_PUSH_DELAY(element);
11551 if (game.engine_version >= VERSION_IDENT(3,0,7,1))
11553 if (player->push_delay_value == -1 || !player_was_pushing)
11554 player->push_delay_value = GET_NEW_PUSH_DELAY(element);
11557 else if (game.engine_version >= VERSION_IDENT(2,2,0,7))
11559 if (!player->is_pushing)
11560 player->push_delay_value = GET_NEW_PUSH_DELAY(element);
11564 if (game.engine_version >= VERSION_IDENT(2,2,0,7) &&
11565 (game.engine_version < VERSION_IDENT(3,0,7,1) ||
11566 !player_is_pushing))
11567 player->push_delay_value = GET_NEW_PUSH_DELAY(element);
11570 if (!player->is_pushing &&
11571 game.engine_version >= VERSION_IDENT(2,2,0,7))
11572 player->push_delay_value = GET_NEW_PUSH_DELAY(element);
11576 printf("::: push delay: %ld -> %ld [%d, %d] [%d / %d] [%d '%s': %d]\n",
11577 player->push_delay, player->push_delay_value,
11578 FrameCounter, game.engine_version,
11579 player_was_pushing, player->is_pushing,
11580 element, element_info[element].token_name,
11581 GET_NEW_PUSH_DELAY(element));
11584 player->is_pushing = TRUE;
11586 if (!(IN_LEV_FIELD(nextx, nexty) &&
11587 (IS_FREE(nextx, nexty) ||
11588 (Feld[nextx][nexty] == EL_SOKOBAN_FIELD_EMPTY &&
11589 IS_SB_ELEMENT(element)))))
11590 return MF_NO_ACTION;
11592 if (!checkDiagonalPushing(player, x, y, real_dx, real_dy))
11593 return MF_NO_ACTION;
11595 #if USE_NEW_PUSH_DELAY
11598 if ( (player->push_delay == -1) != (player->push_delay2 == 0) )
11599 printf("::: ALERT: %d, %d [%d / %d]\n",
11600 player->push_delay, player->push_delay2,
11601 FrameCounter, FrameCounter / 50);
11604 if (player->push_delay == -1) /* new pushing; restart delay */
11605 player->push_delay = 0;
11607 if (player->push_delay == 0) /* new pushing; restart delay */
11608 player->push_delay = FrameCounter;
11611 #if USE_NEW_PUSH_DELAY
11613 if ( (player->push_delay > 0) != (!xxx_fr) )
11614 printf("::: PUSH BUG! %d, (%d -> %d) %d [%d / %d]\n",
11615 player->push_delay,
11616 xxx_pdv2, player->push_delay2, player->push_delay_value,
11617 FrameCounter, FrameCounter / 50);
11621 if (player->push_delay > 0 &&
11622 !(tape.playing && tape.file_version < FILE_VERSION_2_0) &&
11623 element != EL_SPRING && element != EL_BALLOON)
11626 if (player->push_delay < player->push_delay_value &&
11627 !(tape.playing && tape.file_version < FILE_VERSION_2_0) &&
11628 element != EL_SPRING && element != EL_BALLOON)
11632 if (!FrameReached(&player->push_delay, player->push_delay_value) &&
11633 !(tape.playing && tape.file_version < FILE_VERSION_2_0) &&
11634 element != EL_SPRING && element != EL_BALLOON)
11637 /* make sure that there is no move delay before next try to push */
11638 #if USE_NEW_MOVE_DELAY
11639 if (game.engine_version >= VERSION_IDENT(3,0,7,1))
11640 player->move_delay = 0;
11642 if (game.engine_version >= VERSION_IDENT(3,0,7,1))
11643 player->move_delay = INITIAL_MOVE_DELAY_OFF;
11646 return MF_NO_ACTION;
11650 printf("::: NOW PUSHING... [%d]\n", FrameCounter);
11653 if (IS_SB_ELEMENT(element))
11655 if (element == EL_SOKOBAN_FIELD_FULL)
11657 Back[x][y] = EL_SOKOBAN_FIELD_EMPTY;
11658 local_player->sokobanfields_still_needed++;
11661 if (Feld[nextx][nexty] == EL_SOKOBAN_FIELD_EMPTY)
11663 Back[nextx][nexty] = EL_SOKOBAN_FIELD_EMPTY;
11664 local_player->sokobanfields_still_needed--;
11667 Feld[x][y] = EL_SOKOBAN_OBJECT;
11669 if (Back[x][y] == Back[nextx][nexty])
11670 PlayLevelSoundAction(x, y, ACTION_PUSHING);
11671 else if (Back[x][y] != 0)
11672 PlayLevelSoundElementAction(x, y, EL_SOKOBAN_FIELD_FULL,
11675 PlayLevelSoundElementAction(nextx, nexty, EL_SOKOBAN_FIELD_EMPTY,
11678 if (local_player->sokobanfields_still_needed == 0 &&
11679 game.emulation == EMU_SOKOBAN)
11681 player->LevelSolved = player->GameOver = TRUE;
11682 PlayLevelSound(x, y, SND_GAME_SOKOBAN_SOLVING);
11686 PlayLevelSoundElementAction(x, y, element, ACTION_PUSHING);
11688 InitMovingField(x, y, move_direction);
11689 GfxAction[x][y] = ACTION_PUSHING;
11691 if (mode == DF_SNAP)
11692 ContinueMoving(x, y);
11694 MovPos[x][y] = (dx != 0 ? dx : dy);
11696 Pushed[x][y] = TRUE;
11697 Pushed[nextx][nexty] = TRUE;
11699 if (game.engine_version < VERSION_IDENT(2,2,0,7))
11700 player->push_delay_value = GET_NEW_PUSH_DELAY(element);
11702 player->push_delay_value = -1; /* get new value later */
11705 /* check for element change _after_ element has been pushed! */
11709 /* !!! TEST ONLY !!! */
11710 CheckElementChangeByPlayer(x, y, element, CE_PUSHED_BY_PLAYER,
11711 player->index_bit, dig_side);
11712 CheckTriggeredElementChangeByPlayer(x, y, element,CE_OTHER_GETS_PUSHED,
11713 player->index_bit, dig_side);
11715 CheckTriggeredElementChangeByPlayer(x, y, element,CE_OTHER_GETS_PUSHED,
11716 player->index_bit, dig_side);
11717 CheckElementChangeByPlayer(x, y, element, CE_PUSHED_BY_PLAYER,
11718 player->index_bit, dig_side);
11724 else if (IS_SWITCHABLE(element))
11726 if (PLAYER_SWITCHING(player, x, y))
11728 CheckTriggeredElementChangeByPlayer(x,y, element,
11729 CE_OTHER_GETS_PRESSED,
11730 player->index_bit, dig_side);
11735 player->is_switching = TRUE;
11736 player->switch_x = x;
11737 player->switch_y = y;
11739 PlayLevelSoundElementAction(x, y, element, ACTION_ACTIVATING);
11741 if (element == EL_ROBOT_WHEEL)
11743 Feld[x][y] = EL_ROBOT_WHEEL_ACTIVE;
11747 DrawLevelField(x, y);
11749 else if (element == EL_SP_TERMINAL)
11753 for (yy = 0; yy < lev_fieldy; yy++) for (xx=0; xx < lev_fieldx; xx++)
11755 if (Feld[xx][yy] == EL_SP_DISK_YELLOW)
11757 else if (Feld[xx][yy] == EL_SP_TERMINAL)
11758 Feld[xx][yy] = EL_SP_TERMINAL_ACTIVE;
11761 else if (IS_BELT_SWITCH(element))
11763 ToggleBeltSwitch(x, y);
11765 else if (element == EL_SWITCHGATE_SWITCH_UP ||
11766 element == EL_SWITCHGATE_SWITCH_DOWN)
11768 ToggleSwitchgateSwitch(x, y);
11770 else if (element == EL_LIGHT_SWITCH ||
11771 element == EL_LIGHT_SWITCH_ACTIVE)
11773 ToggleLightSwitch(x, y);
11776 PlayLevelSound(x, y, element == EL_LIGHT_SWITCH ?
11777 SND_LIGHT_SWITCH_ACTIVATING :
11778 SND_LIGHT_SWITCH_DEACTIVATING);
11781 else if (element == EL_TIMEGATE_SWITCH)
11783 ActivateTimegateSwitch(x, y);
11785 else if (element == EL_BALLOON_SWITCH_LEFT ||
11786 element == EL_BALLOON_SWITCH_RIGHT ||
11787 element == EL_BALLOON_SWITCH_UP ||
11788 element == EL_BALLOON_SWITCH_DOWN ||
11789 element == EL_BALLOON_SWITCH_ANY)
11791 if (element == EL_BALLOON_SWITCH_ANY)
11792 game.balloon_dir = move_direction;
11794 game.balloon_dir = (element == EL_BALLOON_SWITCH_LEFT ? MV_LEFT :
11795 element == EL_BALLOON_SWITCH_RIGHT ? MV_RIGHT :
11796 element == EL_BALLOON_SWITCH_UP ? MV_UP :
11797 element == EL_BALLOON_SWITCH_DOWN ? MV_DOWN :
11800 else if (element == EL_LAMP)
11802 Feld[x][y] = EL_LAMP_ACTIVE;
11803 local_player->lights_still_needed--;
11805 DrawLevelField(x, y);
11807 else if (element == EL_TIME_ORB_FULL)
11809 Feld[x][y] = EL_TIME_ORB_EMPTY;
11811 DrawGameValue_Time(TimeLeft);
11813 DrawLevelField(x, y);
11816 PlaySoundStereo(SND_TIME_ORB_FULL_COLLECTING, SOUND_MIDDLE);
11820 CheckTriggeredElementChangeByPlayer(x, y, element,
11821 CE_OTHER_IS_SWITCHING,
11822 player->index_bit, dig_side);
11824 CheckTriggeredElementChangeByPlayer(x,y, element,CE_OTHER_GETS_PRESSED,
11825 player->index_bit, dig_side);
11831 if (!PLAYER_SWITCHING(player, x, y))
11833 player->is_switching = TRUE;
11834 player->switch_x = x;
11835 player->switch_y = y;
11838 /* !!! TEST ONLY !!! */
11839 CheckElementChangeByPlayer(x, y, element, CE_SWITCHED,
11840 player->index_bit, dig_side);
11841 CheckTriggeredElementChangeByPlayer(x, y, element,
11842 CE_OTHER_IS_SWITCHING,
11843 player->index_bit, dig_side);
11845 CheckTriggeredElementChangeByPlayer(x, y, element,
11846 CE_OTHER_IS_SWITCHING,
11847 player->index_bit, dig_side);
11848 CheckElementChangeByPlayer(x, y, element, CE_SWITCHED,
11849 player->index_bit, dig_side);
11854 /* !!! TEST ONLY !!! (this breaks "machine", level 000) */
11855 CheckElementChangeByPlayer(x, y, element, CE_PRESSED_BY_PLAYER,
11856 player->index_bit, dig_side);
11857 CheckTriggeredElementChangeByPlayer(x,y, element,CE_OTHER_GETS_PRESSED,
11858 player->index_bit, dig_side);
11860 CheckTriggeredElementChangeByPlayer(x,y, element,CE_OTHER_GETS_PRESSED,
11861 player->index_bit, dig_side);
11862 CheckElementChangeByPlayer(x, y, element, CE_PRESSED_BY_PLAYER,
11863 player->index_bit, dig_side);
11867 return MF_NO_ACTION;
11870 #if USE_NEW_PUSH_DELAY
11871 player->push_delay = -1;
11873 player->push_delay = 0;
11876 if (Feld[x][y] != element) /* really digged/collected something */
11877 player->is_collecting = !player->is_digging;
11882 boolean SnapField(struct PlayerInfo *player, int dx, int dy)
11884 int jx = player->jx, jy = player->jy;
11885 int x = jx + dx, y = jy + dy;
11886 int snap_direction = (dx == -1 ? MV_LEFT :
11887 dx == +1 ? MV_RIGHT :
11889 dy == +1 ? MV_DOWN : MV_NO_MOVING);
11892 if (player->MovPos != 0)
11895 if (player->MovPos != 0 && game.engine_version >= VERSION_IDENT(2,2,0,0))
11899 if (!player->active || !IN_LEV_FIELD(x, y))
11907 if (player->MovPos == 0)
11908 player->is_pushing = FALSE;
11910 player->is_snapping = FALSE;
11912 if (player->MovPos == 0)
11914 player->is_moving = FALSE;
11915 player->is_digging = FALSE;
11916 player->is_collecting = FALSE;
11922 if (player->is_snapping)
11925 player->MovDir = snap_direction;
11928 if (player->MovPos == 0)
11931 player->is_moving = FALSE;
11932 player->is_digging = FALSE;
11933 player->is_collecting = FALSE;
11936 player->is_dropping = FALSE;
11938 if (DigField(player, jx, jy, x, y, 0, 0, DF_SNAP) == MF_NO_ACTION)
11941 player->is_snapping = TRUE;
11944 if (player->MovPos == 0)
11947 player->is_moving = FALSE;
11948 player->is_digging = FALSE;
11949 player->is_collecting = FALSE;
11953 if (player->MovPos != 0) /* prevent graphic bugs in versions < 2.2.0 */
11954 DrawLevelField(player->last_jx, player->last_jy);
11957 DrawLevelField(x, y);
11966 boolean DropElement(struct PlayerInfo *player)
11968 int old_element, new_element;
11969 int dropx = player->jx, dropy = player->jy;
11970 int drop_direction = player->MovDir;
11972 int drop_side = drop_direction;
11974 static int trigger_sides[4] =
11976 CH_SIDE_LEFT, /* dropping left */
11977 CH_SIDE_RIGHT, /* dropping right */
11978 CH_SIDE_TOP, /* dropping up */
11979 CH_SIDE_BOTTOM, /* dropping down */
11981 int drop_side = trigger_sides[MV_DIR_BIT(drop_direction)];
11983 int drop_element = (player->inventory_size > 0 ?
11984 player->inventory_element[player->inventory_size - 1] :
11985 player->inventory_infinite_element != EL_UNDEFINED ?
11986 player->inventory_infinite_element :
11987 player->dynabombs_left > 0 ?
11988 EL_DYNABOMB_PLAYER_1_ACTIVE + player->index_nr :
11991 if (IS_THROWABLE(drop_element))
11993 dropx += GET_DX_FROM_DIR(drop_direction);
11994 dropy += GET_DY_FROM_DIR(drop_direction);
11996 if (!IN_LEV_FIELD(dropx, dropy))
12000 old_element = Feld[dropx][dropy]; /* old element at dropping position */
12001 new_element = drop_element; /* default: no change when dropping */
12003 /* check if player is active, not moving and ready to drop */
12004 if (!player->active || player->MovPos || player->drop_delay > 0)
12007 /* check if player has anything that can be dropped */
12009 if (new_element == EL_UNDEFINED)
12012 if (player->inventory_size == 0 &&
12013 player->inventory_infinite_element == EL_UNDEFINED &&
12014 player->dynabombs_left == 0)
12018 /* check if anything can be dropped at the current position */
12019 if (IS_ACTIVE_BOMB(old_element) || old_element == EL_EXPLOSION)
12022 /* collected custom elements can only be dropped on empty fields */
12024 if (IS_CUSTOM_ELEMENT(new_element) && old_element != EL_EMPTY)
12027 if (player->inventory_size > 0 &&
12028 IS_CUSTOM_ELEMENT(player->inventory_element[player->inventory_size - 1])
12029 && old_element != EL_EMPTY)
12033 if (old_element != EL_EMPTY)
12034 Back[dropx][dropy] = old_element; /* store old element on this field */
12036 ResetGfxAnimation(dropx, dropy);
12037 ResetRandomAnimationValue(dropx, dropy);
12039 if (player->inventory_size > 0 ||
12040 player->inventory_infinite_element != EL_UNDEFINED)
12042 if (player->inventory_size > 0)
12044 player->inventory_size--;
12047 new_element = player->inventory_element[player->inventory_size];
12050 DrawGameValue_Dynamite(local_player->inventory_size);
12052 if (new_element == EL_DYNAMITE)
12053 new_element = EL_DYNAMITE_ACTIVE;
12054 else if (new_element == EL_SP_DISK_RED)
12055 new_element = EL_SP_DISK_RED_ACTIVE;
12058 Feld[dropx][dropy] = new_element;
12060 if (IN_SCR_FIELD(SCREENX(dropx), SCREENY(dropy)))
12061 DrawGraphicThruMask(SCREENX(dropx), SCREENY(dropy),
12062 el2img(Feld[dropx][dropy]), 0);
12064 PlayLevelSoundAction(dropx, dropy, ACTION_DROPPING);
12067 /* needed if previous element just changed to "empty" in the last frame */
12068 Changed[dropx][dropy] = 0; /* allow another change */
12072 /* !!! TEST ONLY !!! */
12073 CheckElementChangeByPlayer(dropx, dropy, new_element, CE_DROPPED_BY_PLAYER,
12074 player->index_bit, drop_side);
12075 CheckTriggeredElementChangeByPlayer(dropx, dropy, new_element,
12076 CE_OTHER_GETS_DROPPED,
12077 player->index_bit, drop_side);
12079 CheckTriggeredElementChangeByPlayer(dropx, dropy, new_element,
12080 CE_OTHER_GETS_DROPPED,
12081 player->index_bit, drop_side);
12082 CheckElementChangeByPlayer(dropx, dropy, new_element, CE_DROPPED_BY_PLAYER,
12083 player->index_bit, drop_side);
12086 TestIfElementTouchesCustomElement(dropx, dropy);
12088 else /* player is dropping a dyna bomb */
12090 player->dynabombs_left--;
12093 new_element = EL_DYNABOMB_PLAYER_1_ACTIVE + player->index_nr;
12096 Feld[dropx][dropy] = new_element;
12098 if (IN_SCR_FIELD(SCREENX(dropx), SCREENY(dropy)))
12099 DrawGraphicThruMask(SCREENX(dropx), SCREENY(dropy),
12100 el2img(Feld[dropx][dropy]), 0);
12102 PlayLevelSoundAction(dropx, dropy, ACTION_DROPPING);
12109 if (Feld[dropx][dropy] == new_element) /* uninitialized unless CE change */
12112 InitField_WithBug1(dropx, dropy, FALSE);
12114 InitField(dropx, dropy, FALSE);
12115 if (CAN_MOVE(Feld[dropx][dropy]))
12116 InitMovDir(dropx, dropy);
12120 new_element = Feld[dropx][dropy]; /* element might have changed */
12122 if (IS_CUSTOM_ELEMENT(new_element) && CAN_MOVE(new_element) &&
12123 element_info[new_element].move_pattern == MV_WHEN_DROPPED)
12126 int move_stepsize = element_info[new_element].move_stepsize;
12128 int move_direction, nextx, nexty;
12130 if (element_info[new_element].move_direction_initial == MV_START_AUTOMATIC)
12131 MovDir[dropx][dropy] = drop_direction;
12133 move_direction = MovDir[dropx][dropy];
12134 nextx = dropx + GET_DX_FROM_DIR(move_direction);
12135 nexty = dropy + GET_DY_FROM_DIR(move_direction);
12138 Changed[dropx][dropy] = 0; /* allow another change */
12139 CheckCollision[dropx][dropy] = 2;
12142 if (IN_LEV_FIELD_AND_IS_FREE(nextx, nexty))
12145 WasJustMoving[dropx][dropy] = 3;
12148 InitMovingField(dropx, dropy, move_direction);
12149 ContinueMoving(dropx, dropy);
12154 /* !!! commented out from 3.1.0-4 to 3.1.0-5 !!! */
12157 Changed[dropx][dropy] = 0; /* allow another change */
12160 TestIfElementHitsCustomElement(dropx, dropy, move_direction);
12162 CheckElementChangeBySide(dropx, dropy, new_element, touched_element,
12163 CE_HITTING_SOMETHING, move_direction);
12171 player->drop_delay = 2 * TILEX / move_stepsize + 1;
12176 player->drop_delay = 8 + 8 + 8;
12180 player->drop_delay = GET_NEW_DROP_DELAY(drop_element);
12185 player->is_dropping = TRUE;
12191 /* ------------------------------------------------------------------------- */
12192 /* game sound playing functions */
12193 /* ------------------------------------------------------------------------- */
12195 static int *loop_sound_frame = NULL;
12196 static int *loop_sound_volume = NULL;
12198 void InitPlayLevelSound()
12200 int num_sounds = getSoundListSize();
12202 checked_free(loop_sound_frame);
12203 checked_free(loop_sound_volume);
12205 loop_sound_frame = checked_calloc(num_sounds * sizeof(int));
12206 loop_sound_volume = checked_calloc(num_sounds * sizeof(int));
12209 static void PlayLevelSound(int x, int y, int nr)
12211 int sx = SCREENX(x), sy = SCREENY(y);
12212 int volume, stereo_position;
12213 int max_distance = 8;
12214 int type = (IS_LOOP_SOUND(nr) ? SND_CTRL_PLAY_LOOP : SND_CTRL_PLAY_SOUND);
12216 if ((!setup.sound_simple && !IS_LOOP_SOUND(nr)) ||
12217 (!setup.sound_loops && IS_LOOP_SOUND(nr)))
12220 if (!IN_LEV_FIELD(x, y) ||
12221 sx < -max_distance || sx >= SCR_FIELDX + max_distance ||
12222 sy < -max_distance || sy >= SCR_FIELDY + max_distance)
12225 volume = SOUND_MAX_VOLUME;
12227 if (!IN_SCR_FIELD(sx, sy))
12229 int dx = ABS(sx - SCR_FIELDX / 2) - SCR_FIELDX / 2;
12230 int dy = ABS(sy - SCR_FIELDY / 2) - SCR_FIELDY / 2;
12232 volume -= volume * (dx > dy ? dx : dy) / max_distance;
12235 stereo_position = (SOUND_MAX_LEFT +
12236 (sx + max_distance) * SOUND_MAX_LEFT2RIGHT /
12237 (SCR_FIELDX + 2 * max_distance));
12239 if (IS_LOOP_SOUND(nr))
12241 /* This assures that quieter loop sounds do not overwrite louder ones,
12242 while restarting sound volume comparison with each new game frame. */
12244 if (loop_sound_volume[nr] > volume && loop_sound_frame[nr] == FrameCounter)
12247 loop_sound_volume[nr] = volume;
12248 loop_sound_frame[nr] = FrameCounter;
12251 PlaySoundExt(nr, volume, stereo_position, type);
12254 static void PlayLevelSoundNearest(int x, int y, int sound_action)
12256 PlayLevelSound(x < LEVELX(BX1) ? LEVELX(BX1) :
12257 x > LEVELX(BX2) ? LEVELX(BX2) : x,
12258 y < LEVELY(BY1) ? LEVELY(BY1) :
12259 y > LEVELY(BY2) ? LEVELY(BY2) : y,
12263 static void PlayLevelSoundAction(int x, int y, int action)
12265 PlayLevelSoundElementAction(x, y, Feld[x][y], action);
12268 static void PlayLevelSoundElementAction(int x, int y, int element, int action)
12270 int sound_effect = element_info[SND_ELEMENT(element)].sound[action];
12272 if (sound_effect != SND_UNDEFINED)
12273 PlayLevelSound(x, y, sound_effect);
12276 static void PlayLevelSoundElementActionIfLoop(int x, int y, int element,
12279 int sound_effect = element_info[SND_ELEMENT(element)].sound[action];
12281 if (sound_effect != SND_UNDEFINED && IS_LOOP_SOUND(sound_effect))
12282 PlayLevelSound(x, y, sound_effect);
12285 static void PlayLevelSoundActionIfLoop(int x, int y, int action)
12287 int sound_effect = element_info[SND_ELEMENT(Feld[x][y])].sound[action];
12289 if (sound_effect != SND_UNDEFINED && IS_LOOP_SOUND(sound_effect))
12290 PlayLevelSound(x, y, sound_effect);
12293 static void StopLevelSoundActionIfLoop(int x, int y, int action)
12295 int sound_effect = element_info[SND_ELEMENT(Feld[x][y])].sound[action];
12297 if (sound_effect != SND_UNDEFINED && IS_LOOP_SOUND(sound_effect))
12298 StopSound(sound_effect);
12301 static void PlayLevelMusic()
12303 if (levelset.music[level_nr] != MUS_UNDEFINED)
12304 PlayMusic(levelset.music[level_nr]); /* from config file */
12306 PlayMusic(MAP_NOCONF_MUSIC(level_nr)); /* from music dir */
12309 void RaiseScore(int value)
12311 local_player->score += value;
12313 DrawGameValue_Score(local_player->score);
12316 void RaiseScoreElement(int element)
12321 case EL_BD_DIAMOND:
12322 case EL_EMERALD_YELLOW:
12323 case EL_EMERALD_RED:
12324 case EL_EMERALD_PURPLE:
12325 case EL_SP_INFOTRON:
12326 RaiseScore(level.score[SC_EMERALD]);
12329 RaiseScore(level.score[SC_DIAMOND]);
12332 RaiseScore(level.score[SC_CRYSTAL]);
12335 RaiseScore(level.score[SC_PEARL]);
12338 case EL_BD_BUTTERFLY:
12339 case EL_SP_ELECTRON:
12340 RaiseScore(level.score[SC_BUG]);
12343 case EL_BD_FIREFLY:
12344 case EL_SP_SNIKSNAK:
12345 RaiseScore(level.score[SC_SPACESHIP]);
12348 case EL_DARK_YAMYAM:
12349 RaiseScore(level.score[SC_YAMYAM]);
12352 RaiseScore(level.score[SC_ROBOT]);
12355 RaiseScore(level.score[SC_PACMAN]);
12358 RaiseScore(level.score[SC_NUT]);
12361 case EL_SP_DISK_RED:
12362 case EL_DYNABOMB_INCREASE_NUMBER:
12363 case EL_DYNABOMB_INCREASE_SIZE:
12364 case EL_DYNABOMB_INCREASE_POWER:
12365 RaiseScore(level.score[SC_DYNAMITE]);
12367 case EL_SHIELD_NORMAL:
12368 case EL_SHIELD_DEADLY:
12369 RaiseScore(level.score[SC_SHIELD]);
12371 case EL_EXTRA_TIME:
12372 RaiseScore(level.score[SC_TIME_BONUS]);
12378 RaiseScore(level.score[SC_KEY]);
12381 RaiseScore(element_info[element].collect_score);
12386 void RequestQuitGame(boolean ask_if_really_quit)
12388 if (AllPlayersGone ||
12389 !ask_if_really_quit ||
12390 level_editor_test_game ||
12391 Request("Do you really want to quit the game ?",
12392 REQ_ASK | REQ_STAY_CLOSED))
12394 #if defined(NETWORK_AVALIABLE)
12395 if (options.network)
12396 SendToServer_StopPlaying();
12400 game_status = GAME_MODE_MAIN;
12408 if (tape.playing && tape.deactivate_display)
12409 TapeDeactivateDisplayOff(TRUE);
12412 OpenDoor(DOOR_OPEN_1 | DOOR_COPY_BACK);
12415 if (tape.playing && tape.deactivate_display)
12416 TapeDeactivateDisplayOn();
12423 /* ---------- new game button stuff ---------------------------------------- */
12425 /* graphic position values for game buttons */
12426 #define GAME_BUTTON_XSIZE 30
12427 #define GAME_BUTTON_YSIZE 30
12428 #define GAME_BUTTON_XPOS 5
12429 #define GAME_BUTTON_YPOS 215
12430 #define SOUND_BUTTON_XPOS 5
12431 #define SOUND_BUTTON_YPOS (GAME_BUTTON_YPOS + GAME_BUTTON_YSIZE)
12433 #define GAME_BUTTON_STOP_XPOS (GAME_BUTTON_XPOS + 0 * GAME_BUTTON_XSIZE)
12434 #define GAME_BUTTON_PAUSE_XPOS (GAME_BUTTON_XPOS + 1 * GAME_BUTTON_XSIZE)
12435 #define GAME_BUTTON_PLAY_XPOS (GAME_BUTTON_XPOS + 2 * GAME_BUTTON_XSIZE)
12436 #define SOUND_BUTTON_MUSIC_XPOS (SOUND_BUTTON_XPOS + 0 * GAME_BUTTON_XSIZE)
12437 #define SOUND_BUTTON_LOOPS_XPOS (SOUND_BUTTON_XPOS + 1 * GAME_BUTTON_XSIZE)
12438 #define SOUND_BUTTON_SIMPLE_XPOS (SOUND_BUTTON_XPOS + 2 * GAME_BUTTON_XSIZE)
12445 } gamebutton_info[NUM_GAME_BUTTONS] =
12448 GAME_BUTTON_STOP_XPOS, GAME_BUTTON_YPOS,
12453 GAME_BUTTON_PAUSE_XPOS, GAME_BUTTON_YPOS,
12454 GAME_CTRL_ID_PAUSE,
12458 GAME_BUTTON_PLAY_XPOS, GAME_BUTTON_YPOS,
12463 SOUND_BUTTON_MUSIC_XPOS, SOUND_BUTTON_YPOS,
12464 SOUND_CTRL_ID_MUSIC,
12465 "background music on/off"
12468 SOUND_BUTTON_LOOPS_XPOS, SOUND_BUTTON_YPOS,
12469 SOUND_CTRL_ID_LOOPS,
12470 "sound loops on/off"
12473 SOUND_BUTTON_SIMPLE_XPOS, SOUND_BUTTON_YPOS,
12474 SOUND_CTRL_ID_SIMPLE,
12475 "normal sounds on/off"
12479 void CreateGameButtons()
12483 for (i = 0; i < NUM_GAME_BUTTONS; i++)
12485 Bitmap *gd_bitmap = graphic_info[IMG_GLOBAL_DOOR].bitmap;
12486 struct GadgetInfo *gi;
12489 unsigned long event_mask;
12490 int gd_xoffset, gd_yoffset;
12491 int gd_x1, gd_x2, gd_y1, gd_y2;
12494 gd_xoffset = gamebutton_info[i].x;
12495 gd_yoffset = gamebutton_info[i].y;
12496 gd_x1 = DOOR_GFX_PAGEX4 + gd_xoffset;
12497 gd_x2 = DOOR_GFX_PAGEX3 + gd_xoffset;
12499 if (id == GAME_CTRL_ID_STOP ||
12500 id == GAME_CTRL_ID_PAUSE ||
12501 id == GAME_CTRL_ID_PLAY)
12503 button_type = GD_TYPE_NORMAL_BUTTON;
12505 event_mask = GD_EVENT_RELEASED;
12506 gd_y1 = DOOR_GFX_PAGEY1 + gd_yoffset - GAME_BUTTON_YSIZE;
12507 gd_y2 = DOOR_GFX_PAGEY1 + gd_yoffset - GAME_BUTTON_YSIZE;
12511 button_type = GD_TYPE_CHECK_BUTTON;
12513 ((id == SOUND_CTRL_ID_MUSIC && setup.sound_music) ||
12514 (id == SOUND_CTRL_ID_LOOPS && setup.sound_loops) ||
12515 (id == SOUND_CTRL_ID_SIMPLE && setup.sound_simple) ? TRUE : FALSE);
12516 event_mask = GD_EVENT_PRESSED;
12517 gd_y1 = DOOR_GFX_PAGEY1 + gd_yoffset;
12518 gd_y2 = DOOR_GFX_PAGEY1 + gd_yoffset - GAME_BUTTON_YSIZE;
12521 gi = CreateGadget(GDI_CUSTOM_ID, id,
12522 GDI_INFO_TEXT, gamebutton_info[i].infotext,
12523 GDI_X, DX + gd_xoffset,
12524 GDI_Y, DY + gd_yoffset,
12525 GDI_WIDTH, GAME_BUTTON_XSIZE,
12526 GDI_HEIGHT, GAME_BUTTON_YSIZE,
12527 GDI_TYPE, button_type,
12528 GDI_STATE, GD_BUTTON_UNPRESSED,
12529 GDI_CHECKED, checked,
12530 GDI_DESIGN_UNPRESSED, gd_bitmap, gd_x1, gd_y1,
12531 GDI_DESIGN_PRESSED, gd_bitmap, gd_x2, gd_y1,
12532 GDI_ALT_DESIGN_UNPRESSED, gd_bitmap, gd_x1, gd_y2,
12533 GDI_ALT_DESIGN_PRESSED, gd_bitmap, gd_x2, gd_y2,
12534 GDI_EVENT_MASK, event_mask,
12535 GDI_CALLBACK_ACTION, HandleGameButtons,
12539 Error(ERR_EXIT, "cannot create gadget");
12541 game_gadget[id] = gi;
12545 void FreeGameButtons()
12549 for (i = 0; i < NUM_GAME_BUTTONS; i++)
12550 FreeGadget(game_gadget[i]);
12553 static void MapGameButtons()
12557 for (i = 0; i < NUM_GAME_BUTTONS; i++)
12558 MapGadget(game_gadget[i]);
12561 void UnmapGameButtons()
12565 for (i = 0; i < NUM_GAME_BUTTONS; i++)
12566 UnmapGadget(game_gadget[i]);
12569 static void HandleGameButtons(struct GadgetInfo *gi)
12571 int id = gi->custom_id;
12573 if (game_status != GAME_MODE_PLAYING)
12578 case GAME_CTRL_ID_STOP:
12579 RequestQuitGame(TRUE);
12582 case GAME_CTRL_ID_PAUSE:
12583 if (options.network)
12585 #if defined(NETWORK_AVALIABLE)
12587 SendToServer_ContinuePlaying();
12589 SendToServer_PausePlaying();
12593 TapeTogglePause(TAPE_TOGGLE_MANUAL);
12596 case GAME_CTRL_ID_PLAY:
12599 #if defined(NETWORK_AVALIABLE)
12600 if (options.network)
12601 SendToServer_ContinuePlaying();
12605 tape.pausing = FALSE;
12606 DrawVideoDisplay(VIDEO_STATE_PAUSE_OFF,0);
12611 case SOUND_CTRL_ID_MUSIC:
12612 if (setup.sound_music)
12614 setup.sound_music = FALSE;
12617 else if (audio.music_available)
12619 setup.sound = setup.sound_music = TRUE;
12621 SetAudioMode(setup.sound);
12627 case SOUND_CTRL_ID_LOOPS:
12628 if (setup.sound_loops)
12629 setup.sound_loops = FALSE;
12630 else if (audio.loops_available)
12632 setup.sound = setup.sound_loops = TRUE;
12633 SetAudioMode(setup.sound);
12637 case SOUND_CTRL_ID_SIMPLE:
12638 if (setup.sound_simple)
12639 setup.sound_simple = FALSE;
12640 else if (audio.sound_available)
12642 setup.sound = setup.sound_simple = TRUE;
12643 SetAudioMode(setup.sound);